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> |
| 24 | #include <linux/init.h> |
Alexey Dobriyan | a6b7a40 | 2011-06-06 10:43:46 +0000 | [diff] [blame] | 25 | #include <linux/interrupt.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/dma-mapping.h> |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 27 | #include <linux/pm_runtime.h> |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 28 | #include <linux/firmware.h> |
Stanislaw Gruszka | ba04c7c | 2011-02-22 02:00:11 +0000 | [diff] [blame] | 29 | #include <linux/pci-aspm.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 30 | #include <linux/prefetch.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | |
| 32 | #include <asm/io.h> |
| 33 | #include <asm/irq.h> |
| 34 | |
Francois Romieu | 865c652 | 2008-05-11 14:51:00 +0200 | [diff] [blame] | 35 | #define RTL8169_VERSION "2.3LK-NAPI" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | #define MODULENAME "r8169" |
| 37 | #define PFX MODULENAME ": " |
| 38 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 39 | #define FIRMWARE_8168D_1 "rtl_nic/rtl8168d-1.fw" |
| 40 | #define FIRMWARE_8168D_2 "rtl_nic/rtl8168d-2.fw" |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 41 | #define FIRMWARE_8168E_1 "rtl_nic/rtl8168e-1.fw" |
| 42 | #define FIRMWARE_8168E_2 "rtl_nic/rtl8168e-2.fw" |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 43 | #define FIRMWARE_8168E_3 "rtl_nic/rtl8168e-3.fw" |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 44 | #define FIRMWARE_8168F_1 "rtl_nic/rtl8168f-1.fw" |
| 45 | #define FIRMWARE_8168F_2 "rtl_nic/rtl8168f-2.fw" |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 46 | #define FIRMWARE_8105E_1 "rtl_nic/rtl8105e-1.fw" |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 47 | #define FIRMWARE_8402_1 "rtl_nic/rtl8402-1.fw" |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 48 | #define FIRMWARE_8411_1 "rtl_nic/rtl8411-1.fw" |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 49 | #define FIRMWARE_8106E_1 "rtl_nic/rtl8106e-1.fw" |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 50 | #define FIRMWARE_8168G_1 "rtl_nic/rtl8168g-1.fw" |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 51 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #ifdef RTL8169_DEBUG |
| 53 | #define assert(expr) \ |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 54 | if (!(expr)) { \ |
| 55 | printk( "Assertion failed! %s,%s,%s,line=%d\n", \ |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 56 | #expr,__FILE__,__func__,__LINE__); \ |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 57 | } |
Joe Perches | 06fa735 | 2007-10-18 21:15:00 +0200 | [diff] [blame] | 58 | #define dprintk(fmt, args...) \ |
| 59 | do { printk(KERN_DEBUG PFX fmt, ## args); } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #else |
| 61 | #define assert(expr) do {} while (0) |
| 62 | #define dprintk(fmt, args...) do {} while (0) |
| 63 | #endif /* RTL8169_DEBUG */ |
| 64 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 65 | #define R8169_MSG_DEFAULT \ |
Francois Romieu | f0e837d9 | 2005-09-30 16:54:02 -0700 | [diff] [blame] | 66 | (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN) |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 67 | |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 68 | #define TX_SLOTS_AVAIL(tp) \ |
| 69 | (tp->dirty_tx + NUM_TX_DESC - tp->cur_tx) |
| 70 | |
| 71 | /* A skbuff with nr_frags needs nr_frags+1 entries in the tx queue */ |
| 72 | #define TX_FRAGS_READY_FOR(tp,nr_frags) \ |
| 73 | (TX_SLOTS_AVAIL(tp) >= (nr_frags + 1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). |
| 76 | 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] | 77 | static const int multicast_filter_limit = 32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
Francois Romieu | 9c14cea | 2008-07-05 00:21:15 +0200 | [diff] [blame] | 79 | #define MAX_READ_REQUEST_SHIFT 12 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | #define TX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | #define SafeMtu 0x1c20 /* ... actually life sucks beyond ~7k */ |
| 82 | #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */ |
| 83 | |
| 84 | #define R8169_REGS_SIZE 256 |
| 85 | #define R8169_NAPI_WEIGHT 64 |
| 86 | #define NUM_TX_DESC 64 /* Number of Tx descriptor registers */ |
| 87 | #define NUM_RX_DESC 256 /* Number of Rx descriptor registers */ |
| 88 | #define RX_BUF_SIZE 1536 /* Rx Buffer size */ |
| 89 | #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc)) |
| 90 | #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc)) |
| 91 | |
| 92 | #define RTL8169_TX_TIMEOUT (6*HZ) |
| 93 | #define RTL8169_PHY_TIMEOUT (10*HZ) |
| 94 | |
françois romieu | ea8dbdd | 2009-03-15 01:10:50 +0000 | [diff] [blame] | 95 | #define RTL_EEPROM_SIG cpu_to_le32(0x8129) |
| 96 | #define RTL_EEPROM_SIG_MASK cpu_to_le32(0xffff) |
Francois Romieu | e1564ec | 2008-10-16 22:46:13 +0200 | [diff] [blame] | 97 | #define RTL_EEPROM_SIG_ADDR 0x0000 |
| 98 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | /* write/read MMIO register */ |
| 100 | #define RTL_W8(reg, val8) writeb ((val8), ioaddr + (reg)) |
| 101 | #define RTL_W16(reg, val16) writew ((val16), ioaddr + (reg)) |
| 102 | #define RTL_W32(reg, val32) writel ((val32), ioaddr + (reg)) |
| 103 | #define RTL_R8(reg) readb (ioaddr + (reg)) |
| 104 | #define RTL_R16(reg) readw (ioaddr + (reg)) |
Junchang Wang | 06f555f | 2010-05-30 02:26:07 +0000 | [diff] [blame] | 105 | #define RTL_R32(reg) readl (ioaddr + (reg)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | enum mac_version { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 108 | RTL_GIGA_MAC_VER_01 = 0, |
| 109 | RTL_GIGA_MAC_VER_02, |
| 110 | RTL_GIGA_MAC_VER_03, |
| 111 | RTL_GIGA_MAC_VER_04, |
| 112 | RTL_GIGA_MAC_VER_05, |
| 113 | RTL_GIGA_MAC_VER_06, |
| 114 | RTL_GIGA_MAC_VER_07, |
| 115 | RTL_GIGA_MAC_VER_08, |
| 116 | RTL_GIGA_MAC_VER_09, |
| 117 | RTL_GIGA_MAC_VER_10, |
| 118 | RTL_GIGA_MAC_VER_11, |
| 119 | RTL_GIGA_MAC_VER_12, |
| 120 | RTL_GIGA_MAC_VER_13, |
| 121 | RTL_GIGA_MAC_VER_14, |
| 122 | RTL_GIGA_MAC_VER_15, |
| 123 | RTL_GIGA_MAC_VER_16, |
| 124 | RTL_GIGA_MAC_VER_17, |
| 125 | RTL_GIGA_MAC_VER_18, |
| 126 | RTL_GIGA_MAC_VER_19, |
| 127 | RTL_GIGA_MAC_VER_20, |
| 128 | RTL_GIGA_MAC_VER_21, |
| 129 | RTL_GIGA_MAC_VER_22, |
| 130 | RTL_GIGA_MAC_VER_23, |
| 131 | RTL_GIGA_MAC_VER_24, |
| 132 | RTL_GIGA_MAC_VER_25, |
| 133 | RTL_GIGA_MAC_VER_26, |
| 134 | RTL_GIGA_MAC_VER_27, |
| 135 | RTL_GIGA_MAC_VER_28, |
| 136 | RTL_GIGA_MAC_VER_29, |
| 137 | RTL_GIGA_MAC_VER_30, |
| 138 | RTL_GIGA_MAC_VER_31, |
| 139 | RTL_GIGA_MAC_VER_32, |
| 140 | RTL_GIGA_MAC_VER_33, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 141 | RTL_GIGA_MAC_VER_34, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 142 | RTL_GIGA_MAC_VER_35, |
| 143 | RTL_GIGA_MAC_VER_36, |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 144 | RTL_GIGA_MAC_VER_37, |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 145 | RTL_GIGA_MAC_VER_38, |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 146 | RTL_GIGA_MAC_VER_39, |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 147 | RTL_GIGA_MAC_VER_40, |
| 148 | RTL_GIGA_MAC_VER_41, |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 149 | RTL_GIGA_MAC_NONE = 0xff, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | }; |
| 151 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 152 | enum rtl_tx_desc_version { |
| 153 | RTL_TD_0 = 0, |
| 154 | RTL_TD_1 = 1, |
| 155 | }; |
| 156 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 157 | #define JUMBO_1K ETH_DATA_LEN |
| 158 | #define JUMBO_4K (4*1024 - ETH_HLEN - 2) |
| 159 | #define JUMBO_6K (6*1024 - ETH_HLEN - 2) |
| 160 | #define JUMBO_7K (7*1024 - ETH_HLEN - 2) |
| 161 | #define JUMBO_9K (9*1024 - ETH_HLEN - 2) |
| 162 | |
| 163 | #define _R(NAME,TD,FW,SZ,B) { \ |
| 164 | .name = NAME, \ |
| 165 | .txd_version = TD, \ |
| 166 | .fw_name = FW, \ |
| 167 | .jumbo_max = SZ, \ |
| 168 | .jumbo_tx_csum = B \ |
| 169 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | |
Jesper Juhl | 3c6bee1 | 2006-01-09 20:54:01 -0800 | [diff] [blame] | 171 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | const char *name; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 173 | enum rtl_tx_desc_version txd_version; |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 174 | const char *fw_name; |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 175 | u16 jumbo_max; |
| 176 | bool jumbo_tx_csum; |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 177 | } rtl_chip_infos[] = { |
| 178 | /* PCI devices. */ |
| 179 | [RTL_GIGA_MAC_VER_01] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 180 | _R("RTL8169", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 181 | [RTL_GIGA_MAC_VER_02] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 182 | _R("RTL8169s", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 183 | [RTL_GIGA_MAC_VER_03] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 184 | _R("RTL8110s", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 185 | [RTL_GIGA_MAC_VER_04] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 186 | _R("RTL8169sb/8110sb", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 187 | [RTL_GIGA_MAC_VER_05] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 188 | _R("RTL8169sc/8110sc", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 189 | [RTL_GIGA_MAC_VER_06] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 190 | _R("RTL8169sc/8110sc", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 191 | /* PCI-E devices. */ |
| 192 | [RTL_GIGA_MAC_VER_07] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 193 | _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 194 | [RTL_GIGA_MAC_VER_08] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 195 | _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 196 | [RTL_GIGA_MAC_VER_09] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 197 | _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 198 | [RTL_GIGA_MAC_VER_10] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 199 | _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 200 | [RTL_GIGA_MAC_VER_11] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 201 | _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 202 | [RTL_GIGA_MAC_VER_12] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 203 | _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 204 | [RTL_GIGA_MAC_VER_13] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 205 | _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 206 | [RTL_GIGA_MAC_VER_14] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 207 | _R("RTL8100e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 208 | [RTL_GIGA_MAC_VER_15] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 209 | _R("RTL8100e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 210 | [RTL_GIGA_MAC_VER_16] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 211 | _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 212 | [RTL_GIGA_MAC_VER_17] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 213 | _R("RTL8168b/8111b", RTL_TD_1, NULL, JUMBO_4K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 214 | [RTL_GIGA_MAC_VER_18] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 215 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 216 | [RTL_GIGA_MAC_VER_19] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 217 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 218 | [RTL_GIGA_MAC_VER_20] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 219 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 220 | [RTL_GIGA_MAC_VER_21] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 221 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 222 | [RTL_GIGA_MAC_VER_22] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 223 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 224 | [RTL_GIGA_MAC_VER_23] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 225 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 226 | [RTL_GIGA_MAC_VER_24] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 227 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 228 | [RTL_GIGA_MAC_VER_25] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 229 | _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_1, |
| 230 | JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 231 | [RTL_GIGA_MAC_VER_26] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 232 | _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_2, |
| 233 | JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 234 | [RTL_GIGA_MAC_VER_27] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 235 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 236 | [RTL_GIGA_MAC_VER_28] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 237 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 238 | [RTL_GIGA_MAC_VER_29] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 239 | _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1, |
| 240 | JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 241 | [RTL_GIGA_MAC_VER_30] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 242 | _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1, |
| 243 | JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 244 | [RTL_GIGA_MAC_VER_31] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 245 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 246 | [RTL_GIGA_MAC_VER_32] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 247 | _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_1, |
| 248 | JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 249 | [RTL_GIGA_MAC_VER_33] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 250 | _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_2, |
| 251 | JUMBO_9K, false), |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 252 | [RTL_GIGA_MAC_VER_34] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 253 | _R("RTL8168evl/8111evl",RTL_TD_1, FIRMWARE_8168E_3, |
| 254 | JUMBO_9K, false), |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 255 | [RTL_GIGA_MAC_VER_35] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 256 | _R("RTL8168f/8111f", RTL_TD_1, FIRMWARE_8168F_1, |
| 257 | JUMBO_9K, false), |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 258 | [RTL_GIGA_MAC_VER_36] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 259 | _R("RTL8168f/8111f", RTL_TD_1, FIRMWARE_8168F_2, |
| 260 | JUMBO_9K, false), |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 261 | [RTL_GIGA_MAC_VER_37] = |
| 262 | _R("RTL8402", RTL_TD_1, FIRMWARE_8402_1, |
| 263 | JUMBO_1K, true), |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 264 | [RTL_GIGA_MAC_VER_38] = |
| 265 | _R("RTL8411", RTL_TD_1, FIRMWARE_8411_1, |
| 266 | JUMBO_9K, false), |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 267 | [RTL_GIGA_MAC_VER_39] = |
| 268 | _R("RTL8106e", RTL_TD_1, FIRMWARE_8106E_1, |
| 269 | JUMBO_1K, true), |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 270 | [RTL_GIGA_MAC_VER_40] = |
| 271 | _R("RTL8168g/8111g", RTL_TD_1, FIRMWARE_8168G_1, |
| 272 | JUMBO_9K, false), |
| 273 | [RTL_GIGA_MAC_VER_41] = |
| 274 | _R("RTL8168g/8111g", RTL_TD_1, NULL, JUMBO_9K, false), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | }; |
| 276 | #undef _R |
| 277 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 278 | enum cfg_version { |
| 279 | RTL_CFG_0 = 0x00, |
| 280 | RTL_CFG_1, |
| 281 | RTL_CFG_2 |
| 282 | }; |
| 283 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 284 | static DEFINE_PCI_DEVICE_TABLE(rtl8169_pci_tbl) = { |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 285 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 }, |
Francois Romieu | d2eed8c | 2006-08-31 22:01:07 +0200 | [diff] [blame] | 286 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8136), 0, 0, RTL_CFG_2 }, |
Francois Romieu | d81bf55 | 2006-09-20 21:31:20 +0200 | [diff] [blame] | 287 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_0 }, |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 288 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_1 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 289 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 }, |
Francois Romieu | 2a35cfa | 2012-08-31 23:06:17 +0200 | [diff] [blame^] | 290 | { PCI_VENDOR_ID_DLINK, 0x4300, |
| 291 | PCI_VENDOR_ID_DLINK, 0x4b10, 0, 0, RTL_CFG_1 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 292 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4300), 0, 0, RTL_CFG_0 }, |
Lennart Sorensen | 93a3aa2 | 2011-07-28 13:18:11 +0000 | [diff] [blame] | 293 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4302), 0, 0, RTL_CFG_0 }, |
Francois Romieu | bc1660b | 2007-10-12 23:58:09 +0200 | [diff] [blame] | 294 | { PCI_DEVICE(PCI_VENDOR_ID_AT, 0xc107), 0, 0, RTL_CFG_0 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 295 | { PCI_DEVICE(0x16ec, 0x0116), 0, 0, RTL_CFG_0 }, |
| 296 | { PCI_VENDOR_ID_LINKSYS, 0x1032, |
| 297 | PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 }, |
Ciaran McCreesh | 11d2e28 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 298 | { 0x0001, 0x8168, |
| 299 | PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | {0,}, |
| 301 | }; |
| 302 | |
| 303 | MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl); |
| 304 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 305 | static int rx_buf_sz = 16383; |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 306 | static int use_dac; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 307 | static struct { |
| 308 | u32 msg_enable; |
| 309 | } debug = { -1 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 311 | enum rtl_registers { |
| 312 | MAC0 = 0, /* Ethernet hardware address. */ |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 313 | MAC4 = 4, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 314 | MAR0 = 8, /* Multicast filter. */ |
| 315 | CounterAddrLow = 0x10, |
| 316 | CounterAddrHigh = 0x14, |
| 317 | TxDescStartAddrLow = 0x20, |
| 318 | TxDescStartAddrHigh = 0x24, |
| 319 | TxHDescStartAddrLow = 0x28, |
| 320 | TxHDescStartAddrHigh = 0x2c, |
| 321 | FLASH = 0x30, |
| 322 | ERSR = 0x36, |
| 323 | ChipCmd = 0x37, |
| 324 | TxPoll = 0x38, |
| 325 | IntrMask = 0x3c, |
| 326 | IntrStatus = 0x3e, |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 327 | |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 328 | TxConfig = 0x40, |
| 329 | #define TXCFG_AUTO_FIFO (1 << 7) /* 8111e-vl */ |
| 330 | #define TXCFG_EMPTY (1 << 11) /* 8111e-vl */ |
| 331 | |
| 332 | RxConfig = 0x44, |
| 333 | #define RX128_INT_EN (1 << 15) /* 8111c and later */ |
| 334 | #define RX_MULTI_EN (1 << 14) /* 8111c only */ |
| 335 | #define RXCFG_FIFO_SHIFT 13 |
| 336 | /* No threshold before first PCI xfer */ |
| 337 | #define RX_FIFO_THRESH (7 << RXCFG_FIFO_SHIFT) |
| 338 | #define RXCFG_DMA_SHIFT 8 |
| 339 | /* Unlimited maximum PCI burst. */ |
| 340 | #define RX_DMA_BURST (7 << RXCFG_DMA_SHIFT) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 341 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 342 | RxMissed = 0x4c, |
| 343 | Cfg9346 = 0x50, |
| 344 | Config0 = 0x51, |
| 345 | Config1 = 0x52, |
| 346 | Config2 = 0x53, |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 347 | #define PME_SIGNAL (1 << 5) /* 8168c and later */ |
| 348 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 349 | Config3 = 0x54, |
| 350 | Config4 = 0x55, |
| 351 | Config5 = 0x56, |
| 352 | MultiIntr = 0x5c, |
| 353 | PHYAR = 0x60, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 354 | PHYstatus = 0x6c, |
| 355 | RxMaxSize = 0xda, |
| 356 | CPlusCmd = 0xe0, |
| 357 | IntrMitigate = 0xe2, |
| 358 | RxDescAddrLow = 0xe4, |
| 359 | RxDescAddrHigh = 0xe8, |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 360 | EarlyTxThres = 0xec, /* 8169. Unit of 32 bytes. */ |
| 361 | |
| 362 | #define NoEarlyTx 0x3f /* Max value : no early transmit. */ |
| 363 | |
| 364 | MaxTxPacketSize = 0xec, /* 8101/8168. Unit of 128 bytes. */ |
| 365 | |
| 366 | #define TxPacketMax (8064 >> 7) |
Hayes Wang | 3090bd9 | 2011-09-06 16:55:15 +0800 | [diff] [blame] | 367 | #define EarlySize 0x27 |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 368 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 369 | FuncEvent = 0xf0, |
| 370 | FuncEventMask = 0xf4, |
| 371 | FuncPresetState = 0xf8, |
| 372 | FuncForceEvent = 0xfc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | }; |
| 374 | |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 375 | enum rtl8110_registers { |
| 376 | TBICSR = 0x64, |
| 377 | TBI_ANAR = 0x68, |
| 378 | TBI_LPAR = 0x6a, |
| 379 | }; |
| 380 | |
| 381 | enum rtl8168_8101_registers { |
| 382 | CSIDR = 0x64, |
| 383 | CSIAR = 0x68, |
| 384 | #define CSIAR_FLAG 0x80000000 |
| 385 | #define CSIAR_WRITE_CMD 0x80000000 |
| 386 | #define CSIAR_BYTE_ENABLE 0x0f |
| 387 | #define CSIAR_BYTE_ENABLE_SHIFT 12 |
| 388 | #define CSIAR_ADDR_MASK 0x0fff |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 389 | #define CSIAR_FUNC_CARD 0x00000000 |
| 390 | #define CSIAR_FUNC_SDIO 0x00010000 |
| 391 | #define CSIAR_FUNC_NIC 0x00020000 |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 392 | PMCH = 0x6f, |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 393 | EPHYAR = 0x80, |
| 394 | #define EPHYAR_FLAG 0x80000000 |
| 395 | #define EPHYAR_WRITE_CMD 0x80000000 |
| 396 | #define EPHYAR_REG_MASK 0x1f |
| 397 | #define EPHYAR_REG_SHIFT 16 |
| 398 | #define EPHYAR_DATA_MASK 0xffff |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 399 | DLLPR = 0xd0, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 400 | #define PFM_EN (1 << 6) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 401 | DBG_REG = 0xd1, |
| 402 | #define FIX_NAK_1 (1 << 4) |
| 403 | #define FIX_NAK_2 (1 << 3) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 404 | TWSI = 0xd2, |
| 405 | MCU = 0xd3, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 406 | #define NOW_IS_OOB (1 << 7) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 407 | #define TX_EMPTY (1 << 5) |
| 408 | #define RX_EMPTY (1 << 4) |
| 409 | #define RXTX_EMPTY (TX_EMPTY | RX_EMPTY) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 410 | #define EN_NDP (1 << 3) |
| 411 | #define EN_OOB_RESET (1 << 2) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 412 | #define LINK_LIST_RDY (1 << 1) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 413 | EFUSEAR = 0xdc, |
| 414 | #define EFUSEAR_FLAG 0x80000000 |
| 415 | #define EFUSEAR_WRITE_CMD 0x80000000 |
| 416 | #define EFUSEAR_READ_CMD 0x00000000 |
| 417 | #define EFUSEAR_REG_MASK 0x03ff |
| 418 | #define EFUSEAR_REG_SHIFT 8 |
| 419 | #define EFUSEAR_DATA_MASK 0xff |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 420 | }; |
| 421 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 422 | enum rtl8168_registers { |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 423 | LED_FREQ = 0x1a, |
| 424 | EEE_LED = 0x1b, |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 425 | ERIDR = 0x70, |
| 426 | ERIAR = 0x74, |
| 427 | #define ERIAR_FLAG 0x80000000 |
| 428 | #define ERIAR_WRITE_CMD 0x80000000 |
| 429 | #define ERIAR_READ_CMD 0x00000000 |
| 430 | #define ERIAR_ADDR_BYTE_ALIGN 4 |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 431 | #define ERIAR_TYPE_SHIFT 16 |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 432 | #define ERIAR_EXGMAC (0x00 << ERIAR_TYPE_SHIFT) |
| 433 | #define ERIAR_MSIX (0x01 << ERIAR_TYPE_SHIFT) |
| 434 | #define ERIAR_ASF (0x02 << ERIAR_TYPE_SHIFT) |
| 435 | #define ERIAR_MASK_SHIFT 12 |
| 436 | #define ERIAR_MASK_0001 (0x1 << ERIAR_MASK_SHIFT) |
| 437 | #define ERIAR_MASK_0011 (0x3 << ERIAR_MASK_SHIFT) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 438 | #define ERIAR_MASK_0101 (0x5 << ERIAR_MASK_SHIFT) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 439 | #define ERIAR_MASK_1111 (0xf << ERIAR_MASK_SHIFT) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 440 | EPHY_RXER_NUM = 0x7c, |
| 441 | OCPDR = 0xb0, /* OCP GPHY access */ |
| 442 | #define OCPDR_WRITE_CMD 0x80000000 |
| 443 | #define OCPDR_READ_CMD 0x00000000 |
| 444 | #define OCPDR_REG_MASK 0x7f |
| 445 | #define OCPDR_GPHY_REG_SHIFT 16 |
| 446 | #define OCPDR_DATA_MASK 0xffff |
| 447 | OCPAR = 0xb4, |
| 448 | #define OCPAR_FLAG 0x80000000 |
| 449 | #define OCPAR_GPHY_WRITE_CMD 0x8000f060 |
| 450 | #define OCPAR_GPHY_READ_CMD 0x0000f060 |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 451 | GPHY_OCP = 0xb8, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 452 | RDSAR1 = 0xd0, /* 8168c only. Undocumented on 8168dp */ |
| 453 | MISC = 0xf0, /* 8168e only. */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 454 | #define TXPLA_RST (1 << 29) |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 455 | #define DISABLE_LAN_EN (1 << 23) /* Enable GPIO pin */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 456 | #define PWM_EN (1 << 22) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 457 | #define RXDV_GATED_EN (1 << 19) |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 458 | #define EARLY_TALLY_EN (1 << 16) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 459 | }; |
| 460 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 461 | enum rtl_register_content { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | /* InterruptStatusBits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 463 | SYSErr = 0x8000, |
| 464 | PCSTimeout = 0x4000, |
| 465 | SWInt = 0x0100, |
| 466 | TxDescUnavail = 0x0080, |
| 467 | RxFIFOOver = 0x0040, |
| 468 | LinkChg = 0x0020, |
| 469 | RxOverflow = 0x0010, |
| 470 | TxErr = 0x0008, |
| 471 | TxOK = 0x0004, |
| 472 | RxErr = 0x0002, |
| 473 | RxOK = 0x0001, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | |
| 475 | /* RxStatusDesc */ |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 476 | RxBOVF = (1 << 24), |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 477 | RxFOVF = (1 << 23), |
| 478 | RxRWT = (1 << 22), |
| 479 | RxRES = (1 << 21), |
| 480 | RxRUNT = (1 << 20), |
| 481 | RxCRC = (1 << 19), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | |
| 483 | /* ChipCmdBits */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 484 | StopReq = 0x80, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 485 | CmdReset = 0x10, |
| 486 | CmdRxEnb = 0x08, |
| 487 | CmdTxEnb = 0x04, |
| 488 | RxBufEmpty = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
Francois Romieu | 275391a | 2007-02-23 23:50:28 +0100 | [diff] [blame] | 490 | /* TXPoll register p.5 */ |
| 491 | HPQ = 0x80, /* Poll cmd on the high prio queue */ |
| 492 | NPQ = 0x40, /* Poll cmd on the low prio queue */ |
| 493 | FSWInt = 0x01, /* Forced software interrupt */ |
| 494 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 495 | /* Cfg9346Bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 496 | Cfg9346_Lock = 0x00, |
| 497 | Cfg9346_Unlock = 0xc0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 498 | |
| 499 | /* rx_mode_bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 500 | AcceptErr = 0x20, |
| 501 | AcceptRunt = 0x10, |
| 502 | AcceptBroadcast = 0x08, |
| 503 | AcceptMulticast = 0x04, |
| 504 | AcceptMyPhys = 0x02, |
| 505 | AcceptAllPhys = 0x01, |
Francois Romieu | 1687b56 | 2011-07-19 17:21:29 +0200 | [diff] [blame] | 506 | #define RX_CONFIG_ACCEPT_MASK 0x3f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | /* TxConfigBits */ |
| 509 | TxInterFrameGapShift = 24, |
| 510 | TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */ |
| 511 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 512 | /* Config1 register p.24 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 513 | LEDS1 = (1 << 7), |
| 514 | LEDS0 = (1 << 6), |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 515 | Speed_down = (1 << 4), |
| 516 | MEMMAP = (1 << 3), |
| 517 | IOMAP = (1 << 2), |
| 518 | VPD = (1 << 1), |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 519 | PMEnable = (1 << 0), /* Power Management Enable */ |
| 520 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 521 | /* Config2 register p. 25 */ |
françois romieu | 2ca6cf0 | 2011-12-15 08:37:43 +0000 | [diff] [blame] | 522 | MSIEnable = (1 << 5), /* 8169 only. Reserved in the 8168. */ |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 523 | PCI_Clock_66MHz = 0x01, |
| 524 | PCI_Clock_33MHz = 0x00, |
| 525 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 526 | /* Config3 register p.25 */ |
| 527 | MagicPacket = (1 << 5), /* Wake up when receives a Magic Packet */ |
| 528 | LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */ |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 529 | Jumbo_En0 = (1 << 2), /* 8168 only. Reserved in the 8168b */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 530 | Beacon_en = (1 << 0), /* 8168 only. Reserved in the 8168b */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 531 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 532 | /* Config4 register */ |
| 533 | Jumbo_En1 = (1 << 1), /* 8168 only. Reserved in the 8168b */ |
| 534 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 535 | /* Config5 register p.27 */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 536 | BWF = (1 << 6), /* Accept Broadcast wakeup frame */ |
| 537 | MWF = (1 << 5), /* Accept Multicast wakeup frame */ |
| 538 | UWF = (1 << 4), /* Accept Unicast wakeup frame */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 539 | Spi_en = (1 << 3), |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 540 | LanWake = (1 << 1), /* LanWake enable/disable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 541 | PMEStatus = (1 << 0), /* PME status can be reset by PCI RST# */ |
| 542 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | /* TBICSR p.28 */ |
| 544 | TBIReset = 0x80000000, |
| 545 | TBILoopback = 0x40000000, |
| 546 | TBINwEnable = 0x20000000, |
| 547 | TBINwRestart = 0x10000000, |
| 548 | TBILinkOk = 0x02000000, |
| 549 | TBINwComplete = 0x01000000, |
| 550 | |
| 551 | /* CPlusCmd p.31 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 552 | EnableBist = (1 << 15), // 8168 8101 |
| 553 | Mac_dbgo_oe = (1 << 14), // 8168 8101 |
| 554 | Normal_mode = (1 << 13), // unused |
| 555 | Force_half_dup = (1 << 12), // 8168 8101 |
| 556 | Force_rxflow_en = (1 << 11), // 8168 8101 |
| 557 | Force_txflow_en = (1 << 10), // 8168 8101 |
| 558 | Cxpl_dbg_sel = (1 << 9), // 8168 8101 |
| 559 | ASF = (1 << 8), // 8168 8101 |
| 560 | PktCntrDisable = (1 << 7), // 8168 8101 |
| 561 | Mac_dbgo_sel = 0x001c, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | RxVlan = (1 << 6), |
| 563 | RxChkSum = (1 << 5), |
| 564 | PCIDAC = (1 << 4), |
| 565 | PCIMulRW = (1 << 3), |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 566 | INTT_0 = 0x0000, // 8168 |
| 567 | INTT_1 = 0x0001, // 8168 |
| 568 | INTT_2 = 0x0002, // 8168 |
| 569 | INTT_3 = 0x0003, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | |
| 571 | /* rtl8169_PHYstatus */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 572 | TBI_Enable = 0x80, |
| 573 | TxFlowCtrl = 0x40, |
| 574 | RxFlowCtrl = 0x20, |
| 575 | _1000bpsF = 0x10, |
| 576 | _100bps = 0x08, |
| 577 | _10bps = 0x04, |
| 578 | LinkStatus = 0x02, |
| 579 | FullDup = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | /* _TBICSRBit */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 582 | TBILinkOK = 0x02000000, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 583 | |
| 584 | /* DumpCounterCommand */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 585 | CounterDump = 0x8, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | }; |
| 587 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 588 | enum rtl_desc_bit { |
| 589 | /* First doubleword. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | DescOwn = (1 << 31), /* Descriptor is owned by NIC */ |
| 591 | RingEnd = (1 << 30), /* End of descriptor ring */ |
| 592 | FirstFrag = (1 << 29), /* First segment of a packet */ |
| 593 | LastFrag = (1 << 28), /* Final segment of a packet */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 594 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 596 | /* Generic case. */ |
| 597 | enum rtl_tx_desc_bit { |
| 598 | /* First doubleword. */ |
| 599 | TD_LSO = (1 << 27), /* Large Send Offload */ |
| 600 | #define TD_MSS_MAX 0x07ffu /* MSS value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 602 | /* Second doubleword. */ |
| 603 | TxVlanTag = (1 << 17), /* Add VLAN tag */ |
| 604 | }; |
| 605 | |
| 606 | /* 8169, 8168b and 810x except 8102e. */ |
| 607 | enum rtl_tx_desc_bit_0 { |
| 608 | /* First doubleword. */ |
| 609 | #define TD0_MSS_SHIFT 16 /* MSS position (11 bits) */ |
| 610 | TD0_TCP_CS = (1 << 16), /* Calculate TCP/IP checksum */ |
| 611 | TD0_UDP_CS = (1 << 17), /* Calculate UDP/IP checksum */ |
| 612 | TD0_IP_CS = (1 << 18), /* Calculate IP checksum */ |
| 613 | }; |
| 614 | |
| 615 | /* 8102e, 8168c and beyond. */ |
| 616 | enum rtl_tx_desc_bit_1 { |
| 617 | /* Second doubleword. */ |
| 618 | #define TD1_MSS_SHIFT 18 /* MSS position (11 bits) */ |
| 619 | TD1_IP_CS = (1 << 29), /* Calculate IP checksum */ |
| 620 | TD1_TCP_CS = (1 << 30), /* Calculate TCP/IP checksum */ |
| 621 | TD1_UDP_CS = (1 << 31), /* Calculate UDP/IP checksum */ |
| 622 | }; |
| 623 | |
| 624 | static const struct rtl_tx_desc_info { |
| 625 | struct { |
| 626 | u32 udp; |
| 627 | u32 tcp; |
| 628 | } checksum; |
| 629 | u16 mss_shift; |
| 630 | u16 opts_offset; |
| 631 | } tx_desc_info [] = { |
| 632 | [RTL_TD_0] = { |
| 633 | .checksum = { |
| 634 | .udp = TD0_IP_CS | TD0_UDP_CS, |
| 635 | .tcp = TD0_IP_CS | TD0_TCP_CS |
| 636 | }, |
| 637 | .mss_shift = TD0_MSS_SHIFT, |
| 638 | .opts_offset = 0 |
| 639 | }, |
| 640 | [RTL_TD_1] = { |
| 641 | .checksum = { |
| 642 | .udp = TD1_IP_CS | TD1_UDP_CS, |
| 643 | .tcp = TD1_IP_CS | TD1_TCP_CS |
| 644 | }, |
| 645 | .mss_shift = TD1_MSS_SHIFT, |
| 646 | .opts_offset = 1 |
| 647 | } |
| 648 | }; |
| 649 | |
| 650 | enum rtl_rx_desc_bit { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | /* Rx private */ |
| 652 | PID1 = (1 << 18), /* Protocol ID bit 1/2 */ |
| 653 | PID0 = (1 << 17), /* Protocol ID bit 2/2 */ |
| 654 | |
| 655 | #define RxProtoUDP (PID1) |
| 656 | #define RxProtoTCP (PID0) |
| 657 | #define RxProtoIP (PID1 | PID0) |
| 658 | #define RxProtoMask RxProtoIP |
| 659 | |
| 660 | IPFail = (1 << 16), /* IP checksum failed */ |
| 661 | UDPFail = (1 << 15), /* UDP/IP checksum failed */ |
| 662 | TCPFail = (1 << 14), /* TCP/IP checksum failed */ |
| 663 | RxVlanTag = (1 << 16), /* VLAN tag available */ |
| 664 | }; |
| 665 | |
| 666 | #define RsvdMask 0x3fffc000 |
| 667 | |
| 668 | struct TxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 669 | __le32 opts1; |
| 670 | __le32 opts2; |
| 671 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | }; |
| 673 | |
| 674 | struct RxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 675 | __le32 opts1; |
| 676 | __le32 opts2; |
| 677 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | }; |
| 679 | |
| 680 | struct ring_info { |
| 681 | struct sk_buff *skb; |
| 682 | u32 len; |
| 683 | u8 __pad[sizeof(void *) - sizeof(u32)]; |
| 684 | }; |
| 685 | |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 686 | enum features { |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 687 | RTL_FEATURE_WOL = (1 << 0), |
| 688 | RTL_FEATURE_MSI = (1 << 1), |
| 689 | RTL_FEATURE_GMII = (1 << 2), |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 690 | }; |
| 691 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 692 | struct rtl8169_counters { |
| 693 | __le64 tx_packets; |
| 694 | __le64 rx_packets; |
| 695 | __le64 tx_errors; |
| 696 | __le32 rx_errors; |
| 697 | __le16 rx_missed; |
| 698 | __le16 align_errors; |
| 699 | __le32 tx_one_collision; |
| 700 | __le32 tx_multi_collision; |
| 701 | __le64 rx_unicast; |
| 702 | __le64 rx_broadcast; |
| 703 | __le32 rx_multicast; |
| 704 | __le16 tx_aborted; |
| 705 | __le16 tx_underun; |
| 706 | }; |
| 707 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 708 | enum rtl_flag { |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 709 | RTL_FLAG_TASK_ENABLED, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 710 | RTL_FLAG_TASK_SLOW_PENDING, |
| 711 | RTL_FLAG_TASK_RESET_PENDING, |
| 712 | RTL_FLAG_TASK_PHY_PENDING, |
| 713 | RTL_FLAG_MAX |
| 714 | }; |
| 715 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 716 | struct rtl8169_stats { |
| 717 | u64 packets; |
| 718 | u64 bytes; |
| 719 | struct u64_stats_sync syncp; |
| 720 | }; |
| 721 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | struct rtl8169_private { |
| 723 | void __iomem *mmio_addr; /* memory map physical address */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 724 | struct pci_dev *pci_dev; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 725 | struct net_device *dev; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 726 | struct napi_struct napi; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 727 | u32 msg_enable; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 728 | u16 txd_version; |
| 729 | u16 mac_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 730 | u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */ |
| 731 | u32 cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */ |
| 732 | u32 dirty_rx; |
| 733 | u32 dirty_tx; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 734 | struct rtl8169_stats rx_stats; |
| 735 | struct rtl8169_stats tx_stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 736 | struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */ |
| 737 | struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */ |
| 738 | dma_addr_t TxPhyAddr; |
| 739 | dma_addr_t RxPhyAddr; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 740 | void *Rx_databuff[NUM_RX_DESC]; /* Rx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 741 | struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 742 | struct timer_list timer; |
| 743 | u16 cp_cmd; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 744 | |
| 745 | u16 event_slow; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 746 | |
| 747 | struct mdio_ops { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 748 | void (*write)(struct rtl8169_private *, int, int); |
| 749 | int (*read)(struct rtl8169_private *, int); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 750 | } mdio_ops; |
| 751 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 752 | struct pll_power_ops { |
| 753 | void (*down)(struct rtl8169_private *); |
| 754 | void (*up)(struct rtl8169_private *); |
| 755 | } pll_power_ops; |
| 756 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 757 | struct jumbo_ops { |
| 758 | void (*enable)(struct rtl8169_private *); |
| 759 | void (*disable)(struct rtl8169_private *); |
| 760 | } jumbo_ops; |
| 761 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 762 | struct csi_ops { |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 763 | void (*write)(struct rtl8169_private *, int, int); |
| 764 | u32 (*read)(struct rtl8169_private *, int); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 765 | } csi_ops; |
| 766 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 767 | 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] | 768 | int (*get_settings)(struct net_device *, struct ethtool_cmd *); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 769 | void (*phy_reset_enable)(struct rtl8169_private *tp); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 770 | void (*hw_start)(struct net_device *); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 771 | unsigned int (*phy_reset_pending)(struct rtl8169_private *tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | unsigned int (*link_ok)(void __iomem *); |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 773 | int (*do_ioctl)(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 774 | |
| 775 | struct { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 776 | DECLARE_BITMAP(flags, RTL_FLAG_MAX); |
| 777 | struct mutex mutex; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 778 | struct work_struct work; |
| 779 | } wk; |
| 780 | |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 781 | unsigned features; |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 782 | |
| 783 | struct mii_if_info mii; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 784 | struct rtl8169_counters counters; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 785 | u32 saved_wolopts; |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 786 | u32 opts1_mask; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 787 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 788 | struct rtl_fw { |
| 789 | const struct firmware *fw; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 790 | |
| 791 | #define RTL_VER_SIZE 32 |
| 792 | |
| 793 | char version[RTL_VER_SIZE]; |
| 794 | |
| 795 | struct rtl_fw_phy_action { |
| 796 | __le32 *code; |
| 797 | size_t size; |
| 798 | } phy_action; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 799 | } *rtl_fw; |
Phil Carmody | 497888c | 2011-07-14 15:07:13 +0300 | [diff] [blame] | 800 | #define RTL_FIRMWARE_UNKNOWN ERR_PTR(-EAGAIN) |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 801 | |
| 802 | u32 ocp_base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | }; |
| 804 | |
Ralf Baechle | 979b6c1 | 2005-06-13 14:30:40 -0700 | [diff] [blame] | 805 | MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 807 | module_param(use_dac, int, 0); |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 808 | 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] | 809 | module_param_named(debug, debug.msg_enable, int, 0); |
| 810 | MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | MODULE_LICENSE("GPL"); |
| 812 | MODULE_VERSION(RTL8169_VERSION); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 813 | MODULE_FIRMWARE(FIRMWARE_8168D_1); |
| 814 | MODULE_FIRMWARE(FIRMWARE_8168D_2); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 815 | MODULE_FIRMWARE(FIRMWARE_8168E_1); |
| 816 | MODULE_FIRMWARE(FIRMWARE_8168E_2); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 817 | MODULE_FIRMWARE(FIRMWARE_8168E_3); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 818 | MODULE_FIRMWARE(FIRMWARE_8105E_1); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 819 | MODULE_FIRMWARE(FIRMWARE_8168F_1); |
| 820 | MODULE_FIRMWARE(FIRMWARE_8168F_2); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 821 | MODULE_FIRMWARE(FIRMWARE_8402_1); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 822 | MODULE_FIRMWARE(FIRMWARE_8411_1); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 823 | MODULE_FIRMWARE(FIRMWARE_8106E_1); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 824 | MODULE_FIRMWARE(FIRMWARE_8168G_1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 826 | static void rtl_lock_work(struct rtl8169_private *tp) |
| 827 | { |
| 828 | mutex_lock(&tp->wk.mutex); |
| 829 | } |
| 830 | |
| 831 | static void rtl_unlock_work(struct rtl8169_private *tp) |
| 832 | { |
| 833 | mutex_unlock(&tp->wk.mutex); |
| 834 | } |
| 835 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 836 | static void rtl_tx_performance_tweak(struct pci_dev *pdev, u16 force) |
| 837 | { |
| 838 | int cap = pci_pcie_cap(pdev); |
| 839 | |
| 840 | if (cap) { |
| 841 | u16 ctl; |
| 842 | |
| 843 | pci_read_config_word(pdev, cap + PCI_EXP_DEVCTL, &ctl); |
| 844 | ctl = (ctl & ~PCI_EXP_DEVCTL_READRQ) | force; |
| 845 | pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, ctl); |
| 846 | } |
| 847 | } |
| 848 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 849 | struct rtl_cond { |
| 850 | bool (*check)(struct rtl8169_private *); |
| 851 | const char *msg; |
| 852 | }; |
| 853 | |
| 854 | static void rtl_udelay(unsigned int d) |
| 855 | { |
| 856 | udelay(d); |
| 857 | } |
| 858 | |
| 859 | static bool rtl_loop_wait(struct rtl8169_private *tp, const struct rtl_cond *c, |
| 860 | void (*delay)(unsigned int), unsigned int d, int n, |
| 861 | bool high) |
| 862 | { |
| 863 | int i; |
| 864 | |
| 865 | for (i = 0; i < n; i++) { |
| 866 | delay(d); |
| 867 | if (c->check(tp) == high) |
| 868 | return true; |
| 869 | } |
Francois Romieu | 82e316e | 2012-07-11 23:39:51 +0200 | [diff] [blame] | 870 | netif_err(tp, drv, tp->dev, "%s == %d (loop: %d, delay: %d).\n", |
| 871 | c->msg, !high, n, d); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 872 | return false; |
| 873 | } |
| 874 | |
| 875 | static bool rtl_udelay_loop_wait_high(struct rtl8169_private *tp, |
| 876 | const struct rtl_cond *c, |
| 877 | unsigned int d, int n) |
| 878 | { |
| 879 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, true); |
| 880 | } |
| 881 | |
| 882 | static bool rtl_udelay_loop_wait_low(struct rtl8169_private *tp, |
| 883 | const struct rtl_cond *c, |
| 884 | unsigned int d, int n) |
| 885 | { |
| 886 | return rtl_loop_wait(tp, c, rtl_udelay, d, n, false); |
| 887 | } |
| 888 | |
| 889 | static bool rtl_msleep_loop_wait_high(struct rtl8169_private *tp, |
| 890 | const struct rtl_cond *c, |
| 891 | unsigned int d, int n) |
| 892 | { |
| 893 | return rtl_loop_wait(tp, c, msleep, d, n, true); |
| 894 | } |
| 895 | |
| 896 | static bool rtl_msleep_loop_wait_low(struct rtl8169_private *tp, |
| 897 | const struct rtl_cond *c, |
| 898 | unsigned int d, int n) |
| 899 | { |
| 900 | return rtl_loop_wait(tp, c, msleep, d, n, false); |
| 901 | } |
| 902 | |
| 903 | #define DECLARE_RTL_COND(name) \ |
| 904 | static bool name ## _check(struct rtl8169_private *); \ |
| 905 | \ |
| 906 | static const struct rtl_cond name = { \ |
| 907 | .check = name ## _check, \ |
| 908 | .msg = #name \ |
| 909 | }; \ |
| 910 | \ |
| 911 | static bool name ## _check(struct rtl8169_private *tp) |
| 912 | |
| 913 | DECLARE_RTL_COND(rtl_ocpar_cond) |
| 914 | { |
| 915 | void __iomem *ioaddr = tp->mmio_addr; |
| 916 | |
| 917 | return RTL_R32(OCPAR) & OCPAR_FLAG; |
| 918 | } |
| 919 | |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 920 | static u32 ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 921 | { |
| 922 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 923 | |
| 924 | RTL_W32(OCPAR, ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 925 | |
| 926 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 100, 20) ? |
| 927 | RTL_R32(OCPDR) : ~0; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 928 | } |
| 929 | |
| 930 | static void ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, u32 data) |
| 931 | { |
| 932 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 933 | |
| 934 | RTL_W32(OCPDR, data); |
| 935 | RTL_W32(OCPAR, OCPAR_FLAG | ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 936 | |
| 937 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 100, 20); |
| 938 | } |
| 939 | |
| 940 | DECLARE_RTL_COND(rtl_eriar_cond) |
| 941 | { |
| 942 | void __iomem *ioaddr = tp->mmio_addr; |
| 943 | |
| 944 | return RTL_R32(ERIAR) & ERIAR_FLAG; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 945 | } |
| 946 | |
Hayes Wang | fac5b3c | 2011-02-22 17:26:20 +0800 | [diff] [blame] | 947 | static void rtl8168_oob_notify(struct rtl8169_private *tp, u8 cmd) |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 948 | { |
Hayes Wang | fac5b3c | 2011-02-22 17:26:20 +0800 | [diff] [blame] | 949 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 950 | |
| 951 | RTL_W8(ERIDR, cmd); |
| 952 | RTL_W32(ERIAR, 0x800010e8); |
| 953 | msleep(2); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 954 | |
| 955 | if (!rtl_udelay_loop_wait_low(tp, &rtl_eriar_cond, 100, 5)) |
| 956 | return; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 957 | |
Hayes Wang | fac5b3c | 2011-02-22 17:26:20 +0800 | [diff] [blame] | 958 | ocp_write(tp, 0x1, 0x30, 0x00000001); |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | #define OOB_CMD_RESET 0x00 |
| 962 | #define OOB_CMD_DRIVER_START 0x05 |
| 963 | #define OOB_CMD_DRIVER_STOP 0x06 |
| 964 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 965 | static u16 rtl8168_get_ocp_reg(struct rtl8169_private *tp) |
| 966 | { |
| 967 | return (tp->mac_version == RTL_GIGA_MAC_VER_31) ? 0xb8 : 0x10; |
| 968 | } |
| 969 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 970 | DECLARE_RTL_COND(rtl_ocp_read_cond) |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 971 | { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 972 | u16 reg; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 973 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 974 | reg = rtl8168_get_ocp_reg(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 975 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 976 | return ocp_read(tp, 0x0f, reg) & 0x00000800; |
| 977 | } |
| 978 | |
| 979 | static void rtl8168_driver_start(struct rtl8169_private *tp) |
| 980 | { |
| 981 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_START); |
| 982 | |
| 983 | 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] | 984 | } |
| 985 | |
| 986 | static void rtl8168_driver_stop(struct rtl8169_private *tp) |
| 987 | { |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 988 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_STOP); |
| 989 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 990 | 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] | 991 | } |
| 992 | |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 993 | static int r8168dp_check_dash(struct rtl8169_private *tp) |
| 994 | { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 995 | u16 reg = rtl8168_get_ocp_reg(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 996 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 997 | return (ocp_read(tp, 0x0f, reg) & 0x00008000) ? 1 : 0; |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 998 | } |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 999 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1000 | static bool rtl_ocp_reg_failure(struct rtl8169_private *tp, u32 reg) |
| 1001 | { |
| 1002 | if (reg & 0xffff0001) { |
| 1003 | netif_err(tp, drv, tp->dev, "Invalid ocp reg %x!\n", reg); |
| 1004 | return true; |
| 1005 | } |
| 1006 | return false; |
| 1007 | } |
| 1008 | |
| 1009 | DECLARE_RTL_COND(rtl_ocp_gphy_cond) |
| 1010 | { |
| 1011 | void __iomem *ioaddr = tp->mmio_addr; |
| 1012 | |
| 1013 | return RTL_R32(GPHY_OCP) & OCPAR_FLAG; |
| 1014 | } |
| 1015 | |
| 1016 | static void r8168_phy_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 1017 | { |
| 1018 | void __iomem *ioaddr = tp->mmio_addr; |
| 1019 | |
| 1020 | if (rtl_ocp_reg_failure(tp, reg)) |
| 1021 | return; |
| 1022 | |
| 1023 | RTL_W32(GPHY_OCP, OCPAR_FLAG | (reg << 15) | data); |
| 1024 | |
| 1025 | rtl_udelay_loop_wait_low(tp, &rtl_ocp_gphy_cond, 25, 10); |
| 1026 | } |
| 1027 | |
| 1028 | static u16 r8168_phy_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 1029 | { |
| 1030 | void __iomem *ioaddr = tp->mmio_addr; |
| 1031 | |
| 1032 | if (rtl_ocp_reg_failure(tp, reg)) |
| 1033 | return 0; |
| 1034 | |
| 1035 | RTL_W32(GPHY_OCP, reg << 15); |
| 1036 | |
| 1037 | return rtl_udelay_loop_wait_high(tp, &rtl_ocp_gphy_cond, 25, 10) ? |
| 1038 | (RTL_R32(GPHY_OCP) & 0xffff) : ~0; |
| 1039 | } |
| 1040 | |
| 1041 | static void rtl_w1w0_phy_ocp(struct rtl8169_private *tp, int reg, int p, int m) |
| 1042 | { |
| 1043 | int val; |
| 1044 | |
| 1045 | val = r8168_phy_ocp_read(tp, reg); |
| 1046 | r8168_phy_ocp_write(tp, reg, (val | p) & ~m); |
| 1047 | } |
| 1048 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1049 | static void r8168_mac_ocp_write(struct rtl8169_private *tp, u32 reg, u32 data) |
| 1050 | { |
| 1051 | void __iomem *ioaddr = tp->mmio_addr; |
| 1052 | |
| 1053 | if (rtl_ocp_reg_failure(tp, reg)) |
| 1054 | return; |
| 1055 | |
| 1056 | RTL_W32(OCPDR, OCPAR_FLAG | (reg << 15) | data); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1057 | } |
| 1058 | |
| 1059 | static u16 r8168_mac_ocp_read(struct rtl8169_private *tp, u32 reg) |
| 1060 | { |
| 1061 | void __iomem *ioaddr = tp->mmio_addr; |
| 1062 | |
| 1063 | if (rtl_ocp_reg_failure(tp, reg)) |
| 1064 | return 0; |
| 1065 | |
| 1066 | RTL_W32(OCPDR, reg << 15); |
| 1067 | |
Hayes Wang | 3a83ad1 | 2012-07-11 20:31:56 +0800 | [diff] [blame] | 1068 | return RTL_R32(OCPDR); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 1069 | } |
| 1070 | |
| 1071 | #define OCP_STD_PHY_BASE 0xa400 |
| 1072 | |
| 1073 | static void r8168g_mdio_write(struct rtl8169_private *tp, int reg, int value) |
| 1074 | { |
| 1075 | if (reg == 0x1f) { |
| 1076 | tp->ocp_base = value ? value << 4 : OCP_STD_PHY_BASE; |
| 1077 | return; |
| 1078 | } |
| 1079 | |
| 1080 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 1081 | reg -= 0x10; |
| 1082 | |
| 1083 | r8168_phy_ocp_write(tp, tp->ocp_base + reg * 2, value); |
| 1084 | } |
| 1085 | |
| 1086 | static int r8168g_mdio_read(struct rtl8169_private *tp, int reg) |
| 1087 | { |
| 1088 | if (tp->ocp_base != OCP_STD_PHY_BASE) |
| 1089 | reg -= 0x10; |
| 1090 | |
| 1091 | return r8168_phy_ocp_read(tp, tp->ocp_base + reg * 2); |
| 1092 | } |
| 1093 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1094 | DECLARE_RTL_COND(rtl_phyar_cond) |
| 1095 | { |
| 1096 | void __iomem *ioaddr = tp->mmio_addr; |
| 1097 | |
| 1098 | return RTL_R32(PHYAR) & 0x80000000; |
| 1099 | } |
| 1100 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1101 | 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] | 1102 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1103 | void __iomem *ioaddr = tp->mmio_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1105 | RTL_W32(PHYAR, 0x80000000 | (reg & 0x1f) << 16 | (value & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1106 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1107 | rtl_udelay_loop_wait_low(tp, &rtl_phyar_cond, 25, 20); |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 1108 | /* |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 1109 | * According to hardware specs a 20us delay is required after write |
| 1110 | * complete indication, but before sending next command. |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 1111 | */ |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 1112 | udelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1113 | } |
| 1114 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1115 | static int r8169_mdio_read(struct rtl8169_private *tp, int reg) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1116 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1117 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1118 | int value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1119 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1120 | RTL_W32(PHYAR, 0x0 | (reg & 0x1f) << 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1121 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1122 | value = rtl_udelay_loop_wait_high(tp, &rtl_phyar_cond, 25, 20) ? |
| 1123 | RTL_R32(PHYAR) & 0xffff : ~0; |
| 1124 | |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 1125 | /* |
| 1126 | * According to hardware specs a 20us delay is required after read |
| 1127 | * complete indication, but before sending next command. |
| 1128 | */ |
| 1129 | udelay(20); |
| 1130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | return value; |
| 1132 | } |
| 1133 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1134 | 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] | 1135 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1136 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1137 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1138 | 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] | 1139 | RTL_W32(OCPAR, OCPAR_GPHY_WRITE_CMD); |
| 1140 | RTL_W32(EPHY_RXER_NUM, 0); |
| 1141 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1142 | rtl_udelay_loop_wait_low(tp, &rtl_ocpar_cond, 1000, 100); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1143 | } |
| 1144 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1145 | 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] | 1146 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1147 | r8168dp_1_mdio_access(tp, reg, |
| 1148 | OCPDR_WRITE_CMD | (value & OCPDR_DATA_MASK)); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1149 | } |
| 1150 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1151 | 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] | 1152 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1153 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1154 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1155 | r8168dp_1_mdio_access(tp, reg, OCPDR_READ_CMD); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1156 | |
| 1157 | mdelay(1); |
| 1158 | RTL_W32(OCPAR, OCPAR_GPHY_READ_CMD); |
| 1159 | RTL_W32(EPHY_RXER_NUM, 0); |
| 1160 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1161 | return rtl_udelay_loop_wait_high(tp, &rtl_ocpar_cond, 1000, 100) ? |
| 1162 | RTL_R32(OCPDR) & OCPDR_DATA_MASK : ~0; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1163 | } |
| 1164 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1165 | #define R8168DP_1_MDIO_ACCESS_BIT 0x00020000 |
| 1166 | |
| 1167 | static void r8168dp_2_mdio_start(void __iomem *ioaddr) |
| 1168 | { |
| 1169 | RTL_W32(0xd0, RTL_R32(0xd0) & ~R8168DP_1_MDIO_ACCESS_BIT); |
| 1170 | } |
| 1171 | |
| 1172 | static void r8168dp_2_mdio_stop(void __iomem *ioaddr) |
| 1173 | { |
| 1174 | RTL_W32(0xd0, RTL_R32(0xd0) | R8168DP_1_MDIO_ACCESS_BIT); |
| 1175 | } |
| 1176 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1177 | 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] | 1178 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1179 | void __iomem *ioaddr = tp->mmio_addr; |
| 1180 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1181 | r8168dp_2_mdio_start(ioaddr); |
| 1182 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1183 | r8169_mdio_write(tp, reg, value); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1184 | |
| 1185 | r8168dp_2_mdio_stop(ioaddr); |
| 1186 | } |
| 1187 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1188 | 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] | 1189 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1190 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1191 | int value; |
| 1192 | |
| 1193 | r8168dp_2_mdio_start(ioaddr); |
| 1194 | |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1195 | value = r8169_mdio_read(tp, reg); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1196 | |
| 1197 | r8168dp_2_mdio_stop(ioaddr); |
| 1198 | |
| 1199 | return value; |
| 1200 | } |
| 1201 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1202 | static void rtl_writephy(struct rtl8169_private *tp, int location, u32 val) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1203 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1204 | tp->mdio_ops.write(tp, location, val); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1205 | } |
| 1206 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1207 | static int rtl_readphy(struct rtl8169_private *tp, int location) |
| 1208 | { |
Francois Romieu | 2419221 | 2012-07-06 20:19:42 +0200 | [diff] [blame] | 1209 | return tp->mdio_ops.read(tp, location); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1210 | } |
| 1211 | |
| 1212 | static void rtl_patchphy(struct rtl8169_private *tp, int reg_addr, int value) |
| 1213 | { |
| 1214 | rtl_writephy(tp, reg_addr, rtl_readphy(tp, reg_addr) | value); |
| 1215 | } |
| 1216 | |
| 1217 | static void rtl_w1w0_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] | 1218 | { |
| 1219 | int val; |
| 1220 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1221 | val = rtl_readphy(tp, reg_addr); |
| 1222 | rtl_writephy(tp, reg_addr, (val | p) & ~m); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1223 | } |
| 1224 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1225 | static void rtl_mdio_write(struct net_device *dev, int phy_id, int location, |
| 1226 | int val) |
| 1227 | { |
| 1228 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1229 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1230 | rtl_writephy(tp, location, val); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1231 | } |
| 1232 | |
| 1233 | static int rtl_mdio_read(struct net_device *dev, int phy_id, int location) |
| 1234 | { |
| 1235 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1236 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1237 | return rtl_readphy(tp, location); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1238 | } |
| 1239 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1240 | DECLARE_RTL_COND(rtl_ephyar_cond) |
| 1241 | { |
| 1242 | void __iomem *ioaddr = tp->mmio_addr; |
| 1243 | |
| 1244 | return RTL_R32(EPHYAR) & EPHYAR_FLAG; |
| 1245 | } |
| 1246 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1247 | 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] | 1248 | { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1249 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1250 | |
| 1251 | RTL_W32(EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) | |
| 1252 | (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
| 1253 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1254 | rtl_udelay_loop_wait_low(tp, &rtl_ephyar_cond, 10, 100); |
| 1255 | |
| 1256 | udelay(10); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1257 | } |
| 1258 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1259 | static u16 rtl_ephy_read(struct rtl8169_private *tp, int reg_addr) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1260 | { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1261 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1262 | |
| 1263 | RTL_W32(EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
| 1264 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1265 | return rtl_udelay_loop_wait_high(tp, &rtl_ephyar_cond, 10, 100) ? |
| 1266 | RTL_R32(EPHYAR) & EPHYAR_DATA_MASK : ~0; |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1267 | } |
| 1268 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1269 | static void rtl_eri_write(struct rtl8169_private *tp, int addr, u32 mask, |
| 1270 | u32 val, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1271 | { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1272 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1273 | |
| 1274 | BUG_ON((addr & 3) || (mask == 0)); |
| 1275 | RTL_W32(ERIDR, val); |
| 1276 | RTL_W32(ERIAR, ERIAR_WRITE_CMD | type | mask | addr); |
| 1277 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1278 | rtl_udelay_loop_wait_low(tp, &rtl_eriar_cond, 100, 100); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1279 | } |
| 1280 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1281 | 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] | 1282 | { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1283 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1284 | |
| 1285 | RTL_W32(ERIAR, ERIAR_READ_CMD | type | ERIAR_MASK_1111 | addr); |
| 1286 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1287 | return rtl_udelay_loop_wait_high(tp, &rtl_eriar_cond, 100, 100) ? |
| 1288 | RTL_R32(ERIDR) : ~0; |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1289 | } |
| 1290 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1291 | static void rtl_w1w0_eri(struct rtl8169_private *tp, int addr, u32 mask, u32 p, |
| 1292 | u32 m, int type) |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1293 | { |
| 1294 | u32 val; |
| 1295 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1296 | val = rtl_eri_read(tp, addr, type); |
| 1297 | rtl_eri_write(tp, addr, mask, (val & ~m) | p, type); |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1298 | } |
| 1299 | |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1300 | struct exgmac_reg { |
| 1301 | u16 addr; |
| 1302 | u16 mask; |
| 1303 | u32 val; |
| 1304 | }; |
| 1305 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1306 | static void rtl_write_exgmac_batch(struct rtl8169_private *tp, |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1307 | const struct exgmac_reg *r, int len) |
| 1308 | { |
| 1309 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1310 | 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] | 1311 | r++; |
| 1312 | } |
| 1313 | } |
| 1314 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1315 | DECLARE_RTL_COND(rtl_efusear_cond) |
| 1316 | { |
| 1317 | void __iomem *ioaddr = tp->mmio_addr; |
| 1318 | |
| 1319 | return RTL_R32(EFUSEAR) & EFUSEAR_FLAG; |
| 1320 | } |
| 1321 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1322 | 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] | 1323 | { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1324 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1325 | |
| 1326 | RTL_W32(EFUSEAR, (reg_addr & EFUSEAR_REG_MASK) << EFUSEAR_REG_SHIFT); |
| 1327 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1328 | return rtl_udelay_loop_wait_high(tp, &rtl_efusear_cond, 100, 300) ? |
| 1329 | RTL_R32(EFUSEAR) & EFUSEAR_DATA_MASK : ~0; |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1330 | } |
| 1331 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1332 | static u16 rtl_get_events(struct rtl8169_private *tp) |
| 1333 | { |
| 1334 | void __iomem *ioaddr = tp->mmio_addr; |
| 1335 | |
| 1336 | return RTL_R16(IntrStatus); |
| 1337 | } |
| 1338 | |
| 1339 | static void rtl_ack_events(struct rtl8169_private *tp, u16 bits) |
| 1340 | { |
| 1341 | void __iomem *ioaddr = tp->mmio_addr; |
| 1342 | |
| 1343 | RTL_W16(IntrStatus, bits); |
| 1344 | mmiowb(); |
| 1345 | } |
| 1346 | |
| 1347 | static void rtl_irq_disable(struct rtl8169_private *tp) |
| 1348 | { |
| 1349 | void __iomem *ioaddr = tp->mmio_addr; |
| 1350 | |
| 1351 | RTL_W16(IntrMask, 0); |
| 1352 | mmiowb(); |
| 1353 | } |
| 1354 | |
Francois Romieu | 3e990ff | 2012-01-26 12:50:01 +0100 | [diff] [blame] | 1355 | static void rtl_irq_enable(struct rtl8169_private *tp, u16 bits) |
| 1356 | { |
| 1357 | void __iomem *ioaddr = tp->mmio_addr; |
| 1358 | |
| 1359 | RTL_W16(IntrMask, bits); |
| 1360 | } |
| 1361 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1362 | #define RTL_EVENT_NAPI_RX (RxOK | RxErr) |
| 1363 | #define RTL_EVENT_NAPI_TX (TxOK | TxErr) |
| 1364 | #define RTL_EVENT_NAPI (RTL_EVENT_NAPI_RX | RTL_EVENT_NAPI_TX) |
| 1365 | |
| 1366 | static void rtl_irq_enable_all(struct rtl8169_private *tp) |
| 1367 | { |
| 1368 | rtl_irq_enable(tp, RTL_EVENT_NAPI | tp->event_slow); |
| 1369 | } |
| 1370 | |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 1371 | static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1372 | { |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 1373 | void __iomem *ioaddr = tp->mmio_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1374 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1375 | rtl_irq_disable(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1376 | rtl_ack_events(tp, RTL_EVENT_NAPI | tp->event_slow); |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 1377 | RTL_R8(ChipCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | } |
| 1379 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1380 | static unsigned int rtl8169_tbi_reset_pending(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1382 | void __iomem *ioaddr = tp->mmio_addr; |
| 1383 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1384 | return RTL_R32(TBICSR) & TBIReset; |
| 1385 | } |
| 1386 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1387 | static unsigned int rtl8169_xmii_reset_pending(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1389 | return rtl_readphy(tp, MII_BMCR) & BMCR_RESET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1390 | } |
| 1391 | |
| 1392 | static unsigned int rtl8169_tbi_link_ok(void __iomem *ioaddr) |
| 1393 | { |
| 1394 | return RTL_R32(TBICSR) & TBILinkOk; |
| 1395 | } |
| 1396 | |
| 1397 | static unsigned int rtl8169_xmii_link_ok(void __iomem *ioaddr) |
| 1398 | { |
| 1399 | return RTL_R8(PHYstatus) & LinkStatus; |
| 1400 | } |
| 1401 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1402 | static void rtl8169_tbi_reset_enable(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1403 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1404 | void __iomem *ioaddr = tp->mmio_addr; |
| 1405 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | RTL_W32(TBICSR, RTL_R32(TBICSR) | TBIReset); |
| 1407 | } |
| 1408 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1409 | static void rtl8169_xmii_reset_enable(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1410 | { |
| 1411 | unsigned int val; |
| 1412 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1413 | val = rtl_readphy(tp, MII_BMCR) | BMCR_RESET; |
| 1414 | rtl_writephy(tp, MII_BMCR, val & 0xffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1415 | } |
| 1416 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1417 | static void rtl_link_chg_patch(struct rtl8169_private *tp) |
| 1418 | { |
| 1419 | void __iomem *ioaddr = tp->mmio_addr; |
| 1420 | struct net_device *dev = tp->dev; |
| 1421 | |
| 1422 | if (!netif_running(dev)) |
| 1423 | return; |
| 1424 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 1425 | if (tp->mac_version == RTL_GIGA_MAC_VER_34 || |
| 1426 | tp->mac_version == RTL_GIGA_MAC_VER_38) { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1427 | if (RTL_R8(PHYstatus) & _1000bpsF) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1428 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011, |
| 1429 | ERIAR_EXGMAC); |
| 1430 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1431 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1432 | } else if (RTL_R8(PHYstatus) & _100bps) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1433 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1434 | ERIAR_EXGMAC); |
| 1435 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1436 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1437 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1438 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1439 | ERIAR_EXGMAC); |
| 1440 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f, |
| 1441 | ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1442 | } |
| 1443 | /* Reset packet filter */ |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1444 | rtl_w1w0_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1445 | ERIAR_EXGMAC); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1446 | rtl_w1w0_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1447 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1448 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 1449 | tp->mac_version == RTL_GIGA_MAC_VER_36) { |
| 1450 | if (RTL_R8(PHYstatus) & _1000bpsF) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1451 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x00000011, |
| 1452 | ERIAR_EXGMAC); |
| 1453 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x00000005, |
| 1454 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1455 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1456 | rtl_eri_write(tp, 0x1bc, ERIAR_MASK_1111, 0x0000001f, |
| 1457 | ERIAR_EXGMAC); |
| 1458 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_1111, 0x0000003f, |
| 1459 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1460 | } |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1461 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_37) { |
| 1462 | if (RTL_R8(PHYstatus) & _10bps) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1463 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x4d02, |
| 1464 | ERIAR_EXGMAC); |
| 1465 | rtl_eri_write(tp, 0x1dc, ERIAR_MASK_0011, 0x0060, |
| 1466 | ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1467 | } else { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 1468 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, |
| 1469 | ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 1470 | } |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1471 | } |
| 1472 | } |
| 1473 | |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 1474 | static void __rtl8169_check_link_status(struct net_device *dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1475 | struct rtl8169_private *tp, |
| 1476 | void __iomem *ioaddr, bool pm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | if (tp->link_ok(ioaddr)) { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1479 | rtl_link_chg_patch(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1480 | /* This is to cancel a scheduled suspend if there's one. */ |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 1481 | if (pm) |
| 1482 | pm_request_resume(&tp->pci_dev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | netif_carrier_on(dev); |
Francois Romieu | 1519e57 | 2011-02-03 12:02:36 +0100 | [diff] [blame] | 1484 | if (net_ratelimit()) |
| 1485 | netif_info(tp, ifup, dev, "link up\n"); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1486 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1487 | netif_carrier_off(dev); |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1488 | netif_info(tp, ifdown, dev, "link down\n"); |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 1489 | if (pm) |
hayeswang | 10953db | 2011-11-07 20:44:37 +0000 | [diff] [blame] | 1490 | pm_schedule_suspend(&tp->pci_dev->dev, 5000); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1491 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | } |
| 1493 | |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 1494 | static void rtl8169_check_link_status(struct net_device *dev, |
| 1495 | struct rtl8169_private *tp, |
| 1496 | void __iomem *ioaddr) |
| 1497 | { |
| 1498 | __rtl8169_check_link_status(dev, tp, ioaddr, false); |
| 1499 | } |
| 1500 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1501 | #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST) |
| 1502 | |
| 1503 | static u32 __rtl8169_get_wol(struct rtl8169_private *tp) |
| 1504 | { |
| 1505 | void __iomem *ioaddr = tp->mmio_addr; |
| 1506 | u8 options; |
| 1507 | u32 wolopts = 0; |
| 1508 | |
| 1509 | options = RTL_R8(Config1); |
| 1510 | if (!(options & PMEnable)) |
| 1511 | return 0; |
| 1512 | |
| 1513 | options = RTL_R8(Config3); |
| 1514 | if (options & LinkUp) |
| 1515 | wolopts |= WAKE_PHY; |
| 1516 | if (options & MagicPacket) |
| 1517 | wolopts |= WAKE_MAGIC; |
| 1518 | |
| 1519 | options = RTL_R8(Config5); |
| 1520 | if (options & UWF) |
| 1521 | wolopts |= WAKE_UCAST; |
| 1522 | if (options & BWF) |
| 1523 | wolopts |= WAKE_BCAST; |
| 1524 | if (options & MWF) |
| 1525 | wolopts |= WAKE_MCAST; |
| 1526 | |
| 1527 | return wolopts; |
| 1528 | } |
| 1529 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1530 | static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1531 | { |
| 1532 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1533 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1534 | rtl_lock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1535 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1536 | wol->supported = WAKE_ANY; |
| 1537 | wol->wolopts = __rtl8169_get_wol(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1538 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1539 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1540 | } |
| 1541 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1542 | static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1543 | { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1544 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 1545 | unsigned int i; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 1546 | static const struct { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1547 | u32 opt; |
| 1548 | u16 reg; |
| 1549 | u8 mask; |
| 1550 | } cfg[] = { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1551 | { WAKE_PHY, Config3, LinkUp }, |
| 1552 | { WAKE_MAGIC, Config3, MagicPacket }, |
| 1553 | { WAKE_UCAST, Config5, UWF }, |
| 1554 | { WAKE_BCAST, Config5, BWF }, |
| 1555 | { WAKE_MCAST, Config5, MWF }, |
| 1556 | { WAKE_ANY, Config5, LanWake } |
| 1557 | }; |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1558 | u8 options; |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1559 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1560 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 1561 | |
| 1562 | for (i = 0; i < ARRAY_SIZE(cfg); i++) { |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1563 | options = RTL_R8(cfg[i].reg) & ~cfg[i].mask; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1564 | if (wolopts & cfg[i].opt) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1565 | options |= cfg[i].mask; |
| 1566 | RTL_W8(cfg[i].reg, options); |
| 1567 | } |
| 1568 | |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1569 | switch (tp->mac_version) { |
| 1570 | case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_17: |
| 1571 | options = RTL_R8(Config1) & ~PMEnable; |
| 1572 | if (wolopts) |
| 1573 | options |= PMEnable; |
| 1574 | RTL_W8(Config1, options); |
| 1575 | break; |
| 1576 | default: |
Francois Romieu | d387b42 | 2012-04-17 11:12:01 +0200 | [diff] [blame] | 1577 | options = RTL_R8(Config2) & ~PME_SIGNAL; |
| 1578 | if (wolopts) |
| 1579 | options |= PME_SIGNAL; |
| 1580 | RTL_W8(Config2, options); |
Francois Romieu | 851e602 | 2012-04-17 11:10:11 +0200 | [diff] [blame] | 1581 | break; |
| 1582 | } |
| 1583 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1584 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1585 | } |
| 1586 | |
| 1587 | static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1588 | { |
| 1589 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1590 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1591 | rtl_lock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1592 | |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 1593 | if (wol->wolopts) |
| 1594 | tp->features |= RTL_FEATURE_WOL; |
| 1595 | else |
| 1596 | tp->features &= ~RTL_FEATURE_WOL; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1597 | __rtl8169_set_wol(tp, wol->wolopts); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1598 | |
| 1599 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1600 | |
françois romieu | ea80907 | 2010-11-08 13:23:58 +0000 | [diff] [blame] | 1601 | device_set_wakeup_enable(&tp->pci_dev->dev, wol->wolopts); |
| 1602 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1603 | return 0; |
| 1604 | } |
| 1605 | |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1606 | static const char *rtl_lookup_firmware_name(struct rtl8169_private *tp) |
| 1607 | { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 1608 | return rtl_chip_infos[tp->mac_version].fw_name; |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1609 | } |
| 1610 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1611 | static void rtl8169_get_drvinfo(struct net_device *dev, |
| 1612 | struct ethtool_drvinfo *info) |
| 1613 | { |
| 1614 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 1615 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 1617 | strlcpy(info->driver, MODULENAME, sizeof(info->driver)); |
| 1618 | strlcpy(info->version, RTL8169_VERSION, sizeof(info->version)); |
| 1619 | 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] | 1620 | BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version)); |
Rick Jones | 8ac72d1 | 2011-11-22 14:06:26 +0000 | [diff] [blame] | 1621 | if (!IS_ERR_OR_NULL(rtl_fw)) |
| 1622 | strlcpy(info->fw_version, rtl_fw->version, |
| 1623 | sizeof(info->fw_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | } |
| 1625 | |
| 1626 | static int rtl8169_get_regs_len(struct net_device *dev) |
| 1627 | { |
| 1628 | return R8169_REGS_SIZE; |
| 1629 | } |
| 1630 | |
| 1631 | static int rtl8169_set_speed_tbi(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1632 | u8 autoneg, u16 speed, u8 duplex, u32 ignored) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1633 | { |
| 1634 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1635 | void __iomem *ioaddr = tp->mmio_addr; |
| 1636 | int ret = 0; |
| 1637 | u32 reg; |
| 1638 | |
| 1639 | reg = RTL_R32(TBICSR); |
| 1640 | if ((autoneg == AUTONEG_DISABLE) && (speed == SPEED_1000) && |
| 1641 | (duplex == DUPLEX_FULL)) { |
| 1642 | RTL_W32(TBICSR, reg & ~(TBINwEnable | TBINwRestart)); |
| 1643 | } else if (autoneg == AUTONEG_ENABLE) |
| 1644 | RTL_W32(TBICSR, reg | TBINwEnable | TBINwRestart); |
| 1645 | else { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1646 | netif_warn(tp, link, dev, |
| 1647 | "incorrect speed setting refused in TBI mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1648 | ret = -EOPNOTSUPP; |
| 1649 | } |
| 1650 | |
| 1651 | return ret; |
| 1652 | } |
| 1653 | |
| 1654 | static int rtl8169_set_speed_xmii(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1655 | u8 autoneg, u16 speed, u8 duplex, u32 adv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1656 | { |
| 1657 | struct rtl8169_private *tp = netdev_priv(dev); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1658 | int giga_ctrl, bmcr; |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1659 | int rc = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | |
Hayes Wang | 716b50a | 2011-02-22 17:26:18 +0800 | [diff] [blame] | 1661 | rtl_writephy(tp, 0x1f, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | |
| 1663 | if (autoneg == AUTONEG_ENABLE) { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1664 | int auto_nego; |
| 1665 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1666 | auto_nego = rtl_readphy(tp, MII_ADVERTISE); |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1667 | auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL | |
| 1668 | ADVERTISE_100HALF | ADVERTISE_100FULL); |
| 1669 | |
| 1670 | if (adv & ADVERTISED_10baseT_Half) |
| 1671 | auto_nego |= ADVERTISE_10HALF; |
| 1672 | if (adv & ADVERTISED_10baseT_Full) |
| 1673 | auto_nego |= ADVERTISE_10FULL; |
| 1674 | if (adv & ADVERTISED_100baseT_Half) |
| 1675 | auto_nego |= ADVERTISE_100HALF; |
| 1676 | if (adv & ADVERTISED_100baseT_Full) |
| 1677 | auto_nego |= ADVERTISE_100FULL; |
| 1678 | |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1679 | auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 1680 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1681 | giga_ctrl = rtl_readphy(tp, MII_CTRL1000); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1682 | giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); |
| 1683 | |
| 1684 | /* The 8100e/8101e/8102e do Fast Ethernet only. */ |
Francois Romieu | 826e6cb | 2011-03-11 20:30:24 +0100 | [diff] [blame] | 1685 | if (tp->mii.supports_gmii) { |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1686 | if (adv & ADVERTISED_1000baseT_Half) |
| 1687 | giga_ctrl |= ADVERTISE_1000HALF; |
| 1688 | if (adv & ADVERTISED_1000baseT_Full) |
| 1689 | giga_ctrl |= ADVERTISE_1000FULL; |
| 1690 | } else if (adv & (ADVERTISED_1000baseT_Half | |
| 1691 | ADVERTISED_1000baseT_Full)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1692 | netif_info(tp, link, dev, |
| 1693 | "PHY does not support 1000Mbps\n"); |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1694 | goto out; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 1695 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1697 | bmcr = BMCR_ANENABLE | BMCR_ANRESTART; |
Francois Romieu | 623a159 | 2006-05-14 12:42:14 +0200 | [diff] [blame] | 1698 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1699 | rtl_writephy(tp, MII_ADVERTISE, auto_nego); |
| 1700 | rtl_writephy(tp, MII_CTRL1000, giga_ctrl); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1701 | } else { |
| 1702 | giga_ctrl = 0; |
| 1703 | |
| 1704 | if (speed == SPEED_10) |
| 1705 | bmcr = 0; |
| 1706 | else if (speed == SPEED_100) |
| 1707 | bmcr = BMCR_SPEED100; |
| 1708 | else |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1709 | goto out; |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1710 | |
| 1711 | if (duplex == DUPLEX_FULL) |
| 1712 | bmcr |= BMCR_FULLDPLX; |
Roger So | 2584fbc | 2007-07-31 23:52:42 +0200 | [diff] [blame] | 1713 | } |
| 1714 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1715 | rtl_writephy(tp, MII_BMCR, bmcr); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1716 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1717 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 1718 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1719 | if ((speed == SPEED_100) && (autoneg != AUTONEG_ENABLE)) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1720 | rtl_writephy(tp, 0x17, 0x2138); |
| 1721 | rtl_writephy(tp, 0x0e, 0x0260); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1722 | } else { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1723 | rtl_writephy(tp, 0x17, 0x2108); |
| 1724 | rtl_writephy(tp, 0x0e, 0x0000); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1725 | } |
| 1726 | } |
| 1727 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1728 | rc = 0; |
| 1729 | out: |
| 1730 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | } |
| 1732 | |
| 1733 | static int rtl8169_set_speed(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1734 | u8 autoneg, u16 speed, u8 duplex, u32 advertising) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1735 | { |
| 1736 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1737 | int ret; |
| 1738 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1739 | ret = tp->set_speed(dev, autoneg, speed, duplex, advertising); |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1740 | if (ret < 0) |
| 1741 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1743 | if (netif_running(dev) && (autoneg == AUTONEG_ENABLE) && |
| 1744 | (advertising & ADVERTISED_1000baseT_Full)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1745 | mod_timer(&tp->timer, jiffies + RTL8169_PHY_TIMEOUT); |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1746 | } |
| 1747 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1748 | return ret; |
| 1749 | } |
| 1750 | |
| 1751 | static int rtl8169_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 1752 | { |
| 1753 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1754 | int ret; |
| 1755 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1756 | del_timer_sync(&tp->timer); |
| 1757 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1758 | rtl_lock_work(tp); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1759 | ret = rtl8169_set_speed(dev, cmd->autoneg, ethtool_cmd_speed(cmd), |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 1760 | cmd->duplex, cmd->advertising); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1761 | rtl_unlock_work(tp); |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1762 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1763 | return ret; |
| 1764 | } |
| 1765 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 1766 | static netdev_features_t rtl8169_fix_features(struct net_device *dev, |
| 1767 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1768 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1769 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1770 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 1771 | if (dev->mtu > TD_MSS_MAX) |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1772 | features &= ~NETIF_F_ALL_TSO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1773 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1774 | if (dev->mtu > JUMBO_1K && |
| 1775 | !rtl_chip_infos[tp->mac_version].jumbo_tx_csum) |
| 1776 | features &= ~NETIF_F_IP_CSUM; |
| 1777 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1778 | return features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1779 | } |
| 1780 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1781 | static void __rtl8169_set_features(struct net_device *dev, |
| 1782 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1783 | { |
| 1784 | struct rtl8169_private *tp = netdev_priv(dev); |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 1785 | netdev_features_t changed = features ^ dev->features; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1786 | void __iomem *ioaddr = tp->mmio_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1787 | |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 1788 | if (!(changed & (NETIF_F_RXALL | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_RX))) |
| 1789 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1790 | |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 1791 | if (changed & (NETIF_F_RXCSUM | NETIF_F_HW_VLAN_RX)) { |
| 1792 | if (features & NETIF_F_RXCSUM) |
| 1793 | tp->cp_cmd |= RxChkSum; |
| 1794 | else |
| 1795 | tp->cp_cmd &= ~RxChkSum; |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1796 | |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 1797 | if (dev->features & NETIF_F_HW_VLAN_RX) |
| 1798 | tp->cp_cmd |= RxVlan; |
| 1799 | else |
| 1800 | tp->cp_cmd &= ~RxVlan; |
| 1801 | |
| 1802 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 1803 | RTL_R16(CPlusCmd); |
| 1804 | } |
| 1805 | if (changed & NETIF_F_RXALL) { |
| 1806 | int tmp = (RTL_R32(RxConfig) & ~(AcceptErr | AcceptRunt)); |
| 1807 | if (features & NETIF_F_RXALL) |
| 1808 | tmp |= (AcceptErr | AcceptRunt); |
| 1809 | RTL_W32(RxConfig, tmp); |
| 1810 | } |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1811 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1812 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1813 | static int rtl8169_set_features(struct net_device *dev, |
| 1814 | netdev_features_t features) |
| 1815 | { |
| 1816 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1817 | |
| 1818 | rtl_lock_work(tp); |
| 1819 | __rtl8169_set_features(dev, features); |
| 1820 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1821 | |
| 1822 | return 0; |
| 1823 | } |
| 1824 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1825 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1826 | static inline u32 rtl8169_tx_vlan_tag(struct rtl8169_private *tp, |
| 1827 | struct sk_buff *skb) |
| 1828 | { |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 1829 | return (vlan_tx_tag_present(skb)) ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1830 | TxVlanTag | swab16(vlan_tx_tag_get(skb)) : 0x00; |
| 1831 | } |
| 1832 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1833 | 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] | 1834 | { |
| 1835 | u32 opts2 = le32_to_cpu(desc->opts2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1836 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1837 | if (opts2 & RxVlanTag) |
| 1838 | __vlan_hwaccel_put_tag(skb, swab16(opts2 & 0xffff)); |
Eric Dumazet | 2edae08 | 2010-09-06 18:46:39 +0000 | [diff] [blame] | 1839 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1840 | desc->opts2 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1841 | } |
| 1842 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1843 | 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] | 1844 | { |
| 1845 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1846 | void __iomem *ioaddr = tp->mmio_addr; |
| 1847 | u32 status; |
| 1848 | |
| 1849 | cmd->supported = |
| 1850 | SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE; |
| 1851 | cmd->port = PORT_FIBRE; |
| 1852 | cmd->transceiver = XCVR_INTERNAL; |
| 1853 | |
| 1854 | status = RTL_R32(TBICSR); |
| 1855 | cmd->advertising = (status & TBINwEnable) ? ADVERTISED_Autoneg : 0; |
| 1856 | cmd->autoneg = !!(status & TBINwEnable); |
| 1857 | |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 1858 | ethtool_cmd_speed_set(cmd, SPEED_1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | cmd->duplex = DUPLEX_FULL; /* Always set */ |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1860 | |
| 1861 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1862 | } |
| 1863 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1864 | 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] | 1865 | { |
| 1866 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1867 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1868 | return mii_ethtool_gset(&tp->mii, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1869 | } |
| 1870 | |
| 1871 | static int rtl8169_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 1872 | { |
| 1873 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1874 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1875 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1876 | rtl_lock_work(tp); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1877 | rc = tp->get_settings(dev, cmd); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1878 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1880 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1881 | } |
| 1882 | |
| 1883 | static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 1884 | void *p) |
| 1885 | { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1886 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1887 | |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1888 | if (regs->len > R8169_REGS_SIZE) |
| 1889 | regs->len = R8169_REGS_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1890 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1891 | rtl_lock_work(tp); |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1892 | memcpy_fromio(p, tp->mmio_addr, regs->len); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1893 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1894 | } |
| 1895 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1896 | static u32 rtl8169_get_msglevel(struct net_device *dev) |
| 1897 | { |
| 1898 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1899 | |
| 1900 | return tp->msg_enable; |
| 1901 | } |
| 1902 | |
| 1903 | static void rtl8169_set_msglevel(struct net_device *dev, u32 value) |
| 1904 | { |
| 1905 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1906 | |
| 1907 | tp->msg_enable = value; |
| 1908 | } |
| 1909 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1910 | static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = { |
| 1911 | "tx_packets", |
| 1912 | "rx_packets", |
| 1913 | "tx_errors", |
| 1914 | "rx_errors", |
| 1915 | "rx_missed", |
| 1916 | "align_errors", |
| 1917 | "tx_single_collisions", |
| 1918 | "tx_multi_collisions", |
| 1919 | "unicast", |
| 1920 | "broadcast", |
| 1921 | "multicast", |
| 1922 | "tx_aborted", |
| 1923 | "tx_underrun", |
| 1924 | }; |
| 1925 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1926 | static int rtl8169_get_sset_count(struct net_device *dev, int sset) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1927 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1928 | switch (sset) { |
| 1929 | case ETH_SS_STATS: |
| 1930 | return ARRAY_SIZE(rtl8169_gstrings); |
| 1931 | default: |
| 1932 | return -EOPNOTSUPP; |
| 1933 | } |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1934 | } |
| 1935 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1936 | DECLARE_RTL_COND(rtl_counters_cond) |
| 1937 | { |
| 1938 | void __iomem *ioaddr = tp->mmio_addr; |
| 1939 | |
| 1940 | return RTL_R32(CounterAddrLow) & CounterDump; |
| 1941 | } |
| 1942 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1943 | static void rtl8169_update_counters(struct net_device *dev) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1944 | { |
| 1945 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1946 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1947 | struct device *d = &tp->pci_dev->dev; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1948 | struct rtl8169_counters *counters; |
| 1949 | dma_addr_t paddr; |
| 1950 | u32 cmd; |
| 1951 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1952 | /* |
| 1953 | * Some chips are unable to dump tally counters when the receiver |
| 1954 | * is disabled. |
| 1955 | */ |
| 1956 | if ((RTL_R8(ChipCmd) & CmdRxEnb) == 0) |
| 1957 | return; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1958 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 1959 | counters = dma_alloc_coherent(d, sizeof(*counters), &paddr, GFP_KERNEL); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1960 | if (!counters) |
| 1961 | return; |
| 1962 | |
| 1963 | RTL_W32(CounterAddrHigh, (u64)paddr >> 32); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1964 | cmd = (u64)paddr & DMA_BIT_MASK(32); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1965 | RTL_W32(CounterAddrLow, cmd); |
| 1966 | RTL_W32(CounterAddrLow, cmd | CounterDump); |
| 1967 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 1968 | if (rtl_udelay_loop_wait_low(tp, &rtl_counters_cond, 10, 1000)) |
| 1969 | memcpy(&tp->counters, counters, sizeof(*counters)); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1970 | |
| 1971 | RTL_W32(CounterAddrLow, 0); |
| 1972 | RTL_W32(CounterAddrHigh, 0); |
| 1973 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 1974 | dma_free_coherent(d, sizeof(*counters), counters, paddr); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1975 | } |
| 1976 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1977 | static void rtl8169_get_ethtool_stats(struct net_device *dev, |
| 1978 | struct ethtool_stats *stats, u64 *data) |
| 1979 | { |
| 1980 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1981 | |
| 1982 | ASSERT_RTNL(); |
| 1983 | |
| 1984 | rtl8169_update_counters(dev); |
| 1985 | |
| 1986 | data[0] = le64_to_cpu(tp->counters.tx_packets); |
| 1987 | data[1] = le64_to_cpu(tp->counters.rx_packets); |
| 1988 | data[2] = le64_to_cpu(tp->counters.tx_errors); |
| 1989 | data[3] = le32_to_cpu(tp->counters.rx_errors); |
| 1990 | data[4] = le16_to_cpu(tp->counters.rx_missed); |
| 1991 | data[5] = le16_to_cpu(tp->counters.align_errors); |
| 1992 | data[6] = le32_to_cpu(tp->counters.tx_one_collision); |
| 1993 | data[7] = le32_to_cpu(tp->counters.tx_multi_collision); |
| 1994 | data[8] = le64_to_cpu(tp->counters.rx_unicast); |
| 1995 | data[9] = le64_to_cpu(tp->counters.rx_broadcast); |
| 1996 | data[10] = le32_to_cpu(tp->counters.rx_multicast); |
| 1997 | data[11] = le16_to_cpu(tp->counters.tx_aborted); |
| 1998 | data[12] = le16_to_cpu(tp->counters.tx_underun); |
| 1999 | } |
| 2000 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2001 | static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 2002 | { |
| 2003 | switch(stringset) { |
| 2004 | case ETH_SS_STATS: |
| 2005 | memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings)); |
| 2006 | break; |
| 2007 | } |
| 2008 | } |
| 2009 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 2010 | static const struct ethtool_ops rtl8169_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2011 | .get_drvinfo = rtl8169_get_drvinfo, |
| 2012 | .get_regs_len = rtl8169_get_regs_len, |
| 2013 | .get_link = ethtool_op_get_link, |
| 2014 | .get_settings = rtl8169_get_settings, |
| 2015 | .set_settings = rtl8169_set_settings, |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 2016 | .get_msglevel = rtl8169_get_msglevel, |
| 2017 | .set_msglevel = rtl8169_set_msglevel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2018 | .get_regs = rtl8169_get_regs, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 2019 | .get_wol = rtl8169_get_wol, |
| 2020 | .set_wol = rtl8169_set_wol, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2021 | .get_strings = rtl8169_get_strings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 2022 | .get_sset_count = rtl8169_get_sset_count, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 2023 | .get_ethtool_stats = rtl8169_get_ethtool_stats, |
Richard Cochran | e1593bb | 2012-04-03 22:59:35 +0000 | [diff] [blame] | 2024 | .get_ts_info = ethtool_op_get_ts_info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2025 | }; |
| 2026 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 2027 | static void rtl8169_get_mac_version(struct rtl8169_private *tp, |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2028 | struct net_device *dev, u8 default_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2029 | { |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2030 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2031 | /* |
| 2032 | * The driver currently handles the 8168Bf and the 8168Be identically |
| 2033 | * but they can be identified more specifically through the test below |
| 2034 | * if needed: |
| 2035 | * |
| 2036 | * (RTL_R32(TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be |
Francois Romieu | 0127215 | 2007-02-20 22:58:51 +0100 | [diff] [blame] | 2037 | * |
| 2038 | * Same thing for the 8101Eb and the 8101Ec: |
| 2039 | * |
| 2040 | * (RTL_R32(TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2041 | */ |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2042 | static const struct rtl_mac_info { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2043 | u32 mask; |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2044 | u32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2045 | int mac_version; |
| 2046 | } mac_info[] = { |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 2047 | /* 8168G family. */ |
| 2048 | { 0x7cf00000, 0x4c100000, RTL_GIGA_MAC_VER_41 }, |
| 2049 | { 0x7cf00000, 0x4c000000, RTL_GIGA_MAC_VER_40 }, |
| 2050 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2051 | /* 8168F family. */ |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 2052 | { 0x7c800000, 0x48800000, RTL_GIGA_MAC_VER_38 }, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 2053 | { 0x7cf00000, 0x48100000, RTL_GIGA_MAC_VER_36 }, |
| 2054 | { 0x7cf00000, 0x48000000, RTL_GIGA_MAC_VER_35 }, |
| 2055 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2056 | /* 8168E family. */ |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2057 | { 0x7c800000, 0x2c800000, RTL_GIGA_MAC_VER_34 }, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2058 | { 0x7cf00000, 0x2c200000, RTL_GIGA_MAC_VER_33 }, |
| 2059 | { 0x7cf00000, 0x2c100000, RTL_GIGA_MAC_VER_32 }, |
| 2060 | { 0x7c800000, 0x2c000000, RTL_GIGA_MAC_VER_33 }, |
| 2061 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2062 | /* 8168D family. */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2063 | { 0x7cf00000, 0x28300000, RTL_GIGA_MAC_VER_26 }, |
| 2064 | { 0x7cf00000, 0x28100000, RTL_GIGA_MAC_VER_25 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2065 | { 0x7c800000, 0x28000000, RTL_GIGA_MAC_VER_26 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2066 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2067 | /* 8168DP family. */ |
| 2068 | { 0x7cf00000, 0x28800000, RTL_GIGA_MAC_VER_27 }, |
| 2069 | { 0x7cf00000, 0x28a00000, RTL_GIGA_MAC_VER_28 }, |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 2070 | { 0x7cf00000, 0x28b00000, RTL_GIGA_MAC_VER_31 }, |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2071 | |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2072 | /* 8168C family. */ |
Francois Romieu | 17c9929 | 2010-07-11 17:10:09 -0700 | [diff] [blame] | 2073 | { 0x7cf00000, 0x3cb00000, RTL_GIGA_MAC_VER_24 }, |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2074 | { 0x7cf00000, 0x3c900000, RTL_GIGA_MAC_VER_23 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2075 | { 0x7cf00000, 0x3c800000, RTL_GIGA_MAC_VER_18 }, |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 2076 | { 0x7c800000, 0x3c800000, RTL_GIGA_MAC_VER_24 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2077 | { 0x7cf00000, 0x3c000000, RTL_GIGA_MAC_VER_19 }, |
| 2078 | { 0x7cf00000, 0x3c200000, RTL_GIGA_MAC_VER_20 }, |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2079 | { 0x7cf00000, 0x3c300000, RTL_GIGA_MAC_VER_21 }, |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2080 | { 0x7cf00000, 0x3c400000, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 2081 | { 0x7c800000, 0x3c000000, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2082 | |
| 2083 | /* 8168B family. */ |
| 2084 | { 0x7cf00000, 0x38000000, RTL_GIGA_MAC_VER_12 }, |
| 2085 | { 0x7cf00000, 0x38500000, RTL_GIGA_MAC_VER_17 }, |
| 2086 | { 0x7c800000, 0x38000000, RTL_GIGA_MAC_VER_17 }, |
| 2087 | { 0x7c800000, 0x30000000, RTL_GIGA_MAC_VER_11 }, |
| 2088 | |
| 2089 | /* 8101 family. */ |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 2090 | { 0x7cf00000, 0x44900000, RTL_GIGA_MAC_VER_39 }, |
| 2091 | { 0x7c800000, 0x44800000, RTL_GIGA_MAC_VER_39 }, |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 2092 | { 0x7c800000, 0x44000000, RTL_GIGA_MAC_VER_37 }, |
hayeswang | 36a0e6c | 2011-03-21 01:50:30 +0000 | [diff] [blame] | 2093 | { 0x7cf00000, 0x40b00000, RTL_GIGA_MAC_VER_30 }, |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 2094 | { 0x7cf00000, 0x40a00000, RTL_GIGA_MAC_VER_30 }, |
| 2095 | { 0x7cf00000, 0x40900000, RTL_GIGA_MAC_VER_29 }, |
| 2096 | { 0x7c800000, 0x40800000, RTL_GIGA_MAC_VER_30 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2097 | { 0x7cf00000, 0x34a00000, RTL_GIGA_MAC_VER_09 }, |
| 2098 | { 0x7cf00000, 0x24a00000, RTL_GIGA_MAC_VER_09 }, |
| 2099 | { 0x7cf00000, 0x34900000, RTL_GIGA_MAC_VER_08 }, |
| 2100 | { 0x7cf00000, 0x24900000, RTL_GIGA_MAC_VER_08 }, |
| 2101 | { 0x7cf00000, 0x34800000, RTL_GIGA_MAC_VER_07 }, |
| 2102 | { 0x7cf00000, 0x24800000, RTL_GIGA_MAC_VER_07 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2103 | { 0x7cf00000, 0x34000000, RTL_GIGA_MAC_VER_13 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2104 | { 0x7cf00000, 0x34300000, RTL_GIGA_MAC_VER_10 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2105 | { 0x7cf00000, 0x34200000, RTL_GIGA_MAC_VER_16 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2106 | { 0x7c800000, 0x34800000, RTL_GIGA_MAC_VER_09 }, |
| 2107 | { 0x7c800000, 0x24800000, RTL_GIGA_MAC_VER_09 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2108 | { 0x7c800000, 0x34000000, RTL_GIGA_MAC_VER_16 }, |
| 2109 | /* FIXME: where did these entries come from ? -- FR */ |
| 2110 | { 0xfc800000, 0x38800000, RTL_GIGA_MAC_VER_15 }, |
| 2111 | { 0xfc800000, 0x30800000, RTL_GIGA_MAC_VER_14 }, |
| 2112 | |
| 2113 | /* 8110 family. */ |
| 2114 | { 0xfc800000, 0x98000000, RTL_GIGA_MAC_VER_06 }, |
| 2115 | { 0xfc800000, 0x18000000, RTL_GIGA_MAC_VER_05 }, |
| 2116 | { 0xfc800000, 0x10000000, RTL_GIGA_MAC_VER_04 }, |
| 2117 | { 0xfc800000, 0x04000000, RTL_GIGA_MAC_VER_03 }, |
| 2118 | { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 }, |
| 2119 | { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 }, |
| 2120 | |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 2121 | /* Catch-all */ |
| 2122 | { 0x00000000, 0x00000000, RTL_GIGA_MAC_NONE } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 2123 | }; |
| 2124 | const struct rtl_mac_info *p = mac_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2125 | u32 reg; |
| 2126 | |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 2127 | reg = RTL_R32(TxConfig); |
| 2128 | while ((reg & p->mask) != p->val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2129 | p++; |
| 2130 | tp->mac_version = p->mac_version; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 2131 | |
| 2132 | if (tp->mac_version == RTL_GIGA_MAC_NONE) { |
| 2133 | netif_notice(tp, probe, dev, |
| 2134 | "unknown MAC, using family default\n"); |
| 2135 | tp->mac_version = default_version; |
| 2136 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | } |
| 2138 | |
| 2139 | static void rtl8169_print_mac_version(struct rtl8169_private *tp) |
| 2140 | { |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 2141 | dprintk("mac_version = 0x%02x\n", tp->mac_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | } |
| 2143 | |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2144 | struct phy_reg { |
| 2145 | u16 reg; |
| 2146 | u16 val; |
| 2147 | }; |
| 2148 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2149 | static void rtl_writephy_batch(struct rtl8169_private *tp, |
| 2150 | const struct phy_reg *regs, int len) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2151 | { |
| 2152 | while (len-- > 0) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2153 | rtl_writephy(tp, regs->reg, regs->val); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2154 | regs++; |
| 2155 | } |
| 2156 | } |
| 2157 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2158 | #define PHY_READ 0x00000000 |
| 2159 | #define PHY_DATA_OR 0x10000000 |
| 2160 | #define PHY_DATA_AND 0x20000000 |
| 2161 | #define PHY_BJMPN 0x30000000 |
| 2162 | #define PHY_READ_EFUSE 0x40000000 |
| 2163 | #define PHY_READ_MAC_BYTE 0x50000000 |
| 2164 | #define PHY_WRITE_MAC_BYTE 0x60000000 |
| 2165 | #define PHY_CLEAR_READCOUNT 0x70000000 |
| 2166 | #define PHY_WRITE 0x80000000 |
| 2167 | #define PHY_READCOUNT_EQ_SKIP 0x90000000 |
| 2168 | #define PHY_COMP_EQ_SKIPN 0xa0000000 |
| 2169 | #define PHY_COMP_NEQ_SKIPN 0xb0000000 |
| 2170 | #define PHY_WRITE_PREVIOUS 0xc0000000 |
| 2171 | #define PHY_SKIPN 0xd0000000 |
| 2172 | #define PHY_DELAY_MS 0xe0000000 |
| 2173 | #define PHY_WRITE_ERI_WORD 0xf0000000 |
| 2174 | |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2175 | struct fw_info { |
| 2176 | u32 magic; |
| 2177 | char version[RTL_VER_SIZE]; |
| 2178 | __le32 fw_start; |
| 2179 | __le32 fw_len; |
| 2180 | u8 chksum; |
| 2181 | } __packed; |
| 2182 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2183 | #define FW_OPCODE_SIZE sizeof(typeof(*((struct rtl_fw_phy_action *)0)->code)) |
| 2184 | |
| 2185 | 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] | 2186 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2187 | const struct firmware *fw = rtl_fw->fw; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2188 | struct fw_info *fw_info = (struct fw_info *)fw->data; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2189 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
| 2190 | char *version = rtl_fw->version; |
| 2191 | bool rc = false; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2192 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2193 | if (fw->size < FW_OPCODE_SIZE) |
| 2194 | goto out; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2195 | |
| 2196 | if (!fw_info->magic) { |
| 2197 | size_t i, size, start; |
| 2198 | u8 checksum = 0; |
| 2199 | |
| 2200 | if (fw->size < sizeof(*fw_info)) |
| 2201 | goto out; |
| 2202 | |
| 2203 | for (i = 0; i < fw->size; i++) |
| 2204 | checksum += fw->data[i]; |
| 2205 | if (checksum != 0) |
| 2206 | goto out; |
| 2207 | |
| 2208 | start = le32_to_cpu(fw_info->fw_start); |
| 2209 | if (start > fw->size) |
| 2210 | goto out; |
| 2211 | |
| 2212 | size = le32_to_cpu(fw_info->fw_len); |
| 2213 | if (size > (fw->size - start) / FW_OPCODE_SIZE) |
| 2214 | goto out; |
| 2215 | |
| 2216 | memcpy(version, fw_info->version, RTL_VER_SIZE); |
| 2217 | |
| 2218 | pa->code = (__le32 *)(fw->data + start); |
| 2219 | pa->size = size; |
| 2220 | } else { |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2221 | if (fw->size % FW_OPCODE_SIZE) |
| 2222 | goto out; |
| 2223 | |
| 2224 | strlcpy(version, rtl_lookup_firmware_name(tp), RTL_VER_SIZE); |
| 2225 | |
| 2226 | pa->code = (__le32 *)fw->data; |
| 2227 | pa->size = fw->size / FW_OPCODE_SIZE; |
| 2228 | } |
| 2229 | version[RTL_VER_SIZE - 1] = 0; |
| 2230 | |
| 2231 | rc = true; |
| 2232 | out: |
| 2233 | return rc; |
| 2234 | } |
| 2235 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2236 | static bool rtl_fw_data_ok(struct rtl8169_private *tp, struct net_device *dev, |
| 2237 | struct rtl_fw_phy_action *pa) |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2238 | { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2239 | bool rc = false; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2240 | size_t index; |
| 2241 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2242 | for (index = 0; index < pa->size; index++) { |
| 2243 | u32 action = le32_to_cpu(pa->code[index]); |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2244 | u32 regno = (action & 0x0fff0000) >> 16; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2245 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2246 | switch(action & 0xf0000000) { |
| 2247 | case PHY_READ: |
| 2248 | case PHY_DATA_OR: |
| 2249 | case PHY_DATA_AND: |
| 2250 | case PHY_READ_EFUSE: |
| 2251 | case PHY_CLEAR_READCOUNT: |
| 2252 | case PHY_WRITE: |
| 2253 | case PHY_WRITE_PREVIOUS: |
| 2254 | case PHY_DELAY_MS: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2255 | break; |
| 2256 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2257 | case PHY_BJMPN: |
| 2258 | if (regno > index) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2259 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2260 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2261 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2262 | } |
| 2263 | break; |
| 2264 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2265 | if (index + 2 >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2266 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2267 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2268 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2269 | } |
| 2270 | break; |
| 2271 | case PHY_COMP_EQ_SKIPN: |
| 2272 | case PHY_COMP_NEQ_SKIPN: |
| 2273 | case PHY_SKIPN: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2274 | if (index + 1 + regno >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2275 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2276 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2277 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2278 | } |
| 2279 | break; |
| 2280 | |
| 2281 | case PHY_READ_MAC_BYTE: |
| 2282 | case PHY_WRITE_MAC_BYTE: |
| 2283 | case PHY_WRITE_ERI_WORD: |
| 2284 | default: |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2285 | netif_err(tp, ifup, tp->dev, |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2286 | "Invalid action 0x%08x\n", action); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2287 | goto out; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2288 | } |
| 2289 | } |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2290 | rc = true; |
| 2291 | out: |
| 2292 | return rc; |
| 2293 | } |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2294 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2295 | static int rtl_check_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2296 | { |
| 2297 | struct net_device *dev = tp->dev; |
| 2298 | int rc = -EINVAL; |
| 2299 | |
| 2300 | if (!rtl_fw_format_ok(tp, rtl_fw)) { |
| 2301 | netif_err(tp, ifup, dev, "invalid firwmare\n"); |
| 2302 | goto out; |
| 2303 | } |
| 2304 | |
| 2305 | if (rtl_fw_data_ok(tp, dev, &rtl_fw->phy_action)) |
| 2306 | rc = 0; |
| 2307 | out: |
| 2308 | return rc; |
| 2309 | } |
| 2310 | |
| 2311 | static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2312 | { |
| 2313 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
| 2314 | u32 predata, count; |
| 2315 | size_t index; |
| 2316 | |
| 2317 | predata = count = 0; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2318 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2319 | for (index = 0; index < pa->size; ) { |
| 2320 | u32 action = le32_to_cpu(pa->code[index]); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2321 | u32 data = action & 0x0000ffff; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2322 | u32 regno = (action & 0x0fff0000) >> 16; |
| 2323 | |
| 2324 | if (!action) |
| 2325 | break; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2326 | |
| 2327 | switch(action & 0xf0000000) { |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2328 | case PHY_READ: |
| 2329 | predata = rtl_readphy(tp, regno); |
| 2330 | count++; |
| 2331 | index++; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2332 | break; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2333 | case PHY_DATA_OR: |
| 2334 | predata |= data; |
| 2335 | index++; |
| 2336 | break; |
| 2337 | case PHY_DATA_AND: |
| 2338 | predata &= data; |
| 2339 | index++; |
| 2340 | break; |
| 2341 | case PHY_BJMPN: |
| 2342 | index -= regno; |
| 2343 | break; |
| 2344 | case PHY_READ_EFUSE: |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 2345 | predata = rtl8168d_efuse_read(tp, regno); |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2346 | index++; |
| 2347 | break; |
| 2348 | case PHY_CLEAR_READCOUNT: |
| 2349 | count = 0; |
| 2350 | index++; |
| 2351 | break; |
| 2352 | case PHY_WRITE: |
| 2353 | rtl_writephy(tp, regno, data); |
| 2354 | index++; |
| 2355 | break; |
| 2356 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2357 | index += (count == data) ? 2 : 1; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2358 | break; |
| 2359 | case PHY_COMP_EQ_SKIPN: |
| 2360 | if (predata == data) |
| 2361 | index += regno; |
| 2362 | index++; |
| 2363 | break; |
| 2364 | case PHY_COMP_NEQ_SKIPN: |
| 2365 | if (predata != data) |
| 2366 | index += regno; |
| 2367 | index++; |
| 2368 | break; |
| 2369 | case PHY_WRITE_PREVIOUS: |
| 2370 | rtl_writephy(tp, regno, predata); |
| 2371 | index++; |
| 2372 | break; |
| 2373 | case PHY_SKIPN: |
| 2374 | index += regno + 1; |
| 2375 | break; |
| 2376 | case PHY_DELAY_MS: |
| 2377 | mdelay(data); |
| 2378 | index++; |
| 2379 | break; |
| 2380 | |
| 2381 | case PHY_READ_MAC_BYTE: |
| 2382 | case PHY_WRITE_MAC_BYTE: |
| 2383 | case PHY_WRITE_ERI_WORD: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2384 | default: |
| 2385 | BUG(); |
| 2386 | } |
| 2387 | } |
| 2388 | } |
| 2389 | |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2390 | static void rtl_release_firmware(struct rtl8169_private *tp) |
| 2391 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2392 | if (!IS_ERR_OR_NULL(tp->rtl_fw)) { |
| 2393 | release_firmware(tp->rtl_fw->fw); |
| 2394 | kfree(tp->rtl_fw); |
| 2395 | } |
| 2396 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2397 | } |
| 2398 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2399 | static void rtl_apply_firmware(struct rtl8169_private *tp) |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2400 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2401 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2402 | |
| 2403 | /* TODO: release firmware once rtl_phy_write_fw signals failures. */ |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2404 | if (!IS_ERR_OR_NULL(rtl_fw)) |
| 2405 | rtl_phy_write_fw(tp, rtl_fw); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2406 | } |
| 2407 | |
| 2408 | static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val) |
| 2409 | { |
| 2410 | if (rtl_readphy(tp, reg) != val) |
| 2411 | netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n"); |
| 2412 | else |
| 2413 | rtl_apply_firmware(tp); |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2414 | } |
| 2415 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2416 | static void rtl8169s_hw_phy_config(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2417 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2418 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2419 | { 0x1f, 0x0001 }, |
| 2420 | { 0x06, 0x006e }, |
| 2421 | { 0x08, 0x0708 }, |
| 2422 | { 0x15, 0x4000 }, |
| 2423 | { 0x18, 0x65c7 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2424 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2425 | { 0x1f, 0x0001 }, |
| 2426 | { 0x03, 0x00a1 }, |
| 2427 | { 0x02, 0x0008 }, |
| 2428 | { 0x01, 0x0120 }, |
| 2429 | { 0x00, 0x1000 }, |
| 2430 | { 0x04, 0x0800 }, |
| 2431 | { 0x04, 0x0000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2432 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2433 | { 0x03, 0xff41 }, |
| 2434 | { 0x02, 0xdf60 }, |
| 2435 | { 0x01, 0x0140 }, |
| 2436 | { 0x00, 0x0077 }, |
| 2437 | { 0x04, 0x7800 }, |
| 2438 | { 0x04, 0x7000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2439 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2440 | { 0x03, 0x802f }, |
| 2441 | { 0x02, 0x4f02 }, |
| 2442 | { 0x01, 0x0409 }, |
| 2443 | { 0x00, 0xf0f9 }, |
| 2444 | { 0x04, 0x9800 }, |
| 2445 | { 0x04, 0x9000 }, |
| 2446 | |
| 2447 | { 0x03, 0xdf01 }, |
| 2448 | { 0x02, 0xdf20 }, |
| 2449 | { 0x01, 0xff95 }, |
| 2450 | { 0x00, 0xba00 }, |
| 2451 | { 0x04, 0xa800 }, |
| 2452 | { 0x04, 0xa000 }, |
| 2453 | |
| 2454 | { 0x03, 0xff41 }, |
| 2455 | { 0x02, 0xdf20 }, |
| 2456 | { 0x01, 0x0140 }, |
| 2457 | { 0x00, 0x00bb }, |
| 2458 | { 0x04, 0xb800 }, |
| 2459 | { 0x04, 0xb000 }, |
| 2460 | |
| 2461 | { 0x03, 0xdf41 }, |
| 2462 | { 0x02, 0xdc60 }, |
| 2463 | { 0x01, 0x6340 }, |
| 2464 | { 0x00, 0x007d }, |
| 2465 | { 0x04, 0xd800 }, |
| 2466 | { 0x04, 0xd000 }, |
| 2467 | |
| 2468 | { 0x03, 0xdf01 }, |
| 2469 | { 0x02, 0xdf20 }, |
| 2470 | { 0x01, 0x100a }, |
| 2471 | { 0x00, 0xa0ff }, |
| 2472 | { 0x04, 0xf800 }, |
| 2473 | { 0x04, 0xf000 }, |
| 2474 | |
| 2475 | { 0x1f, 0x0000 }, |
| 2476 | { 0x0b, 0x0000 }, |
| 2477 | { 0x00, 0x9200 } |
| 2478 | }; |
| 2479 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2480 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2481 | } |
| 2482 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2483 | static void rtl8169sb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2484 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2485 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a441d7b | 2007-08-17 18:26:35 +0200 | [diff] [blame] | 2486 | { 0x1f, 0x0002 }, |
| 2487 | { 0x01, 0x90d0 }, |
| 2488 | { 0x1f, 0x0000 } |
| 2489 | }; |
| 2490 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2491 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2492 | } |
| 2493 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2494 | static void rtl8169scd_hw_phy_config_quirk(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2495 | { |
| 2496 | struct pci_dev *pdev = tp->pci_dev; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2497 | |
Sergei Shtylyov | ccbae55 | 2011-07-22 05:37:24 +0000 | [diff] [blame] | 2498 | if ((pdev->subsystem_vendor != PCI_VENDOR_ID_GIGABYTE) || |
| 2499 | (pdev->subsystem_device != 0xe000)) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2500 | return; |
| 2501 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2502 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2503 | rtl_writephy(tp, 0x10, 0xf01b); |
| 2504 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2505 | } |
| 2506 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2507 | static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2508 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2509 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2510 | { 0x1f, 0x0001 }, |
| 2511 | { 0x04, 0x0000 }, |
| 2512 | { 0x03, 0x00a1 }, |
| 2513 | { 0x02, 0x0008 }, |
| 2514 | { 0x01, 0x0120 }, |
| 2515 | { 0x00, 0x1000 }, |
| 2516 | { 0x04, 0x0800 }, |
| 2517 | { 0x04, 0x9000 }, |
| 2518 | { 0x03, 0x802f }, |
| 2519 | { 0x02, 0x4f02 }, |
| 2520 | { 0x01, 0x0409 }, |
| 2521 | { 0x00, 0xf099 }, |
| 2522 | { 0x04, 0x9800 }, |
| 2523 | { 0x04, 0xa000 }, |
| 2524 | { 0x03, 0xdf01 }, |
| 2525 | { 0x02, 0xdf20 }, |
| 2526 | { 0x01, 0xff95 }, |
| 2527 | { 0x00, 0xba00 }, |
| 2528 | { 0x04, 0xa800 }, |
| 2529 | { 0x04, 0xf000 }, |
| 2530 | { 0x03, 0xdf01 }, |
| 2531 | { 0x02, 0xdf20 }, |
| 2532 | { 0x01, 0x101a }, |
| 2533 | { 0x00, 0xa0ff }, |
| 2534 | { 0x04, 0xf800 }, |
| 2535 | { 0x04, 0x0000 }, |
| 2536 | { 0x1f, 0x0000 }, |
| 2537 | |
| 2538 | { 0x1f, 0x0001 }, |
| 2539 | { 0x10, 0xf41b }, |
| 2540 | { 0x14, 0xfb54 }, |
| 2541 | { 0x18, 0xf5c7 }, |
| 2542 | { 0x1f, 0x0000 }, |
| 2543 | |
| 2544 | { 0x1f, 0x0001 }, |
| 2545 | { 0x17, 0x0cc0 }, |
| 2546 | { 0x1f, 0x0000 } |
| 2547 | }; |
| 2548 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2549 | 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] | 2550 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2551 | rtl8169scd_hw_phy_config_quirk(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2552 | } |
| 2553 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2554 | static void rtl8169sce_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2555 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2556 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2557 | { 0x1f, 0x0001 }, |
| 2558 | { 0x04, 0x0000 }, |
| 2559 | { 0x03, 0x00a1 }, |
| 2560 | { 0x02, 0x0008 }, |
| 2561 | { 0x01, 0x0120 }, |
| 2562 | { 0x00, 0x1000 }, |
| 2563 | { 0x04, 0x0800 }, |
| 2564 | { 0x04, 0x9000 }, |
| 2565 | { 0x03, 0x802f }, |
| 2566 | { 0x02, 0x4f02 }, |
| 2567 | { 0x01, 0x0409 }, |
| 2568 | { 0x00, 0xf099 }, |
| 2569 | { 0x04, 0x9800 }, |
| 2570 | { 0x04, 0xa000 }, |
| 2571 | { 0x03, 0xdf01 }, |
| 2572 | { 0x02, 0xdf20 }, |
| 2573 | { 0x01, 0xff95 }, |
| 2574 | { 0x00, 0xba00 }, |
| 2575 | { 0x04, 0xa800 }, |
| 2576 | { 0x04, 0xf000 }, |
| 2577 | { 0x03, 0xdf01 }, |
| 2578 | { 0x02, 0xdf20 }, |
| 2579 | { 0x01, 0x101a }, |
| 2580 | { 0x00, 0xa0ff }, |
| 2581 | { 0x04, 0xf800 }, |
| 2582 | { 0x04, 0x0000 }, |
| 2583 | { 0x1f, 0x0000 }, |
| 2584 | |
| 2585 | { 0x1f, 0x0001 }, |
| 2586 | { 0x0b, 0x8480 }, |
| 2587 | { 0x1f, 0x0000 }, |
| 2588 | |
| 2589 | { 0x1f, 0x0001 }, |
| 2590 | { 0x18, 0x67c7 }, |
| 2591 | { 0x04, 0x2000 }, |
| 2592 | { 0x03, 0x002f }, |
| 2593 | { 0x02, 0x4360 }, |
| 2594 | { 0x01, 0x0109 }, |
| 2595 | { 0x00, 0x3022 }, |
| 2596 | { 0x04, 0x2800 }, |
| 2597 | { 0x1f, 0x0000 }, |
| 2598 | |
| 2599 | { 0x1f, 0x0001 }, |
| 2600 | { 0x17, 0x0cc0 }, |
| 2601 | { 0x1f, 0x0000 } |
| 2602 | }; |
| 2603 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2604 | 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] | 2605 | } |
| 2606 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2607 | static void rtl8168bb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2608 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2609 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2610 | { 0x10, 0xf41b }, |
| 2611 | { 0x1f, 0x0000 } |
| 2612 | }; |
| 2613 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2614 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2615 | rtl_patchphy(tp, 0x16, 1 << 0); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2616 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2617 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2618 | } |
| 2619 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2620 | static void rtl8168bef_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2621 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2622 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2623 | { 0x1f, 0x0001 }, |
| 2624 | { 0x10, 0xf41b }, |
| 2625 | { 0x1f, 0x0000 } |
| 2626 | }; |
| 2627 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2628 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2629 | } |
| 2630 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2631 | static void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2632 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2633 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2634 | { 0x1f, 0x0000 }, |
| 2635 | { 0x1d, 0x0f00 }, |
| 2636 | { 0x1f, 0x0002 }, |
| 2637 | { 0x0c, 0x1ec8 }, |
| 2638 | { 0x1f, 0x0000 } |
| 2639 | }; |
| 2640 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2641 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2642 | } |
| 2643 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2644 | static void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2645 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2646 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2647 | { 0x1f, 0x0001 }, |
| 2648 | { 0x1d, 0x3d98 }, |
| 2649 | { 0x1f, 0x0000 } |
| 2650 | }; |
| 2651 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2652 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2653 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2654 | rtl_patchphy(tp, 0x0d, 1 << 5); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2655 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2656 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2657 | } |
| 2658 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2659 | static void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2660 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2661 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a3f8067 | 2007-10-18 14:35:11 +0200 | [diff] [blame] | 2662 | { 0x1f, 0x0001 }, |
| 2663 | { 0x12, 0x2300 }, |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2664 | { 0x1f, 0x0002 }, |
| 2665 | { 0x00, 0x88d4 }, |
| 2666 | { 0x01, 0x82b1 }, |
| 2667 | { 0x03, 0x7002 }, |
| 2668 | { 0x08, 0x9e30 }, |
| 2669 | { 0x09, 0x01f0 }, |
| 2670 | { 0x0a, 0x5500 }, |
| 2671 | { 0x0c, 0x00c8 }, |
| 2672 | { 0x1f, 0x0003 }, |
| 2673 | { 0x12, 0xc096 }, |
| 2674 | { 0x16, 0x000a }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2675 | { 0x1f, 0x0000 }, |
| 2676 | { 0x1f, 0x0000 }, |
| 2677 | { 0x09, 0x2000 }, |
| 2678 | { 0x09, 0x0000 } |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2679 | }; |
| 2680 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2681 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2682 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2683 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2684 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2685 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2686 | } |
| 2687 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2688 | static void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2689 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2690 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2691 | { 0x1f, 0x0001 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2692 | { 0x12, 0x2300 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2693 | { 0x03, 0x802f }, |
| 2694 | { 0x02, 0x4f02 }, |
| 2695 | { 0x01, 0x0409 }, |
| 2696 | { 0x00, 0xf099 }, |
| 2697 | { 0x04, 0x9800 }, |
| 2698 | { 0x04, 0x9000 }, |
| 2699 | { 0x1d, 0x3d98 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2700 | { 0x1f, 0x0002 }, |
| 2701 | { 0x0c, 0x7eb8 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2702 | { 0x06, 0x0761 }, |
| 2703 | { 0x1f, 0x0003 }, |
| 2704 | { 0x16, 0x0f0a }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2705 | { 0x1f, 0x0000 } |
| 2706 | }; |
| 2707 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2708 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2709 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2710 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 2711 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2712 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2713 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2714 | } |
| 2715 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2716 | static void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2717 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2718 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2719 | { 0x1f, 0x0001 }, |
| 2720 | { 0x12, 0x2300 }, |
| 2721 | { 0x1d, 0x3d98 }, |
| 2722 | { 0x1f, 0x0002 }, |
| 2723 | { 0x0c, 0x7eb8 }, |
| 2724 | { 0x06, 0x5461 }, |
| 2725 | { 0x1f, 0x0003 }, |
| 2726 | { 0x16, 0x0f0a }, |
| 2727 | { 0x1f, 0x0000 } |
| 2728 | }; |
| 2729 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2730 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2731 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2732 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 2733 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2734 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2735 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2736 | } |
| 2737 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2738 | static void rtl8168c_4_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2739 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2740 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2741 | } |
| 2742 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2743 | static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2744 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2745 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2746 | /* Channel Estimation */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2747 | { 0x1f, 0x0001 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2748 | { 0x06, 0x4064 }, |
| 2749 | { 0x07, 0x2863 }, |
| 2750 | { 0x08, 0x059c }, |
| 2751 | { 0x09, 0x26b4 }, |
| 2752 | { 0x0a, 0x6a19 }, |
| 2753 | { 0x0b, 0xdcc8 }, |
| 2754 | { 0x10, 0xf06d }, |
| 2755 | { 0x14, 0x7f68 }, |
| 2756 | { 0x18, 0x7fd9 }, |
| 2757 | { 0x1c, 0xf0ff }, |
| 2758 | { 0x1d, 0x3d9c }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2759 | { 0x1f, 0x0003 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2760 | { 0x12, 0xf49f }, |
| 2761 | { 0x13, 0x070b }, |
| 2762 | { 0x1a, 0x05ad }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2763 | { 0x14, 0x94c0 }, |
| 2764 | |
| 2765 | /* |
| 2766 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2767 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2768 | */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2769 | { 0x1f, 0x0002 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2770 | { 0x06, 0x5561 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2771 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2772 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2773 | { 0x06, 0x5561 }, |
| 2774 | |
| 2775 | /* |
| 2776 | * Can not link to 1Gbps with bad cable |
| 2777 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 2778 | */ |
| 2779 | { 0x1f, 0x0001 }, |
| 2780 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2781 | |
| 2782 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2783 | { 0x0d, 0xf880 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2784 | }; |
| 2785 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2786 | 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] | 2787 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2788 | /* |
| 2789 | * Rx Error Issue |
| 2790 | * Fine Tune Switching regulator parameter |
| 2791 | */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2792 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2793 | rtl_w1w0_phy(tp, 0x0b, 0x0010, 0x00ef); |
| 2794 | rtl_w1w0_phy(tp, 0x0c, 0xa200, 0x5d00); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2795 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 2796 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2797 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2798 | { 0x1f, 0x0002 }, |
| 2799 | { 0x05, 0x669a }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2800 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2801 | { 0x05, 0x8330 }, |
| 2802 | { 0x06, 0x669a }, |
| 2803 | { 0x1f, 0x0002 } |
| 2804 | }; |
| 2805 | int val; |
| 2806 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2807 | 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] | 2808 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2809 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2810 | |
| 2811 | if ((val & 0x00ff) != 0x006c) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2812 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2813 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 2814 | 0x0069, 0x006a, 0x006b, 0x006c |
| 2815 | }; |
| 2816 | int i; |
| 2817 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2818 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2819 | |
| 2820 | val &= 0xff00; |
| 2821 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2822 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2823 | } |
| 2824 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2825 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2826 | { 0x1f, 0x0002 }, |
| 2827 | { 0x05, 0x6662 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2828 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2829 | { 0x05, 0x8330 }, |
| 2830 | { 0x06, 0x6662 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2831 | }; |
| 2832 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2833 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2834 | } |
| 2835 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2836 | /* RSET couple improve */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2837 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2838 | rtl_patchphy(tp, 0x0d, 0x0300); |
| 2839 | rtl_patchphy(tp, 0x0f, 0x0010); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2840 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2841 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2842 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2843 | rtl_w1w0_phy(tp, 0x02, 0x0100, 0x0600); |
| 2844 | rtl_w1w0_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2845 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2846 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2847 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2848 | |
| 2849 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2850 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2851 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2852 | } |
| 2853 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2854 | static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [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 */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2858 | { 0x1f, 0x0001 }, |
| 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 }, |
| 2870 | { 0x1f, 0x0003 }, |
| 2871 | { 0x12, 0xf49f }, |
| 2872 | { 0x13, 0x070b }, |
| 2873 | { 0x1a, 0x05ad }, |
| 2874 | { 0x14, 0x94c0 }, |
| 2875 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 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 | */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2880 | { 0x1f, 0x0002 }, |
| 2881 | { 0x06, 0x5561 }, |
| 2882 | { 0x1f, 0x0005 }, |
| 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 } |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [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)); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2898 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 2899 | if (rtl8168d_efuse_read(tp, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2900 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2901 | { 0x1f, 0x0002 }, |
| 2902 | { 0x05, 0x669a }, |
| 2903 | { 0x1f, 0x0005 }, |
| 2904 | { 0x05, 0x8330 }, |
| 2905 | { 0x06, 0x669a }, |
| 2906 | |
| 2907 | { 0x1f, 0x0002 } |
| 2908 | }; |
| 2909 | int val; |
| 2910 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2911 | 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] | 2912 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2913 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2914 | if ((val & 0x00ff) != 0x006c) { |
Joe Perches | b6bc765 | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 2915 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2916 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 2917 | 0x0069, 0x006a, 0x006b, 0x006c |
| 2918 | }; |
| 2919 | int i; |
| 2920 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2921 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2922 | |
| 2923 | val &= 0xff00; |
| 2924 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2925 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2926 | } |
| 2927 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2928 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2929 | { 0x1f, 0x0002 }, |
| 2930 | { 0x05, 0x2642 }, |
| 2931 | { 0x1f, 0x0005 }, |
| 2932 | { 0x05, 0x8330 }, |
| 2933 | { 0x06, 0x2642 } |
| 2934 | }; |
| 2935 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2936 | 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] | 2937 | } |
| 2938 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2939 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2940 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2941 | rtl_w1w0_phy(tp, 0x02, 0x0100, 0x0600); |
| 2942 | rtl_w1w0_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2943 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2944 | /* Switching regulator Slew rate */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2945 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2946 | rtl_patchphy(tp, 0x0f, 0x0017); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2947 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2948 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2949 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2950 | |
| 2951 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2952 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2953 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2954 | } |
| 2955 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2956 | static void rtl8168d_3_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2957 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2958 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2959 | { 0x1f, 0x0002 }, |
| 2960 | { 0x10, 0x0008 }, |
| 2961 | { 0x0d, 0x006c }, |
| 2962 | |
| 2963 | { 0x1f, 0x0000 }, |
| 2964 | { 0x0d, 0xf880 }, |
| 2965 | |
| 2966 | { 0x1f, 0x0001 }, |
| 2967 | { 0x17, 0x0cc0 }, |
| 2968 | |
| 2969 | { 0x1f, 0x0001 }, |
| 2970 | { 0x0b, 0xa4d8 }, |
| 2971 | { 0x09, 0x281c }, |
| 2972 | { 0x07, 0x2883 }, |
| 2973 | { 0x0a, 0x6b35 }, |
| 2974 | { 0x1d, 0x3da4 }, |
| 2975 | { 0x1c, 0xeffd }, |
| 2976 | { 0x14, 0x7f52 }, |
| 2977 | { 0x18, 0x7fc6 }, |
| 2978 | { 0x08, 0x0601 }, |
| 2979 | { 0x06, 0x4063 }, |
| 2980 | { 0x10, 0xf074 }, |
| 2981 | { 0x1f, 0x0003 }, |
| 2982 | { 0x13, 0x0789 }, |
| 2983 | { 0x12, 0xf4bd }, |
| 2984 | { 0x1a, 0x04fd }, |
| 2985 | { 0x14, 0x84b0 }, |
| 2986 | { 0x1f, 0x0000 }, |
| 2987 | { 0x00, 0x9200 }, |
| 2988 | |
| 2989 | { 0x1f, 0x0005 }, |
| 2990 | { 0x01, 0x0340 }, |
| 2991 | { 0x1f, 0x0001 }, |
| 2992 | { 0x04, 0x4000 }, |
| 2993 | { 0x03, 0x1d21 }, |
| 2994 | { 0x02, 0x0c32 }, |
| 2995 | { 0x01, 0x0200 }, |
| 2996 | { 0x00, 0x5554 }, |
| 2997 | { 0x04, 0x4800 }, |
| 2998 | { 0x04, 0x4000 }, |
| 2999 | { 0x04, 0xf000 }, |
| 3000 | { 0x03, 0xdf01 }, |
| 3001 | { 0x02, 0xdf20 }, |
| 3002 | { 0x01, 0x101a }, |
| 3003 | { 0x00, 0xa0ff }, |
| 3004 | { 0x04, 0xf800 }, |
| 3005 | { 0x04, 0xf000 }, |
| 3006 | { 0x1f, 0x0000 }, |
| 3007 | |
| 3008 | { 0x1f, 0x0007 }, |
| 3009 | { 0x1e, 0x0023 }, |
| 3010 | { 0x16, 0x0000 }, |
| 3011 | { 0x1f, 0x0000 } |
| 3012 | }; |
| 3013 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3014 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3015 | } |
| 3016 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3017 | static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp) |
| 3018 | { |
| 3019 | static const struct phy_reg phy_reg_init[] = { |
| 3020 | { 0x1f, 0x0001 }, |
| 3021 | { 0x17, 0x0cc0 }, |
| 3022 | |
| 3023 | { 0x1f, 0x0007 }, |
| 3024 | { 0x1e, 0x002d }, |
| 3025 | { 0x18, 0x0040 }, |
| 3026 | { 0x1f, 0x0000 } |
| 3027 | }; |
| 3028 | |
| 3029 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3030 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 3031 | } |
| 3032 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3033 | static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3034 | { |
| 3035 | static const struct phy_reg phy_reg_init[] = { |
| 3036 | /* Enable Delay cap */ |
| 3037 | { 0x1f, 0x0005 }, |
| 3038 | { 0x05, 0x8b80 }, |
| 3039 | { 0x06, 0xc896 }, |
| 3040 | { 0x1f, 0x0000 }, |
| 3041 | |
| 3042 | /* Channel estimation fine tune */ |
| 3043 | { 0x1f, 0x0001 }, |
| 3044 | { 0x0b, 0x6c20 }, |
| 3045 | { 0x07, 0x2872 }, |
| 3046 | { 0x1c, 0xefff }, |
| 3047 | { 0x1f, 0x0003 }, |
| 3048 | { 0x14, 0x6420 }, |
| 3049 | { 0x1f, 0x0000 }, |
| 3050 | |
| 3051 | /* Update PFM & 10M TX idle timer */ |
| 3052 | { 0x1f, 0x0007 }, |
| 3053 | { 0x1e, 0x002f }, |
| 3054 | { 0x15, 0x1919 }, |
| 3055 | { 0x1f, 0x0000 }, |
| 3056 | |
| 3057 | { 0x1f, 0x0007 }, |
| 3058 | { 0x1e, 0x00ac }, |
| 3059 | { 0x18, 0x0006 }, |
| 3060 | { 0x1f, 0x0000 } |
| 3061 | }; |
| 3062 | |
Francois Romieu | 15ecd03 | 2011-04-27 13:52:22 -0700 | [diff] [blame] | 3063 | rtl_apply_firmware(tp); |
| 3064 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3065 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3066 | |
| 3067 | /* DCO enable for 10M IDLE Power */ |
| 3068 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3069 | rtl_writephy(tp, 0x1e, 0x0023); |
| 3070 | rtl_w1w0_phy(tp, 0x17, 0x0006, 0x0000); |
| 3071 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3072 | |
| 3073 | /* For impedance matching */ |
| 3074 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3075 | rtl_w1w0_phy(tp, 0x08, 0x8000, 0x7f00); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3076 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3077 | |
| 3078 | /* PHY auto speed down */ |
| 3079 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3080 | rtl_writephy(tp, 0x1e, 0x002d); |
| 3081 | rtl_w1w0_phy(tp, 0x18, 0x0050, 0x0000); |
| 3082 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3083 | rtl_w1w0_phy(tp, 0x14, 0x8000, 0x0000); |
| 3084 | |
| 3085 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3086 | rtl_writephy(tp, 0x05, 0x8b86); |
| 3087 | rtl_w1w0_phy(tp, 0x06, 0x0001, 0x0000); |
| 3088 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3089 | |
| 3090 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3091 | rtl_writephy(tp, 0x05, 0x8b85); |
| 3092 | rtl_w1w0_phy(tp, 0x06, 0x0000, 0x2000); |
| 3093 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3094 | rtl_writephy(tp, 0x1e, 0x0020); |
| 3095 | rtl_w1w0_phy(tp, 0x15, 0x0000, 0x1100); |
| 3096 | rtl_writephy(tp, 0x1f, 0x0006); |
| 3097 | rtl_writephy(tp, 0x00, 0x5a00); |
| 3098 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3099 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3100 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3101 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3102 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3103 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3104 | } |
| 3105 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3106 | static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp) |
| 3107 | { |
| 3108 | static const struct phy_reg phy_reg_init[] = { |
| 3109 | /* Enable Delay cap */ |
| 3110 | { 0x1f, 0x0004 }, |
| 3111 | { 0x1f, 0x0007 }, |
| 3112 | { 0x1e, 0x00ac }, |
| 3113 | { 0x18, 0x0006 }, |
| 3114 | { 0x1f, 0x0002 }, |
| 3115 | { 0x1f, 0x0000 }, |
| 3116 | { 0x1f, 0x0000 }, |
| 3117 | |
| 3118 | /* Channel estimation fine tune */ |
| 3119 | { 0x1f, 0x0003 }, |
| 3120 | { 0x09, 0xa20f }, |
| 3121 | { 0x1f, 0x0000 }, |
| 3122 | { 0x1f, 0x0000 }, |
| 3123 | |
| 3124 | /* Green Setting */ |
| 3125 | { 0x1f, 0x0005 }, |
| 3126 | { 0x05, 0x8b5b }, |
| 3127 | { 0x06, 0x9222 }, |
| 3128 | { 0x05, 0x8b6d }, |
| 3129 | { 0x06, 0x8000 }, |
| 3130 | { 0x05, 0x8b76 }, |
| 3131 | { 0x06, 0x8000 }, |
| 3132 | { 0x1f, 0x0000 } |
| 3133 | }; |
| 3134 | |
| 3135 | rtl_apply_firmware(tp); |
| 3136 | |
| 3137 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3138 | |
| 3139 | /* For 4-corner performance improve */ |
| 3140 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3141 | rtl_writephy(tp, 0x05, 0x8b80); |
| 3142 | rtl_w1w0_phy(tp, 0x17, 0x0006, 0x0000); |
| 3143 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3144 | |
| 3145 | /* PHY auto speed down */ |
| 3146 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3147 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3148 | rtl_writephy(tp, 0x1e, 0x002d); |
| 3149 | rtl_w1w0_phy(tp, 0x18, 0x0010, 0x0000); |
| 3150 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3151 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3152 | rtl_w1w0_phy(tp, 0x14, 0x8000, 0x0000); |
| 3153 | |
| 3154 | /* improve 10M EEE waveform */ |
| 3155 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3156 | rtl_writephy(tp, 0x05, 0x8b86); |
| 3157 | rtl_w1w0_phy(tp, 0x06, 0x0001, 0x0000); |
| 3158 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3159 | |
| 3160 | /* Improve 2-pair detection performance */ |
| 3161 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3162 | rtl_writephy(tp, 0x05, 0x8b85); |
| 3163 | rtl_w1w0_phy(tp, 0x06, 0x4000, 0x0000); |
| 3164 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3165 | |
| 3166 | /* EEE setting */ |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3167 | rtl_w1w0_eri(tp, 0x1b0, ERIAR_MASK_1111, 0x0000, 0x0003, ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3168 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3169 | rtl_writephy(tp, 0x05, 0x8b85); |
| 3170 | rtl_w1w0_phy(tp, 0x06, 0x0000, 0x2000); |
| 3171 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3172 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3173 | rtl_writephy(tp, 0x1e, 0x0020); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 3174 | rtl_w1w0_phy(tp, 0x15, 0x0000, 0x0100); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3175 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3176 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3177 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3178 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3179 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3180 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3181 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3182 | |
| 3183 | /* Green feature */ |
| 3184 | rtl_writephy(tp, 0x1f, 0x0003); |
| 3185 | rtl_w1w0_phy(tp, 0x19, 0x0000, 0x0001); |
| 3186 | rtl_w1w0_phy(tp, 0x10, 0x0000, 0x0400); |
| 3187 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3188 | } |
| 3189 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3190 | static void rtl8168f_hw_phy_config(struct rtl8169_private *tp) |
| 3191 | { |
| 3192 | /* For 4-corner performance improve */ |
| 3193 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3194 | rtl_writephy(tp, 0x05, 0x8b80); |
| 3195 | rtl_w1w0_phy(tp, 0x06, 0x0006, 0x0000); |
| 3196 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3197 | |
| 3198 | /* PHY auto speed down */ |
| 3199 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3200 | rtl_writephy(tp, 0x1e, 0x002d); |
| 3201 | rtl_w1w0_phy(tp, 0x18, 0x0010, 0x0000); |
| 3202 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3203 | rtl_w1w0_phy(tp, 0x14, 0x8000, 0x0000); |
| 3204 | |
| 3205 | /* Improve 10M EEE waveform */ |
| 3206 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3207 | rtl_writephy(tp, 0x05, 0x8b86); |
| 3208 | rtl_w1w0_phy(tp, 0x06, 0x0001, 0x0000); |
| 3209 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3210 | } |
| 3211 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3212 | static void rtl8168f_1_hw_phy_config(struct rtl8169_private *tp) |
| 3213 | { |
| 3214 | static const struct phy_reg phy_reg_init[] = { |
| 3215 | /* Channel estimation fine tune */ |
| 3216 | { 0x1f, 0x0003 }, |
| 3217 | { 0x09, 0xa20f }, |
| 3218 | { 0x1f, 0x0000 }, |
| 3219 | |
| 3220 | /* Modify green table for giga & fnet */ |
| 3221 | { 0x1f, 0x0005 }, |
| 3222 | { 0x05, 0x8b55 }, |
| 3223 | { 0x06, 0x0000 }, |
| 3224 | { 0x05, 0x8b5e }, |
| 3225 | { 0x06, 0x0000 }, |
| 3226 | { 0x05, 0x8b67 }, |
| 3227 | { 0x06, 0x0000 }, |
| 3228 | { 0x05, 0x8b70 }, |
| 3229 | { 0x06, 0x0000 }, |
| 3230 | { 0x1f, 0x0000 }, |
| 3231 | { 0x1f, 0x0007 }, |
| 3232 | { 0x1e, 0x0078 }, |
| 3233 | { 0x17, 0x0000 }, |
| 3234 | { 0x19, 0x00fb }, |
| 3235 | { 0x1f, 0x0000 }, |
| 3236 | |
| 3237 | /* Modify green table for 10M */ |
| 3238 | { 0x1f, 0x0005 }, |
| 3239 | { 0x05, 0x8b79 }, |
| 3240 | { 0x06, 0xaa00 }, |
| 3241 | { 0x1f, 0x0000 }, |
| 3242 | |
| 3243 | /* Disable hiimpedance detection (RTCT) */ |
| 3244 | { 0x1f, 0x0003 }, |
| 3245 | { 0x01, 0x328a }, |
| 3246 | { 0x1f, 0x0000 } |
| 3247 | }; |
| 3248 | |
| 3249 | rtl_apply_firmware(tp); |
| 3250 | |
| 3251 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3252 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3253 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3254 | |
| 3255 | /* Improve 2-pair detection performance */ |
| 3256 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3257 | rtl_writephy(tp, 0x05, 0x8b85); |
| 3258 | rtl_w1w0_phy(tp, 0x06, 0x4000, 0x0000); |
| 3259 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3260 | } |
| 3261 | |
| 3262 | static void rtl8168f_2_hw_phy_config(struct rtl8169_private *tp) |
| 3263 | { |
| 3264 | rtl_apply_firmware(tp); |
| 3265 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 3266 | rtl8168f_hw_phy_config(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3267 | } |
| 3268 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3269 | static void rtl8411_hw_phy_config(struct rtl8169_private *tp) |
| 3270 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3271 | static const struct phy_reg phy_reg_init[] = { |
| 3272 | /* Channel estimation fine tune */ |
| 3273 | { 0x1f, 0x0003 }, |
| 3274 | { 0x09, 0xa20f }, |
| 3275 | { 0x1f, 0x0000 }, |
| 3276 | |
| 3277 | /* Modify green table for giga & fnet */ |
| 3278 | { 0x1f, 0x0005 }, |
| 3279 | { 0x05, 0x8b55 }, |
| 3280 | { 0x06, 0x0000 }, |
| 3281 | { 0x05, 0x8b5e }, |
| 3282 | { 0x06, 0x0000 }, |
| 3283 | { 0x05, 0x8b67 }, |
| 3284 | { 0x06, 0x0000 }, |
| 3285 | { 0x05, 0x8b70 }, |
| 3286 | { 0x06, 0x0000 }, |
| 3287 | { 0x1f, 0x0000 }, |
| 3288 | { 0x1f, 0x0007 }, |
| 3289 | { 0x1e, 0x0078 }, |
| 3290 | { 0x17, 0x0000 }, |
| 3291 | { 0x19, 0x00aa }, |
| 3292 | { 0x1f, 0x0000 }, |
| 3293 | |
| 3294 | /* Modify green table for 10M */ |
| 3295 | { 0x1f, 0x0005 }, |
| 3296 | { 0x05, 0x8b79 }, |
| 3297 | { 0x06, 0xaa00 }, |
| 3298 | { 0x1f, 0x0000 }, |
| 3299 | |
| 3300 | /* Disable hiimpedance detection (RTCT) */ |
| 3301 | { 0x1f, 0x0003 }, |
| 3302 | { 0x01, 0x328a }, |
| 3303 | { 0x1f, 0x0000 } |
| 3304 | }; |
| 3305 | |
| 3306 | |
| 3307 | rtl_apply_firmware(tp); |
| 3308 | |
| 3309 | rtl8168f_hw_phy_config(tp); |
| 3310 | |
| 3311 | /* Improve 2-pair detection performance */ |
| 3312 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3313 | rtl_writephy(tp, 0x05, 0x8b85); |
| 3314 | rtl_w1w0_phy(tp, 0x06, 0x4000, 0x0000); |
| 3315 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3316 | |
| 3317 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3318 | |
| 3319 | /* Modify green table for giga */ |
| 3320 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3321 | rtl_writephy(tp, 0x05, 0x8b54); |
| 3322 | rtl_w1w0_phy(tp, 0x06, 0x0000, 0x0800); |
| 3323 | rtl_writephy(tp, 0x05, 0x8b5d); |
| 3324 | rtl_w1w0_phy(tp, 0x06, 0x0000, 0x0800); |
| 3325 | rtl_writephy(tp, 0x05, 0x8a7c); |
| 3326 | rtl_w1w0_phy(tp, 0x06, 0x0000, 0x0100); |
| 3327 | rtl_writephy(tp, 0x05, 0x8a7f); |
| 3328 | rtl_w1w0_phy(tp, 0x06, 0x0100, 0x0000); |
| 3329 | rtl_writephy(tp, 0x05, 0x8a82); |
| 3330 | rtl_w1w0_phy(tp, 0x06, 0x0000, 0x0100); |
| 3331 | rtl_writephy(tp, 0x05, 0x8a85); |
| 3332 | rtl_w1w0_phy(tp, 0x06, 0x0000, 0x0100); |
| 3333 | rtl_writephy(tp, 0x05, 0x8a88); |
| 3334 | rtl_w1w0_phy(tp, 0x06, 0x0000, 0x0100); |
| 3335 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3336 | |
| 3337 | /* uc same-seed solution */ |
| 3338 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3339 | rtl_writephy(tp, 0x05, 0x8b85); |
| 3340 | rtl_w1w0_phy(tp, 0x06, 0x8000, 0x0000); |
| 3341 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3342 | |
| 3343 | /* eee setting */ |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3344 | rtl_w1w0_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x00, 0x03, ERIAR_EXGMAC); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3345 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3346 | rtl_writephy(tp, 0x05, 0x8b85); |
| 3347 | rtl_w1w0_phy(tp, 0x06, 0x0000, 0x2000); |
| 3348 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3349 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3350 | rtl_writephy(tp, 0x1e, 0x0020); |
| 3351 | rtl_w1w0_phy(tp, 0x15, 0x0000, 0x0100); |
| 3352 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3353 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3354 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3355 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3356 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3357 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3358 | |
| 3359 | /* Green feature */ |
| 3360 | rtl_writephy(tp, 0x1f, 0x0003); |
| 3361 | rtl_w1w0_phy(tp, 0x19, 0x0000, 0x0001); |
| 3362 | rtl_w1w0_phy(tp, 0x10, 0x0000, 0x0400); |
| 3363 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3364 | } |
| 3365 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3366 | static void rtl8168g_1_hw_phy_config(struct rtl8169_private *tp) |
| 3367 | { |
| 3368 | static const u16 mac_ocp_patch[] = { |
| 3369 | 0xe008, 0xe01b, 0xe01d, 0xe01f, |
| 3370 | 0xe021, 0xe023, 0xe025, 0xe027, |
| 3371 | 0x49d2, 0xf10d, 0x766c, 0x49e2, |
| 3372 | 0xf00a, 0x1ec0, 0x8ee1, 0xc60a, |
| 3373 | |
| 3374 | 0x77c0, 0x4870, 0x9fc0, 0x1ea0, |
| 3375 | 0xc707, 0x8ee1, 0x9d6c, 0xc603, |
| 3376 | 0xbe00, 0xb416, 0x0076, 0xe86c, |
| 3377 | 0xc602, 0xbe00, 0x0000, 0xc602, |
| 3378 | |
| 3379 | 0xbe00, 0x0000, 0xc602, 0xbe00, |
| 3380 | 0x0000, 0xc602, 0xbe00, 0x0000, |
| 3381 | 0xc602, 0xbe00, 0x0000, 0xc602, |
| 3382 | 0xbe00, 0x0000, 0xc602, 0xbe00, |
| 3383 | |
| 3384 | 0x0000, 0x0000, 0x0000, 0x0000 |
| 3385 | }; |
| 3386 | u32 i; |
| 3387 | |
| 3388 | /* Patch code for GPHY reset */ |
| 3389 | for (i = 0; i < ARRAY_SIZE(mac_ocp_patch); i++) |
| 3390 | r8168_mac_ocp_write(tp, 0xf800 + 2*i, mac_ocp_patch[i]); |
| 3391 | r8168_mac_ocp_write(tp, 0xfc26, 0x8000); |
| 3392 | r8168_mac_ocp_write(tp, 0xfc28, 0x0075); |
| 3393 | |
| 3394 | rtl_apply_firmware(tp); |
| 3395 | |
| 3396 | if (r8168_phy_ocp_read(tp, 0xa460) & 0x0100) |
| 3397 | rtl_w1w0_phy_ocp(tp, 0xbcc4, 0x0000, 0x8000); |
| 3398 | else |
| 3399 | rtl_w1w0_phy_ocp(tp, 0xbcc4, 0x8000, 0x0000); |
| 3400 | |
| 3401 | if (r8168_phy_ocp_read(tp, 0xa466) & 0x0100) |
| 3402 | rtl_w1w0_phy_ocp(tp, 0xc41a, 0x0002, 0x0000); |
| 3403 | else |
| 3404 | rtl_w1w0_phy_ocp(tp, 0xbcc4, 0x0000, 0x0002); |
| 3405 | |
| 3406 | rtl_w1w0_phy_ocp(tp, 0xa442, 0x000c, 0x0000); |
| 3407 | rtl_w1w0_phy_ocp(tp, 0xa4b2, 0x0004, 0x0000); |
| 3408 | |
| 3409 | r8168_phy_ocp_write(tp, 0xa436, 0x8012); |
| 3410 | rtl_w1w0_phy_ocp(tp, 0xa438, 0x8000, 0x0000); |
| 3411 | |
| 3412 | rtl_w1w0_phy_ocp(tp, 0xc422, 0x4000, 0x2000); |
| 3413 | } |
| 3414 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3415 | static void rtl8102e_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3416 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3417 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3418 | { 0x1f, 0x0003 }, |
| 3419 | { 0x08, 0x441d }, |
| 3420 | { 0x01, 0x9100 }, |
| 3421 | { 0x1f, 0x0000 } |
| 3422 | }; |
| 3423 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3424 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3425 | rtl_patchphy(tp, 0x11, 1 << 12); |
| 3426 | rtl_patchphy(tp, 0x19, 1 << 13); |
| 3427 | rtl_patchphy(tp, 0x10, 1 << 15); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3428 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3429 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3430 | } |
| 3431 | |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3432 | static void rtl8105e_hw_phy_config(struct rtl8169_private *tp) |
| 3433 | { |
| 3434 | static const struct phy_reg phy_reg_init[] = { |
| 3435 | { 0x1f, 0x0005 }, |
| 3436 | { 0x1a, 0x0000 }, |
| 3437 | { 0x1f, 0x0000 }, |
| 3438 | |
| 3439 | { 0x1f, 0x0004 }, |
| 3440 | { 0x1c, 0x0000 }, |
| 3441 | { 0x1f, 0x0000 }, |
| 3442 | |
| 3443 | { 0x1f, 0x0001 }, |
| 3444 | { 0x15, 0x7701 }, |
| 3445 | { 0x1f, 0x0000 } |
| 3446 | }; |
| 3447 | |
| 3448 | /* Disable ALDPS before ram code */ |
| 3449 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3450 | rtl_writephy(tp, 0x18, 0x0310); |
| 3451 | msleep(100); |
| 3452 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3453 | rtl_apply_firmware(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3454 | |
| 3455 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3456 | } |
| 3457 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3458 | static void rtl8402_hw_phy_config(struct rtl8169_private *tp) |
| 3459 | { |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3460 | /* Disable ALDPS before setting firmware */ |
| 3461 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3462 | rtl_writephy(tp, 0x18, 0x0310); |
| 3463 | msleep(20); |
| 3464 | |
| 3465 | rtl_apply_firmware(tp); |
| 3466 | |
| 3467 | /* EEE setting */ |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3468 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3469 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3470 | rtl_writephy(tp, 0x10, 0x401f); |
| 3471 | rtl_writephy(tp, 0x19, 0x7030); |
| 3472 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3473 | } |
| 3474 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3475 | static void rtl8106e_hw_phy_config(struct rtl8169_private *tp) |
| 3476 | { |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3477 | static const struct phy_reg phy_reg_init[] = { |
| 3478 | { 0x1f, 0x0004 }, |
| 3479 | { 0x10, 0xc07f }, |
| 3480 | { 0x19, 0x7030 }, |
| 3481 | { 0x1f, 0x0000 } |
| 3482 | }; |
| 3483 | |
| 3484 | /* Disable ALDPS before ram code */ |
| 3485 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3486 | rtl_writephy(tp, 0x18, 0x0310); |
| 3487 | msleep(100); |
| 3488 | |
| 3489 | rtl_apply_firmware(tp); |
| 3490 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3491 | rtl_eri_write(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3492 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3493 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3494 | rtl_eri_write(tp, 0x1d0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3495 | } |
| 3496 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3497 | static void rtl_hw_phy_config(struct net_device *dev) |
| 3498 | { |
| 3499 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3500 | |
| 3501 | rtl8169_print_mac_version(tp); |
| 3502 | |
| 3503 | switch (tp->mac_version) { |
| 3504 | case RTL_GIGA_MAC_VER_01: |
| 3505 | break; |
| 3506 | case RTL_GIGA_MAC_VER_02: |
| 3507 | case RTL_GIGA_MAC_VER_03: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3508 | rtl8169s_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3509 | break; |
| 3510 | case RTL_GIGA_MAC_VER_04: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3511 | rtl8169sb_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3512 | break; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3513 | case RTL_GIGA_MAC_VER_05: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3514 | rtl8169scd_hw_phy_config(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3515 | break; |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 3516 | case RTL_GIGA_MAC_VER_06: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3517 | rtl8169sce_hw_phy_config(tp); |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 3518 | break; |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3519 | case RTL_GIGA_MAC_VER_07: |
| 3520 | case RTL_GIGA_MAC_VER_08: |
| 3521 | case RTL_GIGA_MAC_VER_09: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3522 | rtl8102e_hw_phy_config(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3523 | break; |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3524 | case RTL_GIGA_MAC_VER_11: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3525 | rtl8168bb_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3526 | break; |
| 3527 | case RTL_GIGA_MAC_VER_12: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3528 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3529 | break; |
| 3530 | case RTL_GIGA_MAC_VER_17: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3531 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3532 | break; |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3533 | case RTL_GIGA_MAC_VER_18: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3534 | rtl8168cp_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3535 | break; |
| 3536 | case RTL_GIGA_MAC_VER_19: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3537 | rtl8168c_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3538 | break; |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3539 | case RTL_GIGA_MAC_VER_20: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3540 | rtl8168c_2_hw_phy_config(tp); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3541 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3542 | case RTL_GIGA_MAC_VER_21: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3543 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3544 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3545 | case RTL_GIGA_MAC_VER_22: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3546 | rtl8168c_4_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3547 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3548 | case RTL_GIGA_MAC_VER_23: |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 3549 | case RTL_GIGA_MAC_VER_24: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3550 | rtl8168cp_2_hw_phy_config(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3551 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3552 | case RTL_GIGA_MAC_VER_25: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3553 | rtl8168d_1_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3554 | break; |
| 3555 | case RTL_GIGA_MAC_VER_26: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3556 | rtl8168d_2_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3557 | break; |
| 3558 | case RTL_GIGA_MAC_VER_27: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3559 | rtl8168d_3_hw_phy_config(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3560 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3561 | case RTL_GIGA_MAC_VER_28: |
| 3562 | rtl8168d_4_hw_phy_config(tp); |
| 3563 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3564 | case RTL_GIGA_MAC_VER_29: |
| 3565 | case RTL_GIGA_MAC_VER_30: |
| 3566 | rtl8105e_hw_phy_config(tp); |
| 3567 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3568 | case RTL_GIGA_MAC_VER_31: |
| 3569 | /* None. */ |
| 3570 | break; |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3571 | case RTL_GIGA_MAC_VER_32: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3572 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3573 | rtl8168e_1_hw_phy_config(tp); |
| 3574 | break; |
| 3575 | case RTL_GIGA_MAC_VER_34: |
| 3576 | rtl8168e_2_hw_phy_config(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3577 | break; |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3578 | case RTL_GIGA_MAC_VER_35: |
| 3579 | rtl8168f_1_hw_phy_config(tp); |
| 3580 | break; |
| 3581 | case RTL_GIGA_MAC_VER_36: |
| 3582 | rtl8168f_2_hw_phy_config(tp); |
| 3583 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3584 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3585 | case RTL_GIGA_MAC_VER_37: |
| 3586 | rtl8402_hw_phy_config(tp); |
| 3587 | break; |
| 3588 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3589 | case RTL_GIGA_MAC_VER_38: |
| 3590 | rtl8411_hw_phy_config(tp); |
| 3591 | break; |
| 3592 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3593 | case RTL_GIGA_MAC_VER_39: |
| 3594 | rtl8106e_hw_phy_config(tp); |
| 3595 | break; |
| 3596 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3597 | case RTL_GIGA_MAC_VER_40: |
| 3598 | rtl8168g_1_hw_phy_config(tp); |
| 3599 | break; |
| 3600 | |
| 3601 | case RTL_GIGA_MAC_VER_41: |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3602 | default: |
| 3603 | break; |
| 3604 | } |
| 3605 | } |
| 3606 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3607 | static void rtl_phy_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3608 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3609 | struct timer_list *timer = &tp->timer; |
| 3610 | void __iomem *ioaddr = tp->mmio_addr; |
| 3611 | unsigned long timeout = RTL8169_PHY_TIMEOUT; |
| 3612 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 3613 | assert(tp->mac_version > RTL_GIGA_MAC_VER_01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3614 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3615 | if (tp->phy_reset_pending(tp)) { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 3616 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3617 | * A busy loop could burn quite a few cycles on nowadays CPU. |
| 3618 | * Let's delay the execution of the timer for a few ticks. |
| 3619 | */ |
| 3620 | timeout = HZ/10; |
| 3621 | goto out_mod_timer; |
| 3622 | } |
| 3623 | |
| 3624 | if (tp->link_ok(ioaddr)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3625 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3626 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3627 | netif_warn(tp, link, tp->dev, "PHY reset until link up\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3628 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3629 | tp->phy_reset_enable(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | |
| 3631 | out_mod_timer: |
| 3632 | mod_timer(timer, jiffies + timeout); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3633 | } |
| 3634 | |
| 3635 | static void rtl_schedule_task(struct rtl8169_private *tp, enum rtl_flag flag) |
| 3636 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3637 | if (!test_and_set_bit(flag, tp->wk.flags)) |
| 3638 | schedule_work(&tp->wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3639 | } |
| 3640 | |
| 3641 | static void rtl8169_phy_timer(unsigned long __opaque) |
| 3642 | { |
| 3643 | struct net_device *dev = (struct net_device *)__opaque; |
| 3644 | struct rtl8169_private *tp = netdev_priv(dev); |
| 3645 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 3646 | rtl_schedule_task(tp, RTL_FLAG_TASK_PHY_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3647 | } |
| 3648 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3649 | static void rtl8169_release_board(struct pci_dev *pdev, struct net_device *dev, |
| 3650 | void __iomem *ioaddr) |
| 3651 | { |
| 3652 | iounmap(ioaddr); |
| 3653 | pci_release_regions(pdev); |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3654 | pci_clear_mwi(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3655 | pci_disable_device(pdev); |
| 3656 | free_netdev(dev); |
| 3657 | } |
| 3658 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 3659 | DECLARE_RTL_COND(rtl_phy_reset_cond) |
| 3660 | { |
| 3661 | return tp->phy_reset_pending(tp); |
| 3662 | } |
| 3663 | |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 3664 | static void rtl8169_phy_reset(struct net_device *dev, |
| 3665 | struct rtl8169_private *tp) |
| 3666 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3667 | tp->phy_reset_enable(tp); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 3668 | rtl_msleep_loop_wait_low(tp, &rtl_phy_reset_cond, 1, 100); |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 3669 | } |
| 3670 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 3671 | static bool rtl_tbi_enabled(struct rtl8169_private *tp) |
| 3672 | { |
| 3673 | void __iomem *ioaddr = tp->mmio_addr; |
| 3674 | |
| 3675 | return (tp->mac_version == RTL_GIGA_MAC_VER_01) && |
| 3676 | (RTL_R8(PHYstatus) & TBI_Enable); |
| 3677 | } |
| 3678 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3679 | 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] | 3680 | { |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3681 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3682 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3683 | rtl_hw_phy_config(dev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3684 | |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 3685 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
| 3686 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
| 3687 | RTL_W8(0x82, 0x01); |
| 3688 | } |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3689 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 3690 | pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); |
| 3691 | |
| 3692 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
| 3693 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3694 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 3695 | if (tp->mac_version == RTL_GIGA_MAC_VER_02) { |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3696 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
| 3697 | RTL_W8(0x82, 0x01); |
| 3698 | dprintk("Set PHY Reg 0x0bh = 0x00h\n"); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3699 | rtl_writephy(tp, 0x0b, 0x0000); //w 0x0b 15 0 0 |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3700 | } |
| 3701 | |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 3702 | rtl8169_phy_reset(dev, tp); |
| 3703 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 3704 | rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3705 | ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 3706 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 3707 | (tp->mii.supports_gmii ? |
| 3708 | ADVERTISED_1000baseT_Half | |
| 3709 | ADVERTISED_1000baseT_Full : 0)); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3710 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 3711 | if (rtl_tbi_enabled(tp)) |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3712 | netif_info(tp, link, dev, "TBI auto-negotiating\n"); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3713 | } |
| 3714 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3715 | static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr) |
| 3716 | { |
| 3717 | void __iomem *ioaddr = tp->mmio_addr; |
| 3718 | u32 high; |
| 3719 | u32 low; |
| 3720 | |
| 3721 | low = addr[0] | (addr[1] << 8) | (addr[2] << 16) | (addr[3] << 24); |
| 3722 | high = addr[4] | (addr[5] << 8); |
| 3723 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3724 | rtl_lock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3725 | |
| 3726 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 3727 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3728 | RTL_W32(MAC4, high); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 3729 | RTL_R32(MAC4); |
| 3730 | |
Francois Romieu | 78f1cd0 | 2010-03-27 19:35:46 -0700 | [diff] [blame] | 3731 | RTL_W32(MAC0, low); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 3732 | RTL_R32(MAC0); |
| 3733 | |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 3734 | if (tp->mac_version == RTL_GIGA_MAC_VER_34) { |
| 3735 | const struct exgmac_reg e[] = { |
| 3736 | { .addr = 0xe0, ERIAR_MASK_1111, .val = low }, |
| 3737 | { .addr = 0xe4, ERIAR_MASK_1111, .val = high }, |
| 3738 | { .addr = 0xf0, ERIAR_MASK_1111, .val = low << 16 }, |
| 3739 | { .addr = 0xf4, ERIAR_MASK_1111, .val = high << 16 | |
| 3740 | low >> 16 }, |
| 3741 | }; |
| 3742 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 3743 | rtl_write_exgmac_batch(tp, e, ARRAY_SIZE(e)); |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 3744 | } |
| 3745 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3746 | RTL_W8(Cfg9346, Cfg9346_Lock); |
| 3747 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3748 | rtl_unlock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3749 | } |
| 3750 | |
| 3751 | static int rtl_set_mac_address(struct net_device *dev, void *p) |
| 3752 | { |
| 3753 | struct rtl8169_private *tp = netdev_priv(dev); |
| 3754 | struct sockaddr *addr = p; |
| 3755 | |
| 3756 | if (!is_valid_ether_addr(addr->sa_data)) |
| 3757 | return -EADDRNOTAVAIL; |
| 3758 | |
| 3759 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 3760 | |
| 3761 | rtl_rar_set(tp, dev->dev_addr); |
| 3762 | |
| 3763 | return 0; |
| 3764 | } |
| 3765 | |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 3766 | static int rtl8169_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 3767 | { |
| 3768 | struct rtl8169_private *tp = netdev_priv(dev); |
| 3769 | struct mii_ioctl_data *data = if_mii(ifr); |
| 3770 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3771 | return netif_running(dev) ? tp->do_ioctl(tp, data, cmd) : -ENODEV; |
| 3772 | } |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 3773 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3774 | static int rtl_xmii_ioctl(struct rtl8169_private *tp, |
| 3775 | struct mii_ioctl_data *data, int cmd) |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3776 | { |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 3777 | switch (cmd) { |
| 3778 | case SIOCGMIIPHY: |
| 3779 | data->phy_id = 32; /* Internal PHY */ |
| 3780 | return 0; |
| 3781 | |
| 3782 | case SIOCGMIIREG: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3783 | data->val_out = rtl_readphy(tp, data->reg_num & 0x1f); |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 3784 | return 0; |
| 3785 | |
| 3786 | case SIOCSMIIREG: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3787 | rtl_writephy(tp, data->reg_num & 0x1f, data->val_in); |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 3788 | return 0; |
| 3789 | } |
| 3790 | return -EOPNOTSUPP; |
| 3791 | } |
| 3792 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3793 | static int rtl_tbi_ioctl(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd) |
| 3794 | { |
| 3795 | return -EOPNOTSUPP; |
| 3796 | } |
| 3797 | |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 3798 | static void rtl_disable_msi(struct pci_dev *pdev, struct rtl8169_private *tp) |
| 3799 | { |
| 3800 | if (tp->features & RTL_FEATURE_MSI) { |
| 3801 | pci_disable_msi(pdev); |
| 3802 | tp->features &= ~RTL_FEATURE_MSI; |
| 3803 | } |
| 3804 | } |
| 3805 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 3806 | static void __devinit rtl_init_mdio_ops(struct rtl8169_private *tp) |
| 3807 | { |
| 3808 | struct mdio_ops *ops = &tp->mdio_ops; |
| 3809 | |
| 3810 | switch (tp->mac_version) { |
| 3811 | case RTL_GIGA_MAC_VER_27: |
| 3812 | ops->write = r8168dp_1_mdio_write; |
| 3813 | ops->read = r8168dp_1_mdio_read; |
| 3814 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3815 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 3816 | case RTL_GIGA_MAC_VER_31: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3817 | ops->write = r8168dp_2_mdio_write; |
| 3818 | ops->read = r8168dp_2_mdio_read; |
| 3819 | break; |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3820 | case RTL_GIGA_MAC_VER_40: |
| 3821 | case RTL_GIGA_MAC_VER_41: |
| 3822 | ops->write = r8168g_mdio_write; |
| 3823 | ops->read = r8168g_mdio_read; |
| 3824 | break; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 3825 | default: |
| 3826 | ops->write = r8169_mdio_write; |
| 3827 | ops->read = r8169_mdio_read; |
| 3828 | break; |
| 3829 | } |
| 3830 | } |
| 3831 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 3832 | static void rtl_wol_suspend_quirk(struct rtl8169_private *tp) |
| 3833 | { |
| 3834 | void __iomem *ioaddr = tp->mmio_addr; |
| 3835 | |
| 3836 | switch (tp->mac_version) { |
| 3837 | case RTL_GIGA_MAC_VER_29: |
| 3838 | case RTL_GIGA_MAC_VER_30: |
| 3839 | case RTL_GIGA_MAC_VER_32: |
| 3840 | case RTL_GIGA_MAC_VER_33: |
| 3841 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 3842 | case RTL_GIGA_MAC_VER_37: |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 3843 | case RTL_GIGA_MAC_VER_38: |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 3844 | case RTL_GIGA_MAC_VER_39: |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 3845 | case RTL_GIGA_MAC_VER_40: |
| 3846 | case RTL_GIGA_MAC_VER_41: |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 3847 | RTL_W32(RxConfig, RTL_R32(RxConfig) | |
| 3848 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys); |
| 3849 | break; |
| 3850 | default: |
| 3851 | break; |
| 3852 | } |
| 3853 | } |
| 3854 | |
| 3855 | static bool rtl_wol_pll_power_down(struct rtl8169_private *tp) |
| 3856 | { |
| 3857 | if (!(__rtl8169_get_wol(tp) & WAKE_ANY)) |
| 3858 | return false; |
| 3859 | |
| 3860 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3861 | rtl_writephy(tp, MII_BMCR, 0x0000); |
| 3862 | |
| 3863 | rtl_wol_suspend_quirk(tp); |
| 3864 | |
| 3865 | return true; |
| 3866 | } |
| 3867 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3868 | static void r810x_phy_power_down(struct rtl8169_private *tp) |
| 3869 | { |
| 3870 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3871 | rtl_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 3872 | } |
| 3873 | |
| 3874 | static void r810x_phy_power_up(struct rtl8169_private *tp) |
| 3875 | { |
| 3876 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3877 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE); |
| 3878 | } |
| 3879 | |
| 3880 | static void r810x_pll_power_down(struct rtl8169_private *tp) |
| 3881 | { |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 3882 | void __iomem *ioaddr = tp->mmio_addr; |
| 3883 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 3884 | if (rtl_wol_pll_power_down(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3885 | return; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3886 | |
| 3887 | r810x_phy_power_down(tp); |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 3888 | |
| 3889 | switch (tp->mac_version) { |
| 3890 | case RTL_GIGA_MAC_VER_07: |
| 3891 | case RTL_GIGA_MAC_VER_08: |
| 3892 | case RTL_GIGA_MAC_VER_09: |
| 3893 | case RTL_GIGA_MAC_VER_10: |
| 3894 | case RTL_GIGA_MAC_VER_13: |
| 3895 | case RTL_GIGA_MAC_VER_16: |
| 3896 | break; |
| 3897 | default: |
| 3898 | RTL_W8(PMCH, RTL_R8(PMCH) & ~0x80); |
| 3899 | break; |
| 3900 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3901 | } |
| 3902 | |
| 3903 | static void r810x_pll_power_up(struct rtl8169_private *tp) |
| 3904 | { |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 3905 | void __iomem *ioaddr = tp->mmio_addr; |
| 3906 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3907 | r810x_phy_power_up(tp); |
Hayes Wang | 0004299 | 2012-03-30 14:33:00 +0800 | [diff] [blame] | 3908 | |
| 3909 | switch (tp->mac_version) { |
| 3910 | case RTL_GIGA_MAC_VER_07: |
| 3911 | case RTL_GIGA_MAC_VER_08: |
| 3912 | case RTL_GIGA_MAC_VER_09: |
| 3913 | case RTL_GIGA_MAC_VER_10: |
| 3914 | case RTL_GIGA_MAC_VER_13: |
| 3915 | case RTL_GIGA_MAC_VER_16: |
| 3916 | break; |
| 3917 | default: |
| 3918 | RTL_W8(PMCH, RTL_R8(PMCH) | 0x80); |
| 3919 | break; |
| 3920 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3921 | } |
| 3922 | |
| 3923 | static void r8168_phy_power_up(struct rtl8169_private *tp) |
| 3924 | { |
| 3925 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3926 | switch (tp->mac_version) { |
| 3927 | case RTL_GIGA_MAC_VER_11: |
| 3928 | case RTL_GIGA_MAC_VER_12: |
| 3929 | case RTL_GIGA_MAC_VER_17: |
| 3930 | case RTL_GIGA_MAC_VER_18: |
| 3931 | case RTL_GIGA_MAC_VER_19: |
| 3932 | case RTL_GIGA_MAC_VER_20: |
| 3933 | case RTL_GIGA_MAC_VER_21: |
| 3934 | case RTL_GIGA_MAC_VER_22: |
| 3935 | case RTL_GIGA_MAC_VER_23: |
| 3936 | case RTL_GIGA_MAC_VER_24: |
| 3937 | case RTL_GIGA_MAC_VER_25: |
| 3938 | case RTL_GIGA_MAC_VER_26: |
| 3939 | case RTL_GIGA_MAC_VER_27: |
| 3940 | case RTL_GIGA_MAC_VER_28: |
| 3941 | case RTL_GIGA_MAC_VER_31: |
| 3942 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3943 | break; |
| 3944 | default: |
| 3945 | break; |
| 3946 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3947 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE); |
| 3948 | } |
| 3949 | |
| 3950 | static void r8168_phy_power_down(struct rtl8169_private *tp) |
| 3951 | { |
| 3952 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3953 | switch (tp->mac_version) { |
| 3954 | case RTL_GIGA_MAC_VER_32: |
| 3955 | case RTL_GIGA_MAC_VER_33: |
| 3956 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE | BMCR_PDOWN); |
| 3957 | break; |
| 3958 | |
| 3959 | case RTL_GIGA_MAC_VER_11: |
| 3960 | case RTL_GIGA_MAC_VER_12: |
| 3961 | case RTL_GIGA_MAC_VER_17: |
| 3962 | case RTL_GIGA_MAC_VER_18: |
| 3963 | case RTL_GIGA_MAC_VER_19: |
| 3964 | case RTL_GIGA_MAC_VER_20: |
| 3965 | case RTL_GIGA_MAC_VER_21: |
| 3966 | case RTL_GIGA_MAC_VER_22: |
| 3967 | case RTL_GIGA_MAC_VER_23: |
| 3968 | case RTL_GIGA_MAC_VER_24: |
| 3969 | case RTL_GIGA_MAC_VER_25: |
| 3970 | case RTL_GIGA_MAC_VER_26: |
| 3971 | case RTL_GIGA_MAC_VER_27: |
| 3972 | case RTL_GIGA_MAC_VER_28: |
| 3973 | case RTL_GIGA_MAC_VER_31: |
| 3974 | rtl_writephy(tp, 0x0e, 0x0200); |
| 3975 | default: |
| 3976 | rtl_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 3977 | break; |
| 3978 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3979 | } |
| 3980 | |
| 3981 | static void r8168_pll_power_down(struct rtl8169_private *tp) |
| 3982 | { |
| 3983 | void __iomem *ioaddr = tp->mmio_addr; |
| 3984 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3985 | if ((tp->mac_version == RTL_GIGA_MAC_VER_27 || |
| 3986 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 3987 | tp->mac_version == RTL_GIGA_MAC_VER_31) && |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 3988 | r8168dp_check_dash(tp)) { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3989 | return; |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 3990 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3991 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3992 | if ((tp->mac_version == RTL_GIGA_MAC_VER_23 || |
| 3993 | tp->mac_version == RTL_GIGA_MAC_VER_24) && |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3994 | (RTL_R16(CPlusCmd) & ASF)) { |
| 3995 | return; |
| 3996 | } |
| 3997 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3998 | if (tp->mac_version == RTL_GIGA_MAC_VER_32 || |
| 3999 | tp->mac_version == RTL_GIGA_MAC_VER_33) |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4000 | rtl_ephy_write(tp, 0x19, 0xff64); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4001 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 4002 | if (rtl_wol_pll_power_down(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4003 | return; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4004 | |
| 4005 | r8168_phy_power_down(tp); |
| 4006 | |
| 4007 | switch (tp->mac_version) { |
| 4008 | case RTL_GIGA_MAC_VER_25: |
| 4009 | case RTL_GIGA_MAC_VER_26: |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 4010 | case RTL_GIGA_MAC_VER_27: |
| 4011 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4012 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4013 | case RTL_GIGA_MAC_VER_32: |
| 4014 | case RTL_GIGA_MAC_VER_33: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4015 | RTL_W8(PMCH, RTL_R8(PMCH) & ~0x80); |
| 4016 | break; |
| 4017 | } |
| 4018 | } |
| 4019 | |
| 4020 | static void r8168_pll_power_up(struct rtl8169_private *tp) |
| 4021 | { |
| 4022 | void __iomem *ioaddr = tp->mmio_addr; |
| 4023 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4024 | switch (tp->mac_version) { |
| 4025 | case RTL_GIGA_MAC_VER_25: |
| 4026 | case RTL_GIGA_MAC_VER_26: |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 4027 | case RTL_GIGA_MAC_VER_27: |
| 4028 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4029 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4030 | case RTL_GIGA_MAC_VER_32: |
| 4031 | case RTL_GIGA_MAC_VER_33: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4032 | RTL_W8(PMCH, RTL_R8(PMCH) | 0x80); |
| 4033 | break; |
| 4034 | } |
| 4035 | |
| 4036 | r8168_phy_power_up(tp); |
| 4037 | } |
| 4038 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4039 | static void rtl_generic_op(struct rtl8169_private *tp, |
| 4040 | void (*op)(struct rtl8169_private *)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4041 | { |
| 4042 | if (op) |
| 4043 | op(tp); |
| 4044 | } |
| 4045 | |
| 4046 | static void rtl_pll_power_down(struct rtl8169_private *tp) |
| 4047 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4048 | rtl_generic_op(tp, tp->pll_power_ops.down); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4049 | } |
| 4050 | |
| 4051 | static void rtl_pll_power_up(struct rtl8169_private *tp) |
| 4052 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4053 | rtl_generic_op(tp, tp->pll_power_ops.up); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4054 | } |
| 4055 | |
| 4056 | static void __devinit rtl_init_pll_power_ops(struct rtl8169_private *tp) |
| 4057 | { |
| 4058 | struct pll_power_ops *ops = &tp->pll_power_ops; |
| 4059 | |
| 4060 | switch (tp->mac_version) { |
| 4061 | case RTL_GIGA_MAC_VER_07: |
| 4062 | case RTL_GIGA_MAC_VER_08: |
| 4063 | case RTL_GIGA_MAC_VER_09: |
| 4064 | case RTL_GIGA_MAC_VER_10: |
| 4065 | case RTL_GIGA_MAC_VER_16: |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4066 | case RTL_GIGA_MAC_VER_29: |
| 4067 | case RTL_GIGA_MAC_VER_30: |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4068 | case RTL_GIGA_MAC_VER_37: |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 4069 | case RTL_GIGA_MAC_VER_39: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4070 | ops->down = r810x_pll_power_down; |
| 4071 | ops->up = r810x_pll_power_up; |
| 4072 | break; |
| 4073 | |
| 4074 | case RTL_GIGA_MAC_VER_11: |
| 4075 | case RTL_GIGA_MAC_VER_12: |
| 4076 | case RTL_GIGA_MAC_VER_17: |
| 4077 | case RTL_GIGA_MAC_VER_18: |
| 4078 | case RTL_GIGA_MAC_VER_19: |
| 4079 | case RTL_GIGA_MAC_VER_20: |
| 4080 | case RTL_GIGA_MAC_VER_21: |
| 4081 | case RTL_GIGA_MAC_VER_22: |
| 4082 | case RTL_GIGA_MAC_VER_23: |
| 4083 | case RTL_GIGA_MAC_VER_24: |
| 4084 | case RTL_GIGA_MAC_VER_25: |
| 4085 | case RTL_GIGA_MAC_VER_26: |
| 4086 | case RTL_GIGA_MAC_VER_27: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4087 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4088 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4089 | case RTL_GIGA_MAC_VER_32: |
| 4090 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4091 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4092 | case RTL_GIGA_MAC_VER_35: |
| 4093 | case RTL_GIGA_MAC_VER_36: |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4094 | case RTL_GIGA_MAC_VER_38: |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4095 | case RTL_GIGA_MAC_VER_40: |
| 4096 | case RTL_GIGA_MAC_VER_41: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4097 | ops->down = r8168_pll_power_down; |
| 4098 | ops->up = r8168_pll_power_up; |
| 4099 | break; |
| 4100 | |
| 4101 | default: |
| 4102 | ops->down = NULL; |
| 4103 | ops->up = NULL; |
| 4104 | break; |
| 4105 | } |
| 4106 | } |
| 4107 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4108 | static void rtl_init_rxcfg(struct rtl8169_private *tp) |
| 4109 | { |
| 4110 | void __iomem *ioaddr = tp->mmio_addr; |
| 4111 | |
| 4112 | switch (tp->mac_version) { |
| 4113 | case RTL_GIGA_MAC_VER_01: |
| 4114 | case RTL_GIGA_MAC_VER_02: |
| 4115 | case RTL_GIGA_MAC_VER_03: |
| 4116 | case RTL_GIGA_MAC_VER_04: |
| 4117 | case RTL_GIGA_MAC_VER_05: |
| 4118 | case RTL_GIGA_MAC_VER_06: |
| 4119 | case RTL_GIGA_MAC_VER_10: |
| 4120 | case RTL_GIGA_MAC_VER_11: |
| 4121 | case RTL_GIGA_MAC_VER_12: |
| 4122 | case RTL_GIGA_MAC_VER_13: |
| 4123 | case RTL_GIGA_MAC_VER_14: |
| 4124 | case RTL_GIGA_MAC_VER_15: |
| 4125 | case RTL_GIGA_MAC_VER_16: |
| 4126 | case RTL_GIGA_MAC_VER_17: |
| 4127 | RTL_W32(RxConfig, RX_FIFO_THRESH | RX_DMA_BURST); |
| 4128 | break; |
| 4129 | case RTL_GIGA_MAC_VER_18: |
| 4130 | case RTL_GIGA_MAC_VER_19: |
| 4131 | case RTL_GIGA_MAC_VER_20: |
| 4132 | case RTL_GIGA_MAC_VER_21: |
| 4133 | case RTL_GIGA_MAC_VER_22: |
| 4134 | case RTL_GIGA_MAC_VER_23: |
| 4135 | case RTL_GIGA_MAC_VER_24: |
françois romieu | eb2dc35 | 2012-06-20 12:09:18 +0000 | [diff] [blame] | 4136 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4137 | RTL_W32(RxConfig, RX128_INT_EN | RX_MULTI_EN | RX_DMA_BURST); |
| 4138 | break; |
| 4139 | default: |
| 4140 | RTL_W32(RxConfig, RX128_INT_EN | RX_DMA_BURST); |
| 4141 | break; |
| 4142 | } |
| 4143 | } |
| 4144 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4145 | static void rtl8169_init_ring_indexes(struct rtl8169_private *tp) |
| 4146 | { |
| 4147 | tp->dirty_tx = tp->dirty_rx = tp->cur_tx = tp->cur_rx = 0; |
| 4148 | } |
| 4149 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4150 | static void rtl_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4151 | { |
françois romieu | 9c5028e | 2012-03-02 04:43:14 +0000 | [diff] [blame] | 4152 | void __iomem *ioaddr = tp->mmio_addr; |
| 4153 | |
| 4154 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4155 | rtl_generic_op(tp, tp->jumbo_ops.enable); |
françois romieu | 9c5028e | 2012-03-02 04:43:14 +0000 | [diff] [blame] | 4156 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4157 | } |
| 4158 | |
| 4159 | static void rtl_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4160 | { |
françois romieu | 9c5028e | 2012-03-02 04:43:14 +0000 | [diff] [blame] | 4161 | void __iomem *ioaddr = tp->mmio_addr; |
| 4162 | |
| 4163 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4164 | rtl_generic_op(tp, tp->jumbo_ops.disable); |
françois romieu | 9c5028e | 2012-03-02 04:43:14 +0000 | [diff] [blame] | 4165 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4166 | } |
| 4167 | |
| 4168 | static void r8168c_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4169 | { |
| 4170 | void __iomem *ioaddr = tp->mmio_addr; |
| 4171 | |
| 4172 | RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0); |
| 4173 | RTL_W8(Config4, RTL_R8(Config4) | Jumbo_En1); |
| 4174 | rtl_tx_performance_tweak(tp->pci_dev, 0x2 << MAX_READ_REQUEST_SHIFT); |
| 4175 | } |
| 4176 | |
| 4177 | static void r8168c_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4178 | { |
| 4179 | void __iomem *ioaddr = tp->mmio_addr; |
| 4180 | |
| 4181 | RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0); |
| 4182 | RTL_W8(Config4, RTL_R8(Config4) & ~Jumbo_En1); |
| 4183 | rtl_tx_performance_tweak(tp->pci_dev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4184 | } |
| 4185 | |
| 4186 | static void r8168dp_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4187 | { |
| 4188 | void __iomem *ioaddr = tp->mmio_addr; |
| 4189 | |
| 4190 | RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0); |
| 4191 | } |
| 4192 | |
| 4193 | static void r8168dp_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4194 | { |
| 4195 | void __iomem *ioaddr = tp->mmio_addr; |
| 4196 | |
| 4197 | RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0); |
| 4198 | } |
| 4199 | |
| 4200 | static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4201 | { |
| 4202 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4203 | |
| 4204 | RTL_W8(MaxTxPacketSize, 0x3f); |
| 4205 | RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0); |
| 4206 | RTL_W8(Config4, RTL_R8(Config4) | 0x01); |
Francois Romieu | 4512ff9 | 2011-12-22 18:59:37 +0100 | [diff] [blame] | 4207 | rtl_tx_performance_tweak(tp->pci_dev, 0x2 << MAX_READ_REQUEST_SHIFT); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4208 | } |
| 4209 | |
| 4210 | static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4211 | { |
| 4212 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4213 | |
| 4214 | RTL_W8(MaxTxPacketSize, 0x0c); |
| 4215 | RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0); |
| 4216 | RTL_W8(Config4, RTL_R8(Config4) & ~0x01); |
Francois Romieu | 4512ff9 | 2011-12-22 18:59:37 +0100 | [diff] [blame] | 4217 | rtl_tx_performance_tweak(tp->pci_dev, 0x5 << MAX_READ_REQUEST_SHIFT); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4218 | } |
| 4219 | |
| 4220 | static void r8168b_0_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4221 | { |
| 4222 | rtl_tx_performance_tweak(tp->pci_dev, |
| 4223 | (0x2 << MAX_READ_REQUEST_SHIFT) | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 4224 | } |
| 4225 | |
| 4226 | static void r8168b_0_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4227 | { |
| 4228 | rtl_tx_performance_tweak(tp->pci_dev, |
| 4229 | (0x5 << MAX_READ_REQUEST_SHIFT) | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 4230 | } |
| 4231 | |
| 4232 | static void r8168b_1_hw_jumbo_enable(struct rtl8169_private *tp) |
| 4233 | { |
| 4234 | void __iomem *ioaddr = tp->mmio_addr; |
| 4235 | |
| 4236 | r8168b_0_hw_jumbo_enable(tp); |
| 4237 | |
| 4238 | RTL_W8(Config4, RTL_R8(Config4) | (1 << 0)); |
| 4239 | } |
| 4240 | |
| 4241 | static void r8168b_1_hw_jumbo_disable(struct rtl8169_private *tp) |
| 4242 | { |
| 4243 | void __iomem *ioaddr = tp->mmio_addr; |
| 4244 | |
| 4245 | r8168b_0_hw_jumbo_disable(tp); |
| 4246 | |
| 4247 | RTL_W8(Config4, RTL_R8(Config4) & ~(1 << 0)); |
| 4248 | } |
| 4249 | |
| 4250 | static void __devinit rtl_init_jumbo_ops(struct rtl8169_private *tp) |
| 4251 | { |
| 4252 | struct jumbo_ops *ops = &tp->jumbo_ops; |
| 4253 | |
| 4254 | switch (tp->mac_version) { |
| 4255 | case RTL_GIGA_MAC_VER_11: |
| 4256 | ops->disable = r8168b_0_hw_jumbo_disable; |
| 4257 | ops->enable = r8168b_0_hw_jumbo_enable; |
| 4258 | break; |
| 4259 | case RTL_GIGA_MAC_VER_12: |
| 4260 | case RTL_GIGA_MAC_VER_17: |
| 4261 | ops->disable = r8168b_1_hw_jumbo_disable; |
| 4262 | ops->enable = r8168b_1_hw_jumbo_enable; |
| 4263 | break; |
| 4264 | case RTL_GIGA_MAC_VER_18: /* Wild guess. Needs info from Realtek. */ |
| 4265 | case RTL_GIGA_MAC_VER_19: |
| 4266 | case RTL_GIGA_MAC_VER_20: |
| 4267 | case RTL_GIGA_MAC_VER_21: /* Wild guess. Needs info from Realtek. */ |
| 4268 | case RTL_GIGA_MAC_VER_22: |
| 4269 | case RTL_GIGA_MAC_VER_23: |
| 4270 | case RTL_GIGA_MAC_VER_24: |
| 4271 | case RTL_GIGA_MAC_VER_25: |
| 4272 | case RTL_GIGA_MAC_VER_26: |
| 4273 | ops->disable = r8168c_hw_jumbo_disable; |
| 4274 | ops->enable = r8168c_hw_jumbo_enable; |
| 4275 | break; |
| 4276 | case RTL_GIGA_MAC_VER_27: |
| 4277 | case RTL_GIGA_MAC_VER_28: |
| 4278 | ops->disable = r8168dp_hw_jumbo_disable; |
| 4279 | ops->enable = r8168dp_hw_jumbo_enable; |
| 4280 | break; |
| 4281 | case RTL_GIGA_MAC_VER_31: /* Wild guess. Needs info from Realtek. */ |
| 4282 | case RTL_GIGA_MAC_VER_32: |
| 4283 | case RTL_GIGA_MAC_VER_33: |
| 4284 | case RTL_GIGA_MAC_VER_34: |
| 4285 | ops->disable = r8168e_hw_jumbo_disable; |
| 4286 | ops->enable = r8168e_hw_jumbo_enable; |
| 4287 | break; |
| 4288 | |
| 4289 | /* |
| 4290 | * No action needed for jumbo frames with 8169. |
| 4291 | * No jumbo for 810x at all. |
| 4292 | */ |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4293 | case RTL_GIGA_MAC_VER_40: |
| 4294 | case RTL_GIGA_MAC_VER_41: |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4295 | default: |
| 4296 | ops->disable = NULL; |
| 4297 | ops->enable = NULL; |
| 4298 | break; |
| 4299 | } |
| 4300 | } |
| 4301 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4302 | DECLARE_RTL_COND(rtl_chipcmd_cond) |
| 4303 | { |
| 4304 | void __iomem *ioaddr = tp->mmio_addr; |
| 4305 | |
| 4306 | return RTL_R8(ChipCmd) & CmdReset; |
| 4307 | } |
| 4308 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4309 | static void rtl_hw_reset(struct rtl8169_private *tp) |
| 4310 | { |
| 4311 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4312 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4313 | RTL_W8(ChipCmd, CmdReset); |
| 4314 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4315 | rtl_udelay_loop_wait_low(tp, &rtl_chipcmd_cond, 100, 100); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4316 | } |
| 4317 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4318 | static void rtl_request_uncached_firmware(struct rtl8169_private *tp) |
| 4319 | { |
| 4320 | struct rtl_fw *rtl_fw; |
| 4321 | const char *name; |
| 4322 | int rc = -ENOMEM; |
| 4323 | |
| 4324 | name = rtl_lookup_firmware_name(tp); |
| 4325 | if (!name) |
| 4326 | goto out_no_firmware; |
| 4327 | |
| 4328 | rtl_fw = kzalloc(sizeof(*rtl_fw), GFP_KERNEL); |
| 4329 | if (!rtl_fw) |
| 4330 | goto err_warn; |
| 4331 | |
| 4332 | rc = request_firmware(&rtl_fw->fw, name, &tp->pci_dev->dev); |
| 4333 | if (rc < 0) |
| 4334 | goto err_free; |
| 4335 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 4336 | rc = rtl_check_firmware(tp, rtl_fw); |
| 4337 | if (rc < 0) |
| 4338 | goto err_release_firmware; |
| 4339 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4340 | tp->rtl_fw = rtl_fw; |
| 4341 | out: |
| 4342 | return; |
| 4343 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 4344 | err_release_firmware: |
| 4345 | release_firmware(rtl_fw->fw); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4346 | err_free: |
| 4347 | kfree(rtl_fw); |
| 4348 | err_warn: |
| 4349 | netif_warn(tp, ifup, tp->dev, "unable to load firmware patch %s (%d)\n", |
| 4350 | name, rc); |
| 4351 | out_no_firmware: |
| 4352 | tp->rtl_fw = NULL; |
| 4353 | goto out; |
| 4354 | } |
| 4355 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4356 | static void rtl_request_firmware(struct rtl8169_private *tp) |
| 4357 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4358 | if (IS_ERR(tp->rtl_fw)) |
| 4359 | rtl_request_uncached_firmware(tp); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4360 | } |
| 4361 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4362 | static void rtl_rx_close(struct rtl8169_private *tp) |
| 4363 | { |
| 4364 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4365 | |
Francois Romieu | 1687b56 | 2011-07-19 17:21:29 +0200 | [diff] [blame] | 4366 | RTL_W32(RxConfig, RTL_R32(RxConfig) & ~RX_CONFIG_ACCEPT_MASK); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4367 | } |
| 4368 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4369 | DECLARE_RTL_COND(rtl_npq_cond) |
| 4370 | { |
| 4371 | void __iomem *ioaddr = tp->mmio_addr; |
| 4372 | |
| 4373 | return RTL_R8(TxPoll) & NPQ; |
| 4374 | } |
| 4375 | |
| 4376 | DECLARE_RTL_COND(rtl_txcfg_empty_cond) |
| 4377 | { |
| 4378 | void __iomem *ioaddr = tp->mmio_addr; |
| 4379 | |
| 4380 | return RTL_R32(TxConfig) & TXCFG_EMPTY; |
| 4381 | } |
| 4382 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4383 | static void rtl8169_hw_reset(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4384 | { |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4385 | void __iomem *ioaddr = tp->mmio_addr; |
| 4386 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4387 | /* Disable interrupts */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 4388 | rtl8169_irq_mask_and_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4389 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4390 | rtl_rx_close(tp); |
| 4391 | |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 4392 | if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4393 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 4394 | tp->mac_version == RTL_GIGA_MAC_VER_31) { |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4395 | rtl_udelay_loop_wait_low(tp, &rtl_npq_cond, 20, 42*42); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4396 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_34 || |
| 4397 | tp->mac_version == RTL_GIGA_MAC_VER_35 || |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4398 | tp->mac_version == RTL_GIGA_MAC_VER_36 || |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4399 | tp->mac_version == RTL_GIGA_MAC_VER_37 || |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 4400 | tp->mac_version == RTL_GIGA_MAC_VER_40 || |
| 4401 | tp->mac_version == RTL_GIGA_MAC_VER_41 || |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4402 | tp->mac_version == RTL_GIGA_MAC_VER_38) { |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4403 | RTL_W8(ChipCmd, RTL_R8(ChipCmd) | StopReq); |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4404 | rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 666); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4405 | } else { |
| 4406 | RTL_W8(ChipCmd, RTL_R8(ChipCmd) | StopReq); |
| 4407 | udelay(100); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4408 | } |
| 4409 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4410 | rtl_hw_reset(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4411 | } |
| 4412 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4413 | static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4414 | { |
| 4415 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4416 | |
| 4417 | /* Set DMA burst size and Interframe Gap Time */ |
| 4418 | RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) | |
| 4419 | (InterFrameGap << TxInterFrameGapShift)); |
| 4420 | } |
| 4421 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4422 | static void rtl_hw_start(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4423 | { |
| 4424 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4425 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4426 | tp->hw_start(dev); |
| 4427 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4428 | rtl_irq_enable_all(tp); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4429 | } |
| 4430 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4431 | static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp, |
| 4432 | void __iomem *ioaddr) |
| 4433 | { |
| 4434 | /* |
| 4435 | * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh |
| 4436 | * register to be written before TxDescAddrLow to work. |
| 4437 | * Switching from MMIO to I/O access fixes the issue as well. |
| 4438 | */ |
| 4439 | RTL_W32(TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 4440 | RTL_W32(TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4441 | RTL_W32(RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 4442 | RTL_W32(RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4443 | } |
| 4444 | |
| 4445 | static u16 rtl_rw_cpluscmd(void __iomem *ioaddr) |
| 4446 | { |
| 4447 | u16 cmd; |
| 4448 | |
| 4449 | cmd = RTL_R16(CPlusCmd); |
| 4450 | RTL_W16(CPlusCmd, cmd); |
| 4451 | return cmd; |
| 4452 | } |
| 4453 | |
Eric Dumazet | fdd7b4c | 2009-06-09 04:01:02 -0700 | [diff] [blame] | 4454 | 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] | 4455 | { |
| 4456 | /* Low hurts. Let's disable the filtering. */ |
Raimonds Cicans | 207d6e87 | 2009-10-26 10:52:37 +0000 | [diff] [blame] | 4457 | RTL_W16(RxMaxSize, rx_buf_sz + 1); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4458 | } |
| 4459 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4460 | static void rtl8169_set_magic_reg(void __iomem *ioaddr, unsigned mac_version) |
| 4461 | { |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 4462 | static const struct rtl_cfg2_info { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4463 | u32 mac_version; |
| 4464 | u32 clk; |
| 4465 | u32 val; |
| 4466 | } cfg2_info [] = { |
| 4467 | { RTL_GIGA_MAC_VER_05, PCI_Clock_33MHz, 0x000fff00 }, // 8110SCd |
| 4468 | { RTL_GIGA_MAC_VER_05, PCI_Clock_66MHz, 0x000fffff }, |
| 4469 | { RTL_GIGA_MAC_VER_06, PCI_Clock_33MHz, 0x00ffff00 }, // 8110SCe |
| 4470 | { RTL_GIGA_MAC_VER_06, PCI_Clock_66MHz, 0x00ffffff } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 4471 | }; |
| 4472 | const struct rtl_cfg2_info *p = cfg2_info; |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4473 | unsigned int i; |
| 4474 | u32 clk; |
| 4475 | |
| 4476 | clk = RTL_R8(Config2) & PCI_Clock_66MHz; |
Francois Romieu | cadf185 | 2008-01-03 23:38:38 +0100 | [diff] [blame] | 4477 | for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4478 | if ((p->mac_version == mac_version) && (p->clk == clk)) { |
| 4479 | RTL_W32(0x7c, p->val); |
| 4480 | break; |
| 4481 | } |
| 4482 | } |
| 4483 | } |
| 4484 | |
Francois Romieu | e6b763e | 2012-03-08 09:35:39 +0100 | [diff] [blame] | 4485 | static void rtl_set_rx_mode(struct net_device *dev) |
| 4486 | { |
| 4487 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4488 | void __iomem *ioaddr = tp->mmio_addr; |
| 4489 | u32 mc_filter[2]; /* Multicast hash filter */ |
| 4490 | int rx_mode; |
| 4491 | u32 tmp = 0; |
| 4492 | |
| 4493 | if (dev->flags & IFF_PROMISC) { |
| 4494 | /* Unconditionally log net taps. */ |
| 4495 | netif_notice(tp, link, dev, "Promiscuous mode enabled\n"); |
| 4496 | rx_mode = |
| 4497 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys | |
| 4498 | AcceptAllPhys; |
| 4499 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 4500 | } else if ((netdev_mc_count(dev) > multicast_filter_limit) || |
| 4501 | (dev->flags & IFF_ALLMULTI)) { |
| 4502 | /* Too many to filter perfectly -- accept all multicasts. */ |
| 4503 | rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; |
| 4504 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 4505 | } else { |
| 4506 | struct netdev_hw_addr *ha; |
| 4507 | |
| 4508 | rx_mode = AcceptBroadcast | AcceptMyPhys; |
| 4509 | mc_filter[1] = mc_filter[0] = 0; |
| 4510 | netdev_for_each_mc_addr(ha, dev) { |
| 4511 | int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; |
| 4512 | mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); |
| 4513 | rx_mode |= AcceptMulticast; |
| 4514 | } |
| 4515 | } |
| 4516 | |
| 4517 | if (dev->features & NETIF_F_RXALL) |
| 4518 | rx_mode |= (AcceptErr | AcceptRunt); |
| 4519 | |
| 4520 | tmp = (RTL_R32(RxConfig) & ~RX_CONFIG_ACCEPT_MASK) | rx_mode; |
| 4521 | |
| 4522 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) { |
| 4523 | u32 data = mc_filter[0]; |
| 4524 | |
| 4525 | mc_filter[0] = swab32(mc_filter[1]); |
| 4526 | mc_filter[1] = swab32(data); |
| 4527 | } |
| 4528 | |
| 4529 | RTL_W32(MAR0 + 4, mc_filter[1]); |
| 4530 | RTL_W32(MAR0 + 0, mc_filter[0]); |
| 4531 | |
| 4532 | RTL_W32(RxConfig, tmp); |
| 4533 | } |
| 4534 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4535 | static void rtl_hw_start_8169(struct net_device *dev) |
| 4536 | { |
| 4537 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4538 | void __iomem *ioaddr = tp->mmio_addr; |
| 4539 | struct pci_dev *pdev = tp->pci_dev; |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4540 | |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4541 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) { |
| 4542 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) | PCIMulRW); |
| 4543 | pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, 0x08); |
| 4544 | } |
| 4545 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4546 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4547 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 || |
| 4548 | tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 4549 | tp->mac_version == RTL_GIGA_MAC_VER_03 || |
| 4550 | tp->mac_version == RTL_GIGA_MAC_VER_04) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4551 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 4552 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4553 | rtl_init_rxcfg(tp); |
| 4554 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 4555 | RTL_W8(EarlyTxThres, NoEarlyTx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4556 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4557 | rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4558 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4559 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 || |
| 4560 | tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 4561 | tp->mac_version == RTL_GIGA_MAC_VER_03 || |
| 4562 | tp->mac_version == RTL_GIGA_MAC_VER_04) |
Francois Romieu | c946b30 | 2007-10-04 00:42:50 +0200 | [diff] [blame] | 4563 | rtl_set_rx_tx_config_registers(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4564 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4565 | tp->cp_cmd |= rtl_rw_cpluscmd(ioaddr) | PCIMulRW; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4566 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4567 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 4568 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
Joe Perches | 06fa735 | 2007-10-18 21:15:00 +0200 | [diff] [blame] | 4569 | dprintk("Set MAC Reg C+CR Offset 0xE0. " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4570 | "Bit-3 and bit-14 MUST be 1\n"); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4571 | tp->cp_cmd |= (1 << 14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4572 | } |
| 4573 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4574 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 4575 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4576 | rtl8169_set_magic_reg(ioaddr, tp->mac_version); |
| 4577 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4578 | /* |
| 4579 | * Undocumented corner. Supposedly: |
| 4580 | * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets |
| 4581 | */ |
| 4582 | RTL_W16(IntrMitigate, 0x0000); |
| 4583 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4584 | rtl_set_rx_tx_desc_registers(tp, ioaddr); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4585 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4586 | if (tp->mac_version != RTL_GIGA_MAC_VER_01 && |
| 4587 | tp->mac_version != RTL_GIGA_MAC_VER_02 && |
| 4588 | tp->mac_version != RTL_GIGA_MAC_VER_03 && |
| 4589 | tp->mac_version != RTL_GIGA_MAC_VER_04) { |
Francois Romieu | c946b30 | 2007-10-04 00:42:50 +0200 | [diff] [blame] | 4590 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 4591 | rtl_set_rx_tx_config_registers(tp); |
| 4592 | } |
| 4593 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4594 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Francois Romieu | b518fa8 | 2006-08-16 15:23:13 +0200 | [diff] [blame] | 4595 | |
| 4596 | /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ |
| 4597 | RTL_R8(IntrMask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4598 | |
| 4599 | RTL_W32(RxMissed, 0); |
| 4600 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4601 | rtl_set_rx_mode(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4602 | |
| 4603 | /* no early-rx interrupts */ |
| 4604 | RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4605 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4606 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4607 | static void rtl_csi_write(struct rtl8169_private *tp, int addr, int value) |
| 4608 | { |
| 4609 | if (tp->csi_ops.write) |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 4610 | tp->csi_ops.write(tp, addr, value); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4611 | } |
| 4612 | |
| 4613 | static u32 rtl_csi_read(struct rtl8169_private *tp, int addr) |
| 4614 | { |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 4615 | return tp->csi_ops.read ? tp->csi_ops.read(tp, addr) : ~0; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4616 | } |
| 4617 | |
| 4618 | static void rtl_csi_access_enable(struct rtl8169_private *tp, u32 bits) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4619 | { |
| 4620 | u32 csi; |
| 4621 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4622 | csi = rtl_csi_read(tp, 0x070c) & 0x00ffffff; |
| 4623 | rtl_csi_write(tp, 0x070c, csi | bits); |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4624 | } |
| 4625 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4626 | static void rtl_csi_access_enable_1(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4627 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4628 | rtl_csi_access_enable(tp, 0x17000000); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4629 | } |
| 4630 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4631 | static void rtl_csi_access_enable_2(struct rtl8169_private *tp) |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4632 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4633 | rtl_csi_access_enable(tp, 0x27000000); |
| 4634 | } |
| 4635 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4636 | DECLARE_RTL_COND(rtl_csiar_cond) |
| 4637 | { |
| 4638 | void __iomem *ioaddr = tp->mmio_addr; |
| 4639 | |
| 4640 | return RTL_R32(CSIAR) & CSIAR_FLAG; |
| 4641 | } |
| 4642 | |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 4643 | 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] | 4644 | { |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 4645 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4646 | |
| 4647 | RTL_W32(CSIDR, value); |
| 4648 | RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
| 4649 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 4650 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4651 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4652 | } |
| 4653 | |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 4654 | static u32 r8169_csi_read(struct rtl8169_private *tp, int addr) |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4655 | { |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 4656 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4657 | |
| 4658 | RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) | |
| 4659 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 4660 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4661 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
| 4662 | RTL_R32(CSIDR) : ~0; |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4663 | } |
| 4664 | |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 4665 | 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] | 4666 | { |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 4667 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4668 | |
| 4669 | RTL_W32(CSIDR, value); |
| 4670 | RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
| 4671 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT | |
| 4672 | CSIAR_FUNC_NIC); |
| 4673 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4674 | rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4675 | } |
| 4676 | |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 4677 | static u32 r8402_csi_read(struct rtl8169_private *tp, int addr) |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4678 | { |
Francois Romieu | 52989f0 | 2012-07-06 13:37:00 +0200 | [diff] [blame] | 4679 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4680 | |
| 4681 | RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) | CSIAR_FUNC_NIC | |
| 4682 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 4683 | |
Francois Romieu | ffc4695 | 2012-07-06 14:19:23 +0200 | [diff] [blame] | 4684 | return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
| 4685 | RTL_R32(CSIDR) : ~0; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4686 | } |
| 4687 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4688 | static void __devinit rtl_init_csi_ops(struct rtl8169_private *tp) |
| 4689 | { |
| 4690 | struct csi_ops *ops = &tp->csi_ops; |
| 4691 | |
| 4692 | switch (tp->mac_version) { |
| 4693 | case RTL_GIGA_MAC_VER_01: |
| 4694 | case RTL_GIGA_MAC_VER_02: |
| 4695 | case RTL_GIGA_MAC_VER_03: |
| 4696 | case RTL_GIGA_MAC_VER_04: |
| 4697 | case RTL_GIGA_MAC_VER_05: |
| 4698 | case RTL_GIGA_MAC_VER_06: |
| 4699 | case RTL_GIGA_MAC_VER_10: |
| 4700 | case RTL_GIGA_MAC_VER_11: |
| 4701 | case RTL_GIGA_MAC_VER_12: |
| 4702 | case RTL_GIGA_MAC_VER_13: |
| 4703 | case RTL_GIGA_MAC_VER_14: |
| 4704 | case RTL_GIGA_MAC_VER_15: |
| 4705 | case RTL_GIGA_MAC_VER_16: |
| 4706 | case RTL_GIGA_MAC_VER_17: |
| 4707 | ops->write = NULL; |
| 4708 | ops->read = NULL; |
| 4709 | break; |
| 4710 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4711 | case RTL_GIGA_MAC_VER_37: |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 4712 | case RTL_GIGA_MAC_VER_38: |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 4713 | ops->write = r8402_csi_write; |
| 4714 | ops->read = r8402_csi_read; |
| 4715 | break; |
| 4716 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4717 | default: |
| 4718 | ops->write = r8169_csi_write; |
| 4719 | ops->read = r8169_csi_read; |
| 4720 | break; |
| 4721 | } |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4722 | } |
| 4723 | |
| 4724 | struct ephy_info { |
| 4725 | unsigned int offset; |
| 4726 | u16 mask; |
| 4727 | u16 bits; |
| 4728 | }; |
| 4729 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4730 | static void rtl_ephy_init(struct rtl8169_private *tp, const struct ephy_info *e, |
| 4731 | int len) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4732 | { |
| 4733 | u16 w; |
| 4734 | |
| 4735 | while (len-- > 0) { |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4736 | w = (rtl_ephy_read(tp, e->offset) & ~e->mask) | e->bits; |
| 4737 | rtl_ephy_write(tp, e->offset, w); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4738 | e++; |
| 4739 | } |
| 4740 | } |
| 4741 | |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4742 | static void rtl_disable_clock_request(struct pci_dev *pdev) |
| 4743 | { |
Jon Mason | e44daad | 2011-06-27 07:46:31 +0000 | [diff] [blame] | 4744 | int cap = pci_pcie_cap(pdev); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4745 | |
| 4746 | if (cap) { |
| 4747 | u16 ctl; |
| 4748 | |
| 4749 | pci_read_config_word(pdev, cap + PCI_EXP_LNKCTL, &ctl); |
| 4750 | ctl &= ~PCI_EXP_LNKCTL_CLKREQ_EN; |
| 4751 | pci_write_config_word(pdev, cap + PCI_EXP_LNKCTL, ctl); |
| 4752 | } |
| 4753 | } |
| 4754 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4755 | static void rtl_enable_clock_request(struct pci_dev *pdev) |
| 4756 | { |
Jon Mason | e44daad | 2011-06-27 07:46:31 +0000 | [diff] [blame] | 4757 | int cap = pci_pcie_cap(pdev); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4758 | |
| 4759 | if (cap) { |
| 4760 | u16 ctl; |
| 4761 | |
| 4762 | pci_read_config_word(pdev, cap + PCI_EXP_LNKCTL, &ctl); |
| 4763 | ctl |= PCI_EXP_LNKCTL_CLKREQ_EN; |
| 4764 | pci_write_config_word(pdev, cap + PCI_EXP_LNKCTL, ctl); |
| 4765 | } |
| 4766 | } |
| 4767 | |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4768 | #define R8168_CPCMD_QUIRK_MASK (\ |
| 4769 | EnableBist | \ |
| 4770 | Mac_dbgo_oe | \ |
| 4771 | Force_half_dup | \ |
| 4772 | Force_rxflow_en | \ |
| 4773 | Force_txflow_en | \ |
| 4774 | Cxpl_dbg_sel | \ |
| 4775 | ASF | \ |
| 4776 | PktCntrDisable | \ |
| 4777 | Mac_dbgo_sel) |
| 4778 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4779 | static void rtl_hw_start_8168bb(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4780 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4781 | void __iomem *ioaddr = tp->mmio_addr; |
| 4782 | struct pci_dev *pdev = tp->pci_dev; |
| 4783 | |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4784 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 4785 | |
| 4786 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 4787 | |
Francois Romieu | 2e68ae4 | 2008-06-28 12:00:55 +0200 | [diff] [blame] | 4788 | rtl_tx_performance_tweak(pdev, |
| 4789 | (0x5 << MAX_READ_REQUEST_SHIFT) | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4790 | } |
| 4791 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4792 | static void rtl_hw_start_8168bef(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4793 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4794 | void __iomem *ioaddr = tp->mmio_addr; |
| 4795 | |
| 4796 | rtl_hw_start_8168bb(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4797 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 4798 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4799 | |
| 4800 | RTL_W8(Config4, RTL_R8(Config4) & ~(1 << 0)); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4801 | } |
| 4802 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4803 | static void __rtl_hw_start_8168cp(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4804 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4805 | void __iomem *ioaddr = tp->mmio_addr; |
| 4806 | struct pci_dev *pdev = tp->pci_dev; |
| 4807 | |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4808 | RTL_W8(Config1, RTL_R8(Config1) | Speed_down); |
| 4809 | |
| 4810 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 4811 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4812 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4813 | |
| 4814 | rtl_disable_clock_request(pdev); |
| 4815 | |
| 4816 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4817 | } |
| 4818 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4819 | static void rtl_hw_start_8168cp_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4820 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4821 | static const struct ephy_info e_info_8168cp[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4822 | { 0x01, 0, 0x0001 }, |
| 4823 | { 0x02, 0x0800, 0x1000 }, |
| 4824 | { 0x03, 0, 0x0042 }, |
| 4825 | { 0x06, 0x0080, 0x0000 }, |
| 4826 | { 0x07, 0, 0x2000 } |
| 4827 | }; |
| 4828 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4829 | rtl_csi_access_enable_2(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4830 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4831 | rtl_ephy_init(tp, e_info_8168cp, ARRAY_SIZE(e_info_8168cp)); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4832 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4833 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4834 | } |
| 4835 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4836 | static void rtl_hw_start_8168cp_2(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4837 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4838 | void __iomem *ioaddr = tp->mmio_addr; |
| 4839 | struct pci_dev *pdev = tp->pci_dev; |
| 4840 | |
| 4841 | rtl_csi_access_enable_2(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4842 | |
| 4843 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 4844 | |
| 4845 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4846 | |
| 4847 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 4848 | } |
| 4849 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4850 | static void rtl_hw_start_8168cp_3(struct rtl8169_private *tp) |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4851 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4852 | void __iomem *ioaddr = tp->mmio_addr; |
| 4853 | struct pci_dev *pdev = tp->pci_dev; |
| 4854 | |
| 4855 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4856 | |
| 4857 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 4858 | |
| 4859 | /* Magic. */ |
| 4860 | RTL_W8(DBG_REG, 0x20); |
| 4861 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 4862 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4863 | |
| 4864 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4865 | |
| 4866 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 4867 | } |
| 4868 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4869 | static void rtl_hw_start_8168c_1(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4870 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4871 | void __iomem *ioaddr = tp->mmio_addr; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4872 | static const struct ephy_info e_info_8168c_1[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4873 | { 0x02, 0x0800, 0x1000 }, |
| 4874 | { 0x03, 0, 0x0002 }, |
| 4875 | { 0x06, 0x0080, 0x0000 } |
| 4876 | }; |
| 4877 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4878 | rtl_csi_access_enable_2(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4879 | |
| 4880 | RTL_W8(DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2); |
| 4881 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4882 | 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] | 4883 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4884 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4885 | } |
| 4886 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4887 | static void rtl_hw_start_8168c_2(struct rtl8169_private *tp) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4888 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4889 | static const struct ephy_info e_info_8168c_2[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4890 | { 0x01, 0, 0x0001 }, |
| 4891 | { 0x03, 0x0400, 0x0220 } |
| 4892 | }; |
| 4893 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4894 | rtl_csi_access_enable_2(tp); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4895 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4896 | 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] | 4897 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4898 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4899 | } |
| 4900 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4901 | static void rtl_hw_start_8168c_3(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4902 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4903 | rtl_hw_start_8168c_2(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4904 | } |
| 4905 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4906 | static void rtl_hw_start_8168c_4(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4907 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4908 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4909 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4910 | __rtl_hw_start_8168cp(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4911 | } |
| 4912 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4913 | static void rtl_hw_start_8168d(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4914 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4915 | void __iomem *ioaddr = tp->mmio_addr; |
| 4916 | struct pci_dev *pdev = tp->pci_dev; |
| 4917 | |
| 4918 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4919 | |
| 4920 | rtl_disable_clock_request(pdev); |
| 4921 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 4922 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4923 | |
| 4924 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4925 | |
| 4926 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 4927 | } |
| 4928 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4929 | static void rtl_hw_start_8168dp(struct rtl8169_private *tp) |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4930 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4931 | void __iomem *ioaddr = tp->mmio_addr; |
| 4932 | struct pci_dev *pdev = tp->pci_dev; |
| 4933 | |
| 4934 | rtl_csi_access_enable_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4935 | |
| 4936 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4937 | |
| 4938 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
| 4939 | |
| 4940 | rtl_disable_clock_request(pdev); |
| 4941 | } |
| 4942 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4943 | static void rtl_hw_start_8168d_4(struct rtl8169_private *tp) |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4944 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4945 | void __iomem *ioaddr = tp->mmio_addr; |
| 4946 | struct pci_dev *pdev = tp->pci_dev; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4947 | static const struct ephy_info e_info_8168d_4[] = { |
| 4948 | { 0x0b, ~0, 0x48 }, |
| 4949 | { 0x19, 0x20, 0x50 }, |
| 4950 | { 0x0c, ~0, 0x20 } |
| 4951 | }; |
| 4952 | int i; |
| 4953 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4954 | rtl_csi_access_enable_1(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4955 | |
| 4956 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4957 | |
| 4958 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
| 4959 | |
| 4960 | for (i = 0; i < ARRAY_SIZE(e_info_8168d_4); i++) { |
| 4961 | const struct ephy_info *e = e_info_8168d_4 + i; |
| 4962 | u16 w; |
| 4963 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4964 | w = rtl_ephy_read(tp, e->offset); |
| 4965 | rtl_ephy_write(tp, 0x03, (w & e->mask) | e->bits); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4966 | } |
| 4967 | |
| 4968 | rtl_enable_clock_request(pdev); |
| 4969 | } |
| 4970 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4971 | static void rtl_hw_start_8168e_1(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4972 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4973 | void __iomem *ioaddr = tp->mmio_addr; |
| 4974 | struct pci_dev *pdev = tp->pci_dev; |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4975 | static const struct ephy_info e_info_8168e_1[] = { |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4976 | { 0x00, 0x0200, 0x0100 }, |
| 4977 | { 0x00, 0x0000, 0x0004 }, |
| 4978 | { 0x06, 0x0002, 0x0001 }, |
| 4979 | { 0x06, 0x0000, 0x0030 }, |
| 4980 | { 0x07, 0x0000, 0x2000 }, |
| 4981 | { 0x00, 0x0000, 0x0020 }, |
| 4982 | { 0x03, 0x5800, 0x2000 }, |
| 4983 | { 0x03, 0x0000, 0x0001 }, |
| 4984 | { 0x01, 0x0800, 0x1000 }, |
| 4985 | { 0x07, 0x0000, 0x4000 }, |
| 4986 | { 0x1e, 0x0000, 0x2000 }, |
| 4987 | { 0x19, 0xffff, 0xfe6c }, |
| 4988 | { 0x0a, 0x0000, 0x0040 } |
| 4989 | }; |
| 4990 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 4991 | rtl_csi_access_enable_2(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4992 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 4993 | 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] | 4994 | |
| 4995 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4996 | |
| 4997 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
| 4998 | |
| 4999 | rtl_disable_clock_request(pdev); |
| 5000 | |
| 5001 | /* Reset tx FIFO pointer */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5002 | RTL_W32(MISC, RTL_R32(MISC) | TXPLA_RST); |
| 5003 | RTL_W32(MISC, RTL_R32(MISC) & ~TXPLA_RST); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5004 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5005 | RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5006 | } |
| 5007 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5008 | static void rtl_hw_start_8168e_2(struct rtl8169_private *tp) |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5009 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5010 | void __iomem *ioaddr = tp->mmio_addr; |
| 5011 | struct pci_dev *pdev = tp->pci_dev; |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5012 | static const struct ephy_info e_info_8168e_2[] = { |
| 5013 | { 0x09, 0x0000, 0x0080 }, |
| 5014 | { 0x19, 0x0000, 0x0224 } |
| 5015 | }; |
| 5016 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5017 | rtl_csi_access_enable_1(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5018 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5019 | 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] | 5020 | |
| 5021 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 5022 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5023 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5024 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5025 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 5026 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5027 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 5028 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x07ff0060, ERIAR_EXGMAC); |
| 5029 | rtl_w1w0_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 5030 | rtl_w1w0_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5031 | |
Hayes Wang | 3090bd9 | 2011-09-06 16:55:15 +0800 | [diff] [blame] | 5032 | RTL_W8(MaxTxPacketSize, EarlySize); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5033 | |
| 5034 | rtl_disable_clock_request(pdev); |
| 5035 | |
| 5036 | RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
| 5037 | RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB); |
| 5038 | |
| 5039 | /* Adjust EEE LED frequency */ |
| 5040 | RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07); |
| 5041 | |
| 5042 | RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN); |
| 5043 | RTL_W32(MISC, RTL_R32(MISC) | PWM_EN); |
| 5044 | RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en); |
| 5045 | } |
| 5046 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5047 | static void rtl_hw_start_8168f(struct rtl8169_private *tp) |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5048 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5049 | void __iomem *ioaddr = tp->mmio_addr; |
| 5050 | struct pci_dev *pdev = tp->pci_dev; |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5051 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5052 | rtl_csi_access_enable_2(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5053 | |
| 5054 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 5055 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5056 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5057 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5058 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 5059 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5060 | rtl_w1w0_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5061 | rtl_w1w0_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 5062 | rtl_w1w0_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 5063 | rtl_w1w0_eri(tp, 0x1d0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 5064 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 5065 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x00000060, ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5066 | |
| 5067 | RTL_W8(MaxTxPacketSize, EarlySize); |
| 5068 | |
| 5069 | rtl_disable_clock_request(pdev); |
| 5070 | |
| 5071 | RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
| 5072 | RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5073 | RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN); |
| 5074 | RTL_W32(MISC, RTL_R32(MISC) | PWM_EN); |
| 5075 | RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en); |
| 5076 | } |
| 5077 | |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5078 | static void rtl_hw_start_8168f_1(struct rtl8169_private *tp) |
| 5079 | { |
| 5080 | void __iomem *ioaddr = tp->mmio_addr; |
| 5081 | static const struct ephy_info e_info_8168f_1[] = { |
| 5082 | { 0x06, 0x00c0, 0x0020 }, |
| 5083 | { 0x08, 0x0001, 0x0002 }, |
| 5084 | { 0x09, 0x0000, 0x0080 }, |
| 5085 | { 0x19, 0x0000, 0x0224 } |
| 5086 | }; |
| 5087 | |
| 5088 | rtl_hw_start_8168f(tp); |
| 5089 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5090 | 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] | 5091 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5092 | rtl_w1w0_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 5f886e0 | 2012-03-30 14:33:03 +0800 | [diff] [blame] | 5093 | |
| 5094 | /* Adjust EEE LED frequency */ |
| 5095 | RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07); |
| 5096 | } |
| 5097 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5098 | static void rtl_hw_start_8411(struct rtl8169_private *tp) |
| 5099 | { |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5100 | static const struct ephy_info e_info_8168f_1[] = { |
| 5101 | { 0x06, 0x00c0, 0x0020 }, |
| 5102 | { 0x0f, 0xffff, 0x5200 }, |
| 5103 | { 0x1e, 0x0000, 0x4000 }, |
| 5104 | { 0x19, 0x0000, 0x0224 } |
| 5105 | }; |
| 5106 | |
| 5107 | rtl_hw_start_8168f(tp); |
| 5108 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5109 | 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] | 5110 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5111 | rtl_w1w0_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0x0000, ERIAR_EXGMAC); |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5112 | } |
| 5113 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5114 | static void rtl_hw_start_8168g_1(struct rtl8169_private *tp) |
| 5115 | { |
| 5116 | void __iomem *ioaddr = tp->mmio_addr; |
| 5117 | struct pci_dev *pdev = tp->pci_dev; |
| 5118 | |
| 5119 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x080002, ERIAR_EXGMAC); |
| 5120 | rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC); |
| 5121 | rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC); |
| 5122 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 5123 | |
| 5124 | rtl_csi_access_enable_1(tp); |
| 5125 | |
| 5126 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 5127 | |
| 5128 | rtl_w1w0_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5129 | rtl_w1w0_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 5130 | |
| 5131 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 5132 | RTL_W32(MISC, RTL_R32(MISC) & ~RXDV_GATED_EN); |
| 5133 | RTL_W8(MaxTxPacketSize, EarlySize); |
| 5134 | |
| 5135 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5136 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5137 | |
| 5138 | /* Adjust EEE LED frequency */ |
| 5139 | RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07); |
| 5140 | |
| 5141 | rtl_w1w0_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x02, ERIAR_EXGMAC); |
| 5142 | } |
| 5143 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5144 | static void rtl_hw_start_8168(struct net_device *dev) |
| 5145 | { |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5146 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5147 | void __iomem *ioaddr = tp->mmio_addr; |
| 5148 | |
| 5149 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 5150 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 5151 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5152 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5153 | rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5154 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5155 | tp->cp_cmd |= RTL_R16(CPlusCmd) | PktCntrDisable | INTT_1; |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5156 | |
| 5157 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 5158 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5159 | RTL_W16(IntrMitigate, 0x5151); |
| 5160 | |
| 5161 | /* Work around for RxFIFO overflow. */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 5162 | if (tp->mac_version == RTL_GIGA_MAC_VER_11) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5163 | tp->event_slow |= RxFIFOOver | PCSTimeout; |
| 5164 | tp->event_slow &= ~RxOverflow; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5165 | } |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5166 | |
| 5167 | rtl_set_rx_tx_desc_registers(tp, ioaddr); |
| 5168 | |
Francois Romieu | b836390 | 2008-06-01 12:31:57 +0200 | [diff] [blame] | 5169 | rtl_set_rx_mode(dev); |
| 5170 | |
| 5171 | RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) | |
| 5172 | (InterFrameGap << TxInterFrameGapShift)); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5173 | |
| 5174 | RTL_R8(IntrMask); |
| 5175 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5176 | switch (tp->mac_version) { |
| 5177 | case RTL_GIGA_MAC_VER_11: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5178 | rtl_hw_start_8168bb(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5179 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5180 | |
| 5181 | case RTL_GIGA_MAC_VER_12: |
| 5182 | case RTL_GIGA_MAC_VER_17: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5183 | rtl_hw_start_8168bef(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5184 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5185 | |
| 5186 | case RTL_GIGA_MAC_VER_18: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5187 | rtl_hw_start_8168cp_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5188 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5189 | |
| 5190 | case RTL_GIGA_MAC_VER_19: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5191 | rtl_hw_start_8168c_1(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5192 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5193 | |
| 5194 | case RTL_GIGA_MAC_VER_20: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5195 | rtl_hw_start_8168c_2(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5196 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5197 | |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5198 | case RTL_GIGA_MAC_VER_21: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5199 | rtl_hw_start_8168c_3(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5200 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 5201 | |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5202 | case RTL_GIGA_MAC_VER_22: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5203 | rtl_hw_start_8168c_4(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5204 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 5205 | |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5206 | case RTL_GIGA_MAC_VER_23: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5207 | rtl_hw_start_8168cp_2(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5208 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 5209 | |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5210 | case RTL_GIGA_MAC_VER_24: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5211 | rtl_hw_start_8168cp_3(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5212 | break; |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5213 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5214 | case RTL_GIGA_MAC_VER_25: |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 5215 | case RTL_GIGA_MAC_VER_26: |
| 5216 | case RTL_GIGA_MAC_VER_27: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5217 | rtl_hw_start_8168d(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5218 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5219 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5220 | case RTL_GIGA_MAC_VER_28: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5221 | rtl_hw_start_8168d_4(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5222 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5223 | |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5224 | case RTL_GIGA_MAC_VER_31: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5225 | rtl_hw_start_8168dp(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5226 | break; |
| 5227 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5228 | case RTL_GIGA_MAC_VER_32: |
| 5229 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5230 | rtl_hw_start_8168e_1(tp); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5231 | break; |
| 5232 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5233 | rtl_hw_start_8168e_2(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5234 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5235 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5236 | case RTL_GIGA_MAC_VER_35: |
| 5237 | case RTL_GIGA_MAC_VER_36: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5238 | rtl_hw_start_8168f_1(tp); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5239 | break; |
| 5240 | |
Hayes Wang | b3d7b2f | 2012-03-30 14:48:06 +0800 | [diff] [blame] | 5241 | case RTL_GIGA_MAC_VER_38: |
| 5242 | rtl_hw_start_8411(tp); |
| 5243 | break; |
| 5244 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 5245 | case RTL_GIGA_MAC_VER_40: |
| 5246 | case RTL_GIGA_MAC_VER_41: |
| 5247 | rtl_hw_start_8168g_1(tp); |
| 5248 | break; |
| 5249 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5250 | default: |
| 5251 | printk(KERN_ERR PFX "%s: unknown chipset (mac_version = %d).\n", |
| 5252 | dev->name, tp->mac_version); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5253 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5254 | } |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5255 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5256 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 5257 | |
Francois Romieu | b836390 | 2008-06-01 12:31:57 +0200 | [diff] [blame] | 5258 | RTL_W8(Cfg9346, Cfg9346_Lock); |
| 5259 | |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5260 | RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5261 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5262 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5263 | #define R810X_CPCMD_QUIRK_MASK (\ |
| 5264 | EnableBist | \ |
| 5265 | Mac_dbgo_oe | \ |
| 5266 | Force_half_dup | \ |
françois romieu | 5edcc53 | 2009-08-10 19:41:52 +0000 | [diff] [blame] | 5267 | Force_rxflow_en | \ |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5268 | Force_txflow_en | \ |
| 5269 | Cxpl_dbg_sel | \ |
| 5270 | ASF | \ |
| 5271 | PktCntrDisable | \ |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 5272 | Mac_dbgo_sel) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5273 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5274 | static void rtl_hw_start_8102e_1(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5275 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5276 | void __iomem *ioaddr = tp->mmio_addr; |
| 5277 | struct pci_dev *pdev = tp->pci_dev; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5278 | static const struct ephy_info e_info_8102e_1[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5279 | { 0x01, 0, 0x6e65 }, |
| 5280 | { 0x02, 0, 0x091f }, |
| 5281 | { 0x03, 0, 0xc2f9 }, |
| 5282 | { 0x06, 0, 0xafb5 }, |
| 5283 | { 0x07, 0, 0x0e00 }, |
| 5284 | { 0x19, 0, 0xec80 }, |
| 5285 | { 0x01, 0, 0x2e65 }, |
| 5286 | { 0x01, 0, 0x6e65 } |
| 5287 | }; |
| 5288 | u8 cfg1; |
| 5289 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5290 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5291 | |
| 5292 | RTL_W8(DBG_REG, FIX_NAK_1); |
| 5293 | |
| 5294 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 5295 | |
| 5296 | RTL_W8(Config1, |
| 5297 | LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable); |
| 5298 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 5299 | |
| 5300 | cfg1 = RTL_R8(Config1); |
| 5301 | if ((cfg1 & LEDS0) && (cfg1 & LEDS1)) |
| 5302 | RTL_W8(Config1, cfg1 & ~LEDS0); |
| 5303 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5304 | 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] | 5305 | } |
| 5306 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5307 | static void rtl_hw_start_8102e_2(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5308 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5309 | void __iomem *ioaddr = tp->mmio_addr; |
| 5310 | struct pci_dev *pdev = tp->pci_dev; |
| 5311 | |
| 5312 | rtl_csi_access_enable_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5313 | |
| 5314 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 5315 | |
| 5316 | RTL_W8(Config1, MEMMAP | IOMAP | VPD | PMEnable); |
| 5317 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5318 | } |
| 5319 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5320 | static void rtl_hw_start_8102e_3(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5321 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5322 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5323 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5324 | rtl_ephy_write(tp, 0x03, 0xc2f9); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5325 | } |
| 5326 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5327 | static void rtl_hw_start_8105e_1(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5328 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5329 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5330 | static const struct ephy_info e_info_8105e_1[] = { |
| 5331 | { 0x07, 0, 0x4000 }, |
| 5332 | { 0x19, 0, 0x0200 }, |
| 5333 | { 0x19, 0, 0x0020 }, |
| 5334 | { 0x1e, 0, 0x2000 }, |
| 5335 | { 0x03, 0, 0x0001 }, |
| 5336 | { 0x19, 0, 0x0100 }, |
| 5337 | { 0x19, 0, 0x0004 }, |
| 5338 | { 0x0a, 0, 0x0020 } |
| 5339 | }; |
| 5340 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5341 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5342 | RTL_W32(FuncEvent, RTL_R32(FuncEvent) | 0x002800); |
| 5343 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5344 | /* Disable Early Tally Counter */ |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5345 | RTL_W32(FuncEvent, RTL_R32(FuncEvent) & ~0x010000); |
| 5346 | |
| 5347 | RTL_W8(MCU, RTL_R8(MCU) | EN_NDP | EN_OOB_RESET); |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 5348 | RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5349 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5350 | rtl_ephy_init(tp, e_info_8105e_1, ARRAY_SIZE(e_info_8105e_1)); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5351 | } |
| 5352 | |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5353 | static void rtl_hw_start_8105e_2(struct rtl8169_private *tp) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5354 | { |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5355 | rtl_hw_start_8105e_1(tp); |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5356 | rtl_ephy_write(tp, 0x1e, rtl_ephy_read(tp, 0x1e) | 0x8000); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5357 | } |
| 5358 | |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5359 | static void rtl_hw_start_8402(struct rtl8169_private *tp) |
| 5360 | { |
| 5361 | void __iomem *ioaddr = tp->mmio_addr; |
| 5362 | static const struct ephy_info e_info_8402[] = { |
| 5363 | { 0x19, 0xffff, 0xff64 }, |
| 5364 | { 0x1e, 0, 0x4000 } |
| 5365 | }; |
| 5366 | |
| 5367 | rtl_csi_access_enable_2(tp); |
| 5368 | |
| 5369 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
| 5370 | RTL_W32(FuncEvent, RTL_R32(FuncEvent) | 0x002800); |
| 5371 | |
| 5372 | RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
| 5373 | RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB); |
| 5374 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5375 | rtl_ephy_init(tp, e_info_8402, ARRAY_SIZE(e_info_8402)); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5376 | |
| 5377 | rtl_tx_performance_tweak(tp->pci_dev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 5378 | |
Francois Romieu | fdf6fc0 | 2012-07-06 22:40:38 +0200 | [diff] [blame] | 5379 | rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00000002, ERIAR_EXGMAC); |
| 5380 | rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00000006, ERIAR_EXGMAC); |
| 5381 | rtl_w1w0_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 5382 | rtl_w1w0_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 5383 | rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5384 | rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 5385 | rtl_w1w0_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0e00, 0xff00, ERIAR_EXGMAC); |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5386 | } |
| 5387 | |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5388 | static void rtl_hw_start_8106(struct rtl8169_private *tp) |
| 5389 | { |
| 5390 | void __iomem *ioaddr = tp->mmio_addr; |
| 5391 | |
| 5392 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
| 5393 | RTL_W32(FuncEvent, RTL_R32(FuncEvent) | 0x002800); |
| 5394 | |
| 5395 | RTL_W32(MISC, (RTL_R32(MISC) | DISABLE_LAN_EN) & ~EARLY_TALLY_EN); |
| 5396 | RTL_W8(MCU, RTL_R8(MCU) | EN_NDP | EN_OOB_RESET); |
| 5397 | RTL_W8(DLLPR, RTL_R8(DLLPR) & ~PFM_EN); |
| 5398 | } |
| 5399 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5400 | static void rtl_hw_start_8101(struct net_device *dev) |
| 5401 | { |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5402 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5403 | void __iomem *ioaddr = tp->mmio_addr; |
| 5404 | struct pci_dev *pdev = tp->pci_dev; |
| 5405 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5406 | if (tp->mac_version >= RTL_GIGA_MAC_VER_30) |
| 5407 | tp->event_slow &= ~RxFIFOOver; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 5408 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5409 | if (tp->mac_version == RTL_GIGA_MAC_VER_13 || |
| 5410 | tp->mac_version == RTL_GIGA_MAC_VER_16) { |
Jon Mason | e44daad | 2011-06-27 07:46:31 +0000 | [diff] [blame] | 5411 | int cap = pci_pcie_cap(pdev); |
Francois Romieu | 9c14cea | 2008-07-05 00:21:15 +0200 | [diff] [blame] | 5412 | |
| 5413 | if (cap) { |
| 5414 | pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, |
| 5415 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 5416 | } |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5417 | } |
| 5418 | |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 5419 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 5420 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5421 | switch (tp->mac_version) { |
| 5422 | case RTL_GIGA_MAC_VER_07: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5423 | rtl_hw_start_8102e_1(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5424 | break; |
| 5425 | |
| 5426 | case RTL_GIGA_MAC_VER_08: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5427 | rtl_hw_start_8102e_3(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5428 | break; |
| 5429 | |
| 5430 | case RTL_GIGA_MAC_VER_09: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5431 | rtl_hw_start_8102e_2(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5432 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5433 | |
| 5434 | case RTL_GIGA_MAC_VER_29: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5435 | rtl_hw_start_8105e_1(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5436 | break; |
| 5437 | case RTL_GIGA_MAC_VER_30: |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 5438 | rtl_hw_start_8105e_2(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5439 | break; |
Hayes Wang | 7e18dca | 2012-03-30 14:33:02 +0800 | [diff] [blame] | 5440 | |
| 5441 | case RTL_GIGA_MAC_VER_37: |
| 5442 | rtl_hw_start_8402(tp); |
| 5443 | break; |
Hayes Wang | 5598bfe | 2012-07-02 17:23:21 +0800 | [diff] [blame] | 5444 | |
| 5445 | case RTL_GIGA_MAC_VER_39: |
| 5446 | rtl_hw_start_8106(tp); |
| 5447 | break; |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5448 | } |
| 5449 | |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 5450 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5451 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 5452 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5453 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5454 | rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5455 | |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 5456 | tp->cp_cmd &= ~R810X_CPCMD_QUIRK_MASK; |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5457 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 5458 | |
| 5459 | RTL_W16(IntrMitigate, 0x0000); |
| 5460 | |
| 5461 | rtl_set_rx_tx_desc_registers(tp, ioaddr); |
| 5462 | |
| 5463 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 5464 | rtl_set_rx_tx_config_registers(tp); |
| 5465 | |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5466 | RTL_R8(IntrMask); |
| 5467 | |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5468 | rtl_set_rx_mode(dev); |
| 5469 | |
| 5470 | RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5471 | } |
| 5472 | |
| 5473 | static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) |
| 5474 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5475 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5476 | |
| 5477 | if (new_mtu < ETH_ZLEN || |
| 5478 | new_mtu > rtl_chip_infos[tp->mac_version].jumbo_max) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5479 | return -EINVAL; |
| 5480 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5481 | if (new_mtu > ETH_DATA_LEN) |
| 5482 | rtl_hw_jumbo_enable(tp); |
| 5483 | else |
| 5484 | rtl_hw_jumbo_disable(tp); |
| 5485 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5486 | dev->mtu = new_mtu; |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 5487 | netdev_update_features(dev); |
| 5488 | |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 5489 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5490 | } |
| 5491 | |
| 5492 | static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc) |
| 5493 | { |
Al Viro | 95e0918 | 2007-12-22 18:55:39 +0000 | [diff] [blame] | 5494 | desc->addr = cpu_to_le64(0x0badbadbadbadbadull); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5495 | desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask); |
| 5496 | } |
| 5497 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5498 | static void rtl8169_free_rx_databuff(struct rtl8169_private *tp, |
| 5499 | void **data_buff, struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5500 | { |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5501 | 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] | 5502 | DMA_FROM_DEVICE); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5503 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5504 | kfree(*data_buff); |
| 5505 | *data_buff = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5506 | rtl8169_make_unusable_by_asic(desc); |
| 5507 | } |
| 5508 | |
| 5509 | static inline void rtl8169_mark_to_asic(struct RxDesc *desc, u32 rx_buf_sz) |
| 5510 | { |
| 5511 | u32 eor = le32_to_cpu(desc->opts1) & RingEnd; |
| 5512 | |
| 5513 | desc->opts1 = cpu_to_le32(DescOwn | eor | rx_buf_sz); |
| 5514 | } |
| 5515 | |
| 5516 | static inline void rtl8169_map_to_asic(struct RxDesc *desc, dma_addr_t mapping, |
| 5517 | u32 rx_buf_sz) |
| 5518 | { |
| 5519 | desc->addr = cpu_to_le64(mapping); |
| 5520 | wmb(); |
| 5521 | rtl8169_mark_to_asic(desc, rx_buf_sz); |
| 5522 | } |
| 5523 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5524 | static inline void *rtl8169_align(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5525 | { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5526 | return (void *)ALIGN((long)data, 16); |
| 5527 | } |
| 5528 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5529 | static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp, |
| 5530 | struct RxDesc *desc) |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5531 | { |
| 5532 | void *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5533 | dma_addr_t mapping; |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5534 | struct device *d = &tp->pci_dev->dev; |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5535 | struct net_device *dev = tp->dev; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5536 | int node = dev->dev.parent ? dev_to_node(dev->dev.parent) : -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5537 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5538 | data = kmalloc_node(rx_buf_sz, GFP_KERNEL, node); |
| 5539 | if (!data) |
| 5540 | return NULL; |
Francois Romieu | e9f63f3 | 2007-02-28 23:16:57 +0100 | [diff] [blame] | 5541 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5542 | if (rtl8169_align(data) != data) { |
| 5543 | kfree(data); |
| 5544 | data = kmalloc_node(rx_buf_sz + 15, GFP_KERNEL, node); |
| 5545 | if (!data) |
| 5546 | return NULL; |
| 5547 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5548 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5549 | mapping = dma_map_single(d, rtl8169_align(data), rx_buf_sz, |
Stanislaw Gruszka | 231aee6 | 2010-10-20 22:25:38 +0000 | [diff] [blame] | 5550 | DMA_FROM_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5551 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 5552 | if (net_ratelimit()) |
| 5553 | netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5554 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5555 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5556 | |
| 5557 | rtl8169_map_to_asic(desc, mapping, rx_buf_sz); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5558 | return data; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5559 | |
| 5560 | err_out: |
| 5561 | kfree(data); |
| 5562 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5563 | } |
| 5564 | |
| 5565 | static void rtl8169_rx_clear(struct rtl8169_private *tp) |
| 5566 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5567 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5568 | |
| 5569 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5570 | if (tp->Rx_databuff[i]) { |
| 5571 | rtl8169_free_rx_databuff(tp, tp->Rx_databuff + i, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5572 | tp->RxDescArray + i); |
| 5573 | } |
| 5574 | } |
| 5575 | } |
| 5576 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5577 | static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5578 | { |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5579 | desc->opts1 |= cpu_to_le32(RingEnd); |
| 5580 | } |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 5581 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5582 | static int rtl8169_rx_fill(struct rtl8169_private *tp) |
| 5583 | { |
| 5584 | unsigned int i; |
| 5585 | |
| 5586 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5587 | void *data; |
Francois Romieu | 4ae47c2 | 2007-06-16 23:28:45 +0200 | [diff] [blame] | 5588 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5589 | if (tp->Rx_databuff[i]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5590 | continue; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5591 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5592 | data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5593 | if (!data) { |
| 5594 | rtl8169_make_unusable_by_asic(tp->RxDescArray + i); |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5595 | goto err_out; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5596 | } |
| 5597 | tp->Rx_databuff[i] = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5598 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5599 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5600 | rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1); |
| 5601 | return 0; |
| 5602 | |
| 5603 | err_out: |
| 5604 | rtl8169_rx_clear(tp); |
| 5605 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5606 | } |
| 5607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5608 | static int rtl8169_init_ring(struct net_device *dev) |
| 5609 | { |
| 5610 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5611 | |
| 5612 | rtl8169_init_ring_indexes(tp); |
| 5613 | |
| 5614 | memset(tp->tx_skb, 0x0, NUM_TX_DESC * sizeof(struct ring_info)); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5615 | memset(tp->Rx_databuff, 0x0, NUM_RX_DESC * sizeof(void *)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5616 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5617 | return rtl8169_rx_fill(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5618 | } |
| 5619 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5620 | 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] | 5621 | struct TxDesc *desc) |
| 5622 | { |
| 5623 | unsigned int len = tx_skb->len; |
| 5624 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5625 | dma_unmap_single(d, le64_to_cpu(desc->addr), len, DMA_TO_DEVICE); |
| 5626 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5627 | desc->opts1 = 0x00; |
| 5628 | desc->opts2 = 0x00; |
| 5629 | desc->addr = 0x00; |
| 5630 | tx_skb->len = 0; |
| 5631 | } |
| 5632 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5633 | static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, |
| 5634 | unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5635 | { |
| 5636 | unsigned int i; |
| 5637 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5638 | for (i = 0; i < n; i++) { |
| 5639 | unsigned int entry = (start + i) % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5640 | struct ring_info *tx_skb = tp->tx_skb + entry; |
| 5641 | unsigned int len = tx_skb->len; |
| 5642 | |
| 5643 | if (len) { |
| 5644 | struct sk_buff *skb = tx_skb->skb; |
| 5645 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5646 | rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5647 | tp->TxDescArray + entry); |
| 5648 | if (skb) { |
Stanislaw Gruszka | cac4b22 | 2010-10-20 22:25:40 +0000 | [diff] [blame] | 5649 | tp->dev->stats.tx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5650 | dev_kfree_skb(skb); |
| 5651 | tx_skb->skb = NULL; |
| 5652 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5653 | } |
| 5654 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5655 | } |
| 5656 | |
| 5657 | static void rtl8169_tx_clear(struct rtl8169_private *tp) |
| 5658 | { |
| 5659 | rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5660 | tp->cur_tx = tp->dirty_tx = 0; |
| 5661 | } |
| 5662 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 5663 | static void rtl_reset_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5664 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5665 | struct net_device *dev = tp->dev; |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5666 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5667 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5668 | napi_disable(&tp->napi); |
| 5669 | netif_stop_queue(dev); |
| 5670 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5671 | |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 5672 | rtl8169_hw_reset(tp); |
| 5673 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5674 | for (i = 0; i < NUM_RX_DESC; i++) |
| 5675 | rtl8169_mark_to_asic(tp->RxDescArray + i, rx_buf_sz); |
| 5676 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5677 | rtl8169_tx_clear(tp); |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 5678 | rtl8169_init_ring_indexes(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5679 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5680 | napi_enable(&tp->napi); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5681 | rtl_hw_start(dev); |
| 5682 | netif_wake_queue(dev); |
| 5683 | rtl8169_check_link_status(dev, tp, tp->mmio_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5684 | } |
| 5685 | |
| 5686 | static void rtl8169_tx_timeout(struct net_device *dev) |
| 5687 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5688 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5689 | |
| 5690 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5691 | } |
| 5692 | |
| 5693 | 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] | 5694 | u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5695 | { |
| 5696 | struct skb_shared_info *info = skb_shinfo(skb); |
| 5697 | unsigned int cur_frag, entry; |
Jeff Garzik | a6343af | 2007-07-17 05:39:58 -0400 | [diff] [blame] | 5698 | struct TxDesc * uninitialized_var(txd); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5699 | struct device *d = &tp->pci_dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5700 | |
| 5701 | entry = tp->cur_tx; |
| 5702 | for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5703 | const skb_frag_t *frag = info->frags + cur_frag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5704 | dma_addr_t mapping; |
| 5705 | u32 status, len; |
| 5706 | void *addr; |
| 5707 | |
| 5708 | entry = (entry + 1) % NUM_TX_DESC; |
| 5709 | |
| 5710 | txd = tp->TxDescArray + entry; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5711 | len = skb_frag_size(frag); |
Ian Campbell | 929f618 | 2011-08-31 00:47:06 +0000 | [diff] [blame] | 5712 | addr = skb_frag_address(frag); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5713 | mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5714 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 5715 | if (net_ratelimit()) |
| 5716 | netif_err(tp, drv, tp->dev, |
| 5717 | "Failed to map TX fragments DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5718 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5719 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5720 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5721 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5722 | status = opts[0] | len | |
| 5723 | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5724 | |
| 5725 | txd->opts1 = cpu_to_le32(status); |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5726 | txd->opts2 = cpu_to_le32(opts[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5727 | txd->addr = cpu_to_le64(mapping); |
| 5728 | |
| 5729 | tp->tx_skb[entry].len = len; |
| 5730 | } |
| 5731 | |
| 5732 | if (cur_frag) { |
| 5733 | tp->tx_skb[entry].skb = skb; |
| 5734 | txd->opts1 |= cpu_to_le32(LastFrag); |
| 5735 | } |
| 5736 | |
| 5737 | return cur_frag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5738 | |
| 5739 | err_out: |
| 5740 | rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag); |
| 5741 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5742 | } |
| 5743 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5744 | static inline void rtl8169_tso_csum(struct rtl8169_private *tp, |
| 5745 | struct sk_buff *skb, u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5746 | { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5747 | const struct rtl_tx_desc_info *info = tx_desc_info + tp->txd_version; |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 5748 | u32 mss = skb_shinfo(skb)->gso_size; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5749 | int offset = info->opts_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5750 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5751 | if (mss) { |
| 5752 | opts[0] |= TD_LSO; |
| 5753 | opts[offset] |= min(mss, TD_MSS_MAX) << info->mss_shift; |
| 5754 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5755 | const struct iphdr *ip = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5756 | |
| 5757 | if (ip->protocol == IPPROTO_TCP) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5758 | opts[offset] |= info->checksum.tcp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5759 | else if (ip->protocol == IPPROTO_UDP) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5760 | opts[offset] |= info->checksum.udp; |
| 5761 | else |
| 5762 | WARN_ON_ONCE(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5763 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5764 | } |
| 5765 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5766 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 5767 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5768 | { |
| 5769 | struct rtl8169_private *tp = netdev_priv(dev); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5770 | unsigned int entry = tp->cur_tx % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5771 | struct TxDesc *txd = tp->TxDescArray + entry; |
| 5772 | void __iomem *ioaddr = tp->mmio_addr; |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5773 | struct device *d = &tp->pci_dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5774 | dma_addr_t mapping; |
| 5775 | u32 status, len; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5776 | u32 opts[2]; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5777 | int frags; |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 5778 | |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 5779 | if (unlikely(!TX_FRAGS_READY_FOR(tp, skb_shinfo(skb)->nr_frags))) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 5780 | 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] | 5781 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5782 | } |
| 5783 | |
| 5784 | if (unlikely(le32_to_cpu(txd->opts1) & DescOwn)) |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5785 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5786 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5787 | len = skb_headlen(skb); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5788 | mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5789 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 5790 | if (net_ratelimit()) |
| 5791 | netif_err(tp, drv, dev, "Failed to map TX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5792 | goto err_dma_0; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5793 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5794 | |
| 5795 | tp->tx_skb[entry].len = len; |
| 5796 | txd->addr = cpu_to_le64(mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5797 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5798 | opts[1] = cpu_to_le32(rtl8169_tx_vlan_tag(tp, skb)); |
| 5799 | opts[0] = DescOwn; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5800 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5801 | rtl8169_tso_csum(tp, skb, opts); |
| 5802 | |
| 5803 | frags = rtl8169_xmit_frags(tp, skb, opts); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5804 | if (frags < 0) |
| 5805 | goto err_dma_1; |
| 5806 | else if (frags) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5807 | opts[0] |= FirstFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5808 | else { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5809 | opts[0] |= FirstFrag | LastFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5810 | tp->tx_skb[entry].skb = skb; |
| 5811 | } |
| 5812 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5813 | txd->opts2 = cpu_to_le32(opts[1]); |
| 5814 | |
Richard Cochran | 5047fb5 | 2012-03-10 07:29:42 +0000 | [diff] [blame] | 5815 | skb_tx_timestamp(skb); |
| 5816 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5817 | wmb(); |
| 5818 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5819 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5820 | status = opts[0] | len | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5821 | txd->opts1 = cpu_to_le32(status); |
| 5822 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5823 | tp->cur_tx += frags + 1; |
| 5824 | |
David Dillow | 4c020a9 | 2010-03-03 16:33:10 +0000 | [diff] [blame] | 5825 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5826 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5827 | RTL_W8(TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5828 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5829 | mmiowb(); |
| 5830 | |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 5831 | if (!TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 5832 | /* Avoid wrongly optimistic queue wake-up: rtl_tx thread must |
| 5833 | * not miss a ring update when it notices a stopped queue. |
| 5834 | */ |
| 5835 | smp_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5836 | netif_stop_queue(dev); |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 5837 | /* Sync with rtl_tx: |
| 5838 | * - publish queue status and cur_tx ring index (write barrier) |
| 5839 | * - refresh dirty_tx ring index (read barrier). |
| 5840 | * May the current thread have a pessimistic view of the ring |
| 5841 | * status and forget to wake up queue, a racing rtl_tx thread |
| 5842 | * can't. |
| 5843 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 5844 | smp_mb(); |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 5845 | if (TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5846 | netif_wake_queue(dev); |
| 5847 | } |
| 5848 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5849 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5850 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5851 | err_dma_1: |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5852 | rtl8169_unmap_tx_skb(d, tp->tx_skb + entry, txd); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5853 | err_dma_0: |
| 5854 | dev_kfree_skb(skb); |
| 5855 | dev->stats.tx_dropped++; |
| 5856 | return NETDEV_TX_OK; |
| 5857 | |
| 5858 | err_stop_0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5859 | netif_stop_queue(dev); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5860 | dev->stats.tx_dropped++; |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5861 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5862 | } |
| 5863 | |
| 5864 | static void rtl8169_pcierr_interrupt(struct net_device *dev) |
| 5865 | { |
| 5866 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5867 | struct pci_dev *pdev = tp->pci_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5868 | u16 pci_status, pci_cmd; |
| 5869 | |
| 5870 | pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); |
| 5871 | pci_read_config_word(pdev, PCI_STATUS, &pci_status); |
| 5872 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 5873 | netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n", |
| 5874 | pci_cmd, pci_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5875 | |
| 5876 | /* |
| 5877 | * The recovery sequence below admits a very elaborated explanation: |
| 5878 | * - it seems to work; |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 5879 | * - I did not see what else could be done; |
| 5880 | * - it makes iop3xx happy. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5881 | * |
| 5882 | * Feel free to adjust to your needs. |
| 5883 | */ |
Francois Romieu | a27993f | 2006-12-18 00:04:19 +0100 | [diff] [blame] | 5884 | if (pdev->broken_parity_status) |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 5885 | pci_cmd &= ~PCI_COMMAND_PARITY; |
| 5886 | else |
| 5887 | pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; |
| 5888 | |
| 5889 | pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5890 | |
| 5891 | pci_write_config_word(pdev, PCI_STATUS, |
| 5892 | pci_status & (PCI_STATUS_DETECTED_PARITY | |
| 5893 | PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT | |
| 5894 | PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT)); |
| 5895 | |
| 5896 | /* The infamous DAC f*ckup only happens at boot time */ |
| 5897 | if ((tp->cp_cmd & PCIDAC) && !tp->dirty_rx && !tp->cur_rx) { |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5898 | void __iomem *ioaddr = tp->mmio_addr; |
| 5899 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 5900 | netif_info(tp, intr, dev, "disabling PCI DAC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5901 | tp->cp_cmd &= ~PCIDAC; |
| 5902 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 5903 | dev->features &= ~NETIF_F_HIGHDMA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5904 | } |
| 5905 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5906 | rtl8169_hw_reset(tp); |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 5907 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 5908 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5909 | } |
| 5910 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5911 | static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5912 | { |
| 5913 | unsigned int dirty_tx, tx_left; |
| 5914 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5915 | dirty_tx = tp->dirty_tx; |
| 5916 | smp_rmb(); |
| 5917 | tx_left = tp->cur_tx - dirty_tx; |
| 5918 | |
| 5919 | while (tx_left > 0) { |
| 5920 | unsigned int entry = dirty_tx % NUM_TX_DESC; |
| 5921 | struct ring_info *tx_skb = tp->tx_skb + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5922 | u32 status; |
| 5923 | |
| 5924 | rmb(); |
| 5925 | status = le32_to_cpu(tp->TxDescArray[entry].opts1); |
| 5926 | if (status & DescOwn) |
| 5927 | break; |
| 5928 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5929 | rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb, |
| 5930 | tp->TxDescArray + entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5931 | if (status & LastFrag) { |
Francois Romieu | 17bcb68 | 2012-07-23 22:55:55 +0200 | [diff] [blame] | 5932 | u64_stats_update_begin(&tp->tx_stats.syncp); |
| 5933 | tp->tx_stats.packets++; |
| 5934 | tp->tx_stats.bytes += tx_skb->skb->len; |
| 5935 | u64_stats_update_end(&tp->tx_stats.syncp); |
| 5936 | dev_kfree_skb(tx_skb->skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5937 | tx_skb->skb = NULL; |
| 5938 | } |
| 5939 | dirty_tx++; |
| 5940 | tx_left--; |
| 5941 | } |
| 5942 | |
| 5943 | if (tp->dirty_tx != dirty_tx) { |
| 5944 | tp->dirty_tx = dirty_tx; |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 5945 | /* Sync with rtl8169_start_xmit: |
| 5946 | * - publish dirty_tx ring index (write barrier) |
| 5947 | * - refresh cur_tx ring index and queue status (read barrier) |
| 5948 | * May the current thread miss the stopped queue condition, |
| 5949 | * a racing xmit thread can only have a right view of the |
| 5950 | * ring status. |
| 5951 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 5952 | smp_mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5953 | if (netif_queue_stopped(dev) && |
Julien Ducourthial | 477206a | 2012-05-09 00:00:06 +0200 | [diff] [blame] | 5954 | TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5955 | netif_wake_queue(dev); |
| 5956 | } |
Francois Romieu | d78ae2d | 2007-08-26 20:08:19 +0200 | [diff] [blame] | 5957 | /* |
| 5958 | * 8168 hack: TxPoll requests are lost when the Tx packets are |
| 5959 | * too close. Let's kick an extra TxPoll request when a burst |
| 5960 | * of start_xmit activity is detected (if it is not detected, |
| 5961 | * it is slow enough). -- FR |
| 5962 | */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5963 | if (tp->cur_tx != dirty_tx) { |
| 5964 | void __iomem *ioaddr = tp->mmio_addr; |
| 5965 | |
Francois Romieu | d78ae2d | 2007-08-26 20:08:19 +0200 | [diff] [blame] | 5966 | RTL_W8(TxPoll, NPQ); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5967 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5968 | } |
| 5969 | } |
| 5970 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 5971 | static inline int rtl8169_fragmented_frame(u32 status) |
| 5972 | { |
| 5973 | return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag); |
| 5974 | } |
| 5975 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 5976 | static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5977 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5978 | u32 status = opts1 & RxProtoMask; |
| 5979 | |
| 5980 | if (((status == RxProtoTCP) && !(opts1 & TCPFail)) || |
Shan Wei | d5d3ebe | 2010-11-12 00:15:25 +0000 | [diff] [blame] | 5981 | ((status == RxProtoUDP) && !(opts1 & UDPFail))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5982 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 5983 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 5984 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5985 | } |
| 5986 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5987 | static struct sk_buff *rtl8169_try_rx_copy(void *data, |
| 5988 | struct rtl8169_private *tp, |
| 5989 | int pkt_size, |
| 5990 | dma_addr_t addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5991 | { |
Stephen Hemminger | b449655 | 2007-06-17 01:06:49 +0200 | [diff] [blame] | 5992 | struct sk_buff *skb; |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5993 | struct device *d = &tp->pci_dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5994 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5995 | data = rtl8169_align(data); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5996 | dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5997 | prefetch(data); |
| 5998 | skb = netdev_alloc_skb_ip_align(tp->dev, pkt_size); |
| 5999 | if (skb) |
| 6000 | memcpy(skb->data, data, pkt_size); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 6001 | dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE); |
| 6002 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6003 | return skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6004 | } |
| 6005 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6006 | 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] | 6007 | { |
| 6008 | unsigned int cur_rx, rx_left; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6009 | unsigned int count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6010 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6011 | cur_rx = tp->cur_rx; |
| 6012 | rx_left = NUM_RX_DESC + tp->dirty_rx - cur_rx; |
Francois Romieu | 865c652 | 2008-05-11 14:51:00 +0200 | [diff] [blame] | 6013 | rx_left = min(rx_left, budget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6014 | |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 6015 | for (; rx_left > 0; rx_left--, cur_rx++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6016 | unsigned int entry = cur_rx % NUM_RX_DESC; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6017 | struct RxDesc *desc = tp->RxDescArray + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6018 | u32 status; |
| 6019 | |
| 6020 | rmb(); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 6021 | status = le32_to_cpu(desc->opts1) & tp->opts1_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6022 | |
| 6023 | if (status & DescOwn) |
| 6024 | break; |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 6025 | if (unlikely(status & RxRES)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6026 | netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n", |
| 6027 | status); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6028 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6029 | if (status & (RxRWT | RxRUNT)) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6030 | dev->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6031 | if (status & RxCRC) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6032 | dev->stats.rx_crc_errors++; |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 6033 | if (status & RxFOVF) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6034 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6035 | dev->stats.rx_fifo_errors++; |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 6036 | } |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 6037 | if ((status & (RxRUNT | RxCRC)) && |
| 6038 | !(status & (RxRWT | RxFOVF)) && |
| 6039 | (dev->features & NETIF_F_RXALL)) |
| 6040 | goto process_pkt; |
| 6041 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6042 | rtl8169_mark_to_asic(desc, rx_buf_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6043 | } else { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6044 | struct sk_buff *skb; |
Ben Greear | 6bbe021 | 2012-02-10 15:04:33 +0000 | [diff] [blame] | 6045 | dma_addr_t addr; |
| 6046 | int pkt_size; |
| 6047 | |
| 6048 | process_pkt: |
| 6049 | addr = le64_to_cpu(desc->addr); |
Ben Greear | 79d0c1d | 2012-02-10 15:04:34 +0000 | [diff] [blame] | 6050 | if (likely(!(dev->features & NETIF_F_RXFCS))) |
| 6051 | pkt_size = (status & 0x00003fff) - 4; |
| 6052 | else |
| 6053 | pkt_size = status & 0x00003fff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6054 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6055 | /* |
| 6056 | * The driver does not support incoming fragmented |
| 6057 | * frames. They are seen as a symptom of over-mtu |
| 6058 | * sized frames. |
| 6059 | */ |
| 6060 | if (unlikely(rtl8169_fragmented_frame(status))) { |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6061 | dev->stats.rx_dropped++; |
| 6062 | dev->stats.rx_length_errors++; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6063 | rtl8169_mark_to_asic(desc, rx_buf_sz); |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 6064 | continue; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 6065 | } |
| 6066 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6067 | skb = rtl8169_try_rx_copy(tp->Rx_databuff[entry], |
| 6068 | tp, pkt_size, addr); |
| 6069 | rtl8169_mark_to_asic(desc, rx_buf_sz); |
| 6070 | if (!skb) { |
| 6071 | dev->stats.rx_dropped++; |
| 6072 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6073 | } |
| 6074 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 6075 | rtl8169_rx_csum(skb, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6076 | skb_put(skb, pkt_size); |
| 6077 | skb->protocol = eth_type_trans(skb, dev); |
| 6078 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 6079 | rtl8169_rx_vlan_tag(desc, skb); |
| 6080 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 6081 | napi_gro_receive(&tp->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6082 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6083 | u64_stats_update_begin(&tp->rx_stats.syncp); |
| 6084 | tp->rx_stats.packets++; |
| 6085 | tp->rx_stats.bytes += pkt_size; |
| 6086 | u64_stats_update_end(&tp->rx_stats.syncp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6087 | } |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 6088 | |
| 6089 | /* Work around for AMD plateform. */ |
Al Viro | 95e0918 | 2007-12-22 18:55:39 +0000 | [diff] [blame] | 6090 | if ((desc->opts2 & cpu_to_le32(0xfffe000)) && |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 6091 | (tp->mac_version == RTL_GIGA_MAC_VER_05)) { |
| 6092 | desc->opts2 = 0; |
| 6093 | cur_rx++; |
| 6094 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6095 | } |
| 6096 | |
| 6097 | count = cur_rx - tp->cur_rx; |
| 6098 | tp->cur_rx = cur_rx; |
| 6099 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 6100 | tp->dirty_rx += count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6101 | |
| 6102 | return count; |
| 6103 | } |
| 6104 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 6105 | static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6106 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 6107 | struct net_device *dev = dev_instance; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6108 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6109 | int handled = 0; |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 6110 | u16 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6111 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 6112 | status = rtl_get_events(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6113 | if (status && status != 0xffff) { |
| 6114 | status &= RTL_EVENT_NAPI | tp->event_slow; |
| 6115 | if (status) { |
| 6116 | handled = 1; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 6117 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6118 | rtl_irq_disable(tp); |
| 6119 | napi_schedule(&tp->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6120 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6121 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6122 | return IRQ_RETVAL(handled); |
| 6123 | } |
| 6124 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6125 | /* |
| 6126 | * Workqueue context. |
| 6127 | */ |
| 6128 | static void rtl_slow_event_work(struct rtl8169_private *tp) |
| 6129 | { |
| 6130 | struct net_device *dev = tp->dev; |
| 6131 | u16 status; |
| 6132 | |
| 6133 | status = rtl_get_events(tp) & tp->event_slow; |
| 6134 | rtl_ack_events(tp, status); |
| 6135 | |
| 6136 | if (unlikely(status & RxFIFOOver)) { |
| 6137 | switch (tp->mac_version) { |
| 6138 | /* Work around for rx fifo overflow */ |
| 6139 | case RTL_GIGA_MAC_VER_11: |
| 6140 | netif_stop_queue(dev); |
Francois Romieu | 934714d | 2012-01-31 11:09:21 +0100 | [diff] [blame] | 6141 | /* XXX - Hack alert. See rtl_task(). */ |
| 6142 | set_bit(RTL_FLAG_TASK_RESET_PENDING, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6143 | default: |
| 6144 | break; |
| 6145 | } |
| 6146 | } |
| 6147 | |
| 6148 | if (unlikely(status & SYSErr)) |
| 6149 | rtl8169_pcierr_interrupt(dev); |
| 6150 | |
| 6151 | if (status & LinkChg) |
| 6152 | __rtl8169_check_link_status(dev, tp, tp->mmio_addr, true); |
| 6153 | |
françois romieu | 7dbb491 | 2012-06-09 10:53:16 +0000 | [diff] [blame] | 6154 | rtl_irq_enable_all(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6155 | } |
| 6156 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6157 | static void rtl_task(struct work_struct *work) |
| 6158 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6159 | static const struct { |
| 6160 | int bitnr; |
| 6161 | void (*action)(struct rtl8169_private *); |
| 6162 | } rtl_work[] = { |
Francois Romieu | 934714d | 2012-01-31 11:09:21 +0100 | [diff] [blame] | 6163 | /* XXX - keep rtl_slow_event_work() as first element. */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6164 | { RTL_FLAG_TASK_SLOW_PENDING, rtl_slow_event_work }, |
| 6165 | { RTL_FLAG_TASK_RESET_PENDING, rtl_reset_work }, |
| 6166 | { RTL_FLAG_TASK_PHY_PENDING, rtl_phy_work } |
| 6167 | }; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6168 | struct rtl8169_private *tp = |
| 6169 | container_of(work, struct rtl8169_private, wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6170 | struct net_device *dev = tp->dev; |
| 6171 | int i; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6172 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6173 | rtl_lock_work(tp); |
| 6174 | |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 6175 | if (!netif_running(dev) || |
| 6176 | !test_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6177 | goto out_unlock; |
| 6178 | |
| 6179 | for (i = 0; i < ARRAY_SIZE(rtl_work); i++) { |
| 6180 | bool pending; |
| 6181 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6182 | pending = test_and_clear_bit(rtl_work[i].bitnr, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6183 | if (pending) |
| 6184 | rtl_work[i].action(tp); |
| 6185 | } |
| 6186 | |
| 6187 | out_unlock: |
| 6188 | rtl_unlock_work(tp); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 6189 | } |
| 6190 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6191 | static int rtl8169_poll(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6192 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6193 | struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); |
| 6194 | struct net_device *dev = tp->dev; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6195 | u16 enable_mask = RTL_EVENT_NAPI | tp->event_slow; |
| 6196 | int work_done= 0; |
| 6197 | u16 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6198 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6199 | status = rtl_get_events(tp); |
| 6200 | rtl_ack_events(tp, status & ~tp->event_slow); |
| 6201 | |
| 6202 | if (status & RTL_EVENT_NAPI_RX) |
| 6203 | work_done = rtl_rx(dev, tp, (u32) budget); |
| 6204 | |
| 6205 | if (status & RTL_EVENT_NAPI_TX) |
| 6206 | rtl_tx(dev, tp); |
| 6207 | |
| 6208 | if (status & tp->event_slow) { |
| 6209 | enable_mask &= ~tp->event_slow; |
| 6210 | |
| 6211 | rtl_schedule_task(tp, RTL_FLAG_TASK_SLOW_PENDING); |
| 6212 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6213 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6214 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 6215 | napi_complete(napi); |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 6216 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6217 | rtl_irq_enable(tp, enable_mask); |
| 6218 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6219 | } |
| 6220 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 6221 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6222 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6223 | |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 6224 | static void rtl8169_rx_missed(struct net_device *dev, void __iomem *ioaddr) |
| 6225 | { |
| 6226 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6227 | |
| 6228 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) |
| 6229 | return; |
| 6230 | |
| 6231 | dev->stats.rx_missed_errors += (RTL_R32(RxMissed) & 0xffffff); |
| 6232 | RTL_W32(RxMissed, 0); |
| 6233 | } |
| 6234 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6235 | static void rtl8169_down(struct net_device *dev) |
| 6236 | { |
| 6237 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6238 | void __iomem *ioaddr = tp->mmio_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6239 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 6240 | del_timer_sync(&tp->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6241 | |
Stephen Hemminger | 93dd79e | 2007-10-28 17:14:06 +0100 | [diff] [blame] | 6242 | napi_disable(&tp->napi); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6243 | netif_stop_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6244 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 6245 | rtl8169_hw_reset(tp); |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6246 | /* |
| 6247 | * At this point device interrupts can not be enabled in any function, |
Francois Romieu | 209e5ac | 2012-01-26 09:59:50 +0100 | [diff] [blame] | 6248 | * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task) |
| 6249 | * and napi is disabled (rtl8169_poll). |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 6250 | */ |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 6251 | rtl8169_rx_missed(dev, ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6253 | /* Give a racing hard_start_xmit a few cycles to complete. */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6254 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6256 | rtl8169_tx_clear(tp); |
| 6257 | |
| 6258 | rtl8169_rx_clear(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6259 | |
| 6260 | rtl_pll_power_down(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6261 | } |
| 6262 | |
| 6263 | static int rtl8169_close(struct net_device *dev) |
| 6264 | { |
| 6265 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6266 | struct pci_dev *pdev = tp->pci_dev; |
| 6267 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6268 | pm_runtime_get_sync(&pdev->dev); |
| 6269 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6270 | /* Update counters before going down */ |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 6271 | rtl8169_update_counters(dev); |
| 6272 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6273 | rtl_lock_work(tp); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 6274 | clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6276 | rtl8169_down(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6277 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6278 | |
Francois Romieu | 92a7c4e | 2012-03-10 10:42:12 +0100 | [diff] [blame] | 6279 | free_irq(pdev->irq, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6280 | |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 6281 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 6282 | tp->RxPhyAddr); |
| 6283 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 6284 | tp->TxPhyAddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6285 | tp->TxDescArray = NULL; |
| 6286 | tp->RxDescArray = NULL; |
| 6287 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6288 | pm_runtime_put_sync(&pdev->dev); |
| 6289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6290 | return 0; |
| 6291 | } |
| 6292 | |
Francois Romieu | dc1c00c | 2012-03-08 10:06:18 +0100 | [diff] [blame] | 6293 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6294 | static void rtl8169_netpoll(struct net_device *dev) |
| 6295 | { |
| 6296 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6297 | |
| 6298 | rtl8169_interrupt(tp->pci_dev->irq, dev); |
| 6299 | } |
| 6300 | #endif |
| 6301 | |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6302 | static int rtl_open(struct net_device *dev) |
| 6303 | { |
| 6304 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6305 | void __iomem *ioaddr = tp->mmio_addr; |
| 6306 | struct pci_dev *pdev = tp->pci_dev; |
| 6307 | int retval = -ENOMEM; |
| 6308 | |
| 6309 | pm_runtime_get_sync(&pdev->dev); |
| 6310 | |
| 6311 | /* |
Jiri Kosina | e75d660 | 2012-04-08 21:48:52 +0200 | [diff] [blame] | 6312 | * Rx and Tx descriptors needs 256 bytes alignment. |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6313 | * dma_alloc_coherent provides more. |
| 6314 | */ |
| 6315 | tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES, |
| 6316 | &tp->TxPhyAddr, GFP_KERNEL); |
| 6317 | if (!tp->TxDescArray) |
| 6318 | goto err_pm_runtime_put; |
| 6319 | |
| 6320 | tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, |
| 6321 | &tp->RxPhyAddr, GFP_KERNEL); |
| 6322 | if (!tp->RxDescArray) |
| 6323 | goto err_free_tx_0; |
| 6324 | |
| 6325 | retval = rtl8169_init_ring(dev); |
| 6326 | if (retval < 0) |
| 6327 | goto err_free_rx_1; |
| 6328 | |
| 6329 | INIT_WORK(&tp->wk.work, rtl_task); |
| 6330 | |
| 6331 | smp_mb(); |
| 6332 | |
| 6333 | rtl_request_firmware(tp); |
| 6334 | |
Francois Romieu | 92a7c4e | 2012-03-10 10:42:12 +0100 | [diff] [blame] | 6335 | retval = request_irq(pdev->irq, rtl8169_interrupt, |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6336 | (tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED, |
| 6337 | dev->name, dev); |
| 6338 | if (retval < 0) |
| 6339 | goto err_release_fw_2; |
| 6340 | |
| 6341 | rtl_lock_work(tp); |
| 6342 | |
| 6343 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
| 6344 | |
| 6345 | napi_enable(&tp->napi); |
| 6346 | |
| 6347 | rtl8169_init_phy(dev, tp); |
| 6348 | |
| 6349 | __rtl8169_set_features(dev, dev->features); |
| 6350 | |
| 6351 | rtl_pll_power_up(tp); |
| 6352 | |
| 6353 | rtl_hw_start(dev); |
| 6354 | |
| 6355 | netif_start_queue(dev); |
| 6356 | |
| 6357 | rtl_unlock_work(tp); |
| 6358 | |
| 6359 | tp->saved_wolopts = 0; |
| 6360 | pm_runtime_put_noidle(&pdev->dev); |
| 6361 | |
| 6362 | rtl8169_check_link_status(dev, tp, ioaddr); |
| 6363 | out: |
| 6364 | return retval; |
| 6365 | |
| 6366 | err_release_fw_2: |
| 6367 | rtl_release_firmware(tp); |
| 6368 | rtl8169_rx_clear(tp); |
| 6369 | err_free_rx_1: |
| 6370 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 6371 | tp->RxPhyAddr); |
| 6372 | tp->RxDescArray = NULL; |
| 6373 | err_free_tx_0: |
| 6374 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 6375 | tp->TxPhyAddr); |
| 6376 | tp->TxDescArray = NULL; |
| 6377 | err_pm_runtime_put: |
| 6378 | pm_runtime_put_noidle(&pdev->dev); |
| 6379 | goto out; |
| 6380 | } |
| 6381 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6382 | static struct rtnl_link_stats64 * |
| 6383 | rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6384 | { |
| 6385 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6386 | void __iomem *ioaddr = tp->mmio_addr; |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6387 | unsigned int start; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6388 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6389 | if (netif_running(dev)) |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 6390 | rtl8169_rx_missed(dev, ioaddr); |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6391 | |
Junchang Wang | 8027aa2 | 2012-03-04 23:30:32 +0100 | [diff] [blame] | 6392 | do { |
| 6393 | start = u64_stats_fetch_begin_bh(&tp->rx_stats.syncp); |
| 6394 | stats->rx_packets = tp->rx_stats.packets; |
| 6395 | stats->rx_bytes = tp->rx_stats.bytes; |
| 6396 | } while (u64_stats_fetch_retry_bh(&tp->rx_stats.syncp, start)); |
| 6397 | |
| 6398 | |
| 6399 | do { |
| 6400 | start = u64_stats_fetch_begin_bh(&tp->tx_stats.syncp); |
| 6401 | stats->tx_packets = tp->tx_stats.packets; |
| 6402 | stats->tx_bytes = tp->tx_stats.bytes; |
| 6403 | } while (u64_stats_fetch_retry_bh(&tp->tx_stats.syncp, start)); |
| 6404 | |
| 6405 | stats->rx_dropped = dev->stats.rx_dropped; |
| 6406 | stats->tx_dropped = dev->stats.tx_dropped; |
| 6407 | stats->rx_length_errors = dev->stats.rx_length_errors; |
| 6408 | stats->rx_errors = dev->stats.rx_errors; |
| 6409 | stats->rx_crc_errors = dev->stats.rx_crc_errors; |
| 6410 | stats->rx_fifo_errors = dev->stats.rx_fifo_errors; |
| 6411 | stats->rx_missed_errors = dev->stats.rx_missed_errors; |
| 6412 | |
| 6413 | return stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6414 | } |
| 6415 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6416 | static void rtl8169_net_suspend(struct net_device *dev) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6417 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6418 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6419 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6420 | if (!netif_running(dev)) |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6421 | return; |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6422 | |
| 6423 | netif_device_detach(dev); |
| 6424 | netif_stop_queue(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6425 | |
| 6426 | rtl_lock_work(tp); |
| 6427 | napi_disable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 6428 | clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6429 | rtl_unlock_work(tp); |
| 6430 | |
| 6431 | rtl_pll_power_down(tp); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6432 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6433 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6434 | #ifdef CONFIG_PM |
| 6435 | |
| 6436 | static int rtl8169_suspend(struct device *device) |
| 6437 | { |
| 6438 | struct pci_dev *pdev = to_pci_dev(device); |
| 6439 | struct net_device *dev = pci_get_drvdata(pdev); |
| 6440 | |
| 6441 | rtl8169_net_suspend(dev); |
Francois Romieu | 1371fa6 | 2007-04-02 23:01:11 +0200 | [diff] [blame] | 6442 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6443 | return 0; |
| 6444 | } |
| 6445 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6446 | static void __rtl8169_resume(struct net_device *dev) |
| 6447 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6448 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6449 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6450 | netif_device_attach(dev); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6451 | |
| 6452 | rtl_pll_power_up(tp); |
| 6453 | |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 6454 | rtl_lock_work(tp); |
| 6455 | napi_enable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 6456 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Artem Savkov | cff4c16 | 2012-04-03 10:29:11 +0000 | [diff] [blame] | 6457 | rtl_unlock_work(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6458 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 6459 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6460 | } |
| 6461 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6462 | static int rtl8169_resume(struct device *device) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6463 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6464 | struct pci_dev *pdev = to_pci_dev(device); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6465 | struct net_device *dev = pci_get_drvdata(pdev); |
Stanislaw Gruszka | fccec10 | 2010-10-20 22:25:42 +0000 | [diff] [blame] | 6466 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6467 | |
| 6468 | rtl8169_init_phy(dev, tp); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6469 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6470 | if (netif_running(dev)) |
| 6471 | __rtl8169_resume(dev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6472 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6473 | return 0; |
| 6474 | } |
| 6475 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6476 | static int rtl8169_runtime_suspend(struct device *device) |
| 6477 | { |
| 6478 | struct pci_dev *pdev = to_pci_dev(device); |
| 6479 | struct net_device *dev = pci_get_drvdata(pdev); |
| 6480 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6481 | |
| 6482 | if (!tp->TxDescArray) |
| 6483 | return 0; |
| 6484 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6485 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6486 | tp->saved_wolopts = __rtl8169_get_wol(tp); |
| 6487 | __rtl8169_set_wol(tp, WAKE_ANY); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6488 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6489 | |
| 6490 | rtl8169_net_suspend(dev); |
| 6491 | |
| 6492 | return 0; |
| 6493 | } |
| 6494 | |
| 6495 | static int rtl8169_runtime_resume(struct device *device) |
| 6496 | { |
| 6497 | struct pci_dev *pdev = to_pci_dev(device); |
| 6498 | struct net_device *dev = pci_get_drvdata(pdev); |
| 6499 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6500 | |
| 6501 | if (!tp->TxDescArray) |
| 6502 | return 0; |
| 6503 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6504 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6505 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
| 6506 | tp->saved_wolopts = 0; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6507 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6508 | |
Stanislaw Gruszka | fccec10 | 2010-10-20 22:25:42 +0000 | [diff] [blame] | 6509 | rtl8169_init_phy(dev, tp); |
| 6510 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6511 | __rtl8169_resume(dev); |
| 6512 | |
| 6513 | return 0; |
| 6514 | } |
| 6515 | |
| 6516 | static int rtl8169_runtime_idle(struct device *device) |
| 6517 | { |
| 6518 | struct pci_dev *pdev = to_pci_dev(device); |
| 6519 | struct net_device *dev = pci_get_drvdata(pdev); |
| 6520 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6521 | |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 6522 | return tp->TxDescArray ? -EBUSY : 0; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6523 | } |
| 6524 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 6525 | static const struct dev_pm_ops rtl8169_pm_ops = { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6526 | .suspend = rtl8169_suspend, |
| 6527 | .resume = rtl8169_resume, |
| 6528 | .freeze = rtl8169_suspend, |
| 6529 | .thaw = rtl8169_resume, |
| 6530 | .poweroff = rtl8169_suspend, |
| 6531 | .restore = rtl8169_resume, |
| 6532 | .runtime_suspend = rtl8169_runtime_suspend, |
| 6533 | .runtime_resume = rtl8169_runtime_resume, |
| 6534 | .runtime_idle = rtl8169_runtime_idle, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6535 | }; |
| 6536 | |
| 6537 | #define RTL8169_PM_OPS (&rtl8169_pm_ops) |
| 6538 | |
| 6539 | #else /* !CONFIG_PM */ |
| 6540 | |
| 6541 | #define RTL8169_PM_OPS NULL |
| 6542 | |
| 6543 | #endif /* !CONFIG_PM */ |
| 6544 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6545 | static void rtl_wol_shutdown_quirk(struct rtl8169_private *tp) |
| 6546 | { |
| 6547 | void __iomem *ioaddr = tp->mmio_addr; |
| 6548 | |
| 6549 | /* WoL fails with 8168b when the receiver is disabled. */ |
| 6550 | switch (tp->mac_version) { |
| 6551 | case RTL_GIGA_MAC_VER_11: |
| 6552 | case RTL_GIGA_MAC_VER_12: |
| 6553 | case RTL_GIGA_MAC_VER_17: |
| 6554 | pci_clear_master(tp->pci_dev); |
| 6555 | |
| 6556 | RTL_W8(ChipCmd, CmdRxEnb); |
| 6557 | /* PCI commit */ |
| 6558 | RTL_R8(ChipCmd); |
| 6559 | break; |
| 6560 | default: |
| 6561 | break; |
| 6562 | } |
| 6563 | } |
| 6564 | |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 6565 | static void rtl_shutdown(struct pci_dev *pdev) |
| 6566 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6567 | struct net_device *dev = pci_get_drvdata(pdev); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 6568 | struct rtl8169_private *tp = netdev_priv(dev); |
françois romieu | 2a15cd2 | 2012-03-06 01:14:12 +0000 | [diff] [blame] | 6569 | struct device *d = &pdev->dev; |
| 6570 | |
| 6571 | pm_runtime_get_sync(d); |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 6572 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6573 | rtl8169_net_suspend(dev); |
| 6574 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6575 | /* Restore original MAC address */ |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 6576 | rtl_rar_set(tp, dev->perm_addr); |
| 6577 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 6578 | rtl8169_hw_reset(tp); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 6579 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6580 | if (system_state == SYSTEM_POWER_OFF) { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6581 | if (__rtl8169_get_wol(tp) & WAKE_ANY) { |
| 6582 | rtl_wol_suspend_quirk(tp); |
| 6583 | rtl_wol_shutdown_quirk(tp); |
françois romieu | ca52efd | 2009-07-24 12:34:19 +0000 | [diff] [blame] | 6584 | } |
| 6585 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6586 | pci_wake_from_d3(pdev, true); |
| 6587 | pci_set_power_state(pdev, PCI_D3hot); |
| 6588 | } |
françois romieu | 2a15cd2 | 2012-03-06 01:14:12 +0000 | [diff] [blame] | 6589 | |
| 6590 | pm_runtime_put_noidle(d); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6591 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6592 | |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6593 | static void __devexit rtl_remove_one(struct pci_dev *pdev) |
| 6594 | { |
| 6595 | struct net_device *dev = pci_get_drvdata(pdev); |
| 6596 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6597 | |
| 6598 | if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
| 6599 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 6600 | tp->mac_version == RTL_GIGA_MAC_VER_31) { |
| 6601 | rtl8168_driver_stop(tp); |
| 6602 | } |
| 6603 | |
| 6604 | cancel_work_sync(&tp->wk.work); |
| 6605 | |
Devendra Naga | ad1be8d | 2012-05-31 01:51:20 +0000 | [diff] [blame] | 6606 | netif_napi_del(&tp->napi); |
| 6607 | |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 6608 | unregister_netdev(dev); |
| 6609 | |
| 6610 | rtl_release_firmware(tp); |
| 6611 | |
| 6612 | if (pci_dev_run_wake(pdev)) |
| 6613 | pm_runtime_get_noresume(&pdev->dev); |
| 6614 | |
| 6615 | /* restore original MAC address */ |
| 6616 | rtl_rar_set(tp, dev->perm_addr); |
| 6617 | |
| 6618 | rtl_disable_msi(pdev, tp); |
| 6619 | rtl8169_release_board(pdev, dev, tp->mmio_addr); |
| 6620 | pci_set_drvdata(pdev, NULL); |
| 6621 | } |
| 6622 | |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 6623 | static const struct net_device_ops rtl_netdev_ops = { |
Francois Romieu | df43ac7 | 2012-03-08 09:48:40 +0100 | [diff] [blame] | 6624 | .ndo_open = rtl_open, |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 6625 | .ndo_stop = rtl8169_close, |
| 6626 | .ndo_get_stats64 = rtl8169_get_stats64, |
| 6627 | .ndo_start_xmit = rtl8169_start_xmit, |
| 6628 | .ndo_tx_timeout = rtl8169_tx_timeout, |
| 6629 | .ndo_validate_addr = eth_validate_addr, |
| 6630 | .ndo_change_mtu = rtl8169_change_mtu, |
| 6631 | .ndo_fix_features = rtl8169_fix_features, |
| 6632 | .ndo_set_features = rtl8169_set_features, |
| 6633 | .ndo_set_mac_address = rtl_set_mac_address, |
| 6634 | .ndo_do_ioctl = rtl8169_ioctl, |
| 6635 | .ndo_set_rx_mode = rtl_set_rx_mode, |
| 6636 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 6637 | .ndo_poll_controller = rtl8169_netpoll, |
| 6638 | #endif |
| 6639 | |
| 6640 | }; |
| 6641 | |
Francois Romieu | 31fa8b1 | 2012-03-08 10:09:40 +0100 | [diff] [blame] | 6642 | static const struct rtl_cfg_info { |
| 6643 | void (*hw_start)(struct net_device *); |
| 6644 | unsigned int region; |
| 6645 | unsigned int align; |
| 6646 | u16 event_slow; |
| 6647 | unsigned features; |
| 6648 | u8 default_ver; |
| 6649 | } rtl_cfg_infos [] = { |
| 6650 | [RTL_CFG_0] = { |
| 6651 | .hw_start = rtl_hw_start_8169, |
| 6652 | .region = 1, |
| 6653 | .align = 0, |
| 6654 | .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver, |
| 6655 | .features = RTL_FEATURE_GMII, |
| 6656 | .default_ver = RTL_GIGA_MAC_VER_01, |
| 6657 | }, |
| 6658 | [RTL_CFG_1] = { |
| 6659 | .hw_start = rtl_hw_start_8168, |
| 6660 | .region = 2, |
| 6661 | .align = 8, |
| 6662 | .event_slow = SYSErr | LinkChg | RxOverflow, |
| 6663 | .features = RTL_FEATURE_GMII | RTL_FEATURE_MSI, |
| 6664 | .default_ver = RTL_GIGA_MAC_VER_11, |
| 6665 | }, |
| 6666 | [RTL_CFG_2] = { |
| 6667 | .hw_start = rtl_hw_start_8101, |
| 6668 | .region = 2, |
| 6669 | .align = 8, |
| 6670 | .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver | |
| 6671 | PCSTimeout, |
| 6672 | .features = RTL_FEATURE_MSI, |
| 6673 | .default_ver = RTL_GIGA_MAC_VER_13, |
| 6674 | } |
| 6675 | }; |
| 6676 | |
| 6677 | /* Cfg9346_Unlock assumed. */ |
| 6678 | static unsigned rtl_try_msi(struct rtl8169_private *tp, |
| 6679 | const struct rtl_cfg_info *cfg) |
| 6680 | { |
| 6681 | void __iomem *ioaddr = tp->mmio_addr; |
| 6682 | unsigned msi = 0; |
| 6683 | u8 cfg2; |
| 6684 | |
| 6685 | cfg2 = RTL_R8(Config2) & ~MSIEnable; |
| 6686 | if (cfg->features & RTL_FEATURE_MSI) { |
| 6687 | if (pci_enable_msi(tp->pci_dev)) { |
| 6688 | netif_info(tp, hw, tp->dev, "no MSI. Back to INTx.\n"); |
| 6689 | } else { |
| 6690 | cfg2 |= MSIEnable; |
| 6691 | msi = RTL_FEATURE_MSI; |
| 6692 | } |
| 6693 | } |
| 6694 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
| 6695 | RTL_W8(Config2, cfg2); |
| 6696 | return msi; |
| 6697 | } |
| 6698 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6699 | DECLARE_RTL_COND(rtl_link_list_ready_cond) |
| 6700 | { |
| 6701 | void __iomem *ioaddr = tp->mmio_addr; |
| 6702 | |
| 6703 | return RTL_R8(MCU) & LINK_LIST_RDY; |
| 6704 | } |
| 6705 | |
| 6706 | DECLARE_RTL_COND(rtl_rxtx_empty_cond) |
| 6707 | { |
| 6708 | void __iomem *ioaddr = tp->mmio_addr; |
| 6709 | |
| 6710 | return (RTL_R8(MCU) & RXTX_EMPTY) == RXTX_EMPTY; |
| 6711 | } |
| 6712 | |
| 6713 | static void __devinit rtl_hw_init_8168g(struct rtl8169_private *tp) |
| 6714 | { |
| 6715 | void __iomem *ioaddr = tp->mmio_addr; |
| 6716 | u32 data; |
| 6717 | |
| 6718 | tp->ocp_base = OCP_STD_PHY_BASE; |
| 6719 | |
| 6720 | RTL_W32(MISC, RTL_R32(MISC) | RXDV_GATED_EN); |
| 6721 | |
| 6722 | if (!rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 42)) |
| 6723 | return; |
| 6724 | |
| 6725 | if (!rtl_udelay_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42)) |
| 6726 | return; |
| 6727 | |
| 6728 | RTL_W8(ChipCmd, RTL_R8(ChipCmd) & ~(CmdTxEnb | CmdRxEnb)); |
| 6729 | msleep(1); |
| 6730 | RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB); |
| 6731 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 6732 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6733 | data &= ~(1 << 14); |
| 6734 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 6735 | |
| 6736 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 6737 | return; |
| 6738 | |
Hayes Wang | 5f8bcce | 2012-07-10 08:47:05 +0200 | [diff] [blame] | 6739 | data = r8168_mac_ocp_read(tp, 0xe8de); |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6740 | data |= (1 << 15); |
| 6741 | r8168_mac_ocp_write(tp, 0xe8de, data); |
| 6742 | |
| 6743 | if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
| 6744 | return; |
| 6745 | } |
| 6746 | |
| 6747 | static void __devinit rtl_hw_initialize(struct rtl8169_private *tp) |
| 6748 | { |
| 6749 | switch (tp->mac_version) { |
| 6750 | case RTL_GIGA_MAC_VER_40: |
| 6751 | case RTL_GIGA_MAC_VER_41: |
| 6752 | rtl_hw_init_8168g(tp); |
| 6753 | break; |
| 6754 | |
| 6755 | default: |
| 6756 | break; |
| 6757 | } |
| 6758 | } |
| 6759 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6760 | static int __devinit |
| 6761 | rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 6762 | { |
| 6763 | const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data; |
| 6764 | const unsigned int region = cfg->region; |
| 6765 | struct rtl8169_private *tp; |
| 6766 | struct mii_if_info *mii; |
| 6767 | struct net_device *dev; |
| 6768 | void __iomem *ioaddr; |
| 6769 | int chipset, i; |
| 6770 | int rc; |
| 6771 | |
| 6772 | if (netif_msg_drv(&debug)) { |
| 6773 | printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n", |
| 6774 | MODULENAME, RTL8169_VERSION); |
| 6775 | } |
| 6776 | |
| 6777 | dev = alloc_etherdev(sizeof (*tp)); |
| 6778 | if (!dev) { |
| 6779 | rc = -ENOMEM; |
| 6780 | goto out; |
| 6781 | } |
| 6782 | |
| 6783 | SET_NETDEV_DEV(dev, &pdev->dev); |
Francois Romieu | fa9c385 | 2012-03-08 10:01:50 +0100 | [diff] [blame] | 6784 | dev->netdev_ops = &rtl_netdev_ops; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6785 | tp = netdev_priv(dev); |
| 6786 | tp->dev = dev; |
| 6787 | tp->pci_dev = pdev; |
| 6788 | tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT); |
| 6789 | |
| 6790 | mii = &tp->mii; |
| 6791 | mii->dev = dev; |
| 6792 | mii->mdio_read = rtl_mdio_read; |
| 6793 | mii->mdio_write = rtl_mdio_write; |
| 6794 | mii->phy_id_mask = 0x1f; |
| 6795 | mii->reg_num_mask = 0x1f; |
| 6796 | mii->supports_gmii = !!(cfg->features & RTL_FEATURE_GMII); |
| 6797 | |
| 6798 | /* disable ASPM completely as that cause random device stop working |
| 6799 | * problems as well as full system hangs for some PCIe devices users */ |
| 6800 | pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 | |
| 6801 | PCIE_LINK_STATE_CLKPM); |
| 6802 | |
| 6803 | /* enable device (incl. PCI PM wakeup and hotplug setup) */ |
| 6804 | rc = pci_enable_device(pdev); |
| 6805 | if (rc < 0) { |
| 6806 | netif_err(tp, probe, dev, "enable failure\n"); |
| 6807 | goto err_out_free_dev_1; |
| 6808 | } |
| 6809 | |
| 6810 | if (pci_set_mwi(pdev) < 0) |
| 6811 | netif_info(tp, probe, dev, "Mem-Wr-Inval unavailable\n"); |
| 6812 | |
| 6813 | /* make sure PCI base addr 1 is MMIO */ |
| 6814 | if (!(pci_resource_flags(pdev, region) & IORESOURCE_MEM)) { |
| 6815 | netif_err(tp, probe, dev, |
| 6816 | "region #%d not an MMIO resource, aborting\n", |
| 6817 | region); |
| 6818 | rc = -ENODEV; |
| 6819 | goto err_out_mwi_2; |
| 6820 | } |
| 6821 | |
| 6822 | /* check for weird/broken PCI region reporting */ |
| 6823 | if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) { |
| 6824 | netif_err(tp, probe, dev, |
| 6825 | "Invalid PCI region size(s), aborting\n"); |
| 6826 | rc = -ENODEV; |
| 6827 | goto err_out_mwi_2; |
| 6828 | } |
| 6829 | |
| 6830 | rc = pci_request_regions(pdev, MODULENAME); |
| 6831 | if (rc < 0) { |
| 6832 | netif_err(tp, probe, dev, "could not request regions\n"); |
| 6833 | goto err_out_mwi_2; |
| 6834 | } |
| 6835 | |
| 6836 | tp->cp_cmd = RxChkSum; |
| 6837 | |
| 6838 | if ((sizeof(dma_addr_t) > 4) && |
| 6839 | !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && use_dac) { |
| 6840 | tp->cp_cmd |= PCIDAC; |
| 6841 | dev->features |= NETIF_F_HIGHDMA; |
| 6842 | } else { |
| 6843 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
| 6844 | if (rc < 0) { |
| 6845 | netif_err(tp, probe, dev, "DMA configuration failed\n"); |
| 6846 | goto err_out_free_res_3; |
| 6847 | } |
| 6848 | } |
| 6849 | |
| 6850 | /* ioremap MMIO region */ |
| 6851 | ioaddr = ioremap(pci_resource_start(pdev, region), R8169_REGS_SIZE); |
| 6852 | if (!ioaddr) { |
| 6853 | netif_err(tp, probe, dev, "cannot remap MMIO, aborting\n"); |
| 6854 | rc = -EIO; |
| 6855 | goto err_out_free_res_3; |
| 6856 | } |
| 6857 | tp->mmio_addr = ioaddr; |
| 6858 | |
| 6859 | if (!pci_is_pcie(pdev)) |
| 6860 | netif_info(tp, probe, dev, "not PCI Express\n"); |
| 6861 | |
| 6862 | /* Identify chip attached to board */ |
| 6863 | rtl8169_get_mac_version(tp, dev, cfg->default_ver); |
| 6864 | |
| 6865 | rtl_init_rxcfg(tp); |
| 6866 | |
| 6867 | rtl_irq_disable(tp); |
| 6868 | |
Hayes Wang | c558386 | 2012-07-02 17:23:22 +0800 | [diff] [blame] | 6869 | rtl_hw_initialize(tp); |
| 6870 | |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6871 | rtl_hw_reset(tp); |
| 6872 | |
| 6873 | rtl_ack_events(tp, 0xffff); |
| 6874 | |
| 6875 | pci_set_master(pdev); |
| 6876 | |
| 6877 | /* |
| 6878 | * Pretend we are using VLANs; This bypasses a nasty bug where |
| 6879 | * Interrupts stop flowing on high load on 8110SCd controllers. |
| 6880 | */ |
| 6881 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
| 6882 | tp->cp_cmd |= RxVlan; |
| 6883 | |
| 6884 | rtl_init_mdio_ops(tp); |
| 6885 | rtl_init_pll_power_ops(tp); |
| 6886 | rtl_init_jumbo_ops(tp); |
Hayes Wang | beb1fe1 | 2012-03-30 14:33:01 +0800 | [diff] [blame] | 6887 | rtl_init_csi_ops(tp); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6888 | |
| 6889 | rtl8169_print_mac_version(tp); |
| 6890 | |
| 6891 | chipset = tp->mac_version; |
| 6892 | tp->txd_version = rtl_chip_infos[chipset].txd_version; |
| 6893 | |
| 6894 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 6895 | RTL_W8(Config1, RTL_R8(Config1) | PMEnable); |
| 6896 | RTL_W8(Config5, RTL_R8(Config5) & PMEStatus); |
| 6897 | if ((RTL_R8(Config3) & (LinkUp | MagicPacket)) != 0) |
| 6898 | tp->features |= RTL_FEATURE_WOL; |
| 6899 | if ((RTL_R8(Config5) & (UWF | BWF | MWF)) != 0) |
| 6900 | tp->features |= RTL_FEATURE_WOL; |
| 6901 | tp->features |= rtl_try_msi(tp, cfg); |
| 6902 | RTL_W8(Cfg9346, Cfg9346_Lock); |
| 6903 | |
| 6904 | if (rtl_tbi_enabled(tp)) { |
| 6905 | tp->set_speed = rtl8169_set_speed_tbi; |
| 6906 | tp->get_settings = rtl8169_gset_tbi; |
| 6907 | tp->phy_reset_enable = rtl8169_tbi_reset_enable; |
| 6908 | tp->phy_reset_pending = rtl8169_tbi_reset_pending; |
| 6909 | tp->link_ok = rtl8169_tbi_link_ok; |
| 6910 | tp->do_ioctl = rtl_tbi_ioctl; |
| 6911 | } else { |
| 6912 | tp->set_speed = rtl8169_set_speed_xmii; |
| 6913 | tp->get_settings = rtl8169_gset_xmii; |
| 6914 | tp->phy_reset_enable = rtl8169_xmii_reset_enable; |
| 6915 | tp->phy_reset_pending = rtl8169_xmii_reset_pending; |
| 6916 | tp->link_ok = rtl8169_xmii_link_ok; |
| 6917 | tp->do_ioctl = rtl_xmii_ioctl; |
| 6918 | } |
| 6919 | |
| 6920 | mutex_init(&tp->wk.mutex); |
| 6921 | |
| 6922 | /* Get MAC address */ |
| 6923 | for (i = 0; i < ETH_ALEN; i++) |
| 6924 | dev->dev_addr[i] = RTL_R8(MAC0 + i); |
| 6925 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
| 6926 | |
| 6927 | SET_ETHTOOL_OPS(dev, &rtl8169_ethtool_ops); |
| 6928 | dev->watchdog_timeo = RTL8169_TX_TIMEOUT; |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6929 | |
| 6930 | netif_napi_add(dev, &tp->napi, rtl8169_poll, R8169_NAPI_WEIGHT); |
| 6931 | |
| 6932 | /* don't enable SG, IP_CSUM and TSO by default - it might not work |
| 6933 | * properly for all devices */ |
| 6934 | dev->features |= NETIF_F_RXCSUM | |
| 6935 | NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
| 6936 | |
| 6937 | dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 6938 | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
| 6939 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 6940 | NETIF_F_HIGHDMA; |
| 6941 | |
| 6942 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
| 6943 | /* 8110SCd requires hardware Rx VLAN - disallow toggling */ |
| 6944 | dev->hw_features &= ~NETIF_F_HW_VLAN_RX; |
| 6945 | |
| 6946 | dev->hw_features |= NETIF_F_RXALL; |
| 6947 | dev->hw_features |= NETIF_F_RXFCS; |
| 6948 | |
| 6949 | tp->hw_start = cfg->hw_start; |
| 6950 | tp->event_slow = cfg->event_slow; |
| 6951 | |
| 6952 | tp->opts1_mask = (tp->mac_version != RTL_GIGA_MAC_VER_01) ? |
| 6953 | ~(RxBOVF | RxFOVF) : ~0; |
| 6954 | |
| 6955 | init_timer(&tp->timer); |
| 6956 | tp->timer.data = (unsigned long) dev; |
| 6957 | tp->timer.function = rtl8169_phy_timer; |
| 6958 | |
| 6959 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
| 6960 | |
| 6961 | rc = register_netdev(dev); |
| 6962 | if (rc < 0) |
| 6963 | goto err_out_msi_4; |
| 6964 | |
| 6965 | pci_set_drvdata(pdev, dev); |
| 6966 | |
Francois Romieu | 92a7c4e | 2012-03-10 10:42:12 +0100 | [diff] [blame] | 6967 | netif_info(tp, probe, dev, "%s at 0x%p, %pM, XID %08x IRQ %d\n", |
| 6968 | rtl_chip_infos[chipset].name, ioaddr, dev->dev_addr, |
| 6969 | (u32)(RTL_R32(TxConfig) & 0x9cf0f8ff), pdev->irq); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6970 | if (rtl_chip_infos[chipset].jumbo_max != JUMBO_1K) { |
| 6971 | netif_info(tp, probe, dev, "jumbo features [frames: %d bytes, " |
| 6972 | "tx checksumming: %s]\n", |
| 6973 | rtl_chip_infos[chipset].jumbo_max, |
| 6974 | rtl_chip_infos[chipset].jumbo_tx_csum ? "ok" : "ko"); |
| 6975 | } |
| 6976 | |
| 6977 | if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
| 6978 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 6979 | tp->mac_version == RTL_GIGA_MAC_VER_31) { |
| 6980 | rtl8168_driver_start(tp); |
| 6981 | } |
| 6982 | |
| 6983 | device_set_wakeup_enable(&pdev->dev, tp->features & RTL_FEATURE_WOL); |
| 6984 | |
| 6985 | if (pci_dev_run_wake(pdev)) |
| 6986 | pm_runtime_put_noidle(&pdev->dev); |
| 6987 | |
| 6988 | netif_carrier_off(dev); |
| 6989 | |
| 6990 | out: |
| 6991 | return rc; |
| 6992 | |
| 6993 | err_out_msi_4: |
Devendra Naga | ad1be8d | 2012-05-31 01:51:20 +0000 | [diff] [blame] | 6994 | netif_napi_del(&tp->napi); |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 6995 | rtl_disable_msi(pdev, tp); |
| 6996 | iounmap(ioaddr); |
| 6997 | err_out_free_res_3: |
| 6998 | pci_release_regions(pdev); |
| 6999 | err_out_mwi_2: |
| 7000 | pci_clear_mwi(pdev); |
| 7001 | pci_disable_device(pdev); |
| 7002 | err_out_free_dev_1: |
| 7003 | free_netdev(dev); |
| 7004 | goto out; |
| 7005 | } |
| 7006 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7007 | static struct pci_driver rtl8169_pci_driver = { |
| 7008 | .name = MODULENAME, |
| 7009 | .id_table = rtl8169_pci_tbl, |
Francois Romieu | 3b6cf25 | 2012-03-08 09:59:04 +0100 | [diff] [blame] | 7010 | .probe = rtl_init_one, |
Francois Romieu | e27566e | 2012-03-08 09:54:01 +0100 | [diff] [blame] | 7011 | .remove = __devexit_p(rtl_remove_one), |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 7012 | .shutdown = rtl_shutdown, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 7013 | .driver.pm = RTL8169_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7014 | }; |
| 7015 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 7016 | static int __init rtl8169_init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7017 | { |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 7018 | return pci_register_driver(&rtl8169_pci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7019 | } |
| 7020 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 7021 | static void __exit rtl8169_cleanup_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7022 | { |
| 7023 | pci_unregister_driver(&rtl8169_pci_driver); |
| 7024 | } |
| 7025 | |
| 7026 | module_init(rtl8169_init_module); |
| 7027 | module_exit(rtl8169_cleanup_module); |