|
1 /* |
|
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. |
|
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> |
|
26 #include <linux/pm_runtime.h> |
|
27 |
|
28 #include <asm/system.h> |
|
29 #include <asm/io.h> |
|
30 #include <asm/irq.h> |
|
31 #include "../globals.h" |
|
32 #include "ecdev.h" |
|
33 |
|
34 #define RTL8169_VERSION "2.3LK-NAPI" |
|
35 #define MODULENAME "ec_r8169" |
|
36 #define PFX MODULENAME ": " |
|
37 |
|
38 #ifdef RTL8169_DEBUG |
|
39 #define assert(expr) \ |
|
40 if (!(expr)) { \ |
|
41 printk( "Assertion failed! %s,%s,%s,line=%d\n", \ |
|
42 #expr,__FILE__,__func__,__LINE__); \ |
|
43 } |
|
44 #define dprintk(fmt, args...) \ |
|
45 do { printk(KERN_DEBUG PFX fmt, ## args); } while (0) |
|
46 #else |
|
47 #define assert(expr) do {} while (0) |
|
48 #define dprintk(fmt, args...) do {} while (0) |
|
49 #endif /* RTL8169_DEBUG */ |
|
50 |
|
51 #define R8169_MSG_DEFAULT \ |
|
52 (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN) |
|
53 |
|
54 #define TX_BUFFS_AVAIL(tp) \ |
|
55 (tp->dirty_tx + NUM_TX_DESC - tp->cur_tx - 1) |
|
56 |
|
57 /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). |
|
58 The RTL chips use a 64 element hash table based on the Ethernet CRC. */ |
|
59 static const int multicast_filter_limit = 32; |
|
60 |
|
61 /* MAC address length */ |
|
62 #define MAC_ADDR_LEN 6 |
|
63 |
|
64 #define MAX_READ_REQUEST_SHIFT 12 |
|
65 #define RX_FIFO_THRESH 7 /* 7 means NO threshold, Rx buffer level before first PCI xfer. */ |
|
66 #define RX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */ |
|
67 #define TX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */ |
|
68 #define EarlyTxThld 0x3F /* 0x3F means NO early transmit */ |
|
69 #define SafeMtu 0x1c20 /* ... actually life sucks beyond ~7k */ |
|
70 #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */ |
|
71 |
|
72 #define R8169_REGS_SIZE 256 |
|
73 #define R8169_NAPI_WEIGHT 64 |
|
74 #define NUM_TX_DESC 64 /* Number of Tx descriptor registers */ |
|
75 #define NUM_RX_DESC 256 /* Number of Rx descriptor registers */ |
|
76 #define RX_BUF_SIZE 1536 /* Rx Buffer size */ |
|
77 #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc)) |
|
78 #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc)) |
|
79 |
|
80 #define RTL8169_TX_TIMEOUT (6*HZ) |
|
81 #define RTL8169_PHY_TIMEOUT (10*HZ) |
|
82 |
|
83 #define RTL_EEPROM_SIG cpu_to_le32(0x8129) |
|
84 #define RTL_EEPROM_SIG_MASK cpu_to_le32(0xffff) |
|
85 #define RTL_EEPROM_SIG_ADDR 0x0000 |
|
86 |
|
87 /* write/read MMIO register */ |
|
88 #define RTL_W8(reg, val8) writeb ((val8), ioaddr + (reg)) |
|
89 #define RTL_W16(reg, val16) writew ((val16), ioaddr + (reg)) |
|
90 #define RTL_W32(reg, val32) writel ((val32), ioaddr + (reg)) |
|
91 #define RTL_R8(reg) readb (ioaddr + (reg)) |
|
92 #define RTL_R16(reg) readw (ioaddr + (reg)) |
|
93 #define RTL_R32(reg) readl (ioaddr + (reg)) |
|
94 |
|
95 enum mac_version { |
|
96 RTL_GIGA_MAC_NONE = 0x00, |
|
97 RTL_GIGA_MAC_VER_01 = 0x01, // 8169 |
|
98 RTL_GIGA_MAC_VER_02 = 0x02, // 8169S |
|
99 RTL_GIGA_MAC_VER_03 = 0x03, // 8110S |
|
100 RTL_GIGA_MAC_VER_04 = 0x04, // 8169SB |
|
101 RTL_GIGA_MAC_VER_05 = 0x05, // 8110SCd |
|
102 RTL_GIGA_MAC_VER_06 = 0x06, // 8110SCe |
|
103 RTL_GIGA_MAC_VER_07 = 0x07, // 8102e |
|
104 RTL_GIGA_MAC_VER_08 = 0x08, // 8102e |
|
105 RTL_GIGA_MAC_VER_09 = 0x09, // 8102e |
|
106 RTL_GIGA_MAC_VER_10 = 0x0a, // 8101e |
|
107 RTL_GIGA_MAC_VER_11 = 0x0b, // 8168Bb |
|
108 RTL_GIGA_MAC_VER_12 = 0x0c, // 8168Be |
|
109 RTL_GIGA_MAC_VER_13 = 0x0d, // 8101Eb |
|
110 RTL_GIGA_MAC_VER_14 = 0x0e, // 8101 ? |
|
111 RTL_GIGA_MAC_VER_15 = 0x0f, // 8101 ? |
|
112 RTL_GIGA_MAC_VER_16 = 0x11, // 8101Ec |
|
113 RTL_GIGA_MAC_VER_17 = 0x10, // 8168Bf |
|
114 RTL_GIGA_MAC_VER_18 = 0x12, // 8168CP |
|
115 RTL_GIGA_MAC_VER_19 = 0x13, // 8168C |
|
116 RTL_GIGA_MAC_VER_20 = 0x14, // 8168C |
|
117 RTL_GIGA_MAC_VER_21 = 0x15, // 8168C |
|
118 RTL_GIGA_MAC_VER_22 = 0x16, // 8168C |
|
119 RTL_GIGA_MAC_VER_23 = 0x17, // 8168CP |
|
120 RTL_GIGA_MAC_VER_24 = 0x18, // 8168CP |
|
121 RTL_GIGA_MAC_VER_25 = 0x19, // 8168D |
|
122 RTL_GIGA_MAC_VER_26 = 0x1a, // 8168D |
|
123 RTL_GIGA_MAC_VER_27 = 0x1b // 8168DP |
|
124 }; |
|
125 |
|
126 #define _R(NAME,MAC,MASK) \ |
|
127 { .name = NAME, .mac_version = MAC, .RxConfigMask = MASK } |
|
128 |
|
129 static const struct { |
|
130 const char *name; |
|
131 u8 mac_version; |
|
132 u32 RxConfigMask; /* Clears the bits supported by this chip */ |
|
133 } rtl_chip_info[] = { |
|
134 _R("RTL8169", RTL_GIGA_MAC_VER_01, 0xff7e1880), // 8169 |
|
135 _R("RTL8169s", RTL_GIGA_MAC_VER_02, 0xff7e1880), // 8169S |
|
136 _R("RTL8110s", RTL_GIGA_MAC_VER_03, 0xff7e1880), // 8110S |
|
137 _R("RTL8169sb/8110sb", RTL_GIGA_MAC_VER_04, 0xff7e1880), // 8169SB |
|
138 _R("RTL8169sc/8110sc", RTL_GIGA_MAC_VER_05, 0xff7e1880), // 8110SCd |
|
139 _R("RTL8169sc/8110sc", RTL_GIGA_MAC_VER_06, 0xff7e1880), // 8110SCe |
|
140 _R("RTL8102e", RTL_GIGA_MAC_VER_07, 0xff7e1880), // PCI-E |
|
141 _R("RTL8102e", RTL_GIGA_MAC_VER_08, 0xff7e1880), // PCI-E |
|
142 _R("RTL8102e", RTL_GIGA_MAC_VER_09, 0xff7e1880), // PCI-E |
|
143 _R("RTL8101e", RTL_GIGA_MAC_VER_10, 0xff7e1880), // PCI-E |
|
144 _R("RTL8168b/8111b", RTL_GIGA_MAC_VER_11, 0xff7e1880), // PCI-E |
|
145 _R("RTL8168b/8111b", RTL_GIGA_MAC_VER_12, 0xff7e1880), // PCI-E |
|
146 _R("RTL8101e", RTL_GIGA_MAC_VER_13, 0xff7e1880), // PCI-E 8139 |
|
147 _R("RTL8100e", RTL_GIGA_MAC_VER_14, 0xff7e1880), // PCI-E 8139 |
|
148 _R("RTL8100e", RTL_GIGA_MAC_VER_15, 0xff7e1880), // PCI-E 8139 |
|
149 _R("RTL8168b/8111b", RTL_GIGA_MAC_VER_17, 0xff7e1880), // PCI-E |
|
150 _R("RTL8101e", RTL_GIGA_MAC_VER_16, 0xff7e1880), // PCI-E |
|
151 _R("RTL8168cp/8111cp", RTL_GIGA_MAC_VER_18, 0xff7e1880), // PCI-E |
|
152 _R("RTL8168c/8111c", RTL_GIGA_MAC_VER_19, 0xff7e1880), // PCI-E |
|
153 _R("RTL8168c/8111c", RTL_GIGA_MAC_VER_20, 0xff7e1880), // PCI-E |
|
154 _R("RTL8168c/8111c", RTL_GIGA_MAC_VER_21, 0xff7e1880), // PCI-E |
|
155 _R("RTL8168c/8111c", RTL_GIGA_MAC_VER_22, 0xff7e1880), // PCI-E |
|
156 _R("RTL8168cp/8111cp", RTL_GIGA_MAC_VER_23, 0xff7e1880), // PCI-E |
|
157 _R("RTL8168cp/8111cp", RTL_GIGA_MAC_VER_24, 0xff7e1880), // PCI-E |
|
158 _R("RTL8168d/8111d", RTL_GIGA_MAC_VER_25, 0xff7e1880), // PCI-E |
|
159 _R("RTL8168d/8111d", RTL_GIGA_MAC_VER_26, 0xff7e1880), // PCI-E |
|
160 _R("RTL8168dp/8111dp", RTL_GIGA_MAC_VER_27, 0xff7e1880) // PCI-E |
|
161 }; |
|
162 #undef _R |
|
163 |
|
164 enum cfg_version { |
|
165 RTL_CFG_0 = 0x00, |
|
166 RTL_CFG_1, |
|
167 RTL_CFG_2 |
|
168 }; |
|
169 |
|
170 static void rtl_hw_start_8169(struct net_device *); |
|
171 static void rtl_hw_start_8168(struct net_device *); |
|
172 static void rtl_hw_start_8101(struct net_device *); |
|
173 |
|
174 static DEFINE_PCI_DEVICE_TABLE(rtl8169_pci_tbl) = { |
|
175 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 }, |
|
176 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8136), 0, 0, RTL_CFG_2 }, |
|
177 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_0 }, |
|
178 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_1 }, |
|
179 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 }, |
|
180 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4300), 0, 0, RTL_CFG_0 }, |
|
181 { PCI_DEVICE(PCI_VENDOR_ID_AT, 0xc107), 0, 0, RTL_CFG_0 }, |
|
182 { PCI_DEVICE(0x16ec, 0x0116), 0, 0, RTL_CFG_0 }, |
|
183 { PCI_VENDOR_ID_LINKSYS, 0x1032, |
|
184 PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 }, |
|
185 { 0x0001, 0x8168, |
|
186 PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 }, |
|
187 {0,}, |
|
188 }; |
|
189 |
|
190 /* prevent driver from being loaded automatically */ |
|
191 //MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl); |
|
192 |
|
193 /* |
|
194 * we set our copybreak very high so that we don't have |
|
195 * to allocate 16k frames all the time (see note in |
|
196 * rtl8169_open() |
|
197 */ |
|
198 static int rx_copybreak = 16383; |
|
199 static int use_dac; |
|
200 static struct { |
|
201 u32 msg_enable; |
|
202 } debug = { -1 }; |
|
203 |
|
204 enum rtl_registers { |
|
205 MAC0 = 0, /* Ethernet hardware address. */ |
|
206 MAC4 = 4, |
|
207 MAR0 = 8, /* Multicast filter. */ |
|
208 CounterAddrLow = 0x10, |
|
209 CounterAddrHigh = 0x14, |
|
210 TxDescStartAddrLow = 0x20, |
|
211 TxDescStartAddrHigh = 0x24, |
|
212 TxHDescStartAddrLow = 0x28, |
|
213 TxHDescStartAddrHigh = 0x2c, |
|
214 FLASH = 0x30, |
|
215 ERSR = 0x36, |
|
216 ChipCmd = 0x37, |
|
217 TxPoll = 0x38, |
|
218 IntrMask = 0x3c, |
|
219 IntrStatus = 0x3e, |
|
220 TxConfig = 0x40, |
|
221 RxConfig = 0x44, |
|
222 RxMissed = 0x4c, |
|
223 Cfg9346 = 0x50, |
|
224 Config0 = 0x51, |
|
225 Config1 = 0x52, |
|
226 Config2 = 0x53, |
|
227 Config3 = 0x54, |
|
228 Config4 = 0x55, |
|
229 Config5 = 0x56, |
|
230 MultiIntr = 0x5c, |
|
231 PHYAR = 0x60, |
|
232 PHYstatus = 0x6c, |
|
233 RxMaxSize = 0xda, |
|
234 CPlusCmd = 0xe0, |
|
235 IntrMitigate = 0xe2, |
|
236 RxDescAddrLow = 0xe4, |
|
237 RxDescAddrHigh = 0xe8, |
|
238 EarlyTxThres = 0xec, |
|
239 FuncEvent = 0xf0, |
|
240 FuncEventMask = 0xf4, |
|
241 FuncPresetState = 0xf8, |
|
242 FuncForceEvent = 0xfc, |
|
243 }; |
|
244 |
|
245 enum rtl8110_registers { |
|
246 TBICSR = 0x64, |
|
247 TBI_ANAR = 0x68, |
|
248 TBI_LPAR = 0x6a, |
|
249 }; |
|
250 |
|
251 enum rtl8168_8101_registers { |
|
252 CSIDR = 0x64, |
|
253 CSIAR = 0x68, |
|
254 #define CSIAR_FLAG 0x80000000 |
|
255 #define CSIAR_WRITE_CMD 0x80000000 |
|
256 #define CSIAR_BYTE_ENABLE 0x0f |
|
257 #define CSIAR_BYTE_ENABLE_SHIFT 12 |
|
258 #define CSIAR_ADDR_MASK 0x0fff |
|
259 |
|
260 EPHYAR = 0x80, |
|
261 #define EPHYAR_FLAG 0x80000000 |
|
262 #define EPHYAR_WRITE_CMD 0x80000000 |
|
263 #define EPHYAR_REG_MASK 0x1f |
|
264 #define EPHYAR_REG_SHIFT 16 |
|
265 #define EPHYAR_DATA_MASK 0xffff |
|
266 DBG_REG = 0xd1, |
|
267 #define FIX_NAK_1 (1 << 4) |
|
268 #define FIX_NAK_2 (1 << 3) |
|
269 EFUSEAR = 0xdc, |
|
270 #define EFUSEAR_FLAG 0x80000000 |
|
271 #define EFUSEAR_WRITE_CMD 0x80000000 |
|
272 #define EFUSEAR_READ_CMD 0x00000000 |
|
273 #define EFUSEAR_REG_MASK 0x03ff |
|
274 #define EFUSEAR_REG_SHIFT 8 |
|
275 #define EFUSEAR_DATA_MASK 0xff |
|
276 }; |
|
277 |
|
278 enum rtl_register_content { |
|
279 /* InterruptStatusBits */ |
|
280 SYSErr = 0x8000, |
|
281 PCSTimeout = 0x4000, |
|
282 SWInt = 0x0100, |
|
283 TxDescUnavail = 0x0080, |
|
284 RxFIFOOver = 0x0040, |
|
285 LinkChg = 0x0020, |
|
286 RxOverflow = 0x0010, |
|
287 TxErr = 0x0008, |
|
288 TxOK = 0x0004, |
|
289 RxErr = 0x0002, |
|
290 RxOK = 0x0001, |
|
291 |
|
292 /* RxStatusDesc */ |
|
293 RxFOVF = (1 << 23), |
|
294 RxRWT = (1 << 22), |
|
295 RxRES = (1 << 21), |
|
296 RxRUNT = (1 << 20), |
|
297 RxCRC = (1 << 19), |
|
298 |
|
299 /* ChipCmdBits */ |
|
300 CmdReset = 0x10, |
|
301 CmdRxEnb = 0x08, |
|
302 CmdTxEnb = 0x04, |
|
303 RxBufEmpty = 0x01, |
|
304 |
|
305 /* TXPoll register p.5 */ |
|
306 HPQ = 0x80, /* Poll cmd on the high prio queue */ |
|
307 NPQ = 0x40, /* Poll cmd on the low prio queue */ |
|
308 FSWInt = 0x01, /* Forced software interrupt */ |
|
309 |
|
310 /* Cfg9346Bits */ |
|
311 Cfg9346_Lock = 0x00, |
|
312 Cfg9346_Unlock = 0xc0, |
|
313 |
|
314 /* rx_mode_bits */ |
|
315 AcceptErr = 0x20, |
|
316 AcceptRunt = 0x10, |
|
317 AcceptBroadcast = 0x08, |
|
318 AcceptMulticast = 0x04, |
|
319 AcceptMyPhys = 0x02, |
|
320 AcceptAllPhys = 0x01, |
|
321 |
|
322 /* RxConfigBits */ |
|
323 RxCfgFIFOShift = 13, |
|
324 RxCfgDMAShift = 8, |
|
325 |
|
326 /* TxConfigBits */ |
|
327 TxInterFrameGapShift = 24, |
|
328 TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */ |
|
329 |
|
330 /* Config1 register p.24 */ |
|
331 LEDS1 = (1 << 7), |
|
332 LEDS0 = (1 << 6), |
|
333 MSIEnable = (1 << 5), /* Enable Message Signaled Interrupt */ |
|
334 Speed_down = (1 << 4), |
|
335 MEMMAP = (1 << 3), |
|
336 IOMAP = (1 << 2), |
|
337 VPD = (1 << 1), |
|
338 PMEnable = (1 << 0), /* Power Management Enable */ |
|
339 |
|
340 /* Config2 register p. 25 */ |
|
341 PCI_Clock_66MHz = 0x01, |
|
342 PCI_Clock_33MHz = 0x00, |
|
343 |
|
344 /* Config3 register p.25 */ |
|
345 MagicPacket = (1 << 5), /* Wake up when receives a Magic Packet */ |
|
346 LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */ |
|
347 Beacon_en = (1 << 0), /* 8168 only. Reserved in the 8168b */ |
|
348 |
|
349 /* Config5 register p.27 */ |
|
350 BWF = (1 << 6), /* Accept Broadcast wakeup frame */ |
|
351 MWF = (1 << 5), /* Accept Multicast wakeup frame */ |
|
352 UWF = (1 << 4), /* Accept Unicast wakeup frame */ |
|
353 LanWake = (1 << 1), /* LanWake enable/disable */ |
|
354 PMEStatus = (1 << 0), /* PME status can be reset by PCI RST# */ |
|
355 |
|
356 /* TBICSR p.28 */ |
|
357 TBIReset = 0x80000000, |
|
358 TBILoopback = 0x40000000, |
|
359 TBINwEnable = 0x20000000, |
|
360 TBINwRestart = 0x10000000, |
|
361 TBILinkOk = 0x02000000, |
|
362 TBINwComplete = 0x01000000, |
|
363 |
|
364 /* CPlusCmd p.31 */ |
|
365 EnableBist = (1 << 15), // 8168 8101 |
|
366 Mac_dbgo_oe = (1 << 14), // 8168 8101 |
|
367 Normal_mode = (1 << 13), // unused |
|
368 Force_half_dup = (1 << 12), // 8168 8101 |
|
369 Force_rxflow_en = (1 << 11), // 8168 8101 |
|
370 Force_txflow_en = (1 << 10), // 8168 8101 |
|
371 Cxpl_dbg_sel = (1 << 9), // 8168 8101 |
|
372 ASF = (1 << 8), // 8168 8101 |
|
373 PktCntrDisable = (1 << 7), // 8168 8101 |
|
374 Mac_dbgo_sel = 0x001c, // 8168 |
|
375 RxVlan = (1 << 6), |
|
376 RxChkSum = (1 << 5), |
|
377 PCIDAC = (1 << 4), |
|
378 PCIMulRW = (1 << 3), |
|
379 INTT_0 = 0x0000, // 8168 |
|
380 INTT_1 = 0x0001, // 8168 |
|
381 INTT_2 = 0x0002, // 8168 |
|
382 INTT_3 = 0x0003, // 8168 |
|
383 |
|
384 /* rtl8169_PHYstatus */ |
|
385 TBI_Enable = 0x80, |
|
386 TxFlowCtrl = 0x40, |
|
387 RxFlowCtrl = 0x20, |
|
388 _1000bpsF = 0x10, |
|
389 _100bps = 0x08, |
|
390 _10bps = 0x04, |
|
391 LinkStatus = 0x02, |
|
392 FullDup = 0x01, |
|
393 |
|
394 /* _TBICSRBit */ |
|
395 TBILinkOK = 0x02000000, |
|
396 |
|
397 /* DumpCounterCommand */ |
|
398 CounterDump = 0x8, |
|
399 }; |
|
400 |
|
401 enum desc_status_bit { |
|
402 DescOwn = (1 << 31), /* Descriptor is owned by NIC */ |
|
403 RingEnd = (1 << 30), /* End of descriptor ring */ |
|
404 FirstFrag = (1 << 29), /* First segment of a packet */ |
|
405 LastFrag = (1 << 28), /* Final segment of a packet */ |
|
406 |
|
407 /* Tx private */ |
|
408 LargeSend = (1 << 27), /* TCP Large Send Offload (TSO) */ |
|
409 MSSShift = 16, /* MSS value position */ |
|
410 MSSMask = 0xfff, /* MSS value + LargeSend bit: 12 bits */ |
|
411 IPCS = (1 << 18), /* Calculate IP checksum */ |
|
412 UDPCS = (1 << 17), /* Calculate UDP/IP checksum */ |
|
413 TCPCS = (1 << 16), /* Calculate TCP/IP checksum */ |
|
414 TxVlanTag = (1 << 17), /* Add VLAN tag */ |
|
415 |
|
416 /* Rx private */ |
|
417 PID1 = (1 << 18), /* Protocol ID bit 1/2 */ |
|
418 PID0 = (1 << 17), /* Protocol ID bit 2/2 */ |
|
419 |
|
420 #define RxProtoUDP (PID1) |
|
421 #define RxProtoTCP (PID0) |
|
422 #define RxProtoIP (PID1 | PID0) |
|
423 #define RxProtoMask RxProtoIP |
|
424 |
|
425 IPFail = (1 << 16), /* IP checksum failed */ |
|
426 UDPFail = (1 << 15), /* UDP/IP checksum failed */ |
|
427 TCPFail = (1 << 14), /* TCP/IP checksum failed */ |
|
428 RxVlanTag = (1 << 16), /* VLAN tag available */ |
|
429 }; |
|
430 |
|
431 #define RsvdMask 0x3fffc000 |
|
432 |
|
433 struct TxDesc { |
|
434 __le32 opts1; |
|
435 __le32 opts2; |
|
436 __le64 addr; |
|
437 }; |
|
438 |
|
439 struct RxDesc { |
|
440 __le32 opts1; |
|
441 __le32 opts2; |
|
442 __le64 addr; |
|
443 }; |
|
444 |
|
445 struct ring_info { |
|
446 struct sk_buff *skb; |
|
447 u32 len; |
|
448 u8 __pad[sizeof(void *) - sizeof(u32)]; |
|
449 }; |
|
450 |
|
451 enum features { |
|
452 RTL_FEATURE_WOL = (1 << 0), |
|
453 RTL_FEATURE_MSI = (1 << 1), |
|
454 RTL_FEATURE_GMII = (1 << 2), |
|
455 }; |
|
456 |
|
457 struct rtl8169_counters { |
|
458 __le64 tx_packets; |
|
459 __le64 rx_packets; |
|
460 __le64 tx_errors; |
|
461 __le32 rx_errors; |
|
462 __le16 rx_missed; |
|
463 __le16 align_errors; |
|
464 __le32 tx_one_collision; |
|
465 __le32 tx_multi_collision; |
|
466 __le64 rx_unicast; |
|
467 __le64 rx_broadcast; |
|
468 __le32 rx_multicast; |
|
469 __le16 tx_aborted; |
|
470 __le16 tx_underun; |
|
471 }; |
|
472 |
|
473 struct rtl8169_private { |
|
474 void __iomem *mmio_addr; /* memory map physical address */ |
|
475 struct pci_dev *pci_dev; /* Index of PCI device */ |
|
476 struct net_device *dev; |
|
477 struct napi_struct napi; |
|
478 spinlock_t lock; /* spin lock flag */ |
|
479 u32 msg_enable; |
|
480 int chipset; |
|
481 int mac_version; |
|
482 u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */ |
|
483 u32 cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */ |
|
484 u32 dirty_rx; |
|
485 u32 dirty_tx; |
|
486 struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */ |
|
487 struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */ |
|
488 dma_addr_t TxPhyAddr; |
|
489 dma_addr_t RxPhyAddr; |
|
490 struct sk_buff *Rx_skbuff[NUM_RX_DESC]; /* Rx data buffers */ |
|
491 struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ |
|
492 unsigned align; |
|
493 unsigned rx_buf_sz; |
|
494 struct timer_list timer; |
|
495 u16 cp_cmd; |
|
496 u16 intr_event; |
|
497 u16 napi_event; |
|
498 u16 intr_mask; |
|
499 int phy_1000_ctrl_reg; |
|
500 #ifdef CONFIG_R8169_VLAN |
|
501 struct vlan_group *vlgrp; |
|
502 #endif |
|
503 int (*set_speed)(struct net_device *, u8 autoneg, u16 speed, u8 duplex); |
|
504 int (*get_settings)(struct net_device *, struct ethtool_cmd *); |
|
505 void (*phy_reset_enable)(void __iomem *); |
|
506 void (*hw_start)(struct net_device *); |
|
507 unsigned int (*phy_reset_pending)(void __iomem *); |
|
508 unsigned int (*link_ok)(void __iomem *); |
|
509 int (*do_ioctl)(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd); |
|
510 int pcie_cap; |
|
511 struct delayed_work task; |
|
512 unsigned features; |
|
513 |
|
514 struct mii_if_info mii; |
|
515 struct rtl8169_counters counters; |
|
516 u32 saved_wolopts; |
|
517 |
|
518 ec_device_t *ecdev; |
|
519 unsigned long ec_watchdog_jiffies; |
|
520 }; |
|
521 |
|
522 MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>"); |
|
523 MODULE_DESCRIPTION("EtherCAT-capable RealTek RTL-8169 Gigabit Ethernet driver"); |
|
524 module_param(rx_copybreak, int, 0); |
|
525 MODULE_PARM_DESC(rx_copybreak, "Copy breakpoint for copy-only-tiny-frames"); |
|
526 module_param(use_dac, int, 0); |
|
527 MODULE_PARM_DESC(use_dac, "Enable PCI DAC. Unsafe on 32 bit PCI slot."); |
|
528 module_param_named(debug, debug.msg_enable, int, 0); |
|
529 MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)"); |
|
530 MODULE_LICENSE("GPL"); |
|
531 MODULE_VERSION(EC_MASTER_VERSION); |
|
532 |
|
533 static int rtl8169_open(struct net_device *dev); |
|
534 static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
|
535 struct net_device *dev); |
|
536 static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance); |
|
537 static int rtl8169_init_ring(struct net_device *dev); |
|
538 static void rtl_hw_start(struct net_device *dev); |
|
539 static int rtl8169_close(struct net_device *dev); |
|
540 static void rtl_set_rx_mode(struct net_device *dev); |
|
541 static void rtl8169_tx_timeout(struct net_device *dev); |
|
542 static struct net_device_stats *rtl8169_get_stats(struct net_device *dev); |
|
543 static int rtl8169_rx_interrupt(struct net_device *, struct rtl8169_private *, |
|
544 void __iomem *, u32 budget); |
|
545 static int rtl8169_change_mtu(struct net_device *dev, int new_mtu); |
|
546 static void rtl8169_down(struct net_device *dev); |
|
547 static void rtl8169_rx_clear(struct rtl8169_private *tp); |
|
548 static void ec_poll(struct net_device *dev); |
|
549 static int rtl8169_poll(struct napi_struct *napi, int budget); |
|
550 |
|
551 static const unsigned int rtl8169_rx_config = |
|
552 (RX_FIFO_THRESH << RxCfgFIFOShift) | (RX_DMA_BURST << RxCfgDMAShift); |
|
553 |
|
554 static void mdio_write(void __iomem *ioaddr, int reg_addr, int value) |
|
555 { |
|
556 int i; |
|
557 |
|
558 RTL_W32(PHYAR, 0x80000000 | (reg_addr & 0x1f) << 16 | (value & 0xffff)); |
|
559 |
|
560 for (i = 20; i > 0; i--) { |
|
561 /* |
|
562 * Check if the RTL8169 has completed writing to the specified |
|
563 * MII register. |
|
564 */ |
|
565 if (!(RTL_R32(PHYAR) & 0x80000000)) |
|
566 break; |
|
567 udelay(25); |
|
568 } |
|
569 /* |
|
570 * According to hardware specs a 20us delay is required after write |
|
571 * complete indication, but before sending next command. |
|
572 */ |
|
573 udelay(20); |
|
574 } |
|
575 |
|
576 static int mdio_read(void __iomem *ioaddr, int reg_addr) |
|
577 { |
|
578 int i, value = -1; |
|
579 |
|
580 RTL_W32(PHYAR, 0x0 | (reg_addr & 0x1f) << 16); |
|
581 |
|
582 for (i = 20; i > 0; i--) { |
|
583 /* |
|
584 * Check if the RTL8169 has completed retrieving data from |
|
585 * the specified MII register. |
|
586 */ |
|
587 if (RTL_R32(PHYAR) & 0x80000000) { |
|
588 value = RTL_R32(PHYAR) & 0xffff; |
|
589 break; |
|
590 } |
|
591 udelay(25); |
|
592 } |
|
593 /* |
|
594 * According to hardware specs a 20us delay is required after read |
|
595 * complete indication, but before sending next command. |
|
596 */ |
|
597 udelay(20); |
|
598 |
|
599 return value; |
|
600 } |
|
601 |
|
602 static void mdio_patch(void __iomem *ioaddr, int reg_addr, int value) |
|
603 { |
|
604 mdio_write(ioaddr, reg_addr, mdio_read(ioaddr, reg_addr) | value); |
|
605 } |
|
606 |
|
607 static void mdio_plus_minus(void __iomem *ioaddr, int reg_addr, int p, int m) |
|
608 { |
|
609 int val; |
|
610 |
|
611 val = mdio_read(ioaddr, reg_addr); |
|
612 mdio_write(ioaddr, reg_addr, (val | p) & ~m); |
|
613 } |
|
614 |
|
615 static void rtl_mdio_write(struct net_device *dev, int phy_id, int location, |
|
616 int val) |
|
617 { |
|
618 struct rtl8169_private *tp = netdev_priv(dev); |
|
619 void __iomem *ioaddr = tp->mmio_addr; |
|
620 |
|
621 mdio_write(ioaddr, location, val); |
|
622 } |
|
623 |
|
624 static int rtl_mdio_read(struct net_device *dev, int phy_id, int location) |
|
625 { |
|
626 struct rtl8169_private *tp = netdev_priv(dev); |
|
627 void __iomem *ioaddr = tp->mmio_addr; |
|
628 |
|
629 return mdio_read(ioaddr, location); |
|
630 } |
|
631 |
|
632 static void rtl_ephy_write(void __iomem *ioaddr, int reg_addr, int value) |
|
633 { |
|
634 unsigned int i; |
|
635 |
|
636 RTL_W32(EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) | |
|
637 (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
|
638 |
|
639 for (i = 0; i < 100; i++) { |
|
640 if (!(RTL_R32(EPHYAR) & EPHYAR_FLAG)) |
|
641 break; |
|
642 udelay(10); |
|
643 } |
|
644 } |
|
645 |
|
646 static u16 rtl_ephy_read(void __iomem *ioaddr, int reg_addr) |
|
647 { |
|
648 u16 value = 0xffff; |
|
649 unsigned int i; |
|
650 |
|
651 RTL_W32(EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
|
652 |
|
653 for (i = 0; i < 100; i++) { |
|
654 if (RTL_R32(EPHYAR) & EPHYAR_FLAG) { |
|
655 value = RTL_R32(EPHYAR) & EPHYAR_DATA_MASK; |
|
656 break; |
|
657 } |
|
658 udelay(10); |
|
659 } |
|
660 |
|
661 return value; |
|
662 } |
|
663 |
|
664 static void rtl_csi_write(void __iomem *ioaddr, int addr, int value) |
|
665 { |
|
666 unsigned int i; |
|
667 |
|
668 RTL_W32(CSIDR, value); |
|
669 RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
|
670 CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
|
671 |
|
672 for (i = 0; i < 100; i++) { |
|
673 if (!(RTL_R32(CSIAR) & CSIAR_FLAG)) |
|
674 break; |
|
675 udelay(10); |
|
676 } |
|
677 } |
|
678 |
|
679 static u32 rtl_csi_read(void __iomem *ioaddr, int addr) |
|
680 { |
|
681 u32 value = ~0x00; |
|
682 unsigned int i; |
|
683 |
|
684 RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) | |
|
685 CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
|
686 |
|
687 for (i = 0; i < 100; i++) { |
|
688 if (RTL_R32(CSIAR) & CSIAR_FLAG) { |
|
689 value = RTL_R32(CSIDR); |
|
690 break; |
|
691 } |
|
692 udelay(10); |
|
693 } |
|
694 |
|
695 return value; |
|
696 } |
|
697 |
|
698 static u8 rtl8168d_efuse_read(void __iomem *ioaddr, int reg_addr) |
|
699 { |
|
700 u8 value = 0xff; |
|
701 unsigned int i; |
|
702 |
|
703 RTL_W32(EFUSEAR, (reg_addr & EFUSEAR_REG_MASK) << EFUSEAR_REG_SHIFT); |
|
704 |
|
705 for (i = 0; i < 300; i++) { |
|
706 if (RTL_R32(EFUSEAR) & EFUSEAR_FLAG) { |
|
707 value = RTL_R32(EFUSEAR) & EFUSEAR_DATA_MASK; |
|
708 break; |
|
709 } |
|
710 udelay(100); |
|
711 } |
|
712 |
|
713 return value; |
|
714 } |
|
715 |
|
716 static void rtl8169_irq_mask_and_ack(void __iomem *ioaddr) |
|
717 { |
|
718 RTL_W16(IntrMask, 0x0000); |
|
719 |
|
720 RTL_W16(IntrStatus, 0xffff); |
|
721 } |
|
722 |
|
723 static void rtl8169_asic_down(void __iomem *ioaddr) |
|
724 { |
|
725 RTL_W8(ChipCmd, 0x00); |
|
726 rtl8169_irq_mask_and_ack(ioaddr); |
|
727 RTL_R16(CPlusCmd); |
|
728 } |
|
729 |
|
730 static unsigned int rtl8169_tbi_reset_pending(void __iomem *ioaddr) |
|
731 { |
|
732 return RTL_R32(TBICSR) & TBIReset; |
|
733 } |
|
734 |
|
735 static unsigned int rtl8169_xmii_reset_pending(void __iomem *ioaddr) |
|
736 { |
|
737 return mdio_read(ioaddr, MII_BMCR) & BMCR_RESET; |
|
738 } |
|
739 |
|
740 static unsigned int rtl8169_tbi_link_ok(void __iomem *ioaddr) |
|
741 { |
|
742 return RTL_R32(TBICSR) & TBILinkOk; |
|
743 } |
|
744 |
|
745 static unsigned int rtl8169_xmii_link_ok(void __iomem *ioaddr) |
|
746 { |
|
747 return RTL_R8(PHYstatus) & LinkStatus; |
|
748 } |
|
749 |
|
750 static void rtl8169_tbi_reset_enable(void __iomem *ioaddr) |
|
751 { |
|
752 RTL_W32(TBICSR, RTL_R32(TBICSR) | TBIReset); |
|
753 } |
|
754 |
|
755 static void rtl8169_xmii_reset_enable(void __iomem *ioaddr) |
|
756 { |
|
757 unsigned int val; |
|
758 |
|
759 val = mdio_read(ioaddr, MII_BMCR) | BMCR_RESET; |
|
760 mdio_write(ioaddr, MII_BMCR, val & 0xffff); |
|
761 } |
|
762 |
|
763 static void rtl8169_check_link_status(struct net_device *dev, |
|
764 struct rtl8169_private *tp, |
|
765 void __iomem *ioaddr) |
|
766 { |
|
767 unsigned long flags; |
|
768 |
|
769 if (tp->ecdev) { |
|
770 ecdev_set_link(tp->ecdev, tp->link_ok(ioaddr) ? 1 : 0); |
|
771 } else { |
|
772 spin_lock_irqsave(&tp->lock, flags); |
|
773 if (tp->link_ok(ioaddr)) { |
|
774 /* This is to cancel a scheduled suspend if there's one. */ |
|
775 pm_request_resume(&tp->pci_dev->dev); |
|
776 netif_carrier_on(dev); |
|
777 netif_info(tp, ifup, dev, "link up\n"); |
|
778 } else { |
|
779 netif_carrier_off(dev); |
|
780 netif_info(tp, ifdown, dev, "link down\n"); |
|
781 pm_schedule_suspend(&tp->pci_dev->dev, 100); |
|
782 } |
|
783 spin_unlock_irqrestore(&tp->lock, flags); |
|
784 } |
|
785 } |
|
786 |
|
787 #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST) |
|
788 |
|
789 static u32 __rtl8169_get_wol(struct rtl8169_private *tp) |
|
790 { |
|
791 void __iomem *ioaddr = tp->mmio_addr; |
|
792 u8 options; |
|
793 u32 wolopts = 0; |
|
794 |
|
795 options = RTL_R8(Config1); |
|
796 if (!(options & PMEnable)) |
|
797 return 0; |
|
798 |
|
799 options = RTL_R8(Config3); |
|
800 if (options & LinkUp) |
|
801 wolopts |= WAKE_PHY; |
|
802 if (options & MagicPacket) |
|
803 wolopts |= WAKE_MAGIC; |
|
804 |
|
805 options = RTL_R8(Config5); |
|
806 if (options & UWF) |
|
807 wolopts |= WAKE_UCAST; |
|
808 if (options & BWF) |
|
809 wolopts |= WAKE_BCAST; |
|
810 if (options & MWF) |
|
811 wolopts |= WAKE_MCAST; |
|
812 |
|
813 return wolopts; |
|
814 } |
|
815 |
|
816 static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
|
817 { |
|
818 struct rtl8169_private *tp = netdev_priv(dev); |
|
819 |
|
820 spin_lock_irq(&tp->lock); |
|
821 |
|
822 wol->supported = WAKE_ANY; |
|
823 wol->wolopts = __rtl8169_get_wol(tp); |
|
824 |
|
825 spin_unlock_irq(&tp->lock); |
|
826 } |
|
827 |
|
828 static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts) |
|
829 { |
|
830 void __iomem *ioaddr = tp->mmio_addr; |
|
831 unsigned int i; |
|
832 static const struct { |
|
833 u32 opt; |
|
834 u16 reg; |
|
835 u8 mask; |
|
836 } cfg[] = { |
|
837 { WAKE_ANY, Config1, PMEnable }, |
|
838 { WAKE_PHY, Config3, LinkUp }, |
|
839 { WAKE_MAGIC, Config3, MagicPacket }, |
|
840 { WAKE_UCAST, Config5, UWF }, |
|
841 { WAKE_BCAST, Config5, BWF }, |
|
842 { WAKE_MCAST, Config5, MWF }, |
|
843 { WAKE_ANY, Config5, LanWake } |
|
844 }; |
|
845 |
|
846 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
847 |
|
848 for (i = 0; i < ARRAY_SIZE(cfg); i++) { |
|
849 u8 options = RTL_R8(cfg[i].reg) & ~cfg[i].mask; |
|
850 if (wolopts & cfg[i].opt) |
|
851 options |= cfg[i].mask; |
|
852 RTL_W8(cfg[i].reg, options); |
|
853 } |
|
854 |
|
855 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
856 } |
|
857 |
|
858 static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
|
859 { |
|
860 struct rtl8169_private *tp = netdev_priv(dev); |
|
861 |
|
862 spin_lock_irq(&tp->lock); |
|
863 |
|
864 if (wol->wolopts) |
|
865 tp->features |= RTL_FEATURE_WOL; |
|
866 else |
|
867 tp->features &= ~RTL_FEATURE_WOL; |
|
868 __rtl8169_set_wol(tp, wol->wolopts); |
|
869 device_set_wakeup_enable(&tp->pci_dev->dev, wol->wolopts); |
|
870 |
|
871 spin_unlock_irq(&tp->lock); |
|
872 |
|
873 return 0; |
|
874 } |
|
875 |
|
876 static void rtl8169_get_drvinfo(struct net_device *dev, |
|
877 struct ethtool_drvinfo *info) |
|
878 { |
|
879 struct rtl8169_private *tp = netdev_priv(dev); |
|
880 |
|
881 strcpy(info->driver, MODULENAME); |
|
882 strcpy(info->version, RTL8169_VERSION); |
|
883 strcpy(info->bus_info, pci_name(tp->pci_dev)); |
|
884 } |
|
885 |
|
886 static int rtl8169_get_regs_len(struct net_device *dev) |
|
887 { |
|
888 return R8169_REGS_SIZE; |
|
889 } |
|
890 |
|
891 static int rtl8169_set_speed_tbi(struct net_device *dev, |
|
892 u8 autoneg, u16 speed, u8 duplex) |
|
893 { |
|
894 struct rtl8169_private *tp = netdev_priv(dev); |
|
895 void __iomem *ioaddr = tp->mmio_addr; |
|
896 int ret = 0; |
|
897 u32 reg; |
|
898 |
|
899 reg = RTL_R32(TBICSR); |
|
900 if ((autoneg == AUTONEG_DISABLE) && (speed == SPEED_1000) && |
|
901 (duplex == DUPLEX_FULL)) { |
|
902 RTL_W32(TBICSR, reg & ~(TBINwEnable | TBINwRestart)); |
|
903 } else if (autoneg == AUTONEG_ENABLE) |
|
904 RTL_W32(TBICSR, reg | TBINwEnable | TBINwRestart); |
|
905 else { |
|
906 netif_warn(tp, link, dev, |
|
907 "incorrect speed setting refused in TBI mode\n"); |
|
908 ret = -EOPNOTSUPP; |
|
909 } |
|
910 |
|
911 return ret; |
|
912 } |
|
913 |
|
914 static int rtl8169_set_speed_xmii(struct net_device *dev, |
|
915 u8 autoneg, u16 speed, u8 duplex) |
|
916 { |
|
917 struct rtl8169_private *tp = netdev_priv(dev); |
|
918 void __iomem *ioaddr = tp->mmio_addr; |
|
919 int giga_ctrl, bmcr; |
|
920 |
|
921 if (autoneg == AUTONEG_ENABLE) { |
|
922 int auto_nego; |
|
923 |
|
924 auto_nego = mdio_read(ioaddr, MII_ADVERTISE); |
|
925 auto_nego |= (ADVERTISE_10HALF | ADVERTISE_10FULL | |
|
926 ADVERTISE_100HALF | ADVERTISE_100FULL); |
|
927 auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
|
928 |
|
929 giga_ctrl = mdio_read(ioaddr, MII_CTRL1000); |
|
930 giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); |
|
931 |
|
932 /* The 8100e/8101e/8102e do Fast Ethernet only. */ |
|
933 if ((tp->mac_version != RTL_GIGA_MAC_VER_07) && |
|
934 (tp->mac_version != RTL_GIGA_MAC_VER_08) && |
|
935 (tp->mac_version != RTL_GIGA_MAC_VER_09) && |
|
936 (tp->mac_version != RTL_GIGA_MAC_VER_10) && |
|
937 (tp->mac_version != RTL_GIGA_MAC_VER_13) && |
|
938 (tp->mac_version != RTL_GIGA_MAC_VER_14) && |
|
939 (tp->mac_version != RTL_GIGA_MAC_VER_15) && |
|
940 (tp->mac_version != RTL_GIGA_MAC_VER_16)) { |
|
941 giga_ctrl |= ADVERTISE_1000FULL | ADVERTISE_1000HALF; |
|
942 } else { |
|
943 netif_info(tp, link, dev, |
|
944 "PHY does not support 1000Mbps\n"); |
|
945 } |
|
946 |
|
947 bmcr = BMCR_ANENABLE | BMCR_ANRESTART; |
|
948 |
|
949 if ((tp->mac_version == RTL_GIGA_MAC_VER_11) || |
|
950 (tp->mac_version == RTL_GIGA_MAC_VER_12) || |
|
951 (tp->mac_version >= RTL_GIGA_MAC_VER_17)) { |
|
952 /* |
|
953 * Wake up the PHY. |
|
954 * Vendor specific (0x1f) and reserved (0x0e) MII |
|
955 * registers. |
|
956 */ |
|
957 mdio_write(ioaddr, 0x1f, 0x0000); |
|
958 mdio_write(ioaddr, 0x0e, 0x0000); |
|
959 } |
|
960 |
|
961 mdio_write(ioaddr, MII_ADVERTISE, auto_nego); |
|
962 mdio_write(ioaddr, MII_CTRL1000, giga_ctrl); |
|
963 } else { |
|
964 giga_ctrl = 0; |
|
965 |
|
966 if (speed == SPEED_10) |
|
967 bmcr = 0; |
|
968 else if (speed == SPEED_100) |
|
969 bmcr = BMCR_SPEED100; |
|
970 else |
|
971 return -EINVAL; |
|
972 |
|
973 if (duplex == DUPLEX_FULL) |
|
974 bmcr |= BMCR_FULLDPLX; |
|
975 |
|
976 mdio_write(ioaddr, 0x1f, 0x0000); |
|
977 } |
|
978 |
|
979 tp->phy_1000_ctrl_reg = giga_ctrl; |
|
980 |
|
981 mdio_write(ioaddr, MII_BMCR, bmcr); |
|
982 |
|
983 if ((tp->mac_version == RTL_GIGA_MAC_VER_02) || |
|
984 (tp->mac_version == RTL_GIGA_MAC_VER_03)) { |
|
985 if ((speed == SPEED_100) && (autoneg != AUTONEG_ENABLE)) { |
|
986 mdio_write(ioaddr, 0x17, 0x2138); |
|
987 mdio_write(ioaddr, 0x0e, 0x0260); |
|
988 } else { |
|
989 mdio_write(ioaddr, 0x17, 0x2108); |
|
990 mdio_write(ioaddr, 0x0e, 0x0000); |
|
991 } |
|
992 } |
|
993 |
|
994 return 0; |
|
995 } |
|
996 |
|
997 static int rtl8169_set_speed(struct net_device *dev, |
|
998 u8 autoneg, u16 speed, u8 duplex) |
|
999 { |
|
1000 struct rtl8169_private *tp = netdev_priv(dev); |
|
1001 int ret; |
|
1002 |
|
1003 ret = tp->set_speed(dev, autoneg, speed, duplex); |
|
1004 |
|
1005 if (netif_running(dev) && (tp->phy_1000_ctrl_reg & ADVERTISE_1000FULL)) |
|
1006 mod_timer(&tp->timer, jiffies + RTL8169_PHY_TIMEOUT); |
|
1007 |
|
1008 return ret; |
|
1009 } |
|
1010 |
|
1011 static int rtl8169_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
|
1012 { |
|
1013 struct rtl8169_private *tp = netdev_priv(dev); |
|
1014 unsigned long flags; |
|
1015 int ret; |
|
1016 |
|
1017 spin_lock_irqsave(&tp->lock, flags); |
|
1018 ret = rtl8169_set_speed(dev, cmd->autoneg, cmd->speed, cmd->duplex); |
|
1019 spin_unlock_irqrestore(&tp->lock, flags); |
|
1020 |
|
1021 return ret; |
|
1022 } |
|
1023 |
|
1024 static u32 rtl8169_get_rx_csum(struct net_device *dev) |
|
1025 { |
|
1026 struct rtl8169_private *tp = netdev_priv(dev); |
|
1027 |
|
1028 return tp->cp_cmd & RxChkSum; |
|
1029 } |
|
1030 |
|
1031 static int rtl8169_set_rx_csum(struct net_device *dev, u32 data) |
|
1032 { |
|
1033 struct rtl8169_private *tp = netdev_priv(dev); |
|
1034 void __iomem *ioaddr = tp->mmio_addr; |
|
1035 unsigned long flags; |
|
1036 |
|
1037 spin_lock_irqsave(&tp->lock, flags); |
|
1038 |
|
1039 if (data) |
|
1040 tp->cp_cmd |= RxChkSum; |
|
1041 else |
|
1042 tp->cp_cmd &= ~RxChkSum; |
|
1043 |
|
1044 RTL_W16(CPlusCmd, tp->cp_cmd); |
|
1045 RTL_R16(CPlusCmd); |
|
1046 |
|
1047 spin_unlock_irqrestore(&tp->lock, flags); |
|
1048 |
|
1049 return 0; |
|
1050 } |
|
1051 |
|
1052 #ifdef CONFIG_R8169_VLAN |
|
1053 |
|
1054 static inline u32 rtl8169_tx_vlan_tag(struct rtl8169_private *tp, |
|
1055 struct sk_buff *skb) |
|
1056 { |
|
1057 return (tp->vlgrp && vlan_tx_tag_present(skb)) ? |
|
1058 TxVlanTag | swab16(vlan_tx_tag_get(skb)) : 0x00; |
|
1059 } |
|
1060 |
|
1061 static void rtl8169_vlan_rx_register(struct net_device *dev, |
|
1062 struct vlan_group *grp) |
|
1063 { |
|
1064 struct rtl8169_private *tp = netdev_priv(dev); |
|
1065 void __iomem *ioaddr = tp->mmio_addr; |
|
1066 unsigned long flags; |
|
1067 |
|
1068 spin_lock_irqsave(&tp->lock, flags); |
|
1069 tp->vlgrp = grp; |
|
1070 /* |
|
1071 * Do not disable RxVlan on 8110SCd. |
|
1072 */ |
|
1073 if (tp->vlgrp || (tp->mac_version == RTL_GIGA_MAC_VER_05)) |
|
1074 tp->cp_cmd |= RxVlan; |
|
1075 else |
|
1076 tp->cp_cmd &= ~RxVlan; |
|
1077 RTL_W16(CPlusCmd, tp->cp_cmd); |
|
1078 RTL_R16(CPlusCmd); |
|
1079 spin_unlock_irqrestore(&tp->lock, flags); |
|
1080 } |
|
1081 |
|
1082 static int rtl8169_rx_vlan_skb(struct rtl8169_private *tp, struct RxDesc *desc, |
|
1083 struct sk_buff *skb, int polling) |
|
1084 { |
|
1085 u32 opts2 = le32_to_cpu(desc->opts2); |
|
1086 struct vlan_group *vlgrp = tp->vlgrp; |
|
1087 int ret; |
|
1088 |
|
1089 if (vlgrp && (opts2 & RxVlanTag)) { |
|
1090 __vlan_hwaccel_rx(skb, vlgrp, swab16(opts2 & 0xffff), polling); |
|
1091 ret = 0; |
|
1092 } else |
|
1093 ret = -1; |
|
1094 desc->opts2 = 0; |
|
1095 return ret; |
|
1096 } |
|
1097 |
|
1098 #else /* !CONFIG_R8169_VLAN */ |
|
1099 |
|
1100 static inline u32 rtl8169_tx_vlan_tag(struct rtl8169_private *tp, |
|
1101 struct sk_buff *skb) |
|
1102 { |
|
1103 return 0; |
|
1104 } |
|
1105 |
|
1106 static int rtl8169_rx_vlan_skb(struct rtl8169_private *tp, struct RxDesc *desc, |
|
1107 struct sk_buff *skb, int polling) |
|
1108 { |
|
1109 return -1; |
|
1110 } |
|
1111 |
|
1112 #endif |
|
1113 |
|
1114 static int rtl8169_gset_tbi(struct net_device *dev, struct ethtool_cmd *cmd) |
|
1115 { |
|
1116 struct rtl8169_private *tp = netdev_priv(dev); |
|
1117 void __iomem *ioaddr = tp->mmio_addr; |
|
1118 u32 status; |
|
1119 |
|
1120 cmd->supported = |
|
1121 SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE; |
|
1122 cmd->port = PORT_FIBRE; |
|
1123 cmd->transceiver = XCVR_INTERNAL; |
|
1124 |
|
1125 status = RTL_R32(TBICSR); |
|
1126 cmd->advertising = (status & TBINwEnable) ? ADVERTISED_Autoneg : 0; |
|
1127 cmd->autoneg = !!(status & TBINwEnable); |
|
1128 |
|
1129 cmd->speed = SPEED_1000; |
|
1130 cmd->duplex = DUPLEX_FULL; /* Always set */ |
|
1131 |
|
1132 return 0; |
|
1133 } |
|
1134 |
|
1135 static int rtl8169_gset_xmii(struct net_device *dev, struct ethtool_cmd *cmd) |
|
1136 { |
|
1137 struct rtl8169_private *tp = netdev_priv(dev); |
|
1138 |
|
1139 return mii_ethtool_gset(&tp->mii, cmd); |
|
1140 } |
|
1141 |
|
1142 static int rtl8169_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
|
1143 { |
|
1144 struct rtl8169_private *tp = netdev_priv(dev); |
|
1145 unsigned long flags; |
|
1146 int rc; |
|
1147 |
|
1148 spin_lock_irqsave(&tp->lock, flags); |
|
1149 |
|
1150 rc = tp->get_settings(dev, cmd); |
|
1151 |
|
1152 spin_unlock_irqrestore(&tp->lock, flags); |
|
1153 return rc; |
|
1154 } |
|
1155 |
|
1156 static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
|
1157 void *p) |
|
1158 { |
|
1159 struct rtl8169_private *tp = netdev_priv(dev); |
|
1160 unsigned long flags; |
|
1161 |
|
1162 if (regs->len > R8169_REGS_SIZE) |
|
1163 regs->len = R8169_REGS_SIZE; |
|
1164 |
|
1165 spin_lock_irqsave(&tp->lock, flags); |
|
1166 memcpy_fromio(p, tp->mmio_addr, regs->len); |
|
1167 spin_unlock_irqrestore(&tp->lock, flags); |
|
1168 } |
|
1169 |
|
1170 static u32 rtl8169_get_msglevel(struct net_device *dev) |
|
1171 { |
|
1172 struct rtl8169_private *tp = netdev_priv(dev); |
|
1173 |
|
1174 return tp->msg_enable; |
|
1175 } |
|
1176 |
|
1177 static void rtl8169_set_msglevel(struct net_device *dev, u32 value) |
|
1178 { |
|
1179 struct rtl8169_private *tp = netdev_priv(dev); |
|
1180 |
|
1181 tp->msg_enable = value; |
|
1182 } |
|
1183 |
|
1184 static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = { |
|
1185 "tx_packets", |
|
1186 "rx_packets", |
|
1187 "tx_errors", |
|
1188 "rx_errors", |
|
1189 "rx_missed", |
|
1190 "align_errors", |
|
1191 "tx_single_collisions", |
|
1192 "tx_multi_collisions", |
|
1193 "unicast", |
|
1194 "broadcast", |
|
1195 "multicast", |
|
1196 "tx_aborted", |
|
1197 "tx_underrun", |
|
1198 }; |
|
1199 |
|
1200 static int rtl8169_get_sset_count(struct net_device *dev, int sset) |
|
1201 { |
|
1202 switch (sset) { |
|
1203 case ETH_SS_STATS: |
|
1204 return ARRAY_SIZE(rtl8169_gstrings); |
|
1205 default: |
|
1206 return -EOPNOTSUPP; |
|
1207 } |
|
1208 } |
|
1209 |
|
1210 static void rtl8169_update_counters(struct net_device *dev) |
|
1211 { |
|
1212 struct rtl8169_private *tp = netdev_priv(dev); |
|
1213 void __iomem *ioaddr = tp->mmio_addr; |
|
1214 struct rtl8169_counters *counters; |
|
1215 dma_addr_t paddr; |
|
1216 u32 cmd; |
|
1217 int wait = 1000; |
|
1218 |
|
1219 /* |
|
1220 * Some chips are unable to dump tally counters when the receiver |
|
1221 * is disabled. |
|
1222 */ |
|
1223 if ((RTL_R8(ChipCmd) & CmdRxEnb) == 0) |
|
1224 return; |
|
1225 |
|
1226 counters = dma_alloc_coherent(&tp->pci_dev->dev, sizeof(*counters), |
|
1227 &paddr, GFP_KERNEL); |
|
1228 if (!counters) |
|
1229 return; |
|
1230 |
|
1231 RTL_W32(CounterAddrHigh, (u64)paddr >> 32); |
|
1232 cmd = (u64)paddr & DMA_BIT_MASK(32); |
|
1233 RTL_W32(CounterAddrLow, cmd); |
|
1234 RTL_W32(CounterAddrLow, cmd | CounterDump); |
|
1235 |
|
1236 while (wait--) { |
|
1237 if ((RTL_R32(CounterAddrLow) & CounterDump) == 0) { |
|
1238 /* copy updated counters */ |
|
1239 memcpy(&tp->counters, counters, sizeof(*counters)); |
|
1240 break; |
|
1241 } |
|
1242 udelay(10); |
|
1243 } |
|
1244 |
|
1245 RTL_W32(CounterAddrLow, 0); |
|
1246 RTL_W32(CounterAddrHigh, 0); |
|
1247 |
|
1248 dma_free_coherent(&tp->pci_dev->dev, sizeof(*counters), counters, |
|
1249 paddr); |
|
1250 } |
|
1251 |
|
1252 static void rtl8169_get_ethtool_stats(struct net_device *dev, |
|
1253 struct ethtool_stats *stats, u64 *data) |
|
1254 { |
|
1255 struct rtl8169_private *tp = netdev_priv(dev); |
|
1256 |
|
1257 ASSERT_RTNL(); |
|
1258 |
|
1259 rtl8169_update_counters(dev); |
|
1260 |
|
1261 data[0] = le64_to_cpu(tp->counters.tx_packets); |
|
1262 data[1] = le64_to_cpu(tp->counters.rx_packets); |
|
1263 data[2] = le64_to_cpu(tp->counters.tx_errors); |
|
1264 data[3] = le32_to_cpu(tp->counters.rx_errors); |
|
1265 data[4] = le16_to_cpu(tp->counters.rx_missed); |
|
1266 data[5] = le16_to_cpu(tp->counters.align_errors); |
|
1267 data[6] = le32_to_cpu(tp->counters.tx_one_collision); |
|
1268 data[7] = le32_to_cpu(tp->counters.tx_multi_collision); |
|
1269 data[8] = le64_to_cpu(tp->counters.rx_unicast); |
|
1270 data[9] = le64_to_cpu(tp->counters.rx_broadcast); |
|
1271 data[10] = le32_to_cpu(tp->counters.rx_multicast); |
|
1272 data[11] = le16_to_cpu(tp->counters.tx_aborted); |
|
1273 data[12] = le16_to_cpu(tp->counters.tx_underun); |
|
1274 } |
|
1275 |
|
1276 static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
|
1277 { |
|
1278 switch(stringset) { |
|
1279 case ETH_SS_STATS: |
|
1280 memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings)); |
|
1281 break; |
|
1282 } |
|
1283 } |
|
1284 |
|
1285 static const struct ethtool_ops rtl8169_ethtool_ops = { |
|
1286 .get_drvinfo = rtl8169_get_drvinfo, |
|
1287 .get_regs_len = rtl8169_get_regs_len, |
|
1288 .get_link = ethtool_op_get_link, |
|
1289 .get_settings = rtl8169_get_settings, |
|
1290 .set_settings = rtl8169_set_settings, |
|
1291 .get_msglevel = rtl8169_get_msglevel, |
|
1292 .set_msglevel = rtl8169_set_msglevel, |
|
1293 .get_rx_csum = rtl8169_get_rx_csum, |
|
1294 .set_rx_csum = rtl8169_set_rx_csum, |
|
1295 .set_tx_csum = ethtool_op_set_tx_csum, |
|
1296 .set_sg = ethtool_op_set_sg, |
|
1297 .set_tso = ethtool_op_set_tso, |
|
1298 .get_regs = rtl8169_get_regs, |
|
1299 .get_wol = rtl8169_get_wol, |
|
1300 .set_wol = rtl8169_set_wol, |
|
1301 .get_strings = rtl8169_get_strings, |
|
1302 .get_sset_count = rtl8169_get_sset_count, |
|
1303 .get_ethtool_stats = rtl8169_get_ethtool_stats, |
|
1304 }; |
|
1305 |
|
1306 static void rtl8169_get_mac_version(struct rtl8169_private *tp, |
|
1307 void __iomem *ioaddr) |
|
1308 { |
|
1309 /* |
|
1310 * The driver currently handles the 8168Bf and the 8168Be identically |
|
1311 * but they can be identified more specifically through the test below |
|
1312 * if needed: |
|
1313 * |
|
1314 * (RTL_R32(TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be |
|
1315 * |
|
1316 * Same thing for the 8101Eb and the 8101Ec: |
|
1317 * |
|
1318 * (RTL_R32(TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec |
|
1319 */ |
|
1320 static const struct { |
|
1321 u32 mask; |
|
1322 u32 val; |
|
1323 int mac_version; |
|
1324 } mac_info[] = { |
|
1325 /* 8168D family. */ |
|
1326 { 0x7cf00000, 0x28300000, RTL_GIGA_MAC_VER_26 }, |
|
1327 { 0x7cf00000, 0x28100000, RTL_GIGA_MAC_VER_25 }, |
|
1328 { 0x7c800000, 0x28800000, RTL_GIGA_MAC_VER_27 }, |
|
1329 { 0x7c800000, 0x28000000, RTL_GIGA_MAC_VER_26 }, |
|
1330 |
|
1331 /* 8168C family. */ |
|
1332 { 0x7cf00000, 0x3cb00000, RTL_GIGA_MAC_VER_24 }, |
|
1333 { 0x7cf00000, 0x3c900000, RTL_GIGA_MAC_VER_23 }, |
|
1334 { 0x7cf00000, 0x3c800000, RTL_GIGA_MAC_VER_18 }, |
|
1335 { 0x7c800000, 0x3c800000, RTL_GIGA_MAC_VER_24 }, |
|
1336 { 0x7cf00000, 0x3c000000, RTL_GIGA_MAC_VER_19 }, |
|
1337 { 0x7cf00000, 0x3c200000, RTL_GIGA_MAC_VER_20 }, |
|
1338 { 0x7cf00000, 0x3c300000, RTL_GIGA_MAC_VER_21 }, |
|
1339 { 0x7cf00000, 0x3c400000, RTL_GIGA_MAC_VER_22 }, |
|
1340 { 0x7c800000, 0x3c000000, RTL_GIGA_MAC_VER_22 }, |
|
1341 |
|
1342 /* 8168B family. */ |
|
1343 { 0x7cf00000, 0x38000000, RTL_GIGA_MAC_VER_12 }, |
|
1344 { 0x7cf00000, 0x38500000, RTL_GIGA_MAC_VER_17 }, |
|
1345 { 0x7c800000, 0x38000000, RTL_GIGA_MAC_VER_17 }, |
|
1346 { 0x7c800000, 0x30000000, RTL_GIGA_MAC_VER_11 }, |
|
1347 |
|
1348 /* 8101 family. */ |
|
1349 { 0x7cf00000, 0x34a00000, RTL_GIGA_MAC_VER_09 }, |
|
1350 { 0x7cf00000, 0x24a00000, RTL_GIGA_MAC_VER_09 }, |
|
1351 { 0x7cf00000, 0x34900000, RTL_GIGA_MAC_VER_08 }, |
|
1352 { 0x7cf00000, 0x24900000, RTL_GIGA_MAC_VER_08 }, |
|
1353 { 0x7cf00000, 0x34800000, RTL_GIGA_MAC_VER_07 }, |
|
1354 { 0x7cf00000, 0x24800000, RTL_GIGA_MAC_VER_07 }, |
|
1355 { 0x7cf00000, 0x34000000, RTL_GIGA_MAC_VER_13 }, |
|
1356 { 0x7cf00000, 0x34300000, RTL_GIGA_MAC_VER_10 }, |
|
1357 { 0x7cf00000, 0x34200000, RTL_GIGA_MAC_VER_16 }, |
|
1358 { 0x7c800000, 0x34800000, RTL_GIGA_MAC_VER_09 }, |
|
1359 { 0x7c800000, 0x24800000, RTL_GIGA_MAC_VER_09 }, |
|
1360 { 0x7c800000, 0x34000000, RTL_GIGA_MAC_VER_16 }, |
|
1361 /* FIXME: where did these entries come from ? -- FR */ |
|
1362 { 0xfc800000, 0x38800000, RTL_GIGA_MAC_VER_15 }, |
|
1363 { 0xfc800000, 0x30800000, RTL_GIGA_MAC_VER_14 }, |
|
1364 |
|
1365 /* 8110 family. */ |
|
1366 { 0xfc800000, 0x98000000, RTL_GIGA_MAC_VER_06 }, |
|
1367 { 0xfc800000, 0x18000000, RTL_GIGA_MAC_VER_05 }, |
|
1368 { 0xfc800000, 0x10000000, RTL_GIGA_MAC_VER_04 }, |
|
1369 { 0xfc800000, 0x04000000, RTL_GIGA_MAC_VER_03 }, |
|
1370 { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 }, |
|
1371 { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 }, |
|
1372 |
|
1373 /* Catch-all */ |
|
1374 { 0x00000000, 0x00000000, RTL_GIGA_MAC_NONE } |
|
1375 }, *p = mac_info; |
|
1376 u32 reg; |
|
1377 |
|
1378 reg = RTL_R32(TxConfig); |
|
1379 while ((reg & p->mask) != p->val) |
|
1380 p++; |
|
1381 tp->mac_version = p->mac_version; |
|
1382 } |
|
1383 |
|
1384 static void rtl8169_print_mac_version(struct rtl8169_private *tp) |
|
1385 { |
|
1386 dprintk("mac_version = 0x%02x\n", tp->mac_version); |
|
1387 } |
|
1388 |
|
1389 struct phy_reg { |
|
1390 u16 reg; |
|
1391 u16 val; |
|
1392 }; |
|
1393 |
|
1394 static void rtl_phy_write(void __iomem *ioaddr, const struct phy_reg *regs, int len) |
|
1395 { |
|
1396 while (len-- > 0) { |
|
1397 mdio_write(ioaddr, regs->reg, regs->val); |
|
1398 regs++; |
|
1399 } |
|
1400 } |
|
1401 |
|
1402 static void rtl8169s_hw_phy_config(void __iomem *ioaddr) |
|
1403 { |
|
1404 static const struct phy_reg phy_reg_init[] = { |
|
1405 { 0x1f, 0x0001 }, |
|
1406 { 0x06, 0x006e }, |
|
1407 { 0x08, 0x0708 }, |
|
1408 { 0x15, 0x4000 }, |
|
1409 { 0x18, 0x65c7 }, |
|
1410 |
|
1411 { 0x1f, 0x0001 }, |
|
1412 { 0x03, 0x00a1 }, |
|
1413 { 0x02, 0x0008 }, |
|
1414 { 0x01, 0x0120 }, |
|
1415 { 0x00, 0x1000 }, |
|
1416 { 0x04, 0x0800 }, |
|
1417 { 0x04, 0x0000 }, |
|
1418 |
|
1419 { 0x03, 0xff41 }, |
|
1420 { 0x02, 0xdf60 }, |
|
1421 { 0x01, 0x0140 }, |
|
1422 { 0x00, 0x0077 }, |
|
1423 { 0x04, 0x7800 }, |
|
1424 { 0x04, 0x7000 }, |
|
1425 |
|
1426 { 0x03, 0x802f }, |
|
1427 { 0x02, 0x4f02 }, |
|
1428 { 0x01, 0x0409 }, |
|
1429 { 0x00, 0xf0f9 }, |
|
1430 { 0x04, 0x9800 }, |
|
1431 { 0x04, 0x9000 }, |
|
1432 |
|
1433 { 0x03, 0xdf01 }, |
|
1434 { 0x02, 0xdf20 }, |
|
1435 { 0x01, 0xff95 }, |
|
1436 { 0x00, 0xba00 }, |
|
1437 { 0x04, 0xa800 }, |
|
1438 { 0x04, 0xa000 }, |
|
1439 |
|
1440 { 0x03, 0xff41 }, |
|
1441 { 0x02, 0xdf20 }, |
|
1442 { 0x01, 0x0140 }, |
|
1443 { 0x00, 0x00bb }, |
|
1444 { 0x04, 0xb800 }, |
|
1445 { 0x04, 0xb000 }, |
|
1446 |
|
1447 { 0x03, 0xdf41 }, |
|
1448 { 0x02, 0xdc60 }, |
|
1449 { 0x01, 0x6340 }, |
|
1450 { 0x00, 0x007d }, |
|
1451 { 0x04, 0xd800 }, |
|
1452 { 0x04, 0xd000 }, |
|
1453 |
|
1454 { 0x03, 0xdf01 }, |
|
1455 { 0x02, 0xdf20 }, |
|
1456 { 0x01, 0x100a }, |
|
1457 { 0x00, 0xa0ff }, |
|
1458 { 0x04, 0xf800 }, |
|
1459 { 0x04, 0xf000 }, |
|
1460 |
|
1461 { 0x1f, 0x0000 }, |
|
1462 { 0x0b, 0x0000 }, |
|
1463 { 0x00, 0x9200 } |
|
1464 }; |
|
1465 |
|
1466 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
1467 } |
|
1468 |
|
1469 static void rtl8169sb_hw_phy_config(void __iomem *ioaddr) |
|
1470 { |
|
1471 static const struct phy_reg phy_reg_init[] = { |
|
1472 { 0x1f, 0x0002 }, |
|
1473 { 0x01, 0x90d0 }, |
|
1474 { 0x1f, 0x0000 } |
|
1475 }; |
|
1476 |
|
1477 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
1478 } |
|
1479 |
|
1480 static void rtl8169scd_hw_phy_config_quirk(struct rtl8169_private *tp, |
|
1481 void __iomem *ioaddr) |
|
1482 { |
|
1483 struct pci_dev *pdev = tp->pci_dev; |
|
1484 u16 vendor_id, device_id; |
|
1485 |
|
1486 pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &vendor_id); |
|
1487 pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &device_id); |
|
1488 |
|
1489 if ((vendor_id != PCI_VENDOR_ID_GIGABYTE) || (device_id != 0xe000)) |
|
1490 return; |
|
1491 |
|
1492 mdio_write(ioaddr, 0x1f, 0x0001); |
|
1493 mdio_write(ioaddr, 0x10, 0xf01b); |
|
1494 mdio_write(ioaddr, 0x1f, 0x0000); |
|
1495 } |
|
1496 |
|
1497 static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp, |
|
1498 void __iomem *ioaddr) |
|
1499 { |
|
1500 static const struct phy_reg phy_reg_init[] = { |
|
1501 { 0x1f, 0x0001 }, |
|
1502 { 0x04, 0x0000 }, |
|
1503 { 0x03, 0x00a1 }, |
|
1504 { 0x02, 0x0008 }, |
|
1505 { 0x01, 0x0120 }, |
|
1506 { 0x00, 0x1000 }, |
|
1507 { 0x04, 0x0800 }, |
|
1508 { 0x04, 0x9000 }, |
|
1509 { 0x03, 0x802f }, |
|
1510 { 0x02, 0x4f02 }, |
|
1511 { 0x01, 0x0409 }, |
|
1512 { 0x00, 0xf099 }, |
|
1513 { 0x04, 0x9800 }, |
|
1514 { 0x04, 0xa000 }, |
|
1515 { 0x03, 0xdf01 }, |
|
1516 { 0x02, 0xdf20 }, |
|
1517 { 0x01, 0xff95 }, |
|
1518 { 0x00, 0xba00 }, |
|
1519 { 0x04, 0xa800 }, |
|
1520 { 0x04, 0xf000 }, |
|
1521 { 0x03, 0xdf01 }, |
|
1522 { 0x02, 0xdf20 }, |
|
1523 { 0x01, 0x101a }, |
|
1524 { 0x00, 0xa0ff }, |
|
1525 { 0x04, 0xf800 }, |
|
1526 { 0x04, 0x0000 }, |
|
1527 { 0x1f, 0x0000 }, |
|
1528 |
|
1529 { 0x1f, 0x0001 }, |
|
1530 { 0x10, 0xf41b }, |
|
1531 { 0x14, 0xfb54 }, |
|
1532 { 0x18, 0xf5c7 }, |
|
1533 { 0x1f, 0x0000 }, |
|
1534 |
|
1535 { 0x1f, 0x0001 }, |
|
1536 { 0x17, 0x0cc0 }, |
|
1537 { 0x1f, 0x0000 } |
|
1538 }; |
|
1539 |
|
1540 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
1541 |
|
1542 rtl8169scd_hw_phy_config_quirk(tp, ioaddr); |
|
1543 } |
|
1544 |
|
1545 static void rtl8169sce_hw_phy_config(void __iomem *ioaddr) |
|
1546 { |
|
1547 static const struct phy_reg phy_reg_init[] = { |
|
1548 { 0x1f, 0x0001 }, |
|
1549 { 0x04, 0x0000 }, |
|
1550 { 0x03, 0x00a1 }, |
|
1551 { 0x02, 0x0008 }, |
|
1552 { 0x01, 0x0120 }, |
|
1553 { 0x00, 0x1000 }, |
|
1554 { 0x04, 0x0800 }, |
|
1555 { 0x04, 0x9000 }, |
|
1556 { 0x03, 0x802f }, |
|
1557 { 0x02, 0x4f02 }, |
|
1558 { 0x01, 0x0409 }, |
|
1559 { 0x00, 0xf099 }, |
|
1560 { 0x04, 0x9800 }, |
|
1561 { 0x04, 0xa000 }, |
|
1562 { 0x03, 0xdf01 }, |
|
1563 { 0x02, 0xdf20 }, |
|
1564 { 0x01, 0xff95 }, |
|
1565 { 0x00, 0xba00 }, |
|
1566 { 0x04, 0xa800 }, |
|
1567 { 0x04, 0xf000 }, |
|
1568 { 0x03, 0xdf01 }, |
|
1569 { 0x02, 0xdf20 }, |
|
1570 { 0x01, 0x101a }, |
|
1571 { 0x00, 0xa0ff }, |
|
1572 { 0x04, 0xf800 }, |
|
1573 { 0x04, 0x0000 }, |
|
1574 { 0x1f, 0x0000 }, |
|
1575 |
|
1576 { 0x1f, 0x0001 }, |
|
1577 { 0x0b, 0x8480 }, |
|
1578 { 0x1f, 0x0000 }, |
|
1579 |
|
1580 { 0x1f, 0x0001 }, |
|
1581 { 0x18, 0x67c7 }, |
|
1582 { 0x04, 0x2000 }, |
|
1583 { 0x03, 0x002f }, |
|
1584 { 0x02, 0x4360 }, |
|
1585 { 0x01, 0x0109 }, |
|
1586 { 0x00, 0x3022 }, |
|
1587 { 0x04, 0x2800 }, |
|
1588 { 0x1f, 0x0000 }, |
|
1589 |
|
1590 { 0x1f, 0x0001 }, |
|
1591 { 0x17, 0x0cc0 }, |
|
1592 { 0x1f, 0x0000 } |
|
1593 }; |
|
1594 |
|
1595 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
1596 } |
|
1597 |
|
1598 static void rtl8168bb_hw_phy_config(void __iomem *ioaddr) |
|
1599 { |
|
1600 static const struct phy_reg phy_reg_init[] = { |
|
1601 { 0x10, 0xf41b }, |
|
1602 { 0x1f, 0x0000 } |
|
1603 }; |
|
1604 |
|
1605 mdio_write(ioaddr, 0x1f, 0x0001); |
|
1606 mdio_patch(ioaddr, 0x16, 1 << 0); |
|
1607 |
|
1608 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
1609 } |
|
1610 |
|
1611 static void rtl8168bef_hw_phy_config(void __iomem *ioaddr) |
|
1612 { |
|
1613 static const struct phy_reg phy_reg_init[] = { |
|
1614 { 0x1f, 0x0001 }, |
|
1615 { 0x10, 0xf41b }, |
|
1616 { 0x1f, 0x0000 } |
|
1617 }; |
|
1618 |
|
1619 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
1620 } |
|
1621 |
|
1622 static void rtl8168cp_1_hw_phy_config(void __iomem *ioaddr) |
|
1623 { |
|
1624 static const struct phy_reg phy_reg_init[] = { |
|
1625 { 0x1f, 0x0000 }, |
|
1626 { 0x1d, 0x0f00 }, |
|
1627 { 0x1f, 0x0002 }, |
|
1628 { 0x0c, 0x1ec8 }, |
|
1629 { 0x1f, 0x0000 } |
|
1630 }; |
|
1631 |
|
1632 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
1633 } |
|
1634 |
|
1635 static void rtl8168cp_2_hw_phy_config(void __iomem *ioaddr) |
|
1636 { |
|
1637 static const struct phy_reg phy_reg_init[] = { |
|
1638 { 0x1f, 0x0001 }, |
|
1639 { 0x1d, 0x3d98 }, |
|
1640 { 0x1f, 0x0000 } |
|
1641 }; |
|
1642 |
|
1643 mdio_write(ioaddr, 0x1f, 0x0000); |
|
1644 mdio_patch(ioaddr, 0x14, 1 << 5); |
|
1645 mdio_patch(ioaddr, 0x0d, 1 << 5); |
|
1646 |
|
1647 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
1648 } |
|
1649 |
|
1650 static void rtl8168c_1_hw_phy_config(void __iomem *ioaddr) |
|
1651 { |
|
1652 static const struct phy_reg phy_reg_init[] = { |
|
1653 { 0x1f, 0x0001 }, |
|
1654 { 0x12, 0x2300 }, |
|
1655 { 0x1f, 0x0002 }, |
|
1656 { 0x00, 0x88d4 }, |
|
1657 { 0x01, 0x82b1 }, |
|
1658 { 0x03, 0x7002 }, |
|
1659 { 0x08, 0x9e30 }, |
|
1660 { 0x09, 0x01f0 }, |
|
1661 { 0x0a, 0x5500 }, |
|
1662 { 0x0c, 0x00c8 }, |
|
1663 { 0x1f, 0x0003 }, |
|
1664 { 0x12, 0xc096 }, |
|
1665 { 0x16, 0x000a }, |
|
1666 { 0x1f, 0x0000 }, |
|
1667 { 0x1f, 0x0000 }, |
|
1668 { 0x09, 0x2000 }, |
|
1669 { 0x09, 0x0000 } |
|
1670 }; |
|
1671 |
|
1672 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
1673 |
|
1674 mdio_patch(ioaddr, 0x14, 1 << 5); |
|
1675 mdio_patch(ioaddr, 0x0d, 1 << 5); |
|
1676 mdio_write(ioaddr, 0x1f, 0x0000); |
|
1677 } |
|
1678 |
|
1679 static void rtl8168c_2_hw_phy_config(void __iomem *ioaddr) |
|
1680 { |
|
1681 static const struct phy_reg phy_reg_init[] = { |
|
1682 { 0x1f, 0x0001 }, |
|
1683 { 0x12, 0x2300 }, |
|
1684 { 0x03, 0x802f }, |
|
1685 { 0x02, 0x4f02 }, |
|
1686 { 0x01, 0x0409 }, |
|
1687 { 0x00, 0xf099 }, |
|
1688 { 0x04, 0x9800 }, |
|
1689 { 0x04, 0x9000 }, |
|
1690 { 0x1d, 0x3d98 }, |
|
1691 { 0x1f, 0x0002 }, |
|
1692 { 0x0c, 0x7eb8 }, |
|
1693 { 0x06, 0x0761 }, |
|
1694 { 0x1f, 0x0003 }, |
|
1695 { 0x16, 0x0f0a }, |
|
1696 { 0x1f, 0x0000 } |
|
1697 }; |
|
1698 |
|
1699 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
1700 |
|
1701 mdio_patch(ioaddr, 0x16, 1 << 0); |
|
1702 mdio_patch(ioaddr, 0x14, 1 << 5); |
|
1703 mdio_patch(ioaddr, 0x0d, 1 << 5); |
|
1704 mdio_write(ioaddr, 0x1f, 0x0000); |
|
1705 } |
|
1706 |
|
1707 static void rtl8168c_3_hw_phy_config(void __iomem *ioaddr) |
|
1708 { |
|
1709 static const struct phy_reg phy_reg_init[] = { |
|
1710 { 0x1f, 0x0001 }, |
|
1711 { 0x12, 0x2300 }, |
|
1712 { 0x1d, 0x3d98 }, |
|
1713 { 0x1f, 0x0002 }, |
|
1714 { 0x0c, 0x7eb8 }, |
|
1715 { 0x06, 0x5461 }, |
|
1716 { 0x1f, 0x0003 }, |
|
1717 { 0x16, 0x0f0a }, |
|
1718 { 0x1f, 0x0000 } |
|
1719 }; |
|
1720 |
|
1721 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
1722 |
|
1723 mdio_patch(ioaddr, 0x16, 1 << 0); |
|
1724 mdio_patch(ioaddr, 0x14, 1 << 5); |
|
1725 mdio_patch(ioaddr, 0x0d, 1 << 5); |
|
1726 mdio_write(ioaddr, 0x1f, 0x0000); |
|
1727 } |
|
1728 |
|
1729 static void rtl8168c_4_hw_phy_config(void __iomem *ioaddr) |
|
1730 { |
|
1731 rtl8168c_3_hw_phy_config(ioaddr); |
|
1732 } |
|
1733 |
|
1734 static void rtl8168d_1_hw_phy_config(void __iomem *ioaddr) |
|
1735 { |
|
1736 static const struct phy_reg phy_reg_init_0[] = { |
|
1737 { 0x1f, 0x0001 }, |
|
1738 { 0x06, 0x4064 }, |
|
1739 { 0x07, 0x2863 }, |
|
1740 { 0x08, 0x059c }, |
|
1741 { 0x09, 0x26b4 }, |
|
1742 { 0x0a, 0x6a19 }, |
|
1743 { 0x0b, 0xdcc8 }, |
|
1744 { 0x10, 0xf06d }, |
|
1745 { 0x14, 0x7f68 }, |
|
1746 { 0x18, 0x7fd9 }, |
|
1747 { 0x1c, 0xf0ff }, |
|
1748 { 0x1d, 0x3d9c }, |
|
1749 { 0x1f, 0x0003 }, |
|
1750 { 0x12, 0xf49f }, |
|
1751 { 0x13, 0x070b }, |
|
1752 { 0x1a, 0x05ad }, |
|
1753 { 0x14, 0x94c0 } |
|
1754 }; |
|
1755 static const struct phy_reg phy_reg_init_1[] = { |
|
1756 { 0x1f, 0x0002 }, |
|
1757 { 0x06, 0x5561 }, |
|
1758 { 0x1f, 0x0005 }, |
|
1759 { 0x05, 0x8332 }, |
|
1760 { 0x06, 0x5561 } |
|
1761 }; |
|
1762 static const struct phy_reg phy_reg_init_2[] = { |
|
1763 { 0x1f, 0x0005 }, |
|
1764 { 0x05, 0xffc2 }, |
|
1765 { 0x1f, 0x0005 }, |
|
1766 { 0x05, 0x8000 }, |
|
1767 { 0x06, 0xf8f9 }, |
|
1768 { 0x06, 0xfaef }, |
|
1769 { 0x06, 0x59ee }, |
|
1770 { 0x06, 0xf8ea }, |
|
1771 { 0x06, 0x00ee }, |
|
1772 { 0x06, 0xf8eb }, |
|
1773 { 0x06, 0x00e0 }, |
|
1774 { 0x06, 0xf87c }, |
|
1775 { 0x06, 0xe1f8 }, |
|
1776 { 0x06, 0x7d59 }, |
|
1777 { 0x06, 0x0fef }, |
|
1778 { 0x06, 0x0139 }, |
|
1779 { 0x06, 0x029e }, |
|
1780 { 0x06, 0x06ef }, |
|
1781 { 0x06, 0x1039 }, |
|
1782 { 0x06, 0x089f }, |
|
1783 { 0x06, 0x2aee }, |
|
1784 { 0x06, 0xf8ea }, |
|
1785 { 0x06, 0x00ee }, |
|
1786 { 0x06, 0xf8eb }, |
|
1787 { 0x06, 0x01e0 }, |
|
1788 { 0x06, 0xf87c }, |
|
1789 { 0x06, 0xe1f8 }, |
|
1790 { 0x06, 0x7d58 }, |
|
1791 { 0x06, 0x409e }, |
|
1792 { 0x06, 0x0f39 }, |
|
1793 { 0x06, 0x46aa }, |
|
1794 { 0x06, 0x0bbf }, |
|
1795 { 0x06, 0x8290 }, |
|
1796 { 0x06, 0xd682 }, |
|
1797 { 0x06, 0x9802 }, |
|
1798 { 0x06, 0x014f }, |
|
1799 { 0x06, 0xae09 }, |
|
1800 { 0x06, 0xbf82 }, |
|
1801 { 0x06, 0x98d6 }, |
|
1802 { 0x06, 0x82a0 }, |
|
1803 { 0x06, 0x0201 }, |
|
1804 { 0x06, 0x4fef }, |
|
1805 { 0x06, 0x95fe }, |
|
1806 { 0x06, 0xfdfc }, |
|
1807 { 0x06, 0x05f8 }, |
|
1808 { 0x06, 0xf9fa }, |
|
1809 { 0x06, 0xeef8 }, |
|
1810 { 0x06, 0xea00 }, |
|
1811 { 0x06, 0xeef8 }, |
|
1812 { 0x06, 0xeb00 }, |
|
1813 { 0x06, 0xe2f8 }, |
|
1814 { 0x06, 0x7ce3 }, |
|
1815 { 0x06, 0xf87d }, |
|
1816 { 0x06, 0xa511 }, |
|
1817 { 0x06, 0x1112 }, |
|
1818 { 0x06, 0xd240 }, |
|
1819 { 0x06, 0xd644 }, |
|
1820 { 0x06, 0x4402 }, |
|
1821 { 0x06, 0x8217 }, |
|
1822 { 0x06, 0xd2a0 }, |
|
1823 { 0x06, 0xd6aa }, |
|
1824 { 0x06, 0xaa02 }, |
|
1825 { 0x06, 0x8217 }, |
|
1826 { 0x06, 0xae0f }, |
|
1827 { 0x06, 0xa544 }, |
|
1828 { 0x06, 0x4402 }, |
|
1829 { 0x06, 0xae4d }, |
|
1830 { 0x06, 0xa5aa }, |
|
1831 { 0x06, 0xaa02 }, |
|
1832 { 0x06, 0xae47 }, |
|
1833 { 0x06, 0xaf82 }, |
|
1834 { 0x06, 0x13ee }, |
|
1835 { 0x06, 0x834e }, |
|
1836 { 0x06, 0x00ee }, |
|
1837 { 0x06, 0x834d }, |
|
1838 { 0x06, 0x0fee }, |
|
1839 { 0x06, 0x834c }, |
|
1840 { 0x06, 0x0fee }, |
|
1841 { 0x06, 0x834f }, |
|
1842 { 0x06, 0x00ee }, |
|
1843 { 0x06, 0x8351 }, |
|
1844 { 0x06, 0x00ee }, |
|
1845 { 0x06, 0x834a }, |
|
1846 { 0x06, 0xffee }, |
|
1847 { 0x06, 0x834b }, |
|
1848 { 0x06, 0xffe0 }, |
|
1849 { 0x06, 0x8330 }, |
|
1850 { 0x06, 0xe183 }, |
|
1851 { 0x06, 0x3158 }, |
|
1852 { 0x06, 0xfee4 }, |
|
1853 { 0x06, 0xf88a }, |
|
1854 { 0x06, 0xe5f8 }, |
|
1855 { 0x06, 0x8be0 }, |
|
1856 { 0x06, 0x8332 }, |
|
1857 { 0x06, 0xe183 }, |
|
1858 { 0x06, 0x3359 }, |
|
1859 { 0x06, 0x0fe2 }, |
|
1860 { 0x06, 0x834d }, |
|
1861 { 0x06, 0x0c24 }, |
|
1862 { 0x06, 0x5af0 }, |
|
1863 { 0x06, 0x1e12 }, |
|
1864 { 0x06, 0xe4f8 }, |
|
1865 { 0x06, 0x8ce5 }, |
|
1866 { 0x06, 0xf88d }, |
|
1867 { 0x06, 0xaf82 }, |
|
1868 { 0x06, 0x13e0 }, |
|
1869 { 0x06, 0x834f }, |
|
1870 { 0x06, 0x10e4 }, |
|
1871 { 0x06, 0x834f }, |
|
1872 { 0x06, 0xe083 }, |
|
1873 { 0x06, 0x4e78 }, |
|
1874 { 0x06, 0x009f }, |
|
1875 { 0x06, 0x0ae0 }, |
|
1876 { 0x06, 0x834f }, |
|
1877 { 0x06, 0xa010 }, |
|
1878 { 0x06, 0xa5ee }, |
|
1879 { 0x06, 0x834e }, |
|
1880 { 0x06, 0x01e0 }, |
|
1881 { 0x06, 0x834e }, |
|
1882 { 0x06, 0x7805 }, |
|
1883 { 0x06, 0x9e9a }, |
|
1884 { 0x06, 0xe083 }, |
|
1885 { 0x06, 0x4e78 }, |
|
1886 { 0x06, 0x049e }, |
|
1887 { 0x06, 0x10e0 }, |
|
1888 { 0x06, 0x834e }, |
|
1889 { 0x06, 0x7803 }, |
|
1890 { 0x06, 0x9e0f }, |
|
1891 { 0x06, 0xe083 }, |
|
1892 { 0x06, 0x4e78 }, |
|
1893 { 0x06, 0x019e }, |
|
1894 { 0x06, 0x05ae }, |
|
1895 { 0x06, 0x0caf }, |
|
1896 { 0x06, 0x81f8 }, |
|
1897 { 0x06, 0xaf81 }, |
|
1898 { 0x06, 0xa3af }, |
|
1899 { 0x06, 0x81dc }, |
|
1900 { 0x06, 0xaf82 }, |
|
1901 { 0x06, 0x13ee }, |
|
1902 { 0x06, 0x8348 }, |
|
1903 { 0x06, 0x00ee }, |
|
1904 { 0x06, 0x8349 }, |
|
1905 { 0x06, 0x00e0 }, |
|
1906 { 0x06, 0x8351 }, |
|
1907 { 0x06, 0x10e4 }, |
|
1908 { 0x06, 0x8351 }, |
|
1909 { 0x06, 0x5801 }, |
|
1910 { 0x06, 0x9fea }, |
|
1911 { 0x06, 0xd000 }, |
|
1912 { 0x06, 0xd180 }, |
|
1913 { 0x06, 0x1f66 }, |
|
1914 { 0x06, 0xe2f8 }, |
|
1915 { 0x06, 0xeae3 }, |
|
1916 { 0x06, 0xf8eb }, |
|
1917 { 0x06, 0x5af8 }, |
|
1918 { 0x06, 0x1e20 }, |
|
1919 { 0x06, 0xe6f8 }, |
|
1920 { 0x06, 0xeae5 }, |
|
1921 { 0x06, 0xf8eb }, |
|
1922 { 0x06, 0xd302 }, |
|
1923 { 0x06, 0xb3fe }, |
|
1924 { 0x06, 0xe2f8 }, |
|
1925 { 0x06, 0x7cef }, |
|
1926 { 0x06, 0x325b }, |
|
1927 { 0x06, 0x80e3 }, |
|
1928 { 0x06, 0xf87d }, |
|
1929 { 0x06, 0x9e03 }, |
|
1930 { 0x06, 0x7dff }, |
|
1931 { 0x06, 0xff0d }, |
|
1932 { 0x06, 0x581c }, |
|
1933 { 0x06, 0x551a }, |
|
1934 { 0x06, 0x6511 }, |
|
1935 { 0x06, 0xa190 }, |
|
1936 { 0x06, 0xd3e2 }, |
|
1937 { 0x06, 0x8348 }, |
|
1938 { 0x06, 0xe383 }, |
|
1939 { 0x06, 0x491b }, |
|
1940 { 0x06, 0x56ab }, |
|
1941 { 0x06, 0x08ef }, |
|
1942 { 0x06, 0x56e6 }, |
|
1943 { 0x06, 0x8348 }, |
|
1944 { 0x06, 0xe783 }, |
|
1945 { 0x06, 0x4910 }, |
|
1946 { 0x06, 0xd180 }, |
|
1947 { 0x06, 0x1f66 }, |
|
1948 { 0x06, 0xa004 }, |
|
1949 { 0x06, 0xb9e2 }, |
|
1950 { 0x06, 0x8348 }, |
|
1951 { 0x06, 0xe383 }, |
|
1952 { 0x06, 0x49ef }, |
|
1953 { 0x06, 0x65e2 }, |
|
1954 { 0x06, 0x834a }, |
|
1955 { 0x06, 0xe383 }, |
|
1956 { 0x06, 0x4b1b }, |
|
1957 { 0x06, 0x56aa }, |
|
1958 { 0x06, 0x0eef }, |
|
1959 { 0x06, 0x56e6 }, |
|
1960 { 0x06, 0x834a }, |
|
1961 { 0x06, 0xe783 }, |
|
1962 { 0x06, 0x4be2 }, |
|
1963 { 0x06, 0x834d }, |
|
1964 { 0x06, 0xe683 }, |
|
1965 { 0x06, 0x4ce0 }, |
|
1966 { 0x06, 0x834d }, |
|
1967 { 0x06, 0xa000 }, |
|
1968 { 0x06, 0x0caf }, |
|
1969 { 0x06, 0x81dc }, |
|
1970 { 0x06, 0xe083 }, |
|
1971 { 0x06, 0x4d10 }, |
|
1972 { 0x06, 0xe483 }, |
|
1973 { 0x06, 0x4dae }, |
|
1974 { 0x06, 0x0480 }, |
|
1975 { 0x06, 0xe483 }, |
|
1976 { 0x06, 0x4de0 }, |
|
1977 { 0x06, 0x834e }, |
|
1978 { 0x06, 0x7803 }, |
|
1979 { 0x06, 0x9e0b }, |
|
1980 { 0x06, 0xe083 }, |
|
1981 { 0x06, 0x4e78 }, |
|
1982 { 0x06, 0x049e }, |
|
1983 { 0x06, 0x04ee }, |
|
1984 { 0x06, 0x834e }, |
|
1985 { 0x06, 0x02e0 }, |
|
1986 { 0x06, 0x8332 }, |
|
1987 { 0x06, 0xe183 }, |
|
1988 { 0x06, 0x3359 }, |
|
1989 { 0x06, 0x0fe2 }, |
|
1990 { 0x06, 0x834d }, |
|
1991 { 0x06, 0x0c24 }, |
|
1992 { 0x06, 0x5af0 }, |
|
1993 { 0x06, 0x1e12 }, |
|
1994 { 0x06, 0xe4f8 }, |
|
1995 { 0x06, 0x8ce5 }, |
|
1996 { 0x06, 0xf88d }, |
|
1997 { 0x06, 0xe083 }, |
|
1998 { 0x06, 0x30e1 }, |
|
1999 { 0x06, 0x8331 }, |
|
2000 { 0x06, 0x6801 }, |
|
2001 { 0x06, 0xe4f8 }, |
|
2002 { 0x06, 0x8ae5 }, |
|
2003 { 0x06, 0xf88b }, |
|
2004 { 0x06, 0xae37 }, |
|
2005 { 0x06, 0xee83 }, |
|
2006 { 0x06, 0x4e03 }, |
|
2007 { 0x06, 0xe083 }, |
|
2008 { 0x06, 0x4ce1 }, |
|
2009 { 0x06, 0x834d }, |
|
2010 { 0x06, 0x1b01 }, |
|
2011 { 0x06, 0x9e04 }, |
|
2012 { 0x06, 0xaaa1 }, |
|
2013 { 0x06, 0xaea8 }, |
|
2014 { 0x06, 0xee83 }, |
|
2015 { 0x06, 0x4e04 }, |
|
2016 { 0x06, 0xee83 }, |
|
2017 { 0x06, 0x4f00 }, |
|
2018 { 0x06, 0xaeab }, |
|
2019 { 0x06, 0xe083 }, |
|
2020 { 0x06, 0x4f78 }, |
|
2021 { 0x06, 0x039f }, |
|
2022 { 0x06, 0x14ee }, |
|
2023 { 0x06, 0x834e }, |
|
2024 { 0x06, 0x05d2 }, |
|
2025 { 0x06, 0x40d6 }, |
|
2026 { 0x06, 0x5554 }, |
|
2027 { 0x06, 0x0282 }, |
|
2028 { 0x06, 0x17d2 }, |
|
2029 { 0x06, 0xa0d6 }, |
|
2030 { 0x06, 0xba00 }, |
|
2031 { 0x06, 0x0282 }, |
|
2032 { 0x06, 0x17fe }, |
|
2033 { 0x06, 0xfdfc }, |
|
2034 { 0x06, 0x05f8 }, |
|
2035 { 0x06, 0xe0f8 }, |
|
2036 { 0x06, 0x60e1 }, |
|
2037 { 0x06, 0xf861 }, |
|
2038 { 0x06, 0x6802 }, |
|
2039 { 0x06, 0xe4f8 }, |
|
2040 { 0x06, 0x60e5 }, |
|
2041 { 0x06, 0xf861 }, |
|
2042 { 0x06, 0xe0f8 }, |
|
2043 { 0x06, 0x48e1 }, |
|
2044 { 0x06, 0xf849 }, |
|
2045 { 0x06, 0x580f }, |
|
2046 { 0x06, 0x1e02 }, |
|
2047 { 0x06, 0xe4f8 }, |
|
2048 { 0x06, 0x48e5 }, |
|
2049 { 0x06, 0xf849 }, |
|
2050 { 0x06, 0xd000 }, |
|
2051 { 0x06, 0x0282 }, |
|
2052 { 0x06, 0x5bbf }, |
|
2053 { 0x06, 0x8350 }, |
|
2054 { 0x06, 0xef46 }, |
|
2055 { 0x06, 0xdc19 }, |
|
2056 { 0x06, 0xddd0 }, |
|
2057 { 0x06, 0x0102 }, |
|
2058 { 0x06, 0x825b }, |
|
2059 { 0x06, 0x0282 }, |
|
2060 { 0x06, 0x77e0 }, |
|
2061 { 0x06, 0xf860 }, |
|
2062 { 0x06, 0xe1f8 }, |
|
2063 { 0x06, 0x6158 }, |
|
2064 { 0x06, 0xfde4 }, |
|
2065 { 0x06, 0xf860 }, |
|
2066 { 0x06, 0xe5f8 }, |
|
2067 { 0x06, 0x61fc }, |
|
2068 { 0x06, 0x04f9 }, |
|
2069 { 0x06, 0xfafb }, |
|
2070 { 0x06, 0xc6bf }, |
|
2071 { 0x06, 0xf840 }, |
|
2072 { 0x06, 0xbe83 }, |
|
2073 { 0x06, 0x50a0 }, |
|
2074 { 0x06, 0x0101 }, |
|
2075 { 0x06, 0x071b }, |
|
2076 { 0x06, 0x89cf }, |
|
2077 { 0x06, 0xd208 }, |
|
2078 { 0x06, 0xebdb }, |
|
2079 { 0x06, 0x19b2 }, |
|
2080 { 0x06, 0xfbff }, |
|
2081 { 0x06, 0xfefd }, |
|
2082 { 0x06, 0x04f8 }, |
|
2083 { 0x06, 0xe0f8 }, |
|
2084 { 0x06, 0x48e1 }, |
|
2085 { 0x06, 0xf849 }, |
|
2086 { 0x06, 0x6808 }, |
|
2087 { 0x06, 0xe4f8 }, |
|
2088 { 0x06, 0x48e5 }, |
|
2089 { 0x06, 0xf849 }, |
|
2090 { 0x06, 0x58f7 }, |
|
2091 { 0x06, 0xe4f8 }, |
|
2092 { 0x06, 0x48e5 }, |
|
2093 { 0x06, 0xf849 }, |
|
2094 { 0x06, 0xfc04 }, |
|
2095 { 0x06, 0x4d20 }, |
|
2096 { 0x06, 0x0002 }, |
|
2097 { 0x06, 0x4e22 }, |
|
2098 { 0x06, 0x0002 }, |
|
2099 { 0x06, 0x4ddf }, |
|
2100 { 0x06, 0xff01 }, |
|
2101 { 0x06, 0x4edd }, |
|
2102 { 0x06, 0xff01 }, |
|
2103 { 0x05, 0x83d4 }, |
|
2104 { 0x06, 0x8000 }, |
|
2105 { 0x05, 0x83d8 }, |
|
2106 { 0x06, 0x8051 }, |
|
2107 { 0x02, 0x6010 }, |
|
2108 { 0x03, 0xdc00 }, |
|
2109 { 0x05, 0xfff6 }, |
|
2110 { 0x06, 0x00fc }, |
|
2111 { 0x1f, 0x0000 }, |
|
2112 |
|
2113 { 0x1f, 0x0000 }, |
|
2114 { 0x0d, 0xf880 }, |
|
2115 { 0x1f, 0x0000 } |
|
2116 }; |
|
2117 |
|
2118 rtl_phy_write(ioaddr, phy_reg_init_0, ARRAY_SIZE(phy_reg_init_0)); |
|
2119 |
|
2120 mdio_write(ioaddr, 0x1f, 0x0002); |
|
2121 mdio_plus_minus(ioaddr, 0x0b, 0x0010, 0x00ef); |
|
2122 mdio_plus_minus(ioaddr, 0x0c, 0xa200, 0x5d00); |
|
2123 |
|
2124 rtl_phy_write(ioaddr, phy_reg_init_1, ARRAY_SIZE(phy_reg_init_1)); |
|
2125 |
|
2126 if (rtl8168d_efuse_read(ioaddr, 0x01) == 0xb1) { |
|
2127 static const struct phy_reg phy_reg_init[] = { |
|
2128 { 0x1f, 0x0002 }, |
|
2129 { 0x05, 0x669a }, |
|
2130 { 0x1f, 0x0005 }, |
|
2131 { 0x05, 0x8330 }, |
|
2132 { 0x06, 0x669a }, |
|
2133 { 0x1f, 0x0002 } |
|
2134 }; |
|
2135 int val; |
|
2136 |
|
2137 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2138 |
|
2139 val = mdio_read(ioaddr, 0x0d); |
|
2140 |
|
2141 if ((val & 0x00ff) != 0x006c) { |
|
2142 static const u32 set[] = { |
|
2143 0x0065, 0x0066, 0x0067, 0x0068, |
|
2144 0x0069, 0x006a, 0x006b, 0x006c |
|
2145 }; |
|
2146 int i; |
|
2147 |
|
2148 mdio_write(ioaddr, 0x1f, 0x0002); |
|
2149 |
|
2150 val &= 0xff00; |
|
2151 for (i = 0; i < ARRAY_SIZE(set); i++) |
|
2152 mdio_write(ioaddr, 0x0d, val | set[i]); |
|
2153 } |
|
2154 } else { |
|
2155 static const struct phy_reg phy_reg_init[] = { |
|
2156 { 0x1f, 0x0002 }, |
|
2157 { 0x05, 0x6662 }, |
|
2158 { 0x1f, 0x0005 }, |
|
2159 { 0x05, 0x8330 }, |
|
2160 { 0x06, 0x6662 } |
|
2161 }; |
|
2162 |
|
2163 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2164 } |
|
2165 |
|
2166 mdio_write(ioaddr, 0x1f, 0x0002); |
|
2167 mdio_patch(ioaddr, 0x0d, 0x0300); |
|
2168 mdio_patch(ioaddr, 0x0f, 0x0010); |
|
2169 |
|
2170 mdio_write(ioaddr, 0x1f, 0x0002); |
|
2171 mdio_plus_minus(ioaddr, 0x02, 0x0100, 0x0600); |
|
2172 mdio_plus_minus(ioaddr, 0x03, 0x0000, 0xe000); |
|
2173 |
|
2174 rtl_phy_write(ioaddr, phy_reg_init_2, ARRAY_SIZE(phy_reg_init_2)); |
|
2175 } |
|
2176 |
|
2177 static void rtl8168d_2_hw_phy_config(void __iomem *ioaddr) |
|
2178 { |
|
2179 static const struct phy_reg phy_reg_init_0[] = { |
|
2180 { 0x1f, 0x0001 }, |
|
2181 { 0x06, 0x4064 }, |
|
2182 { 0x07, 0x2863 }, |
|
2183 { 0x08, 0x059c }, |
|
2184 { 0x09, 0x26b4 }, |
|
2185 { 0x0a, 0x6a19 }, |
|
2186 { 0x0b, 0xdcc8 }, |
|
2187 { 0x10, 0xf06d }, |
|
2188 { 0x14, 0x7f68 }, |
|
2189 { 0x18, 0x7fd9 }, |
|
2190 { 0x1c, 0xf0ff }, |
|
2191 { 0x1d, 0x3d9c }, |
|
2192 { 0x1f, 0x0003 }, |
|
2193 { 0x12, 0xf49f }, |
|
2194 { 0x13, 0x070b }, |
|
2195 { 0x1a, 0x05ad }, |
|
2196 { 0x14, 0x94c0 }, |
|
2197 |
|
2198 { 0x1f, 0x0002 }, |
|
2199 { 0x06, 0x5561 }, |
|
2200 { 0x1f, 0x0005 }, |
|
2201 { 0x05, 0x8332 }, |
|
2202 { 0x06, 0x5561 } |
|
2203 }; |
|
2204 static const struct phy_reg phy_reg_init_1[] = { |
|
2205 { 0x1f, 0x0005 }, |
|
2206 { 0x05, 0xffc2 }, |
|
2207 { 0x1f, 0x0005 }, |
|
2208 { 0x05, 0x8000 }, |
|
2209 { 0x06, 0xf8f9 }, |
|
2210 { 0x06, 0xfaee }, |
|
2211 { 0x06, 0xf8ea }, |
|
2212 { 0x06, 0x00ee }, |
|
2213 { 0x06, 0xf8eb }, |
|
2214 { 0x06, 0x00e2 }, |
|
2215 { 0x06, 0xf87c }, |
|
2216 { 0x06, 0xe3f8 }, |
|
2217 { 0x06, 0x7da5 }, |
|
2218 { 0x06, 0x1111 }, |
|
2219 { 0x06, 0x12d2 }, |
|
2220 { 0x06, 0x40d6 }, |
|
2221 { 0x06, 0x4444 }, |
|
2222 { 0x06, 0x0281 }, |
|
2223 { 0x06, 0xc6d2 }, |
|
2224 { 0x06, 0xa0d6 }, |
|
2225 { 0x06, 0xaaaa }, |
|
2226 { 0x06, 0x0281 }, |
|
2227 { 0x06, 0xc6ae }, |
|
2228 { 0x06, 0x0fa5 }, |
|
2229 { 0x06, 0x4444 }, |
|
2230 { 0x06, 0x02ae }, |
|
2231 { 0x06, 0x4da5 }, |
|
2232 { 0x06, 0xaaaa }, |
|
2233 { 0x06, 0x02ae }, |
|
2234 { 0x06, 0x47af }, |
|
2235 { 0x06, 0x81c2 }, |
|
2236 { 0x06, 0xee83 }, |
|
2237 { 0x06, 0x4e00 }, |
|
2238 { 0x06, 0xee83 }, |
|
2239 { 0x06, 0x4d0f }, |
|
2240 { 0x06, 0xee83 }, |
|
2241 { 0x06, 0x4c0f }, |
|
2242 { 0x06, 0xee83 }, |
|
2243 { 0x06, 0x4f00 }, |
|
2244 { 0x06, 0xee83 }, |
|
2245 { 0x06, 0x5100 }, |
|
2246 { 0x06, 0xee83 }, |
|
2247 { 0x06, 0x4aff }, |
|
2248 { 0x06, 0xee83 }, |
|
2249 { 0x06, 0x4bff }, |
|
2250 { 0x06, 0xe083 }, |
|
2251 { 0x06, 0x30e1 }, |
|
2252 { 0x06, 0x8331 }, |
|
2253 { 0x06, 0x58fe }, |
|
2254 { 0x06, 0xe4f8 }, |
|
2255 { 0x06, 0x8ae5 }, |
|
2256 { 0x06, 0xf88b }, |
|
2257 { 0x06, 0xe083 }, |
|
2258 { 0x06, 0x32e1 }, |
|
2259 { 0x06, 0x8333 }, |
|
2260 { 0x06, 0x590f }, |
|
2261 { 0x06, 0xe283 }, |
|
2262 { 0x06, 0x4d0c }, |
|
2263 { 0x06, 0x245a }, |
|
2264 { 0x06, 0xf01e }, |
|
2265 { 0x06, 0x12e4 }, |
|
2266 { 0x06, 0xf88c }, |
|
2267 { 0x06, 0xe5f8 }, |
|
2268 { 0x06, 0x8daf }, |
|
2269 { 0x06, 0x81c2 }, |
|
2270 { 0x06, 0xe083 }, |
|
2271 { 0x06, 0x4f10 }, |
|
2272 { 0x06, 0xe483 }, |
|
2273 { 0x06, 0x4fe0 }, |
|
2274 { 0x06, 0x834e }, |
|
2275 { 0x06, 0x7800 }, |
|
2276 { 0x06, 0x9f0a }, |
|
2277 { 0x06, 0xe083 }, |
|
2278 { 0x06, 0x4fa0 }, |
|
2279 { 0x06, 0x10a5 }, |
|
2280 { 0x06, 0xee83 }, |
|
2281 { 0x06, 0x4e01 }, |
|
2282 { 0x06, 0xe083 }, |
|
2283 { 0x06, 0x4e78 }, |
|
2284 { 0x06, 0x059e }, |
|
2285 { 0x06, 0x9ae0 }, |
|
2286 { 0x06, 0x834e }, |
|
2287 { 0x06, 0x7804 }, |
|
2288 { 0x06, 0x9e10 }, |
|
2289 { 0x06, 0xe083 }, |
|
2290 { 0x06, 0x4e78 }, |
|
2291 { 0x06, 0x039e }, |
|
2292 { 0x06, 0x0fe0 }, |
|
2293 { 0x06, 0x834e }, |
|
2294 { 0x06, 0x7801 }, |
|
2295 { 0x06, 0x9e05 }, |
|
2296 { 0x06, 0xae0c }, |
|
2297 { 0x06, 0xaf81 }, |
|
2298 { 0x06, 0xa7af }, |
|
2299 { 0x06, 0x8152 }, |
|
2300 { 0x06, 0xaf81 }, |
|
2301 { 0x06, 0x8baf }, |
|
2302 { 0x06, 0x81c2 }, |
|
2303 { 0x06, 0xee83 }, |
|
2304 { 0x06, 0x4800 }, |
|
2305 { 0x06, 0xee83 }, |
|
2306 { 0x06, 0x4900 }, |
|
2307 { 0x06, 0xe083 }, |
|
2308 { 0x06, 0x5110 }, |
|
2309 { 0x06, 0xe483 }, |
|
2310 { 0x06, 0x5158 }, |
|
2311 { 0x06, 0x019f }, |
|
2312 { 0x06, 0xead0 }, |
|
2313 { 0x06, 0x00d1 }, |
|
2314 { 0x06, 0x801f }, |
|
2315 { 0x06, 0x66e2 }, |
|
2316 { 0x06, 0xf8ea }, |
|
2317 { 0x06, 0xe3f8 }, |
|
2318 { 0x06, 0xeb5a }, |
|
2319 { 0x06, 0xf81e }, |
|
2320 { 0x06, 0x20e6 }, |
|
2321 { 0x06, 0xf8ea }, |
|
2322 { 0x06, 0xe5f8 }, |
|
2323 { 0x06, 0xebd3 }, |
|
2324 { 0x06, 0x02b3 }, |
|
2325 { 0x06, 0xfee2 }, |
|
2326 { 0x06, 0xf87c }, |
|
2327 { 0x06, 0xef32 }, |
|
2328 { 0x06, 0x5b80 }, |
|
2329 { 0x06, 0xe3f8 }, |
|
2330 { 0x06, 0x7d9e }, |
|
2331 { 0x06, 0x037d }, |
|
2332 { 0x06, 0xffff }, |
|
2333 { 0x06, 0x0d58 }, |
|
2334 { 0x06, 0x1c55 }, |
|
2335 { 0x06, 0x1a65 }, |
|
2336 { 0x06, 0x11a1 }, |
|
2337 { 0x06, 0x90d3 }, |
|
2338 { 0x06, 0xe283 }, |
|
2339 { 0x06, 0x48e3 }, |
|
2340 { 0x06, 0x8349 }, |
|
2341 { 0x06, 0x1b56 }, |
|
2342 { 0x06, 0xab08 }, |
|
2343 { 0x06, 0xef56 }, |
|
2344 { 0x06, 0xe683 }, |
|
2345 { 0x06, 0x48e7 }, |
|
2346 { 0x06, 0x8349 }, |
|
2347 { 0x06, 0x10d1 }, |
|
2348 { 0x06, 0x801f }, |
|
2349 { 0x06, 0x66a0 }, |
|
2350 { 0x06, 0x04b9 }, |
|
2351 { 0x06, 0xe283 }, |
|
2352 { 0x06, 0x48e3 }, |
|
2353 { 0x06, 0x8349 }, |
|
2354 { 0x06, 0xef65 }, |
|
2355 { 0x06, 0xe283 }, |
|
2356 { 0x06, 0x4ae3 }, |
|
2357 { 0x06, 0x834b }, |
|
2358 { 0x06, 0x1b56 }, |
|
2359 { 0x06, 0xaa0e }, |
|
2360 { 0x06, 0xef56 }, |
|
2361 { 0x06, 0xe683 }, |
|
2362 { 0x06, 0x4ae7 }, |
|
2363 { 0x06, 0x834b }, |
|
2364 { 0x06, 0xe283 }, |
|
2365 { 0x06, 0x4de6 }, |
|
2366 { 0x06, 0x834c }, |
|
2367 { 0x06, 0xe083 }, |
|
2368 { 0x06, 0x4da0 }, |
|
2369 { 0x06, 0x000c }, |
|
2370 { 0x06, 0xaf81 }, |
|
2371 { 0x06, 0x8be0 }, |
|
2372 { 0x06, 0x834d }, |
|
2373 { 0x06, 0x10e4 }, |
|
2374 { 0x06, 0x834d }, |
|
2375 { 0x06, 0xae04 }, |
|
2376 { 0x06, 0x80e4 }, |
|
2377 { 0x06, 0x834d }, |
|
2378 { 0x06, 0xe083 }, |
|
2379 { 0x06, 0x4e78 }, |
|
2380 { 0x06, 0x039e }, |
|
2381 { 0x06, 0x0be0 }, |
|
2382 { 0x06, 0x834e }, |
|
2383 { 0x06, 0x7804 }, |
|
2384 { 0x06, 0x9e04 }, |
|
2385 { 0x06, 0xee83 }, |
|
2386 { 0x06, 0x4e02 }, |
|
2387 { 0x06, 0xe083 }, |
|
2388 { 0x06, 0x32e1 }, |
|
2389 { 0x06, 0x8333 }, |
|
2390 { 0x06, 0x590f }, |
|
2391 { 0x06, 0xe283 }, |
|
2392 { 0x06, 0x4d0c }, |
|
2393 { 0x06, 0x245a }, |
|
2394 { 0x06, 0xf01e }, |
|
2395 { 0x06, 0x12e4 }, |
|
2396 { 0x06, 0xf88c }, |
|
2397 { 0x06, 0xe5f8 }, |
|
2398 { 0x06, 0x8de0 }, |
|
2399 { 0x06, 0x8330 }, |
|
2400 { 0x06, 0xe183 }, |
|
2401 { 0x06, 0x3168 }, |
|
2402 { 0x06, 0x01e4 }, |
|
2403 { 0x06, 0xf88a }, |
|
2404 { 0x06, 0xe5f8 }, |
|
2405 { 0x06, 0x8bae }, |
|
2406 { 0x06, 0x37ee }, |
|
2407 { 0x06, 0x834e }, |
|
2408 { 0x06, 0x03e0 }, |
|
2409 { 0x06, 0x834c }, |
|
2410 { 0x06, 0xe183 }, |
|
2411 { 0x06, 0x4d1b }, |
|
2412 { 0x06, 0x019e }, |
|
2413 { 0x06, 0x04aa }, |
|
2414 { 0x06, 0xa1ae }, |
|
2415 { 0x06, 0xa8ee }, |
|
2416 { 0x06, 0x834e }, |
|
2417 { 0x06, 0x04ee }, |
|
2418 { 0x06, 0x834f }, |
|
2419 { 0x06, 0x00ae }, |
|
2420 { 0x06, 0xabe0 }, |
|
2421 { 0x06, 0x834f }, |
|
2422 { 0x06, 0x7803 }, |
|
2423 { 0x06, 0x9f14 }, |
|
2424 { 0x06, 0xee83 }, |
|
2425 { 0x06, 0x4e05 }, |
|
2426 { 0x06, 0xd240 }, |
|
2427 { 0x06, 0xd655 }, |
|
2428 { 0x06, 0x5402 }, |
|
2429 { 0x06, 0x81c6 }, |
|
2430 { 0x06, 0xd2a0 }, |
|
2431 { 0x06, 0xd6ba }, |
|
2432 { 0x06, 0x0002 }, |
|
2433 { 0x06, 0x81c6 }, |
|
2434 { 0x06, 0xfefd }, |
|
2435 { 0x06, 0xfc05 }, |
|
2436 { 0x06, 0xf8e0 }, |
|
2437 { 0x06, 0xf860 }, |
|
2438 { 0x06, 0xe1f8 }, |
|
2439 { 0x06, 0x6168 }, |
|
2440 { 0x06, 0x02e4 }, |
|
2441 { 0x06, 0xf860 }, |
|
2442 { 0x06, 0xe5f8 }, |
|
2443 { 0x06, 0x61e0 }, |
|
2444 { 0x06, 0xf848 }, |
|
2445 { 0x06, 0xe1f8 }, |
|
2446 { 0x06, 0x4958 }, |
|
2447 { 0x06, 0x0f1e }, |
|
2448 { 0x06, 0x02e4 }, |
|
2449 { 0x06, 0xf848 }, |
|
2450 { 0x06, 0xe5f8 }, |
|
2451 { 0x06, 0x49d0 }, |
|
2452 { 0x06, 0x0002 }, |
|
2453 { 0x06, 0x820a }, |
|
2454 { 0x06, 0xbf83 }, |
|
2455 { 0x06, 0x50ef }, |
|
2456 { 0x06, 0x46dc }, |
|
2457 { 0x06, 0x19dd }, |
|
2458 { 0x06, 0xd001 }, |
|
2459 { 0x06, 0x0282 }, |
|
2460 { 0x06, 0x0a02 }, |
|
2461 { 0x06, 0x8226 }, |
|
2462 { 0x06, 0xe0f8 }, |
|
2463 { 0x06, 0x60e1 }, |
|
2464 { 0x06, 0xf861 }, |
|
2465 { 0x06, 0x58fd }, |
|
2466 { 0x06, 0xe4f8 }, |
|
2467 { 0x06, 0x60e5 }, |
|
2468 { 0x06, 0xf861 }, |
|
2469 { 0x06, 0xfc04 }, |
|
2470 { 0x06, 0xf9fa }, |
|
2471 { 0x06, 0xfbc6 }, |
|
2472 { 0x06, 0xbff8 }, |
|
2473 { 0x06, 0x40be }, |
|
2474 { 0x06, 0x8350 }, |
|
2475 { 0x06, 0xa001 }, |
|
2476 { 0x06, 0x0107 }, |
|
2477 { 0x06, 0x1b89 }, |
|
2478 { 0x06, 0xcfd2 }, |
|
2479 { 0x06, 0x08eb }, |
|
2480 { 0x06, 0xdb19 }, |
|
2481 { 0x06, 0xb2fb }, |
|
2482 { 0x06, 0xfffe }, |
|
2483 { 0x06, 0xfd04 }, |
|
2484 { 0x06, 0xf8e0 }, |
|
2485 { 0x06, 0xf848 }, |
|
2486 { 0x06, 0xe1f8 }, |
|
2487 { 0x06, 0x4968 }, |
|
2488 { 0x06, 0x08e4 }, |
|
2489 { 0x06, 0xf848 }, |
|
2490 { 0x06, 0xe5f8 }, |
|
2491 { 0x06, 0x4958 }, |
|
2492 { 0x06, 0xf7e4 }, |
|
2493 { 0x06, 0xf848 }, |
|
2494 { 0x06, 0xe5f8 }, |
|
2495 { 0x06, 0x49fc }, |
|
2496 { 0x06, 0x044d }, |
|
2497 { 0x06, 0x2000 }, |
|
2498 { 0x06, 0x024e }, |
|
2499 { 0x06, 0x2200 }, |
|
2500 { 0x06, 0x024d }, |
|
2501 { 0x06, 0xdfff }, |
|
2502 { 0x06, 0x014e }, |
|
2503 { 0x06, 0xddff }, |
|
2504 { 0x06, 0x0100 }, |
|
2505 { 0x05, 0x83d8 }, |
|
2506 { 0x06, 0x8000 }, |
|
2507 { 0x03, 0xdc00 }, |
|
2508 { 0x05, 0xfff6 }, |
|
2509 { 0x06, 0x00fc }, |
|
2510 { 0x1f, 0x0000 }, |
|
2511 |
|
2512 { 0x1f, 0x0000 }, |
|
2513 { 0x0d, 0xf880 }, |
|
2514 { 0x1f, 0x0000 } |
|
2515 }; |
|
2516 |
|
2517 rtl_phy_write(ioaddr, phy_reg_init_0, ARRAY_SIZE(phy_reg_init_0)); |
|
2518 |
|
2519 if (rtl8168d_efuse_read(ioaddr, 0x01) == 0xb1) { |
|
2520 static const struct phy_reg phy_reg_init[] = { |
|
2521 { 0x1f, 0x0002 }, |
|
2522 { 0x05, 0x669a }, |
|
2523 { 0x1f, 0x0005 }, |
|
2524 { 0x05, 0x8330 }, |
|
2525 { 0x06, 0x669a }, |
|
2526 |
|
2527 { 0x1f, 0x0002 } |
|
2528 }; |
|
2529 int val; |
|
2530 |
|
2531 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2532 |
|
2533 val = mdio_read(ioaddr, 0x0d); |
|
2534 if ((val & 0x00ff) != 0x006c) { |
|
2535 u32 set[] = { |
|
2536 0x0065, 0x0066, 0x0067, 0x0068, |
|
2537 0x0069, 0x006a, 0x006b, 0x006c |
|
2538 }; |
|
2539 int i; |
|
2540 |
|
2541 mdio_write(ioaddr, 0x1f, 0x0002); |
|
2542 |
|
2543 val &= 0xff00; |
|
2544 for (i = 0; i < ARRAY_SIZE(set); i++) |
|
2545 mdio_write(ioaddr, 0x0d, val | set[i]); |
|
2546 } |
|
2547 } else { |
|
2548 static const struct phy_reg phy_reg_init[] = { |
|
2549 { 0x1f, 0x0002 }, |
|
2550 { 0x05, 0x2642 }, |
|
2551 { 0x1f, 0x0005 }, |
|
2552 { 0x05, 0x8330 }, |
|
2553 { 0x06, 0x2642 } |
|
2554 }; |
|
2555 |
|
2556 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2557 } |
|
2558 |
|
2559 mdio_write(ioaddr, 0x1f, 0x0002); |
|
2560 mdio_plus_minus(ioaddr, 0x02, 0x0100, 0x0600); |
|
2561 mdio_plus_minus(ioaddr, 0x03, 0x0000, 0xe000); |
|
2562 |
|
2563 mdio_write(ioaddr, 0x1f, 0x0001); |
|
2564 mdio_write(ioaddr, 0x17, 0x0cc0); |
|
2565 |
|
2566 mdio_write(ioaddr, 0x1f, 0x0002); |
|
2567 mdio_patch(ioaddr, 0x0f, 0x0017); |
|
2568 |
|
2569 rtl_phy_write(ioaddr, phy_reg_init_1, ARRAY_SIZE(phy_reg_init_1)); |
|
2570 } |
|
2571 |
|
2572 static void rtl8168d_3_hw_phy_config(void __iomem *ioaddr) |
|
2573 { |
|
2574 static const struct phy_reg phy_reg_init[] = { |
|
2575 { 0x1f, 0x0002 }, |
|
2576 { 0x10, 0x0008 }, |
|
2577 { 0x0d, 0x006c }, |
|
2578 |
|
2579 { 0x1f, 0x0000 }, |
|
2580 { 0x0d, 0xf880 }, |
|
2581 |
|
2582 { 0x1f, 0x0001 }, |
|
2583 { 0x17, 0x0cc0 }, |
|
2584 |
|
2585 { 0x1f, 0x0001 }, |
|
2586 { 0x0b, 0xa4d8 }, |
|
2587 { 0x09, 0x281c }, |
|
2588 { 0x07, 0x2883 }, |
|
2589 { 0x0a, 0x6b35 }, |
|
2590 { 0x1d, 0x3da4 }, |
|
2591 { 0x1c, 0xeffd }, |
|
2592 { 0x14, 0x7f52 }, |
|
2593 { 0x18, 0x7fc6 }, |
|
2594 { 0x08, 0x0601 }, |
|
2595 { 0x06, 0x4063 }, |
|
2596 { 0x10, 0xf074 }, |
|
2597 { 0x1f, 0x0003 }, |
|
2598 { 0x13, 0x0789 }, |
|
2599 { 0x12, 0xf4bd }, |
|
2600 { 0x1a, 0x04fd }, |
|
2601 { 0x14, 0x84b0 }, |
|
2602 { 0x1f, 0x0000 }, |
|
2603 { 0x00, 0x9200 }, |
|
2604 |
|
2605 { 0x1f, 0x0005 }, |
|
2606 { 0x01, 0x0340 }, |
|
2607 { 0x1f, 0x0001 }, |
|
2608 { 0x04, 0x4000 }, |
|
2609 { 0x03, 0x1d21 }, |
|
2610 { 0x02, 0x0c32 }, |
|
2611 { 0x01, 0x0200 }, |
|
2612 { 0x00, 0x5554 }, |
|
2613 { 0x04, 0x4800 }, |
|
2614 { 0x04, 0x4000 }, |
|
2615 { 0x04, 0xf000 }, |
|
2616 { 0x03, 0xdf01 }, |
|
2617 { 0x02, 0xdf20 }, |
|
2618 { 0x01, 0x101a }, |
|
2619 { 0x00, 0xa0ff }, |
|
2620 { 0x04, 0xf800 }, |
|
2621 { 0x04, 0xf000 }, |
|
2622 { 0x1f, 0x0000 }, |
|
2623 |
|
2624 { 0x1f, 0x0007 }, |
|
2625 { 0x1e, 0x0023 }, |
|
2626 { 0x16, 0x0000 }, |
|
2627 { 0x1f, 0x0000 } |
|
2628 }; |
|
2629 |
|
2630 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2631 } |
|
2632 |
|
2633 static void rtl8102e_hw_phy_config(void __iomem *ioaddr) |
|
2634 { |
|
2635 static const struct phy_reg phy_reg_init[] = { |
|
2636 { 0x1f, 0x0003 }, |
|
2637 { 0x08, 0x441d }, |
|
2638 { 0x01, 0x9100 }, |
|
2639 { 0x1f, 0x0000 } |
|
2640 }; |
|
2641 |
|
2642 mdio_write(ioaddr, 0x1f, 0x0000); |
|
2643 mdio_patch(ioaddr, 0x11, 1 << 12); |
|
2644 mdio_patch(ioaddr, 0x19, 1 << 13); |
|
2645 mdio_patch(ioaddr, 0x10, 1 << 15); |
|
2646 |
|
2647 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2648 } |
|
2649 |
|
2650 static void rtl_hw_phy_config(struct net_device *dev) |
|
2651 { |
|
2652 struct rtl8169_private *tp = netdev_priv(dev); |
|
2653 void __iomem *ioaddr = tp->mmio_addr; |
|
2654 |
|
2655 rtl8169_print_mac_version(tp); |
|
2656 |
|
2657 switch (tp->mac_version) { |
|
2658 case RTL_GIGA_MAC_VER_01: |
|
2659 break; |
|
2660 case RTL_GIGA_MAC_VER_02: |
|
2661 case RTL_GIGA_MAC_VER_03: |
|
2662 rtl8169s_hw_phy_config(ioaddr); |
|
2663 break; |
|
2664 case RTL_GIGA_MAC_VER_04: |
|
2665 rtl8169sb_hw_phy_config(ioaddr); |
|
2666 break; |
|
2667 case RTL_GIGA_MAC_VER_05: |
|
2668 rtl8169scd_hw_phy_config(tp, ioaddr); |
|
2669 break; |
|
2670 case RTL_GIGA_MAC_VER_06: |
|
2671 rtl8169sce_hw_phy_config(ioaddr); |
|
2672 break; |
|
2673 case RTL_GIGA_MAC_VER_07: |
|
2674 case RTL_GIGA_MAC_VER_08: |
|
2675 case RTL_GIGA_MAC_VER_09: |
|
2676 rtl8102e_hw_phy_config(ioaddr); |
|
2677 break; |
|
2678 case RTL_GIGA_MAC_VER_11: |
|
2679 rtl8168bb_hw_phy_config(ioaddr); |
|
2680 break; |
|
2681 case RTL_GIGA_MAC_VER_12: |
|
2682 rtl8168bef_hw_phy_config(ioaddr); |
|
2683 break; |
|
2684 case RTL_GIGA_MAC_VER_17: |
|
2685 rtl8168bef_hw_phy_config(ioaddr); |
|
2686 break; |
|
2687 case RTL_GIGA_MAC_VER_18: |
|
2688 rtl8168cp_1_hw_phy_config(ioaddr); |
|
2689 break; |
|
2690 case RTL_GIGA_MAC_VER_19: |
|
2691 rtl8168c_1_hw_phy_config(ioaddr); |
|
2692 break; |
|
2693 case RTL_GIGA_MAC_VER_20: |
|
2694 rtl8168c_2_hw_phy_config(ioaddr); |
|
2695 break; |
|
2696 case RTL_GIGA_MAC_VER_21: |
|
2697 rtl8168c_3_hw_phy_config(ioaddr); |
|
2698 break; |
|
2699 case RTL_GIGA_MAC_VER_22: |
|
2700 rtl8168c_4_hw_phy_config(ioaddr); |
|
2701 break; |
|
2702 case RTL_GIGA_MAC_VER_23: |
|
2703 case RTL_GIGA_MAC_VER_24: |
|
2704 rtl8168cp_2_hw_phy_config(ioaddr); |
|
2705 break; |
|
2706 case RTL_GIGA_MAC_VER_25: |
|
2707 rtl8168d_1_hw_phy_config(ioaddr); |
|
2708 break; |
|
2709 case RTL_GIGA_MAC_VER_26: |
|
2710 rtl8168d_2_hw_phy_config(ioaddr); |
|
2711 break; |
|
2712 case RTL_GIGA_MAC_VER_27: |
|
2713 rtl8168d_3_hw_phy_config(ioaddr); |
|
2714 break; |
|
2715 |
|
2716 default: |
|
2717 break; |
|
2718 } |
|
2719 } |
|
2720 |
|
2721 static void rtl8169_phy_timer(unsigned long __opaque) |
|
2722 { |
|
2723 struct net_device *dev = (struct net_device *)__opaque; |
|
2724 struct rtl8169_private *tp = netdev_priv(dev); |
|
2725 struct timer_list *timer = &tp->timer; |
|
2726 void __iomem *ioaddr = tp->mmio_addr; |
|
2727 unsigned long timeout = RTL8169_PHY_TIMEOUT; |
|
2728 |
|
2729 assert(tp->mac_version > RTL_GIGA_MAC_VER_01); |
|
2730 |
|
2731 if (!(tp->phy_1000_ctrl_reg & ADVERTISE_1000FULL)) |
|
2732 return; |
|
2733 |
|
2734 if (!tp->ecdev) |
|
2735 spin_lock_irq(&tp->lock); |
|
2736 |
|
2737 if (tp->phy_reset_pending(ioaddr)) { |
|
2738 /* |
|
2739 * A busy loop could burn quite a few cycles on nowadays CPU. |
|
2740 * Let's delay the execution of the timer for a few ticks. |
|
2741 */ |
|
2742 timeout = HZ/10; |
|
2743 goto out_mod_timer; |
|
2744 } |
|
2745 |
|
2746 if (tp->link_ok(ioaddr)) |
|
2747 goto out_unlock; |
|
2748 |
|
2749 netif_warn(tp, link, dev, "PHY reset until link up\n"); |
|
2750 |
|
2751 tp->phy_reset_enable(ioaddr); |
|
2752 |
|
2753 out_mod_timer: |
|
2754 if (!tp->ecdev) |
|
2755 mod_timer(timer, jiffies + timeout); |
|
2756 out_unlock: |
|
2757 if (!tp->ecdev) |
|
2758 spin_unlock_irq(&tp->lock); |
|
2759 } |
|
2760 |
|
2761 static inline void rtl8169_delete_timer(struct net_device *dev) |
|
2762 { |
|
2763 struct rtl8169_private *tp = netdev_priv(dev); |
|
2764 struct timer_list *timer = &tp->timer; |
|
2765 |
|
2766 if (tp->ecdev || tp->mac_version <= RTL_GIGA_MAC_VER_01) |
|
2767 return; |
|
2768 |
|
2769 del_timer_sync(timer); |
|
2770 } |
|
2771 |
|
2772 static inline void rtl8169_request_timer(struct net_device *dev) |
|
2773 { |
|
2774 struct rtl8169_private *tp = netdev_priv(dev); |
|
2775 struct timer_list *timer = &tp->timer; |
|
2776 |
|
2777 if (tp->ecdev || tp->mac_version <= RTL_GIGA_MAC_VER_01) |
|
2778 return; |
|
2779 |
|
2780 mod_timer(timer, jiffies + RTL8169_PHY_TIMEOUT); |
|
2781 } |
|
2782 |
|
2783 #ifdef CONFIG_NET_POLL_CONTROLLER |
|
2784 /* |
|
2785 * Polling 'interrupt' - used by things like netconsole to send skbs |
|
2786 * without having to re-enable interrupts. It's not called while |
|
2787 * the interrupt routine is executing. |
|
2788 */ |
|
2789 static void rtl8169_netpoll(struct net_device *dev) |
|
2790 { |
|
2791 struct rtl8169_private *tp = netdev_priv(dev); |
|
2792 struct pci_dev *pdev = tp->pci_dev; |
|
2793 |
|
2794 disable_irq(pdev->irq); |
|
2795 rtl8169_interrupt(pdev->irq, dev); |
|
2796 enable_irq(pdev->irq); |
|
2797 } |
|
2798 #endif |
|
2799 |
|
2800 static void rtl8169_release_board(struct pci_dev *pdev, struct net_device *dev, |
|
2801 void __iomem *ioaddr) |
|
2802 { |
|
2803 iounmap(ioaddr); |
|
2804 pci_release_regions(pdev); |
|
2805 pci_clear_mwi(pdev); |
|
2806 pci_disable_device(pdev); |
|
2807 free_netdev(dev); |
|
2808 } |
|
2809 |
|
2810 static void rtl8169_phy_reset(struct net_device *dev, |
|
2811 struct rtl8169_private *tp) |
|
2812 { |
|
2813 void __iomem *ioaddr = tp->mmio_addr; |
|
2814 unsigned int i; |
|
2815 |
|
2816 tp->phy_reset_enable(ioaddr); |
|
2817 for (i = 0; i < 100; i++) { |
|
2818 if (!tp->phy_reset_pending(ioaddr)) |
|
2819 return; |
|
2820 msleep(1); |
|
2821 } |
|
2822 netif_err(tp, link, dev, "PHY reset failed\n"); |
|
2823 } |
|
2824 |
|
2825 static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp) |
|
2826 { |
|
2827 void __iomem *ioaddr = tp->mmio_addr; |
|
2828 |
|
2829 rtl_hw_phy_config(dev); |
|
2830 |
|
2831 if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
|
2832 dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
|
2833 RTL_W8(0x82, 0x01); |
|
2834 } |
|
2835 |
|
2836 pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); |
|
2837 |
|
2838 if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
|
2839 pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
|
2840 |
|
2841 if (tp->mac_version == RTL_GIGA_MAC_VER_02) { |
|
2842 dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
|
2843 RTL_W8(0x82, 0x01); |
|
2844 dprintk("Set PHY Reg 0x0bh = 0x00h\n"); |
|
2845 mdio_write(ioaddr, 0x0b, 0x0000); //w 0x0b 15 0 0 |
|
2846 } |
|
2847 |
|
2848 rtl8169_phy_reset(dev, tp); |
|
2849 |
|
2850 /* |
|
2851 * rtl8169_set_speed_xmii takes good care of the Fast Ethernet |
|
2852 * only 8101. Don't panic. |
|
2853 */ |
|
2854 rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL); |
|
2855 |
|
2856 if (RTL_R8(PHYstatus) & TBI_Enable) |
|
2857 netif_info(tp, link, dev, "TBI auto-negotiating\n"); |
|
2858 } |
|
2859 |
|
2860 static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr) |
|
2861 { |
|
2862 void __iomem *ioaddr = tp->mmio_addr; |
|
2863 u32 high; |
|
2864 u32 low; |
|
2865 |
|
2866 low = addr[0] | (addr[1] << 8) | (addr[2] << 16) | (addr[3] << 24); |
|
2867 high = addr[4] | (addr[5] << 8); |
|
2868 |
|
2869 spin_lock_irq(&tp->lock); |
|
2870 |
|
2871 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
2872 |
|
2873 RTL_W32(MAC4, high); |
|
2874 RTL_R32(MAC4); |
|
2875 |
|
2876 RTL_W32(MAC0, low); |
|
2877 RTL_R32(MAC0); |
|
2878 |
|
2879 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
2880 |
|
2881 spin_unlock_irq(&tp->lock); |
|
2882 } |
|
2883 |
|
2884 static int rtl_set_mac_address(struct net_device *dev, void *p) |
|
2885 { |
|
2886 struct rtl8169_private *tp = netdev_priv(dev); |
|
2887 struct sockaddr *addr = p; |
|
2888 |
|
2889 if (!is_valid_ether_addr(addr->sa_data)) |
|
2890 return -EADDRNOTAVAIL; |
|
2891 |
|
2892 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
|
2893 |
|
2894 rtl_rar_set(tp, dev->dev_addr); |
|
2895 |
|
2896 return 0; |
|
2897 } |
|
2898 |
|
2899 static int rtl8169_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
|
2900 { |
|
2901 struct rtl8169_private *tp = netdev_priv(dev); |
|
2902 struct mii_ioctl_data *data = if_mii(ifr); |
|
2903 |
|
2904 return netif_running(dev) ? tp->do_ioctl(tp, data, cmd) : -ENODEV; |
|
2905 } |
|
2906 |
|
2907 static int rtl_xmii_ioctl(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd) |
|
2908 { |
|
2909 switch (cmd) { |
|
2910 case SIOCGMIIPHY: |
|
2911 data->phy_id = 32; /* Internal PHY */ |
|
2912 return 0; |
|
2913 |
|
2914 case SIOCGMIIREG: |
|
2915 data->val_out = mdio_read(tp->mmio_addr, data->reg_num & 0x1f); |
|
2916 return 0; |
|
2917 |
|
2918 case SIOCSMIIREG: |
|
2919 mdio_write(tp->mmio_addr, data->reg_num & 0x1f, data->val_in); |
|
2920 return 0; |
|
2921 } |
|
2922 return -EOPNOTSUPP; |
|
2923 } |
|
2924 |
|
2925 static int rtl_tbi_ioctl(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd) |
|
2926 { |
|
2927 return -EOPNOTSUPP; |
|
2928 } |
|
2929 |
|
2930 static const struct rtl_cfg_info { |
|
2931 void (*hw_start)(struct net_device *); |
|
2932 unsigned int region; |
|
2933 unsigned int align; |
|
2934 u16 intr_event; |
|
2935 u16 napi_event; |
|
2936 unsigned features; |
|
2937 u8 default_ver; |
|
2938 } rtl_cfg_infos [] = { |
|
2939 [RTL_CFG_0] = { |
|
2940 .hw_start = rtl_hw_start_8169, |
|
2941 .region = 1, |
|
2942 .align = 0, |
|
2943 .intr_event = SYSErr | LinkChg | RxOverflow | |
|
2944 RxFIFOOver | TxErr | TxOK | RxOK | RxErr, |
|
2945 .napi_event = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow, |
|
2946 .features = RTL_FEATURE_GMII, |
|
2947 .default_ver = RTL_GIGA_MAC_VER_01, |
|
2948 }, |
|
2949 [RTL_CFG_1] = { |
|
2950 .hw_start = rtl_hw_start_8168, |
|
2951 .region = 2, |
|
2952 .align = 8, |
|
2953 .intr_event = SYSErr | RxFIFOOver | LinkChg | RxOverflow | |
|
2954 TxErr | TxOK | RxOK | RxErr, |
|
2955 .napi_event = TxErr | TxOK | RxOK | RxOverflow, |
|
2956 .features = RTL_FEATURE_GMII | RTL_FEATURE_MSI, |
|
2957 .default_ver = RTL_GIGA_MAC_VER_11, |
|
2958 }, |
|
2959 [RTL_CFG_2] = { |
|
2960 .hw_start = rtl_hw_start_8101, |
|
2961 .region = 2, |
|
2962 .align = 8, |
|
2963 .intr_event = SYSErr | LinkChg | RxOverflow | PCSTimeout | |
|
2964 RxFIFOOver | TxErr | TxOK | RxOK | RxErr, |
|
2965 .napi_event = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow, |
|
2966 .features = RTL_FEATURE_MSI, |
|
2967 .default_ver = RTL_GIGA_MAC_VER_13, |
|
2968 } |
|
2969 }; |
|
2970 |
|
2971 /* Cfg9346_Unlock assumed. */ |
|
2972 static unsigned rtl_try_msi(struct pci_dev *pdev, void __iomem *ioaddr, |
|
2973 const struct rtl_cfg_info *cfg) |
|
2974 { |
|
2975 unsigned msi = 0; |
|
2976 u8 cfg2; |
|
2977 |
|
2978 cfg2 = RTL_R8(Config2) & ~MSIEnable; |
|
2979 if (cfg->features & RTL_FEATURE_MSI) { |
|
2980 if (pci_enable_msi(pdev)) { |
|
2981 dev_info(&pdev->dev, "no MSI. Back to INTx.\n"); |
|
2982 } else { |
|
2983 cfg2 |= MSIEnable; |
|
2984 msi = RTL_FEATURE_MSI; |
|
2985 } |
|
2986 } |
|
2987 RTL_W8(Config2, cfg2); |
|
2988 return msi; |
|
2989 } |
|
2990 |
|
2991 static void rtl_disable_msi(struct pci_dev *pdev, struct rtl8169_private *tp) |
|
2992 { |
|
2993 if (tp->features & RTL_FEATURE_MSI) { |
|
2994 pci_disable_msi(pdev); |
|
2995 tp->features &= ~RTL_FEATURE_MSI; |
|
2996 } |
|
2997 } |
|
2998 |
|
2999 static const struct net_device_ops rtl8169_netdev_ops = { |
|
3000 .ndo_open = rtl8169_open, |
|
3001 .ndo_stop = rtl8169_close, |
|
3002 .ndo_get_stats = rtl8169_get_stats, |
|
3003 .ndo_start_xmit = rtl8169_start_xmit, |
|
3004 .ndo_tx_timeout = rtl8169_tx_timeout, |
|
3005 .ndo_validate_addr = eth_validate_addr, |
|
3006 .ndo_change_mtu = rtl8169_change_mtu, |
|
3007 .ndo_set_mac_address = rtl_set_mac_address, |
|
3008 .ndo_do_ioctl = rtl8169_ioctl, |
|
3009 .ndo_set_multicast_list = rtl_set_rx_mode, |
|
3010 #ifdef CONFIG_R8169_VLAN |
|
3011 .ndo_vlan_rx_register = rtl8169_vlan_rx_register, |
|
3012 #endif |
|
3013 #ifdef CONFIG_NET_POLL_CONTROLLER |
|
3014 .ndo_poll_controller = rtl8169_netpoll, |
|
3015 #endif |
|
3016 |
|
3017 }; |
|
3018 |
|
3019 static int __devinit |
|
3020 rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
|
3021 { |
|
3022 const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data; |
|
3023 const unsigned int region = cfg->region; |
|
3024 struct rtl8169_private *tp; |
|
3025 struct mii_if_info *mii; |
|
3026 struct net_device *dev; |
|
3027 void __iomem *ioaddr; |
|
3028 unsigned int i; |
|
3029 int rc; |
|
3030 |
|
3031 if (netif_msg_drv(&debug)) { |
|
3032 printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n", |
|
3033 MODULENAME, RTL8169_VERSION); |
|
3034 } |
|
3035 |
|
3036 dev = alloc_etherdev(sizeof (*tp)); |
|
3037 if (!dev) { |
|
3038 if (netif_msg_drv(&debug)) |
|
3039 dev_err(&pdev->dev, "unable to alloc new ethernet\n"); |
|
3040 rc = -ENOMEM; |
|
3041 goto out; |
|
3042 } |
|
3043 |
|
3044 SET_NETDEV_DEV(dev, &pdev->dev); |
|
3045 dev->netdev_ops = &rtl8169_netdev_ops; |
|
3046 tp = netdev_priv(dev); |
|
3047 tp->dev = dev; |
|
3048 tp->pci_dev = pdev; |
|
3049 tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT); |
|
3050 |
|
3051 mii = &tp->mii; |
|
3052 mii->dev = dev; |
|
3053 mii->mdio_read = rtl_mdio_read; |
|
3054 mii->mdio_write = rtl_mdio_write; |
|
3055 mii->phy_id_mask = 0x1f; |
|
3056 mii->reg_num_mask = 0x1f; |
|
3057 mii->supports_gmii = !!(cfg->features & RTL_FEATURE_GMII); |
|
3058 |
|
3059 /* enable device (incl. PCI PM wakeup and hotplug setup) */ |
|
3060 rc = pci_enable_device(pdev); |
|
3061 if (rc < 0) { |
|
3062 netif_err(tp, probe, dev, "enable failure\n"); |
|
3063 goto err_out_free_dev_1; |
|
3064 } |
|
3065 |
|
3066 if (pci_set_mwi(pdev) < 0) |
|
3067 netif_info(tp, probe, dev, "Mem-Wr-Inval unavailable\n"); |
|
3068 |
|
3069 /* make sure PCI base addr 1 is MMIO */ |
|
3070 if (!(pci_resource_flags(pdev, region) & IORESOURCE_MEM)) { |
|
3071 netif_err(tp, probe, dev, |
|
3072 "region #%d not an MMIO resource, aborting\n", |
|
3073 region); |
|
3074 rc = -ENODEV; |
|
3075 goto err_out_mwi_2; |
|
3076 } |
|
3077 |
|
3078 /* check for weird/broken PCI region reporting */ |
|
3079 if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) { |
|
3080 netif_err(tp, probe, dev, |
|
3081 "Invalid PCI region size(s), aborting\n"); |
|
3082 rc = -ENODEV; |
|
3083 goto err_out_mwi_2; |
|
3084 } |
|
3085 |
|
3086 rc = pci_request_regions(pdev, MODULENAME); |
|
3087 if (rc < 0) { |
|
3088 netif_err(tp, probe, dev, "could not request regions\n"); |
|
3089 goto err_out_mwi_2; |
|
3090 } |
|
3091 |
|
3092 tp->cp_cmd = PCIMulRW | RxChkSum; |
|
3093 |
|
3094 if ((sizeof(dma_addr_t) > 4) && |
|
3095 !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && use_dac) { |
|
3096 tp->cp_cmd |= PCIDAC; |
|
3097 dev->features |= NETIF_F_HIGHDMA; |
|
3098 } else { |
|
3099 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
|
3100 if (rc < 0) { |
|
3101 netif_err(tp, probe, dev, "DMA configuration failed\n"); |
|
3102 goto err_out_free_res_3; |
|
3103 } |
|
3104 } |
|
3105 |
|
3106 /* ioremap MMIO region */ |
|
3107 ioaddr = ioremap(pci_resource_start(pdev, region), R8169_REGS_SIZE); |
|
3108 if (!ioaddr) { |
|
3109 netif_err(tp, probe, dev, "cannot remap MMIO, aborting\n"); |
|
3110 rc = -EIO; |
|
3111 goto err_out_free_res_3; |
|
3112 } |
|
3113 |
|
3114 tp->pcie_cap = pci_find_capability(pdev, PCI_CAP_ID_EXP); |
|
3115 if (!tp->pcie_cap) |
|
3116 netif_info(tp, probe, dev, "no PCI Express capability\n"); |
|
3117 |
|
3118 RTL_W16(IntrMask, 0x0000); |
|
3119 |
|
3120 /* Soft reset the chip. */ |
|
3121 RTL_W8(ChipCmd, CmdReset); |
|
3122 |
|
3123 /* Check that the chip has finished the reset. */ |
|
3124 for (i = 0; i < 100; i++) { |
|
3125 if ((RTL_R8(ChipCmd) & CmdReset) == 0) |
|
3126 break; |
|
3127 msleep_interruptible(1); |
|
3128 } |
|
3129 |
|
3130 RTL_W16(IntrStatus, 0xffff); |
|
3131 |
|
3132 pci_set_master(pdev); |
|
3133 |
|
3134 /* Identify chip attached to board */ |
|
3135 rtl8169_get_mac_version(tp, ioaddr); |
|
3136 |
|
3137 /* Use appropriate default if unknown */ |
|
3138 if (tp->mac_version == RTL_GIGA_MAC_NONE) { |
|
3139 netif_notice(tp, probe, dev, |
|
3140 "unknown MAC, using family default\n"); |
|
3141 tp->mac_version = cfg->default_ver; |
|
3142 } |
|
3143 |
|
3144 rtl8169_print_mac_version(tp); |
|
3145 |
|
3146 for (i = 0; i < ARRAY_SIZE(rtl_chip_info); i++) { |
|
3147 if (tp->mac_version == rtl_chip_info[i].mac_version) |
|
3148 break; |
|
3149 } |
|
3150 if (i == ARRAY_SIZE(rtl_chip_info)) { |
|
3151 dev_err(&pdev->dev, |
|
3152 "driver bug, MAC version not found in rtl_chip_info\n"); |
|
3153 goto err_out_msi_4; |
|
3154 } |
|
3155 tp->chipset = i; |
|
3156 |
|
3157 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
3158 RTL_W8(Config1, RTL_R8(Config1) | PMEnable); |
|
3159 RTL_W8(Config5, RTL_R8(Config5) & PMEStatus); |
|
3160 if ((RTL_R8(Config3) & (LinkUp | MagicPacket)) != 0) |
|
3161 tp->features |= RTL_FEATURE_WOL; |
|
3162 if ((RTL_R8(Config5) & (UWF | BWF | MWF)) != 0) |
|
3163 tp->features |= RTL_FEATURE_WOL; |
|
3164 tp->features |= rtl_try_msi(pdev, ioaddr, cfg); |
|
3165 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
3166 |
|
3167 if ((tp->mac_version <= RTL_GIGA_MAC_VER_06) && |
|
3168 (RTL_R8(PHYstatus) & TBI_Enable)) { |
|
3169 tp->set_speed = rtl8169_set_speed_tbi; |
|
3170 tp->get_settings = rtl8169_gset_tbi; |
|
3171 tp->phy_reset_enable = rtl8169_tbi_reset_enable; |
|
3172 tp->phy_reset_pending = rtl8169_tbi_reset_pending; |
|
3173 tp->link_ok = rtl8169_tbi_link_ok; |
|
3174 tp->do_ioctl = rtl_tbi_ioctl; |
|
3175 |
|
3176 tp->phy_1000_ctrl_reg = ADVERTISE_1000FULL; /* Implied by TBI */ |
|
3177 } else { |
|
3178 tp->set_speed = rtl8169_set_speed_xmii; |
|
3179 tp->get_settings = rtl8169_gset_xmii; |
|
3180 tp->phy_reset_enable = rtl8169_xmii_reset_enable; |
|
3181 tp->phy_reset_pending = rtl8169_xmii_reset_pending; |
|
3182 tp->link_ok = rtl8169_xmii_link_ok; |
|
3183 tp->do_ioctl = rtl_xmii_ioctl; |
|
3184 } |
|
3185 |
|
3186 spin_lock_init(&tp->lock); |
|
3187 |
|
3188 tp->mmio_addr = ioaddr; |
|
3189 |
|
3190 /* Get MAC address */ |
|
3191 for (i = 0; i < MAC_ADDR_LEN; i++) |
|
3192 dev->dev_addr[i] = RTL_R8(MAC0 + i); |
|
3193 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
|
3194 |
|
3195 SET_ETHTOOL_OPS(dev, &rtl8169_ethtool_ops); |
|
3196 dev->watchdog_timeo = RTL8169_TX_TIMEOUT; |
|
3197 dev->irq = pdev->irq; |
|
3198 dev->base_addr = (unsigned long) ioaddr; |
|
3199 |
|
3200 netif_napi_add(dev, &tp->napi, rtl8169_poll, R8169_NAPI_WEIGHT); |
|
3201 |
|
3202 #ifdef CONFIG_R8169_VLAN |
|
3203 dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
|
3204 #endif |
|
3205 |
|
3206 tp->intr_mask = 0xffff; |
|
3207 tp->align = cfg->align; |
|
3208 tp->hw_start = cfg->hw_start; |
|
3209 tp->intr_event = cfg->intr_event; |
|
3210 tp->napi_event = cfg->napi_event; |
|
3211 |
|
3212 init_timer(&tp->timer); |
|
3213 tp->timer.data = (unsigned long) dev; |
|
3214 tp->timer.function = rtl8169_phy_timer; |
|
3215 |
|
3216 // offer device to EtherCAT master module |
|
3217 tp->ecdev = ecdev_offer(dev, ec_poll, THIS_MODULE); |
|
3218 |
|
3219 if (!tp->ecdev) { |
|
3220 rc = register_netdev(dev); |
|
3221 if (rc < 0) |
|
3222 goto err_out_msi_4; |
|
3223 } |
|
3224 |
|
3225 pci_set_drvdata(pdev, dev); |
|
3226 |
|
3227 netif_info(tp, probe, dev, "%s at 0x%lx, %pM, XID %08x IRQ %d\n", |
|
3228 rtl_chip_info[tp->chipset].name, |
|
3229 dev->base_addr, dev->dev_addr, |
|
3230 (u32)(RTL_R32(TxConfig) & 0x9cf0f8ff), dev->irq); |
|
3231 |
|
3232 rtl8169_init_phy(dev, tp); |
|
3233 |
|
3234 /* |
|
3235 * Pretend we are using VLANs; This bypasses a nasty bug where |
|
3236 * Interrupts stop flowing on high load on 8110SCd controllers. |
|
3237 */ |
|
3238 if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
|
3239 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) | RxVlan); |
|
3240 |
|
3241 device_set_wakeup_enable(&pdev->dev, tp->features & RTL_FEATURE_WOL); |
|
3242 if (tp->ecdev && ecdev_open(tp->ecdev)) { |
|
3243 ecdev_withdraw(tp->ecdev); |
|
3244 goto err_out_msi_4; |
|
3245 } |
|
3246 |
|
3247 if(!tp->ecdev) { |
|
3248 if (pci_dev_run_wake(pdev)) |
|
3249 pm_runtime_put_noidle(&pdev->dev); |
|
3250 } |
|
3251 out: |
|
3252 return rc; |
|
3253 |
|
3254 err_out_msi_4: |
|
3255 rtl_disable_msi(pdev, tp); |
|
3256 iounmap(ioaddr); |
|
3257 err_out_free_res_3: |
|
3258 pci_release_regions(pdev); |
|
3259 err_out_mwi_2: |
|
3260 pci_clear_mwi(pdev); |
|
3261 pci_disable_device(pdev); |
|
3262 err_out_free_dev_1: |
|
3263 free_netdev(dev); |
|
3264 goto out; |
|
3265 } |
|
3266 |
|
3267 static void __devexit rtl8169_remove_one(struct pci_dev *pdev) |
|
3268 { |
|
3269 struct net_device *dev = pci_get_drvdata(pdev); |
|
3270 struct rtl8169_private *tp = netdev_priv(dev); |
|
3271 |
|
3272 flush_scheduled_work(); |
|
3273 |
|
3274 if (tp->ecdev) { |
|
3275 ecdev_close(tp->ecdev); |
|
3276 ecdev_withdraw(tp->ecdev); |
|
3277 } else { |
|
3278 unregister_netdev(dev); |
|
3279 } |
|
3280 |
|
3281 if(!tp->ecdev) { |
|
3282 if (pci_dev_run_wake(pdev)) |
|
3283 pm_runtime_get_noresume(&pdev->dev); |
|
3284 } |
|
3285 |
|
3286 /* restore original MAC address */ |
|
3287 rtl_rar_set(tp, dev->perm_addr); |
|
3288 |
|
3289 rtl_disable_msi(pdev, tp); |
|
3290 rtl8169_release_board(pdev, dev, tp->mmio_addr); |
|
3291 pci_set_drvdata(pdev, NULL); |
|
3292 } |
|
3293 |
|
3294 static void rtl8169_set_rxbufsize(struct rtl8169_private *tp, |
|
3295 unsigned int mtu) |
|
3296 { |
|
3297 unsigned int max_frame = mtu + VLAN_ETH_HLEN + ETH_FCS_LEN; |
|
3298 |
|
3299 if (max_frame != 16383) |
|
3300 printk(KERN_WARNING PFX "WARNING! Changing of MTU on this " |
|
3301 "NIC may lead to frame reception errors!\n"); |
|
3302 |
|
3303 tp->rx_buf_sz = (max_frame > RX_BUF_SIZE) ? max_frame : RX_BUF_SIZE; |
|
3304 } |
|
3305 |
|
3306 static int rtl8169_open(struct net_device *dev) |
|
3307 { |
|
3308 struct rtl8169_private *tp = netdev_priv(dev); |
|
3309 struct pci_dev *pdev = tp->pci_dev; |
|
3310 int retval = -ENOMEM; |
|
3311 |
|
3312 if(!tp->ecdev) |
|
3313 pm_runtime_get_sync(&pdev->dev); |
|
3314 |
|
3315 /* |
|
3316 * Note that we use a magic value here, its wierd I know |
|
3317 * its done because, some subset of rtl8169 hardware suffers from |
|
3318 * a problem in which frames received that are longer than |
|
3319 * the size set in RxMaxSize register return garbage sizes |
|
3320 * when received. To avoid this we need to turn off filtering, |
|
3321 * which is done by setting a value of 16383 in the RxMaxSize register |
|
3322 * and allocating 16k frames to handle the largest possible rx value |
|
3323 * thats what the magic math below does. |
|
3324 */ |
|
3325 rtl8169_set_rxbufsize(tp, 16383 - VLAN_ETH_HLEN - ETH_FCS_LEN); |
|
3326 |
|
3327 /* |
|
3328 * Rx and Tx desscriptors needs 256 bytes alignment. |
|
3329 * dma_alloc_coherent provides more. |
|
3330 */ |
|
3331 tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES, |
|
3332 &tp->TxPhyAddr, GFP_KERNEL); |
|
3333 if (!tp->TxDescArray) |
|
3334 goto err_pm_runtime_put; |
|
3335 |
|
3336 tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, |
|
3337 &tp->RxPhyAddr, GFP_KERNEL); |
|
3338 if (!tp->RxDescArray) |
|
3339 goto err_free_tx_0; |
|
3340 |
|
3341 retval = rtl8169_init_ring(dev); |
|
3342 if (retval < 0) |
|
3343 goto err_free_rx_1; |
|
3344 |
|
3345 INIT_DELAYED_WORK(&tp->task, NULL); |
|
3346 |
|
3347 smp_mb(); |
|
3348 |
|
3349 if (!tp->ecdev) { |
|
3350 retval = request_irq(dev->irq, rtl8169_interrupt, |
|
3351 (tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED, |
|
3352 dev->name, dev); |
|
3353 if (retval < 0) |
|
3354 goto err_release_ring_2; |
|
3355 |
|
3356 napi_enable(&tp->napi); |
|
3357 |
|
3358 } |
|
3359 |
|
3360 rtl_hw_start(dev); |
|
3361 |
|
3362 rtl8169_request_timer(dev); |
|
3363 |
|
3364 tp->saved_wolopts = 0; |
|
3365 if(!tp->ecdev) |
|
3366 pm_runtime_put_noidle(&pdev->dev); |
|
3367 |
|
3368 rtl8169_check_link_status(dev, tp, tp->mmio_addr); |
|
3369 out: |
|
3370 return retval; |
|
3371 |
|
3372 err_release_ring_2: |
|
3373 rtl8169_rx_clear(tp); |
|
3374 err_free_rx_1: |
|
3375 dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
|
3376 tp->RxPhyAddr); |
|
3377 tp->RxDescArray = NULL; |
|
3378 err_free_tx_0: |
|
3379 dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
|
3380 tp->TxPhyAddr); |
|
3381 tp->TxDescArray = NULL; |
|
3382 err_pm_runtime_put: |
|
3383 if(!tp->ecdev) |
|
3384 pm_runtime_put_noidle(&pdev->dev); |
|
3385 goto out; |
|
3386 } |
|
3387 |
|
3388 static void rtl8169_hw_reset(void __iomem *ioaddr) |
|
3389 { |
|
3390 /* Disable interrupts */ |
|
3391 rtl8169_irq_mask_and_ack(ioaddr); |
|
3392 |
|
3393 /* Reset the chipset */ |
|
3394 RTL_W8(ChipCmd, CmdReset); |
|
3395 |
|
3396 /* PCI commit */ |
|
3397 RTL_R8(ChipCmd); |
|
3398 } |
|
3399 |
|
3400 static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp) |
|
3401 { |
|
3402 void __iomem *ioaddr = tp->mmio_addr; |
|
3403 u32 cfg = rtl8169_rx_config; |
|
3404 |
|
3405 cfg |= (RTL_R32(RxConfig) & rtl_chip_info[tp->chipset].RxConfigMask); |
|
3406 RTL_W32(RxConfig, cfg); |
|
3407 |
|
3408 /* Set DMA burst size and Interframe Gap Time */ |
|
3409 RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) | |
|
3410 (InterFrameGap << TxInterFrameGapShift)); |
|
3411 } |
|
3412 |
|
3413 static void rtl_hw_start(struct net_device *dev) |
|
3414 { |
|
3415 struct rtl8169_private *tp = netdev_priv(dev); |
|
3416 void __iomem *ioaddr = tp->mmio_addr; |
|
3417 unsigned int i; |
|
3418 |
|
3419 /* Soft reset the chip. */ |
|
3420 RTL_W8(ChipCmd, CmdReset); |
|
3421 |
|
3422 /* Check that the chip has finished the reset. */ |
|
3423 for (i = 0; i < 100; i++) { |
|
3424 if ((RTL_R8(ChipCmd) & CmdReset) == 0) |
|
3425 break; |
|
3426 msleep_interruptible(1); |
|
3427 } |
|
3428 |
|
3429 tp->hw_start(dev); |
|
3430 |
|
3431 if (!tp->ecdev) |
|
3432 netif_start_queue(dev); |
|
3433 } |
|
3434 |
|
3435 |
|
3436 static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp, |
|
3437 void __iomem *ioaddr) |
|
3438 { |
|
3439 /* |
|
3440 * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh |
|
3441 * register to be written before TxDescAddrLow to work. |
|
3442 * Switching from MMIO to I/O access fixes the issue as well. |
|
3443 */ |
|
3444 RTL_W32(TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); |
|
3445 RTL_W32(TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); |
|
3446 RTL_W32(RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); |
|
3447 RTL_W32(RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); |
|
3448 } |
|
3449 |
|
3450 static u16 rtl_rw_cpluscmd(void __iomem *ioaddr) |
|
3451 { |
|
3452 u16 cmd; |
|
3453 |
|
3454 cmd = RTL_R16(CPlusCmd); |
|
3455 RTL_W16(CPlusCmd, cmd); |
|
3456 return cmd; |
|
3457 } |
|
3458 |
|
3459 static void rtl_set_rx_max_size(void __iomem *ioaddr, unsigned int rx_buf_sz) |
|
3460 { |
|
3461 /* Low hurts. Let's disable the filtering. */ |
|
3462 RTL_W16(RxMaxSize, rx_buf_sz + 1); |
|
3463 } |
|
3464 |
|
3465 static void rtl8169_set_magic_reg(void __iomem *ioaddr, unsigned mac_version) |
|
3466 { |
|
3467 static const struct { |
|
3468 u32 mac_version; |
|
3469 u32 clk; |
|
3470 u32 val; |
|
3471 } cfg2_info [] = { |
|
3472 { RTL_GIGA_MAC_VER_05, PCI_Clock_33MHz, 0x000fff00 }, // 8110SCd |
|
3473 { RTL_GIGA_MAC_VER_05, PCI_Clock_66MHz, 0x000fffff }, |
|
3474 { RTL_GIGA_MAC_VER_06, PCI_Clock_33MHz, 0x00ffff00 }, // 8110SCe |
|
3475 { RTL_GIGA_MAC_VER_06, PCI_Clock_66MHz, 0x00ffffff } |
|
3476 }, *p = cfg2_info; |
|
3477 unsigned int i; |
|
3478 u32 clk; |
|
3479 |
|
3480 clk = RTL_R8(Config2) & PCI_Clock_66MHz; |
|
3481 for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) { |
|
3482 if ((p->mac_version == mac_version) && (p->clk == clk)) { |
|
3483 RTL_W32(0x7c, p->val); |
|
3484 break; |
|
3485 } |
|
3486 } |
|
3487 } |
|
3488 |
|
3489 static void rtl_hw_start_8169(struct net_device *dev) |
|
3490 { |
|
3491 struct rtl8169_private *tp = netdev_priv(dev); |
|
3492 void __iomem *ioaddr = tp->mmio_addr; |
|
3493 struct pci_dev *pdev = tp->pci_dev; |
|
3494 |
|
3495 if (tp->mac_version == RTL_GIGA_MAC_VER_05) { |
|
3496 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) | PCIMulRW); |
|
3497 pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, 0x08); |
|
3498 } |
|
3499 |
|
3500 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
3501 if ((tp->mac_version == RTL_GIGA_MAC_VER_01) || |
|
3502 (tp->mac_version == RTL_GIGA_MAC_VER_02) || |
|
3503 (tp->mac_version == RTL_GIGA_MAC_VER_03) || |
|
3504 (tp->mac_version == RTL_GIGA_MAC_VER_04)) |
|
3505 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
|
3506 |
|
3507 RTL_W8(EarlyTxThres, EarlyTxThld); |
|
3508 |
|
3509 rtl_set_rx_max_size(ioaddr, tp->rx_buf_sz); |
|
3510 |
|
3511 if ((tp->mac_version == RTL_GIGA_MAC_VER_01) || |
|
3512 (tp->mac_version == RTL_GIGA_MAC_VER_02) || |
|
3513 (tp->mac_version == RTL_GIGA_MAC_VER_03) || |
|
3514 (tp->mac_version == RTL_GIGA_MAC_VER_04)) |
|
3515 rtl_set_rx_tx_config_registers(tp); |
|
3516 |
|
3517 tp->cp_cmd |= rtl_rw_cpluscmd(ioaddr) | PCIMulRW; |
|
3518 |
|
3519 if ((tp->mac_version == RTL_GIGA_MAC_VER_02) || |
|
3520 (tp->mac_version == RTL_GIGA_MAC_VER_03)) { |
|
3521 dprintk("Set MAC Reg C+CR Offset 0xE0. " |
|
3522 "Bit-3 and bit-14 MUST be 1\n"); |
|
3523 tp->cp_cmd |= (1 << 14); |
|
3524 } |
|
3525 |
|
3526 RTL_W16(CPlusCmd, tp->cp_cmd); |
|
3527 |
|
3528 rtl8169_set_magic_reg(ioaddr, tp->mac_version); |
|
3529 |
|
3530 /* |
|
3531 * Undocumented corner. Supposedly: |
|
3532 * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets |
|
3533 */ |
|
3534 RTL_W16(IntrMitigate, 0x0000); |
|
3535 |
|
3536 rtl_set_rx_tx_desc_registers(tp, ioaddr); |
|
3537 |
|
3538 if ((tp->mac_version != RTL_GIGA_MAC_VER_01) && |
|
3539 (tp->mac_version != RTL_GIGA_MAC_VER_02) && |
|
3540 (tp->mac_version != RTL_GIGA_MAC_VER_03) && |
|
3541 (tp->mac_version != RTL_GIGA_MAC_VER_04)) { |
|
3542 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
|
3543 rtl_set_rx_tx_config_registers(tp); |
|
3544 } |
|
3545 |
|
3546 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
3547 |
|
3548 /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ |
|
3549 RTL_R8(IntrMask); |
|
3550 |
|
3551 RTL_W32(RxMissed, 0); |
|
3552 |
|
3553 rtl_set_rx_mode(dev); |
|
3554 |
|
3555 /* no early-rx interrupts */ |
|
3556 RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000); |
|
3557 |
|
3558 /* Enable all known interrupts by setting the interrupt mask. */ |
|
3559 if (!tp->ecdev) |
|
3560 RTL_W16(IntrMask, tp->intr_event); |
|
3561 } |
|
3562 |
|
3563 static void rtl_tx_performance_tweak(struct pci_dev *pdev, u16 force) |
|
3564 { |
|
3565 struct net_device *dev = pci_get_drvdata(pdev); |
|
3566 struct rtl8169_private *tp = netdev_priv(dev); |
|
3567 int cap = tp->pcie_cap; |
|
3568 |
|
3569 if (cap) { |
|
3570 u16 ctl; |
|
3571 |
|
3572 pci_read_config_word(pdev, cap + PCI_EXP_DEVCTL, &ctl); |
|
3573 ctl = (ctl & ~PCI_EXP_DEVCTL_READRQ) | force; |
|
3574 pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, ctl); |
|
3575 } |
|
3576 } |
|
3577 |
|
3578 static void rtl_csi_access_enable(void __iomem *ioaddr) |
|
3579 { |
|
3580 u32 csi; |
|
3581 |
|
3582 csi = rtl_csi_read(ioaddr, 0x070c) & 0x00ffffff; |
|
3583 rtl_csi_write(ioaddr, 0x070c, csi | 0x27000000); |
|
3584 } |
|
3585 |
|
3586 struct ephy_info { |
|
3587 unsigned int offset; |
|
3588 u16 mask; |
|
3589 u16 bits; |
|
3590 }; |
|
3591 |
|
3592 static void rtl_ephy_init(void __iomem *ioaddr, const struct ephy_info *e, int len) |
|
3593 { |
|
3594 u16 w; |
|
3595 |
|
3596 while (len-- > 0) { |
|
3597 w = (rtl_ephy_read(ioaddr, e->offset) & ~e->mask) | e->bits; |
|
3598 rtl_ephy_write(ioaddr, e->offset, w); |
|
3599 e++; |
|
3600 } |
|
3601 } |
|
3602 |
|
3603 static void rtl_disable_clock_request(struct pci_dev *pdev) |
|
3604 { |
|
3605 struct net_device *dev = pci_get_drvdata(pdev); |
|
3606 struct rtl8169_private *tp = netdev_priv(dev); |
|
3607 int cap = tp->pcie_cap; |
|
3608 |
|
3609 if (cap) { |
|
3610 u16 ctl; |
|
3611 |
|
3612 pci_read_config_word(pdev, cap + PCI_EXP_LNKCTL, &ctl); |
|
3613 ctl &= ~PCI_EXP_LNKCTL_CLKREQ_EN; |
|
3614 pci_write_config_word(pdev, cap + PCI_EXP_LNKCTL, ctl); |
|
3615 } |
|
3616 } |
|
3617 |
|
3618 #define R8168_CPCMD_QUIRK_MASK (\ |
|
3619 EnableBist | \ |
|
3620 Mac_dbgo_oe | \ |
|
3621 Force_half_dup | \ |
|
3622 Force_rxflow_en | \ |
|
3623 Force_txflow_en | \ |
|
3624 Cxpl_dbg_sel | \ |
|
3625 ASF | \ |
|
3626 PktCntrDisable | \ |
|
3627 Mac_dbgo_sel) |
|
3628 |
|
3629 static void rtl_hw_start_8168bb(void __iomem *ioaddr, struct pci_dev *pdev) |
|
3630 { |
|
3631 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
3632 |
|
3633 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
|
3634 |
|
3635 rtl_tx_performance_tweak(pdev, |
|
3636 (0x5 << MAX_READ_REQUEST_SHIFT) | PCI_EXP_DEVCTL_NOSNOOP_EN); |
|
3637 } |
|
3638 |
|
3639 static void rtl_hw_start_8168bef(void __iomem *ioaddr, struct pci_dev *pdev) |
|
3640 { |
|
3641 rtl_hw_start_8168bb(ioaddr, pdev); |
|
3642 |
|
3643 RTL_W8(EarlyTxThres, EarlyTxThld); |
|
3644 |
|
3645 RTL_W8(Config4, RTL_R8(Config4) & ~(1 << 0)); |
|
3646 } |
|
3647 |
|
3648 static void __rtl_hw_start_8168cp(void __iomem *ioaddr, struct pci_dev *pdev) |
|
3649 { |
|
3650 RTL_W8(Config1, RTL_R8(Config1) | Speed_down); |
|
3651 |
|
3652 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
3653 |
|
3654 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
3655 |
|
3656 rtl_disable_clock_request(pdev); |
|
3657 |
|
3658 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
|
3659 } |
|
3660 |
|
3661 static void rtl_hw_start_8168cp_1(void __iomem *ioaddr, struct pci_dev *pdev) |
|
3662 { |
|
3663 static const struct ephy_info e_info_8168cp[] = { |
|
3664 { 0x01, 0, 0x0001 }, |
|
3665 { 0x02, 0x0800, 0x1000 }, |
|
3666 { 0x03, 0, 0x0042 }, |
|
3667 { 0x06, 0x0080, 0x0000 }, |
|
3668 { 0x07, 0, 0x2000 } |
|
3669 }; |
|
3670 |
|
3671 rtl_csi_access_enable(ioaddr); |
|
3672 |
|
3673 rtl_ephy_init(ioaddr, e_info_8168cp, ARRAY_SIZE(e_info_8168cp)); |
|
3674 |
|
3675 __rtl_hw_start_8168cp(ioaddr, pdev); |
|
3676 } |
|
3677 |
|
3678 static void rtl_hw_start_8168cp_2(void __iomem *ioaddr, struct pci_dev *pdev) |
|
3679 { |
|
3680 rtl_csi_access_enable(ioaddr); |
|
3681 |
|
3682 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
3683 |
|
3684 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
3685 |
|
3686 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
|
3687 } |
|
3688 |
|
3689 static void rtl_hw_start_8168cp_3(void __iomem *ioaddr, struct pci_dev *pdev) |
|
3690 { |
|
3691 rtl_csi_access_enable(ioaddr); |
|
3692 |
|
3693 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
3694 |
|
3695 /* Magic. */ |
|
3696 RTL_W8(DBG_REG, 0x20); |
|
3697 |
|
3698 RTL_W8(EarlyTxThres, EarlyTxThld); |
|
3699 |
|
3700 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
3701 |
|
3702 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
|
3703 } |
|
3704 |
|
3705 static void rtl_hw_start_8168c_1(void __iomem *ioaddr, struct pci_dev *pdev) |
|
3706 { |
|
3707 static const struct ephy_info e_info_8168c_1[] = { |
|
3708 { 0x02, 0x0800, 0x1000 }, |
|
3709 { 0x03, 0, 0x0002 }, |
|
3710 { 0x06, 0x0080, 0x0000 } |
|
3711 }; |
|
3712 |
|
3713 rtl_csi_access_enable(ioaddr); |
|
3714 |
|
3715 RTL_W8(DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2); |
|
3716 |
|
3717 rtl_ephy_init(ioaddr, e_info_8168c_1, ARRAY_SIZE(e_info_8168c_1)); |
|
3718 |
|
3719 __rtl_hw_start_8168cp(ioaddr, pdev); |
|
3720 } |
|
3721 |
|
3722 static void rtl_hw_start_8168c_2(void __iomem *ioaddr, struct pci_dev *pdev) |
|
3723 { |
|
3724 static const struct ephy_info e_info_8168c_2[] = { |
|
3725 { 0x01, 0, 0x0001 }, |
|
3726 { 0x03, 0x0400, 0x0220 } |
|
3727 }; |
|
3728 |
|
3729 rtl_csi_access_enable(ioaddr); |
|
3730 |
|
3731 rtl_ephy_init(ioaddr, e_info_8168c_2, ARRAY_SIZE(e_info_8168c_2)); |
|
3732 |
|
3733 __rtl_hw_start_8168cp(ioaddr, pdev); |
|
3734 } |
|
3735 |
|
3736 static void rtl_hw_start_8168c_3(void __iomem *ioaddr, struct pci_dev *pdev) |
|
3737 { |
|
3738 rtl_hw_start_8168c_2(ioaddr, pdev); |
|
3739 } |
|
3740 |
|
3741 static void rtl_hw_start_8168c_4(void __iomem *ioaddr, struct pci_dev *pdev) |
|
3742 { |
|
3743 rtl_csi_access_enable(ioaddr); |
|
3744 |
|
3745 __rtl_hw_start_8168cp(ioaddr, pdev); |
|
3746 } |
|
3747 |
|
3748 static void rtl_hw_start_8168d(void __iomem *ioaddr, struct pci_dev *pdev) |
|
3749 { |
|
3750 rtl_csi_access_enable(ioaddr); |
|
3751 |
|
3752 rtl_disable_clock_request(pdev); |
|
3753 |
|
3754 RTL_W8(EarlyTxThres, EarlyTxThld); |
|
3755 |
|
3756 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
3757 |
|
3758 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
|
3759 } |
|
3760 |
|
3761 static void rtl_hw_start_8168(struct net_device *dev) |
|
3762 { |
|
3763 struct rtl8169_private *tp = netdev_priv(dev); |
|
3764 void __iomem *ioaddr = tp->mmio_addr; |
|
3765 struct pci_dev *pdev = tp->pci_dev; |
|
3766 |
|
3767 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
3768 |
|
3769 RTL_W8(EarlyTxThres, EarlyTxThld); |
|
3770 |
|
3771 rtl_set_rx_max_size(ioaddr, tp->rx_buf_sz); |
|
3772 |
|
3773 tp->cp_cmd |= RTL_R16(CPlusCmd) | PktCntrDisable | INTT_1; |
|
3774 |
|
3775 RTL_W16(CPlusCmd, tp->cp_cmd); |
|
3776 |
|
3777 RTL_W16(IntrMitigate, 0x5151); |
|
3778 |
|
3779 /* Work around for RxFIFO overflow. */ |
|
3780 if (tp->mac_version == RTL_GIGA_MAC_VER_11) { |
|
3781 tp->intr_event |= RxFIFOOver | PCSTimeout; |
|
3782 tp->intr_event &= ~RxOverflow; |
|
3783 } |
|
3784 |
|
3785 rtl_set_rx_tx_desc_registers(tp, ioaddr); |
|
3786 |
|
3787 rtl_set_rx_mode(dev); |
|
3788 |
|
3789 RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) | |
|
3790 (InterFrameGap << TxInterFrameGapShift)); |
|
3791 |
|
3792 RTL_R8(IntrMask); |
|
3793 |
|
3794 switch (tp->mac_version) { |
|
3795 case RTL_GIGA_MAC_VER_11: |
|
3796 rtl_hw_start_8168bb(ioaddr, pdev); |
|
3797 break; |
|
3798 |
|
3799 case RTL_GIGA_MAC_VER_12: |
|
3800 case RTL_GIGA_MAC_VER_17: |
|
3801 rtl_hw_start_8168bef(ioaddr, pdev); |
|
3802 break; |
|
3803 |
|
3804 case RTL_GIGA_MAC_VER_18: |
|
3805 rtl_hw_start_8168cp_1(ioaddr, pdev); |
|
3806 break; |
|
3807 |
|
3808 case RTL_GIGA_MAC_VER_19: |
|
3809 rtl_hw_start_8168c_1(ioaddr, pdev); |
|
3810 break; |
|
3811 |
|
3812 case RTL_GIGA_MAC_VER_20: |
|
3813 rtl_hw_start_8168c_2(ioaddr, pdev); |
|
3814 break; |
|
3815 |
|
3816 case RTL_GIGA_MAC_VER_21: |
|
3817 rtl_hw_start_8168c_3(ioaddr, pdev); |
|
3818 break; |
|
3819 |
|
3820 case RTL_GIGA_MAC_VER_22: |
|
3821 rtl_hw_start_8168c_4(ioaddr, pdev); |
|
3822 break; |
|
3823 |
|
3824 case RTL_GIGA_MAC_VER_23: |
|
3825 rtl_hw_start_8168cp_2(ioaddr, pdev); |
|
3826 break; |
|
3827 |
|
3828 case RTL_GIGA_MAC_VER_24: |
|
3829 rtl_hw_start_8168cp_3(ioaddr, pdev); |
|
3830 break; |
|
3831 |
|
3832 case RTL_GIGA_MAC_VER_25: |
|
3833 case RTL_GIGA_MAC_VER_26: |
|
3834 case RTL_GIGA_MAC_VER_27: |
|
3835 rtl_hw_start_8168d(ioaddr, pdev); |
|
3836 break; |
|
3837 |
|
3838 default: |
|
3839 printk(KERN_ERR PFX "%s: unknown chipset (mac_version = %d).\n", |
|
3840 dev->name, tp->mac_version); |
|
3841 break; |
|
3842 } |
|
3843 |
|
3844 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
|
3845 |
|
3846 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
3847 |
|
3848 RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000); |
|
3849 |
|
3850 if (!tp->ecdev) |
|
3851 RTL_W16(IntrMask, tp->intr_event); |
|
3852 } |
|
3853 |
|
3854 #define R810X_CPCMD_QUIRK_MASK (\ |
|
3855 EnableBist | \ |
|
3856 Mac_dbgo_oe | \ |
|
3857 Force_half_dup | \ |
|
3858 Force_rxflow_en | \ |
|
3859 Force_txflow_en | \ |
|
3860 Cxpl_dbg_sel | \ |
|
3861 ASF | \ |
|
3862 PktCntrDisable | \ |
|
3863 PCIDAC | \ |
|
3864 PCIMulRW) |
|
3865 |
|
3866 static void rtl_hw_start_8102e_1(void __iomem *ioaddr, struct pci_dev *pdev) |
|
3867 { |
|
3868 static const struct ephy_info e_info_8102e_1[] = { |
|
3869 { 0x01, 0, 0x6e65 }, |
|
3870 { 0x02, 0, 0x091f }, |
|
3871 { 0x03, 0, 0xc2f9 }, |
|
3872 { 0x06, 0, 0xafb5 }, |
|
3873 { 0x07, 0, 0x0e00 }, |
|
3874 { 0x19, 0, 0xec80 }, |
|
3875 { 0x01, 0, 0x2e65 }, |
|
3876 { 0x01, 0, 0x6e65 } |
|
3877 }; |
|
3878 u8 cfg1; |
|
3879 |
|
3880 rtl_csi_access_enable(ioaddr); |
|
3881 |
|
3882 RTL_W8(DBG_REG, FIX_NAK_1); |
|
3883 |
|
3884 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
3885 |
|
3886 RTL_W8(Config1, |
|
3887 LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable); |
|
3888 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
3889 |
|
3890 cfg1 = RTL_R8(Config1); |
|
3891 if ((cfg1 & LEDS0) && (cfg1 & LEDS1)) |
|
3892 RTL_W8(Config1, cfg1 & ~LEDS0); |
|
3893 |
|
3894 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R810X_CPCMD_QUIRK_MASK); |
|
3895 |
|
3896 rtl_ephy_init(ioaddr, e_info_8102e_1, ARRAY_SIZE(e_info_8102e_1)); |
|
3897 } |
|
3898 |
|
3899 static void rtl_hw_start_8102e_2(void __iomem *ioaddr, struct pci_dev *pdev) |
|
3900 { |
|
3901 rtl_csi_access_enable(ioaddr); |
|
3902 |
|
3903 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
3904 |
|
3905 RTL_W8(Config1, MEMMAP | IOMAP | VPD | PMEnable); |
|
3906 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
3907 |
|
3908 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R810X_CPCMD_QUIRK_MASK); |
|
3909 } |
|
3910 |
|
3911 static void rtl_hw_start_8102e_3(void __iomem *ioaddr, struct pci_dev *pdev) |
|
3912 { |
|
3913 rtl_hw_start_8102e_2(ioaddr, pdev); |
|
3914 |
|
3915 rtl_ephy_write(ioaddr, 0x03, 0xc2f9); |
|
3916 } |
|
3917 |
|
3918 static void rtl_hw_start_8101(struct net_device *dev) |
|
3919 { |
|
3920 struct rtl8169_private *tp = netdev_priv(dev); |
|
3921 void __iomem *ioaddr = tp->mmio_addr; |
|
3922 struct pci_dev *pdev = tp->pci_dev; |
|
3923 |
|
3924 if ((tp->mac_version == RTL_GIGA_MAC_VER_13) || |
|
3925 (tp->mac_version == RTL_GIGA_MAC_VER_16)) { |
|
3926 int cap = tp->pcie_cap; |
|
3927 |
|
3928 if (cap) { |
|
3929 pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, |
|
3930 PCI_EXP_DEVCTL_NOSNOOP_EN); |
|
3931 } |
|
3932 } |
|
3933 |
|
3934 switch (tp->mac_version) { |
|
3935 case RTL_GIGA_MAC_VER_07: |
|
3936 rtl_hw_start_8102e_1(ioaddr, pdev); |
|
3937 break; |
|
3938 |
|
3939 case RTL_GIGA_MAC_VER_08: |
|
3940 rtl_hw_start_8102e_3(ioaddr, pdev); |
|
3941 break; |
|
3942 |
|
3943 case RTL_GIGA_MAC_VER_09: |
|
3944 rtl_hw_start_8102e_2(ioaddr, pdev); |
|
3945 break; |
|
3946 } |
|
3947 |
|
3948 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
3949 |
|
3950 RTL_W8(EarlyTxThres, EarlyTxThld); |
|
3951 |
|
3952 rtl_set_rx_max_size(ioaddr, tp->rx_buf_sz); |
|
3953 |
|
3954 tp->cp_cmd |= rtl_rw_cpluscmd(ioaddr) | PCIMulRW; |
|
3955 |
|
3956 RTL_W16(CPlusCmd, tp->cp_cmd); |
|
3957 |
|
3958 RTL_W16(IntrMitigate, 0x0000); |
|
3959 |
|
3960 rtl_set_rx_tx_desc_registers(tp, ioaddr); |
|
3961 |
|
3962 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
|
3963 rtl_set_rx_tx_config_registers(tp); |
|
3964 |
|
3965 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
3966 |
|
3967 RTL_R8(IntrMask); |
|
3968 |
|
3969 rtl_set_rx_mode(dev); |
|
3970 |
|
3971 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
|
3972 |
|
3973 RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000); |
|
3974 |
|
3975 if (!tp->ecdev) |
|
3976 RTL_W16(IntrMask, tp->intr_event); |
|
3977 } |
|
3978 |
|
3979 static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) |
|
3980 { |
|
3981 struct rtl8169_private *tp = netdev_priv(dev); |
|
3982 int ret = 0; |
|
3983 |
|
3984 if (new_mtu < ETH_ZLEN || new_mtu > SafeMtu) |
|
3985 return -EINVAL; |
|
3986 |
|
3987 dev->mtu = new_mtu; |
|
3988 |
|
3989 if (!netif_running(dev)) |
|
3990 goto out; |
|
3991 |
|
3992 rtl8169_down(dev); |
|
3993 |
|
3994 rtl8169_set_rxbufsize(tp, dev->mtu); |
|
3995 |
|
3996 ret = rtl8169_init_ring(dev); |
|
3997 if (ret < 0) |
|
3998 goto out; |
|
3999 |
|
4000 napi_enable(&tp->napi); |
|
4001 |
|
4002 rtl_hw_start(dev); |
|
4003 |
|
4004 rtl8169_request_timer(dev); |
|
4005 |
|
4006 out: |
|
4007 return ret; |
|
4008 } |
|
4009 |
|
4010 static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc) |
|
4011 { |
|
4012 desc->addr = cpu_to_le64(0x0badbadbadbadbadull); |
|
4013 desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask); |
|
4014 } |
|
4015 |
|
4016 static void rtl8169_free_rx_skb(struct rtl8169_private *tp, |
|
4017 struct sk_buff **sk_buff, struct RxDesc *desc) |
|
4018 { |
|
4019 struct pci_dev *pdev = tp->pci_dev; |
|
4020 |
|
4021 dma_unmap_single(&pdev->dev, le64_to_cpu(desc->addr), tp->rx_buf_sz, |
|
4022 PCI_DMA_FROMDEVICE); |
|
4023 dev_kfree_skb(*sk_buff); |
|
4024 *sk_buff = NULL; |
|
4025 rtl8169_make_unusable_by_asic(desc); |
|
4026 } |
|
4027 |
|
4028 static inline void rtl8169_mark_to_asic(struct RxDesc *desc, u32 rx_buf_sz) |
|
4029 { |
|
4030 u32 eor = le32_to_cpu(desc->opts1) & RingEnd; |
|
4031 |
|
4032 desc->opts1 = cpu_to_le32(DescOwn | eor | rx_buf_sz); |
|
4033 } |
|
4034 |
|
4035 static inline void rtl8169_map_to_asic(struct RxDesc *desc, dma_addr_t mapping, |
|
4036 u32 rx_buf_sz) |
|
4037 { |
|
4038 desc->addr = cpu_to_le64(mapping); |
|
4039 wmb(); |
|
4040 rtl8169_mark_to_asic(desc, rx_buf_sz); |
|
4041 } |
|
4042 |
|
4043 static struct sk_buff *rtl8169_alloc_rx_skb(struct pci_dev *pdev, |
|
4044 struct net_device *dev, |
|
4045 struct RxDesc *desc, int rx_buf_sz, |
|
4046 unsigned int align, gfp_t gfp) |
|
4047 { |
|
4048 struct sk_buff *skb; |
|
4049 dma_addr_t mapping; |
|
4050 unsigned int pad; |
|
4051 |
|
4052 pad = align ? align : NET_IP_ALIGN; |
|
4053 |
|
4054 skb = __netdev_alloc_skb(dev, rx_buf_sz + pad, gfp); |
|
4055 if (!skb) |
|
4056 goto err_out; |
|
4057 |
|
4058 skb_reserve(skb, align ? ((pad - 1) & (unsigned long)skb->data) : pad); |
|
4059 |
|
4060 mapping = dma_map_single(&pdev->dev, skb->data, rx_buf_sz, |
|
4061 PCI_DMA_FROMDEVICE); |
|
4062 |
|
4063 rtl8169_map_to_asic(desc, mapping, rx_buf_sz); |
|
4064 out: |
|
4065 return skb; |
|
4066 |
|
4067 err_out: |
|
4068 rtl8169_make_unusable_by_asic(desc); |
|
4069 goto out; |
|
4070 } |
|
4071 |
|
4072 static void rtl8169_rx_clear(struct rtl8169_private *tp) |
|
4073 { |
|
4074 unsigned int i; |
|
4075 |
|
4076 for (i = 0; i < NUM_RX_DESC; i++) { |
|
4077 if (tp->Rx_skbuff[i]) { |
|
4078 rtl8169_free_rx_skb(tp, tp->Rx_skbuff + i, |
|
4079 tp->RxDescArray + i); |
|
4080 } |
|
4081 } |
|
4082 } |
|
4083 |
|
4084 static u32 rtl8169_rx_fill(struct rtl8169_private *tp, struct net_device *dev, |
|
4085 u32 start, u32 end, gfp_t gfp) |
|
4086 { |
|
4087 u32 cur; |
|
4088 |
|
4089 for (cur = start; end - cur != 0; cur++) { |
|
4090 struct sk_buff *skb; |
|
4091 unsigned int i = cur % NUM_RX_DESC; |
|
4092 |
|
4093 WARN_ON((s32)(end - cur) < 0); |
|
4094 |
|
4095 if (tp->Rx_skbuff[i]) |
|
4096 continue; |
|
4097 |
|
4098 skb = rtl8169_alloc_rx_skb(tp->pci_dev, dev, |
|
4099 tp->RxDescArray + i, |
|
4100 tp->rx_buf_sz, tp->align, gfp); |
|
4101 if (!skb) |
|
4102 break; |
|
4103 |
|
4104 tp->Rx_skbuff[i] = skb; |
|
4105 } |
|
4106 return cur - start; |
|
4107 } |
|
4108 |
|
4109 static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc) |
|
4110 { |
|
4111 desc->opts1 |= cpu_to_le32(RingEnd); |
|
4112 } |
|
4113 |
|
4114 static void rtl8169_init_ring_indexes(struct rtl8169_private *tp) |
|
4115 { |
|
4116 tp->dirty_tx = tp->dirty_rx = tp->cur_tx = tp->cur_rx = 0; |
|
4117 } |
|
4118 |
|
4119 static int rtl8169_init_ring(struct net_device *dev) |
|
4120 { |
|
4121 struct rtl8169_private *tp = netdev_priv(dev); |
|
4122 |
|
4123 rtl8169_init_ring_indexes(tp); |
|
4124 |
|
4125 memset(tp->tx_skb, 0x0, NUM_TX_DESC * sizeof(struct ring_info)); |
|
4126 memset(tp->Rx_skbuff, 0x0, NUM_RX_DESC * sizeof(struct sk_buff *)); |
|
4127 |
|
4128 if (rtl8169_rx_fill(tp, dev, 0, NUM_RX_DESC, GFP_KERNEL) != NUM_RX_DESC) |
|
4129 goto err_out; |
|
4130 |
|
4131 rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1); |
|
4132 |
|
4133 return 0; |
|
4134 |
|
4135 err_out: |
|
4136 rtl8169_rx_clear(tp); |
|
4137 return -ENOMEM; |
|
4138 } |
|
4139 |
|
4140 static void rtl8169_unmap_tx_skb(struct pci_dev *pdev, struct ring_info *tx_skb, |
|
4141 struct TxDesc *desc) |
|
4142 { |
|
4143 unsigned int len = tx_skb->len; |
|
4144 |
|
4145 dma_unmap_single(&pdev->dev, le64_to_cpu(desc->addr), len, |
|
4146 PCI_DMA_TODEVICE); |
|
4147 desc->opts1 = 0x00; |
|
4148 desc->opts2 = 0x00; |
|
4149 desc->addr = 0x00; |
|
4150 tx_skb->len = 0; |
|
4151 } |
|
4152 |
|
4153 static void rtl8169_tx_clear(struct rtl8169_private *tp) |
|
4154 { |
|
4155 unsigned int i; |
|
4156 |
|
4157 for (i = tp->dirty_tx; i < tp->dirty_tx + NUM_TX_DESC; i++) { |
|
4158 unsigned int entry = i % NUM_TX_DESC; |
|
4159 struct ring_info *tx_skb = tp->tx_skb + entry; |
|
4160 unsigned int len = tx_skb->len; |
|
4161 |
|
4162 if (len) { |
|
4163 struct sk_buff *skb = tx_skb->skb; |
|
4164 |
|
4165 rtl8169_unmap_tx_skb(tp->pci_dev, tx_skb, |
|
4166 tp->TxDescArray + entry); |
|
4167 if (skb) { |
|
4168 if (!tp->ecdev) |
|
4169 dev_kfree_skb(skb); |
|
4170 tx_skb->skb = NULL; |
|
4171 } |
|
4172 tp->dev->stats.tx_dropped++; |
|
4173 } |
|
4174 } |
|
4175 tp->cur_tx = tp->dirty_tx = 0; |
|
4176 } |
|
4177 |
|
4178 static void rtl8169_schedule_work(struct net_device *dev, work_func_t task) |
|
4179 { |
|
4180 struct rtl8169_private *tp = netdev_priv(dev); |
|
4181 |
|
4182 PREPARE_DELAYED_WORK(&tp->task, task); |
|
4183 schedule_delayed_work(&tp->task, 4); |
|
4184 } |
|
4185 |
|
4186 static void rtl8169_wait_for_quiescence(struct net_device *dev) |
|
4187 { |
|
4188 struct rtl8169_private *tp = netdev_priv(dev); |
|
4189 void __iomem *ioaddr = tp->mmio_addr; |
|
4190 |
|
4191 synchronize_irq(dev->irq); |
|
4192 |
|
4193 /* Wait for any pending NAPI task to complete */ |
|
4194 napi_disable(&tp->napi); |
|
4195 |
|
4196 rtl8169_irq_mask_and_ack(ioaddr); |
|
4197 |
|
4198 tp->intr_mask = 0xffff; |
|
4199 RTL_W16(IntrMask, tp->intr_event); |
|
4200 napi_enable(&tp->napi); |
|
4201 } |
|
4202 |
|
4203 static void rtl8169_reinit_task(struct work_struct *work) |
|
4204 { |
|
4205 struct rtl8169_private *tp = |
|
4206 container_of(work, struct rtl8169_private, task.work); |
|
4207 struct net_device *dev = tp->dev; |
|
4208 int ret; |
|
4209 |
|
4210 rtnl_lock(); |
|
4211 |
|
4212 if (!netif_running(dev)) |
|
4213 goto out_unlock; |
|
4214 |
|
4215 rtl8169_wait_for_quiescence(dev); |
|
4216 rtl8169_close(dev); |
|
4217 |
|
4218 ret = rtl8169_open(dev); |
|
4219 if (unlikely(ret < 0)) { |
|
4220 if (net_ratelimit()) |
|
4221 netif_err(tp, drv, dev, |
|
4222 "reinit failure (status = %d). Rescheduling\n", |
|
4223 ret); |
|
4224 rtl8169_schedule_work(dev, rtl8169_reinit_task); |
|
4225 } |
|
4226 |
|
4227 out_unlock: |
|
4228 rtnl_unlock(); |
|
4229 } |
|
4230 |
|
4231 static void rtl8169_reset_task(struct work_struct *work) |
|
4232 { |
|
4233 struct rtl8169_private *tp = |
|
4234 container_of(work, struct rtl8169_private, task.work); |
|
4235 struct net_device *dev = tp->dev; |
|
4236 |
|
4237 rtnl_lock(); |
|
4238 |
|
4239 if (!netif_running(dev)) |
|
4240 goto out_unlock; |
|
4241 |
|
4242 rtl8169_wait_for_quiescence(dev); |
|
4243 |
|
4244 rtl8169_rx_interrupt(dev, tp, tp->mmio_addr, ~(u32)0); |
|
4245 rtl8169_tx_clear(tp); |
|
4246 |
|
4247 if (tp->dirty_rx == tp->cur_rx) { |
|
4248 rtl8169_init_ring_indexes(tp); |
|
4249 rtl_hw_start(dev); |
|
4250 netif_wake_queue(dev); |
|
4251 rtl8169_check_link_status(dev, tp, tp->mmio_addr); |
|
4252 } else { |
|
4253 if (net_ratelimit()) |
|
4254 netif_emerg(tp, intr, dev, "Rx buffers shortage\n"); |
|
4255 rtl8169_schedule_work(dev, rtl8169_reset_task); |
|
4256 } |
|
4257 |
|
4258 out_unlock: |
|
4259 rtnl_unlock(); |
|
4260 } |
|
4261 |
|
4262 static void rtl8169_tx_timeout(struct net_device *dev) |
|
4263 { |
|
4264 struct rtl8169_private *tp = netdev_priv(dev); |
|
4265 |
|
4266 if (tp->ecdev) |
|
4267 return; |
|
4268 |
|
4269 rtl8169_hw_reset(tp->mmio_addr); |
|
4270 |
|
4271 /* Let's wait a bit while any (async) irq lands on */ |
|
4272 rtl8169_schedule_work(dev, rtl8169_reset_task); |
|
4273 } |
|
4274 |
|
4275 static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb, |
|
4276 u32 opts1) |
|
4277 { |
|
4278 struct skb_shared_info *info = skb_shinfo(skb); |
|
4279 unsigned int cur_frag, entry; |
|
4280 struct TxDesc * uninitialized_var(txd); |
|
4281 |
|
4282 entry = tp->cur_tx; |
|
4283 for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { |
|
4284 skb_frag_t *frag = info->frags + cur_frag; |
|
4285 dma_addr_t mapping; |
|
4286 u32 status, len; |
|
4287 void *addr; |
|
4288 |
|
4289 entry = (entry + 1) % NUM_TX_DESC; |
|
4290 |
|
4291 txd = tp->TxDescArray + entry; |
|
4292 len = frag->size; |
|
4293 addr = ((void *) page_address(frag->page)) + frag->page_offset; |
|
4294 mapping = dma_map_single(&tp->pci_dev->dev, addr, len, |
|
4295 PCI_DMA_TODEVICE); |
|
4296 |
|
4297 /* anti gcc 2.95.3 bugware (sic) */ |
|
4298 status = opts1 | len | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
|
4299 |
|
4300 txd->opts1 = cpu_to_le32(status); |
|
4301 txd->addr = cpu_to_le64(mapping); |
|
4302 |
|
4303 tp->tx_skb[entry].len = len; |
|
4304 } |
|
4305 |
|
4306 if (cur_frag) { |
|
4307 tp->tx_skb[entry].skb = skb; |
|
4308 txd->opts1 |= cpu_to_le32(LastFrag); |
|
4309 } |
|
4310 |
|
4311 return cur_frag; |
|
4312 } |
|
4313 |
|
4314 static inline u32 rtl8169_tso_csum(struct sk_buff *skb, struct net_device *dev) |
|
4315 { |
|
4316 if (dev->features & NETIF_F_TSO) { |
|
4317 u32 mss = skb_shinfo(skb)->gso_size; |
|
4318 |
|
4319 if (mss) |
|
4320 return LargeSend | ((mss & MSSMask) << MSSShift); |
|
4321 } |
|
4322 if (skb->ip_summed == CHECKSUM_PARTIAL) { |
|
4323 const struct iphdr *ip = ip_hdr(skb); |
|
4324 |
|
4325 if (ip->protocol == IPPROTO_TCP) |
|
4326 return IPCS | TCPCS; |
|
4327 else if (ip->protocol == IPPROTO_UDP) |
|
4328 return IPCS | UDPCS; |
|
4329 WARN_ON(1); /* we need a WARN() */ |
|
4330 } |
|
4331 return 0; |
|
4332 } |
|
4333 |
|
4334 static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
|
4335 struct net_device *dev) |
|
4336 { |
|
4337 struct rtl8169_private *tp = netdev_priv(dev); |
|
4338 unsigned int frags, entry = tp->cur_tx % NUM_TX_DESC; |
|
4339 struct TxDesc *txd = tp->TxDescArray + entry; |
|
4340 void __iomem *ioaddr = tp->mmio_addr; |
|
4341 dma_addr_t mapping; |
|
4342 u32 status, len; |
|
4343 u32 opts1; |
|
4344 |
|
4345 if (unlikely(TX_BUFFS_AVAIL(tp) < skb_shinfo(skb)->nr_frags)) { |
|
4346 netif_err(tp, drv, dev, "BUG! Tx Ring full when queue awake!\n"); |
|
4347 goto err_stop; |
|
4348 } |
|
4349 |
|
4350 if (unlikely(le32_to_cpu(txd->opts1) & DescOwn)) |
|
4351 goto err_stop; |
|
4352 |
|
4353 opts1 = DescOwn | rtl8169_tso_csum(skb, dev); |
|
4354 |
|
4355 frags = rtl8169_xmit_frags(tp, skb, opts1); |
|
4356 if (frags) { |
|
4357 len = skb_headlen(skb); |
|
4358 opts1 |= FirstFrag; |
|
4359 } else { |
|
4360 len = skb->len; |
|
4361 opts1 |= FirstFrag | LastFrag; |
|
4362 tp->tx_skb[entry].skb = skb; |
|
4363 } |
|
4364 |
|
4365 mapping = dma_map_single(&tp->pci_dev->dev, skb->data, len, |
|
4366 PCI_DMA_TODEVICE); |
|
4367 |
|
4368 tp->tx_skb[entry].len = len; |
|
4369 txd->addr = cpu_to_le64(mapping); |
|
4370 txd->opts2 = cpu_to_le32(rtl8169_tx_vlan_tag(tp, skb)); |
|
4371 |
|
4372 wmb(); |
|
4373 |
|
4374 /* anti gcc 2.95.3 bugware (sic) */ |
|
4375 status = opts1 | len | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
|
4376 txd->opts1 = cpu_to_le32(status); |
|
4377 |
|
4378 tp->cur_tx += frags + 1; |
|
4379 |
|
4380 wmb(); |
|
4381 |
|
4382 RTL_W8(TxPoll, NPQ); /* set polling bit */ |
|
4383 |
|
4384 if (!tp->ecdev) { |
|
4385 if (TX_BUFFS_AVAIL(tp) < MAX_SKB_FRAGS) { |
|
4386 netif_stop_queue(dev); |
|
4387 smp_rmb(); |
|
4388 if (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS) |
|
4389 netif_wake_queue(dev); |
|
4390 } |
|
4391 } |
|
4392 |
|
4393 return NETDEV_TX_OK; |
|
4394 |
|
4395 err_stop: |
|
4396 if (!tp->ecdev) |
|
4397 netif_stop_queue(dev); |
|
4398 dev->stats.tx_dropped++; |
|
4399 return NETDEV_TX_BUSY; |
|
4400 } |
|
4401 |
|
4402 static void rtl8169_pcierr_interrupt(struct net_device *dev) |
|
4403 { |
|
4404 struct rtl8169_private *tp = netdev_priv(dev); |
|
4405 struct pci_dev *pdev = tp->pci_dev; |
|
4406 void __iomem *ioaddr = tp->mmio_addr; |
|
4407 u16 pci_status, pci_cmd; |
|
4408 |
|
4409 pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); |
|
4410 pci_read_config_word(pdev, PCI_STATUS, &pci_status); |
|
4411 |
|
4412 netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n", |
|
4413 pci_cmd, pci_status); |
|
4414 |
|
4415 /* |
|
4416 * The recovery sequence below admits a very elaborated explanation: |
|
4417 * - it seems to work; |
|
4418 * - I did not see what else could be done; |
|
4419 * - it makes iop3xx happy. |
|
4420 * |
|
4421 * Feel free to adjust to your needs. |
|
4422 */ |
|
4423 if (pdev->broken_parity_status) |
|
4424 pci_cmd &= ~PCI_COMMAND_PARITY; |
|
4425 else |
|
4426 pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; |
|
4427 |
|
4428 pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); |
|
4429 |
|
4430 pci_write_config_word(pdev, PCI_STATUS, |
|
4431 pci_status & (PCI_STATUS_DETECTED_PARITY | |
|
4432 PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT | |
|
4433 PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT)); |
|
4434 |
|
4435 /* The infamous DAC f*ckup only happens at boot time */ |
|
4436 if ((tp->cp_cmd & PCIDAC) && !tp->dirty_rx && !tp->cur_rx) { |
|
4437 netif_info(tp, intr, dev, "disabling PCI DAC\n"); |
|
4438 tp->cp_cmd &= ~PCIDAC; |
|
4439 RTL_W16(CPlusCmd, tp->cp_cmd); |
|
4440 dev->features &= ~NETIF_F_HIGHDMA; |
|
4441 } |
|
4442 |
|
4443 rtl8169_hw_reset(ioaddr); |
|
4444 |
|
4445 rtl8169_schedule_work(dev, rtl8169_reinit_task); |
|
4446 } |
|
4447 |
|
4448 static void rtl8169_tx_interrupt(struct net_device *dev, |
|
4449 struct rtl8169_private *tp, |
|
4450 void __iomem *ioaddr) |
|
4451 { |
|
4452 unsigned int dirty_tx, tx_left; |
|
4453 |
|
4454 dirty_tx = tp->dirty_tx; |
|
4455 smp_rmb(); |
|
4456 tx_left = tp->cur_tx - dirty_tx; |
|
4457 |
|
4458 while (tx_left > 0) { |
|
4459 unsigned int entry = dirty_tx % NUM_TX_DESC; |
|
4460 struct ring_info *tx_skb = tp->tx_skb + entry; |
|
4461 u32 len = tx_skb->len; |
|
4462 u32 status; |
|
4463 |
|
4464 rmb(); |
|
4465 status = le32_to_cpu(tp->TxDescArray[entry].opts1); |
|
4466 if (status & DescOwn) |
|
4467 break; |
|
4468 |
|
4469 dev->stats.tx_bytes += len; |
|
4470 dev->stats.tx_packets++; |
|
4471 |
|
4472 rtl8169_unmap_tx_skb(tp->pci_dev, tx_skb, tp->TxDescArray + entry); |
|
4473 |
|
4474 if (status & LastFrag) { |
|
4475 if (!tp->ecdev) |
|
4476 dev_kfree_skb(tx_skb->skb); |
|
4477 tx_skb->skb = NULL; |
|
4478 } |
|
4479 dirty_tx++; |
|
4480 tx_left--; |
|
4481 } |
|
4482 |
|
4483 if (tp->dirty_tx != dirty_tx) { |
|
4484 tp->dirty_tx = dirty_tx; |
|
4485 smp_wmb(); |
|
4486 if (!tp->ecdev && netif_queue_stopped(dev) && |
|
4487 (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)) { |
|
4488 netif_wake_queue(dev); |
|
4489 } |
|
4490 /* |
|
4491 * 8168 hack: TxPoll requests are lost when the Tx packets are |
|
4492 * too close. Let's kick an extra TxPoll request when a burst |
|
4493 * of start_xmit activity is detected (if it is not detected, |
|
4494 * it is slow enough). -- FR |
|
4495 */ |
|
4496 smp_rmb(); |
|
4497 if (tp->cur_tx != dirty_tx) |
|
4498 RTL_W8(TxPoll, NPQ); |
|
4499 } |
|
4500 } |
|
4501 |
|
4502 static inline int rtl8169_fragmented_frame(u32 status) |
|
4503 { |
|
4504 return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag); |
|
4505 } |
|
4506 |
|
4507 static inline void rtl8169_rx_csum(struct sk_buff *skb, struct RxDesc *desc) |
|
4508 { |
|
4509 u32 opts1 = le32_to_cpu(desc->opts1); |
|
4510 u32 status = opts1 & RxProtoMask; |
|
4511 |
|
4512 if (((status == RxProtoTCP) && !(opts1 & TCPFail)) || |
|
4513 ((status == RxProtoUDP) && !(opts1 & UDPFail)) || |
|
4514 ((status == RxProtoIP) && !(opts1 & IPFail))) |
|
4515 skb->ip_summed = CHECKSUM_UNNECESSARY; |
|
4516 else |
|
4517 skb->ip_summed = CHECKSUM_NONE; |
|
4518 } |
|
4519 |
|
4520 static inline bool rtl8169_try_rx_copy(struct sk_buff **sk_buff, |
|
4521 struct rtl8169_private *tp, int pkt_size, |
|
4522 dma_addr_t addr) |
|
4523 { |
|
4524 struct sk_buff *skb; |
|
4525 bool done = false; |
|
4526 |
|
4527 if (pkt_size >= rx_copybreak) |
|
4528 goto out; |
|
4529 |
|
4530 skb = netdev_alloc_skb_ip_align(tp->dev, pkt_size); |
|
4531 if (!skb) |
|
4532 goto out; |
|
4533 |
|
4534 dma_sync_single_for_cpu(&tp->pci_dev->dev, addr, pkt_size, |
|
4535 PCI_DMA_FROMDEVICE); |
|
4536 skb_copy_from_linear_data(*sk_buff, skb->data, pkt_size); |
|
4537 *sk_buff = skb; |
|
4538 done = true; |
|
4539 out: |
|
4540 return done; |
|
4541 } |
|
4542 |
|
4543 /* |
|
4544 * Warning : rtl8169_rx_interrupt() might be called : |
|
4545 * 1) from NAPI (softirq) context |
|
4546 * (polling = 1 : we should call netif_receive_skb()) |
|
4547 * 2) from process context (rtl8169_reset_task()) |
|
4548 * (polling = 0 : we must call netif_rx() instead) |
|
4549 */ |
|
4550 static int rtl8169_rx_interrupt(struct net_device *dev, |
|
4551 struct rtl8169_private *tp, |
|
4552 void __iomem *ioaddr, u32 budget) |
|
4553 { |
|
4554 unsigned int cur_rx, rx_left; |
|
4555 unsigned int delta, count; |
|
4556 int polling = (budget != ~(u32)0) ? 1 : 0; |
|
4557 |
|
4558 cur_rx = tp->cur_rx; |
|
4559 rx_left = NUM_RX_DESC + tp->dirty_rx - cur_rx; |
|
4560 rx_left = min(rx_left, budget); |
|
4561 |
|
4562 for (; rx_left > 0; rx_left--, cur_rx++) { |
|
4563 unsigned int entry = cur_rx % NUM_RX_DESC; |
|
4564 struct RxDesc *desc = tp->RxDescArray + entry; |
|
4565 u32 status; |
|
4566 |
|
4567 rmb(); |
|
4568 status = le32_to_cpu(desc->opts1); |
|
4569 |
|
4570 if (status & DescOwn) |
|
4571 break; |
|
4572 if (unlikely(status & RxRES)) { |
|
4573 netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n", |
|
4574 status); |
|
4575 dev->stats.rx_errors++; |
|
4576 if (status & (RxRWT | RxRUNT)) |
|
4577 dev->stats.rx_length_errors++; |
|
4578 if (status & RxCRC) |
|
4579 dev->stats.rx_crc_errors++; |
|
4580 if (status & RxFOVF) { |
|
4581 if (!tp->ecdev) |
|
4582 rtl8169_schedule_work(dev, rtl8169_reset_task); |
|
4583 dev->stats.rx_fifo_errors++; |
|
4584 } |
|
4585 rtl8169_mark_to_asic(desc, tp->rx_buf_sz); |
|
4586 } else { |
|
4587 struct sk_buff *skb = tp->Rx_skbuff[entry]; |
|
4588 dma_addr_t addr = le64_to_cpu(desc->addr); |
|
4589 int pkt_size = (status & 0x00001FFF) - 4; |
|
4590 struct pci_dev *pdev = tp->pci_dev; |
|
4591 |
|
4592 /* |
|
4593 * The driver does not support incoming fragmented |
|
4594 * frames. They are seen as a symptom of over-mtu |
|
4595 * sized frames. |
|
4596 */ |
|
4597 if (unlikely(rtl8169_fragmented_frame(status))) { |
|
4598 dev->stats.rx_dropped++; |
|
4599 dev->stats.rx_length_errors++; |
|
4600 rtl8169_mark_to_asic(desc, tp->rx_buf_sz); |
|
4601 continue; |
|
4602 } |
|
4603 |
|
4604 rtl8169_rx_csum(skb, desc); |
|
4605 |
|
4606 if (tp->ecdev) { |
|
4607 pci_dma_sync_single_for_cpu(pdev, addr, pkt_size, |
|
4608 PCI_DMA_FROMDEVICE); |
|
4609 |
|
4610 ecdev_receive(tp->ecdev, skb->data, pkt_size); |
|
4611 |
|
4612 pci_dma_sync_single_for_device(pdev, addr, |
|
4613 pkt_size, PCI_DMA_FROMDEVICE); |
|
4614 rtl8169_mark_to_asic(desc, tp->rx_buf_sz); |
|
4615 |
|
4616 // No need to detect link status as |
|
4617 // long as frames are received: Reset watchdog. |
|
4618 tp->ec_watchdog_jiffies = jiffies; |
|
4619 } else { |
|
4620 if (rtl8169_try_rx_copy(&skb, tp, pkt_size, addr)) { |
|
4621 dma_sync_single_for_device(&pdev->dev, addr, |
|
4622 pkt_size, PCI_DMA_FROMDEVICE); |
|
4623 rtl8169_mark_to_asic(desc, tp->rx_buf_sz); |
|
4624 } else { |
|
4625 dma_unmap_single(&pdev->dev, addr, tp->rx_buf_sz, |
|
4626 PCI_DMA_FROMDEVICE); |
|
4627 tp->Rx_skbuff[entry] = NULL; |
|
4628 } |
|
4629 |
|
4630 skb_put(skb, pkt_size); |
|
4631 skb->protocol = eth_type_trans(skb, dev); |
|
4632 |
|
4633 if (rtl8169_rx_vlan_skb(tp, desc, skb, polling) < 0) { |
|
4634 if (likely(polling)) |
|
4635 netif_receive_skb(skb); |
|
4636 else |
|
4637 netif_rx(skb); |
|
4638 } |
|
4639 } |
|
4640 dev->stats.rx_bytes += pkt_size; |
|
4641 dev->stats.rx_packets++; |
|
4642 } |
|
4643 |
|
4644 /* Work around for AMD plateform. */ |
|
4645 if ((desc->opts2 & cpu_to_le32(0xfffe000)) && |
|
4646 (tp->mac_version == RTL_GIGA_MAC_VER_05)) { |
|
4647 desc->opts2 = 0; |
|
4648 cur_rx++; |
|
4649 } |
|
4650 } |
|
4651 |
|
4652 count = cur_rx - tp->cur_rx; |
|
4653 tp->cur_rx = cur_rx; |
|
4654 |
|
4655 if (tp->ecdev) { |
|
4656 /* descriptors are cleaned up immediately. */ |
|
4657 tp->dirty_rx = tp->cur_rx; |
|
4658 } else { |
|
4659 delta = rtl8169_rx_fill(tp, dev, tp->dirty_rx, tp->cur_rx, GFP_ATOMIC); |
|
4660 |
|
4661 if (!delta && count) |
|
4662 netif_info(tp, intr, dev, "no Rx buffer allocated\n"); |
|
4663 tp->dirty_rx += delta; |
|
4664 |
|
4665 /* |
|
4666 * FIXME: until there is periodic timer to try and refill the ring, |
|
4667 * a temporary shortage may definitely kill the Rx process. |
|
4668 * - disable the asic to try and avoid an overflow and kick it again |
|
4669 * after refill ? |
|
4670 * - how do others driver handle this condition (Uh oh...). |
|
4671 */ |
|
4672 if (tp->dirty_rx + NUM_RX_DESC == tp->cur_rx) |
|
4673 netif_emerg(tp, intr, dev, "Rx buffers exhausted\n"); |
|
4674 } |
|
4675 |
|
4676 return count; |
|
4677 } |
|
4678 |
|
4679 static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) |
|
4680 { |
|
4681 struct net_device *dev = dev_instance; |
|
4682 struct rtl8169_private *tp = netdev_priv(dev); |
|
4683 void __iomem *ioaddr = tp->mmio_addr; |
|
4684 int handled = 0; |
|
4685 int status; |
|
4686 |
|
4687 /* loop handling interrupts until we have no new ones or |
|
4688 * we hit a invalid/hotplug case. |
|
4689 */ |
|
4690 status = RTL_R16(IntrStatus); |
|
4691 while (status && status != 0xffff) { |
|
4692 handled = 1; |
|
4693 |
|
4694 /* Handle all of the error cases first. These will reset |
|
4695 * the chip, so just exit the loop. |
|
4696 */ |
|
4697 if (unlikely(!tp->ecdev && !netif_running(dev))) { |
|
4698 rtl8169_asic_down(ioaddr); |
|
4699 break; |
|
4700 } |
|
4701 |
|
4702 /* Work around for rx fifo overflow */ |
|
4703 if (unlikely(status & RxFIFOOver)) { |
|
4704 netif_stop_queue(dev); |
|
4705 rtl8169_tx_timeout(dev); |
|
4706 break; |
|
4707 } |
|
4708 |
|
4709 if (unlikely(status & SYSErr)) { |
|
4710 rtl8169_pcierr_interrupt(dev); |
|
4711 break; |
|
4712 } |
|
4713 |
|
4714 if (status & LinkChg) |
|
4715 rtl8169_check_link_status(dev, tp, ioaddr); |
|
4716 |
|
4717 /* We need to see the lastest version of tp->intr_mask to |
|
4718 * avoid ignoring an MSI interrupt and having to wait for |
|
4719 * another event which may never come. |
|
4720 */ |
|
4721 smp_rmb(); |
|
4722 if (status & tp->intr_mask & tp->napi_event) { |
|
4723 RTL_W16(IntrMask, tp->intr_event & ~tp->napi_event); |
|
4724 tp->intr_mask = ~tp->napi_event; |
|
4725 |
|
4726 if (likely(napi_schedule_prep(&tp->napi))) |
|
4727 __napi_schedule(&tp->napi); |
|
4728 else |
|
4729 netif_info(tp, intr, dev, |
|
4730 "interrupt %04x in poll\n", status); |
|
4731 } |
|
4732 |
|
4733 /* We only get a new MSI interrupt when all active irq |
|
4734 * sources on the chip have been acknowledged. So, ack |
|
4735 * everything we've seen and check if new sources have become |
|
4736 * active to avoid blocking all interrupts from the chip. |
|
4737 */ |
|
4738 RTL_W16(IntrStatus, |
|
4739 (status & RxFIFOOver) ? (status | RxOverflow) : status); |
|
4740 status = RTL_R16(IntrStatus); |
|
4741 } |
|
4742 |
|
4743 return IRQ_RETVAL(handled); |
|
4744 } |
|
4745 |
|
4746 static void ec_poll(struct net_device *dev) |
|
4747 { |
|
4748 struct rtl8169_private *tp = netdev_priv(dev); |
|
4749 struct pci_dev *pdev = tp->pci_dev; |
|
4750 |
|
4751 rtl8169_interrupt(pdev->irq, dev); |
|
4752 rtl8169_rx_interrupt(dev, tp, tp->mmio_addr, 100); // FIXME |
|
4753 rtl8169_tx_interrupt(dev, tp, tp->mmio_addr); |
|
4754 |
|
4755 if (jiffies - tp->ec_watchdog_jiffies >= 2 * HZ) { |
|
4756 rtl8169_phy_timer((unsigned long) dev); |
|
4757 tp->ec_watchdog_jiffies = jiffies; |
|
4758 } |
|
4759 } |
|
4760 |
|
4761 static int rtl8169_poll(struct napi_struct *napi, int budget) |
|
4762 { |
|
4763 struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); |
|
4764 struct net_device *dev = tp->dev; |
|
4765 void __iomem *ioaddr = tp->mmio_addr; |
|
4766 int work_done; |
|
4767 |
|
4768 work_done = rtl8169_rx_interrupt(dev, tp, ioaddr, (u32) budget); |
|
4769 rtl8169_tx_interrupt(dev, tp, ioaddr); |
|
4770 |
|
4771 if (work_done < budget) { |
|
4772 napi_complete(napi); |
|
4773 |
|
4774 /* We need for force the visibility of tp->intr_mask |
|
4775 * for other CPUs, as we can loose an MSI interrupt |
|
4776 * and potentially wait for a retransmit timeout if we don't. |
|
4777 * The posted write to IntrMask is safe, as it will |
|
4778 * eventually make it to the chip and we won't loose anything |
|
4779 * until it does. |
|
4780 */ |
|
4781 tp->intr_mask = 0xffff; |
|
4782 wmb(); |
|
4783 RTL_W16(IntrMask, tp->intr_event); |
|
4784 } |
|
4785 |
|
4786 return work_done; |
|
4787 } |
|
4788 |
|
4789 static void rtl8169_rx_missed(struct net_device *dev, void __iomem *ioaddr) |
|
4790 { |
|
4791 struct rtl8169_private *tp = netdev_priv(dev); |
|
4792 |
|
4793 if (tp->mac_version > RTL_GIGA_MAC_VER_06) |
|
4794 return; |
|
4795 |
|
4796 dev->stats.rx_missed_errors += (RTL_R32(RxMissed) & 0xffffff); |
|
4797 RTL_W32(RxMissed, 0); |
|
4798 } |
|
4799 |
|
4800 static void rtl8169_down(struct net_device *dev) |
|
4801 { |
|
4802 struct rtl8169_private *tp = netdev_priv(dev); |
|
4803 void __iomem *ioaddr = tp->mmio_addr; |
|
4804 unsigned int intrmask; |
|
4805 |
|
4806 rtl8169_delete_timer(dev); |
|
4807 |
|
4808 if (!tp->ecdev) { |
|
4809 netif_stop_queue(dev); |
|
4810 |
|
4811 napi_disable(&tp->napi); |
|
4812 |
|
4813 } |
|
4814 |
|
4815 core_down: |
|
4816 if (!tp->ecdev) |
|
4817 spin_lock_irq(&tp->lock); |
|
4818 |
|
4819 rtl8169_asic_down(ioaddr); |
|
4820 |
|
4821 rtl8169_rx_missed(dev, ioaddr); |
|
4822 |
|
4823 if (!tp->ecdev) |
|
4824 spin_unlock_irq(&tp->lock); |
|
4825 |
|
4826 if (!tp->ecdev) |
|
4827 synchronize_irq(dev->irq); |
|
4828 |
|
4829 /* Give a racing hard_start_xmit a few cycles to complete. */ |
|
4830 synchronize_sched(); /* FIXME: should this be synchronize_irq()? */ |
|
4831 |
|
4832 /* |
|
4833 * And now for the 50k$ question: are IRQ disabled or not ? |
|
4834 * |
|
4835 * Two paths lead here: |
|
4836 * 1) dev->close |
|
4837 * -> netif_running() is available to sync the current code and the |
|
4838 * IRQ handler. See rtl8169_interrupt for details. |
|
4839 * 2) dev->change_mtu |
|
4840 * -> rtl8169_poll can not be issued again and re-enable the |
|
4841 * interruptions. Let's simply issue the IRQ down sequence again. |
|
4842 * |
|
4843 * No loop if hotpluged or major error (0xffff). |
|
4844 */ |
|
4845 intrmask = RTL_R16(IntrMask); |
|
4846 if (intrmask && (intrmask != 0xffff)) |
|
4847 goto core_down; |
|
4848 |
|
4849 rtl8169_tx_clear(tp); |
|
4850 |
|
4851 rtl8169_rx_clear(tp); |
|
4852 } |
|
4853 |
|
4854 static int rtl8169_close(struct net_device *dev) |
|
4855 { |
|
4856 struct rtl8169_private *tp = netdev_priv(dev); |
|
4857 struct pci_dev *pdev = tp->pci_dev; |
|
4858 |
|
4859 if(!tp->ecdev) |
|
4860 pm_runtime_get_sync(&pdev->dev); |
|
4861 |
|
4862 /* update counters before going down */ |
|
4863 rtl8169_update_counters(dev); |
|
4864 |
|
4865 rtl8169_down(dev); |
|
4866 |
|
4867 if (!tp->ecdev) |
|
4868 free_irq(dev->irq, dev); |
|
4869 |
|
4870 dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
|
4871 tp->RxPhyAddr); |
|
4872 dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
|
4873 tp->TxPhyAddr); |
|
4874 tp->TxDescArray = NULL; |
|
4875 tp->RxDescArray = NULL; |
|
4876 |
|
4877 if(!tp->ecdev) |
|
4878 pm_runtime_put_sync(&pdev->dev); |
|
4879 |
|
4880 return 0; |
|
4881 } |
|
4882 |
|
4883 static void rtl_set_rx_mode(struct net_device *dev) |
|
4884 { |
|
4885 struct rtl8169_private *tp = netdev_priv(dev); |
|
4886 void __iomem *ioaddr = tp->mmio_addr; |
|
4887 unsigned long flags; |
|
4888 u32 mc_filter[2]; /* Multicast hash filter */ |
|
4889 int rx_mode; |
|
4890 u32 tmp = 0; |
|
4891 |
|
4892 if (dev->flags & IFF_PROMISC) { |
|
4893 /* Unconditionally log net taps. */ |
|
4894 netif_notice(tp, link, dev, "Promiscuous mode enabled\n"); |
|
4895 rx_mode = |
|
4896 AcceptBroadcast | AcceptMulticast | AcceptMyPhys | |
|
4897 AcceptAllPhys; |
|
4898 mc_filter[1] = mc_filter[0] = 0xffffffff; |
|
4899 } else if ((netdev_mc_count(dev) > multicast_filter_limit) || |
|
4900 (dev->flags & IFF_ALLMULTI)) { |
|
4901 /* Too many to filter perfectly -- accept all multicasts. */ |
|
4902 rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; |
|
4903 mc_filter[1] = mc_filter[0] = 0xffffffff; |
|
4904 } else { |
|
4905 struct netdev_hw_addr *ha; |
|
4906 |
|
4907 rx_mode = AcceptBroadcast | AcceptMyPhys; |
|
4908 mc_filter[1] = mc_filter[0] = 0; |
|
4909 netdev_for_each_mc_addr(ha, dev) { |
|
4910 int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; |
|
4911 mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); |
|
4912 rx_mode |= AcceptMulticast; |
|
4913 } |
|
4914 } |
|
4915 |
|
4916 spin_lock_irqsave(&tp->lock, flags); |
|
4917 |
|
4918 tmp = rtl8169_rx_config | rx_mode | |
|
4919 (RTL_R32(RxConfig) & rtl_chip_info[tp->chipset].RxConfigMask); |
|
4920 |
|
4921 if (tp->mac_version > RTL_GIGA_MAC_VER_06) { |
|
4922 u32 data = mc_filter[0]; |
|
4923 |
|
4924 mc_filter[0] = swab32(mc_filter[1]); |
|
4925 mc_filter[1] = swab32(data); |
|
4926 } |
|
4927 |
|
4928 RTL_W32(MAR0 + 4, mc_filter[1]); |
|
4929 RTL_W32(MAR0 + 0, mc_filter[0]); |
|
4930 |
|
4931 RTL_W32(RxConfig, tmp); |
|
4932 |
|
4933 spin_unlock_irqrestore(&tp->lock, flags); |
|
4934 } |
|
4935 |
|
4936 /** |
|
4937 * rtl8169_get_stats - Get rtl8169 read/write statistics |
|
4938 * @dev: The Ethernet Device to get statistics for |
|
4939 * |
|
4940 * Get TX/RX statistics for rtl8169 |
|
4941 */ |
|
4942 static struct net_device_stats *rtl8169_get_stats(struct net_device *dev) |
|
4943 { |
|
4944 struct rtl8169_private *tp = netdev_priv(dev); |
|
4945 void __iomem *ioaddr = tp->mmio_addr; |
|
4946 unsigned long flags; |
|
4947 |
|
4948 if (netif_running(dev)) { |
|
4949 spin_lock_irqsave(&tp->lock, flags); |
|
4950 rtl8169_rx_missed(dev, ioaddr); |
|
4951 spin_unlock_irqrestore(&tp->lock, flags); |
|
4952 } |
|
4953 |
|
4954 return &dev->stats; |
|
4955 } |
|
4956 |
|
4957 static void rtl8169_net_suspend(struct net_device *dev) |
|
4958 { |
|
4959 if (!netif_running(dev)) |
|
4960 return; |
|
4961 |
|
4962 netif_device_detach(dev); |
|
4963 netif_stop_queue(dev); |
|
4964 } |
|
4965 |
|
4966 #ifdef CONFIG_PM |
|
4967 |
|
4968 static int rtl8169_suspend(struct device *device) |
|
4969 { |
|
4970 struct pci_dev *pdev = to_pci_dev(device); |
|
4971 struct net_device *dev = pci_get_drvdata(pdev); |
|
4972 struct rtl8169_private *tp = netdev_priv(dev); |
|
4973 |
|
4974 if (tp->ecdev) |
|
4975 return -EBUSY; |
|
4976 |
|
4977 rtl8169_net_suspend(dev); |
|
4978 |
|
4979 return 0; |
|
4980 } |
|
4981 |
|
4982 static void __rtl8169_resume(struct net_device *dev) |
|
4983 { |
|
4984 netif_device_attach(dev); |
|
4985 rtl8169_schedule_work(dev, rtl8169_reset_task); |
|
4986 } |
|
4987 |
|
4988 static int rtl8169_resume(struct device *device) |
|
4989 { |
|
4990 struct pci_dev *pdev = to_pci_dev(device); |
|
4991 struct net_device *dev = pci_get_drvdata(pdev); |
|
4992 struct rtl8169_private *tp = netdev_priv(dev); |
|
4993 |
|
4994 if (tp->ecdev) |
|
4995 return -EBUSY; |
|
4996 |
|
4997 if (netif_running(dev)) |
|
4998 __rtl8169_resume(dev); |
|
4999 |
|
5000 return 0; |
|
5001 } |
|
5002 |
|
5003 static int rtl8169_runtime_suspend(struct device *device) |
|
5004 { |
|
5005 struct pci_dev *pdev = to_pci_dev(device); |
|
5006 struct net_device *dev = pci_get_drvdata(pdev); |
|
5007 struct rtl8169_private *tp = netdev_priv(dev); |
|
5008 |
|
5009 if (!tp->TxDescArray) |
|
5010 return 0; |
|
5011 |
|
5012 spin_lock_irq(&tp->lock); |
|
5013 tp->saved_wolopts = __rtl8169_get_wol(tp); |
|
5014 __rtl8169_set_wol(tp, WAKE_ANY); |
|
5015 spin_unlock_irq(&tp->lock); |
|
5016 |
|
5017 rtl8169_net_suspend(dev); |
|
5018 |
|
5019 return 0; |
|
5020 } |
|
5021 |
|
5022 static int rtl8169_runtime_resume(struct device *device) |
|
5023 { |
|
5024 struct pci_dev *pdev = to_pci_dev(device); |
|
5025 struct net_device *dev = pci_get_drvdata(pdev); |
|
5026 struct rtl8169_private *tp = netdev_priv(dev); |
|
5027 |
|
5028 if (!tp->TxDescArray) |
|
5029 return 0; |
|
5030 |
|
5031 spin_lock_irq(&tp->lock); |
|
5032 __rtl8169_set_wol(tp, tp->saved_wolopts); |
|
5033 tp->saved_wolopts = 0; |
|
5034 spin_unlock_irq(&tp->lock); |
|
5035 |
|
5036 __rtl8169_resume(dev); |
|
5037 |
|
5038 return 0; |
|
5039 } |
|
5040 |
|
5041 static int rtl8169_runtime_idle(struct device *device) |
|
5042 { |
|
5043 struct pci_dev *pdev = to_pci_dev(device); |
|
5044 struct net_device *dev = pci_get_drvdata(pdev); |
|
5045 struct rtl8169_private *tp = netdev_priv(dev); |
|
5046 |
|
5047 if (!tp->TxDescArray) |
|
5048 return 0; |
|
5049 |
|
5050 rtl8169_check_link_status(dev, tp, tp->mmio_addr); |
|
5051 return -EBUSY; |
|
5052 } |
|
5053 |
|
5054 static const struct dev_pm_ops rtl8169_pm_ops = { |
|
5055 .suspend = rtl8169_suspend, |
|
5056 .resume = rtl8169_resume, |
|
5057 .freeze = rtl8169_suspend, |
|
5058 .thaw = rtl8169_resume, |
|
5059 .poweroff = rtl8169_suspend, |
|
5060 .restore = rtl8169_resume, |
|
5061 .runtime_suspend = rtl8169_runtime_suspend, |
|
5062 .runtime_resume = rtl8169_runtime_resume, |
|
5063 .runtime_idle = rtl8169_runtime_idle, |
|
5064 }; |
|
5065 |
|
5066 #define RTL8169_PM_OPS (&rtl8169_pm_ops) |
|
5067 |
|
5068 #else /* !CONFIG_PM */ |
|
5069 |
|
5070 #define RTL8169_PM_OPS NULL |
|
5071 |
|
5072 #endif /* !CONFIG_PM */ |
|
5073 |
|
5074 static void rtl_shutdown(struct pci_dev *pdev) |
|
5075 { |
|
5076 struct net_device *dev = pci_get_drvdata(pdev); |
|
5077 struct rtl8169_private *tp = netdev_priv(dev); |
|
5078 void __iomem *ioaddr = tp->mmio_addr; |
|
5079 |
|
5080 rtl8169_net_suspend(dev); |
|
5081 |
|
5082 /* restore original MAC address */ |
|
5083 rtl_rar_set(tp, dev->perm_addr); |
|
5084 |
|
5085 spin_lock_irq(&tp->lock); |
|
5086 |
|
5087 rtl8169_asic_down(ioaddr); |
|
5088 |
|
5089 spin_unlock_irq(&tp->lock); |
|
5090 |
|
5091 if (system_state == SYSTEM_POWER_OFF) { |
|
5092 /* WoL fails with some 8168 when the receiver is disabled. */ |
|
5093 if (tp->features & RTL_FEATURE_WOL) { |
|
5094 pci_clear_master(pdev); |
|
5095 |
|
5096 RTL_W8(ChipCmd, CmdRxEnb); |
|
5097 /* PCI commit */ |
|
5098 RTL_R8(ChipCmd); |
|
5099 } |
|
5100 |
|
5101 pci_wake_from_d3(pdev, true); |
|
5102 pci_set_power_state(pdev, PCI_D3hot); |
|
5103 } |
|
5104 } |
|
5105 |
|
5106 static struct pci_driver rtl8169_pci_driver = { |
|
5107 .name = MODULENAME, |
|
5108 .id_table = rtl8169_pci_tbl, |
|
5109 .probe = rtl8169_init_one, |
|
5110 .remove = __devexit_p(rtl8169_remove_one), |
|
5111 .shutdown = rtl_shutdown, |
|
5112 .driver.pm = RTL8169_PM_OPS, |
|
5113 }; |
|
5114 |
|
5115 static int __init rtl8169_init_module(void) |
|
5116 { |
|
5117 return pci_register_driver(&rtl8169_pci_driver); |
|
5118 } |
|
5119 |
|
5120 static void __exit rtl8169_cleanup_module(void) |
|
5121 { |
|
5122 pci_unregister_driver(&rtl8169_pci_driver); |
|
5123 } |
|
5124 |
|
5125 module_init(rtl8169_init_module); |
|
5126 module_exit(rtl8169_cleanup_module); |