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 | 99f252b0 | 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 | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 45 | #define FIRMWARE_8105E_1 "rtl_nic/rtl8105e-1.fw" |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 46 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | #ifdef RTL8169_DEBUG |
| 48 | #define assert(expr) \ |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 49 | if (!(expr)) { \ |
| 50 | printk( "Assertion failed! %s,%s,%s,line=%d\n", \ |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 51 | #expr,__FILE__,__func__,__LINE__); \ |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 52 | } |
Joe Perches | 06fa735 | 2007-10-18 21:15:00 +0200 | [diff] [blame] | 53 | #define dprintk(fmt, args...) \ |
| 54 | do { printk(KERN_DEBUG PFX fmt, ## args); } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #else |
| 56 | #define assert(expr) do {} while (0) |
| 57 | #define dprintk(fmt, args...) do {} while (0) |
| 58 | #endif /* RTL8169_DEBUG */ |
| 59 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 60 | #define R8169_MSG_DEFAULT \ |
Francois Romieu | f0e837d | 2005-09-30 16:54:02 -0700 | [diff] [blame] | 61 | (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN) |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | #define TX_BUFFS_AVAIL(tp) \ |
| 64 | (tp->dirty_tx + NUM_TX_DESC - tp->cur_tx - 1) |
| 65 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). |
| 67 | 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] | 68 | static const int multicast_filter_limit = 32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | /* MAC address length */ |
| 71 | #define MAC_ADDR_LEN 6 |
| 72 | |
Francois Romieu | 9c14cea | 2008-07-05 00:21:15 +0200 | [diff] [blame] | 73 | #define MAX_READ_REQUEST_SHIFT 12 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #define TX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | #define SafeMtu 0x1c20 /* ... actually life sucks beyond ~7k */ |
| 76 | #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */ |
| 77 | |
| 78 | #define R8169_REGS_SIZE 256 |
| 79 | #define R8169_NAPI_WEIGHT 64 |
| 80 | #define NUM_TX_DESC 64 /* Number of Tx descriptor registers */ |
| 81 | #define NUM_RX_DESC 256 /* Number of Rx descriptor registers */ |
| 82 | #define RX_BUF_SIZE 1536 /* Rx Buffer size */ |
| 83 | #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc)) |
| 84 | #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc)) |
| 85 | |
| 86 | #define RTL8169_TX_TIMEOUT (6*HZ) |
| 87 | #define RTL8169_PHY_TIMEOUT (10*HZ) |
| 88 | |
françois romieu | ea8dbdd | 2009-03-15 01:10:50 +0000 | [diff] [blame] | 89 | #define RTL_EEPROM_SIG cpu_to_le32(0x8129) |
| 90 | #define RTL_EEPROM_SIG_MASK cpu_to_le32(0xffff) |
Francois Romieu | e1564ec | 2008-10-16 22:46:13 +0200 | [diff] [blame] | 91 | #define RTL_EEPROM_SIG_ADDR 0x0000 |
| 92 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | /* write/read MMIO register */ |
| 94 | #define RTL_W8(reg, val8) writeb ((val8), ioaddr + (reg)) |
| 95 | #define RTL_W16(reg, val16) writew ((val16), ioaddr + (reg)) |
| 96 | #define RTL_W32(reg, val32) writel ((val32), ioaddr + (reg)) |
| 97 | #define RTL_R8(reg) readb (ioaddr + (reg)) |
| 98 | #define RTL_R16(reg) readw (ioaddr + (reg)) |
Junchang Wang | 06f555f | 2010-05-30 02:26:07 +0000 | [diff] [blame] | 99 | #define RTL_R32(reg) readl (ioaddr + (reg)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | |
| 101 | enum mac_version { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 102 | RTL_GIGA_MAC_VER_01 = 0, |
| 103 | RTL_GIGA_MAC_VER_02, |
| 104 | RTL_GIGA_MAC_VER_03, |
| 105 | RTL_GIGA_MAC_VER_04, |
| 106 | RTL_GIGA_MAC_VER_05, |
| 107 | RTL_GIGA_MAC_VER_06, |
| 108 | RTL_GIGA_MAC_VER_07, |
| 109 | RTL_GIGA_MAC_VER_08, |
| 110 | RTL_GIGA_MAC_VER_09, |
| 111 | RTL_GIGA_MAC_VER_10, |
| 112 | RTL_GIGA_MAC_VER_11, |
| 113 | RTL_GIGA_MAC_VER_12, |
| 114 | RTL_GIGA_MAC_VER_13, |
| 115 | RTL_GIGA_MAC_VER_14, |
| 116 | RTL_GIGA_MAC_VER_15, |
| 117 | RTL_GIGA_MAC_VER_16, |
| 118 | RTL_GIGA_MAC_VER_17, |
| 119 | RTL_GIGA_MAC_VER_18, |
| 120 | RTL_GIGA_MAC_VER_19, |
| 121 | RTL_GIGA_MAC_VER_20, |
| 122 | RTL_GIGA_MAC_VER_21, |
| 123 | RTL_GIGA_MAC_VER_22, |
| 124 | RTL_GIGA_MAC_VER_23, |
| 125 | RTL_GIGA_MAC_VER_24, |
| 126 | RTL_GIGA_MAC_VER_25, |
| 127 | RTL_GIGA_MAC_VER_26, |
| 128 | RTL_GIGA_MAC_VER_27, |
| 129 | RTL_GIGA_MAC_VER_28, |
| 130 | RTL_GIGA_MAC_VER_29, |
| 131 | RTL_GIGA_MAC_VER_30, |
| 132 | RTL_GIGA_MAC_VER_31, |
| 133 | RTL_GIGA_MAC_VER_32, |
| 134 | RTL_GIGA_MAC_VER_33, |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 135 | RTL_GIGA_MAC_VER_34, |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 136 | RTL_GIGA_MAC_NONE = 0xff, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | }; |
| 138 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 139 | enum rtl_tx_desc_version { |
| 140 | RTL_TD_0 = 0, |
| 141 | RTL_TD_1 = 1, |
| 142 | }; |
| 143 | |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 144 | #define _R(NAME,TD,FW) \ |
| 145 | { .name = NAME, .txd_version = TD, .fw_name = FW } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
Jesper Juhl | 3c6bee1 | 2006-01-09 20:54:01 -0800 | [diff] [blame] | 147 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | const char *name; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 149 | enum rtl_tx_desc_version txd_version; |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 150 | const char *fw_name; |
| 151 | } rtl_chip_infos[] = { |
| 152 | /* PCI devices. */ |
| 153 | [RTL_GIGA_MAC_VER_01] = |
| 154 | _R("RTL8169", RTL_TD_0, NULL), |
| 155 | [RTL_GIGA_MAC_VER_02] = |
| 156 | _R("RTL8169s", RTL_TD_0, NULL), |
| 157 | [RTL_GIGA_MAC_VER_03] = |
| 158 | _R("RTL8110s", RTL_TD_0, NULL), |
| 159 | [RTL_GIGA_MAC_VER_04] = |
| 160 | _R("RTL8169sb/8110sb", RTL_TD_0, NULL), |
| 161 | [RTL_GIGA_MAC_VER_05] = |
| 162 | _R("RTL8169sc/8110sc", RTL_TD_0, NULL), |
| 163 | [RTL_GIGA_MAC_VER_06] = |
| 164 | _R("RTL8169sc/8110sc", RTL_TD_0, NULL), |
| 165 | /* PCI-E devices. */ |
| 166 | [RTL_GIGA_MAC_VER_07] = |
| 167 | _R("RTL8102e", RTL_TD_1, NULL), |
| 168 | [RTL_GIGA_MAC_VER_08] = |
| 169 | _R("RTL8102e", RTL_TD_1, NULL), |
| 170 | [RTL_GIGA_MAC_VER_09] = |
| 171 | _R("RTL8102e", RTL_TD_1, NULL), |
| 172 | [RTL_GIGA_MAC_VER_10] = |
| 173 | _R("RTL8101e", RTL_TD_0, NULL), |
| 174 | [RTL_GIGA_MAC_VER_11] = |
| 175 | _R("RTL8168b/8111b", RTL_TD_0, NULL), |
| 176 | [RTL_GIGA_MAC_VER_12] = |
| 177 | _R("RTL8168b/8111b", RTL_TD_0, NULL), |
| 178 | [RTL_GIGA_MAC_VER_13] = |
| 179 | _R("RTL8101e", RTL_TD_0, NULL), |
| 180 | [RTL_GIGA_MAC_VER_14] = |
| 181 | _R("RTL8100e", RTL_TD_0, NULL), |
| 182 | [RTL_GIGA_MAC_VER_15] = |
| 183 | _R("RTL8100e", RTL_TD_0, NULL), |
| 184 | [RTL_GIGA_MAC_VER_16] = |
| 185 | _R("RTL8101e", RTL_TD_0, NULL), |
| 186 | [RTL_GIGA_MAC_VER_17] = |
| 187 | _R("RTL8168b/8111b", RTL_TD_0, NULL), |
| 188 | [RTL_GIGA_MAC_VER_18] = |
| 189 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL), |
| 190 | [RTL_GIGA_MAC_VER_19] = |
| 191 | _R("RTL8168c/8111c", RTL_TD_1, NULL), |
| 192 | [RTL_GIGA_MAC_VER_20] = |
| 193 | _R("RTL8168c/8111c", RTL_TD_1, NULL), |
| 194 | [RTL_GIGA_MAC_VER_21] = |
| 195 | _R("RTL8168c/8111c", RTL_TD_1, NULL), |
| 196 | [RTL_GIGA_MAC_VER_22] = |
| 197 | _R("RTL8168c/8111c", RTL_TD_1, NULL), |
| 198 | [RTL_GIGA_MAC_VER_23] = |
| 199 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL), |
| 200 | [RTL_GIGA_MAC_VER_24] = |
| 201 | _R("RTL8168cp/8111cp", RTL_TD_1, NULL), |
| 202 | [RTL_GIGA_MAC_VER_25] = |
| 203 | _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_1), |
| 204 | [RTL_GIGA_MAC_VER_26] = |
| 205 | _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_2), |
| 206 | [RTL_GIGA_MAC_VER_27] = |
| 207 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL), |
| 208 | [RTL_GIGA_MAC_VER_28] = |
| 209 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL), |
| 210 | [RTL_GIGA_MAC_VER_29] = |
| 211 | _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1), |
| 212 | [RTL_GIGA_MAC_VER_30] = |
| 213 | _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1), |
| 214 | [RTL_GIGA_MAC_VER_31] = |
| 215 | _R("RTL8168dp/8111dp", RTL_TD_1, NULL), |
| 216 | [RTL_GIGA_MAC_VER_32] = |
| 217 | _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_1), |
| 218 | [RTL_GIGA_MAC_VER_33] = |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 219 | _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_2), |
| 220 | [RTL_GIGA_MAC_VER_34] = |
| 221 | _R("RTL8168evl/8111evl",RTL_TD_1, FIRMWARE_8168E_3) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 222 | }; |
| 223 | #undef _R |
| 224 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 225 | enum cfg_version { |
| 226 | RTL_CFG_0 = 0x00, |
| 227 | RTL_CFG_1, |
| 228 | RTL_CFG_2 |
| 229 | }; |
| 230 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 231 | static void rtl_hw_start_8169(struct net_device *); |
| 232 | static void rtl_hw_start_8168(struct net_device *); |
| 233 | static void rtl_hw_start_8101(struct net_device *); |
| 234 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 235 | static DEFINE_PCI_DEVICE_TABLE(rtl8169_pci_tbl) = { |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 236 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 }, |
Francois Romieu | d2eed8c | 2006-08-31 22:01:07 +0200 | [diff] [blame] | 237 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8136), 0, 0, RTL_CFG_2 }, |
Francois Romieu | d81bf55 | 2006-09-20 21:31:20 +0200 | [diff] [blame] | 238 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_0 }, |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 239 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_1 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 240 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 }, |
| 241 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4300), 0, 0, RTL_CFG_0 }, |
Lennart Sorensen | 93a3aa2 | 2011-07-28 13:18:11 +0000 | [diff] [blame] | 242 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4302), 0, 0, RTL_CFG_0 }, |
Francois Romieu | bc1660b | 2007-10-12 23:58:09 +0200 | [diff] [blame] | 243 | { PCI_DEVICE(PCI_VENDOR_ID_AT, 0xc107), 0, 0, RTL_CFG_0 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 244 | { PCI_DEVICE(0x16ec, 0x0116), 0, 0, RTL_CFG_0 }, |
| 245 | { PCI_VENDOR_ID_LINKSYS, 0x1032, |
| 246 | PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 }, |
Ciaran McCreesh | 11d2e28 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 247 | { 0x0001, 0x8168, |
| 248 | PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | {0,}, |
| 250 | }; |
| 251 | |
| 252 | MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl); |
| 253 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 254 | static int rx_buf_sz = 16383; |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 255 | static int use_dac; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 256 | static struct { |
| 257 | u32 msg_enable; |
| 258 | } debug = { -1 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 260 | enum rtl_registers { |
| 261 | MAC0 = 0, /* Ethernet hardware address. */ |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 262 | MAC4 = 4, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 263 | MAR0 = 8, /* Multicast filter. */ |
| 264 | CounterAddrLow = 0x10, |
| 265 | CounterAddrHigh = 0x14, |
| 266 | TxDescStartAddrLow = 0x20, |
| 267 | TxDescStartAddrHigh = 0x24, |
| 268 | TxHDescStartAddrLow = 0x28, |
| 269 | TxHDescStartAddrHigh = 0x2c, |
| 270 | FLASH = 0x30, |
| 271 | ERSR = 0x36, |
| 272 | ChipCmd = 0x37, |
| 273 | TxPoll = 0x38, |
| 274 | IntrMask = 0x3c, |
| 275 | IntrStatus = 0x3e, |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 276 | |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 277 | TxConfig = 0x40, |
| 278 | #define TXCFG_AUTO_FIFO (1 << 7) /* 8111e-vl */ |
| 279 | #define TXCFG_EMPTY (1 << 11) /* 8111e-vl */ |
| 280 | |
| 281 | RxConfig = 0x44, |
| 282 | #define RX128_INT_EN (1 << 15) /* 8111c and later */ |
| 283 | #define RX_MULTI_EN (1 << 14) /* 8111c only */ |
| 284 | #define RXCFG_FIFO_SHIFT 13 |
| 285 | /* No threshold before first PCI xfer */ |
| 286 | #define RX_FIFO_THRESH (7 << RXCFG_FIFO_SHIFT) |
| 287 | #define RXCFG_DMA_SHIFT 8 |
| 288 | /* Unlimited maximum PCI burst. */ |
| 289 | #define RX_DMA_BURST (7 << RXCFG_DMA_SHIFT) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 290 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 291 | RxMissed = 0x4c, |
| 292 | Cfg9346 = 0x50, |
| 293 | Config0 = 0x51, |
| 294 | Config1 = 0x52, |
| 295 | Config2 = 0x53, |
| 296 | Config3 = 0x54, |
| 297 | Config4 = 0x55, |
| 298 | Config5 = 0x56, |
| 299 | MultiIntr = 0x5c, |
| 300 | PHYAR = 0x60, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 301 | PHYstatus = 0x6c, |
| 302 | RxMaxSize = 0xda, |
| 303 | CPlusCmd = 0xe0, |
| 304 | IntrMitigate = 0xe2, |
| 305 | RxDescAddrLow = 0xe4, |
| 306 | RxDescAddrHigh = 0xe8, |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 307 | EarlyTxThres = 0xec, /* 8169. Unit of 32 bytes. */ |
| 308 | |
| 309 | #define NoEarlyTx 0x3f /* Max value : no early transmit. */ |
| 310 | |
| 311 | MaxTxPacketSize = 0xec, /* 8101/8168. Unit of 128 bytes. */ |
| 312 | |
| 313 | #define TxPacketMax (8064 >> 7) |
| 314 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 315 | FuncEvent = 0xf0, |
| 316 | FuncEventMask = 0xf4, |
| 317 | FuncPresetState = 0xf8, |
| 318 | FuncForceEvent = 0xfc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | }; |
| 320 | |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 321 | enum rtl8110_registers { |
| 322 | TBICSR = 0x64, |
| 323 | TBI_ANAR = 0x68, |
| 324 | TBI_LPAR = 0x6a, |
| 325 | }; |
| 326 | |
| 327 | enum rtl8168_8101_registers { |
| 328 | CSIDR = 0x64, |
| 329 | CSIAR = 0x68, |
| 330 | #define CSIAR_FLAG 0x80000000 |
| 331 | #define CSIAR_WRITE_CMD 0x80000000 |
| 332 | #define CSIAR_BYTE_ENABLE 0x0f |
| 333 | #define CSIAR_BYTE_ENABLE_SHIFT 12 |
| 334 | #define CSIAR_ADDR_MASK 0x0fff |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 335 | PMCH = 0x6f, |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 336 | EPHYAR = 0x80, |
| 337 | #define EPHYAR_FLAG 0x80000000 |
| 338 | #define EPHYAR_WRITE_CMD 0x80000000 |
| 339 | #define EPHYAR_REG_MASK 0x1f |
| 340 | #define EPHYAR_REG_SHIFT 16 |
| 341 | #define EPHYAR_DATA_MASK 0xffff |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 342 | DLLPR = 0xd0, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 343 | #define PFM_EN (1 << 6) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 344 | DBG_REG = 0xd1, |
| 345 | #define FIX_NAK_1 (1 << 4) |
| 346 | #define FIX_NAK_2 (1 << 3) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 347 | TWSI = 0xd2, |
| 348 | MCU = 0xd3, |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 349 | #define NOW_IS_OOB (1 << 7) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 350 | #define EN_NDP (1 << 3) |
| 351 | #define EN_OOB_RESET (1 << 2) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 352 | EFUSEAR = 0xdc, |
| 353 | #define EFUSEAR_FLAG 0x80000000 |
| 354 | #define EFUSEAR_WRITE_CMD 0x80000000 |
| 355 | #define EFUSEAR_READ_CMD 0x00000000 |
| 356 | #define EFUSEAR_REG_MASK 0x03ff |
| 357 | #define EFUSEAR_REG_SHIFT 8 |
| 358 | #define EFUSEAR_DATA_MASK 0xff |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 359 | }; |
| 360 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 361 | enum rtl8168_registers { |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 362 | LED_FREQ = 0x1a, |
| 363 | EEE_LED = 0x1b, |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 364 | ERIDR = 0x70, |
| 365 | ERIAR = 0x74, |
| 366 | #define ERIAR_FLAG 0x80000000 |
| 367 | #define ERIAR_WRITE_CMD 0x80000000 |
| 368 | #define ERIAR_READ_CMD 0x00000000 |
| 369 | #define ERIAR_ADDR_BYTE_ALIGN 4 |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 370 | #define ERIAR_TYPE_SHIFT 16 |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 371 | #define ERIAR_EXGMAC (0x00 << ERIAR_TYPE_SHIFT) |
| 372 | #define ERIAR_MSIX (0x01 << ERIAR_TYPE_SHIFT) |
| 373 | #define ERIAR_ASF (0x02 << ERIAR_TYPE_SHIFT) |
| 374 | #define ERIAR_MASK_SHIFT 12 |
| 375 | #define ERIAR_MASK_0001 (0x1 << ERIAR_MASK_SHIFT) |
| 376 | #define ERIAR_MASK_0011 (0x3 << ERIAR_MASK_SHIFT) |
| 377 | #define ERIAR_MASK_1111 (0xf << ERIAR_MASK_SHIFT) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 378 | EPHY_RXER_NUM = 0x7c, |
| 379 | OCPDR = 0xb0, /* OCP GPHY access */ |
| 380 | #define OCPDR_WRITE_CMD 0x80000000 |
| 381 | #define OCPDR_READ_CMD 0x00000000 |
| 382 | #define OCPDR_REG_MASK 0x7f |
| 383 | #define OCPDR_GPHY_REG_SHIFT 16 |
| 384 | #define OCPDR_DATA_MASK 0xffff |
| 385 | OCPAR = 0xb4, |
| 386 | #define OCPAR_FLAG 0x80000000 |
| 387 | #define OCPAR_GPHY_WRITE_CMD 0x8000f060 |
| 388 | #define OCPAR_GPHY_READ_CMD 0x0000f060 |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 389 | RDSAR1 = 0xd0, /* 8168c only. Undocumented on 8168dp */ |
| 390 | MISC = 0xf0, /* 8168e only. */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 391 | #define TXPLA_RST (1 << 29) |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 392 | #define PWM_EN (1 << 22) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 393 | }; |
| 394 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 395 | enum rtl_register_content { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | /* InterruptStatusBits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 397 | SYSErr = 0x8000, |
| 398 | PCSTimeout = 0x4000, |
| 399 | SWInt = 0x0100, |
| 400 | TxDescUnavail = 0x0080, |
| 401 | RxFIFOOver = 0x0040, |
| 402 | LinkChg = 0x0020, |
| 403 | RxOverflow = 0x0010, |
| 404 | TxErr = 0x0008, |
| 405 | TxOK = 0x0004, |
| 406 | RxErr = 0x0002, |
| 407 | RxOK = 0x0001, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | |
| 409 | /* RxStatusDesc */ |
Francois Romieu | e03f33a | 2011-08-25 18:47:24 +0200 | [diff] [blame] | 410 | RxBOVF = (1 << 24), |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 411 | RxFOVF = (1 << 23), |
| 412 | RxRWT = (1 << 22), |
| 413 | RxRES = (1 << 21), |
| 414 | RxRUNT = (1 << 20), |
| 415 | RxCRC = (1 << 19), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 | |
| 417 | /* ChipCmdBits */ |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 418 | StopReq = 0x80, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 419 | CmdReset = 0x10, |
| 420 | CmdRxEnb = 0x08, |
| 421 | CmdTxEnb = 0x04, |
| 422 | RxBufEmpty = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
Francois Romieu | 275391a | 2007-02-23 23:50:28 +0100 | [diff] [blame] | 424 | /* TXPoll register p.5 */ |
| 425 | HPQ = 0x80, /* Poll cmd on the high prio queue */ |
| 426 | NPQ = 0x40, /* Poll cmd on the low prio queue */ |
| 427 | FSWInt = 0x01, /* Forced software interrupt */ |
| 428 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | /* Cfg9346Bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 430 | Cfg9346_Lock = 0x00, |
| 431 | Cfg9346_Unlock = 0xc0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
| 433 | /* rx_mode_bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 434 | AcceptErr = 0x20, |
| 435 | AcceptRunt = 0x10, |
| 436 | AcceptBroadcast = 0x08, |
| 437 | AcceptMulticast = 0x04, |
| 438 | AcceptMyPhys = 0x02, |
| 439 | AcceptAllPhys = 0x01, |
Francois Romieu | 1687b56 | 2011-07-19 17:21:29 +0200 | [diff] [blame] | 440 | #define RX_CONFIG_ACCEPT_MASK 0x3f |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | /* TxConfigBits */ |
| 443 | TxInterFrameGapShift = 24, |
| 444 | TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */ |
| 445 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 446 | /* Config1 register p.24 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 447 | LEDS1 = (1 << 7), |
| 448 | LEDS0 = (1 << 6), |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 449 | MSIEnable = (1 << 5), /* Enable Message Signaled Interrupt */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 450 | Speed_down = (1 << 4), |
| 451 | MEMMAP = (1 << 3), |
| 452 | IOMAP = (1 << 2), |
| 453 | VPD = (1 << 1), |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 454 | PMEnable = (1 << 0), /* Power Management Enable */ |
| 455 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 456 | /* Config2 register p. 25 */ |
| 457 | PCI_Clock_66MHz = 0x01, |
| 458 | PCI_Clock_33MHz = 0x00, |
| 459 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 460 | /* Config3 register p.25 */ |
| 461 | MagicPacket = (1 << 5), /* Wake up when receives a Magic Packet */ |
| 462 | LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 463 | Beacon_en = (1 << 0), /* 8168 only. Reserved in the 8168b */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 464 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 465 | /* Config5 register p.27 */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 466 | BWF = (1 << 6), /* Accept Broadcast wakeup frame */ |
| 467 | MWF = (1 << 5), /* Accept Multicast wakeup frame */ |
| 468 | UWF = (1 << 4), /* Accept Unicast wakeup frame */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 469 | Spi_en = (1 << 3), |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 470 | LanWake = (1 << 1), /* LanWake enable/disable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 471 | PMEStatus = (1 << 0), /* PME status can be reset by PCI RST# */ |
| 472 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | /* TBICSR p.28 */ |
| 474 | TBIReset = 0x80000000, |
| 475 | TBILoopback = 0x40000000, |
| 476 | TBINwEnable = 0x20000000, |
| 477 | TBINwRestart = 0x10000000, |
| 478 | TBILinkOk = 0x02000000, |
| 479 | TBINwComplete = 0x01000000, |
| 480 | |
| 481 | /* CPlusCmd p.31 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 482 | EnableBist = (1 << 15), // 8168 8101 |
| 483 | Mac_dbgo_oe = (1 << 14), // 8168 8101 |
| 484 | Normal_mode = (1 << 13), // unused |
| 485 | Force_half_dup = (1 << 12), // 8168 8101 |
| 486 | Force_rxflow_en = (1 << 11), // 8168 8101 |
| 487 | Force_txflow_en = (1 << 10), // 8168 8101 |
| 488 | Cxpl_dbg_sel = (1 << 9), // 8168 8101 |
| 489 | ASF = (1 << 8), // 8168 8101 |
| 490 | PktCntrDisable = (1 << 7), // 8168 8101 |
| 491 | Mac_dbgo_sel = 0x001c, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | RxVlan = (1 << 6), |
| 493 | RxChkSum = (1 << 5), |
| 494 | PCIDAC = (1 << 4), |
| 495 | PCIMulRW = (1 << 3), |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 496 | INTT_0 = 0x0000, // 8168 |
| 497 | INTT_1 = 0x0001, // 8168 |
| 498 | INTT_2 = 0x0002, // 8168 |
| 499 | INTT_3 = 0x0003, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | |
| 501 | /* rtl8169_PHYstatus */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 502 | TBI_Enable = 0x80, |
| 503 | TxFlowCtrl = 0x40, |
| 504 | RxFlowCtrl = 0x20, |
| 505 | _1000bpsF = 0x10, |
| 506 | _100bps = 0x08, |
| 507 | _10bps = 0x04, |
| 508 | LinkStatus = 0x02, |
| 509 | FullDup = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | /* _TBICSRBit */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 512 | TBILinkOK = 0x02000000, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 513 | |
| 514 | /* DumpCounterCommand */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 515 | CounterDump = 0x8, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | }; |
| 517 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 518 | enum rtl_desc_bit { |
| 519 | /* First doubleword. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 520 | DescOwn = (1 << 31), /* Descriptor is owned by NIC */ |
| 521 | RingEnd = (1 << 30), /* End of descriptor ring */ |
| 522 | FirstFrag = (1 << 29), /* First segment of a packet */ |
| 523 | LastFrag = (1 << 28), /* Final segment of a packet */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 524 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 525 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 526 | /* Generic case. */ |
| 527 | enum rtl_tx_desc_bit { |
| 528 | /* First doubleword. */ |
| 529 | TD_LSO = (1 << 27), /* Large Send Offload */ |
| 530 | #define TD_MSS_MAX 0x07ffu /* MSS value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 532 | /* Second doubleword. */ |
| 533 | TxVlanTag = (1 << 17), /* Add VLAN tag */ |
| 534 | }; |
| 535 | |
| 536 | /* 8169, 8168b and 810x except 8102e. */ |
| 537 | enum rtl_tx_desc_bit_0 { |
| 538 | /* First doubleword. */ |
| 539 | #define TD0_MSS_SHIFT 16 /* MSS position (11 bits) */ |
| 540 | TD0_TCP_CS = (1 << 16), /* Calculate TCP/IP checksum */ |
| 541 | TD0_UDP_CS = (1 << 17), /* Calculate UDP/IP checksum */ |
| 542 | TD0_IP_CS = (1 << 18), /* Calculate IP checksum */ |
| 543 | }; |
| 544 | |
| 545 | /* 8102e, 8168c and beyond. */ |
| 546 | enum rtl_tx_desc_bit_1 { |
| 547 | /* Second doubleword. */ |
| 548 | #define TD1_MSS_SHIFT 18 /* MSS position (11 bits) */ |
| 549 | TD1_IP_CS = (1 << 29), /* Calculate IP checksum */ |
| 550 | TD1_TCP_CS = (1 << 30), /* Calculate TCP/IP checksum */ |
| 551 | TD1_UDP_CS = (1 << 31), /* Calculate UDP/IP checksum */ |
| 552 | }; |
| 553 | |
| 554 | static const struct rtl_tx_desc_info { |
| 555 | struct { |
| 556 | u32 udp; |
| 557 | u32 tcp; |
| 558 | } checksum; |
| 559 | u16 mss_shift; |
| 560 | u16 opts_offset; |
| 561 | } tx_desc_info [] = { |
| 562 | [RTL_TD_0] = { |
| 563 | .checksum = { |
| 564 | .udp = TD0_IP_CS | TD0_UDP_CS, |
| 565 | .tcp = TD0_IP_CS | TD0_TCP_CS |
| 566 | }, |
| 567 | .mss_shift = TD0_MSS_SHIFT, |
| 568 | .opts_offset = 0 |
| 569 | }, |
| 570 | [RTL_TD_1] = { |
| 571 | .checksum = { |
| 572 | .udp = TD1_IP_CS | TD1_UDP_CS, |
| 573 | .tcp = TD1_IP_CS | TD1_TCP_CS |
| 574 | }, |
| 575 | .mss_shift = TD1_MSS_SHIFT, |
| 576 | .opts_offset = 1 |
| 577 | } |
| 578 | }; |
| 579 | |
| 580 | enum rtl_rx_desc_bit { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | /* Rx private */ |
| 582 | PID1 = (1 << 18), /* Protocol ID bit 1/2 */ |
| 583 | PID0 = (1 << 17), /* Protocol ID bit 2/2 */ |
| 584 | |
| 585 | #define RxProtoUDP (PID1) |
| 586 | #define RxProtoTCP (PID0) |
| 587 | #define RxProtoIP (PID1 | PID0) |
| 588 | #define RxProtoMask RxProtoIP |
| 589 | |
| 590 | IPFail = (1 << 16), /* IP checksum failed */ |
| 591 | UDPFail = (1 << 15), /* UDP/IP checksum failed */ |
| 592 | TCPFail = (1 << 14), /* TCP/IP checksum failed */ |
| 593 | RxVlanTag = (1 << 16), /* VLAN tag available */ |
| 594 | }; |
| 595 | |
| 596 | #define RsvdMask 0x3fffc000 |
| 597 | |
| 598 | struct TxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 599 | __le32 opts1; |
| 600 | __le32 opts2; |
| 601 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | }; |
| 603 | |
| 604 | struct RxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 605 | __le32 opts1; |
| 606 | __le32 opts2; |
| 607 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | }; |
| 609 | |
| 610 | struct ring_info { |
| 611 | struct sk_buff *skb; |
| 612 | u32 len; |
| 613 | u8 __pad[sizeof(void *) - sizeof(u32)]; |
| 614 | }; |
| 615 | |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 616 | enum features { |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 617 | RTL_FEATURE_WOL = (1 << 0), |
| 618 | RTL_FEATURE_MSI = (1 << 1), |
| 619 | RTL_FEATURE_GMII = (1 << 2), |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 620 | }; |
| 621 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 622 | struct rtl8169_counters { |
| 623 | __le64 tx_packets; |
| 624 | __le64 rx_packets; |
| 625 | __le64 tx_errors; |
| 626 | __le32 rx_errors; |
| 627 | __le16 rx_missed; |
| 628 | __le16 align_errors; |
| 629 | __le32 tx_one_collision; |
| 630 | __le32 tx_multi_collision; |
| 631 | __le64 rx_unicast; |
| 632 | __le64 rx_broadcast; |
| 633 | __le32 rx_multicast; |
| 634 | __le16 tx_aborted; |
| 635 | __le16 tx_underun; |
| 636 | }; |
| 637 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | struct rtl8169_private { |
| 639 | void __iomem *mmio_addr; /* memory map physical address */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 640 | struct pci_dev *pci_dev; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 641 | struct net_device *dev; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 642 | struct napi_struct napi; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 643 | spinlock_t lock; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 644 | u32 msg_enable; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 645 | u16 txd_version; |
| 646 | u16 mac_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */ |
| 648 | u32 cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */ |
| 649 | u32 dirty_rx; |
| 650 | u32 dirty_tx; |
| 651 | struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */ |
| 652 | struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */ |
| 653 | dma_addr_t TxPhyAddr; |
| 654 | dma_addr_t RxPhyAddr; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 655 | void *Rx_databuff[NUM_RX_DESC]; /* Rx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | struct timer_list timer; |
| 658 | u16 cp_cmd; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 659 | u16 intr_event; |
| 660 | u16 napi_event; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | u16 intr_mask; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 662 | |
| 663 | struct mdio_ops { |
| 664 | void (*write)(void __iomem *, int, int); |
| 665 | int (*read)(void __iomem *, int); |
| 666 | } mdio_ops; |
| 667 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 668 | struct pll_power_ops { |
| 669 | void (*down)(struct rtl8169_private *); |
| 670 | void (*up)(struct rtl8169_private *); |
| 671 | } pll_power_ops; |
| 672 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 673 | 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] | 674 | int (*get_settings)(struct net_device *, struct ethtool_cmd *); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 675 | void (*phy_reset_enable)(struct rtl8169_private *tp); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 676 | void (*hw_start)(struct net_device *); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 677 | unsigned int (*phy_reset_pending)(struct rtl8169_private *tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 678 | unsigned int (*link_ok)(void __iomem *); |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 679 | int (*do_ioctl)(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 680 | struct delayed_work task; |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 681 | unsigned features; |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 682 | |
| 683 | struct mii_if_info mii; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 684 | struct rtl8169_counters counters; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 685 | u32 saved_wolopts; |
Francois Romieu | e03f33a | 2011-08-25 18:47:24 +0200 | [diff] [blame] | 686 | u32 opts1_mask; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 687 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 688 | struct rtl_fw { |
| 689 | const struct firmware *fw; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 690 | |
| 691 | #define RTL_VER_SIZE 32 |
| 692 | |
| 693 | char version[RTL_VER_SIZE]; |
| 694 | |
| 695 | struct rtl_fw_phy_action { |
| 696 | __le32 *code; |
| 697 | size_t size; |
| 698 | } phy_action; |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 699 | } *rtl_fw; |
Phil Carmody | 497888c | 2011-07-14 15:07:13 +0300 | [diff] [blame] | 700 | #define RTL_FIRMWARE_UNKNOWN ERR_PTR(-EAGAIN) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | }; |
| 702 | |
Ralf Baechle | 979b6c1 | 2005-06-13 14:30:40 -0700 | [diff] [blame] | 703 | MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 704 | MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | module_param(use_dac, int, 0); |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 706 | 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] | 707 | module_param_named(debug, debug.msg_enable, int, 0); |
| 708 | MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | MODULE_LICENSE("GPL"); |
| 710 | MODULE_VERSION(RTL8169_VERSION); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 711 | MODULE_FIRMWARE(FIRMWARE_8168D_1); |
| 712 | MODULE_FIRMWARE(FIRMWARE_8168D_2); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 713 | MODULE_FIRMWARE(FIRMWARE_8168E_1); |
| 714 | MODULE_FIRMWARE(FIRMWARE_8168E_2); |
Hayes Wang | bbb8af7 | 2011-09-06 16:55:17 +0800 | [diff] [blame] | 715 | MODULE_FIRMWARE(FIRMWARE_8168E_3); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 716 | MODULE_FIRMWARE(FIRMWARE_8105E_1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | |
| 718 | static int rtl8169_open(struct net_device *dev); |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 719 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 720 | struct net_device *dev); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 721 | static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | static int rtl8169_init_ring(struct net_device *dev); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 723 | static void rtl_hw_start(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | static int rtl8169_close(struct net_device *dev); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 725 | static void rtl_set_rx_mode(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | static void rtl8169_tx_timeout(struct net_device *dev); |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 727 | static struct net_device_stats *rtl8169_get_stats(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 728 | static int rtl8169_rx_interrupt(struct net_device *, struct rtl8169_private *, |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 729 | void __iomem *, u32 budget); |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 730 | static int rtl8169_change_mtu(struct net_device *dev, int new_mtu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 731 | static void rtl8169_down(struct net_device *dev); |
Francois Romieu | 99f252b0 | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 732 | static void rtl8169_rx_clear(struct rtl8169_private *tp); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 733 | static int rtl8169_poll(struct napi_struct *napi, int budget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 735 | static u32 ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 736 | { |
| 737 | void __iomem *ioaddr = tp->mmio_addr; |
| 738 | int i; |
| 739 | |
| 740 | RTL_W32(OCPAR, ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
| 741 | for (i = 0; i < 20; i++) { |
| 742 | udelay(100); |
| 743 | if (RTL_R32(OCPAR) & OCPAR_FLAG) |
| 744 | break; |
| 745 | } |
| 746 | return RTL_R32(OCPDR); |
| 747 | } |
| 748 | |
| 749 | static void ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, u32 data) |
| 750 | { |
| 751 | void __iomem *ioaddr = tp->mmio_addr; |
| 752 | int i; |
| 753 | |
| 754 | RTL_W32(OCPDR, data); |
| 755 | RTL_W32(OCPAR, OCPAR_FLAG | ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
| 756 | for (i = 0; i < 20; i++) { |
| 757 | udelay(100); |
| 758 | if ((RTL_R32(OCPAR) & OCPAR_FLAG) == 0) |
| 759 | break; |
| 760 | } |
| 761 | } |
| 762 | |
Hayes Wang | fac5b3c | 2011-02-22 17:26:20 +0800 | [diff] [blame] | 763 | static void rtl8168_oob_notify(struct rtl8169_private *tp, u8 cmd) |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 764 | { |
Hayes Wang | fac5b3c | 2011-02-22 17:26:20 +0800 | [diff] [blame] | 765 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 766 | int i; |
| 767 | |
| 768 | RTL_W8(ERIDR, cmd); |
| 769 | RTL_W32(ERIAR, 0x800010e8); |
| 770 | msleep(2); |
| 771 | for (i = 0; i < 5; i++) { |
| 772 | udelay(100); |
Francois Romieu | 1e4e82b | 2011-06-24 19:52:13 +0200 | [diff] [blame] | 773 | if (!(RTL_R32(ERIAR) & ERIAR_FLAG)) |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 774 | break; |
| 775 | } |
| 776 | |
Hayes Wang | fac5b3c | 2011-02-22 17:26:20 +0800 | [diff] [blame] | 777 | ocp_write(tp, 0x1, 0x30, 0x00000001); |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | #define OOB_CMD_RESET 0x00 |
| 781 | #define OOB_CMD_DRIVER_START 0x05 |
| 782 | #define OOB_CMD_DRIVER_STOP 0x06 |
| 783 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 784 | static u16 rtl8168_get_ocp_reg(struct rtl8169_private *tp) |
| 785 | { |
| 786 | return (tp->mac_version == RTL_GIGA_MAC_VER_31) ? 0xb8 : 0x10; |
| 787 | } |
| 788 | |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 789 | static void rtl8168_driver_start(struct rtl8169_private *tp) |
| 790 | { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 791 | u16 reg; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 792 | int i; |
| 793 | |
| 794 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_START); |
| 795 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 796 | reg = rtl8168_get_ocp_reg(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 797 | |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 798 | for (i = 0; i < 10; i++) { |
| 799 | msleep(10); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 800 | if (ocp_read(tp, 0x0f, reg) & 0x00000800) |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 801 | break; |
| 802 | } |
| 803 | } |
| 804 | |
| 805 | static void rtl8168_driver_stop(struct rtl8169_private *tp) |
| 806 | { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 807 | u16 reg; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 808 | int i; |
| 809 | |
| 810 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_STOP); |
| 811 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 812 | reg = rtl8168_get_ocp_reg(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 813 | |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 814 | for (i = 0; i < 10; i++) { |
| 815 | msleep(10); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 816 | if ((ocp_read(tp, 0x0f, reg) & 0x00000800) == 0) |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 817 | break; |
| 818 | } |
| 819 | } |
| 820 | |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 821 | static int r8168dp_check_dash(struct rtl8169_private *tp) |
| 822 | { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 823 | u16 reg = rtl8168_get_ocp_reg(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 824 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 825 | return (ocp_read(tp, 0x0f, reg) & 0x00008000) ? 1 : 0; |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 826 | } |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 827 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 828 | 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] | 829 | { |
| 830 | int i; |
| 831 | |
Francois Romieu | a6baf3a | 2007-11-08 23:23:21 +0100 | [diff] [blame] | 832 | RTL_W32(PHYAR, 0x80000000 | (reg_addr & 0x1f) << 16 | (value & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 833 | |
Francois Romieu | 2371408 | 2006-01-29 00:49:09 +0100 | [diff] [blame] | 834 | for (i = 20; i > 0; i--) { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 835 | /* |
| 836 | * Check if the RTL8169 has completed writing to the specified |
| 837 | * MII register. |
| 838 | */ |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 839 | if (!(RTL_R32(PHYAR) & 0x80000000)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | break; |
Francois Romieu | 2371408 | 2006-01-29 00:49:09 +0100 | [diff] [blame] | 841 | udelay(25); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 842 | } |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 843 | /* |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 844 | * According to hardware specs a 20us delay is required after write |
| 845 | * complete indication, but before sending next command. |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 846 | */ |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 847 | udelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | } |
| 849 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 850 | static int r8169_mdio_read(void __iomem *ioaddr, int reg_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 851 | { |
| 852 | int i, value = -1; |
| 853 | |
Francois Romieu | a6baf3a | 2007-11-08 23:23:21 +0100 | [diff] [blame] | 854 | RTL_W32(PHYAR, 0x0 | (reg_addr & 0x1f) << 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | |
Francois Romieu | 2371408 | 2006-01-29 00:49:09 +0100 | [diff] [blame] | 856 | for (i = 20; i > 0; i--) { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 857 | /* |
| 858 | * Check if the RTL8169 has completed retrieving data from |
| 859 | * the specified MII register. |
| 860 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | if (RTL_R32(PHYAR) & 0x80000000) { |
Francois Romieu | a6baf3a | 2007-11-08 23:23:21 +0100 | [diff] [blame] | 862 | value = RTL_R32(PHYAR) & 0xffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | break; |
| 864 | } |
Francois Romieu | 2371408 | 2006-01-29 00:49:09 +0100 | [diff] [blame] | 865 | udelay(25); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 866 | } |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 867 | /* |
| 868 | * According to hardware specs a 20us delay is required after read |
| 869 | * complete indication, but before sending next command. |
| 870 | */ |
| 871 | udelay(20); |
| 872 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | return value; |
| 874 | } |
| 875 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 876 | static void r8168dp_1_mdio_access(void __iomem *ioaddr, int reg_addr, u32 data) |
| 877 | { |
| 878 | int i; |
| 879 | |
| 880 | RTL_W32(OCPDR, data | |
| 881 | ((reg_addr & OCPDR_REG_MASK) << OCPDR_GPHY_REG_SHIFT)); |
| 882 | RTL_W32(OCPAR, OCPAR_GPHY_WRITE_CMD); |
| 883 | RTL_W32(EPHY_RXER_NUM, 0); |
| 884 | |
| 885 | for (i = 0; i < 100; i++) { |
| 886 | mdelay(1); |
| 887 | if (!(RTL_R32(OCPAR) & OCPAR_FLAG)) |
| 888 | break; |
| 889 | } |
| 890 | } |
| 891 | |
| 892 | static void r8168dp_1_mdio_write(void __iomem *ioaddr, int reg_addr, int value) |
| 893 | { |
| 894 | r8168dp_1_mdio_access(ioaddr, reg_addr, OCPDR_WRITE_CMD | |
| 895 | (value & OCPDR_DATA_MASK)); |
| 896 | } |
| 897 | |
| 898 | static int r8168dp_1_mdio_read(void __iomem *ioaddr, int reg_addr) |
| 899 | { |
| 900 | int i; |
| 901 | |
| 902 | r8168dp_1_mdio_access(ioaddr, reg_addr, OCPDR_READ_CMD); |
| 903 | |
| 904 | mdelay(1); |
| 905 | RTL_W32(OCPAR, OCPAR_GPHY_READ_CMD); |
| 906 | RTL_W32(EPHY_RXER_NUM, 0); |
| 907 | |
| 908 | for (i = 0; i < 100; i++) { |
| 909 | mdelay(1); |
| 910 | if (RTL_R32(OCPAR) & OCPAR_FLAG) |
| 911 | break; |
| 912 | } |
| 913 | |
| 914 | return RTL_R32(OCPDR) & OCPDR_DATA_MASK; |
| 915 | } |
| 916 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 917 | #define R8168DP_1_MDIO_ACCESS_BIT 0x00020000 |
| 918 | |
| 919 | static void r8168dp_2_mdio_start(void __iomem *ioaddr) |
| 920 | { |
| 921 | RTL_W32(0xd0, RTL_R32(0xd0) & ~R8168DP_1_MDIO_ACCESS_BIT); |
| 922 | } |
| 923 | |
| 924 | static void r8168dp_2_mdio_stop(void __iomem *ioaddr) |
| 925 | { |
| 926 | RTL_W32(0xd0, RTL_R32(0xd0) | R8168DP_1_MDIO_ACCESS_BIT); |
| 927 | } |
| 928 | |
| 929 | static void r8168dp_2_mdio_write(void __iomem *ioaddr, int reg_addr, int value) |
| 930 | { |
| 931 | r8168dp_2_mdio_start(ioaddr); |
| 932 | |
| 933 | r8169_mdio_write(ioaddr, reg_addr, value); |
| 934 | |
| 935 | r8168dp_2_mdio_stop(ioaddr); |
| 936 | } |
| 937 | |
| 938 | static int r8168dp_2_mdio_read(void __iomem *ioaddr, int reg_addr) |
| 939 | { |
| 940 | int value; |
| 941 | |
| 942 | r8168dp_2_mdio_start(ioaddr); |
| 943 | |
| 944 | value = r8169_mdio_read(ioaddr, reg_addr); |
| 945 | |
| 946 | r8168dp_2_mdio_stop(ioaddr); |
| 947 | |
| 948 | return value; |
| 949 | } |
| 950 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 951 | static void rtl_writephy(struct rtl8169_private *tp, int location, u32 val) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 952 | { |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 953 | tp->mdio_ops.write(tp->mmio_addr, location, val); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 954 | } |
| 955 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 956 | static int rtl_readphy(struct rtl8169_private *tp, int location) |
| 957 | { |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 958 | return tp->mdio_ops.read(tp->mmio_addr, location); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 959 | } |
| 960 | |
| 961 | static void rtl_patchphy(struct rtl8169_private *tp, int reg_addr, int value) |
| 962 | { |
| 963 | rtl_writephy(tp, reg_addr, rtl_readphy(tp, reg_addr) | value); |
| 964 | } |
| 965 | |
| 966 | 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] | 967 | { |
| 968 | int val; |
| 969 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 970 | val = rtl_readphy(tp, reg_addr); |
| 971 | rtl_writephy(tp, reg_addr, (val | p) & ~m); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 972 | } |
| 973 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 974 | static void rtl_mdio_write(struct net_device *dev, int phy_id, int location, |
| 975 | int val) |
| 976 | { |
| 977 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 978 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 979 | rtl_writephy(tp, location, val); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 980 | } |
| 981 | |
| 982 | static int rtl_mdio_read(struct net_device *dev, int phy_id, int location) |
| 983 | { |
| 984 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 985 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 986 | return rtl_readphy(tp, location); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 987 | } |
| 988 | |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 989 | static void rtl_ephy_write(void __iomem *ioaddr, int reg_addr, int value) |
| 990 | { |
| 991 | unsigned int i; |
| 992 | |
| 993 | RTL_W32(EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) | |
| 994 | (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
| 995 | |
| 996 | for (i = 0; i < 100; i++) { |
| 997 | if (!(RTL_R32(EPHYAR) & EPHYAR_FLAG)) |
| 998 | break; |
| 999 | udelay(10); |
| 1000 | } |
| 1001 | } |
| 1002 | |
| 1003 | static u16 rtl_ephy_read(void __iomem *ioaddr, int reg_addr) |
| 1004 | { |
| 1005 | u16 value = 0xffff; |
| 1006 | unsigned int i; |
| 1007 | |
| 1008 | RTL_W32(EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
| 1009 | |
| 1010 | for (i = 0; i < 100; i++) { |
| 1011 | if (RTL_R32(EPHYAR) & EPHYAR_FLAG) { |
| 1012 | value = RTL_R32(EPHYAR) & EPHYAR_DATA_MASK; |
| 1013 | break; |
| 1014 | } |
| 1015 | udelay(10); |
| 1016 | } |
| 1017 | |
| 1018 | return value; |
| 1019 | } |
| 1020 | |
| 1021 | static void rtl_csi_write(void __iomem *ioaddr, int addr, int value) |
| 1022 | { |
| 1023 | unsigned int i; |
| 1024 | |
| 1025 | RTL_W32(CSIDR, value); |
| 1026 | RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
| 1027 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 1028 | |
| 1029 | for (i = 0; i < 100; i++) { |
| 1030 | if (!(RTL_R32(CSIAR) & CSIAR_FLAG)) |
| 1031 | break; |
| 1032 | udelay(10); |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | static u32 rtl_csi_read(void __iomem *ioaddr, int addr) |
| 1037 | { |
| 1038 | u32 value = ~0x00; |
| 1039 | unsigned int i; |
| 1040 | |
| 1041 | RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) | |
| 1042 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 1043 | |
| 1044 | for (i = 0; i < 100; i++) { |
| 1045 | if (RTL_R32(CSIAR) & CSIAR_FLAG) { |
| 1046 | value = RTL_R32(CSIDR); |
| 1047 | break; |
| 1048 | } |
| 1049 | udelay(10); |
| 1050 | } |
| 1051 | |
| 1052 | return value; |
| 1053 | } |
| 1054 | |
Hayes Wang | 133ac40 | 2011-07-06 15:58:05 +0800 | [diff] [blame] | 1055 | static |
| 1056 | void rtl_eri_write(void __iomem *ioaddr, int addr, u32 mask, u32 val, int type) |
| 1057 | { |
| 1058 | unsigned int i; |
| 1059 | |
| 1060 | BUG_ON((addr & 3) || (mask == 0)); |
| 1061 | RTL_W32(ERIDR, val); |
| 1062 | RTL_W32(ERIAR, ERIAR_WRITE_CMD | type | mask | addr); |
| 1063 | |
| 1064 | for (i = 0; i < 100; i++) { |
| 1065 | if (!(RTL_R32(ERIAR) & ERIAR_FLAG)) |
| 1066 | break; |
| 1067 | udelay(100); |
| 1068 | } |
| 1069 | } |
| 1070 | |
| 1071 | static u32 rtl_eri_read(void __iomem *ioaddr, int addr, int type) |
| 1072 | { |
| 1073 | u32 value = ~0x00; |
| 1074 | unsigned int i; |
| 1075 | |
| 1076 | RTL_W32(ERIAR, ERIAR_READ_CMD | type | ERIAR_MASK_1111 | addr); |
| 1077 | |
| 1078 | for (i = 0; i < 100; i++) { |
| 1079 | if (RTL_R32(ERIAR) & ERIAR_FLAG) { |
| 1080 | value = RTL_R32(ERIDR); |
| 1081 | break; |
| 1082 | } |
| 1083 | udelay(100); |
| 1084 | } |
| 1085 | |
| 1086 | return value; |
| 1087 | } |
| 1088 | |
| 1089 | static void |
| 1090 | rtl_w1w0_eri(void __iomem *ioaddr, int addr, u32 mask, u32 p, u32 m, int type) |
| 1091 | { |
| 1092 | u32 val; |
| 1093 | |
| 1094 | val = rtl_eri_read(ioaddr, addr, type); |
| 1095 | rtl_eri_write(ioaddr, addr, mask, (val & ~m) | p, type); |
| 1096 | } |
| 1097 | |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 1098 | struct exgmac_reg { |
| 1099 | u16 addr; |
| 1100 | u16 mask; |
| 1101 | u32 val; |
| 1102 | }; |
| 1103 | |
| 1104 | static void rtl_write_exgmac_batch(void __iomem *ioaddr, |
| 1105 | const struct exgmac_reg *r, int len) |
| 1106 | { |
| 1107 | while (len-- > 0) { |
| 1108 | rtl_eri_write(ioaddr, r->addr, r->mask, r->val, ERIAR_EXGMAC); |
| 1109 | r++; |
| 1110 | } |
| 1111 | } |
| 1112 | |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1113 | static u8 rtl8168d_efuse_read(void __iomem *ioaddr, int reg_addr) |
| 1114 | { |
| 1115 | u8 value = 0xff; |
| 1116 | unsigned int i; |
| 1117 | |
| 1118 | RTL_W32(EFUSEAR, (reg_addr & EFUSEAR_REG_MASK) << EFUSEAR_REG_SHIFT); |
| 1119 | |
| 1120 | for (i = 0; i < 300; i++) { |
| 1121 | if (RTL_R32(EFUSEAR) & EFUSEAR_FLAG) { |
| 1122 | value = RTL_R32(EFUSEAR) & EFUSEAR_DATA_MASK; |
| 1123 | break; |
| 1124 | } |
| 1125 | udelay(100); |
| 1126 | } |
| 1127 | |
| 1128 | return value; |
| 1129 | } |
| 1130 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1131 | static void rtl8169_irq_mask_and_ack(void __iomem *ioaddr) |
| 1132 | { |
| 1133 | RTL_W16(IntrMask, 0x0000); |
| 1134 | |
| 1135 | RTL_W16(IntrStatus, 0xffff); |
| 1136 | } |
| 1137 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1138 | static unsigned int rtl8169_tbi_reset_pending(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1139 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1140 | void __iomem *ioaddr = tp->mmio_addr; |
| 1141 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1142 | return RTL_R32(TBICSR) & TBIReset; |
| 1143 | } |
| 1144 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1145 | static unsigned int rtl8169_xmii_reset_pending(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1146 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1147 | return rtl_readphy(tp, MII_BMCR) & BMCR_RESET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | static unsigned int rtl8169_tbi_link_ok(void __iomem *ioaddr) |
| 1151 | { |
| 1152 | return RTL_R32(TBICSR) & TBILinkOk; |
| 1153 | } |
| 1154 | |
| 1155 | static unsigned int rtl8169_xmii_link_ok(void __iomem *ioaddr) |
| 1156 | { |
| 1157 | return RTL_R8(PHYstatus) & LinkStatus; |
| 1158 | } |
| 1159 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1160 | static void rtl8169_tbi_reset_enable(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1161 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1162 | void __iomem *ioaddr = tp->mmio_addr; |
| 1163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | RTL_W32(TBICSR, RTL_R32(TBICSR) | TBIReset); |
| 1165 | } |
| 1166 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1167 | static void rtl8169_xmii_reset_enable(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1168 | { |
| 1169 | unsigned int val; |
| 1170 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1171 | val = rtl_readphy(tp, MII_BMCR) | BMCR_RESET; |
| 1172 | rtl_writephy(tp, MII_BMCR, val & 0xffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1173 | } |
| 1174 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1175 | static void rtl_link_chg_patch(struct rtl8169_private *tp) |
| 1176 | { |
| 1177 | void __iomem *ioaddr = tp->mmio_addr; |
| 1178 | struct net_device *dev = tp->dev; |
| 1179 | |
| 1180 | if (!netif_running(dev)) |
| 1181 | return; |
| 1182 | |
| 1183 | if (tp->mac_version == RTL_GIGA_MAC_VER_34) { |
| 1184 | if (RTL_R8(PHYstatus) & _1000bpsF) { |
| 1185 | rtl_eri_write(ioaddr, 0x1bc, ERIAR_MASK_1111, |
| 1186 | 0x00000011, ERIAR_EXGMAC); |
| 1187 | rtl_eri_write(ioaddr, 0x1dc, ERIAR_MASK_1111, |
| 1188 | 0x00000005, ERIAR_EXGMAC); |
| 1189 | } else if (RTL_R8(PHYstatus) & _100bps) { |
| 1190 | rtl_eri_write(ioaddr, 0x1bc, ERIAR_MASK_1111, |
| 1191 | 0x0000001f, ERIAR_EXGMAC); |
| 1192 | rtl_eri_write(ioaddr, 0x1dc, ERIAR_MASK_1111, |
| 1193 | 0x00000005, ERIAR_EXGMAC); |
| 1194 | } else { |
| 1195 | rtl_eri_write(ioaddr, 0x1bc, ERIAR_MASK_1111, |
| 1196 | 0x0000001f, ERIAR_EXGMAC); |
| 1197 | rtl_eri_write(ioaddr, 0x1dc, ERIAR_MASK_1111, |
| 1198 | 0x0000003f, ERIAR_EXGMAC); |
| 1199 | } |
| 1200 | /* Reset packet filter */ |
| 1201 | rtl_w1w0_eri(ioaddr, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, |
| 1202 | ERIAR_EXGMAC); |
| 1203 | rtl_w1w0_eri(ioaddr, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, |
| 1204 | ERIAR_EXGMAC); |
| 1205 | } |
| 1206 | } |
| 1207 | |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 1208 | static void __rtl8169_check_link_status(struct net_device *dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1209 | struct rtl8169_private *tp, |
| 1210 | void __iomem *ioaddr, bool pm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1211 | { |
| 1212 | unsigned long flags; |
| 1213 | |
| 1214 | spin_lock_irqsave(&tp->lock, flags); |
| 1215 | if (tp->link_ok(ioaddr)) { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1216 | rtl_link_chg_patch(tp); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1217 | /* This is to cancel a scheduled suspend if there's one. */ |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 1218 | if (pm) |
| 1219 | pm_request_resume(&tp->pci_dev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | netif_carrier_on(dev); |
Francois Romieu | 1519e57 | 2011-02-03 12:02:36 +0100 | [diff] [blame] | 1221 | if (net_ratelimit()) |
| 1222 | netif_info(tp, ifup, dev, "link up\n"); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1223 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | netif_carrier_off(dev); |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1225 | netif_info(tp, ifdown, dev, "link down\n"); |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 1226 | if (pm) |
| 1227 | pm_schedule_suspend(&tp->pci_dev->dev, 100); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1228 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1229 | spin_unlock_irqrestore(&tp->lock, flags); |
| 1230 | } |
| 1231 | |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 1232 | static void rtl8169_check_link_status(struct net_device *dev, |
| 1233 | struct rtl8169_private *tp, |
| 1234 | void __iomem *ioaddr) |
| 1235 | { |
| 1236 | __rtl8169_check_link_status(dev, tp, ioaddr, false); |
| 1237 | } |
| 1238 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1239 | #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST) |
| 1240 | |
| 1241 | static u32 __rtl8169_get_wol(struct rtl8169_private *tp) |
| 1242 | { |
| 1243 | void __iomem *ioaddr = tp->mmio_addr; |
| 1244 | u8 options; |
| 1245 | u32 wolopts = 0; |
| 1246 | |
| 1247 | options = RTL_R8(Config1); |
| 1248 | if (!(options & PMEnable)) |
| 1249 | return 0; |
| 1250 | |
| 1251 | options = RTL_R8(Config3); |
| 1252 | if (options & LinkUp) |
| 1253 | wolopts |= WAKE_PHY; |
| 1254 | if (options & MagicPacket) |
| 1255 | wolopts |= WAKE_MAGIC; |
| 1256 | |
| 1257 | options = RTL_R8(Config5); |
| 1258 | if (options & UWF) |
| 1259 | wolopts |= WAKE_UCAST; |
| 1260 | if (options & BWF) |
| 1261 | wolopts |= WAKE_BCAST; |
| 1262 | if (options & MWF) |
| 1263 | wolopts |= WAKE_MCAST; |
| 1264 | |
| 1265 | return wolopts; |
| 1266 | } |
| 1267 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1268 | static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1269 | { |
| 1270 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1271 | |
| 1272 | spin_lock_irq(&tp->lock); |
| 1273 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1274 | wol->supported = WAKE_ANY; |
| 1275 | wol->wolopts = __rtl8169_get_wol(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1276 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1277 | spin_unlock_irq(&tp->lock); |
| 1278 | } |
| 1279 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1280 | static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1281 | { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1282 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 1283 | unsigned int i; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 1284 | static const struct { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1285 | u32 opt; |
| 1286 | u16 reg; |
| 1287 | u8 mask; |
| 1288 | } cfg[] = { |
| 1289 | { WAKE_ANY, Config1, PMEnable }, |
| 1290 | { WAKE_PHY, Config3, LinkUp }, |
| 1291 | { WAKE_MAGIC, Config3, MagicPacket }, |
| 1292 | { WAKE_UCAST, Config5, UWF }, |
| 1293 | { WAKE_BCAST, Config5, BWF }, |
| 1294 | { WAKE_MCAST, Config5, MWF }, |
| 1295 | { WAKE_ANY, Config5, LanWake } |
| 1296 | }; |
| 1297 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1298 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 1299 | |
| 1300 | for (i = 0; i < ARRAY_SIZE(cfg); i++) { |
| 1301 | u8 options = RTL_R8(cfg[i].reg) & ~cfg[i].mask; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1302 | if (wolopts & cfg[i].opt) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1303 | options |= cfg[i].mask; |
| 1304 | RTL_W8(cfg[i].reg, options); |
| 1305 | } |
| 1306 | |
| 1307 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1308 | } |
| 1309 | |
| 1310 | static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1311 | { |
| 1312 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1313 | |
| 1314 | spin_lock_irq(&tp->lock); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1315 | |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 1316 | if (wol->wolopts) |
| 1317 | tp->features |= RTL_FEATURE_WOL; |
| 1318 | else |
| 1319 | tp->features &= ~RTL_FEATURE_WOL; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1320 | __rtl8169_set_wol(tp, wol->wolopts); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1321 | spin_unlock_irq(&tp->lock); |
| 1322 | |
françois romieu | ea80907 | 2010-11-08 13:23:58 +0000 | [diff] [blame] | 1323 | device_set_wakeup_enable(&tp->pci_dev->dev, wol->wolopts); |
| 1324 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1325 | return 0; |
| 1326 | } |
| 1327 | |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1328 | static const char *rtl_lookup_firmware_name(struct rtl8169_private *tp) |
| 1329 | { |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 1330 | return rtl_chip_infos[tp->mac_version].fw_name; |
Francois Romieu | 31bd204 | 2011-04-26 18:58:59 +0200 | [diff] [blame] | 1331 | } |
| 1332 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1333 | static void rtl8169_get_drvinfo(struct net_device *dev, |
| 1334 | struct ethtool_drvinfo *info) |
| 1335 | { |
| 1336 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 1337 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | |
| 1339 | strcpy(info->driver, MODULENAME); |
| 1340 | strcpy(info->version, RTL8169_VERSION); |
| 1341 | strcpy(info->bus_info, pci_name(tp->pci_dev)); |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 1342 | BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version)); |
| 1343 | strcpy(info->fw_version, IS_ERR_OR_NULL(rtl_fw) ? "N/A" : |
| 1344 | rtl_fw->version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
| 1347 | static int rtl8169_get_regs_len(struct net_device *dev) |
| 1348 | { |
| 1349 | return R8169_REGS_SIZE; |
| 1350 | } |
| 1351 | |
| 1352 | static int rtl8169_set_speed_tbi(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1353 | u8 autoneg, u16 speed, u8 duplex, u32 ignored) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1354 | { |
| 1355 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1356 | void __iomem *ioaddr = tp->mmio_addr; |
| 1357 | int ret = 0; |
| 1358 | u32 reg; |
| 1359 | |
| 1360 | reg = RTL_R32(TBICSR); |
| 1361 | if ((autoneg == AUTONEG_DISABLE) && (speed == SPEED_1000) && |
| 1362 | (duplex == DUPLEX_FULL)) { |
| 1363 | RTL_W32(TBICSR, reg & ~(TBINwEnable | TBINwRestart)); |
| 1364 | } else if (autoneg == AUTONEG_ENABLE) |
| 1365 | RTL_W32(TBICSR, reg | TBINwEnable | TBINwRestart); |
| 1366 | else { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1367 | netif_warn(tp, link, dev, |
| 1368 | "incorrect speed setting refused in TBI mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | ret = -EOPNOTSUPP; |
| 1370 | } |
| 1371 | |
| 1372 | return ret; |
| 1373 | } |
| 1374 | |
| 1375 | static int rtl8169_set_speed_xmii(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1376 | u8 autoneg, u16 speed, u8 duplex, u32 adv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | { |
| 1378 | struct rtl8169_private *tp = netdev_priv(dev); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1379 | int giga_ctrl, bmcr; |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1380 | int rc = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1381 | |
Hayes Wang | 716b50a | 2011-02-22 17:26:18 +0800 | [diff] [blame] | 1382 | rtl_writephy(tp, 0x1f, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | |
| 1384 | if (autoneg == AUTONEG_ENABLE) { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1385 | int auto_nego; |
| 1386 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1387 | auto_nego = rtl_readphy(tp, MII_ADVERTISE); |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1388 | auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL | |
| 1389 | ADVERTISE_100HALF | ADVERTISE_100FULL); |
| 1390 | |
| 1391 | if (adv & ADVERTISED_10baseT_Half) |
| 1392 | auto_nego |= ADVERTISE_10HALF; |
| 1393 | if (adv & ADVERTISED_10baseT_Full) |
| 1394 | auto_nego |= ADVERTISE_10FULL; |
| 1395 | if (adv & ADVERTISED_100baseT_Half) |
| 1396 | auto_nego |= ADVERTISE_100HALF; |
| 1397 | if (adv & ADVERTISED_100baseT_Full) |
| 1398 | auto_nego |= ADVERTISE_100FULL; |
| 1399 | |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1400 | auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 1401 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1402 | giga_ctrl = rtl_readphy(tp, MII_CTRL1000); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1403 | giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); |
| 1404 | |
| 1405 | /* The 8100e/8101e/8102e do Fast Ethernet only. */ |
Francois Romieu | 826e6cb | 2011-03-11 20:30:24 +0100 | [diff] [blame] | 1406 | if (tp->mii.supports_gmii) { |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1407 | if (adv & ADVERTISED_1000baseT_Half) |
| 1408 | giga_ctrl |= ADVERTISE_1000HALF; |
| 1409 | if (adv & ADVERTISED_1000baseT_Full) |
| 1410 | giga_ctrl |= ADVERTISE_1000FULL; |
| 1411 | } else if (adv & (ADVERTISED_1000baseT_Half | |
| 1412 | ADVERTISED_1000baseT_Full)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1413 | netif_info(tp, link, dev, |
| 1414 | "PHY does not support 1000Mbps\n"); |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1415 | goto out; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 1416 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1417 | |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1418 | bmcr = BMCR_ANENABLE | BMCR_ANRESTART; |
Francois Romieu | 623a159 | 2006-05-14 12:42:14 +0200 | [diff] [blame] | 1419 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1420 | rtl_writephy(tp, MII_ADVERTISE, auto_nego); |
| 1421 | rtl_writephy(tp, MII_CTRL1000, giga_ctrl); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1422 | } else { |
| 1423 | giga_ctrl = 0; |
| 1424 | |
| 1425 | if (speed == SPEED_10) |
| 1426 | bmcr = 0; |
| 1427 | else if (speed == SPEED_100) |
| 1428 | bmcr = BMCR_SPEED100; |
| 1429 | else |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1430 | goto out; |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1431 | |
| 1432 | if (duplex == DUPLEX_FULL) |
| 1433 | bmcr |= BMCR_FULLDPLX; |
Roger So | 2584fbc | 2007-07-31 23:52:42 +0200 | [diff] [blame] | 1434 | } |
| 1435 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1436 | rtl_writephy(tp, MII_BMCR, bmcr); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1437 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1438 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 1439 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1440 | if ((speed == SPEED_100) && (autoneg != AUTONEG_ENABLE)) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1441 | rtl_writephy(tp, 0x17, 0x2138); |
| 1442 | rtl_writephy(tp, 0x0e, 0x0260); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1443 | } else { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1444 | rtl_writephy(tp, 0x17, 0x2108); |
| 1445 | rtl_writephy(tp, 0x0e, 0x0000); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1446 | } |
| 1447 | } |
| 1448 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1449 | rc = 0; |
| 1450 | out: |
| 1451 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1452 | } |
| 1453 | |
| 1454 | static int rtl8169_set_speed(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1455 | u8 autoneg, u16 speed, u8 duplex, u32 advertising) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1456 | { |
| 1457 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1458 | int ret; |
| 1459 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1460 | ret = tp->set_speed(dev, autoneg, speed, duplex, advertising); |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1461 | if (ret < 0) |
| 1462 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1463 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1464 | if (netif_running(dev) && (autoneg == AUTONEG_ENABLE) && |
| 1465 | (advertising & ADVERTISED_1000baseT_Full)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1466 | mod_timer(&tp->timer, jiffies + RTL8169_PHY_TIMEOUT); |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1467 | } |
| 1468 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | return ret; |
| 1470 | } |
| 1471 | |
| 1472 | static int rtl8169_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 1473 | { |
| 1474 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1475 | unsigned long flags; |
| 1476 | int ret; |
| 1477 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 1478 | del_timer_sync(&tp->timer); |
| 1479 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1480 | spin_lock_irqsave(&tp->lock, flags); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1481 | ret = rtl8169_set_speed(dev, cmd->autoneg, ethtool_cmd_speed(cmd), |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 1482 | cmd->duplex, cmd->advertising); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | spin_unlock_irqrestore(&tp->lock, flags); |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1484 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1485 | return ret; |
| 1486 | } |
| 1487 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1488 | static u32 rtl8169_fix_features(struct net_device *dev, u32 features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 1490 | if (dev->mtu > TD_MSS_MAX) |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1491 | features &= ~NETIF_F_ALL_TSO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1492 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1493 | return features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | } |
| 1495 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1496 | static int rtl8169_set_features(struct net_device *dev, u32 features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1497 | { |
| 1498 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1499 | void __iomem *ioaddr = tp->mmio_addr; |
| 1500 | unsigned long flags; |
| 1501 | |
| 1502 | spin_lock_irqsave(&tp->lock, flags); |
| 1503 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1504 | if (features & NETIF_F_RXCSUM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | tp->cp_cmd |= RxChkSum; |
| 1506 | else |
| 1507 | tp->cp_cmd &= ~RxChkSum; |
| 1508 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1509 | if (dev->features & NETIF_F_HW_VLAN_RX) |
| 1510 | tp->cp_cmd |= RxVlan; |
| 1511 | else |
| 1512 | tp->cp_cmd &= ~RxVlan; |
| 1513 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1514 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 1515 | RTL_R16(CPlusCmd); |
| 1516 | |
| 1517 | spin_unlock_irqrestore(&tp->lock, flags); |
| 1518 | |
| 1519 | return 0; |
| 1520 | } |
| 1521 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1522 | static inline u32 rtl8169_tx_vlan_tag(struct rtl8169_private *tp, |
| 1523 | struct sk_buff *skb) |
| 1524 | { |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 1525 | return (vlan_tx_tag_present(skb)) ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | TxVlanTag | swab16(vlan_tx_tag_get(skb)) : 0x00; |
| 1527 | } |
| 1528 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1529 | 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] | 1530 | { |
| 1531 | u32 opts2 = le32_to_cpu(desc->opts2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1533 | if (opts2 & RxVlanTag) |
| 1534 | __vlan_hwaccel_put_tag(skb, swab16(opts2 & 0xffff)); |
Eric Dumazet | 2edae08 | 2010-09-06 18:46:39 +0000 | [diff] [blame] | 1535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | desc->opts2 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | } |
| 1538 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1539 | 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] | 1540 | { |
| 1541 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1542 | void __iomem *ioaddr = tp->mmio_addr; |
| 1543 | u32 status; |
| 1544 | |
| 1545 | cmd->supported = |
| 1546 | SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE; |
| 1547 | cmd->port = PORT_FIBRE; |
| 1548 | cmd->transceiver = XCVR_INTERNAL; |
| 1549 | |
| 1550 | status = RTL_R32(TBICSR); |
| 1551 | cmd->advertising = (status & TBINwEnable) ? ADVERTISED_Autoneg : 0; |
| 1552 | cmd->autoneg = !!(status & TBINwEnable); |
| 1553 | |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 1554 | ethtool_cmd_speed_set(cmd, SPEED_1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1555 | cmd->duplex = DUPLEX_FULL; /* Always set */ |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1556 | |
| 1557 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1558 | } |
| 1559 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1560 | 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] | 1561 | { |
| 1562 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1563 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1564 | return mii_ethtool_gset(&tp->mii, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1565 | } |
| 1566 | |
| 1567 | static int rtl8169_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 1568 | { |
| 1569 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1570 | unsigned long flags; |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1571 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1572 | |
| 1573 | spin_lock_irqsave(&tp->lock, flags); |
| 1574 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1575 | rc = tp->get_settings(dev, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | |
| 1577 | spin_unlock_irqrestore(&tp->lock, flags); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1578 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1579 | } |
| 1580 | |
| 1581 | static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 1582 | void *p) |
| 1583 | { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1584 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1585 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1586 | |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1587 | if (regs->len > R8169_REGS_SIZE) |
| 1588 | regs->len = R8169_REGS_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1589 | |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1590 | spin_lock_irqsave(&tp->lock, flags); |
| 1591 | memcpy_fromio(p, tp->mmio_addr, regs->len); |
| 1592 | spin_unlock_irqrestore(&tp->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | } |
| 1594 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1595 | static u32 rtl8169_get_msglevel(struct net_device *dev) |
| 1596 | { |
| 1597 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1598 | |
| 1599 | return tp->msg_enable; |
| 1600 | } |
| 1601 | |
| 1602 | static void rtl8169_set_msglevel(struct net_device *dev, u32 value) |
| 1603 | { |
| 1604 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1605 | |
| 1606 | tp->msg_enable = value; |
| 1607 | } |
| 1608 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1609 | static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = { |
| 1610 | "tx_packets", |
| 1611 | "rx_packets", |
| 1612 | "tx_errors", |
| 1613 | "rx_errors", |
| 1614 | "rx_missed", |
| 1615 | "align_errors", |
| 1616 | "tx_single_collisions", |
| 1617 | "tx_multi_collisions", |
| 1618 | "unicast", |
| 1619 | "broadcast", |
| 1620 | "multicast", |
| 1621 | "tx_aborted", |
| 1622 | "tx_underrun", |
| 1623 | }; |
| 1624 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1625 | static int rtl8169_get_sset_count(struct net_device *dev, int sset) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1626 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1627 | switch (sset) { |
| 1628 | case ETH_SS_STATS: |
| 1629 | return ARRAY_SIZE(rtl8169_gstrings); |
| 1630 | default: |
| 1631 | return -EOPNOTSUPP; |
| 1632 | } |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1633 | } |
| 1634 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1635 | static void rtl8169_update_counters(struct net_device *dev) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1636 | { |
| 1637 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1638 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1639 | struct device *d = &tp->pci_dev->dev; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1640 | struct rtl8169_counters *counters; |
| 1641 | dma_addr_t paddr; |
| 1642 | u32 cmd; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1643 | int wait = 1000; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1644 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1645 | /* |
| 1646 | * Some chips are unable to dump tally counters when the receiver |
| 1647 | * is disabled. |
| 1648 | */ |
| 1649 | if ((RTL_R8(ChipCmd) & CmdRxEnb) == 0) |
| 1650 | return; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1651 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 1652 | counters = dma_alloc_coherent(d, sizeof(*counters), &paddr, GFP_KERNEL); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1653 | if (!counters) |
| 1654 | return; |
| 1655 | |
| 1656 | RTL_W32(CounterAddrHigh, (u64)paddr >> 32); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1657 | cmd = (u64)paddr & DMA_BIT_MASK(32); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1658 | RTL_W32(CounterAddrLow, cmd); |
| 1659 | RTL_W32(CounterAddrLow, cmd | CounterDump); |
| 1660 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1661 | while (wait--) { |
| 1662 | if ((RTL_R32(CounterAddrLow) & CounterDump) == 0) { |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1663 | memcpy(&tp->counters, counters, sizeof(*counters)); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1664 | break; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1665 | } |
| 1666 | udelay(10); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | RTL_W32(CounterAddrLow, 0); |
| 1670 | RTL_W32(CounterAddrHigh, 0); |
| 1671 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 1672 | dma_free_coherent(d, sizeof(*counters), counters, paddr); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1673 | } |
| 1674 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1675 | static void rtl8169_get_ethtool_stats(struct net_device *dev, |
| 1676 | struct ethtool_stats *stats, u64 *data) |
| 1677 | { |
| 1678 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1679 | |
| 1680 | ASSERT_RTNL(); |
| 1681 | |
| 1682 | rtl8169_update_counters(dev); |
| 1683 | |
| 1684 | data[0] = le64_to_cpu(tp->counters.tx_packets); |
| 1685 | data[1] = le64_to_cpu(tp->counters.rx_packets); |
| 1686 | data[2] = le64_to_cpu(tp->counters.tx_errors); |
| 1687 | data[3] = le32_to_cpu(tp->counters.rx_errors); |
| 1688 | data[4] = le16_to_cpu(tp->counters.rx_missed); |
| 1689 | data[5] = le16_to_cpu(tp->counters.align_errors); |
| 1690 | data[6] = le32_to_cpu(tp->counters.tx_one_collision); |
| 1691 | data[7] = le32_to_cpu(tp->counters.tx_multi_collision); |
| 1692 | data[8] = le64_to_cpu(tp->counters.rx_unicast); |
| 1693 | data[9] = le64_to_cpu(tp->counters.rx_broadcast); |
| 1694 | data[10] = le32_to_cpu(tp->counters.rx_multicast); |
| 1695 | data[11] = le16_to_cpu(tp->counters.tx_aborted); |
| 1696 | data[12] = le16_to_cpu(tp->counters.tx_underun); |
| 1697 | } |
| 1698 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1699 | static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 1700 | { |
| 1701 | switch(stringset) { |
| 1702 | case ETH_SS_STATS: |
| 1703 | memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings)); |
| 1704 | break; |
| 1705 | } |
| 1706 | } |
| 1707 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 1708 | static const struct ethtool_ops rtl8169_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1709 | .get_drvinfo = rtl8169_get_drvinfo, |
| 1710 | .get_regs_len = rtl8169_get_regs_len, |
| 1711 | .get_link = ethtool_op_get_link, |
| 1712 | .get_settings = rtl8169_get_settings, |
| 1713 | .set_settings = rtl8169_set_settings, |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1714 | .get_msglevel = rtl8169_get_msglevel, |
| 1715 | .set_msglevel = rtl8169_set_msglevel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1716 | .get_regs = rtl8169_get_regs, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1717 | .get_wol = rtl8169_get_wol, |
| 1718 | .set_wol = rtl8169_set_wol, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1719 | .get_strings = rtl8169_get_strings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1720 | .get_sset_count = rtl8169_get_sset_count, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1721 | .get_ethtool_stats = rtl8169_get_ethtool_stats, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1722 | }; |
| 1723 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 1724 | static void rtl8169_get_mac_version(struct rtl8169_private *tp, |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 1725 | struct net_device *dev, u8 default_version) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1726 | { |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 1727 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 1728 | /* |
| 1729 | * The driver currently handles the 8168Bf and the 8168Be identically |
| 1730 | * but they can be identified more specifically through the test below |
| 1731 | * if needed: |
| 1732 | * |
| 1733 | * (RTL_R32(TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be |
Francois Romieu | 0127215 | 2007-02-20 22:58:51 +0100 | [diff] [blame] | 1734 | * |
| 1735 | * Same thing for the 8101Eb and the 8101Ec: |
| 1736 | * |
| 1737 | * (RTL_R32(TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 1738 | */ |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 1739 | static const struct rtl_mac_info { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1740 | u32 mask; |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 1741 | u32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1742 | int mac_version; |
| 1743 | } mac_info[] = { |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 1744 | /* 8168E family. */ |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 1745 | { 0x7c800000, 0x2c800000, RTL_GIGA_MAC_VER_34 }, |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 1746 | { 0x7cf00000, 0x2c200000, RTL_GIGA_MAC_VER_33 }, |
| 1747 | { 0x7cf00000, 0x2c100000, RTL_GIGA_MAC_VER_32 }, |
| 1748 | { 0x7c800000, 0x2c000000, RTL_GIGA_MAC_VER_33 }, |
| 1749 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 1750 | /* 8168D family. */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1751 | { 0x7cf00000, 0x28300000, RTL_GIGA_MAC_VER_26 }, |
| 1752 | { 0x7cf00000, 0x28100000, RTL_GIGA_MAC_VER_25 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1753 | { 0x7c800000, 0x28000000, RTL_GIGA_MAC_VER_26 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 1754 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1755 | /* 8168DP family. */ |
| 1756 | { 0x7cf00000, 0x28800000, RTL_GIGA_MAC_VER_27 }, |
| 1757 | { 0x7cf00000, 0x28a00000, RTL_GIGA_MAC_VER_28 }, |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 1758 | { 0x7cf00000, 0x28b00000, RTL_GIGA_MAC_VER_31 }, |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1759 | |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 1760 | /* 8168C family. */ |
Francois Romieu | 17c9929 | 2010-07-11 17:10:09 -0700 | [diff] [blame] | 1761 | { 0x7cf00000, 0x3cb00000, RTL_GIGA_MAC_VER_24 }, |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 1762 | { 0x7cf00000, 0x3c900000, RTL_GIGA_MAC_VER_23 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 1763 | { 0x7cf00000, 0x3c800000, RTL_GIGA_MAC_VER_18 }, |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 1764 | { 0x7c800000, 0x3c800000, RTL_GIGA_MAC_VER_24 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 1765 | { 0x7cf00000, 0x3c000000, RTL_GIGA_MAC_VER_19 }, |
| 1766 | { 0x7cf00000, 0x3c200000, RTL_GIGA_MAC_VER_20 }, |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 1767 | { 0x7cf00000, 0x3c300000, RTL_GIGA_MAC_VER_21 }, |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 1768 | { 0x7cf00000, 0x3c400000, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 1769 | { 0x7c800000, 0x3c000000, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 1770 | |
| 1771 | /* 8168B family. */ |
| 1772 | { 0x7cf00000, 0x38000000, RTL_GIGA_MAC_VER_12 }, |
| 1773 | { 0x7cf00000, 0x38500000, RTL_GIGA_MAC_VER_17 }, |
| 1774 | { 0x7c800000, 0x38000000, RTL_GIGA_MAC_VER_17 }, |
| 1775 | { 0x7c800000, 0x30000000, RTL_GIGA_MAC_VER_11 }, |
| 1776 | |
| 1777 | /* 8101 family. */ |
hayeswang | 36a0e6c | 2011-03-21 01:50:30 +0000 | [diff] [blame] | 1778 | { 0x7cf00000, 0x40b00000, RTL_GIGA_MAC_VER_30 }, |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 1779 | { 0x7cf00000, 0x40a00000, RTL_GIGA_MAC_VER_30 }, |
| 1780 | { 0x7cf00000, 0x40900000, RTL_GIGA_MAC_VER_29 }, |
| 1781 | { 0x7c800000, 0x40800000, RTL_GIGA_MAC_VER_30 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 1782 | { 0x7cf00000, 0x34a00000, RTL_GIGA_MAC_VER_09 }, |
| 1783 | { 0x7cf00000, 0x24a00000, RTL_GIGA_MAC_VER_09 }, |
| 1784 | { 0x7cf00000, 0x34900000, RTL_GIGA_MAC_VER_08 }, |
| 1785 | { 0x7cf00000, 0x24900000, RTL_GIGA_MAC_VER_08 }, |
| 1786 | { 0x7cf00000, 0x34800000, RTL_GIGA_MAC_VER_07 }, |
| 1787 | { 0x7cf00000, 0x24800000, RTL_GIGA_MAC_VER_07 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 1788 | { 0x7cf00000, 0x34000000, RTL_GIGA_MAC_VER_13 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 1789 | { 0x7cf00000, 0x34300000, RTL_GIGA_MAC_VER_10 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 1790 | { 0x7cf00000, 0x34200000, RTL_GIGA_MAC_VER_16 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 1791 | { 0x7c800000, 0x34800000, RTL_GIGA_MAC_VER_09 }, |
| 1792 | { 0x7c800000, 0x24800000, RTL_GIGA_MAC_VER_09 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 1793 | { 0x7c800000, 0x34000000, RTL_GIGA_MAC_VER_16 }, |
| 1794 | /* FIXME: where did these entries come from ? -- FR */ |
| 1795 | { 0xfc800000, 0x38800000, RTL_GIGA_MAC_VER_15 }, |
| 1796 | { 0xfc800000, 0x30800000, RTL_GIGA_MAC_VER_14 }, |
| 1797 | |
| 1798 | /* 8110 family. */ |
| 1799 | { 0xfc800000, 0x98000000, RTL_GIGA_MAC_VER_06 }, |
| 1800 | { 0xfc800000, 0x18000000, RTL_GIGA_MAC_VER_05 }, |
| 1801 | { 0xfc800000, 0x10000000, RTL_GIGA_MAC_VER_04 }, |
| 1802 | { 0xfc800000, 0x04000000, RTL_GIGA_MAC_VER_03 }, |
| 1803 | { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 }, |
| 1804 | { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 }, |
| 1805 | |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 1806 | /* Catch-all */ |
| 1807 | { 0x00000000, 0x00000000, RTL_GIGA_MAC_NONE } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 1808 | }; |
| 1809 | const struct rtl_mac_info *p = mac_info; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | u32 reg; |
| 1811 | |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 1812 | reg = RTL_R32(TxConfig); |
| 1813 | while ((reg & p->mask) != p->val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1814 | p++; |
| 1815 | tp->mac_version = p->mac_version; |
Francois Romieu | 5d320a2 | 2011-05-08 17:47:36 +0200 | [diff] [blame] | 1816 | |
| 1817 | if (tp->mac_version == RTL_GIGA_MAC_NONE) { |
| 1818 | netif_notice(tp, probe, dev, |
| 1819 | "unknown MAC, using family default\n"); |
| 1820 | tp->mac_version = default_version; |
| 1821 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1822 | } |
| 1823 | |
| 1824 | static void rtl8169_print_mac_version(struct rtl8169_private *tp) |
| 1825 | { |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 1826 | dprintk("mac_version = 0x%02x\n", tp->mac_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1827 | } |
| 1828 | |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 1829 | struct phy_reg { |
| 1830 | u16 reg; |
| 1831 | u16 val; |
| 1832 | }; |
| 1833 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1834 | static void rtl_writephy_batch(struct rtl8169_private *tp, |
| 1835 | const struct phy_reg *regs, int len) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 1836 | { |
| 1837 | while (len-- > 0) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1838 | rtl_writephy(tp, regs->reg, regs->val); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 1839 | regs++; |
| 1840 | } |
| 1841 | } |
| 1842 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 1843 | #define PHY_READ 0x00000000 |
| 1844 | #define PHY_DATA_OR 0x10000000 |
| 1845 | #define PHY_DATA_AND 0x20000000 |
| 1846 | #define PHY_BJMPN 0x30000000 |
| 1847 | #define PHY_READ_EFUSE 0x40000000 |
| 1848 | #define PHY_READ_MAC_BYTE 0x50000000 |
| 1849 | #define PHY_WRITE_MAC_BYTE 0x60000000 |
| 1850 | #define PHY_CLEAR_READCOUNT 0x70000000 |
| 1851 | #define PHY_WRITE 0x80000000 |
| 1852 | #define PHY_READCOUNT_EQ_SKIP 0x90000000 |
| 1853 | #define PHY_COMP_EQ_SKIPN 0xa0000000 |
| 1854 | #define PHY_COMP_NEQ_SKIPN 0xb0000000 |
| 1855 | #define PHY_WRITE_PREVIOUS 0xc0000000 |
| 1856 | #define PHY_SKIPN 0xd0000000 |
| 1857 | #define PHY_DELAY_MS 0xe0000000 |
| 1858 | #define PHY_WRITE_ERI_WORD 0xf0000000 |
| 1859 | |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 1860 | struct fw_info { |
| 1861 | u32 magic; |
| 1862 | char version[RTL_VER_SIZE]; |
| 1863 | __le32 fw_start; |
| 1864 | __le32 fw_len; |
| 1865 | u8 chksum; |
| 1866 | } __packed; |
| 1867 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 1868 | #define FW_OPCODE_SIZE sizeof(typeof(*((struct rtl_fw_phy_action *)0)->code)) |
| 1869 | |
| 1870 | 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] | 1871 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 1872 | const struct firmware *fw = rtl_fw->fw; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 1873 | struct fw_info *fw_info = (struct fw_info *)fw->data; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 1874 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
| 1875 | char *version = rtl_fw->version; |
| 1876 | bool rc = false; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 1877 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 1878 | if (fw->size < FW_OPCODE_SIZE) |
| 1879 | goto out; |
Hayes Wang | 960aee6 | 2011-06-18 11:37:48 +0200 | [diff] [blame] | 1880 | |
| 1881 | if (!fw_info->magic) { |
| 1882 | size_t i, size, start; |
| 1883 | u8 checksum = 0; |
| 1884 | |
| 1885 | if (fw->size < sizeof(*fw_info)) |
| 1886 | goto out; |
| 1887 | |
| 1888 | for (i = 0; i < fw->size; i++) |
| 1889 | checksum += fw->data[i]; |
| 1890 | if (checksum != 0) |
| 1891 | goto out; |
| 1892 | |
| 1893 | start = le32_to_cpu(fw_info->fw_start); |
| 1894 | if (start > fw->size) |
| 1895 | goto out; |
| 1896 | |
| 1897 | size = le32_to_cpu(fw_info->fw_len); |
| 1898 | if (size > (fw->size - start) / FW_OPCODE_SIZE) |
| 1899 | goto out; |
| 1900 | |
| 1901 | memcpy(version, fw_info->version, RTL_VER_SIZE); |
| 1902 | |
| 1903 | pa->code = (__le32 *)(fw->data + start); |
| 1904 | pa->size = size; |
| 1905 | } else { |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 1906 | if (fw->size % FW_OPCODE_SIZE) |
| 1907 | goto out; |
| 1908 | |
| 1909 | strlcpy(version, rtl_lookup_firmware_name(tp), RTL_VER_SIZE); |
| 1910 | |
| 1911 | pa->code = (__le32 *)fw->data; |
| 1912 | pa->size = fw->size / FW_OPCODE_SIZE; |
| 1913 | } |
| 1914 | version[RTL_VER_SIZE - 1] = 0; |
| 1915 | |
| 1916 | rc = true; |
| 1917 | out: |
| 1918 | return rc; |
| 1919 | } |
| 1920 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 1921 | static bool rtl_fw_data_ok(struct rtl8169_private *tp, struct net_device *dev, |
| 1922 | struct rtl_fw_phy_action *pa) |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 1923 | { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 1924 | bool rc = false; |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 1925 | size_t index; |
| 1926 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 1927 | for (index = 0; index < pa->size; index++) { |
| 1928 | u32 action = le32_to_cpu(pa->code[index]); |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 1929 | u32 regno = (action & 0x0fff0000) >> 16; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 1930 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 1931 | switch(action & 0xf0000000) { |
| 1932 | case PHY_READ: |
| 1933 | case PHY_DATA_OR: |
| 1934 | case PHY_DATA_AND: |
| 1935 | case PHY_READ_EFUSE: |
| 1936 | case PHY_CLEAR_READCOUNT: |
| 1937 | case PHY_WRITE: |
| 1938 | case PHY_WRITE_PREVIOUS: |
| 1939 | case PHY_DELAY_MS: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 1940 | break; |
| 1941 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 1942 | case PHY_BJMPN: |
| 1943 | if (regno > index) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 1944 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1945 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 1946 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 1947 | } |
| 1948 | break; |
| 1949 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 1950 | if (index + 2 >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 1951 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1952 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 1953 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 1954 | } |
| 1955 | break; |
| 1956 | case PHY_COMP_EQ_SKIPN: |
| 1957 | case PHY_COMP_NEQ_SKIPN: |
| 1958 | case PHY_SKIPN: |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 1959 | if (index + 1 + regno >= pa->size) { |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 1960 | netif_err(tp, ifup, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1961 | "Out of range of firmware\n"); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 1962 | goto out; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 1963 | } |
| 1964 | break; |
| 1965 | |
| 1966 | case PHY_READ_MAC_BYTE: |
| 1967 | case PHY_WRITE_MAC_BYTE: |
| 1968 | case PHY_WRITE_ERI_WORD: |
| 1969 | default: |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 1970 | netif_err(tp, ifup, tp->dev, |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 1971 | "Invalid action 0x%08x\n", action); |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 1972 | goto out; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 1973 | } |
| 1974 | } |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 1975 | rc = true; |
| 1976 | out: |
| 1977 | return rc; |
| 1978 | } |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 1979 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 1980 | static int rtl_check_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 1981 | { |
| 1982 | struct net_device *dev = tp->dev; |
| 1983 | int rc = -EINVAL; |
| 1984 | |
| 1985 | if (!rtl_fw_format_ok(tp, rtl_fw)) { |
| 1986 | netif_err(tp, ifup, dev, "invalid firwmare\n"); |
| 1987 | goto out; |
| 1988 | } |
| 1989 | |
| 1990 | if (rtl_fw_data_ok(tp, dev, &rtl_fw->phy_action)) |
| 1991 | rc = 0; |
| 1992 | out: |
| 1993 | return rc; |
| 1994 | } |
| 1995 | |
| 1996 | static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
| 1997 | { |
| 1998 | struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
| 1999 | u32 predata, count; |
| 2000 | size_t index; |
| 2001 | |
| 2002 | predata = count = 0; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2003 | |
Francois Romieu | 1c361ef | 2011-06-17 17:16:24 +0200 | [diff] [blame] | 2004 | for (index = 0; index < pa->size; ) { |
| 2005 | u32 action = le32_to_cpu(pa->code[index]); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2006 | u32 data = action & 0x0000ffff; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2007 | u32 regno = (action & 0x0fff0000) >> 16; |
| 2008 | |
| 2009 | if (!action) |
| 2010 | break; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2011 | |
| 2012 | switch(action & 0xf0000000) { |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2013 | case PHY_READ: |
| 2014 | predata = rtl_readphy(tp, regno); |
| 2015 | count++; |
| 2016 | index++; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2017 | break; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2018 | case PHY_DATA_OR: |
| 2019 | predata |= data; |
| 2020 | index++; |
| 2021 | break; |
| 2022 | case PHY_DATA_AND: |
| 2023 | predata &= data; |
| 2024 | index++; |
| 2025 | break; |
| 2026 | case PHY_BJMPN: |
| 2027 | index -= regno; |
| 2028 | break; |
| 2029 | case PHY_READ_EFUSE: |
| 2030 | predata = rtl8168d_efuse_read(tp->mmio_addr, regno); |
| 2031 | index++; |
| 2032 | break; |
| 2033 | case PHY_CLEAR_READCOUNT: |
| 2034 | count = 0; |
| 2035 | index++; |
| 2036 | break; |
| 2037 | case PHY_WRITE: |
| 2038 | rtl_writephy(tp, regno, data); |
| 2039 | index++; |
| 2040 | break; |
| 2041 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2042 | index += (count == data) ? 2 : 1; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 2043 | break; |
| 2044 | case PHY_COMP_EQ_SKIPN: |
| 2045 | if (predata == data) |
| 2046 | index += regno; |
| 2047 | index++; |
| 2048 | break; |
| 2049 | case PHY_COMP_NEQ_SKIPN: |
| 2050 | if (predata != data) |
| 2051 | index += regno; |
| 2052 | index++; |
| 2053 | break; |
| 2054 | case PHY_WRITE_PREVIOUS: |
| 2055 | rtl_writephy(tp, regno, predata); |
| 2056 | index++; |
| 2057 | break; |
| 2058 | case PHY_SKIPN: |
| 2059 | index += regno + 1; |
| 2060 | break; |
| 2061 | case PHY_DELAY_MS: |
| 2062 | mdelay(data); |
| 2063 | index++; |
| 2064 | break; |
| 2065 | |
| 2066 | case PHY_READ_MAC_BYTE: |
| 2067 | case PHY_WRITE_MAC_BYTE: |
| 2068 | case PHY_WRITE_ERI_WORD: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2069 | default: |
| 2070 | BUG(); |
| 2071 | } |
| 2072 | } |
| 2073 | } |
| 2074 | |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2075 | static void rtl_release_firmware(struct rtl8169_private *tp) |
| 2076 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2077 | if (!IS_ERR_OR_NULL(tp->rtl_fw)) { |
| 2078 | release_firmware(tp->rtl_fw->fw); |
| 2079 | kfree(tp->rtl_fw); |
| 2080 | } |
| 2081 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2082 | } |
| 2083 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2084 | static void rtl_apply_firmware(struct rtl8169_private *tp) |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2085 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2086 | struct rtl_fw *rtl_fw = tp->rtl_fw; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2087 | |
| 2088 | /* TODO: release firmware once rtl_phy_write_fw signals failures. */ |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 2089 | if (!IS_ERR_OR_NULL(rtl_fw)) |
| 2090 | rtl_phy_write_fw(tp, rtl_fw); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2091 | } |
| 2092 | |
| 2093 | static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val) |
| 2094 | { |
| 2095 | if (rtl_readphy(tp, reg) != val) |
| 2096 | netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n"); |
| 2097 | else |
| 2098 | rtl_apply_firmware(tp); |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 2099 | } |
| 2100 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2101 | static void rtl8169s_hw_phy_config(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2102 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2103 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2104 | { 0x1f, 0x0001 }, |
| 2105 | { 0x06, 0x006e }, |
| 2106 | { 0x08, 0x0708 }, |
| 2107 | { 0x15, 0x4000 }, |
| 2108 | { 0x18, 0x65c7 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2109 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2110 | { 0x1f, 0x0001 }, |
| 2111 | { 0x03, 0x00a1 }, |
| 2112 | { 0x02, 0x0008 }, |
| 2113 | { 0x01, 0x0120 }, |
| 2114 | { 0x00, 0x1000 }, |
| 2115 | { 0x04, 0x0800 }, |
| 2116 | { 0x04, 0x0000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2117 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2118 | { 0x03, 0xff41 }, |
| 2119 | { 0x02, 0xdf60 }, |
| 2120 | { 0x01, 0x0140 }, |
| 2121 | { 0x00, 0x0077 }, |
| 2122 | { 0x04, 0x7800 }, |
| 2123 | { 0x04, 0x7000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2124 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 2125 | { 0x03, 0x802f }, |
| 2126 | { 0x02, 0x4f02 }, |
| 2127 | { 0x01, 0x0409 }, |
| 2128 | { 0x00, 0xf0f9 }, |
| 2129 | { 0x04, 0x9800 }, |
| 2130 | { 0x04, 0x9000 }, |
| 2131 | |
| 2132 | { 0x03, 0xdf01 }, |
| 2133 | { 0x02, 0xdf20 }, |
| 2134 | { 0x01, 0xff95 }, |
| 2135 | { 0x00, 0xba00 }, |
| 2136 | { 0x04, 0xa800 }, |
| 2137 | { 0x04, 0xa000 }, |
| 2138 | |
| 2139 | { 0x03, 0xff41 }, |
| 2140 | { 0x02, 0xdf20 }, |
| 2141 | { 0x01, 0x0140 }, |
| 2142 | { 0x00, 0x00bb }, |
| 2143 | { 0x04, 0xb800 }, |
| 2144 | { 0x04, 0xb000 }, |
| 2145 | |
| 2146 | { 0x03, 0xdf41 }, |
| 2147 | { 0x02, 0xdc60 }, |
| 2148 | { 0x01, 0x6340 }, |
| 2149 | { 0x00, 0x007d }, |
| 2150 | { 0x04, 0xd800 }, |
| 2151 | { 0x04, 0xd000 }, |
| 2152 | |
| 2153 | { 0x03, 0xdf01 }, |
| 2154 | { 0x02, 0xdf20 }, |
| 2155 | { 0x01, 0x100a }, |
| 2156 | { 0x00, 0xa0ff }, |
| 2157 | { 0x04, 0xf800 }, |
| 2158 | { 0x04, 0xf000 }, |
| 2159 | |
| 2160 | { 0x1f, 0x0000 }, |
| 2161 | { 0x0b, 0x0000 }, |
| 2162 | { 0x00, 0x9200 } |
| 2163 | }; |
| 2164 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2165 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2166 | } |
| 2167 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2168 | static void rtl8169sb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2169 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2170 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a441d7b | 2007-08-17 18:26:35 +0200 | [diff] [blame] | 2171 | { 0x1f, 0x0002 }, |
| 2172 | { 0x01, 0x90d0 }, |
| 2173 | { 0x1f, 0x0000 } |
| 2174 | }; |
| 2175 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2176 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2177 | } |
| 2178 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2179 | static void rtl8169scd_hw_phy_config_quirk(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2180 | { |
| 2181 | struct pci_dev *pdev = tp->pci_dev; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2182 | |
Sergei Shtylyov | ccbae55 | 2011-07-22 05:37:24 +0000 | [diff] [blame] | 2183 | if ((pdev->subsystem_vendor != PCI_VENDOR_ID_GIGABYTE) || |
| 2184 | (pdev->subsystem_device != 0xe000)) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2185 | return; |
| 2186 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2187 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2188 | rtl_writephy(tp, 0x10, 0xf01b); |
| 2189 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2190 | } |
| 2191 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2192 | static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2193 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2194 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2195 | { 0x1f, 0x0001 }, |
| 2196 | { 0x04, 0x0000 }, |
| 2197 | { 0x03, 0x00a1 }, |
| 2198 | { 0x02, 0x0008 }, |
| 2199 | { 0x01, 0x0120 }, |
| 2200 | { 0x00, 0x1000 }, |
| 2201 | { 0x04, 0x0800 }, |
| 2202 | { 0x04, 0x9000 }, |
| 2203 | { 0x03, 0x802f }, |
| 2204 | { 0x02, 0x4f02 }, |
| 2205 | { 0x01, 0x0409 }, |
| 2206 | { 0x00, 0xf099 }, |
| 2207 | { 0x04, 0x9800 }, |
| 2208 | { 0x04, 0xa000 }, |
| 2209 | { 0x03, 0xdf01 }, |
| 2210 | { 0x02, 0xdf20 }, |
| 2211 | { 0x01, 0xff95 }, |
| 2212 | { 0x00, 0xba00 }, |
| 2213 | { 0x04, 0xa800 }, |
| 2214 | { 0x04, 0xf000 }, |
| 2215 | { 0x03, 0xdf01 }, |
| 2216 | { 0x02, 0xdf20 }, |
| 2217 | { 0x01, 0x101a }, |
| 2218 | { 0x00, 0xa0ff }, |
| 2219 | { 0x04, 0xf800 }, |
| 2220 | { 0x04, 0x0000 }, |
| 2221 | { 0x1f, 0x0000 }, |
| 2222 | |
| 2223 | { 0x1f, 0x0001 }, |
| 2224 | { 0x10, 0xf41b }, |
| 2225 | { 0x14, 0xfb54 }, |
| 2226 | { 0x18, 0xf5c7 }, |
| 2227 | { 0x1f, 0x0000 }, |
| 2228 | |
| 2229 | { 0x1f, 0x0001 }, |
| 2230 | { 0x17, 0x0cc0 }, |
| 2231 | { 0x1f, 0x0000 } |
| 2232 | }; |
| 2233 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2234 | 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] | 2235 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2236 | rtl8169scd_hw_phy_config_quirk(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2237 | } |
| 2238 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2239 | static void rtl8169sce_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2240 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2241 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2242 | { 0x1f, 0x0001 }, |
| 2243 | { 0x04, 0x0000 }, |
| 2244 | { 0x03, 0x00a1 }, |
| 2245 | { 0x02, 0x0008 }, |
| 2246 | { 0x01, 0x0120 }, |
| 2247 | { 0x00, 0x1000 }, |
| 2248 | { 0x04, 0x0800 }, |
| 2249 | { 0x04, 0x9000 }, |
| 2250 | { 0x03, 0x802f }, |
| 2251 | { 0x02, 0x4f02 }, |
| 2252 | { 0x01, 0x0409 }, |
| 2253 | { 0x00, 0xf099 }, |
| 2254 | { 0x04, 0x9800 }, |
| 2255 | { 0x04, 0xa000 }, |
| 2256 | { 0x03, 0xdf01 }, |
| 2257 | { 0x02, 0xdf20 }, |
| 2258 | { 0x01, 0xff95 }, |
| 2259 | { 0x00, 0xba00 }, |
| 2260 | { 0x04, 0xa800 }, |
| 2261 | { 0x04, 0xf000 }, |
| 2262 | { 0x03, 0xdf01 }, |
| 2263 | { 0x02, 0xdf20 }, |
| 2264 | { 0x01, 0x101a }, |
| 2265 | { 0x00, 0xa0ff }, |
| 2266 | { 0x04, 0xf800 }, |
| 2267 | { 0x04, 0x0000 }, |
| 2268 | { 0x1f, 0x0000 }, |
| 2269 | |
| 2270 | { 0x1f, 0x0001 }, |
| 2271 | { 0x0b, 0x8480 }, |
| 2272 | { 0x1f, 0x0000 }, |
| 2273 | |
| 2274 | { 0x1f, 0x0001 }, |
| 2275 | { 0x18, 0x67c7 }, |
| 2276 | { 0x04, 0x2000 }, |
| 2277 | { 0x03, 0x002f }, |
| 2278 | { 0x02, 0x4360 }, |
| 2279 | { 0x01, 0x0109 }, |
| 2280 | { 0x00, 0x3022 }, |
| 2281 | { 0x04, 0x2800 }, |
| 2282 | { 0x1f, 0x0000 }, |
| 2283 | |
| 2284 | { 0x1f, 0x0001 }, |
| 2285 | { 0x17, 0x0cc0 }, |
| 2286 | { 0x1f, 0x0000 } |
| 2287 | }; |
| 2288 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2289 | 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] | 2290 | } |
| 2291 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2292 | static void rtl8168bb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2293 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2294 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2295 | { 0x10, 0xf41b }, |
| 2296 | { 0x1f, 0x0000 } |
| 2297 | }; |
| 2298 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2299 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2300 | rtl_patchphy(tp, 0x16, 1 << 0); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2301 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2302 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2303 | } |
| 2304 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2305 | static void rtl8168bef_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2306 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2307 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2308 | { 0x1f, 0x0001 }, |
| 2309 | { 0x10, 0xf41b }, |
| 2310 | { 0x1f, 0x0000 } |
| 2311 | }; |
| 2312 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2313 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2314 | } |
| 2315 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2316 | static void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2317 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2318 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2319 | { 0x1f, 0x0000 }, |
| 2320 | { 0x1d, 0x0f00 }, |
| 2321 | { 0x1f, 0x0002 }, |
| 2322 | { 0x0c, 0x1ec8 }, |
| 2323 | { 0x1f, 0x0000 } |
| 2324 | }; |
| 2325 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2326 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2327 | } |
| 2328 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2329 | static void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2330 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2331 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2332 | { 0x1f, 0x0001 }, |
| 2333 | { 0x1d, 0x3d98 }, |
| 2334 | { 0x1f, 0x0000 } |
| 2335 | }; |
| 2336 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2337 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2338 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2339 | rtl_patchphy(tp, 0x0d, 1 << 5); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2340 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2341 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2342 | } |
| 2343 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2344 | static void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2345 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2346 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a3f8067 | 2007-10-18 14:35:11 +0200 | [diff] [blame] | 2347 | { 0x1f, 0x0001 }, |
| 2348 | { 0x12, 0x2300 }, |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2349 | { 0x1f, 0x0002 }, |
| 2350 | { 0x00, 0x88d4 }, |
| 2351 | { 0x01, 0x82b1 }, |
| 2352 | { 0x03, 0x7002 }, |
| 2353 | { 0x08, 0x9e30 }, |
| 2354 | { 0x09, 0x01f0 }, |
| 2355 | { 0x0a, 0x5500 }, |
| 2356 | { 0x0c, 0x00c8 }, |
| 2357 | { 0x1f, 0x0003 }, |
| 2358 | { 0x12, 0xc096 }, |
| 2359 | { 0x16, 0x000a }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2360 | { 0x1f, 0x0000 }, |
| 2361 | { 0x1f, 0x0000 }, |
| 2362 | { 0x09, 0x2000 }, |
| 2363 | { 0x09, 0x0000 } |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2364 | }; |
| 2365 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2366 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2367 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2368 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2369 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2370 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2371 | } |
| 2372 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2373 | static void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2374 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2375 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2376 | { 0x1f, 0x0001 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2377 | { 0x12, 0x2300 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2378 | { 0x03, 0x802f }, |
| 2379 | { 0x02, 0x4f02 }, |
| 2380 | { 0x01, 0x0409 }, |
| 2381 | { 0x00, 0xf099 }, |
| 2382 | { 0x04, 0x9800 }, |
| 2383 | { 0x04, 0x9000 }, |
| 2384 | { 0x1d, 0x3d98 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2385 | { 0x1f, 0x0002 }, |
| 2386 | { 0x0c, 0x7eb8 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2387 | { 0x06, 0x0761 }, |
| 2388 | { 0x1f, 0x0003 }, |
| 2389 | { 0x16, 0x0f0a }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2390 | { 0x1f, 0x0000 } |
| 2391 | }; |
| 2392 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2393 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2394 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2395 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 2396 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2397 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2398 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2399 | } |
| 2400 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2401 | static void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2402 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2403 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2404 | { 0x1f, 0x0001 }, |
| 2405 | { 0x12, 0x2300 }, |
| 2406 | { 0x1d, 0x3d98 }, |
| 2407 | { 0x1f, 0x0002 }, |
| 2408 | { 0x0c, 0x7eb8 }, |
| 2409 | { 0x06, 0x5461 }, |
| 2410 | { 0x1f, 0x0003 }, |
| 2411 | { 0x16, 0x0f0a }, |
| 2412 | { 0x1f, 0x0000 } |
| 2413 | }; |
| 2414 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2415 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2416 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2417 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 2418 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2419 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2420 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2421 | } |
| 2422 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2423 | static void rtl8168c_4_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2424 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2425 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2426 | } |
| 2427 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2428 | static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2429 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2430 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2431 | /* Channel Estimation */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2432 | { 0x1f, 0x0001 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2433 | { 0x06, 0x4064 }, |
| 2434 | { 0x07, 0x2863 }, |
| 2435 | { 0x08, 0x059c }, |
| 2436 | { 0x09, 0x26b4 }, |
| 2437 | { 0x0a, 0x6a19 }, |
| 2438 | { 0x0b, 0xdcc8 }, |
| 2439 | { 0x10, 0xf06d }, |
| 2440 | { 0x14, 0x7f68 }, |
| 2441 | { 0x18, 0x7fd9 }, |
| 2442 | { 0x1c, 0xf0ff }, |
| 2443 | { 0x1d, 0x3d9c }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2444 | { 0x1f, 0x0003 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2445 | { 0x12, 0xf49f }, |
| 2446 | { 0x13, 0x070b }, |
| 2447 | { 0x1a, 0x05ad }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2448 | { 0x14, 0x94c0 }, |
| 2449 | |
| 2450 | /* |
| 2451 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2452 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2453 | */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2454 | { 0x1f, 0x0002 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2455 | { 0x06, 0x5561 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2456 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2457 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2458 | { 0x06, 0x5561 }, |
| 2459 | |
| 2460 | /* |
| 2461 | * Can not link to 1Gbps with bad cable |
| 2462 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 2463 | */ |
| 2464 | { 0x1f, 0x0001 }, |
| 2465 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2466 | |
| 2467 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2468 | { 0x0d, 0xf880 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2469 | }; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2470 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2471 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2472 | 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] | 2473 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2474 | /* |
| 2475 | * Rx Error Issue |
| 2476 | * Fine Tune Switching regulator parameter |
| 2477 | */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2478 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2479 | rtl_w1w0_phy(tp, 0x0b, 0x0010, 0x00ef); |
| 2480 | rtl_w1w0_phy(tp, 0x0c, 0xa200, 0x5d00); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2481 | |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2482 | if (rtl8168d_efuse_read(ioaddr, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2483 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2484 | { 0x1f, 0x0002 }, |
| 2485 | { 0x05, 0x669a }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2486 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2487 | { 0x05, 0x8330 }, |
| 2488 | { 0x06, 0x669a }, |
| 2489 | { 0x1f, 0x0002 } |
| 2490 | }; |
| 2491 | int val; |
| 2492 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2493 | 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] | 2494 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2495 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2496 | |
| 2497 | if ((val & 0x00ff) != 0x006c) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2498 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2499 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 2500 | 0x0069, 0x006a, 0x006b, 0x006c |
| 2501 | }; |
| 2502 | int i; |
| 2503 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2504 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2505 | |
| 2506 | val &= 0xff00; |
| 2507 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2508 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2509 | } |
| 2510 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2511 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2512 | { 0x1f, 0x0002 }, |
| 2513 | { 0x05, 0x6662 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2514 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2515 | { 0x05, 0x8330 }, |
| 2516 | { 0x06, 0x6662 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2517 | }; |
| 2518 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2519 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2520 | } |
| 2521 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2522 | /* RSET couple improve */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2523 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2524 | rtl_patchphy(tp, 0x0d, 0x0300); |
| 2525 | rtl_patchphy(tp, 0x0f, 0x0010); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2526 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2527 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2528 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2529 | rtl_w1w0_phy(tp, 0x02, 0x0100, 0x0600); |
| 2530 | rtl_w1w0_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2531 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2532 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2533 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2534 | |
| 2535 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2536 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2537 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2538 | } |
| 2539 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2540 | static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2541 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2542 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2543 | /* Channel Estimation */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2544 | { 0x1f, 0x0001 }, |
| 2545 | { 0x06, 0x4064 }, |
| 2546 | { 0x07, 0x2863 }, |
| 2547 | { 0x08, 0x059c }, |
| 2548 | { 0x09, 0x26b4 }, |
| 2549 | { 0x0a, 0x6a19 }, |
| 2550 | { 0x0b, 0xdcc8 }, |
| 2551 | { 0x10, 0xf06d }, |
| 2552 | { 0x14, 0x7f68 }, |
| 2553 | { 0x18, 0x7fd9 }, |
| 2554 | { 0x1c, 0xf0ff }, |
| 2555 | { 0x1d, 0x3d9c }, |
| 2556 | { 0x1f, 0x0003 }, |
| 2557 | { 0x12, 0xf49f }, |
| 2558 | { 0x13, 0x070b }, |
| 2559 | { 0x1a, 0x05ad }, |
| 2560 | { 0x14, 0x94c0 }, |
| 2561 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2562 | /* |
| 2563 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2564 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2565 | */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2566 | { 0x1f, 0x0002 }, |
| 2567 | { 0x06, 0x5561 }, |
| 2568 | { 0x1f, 0x0005 }, |
| 2569 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2570 | { 0x06, 0x5561 }, |
| 2571 | |
| 2572 | /* |
| 2573 | * Can not link to 1Gbps with bad cable |
| 2574 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 2575 | */ |
| 2576 | { 0x1f, 0x0001 }, |
| 2577 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2578 | |
| 2579 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2580 | { 0x0d, 0xf880 } |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2581 | }; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2582 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2583 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2584 | 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] | 2585 | |
| 2586 | if (rtl8168d_efuse_read(ioaddr, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2587 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2588 | { 0x1f, 0x0002 }, |
| 2589 | { 0x05, 0x669a }, |
| 2590 | { 0x1f, 0x0005 }, |
| 2591 | { 0x05, 0x8330 }, |
| 2592 | { 0x06, 0x669a }, |
| 2593 | |
| 2594 | { 0x1f, 0x0002 } |
| 2595 | }; |
| 2596 | int val; |
| 2597 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2598 | 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] | 2599 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2600 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2601 | if ((val & 0x00ff) != 0x006c) { |
Joe Perches | b6bc765 | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 2602 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2603 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 2604 | 0x0069, 0x006a, 0x006b, 0x006c |
| 2605 | }; |
| 2606 | int i; |
| 2607 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2608 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2609 | |
| 2610 | val &= 0xff00; |
| 2611 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2612 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2613 | } |
| 2614 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2615 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2616 | { 0x1f, 0x0002 }, |
| 2617 | { 0x05, 0x2642 }, |
| 2618 | { 0x1f, 0x0005 }, |
| 2619 | { 0x05, 0x8330 }, |
| 2620 | { 0x06, 0x2642 } |
| 2621 | }; |
| 2622 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2623 | 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] | 2624 | } |
| 2625 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2626 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2627 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2628 | rtl_w1w0_phy(tp, 0x02, 0x0100, 0x0600); |
| 2629 | rtl_w1w0_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2630 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2631 | /* Switching regulator Slew rate */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2632 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2633 | rtl_patchphy(tp, 0x0f, 0x0017); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2634 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2635 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2636 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2637 | |
| 2638 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2639 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2640 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2641 | } |
| 2642 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2643 | static void rtl8168d_3_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2644 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2645 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2646 | { 0x1f, 0x0002 }, |
| 2647 | { 0x10, 0x0008 }, |
| 2648 | { 0x0d, 0x006c }, |
| 2649 | |
| 2650 | { 0x1f, 0x0000 }, |
| 2651 | { 0x0d, 0xf880 }, |
| 2652 | |
| 2653 | { 0x1f, 0x0001 }, |
| 2654 | { 0x17, 0x0cc0 }, |
| 2655 | |
| 2656 | { 0x1f, 0x0001 }, |
| 2657 | { 0x0b, 0xa4d8 }, |
| 2658 | { 0x09, 0x281c }, |
| 2659 | { 0x07, 0x2883 }, |
| 2660 | { 0x0a, 0x6b35 }, |
| 2661 | { 0x1d, 0x3da4 }, |
| 2662 | { 0x1c, 0xeffd }, |
| 2663 | { 0x14, 0x7f52 }, |
| 2664 | { 0x18, 0x7fc6 }, |
| 2665 | { 0x08, 0x0601 }, |
| 2666 | { 0x06, 0x4063 }, |
| 2667 | { 0x10, 0xf074 }, |
| 2668 | { 0x1f, 0x0003 }, |
| 2669 | { 0x13, 0x0789 }, |
| 2670 | { 0x12, 0xf4bd }, |
| 2671 | { 0x1a, 0x04fd }, |
| 2672 | { 0x14, 0x84b0 }, |
| 2673 | { 0x1f, 0x0000 }, |
| 2674 | { 0x00, 0x9200 }, |
| 2675 | |
| 2676 | { 0x1f, 0x0005 }, |
| 2677 | { 0x01, 0x0340 }, |
| 2678 | { 0x1f, 0x0001 }, |
| 2679 | { 0x04, 0x4000 }, |
| 2680 | { 0x03, 0x1d21 }, |
| 2681 | { 0x02, 0x0c32 }, |
| 2682 | { 0x01, 0x0200 }, |
| 2683 | { 0x00, 0x5554 }, |
| 2684 | { 0x04, 0x4800 }, |
| 2685 | { 0x04, 0x4000 }, |
| 2686 | { 0x04, 0xf000 }, |
| 2687 | { 0x03, 0xdf01 }, |
| 2688 | { 0x02, 0xdf20 }, |
| 2689 | { 0x01, 0x101a }, |
| 2690 | { 0x00, 0xa0ff }, |
| 2691 | { 0x04, 0xf800 }, |
| 2692 | { 0x04, 0xf000 }, |
| 2693 | { 0x1f, 0x0000 }, |
| 2694 | |
| 2695 | { 0x1f, 0x0007 }, |
| 2696 | { 0x1e, 0x0023 }, |
| 2697 | { 0x16, 0x0000 }, |
| 2698 | { 0x1f, 0x0000 } |
| 2699 | }; |
| 2700 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2701 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2702 | } |
| 2703 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2704 | static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp) |
| 2705 | { |
| 2706 | static const struct phy_reg phy_reg_init[] = { |
| 2707 | { 0x1f, 0x0001 }, |
| 2708 | { 0x17, 0x0cc0 }, |
| 2709 | |
| 2710 | { 0x1f, 0x0007 }, |
| 2711 | { 0x1e, 0x002d }, |
| 2712 | { 0x18, 0x0040 }, |
| 2713 | { 0x1f, 0x0000 } |
| 2714 | }; |
| 2715 | |
| 2716 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 2717 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2718 | } |
| 2719 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2720 | static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp) |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2721 | { |
| 2722 | static const struct phy_reg phy_reg_init[] = { |
| 2723 | /* Enable Delay cap */ |
| 2724 | { 0x1f, 0x0005 }, |
| 2725 | { 0x05, 0x8b80 }, |
| 2726 | { 0x06, 0xc896 }, |
| 2727 | { 0x1f, 0x0000 }, |
| 2728 | |
| 2729 | /* Channel estimation fine tune */ |
| 2730 | { 0x1f, 0x0001 }, |
| 2731 | { 0x0b, 0x6c20 }, |
| 2732 | { 0x07, 0x2872 }, |
| 2733 | { 0x1c, 0xefff }, |
| 2734 | { 0x1f, 0x0003 }, |
| 2735 | { 0x14, 0x6420 }, |
| 2736 | { 0x1f, 0x0000 }, |
| 2737 | |
| 2738 | /* Update PFM & 10M TX idle timer */ |
| 2739 | { 0x1f, 0x0007 }, |
| 2740 | { 0x1e, 0x002f }, |
| 2741 | { 0x15, 0x1919 }, |
| 2742 | { 0x1f, 0x0000 }, |
| 2743 | |
| 2744 | { 0x1f, 0x0007 }, |
| 2745 | { 0x1e, 0x00ac }, |
| 2746 | { 0x18, 0x0006 }, |
| 2747 | { 0x1f, 0x0000 } |
| 2748 | }; |
| 2749 | |
Francois Romieu | 15ecd03 | 2011-04-27 13:52:22 -0700 | [diff] [blame] | 2750 | rtl_apply_firmware(tp); |
| 2751 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2752 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 2753 | |
| 2754 | /* DCO enable for 10M IDLE Power */ |
| 2755 | rtl_writephy(tp, 0x1f, 0x0007); |
| 2756 | rtl_writephy(tp, 0x1e, 0x0023); |
| 2757 | rtl_w1w0_phy(tp, 0x17, 0x0006, 0x0000); |
| 2758 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2759 | |
| 2760 | /* For impedance matching */ |
| 2761 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2762 | rtl_w1w0_phy(tp, 0x08, 0x8000, 0x7f00); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2763 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2764 | |
| 2765 | /* PHY auto speed down */ |
| 2766 | rtl_writephy(tp, 0x1f, 0x0007); |
| 2767 | rtl_writephy(tp, 0x1e, 0x002d); |
| 2768 | rtl_w1w0_phy(tp, 0x18, 0x0050, 0x0000); |
| 2769 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2770 | rtl_w1w0_phy(tp, 0x14, 0x8000, 0x0000); |
| 2771 | |
| 2772 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2773 | rtl_writephy(tp, 0x05, 0x8b86); |
| 2774 | rtl_w1w0_phy(tp, 0x06, 0x0001, 0x0000); |
| 2775 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2776 | |
| 2777 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2778 | rtl_writephy(tp, 0x05, 0x8b85); |
| 2779 | rtl_w1w0_phy(tp, 0x06, 0x0000, 0x2000); |
| 2780 | rtl_writephy(tp, 0x1f, 0x0007); |
| 2781 | rtl_writephy(tp, 0x1e, 0x0020); |
| 2782 | rtl_w1w0_phy(tp, 0x15, 0x0000, 0x1100); |
| 2783 | rtl_writephy(tp, 0x1f, 0x0006); |
| 2784 | rtl_writephy(tp, 0x00, 0x5a00); |
| 2785 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2786 | rtl_writephy(tp, 0x0d, 0x0007); |
| 2787 | rtl_writephy(tp, 0x0e, 0x003c); |
| 2788 | rtl_writephy(tp, 0x0d, 0x4007); |
| 2789 | rtl_writephy(tp, 0x0e, 0x0000); |
| 2790 | rtl_writephy(tp, 0x0d, 0x0000); |
| 2791 | } |
| 2792 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2793 | static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp) |
| 2794 | { |
| 2795 | static const struct phy_reg phy_reg_init[] = { |
| 2796 | /* Enable Delay cap */ |
| 2797 | { 0x1f, 0x0004 }, |
| 2798 | { 0x1f, 0x0007 }, |
| 2799 | { 0x1e, 0x00ac }, |
| 2800 | { 0x18, 0x0006 }, |
| 2801 | { 0x1f, 0x0002 }, |
| 2802 | { 0x1f, 0x0000 }, |
| 2803 | { 0x1f, 0x0000 }, |
| 2804 | |
| 2805 | /* Channel estimation fine tune */ |
| 2806 | { 0x1f, 0x0003 }, |
| 2807 | { 0x09, 0xa20f }, |
| 2808 | { 0x1f, 0x0000 }, |
| 2809 | { 0x1f, 0x0000 }, |
| 2810 | |
| 2811 | /* Green Setting */ |
| 2812 | { 0x1f, 0x0005 }, |
| 2813 | { 0x05, 0x8b5b }, |
| 2814 | { 0x06, 0x9222 }, |
| 2815 | { 0x05, 0x8b6d }, |
| 2816 | { 0x06, 0x8000 }, |
| 2817 | { 0x05, 0x8b76 }, |
| 2818 | { 0x06, 0x8000 }, |
| 2819 | { 0x1f, 0x0000 } |
| 2820 | }; |
| 2821 | |
| 2822 | rtl_apply_firmware(tp); |
| 2823 | |
| 2824 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 2825 | |
| 2826 | /* For 4-corner performance improve */ |
| 2827 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2828 | rtl_writephy(tp, 0x05, 0x8b80); |
| 2829 | rtl_w1w0_phy(tp, 0x17, 0x0006, 0x0000); |
| 2830 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2831 | |
| 2832 | /* PHY auto speed down */ |
| 2833 | rtl_writephy(tp, 0x1f, 0x0004); |
| 2834 | rtl_writephy(tp, 0x1f, 0x0007); |
| 2835 | rtl_writephy(tp, 0x1e, 0x002d); |
| 2836 | rtl_w1w0_phy(tp, 0x18, 0x0010, 0x0000); |
| 2837 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2838 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2839 | rtl_w1w0_phy(tp, 0x14, 0x8000, 0x0000); |
| 2840 | |
| 2841 | /* improve 10M EEE waveform */ |
| 2842 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2843 | rtl_writephy(tp, 0x05, 0x8b86); |
| 2844 | rtl_w1w0_phy(tp, 0x06, 0x0001, 0x0000); |
| 2845 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2846 | |
| 2847 | /* Improve 2-pair detection performance */ |
| 2848 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2849 | rtl_writephy(tp, 0x05, 0x8b85); |
| 2850 | rtl_w1w0_phy(tp, 0x06, 0x4000, 0x0000); |
| 2851 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2852 | |
| 2853 | /* EEE setting */ |
| 2854 | rtl_w1w0_eri(tp->mmio_addr, 0x1b0, ERIAR_MASK_1111, 0x0000, 0x0003, |
| 2855 | ERIAR_EXGMAC); |
| 2856 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2857 | rtl_writephy(tp, 0x05, 0x8b85); |
| 2858 | rtl_w1w0_phy(tp, 0x06, 0x0000, 0x2000); |
| 2859 | rtl_writephy(tp, 0x1f, 0x0004); |
| 2860 | rtl_writephy(tp, 0x1f, 0x0007); |
| 2861 | rtl_writephy(tp, 0x1e, 0x0020); |
| 2862 | rtl_w1w0_phy(tp, 0x06, 0x0000, 0x0100); |
| 2863 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2864 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2865 | rtl_writephy(tp, 0x0d, 0x0007); |
| 2866 | rtl_writephy(tp, 0x0e, 0x003c); |
| 2867 | rtl_writephy(tp, 0x0d, 0x4007); |
| 2868 | rtl_writephy(tp, 0x0e, 0x0000); |
| 2869 | rtl_writephy(tp, 0x0d, 0x0000); |
| 2870 | |
| 2871 | /* Green feature */ |
| 2872 | rtl_writephy(tp, 0x1f, 0x0003); |
| 2873 | rtl_w1w0_phy(tp, 0x19, 0x0000, 0x0001); |
| 2874 | rtl_w1w0_phy(tp, 0x10, 0x0000, 0x0400); |
| 2875 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2876 | } |
| 2877 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2878 | static void rtl8102e_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2879 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2880 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2881 | { 0x1f, 0x0003 }, |
| 2882 | { 0x08, 0x441d }, |
| 2883 | { 0x01, 0x9100 }, |
| 2884 | { 0x1f, 0x0000 } |
| 2885 | }; |
| 2886 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2887 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2888 | rtl_patchphy(tp, 0x11, 1 << 12); |
| 2889 | rtl_patchphy(tp, 0x19, 1 << 13); |
| 2890 | rtl_patchphy(tp, 0x10, 1 << 15); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2891 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2892 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2893 | } |
| 2894 | |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 2895 | static void rtl8105e_hw_phy_config(struct rtl8169_private *tp) |
| 2896 | { |
| 2897 | static const struct phy_reg phy_reg_init[] = { |
| 2898 | { 0x1f, 0x0005 }, |
| 2899 | { 0x1a, 0x0000 }, |
| 2900 | { 0x1f, 0x0000 }, |
| 2901 | |
| 2902 | { 0x1f, 0x0004 }, |
| 2903 | { 0x1c, 0x0000 }, |
| 2904 | { 0x1f, 0x0000 }, |
| 2905 | |
| 2906 | { 0x1f, 0x0001 }, |
| 2907 | { 0x15, 0x7701 }, |
| 2908 | { 0x1f, 0x0000 } |
| 2909 | }; |
| 2910 | |
| 2911 | /* Disable ALDPS before ram code */ |
| 2912 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2913 | rtl_writephy(tp, 0x18, 0x0310); |
| 2914 | msleep(100); |
| 2915 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2916 | rtl_apply_firmware(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 2917 | |
| 2918 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 2919 | } |
| 2920 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2921 | static void rtl_hw_phy_config(struct net_device *dev) |
| 2922 | { |
| 2923 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2924 | |
| 2925 | rtl8169_print_mac_version(tp); |
| 2926 | |
| 2927 | switch (tp->mac_version) { |
| 2928 | case RTL_GIGA_MAC_VER_01: |
| 2929 | break; |
| 2930 | case RTL_GIGA_MAC_VER_02: |
| 2931 | case RTL_GIGA_MAC_VER_03: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2932 | rtl8169s_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2933 | break; |
| 2934 | case RTL_GIGA_MAC_VER_04: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2935 | rtl8169sb_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2936 | break; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2937 | case RTL_GIGA_MAC_VER_05: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2938 | rtl8169scd_hw_phy_config(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2939 | break; |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2940 | case RTL_GIGA_MAC_VER_06: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2941 | rtl8169sce_hw_phy_config(tp); |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2942 | break; |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2943 | case RTL_GIGA_MAC_VER_07: |
| 2944 | case RTL_GIGA_MAC_VER_08: |
| 2945 | case RTL_GIGA_MAC_VER_09: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2946 | rtl8102e_hw_phy_config(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2947 | break; |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2948 | case RTL_GIGA_MAC_VER_11: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2949 | rtl8168bb_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2950 | break; |
| 2951 | case RTL_GIGA_MAC_VER_12: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2952 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2953 | break; |
| 2954 | case RTL_GIGA_MAC_VER_17: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2955 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2956 | break; |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2957 | case RTL_GIGA_MAC_VER_18: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2958 | rtl8168cp_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2959 | break; |
| 2960 | case RTL_GIGA_MAC_VER_19: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2961 | rtl8168c_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2962 | break; |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2963 | case RTL_GIGA_MAC_VER_20: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2964 | rtl8168c_2_hw_phy_config(tp); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2965 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2966 | case RTL_GIGA_MAC_VER_21: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2967 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2968 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2969 | case RTL_GIGA_MAC_VER_22: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2970 | rtl8168c_4_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2971 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2972 | case RTL_GIGA_MAC_VER_23: |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 2973 | case RTL_GIGA_MAC_VER_24: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2974 | rtl8168cp_2_hw_phy_config(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2975 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2976 | case RTL_GIGA_MAC_VER_25: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2977 | rtl8168d_1_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2978 | break; |
| 2979 | case RTL_GIGA_MAC_VER_26: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2980 | rtl8168d_2_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2981 | break; |
| 2982 | case RTL_GIGA_MAC_VER_27: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2983 | rtl8168d_3_hw_phy_config(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2984 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2985 | case RTL_GIGA_MAC_VER_28: |
| 2986 | rtl8168d_4_hw_phy_config(tp); |
| 2987 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 2988 | case RTL_GIGA_MAC_VER_29: |
| 2989 | case RTL_GIGA_MAC_VER_30: |
| 2990 | rtl8105e_hw_phy_config(tp); |
| 2991 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2992 | case RTL_GIGA_MAC_VER_31: |
| 2993 | /* None. */ |
| 2994 | break; |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2995 | case RTL_GIGA_MAC_VER_32: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2996 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 2997 | rtl8168e_1_hw_phy_config(tp); |
| 2998 | break; |
| 2999 | case RTL_GIGA_MAC_VER_34: |
| 3000 | rtl8168e_2_hw_phy_config(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3001 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3002 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3003 | default: |
| 3004 | break; |
| 3005 | } |
| 3006 | } |
| 3007 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3008 | static void rtl8169_phy_timer(unsigned long __opaque) |
| 3009 | { |
| 3010 | struct net_device *dev = (struct net_device *)__opaque; |
| 3011 | struct rtl8169_private *tp = netdev_priv(dev); |
| 3012 | struct timer_list *timer = &tp->timer; |
| 3013 | void __iomem *ioaddr = tp->mmio_addr; |
| 3014 | unsigned long timeout = RTL8169_PHY_TIMEOUT; |
| 3015 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 3016 | assert(tp->mac_version > RTL_GIGA_MAC_VER_01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3017 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3018 | spin_lock_irq(&tp->lock); |
| 3019 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3020 | if (tp->phy_reset_pending(tp)) { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 3021 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3022 | * A busy loop could burn quite a few cycles on nowadays CPU. |
| 3023 | * Let's delay the execution of the timer for a few ticks. |
| 3024 | */ |
| 3025 | timeout = HZ/10; |
| 3026 | goto out_mod_timer; |
| 3027 | } |
| 3028 | |
| 3029 | if (tp->link_ok(ioaddr)) |
| 3030 | goto out_unlock; |
| 3031 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3032 | netif_warn(tp, link, dev, "PHY reset until link up\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3033 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3034 | tp->phy_reset_enable(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3035 | |
| 3036 | out_mod_timer: |
| 3037 | mod_timer(timer, jiffies + timeout); |
| 3038 | out_unlock: |
| 3039 | spin_unlock_irq(&tp->lock); |
| 3040 | } |
| 3041 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3042 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3043 | /* |
| 3044 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 3045 | * without having to re-enable interrupts. It's not called while |
| 3046 | * the interrupt routine is executing. |
| 3047 | */ |
| 3048 | static void rtl8169_netpoll(struct net_device *dev) |
| 3049 | { |
| 3050 | struct rtl8169_private *tp = netdev_priv(dev); |
| 3051 | struct pci_dev *pdev = tp->pci_dev; |
| 3052 | |
| 3053 | disable_irq(pdev->irq); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3054 | rtl8169_interrupt(pdev->irq, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3055 | enable_irq(pdev->irq); |
| 3056 | } |
| 3057 | #endif |
| 3058 | |
| 3059 | static void rtl8169_release_board(struct pci_dev *pdev, struct net_device *dev, |
| 3060 | void __iomem *ioaddr) |
| 3061 | { |
| 3062 | iounmap(ioaddr); |
| 3063 | pci_release_regions(pdev); |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3064 | pci_clear_mwi(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3065 | pci_disable_device(pdev); |
| 3066 | free_netdev(dev); |
| 3067 | } |
| 3068 | |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 3069 | static void rtl8169_phy_reset(struct net_device *dev, |
| 3070 | struct rtl8169_private *tp) |
| 3071 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 3072 | unsigned int i; |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 3073 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3074 | tp->phy_reset_enable(tp); |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 3075 | for (i = 0; i < 100; i++) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3076 | if (!tp->phy_reset_pending(tp)) |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 3077 | return; |
| 3078 | msleep(1); |
| 3079 | } |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3080 | netif_err(tp, link, dev, "PHY reset failed\n"); |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 3081 | } |
| 3082 | |
Francois Romieu | 2544bfc | 2011-09-01 18:42:09 +0200 | [diff] [blame^] | 3083 | static bool rtl_tbi_enabled(struct rtl8169_private *tp) |
| 3084 | { |
| 3085 | void __iomem *ioaddr = tp->mmio_addr; |
| 3086 | |
| 3087 | return (tp->mac_version == RTL_GIGA_MAC_VER_01) && |
| 3088 | (RTL_R8(PHYstatus) & TBI_Enable); |
| 3089 | } |
| 3090 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3091 | 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] | 3092 | { |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3093 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3094 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 3095 | rtl_hw_phy_config(dev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3096 | |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 3097 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
| 3098 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
| 3099 | RTL_W8(0x82, 0x01); |
| 3100 | } |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3101 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 3102 | pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); |
| 3103 | |
| 3104 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
| 3105 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3106 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 3107 | if (tp->mac_version == RTL_GIGA_MAC_VER_02) { |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3108 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
| 3109 | RTL_W8(0x82, 0x01); |
| 3110 | dprintk("Set PHY Reg 0x0bh = 0x00h\n"); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3111 | rtl_writephy(tp, 0x0b, 0x0000); //w 0x0b 15 0 0 |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3112 | } |
| 3113 | |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 3114 | rtl8169_phy_reset(dev, tp); |
| 3115 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 3116 | rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3117 | ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 3118 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 3119 | (tp->mii.supports_gmii ? |
| 3120 | ADVERTISED_1000baseT_Half | |
| 3121 | ADVERTISED_1000baseT_Full : 0)); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3122 | |
Francois Romieu | 2544bfc | 2011-09-01 18:42:09 +0200 | [diff] [blame^] | 3123 | if (rtl_tbi_enabled(tp)) |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3124 | netif_info(tp, link, dev, "TBI auto-negotiating\n"); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3125 | } |
| 3126 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3127 | static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr) |
| 3128 | { |
| 3129 | void __iomem *ioaddr = tp->mmio_addr; |
| 3130 | u32 high; |
| 3131 | u32 low; |
| 3132 | |
| 3133 | low = addr[0] | (addr[1] << 8) | (addr[2] << 16) | (addr[3] << 24); |
| 3134 | high = addr[4] | (addr[5] << 8); |
| 3135 | |
| 3136 | spin_lock_irq(&tp->lock); |
| 3137 | |
| 3138 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
françois romieu | 908ba2b | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 3139 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3140 | RTL_W32(MAC4, high); |
françois romieu | 908ba2b | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 3141 | RTL_R32(MAC4); |
| 3142 | |
Francois Romieu | 78f1cd0 | 2010-03-27 19:35:46 -0700 | [diff] [blame] | 3143 | RTL_W32(MAC0, low); |
françois romieu | 908ba2b | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 3144 | RTL_R32(MAC0); |
| 3145 | |
françois romieu | c28aa38 | 2011-08-02 03:53:43 +0000 | [diff] [blame] | 3146 | if (tp->mac_version == RTL_GIGA_MAC_VER_34) { |
| 3147 | const struct exgmac_reg e[] = { |
| 3148 | { .addr = 0xe0, ERIAR_MASK_1111, .val = low }, |
| 3149 | { .addr = 0xe4, ERIAR_MASK_1111, .val = high }, |
| 3150 | { .addr = 0xf0, ERIAR_MASK_1111, .val = low << 16 }, |
| 3151 | { .addr = 0xf4, ERIAR_MASK_1111, .val = high << 16 | |
| 3152 | low >> 16 }, |
| 3153 | }; |
| 3154 | |
| 3155 | rtl_write_exgmac_batch(ioaddr, e, ARRAY_SIZE(e)); |
| 3156 | } |
| 3157 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 3158 | RTL_W8(Cfg9346, Cfg9346_Lock); |
| 3159 | |
| 3160 | spin_unlock_irq(&tp->lock); |
| 3161 | } |
| 3162 | |
| 3163 | static int rtl_set_mac_address(struct net_device *dev, void *p) |
| 3164 | { |
| 3165 | struct rtl8169_private *tp = netdev_priv(dev); |
| 3166 | struct sockaddr *addr = p; |
| 3167 | |
| 3168 | if (!is_valid_ether_addr(addr->sa_data)) |
| 3169 | return -EADDRNOTAVAIL; |
| 3170 | |
| 3171 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 3172 | |
| 3173 | rtl_rar_set(tp, dev->dev_addr); |
| 3174 | |
| 3175 | return 0; |
| 3176 | } |
| 3177 | |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 3178 | static int rtl8169_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 3179 | { |
| 3180 | struct rtl8169_private *tp = netdev_priv(dev); |
| 3181 | struct mii_ioctl_data *data = if_mii(ifr); |
| 3182 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3183 | return netif_running(dev) ? tp->do_ioctl(tp, data, cmd) : -ENODEV; |
| 3184 | } |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 3185 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3186 | static int rtl_xmii_ioctl(struct rtl8169_private *tp, |
| 3187 | struct mii_ioctl_data *data, int cmd) |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3188 | { |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 3189 | switch (cmd) { |
| 3190 | case SIOCGMIIPHY: |
| 3191 | data->phy_id = 32; /* Internal PHY */ |
| 3192 | return 0; |
| 3193 | |
| 3194 | case SIOCGMIIREG: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3195 | data->val_out = rtl_readphy(tp, data->reg_num & 0x1f); |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 3196 | return 0; |
| 3197 | |
| 3198 | case SIOCSMIIREG: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 3199 | rtl_writephy(tp, data->reg_num & 0x1f, data->val_in); |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 3200 | return 0; |
| 3201 | } |
| 3202 | return -EOPNOTSUPP; |
| 3203 | } |
| 3204 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3205 | static int rtl_tbi_ioctl(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd) |
| 3206 | { |
| 3207 | return -EOPNOTSUPP; |
| 3208 | } |
| 3209 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 3210 | static const struct rtl_cfg_info { |
| 3211 | void (*hw_start)(struct net_device *); |
| 3212 | unsigned int region; |
| 3213 | unsigned int align; |
| 3214 | u16 intr_event; |
| 3215 | u16 napi_event; |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 3216 | unsigned features; |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 3217 | u8 default_ver; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 3218 | } rtl_cfg_infos [] = { |
| 3219 | [RTL_CFG_0] = { |
| 3220 | .hw_start = rtl_hw_start_8169, |
| 3221 | .region = 1, |
Francois Romieu | e9f63f3 | 2007-02-28 23:16:57 +0100 | [diff] [blame] | 3222 | .align = 0, |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 3223 | .intr_event = SYSErr | LinkChg | RxOverflow | |
| 3224 | RxFIFOOver | TxErr | TxOK | RxOK | RxErr, |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 3225 | .napi_event = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow, |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 3226 | .features = RTL_FEATURE_GMII, |
| 3227 | .default_ver = RTL_GIGA_MAC_VER_01, |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 3228 | }, |
| 3229 | [RTL_CFG_1] = { |
| 3230 | .hw_start = rtl_hw_start_8168, |
| 3231 | .region = 2, |
| 3232 | .align = 8, |
françois romieu | 53f5735 | 2010-11-08 13:23:05 +0000 | [diff] [blame] | 3233 | .intr_event = SYSErr | LinkChg | RxOverflow | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 3234 | TxErr | TxOK | RxOK | RxErr, |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 3235 | .napi_event = TxErr | TxOK | RxOK | RxOverflow, |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 3236 | .features = RTL_FEATURE_GMII | RTL_FEATURE_MSI, |
| 3237 | .default_ver = RTL_GIGA_MAC_VER_11, |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 3238 | }, |
| 3239 | [RTL_CFG_2] = { |
| 3240 | .hw_start = rtl_hw_start_8101, |
| 3241 | .region = 2, |
| 3242 | .align = 8, |
| 3243 | .intr_event = SYSErr | LinkChg | RxOverflow | PCSTimeout | |
| 3244 | RxFIFOOver | TxErr | TxOK | RxOK | RxErr, |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 3245 | .napi_event = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow, |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 3246 | .features = RTL_FEATURE_MSI, |
| 3247 | .default_ver = RTL_GIGA_MAC_VER_13, |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 3248 | } |
| 3249 | }; |
| 3250 | |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 3251 | /* Cfg9346_Unlock assumed. */ |
| 3252 | static unsigned rtl_try_msi(struct pci_dev *pdev, void __iomem *ioaddr, |
| 3253 | const struct rtl_cfg_info *cfg) |
| 3254 | { |
| 3255 | unsigned msi = 0; |
| 3256 | u8 cfg2; |
| 3257 | |
| 3258 | cfg2 = RTL_R8(Config2) & ~MSIEnable; |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 3259 | if (cfg->features & RTL_FEATURE_MSI) { |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 3260 | if (pci_enable_msi(pdev)) { |
| 3261 | dev_info(&pdev->dev, "no MSI. Back to INTx.\n"); |
| 3262 | } else { |
| 3263 | cfg2 |= MSIEnable; |
| 3264 | msi = RTL_FEATURE_MSI; |
| 3265 | } |
| 3266 | } |
| 3267 | RTL_W8(Config2, cfg2); |
| 3268 | return msi; |
| 3269 | } |
| 3270 | |
| 3271 | static void rtl_disable_msi(struct pci_dev *pdev, struct rtl8169_private *tp) |
| 3272 | { |
| 3273 | if (tp->features & RTL_FEATURE_MSI) { |
| 3274 | pci_disable_msi(pdev); |
| 3275 | tp->features &= ~RTL_FEATURE_MSI; |
| 3276 | } |
| 3277 | } |
| 3278 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3279 | static const struct net_device_ops rtl8169_netdev_ops = { |
| 3280 | .ndo_open = rtl8169_open, |
| 3281 | .ndo_stop = rtl8169_close, |
| 3282 | .ndo_get_stats = rtl8169_get_stats, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 3283 | .ndo_start_xmit = rtl8169_start_xmit, |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3284 | .ndo_tx_timeout = rtl8169_tx_timeout, |
| 3285 | .ndo_validate_addr = eth_validate_addr, |
| 3286 | .ndo_change_mtu = rtl8169_change_mtu, |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 3287 | .ndo_fix_features = rtl8169_fix_features, |
| 3288 | .ndo_set_features = rtl8169_set_features, |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3289 | .ndo_set_mac_address = rtl_set_mac_address, |
| 3290 | .ndo_do_ioctl = rtl8169_ioctl, |
| 3291 | .ndo_set_multicast_list = rtl_set_rx_mode, |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3292 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3293 | .ndo_poll_controller = rtl8169_netpoll, |
| 3294 | #endif |
| 3295 | |
| 3296 | }; |
| 3297 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 3298 | static void __devinit rtl_init_mdio_ops(struct rtl8169_private *tp) |
| 3299 | { |
| 3300 | struct mdio_ops *ops = &tp->mdio_ops; |
| 3301 | |
| 3302 | switch (tp->mac_version) { |
| 3303 | case RTL_GIGA_MAC_VER_27: |
| 3304 | ops->write = r8168dp_1_mdio_write; |
| 3305 | ops->read = r8168dp_1_mdio_read; |
| 3306 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3307 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 3308 | case RTL_GIGA_MAC_VER_31: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3309 | ops->write = r8168dp_2_mdio_write; |
| 3310 | ops->read = r8168dp_2_mdio_read; |
| 3311 | break; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 3312 | default: |
| 3313 | ops->write = r8169_mdio_write; |
| 3314 | ops->read = r8169_mdio_read; |
| 3315 | break; |
| 3316 | } |
| 3317 | } |
| 3318 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3319 | static void r810x_phy_power_down(struct rtl8169_private *tp) |
| 3320 | { |
| 3321 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3322 | rtl_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 3323 | } |
| 3324 | |
| 3325 | static void r810x_phy_power_up(struct rtl8169_private *tp) |
| 3326 | { |
| 3327 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3328 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE); |
| 3329 | } |
| 3330 | |
| 3331 | static void r810x_pll_power_down(struct rtl8169_private *tp) |
| 3332 | { |
Hayes Wang | 1066338 | 2011-09-06 16:55:14 +0800 | [diff] [blame] | 3333 | void __iomem *ioaddr = tp->mmio_addr; |
| 3334 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3335 | if (__rtl8169_get_wol(tp) & WAKE_ANY) { |
| 3336 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3337 | rtl_writephy(tp, MII_BMCR, 0x0000); |
Hayes Wang | 1066338 | 2011-09-06 16:55:14 +0800 | [diff] [blame] | 3338 | |
| 3339 | if (tp->mac_version == RTL_GIGA_MAC_VER_29 || |
| 3340 | tp->mac_version == RTL_GIGA_MAC_VER_30) |
| 3341 | RTL_W32(RxConfig, RTL_R32(RxConfig) | AcceptBroadcast | |
| 3342 | AcceptMulticast | AcceptMyPhys); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3343 | return; |
| 3344 | } |
| 3345 | |
| 3346 | r810x_phy_power_down(tp); |
| 3347 | } |
| 3348 | |
| 3349 | static void r810x_pll_power_up(struct rtl8169_private *tp) |
| 3350 | { |
| 3351 | r810x_phy_power_up(tp); |
| 3352 | } |
| 3353 | |
| 3354 | static void r8168_phy_power_up(struct rtl8169_private *tp) |
| 3355 | { |
| 3356 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3357 | switch (tp->mac_version) { |
| 3358 | case RTL_GIGA_MAC_VER_11: |
| 3359 | case RTL_GIGA_MAC_VER_12: |
| 3360 | case RTL_GIGA_MAC_VER_17: |
| 3361 | case RTL_GIGA_MAC_VER_18: |
| 3362 | case RTL_GIGA_MAC_VER_19: |
| 3363 | case RTL_GIGA_MAC_VER_20: |
| 3364 | case RTL_GIGA_MAC_VER_21: |
| 3365 | case RTL_GIGA_MAC_VER_22: |
| 3366 | case RTL_GIGA_MAC_VER_23: |
| 3367 | case RTL_GIGA_MAC_VER_24: |
| 3368 | case RTL_GIGA_MAC_VER_25: |
| 3369 | case RTL_GIGA_MAC_VER_26: |
| 3370 | case RTL_GIGA_MAC_VER_27: |
| 3371 | case RTL_GIGA_MAC_VER_28: |
| 3372 | case RTL_GIGA_MAC_VER_31: |
| 3373 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3374 | break; |
| 3375 | default: |
| 3376 | break; |
| 3377 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3378 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE); |
| 3379 | } |
| 3380 | |
| 3381 | static void r8168_phy_power_down(struct rtl8169_private *tp) |
| 3382 | { |
| 3383 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3384 | switch (tp->mac_version) { |
| 3385 | case RTL_GIGA_MAC_VER_32: |
| 3386 | case RTL_GIGA_MAC_VER_33: |
| 3387 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE | BMCR_PDOWN); |
| 3388 | break; |
| 3389 | |
| 3390 | case RTL_GIGA_MAC_VER_11: |
| 3391 | case RTL_GIGA_MAC_VER_12: |
| 3392 | case RTL_GIGA_MAC_VER_17: |
| 3393 | case RTL_GIGA_MAC_VER_18: |
| 3394 | case RTL_GIGA_MAC_VER_19: |
| 3395 | case RTL_GIGA_MAC_VER_20: |
| 3396 | case RTL_GIGA_MAC_VER_21: |
| 3397 | case RTL_GIGA_MAC_VER_22: |
| 3398 | case RTL_GIGA_MAC_VER_23: |
| 3399 | case RTL_GIGA_MAC_VER_24: |
| 3400 | case RTL_GIGA_MAC_VER_25: |
| 3401 | case RTL_GIGA_MAC_VER_26: |
| 3402 | case RTL_GIGA_MAC_VER_27: |
| 3403 | case RTL_GIGA_MAC_VER_28: |
| 3404 | case RTL_GIGA_MAC_VER_31: |
| 3405 | rtl_writephy(tp, 0x0e, 0x0200); |
| 3406 | default: |
| 3407 | rtl_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 3408 | break; |
| 3409 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3410 | } |
| 3411 | |
| 3412 | static void r8168_pll_power_down(struct rtl8169_private *tp) |
| 3413 | { |
| 3414 | void __iomem *ioaddr = tp->mmio_addr; |
| 3415 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3416 | if ((tp->mac_version == RTL_GIGA_MAC_VER_27 || |
| 3417 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 3418 | tp->mac_version == RTL_GIGA_MAC_VER_31) && |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 3419 | r8168dp_check_dash(tp)) { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3420 | return; |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 3421 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3422 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3423 | if ((tp->mac_version == RTL_GIGA_MAC_VER_23 || |
| 3424 | tp->mac_version == RTL_GIGA_MAC_VER_24) && |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3425 | (RTL_R16(CPlusCmd) & ASF)) { |
| 3426 | return; |
| 3427 | } |
| 3428 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3429 | if (tp->mac_version == RTL_GIGA_MAC_VER_32 || |
| 3430 | tp->mac_version == RTL_GIGA_MAC_VER_33) |
| 3431 | rtl_ephy_write(ioaddr, 0x19, 0xff64); |
| 3432 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3433 | if (__rtl8169_get_wol(tp) & WAKE_ANY) { |
| 3434 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3435 | rtl_writephy(tp, MII_BMCR, 0x0000); |
| 3436 | |
Hayes Wang | d4ed95d | 2011-07-06 15:58:07 +0800 | [diff] [blame] | 3437 | if (tp->mac_version == RTL_GIGA_MAC_VER_32 || |
Hayes Wang | 1066338 | 2011-09-06 16:55:14 +0800 | [diff] [blame] | 3438 | tp->mac_version == RTL_GIGA_MAC_VER_33 || |
| 3439 | tp->mac_version == RTL_GIGA_MAC_VER_34) |
Hayes Wang | d4ed95d | 2011-07-06 15:58:07 +0800 | [diff] [blame] | 3440 | RTL_W32(RxConfig, RTL_R32(RxConfig) | AcceptBroadcast | |
| 3441 | AcceptMulticast | AcceptMyPhys); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3442 | return; |
| 3443 | } |
| 3444 | |
| 3445 | r8168_phy_power_down(tp); |
| 3446 | |
| 3447 | switch (tp->mac_version) { |
| 3448 | case RTL_GIGA_MAC_VER_25: |
| 3449 | case RTL_GIGA_MAC_VER_26: |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 3450 | case RTL_GIGA_MAC_VER_27: |
| 3451 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 3452 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3453 | case RTL_GIGA_MAC_VER_32: |
| 3454 | case RTL_GIGA_MAC_VER_33: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3455 | RTL_W8(PMCH, RTL_R8(PMCH) & ~0x80); |
| 3456 | break; |
| 3457 | } |
| 3458 | } |
| 3459 | |
| 3460 | static void r8168_pll_power_up(struct rtl8169_private *tp) |
| 3461 | { |
| 3462 | void __iomem *ioaddr = tp->mmio_addr; |
| 3463 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3464 | if ((tp->mac_version == RTL_GIGA_MAC_VER_27 || |
| 3465 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 3466 | tp->mac_version == RTL_GIGA_MAC_VER_31) && |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 3467 | r8168dp_check_dash(tp)) { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3468 | return; |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 3469 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3470 | |
| 3471 | switch (tp->mac_version) { |
| 3472 | case RTL_GIGA_MAC_VER_25: |
| 3473 | case RTL_GIGA_MAC_VER_26: |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 3474 | case RTL_GIGA_MAC_VER_27: |
| 3475 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 3476 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3477 | case RTL_GIGA_MAC_VER_32: |
| 3478 | case RTL_GIGA_MAC_VER_33: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3479 | RTL_W8(PMCH, RTL_R8(PMCH) | 0x80); |
| 3480 | break; |
| 3481 | } |
| 3482 | |
| 3483 | r8168_phy_power_up(tp); |
| 3484 | } |
| 3485 | |
| 3486 | static void rtl_pll_power_op(struct rtl8169_private *tp, |
| 3487 | void (*op)(struct rtl8169_private *)) |
| 3488 | { |
| 3489 | if (op) |
| 3490 | op(tp); |
| 3491 | } |
| 3492 | |
| 3493 | static void rtl_pll_power_down(struct rtl8169_private *tp) |
| 3494 | { |
| 3495 | rtl_pll_power_op(tp, tp->pll_power_ops.down); |
| 3496 | } |
| 3497 | |
| 3498 | static void rtl_pll_power_up(struct rtl8169_private *tp) |
| 3499 | { |
| 3500 | rtl_pll_power_op(tp, tp->pll_power_ops.up); |
| 3501 | } |
| 3502 | |
| 3503 | static void __devinit rtl_init_pll_power_ops(struct rtl8169_private *tp) |
| 3504 | { |
| 3505 | struct pll_power_ops *ops = &tp->pll_power_ops; |
| 3506 | |
| 3507 | switch (tp->mac_version) { |
| 3508 | case RTL_GIGA_MAC_VER_07: |
| 3509 | case RTL_GIGA_MAC_VER_08: |
| 3510 | case RTL_GIGA_MAC_VER_09: |
| 3511 | case RTL_GIGA_MAC_VER_10: |
| 3512 | case RTL_GIGA_MAC_VER_16: |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3513 | case RTL_GIGA_MAC_VER_29: |
| 3514 | case RTL_GIGA_MAC_VER_30: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3515 | ops->down = r810x_pll_power_down; |
| 3516 | ops->up = r810x_pll_power_up; |
| 3517 | break; |
| 3518 | |
| 3519 | case RTL_GIGA_MAC_VER_11: |
| 3520 | case RTL_GIGA_MAC_VER_12: |
| 3521 | case RTL_GIGA_MAC_VER_17: |
| 3522 | case RTL_GIGA_MAC_VER_18: |
| 3523 | case RTL_GIGA_MAC_VER_19: |
| 3524 | case RTL_GIGA_MAC_VER_20: |
| 3525 | case RTL_GIGA_MAC_VER_21: |
| 3526 | case RTL_GIGA_MAC_VER_22: |
| 3527 | case RTL_GIGA_MAC_VER_23: |
| 3528 | case RTL_GIGA_MAC_VER_24: |
| 3529 | case RTL_GIGA_MAC_VER_25: |
| 3530 | case RTL_GIGA_MAC_VER_26: |
| 3531 | case RTL_GIGA_MAC_VER_27: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3532 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 3533 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3534 | case RTL_GIGA_MAC_VER_32: |
| 3535 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 3536 | case RTL_GIGA_MAC_VER_34: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3537 | ops->down = r8168_pll_power_down; |
| 3538 | ops->up = r8168_pll_power_up; |
| 3539 | break; |
| 3540 | |
| 3541 | default: |
| 3542 | ops->down = NULL; |
| 3543 | ops->up = NULL; |
| 3544 | break; |
| 3545 | } |
| 3546 | } |
| 3547 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 3548 | static void rtl_init_rxcfg(struct rtl8169_private *tp) |
| 3549 | { |
| 3550 | void __iomem *ioaddr = tp->mmio_addr; |
| 3551 | |
| 3552 | switch (tp->mac_version) { |
| 3553 | case RTL_GIGA_MAC_VER_01: |
| 3554 | case RTL_GIGA_MAC_VER_02: |
| 3555 | case RTL_GIGA_MAC_VER_03: |
| 3556 | case RTL_GIGA_MAC_VER_04: |
| 3557 | case RTL_GIGA_MAC_VER_05: |
| 3558 | case RTL_GIGA_MAC_VER_06: |
| 3559 | case RTL_GIGA_MAC_VER_10: |
| 3560 | case RTL_GIGA_MAC_VER_11: |
| 3561 | case RTL_GIGA_MAC_VER_12: |
| 3562 | case RTL_GIGA_MAC_VER_13: |
| 3563 | case RTL_GIGA_MAC_VER_14: |
| 3564 | case RTL_GIGA_MAC_VER_15: |
| 3565 | case RTL_GIGA_MAC_VER_16: |
| 3566 | case RTL_GIGA_MAC_VER_17: |
| 3567 | RTL_W32(RxConfig, RX_FIFO_THRESH | RX_DMA_BURST); |
| 3568 | break; |
| 3569 | case RTL_GIGA_MAC_VER_18: |
| 3570 | case RTL_GIGA_MAC_VER_19: |
| 3571 | case RTL_GIGA_MAC_VER_20: |
| 3572 | case RTL_GIGA_MAC_VER_21: |
| 3573 | case RTL_GIGA_MAC_VER_22: |
| 3574 | case RTL_GIGA_MAC_VER_23: |
| 3575 | case RTL_GIGA_MAC_VER_24: |
| 3576 | RTL_W32(RxConfig, RX128_INT_EN | RX_MULTI_EN | RX_DMA_BURST); |
| 3577 | break; |
| 3578 | default: |
| 3579 | RTL_W32(RxConfig, RX128_INT_EN | RX_DMA_BURST); |
| 3580 | break; |
| 3581 | } |
| 3582 | } |
| 3583 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 3584 | static void rtl8169_init_ring_indexes(struct rtl8169_private *tp) |
| 3585 | { |
| 3586 | tp->dirty_tx = tp->dirty_rx = tp->cur_tx = tp->cur_rx = 0; |
| 3587 | } |
| 3588 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 3589 | static void rtl_hw_reset(struct rtl8169_private *tp) |
| 3590 | { |
| 3591 | void __iomem *ioaddr = tp->mmio_addr; |
| 3592 | int i; |
| 3593 | |
| 3594 | /* Soft reset the chip. */ |
| 3595 | RTL_W8(ChipCmd, CmdReset); |
| 3596 | |
| 3597 | /* Check that the chip has finished the reset. */ |
| 3598 | for (i = 0; i < 100; i++) { |
| 3599 | if ((RTL_R8(ChipCmd) & CmdReset) == 0) |
| 3600 | break; |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 3601 | udelay(100); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 3602 | } |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 3603 | |
| 3604 | rtl8169_init_ring_indexes(tp); |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 3605 | } |
| 3606 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3607 | static int __devinit |
| 3608 | rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 3609 | { |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 3610 | const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data; |
| 3611 | const unsigned int region = cfg->region; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3612 | struct rtl8169_private *tp; |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 3613 | struct mii_if_info *mii; |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3614 | struct net_device *dev; |
| 3615 | void __iomem *ioaddr; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 3616 | int chipset, i; |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 3617 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3618 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3619 | if (netif_msg_drv(&debug)) { |
| 3620 | printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n", |
| 3621 | MODULENAME, RTL8169_VERSION); |
| 3622 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3623 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3624 | dev = alloc_etherdev(sizeof (*tp)); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3625 | if (!dev) { |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 3626 | if (netif_msg_drv(&debug)) |
Jeff Garzik | 9b91cf9 | 2006-06-27 11:39:50 -0400 | [diff] [blame] | 3627 | dev_err(&pdev->dev, "unable to alloc new ethernet\n"); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3628 | rc = -ENOMEM; |
| 3629 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | } |
| 3631 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3632 | SET_NETDEV_DEV(dev, &pdev->dev); |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3633 | dev->netdev_ops = &rtl8169_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3634 | tp = netdev_priv(dev); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3635 | tp->dev = dev; |
Ivan Vecera | 21e197f | 2008-04-17 22:48:41 +0200 | [diff] [blame] | 3636 | tp->pci_dev = pdev; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 3637 | tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3638 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 3639 | mii = &tp->mii; |
| 3640 | mii->dev = dev; |
| 3641 | mii->mdio_read = rtl_mdio_read; |
| 3642 | mii->mdio_write = rtl_mdio_write; |
| 3643 | mii->phy_id_mask = 0x1f; |
| 3644 | mii->reg_num_mask = 0x1f; |
| 3645 | mii->supports_gmii = !!(cfg->features & RTL_FEATURE_GMII); |
| 3646 | |
Stanislaw Gruszka | ba04c7c | 2011-02-22 02:00:11 +0000 | [diff] [blame] | 3647 | /* disable ASPM completely as that cause random device stop working |
| 3648 | * problems as well as full system hangs for some PCIe devices users */ |
| 3649 | pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 | |
| 3650 | PCIE_LINK_STATE_CLKPM); |
| 3651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3652 | /* enable device (incl. PCI PM wakeup and hotplug setup) */ |
| 3653 | rc = pci_enable_device(pdev); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 3654 | if (rc < 0) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3655 | netif_err(tp, probe, dev, "enable failure\n"); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3656 | goto err_out_free_dev_1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3657 | } |
| 3658 | |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3659 | if (pci_set_mwi(pdev) < 0) |
| 3660 | netif_info(tp, probe, dev, "Mem-Wr-Inval unavailable\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3661 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3662 | /* make sure PCI base addr 1 is MMIO */ |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 3663 | if (!(pci_resource_flags(pdev, region) & IORESOURCE_MEM)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3664 | netif_err(tp, probe, dev, |
| 3665 | "region #%d not an MMIO resource, aborting\n", |
| 3666 | region); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3667 | rc = -ENODEV; |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3668 | goto err_out_mwi_2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3669 | } |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3670 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3671 | /* check for weird/broken PCI region reporting */ |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 3672 | if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3673 | netif_err(tp, probe, dev, |
| 3674 | "Invalid PCI region size(s), aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3675 | rc = -ENODEV; |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3676 | goto err_out_mwi_2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3677 | } |
| 3678 | |
| 3679 | rc = pci_request_regions(pdev, MODULENAME); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 3680 | if (rc < 0) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3681 | netif_err(tp, probe, dev, "could not request regions\n"); |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3682 | goto err_out_mwi_2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3683 | } |
| 3684 | |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 3685 | tp->cp_cmd = RxChkSum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3686 | |
| 3687 | if ((sizeof(dma_addr_t) > 4) && |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 3688 | !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && use_dac) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3689 | tp->cp_cmd |= PCIDAC; |
| 3690 | dev->features |= NETIF_F_HIGHDMA; |
| 3691 | } else { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 3692 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3693 | if (rc < 0) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3694 | netif_err(tp, probe, dev, "DMA configuration failed\n"); |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3695 | goto err_out_free_res_3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3696 | } |
| 3697 | } |
| 3698 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3699 | /* ioremap MMIO region */ |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 3700 | ioaddr = ioremap(pci_resource_start(pdev, region), R8169_REGS_SIZE); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3701 | if (!ioaddr) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3702 | netif_err(tp, probe, dev, "cannot remap MMIO, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3703 | rc = -EIO; |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3704 | goto err_out_free_res_3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3705 | } |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 3706 | tp->mmio_addr = ioaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3707 | |
Jon Mason | e44daad | 2011-06-27 07:46:31 +0000 | [diff] [blame] | 3708 | if (!pci_is_pcie(pdev)) |
| 3709 | netif_info(tp, probe, dev, "not PCI Express\n"); |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 3710 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 3711 | /* Identify chip attached to board */ |
| 3712 | rtl8169_get_mac_version(tp, dev, cfg->default_ver); |
| 3713 | |
| 3714 | rtl_init_rxcfg(tp); |
| 3715 | |
Karsten Wiese | d78ad8c | 2009-04-02 01:06:01 -0700 | [diff] [blame] | 3716 | RTL_W16(IntrMask, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3717 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 3718 | rtl_hw_reset(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3719 | |
Karsten Wiese | d78ad8c | 2009-04-02 01:06:01 -0700 | [diff] [blame] | 3720 | RTL_W16(IntrStatus, 0xffff); |
| 3721 | |
françois romieu | ca52efd | 2009-07-24 12:34:19 +0000 | [diff] [blame] | 3722 | pci_set_master(pdev); |
| 3723 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 3724 | /* |
| 3725 | * Pretend we are using VLANs; This bypasses a nasty bug where |
| 3726 | * Interrupts stop flowing on high load on 8110SCd controllers. |
| 3727 | */ |
| 3728 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
| 3729 | tp->cp_cmd |= RxVlan; |
| 3730 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 3731 | rtl_init_mdio_ops(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3732 | rtl_init_pll_power_ops(tp); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 3733 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3734 | rtl8169_print_mac_version(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | |
Francois Romieu | 85bffe6 | 2011-04-27 08:22:39 +0200 | [diff] [blame] | 3736 | chipset = tp->mac_version; |
| 3737 | tp->txd_version = rtl_chip_infos[chipset].txd_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3738 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 3739 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 3740 | RTL_W8(Config1, RTL_R8(Config1) | PMEnable); |
| 3741 | RTL_W8(Config5, RTL_R8(Config5) & PMEStatus); |
Bruno Prémont | 20037fa | 2008-10-08 17:05:03 -0700 | [diff] [blame] | 3742 | if ((RTL_R8(Config3) & (LinkUp | MagicPacket)) != 0) |
| 3743 | tp->features |= RTL_FEATURE_WOL; |
| 3744 | if ((RTL_R8(Config5) & (UWF | BWF | MWF)) != 0) |
| 3745 | tp->features |= RTL_FEATURE_WOL; |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 3746 | tp->features |= rtl_try_msi(pdev, ioaddr, cfg); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 3747 | RTL_W8(Cfg9346, Cfg9346_Lock); |
| 3748 | |
Francois Romieu | 2544bfc | 2011-09-01 18:42:09 +0200 | [diff] [blame^] | 3749 | if (rtl_tbi_enabled(tp)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3750 | tp->set_speed = rtl8169_set_speed_tbi; |
| 3751 | tp->get_settings = rtl8169_gset_tbi; |
| 3752 | tp->phy_reset_enable = rtl8169_tbi_reset_enable; |
| 3753 | tp->phy_reset_pending = rtl8169_tbi_reset_pending; |
| 3754 | tp->link_ok = rtl8169_tbi_link_ok; |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3755 | tp->do_ioctl = rtl_tbi_ioctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3756 | } else { |
| 3757 | tp->set_speed = rtl8169_set_speed_xmii; |
| 3758 | tp->get_settings = rtl8169_gset_xmii; |
| 3759 | tp->phy_reset_enable = rtl8169_xmii_reset_enable; |
| 3760 | tp->phy_reset_pending = rtl8169_xmii_reset_pending; |
| 3761 | tp->link_ok = rtl8169_xmii_link_ok; |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3762 | tp->do_ioctl = rtl_xmii_ioctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3763 | } |
| 3764 | |
Francois Romieu | df58ef51 | 2008-10-09 14:35:58 -0700 | [diff] [blame] | 3765 | spin_lock_init(&tp->lock); |
| 3766 | |
Ivan Vecera | 7bf6bf4 | 2008-09-23 22:46:29 +0000 | [diff] [blame] | 3767 | /* Get MAC address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3768 | for (i = 0; i < MAC_ADDR_LEN; i++) |
| 3769 | dev->dev_addr[i] = RTL_R8(MAC0 + i); |
John W. Linville | 6d6525b | 2005-09-12 10:48:57 -0400 | [diff] [blame] | 3770 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3771 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3772 | SET_ETHTOOL_OPS(dev, &rtl8169_ethtool_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3773 | dev->watchdog_timeo = RTL8169_TX_TIMEOUT; |
| 3774 | dev->irq = pdev->irq; |
| 3775 | dev->base_addr = (unsigned long) ioaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3776 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3777 | netif_napi_add(dev, &tp->napi, rtl8169_poll, R8169_NAPI_WEIGHT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3778 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 3779 | /* don't enable SG, IP_CSUM and TSO by default - it might not work |
| 3780 | * properly for all devices */ |
| 3781 | dev->features |= NETIF_F_RXCSUM | |
| 3782 | NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
| 3783 | |
| 3784 | dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 3785 | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
| 3786 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 3787 | NETIF_F_HIGHDMA; |
| 3788 | |
| 3789 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
| 3790 | /* 8110SCd requires hardware Rx VLAN - disallow toggling */ |
| 3791 | dev->hw_features &= ~NETIF_F_HW_VLAN_RX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | |
| 3793 | tp->intr_mask = 0xffff; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 3794 | tp->hw_start = cfg->hw_start; |
| 3795 | tp->intr_event = cfg->intr_event; |
| 3796 | tp->napi_event = cfg->napi_event; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3797 | |
Francois Romieu | e03f33a | 2011-08-25 18:47:24 +0200 | [diff] [blame] | 3798 | tp->opts1_mask = (tp->mac_version != RTL_GIGA_MAC_VER_01) ? |
| 3799 | ~(RxBOVF | RxFOVF) : ~0; |
| 3800 | |
Francois Romieu | 2efa53f | 2007-03-09 00:00:05 +0100 | [diff] [blame] | 3801 | init_timer(&tp->timer); |
| 3802 | tp->timer.data = (unsigned long) dev; |
| 3803 | tp->timer.function = rtl8169_phy_timer; |
| 3804 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 3805 | tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3806 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3807 | rc = register_netdev(dev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3808 | if (rc < 0) |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3809 | goto err_out_msi_4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3810 | |
| 3811 | pci_set_drvdata(pdev, dev); |
| 3812 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3813 | 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] | 3814 | rtl_chip_infos[chipset].name, dev->base_addr, dev->dev_addr, |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3815 | (u32)(RTL_R32(TxConfig) & 0x9cf0f8ff), dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3816 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3817 | if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
| 3818 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 3819 | tp->mac_version == RTL_GIGA_MAC_VER_31) { |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 3820 | rtl8168_driver_start(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3821 | } |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 3822 | |
Bruno Prémont | 8b76ab3 | 2008-10-08 17:06:25 -0700 | [diff] [blame] | 3823 | device_set_wakeup_enable(&pdev->dev, tp->features & RTL_FEATURE_WOL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3824 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 3825 | if (pci_dev_run_wake(pdev)) |
| 3826 | pm_runtime_put_noidle(&pdev->dev); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 3827 | |
Ivan Vecera | 0d672e9 | 2011-02-15 02:08:39 +0000 | [diff] [blame] | 3828 | netif_carrier_off(dev); |
| 3829 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3830 | out: |
| 3831 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3832 | |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3833 | err_out_msi_4: |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 3834 | rtl_disable_msi(pdev, tp); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3835 | iounmap(ioaddr); |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3836 | err_out_free_res_3: |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3837 | pci_release_regions(pdev); |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3838 | err_out_mwi_2: |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3839 | pci_clear_mwi(pdev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3840 | pci_disable_device(pdev); |
| 3841 | err_out_free_dev_1: |
| 3842 | free_netdev(dev); |
| 3843 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3844 | } |
| 3845 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 3846 | static void __devexit rtl8169_remove_one(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3847 | { |
| 3848 | struct net_device *dev = pci_get_drvdata(pdev); |
| 3849 | struct rtl8169_private *tp = netdev_priv(dev); |
| 3850 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3851 | if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
| 3852 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 3853 | tp->mac_version == RTL_GIGA_MAC_VER_31) { |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 3854 | rtl8168_driver_stop(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3855 | } |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 3856 | |
Tejun Heo | 23f333a | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 3857 | cancel_delayed_work_sync(&tp->task); |
Francois Romieu | eb2a021 | 2007-02-15 23:37:21 +0100 | [diff] [blame] | 3858 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3859 | unregister_netdev(dev); |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 3860 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3861 | rtl_release_firmware(tp); |
| 3862 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 3863 | if (pci_dev_run_wake(pdev)) |
| 3864 | pm_runtime_get_noresume(&pdev->dev); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 3865 | |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 3866 | /* restore original MAC address */ |
| 3867 | rtl_rar_set(tp, dev->perm_addr); |
| 3868 | |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 3869 | rtl_disable_msi(pdev, tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3870 | rtl8169_release_board(pdev, dev, tp->mmio_addr); |
| 3871 | pci_set_drvdata(pdev, NULL); |
| 3872 | } |
| 3873 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 3874 | static void rtl_request_uncached_firmware(struct rtl8169_private *tp) |
| 3875 | { |
| 3876 | struct rtl_fw *rtl_fw; |
| 3877 | const char *name; |
| 3878 | int rc = -ENOMEM; |
| 3879 | |
| 3880 | name = rtl_lookup_firmware_name(tp); |
| 3881 | if (!name) |
| 3882 | goto out_no_firmware; |
| 3883 | |
| 3884 | rtl_fw = kzalloc(sizeof(*rtl_fw), GFP_KERNEL); |
| 3885 | if (!rtl_fw) |
| 3886 | goto err_warn; |
| 3887 | |
| 3888 | rc = request_firmware(&rtl_fw->fw, name, &tp->pci_dev->dev); |
| 3889 | if (rc < 0) |
| 3890 | goto err_free; |
| 3891 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 3892 | rc = rtl_check_firmware(tp, rtl_fw); |
| 3893 | if (rc < 0) |
| 3894 | goto err_release_firmware; |
| 3895 | |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 3896 | tp->rtl_fw = rtl_fw; |
| 3897 | out: |
| 3898 | return; |
| 3899 | |
Francois Romieu | fd112f2 | 2011-06-18 00:10:29 +0200 | [diff] [blame] | 3900 | err_release_firmware: |
| 3901 | release_firmware(rtl_fw->fw); |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 3902 | err_free: |
| 3903 | kfree(rtl_fw); |
| 3904 | err_warn: |
| 3905 | netif_warn(tp, ifup, tp->dev, "unable to load firmware patch %s (%d)\n", |
| 3906 | name, rc); |
| 3907 | out_no_firmware: |
| 3908 | tp->rtl_fw = NULL; |
| 3909 | goto out; |
| 3910 | } |
| 3911 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3912 | static void rtl_request_firmware(struct rtl8169_private *tp) |
| 3913 | { |
Francois Romieu | b6ffd97 | 2011-06-17 17:00:05 +0200 | [diff] [blame] | 3914 | if (IS_ERR(tp->rtl_fw)) |
| 3915 | rtl_request_uncached_firmware(tp); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3916 | } |
| 3917 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3918 | static int rtl8169_open(struct net_device *dev) |
| 3919 | { |
| 3920 | struct rtl8169_private *tp = netdev_priv(dev); |
françois romieu | eee3a96 | 2011-01-08 02:17:26 +0000 | [diff] [blame] | 3921 | void __iomem *ioaddr = tp->mmio_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3922 | struct pci_dev *pdev = tp->pci_dev; |
Francois Romieu | 99f252b0 | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 3923 | int retval = -ENOMEM; |
| 3924 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 3925 | pm_runtime_get_sync(&pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3926 | |
Neil Horman | c0cd884 | 2010-03-29 13:16:02 -0700 | [diff] [blame] | 3927 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3928 | * Rx and Tx desscriptors needs 256 bytes alignment. |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 3929 | * dma_alloc_coherent provides more. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3930 | */ |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 3931 | tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES, |
| 3932 | &tp->TxPhyAddr, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3933 | if (!tp->TxDescArray) |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 3934 | goto err_pm_runtime_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3935 | |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 3936 | tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, |
| 3937 | &tp->RxPhyAddr, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3938 | if (!tp->RxDescArray) |
Francois Romieu | 99f252b0 | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 3939 | goto err_free_tx_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3940 | |
| 3941 | retval = rtl8169_init_ring(dev); |
| 3942 | if (retval < 0) |
Francois Romieu | 99f252b0 | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 3943 | goto err_free_rx_1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3944 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3945 | INIT_DELAYED_WORK(&tp->task, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3946 | |
Francois Romieu | 99f252b0 | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 3947 | smp_mb(); |
| 3948 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3949 | rtl_request_firmware(tp); |
| 3950 | |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 3951 | retval = request_irq(dev->irq, rtl8169_interrupt, |
| 3952 | (tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED, |
Francois Romieu | 99f252b0 | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 3953 | dev->name, dev); |
| 3954 | if (retval < 0) |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3955 | goto err_release_fw_2; |
Francois Romieu | 99f252b0 | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 3956 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3957 | napi_enable(&tp->napi); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3958 | |
françois romieu | eee3a96 | 2011-01-08 02:17:26 +0000 | [diff] [blame] | 3959 | rtl8169_init_phy(dev, tp); |
| 3960 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 3961 | rtl8169_set_features(dev, dev->features); |
françois romieu | eee3a96 | 2011-01-08 02:17:26 +0000 | [diff] [blame] | 3962 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3963 | rtl_pll_power_up(tp); |
| 3964 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 3965 | rtl_hw_start(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3966 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 3967 | tp->saved_wolopts = 0; |
| 3968 | pm_runtime_put_noidle(&pdev->dev); |
| 3969 | |
françois romieu | eee3a96 | 2011-01-08 02:17:26 +0000 | [diff] [blame] | 3970 | rtl8169_check_link_status(dev, tp, ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3971 | out: |
| 3972 | return retval; |
| 3973 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3974 | err_release_fw_2: |
| 3975 | rtl_release_firmware(tp); |
Francois Romieu | 99f252b0 | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 3976 | rtl8169_rx_clear(tp); |
| 3977 | err_free_rx_1: |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 3978 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 3979 | tp->RxPhyAddr); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 3980 | tp->RxDescArray = NULL; |
Francois Romieu | 99f252b0 | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 3981 | err_free_tx_0: |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 3982 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 3983 | tp->TxPhyAddr); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 3984 | tp->TxDescArray = NULL; |
| 3985 | err_pm_runtime_put: |
| 3986 | pm_runtime_put_noidle(&pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3987 | goto out; |
| 3988 | } |
| 3989 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 3990 | static void rtl_rx_close(struct rtl8169_private *tp) |
| 3991 | { |
| 3992 | void __iomem *ioaddr = tp->mmio_addr; |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 3993 | |
Francois Romieu | 1687b56 | 2011-07-19 17:21:29 +0200 | [diff] [blame] | 3994 | RTL_W32(RxConfig, RTL_R32(RxConfig) & ~RX_CONFIG_ACCEPT_MASK); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 3995 | } |
| 3996 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3997 | static void rtl8169_hw_reset(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3998 | { |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3999 | void __iomem *ioaddr = tp->mmio_addr; |
| 4000 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4001 | /* Disable interrupts */ |
| 4002 | rtl8169_irq_mask_and_ack(ioaddr); |
| 4003 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4004 | rtl_rx_close(tp); |
| 4005 | |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 4006 | if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4007 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 4008 | tp->mac_version == RTL_GIGA_MAC_VER_31) { |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4009 | while (RTL_R8(TxPoll) & NPQ) |
| 4010 | udelay(20); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4011 | } else if (tp->mac_version == RTL_GIGA_MAC_VER_34) { |
Hayes Wang | c2b0c1e | 2011-09-06 16:55:16 +0800 | [diff] [blame] | 4012 | RTL_W8(ChipCmd, RTL_R8(ChipCmd) | StopReq); |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4013 | while (!(RTL_R32(TxConfig) & TXCFG_EMPTY)) |
| 4014 | udelay(100); |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4015 | } else { |
| 4016 | RTL_W8(ChipCmd, RTL_R8(ChipCmd) | StopReq); |
| 4017 | udelay(100); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4018 | } |
| 4019 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 4020 | rtl_hw_reset(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4021 | } |
| 4022 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4023 | static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4024 | { |
| 4025 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4026 | |
| 4027 | /* Set DMA burst size and Interframe Gap Time */ |
| 4028 | RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) | |
| 4029 | (InterFrameGap << TxInterFrameGapShift)); |
| 4030 | } |
| 4031 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4032 | static void rtl_hw_start(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4033 | { |
| 4034 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4035 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4036 | tp->hw_start(dev); |
| 4037 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4038 | netif_start_queue(dev); |
| 4039 | } |
| 4040 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4041 | static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp, |
| 4042 | void __iomem *ioaddr) |
| 4043 | { |
| 4044 | /* |
| 4045 | * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh |
| 4046 | * register to be written before TxDescAddrLow to work. |
| 4047 | * Switching from MMIO to I/O access fixes the issue as well. |
| 4048 | */ |
| 4049 | RTL_W32(TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 4050 | RTL_W32(TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4051 | RTL_W32(RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 4052 | RTL_W32(RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4053 | } |
| 4054 | |
| 4055 | static u16 rtl_rw_cpluscmd(void __iomem *ioaddr) |
| 4056 | { |
| 4057 | u16 cmd; |
| 4058 | |
| 4059 | cmd = RTL_R16(CPlusCmd); |
| 4060 | RTL_W16(CPlusCmd, cmd); |
| 4061 | return cmd; |
| 4062 | } |
| 4063 | |
Eric Dumazet | fdd7b4c | 2009-06-09 04:01:02 -0700 | [diff] [blame] | 4064 | 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] | 4065 | { |
| 4066 | /* Low hurts. Let's disable the filtering. */ |
Raimonds Cicans | 207d6e87 | 2009-10-26 10:52:37 +0000 | [diff] [blame] | 4067 | RTL_W16(RxMaxSize, rx_buf_sz + 1); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4068 | } |
| 4069 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4070 | static void rtl8169_set_magic_reg(void __iomem *ioaddr, unsigned mac_version) |
| 4071 | { |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 4072 | static const struct rtl_cfg2_info { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4073 | u32 mac_version; |
| 4074 | u32 clk; |
| 4075 | u32 val; |
| 4076 | } cfg2_info [] = { |
| 4077 | { RTL_GIGA_MAC_VER_05, PCI_Clock_33MHz, 0x000fff00 }, // 8110SCd |
| 4078 | { RTL_GIGA_MAC_VER_05, PCI_Clock_66MHz, 0x000fffff }, |
| 4079 | { RTL_GIGA_MAC_VER_06, PCI_Clock_33MHz, 0x00ffff00 }, // 8110SCe |
| 4080 | { RTL_GIGA_MAC_VER_06, PCI_Clock_66MHz, 0x00ffffff } |
Francois Romieu | 3744100 | 2011-06-17 22:58:54 +0200 | [diff] [blame] | 4081 | }; |
| 4082 | const struct rtl_cfg2_info *p = cfg2_info; |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4083 | unsigned int i; |
| 4084 | u32 clk; |
| 4085 | |
| 4086 | clk = RTL_R8(Config2) & PCI_Clock_66MHz; |
Francois Romieu | cadf185 | 2008-01-03 23:38:38 +0100 | [diff] [blame] | 4087 | for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4088 | if ((p->mac_version == mac_version) && (p->clk == clk)) { |
| 4089 | RTL_W32(0x7c, p->val); |
| 4090 | break; |
| 4091 | } |
| 4092 | } |
| 4093 | } |
| 4094 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4095 | static void rtl_hw_start_8169(struct net_device *dev) |
| 4096 | { |
| 4097 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4098 | void __iomem *ioaddr = tp->mmio_addr; |
| 4099 | struct pci_dev *pdev = tp->pci_dev; |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4100 | |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4101 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) { |
| 4102 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) | PCIMulRW); |
| 4103 | pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, 0x08); |
| 4104 | } |
| 4105 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4106 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4107 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 || |
| 4108 | tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 4109 | tp->mac_version == RTL_GIGA_MAC_VER_03 || |
| 4110 | tp->mac_version == RTL_GIGA_MAC_VER_04) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4111 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 4112 | |
Hayes Wang | e542a22 | 2011-07-06 15:58:04 +0800 | [diff] [blame] | 4113 | rtl_init_rxcfg(tp); |
| 4114 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 4115 | RTL_W8(EarlyTxThres, NoEarlyTx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4116 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4117 | rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4118 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4119 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 || |
| 4120 | tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 4121 | tp->mac_version == RTL_GIGA_MAC_VER_03 || |
| 4122 | tp->mac_version == RTL_GIGA_MAC_VER_04) |
Francois Romieu | c946b30 | 2007-10-04 00:42:50 +0200 | [diff] [blame] | 4123 | rtl_set_rx_tx_config_registers(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4124 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4125 | tp->cp_cmd |= rtl_rw_cpluscmd(ioaddr) | PCIMulRW; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4126 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4127 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 4128 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
Joe Perches | 06fa735 | 2007-10-18 21:15:00 +0200 | [diff] [blame] | 4129 | dprintk("Set MAC Reg C+CR Offset 0xE0. " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4130 | "Bit-3 and bit-14 MUST be 1\n"); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4131 | tp->cp_cmd |= (1 << 14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4132 | } |
| 4133 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4134 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 4135 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4136 | rtl8169_set_magic_reg(ioaddr, tp->mac_version); |
| 4137 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4138 | /* |
| 4139 | * Undocumented corner. Supposedly: |
| 4140 | * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets |
| 4141 | */ |
| 4142 | RTL_W16(IntrMitigate, 0x0000); |
| 4143 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 4144 | rtl_set_rx_tx_desc_registers(tp, ioaddr); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 4145 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4146 | if (tp->mac_version != RTL_GIGA_MAC_VER_01 && |
| 4147 | tp->mac_version != RTL_GIGA_MAC_VER_02 && |
| 4148 | tp->mac_version != RTL_GIGA_MAC_VER_03 && |
| 4149 | tp->mac_version != RTL_GIGA_MAC_VER_04) { |
Francois Romieu | c946b30 | 2007-10-04 00:42:50 +0200 | [diff] [blame] | 4150 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 4151 | rtl_set_rx_tx_config_registers(tp); |
| 4152 | } |
| 4153 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4154 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Francois Romieu | b518fa8 | 2006-08-16 15:23:13 +0200 | [diff] [blame] | 4155 | |
| 4156 | /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ |
| 4157 | RTL_R8(IntrMask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4158 | |
| 4159 | RTL_W32(RxMissed, 0); |
| 4160 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4161 | rtl_set_rx_mode(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4162 | |
| 4163 | /* no early-rx interrupts */ |
| 4164 | RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4165 | |
| 4166 | /* Enable all known interrupts by setting the interrupt mask. */ |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 4167 | RTL_W16(IntrMask, tp->intr_event); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4168 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4169 | |
Francois Romieu | 9c14cea | 2008-07-05 00:21:15 +0200 | [diff] [blame] | 4170 | static void rtl_tx_performance_tweak(struct pci_dev *pdev, u16 force) |
Francois Romieu | 458a9f6 | 2008-08-02 15:50:02 +0200 | [diff] [blame] | 4171 | { |
Jon Mason | e44daad | 2011-06-27 07:46:31 +0000 | [diff] [blame] | 4172 | int cap = pci_pcie_cap(pdev); |
Francois Romieu | 458a9f6 | 2008-08-02 15:50:02 +0200 | [diff] [blame] | 4173 | |
Francois Romieu | 9c14cea | 2008-07-05 00:21:15 +0200 | [diff] [blame] | 4174 | if (cap) { |
| 4175 | u16 ctl; |
| 4176 | |
| 4177 | pci_read_config_word(pdev, cap + PCI_EXP_DEVCTL, &ctl); |
| 4178 | ctl = (ctl & ~PCI_EXP_DEVCTL_READRQ) | force; |
| 4179 | pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, ctl); |
| 4180 | } |
Francois Romieu | 458a9f6 | 2008-08-02 15:50:02 +0200 | [diff] [blame] | 4181 | } |
| 4182 | |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4183 | static void rtl_csi_access_enable(void __iomem *ioaddr, u32 bits) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4184 | { |
| 4185 | u32 csi; |
| 4186 | |
| 4187 | csi = rtl_csi_read(ioaddr, 0x070c) & 0x00ffffff; |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4188 | rtl_csi_write(ioaddr, 0x070c, csi | bits); |
| 4189 | } |
| 4190 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4191 | static void rtl_csi_access_enable_1(void __iomem *ioaddr) |
| 4192 | { |
| 4193 | rtl_csi_access_enable(ioaddr, 0x17000000); |
| 4194 | } |
| 4195 | |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4196 | static void rtl_csi_access_enable_2(void __iomem *ioaddr) |
| 4197 | { |
| 4198 | rtl_csi_access_enable(ioaddr, 0x27000000); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 4199 | } |
| 4200 | |
| 4201 | struct ephy_info { |
| 4202 | unsigned int offset; |
| 4203 | u16 mask; |
| 4204 | u16 bits; |
| 4205 | }; |
| 4206 | |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4207 | 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] | 4208 | { |
| 4209 | u16 w; |
| 4210 | |
| 4211 | while (len-- > 0) { |
| 4212 | w = (rtl_ephy_read(ioaddr, e->offset) & ~e->mask) | e->bits; |
| 4213 | rtl_ephy_write(ioaddr, e->offset, w); |
| 4214 | e++; |
| 4215 | } |
| 4216 | } |
| 4217 | |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4218 | static void rtl_disable_clock_request(struct pci_dev *pdev) |
| 4219 | { |
Jon Mason | e44daad | 2011-06-27 07:46:31 +0000 | [diff] [blame] | 4220 | int cap = pci_pcie_cap(pdev); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4221 | |
| 4222 | if (cap) { |
| 4223 | u16 ctl; |
| 4224 | |
| 4225 | pci_read_config_word(pdev, cap + PCI_EXP_LNKCTL, &ctl); |
| 4226 | ctl &= ~PCI_EXP_LNKCTL_CLKREQ_EN; |
| 4227 | pci_write_config_word(pdev, cap + PCI_EXP_LNKCTL, ctl); |
| 4228 | } |
| 4229 | } |
| 4230 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4231 | static void rtl_enable_clock_request(struct pci_dev *pdev) |
| 4232 | { |
Jon Mason | e44daad | 2011-06-27 07:46:31 +0000 | [diff] [blame] | 4233 | int cap = pci_pcie_cap(pdev); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4234 | |
| 4235 | if (cap) { |
| 4236 | u16 ctl; |
| 4237 | |
| 4238 | pci_read_config_word(pdev, cap + PCI_EXP_LNKCTL, &ctl); |
| 4239 | ctl |= PCI_EXP_LNKCTL_CLKREQ_EN; |
| 4240 | pci_write_config_word(pdev, cap + PCI_EXP_LNKCTL, ctl); |
| 4241 | } |
| 4242 | } |
| 4243 | |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4244 | #define R8168_CPCMD_QUIRK_MASK (\ |
| 4245 | EnableBist | \ |
| 4246 | Mac_dbgo_oe | \ |
| 4247 | Force_half_dup | \ |
| 4248 | Force_rxflow_en | \ |
| 4249 | Force_txflow_en | \ |
| 4250 | Cxpl_dbg_sel | \ |
| 4251 | ASF | \ |
| 4252 | PktCntrDisable | \ |
| 4253 | Mac_dbgo_sel) |
| 4254 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4255 | static void rtl_hw_start_8168bb(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4256 | { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4257 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 4258 | |
| 4259 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 4260 | |
Francois Romieu | 2e68ae4 | 2008-06-28 12:00:55 +0200 | [diff] [blame] | 4261 | rtl_tx_performance_tweak(pdev, |
| 4262 | (0x5 << MAX_READ_REQUEST_SHIFT) | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4263 | } |
| 4264 | |
| 4265 | static void rtl_hw_start_8168bef(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4266 | { |
| 4267 | rtl_hw_start_8168bb(ioaddr, pdev); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4268 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 4269 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4270 | |
| 4271 | RTL_W8(Config4, RTL_R8(Config4) & ~(1 << 0)); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4272 | } |
| 4273 | |
| 4274 | static void __rtl_hw_start_8168cp(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4275 | { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4276 | RTL_W8(Config1, RTL_R8(Config1) | Speed_down); |
| 4277 | |
| 4278 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 4279 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4280 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4281 | |
| 4282 | rtl_disable_clock_request(pdev); |
| 4283 | |
| 4284 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4285 | } |
| 4286 | |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4287 | 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] | 4288 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4289 | static const struct ephy_info e_info_8168cp[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4290 | { 0x01, 0, 0x0001 }, |
| 4291 | { 0x02, 0x0800, 0x1000 }, |
| 4292 | { 0x03, 0, 0x0042 }, |
| 4293 | { 0x06, 0x0080, 0x0000 }, |
| 4294 | { 0x07, 0, 0x2000 } |
| 4295 | }; |
| 4296 | |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4297 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4298 | |
| 4299 | rtl_ephy_init(ioaddr, e_info_8168cp, ARRAY_SIZE(e_info_8168cp)); |
| 4300 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4301 | __rtl_hw_start_8168cp(ioaddr, pdev); |
| 4302 | } |
| 4303 | |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4304 | static void rtl_hw_start_8168cp_2(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4305 | { |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4306 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4307 | |
| 4308 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 4309 | |
| 4310 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4311 | |
| 4312 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 4313 | } |
| 4314 | |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4315 | static void rtl_hw_start_8168cp_3(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4316 | { |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4317 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4318 | |
| 4319 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 4320 | |
| 4321 | /* Magic. */ |
| 4322 | RTL_W8(DBG_REG, 0x20); |
| 4323 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 4324 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4325 | |
| 4326 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4327 | |
| 4328 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 4329 | } |
| 4330 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4331 | static void rtl_hw_start_8168c_1(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4332 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4333 | static const struct ephy_info e_info_8168c_1[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4334 | { 0x02, 0x0800, 0x1000 }, |
| 4335 | { 0x03, 0, 0x0002 }, |
| 4336 | { 0x06, 0x0080, 0x0000 } |
| 4337 | }; |
| 4338 | |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4339 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4340 | |
| 4341 | RTL_W8(DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2); |
| 4342 | |
| 4343 | rtl_ephy_init(ioaddr, e_info_8168c_1, ARRAY_SIZE(e_info_8168c_1)); |
| 4344 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4345 | __rtl_hw_start_8168cp(ioaddr, pdev); |
| 4346 | } |
| 4347 | |
| 4348 | static void rtl_hw_start_8168c_2(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4349 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4350 | static const struct ephy_info e_info_8168c_2[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4351 | { 0x01, 0, 0x0001 }, |
| 4352 | { 0x03, 0x0400, 0x0220 } |
| 4353 | }; |
| 4354 | |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4355 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 4356 | |
| 4357 | rtl_ephy_init(ioaddr, e_info_8168c_2, ARRAY_SIZE(e_info_8168c_2)); |
| 4358 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4359 | __rtl_hw_start_8168cp(ioaddr, pdev); |
| 4360 | } |
| 4361 | |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4362 | static void rtl_hw_start_8168c_3(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4363 | { |
| 4364 | rtl_hw_start_8168c_2(ioaddr, pdev); |
| 4365 | } |
| 4366 | |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4367 | static void rtl_hw_start_8168c_4(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4368 | { |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4369 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4370 | |
| 4371 | __rtl_hw_start_8168cp(ioaddr, pdev); |
| 4372 | } |
| 4373 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4374 | static void rtl_hw_start_8168d(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4375 | { |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4376 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4377 | |
| 4378 | rtl_disable_clock_request(pdev); |
| 4379 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 4380 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4381 | |
| 4382 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4383 | |
| 4384 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 4385 | } |
| 4386 | |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4387 | static void rtl_hw_start_8168dp(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4388 | { |
| 4389 | rtl_csi_access_enable_1(ioaddr); |
| 4390 | |
| 4391 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4392 | |
| 4393 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
| 4394 | |
| 4395 | rtl_disable_clock_request(pdev); |
| 4396 | } |
| 4397 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4398 | static void rtl_hw_start_8168d_4(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4399 | { |
| 4400 | static const struct ephy_info e_info_8168d_4[] = { |
| 4401 | { 0x0b, ~0, 0x48 }, |
| 4402 | { 0x19, 0x20, 0x50 }, |
| 4403 | { 0x0c, ~0, 0x20 } |
| 4404 | }; |
| 4405 | int i; |
| 4406 | |
| 4407 | rtl_csi_access_enable_1(ioaddr); |
| 4408 | |
| 4409 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4410 | |
| 4411 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
| 4412 | |
| 4413 | for (i = 0; i < ARRAY_SIZE(e_info_8168d_4); i++) { |
| 4414 | const struct ephy_info *e = e_info_8168d_4 + i; |
| 4415 | u16 w; |
| 4416 | |
| 4417 | w = rtl_ephy_read(ioaddr, e->offset); |
| 4418 | rtl_ephy_write(ioaddr, 0x03, (w & e->mask) | e->bits); |
| 4419 | } |
| 4420 | |
| 4421 | rtl_enable_clock_request(pdev); |
| 4422 | } |
| 4423 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4424 | 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] | 4425 | { |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4426 | static const struct ephy_info e_info_8168e_1[] = { |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4427 | { 0x00, 0x0200, 0x0100 }, |
| 4428 | { 0x00, 0x0000, 0x0004 }, |
| 4429 | { 0x06, 0x0002, 0x0001 }, |
| 4430 | { 0x06, 0x0000, 0x0030 }, |
| 4431 | { 0x07, 0x0000, 0x2000 }, |
| 4432 | { 0x00, 0x0000, 0x0020 }, |
| 4433 | { 0x03, 0x5800, 0x2000 }, |
| 4434 | { 0x03, 0x0000, 0x0001 }, |
| 4435 | { 0x01, 0x0800, 0x1000 }, |
| 4436 | { 0x07, 0x0000, 0x4000 }, |
| 4437 | { 0x1e, 0x0000, 0x2000 }, |
| 4438 | { 0x19, 0xffff, 0xfe6c }, |
| 4439 | { 0x0a, 0x0000, 0x0040 } |
| 4440 | }; |
| 4441 | |
| 4442 | rtl_csi_access_enable_2(ioaddr); |
| 4443 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4444 | 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] | 4445 | |
| 4446 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4447 | |
| 4448 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
| 4449 | |
| 4450 | rtl_disable_clock_request(pdev); |
| 4451 | |
| 4452 | /* Reset tx FIFO pointer */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4453 | RTL_W32(MISC, RTL_R32(MISC) | TXPLA_RST); |
| 4454 | RTL_W32(MISC, RTL_R32(MISC) & ~TXPLA_RST); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4455 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4456 | RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4457 | } |
| 4458 | |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4459 | static void rtl_hw_start_8168e_2(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4460 | { |
| 4461 | static const struct ephy_info e_info_8168e_2[] = { |
| 4462 | { 0x09, 0x0000, 0x0080 }, |
| 4463 | { 0x19, 0x0000, 0x0224 } |
| 4464 | }; |
| 4465 | |
| 4466 | rtl_csi_access_enable_1(ioaddr); |
| 4467 | |
| 4468 | rtl_ephy_init(ioaddr, e_info_8168e_2, ARRAY_SIZE(e_info_8168e_2)); |
| 4469 | |
| 4470 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4471 | |
| 4472 | rtl_eri_write(ioaddr, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 4473 | rtl_eri_write(ioaddr, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
| 4474 | rtl_eri_write(ioaddr, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
| 4475 | rtl_eri_write(ioaddr, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
| 4476 | rtl_eri_write(ioaddr, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
| 4477 | rtl_eri_write(ioaddr, 0xd0, ERIAR_MASK_1111, 0x07ff0060, ERIAR_EXGMAC); |
| 4478 | rtl_w1w0_eri(ioaddr, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
| 4479 | rtl_w1w0_eri(ioaddr, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, |
| 4480 | ERIAR_EXGMAC); |
| 4481 | |
| 4482 | RTL_W8(MaxTxPacketSize, 0x27); |
| 4483 | |
| 4484 | rtl_disable_clock_request(pdev); |
| 4485 | |
| 4486 | RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
| 4487 | RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB); |
| 4488 | |
| 4489 | /* Adjust EEE LED frequency */ |
| 4490 | RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07); |
| 4491 | |
| 4492 | RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN); |
| 4493 | RTL_W32(MISC, RTL_R32(MISC) | PWM_EN); |
| 4494 | RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en); |
| 4495 | } |
| 4496 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4497 | static void rtl_hw_start_8168(struct net_device *dev) |
| 4498 | { |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4499 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4500 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 4501 | struct pci_dev *pdev = tp->pci_dev; |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4502 | |
| 4503 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 4504 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 4505 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4506 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4507 | rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4508 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 4509 | tp->cp_cmd |= RTL_R16(CPlusCmd) | PktCntrDisable | INTT_1; |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4510 | |
| 4511 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 4512 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 4513 | RTL_W16(IntrMitigate, 0x5151); |
| 4514 | |
| 4515 | /* Work around for RxFIFO overflow. */ |
Ivan Vecera | b5ba6d1 | 2011-01-27 12:24:11 +0100 | [diff] [blame] | 4516 | if (tp->mac_version == RTL_GIGA_MAC_VER_11 || |
| 4517 | tp->mac_version == RTL_GIGA_MAC_VER_22) { |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 4518 | tp->intr_event |= RxFIFOOver | PCSTimeout; |
| 4519 | tp->intr_event &= ~RxOverflow; |
| 4520 | } |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4521 | |
| 4522 | rtl_set_rx_tx_desc_registers(tp, ioaddr); |
| 4523 | |
Francois Romieu | b836390 | 2008-06-01 12:31:57 +0200 | [diff] [blame] | 4524 | rtl_set_rx_mode(dev); |
| 4525 | |
| 4526 | RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) | |
| 4527 | (InterFrameGap << TxInterFrameGapShift)); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4528 | |
| 4529 | RTL_R8(IntrMask); |
| 4530 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4531 | switch (tp->mac_version) { |
| 4532 | case RTL_GIGA_MAC_VER_11: |
| 4533 | rtl_hw_start_8168bb(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4534 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4535 | |
| 4536 | case RTL_GIGA_MAC_VER_12: |
| 4537 | case RTL_GIGA_MAC_VER_17: |
| 4538 | rtl_hw_start_8168bef(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4539 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4540 | |
| 4541 | case RTL_GIGA_MAC_VER_18: |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4542 | rtl_hw_start_8168cp_1(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4543 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4544 | |
| 4545 | case RTL_GIGA_MAC_VER_19: |
| 4546 | rtl_hw_start_8168c_1(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4547 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4548 | |
| 4549 | case RTL_GIGA_MAC_VER_20: |
| 4550 | rtl_hw_start_8168c_2(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4551 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4552 | |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4553 | case RTL_GIGA_MAC_VER_21: |
| 4554 | rtl_hw_start_8168c_3(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4555 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4556 | |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4557 | case RTL_GIGA_MAC_VER_22: |
| 4558 | rtl_hw_start_8168c_4(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4559 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4560 | |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4561 | case RTL_GIGA_MAC_VER_23: |
| 4562 | rtl_hw_start_8168cp_2(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4563 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4564 | |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4565 | case RTL_GIGA_MAC_VER_24: |
| 4566 | rtl_hw_start_8168cp_3(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4567 | break; |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4568 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4569 | case RTL_GIGA_MAC_VER_25: |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 4570 | case RTL_GIGA_MAC_VER_26: |
| 4571 | case RTL_GIGA_MAC_VER_27: |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4572 | rtl_hw_start_8168d(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4573 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4574 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4575 | case RTL_GIGA_MAC_VER_28: |
| 4576 | rtl_hw_start_8168d_4(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4577 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4578 | |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4579 | case RTL_GIGA_MAC_VER_31: |
| 4580 | rtl_hw_start_8168dp(ioaddr, pdev); |
| 4581 | break; |
| 4582 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4583 | case RTL_GIGA_MAC_VER_32: |
| 4584 | case RTL_GIGA_MAC_VER_33: |
Hayes Wang | 7009042 | 2011-07-06 15:58:06 +0800 | [diff] [blame] | 4585 | rtl_hw_start_8168e_1(ioaddr, pdev); |
| 4586 | break; |
| 4587 | case RTL_GIGA_MAC_VER_34: |
| 4588 | rtl_hw_start_8168e_2(ioaddr, pdev); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4589 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4590 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4591 | default: |
| 4592 | printk(KERN_ERR PFX "%s: unknown chipset (mac_version = %d).\n", |
| 4593 | dev->name, tp->mac_version); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4594 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4595 | } |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4596 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 4597 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 4598 | |
Francois Romieu | b836390 | 2008-06-01 12:31:57 +0200 | [diff] [blame] | 4599 | RTL_W8(Cfg9346, Cfg9346_Lock); |
| 4600 | |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4601 | RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4602 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 4603 | RTL_W16(IntrMask, tp->intr_event); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4604 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4605 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4606 | #define R810X_CPCMD_QUIRK_MASK (\ |
| 4607 | EnableBist | \ |
| 4608 | Mac_dbgo_oe | \ |
| 4609 | Force_half_dup | \ |
françois romieu | 5edcc53 | 2009-08-10 19:41:52 +0000 | [diff] [blame] | 4610 | Force_rxflow_en | \ |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4611 | Force_txflow_en | \ |
| 4612 | Cxpl_dbg_sel | \ |
| 4613 | ASF | \ |
| 4614 | PktCntrDisable | \ |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 4615 | Mac_dbgo_sel) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4616 | |
| 4617 | static void rtl_hw_start_8102e_1(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4618 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4619 | static const struct ephy_info e_info_8102e_1[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4620 | { 0x01, 0, 0x6e65 }, |
| 4621 | { 0x02, 0, 0x091f }, |
| 4622 | { 0x03, 0, 0xc2f9 }, |
| 4623 | { 0x06, 0, 0xafb5 }, |
| 4624 | { 0x07, 0, 0x0e00 }, |
| 4625 | { 0x19, 0, 0xec80 }, |
| 4626 | { 0x01, 0, 0x2e65 }, |
| 4627 | { 0x01, 0, 0x6e65 } |
| 4628 | }; |
| 4629 | u8 cfg1; |
| 4630 | |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4631 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4632 | |
| 4633 | RTL_W8(DBG_REG, FIX_NAK_1); |
| 4634 | |
| 4635 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4636 | |
| 4637 | RTL_W8(Config1, |
| 4638 | LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable); |
| 4639 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 4640 | |
| 4641 | cfg1 = RTL_R8(Config1); |
| 4642 | if ((cfg1 & LEDS0) && (cfg1 & LEDS1)) |
| 4643 | RTL_W8(Config1, cfg1 & ~LEDS0); |
| 4644 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4645 | rtl_ephy_init(ioaddr, e_info_8102e_1, ARRAY_SIZE(e_info_8102e_1)); |
| 4646 | } |
| 4647 | |
| 4648 | static void rtl_hw_start_8102e_2(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4649 | { |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4650 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4651 | |
| 4652 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4653 | |
| 4654 | RTL_W8(Config1, MEMMAP | IOMAP | VPD | PMEnable); |
| 4655 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4656 | } |
| 4657 | |
| 4658 | static void rtl_hw_start_8102e_3(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4659 | { |
| 4660 | rtl_hw_start_8102e_2(ioaddr, pdev); |
| 4661 | |
| 4662 | rtl_ephy_write(ioaddr, 0x03, 0xc2f9); |
| 4663 | } |
| 4664 | |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4665 | static void rtl_hw_start_8105e_1(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4666 | { |
| 4667 | static const struct ephy_info e_info_8105e_1[] = { |
| 4668 | { 0x07, 0, 0x4000 }, |
| 4669 | { 0x19, 0, 0x0200 }, |
| 4670 | { 0x19, 0, 0x0020 }, |
| 4671 | { 0x1e, 0, 0x2000 }, |
| 4672 | { 0x03, 0, 0x0001 }, |
| 4673 | { 0x19, 0, 0x0100 }, |
| 4674 | { 0x19, 0, 0x0004 }, |
| 4675 | { 0x0a, 0, 0x0020 } |
| 4676 | }; |
| 4677 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4678 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4679 | RTL_W32(FuncEvent, RTL_R32(FuncEvent) | 0x002800); |
| 4680 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4681 | /* Disable Early Tally Counter */ |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4682 | RTL_W32(FuncEvent, RTL_R32(FuncEvent) & ~0x010000); |
| 4683 | |
| 4684 | RTL_W8(MCU, RTL_R8(MCU) | EN_NDP | EN_OOB_RESET); |
Hayes Wang | 4f6b00e5 | 2011-07-06 15:58:02 +0800 | [diff] [blame] | 4685 | RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4686 | |
| 4687 | rtl_ephy_init(ioaddr, e_info_8105e_1, ARRAY_SIZE(e_info_8105e_1)); |
| 4688 | } |
| 4689 | |
| 4690 | static void rtl_hw_start_8105e_2(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4691 | { |
| 4692 | rtl_hw_start_8105e_1(ioaddr, pdev); |
| 4693 | rtl_ephy_write(ioaddr, 0x1e, rtl_ephy_read(ioaddr, 0x1e) | 0x8000); |
| 4694 | } |
| 4695 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4696 | static void rtl_hw_start_8101(struct net_device *dev) |
| 4697 | { |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 4698 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4699 | void __iomem *ioaddr = tp->mmio_addr; |
| 4700 | struct pci_dev *pdev = tp->pci_dev; |
| 4701 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4702 | if (tp->mac_version == RTL_GIGA_MAC_VER_13 || |
| 4703 | tp->mac_version == RTL_GIGA_MAC_VER_16) { |
Jon Mason | e44daad | 2011-06-27 07:46:31 +0000 | [diff] [blame] | 4704 | int cap = pci_pcie_cap(pdev); |
Francois Romieu | 9c14cea | 2008-07-05 00:21:15 +0200 | [diff] [blame] | 4705 | |
| 4706 | if (cap) { |
| 4707 | pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, |
| 4708 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 4709 | } |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 4710 | } |
| 4711 | |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 4712 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 4713 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4714 | switch (tp->mac_version) { |
| 4715 | case RTL_GIGA_MAC_VER_07: |
| 4716 | rtl_hw_start_8102e_1(ioaddr, pdev); |
| 4717 | break; |
| 4718 | |
| 4719 | case RTL_GIGA_MAC_VER_08: |
| 4720 | rtl_hw_start_8102e_3(ioaddr, pdev); |
| 4721 | break; |
| 4722 | |
| 4723 | case RTL_GIGA_MAC_VER_09: |
| 4724 | rtl_hw_start_8102e_2(ioaddr, pdev); |
| 4725 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4726 | |
| 4727 | case RTL_GIGA_MAC_VER_29: |
| 4728 | rtl_hw_start_8105e_1(ioaddr, pdev); |
| 4729 | break; |
| 4730 | case RTL_GIGA_MAC_VER_30: |
| 4731 | rtl_hw_start_8105e_2(ioaddr, pdev); |
| 4732 | break; |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 4733 | } |
| 4734 | |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 4735 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 4736 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 4737 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 4738 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4739 | rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 4740 | |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 4741 | tp->cp_cmd &= ~R810X_CPCMD_QUIRK_MASK; |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 4742 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 4743 | |
| 4744 | RTL_W16(IntrMitigate, 0x0000); |
| 4745 | |
| 4746 | rtl_set_rx_tx_desc_registers(tp, ioaddr); |
| 4747 | |
| 4748 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 4749 | rtl_set_rx_tx_config_registers(tp); |
| 4750 | |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 4751 | RTL_R8(IntrMask); |
| 4752 | |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 4753 | rtl_set_rx_mode(dev); |
| 4754 | |
| 4755 | RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4756 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 4757 | RTL_W16(IntrMask, tp->intr_event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4758 | } |
| 4759 | |
| 4760 | static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) |
| 4761 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4762 | if (new_mtu < ETH_ZLEN || new_mtu > SafeMtu) |
| 4763 | return -EINVAL; |
| 4764 | |
| 4765 | dev->mtu = new_mtu; |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 4766 | netdev_update_features(dev); |
| 4767 | |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 4768 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4769 | } |
| 4770 | |
| 4771 | static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc) |
| 4772 | { |
Al Viro | 95e0918 | 2007-12-22 18:55:39 +0000 | [diff] [blame] | 4773 | desc->addr = cpu_to_le64(0x0badbadbadbadbadull); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4774 | desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask); |
| 4775 | } |
| 4776 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4777 | static void rtl8169_free_rx_databuff(struct rtl8169_private *tp, |
| 4778 | void **data_buff, struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4779 | { |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4780 | 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] | 4781 | DMA_FROM_DEVICE); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4782 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4783 | kfree(*data_buff); |
| 4784 | *data_buff = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4785 | rtl8169_make_unusable_by_asic(desc); |
| 4786 | } |
| 4787 | |
| 4788 | static inline void rtl8169_mark_to_asic(struct RxDesc *desc, u32 rx_buf_sz) |
| 4789 | { |
| 4790 | u32 eor = le32_to_cpu(desc->opts1) & RingEnd; |
| 4791 | |
| 4792 | desc->opts1 = cpu_to_le32(DescOwn | eor | rx_buf_sz); |
| 4793 | } |
| 4794 | |
| 4795 | static inline void rtl8169_map_to_asic(struct RxDesc *desc, dma_addr_t mapping, |
| 4796 | u32 rx_buf_sz) |
| 4797 | { |
| 4798 | desc->addr = cpu_to_le64(mapping); |
| 4799 | wmb(); |
| 4800 | rtl8169_mark_to_asic(desc, rx_buf_sz); |
| 4801 | } |
| 4802 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4803 | static inline void *rtl8169_align(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4804 | { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4805 | return (void *)ALIGN((long)data, 16); |
| 4806 | } |
| 4807 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 4808 | static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp, |
| 4809 | struct RxDesc *desc) |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4810 | { |
| 4811 | void *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4812 | dma_addr_t mapping; |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4813 | struct device *d = &tp->pci_dev->dev; |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 4814 | struct net_device *dev = tp->dev; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4815 | int node = dev->dev.parent ? dev_to_node(dev->dev.parent) : -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4816 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4817 | data = kmalloc_node(rx_buf_sz, GFP_KERNEL, node); |
| 4818 | if (!data) |
| 4819 | return NULL; |
Francois Romieu | e9f63f3 | 2007-02-28 23:16:57 +0100 | [diff] [blame] | 4820 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4821 | if (rtl8169_align(data) != data) { |
| 4822 | kfree(data); |
| 4823 | data = kmalloc_node(rx_buf_sz + 15, GFP_KERNEL, node); |
| 4824 | if (!data) |
| 4825 | return NULL; |
| 4826 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4827 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4828 | mapping = dma_map_single(d, rtl8169_align(data), rx_buf_sz, |
Stanislaw Gruszka | 231aee6 | 2010-10-20 22:25:38 +0000 | [diff] [blame] | 4829 | DMA_FROM_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 4830 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 4831 | if (net_ratelimit()) |
| 4832 | netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4833 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 4834 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4835 | |
| 4836 | rtl8169_map_to_asic(desc, mapping, rx_buf_sz); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4837 | return data; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4838 | |
| 4839 | err_out: |
| 4840 | kfree(data); |
| 4841 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4842 | } |
| 4843 | |
| 4844 | static void rtl8169_rx_clear(struct rtl8169_private *tp) |
| 4845 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 4846 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4847 | |
| 4848 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4849 | if (tp->Rx_databuff[i]) { |
| 4850 | rtl8169_free_rx_databuff(tp, tp->Rx_databuff + i, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4851 | tp->RxDescArray + i); |
| 4852 | } |
| 4853 | } |
| 4854 | } |
| 4855 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 4856 | static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4857 | { |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 4858 | desc->opts1 |= cpu_to_le32(RingEnd); |
| 4859 | } |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 4860 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 4861 | static int rtl8169_rx_fill(struct rtl8169_private *tp) |
| 4862 | { |
| 4863 | unsigned int i; |
| 4864 | |
| 4865 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4866 | void *data; |
Francois Romieu | 4ae47c2 | 2007-06-16 23:28:45 +0200 | [diff] [blame] | 4867 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4868 | if (tp->Rx_databuff[i]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4869 | continue; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4870 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 4871 | data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4872 | if (!data) { |
| 4873 | rtl8169_make_unusable_by_asic(tp->RxDescArray + i); |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 4874 | goto err_out; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4875 | } |
| 4876 | tp->Rx_databuff[i] = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4877 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4878 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 4879 | rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1); |
| 4880 | return 0; |
| 4881 | |
| 4882 | err_out: |
| 4883 | rtl8169_rx_clear(tp); |
| 4884 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4885 | } |
| 4886 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4887 | static int rtl8169_init_ring(struct net_device *dev) |
| 4888 | { |
| 4889 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4890 | |
| 4891 | rtl8169_init_ring_indexes(tp); |
| 4892 | |
| 4893 | memset(tp->tx_skb, 0x0, NUM_TX_DESC * sizeof(struct ring_info)); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4894 | memset(tp->Rx_databuff, 0x0, NUM_RX_DESC * sizeof(void *)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4895 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 4896 | return rtl8169_rx_fill(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4897 | } |
| 4898 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4899 | 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] | 4900 | struct TxDesc *desc) |
| 4901 | { |
| 4902 | unsigned int len = tx_skb->len; |
| 4903 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4904 | dma_unmap_single(d, le64_to_cpu(desc->addr), len, DMA_TO_DEVICE); |
| 4905 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4906 | desc->opts1 = 0x00; |
| 4907 | desc->opts2 = 0x00; |
| 4908 | desc->addr = 0x00; |
| 4909 | tx_skb->len = 0; |
| 4910 | } |
| 4911 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4912 | static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, |
| 4913 | unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4914 | { |
| 4915 | unsigned int i; |
| 4916 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4917 | for (i = 0; i < n; i++) { |
| 4918 | unsigned int entry = (start + i) % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4919 | struct ring_info *tx_skb = tp->tx_skb + entry; |
| 4920 | unsigned int len = tx_skb->len; |
| 4921 | |
| 4922 | if (len) { |
| 4923 | struct sk_buff *skb = tx_skb->skb; |
| 4924 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4925 | rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4926 | tp->TxDescArray + entry); |
| 4927 | if (skb) { |
Stanislaw Gruszka | cac4b22 | 2010-10-20 22:25:40 +0000 | [diff] [blame] | 4928 | tp->dev->stats.tx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4929 | dev_kfree_skb(skb); |
| 4930 | tx_skb->skb = NULL; |
| 4931 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4932 | } |
| 4933 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4934 | } |
| 4935 | |
| 4936 | static void rtl8169_tx_clear(struct rtl8169_private *tp) |
| 4937 | { |
| 4938 | rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4939 | tp->cur_tx = tp->dirty_tx = 0; |
| 4940 | } |
| 4941 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4942 | static void rtl8169_schedule_work(struct net_device *dev, work_func_t task) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4943 | { |
| 4944 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4945 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4946 | PREPARE_DELAYED_WORK(&tp->task, task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4947 | schedule_delayed_work(&tp->task, 4); |
| 4948 | } |
| 4949 | |
| 4950 | static void rtl8169_wait_for_quiescence(struct net_device *dev) |
| 4951 | { |
| 4952 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4953 | void __iomem *ioaddr = tp->mmio_addr; |
| 4954 | |
| 4955 | synchronize_irq(dev->irq); |
| 4956 | |
| 4957 | /* Wait for any pending NAPI task to complete */ |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 4958 | napi_disable(&tp->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4959 | |
| 4960 | rtl8169_irq_mask_and_ack(ioaddr); |
| 4961 | |
David S. Miller | d1d08d1 | 2008-01-07 20:53:33 -0800 | [diff] [blame] | 4962 | tp->intr_mask = 0xffff; |
| 4963 | RTL_W16(IntrMask, tp->intr_event); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 4964 | napi_enable(&tp->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4965 | } |
| 4966 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4967 | static void rtl8169_reinit_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4968 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4969 | struct rtl8169_private *tp = |
| 4970 | container_of(work, struct rtl8169_private, task.work); |
| 4971 | struct net_device *dev = tp->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4972 | int ret; |
| 4973 | |
Francois Romieu | eb2a021 | 2007-02-15 23:37:21 +0100 | [diff] [blame] | 4974 | rtnl_lock(); |
| 4975 | |
| 4976 | if (!netif_running(dev)) |
| 4977 | goto out_unlock; |
| 4978 | |
| 4979 | rtl8169_wait_for_quiescence(dev); |
| 4980 | rtl8169_close(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4981 | |
| 4982 | ret = rtl8169_open(dev); |
| 4983 | if (unlikely(ret < 0)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 4984 | if (net_ratelimit()) |
| 4985 | netif_err(tp, drv, dev, |
| 4986 | "reinit failure (status = %d). Rescheduling\n", |
| 4987 | ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4988 | rtl8169_schedule_work(dev, rtl8169_reinit_task); |
| 4989 | } |
Francois Romieu | eb2a021 | 2007-02-15 23:37:21 +0100 | [diff] [blame] | 4990 | |
| 4991 | out_unlock: |
| 4992 | rtnl_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4993 | } |
| 4994 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4995 | static void rtl8169_reset_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4996 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4997 | struct rtl8169_private *tp = |
| 4998 | container_of(work, struct rtl8169_private, task.work); |
| 4999 | struct net_device *dev = tp->dev; |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5000 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5001 | |
Francois Romieu | eb2a021 | 2007-02-15 23:37:21 +0100 | [diff] [blame] | 5002 | rtnl_lock(); |
| 5003 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5004 | if (!netif_running(dev)) |
Francois Romieu | eb2a021 | 2007-02-15 23:37:21 +0100 | [diff] [blame] | 5005 | goto out_unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5006 | |
| 5007 | rtl8169_wait_for_quiescence(dev); |
| 5008 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5009 | for (i = 0; i < NUM_RX_DESC; i++) |
| 5010 | rtl8169_mark_to_asic(tp->RxDescArray + i, rx_buf_sz); |
| 5011 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5012 | rtl8169_tx_clear(tp); |
| 5013 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5014 | rtl8169_hw_reset(tp); |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5015 | rtl_hw_start(dev); |
| 5016 | netif_wake_queue(dev); |
| 5017 | rtl8169_check_link_status(dev, tp, tp->mmio_addr); |
Francois Romieu | eb2a021 | 2007-02-15 23:37:21 +0100 | [diff] [blame] | 5018 | |
| 5019 | out_unlock: |
| 5020 | rtnl_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5021 | } |
| 5022 | |
| 5023 | static void rtl8169_tx_timeout(struct net_device *dev) |
| 5024 | { |
| 5025 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5026 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5027 | rtl8169_hw_reset(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5028 | |
| 5029 | /* Let's wait a bit while any (async) irq lands on */ |
| 5030 | rtl8169_schedule_work(dev, rtl8169_reset_task); |
| 5031 | } |
| 5032 | |
| 5033 | 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] | 5034 | u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5035 | { |
| 5036 | struct skb_shared_info *info = skb_shinfo(skb); |
| 5037 | unsigned int cur_frag, entry; |
Jeff Garzik | a6343af | 2007-07-17 05:39:58 -0400 | [diff] [blame] | 5038 | struct TxDesc * uninitialized_var(txd); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5039 | struct device *d = &tp->pci_dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5040 | |
| 5041 | entry = tp->cur_tx; |
| 5042 | for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { |
| 5043 | skb_frag_t *frag = info->frags + cur_frag; |
| 5044 | dma_addr_t mapping; |
| 5045 | u32 status, len; |
| 5046 | void *addr; |
| 5047 | |
| 5048 | entry = (entry + 1) % NUM_TX_DESC; |
| 5049 | |
| 5050 | txd = tp->TxDescArray + entry; |
| 5051 | len = frag->size; |
| 5052 | addr = ((void *) page_address(frag->page)) + frag->page_offset; |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5053 | mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5054 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 5055 | if (net_ratelimit()) |
| 5056 | netif_err(tp, drv, tp->dev, |
| 5057 | "Failed to map TX fragments DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5058 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5059 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5060 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5061 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5062 | status = opts[0] | len | |
| 5063 | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5064 | |
| 5065 | txd->opts1 = cpu_to_le32(status); |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5066 | txd->opts2 = cpu_to_le32(opts[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5067 | txd->addr = cpu_to_le64(mapping); |
| 5068 | |
| 5069 | tp->tx_skb[entry].len = len; |
| 5070 | } |
| 5071 | |
| 5072 | if (cur_frag) { |
| 5073 | tp->tx_skb[entry].skb = skb; |
| 5074 | txd->opts1 |= cpu_to_le32(LastFrag); |
| 5075 | } |
| 5076 | |
| 5077 | return cur_frag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5078 | |
| 5079 | err_out: |
| 5080 | rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag); |
| 5081 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5082 | } |
| 5083 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5084 | static inline void rtl8169_tso_csum(struct rtl8169_private *tp, |
| 5085 | struct sk_buff *skb, u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5086 | { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5087 | 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] | 5088 | u32 mss = skb_shinfo(skb)->gso_size; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5089 | int offset = info->opts_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5090 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5091 | if (mss) { |
| 5092 | opts[0] |= TD_LSO; |
| 5093 | opts[offset] |= min(mss, TD_MSS_MAX) << info->mss_shift; |
| 5094 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 5095 | const struct iphdr *ip = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5096 | |
| 5097 | if (ip->protocol == IPPROTO_TCP) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5098 | opts[offset] |= info->checksum.tcp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5099 | else if (ip->protocol == IPPROTO_UDP) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5100 | opts[offset] |= info->checksum.udp; |
| 5101 | else |
| 5102 | WARN_ON_ONCE(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5103 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5104 | } |
| 5105 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5106 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 5107 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5108 | { |
| 5109 | struct rtl8169_private *tp = netdev_priv(dev); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5110 | unsigned int entry = tp->cur_tx % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5111 | struct TxDesc *txd = tp->TxDescArray + entry; |
| 5112 | void __iomem *ioaddr = tp->mmio_addr; |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5113 | struct device *d = &tp->pci_dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5114 | dma_addr_t mapping; |
| 5115 | u32 status, len; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5116 | u32 opts[2]; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5117 | int frags; |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 5118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5119 | if (unlikely(TX_BUFFS_AVAIL(tp) < skb_shinfo(skb)->nr_frags)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 5120 | 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] | 5121 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5122 | } |
| 5123 | |
| 5124 | if (unlikely(le32_to_cpu(txd->opts1) & DescOwn)) |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5125 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5126 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5127 | len = skb_headlen(skb); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5128 | mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5129 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 5130 | if (net_ratelimit()) |
| 5131 | netif_err(tp, drv, dev, "Failed to map TX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5132 | goto err_dma_0; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 5133 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5134 | |
| 5135 | tp->tx_skb[entry].len = len; |
| 5136 | txd->addr = cpu_to_le64(mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5137 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5138 | opts[1] = cpu_to_le32(rtl8169_tx_vlan_tag(tp, skb)); |
| 5139 | opts[0] = DescOwn; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5140 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5141 | rtl8169_tso_csum(tp, skb, opts); |
| 5142 | |
| 5143 | frags = rtl8169_xmit_frags(tp, skb, opts); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5144 | if (frags < 0) |
| 5145 | goto err_dma_1; |
| 5146 | else if (frags) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5147 | opts[0] |= FirstFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5148 | else { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5149 | opts[0] |= FirstFrag | LastFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5150 | tp->tx_skb[entry].skb = skb; |
| 5151 | } |
| 5152 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5153 | txd->opts2 = cpu_to_le32(opts[1]); |
| 5154 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5155 | wmb(); |
| 5156 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5157 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5158 | status = opts[0] | len | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5159 | txd->opts1 = cpu_to_le32(status); |
| 5160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5161 | tp->cur_tx += frags + 1; |
| 5162 | |
David Dillow | 4c020a9 | 2010-03-03 16:33:10 +0000 | [diff] [blame] | 5163 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5164 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5165 | RTL_W8(TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5166 | |
| 5167 | if (TX_BUFFS_AVAIL(tp) < MAX_SKB_FRAGS) { |
| 5168 | netif_stop_queue(dev); |
| 5169 | smp_rmb(); |
| 5170 | if (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS) |
| 5171 | netif_wake_queue(dev); |
| 5172 | } |
| 5173 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5174 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5175 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5176 | err_dma_1: |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5177 | rtl8169_unmap_tx_skb(d, tp->tx_skb + entry, txd); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 5178 | err_dma_0: |
| 5179 | dev_kfree_skb(skb); |
| 5180 | dev->stats.tx_dropped++; |
| 5181 | return NETDEV_TX_OK; |
| 5182 | |
| 5183 | err_stop_0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5184 | netif_stop_queue(dev); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5185 | dev->stats.tx_dropped++; |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 5186 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5187 | } |
| 5188 | |
| 5189 | static void rtl8169_pcierr_interrupt(struct net_device *dev) |
| 5190 | { |
| 5191 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5192 | struct pci_dev *pdev = tp->pci_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5193 | u16 pci_status, pci_cmd; |
| 5194 | |
| 5195 | pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); |
| 5196 | pci_read_config_word(pdev, PCI_STATUS, &pci_status); |
| 5197 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 5198 | netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n", |
| 5199 | pci_cmd, pci_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5200 | |
| 5201 | /* |
| 5202 | * The recovery sequence below admits a very elaborated explanation: |
| 5203 | * - it seems to work; |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 5204 | * - I did not see what else could be done; |
| 5205 | * - it makes iop3xx happy. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5206 | * |
| 5207 | * Feel free to adjust to your needs. |
| 5208 | */ |
Francois Romieu | a27993f | 2006-12-18 00:04:19 +0100 | [diff] [blame] | 5209 | if (pdev->broken_parity_status) |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 5210 | pci_cmd &= ~PCI_COMMAND_PARITY; |
| 5211 | else |
| 5212 | pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; |
| 5213 | |
| 5214 | pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5215 | |
| 5216 | pci_write_config_word(pdev, PCI_STATUS, |
| 5217 | pci_status & (PCI_STATUS_DETECTED_PARITY | |
| 5218 | PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT | |
| 5219 | PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT)); |
| 5220 | |
| 5221 | /* The infamous DAC f*ckup only happens at boot time */ |
| 5222 | if ((tp->cp_cmd & PCIDAC) && !tp->dirty_rx && !tp->cur_rx) { |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5223 | void __iomem *ioaddr = tp->mmio_addr; |
| 5224 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 5225 | netif_info(tp, intr, dev, "disabling PCI DAC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5226 | tp->cp_cmd &= ~PCIDAC; |
| 5227 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 5228 | dev->features &= ~NETIF_F_HIGHDMA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5229 | } |
| 5230 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 5231 | rtl8169_hw_reset(tp); |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 5232 | |
| 5233 | rtl8169_schedule_work(dev, rtl8169_reinit_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5234 | } |
| 5235 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5236 | static void rtl8169_tx_interrupt(struct net_device *dev, |
| 5237 | struct rtl8169_private *tp, |
| 5238 | void __iomem *ioaddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5239 | { |
| 5240 | unsigned int dirty_tx, tx_left; |
| 5241 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5242 | dirty_tx = tp->dirty_tx; |
| 5243 | smp_rmb(); |
| 5244 | tx_left = tp->cur_tx - dirty_tx; |
| 5245 | |
| 5246 | while (tx_left > 0) { |
| 5247 | unsigned int entry = dirty_tx % NUM_TX_DESC; |
| 5248 | struct ring_info *tx_skb = tp->tx_skb + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5249 | u32 status; |
| 5250 | |
| 5251 | rmb(); |
| 5252 | status = le32_to_cpu(tp->TxDescArray[entry].opts1); |
| 5253 | if (status & DescOwn) |
| 5254 | break; |
| 5255 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5256 | rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb, |
| 5257 | tp->TxDescArray + entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5258 | if (status & LastFrag) { |
Stanislaw Gruszka | cac4b22 | 2010-10-20 22:25:40 +0000 | [diff] [blame] | 5259 | dev->stats.tx_packets++; |
| 5260 | dev->stats.tx_bytes += tx_skb->skb->len; |
Eric Dumazet | 87433bf | 2009-06-09 22:55:53 +0000 | [diff] [blame] | 5261 | dev_kfree_skb(tx_skb->skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5262 | tx_skb->skb = NULL; |
| 5263 | } |
| 5264 | dirty_tx++; |
| 5265 | tx_left--; |
| 5266 | } |
| 5267 | |
| 5268 | if (tp->dirty_tx != dirty_tx) { |
| 5269 | tp->dirty_tx = dirty_tx; |
| 5270 | smp_wmb(); |
| 5271 | if (netif_queue_stopped(dev) && |
| 5272 | (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)) { |
| 5273 | netif_wake_queue(dev); |
| 5274 | } |
Francois Romieu | d78ae2d | 2007-08-26 20:08:19 +0200 | [diff] [blame] | 5275 | /* |
| 5276 | * 8168 hack: TxPoll requests are lost when the Tx packets are |
| 5277 | * too close. Let's kick an extra TxPoll request when a burst |
| 5278 | * of start_xmit activity is detected (if it is not detected, |
| 5279 | * it is slow enough). -- FR |
| 5280 | */ |
| 5281 | smp_rmb(); |
| 5282 | if (tp->cur_tx != dirty_tx) |
| 5283 | RTL_W8(TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5284 | } |
| 5285 | } |
| 5286 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 5287 | static inline int rtl8169_fragmented_frame(u32 status) |
| 5288 | { |
| 5289 | return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag); |
| 5290 | } |
| 5291 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 5292 | static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5293 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5294 | u32 status = opts1 & RxProtoMask; |
| 5295 | |
| 5296 | if (((status == RxProtoTCP) && !(opts1 & TCPFail)) || |
Shan Wei | d5d3ebe | 2010-11-12 00:15:25 +0000 | [diff] [blame] | 5297 | ((status == RxProtoUDP) && !(opts1 & UDPFail))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5298 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 5299 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 5300 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5301 | } |
| 5302 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5303 | static struct sk_buff *rtl8169_try_rx_copy(void *data, |
| 5304 | struct rtl8169_private *tp, |
| 5305 | int pkt_size, |
| 5306 | dma_addr_t addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5307 | { |
Stephen Hemminger | b449655 | 2007-06-17 01:06:49 +0200 | [diff] [blame] | 5308 | struct sk_buff *skb; |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5309 | struct device *d = &tp->pci_dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5310 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5311 | data = rtl8169_align(data); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5312 | dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5313 | prefetch(data); |
| 5314 | skb = netdev_alloc_skb_ip_align(tp->dev, pkt_size); |
| 5315 | if (skb) |
| 5316 | memcpy(skb->data, data, pkt_size); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 5317 | dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE); |
| 5318 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5319 | return skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5320 | } |
| 5321 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5322 | static int rtl8169_rx_interrupt(struct net_device *dev, |
| 5323 | struct rtl8169_private *tp, |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5324 | void __iomem *ioaddr, u32 budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5325 | { |
| 5326 | unsigned int cur_rx, rx_left; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5327 | unsigned int count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5329 | cur_rx = tp->cur_rx; |
| 5330 | rx_left = NUM_RX_DESC + tp->dirty_rx - cur_rx; |
Francois Romieu | 865c652 | 2008-05-11 14:51:00 +0200 | [diff] [blame] | 5331 | rx_left = min(rx_left, budget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5332 | |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 5333 | for (; rx_left > 0; rx_left--, cur_rx++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5334 | unsigned int entry = cur_rx % NUM_RX_DESC; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 5335 | struct RxDesc *desc = tp->RxDescArray + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5336 | u32 status; |
| 5337 | |
| 5338 | rmb(); |
Francois Romieu | e03f33a | 2011-08-25 18:47:24 +0200 | [diff] [blame] | 5339 | status = le32_to_cpu(desc->opts1) & tp->opts1_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5340 | |
| 5341 | if (status & DescOwn) |
| 5342 | break; |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 5343 | if (unlikely(status & RxRES)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 5344 | netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n", |
| 5345 | status); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5346 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5347 | if (status & (RxRWT | RxRUNT)) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5348 | dev->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5349 | if (status & RxCRC) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5350 | dev->stats.rx_crc_errors++; |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 5351 | if (status & RxFOVF) { |
| 5352 | rtl8169_schedule_work(dev, rtl8169_reset_task); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5353 | dev->stats.rx_fifo_errors++; |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 5354 | } |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5355 | rtl8169_mark_to_asic(desc, rx_buf_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5356 | } else { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5357 | struct sk_buff *skb; |
Stephen Hemminger | b449655 | 2007-06-17 01:06:49 +0200 | [diff] [blame] | 5358 | dma_addr_t addr = le64_to_cpu(desc->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5359 | int pkt_size = (status & 0x00001FFF) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5360 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 5361 | /* |
| 5362 | * The driver does not support incoming fragmented |
| 5363 | * frames. They are seen as a symptom of over-mtu |
| 5364 | * sized frames. |
| 5365 | */ |
| 5366 | if (unlikely(rtl8169_fragmented_frame(status))) { |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5367 | dev->stats.rx_dropped++; |
| 5368 | dev->stats.rx_length_errors++; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5369 | rtl8169_mark_to_asic(desc, rx_buf_sz); |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 5370 | continue; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 5371 | } |
| 5372 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5373 | skb = rtl8169_try_rx_copy(tp->Rx_databuff[entry], |
| 5374 | tp, pkt_size, addr); |
| 5375 | rtl8169_mark_to_asic(desc, rx_buf_sz); |
| 5376 | if (!skb) { |
| 5377 | dev->stats.rx_dropped++; |
| 5378 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5379 | } |
| 5380 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 5381 | rtl8169_rx_csum(skb, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5382 | skb_put(skb, pkt_size); |
| 5383 | skb->protocol = eth_type_trans(skb, dev); |
| 5384 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 5385 | rtl8169_rx_vlan_tag(desc, skb); |
| 5386 | |
Francois Romieu | 56de414 | 2011-03-15 17:29:31 +0100 | [diff] [blame] | 5387 | napi_gro_receive(&tp->napi, skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5388 | |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5389 | dev->stats.rx_bytes += pkt_size; |
| 5390 | dev->stats.rx_packets++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5391 | } |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5392 | |
| 5393 | /* Work around for AMD plateform. */ |
Al Viro | 95e0918 | 2007-12-22 18:55:39 +0000 | [diff] [blame] | 5394 | if ((desc->opts2 & cpu_to_le32(0xfffe000)) && |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5395 | (tp->mac_version == RTL_GIGA_MAC_VER_05)) { |
| 5396 | desc->opts2 = 0; |
| 5397 | cur_rx++; |
| 5398 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5399 | } |
| 5400 | |
| 5401 | count = cur_rx - tp->cur_rx; |
| 5402 | tp->cur_rx = cur_rx; |
| 5403 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5404 | tp->dirty_rx += count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5405 | |
| 5406 | return count; |
| 5407 | } |
| 5408 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5409 | static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5410 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5411 | struct net_device *dev = dev_instance; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5412 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5413 | void __iomem *ioaddr = tp->mmio_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5414 | int handled = 0; |
Francois Romieu | 865c652 | 2008-05-11 14:51:00 +0200 | [diff] [blame] | 5415 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5416 | |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 5417 | /* loop handling interrupts until we have no new ones or |
| 5418 | * we hit a invalid/hotplug case. |
| 5419 | */ |
Francois Romieu | 865c652 | 2008-05-11 14:51:00 +0200 | [diff] [blame] | 5420 | status = RTL_R16(IntrStatus); |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 5421 | while (status && status != 0xffff) { |
| 5422 | handled = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5423 | |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 5424 | /* Handle all of the error cases first. These will reset |
| 5425 | * the chip, so just exit the loop. |
| 5426 | */ |
| 5427 | if (unlikely(!netif_running(dev))) { |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5428 | rtl8169_hw_reset(tp); |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 5429 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5430 | } |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 5431 | |
Francois Romieu | 1519e57 | 2011-02-03 12:02:36 +0100 | [diff] [blame] | 5432 | if (unlikely(status & RxFIFOOver)) { |
| 5433 | switch (tp->mac_version) { |
| 5434 | /* Work around for rx fifo overflow */ |
| 5435 | case RTL_GIGA_MAC_VER_11: |
| 5436 | case RTL_GIGA_MAC_VER_22: |
| 5437 | case RTL_GIGA_MAC_VER_26: |
| 5438 | netif_stop_queue(dev); |
| 5439 | rtl8169_tx_timeout(dev); |
| 5440 | goto done; |
Francois Romieu | f60ac8e | 2011-02-03 17:27:52 +0100 | [diff] [blame] | 5441 | /* Testers needed. */ |
| 5442 | case RTL_GIGA_MAC_VER_17: |
| 5443 | case RTL_GIGA_MAC_VER_19: |
| 5444 | case RTL_GIGA_MAC_VER_20: |
| 5445 | case RTL_GIGA_MAC_VER_21: |
| 5446 | case RTL_GIGA_MAC_VER_23: |
| 5447 | case RTL_GIGA_MAC_VER_24: |
| 5448 | case RTL_GIGA_MAC_VER_27: |
| 5449 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5450 | case RTL_GIGA_MAC_VER_31: |
Francois Romieu | 1519e57 | 2011-02-03 12:02:36 +0100 | [diff] [blame] | 5451 | /* Experimental science. Pktgen proof. */ |
| 5452 | case RTL_GIGA_MAC_VER_12: |
| 5453 | case RTL_GIGA_MAC_VER_25: |
| 5454 | if (status == RxFIFOOver) |
| 5455 | goto done; |
| 5456 | break; |
| 5457 | default: |
| 5458 | break; |
| 5459 | } |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 5460 | } |
| 5461 | |
| 5462 | if (unlikely(status & SYSErr)) { |
| 5463 | rtl8169_pcierr_interrupt(dev); |
| 5464 | break; |
| 5465 | } |
| 5466 | |
| 5467 | if (status & LinkChg) |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 5468 | __rtl8169_check_link_status(dev, tp, ioaddr, true); |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 5469 | |
| 5470 | /* We need to see the lastest version of tp->intr_mask to |
| 5471 | * avoid ignoring an MSI interrupt and having to wait for |
| 5472 | * another event which may never come. |
| 5473 | */ |
| 5474 | smp_rmb(); |
| 5475 | if (status & tp->intr_mask & tp->napi_event) { |
| 5476 | RTL_W16(IntrMask, tp->intr_event & ~tp->napi_event); |
| 5477 | tp->intr_mask = ~tp->napi_event; |
| 5478 | |
| 5479 | if (likely(napi_schedule_prep(&tp->napi))) |
| 5480 | __napi_schedule(&tp->napi); |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 5481 | else |
| 5482 | netif_info(tp, intr, dev, |
| 5483 | "interrupt %04x in poll\n", status); |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 5484 | } |
| 5485 | |
| 5486 | /* We only get a new MSI interrupt when all active irq |
| 5487 | * sources on the chip have been acknowledged. So, ack |
| 5488 | * everything we've seen and check if new sources have become |
| 5489 | * active to avoid blocking all interrupts from the chip. |
| 5490 | */ |
| 5491 | RTL_W16(IntrStatus, |
| 5492 | (status & RxFIFOOver) ? (status | RxOverflow) : status); |
| 5493 | status = RTL_R16(IntrStatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5494 | } |
Francois Romieu | 1519e57 | 2011-02-03 12:02:36 +0100 | [diff] [blame] | 5495 | done: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5496 | return IRQ_RETVAL(handled); |
| 5497 | } |
| 5498 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5499 | static int rtl8169_poll(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5500 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5501 | struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); |
| 5502 | struct net_device *dev = tp->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5503 | void __iomem *ioaddr = tp->mmio_addr; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5504 | int work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5505 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5506 | work_done = rtl8169_rx_interrupt(dev, tp, ioaddr, (u32) budget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5507 | rtl8169_tx_interrupt(dev, tp, ioaddr); |
| 5508 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5509 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 5510 | napi_complete(napi); |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 5511 | |
| 5512 | /* We need for force the visibility of tp->intr_mask |
| 5513 | * for other CPUs, as we can loose an MSI interrupt |
| 5514 | * and potentially wait for a retransmit timeout if we don't. |
| 5515 | * The posted write to IntrMask is safe, as it will |
| 5516 | * eventually make it to the chip and we won't loose anything |
| 5517 | * until it does. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5518 | */ |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 5519 | tp->intr_mask = 0xffff; |
David Dillow | 4c020a9 | 2010-03-03 16:33:10 +0000 | [diff] [blame] | 5520 | wmb(); |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5521 | RTL_W16(IntrMask, tp->intr_event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5522 | } |
| 5523 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5524 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5525 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5526 | |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 5527 | static void rtl8169_rx_missed(struct net_device *dev, void __iomem *ioaddr) |
| 5528 | { |
| 5529 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5530 | |
| 5531 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) |
| 5532 | return; |
| 5533 | |
| 5534 | dev->stats.rx_missed_errors += (RTL_R32(RxMissed) & 0xffffff); |
| 5535 | RTL_W32(RxMissed, 0); |
| 5536 | } |
| 5537 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5538 | static void rtl8169_down(struct net_device *dev) |
| 5539 | { |
| 5540 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5541 | void __iomem *ioaddr = tp->mmio_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5542 | |
Francois Romieu | 4876cc1 | 2011-03-11 21:07:11 +0100 | [diff] [blame] | 5543 | del_timer_sync(&tp->timer); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5544 | |
| 5545 | netif_stop_queue(dev); |
| 5546 | |
Stephen Hemminger | 93dd79e | 2007-10-28 17:14:06 +0100 | [diff] [blame] | 5547 | napi_disable(&tp->napi); |
Stephen Hemminger | 93dd79e | 2007-10-28 17:14:06 +0100 | [diff] [blame] | 5548 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5549 | spin_lock_irq(&tp->lock); |
| 5550 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5551 | rtl8169_hw_reset(tp); |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 5552 | /* |
| 5553 | * At this point device interrupts can not be enabled in any function, |
| 5554 | * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task, |
| 5555 | * rtl8169_reinit_task) and napi is disabled (rtl8169_poll). |
| 5556 | */ |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 5557 | rtl8169_rx_missed(dev, ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5558 | |
| 5559 | spin_unlock_irq(&tp->lock); |
| 5560 | |
| 5561 | synchronize_irq(dev->irq); |
| 5562 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5563 | /* Give a racing hard_start_xmit a few cycles to complete. */ |
Paul E. McKenney | fbd568a3e | 2005-05-01 08:59:04 -0700 | [diff] [blame] | 5564 | synchronize_sched(); /* FIXME: should this be synchronize_irq()? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5565 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5566 | rtl8169_tx_clear(tp); |
| 5567 | |
| 5568 | rtl8169_rx_clear(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5569 | |
| 5570 | rtl_pll_power_down(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5571 | } |
| 5572 | |
| 5573 | static int rtl8169_close(struct net_device *dev) |
| 5574 | { |
| 5575 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5576 | struct pci_dev *pdev = tp->pci_dev; |
| 5577 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 5578 | pm_runtime_get_sync(&pdev->dev); |
| 5579 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5580 | /* Update counters before going down */ |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 5581 | rtl8169_update_counters(dev); |
| 5582 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5583 | rtl8169_down(dev); |
| 5584 | |
| 5585 | free_irq(dev->irq, dev); |
| 5586 | |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 5587 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 5588 | tp->RxPhyAddr); |
| 5589 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 5590 | tp->TxPhyAddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5591 | tp->TxDescArray = NULL; |
| 5592 | tp->RxDescArray = NULL; |
| 5593 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 5594 | pm_runtime_put_sync(&pdev->dev); |
| 5595 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5596 | return 0; |
| 5597 | } |
| 5598 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5599 | static void rtl_set_rx_mode(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5600 | { |
| 5601 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5602 | void __iomem *ioaddr = tp->mmio_addr; |
| 5603 | unsigned long flags; |
| 5604 | u32 mc_filter[2]; /* Multicast hash filter */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5605 | int rx_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5606 | u32 tmp = 0; |
| 5607 | |
| 5608 | if (dev->flags & IFF_PROMISC) { |
| 5609 | /* Unconditionally log net taps. */ |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 5610 | netif_notice(tp, link, dev, "Promiscuous mode enabled\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5611 | rx_mode = |
| 5612 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys | |
| 5613 | AcceptAllPhys; |
| 5614 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 5615 | } else if ((netdev_mc_count(dev) > multicast_filter_limit) || |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 5616 | (dev->flags & IFF_ALLMULTI)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5617 | /* Too many to filter perfectly -- accept all multicasts. */ |
| 5618 | rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; |
| 5619 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 5620 | } else { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 5621 | struct netdev_hw_addr *ha; |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5622 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5623 | rx_mode = AcceptBroadcast | AcceptMyPhys; |
| 5624 | mc_filter[1] = mc_filter[0] = 0; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 5625 | netdev_for_each_mc_addr(ha, dev) { |
| 5626 | int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5627 | mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); |
| 5628 | rx_mode |= AcceptMulticast; |
| 5629 | } |
| 5630 | } |
| 5631 | |
| 5632 | spin_lock_irqsave(&tp->lock, flags); |
| 5633 | |
Francois Romieu | 1687b56 | 2011-07-19 17:21:29 +0200 | [diff] [blame] | 5634 | tmp = (RTL_R32(RxConfig) & ~RX_CONFIG_ACCEPT_MASK) | rx_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5635 | |
Francois Romieu | f887cce | 2008-07-17 22:24:18 +0200 | [diff] [blame] | 5636 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) { |
Francois Romieu | 1087f4f | 2007-12-26 22:46:05 +0100 | [diff] [blame] | 5637 | u32 data = mc_filter[0]; |
| 5638 | |
| 5639 | mc_filter[0] = swab32(mc_filter[1]); |
| 5640 | mc_filter[1] = swab32(data); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5641 | } |
| 5642 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5643 | RTL_W32(MAR0 + 4, mc_filter[1]); |
Francois Romieu | 78f1cd0 | 2010-03-27 19:35:46 -0700 | [diff] [blame] | 5644 | RTL_W32(MAR0 + 0, mc_filter[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5645 | |
Francois Romieu | 57a9f23 | 2007-06-04 22:10:15 +0200 | [diff] [blame] | 5646 | RTL_W32(RxConfig, tmp); |
| 5647 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5648 | spin_unlock_irqrestore(&tp->lock, flags); |
| 5649 | } |
| 5650 | |
| 5651 | /** |
| 5652 | * rtl8169_get_stats - Get rtl8169 read/write statistics |
| 5653 | * @dev: The Ethernet Device to get statistics for |
| 5654 | * |
| 5655 | * Get TX/RX statistics for rtl8169 |
| 5656 | */ |
| 5657 | static struct net_device_stats *rtl8169_get_stats(struct net_device *dev) |
| 5658 | { |
| 5659 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5660 | void __iomem *ioaddr = tp->mmio_addr; |
| 5661 | unsigned long flags; |
| 5662 | |
| 5663 | if (netif_running(dev)) { |
| 5664 | spin_lock_irqsave(&tp->lock, flags); |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 5665 | rtl8169_rx_missed(dev, ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5666 | spin_unlock_irqrestore(&tp->lock, flags); |
| 5667 | } |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 5668 | |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5669 | return &dev->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5670 | } |
| 5671 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5672 | static void rtl8169_net_suspend(struct net_device *dev) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5673 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5674 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5675 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5676 | if (!netif_running(dev)) |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5677 | return; |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5678 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5679 | rtl_pll_power_down(tp); |
| 5680 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5681 | netif_device_detach(dev); |
| 5682 | netif_stop_queue(dev); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5683 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5684 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5685 | #ifdef CONFIG_PM |
| 5686 | |
| 5687 | static int rtl8169_suspend(struct device *device) |
| 5688 | { |
| 5689 | struct pci_dev *pdev = to_pci_dev(device); |
| 5690 | struct net_device *dev = pci_get_drvdata(pdev); |
| 5691 | |
| 5692 | rtl8169_net_suspend(dev); |
Francois Romieu | 1371fa6 | 2007-04-02 23:01:11 +0200 | [diff] [blame] | 5693 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5694 | return 0; |
| 5695 | } |
| 5696 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 5697 | static void __rtl8169_resume(struct net_device *dev) |
| 5698 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5699 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5700 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 5701 | netif_device_attach(dev); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5702 | |
| 5703 | rtl_pll_power_up(tp); |
| 5704 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 5705 | rtl8169_schedule_work(dev, rtl8169_reset_task); |
| 5706 | } |
| 5707 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5708 | static int rtl8169_resume(struct device *device) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5709 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5710 | struct pci_dev *pdev = to_pci_dev(device); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5711 | struct net_device *dev = pci_get_drvdata(pdev); |
Stanislaw Gruszka | fccec10 | 2010-10-20 22:25:42 +0000 | [diff] [blame] | 5712 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5713 | |
| 5714 | rtl8169_init_phy(dev, tp); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5715 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 5716 | if (netif_running(dev)) |
| 5717 | __rtl8169_resume(dev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5718 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5719 | return 0; |
| 5720 | } |
| 5721 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 5722 | static int rtl8169_runtime_suspend(struct device *device) |
| 5723 | { |
| 5724 | struct pci_dev *pdev = to_pci_dev(device); |
| 5725 | struct net_device *dev = pci_get_drvdata(pdev); |
| 5726 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5727 | |
| 5728 | if (!tp->TxDescArray) |
| 5729 | return 0; |
| 5730 | |
| 5731 | spin_lock_irq(&tp->lock); |
| 5732 | tp->saved_wolopts = __rtl8169_get_wol(tp); |
| 5733 | __rtl8169_set_wol(tp, WAKE_ANY); |
| 5734 | spin_unlock_irq(&tp->lock); |
| 5735 | |
| 5736 | rtl8169_net_suspend(dev); |
| 5737 | |
| 5738 | return 0; |
| 5739 | } |
| 5740 | |
| 5741 | static int rtl8169_runtime_resume(struct device *device) |
| 5742 | { |
| 5743 | struct pci_dev *pdev = to_pci_dev(device); |
| 5744 | struct net_device *dev = pci_get_drvdata(pdev); |
| 5745 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5746 | |
| 5747 | if (!tp->TxDescArray) |
| 5748 | return 0; |
| 5749 | |
| 5750 | spin_lock_irq(&tp->lock); |
| 5751 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
| 5752 | tp->saved_wolopts = 0; |
| 5753 | spin_unlock_irq(&tp->lock); |
| 5754 | |
Stanislaw Gruszka | fccec10 | 2010-10-20 22:25:42 +0000 | [diff] [blame] | 5755 | rtl8169_init_phy(dev, tp); |
| 5756 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 5757 | __rtl8169_resume(dev); |
| 5758 | |
| 5759 | return 0; |
| 5760 | } |
| 5761 | |
| 5762 | static int rtl8169_runtime_idle(struct device *device) |
| 5763 | { |
| 5764 | struct pci_dev *pdev = to_pci_dev(device); |
| 5765 | struct net_device *dev = pci_get_drvdata(pdev); |
| 5766 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5767 | |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 5768 | return tp->TxDescArray ? -EBUSY : 0; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 5769 | } |
| 5770 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 5771 | static const struct dev_pm_ops rtl8169_pm_ops = { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5772 | .suspend = rtl8169_suspend, |
| 5773 | .resume = rtl8169_resume, |
| 5774 | .freeze = rtl8169_suspend, |
| 5775 | .thaw = rtl8169_resume, |
| 5776 | .poweroff = rtl8169_suspend, |
| 5777 | .restore = rtl8169_resume, |
| 5778 | .runtime_suspend = rtl8169_runtime_suspend, |
| 5779 | .runtime_resume = rtl8169_runtime_resume, |
| 5780 | .runtime_idle = rtl8169_runtime_idle, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5781 | }; |
| 5782 | |
| 5783 | #define RTL8169_PM_OPS (&rtl8169_pm_ops) |
| 5784 | |
| 5785 | #else /* !CONFIG_PM */ |
| 5786 | |
| 5787 | #define RTL8169_PM_OPS NULL |
| 5788 | |
| 5789 | #endif /* !CONFIG_PM */ |
| 5790 | |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 5791 | static void rtl_shutdown(struct pci_dev *pdev) |
| 5792 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5793 | struct net_device *dev = pci_get_drvdata(pdev); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 5794 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5795 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 5796 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5797 | rtl8169_net_suspend(dev); |
| 5798 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5799 | /* Restore original MAC address */ |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 5800 | rtl_rar_set(tp, dev->perm_addr); |
| 5801 | |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 5802 | spin_lock_irq(&tp->lock); |
| 5803 | |
Hayes Wang | 92fc43b | 2011-07-06 15:58:03 +0800 | [diff] [blame] | 5804 | rtl8169_hw_reset(tp); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 5805 | |
| 5806 | spin_unlock_irq(&tp->lock); |
| 5807 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5808 | if (system_state == SYSTEM_POWER_OFF) { |
Hayes Wang | aaa89c0 | 2011-07-06 15:58:08 +0800 | [diff] [blame] | 5809 | /* WoL fails with 8168b when the receiver is disabled. */ |
| 5810 | if ((tp->mac_version == RTL_GIGA_MAC_VER_11 || |
| 5811 | tp->mac_version == RTL_GIGA_MAC_VER_12 || |
| 5812 | tp->mac_version == RTL_GIGA_MAC_VER_17) && |
| 5813 | (tp->features & RTL_FEATURE_WOL)) { |
françois romieu | ca52efd | 2009-07-24 12:34:19 +0000 | [diff] [blame] | 5814 | pci_clear_master(pdev); |
| 5815 | |
| 5816 | RTL_W8(ChipCmd, CmdRxEnb); |
| 5817 | /* PCI commit */ |
| 5818 | RTL_R8(ChipCmd); |
| 5819 | } |
| 5820 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5821 | pci_wake_from_d3(pdev, true); |
| 5822 | pci_set_power_state(pdev, PCI_D3hot); |
| 5823 | } |
| 5824 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5825 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5826 | static struct pci_driver rtl8169_pci_driver = { |
| 5827 | .name = MODULENAME, |
| 5828 | .id_table = rtl8169_pci_tbl, |
| 5829 | .probe = rtl8169_init_one, |
| 5830 | .remove = __devexit_p(rtl8169_remove_one), |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 5831 | .shutdown = rtl_shutdown, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5832 | .driver.pm = RTL8169_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5833 | }; |
| 5834 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5835 | static int __init rtl8169_init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5836 | { |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 5837 | return pci_register_driver(&rtl8169_pci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5838 | } |
| 5839 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5840 | static void __exit rtl8169_cleanup_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5841 | { |
| 5842 | pci_unregister_driver(&rtl8169_pci_driver); |
| 5843 | } |
| 5844 | |
| 5845 | module_init(rtl8169_init_module); |
| 5846 | module_exit(rtl8169_cleanup_module); |