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, |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 158 | RTL_GIGA_MAC_NONE = 0xff, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | }; |
| 160 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 161 | enum rtl_tx_desc_version { |
| 162 | RTL_TD_0 = 0, |
| 163 | RTL_TD_1 = 1, |
| 164 | }; |
| 165 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 166 | #define JUMBO_1K ETH_DATA_LEN |
| 167 | #define JUMBO_4K (4*1024 - ETH_HLEN - 2) |
| 168 | #define JUMBO_6K (6*1024 - ETH_HLEN - 2) |
| 169 | #define JUMBO_7K (7*1024 - ETH_HLEN - 2) |
| 170 | #define JUMBO_9K (9*1024 - ETH_HLEN - 2) |
| 171 | |
| 172 | #define _R(NAME,TD,FW,SZ,B) { \ |
| 173 | .name = NAME, \ |
| 174 | .txd_version = TD, \ |
| 175 | .fw_name = FW, \ |
| 176 | .jumbo_max = SZ, \ |
| 177 | .jumbo_tx_csum = B \ |
| 178 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
Jesper Juhl | 3c6bee1 | 2006-01-09 20:54:01 -0800 | [diff] [blame] | 180 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | const char *name; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 182 | enum rtl_tx_desc_version txd_version; |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 183 | const char *fw_name; |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 184 | u16 jumbo_max; |
| 185 | bool jumbo_tx_csum; |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 186 | } rtl_chip_infos[] = { |
| 187 | /* PCI devices. */ |
| 188 | [RTL_GIGA_MAC_VER_01] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 189 | _R("RTL8169", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 190 | [RTL_GIGA_MAC_VER_02] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 191 | _R("RTL8169s", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 192 | [RTL_GIGA_MAC_VER_03] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 193 | _R("RTL8110s", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 194 | [RTL_GIGA_MAC_VER_04] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 195 | _R("RTL8169sb/8110sb", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 196 | [RTL_GIGA_MAC_VER_05] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 197 | _R("RTL8169sc/8110sc", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 198 | [RTL_GIGA_MAC_VER_06] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 199 | _R("RTL8169sc/8110sc", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 200 | /* PCI-E devices. */ |
| 201 | [RTL_GIGA_MAC_VER_07] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 202 | _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 203 | [RTL_GIGA_MAC_VER_08] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 204 | _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 205 | [RTL_GIGA_MAC_VER_09] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 206 | _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 207 | [RTL_GIGA_MAC_VER_10] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 208 | _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 209 | [RTL_GIGA_MAC_VER_11] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 210 | _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 211 | [RTL_GIGA_MAC_VER_12] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 212 | _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 213 | [RTL_GIGA_MAC_VER_13] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 214 | _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 215 | [RTL_GIGA_MAC_VER_14] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 216 | _R("RTL8100e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 217 | [RTL_GIGA_MAC_VER_15] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 218 | _R("RTL8100e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 219 | [RTL_GIGA_MAC_VER_16] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 220 | _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 221 | [RTL_GIGA_MAC_VER_17] = |
hayeswang | f75761b | 2014-03-11 15:11:59 +0800 | [diff] [blame] | 222 | _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 223 | [RTL_GIGA_MAC_VER_18] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 224 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 225 | [RTL_GIGA_MAC_VER_19] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 226 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 227 | [RTL_GIGA_MAC_VER_20] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 228 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 229 | [RTL_GIGA_MAC_VER_21] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 230 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 231 | [RTL_GIGA_MAC_VER_22] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 232 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 233 | [RTL_GIGA_MAC_VER_23] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 234 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 235 | [RTL_GIGA_MAC_VER_24] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 236 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 237 | [RTL_GIGA_MAC_VER_25] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 238 | _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_1, |
| 239 | JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 240 | [RTL_GIGA_MAC_VER_26] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 241 | _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_2, |
| 242 | JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 243 | [RTL_GIGA_MAC_VER_27] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 244 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 245 | [RTL_GIGA_MAC_VER_28] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 246 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 247 | [RTL_GIGA_MAC_VER_29] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 248 | _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1, |
| 249 | JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 250 | [RTL_GIGA_MAC_VER_30] = |
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_31] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 254 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 255 | [RTL_GIGA_MAC_VER_32] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 256 | _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_1, |
| 257 | JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 258 | [RTL_GIGA_MAC_VER_33] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 259 | _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_2, |
| 260 | JUMBO_9K, false), |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 261 | [RTL_GIGA_MAC_VER_34] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 262 | _R("RTL8168evl/8111evl",RTL_TD_1, FIRMWARE_8168E_3, |
| 263 | JUMBO_9K, false), |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 264 | [RTL_GIGA_MAC_VER_35] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 265 | _R("RTL8168f/8111f", RTL_TD_1, FIRMWARE_8168F_1, |
| 266 | JUMBO_9K, false), |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 267 | [RTL_GIGA_MAC_VER_36] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 268 | _R("RTL8168f/8111f", RTL_TD_1, FIRMWARE_8168F_2, |
| 269 | JUMBO_9K, false), |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 270 | [RTL_GIGA_MAC_VER_37] = |
| 271 | _R("RTL8402", RTL_TD_1, FIRMWARE_8402_1, |
| 272 | JUMBO_1K, true), |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 273 | [RTL_GIGA_MAC_VER_38] = |
| 274 | _R("RTL8411", RTL_TD_1, FIRMWARE_8411_1, |
| 275 | JUMBO_9K, false), |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 276 | [RTL_GIGA_MAC_VER_39] = |
| 277 | _R("RTL8106e", RTL_TD_1, FIRMWARE_8106E_1, |
| 278 | JUMBO_1K, true), |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 279 | [RTL_GIGA_MAC_VER_40] = |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 280 | _R("RTL8168g/8111g", RTL_TD_1, FIRMWARE_8168G_2, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 281 | JUMBO_9K, false), |
| 282 | [RTL_GIGA_MAC_VER_41] = |
| 283 | _R("RTL8168g/8111g", RTL_TD_1, NULL, JUMBO_9K, false), |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 284 | [RTL_GIGA_MAC_VER_42] = |
| 285 | _R("RTL8168g/8111g", RTL_TD_1, FIRMWARE_8168G_3, |
| 286 | JUMBO_9K, false), |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 287 | [RTL_GIGA_MAC_VER_43] = |
| 288 | _R("RTL8106e", RTL_TD_1, FIRMWARE_8106E_2, |
| 289 | JUMBO_1K, true), |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 290 | [RTL_GIGA_MAC_VER_44] = |
| 291 | _R("RTL8411", RTL_TD_1, FIRMWARE_8411_2, |
| 292 | JUMBO_9K, false), |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 293 | [RTL_GIGA_MAC_VER_45] = |
| 294 | _R("RTL8168h/8111h", RTL_TD_1, FIRMWARE_8168H_1, |
| 295 | JUMBO_9K, false), |
| 296 | [RTL_GIGA_MAC_VER_46] = |
| 297 | _R("RTL8168h/8111h", RTL_TD_1, FIRMWARE_8168H_2, |
| 298 | JUMBO_9K, false), |
| 299 | [RTL_GIGA_MAC_VER_47] = |
| 300 | _R("RTL8107e", RTL_TD_1, FIRMWARE_8107E_1, |
| 301 | JUMBO_1K, false), |
| 302 | [RTL_GIGA_MAC_VER_48] = |
| 303 | _R("RTL8107e", RTL_TD_1, FIRMWARE_8107E_2, |
| 304 | JUMBO_1K, false), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | }; |
| 306 | #undef _R |
| 307 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 308 | enum cfg_version { |
| 309 | RTL_CFG_0 = 0x00, |
| 310 | RTL_CFG_1, |
| 311 | RTL_CFG_2 |
| 312 | }; |
| 313 | |
Benoit Taine | 9baa3c3 | 2014-08-08 15:56:03 +0200 | [diff] [blame] | 314 | static const struct pci_device_id rtl8169_pci_tbl[] = { |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 315 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 }, |
Francois Romieu | d2eed8c | 2006-08-31 22:01:07 +0200 | [diff] [blame] | 316 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8136), 0, 0, RTL_CFG_2 }, |
Francois Romieu | d81bf55 | 2006-09-20 21:31:20 +0200 | [diff] [blame] | 317 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_0 }, |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 318 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_1 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 319 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 }, |
Francois Romieu | 2a35cfa | 2012-08-31 23:06:17 +0200 | [diff] [blame] | 320 | { PCI_VENDOR_ID_DLINK, 0x4300, |
| 321 | PCI_VENDOR_ID_DLINK, 0x4b10, 0, 0, RTL_CFG_1 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 322 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4300), 0, 0, RTL_CFG_0 }, |
Lennart Sorensen | 93a3aa2 | 2011-07-28 13:18:11 +0000 | [diff] [blame] | 323 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4302), 0, 0, RTL_CFG_0 }, |
Francois Romieu | bc1660b | 2007-10-12 23:58:09 +0200 | [diff] [blame] | 324 | { PCI_DEVICE(PCI_VENDOR_ID_AT, 0xc107), 0, 0, RTL_CFG_0 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 325 | { PCI_DEVICE(0x16ec, 0x0116), 0, 0, RTL_CFG_0 }, |
| 326 | { PCI_VENDOR_ID_LINKSYS, 0x1032, |
| 327 | PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 }, |
Ciaran McCreesh | 11d2e28 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 328 | { 0x0001, 0x8168, |
| 329 | PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | {0,}, |
| 331 | }; |
| 332 | |
| 333 | MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl); |
| 334 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 335 | static int rx_buf_sz = 16383; |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 336 | static int use_dac; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 337 | static struct { |
| 338 | u32 msg_enable; |
| 339 | } debug = { -1 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 341 | enum rtl_registers { |
| 342 | MAC0 = 0, /* Ethernet hardware address. */ |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 343 | MAC4 = 4, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 344 | MAR0 = 8, /* Multicast filter. */ |
| 345 | CounterAddrLow = 0x10, |
| 346 | CounterAddrHigh = 0x14, |
| 347 | TxDescStartAddrLow = 0x20, |
| 348 | TxDescStartAddrHigh = 0x24, |
| 349 | TxHDescStartAddrLow = 0x28, |
| 350 | TxHDescStartAddrHigh = 0x2c, |
| 351 | FLASH = 0x30, |
| 352 | ERSR = 0x36, |
| 353 | ChipCmd = 0x37, |
| 354 | TxPoll = 0x38, |
| 355 | IntrMask = 0x3c, |
| 356 | IntrStatus = 0x3e, |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 357 | |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 358 | TxConfig = 0x40, |
| 359 | #define TXCFG_AUTO_FIFO (1 << 7) /* 8111e-vl */ |
| 360 | #define TXCFG_EMPTY (1 << 11) /* 8111e-vl */ |
| 361 | |
| 362 | RxConfig = 0x44, |
| 363 | #define RX128_INT_EN (1 << 15) /* 8111c and later */ |
| 364 | #define RX_MULTI_EN (1 << 14) /* 8111c only */ |
| 365 | #define RXCFG_FIFO_SHIFT 13 |
| 366 | /* No threshold before first PCI xfer */ |
| 367 | #define RX_FIFO_THRESH (7 << RXCFG_FIFO_SHIFT) |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 368 | #define RX_EARLY_OFF (1 << 11) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 369 | #define RXCFG_DMA_SHIFT 8 |
| 370 | /* Unlimited maximum PCI burst. */ |
| 371 | #define RX_DMA_BURST (7 << RXCFG_DMA_SHIFT) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 372 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 373 | RxMissed = 0x4c, |
| 374 | Cfg9346 = 0x50, |
| 375 | Config0 = 0x51, |
| 376 | Config1 = 0x52, |
| 377 | Config2 = 0x53, |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 378 | #define PME_SIGNAL (1 << 5) /* 8168c and later */ |
| 379 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 380 | Config3 = 0x54, |
| 381 | Config4 = 0x55, |
| 382 | Config5 = 0x56, |
| 383 | MultiIntr = 0x5c, |
| 384 | PHYAR = 0x60, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 385 | PHYstatus = 0x6c, |
| 386 | RxMaxSize = 0xda, |
| 387 | CPlusCmd = 0xe0, |
| 388 | IntrMitigate = 0xe2, |
| 389 | RxDescAddrLow = 0xe4, |
| 390 | RxDescAddrHigh = 0xe8, |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 391 | EarlyTxThres = 0xec, /* 8169. Unit of 32 bytes. */ |
| 392 | |
| 393 | #define NoEarlyTx 0x3f /* Max value : no early transmit. */ |
| 394 | |
| 395 | MaxTxPacketSize = 0xec, /* 8101/8168. Unit of 128 bytes. */ |
| 396 | |
| 397 | #define TxPacketMax (8064 >> 7) |
Hayes Wang | 3090bd9 | 2011-09-06 16:55:15 +0800 | [diff] [blame] | 398 | #define EarlySize 0x27 |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 399 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 400 | FuncEvent = 0xf0, |
| 401 | FuncEventMask = 0xf4, |
| 402 | FuncPresetState = 0xf8, |
| 403 | FuncForceEvent = 0xfc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 404 | }; |
| 405 | |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 406 | enum rtl8110_registers { |
| 407 | TBICSR = 0x64, |
| 408 | TBI_ANAR = 0x68, |
| 409 | TBI_LPAR = 0x6a, |
| 410 | }; |
| 411 | |
| 412 | enum rtl8168_8101_registers { |
| 413 | CSIDR = 0x64, |
| 414 | CSIAR = 0x68, |
| 415 | #define CSIAR_FLAG 0x80000000 |
| 416 | #define CSIAR_WRITE_CMD 0x80000000 |
| 417 | #define CSIAR_BYTE_ENABLE 0x0f |
| 418 | #define CSIAR_BYTE_ENABLE_SHIFT 12 |
| 419 | #define CSIAR_ADDR_MASK 0x0fff |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 420 | #define CSIAR_FUNC_CARD 0x00000000 |
| 421 | #define CSIAR_FUNC_SDIO 0x00010000 |
| 422 | #define CSIAR_FUNC_NIC 0x00020000 |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 423 | #define CSIAR_FUNC_NIC2 0x00010000 |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 424 | PMCH = 0x6f, |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 425 | EPHYAR = 0x80, |
| 426 | #define EPHYAR_FLAG 0x80000000 |
| 427 | #define EPHYAR_WRITE_CMD 0x80000000 |
| 428 | #define EPHYAR_REG_MASK 0x1f |
| 429 | #define EPHYAR_REG_SHIFT 16 |
| 430 | #define EPHYAR_DATA_MASK 0xffff |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 431 | DLLPR = 0xd0, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 432 | #define PFM_EN (1 << 6) |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 433 | #define TX_10M_PS_EN (1 << 7) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 434 | DBG_REG = 0xd1, |
| 435 | #define FIX_NAK_1 (1 << 4) |
| 436 | #define FIX_NAK_2 (1 << 3) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 437 | TWSI = 0xd2, |
| 438 | MCU = 0xd3, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 439 | #define NOW_IS_OOB (1 << 7) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 440 | #define TX_EMPTY (1 << 5) |
| 441 | #define RX_EMPTY (1 << 4) |
| 442 | #define RXTX_EMPTY (TX_EMPTY | RX_EMPTY) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 443 | #define EN_NDP (1 << 3) |
| 444 | #define EN_OOB_RESET (1 << 2) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 445 | #define LINK_LIST_RDY (1 << 1) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 446 | EFUSEAR = 0xdc, |
| 447 | #define EFUSEAR_FLAG 0x80000000 |
| 448 | #define EFUSEAR_WRITE_CMD 0x80000000 |
| 449 | #define EFUSEAR_READ_CMD 0x00000000 |
| 450 | #define EFUSEAR_REG_MASK 0x03ff |
| 451 | #define EFUSEAR_REG_SHIFT 8 |
| 452 | #define EFUSEAR_DATA_MASK 0xff |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 453 | MISC_1 = 0xf2, |
| 454 | #define PFM_D3COLD_EN (1 << 6) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 455 | }; |
| 456 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 457 | enum rtl8168_registers { |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 458 | LED_FREQ = 0x1a, |
| 459 | EEE_LED = 0x1b, |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 460 | ERIDR = 0x70, |
| 461 | ERIAR = 0x74, |
| 462 | #define ERIAR_FLAG 0x80000000 |
| 463 | #define ERIAR_WRITE_CMD 0x80000000 |
| 464 | #define ERIAR_READ_CMD 0x00000000 |
| 465 | #define ERIAR_ADDR_BYTE_ALIGN 4 |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 466 | #define ERIAR_TYPE_SHIFT 16 |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 467 | #define ERIAR_EXGMAC (0x00 << ERIAR_TYPE_SHIFT) |
| 468 | #define ERIAR_MSIX (0x01 << ERIAR_TYPE_SHIFT) |
| 469 | #define ERIAR_ASF (0x02 << ERIAR_TYPE_SHIFT) |
| 470 | #define ERIAR_MASK_SHIFT 12 |
| 471 | #define ERIAR_MASK_0001 (0x1 << ERIAR_MASK_SHIFT) |
| 472 | #define ERIAR_MASK_0011 (0x3 << ERIAR_MASK_SHIFT) |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 473 | #define ERIAR_MASK_0100 (0x4 << ERIAR_MASK_SHIFT) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 474 | #define ERIAR_MASK_0101 (0x5 << ERIAR_MASK_SHIFT) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 475 | #define ERIAR_MASK_1111 (0xf << ERIAR_MASK_SHIFT) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 476 | EPHY_RXER_NUM = 0x7c, |
| 477 | OCPDR = 0xb0, /* OCP GPHY access */ |
| 478 | #define OCPDR_WRITE_CMD 0x80000000 |
| 479 | #define OCPDR_READ_CMD 0x00000000 |
| 480 | #define OCPDR_REG_MASK 0x7f |
| 481 | #define OCPDR_GPHY_REG_SHIFT 16 |
| 482 | #define OCPDR_DATA_MASK 0xffff |
| 483 | OCPAR = 0xb4, |
| 484 | #define OCPAR_FLAG 0x80000000 |
| 485 | #define OCPAR_GPHY_WRITE_CMD 0x8000f060 |
| 486 | #define OCPAR_GPHY_READ_CMD 0x0000f060 |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 487 | GPHY_OCP = 0xb8, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 488 | RDSAR1 = 0xd0, /* 8168c only. Undocumented on 8168dp */ |
| 489 | MISC = 0xf0, /* 8168e only. */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 490 | #define TXPLA_RST (1 << 29) |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 491 | #define DISABLE_LAN_EN (1 << 23) /* Enable GPIO pin */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 492 | #define PWM_EN (1 << 22) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 493 | #define RXDV_GATED_EN (1 << 19) |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 494 | #define EARLY_TALLY_EN (1 << 16) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 495 | }; |
| 496 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 497 | enum rtl_register_content { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | /* InterruptStatusBits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 499 | SYSErr = 0x8000, |
| 500 | PCSTimeout = 0x4000, |
| 501 | SWInt = 0x0100, |
| 502 | TxDescUnavail = 0x0080, |
| 503 | RxFIFOOver = 0x0040, |
| 504 | LinkChg = 0x0020, |
| 505 | RxOverflow = 0x0010, |
| 506 | TxErr = 0x0008, |
| 507 | TxOK = 0x0004, |
| 508 | RxErr = 0x0002, |
| 509 | RxOK = 0x0001, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
| 511 | /* RxStatusDesc */ |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 512 | RxBOVF = (1 << 24), |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 513 | RxFOVF = (1 << 23), |
| 514 | RxRWT = (1 << 22), |
| 515 | RxRES = (1 << 21), |
| 516 | RxRUNT = (1 << 20), |
| 517 | RxCRC = (1 << 19), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | |
| 519 | /* ChipCmdBits */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 520 | StopReq = 0x80, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 521 | CmdReset = 0x10, |
| 522 | CmdRxEnb = 0x08, |
| 523 | CmdTxEnb = 0x04, |
| 524 | RxBufEmpty = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
Francois Romieu | 275391a | 2007-02-23 23:50:28 +0100 | [diff] [blame] | 526 | /* TXPoll register p.5 */ |
| 527 | HPQ = 0x80, /* Poll cmd on the high prio queue */ |
| 528 | NPQ = 0x40, /* Poll cmd on the low prio queue */ |
| 529 | FSWInt = 0x01, /* Forced software interrupt */ |
| 530 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | /* Cfg9346Bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 532 | Cfg9346_Lock = 0x00, |
| 533 | Cfg9346_Unlock = 0xc0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | |
| 535 | /* rx_mode_bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 536 | AcceptErr = 0x20, |
| 537 | AcceptRunt = 0x10, |
| 538 | AcceptBroadcast = 0x08, |
| 539 | AcceptMulticast = 0x04, |
| 540 | AcceptMyPhys = 0x02, |
| 541 | AcceptAllPhys = 0x01, |
Francois Romieu | 1687b56 | 2011-07-19 17:21:29 +0200 | [diff] [blame] | 542 | #define RX_CONFIG_ACCEPT_MASK 0x3f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | /* TxConfigBits */ |
| 545 | TxInterFrameGapShift = 24, |
| 546 | TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */ |
| 547 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 548 | /* Config1 register p.24 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 549 | LEDS1 = (1 << 7), |
| 550 | LEDS0 = (1 << 6), |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 551 | Speed_down = (1 << 4), |
| 552 | MEMMAP = (1 << 3), |
| 553 | IOMAP = (1 << 2), |
| 554 | VPD = (1 << 1), |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 555 | PMEnable = (1 << 0), /* Power Management Enable */ |
| 556 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 557 | /* Config2 register p. 25 */ |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 558 | ClkReqEn = (1 << 7), /* Clock Request Enable */ |
françois romieu | 2ca6cf0 | 2011-12-15 08:37:43 +0000 | [diff] [blame] | 559 | MSIEnable = (1 << 5), /* 8169 only. Reserved in the 8168. */ |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 560 | PCI_Clock_66MHz = 0x01, |
| 561 | PCI_Clock_33MHz = 0x00, |
| 562 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 563 | /* Config3 register p.25 */ |
| 564 | MagicPacket = (1 << 5), /* Wake up when receives a Magic Packet */ |
| 565 | LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */ |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 566 | Jumbo_En0 = (1 << 2), /* 8168 only. Reserved in the 8168b */ |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 567 | Rdy_to_L23 = (1 << 1), /* L23 Enable */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 568 | Beacon_en = (1 << 0), /* 8168 only. Reserved in the 8168b */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 569 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 570 | /* Config4 register */ |
| 571 | Jumbo_En1 = (1 << 1), /* 8168 only. Reserved in the 8168b */ |
| 572 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 573 | /* Config5 register p.27 */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 574 | BWF = (1 << 6), /* Accept Broadcast wakeup frame */ |
| 575 | MWF = (1 << 5), /* Accept Multicast wakeup frame */ |
| 576 | UWF = (1 << 4), /* Accept Unicast wakeup frame */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 577 | Spi_en = (1 << 3), |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 578 | LanWake = (1 << 1), /* LanWake enable/disable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 579 | PMEStatus = (1 << 0), /* PME status can be reset by PCI RST# */ |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 580 | ASPM_en = (1 << 0), /* ASPM enable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 581 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | /* TBICSR p.28 */ |
| 583 | TBIReset = 0x80000000, |
| 584 | TBILoopback = 0x40000000, |
| 585 | TBINwEnable = 0x20000000, |
| 586 | TBINwRestart = 0x10000000, |
| 587 | TBILinkOk = 0x02000000, |
| 588 | TBINwComplete = 0x01000000, |
| 589 | |
| 590 | /* CPlusCmd p.31 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 591 | EnableBist = (1 << 15), // 8168 8101 |
| 592 | Mac_dbgo_oe = (1 << 14), // 8168 8101 |
| 593 | Normal_mode = (1 << 13), // unused |
| 594 | Force_half_dup = (1 << 12), // 8168 8101 |
| 595 | Force_rxflow_en = (1 << 11), // 8168 8101 |
| 596 | Force_txflow_en = (1 << 10), // 8168 8101 |
| 597 | Cxpl_dbg_sel = (1 << 9), // 8168 8101 |
| 598 | ASF = (1 << 8), // 8168 8101 |
| 599 | PktCntrDisable = (1 << 7), // 8168 8101 |
| 600 | Mac_dbgo_sel = 0x001c, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | RxVlan = (1 << 6), |
| 602 | RxChkSum = (1 << 5), |
| 603 | PCIDAC = (1 << 4), |
| 604 | PCIMulRW = (1 << 3), |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 605 | INTT_0 = 0x0000, // 8168 |
| 606 | INTT_1 = 0x0001, // 8168 |
| 607 | INTT_2 = 0x0002, // 8168 |
| 608 | INTT_3 = 0x0003, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | |
| 610 | /* rtl8169_PHYstatus */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 611 | TBI_Enable = 0x80, |
| 612 | TxFlowCtrl = 0x40, |
| 613 | RxFlowCtrl = 0x20, |
| 614 | _1000bpsF = 0x10, |
| 615 | _100bps = 0x08, |
| 616 | _10bps = 0x04, |
| 617 | LinkStatus = 0x02, |
| 618 | FullDup = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | /* _TBICSRBit */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 621 | TBILinkOK = 0x02000000, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 622 | |
| 623 | /* DumpCounterCommand */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 624 | CounterDump = 0x8, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 625 | |
| 626 | /* magic enable v2 */ |
| 627 | MagicPacket_v2 = (1 << 16), /* Wake up when receives a Magic Packet */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | }; |
| 629 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 630 | enum rtl_desc_bit { |
| 631 | /* First doubleword. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | DescOwn = (1 << 31), /* Descriptor is owned by NIC */ |
| 633 | RingEnd = (1 << 30), /* End of descriptor ring */ |
| 634 | FirstFrag = (1 << 29), /* First segment of a packet */ |
| 635 | LastFrag = (1 << 28), /* Final segment of a packet */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 636 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 638 | /* Generic case. */ |
| 639 | enum rtl_tx_desc_bit { |
| 640 | /* First doubleword. */ |
| 641 | TD_LSO = (1 << 27), /* Large Send Offload */ |
| 642 | #define TD_MSS_MAX 0x07ffu /* MSS value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 643 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 644 | /* Second doubleword. */ |
| 645 | TxVlanTag = (1 << 17), /* Add VLAN tag */ |
| 646 | }; |
| 647 | |
| 648 | /* 8169, 8168b and 810x except 8102e. */ |
| 649 | enum rtl_tx_desc_bit_0 { |
| 650 | /* First doubleword. */ |
| 651 | #define TD0_MSS_SHIFT 16 /* MSS position (11 bits) */ |
| 652 | TD0_TCP_CS = (1 << 16), /* Calculate TCP/IP checksum */ |
| 653 | TD0_UDP_CS = (1 << 17), /* Calculate UDP/IP checksum */ |
| 654 | TD0_IP_CS = (1 << 18), /* Calculate IP checksum */ |
| 655 | }; |
| 656 | |
| 657 | /* 8102e, 8168c and beyond. */ |
| 658 | enum rtl_tx_desc_bit_1 { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 659 | /* First doubleword. */ |
| 660 | TD1_GTSENV4 = (1 << 26), /* Giant Send for IPv4 */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 661 | TD1_GTSENV6 = (1 << 25), /* Giant Send for IPv6 */ |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 662 | #define GTTCPHO_SHIFT 18 |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 663 | #define GTTCPHO_MAX 0x7fU |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 664 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 665 | /* Second doubleword. */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 666 | #define TCPHO_SHIFT 18 |
| 667 | #define TCPHO_MAX 0x3ffU |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 668 | #define TD1_MSS_SHIFT 18 /* MSS position (11 bits) */ |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 669 | TD1_IPv6_CS = (1 << 28), /* Calculate IPv6 checksum */ |
| 670 | TD1_IPv4_CS = (1 << 29), /* Calculate IPv4 checksum */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 671 | TD1_TCP_CS = (1 << 30), /* Calculate TCP/IP checksum */ |
| 672 | TD1_UDP_CS = (1 << 31), /* Calculate UDP/IP checksum */ |
| 673 | }; |
| 674 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 675 | enum rtl_rx_desc_bit { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | /* Rx private */ |
| 677 | PID1 = (1 << 18), /* Protocol ID bit 1/2 */ |
| 678 | PID0 = (1 << 17), /* Protocol ID bit 2/2 */ |
| 679 | |
| 680 | #define RxProtoUDP (PID1) |
| 681 | #define RxProtoTCP (PID0) |
| 682 | #define RxProtoIP (PID1 | PID0) |
| 683 | #define RxProtoMask RxProtoIP |
| 684 | |
| 685 | IPFail = (1 << 16), /* IP checksum failed */ |
| 686 | UDPFail = (1 << 15), /* UDP/IP checksum failed */ |
| 687 | TCPFail = (1 << 14), /* TCP/IP checksum failed */ |
| 688 | RxVlanTag = (1 << 16), /* VLAN tag available */ |
| 689 | }; |
| 690 | |
| 691 | #define RsvdMask 0x3fffc000 |
| 692 | |
| 693 | struct TxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 694 | __le32 opts1; |
| 695 | __le32 opts2; |
| 696 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | }; |
| 698 | |
| 699 | struct RxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 700 | __le32 opts1; |
| 701 | __le32 opts2; |
| 702 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | }; |
| 704 | |
| 705 | struct ring_info { |
| 706 | struct sk_buff *skb; |
| 707 | u32 len; |
| 708 | u8 __pad[sizeof(void *) - sizeof(u32)]; |
| 709 | }; |
| 710 | |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 711 | enum features { |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 712 | RTL_FEATURE_WOL = (1 << 0), |
| 713 | RTL_FEATURE_MSI = (1 << 1), |
| 714 | RTL_FEATURE_GMII = (1 << 2), |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 715 | }; |
| 716 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 717 | struct rtl8169_counters { |
| 718 | __le64 tx_packets; |
| 719 | __le64 rx_packets; |
| 720 | __le64 tx_errors; |
| 721 | __le32 rx_errors; |
| 722 | __le16 rx_missed; |
| 723 | __le16 align_errors; |
| 724 | __le32 tx_one_collision; |
| 725 | __le32 tx_multi_collision; |
| 726 | __le64 rx_unicast; |
| 727 | __le64 rx_broadcast; |
| 728 | __le32 rx_multicast; |
| 729 | __le16 tx_aborted; |
| 730 | __le16 tx_underun; |
| 731 | }; |
| 732 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 733 | enum rtl_flag { |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 734 | RTL_FLAG_TASK_ENABLED, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 735 | RTL_FLAG_TASK_SLOW_PENDING, |
| 736 | RTL_FLAG_TASK_RESET_PENDING, |
| 737 | RTL_FLAG_TASK_PHY_PENDING, |
| 738 | RTL_FLAG_MAX |
| 739 | }; |
| 740 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 741 | struct rtl8169_stats { |
| 742 | u64 packets; |
| 743 | u64 bytes; |
| 744 | struct u64_stats_sync syncp; |
| 745 | }; |
| 746 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | struct rtl8169_private { |
| 748 | void __iomem *mmio_addr; /* memory map physical address */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 749 | struct pci_dev *pci_dev; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 750 | struct net_device *dev; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 751 | struct napi_struct napi; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 752 | u32 msg_enable; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 753 | u16 txd_version; |
| 754 | u16 mac_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */ |
| 756 | 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] | 757 | u32 dirty_tx; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 758 | struct rtl8169_stats rx_stats; |
| 759 | struct rtl8169_stats tx_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */ |
| 761 | struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */ |
| 762 | dma_addr_t TxPhyAddr; |
| 763 | dma_addr_t RxPhyAddr; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 764 | void *Rx_databuff[NUM_RX_DESC]; /* Rx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 765 | struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | struct timer_list timer; |
| 767 | u16 cp_cmd; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 768 | |
| 769 | u16 event_slow; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 770 | |
| 771 | struct mdio_ops { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 772 | void (*write)(struct rtl8169_private *, int, int); |
| 773 | int (*read)(struct rtl8169_private *, int); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 774 | } mdio_ops; |
| 775 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 776 | struct pll_power_ops { |
| 777 | void (*down)(struct rtl8169_private *); |
| 778 | void (*up)(struct rtl8169_private *); |
| 779 | } pll_power_ops; |
| 780 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 781 | struct jumbo_ops { |
| 782 | void (*enable)(struct rtl8169_private *); |
| 783 | void (*disable)(struct rtl8169_private *); |
| 784 | } jumbo_ops; |
| 785 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 786 | struct csi_ops { |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 787 | void (*write)(struct rtl8169_private *, int, int); |
| 788 | u32 (*read)(struct rtl8169_private *, int); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 789 | } csi_ops; |
| 790 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 791 | int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 792 | int (*get_settings)(struct net_device *, struct ethtool_cmd *); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 793 | void (*phy_reset_enable)(struct rtl8169_private *tp); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 794 | void (*hw_start)(struct net_device *); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 795 | unsigned int (*phy_reset_pending)(struct rtl8169_private *tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | unsigned int (*link_ok)(void __iomem *); |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 797 | 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] | 798 | bool (*tso_csum)(struct rtl8169_private *, struct sk_buff *, u32 *); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 799 | |
| 800 | struct { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 801 | DECLARE_BITMAP(flags, RTL_FLAG_MAX); |
| 802 | struct mutex mutex; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 803 | struct work_struct work; |
| 804 | } wk; |
| 805 | |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 806 | unsigned features; |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 807 | |
| 808 | struct mii_if_info mii; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 809 | struct rtl8169_counters counters; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 810 | u32 saved_wolopts; |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 811 | u32 opts1_mask; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 812 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 813 | struct rtl_fw { |
| 814 | const struct firmware *fw; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 815 | |
| 816 | #define RTL_VER_SIZE 32 |
| 817 | |
| 818 | char version[RTL_VER_SIZE]; |
| 819 | |
| 820 | struct rtl_fw_phy_action { |
| 821 | __le32 *code; |
| 822 | size_t size; |
| 823 | } phy_action; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 824 | } *rtl_fw; |
Phil Carmody | 497888c | 2011-07-14 15:07:13 +0300 | [diff] [blame] | 825 | #define RTL_FIRMWARE_UNKNOWN ERR_PTR(-EAGAIN) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 826 | |
| 827 | u32 ocp_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | }; |
| 829 | |
Ralf Baechle | 979b6c1 | 2005-06-13 14:30:40 -0700 | [diff] [blame] | 830 | MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 831 | MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | module_param(use_dac, int, 0); |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 833 | 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] | 834 | module_param_named(debug, debug.msg_enable, int, 0); |
| 835 | MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | MODULE_LICENSE("GPL"); |
| 837 | MODULE_VERSION(RTL8169_VERSION); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 838 | MODULE_FIRMWARE(FIRMWARE_8168D_1); |
| 839 | MODULE_FIRMWARE(FIRMWARE_8168D_2); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 840 | MODULE_FIRMWARE(FIRMWARE_8168E_1); |
| 841 | MODULE_FIRMWARE(FIRMWARE_8168E_2); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 842 | MODULE_FIRMWARE(FIRMWARE_8168E_3); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 843 | MODULE_FIRMWARE(FIRMWARE_8105E_1); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 844 | MODULE_FIRMWARE(FIRMWARE_8168F_1); |
| 845 | MODULE_FIRMWARE(FIRMWARE_8168F_2); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 846 | MODULE_FIRMWARE(FIRMWARE_8402_1); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 847 | MODULE_FIRMWARE(FIRMWARE_8411_1); |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 848 | MODULE_FIRMWARE(FIRMWARE_8411_2); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 849 | MODULE_FIRMWARE(FIRMWARE_8106E_1); |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 850 | MODULE_FIRMWARE(FIRMWARE_8106E_2); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 851 | MODULE_FIRMWARE(FIRMWARE_8168G_2); |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 852 | MODULE_FIRMWARE(FIRMWARE_8168G_3); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 853 | MODULE_FIRMWARE(FIRMWARE_8168H_1); |
| 854 | MODULE_FIRMWARE(FIRMWARE_8168H_2); |
Francois Romieu | a3bf5c4 | 2014-08-26 22:40:38 +0200 | [diff] [blame] | 855 | MODULE_FIRMWARE(FIRMWARE_8107E_1); |
| 856 | MODULE_FIRMWARE(FIRMWARE_8107E_2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 858 | static void rtl_lock_work(struct rtl8169_private *tp) |
| 859 | { |
| 860 | mutex_lock(&tp->wk.mutex); |
| 861 | } |
| 862 | |
| 863 | static void rtl_unlock_work(struct rtl8169_private *tp) |
| 864 | { |
| 865 | mutex_unlock(&tp->wk.mutex); |
| 866 | } |
| 867 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 868 | static void rtl_tx_performance_tweak(struct pci_dev *pdev, u16 force) |
| 869 | { |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 870 | pcie_capability_clear_and_set_word(pdev, PCI_EXP_DEVCTL, |
| 871 | PCI_EXP_DEVCTL_READRQ, force); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 872 | } |
| 873 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 874 | struct rtl_cond { |
| 875 | bool (*check)(struct rtl8169_private *); |
| 876 | const char *msg; |
| 877 | }; |
| 878 | |
| 879 | static void rtl_udelay(unsigned int d) |
| 880 | { |
| 881 | udelay(d); |
| 882 | } |
| 883 | |
| 884 | static bool rtl_loop_wait(struct rtl8169_private *tp, const struct rtl_cond *c, |
| 885 | void (*delay)(unsigned int), unsigned int d, int n, |
| 886 | bool high) |
| 887 | { |
| 888 | int i; |
| 889 | |
| 890 | for (i = 0; i < n; i++) { |
| 891 | delay(d); |
| 892 | if (c->check(tp) == high) |
| 893 | return true; |
| 894 | } |
Francois Romieu | 82e316e | 2012-07-11 23:39:51 +0200 | [diff] [blame] | 895 | netif_err(tp, drv, tp->dev, "%s == %d (loop: %d, delay: %d).\n", |
| 896 | c->msg, !high, n, d); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 897 | return false; |
| 898 | } |
| 899 | |
| 900 | static bool rtl_udelay_loop_wait_high(struct rtl8169_private *tp, |
| 901 | const struct rtl_cond *c, |
| 902 | unsigned int d, int n) |
| 903 | { |
| 904 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, true); |
| 905 | } |
| 906 | |
| 907 | static bool rtl_udelay_loop_wait_low(struct rtl8169_private *tp, |
| 908 | const struct rtl_cond *c, |
| 909 | unsigned int d, int n) |
| 910 | { |
| 911 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, false); |
| 912 | } |
| 913 | |
| 914 | static bool rtl_msleep_loop_wait_high(struct rtl8169_private *tp, |
| 915 | const struct rtl_cond *c, |
| 916 | unsigned int d, int n) |
| 917 | { |
| 918 | return rtl_loop_wait(tp, c, msleep, d, n, true); |
| 919 | } |
| 920 | |
| 921 | static bool rtl_msleep_loop_wait_low(struct rtl8169_private *tp, |
| 922 | const struct rtl_cond *c, |
| 923 | unsigned int d, int n) |
| 924 | { |
| 925 | return rtl_loop_wait(tp, c, msleep, d, n, false); |
| 926 | } |
| 927 | |
| 928 | #define DECLARE_RTL_COND(name) \ |
| 929 | static bool name ## _check(struct rtl8169_private *); \ |
| 930 | \ |
| 931 | static const struct rtl_cond name = { \ |
| 932 | .check = name ## _check, \ |
| 933 | .msg = #name \ |
| 934 | }; \ |
| 935 | \ |
| 936 | static bool name ## _check(struct rtl8169_private *tp) |
| 937 | |
| 938 | DECLARE_RTL_COND(rtl_ocpar_cond) |
| 939 | { |
| 940 | void __iomem *ioaddr = tp->mmio_addr; |
| 941 | |
| 942 | return RTL_R32(OCPAR) & OCPAR_FLAG; |
| 943 | } |
| 944 | |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 945 | static u32 ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 946 | { |
| 947 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 948 | |
| 949 | RTL_W32(OCPAR, ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 950 | |
| 951 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 100, 20) ? |
| 952 | RTL_R32(OCPDR) : ~0; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 953 | } |
| 954 | |
| 955 | static void ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, u32 data) |
| 956 | { |
| 957 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 958 | |
| 959 | RTL_W32(OCPDR, data); |
| 960 | RTL_W32(OCPAR, OCPAR_FLAG | ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 961 | |
| 962 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 100, 20); |
| 963 | } |
| 964 | |
| 965 | DECLARE_RTL_COND(rtl_eriar_cond) |
| 966 | { |
| 967 | void __iomem *ioaddr = tp->mmio_addr; |
| 968 | |
| 969 | return RTL_R32(ERIAR) & ERIAR_FLAG; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 970 | } |
| 971 | |
Hayes Wang | fac5b3c | 2011-02-22 17:26:20 +0800 | [diff] [blame] | 972 | static void rtl8168_oob_notify(struct rtl8169_private *tp, u8 cmd) |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 973 | { |
Hayes Wang | fac5b3c | 2011-02-22 17:26:20 +0800 | [diff] [blame] | 974 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 975 | |
| 976 | RTL_W8(ERIDR, cmd); |
| 977 | RTL_W32(ERIAR, 0x800010e8); |
| 978 | msleep(2); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 979 | |
| 980 | if (!rtl_udelay_loop_wait_low(tp, &rtl_eriar_cond, 100, 5)) |
| 981 | return; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 982 | |
Hayes Wang | fac5b3c | 2011-02-22 17:26:20 +0800 | [diff] [blame] | 983 | ocp_write(tp, 0x1, 0x30, 0x00000001); |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 984 | } |
| 985 | |
| 986 | #define OOB_CMD_RESET 0x00 |
| 987 | #define OOB_CMD_DRIVER_START 0x05 |
| 988 | #define OOB_CMD_DRIVER_STOP 0x06 |
| 989 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 990 | static u16 rtl8168_get_ocp_reg(struct rtl8169_private *tp) |
| 991 | { |
| 992 | return (tp->mac_version == RTL_GIGA_MAC_VER_31) ? 0xb8 : 0x10; |
| 993 | } |
| 994 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 995 | DECLARE_RTL_COND(rtl_ocp_read_cond) |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 996 | { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 997 | u16 reg; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 998 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 999 | reg = rtl8168_get_ocp_reg(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 1000 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1001 | return ocp_read(tp, 0x0f, reg) & 0x00000800; |
| 1002 | } |
| 1003 | |
| 1004 | static void rtl8168_driver_start(struct rtl8169_private *tp) |
| 1005 | { |
| 1006 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_START); |
| 1007 | |
| 1008 | rtl_msleep_loop_wait_high(tp, &rtl_ocp_read_cond, 10, 10); |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 1009 | } |
| 1010 | |
| 1011 | static void rtl8168_driver_stop(struct rtl8169_private *tp) |
| 1012 | { |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 1013 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_STOP); |
| 1014 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1015 | rtl_msleep_loop_wait_low(tp, &rtl_ocp_read_cond, 10, 10); |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 1016 | } |
| 1017 | |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 1018 | static int r8168dp_check_dash(struct rtl8169_private *tp) |
| 1019 | { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1020 | u16 reg = rtl8168_get_ocp_reg(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 1021 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1022 | return (ocp_read(tp, 0x0f, reg) & 0x00008000) ? 1 : 0; |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 1023 | } |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 1024 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1025 | static bool rtl_ocp_reg_failure(struct rtl8169_private *tp, u32 reg) |
| 1026 | { |
| 1027 | if (reg & 0xffff0001) { |
| 1028 | netif_err(tp, drv, tp->dev, "Invalid ocp reg %x!\n", reg); |
| 1029 | return true; |
| 1030 | } |
| 1031 | return false; |
| 1032 | } |
| 1033 | |
| 1034 | DECLARE_RTL_COND(rtl_ocp_gphy_cond) |
| 1035 | { |
| 1036 | void __iomem *ioaddr = tp->mmio_addr; |
| 1037 | |
| 1038 | return RTL_R32(GPHY_OCP) & OCPAR_FLAG; |
| 1039 | } |
| 1040 | |
| 1041 | static void r8168_phy_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 1042 | { |
| 1043 | void __iomem *ioaddr = tp->mmio_addr; |
| 1044 | |
| 1045 | if (rtl_ocp_reg_failure(tp, reg)) |
| 1046 | return; |
| 1047 | |
| 1048 | RTL_W32(GPHY_OCP, OCPAR_FLAG | (reg << 15) | data); |
| 1049 | |
| 1050 | rtl_udelay_loop_wait_low(tp, &rtl_ocp_gphy_cond, 25, 10); |
| 1051 | } |
| 1052 | |
| 1053 | static u16 r8168_phy_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 1054 | { |
| 1055 | void __iomem *ioaddr = tp->mmio_addr; |
| 1056 | |
| 1057 | if (rtl_ocp_reg_failure(tp, reg)) |
| 1058 | return 0; |
| 1059 | |
| 1060 | RTL_W32(GPHY_OCP, reg << 15); |
| 1061 | |
| 1062 | return rtl_udelay_loop_wait_high(tp, &rtl_ocp_gphy_cond, 25, 10) ? |
| 1063 | (RTL_R32(GPHY_OCP) & 0xffff) : ~0; |
| 1064 | } |
| 1065 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1066 | static void r8168_mac_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 1067 | { |
| 1068 | void __iomem *ioaddr = tp->mmio_addr; |
| 1069 | |
| 1070 | if (rtl_ocp_reg_failure(tp, reg)) |
| 1071 | return; |
| 1072 | |
| 1073 | RTL_W32(OCPDR, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1074 | } |
| 1075 | |
| 1076 | static u16 r8168_mac_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 1077 | { |
| 1078 | void __iomem *ioaddr = tp->mmio_addr; |
| 1079 | |
| 1080 | if (rtl_ocp_reg_failure(tp, reg)) |
| 1081 | return 0; |
| 1082 | |
| 1083 | RTL_W32(OCPDR, reg << 15); |
| 1084 | |
Hayes Wang | 3a83ad1 | 2012-07-11 20:31:56 +0800 | [diff] [blame] | 1085 | return RTL_R32(OCPDR); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1086 | } |
| 1087 | |
| 1088 | #define OCP_STD_PHY_BASE 0xa400 |
| 1089 | |
| 1090 | static void r8168g_mdio_write(struct rtl8169_private *tp, int reg, int value) |
| 1091 | { |
| 1092 | if (reg == 0x1f) { |
| 1093 | tp->ocp_base = value ? value << 4 : OCP_STD_PHY_BASE; |
| 1094 | return; |
| 1095 | } |
| 1096 | |
| 1097 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 1098 | reg -= 0x10; |
| 1099 | |
| 1100 | r8168_phy_ocp_write(tp, tp->ocp_base + reg * 2, value); |
| 1101 | } |
| 1102 | |
| 1103 | static int r8168g_mdio_read(struct rtl8169_private *tp, int reg) |
| 1104 | { |
| 1105 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 1106 | reg -= 0x10; |
| 1107 | |
| 1108 | return r8168_phy_ocp_read(tp, tp->ocp_base + reg * 2); |
| 1109 | } |
| 1110 | |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 1111 | static void mac_mcu_write(struct rtl8169_private *tp, int reg, int value) |
| 1112 | { |
| 1113 | if (reg == 0x1f) { |
| 1114 | tp->ocp_base = value << 4; |
| 1115 | return; |
| 1116 | } |
| 1117 | |
| 1118 | r8168_mac_ocp_write(tp, tp->ocp_base + reg, value); |
| 1119 | } |
| 1120 | |
| 1121 | static int mac_mcu_read(struct rtl8169_private *tp, int reg) |
| 1122 | { |
| 1123 | return r8168_mac_ocp_read(tp, tp->ocp_base + reg); |
| 1124 | } |
| 1125 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1126 | DECLARE_RTL_COND(rtl_phyar_cond) |
| 1127 | { |
| 1128 | void __iomem *ioaddr = tp->mmio_addr; |
| 1129 | |
| 1130 | return RTL_R32(PHYAR) & 0x80000000; |
| 1131 | } |
| 1132 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1133 | 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] | 1134 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1135 | void __iomem *ioaddr = tp->mmio_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1137 | RTL_W32(PHYAR, 0x80000000 | (reg & 0x1f) << 16 | (value & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1138 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1139 | rtl_udelay_loop_wait_low(tp, &rtl_phyar_cond, 25, 20); |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 1140 | /* |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 1141 | * According to hardware specs a 20us delay is required after write |
| 1142 | * complete indication, but before sending next command. |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 1143 | */ |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 1144 | udelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | } |
| 1146 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1147 | static int r8169_mdio_read(struct rtl8169_private *tp, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1149 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1150 | int value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1151 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1152 | RTL_W32(PHYAR, 0x0 | (reg & 0x1f) << 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1153 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1154 | value = rtl_udelay_loop_wait_high(tp, &rtl_phyar_cond, 25, 20) ? |
| 1155 | RTL_R32(PHYAR) & 0xffff : ~0; |
| 1156 | |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 1157 | /* |
| 1158 | * According to hardware specs a 20us delay is required after read |
| 1159 | * complete indication, but before sending next command. |
| 1160 | */ |
| 1161 | udelay(20); |
| 1162 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1163 | return value; |
| 1164 | } |
| 1165 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1166 | 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] | 1167 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1168 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1169 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1170 | 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] | 1171 | RTL_W32(OCPAR, OCPAR_GPHY_WRITE_CMD); |
| 1172 | RTL_W32(EPHY_RXER_NUM, 0); |
| 1173 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1174 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 1000, 100); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1175 | } |
| 1176 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1177 | 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] | 1178 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1179 | r8168dp_1_mdio_access(tp, reg, |
| 1180 | OCPDR_WRITE_CMD | (value & OCPDR_DATA_MASK)); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1181 | } |
| 1182 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1183 | 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] | 1184 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1185 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1186 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1187 | r8168dp_1_mdio_access(tp, reg, OCPDR_READ_CMD); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1188 | |
| 1189 | mdelay(1); |
| 1190 | RTL_W32(OCPAR, OCPAR_GPHY_READ_CMD); |
| 1191 | RTL_W32(EPHY_RXER_NUM, 0); |
| 1192 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1193 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 1000, 100) ? |
| 1194 | RTL_R32(OCPDR) & OCPDR_DATA_MASK : ~0; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1195 | } |
| 1196 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1197 | #define R8168DP_1_MDIO_ACCESS_BIT 0x00020000 |
| 1198 | |
| 1199 | static void r8168dp_2_mdio_start(void __iomem *ioaddr) |
| 1200 | { |
| 1201 | RTL_W32(0xd0, RTL_R32(0xd0) & ~R8168DP_1_MDIO_ACCESS_BIT); |
| 1202 | } |
| 1203 | |
| 1204 | static void r8168dp_2_mdio_stop(void __iomem *ioaddr) |
| 1205 | { |
| 1206 | RTL_W32(0xd0, RTL_R32(0xd0) | R8168DP_1_MDIO_ACCESS_BIT); |
| 1207 | } |
| 1208 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1209 | 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] | 1210 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1211 | void __iomem *ioaddr = tp->mmio_addr; |
| 1212 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1213 | r8168dp_2_mdio_start(ioaddr); |
| 1214 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1215 | r8169_mdio_write(tp, reg, value); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1216 | |
| 1217 | r8168dp_2_mdio_stop(ioaddr); |
| 1218 | } |
| 1219 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1220 | 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] | 1221 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1222 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1223 | int value; |
| 1224 | |
| 1225 | r8168dp_2_mdio_start(ioaddr); |
| 1226 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1227 | value = r8169_mdio_read(tp, reg); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1228 | |
| 1229 | r8168dp_2_mdio_stop(ioaddr); |
| 1230 | |
| 1231 | return value; |
| 1232 | } |
| 1233 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1234 | static void rtl_writephy(struct rtl8169_private *tp, int location, u32 val) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1235 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1236 | tp->mdio_ops.write(tp, location, val); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1237 | } |
| 1238 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1239 | static int rtl_readphy(struct rtl8169_private *tp, int location) |
| 1240 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1241 | return tp->mdio_ops.read(tp, location); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1242 | } |
| 1243 | |
| 1244 | static void rtl_patchphy(struct rtl8169_private *tp, int reg_addr, int value) |
| 1245 | { |
| 1246 | rtl_writephy(tp, reg_addr, rtl_readphy(tp, reg_addr) | value); |
| 1247 | } |
| 1248 | |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1249 | 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] | 1250 | { |
| 1251 | int val; |
| 1252 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1253 | val = rtl_readphy(tp, reg_addr); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 1254 | rtl_writephy(tp, reg_addr, (val & ~m) | p); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1255 | } |
| 1256 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1257 | static void rtl_mdio_write(struct net_device *dev, int phy_id, int location, |
| 1258 | int val) |
| 1259 | { |
| 1260 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1261 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1262 | rtl_writephy(tp, location, val); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | static int rtl_mdio_read(struct net_device *dev, int phy_id, int location) |
| 1266 | { |
| 1267 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1268 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1269 | return rtl_readphy(tp, location); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1270 | } |
| 1271 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1272 | DECLARE_RTL_COND(rtl_ephyar_cond) |
| 1273 | { |
| 1274 | void __iomem *ioaddr = tp->mmio_addr; |
| 1275 | |
| 1276 | return RTL_R32(EPHYAR) & EPHYAR_FLAG; |
| 1277 | } |
| 1278 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1279 | 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] | 1280 | { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1281 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1282 | |
| 1283 | RTL_W32(EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) | |
| 1284 | (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
| 1285 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1286 | rtl_udelay_loop_wait_low(tp, &rtl_ephyar_cond, 10, 100); |
| 1287 | |
| 1288 | udelay(10); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1289 | } |
| 1290 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1291 | static u16 rtl_ephy_read(struct rtl8169_private *tp, int reg_addr) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1292 | { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1293 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1294 | |
| 1295 | RTL_W32(EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
| 1296 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1297 | return rtl_udelay_loop_wait_high(tp, &rtl_ephyar_cond, 10, 100) ? |
| 1298 | RTL_R32(EPHYAR) & EPHYAR_DATA_MASK : ~0; |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1299 | } |
| 1300 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1301 | static void rtl_eri_write(struct rtl8169_private *tp, int addr, u32 mask, |
| 1302 | u32 val, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1303 | { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1304 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1305 | |
| 1306 | BUG_ON((addr & 3) || (mask == 0)); |
| 1307 | RTL_W32(ERIDR, val); |
| 1308 | RTL_W32(ERIAR, ERIAR_WRITE_CMD | type | mask | addr); |
| 1309 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1310 | rtl_udelay_loop_wait_low(tp, &rtl_eriar_cond, 100, 100); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1311 | } |
| 1312 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1313 | 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] | 1314 | { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1315 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1316 | |
| 1317 | RTL_W32(ERIAR, ERIAR_READ_CMD | type | ERIAR_MASK_1111 | addr); |
| 1318 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1319 | return rtl_udelay_loop_wait_high(tp, &rtl_eriar_cond, 100, 100) ? |
| 1320 | RTL_R32(ERIDR) : ~0; |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1321 | } |
| 1322 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame^] | 1323 | 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] | 1324 | u32 m, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1325 | { |
| 1326 | u32 val; |
| 1327 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1328 | val = rtl_eri_read(tp, addr, type); |
| 1329 | rtl_eri_write(tp, addr, mask, (val & ~m) | p, type); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1330 | } |
| 1331 | |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1332 | struct exgmac_reg { |
| 1333 | u16 addr; |
| 1334 | u16 mask; |
| 1335 | u32 val; |
| 1336 | }; |
| 1337 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1338 | static void rtl_write_exgmac_batch(struct rtl8169_private *tp, |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1339 | const struct exgmac_reg *r, int len) |
| 1340 | { |
| 1341 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1342 | 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] | 1343 | r++; |
| 1344 | } |
| 1345 | } |
| 1346 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1347 | DECLARE_RTL_COND(rtl_efusear_cond) |
| 1348 | { |
| 1349 | void __iomem *ioaddr = tp->mmio_addr; |
| 1350 | |
| 1351 | return RTL_R32(EFUSEAR) & EFUSEAR_FLAG; |
| 1352 | } |
| 1353 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1354 | 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] | 1355 | { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1356 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1357 | |
| 1358 | RTL_W32(EFUSEAR, (reg_addr & EFUSEAR_REG_MASK) << EFUSEAR_REG_SHIFT); |
| 1359 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1360 | return rtl_udelay_loop_wait_high(tp, &rtl_efusear_cond, 100, 300) ? |
| 1361 | RTL_R32(EFUSEAR) & EFUSEAR_DATA_MASK : ~0; |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1362 | } |
| 1363 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1364 | static u16 rtl_get_events(struct rtl8169_private *tp) |
| 1365 | { |
| 1366 | void __iomem *ioaddr = tp->mmio_addr; |
| 1367 | |
| 1368 | return RTL_R16(IntrStatus); |
| 1369 | } |
| 1370 | |
| 1371 | static void rtl_ack_events(struct rtl8169_private *tp, u16 bits) |
| 1372 | { |
| 1373 | void __iomem *ioaddr = tp->mmio_addr; |
| 1374 | |
| 1375 | RTL_W16(IntrStatus, bits); |
| 1376 | mmiowb(); |
| 1377 | } |
| 1378 | |
| 1379 | static void rtl_irq_disable(struct rtl8169_private *tp) |
| 1380 | { |
| 1381 | void __iomem *ioaddr = tp->mmio_addr; |
| 1382 | |
| 1383 | RTL_W16(IntrMask, 0); |
| 1384 | mmiowb(); |
| 1385 | } |
| 1386 | |
Francois Romieu | 3e990ff | 2012-01-26 12:50:01 +0100 | [diff] [blame] | 1387 | static void rtl_irq_enable(struct rtl8169_private *tp, u16 bits) |
| 1388 | { |
| 1389 | void __iomem *ioaddr = tp->mmio_addr; |
| 1390 | |
| 1391 | RTL_W16(IntrMask, bits); |
| 1392 | } |
| 1393 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1394 | #define RTL_EVENT_NAPI_RX (RxOK | RxErr) |
| 1395 | #define RTL_EVENT_NAPI_TX (TxOK | TxErr) |
| 1396 | #define RTL_EVENT_NAPI (RTL_EVENT_NAPI_RX | RTL_EVENT_NAPI_TX) |
| 1397 | |
| 1398 | static void rtl_irq_enable_all(struct rtl8169_private *tp) |
| 1399 | { |
| 1400 | rtl_irq_enable(tp, RTL_EVENT_NAPI | tp->event_slow); |
| 1401 | } |
| 1402 | |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 1403 | static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1404 | { |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 1405 | void __iomem *ioaddr = tp->mmio_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1407 | rtl_irq_disable(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1408 | rtl_ack_events(tp, RTL_EVENT_NAPI | tp->event_slow); |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 1409 | RTL_R8(ChipCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | } |
| 1411 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1412 | static unsigned int rtl8169_tbi_reset_pending(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1413 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1414 | void __iomem *ioaddr = tp->mmio_addr; |
| 1415 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | return RTL_R32(TBICSR) & TBIReset; |
| 1417 | } |
| 1418 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1419 | static unsigned int rtl8169_xmii_reset_pending(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1421 | return rtl_readphy(tp, MII_BMCR) & BMCR_RESET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | static unsigned int rtl8169_tbi_link_ok(void __iomem *ioaddr) |
| 1425 | { |
| 1426 | return RTL_R32(TBICSR) & TBILinkOk; |
| 1427 | } |
| 1428 | |
| 1429 | static unsigned int rtl8169_xmii_link_ok(void __iomem *ioaddr) |
| 1430 | { |
| 1431 | return RTL_R8(PHYstatus) & LinkStatus; |
| 1432 | } |
| 1433 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1434 | static void rtl8169_tbi_reset_enable(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1435 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1436 | void __iomem *ioaddr = tp->mmio_addr; |
| 1437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | RTL_W32(TBICSR, RTL_R32(TBICSR) | TBIReset); |
| 1439 | } |
| 1440 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1441 | static void rtl8169_xmii_reset_enable(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | { |
| 1443 | unsigned int val; |
| 1444 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1445 | val = rtl_readphy(tp, MII_BMCR) | BMCR_RESET; |
| 1446 | rtl_writephy(tp, MII_BMCR, val & 0xffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1447 | } |
| 1448 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1449 | static void rtl_link_chg_patch(struct rtl8169_private *tp) |
| 1450 | { |
| 1451 | void __iomem *ioaddr = tp->mmio_addr; |
| 1452 | struct net_device *dev = tp->dev; |
| 1453 | |
| 1454 | if (!netif_running(dev)) |
| 1455 | return; |
| 1456 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 1457 | if (tp->mac_version == RTL_GIGA_MAC_VER_34 || |
| 1458 | tp->mac_version == RTL_GIGA_MAC_VER_38) { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1459 | if (RTL_R8(PHYstatus) & _1000bpsF) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1460 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011, |
| 1461 | ERIAR_EXGMAC); |
| 1462 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1463 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1464 | } else if (RTL_R8(PHYstatus) & _100bps) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1465 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1466 | ERIAR_EXGMAC); |
| 1467 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1468 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1469 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1470 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1471 | ERIAR_EXGMAC); |
| 1472 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f, |
| 1473 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1474 | } |
| 1475 | /* Reset packet filter */ |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame^] | 1476 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1477 | ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame^] | 1478 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1479 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1480 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 1481 | tp->mac_version == RTL_GIGA_MAC_VER_36) { |
| 1482 | if (RTL_R8(PHYstatus) & _1000bpsF) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1483 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011, |
| 1484 | ERIAR_EXGMAC); |
| 1485 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1486 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1487 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1488 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1489 | ERIAR_EXGMAC); |
| 1490 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f, |
| 1491 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1492 | } |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1493 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_37) { |
| 1494 | if (RTL_R8(PHYstatus) & _10bps) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1495 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x4d02, |
| 1496 | ERIAR_EXGMAC); |
| 1497 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_0011, 0x0060, |
| 1498 | ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1499 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1500 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, |
| 1501 | ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1502 | } |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1503 | } |
| 1504 | } |
| 1505 | |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 1506 | static void __rtl8169_check_link_status(struct net_device *dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1507 | struct rtl8169_private *tp, |
| 1508 | void __iomem *ioaddr, bool pm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | if (tp->link_ok(ioaddr)) { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1511 | rtl_link_chg_patch(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1512 | /* This is to cancel a scheduled suspend if there's one. */ |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 1513 | if (pm) |
| 1514 | pm_request_resume(&tp->pci_dev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1515 | netif_carrier_on(dev); |
Francois Romieu | 1519e57 | 2011-02-03 12:02:36 +0100 | [diff] [blame] | 1516 | if (net_ratelimit()) |
| 1517 | netif_info(tp, ifup, dev, "link up\n"); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1518 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1519 | netif_carrier_off(dev); |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1520 | netif_info(tp, ifdown, dev, "link down\n"); |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 1521 | if (pm) |
hayeswang | 10953db | 2011-11-07 20:44:37 +0000 | [diff] [blame] | 1522 | pm_schedule_suspend(&tp->pci_dev->dev, 5000); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1523 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1524 | } |
| 1525 | |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 1526 | static void rtl8169_check_link_status(struct net_device *dev, |
| 1527 | struct rtl8169_private *tp, |
| 1528 | void __iomem *ioaddr) |
| 1529 | { |
| 1530 | __rtl8169_check_link_status(dev, tp, ioaddr, false); |
| 1531 | } |
| 1532 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1533 | #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST) |
| 1534 | |
| 1535 | static u32 __rtl8169_get_wol(struct rtl8169_private *tp) |
| 1536 | { |
| 1537 | void __iomem *ioaddr = tp->mmio_addr; |
| 1538 | u8 options; |
| 1539 | u32 wolopts = 0; |
| 1540 | |
| 1541 | options = RTL_R8(Config1); |
| 1542 | if (!(options & PMEnable)) |
| 1543 | return 0; |
| 1544 | |
| 1545 | options = RTL_R8(Config3); |
| 1546 | if (options & LinkUp) |
| 1547 | wolopts |= WAKE_PHY; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1548 | switch (tp->mac_version) { |
Chun-Hao Lin | ac85bcd | 2014-10-01 23:17:16 +0800 | [diff] [blame] | 1549 | case RTL_GIGA_MAC_VER_34: |
| 1550 | case RTL_GIGA_MAC_VER_35: |
| 1551 | case RTL_GIGA_MAC_VER_36: |
| 1552 | case RTL_GIGA_MAC_VER_37: |
| 1553 | case RTL_GIGA_MAC_VER_38: |
| 1554 | case RTL_GIGA_MAC_VER_40: |
| 1555 | case RTL_GIGA_MAC_VER_41: |
| 1556 | case RTL_GIGA_MAC_VER_42: |
| 1557 | case RTL_GIGA_MAC_VER_43: |
| 1558 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1559 | case RTL_GIGA_MAC_VER_45: |
| 1560 | case RTL_GIGA_MAC_VER_46: |
Chun-Hao Lin | ac85bcd | 2014-10-01 23:17:16 +0800 | [diff] [blame] | 1561 | case RTL_GIGA_MAC_VER_47: |
| 1562 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1563 | if (rtl_eri_read(tp, 0xdc, ERIAR_EXGMAC) & MagicPacket_v2) |
| 1564 | wolopts |= WAKE_MAGIC; |
| 1565 | break; |
| 1566 | default: |
| 1567 | if (options & MagicPacket) |
| 1568 | wolopts |= WAKE_MAGIC; |
| 1569 | break; |
| 1570 | } |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1571 | |
| 1572 | options = RTL_R8(Config5); |
| 1573 | if (options & UWF) |
| 1574 | wolopts |= WAKE_UCAST; |
| 1575 | if (options & BWF) |
| 1576 | wolopts |= WAKE_BCAST; |
| 1577 | if (options & MWF) |
| 1578 | wolopts |= WAKE_MCAST; |
| 1579 | |
| 1580 | return wolopts; |
| 1581 | } |
| 1582 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1583 | static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1584 | { |
| 1585 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1586 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1587 | rtl_lock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1588 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1589 | wol->supported = WAKE_ANY; |
| 1590 | wol->wolopts = __rtl8169_get_wol(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1591 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1592 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1593 | } |
| 1594 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1595 | static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1596 | { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1597 | void __iomem *ioaddr = tp->mmio_addr; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1598 | unsigned int i, tmp; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 1599 | static const struct { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1600 | u32 opt; |
| 1601 | u16 reg; |
| 1602 | u8 mask; |
| 1603 | } cfg[] = { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1604 | { WAKE_PHY, Config3, LinkUp }, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1605 | { WAKE_UCAST, Config5, UWF }, |
| 1606 | { WAKE_BCAST, Config5, BWF }, |
| 1607 | { WAKE_MCAST, Config5, MWF }, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1608 | { WAKE_ANY, Config5, LanWake }, |
| 1609 | { WAKE_MAGIC, Config3, MagicPacket } |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1610 | }; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1611 | u8 options; |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1612 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1613 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 1614 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1615 | switch (tp->mac_version) { |
Chun-Hao Lin | ac85bcd | 2014-10-01 23:17:16 +0800 | [diff] [blame] | 1616 | case RTL_GIGA_MAC_VER_34: |
| 1617 | case RTL_GIGA_MAC_VER_35: |
| 1618 | case RTL_GIGA_MAC_VER_36: |
| 1619 | case RTL_GIGA_MAC_VER_37: |
| 1620 | case RTL_GIGA_MAC_VER_38: |
| 1621 | case RTL_GIGA_MAC_VER_40: |
| 1622 | case RTL_GIGA_MAC_VER_41: |
| 1623 | case RTL_GIGA_MAC_VER_42: |
| 1624 | case RTL_GIGA_MAC_VER_43: |
| 1625 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1626 | case RTL_GIGA_MAC_VER_45: |
| 1627 | case RTL_GIGA_MAC_VER_46: |
Chun-Hao Lin | ac85bcd | 2014-10-01 23:17:16 +0800 | [diff] [blame] | 1628 | case RTL_GIGA_MAC_VER_47: |
| 1629 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1630 | tmp = ARRAY_SIZE(cfg) - 1; |
| 1631 | if (wolopts & WAKE_MAGIC) |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame^] | 1632 | rtl_w0w1_eri(tp, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1633 | 0x0dc, |
| 1634 | ERIAR_MASK_0100, |
| 1635 | MagicPacket_v2, |
| 1636 | 0x0000, |
| 1637 | ERIAR_EXGMAC); |
| 1638 | else |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame^] | 1639 | rtl_w0w1_eri(tp, |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 1640 | 0x0dc, |
| 1641 | ERIAR_MASK_0100, |
| 1642 | 0x0000, |
| 1643 | MagicPacket_v2, |
| 1644 | ERIAR_EXGMAC); |
| 1645 | break; |
| 1646 | default: |
| 1647 | tmp = ARRAY_SIZE(cfg); |
| 1648 | break; |
| 1649 | } |
| 1650 | |
| 1651 | for (i = 0; i < tmp; i++) { |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1652 | options = RTL_R8(cfg[i].reg) & ~cfg[i].mask; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1653 | if (wolopts & cfg[i].opt) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1654 | options |= cfg[i].mask; |
| 1655 | RTL_W8(cfg[i].reg, options); |
| 1656 | } |
| 1657 | |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1658 | switch (tp->mac_version) { |
| 1659 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_17: |
| 1660 | options = RTL_R8(Config1) & ~PMEnable; |
| 1661 | if (wolopts) |
| 1662 | options |= PMEnable; |
| 1663 | RTL_W8(Config1, options); |
| 1664 | break; |
| 1665 | default: |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 1666 | options = RTL_R8(Config2) & ~PME_SIGNAL; |
| 1667 | if (wolopts) |
| 1668 | options |= PME_SIGNAL; |
| 1669 | RTL_W8(Config2, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1670 | break; |
| 1671 | } |
| 1672 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1673 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1674 | } |
| 1675 | |
| 1676 | static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1677 | { |
| 1678 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1679 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1680 | rtl_lock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1681 | |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 1682 | if (wol->wolopts) |
| 1683 | tp->features |= RTL_FEATURE_WOL; |
| 1684 | else |
| 1685 | tp->features &= ~RTL_FEATURE_WOL; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1686 | __rtl8169_set_wol(tp, wol->wolopts); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1687 | |
| 1688 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1689 | |
françois romieu | ea80907 | 2010-11-08 13:23:58 +0000 | [diff] [blame] | 1690 | device_set_wakeup_enable(&tp->pci_dev->dev, wol->wolopts); |
| 1691 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1692 | return 0; |
| 1693 | } |
| 1694 | |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1695 | static const char *rtl_lookup_firmware_name(struct rtl8169_private *tp) |
| 1696 | { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 1697 | return rtl_chip_infos[tp->mac_version].fw_name; |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1698 | } |
| 1699 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1700 | static void rtl8169_get_drvinfo(struct net_device *dev, |
| 1701 | struct ethtool_drvinfo *info) |
| 1702 | { |
| 1703 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 1704 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1705 | |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 1706 | strlcpy(info->driver, MODULENAME, sizeof(info->driver)); |
| 1707 | strlcpy(info->version, RTL8169_VERSION, sizeof(info->version)); |
| 1708 | 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] | 1709 | BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version)); |
Rick Jones | 8ac72d1 | 2011-11-22 14:06:26 +0000 | [diff] [blame] | 1710 | if (!IS_ERR_OR_NULL(rtl_fw)) |
| 1711 | strlcpy(info->fw_version, rtl_fw->version, |
| 1712 | sizeof(info->fw_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | } |
| 1714 | |
| 1715 | static int rtl8169_get_regs_len(struct net_device *dev) |
| 1716 | { |
| 1717 | return R8169_REGS_SIZE; |
| 1718 | } |
| 1719 | |
| 1720 | static int rtl8169_set_speed_tbi(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1721 | u8 autoneg, u16 speed, u8 duplex, u32 ignored) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | { |
| 1723 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1724 | void __iomem *ioaddr = tp->mmio_addr; |
| 1725 | int ret = 0; |
| 1726 | u32 reg; |
| 1727 | |
| 1728 | reg = RTL_R32(TBICSR); |
| 1729 | if ((autoneg == AUTONEG_DISABLE) && (speed == SPEED_1000) && |
| 1730 | (duplex == DUPLEX_FULL)) { |
| 1731 | RTL_W32(TBICSR, reg & ~(TBINwEnable | TBINwRestart)); |
| 1732 | } else if (autoneg == AUTONEG_ENABLE) |
| 1733 | RTL_W32(TBICSR, reg | TBINwEnable | TBINwRestart); |
| 1734 | else { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1735 | netif_warn(tp, link, dev, |
| 1736 | "incorrect speed setting refused in TBI mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1737 | ret = -EOPNOTSUPP; |
| 1738 | } |
| 1739 | |
| 1740 | return ret; |
| 1741 | } |
| 1742 | |
| 1743 | static int rtl8169_set_speed_xmii(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1744 | u8 autoneg, u16 speed, u8 duplex, u32 adv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | { |
| 1746 | struct rtl8169_private *tp = netdev_priv(dev); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1747 | int giga_ctrl, bmcr; |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1748 | int rc = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1749 | |
Hayes Wang | 716b50a | 2011-02-22 17:26:18 +0800 | [diff] [blame] | 1750 | rtl_writephy(tp, 0x1f, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1751 | |
| 1752 | if (autoneg == AUTONEG_ENABLE) { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1753 | int auto_nego; |
| 1754 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1755 | auto_nego = rtl_readphy(tp, MII_ADVERTISE); |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1756 | auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL | |
| 1757 | ADVERTISE_100HALF | ADVERTISE_100FULL); |
| 1758 | |
| 1759 | if (adv & ADVERTISED_10baseT_Half) |
| 1760 | auto_nego |= ADVERTISE_10HALF; |
| 1761 | if (adv & ADVERTISED_10baseT_Full) |
| 1762 | auto_nego |= ADVERTISE_10FULL; |
| 1763 | if (adv & ADVERTISED_100baseT_Half) |
| 1764 | auto_nego |= ADVERTISE_100HALF; |
| 1765 | if (adv & ADVERTISED_100baseT_Full) |
| 1766 | auto_nego |= ADVERTISE_100FULL; |
| 1767 | |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1768 | auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 1769 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1770 | giga_ctrl = rtl_readphy(tp, MII_CTRL1000); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1771 | giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); |
| 1772 | |
| 1773 | /* The 8100e/8101e/8102e do Fast Ethernet only. */ |
Francois Romieu | 826e6cb | 2011-03-11 20:30:24 +0100 | [diff] [blame] | 1774 | if (tp->mii.supports_gmii) { |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1775 | if (adv & ADVERTISED_1000baseT_Half) |
| 1776 | giga_ctrl |= ADVERTISE_1000HALF; |
| 1777 | if (adv & ADVERTISED_1000baseT_Full) |
| 1778 | giga_ctrl |= ADVERTISE_1000FULL; |
| 1779 | } else if (adv & (ADVERTISED_1000baseT_Half | |
| 1780 | ADVERTISED_1000baseT_Full)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1781 | netif_info(tp, link, dev, |
| 1782 | "PHY does not support 1000Mbps\n"); |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1783 | goto out; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 1784 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1785 | |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1786 | bmcr = BMCR_ANENABLE | BMCR_ANRESTART; |
Francois Romieu | 623a159 | 2006-05-14 12:42:14 +0200 | [diff] [blame] | 1787 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1788 | rtl_writephy(tp, MII_ADVERTISE, auto_nego); |
| 1789 | rtl_writephy(tp, MII_CTRL1000, giga_ctrl); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1790 | } else { |
| 1791 | giga_ctrl = 0; |
| 1792 | |
| 1793 | if (speed == SPEED_10) |
| 1794 | bmcr = 0; |
| 1795 | else if (speed == SPEED_100) |
| 1796 | bmcr = BMCR_SPEED100; |
| 1797 | else |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1798 | goto out; |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1799 | |
| 1800 | if (duplex == DUPLEX_FULL) |
| 1801 | bmcr |= BMCR_FULLDPLX; |
Roger So | 2584fbc | 2007-07-31 23:52:42 +0200 | [diff] [blame] | 1802 | } |
| 1803 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1804 | rtl_writephy(tp, MII_BMCR, bmcr); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1805 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1806 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 1807 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1808 | if ((speed == SPEED_100) && (autoneg != AUTONEG_ENABLE)) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1809 | rtl_writephy(tp, 0x17, 0x2138); |
| 1810 | rtl_writephy(tp, 0x0e, 0x0260); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1811 | } else { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1812 | rtl_writephy(tp, 0x17, 0x2108); |
| 1813 | rtl_writephy(tp, 0x0e, 0x0000); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1814 | } |
| 1815 | } |
| 1816 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1817 | rc = 0; |
| 1818 | out: |
| 1819 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | } |
| 1821 | |
| 1822 | static int rtl8169_set_speed(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1823 | u8 autoneg, u16 speed, u8 duplex, u32 advertising) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1824 | { |
| 1825 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1826 | int ret; |
| 1827 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1828 | ret = tp->set_speed(dev, autoneg, speed, duplex, advertising); |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1829 | if (ret < 0) |
| 1830 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1831 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1832 | if (netif_running(dev) && (autoneg == AUTONEG_ENABLE) && |
| 1833 | (advertising & ADVERTISED_1000baseT_Full)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | mod_timer(&tp->timer, jiffies + RTL8169_PHY_TIMEOUT); |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1835 | } |
| 1836 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1837 | return ret; |
| 1838 | } |
| 1839 | |
| 1840 | static int rtl8169_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 1841 | { |
| 1842 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1843 | int ret; |
| 1844 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1845 | del_timer_sync(&tp->timer); |
| 1846 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1847 | rtl_lock_work(tp); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1848 | ret = rtl8169_set_speed(dev, cmd->autoneg, ethtool_cmd_speed(cmd), |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 1849 | cmd->duplex, cmd->advertising); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1850 | rtl_unlock_work(tp); |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1851 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1852 | return ret; |
| 1853 | } |
| 1854 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 1855 | static netdev_features_t rtl8169_fix_features(struct net_device *dev, |
| 1856 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1857 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1858 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1859 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 1860 | if (dev->mtu > TD_MSS_MAX) |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1861 | features &= ~NETIF_F_ALL_TSO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1863 | if (dev->mtu > JUMBO_1K && |
| 1864 | !rtl_chip_infos[tp->mac_version].jumbo_tx_csum) |
| 1865 | features &= ~NETIF_F_IP_CSUM; |
| 1866 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1867 | return features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1868 | } |
| 1869 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1870 | static void __rtl8169_set_features(struct net_device *dev, |
| 1871 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1872 | { |
| 1873 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1874 | void __iomem *ioaddr = tp->mmio_addr; |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1875 | u32 rx_config; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1876 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1877 | rx_config = RTL_R32(RxConfig); |
| 1878 | if (features & NETIF_F_RXALL) |
| 1879 | rx_config |= (AcceptErr | AcceptRunt); |
| 1880 | else |
| 1881 | rx_config &= ~(AcceptErr | AcceptRunt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1882 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1883 | RTL_W32(RxConfig, rx_config); |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1884 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1885 | if (features & NETIF_F_RXCSUM) |
| 1886 | tp->cp_cmd |= RxChkSum; |
| 1887 | else |
| 1888 | tp->cp_cmd &= ~RxChkSum; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 1889 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1890 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
| 1891 | tp->cp_cmd |= RxVlan; |
| 1892 | else |
| 1893 | tp->cp_cmd &= ~RxVlan; |
| 1894 | |
| 1895 | tp->cp_cmd |= RTL_R16(CPlusCmd) & ~(RxVlan | RxChkSum); |
| 1896 | |
| 1897 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 1898 | RTL_R16(CPlusCmd); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1899 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1901 | static int rtl8169_set_features(struct net_device *dev, |
| 1902 | netdev_features_t features) |
| 1903 | { |
| 1904 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1905 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1906 | features &= NETIF_F_RXALL | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_RX; |
| 1907 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1908 | rtl_lock_work(tp); |
Dan Carpenter | 85911d7 | 2014-09-19 13:40:25 +0300 | [diff] [blame] | 1909 | if (features ^ dev->features) |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 1910 | __rtl8169_set_features(dev, features); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1911 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1912 | |
| 1913 | return 0; |
| 1914 | } |
| 1915 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1916 | |
Kirill Smelkov | 810f489 | 2012-11-10 21:11:02 +0400 | [diff] [blame] | 1917 | static inline u32 rtl8169_tx_vlan_tag(struct sk_buff *skb) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1918 | { |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 1919 | return (vlan_tx_tag_present(skb)) ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | TxVlanTag | swab16(vlan_tx_tag_get(skb)) : 0x00; |
| 1921 | } |
| 1922 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1923 | 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] | 1924 | { |
| 1925 | u32 opts2 = le32_to_cpu(desc->opts2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1926 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1927 | if (opts2 & RxVlanTag) |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 1928 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), swab16(opts2 & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | } |
| 1930 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1931 | static int rtl8169_gset_tbi(struct net_device *dev, struct ethtool_cmd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1932 | { |
| 1933 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1934 | void __iomem *ioaddr = tp->mmio_addr; |
| 1935 | u32 status; |
| 1936 | |
| 1937 | cmd->supported = |
| 1938 | SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE; |
| 1939 | cmd->port = PORT_FIBRE; |
| 1940 | cmd->transceiver = XCVR_INTERNAL; |
| 1941 | |
| 1942 | status = RTL_R32(TBICSR); |
| 1943 | cmd->advertising = (status & TBINwEnable) ? ADVERTISED_Autoneg : 0; |
| 1944 | cmd->autoneg = !!(status & TBINwEnable); |
| 1945 | |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 1946 | ethtool_cmd_speed_set(cmd, SPEED_1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1947 | cmd->duplex = DUPLEX_FULL; /* Always set */ |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1948 | |
| 1949 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1950 | } |
| 1951 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1952 | static int rtl8169_gset_xmii(struct net_device *dev, struct ethtool_cmd *cmd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1953 | { |
| 1954 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1956 | return mii_ethtool_gset(&tp->mii, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1957 | } |
| 1958 | |
| 1959 | static int rtl8169_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 1960 | { |
| 1961 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1962 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1964 | rtl_lock_work(tp); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1965 | rc = tp->get_settings(dev, cmd); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1966 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1968 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1969 | } |
| 1970 | |
| 1971 | static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 1972 | void *p) |
| 1973 | { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1974 | struct rtl8169_private *tp = netdev_priv(dev); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 1975 | u32 __iomem *data = tp->mmio_addr; |
| 1976 | u32 *dw = p; |
| 1977 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1978 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1979 | rtl_lock_work(tp); |
Peter Wu | 15edae9 | 2013-08-21 23:17:11 +0200 | [diff] [blame] | 1980 | for (i = 0; i < R8169_REGS_SIZE; i += 4) |
| 1981 | memcpy_fromio(dw++, data++, 4); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1982 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | } |
| 1984 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1985 | static u32 rtl8169_get_msglevel(struct net_device *dev) |
| 1986 | { |
| 1987 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1988 | |
| 1989 | return tp->msg_enable; |
| 1990 | } |
| 1991 | |
| 1992 | static void rtl8169_set_msglevel(struct net_device *dev, u32 value) |
| 1993 | { |
| 1994 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1995 | |
| 1996 | tp->msg_enable = value; |
| 1997 | } |
| 1998 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1999 | static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = { |
| 2000 | "tx_packets", |
| 2001 | "rx_packets", |
| 2002 | "tx_errors", |
| 2003 | "rx_errors", |
| 2004 | "rx_missed", |
| 2005 | "align_errors", |
| 2006 | "tx_single_collisions", |
| 2007 | "tx_multi_collisions", |
| 2008 | "unicast", |
| 2009 | "broadcast", |
| 2010 | "multicast", |
| 2011 | "tx_aborted", |
| 2012 | "tx_underrun", |
| 2013 | }; |
| 2014 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2015 | static int rtl8169_get_sset_count(struct net_device *dev, int sset) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2016 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2017 | switch (sset) { |
| 2018 | case ETH_SS_STATS: |
| 2019 | return ARRAY_SIZE(rtl8169_gstrings); |
| 2020 | default: |
| 2021 | return -EOPNOTSUPP; |
| 2022 | } |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2023 | } |
| 2024 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 2025 | DECLARE_RTL_COND(rtl_counters_cond) |
| 2026 | { |
| 2027 | void __iomem *ioaddr = tp->mmio_addr; |
| 2028 | |
| 2029 | return RTL_R32(CounterAddrLow) & CounterDump; |
| 2030 | } |
| 2031 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2032 | static void rtl8169_update_counters(struct net_device *dev) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2033 | { |
| 2034 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2035 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2036 | struct device *d = &tp->pci_dev->dev; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2037 | struct rtl8169_counters *counters; |
| 2038 | dma_addr_t paddr; |
| 2039 | u32 cmd; |
| 2040 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2041 | /* |
| 2042 | * Some chips are unable to dump tally counters when the receiver |
| 2043 | * is disabled. |
| 2044 | */ |
| 2045 | if ((RTL_R8(ChipCmd) & CmdRxEnb) == 0) |
| 2046 | return; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2047 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 2048 | counters = dma_alloc_coherent(d, sizeof(*counters), &paddr, GFP_KERNEL); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2049 | if (!counters) |
| 2050 | return; |
| 2051 | |
| 2052 | RTL_W32(CounterAddrHigh, (u64)paddr >> 32); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2053 | cmd = (u64)paddr & DMA_BIT_MASK(32); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2054 | RTL_W32(CounterAddrLow, cmd); |
| 2055 | RTL_W32(CounterAddrLow, cmd | CounterDump); |
| 2056 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 2057 | if (rtl_udelay_loop_wait_low(tp, &rtl_counters_cond, 10, 1000)) |
| 2058 | memcpy(&tp->counters, counters, sizeof(*counters)); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2059 | |
| 2060 | RTL_W32(CounterAddrLow, 0); |
| 2061 | RTL_W32(CounterAddrHigh, 0); |
| 2062 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 2063 | dma_free_coherent(d, sizeof(*counters), counters, paddr); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2064 | } |
| 2065 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 2066 | static void rtl8169_get_ethtool_stats(struct net_device *dev, |
| 2067 | struct ethtool_stats *stats, u64 *data) |
| 2068 | { |
| 2069 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2070 | |
| 2071 | ASSERT_RTNL(); |
| 2072 | |
| 2073 | rtl8169_update_counters(dev); |
| 2074 | |
| 2075 | data[0] = le64_to_cpu(tp->counters.tx_packets); |
| 2076 | data[1] = le64_to_cpu(tp->counters.rx_packets); |
| 2077 | data[2] = le64_to_cpu(tp->counters.tx_errors); |
| 2078 | data[3] = le32_to_cpu(tp->counters.rx_errors); |
| 2079 | data[4] = le16_to_cpu(tp->counters.rx_missed); |
| 2080 | data[5] = le16_to_cpu(tp->counters.align_errors); |
| 2081 | data[6] = le32_to_cpu(tp->counters.tx_one_collision); |
| 2082 | data[7] = le32_to_cpu(tp->counters.tx_multi_collision); |
| 2083 | data[8] = le64_to_cpu(tp->counters.rx_unicast); |
| 2084 | data[9] = le64_to_cpu(tp->counters.rx_broadcast); |
| 2085 | data[10] = le32_to_cpu(tp->counters.rx_multicast); |
| 2086 | data[11] = le16_to_cpu(tp->counters.tx_aborted); |
| 2087 | data[12] = le16_to_cpu(tp->counters.tx_underun); |
| 2088 | } |
| 2089 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2090 | static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 2091 | { |
| 2092 | switch(stringset) { |
| 2093 | case ETH_SS_STATS: |
| 2094 | memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings)); |
| 2095 | break; |
| 2096 | } |
| 2097 | } |
| 2098 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 2099 | static const struct ethtool_ops rtl8169_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | .get_drvinfo = rtl8169_get_drvinfo, |
| 2101 | .get_regs_len = rtl8169_get_regs_len, |
| 2102 | .get_link = ethtool_op_get_link, |
| 2103 | .get_settings = rtl8169_get_settings, |
| 2104 | .set_settings = rtl8169_set_settings, |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 2105 | .get_msglevel = rtl8169_get_msglevel, |
| 2106 | .set_msglevel = rtl8169_set_msglevel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2107 | .get_regs = rtl8169_get_regs, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 2108 | .get_wol = rtl8169_get_wol, |
| 2109 | .set_wol = rtl8169_set_wol, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2110 | .get_strings = rtl8169_get_strings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2111 | .get_sset_count = rtl8169_get_sset_count, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2112 | .get_ethtool_stats = rtl8169_get_ethtool_stats, |
Richard Cochran | e1593bb | 2012-04-03 22:59:35 +0000 | [diff] [blame] | 2113 | .get_ts_info = ethtool_op_get_ts_info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2114 | }; |
| 2115 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 2116 | static void rtl8169_get_mac_version(struct rtl8169_private *tp, |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2117 | struct net_device *dev, u8 default_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2118 | { |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2119 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2120 | /* |
| 2121 | * The driver currently handles the 8168Bf and the 8168Be identically |
| 2122 | * but they can be identified more specifically through the test below |
| 2123 | * if needed: |
| 2124 | * |
| 2125 | * (RTL_R32(TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be |
Francois Romieu | 0127215 | 2007-02-20 22:58:51 +0100 | [diff] [blame] | 2126 | * |
| 2127 | * Same thing for the 8101Eb and the 8101Ec: |
| 2128 | * |
| 2129 | * (RTL_R32(TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2130 | */ |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2131 | static const struct rtl_mac_info { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2132 | u32 mask; |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2133 | u32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | int mac_version; |
| 2135 | } mac_info[] = { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2136 | /* 8168H family. */ |
| 2137 | { 0x7cf00000, 0x54100000, RTL_GIGA_MAC_VER_46 }, |
| 2138 | { 0x7cf00000, 0x54000000, RTL_GIGA_MAC_VER_45 }, |
| 2139 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2140 | /* 8168G family. */ |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 2141 | { 0x7cf00000, 0x5c800000, RTL_GIGA_MAC_VER_44 }, |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 2142 | { 0x7cf00000, 0x50900000, RTL_GIGA_MAC_VER_42 }, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2143 | { 0x7cf00000, 0x4c100000, RTL_GIGA_MAC_VER_41 }, |
| 2144 | { 0x7cf00000, 0x4c000000, RTL_GIGA_MAC_VER_40 }, |
| 2145 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2146 | /* 8168F family. */ |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 2147 | { 0x7c800000, 0x48800000, RTL_GIGA_MAC_VER_38 }, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2148 | { 0x7cf00000, 0x48100000, RTL_GIGA_MAC_VER_36 }, |
| 2149 | { 0x7cf00000, 0x48000000, RTL_GIGA_MAC_VER_35 }, |
| 2150 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2151 | /* 8168E family. */ |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2152 | { 0x7c800000, 0x2c800000, RTL_GIGA_MAC_VER_34 }, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2153 | { 0x7cf00000, 0x2c200000, RTL_GIGA_MAC_VER_33 }, |
| 2154 | { 0x7cf00000, 0x2c100000, RTL_GIGA_MAC_VER_32 }, |
| 2155 | { 0x7c800000, 0x2c000000, RTL_GIGA_MAC_VER_33 }, |
| 2156 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2157 | /* 8168D family. */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2158 | { 0x7cf00000, 0x28300000, RTL_GIGA_MAC_VER_26 }, |
| 2159 | { 0x7cf00000, 0x28100000, RTL_GIGA_MAC_VER_25 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2160 | { 0x7c800000, 0x28000000, RTL_GIGA_MAC_VER_26 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2161 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2162 | /* 8168DP family. */ |
| 2163 | { 0x7cf00000, 0x28800000, RTL_GIGA_MAC_VER_27 }, |
| 2164 | { 0x7cf00000, 0x28a00000, RTL_GIGA_MAC_VER_28 }, |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 2165 | { 0x7cf00000, 0x28b00000, RTL_GIGA_MAC_VER_31 }, |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2166 | |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2167 | /* 8168C family. */ |
Francois Romieu | 17c9929 | 2010-07-11 17:10:09 -0700 | [diff] [blame] | 2168 | { 0x7cf00000, 0x3cb00000, RTL_GIGA_MAC_VER_24 }, |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2169 | { 0x7cf00000, 0x3c900000, RTL_GIGA_MAC_VER_23 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2170 | { 0x7cf00000, 0x3c800000, RTL_GIGA_MAC_VER_18 }, |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 2171 | { 0x7c800000, 0x3c800000, RTL_GIGA_MAC_VER_24 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2172 | { 0x7cf00000, 0x3c000000, RTL_GIGA_MAC_VER_19 }, |
| 2173 | { 0x7cf00000, 0x3c200000, RTL_GIGA_MAC_VER_20 }, |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2174 | { 0x7cf00000, 0x3c300000, RTL_GIGA_MAC_VER_21 }, |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2175 | { 0x7cf00000, 0x3c400000, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2176 | { 0x7c800000, 0x3c000000, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2177 | |
| 2178 | /* 8168B family. */ |
| 2179 | { 0x7cf00000, 0x38000000, RTL_GIGA_MAC_VER_12 }, |
| 2180 | { 0x7cf00000, 0x38500000, RTL_GIGA_MAC_VER_17 }, |
| 2181 | { 0x7c800000, 0x38000000, RTL_GIGA_MAC_VER_17 }, |
| 2182 | { 0x7c800000, 0x30000000, RTL_GIGA_MAC_VER_11 }, |
| 2183 | |
| 2184 | /* 8101 family. */ |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 2185 | { 0x7cf00000, 0x44900000, RTL_GIGA_MAC_VER_39 }, |
| 2186 | { 0x7c800000, 0x44800000, RTL_GIGA_MAC_VER_39 }, |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 2187 | { 0x7c800000, 0x44000000, RTL_GIGA_MAC_VER_37 }, |
hayeswang | 36a0e6c | 2011-03-21 01:50:30 +0000 | [diff] [blame] | 2188 | { 0x7cf00000, 0x40b00000, RTL_GIGA_MAC_VER_30 }, |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 2189 | { 0x7cf00000, 0x40a00000, RTL_GIGA_MAC_VER_30 }, |
| 2190 | { 0x7cf00000, 0x40900000, RTL_GIGA_MAC_VER_29 }, |
| 2191 | { 0x7c800000, 0x40800000, RTL_GIGA_MAC_VER_30 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2192 | { 0x7cf00000, 0x34a00000, RTL_GIGA_MAC_VER_09 }, |
| 2193 | { 0x7cf00000, 0x24a00000, RTL_GIGA_MAC_VER_09 }, |
| 2194 | { 0x7cf00000, 0x34900000, RTL_GIGA_MAC_VER_08 }, |
| 2195 | { 0x7cf00000, 0x24900000, RTL_GIGA_MAC_VER_08 }, |
| 2196 | { 0x7cf00000, 0x34800000, RTL_GIGA_MAC_VER_07 }, |
| 2197 | { 0x7cf00000, 0x24800000, RTL_GIGA_MAC_VER_07 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2198 | { 0x7cf00000, 0x34000000, RTL_GIGA_MAC_VER_13 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2199 | { 0x7cf00000, 0x34300000, RTL_GIGA_MAC_VER_10 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2200 | { 0x7cf00000, 0x34200000, RTL_GIGA_MAC_VER_16 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2201 | { 0x7c800000, 0x34800000, RTL_GIGA_MAC_VER_09 }, |
| 2202 | { 0x7c800000, 0x24800000, RTL_GIGA_MAC_VER_09 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2203 | { 0x7c800000, 0x34000000, RTL_GIGA_MAC_VER_16 }, |
| 2204 | /* FIXME: where did these entries come from ? -- FR */ |
| 2205 | { 0xfc800000, 0x38800000, RTL_GIGA_MAC_VER_15 }, |
| 2206 | { 0xfc800000, 0x30800000, RTL_GIGA_MAC_VER_14 }, |
| 2207 | |
| 2208 | /* 8110 family. */ |
| 2209 | { 0xfc800000, 0x98000000, RTL_GIGA_MAC_VER_06 }, |
| 2210 | { 0xfc800000, 0x18000000, RTL_GIGA_MAC_VER_05 }, |
| 2211 | { 0xfc800000, 0x10000000, RTL_GIGA_MAC_VER_04 }, |
| 2212 | { 0xfc800000, 0x04000000, RTL_GIGA_MAC_VER_03 }, |
| 2213 | { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 }, |
| 2214 | { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 }, |
| 2215 | |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 2216 | /* Catch-all */ |
| 2217 | { 0x00000000, 0x00000000, RTL_GIGA_MAC_NONE } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2218 | }; |
| 2219 | const struct rtl_mac_info *p = mac_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2220 | u32 reg; |
| 2221 | |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2222 | reg = RTL_R32(TxConfig); |
| 2223 | while ((reg & p->mask) != p->val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2224 | p++; |
| 2225 | tp->mac_version = p->mac_version; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2226 | |
| 2227 | if (tp->mac_version == RTL_GIGA_MAC_NONE) { |
| 2228 | netif_notice(tp, probe, dev, |
| 2229 | "unknown MAC, using family default\n"); |
| 2230 | tp->mac_version = default_version; |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 2231 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_42) { |
| 2232 | tp->mac_version = tp->mii.supports_gmii ? |
| 2233 | RTL_GIGA_MAC_VER_42 : |
| 2234 | RTL_GIGA_MAC_VER_43; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 2235 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_45) { |
| 2236 | tp->mac_version = tp->mii.supports_gmii ? |
| 2237 | RTL_GIGA_MAC_VER_45 : |
| 2238 | RTL_GIGA_MAC_VER_47; |
| 2239 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_46) { |
| 2240 | tp->mac_version = tp->mii.supports_gmii ? |
| 2241 | RTL_GIGA_MAC_VER_46 : |
| 2242 | RTL_GIGA_MAC_VER_48; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2243 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2244 | } |
| 2245 | |
| 2246 | static void rtl8169_print_mac_version(struct rtl8169_private *tp) |
| 2247 | { |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 2248 | dprintk("mac_version = 0x%02x\n", tp->mac_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2249 | } |
| 2250 | |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2251 | struct phy_reg { |
| 2252 | u16 reg; |
| 2253 | u16 val; |
| 2254 | }; |
| 2255 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2256 | static void rtl_writephy_batch(struct rtl8169_private *tp, |
| 2257 | const struct phy_reg *regs, int len) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2258 | { |
| 2259 | while (len-- > 0) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2260 | rtl_writephy(tp, regs->reg, regs->val); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2261 | regs++; |
| 2262 | } |
| 2263 | } |
| 2264 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2265 | #define PHY_READ 0x00000000 |
| 2266 | #define PHY_DATA_OR 0x10000000 |
| 2267 | #define PHY_DATA_AND 0x20000000 |
| 2268 | #define PHY_BJMPN 0x30000000 |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2269 | #define PHY_MDIO_CHG 0x40000000 |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2270 | #define PHY_CLEAR_READCOUNT 0x70000000 |
| 2271 | #define PHY_WRITE 0x80000000 |
| 2272 | #define PHY_READCOUNT_EQ_SKIP 0x90000000 |
| 2273 | #define PHY_COMP_EQ_SKIPN 0xa0000000 |
| 2274 | #define PHY_COMP_NEQ_SKIPN 0xb0000000 |
| 2275 | #define PHY_WRITE_PREVIOUS 0xc0000000 |
| 2276 | #define PHY_SKIPN 0xd0000000 |
| 2277 | #define PHY_DELAY_MS 0xe0000000 |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2278 | |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2279 | struct fw_info { |
| 2280 | u32 magic; |
| 2281 | char version[RTL_VER_SIZE]; |
| 2282 | __le32 fw_start; |
| 2283 | __le32 fw_len; |
| 2284 | u8 chksum; |
| 2285 | } __packed; |
| 2286 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2287 | #define FW_OPCODE_SIZE sizeof(typeof(*((struct rtl_fw_phy_action *)0)->code)) |
| 2288 | |
| 2289 | 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] | 2290 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2291 | const struct firmware *fw = rtl_fw->fw; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2292 | struct fw_info *fw_info = (struct fw_info *)fw->data; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2293 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
| 2294 | char *version = rtl_fw->version; |
| 2295 | bool rc = false; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2296 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2297 | if (fw->size < FW_OPCODE_SIZE) |
| 2298 | goto out; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2299 | |
| 2300 | if (!fw_info->magic) { |
| 2301 | size_t i, size, start; |
| 2302 | u8 checksum = 0; |
| 2303 | |
| 2304 | if (fw->size < sizeof(*fw_info)) |
| 2305 | goto out; |
| 2306 | |
| 2307 | for (i = 0; i < fw->size; i++) |
| 2308 | checksum += fw->data[i]; |
| 2309 | if (checksum != 0) |
| 2310 | goto out; |
| 2311 | |
| 2312 | start = le32_to_cpu(fw_info->fw_start); |
| 2313 | if (start > fw->size) |
| 2314 | goto out; |
| 2315 | |
| 2316 | size = le32_to_cpu(fw_info->fw_len); |
| 2317 | if (size > (fw->size - start) / FW_OPCODE_SIZE) |
| 2318 | goto out; |
| 2319 | |
| 2320 | memcpy(version, fw_info->version, RTL_VER_SIZE); |
| 2321 | |
| 2322 | pa->code = (__le32 *)(fw->data + start); |
| 2323 | pa->size = size; |
| 2324 | } else { |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2325 | if (fw->size % FW_OPCODE_SIZE) |
| 2326 | goto out; |
| 2327 | |
| 2328 | strlcpy(version, rtl_lookup_firmware_name(tp), RTL_VER_SIZE); |
| 2329 | |
| 2330 | pa->code = (__le32 *)fw->data; |
| 2331 | pa->size = fw->size / FW_OPCODE_SIZE; |
| 2332 | } |
| 2333 | version[RTL_VER_SIZE - 1] = 0; |
| 2334 | |
| 2335 | rc = true; |
| 2336 | out: |
| 2337 | return rc; |
| 2338 | } |
| 2339 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2340 | static bool rtl_fw_data_ok(struct rtl8169_private *tp, struct net_device *dev, |
| 2341 | struct rtl_fw_phy_action *pa) |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2342 | { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2343 | bool rc = false; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2344 | size_t index; |
| 2345 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2346 | for (index = 0; index < pa->size; index++) { |
| 2347 | u32 action = le32_to_cpu(pa->code[index]); |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2348 | u32 regno = (action & 0x0fff0000) >> 16; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2349 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2350 | switch(action & 0xf0000000) { |
| 2351 | case PHY_READ: |
| 2352 | case PHY_DATA_OR: |
| 2353 | case PHY_DATA_AND: |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2354 | case PHY_MDIO_CHG: |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2355 | case PHY_CLEAR_READCOUNT: |
| 2356 | case PHY_WRITE: |
| 2357 | case PHY_WRITE_PREVIOUS: |
| 2358 | case PHY_DELAY_MS: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2359 | break; |
| 2360 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2361 | case PHY_BJMPN: |
| 2362 | if (regno > index) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2363 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2364 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2365 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2366 | } |
| 2367 | break; |
| 2368 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2369 | if (index + 2 >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2370 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2371 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2372 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2373 | } |
| 2374 | break; |
| 2375 | case PHY_COMP_EQ_SKIPN: |
| 2376 | case PHY_COMP_NEQ_SKIPN: |
| 2377 | case PHY_SKIPN: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2378 | if (index + 1 + regno >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2379 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2380 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2381 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2382 | } |
| 2383 | break; |
| 2384 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2385 | default: |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2386 | netif_err(tp, ifup, tp->dev, |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2387 | "Invalid action 0x%08x\n", action); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2388 | goto out; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2389 | } |
| 2390 | } |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2391 | rc = true; |
| 2392 | out: |
| 2393 | return rc; |
| 2394 | } |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2395 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2396 | static int rtl_check_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2397 | { |
| 2398 | struct net_device *dev = tp->dev; |
| 2399 | int rc = -EINVAL; |
| 2400 | |
| 2401 | if (!rtl_fw_format_ok(tp, rtl_fw)) { |
| 2402 | netif_err(tp, ifup, dev, "invalid firwmare\n"); |
| 2403 | goto out; |
| 2404 | } |
| 2405 | |
| 2406 | if (rtl_fw_data_ok(tp, dev, &rtl_fw->phy_action)) |
| 2407 | rc = 0; |
| 2408 | out: |
| 2409 | return rc; |
| 2410 | } |
| 2411 | |
| 2412 | static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2413 | { |
| 2414 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2415 | struct mdio_ops org, *ops = &tp->mdio_ops; |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2416 | u32 predata, count; |
| 2417 | size_t index; |
| 2418 | |
| 2419 | predata = count = 0; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2420 | org.write = ops->write; |
| 2421 | org.read = ops->read; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2422 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2423 | for (index = 0; index < pa->size; ) { |
| 2424 | u32 action = le32_to_cpu(pa->code[index]); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2425 | u32 data = action & 0x0000ffff; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2426 | u32 regno = (action & 0x0fff0000) >> 16; |
| 2427 | |
| 2428 | if (!action) |
| 2429 | break; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2430 | |
| 2431 | switch(action & 0xf0000000) { |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2432 | case PHY_READ: |
| 2433 | predata = rtl_readphy(tp, regno); |
| 2434 | count++; |
| 2435 | index++; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2436 | break; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2437 | case PHY_DATA_OR: |
| 2438 | predata |= data; |
| 2439 | index++; |
| 2440 | break; |
| 2441 | case PHY_DATA_AND: |
| 2442 | predata &= data; |
| 2443 | index++; |
| 2444 | break; |
| 2445 | case PHY_BJMPN: |
| 2446 | index -= regno; |
| 2447 | break; |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2448 | case PHY_MDIO_CHG: |
| 2449 | if (data == 0) { |
| 2450 | ops->write = org.write; |
| 2451 | ops->read = org.read; |
| 2452 | } else if (data == 1) { |
| 2453 | ops->write = mac_mcu_write; |
| 2454 | ops->read = mac_mcu_read; |
| 2455 | } |
| 2456 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2457 | index++; |
| 2458 | break; |
| 2459 | case PHY_CLEAR_READCOUNT: |
| 2460 | count = 0; |
| 2461 | index++; |
| 2462 | break; |
| 2463 | case PHY_WRITE: |
| 2464 | rtl_writephy(tp, regno, data); |
| 2465 | index++; |
| 2466 | break; |
| 2467 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2468 | index += (count == data) ? 2 : 1; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2469 | break; |
| 2470 | case PHY_COMP_EQ_SKIPN: |
| 2471 | if (predata == data) |
| 2472 | index += regno; |
| 2473 | index++; |
| 2474 | break; |
| 2475 | case PHY_COMP_NEQ_SKIPN: |
| 2476 | if (predata != data) |
| 2477 | index += regno; |
| 2478 | index++; |
| 2479 | break; |
| 2480 | case PHY_WRITE_PREVIOUS: |
| 2481 | rtl_writephy(tp, regno, predata); |
| 2482 | index++; |
| 2483 | break; |
| 2484 | case PHY_SKIPN: |
| 2485 | index += regno + 1; |
| 2486 | break; |
| 2487 | case PHY_DELAY_MS: |
| 2488 | mdelay(data); |
| 2489 | index++; |
| 2490 | break; |
| 2491 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2492 | default: |
| 2493 | BUG(); |
| 2494 | } |
| 2495 | } |
hayeswang | eee3786 | 2013-04-01 22:23:38 +0000 | [diff] [blame] | 2496 | |
| 2497 | ops->write = org.write; |
| 2498 | ops->read = org.read; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2499 | } |
| 2500 | |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2501 | static void rtl_release_firmware(struct rtl8169_private *tp) |
| 2502 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2503 | if (!IS_ERR_OR_NULL(tp->rtl_fw)) { |
| 2504 | release_firmware(tp->rtl_fw->fw); |
| 2505 | kfree(tp->rtl_fw); |
| 2506 | } |
| 2507 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2508 | } |
| 2509 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2510 | static void rtl_apply_firmware(struct rtl8169_private *tp) |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2511 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2512 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2513 | |
| 2514 | /* TODO: release firmware once rtl_phy_write_fw signals failures. */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 2515 | if (!IS_ERR_OR_NULL(rtl_fw)) |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2516 | rtl_phy_write_fw(tp, rtl_fw); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2517 | } |
| 2518 | |
| 2519 | static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val) |
| 2520 | { |
| 2521 | if (rtl_readphy(tp, reg) != val) |
| 2522 | netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n"); |
| 2523 | else |
| 2524 | rtl_apply_firmware(tp); |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2525 | } |
| 2526 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2527 | static void rtl8169s_hw_phy_config(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2528 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2529 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2530 | { 0x1f, 0x0001 }, |
| 2531 | { 0x06, 0x006e }, |
| 2532 | { 0x08, 0x0708 }, |
| 2533 | { 0x15, 0x4000 }, |
| 2534 | { 0x18, 0x65c7 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2535 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2536 | { 0x1f, 0x0001 }, |
| 2537 | { 0x03, 0x00a1 }, |
| 2538 | { 0x02, 0x0008 }, |
| 2539 | { 0x01, 0x0120 }, |
| 2540 | { 0x00, 0x1000 }, |
| 2541 | { 0x04, 0x0800 }, |
| 2542 | { 0x04, 0x0000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2543 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2544 | { 0x03, 0xff41 }, |
| 2545 | { 0x02, 0xdf60 }, |
| 2546 | { 0x01, 0x0140 }, |
| 2547 | { 0x00, 0x0077 }, |
| 2548 | { 0x04, 0x7800 }, |
| 2549 | { 0x04, 0x7000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2550 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2551 | { 0x03, 0x802f }, |
| 2552 | { 0x02, 0x4f02 }, |
| 2553 | { 0x01, 0x0409 }, |
| 2554 | { 0x00, 0xf0f9 }, |
| 2555 | { 0x04, 0x9800 }, |
| 2556 | { 0x04, 0x9000 }, |
| 2557 | |
| 2558 | { 0x03, 0xdf01 }, |
| 2559 | { 0x02, 0xdf20 }, |
| 2560 | { 0x01, 0xff95 }, |
| 2561 | { 0x00, 0xba00 }, |
| 2562 | { 0x04, 0xa800 }, |
| 2563 | { 0x04, 0xa000 }, |
| 2564 | |
| 2565 | { 0x03, 0xff41 }, |
| 2566 | { 0x02, 0xdf20 }, |
| 2567 | { 0x01, 0x0140 }, |
| 2568 | { 0x00, 0x00bb }, |
| 2569 | { 0x04, 0xb800 }, |
| 2570 | { 0x04, 0xb000 }, |
| 2571 | |
| 2572 | { 0x03, 0xdf41 }, |
| 2573 | { 0x02, 0xdc60 }, |
| 2574 | { 0x01, 0x6340 }, |
| 2575 | { 0x00, 0x007d }, |
| 2576 | { 0x04, 0xd800 }, |
| 2577 | { 0x04, 0xd000 }, |
| 2578 | |
| 2579 | { 0x03, 0xdf01 }, |
| 2580 | { 0x02, 0xdf20 }, |
| 2581 | { 0x01, 0x100a }, |
| 2582 | { 0x00, 0xa0ff }, |
| 2583 | { 0x04, 0xf800 }, |
| 2584 | { 0x04, 0xf000 }, |
| 2585 | |
| 2586 | { 0x1f, 0x0000 }, |
| 2587 | { 0x0b, 0x0000 }, |
| 2588 | { 0x00, 0x9200 } |
| 2589 | }; |
| 2590 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2591 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2592 | } |
| 2593 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2594 | static void rtl8169sb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2595 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2596 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a441d7b | 2007-08-17 18:26:35 +0200 | [diff] [blame] | 2597 | { 0x1f, 0x0002 }, |
| 2598 | { 0x01, 0x90d0 }, |
| 2599 | { 0x1f, 0x0000 } |
| 2600 | }; |
| 2601 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2602 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2603 | } |
| 2604 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2605 | static void rtl8169scd_hw_phy_config_quirk(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2606 | { |
| 2607 | struct pci_dev *pdev = tp->pci_dev; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2608 | |
Sergei Shtylyov | ccbae55 | 2011-07-22 05:37:24 +0000 | [diff] [blame] | 2609 | if ((pdev->subsystem_vendor != PCI_VENDOR_ID_GIGABYTE) || |
| 2610 | (pdev->subsystem_device != 0xe000)) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2611 | return; |
| 2612 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2613 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2614 | rtl_writephy(tp, 0x10, 0xf01b); |
| 2615 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2616 | } |
| 2617 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2618 | static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2619 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2620 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2621 | { 0x1f, 0x0001 }, |
| 2622 | { 0x04, 0x0000 }, |
| 2623 | { 0x03, 0x00a1 }, |
| 2624 | { 0x02, 0x0008 }, |
| 2625 | { 0x01, 0x0120 }, |
| 2626 | { 0x00, 0x1000 }, |
| 2627 | { 0x04, 0x0800 }, |
| 2628 | { 0x04, 0x9000 }, |
| 2629 | { 0x03, 0x802f }, |
| 2630 | { 0x02, 0x4f02 }, |
| 2631 | { 0x01, 0x0409 }, |
| 2632 | { 0x00, 0xf099 }, |
| 2633 | { 0x04, 0x9800 }, |
| 2634 | { 0x04, 0xa000 }, |
| 2635 | { 0x03, 0xdf01 }, |
| 2636 | { 0x02, 0xdf20 }, |
| 2637 | { 0x01, 0xff95 }, |
| 2638 | { 0x00, 0xba00 }, |
| 2639 | { 0x04, 0xa800 }, |
| 2640 | { 0x04, 0xf000 }, |
| 2641 | { 0x03, 0xdf01 }, |
| 2642 | { 0x02, 0xdf20 }, |
| 2643 | { 0x01, 0x101a }, |
| 2644 | { 0x00, 0xa0ff }, |
| 2645 | { 0x04, 0xf800 }, |
| 2646 | { 0x04, 0x0000 }, |
| 2647 | { 0x1f, 0x0000 }, |
| 2648 | |
| 2649 | { 0x1f, 0x0001 }, |
| 2650 | { 0x10, 0xf41b }, |
| 2651 | { 0x14, 0xfb54 }, |
| 2652 | { 0x18, 0xf5c7 }, |
| 2653 | { 0x1f, 0x0000 }, |
| 2654 | |
| 2655 | { 0x1f, 0x0001 }, |
| 2656 | { 0x17, 0x0cc0 }, |
| 2657 | { 0x1f, 0x0000 } |
| 2658 | }; |
| 2659 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2660 | 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] | 2661 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2662 | rtl8169scd_hw_phy_config_quirk(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2663 | } |
| 2664 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2665 | static void rtl8169sce_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2666 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2667 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2668 | { 0x1f, 0x0001 }, |
| 2669 | { 0x04, 0x0000 }, |
| 2670 | { 0x03, 0x00a1 }, |
| 2671 | { 0x02, 0x0008 }, |
| 2672 | { 0x01, 0x0120 }, |
| 2673 | { 0x00, 0x1000 }, |
| 2674 | { 0x04, 0x0800 }, |
| 2675 | { 0x04, 0x9000 }, |
| 2676 | { 0x03, 0x802f }, |
| 2677 | { 0x02, 0x4f02 }, |
| 2678 | { 0x01, 0x0409 }, |
| 2679 | { 0x00, 0xf099 }, |
| 2680 | { 0x04, 0x9800 }, |
| 2681 | { 0x04, 0xa000 }, |
| 2682 | { 0x03, 0xdf01 }, |
| 2683 | { 0x02, 0xdf20 }, |
| 2684 | { 0x01, 0xff95 }, |
| 2685 | { 0x00, 0xba00 }, |
| 2686 | { 0x04, 0xa800 }, |
| 2687 | { 0x04, 0xf000 }, |
| 2688 | { 0x03, 0xdf01 }, |
| 2689 | { 0x02, 0xdf20 }, |
| 2690 | { 0x01, 0x101a }, |
| 2691 | { 0x00, 0xa0ff }, |
| 2692 | { 0x04, 0xf800 }, |
| 2693 | { 0x04, 0x0000 }, |
| 2694 | { 0x1f, 0x0000 }, |
| 2695 | |
| 2696 | { 0x1f, 0x0001 }, |
| 2697 | { 0x0b, 0x8480 }, |
| 2698 | { 0x1f, 0x0000 }, |
| 2699 | |
| 2700 | { 0x1f, 0x0001 }, |
| 2701 | { 0x18, 0x67c7 }, |
| 2702 | { 0x04, 0x2000 }, |
| 2703 | { 0x03, 0x002f }, |
| 2704 | { 0x02, 0x4360 }, |
| 2705 | { 0x01, 0x0109 }, |
| 2706 | { 0x00, 0x3022 }, |
| 2707 | { 0x04, 0x2800 }, |
| 2708 | { 0x1f, 0x0000 }, |
| 2709 | |
| 2710 | { 0x1f, 0x0001 }, |
| 2711 | { 0x17, 0x0cc0 }, |
| 2712 | { 0x1f, 0x0000 } |
| 2713 | }; |
| 2714 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2715 | 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] | 2716 | } |
| 2717 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2718 | static void rtl8168bb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2719 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2720 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2721 | { 0x10, 0xf41b }, |
| 2722 | { 0x1f, 0x0000 } |
| 2723 | }; |
| 2724 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2725 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2726 | rtl_patchphy(tp, 0x16, 1 << 0); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2727 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2728 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2729 | } |
| 2730 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2731 | static void rtl8168bef_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2732 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2733 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2734 | { 0x1f, 0x0001 }, |
| 2735 | { 0x10, 0xf41b }, |
| 2736 | { 0x1f, 0x0000 } |
| 2737 | }; |
| 2738 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2739 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2740 | } |
| 2741 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2742 | static void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2743 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2744 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2745 | { 0x1f, 0x0000 }, |
| 2746 | { 0x1d, 0x0f00 }, |
| 2747 | { 0x1f, 0x0002 }, |
| 2748 | { 0x0c, 0x1ec8 }, |
| 2749 | { 0x1f, 0x0000 } |
| 2750 | }; |
| 2751 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2752 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2753 | } |
| 2754 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2755 | static void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2756 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2757 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2758 | { 0x1f, 0x0001 }, |
| 2759 | { 0x1d, 0x3d98 }, |
| 2760 | { 0x1f, 0x0000 } |
| 2761 | }; |
| 2762 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2763 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2764 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2765 | rtl_patchphy(tp, 0x0d, 1 << 5); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2766 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2767 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2768 | } |
| 2769 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2770 | static void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2771 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2772 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a3f8067 | 2007-10-18 14:35:11 +0200 | [diff] [blame] | 2773 | { 0x1f, 0x0001 }, |
| 2774 | { 0x12, 0x2300 }, |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2775 | { 0x1f, 0x0002 }, |
| 2776 | { 0x00, 0x88d4 }, |
| 2777 | { 0x01, 0x82b1 }, |
| 2778 | { 0x03, 0x7002 }, |
| 2779 | { 0x08, 0x9e30 }, |
| 2780 | { 0x09, 0x01f0 }, |
| 2781 | { 0x0a, 0x5500 }, |
| 2782 | { 0x0c, 0x00c8 }, |
| 2783 | { 0x1f, 0x0003 }, |
| 2784 | { 0x12, 0xc096 }, |
| 2785 | { 0x16, 0x000a }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2786 | { 0x1f, 0x0000 }, |
| 2787 | { 0x1f, 0x0000 }, |
| 2788 | { 0x09, 0x2000 }, |
| 2789 | { 0x09, 0x0000 } |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2790 | }; |
| 2791 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2792 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2793 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2794 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2795 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2796 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2797 | } |
| 2798 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2799 | static void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2800 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2801 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2802 | { 0x1f, 0x0001 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2803 | { 0x12, 0x2300 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2804 | { 0x03, 0x802f }, |
| 2805 | { 0x02, 0x4f02 }, |
| 2806 | { 0x01, 0x0409 }, |
| 2807 | { 0x00, 0xf099 }, |
| 2808 | { 0x04, 0x9800 }, |
| 2809 | { 0x04, 0x9000 }, |
| 2810 | { 0x1d, 0x3d98 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2811 | { 0x1f, 0x0002 }, |
| 2812 | { 0x0c, 0x7eb8 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2813 | { 0x06, 0x0761 }, |
| 2814 | { 0x1f, 0x0003 }, |
| 2815 | { 0x16, 0x0f0a }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2816 | { 0x1f, 0x0000 } |
| 2817 | }; |
| 2818 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2819 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2820 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2821 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 2822 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2823 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2824 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2825 | } |
| 2826 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2827 | static void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2828 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2829 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2830 | { 0x1f, 0x0001 }, |
| 2831 | { 0x12, 0x2300 }, |
| 2832 | { 0x1d, 0x3d98 }, |
| 2833 | { 0x1f, 0x0002 }, |
| 2834 | { 0x0c, 0x7eb8 }, |
| 2835 | { 0x06, 0x5461 }, |
| 2836 | { 0x1f, 0x0003 }, |
| 2837 | { 0x16, 0x0f0a }, |
| 2838 | { 0x1f, 0x0000 } |
| 2839 | }; |
| 2840 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2841 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2842 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2843 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 2844 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2845 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2846 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2847 | } |
| 2848 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2849 | static void rtl8168c_4_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2850 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2851 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2852 | } |
| 2853 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2854 | static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2855 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2856 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2857 | /* Channel Estimation */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2858 | { 0x1f, 0x0001 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2859 | { 0x06, 0x4064 }, |
| 2860 | { 0x07, 0x2863 }, |
| 2861 | { 0x08, 0x059c }, |
| 2862 | { 0x09, 0x26b4 }, |
| 2863 | { 0x0a, 0x6a19 }, |
| 2864 | { 0x0b, 0xdcc8 }, |
| 2865 | { 0x10, 0xf06d }, |
| 2866 | { 0x14, 0x7f68 }, |
| 2867 | { 0x18, 0x7fd9 }, |
| 2868 | { 0x1c, 0xf0ff }, |
| 2869 | { 0x1d, 0x3d9c }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2870 | { 0x1f, 0x0003 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2871 | { 0x12, 0xf49f }, |
| 2872 | { 0x13, 0x070b }, |
| 2873 | { 0x1a, 0x05ad }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2874 | { 0x14, 0x94c0 }, |
| 2875 | |
| 2876 | /* |
| 2877 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2878 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2879 | */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2880 | { 0x1f, 0x0002 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2881 | { 0x06, 0x5561 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2882 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2883 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2884 | { 0x06, 0x5561 }, |
| 2885 | |
| 2886 | /* |
| 2887 | * Can not link to 1Gbps with bad cable |
| 2888 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 2889 | */ |
| 2890 | { 0x1f, 0x0001 }, |
| 2891 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2892 | |
| 2893 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2894 | { 0x0d, 0xf880 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2895 | }; |
| 2896 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2897 | 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] | 2898 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2899 | /* |
| 2900 | * Rx Error Issue |
| 2901 | * Fine Tune Switching regulator parameter |
| 2902 | */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2903 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2904 | rtl_w0w1_phy(tp, 0x0b, 0x0010, 0x00ef); |
| 2905 | rtl_w0w1_phy(tp, 0x0c, 0xa200, 0x5d00); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2906 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 2907 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2908 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2909 | { 0x1f, 0x0002 }, |
| 2910 | { 0x05, 0x669a }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2911 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2912 | { 0x05, 0x8330 }, |
| 2913 | { 0x06, 0x669a }, |
| 2914 | { 0x1f, 0x0002 } |
| 2915 | }; |
| 2916 | int val; |
| 2917 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2918 | 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] | 2919 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2920 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2921 | |
| 2922 | if ((val & 0x00ff) != 0x006c) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2923 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2924 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 2925 | 0x0069, 0x006a, 0x006b, 0x006c |
| 2926 | }; |
| 2927 | int i; |
| 2928 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2929 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2930 | |
| 2931 | val &= 0xff00; |
| 2932 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2933 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2934 | } |
| 2935 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2936 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2937 | { 0x1f, 0x0002 }, |
| 2938 | { 0x05, 0x6662 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2939 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2940 | { 0x05, 0x8330 }, |
| 2941 | { 0x06, 0x6662 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2942 | }; |
| 2943 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2944 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2945 | } |
| 2946 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2947 | /* RSET couple improve */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2948 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2949 | rtl_patchphy(tp, 0x0d, 0x0300); |
| 2950 | rtl_patchphy(tp, 0x0f, 0x0010); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2951 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2952 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2953 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 2954 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 2955 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2956 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2957 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2958 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2959 | |
| 2960 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2961 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2962 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2963 | } |
| 2964 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2965 | static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2966 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2967 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2968 | /* Channel Estimation */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2969 | { 0x1f, 0x0001 }, |
| 2970 | { 0x06, 0x4064 }, |
| 2971 | { 0x07, 0x2863 }, |
| 2972 | { 0x08, 0x059c }, |
| 2973 | { 0x09, 0x26b4 }, |
| 2974 | { 0x0a, 0x6a19 }, |
| 2975 | { 0x0b, 0xdcc8 }, |
| 2976 | { 0x10, 0xf06d }, |
| 2977 | { 0x14, 0x7f68 }, |
| 2978 | { 0x18, 0x7fd9 }, |
| 2979 | { 0x1c, 0xf0ff }, |
| 2980 | { 0x1d, 0x3d9c }, |
| 2981 | { 0x1f, 0x0003 }, |
| 2982 | { 0x12, 0xf49f }, |
| 2983 | { 0x13, 0x070b }, |
| 2984 | { 0x1a, 0x05ad }, |
| 2985 | { 0x14, 0x94c0 }, |
| 2986 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2987 | /* |
| 2988 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2989 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2990 | */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2991 | { 0x1f, 0x0002 }, |
| 2992 | { 0x06, 0x5561 }, |
| 2993 | { 0x1f, 0x0005 }, |
| 2994 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2995 | { 0x06, 0x5561 }, |
| 2996 | |
| 2997 | /* |
| 2998 | * Can not link to 1Gbps with bad cable |
| 2999 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 3000 | */ |
| 3001 | { 0x1f, 0x0001 }, |
| 3002 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3003 | |
| 3004 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3005 | { 0x0d, 0xf880 } |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3006 | }; |
| 3007 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3008 | 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] | 3009 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3010 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3011 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3012 | { 0x1f, 0x0002 }, |
| 3013 | { 0x05, 0x669a }, |
| 3014 | { 0x1f, 0x0005 }, |
| 3015 | { 0x05, 0x8330 }, |
| 3016 | { 0x06, 0x669a }, |
| 3017 | |
| 3018 | { 0x1f, 0x0002 } |
| 3019 | }; |
| 3020 | int val; |
| 3021 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3022 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3023 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3024 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3025 | if ((val & 0x00ff) != 0x006c) { |
Joe Perches | b6bc765 | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 3026 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3027 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 3028 | 0x0069, 0x006a, 0x006b, 0x006c |
| 3029 | }; |
| 3030 | int i; |
| 3031 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3032 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3033 | |
| 3034 | val &= 0xff00; |
| 3035 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3036 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3037 | } |
| 3038 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3039 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3040 | { 0x1f, 0x0002 }, |
| 3041 | { 0x05, 0x2642 }, |
| 3042 | { 0x1f, 0x0005 }, |
| 3043 | { 0x05, 0x8330 }, |
| 3044 | { 0x06, 0x2642 } |
| 3045 | }; |
| 3046 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3047 | 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] | 3048 | } |
| 3049 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3050 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3051 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3052 | rtl_w0w1_phy(tp, 0x02, 0x0100, 0x0600); |
| 3053 | rtl_w0w1_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3054 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3055 | /* Switching regulator Slew rate */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3056 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3057 | rtl_patchphy(tp, 0x0f, 0x0017); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3058 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3059 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3060 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3061 | |
| 3062 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3063 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3064 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3065 | } |
| 3066 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3067 | static void rtl8168d_3_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3068 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3069 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3070 | { 0x1f, 0x0002 }, |
| 3071 | { 0x10, 0x0008 }, |
| 3072 | { 0x0d, 0x006c }, |
| 3073 | |
| 3074 | { 0x1f, 0x0000 }, |
| 3075 | { 0x0d, 0xf880 }, |
| 3076 | |
| 3077 | { 0x1f, 0x0001 }, |
| 3078 | { 0x17, 0x0cc0 }, |
| 3079 | |
| 3080 | { 0x1f, 0x0001 }, |
| 3081 | { 0x0b, 0xa4d8 }, |
| 3082 | { 0x09, 0x281c }, |
| 3083 | { 0x07, 0x2883 }, |
| 3084 | { 0x0a, 0x6b35 }, |
| 3085 | { 0x1d, 0x3da4 }, |
| 3086 | { 0x1c, 0xeffd }, |
| 3087 | { 0x14, 0x7f52 }, |
| 3088 | { 0x18, 0x7fc6 }, |
| 3089 | { 0x08, 0x0601 }, |
| 3090 | { 0x06, 0x4063 }, |
| 3091 | { 0x10, 0xf074 }, |
| 3092 | { 0x1f, 0x0003 }, |
| 3093 | { 0x13, 0x0789 }, |
| 3094 | { 0x12, 0xf4bd }, |
| 3095 | { 0x1a, 0x04fd }, |
| 3096 | { 0x14, 0x84b0 }, |
| 3097 | { 0x1f, 0x0000 }, |
| 3098 | { 0x00, 0x9200 }, |
| 3099 | |
| 3100 | { 0x1f, 0x0005 }, |
| 3101 | { 0x01, 0x0340 }, |
| 3102 | { 0x1f, 0x0001 }, |
| 3103 | { 0x04, 0x4000 }, |
| 3104 | { 0x03, 0x1d21 }, |
| 3105 | { 0x02, 0x0c32 }, |
| 3106 | { 0x01, 0x0200 }, |
| 3107 | { 0x00, 0x5554 }, |
| 3108 | { 0x04, 0x4800 }, |
| 3109 | { 0x04, 0x4000 }, |
| 3110 | { 0x04, 0xf000 }, |
| 3111 | { 0x03, 0xdf01 }, |
| 3112 | { 0x02, 0xdf20 }, |
| 3113 | { 0x01, 0x101a }, |
| 3114 | { 0x00, 0xa0ff }, |
| 3115 | { 0x04, 0xf800 }, |
| 3116 | { 0x04, 0xf000 }, |
| 3117 | { 0x1f, 0x0000 }, |
| 3118 | |
| 3119 | { 0x1f, 0x0007 }, |
| 3120 | { 0x1e, 0x0023 }, |
| 3121 | { 0x16, 0x0000 }, |
| 3122 | { 0x1f, 0x0000 } |
| 3123 | }; |
| 3124 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3125 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3126 | } |
| 3127 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3128 | static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp) |
| 3129 | { |
| 3130 | static const struct phy_reg phy_reg_init[] = { |
| 3131 | { 0x1f, 0x0001 }, |
| 3132 | { 0x17, 0x0cc0 }, |
| 3133 | |
| 3134 | { 0x1f, 0x0007 }, |
| 3135 | { 0x1e, 0x002d }, |
| 3136 | { 0x18, 0x0040 }, |
| 3137 | { 0x1f, 0x0000 } |
| 3138 | }; |
| 3139 | |
| 3140 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3141 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3142 | } |
| 3143 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3144 | static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3145 | { |
| 3146 | static const struct phy_reg phy_reg_init[] = { |
| 3147 | /* Enable Delay cap */ |
| 3148 | { 0x1f, 0x0005 }, |
| 3149 | { 0x05, 0x8b80 }, |
| 3150 | { 0x06, 0xc896 }, |
| 3151 | { 0x1f, 0x0000 }, |
| 3152 | |
| 3153 | /* Channel estimation fine tune */ |
| 3154 | { 0x1f, 0x0001 }, |
| 3155 | { 0x0b, 0x6c20 }, |
| 3156 | { 0x07, 0x2872 }, |
| 3157 | { 0x1c, 0xefff }, |
| 3158 | { 0x1f, 0x0003 }, |
| 3159 | { 0x14, 0x6420 }, |
| 3160 | { 0x1f, 0x0000 }, |
| 3161 | |
| 3162 | /* Update PFM & 10M TX idle timer */ |
| 3163 | { 0x1f, 0x0007 }, |
| 3164 | { 0x1e, 0x002f }, |
| 3165 | { 0x15, 0x1919 }, |
| 3166 | { 0x1f, 0x0000 }, |
| 3167 | |
| 3168 | { 0x1f, 0x0007 }, |
| 3169 | { 0x1e, 0x00ac }, |
| 3170 | { 0x18, 0x0006 }, |
| 3171 | { 0x1f, 0x0000 } |
| 3172 | }; |
| 3173 | |
Francois Romieu | 15ecd03 | 2011-04-27 13:52:22 -0700 | [diff] [blame] | 3174 | rtl_apply_firmware(tp); |
| 3175 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3176 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3177 | |
| 3178 | /* DCO enable for 10M IDLE Power */ |
| 3179 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3180 | rtl_writephy(tp, 0x1e, 0x0023); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3181 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3182 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3183 | |
| 3184 | /* For impedance matching */ |
| 3185 | rtl_writephy(tp, 0x1f, 0x0002); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3186 | rtl_w0w1_phy(tp, 0x08, 0x8000, 0x7f00); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3187 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3188 | |
| 3189 | /* PHY auto speed down */ |
| 3190 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3191 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3192 | rtl_w0w1_phy(tp, 0x18, 0x0050, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3193 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3194 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3195 | |
| 3196 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3197 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3198 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3199 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3200 | |
| 3201 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3202 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3203 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3204 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3205 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3206 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x1100); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3207 | rtl_writephy(tp, 0x1f, 0x0006); |
| 3208 | rtl_writephy(tp, 0x00, 0x5a00); |
| 3209 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3210 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3211 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3212 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3213 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3214 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3215 | } |
| 3216 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3217 | static void rtl_rar_exgmac_set(struct rtl8169_private *tp, u8 *addr) |
| 3218 | { |
| 3219 | const u16 w[] = { |
| 3220 | addr[0] | (addr[1] << 8), |
| 3221 | addr[2] | (addr[3] << 8), |
| 3222 | addr[4] | (addr[5] << 8) |
| 3223 | }; |
| 3224 | const struct exgmac_reg e[] = { |
| 3225 | { .addr = 0xe0, ERIAR_MASK_1111, .val = w[0] | (w[1] << 16) }, |
| 3226 | { .addr = 0xe4, ERIAR_MASK_1111, .val = w[2] }, |
| 3227 | { .addr = 0xf0, ERIAR_MASK_1111, .val = w[0] << 16 }, |
| 3228 | { .addr = 0xf4, ERIAR_MASK_1111, .val = w[1] | (w[2] << 16) } |
| 3229 | }; |
| 3230 | |
| 3231 | rtl_write_exgmac_batch(tp, e, ARRAY_SIZE(e)); |
| 3232 | } |
| 3233 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3234 | static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp) |
| 3235 | { |
| 3236 | static const struct phy_reg phy_reg_init[] = { |
| 3237 | /* Enable Delay cap */ |
| 3238 | { 0x1f, 0x0004 }, |
| 3239 | { 0x1f, 0x0007 }, |
| 3240 | { 0x1e, 0x00ac }, |
| 3241 | { 0x18, 0x0006 }, |
| 3242 | { 0x1f, 0x0002 }, |
| 3243 | { 0x1f, 0x0000 }, |
| 3244 | { 0x1f, 0x0000 }, |
| 3245 | |
| 3246 | /* Channel estimation fine tune */ |
| 3247 | { 0x1f, 0x0003 }, |
| 3248 | { 0x09, 0xa20f }, |
| 3249 | { 0x1f, 0x0000 }, |
| 3250 | { 0x1f, 0x0000 }, |
| 3251 | |
| 3252 | /* Green Setting */ |
| 3253 | { 0x1f, 0x0005 }, |
| 3254 | { 0x05, 0x8b5b }, |
| 3255 | { 0x06, 0x9222 }, |
| 3256 | { 0x05, 0x8b6d }, |
| 3257 | { 0x06, 0x8000 }, |
| 3258 | { 0x05, 0x8b76 }, |
| 3259 | { 0x06, 0x8000 }, |
| 3260 | { 0x1f, 0x0000 } |
| 3261 | }; |
| 3262 | |
| 3263 | rtl_apply_firmware(tp); |
| 3264 | |
| 3265 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3266 | |
| 3267 | /* For 4-corner performance improve */ |
| 3268 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3269 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3270 | rtl_w0w1_phy(tp, 0x17, 0x0006, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3271 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3272 | |
| 3273 | /* PHY auto speed down */ |
| 3274 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3275 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3276 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3277 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3278 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3279 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3280 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3281 | |
| 3282 | /* improve 10M EEE waveform */ |
| 3283 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3284 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3285 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3286 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3287 | |
| 3288 | /* Improve 2-pair detection performance */ |
| 3289 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3290 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3291 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3292 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3293 | |
| 3294 | /* EEE setting */ |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame^] | 3295 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_1111, 0x0000, 0x0003, ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3296 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3297 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3298 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3299 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3300 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3301 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3302 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0100); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3303 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3304 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3305 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3306 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3307 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3308 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3309 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3310 | |
| 3311 | /* Green feature */ |
| 3312 | rtl_writephy(tp, 0x1f, 0x0003); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3313 | rtl_w0w1_phy(tp, 0x19, 0x0000, 0x0001); |
| 3314 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0400); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3315 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | e0c0755 | 2012-10-23 20:24:03 +0000 | [diff] [blame] | 3316 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 3317 | /* Broken BIOS workaround: feed GigaMAC registers with MAC address. */ |
| 3318 | rtl_rar_exgmac_set(tp, tp->dev->dev_addr); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3319 | } |
| 3320 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3321 | static void rtl8168f_hw_phy_config(struct rtl8169_private *tp) |
| 3322 | { |
| 3323 | /* For 4-corner performance improve */ |
| 3324 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3325 | rtl_writephy(tp, 0x05, 0x8b80); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3326 | rtl_w0w1_phy(tp, 0x06, 0x0006, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3327 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3328 | |
| 3329 | /* PHY auto speed down */ |
| 3330 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3331 | rtl_writephy(tp, 0x1e, 0x002d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3332 | rtl_w0w1_phy(tp, 0x18, 0x0010, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3333 | rtl_writephy(tp, 0x1f, 0x0000); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3334 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3335 | |
| 3336 | /* Improve 10M EEE waveform */ |
| 3337 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3338 | rtl_writephy(tp, 0x05, 0x8b86); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3339 | rtl_w0w1_phy(tp, 0x06, 0x0001, 0x0000); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3340 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3341 | } |
| 3342 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3343 | static void rtl8168f_1_hw_phy_config(struct rtl8169_private *tp) |
| 3344 | { |
| 3345 | static const struct phy_reg phy_reg_init[] = { |
| 3346 | /* Channel estimation fine tune */ |
| 3347 | { 0x1f, 0x0003 }, |
| 3348 | { 0x09, 0xa20f }, |
| 3349 | { 0x1f, 0x0000 }, |
| 3350 | |
| 3351 | /* Modify green table for giga & fnet */ |
| 3352 | { 0x1f, 0x0005 }, |
| 3353 | { 0x05, 0x8b55 }, |
| 3354 | { 0x06, 0x0000 }, |
| 3355 | { 0x05, 0x8b5e }, |
| 3356 | { 0x06, 0x0000 }, |
| 3357 | { 0x05, 0x8b67 }, |
| 3358 | { 0x06, 0x0000 }, |
| 3359 | { 0x05, 0x8b70 }, |
| 3360 | { 0x06, 0x0000 }, |
| 3361 | { 0x1f, 0x0000 }, |
| 3362 | { 0x1f, 0x0007 }, |
| 3363 | { 0x1e, 0x0078 }, |
| 3364 | { 0x17, 0x0000 }, |
| 3365 | { 0x19, 0x00fb }, |
| 3366 | { 0x1f, 0x0000 }, |
| 3367 | |
| 3368 | /* Modify green table for 10M */ |
| 3369 | { 0x1f, 0x0005 }, |
| 3370 | { 0x05, 0x8b79 }, |
| 3371 | { 0x06, 0xaa00 }, |
| 3372 | { 0x1f, 0x0000 }, |
| 3373 | |
| 3374 | /* Disable hiimpedance detection (RTCT) */ |
| 3375 | { 0x1f, 0x0003 }, |
| 3376 | { 0x01, 0x328a }, |
| 3377 | { 0x1f, 0x0000 } |
| 3378 | }; |
| 3379 | |
| 3380 | rtl_apply_firmware(tp); |
| 3381 | |
| 3382 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3383 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3384 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3385 | |
| 3386 | /* Improve 2-pair detection performance */ |
| 3387 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3388 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3389 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3390 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3391 | } |
| 3392 | |
| 3393 | static void rtl8168f_2_hw_phy_config(struct rtl8169_private *tp) |
| 3394 | { |
| 3395 | rtl_apply_firmware(tp); |
| 3396 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3397 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3398 | } |
| 3399 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3400 | static void rtl8411_hw_phy_config(struct rtl8169_private *tp) |
| 3401 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3402 | static const struct phy_reg phy_reg_init[] = { |
| 3403 | /* Channel estimation fine tune */ |
| 3404 | { 0x1f, 0x0003 }, |
| 3405 | { 0x09, 0xa20f }, |
| 3406 | { 0x1f, 0x0000 }, |
| 3407 | |
| 3408 | /* Modify green table for giga & fnet */ |
| 3409 | { 0x1f, 0x0005 }, |
| 3410 | { 0x05, 0x8b55 }, |
| 3411 | { 0x06, 0x0000 }, |
| 3412 | { 0x05, 0x8b5e }, |
| 3413 | { 0x06, 0x0000 }, |
| 3414 | { 0x05, 0x8b67 }, |
| 3415 | { 0x06, 0x0000 }, |
| 3416 | { 0x05, 0x8b70 }, |
| 3417 | { 0x06, 0x0000 }, |
| 3418 | { 0x1f, 0x0000 }, |
| 3419 | { 0x1f, 0x0007 }, |
| 3420 | { 0x1e, 0x0078 }, |
| 3421 | { 0x17, 0x0000 }, |
| 3422 | { 0x19, 0x00aa }, |
| 3423 | { 0x1f, 0x0000 }, |
| 3424 | |
| 3425 | /* Modify green table for 10M */ |
| 3426 | { 0x1f, 0x0005 }, |
| 3427 | { 0x05, 0x8b79 }, |
| 3428 | { 0x06, 0xaa00 }, |
| 3429 | { 0x1f, 0x0000 }, |
| 3430 | |
| 3431 | /* Disable hiimpedance detection (RTCT) */ |
| 3432 | { 0x1f, 0x0003 }, |
| 3433 | { 0x01, 0x328a }, |
| 3434 | { 0x1f, 0x0000 } |
| 3435 | }; |
| 3436 | |
| 3437 | |
| 3438 | rtl_apply_firmware(tp); |
| 3439 | |
| 3440 | rtl8168f_hw_phy_config(tp); |
| 3441 | |
| 3442 | /* Improve 2-pair detection performance */ |
| 3443 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3444 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3445 | rtl_w0w1_phy(tp, 0x06, 0x4000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3446 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3447 | |
| 3448 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3449 | |
| 3450 | /* Modify green table for giga */ |
| 3451 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3452 | rtl_writephy(tp, 0x05, 0x8b54); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3453 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3454 | rtl_writephy(tp, 0x05, 0x8b5d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3455 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0800); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3456 | rtl_writephy(tp, 0x05, 0x8a7c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3457 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3458 | rtl_writephy(tp, 0x05, 0x8a7f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3459 | rtl_w0w1_phy(tp, 0x06, 0x0100, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3460 | rtl_writephy(tp, 0x05, 0x8a82); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3461 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3462 | rtl_writephy(tp, 0x05, 0x8a85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3463 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3464 | rtl_writephy(tp, 0x05, 0x8a88); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3465 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3466 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3467 | |
| 3468 | /* uc same-seed solution */ |
| 3469 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3470 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3471 | rtl_w0w1_phy(tp, 0x06, 0x8000, 0x0000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3472 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3473 | |
| 3474 | /* eee setting */ |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame^] | 3475 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x00, 0x03, ERIAR_EXGMAC); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3476 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3477 | rtl_writephy(tp, 0x05, 0x8b85); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3478 | rtl_w0w1_phy(tp, 0x06, 0x0000, 0x2000); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3479 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3480 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3481 | rtl_writephy(tp, 0x1e, 0x0020); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3482 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0100); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3483 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3484 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3485 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3486 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3487 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3488 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3489 | |
| 3490 | /* Green feature */ |
| 3491 | rtl_writephy(tp, 0x1f, 0x0003); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3492 | rtl_w0w1_phy(tp, 0x19, 0x0000, 0x0001); |
| 3493 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0400); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3494 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3495 | } |
| 3496 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3497 | static void rtl8168g_1_hw_phy_config(struct rtl8169_private *tp) |
| 3498 | { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3499 | rtl_apply_firmware(tp); |
| 3500 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3501 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3502 | if (rtl_readphy(tp, 0x10) & 0x0100) { |
| 3503 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3504 | rtl_w0w1_phy(tp, 0x12, 0x0000, 0x8000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3505 | } else { |
| 3506 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3507 | rtl_w0w1_phy(tp, 0x12, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3508 | } |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3509 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3510 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3511 | if (rtl_readphy(tp, 0x13) & 0x0100) { |
| 3512 | rtl_writephy(tp, 0x1f, 0x0c41); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3513 | rtl_w0w1_phy(tp, 0x15, 0x0002, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3514 | } else { |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3515 | rtl_writephy(tp, 0x1f, 0x0c41); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3516 | rtl_w0w1_phy(tp, 0x15, 0x0000, 0x0002); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3517 | } |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3518 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3519 | /* Enable PHY auto speed down */ |
| 3520 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3521 | rtl_w0w1_phy(tp, 0x11, 0x000c, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3522 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3523 | rtl_writephy(tp, 0x1f, 0x0bcc); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3524 | rtl_w0w1_phy(tp, 0x14, 0x0100, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3525 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3526 | rtl_w0w1_phy(tp, 0x11, 0x00c0, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3527 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3528 | rtl_writephy(tp, 0x13, 0x8084); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3529 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x6000); |
| 3530 | rtl_w0w1_phy(tp, 0x10, 0x1003, 0x0000); |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3531 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3532 | /* EEE auto-fallback function */ |
| 3533 | rtl_writephy(tp, 0x1f, 0x0a4b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3534 | rtl_w0w1_phy(tp, 0x11, 0x0004, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3535 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3536 | /* Enable UC LPF tune function */ |
| 3537 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3538 | rtl_writephy(tp, 0x13, 0x8012); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3539 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0x0000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3540 | |
| 3541 | rtl_writephy(tp, 0x1f, 0x0c42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3542 | rtl_w0w1_phy(tp, 0x11, 0x4000, 0x2000); |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3543 | |
hayeswang | fe7524c | 2013-04-01 22:23:37 +0000 | [diff] [blame] | 3544 | /* Improve SWR Efficiency */ |
| 3545 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3546 | rtl_writephy(tp, 0x14, 0x5065); |
| 3547 | rtl_writephy(tp, 0x14, 0xd065); |
| 3548 | rtl_writephy(tp, 0x1f, 0x0bc8); |
| 3549 | rtl_writephy(tp, 0x11, 0x5655); |
| 3550 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3551 | rtl_writephy(tp, 0x14, 0x1065); |
| 3552 | rtl_writephy(tp, 0x14, 0x9065); |
| 3553 | rtl_writephy(tp, 0x14, 0x1065); |
| 3554 | |
David Chang | 1bac107 | 2013-11-27 15:48:36 +0800 | [diff] [blame] | 3555 | /* Check ALDPS bit, disable it if enabled */ |
| 3556 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3557 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3558 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
David Chang | 1bac107 | 2013-11-27 15:48:36 +0800 | [diff] [blame] | 3559 | |
hayeswang | 41f44d1 | 2013-04-01 22:23:36 +0000 | [diff] [blame] | 3560 | rtl_writephy(tp, 0x1f, 0x0000); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3561 | } |
| 3562 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 3563 | static void rtl8168g_2_hw_phy_config(struct rtl8169_private *tp) |
| 3564 | { |
| 3565 | rtl_apply_firmware(tp); |
| 3566 | } |
| 3567 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3568 | static void rtl8168h_1_hw_phy_config(struct rtl8169_private *tp) |
| 3569 | { |
| 3570 | u16 dout_tapbin; |
| 3571 | u32 data; |
| 3572 | |
| 3573 | rtl_apply_firmware(tp); |
| 3574 | |
| 3575 | /* CHN EST parameters adjust - giga master */ |
| 3576 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3577 | rtl_writephy(tp, 0x13, 0x809b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3578 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3579 | rtl_writephy(tp, 0x13, 0x80a2); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3580 | rtl_w0w1_phy(tp, 0x14, 0x8000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3581 | rtl_writephy(tp, 0x13, 0x80a4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3582 | rtl_w0w1_phy(tp, 0x14, 0x8500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3583 | rtl_writephy(tp, 0x13, 0x809c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3584 | rtl_w0w1_phy(tp, 0x14, 0xbd00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3585 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3586 | |
| 3587 | /* CHN EST parameters adjust - giga slave */ |
| 3588 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3589 | rtl_writephy(tp, 0x13, 0x80ad); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3590 | rtl_w0w1_phy(tp, 0x14, 0x7000, 0xf800); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3591 | rtl_writephy(tp, 0x13, 0x80b4); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3592 | rtl_w0w1_phy(tp, 0x14, 0x5000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3593 | rtl_writephy(tp, 0x13, 0x80ac); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3594 | rtl_w0w1_phy(tp, 0x14, 0x4000, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3595 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3596 | |
| 3597 | /* CHN EST parameters adjust - fnet */ |
| 3598 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3599 | rtl_writephy(tp, 0x13, 0x808e); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3600 | rtl_w0w1_phy(tp, 0x14, 0x1200, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3601 | rtl_writephy(tp, 0x13, 0x8090); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3602 | rtl_w0w1_phy(tp, 0x14, 0xe500, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3603 | rtl_writephy(tp, 0x13, 0x8092); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3604 | rtl_w0w1_phy(tp, 0x14, 0x9f00, 0xff00); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3605 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3606 | |
| 3607 | /* enable R-tune & PGA-retune function */ |
| 3608 | dout_tapbin = 0; |
| 3609 | rtl_writephy(tp, 0x1f, 0x0a46); |
| 3610 | data = rtl_readphy(tp, 0x13); |
| 3611 | data &= 3; |
| 3612 | data <<= 2; |
| 3613 | dout_tapbin |= data; |
| 3614 | data = rtl_readphy(tp, 0x12); |
| 3615 | data &= 0xc000; |
| 3616 | data >>= 14; |
| 3617 | dout_tapbin |= data; |
| 3618 | dout_tapbin = ~(dout_tapbin^0x08); |
| 3619 | dout_tapbin <<= 12; |
| 3620 | dout_tapbin &= 0xf000; |
| 3621 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3622 | rtl_writephy(tp, 0x13, 0x827a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3623 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3624 | rtl_writephy(tp, 0x13, 0x827b); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3625 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3626 | rtl_writephy(tp, 0x13, 0x827c); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3627 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3628 | rtl_writephy(tp, 0x13, 0x827d); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3629 | rtl_w0w1_phy(tp, 0x14, dout_tapbin, 0xf000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3630 | |
| 3631 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3632 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3633 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3634 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3635 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3636 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3637 | |
| 3638 | /* enable GPHY 10M */ |
| 3639 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3640 | rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3641 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3642 | |
| 3643 | /* SAR ADC performance */ |
| 3644 | rtl_writephy(tp, 0x1f, 0x0bca); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3645 | rtl_w0w1_phy(tp, 0x17, 0x4000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3646 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3647 | |
| 3648 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3649 | rtl_writephy(tp, 0x13, 0x803f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3650 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3651 | rtl_writephy(tp, 0x13, 0x8047); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3652 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3653 | rtl_writephy(tp, 0x13, 0x804f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3654 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3655 | rtl_writephy(tp, 0x13, 0x8057); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3656 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3657 | rtl_writephy(tp, 0x13, 0x805f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3658 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3659 | rtl_writephy(tp, 0x13, 0x8067); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3660 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3661 | rtl_writephy(tp, 0x13, 0x806f); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3662 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x3000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3663 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3664 | |
| 3665 | /* disable phy pfm mode */ |
| 3666 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3667 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x0080); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3668 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3669 | |
| 3670 | /* Check ALDPS bit, disable it if enabled */ |
| 3671 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3672 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3673 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3674 | |
| 3675 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3676 | } |
| 3677 | |
| 3678 | static void rtl8168h_2_hw_phy_config(struct rtl8169_private *tp) |
| 3679 | { |
| 3680 | u16 ioffset_p3, ioffset_p2, ioffset_p1, ioffset_p0; |
| 3681 | u16 rlen; |
| 3682 | u32 data; |
| 3683 | |
| 3684 | rtl_apply_firmware(tp); |
| 3685 | |
| 3686 | /* CHIN EST parameter update */ |
| 3687 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3688 | rtl_writephy(tp, 0x13, 0x808a); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3689 | rtl_w0w1_phy(tp, 0x14, 0x000a, 0x003f); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3690 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3691 | |
| 3692 | /* enable R-tune & PGA-retune function */ |
| 3693 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3694 | rtl_writephy(tp, 0x13, 0x0811); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3695 | rtl_w0w1_phy(tp, 0x14, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3696 | rtl_writephy(tp, 0x1f, 0x0a42); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3697 | rtl_w0w1_phy(tp, 0x16, 0x0002, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3698 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3699 | |
| 3700 | /* enable GPHY 10M */ |
| 3701 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3702 | rtl_w0w1_phy(tp, 0x11, 0x0800, 0x0000); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3703 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3704 | |
| 3705 | r8168_mac_ocp_write(tp, 0xdd02, 0x807d); |
| 3706 | data = r8168_mac_ocp_read(tp, 0xdd02); |
| 3707 | ioffset_p3 = ((data & 0x80)>>7); |
| 3708 | ioffset_p3 <<= 3; |
| 3709 | |
| 3710 | data = r8168_mac_ocp_read(tp, 0xdd00); |
| 3711 | ioffset_p3 |= ((data & (0xe000))>>13); |
| 3712 | ioffset_p2 = ((data & (0x1e00))>>9); |
| 3713 | ioffset_p1 = ((data & (0x01e0))>>5); |
| 3714 | ioffset_p0 = ((data & 0x0010)>>4); |
| 3715 | ioffset_p0 <<= 3; |
| 3716 | ioffset_p0 |= (data & (0x07)); |
| 3717 | data = (ioffset_p3<<12)|(ioffset_p2<<8)|(ioffset_p1<<4)|(ioffset_p0); |
| 3718 | |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 3719 | if ((ioffset_p3 != 0x0f) || (ioffset_p2 != 0x0f) || |
| 3720 | (ioffset_p1 != 0x0f) || (ioffset_p0 == 0x0f)) { |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3721 | rtl_writephy(tp, 0x1f, 0x0bcf); |
| 3722 | rtl_writephy(tp, 0x16, data); |
| 3723 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3724 | } |
| 3725 | |
| 3726 | /* Modify rlen (TX LPF corner frequency) level */ |
| 3727 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3728 | data = rtl_readphy(tp, 0x16); |
| 3729 | data &= 0x000f; |
| 3730 | rlen = 0; |
| 3731 | if (data > 3) |
| 3732 | rlen = data - 3; |
| 3733 | data = rlen | (rlen<<4) | (rlen<<8) | (rlen<<12); |
| 3734 | rtl_writephy(tp, 0x17, data); |
| 3735 | rtl_writephy(tp, 0x1f, 0x0bcd); |
| 3736 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3737 | |
| 3738 | /* disable phy pfm mode */ |
| 3739 | rtl_writephy(tp, 0x1f, 0x0a44); |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3740 | rtl_w0w1_phy(tp, 0x14, 0x0000, 0x0080); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3741 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3742 | |
| 3743 | /* Check ALDPS bit, disable it if enabled */ |
| 3744 | rtl_writephy(tp, 0x1f, 0x0a43); |
| 3745 | if (rtl_readphy(tp, 0x10) & 0x0004) |
Chun-Hao Lin | 7656442 | 2014-10-01 23:17:17 +0800 | [diff] [blame] | 3746 | rtl_w0w1_phy(tp, 0x10, 0x0000, 0x0004); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3747 | |
| 3748 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3749 | } |
| 3750 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3751 | static void rtl8102e_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3752 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3753 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3754 | { 0x1f, 0x0003 }, |
| 3755 | { 0x08, 0x441d }, |
| 3756 | { 0x01, 0x9100 }, |
| 3757 | { 0x1f, 0x0000 } |
| 3758 | }; |
| 3759 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3760 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3761 | rtl_patchphy(tp, 0x11, 1 << 12); |
| 3762 | rtl_patchphy(tp, 0x19, 1 << 13); |
| 3763 | rtl_patchphy(tp, 0x10, 1 << 15); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3764 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3765 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3766 | } |
| 3767 | |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3768 | static void rtl8105e_hw_phy_config(struct rtl8169_private *tp) |
| 3769 | { |
| 3770 | static const struct phy_reg phy_reg_init[] = { |
| 3771 | { 0x1f, 0x0005 }, |
| 3772 | { 0x1a, 0x0000 }, |
| 3773 | { 0x1f, 0x0000 }, |
| 3774 | |
| 3775 | { 0x1f, 0x0004 }, |
| 3776 | { 0x1c, 0x0000 }, |
| 3777 | { 0x1f, 0x0000 }, |
| 3778 | |
| 3779 | { 0x1f, 0x0001 }, |
| 3780 | { 0x15, 0x7701 }, |
| 3781 | { 0x1f, 0x0000 } |
| 3782 | }; |
| 3783 | |
| 3784 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 3785 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3786 | rtl_writephy(tp, 0x18, 0x0310); |
| 3787 | msleep(100); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3788 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3789 | rtl_apply_firmware(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3790 | |
| 3791 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3792 | } |
| 3793 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3794 | static void rtl8402_hw_phy_config(struct rtl8169_private *tp) |
| 3795 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3796 | /* Disable ALDPS before setting firmware */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 3797 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3798 | rtl_writephy(tp, 0x18, 0x0310); |
| 3799 | msleep(20); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3800 | |
| 3801 | rtl_apply_firmware(tp); |
| 3802 | |
| 3803 | /* EEE setting */ |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3804 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3805 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3806 | rtl_writephy(tp, 0x10, 0x401f); |
| 3807 | rtl_writephy(tp, 0x19, 0x7030); |
| 3808 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3809 | } |
| 3810 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3811 | static void rtl8106e_hw_phy_config(struct rtl8169_private *tp) |
| 3812 | { |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3813 | static const struct phy_reg phy_reg_init[] = { |
| 3814 | { 0x1f, 0x0004 }, |
| 3815 | { 0x10, 0xc07f }, |
| 3816 | { 0x19, 0x7030 }, |
| 3817 | { 0x1f, 0x0000 } |
| 3818 | }; |
| 3819 | |
| 3820 | /* Disable ALDPS before ram code */ |
Francois Romieu | eef63cc | 2013-02-08 23:43:20 +0100 | [diff] [blame] | 3821 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3822 | rtl_writephy(tp, 0x18, 0x0310); |
| 3823 | msleep(100); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3824 | |
| 3825 | rtl_apply_firmware(tp); |
| 3826 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3827 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3828 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3829 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3830 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3831 | } |
| 3832 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3833 | static void rtl_hw_phy_config(struct net_device *dev) |
| 3834 | { |
| 3835 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3836 | |
| 3837 | rtl8169_print_mac_version(tp); |
| 3838 | |
| 3839 | switch (tp->mac_version) { |
| 3840 | case RTL_GIGA_MAC_VER_01: |
| 3841 | break; |
| 3842 | case RTL_GIGA_MAC_VER_02: |
| 3843 | case RTL_GIGA_MAC_VER_03: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3844 | rtl8169s_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3845 | break; |
| 3846 | case RTL_GIGA_MAC_VER_04: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3847 | rtl8169sb_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3848 | break; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3849 | case RTL_GIGA_MAC_VER_05: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3850 | rtl8169scd_hw_phy_config(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3851 | break; |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 3852 | case RTL_GIGA_MAC_VER_06: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3853 | rtl8169sce_hw_phy_config(tp); |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 3854 | break; |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3855 | case RTL_GIGA_MAC_VER_07: |
| 3856 | case RTL_GIGA_MAC_VER_08: |
| 3857 | case RTL_GIGA_MAC_VER_09: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3858 | rtl8102e_hw_phy_config(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3859 | break; |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3860 | case RTL_GIGA_MAC_VER_11: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3861 | rtl8168bb_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3862 | break; |
| 3863 | case RTL_GIGA_MAC_VER_12: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3864 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3865 | break; |
| 3866 | case RTL_GIGA_MAC_VER_17: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3867 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3868 | break; |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3869 | case RTL_GIGA_MAC_VER_18: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3870 | rtl8168cp_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3871 | break; |
| 3872 | case RTL_GIGA_MAC_VER_19: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3873 | rtl8168c_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3874 | break; |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3875 | case RTL_GIGA_MAC_VER_20: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3876 | rtl8168c_2_hw_phy_config(tp); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3877 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3878 | case RTL_GIGA_MAC_VER_21: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3879 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3880 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3881 | case RTL_GIGA_MAC_VER_22: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3882 | rtl8168c_4_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3883 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3884 | case RTL_GIGA_MAC_VER_23: |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 3885 | case RTL_GIGA_MAC_VER_24: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3886 | rtl8168cp_2_hw_phy_config(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3887 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3888 | case RTL_GIGA_MAC_VER_25: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3889 | rtl8168d_1_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3890 | break; |
| 3891 | case RTL_GIGA_MAC_VER_26: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3892 | rtl8168d_2_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3893 | break; |
| 3894 | case RTL_GIGA_MAC_VER_27: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3895 | rtl8168d_3_hw_phy_config(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3896 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3897 | case RTL_GIGA_MAC_VER_28: |
| 3898 | rtl8168d_4_hw_phy_config(tp); |
| 3899 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3900 | case RTL_GIGA_MAC_VER_29: |
| 3901 | case RTL_GIGA_MAC_VER_30: |
| 3902 | rtl8105e_hw_phy_config(tp); |
| 3903 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3904 | case RTL_GIGA_MAC_VER_31: |
| 3905 | /* None. */ |
| 3906 | break; |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3907 | case RTL_GIGA_MAC_VER_32: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3908 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3909 | rtl8168e_1_hw_phy_config(tp); |
| 3910 | break; |
| 3911 | case RTL_GIGA_MAC_VER_34: |
| 3912 | rtl8168e_2_hw_phy_config(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3913 | break; |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3914 | case RTL_GIGA_MAC_VER_35: |
| 3915 | rtl8168f_1_hw_phy_config(tp); |
| 3916 | break; |
| 3917 | case RTL_GIGA_MAC_VER_36: |
| 3918 | rtl8168f_2_hw_phy_config(tp); |
| 3919 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3920 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3921 | case RTL_GIGA_MAC_VER_37: |
| 3922 | rtl8402_hw_phy_config(tp); |
| 3923 | break; |
| 3924 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3925 | case RTL_GIGA_MAC_VER_38: |
| 3926 | rtl8411_hw_phy_config(tp); |
| 3927 | break; |
| 3928 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3929 | case RTL_GIGA_MAC_VER_39: |
| 3930 | rtl8106e_hw_phy_config(tp); |
| 3931 | break; |
| 3932 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3933 | case RTL_GIGA_MAC_VER_40: |
| 3934 | rtl8168g_1_hw_phy_config(tp); |
| 3935 | break; |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 3936 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 3937 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 3938 | case RTL_GIGA_MAC_VER_44: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 3939 | rtl8168g_2_hw_phy_config(tp); |
| 3940 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 3941 | case RTL_GIGA_MAC_VER_45: |
| 3942 | case RTL_GIGA_MAC_VER_47: |
| 3943 | rtl8168h_1_hw_phy_config(tp); |
| 3944 | break; |
| 3945 | case RTL_GIGA_MAC_VER_46: |
| 3946 | case RTL_GIGA_MAC_VER_48: |
| 3947 | rtl8168h_2_hw_phy_config(tp); |
| 3948 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3949 | |
| 3950 | case RTL_GIGA_MAC_VER_41: |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3951 | default: |
| 3952 | break; |
| 3953 | } |
| 3954 | } |
| 3955 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3956 | static void rtl_phy_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3957 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3958 | struct timer_list *timer = &tp->timer; |
| 3959 | void __iomem *ioaddr = tp->mmio_addr; |
| 3960 | unsigned long timeout = RTL8169_PHY_TIMEOUT; |
| 3961 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 3962 | assert(tp->mac_version > RTL_GIGA_MAC_VER_01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3963 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3964 | if (tp->phy_reset_pending(tp)) { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 3965 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3966 | * A busy loop could burn quite a few cycles on nowadays CPU. |
| 3967 | * Let's delay the execution of the timer for a few ticks. |
| 3968 | */ |
| 3969 | timeout = HZ/10; |
| 3970 | goto out_mod_timer; |
| 3971 | } |
| 3972 | |
| 3973 | if (tp->link_ok(ioaddr)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3974 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3975 | |
Lekensteyn | 9bb8eeb | 2013-08-02 10:36:55 +0200 | [diff] [blame] | 3976 | netif_dbg(tp, link, tp->dev, "PHY reset until link up\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3977 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3978 | tp->phy_reset_enable(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3979 | |
| 3980 | out_mod_timer: |
| 3981 | mod_timer(timer, jiffies + timeout); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3982 | } |
| 3983 | |
| 3984 | static void rtl_schedule_task(struct rtl8169_private *tp, enum rtl_flag flag) |
| 3985 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3986 | if (!test_and_set_bit(flag, tp->wk.flags)) |
| 3987 | schedule_work(&tp->wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3988 | } |
| 3989 | |
| 3990 | static void rtl8169_phy_timer(unsigned long __opaque) |
| 3991 | { |
| 3992 | struct net_device *dev = (struct net_device *)__opaque; |
| 3993 | struct rtl8169_private *tp = netdev_priv(dev); |
| 3994 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 3995 | rtl_schedule_task(tp, RTL_FLAG_TASK_PHY_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3996 | } |
| 3997 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3998 | static void rtl8169_release_board(struct pci_dev *pdev, struct net_device *dev, |
| 3999 | void __iomem *ioaddr) |
| 4000 | { |
| 4001 | iounmap(ioaddr); |
| 4002 | pci_release_regions(pdev); |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 4003 | pci_clear_mwi(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4004 | pci_disable_device(pdev); |
| 4005 | free_netdev(dev); |
| 4006 | } |
| 4007 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4008 | DECLARE_RTL_COND(rtl_phy_reset_cond) |
| 4009 | { |
| 4010 | return tp->phy_reset_pending(tp); |
| 4011 | } |
| 4012 | |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 4013 | static void rtl8169_phy_reset(struct net_device *dev, |
| 4014 | struct rtl8169_private *tp) |
| 4015 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4016 | tp->phy_reset_enable(tp); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4017 | rtl_msleep_loop_wait_low(tp, &rtl_phy_reset_cond, 1, 100); |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 4018 | } |
| 4019 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4020 | static bool rtl_tbi_enabled(struct rtl8169_private *tp) |
| 4021 | { |
| 4022 | void __iomem *ioaddr = tp->mmio_addr; |
| 4023 | |
| 4024 | return (tp->mac_version == RTL_GIGA_MAC_VER_01) && |
| 4025 | (RTL_R8(PHYstatus) & TBI_Enable); |
| 4026 | } |
| 4027 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4028 | 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] | 4029 | { |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4030 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4031 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 4032 | rtl_hw_phy_config(dev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4033 | |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 4034 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
| 4035 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
| 4036 | RTL_W8(0x82, 0x01); |
| 4037 | } |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4038 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4039 | pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); |
| 4040 | |
| 4041 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
| 4042 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4043 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4044 | if (tp->mac_version == RTL_GIGA_MAC_VER_02) { |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4045 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
| 4046 | RTL_W8(0x82, 0x01); |
| 4047 | dprintk("Set PHY Reg 0x0bh = 0x00h\n"); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4048 | rtl_writephy(tp, 0x0b, 0x0000); //w 0x0b 15 0 0 |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4049 | } |
| 4050 | |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 4051 | rtl8169_phy_reset(dev, tp); |
| 4052 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 4053 | rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4054 | ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 4055 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 4056 | (tp->mii.supports_gmii ? |
| 4057 | ADVERTISED_1000baseT_Half | |
| 4058 | ADVERTISED_1000baseT_Full : 0)); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4059 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4060 | if (rtl_tbi_enabled(tp)) |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 4061 | netif_info(tp, link, dev, "TBI auto-negotiating\n"); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4062 | } |
| 4063 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4064 | static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr) |
| 4065 | { |
| 4066 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4067 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4068 | rtl_lock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4069 | |
| 4070 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4071 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 4072 | RTL_W32(MAC4, addr[4] | addr[5] << 8); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 4073 | RTL_R32(MAC4); |
| 4074 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 4075 | 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] | 4076 | RTL_R32(MAC0); |
| 4077 | |
françois romieu | 9ecb9aa | 2012-12-07 11:20:21 +0000 | [diff] [blame] | 4078 | if (tp->mac_version == RTL_GIGA_MAC_VER_34) |
| 4079 | rtl_rar_exgmac_set(tp, addr); |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 4080 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4081 | RTL_W8(Cfg9346, Cfg9346_Lock); |
| 4082 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4083 | rtl_unlock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 4084 | } |
| 4085 | |
| 4086 | static int rtl_set_mac_address(struct net_device *dev, void *p) |
| 4087 | { |
| 4088 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4089 | struct sockaddr *addr = p; |
| 4090 | |
| 4091 | if (!is_valid_ether_addr(addr->sa_data)) |
| 4092 | return -EADDRNOTAVAIL; |
| 4093 | |
| 4094 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 4095 | |
| 4096 | rtl_rar_set(tp, dev->dev_addr); |
| 4097 | |
| 4098 | return 0; |
| 4099 | } |
| 4100 | |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4101 | static int rtl8169_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 4102 | { |
| 4103 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4104 | struct mii_ioctl_data *data = if_mii(ifr); |
| 4105 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4106 | return netif_running(dev) ? tp->do_ioctl(tp, data, cmd) : -ENODEV; |
| 4107 | } |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4108 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4109 | static int rtl_xmii_ioctl(struct rtl8169_private *tp, |
| 4110 | struct mii_ioctl_data *data, int cmd) |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4111 | { |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4112 | switch (cmd) { |
| 4113 | case SIOCGMIIPHY: |
| 4114 | data->phy_id = 32; /* Internal PHY */ |
| 4115 | return 0; |
| 4116 | |
| 4117 | case SIOCGMIIREG: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4118 | data->val_out = rtl_readphy(tp, data->reg_num & 0x1f); |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4119 | return 0; |
| 4120 | |
| 4121 | case SIOCSMIIREG: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 4122 | rtl_writephy(tp, data->reg_num & 0x1f, data->val_in); |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 4123 | return 0; |
| 4124 | } |
| 4125 | return -EOPNOTSUPP; |
| 4126 | } |
| 4127 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4128 | static int rtl_tbi_ioctl(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd) |
| 4129 | { |
| 4130 | return -EOPNOTSUPP; |
| 4131 | } |
| 4132 | |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 4133 | static void rtl_disable_msi(struct pci_dev *pdev, struct rtl8169_private *tp) |
| 4134 | { |
| 4135 | if (tp->features & RTL_FEATURE_MSI) { |
| 4136 | pci_disable_msi(pdev); |
| 4137 | tp->features &= ~RTL_FEATURE_MSI; |
| 4138 | } |
| 4139 | } |
| 4140 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 4141 | static void rtl_init_mdio_ops(struct rtl8169_private *tp) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4142 | { |
| 4143 | struct mdio_ops *ops = &tp->mdio_ops; |
| 4144 | |
| 4145 | switch (tp->mac_version) { |
| 4146 | case RTL_GIGA_MAC_VER_27: |
| 4147 | ops->write = r8168dp_1_mdio_write; |
| 4148 | ops->read = r8168dp_1_mdio_read; |
| 4149 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4150 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4151 | case RTL_GIGA_MAC_VER_31: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4152 | ops->write = r8168dp_2_mdio_write; |
| 4153 | ops->read = r8168dp_2_mdio_read; |
| 4154 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4155 | case RTL_GIGA_MAC_VER_40: |
| 4156 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4157 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 4158 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4159 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4160 | case RTL_GIGA_MAC_VER_45: |
| 4161 | case RTL_GIGA_MAC_VER_46: |
| 4162 | case RTL_GIGA_MAC_VER_47: |
| 4163 | case RTL_GIGA_MAC_VER_48: |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4164 | ops->write = r8168g_mdio_write; |
| 4165 | ops->read = r8168g_mdio_read; |
| 4166 | break; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4167 | default: |
| 4168 | ops->write = r8169_mdio_write; |
| 4169 | ops->read = r8169_mdio_read; |
| 4170 | break; |
| 4171 | } |
| 4172 | } |
| 4173 | |
hayeswang | e2409d8 | 2013-03-31 17:02:04 +0000 | [diff] [blame] | 4174 | static void rtl_speed_down(struct rtl8169_private *tp) |
| 4175 | { |
| 4176 | u32 adv; |
| 4177 | int lpa; |
| 4178 | |
| 4179 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4180 | lpa = rtl_readphy(tp, MII_LPA); |
| 4181 | |
| 4182 | if (lpa & (LPA_10HALF | LPA_10FULL)) |
| 4183 | adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full; |
| 4184 | else if (lpa & (LPA_100HALF | LPA_100FULL)) |
| 4185 | adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 4186 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full; |
| 4187 | else |
| 4188 | adv = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 4189 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 4190 | (tp->mii.supports_gmii ? |
| 4191 | ADVERTISED_1000baseT_Half | |
| 4192 | ADVERTISED_1000baseT_Full : 0); |
| 4193 | |
| 4194 | rtl8169_set_speed(tp->dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL, |
| 4195 | adv); |
| 4196 | } |
| 4197 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4198 | static void rtl_wol_suspend_quirk(struct rtl8169_private *tp) |
| 4199 | { |
| 4200 | void __iomem *ioaddr = tp->mmio_addr; |
| 4201 | |
| 4202 | switch (tp->mac_version) { |
Cyril Brulebois | b00e69d | 2012-10-31 14:00:46 +0000 | [diff] [blame] | 4203 | case RTL_GIGA_MAC_VER_25: |
| 4204 | case RTL_GIGA_MAC_VER_26: |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4205 | case RTL_GIGA_MAC_VER_29: |
| 4206 | case RTL_GIGA_MAC_VER_30: |
| 4207 | case RTL_GIGA_MAC_VER_32: |
| 4208 | case RTL_GIGA_MAC_VER_33: |
| 4209 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4210 | case RTL_GIGA_MAC_VER_37: |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4211 | case RTL_GIGA_MAC_VER_38: |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4212 | case RTL_GIGA_MAC_VER_39: |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4213 | case RTL_GIGA_MAC_VER_40: |
| 4214 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4215 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 4216 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4217 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4218 | case RTL_GIGA_MAC_VER_45: |
| 4219 | case RTL_GIGA_MAC_VER_46: |
| 4220 | case RTL_GIGA_MAC_VER_47: |
| 4221 | case RTL_GIGA_MAC_VER_48: |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4222 | RTL_W32(RxConfig, RTL_R32(RxConfig) | |
| 4223 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys); |
| 4224 | break; |
| 4225 | default: |
| 4226 | break; |
| 4227 | } |
| 4228 | } |
| 4229 | |
| 4230 | static bool rtl_wol_pll_power_down(struct rtl8169_private *tp) |
| 4231 | { |
| 4232 | if (!(__rtl8169_get_wol(tp) & WAKE_ANY)) |
| 4233 | return false; |
| 4234 | |
hayeswang | e2409d8 | 2013-03-31 17:02:04 +0000 | [diff] [blame] | 4235 | rtl_speed_down(tp); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4236 | rtl_wol_suspend_quirk(tp); |
| 4237 | |
| 4238 | return true; |
| 4239 | } |
| 4240 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4241 | static void r810x_phy_power_down(struct rtl8169_private *tp) |
| 4242 | { |
| 4243 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4244 | rtl_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 4245 | } |
| 4246 | |
| 4247 | static void r810x_phy_power_up(struct rtl8169_private *tp) |
| 4248 | { |
| 4249 | rtl_writephy(tp, 0x1f, 0x0000); |
| 4250 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE); |
| 4251 | } |
| 4252 | |
| 4253 | static void r810x_pll_power_down(struct rtl8169_private *tp) |
| 4254 | { |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 4255 | void __iomem *ioaddr = tp->mmio_addr; |
| 4256 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4257 | if (rtl_wol_pll_power_down(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4258 | return; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4259 | |
| 4260 | r810x_phy_power_down(tp); |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 4261 | |
| 4262 | switch (tp->mac_version) { |
| 4263 | case RTL_GIGA_MAC_VER_07: |
| 4264 | case RTL_GIGA_MAC_VER_08: |
| 4265 | case RTL_GIGA_MAC_VER_09: |
| 4266 | case RTL_GIGA_MAC_VER_10: |
| 4267 | case RTL_GIGA_MAC_VER_13: |
| 4268 | case RTL_GIGA_MAC_VER_16: |
| 4269 | break; |
| 4270 | default: |
| 4271 | RTL_W8(PMCH, RTL_R8(PMCH) & ~0x80); |
| 4272 | break; |
| 4273 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4274 | } |
| 4275 | |
| 4276 | static void r810x_pll_power_up(struct rtl8169_private *tp) |
| 4277 | { |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 4278 | void __iomem *ioaddr = tp->mmio_addr; |
| 4279 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4280 | r810x_phy_power_up(tp); |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 4281 | |
| 4282 | switch (tp->mac_version) { |
| 4283 | case RTL_GIGA_MAC_VER_07: |
| 4284 | case RTL_GIGA_MAC_VER_08: |
| 4285 | case RTL_GIGA_MAC_VER_09: |
| 4286 | case RTL_GIGA_MAC_VER_10: |
| 4287 | case RTL_GIGA_MAC_VER_13: |
| 4288 | case RTL_GIGA_MAC_VER_16: |
| 4289 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4290 | case RTL_GIGA_MAC_VER_47: |
| 4291 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 4292 | RTL_W8(PMCH, RTL_R8(PMCH) | 0xc0); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4293 | break; |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 4294 | default: |
| 4295 | RTL_W8(PMCH, RTL_R8(PMCH) | 0x80); |
| 4296 | break; |
| 4297 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4298 | } |
| 4299 | |
| 4300 | static void r8168_phy_power_up(struct rtl8169_private *tp) |
| 4301 | { |
| 4302 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4303 | switch (tp->mac_version) { |
| 4304 | case RTL_GIGA_MAC_VER_11: |
| 4305 | case RTL_GIGA_MAC_VER_12: |
| 4306 | case RTL_GIGA_MAC_VER_17: |
| 4307 | case RTL_GIGA_MAC_VER_18: |
| 4308 | case RTL_GIGA_MAC_VER_19: |
| 4309 | case RTL_GIGA_MAC_VER_20: |
| 4310 | case RTL_GIGA_MAC_VER_21: |
| 4311 | case RTL_GIGA_MAC_VER_22: |
| 4312 | case RTL_GIGA_MAC_VER_23: |
| 4313 | case RTL_GIGA_MAC_VER_24: |
| 4314 | case RTL_GIGA_MAC_VER_25: |
| 4315 | case RTL_GIGA_MAC_VER_26: |
| 4316 | case RTL_GIGA_MAC_VER_27: |
| 4317 | case RTL_GIGA_MAC_VER_28: |
| 4318 | case RTL_GIGA_MAC_VER_31: |
| 4319 | rtl_writephy(tp, 0x0e, 0x0000); |
| 4320 | break; |
| 4321 | default: |
| 4322 | break; |
| 4323 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4324 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE); |
| 4325 | } |
| 4326 | |
| 4327 | static void r8168_phy_power_down(struct rtl8169_private *tp) |
| 4328 | { |
| 4329 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4330 | switch (tp->mac_version) { |
| 4331 | case RTL_GIGA_MAC_VER_32: |
| 4332 | case RTL_GIGA_MAC_VER_33: |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4333 | case RTL_GIGA_MAC_VER_40: |
| 4334 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4335 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE | BMCR_PDOWN); |
| 4336 | break; |
| 4337 | |
| 4338 | case RTL_GIGA_MAC_VER_11: |
| 4339 | case RTL_GIGA_MAC_VER_12: |
| 4340 | case RTL_GIGA_MAC_VER_17: |
| 4341 | case RTL_GIGA_MAC_VER_18: |
| 4342 | case RTL_GIGA_MAC_VER_19: |
| 4343 | case RTL_GIGA_MAC_VER_20: |
| 4344 | case RTL_GIGA_MAC_VER_21: |
| 4345 | case RTL_GIGA_MAC_VER_22: |
| 4346 | case RTL_GIGA_MAC_VER_23: |
| 4347 | case RTL_GIGA_MAC_VER_24: |
| 4348 | case RTL_GIGA_MAC_VER_25: |
| 4349 | case RTL_GIGA_MAC_VER_26: |
| 4350 | case RTL_GIGA_MAC_VER_27: |
| 4351 | case RTL_GIGA_MAC_VER_28: |
| 4352 | case RTL_GIGA_MAC_VER_31: |
| 4353 | rtl_writephy(tp, 0x0e, 0x0200); |
| 4354 | default: |
| 4355 | rtl_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 4356 | break; |
| 4357 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4358 | } |
| 4359 | |
| 4360 | static void r8168_pll_power_down(struct rtl8169_private *tp) |
| 4361 | { |
| 4362 | void __iomem *ioaddr = tp->mmio_addr; |
| 4363 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4364 | if ((tp->mac_version == RTL_GIGA_MAC_VER_27 || |
| 4365 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 4366 | tp->mac_version == RTL_GIGA_MAC_VER_31) && |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4367 | r8168dp_check_dash(tp)) { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4368 | return; |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 4369 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4370 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4371 | if ((tp->mac_version == RTL_GIGA_MAC_VER_23 || |
| 4372 | tp->mac_version == RTL_GIGA_MAC_VER_24) && |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4373 | (RTL_R16(CPlusCmd) & ASF)) { |
| 4374 | return; |
| 4375 | } |
| 4376 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4377 | if (tp->mac_version == RTL_GIGA_MAC_VER_32 || |
| 4378 | tp->mac_version == RTL_GIGA_MAC_VER_33) |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4379 | rtl_ephy_write(tp, 0x19, 0xff64); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4380 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4381 | if (rtl_wol_pll_power_down(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4382 | return; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4383 | |
| 4384 | r8168_phy_power_down(tp); |
| 4385 | |
| 4386 | switch (tp->mac_version) { |
| 4387 | case RTL_GIGA_MAC_VER_25: |
| 4388 | case RTL_GIGA_MAC_VER_26: |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 4389 | case RTL_GIGA_MAC_VER_27: |
| 4390 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4391 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4392 | case RTL_GIGA_MAC_VER_32: |
| 4393 | case RTL_GIGA_MAC_VER_33: |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 4394 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4395 | case RTL_GIGA_MAC_VER_45: |
| 4396 | case RTL_GIGA_MAC_VER_46: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4397 | RTL_W8(PMCH, RTL_R8(PMCH) & ~0x80); |
| 4398 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4399 | case RTL_GIGA_MAC_VER_40: |
| 4400 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame^] | 4401 | rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0x00000000, |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4402 | 0xfc000000, ERIAR_EXGMAC); |
Chun-Hao Lin | b8e5e6a | 2014-10-01 23:17:13 +0800 | [diff] [blame] | 4403 | RTL_W8(PMCH, RTL_R8(PMCH) & ~0x80); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4404 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4405 | } |
| 4406 | } |
| 4407 | |
| 4408 | static void r8168_pll_power_up(struct rtl8169_private *tp) |
| 4409 | { |
| 4410 | void __iomem *ioaddr = tp->mmio_addr; |
| 4411 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4412 | switch (tp->mac_version) { |
| 4413 | case RTL_GIGA_MAC_VER_25: |
| 4414 | case RTL_GIGA_MAC_VER_26: |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 4415 | case RTL_GIGA_MAC_VER_27: |
| 4416 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4417 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4418 | case RTL_GIGA_MAC_VER_32: |
| 4419 | case RTL_GIGA_MAC_VER_33: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4420 | RTL_W8(PMCH, RTL_R8(PMCH) | 0x80); |
| 4421 | break; |
Chun-Hao Lin | 42fde73 | 2014-10-01 23:17:14 +0800 | [diff] [blame] | 4422 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4423 | case RTL_GIGA_MAC_VER_45: |
| 4424 | case RTL_GIGA_MAC_VER_46: |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 4425 | RTL_W8(PMCH, RTL_R8(PMCH) | 0xc0); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4426 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4427 | case RTL_GIGA_MAC_VER_40: |
| 4428 | case RTL_GIGA_MAC_VER_41: |
Chun-Hao Lin | b8e5e6a | 2014-10-01 23:17:13 +0800 | [diff] [blame] | 4429 | RTL_W8(PMCH, RTL_R8(PMCH) | 0xc0); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame^] | 4430 | rtl_w0w1_eri(tp, 0x1a8, ERIAR_MASK_1111, 0xfc000000, |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4431 | 0x00000000, ERIAR_EXGMAC); |
| 4432 | break; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4433 | } |
| 4434 | |
| 4435 | r8168_phy_power_up(tp); |
| 4436 | } |
| 4437 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4438 | static void rtl_generic_op(struct rtl8169_private *tp, |
| 4439 | void (*op)(struct rtl8169_private *)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4440 | { |
| 4441 | if (op) |
| 4442 | op(tp); |
| 4443 | } |
| 4444 | |
| 4445 | static void rtl_pll_power_down(struct rtl8169_private *tp) |
| 4446 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4447 | rtl_generic_op(tp, tp->pll_power_ops.down); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4448 | } |
| 4449 | |
| 4450 | static void rtl_pll_power_up(struct rtl8169_private *tp) |
| 4451 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4452 | rtl_generic_op(tp, tp->pll_power_ops.up); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4453 | } |
| 4454 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 4455 | static void rtl_init_pll_power_ops(struct rtl8169_private *tp) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4456 | { |
| 4457 | struct pll_power_ops *ops = &tp->pll_power_ops; |
| 4458 | |
| 4459 | switch (tp->mac_version) { |
| 4460 | case RTL_GIGA_MAC_VER_07: |
| 4461 | case RTL_GIGA_MAC_VER_08: |
| 4462 | case RTL_GIGA_MAC_VER_09: |
| 4463 | case RTL_GIGA_MAC_VER_10: |
| 4464 | case RTL_GIGA_MAC_VER_16: |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4465 | case RTL_GIGA_MAC_VER_29: |
| 4466 | case RTL_GIGA_MAC_VER_30: |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4467 | case RTL_GIGA_MAC_VER_37: |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4468 | case RTL_GIGA_MAC_VER_39: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 4469 | case RTL_GIGA_MAC_VER_43: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4470 | case RTL_GIGA_MAC_VER_47: |
| 4471 | case RTL_GIGA_MAC_VER_48: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4472 | ops->down = r810x_pll_power_down; |
| 4473 | ops->up = r810x_pll_power_up; |
| 4474 | break; |
| 4475 | |
| 4476 | case RTL_GIGA_MAC_VER_11: |
| 4477 | case RTL_GIGA_MAC_VER_12: |
| 4478 | case RTL_GIGA_MAC_VER_17: |
| 4479 | case RTL_GIGA_MAC_VER_18: |
| 4480 | case RTL_GIGA_MAC_VER_19: |
| 4481 | case RTL_GIGA_MAC_VER_20: |
| 4482 | case RTL_GIGA_MAC_VER_21: |
| 4483 | case RTL_GIGA_MAC_VER_22: |
| 4484 | case RTL_GIGA_MAC_VER_23: |
| 4485 | case RTL_GIGA_MAC_VER_24: |
| 4486 | case RTL_GIGA_MAC_VER_25: |
| 4487 | case RTL_GIGA_MAC_VER_26: |
| 4488 | case RTL_GIGA_MAC_VER_27: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4489 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4490 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4491 | case RTL_GIGA_MAC_VER_32: |
| 4492 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4493 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4494 | case RTL_GIGA_MAC_VER_35: |
| 4495 | case RTL_GIGA_MAC_VER_36: |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4496 | case RTL_GIGA_MAC_VER_38: |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4497 | case RTL_GIGA_MAC_VER_40: |
| 4498 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4499 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4500 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4501 | case RTL_GIGA_MAC_VER_45: |
| 4502 | case RTL_GIGA_MAC_VER_46: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4503 | ops->down = r8168_pll_power_down; |
| 4504 | ops->up = r8168_pll_power_up; |
| 4505 | break; |
| 4506 | |
| 4507 | default: |
| 4508 | ops->down = NULL; |
| 4509 | ops->up = NULL; |
| 4510 | break; |
| 4511 | } |
| 4512 | } |
| 4513 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4514 | static void rtl_init_rxcfg(struct rtl8169_private *tp) |
| 4515 | { |
| 4516 | void __iomem *ioaddr = tp->mmio_addr; |
| 4517 | |
| 4518 | switch (tp->mac_version) { |
| 4519 | case RTL_GIGA_MAC_VER_01: |
| 4520 | case RTL_GIGA_MAC_VER_02: |
| 4521 | case RTL_GIGA_MAC_VER_03: |
| 4522 | case RTL_GIGA_MAC_VER_04: |
| 4523 | case RTL_GIGA_MAC_VER_05: |
| 4524 | case RTL_GIGA_MAC_VER_06: |
| 4525 | case RTL_GIGA_MAC_VER_10: |
| 4526 | case RTL_GIGA_MAC_VER_11: |
| 4527 | case RTL_GIGA_MAC_VER_12: |
| 4528 | case RTL_GIGA_MAC_VER_13: |
| 4529 | case RTL_GIGA_MAC_VER_14: |
| 4530 | case RTL_GIGA_MAC_VER_15: |
| 4531 | case RTL_GIGA_MAC_VER_16: |
| 4532 | case RTL_GIGA_MAC_VER_17: |
| 4533 | RTL_W32(RxConfig, RX_FIFO_THRESH | RX_DMA_BURST); |
| 4534 | break; |
| 4535 | case RTL_GIGA_MAC_VER_18: |
| 4536 | case RTL_GIGA_MAC_VER_19: |
| 4537 | case RTL_GIGA_MAC_VER_20: |
| 4538 | case RTL_GIGA_MAC_VER_21: |
| 4539 | case RTL_GIGA_MAC_VER_22: |
| 4540 | case RTL_GIGA_MAC_VER_23: |
| 4541 | case RTL_GIGA_MAC_VER_24: |
françois romieu | eb2dc35 | 2012-06-20 12:09:18 +0000 | [diff] [blame] | 4542 | case RTL_GIGA_MAC_VER_34: |
françois romieu | 3ced8c9 | 2013-09-08 01:15:35 +0200 | [diff] [blame] | 4543 | case RTL_GIGA_MAC_VER_35: |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4544 | RTL_W32(RxConfig, RX128_INT_EN | RX_MULTI_EN | RX_DMA_BURST); |
| 4545 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4546 | case RTL_GIGA_MAC_VER_40: |
Michel Dänzer | 7a9810e | 2014-07-17 12:55:40 +0900 | [diff] [blame] | 4547 | RTL_W32(RxConfig, RX128_INT_EN | RX_MULTI_EN | RX_DMA_BURST | RX_EARLY_OFF); |
| 4548 | break; |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4549 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4550 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 4551 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4552 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4553 | case RTL_GIGA_MAC_VER_45: |
| 4554 | case RTL_GIGA_MAC_VER_46: |
| 4555 | case RTL_GIGA_MAC_VER_47: |
| 4556 | case RTL_GIGA_MAC_VER_48: |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 4557 | RTL_W32(RxConfig, RX128_INT_EN | RX_DMA_BURST | RX_EARLY_OFF); |
| 4558 | break; |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4559 | default: |
| 4560 | RTL_W32(RxConfig, RX128_INT_EN | RX_DMA_BURST); |
| 4561 | break; |
| 4562 | } |
| 4563 | } |
| 4564 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4565 | static void rtl8169_init_ring_indexes(struct rtl8169_private *tp) |
| 4566 | { |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 4567 | tp->dirty_tx = tp->cur_tx = tp->cur_rx = 0; |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4568 | } |
| 4569 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4570 | static void rtl_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4571 | { |
françois romieu | 9c5028e | 2012-03-02 04:43:14 +0000 | [diff] [blame] | 4572 | void __iomem *ioaddr = tp->mmio_addr; |
| 4573 | |
| 4574 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4575 | rtl_generic_op(tp, tp->jumbo_ops.enable); |
françois romieu | 9c5028e | 2012-03-02 04:43:14 +0000 | [diff] [blame] | 4576 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4577 | } |
| 4578 | |
| 4579 | static void rtl_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4580 | { |
françois romieu | 9c5028e | 2012-03-02 04:43:14 +0000 | [diff] [blame] | 4581 | void __iomem *ioaddr = tp->mmio_addr; |
| 4582 | |
| 4583 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4584 | rtl_generic_op(tp, tp->jumbo_ops.disable); |
françois romieu | 9c5028e | 2012-03-02 04:43:14 +0000 | [diff] [blame] | 4585 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4586 | } |
| 4587 | |
| 4588 | static void r8168c_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4589 | { |
| 4590 | void __iomem *ioaddr = tp->mmio_addr; |
| 4591 | |
| 4592 | RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0); |
| 4593 | RTL_W8(Config4, RTL_R8(Config4) | Jumbo_En1); |
| 4594 | rtl_tx_performance_tweak(tp->pci_dev, 0x2 << MAX_READ_REQUEST_SHIFT); |
| 4595 | } |
| 4596 | |
| 4597 | static void r8168c_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4598 | { |
| 4599 | void __iomem *ioaddr = tp->mmio_addr; |
| 4600 | |
| 4601 | RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0); |
| 4602 | RTL_W8(Config4, RTL_R8(Config4) & ~Jumbo_En1); |
| 4603 | rtl_tx_performance_tweak(tp->pci_dev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4604 | } |
| 4605 | |
| 4606 | static void r8168dp_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4607 | { |
| 4608 | void __iomem *ioaddr = tp->mmio_addr; |
| 4609 | |
| 4610 | RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0); |
| 4611 | } |
| 4612 | |
| 4613 | static void r8168dp_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4614 | { |
| 4615 | void __iomem *ioaddr = tp->mmio_addr; |
| 4616 | |
| 4617 | RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0); |
| 4618 | } |
| 4619 | |
| 4620 | static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4621 | { |
| 4622 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4623 | |
| 4624 | RTL_W8(MaxTxPacketSize, 0x3f); |
| 4625 | RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0); |
| 4626 | RTL_W8(Config4, RTL_R8(Config4) | 0x01); |
Francois Romieu | 4512ff9 | 2011-12-22 18:59:37 +0100 | [diff] [blame] | 4627 | rtl_tx_performance_tweak(tp->pci_dev, 0x2 << MAX_READ_REQUEST_SHIFT); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4628 | } |
| 4629 | |
| 4630 | static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4631 | { |
| 4632 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4633 | |
| 4634 | RTL_W8(MaxTxPacketSize, 0x0c); |
| 4635 | RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0); |
| 4636 | RTL_W8(Config4, RTL_R8(Config4) & ~0x01); |
Francois Romieu | 4512ff9 | 2011-12-22 18:59:37 +0100 | [diff] [blame] | 4637 | rtl_tx_performance_tweak(tp->pci_dev, 0x5 << MAX_READ_REQUEST_SHIFT); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4638 | } |
| 4639 | |
| 4640 | static void r8168b_0_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4641 | { |
| 4642 | rtl_tx_performance_tweak(tp->pci_dev, |
| 4643 | (0x2 << MAX_READ_REQUEST_SHIFT) | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 4644 | } |
| 4645 | |
| 4646 | static void r8168b_0_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4647 | { |
| 4648 | rtl_tx_performance_tweak(tp->pci_dev, |
| 4649 | (0x5 << MAX_READ_REQUEST_SHIFT) | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 4650 | } |
| 4651 | |
| 4652 | static void r8168b_1_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4653 | { |
| 4654 | void __iomem *ioaddr = tp->mmio_addr; |
| 4655 | |
| 4656 | r8168b_0_hw_jumbo_enable(tp); |
| 4657 | |
| 4658 | RTL_W8(Config4, RTL_R8(Config4) | (1 << 0)); |
| 4659 | } |
| 4660 | |
| 4661 | static void r8168b_1_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4662 | { |
| 4663 | void __iomem *ioaddr = tp->mmio_addr; |
| 4664 | |
| 4665 | r8168b_0_hw_jumbo_disable(tp); |
| 4666 | |
| 4667 | RTL_W8(Config4, RTL_R8(Config4) & ~(1 << 0)); |
| 4668 | } |
| 4669 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 4670 | static void rtl_init_jumbo_ops(struct rtl8169_private *tp) |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4671 | { |
| 4672 | struct jumbo_ops *ops = &tp->jumbo_ops; |
| 4673 | |
| 4674 | switch (tp->mac_version) { |
| 4675 | case RTL_GIGA_MAC_VER_11: |
| 4676 | ops->disable = r8168b_0_hw_jumbo_disable; |
| 4677 | ops->enable = r8168b_0_hw_jumbo_enable; |
| 4678 | break; |
| 4679 | case RTL_GIGA_MAC_VER_12: |
| 4680 | case RTL_GIGA_MAC_VER_17: |
| 4681 | ops->disable = r8168b_1_hw_jumbo_disable; |
| 4682 | ops->enable = r8168b_1_hw_jumbo_enable; |
| 4683 | break; |
| 4684 | case RTL_GIGA_MAC_VER_18: /* Wild guess. Needs info from Realtek. */ |
| 4685 | case RTL_GIGA_MAC_VER_19: |
| 4686 | case RTL_GIGA_MAC_VER_20: |
| 4687 | case RTL_GIGA_MAC_VER_21: /* Wild guess. Needs info from Realtek. */ |
| 4688 | case RTL_GIGA_MAC_VER_22: |
| 4689 | case RTL_GIGA_MAC_VER_23: |
| 4690 | case RTL_GIGA_MAC_VER_24: |
| 4691 | case RTL_GIGA_MAC_VER_25: |
| 4692 | case RTL_GIGA_MAC_VER_26: |
| 4693 | ops->disable = r8168c_hw_jumbo_disable; |
| 4694 | ops->enable = r8168c_hw_jumbo_enable; |
| 4695 | break; |
| 4696 | case RTL_GIGA_MAC_VER_27: |
| 4697 | case RTL_GIGA_MAC_VER_28: |
| 4698 | ops->disable = r8168dp_hw_jumbo_disable; |
| 4699 | ops->enable = r8168dp_hw_jumbo_enable; |
| 4700 | break; |
| 4701 | case RTL_GIGA_MAC_VER_31: /* Wild guess. Needs info from Realtek. */ |
| 4702 | case RTL_GIGA_MAC_VER_32: |
| 4703 | case RTL_GIGA_MAC_VER_33: |
| 4704 | case RTL_GIGA_MAC_VER_34: |
| 4705 | ops->disable = r8168e_hw_jumbo_disable; |
| 4706 | ops->enable = r8168e_hw_jumbo_enable; |
| 4707 | break; |
| 4708 | |
| 4709 | /* |
| 4710 | * No action needed for jumbo frames with 8169. |
| 4711 | * No jumbo for 810x at all. |
| 4712 | */ |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4713 | case RTL_GIGA_MAC_VER_40: |
| 4714 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 4715 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 4716 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 4717 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4718 | case RTL_GIGA_MAC_VER_45: |
| 4719 | case RTL_GIGA_MAC_VER_46: |
| 4720 | case RTL_GIGA_MAC_VER_47: |
| 4721 | case RTL_GIGA_MAC_VER_48: |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4722 | default: |
| 4723 | ops->disable = NULL; |
| 4724 | ops->enable = NULL; |
| 4725 | break; |
| 4726 | } |
| 4727 | } |
| 4728 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4729 | DECLARE_RTL_COND(rtl_chipcmd_cond) |
| 4730 | { |
| 4731 | void __iomem *ioaddr = tp->mmio_addr; |
| 4732 | |
| 4733 | return RTL_R8(ChipCmd) & CmdReset; |
| 4734 | } |
| 4735 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4736 | static void rtl_hw_reset(struct rtl8169_private *tp) |
| 4737 | { |
| 4738 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4739 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4740 | RTL_W8(ChipCmd, CmdReset); |
| 4741 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4742 | rtl_udelay_loop_wait_low(tp, &rtl_chipcmd_cond, 100, 100); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4743 | } |
| 4744 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4745 | static void rtl_request_uncached_firmware(struct rtl8169_private *tp) |
| 4746 | { |
| 4747 | struct rtl_fw *rtl_fw; |
| 4748 | const char *name; |
| 4749 | int rc = -ENOMEM; |
| 4750 | |
| 4751 | name = rtl_lookup_firmware_name(tp); |
| 4752 | if (!name) |
| 4753 | goto out_no_firmware; |
| 4754 | |
| 4755 | rtl_fw = kzalloc(sizeof(*rtl_fw), GFP_KERNEL); |
| 4756 | if (!rtl_fw) |
| 4757 | goto err_warn; |
| 4758 | |
| 4759 | rc = request_firmware(&rtl_fw->fw, name, &tp->pci_dev->dev); |
| 4760 | if (rc < 0) |
| 4761 | goto err_free; |
| 4762 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 4763 | rc = rtl_check_firmware(tp, rtl_fw); |
| 4764 | if (rc < 0) |
| 4765 | goto err_release_firmware; |
| 4766 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4767 | tp->rtl_fw = rtl_fw; |
| 4768 | out: |
| 4769 | return; |
| 4770 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 4771 | err_release_firmware: |
| 4772 | release_firmware(rtl_fw->fw); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4773 | err_free: |
| 4774 | kfree(rtl_fw); |
| 4775 | err_warn: |
| 4776 | netif_warn(tp, ifup, tp->dev, "unable to load firmware patch %s (%d)\n", |
| 4777 | name, rc); |
| 4778 | out_no_firmware: |
| 4779 | tp->rtl_fw = NULL; |
| 4780 | goto out; |
| 4781 | } |
| 4782 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4783 | static void rtl_request_firmware(struct rtl8169_private *tp) |
| 4784 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4785 | if (IS_ERR(tp->rtl_fw)) |
| 4786 | rtl_request_uncached_firmware(tp); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4787 | } |
| 4788 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4789 | static void rtl_rx_close(struct rtl8169_private *tp) |
| 4790 | { |
| 4791 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4792 | |
Francois Romieu | 1687b56 | 2011-07-19 17:21:29 +0200 | [diff] [blame] | 4793 | RTL_W32(RxConfig, RTL_R32(RxConfig) & ~RX_CONFIG_ACCEPT_MASK); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4794 | } |
| 4795 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4796 | DECLARE_RTL_COND(rtl_npq_cond) |
| 4797 | { |
| 4798 | void __iomem *ioaddr = tp->mmio_addr; |
| 4799 | |
| 4800 | return RTL_R8(TxPoll) & NPQ; |
| 4801 | } |
| 4802 | |
| 4803 | DECLARE_RTL_COND(rtl_txcfg_empty_cond) |
| 4804 | { |
| 4805 | void __iomem *ioaddr = tp->mmio_addr; |
| 4806 | |
| 4807 | return RTL_R32(TxConfig) & TXCFG_EMPTY; |
| 4808 | } |
| 4809 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4810 | static void rtl8169_hw_reset(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4811 | { |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4812 | void __iomem *ioaddr = tp->mmio_addr; |
| 4813 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4814 | /* Disable interrupts */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 4815 | rtl8169_irq_mask_and_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4816 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4817 | rtl_rx_close(tp); |
| 4818 | |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 4819 | if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4820 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 4821 | tp->mac_version == RTL_GIGA_MAC_VER_31) { |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4822 | rtl_udelay_loop_wait_low(tp, &rtl_npq_cond, 20, 42*42); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4823 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_34 || |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 4824 | tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 4825 | tp->mac_version == RTL_GIGA_MAC_VER_36 || |
| 4826 | tp->mac_version == RTL_GIGA_MAC_VER_37 || |
| 4827 | tp->mac_version == RTL_GIGA_MAC_VER_38 || |
| 4828 | tp->mac_version == RTL_GIGA_MAC_VER_40 || |
| 4829 | tp->mac_version == RTL_GIGA_MAC_VER_41 || |
| 4830 | tp->mac_version == RTL_GIGA_MAC_VER_42 || |
| 4831 | tp->mac_version == RTL_GIGA_MAC_VER_43 || |
| 4832 | tp->mac_version == RTL_GIGA_MAC_VER_44 || |
| 4833 | tp->mac_version == RTL_GIGA_MAC_VER_45 || |
| 4834 | tp->mac_version == RTL_GIGA_MAC_VER_46 || |
| 4835 | tp->mac_version == RTL_GIGA_MAC_VER_47 || |
| 4836 | tp->mac_version == RTL_GIGA_MAC_VER_48) { |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4837 | RTL_W8(ChipCmd, RTL_R8(ChipCmd) | StopReq); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4838 | rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 666); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4839 | } else { |
| 4840 | RTL_W8(ChipCmd, RTL_R8(ChipCmd) | StopReq); |
| 4841 | udelay(100); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4842 | } |
| 4843 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4844 | rtl_hw_reset(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4845 | } |
| 4846 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4847 | static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4848 | { |
| 4849 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4850 | |
| 4851 | /* Set DMA burst size and Interframe Gap Time */ |
| 4852 | RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) | |
| 4853 | (InterFrameGap << TxInterFrameGapShift)); |
| 4854 | } |
| 4855 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4856 | static void rtl_hw_start(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4857 | { |
| 4858 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4859 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4860 | tp->hw_start(dev); |
| 4861 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4862 | rtl_irq_enable_all(tp); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4863 | } |
| 4864 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4865 | static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp, |
| 4866 | void __iomem *ioaddr) |
| 4867 | { |
| 4868 | /* |
| 4869 | * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh |
| 4870 | * register to be written before TxDescAddrLow to work. |
| 4871 | * Switching from MMIO to I/O access fixes the issue as well. |
| 4872 | */ |
| 4873 | RTL_W32(TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 4874 | RTL_W32(TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4875 | RTL_W32(RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 4876 | RTL_W32(RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4877 | } |
| 4878 | |
| 4879 | static u16 rtl_rw_cpluscmd(void __iomem *ioaddr) |
| 4880 | { |
| 4881 | u16 cmd; |
| 4882 | |
| 4883 | cmd = RTL_R16(CPlusCmd); |
| 4884 | RTL_W16(CPlusCmd, cmd); |
| 4885 | return cmd; |
| 4886 | } |
| 4887 | |
Eric Dumazet | fdd7b4c | 2009-06-09 04:01:02 -0700 | [diff] [blame] | 4888 | 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] | 4889 | { |
| 4890 | /* Low hurts. Let's disable the filtering. */ |
Raimonds Cicans | 207d6e87 | 2009-10-26 10:52:37 +0000 | [diff] [blame] | 4891 | RTL_W16(RxMaxSize, rx_buf_sz + 1); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4892 | } |
| 4893 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4894 | static void rtl8169_set_magic_reg(void __iomem *ioaddr, unsigned mac_version) |
| 4895 | { |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 4896 | static const struct rtl_cfg2_info { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4897 | u32 mac_version; |
| 4898 | u32 clk; |
| 4899 | u32 val; |
| 4900 | } cfg2_info [] = { |
| 4901 | { RTL_GIGA_MAC_VER_05, PCI_Clock_33MHz, 0x000fff00 }, // 8110SCd |
| 4902 | { RTL_GIGA_MAC_VER_05, PCI_Clock_66MHz, 0x000fffff }, |
| 4903 | { RTL_GIGA_MAC_VER_06, PCI_Clock_33MHz, 0x00ffff00 }, // 8110SCe |
| 4904 | { RTL_GIGA_MAC_VER_06, PCI_Clock_66MHz, 0x00ffffff } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 4905 | }; |
| 4906 | const struct rtl_cfg2_info *p = cfg2_info; |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4907 | unsigned int i; |
| 4908 | u32 clk; |
| 4909 | |
| 4910 | clk = RTL_R8(Config2) & PCI_Clock_66MHz; |
Francois Romieu | cadf185 | 2008-01-03 23:38:38 +0100 | [diff] [blame] | 4911 | for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4912 | if ((p->mac_version == mac_version) && (p->clk == clk)) { |
| 4913 | RTL_W32(0x7c, p->val); |
| 4914 | break; |
| 4915 | } |
| 4916 | } |
| 4917 | } |
| 4918 | |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4919 | static void rtl_set_rx_mode(struct net_device *dev) |
| 4920 | { |
| 4921 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4922 | void __iomem *ioaddr = tp->mmio_addr; |
| 4923 | u32 mc_filter[2]; /* Multicast hash filter */ |
| 4924 | int rx_mode; |
| 4925 | u32 tmp = 0; |
| 4926 | |
| 4927 | if (dev->flags & IFF_PROMISC) { |
| 4928 | /* Unconditionally log net taps. */ |
| 4929 | netif_notice(tp, link, dev, "Promiscuous mode enabled\n"); |
| 4930 | rx_mode = |
| 4931 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys | |
| 4932 | AcceptAllPhys; |
| 4933 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 4934 | } else if ((netdev_mc_count(dev) > multicast_filter_limit) || |
| 4935 | (dev->flags & IFF_ALLMULTI)) { |
| 4936 | /* Too many to filter perfectly -- accept all multicasts. */ |
| 4937 | rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; |
| 4938 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 4939 | } else { |
| 4940 | struct netdev_hw_addr *ha; |
| 4941 | |
| 4942 | rx_mode = AcceptBroadcast | AcceptMyPhys; |
| 4943 | mc_filter[1] = mc_filter[0] = 0; |
| 4944 | netdev_for_each_mc_addr(ha, dev) { |
| 4945 | int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; |
| 4946 | mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); |
| 4947 | rx_mode |= AcceptMulticast; |
| 4948 | } |
| 4949 | } |
| 4950 | |
| 4951 | if (dev->features & NETIF_F_RXALL) |
| 4952 | rx_mode |= (AcceptErr | AcceptRunt); |
| 4953 | |
| 4954 | tmp = (RTL_R32(RxConfig) & ~RX_CONFIG_ACCEPT_MASK) | rx_mode; |
| 4955 | |
| 4956 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) { |
| 4957 | u32 data = mc_filter[0]; |
| 4958 | |
| 4959 | mc_filter[0] = swab32(mc_filter[1]); |
| 4960 | mc_filter[1] = swab32(data); |
| 4961 | } |
| 4962 | |
Nathan Walp | 0481776 | 2012-11-01 12:08:47 +0000 | [diff] [blame] | 4963 | if (tp->mac_version == RTL_GIGA_MAC_VER_35) |
| 4964 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 4965 | |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4966 | RTL_W32(MAR0 + 4, mc_filter[1]); |
| 4967 | RTL_W32(MAR0 + 0, mc_filter[0]); |
| 4968 | |
| 4969 | RTL_W32(RxConfig, tmp); |
| 4970 | } |
| 4971 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4972 | static void rtl_hw_start_8169(struct net_device *dev) |
| 4973 | { |
| 4974 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4975 | void __iomem *ioaddr = tp->mmio_addr; |
| 4976 | struct pci_dev *pdev = tp->pci_dev; |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4977 | |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4978 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) { |
| 4979 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) | PCIMulRW); |
| 4980 | pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, 0x08); |
| 4981 | } |
| 4982 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4983 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4984 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 || |
| 4985 | tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 4986 | tp->mac_version == RTL_GIGA_MAC_VER_03 || |
| 4987 | tp->mac_version == RTL_GIGA_MAC_VER_04) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4988 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 4989 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4990 | rtl_init_rxcfg(tp); |
| 4991 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 4992 | RTL_W8(EarlyTxThres, NoEarlyTx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4993 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4994 | rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4995 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4996 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 || |
| 4997 | tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 4998 | tp->mac_version == RTL_GIGA_MAC_VER_03 || |
| 4999 | tp->mac_version == RTL_GIGA_MAC_VER_04) |
Francois Romieu | c946b30 | 2007-10-04 00:42:50 +0200 | [diff] [blame] | 5000 | rtl_set_rx_tx_config_registers(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5001 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5002 | tp->cp_cmd |= rtl_rw_cpluscmd(ioaddr) | PCIMulRW; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5003 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5004 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 5005 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 5006 | dprintk("Set MAC Reg C+CR Offset 0xe0. " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5007 | "Bit-3 and bit-14 MUST be 1\n"); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5008 | tp->cp_cmd |= (1 << 14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5009 | } |
| 5010 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5011 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 5012 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5013 | rtl8169_set_magic_reg(ioaddr, tp->mac_version); |
| 5014 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5015 | /* |
| 5016 | * Undocumented corner. Supposedly: |
| 5017 | * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets |
| 5018 | */ |
| 5019 | RTL_W16(IntrMitigate, 0x0000); |
| 5020 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 5021 | rtl_set_rx_tx_desc_registers(tp, ioaddr); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 5022 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5023 | if (tp->mac_version != RTL_GIGA_MAC_VER_01 && |
| 5024 | tp->mac_version != RTL_GIGA_MAC_VER_02 && |
| 5025 | tp->mac_version != RTL_GIGA_MAC_VER_03 && |
| 5026 | tp->mac_version != RTL_GIGA_MAC_VER_04) { |
Francois Romieu | c946b30 | 2007-10-04 00:42:50 +0200 | [diff] [blame] | 5027 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 5028 | rtl_set_rx_tx_config_registers(tp); |
| 5029 | } |
| 5030 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5031 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Francois Romieu | b518fa8 | 2006-08-16 15:23:13 +0200 | [diff] [blame] | 5032 | |
| 5033 | /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ |
| 5034 | RTL_R8(IntrMask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5035 | |
| 5036 | RTL_W32(RxMissed, 0); |
| 5037 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5038 | rtl_set_rx_mode(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5039 | |
| 5040 | /* no early-rx interrupts */ |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 5041 | RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5042 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5043 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5044 | static void rtl_csi_write(struct rtl8169_private *tp, int addr, int value) |
| 5045 | { |
| 5046 | if (tp->csi_ops.write) |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5047 | tp->csi_ops.write(tp, addr, value); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5048 | } |
| 5049 | |
| 5050 | static u32 rtl_csi_read(struct rtl8169_private *tp, int addr) |
| 5051 | { |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5052 | return tp->csi_ops.read ? tp->csi_ops.read(tp, addr) : ~0; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5053 | } |
| 5054 | |
| 5055 | static void rtl_csi_access_enable(struct rtl8169_private *tp, u32 bits) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5056 | { |
| 5057 | u32 csi; |
| 5058 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5059 | csi = rtl_csi_read(tp, 0x070c) & 0x00ffffff; |
| 5060 | rtl_csi_write(tp, 0x070c, csi | bits); |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 5061 | } |
| 5062 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5063 | static void rtl_csi_access_enable_1(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5064 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5065 | rtl_csi_access_enable(tp, 0x17000000); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5066 | } |
| 5067 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5068 | static void rtl_csi_access_enable_2(struct rtl8169_private *tp) |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 5069 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5070 | rtl_csi_access_enable(tp, 0x27000000); |
| 5071 | } |
| 5072 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5073 | DECLARE_RTL_COND(rtl_csiar_cond) |
| 5074 | { |
| 5075 | void __iomem *ioaddr = tp->mmio_addr; |
| 5076 | |
| 5077 | return RTL_R32(CSIAR) & CSIAR_FLAG; |
| 5078 | } |
| 5079 | |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5080 | 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] | 5081 | { |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5082 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5083 | |
| 5084 | RTL_W32(CSIDR, value); |
| 5085 | RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
| 5086 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 5087 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5088 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5089 | } |
| 5090 | |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5091 | static u32 r8169_csi_read(struct rtl8169_private *tp, int addr) |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5092 | { |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5093 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5094 | |
| 5095 | RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) | |
| 5096 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 5097 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5098 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
| 5099 | RTL_R32(CSIDR) : ~0; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5100 | } |
| 5101 | |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5102 | 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] | 5103 | { |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5104 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5105 | |
| 5106 | RTL_W32(CSIDR, value); |
| 5107 | RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
| 5108 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT | |
| 5109 | CSIAR_FUNC_NIC); |
| 5110 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5111 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5112 | } |
| 5113 | |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5114 | static u32 r8402_csi_read(struct rtl8169_private *tp, int addr) |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5115 | { |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 5116 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5117 | |
| 5118 | RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) | CSIAR_FUNC_NIC | |
| 5119 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 5120 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 5121 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
| 5122 | RTL_R32(CSIDR) : ~0; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5123 | } |
| 5124 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5125 | static void r8411_csi_write(struct rtl8169_private *tp, int addr, int value) |
| 5126 | { |
| 5127 | void __iomem *ioaddr = tp->mmio_addr; |
| 5128 | |
| 5129 | RTL_W32(CSIDR, value); |
| 5130 | RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
| 5131 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT | |
| 5132 | CSIAR_FUNC_NIC2); |
| 5133 | |
| 5134 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
| 5135 | } |
| 5136 | |
| 5137 | static u32 r8411_csi_read(struct rtl8169_private *tp, int addr) |
| 5138 | { |
| 5139 | void __iomem *ioaddr = tp->mmio_addr; |
| 5140 | |
| 5141 | RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) | CSIAR_FUNC_NIC2 | |
| 5142 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 5143 | |
| 5144 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
| 5145 | RTL_R32(CSIDR) : ~0; |
| 5146 | } |
| 5147 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 5148 | static void rtl_init_csi_ops(struct rtl8169_private *tp) |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5149 | { |
| 5150 | struct csi_ops *ops = &tp->csi_ops; |
| 5151 | |
| 5152 | switch (tp->mac_version) { |
| 5153 | case RTL_GIGA_MAC_VER_01: |
| 5154 | case RTL_GIGA_MAC_VER_02: |
| 5155 | case RTL_GIGA_MAC_VER_03: |
| 5156 | case RTL_GIGA_MAC_VER_04: |
| 5157 | case RTL_GIGA_MAC_VER_05: |
| 5158 | case RTL_GIGA_MAC_VER_06: |
| 5159 | case RTL_GIGA_MAC_VER_10: |
| 5160 | case RTL_GIGA_MAC_VER_11: |
| 5161 | case RTL_GIGA_MAC_VER_12: |
| 5162 | case RTL_GIGA_MAC_VER_13: |
| 5163 | case RTL_GIGA_MAC_VER_14: |
| 5164 | case RTL_GIGA_MAC_VER_15: |
| 5165 | case RTL_GIGA_MAC_VER_16: |
| 5166 | case RTL_GIGA_MAC_VER_17: |
| 5167 | ops->write = NULL; |
| 5168 | ops->read = NULL; |
| 5169 | break; |
| 5170 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5171 | case RTL_GIGA_MAC_VER_37: |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5172 | case RTL_GIGA_MAC_VER_38: |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5173 | ops->write = r8402_csi_write; |
| 5174 | ops->read = r8402_csi_read; |
| 5175 | break; |
| 5176 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5177 | case RTL_GIGA_MAC_VER_44: |
| 5178 | ops->write = r8411_csi_write; |
| 5179 | ops->read = r8411_csi_read; |
| 5180 | break; |
| 5181 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5182 | default: |
| 5183 | ops->write = r8169_csi_write; |
| 5184 | ops->read = r8169_csi_read; |
| 5185 | break; |
| 5186 | } |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5187 | } |
| 5188 | |
| 5189 | struct ephy_info { |
| 5190 | unsigned int offset; |
| 5191 | u16 mask; |
| 5192 | u16 bits; |
| 5193 | }; |
| 5194 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5195 | static void rtl_ephy_init(struct rtl8169_private *tp, const struct ephy_info *e, |
| 5196 | int len) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5197 | { |
| 5198 | u16 w; |
| 5199 | |
| 5200 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5201 | w = (rtl_ephy_read(tp, e->offset) & ~e->mask) | e->bits; |
| 5202 | rtl_ephy_write(tp, e->offset, w); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 5203 | e++; |
| 5204 | } |
| 5205 | } |
| 5206 | |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5207 | static void rtl_disable_clock_request(struct pci_dev *pdev) |
| 5208 | { |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 5209 | pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, |
| 5210 | PCI_EXP_LNKCTL_CLKREQ_EN); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5211 | } |
| 5212 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5213 | static void rtl_enable_clock_request(struct pci_dev *pdev) |
| 5214 | { |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 5215 | pcie_capability_set_word(pdev, PCI_EXP_LNKCTL, |
| 5216 | PCI_EXP_LNKCTL_CLKREQ_EN); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5217 | } |
| 5218 | |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5219 | static void rtl_pcie_state_l2l3_enable(struct rtl8169_private *tp, bool enable) |
| 5220 | { |
| 5221 | void __iomem *ioaddr = tp->mmio_addr; |
| 5222 | u8 data; |
| 5223 | |
| 5224 | data = RTL_R8(Config3); |
| 5225 | |
| 5226 | if (enable) |
| 5227 | data |= Rdy_to_L23; |
| 5228 | else |
| 5229 | data &= ~Rdy_to_L23; |
| 5230 | |
| 5231 | RTL_W8(Config3, data); |
| 5232 | } |
| 5233 | |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5234 | #define R8168_CPCMD_QUIRK_MASK (\ |
| 5235 | EnableBist | \ |
| 5236 | Mac_dbgo_oe | \ |
| 5237 | Force_half_dup | \ |
| 5238 | Force_rxflow_en | \ |
| 5239 | Force_txflow_en | \ |
| 5240 | Cxpl_dbg_sel | \ |
| 5241 | ASF | \ |
| 5242 | PktCntrDisable | \ |
| 5243 | Mac_dbgo_sel) |
| 5244 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5245 | static void rtl_hw_start_8168bb(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5246 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5247 | void __iomem *ioaddr = tp->mmio_addr; |
| 5248 | struct pci_dev *pdev = tp->pci_dev; |
| 5249 | |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5250 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 5251 | |
| 5252 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 5253 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5254 | if (tp->dev->mtu <= ETH_DATA_LEN) { |
| 5255 | rtl_tx_performance_tweak(pdev, (0x5 << MAX_READ_REQUEST_SHIFT) | |
| 5256 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 5257 | } |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5258 | } |
| 5259 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5260 | static void rtl_hw_start_8168bef(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5261 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5262 | void __iomem *ioaddr = tp->mmio_addr; |
| 5263 | |
| 5264 | rtl_hw_start_8168bb(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5265 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 5266 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5267 | |
| 5268 | RTL_W8(Config4, RTL_R8(Config4) & ~(1 << 0)); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5269 | } |
| 5270 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5271 | static void __rtl_hw_start_8168cp(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5272 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5273 | void __iomem *ioaddr = tp->mmio_addr; |
| 5274 | struct pci_dev *pdev = tp->pci_dev; |
| 5275 | |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5276 | RTL_W8(Config1, RTL_R8(Config1) | Speed_down); |
| 5277 | |
| 5278 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 5279 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5280 | if (tp->dev->mtu <= ETH_DATA_LEN) |
| 5281 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5282 | |
| 5283 | rtl_disable_clock_request(pdev); |
| 5284 | |
| 5285 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5286 | } |
| 5287 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5288 | static void rtl_hw_start_8168cp_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5289 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5290 | static const struct ephy_info e_info_8168cp[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5291 | { 0x01, 0, 0x0001 }, |
| 5292 | { 0x02, 0x0800, 0x1000 }, |
| 5293 | { 0x03, 0, 0x0042 }, |
| 5294 | { 0x06, 0x0080, 0x0000 }, |
| 5295 | { 0x07, 0, 0x2000 } |
| 5296 | }; |
| 5297 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5298 | rtl_csi_access_enable_2(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5299 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5300 | rtl_ephy_init(tp, e_info_8168cp, ARRAY_SIZE(e_info_8168cp)); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5301 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5302 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5303 | } |
| 5304 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5305 | static void rtl_hw_start_8168cp_2(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5306 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5307 | void __iomem *ioaddr = tp->mmio_addr; |
| 5308 | struct pci_dev *pdev = tp->pci_dev; |
| 5309 | |
| 5310 | rtl_csi_access_enable_2(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5311 | |
| 5312 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 5313 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5314 | if (tp->dev->mtu <= ETH_DATA_LEN) |
| 5315 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5316 | |
| 5317 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 5318 | } |
| 5319 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5320 | static void rtl_hw_start_8168cp_3(struct rtl8169_private *tp) |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5321 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5322 | void __iomem *ioaddr = tp->mmio_addr; |
| 5323 | struct pci_dev *pdev = tp->pci_dev; |
| 5324 | |
| 5325 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5326 | |
| 5327 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 5328 | |
| 5329 | /* Magic. */ |
| 5330 | RTL_W8(DBG_REG, 0x20); |
| 5331 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 5332 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5333 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5334 | if (tp->dev->mtu <= ETH_DATA_LEN) |
| 5335 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5336 | |
| 5337 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 5338 | } |
| 5339 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5340 | static void rtl_hw_start_8168c_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5341 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5342 | void __iomem *ioaddr = tp->mmio_addr; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5343 | static const struct ephy_info e_info_8168c_1[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5344 | { 0x02, 0x0800, 0x1000 }, |
| 5345 | { 0x03, 0, 0x0002 }, |
| 5346 | { 0x06, 0x0080, 0x0000 } |
| 5347 | }; |
| 5348 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5349 | rtl_csi_access_enable_2(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5350 | |
| 5351 | RTL_W8(DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2); |
| 5352 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5353 | 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] | 5354 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5355 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5356 | } |
| 5357 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5358 | static void rtl_hw_start_8168c_2(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5359 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5360 | static const struct ephy_info e_info_8168c_2[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5361 | { 0x01, 0, 0x0001 }, |
| 5362 | { 0x03, 0x0400, 0x0220 } |
| 5363 | }; |
| 5364 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5365 | rtl_csi_access_enable_2(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 5366 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5367 | 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] | 5368 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5369 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5370 | } |
| 5371 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5372 | static void rtl_hw_start_8168c_3(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5373 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5374 | rtl_hw_start_8168c_2(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5375 | } |
| 5376 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5377 | static void rtl_hw_start_8168c_4(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5378 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5379 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5380 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5381 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5382 | } |
| 5383 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5384 | static void rtl_hw_start_8168d(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5385 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5386 | void __iomem *ioaddr = tp->mmio_addr; |
| 5387 | struct pci_dev *pdev = tp->pci_dev; |
| 5388 | |
| 5389 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5390 | |
| 5391 | rtl_disable_clock_request(pdev); |
| 5392 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 5393 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5394 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5395 | if (tp->dev->mtu <= ETH_DATA_LEN) |
| 5396 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5397 | |
| 5398 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 5399 | } |
| 5400 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5401 | static void rtl_hw_start_8168dp(struct rtl8169_private *tp) |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5402 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5403 | void __iomem *ioaddr = tp->mmio_addr; |
| 5404 | struct pci_dev *pdev = tp->pci_dev; |
| 5405 | |
| 5406 | rtl_csi_access_enable_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5407 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5408 | if (tp->dev->mtu <= ETH_DATA_LEN) |
| 5409 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5410 | |
| 5411 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
| 5412 | |
| 5413 | rtl_disable_clock_request(pdev); |
| 5414 | } |
| 5415 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5416 | static void rtl_hw_start_8168d_4(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5417 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5418 | void __iomem *ioaddr = tp->mmio_addr; |
| 5419 | struct pci_dev *pdev = tp->pci_dev; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5420 | static const struct ephy_info e_info_8168d_4[] = { |
| 5421 | { 0x0b, ~0, 0x48 }, |
| 5422 | { 0x19, 0x20, 0x50 }, |
| 5423 | { 0x0c, ~0, 0x20 } |
| 5424 | }; |
| 5425 | int i; |
| 5426 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5427 | rtl_csi_access_enable_1(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5428 | |
| 5429 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 5430 | |
| 5431 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
| 5432 | |
| 5433 | for (i = 0; i < ARRAY_SIZE(e_info_8168d_4); i++) { |
| 5434 | const struct ephy_info *e = e_info_8168d_4 + i; |
| 5435 | u16 w; |
| 5436 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5437 | w = rtl_ephy_read(tp, e->offset); |
| 5438 | rtl_ephy_write(tp, 0x03, (w & e->mask) | e->bits); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5439 | } |
| 5440 | |
| 5441 | rtl_enable_clock_request(pdev); |
| 5442 | } |
| 5443 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5444 | static void rtl_hw_start_8168e_1(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5445 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5446 | void __iomem *ioaddr = tp->mmio_addr; |
| 5447 | struct pci_dev *pdev = tp->pci_dev; |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5448 | static const struct ephy_info e_info_8168e_1[] = { |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5449 | { 0x00, 0x0200, 0x0100 }, |
| 5450 | { 0x00, 0x0000, 0x0004 }, |
| 5451 | { 0x06, 0x0002, 0x0001 }, |
| 5452 | { 0x06, 0x0000, 0x0030 }, |
| 5453 | { 0x07, 0x0000, 0x2000 }, |
| 5454 | { 0x00, 0x0000, 0x0020 }, |
| 5455 | { 0x03, 0x5800, 0x2000 }, |
| 5456 | { 0x03, 0x0000, 0x0001 }, |
| 5457 | { 0x01, 0x0800, 0x1000 }, |
| 5458 | { 0x07, 0x0000, 0x4000 }, |
| 5459 | { 0x1e, 0x0000, 0x2000 }, |
| 5460 | { 0x19, 0xffff, 0xfe6c }, |
| 5461 | { 0x0a, 0x0000, 0x0040 } |
| 5462 | }; |
| 5463 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5464 | rtl_csi_access_enable_2(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5465 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5466 | 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] | 5467 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5468 | if (tp->dev->mtu <= ETH_DATA_LEN) |
| 5469 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5470 | |
| 5471 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
| 5472 | |
| 5473 | rtl_disable_clock_request(pdev); |
| 5474 | |
| 5475 | /* Reset tx FIFO pointer */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5476 | RTL_W32(MISC, RTL_R32(MISC) | TXPLA_RST); |
| 5477 | RTL_W32(MISC, RTL_R32(MISC) & ~TXPLA_RST); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5478 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5479 | RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5480 | } |
| 5481 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5482 | static void rtl_hw_start_8168e_2(struct rtl8169_private *tp) |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5483 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5484 | void __iomem *ioaddr = tp->mmio_addr; |
| 5485 | struct pci_dev *pdev = tp->pci_dev; |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5486 | static const struct ephy_info e_info_8168e_2[] = { |
| 5487 | { 0x09, 0x0000, 0x0080 }, |
| 5488 | { 0x19, 0x0000, 0x0224 } |
| 5489 | }; |
| 5490 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5491 | rtl_csi_access_enable_1(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5492 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5493 | 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] | 5494 | |
françois romieu | faf1e78 | 2013-02-27 13:01:57 +0000 | [diff] [blame] | 5495 | if (tp->dev->mtu <= ETH_DATA_LEN) |
| 5496 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5497 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5498 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5499 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5500 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 5501 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5502 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 5503 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x07ff0060, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame^] | 5504 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 5505 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5506 | |
Hayes Wang | 3090bd9 | 2011-09-06 16:55:15 +0800 | [diff] [blame] | 5507 | RTL_W8(MaxTxPacketSize, EarlySize); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5508 | |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 5509 | rtl_disable_clock_request(pdev); |
| 5510 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5511 | RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
| 5512 | RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB); |
| 5513 | |
| 5514 | /* Adjust EEE LED frequency */ |
| 5515 | RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07); |
| 5516 | |
| 5517 | RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN); |
| 5518 | RTL_W32(MISC, RTL_R32(MISC) | PWM_EN); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 5519 | RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5520 | } |
| 5521 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5522 | static void rtl_hw_start_8168f(struct rtl8169_private *tp) |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5523 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5524 | void __iomem *ioaddr = tp->mmio_addr; |
| 5525 | struct pci_dev *pdev = tp->pci_dev; |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5526 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5527 | rtl_csi_access_enable_2(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5528 | |
| 5529 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 5530 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5531 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5532 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5533 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 5534 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame^] | 5535 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5536 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 5537 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 5538 | rtl_w0w1_eri(tp, 0x1d0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5539 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 5540 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x00000060, ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5541 | |
| 5542 | RTL_W8(MaxTxPacketSize, EarlySize); |
| 5543 | |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 5544 | rtl_disable_clock_request(pdev); |
| 5545 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5546 | RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
| 5547 | RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5548 | RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 5549 | RTL_W32(MISC, RTL_R32(MISC) | PWM_EN); |
| 5550 | RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5551 | } |
| 5552 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5553 | static void rtl_hw_start_8168f_1(struct rtl8169_private *tp) |
| 5554 | { |
| 5555 | void __iomem *ioaddr = tp->mmio_addr; |
| 5556 | static const struct ephy_info e_info_8168f_1[] = { |
| 5557 | { 0x06, 0x00c0, 0x0020 }, |
| 5558 | { 0x08, 0x0001, 0x0002 }, |
| 5559 | { 0x09, 0x0000, 0x0080 }, |
| 5560 | { 0x19, 0x0000, 0x0224 } |
| 5561 | }; |
| 5562 | |
| 5563 | rtl_hw_start_8168f(tp); |
| 5564 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5565 | 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] | 5566 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame^] | 5567 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5568 | |
| 5569 | /* Adjust EEE LED frequency */ |
| 5570 | RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07); |
| 5571 | } |
| 5572 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5573 | static void rtl_hw_start_8411(struct rtl8169_private *tp) |
| 5574 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5575 | static const struct ephy_info e_info_8168f_1[] = { |
| 5576 | { 0x06, 0x00c0, 0x0020 }, |
| 5577 | { 0x0f, 0xffff, 0x5200 }, |
| 5578 | { 0x1e, 0x0000, 0x4000 }, |
| 5579 | { 0x19, 0x0000, 0x0224 } |
| 5580 | }; |
| 5581 | |
| 5582 | rtl_hw_start_8168f(tp); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5583 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5584 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5585 | rtl_ephy_init(tp, e_info_8168f_1, ARRAY_SIZE(e_info_8168f_1)); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5586 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame^] | 5587 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5588 | } |
| 5589 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5590 | static void rtl_hw_start_8168g_1(struct rtl8169_private *tp) |
| 5591 | { |
| 5592 | void __iomem *ioaddr = tp->mmio_addr; |
| 5593 | struct pci_dev *pdev = tp->pci_dev; |
| 5594 | |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 5595 | RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
| 5596 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5597 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x080002, ERIAR_EXGMAC); |
| 5598 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC); |
| 5599 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC); |
| 5600 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5601 | |
| 5602 | rtl_csi_access_enable_1(tp); |
| 5603 | |
| 5604 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 5605 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame^] | 5606 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5607 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
hayeswang | beb330a | 2013-04-01 22:23:39 +0000 | [diff] [blame] | 5608 | rtl_eri_write(tp, 0x2f8, ERIAR_MASK_0011, 0x1d8f, ERIAR_EXGMAC); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5609 | |
| 5610 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 5611 | RTL_W32(MISC, RTL_R32(MISC) & ~RXDV_GATED_EN); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5612 | RTL_W8(MaxTxPacketSize, EarlySize); |
| 5613 | |
| 5614 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5615 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5616 | |
| 5617 | /* Adjust EEE LED frequency */ |
| 5618 | RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07); |
| 5619 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame^] | 5620 | rtl_w0w1_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC); |
| 5621 | rtl_w0w1_eri(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, 0x1000, ERIAR_EXGMAC); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 5622 | |
| 5623 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5624 | } |
| 5625 | |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5626 | static void rtl_hw_start_8168g_2(struct rtl8169_private *tp) |
| 5627 | { |
| 5628 | void __iomem *ioaddr = tp->mmio_addr; |
| 5629 | static const struct ephy_info e_info_8168g_2[] = { |
| 5630 | { 0x00, 0x0000, 0x0008 }, |
| 5631 | { 0x0c, 0x3df0, 0x0200 }, |
| 5632 | { 0x19, 0xffff, 0xfc00 }, |
| 5633 | { 0x1e, 0xffff, 0x20eb } |
| 5634 | }; |
| 5635 | |
| 5636 | rtl_hw_start_8168g_1(tp); |
| 5637 | |
| 5638 | /* disable aspm and clock request before access ephy */ |
| 5639 | RTL_W8(Config2, RTL_R8(Config2) & ~ClkReqEn); |
| 5640 | RTL_W8(Config5, RTL_R8(Config5) & ~ASPM_en); |
| 5641 | rtl_ephy_init(tp, e_info_8168g_2, ARRAY_SIZE(e_info_8168g_2)); |
| 5642 | } |
| 5643 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5644 | static void rtl_hw_start_8411_2(struct rtl8169_private *tp) |
| 5645 | { |
| 5646 | void __iomem *ioaddr = tp->mmio_addr; |
| 5647 | static const struct ephy_info e_info_8411_2[] = { |
| 5648 | { 0x00, 0x0000, 0x0008 }, |
| 5649 | { 0x0c, 0x3df0, 0x0200 }, |
| 5650 | { 0x0f, 0xffff, 0x5200 }, |
| 5651 | { 0x19, 0x0020, 0x0000 }, |
| 5652 | { 0x1e, 0x0000, 0x2000 } |
| 5653 | }; |
| 5654 | |
| 5655 | rtl_hw_start_8168g_1(tp); |
| 5656 | |
| 5657 | /* disable aspm and clock request before access ephy */ |
| 5658 | RTL_W8(Config2, RTL_R8(Config2) & ~ClkReqEn); |
| 5659 | RTL_W8(Config5, RTL_R8(Config5) & ~ASPM_en); |
| 5660 | rtl_ephy_init(tp, e_info_8411_2, ARRAY_SIZE(e_info_8411_2)); |
| 5661 | } |
| 5662 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5663 | static void rtl_hw_start_8168h_1(struct rtl8169_private *tp) |
| 5664 | { |
| 5665 | void __iomem *ioaddr = tp->mmio_addr; |
| 5666 | struct pci_dev *pdev = tp->pci_dev; |
| 5667 | u16 rg_saw_cnt; |
| 5668 | u32 data; |
| 5669 | static const struct ephy_info e_info_8168h_1[] = { |
| 5670 | { 0x1e, 0x0800, 0x0001 }, |
| 5671 | { 0x1d, 0x0000, 0x0800 }, |
| 5672 | { 0x05, 0xffff, 0x2089 }, |
| 5673 | { 0x06, 0xffff, 0x5881 }, |
| 5674 | { 0x04, 0xffff, 0x154a }, |
| 5675 | { 0x01, 0xffff, 0x068b } |
| 5676 | }; |
| 5677 | |
| 5678 | /* disable aspm and clock request before access ephy */ |
| 5679 | RTL_W8(Config2, RTL_R8(Config2) & ~ClkReqEn); |
| 5680 | RTL_W8(Config5, RTL_R8(Config5) & ~ASPM_en); |
| 5681 | rtl_ephy_init(tp, e_info_8168h_1, ARRAY_SIZE(e_info_8168h_1)); |
| 5682 | |
| 5683 | RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
| 5684 | |
| 5685 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x00080002, ERIAR_EXGMAC); |
| 5686 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC); |
| 5687 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC); |
| 5688 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5689 | |
| 5690 | rtl_csi_access_enable_1(tp); |
| 5691 | |
| 5692 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 5693 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame^] | 5694 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5695 | 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] | 5696 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame^] | 5697 | 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] | 5698 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame^] | 5699 | 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] | 5700 | |
| 5701 | rtl_eri_write(tp, 0x5f0, ERIAR_MASK_0011, 0x4f87, ERIAR_EXGMAC); |
| 5702 | |
| 5703 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 5704 | RTL_W32(MISC, RTL_R32(MISC) & ~RXDV_GATED_EN); |
| 5705 | RTL_W8(MaxTxPacketSize, EarlySize); |
| 5706 | |
| 5707 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5708 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5709 | |
| 5710 | /* Adjust EEE LED frequency */ |
| 5711 | RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07); |
| 5712 | |
| 5713 | RTL_W8(DLLPR, RTL_R8(DLLPR) & ~PFM_EN); |
| 5714 | RTL_W8(DLLPR, RTL_R8(MISC_1) & ~PFM_D3COLD_EN); |
| 5715 | |
| 5716 | RTL_W8(DLLPR, RTL_R8(DLLPR) & ~TX_10M_PS_EN); |
| 5717 | |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame^] | 5718 | 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] | 5719 | |
| 5720 | rtl_pcie_state_l2l3_enable(tp, false); |
| 5721 | |
| 5722 | rtl_writephy(tp, 0x1f, 0x0c42); |
| 5723 | rg_saw_cnt = rtl_readphy(tp, 0x13); |
| 5724 | rtl_writephy(tp, 0x1f, 0x0000); |
| 5725 | if (rg_saw_cnt > 0) { |
| 5726 | u16 sw_cnt_1ms_ini; |
| 5727 | |
| 5728 | sw_cnt_1ms_ini = 16000000/rg_saw_cnt; |
| 5729 | sw_cnt_1ms_ini &= 0x0fff; |
| 5730 | data = r8168_mac_ocp_read(tp, 0xd412); |
| 5731 | data &= 0x0fff; |
| 5732 | data |= sw_cnt_1ms_ini; |
| 5733 | r8168_mac_ocp_write(tp, 0xd412, data); |
| 5734 | } |
| 5735 | |
| 5736 | data = r8168_mac_ocp_read(tp, 0xe056); |
| 5737 | data &= 0xf0; |
| 5738 | data |= 0x07; |
| 5739 | r8168_mac_ocp_write(tp, 0xe056, data); |
| 5740 | |
| 5741 | data = r8168_mac_ocp_read(tp, 0xe052); |
| 5742 | data &= 0x8008; |
| 5743 | data |= 0x6000; |
| 5744 | r8168_mac_ocp_write(tp, 0xe052, data); |
| 5745 | |
| 5746 | data = r8168_mac_ocp_read(tp, 0xe0d6); |
| 5747 | data &= 0x01ff; |
| 5748 | data |= 0x017f; |
| 5749 | r8168_mac_ocp_write(tp, 0xe0d6, data); |
| 5750 | |
| 5751 | data = r8168_mac_ocp_read(tp, 0xd420); |
| 5752 | data &= 0x0fff; |
| 5753 | data |= 0x047f; |
| 5754 | r8168_mac_ocp_write(tp, 0xd420, data); |
| 5755 | |
| 5756 | r8168_mac_ocp_write(tp, 0xe63e, 0x0001); |
| 5757 | r8168_mac_ocp_write(tp, 0xe63e, 0x0000); |
| 5758 | r8168_mac_ocp_write(tp, 0xc094, 0x0000); |
| 5759 | r8168_mac_ocp_write(tp, 0xc09e, 0x0000); |
| 5760 | } |
| 5761 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5762 | static void rtl_hw_start_8168(struct net_device *dev) |
| 5763 | { |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5764 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5765 | void __iomem *ioaddr = tp->mmio_addr; |
| 5766 | |
| 5767 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 5768 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 5769 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5770 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5771 | rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5772 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5773 | tp->cp_cmd |= RTL_R16(CPlusCmd) | PktCntrDisable | INTT_1; |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5774 | |
| 5775 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 5776 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5777 | RTL_W16(IntrMitigate, 0x5151); |
| 5778 | |
| 5779 | /* Work around for RxFIFO overflow. */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 5780 | if (tp->mac_version == RTL_GIGA_MAC_VER_11) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5781 | tp->event_slow |= RxFIFOOver | PCSTimeout; |
| 5782 | tp->event_slow &= ~RxOverflow; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5783 | } |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5784 | |
| 5785 | rtl_set_rx_tx_desc_registers(tp, ioaddr); |
| 5786 | |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 5787 | rtl_set_rx_tx_config_registers(tp); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5788 | |
| 5789 | RTL_R8(IntrMask); |
| 5790 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5791 | switch (tp->mac_version) { |
| 5792 | case RTL_GIGA_MAC_VER_11: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5793 | rtl_hw_start_8168bb(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5794 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5795 | |
| 5796 | case RTL_GIGA_MAC_VER_12: |
| 5797 | case RTL_GIGA_MAC_VER_17: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5798 | rtl_hw_start_8168bef(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5799 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5800 | |
| 5801 | case RTL_GIGA_MAC_VER_18: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5802 | rtl_hw_start_8168cp_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5803 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5804 | |
| 5805 | case RTL_GIGA_MAC_VER_19: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5806 | rtl_hw_start_8168c_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5807 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5808 | |
| 5809 | case RTL_GIGA_MAC_VER_20: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5810 | rtl_hw_start_8168c_2(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5811 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5812 | |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5813 | case RTL_GIGA_MAC_VER_21: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5814 | rtl_hw_start_8168c_3(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5815 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5816 | |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5817 | case RTL_GIGA_MAC_VER_22: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5818 | rtl_hw_start_8168c_4(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5819 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5820 | |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5821 | case RTL_GIGA_MAC_VER_23: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5822 | rtl_hw_start_8168cp_2(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5823 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5824 | |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5825 | case RTL_GIGA_MAC_VER_24: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5826 | rtl_hw_start_8168cp_3(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5827 | break; |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5828 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5829 | case RTL_GIGA_MAC_VER_25: |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 5830 | case RTL_GIGA_MAC_VER_26: |
| 5831 | case RTL_GIGA_MAC_VER_27: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5832 | rtl_hw_start_8168d(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5833 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5834 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5835 | case RTL_GIGA_MAC_VER_28: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5836 | rtl_hw_start_8168d_4(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5837 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5838 | |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5839 | case RTL_GIGA_MAC_VER_31: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5840 | rtl_hw_start_8168dp(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5841 | break; |
| 5842 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5843 | case RTL_GIGA_MAC_VER_32: |
| 5844 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5845 | rtl_hw_start_8168e_1(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5846 | break; |
| 5847 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5848 | rtl_hw_start_8168e_2(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5849 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5850 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5851 | case RTL_GIGA_MAC_VER_35: |
| 5852 | case RTL_GIGA_MAC_VER_36: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5853 | rtl_hw_start_8168f_1(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5854 | break; |
| 5855 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5856 | case RTL_GIGA_MAC_VER_38: |
| 5857 | rtl_hw_start_8411(tp); |
| 5858 | break; |
| 5859 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5860 | case RTL_GIGA_MAC_VER_40: |
| 5861 | case RTL_GIGA_MAC_VER_41: |
| 5862 | rtl_hw_start_8168g_1(tp); |
| 5863 | break; |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 5864 | case RTL_GIGA_MAC_VER_42: |
| 5865 | rtl_hw_start_8168g_2(tp); |
| 5866 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5867 | |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 5868 | case RTL_GIGA_MAC_VER_44: |
| 5869 | rtl_hw_start_8411_2(tp); |
| 5870 | break; |
| 5871 | |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 5872 | case RTL_GIGA_MAC_VER_45: |
| 5873 | case RTL_GIGA_MAC_VER_46: |
| 5874 | rtl_hw_start_8168h_1(tp); |
| 5875 | break; |
| 5876 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5877 | default: |
| 5878 | printk(KERN_ERR PFX "%s: unknown chipset (mac_version = %d).\n", |
| 5879 | dev->name, tp->mac_version); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5880 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5881 | } |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5882 | |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 5883 | RTL_W8(Cfg9346, Cfg9346_Lock); |
| 5884 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5885 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 5886 | |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 5887 | rtl_set_rx_mode(dev); |
Francois Romieu | b836390 | 2008-06-01 12:31:57 +0200 | [diff] [blame] | 5888 | |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 5889 | RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5890 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5891 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5892 | #define R810X_CPCMD_QUIRK_MASK (\ |
| 5893 | EnableBist | \ |
| 5894 | Mac_dbgo_oe | \ |
| 5895 | Force_half_dup | \ |
françois romieu | 5edcc53 | 2009-08-10 19:41:52 +0000 | [diff] [blame] | 5896 | Force_rxflow_en | \ |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5897 | Force_txflow_en | \ |
| 5898 | Cxpl_dbg_sel | \ |
| 5899 | ASF | \ |
| 5900 | PktCntrDisable | \ |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 5901 | Mac_dbgo_sel) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5902 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5903 | static void rtl_hw_start_8102e_1(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5904 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5905 | void __iomem *ioaddr = tp->mmio_addr; |
| 5906 | struct pci_dev *pdev = tp->pci_dev; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5907 | static const struct ephy_info e_info_8102e_1[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5908 | { 0x01, 0, 0x6e65 }, |
| 5909 | { 0x02, 0, 0x091f }, |
| 5910 | { 0x03, 0, 0xc2f9 }, |
| 5911 | { 0x06, 0, 0xafb5 }, |
| 5912 | { 0x07, 0, 0x0e00 }, |
| 5913 | { 0x19, 0, 0xec80 }, |
| 5914 | { 0x01, 0, 0x2e65 }, |
| 5915 | { 0x01, 0, 0x6e65 } |
| 5916 | }; |
| 5917 | u8 cfg1; |
| 5918 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5919 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5920 | |
| 5921 | RTL_W8(DBG_REG, FIX_NAK_1); |
| 5922 | |
| 5923 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 5924 | |
| 5925 | RTL_W8(Config1, |
| 5926 | LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable); |
| 5927 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 5928 | |
| 5929 | cfg1 = RTL_R8(Config1); |
| 5930 | if ((cfg1 & LEDS0) && (cfg1 & LEDS1)) |
| 5931 | RTL_W8(Config1, cfg1 & ~LEDS0); |
| 5932 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5933 | 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] | 5934 | } |
| 5935 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5936 | static void rtl_hw_start_8102e_2(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5937 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5938 | void __iomem *ioaddr = tp->mmio_addr; |
| 5939 | struct pci_dev *pdev = tp->pci_dev; |
| 5940 | |
| 5941 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5942 | |
| 5943 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 5944 | |
| 5945 | RTL_W8(Config1, MEMMAP | IOMAP | VPD | PMEnable); |
| 5946 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5947 | } |
| 5948 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5949 | static void rtl_hw_start_8102e_3(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5950 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5951 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5952 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5953 | rtl_ephy_write(tp, 0x03, 0xc2f9); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5954 | } |
| 5955 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5956 | static void rtl_hw_start_8105e_1(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5957 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5958 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5959 | static const struct ephy_info e_info_8105e_1[] = { |
| 5960 | { 0x07, 0, 0x4000 }, |
| 5961 | { 0x19, 0, 0x0200 }, |
| 5962 | { 0x19, 0, 0x0020 }, |
| 5963 | { 0x1e, 0, 0x2000 }, |
| 5964 | { 0x03, 0, 0x0001 }, |
| 5965 | { 0x19, 0, 0x0100 }, |
| 5966 | { 0x19, 0, 0x0004 }, |
| 5967 | { 0x0a, 0, 0x0020 } |
| 5968 | }; |
| 5969 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5970 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5971 | RTL_W32(FuncEvent, RTL_R32(FuncEvent) | 0x002800); |
| 5972 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5973 | /* Disable Early Tally Counter */ |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5974 | RTL_W32(FuncEvent, RTL_R32(FuncEvent) & ~0x010000); |
| 5975 | |
| 5976 | RTL_W8(MCU, RTL_R8(MCU) | EN_NDP | EN_OOB_RESET); |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 5977 | RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5978 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5979 | 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] | 5980 | |
| 5981 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5982 | } |
| 5983 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5984 | static void rtl_hw_start_8105e_2(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5985 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5986 | rtl_hw_start_8105e_1(tp); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5987 | rtl_ephy_write(tp, 0x1e, rtl_ephy_read(tp, 0x1e) | 0x8000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5988 | } |
| 5989 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5990 | static void rtl_hw_start_8402(struct rtl8169_private *tp) |
| 5991 | { |
| 5992 | void __iomem *ioaddr = tp->mmio_addr; |
| 5993 | static const struct ephy_info e_info_8402[] = { |
| 5994 | { 0x19, 0xffff, 0xff64 }, |
| 5995 | { 0x1e, 0, 0x4000 } |
| 5996 | }; |
| 5997 | |
| 5998 | rtl_csi_access_enable_2(tp); |
| 5999 | |
| 6000 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
| 6001 | RTL_W32(FuncEvent, RTL_R32(FuncEvent) | 0x002800); |
| 6002 | |
| 6003 | RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
| 6004 | RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB); |
| 6005 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6006 | rtl_ephy_init(tp, e_info_8402, ARRAY_SIZE(e_info_8402)); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6007 | |
| 6008 | rtl_tx_performance_tweak(tp->pci_dev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 6009 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6010 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00000002, ERIAR_EXGMAC); |
| 6011 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00000006, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame^] | 6012 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 6013 | rtl_w0w1_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 6014 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 6015 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Chun-Hao Lin | 706123d | 2014-10-01 23:17:18 +0800 | [diff] [blame^] | 6016 | rtl_w0w1_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0e00, 0xff00, ERIAR_EXGMAC); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 6017 | |
| 6018 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6019 | } |
| 6020 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6021 | static void rtl_hw_start_8106(struct rtl8169_private *tp) |
| 6022 | { |
| 6023 | void __iomem *ioaddr = tp->mmio_addr; |
| 6024 | |
| 6025 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
| 6026 | RTL_W32(FuncEvent, RTL_R32(FuncEvent) | 0x002800); |
| 6027 | |
Francois Romieu | 4521e1a9 | 2012-11-01 16:46:28 +0000 | [diff] [blame] | 6028 | RTL_W32(MISC, (RTL_R32(MISC) | DISABLE_LAN_EN) & ~EARLY_TALLY_EN); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6029 | RTL_W8(MCU, RTL_R8(MCU) | EN_NDP | EN_OOB_RESET); |
| 6030 | RTL_W8(DLLPR, RTL_R8(DLLPR) & ~PFM_EN); |
hayeswang | b51ecea | 2014-07-09 14:52:51 +0800 | [diff] [blame] | 6031 | |
| 6032 | rtl_pcie_state_l2l3_enable(tp, false); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6033 | } |
| 6034 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 6035 | static void rtl_hw_start_8101(struct net_device *dev) |
| 6036 | { |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6037 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6038 | void __iomem *ioaddr = tp->mmio_addr; |
| 6039 | struct pci_dev *pdev = tp->pci_dev; |
| 6040 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6041 | if (tp->mac_version >= RTL_GIGA_MAC_VER_30) |
| 6042 | tp->event_slow &= ~RxFIFOOver; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 6043 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6044 | if (tp->mac_version == RTL_GIGA_MAC_VER_13 || |
Jiang Liu | 7d7903b | 2012-07-24 17:20:16 +0800 | [diff] [blame] | 6045 | tp->mac_version == RTL_GIGA_MAC_VER_16) |
Bjorn Helgaas | 8200bc7 | 2012-08-22 10:29:42 -0600 | [diff] [blame] | 6046 | pcie_capability_set_word(pdev, PCI_EXP_DEVCTL, |
| 6047 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6048 | |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 6049 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 6050 | |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6051 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
| 6052 | |
| 6053 | rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
| 6054 | |
| 6055 | tp->cp_cmd &= ~R810X_CPCMD_QUIRK_MASK; |
| 6056 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 6057 | |
| 6058 | rtl_set_rx_tx_desc_registers(tp, ioaddr); |
| 6059 | |
| 6060 | rtl_set_rx_tx_config_registers(tp); |
| 6061 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6062 | switch (tp->mac_version) { |
| 6063 | case RTL_GIGA_MAC_VER_07: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6064 | rtl_hw_start_8102e_1(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6065 | break; |
| 6066 | |
| 6067 | case RTL_GIGA_MAC_VER_08: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6068 | rtl_hw_start_8102e_3(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6069 | break; |
| 6070 | |
| 6071 | case RTL_GIGA_MAC_VER_09: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6072 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 6073 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6074 | |
| 6075 | case RTL_GIGA_MAC_VER_29: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6076 | rtl_hw_start_8105e_1(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6077 | break; |
| 6078 | case RTL_GIGA_MAC_VER_30: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6079 | rtl_hw_start_8105e_2(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 6080 | break; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 6081 | |
| 6082 | case RTL_GIGA_MAC_VER_37: |
| 6083 | rtl_hw_start_8402(tp); |
| 6084 | break; |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 6085 | |
| 6086 | case RTL_GIGA_MAC_VER_39: |
| 6087 | rtl_hw_start_8106(tp); |
| 6088 | break; |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 6089 | case RTL_GIGA_MAC_VER_43: |
| 6090 | rtl_hw_start_8168g_2(tp); |
| 6091 | break; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6092 | case RTL_GIGA_MAC_VER_47: |
| 6093 | case RTL_GIGA_MAC_VER_48: |
| 6094 | rtl_hw_start_8168h_1(tp); |
| 6095 | break; |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6096 | } |
| 6097 | |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 6098 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6099 | |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6100 | RTL_W16(IntrMitigate, 0x0000); |
| 6101 | |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6102 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6103 | |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6104 | rtl_set_rx_mode(dev); |
| 6105 | |
hayeswang | 1a96464 | 2013-04-01 22:23:41 +0000 | [diff] [blame] | 6106 | RTL_R8(IntrMask); |
| 6107 | |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 6108 | RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6109 | } |
| 6110 | |
| 6111 | static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) |
| 6112 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 6113 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6114 | |
| 6115 | if (new_mtu < ETH_ZLEN || |
| 6116 | new_mtu > rtl_chip_infos[tp->mac_version].jumbo_max) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6117 | return -EINVAL; |
| 6118 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 6119 | if (new_mtu > ETH_DATA_LEN) |
| 6120 | rtl_hw_jumbo_enable(tp); |
| 6121 | else |
| 6122 | rtl_hw_jumbo_disable(tp); |
| 6123 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6124 | dev->mtu = new_mtu; |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 6125 | netdev_update_features(dev); |
| 6126 | |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6127 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6128 | } |
| 6129 | |
| 6130 | static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc) |
| 6131 | { |
Al Viro | 95e0918 | 2007-12-22 18:55:39 +0000 | [diff] [blame] | 6132 | desc->addr = cpu_to_le64(0x0badbadbadbadbadull); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6133 | desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask); |
| 6134 | } |
| 6135 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6136 | static void rtl8169_free_rx_databuff(struct rtl8169_private *tp, |
| 6137 | void **data_buff, struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6138 | { |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6139 | 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] | 6140 | DMA_FROM_DEVICE); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6141 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6142 | kfree(*data_buff); |
| 6143 | *data_buff = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6144 | rtl8169_make_unusable_by_asic(desc); |
| 6145 | } |
| 6146 | |
| 6147 | static inline void rtl8169_mark_to_asic(struct RxDesc *desc, u32 rx_buf_sz) |
| 6148 | { |
| 6149 | u32 eor = le32_to_cpu(desc->opts1) & RingEnd; |
| 6150 | |
| 6151 | desc->opts1 = cpu_to_le32(DescOwn | eor | rx_buf_sz); |
| 6152 | } |
| 6153 | |
| 6154 | static inline void rtl8169_map_to_asic(struct RxDesc *desc, dma_addr_t mapping, |
| 6155 | u32 rx_buf_sz) |
| 6156 | { |
| 6157 | desc->addr = cpu_to_le64(mapping); |
| 6158 | wmb(); |
| 6159 | rtl8169_mark_to_asic(desc, rx_buf_sz); |
| 6160 | } |
| 6161 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6162 | static inline void *rtl8169_align(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6163 | { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6164 | return (void *)ALIGN((long)data, 16); |
| 6165 | } |
| 6166 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6167 | static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp, |
| 6168 | struct RxDesc *desc) |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6169 | { |
| 6170 | void *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6171 | dma_addr_t mapping; |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6172 | struct device *d = &tp->pci_dev->dev; |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6173 | struct net_device *dev = tp->dev; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6174 | int node = dev->dev.parent ? dev_to_node(dev->dev.parent) : -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6175 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6176 | data = kmalloc_node(rx_buf_sz, GFP_KERNEL, node); |
| 6177 | if (!data) |
| 6178 | return NULL; |
Francois Romieu | e9f63f3 | 2007-02-28 23:16:57 +0100 | [diff] [blame] | 6179 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6180 | if (rtl8169_align(data) != data) { |
| 6181 | kfree(data); |
| 6182 | data = kmalloc_node(rx_buf_sz + 15, GFP_KERNEL, node); |
| 6183 | if (!data) |
| 6184 | return NULL; |
| 6185 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6186 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6187 | mapping = dma_map_single(d, rtl8169_align(data), rx_buf_sz, |
Stanislaw Gruszka | 231aee6 | 2010-10-20 22:25:38 +0000 | [diff] [blame] | 6188 | DMA_FROM_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6189 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 6190 | if (net_ratelimit()) |
| 6191 | netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6192 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6193 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6194 | |
| 6195 | rtl8169_map_to_asic(desc, mapping, rx_buf_sz); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6196 | return data; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6197 | |
| 6198 | err_out: |
| 6199 | kfree(data); |
| 6200 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6201 | } |
| 6202 | |
| 6203 | static void rtl8169_rx_clear(struct rtl8169_private *tp) |
| 6204 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 6205 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6206 | |
| 6207 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6208 | if (tp->Rx_databuff[i]) { |
| 6209 | rtl8169_free_rx_databuff(tp, tp->Rx_databuff + i, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6210 | tp->RxDescArray + i); |
| 6211 | } |
| 6212 | } |
| 6213 | } |
| 6214 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6215 | static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6216 | { |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6217 | desc->opts1 |= cpu_to_le32(RingEnd); |
| 6218 | } |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6219 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6220 | static int rtl8169_rx_fill(struct rtl8169_private *tp) |
| 6221 | { |
| 6222 | unsigned int i; |
| 6223 | |
| 6224 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6225 | void *data; |
Francois Romieu | 4ae47c2 | 2007-06-16 23:28:45 +0200 | [diff] [blame] | 6226 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6227 | if (tp->Rx_databuff[i]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6228 | continue; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 6229 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6230 | data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6231 | if (!data) { |
| 6232 | rtl8169_make_unusable_by_asic(tp->RxDescArray + i); |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6233 | goto err_out; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6234 | } |
| 6235 | tp->Rx_databuff[i] = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6236 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6237 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6238 | rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1); |
| 6239 | return 0; |
| 6240 | |
| 6241 | err_out: |
| 6242 | rtl8169_rx_clear(tp); |
| 6243 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6244 | } |
| 6245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6246 | static int rtl8169_init_ring(struct net_device *dev) |
| 6247 | { |
| 6248 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6249 | |
| 6250 | rtl8169_init_ring_indexes(tp); |
| 6251 | |
| 6252 | memset(tp->tx_skb, 0x0, NUM_TX_DESC * sizeof(struct ring_info)); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6253 | memset(tp->Rx_databuff, 0x0, NUM_RX_DESC * sizeof(void *)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6254 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 6255 | return rtl8169_rx_fill(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6256 | } |
| 6257 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6258 | 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] | 6259 | struct TxDesc *desc) |
| 6260 | { |
| 6261 | unsigned int len = tx_skb->len; |
| 6262 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6263 | dma_unmap_single(d, le64_to_cpu(desc->addr), len, DMA_TO_DEVICE); |
| 6264 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6265 | desc->opts1 = 0x00; |
| 6266 | desc->opts2 = 0x00; |
| 6267 | desc->addr = 0x00; |
| 6268 | tx_skb->len = 0; |
| 6269 | } |
| 6270 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6271 | static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, |
| 6272 | unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6273 | { |
| 6274 | unsigned int i; |
| 6275 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6276 | for (i = 0; i < n; i++) { |
| 6277 | unsigned int entry = (start + i) % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6278 | struct ring_info *tx_skb = tp->tx_skb + entry; |
| 6279 | unsigned int len = tx_skb->len; |
| 6280 | |
| 6281 | if (len) { |
| 6282 | struct sk_buff *skb = tx_skb->skb; |
| 6283 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6284 | rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6285 | tp->TxDescArray + entry); |
| 6286 | if (skb) { |
Stanislaw Gruszka | cac4b22 | 2010-10-20 22:25:40 +0000 | [diff] [blame] | 6287 | tp->dev->stats.tx_dropped++; |
Eric W. Biederman | 989c9ba | 2014-03-11 14:16:14 -0700 | [diff] [blame] | 6288 | dev_kfree_skb_any(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6289 | tx_skb->skb = NULL; |
| 6290 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6291 | } |
| 6292 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6293 | } |
| 6294 | |
| 6295 | static void rtl8169_tx_clear(struct rtl8169_private *tp) |
| 6296 | { |
| 6297 | rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6298 | tp->cur_tx = tp->dirty_tx = 0; |
| 6299 | } |
| 6300 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6301 | static void rtl_reset_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6302 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 6303 | struct net_device *dev = tp->dev; |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6304 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6305 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6306 | napi_disable(&tp->napi); |
| 6307 | netif_stop_queue(dev); |
| 6308 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6309 | |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 6310 | rtl8169_hw_reset(tp); |
| 6311 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6312 | for (i = 0; i < NUM_RX_DESC; i++) |
| 6313 | rtl8169_mark_to_asic(tp->RxDescArray + i, rx_buf_sz); |
| 6314 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6315 | rtl8169_tx_clear(tp); |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 6316 | rtl8169_init_ring_indexes(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6317 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6318 | napi_enable(&tp->napi); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6319 | rtl_hw_start(dev); |
| 6320 | netif_wake_queue(dev); |
| 6321 | rtl8169_check_link_status(dev, tp, tp->mmio_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6322 | } |
| 6323 | |
| 6324 | static void rtl8169_tx_timeout(struct net_device *dev) |
| 6325 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6326 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6327 | |
| 6328 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6329 | } |
| 6330 | |
| 6331 | 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] | 6332 | u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6333 | { |
| 6334 | struct skb_shared_info *info = skb_shinfo(skb); |
| 6335 | unsigned int cur_frag, entry; |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 6336 | struct TxDesc *uninitialized_var(txd); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6337 | struct device *d = &tp->pci_dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6338 | |
| 6339 | entry = tp->cur_tx; |
| 6340 | for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6341 | const skb_frag_t *frag = info->frags + cur_frag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6342 | dma_addr_t mapping; |
| 6343 | u32 status, len; |
| 6344 | void *addr; |
| 6345 | |
| 6346 | entry = (entry + 1) % NUM_TX_DESC; |
| 6347 | |
| 6348 | txd = tp->TxDescArray + entry; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 6349 | len = skb_frag_size(frag); |
Ian Campbell | 929f618 | 2011-08-31 00:47:06 +0000 | [diff] [blame] | 6350 | addr = skb_frag_address(frag); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6351 | mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6352 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 6353 | if (net_ratelimit()) |
| 6354 | netif_err(tp, drv, tp->dev, |
| 6355 | "Failed to map TX fragments DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6356 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6357 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6358 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6359 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6360 | status = opts[0] | len | |
| 6361 | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6362 | |
| 6363 | txd->opts1 = cpu_to_le32(status); |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6364 | txd->opts2 = cpu_to_le32(opts[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6365 | txd->addr = cpu_to_le64(mapping); |
| 6366 | |
| 6367 | tp->tx_skb[entry].len = len; |
| 6368 | } |
| 6369 | |
| 6370 | if (cur_frag) { |
| 6371 | tp->tx_skb[entry].skb = skb; |
| 6372 | txd->opts1 |= cpu_to_le32(LastFrag); |
| 6373 | } |
| 6374 | |
| 6375 | return cur_frag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6376 | |
| 6377 | err_out: |
| 6378 | rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag); |
| 6379 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6380 | } |
| 6381 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6382 | static bool rtl_skb_pad(struct sk_buff *skb) |
| 6383 | { |
| 6384 | if (skb_padto(skb, ETH_ZLEN)) |
| 6385 | return false; |
| 6386 | skb_put(skb, ETH_ZLEN - skb->len); |
| 6387 | return true; |
| 6388 | } |
| 6389 | |
| 6390 | static bool rtl_test_hw_pad_bug(struct rtl8169_private *tp, struct sk_buff *skb) |
| 6391 | { |
| 6392 | return skb->len < ETH_ZLEN && tp->mac_version == RTL_GIGA_MAC_VER_34; |
| 6393 | } |
| 6394 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6395 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 6396 | struct net_device *dev); |
| 6397 | /* r8169_csum_workaround() |
| 6398 | * The hw limites the value the transport offset. When the offset is out of the |
| 6399 | * range, calculate the checksum by sw. |
| 6400 | */ |
| 6401 | static void r8169_csum_workaround(struct rtl8169_private *tp, |
| 6402 | struct sk_buff *skb) |
| 6403 | { |
| 6404 | if (skb_shinfo(skb)->gso_size) { |
| 6405 | netdev_features_t features = tp->dev->features; |
| 6406 | struct sk_buff *segs, *nskb; |
| 6407 | |
| 6408 | features &= ~(NETIF_F_SG | NETIF_F_IPV6_CSUM | NETIF_F_TSO6); |
| 6409 | segs = skb_gso_segment(skb, features); |
| 6410 | if (IS_ERR(segs) || !segs) |
| 6411 | goto drop; |
| 6412 | |
| 6413 | do { |
| 6414 | nskb = segs; |
| 6415 | segs = segs->next; |
| 6416 | nskb->next = NULL; |
| 6417 | rtl8169_start_xmit(nskb, tp->dev); |
| 6418 | } while (segs); |
| 6419 | |
| 6420 | dev_kfree_skb(skb); |
| 6421 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 6422 | if (skb_checksum_help(skb) < 0) |
| 6423 | goto drop; |
| 6424 | |
| 6425 | rtl8169_start_xmit(skb, tp->dev); |
| 6426 | } else { |
| 6427 | struct net_device_stats *stats; |
| 6428 | |
| 6429 | drop: |
| 6430 | stats = &tp->dev->stats; |
| 6431 | stats->tx_dropped++; |
| 6432 | dev_kfree_skb(skb); |
| 6433 | } |
| 6434 | } |
| 6435 | |
| 6436 | /* msdn_giant_send_check() |
| 6437 | * According to the document of microsoft, the TCP Pseudo Header excludes the |
| 6438 | * packet length for IPv6 TCP large packets. |
| 6439 | */ |
| 6440 | static int msdn_giant_send_check(struct sk_buff *skb) |
| 6441 | { |
| 6442 | const struct ipv6hdr *ipv6h; |
| 6443 | struct tcphdr *th; |
| 6444 | int ret; |
| 6445 | |
| 6446 | ret = skb_cow_head(skb, 0); |
| 6447 | if (ret) |
| 6448 | return ret; |
| 6449 | |
| 6450 | ipv6h = ipv6_hdr(skb); |
| 6451 | th = tcp_hdr(skb); |
| 6452 | |
| 6453 | th->check = 0; |
| 6454 | th->check = ~tcp_v6_check(0, &ipv6h->saddr, &ipv6h->daddr, 0); |
| 6455 | |
| 6456 | return ret; |
| 6457 | } |
| 6458 | |
| 6459 | static inline __be16 get_protocol(struct sk_buff *skb) |
| 6460 | { |
| 6461 | __be16 protocol; |
| 6462 | |
| 6463 | if (skb->protocol == htons(ETH_P_8021Q)) |
| 6464 | protocol = vlan_eth_hdr(skb)->h_vlan_encapsulated_proto; |
| 6465 | else |
| 6466 | protocol = skb->protocol; |
| 6467 | |
| 6468 | return protocol; |
| 6469 | } |
| 6470 | |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6471 | static bool rtl8169_tso_csum_v1(struct rtl8169_private *tp, |
| 6472 | struct sk_buff *skb, u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6473 | { |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 6474 | u32 mss = skb_shinfo(skb)->gso_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6475 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6476 | if (mss) { |
| 6477 | opts[0] |= TD_LSO; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6478 | opts[0] |= min(mss, TD_MSS_MAX) << TD0_MSS_SHIFT; |
| 6479 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
| 6480 | const struct iphdr *ip = ip_hdr(skb); |
| 6481 | |
| 6482 | if (ip->protocol == IPPROTO_TCP) |
| 6483 | opts[0] |= TD0_IP_CS | TD0_TCP_CS; |
| 6484 | else if (ip->protocol == IPPROTO_UDP) |
| 6485 | opts[0] |= TD0_IP_CS | TD0_UDP_CS; |
| 6486 | else |
| 6487 | WARN_ON_ONCE(1); |
| 6488 | } |
| 6489 | |
| 6490 | return true; |
| 6491 | } |
| 6492 | |
| 6493 | static bool rtl8169_tso_csum_v2(struct rtl8169_private *tp, |
| 6494 | struct sk_buff *skb, u32 *opts) |
| 6495 | { |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 6496 | u32 transport_offset = (u32)skb_transport_offset(skb); |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6497 | u32 mss = skb_shinfo(skb)->gso_size; |
| 6498 | |
| 6499 | if (mss) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6500 | if (transport_offset > GTTCPHO_MAX) { |
| 6501 | netif_warn(tp, tx_err, tp->dev, |
| 6502 | "Invalid transport offset 0x%x for TSO\n", |
| 6503 | transport_offset); |
| 6504 | return false; |
| 6505 | } |
| 6506 | |
| 6507 | switch (get_protocol(skb)) { |
| 6508 | case htons(ETH_P_IP): |
| 6509 | opts[0] |= TD1_GTSENV4; |
| 6510 | break; |
| 6511 | |
| 6512 | case htons(ETH_P_IPV6): |
| 6513 | if (msdn_giant_send_check(skb)) |
| 6514 | return false; |
| 6515 | |
| 6516 | opts[0] |= TD1_GTSENV6; |
| 6517 | break; |
| 6518 | |
| 6519 | default: |
| 6520 | WARN_ON_ONCE(1); |
| 6521 | break; |
| 6522 | } |
| 6523 | |
hayeswang | bdfa4ed | 2014-07-11 16:25:57 +0800 | [diff] [blame] | 6524 | opts[0] |= transport_offset << GTTCPHO_SHIFT; |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6525 | opts[1] |= min(mss, TD_MSS_MAX) << TD1_MSS_SHIFT; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6526 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6527 | u8 ip_protocol; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6528 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6529 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
| 6530 | return skb_checksum_help(skb) == 0 && rtl_skb_pad(skb); |
| 6531 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6532 | if (transport_offset > TCPHO_MAX) { |
| 6533 | netif_warn(tp, tx_err, tp->dev, |
| 6534 | "Invalid transport offset 0x%x\n", |
| 6535 | transport_offset); |
| 6536 | return false; |
| 6537 | } |
| 6538 | |
| 6539 | switch (get_protocol(skb)) { |
| 6540 | case htons(ETH_P_IP): |
| 6541 | opts[1] |= TD1_IPv4_CS; |
| 6542 | ip_protocol = ip_hdr(skb)->protocol; |
| 6543 | break; |
| 6544 | |
| 6545 | case htons(ETH_P_IPV6): |
| 6546 | opts[1] |= TD1_IPv6_CS; |
| 6547 | ip_protocol = ipv6_hdr(skb)->nexthdr; |
| 6548 | break; |
| 6549 | |
| 6550 | default: |
| 6551 | ip_protocol = IPPROTO_RAW; |
| 6552 | break; |
| 6553 | } |
| 6554 | |
| 6555 | if (ip_protocol == IPPROTO_TCP) |
| 6556 | opts[1] |= TD1_TCP_CS; |
| 6557 | else if (ip_protocol == IPPROTO_UDP) |
| 6558 | opts[1] |= TD1_UDP_CS; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6559 | else |
| 6560 | WARN_ON_ONCE(1); |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6561 | |
| 6562 | opts[1] |= transport_offset << TCPHO_SHIFT; |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6563 | } else { |
| 6564 | if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
| 6565 | return rtl_skb_pad(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6566 | } |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 6567 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6568 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6569 | } |
| 6570 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6571 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 6572 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6573 | { |
| 6574 | struct rtl8169_private *tp = netdev_priv(dev); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6575 | unsigned int entry = tp->cur_tx % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6576 | struct TxDesc *txd = tp->TxDescArray + entry; |
| 6577 | void __iomem *ioaddr = tp->mmio_addr; |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6578 | struct device *d = &tp->pci_dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6579 | dma_addr_t mapping; |
| 6580 | u32 status, len; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6581 | u32 opts[2]; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6582 | int frags; |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6583 | |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 6584 | if (unlikely(!TX_FRAGS_READY_FOR(tp, skb_shinfo(skb)->nr_frags))) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6585 | 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] | 6586 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6587 | } |
| 6588 | |
| 6589 | if (unlikely(le32_to_cpu(txd->opts1) & DescOwn)) |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6590 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6591 | |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6592 | opts[1] = cpu_to_le32(rtl8169_tx_vlan_tag(skb)); |
| 6593 | opts[0] = DescOwn; |
| 6594 | |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 6595 | if (!tp->tso_csum(tp, skb, opts)) { |
| 6596 | r8169_csum_workaround(tp, skb); |
| 6597 | return NETDEV_TX_OK; |
| 6598 | } |
françois romieu | b423e9a | 2013-05-18 01:24:46 +0000 | [diff] [blame] | 6599 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6600 | len = skb_headlen(skb); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6601 | mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6602 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 6603 | if (net_ratelimit()) |
| 6604 | netif_err(tp, drv, dev, "Failed to map TX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6605 | goto err_dma_0; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 6606 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6607 | |
| 6608 | tp->tx_skb[entry].len = len; |
| 6609 | txd->addr = cpu_to_le64(mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6610 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6611 | frags = rtl8169_xmit_frags(tp, skb, opts); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6612 | if (frags < 0) |
| 6613 | goto err_dma_1; |
| 6614 | else if (frags) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6615 | opts[0] |= FirstFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6616 | else { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6617 | opts[0] |= FirstFrag | LastFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6618 | tp->tx_skb[entry].skb = skb; |
| 6619 | } |
| 6620 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6621 | txd->opts2 = cpu_to_le32(opts[1]); |
| 6622 | |
Richard Cochran | 5047fb5 | 2012-03-10 07:29:42 +0000 | [diff] [blame] | 6623 | skb_tx_timestamp(skb); |
| 6624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6625 | wmb(); |
| 6626 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6627 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 6628 | status = opts[0] | len | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6629 | txd->opts1 = cpu_to_le32(status); |
| 6630 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6631 | tp->cur_tx += frags + 1; |
| 6632 | |
David Dillow | 4c020a9 | 2010-03-03 16:33:10 +0000 | [diff] [blame] | 6633 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6634 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6635 | RTL_W8(TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6636 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6637 | mmiowb(); |
| 6638 | |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 6639 | if (!TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6640 | /* Avoid wrongly optimistic queue wake-up: rtl_tx thread must |
| 6641 | * not miss a ring update when it notices a stopped queue. |
| 6642 | */ |
| 6643 | smp_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6644 | netif_stop_queue(dev); |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6645 | /* Sync with rtl_tx: |
| 6646 | * - publish queue status and cur_tx ring index (write barrier) |
| 6647 | * - refresh dirty_tx ring index (read barrier). |
| 6648 | * May the current thread have a pessimistic view of the ring |
| 6649 | * status and forget to wake up queue, a racing rtl_tx thread |
| 6650 | * can't. |
| 6651 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 6652 | smp_mb(); |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 6653 | if (TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6654 | netif_wake_queue(dev); |
| 6655 | } |
| 6656 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6657 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6658 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6659 | err_dma_1: |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6660 | rtl8169_unmap_tx_skb(d, tp->tx_skb + entry, txd); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6661 | err_dma_0: |
Eric W. Biederman | 989c9ba | 2014-03-11 14:16:14 -0700 | [diff] [blame] | 6662 | dev_kfree_skb_any(skb); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 6663 | dev->stats.tx_dropped++; |
| 6664 | return NETDEV_TX_OK; |
| 6665 | |
| 6666 | err_stop_0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6667 | netif_stop_queue(dev); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6668 | dev->stats.tx_dropped++; |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 6669 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6670 | } |
| 6671 | |
| 6672 | static void rtl8169_pcierr_interrupt(struct net_device *dev) |
| 6673 | { |
| 6674 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6675 | struct pci_dev *pdev = tp->pci_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6676 | u16 pci_status, pci_cmd; |
| 6677 | |
| 6678 | pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); |
| 6679 | pci_read_config_word(pdev, PCI_STATUS, &pci_status); |
| 6680 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6681 | netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n", |
| 6682 | pci_cmd, pci_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6683 | |
| 6684 | /* |
| 6685 | * The recovery sequence below admits a very elaborated explanation: |
| 6686 | * - it seems to work; |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6687 | * - I did not see what else could be done; |
| 6688 | * - it makes iop3xx happy. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6689 | * |
| 6690 | * Feel free to adjust to your needs. |
| 6691 | */ |
Francois Romieu | a27993f | 2006-12-18 00:04:19 +0100 | [diff] [blame] | 6692 | if (pdev->broken_parity_status) |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6693 | pci_cmd &= ~PCI_COMMAND_PARITY; |
| 6694 | else |
| 6695 | pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; |
| 6696 | |
| 6697 | pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6698 | |
| 6699 | pci_write_config_word(pdev, PCI_STATUS, |
| 6700 | pci_status & (PCI_STATUS_DETECTED_PARITY | |
| 6701 | PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT | |
| 6702 | PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT)); |
| 6703 | |
| 6704 | /* The infamous DAC f*ckup only happens at boot time */ |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 6705 | if ((tp->cp_cmd & PCIDAC) && !tp->cur_rx) { |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 6706 | void __iomem *ioaddr = tp->mmio_addr; |
| 6707 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6708 | netif_info(tp, intr, dev, "disabling PCI DAC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6709 | tp->cp_cmd &= ~PCIDAC; |
| 6710 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 6711 | dev->features &= ~NETIF_F_HIGHDMA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6712 | } |
| 6713 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 6714 | rtl8169_hw_reset(tp); |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 6715 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 6716 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6717 | } |
| 6718 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6719 | static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6720 | { |
| 6721 | unsigned int dirty_tx, tx_left; |
| 6722 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6723 | dirty_tx = tp->dirty_tx; |
| 6724 | smp_rmb(); |
| 6725 | tx_left = tp->cur_tx - dirty_tx; |
| 6726 | |
| 6727 | while (tx_left > 0) { |
| 6728 | unsigned int entry = dirty_tx % NUM_TX_DESC; |
| 6729 | struct ring_info *tx_skb = tp->tx_skb + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6730 | u32 status; |
| 6731 | |
| 6732 | rmb(); |
| 6733 | status = le32_to_cpu(tp->TxDescArray[entry].opts1); |
| 6734 | if (status & DescOwn) |
| 6735 | break; |
| 6736 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6737 | rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb, |
| 6738 | tp->TxDescArray + entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6739 | if (status & LastFrag) { |
Francois Romieu | 17bcb68 | 2012-07-23 22:55:55 +0200 | [diff] [blame] | 6740 | u64_stats_update_begin(&tp->tx_stats.syncp); |
| 6741 | tp->tx_stats.packets++; |
| 6742 | tp->tx_stats.bytes += tx_skb->skb->len; |
| 6743 | u64_stats_update_end(&tp->tx_stats.syncp); |
Eric W. Biederman | 989c9ba | 2014-03-11 14:16:14 -0700 | [diff] [blame] | 6744 | dev_kfree_skb_any(tx_skb->skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6745 | tx_skb->skb = NULL; |
| 6746 | } |
| 6747 | dirty_tx++; |
| 6748 | tx_left--; |
| 6749 | } |
| 6750 | |
| 6751 | if (tp->dirty_tx != dirty_tx) { |
| 6752 | tp->dirty_tx = dirty_tx; |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 6753 | /* Sync with rtl8169_start_xmit: |
| 6754 | * - publish dirty_tx ring index (write barrier) |
| 6755 | * - refresh cur_tx ring index and queue status (read barrier) |
| 6756 | * May the current thread miss the stopped queue condition, |
| 6757 | * a racing xmit thread can only have a right view of the |
| 6758 | * ring status. |
| 6759 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 6760 | smp_mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6761 | if (netif_queue_stopped(dev) && |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 6762 | TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6763 | netif_wake_queue(dev); |
| 6764 | } |
Francois Romieu | d78ae2d | 2007-08-26 20:08:19 +0200 | [diff] [blame] | 6765 | /* |
| 6766 | * 8168 hack: TxPoll requests are lost when the Tx packets are |
| 6767 | * too close. Let's kick an extra TxPoll request when a burst |
| 6768 | * of start_xmit activity is detected (if it is not detected, |
| 6769 | * it is slow enough). -- FR |
| 6770 | */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6771 | if (tp->cur_tx != dirty_tx) { |
| 6772 | void __iomem *ioaddr = tp->mmio_addr; |
| 6773 | |
Francois Romieu | d78ae2d | 2007-08-26 20:08:19 +0200 | [diff] [blame] | 6774 | RTL_W8(TxPoll, NPQ); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6775 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6776 | } |
| 6777 | } |
| 6778 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6779 | static inline int rtl8169_fragmented_frame(u32 status) |
| 6780 | { |
| 6781 | return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag); |
| 6782 | } |
| 6783 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 6784 | static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6785 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6786 | u32 status = opts1 & RxProtoMask; |
| 6787 | |
| 6788 | if (((status == RxProtoTCP) && !(opts1 & TCPFail)) || |
Shan Wei | d5d3ebe | 2010-11-12 00:15:25 +0000 | [diff] [blame] | 6789 | ((status == RxProtoUDP) && !(opts1 & UDPFail))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6790 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 6791 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 6792 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6793 | } |
| 6794 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6795 | static struct sk_buff *rtl8169_try_rx_copy(void *data, |
| 6796 | struct rtl8169_private *tp, |
| 6797 | int pkt_size, |
| 6798 | dma_addr_t addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6799 | { |
Stephen Hemminger | b449655 | 2007-06-17 01:06:49 +0200 | [diff] [blame] | 6800 | struct sk_buff *skb; |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6801 | struct device *d = &tp->pci_dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6802 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6803 | data = rtl8169_align(data); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6804 | dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6805 | prefetch(data); |
| 6806 | skb = netdev_alloc_skb_ip_align(tp->dev, pkt_size); |
| 6807 | if (skb) |
| 6808 | memcpy(skb->data, data, pkt_size); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6809 | dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE); |
| 6810 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6811 | return skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6812 | } |
| 6813 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6814 | 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] | 6815 | { |
| 6816 | unsigned int cur_rx, rx_left; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6817 | unsigned int count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6818 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6819 | cur_rx = tp->cur_rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6820 | |
Timo Teräs | 9fba081 | 2013-01-15 21:01:24 +0000 | [diff] [blame] | 6821 | 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] | 6822 | unsigned int entry = cur_rx % NUM_RX_DESC; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6823 | struct RxDesc *desc = tp->RxDescArray + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6824 | u32 status; |
| 6825 | |
| 6826 | rmb(); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 6827 | status = le32_to_cpu(desc->opts1) & tp->opts1_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6828 | |
| 6829 | if (status & DescOwn) |
| 6830 | break; |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 6831 | if (unlikely(status & RxRES)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6832 | netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n", |
| 6833 | status); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6834 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6835 | if (status & (RxRWT | RxRUNT)) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6836 | dev->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6837 | if (status & RxCRC) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6838 | dev->stats.rx_crc_errors++; |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 6839 | if (status & RxFOVF) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6840 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6841 | dev->stats.rx_fifo_errors++; |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 6842 | } |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 6843 | if ((status & (RxRUNT | RxCRC)) && |
| 6844 | !(status & (RxRWT | RxFOVF)) && |
| 6845 | (dev->features & NETIF_F_RXALL)) |
| 6846 | goto process_pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6847 | } else { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6848 | struct sk_buff *skb; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 6849 | dma_addr_t addr; |
| 6850 | int pkt_size; |
| 6851 | |
| 6852 | process_pkt: |
| 6853 | addr = le64_to_cpu(desc->addr); |
Ben Greear | 79d0c1d | 2012-02-10 15:04:34 +0000 | [diff] [blame] | 6854 | if (likely(!(dev->features & NETIF_F_RXFCS))) |
| 6855 | pkt_size = (status & 0x00003fff) - 4; |
| 6856 | else |
| 6857 | pkt_size = status & 0x00003fff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6858 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6859 | /* |
| 6860 | * The driver does not support incoming fragmented |
| 6861 | * frames. They are seen as a symptom of over-mtu |
| 6862 | * sized frames. |
| 6863 | */ |
| 6864 | if (unlikely(rtl8169_fragmented_frame(status))) { |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6865 | dev->stats.rx_dropped++; |
| 6866 | dev->stats.rx_length_errors++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6867 | goto release_descriptor; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6868 | } |
| 6869 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6870 | skb = rtl8169_try_rx_copy(tp->Rx_databuff[entry], |
| 6871 | tp, pkt_size, addr); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6872 | if (!skb) { |
| 6873 | dev->stats.rx_dropped++; |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6874 | goto release_descriptor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6875 | } |
| 6876 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 6877 | rtl8169_rx_csum(skb, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6878 | skb_put(skb, pkt_size); |
| 6879 | skb->protocol = eth_type_trans(skb, dev); |
| 6880 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 6881 | rtl8169_rx_vlan_tag(desc, skb); |
| 6882 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6883 | napi_gro_receive(&tp->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6884 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6885 | u64_stats_update_begin(&tp->rx_stats.syncp); |
| 6886 | tp->rx_stats.packets++; |
| 6887 | tp->rx_stats.bytes += pkt_size; |
| 6888 | u64_stats_update_end(&tp->rx_stats.syncp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6889 | } |
françois romieu | ce11ff5 | 2013-01-24 13:30:06 +0000 | [diff] [blame] | 6890 | release_descriptor: |
| 6891 | desc->opts2 = 0; |
| 6892 | wmb(); |
| 6893 | rtl8169_mark_to_asic(desc, rx_buf_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6894 | } |
| 6895 | |
| 6896 | count = cur_rx - tp->cur_rx; |
| 6897 | tp->cur_rx = cur_rx; |
| 6898 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6899 | return count; |
| 6900 | } |
| 6901 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 6902 | static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6903 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 6904 | struct net_device *dev = dev_instance; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6905 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6906 | int handled = 0; |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 6907 | u16 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6908 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 6909 | status = rtl_get_events(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6910 | if (status && status != 0xffff) { |
| 6911 | status &= RTL_EVENT_NAPI | tp->event_slow; |
| 6912 | if (status) { |
| 6913 | handled = 1; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 6914 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6915 | rtl_irq_disable(tp); |
| 6916 | napi_schedule(&tp->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6917 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6918 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6919 | return IRQ_RETVAL(handled); |
| 6920 | } |
| 6921 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6922 | /* |
| 6923 | * Workqueue context. |
| 6924 | */ |
| 6925 | static void rtl_slow_event_work(struct rtl8169_private *tp) |
| 6926 | { |
| 6927 | struct net_device *dev = tp->dev; |
| 6928 | u16 status; |
| 6929 | |
| 6930 | status = rtl_get_events(tp) & tp->event_slow; |
| 6931 | rtl_ack_events(tp, status); |
| 6932 | |
| 6933 | if (unlikely(status & RxFIFOOver)) { |
| 6934 | switch (tp->mac_version) { |
| 6935 | /* Work around for rx fifo overflow */ |
| 6936 | case RTL_GIGA_MAC_VER_11: |
| 6937 | netif_stop_queue(dev); |
Francois Romieu | 934714d | 2012-01-31 11:09:21 +0100 | [diff] [blame] | 6938 | /* XXX - Hack alert. See rtl_task(). */ |
| 6939 | set_bit(RTL_FLAG_TASK_RESET_PENDING, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6940 | default: |
| 6941 | break; |
| 6942 | } |
| 6943 | } |
| 6944 | |
| 6945 | if (unlikely(status & SYSErr)) |
| 6946 | rtl8169_pcierr_interrupt(dev); |
| 6947 | |
| 6948 | if (status & LinkChg) |
| 6949 | __rtl8169_check_link_status(dev, tp, tp->mmio_addr, true); |
| 6950 | |
françois romieu | 7dbb491 | 2012-06-09 10:53:16 +0000 | [diff] [blame] | 6951 | rtl_irq_enable_all(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6952 | } |
| 6953 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6954 | static void rtl_task(struct work_struct *work) |
| 6955 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6956 | static const struct { |
| 6957 | int bitnr; |
| 6958 | void (*action)(struct rtl8169_private *); |
| 6959 | } rtl_work[] = { |
Francois Romieu | 934714d | 2012-01-31 11:09:21 +0100 | [diff] [blame] | 6960 | /* XXX - keep rtl_slow_event_work() as first element. */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6961 | { RTL_FLAG_TASK_SLOW_PENDING, rtl_slow_event_work }, |
| 6962 | { RTL_FLAG_TASK_RESET_PENDING, rtl_reset_work }, |
| 6963 | { RTL_FLAG_TASK_PHY_PENDING, rtl_phy_work } |
| 6964 | }; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6965 | struct rtl8169_private *tp = |
| 6966 | container_of(work, struct rtl8169_private, wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6967 | struct net_device *dev = tp->dev; |
| 6968 | int i; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6969 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6970 | rtl_lock_work(tp); |
| 6971 | |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 6972 | if (!netif_running(dev) || |
| 6973 | !test_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6974 | goto out_unlock; |
| 6975 | |
| 6976 | for (i = 0; i < ARRAY_SIZE(rtl_work); i++) { |
| 6977 | bool pending; |
| 6978 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6979 | pending = test_and_clear_bit(rtl_work[i].bitnr, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6980 | if (pending) |
| 6981 | rtl_work[i].action(tp); |
| 6982 | } |
| 6983 | |
| 6984 | out_unlock: |
| 6985 | rtl_unlock_work(tp); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6986 | } |
| 6987 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6988 | static int rtl8169_poll(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6989 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6990 | struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); |
| 6991 | struct net_device *dev = tp->dev; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6992 | u16 enable_mask = RTL_EVENT_NAPI | tp->event_slow; |
| 6993 | int work_done= 0; |
| 6994 | u16 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6995 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6996 | status = rtl_get_events(tp); |
| 6997 | rtl_ack_events(tp, status & ~tp->event_slow); |
| 6998 | |
| 6999 | if (status & RTL_EVENT_NAPI_RX) |
| 7000 | work_done = rtl_rx(dev, tp, (u32) budget); |
| 7001 | |
| 7002 | if (status & RTL_EVENT_NAPI_TX) |
| 7003 | rtl_tx(dev, tp); |
| 7004 | |
| 7005 | if (status & tp->event_slow) { |
| 7006 | enable_mask &= ~tp->event_slow; |
| 7007 | |
| 7008 | rtl_schedule_task(tp, RTL_FLAG_TASK_SLOW_PENDING); |
| 7009 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7010 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7011 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 7012 | napi_complete(napi); |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 7013 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7014 | rtl_irq_enable(tp, enable_mask); |
| 7015 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7016 | } |
| 7017 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 7018 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7019 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7020 | |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 7021 | static void rtl8169_rx_missed(struct net_device *dev, void __iomem *ioaddr) |
| 7022 | { |
| 7023 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7024 | |
| 7025 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) |
| 7026 | return; |
| 7027 | |
| 7028 | dev->stats.rx_missed_errors += (RTL_R32(RxMissed) & 0xffffff); |
| 7029 | RTL_W32(RxMissed, 0); |
| 7030 | } |
| 7031 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7032 | static void rtl8169_down(struct net_device *dev) |
| 7033 | { |
| 7034 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7035 | void __iomem *ioaddr = tp->mmio_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7036 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 7037 | del_timer_sync(&tp->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7038 | |
Stephen Hemminger | 93dd79e | 2007-10-28 17:14:06 +0100 | [diff] [blame] | 7039 | napi_disable(&tp->napi); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7040 | netif_stop_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7041 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 7042 | rtl8169_hw_reset(tp); |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 7043 | /* |
| 7044 | * At this point device interrupts can not be enabled in any function, |
Francois Romieu | 209e5ac | 2012-01-26 09:59:50 +0100 | [diff] [blame] | 7045 | * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task) |
| 7046 | * and napi is disabled (rtl8169_poll). |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 7047 | */ |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 7048 | rtl8169_rx_missed(dev, ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7049 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7050 | /* Give a racing hard_start_xmit a few cycles to complete. */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7051 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7052 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7053 | rtl8169_tx_clear(tp); |
| 7054 | |
| 7055 | rtl8169_rx_clear(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7056 | |
| 7057 | rtl_pll_power_down(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7058 | } |
| 7059 | |
| 7060 | static int rtl8169_close(struct net_device *dev) |
| 7061 | { |
| 7062 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7063 | struct pci_dev *pdev = tp->pci_dev; |
| 7064 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7065 | pm_runtime_get_sync(&pdev->dev); |
| 7066 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7067 | /* Update counters before going down */ |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 7068 | rtl8169_update_counters(dev); |
| 7069 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7070 | rtl_lock_work(tp); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7071 | clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7072 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7073 | rtl8169_down(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7074 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7075 | |
Lekensteyn | 4ea7244 | 2013-07-22 09:53:30 +0200 | [diff] [blame] | 7076 | cancel_work_sync(&tp->wk.work); |
| 7077 | |
Francois Romieu | 92a7c4e | 2012-03-10 10:42:12 +0100 | [diff] [blame] | 7078 | free_irq(pdev->irq, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7079 | |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 7080 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 7081 | tp->RxPhyAddr); |
| 7082 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 7083 | tp->TxPhyAddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7084 | tp->TxDescArray = NULL; |
| 7085 | tp->RxDescArray = NULL; |
| 7086 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7087 | pm_runtime_put_sync(&pdev->dev); |
| 7088 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7089 | return 0; |
| 7090 | } |
| 7091 | |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 7092 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7093 | static void rtl8169_netpoll(struct net_device *dev) |
| 7094 | { |
| 7095 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7096 | |
| 7097 | rtl8169_interrupt(tp->pci_dev->irq, dev); |
| 7098 | } |
| 7099 | #endif |
| 7100 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7101 | static int rtl_open(struct net_device *dev) |
| 7102 | { |
| 7103 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7104 | void __iomem *ioaddr = tp->mmio_addr; |
| 7105 | struct pci_dev *pdev = tp->pci_dev; |
| 7106 | int retval = -ENOMEM; |
| 7107 | |
| 7108 | pm_runtime_get_sync(&pdev->dev); |
| 7109 | |
| 7110 | /* |
Jiri Kosina | e75d660 | 2012-04-08 21:48:52 +0200 | [diff] [blame] | 7111 | * Rx and Tx descriptors needs 256 bytes alignment. |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7112 | * dma_alloc_coherent provides more. |
| 7113 | */ |
| 7114 | tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES, |
| 7115 | &tp->TxPhyAddr, GFP_KERNEL); |
| 7116 | if (!tp->TxDescArray) |
| 7117 | goto err_pm_runtime_put; |
| 7118 | |
| 7119 | tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, |
| 7120 | &tp->RxPhyAddr, GFP_KERNEL); |
| 7121 | if (!tp->RxDescArray) |
| 7122 | goto err_free_tx_0; |
| 7123 | |
| 7124 | retval = rtl8169_init_ring(dev); |
| 7125 | if (retval < 0) |
| 7126 | goto err_free_rx_1; |
| 7127 | |
| 7128 | INIT_WORK(&tp->wk.work, rtl_task); |
| 7129 | |
| 7130 | smp_mb(); |
| 7131 | |
| 7132 | rtl_request_firmware(tp); |
| 7133 | |
Francois Romieu | 92a7c4e | 2012-03-10 10:42:12 +0100 | [diff] [blame] | 7134 | retval = request_irq(pdev->irq, rtl8169_interrupt, |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7135 | (tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED, |
| 7136 | dev->name, dev); |
| 7137 | if (retval < 0) |
| 7138 | goto err_release_fw_2; |
| 7139 | |
| 7140 | rtl_lock_work(tp); |
| 7141 | |
| 7142 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
| 7143 | |
| 7144 | napi_enable(&tp->napi); |
| 7145 | |
| 7146 | rtl8169_init_phy(dev, tp); |
| 7147 | |
| 7148 | __rtl8169_set_features(dev, dev->features); |
| 7149 | |
| 7150 | rtl_pll_power_up(tp); |
| 7151 | |
| 7152 | rtl_hw_start(dev); |
| 7153 | |
| 7154 | netif_start_queue(dev); |
| 7155 | |
| 7156 | rtl_unlock_work(tp); |
| 7157 | |
| 7158 | tp->saved_wolopts = 0; |
| 7159 | pm_runtime_put_noidle(&pdev->dev); |
| 7160 | |
| 7161 | rtl8169_check_link_status(dev, tp, ioaddr); |
| 7162 | out: |
| 7163 | return retval; |
| 7164 | |
| 7165 | err_release_fw_2: |
| 7166 | rtl_release_firmware(tp); |
| 7167 | rtl8169_rx_clear(tp); |
| 7168 | err_free_rx_1: |
| 7169 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 7170 | tp->RxPhyAddr); |
| 7171 | tp->RxDescArray = NULL; |
| 7172 | err_free_tx_0: |
| 7173 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 7174 | tp->TxPhyAddr); |
| 7175 | tp->TxDescArray = NULL; |
| 7176 | err_pm_runtime_put: |
| 7177 | pm_runtime_put_noidle(&pdev->dev); |
| 7178 | goto out; |
| 7179 | } |
| 7180 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7181 | static struct rtnl_link_stats64 * |
| 7182 | rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7183 | { |
| 7184 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7185 | void __iomem *ioaddr = tp->mmio_addr; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7186 | unsigned int start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7187 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7188 | if (netif_running(dev)) |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 7189 | rtl8169_rx_missed(dev, ioaddr); |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 7190 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7191 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7192 | start = u64_stats_fetch_begin_irq(&tp->rx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7193 | stats->rx_packets = tp->rx_stats.packets; |
| 7194 | stats->rx_bytes = tp->rx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7195 | } while (u64_stats_fetch_retry_irq(&tp->rx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7196 | |
| 7197 | |
| 7198 | do { |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7199 | start = u64_stats_fetch_begin_irq(&tp->tx_stats.syncp); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7200 | stats->tx_packets = tp->tx_stats.packets; |
| 7201 | stats->tx_bytes = tp->tx_stats.bytes; |
Eric W. Biederman | 57a7744 | 2014-03-13 21:26:42 -0700 | [diff] [blame] | 7202 | } while (u64_stats_fetch_retry_irq(&tp->tx_stats.syncp, start)); |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 7203 | |
| 7204 | stats->rx_dropped = dev->stats.rx_dropped; |
| 7205 | stats->tx_dropped = dev->stats.tx_dropped; |
| 7206 | stats->rx_length_errors = dev->stats.rx_length_errors; |
| 7207 | stats->rx_errors = dev->stats.rx_errors; |
| 7208 | stats->rx_crc_errors = dev->stats.rx_crc_errors; |
| 7209 | stats->rx_fifo_errors = dev->stats.rx_fifo_errors; |
| 7210 | stats->rx_missed_errors = dev->stats.rx_missed_errors; |
| 7211 | |
| 7212 | return stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7213 | } |
| 7214 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7215 | static void rtl8169_net_suspend(struct net_device *dev) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7216 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7217 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7218 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7219 | if (!netif_running(dev)) |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7220 | return; |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7221 | |
| 7222 | netif_device_detach(dev); |
| 7223 | netif_stop_queue(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7224 | |
| 7225 | rtl_lock_work(tp); |
| 7226 | napi_disable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7227 | clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7228 | rtl_unlock_work(tp); |
| 7229 | |
| 7230 | rtl_pll_power_down(tp); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7231 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7232 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7233 | #ifdef CONFIG_PM |
| 7234 | |
| 7235 | static int rtl8169_suspend(struct device *device) |
| 7236 | { |
| 7237 | struct pci_dev *pdev = to_pci_dev(device); |
| 7238 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7239 | |
| 7240 | rtl8169_net_suspend(dev); |
Francois Romieu | 1371fa6 | 2007-04-02 23:01:11 +0200 | [diff] [blame] | 7241 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7242 | return 0; |
| 7243 | } |
| 7244 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7245 | static void __rtl8169_resume(struct net_device *dev) |
| 7246 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7247 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7248 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7249 | netif_device_attach(dev); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 7250 | |
| 7251 | rtl_pll_power_up(tp); |
| 7252 | |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 7253 | rtl_lock_work(tp); |
| 7254 | napi_enable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 7255 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 7256 | rtl_unlock_work(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7257 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 7258 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7259 | } |
| 7260 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7261 | static int rtl8169_resume(struct device *device) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7262 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7263 | struct pci_dev *pdev = to_pci_dev(device); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7264 | struct net_device *dev = pci_get_drvdata(pdev); |
Stanislaw Gruszka | fccec10 | 2010-10-20 22:25:42 +0000 | [diff] [blame] | 7265 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7266 | |
| 7267 | rtl8169_init_phy(dev, tp); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7268 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7269 | if (netif_running(dev)) |
| 7270 | __rtl8169_resume(dev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7271 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7272 | return 0; |
| 7273 | } |
| 7274 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7275 | static int rtl8169_runtime_suspend(struct device *device) |
| 7276 | { |
| 7277 | struct pci_dev *pdev = to_pci_dev(device); |
| 7278 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7279 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7280 | |
| 7281 | if (!tp->TxDescArray) |
| 7282 | return 0; |
| 7283 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7284 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7285 | tp->saved_wolopts = __rtl8169_get_wol(tp); |
| 7286 | __rtl8169_set_wol(tp, WAKE_ANY); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7287 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7288 | |
| 7289 | rtl8169_net_suspend(dev); |
| 7290 | |
| 7291 | return 0; |
| 7292 | } |
| 7293 | |
| 7294 | static int rtl8169_runtime_resume(struct device *device) |
| 7295 | { |
| 7296 | struct pci_dev *pdev = to_pci_dev(device); |
| 7297 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7298 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7299 | |
| 7300 | if (!tp->TxDescArray) |
| 7301 | return 0; |
| 7302 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7303 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7304 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
| 7305 | tp->saved_wolopts = 0; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 7306 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7307 | |
Stanislaw Gruszka | fccec10 | 2010-10-20 22:25:42 +0000 | [diff] [blame] | 7308 | rtl8169_init_phy(dev, tp); |
| 7309 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7310 | __rtl8169_resume(dev); |
| 7311 | |
| 7312 | return 0; |
| 7313 | } |
| 7314 | |
| 7315 | static int rtl8169_runtime_idle(struct device *device) |
| 7316 | { |
| 7317 | struct pci_dev *pdev = to_pci_dev(device); |
| 7318 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7319 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7320 | |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 7321 | return tp->TxDescArray ? -EBUSY : 0; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 7322 | } |
| 7323 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 7324 | static const struct dev_pm_ops rtl8169_pm_ops = { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7325 | .suspend = rtl8169_suspend, |
| 7326 | .resume = rtl8169_resume, |
| 7327 | .freeze = rtl8169_suspend, |
| 7328 | .thaw = rtl8169_resume, |
| 7329 | .poweroff = rtl8169_suspend, |
| 7330 | .restore = rtl8169_resume, |
| 7331 | .runtime_suspend = rtl8169_runtime_suspend, |
| 7332 | .runtime_resume = rtl8169_runtime_resume, |
| 7333 | .runtime_idle = rtl8169_runtime_idle, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7334 | }; |
| 7335 | |
| 7336 | #define RTL8169_PM_OPS (&rtl8169_pm_ops) |
| 7337 | |
| 7338 | #else /* !CONFIG_PM */ |
| 7339 | |
| 7340 | #define RTL8169_PM_OPS NULL |
| 7341 | |
| 7342 | #endif /* !CONFIG_PM */ |
| 7343 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7344 | static void rtl_wol_shutdown_quirk(struct rtl8169_private *tp) |
| 7345 | { |
| 7346 | void __iomem *ioaddr = tp->mmio_addr; |
| 7347 | |
| 7348 | /* WoL fails with 8168b when the receiver is disabled. */ |
| 7349 | switch (tp->mac_version) { |
| 7350 | case RTL_GIGA_MAC_VER_11: |
| 7351 | case RTL_GIGA_MAC_VER_12: |
| 7352 | case RTL_GIGA_MAC_VER_17: |
| 7353 | pci_clear_master(tp->pci_dev); |
| 7354 | |
| 7355 | RTL_W8(ChipCmd, CmdRxEnb); |
| 7356 | /* PCI commit */ |
| 7357 | RTL_R8(ChipCmd); |
| 7358 | break; |
| 7359 | default: |
| 7360 | break; |
| 7361 | } |
| 7362 | } |
| 7363 | |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 7364 | static void rtl_shutdown(struct pci_dev *pdev) |
| 7365 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7366 | struct net_device *dev = pci_get_drvdata(pdev); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 7367 | struct rtl8169_private *tp = netdev_priv(dev); |
françois romieu | 2a15cd2 | 2012-03-06 01:14:12 +0000 | [diff] [blame] | 7368 | struct device *d = &pdev->dev; |
| 7369 | |
| 7370 | pm_runtime_get_sync(d); |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 7371 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7372 | rtl8169_net_suspend(dev); |
| 7373 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 7374 | /* Restore original MAC address */ |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 7375 | rtl_rar_set(tp, dev->perm_addr); |
| 7376 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 7377 | rtl8169_hw_reset(tp); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 7378 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7379 | if (system_state == SYSTEM_POWER_OFF) { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 7380 | if (__rtl8169_get_wol(tp) & WAKE_ANY) { |
| 7381 | rtl_wol_suspend_quirk(tp); |
| 7382 | rtl_wol_shutdown_quirk(tp); |
françois romieu | ca52efd | 2009-07-24 12:34:19 +0000 | [diff] [blame] | 7383 | } |
| 7384 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7385 | pci_wake_from_d3(pdev, true); |
| 7386 | pci_set_power_state(pdev, PCI_D3hot); |
| 7387 | } |
françois romieu | 2a15cd2 | 2012-03-06 01:14:12 +0000 | [diff] [blame] | 7388 | |
| 7389 | pm_runtime_put_noidle(d); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7390 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 7391 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7392 | static void rtl_remove_one(struct pci_dev *pdev) |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7393 | { |
| 7394 | struct net_device *dev = pci_get_drvdata(pdev); |
| 7395 | struct rtl8169_private *tp = netdev_priv(dev); |
| 7396 | |
| 7397 | if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
| 7398 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 7399 | tp->mac_version == RTL_GIGA_MAC_VER_31) { |
| 7400 | rtl8168_driver_stop(tp); |
| 7401 | } |
| 7402 | |
Devendra Naga | ad1be8d | 2012-05-31 01:51:20 +0000 | [diff] [blame] | 7403 | netif_napi_del(&tp->napi); |
| 7404 | |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7405 | unregister_netdev(dev); |
| 7406 | |
| 7407 | rtl_release_firmware(tp); |
| 7408 | |
| 7409 | if (pci_dev_run_wake(pdev)) |
| 7410 | pm_runtime_get_noresume(&pdev->dev); |
| 7411 | |
| 7412 | /* restore original MAC address */ |
| 7413 | rtl_rar_set(tp, dev->perm_addr); |
| 7414 | |
| 7415 | rtl_disable_msi(pdev, tp); |
| 7416 | rtl8169_release_board(pdev, dev, tp->mmio_addr); |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7417 | } |
| 7418 | |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 7419 | static const struct net_device_ops rtl_netdev_ops = { |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 7420 | .ndo_open = rtl_open, |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 7421 | .ndo_stop = rtl8169_close, |
| 7422 | .ndo_get_stats64 = rtl8169_get_stats64, |
| 7423 | .ndo_start_xmit = rtl8169_start_xmit, |
| 7424 | .ndo_tx_timeout = rtl8169_tx_timeout, |
| 7425 | .ndo_validate_addr = eth_validate_addr, |
| 7426 | .ndo_change_mtu = rtl8169_change_mtu, |
| 7427 | .ndo_fix_features = rtl8169_fix_features, |
| 7428 | .ndo_set_features = rtl8169_set_features, |
| 7429 | .ndo_set_mac_address = rtl_set_mac_address, |
| 7430 | .ndo_do_ioctl = rtl8169_ioctl, |
| 7431 | .ndo_set_rx_mode = rtl_set_rx_mode, |
| 7432 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 7433 | .ndo_poll_controller = rtl8169_netpoll, |
| 7434 | #endif |
| 7435 | |
| 7436 | }; |
| 7437 | |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 7438 | static const struct rtl_cfg_info { |
| 7439 | void (*hw_start)(struct net_device *); |
| 7440 | unsigned int region; |
| 7441 | unsigned int align; |
| 7442 | u16 event_slow; |
| 7443 | unsigned features; |
| 7444 | u8 default_ver; |
| 7445 | } rtl_cfg_infos [] = { |
| 7446 | [RTL_CFG_0] = { |
| 7447 | .hw_start = rtl_hw_start_8169, |
| 7448 | .region = 1, |
| 7449 | .align = 0, |
| 7450 | .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver, |
| 7451 | .features = RTL_FEATURE_GMII, |
| 7452 | .default_ver = RTL_GIGA_MAC_VER_01, |
| 7453 | }, |
| 7454 | [RTL_CFG_1] = { |
| 7455 | .hw_start = rtl_hw_start_8168, |
| 7456 | .region = 2, |
| 7457 | .align = 8, |
| 7458 | .event_slow = SYSErr | LinkChg | RxOverflow, |
| 7459 | .features = RTL_FEATURE_GMII | RTL_FEATURE_MSI, |
| 7460 | .default_ver = RTL_GIGA_MAC_VER_11, |
| 7461 | }, |
| 7462 | [RTL_CFG_2] = { |
| 7463 | .hw_start = rtl_hw_start_8101, |
| 7464 | .region = 2, |
| 7465 | .align = 8, |
| 7466 | .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver | |
| 7467 | PCSTimeout, |
| 7468 | .features = RTL_FEATURE_MSI, |
| 7469 | .default_ver = RTL_GIGA_MAC_VER_13, |
| 7470 | } |
| 7471 | }; |
| 7472 | |
| 7473 | /* Cfg9346_Unlock assumed. */ |
| 7474 | static unsigned rtl_try_msi(struct rtl8169_private *tp, |
| 7475 | const struct rtl_cfg_info *cfg) |
| 7476 | { |
| 7477 | void __iomem *ioaddr = tp->mmio_addr; |
| 7478 | unsigned msi = 0; |
| 7479 | u8 cfg2; |
| 7480 | |
| 7481 | cfg2 = RTL_R8(Config2) & ~MSIEnable; |
| 7482 | if (cfg->features & RTL_FEATURE_MSI) { |
| 7483 | if (pci_enable_msi(tp->pci_dev)) { |
| 7484 | netif_info(tp, hw, tp->dev, "no MSI. Back to INTx.\n"); |
| 7485 | } else { |
| 7486 | cfg2 |= MSIEnable; |
| 7487 | msi = RTL_FEATURE_MSI; |
| 7488 | } |
| 7489 | } |
| 7490 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
| 7491 | RTL_W8(Config2, cfg2); |
| 7492 | return msi; |
| 7493 | } |
| 7494 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7495 | DECLARE_RTL_COND(rtl_link_list_ready_cond) |
| 7496 | { |
| 7497 | void __iomem *ioaddr = tp->mmio_addr; |
| 7498 | |
| 7499 | return RTL_R8(MCU) & LINK_LIST_RDY; |
| 7500 | } |
| 7501 | |
| 7502 | DECLARE_RTL_COND(rtl_rxtx_empty_cond) |
| 7503 | { |
| 7504 | void __iomem *ioaddr = tp->mmio_addr; |
| 7505 | |
| 7506 | return (RTL_R8(MCU) & RXTX_EMPTY) == RXTX_EMPTY; |
| 7507 | } |
| 7508 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7509 | static void rtl_hw_init_8168g(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7510 | { |
| 7511 | void __iomem *ioaddr = tp->mmio_addr; |
| 7512 | u32 data; |
| 7513 | |
| 7514 | tp->ocp_base = OCP_STD_PHY_BASE; |
| 7515 | |
| 7516 | RTL_W32(MISC, RTL_R32(MISC) | RXDV_GATED_EN); |
| 7517 | |
| 7518 | if (!rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 42)) |
| 7519 | return; |
| 7520 | |
| 7521 | if (!rtl_udelay_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42)) |
| 7522 | return; |
| 7523 | |
| 7524 | RTL_W8(ChipCmd, RTL_R8(ChipCmd) & ~(CmdTxEnb | CmdRxEnb)); |
| 7525 | msleep(1); |
| 7526 | RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB); |
| 7527 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 7528 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7529 | data &= ~(1 << 14); |
| 7530 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 7531 | |
| 7532 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 7533 | return; |
| 7534 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 7535 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7536 | data |= (1 << 15); |
| 7537 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 7538 | |
| 7539 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 7540 | return; |
| 7541 | } |
| 7542 | |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7543 | static void rtl_hw_initialize(struct rtl8169_private *tp) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7544 | { |
| 7545 | switch (tp->mac_version) { |
| 7546 | case RTL_GIGA_MAC_VER_40: |
| 7547 | case RTL_GIGA_MAC_VER_41: |
hayeswang | 57538c4 | 2013-04-01 22:23:40 +0000 | [diff] [blame] | 7548 | case RTL_GIGA_MAC_VER_42: |
hayeswang | 58152cd | 2013-04-01 22:23:42 +0000 | [diff] [blame] | 7549 | case RTL_GIGA_MAC_VER_43: |
hayeswang | 45dd95c | 2013-07-08 17:09:01 +0800 | [diff] [blame] | 7550 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 7551 | case RTL_GIGA_MAC_VER_45: |
| 7552 | case RTL_GIGA_MAC_VER_46: |
| 7553 | case RTL_GIGA_MAC_VER_47: |
| 7554 | case RTL_GIGA_MAC_VER_48: |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7555 | rtl_hw_init_8168g(tp); |
| 7556 | break; |
| 7557 | |
| 7558 | default: |
| 7559 | break; |
| 7560 | } |
| 7561 | } |
| 7562 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7563 | 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] | 7564 | { |
| 7565 | const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data; |
| 7566 | const unsigned int region = cfg->region; |
| 7567 | struct rtl8169_private *tp; |
| 7568 | struct mii_if_info *mii; |
| 7569 | struct net_device *dev; |
| 7570 | void __iomem *ioaddr; |
| 7571 | int chipset, i; |
| 7572 | int rc; |
| 7573 | |
| 7574 | if (netif_msg_drv(&debug)) { |
| 7575 | printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n", |
| 7576 | MODULENAME, RTL8169_VERSION); |
| 7577 | } |
| 7578 | |
| 7579 | dev = alloc_etherdev(sizeof (*tp)); |
| 7580 | if (!dev) { |
| 7581 | rc = -ENOMEM; |
| 7582 | goto out; |
| 7583 | } |
| 7584 | |
| 7585 | SET_NETDEV_DEV(dev, &pdev->dev); |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 7586 | dev->netdev_ops = &rtl_netdev_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7587 | tp = netdev_priv(dev); |
| 7588 | tp->dev = dev; |
| 7589 | tp->pci_dev = pdev; |
| 7590 | tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT); |
| 7591 | |
| 7592 | mii = &tp->mii; |
| 7593 | mii->dev = dev; |
| 7594 | mii->mdio_read = rtl_mdio_read; |
| 7595 | mii->mdio_write = rtl_mdio_write; |
| 7596 | mii->phy_id_mask = 0x1f; |
| 7597 | mii->reg_num_mask = 0x1f; |
| 7598 | mii->supports_gmii = !!(cfg->features & RTL_FEATURE_GMII); |
| 7599 | |
| 7600 | /* disable ASPM completely as that cause random device stop working |
| 7601 | * problems as well as full system hangs for some PCIe devices users */ |
| 7602 | pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 | |
| 7603 | PCIE_LINK_STATE_CLKPM); |
| 7604 | |
| 7605 | /* enable device (incl. PCI PM wakeup and hotplug setup) */ |
| 7606 | rc = pci_enable_device(pdev); |
| 7607 | if (rc < 0) { |
| 7608 | netif_err(tp, probe, dev, "enable failure\n"); |
| 7609 | goto err_out_free_dev_1; |
| 7610 | } |
| 7611 | |
| 7612 | if (pci_set_mwi(pdev) < 0) |
| 7613 | netif_info(tp, probe, dev, "Mem-Wr-Inval unavailable\n"); |
| 7614 | |
| 7615 | /* make sure PCI base addr 1 is MMIO */ |
| 7616 | if (!(pci_resource_flags(pdev, region) & IORESOURCE_MEM)) { |
| 7617 | netif_err(tp, probe, dev, |
| 7618 | "region #%d not an MMIO resource, aborting\n", |
| 7619 | region); |
| 7620 | rc = -ENODEV; |
| 7621 | goto err_out_mwi_2; |
| 7622 | } |
| 7623 | |
| 7624 | /* check for weird/broken PCI region reporting */ |
| 7625 | if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) { |
| 7626 | netif_err(tp, probe, dev, |
| 7627 | "Invalid PCI region size(s), aborting\n"); |
| 7628 | rc = -ENODEV; |
| 7629 | goto err_out_mwi_2; |
| 7630 | } |
| 7631 | |
| 7632 | rc = pci_request_regions(pdev, MODULENAME); |
| 7633 | if (rc < 0) { |
| 7634 | netif_err(tp, probe, dev, "could not request regions\n"); |
| 7635 | goto err_out_mwi_2; |
| 7636 | } |
| 7637 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7638 | tp->cp_cmd = 0; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7639 | |
| 7640 | if ((sizeof(dma_addr_t) > 4) && |
| 7641 | !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && use_dac) { |
| 7642 | tp->cp_cmd |= PCIDAC; |
| 7643 | dev->features |= NETIF_F_HIGHDMA; |
| 7644 | } else { |
| 7645 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 7646 | if (rc < 0) { |
| 7647 | netif_err(tp, probe, dev, "DMA configuration failed\n"); |
| 7648 | goto err_out_free_res_3; |
| 7649 | } |
| 7650 | } |
| 7651 | |
| 7652 | /* ioremap MMIO region */ |
| 7653 | ioaddr = ioremap(pci_resource_start(pdev, region), R8169_REGS_SIZE); |
| 7654 | if (!ioaddr) { |
| 7655 | netif_err(tp, probe, dev, "cannot remap MMIO, aborting\n"); |
| 7656 | rc = -EIO; |
| 7657 | goto err_out_free_res_3; |
| 7658 | } |
| 7659 | tp->mmio_addr = ioaddr; |
| 7660 | |
| 7661 | if (!pci_is_pcie(pdev)) |
| 7662 | netif_info(tp, probe, dev, "not PCI Express\n"); |
| 7663 | |
| 7664 | /* Identify chip attached to board */ |
| 7665 | rtl8169_get_mac_version(tp, dev, cfg->default_ver); |
| 7666 | |
| 7667 | rtl_init_rxcfg(tp); |
| 7668 | |
| 7669 | rtl_irq_disable(tp); |
| 7670 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 7671 | rtl_hw_initialize(tp); |
| 7672 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7673 | rtl_hw_reset(tp); |
| 7674 | |
| 7675 | rtl_ack_events(tp, 0xffff); |
| 7676 | |
| 7677 | pci_set_master(pdev); |
| 7678 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7679 | rtl_init_mdio_ops(tp); |
| 7680 | rtl_init_pll_power_ops(tp); |
| 7681 | rtl_init_jumbo_ops(tp); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 7682 | rtl_init_csi_ops(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7683 | |
| 7684 | rtl8169_print_mac_version(tp); |
| 7685 | |
| 7686 | chipset = tp->mac_version; |
| 7687 | tp->txd_version = rtl_chip_infos[chipset].txd_version; |
| 7688 | |
| 7689 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 7690 | RTL_W8(Config1, RTL_R8(Config1) | PMEnable); |
Peter Wu | 8f9d513 | 2013-08-17 11:00:02 +0200 | [diff] [blame] | 7691 | RTL_W8(Config5, RTL_R8(Config5) & (BWF | MWF | UWF | LanWake | PMEStatus)); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 7692 | switch (tp->mac_version) { |
Chun-Hao Lin | ac85bcd | 2014-10-01 23:17:16 +0800 | [diff] [blame] | 7693 | case RTL_GIGA_MAC_VER_34: |
| 7694 | case RTL_GIGA_MAC_VER_35: |
| 7695 | case RTL_GIGA_MAC_VER_36: |
| 7696 | case RTL_GIGA_MAC_VER_37: |
| 7697 | case RTL_GIGA_MAC_VER_38: |
| 7698 | case RTL_GIGA_MAC_VER_40: |
| 7699 | case RTL_GIGA_MAC_VER_41: |
| 7700 | case RTL_GIGA_MAC_VER_42: |
| 7701 | case RTL_GIGA_MAC_VER_43: |
| 7702 | case RTL_GIGA_MAC_VER_44: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 7703 | case RTL_GIGA_MAC_VER_45: |
| 7704 | case RTL_GIGA_MAC_VER_46: |
Chun-Hao Lin | ac85bcd | 2014-10-01 23:17:16 +0800 | [diff] [blame] | 7705 | case RTL_GIGA_MAC_VER_47: |
| 7706 | case RTL_GIGA_MAC_VER_48: |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 7707 | if (rtl_eri_read(tp, 0xdc, ERIAR_EXGMAC) & MagicPacket_v2) |
| 7708 | tp->features |= RTL_FEATURE_WOL; |
| 7709 | if ((RTL_R8(Config3) & LinkUp) != 0) |
| 7710 | tp->features |= RTL_FEATURE_WOL; |
| 7711 | break; |
| 7712 | default: |
| 7713 | if ((RTL_R8(Config3) & (LinkUp | MagicPacket)) != 0) |
| 7714 | tp->features |= RTL_FEATURE_WOL; |
| 7715 | break; |
| 7716 | } |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7717 | if ((RTL_R8(Config5) & (UWF | BWF | MWF)) != 0) |
| 7718 | tp->features |= RTL_FEATURE_WOL; |
| 7719 | tp->features |= rtl_try_msi(tp, cfg); |
| 7720 | RTL_W8(Cfg9346, Cfg9346_Lock); |
| 7721 | |
| 7722 | if (rtl_tbi_enabled(tp)) { |
| 7723 | tp->set_speed = rtl8169_set_speed_tbi; |
| 7724 | tp->get_settings = rtl8169_gset_tbi; |
| 7725 | tp->phy_reset_enable = rtl8169_tbi_reset_enable; |
| 7726 | tp->phy_reset_pending = rtl8169_tbi_reset_pending; |
| 7727 | tp->link_ok = rtl8169_tbi_link_ok; |
| 7728 | tp->do_ioctl = rtl_tbi_ioctl; |
| 7729 | } else { |
| 7730 | tp->set_speed = rtl8169_set_speed_xmii; |
| 7731 | tp->get_settings = rtl8169_gset_xmii; |
| 7732 | tp->phy_reset_enable = rtl8169_xmii_reset_enable; |
| 7733 | tp->phy_reset_pending = rtl8169_xmii_reset_pending; |
| 7734 | tp->link_ok = rtl8169_xmii_link_ok; |
| 7735 | tp->do_ioctl = rtl_xmii_ioctl; |
| 7736 | } |
| 7737 | |
| 7738 | mutex_init(&tp->wk.mutex); |
Kyle McMartin | 340fea3 | 2014-02-24 20:12:28 -0500 | [diff] [blame] | 7739 | u64_stats_init(&tp->rx_stats.syncp); |
| 7740 | u64_stats_init(&tp->tx_stats.syncp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7741 | |
| 7742 | /* Get MAC address */ |
Chun-Hao Lin | 89cceb2 | 2014-10-01 23:17:15 +0800 | [diff] [blame] | 7743 | if (tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 7744 | tp->mac_version == RTL_GIGA_MAC_VER_36 || |
| 7745 | tp->mac_version == RTL_GIGA_MAC_VER_37 || |
| 7746 | tp->mac_version == RTL_GIGA_MAC_VER_38 || |
| 7747 | tp->mac_version == RTL_GIGA_MAC_VER_40 || |
| 7748 | tp->mac_version == RTL_GIGA_MAC_VER_41 || |
| 7749 | tp->mac_version == RTL_GIGA_MAC_VER_42 || |
| 7750 | tp->mac_version == RTL_GIGA_MAC_VER_43 || |
| 7751 | tp->mac_version == RTL_GIGA_MAC_VER_44 || |
| 7752 | tp->mac_version == RTL_GIGA_MAC_VER_45 || |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 7753 | tp->mac_version == RTL_GIGA_MAC_VER_46 || |
| 7754 | tp->mac_version == RTL_GIGA_MAC_VER_47 || |
| 7755 | tp->mac_version == RTL_GIGA_MAC_VER_48) { |
| 7756 | u16 mac_addr[3]; |
| 7757 | |
Chun-Hao Lin | 05b9687 | 2014-10-01 23:17:12 +0800 | [diff] [blame] | 7758 | *(u32 *)&mac_addr[0] = rtl_eri_read(tp, 0xe0, ERIAR_EXGMAC); |
| 7759 | *(u16 *)&mac_addr[2] = rtl_eri_read(tp, 0xe4, ERIAR_EXGMAC); |
Chun-Hao Lin | 6e1d0b8 | 2014-08-20 01:54:04 +0800 | [diff] [blame] | 7760 | |
| 7761 | if (is_valid_ether_addr((u8 *)mac_addr)) |
| 7762 | rtl_rar_set(tp, (u8 *)mac_addr); |
| 7763 | } |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7764 | for (i = 0; i < ETH_ALEN; i++) |
| 7765 | dev->dev_addr[i] = RTL_R8(MAC0 + i); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7766 | |
Wilfried Klaebe | 7ad24ea | 2014-05-11 00:12:32 +0000 | [diff] [blame] | 7767 | dev->ethtool_ops = &rtl8169_ethtool_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7768 | dev->watchdog_timeo = RTL8169_TX_TIMEOUT; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7769 | |
| 7770 | netif_napi_add(dev, &tp->napi, rtl8169_poll, R8169_NAPI_WEIGHT); |
| 7771 | |
| 7772 | /* don't enable SG, IP_CSUM and TSO by default - it might not work |
| 7773 | * properly for all devices */ |
| 7774 | dev->features |= NETIF_F_RXCSUM | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7775 | NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7776 | |
| 7777 | 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] | 7778 | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_TX | |
| 7779 | NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7780 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 7781 | NETIF_F_HIGHDMA; |
| 7782 | |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7783 | tp->cp_cmd |= RxChkSum | RxVlan; |
| 7784 | |
| 7785 | /* |
| 7786 | * Pretend we are using VLANs; This bypasses a nasty bug where |
| 7787 | * Interrupts stop flowing on high load on 8110SCd controllers. |
| 7788 | */ |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7789 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
hayeswang | 929a031 | 2014-09-16 11:40:47 +0800 | [diff] [blame] | 7790 | /* Disallow toggling */ |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 7791 | dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_RX; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7792 | |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7793 | if (tp->txd_version == RTL_TD_0) |
| 7794 | tp->tso_csum = rtl8169_tso_csum_v1; |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7795 | else if (tp->txd_version == RTL_TD_1) { |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7796 | tp->tso_csum = rtl8169_tso_csum_v2; |
hayeswang | e974604 | 2014-07-11 16:25:58 +0800 | [diff] [blame] | 7797 | dev->hw_features |= NETIF_F_IPV6_CSUM | NETIF_F_TSO6; |
| 7798 | } else |
hayeswang | 5888d3f | 2014-07-11 16:25:56 +0800 | [diff] [blame] | 7799 | WARN_ON_ONCE(1); |
| 7800 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7801 | dev->hw_features |= NETIF_F_RXALL; |
| 7802 | dev->hw_features |= NETIF_F_RXFCS; |
| 7803 | |
| 7804 | tp->hw_start = cfg->hw_start; |
| 7805 | tp->event_slow = cfg->event_slow; |
| 7806 | |
| 7807 | tp->opts1_mask = (tp->mac_version != RTL_GIGA_MAC_VER_01) ? |
| 7808 | ~(RxBOVF | RxFOVF) : ~0; |
| 7809 | |
| 7810 | init_timer(&tp->timer); |
| 7811 | tp->timer.data = (unsigned long) dev; |
| 7812 | tp->timer.function = rtl8169_phy_timer; |
| 7813 | |
| 7814 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
| 7815 | |
| 7816 | rc = register_netdev(dev); |
| 7817 | if (rc < 0) |
| 7818 | goto err_out_msi_4; |
| 7819 | |
| 7820 | pci_set_drvdata(pdev, dev); |
| 7821 | |
Francois Romieu | 92a7c4e | 2012-03-10 10:42:12 +0100 | [diff] [blame] | 7822 | netif_info(tp, probe, dev, "%s at 0x%p, %pM, XID %08x IRQ %d\n", |
| 7823 | rtl_chip_infos[chipset].name, ioaddr, dev->dev_addr, |
| 7824 | (u32)(RTL_R32(TxConfig) & 0x9cf0f8ff), pdev->irq); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7825 | if (rtl_chip_infos[chipset].jumbo_max != JUMBO_1K) { |
| 7826 | netif_info(tp, probe, dev, "jumbo features [frames: %d bytes, " |
| 7827 | "tx checksumming: %s]\n", |
| 7828 | rtl_chip_infos[chipset].jumbo_max, |
| 7829 | rtl_chip_infos[chipset].jumbo_tx_csum ? "ok" : "ko"); |
| 7830 | } |
| 7831 | |
| 7832 | if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
| 7833 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 7834 | tp->mac_version == RTL_GIGA_MAC_VER_31) { |
| 7835 | rtl8168_driver_start(tp); |
| 7836 | } |
| 7837 | |
| 7838 | device_set_wakeup_enable(&pdev->dev, tp->features & RTL_FEATURE_WOL); |
| 7839 | |
| 7840 | if (pci_dev_run_wake(pdev)) |
| 7841 | pm_runtime_put_noidle(&pdev->dev); |
| 7842 | |
| 7843 | netif_carrier_off(dev); |
| 7844 | |
| 7845 | out: |
| 7846 | return rc; |
| 7847 | |
| 7848 | err_out_msi_4: |
Devendra Naga | ad1be8d | 2012-05-31 01:51:20 +0000 | [diff] [blame] | 7849 | netif_napi_del(&tp->napi); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7850 | rtl_disable_msi(pdev, tp); |
| 7851 | iounmap(ioaddr); |
| 7852 | err_out_free_res_3: |
| 7853 | pci_release_regions(pdev); |
| 7854 | err_out_mwi_2: |
| 7855 | pci_clear_mwi(pdev); |
| 7856 | pci_disable_device(pdev); |
| 7857 | err_out_free_dev_1: |
| 7858 | free_netdev(dev); |
| 7859 | goto out; |
| 7860 | } |
| 7861 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7862 | static struct pci_driver rtl8169_pci_driver = { |
| 7863 | .name = MODULENAME, |
| 7864 | .id_table = rtl8169_pci_tbl, |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7865 | .probe = rtl_init_one, |
Bill Pemberton | baf6329 | 2012-12-03 09:23:28 -0500 | [diff] [blame] | 7866 | .remove = rtl_remove_one, |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 7867 | .shutdown = rtl_shutdown, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7868 | .driver.pm = RTL8169_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7869 | }; |
| 7870 | |
Devendra Naga | 3eeb7da | 2012-10-26 09:27:42 +0000 | [diff] [blame] | 7871 | module_pci_driver(rtl8169_pci_driver); |