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 | |
Francois Romieu | 9c14cea | 2008-07-05 00:21:15 +0200 | [diff] [blame] | 87 | #define MAX_READ_REQUEST_SHIFT 12 |
Michal Schmidt | aee77e4 | 2012-09-09 13:55:26 +0000 | [diff] [blame] | 88 | #define TX_DMA_BURST 7 /* Maximum PCI burst, '7' is unlimited */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */ |
| 90 | |
| 91 | #define R8169_REGS_SIZE 256 |
| 92 | #define R8169_NAPI_WEIGHT 64 |
| 93 | #define NUM_TX_DESC 64 /* Number of Tx descriptor registers */ |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 94 | #define NUM_RX_DESC 256U /* Number of Rx descriptor registers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc)) |
| 96 | #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc)) |
| 97 | |
| 98 | #define RTL8169_TX_TIMEOUT (6*HZ) |
| 99 | #define RTL8169_PHY_TIMEOUT (10*HZ) |
| 100 | |
| 101 | /* write/read MMIO register */ |
| 102 | #define RTL_W8(reg, val8) writeb ((val8), ioaddr + (reg)) |
| 103 | #define RTL_W16(reg, val16) writew ((val16), ioaddr + (reg)) |
| 104 | #define RTL_W32(reg, val32) writel ((val32), ioaddr + (reg)) |
| 105 | #define RTL_R8(reg) readb (ioaddr + (reg)) |
| 106 | #define RTL_R16(reg) readw (ioaddr + (reg)) |
Junchang Wang | 06f555f | 2010-05-30 02:26:07 +0000 | [diff] [blame] | 107 | #define RTL_R32(reg) readl (ioaddr + (reg)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | |
| 109 | enum mac_version { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 110 | RTL_GIGA_MAC_VER_01 = 0, |
| 111 | RTL_GIGA_MAC_VER_02, |
| 112 | RTL_GIGA_MAC_VER_03, |
| 113 | RTL_GIGA_MAC_VER_04, |
| 114 | RTL_GIGA_MAC_VER_05, |
| 115 | RTL_GIGA_MAC_VER_06, |
| 116 | RTL_GIGA_MAC_VER_07, |
| 117 | RTL_GIGA_MAC_VER_08, |
| 118 | RTL_GIGA_MAC_VER_09, |
| 119 | RTL_GIGA_MAC_VER_10, |
| 120 | RTL_GIGA_MAC_VER_11, |
| 121 | RTL_GIGA_MAC_VER_12, |
| 122 | RTL_GIGA_MAC_VER_13, |
| 123 | RTL_GIGA_MAC_VER_14, |
| 124 | RTL_GIGA_MAC_VER_15, |
| 125 | RTL_GIGA_MAC_VER_16, |
| 126 | RTL_GIGA_MAC_VER_17, |
| 127 | RTL_GIGA_MAC_VER_18, |
| 128 | RTL_GIGA_MAC_VER_19, |
| 129 | RTL_GIGA_MAC_VER_20, |
| 130 | RTL_GIGA_MAC_VER_21, |
| 131 | RTL_GIGA_MAC_VER_22, |
| 132 | RTL_GIGA_MAC_VER_23, |
| 133 | RTL_GIGA_MAC_VER_24, |
| 134 | RTL_GIGA_MAC_VER_25, |
| 135 | RTL_GIGA_MAC_VER_26, |
| 136 | RTL_GIGA_MAC_VER_27, |
| 137 | RTL_GIGA_MAC_VER_28, |
| 138 | RTL_GIGA_MAC_VER_29, |
| 139 | RTL_GIGA_MAC_VER_30, |
| 140 | RTL_GIGA_MAC_VER_31, |
| 141 | RTL_GIGA_MAC_VER_32, |
| 142 | RTL_GIGA_MAC_VER_33, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 143 | RTL_GIGA_MAC_VER_34, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 144 | RTL_GIGA_MAC_VER_35, |
| 145 | RTL_GIGA_MAC_VER_36, |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 146 | RTL_GIGA_MAC_VER_37, |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 147 | RTL_GIGA_MAC_VER_38, |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 148 | RTL_GIGA_MAC_VER_39, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 149 | RTL_GIGA_MAC_VER_40, |
| 150 | RTL_GIGA_MAC_VER_41, |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 151 | RTL_GIGA_MAC_VER_42, |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 152 | RTL_GIGA_MAC_VER_43, |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 153 | RTL_GIGA_MAC_VER_44, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 154 | RTL_GIGA_MAC_VER_45, |
| 155 | RTL_GIGA_MAC_VER_46, |
| 156 | RTL_GIGA_MAC_VER_47, |
| 157 | RTL_GIGA_MAC_VER_48, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 158 | RTL_GIGA_MAC_VER_49, |
| 159 | RTL_GIGA_MAC_VER_50, |
| 160 | RTL_GIGA_MAC_VER_51, |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 161 | RTL_GIGA_MAC_NONE = 0xff, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | }; |
| 163 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 164 | enum rtl_tx_desc_version { |
| 165 | RTL_TD_0 = 0, |
| 166 | RTL_TD_1 = 1, |
| 167 | }; |
| 168 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 169 | #define JUMBO_1K ETH_DATA_LEN |
| 170 | #define JUMBO_4K (4*1024 - ETH_HLEN - 2) |
| 171 | #define JUMBO_6K (6*1024 - ETH_HLEN - 2) |
| 172 | #define JUMBO_7K (7*1024 - ETH_HLEN - 2) |
| 173 | #define JUMBO_9K (9*1024 - ETH_HLEN - 2) |
| 174 | |
| 175 | #define _R(NAME,TD,FW,SZ,B) { \ |
| 176 | .name = NAME, \ |
| 177 | .txd_version = TD, \ |
| 178 | .fw_name = FW, \ |
| 179 | .jumbo_max = SZ, \ |
| 180 | .jumbo_tx_csum = B \ |
| 181 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | |
Jesper Juhl | 3c6bee1 | 2006-01-09 20:54:01 -0800 | [diff] [blame] | 183 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | const char *name; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 185 | enum rtl_tx_desc_version txd_version; |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 186 | const char *fw_name; |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 187 | u16 jumbo_max; |
| 188 | bool jumbo_tx_csum; |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 189 | } rtl_chip_infos[] = { |
| 190 | /* PCI devices. */ |
| 191 | [RTL_GIGA_MAC_VER_01] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 192 | _R("RTL8169", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 193 | [RTL_GIGA_MAC_VER_02] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 194 | _R("RTL8169s", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 195 | [RTL_GIGA_MAC_VER_03] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 196 | _R("RTL8110s", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 197 | [RTL_GIGA_MAC_VER_04] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 198 | _R("RTL8169sb/8110sb", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 199 | [RTL_GIGA_MAC_VER_05] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 200 | _R("RTL8169sc/8110sc", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 201 | [RTL_GIGA_MAC_VER_06] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 202 | _R("RTL8169sc/8110sc", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 203 | /* PCI-E devices. */ |
| 204 | [RTL_GIGA_MAC_VER_07] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 205 | _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 206 | [RTL_GIGA_MAC_VER_08] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 207 | _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 208 | [RTL_GIGA_MAC_VER_09] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 209 | _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 210 | [RTL_GIGA_MAC_VER_10] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 211 | _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 212 | [RTL_GIGA_MAC_VER_11] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 213 | _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 214 | [RTL_GIGA_MAC_VER_12] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 215 | _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 216 | [RTL_GIGA_MAC_VER_13] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 217 | _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 218 | [RTL_GIGA_MAC_VER_14] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 219 | _R("RTL8100e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 220 | [RTL_GIGA_MAC_VER_15] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 221 | _R("RTL8100e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 222 | [RTL_GIGA_MAC_VER_16] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 223 | _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 224 | [RTL_GIGA_MAC_VER_17] = |
hayeswang | f75761b | 2014-03-11 15:11:59 +0800 | [diff] [blame] | 225 | _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 226 | [RTL_GIGA_MAC_VER_18] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 227 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 228 | [RTL_GIGA_MAC_VER_19] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 229 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 230 | [RTL_GIGA_MAC_VER_20] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 231 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 232 | [RTL_GIGA_MAC_VER_21] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 233 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 234 | [RTL_GIGA_MAC_VER_22] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 235 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 236 | [RTL_GIGA_MAC_VER_23] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 237 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 238 | [RTL_GIGA_MAC_VER_24] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 239 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 240 | [RTL_GIGA_MAC_VER_25] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 241 | _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_1, |
| 242 | JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 243 | [RTL_GIGA_MAC_VER_26] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 244 | _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_2, |
| 245 | JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 246 | [RTL_GIGA_MAC_VER_27] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 247 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 248 | [RTL_GIGA_MAC_VER_28] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 249 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 250 | [RTL_GIGA_MAC_VER_29] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 251 | _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1, |
| 252 | JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 253 | [RTL_GIGA_MAC_VER_30] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 254 | _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1, |
| 255 | JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 256 | [RTL_GIGA_MAC_VER_31] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 257 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 258 | [RTL_GIGA_MAC_VER_32] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 259 | _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_1, |
| 260 | JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 261 | [RTL_GIGA_MAC_VER_33] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 262 | _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_2, |
| 263 | JUMBO_9K, false), |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 264 | [RTL_GIGA_MAC_VER_34] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 265 | _R("RTL8168evl/8111evl",RTL_TD_1, FIRMWARE_8168E_3, |
| 266 | JUMBO_9K, false), |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 267 | [RTL_GIGA_MAC_VER_35] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 268 | _R("RTL8168f/8111f", RTL_TD_1, FIRMWARE_8168F_1, |
| 269 | JUMBO_9K, false), |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 270 | [RTL_GIGA_MAC_VER_36] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 271 | _R("RTL8168f/8111f", RTL_TD_1, FIRMWARE_8168F_2, |
| 272 | JUMBO_9K, false), |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 273 | [RTL_GIGA_MAC_VER_37] = |
| 274 | _R("RTL8402", RTL_TD_1, FIRMWARE_8402_1, |
| 275 | JUMBO_1K, true), |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 276 | [RTL_GIGA_MAC_VER_38] = |
| 277 | _R("RTL8411", RTL_TD_1, FIRMWARE_8411_1, |
| 278 | JUMBO_9K, false), |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 279 | [RTL_GIGA_MAC_VER_39] = |
| 280 | _R("RTL8106e", RTL_TD_1, FIRMWARE_8106E_1, |
| 281 | JUMBO_1K, true), |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 282 | [RTL_GIGA_MAC_VER_40] = |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 283 | _R("RTL8168g/8111g", RTL_TD_1, FIRMWARE_8168G_2, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 284 | JUMBO_9K, false), |
| 285 | [RTL_GIGA_MAC_VER_41] = |
| 286 | _R("RTL8168g/8111g", RTL_TD_1, NULL, JUMBO_9K, false), |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 287 | [RTL_GIGA_MAC_VER_42] = |
| 288 | _R("RTL8168g/8111g", RTL_TD_1, FIRMWARE_8168G_3, |
| 289 | JUMBO_9K, false), |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 290 | [RTL_GIGA_MAC_VER_43] = |
| 291 | _R("RTL8106e", RTL_TD_1, FIRMWARE_8106E_2, |
| 292 | JUMBO_1K, true), |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 293 | [RTL_GIGA_MAC_VER_44] = |
| 294 | _R("RTL8411", RTL_TD_1, FIRMWARE_8411_2, |
| 295 | JUMBO_9K, false), |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 296 | [RTL_GIGA_MAC_VER_45] = |
| 297 | _R("RTL8168h/8111h", RTL_TD_1, FIRMWARE_8168H_1, |
| 298 | JUMBO_9K, false), |
| 299 | [RTL_GIGA_MAC_VER_46] = |
| 300 | _R("RTL8168h/8111h", RTL_TD_1, FIRMWARE_8168H_2, |
| 301 | JUMBO_9K, false), |
| 302 | [RTL_GIGA_MAC_VER_47] = |
| 303 | _R("RTL8107e", RTL_TD_1, FIRMWARE_8107E_1, |
| 304 | JUMBO_1K, false), |
| 305 | [RTL_GIGA_MAC_VER_48] = |
| 306 | _R("RTL8107e", RTL_TD_1, FIRMWARE_8107E_2, |
| 307 | JUMBO_1K, false), |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 308 | [RTL_GIGA_MAC_VER_49] = |
| 309 | _R("RTL8168ep/8111ep", RTL_TD_1, NULL, |
| 310 | JUMBO_9K, false), |
| 311 | [RTL_GIGA_MAC_VER_50] = |
| 312 | _R("RTL8168ep/8111ep", RTL_TD_1, NULL, |
| 313 | JUMBO_9K, false), |
| 314 | [RTL_GIGA_MAC_VER_51] = |
| 315 | _R("RTL8168ep/8111ep", RTL_TD_1, NULL, |
| 316 | JUMBO_9K, false), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | }; |
| 318 | #undef _R |
| 319 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 320 | enum cfg_version { |
| 321 | RTL_CFG_0 = 0x00, |
| 322 | RTL_CFG_1, |
| 323 | RTL_CFG_2 |
| 324 | }; |
| 325 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 326 | static const struct pci_device_id rtl8169_pci_tbl[] = { |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 327 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 }, |
Francois Romieu | d2eed8c | 2006-08-31 22:01:07 +0200 | [diff] [blame] | 328 | { 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] | 329 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8161), 0, 0, RTL_CFG_1 }, |
Francois Romieu | d81bf55 | 2006-09-20 21:31:20 +0200 | [diff] [blame] | 330 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_0 }, |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 331 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_1 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 332 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 }, |
Francois Romieu | 2a35cfa | 2012-08-31 23:06:17 +0200 | [diff] [blame] | 333 | { PCI_VENDOR_ID_DLINK, 0x4300, |
| 334 | PCI_VENDOR_ID_DLINK, 0x4b10, 0, 0, RTL_CFG_1 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 335 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4300), 0, 0, RTL_CFG_0 }, |
Lennart Sorensen | 93a3aa2 | 2011-07-28 13:18:11 +0000 | [diff] [blame] | 336 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4302), 0, 0, RTL_CFG_0 }, |
Francois Romieu | bc1660b | 2007-10-12 23:58:09 +0200 | [diff] [blame] | 337 | { PCI_DEVICE(PCI_VENDOR_ID_AT, 0xc107), 0, 0, RTL_CFG_0 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 338 | { PCI_DEVICE(0x16ec, 0x0116), 0, 0, RTL_CFG_0 }, |
| 339 | { PCI_VENDOR_ID_LINKSYS, 0x1032, |
| 340 | PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 }, |
Ciaran McCreesh | 11d2e28 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 341 | { 0x0001, 0x8168, |
| 342 | PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | {0,}, |
| 344 | }; |
| 345 | |
| 346 | MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl); |
| 347 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 348 | static int rx_buf_sz = 16383; |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 349 | static int use_dac = -1; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 350 | static struct { |
| 351 | u32 msg_enable; |
| 352 | } debug = { -1 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 354 | enum rtl_registers { |
| 355 | MAC0 = 0, /* Ethernet hardware address. */ |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 356 | MAC4 = 4, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 357 | MAR0 = 8, /* Multicast filter. */ |
| 358 | CounterAddrLow = 0x10, |
| 359 | CounterAddrHigh = 0x14, |
| 360 | TxDescStartAddrLow = 0x20, |
| 361 | TxDescStartAddrHigh = 0x24, |
| 362 | TxHDescStartAddrLow = 0x28, |
| 363 | TxHDescStartAddrHigh = 0x2c, |
| 364 | FLASH = 0x30, |
| 365 | ERSR = 0x36, |
| 366 | ChipCmd = 0x37, |
| 367 | TxPoll = 0x38, |
| 368 | IntrMask = 0x3c, |
| 369 | IntrStatus = 0x3e, |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 370 | |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 371 | TxConfig = 0x40, |
| 372 | #define TXCFG_AUTO_FIFO (1 << 7) /* 8111e-vl */ |
| 373 | #define TXCFG_EMPTY (1 << 11) /* 8111e-vl */ |
| 374 | |
| 375 | RxConfig = 0x44, |
| 376 | #define RX128_INT_EN (1 << 15) /* 8111c and later */ |
| 377 | #define RX_MULTI_EN (1 << 14) /* 8111c only */ |
| 378 | #define RXCFG_FIFO_SHIFT 13 |
| 379 | /* No threshold before first PCI xfer */ |
| 380 | #define RX_FIFO_THRESH (7 << RXCFG_FIFO_SHIFT) |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 381 | #define RX_EARLY_OFF (1 << 11) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 382 | #define RXCFG_DMA_SHIFT 8 |
| 383 | /* Unlimited maximum PCI burst. */ |
| 384 | #define RX_DMA_BURST (7 << RXCFG_DMA_SHIFT) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 385 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 386 | RxMissed = 0x4c, |
| 387 | Cfg9346 = 0x50, |
| 388 | Config0 = 0x51, |
| 389 | Config1 = 0x52, |
| 390 | Config2 = 0x53, |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 391 | #define PME_SIGNAL (1 << 5) /* 8168c and later */ |
| 392 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 393 | Config3 = 0x54, |
| 394 | Config4 = 0x55, |
| 395 | Config5 = 0x56, |
| 396 | MultiIntr = 0x5c, |
| 397 | PHYAR = 0x60, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 398 | PHYstatus = 0x6c, |
| 399 | RxMaxSize = 0xda, |
| 400 | CPlusCmd = 0xe0, |
| 401 | IntrMitigate = 0xe2, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 402 | |
| 403 | #define RTL_COALESCE_MASK 0x0f |
| 404 | #define RTL_COALESCE_SHIFT 4 |
| 405 | #define RTL_COALESCE_T_MAX (RTL_COALESCE_MASK) |
| 406 | #define RTL_COALESCE_FRAME_MAX (RTL_COALESCE_MASK << 2) |
| 407 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 408 | RxDescAddrLow = 0xe4, |
| 409 | RxDescAddrHigh = 0xe8, |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 410 | EarlyTxThres = 0xec, /* 8169. Unit of 32 bytes. */ |
| 411 | |
| 412 | #define NoEarlyTx 0x3f /* Max value : no early transmit. */ |
| 413 | |
| 414 | MaxTxPacketSize = 0xec, /* 8101/8168. Unit of 128 bytes. */ |
| 415 | |
| 416 | #define TxPacketMax (8064 >> 7) |
Hayes Wang | 3090bd9 | 2011-09-06 16:55:15 +0800 | [diff] [blame] | 417 | #define EarlySize 0x27 |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 418 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 419 | FuncEvent = 0xf0, |
| 420 | FuncEventMask = 0xf4, |
| 421 | FuncPresetState = 0xf8, |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 422 | IBCR0 = 0xf8, |
| 423 | IBCR2 = 0xf9, |
| 424 | IBIMR0 = 0xfa, |
| 425 | IBISR0 = 0xfb, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 426 | FuncForceEvent = 0xfc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | }; |
| 428 | |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 429 | enum rtl8110_registers { |
| 430 | TBICSR = 0x64, |
| 431 | TBI_ANAR = 0x68, |
| 432 | TBI_LPAR = 0x6a, |
| 433 | }; |
| 434 | |
| 435 | enum rtl8168_8101_registers { |
| 436 | CSIDR = 0x64, |
| 437 | CSIAR = 0x68, |
| 438 | #define CSIAR_FLAG 0x80000000 |
| 439 | #define CSIAR_WRITE_CMD 0x80000000 |
| 440 | #define CSIAR_BYTE_ENABLE 0x0f |
| 441 | #define CSIAR_BYTE_ENABLE_SHIFT 12 |
| 442 | #define CSIAR_ADDR_MASK 0x0fff |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 443 | #define CSIAR_FUNC_CARD 0x00000000 |
| 444 | #define CSIAR_FUNC_SDIO 0x00010000 |
| 445 | #define CSIAR_FUNC_NIC 0x00020000 |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 446 | #define CSIAR_FUNC_NIC2 0x00010000 |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 447 | PMCH = 0x6f, |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 448 | EPHYAR = 0x80, |
| 449 | #define EPHYAR_FLAG 0x80000000 |
| 450 | #define EPHYAR_WRITE_CMD 0x80000000 |
| 451 | #define EPHYAR_REG_MASK 0x1f |
| 452 | #define EPHYAR_REG_SHIFT 16 |
| 453 | #define EPHYAR_DATA_MASK 0xffff |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 454 | DLLPR = 0xd0, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 455 | #define PFM_EN (1 << 6) |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 456 | #define TX_10M_PS_EN (1 << 7) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 457 | DBG_REG = 0xd1, |
| 458 | #define FIX_NAK_1 (1 << 4) |
| 459 | #define FIX_NAK_2 (1 << 3) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 460 | TWSI = 0xd2, |
| 461 | MCU = 0xd3, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 462 | #define NOW_IS_OOB (1 << 7) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 463 | #define TX_EMPTY (1 << 5) |
| 464 | #define RX_EMPTY (1 << 4) |
| 465 | #define RXTX_EMPTY (TX_EMPTY | RX_EMPTY) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 466 | #define EN_NDP (1 << 3) |
| 467 | #define EN_OOB_RESET (1 << 2) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 468 | #define LINK_LIST_RDY (1 << 1) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 469 | EFUSEAR = 0xdc, |
| 470 | #define EFUSEAR_FLAG 0x80000000 |
| 471 | #define EFUSEAR_WRITE_CMD 0x80000000 |
| 472 | #define EFUSEAR_READ_CMD 0x00000000 |
| 473 | #define EFUSEAR_REG_MASK 0x03ff |
| 474 | #define EFUSEAR_REG_SHIFT 8 |
| 475 | #define EFUSEAR_DATA_MASK 0xff |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 476 | MISC_1 = 0xf2, |
| 477 | #define PFM_D3COLD_EN (1 << 6) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 478 | }; |
| 479 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 480 | enum rtl8168_registers { |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 481 | LED_FREQ = 0x1a, |
| 482 | EEE_LED = 0x1b, |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 483 | ERIDR = 0x70, |
| 484 | ERIAR = 0x74, |
| 485 | #define ERIAR_FLAG 0x80000000 |
| 486 | #define ERIAR_WRITE_CMD 0x80000000 |
| 487 | #define ERIAR_READ_CMD 0x00000000 |
| 488 | #define ERIAR_ADDR_BYTE_ALIGN 4 |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 489 | #define ERIAR_TYPE_SHIFT 16 |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 490 | #define ERIAR_EXGMAC (0x00 << ERIAR_TYPE_SHIFT) |
| 491 | #define ERIAR_MSIX (0x01 << ERIAR_TYPE_SHIFT) |
| 492 | #define ERIAR_ASF (0x02 << ERIAR_TYPE_SHIFT) |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 493 | #define ERIAR_OOB (0x02 << ERIAR_TYPE_SHIFT) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 494 | #define ERIAR_MASK_SHIFT 12 |
| 495 | #define ERIAR_MASK_0001 (0x1 << ERIAR_MASK_SHIFT) |
| 496 | #define ERIAR_MASK_0011 (0x3 << ERIAR_MASK_SHIFT) |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 497 | #define ERIAR_MASK_0100 (0x4 << ERIAR_MASK_SHIFT) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 498 | #define ERIAR_MASK_0101 (0x5 << ERIAR_MASK_SHIFT) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 499 | #define ERIAR_MASK_1111 (0xf << ERIAR_MASK_SHIFT) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 500 | EPHY_RXER_NUM = 0x7c, |
| 501 | OCPDR = 0xb0, /* OCP GPHY access */ |
| 502 | #define OCPDR_WRITE_CMD 0x80000000 |
| 503 | #define OCPDR_READ_CMD 0x00000000 |
| 504 | #define OCPDR_REG_MASK 0x7f |
| 505 | #define OCPDR_GPHY_REG_SHIFT 16 |
| 506 | #define OCPDR_DATA_MASK 0xffff |
| 507 | OCPAR = 0xb4, |
| 508 | #define OCPAR_FLAG 0x80000000 |
| 509 | #define OCPAR_GPHY_WRITE_CMD 0x8000f060 |
| 510 | #define OCPAR_GPHY_READ_CMD 0x0000f060 |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 511 | GPHY_OCP = 0xb8, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 512 | RDSAR1 = 0xd0, /* 8168c only. Undocumented on 8168dp */ |
| 513 | MISC = 0xf0, /* 8168e only. */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 514 | #define TXPLA_RST (1 << 29) |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 515 | #define DISABLE_LAN_EN (1 << 23) /* Enable GPIO pin */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 516 | #define PWM_EN (1 << 22) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 517 | #define RXDV_GATED_EN (1 << 19) |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 518 | #define EARLY_TALLY_EN (1 << 16) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 519 | }; |
| 520 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 521 | enum rtl_register_content { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | /* InterruptStatusBits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 523 | SYSErr = 0x8000, |
| 524 | PCSTimeout = 0x4000, |
| 525 | SWInt = 0x0100, |
| 526 | TxDescUnavail = 0x0080, |
| 527 | RxFIFOOver = 0x0040, |
| 528 | LinkChg = 0x0020, |
| 529 | RxOverflow = 0x0010, |
| 530 | TxErr = 0x0008, |
| 531 | TxOK = 0x0004, |
| 532 | RxErr = 0x0002, |
| 533 | RxOK = 0x0001, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
| 535 | /* RxStatusDesc */ |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 536 | RxBOVF = (1 << 24), |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 537 | RxFOVF = (1 << 23), |
| 538 | RxRWT = (1 << 22), |
| 539 | RxRES = (1 << 21), |
| 540 | RxRUNT = (1 << 20), |
| 541 | RxCRC = (1 << 19), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
| 543 | /* ChipCmdBits */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 544 | StopReq = 0x80, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 545 | CmdReset = 0x10, |
| 546 | CmdRxEnb = 0x08, |
| 547 | CmdTxEnb = 0x04, |
| 548 | RxBufEmpty = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | |
Francois Romieu | 275391a | 2007-02-23 23:50:28 +0100 | [diff] [blame] | 550 | /* TXPoll register p.5 */ |
| 551 | HPQ = 0x80, /* Poll cmd on the high prio queue */ |
| 552 | NPQ = 0x40, /* Poll cmd on the low prio queue */ |
| 553 | FSWInt = 0x01, /* Forced software interrupt */ |
| 554 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | /* Cfg9346Bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 556 | Cfg9346_Lock = 0x00, |
| 557 | Cfg9346_Unlock = 0xc0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | |
| 559 | /* rx_mode_bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 560 | AcceptErr = 0x20, |
| 561 | AcceptRunt = 0x10, |
| 562 | AcceptBroadcast = 0x08, |
| 563 | AcceptMulticast = 0x04, |
| 564 | AcceptMyPhys = 0x02, |
| 565 | AcceptAllPhys = 0x01, |
Francois Romieu | 1687b56 | 2011-07-19 17:21:29 +0200 | [diff] [blame] | 566 | #define RX_CONFIG_ACCEPT_MASK 0x3f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | /* TxConfigBits */ |
| 569 | TxInterFrameGapShift = 24, |
| 570 | TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */ |
| 571 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 572 | /* Config1 register p.24 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 573 | LEDS1 = (1 << 7), |
| 574 | LEDS0 = (1 << 6), |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 575 | Speed_down = (1 << 4), |
| 576 | MEMMAP = (1 << 3), |
| 577 | IOMAP = (1 << 2), |
| 578 | VPD = (1 << 1), |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 579 | PMEnable = (1 << 0), /* Power Management Enable */ |
| 580 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 581 | /* Config2 register p. 25 */ |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 582 | ClkReqEn = (1 << 7), /* Clock Request Enable */ |
françois romieu | 2ca6cf0 | 2011-12-15 08:37:43 +0000 | [diff] [blame] | 583 | MSIEnable = (1 << 5), /* 8169 only. Reserved in the 8168. */ |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 584 | PCI_Clock_66MHz = 0x01, |
| 585 | PCI_Clock_33MHz = 0x00, |
| 586 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 587 | /* Config3 register p.25 */ |
| 588 | MagicPacket = (1 << 5), /* Wake up when receives a Magic Packet */ |
| 589 | LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */ |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 590 | Jumbo_En0 = (1 << 2), /* 8168 only. Reserved in the 8168b */ |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 591 | Rdy_to_L23 = (1 << 1), /* L23 Enable */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 592 | Beacon_en = (1 << 0), /* 8168 only. Reserved in the 8168b */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 593 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 594 | /* Config4 register */ |
| 595 | Jumbo_En1 = (1 << 1), /* 8168 only. Reserved in the 8168b */ |
| 596 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 597 | /* Config5 register p.27 */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 598 | BWF = (1 << 6), /* Accept Broadcast wakeup frame */ |
| 599 | MWF = (1 << 5), /* Accept Multicast wakeup frame */ |
| 600 | UWF = (1 << 4), /* Accept Unicast wakeup frame */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 601 | Spi_en = (1 << 3), |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 602 | LanWake = (1 << 1), /* LanWake enable/disable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 603 | PMEStatus = (1 << 0), /* PME status can be reset by PCI RST# */ |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 604 | ASPM_en = (1 << 0), /* ASPM enable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 605 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | /* TBICSR p.28 */ |
| 607 | TBIReset = 0x80000000, |
| 608 | TBILoopback = 0x40000000, |
| 609 | TBINwEnable = 0x20000000, |
| 610 | TBINwRestart = 0x10000000, |
| 611 | TBILinkOk = 0x02000000, |
| 612 | TBINwComplete = 0x01000000, |
| 613 | |
| 614 | /* CPlusCmd p.31 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 615 | EnableBist = (1 << 15), // 8168 8101 |
| 616 | Mac_dbgo_oe = (1 << 14), // 8168 8101 |
| 617 | Normal_mode = (1 << 13), // unused |
| 618 | Force_half_dup = (1 << 12), // 8168 8101 |
| 619 | Force_rxflow_en = (1 << 11), // 8168 8101 |
| 620 | Force_txflow_en = (1 << 10), // 8168 8101 |
| 621 | Cxpl_dbg_sel = (1 << 9), // 8168 8101 |
| 622 | ASF = (1 << 8), // 8168 8101 |
| 623 | PktCntrDisable = (1 << 7), // 8168 8101 |
| 624 | Mac_dbgo_sel = 0x001c, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 625 | RxVlan = (1 << 6), |
| 626 | RxChkSum = (1 << 5), |
| 627 | PCIDAC = (1 << 4), |
| 628 | PCIMulRW = (1 << 3), |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 629 | INTT_0 = 0x0000, // 8168 |
| 630 | INTT_1 = 0x0001, // 8168 |
| 631 | INTT_2 = 0x0002, // 8168 |
| 632 | INTT_3 = 0x0003, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | |
| 634 | /* rtl8169_PHYstatus */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 635 | TBI_Enable = 0x80, |
| 636 | TxFlowCtrl = 0x40, |
| 637 | RxFlowCtrl = 0x20, |
| 638 | _1000bpsF = 0x10, |
| 639 | _100bps = 0x08, |
| 640 | _10bps = 0x04, |
| 641 | LinkStatus = 0x02, |
| 642 | FullDup = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 644 | /* _TBICSRBit */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 645 | TBILinkOK = 0x02000000, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 646 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 647 | /* ResetCounterCommand */ |
| 648 | CounterReset = 0x1, |
| 649 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 650 | /* DumpCounterCommand */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 651 | CounterDump = 0x8, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 652 | |
| 653 | /* magic enable v2 */ |
| 654 | MagicPacket_v2 = (1 << 16), /* Wake up when receives a Magic Packet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | }; |
| 656 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 657 | enum rtl_desc_bit { |
| 658 | /* First doubleword. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | DescOwn = (1 << 31), /* Descriptor is owned by NIC */ |
| 660 | RingEnd = (1 << 30), /* End of descriptor ring */ |
| 661 | FirstFrag = (1 << 29), /* First segment of a packet */ |
| 662 | LastFrag = (1 << 28), /* Final segment of a packet */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 663 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 665 | /* Generic case. */ |
| 666 | enum rtl_tx_desc_bit { |
| 667 | /* First doubleword. */ |
| 668 | TD_LSO = (1 << 27), /* Large Send Offload */ |
| 669 | #define TD_MSS_MAX 0x07ffu /* MSS value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 671 | /* Second doubleword. */ |
| 672 | TxVlanTag = (1 << 17), /* Add VLAN tag */ |
| 673 | }; |
| 674 | |
| 675 | /* 8169, 8168b and 810x except 8102e. */ |
| 676 | enum rtl_tx_desc_bit_0 { |
| 677 | /* First doubleword. */ |
| 678 | #define TD0_MSS_SHIFT 16 /* MSS position (11 bits) */ |
| 679 | TD0_TCP_CS = (1 << 16), /* Calculate TCP/IP checksum */ |
| 680 | TD0_UDP_CS = (1 << 17), /* Calculate UDP/IP checksum */ |
| 681 | TD0_IP_CS = (1 << 18), /* Calculate IP checksum */ |
| 682 | }; |
| 683 | |
| 684 | /* 8102e, 8168c and beyond. */ |
| 685 | enum rtl_tx_desc_bit_1 { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 686 | /* First doubleword. */ |
| 687 | TD1_GTSENV4 = (1 << 26), /* Giant Send for IPv4 */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 688 | TD1_GTSENV6 = (1 << 25), /* Giant Send for IPv6 */ |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 689 | #define GTTCPHO_SHIFT 18 |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 690 | #define GTTCPHO_MAX 0x7fU |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 691 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 692 | /* Second doubleword. */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 693 | #define TCPHO_SHIFT 18 |
| 694 | #define TCPHO_MAX 0x3ffU |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 695 | #define TD1_MSS_SHIFT 18 /* MSS position (11 bits) */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 696 | TD1_IPv6_CS = (1 << 28), /* Calculate IPv6 checksum */ |
| 697 | TD1_IPv4_CS = (1 << 29), /* Calculate IPv4 checksum */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 698 | TD1_TCP_CS = (1 << 30), /* Calculate TCP/IP checksum */ |
| 699 | TD1_UDP_CS = (1 << 31), /* Calculate UDP/IP checksum */ |
| 700 | }; |
| 701 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 702 | enum rtl_rx_desc_bit { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | /* Rx private */ |
| 704 | PID1 = (1 << 18), /* Protocol ID bit 1/2 */ |
Zhu Yanjun | 9b60047 | 2017-01-05 02:54:27 -0500 | [diff] [blame] | 705 | PID0 = (1 << 17), /* Protocol ID bit 0/2 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | |
| 707 | #define RxProtoUDP (PID1) |
| 708 | #define RxProtoTCP (PID0) |
| 709 | #define RxProtoIP (PID1 | PID0) |
| 710 | #define RxProtoMask RxProtoIP |
| 711 | |
| 712 | IPFail = (1 << 16), /* IP checksum failed */ |
| 713 | UDPFail = (1 << 15), /* UDP/IP checksum failed */ |
| 714 | TCPFail = (1 << 14), /* TCP/IP checksum failed */ |
| 715 | RxVlanTag = (1 << 16), /* VLAN tag available */ |
| 716 | }; |
| 717 | |
| 718 | #define RsvdMask 0x3fffc000 |
| 719 | |
| 720 | struct TxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 721 | __le32 opts1; |
| 722 | __le32 opts2; |
| 723 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | }; |
| 725 | |
| 726 | struct RxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 727 | __le32 opts1; |
| 728 | __le32 opts2; |
| 729 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | }; |
| 731 | |
| 732 | struct ring_info { |
| 733 | struct sk_buff *skb; |
| 734 | u32 len; |
| 735 | u8 __pad[sizeof(void *) - sizeof(u32)]; |
| 736 | }; |
| 737 | |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 738 | enum features { |
Heiner Kallweit | 022ddbc | 2018-02-20 07:23:03 +0100 | [diff] [blame] | 739 | RTL_FEATURE_MSI = (1 << 0), |
| 740 | RTL_FEATURE_GMII = (1 << 1), |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 741 | }; |
| 742 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 743 | struct rtl8169_counters { |
| 744 | __le64 tx_packets; |
| 745 | __le64 rx_packets; |
| 746 | __le64 tx_errors; |
| 747 | __le32 rx_errors; |
| 748 | __le16 rx_missed; |
| 749 | __le16 align_errors; |
| 750 | __le32 tx_one_collision; |
| 751 | __le32 tx_multi_collision; |
| 752 | __le64 rx_unicast; |
| 753 | __le64 rx_broadcast; |
| 754 | __le32 rx_multicast; |
| 755 | __le16 tx_aborted; |
| 756 | __le16 tx_underun; |
| 757 | }; |
| 758 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 759 | struct rtl8169_tc_offsets { |
| 760 | bool inited; |
| 761 | __le64 tx_errors; |
| 762 | __le32 tx_multi_collision; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 763 | __le16 tx_aborted; |
| 764 | }; |
| 765 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 766 | enum rtl_flag { |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 767 | RTL_FLAG_TASK_ENABLED, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 768 | RTL_FLAG_TASK_SLOW_PENDING, |
| 769 | RTL_FLAG_TASK_RESET_PENDING, |
| 770 | RTL_FLAG_TASK_PHY_PENDING, |
| 771 | RTL_FLAG_MAX |
| 772 | }; |
| 773 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 774 | struct rtl8169_stats { |
| 775 | u64 packets; |
| 776 | u64 bytes; |
| 777 | struct u64_stats_sync syncp; |
| 778 | }; |
| 779 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | struct rtl8169_private { |
| 781 | void __iomem *mmio_addr; /* memory map physical address */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 782 | struct pci_dev *pci_dev; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 783 | struct net_device *dev; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 784 | struct napi_struct napi; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 785 | u32 msg_enable; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 786 | u16 txd_version; |
| 787 | u16 mac_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 788 | u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */ |
| 789 | 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] | 790 | u32 dirty_tx; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 791 | struct rtl8169_stats rx_stats; |
| 792 | struct rtl8169_stats tx_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */ |
| 794 | struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */ |
| 795 | dma_addr_t TxPhyAddr; |
| 796 | dma_addr_t RxPhyAddr; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 797 | void *Rx_databuff[NUM_RX_DESC]; /* Rx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | struct timer_list timer; |
| 800 | u16 cp_cmd; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 801 | |
| 802 | u16 event_slow; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 803 | const struct rtl_coalesce_info *coalesce_info; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 804 | |
| 805 | struct mdio_ops { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 806 | void (*write)(struct rtl8169_private *, int, int); |
| 807 | int (*read)(struct rtl8169_private *, int); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 808 | } mdio_ops; |
| 809 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 810 | struct pll_power_ops { |
| 811 | void (*down)(struct rtl8169_private *); |
| 812 | void (*up)(struct rtl8169_private *); |
| 813 | } pll_power_ops; |
| 814 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 815 | struct jumbo_ops { |
| 816 | void (*enable)(struct rtl8169_private *); |
| 817 | void (*disable)(struct rtl8169_private *); |
| 818 | } jumbo_ops; |
| 819 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 820 | struct csi_ops { |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 821 | void (*write)(struct rtl8169_private *, int, int); |
| 822 | u32 (*read)(struct rtl8169_private *, int); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 823 | } csi_ops; |
| 824 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 825 | 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] | 826 | int (*get_link_ksettings)(struct net_device *, |
| 827 | struct ethtool_link_ksettings *); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 828 | void (*phy_reset_enable)(struct rtl8169_private *tp); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 829 | void (*hw_start)(struct net_device *); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 830 | unsigned int (*phy_reset_pending)(struct rtl8169_private *tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | unsigned int (*link_ok)(void __iomem *); |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 832 | 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] | 833 | bool (*tso_csum)(struct rtl8169_private *, struct sk_buff *, u32 *); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 834 | |
| 835 | struct { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 836 | DECLARE_BITMAP(flags, RTL_FLAG_MAX); |
| 837 | struct mutex mutex; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 838 | struct work_struct work; |
| 839 | } wk; |
| 840 | |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 841 | unsigned features; |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 842 | |
| 843 | struct mii_if_info mii; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 844 | dma_addr_t counters_phys_addr; |
| 845 | struct rtl8169_counters *counters; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 846 | struct rtl8169_tc_offsets tc_offset; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 847 | u32 saved_wolopts; |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 848 | u32 opts1_mask; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 849 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 850 | struct rtl_fw { |
| 851 | const struct firmware *fw; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 852 | |
| 853 | #define RTL_VER_SIZE 32 |
| 854 | |
| 855 | char version[RTL_VER_SIZE]; |
| 856 | |
| 857 | struct rtl_fw_phy_action { |
| 858 | __le32 *code; |
| 859 | size_t size; |
| 860 | } phy_action; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 861 | } *rtl_fw; |
Phil Carmody | 497888c | 2011-07-14 15:07:13 +0300 | [diff] [blame] | 862 | #define RTL_FIRMWARE_UNKNOWN ERR_PTR(-EAGAIN) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 863 | |
| 864 | u32 ocp_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 865 | }; |
| 866 | |
Ralf Baechle | 979b6c1 | 2005-06-13 14:30:40 -0700 | [diff] [blame] | 867 | MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 869 | module_param(use_dac, int, 0); |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 870 | 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] | 871 | module_param_named(debug, debug.msg_enable, int, 0); |
| 872 | MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | MODULE_LICENSE("GPL"); |
| 874 | MODULE_VERSION(RTL8169_VERSION); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 875 | MODULE_FIRMWARE(FIRMWARE_8168D_1); |
| 876 | MODULE_FIRMWARE(FIRMWARE_8168D_2); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 877 | MODULE_FIRMWARE(FIRMWARE_8168E_1); |
| 878 | MODULE_FIRMWARE(FIRMWARE_8168E_2); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 879 | MODULE_FIRMWARE(FIRMWARE_8168E_3); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 880 | MODULE_FIRMWARE(FIRMWARE_8105E_1); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 881 | MODULE_FIRMWARE(FIRMWARE_8168F_1); |
| 882 | MODULE_FIRMWARE(FIRMWARE_8168F_2); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 883 | MODULE_FIRMWARE(FIRMWARE_8402_1); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 884 | MODULE_FIRMWARE(FIRMWARE_8411_1); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 885 | MODULE_FIRMWARE(FIRMWARE_8411_2); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 886 | MODULE_FIRMWARE(FIRMWARE_8106E_1); |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 887 | MODULE_FIRMWARE(FIRMWARE_8106E_2); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 888 | MODULE_FIRMWARE(FIRMWARE_8168G_2); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 889 | MODULE_FIRMWARE(FIRMWARE_8168G_3); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 890 | MODULE_FIRMWARE(FIRMWARE_8168H_1); |
| 891 | MODULE_FIRMWARE(FIRMWARE_8168H_2); |
Francois Romieu | a3bf5c4 | 2014-08-26 22:40:38 +0200 | [diff] [blame] | 892 | MODULE_FIRMWARE(FIRMWARE_8107E_1); |
| 893 | MODULE_FIRMWARE(FIRMWARE_8107E_2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 894 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 895 | static void rtl_lock_work(struct rtl8169_private *tp) |
| 896 | { |
| 897 | mutex_lock(&tp->wk.mutex); |
| 898 | } |
| 899 | |
| 900 | static void rtl_unlock_work(struct rtl8169_private *tp) |
| 901 | { |
| 902 | mutex_unlock(&tp->wk.mutex); |
| 903 | } |
| 904 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 905 | static void rtl_tx_performance_tweak(struct pci_dev *pdev, u16 force) |
| 906 | { |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 907 | pcie_capability_clear_and_set_word(pdev, PCI_EXP_DEVCTL, |
| 908 | PCI_EXP_DEVCTL_READRQ, force); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 909 | } |
| 910 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 911 | struct rtl_cond { |
| 912 | bool (*check)(struct rtl8169_private *); |
| 913 | const char *msg; |
| 914 | }; |
| 915 | |
| 916 | static void rtl_udelay(unsigned int d) |
| 917 | { |
| 918 | udelay(d); |
| 919 | } |
| 920 | |
| 921 | static bool rtl_loop_wait(struct rtl8169_private *tp, const struct rtl_cond *c, |
| 922 | void (*delay)(unsigned int), unsigned int d, int n, |
| 923 | bool high) |
| 924 | { |
| 925 | int i; |
| 926 | |
| 927 | for (i = 0; i < n; i++) { |
| 928 | delay(d); |
| 929 | if (c->check(tp) == high) |
| 930 | return true; |
| 931 | } |
Francois Romieu | 82e316e | 2012-07-11 23:39:51 +0200 | [diff] [blame] | 932 | netif_err(tp, drv, tp->dev, "%s == %d (loop: %d, delay: %d).\n", |
| 933 | c->msg, !high, n, d); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 934 | return false; |
| 935 | } |
| 936 | |
| 937 | static bool rtl_udelay_loop_wait_high(struct rtl8169_private *tp, |
| 938 | const struct rtl_cond *c, |
| 939 | unsigned int d, int n) |
| 940 | { |
| 941 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, true); |
| 942 | } |
| 943 | |
| 944 | static bool rtl_udelay_loop_wait_low(struct rtl8169_private *tp, |
| 945 | const struct rtl_cond *c, |
| 946 | unsigned int d, int n) |
| 947 | { |
| 948 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, false); |
| 949 | } |
| 950 | |
| 951 | static bool rtl_msleep_loop_wait_high(struct rtl8169_private *tp, |
| 952 | const struct rtl_cond *c, |
| 953 | unsigned int d, int n) |
| 954 | { |
| 955 | return rtl_loop_wait(tp, c, msleep, d, n, true); |
| 956 | } |
| 957 | |
| 958 | static bool rtl_msleep_loop_wait_low(struct rtl8169_private *tp, |
| 959 | const struct rtl_cond *c, |
| 960 | unsigned int d, int n) |
| 961 | { |
| 962 | return rtl_loop_wait(tp, c, msleep, d, n, false); |
| 963 | } |
| 964 | |
| 965 | #define DECLARE_RTL_COND(name) \ |
| 966 | static bool name ## _check(struct rtl8169_private *); \ |
| 967 | \ |
| 968 | static const struct rtl_cond name = { \ |
| 969 | .check = name ## _check, \ |
| 970 | .msg = #name \ |
| 971 | }; \ |
| 972 | \ |
| 973 | static bool name ## _check(struct rtl8169_private *tp) |
| 974 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 975 | static bool rtl_ocp_reg_failure(struct rtl8169_private *tp, u32 reg) |
| 976 | { |
| 977 | if (reg & 0xffff0001) { |
| 978 | netif_err(tp, drv, tp->dev, "Invalid ocp reg %x!\n", reg); |
| 979 | return true; |
| 980 | } |
| 981 | return false; |
| 982 | } |
| 983 | |
| 984 | DECLARE_RTL_COND(rtl_ocp_gphy_cond) |
| 985 | { |
| 986 | void __iomem *ioaddr = tp->mmio_addr; |
| 987 | |
| 988 | return RTL_R32(GPHY_OCP) & OCPAR_FLAG; |
| 989 | } |
| 990 | |
| 991 | static void r8168_phy_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 992 | { |
| 993 | void __iomem *ioaddr = tp->mmio_addr; |
| 994 | |
| 995 | if (rtl_ocp_reg_failure(tp, reg)) |
| 996 | return; |
| 997 | |
| 998 | RTL_W32(GPHY_OCP, OCPAR_FLAG | (reg << 15) | data); |
| 999 | |
| 1000 | rtl_udelay_loop_wait_low(tp, &rtl_ocp_gphy_cond, 25, 10); |
| 1001 | } |
| 1002 | |
| 1003 | static u16 r8168_phy_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 1004 | { |
| 1005 | void __iomem *ioaddr = tp->mmio_addr; |
| 1006 | |
| 1007 | if (rtl_ocp_reg_failure(tp, reg)) |
| 1008 | return 0; |
| 1009 | |
| 1010 | RTL_W32(GPHY_OCP, reg << 15); |
| 1011 | |
| 1012 | return rtl_udelay_loop_wait_high(tp, &rtl_ocp_gphy_cond, 25, 10) ? |
| 1013 | (RTL_R32(GPHY_OCP) & 0xffff) : ~0; |
| 1014 | } |
| 1015 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1016 | static void r8168_mac_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 1017 | { |
| 1018 | void __iomem *ioaddr = tp->mmio_addr; |
| 1019 | |
| 1020 | if (rtl_ocp_reg_failure(tp, reg)) |
| 1021 | return; |
| 1022 | |
| 1023 | RTL_W32(OCPDR, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1024 | } |
| 1025 | |
| 1026 | static u16 r8168_mac_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 1027 | { |
| 1028 | void __iomem *ioaddr = tp->mmio_addr; |
| 1029 | |
| 1030 | if (rtl_ocp_reg_failure(tp, reg)) |
| 1031 | return 0; |
| 1032 | |
| 1033 | RTL_W32(OCPDR, reg << 15); |
| 1034 | |
Hayes Wang | 3a83ad1 | 2012-07-11 20:31:56 +0800 | [diff] [blame] | 1035 | return RTL_R32(OCPDR); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1036 | } |
| 1037 | |
| 1038 | #define OCP_STD_PHY_BASE 0xa400 |
| 1039 | |
| 1040 | static void r8168g_mdio_write(struct rtl8169_private *tp, int reg, int value) |
| 1041 | { |
| 1042 | if (reg == 0x1f) { |
| 1043 | tp->ocp_base = value ? value << 4 : OCP_STD_PHY_BASE; |
| 1044 | return; |
| 1045 | } |
| 1046 | |
| 1047 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 1048 | reg -= 0x10; |
| 1049 | |
| 1050 | r8168_phy_ocp_write(tp, tp->ocp_base + reg * 2, value); |
| 1051 | } |
| 1052 | |
| 1053 | static int r8168g_mdio_read(struct rtl8169_private *tp, int reg) |
| 1054 | { |
| 1055 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 1056 | reg -= 0x10; |
| 1057 | |
| 1058 | return r8168_phy_ocp_read(tp, tp->ocp_base + reg * 2); |
| 1059 | } |
| 1060 | |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 1061 | static void mac_mcu_write(struct rtl8169_private *tp, int reg, int value) |
| 1062 | { |
| 1063 | if (reg == 0x1f) { |
| 1064 | tp->ocp_base = value << 4; |
| 1065 | return; |
| 1066 | } |
| 1067 | |
| 1068 | r8168_mac_ocp_write(tp, tp->ocp_base + reg, value); |
| 1069 | } |
| 1070 | |
| 1071 | static int mac_mcu_read(struct rtl8169_private *tp, int reg) |
| 1072 | { |
| 1073 | return r8168_mac_ocp_read(tp, tp->ocp_base + reg); |
| 1074 | } |
| 1075 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1076 | DECLARE_RTL_COND(rtl_phyar_cond) |
| 1077 | { |
| 1078 | void __iomem *ioaddr = tp->mmio_addr; |
| 1079 | |
| 1080 | return RTL_R32(PHYAR) & 0x80000000; |
| 1081 | } |
| 1082 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1083 | 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] | 1084 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1085 | void __iomem *ioaddr = tp->mmio_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1086 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1087 | RTL_W32(PHYAR, 0x80000000 | (reg & 0x1f) << 16 | (value & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1089 | rtl_udelay_loop_wait_low(tp, &rtl_phyar_cond, 25, 20); |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 1090 | /* |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 1091 | * According to hardware specs a 20us delay is required after write |
| 1092 | * complete indication, but before sending next command. |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 1093 | */ |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 1094 | udelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | } |
| 1096 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1097 | static int r8169_mdio_read(struct rtl8169_private *tp, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1098 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1099 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1100 | int value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1101 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1102 | RTL_W32(PHYAR, 0x0 | (reg & 0x1f) << 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1104 | value = rtl_udelay_loop_wait_high(tp, &rtl_phyar_cond, 25, 20) ? |
| 1105 | RTL_R32(PHYAR) & 0xffff : ~0; |
| 1106 | |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 1107 | /* |
| 1108 | * According to hardware specs a 20us delay is required after read |
| 1109 | * complete indication, but before sending next command. |
| 1110 | */ |
| 1111 | udelay(20); |
| 1112 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | return value; |
| 1114 | } |
| 1115 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1116 | DECLARE_RTL_COND(rtl_ocpar_cond) |
| 1117 | { |
| 1118 | void __iomem *ioaddr = tp->mmio_addr; |
| 1119 | |
| 1120 | return RTL_R32(OCPAR) & OCPAR_FLAG; |
| 1121 | } |
| 1122 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1123 | 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] | 1124 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1125 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1126 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1127 | RTL_W32(OCPDR, data | ((reg & OCPDR_REG_MASK) << OCPDR_GPHY_REG_SHIFT)); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1128 | RTL_W32(OCPAR, OCPAR_GPHY_WRITE_CMD); |
| 1129 | RTL_W32(EPHY_RXER_NUM, 0); |
| 1130 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1131 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 1000, 100); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1132 | } |
| 1133 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1134 | 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] | 1135 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1136 | r8168dp_1_mdio_access(tp, reg, |
| 1137 | OCPDR_WRITE_CMD | (value & OCPDR_DATA_MASK)); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1138 | } |
| 1139 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1140 | 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] | 1141 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1142 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1143 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1144 | r8168dp_1_mdio_access(tp, reg, OCPDR_READ_CMD); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1145 | |
| 1146 | mdelay(1); |
| 1147 | RTL_W32(OCPAR, OCPAR_GPHY_READ_CMD); |
| 1148 | RTL_W32(EPHY_RXER_NUM, 0); |
| 1149 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1150 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 1000, 100) ? |
| 1151 | RTL_R32(OCPDR) & OCPDR_DATA_MASK : ~0; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1152 | } |
| 1153 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1154 | #define R8168DP_1_MDIO_ACCESS_BIT 0x00020000 |
| 1155 | |
| 1156 | static void r8168dp_2_mdio_start(void __iomem *ioaddr) |
| 1157 | { |
| 1158 | RTL_W32(0xd0, RTL_R32(0xd0) & ~R8168DP_1_MDIO_ACCESS_BIT); |
| 1159 | } |
| 1160 | |
| 1161 | static void r8168dp_2_mdio_stop(void __iomem *ioaddr) |
| 1162 | { |
| 1163 | RTL_W32(0xd0, RTL_R32(0xd0) | R8168DP_1_MDIO_ACCESS_BIT); |
| 1164 | } |
| 1165 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1166 | 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] | 1167 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1168 | void __iomem *ioaddr = tp->mmio_addr; |
| 1169 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1170 | r8168dp_2_mdio_start(ioaddr); |
| 1171 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1172 | r8169_mdio_write(tp, reg, value); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1173 | |
| 1174 | r8168dp_2_mdio_stop(ioaddr); |
| 1175 | } |
| 1176 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1177 | 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] | 1178 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1179 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1180 | int value; |
| 1181 | |
| 1182 | r8168dp_2_mdio_start(ioaddr); |
| 1183 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1184 | value = r8169_mdio_read(tp, reg); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1185 | |
| 1186 | r8168dp_2_mdio_stop(ioaddr); |
| 1187 | |
| 1188 | return value; |
| 1189 | } |
| 1190 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1191 | static void rtl_writephy(struct rtl8169_private *tp, int location, u32 val) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1192 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1193 | tp->mdio_ops.write(tp, location, val); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1194 | } |
| 1195 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1196 | static int rtl_readphy(struct rtl8169_private *tp, int location) |
| 1197 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1198 | return tp->mdio_ops.read(tp, location); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1199 | } |
| 1200 | |
| 1201 | static void rtl_patchphy(struct rtl8169_private *tp, int reg_addr, int value) |
| 1202 | { |
| 1203 | rtl_writephy(tp, reg_addr, rtl_readphy(tp, reg_addr) | value); |
| 1204 | } |
| 1205 | |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1206 | 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] | 1207 | { |
| 1208 | int val; |
| 1209 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1210 | val = rtl_readphy(tp, reg_addr); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1211 | rtl_writephy(tp, reg_addr, (val & ~m) | p); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1212 | } |
| 1213 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1214 | static void rtl_mdio_write(struct net_device *dev, int phy_id, int location, |
| 1215 | int val) |
| 1216 | { |
| 1217 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1218 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1219 | rtl_writephy(tp, location, val); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | static int rtl_mdio_read(struct net_device *dev, int phy_id, int location) |
| 1223 | { |
| 1224 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1225 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1226 | return rtl_readphy(tp, location); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1227 | } |
| 1228 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1229 | DECLARE_RTL_COND(rtl_ephyar_cond) |
| 1230 | { |
| 1231 | void __iomem *ioaddr = tp->mmio_addr; |
| 1232 | |
| 1233 | return RTL_R32(EPHYAR) & EPHYAR_FLAG; |
| 1234 | } |
| 1235 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1236 | 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] | 1237 | { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1238 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1239 | |
| 1240 | RTL_W32(EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) | |
| 1241 | (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
| 1242 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1243 | rtl_udelay_loop_wait_low(tp, &rtl_ephyar_cond, 10, 100); |
| 1244 | |
| 1245 | udelay(10); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1246 | } |
| 1247 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1248 | static u16 rtl_ephy_read(struct rtl8169_private *tp, int reg_addr) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1249 | { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1250 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1251 | |
| 1252 | RTL_W32(EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
| 1253 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1254 | return rtl_udelay_loop_wait_high(tp, &rtl_ephyar_cond, 10, 100) ? |
| 1255 | RTL_R32(EPHYAR) & EPHYAR_DATA_MASK : ~0; |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1256 | } |
| 1257 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1258 | DECLARE_RTL_COND(rtl_eriar_cond) |
| 1259 | { |
| 1260 | void __iomem *ioaddr = tp->mmio_addr; |
| 1261 | |
| 1262 | return RTL_R32(ERIAR) & ERIAR_FLAG; |
| 1263 | } |
| 1264 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1265 | static void rtl_eri_write(struct rtl8169_private *tp, int addr, u32 mask, |
| 1266 | u32 val, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1267 | { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1268 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1269 | |
| 1270 | BUG_ON((addr & 3) || (mask == 0)); |
| 1271 | RTL_W32(ERIDR, val); |
| 1272 | RTL_W32(ERIAR, ERIAR_WRITE_CMD | type | mask | addr); |
| 1273 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1274 | rtl_udelay_loop_wait_low(tp, &rtl_eriar_cond, 100, 100); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1275 | } |
| 1276 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1277 | 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] | 1278 | { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1279 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1280 | |
| 1281 | RTL_W32(ERIAR, ERIAR_READ_CMD | type | ERIAR_MASK_1111 | addr); |
| 1282 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1283 | return rtl_udelay_loop_wait_high(tp, &rtl_eriar_cond, 100, 100) ? |
| 1284 | RTL_R32(ERIDR) : ~0; |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1285 | } |
| 1286 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1287 | 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] | 1288 | u32 m, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1289 | { |
| 1290 | u32 val; |
| 1291 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1292 | val = rtl_eri_read(tp, addr, type); |
| 1293 | rtl_eri_write(tp, addr, mask, (val & ~m) | p, type); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1294 | } |
| 1295 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1296 | static u32 r8168dp_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1297 | { |
| 1298 | void __iomem *ioaddr = tp->mmio_addr; |
| 1299 | |
| 1300 | RTL_W32(OCPAR, ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
| 1301 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 100, 20) ? |
| 1302 | RTL_R32(OCPDR) : ~0; |
| 1303 | } |
| 1304 | |
| 1305 | static u32 r8168ep_ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1306 | { |
| 1307 | return rtl_eri_read(tp, reg, ERIAR_OOB); |
| 1308 | } |
| 1309 | |
| 1310 | static u32 ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 1311 | { |
| 1312 | switch (tp->mac_version) { |
| 1313 | case RTL_GIGA_MAC_VER_27: |
| 1314 | case RTL_GIGA_MAC_VER_28: |
| 1315 | case RTL_GIGA_MAC_VER_31: |
| 1316 | return r8168dp_ocp_read(tp, mask, reg); |
| 1317 | case RTL_GIGA_MAC_VER_49: |
| 1318 | case RTL_GIGA_MAC_VER_50: |
| 1319 | case RTL_GIGA_MAC_VER_51: |
| 1320 | return r8168ep_ocp_read(tp, mask, reg); |
| 1321 | default: |
| 1322 | BUG(); |
| 1323 | return ~0; |
| 1324 | } |
| 1325 | } |
| 1326 | |
| 1327 | static void r8168dp_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, |
| 1328 | u32 data) |
| 1329 | { |
| 1330 | void __iomem *ioaddr = tp->mmio_addr; |
| 1331 | |
| 1332 | RTL_W32(OCPDR, data); |
| 1333 | RTL_W32(OCPAR, OCPAR_FLAG | ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
| 1334 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 100, 20); |
| 1335 | } |
| 1336 | |
| 1337 | static void r8168ep_ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, |
| 1338 | u32 data) |
| 1339 | { |
| 1340 | rtl_eri_write(tp, reg, ((u32)mask & 0x0f) << ERIAR_MASK_SHIFT, |
| 1341 | data, ERIAR_OOB); |
| 1342 | } |
| 1343 | |
| 1344 | static void ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, u32 data) |
| 1345 | { |
| 1346 | switch (tp->mac_version) { |
| 1347 | case RTL_GIGA_MAC_VER_27: |
| 1348 | case RTL_GIGA_MAC_VER_28: |
| 1349 | case RTL_GIGA_MAC_VER_31: |
| 1350 | r8168dp_ocp_write(tp, mask, reg, data); |
| 1351 | break; |
| 1352 | case RTL_GIGA_MAC_VER_49: |
| 1353 | case RTL_GIGA_MAC_VER_50: |
| 1354 | case RTL_GIGA_MAC_VER_51: |
| 1355 | r8168ep_ocp_write(tp, mask, reg, data); |
| 1356 | break; |
| 1357 | default: |
| 1358 | BUG(); |
| 1359 | break; |
| 1360 | } |
| 1361 | } |
| 1362 | |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1363 | static void rtl8168_oob_notify(struct rtl8169_private *tp, u8 cmd) |
| 1364 | { |
| 1365 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_0001, cmd, ERIAR_EXGMAC); |
| 1366 | |
| 1367 | ocp_write(tp, 0x1, 0x30, 0x00000001); |
| 1368 | } |
| 1369 | |
| 1370 | #define OOB_CMD_RESET 0x00 |
| 1371 | #define OOB_CMD_DRIVER_START 0x05 |
| 1372 | #define OOB_CMD_DRIVER_STOP 0x06 |
| 1373 | |
| 1374 | static u16 rtl8168_get_ocp_reg(struct rtl8169_private *tp) |
| 1375 | { |
| 1376 | return (tp->mac_version == RTL_GIGA_MAC_VER_31) ? 0xb8 : 0x10; |
| 1377 | } |
| 1378 | |
| 1379 | DECLARE_RTL_COND(rtl_ocp_read_cond) |
| 1380 | { |
| 1381 | u16 reg; |
| 1382 | |
| 1383 | reg = rtl8168_get_ocp_reg(tp); |
| 1384 | |
| 1385 | return ocp_read(tp, 0x0f, reg) & 0x00000800; |
| 1386 | } |
| 1387 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1388 | DECLARE_RTL_COND(rtl_ep_ocp_read_cond) |
| 1389 | { |
| 1390 | return ocp_read(tp, 0x0f, 0x124) & 0x00000001; |
| 1391 | } |
| 1392 | |
| 1393 | DECLARE_RTL_COND(rtl_ocp_tx_cond) |
| 1394 | { |
| 1395 | void __iomem *ioaddr = tp->mmio_addr; |
| 1396 | |
Chunhao Lin | 086ca23 | 2018-01-31 01:32:36 +0800 | [diff] [blame] | 1397 | return RTL_R8(IBISR0) & 0x20; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1398 | } |
| 1399 | |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1400 | static void rtl8168ep_stop_cmac(struct rtl8169_private *tp) |
| 1401 | { |
| 1402 | void __iomem *ioaddr = tp->mmio_addr; |
| 1403 | |
| 1404 | RTL_W8(IBCR2, RTL_R8(IBCR2) & ~0x01); |
Chunhao Lin | 086ca23 | 2018-01-31 01:32:36 +0800 | [diff] [blame] | 1405 | rtl_msleep_loop_wait_high(tp, &rtl_ocp_tx_cond, 50, 2000); |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1406 | RTL_W8(IBISR0, RTL_R8(IBISR0) | 0x20); |
| 1407 | RTL_W8(IBCR0, RTL_R8(IBCR0) & ~0x01); |
| 1408 | } |
| 1409 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1410 | static void rtl8168dp_driver_start(struct rtl8169_private *tp) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1411 | { |
| 1412 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_START); |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1413 | rtl_msleep_loop_wait_high(tp, &rtl_ocp_read_cond, 10, 10); |
| 1414 | } |
| 1415 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1416 | static void rtl8168ep_driver_start(struct rtl8169_private *tp) |
| 1417 | { |
| 1418 | ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_START); |
| 1419 | ocp_write(tp, 0x01, 0x30, ocp_read(tp, 0x01, 0x30) | 0x01); |
| 1420 | rtl_msleep_loop_wait_high(tp, &rtl_ep_ocp_read_cond, 10, 10); |
| 1421 | } |
| 1422 | |
| 1423 | static void rtl8168_driver_start(struct rtl8169_private *tp) |
| 1424 | { |
| 1425 | switch (tp->mac_version) { |
| 1426 | case RTL_GIGA_MAC_VER_27: |
| 1427 | case RTL_GIGA_MAC_VER_28: |
| 1428 | case RTL_GIGA_MAC_VER_31: |
| 1429 | rtl8168dp_driver_start(tp); |
| 1430 | break; |
| 1431 | case RTL_GIGA_MAC_VER_49: |
| 1432 | case RTL_GIGA_MAC_VER_50: |
| 1433 | case RTL_GIGA_MAC_VER_51: |
| 1434 | rtl8168ep_driver_start(tp); |
| 1435 | break; |
| 1436 | default: |
| 1437 | BUG(); |
| 1438 | break; |
| 1439 | } |
| 1440 | } |
| 1441 | |
| 1442 | static void rtl8168dp_driver_stop(struct rtl8169_private *tp) |
| 1443 | { |
| 1444 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_STOP); |
| 1445 | rtl_msleep_loop_wait_low(tp, &rtl_ocp_read_cond, 10, 10); |
| 1446 | } |
| 1447 | |
| 1448 | static void rtl8168ep_driver_stop(struct rtl8169_private *tp) |
| 1449 | { |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 1450 | rtl8168ep_stop_cmac(tp); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1451 | ocp_write(tp, 0x01, 0x180, OOB_CMD_DRIVER_STOP); |
| 1452 | ocp_write(tp, 0x01, 0x30, ocp_read(tp, 0x01, 0x30) | 0x01); |
| 1453 | rtl_msleep_loop_wait_low(tp, &rtl_ep_ocp_read_cond, 10, 10); |
| 1454 | } |
| 1455 | |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1456 | static void rtl8168_driver_stop(struct rtl8169_private *tp) |
| 1457 | { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1458 | switch (tp->mac_version) { |
| 1459 | case RTL_GIGA_MAC_VER_27: |
| 1460 | case RTL_GIGA_MAC_VER_28: |
| 1461 | case RTL_GIGA_MAC_VER_31: |
| 1462 | rtl8168dp_driver_stop(tp); |
| 1463 | break; |
| 1464 | case RTL_GIGA_MAC_VER_49: |
| 1465 | case RTL_GIGA_MAC_VER_50: |
| 1466 | case RTL_GIGA_MAC_VER_51: |
| 1467 | rtl8168ep_driver_stop(tp); |
| 1468 | break; |
| 1469 | default: |
| 1470 | BUG(); |
| 1471 | break; |
| 1472 | } |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1473 | } |
| 1474 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1475 | static int r8168dp_check_dash(struct rtl8169_private *tp) |
Chun-Hao Lin | 2a9b4d9 | 2014-10-01 23:17:20 +0800 | [diff] [blame] | 1476 | { |
| 1477 | u16 reg = rtl8168_get_ocp_reg(tp); |
| 1478 | |
| 1479 | return (ocp_read(tp, 0x0f, reg) & 0x00008000) ? 1 : 0; |
| 1480 | } |
| 1481 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1482 | static int r8168ep_check_dash(struct rtl8169_private *tp) |
| 1483 | { |
| 1484 | return (ocp_read(tp, 0x0f, 0x128) & 0x00000001) ? 1 : 0; |
| 1485 | } |
| 1486 | |
| 1487 | static int r8168_check_dash(struct rtl8169_private *tp) |
| 1488 | { |
| 1489 | switch (tp->mac_version) { |
| 1490 | case RTL_GIGA_MAC_VER_27: |
| 1491 | case RTL_GIGA_MAC_VER_28: |
| 1492 | case RTL_GIGA_MAC_VER_31: |
| 1493 | return r8168dp_check_dash(tp); |
| 1494 | case RTL_GIGA_MAC_VER_49: |
| 1495 | case RTL_GIGA_MAC_VER_50: |
| 1496 | case RTL_GIGA_MAC_VER_51: |
| 1497 | return r8168ep_check_dash(tp); |
| 1498 | default: |
| 1499 | return 0; |
| 1500 | } |
| 1501 | } |
| 1502 | |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1503 | struct exgmac_reg { |
| 1504 | u16 addr; |
| 1505 | u16 mask; |
| 1506 | u32 val; |
| 1507 | }; |
| 1508 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1509 | static void rtl_write_exgmac_batch(struct rtl8169_private *tp, |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1510 | const struct exgmac_reg *r, int len) |
| 1511 | { |
| 1512 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1513 | 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] | 1514 | r++; |
| 1515 | } |
| 1516 | } |
| 1517 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1518 | DECLARE_RTL_COND(rtl_efusear_cond) |
| 1519 | { |
| 1520 | void __iomem *ioaddr = tp->mmio_addr; |
| 1521 | |
| 1522 | return RTL_R32(EFUSEAR) & EFUSEAR_FLAG; |
| 1523 | } |
| 1524 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1525 | 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] | 1526 | { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1527 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1528 | |
| 1529 | RTL_W32(EFUSEAR, (reg_addr & EFUSEAR_REG_MASK) << EFUSEAR_REG_SHIFT); |
| 1530 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1531 | return rtl_udelay_loop_wait_high(tp, &rtl_efusear_cond, 100, 300) ? |
| 1532 | RTL_R32(EFUSEAR) & EFUSEAR_DATA_MASK : ~0; |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1533 | } |
| 1534 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1535 | static u16 rtl_get_events(struct rtl8169_private *tp) |
| 1536 | { |
| 1537 | void __iomem *ioaddr = tp->mmio_addr; |
| 1538 | |
| 1539 | return RTL_R16(IntrStatus); |
| 1540 | } |
| 1541 | |
| 1542 | static void rtl_ack_events(struct rtl8169_private *tp, u16 bits) |
| 1543 | { |
| 1544 | void __iomem *ioaddr = tp->mmio_addr; |
| 1545 | |
| 1546 | RTL_W16(IntrStatus, bits); |
| 1547 | mmiowb(); |
| 1548 | } |
| 1549 | |
| 1550 | static void rtl_irq_disable(struct rtl8169_private *tp) |
| 1551 | { |
| 1552 | void __iomem *ioaddr = tp->mmio_addr; |
| 1553 | |
| 1554 | RTL_W16(IntrMask, 0); |
| 1555 | mmiowb(); |
| 1556 | } |
| 1557 | |
Francois Romieu | 3e990ff | 2012-01-26 12:50:01 +0100 | [diff] [blame] | 1558 | static void rtl_irq_enable(struct rtl8169_private *tp, u16 bits) |
| 1559 | { |
| 1560 | void __iomem *ioaddr = tp->mmio_addr; |
| 1561 | |
| 1562 | RTL_W16(IntrMask, bits); |
| 1563 | } |
| 1564 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1565 | #define RTL_EVENT_NAPI_RX (RxOK | RxErr) |
| 1566 | #define RTL_EVENT_NAPI_TX (TxOK | TxErr) |
| 1567 | #define RTL_EVENT_NAPI (RTL_EVENT_NAPI_RX | RTL_EVENT_NAPI_TX) |
| 1568 | |
| 1569 | static void rtl_irq_enable_all(struct rtl8169_private *tp) |
| 1570 | { |
| 1571 | rtl_irq_enable(tp, RTL_EVENT_NAPI | tp->event_slow); |
| 1572 | } |
| 1573 | |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 1574 | static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | { |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 1576 | void __iomem *ioaddr = tp->mmio_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1578 | rtl_irq_disable(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1579 | rtl_ack_events(tp, RTL_EVENT_NAPI | tp->event_slow); |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 1580 | RTL_R8(ChipCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1581 | } |
| 1582 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1583 | static unsigned int rtl8169_tbi_reset_pending(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1584 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1585 | void __iomem *ioaddr = tp->mmio_addr; |
| 1586 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | return RTL_R32(TBICSR) & TBIReset; |
| 1588 | } |
| 1589 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1590 | static unsigned int rtl8169_xmii_reset_pending(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1591 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1592 | return rtl_readphy(tp, MII_BMCR) & BMCR_RESET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | } |
| 1594 | |
| 1595 | static unsigned int rtl8169_tbi_link_ok(void __iomem *ioaddr) |
| 1596 | { |
| 1597 | return RTL_R32(TBICSR) & TBILinkOk; |
| 1598 | } |
| 1599 | |
| 1600 | static unsigned int rtl8169_xmii_link_ok(void __iomem *ioaddr) |
| 1601 | { |
| 1602 | return RTL_R8(PHYstatus) & LinkStatus; |
| 1603 | } |
| 1604 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1605 | static void rtl8169_tbi_reset_enable(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1607 | void __iomem *ioaddr = tp->mmio_addr; |
| 1608 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1609 | RTL_W32(TBICSR, RTL_R32(TBICSR) | TBIReset); |
| 1610 | } |
| 1611 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1612 | static void rtl8169_xmii_reset_enable(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | { |
| 1614 | unsigned int val; |
| 1615 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1616 | val = rtl_readphy(tp, MII_BMCR) | BMCR_RESET; |
| 1617 | rtl_writephy(tp, MII_BMCR, val & 0xffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | } |
| 1619 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1620 | static void rtl_link_chg_patch(struct rtl8169_private *tp) |
| 1621 | { |
| 1622 | void __iomem *ioaddr = tp->mmio_addr; |
| 1623 | struct net_device *dev = tp->dev; |
| 1624 | |
| 1625 | if (!netif_running(dev)) |
| 1626 | return; |
| 1627 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 1628 | if (tp->mac_version == RTL_GIGA_MAC_VER_34 || |
| 1629 | tp->mac_version == RTL_GIGA_MAC_VER_38) { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1630 | if (RTL_R8(PHYstatus) & _1000bpsF) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1631 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011, |
| 1632 | ERIAR_EXGMAC); |
| 1633 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1634 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1635 | } else if (RTL_R8(PHYstatus) & _100bps) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1636 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1637 | ERIAR_EXGMAC); |
| 1638 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1639 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1640 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1641 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1642 | ERIAR_EXGMAC); |
| 1643 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f, |
| 1644 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1645 | } |
| 1646 | /* Reset packet filter */ |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1647 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1648 | ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1649 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1650 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1651 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 1652 | tp->mac_version == RTL_GIGA_MAC_VER_36) { |
| 1653 | if (RTL_R8(PHYstatus) & _1000bpsF) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1654 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011, |
| 1655 | ERIAR_EXGMAC); |
| 1656 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1657 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1658 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1659 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1660 | ERIAR_EXGMAC); |
| 1661 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f, |
| 1662 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1663 | } |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1664 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_37) { |
| 1665 | if (RTL_R8(PHYstatus) & _10bps) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1666 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x4d02, |
| 1667 | ERIAR_EXGMAC); |
| 1668 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_0011, 0x0060, |
| 1669 | ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1670 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1671 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, |
| 1672 | ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1673 | } |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1674 | } |
| 1675 | } |
| 1676 | |
Heiner Kallweit | ef4d5fc | 2018-01-08 21:39:07 +0100 | [diff] [blame] | 1677 | static void rtl8169_check_link_status(struct net_device *dev, |
| 1678 | struct rtl8169_private *tp, |
| 1679 | void __iomem *ioaddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1681 | if (tp->link_ok(ioaddr)) { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1682 | rtl_link_chg_patch(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1683 | /* This is to cancel a scheduled suspend if there's one. */ |
Heiner Kallweit | ef4d5fc | 2018-01-08 21:39:07 +0100 | [diff] [blame] | 1684 | pm_request_resume(&tp->pci_dev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | netif_carrier_on(dev); |
Francois Romieu | 1519e57 | 2011-02-03 12:02:36 +0100 | [diff] [blame] | 1686 | if (net_ratelimit()) |
| 1687 | netif_info(tp, ifup, dev, "link up\n"); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1688 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1689 | netif_carrier_off(dev); |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1690 | netif_info(tp, ifdown, dev, "link down\n"); |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 1691 | pm_runtime_idle(&tp->pci_dev->dev); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1692 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | } |
| 1694 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1695 | #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST) |
| 1696 | |
| 1697 | static u32 __rtl8169_get_wol(struct rtl8169_private *tp) |
| 1698 | { |
| 1699 | void __iomem *ioaddr = tp->mmio_addr; |
| 1700 | u8 options; |
| 1701 | u32 wolopts = 0; |
| 1702 | |
| 1703 | options = RTL_R8(Config1); |
| 1704 | if (!(options & PMEnable)) |
| 1705 | return 0; |
| 1706 | |
| 1707 | options = RTL_R8(Config3); |
| 1708 | if (options & LinkUp) |
| 1709 | wolopts |= WAKE_PHY; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1710 | switch (tp->mac_version) { |
Chun-Hao Lin | ac85bcd | 2014-10-01 23:17:16 +0800 | [diff] [blame] | 1711 | case RTL_GIGA_MAC_VER_34: |
| 1712 | case RTL_GIGA_MAC_VER_35: |
| 1713 | case RTL_GIGA_MAC_VER_36: |
| 1714 | case RTL_GIGA_MAC_VER_37: |
| 1715 | case RTL_GIGA_MAC_VER_38: |
| 1716 | case RTL_GIGA_MAC_VER_40: |
| 1717 | case RTL_GIGA_MAC_VER_41: |
| 1718 | case RTL_GIGA_MAC_VER_42: |
| 1719 | case RTL_GIGA_MAC_VER_43: |
| 1720 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1721 | case RTL_GIGA_MAC_VER_45: |
| 1722 | case RTL_GIGA_MAC_VER_46: |
Chun-Hao Lin | ac85bcd | 2014-10-01 23:17:16 +0800 | [diff] [blame] | 1723 | case RTL_GIGA_MAC_VER_47: |
| 1724 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1725 | case RTL_GIGA_MAC_VER_49: |
| 1726 | case RTL_GIGA_MAC_VER_50: |
| 1727 | case RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1728 | if (rtl_eri_read(tp, 0xdc, ERIAR_EXGMAC) & MagicPacket_v2) |
| 1729 | wolopts |= WAKE_MAGIC; |
| 1730 | break; |
| 1731 | default: |
| 1732 | if (options & MagicPacket) |
| 1733 | wolopts |= WAKE_MAGIC; |
| 1734 | break; |
| 1735 | } |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1736 | |
| 1737 | options = RTL_R8(Config5); |
| 1738 | if (options & UWF) |
| 1739 | wolopts |= WAKE_UCAST; |
| 1740 | if (options & BWF) |
| 1741 | wolopts |= WAKE_BCAST; |
| 1742 | if (options & MWF) |
| 1743 | wolopts |= WAKE_MCAST; |
| 1744 | |
| 1745 | return wolopts; |
| 1746 | } |
| 1747 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1748 | static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1749 | { |
| 1750 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1751 | struct device *d = &tp->pci_dev->dev; |
| 1752 | |
| 1753 | pm_runtime_get_noresume(d); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1754 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1755 | rtl_lock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1756 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1757 | wol->supported = WAKE_ANY; |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1758 | if (pm_runtime_active(d)) |
| 1759 | wol->wolopts = __rtl8169_get_wol(tp); |
| 1760 | else |
| 1761 | wol->wolopts = tp->saved_wolopts; |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1762 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1763 | rtl_unlock_work(tp); |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1764 | |
| 1765 | pm_runtime_put_noidle(d); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1766 | } |
| 1767 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1768 | static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1769 | { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1770 | void __iomem *ioaddr = tp->mmio_addr; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1771 | unsigned int i, tmp; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 1772 | static const struct { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1773 | u32 opt; |
| 1774 | u16 reg; |
| 1775 | u8 mask; |
| 1776 | } cfg[] = { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1777 | { WAKE_PHY, Config3, LinkUp }, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1778 | { WAKE_UCAST, Config5, UWF }, |
| 1779 | { WAKE_BCAST, Config5, BWF }, |
| 1780 | { WAKE_MCAST, Config5, MWF }, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1781 | { WAKE_ANY, Config5, LanWake }, |
| 1782 | { WAKE_MAGIC, Config3, MagicPacket } |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1783 | }; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1784 | u8 options; |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1785 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1786 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 1787 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1788 | switch (tp->mac_version) { |
Chun-Hao Lin | ac85bcd | 2014-10-01 23:17:16 +0800 | [diff] [blame] | 1789 | case RTL_GIGA_MAC_VER_34: |
| 1790 | case RTL_GIGA_MAC_VER_35: |
| 1791 | case RTL_GIGA_MAC_VER_36: |
| 1792 | case RTL_GIGA_MAC_VER_37: |
| 1793 | case RTL_GIGA_MAC_VER_38: |
| 1794 | case RTL_GIGA_MAC_VER_40: |
| 1795 | case RTL_GIGA_MAC_VER_41: |
| 1796 | case RTL_GIGA_MAC_VER_42: |
| 1797 | case RTL_GIGA_MAC_VER_43: |
| 1798 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1799 | case RTL_GIGA_MAC_VER_45: |
| 1800 | case RTL_GIGA_MAC_VER_46: |
Chun-Hao Lin | ac85bcd | 2014-10-01 23:17:16 +0800 | [diff] [blame] | 1801 | case RTL_GIGA_MAC_VER_47: |
| 1802 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 1803 | case RTL_GIGA_MAC_VER_49: |
| 1804 | case RTL_GIGA_MAC_VER_50: |
| 1805 | case RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1806 | tmp = ARRAY_SIZE(cfg) - 1; |
| 1807 | if (wolopts & WAKE_MAGIC) |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1808 | rtl_w0w1_eri(tp, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1809 | 0x0dc, |
| 1810 | ERIAR_MASK_0100, |
| 1811 | MagicPacket_v2, |
| 1812 | 0x0000, |
| 1813 | ERIAR_EXGMAC); |
| 1814 | else |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 1815 | rtl_w0w1_eri(tp, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1816 | 0x0dc, |
| 1817 | ERIAR_MASK_0100, |
| 1818 | 0x0000, |
| 1819 | MagicPacket_v2, |
| 1820 | ERIAR_EXGMAC); |
| 1821 | break; |
| 1822 | default: |
| 1823 | tmp = ARRAY_SIZE(cfg); |
| 1824 | break; |
| 1825 | } |
| 1826 | |
| 1827 | for (i = 0; i < tmp; i++) { |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1828 | options = RTL_R8(cfg[i].reg) & ~cfg[i].mask; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1829 | if (wolopts & cfg[i].opt) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1830 | options |= cfg[i].mask; |
| 1831 | RTL_W8(cfg[i].reg, options); |
| 1832 | } |
| 1833 | |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1834 | switch (tp->mac_version) { |
| 1835 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_17: |
| 1836 | options = RTL_R8(Config1) & ~PMEnable; |
| 1837 | if (wolopts) |
| 1838 | options |= PMEnable; |
| 1839 | RTL_W8(Config1, options); |
| 1840 | break; |
| 1841 | default: |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 1842 | options = RTL_R8(Config2) & ~PME_SIGNAL; |
| 1843 | if (wolopts) |
| 1844 | options |= PME_SIGNAL; |
| 1845 | RTL_W8(Config2, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1846 | break; |
| 1847 | } |
| 1848 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1849 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1850 | } |
| 1851 | |
| 1852 | static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1853 | { |
| 1854 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1855 | struct device *d = &tp->pci_dev->dev; |
| 1856 | |
| 1857 | pm_runtime_get_noresume(d); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1858 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1859 | rtl_lock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1860 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1861 | if (pm_runtime_active(d)) |
| 1862 | __rtl8169_set_wol(tp, wol->wolopts); |
| 1863 | else |
| 1864 | tp->saved_wolopts = wol->wolopts; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1865 | |
| 1866 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1867 | |
françois romieu | ea80907 | 2010-11-08 13:23:58 +0000 | [diff] [blame] | 1868 | device_set_wakeup_enable(&tp->pci_dev->dev, wol->wolopts); |
| 1869 | |
Chun-Hao Lin | 5fa80a3 | 2016-07-29 16:37:54 +0800 | [diff] [blame] | 1870 | pm_runtime_put_noidle(d); |
| 1871 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1872 | return 0; |
| 1873 | } |
| 1874 | |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1875 | static const char *rtl_lookup_firmware_name(struct rtl8169_private *tp) |
| 1876 | { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 1877 | return rtl_chip_infos[tp->mac_version].fw_name; |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1878 | } |
| 1879 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1880 | static void rtl8169_get_drvinfo(struct net_device *dev, |
| 1881 | struct ethtool_drvinfo *info) |
| 1882 | { |
| 1883 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 1884 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 1886 | strlcpy(info->driver, MODULENAME, sizeof(info->driver)); |
| 1887 | strlcpy(info->version, RTL8169_VERSION, sizeof(info->version)); |
| 1888 | 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] | 1889 | BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version)); |
Rick Jones | 8ac72d1 | 2011-11-22 14:06:26 +0000 | [diff] [blame] | 1890 | if (!IS_ERR_OR_NULL(rtl_fw)) |
| 1891 | strlcpy(info->fw_version, rtl_fw->version, |
| 1892 | sizeof(info->fw_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1893 | } |
| 1894 | |
| 1895 | static int rtl8169_get_regs_len(struct net_device *dev) |
| 1896 | { |
| 1897 | return R8169_REGS_SIZE; |
| 1898 | } |
| 1899 | |
| 1900 | static int rtl8169_set_speed_tbi(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1901 | u8 autoneg, u16 speed, u8 duplex, u32 ignored) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | { |
| 1903 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1904 | void __iomem *ioaddr = tp->mmio_addr; |
| 1905 | int ret = 0; |
| 1906 | u32 reg; |
| 1907 | |
| 1908 | reg = RTL_R32(TBICSR); |
| 1909 | if ((autoneg == AUTONEG_DISABLE) && (speed == SPEED_1000) && |
| 1910 | (duplex == DUPLEX_FULL)) { |
| 1911 | RTL_W32(TBICSR, reg & ~(TBINwEnable | TBINwRestart)); |
| 1912 | } else if (autoneg == AUTONEG_ENABLE) |
| 1913 | RTL_W32(TBICSR, reg | TBINwEnable | TBINwRestart); |
| 1914 | else { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1915 | netif_warn(tp, link, dev, |
| 1916 | "incorrect speed setting refused in TBI mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | ret = -EOPNOTSUPP; |
| 1918 | } |
| 1919 | |
| 1920 | return ret; |
| 1921 | } |
| 1922 | |
| 1923 | static int rtl8169_set_speed_xmii(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1924 | u8 autoneg, u16 speed, u8 duplex, u32 adv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1925 | { |
| 1926 | struct rtl8169_private *tp = netdev_priv(dev); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1927 | int giga_ctrl, bmcr; |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1928 | int rc = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | |
Hayes Wang | 716b50a | 2011-02-22 17:26:18 +0800 | [diff] [blame] | 1930 | rtl_writephy(tp, 0x1f, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | |
| 1932 | if (autoneg == AUTONEG_ENABLE) { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1933 | int auto_nego; |
| 1934 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1935 | auto_nego = rtl_readphy(tp, MII_ADVERTISE); |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1936 | auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL | |
| 1937 | ADVERTISE_100HALF | ADVERTISE_100FULL); |
| 1938 | |
| 1939 | if (adv & ADVERTISED_10baseT_Half) |
| 1940 | auto_nego |= ADVERTISE_10HALF; |
| 1941 | if (adv & ADVERTISED_10baseT_Full) |
| 1942 | auto_nego |= ADVERTISE_10FULL; |
| 1943 | if (adv & ADVERTISED_100baseT_Half) |
| 1944 | auto_nego |= ADVERTISE_100HALF; |
| 1945 | if (adv & ADVERTISED_100baseT_Full) |
| 1946 | auto_nego |= ADVERTISE_100FULL; |
| 1947 | |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1948 | auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 1949 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1950 | giga_ctrl = rtl_readphy(tp, MII_CTRL1000); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1951 | giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); |
| 1952 | |
| 1953 | /* The 8100e/8101e/8102e do Fast Ethernet only. */ |
Francois Romieu | 826e6cb | 2011-03-11 20:30:24 +0100 | [diff] [blame] | 1954 | if (tp->mii.supports_gmii) { |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1955 | if (adv & ADVERTISED_1000baseT_Half) |
| 1956 | giga_ctrl |= ADVERTISE_1000HALF; |
| 1957 | if (adv & ADVERTISED_1000baseT_Full) |
| 1958 | giga_ctrl |= ADVERTISE_1000FULL; |
| 1959 | } else if (adv & (ADVERTISED_1000baseT_Half | |
| 1960 | ADVERTISED_1000baseT_Full)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1961 | netif_info(tp, link, dev, |
| 1962 | "PHY does not support 1000Mbps\n"); |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1963 | goto out; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 1964 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1966 | bmcr = BMCR_ANENABLE | BMCR_ANRESTART; |
Francois Romieu | 623a159 | 2006-05-14 12:42:14 +0200 | [diff] [blame] | 1967 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1968 | rtl_writephy(tp, MII_ADVERTISE, auto_nego); |
| 1969 | rtl_writephy(tp, MII_CTRL1000, giga_ctrl); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1970 | } else { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1971 | if (speed == SPEED_10) |
| 1972 | bmcr = 0; |
| 1973 | else if (speed == SPEED_100) |
| 1974 | bmcr = BMCR_SPEED100; |
| 1975 | else |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1976 | goto out; |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1977 | |
| 1978 | if (duplex == DUPLEX_FULL) |
| 1979 | bmcr |= BMCR_FULLDPLX; |
Roger So | 2584fbc | 2007-07-31 23:52:42 +0200 | [diff] [blame] | 1980 | } |
| 1981 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1982 | rtl_writephy(tp, MII_BMCR, bmcr); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1983 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1984 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 1985 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1986 | if ((speed == SPEED_100) && (autoneg != AUTONEG_ENABLE)) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1987 | rtl_writephy(tp, 0x17, 0x2138); |
| 1988 | rtl_writephy(tp, 0x0e, 0x0260); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1989 | } else { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1990 | rtl_writephy(tp, 0x17, 0x2108); |
| 1991 | rtl_writephy(tp, 0x0e, 0x0000); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1992 | } |
| 1993 | } |
| 1994 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1995 | rc = 0; |
| 1996 | out: |
| 1997 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1998 | } |
| 1999 | |
| 2000 | static int rtl8169_set_speed(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 2001 | u8 autoneg, u16 speed, u8 duplex, u32 advertising) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | { |
| 2003 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2004 | int ret; |
| 2005 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 2006 | ret = tp->set_speed(dev, autoneg, speed, duplex, advertising); |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 2007 | if (ret < 0) |
| 2008 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2009 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 2010 | if (netif_running(dev) && (autoneg == AUTONEG_ENABLE) && |
Chun-Hao Lin | c455697 | 2016-03-11 14:21:14 +0800 | [diff] [blame] | 2011 | (advertising & ADVERTISED_1000baseT_Full) && |
| 2012 | !pci_is_pcie(tp->pci_dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2013 | mod_timer(&tp->timer, jiffies + RTL8169_PHY_TIMEOUT); |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 2014 | } |
| 2015 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2016 | return ret; |
| 2017 | } |
| 2018 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 2019 | static netdev_features_t rtl8169_fix_features(struct net_device *dev, |
| 2020 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2021 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 2022 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2023 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 2024 | if (dev->mtu > TD_MSS_MAX) |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 2025 | features &= ~NETIF_F_ALL_TSO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2026 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 2027 | if (dev->mtu > JUMBO_1K && |
| 2028 | !rtl_chip_infos[tp->mac_version].jumbo_tx_csum) |
| 2029 | features &= ~NETIF_F_IP_CSUM; |
| 2030 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 2031 | return features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2032 | } |
| 2033 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2034 | static void __rtl8169_set_features(struct net_device *dev, |
| 2035 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2036 | { |
| 2037 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2038 | void __iomem *ioaddr = tp->mmio_addr; |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 2039 | u32 rx_config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2040 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 2041 | rx_config = RTL_R32(RxConfig); |
| 2042 | if (features & NETIF_F_RXALL) |
| 2043 | rx_config |= (AcceptErr | AcceptRunt); |
| 2044 | else |
| 2045 | rx_config &= ~(AcceptErr | AcceptRunt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 2047 | RTL_W32(RxConfig, rx_config); |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 2048 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 2049 | if (features & NETIF_F_RXCSUM) |
| 2050 | tp->cp_cmd |= RxChkSum; |
| 2051 | else |
| 2052 | tp->cp_cmd &= ~RxChkSum; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 2053 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 2054 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 2055 | tp->cp_cmd |= RxVlan; |
| 2056 | else |
| 2057 | tp->cp_cmd &= ~RxVlan; |
| 2058 | |
| 2059 | tp->cp_cmd |= RTL_R16(CPlusCmd) & ~(RxVlan | RxChkSum); |
| 2060 | |
| 2061 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 2062 | RTL_R16(CPlusCmd); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2063 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2065 | static int rtl8169_set_features(struct net_device *dev, |
| 2066 | netdev_features_t features) |
| 2067 | { |
| 2068 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2069 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 2070 | features &= NETIF_F_RXALL | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_RX; |
| 2071 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2072 | rtl_lock_work(tp); |
Dan Carpenter | 85911d7 | 2014-09-19 13:40:25 +0300 | [diff] [blame] | 2073 | if (features ^ dev->features) |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 2074 | __rtl8169_set_features(dev, features); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2075 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2076 | |
| 2077 | return 0; |
| 2078 | } |
| 2079 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2080 | |
Kirill Smelkov | 810f489 | 2012-11-10 21:11:02 +0400 | [diff] [blame] | 2081 | static inline u32 rtl8169_tx_vlan_tag(struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2082 | { |
Jiri Pirko | df8a39d | 2015-01-13 17:13:44 +0100 | [diff] [blame] | 2083 | return (skb_vlan_tag_present(skb)) ? |
| 2084 | TxVlanTag | swab16(skb_vlan_tag_get(skb)) : 0x00; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | } |
| 2086 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 2087 | 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] | 2088 | { |
| 2089 | u32 opts2 = le32_to_cpu(desc->opts2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2090 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 2091 | if (opts2 & RxVlanTag) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 2092 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), swab16(opts2 & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2093 | } |
| 2094 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2095 | static int rtl8169_get_link_ksettings_tbi(struct net_device *dev, |
| 2096 | struct ethtool_link_ksettings *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2097 | { |
| 2098 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2099 | void __iomem *ioaddr = tp->mmio_addr; |
| 2100 | u32 status; |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2101 | u32 supported, advertising; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2103 | supported = |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2104 | SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE; |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2105 | cmd->base.port = PORT_FIBRE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2106 | |
| 2107 | status = RTL_R32(TBICSR); |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2108 | advertising = (status & TBINwEnable) ? ADVERTISED_Autoneg : 0; |
| 2109 | cmd->base.autoneg = !!(status & TBINwEnable); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2110 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2111 | cmd->base.speed = SPEED_1000; |
| 2112 | cmd->base.duplex = DUPLEX_FULL; /* Always set */ |
| 2113 | |
| 2114 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.supported, |
| 2115 | supported); |
| 2116 | ethtool_convert_legacy_u32_to_link_mode(cmd->link_modes.advertising, |
| 2117 | advertising); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 2118 | |
| 2119 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2120 | } |
| 2121 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2122 | static int rtl8169_get_link_ksettings_xmii(struct net_device *dev, |
| 2123 | struct ethtool_link_ksettings *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | { |
| 2125 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2126 | |
yuval.shaia@oracle.com | 82c01a8 | 2017-06-04 20:22:00 +0300 | [diff] [blame] | 2127 | mii_ethtool_get_link_ksettings(&tp->mii, cmd); |
| 2128 | |
| 2129 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2130 | } |
| 2131 | |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2132 | static int rtl8169_get_link_ksettings(struct net_device *dev, |
| 2133 | struct ethtool_link_ksettings *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | { |
| 2135 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 2136 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2138 | rtl_lock_work(tp); |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2139 | rc = tp->get_link_ksettings(dev, cmd); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2140 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2141 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 2142 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2143 | } |
| 2144 | |
Tobias Jakobi | 9e77d7a | 2017-11-21 16:15:57 +0100 | [diff] [blame] | 2145 | static int rtl8169_set_link_ksettings(struct net_device *dev, |
| 2146 | const struct ethtool_link_ksettings *cmd) |
| 2147 | { |
| 2148 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2149 | int rc; |
| 2150 | u32 advertising; |
| 2151 | |
| 2152 | if (!ethtool_convert_link_mode_to_legacy_u32(&advertising, |
| 2153 | cmd->link_modes.advertising)) |
| 2154 | return -EINVAL; |
| 2155 | |
| 2156 | del_timer_sync(&tp->timer); |
| 2157 | |
| 2158 | rtl_lock_work(tp); |
| 2159 | rc = rtl8169_set_speed(dev, cmd->base.autoneg, cmd->base.speed, |
| 2160 | cmd->base.duplex, advertising); |
| 2161 | rtl_unlock_work(tp); |
| 2162 | |
| 2163 | return rc; |
| 2164 | } |
| 2165 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 2167 | void *p) |
| 2168 | { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 2169 | struct rtl8169_private *tp = netdev_priv(dev); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 2170 | u32 __iomem *data = tp->mmio_addr; |
| 2171 | u32 *dw = p; |
| 2172 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2173 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2174 | rtl_lock_work(tp); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 2175 | for (i = 0; i < R8169_REGS_SIZE; i += 4) |
| 2176 | memcpy_fromio(dw++, data++, 4); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 2177 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2178 | } |
| 2179 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 2180 | static u32 rtl8169_get_msglevel(struct net_device *dev) |
| 2181 | { |
| 2182 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2183 | |
| 2184 | return tp->msg_enable; |
| 2185 | } |
| 2186 | |
| 2187 | static void rtl8169_set_msglevel(struct net_device *dev, u32 value) |
| 2188 | { |
| 2189 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2190 | |
| 2191 | tp->msg_enable = value; |
| 2192 | } |
| 2193 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2194 | static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = { |
| 2195 | "tx_packets", |
| 2196 | "rx_packets", |
| 2197 | "tx_errors", |
| 2198 | "rx_errors", |
| 2199 | "rx_missed", |
| 2200 | "align_errors", |
| 2201 | "tx_single_collisions", |
| 2202 | "tx_multi_collisions", |
| 2203 | "unicast", |
| 2204 | "broadcast", |
| 2205 | "multicast", |
| 2206 | "tx_aborted", |
| 2207 | "tx_underrun", |
| 2208 | }; |
| 2209 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2210 | static int rtl8169_get_sset_count(struct net_device *dev, int sset) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2211 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2212 | switch (sset) { |
| 2213 | case ETH_SS_STATS: |
| 2214 | return ARRAY_SIZE(rtl8169_gstrings); |
| 2215 | default: |
| 2216 | return -EOPNOTSUPP; |
| 2217 | } |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2218 | } |
| 2219 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2220 | DECLARE_RTL_COND(rtl_counters_cond) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2221 | { |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2222 | void __iomem *ioaddr = tp->mmio_addr; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2223 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2224 | return RTL_R32(CounterAddrLow) & (CounterReset | CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2225 | } |
| 2226 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2227 | static bool rtl8169_do_counters(struct net_device *dev, u32 counter_cmd) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2228 | { |
| 2229 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2230 | void __iomem *ioaddr = tp->mmio_addr; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2231 | dma_addr_t paddr = tp->counters_phys_addr; |
| 2232 | u32 cmd; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2233 | |
| 2234 | RTL_W32(CounterAddrHigh, (u64)paddr >> 32); |
Francois Romieu | a78e936 | 2018-01-26 01:53:26 +0100 | [diff] [blame] | 2235 | RTL_R32(CounterAddrHigh); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2236 | cmd = (u64)paddr & DMA_BIT_MASK(32); |
| 2237 | RTL_W32(CounterAddrLow, cmd); |
| 2238 | RTL_W32(CounterAddrLow, cmd | counter_cmd); |
| 2239 | |
Francois Romieu | a78e936 | 2018-01-26 01:53:26 +0100 | [diff] [blame] | 2240 | return rtl_udelay_loop_wait_low(tp, &rtl_counters_cond, 10, 1000); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2241 | } |
| 2242 | |
| 2243 | static bool rtl8169_reset_counters(struct net_device *dev) |
| 2244 | { |
| 2245 | struct rtl8169_private *tp = netdev_priv(dev); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2246 | |
| 2247 | /* |
| 2248 | * Versions prior to RTL_GIGA_MAC_VER_19 don't support resetting the |
| 2249 | * tally counters. |
| 2250 | */ |
| 2251 | if (tp->mac_version < RTL_GIGA_MAC_VER_19) |
| 2252 | return true; |
| 2253 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2254 | return rtl8169_do_counters(dev, CounterReset); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 2255 | } |
| 2256 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2257 | static bool rtl8169_update_counters(struct net_device *dev) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2258 | { |
| 2259 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2260 | void __iomem *ioaddr = tp->mmio_addr; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2261 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2262 | /* |
| 2263 | * Some chips are unable to dump tally counters when the receiver |
| 2264 | * is disabled. |
| 2265 | */ |
| 2266 | if ((RTL_R8(ChipCmd) & CmdRxEnb) == 0) |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2267 | return true; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2268 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2269 | return rtl8169_do_counters(dev, CounterDump); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2270 | } |
| 2271 | |
| 2272 | static bool rtl8169_init_counter_offsets(struct net_device *dev) |
| 2273 | { |
| 2274 | struct rtl8169_private *tp = netdev_priv(dev); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2275 | struct rtl8169_counters *counters = tp->counters; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2276 | bool ret = false; |
| 2277 | |
| 2278 | /* |
| 2279 | * rtl8169_init_counter_offsets is called from rtl_open. On chip |
| 2280 | * versions prior to RTL_GIGA_MAC_VER_19 the tally counters are only |
| 2281 | * reset by a power cycle, while the counter values collected by the |
| 2282 | * driver are reset at every driver unload/load cycle. |
| 2283 | * |
| 2284 | * To make sure the HW values returned by @get_stats64 match the SW |
| 2285 | * values, we collect the initial values at first open(*) and use them |
| 2286 | * as offsets to normalize the values returned by @get_stats64. |
| 2287 | * |
| 2288 | * (*) We can't call rtl8169_init_counter_offsets from rtl_init_one |
| 2289 | * for the reason stated in rtl8169_update_counters; CmdRxEnb is only |
| 2290 | * set at open time by rtl_hw_start. |
| 2291 | */ |
| 2292 | |
| 2293 | if (tp->tc_offset.inited) |
| 2294 | return true; |
| 2295 | |
| 2296 | /* If both, reset and update fail, propagate to caller. */ |
| 2297 | if (rtl8169_reset_counters(dev)) |
| 2298 | ret = true; |
| 2299 | |
| 2300 | if (rtl8169_update_counters(dev)) |
| 2301 | ret = true; |
| 2302 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2303 | tp->tc_offset.tx_errors = counters->tx_errors; |
| 2304 | tp->tc_offset.tx_multi_collision = counters->tx_multi_collision; |
| 2305 | tp->tc_offset.tx_aborted = counters->tx_aborted; |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 2306 | tp->tc_offset.inited = true; |
| 2307 | |
| 2308 | return ret; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2309 | } |
| 2310 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2311 | static void rtl8169_get_ethtool_stats(struct net_device *dev, |
| 2312 | struct ethtool_stats *stats, u64 *data) |
| 2313 | { |
| 2314 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 2315 | struct device *d = &tp->pci_dev->dev; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2316 | struct rtl8169_counters *counters = tp->counters; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2317 | |
| 2318 | ASSERT_RTNL(); |
| 2319 | |
Chun-Hao Lin | e063623 | 2016-07-29 16:37:55 +0800 | [diff] [blame] | 2320 | pm_runtime_get_noresume(d); |
| 2321 | |
| 2322 | if (pm_runtime_active(d)) |
| 2323 | rtl8169_update_counters(dev); |
| 2324 | |
| 2325 | pm_runtime_put_noidle(d); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2326 | |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 2327 | data[0] = le64_to_cpu(counters->tx_packets); |
| 2328 | data[1] = le64_to_cpu(counters->rx_packets); |
| 2329 | data[2] = le64_to_cpu(counters->tx_errors); |
| 2330 | data[3] = le32_to_cpu(counters->rx_errors); |
| 2331 | data[4] = le16_to_cpu(counters->rx_missed); |
| 2332 | data[5] = le16_to_cpu(counters->align_errors); |
| 2333 | data[6] = le32_to_cpu(counters->tx_one_collision); |
| 2334 | data[7] = le32_to_cpu(counters->tx_multi_collision); |
| 2335 | data[8] = le64_to_cpu(counters->rx_unicast); |
| 2336 | data[9] = le64_to_cpu(counters->rx_broadcast); |
| 2337 | data[10] = le32_to_cpu(counters->rx_multicast); |
| 2338 | data[11] = le16_to_cpu(counters->tx_aborted); |
| 2339 | data[12] = le16_to_cpu(counters->tx_underun); |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2340 | } |
| 2341 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2342 | static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 2343 | { |
| 2344 | switch(stringset) { |
| 2345 | case ETH_SS_STATS: |
| 2346 | memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings)); |
| 2347 | break; |
| 2348 | } |
| 2349 | } |
| 2350 | |
Florian Fainelli | f0903ea | 2016-12-03 12:01:19 -0800 | [diff] [blame] | 2351 | static int rtl8169_nway_reset(struct net_device *dev) |
| 2352 | { |
| 2353 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2354 | |
| 2355 | return mii_nway_restart(&tp->mii); |
| 2356 | } |
| 2357 | |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2358 | /* |
| 2359 | * Interrupt coalescing |
| 2360 | * |
| 2361 | * > 1 - the availability of the IntrMitigate (0xe2) register through the |
| 2362 | * > 8169, 8168 and 810x line of chipsets |
| 2363 | * |
| 2364 | * 8169, 8168, and 8136(810x) serial chipsets support it. |
| 2365 | * |
| 2366 | * > 2 - the Tx timer unit at gigabit speed |
| 2367 | * |
| 2368 | * The unit of the timer depends on both the speed and the setting of CPlusCmd |
| 2369 | * (0xe0) bit 1 and bit 0. |
| 2370 | * |
| 2371 | * For 8169 |
| 2372 | * bit[1:0] \ speed 1000M 100M 10M |
| 2373 | * 0 0 320ns 2.56us 40.96us |
| 2374 | * 0 1 2.56us 20.48us 327.7us |
| 2375 | * 1 0 5.12us 40.96us 655.4us |
| 2376 | * 1 1 10.24us 81.92us 1.31ms |
| 2377 | * |
| 2378 | * For the other |
| 2379 | * bit[1:0] \ speed 1000M 100M 10M |
| 2380 | * 0 0 5us 2.56us 40.96us |
| 2381 | * 0 1 40us 20.48us 327.7us |
| 2382 | * 1 0 80us 40.96us 655.4us |
| 2383 | * 1 1 160us 81.92us 1.31ms |
| 2384 | */ |
| 2385 | |
| 2386 | /* rx/tx scale factors for one particular CPlusCmd[0:1] value */ |
| 2387 | struct rtl_coalesce_scale { |
| 2388 | /* Rx / Tx */ |
| 2389 | u32 nsecs[2]; |
| 2390 | }; |
| 2391 | |
| 2392 | /* rx/tx scale factors for all CPlusCmd[0:1] cases */ |
| 2393 | struct rtl_coalesce_info { |
| 2394 | u32 speed; |
| 2395 | struct rtl_coalesce_scale scalev[4]; /* each CPlusCmd[0:1] case */ |
| 2396 | }; |
| 2397 | |
| 2398 | /* produce (r,t) pairs with each being in series of *1, *8, *8*2, *8*2*2 */ |
| 2399 | #define rxtx_x1822(r, t) { \ |
| 2400 | {{(r), (t)}}, \ |
| 2401 | {{(r)*8, (t)*8}}, \ |
| 2402 | {{(r)*8*2, (t)*8*2}}, \ |
| 2403 | {{(r)*8*2*2, (t)*8*2*2}}, \ |
| 2404 | } |
| 2405 | static const struct rtl_coalesce_info rtl_coalesce_info_8169[] = { |
| 2406 | /* speed delays: rx00 tx00 */ |
| 2407 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 2408 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 2409 | { SPEED_1000, rxtx_x1822( 320, 320) }, |
| 2410 | { 0 }, |
| 2411 | }; |
| 2412 | |
| 2413 | static const struct rtl_coalesce_info rtl_coalesce_info_8168_8136[] = { |
| 2414 | /* speed delays: rx00 tx00 */ |
| 2415 | { SPEED_10, rxtx_x1822(40960, 40960) }, |
| 2416 | { SPEED_100, rxtx_x1822( 2560, 2560) }, |
| 2417 | { SPEED_1000, rxtx_x1822( 5000, 5000) }, |
| 2418 | { 0 }, |
| 2419 | }; |
| 2420 | #undef rxtx_x1822 |
| 2421 | |
| 2422 | /* get rx/tx scale vector corresponding to current speed */ |
| 2423 | static const struct rtl_coalesce_info *rtl_coalesce_info(struct net_device *dev) |
| 2424 | { |
| 2425 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2426 | struct ethtool_link_ksettings ecmd; |
| 2427 | const struct rtl_coalesce_info *ci; |
| 2428 | int rc; |
| 2429 | |
| 2430 | rc = rtl8169_get_link_ksettings(dev, &ecmd); |
| 2431 | if (rc < 0) |
| 2432 | return ERR_PTR(rc); |
| 2433 | |
| 2434 | for (ci = tp->coalesce_info; ci->speed != 0; ci++) { |
| 2435 | if (ecmd.base.speed == ci->speed) { |
| 2436 | return ci; |
| 2437 | } |
| 2438 | } |
| 2439 | |
| 2440 | return ERR_PTR(-ELNRNG); |
| 2441 | } |
| 2442 | |
| 2443 | static int rtl_get_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 2444 | { |
| 2445 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2446 | void __iomem *ioaddr = tp->mmio_addr; |
| 2447 | const struct rtl_coalesce_info *ci; |
| 2448 | const struct rtl_coalesce_scale *scale; |
| 2449 | struct { |
| 2450 | u32 *max_frames; |
| 2451 | u32 *usecs; |
| 2452 | } coal_settings [] = { |
| 2453 | { &ec->rx_max_coalesced_frames, &ec->rx_coalesce_usecs }, |
| 2454 | { &ec->tx_max_coalesced_frames, &ec->tx_coalesce_usecs } |
| 2455 | }, *p = coal_settings; |
| 2456 | int i; |
| 2457 | u16 w; |
| 2458 | |
| 2459 | memset(ec, 0, sizeof(*ec)); |
| 2460 | |
| 2461 | /* get rx/tx scale corresponding to current speed and CPlusCmd[0:1] */ |
| 2462 | ci = rtl_coalesce_info(dev); |
| 2463 | if (IS_ERR(ci)) |
| 2464 | return PTR_ERR(ci); |
| 2465 | |
| 2466 | scale = &ci->scalev[RTL_R16(CPlusCmd) & 3]; |
| 2467 | |
| 2468 | /* read IntrMitigate and adjust according to scale */ |
| 2469 | for (w = RTL_R16(IntrMitigate); w; w >>= RTL_COALESCE_SHIFT, p++) { |
| 2470 | *p->max_frames = (w & RTL_COALESCE_MASK) << 2; |
| 2471 | w >>= RTL_COALESCE_SHIFT; |
| 2472 | *p->usecs = w & RTL_COALESCE_MASK; |
| 2473 | } |
| 2474 | |
| 2475 | for (i = 0; i < 2; i++) { |
| 2476 | p = coal_settings + i; |
| 2477 | *p->usecs = (*p->usecs * scale->nsecs[i]) / 1000; |
| 2478 | |
| 2479 | /* |
| 2480 | * ethtool_coalesce says it is illegal to set both usecs and |
| 2481 | * max_frames to 0. |
| 2482 | */ |
| 2483 | if (!*p->usecs && !*p->max_frames) |
| 2484 | *p->max_frames = 1; |
| 2485 | } |
| 2486 | |
| 2487 | return 0; |
| 2488 | } |
| 2489 | |
| 2490 | /* choose appropriate scale factor and CPlusCmd[0:1] for (speed, nsec) */ |
| 2491 | static const struct rtl_coalesce_scale *rtl_coalesce_choose_scale( |
| 2492 | struct net_device *dev, u32 nsec, u16 *cp01) |
| 2493 | { |
| 2494 | const struct rtl_coalesce_info *ci; |
| 2495 | u16 i; |
| 2496 | |
| 2497 | ci = rtl_coalesce_info(dev); |
| 2498 | if (IS_ERR(ci)) |
| 2499 | return ERR_CAST(ci); |
| 2500 | |
| 2501 | for (i = 0; i < 4; i++) { |
| 2502 | u32 rxtx_maxscale = max(ci->scalev[i].nsecs[0], |
| 2503 | ci->scalev[i].nsecs[1]); |
| 2504 | if (nsec <= rxtx_maxscale * RTL_COALESCE_T_MAX) { |
| 2505 | *cp01 = i; |
| 2506 | return &ci->scalev[i]; |
| 2507 | } |
| 2508 | } |
| 2509 | |
| 2510 | return ERR_PTR(-EINVAL); |
| 2511 | } |
| 2512 | |
| 2513 | static int rtl_set_coalesce(struct net_device *dev, struct ethtool_coalesce *ec) |
| 2514 | { |
| 2515 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2516 | void __iomem *ioaddr = tp->mmio_addr; |
| 2517 | const struct rtl_coalesce_scale *scale; |
| 2518 | struct { |
| 2519 | u32 frames; |
| 2520 | u32 usecs; |
| 2521 | } coal_settings [] = { |
| 2522 | { ec->rx_max_coalesced_frames, ec->rx_coalesce_usecs }, |
| 2523 | { ec->tx_max_coalesced_frames, ec->tx_coalesce_usecs } |
| 2524 | }, *p = coal_settings; |
| 2525 | u16 w = 0, cp01; |
| 2526 | int i; |
| 2527 | |
| 2528 | scale = rtl_coalesce_choose_scale(dev, |
| 2529 | max(p[0].usecs, p[1].usecs) * 1000, &cp01); |
| 2530 | if (IS_ERR(scale)) |
| 2531 | return PTR_ERR(scale); |
| 2532 | |
| 2533 | for (i = 0; i < 2; i++, p++) { |
| 2534 | u32 units; |
| 2535 | |
| 2536 | /* |
| 2537 | * accept max_frames=1 we returned in rtl_get_coalesce. |
| 2538 | * accept it not only when usecs=0 because of e.g. the following scenario: |
| 2539 | * |
| 2540 | * - both rx_usecs=0 & rx_frames=0 in hardware (no delay on RX) |
| 2541 | * - rtl_get_coalesce returns rx_usecs=0, rx_frames=1 |
| 2542 | * - then user does `ethtool -C eth0 rx-usecs 100` |
| 2543 | * |
| 2544 | * since ethtool sends to kernel whole ethtool_coalesce |
| 2545 | * settings, if we do not handle rx_usecs=!0, rx_frames=1 |
| 2546 | * we'll reject it below in `frames % 4 != 0`. |
| 2547 | */ |
| 2548 | if (p->frames == 1) { |
| 2549 | p->frames = 0; |
| 2550 | } |
| 2551 | |
| 2552 | units = p->usecs * 1000 / scale->nsecs[i]; |
| 2553 | if (p->frames > RTL_COALESCE_FRAME_MAX || p->frames % 4) |
| 2554 | return -EINVAL; |
| 2555 | |
| 2556 | w <<= RTL_COALESCE_SHIFT; |
| 2557 | w |= units; |
| 2558 | w <<= RTL_COALESCE_SHIFT; |
| 2559 | w |= p->frames >> 2; |
| 2560 | } |
| 2561 | |
| 2562 | rtl_lock_work(tp); |
| 2563 | |
| 2564 | RTL_W16(IntrMitigate, swab16(w)); |
| 2565 | |
| 2566 | tp->cp_cmd = (tp->cp_cmd & ~3) | cp01; |
| 2567 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 2568 | RTL_R16(CPlusCmd); |
| 2569 | |
| 2570 | rtl_unlock_work(tp); |
| 2571 | |
| 2572 | return 0; |
| 2573 | } |
| 2574 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 2575 | static const struct ethtool_ops rtl8169_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2576 | .get_drvinfo = rtl8169_get_drvinfo, |
| 2577 | .get_regs_len = rtl8169_get_regs_len, |
| 2578 | .get_link = ethtool_op_get_link, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 2579 | .get_coalesce = rtl_get_coalesce, |
| 2580 | .set_coalesce = rtl_set_coalesce, |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 2581 | .get_msglevel = rtl8169_get_msglevel, |
| 2582 | .set_msglevel = rtl8169_set_msglevel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2583 | .get_regs = rtl8169_get_regs, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 2584 | .get_wol = rtl8169_get_wol, |
| 2585 | .set_wol = rtl8169_set_wol, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2586 | .get_strings = rtl8169_get_strings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2587 | .get_sset_count = rtl8169_get_sset_count, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2588 | .get_ethtool_stats = rtl8169_get_ethtool_stats, |
Richard Cochran | e1593bb | 2012-04-03 22:59:35 +0000 | [diff] [blame] | 2589 | .get_ts_info = ethtool_op_get_ts_info, |
Florian Fainelli | f0903ea | 2016-12-03 12:01:19 -0800 | [diff] [blame] | 2590 | .nway_reset = rtl8169_nway_reset, |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 2591 | .get_link_ksettings = rtl8169_get_link_ksettings, |
Tobias Jakobi | 9e77d7a | 2017-11-21 16:15:57 +0100 | [diff] [blame] | 2592 | .set_link_ksettings = rtl8169_set_link_ksettings, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2593 | }; |
| 2594 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 2595 | static void rtl8169_get_mac_version(struct rtl8169_private *tp, |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2596 | struct net_device *dev, u8 default_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2597 | { |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2598 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2599 | /* |
| 2600 | * The driver currently handles the 8168Bf and the 8168Be identically |
| 2601 | * but they can be identified more specifically through the test below |
| 2602 | * if needed: |
| 2603 | * |
| 2604 | * (RTL_R32(TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be |
Francois Romieu | 0127215 | 2007-02-20 22:58:51 +0100 | [diff] [blame] | 2605 | * |
| 2606 | * Same thing for the 8101Eb and the 8101Ec: |
| 2607 | * |
| 2608 | * (RTL_R32(TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2609 | */ |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2610 | static const struct rtl_mac_info { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2611 | u32 mask; |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2612 | u32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2613 | int mac_version; |
| 2614 | } mac_info[] = { |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 2615 | /* 8168EP family. */ |
| 2616 | { 0x7cf00000, 0x50200000, RTL_GIGA_MAC_VER_51 }, |
| 2617 | { 0x7cf00000, 0x50100000, RTL_GIGA_MAC_VER_50 }, |
| 2618 | { 0x7cf00000, 0x50000000, RTL_GIGA_MAC_VER_49 }, |
| 2619 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2620 | /* 8168H family. */ |
| 2621 | { 0x7cf00000, 0x54100000, RTL_GIGA_MAC_VER_46 }, |
| 2622 | { 0x7cf00000, 0x54000000, RTL_GIGA_MAC_VER_45 }, |
| 2623 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2624 | /* 8168G family. */ |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 2625 | { 0x7cf00000, 0x5c800000, RTL_GIGA_MAC_VER_44 }, |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 2626 | { 0x7cf00000, 0x50900000, RTL_GIGA_MAC_VER_42 }, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2627 | { 0x7cf00000, 0x4c100000, RTL_GIGA_MAC_VER_41 }, |
| 2628 | { 0x7cf00000, 0x4c000000, RTL_GIGA_MAC_VER_40 }, |
| 2629 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2630 | /* 8168F family. */ |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 2631 | { 0x7c800000, 0x48800000, RTL_GIGA_MAC_VER_38 }, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2632 | { 0x7cf00000, 0x48100000, RTL_GIGA_MAC_VER_36 }, |
| 2633 | { 0x7cf00000, 0x48000000, RTL_GIGA_MAC_VER_35 }, |
| 2634 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2635 | /* 8168E family. */ |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2636 | { 0x7c800000, 0x2c800000, RTL_GIGA_MAC_VER_34 }, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2637 | { 0x7cf00000, 0x2c200000, RTL_GIGA_MAC_VER_33 }, |
| 2638 | { 0x7cf00000, 0x2c100000, RTL_GIGA_MAC_VER_32 }, |
| 2639 | { 0x7c800000, 0x2c000000, RTL_GIGA_MAC_VER_33 }, |
| 2640 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2641 | /* 8168D family. */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2642 | { 0x7cf00000, 0x28300000, RTL_GIGA_MAC_VER_26 }, |
| 2643 | { 0x7cf00000, 0x28100000, RTL_GIGA_MAC_VER_25 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2644 | { 0x7c800000, 0x28000000, RTL_GIGA_MAC_VER_26 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2645 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2646 | /* 8168DP family. */ |
| 2647 | { 0x7cf00000, 0x28800000, RTL_GIGA_MAC_VER_27 }, |
| 2648 | { 0x7cf00000, 0x28a00000, RTL_GIGA_MAC_VER_28 }, |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 2649 | { 0x7cf00000, 0x28b00000, RTL_GIGA_MAC_VER_31 }, |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2650 | |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2651 | /* 8168C family. */ |
Francois Romieu | 17c9929 | 2010-07-11 17:10:09 -0700 | [diff] [blame] | 2652 | { 0x7cf00000, 0x3cb00000, RTL_GIGA_MAC_VER_24 }, |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2653 | { 0x7cf00000, 0x3c900000, RTL_GIGA_MAC_VER_23 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2654 | { 0x7cf00000, 0x3c800000, RTL_GIGA_MAC_VER_18 }, |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 2655 | { 0x7c800000, 0x3c800000, RTL_GIGA_MAC_VER_24 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2656 | { 0x7cf00000, 0x3c000000, RTL_GIGA_MAC_VER_19 }, |
| 2657 | { 0x7cf00000, 0x3c200000, RTL_GIGA_MAC_VER_20 }, |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2658 | { 0x7cf00000, 0x3c300000, RTL_GIGA_MAC_VER_21 }, |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2659 | { 0x7cf00000, 0x3c400000, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2660 | { 0x7c800000, 0x3c000000, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2661 | |
| 2662 | /* 8168B family. */ |
| 2663 | { 0x7cf00000, 0x38000000, RTL_GIGA_MAC_VER_12 }, |
| 2664 | { 0x7cf00000, 0x38500000, RTL_GIGA_MAC_VER_17 }, |
| 2665 | { 0x7c800000, 0x38000000, RTL_GIGA_MAC_VER_17 }, |
| 2666 | { 0x7c800000, 0x30000000, RTL_GIGA_MAC_VER_11 }, |
| 2667 | |
| 2668 | /* 8101 family. */ |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 2669 | { 0x7cf00000, 0x44900000, RTL_GIGA_MAC_VER_39 }, |
| 2670 | { 0x7c800000, 0x44800000, RTL_GIGA_MAC_VER_39 }, |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 2671 | { 0x7c800000, 0x44000000, RTL_GIGA_MAC_VER_37 }, |
hayeswang | 36a0e6c | 2011-03-21 01:50:30 +0000 | [diff] [blame] | 2672 | { 0x7cf00000, 0x40b00000, RTL_GIGA_MAC_VER_30 }, |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 2673 | { 0x7cf00000, 0x40a00000, RTL_GIGA_MAC_VER_30 }, |
| 2674 | { 0x7cf00000, 0x40900000, RTL_GIGA_MAC_VER_29 }, |
| 2675 | { 0x7c800000, 0x40800000, RTL_GIGA_MAC_VER_30 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2676 | { 0x7cf00000, 0x34a00000, RTL_GIGA_MAC_VER_09 }, |
| 2677 | { 0x7cf00000, 0x24a00000, RTL_GIGA_MAC_VER_09 }, |
| 2678 | { 0x7cf00000, 0x34900000, RTL_GIGA_MAC_VER_08 }, |
| 2679 | { 0x7cf00000, 0x24900000, RTL_GIGA_MAC_VER_08 }, |
| 2680 | { 0x7cf00000, 0x34800000, RTL_GIGA_MAC_VER_07 }, |
| 2681 | { 0x7cf00000, 0x24800000, RTL_GIGA_MAC_VER_07 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2682 | { 0x7cf00000, 0x34000000, RTL_GIGA_MAC_VER_13 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2683 | { 0x7cf00000, 0x34300000, RTL_GIGA_MAC_VER_10 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2684 | { 0x7cf00000, 0x34200000, RTL_GIGA_MAC_VER_16 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2685 | { 0x7c800000, 0x34800000, RTL_GIGA_MAC_VER_09 }, |
| 2686 | { 0x7c800000, 0x24800000, RTL_GIGA_MAC_VER_09 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2687 | { 0x7c800000, 0x34000000, RTL_GIGA_MAC_VER_16 }, |
| 2688 | /* FIXME: where did these entries come from ? -- FR */ |
| 2689 | { 0xfc800000, 0x38800000, RTL_GIGA_MAC_VER_15 }, |
| 2690 | { 0xfc800000, 0x30800000, RTL_GIGA_MAC_VER_14 }, |
| 2691 | |
| 2692 | /* 8110 family. */ |
| 2693 | { 0xfc800000, 0x98000000, RTL_GIGA_MAC_VER_06 }, |
| 2694 | { 0xfc800000, 0x18000000, RTL_GIGA_MAC_VER_05 }, |
| 2695 | { 0xfc800000, 0x10000000, RTL_GIGA_MAC_VER_04 }, |
| 2696 | { 0xfc800000, 0x04000000, RTL_GIGA_MAC_VER_03 }, |
| 2697 | { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 }, |
| 2698 | { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 }, |
| 2699 | |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 2700 | /* Catch-all */ |
| 2701 | { 0x00000000, 0x00000000, RTL_GIGA_MAC_NONE } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2702 | }; |
| 2703 | const struct rtl_mac_info *p = mac_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2704 | u32 reg; |
| 2705 | |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2706 | reg = RTL_R32(TxConfig); |
| 2707 | while ((reg & p->mask) != p->val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2708 | p++; |
| 2709 | tp->mac_version = p->mac_version; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2710 | |
| 2711 | if (tp->mac_version == RTL_GIGA_MAC_NONE) { |
| 2712 | netif_notice(tp, probe, dev, |
| 2713 | "unknown MAC, using family default\n"); |
| 2714 | tp->mac_version = default_version; |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 2715 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_42) { |
| 2716 | tp->mac_version = tp->mii.supports_gmii ? |
| 2717 | RTL_GIGA_MAC_VER_42 : |
| 2718 | RTL_GIGA_MAC_VER_43; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2719 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_45) { |
| 2720 | tp->mac_version = tp->mii.supports_gmii ? |
| 2721 | RTL_GIGA_MAC_VER_45 : |
| 2722 | RTL_GIGA_MAC_VER_47; |
| 2723 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_46) { |
| 2724 | tp->mac_version = tp->mii.supports_gmii ? |
| 2725 | RTL_GIGA_MAC_VER_46 : |
| 2726 | RTL_GIGA_MAC_VER_48; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2727 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2728 | } |
| 2729 | |
| 2730 | static void rtl8169_print_mac_version(struct rtl8169_private *tp) |
| 2731 | { |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 2732 | dprintk("mac_version = 0x%02x\n", tp->mac_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2733 | } |
| 2734 | |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2735 | struct phy_reg { |
| 2736 | u16 reg; |
| 2737 | u16 val; |
| 2738 | }; |
| 2739 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2740 | static void rtl_writephy_batch(struct rtl8169_private *tp, |
| 2741 | const struct phy_reg *regs, int len) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2742 | { |
| 2743 | while (len-- > 0) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2744 | rtl_writephy(tp, regs->reg, regs->val); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2745 | regs++; |
| 2746 | } |
| 2747 | } |
| 2748 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2749 | #define PHY_READ 0x00000000 |
| 2750 | #define PHY_DATA_OR 0x10000000 |
| 2751 | #define PHY_DATA_AND 0x20000000 |
| 2752 | #define PHY_BJMPN 0x30000000 |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2753 | #define PHY_MDIO_CHG 0x40000000 |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2754 | #define PHY_CLEAR_READCOUNT 0x70000000 |
| 2755 | #define PHY_WRITE 0x80000000 |
| 2756 | #define PHY_READCOUNT_EQ_SKIP 0x90000000 |
| 2757 | #define PHY_COMP_EQ_SKIPN 0xa0000000 |
| 2758 | #define PHY_COMP_NEQ_SKIPN 0xb0000000 |
| 2759 | #define PHY_WRITE_PREVIOUS 0xc0000000 |
| 2760 | #define PHY_SKIPN 0xd0000000 |
| 2761 | #define PHY_DELAY_MS 0xe0000000 |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2762 | |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2763 | struct fw_info { |
| 2764 | u32 magic; |
| 2765 | char version[RTL_VER_SIZE]; |
| 2766 | __le32 fw_start; |
| 2767 | __le32 fw_len; |
| 2768 | u8 chksum; |
| 2769 | } __packed; |
| 2770 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2771 | #define FW_OPCODE_SIZE sizeof(typeof(*((struct rtl_fw_phy_action *)0)->code)) |
| 2772 | |
| 2773 | 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] | 2774 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2775 | const struct firmware *fw = rtl_fw->fw; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2776 | struct fw_info *fw_info = (struct fw_info *)fw->data; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2777 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
| 2778 | char *version = rtl_fw->version; |
| 2779 | bool rc = false; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2780 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2781 | if (fw->size < FW_OPCODE_SIZE) |
| 2782 | goto out; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2783 | |
| 2784 | if (!fw_info->magic) { |
| 2785 | size_t i, size, start; |
| 2786 | u8 checksum = 0; |
| 2787 | |
| 2788 | if (fw->size < sizeof(*fw_info)) |
| 2789 | goto out; |
| 2790 | |
| 2791 | for (i = 0; i < fw->size; i++) |
| 2792 | checksum += fw->data[i]; |
| 2793 | if (checksum != 0) |
| 2794 | goto out; |
| 2795 | |
| 2796 | start = le32_to_cpu(fw_info->fw_start); |
| 2797 | if (start > fw->size) |
| 2798 | goto out; |
| 2799 | |
| 2800 | size = le32_to_cpu(fw_info->fw_len); |
| 2801 | if (size > (fw->size - start) / FW_OPCODE_SIZE) |
| 2802 | goto out; |
| 2803 | |
| 2804 | memcpy(version, fw_info->version, RTL_VER_SIZE); |
| 2805 | |
| 2806 | pa->code = (__le32 *)(fw->data + start); |
| 2807 | pa->size = size; |
| 2808 | } else { |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2809 | if (fw->size % FW_OPCODE_SIZE) |
| 2810 | goto out; |
| 2811 | |
| 2812 | strlcpy(version, rtl_lookup_firmware_name(tp), RTL_VER_SIZE); |
| 2813 | |
| 2814 | pa->code = (__le32 *)fw->data; |
| 2815 | pa->size = fw->size / FW_OPCODE_SIZE; |
| 2816 | } |
| 2817 | version[RTL_VER_SIZE - 1] = 0; |
| 2818 | |
| 2819 | rc = true; |
| 2820 | out: |
| 2821 | return rc; |
| 2822 | } |
| 2823 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2824 | static bool rtl_fw_data_ok(struct rtl8169_private *tp, struct net_device *dev, |
| 2825 | struct rtl_fw_phy_action *pa) |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2826 | { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2827 | bool rc = false; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2828 | size_t index; |
| 2829 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2830 | for (index = 0; index < pa->size; index++) { |
| 2831 | u32 action = le32_to_cpu(pa->code[index]); |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2832 | u32 regno = (action & 0x0fff0000) >> 16; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2833 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2834 | switch(action & 0xf0000000) { |
| 2835 | case PHY_READ: |
| 2836 | case PHY_DATA_OR: |
| 2837 | case PHY_DATA_AND: |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2838 | case PHY_MDIO_CHG: |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2839 | case PHY_CLEAR_READCOUNT: |
| 2840 | case PHY_WRITE: |
| 2841 | case PHY_WRITE_PREVIOUS: |
| 2842 | case PHY_DELAY_MS: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2843 | break; |
| 2844 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2845 | case PHY_BJMPN: |
| 2846 | if (regno > index) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2847 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2848 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2849 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2850 | } |
| 2851 | break; |
| 2852 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2853 | if (index + 2 >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2854 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2855 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2856 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2857 | } |
| 2858 | break; |
| 2859 | case PHY_COMP_EQ_SKIPN: |
| 2860 | case PHY_COMP_NEQ_SKIPN: |
| 2861 | case PHY_SKIPN: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2862 | if (index + 1 + regno >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2863 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2864 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2865 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2866 | } |
| 2867 | break; |
| 2868 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2869 | default: |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2870 | netif_err(tp, ifup, tp->dev, |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2871 | "Invalid action 0x%08x\n", action); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2872 | goto out; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2873 | } |
| 2874 | } |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2875 | rc = true; |
| 2876 | out: |
| 2877 | return rc; |
| 2878 | } |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2879 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2880 | static int rtl_check_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2881 | { |
| 2882 | struct net_device *dev = tp->dev; |
| 2883 | int rc = -EINVAL; |
| 2884 | |
| 2885 | if (!rtl_fw_format_ok(tp, rtl_fw)) { |
Yannick Guerrini | 5c2d2b1 | 2015-02-24 13:03:51 +0100 | [diff] [blame] | 2886 | netif_err(tp, ifup, dev, "invalid firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2887 | goto out; |
| 2888 | } |
| 2889 | |
| 2890 | if (rtl_fw_data_ok(tp, dev, &rtl_fw->phy_action)) |
| 2891 | rc = 0; |
| 2892 | out: |
| 2893 | return rc; |
| 2894 | } |
| 2895 | |
| 2896 | static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2897 | { |
| 2898 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2899 | struct mdio_ops org, *ops = &tp->mdio_ops; |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2900 | u32 predata, count; |
| 2901 | size_t index; |
| 2902 | |
| 2903 | predata = count = 0; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2904 | org.write = ops->write; |
| 2905 | org.read = ops->read; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2906 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2907 | for (index = 0; index < pa->size; ) { |
| 2908 | u32 action = le32_to_cpu(pa->code[index]); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2909 | u32 data = action & 0x0000ffff; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2910 | u32 regno = (action & 0x0fff0000) >> 16; |
| 2911 | |
| 2912 | if (!action) |
| 2913 | break; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2914 | |
| 2915 | switch(action & 0xf0000000) { |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2916 | case PHY_READ: |
| 2917 | predata = rtl_readphy(tp, regno); |
| 2918 | count++; |
| 2919 | index++; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2920 | break; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2921 | case PHY_DATA_OR: |
| 2922 | predata |= data; |
| 2923 | index++; |
| 2924 | break; |
| 2925 | case PHY_DATA_AND: |
| 2926 | predata &= data; |
| 2927 | index++; |
| 2928 | break; |
| 2929 | case PHY_BJMPN: |
| 2930 | index -= regno; |
| 2931 | break; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2932 | case PHY_MDIO_CHG: |
| 2933 | if (data == 0) { |
| 2934 | ops->write = org.write; |
| 2935 | ops->read = org.read; |
| 2936 | } else if (data == 1) { |
| 2937 | ops->write = mac_mcu_write; |
| 2938 | ops->read = mac_mcu_read; |
| 2939 | } |
| 2940 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2941 | index++; |
| 2942 | break; |
| 2943 | case PHY_CLEAR_READCOUNT: |
| 2944 | count = 0; |
| 2945 | index++; |
| 2946 | break; |
| 2947 | case PHY_WRITE: |
| 2948 | rtl_writephy(tp, regno, data); |
| 2949 | index++; |
| 2950 | break; |
| 2951 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2952 | index += (count == data) ? 2 : 1; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2953 | break; |
| 2954 | case PHY_COMP_EQ_SKIPN: |
| 2955 | if (predata == data) |
| 2956 | index += regno; |
| 2957 | index++; |
| 2958 | break; |
| 2959 | case PHY_COMP_NEQ_SKIPN: |
| 2960 | if (predata != data) |
| 2961 | index += regno; |
| 2962 | index++; |
| 2963 | break; |
| 2964 | case PHY_WRITE_PREVIOUS: |
| 2965 | rtl_writephy(tp, regno, predata); |
| 2966 | index++; |
| 2967 | break; |
| 2968 | case PHY_SKIPN: |
| 2969 | index += regno + 1; |
| 2970 | break; |
| 2971 | case PHY_DELAY_MS: |
| 2972 | mdelay(data); |
| 2973 | index++; |
| 2974 | break; |
| 2975 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2976 | default: |
| 2977 | BUG(); |
| 2978 | } |
| 2979 | } |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2980 | |
| 2981 | ops->write = org.write; |
| 2982 | ops->read = org.read; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2983 | } |
| 2984 | |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2985 | static void rtl_release_firmware(struct rtl8169_private *tp) |
| 2986 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2987 | if (!IS_ERR_OR_NULL(tp->rtl_fw)) { |
| 2988 | release_firmware(tp->rtl_fw->fw); |
| 2989 | kfree(tp->rtl_fw); |
| 2990 | } |
| 2991 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2992 | } |
| 2993 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2994 | static void rtl_apply_firmware(struct rtl8169_private *tp) |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2995 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2996 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2997 | |
| 2998 | /* TODO: release firmware once rtl_phy_write_fw signals failures. */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 2999 | if (!IS_ERR_OR_NULL(rtl_fw)) |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 3000 | rtl_phy_write_fw(tp, rtl_fw); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3001 | } |
| 3002 | |
| 3003 | static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val) |
| 3004 | { |
| 3005 | if (rtl_readphy(tp, reg) != val) |
| 3006 | netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n"); |
| 3007 | else |
| 3008 | rtl_apply_firmware(tp); |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 3009 | } |
| 3010 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3011 | static void rtl8169s_hw_phy_config(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3012 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3013 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 3014 | { 0x1f, 0x0001 }, |
| 3015 | { 0x06, 0x006e }, |
| 3016 | { 0x08, 0x0708 }, |
| 3017 | { 0x15, 0x4000 }, |
| 3018 | { 0x18, 0x65c7 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3019 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 3020 | { 0x1f, 0x0001 }, |
| 3021 | { 0x03, 0x00a1 }, |
| 3022 | { 0x02, 0x0008 }, |
| 3023 | { 0x01, 0x0120 }, |
| 3024 | { 0x00, 0x1000 }, |
| 3025 | { 0x04, 0x0800 }, |
| 3026 | { 0x04, 0x0000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3027 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 3028 | { 0x03, 0xff41 }, |
| 3029 | { 0x02, 0xdf60 }, |
| 3030 | { 0x01, 0x0140 }, |
| 3031 | { 0x00, 0x0077 }, |
| 3032 | { 0x04, 0x7800 }, |
| 3033 | { 0x04, 0x7000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3034 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 3035 | { 0x03, 0x802f }, |
| 3036 | { 0x02, 0x4f02 }, |
| 3037 | { 0x01, 0x0409 }, |
| 3038 | { 0x00, 0xf0f9 }, |
| 3039 | { 0x04, 0x9800 }, |
| 3040 | { 0x04, 0x9000 }, |
| 3041 | |
| 3042 | { 0x03, 0xdf01 }, |
| 3043 | { 0x02, 0xdf20 }, |
| 3044 | { 0x01, 0xff95 }, |
| 3045 | { 0x00, 0xba00 }, |
| 3046 | { 0x04, 0xa800 }, |
| 3047 | { 0x04, 0xa000 }, |
| 3048 | |
| 3049 | { 0x03, 0xff41 }, |
| 3050 | { 0x02, 0xdf20 }, |
| 3051 | { 0x01, 0x0140 }, |
| 3052 | { 0x00, 0x00bb }, |
| 3053 | { 0x04, 0xb800 }, |
| 3054 | { 0x04, 0xb000 }, |
| 3055 | |
| 3056 | { 0x03, 0xdf41 }, |
| 3057 | { 0x02, 0xdc60 }, |
| 3058 | { 0x01, 0x6340 }, |
| 3059 | { 0x00, 0x007d }, |
| 3060 | { 0x04, 0xd800 }, |
| 3061 | { 0x04, 0xd000 }, |
| 3062 | |
| 3063 | { 0x03, 0xdf01 }, |
| 3064 | { 0x02, 0xdf20 }, |
| 3065 | { 0x01, 0x100a }, |
| 3066 | { 0x00, 0xa0ff }, |
| 3067 | { 0x04, 0xf800 }, |
| 3068 | { 0x04, 0xf000 }, |
| 3069 | |
| 3070 | { 0x1f, 0x0000 }, |
| 3071 | { 0x0b, 0x0000 }, |
| 3072 | { 0x00, 0x9200 } |
| 3073 | }; |
| 3074 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3075 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3076 | } |
| 3077 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3078 | static void rtl8169sb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3079 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3080 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a441d7b | 2007-08-17 18:26:35 +0200 | [diff] [blame] | 3081 | { 0x1f, 0x0002 }, |
| 3082 | { 0x01, 0x90d0 }, |
| 3083 | { 0x1f, 0x0000 } |
| 3084 | }; |
| 3085 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3086 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3087 | } |
| 3088 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3089 | static void rtl8169scd_hw_phy_config_quirk(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3090 | { |
| 3091 | struct pci_dev *pdev = tp->pci_dev; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3092 | |
Sergei Shtylyov | ccbae55 | 2011-07-22 05:37:24 +0000 | [diff] [blame] | 3093 | if ((pdev->subsystem_vendor != PCI_VENDOR_ID_GIGABYTE) || |
| 3094 | (pdev->subsystem_device != 0xe000)) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3095 | return; |
| 3096 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3097 | rtl_writephy(tp, 0x1f, 0x0001); |
| 3098 | rtl_writephy(tp, 0x10, 0xf01b); |
| 3099 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3100 | } |
| 3101 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3102 | static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3103 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3104 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3105 | { 0x1f, 0x0001 }, |
| 3106 | { 0x04, 0x0000 }, |
| 3107 | { 0x03, 0x00a1 }, |
| 3108 | { 0x02, 0x0008 }, |
| 3109 | { 0x01, 0x0120 }, |
| 3110 | { 0x00, 0x1000 }, |
| 3111 | { 0x04, 0x0800 }, |
| 3112 | { 0x04, 0x9000 }, |
| 3113 | { 0x03, 0x802f }, |
| 3114 | { 0x02, 0x4f02 }, |
| 3115 | { 0x01, 0x0409 }, |
| 3116 | { 0x00, 0xf099 }, |
| 3117 | { 0x04, 0x9800 }, |
| 3118 | { 0x04, 0xa000 }, |
| 3119 | { 0x03, 0xdf01 }, |
| 3120 | { 0x02, 0xdf20 }, |
| 3121 | { 0x01, 0xff95 }, |
| 3122 | { 0x00, 0xba00 }, |
| 3123 | { 0x04, 0xa800 }, |
| 3124 | { 0x04, 0xf000 }, |
| 3125 | { 0x03, 0xdf01 }, |
| 3126 | { 0x02, 0xdf20 }, |
| 3127 | { 0x01, 0x101a }, |
| 3128 | { 0x00, 0xa0ff }, |
| 3129 | { 0x04, 0xf800 }, |
| 3130 | { 0x04, 0x0000 }, |
| 3131 | { 0x1f, 0x0000 }, |
| 3132 | |
| 3133 | { 0x1f, 0x0001 }, |
| 3134 | { 0x10, 0xf41b }, |
| 3135 | { 0x14, 0xfb54 }, |
| 3136 | { 0x18, 0xf5c7 }, |
| 3137 | { 0x1f, 0x0000 }, |
| 3138 | |
| 3139 | { 0x1f, 0x0001 }, |
| 3140 | { 0x17, 0x0cc0 }, |
| 3141 | { 0x1f, 0x0000 } |
| 3142 | }; |
| 3143 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3144 | 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] | 3145 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3146 | rtl8169scd_hw_phy_config_quirk(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3147 | } |
| 3148 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3149 | static void rtl8169sce_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 3150 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3151 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 3152 | { 0x1f, 0x0001 }, |
| 3153 | { 0x04, 0x0000 }, |
| 3154 | { 0x03, 0x00a1 }, |
| 3155 | { 0x02, 0x0008 }, |
| 3156 | { 0x01, 0x0120 }, |
| 3157 | { 0x00, 0x1000 }, |
| 3158 | { 0x04, 0x0800 }, |
| 3159 | { 0x04, 0x9000 }, |
| 3160 | { 0x03, 0x802f }, |
| 3161 | { 0x02, 0x4f02 }, |
| 3162 | { 0x01, 0x0409 }, |
| 3163 | { 0x00, 0xf099 }, |
| 3164 | { 0x04, 0x9800 }, |
| 3165 | { 0x04, 0xa000 }, |
| 3166 | { 0x03, 0xdf01 }, |
| 3167 | { 0x02, 0xdf20 }, |
| 3168 | { 0x01, 0xff95 }, |
| 3169 | { 0x00, 0xba00 }, |
| 3170 | { 0x04, 0xa800 }, |
| 3171 | { 0x04, 0xf000 }, |
| 3172 | { 0x03, 0xdf01 }, |
| 3173 | { 0x02, 0xdf20 }, |
| 3174 | { 0x01, 0x101a }, |
| 3175 | { 0x00, 0xa0ff }, |
| 3176 | { 0x04, 0xf800 }, |
| 3177 | { 0x04, 0x0000 }, |
| 3178 | { 0x1f, 0x0000 }, |
| 3179 | |
| 3180 | { 0x1f, 0x0001 }, |
| 3181 | { 0x0b, 0x8480 }, |
| 3182 | { 0x1f, 0x0000 }, |
| 3183 | |
| 3184 | { 0x1f, 0x0001 }, |
| 3185 | { 0x18, 0x67c7 }, |
| 3186 | { 0x04, 0x2000 }, |
| 3187 | { 0x03, 0x002f }, |
| 3188 | { 0x02, 0x4360 }, |
| 3189 | { 0x01, 0x0109 }, |
| 3190 | { 0x00, 0x3022 }, |
| 3191 | { 0x04, 0x2800 }, |
| 3192 | { 0x1f, 0x0000 }, |
| 3193 | |
| 3194 | { 0x1f, 0x0001 }, |
| 3195 | { 0x17, 0x0cc0 }, |
| 3196 | { 0x1f, 0x0000 } |
| 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)); |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 3200 | } |
| 3201 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3202 | static void rtl8168bb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3203 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3204 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3205 | { 0x10, 0xf41b }, |
| 3206 | { 0x1f, 0x0000 } |
| 3207 | }; |
| 3208 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3209 | rtl_writephy(tp, 0x1f, 0x0001); |
| 3210 | rtl_patchphy(tp, 0x16, 1 << 0); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3211 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3212 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3213 | } |
| 3214 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3215 | static void rtl8168bef_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3216 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3217 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3218 | { 0x1f, 0x0001 }, |
| 3219 | { 0x10, 0xf41b }, |
| 3220 | { 0x1f, 0x0000 } |
| 3221 | }; |
| 3222 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3223 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3224 | } |
| 3225 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3226 | static void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3227 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3228 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3229 | { 0x1f, 0x0000 }, |
| 3230 | { 0x1d, 0x0f00 }, |
| 3231 | { 0x1f, 0x0002 }, |
| 3232 | { 0x0c, 0x1ec8 }, |
| 3233 | { 0x1f, 0x0000 } |
| 3234 | }; |
| 3235 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3236 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3237 | } |
| 3238 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3239 | static void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3240 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3241 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3242 | { 0x1f, 0x0001 }, |
| 3243 | { 0x1d, 0x3d98 }, |
| 3244 | { 0x1f, 0x0000 } |
| 3245 | }; |
| 3246 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3247 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3248 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 3249 | rtl_patchphy(tp, 0x0d, 1 << 5); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3250 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3251 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3252 | } |
| 3253 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3254 | static void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3255 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3256 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a3f8067 | 2007-10-18 14:35:11 +0200 | [diff] [blame] | 3257 | { 0x1f, 0x0001 }, |
| 3258 | { 0x12, 0x2300 }, |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3259 | { 0x1f, 0x0002 }, |
| 3260 | { 0x00, 0x88d4 }, |
| 3261 | { 0x01, 0x82b1 }, |
| 3262 | { 0x03, 0x7002 }, |
| 3263 | { 0x08, 0x9e30 }, |
| 3264 | { 0x09, 0x01f0 }, |
| 3265 | { 0x0a, 0x5500 }, |
| 3266 | { 0x0c, 0x00c8 }, |
| 3267 | { 0x1f, 0x0003 }, |
| 3268 | { 0x12, 0xc096 }, |
| 3269 | { 0x16, 0x000a }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3270 | { 0x1f, 0x0000 }, |
| 3271 | { 0x1f, 0x0000 }, |
| 3272 | { 0x09, 0x2000 }, |
| 3273 | { 0x09, 0x0000 } |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3274 | }; |
| 3275 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3276 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3277 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3278 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 3279 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3280 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3281 | } |
| 3282 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3283 | static void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3284 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3285 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3286 | { 0x1f, 0x0001 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3287 | { 0x12, 0x2300 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3288 | { 0x03, 0x802f }, |
| 3289 | { 0x02, 0x4f02 }, |
| 3290 | { 0x01, 0x0409 }, |
| 3291 | { 0x00, 0xf099 }, |
| 3292 | { 0x04, 0x9800 }, |
| 3293 | { 0x04, 0x9000 }, |
| 3294 | { 0x1d, 0x3d98 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3295 | { 0x1f, 0x0002 }, |
| 3296 | { 0x0c, 0x7eb8 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3297 | { 0x06, 0x0761 }, |
| 3298 | { 0x1f, 0x0003 }, |
| 3299 | { 0x16, 0x0f0a }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3300 | { 0x1f, 0x0000 } |
| 3301 | }; |
| 3302 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3303 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 3304 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3305 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 3306 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 3307 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3308 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3309 | } |
| 3310 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3311 | static void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3312 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3313 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3314 | { 0x1f, 0x0001 }, |
| 3315 | { 0x12, 0x2300 }, |
| 3316 | { 0x1d, 0x3d98 }, |
| 3317 | { 0x1f, 0x0002 }, |
| 3318 | { 0x0c, 0x7eb8 }, |
| 3319 | { 0x06, 0x5461 }, |
| 3320 | { 0x1f, 0x0003 }, |
| 3321 | { 0x16, 0x0f0a }, |
| 3322 | { 0x1f, 0x0000 } |
| 3323 | }; |
| 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)); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3326 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3327 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 3328 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 3329 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3330 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3331 | } |
| 3332 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3333 | static void rtl8168c_4_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3334 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3335 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3336 | } |
| 3337 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3338 | static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3339 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3340 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3341 | /* Channel Estimation */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3342 | { 0x1f, 0x0001 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3343 | { 0x06, 0x4064 }, |
| 3344 | { 0x07, 0x2863 }, |
| 3345 | { 0x08, 0x059c }, |
| 3346 | { 0x09, 0x26b4 }, |
| 3347 | { 0x0a, 0x6a19 }, |
| 3348 | { 0x0b, 0xdcc8 }, |
| 3349 | { 0x10, 0xf06d }, |
| 3350 | { 0x14, 0x7f68 }, |
| 3351 | { 0x18, 0x7fd9 }, |
| 3352 | { 0x1c, 0xf0ff }, |
| 3353 | { 0x1d, 0x3d9c }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3354 | { 0x1f, 0x0003 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3355 | { 0x12, 0xf49f }, |
| 3356 | { 0x13, 0x070b }, |
| 3357 | { 0x1a, 0x05ad }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3358 | { 0x14, 0x94c0 }, |
| 3359 | |
| 3360 | /* |
| 3361 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3362 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3363 | */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3364 | { 0x1f, 0x0002 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3365 | { 0x06, 0x5561 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3366 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3367 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3368 | { 0x06, 0x5561 }, |
| 3369 | |
| 3370 | /* |
| 3371 | * Can not link to 1Gbps with bad cable |
| 3372 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 3373 | */ |
| 3374 | { 0x1f, 0x0001 }, |
| 3375 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3376 | |
| 3377 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3378 | { 0x0d, 0xf880 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3379 | }; |
| 3380 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3381 | 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] | 3382 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3383 | /* |
| 3384 | * Rx Error Issue |
| 3385 | * Fine Tune Switching regulator parameter |
| 3386 | */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3387 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3388 | rtl_w0w1_phy(tp, 0x0b, 0x0010, 0x00ef); |
| 3389 | rtl_w0w1_phy(tp, 0x0c, 0xa200, 0x5d00); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3390 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3391 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3392 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3393 | { 0x1f, 0x0002 }, |
| 3394 | { 0x05, 0x669a }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3395 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3396 | { 0x05, 0x8330 }, |
| 3397 | { 0x06, 0x669a }, |
| 3398 | { 0x1f, 0x0002 } |
| 3399 | }; |
| 3400 | int val; |
| 3401 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3402 | 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] | 3403 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3404 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3405 | |
| 3406 | if ((val & 0x00ff) != 0x006c) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3407 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3408 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 3409 | 0x0069, 0x006a, 0x006b, 0x006c |
| 3410 | }; |
| 3411 | int i; |
| 3412 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3413 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3414 | |
| 3415 | val &= 0xff00; |
| 3416 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3417 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3418 | } |
| 3419 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3420 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3421 | { 0x1f, 0x0002 }, |
| 3422 | { 0x05, 0x6662 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3423 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3424 | { 0x05, 0x8330 }, |
| 3425 | { 0x06, 0x6662 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3426 | }; |
| 3427 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3428 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3429 | } |
| 3430 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3431 | /* RSET couple improve */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3432 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3433 | rtl_patchphy(tp, 0x0d, 0x0300); |
| 3434 | rtl_patchphy(tp, 0x0f, 0x0010); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3435 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3436 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3437 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3438 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 3439 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3440 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3441 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3442 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3443 | |
| 3444 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3445 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3446 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3447 | } |
| 3448 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3449 | static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3450 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3451 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3452 | /* Channel Estimation */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3453 | { 0x1f, 0x0001 }, |
| 3454 | { 0x06, 0x4064 }, |
| 3455 | { 0x07, 0x2863 }, |
| 3456 | { 0x08, 0x059c }, |
| 3457 | { 0x09, 0x26b4 }, |
| 3458 | { 0x0a, 0x6a19 }, |
| 3459 | { 0x0b, 0xdcc8 }, |
| 3460 | { 0x10, 0xf06d }, |
| 3461 | { 0x14, 0x7f68 }, |
| 3462 | { 0x18, 0x7fd9 }, |
| 3463 | { 0x1c, 0xf0ff }, |
| 3464 | { 0x1d, 0x3d9c }, |
| 3465 | { 0x1f, 0x0003 }, |
| 3466 | { 0x12, 0xf49f }, |
| 3467 | { 0x13, 0x070b }, |
| 3468 | { 0x1a, 0x05ad }, |
| 3469 | { 0x14, 0x94c0 }, |
| 3470 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3471 | /* |
| 3472 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3473 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3474 | */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3475 | { 0x1f, 0x0002 }, |
| 3476 | { 0x06, 0x5561 }, |
| 3477 | { 0x1f, 0x0005 }, |
| 3478 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3479 | { 0x06, 0x5561 }, |
| 3480 | |
| 3481 | /* |
| 3482 | * Can not link to 1Gbps with bad cable |
| 3483 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 3484 | */ |
| 3485 | { 0x1f, 0x0001 }, |
| 3486 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3487 | |
| 3488 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3489 | { 0x0d, 0xf880 } |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3490 | }; |
| 3491 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3492 | 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] | 3493 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3494 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3495 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3496 | { 0x1f, 0x0002 }, |
| 3497 | { 0x05, 0x669a }, |
| 3498 | { 0x1f, 0x0005 }, |
| 3499 | { 0x05, 0x8330 }, |
| 3500 | { 0x06, 0x669a }, |
| 3501 | |
| 3502 | { 0x1f, 0x0002 } |
| 3503 | }; |
| 3504 | int val; |
| 3505 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3506 | 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] | 3507 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3508 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3509 | if ((val & 0x00ff) != 0x006c) { |
Joe Perches | b6bc765 | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 3510 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3511 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 3512 | 0x0069, 0x006a, 0x006b, 0x006c |
| 3513 | }; |
| 3514 | int i; |
| 3515 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3516 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3517 | |
| 3518 | val &= 0xff00; |
| 3519 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3520 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3521 | } |
| 3522 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3523 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3524 | { 0x1f, 0x0002 }, |
| 3525 | { 0x05, 0x2642 }, |
| 3526 | { 0x1f, 0x0005 }, |
| 3527 | { 0x05, 0x8330 }, |
| 3528 | { 0x06, 0x2642 } |
| 3529 | }; |
| 3530 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3531 | 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] | 3532 | } |
| 3533 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3534 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3535 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3536 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 3537 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3538 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3539 | /* Switching regulator Slew rate */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3540 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3541 | rtl_patchphy(tp, 0x0f, 0x0017); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3542 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3543 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3544 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3545 | |
| 3546 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3547 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3548 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3549 | } |
| 3550 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3551 | static void rtl8168d_3_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3552 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3553 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3554 | { 0x1f, 0x0002 }, |
| 3555 | { 0x10, 0x0008 }, |
| 3556 | { 0x0d, 0x006c }, |
| 3557 | |
| 3558 | { 0x1f, 0x0000 }, |
| 3559 | { 0x0d, 0xf880 }, |
| 3560 | |
| 3561 | { 0x1f, 0x0001 }, |
| 3562 | { 0x17, 0x0cc0 }, |
| 3563 | |
| 3564 | { 0x1f, 0x0001 }, |
| 3565 | { 0x0b, 0xa4d8 }, |
| 3566 | { 0x09, 0x281c }, |
| 3567 | { 0x07, 0x2883 }, |
| 3568 | { 0x0a, 0x6b35 }, |
| 3569 | { 0x1d, 0x3da4 }, |
| 3570 | { 0x1c, 0xeffd }, |
| 3571 | { 0x14, 0x7f52 }, |
| 3572 | { 0x18, 0x7fc6 }, |
| 3573 | { 0x08, 0x0601 }, |
| 3574 | { 0x06, 0x4063 }, |
| 3575 | { 0x10, 0xf074 }, |
| 3576 | { 0x1f, 0x0003 }, |
| 3577 | { 0x13, 0x0789 }, |
| 3578 | { 0x12, 0xf4bd }, |
| 3579 | { 0x1a, 0x04fd }, |
| 3580 | { 0x14, 0x84b0 }, |
| 3581 | { 0x1f, 0x0000 }, |
| 3582 | { 0x00, 0x9200 }, |
| 3583 | |
| 3584 | { 0x1f, 0x0005 }, |
| 3585 | { 0x01, 0x0340 }, |
| 3586 | { 0x1f, 0x0001 }, |
| 3587 | { 0x04, 0x4000 }, |
| 3588 | { 0x03, 0x1d21 }, |
| 3589 | { 0x02, 0x0c32 }, |
| 3590 | { 0x01, 0x0200 }, |
| 3591 | { 0x00, 0x5554 }, |
| 3592 | { 0x04, 0x4800 }, |
| 3593 | { 0x04, 0x4000 }, |
| 3594 | { 0x04, 0xf000 }, |
| 3595 | { 0x03, 0xdf01 }, |
| 3596 | { 0x02, 0xdf20 }, |
| 3597 | { 0x01, 0x101a }, |
| 3598 | { 0x00, 0xa0ff }, |
| 3599 | { 0x04, 0xf800 }, |
| 3600 | { 0x04, 0xf000 }, |
| 3601 | { 0x1f, 0x0000 }, |
| 3602 | |
| 3603 | { 0x1f, 0x0007 }, |
| 3604 | { 0x1e, 0x0023 }, |
| 3605 | { 0x16, 0x0000 }, |
| 3606 | { 0x1f, 0x0000 } |
| 3607 | }; |
| 3608 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3609 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3610 | } |
| 3611 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3612 | static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp) |
| 3613 | { |
| 3614 | static const struct phy_reg phy_reg_init[] = { |
| 3615 | { 0x1f, 0x0001 }, |
| 3616 | { 0x17, 0x0cc0 }, |
| 3617 | |
| 3618 | { 0x1f, 0x0007 }, |
| 3619 | { 0x1e, 0x002d }, |
| 3620 | { 0x18, 0x0040 }, |
| 3621 | { 0x1f, 0x0000 } |
| 3622 | }; |
| 3623 | |
| 3624 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3625 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3626 | } |
| 3627 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3628 | static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3629 | { |
| 3630 | static const struct phy_reg phy_reg_init[] = { |
| 3631 | /* Enable Delay cap */ |
| 3632 | { 0x1f, 0x0005 }, |
| 3633 | { 0x05, 0x8b80 }, |
| 3634 | { 0x06, 0xc896 }, |
| 3635 | { 0x1f, 0x0000 }, |
| 3636 | |
| 3637 | /* Channel estimation fine tune */ |
| 3638 | { 0x1f, 0x0001 }, |
| 3639 | { 0x0b, 0x6c20 }, |
| 3640 | { 0x07, 0x2872 }, |
| 3641 | { 0x1c, 0xefff }, |
| 3642 | { 0x1f, 0x0003 }, |
| 3643 | { 0x14, 0x6420 }, |
| 3644 | { 0x1f, 0x0000 }, |
| 3645 | |
| 3646 | /* Update PFM & 10M TX idle timer */ |
| 3647 | { 0x1f, 0x0007 }, |
| 3648 | { 0x1e, 0x002f }, |
| 3649 | { 0x15, 0x1919 }, |
| 3650 | { 0x1f, 0x0000 }, |
| 3651 | |
| 3652 | { 0x1f, 0x0007 }, |
| 3653 | { 0x1e, 0x00ac }, |
| 3654 | { 0x18, 0x0006 }, |
| 3655 | { 0x1f, 0x0000 } |
| 3656 | }; |
| 3657 | |
Francois Romieu | 15ecd03 | 2011-04-27 13:52:22 -0700 | [diff] [blame] | 3658 | rtl_apply_firmware(tp); |
| 3659 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3660 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3661 | |
| 3662 | /* DCO enable for 10M IDLE Power */ |
| 3663 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3664 | rtl_writephy(tp, 0x1e, 0x0023); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3665 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3666 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3667 | |
| 3668 | /* For impedance matching */ |
| 3669 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3670 | rtl_w0w1_phy(tp, 0x08, 0x8000, 0x7f00); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3671 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3672 | |
| 3673 | /* PHY auto speed down */ |
| 3674 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3675 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3676 | rtl_w0w1_phy(tp, 0x18, 0x0050, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3677 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3678 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3679 | |
| 3680 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3681 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3682 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3683 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3684 | |
| 3685 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3686 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3687 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3688 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3689 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3690 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x1100); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3691 | rtl_writephy(tp, 0x1f, 0x0006); |
| 3692 | rtl_writephy(tp, 0x00, 0x5a00); |
| 3693 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3694 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3695 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3696 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3697 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3698 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3699 | } |
| 3700 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3701 | static void rtl_rar_exgmac_set(struct rtl8169_private *tp, u8 *addr) |
| 3702 | { |
| 3703 | const u16 w[] = { |
| 3704 | addr[0] | (addr[1] << 8), |
| 3705 | addr[2] | (addr[3] << 8), |
| 3706 | addr[4] | (addr[5] << 8) |
| 3707 | }; |
| 3708 | const struct exgmac_reg e[] = { |
| 3709 | { .addr = 0xe0, ERIAR_MASK_1111, .val = w[0] | (w[1] << 16) }, |
| 3710 | { .addr = 0xe4, ERIAR_MASK_1111, .val = w[2] }, |
| 3711 | { .addr = 0xf0, ERIAR_MASK_1111, .val = w[0] << 16 }, |
| 3712 | { .addr = 0xf4, ERIAR_MASK_1111, .val = w[1] | (w[2] << 16) } |
| 3713 | }; |
| 3714 | |
| 3715 | rtl_write_exgmac_batch(tp, e, ARRAY_SIZE(e)); |
| 3716 | } |
| 3717 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3718 | static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp) |
| 3719 | { |
| 3720 | static const struct phy_reg phy_reg_init[] = { |
| 3721 | /* Enable Delay cap */ |
| 3722 | { 0x1f, 0x0004 }, |
| 3723 | { 0x1f, 0x0007 }, |
| 3724 | { 0x1e, 0x00ac }, |
| 3725 | { 0x18, 0x0006 }, |
| 3726 | { 0x1f, 0x0002 }, |
| 3727 | { 0x1f, 0x0000 }, |
| 3728 | { 0x1f, 0x0000 }, |
| 3729 | |
| 3730 | /* Channel estimation fine tune */ |
| 3731 | { 0x1f, 0x0003 }, |
| 3732 | { 0x09, 0xa20f }, |
| 3733 | { 0x1f, 0x0000 }, |
| 3734 | { 0x1f, 0x0000 }, |
| 3735 | |
| 3736 | /* Green Setting */ |
| 3737 | { 0x1f, 0x0005 }, |
| 3738 | { 0x05, 0x8b5b }, |
| 3739 | { 0x06, 0x9222 }, |
| 3740 | { 0x05, 0x8b6d }, |
| 3741 | { 0x06, 0x8000 }, |
| 3742 | { 0x05, 0x8b76 }, |
| 3743 | { 0x06, 0x8000 }, |
| 3744 | { 0x1f, 0x0000 } |
| 3745 | }; |
| 3746 | |
| 3747 | rtl_apply_firmware(tp); |
| 3748 | |
| 3749 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3750 | |
| 3751 | /* For 4-corner performance improve */ |
| 3752 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3753 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3754 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3755 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3756 | |
| 3757 | /* PHY auto speed down */ |
| 3758 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3759 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3760 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3761 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3762 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3763 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3764 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3765 | |
| 3766 | /* improve 10M EEE waveform */ |
| 3767 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3768 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3769 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3770 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3771 | |
| 3772 | /* Improve 2-pair detection performance */ |
| 3773 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3774 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3775 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3776 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3777 | |
| 3778 | /* EEE setting */ |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3779 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_1111, 0x0003, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3780 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3781 | rtl_writephy(tp, 0x05, 0x8b85); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3782 | rtl_w0w1_phy(tp, 0x06, 0x2000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3783 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3784 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3785 | rtl_writephy(tp, 0x1e, 0x0020); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3786 | rtl_w0w1_phy(tp, 0x15, 0x0100, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3787 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3788 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3789 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3790 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3791 | rtl_writephy(tp, 0x0d, 0x4007); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3792 | rtl_writephy(tp, 0x0e, 0x0006); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3793 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3794 | |
| 3795 | /* Green feature */ |
| 3796 | rtl_writephy(tp, 0x1f, 0x0003); |
Heiner Kallweit | 1814d6a | 2017-11-19 11:09:58 +0100 | [diff] [blame] | 3797 | rtl_w0w1_phy(tp, 0x19, 0x0001, 0x0000); |
| 3798 | rtl_w0w1_phy(tp, 0x10, 0x0400, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3799 | rtl_writephy(tp, 0x1f, 0x0000); |
Heiner Kallweit | b399a39 | 2017-11-19 11:15:46 +0100 | [diff] [blame] | 3800 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3801 | rtl_w0w1_phy(tp, 0x01, 0x0100, 0x0000); |
| 3802 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | e0c0755 | 2012-10-23 20:24:03 +0000 | [diff] [blame] | 3803 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3804 | /* Broken BIOS workaround: feed GigaMAC registers with MAC address. */ |
| 3805 | rtl_rar_exgmac_set(tp, tp->dev->dev_addr); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3806 | } |
| 3807 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3808 | static void rtl8168f_hw_phy_config(struct rtl8169_private *tp) |
| 3809 | { |
| 3810 | /* For 4-corner performance improve */ |
| 3811 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3812 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3813 | rtl_w0w1_phy(tp, 0x06, 0x0006, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3814 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3815 | |
| 3816 | /* PHY auto speed down */ |
| 3817 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3818 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3819 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3820 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3821 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3822 | |
| 3823 | /* Improve 10M EEE waveform */ |
| 3824 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3825 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3826 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3827 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3828 | } |
| 3829 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3830 | static void rtl8168f_1_hw_phy_config(struct rtl8169_private *tp) |
| 3831 | { |
| 3832 | static const struct phy_reg phy_reg_init[] = { |
| 3833 | /* Channel estimation fine tune */ |
| 3834 | { 0x1f, 0x0003 }, |
| 3835 | { 0x09, 0xa20f }, |
| 3836 | { 0x1f, 0x0000 }, |
| 3837 | |
| 3838 | /* Modify green table for giga & fnet */ |
| 3839 | { 0x1f, 0x0005 }, |
| 3840 | { 0x05, 0x8b55 }, |
| 3841 | { 0x06, 0x0000 }, |
| 3842 | { 0x05, 0x8b5e }, |
| 3843 | { 0x06, 0x0000 }, |
| 3844 | { 0x05, 0x8b67 }, |
| 3845 | { 0x06, 0x0000 }, |
| 3846 | { 0x05, 0x8b70 }, |
| 3847 | { 0x06, 0x0000 }, |
| 3848 | { 0x1f, 0x0000 }, |
| 3849 | { 0x1f, 0x0007 }, |
| 3850 | { 0x1e, 0x0078 }, |
| 3851 | { 0x17, 0x0000 }, |
| 3852 | { 0x19, 0x00fb }, |
| 3853 | { 0x1f, 0x0000 }, |
| 3854 | |
| 3855 | /* Modify green table for 10M */ |
| 3856 | { 0x1f, 0x0005 }, |
| 3857 | { 0x05, 0x8b79 }, |
| 3858 | { 0x06, 0xaa00 }, |
| 3859 | { 0x1f, 0x0000 }, |
| 3860 | |
| 3861 | /* Disable hiimpedance detection (RTCT) */ |
| 3862 | { 0x1f, 0x0003 }, |
| 3863 | { 0x01, 0x328a }, |
| 3864 | { 0x1f, 0x0000 } |
| 3865 | }; |
| 3866 | |
| 3867 | rtl_apply_firmware(tp); |
| 3868 | |
| 3869 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3870 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3871 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3872 | |
| 3873 | /* Improve 2-pair detection performance */ |
| 3874 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3875 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3876 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3877 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3878 | } |
| 3879 | |
| 3880 | static void rtl8168f_2_hw_phy_config(struct rtl8169_private *tp) |
| 3881 | { |
| 3882 | rtl_apply_firmware(tp); |
| 3883 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3884 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3885 | } |
| 3886 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3887 | static void rtl8411_hw_phy_config(struct rtl8169_private *tp) |
| 3888 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3889 | static const struct phy_reg phy_reg_init[] = { |
| 3890 | /* Channel estimation fine tune */ |
| 3891 | { 0x1f, 0x0003 }, |
| 3892 | { 0x09, 0xa20f }, |
| 3893 | { 0x1f, 0x0000 }, |
| 3894 | |
| 3895 | /* Modify green table for giga & fnet */ |
| 3896 | { 0x1f, 0x0005 }, |
| 3897 | { 0x05, 0x8b55 }, |
| 3898 | { 0x06, 0x0000 }, |
| 3899 | { 0x05, 0x8b5e }, |
| 3900 | { 0x06, 0x0000 }, |
| 3901 | { 0x05, 0x8b67 }, |
| 3902 | { 0x06, 0x0000 }, |
| 3903 | { 0x05, 0x8b70 }, |
| 3904 | { 0x06, 0x0000 }, |
| 3905 | { 0x1f, 0x0000 }, |
| 3906 | { 0x1f, 0x0007 }, |
| 3907 | { 0x1e, 0x0078 }, |
| 3908 | { 0x17, 0x0000 }, |
| 3909 | { 0x19, 0x00aa }, |
| 3910 | { 0x1f, 0x0000 }, |
| 3911 | |
| 3912 | /* Modify green table for 10M */ |
| 3913 | { 0x1f, 0x0005 }, |
| 3914 | { 0x05, 0x8b79 }, |
| 3915 | { 0x06, 0xaa00 }, |
| 3916 | { 0x1f, 0x0000 }, |
| 3917 | |
| 3918 | /* Disable hiimpedance detection (RTCT) */ |
| 3919 | { 0x1f, 0x0003 }, |
| 3920 | { 0x01, 0x328a }, |
| 3921 | { 0x1f, 0x0000 } |
| 3922 | }; |
| 3923 | |
| 3924 | |
| 3925 | rtl_apply_firmware(tp); |
| 3926 | |
| 3927 | rtl8168f_hw_phy_config(tp); |
| 3928 | |
| 3929 | /* Improve 2-pair detection performance */ |
| 3930 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3931 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3932 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3933 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3934 | |
| 3935 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3936 | |
| 3937 | /* Modify green table for giga */ |
| 3938 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3939 | rtl_writephy(tp, 0x05, 0x8b54); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3940 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3941 | rtl_writephy(tp, 0x05, 0x8b5d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3942 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3943 | rtl_writephy(tp, 0x05, 0x8a7c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3944 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3945 | rtl_writephy(tp, 0x05, 0x8a7f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3946 | rtl_w0w1_phy(tp, 0x06, 0x0100, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3947 | rtl_writephy(tp, 0x05, 0x8a82); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3948 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3949 | rtl_writephy(tp, 0x05, 0x8a85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3950 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3951 | rtl_writephy(tp, 0x05, 0x8a88); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3952 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3953 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3954 | |
| 3955 | /* uc same-seed solution */ |
| 3956 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3957 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3958 | rtl_w0w1_phy(tp, 0x06, 0x8000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3959 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3960 | |
| 3961 | /* eee setting */ |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 3962 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x00, 0x03, ERIAR_EXGMAC); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3963 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3964 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3965 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3966 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3967 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3968 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3969 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3970 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3971 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3972 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3973 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3974 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3975 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3976 | |
| 3977 | /* Green feature */ |
| 3978 | rtl_writephy(tp, 0x1f, 0x0003); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3979 | rtl_w0w1_phy(tp, 0x19, 0x0000, 0x0001); |
| 3980 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0400); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3981 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3982 | } |
| 3983 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3984 | static void rtl8168g_1_hw_phy_config(struct rtl8169_private *tp) |
| 3985 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3986 | rtl_apply_firmware(tp); |
| 3987 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3988 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3989 | if (rtl_readphy(tp, 0x10) & 0x0100) { |
| 3990 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3991 | rtl_w0w1_phy(tp, 0x12, 0x0000, 0x8000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3992 | } else { |
| 3993 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3994 | rtl_w0w1_phy(tp, 0x12, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3995 | } |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3996 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3997 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3998 | if (rtl_readphy(tp, 0x13) & 0x0100) { |
| 3999 | rtl_writephy(tp, 0x1f, 0x0c41); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4000 | rtl_w0w1_phy(tp, 0x15, 0x0002, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 4001 | } else { |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 4002 | rtl_writephy(tp, 0x1f, 0x0c41); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4003 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0002); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 4004 | } |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4005 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 4006 | /* Enable PHY auto speed down */ |
| 4007 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4008 | rtl_w0w1_phy(tp, 0x11, 0x000c, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4009 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 4010 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4011 | rtl_w0w1_phy(tp, 0x14, 0x0100, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 4012 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4013 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 4014 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4015 | rtl_writephy(tp, 0x13, 0x8084); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4016 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 4017 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 4018 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 4019 | /* EEE auto-fallback function */ |
| 4020 | rtl_writephy(tp, 0x1f, 0x0a4b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4021 | rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4022 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 4023 | /* Enable UC LPF tune function */ |
| 4024 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4025 | rtl_writephy(tp, 0x13, 0x8012); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4026 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 4027 | |
| 4028 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4029 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 4030 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 4031 | /* Improve SWR Efficiency */ |
| 4032 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4033 | rtl_writephy(tp, 0x14, 0x5065); |
| 4034 | rtl_writephy(tp, 0x14, 0xd065); |
| 4035 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 4036 | rtl_writephy(tp, 0x11, 0x5655); |
| 4037 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4038 | rtl_writephy(tp, 0x14, 0x1065); |
| 4039 | rtl_writephy(tp, 0x14, 0x9065); |
| 4040 | rtl_writephy(tp, 0x14, 0x1065); |
| 4041 | |
David Chang | 1bac107 | 2013-11-27 15:48:36 +0800 | [diff] [blame] | 4042 | /* Check ALDPS bit, disable it if enabled */ |
| 4043 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4044 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4045 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
David Chang | 1bac107 | 2013-11-27 15:48:36 +0800 | [diff] [blame] | 4046 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 4047 | rtl_writephy(tp, 0x1f, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4048 | } |
| 4049 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4050 | static void rtl8168g_2_hw_phy_config(struct rtl8169_private *tp) |
| 4051 | { |
| 4052 | rtl_apply_firmware(tp); |
| 4053 | } |
| 4054 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4055 | static void rtl8168h_1_hw_phy_config(struct rtl8169_private *tp) |
| 4056 | { |
| 4057 | u16 dout_tapbin; |
| 4058 | u32 data; |
| 4059 | |
| 4060 | rtl_apply_firmware(tp); |
| 4061 | |
| 4062 | /* CHN EST parameters adjust - giga master */ |
| 4063 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4064 | rtl_writephy(tp, 0x13, 0x809b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4065 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4066 | rtl_writephy(tp, 0x13, 0x80a2); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4067 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4068 | rtl_writephy(tp, 0x13, 0x80a4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4069 | rtl_w0w1_phy(tp, 0x14, 0x8500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4070 | rtl_writephy(tp, 0x13, 0x809c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4071 | rtl_w0w1_phy(tp, 0x14, 0xbd00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4072 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4073 | |
| 4074 | /* CHN EST parameters adjust - giga slave */ |
| 4075 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4076 | rtl_writephy(tp, 0x13, 0x80ad); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4077 | rtl_w0w1_phy(tp, 0x14, 0x7000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4078 | rtl_writephy(tp, 0x13, 0x80b4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4079 | rtl_w0w1_phy(tp, 0x14, 0x5000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4080 | rtl_writephy(tp, 0x13, 0x80ac); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4081 | rtl_w0w1_phy(tp, 0x14, 0x4000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4082 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4083 | |
| 4084 | /* CHN EST parameters adjust - fnet */ |
| 4085 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4086 | rtl_writephy(tp, 0x13, 0x808e); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4087 | rtl_w0w1_phy(tp, 0x14, 0x1200, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4088 | rtl_writephy(tp, 0x13, 0x8090); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4089 | rtl_w0w1_phy(tp, 0x14, 0xe500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4090 | rtl_writephy(tp, 0x13, 0x8092); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4091 | rtl_w0w1_phy(tp, 0x14, 0x9f00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4092 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4093 | |
| 4094 | /* enable R-tune & PGA-retune function */ |
| 4095 | dout_tapbin = 0; |
| 4096 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 4097 | data = rtl_readphy(tp, 0x13); |
| 4098 | data &= 3; |
| 4099 | data <<= 2; |
| 4100 | dout_tapbin |= data; |
| 4101 | data = rtl_readphy(tp, 0x12); |
| 4102 | data &= 0xc000; |
| 4103 | data >>= 14; |
| 4104 | dout_tapbin |= data; |
| 4105 | dout_tapbin = ~(dout_tapbin^0x08); |
| 4106 | dout_tapbin <<= 12; |
| 4107 | dout_tapbin &= 0xf000; |
| 4108 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4109 | rtl_writephy(tp, 0x13, 0x827a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4110 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4111 | rtl_writephy(tp, 0x13, 0x827b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4112 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4113 | rtl_writephy(tp, 0x13, 0x827c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4114 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4115 | rtl_writephy(tp, 0x13, 0x827d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4116 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4117 | |
| 4118 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4119 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4120 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4121 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4122 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4123 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4124 | |
| 4125 | /* enable GPHY 10M */ |
| 4126 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4127 | rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4128 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4129 | |
| 4130 | /* SAR ADC performance */ |
| 4131 | rtl_writephy(tp, 0x1f, 0x0bca); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4132 | rtl_w0w1_phy(tp, 0x17, 0x4000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4133 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4134 | |
| 4135 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4136 | rtl_writephy(tp, 0x13, 0x803f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4137 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4138 | rtl_writephy(tp, 0x13, 0x8047); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4139 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4140 | rtl_writephy(tp, 0x13, 0x804f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4141 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4142 | rtl_writephy(tp, 0x13, 0x8057); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4143 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4144 | rtl_writephy(tp, 0x13, 0x805f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4145 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4146 | rtl_writephy(tp, 0x13, 0x8067); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4147 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4148 | rtl_writephy(tp, 0x13, 0x806f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4149 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4150 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4151 | |
| 4152 | /* disable phy pfm mode */ |
| 4153 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | c832c35f | 2015-12-29 22:13:38 +0800 | [diff] [blame] | 4154 | rtl_w0w1_phy(tp, 0x11, 0x0000, 0x0080); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4155 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4156 | |
| 4157 | /* Check ALDPS bit, disable it if enabled */ |
| 4158 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4159 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4160 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4161 | |
| 4162 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4163 | } |
| 4164 | |
| 4165 | static void rtl8168h_2_hw_phy_config(struct rtl8169_private *tp) |
| 4166 | { |
| 4167 | u16 ioffset_p3, ioffset_p2, ioffset_p1, ioffset_p0; |
| 4168 | u16 rlen; |
| 4169 | u32 data; |
| 4170 | |
| 4171 | rtl_apply_firmware(tp); |
| 4172 | |
| 4173 | /* CHIN EST parameter update */ |
| 4174 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4175 | rtl_writephy(tp, 0x13, 0x808a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4176 | rtl_w0w1_phy(tp, 0x14, 0x000a, 0x003f); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4177 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4178 | |
| 4179 | /* enable R-tune & PGA-retune function */ |
| 4180 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4181 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4182 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4183 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4184 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4185 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4186 | |
| 4187 | /* enable GPHY 10M */ |
| 4188 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4189 | rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4190 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4191 | |
| 4192 | r8168_mac_ocp_write(tp, 0xdd02, 0x807d); |
| 4193 | data = r8168_mac_ocp_read(tp, 0xdd02); |
| 4194 | ioffset_p3 = ((data & 0x80)>>7); |
| 4195 | ioffset_p3 <<= 3; |
| 4196 | |
| 4197 | data = r8168_mac_ocp_read(tp, 0xdd00); |
| 4198 | ioffset_p3 |= ((data & (0xe000))>>13); |
| 4199 | ioffset_p2 = ((data & (0x1e00))>>9); |
| 4200 | ioffset_p1 = ((data & (0x01e0))>>5); |
| 4201 | ioffset_p0 = ((data & 0x0010)>>4); |
| 4202 | ioffset_p0 <<= 3; |
| 4203 | ioffset_p0 |= (data & (0x07)); |
| 4204 | data = (ioffset_p3<<12)|(ioffset_p2<<8)|(ioffset_p1<<4)|(ioffset_p0); |
| 4205 | |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 4206 | if ((ioffset_p3 != 0x0f) || (ioffset_p2 != 0x0f) || |
Chun-Hao Lin | e2e2788 | 2015-12-24 21:15:26 +0800 | [diff] [blame] | 4207 | (ioffset_p1 != 0x0f) || (ioffset_p0 != 0x0f)) { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4208 | rtl_writephy(tp, 0x1f, 0x0bcf); |
| 4209 | rtl_writephy(tp, 0x16, data); |
| 4210 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4211 | } |
| 4212 | |
| 4213 | /* Modify rlen (TX LPF corner frequency) level */ |
| 4214 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4215 | data = rtl_readphy(tp, 0x16); |
| 4216 | data &= 0x000f; |
| 4217 | rlen = 0; |
| 4218 | if (data > 3) |
| 4219 | rlen = data - 3; |
| 4220 | data = rlen | (rlen<<4) | (rlen<<8) | (rlen<<12); |
| 4221 | rtl_writephy(tp, 0x17, data); |
| 4222 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4223 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4224 | |
| 4225 | /* disable phy pfm mode */ |
| 4226 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | c832c35f | 2015-12-29 22:13:38 +0800 | [diff] [blame] | 4227 | rtl_w0w1_phy(tp, 0x11, 0x0000, 0x0080); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4228 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4229 | |
| 4230 | /* Check ALDPS bit, disable it if enabled */ |
| 4231 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4232 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 4233 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4234 | |
| 4235 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4236 | } |
| 4237 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4238 | static void rtl8168ep_1_hw_phy_config(struct rtl8169_private *tp) |
| 4239 | { |
| 4240 | /* Enable PHY auto speed down */ |
| 4241 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 4242 | rtl_w0w1_phy(tp, 0x11, 0x000c, 0x0000); |
| 4243 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4244 | |
| 4245 | /* patch 10M & ALDPS */ |
| 4246 | rtl_writephy(tp, 0x1f, 0x0bcc); |
| 4247 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x0100); |
| 4248 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 4249 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
| 4250 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4251 | rtl_writephy(tp, 0x13, 0x8084); |
| 4252 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 4253 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
| 4254 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4255 | |
| 4256 | /* Enable EEE auto-fallback function */ |
| 4257 | rtl_writephy(tp, 0x1f, 0x0a4b); |
| 4258 | rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000); |
| 4259 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4260 | |
| 4261 | /* Enable UC LPF tune function */ |
| 4262 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4263 | rtl_writephy(tp, 0x13, 0x8012); |
| 4264 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 4265 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4266 | |
| 4267 | /* set rg_sel_sdm_rate */ |
| 4268 | rtl_writephy(tp, 0x1f, 0x0c42); |
| 4269 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
| 4270 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4271 | |
| 4272 | /* Check ALDPS bit, disable it if enabled */ |
| 4273 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4274 | if (rtl_readphy(tp, 0x10) & 0x0004) |
| 4275 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
| 4276 | |
| 4277 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4278 | } |
| 4279 | |
| 4280 | static void rtl8168ep_2_hw_phy_config(struct rtl8169_private *tp) |
| 4281 | { |
| 4282 | /* patch 10M & ALDPS */ |
| 4283 | rtl_writephy(tp, 0x1f, 0x0bcc); |
| 4284 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x0100); |
| 4285 | rtl_writephy(tp, 0x1f, 0x0a44); |
| 4286 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
| 4287 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4288 | rtl_writephy(tp, 0x13, 0x8084); |
| 4289 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 4290 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
| 4291 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4292 | |
| 4293 | /* Enable UC LPF tune function */ |
| 4294 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4295 | rtl_writephy(tp, 0x13, 0x8012); |
| 4296 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
| 4297 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4298 | |
| 4299 | /* Set rg_sel_sdm_rate */ |
| 4300 | rtl_writephy(tp, 0x1f, 0x0c42); |
| 4301 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
| 4302 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4303 | |
| 4304 | /* Channel estimation parameters */ |
| 4305 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4306 | rtl_writephy(tp, 0x13, 0x80f3); |
| 4307 | rtl_w0w1_phy(tp, 0x14, 0x8b00, ~0x8bff); |
| 4308 | rtl_writephy(tp, 0x13, 0x80f0); |
| 4309 | rtl_w0w1_phy(tp, 0x14, 0x3a00, ~0x3aff); |
| 4310 | rtl_writephy(tp, 0x13, 0x80ef); |
| 4311 | rtl_w0w1_phy(tp, 0x14, 0x0500, ~0x05ff); |
| 4312 | rtl_writephy(tp, 0x13, 0x80f6); |
| 4313 | rtl_w0w1_phy(tp, 0x14, 0x6e00, ~0x6eff); |
| 4314 | rtl_writephy(tp, 0x13, 0x80ec); |
| 4315 | rtl_w0w1_phy(tp, 0x14, 0x6800, ~0x68ff); |
| 4316 | rtl_writephy(tp, 0x13, 0x80ed); |
| 4317 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 4318 | rtl_writephy(tp, 0x13, 0x80f2); |
| 4319 | rtl_w0w1_phy(tp, 0x14, 0xf400, ~0xf4ff); |
| 4320 | rtl_writephy(tp, 0x13, 0x80f4); |
| 4321 | rtl_w0w1_phy(tp, 0x14, 0x8500, ~0x85ff); |
| 4322 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4323 | rtl_writephy(tp, 0x13, 0x8110); |
| 4324 | rtl_w0w1_phy(tp, 0x14, 0xa800, ~0xa8ff); |
| 4325 | rtl_writephy(tp, 0x13, 0x810f); |
| 4326 | rtl_w0w1_phy(tp, 0x14, 0x1d00, ~0x1dff); |
| 4327 | rtl_writephy(tp, 0x13, 0x8111); |
| 4328 | rtl_w0w1_phy(tp, 0x14, 0xf500, ~0xf5ff); |
| 4329 | rtl_writephy(tp, 0x13, 0x8113); |
| 4330 | rtl_w0w1_phy(tp, 0x14, 0x6100, ~0x61ff); |
| 4331 | rtl_writephy(tp, 0x13, 0x8115); |
| 4332 | rtl_w0w1_phy(tp, 0x14, 0x9200, ~0x92ff); |
| 4333 | rtl_writephy(tp, 0x13, 0x810e); |
| 4334 | rtl_w0w1_phy(tp, 0x14, 0x0400, ~0x04ff); |
| 4335 | rtl_writephy(tp, 0x13, 0x810c); |
| 4336 | rtl_w0w1_phy(tp, 0x14, 0x7c00, ~0x7cff); |
| 4337 | rtl_writephy(tp, 0x13, 0x810b); |
| 4338 | rtl_w0w1_phy(tp, 0x14, 0x5a00, ~0x5aff); |
| 4339 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4340 | rtl_writephy(tp, 0x13, 0x80d1); |
| 4341 | rtl_w0w1_phy(tp, 0x14, 0xff00, ~0xffff); |
| 4342 | rtl_writephy(tp, 0x13, 0x80cd); |
| 4343 | rtl_w0w1_phy(tp, 0x14, 0x9e00, ~0x9eff); |
| 4344 | rtl_writephy(tp, 0x13, 0x80d3); |
| 4345 | rtl_w0w1_phy(tp, 0x14, 0x0e00, ~0x0eff); |
| 4346 | rtl_writephy(tp, 0x13, 0x80d5); |
| 4347 | rtl_w0w1_phy(tp, 0x14, 0xca00, ~0xcaff); |
| 4348 | rtl_writephy(tp, 0x13, 0x80d7); |
| 4349 | rtl_w0w1_phy(tp, 0x14, 0x8400, ~0x84ff); |
| 4350 | |
| 4351 | /* Force PWM-mode */ |
| 4352 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4353 | rtl_writephy(tp, 0x14, 0x5065); |
| 4354 | rtl_writephy(tp, 0x14, 0xd065); |
| 4355 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 4356 | rtl_writephy(tp, 0x12, 0x00ed); |
| 4357 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 4358 | rtl_writephy(tp, 0x14, 0x1065); |
| 4359 | rtl_writephy(tp, 0x14, 0x9065); |
| 4360 | rtl_writephy(tp, 0x14, 0x1065); |
| 4361 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4362 | |
| 4363 | /* Check ALDPS bit, disable it if enabled */ |
| 4364 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 4365 | if (rtl_readphy(tp, 0x10) & 0x0004) |
| 4366 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
| 4367 | |
| 4368 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4369 | } |
| 4370 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4371 | static void rtl8102e_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4372 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4373 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4374 | { 0x1f, 0x0003 }, |
| 4375 | { 0x08, 0x441d }, |
| 4376 | { 0x01, 0x9100 }, |
| 4377 | { 0x1f, 0x0000 } |
| 4378 | }; |
| 4379 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4380 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4381 | rtl_patchphy(tp, 0x11, 1 << 12); |
| 4382 | rtl_patchphy(tp, 0x19, 1 << 13); |
| 4383 | rtl_patchphy(tp, 0x10, 1 << 15); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4384 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4385 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4386 | } |
| 4387 | |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4388 | static void rtl8105e_hw_phy_config(struct rtl8169_private *tp) |
| 4389 | { |
| 4390 | static const struct phy_reg phy_reg_init[] = { |
| 4391 | { 0x1f, 0x0005 }, |
| 4392 | { 0x1a, 0x0000 }, |
| 4393 | { 0x1f, 0x0000 }, |
| 4394 | |
| 4395 | { 0x1f, 0x0004 }, |
| 4396 | { 0x1c, 0x0000 }, |
| 4397 | { 0x1f, 0x0000 }, |
| 4398 | |
| 4399 | { 0x1f, 0x0001 }, |
| 4400 | { 0x15, 0x7701 }, |
| 4401 | { 0x1f, 0x0000 } |
| 4402 | }; |
| 4403 | |
| 4404 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 4405 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4406 | rtl_writephy(tp, 0x18, 0x0310); |
| 4407 | msleep(100); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4408 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4409 | rtl_apply_firmware(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4410 | |
| 4411 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 4412 | } |
| 4413 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4414 | static void rtl8402_hw_phy_config(struct rtl8169_private *tp) |
| 4415 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4416 | /* Disable ALDPS before setting firmware */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 4417 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4418 | rtl_writephy(tp, 0x18, 0x0310); |
| 4419 | msleep(20); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4420 | |
| 4421 | rtl_apply_firmware(tp); |
| 4422 | |
| 4423 | /* EEE setting */ |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4424 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4425 | rtl_writephy(tp, 0x1f, 0x0004); |
| 4426 | rtl_writephy(tp, 0x10, 0x401f); |
| 4427 | rtl_writephy(tp, 0x19, 0x7030); |
| 4428 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4429 | } |
| 4430 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4431 | static void rtl8106e_hw_phy_config(struct rtl8169_private *tp) |
| 4432 | { |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4433 | static const struct phy_reg phy_reg_init[] = { |
| 4434 | { 0x1f, 0x0004 }, |
| 4435 | { 0x10, 0xc07f }, |
| 4436 | { 0x19, 0x7030 }, |
| 4437 | { 0x1f, 0x0000 } |
| 4438 | }; |
| 4439 | |
| 4440 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 4441 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4442 | rtl_writephy(tp, 0x18, 0x0310); |
| 4443 | msleep(100); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4444 | |
| 4445 | rtl_apply_firmware(tp); |
| 4446 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4447 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4448 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 4449 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4450 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4451 | } |
| 4452 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4453 | static void rtl_hw_phy_config(struct net_device *dev) |
| 4454 | { |
| 4455 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4456 | |
| 4457 | rtl8169_print_mac_version(tp); |
| 4458 | |
| 4459 | switch (tp->mac_version) { |
| 4460 | case RTL_GIGA_MAC_VER_01: |
| 4461 | break; |
| 4462 | case RTL_GIGA_MAC_VER_02: |
| 4463 | case RTL_GIGA_MAC_VER_03: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4464 | rtl8169s_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4465 | break; |
| 4466 | case RTL_GIGA_MAC_VER_04: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4467 | rtl8169sb_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4468 | break; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 4469 | case RTL_GIGA_MAC_VER_05: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4470 | rtl8169scd_hw_phy_config(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 4471 | break; |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 4472 | case RTL_GIGA_MAC_VER_06: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4473 | rtl8169sce_hw_phy_config(tp); |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 4474 | break; |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4475 | case RTL_GIGA_MAC_VER_07: |
| 4476 | case RTL_GIGA_MAC_VER_08: |
| 4477 | case RTL_GIGA_MAC_VER_09: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4478 | rtl8102e_hw_phy_config(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4479 | break; |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4480 | case RTL_GIGA_MAC_VER_11: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4481 | rtl8168bb_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4482 | break; |
| 4483 | case RTL_GIGA_MAC_VER_12: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4484 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4485 | break; |
| 4486 | case RTL_GIGA_MAC_VER_17: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4487 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 4488 | break; |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 4489 | case RTL_GIGA_MAC_VER_18: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4490 | rtl8168cp_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 4491 | break; |
| 4492 | case RTL_GIGA_MAC_VER_19: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4493 | rtl8168c_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 4494 | break; |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 4495 | case RTL_GIGA_MAC_VER_20: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4496 | rtl8168c_2_hw_phy_config(tp); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 4497 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4498 | case RTL_GIGA_MAC_VER_21: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4499 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4500 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4501 | case RTL_GIGA_MAC_VER_22: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4502 | rtl8168c_4_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4503 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4504 | case RTL_GIGA_MAC_VER_23: |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4505 | case RTL_GIGA_MAC_VER_24: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4506 | rtl8168cp_2_hw_phy_config(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4507 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4508 | case RTL_GIGA_MAC_VER_25: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 4509 | rtl8168d_1_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 4510 | break; |
| 4511 | case RTL_GIGA_MAC_VER_26: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 4512 | rtl8168d_2_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 4513 | break; |
| 4514 | case RTL_GIGA_MAC_VER_27: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4515 | rtl8168d_3_hw_phy_config(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4516 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4517 | case RTL_GIGA_MAC_VER_28: |
| 4518 | rtl8168d_4_hw_phy_config(tp); |
| 4519 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4520 | case RTL_GIGA_MAC_VER_29: |
| 4521 | case RTL_GIGA_MAC_VER_30: |
| 4522 | rtl8105e_hw_phy_config(tp); |
| 4523 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4524 | case RTL_GIGA_MAC_VER_31: |
| 4525 | /* None. */ |
| 4526 | break; |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4527 | case RTL_GIGA_MAC_VER_32: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4528 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4529 | rtl8168e_1_hw_phy_config(tp); |
| 4530 | break; |
| 4531 | case RTL_GIGA_MAC_VER_34: |
| 4532 | rtl8168e_2_hw_phy_config(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4533 | break; |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4534 | case RTL_GIGA_MAC_VER_35: |
| 4535 | rtl8168f_1_hw_phy_config(tp); |
| 4536 | break; |
| 4537 | case RTL_GIGA_MAC_VER_36: |
| 4538 | rtl8168f_2_hw_phy_config(tp); |
| 4539 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4540 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4541 | case RTL_GIGA_MAC_VER_37: |
| 4542 | rtl8402_hw_phy_config(tp); |
| 4543 | break; |
| 4544 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4545 | case RTL_GIGA_MAC_VER_38: |
| 4546 | rtl8411_hw_phy_config(tp); |
| 4547 | break; |
| 4548 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4549 | case RTL_GIGA_MAC_VER_39: |
| 4550 | rtl8106e_hw_phy_config(tp); |
| 4551 | break; |
| 4552 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4553 | case RTL_GIGA_MAC_VER_40: |
| 4554 | rtl8168g_1_hw_phy_config(tp); |
| 4555 | break; |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4556 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 4557 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4558 | case RTL_GIGA_MAC_VER_44: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4559 | rtl8168g_2_hw_phy_config(tp); |
| 4560 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4561 | case RTL_GIGA_MAC_VER_45: |
| 4562 | case RTL_GIGA_MAC_VER_47: |
| 4563 | rtl8168h_1_hw_phy_config(tp); |
| 4564 | break; |
| 4565 | case RTL_GIGA_MAC_VER_46: |
| 4566 | case RTL_GIGA_MAC_VER_48: |
| 4567 | rtl8168h_2_hw_phy_config(tp); |
| 4568 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4569 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4570 | case RTL_GIGA_MAC_VER_49: |
| 4571 | rtl8168ep_1_hw_phy_config(tp); |
| 4572 | break; |
| 4573 | case RTL_GIGA_MAC_VER_50: |
| 4574 | case RTL_GIGA_MAC_VER_51: |
| 4575 | rtl8168ep_2_hw_phy_config(tp); |
| 4576 | break; |
| 4577 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4578 | case RTL_GIGA_MAC_VER_41: |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4579 | default: |
| 4580 | break; |
| 4581 | } |
| 4582 | } |
| 4583 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4584 | static void rtl_phy_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4585 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4586 | struct timer_list *timer = &tp->timer; |
| 4587 | void __iomem *ioaddr = tp->mmio_addr; |
| 4588 | unsigned long timeout = RTL8169_PHY_TIMEOUT; |
| 4589 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4590 | assert(tp->mac_version > RTL_GIGA_MAC_VER_01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4591 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4592 | if (tp->phy_reset_pending(tp)) { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 4593 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4594 | * A busy loop could burn quite a few cycles on nowadays CPU. |
| 4595 | * Let's delay the execution of the timer for a few ticks. |
| 4596 | */ |
| 4597 | timeout = HZ/10; |
| 4598 | goto out_mod_timer; |
| 4599 | } |
| 4600 | |
| 4601 | if (tp->link_ok(ioaddr)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4602 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4603 | |
Lekensteyn | 9bb8eeb | 2013-08-02 10:36:55 +0200 | [diff] [blame] | 4604 | netif_dbg(tp, link, tp->dev, "PHY reset until link up\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4605 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4606 | tp->phy_reset_enable(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4607 | |
| 4608 | out_mod_timer: |
| 4609 | mod_timer(timer, jiffies + timeout); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4610 | } |
| 4611 | |
| 4612 | static void rtl_schedule_task(struct rtl8169_private *tp, enum rtl_flag flag) |
| 4613 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4614 | if (!test_and_set_bit(flag, tp->wk.flags)) |
| 4615 | schedule_work(&tp->wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4616 | } |
| 4617 | |
Kees Cook | 9de36cc | 2017-10-25 03:53:12 -0700 | [diff] [blame] | 4618 | static void rtl8169_phy_timer(struct timer_list *t) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4619 | { |
Kees Cook | 9de36cc | 2017-10-25 03:53:12 -0700 | [diff] [blame] | 4620 | struct rtl8169_private *tp = from_timer(tp, t, timer); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4621 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 4622 | rtl_schedule_task(tp, RTL_FLAG_TASK_PHY_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4623 | } |
| 4624 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4625 | DECLARE_RTL_COND(rtl_phy_reset_cond) |
| 4626 | { |
| 4627 | return tp->phy_reset_pending(tp); |
| 4628 | } |
| 4629 | |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 4630 | static void rtl8169_phy_reset(struct net_device *dev, |
| 4631 | struct rtl8169_private *tp) |
| 4632 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4633 | tp->phy_reset_enable(tp); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4634 | rtl_msleep_loop_wait_low(tp, &rtl_phy_reset_cond, 1, 100); |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 4635 | } |
| 4636 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4637 | static bool rtl_tbi_enabled(struct rtl8169_private *tp) |
| 4638 | { |
| 4639 | void __iomem *ioaddr = tp->mmio_addr; |
| 4640 | |
| 4641 | return (tp->mac_version == RTL_GIGA_MAC_VER_01) && |
| 4642 | (RTL_R8(PHYstatus) & TBI_Enable); |
| 4643 | } |
| 4644 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4645 | 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] | 4646 | { |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4647 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4648 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4649 | rtl_hw_phy_config(dev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4650 | |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 4651 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
| 4652 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
| 4653 | RTL_W8(0x82, 0x01); |
| 4654 | } |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4655 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4656 | pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); |
| 4657 | |
| 4658 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
| 4659 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4660 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4661 | if (tp->mac_version == RTL_GIGA_MAC_VER_02) { |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4662 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
| 4663 | RTL_W8(0x82, 0x01); |
| 4664 | dprintk("Set PHY Reg 0x0bh = 0x00h\n"); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4665 | rtl_writephy(tp, 0x0b, 0x0000); //w 0x0b 15 0 0 |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4666 | } |
| 4667 | |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 4668 | rtl8169_phy_reset(dev, tp); |
| 4669 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 4670 | rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4671 | ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 4672 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 4673 | (tp->mii.supports_gmii ? |
| 4674 | ADVERTISED_1000baseT_Half | |
| 4675 | ADVERTISED_1000baseT_Full : 0)); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4676 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4677 | if (rtl_tbi_enabled(tp)) |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 4678 | netif_info(tp, link, dev, "TBI auto-negotiating\n"); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4679 | } |
| 4680 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4681 | static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr) |
| 4682 | { |
| 4683 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4684 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4685 | rtl_lock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4686 | |
| 4687 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4688 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 4689 | RTL_W32(MAC4, addr[4] | addr[5] << 8); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4690 | RTL_R32(MAC4); |
| 4691 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 4692 | RTL_W32(MAC0, addr[0] | addr[1] << 8 | addr[2] << 16 | addr[3] << 24); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4693 | RTL_R32(MAC0); |
| 4694 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 4695 | if (tp->mac_version == RTL_GIGA_MAC_VER_34) |
| 4696 | rtl_rar_exgmac_set(tp, addr); |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 4697 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4698 | RTL_W8(Cfg9346, Cfg9346_Lock); |
| 4699 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4700 | rtl_unlock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4701 | } |
| 4702 | |
| 4703 | static int rtl_set_mac_address(struct net_device *dev, void *p) |
| 4704 | { |
| 4705 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 4706 | struct device *d = &tp->pci_dev->dev; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4707 | struct sockaddr *addr = p; |
| 4708 | |
| 4709 | if (!is_valid_ether_addr(addr->sa_data)) |
| 4710 | return -EADDRNOTAVAIL; |
| 4711 | |
| 4712 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 4713 | |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 4714 | pm_runtime_get_noresume(d); |
| 4715 | |
| 4716 | if (pm_runtime_active(d)) |
| 4717 | rtl_rar_set(tp, dev->dev_addr); |
| 4718 | |
| 4719 | pm_runtime_put_noidle(d); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4720 | |
| 4721 | return 0; |
| 4722 | } |
| 4723 | |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4724 | static int rtl8169_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 4725 | { |
| 4726 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4727 | struct mii_ioctl_data *data = if_mii(ifr); |
| 4728 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4729 | return netif_running(dev) ? tp->do_ioctl(tp, data, cmd) : -ENODEV; |
| 4730 | } |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4731 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4732 | static int rtl_xmii_ioctl(struct rtl8169_private *tp, |
| 4733 | struct mii_ioctl_data *data, int cmd) |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4734 | { |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4735 | switch (cmd) { |
| 4736 | case SIOCGMIIPHY: |
| 4737 | data->phy_id = 32; /* Internal PHY */ |
| 4738 | return 0; |
| 4739 | |
| 4740 | case SIOCGMIIREG: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4741 | data->val_out = rtl_readphy(tp, data->reg_num & 0x1f); |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4742 | return 0; |
| 4743 | |
| 4744 | case SIOCSMIIREG: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4745 | rtl_writephy(tp, data->reg_num & 0x1f, data->val_in); |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4746 | return 0; |
| 4747 | } |
| 4748 | return -EOPNOTSUPP; |
| 4749 | } |
| 4750 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4751 | static int rtl_tbi_ioctl(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd) |
| 4752 | { |
| 4753 | return -EOPNOTSUPP; |
| 4754 | } |
| 4755 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 4756 | static void rtl_init_mdio_ops(struct rtl8169_private *tp) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4757 | { |
| 4758 | struct mdio_ops *ops = &tp->mdio_ops; |
| 4759 | |
| 4760 | switch (tp->mac_version) { |
| 4761 | case RTL_GIGA_MAC_VER_27: |
| 4762 | ops->write = r8168dp_1_mdio_write; |
| 4763 | ops->read = r8168dp_1_mdio_read; |
| 4764 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4765 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4766 | case RTL_GIGA_MAC_VER_31: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4767 | ops->write = r8168dp_2_mdio_write; |
| 4768 | ops->read = r8168dp_2_mdio_read; |
| 4769 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4770 | case RTL_GIGA_MAC_VER_40: |
| 4771 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4772 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 4773 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4774 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4775 | case RTL_GIGA_MAC_VER_45: |
| 4776 | case RTL_GIGA_MAC_VER_46: |
| 4777 | case RTL_GIGA_MAC_VER_47: |
| 4778 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4779 | case RTL_GIGA_MAC_VER_49: |
| 4780 | case RTL_GIGA_MAC_VER_50: |
| 4781 | case RTL_GIGA_MAC_VER_51: |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4782 | ops->write = r8168g_mdio_write; |
| 4783 | ops->read = r8168g_mdio_read; |
| 4784 | break; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4785 | default: |
| 4786 | ops->write = r8169_mdio_write; |
| 4787 | ops->read = r8169_mdio_read; |
| 4788 | break; |
| 4789 | } |
| 4790 | } |
| 4791 | |
hayeswang | e2409d8 | 2013-03-31 17:02:04 +0000 | [diff] [blame] | 4792 | static void rtl_speed_down(struct rtl8169_private *tp) |
| 4793 | { |
| 4794 | u32 adv; |
| 4795 | int lpa; |
| 4796 | |
| 4797 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4798 | lpa = rtl_readphy(tp, MII_LPA); |
| 4799 | |
| 4800 | if (lpa & (LPA_10HALF | LPA_10FULL)) |
| 4801 | adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full; |
| 4802 | else if (lpa & (LPA_100HALF | LPA_100FULL)) |
| 4803 | adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 4804 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full; |
| 4805 | else |
| 4806 | adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 4807 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 4808 | (tp->mii.supports_gmii ? |
| 4809 | ADVERTISED_1000baseT_Half | |
| 4810 | ADVERTISED_1000baseT_Full : 0); |
| 4811 | |
| 4812 | rtl8169_set_speed(tp->dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL, |
| 4813 | adv); |
| 4814 | } |
| 4815 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4816 | static void rtl_wol_suspend_quirk(struct rtl8169_private *tp) |
| 4817 | { |
| 4818 | void __iomem *ioaddr = tp->mmio_addr; |
| 4819 | |
| 4820 | switch (tp->mac_version) { |
Cyril Brulebois | b00e69d | 2012-10-31 14:00:46 +0000 | [diff] [blame] | 4821 | case RTL_GIGA_MAC_VER_25: |
| 4822 | case RTL_GIGA_MAC_VER_26: |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4823 | case RTL_GIGA_MAC_VER_29: |
| 4824 | case RTL_GIGA_MAC_VER_30: |
| 4825 | case RTL_GIGA_MAC_VER_32: |
| 4826 | case RTL_GIGA_MAC_VER_33: |
| 4827 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4828 | case RTL_GIGA_MAC_VER_37: |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4829 | case RTL_GIGA_MAC_VER_38: |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4830 | case RTL_GIGA_MAC_VER_39: |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4831 | case RTL_GIGA_MAC_VER_40: |
| 4832 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4833 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 4834 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4835 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4836 | case RTL_GIGA_MAC_VER_45: |
| 4837 | case RTL_GIGA_MAC_VER_46: |
| 4838 | case RTL_GIGA_MAC_VER_47: |
| 4839 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4840 | case RTL_GIGA_MAC_VER_49: |
| 4841 | case RTL_GIGA_MAC_VER_50: |
| 4842 | case RTL_GIGA_MAC_VER_51: |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4843 | RTL_W32(RxConfig, RTL_R32(RxConfig) | |
| 4844 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys); |
| 4845 | break; |
| 4846 | default: |
| 4847 | break; |
| 4848 | } |
| 4849 | } |
| 4850 | |
| 4851 | static bool rtl_wol_pll_power_down(struct rtl8169_private *tp) |
| 4852 | { |
| 4853 | if (!(__rtl8169_get_wol(tp) & WAKE_ANY)) |
| 4854 | return false; |
| 4855 | |
hayeswang | e2409d8 | 2013-03-31 17:02:04 +0000 | [diff] [blame] | 4856 | rtl_speed_down(tp); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4857 | rtl_wol_suspend_quirk(tp); |
| 4858 | |
| 4859 | return true; |
| 4860 | } |
| 4861 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4862 | static void r810x_phy_power_down(struct rtl8169_private *tp) |
| 4863 | { |
| 4864 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4865 | rtl_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 4866 | } |
| 4867 | |
| 4868 | static void r810x_phy_power_up(struct rtl8169_private *tp) |
| 4869 | { |
| 4870 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4871 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE); |
| 4872 | } |
| 4873 | |
| 4874 | static void r810x_pll_power_down(struct rtl8169_private *tp) |
| 4875 | { |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 4876 | void __iomem *ioaddr = tp->mmio_addr; |
| 4877 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4878 | if (rtl_wol_pll_power_down(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4879 | return; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4880 | |
| 4881 | r810x_phy_power_down(tp); |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 4882 | |
| 4883 | switch (tp->mac_version) { |
| 4884 | case RTL_GIGA_MAC_VER_07: |
| 4885 | case RTL_GIGA_MAC_VER_08: |
| 4886 | case RTL_GIGA_MAC_VER_09: |
| 4887 | case RTL_GIGA_MAC_VER_10: |
| 4888 | case RTL_GIGA_MAC_VER_13: |
| 4889 | case RTL_GIGA_MAC_VER_16: |
| 4890 | break; |
| 4891 | default: |
| 4892 | RTL_W8(PMCH, RTL_R8(PMCH) & ~0x80); |
| 4893 | break; |
| 4894 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4895 | } |
| 4896 | |
| 4897 | static void r810x_pll_power_up(struct rtl8169_private *tp) |
| 4898 | { |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 4899 | void __iomem *ioaddr = tp->mmio_addr; |
| 4900 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4901 | r810x_phy_power_up(tp); |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 4902 | |
| 4903 | switch (tp->mac_version) { |
| 4904 | case RTL_GIGA_MAC_VER_07: |
| 4905 | case RTL_GIGA_MAC_VER_08: |
| 4906 | case RTL_GIGA_MAC_VER_09: |
| 4907 | case RTL_GIGA_MAC_VER_10: |
| 4908 | case RTL_GIGA_MAC_VER_13: |
| 4909 | case RTL_GIGA_MAC_VER_16: |
| 4910 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4911 | case RTL_GIGA_MAC_VER_47: |
| 4912 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 4913 | RTL_W8(PMCH, RTL_R8(PMCH) | 0xc0); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4914 | break; |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 4915 | default: |
| 4916 | RTL_W8(PMCH, RTL_R8(PMCH) | 0x80); |
| 4917 | break; |
| 4918 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4919 | } |
| 4920 | |
| 4921 | static void r8168_phy_power_up(struct rtl8169_private *tp) |
| 4922 | { |
| 4923 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4924 | switch (tp->mac_version) { |
| 4925 | case RTL_GIGA_MAC_VER_11: |
| 4926 | case RTL_GIGA_MAC_VER_12: |
| 4927 | case RTL_GIGA_MAC_VER_17: |
| 4928 | case RTL_GIGA_MAC_VER_18: |
| 4929 | case RTL_GIGA_MAC_VER_19: |
| 4930 | case RTL_GIGA_MAC_VER_20: |
| 4931 | case RTL_GIGA_MAC_VER_21: |
| 4932 | case RTL_GIGA_MAC_VER_22: |
| 4933 | case RTL_GIGA_MAC_VER_23: |
| 4934 | case RTL_GIGA_MAC_VER_24: |
| 4935 | case RTL_GIGA_MAC_VER_25: |
| 4936 | case RTL_GIGA_MAC_VER_26: |
| 4937 | case RTL_GIGA_MAC_VER_27: |
| 4938 | case RTL_GIGA_MAC_VER_28: |
| 4939 | case RTL_GIGA_MAC_VER_31: |
| 4940 | rtl_writephy(tp, 0x0e, 0x0000); |
| 4941 | break; |
| 4942 | default: |
| 4943 | break; |
| 4944 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4945 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE); |
| 4946 | } |
| 4947 | |
| 4948 | static void r8168_phy_power_down(struct rtl8169_private *tp) |
| 4949 | { |
| 4950 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4951 | switch (tp->mac_version) { |
| 4952 | case RTL_GIGA_MAC_VER_32: |
| 4953 | case RTL_GIGA_MAC_VER_33: |
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: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4956 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE | BMCR_PDOWN); |
| 4957 | break; |
| 4958 | |
| 4959 | case RTL_GIGA_MAC_VER_11: |
| 4960 | case RTL_GIGA_MAC_VER_12: |
| 4961 | case RTL_GIGA_MAC_VER_17: |
| 4962 | case RTL_GIGA_MAC_VER_18: |
| 4963 | case RTL_GIGA_MAC_VER_19: |
| 4964 | case RTL_GIGA_MAC_VER_20: |
| 4965 | case RTL_GIGA_MAC_VER_21: |
| 4966 | case RTL_GIGA_MAC_VER_22: |
| 4967 | case RTL_GIGA_MAC_VER_23: |
| 4968 | case RTL_GIGA_MAC_VER_24: |
| 4969 | case RTL_GIGA_MAC_VER_25: |
| 4970 | case RTL_GIGA_MAC_VER_26: |
| 4971 | case RTL_GIGA_MAC_VER_27: |
| 4972 | case RTL_GIGA_MAC_VER_28: |
| 4973 | case RTL_GIGA_MAC_VER_31: |
| 4974 | rtl_writephy(tp, 0x0e, 0x0200); |
| 4975 | default: |
| 4976 | rtl_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 4977 | break; |
| 4978 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4979 | } |
| 4980 | |
| 4981 | static void r8168_pll_power_down(struct rtl8169_private *tp) |
| 4982 | { |
| 4983 | void __iomem *ioaddr = tp->mmio_addr; |
| 4984 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4985 | if ((tp->mac_version == RTL_GIGA_MAC_VER_27 || |
| 4986 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 4987 | tp->mac_version == RTL_GIGA_MAC_VER_31 || |
| 4988 | tp->mac_version == RTL_GIGA_MAC_VER_49 || |
| 4989 | tp->mac_version == RTL_GIGA_MAC_VER_50 || |
| 4990 | tp->mac_version == RTL_GIGA_MAC_VER_51) && |
Chun-Hao Lin | 2f8c040 | 2014-10-01 23:17:19 +0800 | [diff] [blame] | 4991 | r8168_check_dash(tp)) { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4992 | return; |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 4993 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4994 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4995 | if ((tp->mac_version == RTL_GIGA_MAC_VER_23 || |
| 4996 | tp->mac_version == RTL_GIGA_MAC_VER_24) && |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4997 | (RTL_R16(CPlusCmd) & ASF)) { |
| 4998 | return; |
| 4999 | } |
| 5000 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5001 | if (tp->mac_version == RTL_GIGA_MAC_VER_32 || |
| 5002 | tp->mac_version == RTL_GIGA_MAC_VER_33) |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5003 | rtl_ephy_write(tp, 0x19, 0xff64); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5004 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 5005 | if (rtl_wol_pll_power_down(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5006 | return; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5007 | |
| 5008 | r8168_phy_power_down(tp); |
| 5009 | |
| 5010 | switch (tp->mac_version) { |
| 5011 | case RTL_GIGA_MAC_VER_25: |
| 5012 | case RTL_GIGA_MAC_VER_26: |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 5013 | case RTL_GIGA_MAC_VER_27: |
| 5014 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5015 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5016 | case RTL_GIGA_MAC_VER_32: |
| 5017 | case RTL_GIGA_MAC_VER_33: |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 5018 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5019 | case RTL_GIGA_MAC_VER_45: |
| 5020 | case RTL_GIGA_MAC_VER_46: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5021 | case RTL_GIGA_MAC_VER_50: |
| 5022 | case RTL_GIGA_MAC_VER_51: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5023 | RTL_W8(PMCH, RTL_R8(PMCH) & ~0x80); |
| 5024 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 5025 | case RTL_GIGA_MAC_VER_40: |
| 5026 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5027 | case RTL_GIGA_MAC_VER_49: |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5028 | rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0x00000000, |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 5029 | 0xfc000000, ERIAR_EXGMAC); |
Chun-Hao Lin | b8e5e6a | 2014-10-01 23:17:13 +0800 | [diff] [blame] | 5030 | RTL_W8(PMCH, RTL_R8(PMCH) & ~0x80); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 5031 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5032 | } |
| 5033 | } |
| 5034 | |
| 5035 | static void r8168_pll_power_up(struct rtl8169_private *tp) |
| 5036 | { |
| 5037 | void __iomem *ioaddr = tp->mmio_addr; |
| 5038 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5039 | switch (tp->mac_version) { |
| 5040 | case RTL_GIGA_MAC_VER_25: |
| 5041 | case RTL_GIGA_MAC_VER_26: |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 5042 | case RTL_GIGA_MAC_VER_27: |
| 5043 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5044 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5045 | case RTL_GIGA_MAC_VER_32: |
| 5046 | case RTL_GIGA_MAC_VER_33: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5047 | RTL_W8(PMCH, RTL_R8(PMCH) | 0x80); |
| 5048 | break; |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 5049 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5050 | case RTL_GIGA_MAC_VER_45: |
| 5051 | case RTL_GIGA_MAC_VER_46: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5052 | case RTL_GIGA_MAC_VER_50: |
| 5053 | case RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 5054 | RTL_W8(PMCH, RTL_R8(PMCH) | 0xc0); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5055 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 5056 | case RTL_GIGA_MAC_VER_40: |
| 5057 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5058 | case RTL_GIGA_MAC_VER_49: |
Chun-Hao Lin | b8e5e6a | 2014-10-01 23:17:13 +0800 | [diff] [blame] | 5059 | RTL_W8(PMCH, RTL_R8(PMCH) | 0xc0); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 5060 | rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0xfc000000, |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 5061 | 0x00000000, ERIAR_EXGMAC); |
| 5062 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5063 | } |
| 5064 | |
| 5065 | r8168_phy_power_up(tp); |
| 5066 | } |
| 5067 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5068 | static void rtl_generic_op(struct rtl8169_private *tp, |
| 5069 | void (*op)(struct rtl8169_private *)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5070 | { |
| 5071 | if (op) |
| 5072 | op(tp); |
| 5073 | } |
| 5074 | |
| 5075 | static void rtl_pll_power_down(struct rtl8169_private *tp) |
| 5076 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5077 | rtl_generic_op(tp, tp->pll_power_ops.down); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5078 | } |
| 5079 | |
| 5080 | static void rtl_pll_power_up(struct rtl8169_private *tp) |
| 5081 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5082 | rtl_generic_op(tp, tp->pll_power_ops.up); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5083 | } |
| 5084 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 5085 | static void rtl_init_pll_power_ops(struct rtl8169_private *tp) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5086 | { |
| 5087 | struct pll_power_ops *ops = &tp->pll_power_ops; |
| 5088 | |
| 5089 | switch (tp->mac_version) { |
| 5090 | case RTL_GIGA_MAC_VER_07: |
| 5091 | case RTL_GIGA_MAC_VER_08: |
| 5092 | case RTL_GIGA_MAC_VER_09: |
| 5093 | case RTL_GIGA_MAC_VER_10: |
| 5094 | case RTL_GIGA_MAC_VER_16: |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5095 | case RTL_GIGA_MAC_VER_29: |
| 5096 | case RTL_GIGA_MAC_VER_30: |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5097 | case RTL_GIGA_MAC_VER_37: |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5098 | case RTL_GIGA_MAC_VER_39: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 5099 | case RTL_GIGA_MAC_VER_43: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5100 | case RTL_GIGA_MAC_VER_47: |
| 5101 | case RTL_GIGA_MAC_VER_48: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5102 | ops->down = r810x_pll_power_down; |
| 5103 | ops->up = r810x_pll_power_up; |
| 5104 | break; |
| 5105 | |
| 5106 | case RTL_GIGA_MAC_VER_11: |
| 5107 | case RTL_GIGA_MAC_VER_12: |
| 5108 | case RTL_GIGA_MAC_VER_17: |
| 5109 | case RTL_GIGA_MAC_VER_18: |
| 5110 | case RTL_GIGA_MAC_VER_19: |
| 5111 | case RTL_GIGA_MAC_VER_20: |
| 5112 | case RTL_GIGA_MAC_VER_21: |
| 5113 | case RTL_GIGA_MAC_VER_22: |
| 5114 | case RTL_GIGA_MAC_VER_23: |
| 5115 | case RTL_GIGA_MAC_VER_24: |
| 5116 | case RTL_GIGA_MAC_VER_25: |
| 5117 | case RTL_GIGA_MAC_VER_26: |
| 5118 | case RTL_GIGA_MAC_VER_27: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5119 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5120 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5121 | case RTL_GIGA_MAC_VER_32: |
| 5122 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5123 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5124 | case RTL_GIGA_MAC_VER_35: |
| 5125 | case RTL_GIGA_MAC_VER_36: |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5126 | case RTL_GIGA_MAC_VER_38: |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5127 | case RTL_GIGA_MAC_VER_40: |
| 5128 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5129 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5130 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5131 | case RTL_GIGA_MAC_VER_45: |
| 5132 | case RTL_GIGA_MAC_VER_46: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5133 | case RTL_GIGA_MAC_VER_49: |
| 5134 | case RTL_GIGA_MAC_VER_50: |
| 5135 | case RTL_GIGA_MAC_VER_51: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5136 | ops->down = r8168_pll_power_down; |
| 5137 | ops->up = r8168_pll_power_up; |
| 5138 | break; |
| 5139 | |
| 5140 | default: |
| 5141 | ops->down = NULL; |
| 5142 | ops->up = NULL; |
| 5143 | break; |
| 5144 | } |
| 5145 | } |
| 5146 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 5147 | static void rtl_init_rxcfg(struct rtl8169_private *tp) |
| 5148 | { |
| 5149 | void __iomem *ioaddr = tp->mmio_addr; |
| 5150 | |
| 5151 | switch (tp->mac_version) { |
| 5152 | case RTL_GIGA_MAC_VER_01: |
| 5153 | case RTL_GIGA_MAC_VER_02: |
| 5154 | case RTL_GIGA_MAC_VER_03: |
| 5155 | case RTL_GIGA_MAC_VER_04: |
| 5156 | case RTL_GIGA_MAC_VER_05: |
| 5157 | case RTL_GIGA_MAC_VER_06: |
| 5158 | case RTL_GIGA_MAC_VER_10: |
| 5159 | case RTL_GIGA_MAC_VER_11: |
| 5160 | case RTL_GIGA_MAC_VER_12: |
| 5161 | case RTL_GIGA_MAC_VER_13: |
| 5162 | case RTL_GIGA_MAC_VER_14: |
| 5163 | case RTL_GIGA_MAC_VER_15: |
| 5164 | case RTL_GIGA_MAC_VER_16: |
| 5165 | case RTL_GIGA_MAC_VER_17: |
| 5166 | RTL_W32(RxConfig, RX_FIFO_THRESH | RX_DMA_BURST); |
| 5167 | break; |
| 5168 | case RTL_GIGA_MAC_VER_18: |
| 5169 | case RTL_GIGA_MAC_VER_19: |
| 5170 | case RTL_GIGA_MAC_VER_20: |
| 5171 | case RTL_GIGA_MAC_VER_21: |
| 5172 | case RTL_GIGA_MAC_VER_22: |
| 5173 | case RTL_GIGA_MAC_VER_23: |
| 5174 | case RTL_GIGA_MAC_VER_24: |
françois romieu | eb2dc35 | 2012-06-20 12:09:18 +0000 | [diff] [blame] | 5175 | case RTL_GIGA_MAC_VER_34: |
françois romieu | 3ced8c9 | 2013-09-08 01:15:35 +0200 | [diff] [blame] | 5176 | case RTL_GIGA_MAC_VER_35: |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 5177 | RTL_W32(RxConfig, RX128_INT_EN | RX_MULTI_EN | RX_DMA_BURST); |
| 5178 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 5179 | case RTL_GIGA_MAC_VER_40: |
| 5180 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5181 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 5182 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5183 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5184 | case RTL_GIGA_MAC_VER_45: |
| 5185 | case RTL_GIGA_MAC_VER_46: |
| 5186 | case RTL_GIGA_MAC_VER_47: |
| 5187 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5188 | case RTL_GIGA_MAC_VER_49: |
| 5189 | case RTL_GIGA_MAC_VER_50: |
| 5190 | case RTL_GIGA_MAC_VER_51: |
Ivan Vecera | 7ebc482 | 2015-08-04 22:11:43 +0200 | [diff] [blame] | 5191 | RTL_W32(RxConfig, RX128_INT_EN | RX_MULTI_EN | RX_DMA_BURST | RX_EARLY_OFF); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 5192 | break; |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 5193 | default: |
| 5194 | RTL_W32(RxConfig, RX128_INT_EN | RX_DMA_BURST); |
| 5195 | break; |
| 5196 | } |
| 5197 | } |
| 5198 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5199 | static void rtl8169_init_ring_indexes(struct rtl8169_private *tp) |
| 5200 | { |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 5201 | tp->dirty_tx = tp->cur_tx = tp->cur_rx = 0; |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5202 | } |
| 5203 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5204 | static void rtl_hw_jumbo_enable(struct rtl8169_private *tp) |
| 5205 | { |
françois romieu | 9c5028e | 2012-03-02 04:43:14 +0000 | [diff] [blame] | 5206 | void __iomem *ioaddr = tp->mmio_addr; |
| 5207 | |
| 5208 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5209 | rtl_generic_op(tp, tp->jumbo_ops.enable); |
françois romieu | 9c5028e | 2012-03-02 04:43:14 +0000 | [diff] [blame] | 5210 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5211 | } |
| 5212 | |
| 5213 | static void rtl_hw_jumbo_disable(struct rtl8169_private *tp) |
| 5214 | { |
françois romieu | 9c5028e | 2012-03-02 04:43:14 +0000 | [diff] [blame] | 5215 | void __iomem *ioaddr = tp->mmio_addr; |
| 5216 | |
| 5217 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5218 | rtl_generic_op(tp, tp->jumbo_ops.disable); |
françois romieu | 9c5028e | 2012-03-02 04:43:14 +0000 | [diff] [blame] | 5219 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5220 | } |
| 5221 | |
| 5222 | static void r8168c_hw_jumbo_enable(struct rtl8169_private *tp) |
| 5223 | { |
| 5224 | void __iomem *ioaddr = tp->mmio_addr; |
| 5225 | |
| 5226 | RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0); |
| 5227 | RTL_W8(Config4, RTL_R8(Config4) | Jumbo_En1); |
Rafał Miłecki | f65d539 | 2015-01-26 18:06:31 +0100 | [diff] [blame] | 5228 | rtl_tx_performance_tweak(tp->pci_dev, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5229 | } |
| 5230 | |
| 5231 | static void r8168c_hw_jumbo_disable(struct rtl8169_private *tp) |
| 5232 | { |
| 5233 | void __iomem *ioaddr = tp->mmio_addr; |
| 5234 | |
| 5235 | RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0); |
| 5236 | RTL_W8(Config4, RTL_R8(Config4) & ~Jumbo_En1); |
| 5237 | rtl_tx_performance_tweak(tp->pci_dev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 5238 | } |
| 5239 | |
| 5240 | static void r8168dp_hw_jumbo_enable(struct rtl8169_private *tp) |
| 5241 | { |
| 5242 | void __iomem *ioaddr = tp->mmio_addr; |
| 5243 | |
| 5244 | RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0); |
| 5245 | } |
| 5246 | |
| 5247 | static void r8168dp_hw_jumbo_disable(struct rtl8169_private *tp) |
| 5248 | { |
| 5249 | void __iomem *ioaddr = tp->mmio_addr; |
| 5250 | |
| 5251 | RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0); |
| 5252 | } |
| 5253 | |
| 5254 | static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp) |
| 5255 | { |
| 5256 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5257 | |
| 5258 | RTL_W8(MaxTxPacketSize, 0x3f); |
| 5259 | RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0); |
| 5260 | RTL_W8(Config4, RTL_R8(Config4) | 0x01); |
Rafał Miłecki | f65d539 | 2015-01-26 18:06:31 +0100 | [diff] [blame] | 5261 | rtl_tx_performance_tweak(tp->pci_dev, PCI_EXP_DEVCTL_READRQ_512B); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5262 | } |
| 5263 | |
| 5264 | static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp) |
| 5265 | { |
| 5266 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5267 | |
| 5268 | RTL_W8(MaxTxPacketSize, 0x0c); |
| 5269 | RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0); |
| 5270 | RTL_W8(Config4, RTL_R8(Config4) & ~0x01); |
Francois Romieu | 4512ff9 | 2011-12-22 18:59:37 +0100 | [diff] [blame] | 5271 | rtl_tx_performance_tweak(tp->pci_dev, 0x5 << MAX_READ_REQUEST_SHIFT); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5272 | } |
| 5273 | |
| 5274 | static void r8168b_0_hw_jumbo_enable(struct rtl8169_private *tp) |
| 5275 | { |
| 5276 | rtl_tx_performance_tweak(tp->pci_dev, |
Rafał Miłecki | f65d539 | 2015-01-26 18:06:31 +0100 | [diff] [blame] | 5277 | PCI_EXP_DEVCTL_READRQ_512B | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5278 | } |
| 5279 | |
| 5280 | static void r8168b_0_hw_jumbo_disable(struct rtl8169_private *tp) |
| 5281 | { |
| 5282 | rtl_tx_performance_tweak(tp->pci_dev, |
| 5283 | (0x5 << MAX_READ_REQUEST_SHIFT) | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 5284 | } |
| 5285 | |
| 5286 | static void r8168b_1_hw_jumbo_enable(struct rtl8169_private *tp) |
| 5287 | { |
| 5288 | void __iomem *ioaddr = tp->mmio_addr; |
| 5289 | |
| 5290 | r8168b_0_hw_jumbo_enable(tp); |
| 5291 | |
| 5292 | RTL_W8(Config4, RTL_R8(Config4) | (1 << 0)); |
| 5293 | } |
| 5294 | |
| 5295 | static void r8168b_1_hw_jumbo_disable(struct rtl8169_private *tp) |
| 5296 | { |
| 5297 | void __iomem *ioaddr = tp->mmio_addr; |
| 5298 | |
| 5299 | r8168b_0_hw_jumbo_disable(tp); |
| 5300 | |
| 5301 | RTL_W8(Config4, RTL_R8(Config4) & ~(1 << 0)); |
| 5302 | } |
| 5303 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 5304 | static void rtl_init_jumbo_ops(struct rtl8169_private *tp) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5305 | { |
| 5306 | struct jumbo_ops *ops = &tp->jumbo_ops; |
| 5307 | |
| 5308 | switch (tp->mac_version) { |
| 5309 | case RTL_GIGA_MAC_VER_11: |
| 5310 | ops->disable = r8168b_0_hw_jumbo_disable; |
| 5311 | ops->enable = r8168b_0_hw_jumbo_enable; |
| 5312 | break; |
| 5313 | case RTL_GIGA_MAC_VER_12: |
| 5314 | case RTL_GIGA_MAC_VER_17: |
| 5315 | ops->disable = r8168b_1_hw_jumbo_disable; |
| 5316 | ops->enable = r8168b_1_hw_jumbo_enable; |
| 5317 | break; |
| 5318 | case RTL_GIGA_MAC_VER_18: /* Wild guess. Needs info from Realtek. */ |
| 5319 | case RTL_GIGA_MAC_VER_19: |
| 5320 | case RTL_GIGA_MAC_VER_20: |
| 5321 | case RTL_GIGA_MAC_VER_21: /* Wild guess. Needs info from Realtek. */ |
| 5322 | case RTL_GIGA_MAC_VER_22: |
| 5323 | case RTL_GIGA_MAC_VER_23: |
| 5324 | case RTL_GIGA_MAC_VER_24: |
| 5325 | case RTL_GIGA_MAC_VER_25: |
| 5326 | case RTL_GIGA_MAC_VER_26: |
| 5327 | ops->disable = r8168c_hw_jumbo_disable; |
| 5328 | ops->enable = r8168c_hw_jumbo_enable; |
| 5329 | break; |
| 5330 | case RTL_GIGA_MAC_VER_27: |
| 5331 | case RTL_GIGA_MAC_VER_28: |
| 5332 | ops->disable = r8168dp_hw_jumbo_disable; |
| 5333 | ops->enable = r8168dp_hw_jumbo_enable; |
| 5334 | break; |
| 5335 | case RTL_GIGA_MAC_VER_31: /* Wild guess. Needs info from Realtek. */ |
| 5336 | case RTL_GIGA_MAC_VER_32: |
| 5337 | case RTL_GIGA_MAC_VER_33: |
| 5338 | case RTL_GIGA_MAC_VER_34: |
| 5339 | ops->disable = r8168e_hw_jumbo_disable; |
| 5340 | ops->enable = r8168e_hw_jumbo_enable; |
| 5341 | break; |
| 5342 | |
| 5343 | /* |
| 5344 | * No action needed for jumbo frames with 8169. |
| 5345 | * No jumbo for 810x at all. |
| 5346 | */ |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5347 | case RTL_GIGA_MAC_VER_40: |
| 5348 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5349 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 5350 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5351 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5352 | case RTL_GIGA_MAC_VER_45: |
| 5353 | case RTL_GIGA_MAC_VER_46: |
| 5354 | case RTL_GIGA_MAC_VER_47: |
| 5355 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5356 | case RTL_GIGA_MAC_VER_49: |
| 5357 | case RTL_GIGA_MAC_VER_50: |
| 5358 | case RTL_GIGA_MAC_VER_51: |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5359 | default: |
| 5360 | ops->disable = NULL; |
| 5361 | ops->enable = NULL; |
| 5362 | break; |
| 5363 | } |
| 5364 | } |
| 5365 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5366 | DECLARE_RTL_COND(rtl_chipcmd_cond) |
| 5367 | { |
| 5368 | void __iomem *ioaddr = tp->mmio_addr; |
| 5369 | |
| 5370 | return RTL_R8(ChipCmd) & CmdReset; |
| 5371 | } |
| 5372 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 5373 | static void rtl_hw_reset(struct rtl8169_private *tp) |
| 5374 | { |
| 5375 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 5376 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 5377 | RTL_W8(ChipCmd, CmdReset); |
| 5378 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5379 | rtl_udelay_loop_wait_low(tp, &rtl_chipcmd_cond, 100, 100); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 5380 | } |
| 5381 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 5382 | static void rtl_request_uncached_firmware(struct rtl8169_private *tp) |
| 5383 | { |
| 5384 | struct rtl_fw *rtl_fw; |
| 5385 | const char *name; |
| 5386 | int rc = -ENOMEM; |
| 5387 | |
| 5388 | name = rtl_lookup_firmware_name(tp); |
| 5389 | if (!name) |
| 5390 | goto out_no_firmware; |
| 5391 | |
| 5392 | rtl_fw = kzalloc(sizeof(*rtl_fw), GFP_KERNEL); |
| 5393 | if (!rtl_fw) |
| 5394 | goto err_warn; |
| 5395 | |
| 5396 | rc = request_firmware(&rtl_fw->fw, name, &tp->pci_dev->dev); |
| 5397 | if (rc < 0) |
| 5398 | goto err_free; |
| 5399 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 5400 | rc = rtl_check_firmware(tp, rtl_fw); |
| 5401 | if (rc < 0) |
| 5402 | goto err_release_firmware; |
| 5403 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 5404 | tp->rtl_fw = rtl_fw; |
| 5405 | out: |
| 5406 | return; |
| 5407 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 5408 | err_release_firmware: |
| 5409 | release_firmware(rtl_fw->fw); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 5410 | err_free: |
| 5411 | kfree(rtl_fw); |
| 5412 | err_warn: |
| 5413 | netif_warn(tp, ifup, tp->dev, "unable to load firmware patch %s (%d)\n", |
| 5414 | name, rc); |
| 5415 | out_no_firmware: |
| 5416 | tp->rtl_fw = NULL; |
| 5417 | goto out; |
| 5418 | } |
| 5419 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 5420 | static void rtl_request_firmware(struct rtl8169_private *tp) |
| 5421 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 5422 | if (IS_ERR(tp->rtl_fw)) |
| 5423 | rtl_request_uncached_firmware(tp); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 5424 | } |
| 5425 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5426 | static void rtl_rx_close(struct rtl8169_private *tp) |
| 5427 | { |
| 5428 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5429 | |
Francois Romieu | 1687b56 | 2011-07-19 17:21:29 +0200 | [diff] [blame] | 5430 | RTL_W32(RxConfig, RTL_R32(RxConfig) & ~RX_CONFIG_ACCEPT_MASK); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5431 | } |
| 5432 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5433 | DECLARE_RTL_COND(rtl_npq_cond) |
| 5434 | { |
| 5435 | void __iomem *ioaddr = tp->mmio_addr; |
| 5436 | |
| 5437 | return RTL_R8(TxPoll) & NPQ; |
| 5438 | } |
| 5439 | |
| 5440 | DECLARE_RTL_COND(rtl_txcfg_empty_cond) |
| 5441 | { |
| 5442 | void __iomem *ioaddr = tp->mmio_addr; |
| 5443 | |
| 5444 | return RTL_R32(TxConfig) & TXCFG_EMPTY; |
| 5445 | } |
| 5446 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5447 | static void rtl8169_hw_reset(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5448 | { |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5449 | void __iomem *ioaddr = tp->mmio_addr; |
| 5450 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5451 | /* Disable interrupts */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 5452 | rtl8169_irq_mask_and_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5453 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5454 | rtl_rx_close(tp); |
| 5455 | |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 5456 | if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5457 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 5458 | tp->mac_version == RTL_GIGA_MAC_VER_31) { |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5459 | rtl_udelay_loop_wait_low(tp, &rtl_npq_cond, 20, 42*42); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5460 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_34 || |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5461 | tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 5462 | tp->mac_version == RTL_GIGA_MAC_VER_36 || |
| 5463 | tp->mac_version == RTL_GIGA_MAC_VER_37 || |
| 5464 | tp->mac_version == RTL_GIGA_MAC_VER_38 || |
| 5465 | tp->mac_version == RTL_GIGA_MAC_VER_40 || |
| 5466 | tp->mac_version == RTL_GIGA_MAC_VER_41 || |
| 5467 | tp->mac_version == RTL_GIGA_MAC_VER_42 || |
| 5468 | tp->mac_version == RTL_GIGA_MAC_VER_43 || |
| 5469 | tp->mac_version == RTL_GIGA_MAC_VER_44 || |
| 5470 | tp->mac_version == RTL_GIGA_MAC_VER_45 || |
| 5471 | tp->mac_version == RTL_GIGA_MAC_VER_46 || |
| 5472 | tp->mac_version == RTL_GIGA_MAC_VER_47 || |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 5473 | tp->mac_version == RTL_GIGA_MAC_VER_48 || |
| 5474 | tp->mac_version == RTL_GIGA_MAC_VER_49 || |
| 5475 | tp->mac_version == RTL_GIGA_MAC_VER_50 || |
| 5476 | tp->mac_version == RTL_GIGA_MAC_VER_51) { |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 5477 | RTL_W8(ChipCmd, RTL_R8(ChipCmd) | StopReq); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5478 | rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 666); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5479 | } else { |
| 5480 | RTL_W8(ChipCmd, RTL_R8(ChipCmd) | StopReq); |
| 5481 | udelay(100); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5482 | } |
| 5483 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5484 | rtl_hw_reset(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5485 | } |
| 5486 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5487 | static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5488 | { |
| 5489 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5490 | |
| 5491 | /* Set DMA burst size and Interframe Gap Time */ |
| 5492 | RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) | |
| 5493 | (InterFrameGap << TxInterFrameGapShift)); |
| 5494 | } |
| 5495 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5496 | static void rtl_hw_start(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5497 | { |
| 5498 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5499 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5500 | tp->hw_start(dev); |
| 5501 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5502 | rtl_irq_enable_all(tp); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5503 | } |
| 5504 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5505 | static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp, |
| 5506 | void __iomem *ioaddr) |
| 5507 | { |
| 5508 | /* |
| 5509 | * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh |
| 5510 | * register to be written before TxDescAddrLow to work. |
| 5511 | * Switching from MMIO to I/O access fixes the issue as well. |
| 5512 | */ |
| 5513 | RTL_W32(TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5514 | RTL_W32(TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5515 | RTL_W32(RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5516 | RTL_W32(RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5517 | } |
| 5518 | |
| 5519 | static u16 rtl_rw_cpluscmd(void __iomem *ioaddr) |
| 5520 | { |
| 5521 | u16 cmd; |
| 5522 | |
| 5523 | cmd = RTL_R16(CPlusCmd); |
| 5524 | RTL_W16(CPlusCmd, cmd); |
| 5525 | return cmd; |
| 5526 | } |
| 5527 | |
Eric Dumazet | fdd7b4c | 2009-06-09 04:01:02 -0700 | [diff] [blame] | 5528 | static void rtl_set_rx_max_size(void __iomem *ioaddr, unsigned int rx_buf_sz) |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5529 | { |
| 5530 | /* Low hurts. Let's disable the filtering. */ |
Raimonds Cicans | 207d6e87 | 2009-10-26 10:52:37 +0000 | [diff] [blame] | 5531 | RTL_W16(RxMaxSize, rx_buf_sz + 1); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5532 | } |
| 5533 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5534 | static void rtl8169_set_magic_reg(void __iomem *ioaddr, unsigned mac_version) |
| 5535 | { |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 5536 | static const struct rtl_cfg2_info { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5537 | u32 mac_version; |
| 5538 | u32 clk; |
| 5539 | u32 val; |
| 5540 | } cfg2_info [] = { |
| 5541 | { RTL_GIGA_MAC_VER_05, PCI_Clock_33MHz, 0x000fff00 }, // 8110SCd |
| 5542 | { RTL_GIGA_MAC_VER_05, PCI_Clock_66MHz, 0x000fffff }, |
| 5543 | { RTL_GIGA_MAC_VER_06, PCI_Clock_33MHz, 0x00ffff00 }, // 8110SCe |
| 5544 | { RTL_GIGA_MAC_VER_06, PCI_Clock_66MHz, 0x00ffffff } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 5545 | }; |
| 5546 | const struct rtl_cfg2_info *p = cfg2_info; |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5547 | unsigned int i; |
| 5548 | u32 clk; |
| 5549 | |
| 5550 | clk = RTL_R8(Config2) & PCI_Clock_66MHz; |
Francois Romieu | cadf185 | 2008-01-03 23:38:38 +0100 | [diff] [blame] | 5551 | for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5552 | if ((p->mac_version == mac_version) && (p->clk == clk)) { |
| 5553 | RTL_W32(0x7c, p->val); |
| 5554 | break; |
| 5555 | } |
| 5556 | } |
| 5557 | } |
| 5558 | |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5559 | static void rtl_set_rx_mode(struct net_device *dev) |
| 5560 | { |
| 5561 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5562 | void __iomem *ioaddr = tp->mmio_addr; |
| 5563 | u32 mc_filter[2]; /* Multicast hash filter */ |
| 5564 | int rx_mode; |
| 5565 | u32 tmp = 0; |
| 5566 | |
| 5567 | if (dev->flags & IFF_PROMISC) { |
| 5568 | /* Unconditionally log net taps. */ |
| 5569 | netif_notice(tp, link, dev, "Promiscuous mode enabled\n"); |
| 5570 | rx_mode = |
| 5571 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys | |
| 5572 | AcceptAllPhys; |
| 5573 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 5574 | } else if ((netdev_mc_count(dev) > multicast_filter_limit) || |
| 5575 | (dev->flags & IFF_ALLMULTI)) { |
| 5576 | /* Too many to filter perfectly -- accept all multicasts. */ |
| 5577 | rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; |
| 5578 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 5579 | } else { |
| 5580 | struct netdev_hw_addr *ha; |
| 5581 | |
| 5582 | rx_mode = AcceptBroadcast | AcceptMyPhys; |
| 5583 | mc_filter[1] = mc_filter[0] = 0; |
| 5584 | netdev_for_each_mc_addr(ha, dev) { |
| 5585 | int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; |
| 5586 | mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); |
| 5587 | rx_mode |= AcceptMulticast; |
| 5588 | } |
| 5589 | } |
| 5590 | |
| 5591 | if (dev->features & NETIF_F_RXALL) |
| 5592 | rx_mode |= (AcceptErr | AcceptRunt); |
| 5593 | |
| 5594 | tmp = (RTL_R32(RxConfig) & ~RX_CONFIG_ACCEPT_MASK) | rx_mode; |
| 5595 | |
| 5596 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) { |
| 5597 | u32 data = mc_filter[0]; |
| 5598 | |
| 5599 | mc_filter[0] = swab32(mc_filter[1]); |
| 5600 | mc_filter[1] = swab32(data); |
| 5601 | } |
| 5602 | |
Nathan Walp | 0481776 | 2012-11-01 12:08:47 +0000 | [diff] [blame] | 5603 | if (tp->mac_version == RTL_GIGA_MAC_VER_35) |
| 5604 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 5605 | |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 5606 | RTL_W32(MAR0 + 4, mc_filter[1]); |
| 5607 | RTL_W32(MAR0 + 0, mc_filter[0]); |
| 5608 | |
| 5609 | RTL_W32(RxConfig, tmp); |
| 5610 | } |
| 5611 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5612 | static void rtl_hw_start_8169(struct net_device *dev) |
| 5613 | { |
| 5614 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5615 | void __iomem *ioaddr = tp->mmio_addr; |
| 5616 | struct pci_dev *pdev = tp->pci_dev; |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5617 | |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5618 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) { |
| 5619 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) | PCIMulRW); |
| 5620 | pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, 0x08); |
| 5621 | } |
| 5622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5623 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5624 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 || |
| 5625 | tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 5626 | tp->mac_version == RTL_GIGA_MAC_VER_03 || |
| 5627 | tp->mac_version == RTL_GIGA_MAC_VER_04) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5628 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 5629 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 5630 | rtl_init_rxcfg(tp); |
| 5631 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 5632 | RTL_W8(EarlyTxThres, NoEarlyTx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5633 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5634 | rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5635 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5636 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 || |
| 5637 | tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 5638 | tp->mac_version == RTL_GIGA_MAC_VER_03 || |
| 5639 | tp->mac_version == RTL_GIGA_MAC_VER_04) |
Francois Romieu | c946b30 | 2007-10-04 00:42:50 +0200 | [diff] [blame] | 5640 | rtl_set_rx_tx_config_registers(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5641 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5642 | tp->cp_cmd |= rtl_rw_cpluscmd(ioaddr) | PCIMulRW; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5643 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5644 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 5645 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 5646 | dprintk("Set MAC Reg C+CR Offset 0xe0. " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5647 | "Bit-3 and bit-14 MUST be 1\n"); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5648 | tp->cp_cmd |= (1 << 14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5649 | } |
| 5650 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5651 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 5652 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5653 | rtl8169_set_magic_reg(ioaddr, tp->mac_version); |
| 5654 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5655 | /* |
| 5656 | * Undocumented corner. Supposedly: |
| 5657 | * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets |
| 5658 | */ |
| 5659 | RTL_W16(IntrMitigate, 0x0000); |
| 5660 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5661 | rtl_set_rx_tx_desc_registers(tp, ioaddr); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5662 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5663 | if (tp->mac_version != RTL_GIGA_MAC_VER_01 && |
| 5664 | tp->mac_version != RTL_GIGA_MAC_VER_02 && |
| 5665 | tp->mac_version != RTL_GIGA_MAC_VER_03 && |
| 5666 | tp->mac_version != RTL_GIGA_MAC_VER_04) { |
Francois Romieu | c946b30 | 2007-10-04 00:42:50 +0200 | [diff] [blame] | 5667 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 5668 | rtl_set_rx_tx_config_registers(tp); |
| 5669 | } |
| 5670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5671 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Francois Romieu | b518fa8 | 2006-08-16 15:23:13 +0200 | [diff] [blame] | 5672 | |
| 5673 | /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ |
| 5674 | RTL_R8(IntrMask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5675 | |
| 5676 | RTL_W32(RxMissed, 0); |
| 5677 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5678 | rtl_set_rx_mode(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5679 | |
| 5680 | /* no early-rx interrupts */ |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 5681 | RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5682 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5683 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5684 | static void rtl_csi_write(struct rtl8169_private *tp, int addr, int value) |
| 5685 | { |
| 5686 | if (tp->csi_ops.write) |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5687 | tp->csi_ops.write(tp, addr, value); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5688 | } |
| 5689 | |
| 5690 | static u32 rtl_csi_read(struct rtl8169_private *tp, int addr) |
| 5691 | { |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5692 | return tp->csi_ops.read ? tp->csi_ops.read(tp, addr) : ~0; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5693 | } |
| 5694 | |
| 5695 | static void rtl_csi_access_enable(struct rtl8169_private *tp, u32 bits) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5696 | { |
| 5697 | u32 csi; |
| 5698 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5699 | csi = rtl_csi_read(tp, 0x070c) & 0x00ffffff; |
| 5700 | rtl_csi_write(tp, 0x070c, csi | bits); |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 5701 | } |
| 5702 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5703 | static void rtl_csi_access_enable_1(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5704 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5705 | rtl_csi_access_enable(tp, 0x17000000); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5706 | } |
| 5707 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5708 | static void rtl_csi_access_enable_2(struct rtl8169_private *tp) |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 5709 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5710 | rtl_csi_access_enable(tp, 0x27000000); |
| 5711 | } |
| 5712 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5713 | DECLARE_RTL_COND(rtl_csiar_cond) |
| 5714 | { |
| 5715 | void __iomem *ioaddr = tp->mmio_addr; |
| 5716 | |
| 5717 | return RTL_R32(CSIAR) & CSIAR_FLAG; |
| 5718 | } |
| 5719 | |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5720 | 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] | 5721 | { |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5722 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5723 | |
| 5724 | RTL_W32(CSIDR, value); |
| 5725 | RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
| 5726 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 5727 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5728 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5729 | } |
| 5730 | |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5731 | static u32 r8169_csi_read(struct rtl8169_private *tp, int addr) |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5732 | { |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5733 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5734 | |
| 5735 | RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) | |
| 5736 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 5737 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5738 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
| 5739 | RTL_R32(CSIDR) : ~0; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5740 | } |
| 5741 | |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5742 | 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] | 5743 | { |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5744 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5745 | |
| 5746 | RTL_W32(CSIDR, value); |
| 5747 | RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
| 5748 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT | |
| 5749 | CSIAR_FUNC_NIC); |
| 5750 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5751 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5752 | } |
| 5753 | |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5754 | static u32 r8402_csi_read(struct rtl8169_private *tp, int addr) |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5755 | { |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5756 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5757 | |
| 5758 | RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) | CSIAR_FUNC_NIC | |
| 5759 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 5760 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5761 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
| 5762 | RTL_R32(CSIDR) : ~0; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5763 | } |
| 5764 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5765 | static void r8411_csi_write(struct rtl8169_private *tp, int addr, int value) |
| 5766 | { |
| 5767 | void __iomem *ioaddr = tp->mmio_addr; |
| 5768 | |
| 5769 | RTL_W32(CSIDR, value); |
| 5770 | RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
| 5771 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT | |
| 5772 | CSIAR_FUNC_NIC2); |
| 5773 | |
| 5774 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
| 5775 | } |
| 5776 | |
| 5777 | static u32 r8411_csi_read(struct rtl8169_private *tp, int addr) |
| 5778 | { |
| 5779 | void __iomem *ioaddr = tp->mmio_addr; |
| 5780 | |
| 5781 | RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) | CSIAR_FUNC_NIC2 | |
| 5782 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 5783 | |
| 5784 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
| 5785 | RTL_R32(CSIDR) : ~0; |
| 5786 | } |
| 5787 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 5788 | static void rtl_init_csi_ops(struct rtl8169_private *tp) |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5789 | { |
| 5790 | struct csi_ops *ops = &tp->csi_ops; |
| 5791 | |
| 5792 | switch (tp->mac_version) { |
| 5793 | case RTL_GIGA_MAC_VER_01: |
| 5794 | case RTL_GIGA_MAC_VER_02: |
| 5795 | case RTL_GIGA_MAC_VER_03: |
| 5796 | case RTL_GIGA_MAC_VER_04: |
| 5797 | case RTL_GIGA_MAC_VER_05: |
| 5798 | case RTL_GIGA_MAC_VER_06: |
| 5799 | case RTL_GIGA_MAC_VER_10: |
| 5800 | case RTL_GIGA_MAC_VER_11: |
| 5801 | case RTL_GIGA_MAC_VER_12: |
| 5802 | case RTL_GIGA_MAC_VER_13: |
| 5803 | case RTL_GIGA_MAC_VER_14: |
| 5804 | case RTL_GIGA_MAC_VER_15: |
| 5805 | case RTL_GIGA_MAC_VER_16: |
| 5806 | case RTL_GIGA_MAC_VER_17: |
| 5807 | ops->write = NULL; |
| 5808 | ops->read = NULL; |
| 5809 | break; |
| 5810 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5811 | case RTL_GIGA_MAC_VER_37: |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5812 | case RTL_GIGA_MAC_VER_38: |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5813 | ops->write = r8402_csi_write; |
| 5814 | ops->read = r8402_csi_read; |
| 5815 | break; |
| 5816 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5817 | case RTL_GIGA_MAC_VER_44: |
| 5818 | ops->write = r8411_csi_write; |
| 5819 | ops->read = r8411_csi_read; |
| 5820 | break; |
| 5821 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5822 | default: |
| 5823 | ops->write = r8169_csi_write; |
| 5824 | ops->read = r8169_csi_read; |
| 5825 | break; |
| 5826 | } |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5827 | } |
| 5828 | |
| 5829 | struct ephy_info { |
| 5830 | unsigned int offset; |
| 5831 | u16 mask; |
| 5832 | u16 bits; |
| 5833 | }; |
| 5834 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5835 | static void rtl_ephy_init(struct rtl8169_private *tp, const struct ephy_info *e, |
| 5836 | int len) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5837 | { |
| 5838 | u16 w; |
| 5839 | |
| 5840 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5841 | w = (rtl_ephy_read(tp, e->offset) & ~e->mask) | e->bits; |
| 5842 | rtl_ephy_write(tp, e->offset, w); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5843 | e++; |
| 5844 | } |
| 5845 | } |
| 5846 | |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5847 | static void rtl_disable_clock_request(struct pci_dev *pdev) |
| 5848 | { |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 5849 | pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, |
| 5850 | PCI_EXP_LNKCTL_CLKREQ_EN); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5851 | } |
| 5852 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5853 | static void rtl_enable_clock_request(struct pci_dev *pdev) |
| 5854 | { |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 5855 | pcie_capability_set_word(pdev, PCI_EXP_LNKCTL, |
| 5856 | PCI_EXP_LNKCTL_CLKREQ_EN); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5857 | } |
| 5858 | |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5859 | static void rtl_pcie_state_l2l3_enable(struct rtl8169_private *tp, bool enable) |
| 5860 | { |
| 5861 | void __iomem *ioaddr = tp->mmio_addr; |
| 5862 | u8 data; |
| 5863 | |
| 5864 | data = RTL_R8(Config3); |
| 5865 | |
| 5866 | if (enable) |
| 5867 | data |= Rdy_to_L23; |
| 5868 | else |
| 5869 | data &= ~Rdy_to_L23; |
| 5870 | |
| 5871 | RTL_W8(Config3, data); |
| 5872 | } |
| 5873 | |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5874 | #define R8168_CPCMD_QUIRK_MASK (\ |
| 5875 | EnableBist | \ |
| 5876 | Mac_dbgo_oe | \ |
| 5877 | Force_half_dup | \ |
| 5878 | Force_rxflow_en | \ |
| 5879 | Force_txflow_en | \ |
| 5880 | Cxpl_dbg_sel | \ |
| 5881 | ASF | \ |
| 5882 | PktCntrDisable | \ |
| 5883 | Mac_dbgo_sel) |
| 5884 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5885 | static void rtl_hw_start_8168bb(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5886 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5887 | void __iomem *ioaddr = tp->mmio_addr; |
| 5888 | struct pci_dev *pdev = tp->pci_dev; |
| 5889 | |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5890 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 5891 | |
| 5892 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 5893 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5894 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
| 5895 | rtl_tx_performance_tweak(pdev, (0x5 << MAX_READ_REQUEST_SHIFT) | |
| 5896 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 5897 | } |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5898 | } |
| 5899 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5900 | static void rtl_hw_start_8168bef(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5901 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5902 | void __iomem *ioaddr = tp->mmio_addr; |
| 5903 | |
| 5904 | rtl_hw_start_8168bb(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5905 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 5906 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5907 | |
| 5908 | RTL_W8(Config4, RTL_R8(Config4) & ~(1 << 0)); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5909 | } |
| 5910 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5911 | static void __rtl_hw_start_8168cp(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5912 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5913 | void __iomem *ioaddr = tp->mmio_addr; |
| 5914 | struct pci_dev *pdev = tp->pci_dev; |
| 5915 | |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5916 | RTL_W8(Config1, RTL_R8(Config1) | Speed_down); |
| 5917 | |
| 5918 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 5919 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5920 | if (tp->dev->mtu <= ETH_DATA_LEN) |
| 5921 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5922 | |
| 5923 | rtl_disable_clock_request(pdev); |
| 5924 | |
| 5925 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5926 | } |
| 5927 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5928 | static void rtl_hw_start_8168cp_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5929 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5930 | static const struct ephy_info e_info_8168cp[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5931 | { 0x01, 0, 0x0001 }, |
| 5932 | { 0x02, 0x0800, 0x1000 }, |
| 5933 | { 0x03, 0, 0x0042 }, |
| 5934 | { 0x06, 0x0080, 0x0000 }, |
| 5935 | { 0x07, 0, 0x2000 } |
| 5936 | }; |
| 5937 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5938 | rtl_csi_access_enable_2(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5939 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5940 | rtl_ephy_init(tp, e_info_8168cp, ARRAY_SIZE(e_info_8168cp)); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5941 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5942 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5943 | } |
| 5944 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5945 | static void rtl_hw_start_8168cp_2(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5946 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5947 | void __iomem *ioaddr = tp->mmio_addr; |
| 5948 | struct pci_dev *pdev = tp->pci_dev; |
| 5949 | |
| 5950 | rtl_csi_access_enable_2(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5951 | |
| 5952 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 5953 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5954 | if (tp->dev->mtu <= ETH_DATA_LEN) |
| 5955 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5956 | |
| 5957 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 5958 | } |
| 5959 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5960 | static void rtl_hw_start_8168cp_3(struct rtl8169_private *tp) |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5961 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5962 | void __iomem *ioaddr = tp->mmio_addr; |
| 5963 | struct pci_dev *pdev = tp->pci_dev; |
| 5964 | |
| 5965 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5966 | |
| 5967 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 5968 | |
| 5969 | /* Magic. */ |
| 5970 | RTL_W8(DBG_REG, 0x20); |
| 5971 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 5972 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5973 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5974 | if (tp->dev->mtu <= ETH_DATA_LEN) |
| 5975 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5976 | |
| 5977 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 5978 | } |
| 5979 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5980 | static void rtl_hw_start_8168c_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5981 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5982 | void __iomem *ioaddr = tp->mmio_addr; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5983 | static const struct ephy_info e_info_8168c_1[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5984 | { 0x02, 0x0800, 0x1000 }, |
| 5985 | { 0x03, 0, 0x0002 }, |
| 5986 | { 0x06, 0x0080, 0x0000 } |
| 5987 | }; |
| 5988 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5989 | rtl_csi_access_enable_2(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5990 | |
| 5991 | RTL_W8(DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2); |
| 5992 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5993 | 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] | 5994 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5995 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5996 | } |
| 5997 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5998 | static void rtl_hw_start_8168c_2(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5999 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 6000 | static const struct ephy_info e_info_8168c_2[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 6001 | { 0x01, 0, 0x0001 }, |
| 6002 | { 0x03, 0x0400, 0x0220 } |
| 6003 | }; |
| 6004 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6005 | rtl_csi_access_enable_2(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 6006 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6007 | 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] | 6008 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6009 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6010 | } |
| 6011 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6012 | static void rtl_hw_start_8168c_3(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 6013 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6014 | rtl_hw_start_8168c_2(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 6015 | } |
| 6016 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6017 | static void rtl_hw_start_8168c_4(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 6018 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6019 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 6020 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6021 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 6022 | } |
| 6023 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6024 | static void rtl_hw_start_8168d(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 6025 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6026 | void __iomem *ioaddr = tp->mmio_addr; |
| 6027 | struct pci_dev *pdev = tp->pci_dev; |
| 6028 | |
| 6029 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 6030 | |
| 6031 | rtl_disable_clock_request(pdev); |
| 6032 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 6033 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 6034 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 6035 | if (tp->dev->mtu <= ETH_DATA_LEN) |
| 6036 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 6037 | |
| 6038 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 6039 | } |
| 6040 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6041 | static void rtl_hw_start_8168dp(struct rtl8169_private *tp) |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6042 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6043 | void __iomem *ioaddr = tp->mmio_addr; |
| 6044 | struct pci_dev *pdev = tp->pci_dev; |
| 6045 | |
| 6046 | rtl_csi_access_enable_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6047 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 6048 | if (tp->dev->mtu <= ETH_DATA_LEN) |
| 6049 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6050 | |
| 6051 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
| 6052 | |
| 6053 | rtl_disable_clock_request(pdev); |
| 6054 | } |
| 6055 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6056 | static void rtl_hw_start_8168d_4(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 6057 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6058 | void __iomem *ioaddr = tp->mmio_addr; |
| 6059 | struct pci_dev *pdev = tp->pci_dev; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 6060 | static const struct ephy_info e_info_8168d_4[] = { |
Chun-Hao Lin | 1016a4a | 2015-12-29 22:13:39 +0800 | [diff] [blame] | 6061 | { 0x0b, 0x0000, 0x0048 }, |
| 6062 | { 0x19, 0x0020, 0x0050 }, |
| 6063 | { 0x0c, 0x0100, 0x0020 } |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 6064 | }; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 6065 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6066 | rtl_csi_access_enable_1(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 6067 | |
| 6068 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 6069 | |
| 6070 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
| 6071 | |
Chun-Hao Lin | 1016a4a | 2015-12-29 22:13:39 +0800 | [diff] [blame] | 6072 | 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] | 6073 | |
| 6074 | rtl_enable_clock_request(pdev); |
| 6075 | } |
| 6076 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6077 | static void rtl_hw_start_8168e_1(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 6078 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6079 | void __iomem *ioaddr = tp->mmio_addr; |
| 6080 | struct pci_dev *pdev = tp->pci_dev; |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 6081 | static const struct ephy_info e_info_8168e_1[] = { |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 6082 | { 0x00, 0x0200, 0x0100 }, |
| 6083 | { 0x00, 0x0000, 0x0004 }, |
| 6084 | { 0x06, 0x0002, 0x0001 }, |
| 6085 | { 0x06, 0x0000, 0x0030 }, |
| 6086 | { 0x07, 0x0000, 0x2000 }, |
| 6087 | { 0x00, 0x0000, 0x0020 }, |
| 6088 | { 0x03, 0x5800, 0x2000 }, |
| 6089 | { 0x03, 0x0000, 0x0001 }, |
| 6090 | { 0x01, 0x0800, 0x1000 }, |
| 6091 | { 0x07, 0x0000, 0x4000 }, |
| 6092 | { 0x1e, 0x0000, 0x2000 }, |
| 6093 | { 0x19, 0xffff, 0xfe6c }, |
| 6094 | { 0x0a, 0x0000, 0x0040 } |
| 6095 | }; |
| 6096 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6097 | rtl_csi_access_enable_2(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 6098 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6099 | 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] | 6100 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 6101 | if (tp->dev->mtu <= ETH_DATA_LEN) |
| 6102 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 6103 | |
| 6104 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
| 6105 | |
| 6106 | rtl_disable_clock_request(pdev); |
| 6107 | |
| 6108 | /* Reset tx FIFO pointer */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6109 | RTL_W32(MISC, RTL_R32(MISC) | TXPLA_RST); |
| 6110 | RTL_W32(MISC, RTL_R32(MISC) & ~TXPLA_RST); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 6111 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6112 | RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 6113 | } |
| 6114 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6115 | static void rtl_hw_start_8168e_2(struct rtl8169_private *tp) |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 6116 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6117 | void __iomem *ioaddr = tp->mmio_addr; |
| 6118 | struct pci_dev *pdev = tp->pci_dev; |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 6119 | static const struct ephy_info e_info_8168e_2[] = { |
| 6120 | { 0x09, 0x0000, 0x0080 }, |
| 6121 | { 0x19, 0x0000, 0x0224 } |
| 6122 | }; |
| 6123 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6124 | rtl_csi_access_enable_1(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 6125 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6126 | 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] | 6127 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 6128 | if (tp->dev->mtu <= ETH_DATA_LEN) |
| 6129 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 6130 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6131 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6132 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6133 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 6134 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 6135 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 6136 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x07ff0060, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6137 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 6138 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 6139 | |
Hayes Wang | 3090bd9 | 2011-09-06 16:55:15 +0800 | [diff] [blame] | 6140 | RTL_W8(MaxTxPacketSize, EarlySize); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 6141 | |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 6142 | rtl_disable_clock_request(pdev); |
| 6143 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 6144 | RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
| 6145 | RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB); |
| 6146 | |
| 6147 | /* Adjust EEE LED frequency */ |
| 6148 | RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07); |
| 6149 | |
| 6150 | RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN); |
| 6151 | RTL_W32(MISC, RTL_R32(MISC) | PWM_EN); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 6152 | RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 6153 | } |
| 6154 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 6155 | static void rtl_hw_start_8168f(struct rtl8169_private *tp) |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 6156 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6157 | void __iomem *ioaddr = tp->mmio_addr; |
| 6158 | struct pci_dev *pdev = tp->pci_dev; |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 6159 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 6160 | rtl_csi_access_enable_2(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 6161 | |
| 6162 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 6163 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6164 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6165 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6166 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 6167 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6168 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 6169 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 6170 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 6171 | rtl_w0w1_eri(tp, 0x1d0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6172 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 6173 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x00000060, ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 6174 | |
| 6175 | RTL_W8(MaxTxPacketSize, EarlySize); |
| 6176 | |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 6177 | rtl_disable_clock_request(pdev); |
| 6178 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 6179 | RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
| 6180 | RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 6181 | RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 6182 | RTL_W32(MISC, RTL_R32(MISC) | PWM_EN); |
| 6183 | RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 6184 | } |
| 6185 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 6186 | static void rtl_hw_start_8168f_1(struct rtl8169_private *tp) |
| 6187 | { |
| 6188 | void __iomem *ioaddr = tp->mmio_addr; |
| 6189 | static const struct ephy_info e_info_8168f_1[] = { |
| 6190 | { 0x06, 0x00c0, 0x0020 }, |
| 6191 | { 0x08, 0x0001, 0x0002 }, |
| 6192 | { 0x09, 0x0000, 0x0080 }, |
| 6193 | { 0x19, 0x0000, 0x0224 } |
| 6194 | }; |
| 6195 | |
| 6196 | rtl_hw_start_8168f(tp); |
| 6197 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6198 | 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] | 6199 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6200 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 6201 | |
| 6202 | /* Adjust EEE LED frequency */ |
| 6203 | RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07); |
| 6204 | } |
| 6205 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 6206 | static void rtl_hw_start_8411(struct rtl8169_private *tp) |
| 6207 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 6208 | static const struct ephy_info e_info_8168f_1[] = { |
| 6209 | { 0x06, 0x00c0, 0x0020 }, |
| 6210 | { 0x0f, 0xffff, 0x5200 }, |
| 6211 | { 0x1e, 0x0000, 0x4000 }, |
| 6212 | { 0x19, 0x0000, 0x0224 } |
| 6213 | }; |
| 6214 | |
| 6215 | rtl_hw_start_8168f(tp); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 6216 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 6217 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6218 | 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] | 6219 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6220 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 6221 | } |
| 6222 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 6223 | static void rtl_hw_start_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6224 | { |
| 6225 | void __iomem *ioaddr = tp->mmio_addr; |
| 6226 | struct pci_dev *pdev = tp->pci_dev; |
| 6227 | |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 6228 | RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
| 6229 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6230 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x080002, ERIAR_EXGMAC); |
| 6231 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC); |
| 6232 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC); |
| 6233 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 6234 | |
| 6235 | rtl_csi_access_enable_1(tp); |
| 6236 | |
| 6237 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 6238 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6239 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 6240 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 6241 | rtl_eri_write(tp, 0x2f8, ERIAR_MASK_0011, 0x1d8f, ERIAR_EXGMAC); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6242 | |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 6243 | RTL_W32(MISC, RTL_R32(MISC) & ~RXDV_GATED_EN); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6244 | RTL_W8(MaxTxPacketSize, EarlySize); |
| 6245 | |
| 6246 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6247 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6248 | |
| 6249 | /* Adjust EEE LED frequency */ |
| 6250 | RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07); |
| 6251 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6252 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC); |
| 6253 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, 0x1000, ERIAR_EXGMAC); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 6254 | |
| 6255 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6256 | } |
| 6257 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 6258 | static void rtl_hw_start_8168g_1(struct rtl8169_private *tp) |
| 6259 | { |
| 6260 | void __iomem *ioaddr = tp->mmio_addr; |
| 6261 | static const struct ephy_info e_info_8168g_1[] = { |
| 6262 | { 0x00, 0x0000, 0x0008 }, |
| 6263 | { 0x0c, 0x37d0, 0x0820 }, |
| 6264 | { 0x1e, 0x0000, 0x0001 }, |
| 6265 | { 0x19, 0x8000, 0x0000 } |
| 6266 | }; |
| 6267 | |
| 6268 | rtl_hw_start_8168g(tp); |
| 6269 | |
| 6270 | /* disable aspm and clock request before access ephy */ |
| 6271 | RTL_W8(Config2, RTL_R8(Config2) & ~ClkReqEn); |
| 6272 | RTL_W8(Config5, RTL_R8(Config5) & ~ASPM_en); |
| 6273 | rtl_ephy_init(tp, e_info_8168g_1, ARRAY_SIZE(e_info_8168g_1)); |
| 6274 | } |
| 6275 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 6276 | static void rtl_hw_start_8168g_2(struct rtl8169_private *tp) |
| 6277 | { |
| 6278 | void __iomem *ioaddr = tp->mmio_addr; |
| 6279 | static const struct ephy_info e_info_8168g_2[] = { |
| 6280 | { 0x00, 0x0000, 0x0008 }, |
| 6281 | { 0x0c, 0x3df0, 0x0200 }, |
| 6282 | { 0x19, 0xffff, 0xfc00 }, |
| 6283 | { 0x1e, 0xffff, 0x20eb } |
| 6284 | }; |
| 6285 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 6286 | rtl_hw_start_8168g(tp); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 6287 | |
| 6288 | /* disable aspm and clock request before access ephy */ |
| 6289 | RTL_W8(Config2, RTL_R8(Config2) & ~ClkReqEn); |
| 6290 | RTL_W8(Config5, RTL_R8(Config5) & ~ASPM_en); |
| 6291 | rtl_ephy_init(tp, e_info_8168g_2, ARRAY_SIZE(e_info_8168g_2)); |
| 6292 | } |
| 6293 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 6294 | static void rtl_hw_start_8411_2(struct rtl8169_private *tp) |
| 6295 | { |
| 6296 | void __iomem *ioaddr = tp->mmio_addr; |
| 6297 | static const struct ephy_info e_info_8411_2[] = { |
| 6298 | { 0x00, 0x0000, 0x0008 }, |
| 6299 | { 0x0c, 0x3df0, 0x0200 }, |
| 6300 | { 0x0f, 0xffff, 0x5200 }, |
| 6301 | { 0x19, 0x0020, 0x0000 }, |
| 6302 | { 0x1e, 0x0000, 0x2000 } |
| 6303 | }; |
| 6304 | |
Chun-Hao Lin | 5fbea33 | 2014-12-10 21:28:38 +0800 | [diff] [blame] | 6305 | rtl_hw_start_8168g(tp); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 6306 | |
| 6307 | /* disable aspm and clock request before access ephy */ |
| 6308 | RTL_W8(Config2, RTL_R8(Config2) & ~ClkReqEn); |
| 6309 | RTL_W8(Config5, RTL_R8(Config5) & ~ASPM_en); |
| 6310 | rtl_ephy_init(tp, e_info_8411_2, ARRAY_SIZE(e_info_8411_2)); |
| 6311 | } |
| 6312 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6313 | static void rtl_hw_start_8168h_1(struct rtl8169_private *tp) |
| 6314 | { |
| 6315 | void __iomem *ioaddr = tp->mmio_addr; |
| 6316 | struct pci_dev *pdev = tp->pci_dev; |
Andrzej Hajda | 72521ea | 2015-09-24 16:00:24 +0200 | [diff] [blame] | 6317 | int rg_saw_cnt; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6318 | u32 data; |
| 6319 | static const struct ephy_info e_info_8168h_1[] = { |
| 6320 | { 0x1e, 0x0800, 0x0001 }, |
| 6321 | { 0x1d, 0x0000, 0x0800 }, |
| 6322 | { 0x05, 0xffff, 0x2089 }, |
| 6323 | { 0x06, 0xffff, 0x5881 }, |
| 6324 | { 0x04, 0xffff, 0x154a }, |
| 6325 | { 0x01, 0xffff, 0x068b } |
| 6326 | }; |
| 6327 | |
| 6328 | /* disable aspm and clock request before access ephy */ |
| 6329 | RTL_W8(Config2, RTL_R8(Config2) & ~ClkReqEn); |
| 6330 | RTL_W8(Config5, RTL_R8(Config5) & ~ASPM_en); |
| 6331 | rtl_ephy_init(tp, e_info_8168h_1, ARRAY_SIZE(e_info_8168h_1)); |
| 6332 | |
| 6333 | RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
| 6334 | |
| 6335 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC); |
| 6336 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC); |
| 6337 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC); |
| 6338 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 6339 | |
| 6340 | rtl_csi_access_enable_1(tp); |
| 6341 | |
| 6342 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 6343 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6344 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 6345 | 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] | 6346 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6347 | 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] | 6348 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6349 | 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] | 6350 | |
| 6351 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC); |
| 6352 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6353 | RTL_W32(MISC, RTL_R32(MISC) & ~RXDV_GATED_EN); |
| 6354 | RTL_W8(MaxTxPacketSize, EarlySize); |
| 6355 | |
| 6356 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6357 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6358 | |
| 6359 | /* Adjust EEE LED frequency */ |
| 6360 | RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07); |
| 6361 | |
| 6362 | RTL_W8(DLLPR, RTL_R8(DLLPR) & ~PFM_EN); |
Chun-Hao Lin | 69f3dc3 | 2015-12-29 22:13:37 +0800 | [diff] [blame] | 6363 | RTL_W8(MISC_1, RTL_R8(MISC_1) & ~PFM_D3COLD_EN); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6364 | |
| 6365 | RTL_W8(DLLPR, RTL_R8(DLLPR) & ~TX_10M_PS_EN); |
| 6366 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6367 | 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] | 6368 | |
| 6369 | rtl_pcie_state_l2l3_enable(tp, false); |
| 6370 | |
| 6371 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 5849333 | 2015-12-24 21:15:27 +0800 | [diff] [blame] | 6372 | rg_saw_cnt = (rtl_readphy(tp, 0x13) & 0x3fff); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6373 | rtl_writephy(tp, 0x1f, 0x0000); |
| 6374 | if (rg_saw_cnt > 0) { |
| 6375 | u16 sw_cnt_1ms_ini; |
| 6376 | |
| 6377 | sw_cnt_1ms_ini = 16000000/rg_saw_cnt; |
| 6378 | sw_cnt_1ms_ini &= 0x0fff; |
| 6379 | data = r8168_mac_ocp_read(tp, 0xd412); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 6380 | data &= ~0x0fff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6381 | data |= sw_cnt_1ms_ini; |
| 6382 | r8168_mac_ocp_write(tp, 0xd412, data); |
| 6383 | } |
| 6384 | |
| 6385 | data = r8168_mac_ocp_read(tp, 0xe056); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 6386 | data &= ~0xf0; |
| 6387 | data |= 0x70; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6388 | r8168_mac_ocp_write(tp, 0xe056, data); |
| 6389 | |
| 6390 | data = r8168_mac_ocp_read(tp, 0xe052); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 6391 | data &= ~0x6000; |
| 6392 | data |= 0x8008; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6393 | r8168_mac_ocp_write(tp, 0xe052, data); |
| 6394 | |
| 6395 | data = r8168_mac_ocp_read(tp, 0xe0d6); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 6396 | data &= ~0x01ff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6397 | data |= 0x017f; |
| 6398 | r8168_mac_ocp_write(tp, 0xe0d6, data); |
| 6399 | |
| 6400 | data = r8168_mac_ocp_read(tp, 0xd420); |
Chun-Hao Lin | a2cb7ec | 2016-02-05 02:28:00 +0800 | [diff] [blame] | 6401 | data &= ~0x0fff; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6402 | data |= 0x047f; |
| 6403 | r8168_mac_ocp_write(tp, 0xd420, data); |
| 6404 | |
| 6405 | r8168_mac_ocp_write(tp, 0xe63e, 0x0001); |
| 6406 | r8168_mac_ocp_write(tp, 0xe63e, 0x0000); |
| 6407 | r8168_mac_ocp_write(tp, 0xc094, 0x0000); |
| 6408 | r8168_mac_ocp_write(tp, 0xc09e, 0x0000); |
| 6409 | } |
| 6410 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6411 | static void rtl_hw_start_8168ep(struct rtl8169_private *tp) |
| 6412 | { |
| 6413 | void __iomem *ioaddr = tp->mmio_addr; |
| 6414 | struct pci_dev *pdev = tp->pci_dev; |
| 6415 | |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 6416 | rtl8168ep_stop_cmac(tp); |
| 6417 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6418 | RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
| 6419 | |
| 6420 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC); |
| 6421 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x2f, ERIAR_EXGMAC); |
| 6422 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x5f, ERIAR_EXGMAC); |
| 6423 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 6424 | |
| 6425 | rtl_csi_access_enable_1(tp); |
| 6426 | |
| 6427 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 6428 | |
| 6429 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 6430 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 6431 | |
| 6432 | rtl_w0w1_eri(tp, 0xd4, ERIAR_MASK_1111, 0x1f80, 0x00, ERIAR_EXGMAC); |
| 6433 | |
| 6434 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC); |
| 6435 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6436 | RTL_W32(MISC, RTL_R32(MISC) & ~RXDV_GATED_EN); |
| 6437 | RTL_W8(MaxTxPacketSize, EarlySize); |
| 6438 | |
| 6439 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6440 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6441 | |
| 6442 | /* Adjust EEE LED frequency */ |
| 6443 | RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07); |
| 6444 | |
| 6445 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC); |
| 6446 | |
| 6447 | RTL_W8(DLLPR, RTL_R8(DLLPR) & ~TX_10M_PS_EN); |
| 6448 | |
| 6449 | rtl_pcie_state_l2l3_enable(tp, false); |
| 6450 | } |
| 6451 | |
| 6452 | static void rtl_hw_start_8168ep_1(struct rtl8169_private *tp) |
| 6453 | { |
| 6454 | void __iomem *ioaddr = tp->mmio_addr; |
| 6455 | static const struct ephy_info e_info_8168ep_1[] = { |
| 6456 | { 0x00, 0xffff, 0x10ab }, |
| 6457 | { 0x06, 0xffff, 0xf030 }, |
| 6458 | { 0x08, 0xffff, 0x2006 }, |
| 6459 | { 0x0d, 0xffff, 0x1666 }, |
| 6460 | { 0x0c, 0x3ff0, 0x0000 } |
| 6461 | }; |
| 6462 | |
| 6463 | /* disable aspm and clock request before access ephy */ |
| 6464 | RTL_W8(Config2, RTL_R8(Config2) & ~ClkReqEn); |
| 6465 | RTL_W8(Config5, RTL_R8(Config5) & ~ASPM_en); |
| 6466 | rtl_ephy_init(tp, e_info_8168ep_1, ARRAY_SIZE(e_info_8168ep_1)); |
| 6467 | |
| 6468 | rtl_hw_start_8168ep(tp); |
| 6469 | } |
| 6470 | |
| 6471 | static void rtl_hw_start_8168ep_2(struct rtl8169_private *tp) |
| 6472 | { |
| 6473 | void __iomem *ioaddr = tp->mmio_addr; |
| 6474 | static const struct ephy_info e_info_8168ep_2[] = { |
| 6475 | { 0x00, 0xffff, 0x10a3 }, |
| 6476 | { 0x19, 0xffff, 0xfc00 }, |
| 6477 | { 0x1e, 0xffff, 0x20ea } |
| 6478 | }; |
| 6479 | |
| 6480 | /* disable aspm and clock request before access ephy */ |
| 6481 | RTL_W8(Config2, RTL_R8(Config2) & ~ClkReqEn); |
| 6482 | RTL_W8(Config5, RTL_R8(Config5) & ~ASPM_en); |
| 6483 | rtl_ephy_init(tp, e_info_8168ep_2, ARRAY_SIZE(e_info_8168ep_2)); |
| 6484 | |
| 6485 | rtl_hw_start_8168ep(tp); |
| 6486 | |
| 6487 | RTL_W8(DLLPR, RTL_R8(DLLPR) & ~PFM_EN); |
Chun-Hao Lin | 69f3dc3 | 2015-12-29 22:13:37 +0800 | [diff] [blame] | 6488 | RTL_W8(MISC_1, RTL_R8(MISC_1) & ~PFM_D3COLD_EN); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6489 | } |
| 6490 | |
| 6491 | static void rtl_hw_start_8168ep_3(struct rtl8169_private *tp) |
| 6492 | { |
| 6493 | void __iomem *ioaddr = tp->mmio_addr; |
| 6494 | u32 data; |
| 6495 | static const struct ephy_info e_info_8168ep_3[] = { |
| 6496 | { 0x00, 0xffff, 0x10a3 }, |
| 6497 | { 0x19, 0xffff, 0x7c00 }, |
| 6498 | { 0x1e, 0xffff, 0x20eb }, |
| 6499 | { 0x0d, 0xffff, 0x1666 } |
| 6500 | }; |
| 6501 | |
| 6502 | /* disable aspm and clock request before access ephy */ |
| 6503 | RTL_W8(Config2, RTL_R8(Config2) & ~ClkReqEn); |
| 6504 | RTL_W8(Config5, RTL_R8(Config5) & ~ASPM_en); |
| 6505 | rtl_ephy_init(tp, e_info_8168ep_3, ARRAY_SIZE(e_info_8168ep_3)); |
| 6506 | |
| 6507 | rtl_hw_start_8168ep(tp); |
| 6508 | |
| 6509 | RTL_W8(DLLPR, RTL_R8(DLLPR) & ~PFM_EN); |
Chun-Hao Lin | 69f3dc3 | 2015-12-29 22:13:37 +0800 | [diff] [blame] | 6510 | RTL_W8(MISC_1, RTL_R8(MISC_1) & ~PFM_D3COLD_EN); |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6511 | |
| 6512 | data = r8168_mac_ocp_read(tp, 0xd3e2); |
| 6513 | data &= 0xf000; |
| 6514 | data |= 0x0271; |
| 6515 | r8168_mac_ocp_write(tp, 0xd3e2, data); |
| 6516 | |
| 6517 | data = r8168_mac_ocp_read(tp, 0xd3e4); |
| 6518 | data &= 0xff00; |
| 6519 | r8168_mac_ocp_write(tp, 0xd3e4, data); |
| 6520 | |
| 6521 | data = r8168_mac_ocp_read(tp, 0xe860); |
| 6522 | data |= 0x0080; |
| 6523 | r8168_mac_ocp_write(tp, 0xe860, data); |
| 6524 | } |
| 6525 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 6526 | static void rtl_hw_start_8168(struct net_device *dev) |
| 6527 | { |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6528 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6529 | void __iomem *ioaddr = tp->mmio_addr; |
| 6530 | |
| 6531 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 6532 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 6533 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6534 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6535 | rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6536 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 6537 | tp->cp_cmd |= RTL_R16(CPlusCmd) | PktCntrDisable | INTT_1; |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6538 | |
| 6539 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 6540 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 6541 | RTL_W16(IntrMitigate, 0x5151); |
| 6542 | |
| 6543 | /* Work around for RxFIFO overflow. */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 6544 | if (tp->mac_version == RTL_GIGA_MAC_VER_11) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6545 | tp->event_slow |= RxFIFOOver | PCSTimeout; |
| 6546 | tp->event_slow &= ~RxOverflow; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 6547 | } |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6548 | |
| 6549 | rtl_set_rx_tx_desc_registers(tp, ioaddr); |
| 6550 | |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6551 | rtl_set_rx_tx_config_registers(tp); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6552 | |
| 6553 | RTL_R8(IntrMask); |
| 6554 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6555 | switch (tp->mac_version) { |
| 6556 | case RTL_GIGA_MAC_VER_11: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6557 | rtl_hw_start_8168bb(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6558 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6559 | |
| 6560 | case RTL_GIGA_MAC_VER_12: |
| 6561 | case RTL_GIGA_MAC_VER_17: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6562 | rtl_hw_start_8168bef(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6563 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6564 | |
| 6565 | case RTL_GIGA_MAC_VER_18: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6566 | rtl_hw_start_8168cp_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6567 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6568 | |
| 6569 | case RTL_GIGA_MAC_VER_19: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6570 | rtl_hw_start_8168c_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6571 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6572 | |
| 6573 | case RTL_GIGA_MAC_VER_20: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6574 | rtl_hw_start_8168c_2(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6575 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6576 | |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 6577 | case RTL_GIGA_MAC_VER_21: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6578 | rtl_hw_start_8168c_3(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6579 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 6580 | |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 6581 | case RTL_GIGA_MAC_VER_22: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6582 | rtl_hw_start_8168c_4(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6583 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 6584 | |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 6585 | case RTL_GIGA_MAC_VER_23: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6586 | rtl_hw_start_8168cp_2(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6587 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 6588 | |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 6589 | case RTL_GIGA_MAC_VER_24: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6590 | rtl_hw_start_8168cp_3(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6591 | break; |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 6592 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 6593 | case RTL_GIGA_MAC_VER_25: |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 6594 | case RTL_GIGA_MAC_VER_26: |
| 6595 | case RTL_GIGA_MAC_VER_27: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6596 | rtl_hw_start_8168d(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6597 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 6598 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 6599 | case RTL_GIGA_MAC_VER_28: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6600 | rtl_hw_start_8168d_4(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6601 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6602 | |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6603 | case RTL_GIGA_MAC_VER_31: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6604 | rtl_hw_start_8168dp(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6605 | break; |
| 6606 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 6607 | case RTL_GIGA_MAC_VER_32: |
| 6608 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6609 | rtl_hw_start_8168e_1(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 6610 | break; |
| 6611 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6612 | rtl_hw_start_8168e_2(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 6613 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 6614 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 6615 | case RTL_GIGA_MAC_VER_35: |
| 6616 | case RTL_GIGA_MAC_VER_36: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6617 | rtl_hw_start_8168f_1(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 6618 | break; |
| 6619 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 6620 | case RTL_GIGA_MAC_VER_38: |
| 6621 | rtl_hw_start_8411(tp); |
| 6622 | break; |
| 6623 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6624 | case RTL_GIGA_MAC_VER_40: |
| 6625 | case RTL_GIGA_MAC_VER_41: |
| 6626 | rtl_hw_start_8168g_1(tp); |
| 6627 | break; |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 6628 | case RTL_GIGA_MAC_VER_42: |
| 6629 | rtl_hw_start_8168g_2(tp); |
| 6630 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6631 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 6632 | case RTL_GIGA_MAC_VER_44: |
| 6633 | rtl_hw_start_8411_2(tp); |
| 6634 | break; |
| 6635 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6636 | case RTL_GIGA_MAC_VER_45: |
| 6637 | case RTL_GIGA_MAC_VER_46: |
| 6638 | rtl_hw_start_8168h_1(tp); |
| 6639 | break; |
| 6640 | |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 6641 | case RTL_GIGA_MAC_VER_49: |
| 6642 | rtl_hw_start_8168ep_1(tp); |
| 6643 | break; |
| 6644 | |
| 6645 | case RTL_GIGA_MAC_VER_50: |
| 6646 | rtl_hw_start_8168ep_2(tp); |
| 6647 | break; |
| 6648 | |
| 6649 | case RTL_GIGA_MAC_VER_51: |
| 6650 | rtl_hw_start_8168ep_3(tp); |
| 6651 | break; |
| 6652 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6653 | default: |
| 6654 | printk(KERN_ERR PFX "%s: unknown chipset (mac_version = %d).\n", |
| 6655 | dev->name, tp->mac_version); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 6656 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 6657 | } |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 6658 | |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6659 | RTL_W8(Cfg9346, Cfg9346_Lock); |
| 6660 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 6661 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 6662 | |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6663 | rtl_set_rx_mode(dev); |
Francois Romieu | b836390 | 2008-06-01 12:31:57 +0200 | [diff] [blame] | 6664 | |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 6665 | RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 6666 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6667 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6668 | #define R810X_CPCMD_QUIRK_MASK (\ |
| 6669 | EnableBist | \ |
| 6670 | Mac_dbgo_oe | \ |
| 6671 | Force_half_dup | \ |
françois romieu | 5edcc53 | 2009-08-10 19:41:52 +0000 | [diff] [blame] | 6672 | Force_rxflow_en | \ |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6673 | Force_txflow_en | \ |
| 6674 | Cxpl_dbg_sel | \ |
| 6675 | ASF | \ |
| 6676 | PktCntrDisable | \ |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 6677 | Mac_dbgo_sel) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6678 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6679 | static void rtl_hw_start_8102e_1(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6680 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6681 | void __iomem *ioaddr = tp->mmio_addr; |
| 6682 | struct pci_dev *pdev = tp->pci_dev; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 6683 | static const struct ephy_info e_info_8102e_1[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6684 | { 0x01, 0, 0x6e65 }, |
| 6685 | { 0x02, 0, 0x091f }, |
| 6686 | { 0x03, 0, 0xc2f9 }, |
| 6687 | { 0x06, 0, 0xafb5 }, |
| 6688 | { 0x07, 0, 0x0e00 }, |
| 6689 | { 0x19, 0, 0xec80 }, |
| 6690 | { 0x01, 0, 0x2e65 }, |
| 6691 | { 0x01, 0, 0x6e65 } |
| 6692 | }; |
| 6693 | u8 cfg1; |
| 6694 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6695 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6696 | |
| 6697 | RTL_W8(DBG_REG, FIX_NAK_1); |
| 6698 | |
| 6699 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 6700 | |
| 6701 | RTL_W8(Config1, |
| 6702 | LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable); |
| 6703 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 6704 | |
| 6705 | cfg1 = RTL_R8(Config1); |
| 6706 | if ((cfg1 & LEDS0) && (cfg1 & LEDS1)) |
| 6707 | RTL_W8(Config1, cfg1 & ~LEDS0); |
| 6708 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6709 | 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] | 6710 | } |
| 6711 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6712 | static void rtl_hw_start_8102e_2(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6713 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6714 | void __iomem *ioaddr = tp->mmio_addr; |
| 6715 | struct pci_dev *pdev = tp->pci_dev; |
| 6716 | |
| 6717 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6718 | |
| 6719 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 6720 | |
| 6721 | RTL_W8(Config1, MEMMAP | IOMAP | VPD | PMEnable); |
| 6722 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6723 | } |
| 6724 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6725 | static void rtl_hw_start_8102e_3(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6726 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6727 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6728 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6729 | rtl_ephy_write(tp, 0x03, 0xc2f9); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6730 | } |
| 6731 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6732 | static void rtl_hw_start_8105e_1(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6733 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6734 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6735 | static const struct ephy_info e_info_8105e_1[] = { |
| 6736 | { 0x07, 0, 0x4000 }, |
| 6737 | { 0x19, 0, 0x0200 }, |
| 6738 | { 0x19, 0, 0x0020 }, |
| 6739 | { 0x1e, 0, 0x2000 }, |
| 6740 | { 0x03, 0, 0x0001 }, |
| 6741 | { 0x19, 0, 0x0100 }, |
| 6742 | { 0x19, 0, 0x0004 }, |
| 6743 | { 0x0a, 0, 0x0020 } |
| 6744 | }; |
| 6745 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6746 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6747 | RTL_W32(FuncEvent, RTL_R32(FuncEvent) | 0x002800); |
| 6748 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6749 | /* Disable Early Tally Counter */ |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6750 | RTL_W32(FuncEvent, RTL_R32(FuncEvent) & ~0x010000); |
| 6751 | |
| 6752 | RTL_W8(MCU, RTL_R8(MCU) | EN_NDP | EN_OOB_RESET); |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 6753 | RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6754 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6755 | 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] | 6756 | |
| 6757 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6758 | } |
| 6759 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6760 | static void rtl_hw_start_8105e_2(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6761 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6762 | rtl_hw_start_8105e_1(tp); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6763 | rtl_ephy_write(tp, 0x1e, rtl_ephy_read(tp, 0x1e) | 0x8000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6764 | } |
| 6765 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6766 | static void rtl_hw_start_8402(struct rtl8169_private *tp) |
| 6767 | { |
| 6768 | void __iomem *ioaddr = tp->mmio_addr; |
| 6769 | static const struct ephy_info e_info_8402[] = { |
| 6770 | { 0x19, 0xffff, 0xff64 }, |
| 6771 | { 0x1e, 0, 0x4000 } |
| 6772 | }; |
| 6773 | |
| 6774 | rtl_csi_access_enable_2(tp); |
| 6775 | |
| 6776 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
| 6777 | RTL_W32(FuncEvent, RTL_R32(FuncEvent) | 0x002800); |
| 6778 | |
| 6779 | RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
| 6780 | RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB); |
| 6781 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6782 | rtl_ephy_init(tp, e_info_8402, ARRAY_SIZE(e_info_8402)); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6783 | |
| 6784 | rtl_tx_performance_tweak(tp->pci_dev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 6785 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6786 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00000002, ERIAR_EXGMAC); |
| 6787 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00000006, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6788 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 6789 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6790 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6791 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame] | 6792 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0e00, 0xff00, ERIAR_EXGMAC); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 6793 | |
| 6794 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6795 | } |
| 6796 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6797 | static void rtl_hw_start_8106(struct rtl8169_private *tp) |
| 6798 | { |
| 6799 | void __iomem *ioaddr = tp->mmio_addr; |
| 6800 | |
| 6801 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
| 6802 | RTL_W32(FuncEvent, RTL_R32(FuncEvent) | 0x002800); |
| 6803 | |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 6804 | RTL_W32(MISC, (RTL_R32(MISC) | DISABLE_LAN_EN) & ~EARLY_TALLY_EN); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6805 | RTL_W8(MCU, RTL_R8(MCU) | EN_NDP | EN_OOB_RESET); |
| 6806 | RTL_W8(DLLPR, RTL_R8(DLLPR) & ~PFM_EN); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 6807 | |
| 6808 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6809 | } |
| 6810 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 6811 | static void rtl_hw_start_8101(struct net_device *dev) |
| 6812 | { |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6813 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6814 | void __iomem *ioaddr = tp->mmio_addr; |
| 6815 | struct pci_dev *pdev = tp->pci_dev; |
| 6816 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6817 | if (tp->mac_version >= RTL_GIGA_MAC_VER_30) |
| 6818 | tp->event_slow &= ~RxFIFOOver; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 6819 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6820 | if (tp->mac_version == RTL_GIGA_MAC_VER_13 || |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 6821 | tp->mac_version == RTL_GIGA_MAC_VER_16) |
Bjorn Helgaas | 8200bc7 | 2012-08-22 10:29:42 -0600 | [diff] [blame] | 6822 | pcie_capability_set_word(pdev, PCI_EXP_DEVCTL, |
| 6823 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6824 | |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 6825 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 6826 | |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6827 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
| 6828 | |
| 6829 | rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
| 6830 | |
| 6831 | tp->cp_cmd &= ~R810X_CPCMD_QUIRK_MASK; |
| 6832 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 6833 | |
| 6834 | rtl_set_rx_tx_desc_registers(tp, ioaddr); |
| 6835 | |
| 6836 | rtl_set_rx_tx_config_registers(tp); |
| 6837 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6838 | switch (tp->mac_version) { |
| 6839 | case RTL_GIGA_MAC_VER_07: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6840 | rtl_hw_start_8102e_1(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6841 | break; |
| 6842 | |
| 6843 | case RTL_GIGA_MAC_VER_08: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6844 | rtl_hw_start_8102e_3(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6845 | break; |
| 6846 | |
| 6847 | case RTL_GIGA_MAC_VER_09: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6848 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6849 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6850 | |
| 6851 | case RTL_GIGA_MAC_VER_29: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6852 | rtl_hw_start_8105e_1(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6853 | break; |
| 6854 | case RTL_GIGA_MAC_VER_30: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6855 | rtl_hw_start_8105e_2(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6856 | break; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6857 | |
| 6858 | case RTL_GIGA_MAC_VER_37: |
| 6859 | rtl_hw_start_8402(tp); |
| 6860 | break; |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6861 | |
| 6862 | case RTL_GIGA_MAC_VER_39: |
| 6863 | rtl_hw_start_8106(tp); |
| 6864 | break; |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 6865 | case RTL_GIGA_MAC_VER_43: |
| 6866 | rtl_hw_start_8168g_2(tp); |
| 6867 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6868 | case RTL_GIGA_MAC_VER_47: |
| 6869 | case RTL_GIGA_MAC_VER_48: |
| 6870 | rtl_hw_start_8168h_1(tp); |
| 6871 | break; |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6872 | } |
| 6873 | |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 6874 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6875 | |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6876 | RTL_W16(IntrMitigate, 0x0000); |
| 6877 | |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6878 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6879 | |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6880 | rtl_set_rx_mode(dev); |
| 6881 | |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6882 | RTL_R8(IntrMask); |
| 6883 | |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6884 | RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6885 | } |
| 6886 | |
| 6887 | static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) |
| 6888 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 6889 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6890 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 6891 | if (new_mtu > ETH_DATA_LEN) |
| 6892 | rtl_hw_jumbo_enable(tp); |
| 6893 | else |
| 6894 | rtl_hw_jumbo_disable(tp); |
| 6895 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6896 | dev->mtu = new_mtu; |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 6897 | netdev_update_features(dev); |
| 6898 | |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6899 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6900 | } |
| 6901 | |
| 6902 | static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc) |
| 6903 | { |
Al Viro | 95e0918 | 2007-12-22 18:55:39 +0000 | [diff] [blame] | 6904 | desc->addr = cpu_to_le64(0x0badbadbadbadbadull); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6905 | desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask); |
| 6906 | } |
| 6907 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6908 | static void rtl8169_free_rx_databuff(struct rtl8169_private *tp, |
| 6909 | void **data_buff, struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6910 | { |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6911 | dma_unmap_single(&tp->pci_dev->dev, le64_to_cpu(desc->addr), rx_buf_sz, |
Stanislaw Gruszka | 231aee6 | 2010-10-20 22:25:38 +0000 | [diff] [blame] | 6912 | DMA_FROM_DEVICE); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6913 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6914 | kfree(*data_buff); |
| 6915 | *data_buff = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6916 | rtl8169_make_unusable_by_asic(desc); |
| 6917 | } |
| 6918 | |
| 6919 | static inline void rtl8169_mark_to_asic(struct RxDesc *desc, u32 rx_buf_sz) |
| 6920 | { |
| 6921 | u32 eor = le32_to_cpu(desc->opts1) & RingEnd; |
| 6922 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 6923 | /* Force memory writes to complete before releasing descriptor */ |
| 6924 | dma_wmb(); |
| 6925 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6926 | desc->opts1 = cpu_to_le32(DescOwn | eor | rx_buf_sz); |
| 6927 | } |
| 6928 | |
| 6929 | static inline void rtl8169_map_to_asic(struct RxDesc *desc, dma_addr_t mapping, |
| 6930 | u32 rx_buf_sz) |
| 6931 | { |
| 6932 | desc->addr = cpu_to_le64(mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6933 | rtl8169_mark_to_asic(desc, rx_buf_sz); |
| 6934 | } |
| 6935 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6936 | static inline void *rtl8169_align(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6937 | { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6938 | return (void *)ALIGN((long)data, 16); |
| 6939 | } |
| 6940 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6941 | static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp, |
| 6942 | struct RxDesc *desc) |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6943 | { |
| 6944 | void *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6945 | dma_addr_t mapping; |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6946 | struct device *d = &tp->pci_dev->dev; |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6947 | struct net_device *dev = tp->dev; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6948 | int node = dev->dev.parent ? dev_to_node(dev->dev.parent) : -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6949 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6950 | data = kmalloc_node(rx_buf_sz, GFP_KERNEL, node); |
| 6951 | if (!data) |
| 6952 | return NULL; |
Francois Romieu | e9f63f3 | 2007-02-28 23:16:57 +0100 | [diff] [blame] | 6953 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6954 | if (rtl8169_align(data) != data) { |
| 6955 | kfree(data); |
| 6956 | data = kmalloc_node(rx_buf_sz + 15, GFP_KERNEL, node); |
| 6957 | if (!data) |
| 6958 | return NULL; |
| 6959 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6960 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6961 | mapping = dma_map_single(d, rtl8169_align(data), rx_buf_sz, |
Stanislaw Gruszka | 231aee6 | 2010-10-20 22:25:38 +0000 | [diff] [blame] | 6962 | DMA_FROM_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6963 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 6964 | if (net_ratelimit()) |
| 6965 | netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6966 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6967 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6968 | |
| 6969 | rtl8169_map_to_asic(desc, mapping, rx_buf_sz); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6970 | return data; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6971 | |
| 6972 | err_out: |
| 6973 | kfree(data); |
| 6974 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6975 | } |
| 6976 | |
| 6977 | static void rtl8169_rx_clear(struct rtl8169_private *tp) |
| 6978 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 6979 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6980 | |
| 6981 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6982 | if (tp->Rx_databuff[i]) { |
| 6983 | rtl8169_free_rx_databuff(tp, tp->Rx_databuff + i, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6984 | tp->RxDescArray + i); |
| 6985 | } |
| 6986 | } |
| 6987 | } |
| 6988 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6989 | static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6990 | { |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6991 | desc->opts1 |= cpu_to_le32(RingEnd); |
| 6992 | } |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6993 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6994 | static int rtl8169_rx_fill(struct rtl8169_private *tp) |
| 6995 | { |
| 6996 | unsigned int i; |
| 6997 | |
| 6998 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6999 | void *data; |
Francois Romieu | 4ae47c2 | 2007-06-16 23:28:45 +0200 | [diff] [blame] | 7000 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7001 | if (tp->Rx_databuff[i]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7002 | continue; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 7003 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 7004 | data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7005 | if (!data) { |
| 7006 | rtl8169_make_unusable_by_asic(tp->RxDescArray + i); |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 7007 | goto err_out; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7008 | } |
| 7009 | tp->Rx_databuff[i] = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7010 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7011 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 7012 | rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1); |
| 7013 | return 0; |
| 7014 | |
| 7015 | err_out: |
| 7016 | rtl8169_rx_clear(tp); |
| 7017 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7018 | } |
| 7019 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7020 | static int rtl8169_init_ring(struct net_device *dev) |
| 7021 | { |
| 7022 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7023 | |
| 7024 | rtl8169_init_ring_indexes(tp); |
| 7025 | |
| 7026 | memset(tp->tx_skb, 0x0, NUM_TX_DESC * sizeof(struct ring_info)); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7027 | memset(tp->Rx_databuff, 0x0, NUM_RX_DESC * sizeof(void *)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7028 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 7029 | return rtl8169_rx_fill(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7030 | } |
| 7031 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 7032 | 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] | 7033 | struct TxDesc *desc) |
| 7034 | { |
| 7035 | unsigned int len = tx_skb->len; |
| 7036 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 7037 | dma_unmap_single(d, le64_to_cpu(desc->addr), len, DMA_TO_DEVICE); |
| 7038 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7039 | desc->opts1 = 0x00; |
| 7040 | desc->opts2 = 0x00; |
| 7041 | desc->addr = 0x00; |
| 7042 | tx_skb->len = 0; |
| 7043 | } |
| 7044 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7045 | static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, |
| 7046 | unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7047 | { |
| 7048 | unsigned int i; |
| 7049 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7050 | for (i = 0; i < n; i++) { |
| 7051 | unsigned int entry = (start + i) % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7052 | struct ring_info *tx_skb = tp->tx_skb + entry; |
| 7053 | unsigned int len = tx_skb->len; |
| 7054 | |
| 7055 | if (len) { |
| 7056 | struct sk_buff *skb = tx_skb->skb; |
| 7057 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 7058 | rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7059 | tp->TxDescArray + entry); |
| 7060 | if (skb) { |
Florian Fainelli | 7a4b813c | 2017-08-24 18:34:44 -0700 | [diff] [blame] | 7061 | dev_consume_skb_any(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7062 | tx_skb->skb = NULL; |
| 7063 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7064 | } |
| 7065 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7066 | } |
| 7067 | |
| 7068 | static void rtl8169_tx_clear(struct rtl8169_private *tp) |
| 7069 | { |
| 7070 | rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7071 | tp->cur_tx = tp->dirty_tx = 0; |
| 7072 | } |
| 7073 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 7074 | static void rtl_reset_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7075 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 7076 | struct net_device *dev = tp->dev; |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 7077 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7078 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7079 | napi_disable(&tp->napi); |
| 7080 | netif_stop_queue(dev); |
| 7081 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7082 | |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 7083 | rtl8169_hw_reset(tp); |
| 7084 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 7085 | for (i = 0; i < NUM_RX_DESC; i++) |
| 7086 | rtl8169_mark_to_asic(tp->RxDescArray + i, rx_buf_sz); |
| 7087 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7088 | rtl8169_tx_clear(tp); |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 7089 | rtl8169_init_ring_indexes(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7090 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7091 | napi_enable(&tp->napi); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 7092 | rtl_hw_start(dev); |
| 7093 | netif_wake_queue(dev); |
| 7094 | rtl8169_check_link_status(dev, tp, tp->mmio_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7095 | } |
| 7096 | |
| 7097 | static void rtl8169_tx_timeout(struct net_device *dev) |
| 7098 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7099 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7100 | |
| 7101 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7102 | } |
| 7103 | |
| 7104 | 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] | 7105 | u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7106 | { |
| 7107 | struct skb_shared_info *info = skb_shinfo(skb); |
| 7108 | unsigned int cur_frag, entry; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 7109 | struct TxDesc *uninitialized_var(txd); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 7110 | struct device *d = &tp->pci_dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7111 | |
| 7112 | entry = tp->cur_tx; |
| 7113 | for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7114 | const skb_frag_t *frag = info->frags + cur_frag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7115 | dma_addr_t mapping; |
| 7116 | u32 status, len; |
| 7117 | void *addr; |
| 7118 | |
| 7119 | entry = (entry + 1) % NUM_TX_DESC; |
| 7120 | |
| 7121 | txd = tp->TxDescArray + entry; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 7122 | len = skb_frag_size(frag); |
Ian Campbell | 929f618 | 2011-08-31 00:47:06 +0000 | [diff] [blame] | 7123 | addr = skb_frag_address(frag); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 7124 | mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 7125 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 7126 | if (net_ratelimit()) |
| 7127 | netif_err(tp, drv, tp->dev, |
| 7128 | "Failed to map TX fragments DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7129 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 7130 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7131 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7132 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7133 | status = opts[0] | len | |
| 7134 | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7135 | |
| 7136 | txd->opts1 = cpu_to_le32(status); |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7137 | txd->opts2 = cpu_to_le32(opts[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7138 | txd->addr = cpu_to_le64(mapping); |
| 7139 | |
| 7140 | tp->tx_skb[entry].len = len; |
| 7141 | } |
| 7142 | |
| 7143 | if (cur_frag) { |
| 7144 | tp->tx_skb[entry].skb = skb; |
| 7145 | txd->opts1 |= cpu_to_le32(LastFrag); |
| 7146 | } |
| 7147 | |
| 7148 | return cur_frag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7149 | |
| 7150 | err_out: |
| 7151 | rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag); |
| 7152 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7153 | } |
| 7154 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 7155 | static bool rtl_test_hw_pad_bug(struct rtl8169_private *tp, struct sk_buff *skb) |
| 7156 | { |
| 7157 | return skb->len < ETH_ZLEN && tp->mac_version == RTL_GIGA_MAC_VER_34; |
| 7158 | } |
| 7159 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7160 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 7161 | struct net_device *dev); |
| 7162 | /* r8169_csum_workaround() |
| 7163 | * The hw limites the value the transport offset. When the offset is out of the |
| 7164 | * range, calculate the checksum by sw. |
| 7165 | */ |
| 7166 | static void r8169_csum_workaround(struct rtl8169_private *tp, |
| 7167 | struct sk_buff *skb) |
| 7168 | { |
| 7169 | if (skb_shinfo(skb)->gso_size) { |
| 7170 | netdev_features_t features = tp->dev->features; |
| 7171 | struct sk_buff *segs, *nskb; |
| 7172 | |
| 7173 | features &= ~(NETIF_F_SG | NETIF_F_IPV6_CSUM | NETIF_F_TSO6); |
| 7174 | segs = skb_gso_segment(skb, features); |
| 7175 | if (IS_ERR(segs) || !segs) |
| 7176 | goto drop; |
| 7177 | |
| 7178 | do { |
| 7179 | nskb = segs; |
| 7180 | segs = segs->next; |
| 7181 | nskb->next = NULL; |
| 7182 | rtl8169_start_xmit(nskb, tp->dev); |
| 7183 | } while (segs); |
| 7184 | |
Alexander Duyck | eb78139 | 2015-05-01 10:34:44 -0700 | [diff] [blame] | 7185 | dev_consume_skb_any(skb); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7186 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 7187 | if (skb_checksum_help(skb) < 0) |
| 7188 | goto drop; |
| 7189 | |
| 7190 | rtl8169_start_xmit(skb, tp->dev); |
| 7191 | } else { |
| 7192 | struct net_device_stats *stats; |
| 7193 | |
| 7194 | drop: |
| 7195 | stats = &tp->dev->stats; |
| 7196 | stats->tx_dropped++; |
Alexander Duyck | eb78139 | 2015-05-01 10:34:44 -0700 | [diff] [blame] | 7197 | dev_kfree_skb_any(skb); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7198 | } |
| 7199 | } |
| 7200 | |
| 7201 | /* msdn_giant_send_check() |
| 7202 | * According to the document of microsoft, the TCP Pseudo Header excludes the |
| 7203 | * packet length for IPv6 TCP large packets. |
| 7204 | */ |
| 7205 | static int msdn_giant_send_check(struct sk_buff *skb) |
| 7206 | { |
| 7207 | const struct ipv6hdr *ipv6h; |
| 7208 | struct tcphdr *th; |
| 7209 | int ret; |
| 7210 | |
| 7211 | ret = skb_cow_head(skb, 0); |
| 7212 | if (ret) |
| 7213 | return ret; |
| 7214 | |
| 7215 | ipv6h = ipv6_hdr(skb); |
| 7216 | th = tcp_hdr(skb); |
| 7217 | |
| 7218 | th->check = 0; |
| 7219 | th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0); |
| 7220 | |
| 7221 | return ret; |
| 7222 | } |
| 7223 | |
| 7224 | static inline __be16 get_protocol(struct sk_buff *skb) |
| 7225 | { |
| 7226 | __be16 protocol; |
| 7227 | |
| 7228 | if (skb->protocol == htons(ETH_P_8021Q)) |
| 7229 | protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto; |
| 7230 | else |
| 7231 | protocol = skb->protocol; |
| 7232 | |
| 7233 | return protocol; |
| 7234 | } |
| 7235 | |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7236 | static bool rtl8169_tso_csum_v1(struct rtl8169_private *tp, |
| 7237 | struct sk_buff *skb, u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7238 | { |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 7239 | u32 mss = skb_shinfo(skb)->gso_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7240 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7241 | if (mss) { |
| 7242 | opts[0] |= TD_LSO; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7243 | opts[0] |= min(mss, TD_MSS_MAX) << TD0_MSS_SHIFT; |
| 7244 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 7245 | const struct iphdr *ip = ip_hdr(skb); |
| 7246 | |
| 7247 | if (ip->protocol == IPPROTO_TCP) |
| 7248 | opts[0] |= TD0_IP_CS | TD0_TCP_CS; |
| 7249 | else if (ip->protocol == IPPROTO_UDP) |
| 7250 | opts[0] |= TD0_IP_CS | TD0_UDP_CS; |
| 7251 | else |
| 7252 | WARN_ON_ONCE(1); |
| 7253 | } |
| 7254 | |
| 7255 | return true; |
| 7256 | } |
| 7257 | |
| 7258 | static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp, |
| 7259 | struct sk_buff *skb, u32 *opts) |
| 7260 | { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 7261 | u32 transport_offset = (u32)skb_transport_offset(skb); |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7262 | u32 mss = skb_shinfo(skb)->gso_size; |
| 7263 | |
| 7264 | if (mss) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7265 | if (transport_offset > GTTCPHO_MAX) { |
| 7266 | netif_warn(tp, tx_err, tp->dev, |
| 7267 | "Invalid transport offset 0x%x for TSO\n", |
| 7268 | transport_offset); |
| 7269 | return false; |
| 7270 | } |
| 7271 | |
| 7272 | switch (get_protocol(skb)) { |
| 7273 | case htons(ETH_P_IP): |
| 7274 | opts[0] |= TD1_GTSENV4; |
| 7275 | break; |
| 7276 | |
| 7277 | case htons(ETH_P_IPV6): |
| 7278 | if (msdn_giant_send_check(skb)) |
| 7279 | return false; |
| 7280 | |
| 7281 | opts[0] |= TD1_GTSENV6; |
| 7282 | break; |
| 7283 | |
| 7284 | default: |
| 7285 | WARN_ON_ONCE(1); |
| 7286 | break; |
| 7287 | } |
| 7288 | |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 7289 | opts[0] |= transport_offset << GTTCPHO_SHIFT; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7290 | opts[1] |= min(mss, TD_MSS_MAX) << TD1_MSS_SHIFT; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7291 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7292 | u8 ip_protocol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7293 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 7294 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
Alexander Duyck | 207c5f4 | 2014-12-03 08:18:04 -0800 | [diff] [blame] | 7295 | return !(skb_checksum_help(skb) || eth_skb_pad(skb)); |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 7296 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7297 | if (transport_offset > TCPHO_MAX) { |
| 7298 | netif_warn(tp, tx_err, tp->dev, |
| 7299 | "Invalid transport offset 0x%x\n", |
| 7300 | transport_offset); |
| 7301 | return false; |
| 7302 | } |
| 7303 | |
| 7304 | switch (get_protocol(skb)) { |
| 7305 | case htons(ETH_P_IP): |
| 7306 | opts[1] |= TD1_IPv4_CS; |
| 7307 | ip_protocol = ip_hdr(skb)->protocol; |
| 7308 | break; |
| 7309 | |
| 7310 | case htons(ETH_P_IPV6): |
| 7311 | opts[1] |= TD1_IPv6_CS; |
| 7312 | ip_protocol = ipv6_hdr(skb)->nexthdr; |
| 7313 | break; |
| 7314 | |
| 7315 | default: |
| 7316 | ip_protocol = IPPROTO_RAW; |
| 7317 | break; |
| 7318 | } |
| 7319 | |
| 7320 | if (ip_protocol == IPPROTO_TCP) |
| 7321 | opts[1] |= TD1_TCP_CS; |
| 7322 | else if (ip_protocol == IPPROTO_UDP) |
| 7323 | opts[1] |= TD1_UDP_CS; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7324 | else |
| 7325 | WARN_ON_ONCE(1); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7326 | |
| 7327 | opts[1] |= transport_offset << TCPHO_SHIFT; |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 7328 | } else { |
| 7329 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
Alexander Duyck | 207c5f4 | 2014-12-03 08:18:04 -0800 | [diff] [blame] | 7330 | return !eth_skb_pad(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7331 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7332 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 7333 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7334 | } |
| 7335 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 7336 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 7337 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7338 | { |
| 7339 | struct rtl8169_private *tp = netdev_priv(dev); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7340 | unsigned int entry = tp->cur_tx % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7341 | struct TxDesc *txd = tp->TxDescArray + entry; |
| 7342 | void __iomem *ioaddr = tp->mmio_addr; |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 7343 | struct device *d = &tp->pci_dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7344 | dma_addr_t mapping; |
| 7345 | u32 status, len; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7346 | u32 opts[2]; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7347 | int frags; |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 7348 | |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 7349 | if (unlikely(!TX_FRAGS_READY_FOR(tp, skb_shinfo(skb)->nr_frags))) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 7350 | 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] | 7351 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7352 | } |
| 7353 | |
| 7354 | if (unlikely(le32_to_cpu(txd->opts1) & DescOwn)) |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7355 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7356 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 7357 | opts[1] = cpu_to_le32(rtl8169_tx_vlan_tag(skb)); |
| 7358 | opts[0] = DescOwn; |
| 7359 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7360 | if (!tp->tso_csum(tp, skb, opts)) { |
| 7361 | r8169_csum_workaround(tp, skb); |
| 7362 | return NETDEV_TX_OK; |
| 7363 | } |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 7364 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7365 | len = skb_headlen(skb); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 7366 | mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 7367 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 7368 | if (net_ratelimit()) |
| 7369 | netif_err(tp, drv, dev, "Failed to map TX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7370 | goto err_dma_0; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 7371 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7372 | |
| 7373 | tp->tx_skb[entry].len = len; |
| 7374 | txd->addr = cpu_to_le64(mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7375 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7376 | frags = rtl8169_xmit_frags(tp, skb, opts); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7377 | if (frags < 0) |
| 7378 | goto err_dma_1; |
| 7379 | else if (frags) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7380 | opts[0] |= FirstFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7381 | else { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7382 | opts[0] |= FirstFrag | LastFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7383 | tp->tx_skb[entry].skb = skb; |
| 7384 | } |
| 7385 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7386 | txd->opts2 = cpu_to_le32(opts[1]); |
| 7387 | |
Richard Cochran | 5047fb5 | 2012-03-10 07:29:42 +0000 | [diff] [blame] | 7388 | skb_tx_timestamp(skb); |
| 7389 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 7390 | /* Force memory writes to complete before releasing descriptor */ |
| 7391 | dma_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7392 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7393 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 7394 | status = opts[0] | len | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7395 | txd->opts1 = cpu_to_le32(status); |
| 7396 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 7397 | /* Force all memory writes to complete before notifying device */ |
David Dillow | 4c020a9 | 2010-03-03 16:33:10 +0000 | [diff] [blame] | 7398 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7399 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 7400 | tp->cur_tx += frags + 1; |
| 7401 | |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 7402 | RTL_W8(TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7403 | |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 7404 | mmiowb(); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7405 | |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 7406 | if (!TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 7407 | /* Avoid wrongly optimistic queue wake-up: rtl_tx thread must |
| 7408 | * not miss a ring update when it notices a stopped queue. |
| 7409 | */ |
| 7410 | smp_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7411 | netif_stop_queue(dev); |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 7412 | /* Sync with rtl_tx: |
| 7413 | * - publish queue status and cur_tx ring index (write barrier) |
| 7414 | * - refresh dirty_tx ring index (read barrier). |
| 7415 | * May the current thread have a pessimistic view of the ring |
| 7416 | * status and forget to wake up queue, a racing rtl_tx thread |
| 7417 | * can't. |
| 7418 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 7419 | smp_mb(); |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 7420 | if (TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7421 | netif_wake_queue(dev); |
| 7422 | } |
| 7423 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 7424 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7425 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7426 | err_dma_1: |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 7427 | rtl8169_unmap_tx_skb(d, tp->tx_skb + entry, txd); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7428 | err_dma_0: |
Eric W. Biederman | 989c9ba | 2014-03-11 14:16:14 -0700 | [diff] [blame] | 7429 | dev_kfree_skb_any(skb); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 7430 | dev->stats.tx_dropped++; |
| 7431 | return NETDEV_TX_OK; |
| 7432 | |
| 7433 | err_stop_0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7434 | netif_stop_queue(dev); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 7435 | dev->stats.tx_dropped++; |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 7436 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7437 | } |
| 7438 | |
| 7439 | static void rtl8169_pcierr_interrupt(struct net_device *dev) |
| 7440 | { |
| 7441 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7442 | struct pci_dev *pdev = tp->pci_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7443 | u16 pci_status, pci_cmd; |
| 7444 | |
| 7445 | pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); |
| 7446 | pci_read_config_word(pdev, PCI_STATUS, &pci_status); |
| 7447 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 7448 | netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n", |
| 7449 | pci_cmd, pci_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7450 | |
| 7451 | /* |
| 7452 | * The recovery sequence below admits a very elaborated explanation: |
| 7453 | * - it seems to work; |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 7454 | * - I did not see what else could be done; |
| 7455 | * - it makes iop3xx happy. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7456 | * |
| 7457 | * Feel free to adjust to your needs. |
| 7458 | */ |
Francois Romieu | a27993f | 2006-12-18 00:04:19 +0100 | [diff] [blame] | 7459 | if (pdev->broken_parity_status) |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 7460 | pci_cmd &= ~PCI_COMMAND_PARITY; |
| 7461 | else |
| 7462 | pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; |
| 7463 | |
| 7464 | pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7465 | |
| 7466 | pci_write_config_word(pdev, PCI_STATUS, |
| 7467 | pci_status & (PCI_STATUS_DETECTED_PARITY | |
| 7468 | PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT | |
| 7469 | PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT)); |
| 7470 | |
| 7471 | /* The infamous DAC f*ckup only happens at boot time */ |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 7472 | if ((tp->cp_cmd & PCIDAC) && !tp->cur_rx) { |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 7473 | void __iomem *ioaddr = tp->mmio_addr; |
| 7474 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 7475 | netif_info(tp, intr, dev, "disabling PCI DAC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7476 | tp->cp_cmd &= ~PCIDAC; |
| 7477 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 7478 | dev->features &= ~NETIF_F_HIGHDMA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7479 | } |
| 7480 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 7481 | rtl8169_hw_reset(tp); |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 7482 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 7483 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7484 | } |
| 7485 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7486 | static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7487 | { |
| 7488 | unsigned int dirty_tx, tx_left; |
| 7489 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7490 | dirty_tx = tp->dirty_tx; |
| 7491 | smp_rmb(); |
| 7492 | tx_left = tp->cur_tx - dirty_tx; |
| 7493 | |
| 7494 | while (tx_left > 0) { |
| 7495 | unsigned int entry = dirty_tx % NUM_TX_DESC; |
| 7496 | struct ring_info *tx_skb = tp->tx_skb + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7497 | u32 status; |
| 7498 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7499 | status = le32_to_cpu(tp->TxDescArray[entry].opts1); |
| 7500 | if (status & DescOwn) |
| 7501 | break; |
| 7502 | |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 7503 | /* This barrier is needed to keep us from reading |
| 7504 | * any other fields out of the Tx descriptor until |
| 7505 | * we know the status of DescOwn |
| 7506 | */ |
| 7507 | dma_rmb(); |
| 7508 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 7509 | rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb, |
| 7510 | tp->TxDescArray + entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7511 | if (status & LastFrag) { |
David S. Miller | 87cda7c | 2015-02-22 15:54:29 -0500 | [diff] [blame] | 7512 | u64_stats_update_begin(&tp->tx_stats.syncp); |
| 7513 | tp->tx_stats.packets++; |
| 7514 | tp->tx_stats.bytes += tx_skb->skb->len; |
| 7515 | u64_stats_update_end(&tp->tx_stats.syncp); |
Florian Fainelli | 7a4b813c | 2017-08-24 18:34:44 -0700 | [diff] [blame] | 7516 | dev_consume_skb_any(tx_skb->skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7517 | tx_skb->skb = NULL; |
| 7518 | } |
| 7519 | dirty_tx++; |
| 7520 | tx_left--; |
| 7521 | } |
| 7522 | |
| 7523 | if (tp->dirty_tx != dirty_tx) { |
| 7524 | tp->dirty_tx = dirty_tx; |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 7525 | /* Sync with rtl8169_start_xmit: |
| 7526 | * - publish dirty_tx ring index (write barrier) |
| 7527 | * - refresh cur_tx ring index and queue status (read barrier) |
| 7528 | * May the current thread miss the stopped queue condition, |
| 7529 | * a racing xmit thread can only have a right view of the |
| 7530 | * ring status. |
| 7531 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 7532 | smp_mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7533 | if (netif_queue_stopped(dev) && |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 7534 | TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7535 | netif_wake_queue(dev); |
| 7536 | } |
Francois Romieu | d78ae2d | 2007-08-26 20:08:19 +0200 | [diff] [blame] | 7537 | /* |
| 7538 | * 8168 hack: TxPoll requests are lost when the Tx packets are |
| 7539 | * too close. Let's kick an extra TxPoll request when a burst |
| 7540 | * of start_xmit activity is detected (if it is not detected, |
| 7541 | * it is slow enough). -- FR |
| 7542 | */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7543 | if (tp->cur_tx != dirty_tx) { |
| 7544 | void __iomem *ioaddr = tp->mmio_addr; |
| 7545 | |
Francois Romieu | d78ae2d | 2007-08-26 20:08:19 +0200 | [diff] [blame] | 7546 | RTL_W8(TxPoll, NPQ); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7547 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7548 | } |
| 7549 | } |
| 7550 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 7551 | static inline int rtl8169_fragmented_frame(u32 status) |
| 7552 | { |
| 7553 | return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag); |
| 7554 | } |
| 7555 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 7556 | static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7557 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7558 | u32 status = opts1 & RxProtoMask; |
| 7559 | |
| 7560 | if (((status == RxProtoTCP) && !(opts1 & TCPFail)) || |
Shan Wei | d5d3ebe | 2010-11-12 00:15:25 +0000 | [diff] [blame] | 7561 | ((status == RxProtoUDP) && !(opts1 & UDPFail))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7562 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 7563 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 7564 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7565 | } |
| 7566 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7567 | static struct sk_buff *rtl8169_try_rx_copy(void *data, |
| 7568 | struct rtl8169_private *tp, |
| 7569 | int pkt_size, |
| 7570 | dma_addr_t addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7571 | { |
Stephen Hemminger | b449655 | 2007-06-17 01:06:49 +0200 | [diff] [blame] | 7572 | struct sk_buff *skb; |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 7573 | struct device *d = &tp->pci_dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7574 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7575 | data = rtl8169_align(data); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 7576 | dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7577 | prefetch(data); |
Alexander Duyck | e2338f8 | 2014-12-09 19:41:09 -0800 | [diff] [blame] | 7578 | skb = napi_alloc_skb(&tp->napi, pkt_size); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7579 | if (skb) |
| 7580 | memcpy(skb->data, data, pkt_size); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 7581 | dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE); |
| 7582 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7583 | return skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7584 | } |
| 7585 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7586 | 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] | 7587 | { |
| 7588 | unsigned int cur_rx, rx_left; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7589 | unsigned int count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7590 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7591 | cur_rx = tp->cur_rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7592 | |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 7593 | 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] | 7594 | unsigned int entry = cur_rx % NUM_RX_DESC; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 7595 | struct RxDesc *desc = tp->RxDescArray + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7596 | u32 status; |
| 7597 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 7598 | status = le32_to_cpu(desc->opts1) & tp->opts1_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7599 | if (status & DescOwn) |
| 7600 | break; |
Alexander Duyck | a075013 | 2014-12-11 15:02:17 -0800 | [diff] [blame] | 7601 | |
| 7602 | /* This barrier is needed to keep us from reading |
| 7603 | * any other fields out of the Rx descriptor until |
| 7604 | * we know the status of DescOwn |
| 7605 | */ |
| 7606 | dma_rmb(); |
| 7607 | |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 7608 | if (unlikely(status & RxRES)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 7609 | netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n", |
| 7610 | status); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 7611 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7612 | if (status & (RxRWT | RxRUNT)) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 7613 | dev->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7614 | if (status & RxCRC) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 7615 | dev->stats.rx_crc_errors++; |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 7616 | if (status & RxFOVF) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7617 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 7618 | dev->stats.rx_fifo_errors++; |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 7619 | } |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 7620 | if ((status & (RxRUNT | RxCRC)) && |
| 7621 | !(status & (RxRWT | RxFOVF)) && |
| 7622 | (dev->features & NETIF_F_RXALL)) |
| 7623 | goto process_pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7624 | } else { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7625 | struct sk_buff *skb; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 7626 | dma_addr_t addr; |
| 7627 | int pkt_size; |
| 7628 | |
| 7629 | process_pkt: |
| 7630 | addr = le64_to_cpu(desc->addr); |
Ben Greear | 79d0c1d | 2012-02-10 15:04:34 +0000 | [diff] [blame] | 7631 | if (likely(!(dev->features & NETIF_F_RXFCS))) |
| 7632 | pkt_size = (status & 0x00003fff) - 4; |
| 7633 | else |
| 7634 | pkt_size = status & 0x00003fff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7635 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 7636 | /* |
| 7637 | * The driver does not support incoming fragmented |
| 7638 | * frames. They are seen as a symptom of over-mtu |
| 7639 | * sized frames. |
| 7640 | */ |
| 7641 | if (unlikely(rtl8169_fragmented_frame(status))) { |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 7642 | dev->stats.rx_dropped++; |
| 7643 | dev->stats.rx_length_errors++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 7644 | goto release_descriptor; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 7645 | } |
| 7646 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7647 | skb = rtl8169_try_rx_copy(tp->Rx_databuff[entry], |
| 7648 | tp, pkt_size, addr); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 7649 | if (!skb) { |
| 7650 | dev->stats.rx_dropped++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 7651 | goto release_descriptor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7652 | } |
| 7653 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 7654 | rtl8169_rx_csum(skb, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7655 | skb_put(skb, pkt_size); |
| 7656 | skb->protocol = eth_type_trans(skb, dev); |
| 7657 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 7658 | rtl8169_rx_vlan_tag(desc, skb); |
| 7659 | |
françois romieu | 3917429 | 2015-11-11 23:35:18 +0100 | [diff] [blame] | 7660 | if (skb->pkt_type == PACKET_MULTICAST) |
| 7661 | dev->stats.multicast++; |
| 7662 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 7663 | napi_gro_receive(&tp->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7664 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7665 | u64_stats_update_begin(&tp->rx_stats.syncp); |
| 7666 | tp->rx_stats.packets++; |
| 7667 | tp->rx_stats.bytes += pkt_size; |
| 7668 | u64_stats_update_end(&tp->rx_stats.syncp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7669 | } |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 7670 | release_descriptor: |
| 7671 | desc->opts2 = 0; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 7672 | rtl8169_mark_to_asic(desc, rx_buf_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7673 | } |
| 7674 | |
| 7675 | count = cur_rx - tp->cur_rx; |
| 7676 | tp->cur_rx = cur_rx; |
| 7677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7678 | return count; |
| 7679 | } |
| 7680 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 7681 | static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7682 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 7683 | struct net_device *dev = dev_instance; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7684 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7685 | int handled = 0; |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 7686 | u16 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7687 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 7688 | status = rtl_get_events(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7689 | if (status && status != 0xffff) { |
| 7690 | status &= RTL_EVENT_NAPI | tp->event_slow; |
| 7691 | if (status) { |
| 7692 | handled = 1; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 7693 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7694 | rtl_irq_disable(tp); |
| 7695 | napi_schedule(&tp->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7696 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7697 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7698 | return IRQ_RETVAL(handled); |
| 7699 | } |
| 7700 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7701 | /* |
| 7702 | * Workqueue context. |
| 7703 | */ |
| 7704 | static void rtl_slow_event_work(struct rtl8169_private *tp) |
| 7705 | { |
| 7706 | struct net_device *dev = tp->dev; |
| 7707 | u16 status; |
| 7708 | |
| 7709 | status = rtl_get_events(tp) & tp->event_slow; |
| 7710 | rtl_ack_events(tp, status); |
| 7711 | |
| 7712 | if (unlikely(status & RxFIFOOver)) { |
| 7713 | switch (tp->mac_version) { |
| 7714 | /* Work around for rx fifo overflow */ |
| 7715 | case RTL_GIGA_MAC_VER_11: |
| 7716 | netif_stop_queue(dev); |
Francois Romieu | 934714d | 2012-01-31 11:09:21 +0100 | [diff] [blame] | 7717 | /* XXX - Hack alert. See rtl_task(). */ |
| 7718 | set_bit(RTL_FLAG_TASK_RESET_PENDING, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7719 | default: |
| 7720 | break; |
| 7721 | } |
| 7722 | } |
| 7723 | |
| 7724 | if (unlikely(status & SYSErr)) |
| 7725 | rtl8169_pcierr_interrupt(dev); |
| 7726 | |
| 7727 | if (status & LinkChg) |
Heiner Kallweit | ef4d5fc | 2018-01-08 21:39:07 +0100 | [diff] [blame] | 7728 | rtl8169_check_link_status(dev, tp, tp->mmio_addr); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7729 | |
françois romieu | 7dbb491 | 2012-06-09 10:53:16 +0000 | [diff] [blame] | 7730 | rtl_irq_enable_all(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7731 | } |
| 7732 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 7733 | static void rtl_task(struct work_struct *work) |
| 7734 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7735 | static const struct { |
| 7736 | int bitnr; |
| 7737 | void (*action)(struct rtl8169_private *); |
| 7738 | } rtl_work[] = { |
Francois Romieu | 934714d | 2012-01-31 11:09:21 +0100 | [diff] [blame] | 7739 | /* XXX - keep rtl_slow_event_work() as first element. */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7740 | { RTL_FLAG_TASK_SLOW_PENDING, rtl_slow_event_work }, |
| 7741 | { RTL_FLAG_TASK_RESET_PENDING, rtl_reset_work }, |
| 7742 | { RTL_FLAG_TASK_PHY_PENDING, rtl_phy_work } |
| 7743 | }; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 7744 | struct rtl8169_private *tp = |
| 7745 | container_of(work, struct rtl8169_private, wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7746 | struct net_device *dev = tp->dev; |
| 7747 | int i; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 7748 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7749 | rtl_lock_work(tp); |
| 7750 | |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7751 | if (!netif_running(dev) || |
| 7752 | !test_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7753 | goto out_unlock; |
| 7754 | |
| 7755 | for (i = 0; i < ARRAY_SIZE(rtl_work); i++) { |
| 7756 | bool pending; |
| 7757 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7758 | pending = test_and_clear_bit(rtl_work[i].bitnr, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7759 | if (pending) |
| 7760 | rtl_work[i].action(tp); |
| 7761 | } |
| 7762 | |
| 7763 | out_unlock: |
| 7764 | rtl_unlock_work(tp); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 7765 | } |
| 7766 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7767 | static int rtl8169_poll(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7768 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7769 | struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); |
| 7770 | struct net_device *dev = tp->dev; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7771 | u16 enable_mask = RTL_EVENT_NAPI | tp->event_slow; |
| 7772 | int work_done= 0; |
| 7773 | u16 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7774 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7775 | status = rtl_get_events(tp); |
| 7776 | rtl_ack_events(tp, status & ~tp->event_slow); |
| 7777 | |
| 7778 | if (status & RTL_EVENT_NAPI_RX) |
| 7779 | work_done = rtl_rx(dev, tp, (u32) budget); |
| 7780 | |
| 7781 | if (status & RTL_EVENT_NAPI_TX) |
| 7782 | rtl_tx(dev, tp); |
| 7783 | |
| 7784 | if (status & tp->event_slow) { |
| 7785 | enable_mask &= ~tp->event_slow; |
| 7786 | |
| 7787 | rtl_schedule_task(tp, RTL_FLAG_TASK_SLOW_PENDING); |
| 7788 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7789 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7790 | if (work_done < budget) { |
Eric Dumazet | 6ad2016 | 2017-01-30 08:22:01 -0800 | [diff] [blame] | 7791 | napi_complete_done(napi, work_done); |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 7792 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7793 | rtl_irq_enable(tp, enable_mask); |
| 7794 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7795 | } |
| 7796 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7797 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7798 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7799 | |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 7800 | static void rtl8169_rx_missed(struct net_device *dev, void __iomem *ioaddr) |
| 7801 | { |
| 7802 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7803 | |
| 7804 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) |
| 7805 | return; |
| 7806 | |
| 7807 | dev->stats.rx_missed_errors += (RTL_R32(RxMissed) & 0xffffff); |
| 7808 | RTL_W32(RxMissed, 0); |
| 7809 | } |
| 7810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7811 | static void rtl8169_down(struct net_device *dev) |
| 7812 | { |
| 7813 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7814 | void __iomem *ioaddr = tp->mmio_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7815 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 7816 | del_timer_sync(&tp->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7817 | |
Stephen Hemminger | 93dd79e | 2007-10-28 17:14:06 +0100 | [diff] [blame] | 7818 | napi_disable(&tp->napi); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7819 | netif_stop_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7820 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 7821 | rtl8169_hw_reset(tp); |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 7822 | /* |
| 7823 | * At this point device interrupts can not be enabled in any function, |
Francois Romieu | 209e5ac | 2012-01-26 09:59:50 +0100 | [diff] [blame] | 7824 | * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task) |
| 7825 | * and napi is disabled (rtl8169_poll). |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 7826 | */ |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 7827 | rtl8169_rx_missed(dev, ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7828 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7829 | /* Give a racing hard_start_xmit a few cycles to complete. */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7830 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7831 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7832 | rtl8169_tx_clear(tp); |
| 7833 | |
| 7834 | rtl8169_rx_clear(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7835 | |
| 7836 | rtl_pll_power_down(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7837 | } |
| 7838 | |
| 7839 | static int rtl8169_close(struct net_device *dev) |
| 7840 | { |
| 7841 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7842 | struct pci_dev *pdev = tp->pci_dev; |
| 7843 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7844 | pm_runtime_get_sync(&pdev->dev); |
| 7845 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7846 | /* Update counters before going down */ |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 7847 | rtl8169_update_counters(dev); |
| 7848 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7849 | rtl_lock_work(tp); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7850 | clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7851 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7852 | rtl8169_down(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7853 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7854 | |
Lekensteyn | 4ea7244 | 2013-07-22 09:53:30 +0200 | [diff] [blame] | 7855 | cancel_work_sync(&tp->wk.work); |
| 7856 | |
Francois Romieu | 92a7c4e | 2012-03-10 10:42:12 +0100 | [diff] [blame] | 7857 | free_irq(pdev->irq, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7858 | |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 7859 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 7860 | tp->RxPhyAddr); |
| 7861 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 7862 | tp->TxPhyAddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7863 | tp->TxDescArray = NULL; |
| 7864 | tp->RxDescArray = NULL; |
| 7865 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7866 | pm_runtime_put_sync(&pdev->dev); |
| 7867 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7868 | return 0; |
| 7869 | } |
| 7870 | |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 7871 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7872 | static void rtl8169_netpoll(struct net_device *dev) |
| 7873 | { |
| 7874 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7875 | |
| 7876 | rtl8169_interrupt(tp->pci_dev->irq, dev); |
| 7877 | } |
| 7878 | #endif |
| 7879 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7880 | static int rtl_open(struct net_device *dev) |
| 7881 | { |
| 7882 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7883 | void __iomem *ioaddr = tp->mmio_addr; |
| 7884 | struct pci_dev *pdev = tp->pci_dev; |
| 7885 | int retval = -ENOMEM; |
| 7886 | |
| 7887 | pm_runtime_get_sync(&pdev->dev); |
| 7888 | |
| 7889 | /* |
Jiri Kosina | e75d660 | 2012-04-08 21:48:52 +0200 | [diff] [blame] | 7890 | * Rx and Tx descriptors needs 256 bytes alignment. |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7891 | * dma_alloc_coherent provides more. |
| 7892 | */ |
| 7893 | tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES, |
| 7894 | &tp->TxPhyAddr, GFP_KERNEL); |
| 7895 | if (!tp->TxDescArray) |
| 7896 | goto err_pm_runtime_put; |
| 7897 | |
| 7898 | tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, |
| 7899 | &tp->RxPhyAddr, GFP_KERNEL); |
| 7900 | if (!tp->RxDescArray) |
| 7901 | goto err_free_tx_0; |
| 7902 | |
| 7903 | retval = rtl8169_init_ring(dev); |
| 7904 | if (retval < 0) |
| 7905 | goto err_free_rx_1; |
| 7906 | |
| 7907 | INIT_WORK(&tp->wk.work, rtl_task); |
| 7908 | |
| 7909 | smp_mb(); |
| 7910 | |
| 7911 | rtl_request_firmware(tp); |
| 7912 | |
Francois Romieu | 92a7c4e | 2012-03-10 10:42:12 +0100 | [diff] [blame] | 7913 | retval = request_irq(pdev->irq, rtl8169_interrupt, |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7914 | (tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED, |
| 7915 | dev->name, dev); |
| 7916 | if (retval < 0) |
| 7917 | goto err_release_fw_2; |
| 7918 | |
| 7919 | rtl_lock_work(tp); |
| 7920 | |
| 7921 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
| 7922 | |
| 7923 | napi_enable(&tp->napi); |
| 7924 | |
| 7925 | rtl8169_init_phy(dev, tp); |
| 7926 | |
| 7927 | __rtl8169_set_features(dev, dev->features); |
| 7928 | |
| 7929 | rtl_pll_power_up(tp); |
| 7930 | |
| 7931 | rtl_hw_start(dev); |
| 7932 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7933 | if (!rtl8169_init_counter_offsets(dev)) |
| 7934 | netif_warn(tp, hw, dev, "counter reset/update failed\n"); |
| 7935 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7936 | netif_start_queue(dev); |
| 7937 | |
| 7938 | rtl_unlock_work(tp); |
| 7939 | |
| 7940 | tp->saved_wolopts = 0; |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 7941 | pm_runtime_put_sync(&pdev->dev); |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7942 | |
| 7943 | rtl8169_check_link_status(dev, tp, ioaddr); |
| 7944 | out: |
| 7945 | return retval; |
| 7946 | |
| 7947 | err_release_fw_2: |
| 7948 | rtl_release_firmware(tp); |
| 7949 | rtl8169_rx_clear(tp); |
| 7950 | err_free_rx_1: |
| 7951 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 7952 | tp->RxPhyAddr); |
| 7953 | tp->RxDescArray = NULL; |
| 7954 | err_free_tx_0: |
| 7955 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 7956 | tp->TxPhyAddr); |
| 7957 | tp->TxDescArray = NULL; |
| 7958 | err_pm_runtime_put: |
| 7959 | pm_runtime_put_noidle(&pdev->dev); |
| 7960 | goto out; |
| 7961 | } |
| 7962 | |
stephen hemminger | bc1f447 | 2017-01-06 19:12:52 -0800 | [diff] [blame] | 7963 | static void |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7964 | rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7965 | { |
| 7966 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7967 | void __iomem *ioaddr = tp->mmio_addr; |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7968 | struct pci_dev *pdev = tp->pci_dev; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 7969 | struct rtl8169_counters *counters = tp->counters; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7970 | unsigned int start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7971 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 7972 | pm_runtime_get_noresume(&pdev->dev); |
| 7973 | |
| 7974 | if (netif_running(dev) && pm_runtime_active(&pdev->dev)) |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 7975 | rtl8169_rx_missed(dev, ioaddr); |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 7976 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7977 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7978 | start = u64_stats_fetch_begin_irq(&tp->rx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7979 | stats->rx_packets = tp->rx_stats.packets; |
| 7980 | stats->rx_bytes = tp->rx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7981 | } while (u64_stats_fetch_retry_irq(&tp->rx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7982 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7983 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7984 | start = u64_stats_fetch_begin_irq(&tp->tx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7985 | stats->tx_packets = tp->tx_stats.packets; |
| 7986 | stats->tx_bytes = tp->tx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7987 | } while (u64_stats_fetch_retry_irq(&tp->tx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7988 | |
| 7989 | stats->rx_dropped = dev->stats.rx_dropped; |
| 7990 | stats->tx_dropped = dev->stats.tx_dropped; |
| 7991 | stats->rx_length_errors = dev->stats.rx_length_errors; |
| 7992 | stats->rx_errors = dev->stats.rx_errors; |
| 7993 | stats->rx_crc_errors = dev->stats.rx_crc_errors; |
| 7994 | stats->rx_fifo_errors = dev->stats.rx_fifo_errors; |
| 7995 | stats->rx_missed_errors = dev->stats.rx_missed_errors; |
Corinna Vinschen | d7d2d89 | 2015-08-27 17:11:48 +0200 | [diff] [blame] | 7996 | stats->multicast = dev->stats.multicast; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7997 | |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 7998 | /* |
| 7999 | * Fetch additonal counter values missing in stats collected by driver |
| 8000 | * from tally counters. |
| 8001 | */ |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 8002 | if (pm_runtime_active(&pdev->dev)) |
| 8003 | rtl8169_update_counters(dev); |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 8004 | |
| 8005 | /* |
| 8006 | * Subtract values fetched during initalization. |
| 8007 | * See rtl8169_init_counter_offsets for a description why we do that. |
| 8008 | */ |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 8009 | stats->tx_errors = le64_to_cpu(counters->tx_errors) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 8010 | le64_to_cpu(tp->tc_offset.tx_errors); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 8011 | stats->collisions = le32_to_cpu(counters->tx_multi_collision) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 8012 | le32_to_cpu(tp->tc_offset.tx_multi_collision); |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 8013 | stats->tx_aborted_errors = le16_to_cpu(counters->tx_aborted) - |
Corinna Vinschen | 6e85d5a | 2015-08-24 12:52:39 +0200 | [diff] [blame] | 8014 | le16_to_cpu(tp->tc_offset.tx_aborted); |
| 8015 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 8016 | pm_runtime_put_noidle(&pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8017 | } |
| 8018 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 8019 | static void rtl8169_net_suspend(struct net_device *dev) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 8020 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 8021 | struct rtl8169_private *tp = netdev_priv(dev); |
| 8022 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 8023 | if (!netif_running(dev)) |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 8024 | return; |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 8025 | |
| 8026 | netif_device_detach(dev); |
| 8027 | netif_stop_queue(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 8028 | |
| 8029 | rtl_lock_work(tp); |
| 8030 | napi_disable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 8031 | clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 8032 | rtl_unlock_work(tp); |
| 8033 | |
| 8034 | rtl_pll_power_down(tp); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 8035 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 8036 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 8037 | #ifdef CONFIG_PM |
| 8038 | |
| 8039 | static int rtl8169_suspend(struct device *device) |
| 8040 | { |
| 8041 | struct pci_dev *pdev = to_pci_dev(device); |
| 8042 | struct net_device *dev = pci_get_drvdata(pdev); |
| 8043 | |
| 8044 | rtl8169_net_suspend(dev); |
Francois Romieu | 1371fa6 | 2007-04-02 23:01:11 +0200 | [diff] [blame] | 8045 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 8046 | return 0; |
| 8047 | } |
| 8048 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 8049 | static void __rtl8169_resume(struct net_device *dev) |
| 8050 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 8051 | struct rtl8169_private *tp = netdev_priv(dev); |
| 8052 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 8053 | netif_device_attach(dev); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 8054 | |
| 8055 | rtl_pll_power_up(tp); |
| 8056 | |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 8057 | rtl_lock_work(tp); |
| 8058 | napi_enable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 8059 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 8060 | rtl_unlock_work(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 8061 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 8062 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 8063 | } |
| 8064 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 8065 | static int rtl8169_resume(struct device *device) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 8066 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 8067 | struct pci_dev *pdev = to_pci_dev(device); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 8068 | struct net_device *dev = pci_get_drvdata(pdev); |
Stanislaw Gruszka | fccec10 | 2010-10-20 22:25:42 +0000 | [diff] [blame] | 8069 | struct rtl8169_private *tp = netdev_priv(dev); |
| 8070 | |
| 8071 | rtl8169_init_phy(dev, tp); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 8072 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 8073 | if (netif_running(dev)) |
| 8074 | __rtl8169_resume(dev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 8075 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 8076 | return 0; |
| 8077 | } |
| 8078 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 8079 | static int rtl8169_runtime_suspend(struct device *device) |
| 8080 | { |
| 8081 | struct pci_dev *pdev = to_pci_dev(device); |
| 8082 | struct net_device *dev = pci_get_drvdata(pdev); |
| 8083 | struct rtl8169_private *tp = netdev_priv(dev); |
| 8084 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 8085 | if (!tp->TxDescArray) { |
| 8086 | rtl_pll_power_down(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 8087 | return 0; |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 8088 | } |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 8089 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 8090 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 8091 | tp->saved_wolopts = __rtl8169_get_wol(tp); |
| 8092 | __rtl8169_set_wol(tp, WAKE_ANY); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 8093 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 8094 | |
| 8095 | rtl8169_net_suspend(dev); |
| 8096 | |
Chun-Hao Lin | f09cf4b | 2016-02-24 14:18:42 +0800 | [diff] [blame] | 8097 | /* Update counters before going runtime suspend */ |
| 8098 | rtl8169_rx_missed(dev, tp->mmio_addr); |
| 8099 | rtl8169_update_counters(dev); |
| 8100 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 8101 | return 0; |
| 8102 | } |
| 8103 | |
| 8104 | static int rtl8169_runtime_resume(struct device *device) |
| 8105 | { |
| 8106 | struct pci_dev *pdev = to_pci_dev(device); |
| 8107 | struct net_device *dev = pci_get_drvdata(pdev); |
| 8108 | struct rtl8169_private *tp = netdev_priv(dev); |
Chun-Hao Lin | f51d4a1 | 2016-07-29 16:37:56 +0800 | [diff] [blame] | 8109 | rtl_rar_set(tp, dev->dev_addr); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 8110 | |
| 8111 | if (!tp->TxDescArray) |
| 8112 | return 0; |
| 8113 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 8114 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 8115 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
| 8116 | tp->saved_wolopts = 0; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 8117 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 8118 | |
Stanislaw Gruszka | fccec10 | 2010-10-20 22:25:42 +0000 | [diff] [blame] | 8119 | rtl8169_init_phy(dev, tp); |
| 8120 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 8121 | __rtl8169_resume(dev); |
| 8122 | |
| 8123 | return 0; |
| 8124 | } |
| 8125 | |
| 8126 | static int rtl8169_runtime_idle(struct device *device) |
| 8127 | { |
| 8128 | struct pci_dev *pdev = to_pci_dev(device); |
| 8129 | struct net_device *dev = pci_get_drvdata(pdev); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 8130 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 8131 | if (!netif_running(dev) || !netif_carrier_ok(dev)) |
| 8132 | pm_schedule_suspend(device, 10000); |
| 8133 | |
| 8134 | return -EBUSY; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 8135 | } |
| 8136 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 8137 | static const struct dev_pm_ops rtl8169_pm_ops = { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 8138 | .suspend = rtl8169_suspend, |
| 8139 | .resume = rtl8169_resume, |
| 8140 | .freeze = rtl8169_suspend, |
| 8141 | .thaw = rtl8169_resume, |
| 8142 | .poweroff = rtl8169_suspend, |
| 8143 | .restore = rtl8169_resume, |
| 8144 | .runtime_suspend = rtl8169_runtime_suspend, |
| 8145 | .runtime_resume = rtl8169_runtime_resume, |
| 8146 | .runtime_idle = rtl8169_runtime_idle, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 8147 | }; |
| 8148 | |
| 8149 | #define RTL8169_PM_OPS (&rtl8169_pm_ops) |
| 8150 | |
| 8151 | #else /* !CONFIG_PM */ |
| 8152 | |
| 8153 | #define RTL8169_PM_OPS NULL |
| 8154 | |
| 8155 | #endif /* !CONFIG_PM */ |
| 8156 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 8157 | static void rtl_wol_shutdown_quirk(struct rtl8169_private *tp) |
| 8158 | { |
| 8159 | void __iomem *ioaddr = tp->mmio_addr; |
| 8160 | |
| 8161 | /* WoL fails with 8168b when the receiver is disabled. */ |
| 8162 | switch (tp->mac_version) { |
| 8163 | case RTL_GIGA_MAC_VER_11: |
| 8164 | case RTL_GIGA_MAC_VER_12: |
| 8165 | case RTL_GIGA_MAC_VER_17: |
| 8166 | pci_clear_master(tp->pci_dev); |
| 8167 | |
| 8168 | RTL_W8(ChipCmd, CmdRxEnb); |
| 8169 | /* PCI commit */ |
| 8170 | RTL_R8(ChipCmd); |
| 8171 | break; |
| 8172 | default: |
| 8173 | break; |
| 8174 | } |
| 8175 | } |
| 8176 | |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 8177 | static void rtl_shutdown(struct pci_dev *pdev) |
| 8178 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 8179 | struct net_device *dev = pci_get_drvdata(pdev); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 8180 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 8181 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 8182 | rtl8169_net_suspend(dev); |
| 8183 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 8184 | /* Restore original MAC address */ |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 8185 | rtl_rar_set(tp, dev->perm_addr); |
| 8186 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 8187 | rtl8169_hw_reset(tp); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 8188 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 8189 | if (system_state == SYSTEM_POWER_OFF) { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 8190 | if (__rtl8169_get_wol(tp) & WAKE_ANY) { |
| 8191 | rtl_wol_suspend_quirk(tp); |
| 8192 | rtl_wol_shutdown_quirk(tp); |
françois romieu | ca52efd | 2009-07-24 12:34:19 +0000 | [diff] [blame] | 8193 | } |
| 8194 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 8195 | pci_wake_from_d3(pdev, true); |
| 8196 | pci_set_power_state(pdev, PCI_D3hot); |
| 8197 | } |
| 8198 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 8199 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 8200 | static void rtl_remove_one(struct pci_dev *pdev) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 8201 | { |
| 8202 | struct net_device *dev = pci_get_drvdata(pdev); |
| 8203 | struct rtl8169_private *tp = netdev_priv(dev); |
| 8204 | |
Chun-Hao Lin | ee7a1be | 2014-10-01 23:17:21 +0800 | [diff] [blame] | 8205 | if ((tp->mac_version == RTL_GIGA_MAC_VER_27 || |
| 8206 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 8207 | tp->mac_version == RTL_GIGA_MAC_VER_31 || |
| 8208 | tp->mac_version == RTL_GIGA_MAC_VER_49 || |
| 8209 | tp->mac_version == RTL_GIGA_MAC_VER_50 || |
| 8210 | tp->mac_version == RTL_GIGA_MAC_VER_51) && |
Chun-Hao Lin | ee7a1be | 2014-10-01 23:17:21 +0800 | [diff] [blame] | 8211 | r8168_check_dash(tp)) { |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 8212 | rtl8168_driver_stop(tp); |
| 8213 | } |
| 8214 | |
Devendra Naga | ad1be8d | 2012-05-31 01:51:20 +0000 | [diff] [blame] | 8215 | netif_napi_del(&tp->napi); |
| 8216 | |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 8217 | unregister_netdev(dev); |
| 8218 | |
| 8219 | rtl_release_firmware(tp); |
| 8220 | |
| 8221 | if (pci_dev_run_wake(pdev)) |
| 8222 | pm_runtime_get_noresume(&pdev->dev); |
| 8223 | |
| 8224 | /* restore original MAC address */ |
| 8225 | rtl_rar_set(tp, dev->perm_addr); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 8226 | } |
| 8227 | |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 8228 | static const struct net_device_ops rtl_netdev_ops = { |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 8229 | .ndo_open = rtl_open, |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 8230 | .ndo_stop = rtl8169_close, |
| 8231 | .ndo_get_stats64 = rtl8169_get_stats64, |
| 8232 | .ndo_start_xmit = rtl8169_start_xmit, |
| 8233 | .ndo_tx_timeout = rtl8169_tx_timeout, |
| 8234 | .ndo_validate_addr = eth_validate_addr, |
| 8235 | .ndo_change_mtu = rtl8169_change_mtu, |
| 8236 | .ndo_fix_features = rtl8169_fix_features, |
| 8237 | .ndo_set_features = rtl8169_set_features, |
| 8238 | .ndo_set_mac_address = rtl_set_mac_address, |
| 8239 | .ndo_do_ioctl = rtl8169_ioctl, |
| 8240 | .ndo_set_rx_mode = rtl_set_rx_mode, |
| 8241 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 8242 | .ndo_poll_controller = rtl8169_netpoll, |
| 8243 | #endif |
| 8244 | |
| 8245 | }; |
| 8246 | |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8247 | static const struct rtl_cfg_info { |
| 8248 | void (*hw_start)(struct net_device *); |
| 8249 | unsigned int region; |
| 8250 | unsigned int align; |
| 8251 | u16 event_slow; |
| 8252 | unsigned features; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 8253 | const struct rtl_coalesce_info *coalesce_info; |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8254 | u8 default_ver; |
| 8255 | } rtl_cfg_infos [] = { |
| 8256 | [RTL_CFG_0] = { |
| 8257 | .hw_start = rtl_hw_start_8169, |
| 8258 | .region = 1, |
| 8259 | .align = 0, |
| 8260 | .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver, |
| 8261 | .features = RTL_FEATURE_GMII, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 8262 | .coalesce_info = rtl_coalesce_info_8169, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8263 | .default_ver = RTL_GIGA_MAC_VER_01, |
| 8264 | }, |
| 8265 | [RTL_CFG_1] = { |
| 8266 | .hw_start = rtl_hw_start_8168, |
| 8267 | .region = 2, |
| 8268 | .align = 8, |
| 8269 | .event_slow = SYSErr | LinkChg | RxOverflow, |
| 8270 | .features = RTL_FEATURE_GMII | RTL_FEATURE_MSI, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 8271 | .coalesce_info = rtl_coalesce_info_8168_8136, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8272 | .default_ver = RTL_GIGA_MAC_VER_11, |
| 8273 | }, |
| 8274 | [RTL_CFG_2] = { |
| 8275 | .hw_start = rtl_hw_start_8101, |
| 8276 | .region = 2, |
| 8277 | .align = 8, |
| 8278 | .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver | |
| 8279 | PCSTimeout, |
| 8280 | .features = RTL_FEATURE_MSI, |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 8281 | .coalesce_info = rtl_coalesce_info_8168_8136, |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 8282 | .default_ver = RTL_GIGA_MAC_VER_13, |
| 8283 | } |
| 8284 | }; |
| 8285 | |
| 8286 | /* Cfg9346_Unlock assumed. */ |
| 8287 | static unsigned rtl_try_msi(struct rtl8169_private *tp, |
| 8288 | const struct rtl_cfg_info *cfg) |
| 8289 | { |
| 8290 | void __iomem *ioaddr = tp->mmio_addr; |
| 8291 | unsigned msi = 0; |
| 8292 | u8 cfg2; |
| 8293 | |
| 8294 | cfg2 = RTL_R8(Config2) & ~MSIEnable; |
| 8295 | if (cfg->features & RTL_FEATURE_MSI) { |
| 8296 | if (pci_enable_msi(tp->pci_dev)) { |
| 8297 | netif_info(tp, hw, tp->dev, "no MSI. Back to INTx.\n"); |
| 8298 | } else { |
| 8299 | cfg2 |= MSIEnable; |
| 8300 | msi = RTL_FEATURE_MSI; |
| 8301 | } |
| 8302 | } |
| 8303 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
| 8304 | RTL_W8(Config2, cfg2); |
| 8305 | return msi; |
| 8306 | } |
| 8307 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8308 | DECLARE_RTL_COND(rtl_link_list_ready_cond) |
| 8309 | { |
| 8310 | void __iomem *ioaddr = tp->mmio_addr; |
| 8311 | |
| 8312 | return RTL_R8(MCU) & LINK_LIST_RDY; |
| 8313 | } |
| 8314 | |
| 8315 | DECLARE_RTL_COND(rtl_rxtx_empty_cond) |
| 8316 | { |
| 8317 | void __iomem *ioaddr = tp->mmio_addr; |
| 8318 | |
| 8319 | return (RTL_R8(MCU) & RXTX_EMPTY) == RXTX_EMPTY; |
| 8320 | } |
| 8321 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 8322 | static void rtl_hw_init_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8323 | { |
| 8324 | void __iomem *ioaddr = tp->mmio_addr; |
| 8325 | u32 data; |
| 8326 | |
| 8327 | tp->ocp_base = OCP_STD_PHY_BASE; |
| 8328 | |
| 8329 | RTL_W32(MISC, RTL_R32(MISC) | RXDV_GATED_EN); |
| 8330 | |
| 8331 | if (!rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 42)) |
| 8332 | return; |
| 8333 | |
| 8334 | if (!rtl_udelay_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42)) |
| 8335 | return; |
| 8336 | |
| 8337 | RTL_W8(ChipCmd, RTL_R8(ChipCmd) & ~(CmdTxEnb | CmdRxEnb)); |
| 8338 | msleep(1); |
| 8339 | RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB); |
| 8340 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 8341 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8342 | data &= ~(1 << 14); |
| 8343 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 8344 | |
| 8345 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 8346 | return; |
| 8347 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 8348 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8349 | data |= (1 << 15); |
| 8350 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 8351 | |
| 8352 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 8353 | return; |
| 8354 | } |
| 8355 | |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 8356 | static void rtl_hw_init_8168ep(struct rtl8169_private *tp) |
| 8357 | { |
| 8358 | rtl8168ep_stop_cmac(tp); |
| 8359 | rtl_hw_init_8168g(tp); |
| 8360 | } |
| 8361 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 8362 | static void rtl_hw_initialize(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8363 | { |
| 8364 | switch (tp->mac_version) { |
| 8365 | case RTL_GIGA_MAC_VER_40: |
| 8366 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 8367 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 8368 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 8369 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 8370 | case RTL_GIGA_MAC_VER_45: |
| 8371 | case RTL_GIGA_MAC_VER_46: |
| 8372 | case RTL_GIGA_MAC_VER_47: |
| 8373 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 8374 | rtl_hw_init_8168g(tp); |
| 8375 | break; |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 8376 | case RTL_GIGA_MAC_VER_49: |
| 8377 | case RTL_GIGA_MAC_VER_50: |
| 8378 | case RTL_GIGA_MAC_VER_51: |
Chun-Hao Lin | 003609d | 2014-12-02 16:48:31 +0800 | [diff] [blame] | 8379 | rtl_hw_init_8168ep(tp); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8380 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8381 | default: |
| 8382 | break; |
| 8383 | } |
| 8384 | } |
| 8385 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 8386 | 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] | 8387 | { |
| 8388 | const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data; |
| 8389 | const unsigned int region = cfg->region; |
| 8390 | struct rtl8169_private *tp; |
| 8391 | struct mii_if_info *mii; |
| 8392 | struct net_device *dev; |
| 8393 | void __iomem *ioaddr; |
| 8394 | int chipset, i; |
| 8395 | int rc; |
| 8396 | |
| 8397 | if (netif_msg_drv(&debug)) { |
| 8398 | printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n", |
| 8399 | MODULENAME, RTL8169_VERSION); |
| 8400 | } |
| 8401 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8402 | dev = devm_alloc_etherdev(&pdev->dev, sizeof (*tp)); |
| 8403 | if (!dev) |
| 8404 | return -ENOMEM; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8405 | |
| 8406 | SET_NETDEV_DEV(dev, &pdev->dev); |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 8407 | dev->netdev_ops = &rtl_netdev_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8408 | tp = netdev_priv(dev); |
| 8409 | tp->dev = dev; |
| 8410 | tp->pci_dev = pdev; |
| 8411 | tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT); |
| 8412 | |
| 8413 | mii = &tp->mii; |
| 8414 | mii->dev = dev; |
| 8415 | mii->mdio_read = rtl_mdio_read; |
| 8416 | mii->mdio_write = rtl_mdio_write; |
| 8417 | mii->phy_id_mask = 0x1f; |
| 8418 | mii->reg_num_mask = 0x1f; |
| 8419 | mii->supports_gmii = !!(cfg->features & RTL_FEATURE_GMII); |
| 8420 | |
| 8421 | /* disable ASPM completely as that cause random device stop working |
| 8422 | * problems as well as full system hangs for some PCIe devices users */ |
| 8423 | pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 | |
| 8424 | PCIE_LINK_STATE_CLKPM); |
| 8425 | |
| 8426 | /* enable device (incl. PCI PM wakeup and hotplug setup) */ |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8427 | rc = pcim_enable_device(pdev); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8428 | if (rc < 0) { |
| 8429 | netif_err(tp, probe, dev, "enable failure\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8430 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8431 | } |
| 8432 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8433 | if (pcim_set_mwi(pdev) < 0) |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8434 | netif_info(tp, probe, dev, "Mem-Wr-Inval unavailable\n"); |
| 8435 | |
| 8436 | /* make sure PCI base addr 1 is MMIO */ |
| 8437 | if (!(pci_resource_flags(pdev, region) & IORESOURCE_MEM)) { |
| 8438 | netif_err(tp, probe, dev, |
| 8439 | "region #%d not an MMIO resource, aborting\n", |
| 8440 | region); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8441 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8442 | } |
| 8443 | |
| 8444 | /* check for weird/broken PCI region reporting */ |
| 8445 | if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) { |
| 8446 | netif_err(tp, probe, dev, |
| 8447 | "Invalid PCI region size(s), aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8448 | return -ENODEV; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8449 | } |
| 8450 | |
| 8451 | rc = pci_request_regions(pdev, MODULENAME); |
| 8452 | if (rc < 0) { |
| 8453 | netif_err(tp, probe, dev, "could not request regions\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8454 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8455 | } |
| 8456 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8457 | /* ioremap MMIO region */ |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8458 | ioaddr = devm_ioremap(&pdev->dev, pci_resource_start(pdev, region), |
| 8459 | R8169_REGS_SIZE); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8460 | if (!ioaddr) { |
| 8461 | netif_err(tp, probe, dev, "cannot remap MMIO, aborting\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8462 | return -EIO; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8463 | } |
| 8464 | tp->mmio_addr = ioaddr; |
| 8465 | |
| 8466 | if (!pci_is_pcie(pdev)) |
| 8467 | netif_info(tp, probe, dev, "not PCI Express\n"); |
| 8468 | |
| 8469 | /* Identify chip attached to board */ |
| 8470 | rtl8169_get_mac_version(tp, dev, cfg->default_ver); |
| 8471 | |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 8472 | tp->cp_cmd = 0; |
| 8473 | |
| 8474 | if ((sizeof(dma_addr_t) > 4) && |
| 8475 | (use_dac == 1 || (use_dac == -1 && pci_is_pcie(pdev) && |
| 8476 | tp->mac_version >= RTL_GIGA_MAC_VER_18)) && |
Ard Biesheuvel | f007643 | 2016-10-14 14:40:33 +0100 | [diff] [blame] | 8477 | !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
| 8478 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 8479 | |
| 8480 | /* CPlusCmd Dual Access Cycle is only needed for non-PCIe */ |
| 8481 | if (!pci_is_pcie(pdev)) |
| 8482 | tp->cp_cmd |= PCIDAC; |
| 8483 | dev->features |= NETIF_F_HIGHDMA; |
| 8484 | } else { |
| 8485 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 8486 | if (rc < 0) { |
| 8487 | netif_err(tp, probe, dev, "DMA configuration failed\n"); |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8488 | return rc; |
Ard Biesheuvel | 27896c8 | 2016-05-14 22:40:15 +0200 | [diff] [blame] | 8489 | } |
| 8490 | } |
| 8491 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8492 | rtl_init_rxcfg(tp); |
| 8493 | |
| 8494 | rtl_irq_disable(tp); |
| 8495 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 8496 | rtl_hw_initialize(tp); |
| 8497 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8498 | rtl_hw_reset(tp); |
| 8499 | |
| 8500 | rtl_ack_events(tp, 0xffff); |
| 8501 | |
| 8502 | pci_set_master(pdev); |
| 8503 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8504 | rtl_init_mdio_ops(tp); |
| 8505 | rtl_init_pll_power_ops(tp); |
| 8506 | rtl_init_jumbo_ops(tp); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 8507 | rtl_init_csi_ops(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8508 | |
| 8509 | rtl8169_print_mac_version(tp); |
| 8510 | |
| 8511 | chipset = tp->mac_version; |
| 8512 | tp->txd_version = rtl_chip_infos[chipset].txd_version; |
| 8513 | |
| 8514 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8515 | tp->features |= rtl_try_msi(tp, cfg); |
| 8516 | RTL_W8(Cfg9346, Cfg9346_Lock); |
| 8517 | |
Heiner Kallweit | 7edf6d3 | 2018-02-22 21:22:40 +0100 | [diff] [blame^] | 8518 | /* override BIOS settings, use userspace tools to enable WOL */ |
| 8519 | __rtl8169_set_wol(tp, 0); |
| 8520 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8521 | if (rtl_tbi_enabled(tp)) { |
| 8522 | tp->set_speed = rtl8169_set_speed_tbi; |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 8523 | tp->get_link_ksettings = rtl8169_get_link_ksettings_tbi; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8524 | tp->phy_reset_enable = rtl8169_tbi_reset_enable; |
| 8525 | tp->phy_reset_pending = rtl8169_tbi_reset_pending; |
| 8526 | tp->link_ok = rtl8169_tbi_link_ok; |
| 8527 | tp->do_ioctl = rtl_tbi_ioctl; |
| 8528 | } else { |
| 8529 | tp->set_speed = rtl8169_set_speed_xmii; |
Philippe Reynes | 6fa1ba6 | 2017-02-23 22:34:43 +0100 | [diff] [blame] | 8530 | tp->get_link_ksettings = rtl8169_get_link_ksettings_xmii; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8531 | tp->phy_reset_enable = rtl8169_xmii_reset_enable; |
| 8532 | tp->phy_reset_pending = rtl8169_xmii_reset_pending; |
| 8533 | tp->link_ok = rtl8169_xmii_link_ok; |
| 8534 | tp->do_ioctl = rtl_xmii_ioctl; |
| 8535 | } |
| 8536 | |
| 8537 | mutex_init(&tp->wk.mutex); |
Kyle McMartin | 340fea3 | 2014-02-24 20:12:28 -0500 | [diff] [blame] | 8538 | u64_stats_init(&tp->rx_stats.syncp); |
| 8539 | u64_stats_init(&tp->tx_stats.syncp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8540 | |
| 8541 | /* Get MAC address */ |
Chun-Hao Lin | 89cceb2 | 2014-10-01 23:17:15 +0800 | [diff] [blame] | 8542 | if (tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 8543 | tp->mac_version == RTL_GIGA_MAC_VER_36 || |
| 8544 | tp->mac_version == RTL_GIGA_MAC_VER_37 || |
| 8545 | tp->mac_version == RTL_GIGA_MAC_VER_38 || |
| 8546 | tp->mac_version == RTL_GIGA_MAC_VER_40 || |
| 8547 | tp->mac_version == RTL_GIGA_MAC_VER_41 || |
| 8548 | tp->mac_version == RTL_GIGA_MAC_VER_42 || |
| 8549 | tp->mac_version == RTL_GIGA_MAC_VER_43 || |
| 8550 | tp->mac_version == RTL_GIGA_MAC_VER_44 || |
| 8551 | tp->mac_version == RTL_GIGA_MAC_VER_45 || |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 8552 | tp->mac_version == RTL_GIGA_MAC_VER_46 || |
| 8553 | tp->mac_version == RTL_GIGA_MAC_VER_47 || |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 8554 | tp->mac_version == RTL_GIGA_MAC_VER_48 || |
| 8555 | tp->mac_version == RTL_GIGA_MAC_VER_49 || |
| 8556 | tp->mac_version == RTL_GIGA_MAC_VER_50 || |
| 8557 | tp->mac_version == RTL_GIGA_MAC_VER_51) { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 8558 | u16 mac_addr[3]; |
| 8559 | |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 8560 | *(u32 *)&mac_addr[0] = rtl_eri_read(tp, 0xe0, ERIAR_EXGMAC); |
| 8561 | *(u16 *)&mac_addr[2] = rtl_eri_read(tp, 0xe4, ERIAR_EXGMAC); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 8562 | |
| 8563 | if (is_valid_ether_addr((u8 *)mac_addr)) |
| 8564 | rtl_rar_set(tp, (u8 *)mac_addr); |
| 8565 | } |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8566 | for (i = 0; i < ETH_ALEN; i++) |
| 8567 | dev->dev_addr[i] = RTL_R8(MAC0 + i); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8568 | |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 8569 | dev->ethtool_ops = &rtl8169_ethtool_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8570 | dev->watchdog_timeo = RTL8169_TX_TIMEOUT; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8571 | |
| 8572 | netif_napi_add(dev, &tp->napi, rtl8169_poll, R8169_NAPI_WEIGHT); |
| 8573 | |
| 8574 | /* don't enable SG, IP_CSUM and TSO by default - it might not work |
| 8575 | * properly for all devices */ |
| 8576 | dev->features |= NETIF_F_RXCSUM | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 8577 | NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8578 | |
| 8579 | 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] | 8580 | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_TX | |
| 8581 | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8582 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 8583 | NETIF_F_HIGHDMA; |
| 8584 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 8585 | tp->cp_cmd |= RxChkSum | RxVlan; |
| 8586 | |
| 8587 | /* |
| 8588 | * Pretend we are using VLANs; This bypasses a nasty bug where |
| 8589 | * Interrupts stop flowing on high load on 8110SCd controllers. |
| 8590 | */ |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8591 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 8592 | /* Disallow toggling */ |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 8593 | dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8594 | |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 8595 | if (tp->txd_version == RTL_TD_0) |
| 8596 | tp->tso_csum = rtl8169_tso_csum_v1; |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 8597 | else if (tp->txd_version == RTL_TD_1) { |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 8598 | tp->tso_csum = rtl8169_tso_csum_v2; |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 8599 | dev->hw_features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6; |
| 8600 | } else |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 8601 | WARN_ON_ONCE(1); |
| 8602 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8603 | dev->hw_features |= NETIF_F_RXALL; |
| 8604 | dev->hw_features |= NETIF_F_RXFCS; |
| 8605 | |
Jarod Wilson | c7315a9 | 2016-10-17 15:54:09 -0400 | [diff] [blame] | 8606 | /* MTU range: 60 - hw-specific max */ |
| 8607 | dev->min_mtu = ETH_ZLEN; |
| 8608 | dev->max_mtu = rtl_chip_infos[chipset].jumbo_max; |
| 8609 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8610 | tp->hw_start = cfg->hw_start; |
| 8611 | tp->event_slow = cfg->event_slow; |
Francois Romieu | 5097083 | 2017-10-27 13:24:49 +0300 | [diff] [blame] | 8612 | tp->coalesce_info = cfg->coalesce_info; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8613 | |
| 8614 | tp->opts1_mask = (tp->mac_version != RTL_GIGA_MAC_VER_01) ? |
| 8615 | ~(RxBOVF | RxFOVF) : ~0; |
| 8616 | |
Kees Cook | 9de36cc | 2017-10-25 03:53:12 -0700 | [diff] [blame] | 8617 | timer_setup(&tp->timer, rtl8169_phy_timer, 0); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8618 | |
| 8619 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
| 8620 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8621 | tp->counters = dmam_alloc_coherent (&pdev->dev, sizeof(*tp->counters), |
| 8622 | &tp->counters_phys_addr, |
| 8623 | GFP_KERNEL); |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 8624 | if (!tp->counters) |
| 8625 | return -ENOMEM; |
Corinna Vinschen | 4202032 | 2015-09-10 10:47:35 +0200 | [diff] [blame] | 8626 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8627 | rc = register_netdev(dev); |
| 8628 | if (rc < 0) |
Heiner Kallweit | 4cf964a | 2017-12-12 07:41:06 +0100 | [diff] [blame] | 8629 | return rc; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8630 | |
| 8631 | pci_set_drvdata(pdev, dev); |
| 8632 | |
Francois Romieu | 92a7c4e | 2012-03-10 10:42:12 +0100 | [diff] [blame] | 8633 | netif_info(tp, probe, dev, "%s at 0x%p, %pM, XID %08x IRQ %d\n", |
| 8634 | rtl_chip_infos[chipset].name, ioaddr, dev->dev_addr, |
| 8635 | (u32)(RTL_R32(TxConfig) & 0x9cf0f8ff), pdev->irq); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8636 | if (rtl_chip_infos[chipset].jumbo_max != JUMBO_1K) { |
| 8637 | netif_info(tp, probe, dev, "jumbo features [frames: %d bytes, " |
| 8638 | "tx checksumming: %s]\n", |
| 8639 | rtl_chip_infos[chipset].jumbo_max, |
| 8640 | rtl_chip_infos[chipset].jumbo_tx_csum ? "ok" : "ko"); |
| 8641 | } |
| 8642 | |
Chun-Hao Lin | ee7a1be | 2014-10-01 23:17:21 +0800 | [diff] [blame] | 8643 | if ((tp->mac_version == RTL_GIGA_MAC_VER_27 || |
| 8644 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
Chun-Hao Lin | 935e221 | 2014-10-07 15:10:41 +0800 | [diff] [blame] | 8645 | tp->mac_version == RTL_GIGA_MAC_VER_31 || |
| 8646 | tp->mac_version == RTL_GIGA_MAC_VER_49 || |
| 8647 | tp->mac_version == RTL_GIGA_MAC_VER_50 || |
| 8648 | tp->mac_version == RTL_GIGA_MAC_VER_51) && |
Chun-Hao Lin | ee7a1be | 2014-10-01 23:17:21 +0800 | [diff] [blame] | 8649 | r8168_check_dash(tp)) { |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8650 | rtl8168_driver_start(tp); |
| 8651 | } |
| 8652 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8653 | netif_carrier_off(dev); |
| 8654 | |
Heiner Kallweit | a92a084 | 2018-01-08 21:39:13 +0100 | [diff] [blame] | 8655 | if (pci_dev_run_wake(pdev)) |
| 8656 | pm_runtime_put_sync(&pdev->dev); |
| 8657 | |
Heiner Kallweit | 4c45d24 | 2017-12-12 07:41:02 +0100 | [diff] [blame] | 8658 | return 0; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8659 | } |
| 8660 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8661 | static struct pci_driver rtl8169_pci_driver = { |
| 8662 | .name = MODULENAME, |
| 8663 | .id_table = rtl8169_pci_tbl, |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 8664 | .probe = rtl_init_one, |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 8665 | .remove = rtl_remove_one, |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 8666 | .shutdown = rtl_shutdown, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 8667 | .driver.pm = RTL8169_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8668 | }; |
| 8669 | |
Devendra Naga | 3eeb7da | 2012-10-26 09:27:42 +0000 | [diff] [blame] | 8670 | module_pci_driver(rtl8169_pci_driver); |