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 | |
Francois Romieu | 99f252b | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 32 | #include <asm/system.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | #include <asm/io.h> |
| 34 | #include <asm/irq.h> |
| 35 | |
Francois Romieu | 865c652 | 2008-05-11 14:51:00 +0200 | [diff] [blame] | 36 | #define RTL8169_VERSION "2.3LK-NAPI" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 37 | #define MODULENAME "r8169" |
| 38 | #define PFX MODULENAME ": " |
| 39 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 40 | #define FIRMWARE_8168D_1 "rtl_nic/rtl8168d-1.fw" |
| 41 | #define FIRMWARE_8168D_2 "rtl_nic/rtl8168d-2.fw" |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 42 | #define FIRMWARE_8168E_1 "rtl_nic/rtl8168e-1.fw" |
| 43 | #define FIRMWARE_8168E_2 "rtl_nic/rtl8168e-2.fw" |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 44 | #define FIRMWARE_8168E_3 "rtl_nic/rtl8168e-3.fw" |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 45 | #define FIRMWARE_8168F_1 "rtl_nic/rtl8168f-1.fw" |
| 46 | #define FIRMWARE_8168F_2 "rtl_nic/rtl8168f-2.fw" |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 47 | #define FIRMWARE_8105E_1 "rtl_nic/rtl8105e-1.fw" |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #ifdef RTL8169_DEBUG |
| 50 | #define assert(expr) \ |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 51 | if (!(expr)) { \ |
| 52 | printk( "Assertion failed! %s,%s,%s,line=%d\n", \ |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 53 | #expr,__FILE__,__func__,__LINE__); \ |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 54 | } |
Joe Perches | 06fa735 | 2007-10-18 21:15:00 +0200 | [diff] [blame] | 55 | #define dprintk(fmt, args...) \ |
| 56 | do { printk(KERN_DEBUG PFX fmt, ## args); } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | #else |
| 58 | #define assert(expr) do {} while (0) |
| 59 | #define dprintk(fmt, args...) do {} while (0) |
| 60 | #endif /* RTL8169_DEBUG */ |
| 61 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 62 | #define R8169_MSG_DEFAULT \ |
Francois Romieu | f0e837d9 | 2005-09-30 16:54:02 -0700 | [diff] [blame] | 63 | (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN) |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 64 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 65 | #define TX_BUFFS_AVAIL(tp) \ |
| 66 | (tp->dirty_tx + NUM_TX_DESC - tp->cur_tx - 1) |
| 67 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). |
| 69 | 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] | 70 | static const int multicast_filter_limit = 32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Francois Romieu | 9c14cea | 2008-07-05 00:21:15 +0200 | [diff] [blame] | 72 | #define MAX_READ_REQUEST_SHIFT 12 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | #define TX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #define SafeMtu 0x1c20 /* ... actually life sucks beyond ~7k */ |
| 75 | #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */ |
| 76 | |
| 77 | #define R8169_REGS_SIZE 256 |
| 78 | #define R8169_NAPI_WEIGHT 64 |
| 79 | #define NUM_TX_DESC 64 /* Number of Tx descriptor registers */ |
| 80 | #define NUM_RX_DESC 256 /* Number of Rx descriptor registers */ |
| 81 | #define RX_BUF_SIZE 1536 /* Rx Buffer size */ |
| 82 | #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc)) |
| 83 | #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc)) |
| 84 | |
| 85 | #define RTL8169_TX_TIMEOUT (6*HZ) |
| 86 | #define RTL8169_PHY_TIMEOUT (10*HZ) |
| 87 | |
françois romieu | ea8dbdd | 2009-03-15 01:10:50 +0000 | [diff] [blame] | 88 | #define RTL_EEPROM_SIG cpu_to_le32(0x8129) |
| 89 | #define RTL_EEPROM_SIG_MASK cpu_to_le32(0xffff) |
Francois Romieu | e1564ec | 2008-10-16 22:46:13 +0200 | [diff] [blame] | 90 | #define RTL_EEPROM_SIG_ADDR 0x0000 |
| 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | /* write/read MMIO register */ |
| 93 | #define RTL_W8(reg, val8) writeb ((val8), ioaddr + (reg)) |
| 94 | #define RTL_W16(reg, val16) writew ((val16), ioaddr + (reg)) |
| 95 | #define RTL_W32(reg, val32) writel ((val32), ioaddr + (reg)) |
| 96 | #define RTL_R8(reg) readb (ioaddr + (reg)) |
| 97 | #define RTL_R16(reg) readw (ioaddr + (reg)) |
Junchang Wang | 06f555f | 2010-05-30 02:26:07 +0000 | [diff] [blame] | 98 | #define RTL_R32(reg) readl (ioaddr + (reg)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
| 100 | enum mac_version { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 101 | RTL_GIGA_MAC_VER_01 = 0, |
| 102 | RTL_GIGA_MAC_VER_02, |
| 103 | RTL_GIGA_MAC_VER_03, |
| 104 | RTL_GIGA_MAC_VER_04, |
| 105 | RTL_GIGA_MAC_VER_05, |
| 106 | RTL_GIGA_MAC_VER_06, |
| 107 | RTL_GIGA_MAC_VER_07, |
| 108 | RTL_GIGA_MAC_VER_08, |
| 109 | RTL_GIGA_MAC_VER_09, |
| 110 | RTL_GIGA_MAC_VER_10, |
| 111 | RTL_GIGA_MAC_VER_11, |
| 112 | RTL_GIGA_MAC_VER_12, |
| 113 | RTL_GIGA_MAC_VER_13, |
| 114 | RTL_GIGA_MAC_VER_14, |
| 115 | RTL_GIGA_MAC_VER_15, |
| 116 | RTL_GIGA_MAC_VER_16, |
| 117 | RTL_GIGA_MAC_VER_17, |
| 118 | RTL_GIGA_MAC_VER_18, |
| 119 | RTL_GIGA_MAC_VER_19, |
| 120 | RTL_GIGA_MAC_VER_20, |
| 121 | RTL_GIGA_MAC_VER_21, |
| 122 | RTL_GIGA_MAC_VER_22, |
| 123 | RTL_GIGA_MAC_VER_23, |
| 124 | RTL_GIGA_MAC_VER_24, |
| 125 | RTL_GIGA_MAC_VER_25, |
| 126 | RTL_GIGA_MAC_VER_26, |
| 127 | RTL_GIGA_MAC_VER_27, |
| 128 | RTL_GIGA_MAC_VER_28, |
| 129 | RTL_GIGA_MAC_VER_29, |
| 130 | RTL_GIGA_MAC_VER_30, |
| 131 | RTL_GIGA_MAC_VER_31, |
| 132 | RTL_GIGA_MAC_VER_32, |
| 133 | RTL_GIGA_MAC_VER_33, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 134 | RTL_GIGA_MAC_VER_34, |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 135 | RTL_GIGA_MAC_VER_35, |
| 136 | RTL_GIGA_MAC_VER_36, |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 137 | RTL_GIGA_MAC_NONE = 0xff, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | }; |
| 139 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 140 | enum rtl_tx_desc_version { |
| 141 | RTL_TD_0 = 0, |
| 142 | RTL_TD_1 = 1, |
| 143 | }; |
| 144 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 145 | #define JUMBO_1K ETH_DATA_LEN |
| 146 | #define JUMBO_4K (4*1024 - ETH_HLEN - 2) |
| 147 | #define JUMBO_6K (6*1024 - ETH_HLEN - 2) |
| 148 | #define JUMBO_7K (7*1024 - ETH_HLEN - 2) |
| 149 | #define JUMBO_9K (9*1024 - ETH_HLEN - 2) |
| 150 | |
| 151 | #define _R(NAME,TD,FW,SZ,B) { \ |
| 152 | .name = NAME, \ |
| 153 | .txd_version = TD, \ |
| 154 | .fw_name = FW, \ |
| 155 | .jumbo_max = SZ, \ |
| 156 | .jumbo_tx_csum = B \ |
| 157 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
Jesper Juhl | 3c6bee1 | 2006-01-09 20:54:01 -0800 | [diff] [blame] | 159 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | const char *name; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 161 | enum rtl_tx_desc_version txd_version; |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 162 | const char *fw_name; |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 163 | u16 jumbo_max; |
| 164 | bool jumbo_tx_csum; |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 165 | } rtl_chip_infos[] = { |
| 166 | /* PCI devices. */ |
| 167 | [RTL_GIGA_MAC_VER_01] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 168 | _R("RTL8169", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 169 | [RTL_GIGA_MAC_VER_02] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 170 | _R("RTL8169s", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 171 | [RTL_GIGA_MAC_VER_03] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 172 | _R("RTL8110s", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 173 | [RTL_GIGA_MAC_VER_04] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 174 | _R("RTL8169sb/8110sb", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 175 | [RTL_GIGA_MAC_VER_05] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 176 | _R("RTL8169sc/8110sc", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 177 | [RTL_GIGA_MAC_VER_06] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 178 | _R("RTL8169sc/8110sc", RTL_TD_0, NULL, JUMBO_7K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 179 | /* PCI-E devices. */ |
| 180 | [RTL_GIGA_MAC_VER_07] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 181 | _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 182 | [RTL_GIGA_MAC_VER_08] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 183 | _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 184 | [RTL_GIGA_MAC_VER_09] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 185 | _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 186 | [RTL_GIGA_MAC_VER_10] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 187 | _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 188 | [RTL_GIGA_MAC_VER_11] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 189 | _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 190 | [RTL_GIGA_MAC_VER_12] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 191 | _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 192 | [RTL_GIGA_MAC_VER_13] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 193 | _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 194 | [RTL_GIGA_MAC_VER_14] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 195 | _R("RTL8100e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 196 | [RTL_GIGA_MAC_VER_15] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 197 | _R("RTL8100e", RTL_TD_0, NULL, JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 198 | [RTL_GIGA_MAC_VER_16] = |
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_17] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 201 | _R("RTL8168b/8111b", RTL_TD_1, NULL, JUMBO_4K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 202 | [RTL_GIGA_MAC_VER_18] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 203 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 204 | [RTL_GIGA_MAC_VER_19] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 205 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 206 | [RTL_GIGA_MAC_VER_20] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 207 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 208 | [RTL_GIGA_MAC_VER_21] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 209 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 210 | [RTL_GIGA_MAC_VER_22] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 211 | _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 212 | [RTL_GIGA_MAC_VER_23] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 213 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 214 | [RTL_GIGA_MAC_VER_24] = |
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_25] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 217 | _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_1, |
| 218 | JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 219 | [RTL_GIGA_MAC_VER_26] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 220 | _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_2, |
| 221 | JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 222 | [RTL_GIGA_MAC_VER_27] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 223 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 224 | [RTL_GIGA_MAC_VER_28] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 225 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 226 | [RTL_GIGA_MAC_VER_29] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 227 | _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1, |
| 228 | JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 229 | [RTL_GIGA_MAC_VER_30] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 230 | _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1, |
| 231 | JUMBO_1K, true), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 232 | [RTL_GIGA_MAC_VER_31] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 233 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 234 | [RTL_GIGA_MAC_VER_32] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 235 | _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_1, |
| 236 | JUMBO_9K, false), |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 237 | [RTL_GIGA_MAC_VER_33] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 238 | _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_2, |
| 239 | JUMBO_9K, false), |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 240 | [RTL_GIGA_MAC_VER_34] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 241 | _R("RTL8168evl/8111evl",RTL_TD_1, FIRMWARE_8168E_3, |
| 242 | JUMBO_9K, false), |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 243 | [RTL_GIGA_MAC_VER_35] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 244 | _R("RTL8168f/8111f", RTL_TD_1, FIRMWARE_8168F_1, |
| 245 | JUMBO_9K, false), |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 246 | [RTL_GIGA_MAC_VER_36] = |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 247 | _R("RTL8168f/8111f", RTL_TD_1, FIRMWARE_8168F_2, |
| 248 | JUMBO_9K, false), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | }; |
| 250 | #undef _R |
| 251 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 252 | enum cfg_version { |
| 253 | RTL_CFG_0 = 0x00, |
| 254 | RTL_CFG_1, |
| 255 | RTL_CFG_2 |
| 256 | }; |
| 257 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 258 | static void rtl_hw_start_8169(struct net_device *); |
| 259 | static void rtl_hw_start_8168(struct net_device *); |
| 260 | static void rtl_hw_start_8101(struct net_device *); |
| 261 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 262 | static DEFINE_PCI_DEVICE_TABLE(rtl8169_pci_tbl) = { |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 263 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 }, |
Francois Romieu | d2eed8c | 2006-08-31 22:01:07 +0200 | [diff] [blame] | 264 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8136), 0, 0, RTL_CFG_2 }, |
Francois Romieu | d81bf55 | 2006-09-20 21:31:20 +0200 | [diff] [blame] | 265 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_0 }, |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 266 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_1 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 267 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 }, |
| 268 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4300), 0, 0, RTL_CFG_0 }, |
Lennart Sorensen | 93a3aa2 | 2011-07-28 13:18:11 +0000 | [diff] [blame] | 269 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4302), 0, 0, RTL_CFG_0 }, |
Francois Romieu | bc1660b | 2007-10-12 23:58:09 +0200 | [diff] [blame] | 270 | { PCI_DEVICE(PCI_VENDOR_ID_AT, 0xc107), 0, 0, RTL_CFG_0 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 271 | { PCI_DEVICE(0x16ec, 0x0116), 0, 0, RTL_CFG_0 }, |
| 272 | { PCI_VENDOR_ID_LINKSYS, 0x1032, |
| 273 | PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 }, |
Ciaran McCreesh | 11d2e28 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 274 | { 0x0001, 0x8168, |
| 275 | PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | {0,}, |
| 277 | }; |
| 278 | |
| 279 | MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl); |
| 280 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 281 | static int rx_buf_sz = 16383; |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 282 | static int use_dac; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 283 | static struct { |
| 284 | u32 msg_enable; |
| 285 | } debug = { -1 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 286 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 287 | enum rtl_registers { |
| 288 | MAC0 = 0, /* Ethernet hardware address. */ |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 289 | MAC4 = 4, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 290 | MAR0 = 8, /* Multicast filter. */ |
| 291 | CounterAddrLow = 0x10, |
| 292 | CounterAddrHigh = 0x14, |
| 293 | TxDescStartAddrLow = 0x20, |
| 294 | TxDescStartAddrHigh = 0x24, |
| 295 | TxHDescStartAddrLow = 0x28, |
| 296 | TxHDescStartAddrHigh = 0x2c, |
| 297 | FLASH = 0x30, |
| 298 | ERSR = 0x36, |
| 299 | ChipCmd = 0x37, |
| 300 | TxPoll = 0x38, |
| 301 | IntrMask = 0x3c, |
| 302 | IntrStatus = 0x3e, |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 303 | |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 304 | TxConfig = 0x40, |
| 305 | #define TXCFG_AUTO_FIFO (1 << 7) /* 8111e-vl */ |
| 306 | #define TXCFG_EMPTY (1 << 11) /* 8111e-vl */ |
| 307 | |
| 308 | RxConfig = 0x44, |
| 309 | #define RX128_INT_EN (1 << 15) /* 8111c and later */ |
| 310 | #define RX_MULTI_EN (1 << 14) /* 8111c only */ |
| 311 | #define RXCFG_FIFO_SHIFT 13 |
| 312 | /* No threshold before first PCI xfer */ |
| 313 | #define RX_FIFO_THRESH (7 << RXCFG_FIFO_SHIFT) |
| 314 | #define RXCFG_DMA_SHIFT 8 |
| 315 | /* Unlimited maximum PCI burst. */ |
| 316 | #define RX_DMA_BURST (7 << RXCFG_DMA_SHIFT) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 317 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 318 | RxMissed = 0x4c, |
| 319 | Cfg9346 = 0x50, |
| 320 | Config0 = 0x51, |
| 321 | Config1 = 0x52, |
| 322 | Config2 = 0x53, |
| 323 | Config3 = 0x54, |
| 324 | Config4 = 0x55, |
| 325 | Config5 = 0x56, |
| 326 | MultiIntr = 0x5c, |
| 327 | PHYAR = 0x60, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 328 | PHYstatus = 0x6c, |
| 329 | RxMaxSize = 0xda, |
| 330 | CPlusCmd = 0xe0, |
| 331 | IntrMitigate = 0xe2, |
| 332 | RxDescAddrLow = 0xe4, |
| 333 | RxDescAddrHigh = 0xe8, |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 334 | EarlyTxThres = 0xec, /* 8169. Unit of 32 bytes. */ |
| 335 | |
| 336 | #define NoEarlyTx 0x3f /* Max value : no early transmit. */ |
| 337 | |
| 338 | MaxTxPacketSize = 0xec, /* 8101/8168. Unit of 128 bytes. */ |
| 339 | |
| 340 | #define TxPacketMax (8064 >> 7) |
Hayes Wang | 3090bd9 | 2011-09-06 16:55:15 +0800 | [diff] [blame] | 341 | #define EarlySize 0x27 |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 342 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 343 | FuncEvent = 0xf0, |
| 344 | FuncEventMask = 0xf4, |
| 345 | FuncPresetState = 0xf8, |
| 346 | FuncForceEvent = 0xfc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | }; |
| 348 | |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 349 | enum rtl8110_registers { |
| 350 | TBICSR = 0x64, |
| 351 | TBI_ANAR = 0x68, |
| 352 | TBI_LPAR = 0x6a, |
| 353 | }; |
| 354 | |
| 355 | enum rtl8168_8101_registers { |
| 356 | CSIDR = 0x64, |
| 357 | CSIAR = 0x68, |
| 358 | #define CSIAR_FLAG 0x80000000 |
| 359 | #define CSIAR_WRITE_CMD 0x80000000 |
| 360 | #define CSIAR_BYTE_ENABLE 0x0f |
| 361 | #define CSIAR_BYTE_ENABLE_SHIFT 12 |
| 362 | #define CSIAR_ADDR_MASK 0x0fff |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 363 | PMCH = 0x6f, |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 364 | EPHYAR = 0x80, |
| 365 | #define EPHYAR_FLAG 0x80000000 |
| 366 | #define EPHYAR_WRITE_CMD 0x80000000 |
| 367 | #define EPHYAR_REG_MASK 0x1f |
| 368 | #define EPHYAR_REG_SHIFT 16 |
| 369 | #define EPHYAR_DATA_MASK 0xffff |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 370 | DLLPR = 0xd0, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 371 | #define PFM_EN (1 << 6) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 372 | DBG_REG = 0xd1, |
| 373 | #define FIX_NAK_1 (1 << 4) |
| 374 | #define FIX_NAK_2 (1 << 3) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 375 | TWSI = 0xd2, |
| 376 | MCU = 0xd3, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 377 | #define NOW_IS_OOB (1 << 7) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 378 | #define EN_NDP (1 << 3) |
| 379 | #define EN_OOB_RESET (1 << 2) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 380 | EFUSEAR = 0xdc, |
| 381 | #define EFUSEAR_FLAG 0x80000000 |
| 382 | #define EFUSEAR_WRITE_CMD 0x80000000 |
| 383 | #define EFUSEAR_READ_CMD 0x00000000 |
| 384 | #define EFUSEAR_REG_MASK 0x03ff |
| 385 | #define EFUSEAR_REG_SHIFT 8 |
| 386 | #define EFUSEAR_DATA_MASK 0xff |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 387 | }; |
| 388 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 389 | enum rtl8168_registers { |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 390 | LED_FREQ = 0x1a, |
| 391 | EEE_LED = 0x1b, |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 392 | ERIDR = 0x70, |
| 393 | ERIAR = 0x74, |
| 394 | #define ERIAR_FLAG 0x80000000 |
| 395 | #define ERIAR_WRITE_CMD 0x80000000 |
| 396 | #define ERIAR_READ_CMD 0x00000000 |
| 397 | #define ERIAR_ADDR_BYTE_ALIGN 4 |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 398 | #define ERIAR_TYPE_SHIFT 16 |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 399 | #define ERIAR_EXGMAC (0x00 << ERIAR_TYPE_SHIFT) |
| 400 | #define ERIAR_MSIX (0x01 << ERIAR_TYPE_SHIFT) |
| 401 | #define ERIAR_ASF (0x02 << ERIAR_TYPE_SHIFT) |
| 402 | #define ERIAR_MASK_SHIFT 12 |
| 403 | #define ERIAR_MASK_0001 (0x1 << ERIAR_MASK_SHIFT) |
| 404 | #define ERIAR_MASK_0011 (0x3 << ERIAR_MASK_SHIFT) |
| 405 | #define ERIAR_MASK_1111 (0xf << ERIAR_MASK_SHIFT) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 406 | EPHY_RXER_NUM = 0x7c, |
| 407 | OCPDR = 0xb0, /* OCP GPHY access */ |
| 408 | #define OCPDR_WRITE_CMD 0x80000000 |
| 409 | #define OCPDR_READ_CMD 0x00000000 |
| 410 | #define OCPDR_REG_MASK 0x7f |
| 411 | #define OCPDR_GPHY_REG_SHIFT 16 |
| 412 | #define OCPDR_DATA_MASK 0xffff |
| 413 | OCPAR = 0xb4, |
| 414 | #define OCPAR_FLAG 0x80000000 |
| 415 | #define OCPAR_GPHY_WRITE_CMD 0x8000f060 |
| 416 | #define OCPAR_GPHY_READ_CMD 0x0000f060 |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 417 | RDSAR1 = 0xd0, /* 8168c only. Undocumented on 8168dp */ |
| 418 | MISC = 0xf0, /* 8168e only. */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 419 | #define TXPLA_RST (1 << 29) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 420 | #define PWM_EN (1 << 22) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 421 | }; |
| 422 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 423 | enum rtl_register_content { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | /* InterruptStatusBits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 425 | SYSErr = 0x8000, |
| 426 | PCSTimeout = 0x4000, |
| 427 | SWInt = 0x0100, |
| 428 | TxDescUnavail = 0x0080, |
| 429 | RxFIFOOver = 0x0040, |
| 430 | LinkChg = 0x0020, |
| 431 | RxOverflow = 0x0010, |
| 432 | TxErr = 0x0008, |
| 433 | TxOK = 0x0004, |
| 434 | RxErr = 0x0002, |
| 435 | RxOK = 0x0001, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
| 437 | /* RxStatusDesc */ |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 438 | RxBOVF = (1 << 24), |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 439 | RxFOVF = (1 << 23), |
| 440 | RxRWT = (1 << 22), |
| 441 | RxRES = (1 << 21), |
| 442 | RxRUNT = (1 << 20), |
| 443 | RxCRC = (1 << 19), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
| 445 | /* ChipCmdBits */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 446 | StopReq = 0x80, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 447 | CmdReset = 0x10, |
| 448 | CmdRxEnb = 0x08, |
| 449 | CmdTxEnb = 0x04, |
| 450 | RxBufEmpty = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
Francois Romieu | 275391a | 2007-02-23 23:50:28 +0100 | [diff] [blame] | 452 | /* TXPoll register p.5 */ |
| 453 | HPQ = 0x80, /* Poll cmd on the high prio queue */ |
| 454 | NPQ = 0x40, /* Poll cmd on the low prio queue */ |
| 455 | FSWInt = 0x01, /* Forced software interrupt */ |
| 456 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | /* Cfg9346Bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 458 | Cfg9346_Lock = 0x00, |
| 459 | Cfg9346_Unlock = 0xc0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | |
| 461 | /* rx_mode_bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 462 | AcceptErr = 0x20, |
| 463 | AcceptRunt = 0x10, |
| 464 | AcceptBroadcast = 0x08, |
| 465 | AcceptMulticast = 0x04, |
| 466 | AcceptMyPhys = 0x02, |
| 467 | AcceptAllPhys = 0x01, |
Francois Romieu | 1687b56 | 2011-07-19 17:21:29 +0200 | [diff] [blame] | 468 | #define RX_CONFIG_ACCEPT_MASK 0x3f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | /* TxConfigBits */ |
| 471 | TxInterFrameGapShift = 24, |
| 472 | TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */ |
| 473 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 474 | /* Config1 register p.24 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 475 | LEDS1 = (1 << 7), |
| 476 | LEDS0 = (1 << 6), |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 477 | Speed_down = (1 << 4), |
| 478 | MEMMAP = (1 << 3), |
| 479 | IOMAP = (1 << 2), |
| 480 | VPD = (1 << 1), |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 481 | PMEnable = (1 << 0), /* Power Management Enable */ |
| 482 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 483 | /* Config2 register p. 25 */ |
françois romieu | 2ca6cf0 | 2011-12-15 08:37:43 +0000 | [diff] [blame] | 484 | MSIEnable = (1 << 5), /* 8169 only. Reserved in the 8168. */ |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 485 | PCI_Clock_66MHz = 0x01, |
| 486 | PCI_Clock_33MHz = 0x00, |
| 487 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 488 | /* Config3 register p.25 */ |
| 489 | MagicPacket = (1 << 5), /* Wake up when receives a Magic Packet */ |
| 490 | LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */ |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 491 | Jumbo_En0 = (1 << 2), /* 8168 only. Reserved in the 8168b */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 492 | Beacon_en = (1 << 0), /* 8168 only. Reserved in the 8168b */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 493 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 494 | /* Config4 register */ |
| 495 | Jumbo_En1 = (1 << 1), /* 8168 only. Reserved in the 8168b */ |
| 496 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 497 | /* Config5 register p.27 */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 498 | BWF = (1 << 6), /* Accept Broadcast wakeup frame */ |
| 499 | MWF = (1 << 5), /* Accept Multicast wakeup frame */ |
| 500 | UWF = (1 << 4), /* Accept Unicast wakeup frame */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 501 | Spi_en = (1 << 3), |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 502 | LanWake = (1 << 1), /* LanWake enable/disable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 503 | PMEStatus = (1 << 0), /* PME status can be reset by PCI RST# */ |
| 504 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | /* TBICSR p.28 */ |
| 506 | TBIReset = 0x80000000, |
| 507 | TBILoopback = 0x40000000, |
| 508 | TBINwEnable = 0x20000000, |
| 509 | TBINwRestart = 0x10000000, |
| 510 | TBILinkOk = 0x02000000, |
| 511 | TBINwComplete = 0x01000000, |
| 512 | |
| 513 | /* CPlusCmd p.31 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 514 | EnableBist = (1 << 15), // 8168 8101 |
| 515 | Mac_dbgo_oe = (1 << 14), // 8168 8101 |
| 516 | Normal_mode = (1 << 13), // unused |
| 517 | Force_half_dup = (1 << 12), // 8168 8101 |
| 518 | Force_rxflow_en = (1 << 11), // 8168 8101 |
| 519 | Force_txflow_en = (1 << 10), // 8168 8101 |
| 520 | Cxpl_dbg_sel = (1 << 9), // 8168 8101 |
| 521 | ASF = (1 << 8), // 8168 8101 |
| 522 | PktCntrDisable = (1 << 7), // 8168 8101 |
| 523 | Mac_dbgo_sel = 0x001c, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | RxVlan = (1 << 6), |
| 525 | RxChkSum = (1 << 5), |
| 526 | PCIDAC = (1 << 4), |
| 527 | PCIMulRW = (1 << 3), |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 528 | INTT_0 = 0x0000, // 8168 |
| 529 | INTT_1 = 0x0001, // 8168 |
| 530 | INTT_2 = 0x0002, // 8168 |
| 531 | INTT_3 = 0x0003, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | |
| 533 | /* rtl8169_PHYstatus */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 534 | TBI_Enable = 0x80, |
| 535 | TxFlowCtrl = 0x40, |
| 536 | RxFlowCtrl = 0x20, |
| 537 | _1000bpsF = 0x10, |
| 538 | _100bps = 0x08, |
| 539 | _10bps = 0x04, |
| 540 | LinkStatus = 0x02, |
| 541 | FullDup = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 543 | /* _TBICSRBit */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 544 | TBILinkOK = 0x02000000, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 545 | |
| 546 | /* DumpCounterCommand */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 547 | CounterDump = 0x8, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | }; |
| 549 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 550 | enum rtl_desc_bit { |
| 551 | /* First doubleword. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | DescOwn = (1 << 31), /* Descriptor is owned by NIC */ |
| 553 | RingEnd = (1 << 30), /* End of descriptor ring */ |
| 554 | FirstFrag = (1 << 29), /* First segment of a packet */ |
| 555 | LastFrag = (1 << 28), /* Final segment of a packet */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 556 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 558 | /* Generic case. */ |
| 559 | enum rtl_tx_desc_bit { |
| 560 | /* First doubleword. */ |
| 561 | TD_LSO = (1 << 27), /* Large Send Offload */ |
| 562 | #define TD_MSS_MAX 0x07ffu /* MSS value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 564 | /* Second doubleword. */ |
| 565 | TxVlanTag = (1 << 17), /* Add VLAN tag */ |
| 566 | }; |
| 567 | |
| 568 | /* 8169, 8168b and 810x except 8102e. */ |
| 569 | enum rtl_tx_desc_bit_0 { |
| 570 | /* First doubleword. */ |
| 571 | #define TD0_MSS_SHIFT 16 /* MSS position (11 bits) */ |
| 572 | TD0_TCP_CS = (1 << 16), /* Calculate TCP/IP checksum */ |
| 573 | TD0_UDP_CS = (1 << 17), /* Calculate UDP/IP checksum */ |
| 574 | TD0_IP_CS = (1 << 18), /* Calculate IP checksum */ |
| 575 | }; |
| 576 | |
| 577 | /* 8102e, 8168c and beyond. */ |
| 578 | enum rtl_tx_desc_bit_1 { |
| 579 | /* Second doubleword. */ |
| 580 | #define TD1_MSS_SHIFT 18 /* MSS position (11 bits) */ |
| 581 | TD1_IP_CS = (1 << 29), /* Calculate IP checksum */ |
| 582 | TD1_TCP_CS = (1 << 30), /* Calculate TCP/IP checksum */ |
| 583 | TD1_UDP_CS = (1 << 31), /* Calculate UDP/IP checksum */ |
| 584 | }; |
| 585 | |
| 586 | static const struct rtl_tx_desc_info { |
| 587 | struct { |
| 588 | u32 udp; |
| 589 | u32 tcp; |
| 590 | } checksum; |
| 591 | u16 mss_shift; |
| 592 | u16 opts_offset; |
| 593 | } tx_desc_info [] = { |
| 594 | [RTL_TD_0] = { |
| 595 | .checksum = { |
| 596 | .udp = TD0_IP_CS | TD0_UDP_CS, |
| 597 | .tcp = TD0_IP_CS | TD0_TCP_CS |
| 598 | }, |
| 599 | .mss_shift = TD0_MSS_SHIFT, |
| 600 | .opts_offset = 0 |
| 601 | }, |
| 602 | [RTL_TD_1] = { |
| 603 | .checksum = { |
| 604 | .udp = TD1_IP_CS | TD1_UDP_CS, |
| 605 | .tcp = TD1_IP_CS | TD1_TCP_CS |
| 606 | }, |
| 607 | .mss_shift = TD1_MSS_SHIFT, |
| 608 | .opts_offset = 1 |
| 609 | } |
| 610 | }; |
| 611 | |
| 612 | enum rtl_rx_desc_bit { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | /* Rx private */ |
| 614 | PID1 = (1 << 18), /* Protocol ID bit 1/2 */ |
| 615 | PID0 = (1 << 17), /* Protocol ID bit 2/2 */ |
| 616 | |
| 617 | #define RxProtoUDP (PID1) |
| 618 | #define RxProtoTCP (PID0) |
| 619 | #define RxProtoIP (PID1 | PID0) |
| 620 | #define RxProtoMask RxProtoIP |
| 621 | |
| 622 | IPFail = (1 << 16), /* IP checksum failed */ |
| 623 | UDPFail = (1 << 15), /* UDP/IP checksum failed */ |
| 624 | TCPFail = (1 << 14), /* TCP/IP checksum failed */ |
| 625 | RxVlanTag = (1 << 16), /* VLAN tag available */ |
| 626 | }; |
| 627 | |
| 628 | #define RsvdMask 0x3fffc000 |
| 629 | |
| 630 | struct TxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 631 | __le32 opts1; |
| 632 | __le32 opts2; |
| 633 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | }; |
| 635 | |
| 636 | struct RxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 637 | __le32 opts1; |
| 638 | __le32 opts2; |
| 639 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 640 | }; |
| 641 | |
| 642 | struct ring_info { |
| 643 | struct sk_buff *skb; |
| 644 | u32 len; |
| 645 | u8 __pad[sizeof(void *) - sizeof(u32)]; |
| 646 | }; |
| 647 | |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 648 | enum features { |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 649 | RTL_FEATURE_WOL = (1 << 0), |
| 650 | RTL_FEATURE_MSI = (1 << 1), |
| 651 | RTL_FEATURE_GMII = (1 << 2), |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 652 | }; |
| 653 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 654 | struct rtl8169_counters { |
| 655 | __le64 tx_packets; |
| 656 | __le64 rx_packets; |
| 657 | __le64 tx_errors; |
| 658 | __le32 rx_errors; |
| 659 | __le16 rx_missed; |
| 660 | __le16 align_errors; |
| 661 | __le32 tx_one_collision; |
| 662 | __le32 tx_multi_collision; |
| 663 | __le64 rx_unicast; |
| 664 | __le64 rx_broadcast; |
| 665 | __le32 rx_multicast; |
| 666 | __le16 tx_aborted; |
| 667 | __le16 tx_underun; |
| 668 | }; |
| 669 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 670 | enum rtl_flag { |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 671 | RTL_FLAG_TASK_ENABLED, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 672 | RTL_FLAG_TASK_SLOW_PENDING, |
| 673 | RTL_FLAG_TASK_RESET_PENDING, |
| 674 | RTL_FLAG_TASK_PHY_PENDING, |
| 675 | RTL_FLAG_MAX |
| 676 | }; |
| 677 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | struct rtl8169_private { |
| 679 | void __iomem *mmio_addr; /* memory map physical address */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 680 | struct pci_dev *pci_dev; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 681 | struct net_device *dev; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 682 | struct napi_struct napi; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 683 | spinlock_t lock; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 684 | u32 msg_enable; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 685 | u16 txd_version; |
| 686 | u16 mac_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */ |
| 688 | u32 cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */ |
| 689 | u32 dirty_rx; |
| 690 | u32 dirty_tx; |
| 691 | struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */ |
| 692 | struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */ |
| 693 | dma_addr_t TxPhyAddr; |
| 694 | dma_addr_t RxPhyAddr; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 695 | void *Rx_databuff[NUM_RX_DESC]; /* Rx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 696 | struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | struct timer_list timer; |
| 698 | u16 cp_cmd; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 699 | |
| 700 | u16 event_slow; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 701 | |
| 702 | struct mdio_ops { |
| 703 | void (*write)(void __iomem *, int, int); |
| 704 | int (*read)(void __iomem *, int); |
| 705 | } mdio_ops; |
| 706 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 707 | struct pll_power_ops { |
| 708 | void (*down)(struct rtl8169_private *); |
| 709 | void (*up)(struct rtl8169_private *); |
| 710 | } pll_power_ops; |
| 711 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 712 | struct jumbo_ops { |
| 713 | void (*enable)(struct rtl8169_private *); |
| 714 | void (*disable)(struct rtl8169_private *); |
| 715 | } jumbo_ops; |
| 716 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 717 | 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] | 718 | int (*get_settings)(struct net_device *, struct ethtool_cmd *); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 719 | void (*phy_reset_enable)(struct rtl8169_private *tp); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 720 | void (*hw_start)(struct net_device *); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 721 | unsigned int (*phy_reset_pending)(struct rtl8169_private *tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | unsigned int (*link_ok)(void __iomem *); |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 723 | 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] | 724 | |
| 725 | struct { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 726 | DECLARE_BITMAP(flags, RTL_FLAG_MAX); |
| 727 | struct mutex mutex; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 728 | struct work_struct work; |
| 729 | } wk; |
| 730 | |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 731 | unsigned features; |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 732 | |
| 733 | struct mii_if_info mii; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 734 | struct rtl8169_counters counters; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 735 | u32 saved_wolopts; |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 736 | u32 opts1_mask; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 737 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 738 | struct rtl_fw { |
| 739 | const struct firmware *fw; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 740 | |
| 741 | #define RTL_VER_SIZE 32 |
| 742 | |
| 743 | char version[RTL_VER_SIZE]; |
| 744 | |
| 745 | struct rtl_fw_phy_action { |
| 746 | __le32 *code; |
| 747 | size_t size; |
| 748 | } phy_action; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 749 | } *rtl_fw; |
Phil Carmody | 497888c | 2011-07-14 15:07:13 +0300 | [diff] [blame] | 750 | #define RTL_FIRMWARE_UNKNOWN ERR_PTR(-EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | }; |
| 752 | |
Ralf Baechle | 979b6c1 | 2005-06-13 14:30:40 -0700 | [diff] [blame] | 753 | MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | module_param(use_dac, int, 0); |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 756 | 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] | 757 | module_param_named(debug, debug.msg_enable, int, 0); |
| 758 | MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 759 | MODULE_LICENSE("GPL"); |
| 760 | MODULE_VERSION(RTL8169_VERSION); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 761 | MODULE_FIRMWARE(FIRMWARE_8168D_1); |
| 762 | MODULE_FIRMWARE(FIRMWARE_8168D_2); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 763 | MODULE_FIRMWARE(FIRMWARE_8168E_1); |
| 764 | MODULE_FIRMWARE(FIRMWARE_8168E_2); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 765 | MODULE_FIRMWARE(FIRMWARE_8168E_3); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 766 | MODULE_FIRMWARE(FIRMWARE_8105E_1); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 767 | MODULE_FIRMWARE(FIRMWARE_8168F_1); |
| 768 | MODULE_FIRMWARE(FIRMWARE_8168F_2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | |
| 770 | static int rtl8169_open(struct net_device *dev); |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 771 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 772 | struct net_device *dev); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 773 | static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | static int rtl8169_init_ring(struct net_device *dev); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 775 | static void rtl_hw_start(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | static int rtl8169_close(struct net_device *dev); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 777 | static void rtl_set_rx_mode(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | static void rtl8169_tx_timeout(struct net_device *dev); |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 779 | static struct net_device_stats *rtl8169_get_stats(struct net_device *dev); |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 780 | static int rtl8169_change_mtu(struct net_device *dev, int new_mtu); |
Francois Romieu | 99f252b | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 781 | static void rtl8169_rx_clear(struct rtl8169_private *tp); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 782 | static int rtl8169_poll(struct napi_struct *napi, int budget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 784 | static void rtl_lock_work(struct rtl8169_private *tp) |
| 785 | { |
| 786 | mutex_lock(&tp->wk.mutex); |
| 787 | } |
| 788 | |
| 789 | static void rtl_unlock_work(struct rtl8169_private *tp) |
| 790 | { |
| 791 | mutex_unlock(&tp->wk.mutex); |
| 792 | } |
| 793 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 794 | static void rtl_tx_performance_tweak(struct pci_dev *pdev, u16 force) |
| 795 | { |
| 796 | int cap = pci_pcie_cap(pdev); |
| 797 | |
| 798 | if (cap) { |
| 799 | u16 ctl; |
| 800 | |
| 801 | pci_read_config_word(pdev, cap + PCI_EXP_DEVCTL, &ctl); |
| 802 | ctl = (ctl & ~PCI_EXP_DEVCTL_READRQ) | force; |
| 803 | pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, ctl); |
| 804 | } |
| 805 | } |
| 806 | |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 807 | static u32 ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 808 | { |
| 809 | void __iomem *ioaddr = tp->mmio_addr; |
| 810 | int i; |
| 811 | |
| 812 | RTL_W32(OCPAR, ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
| 813 | for (i = 0; i < 20; i++) { |
| 814 | udelay(100); |
| 815 | if (RTL_R32(OCPAR) & OCPAR_FLAG) |
| 816 | break; |
| 817 | } |
| 818 | return RTL_R32(OCPDR); |
| 819 | } |
| 820 | |
| 821 | static void ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, u32 data) |
| 822 | { |
| 823 | void __iomem *ioaddr = tp->mmio_addr; |
| 824 | int i; |
| 825 | |
| 826 | RTL_W32(OCPDR, data); |
| 827 | RTL_W32(OCPAR, OCPAR_FLAG | ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
| 828 | for (i = 0; i < 20; i++) { |
| 829 | udelay(100); |
| 830 | if ((RTL_R32(OCPAR) & OCPAR_FLAG) == 0) |
| 831 | break; |
| 832 | } |
| 833 | } |
| 834 | |
Hayes Wang | fac5b3c | 2011-02-22 17:26:20 +0800 | [diff] [blame] | 835 | static void rtl8168_oob_notify(struct rtl8169_private *tp, u8 cmd) |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 836 | { |
Hayes Wang | fac5b3c | 2011-02-22 17:26:20 +0800 | [diff] [blame] | 837 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 838 | int i; |
| 839 | |
| 840 | RTL_W8(ERIDR, cmd); |
| 841 | RTL_W32(ERIAR, 0x800010e8); |
| 842 | msleep(2); |
| 843 | for (i = 0; i < 5; i++) { |
| 844 | udelay(100); |
Francois Romieu | 1e4e82b | 2011-06-24 19:52:13 +0200 | [diff] [blame] | 845 | if (!(RTL_R32(ERIAR) & ERIAR_FLAG)) |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 846 | break; |
| 847 | } |
| 848 | |
Hayes Wang | fac5b3c | 2011-02-22 17:26:20 +0800 | [diff] [blame] | 849 | ocp_write(tp, 0x1, 0x30, 0x00000001); |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 850 | } |
| 851 | |
| 852 | #define OOB_CMD_RESET 0x00 |
| 853 | #define OOB_CMD_DRIVER_START 0x05 |
| 854 | #define OOB_CMD_DRIVER_STOP 0x06 |
| 855 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 856 | static u16 rtl8168_get_ocp_reg(struct rtl8169_private *tp) |
| 857 | { |
| 858 | return (tp->mac_version == RTL_GIGA_MAC_VER_31) ? 0xb8 : 0x10; |
| 859 | } |
| 860 | |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 861 | static void rtl8168_driver_start(struct rtl8169_private *tp) |
| 862 | { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 863 | u16 reg; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 864 | int i; |
| 865 | |
| 866 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_START); |
| 867 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 868 | reg = rtl8168_get_ocp_reg(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 869 | |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 870 | for (i = 0; i < 10; i++) { |
| 871 | msleep(10); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 872 | if (ocp_read(tp, 0x0f, reg) & 0x00000800) |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 873 | break; |
| 874 | } |
| 875 | } |
| 876 | |
| 877 | static void rtl8168_driver_stop(struct rtl8169_private *tp) |
| 878 | { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 879 | u16 reg; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 880 | int i; |
| 881 | |
| 882 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_STOP); |
| 883 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 884 | reg = rtl8168_get_ocp_reg(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 885 | |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 886 | for (i = 0; i < 10; i++) { |
| 887 | msleep(10); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 888 | if ((ocp_read(tp, 0x0f, reg) & 0x00000800) == 0) |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 889 | break; |
| 890 | } |
| 891 | } |
| 892 | |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 893 | static int r8168dp_check_dash(struct rtl8169_private *tp) |
| 894 | { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 895 | u16 reg = rtl8168_get_ocp_reg(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 896 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 897 | return (ocp_read(tp, 0x0f, reg) & 0x00008000) ? 1 : 0; |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 898 | } |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 899 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 900 | static void r8169_mdio_write(void __iomem *ioaddr, int reg_addr, int value) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 901 | { |
| 902 | int i; |
| 903 | |
Francois Romieu | a6baf3a | 2007-11-08 23:23:21 +0100 | [diff] [blame] | 904 | RTL_W32(PHYAR, 0x80000000 | (reg_addr & 0x1f) << 16 | (value & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | |
Francois Romieu | 2371408 | 2006-01-29 00:49:09 +0100 | [diff] [blame] | 906 | for (i = 20; i > 0; i--) { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 907 | /* |
| 908 | * Check if the RTL8169 has completed writing to the specified |
| 909 | * MII register. |
| 910 | */ |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 911 | if (!(RTL_R32(PHYAR) & 0x80000000)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | break; |
Francois Romieu | 2371408 | 2006-01-29 00:49:09 +0100 | [diff] [blame] | 913 | udelay(25); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | } |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 915 | /* |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 916 | * According to hardware specs a 20us delay is required after write |
| 917 | * complete indication, but before sending next command. |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 918 | */ |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 919 | udelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | } |
| 921 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 922 | static int r8169_mdio_read(void __iomem *ioaddr, int reg_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 923 | { |
| 924 | int i, value = -1; |
| 925 | |
Francois Romieu | a6baf3a | 2007-11-08 23:23:21 +0100 | [diff] [blame] | 926 | RTL_W32(PHYAR, 0x0 | (reg_addr & 0x1f) << 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 927 | |
Francois Romieu | 2371408 | 2006-01-29 00:49:09 +0100 | [diff] [blame] | 928 | for (i = 20; i > 0; i--) { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 929 | /* |
| 930 | * Check if the RTL8169 has completed retrieving data from |
| 931 | * the specified MII register. |
| 932 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 933 | if (RTL_R32(PHYAR) & 0x80000000) { |
Francois Romieu | a6baf3a | 2007-11-08 23:23:21 +0100 | [diff] [blame] | 934 | value = RTL_R32(PHYAR) & 0xffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 935 | break; |
| 936 | } |
Francois Romieu | 2371408 | 2006-01-29 00:49:09 +0100 | [diff] [blame] | 937 | udelay(25); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | } |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 939 | /* |
| 940 | * According to hardware specs a 20us delay is required after read |
| 941 | * complete indication, but before sending next command. |
| 942 | */ |
| 943 | udelay(20); |
| 944 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | return value; |
| 946 | } |
| 947 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 948 | static void r8168dp_1_mdio_access(void __iomem *ioaddr, int reg_addr, u32 data) |
| 949 | { |
| 950 | int i; |
| 951 | |
| 952 | RTL_W32(OCPDR, data | |
| 953 | ((reg_addr & OCPDR_REG_MASK) << OCPDR_GPHY_REG_SHIFT)); |
| 954 | RTL_W32(OCPAR, OCPAR_GPHY_WRITE_CMD); |
| 955 | RTL_W32(EPHY_RXER_NUM, 0); |
| 956 | |
| 957 | for (i = 0; i < 100; i++) { |
| 958 | mdelay(1); |
| 959 | if (!(RTL_R32(OCPAR) & OCPAR_FLAG)) |
| 960 | break; |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | static void r8168dp_1_mdio_write(void __iomem *ioaddr, int reg_addr, int value) |
| 965 | { |
| 966 | r8168dp_1_mdio_access(ioaddr, reg_addr, OCPDR_WRITE_CMD | |
| 967 | (value & OCPDR_DATA_MASK)); |
| 968 | } |
| 969 | |
| 970 | static int r8168dp_1_mdio_read(void __iomem *ioaddr, int reg_addr) |
| 971 | { |
| 972 | int i; |
| 973 | |
| 974 | r8168dp_1_mdio_access(ioaddr, reg_addr, OCPDR_READ_CMD); |
| 975 | |
| 976 | mdelay(1); |
| 977 | RTL_W32(OCPAR, OCPAR_GPHY_READ_CMD); |
| 978 | RTL_W32(EPHY_RXER_NUM, 0); |
| 979 | |
| 980 | for (i = 0; i < 100; i++) { |
| 981 | mdelay(1); |
| 982 | if (RTL_R32(OCPAR) & OCPAR_FLAG) |
| 983 | break; |
| 984 | } |
| 985 | |
| 986 | return RTL_R32(OCPDR) & OCPDR_DATA_MASK; |
| 987 | } |
| 988 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 989 | #define R8168DP_1_MDIO_ACCESS_BIT 0x00020000 |
| 990 | |
| 991 | static void r8168dp_2_mdio_start(void __iomem *ioaddr) |
| 992 | { |
| 993 | RTL_W32(0xd0, RTL_R32(0xd0) & ~R8168DP_1_MDIO_ACCESS_BIT); |
| 994 | } |
| 995 | |
| 996 | static void r8168dp_2_mdio_stop(void __iomem *ioaddr) |
| 997 | { |
| 998 | RTL_W32(0xd0, RTL_R32(0xd0) | R8168DP_1_MDIO_ACCESS_BIT); |
| 999 | } |
| 1000 | |
| 1001 | static void r8168dp_2_mdio_write(void __iomem *ioaddr, int reg_addr, int value) |
| 1002 | { |
| 1003 | r8168dp_2_mdio_start(ioaddr); |
| 1004 | |
| 1005 | r8169_mdio_write(ioaddr, reg_addr, value); |
| 1006 | |
| 1007 | r8168dp_2_mdio_stop(ioaddr); |
| 1008 | } |
| 1009 | |
| 1010 | static int r8168dp_2_mdio_read(void __iomem *ioaddr, int reg_addr) |
| 1011 | { |
| 1012 | int value; |
| 1013 | |
| 1014 | r8168dp_2_mdio_start(ioaddr); |
| 1015 | |
| 1016 | value = r8169_mdio_read(ioaddr, reg_addr); |
| 1017 | |
| 1018 | r8168dp_2_mdio_stop(ioaddr); |
| 1019 | |
| 1020 | return value; |
| 1021 | } |
| 1022 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1023 | static void rtl_writephy(struct rtl8169_private *tp, int location, u32 val) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1024 | { |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1025 | tp->mdio_ops.write(tp->mmio_addr, location, val); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1026 | } |
| 1027 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1028 | static int rtl_readphy(struct rtl8169_private *tp, int location) |
| 1029 | { |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 1030 | return tp->mdio_ops.read(tp->mmio_addr, location); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | static void rtl_patchphy(struct rtl8169_private *tp, int reg_addr, int value) |
| 1034 | { |
| 1035 | rtl_writephy(tp, reg_addr, rtl_readphy(tp, reg_addr) | value); |
| 1036 | } |
| 1037 | |
| 1038 | 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] | 1039 | { |
| 1040 | int val; |
| 1041 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1042 | val = rtl_readphy(tp, reg_addr); |
| 1043 | rtl_writephy(tp, reg_addr, (val | p) & ~m); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1044 | } |
| 1045 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1046 | static void rtl_mdio_write(struct net_device *dev, int phy_id, int location, |
| 1047 | int val) |
| 1048 | { |
| 1049 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1050 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1051 | rtl_writephy(tp, location, val); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | static int rtl_mdio_read(struct net_device *dev, int phy_id, int location) |
| 1055 | { |
| 1056 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1057 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1058 | return rtl_readphy(tp, location); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1059 | } |
| 1060 | |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 1061 | static void rtl_ephy_write(void __iomem *ioaddr, int reg_addr, int value) |
| 1062 | { |
| 1063 | unsigned int i; |
| 1064 | |
| 1065 | RTL_W32(EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) | |
| 1066 | (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
| 1067 | |
| 1068 | for (i = 0; i < 100; i++) { |
| 1069 | if (!(RTL_R32(EPHYAR) & EPHYAR_FLAG)) |
| 1070 | break; |
| 1071 | udelay(10); |
| 1072 | } |
| 1073 | } |
| 1074 | |
| 1075 | static u16 rtl_ephy_read(void __iomem *ioaddr, int reg_addr) |
| 1076 | { |
| 1077 | u16 value = 0xffff; |
| 1078 | unsigned int i; |
| 1079 | |
| 1080 | RTL_W32(EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
| 1081 | |
| 1082 | for (i = 0; i < 100; i++) { |
| 1083 | if (RTL_R32(EPHYAR) & EPHYAR_FLAG) { |
| 1084 | value = RTL_R32(EPHYAR) & EPHYAR_DATA_MASK; |
| 1085 | break; |
| 1086 | } |
| 1087 | udelay(10); |
| 1088 | } |
| 1089 | |
| 1090 | return value; |
| 1091 | } |
| 1092 | |
| 1093 | static void rtl_csi_write(void __iomem *ioaddr, int addr, int value) |
| 1094 | { |
| 1095 | unsigned int i; |
| 1096 | |
| 1097 | RTL_W32(CSIDR, value); |
| 1098 | RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
| 1099 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 1100 | |
| 1101 | for (i = 0; i < 100; i++) { |
| 1102 | if (!(RTL_R32(CSIAR) & CSIAR_FLAG)) |
| 1103 | break; |
| 1104 | udelay(10); |
| 1105 | } |
| 1106 | } |
| 1107 | |
| 1108 | static u32 rtl_csi_read(void __iomem *ioaddr, int addr) |
| 1109 | { |
| 1110 | u32 value = ~0x00; |
| 1111 | unsigned int i; |
| 1112 | |
| 1113 | RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) | |
| 1114 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 1115 | |
| 1116 | for (i = 0; i < 100; i++) { |
| 1117 | if (RTL_R32(CSIAR) & CSIAR_FLAG) { |
| 1118 | value = RTL_R32(CSIDR); |
| 1119 | break; |
| 1120 | } |
| 1121 | udelay(10); |
| 1122 | } |
| 1123 | |
| 1124 | return value; |
| 1125 | } |
| 1126 | |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1127 | static |
| 1128 | void rtl_eri_write(void __iomem *ioaddr, int addr, u32 mask, u32 val, int type) |
| 1129 | { |
| 1130 | unsigned int i; |
| 1131 | |
| 1132 | BUG_ON((addr & 3) || (mask == 0)); |
| 1133 | RTL_W32(ERIDR, val); |
| 1134 | RTL_W32(ERIAR, ERIAR_WRITE_CMD | type | mask | addr); |
| 1135 | |
| 1136 | for (i = 0; i < 100; i++) { |
| 1137 | if (!(RTL_R32(ERIAR) & ERIAR_FLAG)) |
| 1138 | break; |
| 1139 | udelay(100); |
| 1140 | } |
| 1141 | } |
| 1142 | |
| 1143 | static u32 rtl_eri_read(void __iomem *ioaddr, int addr, int type) |
| 1144 | { |
| 1145 | u32 value = ~0x00; |
| 1146 | unsigned int i; |
| 1147 | |
| 1148 | RTL_W32(ERIAR, ERIAR_READ_CMD | type | ERIAR_MASK_1111 | addr); |
| 1149 | |
| 1150 | for (i = 0; i < 100; i++) { |
| 1151 | if (RTL_R32(ERIAR) & ERIAR_FLAG) { |
| 1152 | value = RTL_R32(ERIDR); |
| 1153 | break; |
| 1154 | } |
| 1155 | udelay(100); |
| 1156 | } |
| 1157 | |
| 1158 | return value; |
| 1159 | } |
| 1160 | |
| 1161 | static void |
| 1162 | rtl_w1w0_eri(void __iomem *ioaddr, int addr, u32 mask, u32 p, u32 m, int type) |
| 1163 | { |
| 1164 | u32 val; |
| 1165 | |
| 1166 | val = rtl_eri_read(ioaddr, addr, type); |
| 1167 | rtl_eri_write(ioaddr, addr, mask, (val & ~m) | p, type); |
| 1168 | } |
| 1169 | |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1170 | struct exgmac_reg { |
| 1171 | u16 addr; |
| 1172 | u16 mask; |
| 1173 | u32 val; |
| 1174 | }; |
| 1175 | |
| 1176 | static void rtl_write_exgmac_batch(void __iomem *ioaddr, |
| 1177 | const struct exgmac_reg *r, int len) |
| 1178 | { |
| 1179 | while (len-- > 0) { |
| 1180 | rtl_eri_write(ioaddr, r->addr, r->mask, r->val, ERIAR_EXGMAC); |
| 1181 | r++; |
| 1182 | } |
| 1183 | } |
| 1184 | |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1185 | static u8 rtl8168d_efuse_read(void __iomem *ioaddr, int reg_addr) |
| 1186 | { |
| 1187 | u8 value = 0xff; |
| 1188 | unsigned int i; |
| 1189 | |
| 1190 | RTL_W32(EFUSEAR, (reg_addr & EFUSEAR_REG_MASK) << EFUSEAR_REG_SHIFT); |
| 1191 | |
| 1192 | for (i = 0; i < 300; i++) { |
| 1193 | if (RTL_R32(EFUSEAR) & EFUSEAR_FLAG) { |
| 1194 | value = RTL_R32(EFUSEAR) & EFUSEAR_DATA_MASK; |
| 1195 | break; |
| 1196 | } |
| 1197 | udelay(100); |
| 1198 | } |
| 1199 | |
| 1200 | return value; |
| 1201 | } |
| 1202 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1203 | static u16 rtl_get_events(struct rtl8169_private *tp) |
| 1204 | { |
| 1205 | void __iomem *ioaddr = tp->mmio_addr; |
| 1206 | |
| 1207 | return RTL_R16(IntrStatus); |
| 1208 | } |
| 1209 | |
| 1210 | static void rtl_ack_events(struct rtl8169_private *tp, u16 bits) |
| 1211 | { |
| 1212 | void __iomem *ioaddr = tp->mmio_addr; |
| 1213 | |
| 1214 | RTL_W16(IntrStatus, bits); |
| 1215 | mmiowb(); |
| 1216 | } |
| 1217 | |
| 1218 | static void rtl_irq_disable(struct rtl8169_private *tp) |
| 1219 | { |
| 1220 | void __iomem *ioaddr = tp->mmio_addr; |
| 1221 | |
| 1222 | RTL_W16(IntrMask, 0); |
| 1223 | mmiowb(); |
| 1224 | } |
| 1225 | |
Francois Romieu | 3e990ff | 2012-01-26 12:50:01 +0100 | [diff] [blame] | 1226 | static void rtl_irq_enable(struct rtl8169_private *tp, u16 bits) |
| 1227 | { |
| 1228 | void __iomem *ioaddr = tp->mmio_addr; |
| 1229 | |
| 1230 | RTL_W16(IntrMask, bits); |
| 1231 | } |
| 1232 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1233 | #define RTL_EVENT_NAPI_RX (RxOK | RxErr) |
| 1234 | #define RTL_EVENT_NAPI_TX (TxOK | TxErr) |
| 1235 | #define RTL_EVENT_NAPI (RTL_EVENT_NAPI_RX | RTL_EVENT_NAPI_TX) |
| 1236 | |
| 1237 | static void rtl_irq_enable_all(struct rtl8169_private *tp) |
| 1238 | { |
| 1239 | rtl_irq_enable(tp, RTL_EVENT_NAPI | tp->event_slow); |
| 1240 | } |
| 1241 | |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 1242 | static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1243 | { |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 1244 | void __iomem *ioaddr = tp->mmio_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 1246 | rtl_irq_disable(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1247 | rtl_ack_events(tp, RTL_EVENT_NAPI | tp->event_slow); |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 1248 | RTL_R8(ChipCmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1249 | } |
| 1250 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1251 | static unsigned int rtl8169_tbi_reset_pending(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1253 | void __iomem *ioaddr = tp->mmio_addr; |
| 1254 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | return RTL_R32(TBICSR) & TBIReset; |
| 1256 | } |
| 1257 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1258 | static unsigned int rtl8169_xmii_reset_pending(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1260 | return rtl_readphy(tp, MII_BMCR) & BMCR_RESET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1261 | } |
| 1262 | |
| 1263 | static unsigned int rtl8169_tbi_link_ok(void __iomem *ioaddr) |
| 1264 | { |
| 1265 | return RTL_R32(TBICSR) & TBILinkOk; |
| 1266 | } |
| 1267 | |
| 1268 | static unsigned int rtl8169_xmii_link_ok(void __iomem *ioaddr) |
| 1269 | { |
| 1270 | return RTL_R8(PHYstatus) & LinkStatus; |
| 1271 | } |
| 1272 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1273 | static void rtl8169_tbi_reset_enable(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1274 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1275 | void __iomem *ioaddr = tp->mmio_addr; |
| 1276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1277 | RTL_W32(TBICSR, RTL_R32(TBICSR) | TBIReset); |
| 1278 | } |
| 1279 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1280 | static void rtl8169_xmii_reset_enable(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1281 | { |
| 1282 | unsigned int val; |
| 1283 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1284 | val = rtl_readphy(tp, MII_BMCR) | BMCR_RESET; |
| 1285 | rtl_writephy(tp, MII_BMCR, val & 0xffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1286 | } |
| 1287 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1288 | static void rtl_link_chg_patch(struct rtl8169_private *tp) |
| 1289 | { |
| 1290 | void __iomem *ioaddr = tp->mmio_addr; |
| 1291 | struct net_device *dev = tp->dev; |
| 1292 | |
| 1293 | if (!netif_running(dev)) |
| 1294 | return; |
| 1295 | |
| 1296 | if (tp->mac_version == RTL_GIGA_MAC_VER_34) { |
| 1297 | if (RTL_R8(PHYstatus) & _1000bpsF) { |
| 1298 | rtl_eri_write(ioaddr, 0x1bc, ERIAR_MASK_1111, |
| 1299 | 0x00000011, ERIAR_EXGMAC); |
| 1300 | rtl_eri_write(ioaddr, 0x1dc, ERIAR_MASK_1111, |
| 1301 | 0x00000005, ERIAR_EXGMAC); |
| 1302 | } else if (RTL_R8(PHYstatus) & _100bps) { |
| 1303 | rtl_eri_write(ioaddr, 0x1bc, ERIAR_MASK_1111, |
| 1304 | 0x0000001f, ERIAR_EXGMAC); |
| 1305 | rtl_eri_write(ioaddr, 0x1dc, ERIAR_MASK_1111, |
| 1306 | 0x00000005, ERIAR_EXGMAC); |
| 1307 | } else { |
| 1308 | rtl_eri_write(ioaddr, 0x1bc, ERIAR_MASK_1111, |
| 1309 | 0x0000001f, ERIAR_EXGMAC); |
| 1310 | rtl_eri_write(ioaddr, 0x1dc, ERIAR_MASK_1111, |
| 1311 | 0x0000003f, ERIAR_EXGMAC); |
| 1312 | } |
| 1313 | /* Reset packet filter */ |
| 1314 | rtl_w1w0_eri(ioaddr, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, |
| 1315 | ERIAR_EXGMAC); |
| 1316 | rtl_w1w0_eri(ioaddr, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, |
| 1317 | ERIAR_EXGMAC); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1318 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 1319 | tp->mac_version == RTL_GIGA_MAC_VER_36) { |
| 1320 | if (RTL_R8(PHYstatus) & _1000bpsF) { |
| 1321 | rtl_eri_write(ioaddr, 0x1bc, ERIAR_MASK_1111, |
| 1322 | 0x00000011, ERIAR_EXGMAC); |
| 1323 | rtl_eri_write(ioaddr, 0x1dc, ERIAR_MASK_1111, |
| 1324 | 0x00000005, ERIAR_EXGMAC); |
| 1325 | } else { |
| 1326 | rtl_eri_write(ioaddr, 0x1bc, ERIAR_MASK_1111, |
| 1327 | 0x0000001f, ERIAR_EXGMAC); |
| 1328 | rtl_eri_write(ioaddr, 0x1dc, ERIAR_MASK_1111, |
| 1329 | 0x0000003f, ERIAR_EXGMAC); |
| 1330 | } |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1331 | } |
| 1332 | } |
| 1333 | |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 1334 | static void __rtl8169_check_link_status(struct net_device *dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1335 | struct rtl8169_private *tp, |
| 1336 | void __iomem *ioaddr, bool pm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1337 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | if (tp->link_ok(ioaddr)) { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1339 | rtl_link_chg_patch(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1340 | /* This is to cancel a scheduled suspend if there's one. */ |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 1341 | if (pm) |
| 1342 | pm_request_resume(&tp->pci_dev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | netif_carrier_on(dev); |
Francois Romieu | 1519e57 | 2011-02-03 12:02:36 +0100 | [diff] [blame] | 1344 | if (net_ratelimit()) |
| 1345 | netif_info(tp, ifup, dev, "link up\n"); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1346 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1347 | netif_carrier_off(dev); |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1348 | netif_info(tp, ifdown, dev, "link down\n"); |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 1349 | if (pm) |
hayeswang | 10953db | 2011-11-07 20:44:37 +0000 | [diff] [blame] | 1350 | pm_schedule_suspend(&tp->pci_dev->dev, 5000); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1351 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1352 | } |
| 1353 | |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 1354 | static void rtl8169_check_link_status(struct net_device *dev, |
| 1355 | struct rtl8169_private *tp, |
| 1356 | void __iomem *ioaddr) |
| 1357 | { |
| 1358 | __rtl8169_check_link_status(dev, tp, ioaddr, false); |
| 1359 | } |
| 1360 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1361 | #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST) |
| 1362 | |
| 1363 | static u32 __rtl8169_get_wol(struct rtl8169_private *tp) |
| 1364 | { |
| 1365 | void __iomem *ioaddr = tp->mmio_addr; |
| 1366 | u8 options; |
| 1367 | u32 wolopts = 0; |
| 1368 | |
| 1369 | options = RTL_R8(Config1); |
| 1370 | if (!(options & PMEnable)) |
| 1371 | return 0; |
| 1372 | |
| 1373 | options = RTL_R8(Config3); |
| 1374 | if (options & LinkUp) |
| 1375 | wolopts |= WAKE_PHY; |
| 1376 | if (options & MagicPacket) |
| 1377 | wolopts |= WAKE_MAGIC; |
| 1378 | |
| 1379 | options = RTL_R8(Config5); |
| 1380 | if (options & UWF) |
| 1381 | wolopts |= WAKE_UCAST; |
| 1382 | if (options & BWF) |
| 1383 | wolopts |= WAKE_BCAST; |
| 1384 | if (options & MWF) |
| 1385 | wolopts |= WAKE_MCAST; |
| 1386 | |
| 1387 | return wolopts; |
| 1388 | } |
| 1389 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1390 | static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1391 | { |
| 1392 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1393 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1394 | rtl_lock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1395 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1396 | wol->supported = WAKE_ANY; |
| 1397 | wol->wolopts = __rtl8169_get_wol(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1398 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1399 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1400 | } |
| 1401 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1402 | static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1403 | { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1404 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 1405 | unsigned int i; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 1406 | static const struct { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1407 | u32 opt; |
| 1408 | u16 reg; |
| 1409 | u8 mask; |
| 1410 | } cfg[] = { |
| 1411 | { WAKE_ANY, Config1, PMEnable }, |
| 1412 | { WAKE_PHY, Config3, LinkUp }, |
| 1413 | { WAKE_MAGIC, Config3, MagicPacket }, |
| 1414 | { WAKE_UCAST, Config5, UWF }, |
| 1415 | { WAKE_BCAST, Config5, BWF }, |
| 1416 | { WAKE_MCAST, Config5, MWF }, |
| 1417 | { WAKE_ANY, Config5, LanWake } |
| 1418 | }; |
| 1419 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1420 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 1421 | |
| 1422 | for (i = 0; i < ARRAY_SIZE(cfg); i++) { |
| 1423 | u8 options = RTL_R8(cfg[i].reg) & ~cfg[i].mask; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1424 | if (wolopts & cfg[i].opt) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1425 | options |= cfg[i].mask; |
| 1426 | RTL_W8(cfg[i].reg, options); |
| 1427 | } |
| 1428 | |
| 1429 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1433 | { |
| 1434 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1435 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1436 | rtl_lock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1437 | |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 1438 | if (wol->wolopts) |
| 1439 | tp->features |= RTL_FEATURE_WOL; |
| 1440 | else |
| 1441 | tp->features &= ~RTL_FEATURE_WOL; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1442 | __rtl8169_set_wol(tp, wol->wolopts); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1443 | |
| 1444 | rtl_unlock_work(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1445 | |
françois romieu | ea80907 | 2010-11-08 13:23:58 +0000 | [diff] [blame] | 1446 | device_set_wakeup_enable(&tp->pci_dev->dev, wol->wolopts); |
| 1447 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1448 | return 0; |
| 1449 | } |
| 1450 | |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1451 | static const char *rtl_lookup_firmware_name(struct rtl8169_private *tp) |
| 1452 | { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 1453 | return rtl_chip_infos[tp->mac_version].fw_name; |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1454 | } |
| 1455 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | static void rtl8169_get_drvinfo(struct net_device *dev, |
| 1457 | struct ethtool_drvinfo *info) |
| 1458 | { |
| 1459 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 1460 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 1462 | strlcpy(info->driver, MODULENAME, sizeof(info->driver)); |
| 1463 | strlcpy(info->version, RTL8169_VERSION, sizeof(info->version)); |
| 1464 | 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] | 1465 | BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version)); |
Rick Jones | 8ac72d1 | 2011-11-22 14:06:26 +0000 | [diff] [blame] | 1466 | if (!IS_ERR_OR_NULL(rtl_fw)) |
| 1467 | strlcpy(info->fw_version, rtl_fw->version, |
| 1468 | sizeof(info->fw_version)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | } |
| 1470 | |
| 1471 | static int rtl8169_get_regs_len(struct net_device *dev) |
| 1472 | { |
| 1473 | return R8169_REGS_SIZE; |
| 1474 | } |
| 1475 | |
| 1476 | static int rtl8169_set_speed_tbi(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1477 | u8 autoneg, u16 speed, u8 duplex, u32 ignored) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1478 | { |
| 1479 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1480 | void __iomem *ioaddr = tp->mmio_addr; |
| 1481 | int ret = 0; |
| 1482 | u32 reg; |
| 1483 | |
| 1484 | reg = RTL_R32(TBICSR); |
| 1485 | if ((autoneg == AUTONEG_DISABLE) && (speed == SPEED_1000) && |
| 1486 | (duplex == DUPLEX_FULL)) { |
| 1487 | RTL_W32(TBICSR, reg & ~(TBINwEnable | TBINwRestart)); |
| 1488 | } else if (autoneg == AUTONEG_ENABLE) |
| 1489 | RTL_W32(TBICSR, reg | TBINwEnable | TBINwRestart); |
| 1490 | else { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1491 | netif_warn(tp, link, dev, |
| 1492 | "incorrect speed setting refused in TBI mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | ret = -EOPNOTSUPP; |
| 1494 | } |
| 1495 | |
| 1496 | return ret; |
| 1497 | } |
| 1498 | |
| 1499 | static int rtl8169_set_speed_xmii(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1500 | u8 autoneg, u16 speed, u8 duplex, u32 adv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1501 | { |
| 1502 | struct rtl8169_private *tp = netdev_priv(dev); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1503 | int giga_ctrl, bmcr; |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1504 | int rc = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | |
Hayes Wang | 716b50a | 2011-02-22 17:26:18 +0800 | [diff] [blame] | 1506 | rtl_writephy(tp, 0x1f, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | |
| 1508 | if (autoneg == AUTONEG_ENABLE) { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1509 | int auto_nego; |
| 1510 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1511 | auto_nego = rtl_readphy(tp, MII_ADVERTISE); |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1512 | auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL | |
| 1513 | ADVERTISE_100HALF | ADVERTISE_100FULL); |
| 1514 | |
| 1515 | if (adv & ADVERTISED_10baseT_Half) |
| 1516 | auto_nego |= ADVERTISE_10HALF; |
| 1517 | if (adv & ADVERTISED_10baseT_Full) |
| 1518 | auto_nego |= ADVERTISE_10FULL; |
| 1519 | if (adv & ADVERTISED_100baseT_Half) |
| 1520 | auto_nego |= ADVERTISE_100HALF; |
| 1521 | if (adv & ADVERTISED_100baseT_Full) |
| 1522 | auto_nego |= ADVERTISE_100FULL; |
| 1523 | |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1524 | auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 1525 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1526 | giga_ctrl = rtl_readphy(tp, MII_CTRL1000); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1527 | giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); |
| 1528 | |
| 1529 | /* The 8100e/8101e/8102e do Fast Ethernet only. */ |
Francois Romieu | 826e6cb | 2011-03-11 20:30:24 +0100 | [diff] [blame] | 1530 | if (tp->mii.supports_gmii) { |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1531 | if (adv & ADVERTISED_1000baseT_Half) |
| 1532 | giga_ctrl |= ADVERTISE_1000HALF; |
| 1533 | if (adv & ADVERTISED_1000baseT_Full) |
| 1534 | giga_ctrl |= ADVERTISE_1000FULL; |
| 1535 | } else if (adv & (ADVERTISED_1000baseT_Half | |
| 1536 | ADVERTISED_1000baseT_Full)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1537 | netif_info(tp, link, dev, |
| 1538 | "PHY does not support 1000Mbps\n"); |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1539 | goto out; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 1540 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1541 | |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1542 | bmcr = BMCR_ANENABLE | BMCR_ANRESTART; |
Francois Romieu | 623a159 | 2006-05-14 12:42:14 +0200 | [diff] [blame] | 1543 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1544 | rtl_writephy(tp, MII_ADVERTISE, auto_nego); |
| 1545 | rtl_writephy(tp, MII_CTRL1000, giga_ctrl); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1546 | } else { |
| 1547 | giga_ctrl = 0; |
| 1548 | |
| 1549 | if (speed == SPEED_10) |
| 1550 | bmcr = 0; |
| 1551 | else if (speed == SPEED_100) |
| 1552 | bmcr = BMCR_SPEED100; |
| 1553 | else |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1554 | goto out; |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1555 | |
| 1556 | if (duplex == DUPLEX_FULL) |
| 1557 | bmcr |= BMCR_FULLDPLX; |
Roger So | 2584fbc | 2007-07-31 23:52:42 +0200 | [diff] [blame] | 1558 | } |
| 1559 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1560 | rtl_writephy(tp, MII_BMCR, bmcr); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1561 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1562 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 1563 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1564 | if ((speed == SPEED_100) && (autoneg != AUTONEG_ENABLE)) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1565 | rtl_writephy(tp, 0x17, 0x2138); |
| 1566 | rtl_writephy(tp, 0x0e, 0x0260); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1567 | } else { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1568 | rtl_writephy(tp, 0x17, 0x2108); |
| 1569 | rtl_writephy(tp, 0x0e, 0x0000); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1570 | } |
| 1571 | } |
| 1572 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1573 | rc = 0; |
| 1574 | out: |
| 1575 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | static int rtl8169_set_speed(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1579 | u8 autoneg, u16 speed, u8 duplex, u32 advertising) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1580 | { |
| 1581 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1582 | int ret; |
| 1583 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1584 | ret = tp->set_speed(dev, autoneg, speed, duplex, advertising); |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1585 | if (ret < 0) |
| 1586 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1587 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1588 | if (netif_running(dev) && (autoneg == AUTONEG_ENABLE) && |
| 1589 | (advertising & ADVERTISED_1000baseT_Full)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | mod_timer(&tp->timer, jiffies + RTL8169_PHY_TIMEOUT); |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1591 | } |
| 1592 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | return ret; |
| 1594 | } |
| 1595 | |
| 1596 | static int rtl8169_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 1597 | { |
| 1598 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1599 | int ret; |
| 1600 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1601 | del_timer_sync(&tp->timer); |
| 1602 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1603 | rtl_lock_work(tp); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1604 | ret = rtl8169_set_speed(dev, cmd->autoneg, ethtool_cmd_speed(cmd), |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 1605 | cmd->duplex, cmd->advertising); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1606 | rtl_unlock_work(tp); |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1607 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1608 | return ret; |
| 1609 | } |
| 1610 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 1611 | static netdev_features_t rtl8169_fix_features(struct net_device *dev, |
| 1612 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1613 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1614 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1615 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 1616 | if (dev->mtu > TD_MSS_MAX) |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1617 | features &= ~NETIF_F_ALL_TSO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1618 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 1619 | if (dev->mtu > JUMBO_1K && |
| 1620 | !rtl_chip_infos[tp->mac_version].jumbo_tx_csum) |
| 1621 | features &= ~NETIF_F_IP_CSUM; |
| 1622 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1623 | return features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1624 | } |
| 1625 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1626 | static void __rtl8169_set_features(struct net_device *dev, |
| 1627 | netdev_features_t features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | { |
| 1629 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1631 | void __iomem *ioaddr = tp->mmio_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1632 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1633 | if (features & NETIF_F_RXCSUM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1634 | tp->cp_cmd |= RxChkSum; |
| 1635 | else |
| 1636 | tp->cp_cmd &= ~RxChkSum; |
| 1637 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1638 | if (dev->features & NETIF_F_HW_VLAN_RX) |
| 1639 | tp->cp_cmd |= RxVlan; |
| 1640 | else |
| 1641 | tp->cp_cmd &= ~RxVlan; |
| 1642 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1643 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 1644 | RTL_R16(CPlusCmd); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1645 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1646 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1647 | static int rtl8169_set_features(struct net_device *dev, |
| 1648 | netdev_features_t features) |
| 1649 | { |
| 1650 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1651 | |
| 1652 | rtl_lock_work(tp); |
| 1653 | __rtl8169_set_features(dev, features); |
| 1654 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | |
| 1656 | return 0; |
| 1657 | } |
| 1658 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1659 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | static inline u32 rtl8169_tx_vlan_tag(struct rtl8169_private *tp, |
| 1661 | struct sk_buff *skb) |
| 1662 | { |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 1663 | return (vlan_tx_tag_present(skb)) ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1664 | TxVlanTag | swab16(vlan_tx_tag_get(skb)) : 0x00; |
| 1665 | } |
| 1666 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1667 | 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] | 1668 | { |
| 1669 | u32 opts2 = le32_to_cpu(desc->opts2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1670 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1671 | if (opts2 & RxVlanTag) |
| 1672 | __vlan_hwaccel_put_tag(skb, swab16(opts2 & 0xffff)); |
Eric Dumazet | 2edae08 | 2010-09-06 18:46:39 +0000 | [diff] [blame] | 1673 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | desc->opts2 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1675 | } |
| 1676 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1677 | 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] | 1678 | { |
| 1679 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1680 | void __iomem *ioaddr = tp->mmio_addr; |
| 1681 | u32 status; |
| 1682 | |
| 1683 | cmd->supported = |
| 1684 | SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE; |
| 1685 | cmd->port = PORT_FIBRE; |
| 1686 | cmd->transceiver = XCVR_INTERNAL; |
| 1687 | |
| 1688 | status = RTL_R32(TBICSR); |
| 1689 | cmd->advertising = (status & TBINwEnable) ? ADVERTISED_Autoneg : 0; |
| 1690 | cmd->autoneg = !!(status & TBINwEnable); |
| 1691 | |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 1692 | ethtool_cmd_speed_set(cmd, SPEED_1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1693 | cmd->duplex = DUPLEX_FULL; /* Always set */ |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1694 | |
| 1695 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1696 | } |
| 1697 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1698 | 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] | 1699 | { |
| 1700 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1701 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1702 | return mii_ethtool_gset(&tp->mii, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1703 | } |
| 1704 | |
| 1705 | static int rtl8169_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 1706 | { |
| 1707 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1708 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1710 | rtl_lock_work(tp); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1711 | rc = tp->get_settings(dev, cmd); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1712 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1713 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1714 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1715 | } |
| 1716 | |
| 1717 | static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 1718 | void *p) |
| 1719 | { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1720 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1721 | |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1722 | if (regs->len > R8169_REGS_SIZE) |
| 1723 | regs->len = R8169_REGS_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1724 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1725 | rtl_lock_work(tp); |
| 1726 | spin_lock_bh(&tp->lock); |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1727 | memcpy_fromio(p, tp->mmio_addr, regs->len); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 1728 | spin_unlock_bh(&tp->lock); |
| 1729 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1730 | } |
| 1731 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1732 | static u32 rtl8169_get_msglevel(struct net_device *dev) |
| 1733 | { |
| 1734 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1735 | |
| 1736 | return tp->msg_enable; |
| 1737 | } |
| 1738 | |
| 1739 | static void rtl8169_set_msglevel(struct net_device *dev, u32 value) |
| 1740 | { |
| 1741 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1742 | |
| 1743 | tp->msg_enable = value; |
| 1744 | } |
| 1745 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1746 | static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = { |
| 1747 | "tx_packets", |
| 1748 | "rx_packets", |
| 1749 | "tx_errors", |
| 1750 | "rx_errors", |
| 1751 | "rx_missed", |
| 1752 | "align_errors", |
| 1753 | "tx_single_collisions", |
| 1754 | "tx_multi_collisions", |
| 1755 | "unicast", |
| 1756 | "broadcast", |
| 1757 | "multicast", |
| 1758 | "tx_aborted", |
| 1759 | "tx_underrun", |
| 1760 | }; |
| 1761 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1762 | static int rtl8169_get_sset_count(struct net_device *dev, int sset) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1763 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1764 | switch (sset) { |
| 1765 | case ETH_SS_STATS: |
| 1766 | return ARRAY_SIZE(rtl8169_gstrings); |
| 1767 | default: |
| 1768 | return -EOPNOTSUPP; |
| 1769 | } |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1770 | } |
| 1771 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1772 | static void rtl8169_update_counters(struct net_device *dev) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1773 | { |
| 1774 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1775 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1776 | struct device *d = &tp->pci_dev->dev; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1777 | struct rtl8169_counters *counters; |
| 1778 | dma_addr_t paddr; |
| 1779 | u32 cmd; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1780 | int wait = 1000; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1781 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1782 | /* |
| 1783 | * Some chips are unable to dump tally counters when the receiver |
| 1784 | * is disabled. |
| 1785 | */ |
| 1786 | if ((RTL_R8(ChipCmd) & CmdRxEnb) == 0) |
| 1787 | return; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1788 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 1789 | counters = dma_alloc_coherent(d, sizeof(*counters), &paddr, GFP_KERNEL); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1790 | if (!counters) |
| 1791 | return; |
| 1792 | |
| 1793 | RTL_W32(CounterAddrHigh, (u64)paddr >> 32); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1794 | cmd = (u64)paddr & DMA_BIT_MASK(32); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1795 | RTL_W32(CounterAddrLow, cmd); |
| 1796 | RTL_W32(CounterAddrLow, cmd | CounterDump); |
| 1797 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1798 | while (wait--) { |
| 1799 | if ((RTL_R32(CounterAddrLow) & CounterDump) == 0) { |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1800 | memcpy(&tp->counters, counters, sizeof(*counters)); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1801 | break; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1802 | } |
| 1803 | udelay(10); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1804 | } |
| 1805 | |
| 1806 | RTL_W32(CounterAddrLow, 0); |
| 1807 | RTL_W32(CounterAddrHigh, 0); |
| 1808 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 1809 | dma_free_coherent(d, sizeof(*counters), counters, paddr); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1810 | } |
| 1811 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1812 | static void rtl8169_get_ethtool_stats(struct net_device *dev, |
| 1813 | struct ethtool_stats *stats, u64 *data) |
| 1814 | { |
| 1815 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1816 | |
| 1817 | ASSERT_RTNL(); |
| 1818 | |
| 1819 | rtl8169_update_counters(dev); |
| 1820 | |
| 1821 | data[0] = le64_to_cpu(tp->counters.tx_packets); |
| 1822 | data[1] = le64_to_cpu(tp->counters.rx_packets); |
| 1823 | data[2] = le64_to_cpu(tp->counters.tx_errors); |
| 1824 | data[3] = le32_to_cpu(tp->counters.rx_errors); |
| 1825 | data[4] = le16_to_cpu(tp->counters.rx_missed); |
| 1826 | data[5] = le16_to_cpu(tp->counters.align_errors); |
| 1827 | data[6] = le32_to_cpu(tp->counters.tx_one_collision); |
| 1828 | data[7] = le32_to_cpu(tp->counters.tx_multi_collision); |
| 1829 | data[8] = le64_to_cpu(tp->counters.rx_unicast); |
| 1830 | data[9] = le64_to_cpu(tp->counters.rx_broadcast); |
| 1831 | data[10] = le32_to_cpu(tp->counters.rx_multicast); |
| 1832 | data[11] = le16_to_cpu(tp->counters.tx_aborted); |
| 1833 | data[12] = le16_to_cpu(tp->counters.tx_underun); |
| 1834 | } |
| 1835 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1836 | static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 1837 | { |
| 1838 | switch(stringset) { |
| 1839 | case ETH_SS_STATS: |
| 1840 | memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings)); |
| 1841 | break; |
| 1842 | } |
| 1843 | } |
| 1844 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 1845 | static const struct ethtool_ops rtl8169_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1846 | .get_drvinfo = rtl8169_get_drvinfo, |
| 1847 | .get_regs_len = rtl8169_get_regs_len, |
| 1848 | .get_link = ethtool_op_get_link, |
| 1849 | .get_settings = rtl8169_get_settings, |
| 1850 | .set_settings = rtl8169_set_settings, |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1851 | .get_msglevel = rtl8169_get_msglevel, |
| 1852 | .set_msglevel = rtl8169_set_msglevel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1853 | .get_regs = rtl8169_get_regs, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1854 | .get_wol = rtl8169_get_wol, |
| 1855 | .set_wol = rtl8169_set_wol, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1856 | .get_strings = rtl8169_get_strings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1857 | .get_sset_count = rtl8169_get_sset_count, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1858 | .get_ethtool_stats = rtl8169_get_ethtool_stats, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1859 | }; |
| 1860 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 1861 | static void rtl8169_get_mac_version(struct rtl8169_private *tp, |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 1862 | struct net_device *dev, u8 default_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | { |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 1864 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 1865 | /* |
| 1866 | * The driver currently handles the 8168Bf and the 8168Be identically |
| 1867 | * but they can be identified more specifically through the test below |
| 1868 | * if needed: |
| 1869 | * |
| 1870 | * (RTL_R32(TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be |
Francois Romieu | 0127215 | 2007-02-20 22:58:51 +0100 | [diff] [blame] | 1871 | * |
| 1872 | * Same thing for the 8101Eb and the 8101Ec: |
| 1873 | * |
| 1874 | * (RTL_R32(TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 1875 | */ |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 1876 | static const struct rtl_mac_info { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1877 | u32 mask; |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 1878 | u32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1879 | int mac_version; |
| 1880 | } mac_info[] = { |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 1881 | /* 8168F family. */ |
| 1882 | { 0x7cf00000, 0x48100000, RTL_GIGA_MAC_VER_36 }, |
| 1883 | { 0x7cf00000, 0x48000000, RTL_GIGA_MAC_VER_35 }, |
| 1884 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 1885 | /* 8168E family. */ |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1886 | { 0x7c800000, 0x2c800000, RTL_GIGA_MAC_VER_34 }, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 1887 | { 0x7cf00000, 0x2c200000, RTL_GIGA_MAC_VER_33 }, |
| 1888 | { 0x7cf00000, 0x2c100000, RTL_GIGA_MAC_VER_32 }, |
| 1889 | { 0x7c800000, 0x2c000000, RTL_GIGA_MAC_VER_33 }, |
| 1890 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 1891 | /* 8168D family. */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1892 | { 0x7cf00000, 0x28300000, RTL_GIGA_MAC_VER_26 }, |
| 1893 | { 0x7cf00000, 0x28100000, RTL_GIGA_MAC_VER_25 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1894 | { 0x7c800000, 0x28000000, RTL_GIGA_MAC_VER_26 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 1895 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1896 | /* 8168DP family. */ |
| 1897 | { 0x7cf00000, 0x28800000, RTL_GIGA_MAC_VER_27 }, |
| 1898 | { 0x7cf00000, 0x28a00000, RTL_GIGA_MAC_VER_28 }, |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 1899 | { 0x7cf00000, 0x28b00000, RTL_GIGA_MAC_VER_31 }, |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1900 | |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 1901 | /* 8168C family. */ |
Francois Romieu | 17c9929 | 2010-07-11 17:10:09 -0700 | [diff] [blame] | 1902 | { 0x7cf00000, 0x3cb00000, RTL_GIGA_MAC_VER_24 }, |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 1903 | { 0x7cf00000, 0x3c900000, RTL_GIGA_MAC_VER_23 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 1904 | { 0x7cf00000, 0x3c800000, RTL_GIGA_MAC_VER_18 }, |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 1905 | { 0x7c800000, 0x3c800000, RTL_GIGA_MAC_VER_24 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 1906 | { 0x7cf00000, 0x3c000000, RTL_GIGA_MAC_VER_19 }, |
| 1907 | { 0x7cf00000, 0x3c200000, RTL_GIGA_MAC_VER_20 }, |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 1908 | { 0x7cf00000, 0x3c300000, RTL_GIGA_MAC_VER_21 }, |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 1909 | { 0x7cf00000, 0x3c400000, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 1910 | { 0x7c800000, 0x3c000000, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 1911 | |
| 1912 | /* 8168B family. */ |
| 1913 | { 0x7cf00000, 0x38000000, RTL_GIGA_MAC_VER_12 }, |
| 1914 | { 0x7cf00000, 0x38500000, RTL_GIGA_MAC_VER_17 }, |
| 1915 | { 0x7c800000, 0x38000000, RTL_GIGA_MAC_VER_17 }, |
| 1916 | { 0x7c800000, 0x30000000, RTL_GIGA_MAC_VER_11 }, |
| 1917 | |
| 1918 | /* 8101 family. */ |
hayeswang | 36a0e6c | 2011-03-21 01:50:30 +0000 | [diff] [blame] | 1919 | { 0x7cf00000, 0x40b00000, RTL_GIGA_MAC_VER_30 }, |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 1920 | { 0x7cf00000, 0x40a00000, RTL_GIGA_MAC_VER_30 }, |
| 1921 | { 0x7cf00000, 0x40900000, RTL_GIGA_MAC_VER_29 }, |
| 1922 | { 0x7c800000, 0x40800000, RTL_GIGA_MAC_VER_30 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 1923 | { 0x7cf00000, 0x34a00000, RTL_GIGA_MAC_VER_09 }, |
| 1924 | { 0x7cf00000, 0x24a00000, RTL_GIGA_MAC_VER_09 }, |
| 1925 | { 0x7cf00000, 0x34900000, RTL_GIGA_MAC_VER_08 }, |
| 1926 | { 0x7cf00000, 0x24900000, RTL_GIGA_MAC_VER_08 }, |
| 1927 | { 0x7cf00000, 0x34800000, RTL_GIGA_MAC_VER_07 }, |
| 1928 | { 0x7cf00000, 0x24800000, RTL_GIGA_MAC_VER_07 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 1929 | { 0x7cf00000, 0x34000000, RTL_GIGA_MAC_VER_13 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 1930 | { 0x7cf00000, 0x34300000, RTL_GIGA_MAC_VER_10 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 1931 | { 0x7cf00000, 0x34200000, RTL_GIGA_MAC_VER_16 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 1932 | { 0x7c800000, 0x34800000, RTL_GIGA_MAC_VER_09 }, |
| 1933 | { 0x7c800000, 0x24800000, RTL_GIGA_MAC_VER_09 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 1934 | { 0x7c800000, 0x34000000, RTL_GIGA_MAC_VER_16 }, |
| 1935 | /* FIXME: where did these entries come from ? -- FR */ |
| 1936 | { 0xfc800000, 0x38800000, RTL_GIGA_MAC_VER_15 }, |
| 1937 | { 0xfc800000, 0x30800000, RTL_GIGA_MAC_VER_14 }, |
| 1938 | |
| 1939 | /* 8110 family. */ |
| 1940 | { 0xfc800000, 0x98000000, RTL_GIGA_MAC_VER_06 }, |
| 1941 | { 0xfc800000, 0x18000000, RTL_GIGA_MAC_VER_05 }, |
| 1942 | { 0xfc800000, 0x10000000, RTL_GIGA_MAC_VER_04 }, |
| 1943 | { 0xfc800000, 0x04000000, RTL_GIGA_MAC_VER_03 }, |
| 1944 | { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 }, |
| 1945 | { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 }, |
| 1946 | |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 1947 | /* Catch-all */ |
| 1948 | { 0x00000000, 0x00000000, RTL_GIGA_MAC_NONE } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 1949 | }; |
| 1950 | const struct rtl_mac_info *p = mac_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1951 | u32 reg; |
| 1952 | |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 1953 | reg = RTL_R32(TxConfig); |
| 1954 | while ((reg & p->mask) != p->val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1955 | p++; |
| 1956 | tp->mac_version = p->mac_version; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 1957 | |
| 1958 | if (tp->mac_version == RTL_GIGA_MAC_NONE) { |
| 1959 | netif_notice(tp, probe, dev, |
| 1960 | "unknown MAC, using family default\n"); |
| 1961 | tp->mac_version = default_version; |
| 1962 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1963 | } |
| 1964 | |
| 1965 | static void rtl8169_print_mac_version(struct rtl8169_private *tp) |
| 1966 | { |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 1967 | dprintk("mac_version = 0x%02x\n", tp->mac_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1968 | } |
| 1969 | |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 1970 | struct phy_reg { |
| 1971 | u16 reg; |
| 1972 | u16 val; |
| 1973 | }; |
| 1974 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1975 | static void rtl_writephy_batch(struct rtl8169_private *tp, |
| 1976 | const struct phy_reg *regs, int len) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 1977 | { |
| 1978 | while (len-- > 0) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1979 | rtl_writephy(tp, regs->reg, regs->val); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 1980 | regs++; |
| 1981 | } |
| 1982 | } |
| 1983 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 1984 | #define PHY_READ 0x00000000 |
| 1985 | #define PHY_DATA_OR 0x10000000 |
| 1986 | #define PHY_DATA_AND 0x20000000 |
| 1987 | #define PHY_BJMPN 0x30000000 |
| 1988 | #define PHY_READ_EFUSE 0x40000000 |
| 1989 | #define PHY_READ_MAC_BYTE 0x50000000 |
| 1990 | #define PHY_WRITE_MAC_BYTE 0x60000000 |
| 1991 | #define PHY_CLEAR_READCOUNT 0x70000000 |
| 1992 | #define PHY_WRITE 0x80000000 |
| 1993 | #define PHY_READCOUNT_EQ_SKIP 0x90000000 |
| 1994 | #define PHY_COMP_EQ_SKIPN 0xa0000000 |
| 1995 | #define PHY_COMP_NEQ_SKIPN 0xb0000000 |
| 1996 | #define PHY_WRITE_PREVIOUS 0xc0000000 |
| 1997 | #define PHY_SKIPN 0xd0000000 |
| 1998 | #define PHY_DELAY_MS 0xe0000000 |
| 1999 | #define PHY_WRITE_ERI_WORD 0xf0000000 |
| 2000 | |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2001 | struct fw_info { |
| 2002 | u32 magic; |
| 2003 | char version[RTL_VER_SIZE]; |
| 2004 | __le32 fw_start; |
| 2005 | __le32 fw_len; |
| 2006 | u8 chksum; |
| 2007 | } __packed; |
| 2008 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2009 | #define FW_OPCODE_SIZE sizeof(typeof(*((struct rtl_fw_phy_action *)0)->code)) |
| 2010 | |
| 2011 | 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] | 2012 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2013 | const struct firmware *fw = rtl_fw->fw; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2014 | struct fw_info *fw_info = (struct fw_info *)fw->data; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2015 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
| 2016 | char *version = rtl_fw->version; |
| 2017 | bool rc = false; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2018 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2019 | if (fw->size < FW_OPCODE_SIZE) |
| 2020 | goto out; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 2021 | |
| 2022 | if (!fw_info->magic) { |
| 2023 | size_t i, size, start; |
| 2024 | u8 checksum = 0; |
| 2025 | |
| 2026 | if (fw->size < sizeof(*fw_info)) |
| 2027 | goto out; |
| 2028 | |
| 2029 | for (i = 0; i < fw->size; i++) |
| 2030 | checksum += fw->data[i]; |
| 2031 | if (checksum != 0) |
| 2032 | goto out; |
| 2033 | |
| 2034 | start = le32_to_cpu(fw_info->fw_start); |
| 2035 | if (start > fw->size) |
| 2036 | goto out; |
| 2037 | |
| 2038 | size = le32_to_cpu(fw_info->fw_len); |
| 2039 | if (size > (fw->size - start) / FW_OPCODE_SIZE) |
| 2040 | goto out; |
| 2041 | |
| 2042 | memcpy(version, fw_info->version, RTL_VER_SIZE); |
| 2043 | |
| 2044 | pa->code = (__le32 *)(fw->data + start); |
| 2045 | pa->size = size; |
| 2046 | } else { |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2047 | if (fw->size % FW_OPCODE_SIZE) |
| 2048 | goto out; |
| 2049 | |
| 2050 | strlcpy(version, rtl_lookup_firmware_name(tp), RTL_VER_SIZE); |
| 2051 | |
| 2052 | pa->code = (__le32 *)fw->data; |
| 2053 | pa->size = fw->size / FW_OPCODE_SIZE; |
| 2054 | } |
| 2055 | version[RTL_VER_SIZE - 1] = 0; |
| 2056 | |
| 2057 | rc = true; |
| 2058 | out: |
| 2059 | return rc; |
| 2060 | } |
| 2061 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2062 | static bool rtl_fw_data_ok(struct rtl8169_private *tp, struct net_device *dev, |
| 2063 | struct rtl_fw_phy_action *pa) |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2064 | { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2065 | bool rc = false; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2066 | size_t index; |
| 2067 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2068 | for (index = 0; index < pa->size; index++) { |
| 2069 | u32 action = le32_to_cpu(pa->code[index]); |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2070 | u32 regno = (action & 0x0fff0000) >> 16; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2071 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2072 | switch(action & 0xf0000000) { |
| 2073 | case PHY_READ: |
| 2074 | case PHY_DATA_OR: |
| 2075 | case PHY_DATA_AND: |
| 2076 | case PHY_READ_EFUSE: |
| 2077 | case PHY_CLEAR_READCOUNT: |
| 2078 | case PHY_WRITE: |
| 2079 | case PHY_WRITE_PREVIOUS: |
| 2080 | case PHY_DELAY_MS: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2081 | break; |
| 2082 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2083 | case PHY_BJMPN: |
| 2084 | if (regno > index) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2085 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2086 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2087 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2088 | } |
| 2089 | break; |
| 2090 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2091 | if (index + 2 >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2092 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2093 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2094 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2095 | } |
| 2096 | break; |
| 2097 | case PHY_COMP_EQ_SKIPN: |
| 2098 | case PHY_COMP_NEQ_SKIPN: |
| 2099 | case PHY_SKIPN: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2100 | if (index + 1 + regno >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2101 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2102 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2103 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2104 | } |
| 2105 | break; |
| 2106 | |
| 2107 | case PHY_READ_MAC_BYTE: |
| 2108 | case PHY_WRITE_MAC_BYTE: |
| 2109 | case PHY_WRITE_ERI_WORD: |
| 2110 | default: |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2111 | netif_err(tp, ifup, tp->dev, |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2112 | "Invalid action 0x%08x\n", action); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2113 | goto out; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2114 | } |
| 2115 | } |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2116 | rc = true; |
| 2117 | out: |
| 2118 | return rc; |
| 2119 | } |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2120 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 2121 | static int rtl_check_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2122 | { |
| 2123 | struct net_device *dev = tp->dev; |
| 2124 | int rc = -EINVAL; |
| 2125 | |
| 2126 | if (!rtl_fw_format_ok(tp, rtl_fw)) { |
| 2127 | netif_err(tp, ifup, dev, "invalid firwmare\n"); |
| 2128 | goto out; |
| 2129 | } |
| 2130 | |
| 2131 | if (rtl_fw_data_ok(tp, dev, &rtl_fw->phy_action)) |
| 2132 | rc = 0; |
| 2133 | out: |
| 2134 | return rc; |
| 2135 | } |
| 2136 | |
| 2137 | static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 2138 | { |
| 2139 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
| 2140 | u32 predata, count; |
| 2141 | size_t index; |
| 2142 | |
| 2143 | predata = count = 0; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2144 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2145 | for (index = 0; index < pa->size; ) { |
| 2146 | u32 action = le32_to_cpu(pa->code[index]); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2147 | u32 data = action & 0x0000ffff; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2148 | u32 regno = (action & 0x0fff0000) >> 16; |
| 2149 | |
| 2150 | if (!action) |
| 2151 | break; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2152 | |
| 2153 | switch(action & 0xf0000000) { |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2154 | case PHY_READ: |
| 2155 | predata = rtl_readphy(tp, regno); |
| 2156 | count++; |
| 2157 | index++; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2158 | break; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2159 | case PHY_DATA_OR: |
| 2160 | predata |= data; |
| 2161 | index++; |
| 2162 | break; |
| 2163 | case PHY_DATA_AND: |
| 2164 | predata &= data; |
| 2165 | index++; |
| 2166 | break; |
| 2167 | case PHY_BJMPN: |
| 2168 | index -= regno; |
| 2169 | break; |
| 2170 | case PHY_READ_EFUSE: |
| 2171 | predata = rtl8168d_efuse_read(tp->mmio_addr, regno); |
| 2172 | index++; |
| 2173 | break; |
| 2174 | case PHY_CLEAR_READCOUNT: |
| 2175 | count = 0; |
| 2176 | index++; |
| 2177 | break; |
| 2178 | case PHY_WRITE: |
| 2179 | rtl_writephy(tp, regno, data); |
| 2180 | index++; |
| 2181 | break; |
| 2182 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2183 | index += (count == data) ? 2 : 1; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2184 | break; |
| 2185 | case PHY_COMP_EQ_SKIPN: |
| 2186 | if (predata == data) |
| 2187 | index += regno; |
| 2188 | index++; |
| 2189 | break; |
| 2190 | case PHY_COMP_NEQ_SKIPN: |
| 2191 | if (predata != data) |
| 2192 | index += regno; |
| 2193 | index++; |
| 2194 | break; |
| 2195 | case PHY_WRITE_PREVIOUS: |
| 2196 | rtl_writephy(tp, regno, predata); |
| 2197 | index++; |
| 2198 | break; |
| 2199 | case PHY_SKIPN: |
| 2200 | index += regno + 1; |
| 2201 | break; |
| 2202 | case PHY_DELAY_MS: |
| 2203 | mdelay(data); |
| 2204 | index++; |
| 2205 | break; |
| 2206 | |
| 2207 | case PHY_READ_MAC_BYTE: |
| 2208 | case PHY_WRITE_MAC_BYTE: |
| 2209 | case PHY_WRITE_ERI_WORD: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2210 | default: |
| 2211 | BUG(); |
| 2212 | } |
| 2213 | } |
| 2214 | } |
| 2215 | |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2216 | static void rtl_release_firmware(struct rtl8169_private *tp) |
| 2217 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2218 | if (!IS_ERR_OR_NULL(tp->rtl_fw)) { |
| 2219 | release_firmware(tp->rtl_fw->fw); |
| 2220 | kfree(tp->rtl_fw); |
| 2221 | } |
| 2222 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2223 | } |
| 2224 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2225 | static void rtl_apply_firmware(struct rtl8169_private *tp) |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2226 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2227 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2228 | |
| 2229 | /* TODO: release firmware once rtl_phy_write_fw signals failures. */ |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2230 | if (!IS_ERR_OR_NULL(rtl_fw)) |
| 2231 | rtl_phy_write_fw(tp, rtl_fw); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2232 | } |
| 2233 | |
| 2234 | static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val) |
| 2235 | { |
| 2236 | if (rtl_readphy(tp, reg) != val) |
| 2237 | netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n"); |
| 2238 | else |
| 2239 | rtl_apply_firmware(tp); |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2240 | } |
| 2241 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2242 | static void rtl8169s_hw_phy_config(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2243 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2244 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2245 | { 0x1f, 0x0001 }, |
| 2246 | { 0x06, 0x006e }, |
| 2247 | { 0x08, 0x0708 }, |
| 2248 | { 0x15, 0x4000 }, |
| 2249 | { 0x18, 0x65c7 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2250 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2251 | { 0x1f, 0x0001 }, |
| 2252 | { 0x03, 0x00a1 }, |
| 2253 | { 0x02, 0x0008 }, |
| 2254 | { 0x01, 0x0120 }, |
| 2255 | { 0x00, 0x1000 }, |
| 2256 | { 0x04, 0x0800 }, |
| 2257 | { 0x04, 0x0000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2258 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2259 | { 0x03, 0xff41 }, |
| 2260 | { 0x02, 0xdf60 }, |
| 2261 | { 0x01, 0x0140 }, |
| 2262 | { 0x00, 0x0077 }, |
| 2263 | { 0x04, 0x7800 }, |
| 2264 | { 0x04, 0x7000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2265 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2266 | { 0x03, 0x802f }, |
| 2267 | { 0x02, 0x4f02 }, |
| 2268 | { 0x01, 0x0409 }, |
| 2269 | { 0x00, 0xf0f9 }, |
| 2270 | { 0x04, 0x9800 }, |
| 2271 | { 0x04, 0x9000 }, |
| 2272 | |
| 2273 | { 0x03, 0xdf01 }, |
| 2274 | { 0x02, 0xdf20 }, |
| 2275 | { 0x01, 0xff95 }, |
| 2276 | { 0x00, 0xba00 }, |
| 2277 | { 0x04, 0xa800 }, |
| 2278 | { 0x04, 0xa000 }, |
| 2279 | |
| 2280 | { 0x03, 0xff41 }, |
| 2281 | { 0x02, 0xdf20 }, |
| 2282 | { 0x01, 0x0140 }, |
| 2283 | { 0x00, 0x00bb }, |
| 2284 | { 0x04, 0xb800 }, |
| 2285 | { 0x04, 0xb000 }, |
| 2286 | |
| 2287 | { 0x03, 0xdf41 }, |
| 2288 | { 0x02, 0xdc60 }, |
| 2289 | { 0x01, 0x6340 }, |
| 2290 | { 0x00, 0x007d }, |
| 2291 | { 0x04, 0xd800 }, |
| 2292 | { 0x04, 0xd000 }, |
| 2293 | |
| 2294 | { 0x03, 0xdf01 }, |
| 2295 | { 0x02, 0xdf20 }, |
| 2296 | { 0x01, 0x100a }, |
| 2297 | { 0x00, 0xa0ff }, |
| 2298 | { 0x04, 0xf800 }, |
| 2299 | { 0x04, 0xf000 }, |
| 2300 | |
| 2301 | { 0x1f, 0x0000 }, |
| 2302 | { 0x0b, 0x0000 }, |
| 2303 | { 0x00, 0x9200 } |
| 2304 | }; |
| 2305 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2306 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2307 | } |
| 2308 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2309 | static void rtl8169sb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2310 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2311 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a441d7b | 2007-08-17 18:26:35 +0200 | [diff] [blame] | 2312 | { 0x1f, 0x0002 }, |
| 2313 | { 0x01, 0x90d0 }, |
| 2314 | { 0x1f, 0x0000 } |
| 2315 | }; |
| 2316 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2317 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2318 | } |
| 2319 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2320 | static void rtl8169scd_hw_phy_config_quirk(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2321 | { |
| 2322 | struct pci_dev *pdev = tp->pci_dev; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2323 | |
Sergei Shtylyov | ccbae55 | 2011-07-22 05:37:24 +0000 | [diff] [blame] | 2324 | if ((pdev->subsystem_vendor != PCI_VENDOR_ID_GIGABYTE) || |
| 2325 | (pdev->subsystem_device != 0xe000)) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2326 | return; |
| 2327 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2328 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2329 | rtl_writephy(tp, 0x10, 0xf01b); |
| 2330 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2331 | } |
| 2332 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2333 | static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2334 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2335 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2336 | { 0x1f, 0x0001 }, |
| 2337 | { 0x04, 0x0000 }, |
| 2338 | { 0x03, 0x00a1 }, |
| 2339 | { 0x02, 0x0008 }, |
| 2340 | { 0x01, 0x0120 }, |
| 2341 | { 0x00, 0x1000 }, |
| 2342 | { 0x04, 0x0800 }, |
| 2343 | { 0x04, 0x9000 }, |
| 2344 | { 0x03, 0x802f }, |
| 2345 | { 0x02, 0x4f02 }, |
| 2346 | { 0x01, 0x0409 }, |
| 2347 | { 0x00, 0xf099 }, |
| 2348 | { 0x04, 0x9800 }, |
| 2349 | { 0x04, 0xa000 }, |
| 2350 | { 0x03, 0xdf01 }, |
| 2351 | { 0x02, 0xdf20 }, |
| 2352 | { 0x01, 0xff95 }, |
| 2353 | { 0x00, 0xba00 }, |
| 2354 | { 0x04, 0xa800 }, |
| 2355 | { 0x04, 0xf000 }, |
| 2356 | { 0x03, 0xdf01 }, |
| 2357 | { 0x02, 0xdf20 }, |
| 2358 | { 0x01, 0x101a }, |
| 2359 | { 0x00, 0xa0ff }, |
| 2360 | { 0x04, 0xf800 }, |
| 2361 | { 0x04, 0x0000 }, |
| 2362 | { 0x1f, 0x0000 }, |
| 2363 | |
| 2364 | { 0x1f, 0x0001 }, |
| 2365 | { 0x10, 0xf41b }, |
| 2366 | { 0x14, 0xfb54 }, |
| 2367 | { 0x18, 0xf5c7 }, |
| 2368 | { 0x1f, 0x0000 }, |
| 2369 | |
| 2370 | { 0x1f, 0x0001 }, |
| 2371 | { 0x17, 0x0cc0 }, |
| 2372 | { 0x1f, 0x0000 } |
| 2373 | }; |
| 2374 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2375 | 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] | 2376 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2377 | rtl8169scd_hw_phy_config_quirk(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2378 | } |
| 2379 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2380 | static void rtl8169sce_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2381 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2382 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2383 | { 0x1f, 0x0001 }, |
| 2384 | { 0x04, 0x0000 }, |
| 2385 | { 0x03, 0x00a1 }, |
| 2386 | { 0x02, 0x0008 }, |
| 2387 | { 0x01, 0x0120 }, |
| 2388 | { 0x00, 0x1000 }, |
| 2389 | { 0x04, 0x0800 }, |
| 2390 | { 0x04, 0x9000 }, |
| 2391 | { 0x03, 0x802f }, |
| 2392 | { 0x02, 0x4f02 }, |
| 2393 | { 0x01, 0x0409 }, |
| 2394 | { 0x00, 0xf099 }, |
| 2395 | { 0x04, 0x9800 }, |
| 2396 | { 0x04, 0xa000 }, |
| 2397 | { 0x03, 0xdf01 }, |
| 2398 | { 0x02, 0xdf20 }, |
| 2399 | { 0x01, 0xff95 }, |
| 2400 | { 0x00, 0xba00 }, |
| 2401 | { 0x04, 0xa800 }, |
| 2402 | { 0x04, 0xf000 }, |
| 2403 | { 0x03, 0xdf01 }, |
| 2404 | { 0x02, 0xdf20 }, |
| 2405 | { 0x01, 0x101a }, |
| 2406 | { 0x00, 0xa0ff }, |
| 2407 | { 0x04, 0xf800 }, |
| 2408 | { 0x04, 0x0000 }, |
| 2409 | { 0x1f, 0x0000 }, |
| 2410 | |
| 2411 | { 0x1f, 0x0001 }, |
| 2412 | { 0x0b, 0x8480 }, |
| 2413 | { 0x1f, 0x0000 }, |
| 2414 | |
| 2415 | { 0x1f, 0x0001 }, |
| 2416 | { 0x18, 0x67c7 }, |
| 2417 | { 0x04, 0x2000 }, |
| 2418 | { 0x03, 0x002f }, |
| 2419 | { 0x02, 0x4360 }, |
| 2420 | { 0x01, 0x0109 }, |
| 2421 | { 0x00, 0x3022 }, |
| 2422 | { 0x04, 0x2800 }, |
| 2423 | { 0x1f, 0x0000 }, |
| 2424 | |
| 2425 | { 0x1f, 0x0001 }, |
| 2426 | { 0x17, 0x0cc0 }, |
| 2427 | { 0x1f, 0x0000 } |
| 2428 | }; |
| 2429 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2430 | 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] | 2431 | } |
| 2432 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2433 | static void rtl8168bb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2434 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2435 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2436 | { 0x10, 0xf41b }, |
| 2437 | { 0x1f, 0x0000 } |
| 2438 | }; |
| 2439 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2440 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2441 | rtl_patchphy(tp, 0x16, 1 << 0); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2442 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2443 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2444 | } |
| 2445 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2446 | static void rtl8168bef_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2447 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2448 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2449 | { 0x1f, 0x0001 }, |
| 2450 | { 0x10, 0xf41b }, |
| 2451 | { 0x1f, 0x0000 } |
| 2452 | }; |
| 2453 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2454 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2455 | } |
| 2456 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2457 | static void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2458 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2459 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2460 | { 0x1f, 0x0000 }, |
| 2461 | { 0x1d, 0x0f00 }, |
| 2462 | { 0x1f, 0x0002 }, |
| 2463 | { 0x0c, 0x1ec8 }, |
| 2464 | { 0x1f, 0x0000 } |
| 2465 | }; |
| 2466 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2467 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2468 | } |
| 2469 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2470 | static void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2471 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2472 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2473 | { 0x1f, 0x0001 }, |
| 2474 | { 0x1d, 0x3d98 }, |
| 2475 | { 0x1f, 0x0000 } |
| 2476 | }; |
| 2477 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2478 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2479 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2480 | rtl_patchphy(tp, 0x0d, 1 << 5); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2481 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2482 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2483 | } |
| 2484 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2485 | static void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2486 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2487 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a3f8067 | 2007-10-18 14:35:11 +0200 | [diff] [blame] | 2488 | { 0x1f, 0x0001 }, |
| 2489 | { 0x12, 0x2300 }, |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2490 | { 0x1f, 0x0002 }, |
| 2491 | { 0x00, 0x88d4 }, |
| 2492 | { 0x01, 0x82b1 }, |
| 2493 | { 0x03, 0x7002 }, |
| 2494 | { 0x08, 0x9e30 }, |
| 2495 | { 0x09, 0x01f0 }, |
| 2496 | { 0x0a, 0x5500 }, |
| 2497 | { 0x0c, 0x00c8 }, |
| 2498 | { 0x1f, 0x0003 }, |
| 2499 | { 0x12, 0xc096 }, |
| 2500 | { 0x16, 0x000a }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2501 | { 0x1f, 0x0000 }, |
| 2502 | { 0x1f, 0x0000 }, |
| 2503 | { 0x09, 0x2000 }, |
| 2504 | { 0x09, 0x0000 } |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2505 | }; |
| 2506 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2507 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2508 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2509 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2510 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2511 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2512 | } |
| 2513 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2514 | static void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2515 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2516 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2517 | { 0x1f, 0x0001 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2518 | { 0x12, 0x2300 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2519 | { 0x03, 0x802f }, |
| 2520 | { 0x02, 0x4f02 }, |
| 2521 | { 0x01, 0x0409 }, |
| 2522 | { 0x00, 0xf099 }, |
| 2523 | { 0x04, 0x9800 }, |
| 2524 | { 0x04, 0x9000 }, |
| 2525 | { 0x1d, 0x3d98 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2526 | { 0x1f, 0x0002 }, |
| 2527 | { 0x0c, 0x7eb8 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2528 | { 0x06, 0x0761 }, |
| 2529 | { 0x1f, 0x0003 }, |
| 2530 | { 0x16, 0x0f0a }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2531 | { 0x1f, 0x0000 } |
| 2532 | }; |
| 2533 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2534 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2535 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2536 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 2537 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2538 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2539 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2540 | } |
| 2541 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2542 | static void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2543 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2544 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2545 | { 0x1f, 0x0001 }, |
| 2546 | { 0x12, 0x2300 }, |
| 2547 | { 0x1d, 0x3d98 }, |
| 2548 | { 0x1f, 0x0002 }, |
| 2549 | { 0x0c, 0x7eb8 }, |
| 2550 | { 0x06, 0x5461 }, |
| 2551 | { 0x1f, 0x0003 }, |
| 2552 | { 0x16, 0x0f0a }, |
| 2553 | { 0x1f, 0x0000 } |
| 2554 | }; |
| 2555 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2556 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2557 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2558 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 2559 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2560 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2561 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2562 | } |
| 2563 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2564 | static void rtl8168c_4_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2565 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2566 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2567 | } |
| 2568 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2569 | static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2570 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2571 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2572 | /* Channel Estimation */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2573 | { 0x1f, 0x0001 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2574 | { 0x06, 0x4064 }, |
| 2575 | { 0x07, 0x2863 }, |
| 2576 | { 0x08, 0x059c }, |
| 2577 | { 0x09, 0x26b4 }, |
| 2578 | { 0x0a, 0x6a19 }, |
| 2579 | { 0x0b, 0xdcc8 }, |
| 2580 | { 0x10, 0xf06d }, |
| 2581 | { 0x14, 0x7f68 }, |
| 2582 | { 0x18, 0x7fd9 }, |
| 2583 | { 0x1c, 0xf0ff }, |
| 2584 | { 0x1d, 0x3d9c }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2585 | { 0x1f, 0x0003 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2586 | { 0x12, 0xf49f }, |
| 2587 | { 0x13, 0x070b }, |
| 2588 | { 0x1a, 0x05ad }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2589 | { 0x14, 0x94c0 }, |
| 2590 | |
| 2591 | /* |
| 2592 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2593 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2594 | */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2595 | { 0x1f, 0x0002 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2596 | { 0x06, 0x5561 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2597 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2598 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2599 | { 0x06, 0x5561 }, |
| 2600 | |
| 2601 | /* |
| 2602 | * Can not link to 1Gbps with bad cable |
| 2603 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 2604 | */ |
| 2605 | { 0x1f, 0x0001 }, |
| 2606 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2607 | |
| 2608 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2609 | { 0x0d, 0xf880 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2610 | }; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2611 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2612 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2613 | 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] | 2614 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2615 | /* |
| 2616 | * Rx Error Issue |
| 2617 | * Fine Tune Switching regulator parameter |
| 2618 | */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2619 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2620 | rtl_w1w0_phy(tp, 0x0b, 0x0010, 0x00ef); |
| 2621 | rtl_w1w0_phy(tp, 0x0c, 0xa200, 0x5d00); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2622 | |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2623 | if (rtl8168d_efuse_read(ioaddr, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2624 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2625 | { 0x1f, 0x0002 }, |
| 2626 | { 0x05, 0x669a }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2627 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2628 | { 0x05, 0x8330 }, |
| 2629 | { 0x06, 0x669a }, |
| 2630 | { 0x1f, 0x0002 } |
| 2631 | }; |
| 2632 | int val; |
| 2633 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2634 | 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] | 2635 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2636 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2637 | |
| 2638 | if ((val & 0x00ff) != 0x006c) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2639 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2640 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 2641 | 0x0069, 0x006a, 0x006b, 0x006c |
| 2642 | }; |
| 2643 | int i; |
| 2644 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2645 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2646 | |
| 2647 | val &= 0xff00; |
| 2648 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2649 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2650 | } |
| 2651 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2652 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2653 | { 0x1f, 0x0002 }, |
| 2654 | { 0x05, 0x6662 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2655 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2656 | { 0x05, 0x8330 }, |
| 2657 | { 0x06, 0x6662 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2658 | }; |
| 2659 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2660 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2661 | } |
| 2662 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2663 | /* RSET couple improve */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2664 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2665 | rtl_patchphy(tp, 0x0d, 0x0300); |
| 2666 | rtl_patchphy(tp, 0x0f, 0x0010); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2667 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2668 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2669 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2670 | rtl_w1w0_phy(tp, 0x02, 0x0100, 0x0600); |
| 2671 | rtl_w1w0_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2672 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2673 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2674 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2675 | |
| 2676 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2677 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2678 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2679 | } |
| 2680 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2681 | static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2682 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2683 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2684 | /* Channel Estimation */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2685 | { 0x1f, 0x0001 }, |
| 2686 | { 0x06, 0x4064 }, |
| 2687 | { 0x07, 0x2863 }, |
| 2688 | { 0x08, 0x059c }, |
| 2689 | { 0x09, 0x26b4 }, |
| 2690 | { 0x0a, 0x6a19 }, |
| 2691 | { 0x0b, 0xdcc8 }, |
| 2692 | { 0x10, 0xf06d }, |
| 2693 | { 0x14, 0x7f68 }, |
| 2694 | { 0x18, 0x7fd9 }, |
| 2695 | { 0x1c, 0xf0ff }, |
| 2696 | { 0x1d, 0x3d9c }, |
| 2697 | { 0x1f, 0x0003 }, |
| 2698 | { 0x12, 0xf49f }, |
| 2699 | { 0x13, 0x070b }, |
| 2700 | { 0x1a, 0x05ad }, |
| 2701 | { 0x14, 0x94c0 }, |
| 2702 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2703 | /* |
| 2704 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2705 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2706 | */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2707 | { 0x1f, 0x0002 }, |
| 2708 | { 0x06, 0x5561 }, |
| 2709 | { 0x1f, 0x0005 }, |
| 2710 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2711 | { 0x06, 0x5561 }, |
| 2712 | |
| 2713 | /* |
| 2714 | * Can not link to 1Gbps with bad cable |
| 2715 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 2716 | */ |
| 2717 | { 0x1f, 0x0001 }, |
| 2718 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2719 | |
| 2720 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2721 | { 0x0d, 0xf880 } |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2722 | }; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2723 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2724 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2725 | 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] | 2726 | |
| 2727 | if (rtl8168d_efuse_read(ioaddr, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2728 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2729 | { 0x1f, 0x0002 }, |
| 2730 | { 0x05, 0x669a }, |
| 2731 | { 0x1f, 0x0005 }, |
| 2732 | { 0x05, 0x8330 }, |
| 2733 | { 0x06, 0x669a }, |
| 2734 | |
| 2735 | { 0x1f, 0x0002 } |
| 2736 | }; |
| 2737 | int val; |
| 2738 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2739 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2740 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2741 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2742 | if ((val & 0x00ff) != 0x006c) { |
Joe Perches | b6bc765 | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 2743 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2744 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 2745 | 0x0069, 0x006a, 0x006b, 0x006c |
| 2746 | }; |
| 2747 | int i; |
| 2748 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2749 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2750 | |
| 2751 | val &= 0xff00; |
| 2752 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2753 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2754 | } |
| 2755 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2756 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2757 | { 0x1f, 0x0002 }, |
| 2758 | { 0x05, 0x2642 }, |
| 2759 | { 0x1f, 0x0005 }, |
| 2760 | { 0x05, 0x8330 }, |
| 2761 | { 0x06, 0x2642 } |
| 2762 | }; |
| 2763 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2764 | 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] | 2765 | } |
| 2766 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2767 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2768 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2769 | rtl_w1w0_phy(tp, 0x02, 0x0100, 0x0600); |
| 2770 | rtl_w1w0_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2771 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2772 | /* Switching regulator Slew rate */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2773 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2774 | rtl_patchphy(tp, 0x0f, 0x0017); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2775 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2776 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2777 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2778 | |
| 2779 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2780 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2781 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2782 | } |
| 2783 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2784 | static void rtl8168d_3_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2785 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2786 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2787 | { 0x1f, 0x0002 }, |
| 2788 | { 0x10, 0x0008 }, |
| 2789 | { 0x0d, 0x006c }, |
| 2790 | |
| 2791 | { 0x1f, 0x0000 }, |
| 2792 | { 0x0d, 0xf880 }, |
| 2793 | |
| 2794 | { 0x1f, 0x0001 }, |
| 2795 | { 0x17, 0x0cc0 }, |
| 2796 | |
| 2797 | { 0x1f, 0x0001 }, |
| 2798 | { 0x0b, 0xa4d8 }, |
| 2799 | { 0x09, 0x281c }, |
| 2800 | { 0x07, 0x2883 }, |
| 2801 | { 0x0a, 0x6b35 }, |
| 2802 | { 0x1d, 0x3da4 }, |
| 2803 | { 0x1c, 0xeffd }, |
| 2804 | { 0x14, 0x7f52 }, |
| 2805 | { 0x18, 0x7fc6 }, |
| 2806 | { 0x08, 0x0601 }, |
| 2807 | { 0x06, 0x4063 }, |
| 2808 | { 0x10, 0xf074 }, |
| 2809 | { 0x1f, 0x0003 }, |
| 2810 | { 0x13, 0x0789 }, |
| 2811 | { 0x12, 0xf4bd }, |
| 2812 | { 0x1a, 0x04fd }, |
| 2813 | { 0x14, 0x84b0 }, |
| 2814 | { 0x1f, 0x0000 }, |
| 2815 | { 0x00, 0x9200 }, |
| 2816 | |
| 2817 | { 0x1f, 0x0005 }, |
| 2818 | { 0x01, 0x0340 }, |
| 2819 | { 0x1f, 0x0001 }, |
| 2820 | { 0x04, 0x4000 }, |
| 2821 | { 0x03, 0x1d21 }, |
| 2822 | { 0x02, 0x0c32 }, |
| 2823 | { 0x01, 0x0200 }, |
| 2824 | { 0x00, 0x5554 }, |
| 2825 | { 0x04, 0x4800 }, |
| 2826 | { 0x04, 0x4000 }, |
| 2827 | { 0x04, 0xf000 }, |
| 2828 | { 0x03, 0xdf01 }, |
| 2829 | { 0x02, 0xdf20 }, |
| 2830 | { 0x01, 0x101a }, |
| 2831 | { 0x00, 0xa0ff }, |
| 2832 | { 0x04, 0xf800 }, |
| 2833 | { 0x04, 0xf000 }, |
| 2834 | { 0x1f, 0x0000 }, |
| 2835 | |
| 2836 | { 0x1f, 0x0007 }, |
| 2837 | { 0x1e, 0x0023 }, |
| 2838 | { 0x16, 0x0000 }, |
| 2839 | { 0x1f, 0x0000 } |
| 2840 | }; |
| 2841 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2842 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2843 | } |
| 2844 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2845 | static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp) |
| 2846 | { |
| 2847 | static const struct phy_reg phy_reg_init[] = { |
| 2848 | { 0x1f, 0x0001 }, |
| 2849 | { 0x17, 0x0cc0 }, |
| 2850 | |
| 2851 | { 0x1f, 0x0007 }, |
| 2852 | { 0x1e, 0x002d }, |
| 2853 | { 0x18, 0x0040 }, |
| 2854 | { 0x1f, 0x0000 } |
| 2855 | }; |
| 2856 | |
| 2857 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 2858 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2859 | } |
| 2860 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2861 | static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2862 | { |
| 2863 | static const struct phy_reg phy_reg_init[] = { |
| 2864 | /* Enable Delay cap */ |
| 2865 | { 0x1f, 0x0005 }, |
| 2866 | { 0x05, 0x8b80 }, |
| 2867 | { 0x06, 0xc896 }, |
| 2868 | { 0x1f, 0x0000 }, |
| 2869 | |
| 2870 | /* Channel estimation fine tune */ |
| 2871 | { 0x1f, 0x0001 }, |
| 2872 | { 0x0b, 0x6c20 }, |
| 2873 | { 0x07, 0x2872 }, |
| 2874 | { 0x1c, 0xefff }, |
| 2875 | { 0x1f, 0x0003 }, |
| 2876 | { 0x14, 0x6420 }, |
| 2877 | { 0x1f, 0x0000 }, |
| 2878 | |
| 2879 | /* Update PFM & 10M TX idle timer */ |
| 2880 | { 0x1f, 0x0007 }, |
| 2881 | { 0x1e, 0x002f }, |
| 2882 | { 0x15, 0x1919 }, |
| 2883 | { 0x1f, 0x0000 }, |
| 2884 | |
| 2885 | { 0x1f, 0x0007 }, |
| 2886 | { 0x1e, 0x00ac }, |
| 2887 | { 0x18, 0x0006 }, |
| 2888 | { 0x1f, 0x0000 } |
| 2889 | }; |
| 2890 | |
Francois Romieu | 15ecd03 | 2011-04-27 13:52:22 -0700 | [diff] [blame] | 2891 | rtl_apply_firmware(tp); |
| 2892 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2893 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 2894 | |
| 2895 | /* DCO enable for 10M IDLE Power */ |
| 2896 | rtl_writephy(tp, 0x1f, 0x0007); |
| 2897 | rtl_writephy(tp, 0x1e, 0x0023); |
| 2898 | rtl_w1w0_phy(tp, 0x17, 0x0006, 0x0000); |
| 2899 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2900 | |
| 2901 | /* For impedance matching */ |
| 2902 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2903 | rtl_w1w0_phy(tp, 0x08, 0x8000, 0x7f00); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2904 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2905 | |
| 2906 | /* PHY auto speed down */ |
| 2907 | rtl_writephy(tp, 0x1f, 0x0007); |
| 2908 | rtl_writephy(tp, 0x1e, 0x002d); |
| 2909 | rtl_w1w0_phy(tp, 0x18, 0x0050, 0x0000); |
| 2910 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2911 | rtl_w1w0_phy(tp, 0x14, 0x8000, 0x0000); |
| 2912 | |
| 2913 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2914 | rtl_writephy(tp, 0x05, 0x8b86); |
| 2915 | rtl_w1w0_phy(tp, 0x06, 0x0001, 0x0000); |
| 2916 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2917 | |
| 2918 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2919 | rtl_writephy(tp, 0x05, 0x8b85); |
| 2920 | rtl_w1w0_phy(tp, 0x06, 0x0000, 0x2000); |
| 2921 | rtl_writephy(tp, 0x1f, 0x0007); |
| 2922 | rtl_writephy(tp, 0x1e, 0x0020); |
| 2923 | rtl_w1w0_phy(tp, 0x15, 0x0000, 0x1100); |
| 2924 | rtl_writephy(tp, 0x1f, 0x0006); |
| 2925 | rtl_writephy(tp, 0x00, 0x5a00); |
| 2926 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2927 | rtl_writephy(tp, 0x0d, 0x0007); |
| 2928 | rtl_writephy(tp, 0x0e, 0x003c); |
| 2929 | rtl_writephy(tp, 0x0d, 0x4007); |
| 2930 | rtl_writephy(tp, 0x0e, 0x0000); |
| 2931 | rtl_writephy(tp, 0x0d, 0x0000); |
| 2932 | } |
| 2933 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2934 | static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp) |
| 2935 | { |
| 2936 | static const struct phy_reg phy_reg_init[] = { |
| 2937 | /* Enable Delay cap */ |
| 2938 | { 0x1f, 0x0004 }, |
| 2939 | { 0x1f, 0x0007 }, |
| 2940 | { 0x1e, 0x00ac }, |
| 2941 | { 0x18, 0x0006 }, |
| 2942 | { 0x1f, 0x0002 }, |
| 2943 | { 0x1f, 0x0000 }, |
| 2944 | { 0x1f, 0x0000 }, |
| 2945 | |
| 2946 | /* Channel estimation fine tune */ |
| 2947 | { 0x1f, 0x0003 }, |
| 2948 | { 0x09, 0xa20f }, |
| 2949 | { 0x1f, 0x0000 }, |
| 2950 | { 0x1f, 0x0000 }, |
| 2951 | |
| 2952 | /* Green Setting */ |
| 2953 | { 0x1f, 0x0005 }, |
| 2954 | { 0x05, 0x8b5b }, |
| 2955 | { 0x06, 0x9222 }, |
| 2956 | { 0x05, 0x8b6d }, |
| 2957 | { 0x06, 0x8000 }, |
| 2958 | { 0x05, 0x8b76 }, |
| 2959 | { 0x06, 0x8000 }, |
| 2960 | { 0x1f, 0x0000 } |
| 2961 | }; |
| 2962 | |
| 2963 | rtl_apply_firmware(tp); |
| 2964 | |
| 2965 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 2966 | |
| 2967 | /* For 4-corner performance improve */ |
| 2968 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2969 | rtl_writephy(tp, 0x05, 0x8b80); |
| 2970 | rtl_w1w0_phy(tp, 0x17, 0x0006, 0x0000); |
| 2971 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2972 | |
| 2973 | /* PHY auto speed down */ |
| 2974 | rtl_writephy(tp, 0x1f, 0x0004); |
| 2975 | rtl_writephy(tp, 0x1f, 0x0007); |
| 2976 | rtl_writephy(tp, 0x1e, 0x002d); |
| 2977 | rtl_w1w0_phy(tp, 0x18, 0x0010, 0x0000); |
| 2978 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2979 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2980 | rtl_w1w0_phy(tp, 0x14, 0x8000, 0x0000); |
| 2981 | |
| 2982 | /* improve 10M EEE waveform */ |
| 2983 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2984 | rtl_writephy(tp, 0x05, 0x8b86); |
| 2985 | rtl_w1w0_phy(tp, 0x06, 0x0001, 0x0000); |
| 2986 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2987 | |
| 2988 | /* Improve 2-pair detection performance */ |
| 2989 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2990 | rtl_writephy(tp, 0x05, 0x8b85); |
| 2991 | rtl_w1w0_phy(tp, 0x06, 0x4000, 0x0000); |
| 2992 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2993 | |
| 2994 | /* EEE setting */ |
| 2995 | rtl_w1w0_eri(tp->mmio_addr, 0x1b0, ERIAR_MASK_1111, 0x0000, 0x0003, |
| 2996 | ERIAR_EXGMAC); |
| 2997 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2998 | rtl_writephy(tp, 0x05, 0x8b85); |
| 2999 | rtl_w1w0_phy(tp, 0x06, 0x0000, 0x2000); |
| 3000 | rtl_writephy(tp, 0x1f, 0x0004); |
| 3001 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3002 | rtl_writephy(tp, 0x1e, 0x0020); |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 3003 | rtl_w1w0_phy(tp, 0x15, 0x0000, 0x0100); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3004 | rtl_writephy(tp, 0x1f, 0x0002); |
| 3005 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3006 | rtl_writephy(tp, 0x0d, 0x0007); |
| 3007 | rtl_writephy(tp, 0x0e, 0x003c); |
| 3008 | rtl_writephy(tp, 0x0d, 0x4007); |
| 3009 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3010 | rtl_writephy(tp, 0x0d, 0x0000); |
| 3011 | |
| 3012 | /* Green feature */ |
| 3013 | rtl_writephy(tp, 0x1f, 0x0003); |
| 3014 | rtl_w1w0_phy(tp, 0x19, 0x0000, 0x0001); |
| 3015 | rtl_w1w0_phy(tp, 0x10, 0x0000, 0x0400); |
| 3016 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3017 | } |
| 3018 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3019 | static void rtl8168f_1_hw_phy_config(struct rtl8169_private *tp) |
| 3020 | { |
| 3021 | static const struct phy_reg phy_reg_init[] = { |
| 3022 | /* Channel estimation fine tune */ |
| 3023 | { 0x1f, 0x0003 }, |
| 3024 | { 0x09, 0xa20f }, |
| 3025 | { 0x1f, 0x0000 }, |
| 3026 | |
| 3027 | /* Modify green table for giga & fnet */ |
| 3028 | { 0x1f, 0x0005 }, |
| 3029 | { 0x05, 0x8b55 }, |
| 3030 | { 0x06, 0x0000 }, |
| 3031 | { 0x05, 0x8b5e }, |
| 3032 | { 0x06, 0x0000 }, |
| 3033 | { 0x05, 0x8b67 }, |
| 3034 | { 0x06, 0x0000 }, |
| 3035 | { 0x05, 0x8b70 }, |
| 3036 | { 0x06, 0x0000 }, |
| 3037 | { 0x1f, 0x0000 }, |
| 3038 | { 0x1f, 0x0007 }, |
| 3039 | { 0x1e, 0x0078 }, |
| 3040 | { 0x17, 0x0000 }, |
| 3041 | { 0x19, 0x00fb }, |
| 3042 | { 0x1f, 0x0000 }, |
| 3043 | |
| 3044 | /* Modify green table for 10M */ |
| 3045 | { 0x1f, 0x0005 }, |
| 3046 | { 0x05, 0x8b79 }, |
| 3047 | { 0x06, 0xaa00 }, |
| 3048 | { 0x1f, 0x0000 }, |
| 3049 | |
| 3050 | /* Disable hiimpedance detection (RTCT) */ |
| 3051 | { 0x1f, 0x0003 }, |
| 3052 | { 0x01, 0x328a }, |
| 3053 | { 0x1f, 0x0000 } |
| 3054 | }; |
| 3055 | |
| 3056 | rtl_apply_firmware(tp); |
| 3057 | |
| 3058 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3059 | |
| 3060 | /* For 4-corner performance improve */ |
| 3061 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3062 | rtl_writephy(tp, 0x05, 0x8b80); |
| 3063 | rtl_w1w0_phy(tp, 0x06, 0x0006, 0x0000); |
| 3064 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3065 | |
| 3066 | /* PHY auto speed down */ |
| 3067 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3068 | rtl_writephy(tp, 0x1e, 0x002d); |
| 3069 | rtl_w1w0_phy(tp, 0x18, 0x0010, 0x0000); |
| 3070 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3071 | rtl_w1w0_phy(tp, 0x14, 0x8000, 0x0000); |
| 3072 | |
| 3073 | /* Improve 10M EEE waveform */ |
| 3074 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3075 | rtl_writephy(tp, 0x05, 0x8b86); |
| 3076 | rtl_w1w0_phy(tp, 0x06, 0x0001, 0x0000); |
| 3077 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3078 | |
| 3079 | /* Improve 2-pair detection performance */ |
| 3080 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3081 | rtl_writephy(tp, 0x05, 0x8b85); |
| 3082 | rtl_w1w0_phy(tp, 0x06, 0x4000, 0x0000); |
| 3083 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3084 | } |
| 3085 | |
| 3086 | static void rtl8168f_2_hw_phy_config(struct rtl8169_private *tp) |
| 3087 | { |
| 3088 | rtl_apply_firmware(tp); |
| 3089 | |
| 3090 | /* For 4-corner performance improve */ |
| 3091 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3092 | rtl_writephy(tp, 0x05, 0x8b80); |
| 3093 | rtl_w1w0_phy(tp, 0x06, 0x0006, 0x0000); |
| 3094 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3095 | |
| 3096 | /* PHY auto speed down */ |
| 3097 | rtl_writephy(tp, 0x1f, 0x0007); |
| 3098 | rtl_writephy(tp, 0x1e, 0x002d); |
| 3099 | rtl_w1w0_phy(tp, 0x18, 0x0010, 0x0000); |
| 3100 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3101 | rtl_w1w0_phy(tp, 0x14, 0x8000, 0x0000); |
| 3102 | |
| 3103 | /* Improve 10M EEE waveform */ |
| 3104 | rtl_writephy(tp, 0x1f, 0x0005); |
| 3105 | rtl_writephy(tp, 0x05, 0x8b86); |
| 3106 | rtl_w1w0_phy(tp, 0x06, 0x0001, 0x0000); |
| 3107 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3108 | } |
| 3109 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3110 | static void rtl8102e_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3111 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3112 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3113 | { 0x1f, 0x0003 }, |
| 3114 | { 0x08, 0x441d }, |
| 3115 | { 0x01, 0x9100 }, |
| 3116 | { 0x1f, 0x0000 } |
| 3117 | }; |
| 3118 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3119 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3120 | rtl_patchphy(tp, 0x11, 1 << 12); |
| 3121 | rtl_patchphy(tp, 0x19, 1 << 13); |
| 3122 | rtl_patchphy(tp, 0x10, 1 << 15); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3123 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3124 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3125 | } |
| 3126 | |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3127 | static void rtl8105e_hw_phy_config(struct rtl8169_private *tp) |
| 3128 | { |
| 3129 | static const struct phy_reg phy_reg_init[] = { |
| 3130 | { 0x1f, 0x0005 }, |
| 3131 | { 0x1a, 0x0000 }, |
| 3132 | { 0x1f, 0x0000 }, |
| 3133 | |
| 3134 | { 0x1f, 0x0004 }, |
| 3135 | { 0x1c, 0x0000 }, |
| 3136 | { 0x1f, 0x0000 }, |
| 3137 | |
| 3138 | { 0x1f, 0x0001 }, |
| 3139 | { 0x15, 0x7701 }, |
| 3140 | { 0x1f, 0x0000 } |
| 3141 | }; |
| 3142 | |
| 3143 | /* Disable ALDPS before ram code */ |
| 3144 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3145 | rtl_writephy(tp, 0x18, 0x0310); |
| 3146 | msleep(100); |
| 3147 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3148 | rtl_apply_firmware(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3149 | |
| 3150 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 3151 | } |
| 3152 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3153 | static void rtl_hw_phy_config(struct net_device *dev) |
| 3154 | { |
| 3155 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3156 | |
| 3157 | rtl8169_print_mac_version(tp); |
| 3158 | |
| 3159 | switch (tp->mac_version) { |
| 3160 | case RTL_GIGA_MAC_VER_01: |
| 3161 | break; |
| 3162 | case RTL_GIGA_MAC_VER_02: |
| 3163 | case RTL_GIGA_MAC_VER_03: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3164 | rtl8169s_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3165 | break; |
| 3166 | case RTL_GIGA_MAC_VER_04: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3167 | rtl8169sb_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3168 | break; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3169 | case RTL_GIGA_MAC_VER_05: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3170 | rtl8169scd_hw_phy_config(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 3171 | break; |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 3172 | case RTL_GIGA_MAC_VER_06: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3173 | rtl8169sce_hw_phy_config(tp); |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 3174 | break; |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3175 | case RTL_GIGA_MAC_VER_07: |
| 3176 | case RTL_GIGA_MAC_VER_08: |
| 3177 | case RTL_GIGA_MAC_VER_09: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3178 | rtl8102e_hw_phy_config(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 3179 | break; |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3180 | case RTL_GIGA_MAC_VER_11: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3181 | rtl8168bb_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3182 | break; |
| 3183 | case RTL_GIGA_MAC_VER_12: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3184 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3185 | break; |
| 3186 | case RTL_GIGA_MAC_VER_17: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3187 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 3188 | break; |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3189 | case RTL_GIGA_MAC_VER_18: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3190 | rtl8168cp_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3191 | break; |
| 3192 | case RTL_GIGA_MAC_VER_19: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3193 | rtl8168c_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 3194 | break; |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3195 | case RTL_GIGA_MAC_VER_20: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3196 | rtl8168c_2_hw_phy_config(tp); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 3197 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3198 | case RTL_GIGA_MAC_VER_21: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3199 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3200 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3201 | case RTL_GIGA_MAC_VER_22: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3202 | rtl8168c_4_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3203 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3204 | case RTL_GIGA_MAC_VER_23: |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 3205 | case RTL_GIGA_MAC_VER_24: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3206 | rtl8168cp_2_hw_phy_config(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3207 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3208 | case RTL_GIGA_MAC_VER_25: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3209 | rtl8168d_1_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3210 | break; |
| 3211 | case RTL_GIGA_MAC_VER_26: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 3212 | rtl8168d_2_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 3213 | break; |
| 3214 | case RTL_GIGA_MAC_VER_27: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3215 | rtl8168d_3_hw_phy_config(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 3216 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3217 | case RTL_GIGA_MAC_VER_28: |
| 3218 | rtl8168d_4_hw_phy_config(tp); |
| 3219 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3220 | case RTL_GIGA_MAC_VER_29: |
| 3221 | case RTL_GIGA_MAC_VER_30: |
| 3222 | rtl8105e_hw_phy_config(tp); |
| 3223 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3224 | case RTL_GIGA_MAC_VER_31: |
| 3225 | /* None. */ |
| 3226 | break; |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3227 | case RTL_GIGA_MAC_VER_32: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3228 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3229 | rtl8168e_1_hw_phy_config(tp); |
| 3230 | break; |
| 3231 | case RTL_GIGA_MAC_VER_34: |
| 3232 | rtl8168e_2_hw_phy_config(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3233 | break; |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3234 | case RTL_GIGA_MAC_VER_35: |
| 3235 | rtl8168f_1_hw_phy_config(tp); |
| 3236 | break; |
| 3237 | case RTL_GIGA_MAC_VER_36: |
| 3238 | rtl8168f_2_hw_phy_config(tp); |
| 3239 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3240 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3241 | default: |
| 3242 | break; |
| 3243 | } |
| 3244 | } |
| 3245 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3246 | static void rtl_phy_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3247 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3248 | struct timer_list *timer = &tp->timer; |
| 3249 | void __iomem *ioaddr = tp->mmio_addr; |
| 3250 | unsigned long timeout = RTL8169_PHY_TIMEOUT; |
| 3251 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 3252 | assert(tp->mac_version > RTL_GIGA_MAC_VER_01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3253 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3254 | if (tp->phy_reset_pending(tp)) { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 3255 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3256 | * A busy loop could burn quite a few cycles on nowadays CPU. |
| 3257 | * Let's delay the execution of the timer for a few ticks. |
| 3258 | */ |
| 3259 | timeout = HZ/10; |
| 3260 | goto out_mod_timer; |
| 3261 | } |
| 3262 | |
| 3263 | if (tp->link_ok(ioaddr)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3264 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3266 | netif_warn(tp, link, tp->dev, "PHY reset until link up\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3267 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3268 | tp->phy_reset_enable(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3269 | |
| 3270 | out_mod_timer: |
| 3271 | mod_timer(timer, jiffies + timeout); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3272 | } |
| 3273 | |
| 3274 | static void rtl_schedule_task(struct rtl8169_private *tp, enum rtl_flag flag) |
| 3275 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3276 | if (!test_and_set_bit(flag, tp->wk.flags)) |
| 3277 | schedule_work(&tp->wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3278 | } |
| 3279 | |
| 3280 | static void rtl8169_phy_timer(unsigned long __opaque) |
| 3281 | { |
| 3282 | struct net_device *dev = (struct net_device *)__opaque; |
| 3283 | struct rtl8169_private *tp = netdev_priv(dev); |
| 3284 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 3285 | rtl_schedule_task(tp, RTL_FLAG_TASK_PHY_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3286 | } |
| 3287 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | #ifdef CONFIG_NET_POLL_CONTROLLER |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3289 | static void rtl8169_netpoll(struct net_device *dev) |
| 3290 | { |
| 3291 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3292 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3293 | rtl8169_interrupt(tp->pci_dev->irq, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3294 | } |
| 3295 | #endif |
| 3296 | |
| 3297 | static void rtl8169_release_board(struct pci_dev *pdev, struct net_device *dev, |
| 3298 | void __iomem *ioaddr) |
| 3299 | { |
| 3300 | iounmap(ioaddr); |
| 3301 | pci_release_regions(pdev); |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3302 | pci_clear_mwi(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3303 | pci_disable_device(pdev); |
| 3304 | free_netdev(dev); |
| 3305 | } |
| 3306 | |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 3307 | static void rtl8169_phy_reset(struct net_device *dev, |
| 3308 | struct rtl8169_private *tp) |
| 3309 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 3310 | unsigned int i; |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 3311 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3312 | tp->phy_reset_enable(tp); |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 3313 | for (i = 0; i < 100; i++) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3314 | if (!tp->phy_reset_pending(tp)) |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 3315 | return; |
| 3316 | msleep(1); |
| 3317 | } |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3318 | netif_err(tp, link, dev, "PHY reset failed\n"); |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 3319 | } |
| 3320 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 3321 | static bool rtl_tbi_enabled(struct rtl8169_private *tp) |
| 3322 | { |
| 3323 | void __iomem *ioaddr = tp->mmio_addr; |
| 3324 | |
| 3325 | return (tp->mac_version == RTL_GIGA_MAC_VER_01) && |
| 3326 | (RTL_R8(PHYstatus) & TBI_Enable); |
| 3327 | } |
| 3328 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3329 | 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] | 3330 | { |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3331 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3332 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3333 | rtl_hw_phy_config(dev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3334 | |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 3335 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
| 3336 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
| 3337 | RTL_W8(0x82, 0x01); |
| 3338 | } |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3339 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 3340 | pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); |
| 3341 | |
| 3342 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
| 3343 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3344 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 3345 | if (tp->mac_version == RTL_GIGA_MAC_VER_02) { |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3346 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
| 3347 | RTL_W8(0x82, 0x01); |
| 3348 | dprintk("Set PHY Reg 0x0bh = 0x00h\n"); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3349 | rtl_writephy(tp, 0x0b, 0x0000); //w 0x0b 15 0 0 |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3350 | } |
| 3351 | |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 3352 | rtl8169_phy_reset(dev, tp); |
| 3353 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 3354 | rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3355 | ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 3356 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 3357 | (tp->mii.supports_gmii ? |
| 3358 | ADVERTISED_1000baseT_Half | |
| 3359 | ADVERTISED_1000baseT_Full : 0)); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3360 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 3361 | if (rtl_tbi_enabled(tp)) |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3362 | netif_info(tp, link, dev, "TBI auto-negotiating\n"); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3363 | } |
| 3364 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3365 | static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr) |
| 3366 | { |
| 3367 | void __iomem *ioaddr = tp->mmio_addr; |
| 3368 | u32 high; |
| 3369 | u32 low; |
| 3370 | |
| 3371 | low = addr[0] | (addr[1] << 8) | (addr[2] << 16) | (addr[3] << 24); |
| 3372 | high = addr[4] | (addr[5] << 8); |
| 3373 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3374 | rtl_lock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3375 | |
| 3376 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 3377 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3378 | RTL_W32(MAC4, high); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 3379 | RTL_R32(MAC4); |
| 3380 | |
Francois Romieu | 78f1cd0 | 2010-03-27 19:35:46 -0700 | [diff] [blame] | 3381 | RTL_W32(MAC0, low); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 3382 | RTL_R32(MAC0); |
| 3383 | |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 3384 | if (tp->mac_version == RTL_GIGA_MAC_VER_34) { |
| 3385 | const struct exgmac_reg e[] = { |
| 3386 | { .addr = 0xe0, ERIAR_MASK_1111, .val = low }, |
| 3387 | { .addr = 0xe4, ERIAR_MASK_1111, .val = high }, |
| 3388 | { .addr = 0xf0, ERIAR_MASK_1111, .val = low << 16 }, |
| 3389 | { .addr = 0xf4, ERIAR_MASK_1111, .val = high << 16 | |
| 3390 | low >> 16 }, |
| 3391 | }; |
| 3392 | |
| 3393 | rtl_write_exgmac_batch(ioaddr, e, ARRAY_SIZE(e)); |
| 3394 | } |
| 3395 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3396 | RTL_W8(Cfg9346, Cfg9346_Lock); |
| 3397 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3398 | rtl_unlock_work(tp); |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3399 | } |
| 3400 | |
| 3401 | static int rtl_set_mac_address(struct net_device *dev, void *p) |
| 3402 | { |
| 3403 | struct rtl8169_private *tp = netdev_priv(dev); |
| 3404 | struct sockaddr *addr = p; |
| 3405 | |
| 3406 | if (!is_valid_ether_addr(addr->sa_data)) |
| 3407 | return -EADDRNOTAVAIL; |
| 3408 | |
| 3409 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 3410 | |
| 3411 | rtl_rar_set(tp, dev->dev_addr); |
| 3412 | |
| 3413 | return 0; |
| 3414 | } |
| 3415 | |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 3416 | static int rtl8169_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 3417 | { |
| 3418 | struct rtl8169_private *tp = netdev_priv(dev); |
| 3419 | struct mii_ioctl_data *data = if_mii(ifr); |
| 3420 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3421 | return netif_running(dev) ? tp->do_ioctl(tp, data, cmd) : -ENODEV; |
| 3422 | } |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 3423 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3424 | static int rtl_xmii_ioctl(struct rtl8169_private *tp, |
| 3425 | struct mii_ioctl_data *data, int cmd) |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3426 | { |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 3427 | switch (cmd) { |
| 3428 | case SIOCGMIIPHY: |
| 3429 | data->phy_id = 32; /* Internal PHY */ |
| 3430 | return 0; |
| 3431 | |
| 3432 | case SIOCGMIIREG: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3433 | data->val_out = rtl_readphy(tp, data->reg_num & 0x1f); |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 3434 | return 0; |
| 3435 | |
| 3436 | case SIOCSMIIREG: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3437 | rtl_writephy(tp, data->reg_num & 0x1f, data->val_in); |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 3438 | return 0; |
| 3439 | } |
| 3440 | return -EOPNOTSUPP; |
| 3441 | } |
| 3442 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3443 | static int rtl_tbi_ioctl(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd) |
| 3444 | { |
| 3445 | return -EOPNOTSUPP; |
| 3446 | } |
| 3447 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 3448 | static const struct rtl_cfg_info { |
| 3449 | void (*hw_start)(struct net_device *); |
| 3450 | unsigned int region; |
| 3451 | unsigned int align; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3452 | u16 event_slow; |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 3453 | unsigned features; |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 3454 | u8 default_ver; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 3455 | } rtl_cfg_infos [] = { |
| 3456 | [RTL_CFG_0] = { |
| 3457 | .hw_start = rtl_hw_start_8169, |
| 3458 | .region = 1, |
Francois Romieu | e9f63f3 | 2007-02-28 23:16:57 +0100 | [diff] [blame] | 3459 | .align = 0, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3460 | .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver, |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 3461 | .features = RTL_FEATURE_GMII, |
| 3462 | .default_ver = RTL_GIGA_MAC_VER_01, |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 3463 | }, |
| 3464 | [RTL_CFG_1] = { |
| 3465 | .hw_start = rtl_hw_start_8168, |
| 3466 | .region = 2, |
| 3467 | .align = 8, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3468 | .event_slow = SYSErr | LinkChg | RxOverflow, |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 3469 | .features = RTL_FEATURE_GMII | RTL_FEATURE_MSI, |
| 3470 | .default_ver = RTL_GIGA_MAC_VER_11, |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 3471 | }, |
| 3472 | [RTL_CFG_2] = { |
| 3473 | .hw_start = rtl_hw_start_8101, |
| 3474 | .region = 2, |
| 3475 | .align = 8, |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 3476 | .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver | |
| 3477 | PCSTimeout, |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 3478 | .features = RTL_FEATURE_MSI, |
| 3479 | .default_ver = RTL_GIGA_MAC_VER_13, |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 3480 | } |
| 3481 | }; |
| 3482 | |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 3483 | /* Cfg9346_Unlock assumed. */ |
françois romieu | 2ca6cf0 | 2011-12-15 08:37:43 +0000 | [diff] [blame] | 3484 | static unsigned rtl_try_msi(struct rtl8169_private *tp, |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 3485 | const struct rtl_cfg_info *cfg) |
| 3486 | { |
françois romieu | 2ca6cf0 | 2011-12-15 08:37:43 +0000 | [diff] [blame] | 3487 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 3488 | unsigned msi = 0; |
| 3489 | u8 cfg2; |
| 3490 | |
| 3491 | cfg2 = RTL_R8(Config2) & ~MSIEnable; |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 3492 | if (cfg->features & RTL_FEATURE_MSI) { |
françois romieu | 2ca6cf0 | 2011-12-15 08:37:43 +0000 | [diff] [blame] | 3493 | if (pci_enable_msi(tp->pci_dev)) { |
| 3494 | netif_info(tp, hw, tp->dev, "no MSI. Back to INTx.\n"); |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 3495 | } else { |
| 3496 | cfg2 |= MSIEnable; |
| 3497 | msi = RTL_FEATURE_MSI; |
| 3498 | } |
| 3499 | } |
françois romieu | 2ca6cf0 | 2011-12-15 08:37:43 +0000 | [diff] [blame] | 3500 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
| 3501 | RTL_W8(Config2, cfg2); |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 3502 | return msi; |
| 3503 | } |
| 3504 | |
| 3505 | static void rtl_disable_msi(struct pci_dev *pdev, struct rtl8169_private *tp) |
| 3506 | { |
| 3507 | if (tp->features & RTL_FEATURE_MSI) { |
| 3508 | pci_disable_msi(pdev); |
| 3509 | tp->features &= ~RTL_FEATURE_MSI; |
| 3510 | } |
| 3511 | } |
| 3512 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3513 | static const struct net_device_ops rtl8169_netdev_ops = { |
| 3514 | .ndo_open = rtl8169_open, |
| 3515 | .ndo_stop = rtl8169_close, |
| 3516 | .ndo_get_stats = rtl8169_get_stats, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 3517 | .ndo_start_xmit = rtl8169_start_xmit, |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3518 | .ndo_tx_timeout = rtl8169_tx_timeout, |
| 3519 | .ndo_validate_addr = eth_validate_addr, |
| 3520 | .ndo_change_mtu = rtl8169_change_mtu, |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 3521 | .ndo_fix_features = rtl8169_fix_features, |
| 3522 | .ndo_set_features = rtl8169_set_features, |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3523 | .ndo_set_mac_address = rtl_set_mac_address, |
| 3524 | .ndo_do_ioctl = rtl8169_ioctl, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 3525 | .ndo_set_rx_mode = rtl_set_rx_mode, |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3526 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3527 | .ndo_poll_controller = rtl8169_netpoll, |
| 3528 | #endif |
| 3529 | |
| 3530 | }; |
| 3531 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 3532 | static void __devinit rtl_init_mdio_ops(struct rtl8169_private *tp) |
| 3533 | { |
| 3534 | struct mdio_ops *ops = &tp->mdio_ops; |
| 3535 | |
| 3536 | switch (tp->mac_version) { |
| 3537 | case RTL_GIGA_MAC_VER_27: |
| 3538 | ops->write = r8168dp_1_mdio_write; |
| 3539 | ops->read = r8168dp_1_mdio_read; |
| 3540 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3541 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 3542 | case RTL_GIGA_MAC_VER_31: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3543 | ops->write = r8168dp_2_mdio_write; |
| 3544 | ops->read = r8168dp_2_mdio_read; |
| 3545 | break; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 3546 | default: |
| 3547 | ops->write = r8169_mdio_write; |
| 3548 | ops->read = r8169_mdio_read; |
| 3549 | break; |
| 3550 | } |
| 3551 | } |
| 3552 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 3553 | static void rtl_wol_suspend_quirk(struct rtl8169_private *tp) |
| 3554 | { |
| 3555 | void __iomem *ioaddr = tp->mmio_addr; |
| 3556 | |
| 3557 | switch (tp->mac_version) { |
| 3558 | case RTL_GIGA_MAC_VER_29: |
| 3559 | case RTL_GIGA_MAC_VER_30: |
| 3560 | case RTL_GIGA_MAC_VER_32: |
| 3561 | case RTL_GIGA_MAC_VER_33: |
| 3562 | case RTL_GIGA_MAC_VER_34: |
| 3563 | RTL_W32(RxConfig, RTL_R32(RxConfig) | |
| 3564 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys); |
| 3565 | break; |
| 3566 | default: |
| 3567 | break; |
| 3568 | } |
| 3569 | } |
| 3570 | |
| 3571 | static bool rtl_wol_pll_power_down(struct rtl8169_private *tp) |
| 3572 | { |
| 3573 | if (!(__rtl8169_get_wol(tp) & WAKE_ANY)) |
| 3574 | return false; |
| 3575 | |
| 3576 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3577 | rtl_writephy(tp, MII_BMCR, 0x0000); |
| 3578 | |
| 3579 | rtl_wol_suspend_quirk(tp); |
| 3580 | |
| 3581 | return true; |
| 3582 | } |
| 3583 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3584 | static void r810x_phy_power_down(struct rtl8169_private *tp) |
| 3585 | { |
| 3586 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3587 | rtl_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 3588 | } |
| 3589 | |
| 3590 | static void r810x_phy_power_up(struct rtl8169_private *tp) |
| 3591 | { |
| 3592 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3593 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE); |
| 3594 | } |
| 3595 | |
| 3596 | static void r810x_pll_power_down(struct rtl8169_private *tp) |
| 3597 | { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 3598 | if (rtl_wol_pll_power_down(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3599 | return; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3600 | |
| 3601 | r810x_phy_power_down(tp); |
| 3602 | } |
| 3603 | |
| 3604 | static void r810x_pll_power_up(struct rtl8169_private *tp) |
| 3605 | { |
| 3606 | r810x_phy_power_up(tp); |
| 3607 | } |
| 3608 | |
| 3609 | static void r8168_phy_power_up(struct rtl8169_private *tp) |
| 3610 | { |
| 3611 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3612 | switch (tp->mac_version) { |
| 3613 | case RTL_GIGA_MAC_VER_11: |
| 3614 | case RTL_GIGA_MAC_VER_12: |
| 3615 | case RTL_GIGA_MAC_VER_17: |
| 3616 | case RTL_GIGA_MAC_VER_18: |
| 3617 | case RTL_GIGA_MAC_VER_19: |
| 3618 | case RTL_GIGA_MAC_VER_20: |
| 3619 | case RTL_GIGA_MAC_VER_21: |
| 3620 | case RTL_GIGA_MAC_VER_22: |
| 3621 | case RTL_GIGA_MAC_VER_23: |
| 3622 | case RTL_GIGA_MAC_VER_24: |
| 3623 | case RTL_GIGA_MAC_VER_25: |
| 3624 | case RTL_GIGA_MAC_VER_26: |
| 3625 | case RTL_GIGA_MAC_VER_27: |
| 3626 | case RTL_GIGA_MAC_VER_28: |
| 3627 | case RTL_GIGA_MAC_VER_31: |
| 3628 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3629 | break; |
| 3630 | default: |
| 3631 | break; |
| 3632 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3633 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE); |
| 3634 | } |
| 3635 | |
| 3636 | static void r8168_phy_power_down(struct rtl8169_private *tp) |
| 3637 | { |
| 3638 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3639 | switch (tp->mac_version) { |
| 3640 | case RTL_GIGA_MAC_VER_32: |
| 3641 | case RTL_GIGA_MAC_VER_33: |
| 3642 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE | BMCR_PDOWN); |
| 3643 | break; |
| 3644 | |
| 3645 | case RTL_GIGA_MAC_VER_11: |
| 3646 | case RTL_GIGA_MAC_VER_12: |
| 3647 | case RTL_GIGA_MAC_VER_17: |
| 3648 | case RTL_GIGA_MAC_VER_18: |
| 3649 | case RTL_GIGA_MAC_VER_19: |
| 3650 | case RTL_GIGA_MAC_VER_20: |
| 3651 | case RTL_GIGA_MAC_VER_21: |
| 3652 | case RTL_GIGA_MAC_VER_22: |
| 3653 | case RTL_GIGA_MAC_VER_23: |
| 3654 | case RTL_GIGA_MAC_VER_24: |
| 3655 | case RTL_GIGA_MAC_VER_25: |
| 3656 | case RTL_GIGA_MAC_VER_26: |
| 3657 | case RTL_GIGA_MAC_VER_27: |
| 3658 | case RTL_GIGA_MAC_VER_28: |
| 3659 | case RTL_GIGA_MAC_VER_31: |
| 3660 | rtl_writephy(tp, 0x0e, 0x0200); |
| 3661 | default: |
| 3662 | rtl_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 3663 | break; |
| 3664 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3665 | } |
| 3666 | |
| 3667 | static void r8168_pll_power_down(struct rtl8169_private *tp) |
| 3668 | { |
| 3669 | void __iomem *ioaddr = tp->mmio_addr; |
| 3670 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3671 | if ((tp->mac_version == RTL_GIGA_MAC_VER_27 || |
| 3672 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 3673 | tp->mac_version == RTL_GIGA_MAC_VER_31) && |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 3674 | r8168dp_check_dash(tp)) { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3675 | return; |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 3676 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3677 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3678 | if ((tp->mac_version == RTL_GIGA_MAC_VER_23 || |
| 3679 | tp->mac_version == RTL_GIGA_MAC_VER_24) && |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3680 | (RTL_R16(CPlusCmd) & ASF)) { |
| 3681 | return; |
| 3682 | } |
| 3683 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3684 | if (tp->mac_version == RTL_GIGA_MAC_VER_32 || |
| 3685 | tp->mac_version == RTL_GIGA_MAC_VER_33) |
| 3686 | rtl_ephy_write(ioaddr, 0x19, 0xff64); |
| 3687 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 3688 | if (rtl_wol_pll_power_down(tp)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3689 | return; |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3690 | |
| 3691 | r8168_phy_power_down(tp); |
| 3692 | |
| 3693 | switch (tp->mac_version) { |
| 3694 | case RTL_GIGA_MAC_VER_25: |
| 3695 | case RTL_GIGA_MAC_VER_26: |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 3696 | case RTL_GIGA_MAC_VER_27: |
| 3697 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 3698 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3699 | case RTL_GIGA_MAC_VER_32: |
| 3700 | case RTL_GIGA_MAC_VER_33: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3701 | RTL_W8(PMCH, RTL_R8(PMCH) & ~0x80); |
| 3702 | break; |
| 3703 | } |
| 3704 | } |
| 3705 | |
| 3706 | static void r8168_pll_power_up(struct rtl8169_private *tp) |
| 3707 | { |
| 3708 | void __iomem *ioaddr = tp->mmio_addr; |
| 3709 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3710 | if ((tp->mac_version == RTL_GIGA_MAC_VER_27 || |
| 3711 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 3712 | tp->mac_version == RTL_GIGA_MAC_VER_31) && |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 3713 | r8168dp_check_dash(tp)) { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3714 | return; |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 3715 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3716 | |
| 3717 | switch (tp->mac_version) { |
| 3718 | case RTL_GIGA_MAC_VER_25: |
| 3719 | case RTL_GIGA_MAC_VER_26: |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 3720 | case RTL_GIGA_MAC_VER_27: |
| 3721 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 3722 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3723 | case RTL_GIGA_MAC_VER_32: |
| 3724 | case RTL_GIGA_MAC_VER_33: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3725 | RTL_W8(PMCH, RTL_R8(PMCH) | 0x80); |
| 3726 | break; |
| 3727 | } |
| 3728 | |
| 3729 | r8168_phy_power_up(tp); |
| 3730 | } |
| 3731 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3732 | static void rtl_generic_op(struct rtl8169_private *tp, |
| 3733 | void (*op)(struct rtl8169_private *)) |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3734 | { |
| 3735 | if (op) |
| 3736 | op(tp); |
| 3737 | } |
| 3738 | |
| 3739 | static void rtl_pll_power_down(struct rtl8169_private *tp) |
| 3740 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3741 | rtl_generic_op(tp, tp->pll_power_ops.down); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3742 | } |
| 3743 | |
| 3744 | static void rtl_pll_power_up(struct rtl8169_private *tp) |
| 3745 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3746 | rtl_generic_op(tp, tp->pll_power_ops.up); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3747 | } |
| 3748 | |
| 3749 | static void __devinit rtl_init_pll_power_ops(struct rtl8169_private *tp) |
| 3750 | { |
| 3751 | struct pll_power_ops *ops = &tp->pll_power_ops; |
| 3752 | |
| 3753 | switch (tp->mac_version) { |
| 3754 | case RTL_GIGA_MAC_VER_07: |
| 3755 | case RTL_GIGA_MAC_VER_08: |
| 3756 | case RTL_GIGA_MAC_VER_09: |
| 3757 | case RTL_GIGA_MAC_VER_10: |
| 3758 | case RTL_GIGA_MAC_VER_16: |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3759 | case RTL_GIGA_MAC_VER_29: |
| 3760 | case RTL_GIGA_MAC_VER_30: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3761 | ops->down = r810x_pll_power_down; |
| 3762 | ops->up = r810x_pll_power_up; |
| 3763 | break; |
| 3764 | |
| 3765 | case RTL_GIGA_MAC_VER_11: |
| 3766 | case RTL_GIGA_MAC_VER_12: |
| 3767 | case RTL_GIGA_MAC_VER_17: |
| 3768 | case RTL_GIGA_MAC_VER_18: |
| 3769 | case RTL_GIGA_MAC_VER_19: |
| 3770 | case RTL_GIGA_MAC_VER_20: |
| 3771 | case RTL_GIGA_MAC_VER_21: |
| 3772 | case RTL_GIGA_MAC_VER_22: |
| 3773 | case RTL_GIGA_MAC_VER_23: |
| 3774 | case RTL_GIGA_MAC_VER_24: |
| 3775 | case RTL_GIGA_MAC_VER_25: |
| 3776 | case RTL_GIGA_MAC_VER_26: |
| 3777 | case RTL_GIGA_MAC_VER_27: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3778 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 3779 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3780 | case RTL_GIGA_MAC_VER_32: |
| 3781 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3782 | case RTL_GIGA_MAC_VER_34: |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 3783 | case RTL_GIGA_MAC_VER_35: |
| 3784 | case RTL_GIGA_MAC_VER_36: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3785 | ops->down = r8168_pll_power_down; |
| 3786 | ops->up = r8168_pll_power_up; |
| 3787 | break; |
| 3788 | |
| 3789 | default: |
| 3790 | ops->down = NULL; |
| 3791 | ops->up = NULL; |
| 3792 | break; |
| 3793 | } |
| 3794 | } |
| 3795 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 3796 | static void rtl_init_rxcfg(struct rtl8169_private *tp) |
| 3797 | { |
| 3798 | void __iomem *ioaddr = tp->mmio_addr; |
| 3799 | |
| 3800 | switch (tp->mac_version) { |
| 3801 | case RTL_GIGA_MAC_VER_01: |
| 3802 | case RTL_GIGA_MAC_VER_02: |
| 3803 | case RTL_GIGA_MAC_VER_03: |
| 3804 | case RTL_GIGA_MAC_VER_04: |
| 3805 | case RTL_GIGA_MAC_VER_05: |
| 3806 | case RTL_GIGA_MAC_VER_06: |
| 3807 | case RTL_GIGA_MAC_VER_10: |
| 3808 | case RTL_GIGA_MAC_VER_11: |
| 3809 | case RTL_GIGA_MAC_VER_12: |
| 3810 | case RTL_GIGA_MAC_VER_13: |
| 3811 | case RTL_GIGA_MAC_VER_14: |
| 3812 | case RTL_GIGA_MAC_VER_15: |
| 3813 | case RTL_GIGA_MAC_VER_16: |
| 3814 | case RTL_GIGA_MAC_VER_17: |
| 3815 | RTL_W32(RxConfig, RX_FIFO_THRESH | RX_DMA_BURST); |
| 3816 | break; |
| 3817 | case RTL_GIGA_MAC_VER_18: |
| 3818 | case RTL_GIGA_MAC_VER_19: |
| 3819 | case RTL_GIGA_MAC_VER_20: |
| 3820 | case RTL_GIGA_MAC_VER_21: |
| 3821 | case RTL_GIGA_MAC_VER_22: |
| 3822 | case RTL_GIGA_MAC_VER_23: |
| 3823 | case RTL_GIGA_MAC_VER_24: |
| 3824 | RTL_W32(RxConfig, RX128_INT_EN | RX_MULTI_EN | RX_DMA_BURST); |
| 3825 | break; |
| 3826 | default: |
| 3827 | RTL_W32(RxConfig, RX128_INT_EN | RX_DMA_BURST); |
| 3828 | break; |
| 3829 | } |
| 3830 | } |
| 3831 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 3832 | static void rtl8169_init_ring_indexes(struct rtl8169_private *tp) |
| 3833 | { |
| 3834 | tp->dirty_tx = tp->dirty_rx = tp->cur_tx = tp->cur_rx = 0; |
| 3835 | } |
| 3836 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3837 | static void rtl_hw_jumbo_enable(struct rtl8169_private *tp) |
| 3838 | { |
| 3839 | rtl_generic_op(tp, tp->jumbo_ops.enable); |
| 3840 | } |
| 3841 | |
| 3842 | static void rtl_hw_jumbo_disable(struct rtl8169_private *tp) |
| 3843 | { |
| 3844 | rtl_generic_op(tp, tp->jumbo_ops.disable); |
| 3845 | } |
| 3846 | |
| 3847 | static void r8168c_hw_jumbo_enable(struct rtl8169_private *tp) |
| 3848 | { |
| 3849 | void __iomem *ioaddr = tp->mmio_addr; |
| 3850 | |
| 3851 | RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0); |
| 3852 | RTL_W8(Config4, RTL_R8(Config4) | Jumbo_En1); |
| 3853 | rtl_tx_performance_tweak(tp->pci_dev, 0x2 << MAX_READ_REQUEST_SHIFT); |
| 3854 | } |
| 3855 | |
| 3856 | static void r8168c_hw_jumbo_disable(struct rtl8169_private *tp) |
| 3857 | { |
| 3858 | void __iomem *ioaddr = tp->mmio_addr; |
| 3859 | |
| 3860 | RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0); |
| 3861 | RTL_W8(Config4, RTL_R8(Config4) & ~Jumbo_En1); |
| 3862 | rtl_tx_performance_tweak(tp->pci_dev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 3863 | } |
| 3864 | |
| 3865 | static void r8168dp_hw_jumbo_enable(struct rtl8169_private *tp) |
| 3866 | { |
| 3867 | void __iomem *ioaddr = tp->mmio_addr; |
| 3868 | |
| 3869 | RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0); |
| 3870 | } |
| 3871 | |
| 3872 | static void r8168dp_hw_jumbo_disable(struct rtl8169_private *tp) |
| 3873 | { |
| 3874 | void __iomem *ioaddr = tp->mmio_addr; |
| 3875 | |
| 3876 | RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0); |
| 3877 | } |
| 3878 | |
| 3879 | static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp) |
| 3880 | { |
| 3881 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3882 | |
| 3883 | RTL_W8(MaxTxPacketSize, 0x3f); |
| 3884 | RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0); |
| 3885 | RTL_W8(Config4, RTL_R8(Config4) | 0x01); |
Francois Romieu | 4512ff9 | 2011-12-22 18:59:37 +0100 | [diff] [blame] | 3886 | rtl_tx_performance_tweak(tp->pci_dev, 0x2 << MAX_READ_REQUEST_SHIFT); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3887 | } |
| 3888 | |
| 3889 | static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp) |
| 3890 | { |
| 3891 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3892 | |
| 3893 | RTL_W8(MaxTxPacketSize, 0x0c); |
| 3894 | RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0); |
| 3895 | RTL_W8(Config4, RTL_R8(Config4) & ~0x01); |
Francois Romieu | 4512ff9 | 2011-12-22 18:59:37 +0100 | [diff] [blame] | 3896 | rtl_tx_performance_tweak(tp->pci_dev, 0x5 << MAX_READ_REQUEST_SHIFT); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 3897 | } |
| 3898 | |
| 3899 | static void r8168b_0_hw_jumbo_enable(struct rtl8169_private *tp) |
| 3900 | { |
| 3901 | rtl_tx_performance_tweak(tp->pci_dev, |
| 3902 | (0x2 << MAX_READ_REQUEST_SHIFT) | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 3903 | } |
| 3904 | |
| 3905 | static void r8168b_0_hw_jumbo_disable(struct rtl8169_private *tp) |
| 3906 | { |
| 3907 | rtl_tx_performance_tweak(tp->pci_dev, |
| 3908 | (0x5 << MAX_READ_REQUEST_SHIFT) | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 3909 | } |
| 3910 | |
| 3911 | static void r8168b_1_hw_jumbo_enable(struct rtl8169_private *tp) |
| 3912 | { |
| 3913 | void __iomem *ioaddr = tp->mmio_addr; |
| 3914 | |
| 3915 | r8168b_0_hw_jumbo_enable(tp); |
| 3916 | |
| 3917 | RTL_W8(Config4, RTL_R8(Config4) | (1 << 0)); |
| 3918 | } |
| 3919 | |
| 3920 | static void r8168b_1_hw_jumbo_disable(struct rtl8169_private *tp) |
| 3921 | { |
| 3922 | void __iomem *ioaddr = tp->mmio_addr; |
| 3923 | |
| 3924 | r8168b_0_hw_jumbo_disable(tp); |
| 3925 | |
| 3926 | RTL_W8(Config4, RTL_R8(Config4) & ~(1 << 0)); |
| 3927 | } |
| 3928 | |
| 3929 | static void __devinit rtl_init_jumbo_ops(struct rtl8169_private *tp) |
| 3930 | { |
| 3931 | struct jumbo_ops *ops = &tp->jumbo_ops; |
| 3932 | |
| 3933 | switch (tp->mac_version) { |
| 3934 | case RTL_GIGA_MAC_VER_11: |
| 3935 | ops->disable = r8168b_0_hw_jumbo_disable; |
| 3936 | ops->enable = r8168b_0_hw_jumbo_enable; |
| 3937 | break; |
| 3938 | case RTL_GIGA_MAC_VER_12: |
| 3939 | case RTL_GIGA_MAC_VER_17: |
| 3940 | ops->disable = r8168b_1_hw_jumbo_disable; |
| 3941 | ops->enable = r8168b_1_hw_jumbo_enable; |
| 3942 | break; |
| 3943 | case RTL_GIGA_MAC_VER_18: /* Wild guess. Needs info from Realtek. */ |
| 3944 | case RTL_GIGA_MAC_VER_19: |
| 3945 | case RTL_GIGA_MAC_VER_20: |
| 3946 | case RTL_GIGA_MAC_VER_21: /* Wild guess. Needs info from Realtek. */ |
| 3947 | case RTL_GIGA_MAC_VER_22: |
| 3948 | case RTL_GIGA_MAC_VER_23: |
| 3949 | case RTL_GIGA_MAC_VER_24: |
| 3950 | case RTL_GIGA_MAC_VER_25: |
| 3951 | case RTL_GIGA_MAC_VER_26: |
| 3952 | ops->disable = r8168c_hw_jumbo_disable; |
| 3953 | ops->enable = r8168c_hw_jumbo_enable; |
| 3954 | break; |
| 3955 | case RTL_GIGA_MAC_VER_27: |
| 3956 | case RTL_GIGA_MAC_VER_28: |
| 3957 | ops->disable = r8168dp_hw_jumbo_disable; |
| 3958 | ops->enable = r8168dp_hw_jumbo_enable; |
| 3959 | break; |
| 3960 | case RTL_GIGA_MAC_VER_31: /* Wild guess. Needs info from Realtek. */ |
| 3961 | case RTL_GIGA_MAC_VER_32: |
| 3962 | case RTL_GIGA_MAC_VER_33: |
| 3963 | case RTL_GIGA_MAC_VER_34: |
| 3964 | ops->disable = r8168e_hw_jumbo_disable; |
| 3965 | ops->enable = r8168e_hw_jumbo_enable; |
| 3966 | break; |
| 3967 | |
| 3968 | /* |
| 3969 | * No action needed for jumbo frames with 8169. |
| 3970 | * No jumbo for 810x at all. |
| 3971 | */ |
| 3972 | default: |
| 3973 | ops->disable = NULL; |
| 3974 | ops->enable = NULL; |
| 3975 | break; |
| 3976 | } |
| 3977 | } |
| 3978 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 3979 | static void rtl_hw_reset(struct rtl8169_private *tp) |
| 3980 | { |
| 3981 | void __iomem *ioaddr = tp->mmio_addr; |
| 3982 | int i; |
| 3983 | |
| 3984 | /* Soft reset the chip. */ |
| 3985 | RTL_W8(ChipCmd, CmdReset); |
| 3986 | |
| 3987 | /* Check that the chip has finished the reset. */ |
| 3988 | for (i = 0; i < 100; i++) { |
| 3989 | if ((RTL_R8(ChipCmd) & CmdReset) == 0) |
| 3990 | break; |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 3991 | udelay(100); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 3992 | } |
| 3993 | } |
| 3994 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3995 | static int __devinit |
| 3996 | rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 3997 | { |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 3998 | const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data; |
| 3999 | const unsigned int region = cfg->region; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4000 | struct rtl8169_private *tp; |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 4001 | struct mii_if_info *mii; |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4002 | struct net_device *dev; |
| 4003 | void __iomem *ioaddr; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 4004 | int chipset, i; |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 4005 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4006 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4007 | if (netif_msg_drv(&debug)) { |
| 4008 | printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n", |
| 4009 | MODULENAME, RTL8169_VERSION); |
| 4010 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4011 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4012 | dev = alloc_etherdev(sizeof (*tp)); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4013 | if (!dev) { |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 4014 | if (netif_msg_drv(&debug)) |
Jeff Garzik | 9b91cf9 | 2006-06-27 11:39:50 -0400 | [diff] [blame] | 4015 | dev_err(&pdev->dev, "unable to alloc new ethernet\n"); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4016 | rc = -ENOMEM; |
| 4017 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4018 | } |
| 4019 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4020 | SET_NETDEV_DEV(dev, &pdev->dev); |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4021 | dev->netdev_ops = &rtl8169_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4022 | tp = netdev_priv(dev); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4023 | tp->dev = dev; |
Ivan Vecera | 21e197f | 2008-04-17 22:48:41 +0200 | [diff] [blame] | 4024 | tp->pci_dev = pdev; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 4025 | tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4026 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 4027 | mii = &tp->mii; |
| 4028 | mii->dev = dev; |
| 4029 | mii->mdio_read = rtl_mdio_read; |
| 4030 | mii->mdio_write = rtl_mdio_write; |
| 4031 | mii->phy_id_mask = 0x1f; |
| 4032 | mii->reg_num_mask = 0x1f; |
| 4033 | mii->supports_gmii = !!(cfg->features & RTL_FEATURE_GMII); |
| 4034 | |
Stanislaw Gruszka | ba04c7c | 2011-02-22 02:00:11 +0000 | [diff] [blame] | 4035 | /* disable ASPM completely as that cause random device stop working |
| 4036 | * problems as well as full system hangs for some PCIe devices users */ |
| 4037 | pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 | |
| 4038 | PCIE_LINK_STATE_CLKPM); |
| 4039 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4040 | /* enable device (incl. PCI PM wakeup and hotplug setup) */ |
| 4041 | rc = pci_enable_device(pdev); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 4042 | if (rc < 0) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 4043 | netif_err(tp, probe, dev, "enable failure\n"); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4044 | goto err_out_free_dev_1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4045 | } |
| 4046 | |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 4047 | if (pci_set_mwi(pdev) < 0) |
| 4048 | netif_info(tp, probe, dev, "Mem-Wr-Inval unavailable\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4049 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4050 | /* make sure PCI base addr 1 is MMIO */ |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4051 | if (!(pci_resource_flags(pdev, region) & IORESOURCE_MEM)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 4052 | netif_err(tp, probe, dev, |
| 4053 | "region #%d not an MMIO resource, aborting\n", |
| 4054 | region); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4055 | rc = -ENODEV; |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 4056 | goto err_out_mwi_2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4057 | } |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4058 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4059 | /* check for weird/broken PCI region reporting */ |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4060 | if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 4061 | netif_err(tp, probe, dev, |
| 4062 | "Invalid PCI region size(s), aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4063 | rc = -ENODEV; |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 4064 | goto err_out_mwi_2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4065 | } |
| 4066 | |
| 4067 | rc = pci_request_regions(pdev, MODULENAME); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 4068 | if (rc < 0) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 4069 | netif_err(tp, probe, dev, "could not request regions\n"); |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 4070 | goto err_out_mwi_2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4071 | } |
| 4072 | |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 4073 | tp->cp_cmd = RxChkSum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4074 | |
| 4075 | if ((sizeof(dma_addr_t) > 4) && |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 4076 | !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && use_dac) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4077 | tp->cp_cmd |= PCIDAC; |
| 4078 | dev->features |= NETIF_F_HIGHDMA; |
| 4079 | } else { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 4080 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4081 | if (rc < 0) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 4082 | netif_err(tp, probe, dev, "DMA configuration failed\n"); |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 4083 | goto err_out_free_res_3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4084 | } |
| 4085 | } |
| 4086 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4087 | /* ioremap MMIO region */ |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4088 | ioaddr = ioremap(pci_resource_start(pdev, region), R8169_REGS_SIZE); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4089 | if (!ioaddr) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 4090 | netif_err(tp, probe, dev, "cannot remap MMIO, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4091 | rc = -EIO; |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 4092 | goto err_out_free_res_3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4093 | } |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4094 | tp->mmio_addr = ioaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4095 | |
Jon Mason | e44daad | 2011-06-27 07:46:31 +0000 | [diff] [blame] | 4096 | if (!pci_is_pcie(pdev)) |
| 4097 | netif_info(tp, probe, dev, "not PCI Express\n"); |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 4098 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4099 | /* Identify chip attached to board */ |
| 4100 | rtl8169_get_mac_version(tp, dev, cfg->default_ver); |
| 4101 | |
| 4102 | rtl_init_rxcfg(tp); |
| 4103 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 4104 | rtl_irq_disable(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4105 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 4106 | rtl_hw_reset(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4107 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 4108 | rtl_ack_events(tp, 0xffff); |
Karsten Wiese | d78ad8c | 2009-04-02 01:06:01 -0700 | [diff] [blame] | 4109 | |
françois romieu | ca52efd | 2009-07-24 12:34:19 +0000 | [diff] [blame] | 4110 | pci_set_master(pdev); |
| 4111 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 4112 | /* |
| 4113 | * Pretend we are using VLANs; This bypasses a nasty bug where |
| 4114 | * Interrupts stop flowing on high load on 8110SCd controllers. |
| 4115 | */ |
| 4116 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
| 4117 | tp->cp_cmd |= RxVlan; |
| 4118 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4119 | rtl_init_mdio_ops(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4120 | rtl_init_pll_power_ops(tp); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4121 | rtl_init_jumbo_ops(tp); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 4122 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4123 | rtl8169_print_mac_version(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 4125 | chipset = tp->mac_version; |
| 4126 | tp->txd_version = rtl_chip_infos[chipset].txd_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4127 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 4128 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 4129 | RTL_W8(Config1, RTL_R8(Config1) | PMEnable); |
| 4130 | RTL_W8(Config5, RTL_R8(Config5) & PMEStatus); |
Bruno Prémont | 20037fa | 2008-10-08 17:05:03 -0700 | [diff] [blame] | 4131 | if ((RTL_R8(Config3) & (LinkUp | MagicPacket)) != 0) |
| 4132 | tp->features |= RTL_FEATURE_WOL; |
| 4133 | if ((RTL_R8(Config5) & (UWF | BWF | MWF)) != 0) |
| 4134 | tp->features |= RTL_FEATURE_WOL; |
françois romieu | 2ca6cf0 | 2011-12-15 08:37:43 +0000 | [diff] [blame] | 4135 | tp->features |= rtl_try_msi(tp, cfg); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 4136 | RTL_W8(Cfg9346, Cfg9346_Lock); |
| 4137 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4138 | if (rtl_tbi_enabled(tp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4139 | tp->set_speed = rtl8169_set_speed_tbi; |
| 4140 | tp->get_settings = rtl8169_gset_tbi; |
| 4141 | tp->phy_reset_enable = rtl8169_tbi_reset_enable; |
| 4142 | tp->phy_reset_pending = rtl8169_tbi_reset_pending; |
| 4143 | tp->link_ok = rtl8169_tbi_link_ok; |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4144 | tp->do_ioctl = rtl_tbi_ioctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4145 | } else { |
| 4146 | tp->set_speed = rtl8169_set_speed_xmii; |
| 4147 | tp->get_settings = rtl8169_gset_xmii; |
| 4148 | tp->phy_reset_enable = rtl8169_xmii_reset_enable; |
| 4149 | tp->phy_reset_pending = rtl8169_xmii_reset_pending; |
| 4150 | tp->link_ok = rtl8169_xmii_link_ok; |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 4151 | tp->do_ioctl = rtl_xmii_ioctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4152 | } |
| 4153 | |
Francois Romieu | df58ef51 | 2008-10-09 14:35:58 -0700 | [diff] [blame] | 4154 | spin_lock_init(&tp->lock); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4155 | mutex_init(&tp->wk.mutex); |
Francois Romieu | df58ef51 | 2008-10-09 14:35:58 -0700 | [diff] [blame] | 4156 | |
Ivan Vecera | 7bf6bf4 | 2008-09-23 22:46:29 +0000 | [diff] [blame] | 4157 | /* Get MAC address */ |
Joe Perches | 6a3c910c | 2011-11-16 09:38:02 +0000 | [diff] [blame] | 4158 | for (i = 0; i < ETH_ALEN; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4159 | dev->dev_addr[i] = RTL_R8(MAC0 + i); |
John W. Linville | 6d6525b | 2005-09-12 10:48:57 -0400 | [diff] [blame] | 4160 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4161 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4162 | SET_ETHTOOL_OPS(dev, &rtl8169_ethtool_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4163 | dev->watchdog_timeo = RTL8169_TX_TIMEOUT; |
| 4164 | dev->irq = pdev->irq; |
| 4165 | dev->base_addr = (unsigned long) ioaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4166 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 4167 | netif_napi_add(dev, &tp->napi, rtl8169_poll, R8169_NAPI_WEIGHT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4168 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 4169 | /* don't enable SG, IP_CSUM and TSO by default - it might not work |
| 4170 | * properly for all devices */ |
| 4171 | dev->features |= NETIF_F_RXCSUM | |
| 4172 | NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
| 4173 | |
| 4174 | dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 4175 | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
| 4176 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 4177 | NETIF_F_HIGHDMA; |
| 4178 | |
| 4179 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
| 4180 | /* 8110SCd requires hardware Rx VLAN - disallow toggling */ |
| 4181 | dev->hw_features &= ~NETIF_F_HW_VLAN_RX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4182 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 4183 | tp->hw_start = cfg->hw_start; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4184 | tp->event_slow = cfg->event_slow; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4185 | |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4186 | tp->opts1_mask = (tp->mac_version != RTL_GIGA_MAC_VER_01) ? |
| 4187 | ~(RxBOVF | RxFOVF) : ~0; |
| 4188 | |
Francois Romieu | 2efa53f | 2007-03-09 00:00:05 +0100 | [diff] [blame] | 4189 | init_timer(&tp->timer); |
| 4190 | tp->timer.data = (unsigned long) dev; |
| 4191 | tp->timer.function = rtl8169_phy_timer; |
| 4192 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4193 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4194 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4195 | rc = register_netdev(dev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4196 | if (rc < 0) |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 4197 | goto err_out_msi_4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4198 | |
| 4199 | pci_set_drvdata(pdev, dev); |
| 4200 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 4201 | netif_info(tp, probe, dev, "%s at 0x%lx, %pM, XID %08x IRQ %d\n", |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 4202 | rtl_chip_infos[chipset].name, dev->base_addr, dev->dev_addr, |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 4203 | (u32)(RTL_R32(TxConfig) & 0x9cf0f8ff), dev->irq); |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 4204 | if (rtl_chip_infos[chipset].jumbo_max != JUMBO_1K) { |
| 4205 | netif_info(tp, probe, dev, "jumbo features [frames: %d bytes, " |
| 4206 | "tx checksumming: %s]\n", |
| 4207 | rtl_chip_infos[chipset].jumbo_max, |
| 4208 | rtl_chip_infos[chipset].jumbo_tx_csum ? "ok" : "ko"); |
| 4209 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4210 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4211 | if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
| 4212 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 4213 | tp->mac_version == RTL_GIGA_MAC_VER_31) { |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 4214 | rtl8168_driver_start(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4215 | } |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 4216 | |
Bruno Prémont | 8b76ab3 | 2008-10-08 17:06:25 -0700 | [diff] [blame] | 4217 | device_set_wakeup_enable(&pdev->dev, tp->features & RTL_FEATURE_WOL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4218 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 4219 | if (pci_dev_run_wake(pdev)) |
| 4220 | pm_runtime_put_noidle(&pdev->dev); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 4221 | |
Ivan Vecera | 0d672e9 | 2011-02-15 02:08:39 +0000 | [diff] [blame] | 4222 | netif_carrier_off(dev); |
| 4223 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4224 | out: |
| 4225 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4226 | |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 4227 | err_out_msi_4: |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 4228 | rtl_disable_msi(pdev, tp); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4229 | iounmap(ioaddr); |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 4230 | err_out_free_res_3: |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4231 | pci_release_regions(pdev); |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 4232 | err_out_mwi_2: |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4233 | pci_clear_mwi(pdev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 4234 | pci_disable_device(pdev); |
| 4235 | err_out_free_dev_1: |
| 4236 | free_netdev(dev); |
| 4237 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4238 | } |
| 4239 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 4240 | static void __devexit rtl8169_remove_one(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4241 | { |
| 4242 | struct net_device *dev = pci_get_drvdata(pdev); |
| 4243 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4244 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4245 | if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
| 4246 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 4247 | tp->mac_version == RTL_GIGA_MAC_VER_31) { |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 4248 | rtl8168_driver_stop(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4249 | } |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 4250 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 4251 | cancel_work_sync(&tp->wk.work); |
Francois Romieu | eb2a021 | 2007-02-15 23:37:21 +0100 | [diff] [blame] | 4252 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4253 | unregister_netdev(dev); |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 4254 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4255 | rtl_release_firmware(tp); |
| 4256 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 4257 | if (pci_dev_run_wake(pdev)) |
| 4258 | pm_runtime_get_noresume(&pdev->dev); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 4259 | |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 4260 | /* restore original MAC address */ |
| 4261 | rtl_rar_set(tp, dev->perm_addr); |
| 4262 | |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 4263 | rtl_disable_msi(pdev, tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4264 | rtl8169_release_board(pdev, dev, tp->mmio_addr); |
| 4265 | pci_set_drvdata(pdev, NULL); |
| 4266 | } |
| 4267 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4268 | static void rtl_request_uncached_firmware(struct rtl8169_private *tp) |
| 4269 | { |
| 4270 | struct rtl_fw *rtl_fw; |
| 4271 | const char *name; |
| 4272 | int rc = -ENOMEM; |
| 4273 | |
| 4274 | name = rtl_lookup_firmware_name(tp); |
| 4275 | if (!name) |
| 4276 | goto out_no_firmware; |
| 4277 | |
| 4278 | rtl_fw = kzalloc(sizeof(*rtl_fw), GFP_KERNEL); |
| 4279 | if (!rtl_fw) |
| 4280 | goto err_warn; |
| 4281 | |
| 4282 | rc = request_firmware(&rtl_fw->fw, name, &tp->pci_dev->dev); |
| 4283 | if (rc < 0) |
| 4284 | goto err_free; |
| 4285 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 4286 | rc = rtl_check_firmware(tp, rtl_fw); |
| 4287 | if (rc < 0) |
| 4288 | goto err_release_firmware; |
| 4289 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4290 | tp->rtl_fw = rtl_fw; |
| 4291 | out: |
| 4292 | return; |
| 4293 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 4294 | err_release_firmware: |
| 4295 | release_firmware(rtl_fw->fw); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4296 | err_free: |
| 4297 | kfree(rtl_fw); |
| 4298 | err_warn: |
| 4299 | netif_warn(tp, ifup, tp->dev, "unable to load firmware patch %s (%d)\n", |
| 4300 | name, rc); |
| 4301 | out_no_firmware: |
| 4302 | tp->rtl_fw = NULL; |
| 4303 | goto out; |
| 4304 | } |
| 4305 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4306 | static void rtl_request_firmware(struct rtl8169_private *tp) |
| 4307 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 4308 | if (IS_ERR(tp->rtl_fw)) |
| 4309 | rtl_request_uncached_firmware(tp); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4310 | } |
| 4311 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 4312 | static void rtl_task(struct work_struct *); |
| 4313 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4314 | static int rtl8169_open(struct net_device *dev) |
| 4315 | { |
| 4316 | struct rtl8169_private *tp = netdev_priv(dev); |
françois romieu | eee3a96 | 2011-01-08 02:17:26 +0000 | [diff] [blame] | 4317 | void __iomem *ioaddr = tp->mmio_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4318 | struct pci_dev *pdev = tp->pci_dev; |
Francois Romieu | 99f252b | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 4319 | int retval = -ENOMEM; |
| 4320 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 4321 | pm_runtime_get_sync(&pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4322 | |
Neil Horman | c0cd884 | 2010-03-29 13:16:02 -0700 | [diff] [blame] | 4323 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4324 | * Rx and Tx desscriptors needs 256 bytes alignment. |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 4325 | * dma_alloc_coherent provides more. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4326 | */ |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 4327 | tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES, |
| 4328 | &tp->TxPhyAddr, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4329 | if (!tp->TxDescArray) |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 4330 | goto err_pm_runtime_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4331 | |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 4332 | tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, |
| 4333 | &tp->RxPhyAddr, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4334 | if (!tp->RxDescArray) |
Francois Romieu | 99f252b | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 4335 | goto err_free_tx_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4336 | |
| 4337 | retval = rtl8169_init_ring(dev); |
| 4338 | if (retval < 0) |
Francois Romieu | 99f252b | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 4339 | goto err_free_rx_1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4340 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 4341 | INIT_WORK(&tp->wk.work, rtl_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4342 | |
Francois Romieu | 99f252b | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 4343 | smp_mb(); |
| 4344 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4345 | rtl_request_firmware(tp); |
| 4346 | |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 4347 | retval = request_irq(dev->irq, rtl8169_interrupt, |
| 4348 | (tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED, |
Francois Romieu | 99f252b | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 4349 | dev->name, dev); |
| 4350 | if (retval < 0) |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4351 | goto err_release_fw_2; |
Francois Romieu | 99f252b | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 4352 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4353 | rtl_lock_work(tp); |
| 4354 | |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 4355 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4356 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 4357 | napi_enable(&tp->napi); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 4358 | |
françois romieu | eee3a96 | 2011-01-08 02:17:26 +0000 | [diff] [blame] | 4359 | rtl8169_init_phy(dev, tp); |
| 4360 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4361 | __rtl8169_set_features(dev, dev->features); |
françois romieu | eee3a96 | 2011-01-08 02:17:26 +0000 | [diff] [blame] | 4362 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 4363 | rtl_pll_power_up(tp); |
| 4364 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4365 | rtl_hw_start(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4366 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4367 | netif_start_queue(dev); |
| 4368 | |
| 4369 | rtl_unlock_work(tp); |
| 4370 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 4371 | tp->saved_wolopts = 0; |
| 4372 | pm_runtime_put_noidle(&pdev->dev); |
| 4373 | |
françois romieu | eee3a96 | 2011-01-08 02:17:26 +0000 | [diff] [blame] | 4374 | rtl8169_check_link_status(dev, tp, ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4375 | out: |
| 4376 | return retval; |
| 4377 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 4378 | err_release_fw_2: |
| 4379 | rtl_release_firmware(tp); |
Francois Romieu | 99f252b | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 4380 | rtl8169_rx_clear(tp); |
| 4381 | err_free_rx_1: |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 4382 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 4383 | tp->RxPhyAddr); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 4384 | tp->RxDescArray = NULL; |
Francois Romieu | 99f252b | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 4385 | err_free_tx_0: |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 4386 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 4387 | tp->TxPhyAddr); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 4388 | tp->TxDescArray = NULL; |
| 4389 | err_pm_runtime_put: |
| 4390 | pm_runtime_put_noidle(&pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4391 | goto out; |
| 4392 | } |
| 4393 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4394 | static void rtl_rx_close(struct rtl8169_private *tp) |
| 4395 | { |
| 4396 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4397 | |
Francois Romieu | 1687b56 | 2011-07-19 17:21:29 +0200 | [diff] [blame] | 4398 | RTL_W32(RxConfig, RTL_R32(RxConfig) & ~RX_CONFIG_ACCEPT_MASK); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4399 | } |
| 4400 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4401 | static void rtl8169_hw_reset(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4402 | { |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4403 | void __iomem *ioaddr = tp->mmio_addr; |
| 4404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4405 | /* Disable interrupts */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 4406 | rtl8169_irq_mask_and_ack(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4407 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4408 | rtl_rx_close(tp); |
| 4409 | |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 4410 | if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4411 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 4412 | tp->mac_version == RTL_GIGA_MAC_VER_31) { |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4413 | while (RTL_R8(TxPoll) & NPQ) |
| 4414 | udelay(20); |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4415 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_34 || |
| 4416 | tp->mac_version == RTL_GIGA_MAC_VER_35 || |
| 4417 | tp->mac_version == RTL_GIGA_MAC_VER_36) { |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 4418 | RTL_W8(ChipCmd, RTL_R8(ChipCmd) | StopReq); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4419 | while (!(RTL_R32(TxConfig) & TXCFG_EMPTY)) |
| 4420 | udelay(100); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4421 | } else { |
| 4422 | RTL_W8(ChipCmd, RTL_R8(ChipCmd) | StopReq); |
| 4423 | udelay(100); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4424 | } |
| 4425 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4426 | rtl_hw_reset(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4427 | } |
| 4428 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4429 | static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4430 | { |
| 4431 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4432 | |
| 4433 | /* Set DMA burst size and Interframe Gap Time */ |
| 4434 | RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) | |
| 4435 | (InterFrameGap << TxInterFrameGapShift)); |
| 4436 | } |
| 4437 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4438 | static void rtl_hw_start(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4439 | { |
| 4440 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4441 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4442 | tp->hw_start(dev); |
| 4443 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4444 | rtl_irq_enable_all(tp); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4445 | } |
| 4446 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4447 | static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp, |
| 4448 | void __iomem *ioaddr) |
| 4449 | { |
| 4450 | /* |
| 4451 | * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh |
| 4452 | * register to be written before TxDescAddrLow to work. |
| 4453 | * Switching from MMIO to I/O access fixes the issue as well. |
| 4454 | */ |
| 4455 | RTL_W32(TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 4456 | RTL_W32(TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4457 | RTL_W32(RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 4458 | RTL_W32(RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4459 | } |
| 4460 | |
| 4461 | static u16 rtl_rw_cpluscmd(void __iomem *ioaddr) |
| 4462 | { |
| 4463 | u16 cmd; |
| 4464 | |
| 4465 | cmd = RTL_R16(CPlusCmd); |
| 4466 | RTL_W16(CPlusCmd, cmd); |
| 4467 | return cmd; |
| 4468 | } |
| 4469 | |
Eric Dumazet | fdd7b4c | 2009-06-09 04:01:02 -0700 | [diff] [blame] | 4470 | 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] | 4471 | { |
| 4472 | /* Low hurts. Let's disable the filtering. */ |
Raimonds Cicans | 207d6e87 | 2009-10-26 10:52:37 +0000 | [diff] [blame] | 4473 | RTL_W16(RxMaxSize, rx_buf_sz + 1); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4474 | } |
| 4475 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4476 | static void rtl8169_set_magic_reg(void __iomem *ioaddr, unsigned mac_version) |
| 4477 | { |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 4478 | static const struct rtl_cfg2_info { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4479 | u32 mac_version; |
| 4480 | u32 clk; |
| 4481 | u32 val; |
| 4482 | } cfg2_info [] = { |
| 4483 | { RTL_GIGA_MAC_VER_05, PCI_Clock_33MHz, 0x000fff00 }, // 8110SCd |
| 4484 | { RTL_GIGA_MAC_VER_05, PCI_Clock_66MHz, 0x000fffff }, |
| 4485 | { RTL_GIGA_MAC_VER_06, PCI_Clock_33MHz, 0x00ffff00 }, // 8110SCe |
| 4486 | { RTL_GIGA_MAC_VER_06, PCI_Clock_66MHz, 0x00ffffff } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 4487 | }; |
| 4488 | const struct rtl_cfg2_info *p = cfg2_info; |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4489 | unsigned int i; |
| 4490 | u32 clk; |
| 4491 | |
| 4492 | clk = RTL_R8(Config2) & PCI_Clock_66MHz; |
Francois Romieu | cadf185 | 2008-01-03 23:38:38 +0100 | [diff] [blame] | 4493 | for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4494 | if ((p->mac_version == mac_version) && (p->clk == clk)) { |
| 4495 | RTL_W32(0x7c, p->val); |
| 4496 | break; |
| 4497 | } |
| 4498 | } |
| 4499 | } |
| 4500 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4501 | static void rtl_hw_start_8169(struct net_device *dev) |
| 4502 | { |
| 4503 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4504 | void __iomem *ioaddr = tp->mmio_addr; |
| 4505 | struct pci_dev *pdev = tp->pci_dev; |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4506 | |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4507 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) { |
| 4508 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) | PCIMulRW); |
| 4509 | pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, 0x08); |
| 4510 | } |
| 4511 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4512 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4513 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 || |
| 4514 | tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 4515 | tp->mac_version == RTL_GIGA_MAC_VER_03 || |
| 4516 | tp->mac_version == RTL_GIGA_MAC_VER_04) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4517 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 4518 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4519 | rtl_init_rxcfg(tp); |
| 4520 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 4521 | RTL_W8(EarlyTxThres, NoEarlyTx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4523 | rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4524 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4525 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 || |
| 4526 | tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 4527 | tp->mac_version == RTL_GIGA_MAC_VER_03 || |
| 4528 | tp->mac_version == RTL_GIGA_MAC_VER_04) |
Francois Romieu | c946b30 | 2007-10-04 00:42:50 +0200 | [diff] [blame] | 4529 | rtl_set_rx_tx_config_registers(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4530 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4531 | tp->cp_cmd |= rtl_rw_cpluscmd(ioaddr) | PCIMulRW; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4532 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4533 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 4534 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
Joe Perches | 06fa735 | 2007-10-18 21:15:00 +0200 | [diff] [blame] | 4535 | dprintk("Set MAC Reg C+CR Offset 0xE0. " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4536 | "Bit-3 and bit-14 MUST be 1\n"); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4537 | tp->cp_cmd |= (1 << 14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4538 | } |
| 4539 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4540 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 4541 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4542 | rtl8169_set_magic_reg(ioaddr, tp->mac_version); |
| 4543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4544 | /* |
| 4545 | * Undocumented corner. Supposedly: |
| 4546 | * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets |
| 4547 | */ |
| 4548 | RTL_W16(IntrMitigate, 0x0000); |
| 4549 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4550 | rtl_set_rx_tx_desc_registers(tp, ioaddr); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4551 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4552 | if (tp->mac_version != RTL_GIGA_MAC_VER_01 && |
| 4553 | tp->mac_version != RTL_GIGA_MAC_VER_02 && |
| 4554 | tp->mac_version != RTL_GIGA_MAC_VER_03 && |
| 4555 | tp->mac_version != RTL_GIGA_MAC_VER_04) { |
Francois Romieu | c946b30 | 2007-10-04 00:42:50 +0200 | [diff] [blame] | 4556 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 4557 | rtl_set_rx_tx_config_registers(tp); |
| 4558 | } |
| 4559 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4560 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Francois Romieu | b518fa8 | 2006-08-16 15:23:13 +0200 | [diff] [blame] | 4561 | |
| 4562 | /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ |
| 4563 | RTL_R8(IntrMask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4564 | |
| 4565 | RTL_W32(RxMissed, 0); |
| 4566 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4567 | rtl_set_rx_mode(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4568 | |
| 4569 | /* no early-rx interrupts */ |
| 4570 | RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4571 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4572 | |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4573 | static void rtl_csi_access_enable(void __iomem *ioaddr, u32 bits) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4574 | { |
| 4575 | u32 csi; |
| 4576 | |
| 4577 | csi = rtl_csi_read(ioaddr, 0x070c) & 0x00ffffff; |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4578 | rtl_csi_write(ioaddr, 0x070c, csi | bits); |
| 4579 | } |
| 4580 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4581 | static void rtl_csi_access_enable_1(void __iomem *ioaddr) |
| 4582 | { |
| 4583 | rtl_csi_access_enable(ioaddr, 0x17000000); |
| 4584 | } |
| 4585 | |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4586 | static void rtl_csi_access_enable_2(void __iomem *ioaddr) |
| 4587 | { |
| 4588 | rtl_csi_access_enable(ioaddr, 0x27000000); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4589 | } |
| 4590 | |
| 4591 | struct ephy_info { |
| 4592 | unsigned int offset; |
| 4593 | u16 mask; |
| 4594 | u16 bits; |
| 4595 | }; |
| 4596 | |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4597 | static void rtl_ephy_init(void __iomem *ioaddr, const struct ephy_info *e, int len) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4598 | { |
| 4599 | u16 w; |
| 4600 | |
| 4601 | while (len-- > 0) { |
| 4602 | w = (rtl_ephy_read(ioaddr, e->offset) & ~e->mask) | e->bits; |
| 4603 | rtl_ephy_write(ioaddr, e->offset, w); |
| 4604 | e++; |
| 4605 | } |
| 4606 | } |
| 4607 | |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4608 | static void rtl_disable_clock_request(struct pci_dev *pdev) |
| 4609 | { |
Jon Mason | e44daad | 2011-06-27 07:46:31 +0000 | [diff] [blame] | 4610 | int cap = pci_pcie_cap(pdev); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4611 | |
| 4612 | if (cap) { |
| 4613 | u16 ctl; |
| 4614 | |
| 4615 | pci_read_config_word(pdev, cap + PCI_EXP_LNKCTL, &ctl); |
| 4616 | ctl &= ~PCI_EXP_LNKCTL_CLKREQ_EN; |
| 4617 | pci_write_config_word(pdev, cap + PCI_EXP_LNKCTL, ctl); |
| 4618 | } |
| 4619 | } |
| 4620 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4621 | static void rtl_enable_clock_request(struct pci_dev *pdev) |
| 4622 | { |
Jon Mason | e44daad | 2011-06-27 07:46:31 +0000 | [diff] [blame] | 4623 | int cap = pci_pcie_cap(pdev); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4624 | |
| 4625 | if (cap) { |
| 4626 | u16 ctl; |
| 4627 | |
| 4628 | pci_read_config_word(pdev, cap + PCI_EXP_LNKCTL, &ctl); |
| 4629 | ctl |= PCI_EXP_LNKCTL_CLKREQ_EN; |
| 4630 | pci_write_config_word(pdev, cap + PCI_EXP_LNKCTL, ctl); |
| 4631 | } |
| 4632 | } |
| 4633 | |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4634 | #define R8168_CPCMD_QUIRK_MASK (\ |
| 4635 | EnableBist | \ |
| 4636 | Mac_dbgo_oe | \ |
| 4637 | Force_half_dup | \ |
| 4638 | Force_rxflow_en | \ |
| 4639 | Force_txflow_en | \ |
| 4640 | Cxpl_dbg_sel | \ |
| 4641 | ASF | \ |
| 4642 | PktCntrDisable | \ |
| 4643 | Mac_dbgo_sel) |
| 4644 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4645 | static void rtl_hw_start_8168bb(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4646 | { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4647 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 4648 | |
| 4649 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 4650 | |
Francois Romieu | 2e68ae4 | 2008-06-28 12:00:55 +0200 | [diff] [blame] | 4651 | rtl_tx_performance_tweak(pdev, |
| 4652 | (0x5 << MAX_READ_REQUEST_SHIFT) | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4653 | } |
| 4654 | |
| 4655 | static void rtl_hw_start_8168bef(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4656 | { |
| 4657 | rtl_hw_start_8168bb(ioaddr, pdev); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4658 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 4659 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4660 | |
| 4661 | RTL_W8(Config4, RTL_R8(Config4) & ~(1 << 0)); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4662 | } |
| 4663 | |
| 4664 | static void __rtl_hw_start_8168cp(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4665 | { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4666 | RTL_W8(Config1, RTL_R8(Config1) | Speed_down); |
| 4667 | |
| 4668 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 4669 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4670 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4671 | |
| 4672 | rtl_disable_clock_request(pdev); |
| 4673 | |
| 4674 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4675 | } |
| 4676 | |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4677 | static void rtl_hw_start_8168cp_1(void __iomem *ioaddr, struct pci_dev *pdev) |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4678 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4679 | static const struct ephy_info e_info_8168cp[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4680 | { 0x01, 0, 0x0001 }, |
| 4681 | { 0x02, 0x0800, 0x1000 }, |
| 4682 | { 0x03, 0, 0x0042 }, |
| 4683 | { 0x06, 0x0080, 0x0000 }, |
| 4684 | { 0x07, 0, 0x2000 } |
| 4685 | }; |
| 4686 | |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4687 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4688 | |
| 4689 | rtl_ephy_init(ioaddr, e_info_8168cp, ARRAY_SIZE(e_info_8168cp)); |
| 4690 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4691 | __rtl_hw_start_8168cp(ioaddr, pdev); |
| 4692 | } |
| 4693 | |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4694 | static void rtl_hw_start_8168cp_2(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4695 | { |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4696 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4697 | |
| 4698 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 4699 | |
| 4700 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4701 | |
| 4702 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 4703 | } |
| 4704 | |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4705 | static void rtl_hw_start_8168cp_3(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4706 | { |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4707 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4708 | |
| 4709 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 4710 | |
| 4711 | /* Magic. */ |
| 4712 | RTL_W8(DBG_REG, 0x20); |
| 4713 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 4714 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4715 | |
| 4716 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4717 | |
| 4718 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 4719 | } |
| 4720 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4721 | static void rtl_hw_start_8168c_1(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4722 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4723 | static const struct ephy_info e_info_8168c_1[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4724 | { 0x02, 0x0800, 0x1000 }, |
| 4725 | { 0x03, 0, 0x0002 }, |
| 4726 | { 0x06, 0x0080, 0x0000 } |
| 4727 | }; |
| 4728 | |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4729 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4730 | |
| 4731 | RTL_W8(DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2); |
| 4732 | |
| 4733 | rtl_ephy_init(ioaddr, e_info_8168c_1, ARRAY_SIZE(e_info_8168c_1)); |
| 4734 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4735 | __rtl_hw_start_8168cp(ioaddr, pdev); |
| 4736 | } |
| 4737 | |
| 4738 | static void rtl_hw_start_8168c_2(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4739 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4740 | static const struct ephy_info e_info_8168c_2[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4741 | { 0x01, 0, 0x0001 }, |
| 4742 | { 0x03, 0x0400, 0x0220 } |
| 4743 | }; |
| 4744 | |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4745 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4746 | |
| 4747 | rtl_ephy_init(ioaddr, e_info_8168c_2, ARRAY_SIZE(e_info_8168c_2)); |
| 4748 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4749 | __rtl_hw_start_8168cp(ioaddr, pdev); |
| 4750 | } |
| 4751 | |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4752 | static void rtl_hw_start_8168c_3(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4753 | { |
| 4754 | rtl_hw_start_8168c_2(ioaddr, pdev); |
| 4755 | } |
| 4756 | |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4757 | static void rtl_hw_start_8168c_4(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4758 | { |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4759 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4760 | |
| 4761 | __rtl_hw_start_8168cp(ioaddr, pdev); |
| 4762 | } |
| 4763 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4764 | static void rtl_hw_start_8168d(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4765 | { |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4766 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4767 | |
| 4768 | rtl_disable_clock_request(pdev); |
| 4769 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 4770 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4771 | |
| 4772 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4773 | |
| 4774 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 4775 | } |
| 4776 | |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4777 | static void rtl_hw_start_8168dp(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4778 | { |
| 4779 | rtl_csi_access_enable_1(ioaddr); |
| 4780 | |
| 4781 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4782 | |
| 4783 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
| 4784 | |
| 4785 | rtl_disable_clock_request(pdev); |
| 4786 | } |
| 4787 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4788 | static void rtl_hw_start_8168d_4(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4789 | { |
| 4790 | static const struct ephy_info e_info_8168d_4[] = { |
| 4791 | { 0x0b, ~0, 0x48 }, |
| 4792 | { 0x19, 0x20, 0x50 }, |
| 4793 | { 0x0c, ~0, 0x20 } |
| 4794 | }; |
| 4795 | int i; |
| 4796 | |
| 4797 | rtl_csi_access_enable_1(ioaddr); |
| 4798 | |
| 4799 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4800 | |
| 4801 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
| 4802 | |
| 4803 | for (i = 0; i < ARRAY_SIZE(e_info_8168d_4); i++) { |
| 4804 | const struct ephy_info *e = e_info_8168d_4 + i; |
| 4805 | u16 w; |
| 4806 | |
| 4807 | w = rtl_ephy_read(ioaddr, e->offset); |
| 4808 | rtl_ephy_write(ioaddr, 0x03, (w & e->mask) | e->bits); |
| 4809 | } |
| 4810 | |
| 4811 | rtl_enable_clock_request(pdev); |
| 4812 | } |
| 4813 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4814 | static void rtl_hw_start_8168e_1(void __iomem *ioaddr, struct pci_dev *pdev) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4815 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4816 | static const struct ephy_info e_info_8168e_1[] = { |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4817 | { 0x00, 0x0200, 0x0100 }, |
| 4818 | { 0x00, 0x0000, 0x0004 }, |
| 4819 | { 0x06, 0x0002, 0x0001 }, |
| 4820 | { 0x06, 0x0000, 0x0030 }, |
| 4821 | { 0x07, 0x0000, 0x2000 }, |
| 4822 | { 0x00, 0x0000, 0x0020 }, |
| 4823 | { 0x03, 0x5800, 0x2000 }, |
| 4824 | { 0x03, 0x0000, 0x0001 }, |
| 4825 | { 0x01, 0x0800, 0x1000 }, |
| 4826 | { 0x07, 0x0000, 0x4000 }, |
| 4827 | { 0x1e, 0x0000, 0x2000 }, |
| 4828 | { 0x19, 0xffff, 0xfe6c }, |
| 4829 | { 0x0a, 0x0000, 0x0040 } |
| 4830 | }; |
| 4831 | |
| 4832 | rtl_csi_access_enable_2(ioaddr); |
| 4833 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4834 | rtl_ephy_init(ioaddr, e_info_8168e_1, ARRAY_SIZE(e_info_8168e_1)); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4835 | |
| 4836 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4837 | |
| 4838 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
| 4839 | |
| 4840 | rtl_disable_clock_request(pdev); |
| 4841 | |
| 4842 | /* Reset tx FIFO pointer */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4843 | RTL_W32(MISC, RTL_R32(MISC) | TXPLA_RST); |
| 4844 | RTL_W32(MISC, RTL_R32(MISC) & ~TXPLA_RST); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4845 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4846 | RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4847 | } |
| 4848 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4849 | static void rtl_hw_start_8168e_2(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4850 | { |
| 4851 | static const struct ephy_info e_info_8168e_2[] = { |
| 4852 | { 0x09, 0x0000, 0x0080 }, |
| 4853 | { 0x19, 0x0000, 0x0224 } |
| 4854 | }; |
| 4855 | |
| 4856 | rtl_csi_access_enable_1(ioaddr); |
| 4857 | |
| 4858 | rtl_ephy_init(ioaddr, e_info_8168e_2, ARRAY_SIZE(e_info_8168e_2)); |
| 4859 | |
| 4860 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4861 | |
| 4862 | rtl_eri_write(ioaddr, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 4863 | rtl_eri_write(ioaddr, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 4864 | rtl_eri_write(ioaddr, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 4865 | rtl_eri_write(ioaddr, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 4866 | rtl_eri_write(ioaddr, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 4867 | rtl_eri_write(ioaddr, 0xd0, ERIAR_MASK_1111, 0x07ff0060, ERIAR_EXGMAC); |
| 4868 | rtl_w1w0_eri(ioaddr, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 4869 | rtl_w1w0_eri(ioaddr, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, |
| 4870 | ERIAR_EXGMAC); |
| 4871 | |
Hayes Wang | 3090bd9 | 2011-09-06 16:55:15 +0800 | [diff] [blame] | 4872 | RTL_W8(MaxTxPacketSize, EarlySize); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4873 | |
| 4874 | rtl_disable_clock_request(pdev); |
| 4875 | |
| 4876 | RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
| 4877 | RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB); |
| 4878 | |
| 4879 | /* Adjust EEE LED frequency */ |
| 4880 | RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07); |
| 4881 | |
| 4882 | RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN); |
| 4883 | RTL_W32(MISC, RTL_R32(MISC) | PWM_EN); |
| 4884 | RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en); |
| 4885 | } |
| 4886 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 4887 | static void rtl_hw_start_8168f_1(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4888 | { |
| 4889 | static const struct ephy_info e_info_8168f_1[] = { |
| 4890 | { 0x06, 0x00c0, 0x0020 }, |
| 4891 | { 0x08, 0x0001, 0x0002 }, |
| 4892 | { 0x09, 0x0000, 0x0080 }, |
| 4893 | { 0x19, 0x0000, 0x0224 } |
| 4894 | }; |
| 4895 | |
| 4896 | rtl_csi_access_enable_1(ioaddr); |
| 4897 | |
| 4898 | rtl_ephy_init(ioaddr, e_info_8168f_1, ARRAY_SIZE(e_info_8168f_1)); |
| 4899 | |
| 4900 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4901 | |
| 4902 | rtl_eri_write(ioaddr, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 4903 | rtl_eri_write(ioaddr, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 4904 | rtl_eri_write(ioaddr, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 4905 | rtl_eri_write(ioaddr, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 4906 | rtl_w1w0_eri(ioaddr, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
| 4907 | rtl_w1w0_eri(ioaddr, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
| 4908 | rtl_w1w0_eri(ioaddr, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 4909 | rtl_w1w0_eri(ioaddr, 0x1d0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 4910 | rtl_eri_write(ioaddr, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 4911 | rtl_eri_write(ioaddr, 0xd0, ERIAR_MASK_1111, 0x00000060, ERIAR_EXGMAC); |
| 4912 | rtl_w1w0_eri(ioaddr, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, |
| 4913 | ERIAR_EXGMAC); |
| 4914 | |
| 4915 | RTL_W8(MaxTxPacketSize, EarlySize); |
| 4916 | |
| 4917 | rtl_disable_clock_request(pdev); |
| 4918 | |
| 4919 | RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
| 4920 | RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB); |
| 4921 | |
| 4922 | /* Adjust EEE LED frequency */ |
| 4923 | RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07); |
| 4924 | |
| 4925 | RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN); |
| 4926 | RTL_W32(MISC, RTL_R32(MISC) | PWM_EN); |
| 4927 | RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en); |
| 4928 | } |
| 4929 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4930 | static void rtl_hw_start_8168(struct net_device *dev) |
| 4931 | { |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4932 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4933 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 4934 | struct pci_dev *pdev = tp->pci_dev; |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4935 | |
| 4936 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 4937 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 4938 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4939 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4940 | rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4941 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 4942 | tp->cp_cmd |= RTL_R16(CPlusCmd) | PktCntrDisable | INTT_1; |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4943 | |
| 4944 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 4945 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 4946 | RTL_W16(IntrMitigate, 0x5151); |
| 4947 | |
| 4948 | /* Work around for RxFIFO overflow. */ |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 4949 | if (tp->mac_version == RTL_GIGA_MAC_VER_11) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 4950 | tp->event_slow |= RxFIFOOver | PCSTimeout; |
| 4951 | tp->event_slow &= ~RxOverflow; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 4952 | } |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4953 | |
| 4954 | rtl_set_rx_tx_desc_registers(tp, ioaddr); |
| 4955 | |
Francois Romieu | b836390 | 2008-06-01 12:31:57 +0200 | [diff] [blame] | 4956 | rtl_set_rx_mode(dev); |
| 4957 | |
| 4958 | RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) | |
| 4959 | (InterFrameGap << TxInterFrameGapShift)); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4960 | |
| 4961 | RTL_R8(IntrMask); |
| 4962 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4963 | switch (tp->mac_version) { |
| 4964 | case RTL_GIGA_MAC_VER_11: |
| 4965 | rtl_hw_start_8168bb(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4966 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4967 | |
| 4968 | case RTL_GIGA_MAC_VER_12: |
| 4969 | case RTL_GIGA_MAC_VER_17: |
| 4970 | rtl_hw_start_8168bef(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4971 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4972 | |
| 4973 | case RTL_GIGA_MAC_VER_18: |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4974 | rtl_hw_start_8168cp_1(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4975 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4976 | |
| 4977 | case RTL_GIGA_MAC_VER_19: |
| 4978 | rtl_hw_start_8168c_1(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4979 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4980 | |
| 4981 | case RTL_GIGA_MAC_VER_20: |
| 4982 | rtl_hw_start_8168c_2(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4983 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4984 | |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4985 | case RTL_GIGA_MAC_VER_21: |
| 4986 | rtl_hw_start_8168c_3(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4987 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4988 | |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4989 | case RTL_GIGA_MAC_VER_22: |
| 4990 | rtl_hw_start_8168c_4(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4991 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4992 | |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4993 | case RTL_GIGA_MAC_VER_23: |
| 4994 | rtl_hw_start_8168cp_2(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4995 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4996 | |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4997 | case RTL_GIGA_MAC_VER_24: |
| 4998 | rtl_hw_start_8168cp_3(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4999 | break; |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 5000 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5001 | case RTL_GIGA_MAC_VER_25: |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 5002 | case RTL_GIGA_MAC_VER_26: |
| 5003 | case RTL_GIGA_MAC_VER_27: |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5004 | rtl_hw_start_8168d(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5005 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 5006 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5007 | case RTL_GIGA_MAC_VER_28: |
| 5008 | rtl_hw_start_8168d_4(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5009 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5010 | |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5011 | case RTL_GIGA_MAC_VER_31: |
| 5012 | rtl_hw_start_8168dp(ioaddr, pdev); |
| 5013 | break; |
| 5014 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5015 | case RTL_GIGA_MAC_VER_32: |
| 5016 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 5017 | rtl_hw_start_8168e_1(ioaddr, pdev); |
| 5018 | break; |
| 5019 | case RTL_GIGA_MAC_VER_34: |
| 5020 | rtl_hw_start_8168e_2(ioaddr, pdev); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 5021 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5022 | |
Hayes Wang | c221892 | 2011-09-06 16:55:18 +0800 | [diff] [blame] | 5023 | case RTL_GIGA_MAC_VER_35: |
| 5024 | case RTL_GIGA_MAC_VER_36: |
| 5025 | rtl_hw_start_8168f_1(ioaddr, pdev); |
| 5026 | break; |
| 5027 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5028 | default: |
| 5029 | printk(KERN_ERR PFX "%s: unknown chipset (mac_version = %d).\n", |
| 5030 | dev->name, tp->mac_version); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5031 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 5032 | } |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5033 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5034 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 5035 | |
Francois Romieu | b836390 | 2008-06-01 12:31:57 +0200 | [diff] [blame] | 5036 | RTL_W8(Cfg9346, Cfg9346_Lock); |
| 5037 | |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 5038 | RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5039 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5040 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5041 | #define R810X_CPCMD_QUIRK_MASK (\ |
| 5042 | EnableBist | \ |
| 5043 | Mac_dbgo_oe | \ |
| 5044 | Force_half_dup | \ |
françois romieu | 5edcc53 | 2009-08-10 19:41:52 +0000 | [diff] [blame] | 5045 | Force_rxflow_en | \ |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5046 | Force_txflow_en | \ |
| 5047 | Cxpl_dbg_sel | \ |
| 5048 | ASF | \ |
| 5049 | PktCntrDisable | \ |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 5050 | Mac_dbgo_sel) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5051 | |
| 5052 | static void rtl_hw_start_8102e_1(void __iomem *ioaddr, struct pci_dev *pdev) |
| 5053 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 5054 | static const struct ephy_info e_info_8102e_1[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5055 | { 0x01, 0, 0x6e65 }, |
| 5056 | { 0x02, 0, 0x091f }, |
| 5057 | { 0x03, 0, 0xc2f9 }, |
| 5058 | { 0x06, 0, 0xafb5 }, |
| 5059 | { 0x07, 0, 0x0e00 }, |
| 5060 | { 0x19, 0, 0xec80 }, |
| 5061 | { 0x01, 0, 0x2e65 }, |
| 5062 | { 0x01, 0, 0x6e65 } |
| 5063 | }; |
| 5064 | u8 cfg1; |
| 5065 | |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 5066 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5067 | |
| 5068 | RTL_W8(DBG_REG, FIX_NAK_1); |
| 5069 | |
| 5070 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 5071 | |
| 5072 | RTL_W8(Config1, |
| 5073 | LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable); |
| 5074 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 5075 | |
| 5076 | cfg1 = RTL_R8(Config1); |
| 5077 | if ((cfg1 & LEDS0) && (cfg1 & LEDS1)) |
| 5078 | RTL_W8(Config1, cfg1 & ~LEDS0); |
| 5079 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5080 | rtl_ephy_init(ioaddr, e_info_8102e_1, ARRAY_SIZE(e_info_8102e_1)); |
| 5081 | } |
| 5082 | |
| 5083 | static void rtl_hw_start_8102e_2(void __iomem *ioaddr, struct pci_dev *pdev) |
| 5084 | { |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 5085 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5086 | |
| 5087 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 5088 | |
| 5089 | RTL_W8(Config1, MEMMAP | IOMAP | VPD | PMEnable); |
| 5090 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5091 | } |
| 5092 | |
| 5093 | static void rtl_hw_start_8102e_3(void __iomem *ioaddr, struct pci_dev *pdev) |
| 5094 | { |
| 5095 | rtl_hw_start_8102e_2(ioaddr, pdev); |
| 5096 | |
| 5097 | rtl_ephy_write(ioaddr, 0x03, 0xc2f9); |
| 5098 | } |
| 5099 | |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5100 | static void rtl_hw_start_8105e_1(void __iomem *ioaddr, struct pci_dev *pdev) |
| 5101 | { |
| 5102 | static const struct ephy_info e_info_8105e_1[] = { |
| 5103 | { 0x07, 0, 0x4000 }, |
| 5104 | { 0x19, 0, 0x0200 }, |
| 5105 | { 0x19, 0, 0x0020 }, |
| 5106 | { 0x1e, 0, 0x2000 }, |
| 5107 | { 0x03, 0, 0x0001 }, |
| 5108 | { 0x19, 0, 0x0100 }, |
| 5109 | { 0x19, 0, 0x0004 }, |
| 5110 | { 0x0a, 0, 0x0020 } |
| 5111 | }; |
| 5112 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5113 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5114 | RTL_W32(FuncEvent, RTL_R32(FuncEvent) | 0x002800); |
| 5115 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5116 | /* Disable Early Tally Counter */ |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5117 | RTL_W32(FuncEvent, RTL_R32(FuncEvent) & ~0x010000); |
| 5118 | |
| 5119 | RTL_W8(MCU, RTL_R8(MCU) | EN_NDP | EN_OOB_RESET); |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 5120 | RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5121 | |
| 5122 | rtl_ephy_init(ioaddr, e_info_8105e_1, ARRAY_SIZE(e_info_8105e_1)); |
| 5123 | } |
| 5124 | |
| 5125 | static void rtl_hw_start_8105e_2(void __iomem *ioaddr, struct pci_dev *pdev) |
| 5126 | { |
| 5127 | rtl_hw_start_8105e_1(ioaddr, pdev); |
| 5128 | rtl_ephy_write(ioaddr, 0x1e, rtl_ephy_read(ioaddr, 0x1e) | 0x8000); |
| 5129 | } |
| 5130 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5131 | static void rtl_hw_start_8101(struct net_device *dev) |
| 5132 | { |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5133 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5134 | void __iomem *ioaddr = tp->mmio_addr; |
| 5135 | struct pci_dev *pdev = tp->pci_dev; |
| 5136 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5137 | if (tp->mac_version >= RTL_GIGA_MAC_VER_30) |
| 5138 | tp->event_slow &= ~RxFIFOOver; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 5139 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5140 | if (tp->mac_version == RTL_GIGA_MAC_VER_13 || |
| 5141 | tp->mac_version == RTL_GIGA_MAC_VER_16) { |
Jon Mason | e44daad | 2011-06-27 07:46:31 +0000 | [diff] [blame] | 5142 | int cap = pci_pcie_cap(pdev); |
Francois Romieu | 9c14cea | 2008-07-05 00:21:15 +0200 | [diff] [blame] | 5143 | |
| 5144 | if (cap) { |
| 5145 | pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, |
| 5146 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 5147 | } |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5148 | } |
| 5149 | |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 5150 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 5151 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 5152 | switch (tp->mac_version) { |
| 5153 | case RTL_GIGA_MAC_VER_07: |
| 5154 | rtl_hw_start_8102e_1(ioaddr, pdev); |
| 5155 | break; |
| 5156 | |
| 5157 | case RTL_GIGA_MAC_VER_08: |
| 5158 | rtl_hw_start_8102e_3(ioaddr, pdev); |
| 5159 | break; |
| 5160 | |
| 5161 | case RTL_GIGA_MAC_VER_09: |
| 5162 | rtl_hw_start_8102e_2(ioaddr, pdev); |
| 5163 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 5164 | |
| 5165 | case RTL_GIGA_MAC_VER_29: |
| 5166 | rtl_hw_start_8105e_1(ioaddr, pdev); |
| 5167 | break; |
| 5168 | case RTL_GIGA_MAC_VER_30: |
| 5169 | rtl_hw_start_8105e_2(ioaddr, pdev); |
| 5170 | break; |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5171 | } |
| 5172 | |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 5173 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5174 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 5175 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5176 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5177 | rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5178 | |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 5179 | tp->cp_cmd &= ~R810X_CPCMD_QUIRK_MASK; |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5180 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 5181 | |
| 5182 | RTL_W16(IntrMitigate, 0x0000); |
| 5183 | |
| 5184 | rtl_set_rx_tx_desc_registers(tp, ioaddr); |
| 5185 | |
| 5186 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 5187 | rtl_set_rx_tx_config_registers(tp); |
| 5188 | |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5189 | RTL_R8(IntrMask); |
| 5190 | |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 5191 | rtl_set_rx_mode(dev); |
| 5192 | |
| 5193 | RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5194 | } |
| 5195 | |
| 5196 | static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) |
| 5197 | { |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5198 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5199 | |
| 5200 | if (new_mtu < ETH_ZLEN || |
| 5201 | new_mtu > rtl_chip_infos[tp->mac_version].jumbo_max) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5202 | return -EINVAL; |
| 5203 | |
Francois Romieu | d58d46b | 2011-05-03 16:38:29 +0200 | [diff] [blame] | 5204 | if (new_mtu > ETH_DATA_LEN) |
| 5205 | rtl_hw_jumbo_enable(tp); |
| 5206 | else |
| 5207 | rtl_hw_jumbo_disable(tp); |
| 5208 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5209 | dev->mtu = new_mtu; |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 5210 | netdev_update_features(dev); |
| 5211 | |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 5212 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5213 | } |
| 5214 | |
| 5215 | static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc) |
| 5216 | { |
Al Viro | 95e0918 | 2007-12-22 18:55:39 +0000 | [diff] [blame] | 5217 | desc->addr = cpu_to_le64(0x0badbadbadbadbadull); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5218 | desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask); |
| 5219 | } |
| 5220 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5221 | static void rtl8169_free_rx_databuff(struct rtl8169_private *tp, |
| 5222 | void **data_buff, struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5223 | { |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5224 | 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] | 5225 | DMA_FROM_DEVICE); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5226 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5227 | kfree(*data_buff); |
| 5228 | *data_buff = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5229 | rtl8169_make_unusable_by_asic(desc); |
| 5230 | } |
| 5231 | |
| 5232 | static inline void rtl8169_mark_to_asic(struct RxDesc *desc, u32 rx_buf_sz) |
| 5233 | { |
| 5234 | u32 eor = le32_to_cpu(desc->opts1) & RingEnd; |
| 5235 | |
| 5236 | desc->opts1 = cpu_to_le32(DescOwn | eor | rx_buf_sz); |
| 5237 | } |
| 5238 | |
| 5239 | static inline void rtl8169_map_to_asic(struct RxDesc *desc, dma_addr_t mapping, |
| 5240 | u32 rx_buf_sz) |
| 5241 | { |
| 5242 | desc->addr = cpu_to_le64(mapping); |
| 5243 | wmb(); |
| 5244 | rtl8169_mark_to_asic(desc, rx_buf_sz); |
| 5245 | } |
| 5246 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5247 | static inline void *rtl8169_align(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5248 | { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5249 | return (void *)ALIGN((long)data, 16); |
| 5250 | } |
| 5251 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5252 | static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp, |
| 5253 | struct RxDesc *desc) |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5254 | { |
| 5255 | void *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5256 | dma_addr_t mapping; |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5257 | struct device *d = &tp->pci_dev->dev; |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5258 | struct net_device *dev = tp->dev; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5259 | int node = dev->dev.parent ? dev_to_node(dev->dev.parent) : -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5260 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5261 | data = kmalloc_node(rx_buf_sz, GFP_KERNEL, node); |
| 5262 | if (!data) |
| 5263 | return NULL; |
Francois Romieu | e9f63f3 | 2007-02-28 23:16:57 +0100 | [diff] [blame] | 5264 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5265 | if (rtl8169_align(data) != data) { |
| 5266 | kfree(data); |
| 5267 | data = kmalloc_node(rx_buf_sz + 15, GFP_KERNEL, node); |
| 5268 | if (!data) |
| 5269 | return NULL; |
| 5270 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5271 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5272 | mapping = dma_map_single(d, rtl8169_align(data), rx_buf_sz, |
Stanislaw Gruszka | 231aee6 | 2010-10-20 22:25:38 +0000 | [diff] [blame] | 5273 | DMA_FROM_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5274 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 5275 | if (net_ratelimit()) |
| 5276 | netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5277 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5278 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5279 | |
| 5280 | rtl8169_map_to_asic(desc, mapping, rx_buf_sz); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5281 | return data; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5282 | |
| 5283 | err_out: |
| 5284 | kfree(data); |
| 5285 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5286 | } |
| 5287 | |
| 5288 | static void rtl8169_rx_clear(struct rtl8169_private *tp) |
| 5289 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5290 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5291 | |
| 5292 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5293 | if (tp->Rx_databuff[i]) { |
| 5294 | rtl8169_free_rx_databuff(tp, tp->Rx_databuff + i, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5295 | tp->RxDescArray + i); |
| 5296 | } |
| 5297 | } |
| 5298 | } |
| 5299 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5300 | static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5301 | { |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5302 | desc->opts1 |= cpu_to_le32(RingEnd); |
| 5303 | } |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 5304 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5305 | static int rtl8169_rx_fill(struct rtl8169_private *tp) |
| 5306 | { |
| 5307 | unsigned int i; |
| 5308 | |
| 5309 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5310 | void *data; |
Francois Romieu | 4ae47c2 | 2007-06-16 23:28:45 +0200 | [diff] [blame] | 5311 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5312 | if (tp->Rx_databuff[i]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5313 | continue; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5314 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5315 | data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5316 | if (!data) { |
| 5317 | rtl8169_make_unusable_by_asic(tp->RxDescArray + i); |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5318 | goto err_out; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5319 | } |
| 5320 | tp->Rx_databuff[i] = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5321 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5322 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5323 | rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1); |
| 5324 | return 0; |
| 5325 | |
| 5326 | err_out: |
| 5327 | rtl8169_rx_clear(tp); |
| 5328 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5329 | } |
| 5330 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5331 | static int rtl8169_init_ring(struct net_device *dev) |
| 5332 | { |
| 5333 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5334 | |
| 5335 | rtl8169_init_ring_indexes(tp); |
| 5336 | |
| 5337 | memset(tp->tx_skb, 0x0, NUM_TX_DESC * sizeof(struct ring_info)); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5338 | memset(tp->Rx_databuff, 0x0, NUM_RX_DESC * sizeof(void *)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5339 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 5340 | return rtl8169_rx_fill(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5341 | } |
| 5342 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5343 | 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] | 5344 | struct TxDesc *desc) |
| 5345 | { |
| 5346 | unsigned int len = tx_skb->len; |
| 5347 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5348 | dma_unmap_single(d, le64_to_cpu(desc->addr), len, DMA_TO_DEVICE); |
| 5349 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5350 | desc->opts1 = 0x00; |
| 5351 | desc->opts2 = 0x00; |
| 5352 | desc->addr = 0x00; |
| 5353 | tx_skb->len = 0; |
| 5354 | } |
| 5355 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5356 | static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, |
| 5357 | unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5358 | { |
| 5359 | unsigned int i; |
| 5360 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5361 | for (i = 0; i < n; i++) { |
| 5362 | unsigned int entry = (start + i) % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5363 | struct ring_info *tx_skb = tp->tx_skb + entry; |
| 5364 | unsigned int len = tx_skb->len; |
| 5365 | |
| 5366 | if (len) { |
| 5367 | struct sk_buff *skb = tx_skb->skb; |
| 5368 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5369 | rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5370 | tp->TxDescArray + entry); |
| 5371 | if (skb) { |
Stanislaw Gruszka | cac4b22 | 2010-10-20 22:25:40 +0000 | [diff] [blame] | 5372 | tp->dev->stats.tx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5373 | dev_kfree_skb(skb); |
| 5374 | tx_skb->skb = NULL; |
| 5375 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5376 | } |
| 5377 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5378 | } |
| 5379 | |
| 5380 | static void rtl8169_tx_clear(struct rtl8169_private *tp) |
| 5381 | { |
| 5382 | rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5383 | tp->cur_tx = tp->dirty_tx = 0; |
| 5384 | } |
| 5385 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 5386 | static void rtl_reset_work(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5387 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 5388 | struct net_device *dev = tp->dev; |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5389 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5390 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5391 | napi_disable(&tp->napi); |
| 5392 | netif_stop_queue(dev); |
| 5393 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5394 | |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 5395 | rtl8169_hw_reset(tp); |
| 5396 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5397 | for (i = 0; i < NUM_RX_DESC; i++) |
| 5398 | rtl8169_mark_to_asic(tp->RxDescArray + i, rx_buf_sz); |
| 5399 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5400 | rtl8169_tx_clear(tp); |
françois romieu | c7c2c39 | 2011-12-04 20:30:52 +0000 | [diff] [blame] | 5401 | rtl8169_init_ring_indexes(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5402 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5403 | napi_enable(&tp->napi); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5404 | rtl_hw_start(dev); |
| 5405 | netif_wake_queue(dev); |
| 5406 | rtl8169_check_link_status(dev, tp, tp->mmio_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5407 | } |
| 5408 | |
| 5409 | static void rtl8169_tx_timeout(struct net_device *dev) |
| 5410 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5411 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5412 | |
| 5413 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5414 | } |
| 5415 | |
| 5416 | 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] | 5417 | u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5418 | { |
| 5419 | struct skb_shared_info *info = skb_shinfo(skb); |
| 5420 | unsigned int cur_frag, entry; |
Jeff Garzik | a6343af | 2007-07-17 05:39:58 -0400 | [diff] [blame] | 5421 | struct TxDesc * uninitialized_var(txd); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5422 | struct device *d = &tp->pci_dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5423 | |
| 5424 | entry = tp->cur_tx; |
| 5425 | for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5426 | const skb_frag_t *frag = info->frags + cur_frag; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5427 | dma_addr_t mapping; |
| 5428 | u32 status, len; |
| 5429 | void *addr; |
| 5430 | |
| 5431 | entry = (entry + 1) % NUM_TX_DESC; |
| 5432 | |
| 5433 | txd = tp->TxDescArray + entry; |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 5434 | len = skb_frag_size(frag); |
Ian Campbell | 929f618 | 2011-08-31 00:47:06 +0000 | [diff] [blame] | 5435 | addr = skb_frag_address(frag); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5436 | mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5437 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 5438 | if (net_ratelimit()) |
| 5439 | netif_err(tp, drv, tp->dev, |
| 5440 | "Failed to map TX fragments DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5441 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5442 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5443 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5444 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5445 | status = opts[0] | len | |
| 5446 | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5447 | |
| 5448 | txd->opts1 = cpu_to_le32(status); |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5449 | txd->opts2 = cpu_to_le32(opts[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5450 | txd->addr = cpu_to_le64(mapping); |
| 5451 | |
| 5452 | tp->tx_skb[entry].len = len; |
| 5453 | } |
| 5454 | |
| 5455 | if (cur_frag) { |
| 5456 | tp->tx_skb[entry].skb = skb; |
| 5457 | txd->opts1 |= cpu_to_le32(LastFrag); |
| 5458 | } |
| 5459 | |
| 5460 | return cur_frag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5461 | |
| 5462 | err_out: |
| 5463 | rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag); |
| 5464 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5465 | } |
| 5466 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5467 | static inline void rtl8169_tso_csum(struct rtl8169_private *tp, |
| 5468 | struct sk_buff *skb, u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5469 | { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5470 | 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] | 5471 | u32 mss = skb_shinfo(skb)->gso_size; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5472 | int offset = info->opts_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5473 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5474 | if (mss) { |
| 5475 | opts[0] |= TD_LSO; |
| 5476 | opts[offset] |= min(mss, TD_MSS_MAX) << info->mss_shift; |
| 5477 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5478 | const struct iphdr *ip = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5479 | |
| 5480 | if (ip->protocol == IPPROTO_TCP) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5481 | opts[offset] |= info->checksum.tcp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5482 | else if (ip->protocol == IPPROTO_UDP) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5483 | opts[offset] |= info->checksum.udp; |
| 5484 | else |
| 5485 | WARN_ON_ONCE(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5486 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5487 | } |
| 5488 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5489 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 5490 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5491 | { |
| 5492 | struct rtl8169_private *tp = netdev_priv(dev); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5493 | unsigned int entry = tp->cur_tx % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5494 | struct TxDesc *txd = tp->TxDescArray + entry; |
| 5495 | void __iomem *ioaddr = tp->mmio_addr; |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5496 | struct device *d = &tp->pci_dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5497 | dma_addr_t mapping; |
| 5498 | u32 status, len; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5499 | u32 opts[2]; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5500 | int frags; |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 5501 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5502 | if (unlikely(TX_BUFFS_AVAIL(tp) < skb_shinfo(skb)->nr_frags)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 5503 | 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] | 5504 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5505 | } |
| 5506 | |
| 5507 | if (unlikely(le32_to_cpu(txd->opts1) & DescOwn)) |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5508 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5509 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5510 | len = skb_headlen(skb); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5511 | mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5512 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 5513 | if (net_ratelimit()) |
| 5514 | netif_err(tp, drv, dev, "Failed to map TX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5515 | goto err_dma_0; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5516 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5517 | |
| 5518 | tp->tx_skb[entry].len = len; |
| 5519 | txd->addr = cpu_to_le64(mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5520 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5521 | opts[1] = cpu_to_le32(rtl8169_tx_vlan_tag(tp, skb)); |
| 5522 | opts[0] = DescOwn; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5523 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5524 | rtl8169_tso_csum(tp, skb, opts); |
| 5525 | |
| 5526 | frags = rtl8169_xmit_frags(tp, skb, opts); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5527 | if (frags < 0) |
| 5528 | goto err_dma_1; |
| 5529 | else if (frags) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5530 | opts[0] |= FirstFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5531 | else { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5532 | opts[0] |= FirstFrag | LastFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5533 | tp->tx_skb[entry].skb = skb; |
| 5534 | } |
| 5535 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5536 | txd->opts2 = cpu_to_le32(opts[1]); |
| 5537 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5538 | wmb(); |
| 5539 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5540 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5541 | status = opts[0] | len | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5542 | txd->opts1 = cpu_to_le32(status); |
| 5543 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5544 | tp->cur_tx += frags + 1; |
| 5545 | |
David Dillow | 4c020a9 | 2010-03-03 16:33:10 +0000 | [diff] [blame] | 5546 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5547 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5548 | RTL_W8(TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5549 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5550 | mmiowb(); |
| 5551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5552 | if (TX_BUFFS_AVAIL(tp) < MAX_SKB_FRAGS) { |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 5553 | /* Avoid wrongly optimistic queue wake-up: rtl_tx thread must |
| 5554 | * not miss a ring update when it notices a stopped queue. |
| 5555 | */ |
| 5556 | smp_wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5557 | netif_stop_queue(dev); |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 5558 | /* Sync with rtl_tx: |
| 5559 | * - publish queue status and cur_tx ring index (write barrier) |
| 5560 | * - refresh dirty_tx ring index (read barrier). |
| 5561 | * May the current thread have a pessimistic view of the ring |
| 5562 | * status and forget to wake up queue, a racing rtl_tx thread |
| 5563 | * can't. |
| 5564 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 5565 | smp_mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5566 | if (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS) |
| 5567 | netif_wake_queue(dev); |
| 5568 | } |
| 5569 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5570 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5571 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5572 | err_dma_1: |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5573 | rtl8169_unmap_tx_skb(d, tp->tx_skb + entry, txd); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5574 | err_dma_0: |
| 5575 | dev_kfree_skb(skb); |
| 5576 | dev->stats.tx_dropped++; |
| 5577 | return NETDEV_TX_OK; |
| 5578 | |
| 5579 | err_stop_0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5580 | netif_stop_queue(dev); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5581 | dev->stats.tx_dropped++; |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5582 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5583 | } |
| 5584 | |
| 5585 | static void rtl8169_pcierr_interrupt(struct net_device *dev) |
| 5586 | { |
| 5587 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5588 | struct pci_dev *pdev = tp->pci_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5589 | u16 pci_status, pci_cmd; |
| 5590 | |
| 5591 | pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); |
| 5592 | pci_read_config_word(pdev, PCI_STATUS, &pci_status); |
| 5593 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 5594 | netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n", |
| 5595 | pci_cmd, pci_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5596 | |
| 5597 | /* |
| 5598 | * The recovery sequence below admits a very elaborated explanation: |
| 5599 | * - it seems to work; |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 5600 | * - I did not see what else could be done; |
| 5601 | * - it makes iop3xx happy. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5602 | * |
| 5603 | * Feel free to adjust to your needs. |
| 5604 | */ |
Francois Romieu | a27993f | 2006-12-18 00:04:19 +0100 | [diff] [blame] | 5605 | if (pdev->broken_parity_status) |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 5606 | pci_cmd &= ~PCI_COMMAND_PARITY; |
| 5607 | else |
| 5608 | pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; |
| 5609 | |
| 5610 | pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5611 | |
| 5612 | pci_write_config_word(pdev, PCI_STATUS, |
| 5613 | pci_status & (PCI_STATUS_DETECTED_PARITY | |
| 5614 | PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT | |
| 5615 | PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT)); |
| 5616 | |
| 5617 | /* The infamous DAC f*ckup only happens at boot time */ |
| 5618 | if ((tp->cp_cmd & PCIDAC) && !tp->dirty_rx && !tp->cur_rx) { |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5619 | void __iomem *ioaddr = tp->mmio_addr; |
| 5620 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 5621 | netif_info(tp, intr, dev, "disabling PCI DAC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5622 | tp->cp_cmd &= ~PCIDAC; |
| 5623 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 5624 | dev->features &= ~NETIF_F_HIGHDMA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5625 | } |
| 5626 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5627 | rtl8169_hw_reset(tp); |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 5628 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 5629 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5630 | } |
| 5631 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5632 | static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5633 | { |
| 5634 | unsigned int dirty_tx, tx_left; |
| 5635 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5636 | dirty_tx = tp->dirty_tx; |
| 5637 | smp_rmb(); |
| 5638 | tx_left = tp->cur_tx - dirty_tx; |
| 5639 | |
| 5640 | while (tx_left > 0) { |
| 5641 | unsigned int entry = dirty_tx % NUM_TX_DESC; |
| 5642 | struct ring_info *tx_skb = tp->tx_skb + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5643 | u32 status; |
| 5644 | |
| 5645 | rmb(); |
| 5646 | status = le32_to_cpu(tp->TxDescArray[entry].opts1); |
| 5647 | if (status & DescOwn) |
| 5648 | break; |
| 5649 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5650 | rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb, |
| 5651 | tp->TxDescArray + entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5652 | if (status & LastFrag) { |
Stanislaw Gruszka | cac4b22 | 2010-10-20 22:25:40 +0000 | [diff] [blame] | 5653 | dev->stats.tx_packets++; |
| 5654 | dev->stats.tx_bytes += tx_skb->skb->len; |
Eric Dumazet | 87433bf | 2009-06-09 22:55:53 +0000 | [diff] [blame] | 5655 | dev_kfree_skb(tx_skb->skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5656 | tx_skb->skb = NULL; |
| 5657 | } |
| 5658 | dirty_tx++; |
| 5659 | tx_left--; |
| 5660 | } |
| 5661 | |
| 5662 | if (tp->dirty_tx != dirty_tx) { |
| 5663 | tp->dirty_tx = dirty_tx; |
Francois Romieu | ae1f23f | 2012-01-31 00:00:19 +0100 | [diff] [blame] | 5664 | /* Sync with rtl8169_start_xmit: |
| 5665 | * - publish dirty_tx ring index (write barrier) |
| 5666 | * - refresh cur_tx ring index and queue status (read barrier) |
| 5667 | * May the current thread miss the stopped queue condition, |
| 5668 | * a racing xmit thread can only have a right view of the |
| 5669 | * ring status. |
| 5670 | */ |
Francois Romieu | 1e874e0 | 2012-01-27 15:05:38 +0100 | [diff] [blame] | 5671 | smp_mb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5672 | if (netif_queue_stopped(dev) && |
| 5673 | (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)) { |
| 5674 | netif_wake_queue(dev); |
| 5675 | } |
Francois Romieu | d78ae2d | 2007-08-26 20:08:19 +0200 | [diff] [blame] | 5676 | /* |
| 5677 | * 8168 hack: TxPoll requests are lost when the Tx packets are |
| 5678 | * too close. Let's kick an extra TxPoll request when a burst |
| 5679 | * of start_xmit activity is detected (if it is not detected, |
| 5680 | * it is slow enough). -- FR |
| 5681 | */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5682 | if (tp->cur_tx != dirty_tx) { |
| 5683 | void __iomem *ioaddr = tp->mmio_addr; |
| 5684 | |
Francois Romieu | d78ae2d | 2007-08-26 20:08:19 +0200 | [diff] [blame] | 5685 | RTL_W8(TxPoll, NPQ); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5686 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5687 | } |
| 5688 | } |
| 5689 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 5690 | static inline int rtl8169_fragmented_frame(u32 status) |
| 5691 | { |
| 5692 | return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag); |
| 5693 | } |
| 5694 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 5695 | static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5696 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5697 | u32 status = opts1 & RxProtoMask; |
| 5698 | |
| 5699 | if (((status == RxProtoTCP) && !(opts1 & TCPFail)) || |
Shan Wei | d5d3ebe | 2010-11-12 00:15:25 +0000 | [diff] [blame] | 5700 | ((status == RxProtoUDP) && !(opts1 & UDPFail))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5701 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 5702 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 5703 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5704 | } |
| 5705 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5706 | static struct sk_buff *rtl8169_try_rx_copy(void *data, |
| 5707 | struct rtl8169_private *tp, |
| 5708 | int pkt_size, |
| 5709 | dma_addr_t addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5710 | { |
Stephen Hemminger | b449655 | 2007-06-17 01:06:49 +0200 | [diff] [blame] | 5711 | struct sk_buff *skb; |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5712 | struct device *d = &tp->pci_dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5713 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5714 | data = rtl8169_align(data); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5715 | dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5716 | prefetch(data); |
| 5717 | skb = netdev_alloc_skb_ip_align(tp->dev, pkt_size); |
| 5718 | if (skb) |
| 5719 | memcpy(skb->data, data, pkt_size); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5720 | dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE); |
| 5721 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5722 | return skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5723 | } |
| 5724 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5725 | 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] | 5726 | { |
| 5727 | unsigned int cur_rx, rx_left; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5728 | unsigned int count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5729 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5730 | cur_rx = tp->cur_rx; |
| 5731 | rx_left = NUM_RX_DESC + tp->dirty_rx - cur_rx; |
Francois Romieu | 865c652 | 2008-05-11 14:51:00 +0200 | [diff] [blame] | 5732 | rx_left = min(rx_left, budget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5733 | |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 5734 | for (; rx_left > 0; rx_left--, cur_rx++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5735 | unsigned int entry = cur_rx % NUM_RX_DESC; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 5736 | struct RxDesc *desc = tp->RxDescArray + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5737 | u32 status; |
| 5738 | |
| 5739 | rmb(); |
David S. Miller | 8decf86 | 2011-09-22 03:23:13 -0400 | [diff] [blame] | 5740 | status = le32_to_cpu(desc->opts1) & tp->opts1_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5741 | |
| 5742 | if (status & DescOwn) |
| 5743 | break; |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 5744 | if (unlikely(status & RxRES)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 5745 | netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n", |
| 5746 | status); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5747 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5748 | if (status & (RxRWT | RxRUNT)) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5749 | dev->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5750 | if (status & RxCRC) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5751 | dev->stats.rx_crc_errors++; |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 5752 | if (status & RxFOVF) { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5753 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5754 | dev->stats.rx_fifo_errors++; |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 5755 | } |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5756 | rtl8169_mark_to_asic(desc, rx_buf_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5757 | } else { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5758 | struct sk_buff *skb; |
Stephen Hemminger | b449655 | 2007-06-17 01:06:49 +0200 | [diff] [blame] | 5759 | dma_addr_t addr = le64_to_cpu(desc->addr); |
Francois Romieu | deb9d93c | 2011-07-12 08:24:28 +0200 | [diff] [blame] | 5760 | int pkt_size = (status & 0x00003fff) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5761 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 5762 | /* |
| 5763 | * The driver does not support incoming fragmented |
| 5764 | * frames. They are seen as a symptom of over-mtu |
| 5765 | * sized frames. |
| 5766 | */ |
| 5767 | if (unlikely(rtl8169_fragmented_frame(status))) { |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5768 | dev->stats.rx_dropped++; |
| 5769 | dev->stats.rx_length_errors++; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5770 | rtl8169_mark_to_asic(desc, rx_buf_sz); |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 5771 | continue; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 5772 | } |
| 5773 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5774 | skb = rtl8169_try_rx_copy(tp->Rx_databuff[entry], |
| 5775 | tp, pkt_size, addr); |
| 5776 | rtl8169_mark_to_asic(desc, rx_buf_sz); |
| 5777 | if (!skb) { |
| 5778 | dev->stats.rx_dropped++; |
| 5779 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5780 | } |
| 5781 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 5782 | rtl8169_rx_csum(skb, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5783 | skb_put(skb, pkt_size); |
| 5784 | skb->protocol = eth_type_trans(skb, dev); |
| 5785 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 5786 | rtl8169_rx_vlan_tag(desc, skb); |
| 5787 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5788 | napi_gro_receive(&tp->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5789 | |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5790 | dev->stats.rx_bytes += pkt_size; |
| 5791 | dev->stats.rx_packets++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5792 | } |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5793 | |
| 5794 | /* Work around for AMD plateform. */ |
Al Viro | 95e0918 | 2007-12-22 18:55:39 +0000 | [diff] [blame] | 5795 | if ((desc->opts2 & cpu_to_le32(0xfffe000)) && |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5796 | (tp->mac_version == RTL_GIGA_MAC_VER_05)) { |
| 5797 | desc->opts2 = 0; |
| 5798 | cur_rx++; |
| 5799 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5800 | } |
| 5801 | |
| 5802 | count = cur_rx - tp->cur_rx; |
| 5803 | tp->cur_rx = cur_rx; |
| 5804 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5805 | tp->dirty_rx += count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5806 | |
| 5807 | return count; |
| 5808 | } |
| 5809 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5810 | static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5811 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5812 | struct net_device *dev = dev_instance; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5813 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5814 | int handled = 0; |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 5815 | u16 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5816 | |
Francois Romieu | 9085cdfa | 2012-01-26 12:59:08 +0100 | [diff] [blame] | 5817 | status = rtl_get_events(tp); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5818 | if (status && status != 0xffff) { |
| 5819 | status &= RTL_EVENT_NAPI | tp->event_slow; |
| 5820 | if (status) { |
| 5821 | handled = 1; |
françois romieu | 811fd30 | 2011-12-04 20:30:45 +0000 | [diff] [blame] | 5822 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5823 | rtl_irq_disable(tp); |
| 5824 | napi_schedule(&tp->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5825 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5826 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5827 | return IRQ_RETVAL(handled); |
| 5828 | } |
| 5829 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5830 | /* |
| 5831 | * Workqueue context. |
| 5832 | */ |
| 5833 | static void rtl_slow_event_work(struct rtl8169_private *tp) |
| 5834 | { |
| 5835 | struct net_device *dev = tp->dev; |
| 5836 | u16 status; |
| 5837 | |
| 5838 | status = rtl_get_events(tp) & tp->event_slow; |
| 5839 | rtl_ack_events(tp, status); |
| 5840 | |
| 5841 | if (unlikely(status & RxFIFOOver)) { |
| 5842 | switch (tp->mac_version) { |
| 5843 | /* Work around for rx fifo overflow */ |
| 5844 | case RTL_GIGA_MAC_VER_11: |
| 5845 | netif_stop_queue(dev); |
Francois Romieu | 934714d | 2012-01-31 11:09:21 +0100 | [diff] [blame^] | 5846 | /* XXX - Hack alert. See rtl_task(). */ |
| 5847 | set_bit(RTL_FLAG_TASK_RESET_PENDING, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5848 | default: |
| 5849 | break; |
| 5850 | } |
| 5851 | } |
| 5852 | |
| 5853 | if (unlikely(status & SYSErr)) |
| 5854 | rtl8169_pcierr_interrupt(dev); |
| 5855 | |
| 5856 | if (status & LinkChg) |
| 5857 | __rtl8169_check_link_status(dev, tp, tp->mmio_addr, true); |
| 5858 | |
| 5859 | napi_disable(&tp->napi); |
| 5860 | rtl_irq_disable(tp); |
| 5861 | |
| 5862 | napi_enable(&tp->napi); |
| 5863 | napi_schedule(&tp->napi); |
| 5864 | } |
| 5865 | |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 5866 | static void rtl_task(struct work_struct *work) |
| 5867 | { |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5868 | static const struct { |
| 5869 | int bitnr; |
| 5870 | void (*action)(struct rtl8169_private *); |
| 5871 | } rtl_work[] = { |
Francois Romieu | 934714d | 2012-01-31 11:09:21 +0100 | [diff] [blame^] | 5872 | /* XXX - keep rtl_slow_event_work() as first element. */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5873 | { RTL_FLAG_TASK_SLOW_PENDING, rtl_slow_event_work }, |
| 5874 | { RTL_FLAG_TASK_RESET_PENDING, rtl_reset_work }, |
| 5875 | { RTL_FLAG_TASK_PHY_PENDING, rtl_phy_work } |
| 5876 | }; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 5877 | struct rtl8169_private *tp = |
| 5878 | container_of(work, struct rtl8169_private, wk.work); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5879 | struct net_device *dev = tp->dev; |
| 5880 | int i; |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 5881 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5882 | rtl_lock_work(tp); |
| 5883 | |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 5884 | if (!netif_running(dev) || |
| 5885 | !test_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags)) |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5886 | goto out_unlock; |
| 5887 | |
| 5888 | for (i = 0; i < ARRAY_SIZE(rtl_work); i++) { |
| 5889 | bool pending; |
| 5890 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5891 | pending = test_and_clear_bit(rtl_work[i].bitnr, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5892 | if (pending) |
| 5893 | rtl_work[i].action(tp); |
| 5894 | } |
| 5895 | |
| 5896 | out_unlock: |
| 5897 | rtl_unlock_work(tp); |
Francois Romieu | 4422bcd | 2012-01-26 11:23:32 +0100 | [diff] [blame] | 5898 | } |
| 5899 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5900 | static int rtl8169_poll(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5901 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5902 | struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); |
| 5903 | struct net_device *dev = tp->dev; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5904 | u16 enable_mask = RTL_EVENT_NAPI | tp->event_slow; |
| 5905 | int work_done= 0; |
| 5906 | u16 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5907 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5908 | status = rtl_get_events(tp); |
| 5909 | rtl_ack_events(tp, status & ~tp->event_slow); |
| 5910 | |
| 5911 | if (status & RTL_EVENT_NAPI_RX) |
| 5912 | work_done = rtl_rx(dev, tp, (u32) budget); |
| 5913 | |
| 5914 | if (status & RTL_EVENT_NAPI_TX) |
| 5915 | rtl_tx(dev, tp); |
| 5916 | |
| 5917 | if (status & tp->event_slow) { |
| 5918 | enable_mask &= ~tp->event_slow; |
| 5919 | |
| 5920 | rtl_schedule_task(tp, RTL_FLAG_TASK_SLOW_PENDING); |
| 5921 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5922 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5923 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 5924 | napi_complete(napi); |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 5925 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5926 | rtl_irq_enable(tp, enable_mask); |
| 5927 | mmiowb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5928 | } |
| 5929 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5930 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5931 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5932 | |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 5933 | static void rtl8169_rx_missed(struct net_device *dev, void __iomem *ioaddr) |
| 5934 | { |
| 5935 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5936 | |
| 5937 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) |
| 5938 | return; |
| 5939 | |
| 5940 | dev->stats.rx_missed_errors += (RTL_R32(RxMissed) & 0xffffff); |
| 5941 | RTL_W32(RxMissed, 0); |
| 5942 | } |
| 5943 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5944 | static void rtl8169_down(struct net_device *dev) |
| 5945 | { |
| 5946 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5947 | void __iomem *ioaddr = tp->mmio_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5948 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 5949 | del_timer_sync(&tp->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5950 | |
Stephen Hemminger | 93dd79e | 2007-10-28 17:14:06 +0100 | [diff] [blame] | 5951 | napi_disable(&tp->napi); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5952 | netif_stop_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5953 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5954 | rtl8169_hw_reset(tp); |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 5955 | /* |
| 5956 | * At this point device interrupts can not be enabled in any function, |
Francois Romieu | 209e5ac | 2012-01-26 09:59:50 +0100 | [diff] [blame] | 5957 | * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task) |
| 5958 | * and napi is disabled (rtl8169_poll). |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 5959 | */ |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 5960 | rtl8169_rx_missed(dev, ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5961 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5962 | /* Give a racing hard_start_xmit a few cycles to complete. */ |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5963 | synchronize_sched(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5964 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5965 | rtl8169_tx_clear(tp); |
| 5966 | |
| 5967 | rtl8169_rx_clear(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5968 | |
| 5969 | rtl_pll_power_down(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5970 | } |
| 5971 | |
| 5972 | static int rtl8169_close(struct net_device *dev) |
| 5973 | { |
| 5974 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5975 | struct pci_dev *pdev = tp->pci_dev; |
| 5976 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 5977 | pm_runtime_get_sync(&pdev->dev); |
| 5978 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5979 | /* Update counters before going down */ |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 5980 | rtl8169_update_counters(dev); |
| 5981 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5982 | rtl_lock_work(tp); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 5983 | clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5984 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5985 | rtl8169_down(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 5986 | rtl_unlock_work(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5987 | |
| 5988 | free_irq(dev->irq, dev); |
| 5989 | |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 5990 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 5991 | tp->RxPhyAddr); |
| 5992 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 5993 | tp->TxPhyAddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5994 | tp->TxDescArray = NULL; |
| 5995 | tp->RxDescArray = NULL; |
| 5996 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 5997 | pm_runtime_put_sync(&pdev->dev); |
| 5998 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5999 | return 0; |
| 6000 | } |
| 6001 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 6002 | static void rtl_set_rx_mode(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6003 | { |
| 6004 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6005 | void __iomem *ioaddr = tp->mmio_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6006 | u32 mc_filter[2]; /* Multicast hash filter */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 6007 | int rx_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6008 | u32 tmp = 0; |
| 6009 | |
| 6010 | if (dev->flags & IFF_PROMISC) { |
| 6011 | /* Unconditionally log net taps. */ |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 6012 | netif_notice(tp, link, dev, "Promiscuous mode enabled\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6013 | rx_mode = |
| 6014 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys | |
| 6015 | AcceptAllPhys; |
| 6016 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 6017 | } else if ((netdev_mc_count(dev) > multicast_filter_limit) || |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 6018 | (dev->flags & IFF_ALLMULTI)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6019 | /* Too many to filter perfectly -- accept all multicasts. */ |
| 6020 | rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; |
| 6021 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 6022 | } else { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 6023 | struct netdev_hw_addr *ha; |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 6024 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6025 | rx_mode = AcceptBroadcast | AcceptMyPhys; |
| 6026 | mc_filter[1] = mc_filter[0] = 0; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 6027 | netdev_for_each_mc_addr(ha, dev) { |
| 6028 | int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6029 | mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); |
| 6030 | rx_mode |= AcceptMulticast; |
| 6031 | } |
| 6032 | } |
| 6033 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6034 | spin_lock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6035 | |
Francois Romieu | 1687b56 | 2011-07-19 17:21:29 +0200 | [diff] [blame] | 6036 | tmp = (RTL_R32(RxConfig) & ~RX_CONFIG_ACCEPT_MASK) | rx_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6037 | |
Francois Romieu | f887cce | 2008-07-17 22:24:18 +0200 | [diff] [blame] | 6038 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) { |
Francois Romieu | 1087f4f | 2007-12-26 22:46:05 +0100 | [diff] [blame] | 6039 | u32 data = mc_filter[0]; |
| 6040 | |
| 6041 | mc_filter[0] = swab32(mc_filter[1]); |
| 6042 | mc_filter[1] = swab32(data); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 6043 | } |
| 6044 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6045 | RTL_W32(MAR0 + 4, mc_filter[1]); |
Francois Romieu | 78f1cd0 | 2010-03-27 19:35:46 -0700 | [diff] [blame] | 6046 | RTL_W32(MAR0 + 0, mc_filter[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6047 | |
Francois Romieu | 57a9f23 | 2007-06-04 22:10:15 +0200 | [diff] [blame] | 6048 | RTL_W32(RxConfig, tmp); |
| 6049 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6050 | spin_unlock_bh(&tp->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6051 | } |
| 6052 | |
| 6053 | /** |
| 6054 | * rtl8169_get_stats - Get rtl8169 read/write statistics |
| 6055 | * @dev: The Ethernet Device to get statistics for |
| 6056 | * |
| 6057 | * Get TX/RX statistics for rtl8169 |
| 6058 | */ |
| 6059 | static struct net_device_stats *rtl8169_get_stats(struct net_device *dev) |
| 6060 | { |
| 6061 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6062 | void __iomem *ioaddr = tp->mmio_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6063 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6064 | if (netif_running(dev)) |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 6065 | rtl8169_rx_missed(dev, ioaddr); |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 6066 | |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 6067 | return &dev->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6068 | } |
| 6069 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6070 | static void rtl8169_net_suspend(struct net_device *dev) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6071 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6072 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6073 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6074 | if (!netif_running(dev)) |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6075 | return; |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6076 | |
| 6077 | netif_device_detach(dev); |
| 6078 | netif_stop_queue(dev); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6079 | |
| 6080 | rtl_lock_work(tp); |
| 6081 | napi_disable(&tp->napi); |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 6082 | clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6083 | rtl_unlock_work(tp); |
| 6084 | |
| 6085 | rtl_pll_power_down(tp); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6086 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6087 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6088 | #ifdef CONFIG_PM |
| 6089 | |
| 6090 | static int rtl8169_suspend(struct device *device) |
| 6091 | { |
| 6092 | struct pci_dev *pdev = to_pci_dev(device); |
| 6093 | struct net_device *dev = pci_get_drvdata(pdev); |
| 6094 | |
| 6095 | rtl8169_net_suspend(dev); |
Francois Romieu | 1371fa6 | 2007-04-02 23:01:11 +0200 | [diff] [blame] | 6096 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6097 | return 0; |
| 6098 | } |
| 6099 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6100 | static void __rtl8169_resume(struct net_device *dev) |
| 6101 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6102 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6103 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6104 | netif_device_attach(dev); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 6105 | |
| 6106 | rtl_pll_power_up(tp); |
| 6107 | |
Francois Romieu | 6c4a70c | 2012-01-31 10:56:44 +0100 | [diff] [blame] | 6108 | set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6109 | |
Francois Romieu | 98ddf98 | 2012-01-31 10:47:34 +0100 | [diff] [blame] | 6110 | rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6111 | } |
| 6112 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6113 | static int rtl8169_resume(struct device *device) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6114 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6115 | struct pci_dev *pdev = to_pci_dev(device); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6116 | struct net_device *dev = pci_get_drvdata(pdev); |
Stanislaw Gruszka | fccec10 | 2010-10-20 22:25:42 +0000 | [diff] [blame] | 6117 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6118 | |
| 6119 | rtl8169_init_phy(dev, tp); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6120 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6121 | if (netif_running(dev)) |
| 6122 | __rtl8169_resume(dev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6123 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6124 | return 0; |
| 6125 | } |
| 6126 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6127 | static int rtl8169_runtime_suspend(struct device *device) |
| 6128 | { |
| 6129 | struct pci_dev *pdev = to_pci_dev(device); |
| 6130 | struct net_device *dev = pci_get_drvdata(pdev); |
| 6131 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6132 | |
| 6133 | if (!tp->TxDescArray) |
| 6134 | return 0; |
| 6135 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6136 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6137 | tp->saved_wolopts = __rtl8169_get_wol(tp); |
| 6138 | __rtl8169_set_wol(tp, WAKE_ANY); |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6139 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6140 | |
| 6141 | rtl8169_net_suspend(dev); |
| 6142 | |
| 6143 | return 0; |
| 6144 | } |
| 6145 | |
| 6146 | static int rtl8169_runtime_resume(struct device *device) |
| 6147 | { |
| 6148 | struct pci_dev *pdev = to_pci_dev(device); |
| 6149 | struct net_device *dev = pci_get_drvdata(pdev); |
| 6150 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6151 | |
| 6152 | if (!tp->TxDescArray) |
| 6153 | return 0; |
| 6154 | |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6155 | rtl_lock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6156 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
| 6157 | tp->saved_wolopts = 0; |
Francois Romieu | da78dbf | 2012-01-26 14:18:23 +0100 | [diff] [blame] | 6158 | rtl_unlock_work(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6159 | |
Stanislaw Gruszka | fccec10 | 2010-10-20 22:25:42 +0000 | [diff] [blame] | 6160 | rtl8169_init_phy(dev, tp); |
| 6161 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6162 | __rtl8169_resume(dev); |
| 6163 | |
| 6164 | return 0; |
| 6165 | } |
| 6166 | |
| 6167 | static int rtl8169_runtime_idle(struct device *device) |
| 6168 | { |
| 6169 | struct pci_dev *pdev = to_pci_dev(device); |
| 6170 | struct net_device *dev = pci_get_drvdata(pdev); |
| 6171 | struct rtl8169_private *tp = netdev_priv(dev); |
| 6172 | |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 6173 | return tp->TxDescArray ? -EBUSY : 0; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 6174 | } |
| 6175 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 6176 | static const struct dev_pm_ops rtl8169_pm_ops = { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6177 | .suspend = rtl8169_suspend, |
| 6178 | .resume = rtl8169_resume, |
| 6179 | .freeze = rtl8169_suspend, |
| 6180 | .thaw = rtl8169_resume, |
| 6181 | .poweroff = rtl8169_suspend, |
| 6182 | .restore = rtl8169_resume, |
| 6183 | .runtime_suspend = rtl8169_runtime_suspend, |
| 6184 | .runtime_resume = rtl8169_runtime_resume, |
| 6185 | .runtime_idle = rtl8169_runtime_idle, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6186 | }; |
| 6187 | |
| 6188 | #define RTL8169_PM_OPS (&rtl8169_pm_ops) |
| 6189 | |
| 6190 | #else /* !CONFIG_PM */ |
| 6191 | |
| 6192 | #define RTL8169_PM_OPS NULL |
| 6193 | |
| 6194 | #endif /* !CONFIG_PM */ |
| 6195 | |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6196 | static void rtl_wol_shutdown_quirk(struct rtl8169_private *tp) |
| 6197 | { |
| 6198 | void __iomem *ioaddr = tp->mmio_addr; |
| 6199 | |
| 6200 | /* WoL fails with 8168b when the receiver is disabled. */ |
| 6201 | switch (tp->mac_version) { |
| 6202 | case RTL_GIGA_MAC_VER_11: |
| 6203 | case RTL_GIGA_MAC_VER_12: |
| 6204 | case RTL_GIGA_MAC_VER_17: |
| 6205 | pci_clear_master(tp->pci_dev); |
| 6206 | |
| 6207 | RTL_W8(ChipCmd, CmdRxEnb); |
| 6208 | /* PCI commit */ |
| 6209 | RTL_R8(ChipCmd); |
| 6210 | break; |
| 6211 | default: |
| 6212 | break; |
| 6213 | } |
| 6214 | } |
| 6215 | |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 6216 | static void rtl_shutdown(struct pci_dev *pdev) |
| 6217 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6218 | struct net_device *dev = pci_get_drvdata(pdev); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 6219 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 6220 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6221 | rtl8169_net_suspend(dev); |
| 6222 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 6223 | /* Restore original MAC address */ |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 6224 | rtl_rar_set(tp, dev->perm_addr); |
| 6225 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 6226 | rtl8169_hw_reset(tp); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 6227 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6228 | if (system_state == SYSTEM_POWER_OFF) { |
David S. Miller | 1805b2f | 2011-10-24 18:18:09 -0400 | [diff] [blame] | 6229 | if (__rtl8169_get_wol(tp) & WAKE_ANY) { |
| 6230 | rtl_wol_suspend_quirk(tp); |
| 6231 | rtl_wol_shutdown_quirk(tp); |
françois romieu | ca52efd | 2009-07-24 12:34:19 +0000 | [diff] [blame] | 6232 | } |
| 6233 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6234 | pci_wake_from_d3(pdev, true); |
| 6235 | pci_set_power_state(pdev, PCI_D3hot); |
| 6236 | } |
| 6237 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 6238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6239 | static struct pci_driver rtl8169_pci_driver = { |
| 6240 | .name = MODULENAME, |
| 6241 | .id_table = rtl8169_pci_tbl, |
| 6242 | .probe = rtl8169_init_one, |
| 6243 | .remove = __devexit_p(rtl8169_remove_one), |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 6244 | .shutdown = rtl_shutdown, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 6245 | .driver.pm = RTL8169_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6246 | }; |
| 6247 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 6248 | static int __init rtl8169_init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6249 | { |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 6250 | return pci_register_driver(&rtl8169_pci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6251 | } |
| 6252 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 6253 | static void __exit rtl8169_cleanup_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6254 | { |
| 6255 | pci_unregister_driver(&rtl8169_pci_driver); |
| 6256 | } |
| 6257 | |
| 6258 | module_init(rtl8169_init_module); |
| 6259 | module_exit(rtl8169_cleanup_module); |