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 |
| 91 | #define R8169_NAPI_WEIGHT 64 |
| 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 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 347 | static int rx_buf_sz = 16383; |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 348 | static int use_dac = -1; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 349 | static struct { |
| 350 | u32 msg_enable; |
| 351 | } debug = { -1 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 353 | enum rtl_registers { |
| 354 | MAC0 = 0, /* Ethernet hardware address. */ |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 355 | MAC4 = 4, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 356 | MAR0 = 8, /* Multicast filter. */ |
| 357 | CounterAddrLow = 0x10, |
| 358 | CounterAddrHigh = 0x14, |
| 359 | TxDescStartAddrLow = 0x20, |
| 360 | TxDescStartAddrHigh = 0x24, |
| 361 | TxHDescStartAddrLow = 0x28, |
| 362 | TxHDescStartAddrHigh = 0x2c, |
| 363 | FLASH = 0x30, |
| 364 | ERSR = 0x36, |
| 365 | ChipCmd = 0x37, |
| 366 | TxPoll = 0x38, |
| 367 | IntrMask = 0x3c, |
| 368 | IntrStatus = 0x3e, |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 369 | |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 370 | TxConfig = 0x40, |
| 371 | #define TXCFG_AUTO_FIFO (1 << 7) /* 8111e-vl */ |
| 372 | #define TXCFG_EMPTY (1 << 11) /* 8111e-vl */ |
| 373 | |
| 374 | RxConfig = 0x44, |
| 375 | #define RX128_INT_EN (1 << 15) /* 8111c and later */ |
| 376 | #define RX_MULTI_EN (1 << 14) /* 8111c only */ |
| 377 | #define RXCFG_FIFO_SHIFT 13 |
| 378 | /* No threshold before first PCI xfer */ |
| 379 | #define RX_FIFO_THRESH (7 << RXCFG_FIFO_SHIFT) |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 380 | #define RX_EARLY_OFF (1 << 11) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 381 | #define RXCFG_DMA_SHIFT 8 |
| 382 | /* Unlimited maximum PCI burst. */ |
| 383 | #define RX_DMA_BURST (7 << RXCFG_DMA_SHIFT) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 384 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 385 | RxMissed = 0x4c, |
| 386 | Cfg9346 = 0x50, |
| 387 | Config0 = 0x51, |
| 388 | Config1 = 0x52, |
| 389 | Config2 = 0x53, |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 390 | #define PME_SIGNAL (1 << 5) /* 8168c and later */ |
| 391 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 392 | Config3 = 0x54, |
| 393 | Config4 = 0x55, |
| 394 | Config5 = 0x56, |
| 395 | MultiIntr = 0x5c, |
| 396 | PHYAR = 0x60, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 397 | PHYstatus = 0x6c, |
| 398 | RxMaxSize = 0xda, |
| 399 | CPlusCmd = 0xe0, |
| 400 | IntrMitigate = 0xe2, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 401 | |
| 402 | #define RTL_COALESCE_MASK 0x0f |
| 403 | #define RTL_COALESCE_SHIFT 4 |
| 404 | #define RTL_COALESCE_T_MAX (RTL_COALESCE_MASK) |
| 405 | #define RTL_COALESCE_FRAME_MAX (RTL_COALESCE_MASK << 2) |
| 406 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 407 | RxDescAddrLow = 0xe4, |
| 408 | RxDescAddrHigh = 0xe8, |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 409 | EarlyTxThres = 0xec, /* 8169. Unit of 32 bytes. */ |
| 410 | |
| 411 | #define NoEarlyTx 0x3f /* Max value : no early transmit. */ |
| 412 | |
| 413 | MaxTxPacketSize = 0xec, /* 8101/8168. Unit of 128 bytes. */ |
| 414 | |
| 415 | #define TxPacketMax (8064 >> 7) |
Hayes Wang | 3090bd9 | 2011-09-06 16:55:15 +0800 | [diff] [blame] | 416 | #define EarlySize 0x27 |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 417 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 418 | FuncEvent = 0xf0, |
| 419 | FuncEventMask = 0xf4, |
| 420 | FuncPresetState = 0xf8, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 421 | IBCR0 = 0xf8, |
| 422 | IBCR2 = 0xf9, |
| 423 | IBIMR0 = 0xfa, |
| 424 | IBISR0 = 0xfb, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 425 | FuncForceEvent = 0xfc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | }; |
| 427 | |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 428 | enum rtl8110_registers { |
| 429 | TBICSR = 0x64, |
| 430 | TBI_ANAR = 0x68, |
| 431 | TBI_LPAR = 0x6a, |
| 432 | }; |
| 433 | |
| 434 | enum rtl8168_8101_registers { |
| 435 | CSIDR = 0x64, |
| 436 | CSIAR = 0x68, |
| 437 | #define CSIAR_FLAG 0x80000000 |
| 438 | #define CSIAR_WRITE_CMD 0x80000000 |
| 439 | #define CSIAR_BYTE_ENABLE 0x0f |
| 440 | #define CSIAR_BYTE_ENABLE_SHIFT 12 |
| 441 | #define CSIAR_ADDR_MASK 0x0fff |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 442 | #define CSIAR_FUNC_CARD 0x00000000 |
| 443 | #define CSIAR_FUNC_SDIO 0x00010000 |
| 444 | #define CSIAR_FUNC_NIC 0x00020000 |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 445 | #define CSIAR_FUNC_NIC2 0x00010000 |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 446 | PMCH = 0x6f, |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 447 | EPHYAR = 0x80, |
| 448 | #define EPHYAR_FLAG 0x80000000 |
| 449 | #define EPHYAR_WRITE_CMD 0x80000000 |
| 450 | #define EPHYAR_REG_MASK 0x1f |
| 451 | #define EPHYAR_REG_SHIFT 16 |
| 452 | #define EPHYAR_DATA_MASK 0xffff |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 453 | DLLPR = 0xd0, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 454 | #define PFM_EN (1 << 6) |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 455 | #define TX_10M_PS_EN (1 << 7) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 456 | DBG_REG = 0xd1, |
| 457 | #define FIX_NAK_1 (1 << 4) |
| 458 | #define FIX_NAK_2 (1 << 3) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 459 | TWSI = 0xd2, |
| 460 | MCU = 0xd3, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 461 | #define NOW_IS_OOB (1 << 7) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 462 | #define TX_EMPTY (1 << 5) |
| 463 | #define RX_EMPTY (1 << 4) |
| 464 | #define RXTX_EMPTY (TX_EMPTY | RX_EMPTY) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 465 | #define EN_NDP (1 << 3) |
| 466 | #define EN_OOB_RESET (1 << 2) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 467 | #define LINK_LIST_RDY (1 << 1) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 468 | EFUSEAR = 0xdc, |
| 469 | #define EFUSEAR_FLAG 0x80000000 |
| 470 | #define EFUSEAR_WRITE_CMD 0x80000000 |
| 471 | #define EFUSEAR_READ_CMD 0x00000000 |
| 472 | #define EFUSEAR_REG_MASK 0x03ff |
| 473 | #define EFUSEAR_REG_SHIFT 8 |
| 474 | #define EFUSEAR_DATA_MASK 0xff |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 475 | MISC_1 = 0xf2, |
| 476 | #define PFM_D3COLD_EN (1 << 6) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 477 | }; |
| 478 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 479 | enum rtl8168_registers { |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 480 | LED_FREQ = 0x1a, |
| 481 | EEE_LED = 0x1b, |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 482 | ERIDR = 0x70, |
| 483 | ERIAR = 0x74, |
| 484 | #define ERIAR_FLAG 0x80000000 |
| 485 | #define ERIAR_WRITE_CMD 0x80000000 |
| 486 | #define ERIAR_READ_CMD 0x00000000 |
| 487 | #define ERIAR_ADDR_BYTE_ALIGN 4 |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 488 | #define ERIAR_TYPE_SHIFT 16 |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 489 | #define ERIAR_EXGMAC (0x00 << ERIAR_TYPE_SHIFT) |
| 490 | #define ERIAR_MSIX (0x01 << ERIAR_TYPE_SHIFT) |
| 491 | #define ERIAR_ASF (0x02 << ERIAR_TYPE_SHIFT) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 492 | #define ERIAR_OOB (0x02 << ERIAR_TYPE_SHIFT) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 493 | #define ERIAR_MASK_SHIFT 12 |
| 494 | #define ERIAR_MASK_0001 (0x1 << ERIAR_MASK_SHIFT) |
| 495 | #define ERIAR_MASK_0011 (0x3 << ERIAR_MASK_SHIFT) |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 496 | #define ERIAR_MASK_0100 (0x4 << ERIAR_MASK_SHIFT) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 497 | #define ERIAR_MASK_0101 (0x5 << ERIAR_MASK_SHIFT) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 498 | #define ERIAR_MASK_1111 (0xf << ERIAR_MASK_SHIFT) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 499 | EPHY_RXER_NUM = 0x7c, |
| 500 | OCPDR = 0xb0, /* OCP GPHY access */ |
| 501 | #define OCPDR_WRITE_CMD 0x80000000 |
| 502 | #define OCPDR_READ_CMD 0x00000000 |
| 503 | #define OCPDR_REG_MASK 0x7f |
| 504 | #define OCPDR_GPHY_REG_SHIFT 16 |
| 505 | #define OCPDR_DATA_MASK 0xffff |
| 506 | OCPAR = 0xb4, |
| 507 | #define OCPAR_FLAG 0x80000000 |
| 508 | #define OCPAR_GPHY_WRITE_CMD 0x8000f060 |
| 509 | #define OCPAR_GPHY_READ_CMD 0x0000f060 |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 510 | GPHY_OCP = 0xb8, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 511 | RDSAR1 = 0xd0, /* 8168c only. Undocumented on 8168dp */ |
| 512 | MISC = 0xf0, /* 8168e only. */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 513 | #define TXPLA_RST (1 << 29) |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 514 | #define DISABLE_LAN_EN (1 << 23) /* Enable GPIO pin */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 515 | #define PWM_EN (1 << 22) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 516 | #define RXDV_GATED_EN (1 << 19) |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 517 | #define EARLY_TALLY_EN (1 << 16) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 518 | }; |
| 519 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 520 | enum rtl_register_content { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | /* InterruptStatusBits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 522 | SYSErr = 0x8000, |
| 523 | PCSTimeout = 0x4000, |
| 524 | SWInt = 0x0100, |
| 525 | TxDescUnavail = 0x0080, |
| 526 | RxFIFOOver = 0x0040, |
| 527 | LinkChg = 0x0020, |
| 528 | RxOverflow = 0x0010, |
| 529 | TxErr = 0x0008, |
| 530 | TxOK = 0x0004, |
| 531 | RxErr = 0x0002, |
| 532 | RxOK = 0x0001, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
| 534 | /* RxStatusDesc */ |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 535 | RxBOVF = (1 << 24), |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 536 | RxFOVF = (1 << 23), |
| 537 | RxRWT = (1 << 22), |
| 538 | RxRES = (1 << 21), |
| 539 | RxRUNT = (1 << 20), |
| 540 | RxCRC = (1 << 19), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
| 542 | /* ChipCmdBits */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 543 | StopReq = 0x80, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 544 | CmdReset = 0x10, |
| 545 | CmdRxEnb = 0x08, |
| 546 | CmdTxEnb = 0x04, |
| 547 | RxBufEmpty = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | |
Francois Romieu | 275391a | 2007-02-23 23:50:28 +0100 | [diff] [blame] | 549 | /* TXPoll register p.5 */ |
| 550 | HPQ = 0x80, /* Poll cmd on the high prio queue */ |
| 551 | NPQ = 0x40, /* Poll cmd on the low prio queue */ |
| 552 | FSWInt = 0x01, /* Forced software interrupt */ |
| 553 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | /* Cfg9346Bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 555 | Cfg9346_Lock = 0x00, |
| 556 | Cfg9346_Unlock = 0xc0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
| 558 | /* rx_mode_bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 559 | AcceptErr = 0x20, |
| 560 | AcceptRunt = 0x10, |
| 561 | AcceptBroadcast = 0x08, |
| 562 | AcceptMulticast = 0x04, |
| 563 | AcceptMyPhys = 0x02, |
| 564 | AcceptAllPhys = 0x01, |
Francois Romieu | 1687b56 | 2011-07-19 17:21:29 +0200 | [diff] [blame] | 565 | #define RX_CONFIG_ACCEPT_MASK 0x3f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | /* TxConfigBits */ |
| 568 | TxInterFrameGapShift = 24, |
| 569 | TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */ |
| 570 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 571 | /* Config1 register p.24 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 572 | LEDS1 = (1 << 7), |
| 573 | LEDS0 = (1 << 6), |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 574 | Speed_down = (1 << 4), |
| 575 | MEMMAP = (1 << 3), |
| 576 | IOMAP = (1 << 2), |
| 577 | VPD = (1 << 1), |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 578 | PMEnable = (1 << 0), /* Power Management Enable */ |
| 579 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 580 | /* Config2 register p. 25 */ |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 581 | ClkReqEn = (1 << 7), /* Clock Request Enable */ |
françois romieu | 2ca6cf0 | 2011-12-15 08:37:43 +0000 | [diff] [blame] | 582 | MSIEnable = (1 << 5), /* 8169 only. Reserved in the 8168. */ |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 583 | PCI_Clock_66MHz = 0x01, |
| 584 | PCI_Clock_33MHz = 0x00, |
| 585 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 586 | /* Config3 register p.25 */ |
| 587 | MagicPacket = (1 << 5), /* Wake up when receives a Magic Packet */ |
| 588 | LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */ |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 589 | Jumbo_En0 = (1 << 2), /* 8168 only. Reserved in the 8168b */ |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 590 | Rdy_to_L23 = (1 << 1), /* L23 Enable */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 591 | Beacon_en = (1 << 0), /* 8168 only. Reserved in the 8168b */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 592 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 593 | /* Config4 register */ |
| 594 | Jumbo_En1 = (1 << 1), /* 8168 only. Reserved in the 8168b */ |
| 595 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 596 | /* Config5 register p.27 */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 597 | BWF = (1 << 6), /* Accept Broadcast wakeup frame */ |
| 598 | MWF = (1 << 5), /* Accept Multicast wakeup frame */ |
| 599 | UWF = (1 << 4), /* Accept Unicast wakeup frame */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 600 | Spi_en = (1 << 3), |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 601 | LanWake = (1 << 1), /* LanWake enable/disable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 602 | PMEStatus = (1 << 0), /* PME status can be reset by PCI RST# */ |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 603 | ASPM_en = (1 << 0), /* ASPM enable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 604 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 605 | /* TBICSR p.28 */ |
| 606 | TBIReset = 0x80000000, |
| 607 | TBILoopback = 0x40000000, |
| 608 | TBINwEnable = 0x20000000, |
| 609 | TBINwRestart = 0x10000000, |
| 610 | TBILinkOk = 0x02000000, |
| 611 | TBINwComplete = 0x01000000, |
| 612 | |
| 613 | /* CPlusCmd p.31 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 614 | EnableBist = (1 << 15), // 8168 8101 |
| 615 | Mac_dbgo_oe = (1 << 14), // 8168 8101 |
| 616 | Normal_mode = (1 << 13), // unused |
| 617 | Force_half_dup = (1 << 12), // 8168 8101 |
| 618 | Force_rxflow_en = (1 << 11), // 8168 8101 |
| 619 | Force_txflow_en = (1 << 10), // 8168 8101 |
| 620 | Cxpl_dbg_sel = (1 << 9), // 8168 8101 |
| 621 | ASF = (1 << 8), // 8168 8101 |
| 622 | PktCntrDisable = (1 << 7), // 8168 8101 |
| 623 | Mac_dbgo_sel = 0x001c, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | RxVlan = (1 << 6), |
| 625 | RxChkSum = (1 << 5), |
| 626 | PCIDAC = (1 << 4), |
| 627 | PCIMulRW = (1 << 3), |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 628 | INTT_0 = 0x0000, // 8168 |
| 629 | INTT_1 = 0x0001, // 8168 |
| 630 | INTT_2 = 0x0002, // 8168 |
| 631 | INTT_3 = 0x0003, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | |
| 633 | /* rtl8169_PHYstatus */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 634 | TBI_Enable = 0x80, |
| 635 | TxFlowCtrl = 0x40, |
| 636 | RxFlowCtrl = 0x20, |
| 637 | _1000bpsF = 0x10, |
| 638 | _100bps = 0x08, |
| 639 | _10bps = 0x04, |
| 640 | LinkStatus = 0x02, |
| 641 | FullDup = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | /* _TBICSRBit */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 644 | TBILinkOK = 0x02000000, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 645 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 646 | /* ResetCounterCommand */ |
| 647 | CounterReset = 0x1, |
| 648 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 649 | /* DumpCounterCommand */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 650 | CounterDump = 0x8, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 651 | |
| 652 | /* magic enable v2 */ |
| 653 | MagicPacket_v2 = (1 << 16), /* Wake up when receives a Magic Packet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 654 | }; |
| 655 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 656 | enum rtl_desc_bit { |
| 657 | /* First doubleword. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | DescOwn = (1 << 31), /* Descriptor is owned by NIC */ |
| 659 | RingEnd = (1 << 30), /* End of descriptor ring */ |
| 660 | FirstFrag = (1 << 29), /* First segment of a packet */ |
| 661 | LastFrag = (1 << 28), /* Final segment of a packet */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 662 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 664 | /* Generic case. */ |
| 665 | enum rtl_tx_desc_bit { |
| 666 | /* First doubleword. */ |
| 667 | TD_LSO = (1 << 27), /* Large Send Offload */ |
| 668 | #define TD_MSS_MAX 0x07ffu /* MSS value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 670 | /* Second doubleword. */ |
| 671 | TxVlanTag = (1 << 17), /* Add VLAN tag */ |
| 672 | }; |
| 673 | |
| 674 | /* 8169, 8168b and 810x except 8102e. */ |
| 675 | enum rtl_tx_desc_bit_0 { |
| 676 | /* First doubleword. */ |
| 677 | #define TD0_MSS_SHIFT 16 /* MSS position (11 bits) */ |
| 678 | TD0_TCP_CS = (1 << 16), /* Calculate TCP/IP checksum */ |
| 679 | TD0_UDP_CS = (1 << 17), /* Calculate UDP/IP checksum */ |
| 680 | TD0_IP_CS = (1 << 18), /* Calculate IP checksum */ |
| 681 | }; |
| 682 | |
| 683 | /* 8102e, 8168c and beyond. */ |
| 684 | enum rtl_tx_desc_bit_1 { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 685 | /* First doubleword. */ |
| 686 | TD1_GTSENV4 = (1 << 26), /* Giant Send for IPv4 */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 687 | TD1_GTSENV6 = (1 << 25), /* Giant Send for IPv6 */ |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 688 | #define GTTCPHO_SHIFT 18 |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 689 | #define GTTCPHO_MAX 0x7fU |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 690 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 691 | /* Second doubleword. */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 692 | #define TCPHO_SHIFT 18 |
| 693 | #define TCPHO_MAX 0x3ffU |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 694 | #define TD1_MSS_SHIFT 18 /* MSS position (11 bits) */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 695 | TD1_IPv6_CS = (1 << 28), /* Calculate IPv6 checksum */ |
| 696 | TD1_IPv4_CS = (1 << 29), /* Calculate IPv4 checksum */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 697 | TD1_TCP_CS = (1 << 30), /* Calculate TCP/IP checksum */ |
| 698 | TD1_UDP_CS = (1 << 31), /* Calculate UDP/IP checksum */ |
| 699 | }; |
| 700 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 701 | enum rtl_rx_desc_bit { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | /* Rx private */ |
| 703 | PID1 = (1 << 18), /* Protocol ID bit 1/2 */ |
Zhu Yanjun | 9b60047 | 2017-01-05 02:54:27 -0500 | [diff] [blame] | 704 | PID0 = (1 << 17), /* Protocol ID bit 0/2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | |
| 706 | #define RxProtoUDP (PID1) |
| 707 | #define RxProtoTCP (PID0) |
| 708 | #define RxProtoIP (PID1 | PID0) |
| 709 | #define RxProtoMask RxProtoIP |
| 710 | |
| 711 | IPFail = (1 << 16), /* IP checksum failed */ |
| 712 | UDPFail = (1 << 15), /* UDP/IP checksum failed */ |
| 713 | TCPFail = (1 << 14), /* TCP/IP checksum failed */ |
| 714 | RxVlanTag = (1 << 16), /* VLAN tag available */ |
| 715 | }; |
| 716 | |
| 717 | #define RsvdMask 0x3fffc000 |
| 718 | |
| 719 | struct TxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 720 | __le32 opts1; |
| 721 | __le32 opts2; |
| 722 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 | }; |
| 724 | |
| 725 | struct RxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 726 | __le32 opts1; |
| 727 | __le32 opts2; |
| 728 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | }; |
| 730 | |
| 731 | struct ring_info { |
| 732 | struct sk_buff *skb; |
| 733 | u32 len; |
| 734 | u8 __pad[sizeof(void *) - sizeof(u32)]; |
| 735 | }; |
| 736 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 737 | struct rtl8169_counters { |
| 738 | __le64 tx_packets; |
| 739 | __le64 rx_packets; |
| 740 | __le64 tx_errors; |
| 741 | __le32 rx_errors; |
| 742 | __le16 rx_missed; |
| 743 | __le16 align_errors; |
| 744 | __le32 tx_one_collision; |
| 745 | __le32 tx_multi_collision; |
| 746 | __le64 rx_unicast; |
| 747 | __le64 rx_broadcast; |
| 748 | __le32 rx_multicast; |
| 749 | __le16 tx_aborted; |
| 750 | __le16 tx_underun; |
| 751 | }; |
| 752 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 753 | struct rtl8169_tc_offsets { |
| 754 | bool inited; |
| 755 | __le64 tx_errors; |
| 756 | __le32 tx_multi_collision; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 757 | __le16 tx_aborted; |
| 758 | }; |
| 759 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 760 | enum rtl_flag { |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 761 | RTL_FLAG_TASK_ENABLED, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 762 | RTL_FLAG_TASK_SLOW_PENDING, |
| 763 | RTL_FLAG_TASK_RESET_PENDING, |
| 764 | RTL_FLAG_TASK_PHY_PENDING, |
| 765 | RTL_FLAG_MAX |
| 766 | }; |
| 767 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 768 | struct rtl8169_stats { |
| 769 | u64 packets; |
| 770 | u64 bytes; |
| 771 | struct u64_stats_sync syncp; |
| 772 | }; |
| 773 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | struct rtl8169_private { |
| 775 | void __iomem *mmio_addr; /* memory map physical address */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 776 | struct pci_dev *pci_dev; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 777 | struct net_device *dev; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 778 | struct napi_struct napi; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 779 | u32 msg_enable; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 780 | u16 txd_version; |
| 781 | u16 mac_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */ |
| 783 | 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] | 784 | u32 dirty_tx; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 785 | struct rtl8169_stats rx_stats; |
| 786 | struct rtl8169_stats tx_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */ |
| 788 | struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */ |
| 789 | dma_addr_t TxPhyAddr; |
| 790 | dma_addr_t RxPhyAddr; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 791 | void *Rx_databuff[NUM_RX_DESC]; /* Rx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | struct timer_list timer; |
| 794 | u16 cp_cmd; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 795 | |
| 796 | u16 event_slow; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 797 | const struct rtl_coalesce_info *coalesce_info; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 798 | |
| 799 | struct mdio_ops { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 800 | void (*write)(struct rtl8169_private *, int, int); |
| 801 | int (*read)(struct rtl8169_private *, int); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 802 | } mdio_ops; |
| 803 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 804 | struct pll_power_ops { |
| 805 | void (*down)(struct rtl8169_private *); |
| 806 | void (*up)(struct rtl8169_private *); |
| 807 | } pll_power_ops; |
| 808 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 809 | struct jumbo_ops { |
| 810 | void (*enable)(struct rtl8169_private *); |
| 811 | void (*disable)(struct rtl8169_private *); |
| 812 | } jumbo_ops; |
| 813 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 814 | struct csi_ops { |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 815 | void (*write)(struct rtl8169_private *, int, int); |
| 816 | u32 (*read)(struct rtl8169_private *, int); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 817 | } csi_ops; |
| 818 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 819 | 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] | 820 | int (*get_link_ksettings)(struct net_device *, |
| 821 | struct ethtool_link_ksettings *); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 822 | void (*phy_reset_enable)(struct rtl8169_private *tp); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 823 | void (*hw_start)(struct net_device *); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 824 | unsigned int (*phy_reset_pending)(struct rtl8169_private *tp); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 825 | unsigned int (*link_ok)(struct rtl8169_private *tp); |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 826 | 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] | 827 | bool (*tso_csum)(struct rtl8169_private *, struct sk_buff *, u32 *); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 828 | |
| 829 | struct { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 830 | DECLARE_BITMAP(flags, RTL_FLAG_MAX); |
| 831 | struct mutex mutex; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 832 | struct work_struct work; |
| 833 | } wk; |
| 834 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 835 | struct mii_if_info mii; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 836 | dma_addr_t counters_phys_addr; |
| 837 | struct rtl8169_counters *counters; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 838 | struct rtl8169_tc_offsets tc_offset; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 839 | u32 saved_wolopts; |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 840 | u32 opts1_mask; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 841 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 842 | struct rtl_fw { |
| 843 | const struct firmware *fw; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 844 | |
| 845 | #define RTL_VER_SIZE 32 |
| 846 | |
| 847 | char version[RTL_VER_SIZE]; |
| 848 | |
| 849 | struct rtl_fw_phy_action { |
| 850 | __le32 *code; |
| 851 | size_t size; |
| 852 | } phy_action; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 853 | } *rtl_fw; |
Phil Carmody | 497888c | 2011-07-14 15:07:13 +0300 | [diff] [blame] | 854 | #define RTL_FIRMWARE_UNKNOWN ERR_PTR(-EAGAIN) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 855 | |
| 856 | u32 ocp_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | }; |
| 858 | |
Ralf Baechle | 979b6c1 | 2005-06-13 14:30:40 -0700 | [diff] [blame] | 859 | MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | module_param(use_dac, int, 0); |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 862 | 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] | 863 | module_param_named(debug, debug.msg_enable, int, 0); |
| 864 | MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | MODULE_LICENSE("GPL"); |
| 866 | MODULE_VERSION(RTL8169_VERSION); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 867 | MODULE_FIRMWARE(FIRMWARE_8168D_1); |
| 868 | MODULE_FIRMWARE(FIRMWARE_8168D_2); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 869 | MODULE_FIRMWARE(FIRMWARE_8168E_1); |
| 870 | MODULE_FIRMWARE(FIRMWARE_8168E_2); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 871 | MODULE_FIRMWARE(FIRMWARE_8168E_3); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 872 | MODULE_FIRMWARE(FIRMWARE_8105E_1); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 873 | MODULE_FIRMWARE(FIRMWARE_8168F_1); |
| 874 | MODULE_FIRMWARE(FIRMWARE_8168F_2); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 875 | MODULE_FIRMWARE(FIRMWARE_8402_1); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 876 | MODULE_FIRMWARE(FIRMWARE_8411_1); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 877 | MODULE_FIRMWARE(FIRMWARE_8411_2); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 878 | MODULE_FIRMWARE(FIRMWARE_8106E_1); |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 879 | MODULE_FIRMWARE(FIRMWARE_8106E_2); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 880 | MODULE_FIRMWARE(FIRMWARE_8168G_2); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 881 | MODULE_FIRMWARE(FIRMWARE_8168G_3); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 882 | MODULE_FIRMWARE(FIRMWARE_8168H_1); |
| 883 | MODULE_FIRMWARE(FIRMWARE_8168H_2); |
Francois Romieu | a3bf5c4 | 2014-08-26 22:40:38 +0200 | [diff] [blame] | 884 | MODULE_FIRMWARE(FIRMWARE_8107E_1); |
| 885 | MODULE_FIRMWARE(FIRMWARE_8107E_2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 887 | static inline struct device *tp_to_dev(struct rtl8169_private *tp) |
| 888 | { |
| 889 | return &tp->pci_dev->dev; |
| 890 | } |
| 891 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 892 | static void rtl_lock_work(struct rtl8169_private *tp) |
| 893 | { |
| 894 | mutex_lock(&tp->wk.mutex); |
| 895 | } |
| 896 | |
| 897 | static void rtl_unlock_work(struct rtl8169_private *tp) |
| 898 | { |
| 899 | mutex_unlock(&tp->wk.mutex); |
| 900 | } |
| 901 | |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 902 | static void rtl_tx_performance_tweak(struct rtl8169_private *tp, u16 force) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 903 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 904 | pcie_capability_clear_and_set_word(tp->pci_dev, PCI_EXP_DEVCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 905 | PCI_EXP_DEVCTL_READRQ, force); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 906 | } |
| 907 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 908 | struct rtl_cond { |
| 909 | bool (*check)(struct rtl8169_private *); |
| 910 | const char *msg; |
| 911 | }; |
| 912 | |
| 913 | static void rtl_udelay(unsigned int d) |
| 914 | { |
| 915 | udelay(d); |
| 916 | } |
| 917 | |
| 918 | static bool rtl_loop_wait(struct rtl8169_private *tp, const struct rtl_cond *c, |
| 919 | void (*delay)(unsigned int), unsigned int d, int n, |
| 920 | bool high) |
| 921 | { |
| 922 | int i; |
| 923 | |
| 924 | for (i = 0; i < n; i++) { |
| 925 | delay(d); |
| 926 | if (c->check(tp) == high) |
| 927 | return true; |
| 928 | } |
Francois Romieu | 82e316e | 2012-07-11 23:39:51 +0200 | [diff] [blame] | 929 | netif_err(tp, drv, tp->dev, "%s == %d (loop: %d, delay: %d).\n", |
| 930 | c->msg, !high, n, d); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 931 | return false; |
| 932 | } |
| 933 | |
| 934 | static bool rtl_udelay_loop_wait_high(struct rtl8169_private *tp, |
| 935 | const struct rtl_cond *c, |
| 936 | unsigned int d, int n) |
| 937 | { |
| 938 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, true); |
| 939 | } |
| 940 | |
| 941 | static bool rtl_udelay_loop_wait_low(struct rtl8169_private *tp, |
| 942 | const struct rtl_cond *c, |
| 943 | unsigned int d, int n) |
| 944 | { |
| 945 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, false); |
| 946 | } |
| 947 | |
| 948 | static bool rtl_msleep_loop_wait_high(struct rtl8169_private *tp, |
| 949 | const struct rtl_cond *c, |
| 950 | unsigned int d, int n) |
| 951 | { |
| 952 | return rtl_loop_wait(tp, c, msleep, d, n, true); |
| 953 | } |
| 954 | |
| 955 | static bool rtl_msleep_loop_wait_low(struct rtl8169_private *tp, |
| 956 | const struct rtl_cond *c, |
| 957 | unsigned int d, int n) |
| 958 | { |
| 959 | return rtl_loop_wait(tp, c, msleep, d, n, false); |
| 960 | } |
| 961 | |
| 962 | #define DECLARE_RTL_COND(name) \ |
| 963 | static bool name ## _check(struct rtl8169_private *); \ |
| 964 | \ |
| 965 | static const struct rtl_cond name = { \ |
| 966 | .check = name ## _check, \ |
| 967 | .msg = #name \ |
| 968 | }; \ |
| 969 | \ |
| 970 | static bool name ## _check(struct rtl8169_private *tp) |
| 971 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 972 | static bool rtl_ocp_reg_failure(struct rtl8169_private *tp, u32 reg) |
| 973 | { |
| 974 | if (reg & 0xffff0001) { |
| 975 | netif_err(tp, drv, tp->dev, "Invalid ocp reg %x!\n", reg); |
| 976 | return true; |
| 977 | } |
| 978 | return false; |
| 979 | } |
| 980 | |
| 981 | DECLARE_RTL_COND(rtl_ocp_gphy_cond) |
| 982 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 983 | return RTL_R32(tp, GPHY_OCP) & OCPAR_FLAG; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | static void r8168_phy_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 987 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 988 | if (rtl_ocp_reg_failure(tp, reg)) |
| 989 | return; |
| 990 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 991 | RTL_W32(tp, GPHY_OCP, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 992 | |
| 993 | rtl_udelay_loop_wait_low(tp, &rtl_ocp_gphy_cond, 25, 10); |
| 994 | } |
| 995 | |
| 996 | static u16 r8168_phy_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 997 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 998 | if (rtl_ocp_reg_failure(tp, reg)) |
| 999 | return 0; |
| 1000 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1001 | RTL_W32(tp, GPHY_OCP, reg << 15); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1002 | |
| 1003 | 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] | 1004 | (RTL_R32(tp, GPHY_OCP) & 0xffff) : ~0; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1005 | } |
| 1006 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1007 | static void r8168_mac_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 1008 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1009 | if (rtl_ocp_reg_failure(tp, reg)) |
| 1010 | return; |
| 1011 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1012 | RTL_W32(tp, OCPDR, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1013 | } |
| 1014 | |
| 1015 | static u16 r8168_mac_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 1016 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1017 | if (rtl_ocp_reg_failure(tp, reg)) |
| 1018 | return 0; |
| 1019 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1020 | RTL_W32(tp, OCPDR, reg << 15); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1021 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1022 | return RTL_R32(tp, OCPDR); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | #define OCP_STD_PHY_BASE 0xa400 |
| 1026 | |
| 1027 | static void r8168g_mdio_write(struct rtl8169_private *tp, int reg, int value) |
| 1028 | { |
| 1029 | if (reg == 0x1f) { |
| 1030 | tp->ocp_base = value ? value << 4 : OCP_STD_PHY_BASE; |
| 1031 | return; |
| 1032 | } |
| 1033 | |
| 1034 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 1035 | reg -= 0x10; |
| 1036 | |
| 1037 | r8168_phy_ocp_write(tp, tp->ocp_base + reg * 2, value); |
| 1038 | } |
| 1039 | |
| 1040 | static int r8168g_mdio_read(struct rtl8169_private *tp, int reg) |
| 1041 | { |
| 1042 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 1043 | reg -= 0x10; |
| 1044 | |
| 1045 | return r8168_phy_ocp_read(tp, tp->ocp_base + reg * 2); |
| 1046 | } |
| 1047 | |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 1048 | static void mac_mcu_write(struct rtl8169_private *tp, int reg, int value) |
| 1049 | { |
| 1050 | if (reg == 0x1f) { |
| 1051 | tp->ocp_base = value << 4; |
| 1052 | return; |
| 1053 | } |
| 1054 | |
| 1055 | r8168_mac_ocp_write(tp, tp->ocp_base + reg, value); |
| 1056 | } |
| 1057 | |
| 1058 | static int mac_mcu_read(struct rtl8169_private *tp, int reg) |
| 1059 | { |
| 1060 | return r8168_mac_ocp_read(tp, tp->ocp_base + reg); |
| 1061 | } |
| 1062 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1063 | DECLARE_RTL_COND(rtl_phyar_cond) |
| 1064 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1065 | return RTL_R32(tp, PHYAR) & 0x80000000; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1066 | } |
| 1067 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1068 | 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] | 1069 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1070 | RTL_W32(tp, PHYAR, 0x80000000 | (reg & 0x1f) << 16 | (value & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1072 | rtl_udelay_loop_wait_low(tp, &rtl_phyar_cond, 25, 20); |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 1073 | /* |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 1074 | * According to hardware specs a 20us delay is required after write |
| 1075 | * complete indication, but before sending next command. |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 1076 | */ |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 1077 | udelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1078 | } |
| 1079 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1080 | static int r8169_mdio_read(struct rtl8169_private *tp, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1081 | { |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1082 | int value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1083 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1084 | RTL_W32(tp, PHYAR, 0x0 | (reg & 0x1f) << 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1085 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1086 | value = rtl_udelay_loop_wait_high(tp, &rtl_phyar_cond, 25, 20) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1087 | RTL_R32(tp, PHYAR) & 0xffff : ~0; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1088 | |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 1089 | /* |
| 1090 | * According to hardware specs a 20us delay is required after read |
| 1091 | * complete indication, but before sending next command. |
| 1092 | */ |
| 1093 | udelay(20); |
| 1094 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | return value; |
| 1096 | } |
| 1097 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1098 | DECLARE_RTL_COND(rtl_ocpar_cond) |
| 1099 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1100 | return RTL_R32(tp, OCPAR) & OCPAR_FLAG; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1101 | } |
| 1102 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1103 | 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] | 1104 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1105 | RTL_W32(tp, OCPDR, data | ((reg & OCPDR_REG_MASK) << OCPDR_GPHY_REG_SHIFT)); |
| 1106 | RTL_W32(tp, OCPAR, OCPAR_GPHY_WRITE_CMD); |
| 1107 | RTL_W32(tp, EPHY_RXER_NUM, 0); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1108 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1109 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 1000, 100); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1112 | 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] | 1113 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1114 | r8168dp_1_mdio_access(tp, reg, |
| 1115 | OCPDR_WRITE_CMD | (value & OCPDR_DATA_MASK)); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1118 | 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] | 1119 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1120 | r8168dp_1_mdio_access(tp, reg, OCPDR_READ_CMD); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1121 | |
| 1122 | mdelay(1); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1123 | RTL_W32(tp, OCPAR, OCPAR_GPHY_READ_CMD); |
| 1124 | RTL_W32(tp, EPHY_RXER_NUM, 0); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1125 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1126 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 1000, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1127 | RTL_R32(tp, OCPDR) & OCPDR_DATA_MASK : ~0; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1128 | } |
| 1129 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1130 | #define R8168DP_1_MDIO_ACCESS_BIT 0x00020000 |
| 1131 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1132 | static void r8168dp_2_mdio_start(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1133 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1134 | 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] | 1135 | } |
| 1136 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1137 | static void r8168dp_2_mdio_stop(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1138 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1139 | 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] | 1140 | } |
| 1141 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1142 | 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] | 1143 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1144 | r8168dp_2_mdio_start(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1145 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1146 | r8169_mdio_write(tp, reg, value); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1147 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1148 | r8168dp_2_mdio_stop(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1151 | 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] | 1152 | { |
| 1153 | int value; |
| 1154 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1155 | r8168dp_2_mdio_start(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1156 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1157 | value = r8169_mdio_read(tp, reg); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1158 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1159 | r8168dp_2_mdio_stop(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1160 | |
| 1161 | return value; |
| 1162 | } |
| 1163 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1164 | static void rtl_writephy(struct rtl8169_private *tp, int location, u32 val) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1165 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1166 | tp->mdio_ops.write(tp, location, val); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1167 | } |
| 1168 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1169 | static int rtl_readphy(struct rtl8169_private *tp, int location) |
| 1170 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1171 | return tp->mdio_ops.read(tp, location); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | static void rtl_patchphy(struct rtl8169_private *tp, int reg_addr, int value) |
| 1175 | { |
| 1176 | rtl_writephy(tp, reg_addr, rtl_readphy(tp, reg_addr) | value); |
| 1177 | } |
| 1178 | |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1179 | 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] | 1180 | { |
| 1181 | int val; |
| 1182 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1183 | val = rtl_readphy(tp, reg_addr); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1184 | rtl_writephy(tp, reg_addr, (val & ~m) | p); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1185 | } |
| 1186 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1187 | static void rtl_mdio_write(struct net_device *dev, int phy_id, int location, |
| 1188 | int val) |
| 1189 | { |
| 1190 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1191 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1192 | rtl_writephy(tp, location, val); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1193 | } |
| 1194 | |
| 1195 | static int rtl_mdio_read(struct net_device *dev, int phy_id, int location) |
| 1196 | { |
| 1197 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1198 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1199 | return rtl_readphy(tp, location); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1200 | } |
| 1201 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1202 | DECLARE_RTL_COND(rtl_ephyar_cond) |
| 1203 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1204 | return RTL_R32(tp, EPHYAR) & EPHYAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1205 | } |
| 1206 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1207 | 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] | 1208 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1209 | RTL_W32(tp, EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) | |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1210 | (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
| 1211 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1212 | rtl_udelay_loop_wait_low(tp, &rtl_ephyar_cond, 10, 100); |
| 1213 | |
| 1214 | udelay(10); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1215 | } |
| 1216 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1217 | static u16 rtl_ephy_read(struct rtl8169_private *tp, int reg_addr) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1218 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1219 | RTL_W32(tp, EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1220 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1221 | return rtl_udelay_loop_wait_high(tp, &rtl_ephyar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1222 | RTL_R32(tp, EPHYAR) & EPHYAR_DATA_MASK : ~0; |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1223 | } |
| 1224 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1225 | DECLARE_RTL_COND(rtl_eriar_cond) |
| 1226 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1227 | return RTL_R32(tp, ERIAR) & ERIAR_FLAG; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1228 | } |
| 1229 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1230 | static void rtl_eri_write(struct rtl8169_private *tp, int addr, u32 mask, |
| 1231 | u32 val, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1232 | { |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1233 | BUG_ON((addr & 3) || (mask == 0)); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1234 | RTL_W32(tp, ERIDR, val); |
| 1235 | RTL_W32(tp, ERIAR, ERIAR_WRITE_CMD | type | mask | addr); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1236 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1237 | rtl_udelay_loop_wait_low(tp, &rtl_eriar_cond, 100, 100); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1238 | } |
| 1239 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1240 | 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] | 1241 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1242 | RTL_W32(tp, ERIAR, ERIAR_READ_CMD | type | ERIAR_MASK_1111 | addr); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1243 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1244 | return rtl_udelay_loop_wait_high(tp, &rtl_eriar_cond, 100, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1245 | RTL_R32(tp, ERIDR) : ~0; |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1246 | } |
| 1247 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1248 | 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] | 1249 | u32 m, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1250 | { |
| 1251 | u32 val; |
| 1252 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1253 | val = rtl_eri_read(tp, addr, type); |
| 1254 | rtl_eri_write(tp, addr, mask, (val & ~m) | p, type); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1255 | } |
| 1256 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1257 | static u32 r8168dp_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1258 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1259 | RTL_W32(tp, OCPAR, ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1260 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 100, 20) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1261 | RTL_R32(tp, OCPDR) : ~0; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | static u32 r8168ep_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1265 | { |
| 1266 | return rtl_eri_read(tp, reg, ERIAR_OOB); |
| 1267 | } |
| 1268 | |
| 1269 | static u32 ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1270 | { |
| 1271 | switch (tp->mac_version) { |
| 1272 | case RTL_GIGA_MAC_VER_27: |
| 1273 | case RTL_GIGA_MAC_VER_28: |
| 1274 | case RTL_GIGA_MAC_VER_31: |
| 1275 | return r8168dp_ocp_read(tp, mask, reg); |
| 1276 | case RTL_GIGA_MAC_VER_49: |
| 1277 | case RTL_GIGA_MAC_VER_50: |
| 1278 | case RTL_GIGA_MAC_VER_51: |
| 1279 | return r8168ep_ocp_read(tp, mask, reg); |
| 1280 | default: |
| 1281 | BUG(); |
| 1282 | return ~0; |
| 1283 | } |
| 1284 | } |
| 1285 | |
| 1286 | static void r8168dp_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, |
| 1287 | u32 data) |
| 1288 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1289 | RTL_W32(tp, OCPDR, data); |
| 1290 | 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] | 1291 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 100, 20); |
| 1292 | } |
| 1293 | |
| 1294 | static void r8168ep_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, |
| 1295 | u32 data) |
| 1296 | { |
| 1297 | rtl_eri_write(tp, reg, ((u32)mask & 0x0f) << ERIAR_MASK_SHIFT, |
| 1298 | data, ERIAR_OOB); |
| 1299 | } |
| 1300 | |
| 1301 | static void ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, u32 data) |
| 1302 | { |
| 1303 | switch (tp->mac_version) { |
| 1304 | case RTL_GIGA_MAC_VER_27: |
| 1305 | case RTL_GIGA_MAC_VER_28: |
| 1306 | case RTL_GIGA_MAC_VER_31: |
| 1307 | r8168dp_ocp_write(tp, mask, reg, data); |
| 1308 | break; |
| 1309 | case RTL_GIGA_MAC_VER_49: |
| 1310 | case RTL_GIGA_MAC_VER_50: |
| 1311 | case RTL_GIGA_MAC_VER_51: |
| 1312 | r8168ep_ocp_write(tp, mask, reg, data); |
| 1313 | break; |
| 1314 | default: |
| 1315 | BUG(); |
| 1316 | break; |
| 1317 | } |
| 1318 | } |
| 1319 | |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1320 | static void rtl8168_oob_notify(struct rtl8169_private *tp, u8 cmd) |
| 1321 | { |
| 1322 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_0001, cmd, ERIAR_EXGMAC); |
| 1323 | |
| 1324 | ocp_write(tp, 0x1, 0x30, 0x00000001); |
| 1325 | } |
| 1326 | |
| 1327 | #define OOB_CMD_RESET 0x00 |
| 1328 | #define OOB_CMD_DRIVER_START 0x05 |
| 1329 | #define OOB_CMD_DRIVER_STOP 0x06 |
| 1330 | |
| 1331 | static u16 rtl8168_get_ocp_reg(struct rtl8169_private *tp) |
| 1332 | { |
| 1333 | return (tp->mac_version == RTL_GIGA_MAC_VER_31) ? 0xb8 : 0x10; |
| 1334 | } |
| 1335 | |
| 1336 | DECLARE_RTL_COND(rtl_ocp_read_cond) |
| 1337 | { |
| 1338 | u16 reg; |
| 1339 | |
| 1340 | reg = rtl8168_get_ocp_reg(tp); |
| 1341 | |
| 1342 | return ocp_read(tp, 0x0f, reg) & 0x00000800; |
| 1343 | } |
| 1344 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1345 | DECLARE_RTL_COND(rtl_ep_ocp_read_cond) |
| 1346 | { |
| 1347 | return ocp_read(tp, 0x0f, 0x124) & 0x00000001; |
| 1348 | } |
| 1349 | |
| 1350 | DECLARE_RTL_COND(rtl_ocp_tx_cond) |
| 1351 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1352 | return RTL_R8(tp, IBISR0) & 0x20; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1353 | } |
| 1354 | |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1355 | static void rtl8168ep_stop_cmac(struct rtl8169_private *tp) |
| 1356 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1357 | RTL_W8(tp, IBCR2, RTL_R8(tp, IBCR2) & ~0x01); |
Chunhao Lin | 086ca23 | 2018-01-31 01:32:36 +0800 | [diff] [blame] | 1358 | rtl_msleep_loop_wait_high(tp, &rtl_ocp_tx_cond, 50, 2000); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1359 | RTL_W8(tp, IBISR0, RTL_R8(tp, IBISR0) | 0x20); |
| 1360 | RTL_W8(tp, IBCR0, RTL_R8(tp, IBCR0) & ~0x01); |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1361 | } |
| 1362 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1363 | static void rtl8168dp_driver_start(struct rtl8169_private *tp) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1364 | { |
| 1365 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_START); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1366 | rtl_msleep_loop_wait_high(tp, &rtl_ocp_read_cond, 10, 10); |
| 1367 | } |
| 1368 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1369 | static void rtl8168ep_driver_start(struct rtl8169_private *tp) |
| 1370 | { |
| 1371 | ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_START); |
| 1372 | ocp_write(tp, 0x01, 0x30, ocp_read(tp, 0x01, 0x30) | 0x01); |
| 1373 | rtl_msleep_loop_wait_high(tp, &rtl_ep_ocp_read_cond, 10, 10); |
| 1374 | } |
| 1375 | |
| 1376 | static void rtl8168_driver_start(struct rtl8169_private *tp) |
| 1377 | { |
| 1378 | switch (tp->mac_version) { |
| 1379 | case RTL_GIGA_MAC_VER_27: |
| 1380 | case RTL_GIGA_MAC_VER_28: |
| 1381 | case RTL_GIGA_MAC_VER_31: |
| 1382 | rtl8168dp_driver_start(tp); |
| 1383 | break; |
| 1384 | case RTL_GIGA_MAC_VER_49: |
| 1385 | case RTL_GIGA_MAC_VER_50: |
| 1386 | case RTL_GIGA_MAC_VER_51: |
| 1387 | rtl8168ep_driver_start(tp); |
| 1388 | break; |
| 1389 | default: |
| 1390 | BUG(); |
| 1391 | break; |
| 1392 | } |
| 1393 | } |
| 1394 | |
| 1395 | static void rtl8168dp_driver_stop(struct rtl8169_private *tp) |
| 1396 | { |
| 1397 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_STOP); |
| 1398 | rtl_msleep_loop_wait_low(tp, &rtl_ocp_read_cond, 10, 10); |
| 1399 | } |
| 1400 | |
| 1401 | static void rtl8168ep_driver_stop(struct rtl8169_private *tp) |
| 1402 | { |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1403 | rtl8168ep_stop_cmac(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1404 | ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_STOP); |
| 1405 | ocp_write(tp, 0x01, 0x30, ocp_read(tp, 0x01, 0x30) | 0x01); |
| 1406 | rtl_msleep_loop_wait_low(tp, &rtl_ep_ocp_read_cond, 10, 10); |
| 1407 | } |
| 1408 | |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1409 | static void rtl8168_driver_stop(struct rtl8169_private *tp) |
| 1410 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1411 | switch (tp->mac_version) { |
| 1412 | case RTL_GIGA_MAC_VER_27: |
| 1413 | case RTL_GIGA_MAC_VER_28: |
| 1414 | case RTL_GIGA_MAC_VER_31: |
| 1415 | rtl8168dp_driver_stop(tp); |
| 1416 | break; |
| 1417 | case RTL_GIGA_MAC_VER_49: |
| 1418 | case RTL_GIGA_MAC_VER_50: |
| 1419 | case RTL_GIGA_MAC_VER_51: |
| 1420 | rtl8168ep_driver_stop(tp); |
| 1421 | break; |
| 1422 | default: |
| 1423 | BUG(); |
| 1424 | break; |
| 1425 | } |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1426 | } |
| 1427 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1428 | static bool r8168dp_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1429 | { |
| 1430 | u16 reg = rtl8168_get_ocp_reg(tp); |
| 1431 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1432 | return !!(ocp_read(tp, 0x0f, reg) & 0x00008000); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1433 | } |
| 1434 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1435 | static bool r8168ep_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1436 | { |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1437 | return !!(ocp_read(tp, 0x0f, 0x128) & 0x00000001); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1438 | } |
| 1439 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1440 | static bool r8168_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1441 | { |
| 1442 | switch (tp->mac_version) { |
| 1443 | case RTL_GIGA_MAC_VER_27: |
| 1444 | case RTL_GIGA_MAC_VER_28: |
| 1445 | case RTL_GIGA_MAC_VER_31: |
| 1446 | return r8168dp_check_dash(tp); |
| 1447 | case RTL_GIGA_MAC_VER_49: |
| 1448 | case RTL_GIGA_MAC_VER_50: |
| 1449 | case RTL_GIGA_MAC_VER_51: |
| 1450 | return r8168ep_check_dash(tp); |
| 1451 | default: |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 1452 | return false; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1453 | } |
| 1454 | } |
| 1455 | |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1456 | struct exgmac_reg { |
| 1457 | u16 addr; |
| 1458 | u16 mask; |
| 1459 | u32 val; |
| 1460 | }; |
| 1461 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1462 | static void rtl_write_exgmac_batch(struct rtl8169_private *tp, |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1463 | const struct exgmac_reg *r, int len) |
| 1464 | { |
| 1465 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1466 | 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] | 1467 | r++; |
| 1468 | } |
| 1469 | } |
| 1470 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1471 | DECLARE_RTL_COND(rtl_efusear_cond) |
| 1472 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1473 | return RTL_R32(tp, EFUSEAR) & EFUSEAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1474 | } |
| 1475 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1476 | 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] | 1477 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1478 | 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] | 1479 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1480 | return rtl_udelay_loop_wait_high(tp, &rtl_efusear_cond, 100, 300) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1481 | RTL_R32(tp, EFUSEAR) & EFUSEAR_DATA_MASK : ~0; |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1482 | } |
| 1483 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1484 | static u16 rtl_get_events(struct rtl8169_private *tp) |
| 1485 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1486 | return RTL_R16(tp, IntrStatus); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1487 | } |
| 1488 | |
| 1489 | static void rtl_ack_events(struct rtl8169_private *tp, u16 bits) |
| 1490 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1491 | RTL_W16(tp, IntrStatus, bits); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1492 | mmiowb(); |
| 1493 | } |
| 1494 | |
| 1495 | static void rtl_irq_disable(struct rtl8169_private *tp) |
| 1496 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1497 | RTL_W16(tp, IntrMask, 0); |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1498 | mmiowb(); |
| 1499 | } |
| 1500 | |
Francois Romieu | 3e990ff | 2012-01-26 12:50:01 +0100 | [diff] [blame] | 1501 | static void rtl_irq_enable(struct rtl8169_private *tp, u16 bits) |
| 1502 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1503 | RTL_W16(tp, IntrMask, bits); |
Francois Romieu | 3e990ff | 2012-01-26 12:50:01 +0100 | [diff] [blame] | 1504 | } |
| 1505 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1506 | #define RTL_EVENT_NAPI_RX (RxOK | RxErr) |
| 1507 | #define RTL_EVENT_NAPI_TX (TxOK | TxErr) |
| 1508 | #define RTL_EVENT_NAPI (RTL_EVENT_NAPI_RX | RTL_EVENT_NAPI_TX) |
| 1509 | |
| 1510 | static void rtl_irq_enable_all(struct rtl8169_private *tp) |
| 1511 | { |
| 1512 | rtl_irq_enable(tp, RTL_EVENT_NAPI | tp->event_slow); |
| 1513 | } |
| 1514 | |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 1515 | static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | { |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1517 | rtl_irq_disable(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1518 | rtl_ack_events(tp, RTL_EVENT_NAPI | tp->event_slow); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1519 | RTL_R8(tp, ChipCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | } |
| 1521 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1522 | static unsigned int rtl8169_tbi_reset_pending(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1524 | return RTL_R32(tp, TBICSR) & TBIReset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | } |
| 1526 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1527 | static unsigned int rtl8169_xmii_reset_pending(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1529 | return rtl_readphy(tp, MII_BMCR) & BMCR_RESET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1530 | } |
| 1531 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1532 | static unsigned int rtl8169_tbi_link_ok(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1534 | return RTL_R32(tp, TBICSR) & TBILinkOk; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | } |
| 1536 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1537 | static unsigned int rtl8169_xmii_link_ok(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1538 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1539 | return RTL_R8(tp, PHYstatus) & LinkStatus; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | } |
| 1541 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1542 | static void rtl8169_tbi_reset_enable(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1543 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1544 | RTL_W32(tp, TBICSR, RTL_R32(tp, TBICSR) | TBIReset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1545 | } |
| 1546 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1547 | static void rtl8169_xmii_reset_enable(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | { |
| 1549 | unsigned int val; |
| 1550 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1551 | val = rtl_readphy(tp, MII_BMCR) | BMCR_RESET; |
| 1552 | rtl_writephy(tp, MII_BMCR, val & 0xffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | } |
| 1554 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1555 | static void rtl_link_chg_patch(struct rtl8169_private *tp) |
| 1556 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1557 | struct net_device *dev = tp->dev; |
| 1558 | |
| 1559 | if (!netif_running(dev)) |
| 1560 | return; |
| 1561 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 1562 | if (tp->mac_version == RTL_GIGA_MAC_VER_34 || |
| 1563 | tp->mac_version == RTL_GIGA_MAC_VER_38) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1564 | if (RTL_R8(tp, PHYstatus) & _1000bpsF) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1565 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011, |
| 1566 | ERIAR_EXGMAC); |
| 1567 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1568 | ERIAR_EXGMAC); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1569 | } else if (RTL_R8(tp, PHYstatus) & _100bps) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1570 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1571 | ERIAR_EXGMAC); |
| 1572 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1573 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1574 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1575 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1576 | ERIAR_EXGMAC); |
| 1577 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f, |
| 1578 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1579 | } |
| 1580 | /* Reset packet filter */ |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1581 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1582 | ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1583 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1584 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1585 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 1586 | tp->mac_version == RTL_GIGA_MAC_VER_36) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1587 | if (RTL_R8(tp, PHYstatus) & _1000bpsF) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1588 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011, |
| 1589 | ERIAR_EXGMAC); |
| 1590 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1591 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1592 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1593 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1594 | ERIAR_EXGMAC); |
| 1595 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f, |
| 1596 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1597 | } |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1598 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_37) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1599 | if (RTL_R8(tp, PHYstatus) & _10bps) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1600 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x4d02, |
| 1601 | ERIAR_EXGMAC); |
| 1602 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_0011, 0x0060, |
| 1603 | ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1604 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1605 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, |
| 1606 | ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1607 | } |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1608 | } |
| 1609 | } |
| 1610 | |
Heiner Kallweit | ef4d5fc | 2018-01-08 21:39:07 +0100 | [diff] [blame] | 1611 | static void rtl8169_check_link_status(struct net_device *dev, |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1612 | struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | { |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1614 | struct device *d = tp_to_dev(tp); |
| 1615 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1616 | if (tp->link_ok(tp)) { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1617 | rtl_link_chg_patch(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1618 | /* This is to cancel a scheduled suspend if there's one. */ |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1619 | pm_request_resume(d); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1620 | netif_carrier_on(dev); |
Francois Romieu | 1519e57 | 2011-02-03 12:02:36 +0100 | [diff] [blame] | 1621 | if (net_ratelimit()) |
| 1622 | netif_info(tp, ifup, dev, "link up\n"); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1623 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | netif_carrier_off(dev); |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1625 | netif_info(tp, ifdown, dev, "link down\n"); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1626 | pm_runtime_idle(d); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1627 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | } |
| 1629 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1630 | #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST) |
| 1631 | |
| 1632 | static u32 __rtl8169_get_wol(struct rtl8169_private *tp) |
| 1633 | { |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1634 | u8 options; |
| 1635 | u32 wolopts = 0; |
| 1636 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1637 | options = RTL_R8(tp, Config1); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1638 | if (!(options & PMEnable)) |
| 1639 | return 0; |
| 1640 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1641 | options = RTL_R8(tp, Config3); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1642 | if (options & LinkUp) |
| 1643 | wolopts |= WAKE_PHY; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1644 | switch (tp->mac_version) { |
Chun-Hao Lin | ac85bcd | 2014-10-01 23:17:16 +0800 | [diff] [blame] | 1645 | case RTL_GIGA_MAC_VER_34: |
| 1646 | case RTL_GIGA_MAC_VER_35: |
| 1647 | case RTL_GIGA_MAC_VER_36: |
| 1648 | case RTL_GIGA_MAC_VER_37: |
| 1649 | case RTL_GIGA_MAC_VER_38: |
| 1650 | case RTL_GIGA_MAC_VER_40: |
| 1651 | case RTL_GIGA_MAC_VER_41: |
| 1652 | case RTL_GIGA_MAC_VER_42: |
| 1653 | case RTL_GIGA_MAC_VER_43: |
| 1654 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1655 | case RTL_GIGA_MAC_VER_45: |
| 1656 | case RTL_GIGA_MAC_VER_46: |
Chun-Hao Lin | ac85bcd | 2014-10-01 23:17:16 +0800 | [diff] [blame] | 1657 | case RTL_GIGA_MAC_VER_47: |
| 1658 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1659 | case RTL_GIGA_MAC_VER_49: |
| 1660 | case RTL_GIGA_MAC_VER_50: |
| 1661 | case RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1662 | if (rtl_eri_read(tp, 0xdc, ERIAR_EXGMAC) & MagicPacket_v2) |
| 1663 | wolopts |= WAKE_MAGIC; |
| 1664 | break; |
| 1665 | default: |
| 1666 | if (options & MagicPacket) |
| 1667 | wolopts |= WAKE_MAGIC; |
| 1668 | break; |
| 1669 | } |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1670 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1671 | options = RTL_R8(tp, Config5); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1672 | if (options & UWF) |
| 1673 | wolopts |= WAKE_UCAST; |
| 1674 | if (options & BWF) |
| 1675 | wolopts |= WAKE_BCAST; |
| 1676 | if (options & MWF) |
| 1677 | wolopts |= WAKE_MCAST; |
| 1678 | |
| 1679 | return wolopts; |
| 1680 | } |
| 1681 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1682 | static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1683 | { |
| 1684 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1685 | struct device *d = tp_to_dev(tp); |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1686 | |
| 1687 | pm_runtime_get_noresume(d); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1688 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1689 | rtl_lock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1690 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1691 | wol->supported = WAKE_ANY; |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1692 | if (pm_runtime_active(d)) |
| 1693 | wol->wolopts = __rtl8169_get_wol(tp); |
| 1694 | else |
| 1695 | wol->wolopts = tp->saved_wolopts; |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1696 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1697 | rtl_unlock_work(tp); |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1698 | |
| 1699 | pm_runtime_put_noidle(d); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1700 | } |
| 1701 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1702 | static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1703 | { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1704 | unsigned int i, tmp; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 1705 | static const struct { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1706 | u32 opt; |
| 1707 | u16 reg; |
| 1708 | u8 mask; |
| 1709 | } cfg[] = { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1710 | { WAKE_PHY, Config3, LinkUp }, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1711 | { WAKE_UCAST, Config5, UWF }, |
| 1712 | { WAKE_BCAST, Config5, BWF }, |
| 1713 | { WAKE_MCAST, Config5, MWF }, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1714 | { WAKE_ANY, Config5, LanWake }, |
| 1715 | { WAKE_MAGIC, Config3, MagicPacket } |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1716 | }; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1717 | u8 options; |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1718 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1719 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1720 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1721 | switch (tp->mac_version) { |
Chun-Hao Lin | ac85bcd | 2014-10-01 23:17:16 +0800 | [diff] [blame] | 1722 | case RTL_GIGA_MAC_VER_34: |
| 1723 | case RTL_GIGA_MAC_VER_35: |
| 1724 | case RTL_GIGA_MAC_VER_36: |
| 1725 | case RTL_GIGA_MAC_VER_37: |
| 1726 | case RTL_GIGA_MAC_VER_38: |
| 1727 | case RTL_GIGA_MAC_VER_40: |
| 1728 | case RTL_GIGA_MAC_VER_41: |
| 1729 | case RTL_GIGA_MAC_VER_42: |
| 1730 | case RTL_GIGA_MAC_VER_43: |
| 1731 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1732 | case RTL_GIGA_MAC_VER_45: |
| 1733 | case RTL_GIGA_MAC_VER_46: |
Chun-Hao Lin | ac85bcd | 2014-10-01 23:17:16 +0800 | [diff] [blame] | 1734 | case RTL_GIGA_MAC_VER_47: |
| 1735 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1736 | case RTL_GIGA_MAC_VER_49: |
| 1737 | case RTL_GIGA_MAC_VER_50: |
| 1738 | case RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1739 | tmp = ARRAY_SIZE(cfg) - 1; |
| 1740 | if (wolopts & WAKE_MAGIC) |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1741 | rtl_w0w1_eri(tp, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1742 | 0x0dc, |
| 1743 | ERIAR_MASK_0100, |
| 1744 | MagicPacket_v2, |
| 1745 | 0x0000, |
| 1746 | ERIAR_EXGMAC); |
| 1747 | else |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1748 | rtl_w0w1_eri(tp, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1749 | 0x0dc, |
| 1750 | ERIAR_MASK_0100, |
| 1751 | 0x0000, |
| 1752 | MagicPacket_v2, |
| 1753 | ERIAR_EXGMAC); |
| 1754 | break; |
| 1755 | default: |
| 1756 | tmp = ARRAY_SIZE(cfg); |
| 1757 | break; |
| 1758 | } |
| 1759 | |
| 1760 | for (i = 0; i < tmp; i++) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1761 | options = RTL_R8(tp, cfg[i].reg) & ~cfg[i].mask; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1762 | if (wolopts & cfg[i].opt) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1763 | options |= cfg[i].mask; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1764 | RTL_W8(tp, cfg[i].reg, options); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1765 | } |
| 1766 | |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1767 | switch (tp->mac_version) { |
| 1768 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_17: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1769 | options = RTL_R8(tp, Config1) & ~PMEnable; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1770 | if (wolopts) |
| 1771 | options |= PMEnable; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1772 | RTL_W8(tp, Config1, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1773 | break; |
| 1774 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1775 | options = RTL_R8(tp, Config2) & ~PME_SIGNAL; |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 1776 | if (wolopts) |
| 1777 | options |= PME_SIGNAL; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1778 | RTL_W8(tp, Config2, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1779 | break; |
| 1780 | } |
| 1781 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1782 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1783 | } |
| 1784 | |
| 1785 | static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1786 | { |
| 1787 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1788 | struct device *d = tp_to_dev(tp); |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1789 | |
| 1790 | pm_runtime_get_noresume(d); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1791 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1792 | rtl_lock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1793 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1794 | if (pm_runtime_active(d)) |
| 1795 | __rtl8169_set_wol(tp, wol->wolopts); |
| 1796 | else |
| 1797 | tp->saved_wolopts = wol->wolopts; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1798 | |
| 1799 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1800 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 1801 | device_set_wakeup_enable(d, wol->wolopts); |
françois romieu | ea80907 | 2010-11-08 13:23:58 +0000 | [diff] [blame] | 1802 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1803 | pm_runtime_put_noidle(d); |
| 1804 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1805 | return 0; |
| 1806 | } |
| 1807 | |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1808 | static const char *rtl_lookup_firmware_name(struct rtl8169_private *tp) |
| 1809 | { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 1810 | return rtl_chip_infos[tp->mac_version].fw_name; |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1811 | } |
| 1812 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1813 | static void rtl8169_get_drvinfo(struct net_device *dev, |
| 1814 | struct ethtool_drvinfo *info) |
| 1815 | { |
| 1816 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 1817 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1818 | |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 1819 | strlcpy(info->driver, MODULENAME, sizeof(info->driver)); |
| 1820 | strlcpy(info->version, RTL8169_VERSION, sizeof(info->version)); |
| 1821 | 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] | 1822 | BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version)); |
Rick Jones | 8ac72d1 | 2011-11-22 14:06:26 +0000 | [diff] [blame] | 1823 | if (!IS_ERR_OR_NULL(rtl_fw)) |
| 1824 | strlcpy(info->fw_version, rtl_fw->version, |
| 1825 | sizeof(info->fw_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | static int rtl8169_get_regs_len(struct net_device *dev) |
| 1829 | { |
| 1830 | return R8169_REGS_SIZE; |
| 1831 | } |
| 1832 | |
| 1833 | static int rtl8169_set_speed_tbi(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1834 | u8 autoneg, u16 speed, u8 duplex, u32 ignored) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1835 | { |
| 1836 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | int ret = 0; |
| 1838 | u32 reg; |
| 1839 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1840 | reg = RTL_R32(tp, TBICSR); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | if ((autoneg == AUTONEG_DISABLE) && (speed == SPEED_1000) && |
| 1842 | (duplex == DUPLEX_FULL)) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1843 | RTL_W32(tp, TBICSR, reg & ~(TBINwEnable | TBINwRestart)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1844 | } else if (autoneg == AUTONEG_ENABLE) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1845 | RTL_W32(tp, TBICSR, reg | TBINwEnable | TBINwRestart); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | else { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1847 | netif_warn(tp, link, dev, |
| 1848 | "incorrect speed setting refused in TBI mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | ret = -EOPNOTSUPP; |
| 1850 | } |
| 1851 | |
| 1852 | return ret; |
| 1853 | } |
| 1854 | |
| 1855 | static int rtl8169_set_speed_xmii(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1856 | u8 autoneg, u16 speed, u8 duplex, u32 adv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | { |
| 1858 | struct rtl8169_private *tp = netdev_priv(dev); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1859 | int giga_ctrl, bmcr; |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1860 | int rc = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1861 | |
Hayes Wang | 716b50a | 2011-02-22 17:26:18 +0800 | [diff] [blame] | 1862 | rtl_writephy(tp, 0x1f, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | |
| 1864 | if (autoneg == AUTONEG_ENABLE) { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1865 | int auto_nego; |
| 1866 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1867 | auto_nego = rtl_readphy(tp, MII_ADVERTISE); |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1868 | auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL | |
| 1869 | ADVERTISE_100HALF | ADVERTISE_100FULL); |
| 1870 | |
| 1871 | if (adv & ADVERTISED_10baseT_Half) |
| 1872 | auto_nego |= ADVERTISE_10HALF; |
| 1873 | if (adv & ADVERTISED_10baseT_Full) |
| 1874 | auto_nego |= ADVERTISE_10FULL; |
| 1875 | if (adv & ADVERTISED_100baseT_Half) |
| 1876 | auto_nego |= ADVERTISE_100HALF; |
| 1877 | if (adv & ADVERTISED_100baseT_Full) |
| 1878 | auto_nego |= ADVERTISE_100FULL; |
| 1879 | |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1880 | auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 1881 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1882 | giga_ctrl = rtl_readphy(tp, MII_CTRL1000); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1883 | giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); |
| 1884 | |
| 1885 | /* The 8100e/8101e/8102e do Fast Ethernet only. */ |
Francois Romieu | 826e6cb | 2011-03-11 20:30:24 +0100 | [diff] [blame] | 1886 | if (tp->mii.supports_gmii) { |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1887 | if (adv & ADVERTISED_1000baseT_Half) |
| 1888 | giga_ctrl |= ADVERTISE_1000HALF; |
| 1889 | if (adv & ADVERTISED_1000baseT_Full) |
| 1890 | giga_ctrl |= ADVERTISE_1000FULL; |
| 1891 | } else if (adv & (ADVERTISED_1000baseT_Half | |
| 1892 | ADVERTISED_1000baseT_Full)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1893 | netif_info(tp, link, dev, |
| 1894 | "PHY does not support 1000Mbps\n"); |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1895 | goto out; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 1896 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1898 | bmcr = BMCR_ANENABLE | BMCR_ANRESTART; |
Francois Romieu | 623a159 | 2006-05-14 12:42:14 +0200 | [diff] [blame] | 1899 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1900 | rtl_writephy(tp, MII_ADVERTISE, auto_nego); |
| 1901 | rtl_writephy(tp, MII_CTRL1000, giga_ctrl); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1902 | } else { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1903 | if (speed == SPEED_10) |
| 1904 | bmcr = 0; |
| 1905 | else if (speed == SPEED_100) |
| 1906 | bmcr = BMCR_SPEED100; |
| 1907 | else |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1908 | goto out; |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1909 | |
| 1910 | if (duplex == DUPLEX_FULL) |
| 1911 | bmcr |= BMCR_FULLDPLX; |
Roger So | 2584fbc | 2007-07-31 23:52:42 +0200 | [diff] [blame] | 1912 | } |
| 1913 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1914 | rtl_writephy(tp, MII_BMCR, bmcr); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1915 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1916 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 1917 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1918 | if ((speed == SPEED_100) && (autoneg != AUTONEG_ENABLE)) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1919 | rtl_writephy(tp, 0x17, 0x2138); |
| 1920 | rtl_writephy(tp, 0x0e, 0x0260); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1921 | } else { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1922 | rtl_writephy(tp, 0x17, 0x2108); |
| 1923 | rtl_writephy(tp, 0x0e, 0x0000); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1924 | } |
| 1925 | } |
| 1926 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1927 | rc = 0; |
| 1928 | out: |
| 1929 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | static int rtl8169_set_speed(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1933 | u8 autoneg, u16 speed, u8 duplex, u32 advertising) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1934 | { |
| 1935 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1936 | int ret; |
| 1937 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1938 | ret = tp->set_speed(dev, autoneg, speed, duplex, advertising); |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1939 | if (ret < 0) |
| 1940 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1941 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1942 | if (netif_running(dev) && (autoneg == AUTONEG_ENABLE) && |
Chun-Hao Lin | c455697 | 2016-03-11 14:21:14 +0800 | [diff] [blame] | 1943 | (advertising & ADVERTISED_1000baseT_Full) && |
| 1944 | !pci_is_pcie(tp->pci_dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1945 | mod_timer(&tp->timer, jiffies + RTL8169_PHY_TIMEOUT); |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1946 | } |
| 1947 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1948 | return ret; |
| 1949 | } |
| 1950 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 1951 | static netdev_features_t rtl8169_fix_features(struct net_device *dev, |
| 1952 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1954 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1955 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 1956 | if (dev->mtu > TD_MSS_MAX) |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1957 | features &= ~NETIF_F_ALL_TSO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1958 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1959 | if (dev->mtu > JUMBO_1K && |
| 1960 | !rtl_chip_infos[tp->mac_version].jumbo_tx_csum) |
| 1961 | features &= ~NETIF_F_IP_CSUM; |
| 1962 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1963 | return features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1964 | } |
| 1965 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1966 | static void __rtl8169_set_features(struct net_device *dev, |
| 1967 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | { |
| 1969 | struct rtl8169_private *tp = netdev_priv(dev); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1970 | u32 rx_config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1971 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1972 | rx_config = RTL_R32(tp, RxConfig); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1973 | if (features & NETIF_F_RXALL) |
| 1974 | rx_config |= (AcceptErr | AcceptRunt); |
| 1975 | else |
| 1976 | rx_config &= ~(AcceptErr | AcceptRunt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1978 | RTL_W32(tp, RxConfig, rx_config); |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1979 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1980 | if (features & NETIF_F_RXCSUM) |
| 1981 | tp->cp_cmd |= RxChkSum; |
| 1982 | else |
| 1983 | tp->cp_cmd &= ~RxChkSum; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 1984 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1985 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 1986 | tp->cp_cmd |= RxVlan; |
| 1987 | else |
| 1988 | tp->cp_cmd &= ~RxVlan; |
| 1989 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1990 | tp->cp_cmd |= RTL_R16(tp, CPlusCmd) & ~(RxVlan | RxChkSum); |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1991 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 1992 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 1993 | RTL_R16(tp, CPlusCmd); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1994 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1995 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1996 | static int rtl8169_set_features(struct net_device *dev, |
| 1997 | netdev_features_t features) |
| 1998 | { |
| 1999 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2000 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 2001 | features &= NETIF_F_RXALL | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_RX; |
| 2002 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2003 | rtl_lock_work(tp); |
Dan Carpenter | 85911d7 | 2014-09-19 13:40:25 +0300 | [diff] [blame] | 2004 | if (features ^ dev->features) |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 2005 | __rtl8169_set_features(dev, features); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2006 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2007 | |
| 2008 | return 0; |
| 2009 | } |
| 2010 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2011 | |
Kirill Smelkov | 810f489 | 2012-11-10 21:11:02 +0400 | [diff] [blame] | 2012 | static inline u32 rtl8169_tx_vlan_tag(struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | { |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 2014 | return (skb_vlan_tag_present(skb)) ? |
| 2015 | TxVlanTag | swab16(skb_vlan_tag_get(skb)) : 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | } |
| 2017 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 2018 | 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] | 2019 | { |
| 2020 | u32 opts2 = le32_to_cpu(desc->opts2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 2022 | if (opts2 & RxVlanTag) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 2023 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), swab16(opts2 & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2024 | } |
| 2025 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2026 | static int rtl8169_get_link_ksettings_tbi(struct net_device *dev, |
| 2027 | struct ethtool_link_ksettings *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2028 | { |
| 2029 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | u32 status; |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2031 | u32 supported, advertising; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2033 | supported = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE; |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2035 | cmd->base.port = PORT_FIBRE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2037 | status = RTL_R32(tp, TBICSR); |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2038 | advertising = (status & TBINwEnable) ? ADVERTISED_Autoneg : 0; |
| 2039 | cmd->base.autoneg = !!(status & TBINwEnable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2041 | cmd->base.speed = SPEED_1000; |
| 2042 | cmd->base.duplex = DUPLEX_FULL; /* Always set */ |
| 2043 | |
| 2044 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, |
| 2045 | supported); |
| 2046 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, |
| 2047 | advertising); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 2048 | |
| 2049 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2050 | } |
| 2051 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2052 | static int rtl8169_get_link_ksettings_xmii(struct net_device *dev, |
| 2053 | struct ethtool_link_ksettings *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2054 | { |
| 2055 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2056 | |
yuval.shaia@oracle.com | 82c01a8 | 2017-06-04 20:22:00 +0300 | [diff] [blame] | 2057 | mii_ethtool_get_link_ksettings(&tp->mii, cmd); |
| 2058 | |
| 2059 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | } |
| 2061 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2062 | static int rtl8169_get_link_ksettings(struct net_device *dev, |
| 2063 | struct ethtool_link_ksettings *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | { |
| 2065 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 2066 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2067 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2068 | rtl_lock_work(tp); |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2069 | rc = tp->get_link_ksettings(dev, cmd); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2070 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2071 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 2072 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2073 | } |
| 2074 | |
Tobias Jakobi | 9e77d7a | 2017-11-21 16:15:57 +0100 | [diff] [blame] | 2075 | static int rtl8169_set_link_ksettings(struct net_device *dev, |
| 2076 | const struct ethtool_link_ksettings *cmd) |
| 2077 | { |
| 2078 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2079 | int rc; |
| 2080 | u32 advertising; |
| 2081 | |
| 2082 | if (!ethtool_convert_link_mode_to_legacy_u32(&advertising, |
| 2083 | cmd->link_modes.advertising)) |
| 2084 | return -EINVAL; |
| 2085 | |
| 2086 | del_timer_sync(&tp->timer); |
| 2087 | |
| 2088 | rtl_lock_work(tp); |
| 2089 | rc = rtl8169_set_speed(dev, cmd->base.autoneg, cmd->base.speed, |
| 2090 | cmd->base.duplex, advertising); |
| 2091 | rtl_unlock_work(tp); |
| 2092 | |
| 2093 | return rc; |
| 2094 | } |
| 2095 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2096 | static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 2097 | void *p) |
| 2098 | { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 2099 | struct rtl8169_private *tp = netdev_priv(dev); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 2100 | u32 __iomem *data = tp->mmio_addr; |
| 2101 | u32 *dw = p; |
| 2102 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2103 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2104 | rtl_lock_work(tp); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 2105 | for (i = 0; i < R8169_REGS_SIZE; i += 4) |
| 2106 | memcpy_fromio(dw++, data++, 4); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2107 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2108 | } |
| 2109 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 2110 | static u32 rtl8169_get_msglevel(struct net_device *dev) |
| 2111 | { |
| 2112 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2113 | |
| 2114 | return tp->msg_enable; |
| 2115 | } |
| 2116 | |
| 2117 | static void rtl8169_set_msglevel(struct net_device *dev, u32 value) |
| 2118 | { |
| 2119 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2120 | |
| 2121 | tp->msg_enable = value; |
| 2122 | } |
| 2123 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2124 | static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = { |
| 2125 | "tx_packets", |
| 2126 | "rx_packets", |
| 2127 | "tx_errors", |
| 2128 | "rx_errors", |
| 2129 | "rx_missed", |
| 2130 | "align_errors", |
| 2131 | "tx_single_collisions", |
| 2132 | "tx_multi_collisions", |
| 2133 | "unicast", |
| 2134 | "broadcast", |
| 2135 | "multicast", |
| 2136 | "tx_aborted", |
| 2137 | "tx_underrun", |
| 2138 | }; |
| 2139 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2140 | static int rtl8169_get_sset_count(struct net_device *dev, int sset) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2141 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2142 | switch (sset) { |
| 2143 | case ETH_SS_STATS: |
| 2144 | return ARRAY_SIZE(rtl8169_gstrings); |
| 2145 | default: |
| 2146 | return -EOPNOTSUPP; |
| 2147 | } |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2148 | } |
| 2149 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2150 | DECLARE_RTL_COND(rtl_counters_cond) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2151 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2152 | return RTL_R32(tp, CounterAddrLow) & (CounterReset | CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2153 | } |
| 2154 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2155 | static bool rtl8169_do_counters(struct net_device *dev, u32 counter_cmd) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2156 | { |
| 2157 | struct rtl8169_private *tp = netdev_priv(dev); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2158 | dma_addr_t paddr = tp->counters_phys_addr; |
| 2159 | u32 cmd; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2160 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2161 | RTL_W32(tp, CounterAddrHigh, (u64)paddr >> 32); |
| 2162 | RTL_R32(tp, CounterAddrHigh); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2163 | cmd = (u64)paddr & DMA_BIT_MASK(32); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2164 | RTL_W32(tp, CounterAddrLow, cmd); |
| 2165 | RTL_W32(tp, CounterAddrLow, cmd | counter_cmd); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2166 | |
Francois Romieu | a78e936 | 2018-01-26 01:53:26 +0100 | [diff] [blame] | 2167 | return rtl_udelay_loop_wait_low(tp, &rtl_counters_cond, 10, 1000); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2168 | } |
| 2169 | |
| 2170 | static bool rtl8169_reset_counters(struct net_device *dev) |
| 2171 | { |
| 2172 | struct rtl8169_private *tp = netdev_priv(dev); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2173 | |
| 2174 | /* |
| 2175 | * Versions prior to RTL_GIGA_MAC_VER_19 don't support resetting the |
| 2176 | * tally counters. |
| 2177 | */ |
| 2178 | if (tp->mac_version < RTL_GIGA_MAC_VER_19) |
| 2179 | return true; |
| 2180 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2181 | return rtl8169_do_counters(dev, CounterReset); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 2182 | } |
| 2183 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2184 | static bool rtl8169_update_counters(struct net_device *dev) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2185 | { |
| 2186 | struct rtl8169_private *tp = netdev_priv(dev); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2187 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2188 | /* |
| 2189 | * Some chips are unable to dump tally counters when the receiver |
| 2190 | * is disabled. |
| 2191 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2192 | if ((RTL_R8(tp, ChipCmd) & CmdRxEnb) == 0) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2193 | return true; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2194 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2195 | return rtl8169_do_counters(dev, CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2196 | } |
| 2197 | |
| 2198 | static bool rtl8169_init_counter_offsets(struct net_device *dev) |
| 2199 | { |
| 2200 | struct rtl8169_private *tp = netdev_priv(dev); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2201 | struct rtl8169_counters *counters = tp->counters; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2202 | bool ret = false; |
| 2203 | |
| 2204 | /* |
| 2205 | * rtl8169_init_counter_offsets is called from rtl_open. On chip |
| 2206 | * versions prior to RTL_GIGA_MAC_VER_19 the tally counters are only |
| 2207 | * reset by a power cycle, while the counter values collected by the |
| 2208 | * driver are reset at every driver unload/load cycle. |
| 2209 | * |
| 2210 | * To make sure the HW values returned by @get_stats64 match the SW |
| 2211 | * values, we collect the initial values at first open(*) and use them |
| 2212 | * as offsets to normalize the values returned by @get_stats64. |
| 2213 | * |
| 2214 | * (*) We can't call rtl8169_init_counter_offsets from rtl_init_one |
| 2215 | * for the reason stated in rtl8169_update_counters; CmdRxEnb is only |
| 2216 | * set at open time by rtl_hw_start. |
| 2217 | */ |
| 2218 | |
| 2219 | if (tp->tc_offset.inited) |
| 2220 | return true; |
| 2221 | |
| 2222 | /* If both, reset and update fail, propagate to caller. */ |
| 2223 | if (rtl8169_reset_counters(dev)) |
| 2224 | ret = true; |
| 2225 | |
| 2226 | if (rtl8169_update_counters(dev)) |
| 2227 | ret = true; |
| 2228 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2229 | tp->tc_offset.tx_errors = counters->tx_errors; |
| 2230 | tp->tc_offset.tx_multi_collision = counters->tx_multi_collision; |
| 2231 | tp->tc_offset.tx_aborted = counters->tx_aborted; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2232 | tp->tc_offset.inited = true; |
| 2233 | |
| 2234 | return ret; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2235 | } |
| 2236 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2237 | static void rtl8169_get_ethtool_stats(struct net_device *dev, |
| 2238 | struct ethtool_stats *stats, u64 *data) |
| 2239 | { |
| 2240 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 2241 | struct device *d = tp_to_dev(tp); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2242 | struct rtl8169_counters *counters = tp->counters; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2243 | |
| 2244 | ASSERT_RTNL(); |
| 2245 | |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 2246 | pm_runtime_get_noresume(d); |
| 2247 | |
| 2248 | if (pm_runtime_active(d)) |
| 2249 | rtl8169_update_counters(dev); |
| 2250 | |
| 2251 | pm_runtime_put_noidle(d); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2252 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2253 | data[0] = le64_to_cpu(counters->tx_packets); |
| 2254 | data[1] = le64_to_cpu(counters->rx_packets); |
| 2255 | data[2] = le64_to_cpu(counters->tx_errors); |
| 2256 | data[3] = le32_to_cpu(counters->rx_errors); |
| 2257 | data[4] = le16_to_cpu(counters->rx_missed); |
| 2258 | data[5] = le16_to_cpu(counters->align_errors); |
| 2259 | data[6] = le32_to_cpu(counters->tx_one_collision); |
| 2260 | data[7] = le32_to_cpu(counters->tx_multi_collision); |
| 2261 | data[8] = le64_to_cpu(counters->rx_unicast); |
| 2262 | data[9] = le64_to_cpu(counters->rx_broadcast); |
| 2263 | data[10] = le32_to_cpu(counters->rx_multicast); |
| 2264 | data[11] = le16_to_cpu(counters->tx_aborted); |
| 2265 | data[12] = le16_to_cpu(counters->tx_underun); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2266 | } |
| 2267 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2268 | static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 2269 | { |
| 2270 | switch(stringset) { |
| 2271 | case ETH_SS_STATS: |
| 2272 | memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings)); |
| 2273 | break; |
| 2274 | } |
| 2275 | } |
| 2276 | |
Florian Fainelli | f0903ea | 2016-12-03 12:01:19 -0800 | [diff] [blame] | 2277 | static int rtl8169_nway_reset(struct net_device *dev) |
| 2278 | { |
| 2279 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2280 | |
| 2281 | return mii_nway_restart(&tp->mii); |
| 2282 | } |
| 2283 | |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2284 | /* |
| 2285 | * Interrupt coalescing |
| 2286 | * |
| 2287 | * > 1 - the availability of the IntrMitigate (0xe2) register through the |
| 2288 | * > 8169, 8168 and 810x line of chipsets |
| 2289 | * |
| 2290 | * 8169, 8168, and 8136(810x) serial chipsets support it. |
| 2291 | * |
| 2292 | * > 2 - the Tx timer unit at gigabit speed |
| 2293 | * |
| 2294 | * The unit of the timer depends on both the speed and the setting of CPlusCmd |
| 2295 | * (0xe0) bit 1 and bit 0. |
| 2296 | * |
| 2297 | * For 8169 |
| 2298 | * bit[1:0] \ speed 1000M 100M 10M |
| 2299 | * 0 0 320ns 2.56us 40.96us |
| 2300 | * 0 1 2.56us 20.48us 327.7us |
| 2301 | * 1 0 5.12us 40.96us 655.4us |
| 2302 | * 1 1 10.24us 81.92us 1.31ms |
| 2303 | * |
| 2304 | * For the other |
| 2305 | * bit[1:0] \ speed 1000M 100M 10M |
| 2306 | * 0 0 5us 2.56us 40.96us |
| 2307 | * 0 1 40us 20.48us 327.7us |
| 2308 | * 1 0 80us 40.96us 655.4us |
| 2309 | * 1 1 160us 81.92us 1.31ms |
| 2310 | */ |
| 2311 | |
| 2312 | /* rx/tx scale factors for one particular CPlusCmd[0:1] value */ |
| 2313 | struct rtl_coalesce_scale { |
| 2314 | /* Rx / Tx */ |
| 2315 | u32 nsecs[2]; |
| 2316 | }; |
| 2317 | |
| 2318 | /* rx/tx scale factors for all CPlusCmd[0:1] cases */ |
| 2319 | struct rtl_coalesce_info { |
| 2320 | u32 speed; |
| 2321 | struct rtl_coalesce_scale scalev[4]; /* each CPlusCmd[0:1] case */ |
| 2322 | }; |
| 2323 | |
| 2324 | /* produce (r,t) pairs with each being in series of *1, *8, *8*2, *8*2*2 */ |
| 2325 | #define rxtx_x1822(r, t) { \ |
| 2326 | {{(r), (t)}}, \ |
| 2327 | {{(r)*8, (t)*8}}, \ |
| 2328 | {{(r)*8*2, (t)*8*2}}, \ |
| 2329 | {{(r)*8*2*2, (t)*8*2*2}}, \ |
| 2330 | } |
| 2331 | static const struct rtl_coalesce_info rtl_coalesce_info_8169[] = { |
| 2332 | /* speed delays: rx00 tx00 */ |
| 2333 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 2334 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 2335 | { SPEED_1000, rxtx_x1822( 320, 320) }, |
| 2336 | { 0 }, |
| 2337 | }; |
| 2338 | |
| 2339 | static const struct rtl_coalesce_info rtl_coalesce_info_8168_8136[] = { |
| 2340 | /* speed delays: rx00 tx00 */ |
| 2341 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 2342 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 2343 | { SPEED_1000, rxtx_x1822( 5000, 5000) }, |
| 2344 | { 0 }, |
| 2345 | }; |
| 2346 | #undef rxtx_x1822 |
| 2347 | |
| 2348 | /* get rx/tx scale vector corresponding to current speed */ |
| 2349 | static const struct rtl_coalesce_info *rtl_coalesce_info(struct net_device *dev) |
| 2350 | { |
| 2351 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2352 | struct ethtool_link_ksettings ecmd; |
| 2353 | const struct rtl_coalesce_info *ci; |
| 2354 | int rc; |
| 2355 | |
| 2356 | rc = rtl8169_get_link_ksettings(dev, &ecmd); |
| 2357 | if (rc < 0) |
| 2358 | return ERR_PTR(rc); |
| 2359 | |
| 2360 | for (ci = tp->coalesce_info; ci->speed != 0; ci++) { |
| 2361 | if (ecmd.base.speed == ci->speed) { |
| 2362 | return ci; |
| 2363 | } |
| 2364 | } |
| 2365 | |
| 2366 | return ERR_PTR(-ELNRNG); |
| 2367 | } |
| 2368 | |
| 2369 | static int rtl_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 2370 | { |
| 2371 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2372 | const struct rtl_coalesce_info *ci; |
| 2373 | const struct rtl_coalesce_scale *scale; |
| 2374 | struct { |
| 2375 | u32 *max_frames; |
| 2376 | u32 *usecs; |
| 2377 | } coal_settings [] = { |
| 2378 | { &ec->rx_max_coalesced_frames, &ec->rx_coalesce_usecs }, |
| 2379 | { &ec->tx_max_coalesced_frames, &ec->tx_coalesce_usecs } |
| 2380 | }, *p = coal_settings; |
| 2381 | int i; |
| 2382 | u16 w; |
| 2383 | |
| 2384 | memset(ec, 0, sizeof(*ec)); |
| 2385 | |
| 2386 | /* get rx/tx scale corresponding to current speed and CPlusCmd[0:1] */ |
| 2387 | ci = rtl_coalesce_info(dev); |
| 2388 | if (IS_ERR(ci)) |
| 2389 | return PTR_ERR(ci); |
| 2390 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2391 | scale = &ci->scalev[RTL_R16(tp, CPlusCmd) & 3]; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2392 | |
| 2393 | /* read IntrMitigate and adjust according to scale */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2394 | for (w = RTL_R16(tp, IntrMitigate); w; w >>= RTL_COALESCE_SHIFT, p++) { |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2395 | *p->max_frames = (w & RTL_COALESCE_MASK) << 2; |
| 2396 | w >>= RTL_COALESCE_SHIFT; |
| 2397 | *p->usecs = w & RTL_COALESCE_MASK; |
| 2398 | } |
| 2399 | |
| 2400 | for (i = 0; i < 2; i++) { |
| 2401 | p = coal_settings + i; |
| 2402 | *p->usecs = (*p->usecs * scale->nsecs[i]) / 1000; |
| 2403 | |
| 2404 | /* |
| 2405 | * ethtool_coalesce says it is illegal to set both usecs and |
| 2406 | * max_frames to 0. |
| 2407 | */ |
| 2408 | if (!*p->usecs && !*p->max_frames) |
| 2409 | *p->max_frames = 1; |
| 2410 | } |
| 2411 | |
| 2412 | return 0; |
| 2413 | } |
| 2414 | |
| 2415 | /* choose appropriate scale factor and CPlusCmd[0:1] for (speed, nsec) */ |
| 2416 | static const struct rtl_coalesce_scale *rtl_coalesce_choose_scale( |
| 2417 | struct net_device *dev, u32 nsec, u16 *cp01) |
| 2418 | { |
| 2419 | const struct rtl_coalesce_info *ci; |
| 2420 | u16 i; |
| 2421 | |
| 2422 | ci = rtl_coalesce_info(dev); |
| 2423 | if (IS_ERR(ci)) |
| 2424 | return ERR_CAST(ci); |
| 2425 | |
| 2426 | for (i = 0; i < 4; i++) { |
| 2427 | u32 rxtx_maxscale = max(ci->scalev[i].nsecs[0], |
| 2428 | ci->scalev[i].nsecs[1]); |
| 2429 | if (nsec <= rxtx_maxscale * RTL_COALESCE_T_MAX) { |
| 2430 | *cp01 = i; |
| 2431 | return &ci->scalev[i]; |
| 2432 | } |
| 2433 | } |
| 2434 | |
| 2435 | return ERR_PTR(-EINVAL); |
| 2436 | } |
| 2437 | |
| 2438 | static int rtl_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 2439 | { |
| 2440 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2441 | const struct rtl_coalesce_scale *scale; |
| 2442 | struct { |
| 2443 | u32 frames; |
| 2444 | u32 usecs; |
| 2445 | } coal_settings [] = { |
| 2446 | { ec->rx_max_coalesced_frames, ec->rx_coalesce_usecs }, |
| 2447 | { ec->tx_max_coalesced_frames, ec->tx_coalesce_usecs } |
| 2448 | }, *p = coal_settings; |
| 2449 | u16 w = 0, cp01; |
| 2450 | int i; |
| 2451 | |
| 2452 | scale = rtl_coalesce_choose_scale(dev, |
| 2453 | max(p[0].usecs, p[1].usecs) * 1000, &cp01); |
| 2454 | if (IS_ERR(scale)) |
| 2455 | return PTR_ERR(scale); |
| 2456 | |
| 2457 | for (i = 0; i < 2; i++, p++) { |
| 2458 | u32 units; |
| 2459 | |
| 2460 | /* |
| 2461 | * accept max_frames=1 we returned in rtl_get_coalesce. |
| 2462 | * accept it not only when usecs=0 because of e.g. the following scenario: |
| 2463 | * |
| 2464 | * - both rx_usecs=0 & rx_frames=0 in hardware (no delay on RX) |
| 2465 | * - rtl_get_coalesce returns rx_usecs=0, rx_frames=1 |
| 2466 | * - then user does `ethtool -C eth0 rx-usecs 100` |
| 2467 | * |
| 2468 | * since ethtool sends to kernel whole ethtool_coalesce |
| 2469 | * settings, if we do not handle rx_usecs=!0, rx_frames=1 |
| 2470 | * we'll reject it below in `frames % 4 != 0`. |
| 2471 | */ |
| 2472 | if (p->frames == 1) { |
| 2473 | p->frames = 0; |
| 2474 | } |
| 2475 | |
| 2476 | units = p->usecs * 1000 / scale->nsecs[i]; |
| 2477 | if (p->frames > RTL_COALESCE_FRAME_MAX || p->frames % 4) |
| 2478 | return -EINVAL; |
| 2479 | |
| 2480 | w <<= RTL_COALESCE_SHIFT; |
| 2481 | w |= units; |
| 2482 | w <<= RTL_COALESCE_SHIFT; |
| 2483 | w |= p->frames >> 2; |
| 2484 | } |
| 2485 | |
| 2486 | rtl_lock_work(tp); |
| 2487 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2488 | RTL_W16(tp, IntrMitigate, swab16(w)); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2489 | |
| 2490 | tp->cp_cmd = (tp->cp_cmd & ~3) | cp01; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2491 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
| 2492 | RTL_R16(tp, CPlusCmd); |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2493 | |
| 2494 | rtl_unlock_work(tp); |
| 2495 | |
| 2496 | return 0; |
| 2497 | } |
| 2498 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 2499 | static const struct ethtool_ops rtl8169_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2500 | .get_drvinfo = rtl8169_get_drvinfo, |
| 2501 | .get_regs_len = rtl8169_get_regs_len, |
| 2502 | .get_link = ethtool_op_get_link, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2503 | .get_coalesce = rtl_get_coalesce, |
| 2504 | .set_coalesce = rtl_set_coalesce, |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 2505 | .get_msglevel = rtl8169_get_msglevel, |
| 2506 | .set_msglevel = rtl8169_set_msglevel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2507 | .get_regs = rtl8169_get_regs, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 2508 | .get_wol = rtl8169_get_wol, |
| 2509 | .set_wol = rtl8169_set_wol, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2510 | .get_strings = rtl8169_get_strings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2511 | .get_sset_count = rtl8169_get_sset_count, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2512 | .get_ethtool_stats = rtl8169_get_ethtool_stats, |
Richard Cochran | e1593bb | 2012-04-03 22:59:35 +0000 | [diff] [blame] | 2513 | .get_ts_info = ethtool_op_get_ts_info, |
Florian Fainelli | f0903ea | 2016-12-03 12:01:19 -0800 | [diff] [blame] | 2514 | .nway_reset = rtl8169_nway_reset, |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2515 | .get_link_ksettings = rtl8169_get_link_ksettings, |
Tobias Jakobi | 9e77d7a | 2017-11-21 16:15:57 +0100 | [diff] [blame] | 2516 | .set_link_ksettings = rtl8169_set_link_ksettings, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2517 | }; |
| 2518 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 2519 | static void rtl8169_get_mac_version(struct rtl8169_private *tp, |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2520 | struct net_device *dev, u8 default_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2521 | { |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2522 | /* |
| 2523 | * The driver currently handles the 8168Bf and the 8168Be identically |
| 2524 | * but they can be identified more specifically through the test below |
| 2525 | * if needed: |
| 2526 | * |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2527 | * (RTL_R32(tp, TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be |
Francois Romieu | 0127215 | 2007-02-20 22:58:51 +0100 | [diff] [blame] | 2528 | * |
| 2529 | * Same thing for the 8101Eb and the 8101Ec: |
| 2530 | * |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2531 | * (RTL_R32(tp, TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2532 | */ |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2533 | static const struct rtl_mac_info { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2534 | u32 mask; |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2535 | u32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2536 | int mac_version; |
| 2537 | } mac_info[] = { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 2538 | /* 8168EP family. */ |
| 2539 | { 0x7cf00000, 0x50200000, RTL_GIGA_MAC_VER_51 }, |
| 2540 | { 0x7cf00000, 0x50100000, RTL_GIGA_MAC_VER_50 }, |
| 2541 | { 0x7cf00000, 0x50000000, RTL_GIGA_MAC_VER_49 }, |
| 2542 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2543 | /* 8168H family. */ |
| 2544 | { 0x7cf00000, 0x54100000, RTL_GIGA_MAC_VER_46 }, |
| 2545 | { 0x7cf00000, 0x54000000, RTL_GIGA_MAC_VER_45 }, |
| 2546 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2547 | /* 8168G family. */ |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 2548 | { 0x7cf00000, 0x5c800000, RTL_GIGA_MAC_VER_44 }, |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 2549 | { 0x7cf00000, 0x50900000, RTL_GIGA_MAC_VER_42 }, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2550 | { 0x7cf00000, 0x4c100000, RTL_GIGA_MAC_VER_41 }, |
| 2551 | { 0x7cf00000, 0x4c000000, RTL_GIGA_MAC_VER_40 }, |
| 2552 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2553 | /* 8168F family. */ |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 2554 | { 0x7c800000, 0x48800000, RTL_GIGA_MAC_VER_38 }, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2555 | { 0x7cf00000, 0x48100000, RTL_GIGA_MAC_VER_36 }, |
| 2556 | { 0x7cf00000, 0x48000000, RTL_GIGA_MAC_VER_35 }, |
| 2557 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2558 | /* 8168E family. */ |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2559 | { 0x7c800000, 0x2c800000, RTL_GIGA_MAC_VER_34 }, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2560 | { 0x7cf00000, 0x2c200000, RTL_GIGA_MAC_VER_33 }, |
| 2561 | { 0x7cf00000, 0x2c100000, RTL_GIGA_MAC_VER_32 }, |
| 2562 | { 0x7c800000, 0x2c000000, RTL_GIGA_MAC_VER_33 }, |
| 2563 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2564 | /* 8168D family. */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2565 | { 0x7cf00000, 0x28300000, RTL_GIGA_MAC_VER_26 }, |
| 2566 | { 0x7cf00000, 0x28100000, RTL_GIGA_MAC_VER_25 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2567 | { 0x7c800000, 0x28000000, RTL_GIGA_MAC_VER_26 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2568 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2569 | /* 8168DP family. */ |
| 2570 | { 0x7cf00000, 0x28800000, RTL_GIGA_MAC_VER_27 }, |
| 2571 | { 0x7cf00000, 0x28a00000, RTL_GIGA_MAC_VER_28 }, |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 2572 | { 0x7cf00000, 0x28b00000, RTL_GIGA_MAC_VER_31 }, |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2573 | |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2574 | /* 8168C family. */ |
Francois Romieu | 17c9929 | 2010-07-11 17:10:09 -0700 | [diff] [blame] | 2575 | { 0x7cf00000, 0x3cb00000, RTL_GIGA_MAC_VER_24 }, |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2576 | { 0x7cf00000, 0x3c900000, RTL_GIGA_MAC_VER_23 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2577 | { 0x7cf00000, 0x3c800000, RTL_GIGA_MAC_VER_18 }, |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 2578 | { 0x7c800000, 0x3c800000, RTL_GIGA_MAC_VER_24 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2579 | { 0x7cf00000, 0x3c000000, RTL_GIGA_MAC_VER_19 }, |
| 2580 | { 0x7cf00000, 0x3c200000, RTL_GIGA_MAC_VER_20 }, |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2581 | { 0x7cf00000, 0x3c300000, RTL_GIGA_MAC_VER_21 }, |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2582 | { 0x7cf00000, 0x3c400000, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2583 | { 0x7c800000, 0x3c000000, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2584 | |
| 2585 | /* 8168B family. */ |
| 2586 | { 0x7cf00000, 0x38000000, RTL_GIGA_MAC_VER_12 }, |
| 2587 | { 0x7cf00000, 0x38500000, RTL_GIGA_MAC_VER_17 }, |
| 2588 | { 0x7c800000, 0x38000000, RTL_GIGA_MAC_VER_17 }, |
| 2589 | { 0x7c800000, 0x30000000, RTL_GIGA_MAC_VER_11 }, |
| 2590 | |
| 2591 | /* 8101 family. */ |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 2592 | { 0x7cf00000, 0x44900000, RTL_GIGA_MAC_VER_39 }, |
| 2593 | { 0x7c800000, 0x44800000, RTL_GIGA_MAC_VER_39 }, |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 2594 | { 0x7c800000, 0x44000000, RTL_GIGA_MAC_VER_37 }, |
hayeswang | 36a0e6c | 2011-03-21 01:50:30 +0000 | [diff] [blame] | 2595 | { 0x7cf00000, 0x40b00000, RTL_GIGA_MAC_VER_30 }, |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 2596 | { 0x7cf00000, 0x40a00000, RTL_GIGA_MAC_VER_30 }, |
| 2597 | { 0x7cf00000, 0x40900000, RTL_GIGA_MAC_VER_29 }, |
| 2598 | { 0x7c800000, 0x40800000, RTL_GIGA_MAC_VER_30 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2599 | { 0x7cf00000, 0x34a00000, RTL_GIGA_MAC_VER_09 }, |
| 2600 | { 0x7cf00000, 0x24a00000, RTL_GIGA_MAC_VER_09 }, |
| 2601 | { 0x7cf00000, 0x34900000, RTL_GIGA_MAC_VER_08 }, |
| 2602 | { 0x7cf00000, 0x24900000, RTL_GIGA_MAC_VER_08 }, |
| 2603 | { 0x7cf00000, 0x34800000, RTL_GIGA_MAC_VER_07 }, |
| 2604 | { 0x7cf00000, 0x24800000, RTL_GIGA_MAC_VER_07 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2605 | { 0x7cf00000, 0x34000000, RTL_GIGA_MAC_VER_13 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2606 | { 0x7cf00000, 0x34300000, RTL_GIGA_MAC_VER_10 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2607 | { 0x7cf00000, 0x34200000, RTL_GIGA_MAC_VER_16 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2608 | { 0x7c800000, 0x34800000, RTL_GIGA_MAC_VER_09 }, |
| 2609 | { 0x7c800000, 0x24800000, RTL_GIGA_MAC_VER_09 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2610 | { 0x7c800000, 0x34000000, RTL_GIGA_MAC_VER_16 }, |
| 2611 | /* FIXME: where did these entries come from ? -- FR */ |
| 2612 | { 0xfc800000, 0x38800000, RTL_GIGA_MAC_VER_15 }, |
| 2613 | { 0xfc800000, 0x30800000, RTL_GIGA_MAC_VER_14 }, |
| 2614 | |
| 2615 | /* 8110 family. */ |
| 2616 | { 0xfc800000, 0x98000000, RTL_GIGA_MAC_VER_06 }, |
| 2617 | { 0xfc800000, 0x18000000, RTL_GIGA_MAC_VER_05 }, |
| 2618 | { 0xfc800000, 0x10000000, RTL_GIGA_MAC_VER_04 }, |
| 2619 | { 0xfc800000, 0x04000000, RTL_GIGA_MAC_VER_03 }, |
| 2620 | { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 }, |
| 2621 | { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 }, |
| 2622 | |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 2623 | /* Catch-all */ |
| 2624 | { 0x00000000, 0x00000000, RTL_GIGA_MAC_NONE } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2625 | }; |
| 2626 | const struct rtl_mac_info *p = mac_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2627 | u32 reg; |
| 2628 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 2629 | reg = RTL_R32(tp, TxConfig); |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2630 | while ((reg & p->mask) != p->val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2631 | p++; |
| 2632 | tp->mac_version = p->mac_version; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2633 | |
| 2634 | if (tp->mac_version == RTL_GIGA_MAC_NONE) { |
| 2635 | netif_notice(tp, probe, dev, |
| 2636 | "unknown MAC, using family default\n"); |
| 2637 | tp->mac_version = default_version; |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 2638 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_42) { |
| 2639 | tp->mac_version = tp->mii.supports_gmii ? |
| 2640 | RTL_GIGA_MAC_VER_42 : |
| 2641 | RTL_GIGA_MAC_VER_43; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2642 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_45) { |
| 2643 | tp->mac_version = tp->mii.supports_gmii ? |
| 2644 | RTL_GIGA_MAC_VER_45 : |
| 2645 | RTL_GIGA_MAC_VER_47; |
| 2646 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_46) { |
| 2647 | tp->mac_version = tp->mii.supports_gmii ? |
| 2648 | RTL_GIGA_MAC_VER_46 : |
| 2649 | RTL_GIGA_MAC_VER_48; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2650 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2651 | } |
| 2652 | |
| 2653 | static void rtl8169_print_mac_version(struct rtl8169_private *tp) |
| 2654 | { |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 2655 | dprintk("mac_version = 0x%02x\n", tp->mac_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | } |
| 2657 | |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2658 | struct phy_reg { |
| 2659 | u16 reg; |
| 2660 | u16 val; |
| 2661 | }; |
| 2662 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2663 | static void rtl_writephy_batch(struct rtl8169_private *tp, |
| 2664 | const struct phy_reg *regs, int len) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2665 | { |
| 2666 | while (len-- > 0) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2667 | rtl_writephy(tp, regs->reg, regs->val); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2668 | regs++; |
| 2669 | } |
| 2670 | } |
| 2671 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2672 | #define PHY_READ 0x00000000 |
| 2673 | #define PHY_DATA_OR 0x10000000 |
| 2674 | #define PHY_DATA_AND 0x20000000 |
| 2675 | #define PHY_BJMPN 0x30000000 |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2676 | #define PHY_MDIO_CHG 0x40000000 |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2677 | #define PHY_CLEAR_READCOUNT 0x70000000 |
| 2678 | #define PHY_WRITE 0x80000000 |
| 2679 | #define PHY_READCOUNT_EQ_SKIP 0x90000000 |
| 2680 | #define PHY_COMP_EQ_SKIPN 0xa0000000 |
| 2681 | #define PHY_COMP_NEQ_SKIPN 0xb0000000 |
| 2682 | #define PHY_WRITE_PREVIOUS 0xc0000000 |
| 2683 | #define PHY_SKIPN 0xd0000000 |
| 2684 | #define PHY_DELAY_MS 0xe0000000 |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2685 | |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2686 | struct fw_info { |
| 2687 | u32 magic; |
| 2688 | char version[RTL_VER_SIZE]; |
| 2689 | __le32 fw_start; |
| 2690 | __le32 fw_len; |
| 2691 | u8 chksum; |
| 2692 | } __packed; |
| 2693 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2694 | #define FW_OPCODE_SIZE sizeof(typeof(*((struct rtl_fw_phy_action *)0)->code)) |
| 2695 | |
| 2696 | 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] | 2697 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2698 | const struct firmware *fw = rtl_fw->fw; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2699 | struct fw_info *fw_info = (struct fw_info *)fw->data; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2700 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
| 2701 | char *version = rtl_fw->version; |
| 2702 | bool rc = false; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2703 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2704 | if (fw->size < FW_OPCODE_SIZE) |
| 2705 | goto out; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2706 | |
| 2707 | if (!fw_info->magic) { |
| 2708 | size_t i, size, start; |
| 2709 | u8 checksum = 0; |
| 2710 | |
| 2711 | if (fw->size < sizeof(*fw_info)) |
| 2712 | goto out; |
| 2713 | |
| 2714 | for (i = 0; i < fw->size; i++) |
| 2715 | checksum += fw->data[i]; |
| 2716 | if (checksum != 0) |
| 2717 | goto out; |
| 2718 | |
| 2719 | start = le32_to_cpu(fw_info->fw_start); |
| 2720 | if (start > fw->size) |
| 2721 | goto out; |
| 2722 | |
| 2723 | size = le32_to_cpu(fw_info->fw_len); |
| 2724 | if (size > (fw->size - start) / FW_OPCODE_SIZE) |
| 2725 | goto out; |
| 2726 | |
| 2727 | memcpy(version, fw_info->version, RTL_VER_SIZE); |
| 2728 | |
| 2729 | pa->code = (__le32 *)(fw->data + start); |
| 2730 | pa->size = size; |
| 2731 | } else { |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2732 | if (fw->size % FW_OPCODE_SIZE) |
| 2733 | goto out; |
| 2734 | |
| 2735 | strlcpy(version, rtl_lookup_firmware_name(tp), RTL_VER_SIZE); |
| 2736 | |
| 2737 | pa->code = (__le32 *)fw->data; |
| 2738 | pa->size = fw->size / FW_OPCODE_SIZE; |
| 2739 | } |
| 2740 | version[RTL_VER_SIZE - 1] = 0; |
| 2741 | |
| 2742 | rc = true; |
| 2743 | out: |
| 2744 | return rc; |
| 2745 | } |
| 2746 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2747 | static bool rtl_fw_data_ok(struct rtl8169_private *tp, struct net_device *dev, |
| 2748 | struct rtl_fw_phy_action *pa) |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2749 | { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2750 | bool rc = false; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2751 | size_t index; |
| 2752 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2753 | for (index = 0; index < pa->size; index++) { |
| 2754 | u32 action = le32_to_cpu(pa->code[index]); |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2755 | u32 regno = (action & 0x0fff0000) >> 16; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2756 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2757 | switch(action & 0xf0000000) { |
| 2758 | case PHY_READ: |
| 2759 | case PHY_DATA_OR: |
| 2760 | case PHY_DATA_AND: |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2761 | case PHY_MDIO_CHG: |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2762 | case PHY_CLEAR_READCOUNT: |
| 2763 | case PHY_WRITE: |
| 2764 | case PHY_WRITE_PREVIOUS: |
| 2765 | case PHY_DELAY_MS: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2766 | break; |
| 2767 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2768 | case PHY_BJMPN: |
| 2769 | if (regno > index) { |
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_READCOUNT_EQ_SKIP: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2776 | if (index + 2 >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2777 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2778 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2779 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2780 | } |
| 2781 | break; |
| 2782 | case PHY_COMP_EQ_SKIPN: |
| 2783 | case PHY_COMP_NEQ_SKIPN: |
| 2784 | case PHY_SKIPN: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2785 | if (index + 1 + regno >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2786 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2787 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2788 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2789 | } |
| 2790 | break; |
| 2791 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2792 | default: |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2793 | netif_err(tp, ifup, tp->dev, |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2794 | "Invalid action 0x%08x\n", action); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2795 | goto out; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2796 | } |
| 2797 | } |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2798 | rc = true; |
| 2799 | out: |
| 2800 | return rc; |
| 2801 | } |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2802 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2803 | static int rtl_check_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2804 | { |
| 2805 | struct net_device *dev = tp->dev; |
| 2806 | int rc = -EINVAL; |
| 2807 | |
| 2808 | if (!rtl_fw_format_ok(tp, rtl_fw)) { |
Yannick Guerrini | 5c2d2b1 | 2015-02-24 13:03:51 +0100 | [diff] [blame] | 2809 | netif_err(tp, ifup, dev, "invalid firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2810 | goto out; |
| 2811 | } |
| 2812 | |
| 2813 | if (rtl_fw_data_ok(tp, dev, &rtl_fw->phy_action)) |
| 2814 | rc = 0; |
| 2815 | out: |
| 2816 | return rc; |
| 2817 | } |
| 2818 | |
| 2819 | static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2820 | { |
| 2821 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2822 | struct mdio_ops org, *ops = &tp->mdio_ops; |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2823 | u32 predata, count; |
| 2824 | size_t index; |
| 2825 | |
| 2826 | predata = count = 0; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2827 | org.write = ops->write; |
| 2828 | org.read = ops->read; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2829 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2830 | for (index = 0; index < pa->size; ) { |
| 2831 | u32 action = le32_to_cpu(pa->code[index]); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2832 | u32 data = action & 0x0000ffff; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2833 | u32 regno = (action & 0x0fff0000) >> 16; |
| 2834 | |
| 2835 | if (!action) |
| 2836 | break; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2837 | |
| 2838 | switch(action & 0xf0000000) { |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2839 | case PHY_READ: |
| 2840 | predata = rtl_readphy(tp, regno); |
| 2841 | count++; |
| 2842 | index++; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2843 | break; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2844 | case PHY_DATA_OR: |
| 2845 | predata |= data; |
| 2846 | index++; |
| 2847 | break; |
| 2848 | case PHY_DATA_AND: |
| 2849 | predata &= data; |
| 2850 | index++; |
| 2851 | break; |
| 2852 | case PHY_BJMPN: |
| 2853 | index -= regno; |
| 2854 | break; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2855 | case PHY_MDIO_CHG: |
| 2856 | if (data == 0) { |
| 2857 | ops->write = org.write; |
| 2858 | ops->read = org.read; |
| 2859 | } else if (data == 1) { |
| 2860 | ops->write = mac_mcu_write; |
| 2861 | ops->read = mac_mcu_read; |
| 2862 | } |
| 2863 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2864 | index++; |
| 2865 | break; |
| 2866 | case PHY_CLEAR_READCOUNT: |
| 2867 | count = 0; |
| 2868 | index++; |
| 2869 | break; |
| 2870 | case PHY_WRITE: |
| 2871 | rtl_writephy(tp, regno, data); |
| 2872 | index++; |
| 2873 | break; |
| 2874 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2875 | index += (count == data) ? 2 : 1; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2876 | break; |
| 2877 | case PHY_COMP_EQ_SKIPN: |
| 2878 | if (predata == data) |
| 2879 | index += regno; |
| 2880 | index++; |
| 2881 | break; |
| 2882 | case PHY_COMP_NEQ_SKIPN: |
| 2883 | if (predata != data) |
| 2884 | index += regno; |
| 2885 | index++; |
| 2886 | break; |
| 2887 | case PHY_WRITE_PREVIOUS: |
| 2888 | rtl_writephy(tp, regno, predata); |
| 2889 | index++; |
| 2890 | break; |
| 2891 | case PHY_SKIPN: |
| 2892 | index += regno + 1; |
| 2893 | break; |
| 2894 | case PHY_DELAY_MS: |
| 2895 | mdelay(data); |
| 2896 | index++; |
| 2897 | break; |
| 2898 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2899 | default: |
| 2900 | BUG(); |
| 2901 | } |
| 2902 | } |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2903 | |
| 2904 | ops->write = org.write; |
| 2905 | ops->read = org.read; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2906 | } |
| 2907 | |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2908 | static void rtl_release_firmware(struct rtl8169_private *tp) |
| 2909 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2910 | if (!IS_ERR_OR_NULL(tp->rtl_fw)) { |
| 2911 | release_firmware(tp->rtl_fw->fw); |
| 2912 | kfree(tp->rtl_fw); |
| 2913 | } |
| 2914 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2915 | } |
| 2916 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2917 | static void rtl_apply_firmware(struct rtl8169_private *tp) |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2918 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2919 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2920 | |
| 2921 | /* TODO: release firmware once rtl_phy_write_fw signals failures. */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 2922 | if (!IS_ERR_OR_NULL(rtl_fw)) |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2923 | rtl_phy_write_fw(tp, rtl_fw); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2924 | } |
| 2925 | |
| 2926 | static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val) |
| 2927 | { |
| 2928 | if (rtl_readphy(tp, reg) != val) |
| 2929 | netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n"); |
| 2930 | else |
| 2931 | rtl_apply_firmware(tp); |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2932 | } |
| 2933 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2934 | static void rtl8169s_hw_phy_config(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2935 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2936 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2937 | { 0x1f, 0x0001 }, |
| 2938 | { 0x06, 0x006e }, |
| 2939 | { 0x08, 0x0708 }, |
| 2940 | { 0x15, 0x4000 }, |
| 2941 | { 0x18, 0x65c7 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2942 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2943 | { 0x1f, 0x0001 }, |
| 2944 | { 0x03, 0x00a1 }, |
| 2945 | { 0x02, 0x0008 }, |
| 2946 | { 0x01, 0x0120 }, |
| 2947 | { 0x00, 0x1000 }, |
| 2948 | { 0x04, 0x0800 }, |
| 2949 | { 0x04, 0x0000 }, |
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, 0xff41 }, |
| 2952 | { 0x02, 0xdf60 }, |
| 2953 | { 0x01, 0x0140 }, |
| 2954 | { 0x00, 0x0077 }, |
| 2955 | { 0x04, 0x7800 }, |
| 2956 | { 0x04, 0x7000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2957 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2958 | { 0x03, 0x802f }, |
| 2959 | { 0x02, 0x4f02 }, |
| 2960 | { 0x01, 0x0409 }, |
| 2961 | { 0x00, 0xf0f9 }, |
| 2962 | { 0x04, 0x9800 }, |
| 2963 | { 0x04, 0x9000 }, |
| 2964 | |
| 2965 | { 0x03, 0xdf01 }, |
| 2966 | { 0x02, 0xdf20 }, |
| 2967 | { 0x01, 0xff95 }, |
| 2968 | { 0x00, 0xba00 }, |
| 2969 | { 0x04, 0xa800 }, |
| 2970 | { 0x04, 0xa000 }, |
| 2971 | |
| 2972 | { 0x03, 0xff41 }, |
| 2973 | { 0x02, 0xdf20 }, |
| 2974 | { 0x01, 0x0140 }, |
| 2975 | { 0x00, 0x00bb }, |
| 2976 | { 0x04, 0xb800 }, |
| 2977 | { 0x04, 0xb000 }, |
| 2978 | |
| 2979 | { 0x03, 0xdf41 }, |
| 2980 | { 0x02, 0xdc60 }, |
| 2981 | { 0x01, 0x6340 }, |
| 2982 | { 0x00, 0x007d }, |
| 2983 | { 0x04, 0xd800 }, |
| 2984 | { 0x04, 0xd000 }, |
| 2985 | |
| 2986 | { 0x03, 0xdf01 }, |
| 2987 | { 0x02, 0xdf20 }, |
| 2988 | { 0x01, 0x100a }, |
| 2989 | { 0x00, 0xa0ff }, |
| 2990 | { 0x04, 0xf800 }, |
| 2991 | { 0x04, 0xf000 }, |
| 2992 | |
| 2993 | { 0x1f, 0x0000 }, |
| 2994 | { 0x0b, 0x0000 }, |
| 2995 | { 0x00, 0x9200 } |
| 2996 | }; |
| 2997 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2998 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2999 | } |
| 3000 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3001 | static void rtl8169sb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3002 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3003 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a441d7b | 2007-08-17 18:26:35 +0200 | [diff] [blame] | 3004 | { 0x1f, 0x0002 }, |
| 3005 | { 0x01, 0x90d0 }, |
| 3006 | { 0x1f, 0x0000 } |
| 3007 | }; |
| 3008 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3009 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3010 | } |
| 3011 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3012 | static void rtl8169scd_hw_phy_config_quirk(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3013 | { |
| 3014 | struct pci_dev *pdev = tp->pci_dev; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3015 | |
Sergei Shtylyov | ccbae55 | 2011-07-22 05:37:24 +0000 | [diff] [blame] | 3016 | if ((pdev->subsystem_vendor != PCI_VENDOR_ID_GIGABYTE) || |
| 3017 | (pdev->subsystem_device != 0xe000)) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3018 | return; |
| 3019 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3020 | rtl_writephy(tp, 0x1f, 0x0001); |
| 3021 | rtl_writephy(tp, 0x10, 0xf01b); |
| 3022 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3023 | } |
| 3024 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3025 | static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3026 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3027 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3028 | { 0x1f, 0x0001 }, |
| 3029 | { 0x04, 0x0000 }, |
| 3030 | { 0x03, 0x00a1 }, |
| 3031 | { 0x02, 0x0008 }, |
| 3032 | { 0x01, 0x0120 }, |
| 3033 | { 0x00, 0x1000 }, |
| 3034 | { 0x04, 0x0800 }, |
| 3035 | { 0x04, 0x9000 }, |
| 3036 | { 0x03, 0x802f }, |
| 3037 | { 0x02, 0x4f02 }, |
| 3038 | { 0x01, 0x0409 }, |
| 3039 | { 0x00, 0xf099 }, |
| 3040 | { 0x04, 0x9800 }, |
| 3041 | { 0x04, 0xa000 }, |
| 3042 | { 0x03, 0xdf01 }, |
| 3043 | { 0x02, 0xdf20 }, |
| 3044 | { 0x01, 0xff95 }, |
| 3045 | { 0x00, 0xba00 }, |
| 3046 | { 0x04, 0xa800 }, |
| 3047 | { 0x04, 0xf000 }, |
| 3048 | { 0x03, 0xdf01 }, |
| 3049 | { 0x02, 0xdf20 }, |
| 3050 | { 0x01, 0x101a }, |
| 3051 | { 0x00, 0xa0ff }, |
| 3052 | { 0x04, 0xf800 }, |
| 3053 | { 0x04, 0x0000 }, |
| 3054 | { 0x1f, 0x0000 }, |
| 3055 | |
| 3056 | { 0x1f, 0x0001 }, |
| 3057 | { 0x10, 0xf41b }, |
| 3058 | { 0x14, 0xfb54 }, |
| 3059 | { 0x18, 0xf5c7 }, |
| 3060 | { 0x1f, 0x0000 }, |
| 3061 | |
| 3062 | { 0x1f, 0x0001 }, |
| 3063 | { 0x17, 0x0cc0 }, |
| 3064 | { 0x1f, 0x0000 } |
| 3065 | }; |
| 3066 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3067 | 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] | 3068 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3069 | rtl8169scd_hw_phy_config_quirk(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3070 | } |
| 3071 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3072 | static void rtl8169sce_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 3073 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3074 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 3075 | { 0x1f, 0x0001 }, |
| 3076 | { 0x04, 0x0000 }, |
| 3077 | { 0x03, 0x00a1 }, |
| 3078 | { 0x02, 0x0008 }, |
| 3079 | { 0x01, 0x0120 }, |
| 3080 | { 0x00, 0x1000 }, |
| 3081 | { 0x04, 0x0800 }, |
| 3082 | { 0x04, 0x9000 }, |
| 3083 | { 0x03, 0x802f }, |
| 3084 | { 0x02, 0x4f02 }, |
| 3085 | { 0x01, 0x0409 }, |
| 3086 | { 0x00, 0xf099 }, |
| 3087 | { 0x04, 0x9800 }, |
| 3088 | { 0x04, 0xa000 }, |
| 3089 | { 0x03, 0xdf01 }, |
| 3090 | { 0x02, 0xdf20 }, |
| 3091 | { 0x01, 0xff95 }, |
| 3092 | { 0x00, 0xba00 }, |
| 3093 | { 0x04, 0xa800 }, |
| 3094 | { 0x04, 0xf000 }, |
| 3095 | { 0x03, 0xdf01 }, |
| 3096 | { 0x02, 0xdf20 }, |
| 3097 | { 0x01, 0x101a }, |
| 3098 | { 0x00, 0xa0ff }, |
| 3099 | { 0x04, 0xf800 }, |
| 3100 | { 0x04, 0x0000 }, |
| 3101 | { 0x1f, 0x0000 }, |
| 3102 | |
| 3103 | { 0x1f, 0x0001 }, |
| 3104 | { 0x0b, 0x8480 }, |
| 3105 | { 0x1f, 0x0000 }, |
| 3106 | |
| 3107 | { 0x1f, 0x0001 }, |
| 3108 | { 0x18, 0x67c7 }, |
| 3109 | { 0x04, 0x2000 }, |
| 3110 | { 0x03, 0x002f }, |
| 3111 | { 0x02, 0x4360 }, |
| 3112 | { 0x01, 0x0109 }, |
| 3113 | { 0x00, 0x3022 }, |
| 3114 | { 0x04, 0x2800 }, |
| 3115 | { 0x1f, 0x0000 }, |
| 3116 | |
| 3117 | { 0x1f, 0x0001 }, |
| 3118 | { 0x17, 0x0cc0 }, |
| 3119 | { 0x1f, 0x0000 } |
| 3120 | }; |
| 3121 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3122 | 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] | 3123 | } |
| 3124 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3125 | static void rtl8168bb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3126 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3127 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3128 | { 0x10, 0xf41b }, |
| 3129 | { 0x1f, 0x0000 } |
| 3130 | }; |
| 3131 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3132 | rtl_writephy(tp, 0x1f, 0x0001); |
| 3133 | rtl_patchphy(tp, 0x16, 1 << 0); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3134 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3135 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3136 | } |
| 3137 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3138 | static void rtl8168bef_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3139 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3140 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3141 | { 0x1f, 0x0001 }, |
| 3142 | { 0x10, 0xf41b }, |
| 3143 | { 0x1f, 0x0000 } |
| 3144 | }; |
| 3145 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3146 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3147 | } |
| 3148 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3149 | static void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3150 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3151 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3152 | { 0x1f, 0x0000 }, |
| 3153 | { 0x1d, 0x0f00 }, |
| 3154 | { 0x1f, 0x0002 }, |
| 3155 | { 0x0c, 0x1ec8 }, |
| 3156 | { 0x1f, 0x0000 } |
| 3157 | }; |
| 3158 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3159 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3160 | } |
| 3161 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3162 | static void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3163 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3164 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3165 | { 0x1f, 0x0001 }, |
| 3166 | { 0x1d, 0x3d98 }, |
| 3167 | { 0x1f, 0x0000 } |
| 3168 | }; |
| 3169 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3170 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3171 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 3172 | rtl_patchphy(tp, 0x0d, 1 << 5); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3173 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3174 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3175 | } |
| 3176 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3177 | static void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3178 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3179 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a3f8067 | 2007-10-18 14:35:11 +0200 | [diff] [blame] | 3180 | { 0x1f, 0x0001 }, |
| 3181 | { 0x12, 0x2300 }, |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3182 | { 0x1f, 0x0002 }, |
| 3183 | { 0x00, 0x88d4 }, |
| 3184 | { 0x01, 0x82b1 }, |
| 3185 | { 0x03, 0x7002 }, |
| 3186 | { 0x08, 0x9e30 }, |
| 3187 | { 0x09, 0x01f0 }, |
| 3188 | { 0x0a, 0x5500 }, |
| 3189 | { 0x0c, 0x00c8 }, |
| 3190 | { 0x1f, 0x0003 }, |
| 3191 | { 0x12, 0xc096 }, |
| 3192 | { 0x16, 0x000a }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3193 | { 0x1f, 0x0000 }, |
| 3194 | { 0x1f, 0x0000 }, |
| 3195 | { 0x09, 0x2000 }, |
| 3196 | { 0x09, 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 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3200 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3201 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 3202 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3203 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3204 | } |
| 3205 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3206 | static void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3207 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3208 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3209 | { 0x1f, 0x0001 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3210 | { 0x12, 0x2300 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3211 | { 0x03, 0x802f }, |
| 3212 | { 0x02, 0x4f02 }, |
| 3213 | { 0x01, 0x0409 }, |
| 3214 | { 0x00, 0xf099 }, |
| 3215 | { 0x04, 0x9800 }, |
| 3216 | { 0x04, 0x9000 }, |
| 3217 | { 0x1d, 0x3d98 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3218 | { 0x1f, 0x0002 }, |
| 3219 | { 0x0c, 0x7eb8 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3220 | { 0x06, 0x0761 }, |
| 3221 | { 0x1f, 0x0003 }, |
| 3222 | { 0x16, 0x0f0a }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3223 | { 0x1f, 0x0000 } |
| 3224 | }; |
| 3225 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3226 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3227 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3228 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 3229 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 3230 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3231 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3232 | } |
| 3233 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3234 | static void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3235 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3236 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3237 | { 0x1f, 0x0001 }, |
| 3238 | { 0x12, 0x2300 }, |
| 3239 | { 0x1d, 0x3d98 }, |
| 3240 | { 0x1f, 0x0002 }, |
| 3241 | { 0x0c, 0x7eb8 }, |
| 3242 | { 0x06, 0x5461 }, |
| 3243 | { 0x1f, 0x0003 }, |
| 3244 | { 0x16, 0x0f0a }, |
| 3245 | { 0x1f, 0x0000 } |
| 3246 | }; |
| 3247 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3248 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3249 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3250 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 3251 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 3252 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3253 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3254 | } |
| 3255 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3256 | static void rtl8168c_4_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3257 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3258 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3259 | } |
| 3260 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3261 | static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3262 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3263 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3264 | /* Channel Estimation */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3265 | { 0x1f, 0x0001 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3266 | { 0x06, 0x4064 }, |
| 3267 | { 0x07, 0x2863 }, |
| 3268 | { 0x08, 0x059c }, |
| 3269 | { 0x09, 0x26b4 }, |
| 3270 | { 0x0a, 0x6a19 }, |
| 3271 | { 0x0b, 0xdcc8 }, |
| 3272 | { 0x10, 0xf06d }, |
| 3273 | { 0x14, 0x7f68 }, |
| 3274 | { 0x18, 0x7fd9 }, |
| 3275 | { 0x1c, 0xf0ff }, |
| 3276 | { 0x1d, 0x3d9c }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3277 | { 0x1f, 0x0003 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3278 | { 0x12, 0xf49f }, |
| 3279 | { 0x13, 0x070b }, |
| 3280 | { 0x1a, 0x05ad }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3281 | { 0x14, 0x94c0 }, |
| 3282 | |
| 3283 | /* |
| 3284 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3285 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3286 | */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3287 | { 0x1f, 0x0002 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3288 | { 0x06, 0x5561 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3289 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3290 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3291 | { 0x06, 0x5561 }, |
| 3292 | |
| 3293 | /* |
| 3294 | * Can not link to 1Gbps with bad cable |
| 3295 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 3296 | */ |
| 3297 | { 0x1f, 0x0001 }, |
| 3298 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3299 | |
| 3300 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3301 | { 0x0d, 0xf880 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3302 | }; |
| 3303 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3304 | 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] | 3305 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3306 | /* |
| 3307 | * Rx Error Issue |
| 3308 | * Fine Tune Switching regulator parameter |
| 3309 | */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3310 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3311 | rtl_w0w1_phy(tp, 0x0b, 0x0010, 0x00ef); |
| 3312 | rtl_w0w1_phy(tp, 0x0c, 0xa200, 0x5d00); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3313 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3314 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3315 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3316 | { 0x1f, 0x0002 }, |
| 3317 | { 0x05, 0x669a }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3318 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3319 | { 0x05, 0x8330 }, |
| 3320 | { 0x06, 0x669a }, |
| 3321 | { 0x1f, 0x0002 } |
| 3322 | }; |
| 3323 | int val; |
| 3324 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3325 | 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] | 3326 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3327 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3328 | |
| 3329 | if ((val & 0x00ff) != 0x006c) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3330 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3331 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 3332 | 0x0069, 0x006a, 0x006b, 0x006c |
| 3333 | }; |
| 3334 | int i; |
| 3335 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3336 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3337 | |
| 3338 | val &= 0xff00; |
| 3339 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3340 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3341 | } |
| 3342 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3343 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3344 | { 0x1f, 0x0002 }, |
| 3345 | { 0x05, 0x6662 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3346 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3347 | { 0x05, 0x8330 }, |
| 3348 | { 0x06, 0x6662 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3349 | }; |
| 3350 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3351 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3352 | } |
| 3353 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3354 | /* RSET couple improve */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3355 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3356 | rtl_patchphy(tp, 0x0d, 0x0300); |
| 3357 | rtl_patchphy(tp, 0x0f, 0x0010); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3358 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3359 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3360 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3361 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 3362 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3363 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3364 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3365 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3366 | |
| 3367 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3368 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3369 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3370 | } |
| 3371 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3372 | static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3373 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3374 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3375 | /* Channel Estimation */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3376 | { 0x1f, 0x0001 }, |
| 3377 | { 0x06, 0x4064 }, |
| 3378 | { 0x07, 0x2863 }, |
| 3379 | { 0x08, 0x059c }, |
| 3380 | { 0x09, 0x26b4 }, |
| 3381 | { 0x0a, 0x6a19 }, |
| 3382 | { 0x0b, 0xdcc8 }, |
| 3383 | { 0x10, 0xf06d }, |
| 3384 | { 0x14, 0x7f68 }, |
| 3385 | { 0x18, 0x7fd9 }, |
| 3386 | { 0x1c, 0xf0ff }, |
| 3387 | { 0x1d, 0x3d9c }, |
| 3388 | { 0x1f, 0x0003 }, |
| 3389 | { 0x12, 0xf49f }, |
| 3390 | { 0x13, 0x070b }, |
| 3391 | { 0x1a, 0x05ad }, |
| 3392 | { 0x14, 0x94c0 }, |
| 3393 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3394 | /* |
| 3395 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3396 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3397 | */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3398 | { 0x1f, 0x0002 }, |
| 3399 | { 0x06, 0x5561 }, |
| 3400 | { 0x1f, 0x0005 }, |
| 3401 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3402 | { 0x06, 0x5561 }, |
| 3403 | |
| 3404 | /* |
| 3405 | * Can not link to 1Gbps with bad cable |
| 3406 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 3407 | */ |
| 3408 | { 0x1f, 0x0001 }, |
| 3409 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3410 | |
| 3411 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3412 | { 0x0d, 0xf880 } |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3413 | }; |
| 3414 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3415 | 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] | 3416 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3417 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3418 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3419 | { 0x1f, 0x0002 }, |
| 3420 | { 0x05, 0x669a }, |
| 3421 | { 0x1f, 0x0005 }, |
| 3422 | { 0x05, 0x8330 }, |
| 3423 | { 0x06, 0x669a }, |
| 3424 | |
| 3425 | { 0x1f, 0x0002 } |
| 3426 | }; |
| 3427 | int val; |
| 3428 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3429 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3430 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3431 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3432 | if ((val & 0x00ff) != 0x006c) { |
Joe Perches | b6bc765 | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 3433 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3434 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 3435 | 0x0069, 0x006a, 0x006b, 0x006c |
| 3436 | }; |
| 3437 | int i; |
| 3438 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3439 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3440 | |
| 3441 | val &= 0xff00; |
| 3442 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3443 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3444 | } |
| 3445 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3446 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3447 | { 0x1f, 0x0002 }, |
| 3448 | { 0x05, 0x2642 }, |
| 3449 | { 0x1f, 0x0005 }, |
| 3450 | { 0x05, 0x8330 }, |
| 3451 | { 0x06, 0x2642 } |
| 3452 | }; |
| 3453 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3454 | 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] | 3455 | } |
| 3456 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3457 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3458 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3459 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 3460 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3461 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3462 | /* Switching regulator Slew rate */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3463 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3464 | rtl_patchphy(tp, 0x0f, 0x0017); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3465 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3466 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3467 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3468 | |
| 3469 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3470 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3471 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3472 | } |
| 3473 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3474 | static void rtl8168d_3_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3475 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3476 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3477 | { 0x1f, 0x0002 }, |
| 3478 | { 0x10, 0x0008 }, |
| 3479 | { 0x0d, 0x006c }, |
| 3480 | |
| 3481 | { 0x1f, 0x0000 }, |
| 3482 | { 0x0d, 0xf880 }, |
| 3483 | |
| 3484 | { 0x1f, 0x0001 }, |
| 3485 | { 0x17, 0x0cc0 }, |
| 3486 | |
| 3487 | { 0x1f, 0x0001 }, |
| 3488 | { 0x0b, 0xa4d8 }, |
| 3489 | { 0x09, 0x281c }, |
| 3490 | { 0x07, 0x2883 }, |
| 3491 | { 0x0a, 0x6b35 }, |
| 3492 | { 0x1d, 0x3da4 }, |
| 3493 | { 0x1c, 0xeffd }, |
| 3494 | { 0x14, 0x7f52 }, |
| 3495 | { 0x18, 0x7fc6 }, |
| 3496 | { 0x08, 0x0601 }, |
| 3497 | { 0x06, 0x4063 }, |
| 3498 | { 0x10, 0xf074 }, |
| 3499 | { 0x1f, 0x0003 }, |
| 3500 | { 0x13, 0x0789 }, |
| 3501 | { 0x12, 0xf4bd }, |
| 3502 | { 0x1a, 0x04fd }, |
| 3503 | { 0x14, 0x84b0 }, |
| 3504 | { 0x1f, 0x0000 }, |
| 3505 | { 0x00, 0x9200 }, |
| 3506 | |
| 3507 | { 0x1f, 0x0005 }, |
| 3508 | { 0x01, 0x0340 }, |
| 3509 | { 0x1f, 0x0001 }, |
| 3510 | { 0x04, 0x4000 }, |
| 3511 | { 0x03, 0x1d21 }, |
| 3512 | { 0x02, 0x0c32 }, |
| 3513 | { 0x01, 0x0200 }, |
| 3514 | { 0x00, 0x5554 }, |
| 3515 | { 0x04, 0x4800 }, |
| 3516 | { 0x04, 0x4000 }, |
| 3517 | { 0x04, 0xf000 }, |
| 3518 | { 0x03, 0xdf01 }, |
| 3519 | { 0x02, 0xdf20 }, |
| 3520 | { 0x01, 0x101a }, |
| 3521 | { 0x00, 0xa0ff }, |
| 3522 | { 0x04, 0xf800 }, |
| 3523 | { 0x04, 0xf000 }, |
| 3524 | { 0x1f, 0x0000 }, |
| 3525 | |
| 3526 | { 0x1f, 0x0007 }, |
| 3527 | { 0x1e, 0x0023 }, |
| 3528 | { 0x16, 0x0000 }, |
| 3529 | { 0x1f, 0x0000 } |
| 3530 | }; |
| 3531 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3532 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3533 | } |
| 3534 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3535 | static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp) |
| 3536 | { |
| 3537 | static const struct phy_reg phy_reg_init[] = { |
| 3538 | { 0x1f, 0x0001 }, |
| 3539 | { 0x17, 0x0cc0 }, |
| 3540 | |
| 3541 | { 0x1f, 0x0007 }, |
| 3542 | { 0x1e, 0x002d }, |
| 3543 | { 0x18, 0x0040 }, |
| 3544 | { 0x1f, 0x0000 } |
| 3545 | }; |
| 3546 | |
| 3547 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3548 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3549 | } |
| 3550 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3551 | static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3552 | { |
| 3553 | static const struct phy_reg phy_reg_init[] = { |
| 3554 | /* Enable Delay cap */ |
| 3555 | { 0x1f, 0x0005 }, |
| 3556 | { 0x05, 0x8b80 }, |
| 3557 | { 0x06, 0xc896 }, |
| 3558 | { 0x1f, 0x0000 }, |
| 3559 | |
| 3560 | /* Channel estimation fine tune */ |
| 3561 | { 0x1f, 0x0001 }, |
| 3562 | { 0x0b, 0x6c20 }, |
| 3563 | { 0x07, 0x2872 }, |
| 3564 | { 0x1c, 0xefff }, |
| 3565 | { 0x1f, 0x0003 }, |
| 3566 | { 0x14, 0x6420 }, |
| 3567 | { 0x1f, 0x0000 }, |
| 3568 | |
| 3569 | /* Update PFM & 10M TX idle timer */ |
| 3570 | { 0x1f, 0x0007 }, |
| 3571 | { 0x1e, 0x002f }, |
| 3572 | { 0x15, 0x1919 }, |
| 3573 | { 0x1f, 0x0000 }, |
| 3574 | |
| 3575 | { 0x1f, 0x0007 }, |
| 3576 | { 0x1e, 0x00ac }, |
| 3577 | { 0x18, 0x0006 }, |
| 3578 | { 0x1f, 0x0000 } |
| 3579 | }; |
| 3580 | |
Francois Romieu | 15ecd03 | 2011-04-27 13:52:22 -0700 | [diff] [blame] | 3581 | rtl_apply_firmware(tp); |
| 3582 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3583 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3584 | |
| 3585 | /* DCO enable for 10M IDLE Power */ |
| 3586 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3587 | rtl_writephy(tp, 0x1e, 0x0023); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3588 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3589 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3590 | |
| 3591 | /* For impedance matching */ |
| 3592 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3593 | rtl_w0w1_phy(tp, 0x08, 0x8000, 0x7f00); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3594 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3595 | |
| 3596 | /* PHY auto speed down */ |
| 3597 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3598 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3599 | rtl_w0w1_phy(tp, 0x18, 0x0050, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3600 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3601 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3602 | |
| 3603 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3604 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3605 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3606 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3607 | |
| 3608 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3609 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3610 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3611 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3612 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3613 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x1100); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3614 | rtl_writephy(tp, 0x1f, 0x0006); |
| 3615 | rtl_writephy(tp, 0x00, 0x5a00); |
| 3616 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3617 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3618 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3619 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3620 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3621 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3622 | } |
| 3623 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3624 | static void rtl_rar_exgmac_set(struct rtl8169_private *tp, u8 *addr) |
| 3625 | { |
| 3626 | const u16 w[] = { |
| 3627 | addr[0] | (addr[1] << 8), |
| 3628 | addr[2] | (addr[3] << 8), |
| 3629 | addr[4] | (addr[5] << 8) |
| 3630 | }; |
| 3631 | const struct exgmac_reg e[] = { |
| 3632 | { .addr = 0xe0, ERIAR_MASK_1111, .val = w[0] | (w[1] << 16) }, |
| 3633 | { .addr = 0xe4, ERIAR_MASK_1111, .val = w[2] }, |
| 3634 | { .addr = 0xf0, ERIAR_MASK_1111, .val = w[0] << 16 }, |
| 3635 | { .addr = 0xf4, ERIAR_MASK_1111, .val = w[1] | (w[2] << 16) } |
| 3636 | }; |
| 3637 | |
| 3638 | rtl_write_exgmac_batch(tp, e, ARRAY_SIZE(e)); |
| 3639 | } |
| 3640 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3641 | static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp) |
| 3642 | { |
| 3643 | static const struct phy_reg phy_reg_init[] = { |
| 3644 | /* Enable Delay cap */ |
| 3645 | { 0x1f, 0x0004 }, |
| 3646 | { 0x1f, 0x0007 }, |
| 3647 | { 0x1e, 0x00ac }, |
| 3648 | { 0x18, 0x0006 }, |
| 3649 | { 0x1f, 0x0002 }, |
| 3650 | { 0x1f, 0x0000 }, |
| 3651 | { 0x1f, 0x0000 }, |
| 3652 | |
| 3653 | /* Channel estimation fine tune */ |
| 3654 | { 0x1f, 0x0003 }, |
| 3655 | { 0x09, 0xa20f }, |
| 3656 | { 0x1f, 0x0000 }, |
| 3657 | { 0x1f, 0x0000 }, |
| 3658 | |
| 3659 | /* Green Setting */ |
| 3660 | { 0x1f, 0x0005 }, |
| 3661 | { 0x05, 0x8b5b }, |
| 3662 | { 0x06, 0x9222 }, |
| 3663 | { 0x05, 0x8b6d }, |
| 3664 | { 0x06, 0x8000 }, |
| 3665 | { 0x05, 0x8b76 }, |
| 3666 | { 0x06, 0x8000 }, |
| 3667 | { 0x1f, 0x0000 } |
| 3668 | }; |
| 3669 | |
| 3670 | rtl_apply_firmware(tp); |
| 3671 | |
| 3672 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3673 | |
| 3674 | /* For 4-corner performance improve */ |
| 3675 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3676 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3677 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3678 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3679 | |
| 3680 | /* PHY auto speed down */ |
| 3681 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3682 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3683 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3684 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3685 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3686 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3687 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3688 | |
| 3689 | /* improve 10M EEE waveform */ |
| 3690 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3691 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3692 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3693 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3694 | |
| 3695 | /* Improve 2-pair detection performance */ |
| 3696 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3697 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3698 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3699 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3700 | |
| 3701 | /* EEE setting */ |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3702 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_1111, 0x0003, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3703 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3704 | rtl_writephy(tp, 0x05, 0x8b85); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3705 | rtl_w0w1_phy(tp, 0x06, 0x2000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3706 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3707 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3708 | rtl_writephy(tp, 0x1e, 0x0020); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3709 | rtl_w0w1_phy(tp, 0x15, 0x0100, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3710 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3711 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3712 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3713 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3714 | rtl_writephy(tp, 0x0d, 0x4007); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3715 | rtl_writephy(tp, 0x0e, 0x0006); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3716 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3717 | |
| 3718 | /* Green feature */ |
| 3719 | rtl_writephy(tp, 0x1f, 0x0003); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3720 | rtl_w0w1_phy(tp, 0x19, 0x0001, 0x0000); |
| 3721 | rtl_w0w1_phy(tp, 0x10, 0x0400, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3722 | rtl_writephy(tp, 0x1f, 0x0000); |
Heiner Kallweit | b399a39 | 2017-11-19 11:15:46 +0100 | [diff] [blame] | 3723 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3724 | rtl_w0w1_phy(tp, 0x01, 0x0100, 0x0000); |
| 3725 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | e0c0755 | 2012-10-23 20:24:03 +0000 | [diff] [blame] | 3726 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3727 | /* Broken BIOS workaround: feed GigaMAC registers with MAC address. */ |
| 3728 | rtl_rar_exgmac_set(tp, tp->dev->dev_addr); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3729 | } |
| 3730 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3731 | static void rtl8168f_hw_phy_config(struct rtl8169_private *tp) |
| 3732 | { |
| 3733 | /* For 4-corner performance improve */ |
| 3734 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3735 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3736 | rtl_w0w1_phy(tp, 0x06, 0x0006, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3737 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3738 | |
| 3739 | /* PHY auto speed down */ |
| 3740 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3741 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3742 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3743 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3744 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3745 | |
| 3746 | /* Improve 10M EEE waveform */ |
| 3747 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3748 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3749 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3750 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3751 | } |
| 3752 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3753 | static void rtl8168f_1_hw_phy_config(struct rtl8169_private *tp) |
| 3754 | { |
| 3755 | static const struct phy_reg phy_reg_init[] = { |
| 3756 | /* Channel estimation fine tune */ |
| 3757 | { 0x1f, 0x0003 }, |
| 3758 | { 0x09, 0xa20f }, |
| 3759 | { 0x1f, 0x0000 }, |
| 3760 | |
| 3761 | /* Modify green table for giga & fnet */ |
| 3762 | { 0x1f, 0x0005 }, |
| 3763 | { 0x05, 0x8b55 }, |
| 3764 | { 0x06, 0x0000 }, |
| 3765 | { 0x05, 0x8b5e }, |
| 3766 | { 0x06, 0x0000 }, |
| 3767 | { 0x05, 0x8b67 }, |
| 3768 | { 0x06, 0x0000 }, |
| 3769 | { 0x05, 0x8b70 }, |
| 3770 | { 0x06, 0x0000 }, |
| 3771 | { 0x1f, 0x0000 }, |
| 3772 | { 0x1f, 0x0007 }, |
| 3773 | { 0x1e, 0x0078 }, |
| 3774 | { 0x17, 0x0000 }, |
| 3775 | { 0x19, 0x00fb }, |
| 3776 | { 0x1f, 0x0000 }, |
| 3777 | |
| 3778 | /* Modify green table for 10M */ |
| 3779 | { 0x1f, 0x0005 }, |
| 3780 | { 0x05, 0x8b79 }, |
| 3781 | { 0x06, 0xaa00 }, |
| 3782 | { 0x1f, 0x0000 }, |
| 3783 | |
| 3784 | /* Disable hiimpedance detection (RTCT) */ |
| 3785 | { 0x1f, 0x0003 }, |
| 3786 | { 0x01, 0x328a }, |
| 3787 | { 0x1f, 0x0000 } |
| 3788 | }; |
| 3789 | |
| 3790 | rtl_apply_firmware(tp); |
| 3791 | |
| 3792 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3793 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3794 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3795 | |
| 3796 | /* Improve 2-pair detection performance */ |
| 3797 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3798 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3799 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3800 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3801 | } |
| 3802 | |
| 3803 | static void rtl8168f_2_hw_phy_config(struct rtl8169_private *tp) |
| 3804 | { |
| 3805 | rtl_apply_firmware(tp); |
| 3806 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3807 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3808 | } |
| 3809 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3810 | static void rtl8411_hw_phy_config(struct rtl8169_private *tp) |
| 3811 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3812 | static const struct phy_reg phy_reg_init[] = { |
| 3813 | /* Channel estimation fine tune */ |
| 3814 | { 0x1f, 0x0003 }, |
| 3815 | { 0x09, 0xa20f }, |
| 3816 | { 0x1f, 0x0000 }, |
| 3817 | |
| 3818 | /* Modify green table for giga & fnet */ |
| 3819 | { 0x1f, 0x0005 }, |
| 3820 | { 0x05, 0x8b55 }, |
| 3821 | { 0x06, 0x0000 }, |
| 3822 | { 0x05, 0x8b5e }, |
| 3823 | { 0x06, 0x0000 }, |
| 3824 | { 0x05, 0x8b67 }, |
| 3825 | { 0x06, 0x0000 }, |
| 3826 | { 0x05, 0x8b70 }, |
| 3827 | { 0x06, 0x0000 }, |
| 3828 | { 0x1f, 0x0000 }, |
| 3829 | { 0x1f, 0x0007 }, |
| 3830 | { 0x1e, 0x0078 }, |
| 3831 | { 0x17, 0x0000 }, |
| 3832 | { 0x19, 0x00aa }, |
| 3833 | { 0x1f, 0x0000 }, |
| 3834 | |
| 3835 | /* Modify green table for 10M */ |
| 3836 | { 0x1f, 0x0005 }, |
| 3837 | { 0x05, 0x8b79 }, |
| 3838 | { 0x06, 0xaa00 }, |
| 3839 | { 0x1f, 0x0000 }, |
| 3840 | |
| 3841 | /* Disable hiimpedance detection (RTCT) */ |
| 3842 | { 0x1f, 0x0003 }, |
| 3843 | { 0x01, 0x328a }, |
| 3844 | { 0x1f, 0x0000 } |
| 3845 | }; |
| 3846 | |
| 3847 | |
| 3848 | rtl_apply_firmware(tp); |
| 3849 | |
| 3850 | rtl8168f_hw_phy_config(tp); |
| 3851 | |
| 3852 | /* Improve 2-pair detection performance */ |
| 3853 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3854 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3855 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3856 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3857 | |
| 3858 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3859 | |
| 3860 | /* Modify green table for giga */ |
| 3861 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3862 | rtl_writephy(tp, 0x05, 0x8b54); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3863 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3864 | rtl_writephy(tp, 0x05, 0x8b5d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3865 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3866 | rtl_writephy(tp, 0x05, 0x8a7c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3867 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3868 | rtl_writephy(tp, 0x05, 0x8a7f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3869 | rtl_w0w1_phy(tp, 0x06, 0x0100, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3870 | rtl_writephy(tp, 0x05, 0x8a82); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3871 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3872 | rtl_writephy(tp, 0x05, 0x8a85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3873 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3874 | rtl_writephy(tp, 0x05, 0x8a88); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3875 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3876 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3877 | |
| 3878 | /* uc same-seed solution */ |
| 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, 0x8000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3882 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3883 | |
| 3884 | /* eee setting */ |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 3885 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x00, 0x03, ERIAR_EXGMAC); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3886 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3887 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3888 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3889 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3890 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3891 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3892 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3893 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3894 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3895 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3896 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3897 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3898 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3899 | |
| 3900 | /* Green feature */ |
| 3901 | rtl_writephy(tp, 0x1f, 0x0003); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3902 | rtl_w0w1_phy(tp, 0x19, 0x0000, 0x0001); |
| 3903 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0400); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3904 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3905 | } |
| 3906 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3907 | static void rtl8168g_1_hw_phy_config(struct rtl8169_private *tp) |
| 3908 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3909 | rtl_apply_firmware(tp); |
| 3910 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3911 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3912 | if (rtl_readphy(tp, 0x10) & 0x0100) { |
| 3913 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3914 | rtl_w0w1_phy(tp, 0x12, 0x0000, 0x8000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3915 | } else { |
| 3916 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3917 | rtl_w0w1_phy(tp, 0x12, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3918 | } |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3919 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3920 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3921 | if (rtl_readphy(tp, 0x13) & 0x0100) { |
| 3922 | rtl_writephy(tp, 0x1f, 0x0c41); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3923 | rtl_w0w1_phy(tp, 0x15, 0x0002, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3924 | } else { |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3925 | rtl_writephy(tp, 0x1f, 0x0c41); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3926 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0002); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3927 | } |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3928 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3929 | /* Enable PHY auto speed down */ |
| 3930 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3931 | rtl_w0w1_phy(tp, 0x11, 0x000c, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3932 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3933 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3934 | rtl_w0w1_phy(tp, 0x14, 0x0100, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3935 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3936 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3937 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3938 | rtl_writephy(tp, 0x13, 0x8084); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3939 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 3940 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3941 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3942 | /* EEE auto-fallback function */ |
| 3943 | rtl_writephy(tp, 0x1f, 0x0a4b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3944 | rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3945 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3946 | /* Enable UC LPF tune function */ |
| 3947 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3948 | rtl_writephy(tp, 0x13, 0x8012); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3949 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3950 | |
| 3951 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3952 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3953 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3954 | /* Improve SWR Efficiency */ |
| 3955 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3956 | rtl_writephy(tp, 0x14, 0x5065); |
| 3957 | rtl_writephy(tp, 0x14, 0xd065); |
| 3958 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 3959 | rtl_writephy(tp, 0x11, 0x5655); |
| 3960 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3961 | rtl_writephy(tp, 0x14, 0x1065); |
| 3962 | rtl_writephy(tp, 0x14, 0x9065); |
| 3963 | rtl_writephy(tp, 0x14, 0x1065); |
| 3964 | |
David Chang | 1bac107 | 2013-11-27 15:48:36 +0800 | [diff] [blame] | 3965 | /* Check ALDPS bit, disable it if enabled */ |
| 3966 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3967 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3968 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
David Chang | 1bac107 | 2013-11-27 15:48:36 +0800 | [diff] [blame] | 3969 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3970 | rtl_writephy(tp, 0x1f, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3971 | } |
| 3972 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 3973 | static void rtl8168g_2_hw_phy_config(struct rtl8169_private *tp) |
| 3974 | { |
| 3975 | rtl_apply_firmware(tp); |
| 3976 | } |
| 3977 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3978 | static void rtl8168h_1_hw_phy_config(struct rtl8169_private *tp) |
| 3979 | { |
| 3980 | u16 dout_tapbin; |
| 3981 | u32 data; |
| 3982 | |
| 3983 | rtl_apply_firmware(tp); |
| 3984 | |
| 3985 | /* CHN EST parameters adjust - giga master */ |
| 3986 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3987 | rtl_writephy(tp, 0x13, 0x809b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3988 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3989 | rtl_writephy(tp, 0x13, 0x80a2); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3990 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3991 | rtl_writephy(tp, 0x13, 0x80a4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3992 | rtl_w0w1_phy(tp, 0x14, 0x8500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3993 | rtl_writephy(tp, 0x13, 0x809c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3994 | rtl_w0w1_phy(tp, 0x14, 0xbd00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3995 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3996 | |
| 3997 | /* CHN EST parameters adjust - giga slave */ |
| 3998 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3999 | rtl_writephy(tp, 0x13, 0x80ad); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4000 | rtl_w0w1_phy(tp, 0x14, 0x7000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4001 | rtl_writephy(tp, 0x13, 0x80b4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4002 | rtl_w0w1_phy(tp, 0x14, 0x5000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4003 | rtl_writephy(tp, 0x13, 0x80ac); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4004 | rtl_w0w1_phy(tp, 0x14, 0x4000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4005 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4006 | |
| 4007 | /* CHN EST parameters adjust - fnet */ |
| 4008 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4009 | rtl_writephy(tp, 0x13, 0x808e); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4010 | rtl_w0w1_phy(tp, 0x14, 0x1200, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4011 | rtl_writephy(tp, 0x13, 0x8090); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4012 | rtl_w0w1_phy(tp, 0x14, 0xe500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4013 | rtl_writephy(tp, 0x13, 0x8092); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4014 | rtl_w0w1_phy(tp, 0x14, 0x9f00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4015 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4016 | |
| 4017 | /* enable R-tune & PGA-retune function */ |
| 4018 | dout_tapbin = 0; |
| 4019 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 4020 | data = rtl_readphy(tp, 0x13); |
| 4021 | data &= 3; |
| 4022 | data <<= 2; |
| 4023 | dout_tapbin |= data; |
| 4024 | data = rtl_readphy(tp, 0x12); |
| 4025 | data &= 0xc000; |
| 4026 | data >>= 14; |
| 4027 | dout_tapbin |= data; |
| 4028 | dout_tapbin = ~(dout_tapbin^0x08); |
| 4029 | dout_tapbin <<= 12; |
| 4030 | dout_tapbin &= 0xf000; |
| 4031 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4032 | rtl_writephy(tp, 0x13, 0x827a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4033 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4034 | rtl_writephy(tp, 0x13, 0x827b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4035 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4036 | rtl_writephy(tp, 0x13, 0x827c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4037 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4038 | rtl_writephy(tp, 0x13, 0x827d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4039 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4040 | |
| 4041 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4042 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4043 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4044 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4045 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4046 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4047 | |
| 4048 | /* enable GPHY 10M */ |
| 4049 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4050 | rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4051 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4052 | |
| 4053 | /* SAR ADC performance */ |
| 4054 | rtl_writephy(tp, 0x1f, 0x0bca); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4055 | rtl_w0w1_phy(tp, 0x17, 0x4000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4056 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4057 | |
| 4058 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4059 | rtl_writephy(tp, 0x13, 0x803f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4060 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4061 | rtl_writephy(tp, 0x13, 0x8047); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4062 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4063 | rtl_writephy(tp, 0x13, 0x804f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4064 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4065 | rtl_writephy(tp, 0x13, 0x8057); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4066 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4067 | rtl_writephy(tp, 0x13, 0x805f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4068 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4069 | rtl_writephy(tp, 0x13, 0x8067); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4070 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4071 | rtl_writephy(tp, 0x13, 0x806f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4072 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4073 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4074 | |
| 4075 | /* disable phy pfm mode */ |
| 4076 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | c832c35f | 2015-12-29 22:13:38 +0800 | [diff] [blame] | 4077 | rtl_w0w1_phy(tp, 0x11, 0x0000, 0x0080); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4078 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4079 | |
| 4080 | /* Check ALDPS bit, disable it if enabled */ |
| 4081 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4082 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4083 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4084 | |
| 4085 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4086 | } |
| 4087 | |
| 4088 | static void rtl8168h_2_hw_phy_config(struct rtl8169_private *tp) |
| 4089 | { |
| 4090 | u16 ioffset_p3, ioffset_p2, ioffset_p1, ioffset_p0; |
| 4091 | u16 rlen; |
| 4092 | u32 data; |
| 4093 | |
| 4094 | rtl_apply_firmware(tp); |
| 4095 | |
| 4096 | /* CHIN EST parameter update */ |
| 4097 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4098 | rtl_writephy(tp, 0x13, 0x808a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4099 | rtl_w0w1_phy(tp, 0x14, 0x000a, 0x003f); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4100 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4101 | |
| 4102 | /* enable R-tune & PGA-retune function */ |
| 4103 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4104 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4105 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4106 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4107 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4108 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4109 | |
| 4110 | /* enable GPHY 10M */ |
| 4111 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4112 | rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4113 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4114 | |
| 4115 | r8168_mac_ocp_write(tp, 0xdd02, 0x807d); |
| 4116 | data = r8168_mac_ocp_read(tp, 0xdd02); |
| 4117 | ioffset_p3 = ((data & 0x80)>>7); |
| 4118 | ioffset_p3 <<= 3; |
| 4119 | |
| 4120 | data = r8168_mac_ocp_read(tp, 0xdd00); |
| 4121 | ioffset_p3 |= ((data & (0xe000))>>13); |
| 4122 | ioffset_p2 = ((data & (0x1e00))>>9); |
| 4123 | ioffset_p1 = ((data & (0x01e0))>>5); |
| 4124 | ioffset_p0 = ((data & 0x0010)>>4); |
| 4125 | ioffset_p0 <<= 3; |
| 4126 | ioffset_p0 |= (data & (0x07)); |
| 4127 | data = (ioffset_p3<<12)|(ioffset_p2<<8)|(ioffset_p1<<4)|(ioffset_p0); |
| 4128 | |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 4129 | if ((ioffset_p3 != 0x0f) || (ioffset_p2 != 0x0f) || |
Chun-Hao Lin | e2e2788 | 2015-12-24 21:15:26 +0800 | [diff] [blame] | 4130 | (ioffset_p1 != 0x0f) || (ioffset_p0 != 0x0f)) { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4131 | rtl_writephy(tp, 0x1f, 0x0bcf); |
| 4132 | rtl_writephy(tp, 0x16, data); |
| 4133 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4134 | } |
| 4135 | |
| 4136 | /* Modify rlen (TX LPF corner frequency) level */ |
| 4137 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4138 | data = rtl_readphy(tp, 0x16); |
| 4139 | data &= 0x000f; |
| 4140 | rlen = 0; |
| 4141 | if (data > 3) |
| 4142 | rlen = data - 3; |
| 4143 | data = rlen | (rlen<<4) | (rlen<<8) | (rlen<<12); |
| 4144 | rtl_writephy(tp, 0x17, data); |
| 4145 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4146 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4147 | |
| 4148 | /* disable phy pfm mode */ |
| 4149 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | c832c35f | 2015-12-29 22:13:38 +0800 | [diff] [blame] | 4150 | rtl_w0w1_phy(tp, 0x11, 0x0000, 0x0080); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4151 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4152 | |
| 4153 | /* Check ALDPS bit, disable it if enabled */ |
| 4154 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4155 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4156 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4157 | |
| 4158 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4159 | } |
| 4160 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4161 | static void rtl8168ep_1_hw_phy_config(struct rtl8169_private *tp) |
| 4162 | { |
| 4163 | /* Enable PHY auto speed down */ |
| 4164 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 4165 | rtl_w0w1_phy(tp, 0x11, 0x000c, 0x0000); |
| 4166 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4167 | |
| 4168 | /* patch 10M & ALDPS */ |
| 4169 | rtl_writephy(tp, 0x1f, 0x0bcc); |
| 4170 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x0100); |
| 4171 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 4172 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
| 4173 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4174 | rtl_writephy(tp, 0x13, 0x8084); |
| 4175 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 4176 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
| 4177 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4178 | |
| 4179 | /* Enable EEE auto-fallback function */ |
| 4180 | rtl_writephy(tp, 0x1f, 0x0a4b); |
| 4181 | rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000); |
| 4182 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4183 | |
| 4184 | /* Enable UC LPF tune function */ |
| 4185 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4186 | rtl_writephy(tp, 0x13, 0x8012); |
| 4187 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 4188 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4189 | |
| 4190 | /* set rg_sel_sdm_rate */ |
| 4191 | rtl_writephy(tp, 0x1f, 0x0c42); |
| 4192 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
| 4193 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4194 | |
| 4195 | /* Check ALDPS bit, disable it if enabled */ |
| 4196 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4197 | if (rtl_readphy(tp, 0x10) & 0x0004) |
| 4198 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
| 4199 | |
| 4200 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4201 | } |
| 4202 | |
| 4203 | static void rtl8168ep_2_hw_phy_config(struct rtl8169_private *tp) |
| 4204 | { |
| 4205 | /* patch 10M & ALDPS */ |
| 4206 | rtl_writephy(tp, 0x1f, 0x0bcc); |
| 4207 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x0100); |
| 4208 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 4209 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
| 4210 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4211 | rtl_writephy(tp, 0x13, 0x8084); |
| 4212 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 4213 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
| 4214 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4215 | |
| 4216 | /* Enable UC LPF tune function */ |
| 4217 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4218 | rtl_writephy(tp, 0x13, 0x8012); |
| 4219 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 4220 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4221 | |
| 4222 | /* Set rg_sel_sdm_rate */ |
| 4223 | rtl_writephy(tp, 0x1f, 0x0c42); |
| 4224 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
| 4225 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4226 | |
| 4227 | /* Channel estimation parameters */ |
| 4228 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4229 | rtl_writephy(tp, 0x13, 0x80f3); |
| 4230 | rtl_w0w1_phy(tp, 0x14, 0x8b00, ~0x8bff); |
| 4231 | rtl_writephy(tp, 0x13, 0x80f0); |
| 4232 | rtl_w0w1_phy(tp, 0x14, 0x3a00, ~0x3aff); |
| 4233 | rtl_writephy(tp, 0x13, 0x80ef); |
| 4234 | rtl_w0w1_phy(tp, 0x14, 0x0500, ~0x05ff); |
| 4235 | rtl_writephy(tp, 0x13, 0x80f6); |
| 4236 | rtl_w0w1_phy(tp, 0x14, 0x6e00, ~0x6eff); |
| 4237 | rtl_writephy(tp, 0x13, 0x80ec); |
| 4238 | rtl_w0w1_phy(tp, 0x14, 0x6800, ~0x68ff); |
| 4239 | rtl_writephy(tp, 0x13, 0x80ed); |
| 4240 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 4241 | rtl_writephy(tp, 0x13, 0x80f2); |
| 4242 | rtl_w0w1_phy(tp, 0x14, 0xf400, ~0xf4ff); |
| 4243 | rtl_writephy(tp, 0x13, 0x80f4); |
| 4244 | rtl_w0w1_phy(tp, 0x14, 0x8500, ~0x85ff); |
| 4245 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4246 | rtl_writephy(tp, 0x13, 0x8110); |
| 4247 | rtl_w0w1_phy(tp, 0x14, 0xa800, ~0xa8ff); |
| 4248 | rtl_writephy(tp, 0x13, 0x810f); |
| 4249 | rtl_w0w1_phy(tp, 0x14, 0x1d00, ~0x1dff); |
| 4250 | rtl_writephy(tp, 0x13, 0x8111); |
| 4251 | rtl_w0w1_phy(tp, 0x14, 0xf500, ~0xf5ff); |
| 4252 | rtl_writephy(tp, 0x13, 0x8113); |
| 4253 | rtl_w0w1_phy(tp, 0x14, 0x6100, ~0x61ff); |
| 4254 | rtl_writephy(tp, 0x13, 0x8115); |
| 4255 | rtl_w0w1_phy(tp, 0x14, 0x9200, ~0x92ff); |
| 4256 | rtl_writephy(tp, 0x13, 0x810e); |
| 4257 | rtl_w0w1_phy(tp, 0x14, 0x0400, ~0x04ff); |
| 4258 | rtl_writephy(tp, 0x13, 0x810c); |
| 4259 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 4260 | rtl_writephy(tp, 0x13, 0x810b); |
| 4261 | rtl_w0w1_phy(tp, 0x14, 0x5a00, ~0x5aff); |
| 4262 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4263 | rtl_writephy(tp, 0x13, 0x80d1); |
| 4264 | rtl_w0w1_phy(tp, 0x14, 0xff00, ~0xffff); |
| 4265 | rtl_writephy(tp, 0x13, 0x80cd); |
| 4266 | rtl_w0w1_phy(tp, 0x14, 0x9e00, ~0x9eff); |
| 4267 | rtl_writephy(tp, 0x13, 0x80d3); |
| 4268 | rtl_w0w1_phy(tp, 0x14, 0x0e00, ~0x0eff); |
| 4269 | rtl_writephy(tp, 0x13, 0x80d5); |
| 4270 | rtl_w0w1_phy(tp, 0x14, 0xca00, ~0xcaff); |
| 4271 | rtl_writephy(tp, 0x13, 0x80d7); |
| 4272 | rtl_w0w1_phy(tp, 0x14, 0x8400, ~0x84ff); |
| 4273 | |
| 4274 | /* Force PWM-mode */ |
| 4275 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4276 | rtl_writephy(tp, 0x14, 0x5065); |
| 4277 | rtl_writephy(tp, 0x14, 0xd065); |
| 4278 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 4279 | rtl_writephy(tp, 0x12, 0x00ed); |
| 4280 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4281 | rtl_writephy(tp, 0x14, 0x1065); |
| 4282 | rtl_writephy(tp, 0x14, 0x9065); |
| 4283 | rtl_writephy(tp, 0x14, 0x1065); |
| 4284 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4285 | |
| 4286 | /* Check ALDPS bit, disable it if enabled */ |
| 4287 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4288 | if (rtl_readphy(tp, 0x10) & 0x0004) |
| 4289 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
| 4290 | |
| 4291 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4292 | } |
| 4293 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4294 | static void rtl8102e_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4295 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4296 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4297 | { 0x1f, 0x0003 }, |
| 4298 | { 0x08, 0x441d }, |
| 4299 | { 0x01, 0x9100 }, |
| 4300 | { 0x1f, 0x0000 } |
| 4301 | }; |
| 4302 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4303 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4304 | rtl_patchphy(tp, 0x11, 1 << 12); |
| 4305 | rtl_patchphy(tp, 0x19, 1 << 13); |
| 4306 | rtl_patchphy(tp, 0x10, 1 << 15); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4307 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4308 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4309 | } |
| 4310 | |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4311 | static void rtl8105e_hw_phy_config(struct rtl8169_private *tp) |
| 4312 | { |
| 4313 | static const struct phy_reg phy_reg_init[] = { |
| 4314 | { 0x1f, 0x0005 }, |
| 4315 | { 0x1a, 0x0000 }, |
| 4316 | { 0x1f, 0x0000 }, |
| 4317 | |
| 4318 | { 0x1f, 0x0004 }, |
| 4319 | { 0x1c, 0x0000 }, |
| 4320 | { 0x1f, 0x0000 }, |
| 4321 | |
| 4322 | { 0x1f, 0x0001 }, |
| 4323 | { 0x15, 0x7701 }, |
| 4324 | { 0x1f, 0x0000 } |
| 4325 | }; |
| 4326 | |
| 4327 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 4328 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4329 | rtl_writephy(tp, 0x18, 0x0310); |
| 4330 | msleep(100); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4331 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4332 | rtl_apply_firmware(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4333 | |
| 4334 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 4335 | } |
| 4336 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4337 | static void rtl8402_hw_phy_config(struct rtl8169_private *tp) |
| 4338 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4339 | /* Disable ALDPS before setting firmware */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 4340 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4341 | rtl_writephy(tp, 0x18, 0x0310); |
| 4342 | msleep(20); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4343 | |
| 4344 | rtl_apply_firmware(tp); |
| 4345 | |
| 4346 | /* EEE setting */ |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4347 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4348 | rtl_writephy(tp, 0x1f, 0x0004); |
| 4349 | rtl_writephy(tp, 0x10, 0x401f); |
| 4350 | rtl_writephy(tp, 0x19, 0x7030); |
| 4351 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4352 | } |
| 4353 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4354 | static void rtl8106e_hw_phy_config(struct rtl8169_private *tp) |
| 4355 | { |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4356 | static const struct phy_reg phy_reg_init[] = { |
| 4357 | { 0x1f, 0x0004 }, |
| 4358 | { 0x10, 0xc07f }, |
| 4359 | { 0x19, 0x7030 }, |
| 4360 | { 0x1f, 0x0000 } |
| 4361 | }; |
| 4362 | |
| 4363 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 4364 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4365 | rtl_writephy(tp, 0x18, 0x0310); |
| 4366 | msleep(100); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4367 | |
| 4368 | rtl_apply_firmware(tp); |
| 4369 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4370 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4371 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 4372 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4373 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4374 | } |
| 4375 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4376 | static void rtl_hw_phy_config(struct net_device *dev) |
| 4377 | { |
| 4378 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4379 | |
| 4380 | rtl8169_print_mac_version(tp); |
| 4381 | |
| 4382 | switch (tp->mac_version) { |
| 4383 | case RTL_GIGA_MAC_VER_01: |
| 4384 | break; |
| 4385 | case RTL_GIGA_MAC_VER_02: |
| 4386 | case RTL_GIGA_MAC_VER_03: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4387 | rtl8169s_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4388 | break; |
| 4389 | case RTL_GIGA_MAC_VER_04: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4390 | rtl8169sb_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4391 | break; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 4392 | case RTL_GIGA_MAC_VER_05: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4393 | rtl8169scd_hw_phy_config(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 4394 | break; |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 4395 | case RTL_GIGA_MAC_VER_06: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4396 | rtl8169sce_hw_phy_config(tp); |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 4397 | break; |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4398 | case RTL_GIGA_MAC_VER_07: |
| 4399 | case RTL_GIGA_MAC_VER_08: |
| 4400 | case RTL_GIGA_MAC_VER_09: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4401 | rtl8102e_hw_phy_config(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4402 | break; |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4403 | case RTL_GIGA_MAC_VER_11: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4404 | rtl8168bb_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4405 | break; |
| 4406 | case RTL_GIGA_MAC_VER_12: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4407 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4408 | break; |
| 4409 | case RTL_GIGA_MAC_VER_17: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4410 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4411 | break; |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 4412 | case RTL_GIGA_MAC_VER_18: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4413 | rtl8168cp_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 4414 | break; |
| 4415 | case RTL_GIGA_MAC_VER_19: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4416 | rtl8168c_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 4417 | break; |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 4418 | case RTL_GIGA_MAC_VER_20: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4419 | rtl8168c_2_hw_phy_config(tp); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 4420 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4421 | case RTL_GIGA_MAC_VER_21: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4422 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4423 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4424 | case RTL_GIGA_MAC_VER_22: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4425 | rtl8168c_4_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4426 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4427 | case RTL_GIGA_MAC_VER_23: |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4428 | case RTL_GIGA_MAC_VER_24: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4429 | rtl8168cp_2_hw_phy_config(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4430 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4431 | case RTL_GIGA_MAC_VER_25: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 4432 | rtl8168d_1_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 4433 | break; |
| 4434 | case RTL_GIGA_MAC_VER_26: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 4435 | rtl8168d_2_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 4436 | break; |
| 4437 | case RTL_GIGA_MAC_VER_27: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4438 | rtl8168d_3_hw_phy_config(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4439 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4440 | case RTL_GIGA_MAC_VER_28: |
| 4441 | rtl8168d_4_hw_phy_config(tp); |
| 4442 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4443 | case RTL_GIGA_MAC_VER_29: |
| 4444 | case RTL_GIGA_MAC_VER_30: |
| 4445 | rtl8105e_hw_phy_config(tp); |
| 4446 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4447 | case RTL_GIGA_MAC_VER_31: |
| 4448 | /* None. */ |
| 4449 | break; |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4450 | case RTL_GIGA_MAC_VER_32: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4451 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4452 | rtl8168e_1_hw_phy_config(tp); |
| 4453 | break; |
| 4454 | case RTL_GIGA_MAC_VER_34: |
| 4455 | rtl8168e_2_hw_phy_config(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4456 | break; |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4457 | case RTL_GIGA_MAC_VER_35: |
| 4458 | rtl8168f_1_hw_phy_config(tp); |
| 4459 | break; |
| 4460 | case RTL_GIGA_MAC_VER_36: |
| 4461 | rtl8168f_2_hw_phy_config(tp); |
| 4462 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4463 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4464 | case RTL_GIGA_MAC_VER_37: |
| 4465 | rtl8402_hw_phy_config(tp); |
| 4466 | break; |
| 4467 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4468 | case RTL_GIGA_MAC_VER_38: |
| 4469 | rtl8411_hw_phy_config(tp); |
| 4470 | break; |
| 4471 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4472 | case RTL_GIGA_MAC_VER_39: |
| 4473 | rtl8106e_hw_phy_config(tp); |
| 4474 | break; |
| 4475 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4476 | case RTL_GIGA_MAC_VER_40: |
| 4477 | rtl8168g_1_hw_phy_config(tp); |
| 4478 | break; |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4479 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 4480 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4481 | case RTL_GIGA_MAC_VER_44: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4482 | rtl8168g_2_hw_phy_config(tp); |
| 4483 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4484 | case RTL_GIGA_MAC_VER_45: |
| 4485 | case RTL_GIGA_MAC_VER_47: |
| 4486 | rtl8168h_1_hw_phy_config(tp); |
| 4487 | break; |
| 4488 | case RTL_GIGA_MAC_VER_46: |
| 4489 | case RTL_GIGA_MAC_VER_48: |
| 4490 | rtl8168h_2_hw_phy_config(tp); |
| 4491 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4492 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4493 | case RTL_GIGA_MAC_VER_49: |
| 4494 | rtl8168ep_1_hw_phy_config(tp); |
| 4495 | break; |
| 4496 | case RTL_GIGA_MAC_VER_50: |
| 4497 | case RTL_GIGA_MAC_VER_51: |
| 4498 | rtl8168ep_2_hw_phy_config(tp); |
| 4499 | break; |
| 4500 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4501 | case RTL_GIGA_MAC_VER_41: |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4502 | default: |
| 4503 | break; |
| 4504 | } |
| 4505 | } |
| 4506 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4507 | static void rtl_phy_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4508 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4509 | struct timer_list *timer = &tp->timer; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4510 | unsigned long timeout = RTL8169_PHY_TIMEOUT; |
| 4511 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4512 | assert(tp->mac_version > RTL_GIGA_MAC_VER_01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4513 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4514 | if (tp->phy_reset_pending(tp)) { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 4515 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4516 | * A busy loop could burn quite a few cycles on nowadays CPU. |
| 4517 | * Let's delay the execution of the timer for a few ticks. |
| 4518 | */ |
| 4519 | timeout = HZ/10; |
| 4520 | goto out_mod_timer; |
| 4521 | } |
| 4522 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4523 | if (tp->link_ok(tp)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4524 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4525 | |
Lekensteyn | 9bb8eeb | 2013-08-02 10:36:55 +0200 | [diff] [blame] | 4526 | netif_dbg(tp, link, tp->dev, "PHY reset until link up\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4527 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4528 | tp->phy_reset_enable(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4529 | |
| 4530 | out_mod_timer: |
| 4531 | mod_timer(timer, jiffies + timeout); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4532 | } |
| 4533 | |
| 4534 | static void rtl_schedule_task(struct rtl8169_private *tp, enum rtl_flag flag) |
| 4535 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4536 | if (!test_and_set_bit(flag, tp->wk.flags)) |
| 4537 | schedule_work(&tp->wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4538 | } |
| 4539 | |
Kees Cook | 9de36cc | 2017-10-25 03:53:12 -0700 | [diff] [blame] | 4540 | static void rtl8169_phy_timer(struct timer_list *t) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4541 | { |
Kees Cook | 9de36cc | 2017-10-25 03:53:12 -0700 | [diff] [blame] | 4542 | struct rtl8169_private *tp = from_timer(tp, t, timer); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4543 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 4544 | rtl_schedule_task(tp, RTL_FLAG_TASK_PHY_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4545 | } |
| 4546 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4547 | DECLARE_RTL_COND(rtl_phy_reset_cond) |
| 4548 | { |
| 4549 | return tp->phy_reset_pending(tp); |
| 4550 | } |
| 4551 | |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 4552 | static void rtl8169_phy_reset(struct net_device *dev, |
| 4553 | struct rtl8169_private *tp) |
| 4554 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4555 | tp->phy_reset_enable(tp); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4556 | rtl_msleep_loop_wait_low(tp, &rtl_phy_reset_cond, 1, 100); |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 4557 | } |
| 4558 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4559 | static bool rtl_tbi_enabled(struct rtl8169_private *tp) |
| 4560 | { |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4561 | return (tp->mac_version == RTL_GIGA_MAC_VER_01) && |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4562 | (RTL_R8(tp, PHYstatus) & TBI_Enable); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4563 | } |
| 4564 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4565 | 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] | 4566 | { |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4567 | rtl_hw_phy_config(dev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4568 | |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 4569 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
| 4570 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4571 | RTL_W8(tp, 0x82, 0x01); |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 4572 | } |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4573 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4574 | pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); |
| 4575 | |
| 4576 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
| 4577 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4578 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4579 | if (tp->mac_version == RTL_GIGA_MAC_VER_02) { |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4580 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4581 | RTL_W8(tp, 0x82, 0x01); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4582 | dprintk("Set PHY Reg 0x0bh = 0x00h\n"); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4583 | rtl_writephy(tp, 0x0b, 0x0000); //w 0x0b 15 0 0 |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4584 | } |
| 4585 | |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 4586 | rtl8169_phy_reset(dev, tp); |
| 4587 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 4588 | rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4589 | ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 4590 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 4591 | (tp->mii.supports_gmii ? |
| 4592 | ADVERTISED_1000baseT_Half | |
| 4593 | ADVERTISED_1000baseT_Full : 0)); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4594 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4595 | if (rtl_tbi_enabled(tp)) |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 4596 | netif_info(tp, link, dev, "TBI auto-negotiating\n"); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4597 | } |
| 4598 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4599 | static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr) |
| 4600 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4601 | rtl_lock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4602 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4603 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4604 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4605 | RTL_W32(tp, MAC4, addr[4] | addr[5] << 8); |
| 4606 | RTL_R32(tp, MAC4); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4607 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4608 | RTL_W32(tp, MAC0, addr[0] | addr[1] << 8 | addr[2] << 16 | addr[3] << 24); |
| 4609 | RTL_R32(tp, MAC0); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4610 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 4611 | if (tp->mac_version == RTL_GIGA_MAC_VER_34) |
| 4612 | rtl_rar_exgmac_set(tp, addr); |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 4613 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4614 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4615 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4616 | rtl_unlock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4617 | } |
| 4618 | |
| 4619 | static int rtl_set_mac_address(struct net_device *dev, void *p) |
| 4620 | { |
| 4621 | struct rtl8169_private *tp = netdev_priv(dev); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 4622 | struct device *d = tp_to_dev(tp); |
Heiner Kallweit | 1f7aa2b | 2018-03-20 07:45:33 +0100 | [diff] [blame] | 4623 | int ret; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4624 | |
Heiner Kallweit | 1f7aa2b | 2018-03-20 07:45:33 +0100 | [diff] [blame] | 4625 | ret = eth_mac_addr(dev, p); |
| 4626 | if (ret) |
| 4627 | return ret; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4628 | |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 4629 | pm_runtime_get_noresume(d); |
| 4630 | |
| 4631 | if (pm_runtime_active(d)) |
| 4632 | rtl_rar_set(tp, dev->dev_addr); |
| 4633 | |
| 4634 | pm_runtime_put_noidle(d); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4635 | |
| 4636 | return 0; |
| 4637 | } |
| 4638 | |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4639 | static int rtl8169_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 4640 | { |
| 4641 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4642 | struct mii_ioctl_data *data = if_mii(ifr); |
| 4643 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4644 | return netif_running(dev) ? tp->do_ioctl(tp, data, cmd) : -ENODEV; |
| 4645 | } |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4646 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4647 | static int rtl_xmii_ioctl(struct rtl8169_private *tp, |
| 4648 | struct mii_ioctl_data *data, int cmd) |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4649 | { |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4650 | switch (cmd) { |
| 4651 | case SIOCGMIIPHY: |
| 4652 | data->phy_id = 32; /* Internal PHY */ |
| 4653 | return 0; |
| 4654 | |
| 4655 | case SIOCGMIIREG: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4656 | data->val_out = rtl_readphy(tp, data->reg_num & 0x1f); |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4657 | return 0; |
| 4658 | |
| 4659 | case SIOCSMIIREG: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4660 | rtl_writephy(tp, data->reg_num & 0x1f, data->val_in); |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4661 | return 0; |
| 4662 | } |
| 4663 | return -EOPNOTSUPP; |
| 4664 | } |
| 4665 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4666 | static int rtl_tbi_ioctl(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd) |
| 4667 | { |
| 4668 | return -EOPNOTSUPP; |
| 4669 | } |
| 4670 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 4671 | static void rtl_init_mdio_ops(struct rtl8169_private *tp) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4672 | { |
| 4673 | struct mdio_ops *ops = &tp->mdio_ops; |
| 4674 | |
| 4675 | switch (tp->mac_version) { |
| 4676 | case RTL_GIGA_MAC_VER_27: |
| 4677 | ops->write = r8168dp_1_mdio_write; |
| 4678 | ops->read = r8168dp_1_mdio_read; |
| 4679 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4680 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4681 | case RTL_GIGA_MAC_VER_31: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4682 | ops->write = r8168dp_2_mdio_write; |
| 4683 | ops->read = r8168dp_2_mdio_read; |
| 4684 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4685 | case RTL_GIGA_MAC_VER_40: |
| 4686 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4687 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 4688 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4689 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4690 | case RTL_GIGA_MAC_VER_45: |
| 4691 | case RTL_GIGA_MAC_VER_46: |
| 4692 | case RTL_GIGA_MAC_VER_47: |
| 4693 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4694 | case RTL_GIGA_MAC_VER_49: |
| 4695 | case RTL_GIGA_MAC_VER_50: |
| 4696 | case RTL_GIGA_MAC_VER_51: |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4697 | ops->write = r8168g_mdio_write; |
| 4698 | ops->read = r8168g_mdio_read; |
| 4699 | break; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4700 | default: |
| 4701 | ops->write = r8169_mdio_write; |
| 4702 | ops->read = r8169_mdio_read; |
| 4703 | break; |
| 4704 | } |
| 4705 | } |
| 4706 | |
hayeswang | e2409d8 | 2013-03-31 17:02:04 +0000 | [diff] [blame] | 4707 | static void rtl_speed_down(struct rtl8169_private *tp) |
| 4708 | { |
| 4709 | u32 adv; |
| 4710 | int lpa; |
| 4711 | |
| 4712 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4713 | lpa = rtl_readphy(tp, MII_LPA); |
| 4714 | |
| 4715 | if (lpa & (LPA_10HALF | LPA_10FULL)) |
| 4716 | adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full; |
| 4717 | else if (lpa & (LPA_100HALF | LPA_100FULL)) |
| 4718 | adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 4719 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full; |
| 4720 | else |
| 4721 | adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 4722 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 4723 | (tp->mii.supports_gmii ? |
| 4724 | ADVERTISED_1000baseT_Half | |
| 4725 | ADVERTISED_1000baseT_Full : 0); |
| 4726 | |
| 4727 | rtl8169_set_speed(tp->dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL, |
| 4728 | adv); |
| 4729 | } |
| 4730 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4731 | static void rtl_wol_suspend_quirk(struct rtl8169_private *tp) |
| 4732 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4733 | switch (tp->mac_version) { |
Cyril Brulebois | b00e69d | 2012-10-31 14:00:46 +0000 | [diff] [blame] | 4734 | case RTL_GIGA_MAC_VER_25: |
| 4735 | case RTL_GIGA_MAC_VER_26: |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4736 | case RTL_GIGA_MAC_VER_29: |
| 4737 | case RTL_GIGA_MAC_VER_30: |
| 4738 | case RTL_GIGA_MAC_VER_32: |
| 4739 | case RTL_GIGA_MAC_VER_33: |
| 4740 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4741 | case RTL_GIGA_MAC_VER_37: |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4742 | case RTL_GIGA_MAC_VER_38: |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4743 | case RTL_GIGA_MAC_VER_39: |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4744 | case RTL_GIGA_MAC_VER_40: |
| 4745 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4746 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 4747 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4748 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4749 | case RTL_GIGA_MAC_VER_45: |
| 4750 | case RTL_GIGA_MAC_VER_46: |
| 4751 | case RTL_GIGA_MAC_VER_47: |
| 4752 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4753 | case RTL_GIGA_MAC_VER_49: |
| 4754 | case RTL_GIGA_MAC_VER_50: |
| 4755 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4756 | RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4757 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys); |
| 4758 | break; |
| 4759 | default: |
| 4760 | break; |
| 4761 | } |
| 4762 | } |
| 4763 | |
| 4764 | static bool rtl_wol_pll_power_down(struct rtl8169_private *tp) |
| 4765 | { |
| 4766 | if (!(__rtl8169_get_wol(tp) & WAKE_ANY)) |
| 4767 | return false; |
| 4768 | |
hayeswang | e2409d8 | 2013-03-31 17:02:04 +0000 | [diff] [blame] | 4769 | rtl_speed_down(tp); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4770 | rtl_wol_suspend_quirk(tp); |
| 4771 | |
| 4772 | return true; |
| 4773 | } |
| 4774 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4775 | static void r810x_phy_power_down(struct rtl8169_private *tp) |
| 4776 | { |
| 4777 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4778 | rtl_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 4779 | } |
| 4780 | |
| 4781 | static void r810x_phy_power_up(struct rtl8169_private *tp) |
| 4782 | { |
| 4783 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4784 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE); |
| 4785 | } |
| 4786 | |
| 4787 | static void r810x_pll_power_down(struct rtl8169_private *tp) |
| 4788 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4789 | if (rtl_wol_pll_power_down(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4790 | return; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4791 | |
| 4792 | r810x_phy_power_down(tp); |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 4793 | |
| 4794 | switch (tp->mac_version) { |
| 4795 | case RTL_GIGA_MAC_VER_07: |
| 4796 | case RTL_GIGA_MAC_VER_08: |
| 4797 | case RTL_GIGA_MAC_VER_09: |
| 4798 | case RTL_GIGA_MAC_VER_10: |
| 4799 | case RTL_GIGA_MAC_VER_13: |
| 4800 | case RTL_GIGA_MAC_VER_16: |
| 4801 | break; |
| 4802 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4803 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 4804 | break; |
| 4805 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4806 | } |
| 4807 | |
| 4808 | static void r810x_pll_power_up(struct rtl8169_private *tp) |
| 4809 | { |
| 4810 | r810x_phy_power_up(tp); |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 4811 | |
| 4812 | switch (tp->mac_version) { |
| 4813 | case RTL_GIGA_MAC_VER_07: |
| 4814 | case RTL_GIGA_MAC_VER_08: |
| 4815 | case RTL_GIGA_MAC_VER_09: |
| 4816 | case RTL_GIGA_MAC_VER_10: |
| 4817 | case RTL_GIGA_MAC_VER_13: |
| 4818 | case RTL_GIGA_MAC_VER_16: |
| 4819 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4820 | case RTL_GIGA_MAC_VER_47: |
| 4821 | case RTL_GIGA_MAC_VER_48: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4822 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4823 | break; |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 4824 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4825 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0x80); |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 4826 | break; |
| 4827 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4828 | } |
| 4829 | |
| 4830 | static void r8168_phy_power_up(struct rtl8169_private *tp) |
| 4831 | { |
| 4832 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4833 | switch (tp->mac_version) { |
| 4834 | case RTL_GIGA_MAC_VER_11: |
| 4835 | case RTL_GIGA_MAC_VER_12: |
| 4836 | case RTL_GIGA_MAC_VER_17: |
| 4837 | case RTL_GIGA_MAC_VER_18: |
| 4838 | case RTL_GIGA_MAC_VER_19: |
| 4839 | case RTL_GIGA_MAC_VER_20: |
| 4840 | case RTL_GIGA_MAC_VER_21: |
| 4841 | case RTL_GIGA_MAC_VER_22: |
| 4842 | case RTL_GIGA_MAC_VER_23: |
| 4843 | case RTL_GIGA_MAC_VER_24: |
| 4844 | case RTL_GIGA_MAC_VER_25: |
| 4845 | case RTL_GIGA_MAC_VER_26: |
| 4846 | case RTL_GIGA_MAC_VER_27: |
| 4847 | case RTL_GIGA_MAC_VER_28: |
| 4848 | case RTL_GIGA_MAC_VER_31: |
| 4849 | rtl_writephy(tp, 0x0e, 0x0000); |
| 4850 | break; |
| 4851 | default: |
| 4852 | break; |
| 4853 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4854 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE); |
| 4855 | } |
| 4856 | |
| 4857 | static void r8168_phy_power_down(struct rtl8169_private *tp) |
| 4858 | { |
| 4859 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4860 | switch (tp->mac_version) { |
| 4861 | case RTL_GIGA_MAC_VER_32: |
| 4862 | case RTL_GIGA_MAC_VER_33: |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4863 | case RTL_GIGA_MAC_VER_40: |
| 4864 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4865 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE | BMCR_PDOWN); |
| 4866 | break; |
| 4867 | |
| 4868 | case RTL_GIGA_MAC_VER_11: |
| 4869 | case RTL_GIGA_MAC_VER_12: |
| 4870 | case RTL_GIGA_MAC_VER_17: |
| 4871 | case RTL_GIGA_MAC_VER_18: |
| 4872 | case RTL_GIGA_MAC_VER_19: |
| 4873 | case RTL_GIGA_MAC_VER_20: |
| 4874 | case RTL_GIGA_MAC_VER_21: |
| 4875 | case RTL_GIGA_MAC_VER_22: |
| 4876 | case RTL_GIGA_MAC_VER_23: |
| 4877 | case RTL_GIGA_MAC_VER_24: |
| 4878 | case RTL_GIGA_MAC_VER_25: |
| 4879 | case RTL_GIGA_MAC_VER_26: |
| 4880 | case RTL_GIGA_MAC_VER_27: |
| 4881 | case RTL_GIGA_MAC_VER_28: |
| 4882 | case RTL_GIGA_MAC_VER_31: |
| 4883 | rtl_writephy(tp, 0x0e, 0x0200); |
| 4884 | default: |
| 4885 | rtl_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 4886 | break; |
| 4887 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4888 | } |
| 4889 | |
| 4890 | static void r8168_pll_power_down(struct rtl8169_private *tp) |
| 4891 | { |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 4892 | if (r8168_check_dash(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4893 | return; |
| 4894 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4895 | if ((tp->mac_version == RTL_GIGA_MAC_VER_23 || |
| 4896 | tp->mac_version == RTL_GIGA_MAC_VER_24) && |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4897 | (RTL_R16(tp, CPlusCmd) & ASF)) { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4898 | return; |
| 4899 | } |
| 4900 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4901 | if (tp->mac_version == RTL_GIGA_MAC_VER_32 || |
| 4902 | tp->mac_version == RTL_GIGA_MAC_VER_33) |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4903 | rtl_ephy_write(tp, 0x19, 0xff64); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4904 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4905 | if (rtl_wol_pll_power_down(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4906 | return; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4907 | |
| 4908 | r8168_phy_power_down(tp); |
| 4909 | |
| 4910 | switch (tp->mac_version) { |
| 4911 | case RTL_GIGA_MAC_VER_25: |
| 4912 | case RTL_GIGA_MAC_VER_26: |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 4913 | case RTL_GIGA_MAC_VER_27: |
| 4914 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4915 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4916 | case RTL_GIGA_MAC_VER_32: |
| 4917 | case RTL_GIGA_MAC_VER_33: |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 4918 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4919 | case RTL_GIGA_MAC_VER_45: |
| 4920 | case RTL_GIGA_MAC_VER_46: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4921 | case RTL_GIGA_MAC_VER_50: |
| 4922 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4923 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4924 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4925 | case RTL_GIGA_MAC_VER_40: |
| 4926 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4927 | case RTL_GIGA_MAC_VER_49: |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 4928 | rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0x00000000, |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4929 | 0xfc000000, ERIAR_EXGMAC); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4930 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) & ~0x80); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4931 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4932 | } |
| 4933 | } |
| 4934 | |
| 4935 | static void r8168_pll_power_up(struct rtl8169_private *tp) |
| 4936 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4937 | switch (tp->mac_version) { |
| 4938 | case RTL_GIGA_MAC_VER_25: |
| 4939 | case RTL_GIGA_MAC_VER_26: |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 4940 | case RTL_GIGA_MAC_VER_27: |
| 4941 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4942 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4943 | case RTL_GIGA_MAC_VER_32: |
| 4944 | case RTL_GIGA_MAC_VER_33: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4945 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0x80); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4946 | break; |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 4947 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4948 | case RTL_GIGA_MAC_VER_45: |
| 4949 | case RTL_GIGA_MAC_VER_46: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4950 | case RTL_GIGA_MAC_VER_50: |
| 4951 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4952 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4953 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4954 | case RTL_GIGA_MAC_VER_40: |
| 4955 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4956 | case RTL_GIGA_MAC_VER_49: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 4957 | RTL_W8(tp, PMCH, RTL_R8(tp, PMCH) | 0xc0); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 4958 | rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0xfc000000, |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4959 | 0x00000000, ERIAR_EXGMAC); |
| 4960 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4961 | } |
| 4962 | |
| 4963 | r8168_phy_power_up(tp); |
| 4964 | } |
| 4965 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4966 | static void rtl_generic_op(struct rtl8169_private *tp, |
| 4967 | void (*op)(struct rtl8169_private *)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4968 | { |
| 4969 | if (op) |
| 4970 | op(tp); |
| 4971 | } |
| 4972 | |
| 4973 | static void rtl_pll_power_down(struct rtl8169_private *tp) |
| 4974 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4975 | rtl_generic_op(tp, tp->pll_power_ops.down); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4976 | } |
| 4977 | |
| 4978 | static void rtl_pll_power_up(struct rtl8169_private *tp) |
| 4979 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4980 | rtl_generic_op(tp, tp->pll_power_ops.up); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4981 | } |
| 4982 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 4983 | static void rtl_init_pll_power_ops(struct rtl8169_private *tp) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4984 | { |
| 4985 | struct pll_power_ops *ops = &tp->pll_power_ops; |
| 4986 | |
| 4987 | switch (tp->mac_version) { |
| 4988 | case RTL_GIGA_MAC_VER_07: |
| 4989 | case RTL_GIGA_MAC_VER_08: |
| 4990 | case RTL_GIGA_MAC_VER_09: |
| 4991 | case RTL_GIGA_MAC_VER_10: |
| 4992 | case RTL_GIGA_MAC_VER_16: |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4993 | case RTL_GIGA_MAC_VER_29: |
| 4994 | case RTL_GIGA_MAC_VER_30: |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4995 | case RTL_GIGA_MAC_VER_37: |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4996 | case RTL_GIGA_MAC_VER_39: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 4997 | case RTL_GIGA_MAC_VER_43: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4998 | case RTL_GIGA_MAC_VER_47: |
| 4999 | case RTL_GIGA_MAC_VER_48: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5000 | ops->down = r810x_pll_power_down; |
| 5001 | ops->up = r810x_pll_power_up; |
| 5002 | break; |
| 5003 | |
| 5004 | case RTL_GIGA_MAC_VER_11: |
| 5005 | case RTL_GIGA_MAC_VER_12: |
| 5006 | case RTL_GIGA_MAC_VER_17: |
| 5007 | case RTL_GIGA_MAC_VER_18: |
| 5008 | case RTL_GIGA_MAC_VER_19: |
| 5009 | case RTL_GIGA_MAC_VER_20: |
| 5010 | case RTL_GIGA_MAC_VER_21: |
| 5011 | case RTL_GIGA_MAC_VER_22: |
| 5012 | case RTL_GIGA_MAC_VER_23: |
| 5013 | case RTL_GIGA_MAC_VER_24: |
| 5014 | case RTL_GIGA_MAC_VER_25: |
| 5015 | case RTL_GIGA_MAC_VER_26: |
| 5016 | case RTL_GIGA_MAC_VER_27: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5017 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5018 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5019 | case RTL_GIGA_MAC_VER_32: |
| 5020 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5021 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5022 | case RTL_GIGA_MAC_VER_35: |
| 5023 | case RTL_GIGA_MAC_VER_36: |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5024 | case RTL_GIGA_MAC_VER_38: |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5025 | case RTL_GIGA_MAC_VER_40: |
| 5026 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5027 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5028 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5029 | case RTL_GIGA_MAC_VER_45: |
| 5030 | case RTL_GIGA_MAC_VER_46: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5031 | case RTL_GIGA_MAC_VER_49: |
| 5032 | case RTL_GIGA_MAC_VER_50: |
| 5033 | case RTL_GIGA_MAC_VER_51: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5034 | ops->down = r8168_pll_power_down; |
| 5035 | ops->up = r8168_pll_power_up; |
| 5036 | break; |
| 5037 | |
| 5038 | default: |
| 5039 | ops->down = NULL; |
| 5040 | ops->up = NULL; |
| 5041 | break; |
| 5042 | } |
| 5043 | } |
| 5044 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 5045 | static void rtl_init_rxcfg(struct rtl8169_private *tp) |
| 5046 | { |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 5047 | switch (tp->mac_version) { |
| 5048 | case RTL_GIGA_MAC_VER_01: |
| 5049 | case RTL_GIGA_MAC_VER_02: |
| 5050 | case RTL_GIGA_MAC_VER_03: |
| 5051 | case RTL_GIGA_MAC_VER_04: |
| 5052 | case RTL_GIGA_MAC_VER_05: |
| 5053 | case RTL_GIGA_MAC_VER_06: |
| 5054 | case RTL_GIGA_MAC_VER_10: |
| 5055 | case RTL_GIGA_MAC_VER_11: |
| 5056 | case RTL_GIGA_MAC_VER_12: |
| 5057 | case RTL_GIGA_MAC_VER_13: |
| 5058 | case RTL_GIGA_MAC_VER_14: |
| 5059 | case RTL_GIGA_MAC_VER_15: |
| 5060 | case RTL_GIGA_MAC_VER_16: |
| 5061 | case RTL_GIGA_MAC_VER_17: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5062 | RTL_W32(tp, RxConfig, RX_FIFO_THRESH | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 5063 | break; |
| 5064 | case RTL_GIGA_MAC_VER_18: |
| 5065 | case RTL_GIGA_MAC_VER_19: |
| 5066 | case RTL_GIGA_MAC_VER_20: |
| 5067 | case RTL_GIGA_MAC_VER_21: |
| 5068 | case RTL_GIGA_MAC_VER_22: |
| 5069 | case RTL_GIGA_MAC_VER_23: |
| 5070 | case RTL_GIGA_MAC_VER_24: |
françois romieu | eb2dc35 | 2012-06-20 12:09:18 +0000 | [diff] [blame] | 5071 | case RTL_GIGA_MAC_VER_34: |
françois romieu | 3ced8c9 | 2013-09-08 01:15:35 +0200 | [diff] [blame] | 5072 | case RTL_GIGA_MAC_VER_35: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5073 | 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] | 5074 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 5075 | case RTL_GIGA_MAC_VER_40: |
| 5076 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5077 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 5078 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5079 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5080 | case RTL_GIGA_MAC_VER_45: |
| 5081 | case RTL_GIGA_MAC_VER_46: |
| 5082 | case RTL_GIGA_MAC_VER_47: |
| 5083 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5084 | case RTL_GIGA_MAC_VER_49: |
| 5085 | case RTL_GIGA_MAC_VER_50: |
| 5086 | case RTL_GIGA_MAC_VER_51: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5087 | 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] | 5088 | break; |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 5089 | default: |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5090 | RTL_W32(tp, RxConfig, RX128_INT_EN | RX_DMA_BURST); |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 5091 | break; |
| 5092 | } |
| 5093 | } |
| 5094 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5095 | static void rtl8169_init_ring_indexes(struct rtl8169_private *tp) |
| 5096 | { |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 5097 | tp->dirty_tx = tp->cur_tx = tp->cur_rx = 0; |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5098 | } |
| 5099 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5100 | static void rtl_hw_jumbo_enable(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.enable); |
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 rtl_hw_jumbo_disable(struct rtl8169_private *tp) |
| 5108 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5109 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5110 | rtl_generic_op(tp, tp->jumbo_ops.disable); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5111 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5112 | } |
| 5113 | |
| 5114 | static void r8168c_hw_jumbo_enable(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 | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 5118 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5119 | } |
| 5120 | |
| 5121 | static void r8168c_hw_jumbo_disable(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); |
| 5124 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~Jumbo_En1); |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5125 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5126 | } |
| 5127 | |
| 5128 | static void r8168dp_hw_jumbo_enable(struct rtl8169_private *tp) |
| 5129 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5130 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5131 | } |
| 5132 | |
| 5133 | static void r8168dp_hw_jumbo_disable(struct rtl8169_private *tp) |
| 5134 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5135 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5136 | } |
| 5137 | |
| 5138 | static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp) |
| 5139 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5140 | RTL_W8(tp, MaxTxPacketSize, 0x3f); |
| 5141 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) | Jumbo_En0); |
| 5142 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) | 0x01); |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 5143 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5144 | } |
| 5145 | |
| 5146 | static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp) |
| 5147 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5148 | RTL_W8(tp, MaxTxPacketSize, 0x0c); |
| 5149 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Jumbo_En0); |
| 5150 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~0x01); |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5151 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5152 | } |
| 5153 | |
| 5154 | static void r8168b_0_hw_jumbo_enable(struct rtl8169_private *tp) |
| 5155 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 5156 | rtl_tx_performance_tweak(tp, |
Rafał Miłecki | f65d539 | 2015-01-26 18:06:31 +0100 | [diff] [blame] | 5157 | PCI_EXP_DEVCTL_READRQ_512B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5158 | } |
| 5159 | |
| 5160 | static void r8168b_0_hw_jumbo_disable(struct rtl8169_private *tp) |
| 5161 | { |
Heiner Kallweit | cb73200 | 2018-03-20 07:45:35 +0100 | [diff] [blame] | 5162 | rtl_tx_performance_tweak(tp, |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5163 | PCI_EXP_DEVCTL_READRQ_4096B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5164 | } |
| 5165 | |
| 5166 | static void r8168b_1_hw_jumbo_enable(struct rtl8169_private *tp) |
| 5167 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5168 | r8168b_0_hw_jumbo_enable(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 | |
| 5173 | static void r8168b_1_hw_jumbo_disable(struct rtl8169_private *tp) |
| 5174 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5175 | r8168b_0_hw_jumbo_disable(tp); |
| 5176 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5177 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0)); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5178 | } |
| 5179 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 5180 | static void rtl_init_jumbo_ops(struct rtl8169_private *tp) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5181 | { |
| 5182 | struct jumbo_ops *ops = &tp->jumbo_ops; |
| 5183 | |
| 5184 | switch (tp->mac_version) { |
| 5185 | case RTL_GIGA_MAC_VER_11: |
| 5186 | ops->disable = r8168b_0_hw_jumbo_disable; |
| 5187 | ops->enable = r8168b_0_hw_jumbo_enable; |
| 5188 | break; |
| 5189 | case RTL_GIGA_MAC_VER_12: |
| 5190 | case RTL_GIGA_MAC_VER_17: |
| 5191 | ops->disable = r8168b_1_hw_jumbo_disable; |
| 5192 | ops->enable = r8168b_1_hw_jumbo_enable; |
| 5193 | break; |
| 5194 | case RTL_GIGA_MAC_VER_18: /* Wild guess. Needs info from Realtek. */ |
| 5195 | case RTL_GIGA_MAC_VER_19: |
| 5196 | case RTL_GIGA_MAC_VER_20: |
| 5197 | case RTL_GIGA_MAC_VER_21: /* Wild guess. Needs info from Realtek. */ |
| 5198 | case RTL_GIGA_MAC_VER_22: |
| 5199 | case RTL_GIGA_MAC_VER_23: |
| 5200 | case RTL_GIGA_MAC_VER_24: |
| 5201 | case RTL_GIGA_MAC_VER_25: |
| 5202 | case RTL_GIGA_MAC_VER_26: |
| 5203 | ops->disable = r8168c_hw_jumbo_disable; |
| 5204 | ops->enable = r8168c_hw_jumbo_enable; |
| 5205 | break; |
| 5206 | case RTL_GIGA_MAC_VER_27: |
| 5207 | case RTL_GIGA_MAC_VER_28: |
| 5208 | ops->disable = r8168dp_hw_jumbo_disable; |
| 5209 | ops->enable = r8168dp_hw_jumbo_enable; |
| 5210 | break; |
| 5211 | case RTL_GIGA_MAC_VER_31: /* Wild guess. Needs info from Realtek. */ |
| 5212 | case RTL_GIGA_MAC_VER_32: |
| 5213 | case RTL_GIGA_MAC_VER_33: |
| 5214 | case RTL_GIGA_MAC_VER_34: |
| 5215 | ops->disable = r8168e_hw_jumbo_disable; |
| 5216 | ops->enable = r8168e_hw_jumbo_enable; |
| 5217 | break; |
| 5218 | |
| 5219 | /* |
| 5220 | * No action needed for jumbo frames with 8169. |
| 5221 | * No jumbo for 810x at all. |
| 5222 | */ |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5223 | case RTL_GIGA_MAC_VER_40: |
| 5224 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5225 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 5226 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5227 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5228 | case RTL_GIGA_MAC_VER_45: |
| 5229 | case RTL_GIGA_MAC_VER_46: |
| 5230 | case RTL_GIGA_MAC_VER_47: |
| 5231 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5232 | case RTL_GIGA_MAC_VER_49: |
| 5233 | case RTL_GIGA_MAC_VER_50: |
| 5234 | case RTL_GIGA_MAC_VER_51: |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5235 | default: |
| 5236 | ops->disable = NULL; |
| 5237 | ops->enable = NULL; |
| 5238 | break; |
| 5239 | } |
| 5240 | } |
| 5241 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5242 | DECLARE_RTL_COND(rtl_chipcmd_cond) |
| 5243 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5244 | return RTL_R8(tp, ChipCmd) & CmdReset; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5245 | } |
| 5246 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 5247 | static void rtl_hw_reset(struct rtl8169_private *tp) |
| 5248 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5249 | RTL_W8(tp, ChipCmd, CmdReset); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 5250 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5251 | rtl_udelay_loop_wait_low(tp, &rtl_chipcmd_cond, 100, 100); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 5252 | } |
| 5253 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 5254 | static void rtl_request_uncached_firmware(struct rtl8169_private *tp) |
| 5255 | { |
| 5256 | struct rtl_fw *rtl_fw; |
| 5257 | const char *name; |
| 5258 | int rc = -ENOMEM; |
| 5259 | |
| 5260 | name = rtl_lookup_firmware_name(tp); |
| 5261 | if (!name) |
| 5262 | goto out_no_firmware; |
| 5263 | |
| 5264 | rtl_fw = kzalloc(sizeof(*rtl_fw), GFP_KERNEL); |
| 5265 | if (!rtl_fw) |
| 5266 | goto err_warn; |
| 5267 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 5268 | rc = request_firmware(&rtl_fw->fw, name, tp_to_dev(tp)); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 5269 | if (rc < 0) |
| 5270 | goto err_free; |
| 5271 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 5272 | rc = rtl_check_firmware(tp, rtl_fw); |
| 5273 | if (rc < 0) |
| 5274 | goto err_release_firmware; |
| 5275 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 5276 | tp->rtl_fw = rtl_fw; |
| 5277 | out: |
| 5278 | return; |
| 5279 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 5280 | err_release_firmware: |
| 5281 | release_firmware(rtl_fw->fw); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 5282 | err_free: |
| 5283 | kfree(rtl_fw); |
| 5284 | err_warn: |
| 5285 | netif_warn(tp, ifup, tp->dev, "unable to load firmware patch %s (%d)\n", |
| 5286 | name, rc); |
| 5287 | out_no_firmware: |
| 5288 | tp->rtl_fw = NULL; |
| 5289 | goto out; |
| 5290 | } |
| 5291 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 5292 | static void rtl_request_firmware(struct rtl8169_private *tp) |
| 5293 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 5294 | if (IS_ERR(tp->rtl_fw)) |
| 5295 | rtl_request_uncached_firmware(tp); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 5296 | } |
| 5297 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5298 | static void rtl_rx_close(struct rtl8169_private *tp) |
| 5299 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5300 | RTL_W32(tp, RxConfig, RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5301 | } |
| 5302 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5303 | DECLARE_RTL_COND(rtl_npq_cond) |
| 5304 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5305 | return RTL_R8(tp, TxPoll) & NPQ; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5306 | } |
| 5307 | |
| 5308 | DECLARE_RTL_COND(rtl_txcfg_empty_cond) |
| 5309 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5310 | return RTL_R32(tp, TxConfig) & TXCFG_EMPTY; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5311 | } |
| 5312 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5313 | static void rtl8169_hw_reset(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5314 | { |
| 5315 | /* Disable interrupts */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 5316 | rtl8169_irq_mask_and_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5317 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5318 | rtl_rx_close(tp); |
| 5319 | |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 5320 | if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5321 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 5322 | tp->mac_version == RTL_GIGA_MAC_VER_31) { |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5323 | rtl_udelay_loop_wait_low(tp, &rtl_npq_cond, 20, 42*42); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5324 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_34 || |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5325 | tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 5326 | tp->mac_version == RTL_GIGA_MAC_VER_36 || |
| 5327 | tp->mac_version == RTL_GIGA_MAC_VER_37 || |
| 5328 | tp->mac_version == RTL_GIGA_MAC_VER_38 || |
| 5329 | tp->mac_version == RTL_GIGA_MAC_VER_40 || |
| 5330 | tp->mac_version == RTL_GIGA_MAC_VER_41 || |
| 5331 | tp->mac_version == RTL_GIGA_MAC_VER_42 || |
| 5332 | tp->mac_version == RTL_GIGA_MAC_VER_43 || |
| 5333 | tp->mac_version == RTL_GIGA_MAC_VER_44 || |
| 5334 | tp->mac_version == RTL_GIGA_MAC_VER_45 || |
| 5335 | tp->mac_version == RTL_GIGA_MAC_VER_46 || |
| 5336 | tp->mac_version == RTL_GIGA_MAC_VER_47 || |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5337 | tp->mac_version == RTL_GIGA_MAC_VER_48 || |
| 5338 | tp->mac_version == RTL_GIGA_MAC_VER_49 || |
| 5339 | tp->mac_version == RTL_GIGA_MAC_VER_50 || |
| 5340 | tp->mac_version == RTL_GIGA_MAC_VER_51) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5341 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5342 | rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 666); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5343 | } else { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5344 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) | StopReq); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5345 | udelay(100); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5346 | } |
| 5347 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5348 | rtl_hw_reset(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5349 | } |
| 5350 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5351 | static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5352 | { |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5353 | /* Set DMA burst size and Interframe Gap Time */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5354 | RTL_W32(tp, TxConfig, (TX_DMA_BURST << TxDMAShift) | |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5355 | (InterFrameGap << TxInterFrameGapShift)); |
| 5356 | } |
| 5357 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5358 | static void rtl_hw_start(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5359 | { |
| 5360 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5361 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5362 | tp->hw_start(dev); |
| 5363 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5364 | rtl_irq_enable_all(tp); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5365 | } |
| 5366 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5367 | static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp) |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5368 | { |
| 5369 | /* |
| 5370 | * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh |
| 5371 | * register to be written before TxDescAddrLow to work. |
| 5372 | * Switching from MMIO to I/O access fixes the issue as well. |
| 5373 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5374 | RTL_W32(tp, TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); |
| 5375 | RTL_W32(tp, TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); |
| 5376 | RTL_W32(tp, RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); |
| 5377 | RTL_W32(tp, RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5378 | } |
| 5379 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5380 | static u16 rtl_rw_cpluscmd(struct rtl8169_private *tp) |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5381 | { |
| 5382 | u16 cmd; |
| 5383 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5384 | cmd = RTL_R16(tp, CPlusCmd); |
| 5385 | RTL_W16(tp, CPlusCmd, cmd); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5386 | return cmd; |
| 5387 | } |
| 5388 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5389 | static void rtl_set_rx_max_size(struct rtl8169_private *tp, unsigned int rx_buf_sz) |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5390 | { |
| 5391 | /* Low hurts. Let's disable the filtering. */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5392 | RTL_W16(tp, RxMaxSize, rx_buf_sz + 1); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5393 | } |
| 5394 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5395 | 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] | 5396 | { |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 5397 | static const struct rtl_cfg2_info { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5398 | u32 mac_version; |
| 5399 | u32 clk; |
| 5400 | u32 val; |
| 5401 | } cfg2_info [] = { |
| 5402 | { RTL_GIGA_MAC_VER_05, PCI_Clock_33MHz, 0x000fff00 }, // 8110SCd |
| 5403 | { RTL_GIGA_MAC_VER_05, PCI_Clock_66MHz, 0x000fffff }, |
| 5404 | { RTL_GIGA_MAC_VER_06, PCI_Clock_33MHz, 0x00ffff00 }, // 8110SCe |
| 5405 | { RTL_GIGA_MAC_VER_06, PCI_Clock_66MHz, 0x00ffffff } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 5406 | }; |
| 5407 | const struct rtl_cfg2_info *p = cfg2_info; |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5408 | unsigned int i; |
| 5409 | u32 clk; |
| 5410 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5411 | clk = RTL_R8(tp, Config2) & PCI_Clock_66MHz; |
Francois Romieu | cadf185 | 2008-01-03 23:38:38 +0100 | [diff] [blame] | 5412 | for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5413 | if ((p->mac_version == mac_version) && (p->clk == clk)) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5414 | RTL_W32(tp, 0x7c, p->val); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5415 | break; |
| 5416 | } |
| 5417 | } |
| 5418 | } |
| 5419 | |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5420 | static void rtl_set_rx_mode(struct net_device *dev) |
| 5421 | { |
| 5422 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5423 | u32 mc_filter[2]; /* Multicast hash filter */ |
| 5424 | int rx_mode; |
| 5425 | u32 tmp = 0; |
| 5426 | |
| 5427 | if (dev->flags & IFF_PROMISC) { |
| 5428 | /* Unconditionally log net taps. */ |
| 5429 | netif_notice(tp, link, dev, "Promiscuous mode enabled\n"); |
| 5430 | rx_mode = |
| 5431 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys | |
| 5432 | AcceptAllPhys; |
| 5433 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 5434 | } else if ((netdev_mc_count(dev) > multicast_filter_limit) || |
| 5435 | (dev->flags & IFF_ALLMULTI)) { |
| 5436 | /* Too many to filter perfectly -- accept all multicasts. */ |
| 5437 | rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; |
| 5438 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 5439 | } else { |
| 5440 | struct netdev_hw_addr *ha; |
| 5441 | |
| 5442 | rx_mode = AcceptBroadcast | AcceptMyPhys; |
| 5443 | mc_filter[1] = mc_filter[0] = 0; |
| 5444 | netdev_for_each_mc_addr(ha, dev) { |
| 5445 | int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; |
| 5446 | mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); |
| 5447 | rx_mode |= AcceptMulticast; |
| 5448 | } |
| 5449 | } |
| 5450 | |
| 5451 | if (dev->features & NETIF_F_RXALL) |
| 5452 | rx_mode |= (AcceptErr | AcceptRunt); |
| 5453 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5454 | tmp = (RTL_R32(tp, RxConfig) & ~RX_CONFIG_ACCEPT_MASK) | rx_mode; |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5455 | |
| 5456 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) { |
| 5457 | u32 data = mc_filter[0]; |
| 5458 | |
| 5459 | mc_filter[0] = swab32(mc_filter[1]); |
| 5460 | mc_filter[1] = swab32(data); |
| 5461 | } |
| 5462 | |
Nathan Walp | 0481776 | 2012-11-01 12:08:47 +0000 | [diff] [blame] | 5463 | if (tp->mac_version == RTL_GIGA_MAC_VER_35) |
| 5464 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 5465 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5466 | RTL_W32(tp, MAR0 + 4, mc_filter[1]); |
| 5467 | RTL_W32(tp, MAR0 + 0, mc_filter[0]); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5468 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5469 | RTL_W32(tp, RxConfig, tmp); |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5470 | } |
| 5471 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5472 | static void rtl_hw_start_8169(struct net_device *dev) |
| 5473 | { |
| 5474 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5475 | struct pci_dev *pdev = tp->pci_dev; |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5476 | |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5477 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5478 | RTL_W16(tp, CPlusCmd, RTL_R16(tp, CPlusCmd) | PCIMulRW); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5479 | pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, 0x08); |
| 5480 | } |
| 5481 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5482 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5483 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 || |
| 5484 | tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 5485 | tp->mac_version == RTL_GIGA_MAC_VER_03 || |
| 5486 | tp->mac_version == RTL_GIGA_MAC_VER_04) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5487 | RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5488 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 5489 | rtl_init_rxcfg(tp); |
| 5490 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5491 | RTL_W8(tp, EarlyTxThres, NoEarlyTx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5492 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5493 | rtl_set_rx_max_size(tp, rx_buf_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5494 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5495 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 || |
| 5496 | tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 5497 | tp->mac_version == RTL_GIGA_MAC_VER_03 || |
| 5498 | tp->mac_version == RTL_GIGA_MAC_VER_04) |
Francois Romieu | c946b30 | 2007-10-04 00:42:50 +0200 | [diff] [blame] | 5499 | rtl_set_rx_tx_config_registers(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5500 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5501 | tp->cp_cmd |= rtl_rw_cpluscmd(tp) | PCIMulRW; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5502 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5503 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 5504 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 5505 | dprintk("Set MAC Reg C+CR Offset 0xe0. " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5506 | "Bit-3 and bit-14 MUST be 1\n"); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5507 | tp->cp_cmd |= (1 << 14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5508 | } |
| 5509 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5510 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5511 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5512 | rtl8169_set_magic_reg(tp, tp->mac_version); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5514 | /* |
| 5515 | * Undocumented corner. Supposedly: |
| 5516 | * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets |
| 5517 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5518 | RTL_W16(tp, IntrMitigate, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5519 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5520 | rtl_set_rx_tx_desc_registers(tp); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5521 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5522 | if (tp->mac_version != RTL_GIGA_MAC_VER_01 && |
| 5523 | tp->mac_version != RTL_GIGA_MAC_VER_02 && |
| 5524 | tp->mac_version != RTL_GIGA_MAC_VER_03 && |
| 5525 | tp->mac_version != RTL_GIGA_MAC_VER_04) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5526 | RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb); |
Francois Romieu | c946b30 | 2007-10-04 00:42:50 +0200 | [diff] [blame] | 5527 | rtl_set_rx_tx_config_registers(tp); |
| 5528 | } |
| 5529 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5530 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Francois Romieu | b518fa8 | 2006-08-16 15:23:13 +0200 | [diff] [blame] | 5531 | |
| 5532 | /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5533 | RTL_R8(tp, IntrMask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5534 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5535 | RTL_W32(tp, RxMissed, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5536 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5537 | rtl_set_rx_mode(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5538 | |
| 5539 | /* no early-rx interrupts */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5540 | RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5541 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5542 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5543 | static void rtl_csi_write(struct rtl8169_private *tp, int addr, int value) |
| 5544 | { |
| 5545 | if (tp->csi_ops.write) |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5546 | tp->csi_ops.write(tp, addr, value); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5547 | } |
| 5548 | |
| 5549 | static u32 rtl_csi_read(struct rtl8169_private *tp, int addr) |
| 5550 | { |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5551 | return tp->csi_ops.read ? tp->csi_ops.read(tp, addr) : ~0; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5552 | } |
| 5553 | |
| 5554 | static void rtl_csi_access_enable(struct rtl8169_private *tp, u32 bits) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5555 | { |
| 5556 | u32 csi; |
| 5557 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5558 | csi = rtl_csi_read(tp, 0x070c) & 0x00ffffff; |
| 5559 | rtl_csi_write(tp, 0x070c, csi | bits); |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 5560 | } |
| 5561 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5562 | static void rtl_csi_access_enable_1(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5563 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5564 | rtl_csi_access_enable(tp, 0x17000000); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5565 | } |
| 5566 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5567 | static void rtl_csi_access_enable_2(struct rtl8169_private *tp) |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 5568 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5569 | rtl_csi_access_enable(tp, 0x27000000); |
| 5570 | } |
| 5571 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5572 | DECLARE_RTL_COND(rtl_csiar_cond) |
| 5573 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5574 | return RTL_R32(tp, CSIAR) & CSIAR_FLAG; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5575 | } |
| 5576 | |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5577 | 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] | 5578 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5579 | RTL_W32(tp, CSIDR, value); |
| 5580 | RTL_W32(tp, CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5581 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 5582 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5583 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5584 | } |
| 5585 | |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5586 | static u32 r8169_csi_read(struct rtl8169_private *tp, int addr) |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5587 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5588 | RTL_W32(tp, CSIAR, (addr & CSIAR_ADDR_MASK) | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5589 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 5590 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5591 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5592 | RTL_R32(tp, CSIDR) : ~0; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5593 | } |
| 5594 | |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5595 | 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] | 5596 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5597 | RTL_W32(tp, CSIDR, value); |
| 5598 | RTL_W32(tp, CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5599 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT | |
| 5600 | CSIAR_FUNC_NIC); |
| 5601 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5602 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5603 | } |
| 5604 | |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5605 | static u32 r8402_csi_read(struct rtl8169_private *tp, int addr) |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5606 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5607 | RTL_W32(tp, CSIAR, (addr & CSIAR_ADDR_MASK) | CSIAR_FUNC_NIC | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5608 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 5609 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5610 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5611 | RTL_R32(tp, CSIDR) : ~0; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5612 | } |
| 5613 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5614 | static void r8411_csi_write(struct rtl8169_private *tp, int addr, int value) |
| 5615 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5616 | RTL_W32(tp, CSIDR, value); |
| 5617 | RTL_W32(tp, CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5618 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT | |
| 5619 | CSIAR_FUNC_NIC2); |
| 5620 | |
| 5621 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
| 5622 | } |
| 5623 | |
| 5624 | static u32 r8411_csi_read(struct rtl8169_private *tp, int addr) |
| 5625 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5626 | RTL_W32(tp, CSIAR, (addr & CSIAR_ADDR_MASK) | CSIAR_FUNC_NIC2 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5627 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 5628 | |
| 5629 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5630 | RTL_R32(tp, CSIDR) : ~0; |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5631 | } |
| 5632 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 5633 | static void rtl_init_csi_ops(struct rtl8169_private *tp) |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5634 | { |
| 5635 | struct csi_ops *ops = &tp->csi_ops; |
| 5636 | |
| 5637 | switch (tp->mac_version) { |
| 5638 | case RTL_GIGA_MAC_VER_01: |
| 5639 | case RTL_GIGA_MAC_VER_02: |
| 5640 | case RTL_GIGA_MAC_VER_03: |
| 5641 | case RTL_GIGA_MAC_VER_04: |
| 5642 | case RTL_GIGA_MAC_VER_05: |
| 5643 | case RTL_GIGA_MAC_VER_06: |
| 5644 | case RTL_GIGA_MAC_VER_10: |
| 5645 | case RTL_GIGA_MAC_VER_11: |
| 5646 | case RTL_GIGA_MAC_VER_12: |
| 5647 | case RTL_GIGA_MAC_VER_13: |
| 5648 | case RTL_GIGA_MAC_VER_14: |
| 5649 | case RTL_GIGA_MAC_VER_15: |
| 5650 | case RTL_GIGA_MAC_VER_16: |
| 5651 | case RTL_GIGA_MAC_VER_17: |
| 5652 | ops->write = NULL; |
| 5653 | ops->read = NULL; |
| 5654 | break; |
| 5655 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5656 | case RTL_GIGA_MAC_VER_37: |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5657 | case RTL_GIGA_MAC_VER_38: |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5658 | ops->write = r8402_csi_write; |
| 5659 | ops->read = r8402_csi_read; |
| 5660 | break; |
| 5661 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5662 | case RTL_GIGA_MAC_VER_44: |
| 5663 | ops->write = r8411_csi_write; |
| 5664 | ops->read = r8411_csi_read; |
| 5665 | break; |
| 5666 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5667 | default: |
| 5668 | ops->write = r8169_csi_write; |
| 5669 | ops->read = r8169_csi_read; |
| 5670 | break; |
| 5671 | } |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5672 | } |
| 5673 | |
| 5674 | struct ephy_info { |
| 5675 | unsigned int offset; |
| 5676 | u16 mask; |
| 5677 | u16 bits; |
| 5678 | }; |
| 5679 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5680 | static void rtl_ephy_init(struct rtl8169_private *tp, const struct ephy_info *e, |
| 5681 | int len) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5682 | { |
| 5683 | u16 w; |
| 5684 | |
| 5685 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5686 | w = (rtl_ephy_read(tp, e->offset) & ~e->mask) | e->bits; |
| 5687 | rtl_ephy_write(tp, e->offset, w); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5688 | e++; |
| 5689 | } |
| 5690 | } |
| 5691 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5692 | static void rtl_disable_clock_request(struct rtl8169_private *tp) |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5693 | { |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5694 | pcie_capability_clear_word(tp->pci_dev, PCI_EXP_LNKCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 5695 | PCI_EXP_LNKCTL_CLKREQ_EN); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5696 | } |
| 5697 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5698 | static void rtl_enable_clock_request(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5699 | { |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5700 | pcie_capability_set_word(tp->pci_dev, PCI_EXP_LNKCTL, |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 5701 | PCI_EXP_LNKCTL_CLKREQ_EN); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5702 | } |
| 5703 | |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5704 | static void rtl_pcie_state_l2l3_enable(struct rtl8169_private *tp, bool enable) |
| 5705 | { |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5706 | u8 data; |
| 5707 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5708 | data = RTL_R8(tp, Config3); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5709 | |
| 5710 | if (enable) |
| 5711 | data |= Rdy_to_L23; |
| 5712 | else |
| 5713 | data &= ~Rdy_to_L23; |
| 5714 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5715 | RTL_W8(tp, Config3, data); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5716 | } |
| 5717 | |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5718 | #define R8168_CPCMD_QUIRK_MASK (\ |
| 5719 | EnableBist | \ |
| 5720 | Mac_dbgo_oe | \ |
| 5721 | Force_half_dup | \ |
| 5722 | Force_rxflow_en | \ |
| 5723 | Force_txflow_en | \ |
| 5724 | Cxpl_dbg_sel | \ |
| 5725 | ASF | \ |
| 5726 | PktCntrDisable | \ |
| 5727 | Mac_dbgo_sel) |
| 5728 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5729 | static void rtl_hw_start_8168bb(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5730 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5731 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5732 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5733 | RTL_W16(tp, CPlusCmd, RTL_R16(tp, CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5734 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5735 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5736 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5737 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 5738 | } |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5739 | } |
| 5740 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5741 | static void rtl_hw_start_8168bef(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5742 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5743 | rtl_hw_start_8168bb(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5744 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5745 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5746 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5747 | RTL_W8(tp, Config4, RTL_R8(tp, Config4) & ~(1 << 0)); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5748 | } |
| 5749 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5750 | static void __rtl_hw_start_8168cp(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5751 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5752 | RTL_W8(tp, Config1, RTL_R8(tp, Config1) | Speed_down); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5753 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5754 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5755 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5756 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5757 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5758 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5759 | rtl_disable_clock_request(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5760 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5761 | RTL_W16(tp, CPlusCmd, RTL_R16(tp, CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5762 | } |
| 5763 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5764 | static void rtl_hw_start_8168cp_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5765 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5766 | static const struct ephy_info e_info_8168cp[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5767 | { 0x01, 0, 0x0001 }, |
| 5768 | { 0x02, 0x0800, 0x1000 }, |
| 5769 | { 0x03, 0, 0x0042 }, |
| 5770 | { 0x06, 0x0080, 0x0000 }, |
| 5771 | { 0x07, 0, 0x2000 } |
| 5772 | }; |
| 5773 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5774 | rtl_csi_access_enable_2(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5775 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5776 | rtl_ephy_init(tp, e_info_8168cp, ARRAY_SIZE(e_info_8168cp)); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5777 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5778 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5779 | } |
| 5780 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5781 | static void rtl_hw_start_8168cp_2(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5782 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5783 | rtl_csi_access_enable_2(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5784 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5785 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5786 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5787 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5788 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5789 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5790 | RTL_W16(tp, CPlusCmd, RTL_R16(tp, CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5791 | } |
| 5792 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5793 | static void rtl_hw_start_8168cp_3(struct rtl8169_private *tp) |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5794 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5795 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5796 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5797 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5798 | |
| 5799 | /* Magic. */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5800 | RTL_W8(tp, DBG_REG, 0x20); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5801 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5802 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5803 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5804 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5805 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5806 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5807 | RTL_W16(tp, CPlusCmd, RTL_R16(tp, CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5808 | } |
| 5809 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5810 | static void rtl_hw_start_8168c_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5811 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5812 | static const struct ephy_info e_info_8168c_1[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5813 | { 0x02, 0x0800, 0x1000 }, |
| 5814 | { 0x03, 0, 0x0002 }, |
| 5815 | { 0x06, 0x0080, 0x0000 } |
| 5816 | }; |
| 5817 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5818 | rtl_csi_access_enable_2(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5819 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5820 | RTL_W8(tp, DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5821 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5822 | 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] | 5823 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5824 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5825 | } |
| 5826 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5827 | static void rtl_hw_start_8168c_2(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5828 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5829 | static const struct ephy_info e_info_8168c_2[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5830 | { 0x01, 0, 0x0001 }, |
| 5831 | { 0x03, 0x0400, 0x0220 } |
| 5832 | }; |
| 5833 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5834 | rtl_csi_access_enable_2(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5835 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5836 | 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] | 5837 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5838 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5839 | } |
| 5840 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5841 | static void rtl_hw_start_8168c_3(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5842 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5843 | rtl_hw_start_8168c_2(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5844 | } |
| 5845 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5846 | static void rtl_hw_start_8168c_4(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5847 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5848 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5849 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5850 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5851 | } |
| 5852 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5853 | static void rtl_hw_start_8168d(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5854 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5855 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5856 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5857 | rtl_disable_clock_request(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5858 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5859 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5860 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5861 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5862 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5863 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5864 | RTL_W16(tp, CPlusCmd, RTL_R16(tp, CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5865 | } |
| 5866 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5867 | static void rtl_hw_start_8168dp(struct rtl8169_private *tp) |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5868 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5869 | rtl_csi_access_enable_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5870 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5871 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5872 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5873 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5874 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5875 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5876 | rtl_disable_clock_request(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5877 | } |
| 5878 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5879 | static void rtl_hw_start_8168d_4(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5880 | { |
| 5881 | static const struct ephy_info e_info_8168d_4[] = { |
Chun-Hao Lin | 1016a4a | 2015-12-29 22:13:39 +0800 | [diff] [blame] | 5882 | { 0x0b, 0x0000, 0x0048 }, |
| 5883 | { 0x19, 0x0020, 0x0050 }, |
| 5884 | { 0x0c, 0x0100, 0x0020 } |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5885 | }; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5886 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5887 | rtl_csi_access_enable_1(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5888 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5889 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5890 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5891 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5892 | |
Chun-Hao Lin | 1016a4a | 2015-12-29 22:13:39 +0800 | [diff] [blame] | 5893 | 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] | 5894 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5895 | rtl_enable_clock_request(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5896 | } |
| 5897 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5898 | static void rtl_hw_start_8168e_1(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5899 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5900 | static const struct ephy_info e_info_8168e_1[] = { |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5901 | { 0x00, 0x0200, 0x0100 }, |
| 5902 | { 0x00, 0x0000, 0x0004 }, |
| 5903 | { 0x06, 0x0002, 0x0001 }, |
| 5904 | { 0x06, 0x0000, 0x0030 }, |
| 5905 | { 0x07, 0x0000, 0x2000 }, |
| 5906 | { 0x00, 0x0000, 0x0020 }, |
| 5907 | { 0x03, 0x5800, 0x2000 }, |
| 5908 | { 0x03, 0x0000, 0x0001 }, |
| 5909 | { 0x01, 0x0800, 0x1000 }, |
| 5910 | { 0x07, 0x0000, 0x4000 }, |
| 5911 | { 0x1e, 0x0000, 0x2000 }, |
| 5912 | { 0x19, 0xffff, 0xfe6c }, |
| 5913 | { 0x0a, 0x0000, 0x0040 } |
| 5914 | }; |
| 5915 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5916 | rtl_csi_access_enable_2(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5917 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5918 | 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] | 5919 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5920 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5921 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5922 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5923 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5924 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5925 | rtl_disable_clock_request(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5926 | |
| 5927 | /* Reset tx FIFO pointer */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5928 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | TXPLA_RST); |
| 5929 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~TXPLA_RST); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5930 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5931 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5932 | } |
| 5933 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5934 | static void rtl_hw_start_8168e_2(struct rtl8169_private *tp) |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5935 | { |
| 5936 | static const struct ephy_info e_info_8168e_2[] = { |
| 5937 | { 0x09, 0x0000, 0x0080 }, |
| 5938 | { 0x19, 0x0000, 0x0224 } |
| 5939 | }; |
| 5940 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5941 | rtl_csi_access_enable_1(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5942 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5943 | 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] | 5944 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5945 | if (tp->dev->mtu <= ETH_DATA_LEN) |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5946 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5947 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5948 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5949 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5950 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 5951 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5952 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 5953 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x07ff0060, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5954 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 5955 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5956 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5957 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5958 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5959 | rtl_disable_clock_request(tp); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 5960 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5961 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
| 5962 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5963 | |
| 5964 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5965 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5966 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5967 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
| 5968 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN); |
| 5969 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5970 | } |
| 5971 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5972 | static void rtl_hw_start_8168f(struct rtl8169_private *tp) |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5973 | { |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5974 | rtl_csi_access_enable_2(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5975 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 5976 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5977 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5978 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5979 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5980 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 5981 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5982 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5983 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 5984 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 5985 | rtl_w0w1_eri(tp, 0x1d0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5986 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 5987 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x00000060, ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5988 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5989 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5990 | |
Heiner Kallweit | 73c86ee | 2018-03-20 07:45:40 +0100 | [diff] [blame] | 5991 | rtl_disable_clock_request(tp); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 5992 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 5993 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
| 5994 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
| 5995 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
| 5996 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | PWM_EN); |
| 5997 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~Spi_en); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5998 | } |
| 5999 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 6000 | static void rtl_hw_start_8168f_1(struct rtl8169_private *tp) |
| 6001 | { |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 6002 | static const struct ephy_info e_info_8168f_1[] = { |
| 6003 | { 0x06, 0x00c0, 0x0020 }, |
| 6004 | { 0x08, 0x0001, 0x0002 }, |
| 6005 | { 0x09, 0x0000, 0x0080 }, |
| 6006 | { 0x19, 0x0000, 0x0224 } |
| 6007 | }; |
| 6008 | |
| 6009 | rtl_hw_start_8168f(tp); |
| 6010 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6011 | 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] | 6012 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6013 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 6014 | |
| 6015 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6016 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 6017 | } |
| 6018 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 6019 | static void rtl_hw_start_8411(struct rtl8169_private *tp) |
| 6020 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 6021 | static const struct ephy_info e_info_8168f_1[] = { |
| 6022 | { 0x06, 0x00c0, 0x0020 }, |
| 6023 | { 0x0f, 0xffff, 0x5200 }, |
| 6024 | { 0x1e, 0x0000, 0x4000 }, |
| 6025 | { 0x19, 0x0000, 0x0224 } |
| 6026 | }; |
| 6027 | |
| 6028 | rtl_hw_start_8168f(tp); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 6029 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 6030 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6031 | 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] | 6032 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6033 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 6034 | } |
| 6035 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 6036 | static void rtl_hw_start_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6037 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6038 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 6039 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6040 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x080002, ERIAR_EXGMAC); |
| 6041 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC); |
| 6042 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC); |
| 6043 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 6044 | |
| 6045 | rtl_csi_access_enable_1(tp); |
| 6046 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 6047 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
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, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 6050 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 6051 | rtl_eri_write(tp, 0x2f8, ERIAR_MASK_0011, 0x1d8f, ERIAR_EXGMAC); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6052 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6053 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 6054 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6055 | |
| 6056 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6057 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6058 | |
| 6059 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6060 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6061 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6062 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC); |
| 6063 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, 0x1000, ERIAR_EXGMAC); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 6064 | |
| 6065 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6066 | } |
| 6067 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 6068 | static void rtl_hw_start_8168g_1(struct rtl8169_private *tp) |
| 6069 | { |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 6070 | static const struct ephy_info e_info_8168g_1[] = { |
| 6071 | { 0x00, 0x0000, 0x0008 }, |
| 6072 | { 0x0c, 0x37d0, 0x0820 }, |
| 6073 | { 0x1e, 0x0000, 0x0001 }, |
| 6074 | { 0x19, 0x8000, 0x0000 } |
| 6075 | }; |
| 6076 | |
| 6077 | rtl_hw_start_8168g(tp); |
| 6078 | |
| 6079 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6080 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 6081 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 6082 | rtl_ephy_init(tp, e_info_8168g_1, ARRAY_SIZE(e_info_8168g_1)); |
| 6083 | } |
| 6084 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 6085 | static void rtl_hw_start_8168g_2(struct rtl8169_private *tp) |
| 6086 | { |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 6087 | static const struct ephy_info e_info_8168g_2[] = { |
| 6088 | { 0x00, 0x0000, 0x0008 }, |
| 6089 | { 0x0c, 0x3df0, 0x0200 }, |
| 6090 | { 0x19, 0xffff, 0xfc00 }, |
| 6091 | { 0x1e, 0xffff, 0x20eb } |
| 6092 | }; |
| 6093 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 6094 | rtl_hw_start_8168g(tp); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 6095 | |
| 6096 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6097 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 6098 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 6099 | rtl_ephy_init(tp, e_info_8168g_2, ARRAY_SIZE(e_info_8168g_2)); |
| 6100 | } |
| 6101 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 6102 | static void rtl_hw_start_8411_2(struct rtl8169_private *tp) |
| 6103 | { |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 6104 | static const struct ephy_info e_info_8411_2[] = { |
| 6105 | { 0x00, 0x0000, 0x0008 }, |
| 6106 | { 0x0c, 0x3df0, 0x0200 }, |
| 6107 | { 0x0f, 0xffff, 0x5200 }, |
| 6108 | { 0x19, 0x0020, 0x0000 }, |
| 6109 | { 0x1e, 0x0000, 0x2000 } |
| 6110 | }; |
| 6111 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 6112 | rtl_hw_start_8168g(tp); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 6113 | |
| 6114 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6115 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 6116 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 6117 | rtl_ephy_init(tp, e_info_8411_2, ARRAY_SIZE(e_info_8411_2)); |
| 6118 | } |
| 6119 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6120 | static void rtl_hw_start_8168h_1(struct rtl8169_private *tp) |
| 6121 | { |
Andrzej Hajda | 72521ea | 2015-09-24 16:00:24 +0200 | [diff] [blame] | 6122 | int rg_saw_cnt; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6123 | u32 data; |
| 6124 | static const struct ephy_info e_info_8168h_1[] = { |
| 6125 | { 0x1e, 0x0800, 0x0001 }, |
| 6126 | { 0x1d, 0x0000, 0x0800 }, |
| 6127 | { 0x05, 0xffff, 0x2089 }, |
| 6128 | { 0x06, 0xffff, 0x5881 }, |
| 6129 | { 0x04, 0xffff, 0x154a }, |
| 6130 | { 0x01, 0xffff, 0x068b } |
| 6131 | }; |
| 6132 | |
| 6133 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6134 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 6135 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6136 | rtl_ephy_init(tp, e_info_8168h_1, ARRAY_SIZE(e_info_8168h_1)); |
| 6137 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6138 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6139 | |
| 6140 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC); |
| 6141 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC); |
| 6142 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC); |
| 6143 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 6144 | |
| 6145 | rtl_csi_access_enable_1(tp); |
| 6146 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 6147 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6148 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6149 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 6150 | 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] | 6151 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6152 | 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] | 6153 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6154 | 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] | 6155 | |
| 6156 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC); |
| 6157 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6158 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 6159 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6160 | |
| 6161 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6162 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6163 | |
| 6164 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6165 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6166 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6167 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 6168 | 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] | 6169 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6170 | 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] | 6171 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6172 | 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] | 6173 | |
| 6174 | rtl_pcie_state_l2l3_enable(tp, false); |
| 6175 | |
| 6176 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 5849333 | 2015-12-24 21:15:27 +0800 | [diff] [blame] | 6177 | rg_saw_cnt = (rtl_readphy(tp, 0x13) & 0x3fff); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6178 | rtl_writephy(tp, 0x1f, 0x0000); |
| 6179 | if (rg_saw_cnt > 0) { |
| 6180 | u16 sw_cnt_1ms_ini; |
| 6181 | |
| 6182 | sw_cnt_1ms_ini = 16000000/rg_saw_cnt; |
| 6183 | sw_cnt_1ms_ini &= 0x0fff; |
| 6184 | data = r8168_mac_ocp_read(tp, 0xd412); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 6185 | data &= ~0x0fff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6186 | data |= sw_cnt_1ms_ini; |
| 6187 | r8168_mac_ocp_write(tp, 0xd412, data); |
| 6188 | } |
| 6189 | |
| 6190 | data = r8168_mac_ocp_read(tp, 0xe056); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 6191 | data &= ~0xf0; |
| 6192 | data |= 0x70; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6193 | r8168_mac_ocp_write(tp, 0xe056, data); |
| 6194 | |
| 6195 | data = r8168_mac_ocp_read(tp, 0xe052); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 6196 | data &= ~0x6000; |
| 6197 | data |= 0x8008; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6198 | r8168_mac_ocp_write(tp, 0xe052, data); |
| 6199 | |
| 6200 | data = r8168_mac_ocp_read(tp, 0xe0d6); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 6201 | data &= ~0x01ff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6202 | data |= 0x017f; |
| 6203 | r8168_mac_ocp_write(tp, 0xe0d6, data); |
| 6204 | |
| 6205 | data = r8168_mac_ocp_read(tp, 0xd420); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 6206 | data &= ~0x0fff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6207 | data |= 0x047f; |
| 6208 | r8168_mac_ocp_write(tp, 0xd420, data); |
| 6209 | |
| 6210 | r8168_mac_ocp_write(tp, 0xe63e, 0x0001); |
| 6211 | r8168_mac_ocp_write(tp, 0xe63e, 0x0000); |
| 6212 | r8168_mac_ocp_write(tp, 0xc094, 0x0000); |
| 6213 | r8168_mac_ocp_write(tp, 0xc09e, 0x0000); |
| 6214 | } |
| 6215 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6216 | static void rtl_hw_start_8168ep(struct rtl8169_private *tp) |
| 6217 | { |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 6218 | rtl8168ep_stop_cmac(tp); |
| 6219 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6220 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6221 | |
| 6222 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC); |
| 6223 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x2f, ERIAR_EXGMAC); |
| 6224 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x5f, ERIAR_EXGMAC); |
| 6225 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 6226 | |
| 6227 | rtl_csi_access_enable_1(tp); |
| 6228 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 6229 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6230 | |
| 6231 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 6232 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 6233 | |
| 6234 | rtl_w0w1_eri(tp, 0xd4, ERIAR_MASK_1111, 0x1f80, 0x00, ERIAR_EXGMAC); |
| 6235 | |
| 6236 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC); |
| 6237 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6238 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) & ~RXDV_GATED_EN); |
| 6239 | RTL_W8(tp, MaxTxPacketSize, EarlySize); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6240 | |
| 6241 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6242 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6243 | |
| 6244 | /* Adjust EEE LED frequency */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6245 | RTL_W8(tp, EEE_LED, RTL_R8(tp, EEE_LED) & ~0x07); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6246 | |
| 6247 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC); |
| 6248 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6249 | 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] | 6250 | |
| 6251 | rtl_pcie_state_l2l3_enable(tp, false); |
| 6252 | } |
| 6253 | |
| 6254 | static void rtl_hw_start_8168ep_1(struct rtl8169_private *tp) |
| 6255 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6256 | static const struct ephy_info e_info_8168ep_1[] = { |
| 6257 | { 0x00, 0xffff, 0x10ab }, |
| 6258 | { 0x06, 0xffff, 0xf030 }, |
| 6259 | { 0x08, 0xffff, 0x2006 }, |
| 6260 | { 0x0d, 0xffff, 0x1666 }, |
| 6261 | { 0x0c, 0x3ff0, 0x0000 } |
| 6262 | }; |
| 6263 | |
| 6264 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6265 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 6266 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6267 | rtl_ephy_init(tp, e_info_8168ep_1, ARRAY_SIZE(e_info_8168ep_1)); |
| 6268 | |
| 6269 | rtl_hw_start_8168ep(tp); |
| 6270 | } |
| 6271 | |
| 6272 | static void rtl_hw_start_8168ep_2(struct rtl8169_private *tp) |
| 6273 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6274 | static const struct ephy_info e_info_8168ep_2[] = { |
| 6275 | { 0x00, 0xffff, 0x10a3 }, |
| 6276 | { 0x19, 0xffff, 0xfc00 }, |
| 6277 | { 0x1e, 0xffff, 0x20ea } |
| 6278 | }; |
| 6279 | |
| 6280 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6281 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 6282 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6283 | rtl_ephy_init(tp, e_info_8168ep_2, ARRAY_SIZE(e_info_8168ep_2)); |
| 6284 | |
| 6285 | rtl_hw_start_8168ep(tp); |
| 6286 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6287 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 6288 | 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] | 6289 | } |
| 6290 | |
| 6291 | static void rtl_hw_start_8168ep_3(struct rtl8169_private *tp) |
| 6292 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6293 | u32 data; |
| 6294 | static const struct ephy_info e_info_8168ep_3[] = { |
| 6295 | { 0x00, 0xffff, 0x10a3 }, |
| 6296 | { 0x19, 0xffff, 0x7c00 }, |
| 6297 | { 0x1e, 0xffff, 0x20eb }, |
| 6298 | { 0x0d, 0xffff, 0x1666 } |
| 6299 | }; |
| 6300 | |
| 6301 | /* disable aspm and clock request before access ephy */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6302 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~ClkReqEn); |
| 6303 | RTL_W8(tp, Config5, RTL_R8(tp, Config5) & ~ASPM_en); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6304 | rtl_ephy_init(tp, e_info_8168ep_3, ARRAY_SIZE(e_info_8168ep_3)); |
| 6305 | |
| 6306 | rtl_hw_start_8168ep(tp); |
| 6307 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6308 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
| 6309 | 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] | 6310 | |
| 6311 | data = r8168_mac_ocp_read(tp, 0xd3e2); |
| 6312 | data &= 0xf000; |
| 6313 | data |= 0x0271; |
| 6314 | r8168_mac_ocp_write(tp, 0xd3e2, data); |
| 6315 | |
| 6316 | data = r8168_mac_ocp_read(tp, 0xd3e4); |
| 6317 | data &= 0xff00; |
| 6318 | r8168_mac_ocp_write(tp, 0xd3e4, data); |
| 6319 | |
| 6320 | data = r8168_mac_ocp_read(tp, 0xe860); |
| 6321 | data |= 0x0080; |
| 6322 | r8168_mac_ocp_write(tp, 0xe860, data); |
| 6323 | } |
| 6324 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 6325 | static void rtl_hw_start_8168(struct net_device *dev) |
| 6326 | { |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6327 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6328 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6329 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6330 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6331 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6332 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6333 | rtl_set_rx_max_size(tp, rx_buf_sz); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6334 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6335 | tp->cp_cmd |= RTL_R16(tp, CPlusCmd) | PktCntrDisable | INTT_1; |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6336 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6337 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6338 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6339 | RTL_W16(tp, IntrMitigate, 0x5151); |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 6340 | |
| 6341 | /* Work around for RxFIFO overflow. */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 6342 | if (tp->mac_version == RTL_GIGA_MAC_VER_11) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6343 | tp->event_slow |= RxFIFOOver | PCSTimeout; |
| 6344 | tp->event_slow &= ~RxOverflow; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 6345 | } |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6346 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6347 | rtl_set_rx_tx_desc_registers(tp); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6348 | |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6349 | rtl_set_rx_tx_config_registers(tp); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6350 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6351 | RTL_R8(tp, IntrMask); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6352 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6353 | switch (tp->mac_version) { |
| 6354 | case RTL_GIGA_MAC_VER_11: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6355 | rtl_hw_start_8168bb(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6356 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6357 | |
| 6358 | case RTL_GIGA_MAC_VER_12: |
| 6359 | case RTL_GIGA_MAC_VER_17: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6360 | rtl_hw_start_8168bef(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6361 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6362 | |
| 6363 | case RTL_GIGA_MAC_VER_18: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6364 | rtl_hw_start_8168cp_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6365 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6366 | |
| 6367 | case RTL_GIGA_MAC_VER_19: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6368 | rtl_hw_start_8168c_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6369 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6370 | |
| 6371 | case RTL_GIGA_MAC_VER_20: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6372 | rtl_hw_start_8168c_2(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6373 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6374 | |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 6375 | case RTL_GIGA_MAC_VER_21: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6376 | rtl_hw_start_8168c_3(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6377 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 6378 | |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 6379 | case RTL_GIGA_MAC_VER_22: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6380 | rtl_hw_start_8168c_4(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6381 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 6382 | |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 6383 | case RTL_GIGA_MAC_VER_23: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6384 | rtl_hw_start_8168cp_2(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6385 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 6386 | |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 6387 | case RTL_GIGA_MAC_VER_24: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6388 | rtl_hw_start_8168cp_3(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6389 | break; |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 6390 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 6391 | case RTL_GIGA_MAC_VER_25: |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 6392 | case RTL_GIGA_MAC_VER_26: |
| 6393 | case RTL_GIGA_MAC_VER_27: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6394 | rtl_hw_start_8168d(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6395 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 6396 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 6397 | case RTL_GIGA_MAC_VER_28: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6398 | rtl_hw_start_8168d_4(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6399 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6400 | |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6401 | case RTL_GIGA_MAC_VER_31: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6402 | rtl_hw_start_8168dp(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6403 | break; |
| 6404 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 6405 | case RTL_GIGA_MAC_VER_32: |
| 6406 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6407 | rtl_hw_start_8168e_1(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 6408 | break; |
| 6409 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6410 | rtl_hw_start_8168e_2(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 6411 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 6412 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 6413 | case RTL_GIGA_MAC_VER_35: |
| 6414 | case RTL_GIGA_MAC_VER_36: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6415 | rtl_hw_start_8168f_1(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 6416 | break; |
| 6417 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 6418 | case RTL_GIGA_MAC_VER_38: |
| 6419 | rtl_hw_start_8411(tp); |
| 6420 | break; |
| 6421 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6422 | case RTL_GIGA_MAC_VER_40: |
| 6423 | case RTL_GIGA_MAC_VER_41: |
| 6424 | rtl_hw_start_8168g_1(tp); |
| 6425 | break; |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 6426 | case RTL_GIGA_MAC_VER_42: |
| 6427 | rtl_hw_start_8168g_2(tp); |
| 6428 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6429 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 6430 | case RTL_GIGA_MAC_VER_44: |
| 6431 | rtl_hw_start_8411_2(tp); |
| 6432 | break; |
| 6433 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6434 | case RTL_GIGA_MAC_VER_45: |
| 6435 | case RTL_GIGA_MAC_VER_46: |
| 6436 | rtl_hw_start_8168h_1(tp); |
| 6437 | break; |
| 6438 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6439 | case RTL_GIGA_MAC_VER_49: |
| 6440 | rtl_hw_start_8168ep_1(tp); |
| 6441 | break; |
| 6442 | |
| 6443 | case RTL_GIGA_MAC_VER_50: |
| 6444 | rtl_hw_start_8168ep_2(tp); |
| 6445 | break; |
| 6446 | |
| 6447 | case RTL_GIGA_MAC_VER_51: |
| 6448 | rtl_hw_start_8168ep_3(tp); |
| 6449 | break; |
| 6450 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6451 | default: |
| 6452 | printk(KERN_ERR PFX "%s: unknown chipset (mac_version = %d).\n", |
| 6453 | dev->name, tp->mac_version); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6454 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6455 | } |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6456 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6457 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6458 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6459 | RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb); |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 6460 | |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6461 | rtl_set_rx_mode(dev); |
Francois Romieu | b836390 | 2008-06-01 12:31:57 +0200 | [diff] [blame] | 6462 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6463 | RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 6464 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6465 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6466 | #define R810X_CPCMD_QUIRK_MASK (\ |
| 6467 | EnableBist | \ |
| 6468 | Mac_dbgo_oe | \ |
| 6469 | Force_half_dup | \ |
françois romieu | 5edcc53 | 2009-08-10 19:41:52 +0000 | [diff] [blame] | 6470 | Force_rxflow_en | \ |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6471 | Force_txflow_en | \ |
| 6472 | Cxpl_dbg_sel | \ |
| 6473 | ASF | \ |
| 6474 | PktCntrDisable | \ |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 6475 | Mac_dbgo_sel) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6476 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6477 | static void rtl_hw_start_8102e_1(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6478 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 6479 | static const struct ephy_info e_info_8102e_1[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6480 | { 0x01, 0, 0x6e65 }, |
| 6481 | { 0x02, 0, 0x091f }, |
| 6482 | { 0x03, 0, 0xc2f9 }, |
| 6483 | { 0x06, 0, 0xafb5 }, |
| 6484 | { 0x07, 0, 0x0e00 }, |
| 6485 | { 0x19, 0, 0xec80 }, |
| 6486 | { 0x01, 0, 0x2e65 }, |
| 6487 | { 0x01, 0, 0x6e65 } |
| 6488 | }; |
| 6489 | u8 cfg1; |
| 6490 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6491 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6492 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6493 | RTL_W8(tp, DBG_REG, FIX_NAK_1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6494 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 6495 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6496 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6497 | RTL_W8(tp, Config1, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6498 | LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6499 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6500 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6501 | cfg1 = RTL_R8(tp, Config1); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6502 | if ((cfg1 & LEDS0) && (cfg1 & LEDS1)) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6503 | RTL_W8(tp, Config1, cfg1 & ~LEDS0); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6504 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6505 | 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] | 6506 | } |
| 6507 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6508 | static void rtl_hw_start_8102e_2(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6509 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6510 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6511 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 6512 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6513 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6514 | RTL_W8(tp, Config1, MEMMAP | IOMAP | VPD | PMEnable); |
| 6515 | RTL_W8(tp, Config3, RTL_R8(tp, Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6516 | } |
| 6517 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6518 | static void rtl_hw_start_8102e_3(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6519 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6520 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6521 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6522 | rtl_ephy_write(tp, 0x03, 0xc2f9); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6523 | } |
| 6524 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6525 | static void rtl_hw_start_8105e_1(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6526 | { |
| 6527 | static const struct ephy_info e_info_8105e_1[] = { |
| 6528 | { 0x07, 0, 0x4000 }, |
| 6529 | { 0x19, 0, 0x0200 }, |
| 6530 | { 0x19, 0, 0x0020 }, |
| 6531 | { 0x1e, 0, 0x2000 }, |
| 6532 | { 0x03, 0, 0x0001 }, |
| 6533 | { 0x19, 0, 0x0100 }, |
| 6534 | { 0x19, 0, 0x0004 }, |
| 6535 | { 0x0a, 0, 0x0020 } |
| 6536 | }; |
| 6537 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6538 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6539 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6540 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6541 | /* Disable Early Tally Counter */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6542 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) & ~0x010000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6543 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6544 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET); |
| 6545 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) | PFM_EN); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6546 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6547 | 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] | 6548 | |
| 6549 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6550 | } |
| 6551 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6552 | static void rtl_hw_start_8105e_2(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6553 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6554 | rtl_hw_start_8105e_1(tp); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6555 | rtl_ephy_write(tp, 0x1e, rtl_ephy_read(tp, 0x1e) | 0x8000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6556 | } |
| 6557 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6558 | static void rtl_hw_start_8402(struct rtl8169_private *tp) |
| 6559 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6560 | static const struct ephy_info e_info_8402[] = { |
| 6561 | { 0x19, 0xffff, 0xff64 }, |
| 6562 | { 0x1e, 0, 0x4000 } |
| 6563 | }; |
| 6564 | |
| 6565 | rtl_csi_access_enable_2(tp); |
| 6566 | |
| 6567 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6568 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6569 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6570 | RTL_W32(tp, TxConfig, RTL_R32(tp, TxConfig) | TXCFG_AUTO_FIFO); |
| 6571 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6572 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6573 | rtl_ephy_init(tp, e_info_8402, ARRAY_SIZE(e_info_8402)); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6574 | |
Heiner Kallweit | 8d98aa3 | 2018-04-16 21:38:27 +0200 | [diff] [blame] | 6575 | rtl_tx_performance_tweak(tp, PCI_EXP_DEVCTL_READRQ_4096B); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6576 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6577 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00000002, ERIAR_EXGMAC); |
| 6578 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00000006, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6579 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 6580 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6581 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6582 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6583 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0e00, 0xff00, ERIAR_EXGMAC); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 6584 | |
| 6585 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6586 | } |
| 6587 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6588 | static void rtl_hw_start_8106(struct rtl8169_private *tp) |
| 6589 | { |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6590 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6591 | RTL_W32(tp, FuncEvent, RTL_R32(tp, FuncEvent) | 0x002800); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6592 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6593 | RTL_W32(tp, MISC, (RTL_R32(tp, MISC) | DISABLE_LAN_EN) & ~EARLY_TALLY_EN); |
| 6594 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) | EN_NDP | EN_OOB_RESET); |
| 6595 | RTL_W8(tp, DLLPR, RTL_R8(tp, DLLPR) & ~PFM_EN); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 6596 | |
| 6597 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6598 | } |
| 6599 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 6600 | static void rtl_hw_start_8101(struct net_device *dev) |
| 6601 | { |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6602 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6603 | struct pci_dev *pdev = tp->pci_dev; |
| 6604 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6605 | if (tp->mac_version >= RTL_GIGA_MAC_VER_30) |
| 6606 | tp->event_slow &= ~RxFIFOOver; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 6607 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6608 | if (tp->mac_version == RTL_GIGA_MAC_VER_13 || |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 6609 | tp->mac_version == RTL_GIGA_MAC_VER_16) |
Bjorn Helgaas | 8200bc7 | 2012-08-22 10:29:42 -0600 | [diff] [blame] | 6610 | pcie_capability_set_word(pdev, PCI_EXP_DEVCTL, |
| 6611 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6612 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6613 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 6614 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6615 | RTL_W8(tp, MaxTxPacketSize, TxPacketMax); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6616 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6617 | rtl_set_rx_max_size(tp, rx_buf_sz); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6618 | |
| 6619 | tp->cp_cmd &= ~R810X_CPCMD_QUIRK_MASK; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6620 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6621 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6622 | rtl_set_rx_tx_desc_registers(tp); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6623 | |
| 6624 | rtl_set_rx_tx_config_registers(tp); |
| 6625 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6626 | switch (tp->mac_version) { |
| 6627 | case RTL_GIGA_MAC_VER_07: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6628 | rtl_hw_start_8102e_1(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6629 | break; |
| 6630 | |
| 6631 | case RTL_GIGA_MAC_VER_08: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6632 | rtl_hw_start_8102e_3(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6633 | break; |
| 6634 | |
| 6635 | case RTL_GIGA_MAC_VER_09: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6636 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6637 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6638 | |
| 6639 | case RTL_GIGA_MAC_VER_29: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6640 | rtl_hw_start_8105e_1(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6641 | break; |
| 6642 | case RTL_GIGA_MAC_VER_30: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6643 | rtl_hw_start_8105e_2(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6644 | break; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6645 | |
| 6646 | case RTL_GIGA_MAC_VER_37: |
| 6647 | rtl_hw_start_8402(tp); |
| 6648 | break; |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6649 | |
| 6650 | case RTL_GIGA_MAC_VER_39: |
| 6651 | rtl_hw_start_8106(tp); |
| 6652 | break; |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 6653 | case RTL_GIGA_MAC_VER_43: |
| 6654 | rtl_hw_start_8168g_2(tp); |
| 6655 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6656 | case RTL_GIGA_MAC_VER_47: |
| 6657 | case RTL_GIGA_MAC_VER_48: |
| 6658 | rtl_hw_start_8168h_1(tp); |
| 6659 | break; |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6660 | } |
| 6661 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6662 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6663 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6664 | RTL_W16(tp, IntrMitigate, 0x0000); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6665 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6666 | RTL_W8(tp, ChipCmd, CmdTxEnb | CmdRxEnb); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6667 | |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6668 | rtl_set_rx_mode(dev); |
| 6669 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6670 | RTL_R8(tp, IntrMask); |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6671 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6672 | RTL_W16(tp, MultiIntr, RTL_R16(tp, MultiIntr) & 0xf000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6673 | } |
| 6674 | |
| 6675 | static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) |
| 6676 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 6677 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6678 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 6679 | if (new_mtu > ETH_DATA_LEN) |
| 6680 | rtl_hw_jumbo_enable(tp); |
| 6681 | else |
| 6682 | rtl_hw_jumbo_disable(tp); |
| 6683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6684 | dev->mtu = new_mtu; |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 6685 | netdev_update_features(dev); |
| 6686 | |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6687 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6688 | } |
| 6689 | |
| 6690 | static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc) |
| 6691 | { |
Al Viro | 95e0918 | 2007-12-22 18:55:39 +0000 | [diff] [blame] | 6692 | desc->addr = cpu_to_le64(0x0badbadbadbadbadull); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6693 | desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask); |
| 6694 | } |
| 6695 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6696 | static void rtl8169_free_rx_databuff(struct rtl8169_private *tp, |
| 6697 | void **data_buff, struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6698 | { |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6699 | dma_unmap_single(tp_to_dev(tp), le64_to_cpu(desc->addr), rx_buf_sz, |
Stanislaw Gruszka | 231aee6 | 2010-10-20 22:25:38 +0000 | [diff] [blame] | 6700 | DMA_FROM_DEVICE); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6701 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6702 | kfree(*data_buff); |
| 6703 | *data_buff = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6704 | rtl8169_make_unusable_by_asic(desc); |
| 6705 | } |
| 6706 | |
| 6707 | static inline void rtl8169_mark_to_asic(struct RxDesc *desc, u32 rx_buf_sz) |
| 6708 | { |
| 6709 | u32 eor = le32_to_cpu(desc->opts1) & RingEnd; |
| 6710 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6711 | /* Force memory writes to complete before releasing descriptor */ |
| 6712 | dma_wmb(); |
| 6713 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6714 | desc->opts1 = cpu_to_le32(DescOwn | eor | rx_buf_sz); |
| 6715 | } |
| 6716 | |
| 6717 | static inline void rtl8169_map_to_asic(struct RxDesc *desc, dma_addr_t mapping, |
| 6718 | u32 rx_buf_sz) |
| 6719 | { |
| 6720 | desc->addr = cpu_to_le64(mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6721 | rtl8169_mark_to_asic(desc, rx_buf_sz); |
| 6722 | } |
| 6723 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6724 | static inline void *rtl8169_align(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6725 | { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6726 | return (void *)ALIGN((long)data, 16); |
| 6727 | } |
| 6728 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6729 | static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp, |
| 6730 | struct RxDesc *desc) |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6731 | { |
| 6732 | void *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6733 | dma_addr_t mapping; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6734 | struct device *d = tp_to_dev(tp); |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6735 | struct net_device *dev = tp->dev; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6736 | int node = dev->dev.parent ? dev_to_node(dev->dev.parent) : -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6737 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6738 | data = kmalloc_node(rx_buf_sz, GFP_KERNEL, node); |
| 6739 | if (!data) |
| 6740 | return NULL; |
Francois Romieu | e9f63f3 | 2007-02-28 23:16:57 +0100 | [diff] [blame] | 6741 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6742 | if (rtl8169_align(data) != data) { |
| 6743 | kfree(data); |
| 6744 | data = kmalloc_node(rx_buf_sz + 15, GFP_KERNEL, node); |
| 6745 | if (!data) |
| 6746 | return NULL; |
| 6747 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6748 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6749 | mapping = dma_map_single(d, rtl8169_align(data), rx_buf_sz, |
Stanislaw Gruszka | 231aee6 | 2010-10-20 22:25:38 +0000 | [diff] [blame] | 6750 | DMA_FROM_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6751 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 6752 | if (net_ratelimit()) |
| 6753 | netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6754 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6755 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6756 | |
| 6757 | rtl8169_map_to_asic(desc, mapping, rx_buf_sz); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6758 | return data; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6759 | |
| 6760 | err_out: |
| 6761 | kfree(data); |
| 6762 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6763 | } |
| 6764 | |
| 6765 | static void rtl8169_rx_clear(struct rtl8169_private *tp) |
| 6766 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 6767 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6768 | |
| 6769 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6770 | if (tp->Rx_databuff[i]) { |
| 6771 | rtl8169_free_rx_databuff(tp, tp->Rx_databuff + i, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6772 | tp->RxDescArray + i); |
| 6773 | } |
| 6774 | } |
| 6775 | } |
| 6776 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6777 | static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6778 | { |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6779 | desc->opts1 |= cpu_to_le32(RingEnd); |
| 6780 | } |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6781 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6782 | static int rtl8169_rx_fill(struct rtl8169_private *tp) |
| 6783 | { |
| 6784 | unsigned int i; |
| 6785 | |
| 6786 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6787 | void *data; |
Francois Romieu | 4ae47c2 | 2007-06-16 23:28:45 +0200 | [diff] [blame] | 6788 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6789 | if (tp->Rx_databuff[i]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6790 | continue; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 6791 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6792 | data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6793 | if (!data) { |
| 6794 | rtl8169_make_unusable_by_asic(tp->RxDescArray + i); |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6795 | goto err_out; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6796 | } |
| 6797 | tp->Rx_databuff[i] = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6798 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6799 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6800 | rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1); |
| 6801 | return 0; |
| 6802 | |
| 6803 | err_out: |
| 6804 | rtl8169_rx_clear(tp); |
| 6805 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6806 | } |
| 6807 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6808 | static int rtl8169_init_ring(struct net_device *dev) |
| 6809 | { |
| 6810 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6811 | |
| 6812 | rtl8169_init_ring_indexes(tp); |
| 6813 | |
| 6814 | memset(tp->tx_skb, 0x0, NUM_TX_DESC * sizeof(struct ring_info)); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6815 | memset(tp->Rx_databuff, 0x0, NUM_RX_DESC * sizeof(void *)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6816 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6817 | return rtl8169_rx_fill(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6818 | } |
| 6819 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6820 | 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] | 6821 | struct TxDesc *desc) |
| 6822 | { |
| 6823 | unsigned int len = tx_skb->len; |
| 6824 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6825 | dma_unmap_single(d, le64_to_cpu(desc->addr), len, DMA_TO_DEVICE); |
| 6826 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6827 | desc->opts1 = 0x00; |
| 6828 | desc->opts2 = 0x00; |
| 6829 | desc->addr = 0x00; |
| 6830 | tx_skb->len = 0; |
| 6831 | } |
| 6832 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6833 | static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, |
| 6834 | unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6835 | { |
| 6836 | unsigned int i; |
| 6837 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6838 | for (i = 0; i < n; i++) { |
| 6839 | unsigned int entry = (start + i) % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6840 | struct ring_info *tx_skb = tp->tx_skb + entry; |
| 6841 | unsigned int len = tx_skb->len; |
| 6842 | |
| 6843 | if (len) { |
| 6844 | struct sk_buff *skb = tx_skb->skb; |
| 6845 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6846 | rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6847 | tp->TxDescArray + entry); |
| 6848 | if (skb) { |
Florian Fainelli | 7a4b813c | 2017-08-24 18:34:44 -0700 | [diff] [blame] | 6849 | dev_consume_skb_any(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6850 | tx_skb->skb = NULL; |
| 6851 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6852 | } |
| 6853 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6854 | } |
| 6855 | |
| 6856 | static void rtl8169_tx_clear(struct rtl8169_private *tp) |
| 6857 | { |
| 6858 | rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6859 | tp->cur_tx = tp->dirty_tx = 0; |
| 6860 | } |
| 6861 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6862 | static void rtl_reset_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6863 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6864 | struct net_device *dev = tp->dev; |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6865 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6866 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6867 | napi_disable(&tp->napi); |
| 6868 | netif_stop_queue(dev); |
| 6869 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6870 | |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 6871 | rtl8169_hw_reset(tp); |
| 6872 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6873 | for (i = 0; i < NUM_RX_DESC; i++) |
| 6874 | rtl8169_mark_to_asic(tp->RxDescArray + i, rx_buf_sz); |
| 6875 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6876 | rtl8169_tx_clear(tp); |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 6877 | rtl8169_init_ring_indexes(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6878 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6879 | napi_enable(&tp->napi); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6880 | rtl_hw_start(dev); |
| 6881 | netif_wake_queue(dev); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 6882 | rtl8169_check_link_status(dev, tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6883 | } |
| 6884 | |
| 6885 | static void rtl8169_tx_timeout(struct net_device *dev) |
| 6886 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6887 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6888 | |
| 6889 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6890 | } |
| 6891 | |
| 6892 | 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] | 6893 | u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6894 | { |
| 6895 | struct skb_shared_info *info = skb_shinfo(skb); |
| 6896 | unsigned int cur_frag, entry; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6897 | struct TxDesc *uninitialized_var(txd); |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 6898 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6899 | |
| 6900 | entry = tp->cur_tx; |
| 6901 | for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6902 | const skb_frag_t *frag = info->frags + cur_frag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6903 | dma_addr_t mapping; |
| 6904 | u32 status, len; |
| 6905 | void *addr; |
| 6906 | |
| 6907 | entry = (entry + 1) % NUM_TX_DESC; |
| 6908 | |
| 6909 | txd = tp->TxDescArray + entry; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6910 | len = skb_frag_size(frag); |
Ian Campbell | 929f618 | 2011-08-31 00:47:06 +0000 | [diff] [blame] | 6911 | addr = skb_frag_address(frag); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6912 | mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6913 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 6914 | if (net_ratelimit()) |
| 6915 | netif_err(tp, drv, tp->dev, |
| 6916 | "Failed to map TX fragments DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6917 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6918 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6919 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6920 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6921 | status = opts[0] | len | |
| 6922 | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6923 | |
| 6924 | txd->opts1 = cpu_to_le32(status); |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6925 | txd->opts2 = cpu_to_le32(opts[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6926 | txd->addr = cpu_to_le64(mapping); |
| 6927 | |
| 6928 | tp->tx_skb[entry].len = len; |
| 6929 | } |
| 6930 | |
| 6931 | if (cur_frag) { |
| 6932 | tp->tx_skb[entry].skb = skb; |
| 6933 | txd->opts1 |= cpu_to_le32(LastFrag); |
| 6934 | } |
| 6935 | |
| 6936 | return cur_frag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6937 | |
| 6938 | err_out: |
| 6939 | rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag); |
| 6940 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6941 | } |
| 6942 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6943 | static bool rtl_test_hw_pad_bug(struct rtl8169_private *tp, struct sk_buff *skb) |
| 6944 | { |
| 6945 | return skb->len < ETH_ZLEN && tp->mac_version == RTL_GIGA_MAC_VER_34; |
| 6946 | } |
| 6947 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6948 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 6949 | struct net_device *dev); |
| 6950 | /* r8169_csum_workaround() |
| 6951 | * The hw limites the value the transport offset. When the offset is out of the |
| 6952 | * range, calculate the checksum by sw. |
| 6953 | */ |
| 6954 | static void r8169_csum_workaround(struct rtl8169_private *tp, |
| 6955 | struct sk_buff *skb) |
| 6956 | { |
| 6957 | if (skb_shinfo(skb)->gso_size) { |
| 6958 | netdev_features_t features = tp->dev->features; |
| 6959 | struct sk_buff *segs, *nskb; |
| 6960 | |
| 6961 | features &= ~(NETIF_F_SG | NETIF_F_IPV6_CSUM | NETIF_F_TSO6); |
| 6962 | segs = skb_gso_segment(skb, features); |
| 6963 | if (IS_ERR(segs) || !segs) |
| 6964 | goto drop; |
| 6965 | |
| 6966 | do { |
| 6967 | nskb = segs; |
| 6968 | segs = segs->next; |
| 6969 | nskb->next = NULL; |
| 6970 | rtl8169_start_xmit(nskb, tp->dev); |
| 6971 | } while (segs); |
| 6972 | |
Alexander Duyck | eb78139 | 2015-05-01 10:34:44 -0700 | [diff] [blame] | 6973 | dev_consume_skb_any(skb); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6974 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 6975 | if (skb_checksum_help(skb) < 0) |
| 6976 | goto drop; |
| 6977 | |
| 6978 | rtl8169_start_xmit(skb, tp->dev); |
| 6979 | } else { |
| 6980 | struct net_device_stats *stats; |
| 6981 | |
| 6982 | drop: |
| 6983 | stats = &tp->dev->stats; |
| 6984 | stats->tx_dropped++; |
Alexander Duyck | eb78139 | 2015-05-01 10:34:44 -0700 | [diff] [blame] | 6985 | dev_kfree_skb_any(skb); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6986 | } |
| 6987 | } |
| 6988 | |
| 6989 | /* msdn_giant_send_check() |
| 6990 | * According to the document of microsoft, the TCP Pseudo Header excludes the |
| 6991 | * packet length for IPv6 TCP large packets. |
| 6992 | */ |
| 6993 | static int msdn_giant_send_check(struct sk_buff *skb) |
| 6994 | { |
| 6995 | const struct ipv6hdr *ipv6h; |
| 6996 | struct tcphdr *th; |
| 6997 | int ret; |
| 6998 | |
| 6999 | ret = skb_cow_head(skb, 0); |
| 7000 | if (ret) |
| 7001 | return ret; |
| 7002 | |
| 7003 | ipv6h = ipv6_hdr(skb); |
| 7004 | th = tcp_hdr(skb); |
| 7005 | |
| 7006 | th->check = 0; |
| 7007 | th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0); |
| 7008 | |
| 7009 | return ret; |
| 7010 | } |
| 7011 | |
| 7012 | static inline __be16 get_protocol(struct sk_buff *skb) |
| 7013 | { |
| 7014 | __be16 protocol; |
| 7015 | |
| 7016 | if (skb->protocol == htons(ETH_P_8021Q)) |
| 7017 | protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto; |
| 7018 | else |
| 7019 | protocol = skb->protocol; |
| 7020 | |
| 7021 | return protocol; |
| 7022 | } |
| 7023 | |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7024 | static bool rtl8169_tso_csum_v1(struct rtl8169_private *tp, |
| 7025 | struct sk_buff *skb, u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7026 | { |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 7027 | u32 mss = skb_shinfo(skb)->gso_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7028 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7029 | if (mss) { |
| 7030 | opts[0] |= TD_LSO; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7031 | opts[0] |= min(mss, TD_MSS_MAX) << TD0_MSS_SHIFT; |
| 7032 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 7033 | const struct iphdr *ip = ip_hdr(skb); |
| 7034 | |
| 7035 | if (ip->protocol == IPPROTO_TCP) |
| 7036 | opts[0] |= TD0_IP_CS | TD0_TCP_CS; |
| 7037 | else if (ip->protocol == IPPROTO_UDP) |
| 7038 | opts[0] |= TD0_IP_CS | TD0_UDP_CS; |
| 7039 | else |
| 7040 | WARN_ON_ONCE(1); |
| 7041 | } |
| 7042 | |
| 7043 | return true; |
| 7044 | } |
| 7045 | |
| 7046 | static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp, |
| 7047 | struct sk_buff *skb, u32 *opts) |
| 7048 | { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 7049 | u32 transport_offset = (u32)skb_transport_offset(skb); |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7050 | u32 mss = skb_shinfo(skb)->gso_size; |
| 7051 | |
| 7052 | if (mss) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7053 | if (transport_offset > GTTCPHO_MAX) { |
| 7054 | netif_warn(tp, tx_err, tp->dev, |
| 7055 | "Invalid transport offset 0x%x for TSO\n", |
| 7056 | transport_offset); |
| 7057 | return false; |
| 7058 | } |
| 7059 | |
| 7060 | switch (get_protocol(skb)) { |
| 7061 | case htons(ETH_P_IP): |
| 7062 | opts[0] |= TD1_GTSENV4; |
| 7063 | break; |
| 7064 | |
| 7065 | case htons(ETH_P_IPV6): |
| 7066 | if (msdn_giant_send_check(skb)) |
| 7067 | return false; |
| 7068 | |
| 7069 | opts[0] |= TD1_GTSENV6; |
| 7070 | break; |
| 7071 | |
| 7072 | default: |
| 7073 | WARN_ON_ONCE(1); |
| 7074 | break; |
| 7075 | } |
| 7076 | |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 7077 | opts[0] |= transport_offset << GTTCPHO_SHIFT; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7078 | opts[1] |= min(mss, TD_MSS_MAX) << TD1_MSS_SHIFT; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7079 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7080 | u8 ip_protocol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7081 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 7082 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
Alexander Duyck | 207c5f4 | 2014-12-03 08:18:04 -0800 | [diff] [blame] | 7083 | return !(skb_checksum_help(skb) || eth_skb_pad(skb)); |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 7084 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7085 | if (transport_offset > TCPHO_MAX) { |
| 7086 | netif_warn(tp, tx_err, tp->dev, |
| 7087 | "Invalid transport offset 0x%x\n", |
| 7088 | transport_offset); |
| 7089 | return false; |
| 7090 | } |
| 7091 | |
| 7092 | switch (get_protocol(skb)) { |
| 7093 | case htons(ETH_P_IP): |
| 7094 | opts[1] |= TD1_IPv4_CS; |
| 7095 | ip_protocol = ip_hdr(skb)->protocol; |
| 7096 | break; |
| 7097 | |
| 7098 | case htons(ETH_P_IPV6): |
| 7099 | opts[1] |= TD1_IPv6_CS; |
| 7100 | ip_protocol = ipv6_hdr(skb)->nexthdr; |
| 7101 | break; |
| 7102 | |
| 7103 | default: |
| 7104 | ip_protocol = IPPROTO_RAW; |
| 7105 | break; |
| 7106 | } |
| 7107 | |
| 7108 | if (ip_protocol == IPPROTO_TCP) |
| 7109 | opts[1] |= TD1_TCP_CS; |
| 7110 | else if (ip_protocol == IPPROTO_UDP) |
| 7111 | opts[1] |= TD1_UDP_CS; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7112 | else |
| 7113 | WARN_ON_ONCE(1); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7114 | |
| 7115 | opts[1] |= transport_offset << TCPHO_SHIFT; |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 7116 | } else { |
| 7117 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
Alexander Duyck | 207c5f4 | 2014-12-03 08:18:04 -0800 | [diff] [blame] | 7118 | return !eth_skb_pad(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7119 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7120 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 7121 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7122 | } |
| 7123 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 7124 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 7125 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7126 | { |
| 7127 | struct rtl8169_private *tp = netdev_priv(dev); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7128 | unsigned int entry = tp->cur_tx % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7129 | struct TxDesc *txd = tp->TxDescArray + entry; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 7130 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7131 | dma_addr_t mapping; |
| 7132 | u32 status, len; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7133 | u32 opts[2]; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7134 | int frags; |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 7135 | |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 7136 | if (unlikely(!TX_FRAGS_READY_FOR(tp, skb_shinfo(skb)->nr_frags))) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 7137 | 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] | 7138 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7139 | } |
| 7140 | |
| 7141 | if (unlikely(le32_to_cpu(txd->opts1) & DescOwn)) |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7142 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7143 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 7144 | opts[1] = cpu_to_le32(rtl8169_tx_vlan_tag(skb)); |
| 7145 | opts[0] = DescOwn; |
| 7146 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7147 | if (!tp->tso_csum(tp, skb, opts)) { |
| 7148 | r8169_csum_workaround(tp, skb); |
| 7149 | return NETDEV_TX_OK; |
| 7150 | } |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 7151 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7152 | len = skb_headlen(skb); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 7153 | mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 7154 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 7155 | if (net_ratelimit()) |
| 7156 | netif_err(tp, drv, dev, "Failed to map TX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7157 | goto err_dma_0; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 7158 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7159 | |
| 7160 | tp->tx_skb[entry].len = len; |
| 7161 | txd->addr = cpu_to_le64(mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7162 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7163 | frags = rtl8169_xmit_frags(tp, skb, opts); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7164 | if (frags < 0) |
| 7165 | goto err_dma_1; |
| 7166 | else if (frags) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7167 | opts[0] |= FirstFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7168 | else { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7169 | opts[0] |= FirstFrag | LastFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7170 | tp->tx_skb[entry].skb = skb; |
| 7171 | } |
| 7172 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7173 | txd->opts2 = cpu_to_le32(opts[1]); |
| 7174 | |
Richard Cochran | 5047fb5 | 2012-03-10 07:29:42 +0000 | [diff] [blame] | 7175 | skb_tx_timestamp(skb); |
| 7176 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 7177 | /* Force memory writes to complete before releasing descriptor */ |
| 7178 | dma_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7179 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7180 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7181 | status = opts[0] | len | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7182 | txd->opts1 = cpu_to_le32(status); |
| 7183 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 7184 | /* Force all memory writes to complete before notifying device */ |
David Dillow | 4c020a9 | 2010-03-03 16:33:10 +0000 | [diff] [blame] | 7185 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7186 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 7187 | tp->cur_tx += frags + 1; |
| 7188 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7189 | RTL_W8(tp, TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7190 | |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 7191 | mmiowb(); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7192 | |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 7193 | if (!TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 7194 | /* Avoid wrongly optimistic queue wake-up: rtl_tx thread must |
| 7195 | * not miss a ring update when it notices a stopped queue. |
| 7196 | */ |
| 7197 | smp_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7198 | netif_stop_queue(dev); |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 7199 | /* Sync with rtl_tx: |
| 7200 | * - publish queue status and cur_tx ring index (write barrier) |
| 7201 | * - refresh dirty_tx ring index (read barrier). |
| 7202 | * May the current thread have a pessimistic view of the ring |
| 7203 | * status and forget to wake up queue, a racing rtl_tx thread |
| 7204 | * can't. |
| 7205 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 7206 | smp_mb(); |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 7207 | if (TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7208 | netif_wake_queue(dev); |
| 7209 | } |
| 7210 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 7211 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7212 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7213 | err_dma_1: |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 7214 | rtl8169_unmap_tx_skb(d, tp->tx_skb + entry, txd); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7215 | err_dma_0: |
Eric W. Biederman | 989c9ba | 2014-03-11 14:16:14 -0700 | [diff] [blame] | 7216 | dev_kfree_skb_any(skb); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7217 | dev->stats.tx_dropped++; |
| 7218 | return NETDEV_TX_OK; |
| 7219 | |
| 7220 | err_stop_0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7221 | netif_stop_queue(dev); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 7222 | dev->stats.tx_dropped++; |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 7223 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7224 | } |
| 7225 | |
| 7226 | static void rtl8169_pcierr_interrupt(struct net_device *dev) |
| 7227 | { |
| 7228 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7229 | struct pci_dev *pdev = tp->pci_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7230 | u16 pci_status, pci_cmd; |
| 7231 | |
| 7232 | pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); |
| 7233 | pci_read_config_word(pdev, PCI_STATUS, &pci_status); |
| 7234 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 7235 | netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n", |
| 7236 | pci_cmd, pci_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7237 | |
| 7238 | /* |
| 7239 | * The recovery sequence below admits a very elaborated explanation: |
| 7240 | * - it seems to work; |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 7241 | * - I did not see what else could be done; |
| 7242 | * - it makes iop3xx happy. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7243 | * |
| 7244 | * Feel free to adjust to your needs. |
| 7245 | */ |
Francois Romieu | a27993f | 2006-12-18 00:04:19 +0100 | [diff] [blame] | 7246 | if (pdev->broken_parity_status) |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 7247 | pci_cmd &= ~PCI_COMMAND_PARITY; |
| 7248 | else |
| 7249 | pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; |
| 7250 | |
| 7251 | pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7252 | |
| 7253 | pci_write_config_word(pdev, PCI_STATUS, |
| 7254 | pci_status & (PCI_STATUS_DETECTED_PARITY | |
| 7255 | PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT | |
| 7256 | PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT)); |
| 7257 | |
| 7258 | /* The infamous DAC f*ckup only happens at boot time */ |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 7259 | if ((tp->cp_cmd & PCIDAC) && !tp->cur_rx) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 7260 | netif_info(tp, intr, dev, "disabling PCI DAC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7261 | tp->cp_cmd &= ~PCIDAC; |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7262 | RTL_W16(tp, CPlusCmd, tp->cp_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7263 | dev->features &= ~NETIF_F_HIGHDMA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7264 | } |
| 7265 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 7266 | rtl8169_hw_reset(tp); |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 7267 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 7268 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7269 | } |
| 7270 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7271 | static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7272 | { |
| 7273 | unsigned int dirty_tx, tx_left; |
| 7274 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7275 | dirty_tx = tp->dirty_tx; |
| 7276 | smp_rmb(); |
| 7277 | tx_left = tp->cur_tx - dirty_tx; |
| 7278 | |
| 7279 | while (tx_left > 0) { |
| 7280 | unsigned int entry = dirty_tx % NUM_TX_DESC; |
| 7281 | struct ring_info *tx_skb = tp->tx_skb + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7282 | u32 status; |
| 7283 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7284 | status = le32_to_cpu(tp->TxDescArray[entry].opts1); |
| 7285 | if (status & DescOwn) |
| 7286 | break; |
| 7287 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 7288 | /* This barrier is needed to keep us from reading |
| 7289 | * any other fields out of the Tx descriptor until |
| 7290 | * we know the status of DescOwn |
| 7291 | */ |
| 7292 | dma_rmb(); |
| 7293 | |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 7294 | rtl8169_unmap_tx_skb(tp_to_dev(tp), tx_skb, |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 7295 | tp->TxDescArray + entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7296 | if (status & LastFrag) { |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 7297 | u64_stats_update_begin(&tp->tx_stats.syncp); |
| 7298 | tp->tx_stats.packets++; |
| 7299 | tp->tx_stats.bytes += tx_skb->skb->len; |
| 7300 | u64_stats_update_end(&tp->tx_stats.syncp); |
Florian Fainelli | 7a4b813c | 2017-08-24 18:34:44 -0700 | [diff] [blame] | 7301 | dev_consume_skb_any(tx_skb->skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7302 | tx_skb->skb = NULL; |
| 7303 | } |
| 7304 | dirty_tx++; |
| 7305 | tx_left--; |
| 7306 | } |
| 7307 | |
| 7308 | if (tp->dirty_tx != dirty_tx) { |
| 7309 | tp->dirty_tx = dirty_tx; |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 7310 | /* Sync with rtl8169_start_xmit: |
| 7311 | * - publish dirty_tx ring index (write barrier) |
| 7312 | * - refresh cur_tx ring index and queue status (read barrier) |
| 7313 | * May the current thread miss the stopped queue condition, |
| 7314 | * a racing xmit thread can only have a right view of the |
| 7315 | * ring status. |
| 7316 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 7317 | smp_mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7318 | if (netif_queue_stopped(dev) && |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 7319 | TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7320 | netif_wake_queue(dev); |
| 7321 | } |
Francois Romieu | d78ae2d | 2007-08-26 20:08:19 +0200 | [diff] [blame] | 7322 | /* |
| 7323 | * 8168 hack: TxPoll requests are lost when the Tx packets are |
| 7324 | * too close. Let's kick an extra TxPoll request when a burst |
| 7325 | * of start_xmit activity is detected (if it is not detected, |
| 7326 | * it is slow enough). -- FR |
| 7327 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7328 | if (tp->cur_tx != dirty_tx) |
| 7329 | RTL_W8(tp, TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7330 | } |
| 7331 | } |
| 7332 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 7333 | static inline int rtl8169_fragmented_frame(u32 status) |
| 7334 | { |
| 7335 | return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag); |
| 7336 | } |
| 7337 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 7338 | static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7339 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7340 | u32 status = opts1 & RxProtoMask; |
| 7341 | |
| 7342 | if (((status == RxProtoTCP) && !(opts1 & TCPFail)) || |
Shan Wei | d5d3ebe | 2010-11-12 00:15:25 +0000 | [diff] [blame] | 7343 | ((status == RxProtoUDP) && !(opts1 & UDPFail))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7344 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 7345 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 7346 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7347 | } |
| 7348 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7349 | static struct sk_buff *rtl8169_try_rx_copy(void *data, |
| 7350 | struct rtl8169_private *tp, |
| 7351 | int pkt_size, |
| 7352 | dma_addr_t addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7353 | { |
Stephen Hemminger | b449655 | 2007-06-17 01:06:49 +0200 | [diff] [blame] | 7354 | struct sk_buff *skb; |
Heiner Kallweit | 1e1205b | 2018-03-20 07:45:42 +0100 | [diff] [blame] | 7355 | struct device *d = tp_to_dev(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7356 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7357 | data = rtl8169_align(data); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 7358 | dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7359 | prefetch(data); |
Alexander Duyck | e2338f8 | 2014-12-09 19:41:09 -0800 | [diff] [blame] | 7360 | skb = napi_alloc_skb(&tp->napi, pkt_size); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7361 | if (skb) |
Heiner Kallweit | 8a67aa8 | 2018-04-17 23:19:07 +0200 | [diff] [blame^] | 7362 | skb_copy_to_linear_data(skb, data, pkt_size); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 7363 | dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE); |
| 7364 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7365 | return skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7366 | } |
| 7367 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7368 | 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] | 7369 | { |
| 7370 | unsigned int cur_rx, rx_left; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7371 | unsigned int count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7373 | cur_rx = tp->cur_rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7374 | |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 7375 | 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] | 7376 | unsigned int entry = cur_rx % NUM_RX_DESC; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 7377 | struct RxDesc *desc = tp->RxDescArray + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7378 | u32 status; |
| 7379 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 7380 | status = le32_to_cpu(desc->opts1) & tp->opts1_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7381 | if (status & DescOwn) |
| 7382 | break; |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 7383 | |
| 7384 | /* This barrier is needed to keep us from reading |
| 7385 | * any other fields out of the Rx descriptor until |
| 7386 | * we know the status of DescOwn |
| 7387 | */ |
| 7388 | dma_rmb(); |
| 7389 | |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 7390 | if (unlikely(status & RxRES)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 7391 | netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n", |
| 7392 | status); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 7393 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7394 | if (status & (RxRWT | RxRUNT)) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 7395 | dev->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7396 | if (status & RxCRC) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 7397 | dev->stats.rx_crc_errors++; |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 7398 | if (status & RxFOVF) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7399 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 7400 | dev->stats.rx_fifo_errors++; |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 7401 | } |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 7402 | if ((status & (RxRUNT | RxCRC)) && |
| 7403 | !(status & (RxRWT | RxFOVF)) && |
| 7404 | (dev->features & NETIF_F_RXALL)) |
| 7405 | goto process_pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7406 | } else { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7407 | struct sk_buff *skb; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 7408 | dma_addr_t addr; |
| 7409 | int pkt_size; |
| 7410 | |
| 7411 | process_pkt: |
| 7412 | addr = le64_to_cpu(desc->addr); |
Ben Greear | 79d0c1d | 2012-02-10 15:04:34 +0000 | [diff] [blame] | 7413 | if (likely(!(dev->features & NETIF_F_RXFCS))) |
| 7414 | pkt_size = (status & 0x00003fff) - 4; |
| 7415 | else |
| 7416 | pkt_size = status & 0x00003fff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7417 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 7418 | /* |
| 7419 | * The driver does not support incoming fragmented |
| 7420 | * frames. They are seen as a symptom of over-mtu |
| 7421 | * sized frames. |
| 7422 | */ |
| 7423 | if (unlikely(rtl8169_fragmented_frame(status))) { |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 7424 | dev->stats.rx_dropped++; |
| 7425 | dev->stats.rx_length_errors++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 7426 | goto release_descriptor; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 7427 | } |
| 7428 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7429 | skb = rtl8169_try_rx_copy(tp->Rx_databuff[entry], |
| 7430 | tp, pkt_size, addr); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7431 | if (!skb) { |
| 7432 | dev->stats.rx_dropped++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 7433 | goto release_descriptor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7434 | } |
| 7435 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 7436 | rtl8169_rx_csum(skb, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7437 | skb_put(skb, pkt_size); |
| 7438 | skb->protocol = eth_type_trans(skb, dev); |
| 7439 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 7440 | rtl8169_rx_vlan_tag(desc, skb); |
| 7441 | |
françois romieu | 3917429 | 2015-11-11 23:35:18 +0100 | [diff] [blame] | 7442 | if (skb->pkt_type == PACKET_MULTICAST) |
| 7443 | dev->stats.multicast++; |
| 7444 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 7445 | napi_gro_receive(&tp->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7446 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7447 | u64_stats_update_begin(&tp->rx_stats.syncp); |
| 7448 | tp->rx_stats.packets++; |
| 7449 | tp->rx_stats.bytes += pkt_size; |
| 7450 | u64_stats_update_end(&tp->rx_stats.syncp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7451 | } |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 7452 | release_descriptor: |
| 7453 | desc->opts2 = 0; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 7454 | rtl8169_mark_to_asic(desc, rx_buf_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7455 | } |
| 7456 | |
| 7457 | count = cur_rx - tp->cur_rx; |
| 7458 | tp->cur_rx = cur_rx; |
| 7459 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7460 | return count; |
| 7461 | } |
| 7462 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 7463 | static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7464 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 7465 | struct net_device *dev = dev_instance; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7466 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7467 | int handled = 0; |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 7468 | u16 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7469 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 7470 | status = rtl_get_events(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7471 | if (status && status != 0xffff) { |
| 7472 | status &= RTL_EVENT_NAPI | tp->event_slow; |
| 7473 | if (status) { |
| 7474 | handled = 1; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 7475 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7476 | rtl_irq_disable(tp); |
| 7477 | napi_schedule(&tp->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7478 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7479 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7480 | return IRQ_RETVAL(handled); |
| 7481 | } |
| 7482 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7483 | /* |
| 7484 | * Workqueue context. |
| 7485 | */ |
| 7486 | static void rtl_slow_event_work(struct rtl8169_private *tp) |
| 7487 | { |
| 7488 | struct net_device *dev = tp->dev; |
| 7489 | u16 status; |
| 7490 | |
| 7491 | status = rtl_get_events(tp) & tp->event_slow; |
| 7492 | rtl_ack_events(tp, status); |
| 7493 | |
| 7494 | if (unlikely(status & RxFIFOOver)) { |
| 7495 | switch (tp->mac_version) { |
| 7496 | /* Work around for rx fifo overflow */ |
| 7497 | case RTL_GIGA_MAC_VER_11: |
| 7498 | netif_stop_queue(dev); |
Francois Romieu | 934714d | 2012-01-31 11:09:21 +0100 | [diff] [blame] | 7499 | /* XXX - Hack alert. See rtl_task(). */ |
| 7500 | set_bit(RTL_FLAG_TASK_RESET_PENDING, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7501 | default: |
| 7502 | break; |
| 7503 | } |
| 7504 | } |
| 7505 | |
| 7506 | if (unlikely(status & SYSErr)) |
| 7507 | rtl8169_pcierr_interrupt(dev); |
| 7508 | |
| 7509 | if (status & LinkChg) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7510 | rtl8169_check_link_status(dev, tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7511 | |
françois romieu | 7dbb491 | 2012-06-09 10:53:16 +0000 | [diff] [blame] | 7512 | rtl_irq_enable_all(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7513 | } |
| 7514 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 7515 | static void rtl_task(struct work_struct *work) |
| 7516 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7517 | static const struct { |
| 7518 | int bitnr; |
| 7519 | void (*action)(struct rtl8169_private *); |
| 7520 | } rtl_work[] = { |
Francois Romieu | 934714d | 2012-01-31 11:09:21 +0100 | [diff] [blame] | 7521 | /* XXX - keep rtl_slow_event_work() as first element. */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7522 | { RTL_FLAG_TASK_SLOW_PENDING, rtl_slow_event_work }, |
| 7523 | { RTL_FLAG_TASK_RESET_PENDING, rtl_reset_work }, |
| 7524 | { RTL_FLAG_TASK_PHY_PENDING, rtl_phy_work } |
| 7525 | }; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 7526 | struct rtl8169_private *tp = |
| 7527 | container_of(work, struct rtl8169_private, wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7528 | struct net_device *dev = tp->dev; |
| 7529 | int i; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 7530 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7531 | rtl_lock_work(tp); |
| 7532 | |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7533 | if (!netif_running(dev) || |
| 7534 | !test_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7535 | goto out_unlock; |
| 7536 | |
| 7537 | for (i = 0; i < ARRAY_SIZE(rtl_work); i++) { |
| 7538 | bool pending; |
| 7539 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7540 | pending = test_and_clear_bit(rtl_work[i].bitnr, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7541 | if (pending) |
| 7542 | rtl_work[i].action(tp); |
| 7543 | } |
| 7544 | |
| 7545 | out_unlock: |
| 7546 | rtl_unlock_work(tp); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 7547 | } |
| 7548 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7549 | static int rtl8169_poll(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7550 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7551 | struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); |
| 7552 | struct net_device *dev = tp->dev; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7553 | u16 enable_mask = RTL_EVENT_NAPI | tp->event_slow; |
| 7554 | int work_done= 0; |
| 7555 | u16 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7556 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7557 | status = rtl_get_events(tp); |
| 7558 | rtl_ack_events(tp, status & ~tp->event_slow); |
| 7559 | |
| 7560 | if (status & RTL_EVENT_NAPI_RX) |
| 7561 | work_done = rtl_rx(dev, tp, (u32) budget); |
| 7562 | |
| 7563 | if (status & RTL_EVENT_NAPI_TX) |
| 7564 | rtl_tx(dev, tp); |
| 7565 | |
| 7566 | if (status & tp->event_slow) { |
| 7567 | enable_mask &= ~tp->event_slow; |
| 7568 | |
| 7569 | rtl_schedule_task(tp, RTL_FLAG_TASK_SLOW_PENDING); |
| 7570 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7571 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7572 | if (work_done < budget) { |
Eric Dumazet | 6ad2016 | 2017-01-30 08:22:01 -0800 | [diff] [blame] | 7573 | napi_complete_done(napi, work_done); |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 7574 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7575 | rtl_irq_enable(tp, enable_mask); |
| 7576 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7577 | } |
| 7578 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7579 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7580 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7581 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7582 | static void rtl8169_rx_missed(struct net_device *dev) |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 7583 | { |
| 7584 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7585 | |
| 7586 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) |
| 7587 | return; |
| 7588 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7589 | dev->stats.rx_missed_errors += RTL_R32(tp, RxMissed) & 0xffffff; |
| 7590 | RTL_W32(tp, RxMissed, 0); |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 7591 | } |
| 7592 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7593 | static void rtl8169_down(struct net_device *dev) |
| 7594 | { |
| 7595 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7596 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 7597 | del_timer_sync(&tp->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7598 | |
Stephen Hemminger | 93dd79e | 2007-10-28 17:14:06 +0100 | [diff] [blame] | 7599 | napi_disable(&tp->napi); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7600 | netif_stop_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7601 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 7602 | rtl8169_hw_reset(tp); |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 7603 | /* |
| 7604 | * At this point device interrupts can not be enabled in any function, |
Francois Romieu | 209e5ac | 2012-01-26 09:59:50 +0100 | [diff] [blame] | 7605 | * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task) |
| 7606 | * and napi is disabled (rtl8169_poll). |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 7607 | */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7608 | rtl8169_rx_missed(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7609 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7610 | /* Give a racing hard_start_xmit a few cycles to complete. */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7611 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7613 | rtl8169_tx_clear(tp); |
| 7614 | |
| 7615 | rtl8169_rx_clear(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7616 | |
| 7617 | rtl_pll_power_down(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7618 | } |
| 7619 | |
| 7620 | static int rtl8169_close(struct net_device *dev) |
| 7621 | { |
| 7622 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7623 | struct pci_dev *pdev = tp->pci_dev; |
| 7624 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7625 | pm_runtime_get_sync(&pdev->dev); |
| 7626 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7627 | /* Update counters before going down */ |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 7628 | rtl8169_update_counters(dev); |
| 7629 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7630 | rtl_lock_work(tp); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7631 | clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7632 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7633 | rtl8169_down(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7634 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7635 | |
Lekensteyn | 4ea7244 | 2013-07-22 09:53:30 +0200 | [diff] [blame] | 7636 | cancel_work_sync(&tp->wk.work); |
| 7637 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7638 | pci_free_irq(pdev, 0, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7639 | |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 7640 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 7641 | tp->RxPhyAddr); |
| 7642 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 7643 | tp->TxPhyAddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7644 | tp->TxDescArray = NULL; |
| 7645 | tp->RxDescArray = NULL; |
| 7646 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7647 | pm_runtime_put_sync(&pdev->dev); |
| 7648 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7649 | return 0; |
| 7650 | } |
| 7651 | |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 7652 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7653 | static void rtl8169_netpoll(struct net_device *dev) |
| 7654 | { |
| 7655 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7656 | |
Heiner Kallweit | 2927499 | 2018-02-28 20:43:38 +0100 | [diff] [blame] | 7657 | rtl8169_interrupt(pci_irq_vector(tp->pci_dev, 0), dev); |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 7658 | } |
| 7659 | #endif |
| 7660 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7661 | static int rtl_open(struct net_device *dev) |
| 7662 | { |
| 7663 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7664 | struct pci_dev *pdev = tp->pci_dev; |
| 7665 | int retval = -ENOMEM; |
| 7666 | |
| 7667 | pm_runtime_get_sync(&pdev->dev); |
| 7668 | |
| 7669 | /* |
Jiri Kosina | e75d660 | 2012-04-08 21:48:52 +0200 | [diff] [blame] | 7670 | * Rx and Tx descriptors needs 256 bytes alignment. |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7671 | * dma_alloc_coherent provides more. |
| 7672 | */ |
| 7673 | tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES, |
| 7674 | &tp->TxPhyAddr, GFP_KERNEL); |
| 7675 | if (!tp->TxDescArray) |
| 7676 | goto err_pm_runtime_put; |
| 7677 | |
| 7678 | tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, |
| 7679 | &tp->RxPhyAddr, GFP_KERNEL); |
| 7680 | if (!tp->RxDescArray) |
| 7681 | goto err_free_tx_0; |
| 7682 | |
| 7683 | retval = rtl8169_init_ring(dev); |
| 7684 | if (retval < 0) |
| 7685 | goto err_free_rx_1; |
| 7686 | |
| 7687 | INIT_WORK(&tp->wk.work, rtl_task); |
| 7688 | |
| 7689 | smp_mb(); |
| 7690 | |
| 7691 | rtl_request_firmware(tp); |
| 7692 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 7693 | retval = pci_request_irq(pdev, 0, rtl8169_interrupt, NULL, dev, |
| 7694 | dev->name); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7695 | if (retval < 0) |
| 7696 | goto err_release_fw_2; |
| 7697 | |
| 7698 | rtl_lock_work(tp); |
| 7699 | |
| 7700 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
| 7701 | |
| 7702 | napi_enable(&tp->napi); |
| 7703 | |
| 7704 | rtl8169_init_phy(dev, tp); |
| 7705 | |
| 7706 | __rtl8169_set_features(dev, dev->features); |
| 7707 | |
| 7708 | rtl_pll_power_up(tp); |
| 7709 | |
| 7710 | rtl_hw_start(dev); |
| 7711 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7712 | if (!rtl8169_init_counter_offsets(dev)) |
| 7713 | netif_warn(tp, hw, dev, "counter reset/update failed\n"); |
| 7714 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7715 | netif_start_queue(dev); |
| 7716 | |
| 7717 | rtl_unlock_work(tp); |
| 7718 | |
| 7719 | tp->saved_wolopts = 0; |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7720 | pm_runtime_put_sync(&pdev->dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7721 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7722 | rtl8169_check_link_status(dev, tp); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7723 | out: |
| 7724 | return retval; |
| 7725 | |
| 7726 | err_release_fw_2: |
| 7727 | rtl_release_firmware(tp); |
| 7728 | rtl8169_rx_clear(tp); |
| 7729 | err_free_rx_1: |
| 7730 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 7731 | tp->RxPhyAddr); |
| 7732 | tp->RxDescArray = NULL; |
| 7733 | err_free_tx_0: |
| 7734 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 7735 | tp->TxPhyAddr); |
| 7736 | tp->TxDescArray = NULL; |
| 7737 | err_pm_runtime_put: |
| 7738 | pm_runtime_put_noidle(&pdev->dev); |
| 7739 | goto out; |
| 7740 | } |
| 7741 | |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 7742 | static void |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7743 | rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7744 | { |
| 7745 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7746 | struct pci_dev *pdev = tp->pci_dev; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7747 | struct rtl8169_counters *counters = tp->counters; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7748 | unsigned int start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7749 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7750 | pm_runtime_get_noresume(&pdev->dev); |
| 7751 | |
| 7752 | if (netif_running(dev) && pm_runtime_active(&pdev->dev)) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7753 | rtl8169_rx_missed(dev); |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 7754 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7755 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7756 | start = u64_stats_fetch_begin_irq(&tp->rx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7757 | stats->rx_packets = tp->rx_stats.packets; |
| 7758 | stats->rx_bytes = tp->rx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7759 | } while (u64_stats_fetch_retry_irq(&tp->rx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7760 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7761 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7762 | start = u64_stats_fetch_begin_irq(&tp->tx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7763 | stats->tx_packets = tp->tx_stats.packets; |
| 7764 | stats->tx_bytes = tp->tx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7765 | } while (u64_stats_fetch_retry_irq(&tp->tx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7766 | |
| 7767 | stats->rx_dropped = dev->stats.rx_dropped; |
| 7768 | stats->tx_dropped = dev->stats.tx_dropped; |
| 7769 | stats->rx_length_errors = dev->stats.rx_length_errors; |
| 7770 | stats->rx_errors = dev->stats.rx_errors; |
| 7771 | stats->rx_crc_errors = dev->stats.rx_crc_errors; |
| 7772 | stats->rx_fifo_errors = dev->stats.rx_fifo_errors; |
| 7773 | stats->rx_missed_errors = dev->stats.rx_missed_errors; |
Corinna Vinschen | d7d2d89 | 2015-08-27 17:11:48 +0200 | [diff] [blame] | 7774 | stats->multicast = dev->stats.multicast; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7775 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7776 | /* |
| 7777 | * Fetch additonal counter values missing in stats collected by driver |
| 7778 | * from tally counters. |
| 7779 | */ |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7780 | if (pm_runtime_active(&pdev->dev)) |
| 7781 | rtl8169_update_counters(dev); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7782 | |
| 7783 | /* |
| 7784 | * Subtract values fetched during initalization. |
| 7785 | * See rtl8169_init_counter_offsets for a description why we do that. |
| 7786 | */ |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7787 | stats->tx_errors = le64_to_cpu(counters->tx_errors) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7788 | le64_to_cpu(tp->tc_offset.tx_errors); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7789 | stats->collisions = le32_to_cpu(counters->tx_multi_collision) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7790 | le32_to_cpu(tp->tc_offset.tx_multi_collision); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7791 | stats->tx_aborted_errors = le16_to_cpu(counters->tx_aborted) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7792 | le16_to_cpu(tp->tc_offset.tx_aborted); |
| 7793 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7794 | pm_runtime_put_noidle(&pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7795 | } |
| 7796 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7797 | static void rtl8169_net_suspend(struct net_device *dev) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7798 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7799 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7800 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7801 | if (!netif_running(dev)) |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7802 | return; |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7803 | |
| 7804 | netif_device_detach(dev); |
| 7805 | netif_stop_queue(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7806 | |
| 7807 | rtl_lock_work(tp); |
| 7808 | napi_disable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7809 | clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7810 | rtl_unlock_work(tp); |
| 7811 | |
| 7812 | rtl_pll_power_down(tp); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7813 | } |
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 | #ifdef CONFIG_PM |
| 7816 | |
| 7817 | static int rtl8169_suspend(struct device *device) |
| 7818 | { |
| 7819 | struct pci_dev *pdev = to_pci_dev(device); |
| 7820 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7821 | |
| 7822 | rtl8169_net_suspend(dev); |
Francois Romieu | 1371fa6 | 2007-04-02 23:01:11 +0200 | [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 void __rtl8169_resume(struct net_device *dev) |
| 7828 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7829 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7830 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7831 | netif_device_attach(dev); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7832 | |
| 7833 | rtl_pll_power_up(tp); |
| 7834 | |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 7835 | rtl_lock_work(tp); |
| 7836 | napi_enable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7837 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 7838 | rtl_unlock_work(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7839 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 7840 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7841 | } |
| 7842 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7843 | static int rtl8169_resume(struct device *device) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7844 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7845 | struct pci_dev *pdev = to_pci_dev(device); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7846 | struct net_device *dev = pci_get_drvdata(pdev); |
Stanislaw Gruszka | fccec10 | 2010-10-20 22:25:42 +0000 | [diff] [blame] | 7847 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7848 | |
| 7849 | rtl8169_init_phy(dev, tp); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7850 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7851 | if (netif_running(dev)) |
| 7852 | __rtl8169_resume(dev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7853 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7854 | return 0; |
| 7855 | } |
| 7856 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7857 | static int rtl8169_runtime_suspend(struct device *device) |
| 7858 | { |
| 7859 | struct pci_dev *pdev = to_pci_dev(device); |
| 7860 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7861 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7862 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7863 | if (!tp->TxDescArray) { |
| 7864 | rtl_pll_power_down(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7865 | return 0; |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7866 | } |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7867 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7868 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7869 | tp->saved_wolopts = __rtl8169_get_wol(tp); |
| 7870 | __rtl8169_set_wol(tp, WAKE_ANY); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7871 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7872 | |
| 7873 | rtl8169_net_suspend(dev); |
| 7874 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7875 | /* Update counters before going runtime suspend */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7876 | rtl8169_rx_missed(dev); |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7877 | rtl8169_update_counters(dev); |
| 7878 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7879 | return 0; |
| 7880 | } |
| 7881 | |
| 7882 | static int rtl8169_runtime_resume(struct device *device) |
| 7883 | { |
| 7884 | struct pci_dev *pdev = to_pci_dev(device); |
| 7885 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7886 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 7887 | rtl_rar_set(tp, dev->dev_addr); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7888 | |
| 7889 | if (!tp->TxDescArray) |
| 7890 | return 0; |
| 7891 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7892 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7893 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
| 7894 | tp->saved_wolopts = 0; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7895 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7896 | |
Stanislaw Gruszka | fccec10 | 2010-10-20 22:25:42 +0000 | [diff] [blame] | 7897 | rtl8169_init_phy(dev, tp); |
| 7898 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7899 | __rtl8169_resume(dev); |
| 7900 | |
| 7901 | return 0; |
| 7902 | } |
| 7903 | |
| 7904 | static int rtl8169_runtime_idle(struct device *device) |
| 7905 | { |
| 7906 | struct pci_dev *pdev = to_pci_dev(device); |
| 7907 | struct net_device *dev = pci_get_drvdata(pdev); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7908 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7909 | if (!netif_running(dev) || !netif_carrier_ok(dev)) |
| 7910 | pm_schedule_suspend(device, 10000); |
| 7911 | |
| 7912 | return -EBUSY; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7913 | } |
| 7914 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 7915 | static const struct dev_pm_ops rtl8169_pm_ops = { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7916 | .suspend = rtl8169_suspend, |
| 7917 | .resume = rtl8169_resume, |
| 7918 | .freeze = rtl8169_suspend, |
| 7919 | .thaw = rtl8169_resume, |
| 7920 | .poweroff = rtl8169_suspend, |
| 7921 | .restore = rtl8169_resume, |
| 7922 | .runtime_suspend = rtl8169_runtime_suspend, |
| 7923 | .runtime_resume = rtl8169_runtime_resume, |
| 7924 | .runtime_idle = rtl8169_runtime_idle, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7925 | }; |
| 7926 | |
| 7927 | #define RTL8169_PM_OPS (&rtl8169_pm_ops) |
| 7928 | |
| 7929 | #else /* !CONFIG_PM */ |
| 7930 | |
| 7931 | #define RTL8169_PM_OPS NULL |
| 7932 | |
| 7933 | #endif /* !CONFIG_PM */ |
| 7934 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7935 | static void rtl_wol_shutdown_quirk(struct rtl8169_private *tp) |
| 7936 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7937 | /* WoL fails with 8168b when the receiver is disabled. */ |
| 7938 | switch (tp->mac_version) { |
| 7939 | case RTL_GIGA_MAC_VER_11: |
| 7940 | case RTL_GIGA_MAC_VER_12: |
| 7941 | case RTL_GIGA_MAC_VER_17: |
| 7942 | pci_clear_master(tp->pci_dev); |
| 7943 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7944 | RTL_W8(tp, ChipCmd, CmdRxEnb); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7945 | /* PCI commit */ |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 7946 | RTL_R8(tp, ChipCmd); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7947 | break; |
| 7948 | default: |
| 7949 | break; |
| 7950 | } |
| 7951 | } |
| 7952 | |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 7953 | static void rtl_shutdown(struct pci_dev *pdev) |
| 7954 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7955 | struct net_device *dev = pci_get_drvdata(pdev); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 7956 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 7957 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7958 | rtl8169_net_suspend(dev); |
| 7959 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7960 | /* Restore original MAC address */ |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 7961 | rtl_rar_set(tp, dev->perm_addr); |
| 7962 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 7963 | rtl8169_hw_reset(tp); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 7964 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7965 | if (system_state == SYSTEM_POWER_OFF) { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7966 | if (__rtl8169_get_wol(tp) & WAKE_ANY) { |
| 7967 | rtl_wol_suspend_quirk(tp); |
| 7968 | rtl_wol_shutdown_quirk(tp); |
françois romieu | ca52efd | 2009-07-24 12:34:19 +0000 | [diff] [blame] | 7969 | } |
| 7970 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7971 | pci_wake_from_d3(pdev, true); |
| 7972 | pci_set_power_state(pdev, PCI_D3hot); |
| 7973 | } |
| 7974 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7975 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7976 | static void rtl_remove_one(struct pci_dev *pdev) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7977 | { |
| 7978 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7979 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7980 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 7981 | if (r8168_check_dash(tp)) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7982 | rtl8168_driver_stop(tp); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7983 | |
Devendra Naga | ad1be8d | 2012-05-31 01:51:20 +0000 | [diff] [blame] | 7984 | netif_napi_del(&tp->napi); |
| 7985 | |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7986 | unregister_netdev(dev); |
| 7987 | |
| 7988 | rtl_release_firmware(tp); |
| 7989 | |
| 7990 | if (pci_dev_run_wake(pdev)) |
| 7991 | pm_runtime_get_noresume(&pdev->dev); |
| 7992 | |
| 7993 | /* restore original MAC address */ |
| 7994 | rtl_rar_set(tp, dev->perm_addr); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7995 | } |
| 7996 | |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 7997 | static const struct net_device_ops rtl_netdev_ops = { |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7998 | .ndo_open = rtl_open, |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 7999 | .ndo_stop = rtl8169_close, |
| 8000 | .ndo_get_stats64 = rtl8169_get_stats64, |
| 8001 | .ndo_start_xmit = rtl8169_start_xmit, |
| 8002 | .ndo_tx_timeout = rtl8169_tx_timeout, |
| 8003 | .ndo_validate_addr = eth_validate_addr, |
| 8004 | .ndo_change_mtu = rtl8169_change_mtu, |
| 8005 | .ndo_fix_features = rtl8169_fix_features, |
| 8006 | .ndo_set_features = rtl8169_set_features, |
| 8007 | .ndo_set_mac_address = rtl_set_mac_address, |
| 8008 | .ndo_do_ioctl = rtl8169_ioctl, |
| 8009 | .ndo_set_rx_mode = rtl_set_rx_mode, |
| 8010 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 8011 | .ndo_poll_controller = rtl8169_netpoll, |
| 8012 | #endif |
| 8013 | |
| 8014 | }; |
| 8015 | |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8016 | static const struct rtl_cfg_info { |
| 8017 | void (*hw_start)(struct net_device *); |
| 8018 | unsigned int region; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8019 | u16 event_slow; |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 8020 | unsigned int has_gmii:1; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 8021 | const struct rtl_coalesce_info *coalesce_info; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8022 | u8 default_ver; |
| 8023 | } rtl_cfg_infos [] = { |
| 8024 | [RTL_CFG_0] = { |
| 8025 | .hw_start = rtl_hw_start_8169, |
| 8026 | .region = 1, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8027 | .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver, |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 8028 | .has_gmii = 1, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 8029 | .coalesce_info = rtl_coalesce_info_8169, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8030 | .default_ver = RTL_GIGA_MAC_VER_01, |
| 8031 | }, |
| 8032 | [RTL_CFG_1] = { |
| 8033 | .hw_start = rtl_hw_start_8168, |
| 8034 | .region = 2, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8035 | .event_slow = SYSErr | LinkChg | RxOverflow, |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 8036 | .has_gmii = 1, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 8037 | .coalesce_info = rtl_coalesce_info_8168_8136, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8038 | .default_ver = RTL_GIGA_MAC_VER_11, |
| 8039 | }, |
| 8040 | [RTL_CFG_2] = { |
| 8041 | .hw_start = rtl_hw_start_8101, |
| 8042 | .region = 2, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8043 | .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver | |
| 8044 | PCSTimeout, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 8045 | .coalesce_info = rtl_coalesce_info_8168_8136, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8046 | .default_ver = RTL_GIGA_MAC_VER_13, |
| 8047 | } |
| 8048 | }; |
| 8049 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 8050 | static int rtl_alloc_irq(struct rtl8169_private *tp) |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8051 | { |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 8052 | unsigned int flags; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8053 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 8054 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 8055 | RTL_W8(tp, Cfg9346, Cfg9346_Unlock); |
| 8056 | RTL_W8(tp, Config2, RTL_R8(tp, Config2) & ~MSIEnable); |
| 8057 | RTL_W8(tp, Cfg9346, Cfg9346_Lock); |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 8058 | flags = PCI_IRQ_LEGACY; |
| 8059 | } else { |
| 8060 | flags = PCI_IRQ_ALL_TYPES; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8061 | } |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 8062 | |
| 8063 | return pci_alloc_irq_vectors(tp->pci_dev, 1, 1, flags); |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8064 | } |
| 8065 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8066 | DECLARE_RTL_COND(rtl_link_list_ready_cond) |
| 8067 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 8068 | return RTL_R8(tp, MCU) & LINK_LIST_RDY; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8069 | } |
| 8070 | |
| 8071 | DECLARE_RTL_COND(rtl_rxtx_empty_cond) |
| 8072 | { |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 8073 | return (RTL_R8(tp, MCU) & RXTX_EMPTY) == RXTX_EMPTY; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8074 | } |
| 8075 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 8076 | static void rtl_hw_init_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8077 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8078 | u32 data; |
| 8079 | |
| 8080 | tp->ocp_base = OCP_STD_PHY_BASE; |
| 8081 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 8082 | RTL_W32(tp, MISC, RTL_R32(tp, MISC) | RXDV_GATED_EN); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8083 | |
| 8084 | if (!rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 42)) |
| 8085 | return; |
| 8086 | |
| 8087 | if (!rtl_udelay_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42)) |
| 8088 | return; |
| 8089 | |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 8090 | RTL_W8(tp, ChipCmd, RTL_R8(tp, ChipCmd) & ~(CmdTxEnb | CmdRxEnb)); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8091 | msleep(1); |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 8092 | RTL_W8(tp, MCU, RTL_R8(tp, MCU) & ~NOW_IS_OOB); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8093 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 8094 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8095 | data &= ~(1 << 14); |
| 8096 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 8097 | |
| 8098 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 8099 | return; |
| 8100 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 8101 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8102 | data |= (1 << 15); |
| 8103 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 8104 | |
| 8105 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 8106 | return; |
| 8107 | } |
| 8108 | |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 8109 | static void rtl_hw_init_8168ep(struct rtl8169_private *tp) |
| 8110 | { |
| 8111 | rtl8168ep_stop_cmac(tp); |
| 8112 | rtl_hw_init_8168g(tp); |
| 8113 | } |
| 8114 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 8115 | static void rtl_hw_initialize(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8116 | { |
| 8117 | switch (tp->mac_version) { |
| 8118 | case RTL_GIGA_MAC_VER_40: |
| 8119 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 8120 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 8121 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 8122 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 8123 | case RTL_GIGA_MAC_VER_45: |
| 8124 | case RTL_GIGA_MAC_VER_46: |
| 8125 | case RTL_GIGA_MAC_VER_47: |
| 8126 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 8127 | rtl_hw_init_8168g(tp); |
| 8128 | break; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 8129 | case RTL_GIGA_MAC_VER_49: |
| 8130 | case RTL_GIGA_MAC_VER_50: |
| 8131 | case RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 8132 | rtl_hw_init_8168ep(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8133 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8134 | default: |
| 8135 | break; |
| 8136 | } |
| 8137 | } |
| 8138 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 8139 | 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] | 8140 | { |
| 8141 | const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data; |
| 8142 | const unsigned int region = cfg->region; |
| 8143 | struct rtl8169_private *tp; |
| 8144 | struct mii_if_info *mii; |
| 8145 | struct net_device *dev; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8146 | int chipset, i; |
| 8147 | int rc; |
| 8148 | |
| 8149 | if (netif_msg_drv(&debug)) { |
| 8150 | printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n", |
| 8151 | MODULENAME, RTL8169_VERSION); |
| 8152 | } |
| 8153 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8154 | dev = devm_alloc_etherdev(&pdev->dev, sizeof (*tp)); |
| 8155 | if (!dev) |
| 8156 | return -ENOMEM; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8157 | |
| 8158 | SET_NETDEV_DEV(dev, &pdev->dev); |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 8159 | dev->netdev_ops = &rtl_netdev_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8160 | tp = netdev_priv(dev); |
| 8161 | tp->dev = dev; |
| 8162 | tp->pci_dev = pdev; |
| 8163 | tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT); |
| 8164 | |
| 8165 | mii = &tp->mii; |
| 8166 | mii->dev = dev; |
| 8167 | mii->mdio_read = rtl_mdio_read; |
| 8168 | mii->mdio_write = rtl_mdio_write; |
| 8169 | mii->phy_id_mask = 0x1f; |
| 8170 | mii->reg_num_mask = 0x1f; |
Heiner Kallweit | 14967f9 | 2018-02-28 07:55:20 +0100 | [diff] [blame] | 8171 | mii->supports_gmii = cfg->has_gmii; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8172 | |
| 8173 | /* disable ASPM completely as that cause random device stop working |
| 8174 | * problems as well as full system hangs for some PCIe devices users */ |
| 8175 | pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 | |
| 8176 | PCIE_LINK_STATE_CLKPM); |
| 8177 | |
| 8178 | /* enable device (incl. PCI PM wakeup and hotplug setup) */ |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8179 | rc = pcim_enable_device(pdev); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8180 | if (rc < 0) { |
| 8181 | netif_err(tp, probe, dev, "enable failure\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8182 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8183 | } |
| 8184 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8185 | if (pcim_set_mwi(pdev) < 0) |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8186 | netif_info(tp, probe, dev, "Mem-Wr-Inval unavailable\n"); |
| 8187 | |
| 8188 | /* make sure PCI base addr 1 is MMIO */ |
| 8189 | if (!(pci_resource_flags(pdev, region) & IORESOURCE_MEM)) { |
| 8190 | netif_err(tp, probe, dev, |
| 8191 | "region #%d not an MMIO resource, aborting\n", |
| 8192 | region); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8193 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8194 | } |
| 8195 | |
| 8196 | /* check for weird/broken PCI region reporting */ |
| 8197 | if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) { |
| 8198 | netif_err(tp, probe, dev, |
| 8199 | "Invalid PCI region size(s), aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8200 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8201 | } |
| 8202 | |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 8203 | rc = pcim_iomap_regions(pdev, BIT(region), MODULENAME); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8204 | if (rc < 0) { |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 8205 | netif_err(tp, probe, dev, "cannot remap MMIO, aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8206 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8207 | } |
| 8208 | |
Andy Shevchenko | 93a00d4 | 2018-03-01 13:27:35 +0200 | [diff] [blame] | 8209 | tp->mmio_addr = pcim_iomap_table(pdev)[region]; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8210 | |
| 8211 | if (!pci_is_pcie(pdev)) |
| 8212 | netif_info(tp, probe, dev, "not PCI Express\n"); |
| 8213 | |
| 8214 | /* Identify chip attached to board */ |
| 8215 | rtl8169_get_mac_version(tp, dev, cfg->default_ver); |
| 8216 | |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 8217 | tp->cp_cmd = 0; |
| 8218 | |
| 8219 | if ((sizeof(dma_addr_t) > 4) && |
| 8220 | (use_dac == 1 || (use_dac == -1 && pci_is_pcie(pdev) && |
| 8221 | tp->mac_version >= RTL_GIGA_MAC_VER_18)) && |
Ard Biesheuvel | f007643 | 2016-10-14 14:40:33 +0100 | [diff] [blame] | 8222 | !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
| 8223 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 8224 | |
| 8225 | /* CPlusCmd Dual Access Cycle is only needed for non-PCIe */ |
| 8226 | if (!pci_is_pcie(pdev)) |
| 8227 | tp->cp_cmd |= PCIDAC; |
| 8228 | dev->features |= NETIF_F_HIGHDMA; |
| 8229 | } else { |
| 8230 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 8231 | if (rc < 0) { |
| 8232 | netif_err(tp, probe, dev, "DMA configuration failed\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8233 | return rc; |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 8234 | } |
| 8235 | } |
| 8236 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8237 | rtl_init_rxcfg(tp); |
| 8238 | |
| 8239 | rtl_irq_disable(tp); |
| 8240 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8241 | rtl_hw_initialize(tp); |
| 8242 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8243 | rtl_hw_reset(tp); |
| 8244 | |
| 8245 | rtl_ack_events(tp, 0xffff); |
| 8246 | |
| 8247 | pci_set_master(pdev); |
| 8248 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8249 | rtl_init_mdio_ops(tp); |
| 8250 | rtl_init_pll_power_ops(tp); |
| 8251 | rtl_init_jumbo_ops(tp); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 8252 | rtl_init_csi_ops(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8253 | |
| 8254 | rtl8169_print_mac_version(tp); |
| 8255 | |
| 8256 | chipset = tp->mac_version; |
| 8257 | tp->txd_version = rtl_chip_infos[chipset].txd_version; |
| 8258 | |
Heiner Kallweit | 6c6aa15 | 2018-02-24 16:53:23 +0100 | [diff] [blame] | 8259 | rc = rtl_alloc_irq(tp); |
| 8260 | if (rc < 0) { |
| 8261 | netif_err(tp, probe, dev, "Can't allocate interrupt\n"); |
| 8262 | return rc; |
| 8263 | } |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8264 | |
Heiner Kallweit | 7edf6d3 | 2018-02-22 21:22:40 +0100 | [diff] [blame] | 8265 | /* override BIOS settings, use userspace tools to enable WOL */ |
| 8266 | __rtl8169_set_wol(tp, 0); |
| 8267 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8268 | if (rtl_tbi_enabled(tp)) { |
| 8269 | tp->set_speed = rtl8169_set_speed_tbi; |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 8270 | tp->get_link_ksettings = rtl8169_get_link_ksettings_tbi; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8271 | tp->phy_reset_enable = rtl8169_tbi_reset_enable; |
| 8272 | tp->phy_reset_pending = rtl8169_tbi_reset_pending; |
| 8273 | tp->link_ok = rtl8169_tbi_link_ok; |
| 8274 | tp->do_ioctl = rtl_tbi_ioctl; |
| 8275 | } else { |
| 8276 | tp->set_speed = rtl8169_set_speed_xmii; |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 8277 | tp->get_link_ksettings = rtl8169_get_link_ksettings_xmii; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8278 | tp->phy_reset_enable = rtl8169_xmii_reset_enable; |
| 8279 | tp->phy_reset_pending = rtl8169_xmii_reset_pending; |
| 8280 | tp->link_ok = rtl8169_xmii_link_ok; |
| 8281 | tp->do_ioctl = rtl_xmii_ioctl; |
| 8282 | } |
| 8283 | |
| 8284 | mutex_init(&tp->wk.mutex); |
Kyle McMartin | 340fea3 | 2014-02-24 20:12:28 -0500 | [diff] [blame] | 8285 | u64_stats_init(&tp->rx_stats.syncp); |
| 8286 | u64_stats_init(&tp->tx_stats.syncp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8287 | |
| 8288 | /* Get MAC address */ |
Chun-Hao Lin | 89cceb2 | 2014-10-01 23:17:15 +0800 | [diff] [blame] | 8289 | if (tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 8290 | tp->mac_version == RTL_GIGA_MAC_VER_36 || |
| 8291 | tp->mac_version == RTL_GIGA_MAC_VER_37 || |
| 8292 | tp->mac_version == RTL_GIGA_MAC_VER_38 || |
| 8293 | tp->mac_version == RTL_GIGA_MAC_VER_40 || |
| 8294 | tp->mac_version == RTL_GIGA_MAC_VER_41 || |
| 8295 | tp->mac_version == RTL_GIGA_MAC_VER_42 || |
| 8296 | tp->mac_version == RTL_GIGA_MAC_VER_43 || |
| 8297 | tp->mac_version == RTL_GIGA_MAC_VER_44 || |
| 8298 | tp->mac_version == RTL_GIGA_MAC_VER_45 || |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 8299 | tp->mac_version == RTL_GIGA_MAC_VER_46 || |
| 8300 | tp->mac_version == RTL_GIGA_MAC_VER_47 || |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 8301 | tp->mac_version == RTL_GIGA_MAC_VER_48 || |
| 8302 | tp->mac_version == RTL_GIGA_MAC_VER_49 || |
| 8303 | tp->mac_version == RTL_GIGA_MAC_VER_50 || |
| 8304 | tp->mac_version == RTL_GIGA_MAC_VER_51) { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 8305 | u16 mac_addr[3]; |
| 8306 | |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 8307 | *(u32 *)&mac_addr[0] = rtl_eri_read(tp, 0xe0, ERIAR_EXGMAC); |
| 8308 | *(u16 *)&mac_addr[2] = rtl_eri_read(tp, 0xe4, ERIAR_EXGMAC); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 8309 | |
| 8310 | if (is_valid_ether_addr((u8 *)mac_addr)) |
| 8311 | rtl_rar_set(tp, (u8 *)mac_addr); |
| 8312 | } |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8313 | for (i = 0; i < ETH_ALEN; i++) |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 8314 | dev->dev_addr[i] = RTL_R8(tp, MAC0 + i); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8315 | |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 8316 | dev->ethtool_ops = &rtl8169_ethtool_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8317 | dev->watchdog_timeo = RTL8169_TX_TIMEOUT; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8318 | |
| 8319 | netif_napi_add(dev, &tp->napi, rtl8169_poll, R8169_NAPI_WEIGHT); |
| 8320 | |
| 8321 | /* don't enable SG, IP_CSUM and TSO by default - it might not work |
| 8322 | * properly for all devices */ |
| 8323 | dev->features |= NETIF_F_RXCSUM | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 8324 | NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8325 | |
| 8326 | 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] | 8327 | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_TX | |
| 8328 | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8329 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 8330 | NETIF_F_HIGHDMA; |
| 8331 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 8332 | tp->cp_cmd |= RxChkSum | RxVlan; |
| 8333 | |
| 8334 | /* |
| 8335 | * Pretend we are using VLANs; This bypasses a nasty bug where |
| 8336 | * Interrupts stop flowing on high load on 8110SCd controllers. |
| 8337 | */ |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8338 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 8339 | /* Disallow toggling */ |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 8340 | dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8341 | |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 8342 | if (tp->txd_version == RTL_TD_0) |
| 8343 | tp->tso_csum = rtl8169_tso_csum_v1; |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 8344 | else if (tp->txd_version == RTL_TD_1) { |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 8345 | tp->tso_csum = rtl8169_tso_csum_v2; |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 8346 | dev->hw_features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6; |
| 8347 | } else |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 8348 | WARN_ON_ONCE(1); |
| 8349 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8350 | dev->hw_features |= NETIF_F_RXALL; |
| 8351 | dev->hw_features |= NETIF_F_RXFCS; |
| 8352 | |
Jarod Wilson | c7315a9 | 2016-10-17 15:54:09 -0400 | [diff] [blame] | 8353 | /* MTU range: 60 - hw-specific max */ |
| 8354 | dev->min_mtu = ETH_ZLEN; |
| 8355 | dev->max_mtu = rtl_chip_infos[chipset].jumbo_max; |
| 8356 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8357 | tp->hw_start = cfg->hw_start; |
| 8358 | tp->event_slow = cfg->event_slow; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 8359 | tp->coalesce_info = cfg->coalesce_info; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8360 | |
| 8361 | tp->opts1_mask = (tp->mac_version != RTL_GIGA_MAC_VER_01) ? |
| 8362 | ~(RxBOVF | RxFOVF) : ~0; |
| 8363 | |
Kees Cook | 9de36cc | 2017-10-25 03:53:12 -0700 | [diff] [blame] | 8364 | timer_setup(&tp->timer, rtl8169_phy_timer, 0); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8365 | |
| 8366 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
| 8367 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8368 | tp->counters = dmam_alloc_coherent (&pdev->dev, sizeof(*tp->counters), |
| 8369 | &tp->counters_phys_addr, |
| 8370 | GFP_KERNEL); |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 8371 | if (!tp->counters) |
| 8372 | return -ENOMEM; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 8373 | |
Heiner Kallweit | 19c9ea3 | 2018-03-26 19:19:30 +0200 | [diff] [blame] | 8374 | pci_set_drvdata(pdev, dev); |
| 8375 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8376 | rc = register_netdev(dev); |
| 8377 | if (rc < 0) |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 8378 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8379 | |
Francois Romieu | 92a7c4e | 2012-03-10 10:42:12 +0100 | [diff] [blame] | 8380 | 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] | 8381 | rtl_chip_infos[chipset].name, tp->mmio_addr, dev->dev_addr, |
Andy Shevchenko | 1ef7286 | 2018-03-01 13:27:34 +0200 | [diff] [blame] | 8382 | (u32)(RTL_R32(tp, TxConfig) & 0x9cf0f8ff), |
Heiner Kallweit | 2927499 | 2018-02-28 20:43:38 +0100 | [diff] [blame] | 8383 | pci_irq_vector(pdev, 0)); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8384 | if (rtl_chip_infos[chipset].jumbo_max != JUMBO_1K) { |
| 8385 | netif_info(tp, probe, dev, "jumbo features [frames: %d bytes, " |
| 8386 | "tx checksumming: %s]\n", |
| 8387 | rtl_chip_infos[chipset].jumbo_max, |
| 8388 | rtl_chip_infos[chipset].jumbo_tx_csum ? "ok" : "ko"); |
| 8389 | } |
| 8390 | |
Heiner Kallweit | 9dbe789 | 2018-02-22 21:37:48 +0100 | [diff] [blame] | 8391 | if (r8168_check_dash(tp)) |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8392 | rtl8168_driver_start(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8393 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8394 | netif_carrier_off(dev); |
| 8395 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 8396 | if (pci_dev_run_wake(pdev)) |
| 8397 | pm_runtime_put_sync(&pdev->dev); |
| 8398 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8399 | return 0; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8400 | } |
| 8401 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8402 | static struct pci_driver rtl8169_pci_driver = { |
| 8403 | .name = MODULENAME, |
| 8404 | .id_table = rtl8169_pci_tbl, |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8405 | .probe = rtl_init_one, |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 8406 | .remove = rtl_remove_one, |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 8407 | .shutdown = rtl_shutdown, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 8408 | .driver.pm = RTL8169_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8409 | }; |
| 8410 | |
Devendra Naga | 3eeb7da | 2012-10-26 09:27:42 +0000 | [diff] [blame] | 8411 | module_pci_driver(rtl8169_pci_driver); |