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> |
| 25 | #include <linux/dma-mapping.h> |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 26 | #include <linux/pm_runtime.h> |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 27 | #include <linux/firmware.h> |
Stanislaw Gruszka | ba04c7c | 2011-02-22 02:00:11 +0000 | [diff] [blame] | 28 | #include <linux/pci-aspm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | |
Francois Romieu | 99f252b | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 30 | #include <asm/system.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <asm/io.h> |
| 32 | #include <asm/irq.h> |
| 33 | |
Francois Romieu | 865c652 | 2008-05-11 14:51:00 +0200 | [diff] [blame] | 34 | #define RTL8169_VERSION "2.3LK-NAPI" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | #define MODULENAME "r8169" |
| 36 | #define PFX MODULENAME ": " |
| 37 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 38 | #define FIRMWARE_8168D_1 "rtl_nic/rtl8168d-1.fw" |
| 39 | #define FIRMWARE_8168D_2 "rtl_nic/rtl8168d-2.fw" |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 40 | #define FIRMWARE_8168E_1 "rtl_nic/rtl8168e-1.fw" |
| 41 | #define FIRMWARE_8168E_2 "rtl_nic/rtl8168e-2.fw" |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 42 | #define FIRMWARE_8105E_1 "rtl_nic/rtl8105e-1.fw" |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #ifdef RTL8169_DEBUG |
| 45 | #define assert(expr) \ |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 46 | if (!(expr)) { \ |
| 47 | printk( "Assertion failed! %s,%s,%s,line=%d\n", \ |
Harvey Harrison | b39d66a | 2008-08-20 16:52:04 -0700 | [diff] [blame] | 48 | #expr,__FILE__,__func__,__LINE__); \ |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 49 | } |
Joe Perches | 06fa735 | 2007-10-18 21:15:00 +0200 | [diff] [blame] | 50 | #define dprintk(fmt, args...) \ |
| 51 | do { printk(KERN_DEBUG PFX fmt, ## args); } while (0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | #else |
| 53 | #define assert(expr) do {} while (0) |
| 54 | #define dprintk(fmt, args...) do {} while (0) |
| 55 | #endif /* RTL8169_DEBUG */ |
| 56 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 57 | #define R8169_MSG_DEFAULT \ |
Francois Romieu | f0e837d9 | 2005-09-30 16:54:02 -0700 | [diff] [blame] | 58 | (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN) |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | #define TX_BUFFS_AVAIL(tp) \ |
| 61 | (tp->dirty_tx + NUM_TX_DESC - tp->cur_tx - 1) |
| 62 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). |
| 64 | 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] | 65 | static const int multicast_filter_limit = 32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 66 | |
| 67 | /* MAC address length */ |
| 68 | #define MAC_ADDR_LEN 6 |
| 69 | |
Francois Romieu | 9c14cea | 2008-07-05 00:21:15 +0200 | [diff] [blame] | 70 | #define MAX_READ_REQUEST_SHIFT 12 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | #define RX_FIFO_THRESH 7 /* 7 means NO threshold, Rx buffer level before first PCI xfer. */ |
| 72 | #define RX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */ |
| 73 | #define TX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | #define SafeMtu 0x1c20 /* ... actually life sucks beyond ~7k */ |
| 75 | #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */ |
| 76 | |
| 77 | #define R8169_REGS_SIZE 256 |
| 78 | #define R8169_NAPI_WEIGHT 64 |
| 79 | #define NUM_TX_DESC 64 /* Number of Tx descriptor registers */ |
| 80 | #define NUM_RX_DESC 256 /* Number of Rx descriptor registers */ |
| 81 | #define RX_BUF_SIZE 1536 /* Rx Buffer size */ |
| 82 | #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc)) |
| 83 | #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc)) |
| 84 | |
| 85 | #define RTL8169_TX_TIMEOUT (6*HZ) |
| 86 | #define RTL8169_PHY_TIMEOUT (10*HZ) |
| 87 | |
françois romieu | ea8dbdd | 2009-03-15 01:10:50 +0000 | [diff] [blame] | 88 | #define RTL_EEPROM_SIG cpu_to_le32(0x8129) |
| 89 | #define RTL_EEPROM_SIG_MASK cpu_to_le32(0xffff) |
Francois Romieu | e1564ec | 2008-10-16 22:46:13 +0200 | [diff] [blame] | 90 | #define RTL_EEPROM_SIG_ADDR 0x0000 |
| 91 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | /* write/read MMIO register */ |
| 93 | #define RTL_W8(reg, val8) writeb ((val8), ioaddr + (reg)) |
| 94 | #define RTL_W16(reg, val16) writew ((val16), ioaddr + (reg)) |
| 95 | #define RTL_W32(reg, val32) writel ((val32), ioaddr + (reg)) |
| 96 | #define RTL_R8(reg) readb (ioaddr + (reg)) |
| 97 | #define RTL_R16(reg) readw (ioaddr + (reg)) |
Junchang Wang | 06f555f | 2010-05-30 02:26:07 +0000 | [diff] [blame] | 98 | #define RTL_R32(reg) readl (ioaddr + (reg)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | |
| 100 | enum mac_version { |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 101 | RTL_GIGA_MAC_NONE = 0x00, |
Francois Romieu | ba6eb6e | 2007-06-11 23:35:18 +0200 | [diff] [blame] | 102 | RTL_GIGA_MAC_VER_01 = 0x01, // 8169 |
| 103 | RTL_GIGA_MAC_VER_02 = 0x02, // 8169S |
| 104 | RTL_GIGA_MAC_VER_03 = 0x03, // 8110S |
| 105 | RTL_GIGA_MAC_VER_04 = 0x04, // 8169SB |
| 106 | RTL_GIGA_MAC_VER_05 = 0x05, // 8110SCd |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 107 | RTL_GIGA_MAC_VER_06 = 0x06, // 8110SCe |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 108 | RTL_GIGA_MAC_VER_07 = 0x07, // 8102e |
| 109 | RTL_GIGA_MAC_VER_08 = 0x08, // 8102e |
| 110 | RTL_GIGA_MAC_VER_09 = 0x09, // 8102e |
| 111 | RTL_GIGA_MAC_VER_10 = 0x0a, // 8101e |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 112 | RTL_GIGA_MAC_VER_11 = 0x0b, // 8168Bb |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 113 | RTL_GIGA_MAC_VER_12 = 0x0c, // 8168Be |
| 114 | RTL_GIGA_MAC_VER_13 = 0x0d, // 8101Eb |
| 115 | RTL_GIGA_MAC_VER_14 = 0x0e, // 8101 ? |
| 116 | RTL_GIGA_MAC_VER_15 = 0x0f, // 8101 ? |
| 117 | RTL_GIGA_MAC_VER_16 = 0x11, // 8101Ec |
| 118 | RTL_GIGA_MAC_VER_17 = 0x10, // 8168Bf |
| 119 | RTL_GIGA_MAC_VER_18 = 0x12, // 8168CP |
| 120 | RTL_GIGA_MAC_VER_19 = 0x13, // 8168C |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 121 | RTL_GIGA_MAC_VER_20 = 0x14, // 8168C |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 122 | RTL_GIGA_MAC_VER_21 = 0x15, // 8168C |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 123 | RTL_GIGA_MAC_VER_22 = 0x16, // 8168C |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 124 | RTL_GIGA_MAC_VER_23 = 0x17, // 8168CP |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 125 | RTL_GIGA_MAC_VER_24 = 0x18, // 8168CP |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 126 | RTL_GIGA_MAC_VER_25 = 0x19, // 8168D |
| 127 | RTL_GIGA_MAC_VER_26 = 0x1a, // 8168D |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 128 | RTL_GIGA_MAC_VER_27 = 0x1b, // 8168DP |
| 129 | RTL_GIGA_MAC_VER_28 = 0x1c, // 8168DP |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 130 | RTL_GIGA_MAC_VER_29 = 0x1d, // 8105E |
| 131 | RTL_GIGA_MAC_VER_30 = 0x1e, // 8105E |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 132 | RTL_GIGA_MAC_VER_31 = 0x1f, // 8168DP |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 133 | RTL_GIGA_MAC_VER_32 = 0x20, // 8168E |
| 134 | RTL_GIGA_MAC_VER_33 = 0x21, // 8168E |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | }; |
| 136 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 137 | enum rtl_tx_desc_version { |
| 138 | RTL_TD_0 = 0, |
| 139 | RTL_TD_1 = 1, |
| 140 | }; |
| 141 | |
| 142 | #define _R(NAME,MAC,TD) \ |
| 143 | { .name = NAME, .mac_version = MAC, .txd_version = TD } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
Jesper Juhl | 3c6bee1 | 2006-01-09 20:54:01 -0800 | [diff] [blame] | 145 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | const char *name; |
| 147 | u8 mac_version; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 148 | enum rtl_tx_desc_version txd_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | } rtl_chip_info[] = { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 150 | _R("RTL8169", RTL_GIGA_MAC_VER_01, RTL_TD_0), // 8169 |
| 151 | _R("RTL8169s", RTL_GIGA_MAC_VER_02, RTL_TD_0), // 8169S |
| 152 | _R("RTL8110s", RTL_GIGA_MAC_VER_03, RTL_TD_0), // 8110S |
| 153 | _R("RTL8169sb/8110sb", RTL_GIGA_MAC_VER_04, RTL_TD_0), // 8169SB |
| 154 | _R("RTL8169sc/8110sc", RTL_GIGA_MAC_VER_05, RTL_TD_0), // 8110SCd |
| 155 | _R("RTL8169sc/8110sc", RTL_GIGA_MAC_VER_06, RTL_TD_0), // 8110SCe |
| 156 | _R("RTL8102e", RTL_GIGA_MAC_VER_07, RTL_TD_1), // PCI-E |
| 157 | _R("RTL8102e", RTL_GIGA_MAC_VER_08, RTL_TD_1), // PCI-E |
| 158 | _R("RTL8102e", RTL_GIGA_MAC_VER_09, RTL_TD_1), // PCI-E |
| 159 | _R("RTL8101e", RTL_GIGA_MAC_VER_10, RTL_TD_0), // PCI-E |
| 160 | _R("RTL8168b/8111b", RTL_GIGA_MAC_VER_11, RTL_TD_0), // PCI-E |
| 161 | _R("RTL8168b/8111b", RTL_GIGA_MAC_VER_12, RTL_TD_0), // PCI-E |
| 162 | _R("RTL8101e", RTL_GIGA_MAC_VER_13, RTL_TD_0), // PCI-E 8139 |
| 163 | _R("RTL8100e", RTL_GIGA_MAC_VER_14, RTL_TD_0), // PCI-E 8139 |
| 164 | _R("RTL8100e", RTL_GIGA_MAC_VER_15, RTL_TD_0), // PCI-E 8139 |
| 165 | _R("RTL8168b/8111b", RTL_GIGA_MAC_VER_17, RTL_TD_0), // PCI-E |
| 166 | _R("RTL8101e", RTL_GIGA_MAC_VER_16, RTL_TD_0), // PCI-E |
| 167 | _R("RTL8168cp/8111cp", RTL_GIGA_MAC_VER_18, RTL_TD_1), // PCI-E |
| 168 | _R("RTL8168c/8111c", RTL_GIGA_MAC_VER_19, RTL_TD_1), // PCI-E |
| 169 | _R("RTL8168c/8111c", RTL_GIGA_MAC_VER_20, RTL_TD_1), // PCI-E |
| 170 | _R("RTL8168c/8111c", RTL_GIGA_MAC_VER_21, RTL_TD_1), // PCI-E |
| 171 | _R("RTL8168c/8111c", RTL_GIGA_MAC_VER_22, RTL_TD_1), // PCI-E |
| 172 | _R("RTL8168cp/8111cp", RTL_GIGA_MAC_VER_23, RTL_TD_1), // PCI-E |
| 173 | _R("RTL8168cp/8111cp", RTL_GIGA_MAC_VER_24, RTL_TD_1), // PCI-E |
| 174 | _R("RTL8168d/8111d", RTL_GIGA_MAC_VER_25, RTL_TD_1), // PCI-E |
| 175 | _R("RTL8168d/8111d", RTL_GIGA_MAC_VER_26, RTL_TD_1), // PCI-E |
| 176 | _R("RTL8168dp/8111dp", RTL_GIGA_MAC_VER_27, RTL_TD_1), // PCI-E |
| 177 | _R("RTL8168dp/8111dp", RTL_GIGA_MAC_VER_28, RTL_TD_1), // PCI-E |
| 178 | _R("RTL8105e", RTL_GIGA_MAC_VER_29, RTL_TD_1), // PCI-E |
| 179 | _R("RTL8105e", RTL_GIGA_MAC_VER_30, RTL_TD_1), // PCI-E |
| 180 | _R("RTL8168dp/8111dp", RTL_GIGA_MAC_VER_31, RTL_TD_1), // PCI-E |
| 181 | _R("RTL8168e/8111e", RTL_GIGA_MAC_VER_32, RTL_TD_1), // PCI-E |
| 182 | _R("RTL8168e/8111e", RTL_GIGA_MAC_VER_33, RTL_TD_1) // PCI-E |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | }; |
| 184 | #undef _R |
| 185 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 186 | static const struct rtl_firmware_info { |
| 187 | int mac_version; |
| 188 | const char *fw_name; |
| 189 | } rtl_firmware_infos[] = { |
| 190 | { .mac_version = RTL_GIGA_MAC_VER_25, .fw_name = FIRMWARE_8168D_1 }, |
| 191 | { .mac_version = RTL_GIGA_MAC_VER_26, .fw_name = FIRMWARE_8168D_2 }, |
| 192 | { .mac_version = RTL_GIGA_MAC_VER_29, .fw_name = FIRMWARE_8105E_1 }, |
David S. Miller | 2bd93d7 | 2011-04-26 12:16:46 -0700 | [diff] [blame] | 193 | { .mac_version = RTL_GIGA_MAC_VER_30, .fw_name = FIRMWARE_8105E_1 }, |
Francois Romieu | 15ecd03 | 2011-04-27 13:52:22 -0700 | [diff] [blame] | 194 | { .mac_version = RTL_GIGA_MAC_VER_32, .fw_name = FIRMWARE_8168E_1 }, |
| 195 | { .mac_version = RTL_GIGA_MAC_VER_33, .fw_name = FIRMWARE_8168E_2 } |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 196 | }; |
| 197 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 198 | enum cfg_version { |
| 199 | RTL_CFG_0 = 0x00, |
| 200 | RTL_CFG_1, |
| 201 | RTL_CFG_2 |
| 202 | }; |
| 203 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 204 | static void rtl_hw_start_8169(struct net_device *); |
| 205 | static void rtl_hw_start_8168(struct net_device *); |
| 206 | static void rtl_hw_start_8101(struct net_device *); |
| 207 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 208 | static DEFINE_PCI_DEVICE_TABLE(rtl8169_pci_tbl) = { |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 209 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 }, |
Francois Romieu | d2eed8c | 2006-08-31 22:01:07 +0200 | [diff] [blame] | 210 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8136), 0, 0, RTL_CFG_2 }, |
Francois Romieu | d81bf55 | 2006-09-20 21:31:20 +0200 | [diff] [blame] | 211 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_0 }, |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 212 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_1 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 213 | { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 }, |
| 214 | { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4300), 0, 0, RTL_CFG_0 }, |
Francois Romieu | bc1660b | 2007-10-12 23:58:09 +0200 | [diff] [blame] | 215 | { PCI_DEVICE(PCI_VENDOR_ID_AT, 0xc107), 0, 0, RTL_CFG_0 }, |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 216 | { PCI_DEVICE(0x16ec, 0x0116), 0, 0, RTL_CFG_0 }, |
| 217 | { PCI_VENDOR_ID_LINKSYS, 0x1032, |
| 218 | PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 }, |
Ciaran McCreesh | 11d2e28 | 2007-11-01 22:48:15 +0100 | [diff] [blame] | 219 | { 0x0001, 0x8168, |
| 220 | PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | {0,}, |
| 222 | }; |
| 223 | |
| 224 | MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl); |
| 225 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 226 | static int rx_buf_sz = 16383; |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 227 | static int use_dac; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 228 | static struct { |
| 229 | u32 msg_enable; |
| 230 | } debug = { -1 }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 232 | enum rtl_registers { |
| 233 | MAC0 = 0, /* Ethernet hardware address. */ |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 234 | MAC4 = 4, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 235 | MAR0 = 8, /* Multicast filter. */ |
| 236 | CounterAddrLow = 0x10, |
| 237 | CounterAddrHigh = 0x14, |
| 238 | TxDescStartAddrLow = 0x20, |
| 239 | TxDescStartAddrHigh = 0x24, |
| 240 | TxHDescStartAddrLow = 0x28, |
| 241 | TxHDescStartAddrHigh = 0x2c, |
| 242 | FLASH = 0x30, |
| 243 | ERSR = 0x36, |
| 244 | ChipCmd = 0x37, |
| 245 | TxPoll = 0x38, |
| 246 | IntrMask = 0x3c, |
| 247 | IntrStatus = 0x3e, |
| 248 | TxConfig = 0x40, |
| 249 | RxConfig = 0x44, |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 250 | |
| 251 | #define RTL_RX_CONFIG_MASK 0xff7e1880u |
| 252 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 253 | RxMissed = 0x4c, |
| 254 | Cfg9346 = 0x50, |
| 255 | Config0 = 0x51, |
| 256 | Config1 = 0x52, |
| 257 | Config2 = 0x53, |
| 258 | Config3 = 0x54, |
| 259 | Config4 = 0x55, |
| 260 | Config5 = 0x56, |
| 261 | MultiIntr = 0x5c, |
| 262 | PHYAR = 0x60, |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 263 | PHYstatus = 0x6c, |
| 264 | RxMaxSize = 0xda, |
| 265 | CPlusCmd = 0xe0, |
| 266 | IntrMitigate = 0xe2, |
| 267 | RxDescAddrLow = 0xe4, |
| 268 | RxDescAddrHigh = 0xe8, |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 269 | EarlyTxThres = 0xec, /* 8169. Unit of 32 bytes. */ |
| 270 | |
| 271 | #define NoEarlyTx 0x3f /* Max value : no early transmit. */ |
| 272 | |
| 273 | MaxTxPacketSize = 0xec, /* 8101/8168. Unit of 128 bytes. */ |
| 274 | |
| 275 | #define TxPacketMax (8064 >> 7) |
| 276 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 277 | FuncEvent = 0xf0, |
| 278 | FuncEventMask = 0xf4, |
| 279 | FuncPresetState = 0xf8, |
| 280 | FuncForceEvent = 0xfc, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | }; |
| 282 | |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 283 | enum rtl8110_registers { |
| 284 | TBICSR = 0x64, |
| 285 | TBI_ANAR = 0x68, |
| 286 | TBI_LPAR = 0x6a, |
| 287 | }; |
| 288 | |
| 289 | enum rtl8168_8101_registers { |
| 290 | CSIDR = 0x64, |
| 291 | CSIAR = 0x68, |
| 292 | #define CSIAR_FLAG 0x80000000 |
| 293 | #define CSIAR_WRITE_CMD 0x80000000 |
| 294 | #define CSIAR_BYTE_ENABLE 0x0f |
| 295 | #define CSIAR_BYTE_ENABLE_SHIFT 12 |
| 296 | #define CSIAR_ADDR_MASK 0x0fff |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 297 | PMCH = 0x6f, |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 298 | EPHYAR = 0x80, |
| 299 | #define EPHYAR_FLAG 0x80000000 |
| 300 | #define EPHYAR_WRITE_CMD 0x80000000 |
| 301 | #define EPHYAR_REG_MASK 0x1f |
| 302 | #define EPHYAR_REG_SHIFT 16 |
| 303 | #define EPHYAR_DATA_MASK 0xffff |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 304 | DLLPR = 0xd0, |
| 305 | #define PM_SWITCH (1 << 6) |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 306 | DBG_REG = 0xd1, |
| 307 | #define FIX_NAK_1 (1 << 4) |
| 308 | #define FIX_NAK_2 (1 << 3) |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 309 | TWSI = 0xd2, |
| 310 | MCU = 0xd3, |
| 311 | #define EN_NDP (1 << 3) |
| 312 | #define EN_OOB_RESET (1 << 2) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 313 | EFUSEAR = 0xdc, |
| 314 | #define EFUSEAR_FLAG 0x80000000 |
| 315 | #define EFUSEAR_WRITE_CMD 0x80000000 |
| 316 | #define EFUSEAR_READ_CMD 0x00000000 |
| 317 | #define EFUSEAR_REG_MASK 0x03ff |
| 318 | #define EFUSEAR_REG_SHIFT 8 |
| 319 | #define EFUSEAR_DATA_MASK 0xff |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 320 | }; |
| 321 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 322 | enum rtl8168_registers { |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 323 | ERIDR = 0x70, |
| 324 | ERIAR = 0x74, |
| 325 | #define ERIAR_FLAG 0x80000000 |
| 326 | #define ERIAR_WRITE_CMD 0x80000000 |
| 327 | #define ERIAR_READ_CMD 0x00000000 |
| 328 | #define ERIAR_ADDR_BYTE_ALIGN 4 |
| 329 | #define ERIAR_EXGMAC 0 |
| 330 | #define ERIAR_MSIX 1 |
| 331 | #define ERIAR_ASF 2 |
| 332 | #define ERIAR_TYPE_SHIFT 16 |
| 333 | #define ERIAR_BYTEEN 0x0f |
| 334 | #define ERIAR_BYTEEN_SHIFT 12 |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 335 | EPHY_RXER_NUM = 0x7c, |
| 336 | OCPDR = 0xb0, /* OCP GPHY access */ |
| 337 | #define OCPDR_WRITE_CMD 0x80000000 |
| 338 | #define OCPDR_READ_CMD 0x00000000 |
| 339 | #define OCPDR_REG_MASK 0x7f |
| 340 | #define OCPDR_GPHY_REG_SHIFT 16 |
| 341 | #define OCPDR_DATA_MASK 0xffff |
| 342 | OCPAR = 0xb4, |
| 343 | #define OCPAR_FLAG 0x80000000 |
| 344 | #define OCPAR_GPHY_WRITE_CMD 0x8000f060 |
| 345 | #define OCPAR_GPHY_READ_CMD 0x0000f060 |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 346 | RDSAR1 = 0xd0, /* 8168c only. Undocumented on 8168dp */ |
| 347 | MISC = 0xf0, /* 8168e only. */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 348 | #define TXPLA_RST (1 << 29) |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 349 | }; |
| 350 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 351 | enum rtl_register_content { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | /* InterruptStatusBits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 353 | SYSErr = 0x8000, |
| 354 | PCSTimeout = 0x4000, |
| 355 | SWInt = 0x0100, |
| 356 | TxDescUnavail = 0x0080, |
| 357 | RxFIFOOver = 0x0040, |
| 358 | LinkChg = 0x0020, |
| 359 | RxOverflow = 0x0010, |
| 360 | TxErr = 0x0008, |
| 361 | TxOK = 0x0004, |
| 362 | RxErr = 0x0002, |
| 363 | RxOK = 0x0001, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | |
| 365 | /* RxStatusDesc */ |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 366 | RxFOVF = (1 << 23), |
| 367 | RxRWT = (1 << 22), |
| 368 | RxRES = (1 << 21), |
| 369 | RxRUNT = (1 << 20), |
| 370 | RxCRC = (1 << 19), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | |
| 372 | /* ChipCmdBits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 373 | CmdReset = 0x10, |
| 374 | CmdRxEnb = 0x08, |
| 375 | CmdTxEnb = 0x04, |
| 376 | RxBufEmpty = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | |
Francois Romieu | 275391a | 2007-02-23 23:50:28 +0100 | [diff] [blame] | 378 | /* TXPoll register p.5 */ |
| 379 | HPQ = 0x80, /* Poll cmd on the high prio queue */ |
| 380 | NPQ = 0x40, /* Poll cmd on the low prio queue */ |
| 381 | FSWInt = 0x01, /* Forced software interrupt */ |
| 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | /* Cfg9346Bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 384 | Cfg9346_Lock = 0x00, |
| 385 | Cfg9346_Unlock = 0xc0, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | |
| 387 | /* rx_mode_bits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 388 | AcceptErr = 0x20, |
| 389 | AcceptRunt = 0x10, |
| 390 | AcceptBroadcast = 0x08, |
| 391 | AcceptMulticast = 0x04, |
| 392 | AcceptMyPhys = 0x02, |
| 393 | AcceptAllPhys = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | |
| 395 | /* RxConfigBits */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 396 | RxCfgFIFOShift = 13, |
| 397 | RxCfgDMAShift = 8, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
| 399 | /* TxConfigBits */ |
| 400 | TxInterFrameGapShift = 24, |
| 401 | TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */ |
| 402 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 403 | /* Config1 register p.24 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 404 | LEDS1 = (1 << 7), |
| 405 | LEDS0 = (1 << 6), |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 406 | MSIEnable = (1 << 5), /* Enable Message Signaled Interrupt */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 407 | Speed_down = (1 << 4), |
| 408 | MEMMAP = (1 << 3), |
| 409 | IOMAP = (1 << 2), |
| 410 | VPD = (1 << 1), |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 411 | PMEnable = (1 << 0), /* Power Management Enable */ |
| 412 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 413 | /* Config2 register p. 25 */ |
| 414 | PCI_Clock_66MHz = 0x01, |
| 415 | PCI_Clock_33MHz = 0x00, |
| 416 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 417 | /* Config3 register p.25 */ |
| 418 | MagicPacket = (1 << 5), /* Wake up when receives a Magic Packet */ |
| 419 | LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 420 | Beacon_en = (1 << 0), /* 8168 only. Reserved in the 8168b */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 421 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 422 | /* Config5 register p.27 */ |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 423 | BWF = (1 << 6), /* Accept Broadcast wakeup frame */ |
| 424 | MWF = (1 << 5), /* Accept Multicast wakeup frame */ |
| 425 | UWF = (1 << 4), /* Accept Unicast wakeup frame */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 426 | Spi_en = (1 << 3), |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 427 | LanWake = (1 << 1), /* LanWake enable/disable */ |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 428 | PMEStatus = (1 << 0), /* PME status can be reset by PCI RST# */ |
| 429 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | /* TBICSR p.28 */ |
| 431 | TBIReset = 0x80000000, |
| 432 | TBILoopback = 0x40000000, |
| 433 | TBINwEnable = 0x20000000, |
| 434 | TBINwRestart = 0x10000000, |
| 435 | TBILinkOk = 0x02000000, |
| 436 | TBINwComplete = 0x01000000, |
| 437 | |
| 438 | /* CPlusCmd p.31 */ |
Francois Romieu | f162a5d | 2008-06-01 22:37:49 +0200 | [diff] [blame] | 439 | EnableBist = (1 << 15), // 8168 8101 |
| 440 | Mac_dbgo_oe = (1 << 14), // 8168 8101 |
| 441 | Normal_mode = (1 << 13), // unused |
| 442 | Force_half_dup = (1 << 12), // 8168 8101 |
| 443 | Force_rxflow_en = (1 << 11), // 8168 8101 |
| 444 | Force_txflow_en = (1 << 10), // 8168 8101 |
| 445 | Cxpl_dbg_sel = (1 << 9), // 8168 8101 |
| 446 | ASF = (1 << 8), // 8168 8101 |
| 447 | PktCntrDisable = (1 << 7), // 8168 8101 |
| 448 | Mac_dbgo_sel = 0x001c, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | RxVlan = (1 << 6), |
| 450 | RxChkSum = (1 << 5), |
| 451 | PCIDAC = (1 << 4), |
| 452 | PCIMulRW = (1 << 3), |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 453 | INTT_0 = 0x0000, // 8168 |
| 454 | INTT_1 = 0x0001, // 8168 |
| 455 | INTT_2 = 0x0002, // 8168 |
| 456 | INTT_3 = 0x0003, // 8168 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | |
| 458 | /* rtl8169_PHYstatus */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 459 | TBI_Enable = 0x80, |
| 460 | TxFlowCtrl = 0x40, |
| 461 | RxFlowCtrl = 0x20, |
| 462 | _1000bpsF = 0x10, |
| 463 | _100bps = 0x08, |
| 464 | _10bps = 0x04, |
| 465 | LinkStatus = 0x02, |
| 466 | FullDup = 0x01, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | /* _TBICSRBit */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 469 | TBILinkOK = 0x02000000, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 470 | |
| 471 | /* DumpCounterCommand */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 472 | CounterDump = 0x8, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | }; |
| 474 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 475 | enum rtl_desc_bit { |
| 476 | /* First doubleword. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | DescOwn = (1 << 31), /* Descriptor is owned by NIC */ |
| 478 | RingEnd = (1 << 30), /* End of descriptor ring */ |
| 479 | FirstFrag = (1 << 29), /* First segment of a packet */ |
| 480 | LastFrag = (1 << 28), /* Final segment of a packet */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 481 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 483 | /* Generic case. */ |
| 484 | enum rtl_tx_desc_bit { |
| 485 | /* First doubleword. */ |
| 486 | TD_LSO = (1 << 27), /* Large Send Offload */ |
| 487 | #define TD_MSS_MAX 0x07ffu /* MSS value */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 489 | /* Second doubleword. */ |
| 490 | TxVlanTag = (1 << 17), /* Add VLAN tag */ |
| 491 | }; |
| 492 | |
| 493 | /* 8169, 8168b and 810x except 8102e. */ |
| 494 | enum rtl_tx_desc_bit_0 { |
| 495 | /* First doubleword. */ |
| 496 | #define TD0_MSS_SHIFT 16 /* MSS position (11 bits) */ |
| 497 | TD0_TCP_CS = (1 << 16), /* Calculate TCP/IP checksum */ |
| 498 | TD0_UDP_CS = (1 << 17), /* Calculate UDP/IP checksum */ |
| 499 | TD0_IP_CS = (1 << 18), /* Calculate IP checksum */ |
| 500 | }; |
| 501 | |
| 502 | /* 8102e, 8168c and beyond. */ |
| 503 | enum rtl_tx_desc_bit_1 { |
| 504 | /* Second doubleword. */ |
| 505 | #define TD1_MSS_SHIFT 18 /* MSS position (11 bits) */ |
| 506 | TD1_IP_CS = (1 << 29), /* Calculate IP checksum */ |
| 507 | TD1_TCP_CS = (1 << 30), /* Calculate TCP/IP checksum */ |
| 508 | TD1_UDP_CS = (1 << 31), /* Calculate UDP/IP checksum */ |
| 509 | }; |
| 510 | |
| 511 | static const struct rtl_tx_desc_info { |
| 512 | struct { |
| 513 | u32 udp; |
| 514 | u32 tcp; |
| 515 | } checksum; |
| 516 | u16 mss_shift; |
| 517 | u16 opts_offset; |
| 518 | } tx_desc_info [] = { |
| 519 | [RTL_TD_0] = { |
| 520 | .checksum = { |
| 521 | .udp = TD0_IP_CS | TD0_UDP_CS, |
| 522 | .tcp = TD0_IP_CS | TD0_TCP_CS |
| 523 | }, |
| 524 | .mss_shift = TD0_MSS_SHIFT, |
| 525 | .opts_offset = 0 |
| 526 | }, |
| 527 | [RTL_TD_1] = { |
| 528 | .checksum = { |
| 529 | .udp = TD1_IP_CS | TD1_UDP_CS, |
| 530 | .tcp = TD1_IP_CS | TD1_TCP_CS |
| 531 | }, |
| 532 | .mss_shift = TD1_MSS_SHIFT, |
| 533 | .opts_offset = 1 |
| 534 | } |
| 535 | }; |
| 536 | |
| 537 | enum rtl_rx_desc_bit { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | /* Rx private */ |
| 539 | PID1 = (1 << 18), /* Protocol ID bit 1/2 */ |
| 540 | PID0 = (1 << 17), /* Protocol ID bit 2/2 */ |
| 541 | |
| 542 | #define RxProtoUDP (PID1) |
| 543 | #define RxProtoTCP (PID0) |
| 544 | #define RxProtoIP (PID1 | PID0) |
| 545 | #define RxProtoMask RxProtoIP |
| 546 | |
| 547 | IPFail = (1 << 16), /* IP checksum failed */ |
| 548 | UDPFail = (1 << 15), /* UDP/IP checksum failed */ |
| 549 | TCPFail = (1 << 14), /* TCP/IP checksum failed */ |
| 550 | RxVlanTag = (1 << 16), /* VLAN tag available */ |
| 551 | }; |
| 552 | |
| 553 | #define RsvdMask 0x3fffc000 |
| 554 | |
| 555 | struct TxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 556 | __le32 opts1; |
| 557 | __le32 opts2; |
| 558 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 559 | }; |
| 560 | |
| 561 | struct RxDesc { |
Rolf Eike Beer | 6cccd6e | 2007-05-21 22:11:04 +0200 | [diff] [blame] | 562 | __le32 opts1; |
| 563 | __le32 opts2; |
| 564 | __le64 addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | }; |
| 566 | |
| 567 | struct ring_info { |
| 568 | struct sk_buff *skb; |
| 569 | u32 len; |
| 570 | u8 __pad[sizeof(void *) - sizeof(u32)]; |
| 571 | }; |
| 572 | |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 573 | enum features { |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 574 | RTL_FEATURE_WOL = (1 << 0), |
| 575 | RTL_FEATURE_MSI = (1 << 1), |
| 576 | RTL_FEATURE_GMII = (1 << 2), |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 577 | }; |
| 578 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 579 | struct rtl8169_counters { |
| 580 | __le64 tx_packets; |
| 581 | __le64 rx_packets; |
| 582 | __le64 tx_errors; |
| 583 | __le32 rx_errors; |
| 584 | __le16 rx_missed; |
| 585 | __le16 align_errors; |
| 586 | __le32 tx_one_collision; |
| 587 | __le32 tx_multi_collision; |
| 588 | __le64 rx_unicast; |
| 589 | __le64 rx_broadcast; |
| 590 | __le32 rx_multicast; |
| 591 | __le16 tx_aborted; |
| 592 | __le16 tx_underun; |
| 593 | }; |
| 594 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | struct rtl8169_private { |
| 596 | void __iomem *mmio_addr; /* memory map physical address */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 597 | struct pci_dev *pci_dev; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 598 | struct net_device *dev; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 599 | struct napi_struct napi; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 600 | spinlock_t lock; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 601 | u32 msg_enable; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 602 | u16 txd_version; |
| 603 | u16 mac_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */ |
| 605 | u32 cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */ |
| 606 | u32 dirty_rx; |
| 607 | u32 dirty_tx; |
| 608 | struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */ |
| 609 | struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */ |
| 610 | dma_addr_t TxPhyAddr; |
| 611 | dma_addr_t RxPhyAddr; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 612 | void *Rx_databuff[NUM_RX_DESC]; /* Rx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | struct timer_list timer; |
| 615 | u16 cp_cmd; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 616 | u16 intr_event; |
| 617 | u16 napi_event; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | u16 intr_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | int phy_1000_ctrl_reg; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 620 | |
| 621 | struct mdio_ops { |
| 622 | void (*write)(void __iomem *, int, int); |
| 623 | int (*read)(void __iomem *, int); |
| 624 | } mdio_ops; |
| 625 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 626 | struct pll_power_ops { |
| 627 | void (*down)(struct rtl8169_private *); |
| 628 | void (*up)(struct rtl8169_private *); |
| 629 | } pll_power_ops; |
| 630 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 631 | 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] | 632 | int (*get_settings)(struct net_device *, struct ethtool_cmd *); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 633 | void (*phy_reset_enable)(struct rtl8169_private *tp); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 634 | void (*hw_start)(struct net_device *); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 635 | unsigned int (*phy_reset_pending)(struct rtl8169_private *tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | unsigned int (*link_ok)(void __iomem *); |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 637 | int (*do_ioctl)(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd); |
Francois Romieu | 9c14cea | 2008-07-05 00:21:15 +0200 | [diff] [blame] | 638 | int pcie_cap; |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 639 | struct delayed_work task; |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 640 | unsigned features; |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 641 | |
| 642 | struct mii_if_info mii; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 643 | struct rtl8169_counters counters; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 644 | u32 saved_wolopts; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 645 | |
| 646 | const struct firmware *fw; |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 647 | #define RTL_FIRMWARE_UNKNOWN ERR_PTR(-EAGAIN); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | }; |
| 649 | |
Ralf Baechle | 979b6c1 | 2005-06-13 14:30:40 -0700 | [diff] [blame] | 650 | MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 651 | MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | module_param(use_dac, int, 0); |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 653 | 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] | 654 | module_param_named(debug, debug.msg_enable, int, 0); |
| 655 | MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | MODULE_LICENSE("GPL"); |
| 657 | MODULE_VERSION(RTL8169_VERSION); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 658 | MODULE_FIRMWARE(FIRMWARE_8168D_1); |
| 659 | MODULE_FIRMWARE(FIRMWARE_8168D_2); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 660 | MODULE_FIRMWARE(FIRMWARE_8168E_1); |
| 661 | MODULE_FIRMWARE(FIRMWARE_8168E_2); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 662 | MODULE_FIRMWARE(FIRMWARE_8105E_1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | |
| 664 | static int rtl8169_open(struct net_device *dev); |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 665 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 666 | struct net_device *dev); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 667 | static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | static int rtl8169_init_ring(struct net_device *dev); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 669 | static void rtl_hw_start(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | static int rtl8169_close(struct net_device *dev); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 671 | static void rtl_set_rx_mode(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | static void rtl8169_tx_timeout(struct net_device *dev); |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 673 | static struct net_device_stats *rtl8169_get_stats(struct net_device *dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 674 | static int rtl8169_rx_interrupt(struct net_device *, struct rtl8169_private *, |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 675 | void __iomem *, u32 budget); |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 676 | static int rtl8169_change_mtu(struct net_device *dev, int new_mtu); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | static void rtl8169_down(struct net_device *dev); |
Francois Romieu | 99f252b | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 678 | static void rtl8169_rx_clear(struct rtl8169_private *tp); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 679 | static int rtl8169_poll(struct napi_struct *napi, int budget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 681 | static const unsigned int rtl8169_rx_config = |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 682 | (RX_FIFO_THRESH << RxCfgFIFOShift) | (RX_DMA_BURST << RxCfgDMAShift); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 684 | static u32 ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
| 685 | { |
| 686 | void __iomem *ioaddr = tp->mmio_addr; |
| 687 | int i; |
| 688 | |
| 689 | RTL_W32(OCPAR, ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
| 690 | for (i = 0; i < 20; i++) { |
| 691 | udelay(100); |
| 692 | if (RTL_R32(OCPAR) & OCPAR_FLAG) |
| 693 | break; |
| 694 | } |
| 695 | return RTL_R32(OCPDR); |
| 696 | } |
| 697 | |
| 698 | static void ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, u32 data) |
| 699 | { |
| 700 | void __iomem *ioaddr = tp->mmio_addr; |
| 701 | int i; |
| 702 | |
| 703 | RTL_W32(OCPDR, data); |
| 704 | RTL_W32(OCPAR, OCPAR_FLAG | ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
| 705 | for (i = 0; i < 20; i++) { |
| 706 | udelay(100); |
| 707 | if ((RTL_R32(OCPAR) & OCPAR_FLAG) == 0) |
| 708 | break; |
| 709 | } |
| 710 | } |
| 711 | |
Hayes Wang | fac5b3c | 2011-02-22 17:26:20 +0800 | [diff] [blame] | 712 | static void rtl8168_oob_notify(struct rtl8169_private *tp, u8 cmd) |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 713 | { |
Hayes Wang | fac5b3c | 2011-02-22 17:26:20 +0800 | [diff] [blame] | 714 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 715 | int i; |
| 716 | |
| 717 | RTL_W8(ERIDR, cmd); |
| 718 | RTL_W32(ERIAR, 0x800010e8); |
| 719 | msleep(2); |
| 720 | for (i = 0; i < 5; i++) { |
| 721 | udelay(100); |
| 722 | if (!(RTL_R32(ERIDR) & ERIAR_FLAG)) |
| 723 | break; |
| 724 | } |
| 725 | |
Hayes Wang | fac5b3c | 2011-02-22 17:26:20 +0800 | [diff] [blame] | 726 | ocp_write(tp, 0x1, 0x30, 0x00000001); |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 727 | } |
| 728 | |
| 729 | #define OOB_CMD_RESET 0x00 |
| 730 | #define OOB_CMD_DRIVER_START 0x05 |
| 731 | #define OOB_CMD_DRIVER_STOP 0x06 |
| 732 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 733 | static u16 rtl8168_get_ocp_reg(struct rtl8169_private *tp) |
| 734 | { |
| 735 | return (tp->mac_version == RTL_GIGA_MAC_VER_31) ? 0xb8 : 0x10; |
| 736 | } |
| 737 | |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 738 | static void rtl8168_driver_start(struct rtl8169_private *tp) |
| 739 | { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 740 | u16 reg; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 741 | int i; |
| 742 | |
| 743 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_START); |
| 744 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 745 | reg = rtl8168_get_ocp_reg(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 746 | |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 747 | for (i = 0; i < 10; i++) { |
| 748 | msleep(10); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 749 | if (ocp_read(tp, 0x0f, reg) & 0x00000800) |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 750 | break; |
| 751 | } |
| 752 | } |
| 753 | |
| 754 | static void rtl8168_driver_stop(struct rtl8169_private *tp) |
| 755 | { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 756 | u16 reg; |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 757 | int i; |
| 758 | |
| 759 | rtl8168_oob_notify(tp, OOB_CMD_DRIVER_STOP); |
| 760 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 761 | reg = rtl8168_get_ocp_reg(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 762 | |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 763 | for (i = 0; i < 10; i++) { |
| 764 | msleep(10); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 765 | if ((ocp_read(tp, 0x0f, reg) & 0x00000800) == 0) |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 766 | break; |
| 767 | } |
| 768 | } |
| 769 | |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 770 | static int r8168dp_check_dash(struct rtl8169_private *tp) |
| 771 | { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 772 | u16 reg = rtl8168_get_ocp_reg(tp); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 773 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 774 | return (ocp_read(tp, 0x0f, reg) & 0x00008000) ? 1 : 0; |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 775 | } |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 776 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 777 | 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] | 778 | { |
| 779 | int i; |
| 780 | |
Francois Romieu | a6baf3a | 2007-11-08 23:23:21 +0100 | [diff] [blame] | 781 | RTL_W32(PHYAR, 0x80000000 | (reg_addr & 0x1f) << 16 | (value & 0xffff)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | |
Francois Romieu | 2371408 | 2006-01-29 00:49:09 +0100 | [diff] [blame] | 783 | for (i = 20; i > 0; i--) { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 784 | /* |
| 785 | * Check if the RTL8169 has completed writing to the specified |
| 786 | * MII register. |
| 787 | */ |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 788 | if (!(RTL_R32(PHYAR) & 0x80000000)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | break; |
Francois Romieu | 2371408 | 2006-01-29 00:49:09 +0100 | [diff] [blame] | 790 | udelay(25); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | } |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 792 | /* |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 793 | * According to hardware specs a 20us delay is required after write |
| 794 | * complete indication, but before sending next command. |
Timo Teräs | 024a07b | 2010-06-06 15:38:47 -0700 | [diff] [blame] | 795 | */ |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 796 | udelay(20); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 797 | } |
| 798 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 799 | static int r8169_mdio_read(void __iomem *ioaddr, int reg_addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 800 | { |
| 801 | int i, value = -1; |
| 802 | |
Francois Romieu | a6baf3a | 2007-11-08 23:23:21 +0100 | [diff] [blame] | 803 | RTL_W32(PHYAR, 0x0 | (reg_addr & 0x1f) << 16); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 804 | |
Francois Romieu | 2371408 | 2006-01-29 00:49:09 +0100 | [diff] [blame] | 805 | for (i = 20; i > 0; i--) { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 806 | /* |
| 807 | * Check if the RTL8169 has completed retrieving data from |
| 808 | * the specified MII register. |
| 809 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | if (RTL_R32(PHYAR) & 0x80000000) { |
Francois Romieu | a6baf3a | 2007-11-08 23:23:21 +0100 | [diff] [blame] | 811 | value = RTL_R32(PHYAR) & 0xffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 812 | break; |
| 813 | } |
Francois Romieu | 2371408 | 2006-01-29 00:49:09 +0100 | [diff] [blame] | 814 | udelay(25); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 815 | } |
Timo Teräs | 81a95f0 | 2010-06-09 17:31:48 -0700 | [diff] [blame] | 816 | /* |
| 817 | * According to hardware specs a 20us delay is required after read |
| 818 | * complete indication, but before sending next command. |
| 819 | */ |
| 820 | udelay(20); |
| 821 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 822 | return value; |
| 823 | } |
| 824 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 825 | static void r8168dp_1_mdio_access(void __iomem *ioaddr, int reg_addr, u32 data) |
| 826 | { |
| 827 | int i; |
| 828 | |
| 829 | RTL_W32(OCPDR, data | |
| 830 | ((reg_addr & OCPDR_REG_MASK) << OCPDR_GPHY_REG_SHIFT)); |
| 831 | RTL_W32(OCPAR, OCPAR_GPHY_WRITE_CMD); |
| 832 | RTL_W32(EPHY_RXER_NUM, 0); |
| 833 | |
| 834 | for (i = 0; i < 100; i++) { |
| 835 | mdelay(1); |
| 836 | if (!(RTL_R32(OCPAR) & OCPAR_FLAG)) |
| 837 | break; |
| 838 | } |
| 839 | } |
| 840 | |
| 841 | static void r8168dp_1_mdio_write(void __iomem *ioaddr, int reg_addr, int value) |
| 842 | { |
| 843 | r8168dp_1_mdio_access(ioaddr, reg_addr, OCPDR_WRITE_CMD | |
| 844 | (value & OCPDR_DATA_MASK)); |
| 845 | } |
| 846 | |
| 847 | static int r8168dp_1_mdio_read(void __iomem *ioaddr, int reg_addr) |
| 848 | { |
| 849 | int i; |
| 850 | |
| 851 | r8168dp_1_mdio_access(ioaddr, reg_addr, OCPDR_READ_CMD); |
| 852 | |
| 853 | mdelay(1); |
| 854 | RTL_W32(OCPAR, OCPAR_GPHY_READ_CMD); |
| 855 | RTL_W32(EPHY_RXER_NUM, 0); |
| 856 | |
| 857 | for (i = 0; i < 100; i++) { |
| 858 | mdelay(1); |
| 859 | if (RTL_R32(OCPAR) & OCPAR_FLAG) |
| 860 | break; |
| 861 | } |
| 862 | |
| 863 | return RTL_R32(OCPDR) & OCPDR_DATA_MASK; |
| 864 | } |
| 865 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 866 | #define R8168DP_1_MDIO_ACCESS_BIT 0x00020000 |
| 867 | |
| 868 | static void r8168dp_2_mdio_start(void __iomem *ioaddr) |
| 869 | { |
| 870 | RTL_W32(0xd0, RTL_R32(0xd0) & ~R8168DP_1_MDIO_ACCESS_BIT); |
| 871 | } |
| 872 | |
| 873 | static void r8168dp_2_mdio_stop(void __iomem *ioaddr) |
| 874 | { |
| 875 | RTL_W32(0xd0, RTL_R32(0xd0) | R8168DP_1_MDIO_ACCESS_BIT); |
| 876 | } |
| 877 | |
| 878 | static void r8168dp_2_mdio_write(void __iomem *ioaddr, int reg_addr, int value) |
| 879 | { |
| 880 | r8168dp_2_mdio_start(ioaddr); |
| 881 | |
| 882 | r8169_mdio_write(ioaddr, reg_addr, value); |
| 883 | |
| 884 | r8168dp_2_mdio_stop(ioaddr); |
| 885 | } |
| 886 | |
| 887 | static int r8168dp_2_mdio_read(void __iomem *ioaddr, int reg_addr) |
| 888 | { |
| 889 | int value; |
| 890 | |
| 891 | r8168dp_2_mdio_start(ioaddr); |
| 892 | |
| 893 | value = r8169_mdio_read(ioaddr, reg_addr); |
| 894 | |
| 895 | r8168dp_2_mdio_stop(ioaddr); |
| 896 | |
| 897 | return value; |
| 898 | } |
| 899 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 900 | static void rtl_writephy(struct rtl8169_private *tp, int location, u32 val) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 901 | { |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 902 | tp->mdio_ops.write(tp->mmio_addr, location, val); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 903 | } |
| 904 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 905 | static int rtl_readphy(struct rtl8169_private *tp, int location) |
| 906 | { |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 907 | return tp->mdio_ops.read(tp->mmio_addr, location); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | static void rtl_patchphy(struct rtl8169_private *tp, int reg_addr, int value) |
| 911 | { |
| 912 | rtl_writephy(tp, reg_addr, rtl_readphy(tp, reg_addr) | value); |
| 913 | } |
| 914 | |
| 915 | 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] | 916 | { |
| 917 | int val; |
| 918 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 919 | val = rtl_readphy(tp, reg_addr); |
| 920 | rtl_writephy(tp, reg_addr, (val | p) & ~m); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 921 | } |
| 922 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 923 | static void rtl_mdio_write(struct net_device *dev, int phy_id, int location, |
| 924 | int val) |
| 925 | { |
| 926 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 927 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 928 | rtl_writephy(tp, location, val); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 929 | } |
| 930 | |
| 931 | static int rtl_mdio_read(struct net_device *dev, int phy_id, int location) |
| 932 | { |
| 933 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 934 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 935 | return rtl_readphy(tp, location); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 936 | } |
| 937 | |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 938 | static void rtl_ephy_write(void __iomem *ioaddr, int reg_addr, int value) |
| 939 | { |
| 940 | unsigned int i; |
| 941 | |
| 942 | RTL_W32(EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) | |
| 943 | (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
| 944 | |
| 945 | for (i = 0; i < 100; i++) { |
| 946 | if (!(RTL_R32(EPHYAR) & EPHYAR_FLAG)) |
| 947 | break; |
| 948 | udelay(10); |
| 949 | } |
| 950 | } |
| 951 | |
| 952 | static u16 rtl_ephy_read(void __iomem *ioaddr, int reg_addr) |
| 953 | { |
| 954 | u16 value = 0xffff; |
| 955 | unsigned int i; |
| 956 | |
| 957 | RTL_W32(EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
| 958 | |
| 959 | for (i = 0; i < 100; i++) { |
| 960 | if (RTL_R32(EPHYAR) & EPHYAR_FLAG) { |
| 961 | value = RTL_R32(EPHYAR) & EPHYAR_DATA_MASK; |
| 962 | break; |
| 963 | } |
| 964 | udelay(10); |
| 965 | } |
| 966 | |
| 967 | return value; |
| 968 | } |
| 969 | |
| 970 | static void rtl_csi_write(void __iomem *ioaddr, int addr, int value) |
| 971 | { |
| 972 | unsigned int i; |
| 973 | |
| 974 | RTL_W32(CSIDR, value); |
| 975 | RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
| 976 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 977 | |
| 978 | for (i = 0; i < 100; i++) { |
| 979 | if (!(RTL_R32(CSIAR) & CSIAR_FLAG)) |
| 980 | break; |
| 981 | udelay(10); |
| 982 | } |
| 983 | } |
| 984 | |
| 985 | static u32 rtl_csi_read(void __iomem *ioaddr, int addr) |
| 986 | { |
| 987 | u32 value = ~0x00; |
| 988 | unsigned int i; |
| 989 | |
| 990 | RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) | |
| 991 | CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
| 992 | |
| 993 | for (i = 0; i < 100; i++) { |
| 994 | if (RTL_R32(CSIAR) & CSIAR_FLAG) { |
| 995 | value = RTL_R32(CSIDR); |
| 996 | break; |
| 997 | } |
| 998 | udelay(10); |
| 999 | } |
| 1000 | |
| 1001 | return value; |
| 1002 | } |
| 1003 | |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1004 | static u8 rtl8168d_efuse_read(void __iomem *ioaddr, int reg_addr) |
| 1005 | { |
| 1006 | u8 value = 0xff; |
| 1007 | unsigned int i; |
| 1008 | |
| 1009 | RTL_W32(EFUSEAR, (reg_addr & EFUSEAR_REG_MASK) << EFUSEAR_REG_SHIFT); |
| 1010 | |
| 1011 | for (i = 0; i < 300; i++) { |
| 1012 | if (RTL_R32(EFUSEAR) & EFUSEAR_FLAG) { |
| 1013 | value = RTL_R32(EFUSEAR) & EFUSEAR_DATA_MASK; |
| 1014 | break; |
| 1015 | } |
| 1016 | udelay(100); |
| 1017 | } |
| 1018 | |
| 1019 | return value; |
| 1020 | } |
| 1021 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1022 | static void rtl8169_irq_mask_and_ack(void __iomem *ioaddr) |
| 1023 | { |
| 1024 | RTL_W16(IntrMask, 0x0000); |
| 1025 | |
| 1026 | RTL_W16(IntrStatus, 0xffff); |
| 1027 | } |
| 1028 | |
| 1029 | static void rtl8169_asic_down(void __iomem *ioaddr) |
| 1030 | { |
| 1031 | RTL_W8(ChipCmd, 0x00); |
| 1032 | rtl8169_irq_mask_and_ack(ioaddr); |
| 1033 | RTL_R16(CPlusCmd); |
| 1034 | } |
| 1035 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1036 | static unsigned int rtl8169_tbi_reset_pending(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1038 | void __iomem *ioaddr = tp->mmio_addr; |
| 1039 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1040 | return RTL_R32(TBICSR) & TBIReset; |
| 1041 | } |
| 1042 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1043 | static unsigned int rtl8169_xmii_reset_pending(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1044 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1045 | return rtl_readphy(tp, MII_BMCR) & BMCR_RESET; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1046 | } |
| 1047 | |
| 1048 | static unsigned int rtl8169_tbi_link_ok(void __iomem *ioaddr) |
| 1049 | { |
| 1050 | return RTL_R32(TBICSR) & TBILinkOk; |
| 1051 | } |
| 1052 | |
| 1053 | static unsigned int rtl8169_xmii_link_ok(void __iomem *ioaddr) |
| 1054 | { |
| 1055 | return RTL_R8(PHYstatus) & LinkStatus; |
| 1056 | } |
| 1057 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1058 | static void rtl8169_tbi_reset_enable(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1059 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1060 | void __iomem *ioaddr = tp->mmio_addr; |
| 1061 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1062 | RTL_W32(TBICSR, RTL_R32(TBICSR) | TBIReset); |
| 1063 | } |
| 1064 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1065 | static void rtl8169_xmii_reset_enable(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1066 | { |
| 1067 | unsigned int val; |
| 1068 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1069 | val = rtl_readphy(tp, MII_BMCR) | BMCR_RESET; |
| 1070 | rtl_writephy(tp, MII_BMCR, val & 0xffff); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | } |
| 1072 | |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 1073 | static void __rtl8169_check_link_status(struct net_device *dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1074 | struct rtl8169_private *tp, |
| 1075 | void __iomem *ioaddr, bool pm) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1076 | { |
| 1077 | unsigned long flags; |
| 1078 | |
| 1079 | spin_lock_irqsave(&tp->lock, flags); |
| 1080 | if (tp->link_ok(ioaddr)) { |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1081 | /* This is to cancel a scheduled suspend if there's one. */ |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 1082 | if (pm) |
| 1083 | pm_request_resume(&tp->pci_dev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1084 | netif_carrier_on(dev); |
Francois Romieu | 1519e57 | 2011-02-03 12:02:36 +0100 | [diff] [blame] | 1085 | if (net_ratelimit()) |
| 1086 | netif_info(tp, ifup, dev, "link up\n"); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1087 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | netif_carrier_off(dev); |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1089 | netif_info(tp, ifdown, dev, "link down\n"); |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 1090 | if (pm) |
| 1091 | pm_schedule_suspend(&tp->pci_dev->dev, 100); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1092 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1093 | spin_unlock_irqrestore(&tp->lock, flags); |
| 1094 | } |
| 1095 | |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 1096 | static void rtl8169_check_link_status(struct net_device *dev, |
| 1097 | struct rtl8169_private *tp, |
| 1098 | void __iomem *ioaddr) |
| 1099 | { |
| 1100 | __rtl8169_check_link_status(dev, tp, ioaddr, false); |
| 1101 | } |
| 1102 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1103 | #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST) |
| 1104 | |
| 1105 | static u32 __rtl8169_get_wol(struct rtl8169_private *tp) |
| 1106 | { |
| 1107 | void __iomem *ioaddr = tp->mmio_addr; |
| 1108 | u8 options; |
| 1109 | u32 wolopts = 0; |
| 1110 | |
| 1111 | options = RTL_R8(Config1); |
| 1112 | if (!(options & PMEnable)) |
| 1113 | return 0; |
| 1114 | |
| 1115 | options = RTL_R8(Config3); |
| 1116 | if (options & LinkUp) |
| 1117 | wolopts |= WAKE_PHY; |
| 1118 | if (options & MagicPacket) |
| 1119 | wolopts |= WAKE_MAGIC; |
| 1120 | |
| 1121 | options = RTL_R8(Config5); |
| 1122 | if (options & UWF) |
| 1123 | wolopts |= WAKE_UCAST; |
| 1124 | if (options & BWF) |
| 1125 | wolopts |= WAKE_BCAST; |
| 1126 | if (options & MWF) |
| 1127 | wolopts |= WAKE_MCAST; |
| 1128 | |
| 1129 | return wolopts; |
| 1130 | } |
| 1131 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1132 | static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1133 | { |
| 1134 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1135 | |
| 1136 | spin_lock_irq(&tp->lock); |
| 1137 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1138 | wol->supported = WAKE_ANY; |
| 1139 | wol->wolopts = __rtl8169_get_wol(tp); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1140 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1141 | spin_unlock_irq(&tp->lock); |
| 1142 | } |
| 1143 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1144 | static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1145 | { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1146 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 1147 | unsigned int i; |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 1148 | static const struct { |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1149 | u32 opt; |
| 1150 | u16 reg; |
| 1151 | u8 mask; |
| 1152 | } cfg[] = { |
| 1153 | { WAKE_ANY, Config1, PMEnable }, |
| 1154 | { WAKE_PHY, Config3, LinkUp }, |
| 1155 | { WAKE_MAGIC, Config3, MagicPacket }, |
| 1156 | { WAKE_UCAST, Config5, UWF }, |
| 1157 | { WAKE_BCAST, Config5, BWF }, |
| 1158 | { WAKE_MCAST, Config5, MWF }, |
| 1159 | { WAKE_ANY, Config5, LanWake } |
| 1160 | }; |
| 1161 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1162 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 1163 | |
| 1164 | for (i = 0; i < ARRAY_SIZE(cfg); i++) { |
| 1165 | u8 options = RTL_R8(cfg[i].reg) & ~cfg[i].mask; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1166 | if (wolopts & cfg[i].opt) |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1167 | options |= cfg[i].mask; |
| 1168 | RTL_W8(cfg[i].reg, options); |
| 1169 | } |
| 1170 | |
| 1171 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
| 1175 | { |
| 1176 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1177 | |
| 1178 | spin_lock_irq(&tp->lock); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1179 | |
Francois Romieu | f23e7fd | 2007-10-04 22:36:14 +0200 | [diff] [blame] | 1180 | if (wol->wolopts) |
| 1181 | tp->features |= RTL_FEATURE_WOL; |
| 1182 | else |
| 1183 | tp->features &= ~RTL_FEATURE_WOL; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 1184 | __rtl8169_set_wol(tp, wol->wolopts); |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1185 | spin_unlock_irq(&tp->lock); |
| 1186 | |
françois romieu | ea80907 | 2010-11-08 13:23:58 +0000 | [diff] [blame] | 1187 | device_set_wakeup_enable(&tp->pci_dev->dev, wol->wolopts); |
| 1188 | |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1189 | return 0; |
| 1190 | } |
| 1191 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1192 | static void rtl8169_get_drvinfo(struct net_device *dev, |
| 1193 | struct ethtool_drvinfo *info) |
| 1194 | { |
| 1195 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1196 | |
| 1197 | strcpy(info->driver, MODULENAME); |
| 1198 | strcpy(info->version, RTL8169_VERSION); |
| 1199 | strcpy(info->bus_info, pci_name(tp->pci_dev)); |
| 1200 | } |
| 1201 | |
| 1202 | static int rtl8169_get_regs_len(struct net_device *dev) |
| 1203 | { |
| 1204 | return R8169_REGS_SIZE; |
| 1205 | } |
| 1206 | |
| 1207 | static int rtl8169_set_speed_tbi(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1208 | u8 autoneg, u16 speed, u8 duplex, u32 ignored) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | { |
| 1210 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1211 | void __iomem *ioaddr = tp->mmio_addr; |
| 1212 | int ret = 0; |
| 1213 | u32 reg; |
| 1214 | |
| 1215 | reg = RTL_R32(TBICSR); |
| 1216 | if ((autoneg == AUTONEG_DISABLE) && (speed == SPEED_1000) && |
| 1217 | (duplex == DUPLEX_FULL)) { |
| 1218 | RTL_W32(TBICSR, reg & ~(TBINwEnable | TBINwRestart)); |
| 1219 | } else if (autoneg == AUTONEG_ENABLE) |
| 1220 | RTL_W32(TBICSR, reg | TBINwEnable | TBINwRestart); |
| 1221 | else { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1222 | netif_warn(tp, link, dev, |
| 1223 | "incorrect speed setting refused in TBI mode\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1224 | ret = -EOPNOTSUPP; |
| 1225 | } |
| 1226 | |
| 1227 | return ret; |
| 1228 | } |
| 1229 | |
| 1230 | static int rtl8169_set_speed_xmii(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1231 | u8 autoneg, u16 speed, u8 duplex, u32 adv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1232 | { |
| 1233 | struct rtl8169_private *tp = netdev_priv(dev); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1234 | int giga_ctrl, bmcr; |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1235 | int rc = -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | |
Hayes Wang | 716b50a | 2011-02-22 17:26:18 +0800 | [diff] [blame] | 1237 | rtl_writephy(tp, 0x1f, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1238 | |
| 1239 | if (autoneg == AUTONEG_ENABLE) { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1240 | int auto_nego; |
| 1241 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1242 | auto_nego = rtl_readphy(tp, MII_ADVERTISE); |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1243 | auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL | |
| 1244 | ADVERTISE_100HALF | ADVERTISE_100FULL); |
| 1245 | |
| 1246 | if (adv & ADVERTISED_10baseT_Half) |
| 1247 | auto_nego |= ADVERTISE_10HALF; |
| 1248 | if (adv & ADVERTISED_10baseT_Full) |
| 1249 | auto_nego |= ADVERTISE_10FULL; |
| 1250 | if (adv & ADVERTISED_100baseT_Half) |
| 1251 | auto_nego |= ADVERTISE_100HALF; |
| 1252 | if (adv & ADVERTISED_100baseT_Full) |
| 1253 | auto_nego |= ADVERTISE_100FULL; |
| 1254 | |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1255 | auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 1256 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1257 | giga_ctrl = rtl_readphy(tp, MII_CTRL1000); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1258 | giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); |
| 1259 | |
| 1260 | /* The 8100e/8101e/8102e do Fast Ethernet only. */ |
Francois Romieu | 826e6cb | 2011-03-11 20:30:24 +0100 | [diff] [blame^] | 1261 | if (tp->mii.supports_gmii) { |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1262 | if (adv & ADVERTISED_1000baseT_Half) |
| 1263 | giga_ctrl |= ADVERTISE_1000HALF; |
| 1264 | if (adv & ADVERTISED_1000baseT_Full) |
| 1265 | giga_ctrl |= ADVERTISE_1000FULL; |
| 1266 | } else if (adv & (ADVERTISED_1000baseT_Half | |
| 1267 | ADVERTISED_1000baseT_Full)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 1268 | netif_info(tp, link, dev, |
| 1269 | "PHY does not support 1000Mbps\n"); |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1270 | goto out; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 1271 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1273 | bmcr = BMCR_ANENABLE | BMCR_ANRESTART; |
Francois Romieu | 623a159 | 2006-05-14 12:42:14 +0200 | [diff] [blame] | 1274 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1275 | rtl_writephy(tp, MII_ADVERTISE, auto_nego); |
| 1276 | rtl_writephy(tp, MII_CTRL1000, giga_ctrl); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1277 | } else { |
| 1278 | giga_ctrl = 0; |
| 1279 | |
| 1280 | if (speed == SPEED_10) |
| 1281 | bmcr = 0; |
| 1282 | else if (speed == SPEED_100) |
| 1283 | bmcr = BMCR_SPEED100; |
| 1284 | else |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1285 | goto out; |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1286 | |
| 1287 | if (duplex == DUPLEX_FULL) |
| 1288 | bmcr |= BMCR_FULLDPLX; |
Roger So | 2584fbc | 2007-07-31 23:52:42 +0200 | [diff] [blame] | 1289 | } |
| 1290 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | tp->phy_1000_ctrl_reg = giga_ctrl; |
| 1292 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1293 | rtl_writephy(tp, MII_BMCR, bmcr); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1294 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1295 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 1296 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1297 | if ((speed == SPEED_100) && (autoneg != AUTONEG_ENABLE)) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1298 | rtl_writephy(tp, 0x17, 0x2138); |
| 1299 | rtl_writephy(tp, 0x0e, 0x0260); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1300 | } else { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1301 | rtl_writephy(tp, 0x17, 0x2108); |
| 1302 | rtl_writephy(tp, 0x0e, 0x0000); |
françois romieu | 3577aa1 | 2009-05-19 10:46:48 +0000 | [diff] [blame] | 1303 | } |
| 1304 | } |
| 1305 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1306 | rc = 0; |
| 1307 | out: |
| 1308 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | } |
| 1310 | |
| 1311 | static int rtl8169_set_speed(struct net_device *dev, |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1312 | u8 autoneg, u16 speed, u8 duplex, u32 advertising) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1313 | { |
| 1314 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1315 | int ret; |
| 1316 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 1317 | ret = tp->set_speed(dev, autoneg, speed, duplex, advertising); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | |
Francois Romieu | 64e4bfb | 2006-08-17 12:43:06 +0200 | [diff] [blame] | 1319 | if (netif_running(dev) && (tp->phy_1000_ctrl_reg & ADVERTISE_1000FULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | mod_timer(&tp->timer, jiffies + RTL8169_PHY_TIMEOUT); |
| 1321 | |
| 1322 | return ret; |
| 1323 | } |
| 1324 | |
| 1325 | static int rtl8169_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 1326 | { |
| 1327 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1328 | unsigned long flags; |
| 1329 | int ret; |
| 1330 | |
| 1331 | spin_lock_irqsave(&tp->lock, flags); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1332 | ret = rtl8169_set_speed(dev, cmd->autoneg, ethtool_cmd_speed(cmd), |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 1333 | cmd->duplex, cmd->advertising); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1334 | spin_unlock_irqrestore(&tp->lock, flags); |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1335 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | return ret; |
| 1337 | } |
| 1338 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1339 | static u32 rtl8169_fix_features(struct net_device *dev, u32 features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 1341 | if (dev->mtu > TD_MSS_MAX) |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1342 | features &= ~NETIF_F_ALL_TSO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1343 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1344 | return features; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | } |
| 1346 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1347 | static int rtl8169_set_features(struct net_device *dev, u32 features) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1348 | { |
| 1349 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1350 | void __iomem *ioaddr = tp->mmio_addr; |
| 1351 | unsigned long flags; |
| 1352 | |
| 1353 | spin_lock_irqsave(&tp->lock, flags); |
| 1354 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1355 | if (features & NETIF_F_RXCSUM) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | tp->cp_cmd |= RxChkSum; |
| 1357 | else |
| 1358 | tp->cp_cmd &= ~RxChkSum; |
| 1359 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 1360 | if (dev->features & NETIF_F_HW_VLAN_RX) |
| 1361 | tp->cp_cmd |= RxVlan; |
| 1362 | else |
| 1363 | tp->cp_cmd &= ~RxVlan; |
| 1364 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 1366 | RTL_R16(CPlusCmd); |
| 1367 | |
| 1368 | spin_unlock_irqrestore(&tp->lock, flags); |
| 1369 | |
| 1370 | return 0; |
| 1371 | } |
| 1372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | static inline u32 rtl8169_tx_vlan_tag(struct rtl8169_private *tp, |
| 1374 | struct sk_buff *skb) |
| 1375 | { |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 1376 | return (vlan_tx_tag_present(skb)) ? |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | TxVlanTag | swab16(vlan_tx_tag_get(skb)) : 0x00; |
| 1378 | } |
| 1379 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1380 | 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] | 1381 | { |
| 1382 | u32 opts2 = le32_to_cpu(desc->opts2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1383 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 1384 | if (opts2 & RxVlanTag) |
| 1385 | __vlan_hwaccel_put_tag(skb, swab16(opts2 & 0xffff)); |
Eric Dumazet | 2edae08 | 2010-09-06 18:46:39 +0000 | [diff] [blame] | 1386 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | desc->opts2 = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1388 | } |
| 1389 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1390 | 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] | 1391 | { |
| 1392 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1393 | void __iomem *ioaddr = tp->mmio_addr; |
| 1394 | u32 status; |
| 1395 | |
| 1396 | cmd->supported = |
| 1397 | SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE; |
| 1398 | cmd->port = PORT_FIBRE; |
| 1399 | cmd->transceiver = XCVR_INTERNAL; |
| 1400 | |
| 1401 | status = RTL_R32(TBICSR); |
| 1402 | cmd->advertising = (status & TBINwEnable) ? ADVERTISED_Autoneg : 0; |
| 1403 | cmd->autoneg = !!(status & TBINwEnable); |
| 1404 | |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 1405 | ethtool_cmd_speed_set(cmd, SPEED_1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | cmd->duplex = DUPLEX_FULL; /* Always set */ |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1407 | |
| 1408 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1409 | } |
| 1410 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1411 | 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] | 1412 | { |
| 1413 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1414 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1415 | return mii_ethtool_gset(&tp->mii, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1416 | } |
| 1417 | |
| 1418 | static int rtl8169_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
| 1419 | { |
| 1420 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1421 | unsigned long flags; |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1422 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1423 | |
| 1424 | spin_lock_irqsave(&tp->lock, flags); |
| 1425 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1426 | rc = tp->get_settings(dev, cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | |
| 1428 | spin_unlock_irqrestore(&tp->lock, flags); |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 1429 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
| 1433 | void *p) |
| 1434 | { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1435 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1436 | unsigned long flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1438 | if (regs->len > R8169_REGS_SIZE) |
| 1439 | regs->len = R8169_REGS_SIZE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1440 | |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 1441 | spin_lock_irqsave(&tp->lock, flags); |
| 1442 | memcpy_fromio(p, tp->mmio_addr, regs->len); |
| 1443 | spin_unlock_irqrestore(&tp->lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | } |
| 1445 | |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1446 | static u32 rtl8169_get_msglevel(struct net_device *dev) |
| 1447 | { |
| 1448 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1449 | |
| 1450 | return tp->msg_enable; |
| 1451 | } |
| 1452 | |
| 1453 | static void rtl8169_set_msglevel(struct net_device *dev, u32 value) |
| 1454 | { |
| 1455 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1456 | |
| 1457 | tp->msg_enable = value; |
| 1458 | } |
| 1459 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1460 | static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = { |
| 1461 | "tx_packets", |
| 1462 | "rx_packets", |
| 1463 | "tx_errors", |
| 1464 | "rx_errors", |
| 1465 | "rx_missed", |
| 1466 | "align_errors", |
| 1467 | "tx_single_collisions", |
| 1468 | "tx_multi_collisions", |
| 1469 | "unicast", |
| 1470 | "broadcast", |
| 1471 | "multicast", |
| 1472 | "tx_aborted", |
| 1473 | "tx_underrun", |
| 1474 | }; |
| 1475 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1476 | static int rtl8169_get_sset_count(struct net_device *dev, int sset) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1477 | { |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1478 | switch (sset) { |
| 1479 | case ETH_SS_STATS: |
| 1480 | return ARRAY_SIZE(rtl8169_gstrings); |
| 1481 | default: |
| 1482 | return -EOPNOTSUPP; |
| 1483 | } |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1484 | } |
| 1485 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1486 | static void rtl8169_update_counters(struct net_device *dev) |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1487 | { |
| 1488 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1489 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1490 | struct device *d = &tp->pci_dev->dev; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1491 | struct rtl8169_counters *counters; |
| 1492 | dma_addr_t paddr; |
| 1493 | u32 cmd; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1494 | int wait = 1000; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1495 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1496 | /* |
| 1497 | * Some chips are unable to dump tally counters when the receiver |
| 1498 | * is disabled. |
| 1499 | */ |
| 1500 | if ((RTL_R8(ChipCmd) & CmdRxEnb) == 0) |
| 1501 | return; |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1502 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 1503 | counters = dma_alloc_coherent(d, sizeof(*counters), &paddr, GFP_KERNEL); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1504 | if (!counters) |
| 1505 | return; |
| 1506 | |
| 1507 | RTL_W32(CounterAddrHigh, (u64)paddr >> 32); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1508 | cmd = (u64)paddr & DMA_BIT_MASK(32); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1509 | RTL_W32(CounterAddrLow, cmd); |
| 1510 | RTL_W32(CounterAddrLow, cmd | CounterDump); |
| 1511 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1512 | while (wait--) { |
| 1513 | if ((RTL_R32(CounterAddrLow) & CounterDump) == 0) { |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1514 | memcpy(&tp->counters, counters, sizeof(*counters)); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1515 | break; |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1516 | } |
| 1517 | udelay(10); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | RTL_W32(CounterAddrLow, 0); |
| 1521 | RTL_W32(CounterAddrHigh, 0); |
| 1522 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 1523 | dma_free_coherent(d, sizeof(*counters), counters, paddr); |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1524 | } |
| 1525 | |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 1526 | static void rtl8169_get_ethtool_stats(struct net_device *dev, |
| 1527 | struct ethtool_stats *stats, u64 *data) |
| 1528 | { |
| 1529 | struct rtl8169_private *tp = netdev_priv(dev); |
| 1530 | |
| 1531 | ASSERT_RTNL(); |
| 1532 | |
| 1533 | rtl8169_update_counters(dev); |
| 1534 | |
| 1535 | data[0] = le64_to_cpu(tp->counters.tx_packets); |
| 1536 | data[1] = le64_to_cpu(tp->counters.rx_packets); |
| 1537 | data[2] = le64_to_cpu(tp->counters.tx_errors); |
| 1538 | data[3] = le32_to_cpu(tp->counters.rx_errors); |
| 1539 | data[4] = le16_to_cpu(tp->counters.rx_missed); |
| 1540 | data[5] = le16_to_cpu(tp->counters.align_errors); |
| 1541 | data[6] = le32_to_cpu(tp->counters.tx_one_collision); |
| 1542 | data[7] = le32_to_cpu(tp->counters.tx_multi_collision); |
| 1543 | data[8] = le64_to_cpu(tp->counters.rx_unicast); |
| 1544 | data[9] = le64_to_cpu(tp->counters.rx_broadcast); |
| 1545 | data[10] = le32_to_cpu(tp->counters.rx_multicast); |
| 1546 | data[11] = le16_to_cpu(tp->counters.tx_aborted); |
| 1547 | data[12] = le16_to_cpu(tp->counters.tx_underun); |
| 1548 | } |
| 1549 | |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1550 | static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
| 1551 | { |
| 1552 | switch(stringset) { |
| 1553 | case ETH_SS_STATS: |
| 1554 | memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings)); |
| 1555 | break; |
| 1556 | } |
| 1557 | } |
| 1558 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 1559 | static const struct ethtool_ops rtl8169_ethtool_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | .get_drvinfo = rtl8169_get_drvinfo, |
| 1561 | .get_regs_len = rtl8169_get_regs_len, |
| 1562 | .get_link = ethtool_op_get_link, |
| 1563 | .get_settings = rtl8169_get_settings, |
| 1564 | .set_settings = rtl8169_set_settings, |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 1565 | .get_msglevel = rtl8169_get_msglevel, |
| 1566 | .set_msglevel = rtl8169_set_msglevel, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1567 | .get_regs = rtl8169_get_regs, |
Francois Romieu | 61a4dcc | 2006-02-23 00:55:25 +0100 | [diff] [blame] | 1568 | .get_wol = rtl8169_get_wol, |
| 1569 | .set_wol = rtl8169_set_wol, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1570 | .get_strings = rtl8169_get_strings, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 1571 | .get_sset_count = rtl8169_get_sset_count, |
Stephen Hemminger | d4a3a0f | 2005-05-27 21:11:56 +0200 | [diff] [blame] | 1572 | .get_ethtool_stats = rtl8169_get_ethtool_stats, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1573 | }; |
| 1574 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 1575 | static void rtl8169_get_mac_version(struct rtl8169_private *tp, |
| 1576 | void __iomem *ioaddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | { |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 1578 | /* |
| 1579 | * The driver currently handles the 8168Bf and the 8168Be identically |
| 1580 | * but they can be identified more specifically through the test below |
| 1581 | * if needed: |
| 1582 | * |
| 1583 | * (RTL_R32(TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be |
Francois Romieu | 0127215 | 2007-02-20 22:58:51 +0100 | [diff] [blame] | 1584 | * |
| 1585 | * Same thing for the 8101Eb and the 8101Ec: |
| 1586 | * |
| 1587 | * (RTL_R32(TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 1588 | */ |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 1589 | static const struct { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | u32 mask; |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 1591 | u32 val; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1592 | int mac_version; |
| 1593 | } mac_info[] = { |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 1594 | /* 8168E family. */ |
| 1595 | { 0x7cf00000, 0x2c200000, RTL_GIGA_MAC_VER_33 }, |
| 1596 | { 0x7cf00000, 0x2c100000, RTL_GIGA_MAC_VER_32 }, |
| 1597 | { 0x7c800000, 0x2c000000, RTL_GIGA_MAC_VER_33 }, |
| 1598 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 1599 | /* 8168D family. */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1600 | { 0x7cf00000, 0x28300000, RTL_GIGA_MAC_VER_26 }, |
| 1601 | { 0x7cf00000, 0x28100000, RTL_GIGA_MAC_VER_25 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 1602 | { 0x7c800000, 0x28000000, RTL_GIGA_MAC_VER_26 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 1603 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1604 | /* 8168DP family. */ |
| 1605 | { 0x7cf00000, 0x28800000, RTL_GIGA_MAC_VER_27 }, |
| 1606 | { 0x7cf00000, 0x28a00000, RTL_GIGA_MAC_VER_28 }, |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 1607 | { 0x7cf00000, 0x28b00000, RTL_GIGA_MAC_VER_31 }, |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 1608 | |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 1609 | /* 8168C family. */ |
Francois Romieu | 17c9929 | 2010-07-11 17:10:09 -0700 | [diff] [blame] | 1610 | { 0x7cf00000, 0x3cb00000, RTL_GIGA_MAC_VER_24 }, |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 1611 | { 0x7cf00000, 0x3c900000, RTL_GIGA_MAC_VER_23 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 1612 | { 0x7cf00000, 0x3c800000, RTL_GIGA_MAC_VER_18 }, |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 1613 | { 0x7c800000, 0x3c800000, RTL_GIGA_MAC_VER_24 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 1614 | { 0x7cf00000, 0x3c000000, RTL_GIGA_MAC_VER_19 }, |
| 1615 | { 0x7cf00000, 0x3c200000, RTL_GIGA_MAC_VER_20 }, |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 1616 | { 0x7cf00000, 0x3c300000, RTL_GIGA_MAC_VER_21 }, |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 1617 | { 0x7cf00000, 0x3c400000, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | ef808d5 | 2008-06-29 13:10:54 +0200 | [diff] [blame] | 1618 | { 0x7c800000, 0x3c000000, RTL_GIGA_MAC_VER_22 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 1619 | |
| 1620 | /* 8168B family. */ |
| 1621 | { 0x7cf00000, 0x38000000, RTL_GIGA_MAC_VER_12 }, |
| 1622 | { 0x7cf00000, 0x38500000, RTL_GIGA_MAC_VER_17 }, |
| 1623 | { 0x7c800000, 0x38000000, RTL_GIGA_MAC_VER_17 }, |
| 1624 | { 0x7c800000, 0x30000000, RTL_GIGA_MAC_VER_11 }, |
| 1625 | |
| 1626 | /* 8101 family. */ |
hayeswang | 36a0e6c | 2011-03-21 01:50:30 +0000 | [diff] [blame] | 1627 | { 0x7cf00000, 0x40b00000, RTL_GIGA_MAC_VER_30 }, |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 1628 | { 0x7cf00000, 0x40a00000, RTL_GIGA_MAC_VER_30 }, |
| 1629 | { 0x7cf00000, 0x40900000, RTL_GIGA_MAC_VER_29 }, |
| 1630 | { 0x7c800000, 0x40800000, RTL_GIGA_MAC_VER_30 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 1631 | { 0x7cf00000, 0x34a00000, RTL_GIGA_MAC_VER_09 }, |
| 1632 | { 0x7cf00000, 0x24a00000, RTL_GIGA_MAC_VER_09 }, |
| 1633 | { 0x7cf00000, 0x34900000, RTL_GIGA_MAC_VER_08 }, |
| 1634 | { 0x7cf00000, 0x24900000, RTL_GIGA_MAC_VER_08 }, |
| 1635 | { 0x7cf00000, 0x34800000, RTL_GIGA_MAC_VER_07 }, |
| 1636 | { 0x7cf00000, 0x24800000, RTL_GIGA_MAC_VER_07 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 1637 | { 0x7cf00000, 0x34000000, RTL_GIGA_MAC_VER_13 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 1638 | { 0x7cf00000, 0x34300000, RTL_GIGA_MAC_VER_10 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 1639 | { 0x7cf00000, 0x34200000, RTL_GIGA_MAC_VER_16 }, |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 1640 | { 0x7c800000, 0x34800000, RTL_GIGA_MAC_VER_09 }, |
| 1641 | { 0x7c800000, 0x24800000, RTL_GIGA_MAC_VER_09 }, |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 1642 | { 0x7c800000, 0x34000000, RTL_GIGA_MAC_VER_16 }, |
| 1643 | /* FIXME: where did these entries come from ? -- FR */ |
| 1644 | { 0xfc800000, 0x38800000, RTL_GIGA_MAC_VER_15 }, |
| 1645 | { 0xfc800000, 0x30800000, RTL_GIGA_MAC_VER_14 }, |
| 1646 | |
| 1647 | /* 8110 family. */ |
| 1648 | { 0xfc800000, 0x98000000, RTL_GIGA_MAC_VER_06 }, |
| 1649 | { 0xfc800000, 0x18000000, RTL_GIGA_MAC_VER_05 }, |
| 1650 | { 0xfc800000, 0x10000000, RTL_GIGA_MAC_VER_04 }, |
| 1651 | { 0xfc800000, 0x04000000, RTL_GIGA_MAC_VER_03 }, |
| 1652 | { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 }, |
| 1653 | { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 }, |
| 1654 | |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 1655 | /* Catch-all */ |
| 1656 | { 0x00000000, 0x00000000, RTL_GIGA_MAC_NONE } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1657 | }, *p = mac_info; |
| 1658 | u32 reg; |
| 1659 | |
Francois Romieu | e3cf0cc | 2007-08-17 14:55:46 +0200 | [diff] [blame] | 1660 | reg = RTL_R32(TxConfig); |
| 1661 | while ((reg & p->mask) != p->val) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | p++; |
| 1663 | tp->mac_version = p->mac_version; |
| 1664 | } |
| 1665 | |
| 1666 | static void rtl8169_print_mac_version(struct rtl8169_private *tp) |
| 1667 | { |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 1668 | dprintk("mac_version = 0x%02x\n", tp->mac_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1669 | } |
| 1670 | |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 1671 | struct phy_reg { |
| 1672 | u16 reg; |
| 1673 | u16 val; |
| 1674 | }; |
| 1675 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1676 | static void rtl_writephy_batch(struct rtl8169_private *tp, |
| 1677 | const struct phy_reg *regs, int len) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 1678 | { |
| 1679 | while (len-- > 0) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1680 | rtl_writephy(tp, regs->reg, regs->val); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 1681 | regs++; |
| 1682 | } |
| 1683 | } |
| 1684 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 1685 | #define PHY_READ 0x00000000 |
| 1686 | #define PHY_DATA_OR 0x10000000 |
| 1687 | #define PHY_DATA_AND 0x20000000 |
| 1688 | #define PHY_BJMPN 0x30000000 |
| 1689 | #define PHY_READ_EFUSE 0x40000000 |
| 1690 | #define PHY_READ_MAC_BYTE 0x50000000 |
| 1691 | #define PHY_WRITE_MAC_BYTE 0x60000000 |
| 1692 | #define PHY_CLEAR_READCOUNT 0x70000000 |
| 1693 | #define PHY_WRITE 0x80000000 |
| 1694 | #define PHY_READCOUNT_EQ_SKIP 0x90000000 |
| 1695 | #define PHY_COMP_EQ_SKIPN 0xa0000000 |
| 1696 | #define PHY_COMP_NEQ_SKIPN 0xb0000000 |
| 1697 | #define PHY_WRITE_PREVIOUS 0xc0000000 |
| 1698 | #define PHY_SKIPN 0xd0000000 |
| 1699 | #define PHY_DELAY_MS 0xe0000000 |
| 1700 | #define PHY_WRITE_ERI_WORD 0xf0000000 |
| 1701 | |
| 1702 | static void |
| 1703 | rtl_phy_write_fw(struct rtl8169_private *tp, const struct firmware *fw) |
| 1704 | { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 1705 | __le32 *phytable = (__le32 *)fw->data; |
| 1706 | struct net_device *dev = tp->dev; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 1707 | size_t index, fw_size = fw->size / sizeof(*phytable); |
| 1708 | u32 predata, count; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 1709 | |
| 1710 | if (fw->size % sizeof(*phytable)) { |
| 1711 | netif_err(tp, probe, dev, "odd sized firmware %zd\n", fw->size); |
| 1712 | return; |
| 1713 | } |
| 1714 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 1715 | for (index = 0; index < fw_size; index++) { |
| 1716 | u32 action = le32_to_cpu(phytable[index]); |
| 1717 | u32 regno = (action & 0x0fff0000) >> 16; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 1718 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 1719 | switch(action & 0xf0000000) { |
| 1720 | case PHY_READ: |
| 1721 | case PHY_DATA_OR: |
| 1722 | case PHY_DATA_AND: |
| 1723 | case PHY_READ_EFUSE: |
| 1724 | case PHY_CLEAR_READCOUNT: |
| 1725 | case PHY_WRITE: |
| 1726 | case PHY_WRITE_PREVIOUS: |
| 1727 | case PHY_DELAY_MS: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 1728 | break; |
| 1729 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 1730 | case PHY_BJMPN: |
| 1731 | if (regno > index) { |
| 1732 | netif_err(tp, probe, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1733 | "Out of range of firmware\n"); |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 1734 | return; |
| 1735 | } |
| 1736 | break; |
| 1737 | case PHY_READCOUNT_EQ_SKIP: |
| 1738 | if (index + 2 >= fw_size) { |
| 1739 | netif_err(tp, probe, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1740 | "Out of range of firmware\n"); |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 1741 | return; |
| 1742 | } |
| 1743 | break; |
| 1744 | case PHY_COMP_EQ_SKIPN: |
| 1745 | case PHY_COMP_NEQ_SKIPN: |
| 1746 | case PHY_SKIPN: |
| 1747 | if (index + 1 + regno >= fw_size) { |
| 1748 | netif_err(tp, probe, tp->dev, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1749 | "Out of range of firmware\n"); |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 1750 | return; |
| 1751 | } |
| 1752 | break; |
| 1753 | |
| 1754 | case PHY_READ_MAC_BYTE: |
| 1755 | case PHY_WRITE_MAC_BYTE: |
| 1756 | case PHY_WRITE_ERI_WORD: |
| 1757 | default: |
| 1758 | netif_err(tp, probe, tp->dev, |
| 1759 | "Invalid action 0x%08x\n", action); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 1760 | return; |
| 1761 | } |
| 1762 | } |
| 1763 | |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 1764 | predata = 0; |
| 1765 | count = 0; |
| 1766 | |
| 1767 | for (index = 0; index < fw_size; ) { |
| 1768 | u32 action = le32_to_cpu(phytable[index]); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 1769 | u32 data = action & 0x0000ffff; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 1770 | u32 regno = (action & 0x0fff0000) >> 16; |
| 1771 | |
| 1772 | if (!action) |
| 1773 | break; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 1774 | |
| 1775 | switch(action & 0xf0000000) { |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 1776 | case PHY_READ: |
| 1777 | predata = rtl_readphy(tp, regno); |
| 1778 | count++; |
| 1779 | index++; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 1780 | break; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 1781 | case PHY_DATA_OR: |
| 1782 | predata |= data; |
| 1783 | index++; |
| 1784 | break; |
| 1785 | case PHY_DATA_AND: |
| 1786 | predata &= data; |
| 1787 | index++; |
| 1788 | break; |
| 1789 | case PHY_BJMPN: |
| 1790 | index -= regno; |
| 1791 | break; |
| 1792 | case PHY_READ_EFUSE: |
| 1793 | predata = rtl8168d_efuse_read(tp->mmio_addr, regno); |
| 1794 | index++; |
| 1795 | break; |
| 1796 | case PHY_CLEAR_READCOUNT: |
| 1797 | count = 0; |
| 1798 | index++; |
| 1799 | break; |
| 1800 | case PHY_WRITE: |
| 1801 | rtl_writephy(tp, regno, data); |
| 1802 | index++; |
| 1803 | break; |
| 1804 | case PHY_READCOUNT_EQ_SKIP: |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 1805 | index += (count == data) ? 2 : 1; |
hayeswang | 42b82dc | 2011-01-10 02:07:25 +0000 | [diff] [blame] | 1806 | break; |
| 1807 | case PHY_COMP_EQ_SKIPN: |
| 1808 | if (predata == data) |
| 1809 | index += regno; |
| 1810 | index++; |
| 1811 | break; |
| 1812 | case PHY_COMP_NEQ_SKIPN: |
| 1813 | if (predata != data) |
| 1814 | index += regno; |
| 1815 | index++; |
| 1816 | break; |
| 1817 | case PHY_WRITE_PREVIOUS: |
| 1818 | rtl_writephy(tp, regno, predata); |
| 1819 | index++; |
| 1820 | break; |
| 1821 | case PHY_SKIPN: |
| 1822 | index += regno + 1; |
| 1823 | break; |
| 1824 | case PHY_DELAY_MS: |
| 1825 | mdelay(data); |
| 1826 | index++; |
| 1827 | break; |
| 1828 | |
| 1829 | case PHY_READ_MAC_BYTE: |
| 1830 | case PHY_WRITE_MAC_BYTE: |
| 1831 | case PHY_WRITE_ERI_WORD: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 1832 | default: |
| 1833 | BUG(); |
| 1834 | } |
| 1835 | } |
| 1836 | } |
| 1837 | |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 1838 | static void rtl_release_firmware(struct rtl8169_private *tp) |
| 1839 | { |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 1840 | if (!IS_ERR_OR_NULL(tp->fw)) |
| 1841 | release_firmware(tp->fw); |
| 1842 | tp->fw = RTL_FIRMWARE_UNKNOWN; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 1843 | } |
| 1844 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 1845 | static void rtl_apply_firmware(struct rtl8169_private *tp) |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 1846 | { |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 1847 | const struct firmware *fw = tp->fw; |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 1848 | |
| 1849 | /* TODO: release firmware once rtl_phy_write_fw signals failures. */ |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 1850 | if (!IS_ERR_OR_NULL(fw)) |
| 1851 | rtl_phy_write_fw(tp, fw); |
| 1852 | } |
| 1853 | |
| 1854 | static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val) |
| 1855 | { |
| 1856 | if (rtl_readphy(tp, reg) != val) |
| 1857 | netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n"); |
| 1858 | else |
| 1859 | rtl_apply_firmware(tp); |
françois romieu | f1e02ed | 2011-01-13 13:07:53 +0000 | [diff] [blame] | 1860 | } |
| 1861 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1862 | static void rtl8169s_hw_phy_config(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 1864 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 1865 | { 0x1f, 0x0001 }, |
| 1866 | { 0x06, 0x006e }, |
| 1867 | { 0x08, 0x0708 }, |
| 1868 | { 0x15, 0x4000 }, |
| 1869 | { 0x18, 0x65c7 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1870 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 1871 | { 0x1f, 0x0001 }, |
| 1872 | { 0x03, 0x00a1 }, |
| 1873 | { 0x02, 0x0008 }, |
| 1874 | { 0x01, 0x0120 }, |
| 1875 | { 0x00, 0x1000 }, |
| 1876 | { 0x04, 0x0800 }, |
| 1877 | { 0x04, 0x0000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1878 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 1879 | { 0x03, 0xff41 }, |
| 1880 | { 0x02, 0xdf60 }, |
| 1881 | { 0x01, 0x0140 }, |
| 1882 | { 0x00, 0x0077 }, |
| 1883 | { 0x04, 0x7800 }, |
| 1884 | { 0x04, 0x7000 }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | |
françois romieu | 0b9b571 | 2009-08-10 19:44:56 +0000 | [diff] [blame] | 1886 | { 0x03, 0x802f }, |
| 1887 | { 0x02, 0x4f02 }, |
| 1888 | { 0x01, 0x0409 }, |
| 1889 | { 0x00, 0xf0f9 }, |
| 1890 | { 0x04, 0x9800 }, |
| 1891 | { 0x04, 0x9000 }, |
| 1892 | |
| 1893 | { 0x03, 0xdf01 }, |
| 1894 | { 0x02, 0xdf20 }, |
| 1895 | { 0x01, 0xff95 }, |
| 1896 | { 0x00, 0xba00 }, |
| 1897 | { 0x04, 0xa800 }, |
| 1898 | { 0x04, 0xa000 }, |
| 1899 | |
| 1900 | { 0x03, 0xff41 }, |
| 1901 | { 0x02, 0xdf20 }, |
| 1902 | { 0x01, 0x0140 }, |
| 1903 | { 0x00, 0x00bb }, |
| 1904 | { 0x04, 0xb800 }, |
| 1905 | { 0x04, 0xb000 }, |
| 1906 | |
| 1907 | { 0x03, 0xdf41 }, |
| 1908 | { 0x02, 0xdc60 }, |
| 1909 | { 0x01, 0x6340 }, |
| 1910 | { 0x00, 0x007d }, |
| 1911 | { 0x04, 0xd800 }, |
| 1912 | { 0x04, 0xd000 }, |
| 1913 | |
| 1914 | { 0x03, 0xdf01 }, |
| 1915 | { 0x02, 0xdf20 }, |
| 1916 | { 0x01, 0x100a }, |
| 1917 | { 0x00, 0xa0ff }, |
| 1918 | { 0x04, 0xf800 }, |
| 1919 | { 0x04, 0xf000 }, |
| 1920 | |
| 1921 | { 0x1f, 0x0000 }, |
| 1922 | { 0x0b, 0x0000 }, |
| 1923 | { 0x00, 0x9200 } |
| 1924 | }; |
| 1925 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1926 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1927 | } |
| 1928 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1929 | static void rtl8169sb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 1930 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 1931 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a441d7b | 2007-08-17 18:26:35 +0200 | [diff] [blame] | 1932 | { 0x1f, 0x0002 }, |
| 1933 | { 0x01, 0x90d0 }, |
| 1934 | { 0x1f, 0x0000 } |
| 1935 | }; |
| 1936 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1937 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 1938 | } |
| 1939 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1940 | static void rtl8169scd_hw_phy_config_quirk(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 1941 | { |
| 1942 | struct pci_dev *pdev = tp->pci_dev; |
| 1943 | u16 vendor_id, device_id; |
| 1944 | |
| 1945 | pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &vendor_id); |
| 1946 | pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &device_id); |
| 1947 | |
| 1948 | if ((vendor_id != PCI_VENDOR_ID_GIGABYTE) || (device_id != 0xe000)) |
| 1949 | return; |
| 1950 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1951 | rtl_writephy(tp, 0x1f, 0x0001); |
| 1952 | rtl_writephy(tp, 0x10, 0xf01b); |
| 1953 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 1954 | } |
| 1955 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1956 | static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 1957 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 1958 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 1959 | { 0x1f, 0x0001 }, |
| 1960 | { 0x04, 0x0000 }, |
| 1961 | { 0x03, 0x00a1 }, |
| 1962 | { 0x02, 0x0008 }, |
| 1963 | { 0x01, 0x0120 }, |
| 1964 | { 0x00, 0x1000 }, |
| 1965 | { 0x04, 0x0800 }, |
| 1966 | { 0x04, 0x9000 }, |
| 1967 | { 0x03, 0x802f }, |
| 1968 | { 0x02, 0x4f02 }, |
| 1969 | { 0x01, 0x0409 }, |
| 1970 | { 0x00, 0xf099 }, |
| 1971 | { 0x04, 0x9800 }, |
| 1972 | { 0x04, 0xa000 }, |
| 1973 | { 0x03, 0xdf01 }, |
| 1974 | { 0x02, 0xdf20 }, |
| 1975 | { 0x01, 0xff95 }, |
| 1976 | { 0x00, 0xba00 }, |
| 1977 | { 0x04, 0xa800 }, |
| 1978 | { 0x04, 0xf000 }, |
| 1979 | { 0x03, 0xdf01 }, |
| 1980 | { 0x02, 0xdf20 }, |
| 1981 | { 0x01, 0x101a }, |
| 1982 | { 0x00, 0xa0ff }, |
| 1983 | { 0x04, 0xf800 }, |
| 1984 | { 0x04, 0x0000 }, |
| 1985 | { 0x1f, 0x0000 }, |
| 1986 | |
| 1987 | { 0x1f, 0x0001 }, |
| 1988 | { 0x10, 0xf41b }, |
| 1989 | { 0x14, 0xfb54 }, |
| 1990 | { 0x18, 0xf5c7 }, |
| 1991 | { 0x1f, 0x0000 }, |
| 1992 | |
| 1993 | { 0x1f, 0x0001 }, |
| 1994 | { 0x17, 0x0cc0 }, |
| 1995 | { 0x1f, 0x0000 } |
| 1996 | }; |
| 1997 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 1998 | 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] | 1999 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2000 | rtl8169scd_hw_phy_config_quirk(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2001 | } |
| 2002 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2003 | static void rtl8169sce_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2004 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2005 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2006 | { 0x1f, 0x0001 }, |
| 2007 | { 0x04, 0x0000 }, |
| 2008 | { 0x03, 0x00a1 }, |
| 2009 | { 0x02, 0x0008 }, |
| 2010 | { 0x01, 0x0120 }, |
| 2011 | { 0x00, 0x1000 }, |
| 2012 | { 0x04, 0x0800 }, |
| 2013 | { 0x04, 0x9000 }, |
| 2014 | { 0x03, 0x802f }, |
| 2015 | { 0x02, 0x4f02 }, |
| 2016 | { 0x01, 0x0409 }, |
| 2017 | { 0x00, 0xf099 }, |
| 2018 | { 0x04, 0x9800 }, |
| 2019 | { 0x04, 0xa000 }, |
| 2020 | { 0x03, 0xdf01 }, |
| 2021 | { 0x02, 0xdf20 }, |
| 2022 | { 0x01, 0xff95 }, |
| 2023 | { 0x00, 0xba00 }, |
| 2024 | { 0x04, 0xa800 }, |
| 2025 | { 0x04, 0xf000 }, |
| 2026 | { 0x03, 0xdf01 }, |
| 2027 | { 0x02, 0xdf20 }, |
| 2028 | { 0x01, 0x101a }, |
| 2029 | { 0x00, 0xa0ff }, |
| 2030 | { 0x04, 0xf800 }, |
| 2031 | { 0x04, 0x0000 }, |
| 2032 | { 0x1f, 0x0000 }, |
| 2033 | |
| 2034 | { 0x1f, 0x0001 }, |
| 2035 | { 0x0b, 0x8480 }, |
| 2036 | { 0x1f, 0x0000 }, |
| 2037 | |
| 2038 | { 0x1f, 0x0001 }, |
| 2039 | { 0x18, 0x67c7 }, |
| 2040 | { 0x04, 0x2000 }, |
| 2041 | { 0x03, 0x002f }, |
| 2042 | { 0x02, 0x4360 }, |
| 2043 | { 0x01, 0x0109 }, |
| 2044 | { 0x00, 0x3022 }, |
| 2045 | { 0x04, 0x2800 }, |
| 2046 | { 0x1f, 0x0000 }, |
| 2047 | |
| 2048 | { 0x1f, 0x0001 }, |
| 2049 | { 0x17, 0x0cc0 }, |
| 2050 | { 0x1f, 0x0000 } |
| 2051 | }; |
| 2052 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2053 | 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] | 2054 | } |
| 2055 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2056 | static void rtl8168bb_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2057 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2058 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2059 | { 0x10, 0xf41b }, |
| 2060 | { 0x1f, 0x0000 } |
| 2061 | }; |
| 2062 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2063 | rtl_writephy(tp, 0x1f, 0x0001); |
| 2064 | rtl_patchphy(tp, 0x16, 1 << 0); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2065 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2066 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2067 | } |
| 2068 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2069 | static void rtl8168bef_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2070 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2071 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2072 | { 0x1f, 0x0001 }, |
| 2073 | { 0x10, 0xf41b }, |
| 2074 | { 0x1f, 0x0000 } |
| 2075 | }; |
| 2076 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2077 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2078 | } |
| 2079 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2080 | static void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2081 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2082 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2083 | { 0x1f, 0x0000 }, |
| 2084 | { 0x1d, 0x0f00 }, |
| 2085 | { 0x1f, 0x0002 }, |
| 2086 | { 0x0c, 0x1ec8 }, |
| 2087 | { 0x1f, 0x0000 } |
| 2088 | }; |
| 2089 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2090 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2091 | } |
| 2092 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2093 | static void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2094 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2095 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2096 | { 0x1f, 0x0001 }, |
| 2097 | { 0x1d, 0x3d98 }, |
| 2098 | { 0x1f, 0x0000 } |
| 2099 | }; |
| 2100 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2101 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2102 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2103 | rtl_patchphy(tp, 0x0d, 1 << 5); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2104 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2105 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2106 | } |
| 2107 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2108 | static void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2109 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2110 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | a3f8067 | 2007-10-18 14:35:11 +0200 | [diff] [blame] | 2111 | { 0x1f, 0x0001 }, |
| 2112 | { 0x12, 0x2300 }, |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2113 | { 0x1f, 0x0002 }, |
| 2114 | { 0x00, 0x88d4 }, |
| 2115 | { 0x01, 0x82b1 }, |
| 2116 | { 0x03, 0x7002 }, |
| 2117 | { 0x08, 0x9e30 }, |
| 2118 | { 0x09, 0x01f0 }, |
| 2119 | { 0x0a, 0x5500 }, |
| 2120 | { 0x0c, 0x00c8 }, |
| 2121 | { 0x1f, 0x0003 }, |
| 2122 | { 0x12, 0xc096 }, |
| 2123 | { 0x16, 0x000a }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2124 | { 0x1f, 0x0000 }, |
| 2125 | { 0x1f, 0x0000 }, |
| 2126 | { 0x09, 0x2000 }, |
| 2127 | { 0x09, 0x0000 } |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2128 | }; |
| 2129 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2130 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2131 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2132 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2133 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2134 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2135 | } |
| 2136 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2137 | static void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2138 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2139 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2140 | { 0x1f, 0x0001 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2141 | { 0x12, 0x2300 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2142 | { 0x03, 0x802f }, |
| 2143 | { 0x02, 0x4f02 }, |
| 2144 | { 0x01, 0x0409 }, |
| 2145 | { 0x00, 0xf099 }, |
| 2146 | { 0x04, 0x9800 }, |
| 2147 | { 0x04, 0x9000 }, |
| 2148 | { 0x1d, 0x3d98 }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2149 | { 0x1f, 0x0002 }, |
| 2150 | { 0x0c, 0x7eb8 }, |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2151 | { 0x06, 0x0761 }, |
| 2152 | { 0x1f, 0x0003 }, |
| 2153 | { 0x16, 0x0f0a }, |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2154 | { 0x1f, 0x0000 } |
| 2155 | }; |
| 2156 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2157 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | f50d427 | 2008-05-30 16:07:07 +0200 | [diff] [blame] | 2158 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2159 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 2160 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2161 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2162 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2163 | } |
| 2164 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2165 | static void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2166 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2167 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2168 | { 0x1f, 0x0001 }, |
| 2169 | { 0x12, 0x2300 }, |
| 2170 | { 0x1d, 0x3d98 }, |
| 2171 | { 0x1f, 0x0002 }, |
| 2172 | { 0x0c, 0x7eb8 }, |
| 2173 | { 0x06, 0x5461 }, |
| 2174 | { 0x1f, 0x0003 }, |
| 2175 | { 0x16, 0x0f0a }, |
| 2176 | { 0x1f, 0x0000 } |
| 2177 | }; |
| 2178 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2179 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2180 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2181 | rtl_patchphy(tp, 0x16, 1 << 0); |
| 2182 | rtl_patchphy(tp, 0x14, 1 << 5); |
| 2183 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2184 | rtl_writephy(tp, 0x1f, 0x0000); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2185 | } |
| 2186 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2187 | static void rtl8168c_4_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2188 | { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2189 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2190 | } |
| 2191 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2192 | static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2193 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2194 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2195 | /* Channel Estimation */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2196 | { 0x1f, 0x0001 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2197 | { 0x06, 0x4064 }, |
| 2198 | { 0x07, 0x2863 }, |
| 2199 | { 0x08, 0x059c }, |
| 2200 | { 0x09, 0x26b4 }, |
| 2201 | { 0x0a, 0x6a19 }, |
| 2202 | { 0x0b, 0xdcc8 }, |
| 2203 | { 0x10, 0xf06d }, |
| 2204 | { 0x14, 0x7f68 }, |
| 2205 | { 0x18, 0x7fd9 }, |
| 2206 | { 0x1c, 0xf0ff }, |
| 2207 | { 0x1d, 0x3d9c }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2208 | { 0x1f, 0x0003 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2209 | { 0x12, 0xf49f }, |
| 2210 | { 0x13, 0x070b }, |
| 2211 | { 0x1a, 0x05ad }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2212 | { 0x14, 0x94c0 }, |
| 2213 | |
| 2214 | /* |
| 2215 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2216 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2217 | */ |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2218 | { 0x1f, 0x0002 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2219 | { 0x06, 0x5561 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2220 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2221 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2222 | { 0x06, 0x5561 }, |
| 2223 | |
| 2224 | /* |
| 2225 | * Can not link to 1Gbps with bad cable |
| 2226 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 2227 | */ |
| 2228 | { 0x1f, 0x0001 }, |
| 2229 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2230 | |
| 2231 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2232 | { 0x0d, 0xf880 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2233 | }; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2234 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2235 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2236 | 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] | 2237 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2238 | /* |
| 2239 | * Rx Error Issue |
| 2240 | * Fine Tune Switching regulator parameter |
| 2241 | */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2242 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2243 | rtl_w1w0_phy(tp, 0x0b, 0x0010, 0x00ef); |
| 2244 | rtl_w1w0_phy(tp, 0x0c, 0xa200, 0x5d00); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2245 | |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2246 | if (rtl8168d_efuse_read(ioaddr, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2247 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2248 | { 0x1f, 0x0002 }, |
| 2249 | { 0x05, 0x669a }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2250 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2251 | { 0x05, 0x8330 }, |
| 2252 | { 0x06, 0x669a }, |
| 2253 | { 0x1f, 0x0002 } |
| 2254 | }; |
| 2255 | int val; |
| 2256 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2257 | 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] | 2258 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2259 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2260 | |
| 2261 | if ((val & 0x00ff) != 0x006c) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2262 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2263 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 2264 | 0x0069, 0x006a, 0x006b, 0x006c |
| 2265 | }; |
| 2266 | int i; |
| 2267 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2268 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2269 | |
| 2270 | val &= 0xff00; |
| 2271 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2272 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2273 | } |
| 2274 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2275 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2276 | { 0x1f, 0x0002 }, |
| 2277 | { 0x05, 0x6662 }, |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2278 | { 0x1f, 0x0005 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2279 | { 0x05, 0x8330 }, |
| 2280 | { 0x06, 0x6662 } |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2281 | }; |
| 2282 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2283 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2284 | } |
| 2285 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2286 | /* RSET couple improve */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2287 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2288 | rtl_patchphy(tp, 0x0d, 0x0300); |
| 2289 | rtl_patchphy(tp, 0x0f, 0x0010); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2290 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2291 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2292 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2293 | rtl_w1w0_phy(tp, 0x02, 0x0100, 0x0600); |
| 2294 | rtl_w1w0_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2295 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2296 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2297 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2298 | |
| 2299 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2300 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2301 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2302 | } |
| 2303 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2304 | static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2305 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2306 | static const struct phy_reg phy_reg_init_0[] = { |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2307 | /* Channel Estimation */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2308 | { 0x1f, 0x0001 }, |
| 2309 | { 0x06, 0x4064 }, |
| 2310 | { 0x07, 0x2863 }, |
| 2311 | { 0x08, 0x059c }, |
| 2312 | { 0x09, 0x26b4 }, |
| 2313 | { 0x0a, 0x6a19 }, |
| 2314 | { 0x0b, 0xdcc8 }, |
| 2315 | { 0x10, 0xf06d }, |
| 2316 | { 0x14, 0x7f68 }, |
| 2317 | { 0x18, 0x7fd9 }, |
| 2318 | { 0x1c, 0xf0ff }, |
| 2319 | { 0x1d, 0x3d9c }, |
| 2320 | { 0x1f, 0x0003 }, |
| 2321 | { 0x12, 0xf49f }, |
| 2322 | { 0x13, 0x070b }, |
| 2323 | { 0x1a, 0x05ad }, |
| 2324 | { 0x14, 0x94c0 }, |
| 2325 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2326 | /* |
| 2327 | * Tx Error Issue |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2328 | * Enhance line driver power |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2329 | */ |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2330 | { 0x1f, 0x0002 }, |
| 2331 | { 0x06, 0x5561 }, |
| 2332 | { 0x1f, 0x0005 }, |
| 2333 | { 0x05, 0x8332 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2334 | { 0x06, 0x5561 }, |
| 2335 | |
| 2336 | /* |
| 2337 | * Can not link to 1Gbps with bad cable |
| 2338 | * Decrease SNR threshold form 21.07dB to 19.04dB |
| 2339 | */ |
| 2340 | { 0x1f, 0x0001 }, |
| 2341 | { 0x17, 0x0cc0 }, |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2342 | |
| 2343 | { 0x1f, 0x0000 }, |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2344 | { 0x0d, 0xf880 } |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2345 | }; |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2346 | void __iomem *ioaddr = tp->mmio_addr; |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2347 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2348 | 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] | 2349 | |
| 2350 | if (rtl8168d_efuse_read(ioaddr, 0x01) == 0xb1) { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2351 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2352 | { 0x1f, 0x0002 }, |
| 2353 | { 0x05, 0x669a }, |
| 2354 | { 0x1f, 0x0005 }, |
| 2355 | { 0x05, 0x8330 }, |
| 2356 | { 0x06, 0x669a }, |
| 2357 | |
| 2358 | { 0x1f, 0x0002 } |
| 2359 | }; |
| 2360 | int val; |
| 2361 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2362 | 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] | 2363 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2364 | val = rtl_readphy(tp, 0x0d); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2365 | if ((val & 0x00ff) != 0x006c) { |
Joe Perches | b6bc765 | 2010-12-21 02:16:08 -0800 | [diff] [blame] | 2366 | static const u32 set[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2367 | 0x0065, 0x0066, 0x0067, 0x0068, |
| 2368 | 0x0069, 0x006a, 0x006b, 0x006c |
| 2369 | }; |
| 2370 | int i; |
| 2371 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2372 | rtl_writephy(tp, 0x1f, 0x0002); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2373 | |
| 2374 | val &= 0xff00; |
| 2375 | for (i = 0; i < ARRAY_SIZE(set); i++) |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2376 | rtl_writephy(tp, 0x0d, val | set[i]); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2377 | } |
| 2378 | } else { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2379 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2380 | { 0x1f, 0x0002 }, |
| 2381 | { 0x05, 0x2642 }, |
| 2382 | { 0x1f, 0x0005 }, |
| 2383 | { 0x05, 0x8330 }, |
| 2384 | { 0x06, 0x2642 } |
| 2385 | }; |
| 2386 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2387 | 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] | 2388 | } |
| 2389 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2390 | /* Fine tune PLL performance */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2391 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2392 | rtl_w1w0_phy(tp, 0x02, 0x0100, 0x0600); |
| 2393 | rtl_w1w0_phy(tp, 0x03, 0x0000, 0xe000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2394 | |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2395 | /* Switching regulator Slew rate */ |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2396 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2397 | rtl_patchphy(tp, 0x0f, 0x0017); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2398 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2399 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2400 | rtl_writephy(tp, 0x05, 0x001b); |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2401 | |
| 2402 | rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300); |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2403 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2404 | rtl_writephy(tp, 0x1f, 0x0000); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2405 | } |
| 2406 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2407 | static void rtl8168d_3_hw_phy_config(struct rtl8169_private *tp) |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2408 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2409 | static const struct phy_reg phy_reg_init[] = { |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2410 | { 0x1f, 0x0002 }, |
| 2411 | { 0x10, 0x0008 }, |
| 2412 | { 0x0d, 0x006c }, |
| 2413 | |
| 2414 | { 0x1f, 0x0000 }, |
| 2415 | { 0x0d, 0xf880 }, |
| 2416 | |
| 2417 | { 0x1f, 0x0001 }, |
| 2418 | { 0x17, 0x0cc0 }, |
| 2419 | |
| 2420 | { 0x1f, 0x0001 }, |
| 2421 | { 0x0b, 0xa4d8 }, |
| 2422 | { 0x09, 0x281c }, |
| 2423 | { 0x07, 0x2883 }, |
| 2424 | { 0x0a, 0x6b35 }, |
| 2425 | { 0x1d, 0x3da4 }, |
| 2426 | { 0x1c, 0xeffd }, |
| 2427 | { 0x14, 0x7f52 }, |
| 2428 | { 0x18, 0x7fc6 }, |
| 2429 | { 0x08, 0x0601 }, |
| 2430 | { 0x06, 0x4063 }, |
| 2431 | { 0x10, 0xf074 }, |
| 2432 | { 0x1f, 0x0003 }, |
| 2433 | { 0x13, 0x0789 }, |
| 2434 | { 0x12, 0xf4bd }, |
| 2435 | { 0x1a, 0x04fd }, |
| 2436 | { 0x14, 0x84b0 }, |
| 2437 | { 0x1f, 0x0000 }, |
| 2438 | { 0x00, 0x9200 }, |
| 2439 | |
| 2440 | { 0x1f, 0x0005 }, |
| 2441 | { 0x01, 0x0340 }, |
| 2442 | { 0x1f, 0x0001 }, |
| 2443 | { 0x04, 0x4000 }, |
| 2444 | { 0x03, 0x1d21 }, |
| 2445 | { 0x02, 0x0c32 }, |
| 2446 | { 0x01, 0x0200 }, |
| 2447 | { 0x00, 0x5554 }, |
| 2448 | { 0x04, 0x4800 }, |
| 2449 | { 0x04, 0x4000 }, |
| 2450 | { 0x04, 0xf000 }, |
| 2451 | { 0x03, 0xdf01 }, |
| 2452 | { 0x02, 0xdf20 }, |
| 2453 | { 0x01, 0x101a }, |
| 2454 | { 0x00, 0xa0ff }, |
| 2455 | { 0x04, 0xf800 }, |
| 2456 | { 0x04, 0xf000 }, |
| 2457 | { 0x1f, 0x0000 }, |
| 2458 | |
| 2459 | { 0x1f, 0x0007 }, |
| 2460 | { 0x1e, 0x0023 }, |
| 2461 | { 0x16, 0x0000 }, |
| 2462 | { 0x1f, 0x0000 } |
| 2463 | }; |
| 2464 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2465 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2466 | } |
| 2467 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2468 | static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp) |
| 2469 | { |
| 2470 | static const struct phy_reg phy_reg_init[] = { |
| 2471 | { 0x1f, 0x0001 }, |
| 2472 | { 0x17, 0x0cc0 }, |
| 2473 | |
| 2474 | { 0x1f, 0x0007 }, |
| 2475 | { 0x1e, 0x002d }, |
| 2476 | { 0x18, 0x0040 }, |
| 2477 | { 0x1f, 0x0000 } |
| 2478 | }; |
| 2479 | |
| 2480 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 2481 | rtl_patchphy(tp, 0x0d, 1 << 5); |
| 2482 | } |
| 2483 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2484 | static void rtl8168e_hw_phy_config(struct rtl8169_private *tp) |
| 2485 | { |
| 2486 | static const struct phy_reg phy_reg_init[] = { |
| 2487 | /* Enable Delay cap */ |
| 2488 | { 0x1f, 0x0005 }, |
| 2489 | { 0x05, 0x8b80 }, |
| 2490 | { 0x06, 0xc896 }, |
| 2491 | { 0x1f, 0x0000 }, |
| 2492 | |
| 2493 | /* Channel estimation fine tune */ |
| 2494 | { 0x1f, 0x0001 }, |
| 2495 | { 0x0b, 0x6c20 }, |
| 2496 | { 0x07, 0x2872 }, |
| 2497 | { 0x1c, 0xefff }, |
| 2498 | { 0x1f, 0x0003 }, |
| 2499 | { 0x14, 0x6420 }, |
| 2500 | { 0x1f, 0x0000 }, |
| 2501 | |
| 2502 | /* Update PFM & 10M TX idle timer */ |
| 2503 | { 0x1f, 0x0007 }, |
| 2504 | { 0x1e, 0x002f }, |
| 2505 | { 0x15, 0x1919 }, |
| 2506 | { 0x1f, 0x0000 }, |
| 2507 | |
| 2508 | { 0x1f, 0x0007 }, |
| 2509 | { 0x1e, 0x00ac }, |
| 2510 | { 0x18, 0x0006 }, |
| 2511 | { 0x1f, 0x0000 } |
| 2512 | }; |
| 2513 | |
Francois Romieu | 15ecd03 | 2011-04-27 13:52:22 -0700 | [diff] [blame] | 2514 | rtl_apply_firmware(tp); |
| 2515 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2516 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 2517 | |
| 2518 | /* DCO enable for 10M IDLE Power */ |
| 2519 | rtl_writephy(tp, 0x1f, 0x0007); |
| 2520 | rtl_writephy(tp, 0x1e, 0x0023); |
| 2521 | rtl_w1w0_phy(tp, 0x17, 0x0006, 0x0000); |
| 2522 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2523 | |
| 2524 | /* For impedance matching */ |
| 2525 | rtl_writephy(tp, 0x1f, 0x0002); |
| 2526 | rtl_w1w0_phy(tp, 0x08, 0x8000, 0x7f00); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2527 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2528 | |
| 2529 | /* PHY auto speed down */ |
| 2530 | rtl_writephy(tp, 0x1f, 0x0007); |
| 2531 | rtl_writephy(tp, 0x1e, 0x002d); |
| 2532 | rtl_w1w0_phy(tp, 0x18, 0x0050, 0x0000); |
| 2533 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2534 | rtl_w1w0_phy(tp, 0x14, 0x8000, 0x0000); |
| 2535 | |
| 2536 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2537 | rtl_writephy(tp, 0x05, 0x8b86); |
| 2538 | rtl_w1w0_phy(tp, 0x06, 0x0001, 0x0000); |
| 2539 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2540 | |
| 2541 | rtl_writephy(tp, 0x1f, 0x0005); |
| 2542 | rtl_writephy(tp, 0x05, 0x8b85); |
| 2543 | rtl_w1w0_phy(tp, 0x06, 0x0000, 0x2000); |
| 2544 | rtl_writephy(tp, 0x1f, 0x0007); |
| 2545 | rtl_writephy(tp, 0x1e, 0x0020); |
| 2546 | rtl_w1w0_phy(tp, 0x15, 0x0000, 0x1100); |
| 2547 | rtl_writephy(tp, 0x1f, 0x0006); |
| 2548 | rtl_writephy(tp, 0x00, 0x5a00); |
| 2549 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2550 | rtl_writephy(tp, 0x0d, 0x0007); |
| 2551 | rtl_writephy(tp, 0x0e, 0x003c); |
| 2552 | rtl_writephy(tp, 0x0d, 0x4007); |
| 2553 | rtl_writephy(tp, 0x0e, 0x0000); |
| 2554 | rtl_writephy(tp, 0x0d, 0x0000); |
| 2555 | } |
| 2556 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2557 | static void rtl8102e_hw_phy_config(struct rtl8169_private *tp) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2558 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 2559 | static const struct phy_reg phy_reg_init[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2560 | { 0x1f, 0x0003 }, |
| 2561 | { 0x08, 0x441d }, |
| 2562 | { 0x01, 0x9100 }, |
| 2563 | { 0x1f, 0x0000 } |
| 2564 | }; |
| 2565 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2566 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2567 | rtl_patchphy(tp, 0x11, 1 << 12); |
| 2568 | rtl_patchphy(tp, 0x19, 1 << 13); |
| 2569 | rtl_patchphy(tp, 0x10, 1 << 15); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2570 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2571 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2572 | } |
| 2573 | |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 2574 | static void rtl8105e_hw_phy_config(struct rtl8169_private *tp) |
| 2575 | { |
| 2576 | static const struct phy_reg phy_reg_init[] = { |
| 2577 | { 0x1f, 0x0005 }, |
| 2578 | { 0x1a, 0x0000 }, |
| 2579 | { 0x1f, 0x0000 }, |
| 2580 | |
| 2581 | { 0x1f, 0x0004 }, |
| 2582 | { 0x1c, 0x0000 }, |
| 2583 | { 0x1f, 0x0000 }, |
| 2584 | |
| 2585 | { 0x1f, 0x0001 }, |
| 2586 | { 0x15, 0x7701 }, |
| 2587 | { 0x1f, 0x0000 } |
| 2588 | }; |
| 2589 | |
| 2590 | /* Disable ALDPS before ram code */ |
| 2591 | rtl_writephy(tp, 0x1f, 0x0000); |
| 2592 | rtl_writephy(tp, 0x18, 0x0310); |
| 2593 | msleep(100); |
| 2594 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 2595 | rtl_apply_firmware(tp); |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 2596 | |
| 2597 | rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
| 2598 | } |
| 2599 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2600 | static void rtl_hw_phy_config(struct net_device *dev) |
| 2601 | { |
| 2602 | struct rtl8169_private *tp = netdev_priv(dev); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2603 | |
| 2604 | rtl8169_print_mac_version(tp); |
| 2605 | |
| 2606 | switch (tp->mac_version) { |
| 2607 | case RTL_GIGA_MAC_VER_01: |
| 2608 | break; |
| 2609 | case RTL_GIGA_MAC_VER_02: |
| 2610 | case RTL_GIGA_MAC_VER_03: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2611 | rtl8169s_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2612 | break; |
| 2613 | case RTL_GIGA_MAC_VER_04: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2614 | rtl8169sb_hw_phy_config(tp); |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2615 | break; |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2616 | case RTL_GIGA_MAC_VER_05: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2617 | rtl8169scd_hw_phy_config(tp); |
françois romieu | 2e955856 | 2009-08-10 19:44:19 +0000 | [diff] [blame] | 2618 | break; |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2619 | case RTL_GIGA_MAC_VER_06: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2620 | rtl8169sce_hw_phy_config(tp); |
françois romieu | 8c7006a | 2009-08-10 19:43:29 +0000 | [diff] [blame] | 2621 | break; |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2622 | case RTL_GIGA_MAC_VER_07: |
| 2623 | case RTL_GIGA_MAC_VER_08: |
| 2624 | case RTL_GIGA_MAC_VER_09: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2625 | rtl8102e_hw_phy_config(tp); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 2626 | break; |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2627 | case RTL_GIGA_MAC_VER_11: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2628 | rtl8168bb_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2629 | break; |
| 2630 | case RTL_GIGA_MAC_VER_12: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2631 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2632 | break; |
| 2633 | case RTL_GIGA_MAC_VER_17: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2634 | rtl8168bef_hw_phy_config(tp); |
Francois Romieu | 236b808 | 2008-05-30 16:11:48 +0200 | [diff] [blame] | 2635 | break; |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2636 | case RTL_GIGA_MAC_VER_18: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2637 | rtl8168cp_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2638 | break; |
| 2639 | case RTL_GIGA_MAC_VER_19: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2640 | rtl8168c_1_hw_phy_config(tp); |
Francois Romieu | 867763c | 2007-08-17 18:21:58 +0200 | [diff] [blame] | 2641 | break; |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2642 | case RTL_GIGA_MAC_VER_20: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2643 | rtl8168c_2_hw_phy_config(tp); |
Francois Romieu | 7da97ec | 2007-10-18 15:20:43 +0200 | [diff] [blame] | 2644 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2645 | case RTL_GIGA_MAC_VER_21: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2646 | rtl8168c_3_hw_phy_config(tp); |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 2647 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2648 | case RTL_GIGA_MAC_VER_22: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2649 | rtl8168c_4_hw_phy_config(tp); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 2650 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2651 | case RTL_GIGA_MAC_VER_23: |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 2652 | case RTL_GIGA_MAC_VER_24: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2653 | rtl8168cp_2_hw_phy_config(tp); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2654 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2655 | case RTL_GIGA_MAC_VER_25: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2656 | rtl8168d_1_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2657 | break; |
| 2658 | case RTL_GIGA_MAC_VER_26: |
françois romieu | bca03d5 | 2011-01-03 15:07:31 +0000 | [diff] [blame] | 2659 | rtl8168d_2_hw_phy_config(tp); |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 2660 | break; |
| 2661 | case RTL_GIGA_MAC_VER_27: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2662 | rtl8168d_3_hw_phy_config(tp); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 2663 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2664 | case RTL_GIGA_MAC_VER_28: |
| 2665 | rtl8168d_4_hw_phy_config(tp); |
| 2666 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 2667 | case RTL_GIGA_MAC_VER_29: |
| 2668 | case RTL_GIGA_MAC_VER_30: |
| 2669 | rtl8105e_hw_phy_config(tp); |
| 2670 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2671 | case RTL_GIGA_MAC_VER_31: |
| 2672 | /* None. */ |
| 2673 | break; |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2674 | case RTL_GIGA_MAC_VER_32: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2675 | case RTL_GIGA_MAC_VER_33: |
Francois Romieu | 15ecd03 | 2011-04-27 13:52:22 -0700 | [diff] [blame] | 2676 | rtl8168e_hw_phy_config(tp); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 2677 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 2678 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2679 | default: |
| 2680 | break; |
| 2681 | } |
| 2682 | } |
| 2683 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 | static void rtl8169_phy_timer(unsigned long __opaque) |
| 2685 | { |
| 2686 | struct net_device *dev = (struct net_device *)__opaque; |
| 2687 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2688 | struct timer_list *timer = &tp->timer; |
| 2689 | void __iomem *ioaddr = tp->mmio_addr; |
| 2690 | unsigned long timeout = RTL8169_PHY_TIMEOUT; |
| 2691 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 2692 | assert(tp->mac_version > RTL_GIGA_MAC_VER_01); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2693 | |
Francois Romieu | 64e4bfb | 2006-08-17 12:43:06 +0200 | [diff] [blame] | 2694 | if (!(tp->phy_1000_ctrl_reg & ADVERTISE_1000FULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | return; |
| 2696 | |
| 2697 | spin_lock_irq(&tp->lock); |
| 2698 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2699 | if (tp->phy_reset_pending(tp)) { |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 2700 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2701 | * A busy loop could burn quite a few cycles on nowadays CPU. |
| 2702 | * Let's delay the execution of the timer for a few ticks. |
| 2703 | */ |
| 2704 | timeout = HZ/10; |
| 2705 | goto out_mod_timer; |
| 2706 | } |
| 2707 | |
| 2708 | if (tp->link_ok(ioaddr)) |
| 2709 | goto out_unlock; |
| 2710 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 2711 | netif_warn(tp, link, dev, "PHY reset until link up\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2712 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2713 | tp->phy_reset_enable(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2714 | |
| 2715 | out_mod_timer: |
| 2716 | mod_timer(timer, jiffies + timeout); |
| 2717 | out_unlock: |
| 2718 | spin_unlock_irq(&tp->lock); |
| 2719 | } |
| 2720 | |
| 2721 | static inline void rtl8169_delete_timer(struct net_device *dev) |
| 2722 | { |
| 2723 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2724 | struct timer_list *timer = &tp->timer; |
| 2725 | |
Francois Romieu | e179bb7 | 2007-08-17 15:05:21 +0200 | [diff] [blame] | 2726 | if (tp->mac_version <= RTL_GIGA_MAC_VER_01) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2727 | return; |
| 2728 | |
| 2729 | del_timer_sync(timer); |
| 2730 | } |
| 2731 | |
| 2732 | static inline void rtl8169_request_timer(struct net_device *dev) |
| 2733 | { |
| 2734 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2735 | struct timer_list *timer = &tp->timer; |
| 2736 | |
Francois Romieu | e179bb7 | 2007-08-17 15:05:21 +0200 | [diff] [blame] | 2737 | if (tp->mac_version <= RTL_GIGA_MAC_VER_01) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2738 | return; |
| 2739 | |
Francois Romieu | 2efa53f | 2007-03-09 00:00:05 +0100 | [diff] [blame] | 2740 | mod_timer(timer, jiffies + RTL8169_PHY_TIMEOUT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | } |
| 2742 | |
| 2743 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2744 | /* |
| 2745 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 2746 | * without having to re-enable interrupts. It's not called while |
| 2747 | * the interrupt routine is executing. |
| 2748 | */ |
| 2749 | static void rtl8169_netpoll(struct net_device *dev) |
| 2750 | { |
| 2751 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2752 | struct pci_dev *pdev = tp->pci_dev; |
| 2753 | |
| 2754 | disable_irq(pdev->irq); |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 2755 | rtl8169_interrupt(pdev->irq, dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2756 | enable_irq(pdev->irq); |
| 2757 | } |
| 2758 | #endif |
| 2759 | |
| 2760 | static void rtl8169_release_board(struct pci_dev *pdev, struct net_device *dev, |
| 2761 | void __iomem *ioaddr) |
| 2762 | { |
| 2763 | iounmap(ioaddr); |
| 2764 | pci_release_regions(pdev); |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 2765 | pci_clear_mwi(pdev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2766 | pci_disable_device(pdev); |
| 2767 | free_netdev(dev); |
| 2768 | } |
| 2769 | |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 2770 | static void rtl8169_phy_reset(struct net_device *dev, |
| 2771 | struct rtl8169_private *tp) |
| 2772 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 2773 | unsigned int i; |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 2774 | |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2775 | tp->phy_reset_enable(tp); |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 2776 | for (i = 0; i < 100; i++) { |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2777 | if (!tp->phy_reset_pending(tp)) |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 2778 | return; |
| 2779 | msleep(1); |
| 2780 | } |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 2781 | netif_err(tp, link, dev, "PHY reset failed\n"); |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 2782 | } |
| 2783 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 2784 | 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] | 2785 | { |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 2786 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 2787 | |
Francois Romieu | 5615d9f | 2007-08-17 17:50:46 +0200 | [diff] [blame] | 2788 | rtl_hw_phy_config(dev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 2789 | |
Marcus Sundberg | 77332894 | 2008-07-10 21:28:08 +0200 | [diff] [blame] | 2790 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
| 2791 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
| 2792 | RTL_W8(0x82, 0x01); |
| 2793 | } |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 2794 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 2795 | pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); |
| 2796 | |
| 2797 | if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
| 2798 | pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 2799 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 2800 | if (tp->mac_version == RTL_GIGA_MAC_VER_02) { |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 2801 | dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
| 2802 | RTL_W8(0x82, 0x01); |
| 2803 | dprintk("Set PHY Reg 0x0bh = 0x00h\n"); |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2804 | rtl_writephy(tp, 0x0b, 0x0000); //w 0x0b 15 0 0 |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 2805 | } |
| 2806 | |
Francois Romieu | bf79329 | 2006-11-01 00:53:05 +0100 | [diff] [blame] | 2807 | rtl8169_phy_reset(dev, tp); |
| 2808 | |
Oliver Neukum | 54405cd | 2011-01-06 21:55:13 +0100 | [diff] [blame] | 2809 | rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL, |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2810 | ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 2811 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
| 2812 | (tp->mii.supports_gmii ? |
| 2813 | ADVERTISED_1000baseT_Half | |
| 2814 | ADVERTISED_1000baseT_Full : 0)); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 2815 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 2816 | if (RTL_R8(PHYstatus) & TBI_Enable) |
| 2817 | netif_info(tp, link, dev, "TBI auto-negotiating\n"); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 2818 | } |
| 2819 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 2820 | static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr) |
| 2821 | { |
| 2822 | void __iomem *ioaddr = tp->mmio_addr; |
| 2823 | u32 high; |
| 2824 | u32 low; |
| 2825 | |
| 2826 | low = addr[0] | (addr[1] << 8) | (addr[2] << 16) | (addr[3] << 24); |
| 2827 | high = addr[4] | (addr[5] << 8); |
| 2828 | |
| 2829 | spin_lock_irq(&tp->lock); |
| 2830 | |
| 2831 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 2832 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 2833 | RTL_W32(MAC4, high); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 2834 | RTL_R32(MAC4); |
| 2835 | |
Francois Romieu | 78f1cd0 | 2010-03-27 19:35:46 -0700 | [diff] [blame] | 2836 | RTL_W32(MAC0, low); |
françois romieu | 908ba2bf | 2010-04-26 11:42:58 +0000 | [diff] [blame] | 2837 | RTL_R32(MAC0); |
| 2838 | |
Francois Romieu | 773d202 | 2007-01-31 23:47:43 +0100 | [diff] [blame] | 2839 | RTL_W8(Cfg9346, Cfg9346_Lock); |
| 2840 | |
| 2841 | spin_unlock_irq(&tp->lock); |
| 2842 | } |
| 2843 | |
| 2844 | static int rtl_set_mac_address(struct net_device *dev, void *p) |
| 2845 | { |
| 2846 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2847 | struct sockaddr *addr = p; |
| 2848 | |
| 2849 | if (!is_valid_ether_addr(addr->sa_data)) |
| 2850 | return -EADDRNOTAVAIL; |
| 2851 | |
| 2852 | memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
| 2853 | |
| 2854 | rtl_rar_set(tp, dev->dev_addr); |
| 2855 | |
| 2856 | return 0; |
| 2857 | } |
| 2858 | |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 2859 | static int rtl8169_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
| 2860 | { |
| 2861 | struct rtl8169_private *tp = netdev_priv(dev); |
| 2862 | struct mii_ioctl_data *data = if_mii(ifr); |
| 2863 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 2864 | return netif_running(dev) ? tp->do_ioctl(tp, data, cmd) : -ENODEV; |
| 2865 | } |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 2866 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 2867 | static int rtl_xmii_ioctl(struct rtl8169_private *tp, |
| 2868 | struct mii_ioctl_data *data, int cmd) |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 2869 | { |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 2870 | switch (cmd) { |
| 2871 | case SIOCGMIIPHY: |
| 2872 | data->phy_id = 32; /* Internal PHY */ |
| 2873 | return 0; |
| 2874 | |
| 2875 | case SIOCGMIIREG: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2876 | data->val_out = rtl_readphy(tp, data->reg_num & 0x1f); |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 2877 | return 0; |
| 2878 | |
| 2879 | case SIOCSMIIREG: |
françois romieu | 4da1963 | 2011-01-03 15:07:55 +0000 | [diff] [blame] | 2880 | rtl_writephy(tp, data->reg_num & 0x1f, data->val_in); |
Francois Romieu | 5f787a1 | 2006-08-17 13:02:36 +0200 | [diff] [blame] | 2881 | return 0; |
| 2882 | } |
| 2883 | return -EOPNOTSUPP; |
| 2884 | } |
| 2885 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 2886 | static int rtl_tbi_ioctl(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd) |
| 2887 | { |
| 2888 | return -EOPNOTSUPP; |
| 2889 | } |
| 2890 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2891 | static const struct rtl_cfg_info { |
| 2892 | void (*hw_start)(struct net_device *); |
| 2893 | unsigned int region; |
| 2894 | unsigned int align; |
| 2895 | u16 intr_event; |
| 2896 | u16 napi_event; |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 2897 | unsigned features; |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 2898 | u8 default_ver; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2899 | } rtl_cfg_infos [] = { |
| 2900 | [RTL_CFG_0] = { |
| 2901 | .hw_start = rtl_hw_start_8169, |
| 2902 | .region = 1, |
Francois Romieu | e9f63f3 | 2007-02-28 23:16:57 +0100 | [diff] [blame] | 2903 | .align = 0, |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2904 | .intr_event = SYSErr | LinkChg | RxOverflow | |
| 2905 | RxFIFOOver | TxErr | TxOK | RxOK | RxErr, |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 2906 | .napi_event = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow, |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 2907 | .features = RTL_FEATURE_GMII, |
| 2908 | .default_ver = RTL_GIGA_MAC_VER_01, |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2909 | }, |
| 2910 | [RTL_CFG_1] = { |
| 2911 | .hw_start = rtl_hw_start_8168, |
| 2912 | .region = 2, |
| 2913 | .align = 8, |
françois romieu | 53f5735 | 2010-11-08 13:23:05 +0000 | [diff] [blame] | 2914 | .intr_event = SYSErr | LinkChg | RxOverflow | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2915 | TxErr | TxOK | RxOK | RxErr, |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 2916 | .napi_event = TxErr | TxOK | RxOK | RxOverflow, |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 2917 | .features = RTL_FEATURE_GMII | RTL_FEATURE_MSI, |
| 2918 | .default_ver = RTL_GIGA_MAC_VER_11, |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2919 | }, |
| 2920 | [RTL_CFG_2] = { |
| 2921 | .hw_start = rtl_hw_start_8101, |
| 2922 | .region = 2, |
| 2923 | .align = 8, |
| 2924 | .intr_event = SYSErr | LinkChg | RxOverflow | PCSTimeout | |
| 2925 | RxFIFOOver | TxErr | TxOK | RxOK | RxErr, |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 2926 | .napi_event = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow, |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 2927 | .features = RTL_FEATURE_MSI, |
| 2928 | .default_ver = RTL_GIGA_MAC_VER_13, |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 2929 | } |
| 2930 | }; |
| 2931 | |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 2932 | /* Cfg9346_Unlock assumed. */ |
| 2933 | static unsigned rtl_try_msi(struct pci_dev *pdev, void __iomem *ioaddr, |
| 2934 | const struct rtl_cfg_info *cfg) |
| 2935 | { |
| 2936 | unsigned msi = 0; |
| 2937 | u8 cfg2; |
| 2938 | |
| 2939 | cfg2 = RTL_R8(Config2) & ~MSIEnable; |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 2940 | if (cfg->features & RTL_FEATURE_MSI) { |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 2941 | if (pci_enable_msi(pdev)) { |
| 2942 | dev_info(&pdev->dev, "no MSI. Back to INTx.\n"); |
| 2943 | } else { |
| 2944 | cfg2 |= MSIEnable; |
| 2945 | msi = RTL_FEATURE_MSI; |
| 2946 | } |
| 2947 | } |
| 2948 | RTL_W8(Config2, cfg2); |
| 2949 | return msi; |
| 2950 | } |
| 2951 | |
| 2952 | static void rtl_disable_msi(struct pci_dev *pdev, struct rtl8169_private *tp) |
| 2953 | { |
| 2954 | if (tp->features & RTL_FEATURE_MSI) { |
| 2955 | pci_disable_msi(pdev); |
| 2956 | tp->features &= ~RTL_FEATURE_MSI; |
| 2957 | } |
| 2958 | } |
| 2959 | |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 2960 | static const struct net_device_ops rtl8169_netdev_ops = { |
| 2961 | .ndo_open = rtl8169_open, |
| 2962 | .ndo_stop = rtl8169_close, |
| 2963 | .ndo_get_stats = rtl8169_get_stats, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 2964 | .ndo_start_xmit = rtl8169_start_xmit, |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 2965 | .ndo_tx_timeout = rtl8169_tx_timeout, |
| 2966 | .ndo_validate_addr = eth_validate_addr, |
| 2967 | .ndo_change_mtu = rtl8169_change_mtu, |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 2968 | .ndo_fix_features = rtl8169_fix_features, |
| 2969 | .ndo_set_features = rtl8169_set_features, |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 2970 | .ndo_set_mac_address = rtl_set_mac_address, |
| 2971 | .ndo_do_ioctl = rtl8169_ioctl, |
| 2972 | .ndo_set_multicast_list = rtl_set_rx_mode, |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 2973 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2974 | .ndo_poll_controller = rtl8169_netpoll, |
| 2975 | #endif |
| 2976 | |
| 2977 | }; |
| 2978 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 2979 | static void __devinit rtl_init_mdio_ops(struct rtl8169_private *tp) |
| 2980 | { |
| 2981 | struct mdio_ops *ops = &tp->mdio_ops; |
| 2982 | |
| 2983 | switch (tp->mac_version) { |
| 2984 | case RTL_GIGA_MAC_VER_27: |
| 2985 | ops->write = r8168dp_1_mdio_write; |
| 2986 | ops->read = r8168dp_1_mdio_read; |
| 2987 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2988 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 2989 | case RTL_GIGA_MAC_VER_31: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 2990 | ops->write = r8168dp_2_mdio_write; |
| 2991 | ops->read = r8168dp_2_mdio_read; |
| 2992 | break; |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 2993 | default: |
| 2994 | ops->write = r8169_mdio_write; |
| 2995 | ops->read = r8169_mdio_read; |
| 2996 | break; |
| 2997 | } |
| 2998 | } |
| 2999 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3000 | static void r810x_phy_power_down(struct rtl8169_private *tp) |
| 3001 | { |
| 3002 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3003 | rtl_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 3004 | } |
| 3005 | |
| 3006 | static void r810x_phy_power_up(struct rtl8169_private *tp) |
| 3007 | { |
| 3008 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3009 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE); |
| 3010 | } |
| 3011 | |
| 3012 | static void r810x_pll_power_down(struct rtl8169_private *tp) |
| 3013 | { |
| 3014 | if (__rtl8169_get_wol(tp) & WAKE_ANY) { |
| 3015 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3016 | rtl_writephy(tp, MII_BMCR, 0x0000); |
| 3017 | return; |
| 3018 | } |
| 3019 | |
| 3020 | r810x_phy_power_down(tp); |
| 3021 | } |
| 3022 | |
| 3023 | static void r810x_pll_power_up(struct rtl8169_private *tp) |
| 3024 | { |
| 3025 | r810x_phy_power_up(tp); |
| 3026 | } |
| 3027 | |
| 3028 | static void r8168_phy_power_up(struct rtl8169_private *tp) |
| 3029 | { |
| 3030 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3031 | switch (tp->mac_version) { |
| 3032 | case RTL_GIGA_MAC_VER_11: |
| 3033 | case RTL_GIGA_MAC_VER_12: |
| 3034 | case RTL_GIGA_MAC_VER_17: |
| 3035 | case RTL_GIGA_MAC_VER_18: |
| 3036 | case RTL_GIGA_MAC_VER_19: |
| 3037 | case RTL_GIGA_MAC_VER_20: |
| 3038 | case RTL_GIGA_MAC_VER_21: |
| 3039 | case RTL_GIGA_MAC_VER_22: |
| 3040 | case RTL_GIGA_MAC_VER_23: |
| 3041 | case RTL_GIGA_MAC_VER_24: |
| 3042 | case RTL_GIGA_MAC_VER_25: |
| 3043 | case RTL_GIGA_MAC_VER_26: |
| 3044 | case RTL_GIGA_MAC_VER_27: |
| 3045 | case RTL_GIGA_MAC_VER_28: |
| 3046 | case RTL_GIGA_MAC_VER_31: |
| 3047 | rtl_writephy(tp, 0x0e, 0x0000); |
| 3048 | break; |
| 3049 | default: |
| 3050 | break; |
| 3051 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3052 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE); |
| 3053 | } |
| 3054 | |
| 3055 | static void r8168_phy_power_down(struct rtl8169_private *tp) |
| 3056 | { |
| 3057 | rtl_writephy(tp, 0x1f, 0x0000); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3058 | switch (tp->mac_version) { |
| 3059 | case RTL_GIGA_MAC_VER_32: |
| 3060 | case RTL_GIGA_MAC_VER_33: |
| 3061 | rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE | BMCR_PDOWN); |
| 3062 | break; |
| 3063 | |
| 3064 | case RTL_GIGA_MAC_VER_11: |
| 3065 | case RTL_GIGA_MAC_VER_12: |
| 3066 | case RTL_GIGA_MAC_VER_17: |
| 3067 | case RTL_GIGA_MAC_VER_18: |
| 3068 | case RTL_GIGA_MAC_VER_19: |
| 3069 | case RTL_GIGA_MAC_VER_20: |
| 3070 | case RTL_GIGA_MAC_VER_21: |
| 3071 | case RTL_GIGA_MAC_VER_22: |
| 3072 | case RTL_GIGA_MAC_VER_23: |
| 3073 | case RTL_GIGA_MAC_VER_24: |
| 3074 | case RTL_GIGA_MAC_VER_25: |
| 3075 | case RTL_GIGA_MAC_VER_26: |
| 3076 | case RTL_GIGA_MAC_VER_27: |
| 3077 | case RTL_GIGA_MAC_VER_28: |
| 3078 | case RTL_GIGA_MAC_VER_31: |
| 3079 | rtl_writephy(tp, 0x0e, 0x0200); |
| 3080 | default: |
| 3081 | rtl_writephy(tp, MII_BMCR, BMCR_PDOWN); |
| 3082 | break; |
| 3083 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3084 | } |
| 3085 | |
| 3086 | static void r8168_pll_power_down(struct rtl8169_private *tp) |
| 3087 | { |
| 3088 | void __iomem *ioaddr = tp->mmio_addr; |
| 3089 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3090 | if ((tp->mac_version == RTL_GIGA_MAC_VER_27 || |
| 3091 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 3092 | tp->mac_version == RTL_GIGA_MAC_VER_31) && |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 3093 | r8168dp_check_dash(tp)) { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3094 | return; |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 3095 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3096 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3097 | if ((tp->mac_version == RTL_GIGA_MAC_VER_23 || |
| 3098 | tp->mac_version == RTL_GIGA_MAC_VER_24) && |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3099 | (RTL_R16(CPlusCmd) & ASF)) { |
| 3100 | return; |
| 3101 | } |
| 3102 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3103 | if (tp->mac_version == RTL_GIGA_MAC_VER_32 || |
| 3104 | tp->mac_version == RTL_GIGA_MAC_VER_33) |
| 3105 | rtl_ephy_write(ioaddr, 0x19, 0xff64); |
| 3106 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3107 | if (__rtl8169_get_wol(tp) & WAKE_ANY) { |
| 3108 | rtl_writephy(tp, 0x1f, 0x0000); |
| 3109 | rtl_writephy(tp, MII_BMCR, 0x0000); |
| 3110 | |
| 3111 | RTL_W32(RxConfig, RTL_R32(RxConfig) | |
| 3112 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys); |
| 3113 | return; |
| 3114 | } |
| 3115 | |
| 3116 | r8168_phy_power_down(tp); |
| 3117 | |
| 3118 | switch (tp->mac_version) { |
| 3119 | case RTL_GIGA_MAC_VER_25: |
| 3120 | case RTL_GIGA_MAC_VER_26: |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 3121 | case RTL_GIGA_MAC_VER_27: |
| 3122 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 3123 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3124 | case RTL_GIGA_MAC_VER_32: |
| 3125 | case RTL_GIGA_MAC_VER_33: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3126 | RTL_W8(PMCH, RTL_R8(PMCH) & ~0x80); |
| 3127 | break; |
| 3128 | } |
| 3129 | } |
| 3130 | |
| 3131 | static void r8168_pll_power_up(struct rtl8169_private *tp) |
| 3132 | { |
| 3133 | void __iomem *ioaddr = tp->mmio_addr; |
| 3134 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3135 | if ((tp->mac_version == RTL_GIGA_MAC_VER_27 || |
| 3136 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 3137 | tp->mac_version == RTL_GIGA_MAC_VER_31) && |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 3138 | r8168dp_check_dash(tp)) { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3139 | return; |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 3140 | } |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3141 | |
| 3142 | switch (tp->mac_version) { |
| 3143 | case RTL_GIGA_MAC_VER_25: |
| 3144 | case RTL_GIGA_MAC_VER_26: |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 3145 | case RTL_GIGA_MAC_VER_27: |
| 3146 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 3147 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3148 | case RTL_GIGA_MAC_VER_32: |
| 3149 | case RTL_GIGA_MAC_VER_33: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3150 | RTL_W8(PMCH, RTL_R8(PMCH) | 0x80); |
| 3151 | break; |
| 3152 | } |
| 3153 | |
| 3154 | r8168_phy_power_up(tp); |
| 3155 | } |
| 3156 | |
| 3157 | static void rtl_pll_power_op(struct rtl8169_private *tp, |
| 3158 | void (*op)(struct rtl8169_private *)) |
| 3159 | { |
| 3160 | if (op) |
| 3161 | op(tp); |
| 3162 | } |
| 3163 | |
| 3164 | static void rtl_pll_power_down(struct rtl8169_private *tp) |
| 3165 | { |
| 3166 | rtl_pll_power_op(tp, tp->pll_power_ops.down); |
| 3167 | } |
| 3168 | |
| 3169 | static void rtl_pll_power_up(struct rtl8169_private *tp) |
| 3170 | { |
| 3171 | rtl_pll_power_op(tp, tp->pll_power_ops.up); |
| 3172 | } |
| 3173 | |
| 3174 | static void __devinit rtl_init_pll_power_ops(struct rtl8169_private *tp) |
| 3175 | { |
| 3176 | struct pll_power_ops *ops = &tp->pll_power_ops; |
| 3177 | |
| 3178 | switch (tp->mac_version) { |
| 3179 | case RTL_GIGA_MAC_VER_07: |
| 3180 | case RTL_GIGA_MAC_VER_08: |
| 3181 | case RTL_GIGA_MAC_VER_09: |
| 3182 | case RTL_GIGA_MAC_VER_10: |
| 3183 | case RTL_GIGA_MAC_VER_16: |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 3184 | case RTL_GIGA_MAC_VER_29: |
| 3185 | case RTL_GIGA_MAC_VER_30: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3186 | ops->down = r810x_pll_power_down; |
| 3187 | ops->up = r810x_pll_power_up; |
| 3188 | break; |
| 3189 | |
| 3190 | case RTL_GIGA_MAC_VER_11: |
| 3191 | case RTL_GIGA_MAC_VER_12: |
| 3192 | case RTL_GIGA_MAC_VER_17: |
| 3193 | case RTL_GIGA_MAC_VER_18: |
| 3194 | case RTL_GIGA_MAC_VER_19: |
| 3195 | case RTL_GIGA_MAC_VER_20: |
| 3196 | case RTL_GIGA_MAC_VER_21: |
| 3197 | case RTL_GIGA_MAC_VER_22: |
| 3198 | case RTL_GIGA_MAC_VER_23: |
| 3199 | case RTL_GIGA_MAC_VER_24: |
| 3200 | case RTL_GIGA_MAC_VER_25: |
| 3201 | case RTL_GIGA_MAC_VER_26: |
| 3202 | case RTL_GIGA_MAC_VER_27: |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3203 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 3204 | case RTL_GIGA_MAC_VER_31: |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 3205 | case RTL_GIGA_MAC_VER_32: |
| 3206 | case RTL_GIGA_MAC_VER_33: |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3207 | ops->down = r8168_pll_power_down; |
| 3208 | ops->up = r8168_pll_power_up; |
| 3209 | break; |
| 3210 | |
| 3211 | default: |
| 3212 | ops->down = NULL; |
| 3213 | ops->up = NULL; |
| 3214 | break; |
| 3215 | } |
| 3216 | } |
| 3217 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 3218 | static void rtl_hw_reset(struct rtl8169_private *tp) |
| 3219 | { |
| 3220 | void __iomem *ioaddr = tp->mmio_addr; |
| 3221 | int i; |
| 3222 | |
| 3223 | /* Soft reset the chip. */ |
| 3224 | RTL_W8(ChipCmd, CmdReset); |
| 3225 | |
| 3226 | /* Check that the chip has finished the reset. */ |
| 3227 | for (i = 0; i < 100; i++) { |
| 3228 | if ((RTL_R8(ChipCmd) & CmdReset) == 0) |
| 3229 | break; |
| 3230 | msleep_interruptible(1); |
| 3231 | } |
| 3232 | } |
| 3233 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3234 | static int __devinit |
| 3235 | rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
| 3236 | { |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 3237 | const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data; |
| 3238 | const unsigned int region = cfg->region; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3239 | struct rtl8169_private *tp; |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 3240 | struct mii_if_info *mii; |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3241 | struct net_device *dev; |
| 3242 | void __iomem *ioaddr; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 3243 | int chipset, i; |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 3244 | int rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3245 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3246 | if (netif_msg_drv(&debug)) { |
| 3247 | printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n", |
| 3248 | MODULENAME, RTL8169_VERSION); |
| 3249 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3251 | dev = alloc_etherdev(sizeof (*tp)); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3252 | if (!dev) { |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 3253 | if (netif_msg_drv(&debug)) |
Jeff Garzik | 9b91cf9 | 2006-06-27 11:39:50 -0400 | [diff] [blame] | 3254 | dev_err(&pdev->dev, "unable to alloc new ethernet\n"); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3255 | rc = -ENOMEM; |
| 3256 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3257 | } |
| 3258 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3259 | SET_NETDEV_DEV(dev, &pdev->dev); |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3260 | dev->netdev_ops = &rtl8169_netdev_ops; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3261 | tp = netdev_priv(dev); |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3262 | tp->dev = dev; |
Ivan Vecera | 21e197f | 2008-04-17 22:48:41 +0200 | [diff] [blame] | 3263 | tp->pci_dev = pdev; |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 3264 | tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3265 | |
Francois Romieu | ccdffb9 | 2008-07-26 14:26:06 +0200 | [diff] [blame] | 3266 | mii = &tp->mii; |
| 3267 | mii->dev = dev; |
| 3268 | mii->mdio_read = rtl_mdio_read; |
| 3269 | mii->mdio_write = rtl_mdio_write; |
| 3270 | mii->phy_id_mask = 0x1f; |
| 3271 | mii->reg_num_mask = 0x1f; |
| 3272 | mii->supports_gmii = !!(cfg->features & RTL_FEATURE_GMII); |
| 3273 | |
Stanislaw Gruszka | ba04c7c | 2011-02-22 02:00:11 +0000 | [diff] [blame] | 3274 | /* disable ASPM completely as that cause random device stop working |
| 3275 | * problems as well as full system hangs for some PCIe devices users */ |
| 3276 | pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 | |
| 3277 | PCIE_LINK_STATE_CLKPM); |
| 3278 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3279 | /* enable device (incl. PCI PM wakeup and hotplug setup) */ |
| 3280 | rc = pci_enable_device(pdev); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 3281 | if (rc < 0) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3282 | netif_err(tp, probe, dev, "enable failure\n"); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3283 | goto err_out_free_dev_1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3284 | } |
| 3285 | |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3286 | if (pci_set_mwi(pdev) < 0) |
| 3287 | netif_info(tp, probe, dev, "Mem-Wr-Inval unavailable\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3288 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3289 | /* make sure PCI base addr 1 is MMIO */ |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 3290 | if (!(pci_resource_flags(pdev, region) & IORESOURCE_MEM)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3291 | netif_err(tp, probe, dev, |
| 3292 | "region #%d not an MMIO resource, aborting\n", |
| 3293 | region); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3294 | rc = -ENODEV; |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3295 | goto err_out_mwi_2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3296 | } |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3297 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3298 | /* check for weird/broken PCI region reporting */ |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 3299 | if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3300 | netif_err(tp, probe, dev, |
| 3301 | "Invalid PCI region size(s), aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3302 | rc = -ENODEV; |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3303 | goto err_out_mwi_2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3304 | } |
| 3305 | |
| 3306 | rc = pci_request_regions(pdev, MODULENAME); |
Stephen Hemminger | b57b7e5 | 2005-05-27 21:11:52 +0200 | [diff] [blame] | 3307 | if (rc < 0) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3308 | netif_err(tp, probe, dev, "could not request regions\n"); |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3309 | goto err_out_mwi_2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3310 | } |
| 3311 | |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 3312 | tp->cp_cmd = RxChkSum; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3313 | |
| 3314 | if ((sizeof(dma_addr_t) > 4) && |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 3315 | !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && use_dac) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3316 | tp->cp_cmd |= PCIDAC; |
| 3317 | dev->features |= NETIF_F_HIGHDMA; |
| 3318 | } else { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 3319 | rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3320 | if (rc < 0) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3321 | netif_err(tp, probe, dev, "DMA configuration failed\n"); |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3322 | goto err_out_free_res_3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3323 | } |
| 3324 | } |
| 3325 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3326 | /* ioremap MMIO region */ |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 3327 | ioaddr = ioremap(pci_resource_start(pdev, region), R8169_REGS_SIZE); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3328 | if (!ioaddr) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3329 | netif_err(tp, probe, dev, "cannot remap MMIO, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3330 | rc = -EIO; |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3331 | goto err_out_free_res_3; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3332 | } |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 3333 | tp->mmio_addr = ioaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3334 | |
David S. Miller | 4300e8c | 2010-03-26 10:23:30 -0700 | [diff] [blame] | 3335 | tp->pcie_cap = pci_find_capability(pdev, PCI_CAP_ID_EXP); |
| 3336 | if (!tp->pcie_cap) |
| 3337 | netif_info(tp, probe, dev, "no PCI Express capability\n"); |
| 3338 | |
Karsten Wiese | d78ad8c | 2009-04-02 01:06:01 -0700 | [diff] [blame] | 3339 | RTL_W16(IntrMask, 0x0000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3340 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 3341 | rtl_hw_reset(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3342 | |
Karsten Wiese | d78ad8c | 2009-04-02 01:06:01 -0700 | [diff] [blame] | 3343 | RTL_W16(IntrStatus, 0xffff); |
| 3344 | |
françois romieu | ca52efd | 2009-07-24 12:34:19 +0000 | [diff] [blame] | 3345 | pci_set_master(pdev); |
| 3346 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3347 | /* Identify chip attached to board */ |
| 3348 | rtl8169_get_mac_version(tp, ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3349 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 3350 | /* |
| 3351 | * Pretend we are using VLANs; This bypasses a nasty bug where |
| 3352 | * Interrupts stop flowing on high load on 8110SCd controllers. |
| 3353 | */ |
| 3354 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
| 3355 | tp->cp_cmd |= RxVlan; |
| 3356 | |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 3357 | rtl_init_mdio_ops(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3358 | rtl_init_pll_power_ops(tp); |
françois romieu | c0e45c1 | 2011-01-03 15:08:04 +0000 | [diff] [blame] | 3359 | |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 3360 | /* Use appropriate default if unknown */ |
| 3361 | if (tp->mac_version == RTL_GIGA_MAC_NONE) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3362 | netif_notice(tp, probe, dev, |
| 3363 | "unknown MAC, using family default\n"); |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 3364 | tp->mac_version = cfg->default_ver; |
| 3365 | } |
| 3366 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3367 | rtl8169_print_mac_version(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3368 | |
Roel Kluin | cee60c3 | 2008-04-17 22:35:54 +0200 | [diff] [blame] | 3369 | for (i = 0; i < ARRAY_SIZE(rtl_chip_info); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3370 | if (tp->mac_version == rtl_chip_info[i].mac_version) |
| 3371 | break; |
| 3372 | } |
Roel Kluin | cee60c3 | 2008-04-17 22:35:54 +0200 | [diff] [blame] | 3373 | if (i == ARRAY_SIZE(rtl_chip_info)) { |
Jean Delvare | f21b75e | 2009-05-26 20:54:48 -0700 | [diff] [blame] | 3374 | dev_err(&pdev->dev, |
| 3375 | "driver bug, MAC version not found in rtl_chip_info\n"); |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3376 | goto err_out_msi_4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3377 | } |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 3378 | chipset = i; |
| 3379 | tp->txd_version = rtl_chip_info[chipset].txd_version; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3380 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 3381 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 3382 | RTL_W8(Config1, RTL_R8(Config1) | PMEnable); |
| 3383 | RTL_W8(Config5, RTL_R8(Config5) & PMEStatus); |
Bruno Prémont | 20037fa | 2008-10-08 17:05:03 -0700 | [diff] [blame] | 3384 | if ((RTL_R8(Config3) & (LinkUp | MagicPacket)) != 0) |
| 3385 | tp->features |= RTL_FEATURE_WOL; |
| 3386 | if ((RTL_R8(Config5) & (UWF | BWF | MWF)) != 0) |
| 3387 | tp->features |= RTL_FEATURE_WOL; |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 3388 | tp->features |= rtl_try_msi(pdev, ioaddr, cfg); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 3389 | RTL_W8(Cfg9346, Cfg9346_Lock); |
| 3390 | |
Francois Romieu | 66ec5d4 | 2007-11-06 22:56:10 +0100 | [diff] [blame] | 3391 | if ((tp->mac_version <= RTL_GIGA_MAC_VER_06) && |
| 3392 | (RTL_R8(PHYstatus) & TBI_Enable)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3393 | tp->set_speed = rtl8169_set_speed_tbi; |
| 3394 | tp->get_settings = rtl8169_gset_tbi; |
| 3395 | tp->phy_reset_enable = rtl8169_tbi_reset_enable; |
| 3396 | tp->phy_reset_pending = rtl8169_tbi_reset_pending; |
| 3397 | tp->link_ok = rtl8169_tbi_link_ok; |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3398 | tp->do_ioctl = rtl_tbi_ioctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3399 | |
Francois Romieu | 64e4bfb | 2006-08-17 12:43:06 +0200 | [diff] [blame] | 3400 | tp->phy_1000_ctrl_reg = ADVERTISE_1000FULL; /* Implied by TBI */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3401 | } else { |
| 3402 | tp->set_speed = rtl8169_set_speed_xmii; |
| 3403 | tp->get_settings = rtl8169_gset_xmii; |
| 3404 | tp->phy_reset_enable = rtl8169_xmii_reset_enable; |
| 3405 | tp->phy_reset_pending = rtl8169_xmii_reset_pending; |
| 3406 | tp->link_ok = rtl8169_xmii_link_ok; |
Francois Romieu | 8b4ab28 | 2008-11-19 22:05:25 -0800 | [diff] [blame] | 3407 | tp->do_ioctl = rtl_xmii_ioctl; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3408 | } |
| 3409 | |
Francois Romieu | df58ef51 | 2008-10-09 14:35:58 -0700 | [diff] [blame] | 3410 | spin_lock_init(&tp->lock); |
| 3411 | |
Ivan Vecera | 7bf6bf4 | 2008-09-23 22:46:29 +0000 | [diff] [blame] | 3412 | /* Get MAC address */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3413 | for (i = 0; i < MAC_ADDR_LEN; i++) |
| 3414 | dev->dev_addr[i] = RTL_R8(MAC0 + i); |
John W. Linville | 6d6525b | 2005-09-12 10:48:57 -0400 | [diff] [blame] | 3415 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3416 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3417 | SET_ETHTOOL_OPS(dev, &rtl8169_ethtool_ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | dev->watchdog_timeo = RTL8169_TX_TIMEOUT; |
| 3419 | dev->irq = pdev->irq; |
| 3420 | dev->base_addr = (unsigned long) ioaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3421 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3422 | netif_napi_add(dev, &tp->napi, rtl8169_poll, R8169_NAPI_WEIGHT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3423 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 3424 | /* don't enable SG, IP_CSUM and TSO by default - it might not work |
| 3425 | * properly for all devices */ |
| 3426 | dev->features |= NETIF_F_RXCSUM | |
| 3427 | NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
| 3428 | |
| 3429 | dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 3430 | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
| 3431 | dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
| 3432 | NETIF_F_HIGHDMA; |
| 3433 | |
| 3434 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
| 3435 | /* 8110SCd requires hardware Rx VLAN - disallow toggling */ |
| 3436 | dev->hw_features &= ~NETIF_F_HW_VLAN_RX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3437 | |
| 3438 | tp->intr_mask = 0xffff; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 3439 | tp->hw_start = cfg->hw_start; |
| 3440 | tp->intr_event = cfg->intr_event; |
| 3441 | tp->napi_event = cfg->napi_event; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3442 | |
Francois Romieu | 2efa53f | 2007-03-09 00:00:05 +0100 | [diff] [blame] | 3443 | init_timer(&tp->timer); |
| 3444 | tp->timer.data = (unsigned long) dev; |
| 3445 | tp->timer.function = rtl8169_phy_timer; |
| 3446 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3447 | tp->fw = RTL_FIRMWARE_UNKNOWN; |
| 3448 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3449 | rc = register_netdev(dev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3450 | if (rc < 0) |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3451 | goto err_out_msi_4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3452 | |
| 3453 | pci_set_drvdata(pdev, dev); |
| 3454 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3455 | netif_info(tp, probe, dev, "%s at 0x%lx, %pM, XID %08x IRQ %d\n", |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 3456 | rtl_chip_info[chipset].name, dev->base_addr, dev->dev_addr, |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 3457 | (u32)(RTL_R32(TxConfig) & 0x9cf0f8ff), dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3458 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3459 | if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
| 3460 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 3461 | tp->mac_version == RTL_GIGA_MAC_VER_31) { |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 3462 | rtl8168_driver_start(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3463 | } |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 3464 | |
Bruno Prémont | 8b76ab3 | 2008-10-08 17:06:25 -0700 | [diff] [blame] | 3465 | device_set_wakeup_enable(&pdev->dev, tp->features & RTL_FEATURE_WOL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3466 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 3467 | if (pci_dev_run_wake(pdev)) |
| 3468 | pm_runtime_put_noidle(&pdev->dev); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 3469 | |
Ivan Vecera | 0d672e9 | 2011-02-15 02:08:39 +0000 | [diff] [blame] | 3470 | netif_carrier_off(dev); |
| 3471 | |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3472 | out: |
| 3473 | return rc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3474 | |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3475 | err_out_msi_4: |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 3476 | rtl_disable_msi(pdev, tp); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3477 | iounmap(ioaddr); |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3478 | err_out_free_res_3: |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3479 | pci_release_regions(pdev); |
françois romieu | 87aeec7 | 2010-04-26 11:42:06 +0000 | [diff] [blame] | 3480 | err_out_mwi_2: |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3481 | pci_clear_mwi(pdev); |
Francois Romieu | 4ff96fa | 2006-07-26 22:05:06 +0200 | [diff] [blame] | 3482 | pci_disable_device(pdev); |
| 3483 | err_out_free_dev_1: |
| 3484 | free_netdev(dev); |
| 3485 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3486 | } |
| 3487 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 3488 | static void __devexit rtl8169_remove_one(struct pci_dev *pdev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3489 | { |
| 3490 | struct net_device *dev = pci_get_drvdata(pdev); |
| 3491 | struct rtl8169_private *tp = netdev_priv(dev); |
| 3492 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3493 | if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
| 3494 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 3495 | tp->mac_version == RTL_GIGA_MAC_VER_31) { |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 3496 | rtl8168_driver_stop(tp); |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3497 | } |
françois romieu | b646d90 | 2011-01-03 15:08:21 +0000 | [diff] [blame] | 3498 | |
Tejun Heo | 23f333a | 2010-12-12 16:45:14 +0100 | [diff] [blame] | 3499 | cancel_delayed_work_sync(&tp->task); |
Francois Romieu | eb2a021 | 2007-02-15 23:37:21 +0100 | [diff] [blame] | 3500 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3501 | unregister_netdev(dev); |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 3502 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3503 | rtl_release_firmware(tp); |
| 3504 | |
Alan Stern | f3ec4f8 | 2010-06-08 15:23:51 -0400 | [diff] [blame] | 3505 | if (pci_dev_run_wake(pdev)) |
| 3506 | pm_runtime_get_noresume(&pdev->dev); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 3507 | |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 3508 | /* restore original MAC address */ |
| 3509 | rtl_rar_set(tp, dev->perm_addr); |
| 3510 | |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 3511 | rtl_disable_msi(pdev, tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3512 | rtl8169_release_board(pdev, dev, tp->mmio_addr); |
| 3513 | pci_set_drvdata(pdev, NULL); |
| 3514 | } |
| 3515 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3516 | static void rtl_request_firmware(struct rtl8169_private *tp) |
| 3517 | { |
| 3518 | int i; |
| 3519 | |
| 3520 | /* Return early if the firmware is already loaded / cached. */ |
| 3521 | if (!IS_ERR(tp->fw)) |
| 3522 | goto out; |
| 3523 | |
| 3524 | for (i = 0; i < ARRAY_SIZE(rtl_firmware_infos); i++) { |
| 3525 | const struct rtl_firmware_info *info = rtl_firmware_infos + i; |
| 3526 | |
| 3527 | if (info->mac_version == tp->mac_version) { |
| 3528 | const char *name = info->fw_name; |
| 3529 | int rc; |
| 3530 | |
| 3531 | rc = request_firmware(&tp->fw, name, &tp->pci_dev->dev); |
| 3532 | if (rc < 0) { |
| 3533 | netif_warn(tp, ifup, tp->dev, "unable to load " |
| 3534 | "firmware patch %s (%d)\n", name, rc); |
| 3535 | goto out_disable_request_firmware; |
| 3536 | } |
| 3537 | goto out; |
| 3538 | } |
| 3539 | } |
| 3540 | |
| 3541 | out_disable_request_firmware: |
| 3542 | tp->fw = NULL; |
| 3543 | out: |
| 3544 | return; |
| 3545 | } |
| 3546 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3547 | static int rtl8169_open(struct net_device *dev) |
| 3548 | { |
| 3549 | struct rtl8169_private *tp = netdev_priv(dev); |
françois romieu | eee3a96 | 2011-01-08 02:17:26 +0000 | [diff] [blame] | 3550 | void __iomem *ioaddr = tp->mmio_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3551 | struct pci_dev *pdev = tp->pci_dev; |
Francois Romieu | 99f252b | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 3552 | int retval = -ENOMEM; |
| 3553 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 3554 | pm_runtime_get_sync(&pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3555 | |
Neil Horman | c0cd884 | 2010-03-29 13:16:02 -0700 | [diff] [blame] | 3556 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3557 | * Rx and Tx desscriptors needs 256 bytes alignment. |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 3558 | * dma_alloc_coherent provides more. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3559 | */ |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 3560 | tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES, |
| 3561 | &tp->TxPhyAddr, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3562 | if (!tp->TxDescArray) |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 3563 | goto err_pm_runtime_put; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3564 | |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 3565 | tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, |
| 3566 | &tp->RxPhyAddr, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3567 | if (!tp->RxDescArray) |
Francois Romieu | 99f252b | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 3568 | goto err_free_tx_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3569 | |
| 3570 | retval = rtl8169_init_ring(dev); |
| 3571 | if (retval < 0) |
Francois Romieu | 99f252b | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 3572 | goto err_free_rx_1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3573 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 3574 | INIT_DELAYED_WORK(&tp->task, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3575 | |
Francois Romieu | 99f252b | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 3576 | smp_mb(); |
| 3577 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3578 | rtl_request_firmware(tp); |
| 3579 | |
Francois Romieu | fbac58f | 2007-10-04 22:51:38 +0200 | [diff] [blame] | 3580 | retval = request_irq(dev->irq, rtl8169_interrupt, |
| 3581 | (tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED, |
Francois Romieu | 99f252b | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 3582 | dev->name, dev); |
| 3583 | if (retval < 0) |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3584 | goto err_release_fw_2; |
Francois Romieu | 99f252b | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 3585 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3586 | napi_enable(&tp->napi); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3587 | |
françois romieu | eee3a96 | 2011-01-08 02:17:26 +0000 | [diff] [blame] | 3588 | rtl8169_init_phy(dev, tp); |
| 3589 | |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 3590 | rtl8169_set_features(dev, dev->features); |
françois romieu | eee3a96 | 2011-01-08 02:17:26 +0000 | [diff] [blame] | 3591 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 3592 | rtl_pll_power_up(tp); |
| 3593 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 3594 | rtl_hw_start(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3595 | |
| 3596 | rtl8169_request_timer(dev); |
| 3597 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 3598 | tp->saved_wolopts = 0; |
| 3599 | pm_runtime_put_noidle(&pdev->dev); |
| 3600 | |
françois romieu | eee3a96 | 2011-01-08 02:17:26 +0000 | [diff] [blame] | 3601 | rtl8169_check_link_status(dev, tp, ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3602 | out: |
| 3603 | return retval; |
| 3604 | |
François Romieu | 953a12c | 2011-04-24 17:38:48 +0200 | [diff] [blame] | 3605 | err_release_fw_2: |
| 3606 | rtl_release_firmware(tp); |
Francois Romieu | 99f252b | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 3607 | rtl8169_rx_clear(tp); |
| 3608 | err_free_rx_1: |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 3609 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 3610 | tp->RxPhyAddr); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 3611 | tp->RxDescArray = NULL; |
Francois Romieu | 99f252b | 2007-04-02 22:59:59 +0200 | [diff] [blame] | 3612 | err_free_tx_0: |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 3613 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 3614 | tp->TxPhyAddr); |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 3615 | tp->TxDescArray = NULL; |
| 3616 | err_pm_runtime_put: |
| 3617 | pm_runtime_put_noidle(&pdev->dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3618 | goto out; |
| 3619 | } |
| 3620 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3621 | static void rtl8169_hw_reset(struct rtl8169_private *tp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3622 | { |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3623 | void __iomem *ioaddr = tp->mmio_addr; |
| 3624 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3625 | /* Disable interrupts */ |
| 3626 | rtl8169_irq_mask_and_ack(ioaddr); |
| 3627 | |
Hayes Wang | 5d2e195 | 2011-02-22 17:26:22 +0800 | [diff] [blame] | 3628 | if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 3629 | tp->mac_version == RTL_GIGA_MAC_VER_28 || |
| 3630 | tp->mac_version == RTL_GIGA_MAC_VER_31) { |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3631 | while (RTL_R8(TxPoll) & NPQ) |
| 3632 | udelay(20); |
| 3633 | |
| 3634 | } |
| 3635 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3636 | /* Reset the chipset */ |
| 3637 | RTL_W8(ChipCmd, CmdReset); |
| 3638 | |
| 3639 | /* PCI commit */ |
| 3640 | RTL_R8(ChipCmd); |
| 3641 | } |
| 3642 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 3643 | static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 3644 | { |
| 3645 | void __iomem *ioaddr = tp->mmio_addr; |
| 3646 | u32 cfg = rtl8169_rx_config; |
| 3647 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 3648 | cfg |= (RTL_R32(RxConfig) & RTL_RX_CONFIG_MASK); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 3649 | RTL_W32(RxConfig, cfg); |
| 3650 | |
| 3651 | /* Set DMA burst size and Interframe Gap Time */ |
| 3652 | RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) | |
| 3653 | (InterFrameGap << TxInterFrameGapShift)); |
| 3654 | } |
| 3655 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 3656 | static void rtl_hw_start(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3657 | { |
| 3658 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3659 | |
Francois Romieu | 6f43adc | 2011-04-29 15:05:51 +0200 | [diff] [blame] | 3660 | rtl_hw_reset(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3661 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 3662 | tp->hw_start(dev); |
| 3663 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 3664 | netif_start_queue(dev); |
| 3665 | } |
| 3666 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 3667 | static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp, |
| 3668 | void __iomem *ioaddr) |
| 3669 | { |
| 3670 | /* |
| 3671 | * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh |
| 3672 | * register to be written before TxDescAddrLow to work. |
| 3673 | * Switching from MMIO to I/O access fixes the issue as well. |
| 3674 | */ |
| 3675 | RTL_W32(TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 3676 | RTL_W32(TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 3677 | RTL_W32(RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 3678 | RTL_W32(RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 3679 | } |
| 3680 | |
| 3681 | static u16 rtl_rw_cpluscmd(void __iomem *ioaddr) |
| 3682 | { |
| 3683 | u16 cmd; |
| 3684 | |
| 3685 | cmd = RTL_R16(CPlusCmd); |
| 3686 | RTL_W16(CPlusCmd, cmd); |
| 3687 | return cmd; |
| 3688 | } |
| 3689 | |
Eric Dumazet | fdd7b4c | 2009-06-09 04:01:02 -0700 | [diff] [blame] | 3690 | 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] | 3691 | { |
| 3692 | /* Low hurts. Let's disable the filtering. */ |
Raimonds Cicans | 207d6e87 | 2009-10-26 10:52:37 +0000 | [diff] [blame] | 3693 | RTL_W16(RxMaxSize, rx_buf_sz + 1); |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 3694 | } |
| 3695 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 3696 | static void rtl8169_set_magic_reg(void __iomem *ioaddr, unsigned mac_version) |
| 3697 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3698 | static const struct { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 3699 | u32 mac_version; |
| 3700 | u32 clk; |
| 3701 | u32 val; |
| 3702 | } cfg2_info [] = { |
| 3703 | { RTL_GIGA_MAC_VER_05, PCI_Clock_33MHz, 0x000fff00 }, // 8110SCd |
| 3704 | { RTL_GIGA_MAC_VER_05, PCI_Clock_66MHz, 0x000fffff }, |
| 3705 | { RTL_GIGA_MAC_VER_06, PCI_Clock_33MHz, 0x00ffff00 }, // 8110SCe |
| 3706 | { RTL_GIGA_MAC_VER_06, PCI_Clock_66MHz, 0x00ffffff } |
| 3707 | }, *p = cfg2_info; |
| 3708 | unsigned int i; |
| 3709 | u32 clk; |
| 3710 | |
| 3711 | clk = RTL_R8(Config2) & PCI_Clock_66MHz; |
Francois Romieu | cadf185 | 2008-01-03 23:38:38 +0100 | [diff] [blame] | 3712 | for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) { |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 3713 | if ((p->mac_version == mac_version) && (p->clk == clk)) { |
| 3714 | RTL_W32(0x7c, p->val); |
| 3715 | break; |
| 3716 | } |
| 3717 | } |
| 3718 | } |
| 3719 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 3720 | static void rtl_hw_start_8169(struct net_device *dev) |
| 3721 | { |
| 3722 | struct rtl8169_private *tp = netdev_priv(dev); |
| 3723 | void __iomem *ioaddr = tp->mmio_addr; |
| 3724 | struct pci_dev *pdev = tp->pci_dev; |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 3725 | |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 3726 | if (tp->mac_version == RTL_GIGA_MAC_VER_05) { |
| 3727 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) | PCIMulRW); |
| 3728 | pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, 0x08); |
| 3729 | } |
| 3730 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3731 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3732 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 || |
| 3733 | tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 3734 | tp->mac_version == RTL_GIGA_MAC_VER_03 || |
| 3735 | tp->mac_version == RTL_GIGA_MAC_VER_04) |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 3736 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 3737 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 3738 | RTL_W8(EarlyTxThres, NoEarlyTx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3739 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 3740 | rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3741 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3742 | if (tp->mac_version == RTL_GIGA_MAC_VER_01 || |
| 3743 | tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 3744 | tp->mac_version == RTL_GIGA_MAC_VER_03 || |
| 3745 | tp->mac_version == RTL_GIGA_MAC_VER_04) |
Francois Romieu | c946b30 | 2007-10-04 00:42:50 +0200 | [diff] [blame] | 3746 | rtl_set_rx_tx_config_registers(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 3748 | tp->cp_cmd |= rtl_rw_cpluscmd(ioaddr) | PCIMulRW; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 3749 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3750 | if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
| 3751 | tp->mac_version == RTL_GIGA_MAC_VER_03) { |
Joe Perches | 06fa735 | 2007-10-18 21:15:00 +0200 | [diff] [blame] | 3752 | dprintk("Set MAC Reg C+CR Offset 0xE0. " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3753 | "Bit-3 and bit-14 MUST be 1\n"); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 3754 | tp->cp_cmd |= (1 << 14); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | } |
| 3756 | |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 3757 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 3758 | |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 3759 | rtl8169_set_magic_reg(ioaddr, tp->mac_version); |
| 3760 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3761 | /* |
| 3762 | * Undocumented corner. Supposedly: |
| 3763 | * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets |
| 3764 | */ |
| 3765 | RTL_W16(IntrMitigate, 0x0000); |
| 3766 | |
Francois Romieu | 7f796d83 | 2007-06-11 23:04:41 +0200 | [diff] [blame] | 3767 | rtl_set_rx_tx_desc_registers(tp, ioaddr); |
Francois Romieu | 9cb427b | 2006-11-02 00:10:16 +0100 | [diff] [blame] | 3768 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 3769 | if (tp->mac_version != RTL_GIGA_MAC_VER_01 && |
| 3770 | tp->mac_version != RTL_GIGA_MAC_VER_02 && |
| 3771 | tp->mac_version != RTL_GIGA_MAC_VER_03 && |
| 3772 | tp->mac_version != RTL_GIGA_MAC_VER_04) { |
Francois Romieu | c946b30 | 2007-10-04 00:42:50 +0200 | [diff] [blame] | 3773 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 3774 | rtl_set_rx_tx_config_registers(tp); |
| 3775 | } |
| 3776 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3777 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Francois Romieu | b518fa8 | 2006-08-16 15:23:13 +0200 | [diff] [blame] | 3778 | |
| 3779 | /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ |
| 3780 | RTL_R8(IntrMask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3781 | |
| 3782 | RTL_W32(RxMissed, 0); |
| 3783 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 3784 | rtl_set_rx_mode(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3785 | |
| 3786 | /* no early-rx interrupts */ |
| 3787 | RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 3788 | |
| 3789 | /* Enable all known interrupts by setting the interrupt mask. */ |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 3790 | RTL_W16(IntrMask, tp->intr_event); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 3791 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3792 | |
Francois Romieu | 9c14cea | 2008-07-05 00:21:15 +0200 | [diff] [blame] | 3793 | static void rtl_tx_performance_tweak(struct pci_dev *pdev, u16 force) |
Francois Romieu | 458a9f6 | 2008-08-02 15:50:02 +0200 | [diff] [blame] | 3794 | { |
Francois Romieu | 9c14cea | 2008-07-05 00:21:15 +0200 | [diff] [blame] | 3795 | struct net_device *dev = pci_get_drvdata(pdev); |
| 3796 | struct rtl8169_private *tp = netdev_priv(dev); |
| 3797 | int cap = tp->pcie_cap; |
Francois Romieu | 458a9f6 | 2008-08-02 15:50:02 +0200 | [diff] [blame] | 3798 | |
Francois Romieu | 9c14cea | 2008-07-05 00:21:15 +0200 | [diff] [blame] | 3799 | if (cap) { |
| 3800 | u16 ctl; |
| 3801 | |
| 3802 | pci_read_config_word(pdev, cap + PCI_EXP_DEVCTL, &ctl); |
| 3803 | ctl = (ctl & ~PCI_EXP_DEVCTL_READRQ) | force; |
| 3804 | pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, ctl); |
| 3805 | } |
Francois Romieu | 458a9f6 | 2008-08-02 15:50:02 +0200 | [diff] [blame] | 3806 | } |
| 3807 | |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 3808 | static void rtl_csi_access_enable(void __iomem *ioaddr, u32 bits) |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 3809 | { |
| 3810 | u32 csi; |
| 3811 | |
| 3812 | csi = rtl_csi_read(ioaddr, 0x070c) & 0x00ffffff; |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 3813 | rtl_csi_write(ioaddr, 0x070c, csi | bits); |
| 3814 | } |
| 3815 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3816 | static void rtl_csi_access_enable_1(void __iomem *ioaddr) |
| 3817 | { |
| 3818 | rtl_csi_access_enable(ioaddr, 0x17000000); |
| 3819 | } |
| 3820 | |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 3821 | static void rtl_csi_access_enable_2(void __iomem *ioaddr) |
| 3822 | { |
| 3823 | rtl_csi_access_enable(ioaddr, 0x27000000); |
Francois Romieu | dacf815 | 2008-08-02 20:44:13 +0200 | [diff] [blame] | 3824 | } |
| 3825 | |
| 3826 | struct ephy_info { |
| 3827 | unsigned int offset; |
| 3828 | u16 mask; |
| 3829 | u16 bits; |
| 3830 | }; |
| 3831 | |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3832 | 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] | 3833 | { |
| 3834 | u16 w; |
| 3835 | |
| 3836 | while (len-- > 0) { |
| 3837 | w = (rtl_ephy_read(ioaddr, e->offset) & ~e->mask) | e->bits; |
| 3838 | rtl_ephy_write(ioaddr, e->offset, w); |
| 3839 | e++; |
| 3840 | } |
| 3841 | } |
| 3842 | |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 3843 | static void rtl_disable_clock_request(struct pci_dev *pdev) |
| 3844 | { |
| 3845 | struct net_device *dev = pci_get_drvdata(pdev); |
| 3846 | struct rtl8169_private *tp = netdev_priv(dev); |
| 3847 | int cap = tp->pcie_cap; |
| 3848 | |
| 3849 | if (cap) { |
| 3850 | u16 ctl; |
| 3851 | |
| 3852 | pci_read_config_word(pdev, cap + PCI_EXP_LNKCTL, &ctl); |
| 3853 | ctl &= ~PCI_EXP_LNKCTL_CLKREQ_EN; |
| 3854 | pci_write_config_word(pdev, cap + PCI_EXP_LNKCTL, ctl); |
| 3855 | } |
| 3856 | } |
| 3857 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 3858 | static void rtl_enable_clock_request(struct pci_dev *pdev) |
| 3859 | { |
| 3860 | struct net_device *dev = pci_get_drvdata(pdev); |
| 3861 | struct rtl8169_private *tp = netdev_priv(dev); |
| 3862 | int cap = tp->pcie_cap; |
| 3863 | |
| 3864 | if (cap) { |
| 3865 | u16 ctl; |
| 3866 | |
| 3867 | pci_read_config_word(pdev, cap + PCI_EXP_LNKCTL, &ctl); |
| 3868 | ctl |= PCI_EXP_LNKCTL_CLKREQ_EN; |
| 3869 | pci_write_config_word(pdev, cap + PCI_EXP_LNKCTL, ctl); |
| 3870 | } |
| 3871 | } |
| 3872 | |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 3873 | #define R8168_CPCMD_QUIRK_MASK (\ |
| 3874 | EnableBist | \ |
| 3875 | Mac_dbgo_oe | \ |
| 3876 | Force_half_dup | \ |
| 3877 | Force_rxflow_en | \ |
| 3878 | Force_txflow_en | \ |
| 3879 | Cxpl_dbg_sel | \ |
| 3880 | ASF | \ |
| 3881 | PktCntrDisable | \ |
| 3882 | Mac_dbgo_sel) |
| 3883 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 3884 | static void rtl_hw_start_8168bb(void __iomem *ioaddr, struct pci_dev *pdev) |
| 3885 | { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 3886 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 3887 | |
| 3888 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 3889 | |
Francois Romieu | 2e68ae4 | 2008-06-28 12:00:55 +0200 | [diff] [blame] | 3890 | rtl_tx_performance_tweak(pdev, |
| 3891 | (0x5 << MAX_READ_REQUEST_SHIFT) | PCI_EXP_DEVCTL_NOSNOOP_EN); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 3892 | } |
| 3893 | |
| 3894 | static void rtl_hw_start_8168bef(void __iomem *ioaddr, struct pci_dev *pdev) |
| 3895 | { |
| 3896 | rtl_hw_start_8168bb(ioaddr, pdev); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 3897 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 3898 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 3899 | |
| 3900 | RTL_W8(Config4, RTL_R8(Config4) & ~(1 << 0)); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 3901 | } |
| 3902 | |
| 3903 | static void __rtl_hw_start_8168cp(void __iomem *ioaddr, struct pci_dev *pdev) |
| 3904 | { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 3905 | RTL_W8(Config1, RTL_R8(Config1) | Speed_down); |
| 3906 | |
| 3907 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 3908 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 3909 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 3910 | |
| 3911 | rtl_disable_clock_request(pdev); |
| 3912 | |
| 3913 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 3914 | } |
| 3915 | |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3916 | 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] | 3917 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3918 | static const struct ephy_info e_info_8168cp[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 3919 | { 0x01, 0, 0x0001 }, |
| 3920 | { 0x02, 0x0800, 0x1000 }, |
| 3921 | { 0x03, 0, 0x0042 }, |
| 3922 | { 0x06, 0x0080, 0x0000 }, |
| 3923 | { 0x07, 0, 0x2000 } |
| 3924 | }; |
| 3925 | |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 3926 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 3927 | |
| 3928 | rtl_ephy_init(ioaddr, e_info_8168cp, ARRAY_SIZE(e_info_8168cp)); |
| 3929 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 3930 | __rtl_hw_start_8168cp(ioaddr, pdev); |
| 3931 | } |
| 3932 | |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3933 | static void rtl_hw_start_8168cp_2(void __iomem *ioaddr, struct pci_dev *pdev) |
| 3934 | { |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 3935 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 3936 | |
| 3937 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 3938 | |
| 3939 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 3940 | |
| 3941 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 3942 | } |
| 3943 | |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 3944 | static void rtl_hw_start_8168cp_3(void __iomem *ioaddr, struct pci_dev *pdev) |
| 3945 | { |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 3946 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 3947 | |
| 3948 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 3949 | |
| 3950 | /* Magic. */ |
| 3951 | RTL_W8(DBG_REG, 0x20); |
| 3952 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 3953 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 3954 | |
| 3955 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 3956 | |
| 3957 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 3958 | } |
| 3959 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 3960 | static void rtl_hw_start_8168c_1(void __iomem *ioaddr, struct pci_dev *pdev) |
| 3961 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3962 | static const struct ephy_info e_info_8168c_1[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 3963 | { 0x02, 0x0800, 0x1000 }, |
| 3964 | { 0x03, 0, 0x0002 }, |
| 3965 | { 0x06, 0x0080, 0x0000 } |
| 3966 | }; |
| 3967 | |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 3968 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 3969 | |
| 3970 | RTL_W8(DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2); |
| 3971 | |
| 3972 | rtl_ephy_init(ioaddr, e_info_8168c_1, ARRAY_SIZE(e_info_8168c_1)); |
| 3973 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 3974 | __rtl_hw_start_8168cp(ioaddr, pdev); |
| 3975 | } |
| 3976 | |
| 3977 | static void rtl_hw_start_8168c_2(void __iomem *ioaddr, struct pci_dev *pdev) |
| 3978 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 3979 | static const struct ephy_info e_info_8168c_2[] = { |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 3980 | { 0x01, 0, 0x0001 }, |
| 3981 | { 0x03, 0x0400, 0x0220 } |
| 3982 | }; |
| 3983 | |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 3984 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | b726e49 | 2008-06-28 12:22:59 +0200 | [diff] [blame] | 3985 | |
| 3986 | rtl_ephy_init(ioaddr, e_info_8168c_2, ARRAY_SIZE(e_info_8168c_2)); |
| 3987 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 3988 | __rtl_hw_start_8168cp(ioaddr, pdev); |
| 3989 | } |
| 3990 | |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 3991 | static void rtl_hw_start_8168c_3(void __iomem *ioaddr, struct pci_dev *pdev) |
| 3992 | { |
| 3993 | rtl_hw_start_8168c_2(ioaddr, pdev); |
| 3994 | } |
| 3995 | |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3996 | static void rtl_hw_start_8168c_4(void __iomem *ioaddr, struct pci_dev *pdev) |
| 3997 | { |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 3998 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 3999 | |
| 4000 | __rtl_hw_start_8168cp(ioaddr, pdev); |
| 4001 | } |
| 4002 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4003 | static void rtl_hw_start_8168d(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4004 | { |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4005 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4006 | |
| 4007 | rtl_disable_clock_request(pdev); |
| 4008 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 4009 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4010 | |
| 4011 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4012 | |
| 4013 | RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
| 4014 | } |
| 4015 | |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4016 | static void rtl_hw_start_8168dp(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4017 | { |
| 4018 | rtl_csi_access_enable_1(ioaddr); |
| 4019 | |
| 4020 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4021 | |
| 4022 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
| 4023 | |
| 4024 | rtl_disable_clock_request(pdev); |
| 4025 | } |
| 4026 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4027 | static void rtl_hw_start_8168d_4(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4028 | { |
| 4029 | static const struct ephy_info e_info_8168d_4[] = { |
| 4030 | { 0x0b, ~0, 0x48 }, |
| 4031 | { 0x19, 0x20, 0x50 }, |
| 4032 | { 0x0c, ~0, 0x20 } |
| 4033 | }; |
| 4034 | int i; |
| 4035 | |
| 4036 | rtl_csi_access_enable_1(ioaddr); |
| 4037 | |
| 4038 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4039 | |
| 4040 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
| 4041 | |
| 4042 | for (i = 0; i < ARRAY_SIZE(e_info_8168d_4); i++) { |
| 4043 | const struct ephy_info *e = e_info_8168d_4 + i; |
| 4044 | u16 w; |
| 4045 | |
| 4046 | w = rtl_ephy_read(ioaddr, e->offset); |
| 4047 | rtl_ephy_write(ioaddr, 0x03, (w & e->mask) | e->bits); |
| 4048 | } |
| 4049 | |
| 4050 | rtl_enable_clock_request(pdev); |
| 4051 | } |
| 4052 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4053 | static void rtl_hw_start_8168e(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4054 | { |
| 4055 | static const struct ephy_info e_info_8168e[] = { |
| 4056 | { 0x00, 0x0200, 0x0100 }, |
| 4057 | { 0x00, 0x0000, 0x0004 }, |
| 4058 | { 0x06, 0x0002, 0x0001 }, |
| 4059 | { 0x06, 0x0000, 0x0030 }, |
| 4060 | { 0x07, 0x0000, 0x2000 }, |
| 4061 | { 0x00, 0x0000, 0x0020 }, |
| 4062 | { 0x03, 0x5800, 0x2000 }, |
| 4063 | { 0x03, 0x0000, 0x0001 }, |
| 4064 | { 0x01, 0x0800, 0x1000 }, |
| 4065 | { 0x07, 0x0000, 0x4000 }, |
| 4066 | { 0x1e, 0x0000, 0x2000 }, |
| 4067 | { 0x19, 0xffff, 0xfe6c }, |
| 4068 | { 0x0a, 0x0000, 0x0040 } |
| 4069 | }; |
| 4070 | |
| 4071 | rtl_csi_access_enable_2(ioaddr); |
| 4072 | |
| 4073 | rtl_ephy_init(ioaddr, e_info_8168e, ARRAY_SIZE(e_info_8168e)); |
| 4074 | |
| 4075 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4076 | |
| 4077 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
| 4078 | |
| 4079 | rtl_disable_clock_request(pdev); |
| 4080 | |
| 4081 | /* Reset tx FIFO pointer */ |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4082 | RTL_W32(MISC, RTL_R32(MISC) | TXPLA_RST); |
| 4083 | RTL_W32(MISC, RTL_R32(MISC) & ~TXPLA_RST); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4084 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4085 | RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en); |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4086 | } |
| 4087 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4088 | static void rtl_hw_start_8168(struct net_device *dev) |
| 4089 | { |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4090 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4091 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 4092 | struct pci_dev *pdev = tp->pci_dev; |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4093 | |
| 4094 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 4095 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 4096 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4097 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4098 | rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4099 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 4100 | tp->cp_cmd |= RTL_R16(CPlusCmd) | PktCntrDisable | INTT_1; |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4101 | |
| 4102 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 4103 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 4104 | RTL_W16(IntrMitigate, 0x5151); |
| 4105 | |
| 4106 | /* Work around for RxFIFO overflow. */ |
Ivan Vecera | b5ba6d1 | 2011-01-27 12:24:11 +0100 | [diff] [blame] | 4107 | if (tp->mac_version == RTL_GIGA_MAC_VER_11 || |
| 4108 | tp->mac_version == RTL_GIGA_MAC_VER_22) { |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 4109 | tp->intr_event |= RxFIFOOver | PCSTimeout; |
| 4110 | tp->intr_event &= ~RxOverflow; |
| 4111 | } |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4112 | |
| 4113 | rtl_set_rx_tx_desc_registers(tp, ioaddr); |
| 4114 | |
Francois Romieu | b836390 | 2008-06-01 12:31:57 +0200 | [diff] [blame] | 4115 | rtl_set_rx_mode(dev); |
| 4116 | |
| 4117 | RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) | |
| 4118 | (InterFrameGap << TxInterFrameGapShift)); |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4119 | |
| 4120 | RTL_R8(IntrMask); |
| 4121 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4122 | switch (tp->mac_version) { |
| 4123 | case RTL_GIGA_MAC_VER_11: |
| 4124 | rtl_hw_start_8168bb(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4125 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4126 | |
| 4127 | case RTL_GIGA_MAC_VER_12: |
| 4128 | case RTL_GIGA_MAC_VER_17: |
| 4129 | rtl_hw_start_8168bef(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4130 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4131 | |
| 4132 | case RTL_GIGA_MAC_VER_18: |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4133 | rtl_hw_start_8168cp_1(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4134 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4135 | |
| 4136 | case RTL_GIGA_MAC_VER_19: |
| 4137 | rtl_hw_start_8168c_1(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4138 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4139 | |
| 4140 | case RTL_GIGA_MAC_VER_20: |
| 4141 | rtl_hw_start_8168c_2(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4142 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4143 | |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4144 | case RTL_GIGA_MAC_VER_21: |
| 4145 | rtl_hw_start_8168c_3(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4146 | break; |
Francois Romieu | 197ff76 | 2008-06-28 13:16:02 +0200 | [diff] [blame] | 4147 | |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4148 | case RTL_GIGA_MAC_VER_22: |
| 4149 | rtl_hw_start_8168c_4(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4150 | break; |
Francois Romieu | 6fb0705 | 2008-06-29 11:54:28 +0200 | [diff] [blame] | 4151 | |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4152 | case RTL_GIGA_MAC_VER_23: |
| 4153 | rtl_hw_start_8168cp_2(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4154 | break; |
Francois Romieu | ef3386f | 2008-06-29 12:24:30 +0200 | [diff] [blame] | 4155 | |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4156 | case RTL_GIGA_MAC_VER_24: |
| 4157 | rtl_hw_start_8168cp_3(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4158 | break; |
Francois Romieu | 7f3e3d3 | 2008-07-20 18:53:20 +0200 | [diff] [blame] | 4159 | |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4160 | case RTL_GIGA_MAC_VER_25: |
françois romieu | daf9df6 | 2009-10-07 12:44:20 +0000 | [diff] [blame] | 4161 | case RTL_GIGA_MAC_VER_26: |
| 4162 | case RTL_GIGA_MAC_VER_27: |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4163 | rtl_hw_start_8168d(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4164 | break; |
Francois Romieu | 5b538df | 2008-07-20 16:22:45 +0200 | [diff] [blame] | 4165 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4166 | case RTL_GIGA_MAC_VER_28: |
| 4167 | rtl_hw_start_8168d_4(ioaddr, pdev); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4168 | break; |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4169 | |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4170 | case RTL_GIGA_MAC_VER_31: |
| 4171 | rtl_hw_start_8168dp(ioaddr, pdev); |
| 4172 | break; |
| 4173 | |
hayeswang | 01dc7fe | 2011-03-21 01:50:28 +0000 | [diff] [blame] | 4174 | case RTL_GIGA_MAC_VER_32: |
| 4175 | case RTL_GIGA_MAC_VER_33: |
| 4176 | rtl_hw_start_8168e(ioaddr, pdev); |
| 4177 | break; |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4178 | |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4179 | default: |
| 4180 | printk(KERN_ERR PFX "%s: unknown chipset (mac_version = %d).\n", |
| 4181 | dev->name, tp->mac_version); |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 4182 | break; |
Francois Romieu | 219a1e9 | 2008-06-28 11:58:39 +0200 | [diff] [blame] | 4183 | } |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4184 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 4185 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 4186 | |
Francois Romieu | b836390 | 2008-06-01 12:31:57 +0200 | [diff] [blame] | 4187 | RTL_W8(Cfg9346, Cfg9346_Lock); |
| 4188 | |
Francois Romieu | 2dd9953 | 2007-06-11 23:22:52 +0200 | [diff] [blame] | 4189 | RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4190 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 4191 | RTL_W16(IntrMask, tp->intr_event); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4192 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4193 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4194 | #define R810X_CPCMD_QUIRK_MASK (\ |
| 4195 | EnableBist | \ |
| 4196 | Mac_dbgo_oe | \ |
| 4197 | Force_half_dup | \ |
françois romieu | 5edcc53 | 2009-08-10 19:41:52 +0000 | [diff] [blame] | 4198 | Force_rxflow_en | \ |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4199 | Force_txflow_en | \ |
| 4200 | Cxpl_dbg_sel | \ |
| 4201 | ASF | \ |
| 4202 | PktCntrDisable | \ |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 4203 | Mac_dbgo_sel) |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4204 | |
| 4205 | static void rtl_hw_start_8102e_1(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4206 | { |
Alexey Dobriyan | 350f759 | 2009-11-25 15:54:21 -0800 | [diff] [blame] | 4207 | static const struct ephy_info e_info_8102e_1[] = { |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4208 | { 0x01, 0, 0x6e65 }, |
| 4209 | { 0x02, 0, 0x091f }, |
| 4210 | { 0x03, 0, 0xc2f9 }, |
| 4211 | { 0x06, 0, 0xafb5 }, |
| 4212 | { 0x07, 0, 0x0e00 }, |
| 4213 | { 0x19, 0, 0xec80 }, |
| 4214 | { 0x01, 0, 0x2e65 }, |
| 4215 | { 0x01, 0, 0x6e65 } |
| 4216 | }; |
| 4217 | u8 cfg1; |
| 4218 | |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4219 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4220 | |
| 4221 | RTL_W8(DBG_REG, FIX_NAK_1); |
| 4222 | |
| 4223 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4224 | |
| 4225 | RTL_W8(Config1, |
| 4226 | LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable); |
| 4227 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
| 4228 | |
| 4229 | cfg1 = RTL_R8(Config1); |
| 4230 | if ((cfg1 & LEDS0) && (cfg1 & LEDS1)) |
| 4231 | RTL_W8(Config1, cfg1 & ~LEDS0); |
| 4232 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4233 | rtl_ephy_init(ioaddr, e_info_8102e_1, ARRAY_SIZE(e_info_8102e_1)); |
| 4234 | } |
| 4235 | |
| 4236 | static void rtl_hw_start_8102e_2(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4237 | { |
françois romieu | 650e8d5 | 2011-01-03 15:08:29 +0000 | [diff] [blame] | 4238 | rtl_csi_access_enable_2(ioaddr); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4239 | |
| 4240 | rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
| 4241 | |
| 4242 | RTL_W8(Config1, MEMMAP | IOMAP | VPD | PMEnable); |
| 4243 | RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4244 | } |
| 4245 | |
| 4246 | static void rtl_hw_start_8102e_3(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4247 | { |
| 4248 | rtl_hw_start_8102e_2(ioaddr, pdev); |
| 4249 | |
| 4250 | rtl_ephy_write(ioaddr, 0x03, 0xc2f9); |
| 4251 | } |
| 4252 | |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4253 | static void rtl_hw_start_8105e_1(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4254 | { |
| 4255 | static const struct ephy_info e_info_8105e_1[] = { |
| 4256 | { 0x07, 0, 0x4000 }, |
| 4257 | { 0x19, 0, 0x0200 }, |
| 4258 | { 0x19, 0, 0x0020 }, |
| 4259 | { 0x1e, 0, 0x2000 }, |
| 4260 | { 0x03, 0, 0x0001 }, |
| 4261 | { 0x19, 0, 0x0100 }, |
| 4262 | { 0x19, 0, 0x0004 }, |
| 4263 | { 0x0a, 0, 0x0020 } |
| 4264 | }; |
| 4265 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4266 | /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4267 | RTL_W32(FuncEvent, RTL_R32(FuncEvent) | 0x002800); |
| 4268 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4269 | /* Disable Early Tally Counter */ |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4270 | RTL_W32(FuncEvent, RTL_R32(FuncEvent) & ~0x010000); |
| 4271 | |
| 4272 | RTL_W8(MCU, RTL_R8(MCU) | EN_NDP | EN_OOB_RESET); |
| 4273 | RTL_W8(DLLPR, RTL_R8(DLLPR) | PM_SWITCH); |
| 4274 | |
| 4275 | rtl_ephy_init(ioaddr, e_info_8105e_1, ARRAY_SIZE(e_info_8105e_1)); |
| 4276 | } |
| 4277 | |
| 4278 | static void rtl_hw_start_8105e_2(void __iomem *ioaddr, struct pci_dev *pdev) |
| 4279 | { |
| 4280 | rtl_hw_start_8105e_1(ioaddr, pdev); |
| 4281 | rtl_ephy_write(ioaddr, 0x1e, rtl_ephy_read(ioaddr, 0x1e) | 0x8000); |
| 4282 | } |
| 4283 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4284 | static void rtl_hw_start_8101(struct net_device *dev) |
| 4285 | { |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 4286 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4287 | void __iomem *ioaddr = tp->mmio_addr; |
| 4288 | struct pci_dev *pdev = tp->pci_dev; |
| 4289 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4290 | if (tp->mac_version == RTL_GIGA_MAC_VER_13 || |
| 4291 | tp->mac_version == RTL_GIGA_MAC_VER_16) { |
Francois Romieu | 9c14cea | 2008-07-05 00:21:15 +0200 | [diff] [blame] | 4292 | int cap = tp->pcie_cap; |
| 4293 | |
| 4294 | if (cap) { |
| 4295 | pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, |
| 4296 | PCI_EXP_DEVCTL_NOSNOOP_EN); |
| 4297 | } |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 4298 | } |
| 4299 | |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 4300 | RTL_W8(Cfg9346, Cfg9346_Unlock); |
| 4301 | |
Francois Romieu | 2857ffb | 2008-08-02 21:08:49 +0200 | [diff] [blame] | 4302 | switch (tp->mac_version) { |
| 4303 | case RTL_GIGA_MAC_VER_07: |
| 4304 | rtl_hw_start_8102e_1(ioaddr, pdev); |
| 4305 | break; |
| 4306 | |
| 4307 | case RTL_GIGA_MAC_VER_08: |
| 4308 | rtl_hw_start_8102e_3(ioaddr, pdev); |
| 4309 | break; |
| 4310 | |
| 4311 | case RTL_GIGA_MAC_VER_09: |
| 4312 | rtl_hw_start_8102e_2(ioaddr, pdev); |
| 4313 | break; |
Hayes Wang | 5a5e444 | 2011-02-22 17:26:21 +0800 | [diff] [blame] | 4314 | |
| 4315 | case RTL_GIGA_MAC_VER_29: |
| 4316 | rtl_hw_start_8105e_1(ioaddr, pdev); |
| 4317 | break; |
| 4318 | case RTL_GIGA_MAC_VER_30: |
| 4319 | rtl_hw_start_8105e_2(ioaddr, pdev); |
| 4320 | break; |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 4321 | } |
| 4322 | |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 4323 | RTL_W8(Cfg9346, Cfg9346_Lock); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 4324 | |
françois romieu | f0298f8 | 2011-01-03 15:07:42 +0000 | [diff] [blame] | 4325 | RTL_W8(MaxTxPacketSize, TxPacketMax); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 4326 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4327 | rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 4328 | |
Hayes Wang | d24e9aa | 2011-02-22 17:26:19 +0800 | [diff] [blame] | 4329 | tp->cp_cmd &= ~R810X_CPCMD_QUIRK_MASK; |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 4330 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 4331 | |
| 4332 | RTL_W16(IntrMitigate, 0x0000); |
| 4333 | |
| 4334 | rtl_set_rx_tx_desc_registers(tp, ioaddr); |
| 4335 | |
| 4336 | RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
| 4337 | rtl_set_rx_tx_config_registers(tp); |
| 4338 | |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 4339 | RTL_R8(IntrMask); |
| 4340 | |
Francois Romieu | cdf1a60 | 2007-06-11 23:29:50 +0200 | [diff] [blame] | 4341 | rtl_set_rx_mode(dev); |
| 4342 | |
| 4343 | RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000); |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4344 | |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 4345 | RTL_W16(IntrMask, tp->intr_event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4346 | } |
| 4347 | |
| 4348 | static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) |
| 4349 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4350 | if (new_mtu < ETH_ZLEN || new_mtu > SafeMtu) |
| 4351 | return -EINVAL; |
| 4352 | |
| 4353 | dev->mtu = new_mtu; |
Michał Mirosław | 350fb32 | 2011-04-08 06:35:56 +0000 | [diff] [blame] | 4354 | netdev_update_features(dev); |
| 4355 | |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 4356 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4357 | } |
| 4358 | |
| 4359 | static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc) |
| 4360 | { |
Al Viro | 95e0918 | 2007-12-22 18:55:39 +0000 | [diff] [blame] | 4361 | desc->addr = cpu_to_le64(0x0badbadbadbadbadull); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4362 | desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask); |
| 4363 | } |
| 4364 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4365 | static void rtl8169_free_rx_databuff(struct rtl8169_private *tp, |
| 4366 | void **data_buff, struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4367 | { |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4368 | 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] | 4369 | DMA_FROM_DEVICE); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4370 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4371 | kfree(*data_buff); |
| 4372 | *data_buff = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4373 | rtl8169_make_unusable_by_asic(desc); |
| 4374 | } |
| 4375 | |
| 4376 | static inline void rtl8169_mark_to_asic(struct RxDesc *desc, u32 rx_buf_sz) |
| 4377 | { |
| 4378 | u32 eor = le32_to_cpu(desc->opts1) & RingEnd; |
| 4379 | |
| 4380 | desc->opts1 = cpu_to_le32(DescOwn | eor | rx_buf_sz); |
| 4381 | } |
| 4382 | |
| 4383 | static inline void rtl8169_map_to_asic(struct RxDesc *desc, dma_addr_t mapping, |
| 4384 | u32 rx_buf_sz) |
| 4385 | { |
| 4386 | desc->addr = cpu_to_le64(mapping); |
| 4387 | wmb(); |
| 4388 | rtl8169_mark_to_asic(desc, rx_buf_sz); |
| 4389 | } |
| 4390 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4391 | static inline void *rtl8169_align(void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4392 | { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4393 | return (void *)ALIGN((long)data, 16); |
| 4394 | } |
| 4395 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 4396 | static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp, |
| 4397 | struct RxDesc *desc) |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4398 | { |
| 4399 | void *data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4400 | dma_addr_t mapping; |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4401 | struct device *d = &tp->pci_dev->dev; |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 4402 | struct net_device *dev = tp->dev; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4403 | int node = dev->dev.parent ? dev_to_node(dev->dev.parent) : -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4404 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4405 | data = kmalloc_node(rx_buf_sz, GFP_KERNEL, node); |
| 4406 | if (!data) |
| 4407 | return NULL; |
Francois Romieu | e9f63f3 | 2007-02-28 23:16:57 +0100 | [diff] [blame] | 4408 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4409 | if (rtl8169_align(data) != data) { |
| 4410 | kfree(data); |
| 4411 | data = kmalloc_node(rx_buf_sz + 15, GFP_KERNEL, node); |
| 4412 | if (!data) |
| 4413 | return NULL; |
| 4414 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4415 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4416 | mapping = dma_map_single(d, rtl8169_align(data), rx_buf_sz, |
Stanislaw Gruszka | 231aee6 | 2010-10-20 22:25:38 +0000 | [diff] [blame] | 4417 | DMA_FROM_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 4418 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 4419 | if (net_ratelimit()) |
| 4420 | netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4421 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 4422 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4423 | |
| 4424 | rtl8169_map_to_asic(desc, mapping, rx_buf_sz); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4425 | return data; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4426 | |
| 4427 | err_out: |
| 4428 | kfree(data); |
| 4429 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4430 | } |
| 4431 | |
| 4432 | static void rtl8169_rx_clear(struct rtl8169_private *tp) |
| 4433 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 4434 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4435 | |
| 4436 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4437 | if (tp->Rx_databuff[i]) { |
| 4438 | rtl8169_free_rx_databuff(tp, tp->Rx_databuff + i, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4439 | tp->RxDescArray + i); |
| 4440 | } |
| 4441 | } |
| 4442 | } |
| 4443 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 4444 | static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4445 | { |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 4446 | desc->opts1 |= cpu_to_le32(RingEnd); |
| 4447 | } |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 4448 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 4449 | static int rtl8169_rx_fill(struct rtl8169_private *tp) |
| 4450 | { |
| 4451 | unsigned int i; |
| 4452 | |
| 4453 | for (i = 0; i < NUM_RX_DESC; i++) { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4454 | void *data; |
Francois Romieu | 4ae47c2 | 2007-06-16 23:28:45 +0200 | [diff] [blame] | 4455 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4456 | if (tp->Rx_databuff[i]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4457 | continue; |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 4458 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 4459 | data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4460 | if (!data) { |
| 4461 | rtl8169_make_unusable_by_asic(tp->RxDescArray + i); |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 4462 | goto err_out; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4463 | } |
| 4464 | tp->Rx_databuff[i] = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4465 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4466 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 4467 | rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1); |
| 4468 | return 0; |
| 4469 | |
| 4470 | err_out: |
| 4471 | rtl8169_rx_clear(tp); |
| 4472 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4473 | } |
| 4474 | |
| 4475 | static void rtl8169_init_ring_indexes(struct rtl8169_private *tp) |
| 4476 | { |
| 4477 | tp->dirty_tx = tp->dirty_rx = tp->cur_tx = tp->cur_rx = 0; |
| 4478 | } |
| 4479 | |
| 4480 | static int rtl8169_init_ring(struct net_device *dev) |
| 4481 | { |
| 4482 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4483 | |
| 4484 | rtl8169_init_ring_indexes(tp); |
| 4485 | |
| 4486 | memset(tp->tx_skb, 0x0, NUM_TX_DESC * sizeof(struct ring_info)); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4487 | memset(tp->Rx_databuff, 0x0, NUM_RX_DESC * sizeof(void *)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4488 | |
Stanislaw Gruszka | 0ecbe1c | 2010-10-20 22:25:37 +0000 | [diff] [blame] | 4489 | return rtl8169_rx_fill(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4490 | } |
| 4491 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4492 | 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] | 4493 | struct TxDesc *desc) |
| 4494 | { |
| 4495 | unsigned int len = tx_skb->len; |
| 4496 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4497 | dma_unmap_single(d, le64_to_cpu(desc->addr), len, DMA_TO_DEVICE); |
| 4498 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4499 | desc->opts1 = 0x00; |
| 4500 | desc->opts2 = 0x00; |
| 4501 | desc->addr = 0x00; |
| 4502 | tx_skb->len = 0; |
| 4503 | } |
| 4504 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4505 | static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, |
| 4506 | unsigned int n) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4507 | { |
| 4508 | unsigned int i; |
| 4509 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4510 | for (i = 0; i < n; i++) { |
| 4511 | unsigned int entry = (start + i) % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4512 | struct ring_info *tx_skb = tp->tx_skb + entry; |
| 4513 | unsigned int len = tx_skb->len; |
| 4514 | |
| 4515 | if (len) { |
| 4516 | struct sk_buff *skb = tx_skb->skb; |
| 4517 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4518 | rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4519 | tp->TxDescArray + entry); |
| 4520 | if (skb) { |
Stanislaw Gruszka | cac4b22 | 2010-10-20 22:25:40 +0000 | [diff] [blame] | 4521 | tp->dev->stats.tx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4522 | dev_kfree_skb(skb); |
| 4523 | tx_skb->skb = NULL; |
| 4524 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4525 | } |
| 4526 | } |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4527 | } |
| 4528 | |
| 4529 | static void rtl8169_tx_clear(struct rtl8169_private *tp) |
| 4530 | { |
| 4531 | rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4532 | tp->cur_tx = tp->dirty_tx = 0; |
| 4533 | } |
| 4534 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4535 | 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] | 4536 | { |
| 4537 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4538 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4539 | PREPARE_DELAYED_WORK(&tp->task, task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4540 | schedule_delayed_work(&tp->task, 4); |
| 4541 | } |
| 4542 | |
| 4543 | static void rtl8169_wait_for_quiescence(struct net_device *dev) |
| 4544 | { |
| 4545 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4546 | void __iomem *ioaddr = tp->mmio_addr; |
| 4547 | |
| 4548 | synchronize_irq(dev->irq); |
| 4549 | |
| 4550 | /* Wait for any pending NAPI task to complete */ |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 4551 | napi_disable(&tp->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4552 | |
| 4553 | rtl8169_irq_mask_and_ack(ioaddr); |
| 4554 | |
David S. Miller | d1d08d1 | 2008-01-07 20:53:33 -0800 | [diff] [blame] | 4555 | tp->intr_mask = 0xffff; |
| 4556 | RTL_W16(IntrMask, tp->intr_event); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 4557 | napi_enable(&tp->napi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4558 | } |
| 4559 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4560 | static void rtl8169_reinit_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4561 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4562 | struct rtl8169_private *tp = |
| 4563 | container_of(work, struct rtl8169_private, task.work); |
| 4564 | struct net_device *dev = tp->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4565 | int ret; |
| 4566 | |
Francois Romieu | eb2a021 | 2007-02-15 23:37:21 +0100 | [diff] [blame] | 4567 | rtnl_lock(); |
| 4568 | |
| 4569 | if (!netif_running(dev)) |
| 4570 | goto out_unlock; |
| 4571 | |
| 4572 | rtl8169_wait_for_quiescence(dev); |
| 4573 | rtl8169_close(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4574 | |
| 4575 | ret = rtl8169_open(dev); |
| 4576 | if (unlikely(ret < 0)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 4577 | if (net_ratelimit()) |
| 4578 | netif_err(tp, drv, dev, |
| 4579 | "reinit failure (status = %d). Rescheduling\n", |
| 4580 | ret); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4581 | rtl8169_schedule_work(dev, rtl8169_reinit_task); |
| 4582 | } |
Francois Romieu | eb2a021 | 2007-02-15 23:37:21 +0100 | [diff] [blame] | 4583 | |
| 4584 | out_unlock: |
| 4585 | rtnl_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4586 | } |
| 4587 | |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4588 | static void rtl8169_reset_task(struct work_struct *work) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4589 | { |
David Howells | c402895 | 2006-11-22 14:57:56 +0000 | [diff] [blame] | 4590 | struct rtl8169_private *tp = |
| 4591 | container_of(work, struct rtl8169_private, task.work); |
| 4592 | struct net_device *dev = tp->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4593 | |
Francois Romieu | eb2a021 | 2007-02-15 23:37:21 +0100 | [diff] [blame] | 4594 | rtnl_lock(); |
| 4595 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4596 | if (!netif_running(dev)) |
Francois Romieu | eb2a021 | 2007-02-15 23:37:21 +0100 | [diff] [blame] | 4597 | goto out_unlock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4598 | |
| 4599 | rtl8169_wait_for_quiescence(dev); |
| 4600 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 4601 | rtl8169_rx_interrupt(dev, tp, tp->mmio_addr, ~(u32)0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4602 | rtl8169_tx_clear(tp); |
| 4603 | |
| 4604 | if (tp->dirty_rx == tp->cur_rx) { |
| 4605 | rtl8169_init_ring_indexes(tp); |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 4606 | rtl_hw_start(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4607 | netif_wake_queue(dev); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 4608 | rtl8169_check_link_status(dev, tp, tp->mmio_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4609 | } else { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 4610 | if (net_ratelimit()) |
| 4611 | netif_emerg(tp, intr, dev, "Rx buffers shortage\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4612 | rtl8169_schedule_work(dev, rtl8169_reset_task); |
| 4613 | } |
Francois Romieu | eb2a021 | 2007-02-15 23:37:21 +0100 | [diff] [blame] | 4614 | |
| 4615 | out_unlock: |
| 4616 | rtnl_unlock(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4617 | } |
| 4618 | |
| 4619 | static void rtl8169_tx_timeout(struct net_device *dev) |
| 4620 | { |
| 4621 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4622 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4623 | rtl8169_hw_reset(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4624 | |
| 4625 | /* Let's wait a bit while any (async) irq lands on */ |
| 4626 | rtl8169_schedule_work(dev, rtl8169_reset_task); |
| 4627 | } |
| 4628 | |
| 4629 | 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] | 4630 | u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4631 | { |
| 4632 | struct skb_shared_info *info = skb_shinfo(skb); |
| 4633 | unsigned int cur_frag, entry; |
Jeff Garzik | a6343af | 2007-07-17 05:39:58 -0400 | [diff] [blame] | 4634 | struct TxDesc * uninitialized_var(txd); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4635 | struct device *d = &tp->pci_dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4636 | |
| 4637 | entry = tp->cur_tx; |
| 4638 | for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { |
| 4639 | skb_frag_t *frag = info->frags + cur_frag; |
| 4640 | dma_addr_t mapping; |
| 4641 | u32 status, len; |
| 4642 | void *addr; |
| 4643 | |
| 4644 | entry = (entry + 1) % NUM_TX_DESC; |
| 4645 | |
| 4646 | txd = tp->TxDescArray + entry; |
| 4647 | len = frag->size; |
| 4648 | addr = ((void *) page_address(frag->page)) + frag->page_offset; |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4649 | mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 4650 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 4651 | if (net_ratelimit()) |
| 4652 | netif_err(tp, drv, tp->dev, |
| 4653 | "Failed to map TX fragments DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4654 | goto err_out; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 4655 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4656 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4657 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 4658 | status = opts[0] | len | |
| 4659 | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4660 | |
| 4661 | txd->opts1 = cpu_to_le32(status); |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 4662 | txd->opts2 = cpu_to_le32(opts[1]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4663 | txd->addr = cpu_to_le64(mapping); |
| 4664 | |
| 4665 | tp->tx_skb[entry].len = len; |
| 4666 | } |
| 4667 | |
| 4668 | if (cur_frag) { |
| 4669 | tp->tx_skb[entry].skb = skb; |
| 4670 | txd->opts1 |= cpu_to_le32(LastFrag); |
| 4671 | } |
| 4672 | |
| 4673 | return cur_frag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4674 | |
| 4675 | err_out: |
| 4676 | rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag); |
| 4677 | return -EIO; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4678 | } |
| 4679 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 4680 | static inline void rtl8169_tso_csum(struct rtl8169_private *tp, |
| 4681 | struct sk_buff *skb, u32 *opts) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4682 | { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 4683 | 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] | 4684 | u32 mss = skb_shinfo(skb)->gso_size; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 4685 | int offset = info->opts_offset; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4686 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 4687 | if (mss) { |
| 4688 | opts[0] |= TD_LSO; |
| 4689 | opts[offset] |= min(mss, TD_MSS_MAX) << info->mss_shift; |
| 4690 | } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Arnaldo Carvalho de Melo | eddc9ec | 2007-04-20 22:47:35 -0700 | [diff] [blame] | 4691 | const struct iphdr *ip = ip_hdr(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4692 | |
| 4693 | if (ip->protocol == IPPROTO_TCP) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 4694 | opts[offset] |= info->checksum.tcp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4695 | else if (ip->protocol == IPPROTO_UDP) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 4696 | opts[offset] |= info->checksum.udp; |
| 4697 | else |
| 4698 | WARN_ON_ONCE(1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4699 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4700 | } |
| 4701 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 4702 | static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
| 4703 | struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4704 | { |
| 4705 | struct rtl8169_private *tp = netdev_priv(dev); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4706 | unsigned int entry = tp->cur_tx % NUM_TX_DESC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4707 | struct TxDesc *txd = tp->TxDescArray + entry; |
| 4708 | void __iomem *ioaddr = tp->mmio_addr; |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4709 | struct device *d = &tp->pci_dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4710 | dma_addr_t mapping; |
| 4711 | u32 status, len; |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 4712 | u32 opts[2]; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4713 | int frags; |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 4714 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4715 | if (unlikely(TX_BUFFS_AVAIL(tp) < skb_shinfo(skb)->nr_frags)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 4716 | 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] | 4717 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4718 | } |
| 4719 | |
| 4720 | if (unlikely(le32_to_cpu(txd->opts1) & DescOwn)) |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4721 | goto err_stop_0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4722 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4723 | len = skb_headlen(skb); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4724 | mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE); |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 4725 | if (unlikely(dma_mapping_error(d, mapping))) { |
| 4726 | if (net_ratelimit()) |
| 4727 | netif_err(tp, drv, dev, "Failed to map TX DMA!\n"); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4728 | goto err_dma_0; |
Stanislaw Gruszka | d827d86 | 2010-10-20 22:25:43 +0000 | [diff] [blame] | 4729 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4730 | |
| 4731 | tp->tx_skb[entry].len = len; |
| 4732 | txd->addr = cpu_to_le64(mapping); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4733 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 4734 | opts[1] = cpu_to_le32(rtl8169_tx_vlan_tag(tp, skb)); |
| 4735 | opts[0] = DescOwn; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4736 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 4737 | rtl8169_tso_csum(tp, skb, opts); |
| 4738 | |
| 4739 | frags = rtl8169_xmit_frags(tp, skb, opts); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4740 | if (frags < 0) |
| 4741 | goto err_dma_1; |
| 4742 | else if (frags) |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 4743 | opts[0] |= FirstFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4744 | else { |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 4745 | opts[0] |= FirstFrag | LastFrag; |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4746 | tp->tx_skb[entry].skb = skb; |
| 4747 | } |
| 4748 | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 4749 | txd->opts2 = cpu_to_le32(opts[1]); |
| 4750 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4751 | wmb(); |
| 4752 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4753 | /* Anti gcc 2.95.3 bugware (sic) */ |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 4754 | status = opts[0] | len | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4755 | txd->opts1 = cpu_to_le32(status); |
| 4756 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4757 | tp->cur_tx += frags + 1; |
| 4758 | |
David Dillow | 4c020a9 | 2010-03-03 16:33:10 +0000 | [diff] [blame] | 4759 | wmb(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4760 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 4761 | RTL_W8(TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4762 | |
| 4763 | if (TX_BUFFS_AVAIL(tp) < MAX_SKB_FRAGS) { |
| 4764 | netif_stop_queue(dev); |
| 4765 | smp_rmb(); |
| 4766 | if (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS) |
| 4767 | netif_wake_queue(dev); |
| 4768 | } |
| 4769 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 4770 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4771 | |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4772 | err_dma_1: |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4773 | rtl8169_unmap_tx_skb(d, tp->tx_skb + entry, txd); |
Stanislaw Gruszka | 3eafe50 | 2010-10-20 22:25:36 +0000 | [diff] [blame] | 4774 | err_dma_0: |
| 4775 | dev_kfree_skb(skb); |
| 4776 | dev->stats.tx_dropped++; |
| 4777 | return NETDEV_TX_OK; |
| 4778 | |
| 4779 | err_stop_0: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4780 | netif_stop_queue(dev); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 4781 | dev->stats.tx_dropped++; |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 4782 | return NETDEV_TX_BUSY; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4783 | } |
| 4784 | |
| 4785 | static void rtl8169_pcierr_interrupt(struct net_device *dev) |
| 4786 | { |
| 4787 | struct rtl8169_private *tp = netdev_priv(dev); |
| 4788 | struct pci_dev *pdev = tp->pci_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4789 | u16 pci_status, pci_cmd; |
| 4790 | |
| 4791 | pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); |
| 4792 | pci_read_config_word(pdev, PCI_STATUS, &pci_status); |
| 4793 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 4794 | netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n", |
| 4795 | pci_cmd, pci_status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4796 | |
| 4797 | /* |
| 4798 | * The recovery sequence below admits a very elaborated explanation: |
| 4799 | * - it seems to work; |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 4800 | * - I did not see what else could be done; |
| 4801 | * - it makes iop3xx happy. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4802 | * |
| 4803 | * Feel free to adjust to your needs. |
| 4804 | */ |
Francois Romieu | a27993f | 2006-12-18 00:04:19 +0100 | [diff] [blame] | 4805 | if (pdev->broken_parity_status) |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 4806 | pci_cmd &= ~PCI_COMMAND_PARITY; |
| 4807 | else |
| 4808 | pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; |
| 4809 | |
| 4810 | pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4811 | |
| 4812 | pci_write_config_word(pdev, PCI_STATUS, |
| 4813 | pci_status & (PCI_STATUS_DETECTED_PARITY | |
| 4814 | PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT | |
| 4815 | PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT)); |
| 4816 | |
| 4817 | /* The infamous DAC f*ckup only happens at boot time */ |
| 4818 | if ((tp->cp_cmd & PCIDAC) && !tp->dirty_rx && !tp->cur_rx) { |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4819 | void __iomem *ioaddr = tp->mmio_addr; |
| 4820 | |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 4821 | netif_info(tp, intr, dev, "disabling PCI DAC\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4822 | tp->cp_cmd &= ~PCIDAC; |
| 4823 | RTL_W16(CPlusCmd, tp->cp_cmd); |
| 4824 | dev->features &= ~NETIF_F_HIGHDMA; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4825 | } |
| 4826 | |
françois romieu | e6de30d | 2011-01-03 15:08:37 +0000 | [diff] [blame] | 4827 | rtl8169_hw_reset(tp); |
Francois Romieu | d03902b | 2006-11-23 00:00:42 +0100 | [diff] [blame] | 4828 | |
| 4829 | rtl8169_schedule_work(dev, rtl8169_reinit_task); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4830 | } |
| 4831 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 4832 | static void rtl8169_tx_interrupt(struct net_device *dev, |
| 4833 | struct rtl8169_private *tp, |
| 4834 | void __iomem *ioaddr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4835 | { |
| 4836 | unsigned int dirty_tx, tx_left; |
| 4837 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4838 | dirty_tx = tp->dirty_tx; |
| 4839 | smp_rmb(); |
| 4840 | tx_left = tp->cur_tx - dirty_tx; |
| 4841 | |
| 4842 | while (tx_left > 0) { |
| 4843 | unsigned int entry = dirty_tx % NUM_TX_DESC; |
| 4844 | struct ring_info *tx_skb = tp->tx_skb + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4845 | u32 status; |
| 4846 | |
| 4847 | rmb(); |
| 4848 | status = le32_to_cpu(tp->TxDescArray[entry].opts1); |
| 4849 | if (status & DescOwn) |
| 4850 | break; |
| 4851 | |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4852 | rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb, |
| 4853 | tp->TxDescArray + entry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4854 | if (status & LastFrag) { |
Stanislaw Gruszka | cac4b22 | 2010-10-20 22:25:40 +0000 | [diff] [blame] | 4855 | dev->stats.tx_packets++; |
| 4856 | dev->stats.tx_bytes += tx_skb->skb->len; |
Eric Dumazet | 87433bf | 2009-06-09 22:55:53 +0000 | [diff] [blame] | 4857 | dev_kfree_skb(tx_skb->skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4858 | tx_skb->skb = NULL; |
| 4859 | } |
| 4860 | dirty_tx++; |
| 4861 | tx_left--; |
| 4862 | } |
| 4863 | |
| 4864 | if (tp->dirty_tx != dirty_tx) { |
| 4865 | tp->dirty_tx = dirty_tx; |
| 4866 | smp_wmb(); |
| 4867 | if (netif_queue_stopped(dev) && |
| 4868 | (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)) { |
| 4869 | netif_wake_queue(dev); |
| 4870 | } |
Francois Romieu | d78ae2d | 2007-08-26 20:08:19 +0200 | [diff] [blame] | 4871 | /* |
| 4872 | * 8168 hack: TxPoll requests are lost when the Tx packets are |
| 4873 | * too close. Let's kick an extra TxPoll request when a burst |
| 4874 | * of start_xmit activity is detected (if it is not detected, |
| 4875 | * it is slow enough). -- FR |
| 4876 | */ |
| 4877 | smp_rmb(); |
| 4878 | if (tp->cur_tx != dirty_tx) |
| 4879 | RTL_W8(TxPoll, NPQ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4880 | } |
| 4881 | } |
| 4882 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 4883 | static inline int rtl8169_fragmented_frame(u32 status) |
| 4884 | { |
| 4885 | return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag); |
| 4886 | } |
| 4887 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 4888 | static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4889 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4890 | u32 status = opts1 & RxProtoMask; |
| 4891 | |
| 4892 | if (((status == RxProtoTCP) && !(opts1 & TCPFail)) || |
Shan Wei | d5d3ebe | 2010-11-12 00:15:25 +0000 | [diff] [blame] | 4893 | ((status == RxProtoUDP) && !(opts1 & UDPFail))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4894 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 4895 | else |
Eric Dumazet | bc8acf2 | 2010-09-02 13:07:41 -0700 | [diff] [blame] | 4896 | skb_checksum_none_assert(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4897 | } |
| 4898 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4899 | static struct sk_buff *rtl8169_try_rx_copy(void *data, |
| 4900 | struct rtl8169_private *tp, |
| 4901 | int pkt_size, |
| 4902 | dma_addr_t addr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4903 | { |
Stephen Hemminger | b449655 | 2007-06-17 01:06:49 +0200 | [diff] [blame] | 4904 | struct sk_buff *skb; |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4905 | struct device *d = &tp->pci_dev->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4906 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4907 | data = rtl8169_align(data); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4908 | dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE); |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4909 | prefetch(data); |
| 4910 | skb = netdev_alloc_skb_ip_align(tp->dev, pkt_size); |
| 4911 | if (skb) |
| 4912 | memcpy(skb->data, data, pkt_size); |
Stanislaw Gruszka | 48addcc | 2010-10-20 22:25:39 +0000 | [diff] [blame] | 4913 | dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE); |
| 4914 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4915 | return skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4916 | } |
| 4917 | |
Eric Dumazet | 630b943 | 2010-03-31 02:08:31 +0000 | [diff] [blame] | 4918 | /* |
| 4919 | * Warning : rtl8169_rx_interrupt() might be called : |
| 4920 | * 1) from NAPI (softirq) context |
| 4921 | * (polling = 1 : we should call netif_receive_skb()) |
| 4922 | * 2) from process context (rtl8169_reset_task()) |
| 4923 | * (polling = 0 : we must call netif_rx() instead) |
| 4924 | */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 4925 | static int rtl8169_rx_interrupt(struct net_device *dev, |
| 4926 | struct rtl8169_private *tp, |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 4927 | void __iomem *ioaddr, u32 budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4928 | { |
| 4929 | unsigned int cur_rx, rx_left; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4930 | unsigned int count; |
Eric Dumazet | 630b943 | 2010-03-31 02:08:31 +0000 | [diff] [blame] | 4931 | int polling = (budget != ~(u32)0) ? 1 : 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4932 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4933 | cur_rx = tp->cur_rx; |
| 4934 | rx_left = NUM_RX_DESC + tp->dirty_rx - cur_rx; |
Francois Romieu | 865c652 | 2008-05-11 14:51:00 +0200 | [diff] [blame] | 4935 | rx_left = min(rx_left, budget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4936 | |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 4937 | for (; rx_left > 0; rx_left--, cur_rx++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4938 | unsigned int entry = cur_rx % NUM_RX_DESC; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 4939 | struct RxDesc *desc = tp->RxDescArray + entry; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4940 | u32 status; |
| 4941 | |
| 4942 | rmb(); |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 4943 | status = le32_to_cpu(desc->opts1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4944 | |
| 4945 | if (status & DescOwn) |
| 4946 | break; |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 4947 | if (unlikely(status & RxRES)) { |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 4948 | netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n", |
| 4949 | status); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 4950 | dev->stats.rx_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4951 | if (status & (RxRWT | RxRUNT)) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 4952 | dev->stats.rx_length_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4953 | if (status & RxCRC) |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 4954 | dev->stats.rx_crc_errors++; |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 4955 | if (status & RxFOVF) { |
| 4956 | rtl8169_schedule_work(dev, rtl8169_reset_task); |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 4957 | dev->stats.rx_fifo_errors++; |
Francois Romieu | 9dccf61 | 2006-05-14 12:31:17 +0200 | [diff] [blame] | 4958 | } |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4959 | rtl8169_mark_to_asic(desc, rx_buf_sz); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4960 | } else { |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4961 | struct sk_buff *skb; |
Stephen Hemminger | b449655 | 2007-06-17 01:06:49 +0200 | [diff] [blame] | 4962 | dma_addr_t addr = le64_to_cpu(desc->addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4963 | int pkt_size = (status & 0x00001FFF) - 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4964 | |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 4965 | /* |
| 4966 | * The driver does not support incoming fragmented |
| 4967 | * frames. They are seen as a symptom of over-mtu |
| 4968 | * sized frames. |
| 4969 | */ |
| 4970 | if (unlikely(rtl8169_fragmented_frame(status))) { |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 4971 | dev->stats.rx_dropped++; |
| 4972 | dev->stats.rx_length_errors++; |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4973 | rtl8169_mark_to_asic(desc, rx_buf_sz); |
Richard Dawe | 4dcb7d3 | 2005-05-27 21:12:00 +0200 | [diff] [blame] | 4974 | continue; |
Francois Romieu | 126fa4b | 2005-05-12 20:09:17 -0400 | [diff] [blame] | 4975 | } |
| 4976 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 4977 | skb = rtl8169_try_rx_copy(tp->Rx_databuff[entry], |
| 4978 | tp, pkt_size, addr); |
| 4979 | rtl8169_mark_to_asic(desc, rx_buf_sz); |
| 4980 | if (!skb) { |
| 4981 | dev->stats.rx_dropped++; |
| 4982 | continue; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4983 | } |
| 4984 | |
Eric Dumazet | adea1ac7 | 2010-09-05 20:04:05 -0700 | [diff] [blame] | 4985 | rtl8169_rx_csum(skb, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4986 | skb_put(skb, pkt_size); |
| 4987 | skb->protocol = eth_type_trans(skb, dev); |
| 4988 | |
Francois Romieu | 7a8fc77 | 2011-03-01 17:18:33 +0100 | [diff] [blame] | 4989 | rtl8169_rx_vlan_tag(desc, skb); |
| 4990 | |
| 4991 | if (likely(polling)) |
| 4992 | napi_gro_receive(&tp->napi, skb); |
| 4993 | else |
| 4994 | netif_rx(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4995 | |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 4996 | dev->stats.rx_bytes += pkt_size; |
| 4997 | dev->stats.rx_packets++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4998 | } |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 4999 | |
| 5000 | /* Work around for AMD plateform. */ |
Al Viro | 95e0918 | 2007-12-22 18:55:39 +0000 | [diff] [blame] | 5001 | if ((desc->opts2 & cpu_to_le32(0xfffe000)) && |
Francois Romieu | 6dccd16 | 2007-02-13 23:38:05 +0100 | [diff] [blame] | 5002 | (tp->mac_version == RTL_GIGA_MAC_VER_05)) { |
| 5003 | desc->opts2 = 0; |
| 5004 | cur_rx++; |
| 5005 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5006 | } |
| 5007 | |
| 5008 | count = cur_rx - tp->cur_rx; |
| 5009 | tp->cur_rx = cur_rx; |
| 5010 | |
Eric Dumazet | 6f0333b | 2010-10-11 11:17:47 +0000 | [diff] [blame] | 5011 | tp->dirty_rx += count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5012 | |
| 5013 | return count; |
| 5014 | } |
| 5015 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5016 | static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5017 | { |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5018 | struct net_device *dev = dev_instance; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5019 | struct rtl8169_private *tp = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5020 | void __iomem *ioaddr = tp->mmio_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5021 | int handled = 0; |
Francois Romieu | 865c652 | 2008-05-11 14:51:00 +0200 | [diff] [blame] | 5022 | int status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5023 | |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 5024 | /* loop handling interrupts until we have no new ones or |
| 5025 | * we hit a invalid/hotplug case. |
| 5026 | */ |
Francois Romieu | 865c652 | 2008-05-11 14:51:00 +0200 | [diff] [blame] | 5027 | status = RTL_R16(IntrStatus); |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 5028 | while (status && status != 0xffff) { |
| 5029 | handled = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5030 | |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 5031 | /* Handle all of the error cases first. These will reset |
| 5032 | * the chip, so just exit the loop. |
| 5033 | */ |
| 5034 | if (unlikely(!netif_running(dev))) { |
| 5035 | rtl8169_asic_down(ioaddr); |
| 5036 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5037 | } |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 5038 | |
Francois Romieu | 1519e57 | 2011-02-03 12:02:36 +0100 | [diff] [blame] | 5039 | if (unlikely(status & RxFIFOOver)) { |
| 5040 | switch (tp->mac_version) { |
| 5041 | /* Work around for rx fifo overflow */ |
| 5042 | case RTL_GIGA_MAC_VER_11: |
| 5043 | case RTL_GIGA_MAC_VER_22: |
| 5044 | case RTL_GIGA_MAC_VER_26: |
| 5045 | netif_stop_queue(dev); |
| 5046 | rtl8169_tx_timeout(dev); |
| 5047 | goto done; |
Francois Romieu | f60ac8e | 2011-02-03 17:27:52 +0100 | [diff] [blame] | 5048 | /* Testers needed. */ |
| 5049 | case RTL_GIGA_MAC_VER_17: |
| 5050 | case RTL_GIGA_MAC_VER_19: |
| 5051 | case RTL_GIGA_MAC_VER_20: |
| 5052 | case RTL_GIGA_MAC_VER_21: |
| 5053 | case RTL_GIGA_MAC_VER_23: |
| 5054 | case RTL_GIGA_MAC_VER_24: |
| 5055 | case RTL_GIGA_MAC_VER_27: |
| 5056 | case RTL_GIGA_MAC_VER_28: |
hayeswang | 4804b3b | 2011-03-21 01:50:29 +0000 | [diff] [blame] | 5057 | case RTL_GIGA_MAC_VER_31: |
Francois Romieu | 1519e57 | 2011-02-03 12:02:36 +0100 | [diff] [blame] | 5058 | /* Experimental science. Pktgen proof. */ |
| 5059 | case RTL_GIGA_MAC_VER_12: |
| 5060 | case RTL_GIGA_MAC_VER_25: |
| 5061 | if (status == RxFIFOOver) |
| 5062 | goto done; |
| 5063 | break; |
| 5064 | default: |
| 5065 | break; |
| 5066 | } |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 5067 | } |
| 5068 | |
| 5069 | if (unlikely(status & SYSErr)) { |
| 5070 | rtl8169_pcierr_interrupt(dev); |
| 5071 | break; |
| 5072 | } |
| 5073 | |
| 5074 | if (status & LinkChg) |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 5075 | __rtl8169_check_link_status(dev, tp, ioaddr, true); |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 5076 | |
| 5077 | /* We need to see the lastest version of tp->intr_mask to |
| 5078 | * avoid ignoring an MSI interrupt and having to wait for |
| 5079 | * another event which may never come. |
| 5080 | */ |
| 5081 | smp_rmb(); |
| 5082 | if (status & tp->intr_mask & tp->napi_event) { |
| 5083 | RTL_W16(IntrMask, tp->intr_event & ~tp->napi_event); |
| 5084 | tp->intr_mask = ~tp->napi_event; |
| 5085 | |
| 5086 | if (likely(napi_schedule_prep(&tp->napi))) |
| 5087 | __napi_schedule(&tp->napi); |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 5088 | else |
| 5089 | netif_info(tp, intr, dev, |
| 5090 | "interrupt %04x in poll\n", status); |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 5091 | } |
| 5092 | |
| 5093 | /* We only get a new MSI interrupt when all active irq |
| 5094 | * sources on the chip have been acknowledged. So, ack |
| 5095 | * everything we've seen and check if new sources have become |
| 5096 | * active to avoid blocking all interrupts from the chip. |
| 5097 | */ |
| 5098 | RTL_W16(IntrStatus, |
| 5099 | (status & RxFIFOOver) ? (status | RxOverflow) : status); |
| 5100 | status = RTL_R16(IntrStatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5101 | } |
Francois Romieu | 1519e57 | 2011-02-03 12:02:36 +0100 | [diff] [blame] | 5102 | done: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5103 | return IRQ_RETVAL(handled); |
| 5104 | } |
| 5105 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5106 | static int rtl8169_poll(struct napi_struct *napi, int budget) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5107 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5108 | struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); |
| 5109 | struct net_device *dev = tp->dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5110 | void __iomem *ioaddr = tp->mmio_addr; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5111 | int work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5112 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5113 | work_done = rtl8169_rx_interrupt(dev, tp, ioaddr, (u32) budget); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5114 | rtl8169_tx_interrupt(dev, tp, ioaddr); |
| 5115 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5116 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 5117 | napi_complete(napi); |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 5118 | |
| 5119 | /* We need for force the visibility of tp->intr_mask |
| 5120 | * for other CPUs, as we can loose an MSI interrupt |
| 5121 | * and potentially wait for a retransmit timeout if we don't. |
| 5122 | * The posted write to IntrMask is safe, as it will |
| 5123 | * eventually make it to the chip and we won't loose anything |
| 5124 | * until it does. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5125 | */ |
David Dillow | f11a377 | 2009-05-22 15:29:34 +0000 | [diff] [blame] | 5126 | tp->intr_mask = 0xffff; |
David Dillow | 4c020a9 | 2010-03-03 16:33:10 +0000 | [diff] [blame] | 5127 | wmb(); |
Francois Romieu | 0e48515 | 2007-02-20 00:00:26 +0100 | [diff] [blame] | 5128 | RTL_W16(IntrMask, tp->intr_event); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5129 | } |
| 5130 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5131 | return work_done; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5132 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5133 | |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 5134 | static void rtl8169_rx_missed(struct net_device *dev, void __iomem *ioaddr) |
| 5135 | { |
| 5136 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5137 | |
| 5138 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) |
| 5139 | return; |
| 5140 | |
| 5141 | dev->stats.rx_missed_errors += (RTL_R32(RxMissed) & 0xffffff); |
| 5142 | RTL_W32(RxMissed, 0); |
| 5143 | } |
| 5144 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5145 | static void rtl8169_down(struct net_device *dev) |
| 5146 | { |
| 5147 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5148 | void __iomem *ioaddr = tp->mmio_addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5149 | |
| 5150 | rtl8169_delete_timer(dev); |
| 5151 | |
| 5152 | netif_stop_queue(dev); |
| 5153 | |
Stephen Hemminger | 93dd79e | 2007-10-28 17:14:06 +0100 | [diff] [blame] | 5154 | napi_disable(&tp->napi); |
Stephen Hemminger | 93dd79e | 2007-10-28 17:14:06 +0100 | [diff] [blame] | 5155 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5156 | spin_lock_irq(&tp->lock); |
| 5157 | |
| 5158 | rtl8169_asic_down(ioaddr); |
Stanislaw Gruszka | 323bb68 | 2010-10-20 22:25:41 +0000 | [diff] [blame] | 5159 | /* |
| 5160 | * At this point device interrupts can not be enabled in any function, |
| 5161 | * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task, |
| 5162 | * rtl8169_reinit_task) and napi is disabled (rtl8169_poll). |
| 5163 | */ |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 5164 | rtl8169_rx_missed(dev, ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5165 | |
| 5166 | spin_unlock_irq(&tp->lock); |
| 5167 | |
| 5168 | synchronize_irq(dev->irq); |
| 5169 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5170 | /* Give a racing hard_start_xmit a few cycles to complete. */ |
Paul E. McKenney | fbd568a3e | 2005-05-01 08:59:04 -0700 | [diff] [blame] | 5171 | synchronize_sched(); /* FIXME: should this be synchronize_irq()? */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5172 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5173 | rtl8169_tx_clear(tp); |
| 5174 | |
| 5175 | rtl8169_rx_clear(tp); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5176 | |
| 5177 | rtl_pll_power_down(tp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5178 | } |
| 5179 | |
| 5180 | static int rtl8169_close(struct net_device *dev) |
| 5181 | { |
| 5182 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5183 | struct pci_dev *pdev = tp->pci_dev; |
| 5184 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 5185 | pm_runtime_get_sync(&pdev->dev); |
| 5186 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5187 | /* Update counters before going down */ |
Ivan Vecera | 355423d | 2009-02-06 21:49:57 -0800 | [diff] [blame] | 5188 | rtl8169_update_counters(dev); |
| 5189 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5190 | rtl8169_down(dev); |
| 5191 | |
| 5192 | free_irq(dev->irq, dev); |
| 5193 | |
Stanislaw Gruszka | 82553bb | 2010-10-08 04:25:01 +0000 | [diff] [blame] | 5194 | dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
| 5195 | tp->RxPhyAddr); |
| 5196 | dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
| 5197 | tp->TxPhyAddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5198 | tp->TxDescArray = NULL; |
| 5199 | tp->RxDescArray = NULL; |
| 5200 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 5201 | pm_runtime_put_sync(&pdev->dev); |
| 5202 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5203 | return 0; |
| 5204 | } |
| 5205 | |
Francois Romieu | 07ce406 | 2007-02-23 23:36:39 +0100 | [diff] [blame] | 5206 | static void rtl_set_rx_mode(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5207 | { |
| 5208 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5209 | void __iomem *ioaddr = tp->mmio_addr; |
| 5210 | unsigned long flags; |
| 5211 | u32 mc_filter[2]; /* Multicast hash filter */ |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5212 | int rx_mode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5213 | u32 tmp = 0; |
| 5214 | |
| 5215 | if (dev->flags & IFF_PROMISC) { |
| 5216 | /* Unconditionally log net taps. */ |
Joe Perches | bf82c18 | 2010-02-09 11:49:50 +0000 | [diff] [blame] | 5217 | netif_notice(tp, link, dev, "Promiscuous mode enabled\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5218 | rx_mode = |
| 5219 | AcceptBroadcast | AcceptMulticast | AcceptMyPhys | |
| 5220 | AcceptAllPhys; |
| 5221 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
Jiri Pirko | 4cd24ea | 2010-02-08 04:30:35 +0000 | [diff] [blame] | 5222 | } else if ((netdev_mc_count(dev) > multicast_filter_limit) || |
Joe Perches | 8e95a20 | 2009-12-03 07:58:21 +0000 | [diff] [blame] | 5223 | (dev->flags & IFF_ALLMULTI)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5224 | /* Too many to filter perfectly -- accept all multicasts. */ |
| 5225 | rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; |
| 5226 | mc_filter[1] = mc_filter[0] = 0xffffffff; |
| 5227 | } else { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 5228 | struct netdev_hw_addr *ha; |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5229 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5230 | rx_mode = AcceptBroadcast | AcceptMyPhys; |
| 5231 | mc_filter[1] = mc_filter[0] = 0; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 5232 | netdev_for_each_mc_addr(ha, dev) { |
| 5233 | int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5234 | mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); |
| 5235 | rx_mode |= AcceptMulticast; |
| 5236 | } |
| 5237 | } |
| 5238 | |
| 5239 | spin_lock_irqsave(&tp->lock, flags); |
| 5240 | |
| 5241 | tmp = rtl8169_rx_config | rx_mode | |
Francois Romieu | 2b7b431 | 2011-04-18 22:53:24 -0700 | [diff] [blame] | 5242 | (RTL_R32(RxConfig) & RTL_RX_CONFIG_MASK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5243 | |
Francois Romieu | f887cce | 2008-07-17 22:24:18 +0200 | [diff] [blame] | 5244 | if (tp->mac_version > RTL_GIGA_MAC_VER_06) { |
Francois Romieu | 1087f4f | 2007-12-26 22:46:05 +0100 | [diff] [blame] | 5245 | u32 data = mc_filter[0]; |
| 5246 | |
| 5247 | mc_filter[0] = swab32(mc_filter[1]); |
| 5248 | mc_filter[1] = swab32(data); |
Francois Romieu | bcf0bf9 | 2006-07-26 23:14:13 +0200 | [diff] [blame] | 5249 | } |
| 5250 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5251 | RTL_W32(MAR0 + 4, mc_filter[1]); |
Francois Romieu | 78f1cd0 | 2010-03-27 19:35:46 -0700 | [diff] [blame] | 5252 | RTL_W32(MAR0 + 0, mc_filter[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5253 | |
Francois Romieu | 57a9f23 | 2007-06-04 22:10:15 +0200 | [diff] [blame] | 5254 | RTL_W32(RxConfig, tmp); |
| 5255 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5256 | spin_unlock_irqrestore(&tp->lock, flags); |
| 5257 | } |
| 5258 | |
| 5259 | /** |
| 5260 | * rtl8169_get_stats - Get rtl8169 read/write statistics |
| 5261 | * @dev: The Ethernet Device to get statistics for |
| 5262 | * |
| 5263 | * Get TX/RX statistics for rtl8169 |
| 5264 | */ |
| 5265 | static struct net_device_stats *rtl8169_get_stats(struct net_device *dev) |
| 5266 | { |
| 5267 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5268 | void __iomem *ioaddr = tp->mmio_addr; |
| 5269 | unsigned long flags; |
| 5270 | |
| 5271 | if (netif_running(dev)) { |
| 5272 | spin_lock_irqsave(&tp->lock, flags); |
Francois Romieu | 523a609 | 2008-09-10 22:28:56 +0200 | [diff] [blame] | 5273 | rtl8169_rx_missed(dev, ioaddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5274 | spin_unlock_irqrestore(&tp->lock, flags); |
| 5275 | } |
Francois Romieu | 5b0384f | 2006-08-16 16:00:01 +0200 | [diff] [blame] | 5276 | |
Francois Romieu | cebf8cc | 2007-10-18 12:06:54 +0200 | [diff] [blame] | 5277 | return &dev->stats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5278 | } |
| 5279 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5280 | static void rtl8169_net_suspend(struct net_device *dev) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5281 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5282 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5283 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5284 | if (!netif_running(dev)) |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5285 | return; |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5286 | |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5287 | rtl_pll_power_down(tp); |
| 5288 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5289 | netif_device_detach(dev); |
| 5290 | netif_stop_queue(dev); |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5291 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5292 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5293 | #ifdef CONFIG_PM |
| 5294 | |
| 5295 | static int rtl8169_suspend(struct device *device) |
| 5296 | { |
| 5297 | struct pci_dev *pdev = to_pci_dev(device); |
| 5298 | struct net_device *dev = pci_get_drvdata(pdev); |
| 5299 | |
| 5300 | rtl8169_net_suspend(dev); |
Francois Romieu | 1371fa6 | 2007-04-02 23:01:11 +0200 | [diff] [blame] | 5301 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5302 | return 0; |
| 5303 | } |
| 5304 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 5305 | static void __rtl8169_resume(struct net_device *dev) |
| 5306 | { |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5307 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5308 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 5309 | netif_device_attach(dev); |
françois romieu | 065c27c | 2011-01-03 15:08:12 +0000 | [diff] [blame] | 5310 | |
| 5311 | rtl_pll_power_up(tp); |
| 5312 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 5313 | rtl8169_schedule_work(dev, rtl8169_reset_task); |
| 5314 | } |
| 5315 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5316 | static int rtl8169_resume(struct device *device) |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5317 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5318 | struct pci_dev *pdev = to_pci_dev(device); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5319 | struct net_device *dev = pci_get_drvdata(pdev); |
Stanislaw Gruszka | fccec10 | 2010-10-20 22:25:42 +0000 | [diff] [blame] | 5320 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5321 | |
| 5322 | rtl8169_init_phy(dev, tp); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5323 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 5324 | if (netif_running(dev)) |
| 5325 | __rtl8169_resume(dev); |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5326 | |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5327 | return 0; |
| 5328 | } |
| 5329 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 5330 | static int rtl8169_runtime_suspend(struct device *device) |
| 5331 | { |
| 5332 | struct pci_dev *pdev = to_pci_dev(device); |
| 5333 | struct net_device *dev = pci_get_drvdata(pdev); |
| 5334 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5335 | |
| 5336 | if (!tp->TxDescArray) |
| 5337 | return 0; |
| 5338 | |
| 5339 | spin_lock_irq(&tp->lock); |
| 5340 | tp->saved_wolopts = __rtl8169_get_wol(tp); |
| 5341 | __rtl8169_set_wol(tp, WAKE_ANY); |
| 5342 | spin_unlock_irq(&tp->lock); |
| 5343 | |
| 5344 | rtl8169_net_suspend(dev); |
| 5345 | |
| 5346 | return 0; |
| 5347 | } |
| 5348 | |
| 5349 | static int rtl8169_runtime_resume(struct device *device) |
| 5350 | { |
| 5351 | struct pci_dev *pdev = to_pci_dev(device); |
| 5352 | struct net_device *dev = pci_get_drvdata(pdev); |
| 5353 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5354 | |
| 5355 | if (!tp->TxDescArray) |
| 5356 | return 0; |
| 5357 | |
| 5358 | spin_lock_irq(&tp->lock); |
| 5359 | __rtl8169_set_wol(tp, tp->saved_wolopts); |
| 5360 | tp->saved_wolopts = 0; |
| 5361 | spin_unlock_irq(&tp->lock); |
| 5362 | |
Stanislaw Gruszka | fccec10 | 2010-10-20 22:25:42 +0000 | [diff] [blame] | 5363 | rtl8169_init_phy(dev, tp); |
| 5364 | |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 5365 | __rtl8169_resume(dev); |
| 5366 | |
| 5367 | return 0; |
| 5368 | } |
| 5369 | |
| 5370 | static int rtl8169_runtime_idle(struct device *device) |
| 5371 | { |
| 5372 | struct pci_dev *pdev = to_pci_dev(device); |
| 5373 | struct net_device *dev = pci_get_drvdata(pdev); |
| 5374 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5375 | |
Rafael J. Wysocki | e4fbce7 | 2010-12-08 15:32:14 +0000 | [diff] [blame] | 5376 | return tp->TxDescArray ? -EBUSY : 0; |
Rafael J. Wysocki | e175944 | 2010-03-14 14:33:51 +0000 | [diff] [blame] | 5377 | } |
| 5378 | |
Alexey Dobriyan | 4714521 | 2009-12-14 18:00:08 -0800 | [diff] [blame] | 5379 | static const struct dev_pm_ops rtl8169_pm_ops = { |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5380 | .suspend = rtl8169_suspend, |
| 5381 | .resume = rtl8169_resume, |
| 5382 | .freeze = rtl8169_suspend, |
| 5383 | .thaw = rtl8169_resume, |
| 5384 | .poweroff = rtl8169_suspend, |
| 5385 | .restore = rtl8169_resume, |
| 5386 | .runtime_suspend = rtl8169_runtime_suspend, |
| 5387 | .runtime_resume = rtl8169_runtime_resume, |
| 5388 | .runtime_idle = rtl8169_runtime_idle, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5389 | }; |
| 5390 | |
| 5391 | #define RTL8169_PM_OPS (&rtl8169_pm_ops) |
| 5392 | |
| 5393 | #else /* !CONFIG_PM */ |
| 5394 | |
| 5395 | #define RTL8169_PM_OPS NULL |
| 5396 | |
| 5397 | #endif /* !CONFIG_PM */ |
| 5398 | |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 5399 | static void rtl_shutdown(struct pci_dev *pdev) |
| 5400 | { |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5401 | struct net_device *dev = pci_get_drvdata(pdev); |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 5402 | struct rtl8169_private *tp = netdev_priv(dev); |
| 5403 | void __iomem *ioaddr = tp->mmio_addr; |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 5404 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5405 | rtl8169_net_suspend(dev); |
| 5406 | |
Francois Romieu | cecb5fd | 2011-04-01 10:21:07 +0200 | [diff] [blame] | 5407 | /* Restore original MAC address */ |
Ivan Vecera | cc098dc | 2009-11-29 23:12:52 -0800 | [diff] [blame] | 5408 | rtl_rar_set(tp, dev->perm_addr); |
| 5409 | |
françois romieu | 4bb3f52 | 2009-06-17 11:41:45 +0000 | [diff] [blame] | 5410 | spin_lock_irq(&tp->lock); |
| 5411 | |
| 5412 | rtl8169_asic_down(ioaddr); |
| 5413 | |
| 5414 | spin_unlock_irq(&tp->lock); |
| 5415 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5416 | if (system_state == SYSTEM_POWER_OFF) { |
françois romieu | ca52efd | 2009-07-24 12:34:19 +0000 | [diff] [blame] | 5417 | /* WoL fails with some 8168 when the receiver is disabled. */ |
| 5418 | if (tp->features & RTL_FEATURE_WOL) { |
| 5419 | pci_clear_master(pdev); |
| 5420 | |
| 5421 | RTL_W8(ChipCmd, CmdRxEnb); |
| 5422 | /* PCI commit */ |
| 5423 | RTL_R8(ChipCmd); |
| 5424 | } |
| 5425 | |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5426 | pci_wake_from_d3(pdev, true); |
| 5427 | pci_set_power_state(pdev, PCI_D3hot); |
| 5428 | } |
| 5429 | } |
Francois Romieu | 5d06a99 | 2006-02-23 00:47:58 +0100 | [diff] [blame] | 5430 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5431 | static struct pci_driver rtl8169_pci_driver = { |
| 5432 | .name = MODULENAME, |
| 5433 | .id_table = rtl8169_pci_tbl, |
| 5434 | .probe = rtl8169_init_one, |
| 5435 | .remove = __devexit_p(rtl8169_remove_one), |
Francois Romieu | 1765f95 | 2008-09-13 17:21:40 +0200 | [diff] [blame] | 5436 | .shutdown = rtl_shutdown, |
Rafael J. Wysocki | 861ab44 | 2009-04-05 08:40:04 +0000 | [diff] [blame] | 5437 | .driver.pm = RTL8169_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5438 | }; |
| 5439 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5440 | static int __init rtl8169_init_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5441 | { |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 5442 | return pci_register_driver(&rtl8169_pci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5443 | } |
| 5444 | |
Francois Romieu | 07d3f51 | 2007-02-21 22:40:46 +0100 | [diff] [blame] | 5445 | static void __exit rtl8169_cleanup_module(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5446 | { |
| 5447 | pci_unregister_driver(&rtl8169_pci_driver); |
| 5448 | } |
| 5449 | |
| 5450 | module_init(rtl8169_init_module); |
| 5451 | module_exit(rtl8169_cleanup_module); |