|
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 * vim: noexpandtab |
|
11 */ |
|
12 |
|
13 #include <linux/module.h> |
|
14 #include <linux/moduleparam.h> |
|
15 #include <linux/pci.h> |
|
16 #include <linux/netdevice.h> |
|
17 #include <linux/etherdevice.h> |
|
18 #include <linux/delay.h> |
|
19 #include <linux/ethtool.h> |
|
20 #include <linux/mii.h> |
|
21 #include <linux/if_vlan.h> |
|
22 #include <linux/crc32.h> |
|
23 #include <linux/in.h> |
|
24 #include <linux/ip.h> |
|
25 #include <linux/tcp.h> |
|
26 #include <linux/init.h> |
|
27 #include <linux/dma-mapping.h> |
|
28 |
|
29 #include <asm/system.h> |
|
30 #include <asm/io.h> |
|
31 #include <asm/irq.h> |
|
32 |
|
33 #include "../globals.h" |
|
34 #include "ecdev.h" |
|
35 |
|
36 #define RTL8169_VERSION "2.3LK-NAPI" |
|
37 #define MODULENAME "ec_r8169" |
|
38 #define PFX MODULENAME ": " |
|
39 |
|
40 #ifdef RTL8169_DEBUG |
|
41 #define assert(expr) \ |
|
42 if (!(expr)) { \ |
|
43 printk( "Assertion failed! %s,%s,%s,line=%d\n", \ |
|
44 #expr,__FILE__,__func__,__LINE__); \ |
|
45 } |
|
46 #define dprintk(fmt, args...) \ |
|
47 do { printk(KERN_DEBUG PFX fmt, ## args); } while (0) |
|
48 #else |
|
49 #define assert(expr) do {} while (0) |
|
50 #define dprintk(fmt, args...) do {} while (0) |
|
51 #endif /* RTL8169_DEBUG */ |
|
52 |
|
53 #define R8169_MSG_DEFAULT \ |
|
54 (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN) |
|
55 |
|
56 #define TX_BUFFS_AVAIL(tp) \ |
|
57 (tp->dirty_tx + NUM_TX_DESC - tp->cur_tx - 1) |
|
58 |
|
59 /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). |
|
60 The RTL chips use a 64 element hash table based on the Ethernet CRC. */ |
|
61 static const int multicast_filter_limit = 32; |
|
62 |
|
63 /* MAC address length */ |
|
64 #define MAC_ADDR_LEN 6 |
|
65 |
|
66 #define MAX_READ_REQUEST_SHIFT 12 |
|
67 #define RX_FIFO_THRESH 7 /* 7 means NO threshold, Rx buffer level before first PCI xfer. */ |
|
68 #define RX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */ |
|
69 #define TX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */ |
|
70 #define EarlyTxThld 0x3F /* 0x3F means NO early transmit */ |
|
71 #define SafeMtu 0x1c20 /* ... actually life sucks beyond ~7k */ |
|
72 #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */ |
|
73 |
|
74 #define R8169_REGS_SIZE 256 |
|
75 #define R8169_NAPI_WEIGHT 64 |
|
76 #define NUM_TX_DESC 64 /* Number of Tx descriptor registers */ |
|
77 #define NUM_RX_DESC 256 /* Number of Rx descriptor registers */ |
|
78 #define RX_BUF_SIZE 1536 /* Rx Buffer size */ |
|
79 #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc)) |
|
80 #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc)) |
|
81 |
|
82 #define RTL8169_TX_TIMEOUT (6*HZ) |
|
83 #define RTL8169_PHY_TIMEOUT (10*HZ) |
|
84 |
|
85 #define RTL_EEPROM_SIG cpu_to_le32(0x8129) |
|
86 #define RTL_EEPROM_SIG_MASK cpu_to_le32(0xffff) |
|
87 #define RTL_EEPROM_SIG_ADDR 0x0000 |
|
88 |
|
89 /* write/read MMIO register */ |
|
90 #define RTL_W8(reg, val8) writeb ((val8), ioaddr + (reg)) |
|
91 #define RTL_W16(reg, val16) writew ((val16), ioaddr + (reg)) |
|
92 #define RTL_W32(reg, val32) writel ((val32), ioaddr + (reg)) |
|
93 #define RTL_R8(reg) readb (ioaddr + (reg)) |
|
94 #define RTL_R16(reg) readw (ioaddr + (reg)) |
|
95 #define RTL_R32(reg) ((unsigned long) readl (ioaddr + (reg))) |
|
96 |
|
97 enum mac_version { |
|
98 RTL_GIGA_MAC_NONE = 0x00, |
|
99 RTL_GIGA_MAC_VER_01 = 0x01, // 8169 |
|
100 RTL_GIGA_MAC_VER_02 = 0x02, // 8169S |
|
101 RTL_GIGA_MAC_VER_03 = 0x03, // 8110S |
|
102 RTL_GIGA_MAC_VER_04 = 0x04, // 8169SB |
|
103 RTL_GIGA_MAC_VER_05 = 0x05, // 8110SCd |
|
104 RTL_GIGA_MAC_VER_06 = 0x06, // 8110SCe |
|
105 RTL_GIGA_MAC_VER_07 = 0x07, // 8102e |
|
106 RTL_GIGA_MAC_VER_08 = 0x08, // 8102e |
|
107 RTL_GIGA_MAC_VER_09 = 0x09, // 8102e |
|
108 RTL_GIGA_MAC_VER_10 = 0x0a, // 8101e |
|
109 RTL_GIGA_MAC_VER_11 = 0x0b, // 8168Bb |
|
110 RTL_GIGA_MAC_VER_12 = 0x0c, // 8168Be |
|
111 RTL_GIGA_MAC_VER_13 = 0x0d, // 8101Eb |
|
112 RTL_GIGA_MAC_VER_14 = 0x0e, // 8101 ? |
|
113 RTL_GIGA_MAC_VER_15 = 0x0f, // 8101 ? |
|
114 RTL_GIGA_MAC_VER_16 = 0x11, // 8101Ec |
|
115 RTL_GIGA_MAC_VER_17 = 0x10, // 8168Bf |
|
116 RTL_GIGA_MAC_VER_18 = 0x12, // 8168CP |
|
117 RTL_GIGA_MAC_VER_19 = 0x13, // 8168C |
|
118 RTL_GIGA_MAC_VER_20 = 0x14, // 8168C |
|
119 RTL_GIGA_MAC_VER_21 = 0x15, // 8168C |
|
120 RTL_GIGA_MAC_VER_22 = 0x16, // 8168C |
|
121 RTL_GIGA_MAC_VER_23 = 0x17, // 8168CP |
|
122 RTL_GIGA_MAC_VER_24 = 0x18, // 8168CP |
|
123 RTL_GIGA_MAC_VER_25 = 0x19 // 8168D |
|
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 }; |
|
160 #undef _R |
|
161 |
|
162 enum cfg_version { |
|
163 RTL_CFG_0 = 0x00, |
|
164 RTL_CFG_1, |
|
165 RTL_CFG_2 |
|
166 }; |
|
167 |
|
168 static void rtl_hw_start_8169(struct net_device *); |
|
169 static void rtl_hw_start_8168(struct net_device *); |
|
170 static void rtl_hw_start_8101(struct net_device *); |
|
171 |
|
172 static struct pci_device_id rtl8169_pci_tbl[] = { |
|
173 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 }, |
|
174 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8136), 0, 0, RTL_CFG_2 }, |
|
175 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_0 }, |
|
176 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_1 }, |
|
177 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 }, |
|
178 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4300), 0, 0, RTL_CFG_0 }, |
|
179 { PCI_DEVICE(PCI_VENDOR_ID_AT, 0xc107), 0, 0, RTL_CFG_0 }, |
|
180 { PCI_DEVICE(0x16ec, 0x0116), 0, 0, RTL_CFG_0 }, |
|
181 { PCI_VENDOR_ID_LINKSYS, 0x1032, |
|
182 PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 }, |
|
183 { 0x0001, 0x8168, |
|
184 PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 }, |
|
185 {0,}, |
|
186 }; |
|
187 |
|
188 /* prevent driver from being loaded automatically */ |
|
189 //MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl); |
|
190 |
|
191 static int rx_copybreak = 200; |
|
192 static int use_dac; |
|
193 static struct { |
|
194 u32 msg_enable; |
|
195 } debug = { -1 }; |
|
196 |
|
197 enum rtl_registers { |
|
198 MAC0 = 0, /* Ethernet hardware address. */ |
|
199 MAC4 = 4, |
|
200 MAR0 = 8, /* Multicast filter. */ |
|
201 CounterAddrLow = 0x10, |
|
202 CounterAddrHigh = 0x14, |
|
203 TxDescStartAddrLow = 0x20, |
|
204 TxDescStartAddrHigh = 0x24, |
|
205 TxHDescStartAddrLow = 0x28, |
|
206 TxHDescStartAddrHigh = 0x2c, |
|
207 FLASH = 0x30, |
|
208 ERSR = 0x36, |
|
209 ChipCmd = 0x37, |
|
210 TxPoll = 0x38, |
|
211 IntrMask = 0x3c, |
|
212 IntrStatus = 0x3e, |
|
213 TxConfig = 0x40, |
|
214 RxConfig = 0x44, |
|
215 RxMissed = 0x4c, |
|
216 Cfg9346 = 0x50, |
|
217 Config0 = 0x51, |
|
218 Config1 = 0x52, |
|
219 Config2 = 0x53, |
|
220 Config3 = 0x54, |
|
221 Config4 = 0x55, |
|
222 Config5 = 0x56, |
|
223 MultiIntr = 0x5c, |
|
224 PHYAR = 0x60, |
|
225 PHYstatus = 0x6c, |
|
226 RxMaxSize = 0xda, |
|
227 CPlusCmd = 0xe0, |
|
228 IntrMitigate = 0xe2, |
|
229 RxDescAddrLow = 0xe4, |
|
230 RxDescAddrHigh = 0xe8, |
|
231 EarlyTxThres = 0xec, |
|
232 FuncEvent = 0xf0, |
|
233 FuncEventMask = 0xf4, |
|
234 FuncPresetState = 0xf8, |
|
235 FuncForceEvent = 0xfc, |
|
236 }; |
|
237 |
|
238 enum rtl8110_registers { |
|
239 TBICSR = 0x64, |
|
240 TBI_ANAR = 0x68, |
|
241 TBI_LPAR = 0x6a, |
|
242 }; |
|
243 |
|
244 enum rtl8168_8101_registers { |
|
245 CSIDR = 0x64, |
|
246 CSIAR = 0x68, |
|
247 #define CSIAR_FLAG 0x80000000 |
|
248 #define CSIAR_WRITE_CMD 0x80000000 |
|
249 #define CSIAR_BYTE_ENABLE 0x0f |
|
250 #define CSIAR_BYTE_ENABLE_SHIFT 12 |
|
251 #define CSIAR_ADDR_MASK 0x0fff |
|
252 |
|
253 EPHYAR = 0x80, |
|
254 #define EPHYAR_FLAG 0x80000000 |
|
255 #define EPHYAR_WRITE_CMD 0x80000000 |
|
256 #define EPHYAR_REG_MASK 0x1f |
|
257 #define EPHYAR_REG_SHIFT 16 |
|
258 #define EPHYAR_DATA_MASK 0xffff |
|
259 DBG_REG = 0xd1, |
|
260 #define FIX_NAK_1 (1 << 4) |
|
261 #define FIX_NAK_2 (1 << 3) |
|
262 }; |
|
263 |
|
264 enum rtl_register_content { |
|
265 /* InterruptStatusBits */ |
|
266 SYSErr = 0x8000, |
|
267 PCSTimeout = 0x4000, |
|
268 SWInt = 0x0100, |
|
269 TxDescUnavail = 0x0080, |
|
270 RxFIFOOver = 0x0040, |
|
271 LinkChg = 0x0020, |
|
272 RxOverflow = 0x0010, |
|
273 TxErr = 0x0008, |
|
274 TxOK = 0x0004, |
|
275 RxErr = 0x0002, |
|
276 RxOK = 0x0001, |
|
277 |
|
278 /* RxStatusDesc */ |
|
279 RxFOVF = (1 << 23), |
|
280 RxRWT = (1 << 22), |
|
281 RxRES = (1 << 21), |
|
282 RxRUNT = (1 << 20), |
|
283 RxCRC = (1 << 19), |
|
284 |
|
285 /* ChipCmdBits */ |
|
286 CmdReset = 0x10, |
|
287 CmdRxEnb = 0x08, |
|
288 CmdTxEnb = 0x04, |
|
289 RxBufEmpty = 0x01, |
|
290 |
|
291 /* TXPoll register p.5 */ |
|
292 HPQ = 0x80, /* Poll cmd on the high prio queue */ |
|
293 NPQ = 0x40, /* Poll cmd on the low prio queue */ |
|
294 FSWInt = 0x01, /* Forced software interrupt */ |
|
295 |
|
296 /* Cfg9346Bits */ |
|
297 Cfg9346_Lock = 0x00, |
|
298 Cfg9346_Unlock = 0xc0, |
|
299 |
|
300 /* rx_mode_bits */ |
|
301 AcceptErr = 0x20, |
|
302 AcceptRunt = 0x10, |
|
303 AcceptBroadcast = 0x08, |
|
304 AcceptMulticast = 0x04, |
|
305 AcceptMyPhys = 0x02, |
|
306 AcceptAllPhys = 0x01, |
|
307 |
|
308 /* RxConfigBits */ |
|
309 RxCfgFIFOShift = 13, |
|
310 RxCfgDMAShift = 8, |
|
311 |
|
312 /* TxConfigBits */ |
|
313 TxInterFrameGapShift = 24, |
|
314 TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */ |
|
315 |
|
316 /* Config1 register p.24 */ |
|
317 LEDS1 = (1 << 7), |
|
318 LEDS0 = (1 << 6), |
|
319 MSIEnable = (1 << 5), /* Enable Message Signaled Interrupt */ |
|
320 Speed_down = (1 << 4), |
|
321 MEMMAP = (1 << 3), |
|
322 IOMAP = (1 << 2), |
|
323 VPD = (1 << 1), |
|
324 PMEnable = (1 << 0), /* Power Management Enable */ |
|
325 |
|
326 /* Config2 register p. 25 */ |
|
327 PCI_Clock_66MHz = 0x01, |
|
328 PCI_Clock_33MHz = 0x00, |
|
329 |
|
330 /* Config3 register p.25 */ |
|
331 MagicPacket = (1 << 5), /* Wake up when receives a Magic Packet */ |
|
332 LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */ |
|
333 Beacon_en = (1 << 0), /* 8168 only. Reserved in the 8168b */ |
|
334 |
|
335 /* Config5 register p.27 */ |
|
336 BWF = (1 << 6), /* Accept Broadcast wakeup frame */ |
|
337 MWF = (1 << 5), /* Accept Multicast wakeup frame */ |
|
338 UWF = (1 << 4), /* Accept Unicast wakeup frame */ |
|
339 LanWake = (1 << 1), /* LanWake enable/disable */ |
|
340 PMEStatus = (1 << 0), /* PME status can be reset by PCI RST# */ |
|
341 |
|
342 /* TBICSR p.28 */ |
|
343 TBIReset = 0x80000000, |
|
344 TBILoopback = 0x40000000, |
|
345 TBINwEnable = 0x20000000, |
|
346 TBINwRestart = 0x10000000, |
|
347 TBILinkOk = 0x02000000, |
|
348 TBINwComplete = 0x01000000, |
|
349 |
|
350 /* CPlusCmd p.31 */ |
|
351 EnableBist = (1 << 15), // 8168 8101 |
|
352 Mac_dbgo_oe = (1 << 14), // 8168 8101 |
|
353 Normal_mode = (1 << 13), // unused |
|
354 Force_half_dup = (1 << 12), // 8168 8101 |
|
355 Force_rxflow_en = (1 << 11), // 8168 8101 |
|
356 Force_txflow_en = (1 << 10), // 8168 8101 |
|
357 Cxpl_dbg_sel = (1 << 9), // 8168 8101 |
|
358 ASF = (1 << 8), // 8168 8101 |
|
359 PktCntrDisable = (1 << 7), // 8168 8101 |
|
360 Mac_dbgo_sel = 0x001c, // 8168 |
|
361 RxVlan = (1 << 6), |
|
362 RxChkSum = (1 << 5), |
|
363 PCIDAC = (1 << 4), |
|
364 PCIMulRW = (1 << 3), |
|
365 INTT_0 = 0x0000, // 8168 |
|
366 INTT_1 = 0x0001, // 8168 |
|
367 INTT_2 = 0x0002, // 8168 |
|
368 INTT_3 = 0x0003, // 8168 |
|
369 |
|
370 /* rtl8169_PHYstatus */ |
|
371 TBI_Enable = 0x80, |
|
372 TxFlowCtrl = 0x40, |
|
373 RxFlowCtrl = 0x20, |
|
374 _1000bpsF = 0x10, |
|
375 _100bps = 0x08, |
|
376 _10bps = 0x04, |
|
377 LinkStatus = 0x02, |
|
378 FullDup = 0x01, |
|
379 |
|
380 /* _TBICSRBit */ |
|
381 TBILinkOK = 0x02000000, |
|
382 |
|
383 /* DumpCounterCommand */ |
|
384 CounterDump = 0x8, |
|
385 }; |
|
386 |
|
387 enum desc_status_bit { |
|
388 DescOwn = (1 << 31), /* Descriptor is owned by NIC */ |
|
389 RingEnd = (1 << 30), /* End of descriptor ring */ |
|
390 FirstFrag = (1 << 29), /* First segment of a packet */ |
|
391 LastFrag = (1 << 28), /* Final segment of a packet */ |
|
392 |
|
393 /* Tx private */ |
|
394 LargeSend = (1 << 27), /* TCP Large Send Offload (TSO) */ |
|
395 MSSShift = 16, /* MSS value position */ |
|
396 MSSMask = 0xfff, /* MSS value + LargeSend bit: 12 bits */ |
|
397 IPCS = (1 << 18), /* Calculate IP checksum */ |
|
398 UDPCS = (1 << 17), /* Calculate UDP/IP checksum */ |
|
399 TCPCS = (1 << 16), /* Calculate TCP/IP checksum */ |
|
400 TxVlanTag = (1 << 17), /* Add VLAN tag */ |
|
401 |
|
402 /* Rx private */ |
|
403 PID1 = (1 << 18), /* Protocol ID bit 1/2 */ |
|
404 PID0 = (1 << 17), /* Protocol ID bit 2/2 */ |
|
405 |
|
406 #define RxProtoUDP (PID1) |
|
407 #define RxProtoTCP (PID0) |
|
408 #define RxProtoIP (PID1 | PID0) |
|
409 #define RxProtoMask RxProtoIP |
|
410 |
|
411 IPFail = (1 << 16), /* IP checksum failed */ |
|
412 UDPFail = (1 << 15), /* UDP/IP checksum failed */ |
|
413 TCPFail = (1 << 14), /* TCP/IP checksum failed */ |
|
414 RxVlanTag = (1 << 16), /* VLAN tag available */ |
|
415 }; |
|
416 |
|
417 #define RsvdMask 0x3fffc000 |
|
418 |
|
419 struct TxDesc { |
|
420 __le32 opts1; |
|
421 __le32 opts2; |
|
422 __le64 addr; |
|
423 }; |
|
424 |
|
425 struct RxDesc { |
|
426 __le32 opts1; |
|
427 __le32 opts2; |
|
428 __le64 addr; |
|
429 }; |
|
430 |
|
431 struct ring_info { |
|
432 struct sk_buff *skb; |
|
433 u32 len; |
|
434 u8 __pad[sizeof(void *) - sizeof(u32)]; |
|
435 }; |
|
436 |
|
437 enum features { |
|
438 RTL_FEATURE_WOL = (1 << 0), |
|
439 RTL_FEATURE_MSI = (1 << 1), |
|
440 RTL_FEATURE_GMII = (1 << 2), |
|
441 }; |
|
442 |
|
443 struct rtl8169_counters { |
|
444 __le64 tx_packets; |
|
445 __le64 rx_packets; |
|
446 __le64 tx_errors; |
|
447 __le32 rx_errors; |
|
448 __le16 rx_missed; |
|
449 __le16 align_errors; |
|
450 __le32 tx_one_collision; |
|
451 __le32 tx_multi_collision; |
|
452 __le64 rx_unicast; |
|
453 __le64 rx_broadcast; |
|
454 __le32 rx_multicast; |
|
455 __le16 tx_aborted; |
|
456 __le16 tx_underun; |
|
457 }; |
|
458 |
|
459 struct rtl8169_private { |
|
460 void __iomem *mmio_addr; /* memory map physical address */ |
|
461 struct pci_dev *pci_dev; /* Index of PCI device */ |
|
462 struct net_device *dev; |
|
463 struct napi_struct napi; |
|
464 spinlock_t lock; /* spin lock flag */ |
|
465 u32 msg_enable; |
|
466 int chipset; |
|
467 int mac_version; |
|
468 u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */ |
|
469 u32 cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */ |
|
470 u32 dirty_rx; |
|
471 u32 dirty_tx; |
|
472 struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */ |
|
473 struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */ |
|
474 dma_addr_t TxPhyAddr; |
|
475 dma_addr_t RxPhyAddr; |
|
476 struct sk_buff *Rx_skbuff[NUM_RX_DESC]; /* Rx data buffers */ |
|
477 struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ |
|
478 unsigned align; |
|
479 unsigned rx_buf_sz; |
|
480 struct timer_list timer; |
|
481 u16 cp_cmd; |
|
482 u16 intr_event; |
|
483 u16 napi_event; |
|
484 u16 intr_mask; |
|
485 int phy_1000_ctrl_reg; |
|
486 #ifdef CONFIG_R8169_VLAN |
|
487 struct vlan_group *vlgrp; |
|
488 #endif |
|
489 int (*set_speed)(struct net_device *, u8 autoneg, u16 speed, u8 duplex); |
|
490 int (*get_settings)(struct net_device *, struct ethtool_cmd *); |
|
491 void (*phy_reset_enable)(void __iomem *); |
|
492 void (*hw_start)(struct net_device *); |
|
493 unsigned int (*phy_reset_pending)(void __iomem *); |
|
494 unsigned int (*link_ok)(void __iomem *); |
|
495 int (*do_ioctl)(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd); |
|
496 int pcie_cap; |
|
497 struct delayed_work task; |
|
498 unsigned features; |
|
499 |
|
500 struct mii_if_info mii; |
|
501 struct rtl8169_counters counters; |
|
502 |
|
503 ec_device_t *ecdev; |
|
504 unsigned long ec_watchdog_jiffies; |
|
505 }; |
|
506 |
|
507 MODULE_AUTHOR("Florian Pose <fp@igh-essen.com>"); |
|
508 MODULE_DESCRIPTION("EtherCAT-capable RealTek RTL-8169 Gigabit Ethernet driver"); |
|
509 module_param(rx_copybreak, int, 0); |
|
510 MODULE_PARM_DESC(rx_copybreak, "Copy breakpoint for copy-only-tiny-frames"); |
|
511 module_param(use_dac, int, 0); |
|
512 MODULE_PARM_DESC(use_dac, "Enable PCI DAC. Unsafe on 32 bit PCI slot."); |
|
513 module_param_named(debug, debug.msg_enable, int, 0); |
|
514 MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)"); |
|
515 MODULE_LICENSE("GPL"); |
|
516 MODULE_VERSION(EC_MASTER_VERSION); |
|
517 |
|
518 static int rtl8169_open(struct net_device *dev); |
|
519 static int rtl8169_start_xmit(struct sk_buff *skb, struct net_device *dev); |
|
520 static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance); |
|
521 static int rtl8169_init_ring(struct net_device *dev); |
|
522 static void rtl_hw_start(struct net_device *dev); |
|
523 static int rtl8169_close(struct net_device *dev); |
|
524 static void rtl_set_rx_mode(struct net_device *dev); |
|
525 static void rtl8169_tx_timeout(struct net_device *dev); |
|
526 static struct net_device_stats *rtl8169_get_stats(struct net_device *dev); |
|
527 static int rtl8169_rx_interrupt(struct net_device *, struct rtl8169_private *, |
|
528 void __iomem *, u32 budget); |
|
529 static int rtl8169_change_mtu(struct net_device *dev, int new_mtu); |
|
530 static void rtl8169_down(struct net_device *dev); |
|
531 static void rtl8169_rx_clear(struct rtl8169_private *tp); |
|
532 static void ec_poll(struct net_device *dev); |
|
533 static int rtl8169_poll(struct napi_struct *napi, int budget); |
|
534 |
|
535 static const unsigned int rtl8169_rx_config = |
|
536 (RX_FIFO_THRESH << RxCfgFIFOShift) | (RX_DMA_BURST << RxCfgDMAShift); |
|
537 |
|
538 static void mdio_write(void __iomem *ioaddr, int reg_addr, int value) |
|
539 { |
|
540 int i; |
|
541 |
|
542 RTL_W32(PHYAR, 0x80000000 | (reg_addr & 0x1f) << 16 | (value & 0xffff)); |
|
543 |
|
544 for (i = 20; i > 0; i--) { |
|
545 /* |
|
546 * Check if the RTL8169 has completed writing to the specified |
|
547 * MII register. |
|
548 */ |
|
549 if (!(RTL_R32(PHYAR) & 0x80000000)) |
|
550 break; |
|
551 udelay(25); |
|
552 } |
|
553 } |
|
554 |
|
555 static int mdio_read(void __iomem *ioaddr, int reg_addr) |
|
556 { |
|
557 int i, value = -1; |
|
558 |
|
559 RTL_W32(PHYAR, 0x0 | (reg_addr & 0x1f) << 16); |
|
560 |
|
561 for (i = 20; i > 0; i--) { |
|
562 /* |
|
563 * Check if the RTL8169 has completed retrieving data from |
|
564 * the specified MII register. |
|
565 */ |
|
566 if (RTL_R32(PHYAR) & 0x80000000) { |
|
567 value = RTL_R32(PHYAR) & 0xffff; |
|
568 break; |
|
569 } |
|
570 udelay(25); |
|
571 } |
|
572 return value; |
|
573 } |
|
574 |
|
575 static void mdio_patch(void __iomem *ioaddr, int reg_addr, int value) |
|
576 { |
|
577 mdio_write(ioaddr, reg_addr, mdio_read(ioaddr, reg_addr) | value); |
|
578 } |
|
579 |
|
580 static void rtl_mdio_write(struct net_device *dev, int phy_id, int location, |
|
581 int val) |
|
582 { |
|
583 struct rtl8169_private *tp = netdev_priv(dev); |
|
584 void __iomem *ioaddr = tp->mmio_addr; |
|
585 |
|
586 mdio_write(ioaddr, location, val); |
|
587 } |
|
588 |
|
589 static int rtl_mdio_read(struct net_device *dev, int phy_id, int location) |
|
590 { |
|
591 struct rtl8169_private *tp = netdev_priv(dev); |
|
592 void __iomem *ioaddr = tp->mmio_addr; |
|
593 |
|
594 return mdio_read(ioaddr, location); |
|
595 } |
|
596 |
|
597 static void rtl_ephy_write(void __iomem *ioaddr, int reg_addr, int value) |
|
598 { |
|
599 unsigned int i; |
|
600 |
|
601 RTL_W32(EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) | |
|
602 (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
|
603 |
|
604 for (i = 0; i < 100; i++) { |
|
605 if (!(RTL_R32(EPHYAR) & EPHYAR_FLAG)) |
|
606 break; |
|
607 udelay(10); |
|
608 } |
|
609 } |
|
610 |
|
611 static u16 rtl_ephy_read(void __iomem *ioaddr, int reg_addr) |
|
612 { |
|
613 u16 value = 0xffff; |
|
614 unsigned int i; |
|
615 |
|
616 RTL_W32(EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
|
617 |
|
618 for (i = 0; i < 100; i++) { |
|
619 if (RTL_R32(EPHYAR) & EPHYAR_FLAG) { |
|
620 value = RTL_R32(EPHYAR) & EPHYAR_DATA_MASK; |
|
621 break; |
|
622 } |
|
623 udelay(10); |
|
624 } |
|
625 |
|
626 return value; |
|
627 } |
|
628 |
|
629 static void rtl_csi_write(void __iomem *ioaddr, int addr, int value) |
|
630 { |
|
631 unsigned int i; |
|
632 |
|
633 RTL_W32(CSIDR, value); |
|
634 RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
|
635 CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
|
636 |
|
637 for (i = 0; i < 100; i++) { |
|
638 if (!(RTL_R32(CSIAR) & CSIAR_FLAG)) |
|
639 break; |
|
640 udelay(10); |
|
641 } |
|
642 } |
|
643 |
|
644 static u32 rtl_csi_read(void __iomem *ioaddr, int addr) |
|
645 { |
|
646 u32 value = ~0x00; |
|
647 unsigned int i; |
|
648 |
|
649 RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) | |
|
650 CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
|
651 |
|
652 for (i = 0; i < 100; i++) { |
|
653 if (RTL_R32(CSIAR) & CSIAR_FLAG) { |
|
654 value = RTL_R32(CSIDR); |
|
655 break; |
|
656 } |
|
657 udelay(10); |
|
658 } |
|
659 |
|
660 return value; |
|
661 } |
|
662 |
|
663 static void rtl8169_irq_mask_and_ack(void __iomem *ioaddr) |
|
664 { |
|
665 RTL_W16(IntrMask, 0x0000); |
|
666 |
|
667 RTL_W16(IntrStatus, 0xffff); |
|
668 } |
|
669 |
|
670 static void rtl8169_asic_down(void __iomem *ioaddr) |
|
671 { |
|
672 RTL_W8(ChipCmd, 0x00); |
|
673 rtl8169_irq_mask_and_ack(ioaddr); |
|
674 RTL_R16(CPlusCmd); |
|
675 } |
|
676 |
|
677 static unsigned int rtl8169_tbi_reset_pending(void __iomem *ioaddr) |
|
678 { |
|
679 return RTL_R32(TBICSR) & TBIReset; |
|
680 } |
|
681 |
|
682 static unsigned int rtl8169_xmii_reset_pending(void __iomem *ioaddr) |
|
683 { |
|
684 return mdio_read(ioaddr, MII_BMCR) & BMCR_RESET; |
|
685 } |
|
686 |
|
687 static unsigned int rtl8169_tbi_link_ok(void __iomem *ioaddr) |
|
688 { |
|
689 return RTL_R32(TBICSR) & TBILinkOk; |
|
690 } |
|
691 |
|
692 static unsigned int rtl8169_xmii_link_ok(void __iomem *ioaddr) |
|
693 { |
|
694 return RTL_R8(PHYstatus) & LinkStatus; |
|
695 } |
|
696 |
|
697 static void rtl8169_tbi_reset_enable(void __iomem *ioaddr) |
|
698 { |
|
699 RTL_W32(TBICSR, RTL_R32(TBICSR) | TBIReset); |
|
700 } |
|
701 |
|
702 static void rtl8169_xmii_reset_enable(void __iomem *ioaddr) |
|
703 { |
|
704 unsigned int val; |
|
705 |
|
706 val = mdio_read(ioaddr, MII_BMCR) | BMCR_RESET; |
|
707 mdio_write(ioaddr, MII_BMCR, val & 0xffff); |
|
708 } |
|
709 |
|
710 static void rtl8169_check_link_status(struct net_device *dev, |
|
711 struct rtl8169_private *tp, |
|
712 void __iomem *ioaddr) |
|
713 { |
|
714 unsigned long flags; |
|
715 |
|
716 if (tp->ecdev) { |
|
717 ecdev_set_link(tp->ecdev, tp->link_ok(ioaddr) ? 1 : 0); |
|
718 } else { |
|
719 spin_lock_irqsave(&tp->lock, flags); |
|
720 if (tp->link_ok(ioaddr)) { |
|
721 netif_carrier_on(dev); |
|
722 if (netif_msg_ifup(tp)) |
|
723 printk(KERN_INFO PFX "%s: link up\n", dev->name); |
|
724 } else { |
|
725 if (netif_msg_ifdown(tp)) |
|
726 printk(KERN_INFO PFX "%s: link down\n", dev->name); |
|
727 netif_carrier_off(dev); |
|
728 } |
|
729 spin_unlock_irqrestore(&tp->lock, flags); |
|
730 } |
|
731 } |
|
732 |
|
733 static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
|
734 { |
|
735 struct rtl8169_private *tp = netdev_priv(dev); |
|
736 void __iomem *ioaddr = tp->mmio_addr; |
|
737 u8 options; |
|
738 |
|
739 wol->wolopts = 0; |
|
740 |
|
741 #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST) |
|
742 wol->supported = WAKE_ANY; |
|
743 |
|
744 spin_lock_irq(&tp->lock); |
|
745 |
|
746 options = RTL_R8(Config1); |
|
747 if (!(options & PMEnable)) |
|
748 goto out_unlock; |
|
749 |
|
750 options = RTL_R8(Config3); |
|
751 if (options & LinkUp) |
|
752 wol->wolopts |= WAKE_PHY; |
|
753 if (options & MagicPacket) |
|
754 wol->wolopts |= WAKE_MAGIC; |
|
755 |
|
756 options = RTL_R8(Config5); |
|
757 if (options & UWF) |
|
758 wol->wolopts |= WAKE_UCAST; |
|
759 if (options & BWF) |
|
760 wol->wolopts |= WAKE_BCAST; |
|
761 if (options & MWF) |
|
762 wol->wolopts |= WAKE_MCAST; |
|
763 |
|
764 out_unlock: |
|
765 spin_unlock_irq(&tp->lock); |
|
766 } |
|
767 |
|
768 static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
|
769 { |
|
770 struct rtl8169_private *tp = netdev_priv(dev); |
|
771 void __iomem *ioaddr = tp->mmio_addr; |
|
772 unsigned int i; |
|
773 static struct { |
|
774 u32 opt; |
|
775 u16 reg; |
|
776 u8 mask; |
|
777 } cfg[] = { |
|
778 { WAKE_ANY, Config1, PMEnable }, |
|
779 { WAKE_PHY, Config3, LinkUp }, |
|
780 { WAKE_MAGIC, Config3, MagicPacket }, |
|
781 { WAKE_UCAST, Config5, UWF }, |
|
782 { WAKE_BCAST, Config5, BWF }, |
|
783 { WAKE_MCAST, Config5, MWF }, |
|
784 { WAKE_ANY, Config5, LanWake } |
|
785 }; |
|
786 |
|
787 spin_lock_irq(&tp->lock); |
|
788 |
|
789 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
790 |
|
791 for (i = 0; i < ARRAY_SIZE(cfg); i++) { |
|
792 u8 options = RTL_R8(cfg[i].reg) & ~cfg[i].mask; |
|
793 if (wol->wolopts & cfg[i].opt) |
|
794 options |= cfg[i].mask; |
|
795 RTL_W8(cfg[i].reg, options); |
|
796 } |
|
797 |
|
798 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
799 |
|
800 if (wol->wolopts) |
|
801 tp->features |= RTL_FEATURE_WOL; |
|
802 else |
|
803 tp->features &= ~RTL_FEATURE_WOL; |
|
804 device_set_wakeup_enable(&tp->pci_dev->dev, wol->wolopts); |
|
805 |
|
806 spin_unlock_irq(&tp->lock); |
|
807 |
|
808 return 0; |
|
809 } |
|
810 |
|
811 static void rtl8169_get_drvinfo(struct net_device *dev, |
|
812 struct ethtool_drvinfo *info) |
|
813 { |
|
814 struct rtl8169_private *tp = netdev_priv(dev); |
|
815 |
|
816 strcpy(info->driver, MODULENAME); |
|
817 strcpy(info->version, RTL8169_VERSION); |
|
818 strcpy(info->bus_info, pci_name(tp->pci_dev)); |
|
819 } |
|
820 |
|
821 static int rtl8169_get_regs_len(struct net_device *dev) |
|
822 { |
|
823 return R8169_REGS_SIZE; |
|
824 } |
|
825 |
|
826 static int rtl8169_set_speed_tbi(struct net_device *dev, |
|
827 u8 autoneg, u16 speed, u8 duplex) |
|
828 { |
|
829 struct rtl8169_private *tp = netdev_priv(dev); |
|
830 void __iomem *ioaddr = tp->mmio_addr; |
|
831 int ret = 0; |
|
832 u32 reg; |
|
833 |
|
834 reg = RTL_R32(TBICSR); |
|
835 if ((autoneg == AUTONEG_DISABLE) && (speed == SPEED_1000) && |
|
836 (duplex == DUPLEX_FULL)) { |
|
837 RTL_W32(TBICSR, reg & ~(TBINwEnable | TBINwRestart)); |
|
838 } else if (autoneg == AUTONEG_ENABLE) |
|
839 RTL_W32(TBICSR, reg | TBINwEnable | TBINwRestart); |
|
840 else { |
|
841 if (netif_msg_link(tp)) { |
|
842 printk(KERN_WARNING "%s: " |
|
843 "incorrect speed setting refused in TBI mode\n", |
|
844 dev->name); |
|
845 } |
|
846 ret = -EOPNOTSUPP; |
|
847 } |
|
848 |
|
849 return ret; |
|
850 } |
|
851 |
|
852 static int rtl8169_set_speed_xmii(struct net_device *dev, |
|
853 u8 autoneg, u16 speed, u8 duplex) |
|
854 { |
|
855 struct rtl8169_private *tp = netdev_priv(dev); |
|
856 void __iomem *ioaddr = tp->mmio_addr; |
|
857 int giga_ctrl, bmcr; |
|
858 |
|
859 if (autoneg == AUTONEG_ENABLE) { |
|
860 int auto_nego; |
|
861 |
|
862 auto_nego = mdio_read(ioaddr, MII_ADVERTISE); |
|
863 auto_nego |= (ADVERTISE_10HALF | ADVERTISE_10FULL | |
|
864 ADVERTISE_100HALF | ADVERTISE_100FULL); |
|
865 auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
|
866 |
|
867 giga_ctrl = mdio_read(ioaddr, MII_CTRL1000); |
|
868 giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); |
|
869 |
|
870 /* The 8100e/8101e/8102e do Fast Ethernet only. */ |
|
871 if ((tp->mac_version != RTL_GIGA_MAC_VER_07) && |
|
872 (tp->mac_version != RTL_GIGA_MAC_VER_08) && |
|
873 (tp->mac_version != RTL_GIGA_MAC_VER_09) && |
|
874 (tp->mac_version != RTL_GIGA_MAC_VER_10) && |
|
875 (tp->mac_version != RTL_GIGA_MAC_VER_13) && |
|
876 (tp->mac_version != RTL_GIGA_MAC_VER_14) && |
|
877 (tp->mac_version != RTL_GIGA_MAC_VER_15) && |
|
878 (tp->mac_version != RTL_GIGA_MAC_VER_16)) { |
|
879 giga_ctrl |= ADVERTISE_1000FULL | ADVERTISE_1000HALF; |
|
880 } else if (netif_msg_link(tp)) { |
|
881 printk(KERN_INFO "%s: PHY does not support 1000Mbps.\n", |
|
882 dev->name); |
|
883 } |
|
884 |
|
885 bmcr = BMCR_ANENABLE | BMCR_ANRESTART; |
|
886 |
|
887 if ((tp->mac_version == RTL_GIGA_MAC_VER_11) || |
|
888 (tp->mac_version == RTL_GIGA_MAC_VER_12) || |
|
889 (tp->mac_version >= RTL_GIGA_MAC_VER_17)) { |
|
890 /* |
|
891 * Wake up the PHY. |
|
892 * Vendor specific (0x1f) and reserved (0x0e) MII |
|
893 * registers. |
|
894 */ |
|
895 mdio_write(ioaddr, 0x1f, 0x0000); |
|
896 mdio_write(ioaddr, 0x0e, 0x0000); |
|
897 } |
|
898 |
|
899 mdio_write(ioaddr, MII_ADVERTISE, auto_nego); |
|
900 mdio_write(ioaddr, MII_CTRL1000, giga_ctrl); |
|
901 } else { |
|
902 giga_ctrl = 0; |
|
903 |
|
904 if (speed == SPEED_10) |
|
905 bmcr = 0; |
|
906 else if (speed == SPEED_100) |
|
907 bmcr = BMCR_SPEED100; |
|
908 else |
|
909 return -EINVAL; |
|
910 |
|
911 if (duplex == DUPLEX_FULL) |
|
912 bmcr |= BMCR_FULLDPLX; |
|
913 |
|
914 mdio_write(ioaddr, 0x1f, 0x0000); |
|
915 } |
|
916 |
|
917 tp->phy_1000_ctrl_reg = giga_ctrl; |
|
918 |
|
919 mdio_write(ioaddr, MII_BMCR, bmcr); |
|
920 |
|
921 if ((tp->mac_version == RTL_GIGA_MAC_VER_02) || |
|
922 (tp->mac_version == RTL_GIGA_MAC_VER_03)) { |
|
923 if ((speed == SPEED_100) && (autoneg != AUTONEG_ENABLE)) { |
|
924 mdio_write(ioaddr, 0x17, 0x2138); |
|
925 mdio_write(ioaddr, 0x0e, 0x0260); |
|
926 } else { |
|
927 mdio_write(ioaddr, 0x17, 0x2108); |
|
928 mdio_write(ioaddr, 0x0e, 0x0000); |
|
929 } |
|
930 } |
|
931 |
|
932 return 0; |
|
933 } |
|
934 |
|
935 static int rtl8169_set_speed(struct net_device *dev, |
|
936 u8 autoneg, u16 speed, u8 duplex) |
|
937 { |
|
938 struct rtl8169_private *tp = netdev_priv(dev); |
|
939 int ret; |
|
940 |
|
941 ret = tp->set_speed(dev, autoneg, speed, duplex); |
|
942 |
|
943 if (netif_running(dev) && (tp->phy_1000_ctrl_reg & ADVERTISE_1000FULL)) |
|
944 mod_timer(&tp->timer, jiffies + RTL8169_PHY_TIMEOUT); |
|
945 |
|
946 return ret; |
|
947 } |
|
948 |
|
949 static int rtl8169_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
|
950 { |
|
951 struct rtl8169_private *tp = netdev_priv(dev); |
|
952 unsigned long flags; |
|
953 int ret; |
|
954 |
|
955 spin_lock_irqsave(&tp->lock, flags); |
|
956 ret = rtl8169_set_speed(dev, cmd->autoneg, cmd->speed, cmd->duplex); |
|
957 spin_unlock_irqrestore(&tp->lock, flags); |
|
958 |
|
959 return ret; |
|
960 } |
|
961 |
|
962 static u32 rtl8169_get_rx_csum(struct net_device *dev) |
|
963 { |
|
964 struct rtl8169_private *tp = netdev_priv(dev); |
|
965 |
|
966 return tp->cp_cmd & RxChkSum; |
|
967 } |
|
968 |
|
969 static int rtl8169_set_rx_csum(struct net_device *dev, u32 data) |
|
970 { |
|
971 struct rtl8169_private *tp = netdev_priv(dev); |
|
972 void __iomem *ioaddr = tp->mmio_addr; |
|
973 unsigned long flags; |
|
974 |
|
975 spin_lock_irqsave(&tp->lock, flags); |
|
976 |
|
977 if (data) |
|
978 tp->cp_cmd |= RxChkSum; |
|
979 else |
|
980 tp->cp_cmd &= ~RxChkSum; |
|
981 |
|
982 RTL_W16(CPlusCmd, tp->cp_cmd); |
|
983 RTL_R16(CPlusCmd); |
|
984 |
|
985 spin_unlock_irqrestore(&tp->lock, flags); |
|
986 |
|
987 return 0; |
|
988 } |
|
989 |
|
990 #ifdef CONFIG_R8169_VLAN |
|
991 |
|
992 static inline u32 rtl8169_tx_vlan_tag(struct rtl8169_private *tp, |
|
993 struct sk_buff *skb) |
|
994 { |
|
995 return (tp->vlgrp && vlan_tx_tag_present(skb)) ? |
|
996 TxVlanTag | swab16(vlan_tx_tag_get(skb)) : 0x00; |
|
997 } |
|
998 |
|
999 static void rtl8169_vlan_rx_register(struct net_device *dev, |
|
1000 struct vlan_group *grp) |
|
1001 { |
|
1002 struct rtl8169_private *tp = netdev_priv(dev); |
|
1003 void __iomem *ioaddr = tp->mmio_addr; |
|
1004 unsigned long flags; |
|
1005 |
|
1006 spin_lock_irqsave(&tp->lock, flags); |
|
1007 tp->vlgrp = grp; |
|
1008 if (tp->vlgrp) |
|
1009 tp->cp_cmd |= RxVlan; |
|
1010 else |
|
1011 tp->cp_cmd &= ~RxVlan; |
|
1012 RTL_W16(CPlusCmd, tp->cp_cmd); |
|
1013 RTL_R16(CPlusCmd); |
|
1014 spin_unlock_irqrestore(&tp->lock, flags); |
|
1015 } |
|
1016 |
|
1017 static int rtl8169_rx_vlan_skb(struct rtl8169_private *tp, struct RxDesc *desc, |
|
1018 struct sk_buff *skb) |
|
1019 { |
|
1020 u32 opts2 = le32_to_cpu(desc->opts2); |
|
1021 struct vlan_group *vlgrp = tp->vlgrp; |
|
1022 int ret; |
|
1023 |
|
1024 if (vlgrp && (opts2 & RxVlanTag)) { |
|
1025 vlan_hwaccel_receive_skb(skb, vlgrp, swab16(opts2 & 0xffff)); |
|
1026 ret = 0; |
|
1027 } else |
|
1028 ret = -1; |
|
1029 desc->opts2 = 0; |
|
1030 return ret; |
|
1031 } |
|
1032 |
|
1033 #else /* !CONFIG_R8169_VLAN */ |
|
1034 |
|
1035 static inline u32 rtl8169_tx_vlan_tag(struct rtl8169_private *tp, |
|
1036 struct sk_buff *skb) |
|
1037 { |
|
1038 return 0; |
|
1039 } |
|
1040 |
|
1041 static int rtl8169_rx_vlan_skb(struct rtl8169_private *tp, struct RxDesc *desc, |
|
1042 struct sk_buff *skb) |
|
1043 { |
|
1044 return -1; |
|
1045 } |
|
1046 |
|
1047 #endif |
|
1048 |
|
1049 static int rtl8169_gset_tbi(struct net_device *dev, struct ethtool_cmd *cmd) |
|
1050 { |
|
1051 struct rtl8169_private *tp = netdev_priv(dev); |
|
1052 void __iomem *ioaddr = tp->mmio_addr; |
|
1053 u32 status; |
|
1054 |
|
1055 cmd->supported = |
|
1056 SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE; |
|
1057 cmd->port = PORT_FIBRE; |
|
1058 cmd->transceiver = XCVR_INTERNAL; |
|
1059 |
|
1060 status = RTL_R32(TBICSR); |
|
1061 cmd->advertising = (status & TBINwEnable) ? ADVERTISED_Autoneg : 0; |
|
1062 cmd->autoneg = !!(status & TBINwEnable); |
|
1063 |
|
1064 cmd->speed = SPEED_1000; |
|
1065 cmd->duplex = DUPLEX_FULL; /* Always set */ |
|
1066 |
|
1067 return 0; |
|
1068 } |
|
1069 |
|
1070 static int rtl8169_gset_xmii(struct net_device *dev, struct ethtool_cmd *cmd) |
|
1071 { |
|
1072 struct rtl8169_private *tp = netdev_priv(dev); |
|
1073 |
|
1074 return mii_ethtool_gset(&tp->mii, cmd); |
|
1075 } |
|
1076 |
|
1077 static int rtl8169_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
|
1078 { |
|
1079 struct rtl8169_private *tp = netdev_priv(dev); |
|
1080 unsigned long flags; |
|
1081 int rc; |
|
1082 |
|
1083 spin_lock_irqsave(&tp->lock, flags); |
|
1084 |
|
1085 rc = tp->get_settings(dev, cmd); |
|
1086 |
|
1087 spin_unlock_irqrestore(&tp->lock, flags); |
|
1088 return rc; |
|
1089 } |
|
1090 |
|
1091 static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
|
1092 void *p) |
|
1093 { |
|
1094 struct rtl8169_private *tp = netdev_priv(dev); |
|
1095 unsigned long flags; |
|
1096 |
|
1097 if (regs->len > R8169_REGS_SIZE) |
|
1098 regs->len = R8169_REGS_SIZE; |
|
1099 |
|
1100 spin_lock_irqsave(&tp->lock, flags); |
|
1101 memcpy_fromio(p, tp->mmio_addr, regs->len); |
|
1102 spin_unlock_irqrestore(&tp->lock, flags); |
|
1103 } |
|
1104 |
|
1105 static u32 rtl8169_get_msglevel(struct net_device *dev) |
|
1106 { |
|
1107 struct rtl8169_private *tp = netdev_priv(dev); |
|
1108 |
|
1109 return tp->msg_enable; |
|
1110 } |
|
1111 |
|
1112 static void rtl8169_set_msglevel(struct net_device *dev, u32 value) |
|
1113 { |
|
1114 struct rtl8169_private *tp = netdev_priv(dev); |
|
1115 |
|
1116 tp->msg_enable = value; |
|
1117 } |
|
1118 |
|
1119 static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = { |
|
1120 "tx_packets", |
|
1121 "rx_packets", |
|
1122 "tx_errors", |
|
1123 "rx_errors", |
|
1124 "rx_missed", |
|
1125 "align_errors", |
|
1126 "tx_single_collisions", |
|
1127 "tx_multi_collisions", |
|
1128 "unicast", |
|
1129 "broadcast", |
|
1130 "multicast", |
|
1131 "tx_aborted", |
|
1132 "tx_underrun", |
|
1133 }; |
|
1134 |
|
1135 static int rtl8169_get_sset_count(struct net_device *dev, int sset) |
|
1136 { |
|
1137 switch (sset) { |
|
1138 case ETH_SS_STATS: |
|
1139 return ARRAY_SIZE(rtl8169_gstrings); |
|
1140 default: |
|
1141 return -EOPNOTSUPP; |
|
1142 } |
|
1143 } |
|
1144 |
|
1145 static void rtl8169_update_counters(struct net_device *dev) |
|
1146 { |
|
1147 struct rtl8169_private *tp = netdev_priv(dev); |
|
1148 void __iomem *ioaddr = tp->mmio_addr; |
|
1149 struct rtl8169_counters *counters; |
|
1150 dma_addr_t paddr; |
|
1151 u32 cmd; |
|
1152 int wait = 1000; |
|
1153 |
|
1154 /* |
|
1155 * Some chips are unable to dump tally counters when the receiver |
|
1156 * is disabled. |
|
1157 */ |
|
1158 if ((RTL_R8(ChipCmd) & CmdRxEnb) == 0) |
|
1159 return; |
|
1160 |
|
1161 counters = pci_alloc_consistent(tp->pci_dev, sizeof(*counters), &paddr); |
|
1162 if (!counters) |
|
1163 return; |
|
1164 |
|
1165 RTL_W32(CounterAddrHigh, (u64)paddr >> 32); |
|
1166 cmd = (u64)paddr & DMA_BIT_MASK(32); |
|
1167 RTL_W32(CounterAddrLow, cmd); |
|
1168 RTL_W32(CounterAddrLow, cmd | CounterDump); |
|
1169 |
|
1170 while (wait--) { |
|
1171 if ((RTL_R32(CounterAddrLow) & CounterDump) == 0) { |
|
1172 /* copy updated counters */ |
|
1173 memcpy(&tp->counters, counters, sizeof(*counters)); |
|
1174 break; |
|
1175 } |
|
1176 udelay(10); |
|
1177 } |
|
1178 |
|
1179 RTL_W32(CounterAddrLow, 0); |
|
1180 RTL_W32(CounterAddrHigh, 0); |
|
1181 |
|
1182 pci_free_consistent(tp->pci_dev, sizeof(*counters), counters, paddr); |
|
1183 } |
|
1184 |
|
1185 static void rtl8169_get_ethtool_stats(struct net_device *dev, |
|
1186 struct ethtool_stats *stats, u64 *data) |
|
1187 { |
|
1188 struct rtl8169_private *tp = netdev_priv(dev); |
|
1189 |
|
1190 ASSERT_RTNL(); |
|
1191 |
|
1192 rtl8169_update_counters(dev); |
|
1193 |
|
1194 data[0] = le64_to_cpu(tp->counters.tx_packets); |
|
1195 data[1] = le64_to_cpu(tp->counters.rx_packets); |
|
1196 data[2] = le64_to_cpu(tp->counters.tx_errors); |
|
1197 data[3] = le32_to_cpu(tp->counters.rx_errors); |
|
1198 data[4] = le16_to_cpu(tp->counters.rx_missed); |
|
1199 data[5] = le16_to_cpu(tp->counters.align_errors); |
|
1200 data[6] = le32_to_cpu(tp->counters.tx_one_collision); |
|
1201 data[7] = le32_to_cpu(tp->counters.tx_multi_collision); |
|
1202 data[8] = le64_to_cpu(tp->counters.rx_unicast); |
|
1203 data[9] = le64_to_cpu(tp->counters.rx_broadcast); |
|
1204 data[10] = le32_to_cpu(tp->counters.rx_multicast); |
|
1205 data[11] = le16_to_cpu(tp->counters.tx_aborted); |
|
1206 data[12] = le16_to_cpu(tp->counters.tx_underun); |
|
1207 } |
|
1208 |
|
1209 static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
|
1210 { |
|
1211 switch(stringset) { |
|
1212 case ETH_SS_STATS: |
|
1213 memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings)); |
|
1214 break; |
|
1215 } |
|
1216 } |
|
1217 |
|
1218 static const struct ethtool_ops rtl8169_ethtool_ops = { |
|
1219 .get_drvinfo = rtl8169_get_drvinfo, |
|
1220 .get_regs_len = rtl8169_get_regs_len, |
|
1221 .get_link = ethtool_op_get_link, |
|
1222 .get_settings = rtl8169_get_settings, |
|
1223 .set_settings = rtl8169_set_settings, |
|
1224 .get_msglevel = rtl8169_get_msglevel, |
|
1225 .set_msglevel = rtl8169_set_msglevel, |
|
1226 .get_rx_csum = rtl8169_get_rx_csum, |
|
1227 .set_rx_csum = rtl8169_set_rx_csum, |
|
1228 .set_tx_csum = ethtool_op_set_tx_csum, |
|
1229 .set_sg = ethtool_op_set_sg, |
|
1230 .set_tso = ethtool_op_set_tso, |
|
1231 .get_regs = rtl8169_get_regs, |
|
1232 .get_wol = rtl8169_get_wol, |
|
1233 .set_wol = rtl8169_set_wol, |
|
1234 .get_strings = rtl8169_get_strings, |
|
1235 .get_sset_count = rtl8169_get_sset_count, |
|
1236 .get_ethtool_stats = rtl8169_get_ethtool_stats, |
|
1237 }; |
|
1238 |
|
1239 static void rtl8169_write_gmii_reg_bit(void __iomem *ioaddr, int reg, |
|
1240 int bitnum, int bitval) |
|
1241 { |
|
1242 int val; |
|
1243 |
|
1244 val = mdio_read(ioaddr, reg); |
|
1245 val = (bitval == 1) ? |
|
1246 val | (bitval << bitnum) : val & ~(0x0001 << bitnum); |
|
1247 mdio_write(ioaddr, reg, val & 0xffff); |
|
1248 } |
|
1249 |
|
1250 static void rtl8169_get_mac_version(struct rtl8169_private *tp, |
|
1251 void __iomem *ioaddr) |
|
1252 { |
|
1253 /* |
|
1254 * The driver currently handles the 8168Bf and the 8168Be identically |
|
1255 * but they can be identified more specifically through the test below |
|
1256 * if needed: |
|
1257 * |
|
1258 * (RTL_R32(TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be |
|
1259 * |
|
1260 * Same thing for the 8101Eb and the 8101Ec: |
|
1261 * |
|
1262 * (RTL_R32(TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec |
|
1263 */ |
|
1264 const struct { |
|
1265 u32 mask; |
|
1266 u32 val; |
|
1267 int mac_version; |
|
1268 } mac_info[] = { |
|
1269 /* 8168D family. */ |
|
1270 { 0x7c800000, 0x28000000, RTL_GIGA_MAC_VER_25 }, |
|
1271 |
|
1272 /* 8168C family. */ |
|
1273 { 0x7cf00000, 0x3ca00000, RTL_GIGA_MAC_VER_24 }, |
|
1274 { 0x7cf00000, 0x3c900000, RTL_GIGA_MAC_VER_23 }, |
|
1275 { 0x7cf00000, 0x3c800000, RTL_GIGA_MAC_VER_18 }, |
|
1276 { 0x7c800000, 0x3c800000, RTL_GIGA_MAC_VER_24 }, |
|
1277 { 0x7cf00000, 0x3c000000, RTL_GIGA_MAC_VER_19 }, |
|
1278 { 0x7cf00000, 0x3c200000, RTL_GIGA_MAC_VER_20 }, |
|
1279 { 0x7cf00000, 0x3c300000, RTL_GIGA_MAC_VER_21 }, |
|
1280 { 0x7cf00000, 0x3c400000, RTL_GIGA_MAC_VER_22 }, |
|
1281 { 0x7c800000, 0x3c000000, RTL_GIGA_MAC_VER_22 }, |
|
1282 |
|
1283 /* 8168B family. */ |
|
1284 { 0x7cf00000, 0x38000000, RTL_GIGA_MAC_VER_12 }, |
|
1285 { 0x7cf00000, 0x38500000, RTL_GIGA_MAC_VER_17 }, |
|
1286 { 0x7c800000, 0x38000000, RTL_GIGA_MAC_VER_17 }, |
|
1287 { 0x7c800000, 0x30000000, RTL_GIGA_MAC_VER_11 }, |
|
1288 |
|
1289 /* 8101 family. */ |
|
1290 { 0x7cf00000, 0x34a00000, RTL_GIGA_MAC_VER_09 }, |
|
1291 { 0x7cf00000, 0x24a00000, RTL_GIGA_MAC_VER_09 }, |
|
1292 { 0x7cf00000, 0x34900000, RTL_GIGA_MAC_VER_08 }, |
|
1293 { 0x7cf00000, 0x24900000, RTL_GIGA_MAC_VER_08 }, |
|
1294 { 0x7cf00000, 0x34800000, RTL_GIGA_MAC_VER_07 }, |
|
1295 { 0x7cf00000, 0x24800000, RTL_GIGA_MAC_VER_07 }, |
|
1296 { 0x7cf00000, 0x34000000, RTL_GIGA_MAC_VER_13 }, |
|
1297 { 0x7cf00000, 0x34300000, RTL_GIGA_MAC_VER_10 }, |
|
1298 { 0x7cf00000, 0x34200000, RTL_GIGA_MAC_VER_16 }, |
|
1299 { 0x7c800000, 0x34800000, RTL_GIGA_MAC_VER_09 }, |
|
1300 { 0x7c800000, 0x24800000, RTL_GIGA_MAC_VER_09 }, |
|
1301 { 0x7c800000, 0x34000000, RTL_GIGA_MAC_VER_16 }, |
|
1302 /* FIXME: where did these entries come from ? -- FR */ |
|
1303 { 0xfc800000, 0x38800000, RTL_GIGA_MAC_VER_15 }, |
|
1304 { 0xfc800000, 0x30800000, RTL_GIGA_MAC_VER_14 }, |
|
1305 |
|
1306 /* 8110 family. */ |
|
1307 { 0xfc800000, 0x98000000, RTL_GIGA_MAC_VER_06 }, |
|
1308 { 0xfc800000, 0x18000000, RTL_GIGA_MAC_VER_05 }, |
|
1309 { 0xfc800000, 0x10000000, RTL_GIGA_MAC_VER_04 }, |
|
1310 { 0xfc800000, 0x04000000, RTL_GIGA_MAC_VER_03 }, |
|
1311 { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 }, |
|
1312 { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 }, |
|
1313 |
|
1314 /* Catch-all */ |
|
1315 { 0x00000000, 0x00000000, RTL_GIGA_MAC_NONE } |
|
1316 }, *p = mac_info; |
|
1317 u32 reg; |
|
1318 |
|
1319 reg = RTL_R32(TxConfig); |
|
1320 while ((reg & p->mask) != p->val) |
|
1321 p++; |
|
1322 tp->mac_version = p->mac_version; |
|
1323 } |
|
1324 |
|
1325 static void rtl8169_print_mac_version(struct rtl8169_private *tp) |
|
1326 { |
|
1327 dprintk("mac_version = 0x%02x\n", tp->mac_version); |
|
1328 } |
|
1329 |
|
1330 struct phy_reg { |
|
1331 u16 reg; |
|
1332 u16 val; |
|
1333 }; |
|
1334 |
|
1335 static void rtl_phy_write(void __iomem *ioaddr, struct phy_reg *regs, int len) |
|
1336 { |
|
1337 while (len-- > 0) { |
|
1338 mdio_write(ioaddr, regs->reg, regs->val); |
|
1339 regs++; |
|
1340 } |
|
1341 } |
|
1342 |
|
1343 static void rtl8169s_hw_phy_config(void __iomem *ioaddr) |
|
1344 { |
|
1345 struct { |
|
1346 u16 regs[5]; /* Beware of bit-sign propagation */ |
|
1347 } phy_magic[5] = { { |
|
1348 { 0x0000, //w 4 15 12 0 |
|
1349 0x00a1, //w 3 15 0 00a1 |
|
1350 0x0008, //w 2 15 0 0008 |
|
1351 0x1020, //w 1 15 0 1020 |
|
1352 0x1000 } },{ //w 0 15 0 1000 |
|
1353 { 0x7000, //w 4 15 12 7 |
|
1354 0xff41, //w 3 15 0 ff41 |
|
1355 0xde60, //w 2 15 0 de60 |
|
1356 0x0140, //w 1 15 0 0140 |
|
1357 0x0077 } },{ //w 0 15 0 0077 |
|
1358 { 0xa000, //w 4 15 12 a |
|
1359 0xdf01, //w 3 15 0 df01 |
|
1360 0xdf20, //w 2 15 0 df20 |
|
1361 0xff95, //w 1 15 0 ff95 |
|
1362 0xfa00 } },{ //w 0 15 0 fa00 |
|
1363 { 0xb000, //w 4 15 12 b |
|
1364 0xff41, //w 3 15 0 ff41 |
|
1365 0xde20, //w 2 15 0 de20 |
|
1366 0x0140, //w 1 15 0 0140 |
|
1367 0x00bb } },{ //w 0 15 0 00bb |
|
1368 { 0xf000, //w 4 15 12 f |
|
1369 0xdf01, //w 3 15 0 df01 |
|
1370 0xdf20, //w 2 15 0 df20 |
|
1371 0xff95, //w 1 15 0 ff95 |
|
1372 0xbf00 } //w 0 15 0 bf00 |
|
1373 } |
|
1374 }, *p = phy_magic; |
|
1375 unsigned int i; |
|
1376 |
|
1377 mdio_write(ioaddr, 0x1f, 0x0001); //w 31 2 0 1 |
|
1378 mdio_write(ioaddr, 0x15, 0x1000); //w 21 15 0 1000 |
|
1379 mdio_write(ioaddr, 0x18, 0x65c7); //w 24 15 0 65c7 |
|
1380 rtl8169_write_gmii_reg_bit(ioaddr, 4, 11, 0); //w 4 11 11 0 |
|
1381 |
|
1382 for (i = 0; i < ARRAY_SIZE(phy_magic); i++, p++) { |
|
1383 int val, pos = 4; |
|
1384 |
|
1385 val = (mdio_read(ioaddr, pos) & 0x0fff) | (p->regs[0] & 0xffff); |
|
1386 mdio_write(ioaddr, pos, val); |
|
1387 while (--pos >= 0) |
|
1388 mdio_write(ioaddr, pos, p->regs[4 - pos] & 0xffff); |
|
1389 rtl8169_write_gmii_reg_bit(ioaddr, 4, 11, 1); //w 4 11 11 1 |
|
1390 rtl8169_write_gmii_reg_bit(ioaddr, 4, 11, 0); //w 4 11 11 0 |
|
1391 } |
|
1392 mdio_write(ioaddr, 0x1f, 0x0000); //w 31 2 0 0 |
|
1393 } |
|
1394 |
|
1395 static void rtl8169sb_hw_phy_config(void __iomem *ioaddr) |
|
1396 { |
|
1397 struct phy_reg phy_reg_init[] = { |
|
1398 { 0x1f, 0x0002 }, |
|
1399 { 0x01, 0x90d0 }, |
|
1400 { 0x1f, 0x0000 } |
|
1401 }; |
|
1402 |
|
1403 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
1404 } |
|
1405 |
|
1406 static void rtl8168bb_hw_phy_config(void __iomem *ioaddr) |
|
1407 { |
|
1408 struct phy_reg phy_reg_init[] = { |
|
1409 { 0x10, 0xf41b }, |
|
1410 { 0x1f, 0x0000 } |
|
1411 }; |
|
1412 |
|
1413 mdio_write(ioaddr, 0x1f, 0x0001); |
|
1414 mdio_patch(ioaddr, 0x16, 1 << 0); |
|
1415 |
|
1416 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
1417 } |
|
1418 |
|
1419 static void rtl8168bef_hw_phy_config(void __iomem *ioaddr) |
|
1420 { |
|
1421 struct phy_reg phy_reg_init[] = { |
|
1422 { 0x1f, 0x0001 }, |
|
1423 { 0x10, 0xf41b }, |
|
1424 { 0x1f, 0x0000 } |
|
1425 }; |
|
1426 |
|
1427 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
1428 } |
|
1429 |
|
1430 static void rtl8168cp_1_hw_phy_config(void __iomem *ioaddr) |
|
1431 { |
|
1432 struct phy_reg phy_reg_init[] = { |
|
1433 { 0x1f, 0x0000 }, |
|
1434 { 0x1d, 0x0f00 }, |
|
1435 { 0x1f, 0x0002 }, |
|
1436 { 0x0c, 0x1ec8 }, |
|
1437 { 0x1f, 0x0000 } |
|
1438 }; |
|
1439 |
|
1440 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
1441 } |
|
1442 |
|
1443 static void rtl8168cp_2_hw_phy_config(void __iomem *ioaddr) |
|
1444 { |
|
1445 struct phy_reg phy_reg_init[] = { |
|
1446 { 0x1f, 0x0001 }, |
|
1447 { 0x1d, 0x3d98 }, |
|
1448 { 0x1f, 0x0000 } |
|
1449 }; |
|
1450 |
|
1451 mdio_write(ioaddr, 0x1f, 0x0000); |
|
1452 mdio_patch(ioaddr, 0x14, 1 << 5); |
|
1453 mdio_patch(ioaddr, 0x0d, 1 << 5); |
|
1454 |
|
1455 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
1456 } |
|
1457 |
|
1458 static void rtl8168c_1_hw_phy_config(void __iomem *ioaddr) |
|
1459 { |
|
1460 struct phy_reg phy_reg_init[] = { |
|
1461 { 0x1f, 0x0001 }, |
|
1462 { 0x12, 0x2300 }, |
|
1463 { 0x1f, 0x0002 }, |
|
1464 { 0x00, 0x88d4 }, |
|
1465 { 0x01, 0x82b1 }, |
|
1466 { 0x03, 0x7002 }, |
|
1467 { 0x08, 0x9e30 }, |
|
1468 { 0x09, 0x01f0 }, |
|
1469 { 0x0a, 0x5500 }, |
|
1470 { 0x0c, 0x00c8 }, |
|
1471 { 0x1f, 0x0003 }, |
|
1472 { 0x12, 0xc096 }, |
|
1473 { 0x16, 0x000a }, |
|
1474 { 0x1f, 0x0000 }, |
|
1475 { 0x1f, 0x0000 }, |
|
1476 { 0x09, 0x2000 }, |
|
1477 { 0x09, 0x0000 } |
|
1478 }; |
|
1479 |
|
1480 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
1481 |
|
1482 mdio_patch(ioaddr, 0x14, 1 << 5); |
|
1483 mdio_patch(ioaddr, 0x0d, 1 << 5); |
|
1484 mdio_write(ioaddr, 0x1f, 0x0000); |
|
1485 } |
|
1486 |
|
1487 static void rtl8168c_2_hw_phy_config(void __iomem *ioaddr) |
|
1488 { |
|
1489 struct phy_reg phy_reg_init[] = { |
|
1490 { 0x1f, 0x0001 }, |
|
1491 { 0x12, 0x2300 }, |
|
1492 { 0x03, 0x802f }, |
|
1493 { 0x02, 0x4f02 }, |
|
1494 { 0x01, 0x0409 }, |
|
1495 { 0x00, 0xf099 }, |
|
1496 { 0x04, 0x9800 }, |
|
1497 { 0x04, 0x9000 }, |
|
1498 { 0x1d, 0x3d98 }, |
|
1499 { 0x1f, 0x0002 }, |
|
1500 { 0x0c, 0x7eb8 }, |
|
1501 { 0x06, 0x0761 }, |
|
1502 { 0x1f, 0x0003 }, |
|
1503 { 0x16, 0x0f0a }, |
|
1504 { 0x1f, 0x0000 } |
|
1505 }; |
|
1506 |
|
1507 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
1508 |
|
1509 mdio_patch(ioaddr, 0x16, 1 << 0); |
|
1510 mdio_patch(ioaddr, 0x14, 1 << 5); |
|
1511 mdio_patch(ioaddr, 0x0d, 1 << 5); |
|
1512 mdio_write(ioaddr, 0x1f, 0x0000); |
|
1513 } |
|
1514 |
|
1515 static void rtl8168c_3_hw_phy_config(void __iomem *ioaddr) |
|
1516 { |
|
1517 struct phy_reg phy_reg_init[] = { |
|
1518 { 0x1f, 0x0001 }, |
|
1519 { 0x12, 0x2300 }, |
|
1520 { 0x1d, 0x3d98 }, |
|
1521 { 0x1f, 0x0002 }, |
|
1522 { 0x0c, 0x7eb8 }, |
|
1523 { 0x06, 0x5461 }, |
|
1524 { 0x1f, 0x0003 }, |
|
1525 { 0x16, 0x0f0a }, |
|
1526 { 0x1f, 0x0000 } |
|
1527 }; |
|
1528 |
|
1529 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
1530 |
|
1531 mdio_patch(ioaddr, 0x16, 1 << 0); |
|
1532 mdio_patch(ioaddr, 0x14, 1 << 5); |
|
1533 mdio_patch(ioaddr, 0x0d, 1 << 5); |
|
1534 mdio_write(ioaddr, 0x1f, 0x0000); |
|
1535 } |
|
1536 |
|
1537 static void rtl8168c_4_hw_phy_config(void __iomem *ioaddr) |
|
1538 { |
|
1539 rtl8168c_3_hw_phy_config(ioaddr); |
|
1540 } |
|
1541 |
|
1542 static void rtl8168d_hw_phy_config(void __iomem *ioaddr) |
|
1543 { |
|
1544 struct phy_reg phy_reg_init_0[] = { |
|
1545 { 0x1f, 0x0001 }, |
|
1546 { 0x09, 0x2770 }, |
|
1547 { 0x08, 0x04d0 }, |
|
1548 { 0x0b, 0xad15 }, |
|
1549 { 0x0c, 0x5bf0 }, |
|
1550 { 0x1c, 0xf101 }, |
|
1551 { 0x1f, 0x0003 }, |
|
1552 { 0x14, 0x94d7 }, |
|
1553 { 0x12, 0xf4d6 }, |
|
1554 { 0x09, 0xca0f }, |
|
1555 { 0x1f, 0x0002 }, |
|
1556 { 0x0b, 0x0b10 }, |
|
1557 { 0x0c, 0xd1f7 }, |
|
1558 { 0x1f, 0x0002 }, |
|
1559 { 0x06, 0x5461 }, |
|
1560 { 0x1f, 0x0002 }, |
|
1561 { 0x05, 0x6662 }, |
|
1562 { 0x1f, 0x0000 }, |
|
1563 { 0x14, 0x0060 }, |
|
1564 { 0x1f, 0x0000 }, |
|
1565 { 0x0d, 0xf8a0 }, |
|
1566 { 0x1f, 0x0005 }, |
|
1567 { 0x05, 0xffc2 } |
|
1568 }; |
|
1569 |
|
1570 rtl_phy_write(ioaddr, phy_reg_init_0, ARRAY_SIZE(phy_reg_init_0)); |
|
1571 |
|
1572 if (mdio_read(ioaddr, 0x06) == 0xc400) { |
|
1573 struct phy_reg phy_reg_init_1[] = { |
|
1574 { 0x1f, 0x0005 }, |
|
1575 { 0x01, 0x0300 }, |
|
1576 { 0x1f, 0x0000 }, |
|
1577 { 0x11, 0x401c }, |
|
1578 { 0x16, 0x4100 }, |
|
1579 { 0x1f, 0x0005 }, |
|
1580 { 0x07, 0x0010 }, |
|
1581 { 0x05, 0x83dc }, |
|
1582 { 0x06, 0x087d }, |
|
1583 { 0x05, 0x8300 }, |
|
1584 { 0x06, 0x0101 }, |
|
1585 { 0x06, 0x05f8 }, |
|
1586 { 0x06, 0xf9fa }, |
|
1587 { 0x06, 0xfbef }, |
|
1588 { 0x06, 0x79e2 }, |
|
1589 { 0x06, 0x835f }, |
|
1590 { 0x06, 0xe0f8 }, |
|
1591 { 0x06, 0x9ae1 }, |
|
1592 { 0x06, 0xf89b }, |
|
1593 { 0x06, 0xef31 }, |
|
1594 { 0x06, 0x3b65 }, |
|
1595 { 0x06, 0xaa07 }, |
|
1596 { 0x06, 0x81e4 }, |
|
1597 { 0x06, 0xf89a }, |
|
1598 { 0x06, 0xe5f8 }, |
|
1599 { 0x06, 0x9baf }, |
|
1600 { 0x06, 0x06ae }, |
|
1601 { 0x05, 0x83dc }, |
|
1602 { 0x06, 0x8300 }, |
|
1603 }; |
|
1604 |
|
1605 rtl_phy_write(ioaddr, phy_reg_init_1, |
|
1606 ARRAY_SIZE(phy_reg_init_1)); |
|
1607 } |
|
1608 |
|
1609 mdio_write(ioaddr, 0x1f, 0x0000); |
|
1610 } |
|
1611 |
|
1612 static void rtl8102e_hw_phy_config(void __iomem *ioaddr) |
|
1613 { |
|
1614 struct phy_reg phy_reg_init[] = { |
|
1615 { 0x1f, 0x0003 }, |
|
1616 { 0x08, 0x441d }, |
|
1617 { 0x01, 0x9100 }, |
|
1618 { 0x1f, 0x0000 } |
|
1619 }; |
|
1620 |
|
1621 mdio_write(ioaddr, 0x1f, 0x0000); |
|
1622 mdio_patch(ioaddr, 0x11, 1 << 12); |
|
1623 mdio_patch(ioaddr, 0x19, 1 << 13); |
|
1624 |
|
1625 rtl_phy_write(ioaddr, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
1626 } |
|
1627 |
|
1628 static void rtl_hw_phy_config(struct net_device *dev) |
|
1629 { |
|
1630 struct rtl8169_private *tp = netdev_priv(dev); |
|
1631 void __iomem *ioaddr = tp->mmio_addr; |
|
1632 |
|
1633 rtl8169_print_mac_version(tp); |
|
1634 |
|
1635 switch (tp->mac_version) { |
|
1636 case RTL_GIGA_MAC_VER_01: |
|
1637 break; |
|
1638 case RTL_GIGA_MAC_VER_02: |
|
1639 case RTL_GIGA_MAC_VER_03: |
|
1640 rtl8169s_hw_phy_config(ioaddr); |
|
1641 break; |
|
1642 case RTL_GIGA_MAC_VER_04: |
|
1643 rtl8169sb_hw_phy_config(ioaddr); |
|
1644 break; |
|
1645 case RTL_GIGA_MAC_VER_07: |
|
1646 case RTL_GIGA_MAC_VER_08: |
|
1647 case RTL_GIGA_MAC_VER_09: |
|
1648 rtl8102e_hw_phy_config(ioaddr); |
|
1649 break; |
|
1650 case RTL_GIGA_MAC_VER_11: |
|
1651 rtl8168bb_hw_phy_config(ioaddr); |
|
1652 break; |
|
1653 case RTL_GIGA_MAC_VER_12: |
|
1654 rtl8168bef_hw_phy_config(ioaddr); |
|
1655 break; |
|
1656 case RTL_GIGA_MAC_VER_17: |
|
1657 rtl8168bef_hw_phy_config(ioaddr); |
|
1658 break; |
|
1659 case RTL_GIGA_MAC_VER_18: |
|
1660 rtl8168cp_1_hw_phy_config(ioaddr); |
|
1661 break; |
|
1662 case RTL_GIGA_MAC_VER_19: |
|
1663 rtl8168c_1_hw_phy_config(ioaddr); |
|
1664 break; |
|
1665 case RTL_GIGA_MAC_VER_20: |
|
1666 rtl8168c_2_hw_phy_config(ioaddr); |
|
1667 break; |
|
1668 case RTL_GIGA_MAC_VER_21: |
|
1669 rtl8168c_3_hw_phy_config(ioaddr); |
|
1670 break; |
|
1671 case RTL_GIGA_MAC_VER_22: |
|
1672 rtl8168c_4_hw_phy_config(ioaddr); |
|
1673 break; |
|
1674 case RTL_GIGA_MAC_VER_23: |
|
1675 case RTL_GIGA_MAC_VER_24: |
|
1676 rtl8168cp_2_hw_phy_config(ioaddr); |
|
1677 break; |
|
1678 case RTL_GIGA_MAC_VER_25: |
|
1679 rtl8168d_hw_phy_config(ioaddr); |
|
1680 break; |
|
1681 |
|
1682 default: |
|
1683 break; |
|
1684 } |
|
1685 } |
|
1686 |
|
1687 static void rtl8169_phy_timer(unsigned long __opaque) |
|
1688 { |
|
1689 struct net_device *dev = (struct net_device *)__opaque; |
|
1690 struct rtl8169_private *tp = netdev_priv(dev); |
|
1691 struct timer_list *timer = &tp->timer; |
|
1692 void __iomem *ioaddr = tp->mmio_addr; |
|
1693 unsigned long timeout = RTL8169_PHY_TIMEOUT; |
|
1694 |
|
1695 assert(tp->mac_version > RTL_GIGA_MAC_VER_01); |
|
1696 |
|
1697 if (!(tp->phy_1000_ctrl_reg & ADVERTISE_1000FULL)) |
|
1698 return; |
|
1699 |
|
1700 if (!tp->ecdev) |
|
1701 spin_lock_irq(&tp->lock); |
|
1702 |
|
1703 if (tp->phy_reset_pending(ioaddr)) { |
|
1704 /* |
|
1705 * A busy loop could burn quite a few cycles on nowadays CPU. |
|
1706 * Let's delay the execution of the timer for a few ticks. |
|
1707 */ |
|
1708 timeout = HZ/10; |
|
1709 goto out_mod_timer; |
|
1710 } |
|
1711 |
|
1712 if (tp->link_ok(ioaddr)) |
|
1713 goto out_unlock; |
|
1714 |
|
1715 if (netif_msg_link(tp)) |
|
1716 printk(KERN_WARNING "%s: PHY reset until link up\n", dev->name); |
|
1717 |
|
1718 tp->phy_reset_enable(ioaddr); |
|
1719 |
|
1720 out_mod_timer: |
|
1721 if (!tp->ecdev) |
|
1722 mod_timer(timer, jiffies + timeout); |
|
1723 out_unlock: |
|
1724 if (!tp->ecdev) |
|
1725 spin_unlock_irq(&tp->lock); |
|
1726 } |
|
1727 |
|
1728 static inline void rtl8169_delete_timer(struct net_device *dev) |
|
1729 { |
|
1730 struct rtl8169_private *tp = netdev_priv(dev); |
|
1731 struct timer_list *timer = &tp->timer; |
|
1732 |
|
1733 if (tp->ecdev || tp->mac_version <= RTL_GIGA_MAC_VER_01) |
|
1734 return; |
|
1735 |
|
1736 del_timer_sync(timer); |
|
1737 } |
|
1738 |
|
1739 static inline void rtl8169_request_timer(struct net_device *dev) |
|
1740 { |
|
1741 struct rtl8169_private *tp = netdev_priv(dev); |
|
1742 struct timer_list *timer = &tp->timer; |
|
1743 |
|
1744 if (tp->ecdev || tp->mac_version <= RTL_GIGA_MAC_VER_01) |
|
1745 return; |
|
1746 |
|
1747 mod_timer(timer, jiffies + RTL8169_PHY_TIMEOUT); |
|
1748 } |
|
1749 |
|
1750 #ifdef CONFIG_NET_POLL_CONTROLLER |
|
1751 /* |
|
1752 * Polling 'interrupt' - used by things like netconsole to send skbs |
|
1753 * without having to re-enable interrupts. It's not called while |
|
1754 * the interrupt routine is executing. |
|
1755 */ |
|
1756 static void rtl8169_netpoll(struct net_device *dev) |
|
1757 { |
|
1758 struct rtl8169_private *tp = netdev_priv(dev); |
|
1759 struct pci_dev *pdev = tp->pci_dev; |
|
1760 |
|
1761 disable_irq(pdev->irq); |
|
1762 rtl8169_interrupt(pdev->irq, dev); |
|
1763 enable_irq(pdev->irq); |
|
1764 } |
|
1765 #endif |
|
1766 |
|
1767 static void rtl8169_release_board(struct pci_dev *pdev, struct net_device *dev, |
|
1768 void __iomem *ioaddr) |
|
1769 { |
|
1770 iounmap(ioaddr); |
|
1771 pci_release_regions(pdev); |
|
1772 pci_disable_device(pdev); |
|
1773 free_netdev(dev); |
|
1774 } |
|
1775 |
|
1776 static void rtl8169_phy_reset(struct net_device *dev, |
|
1777 struct rtl8169_private *tp) |
|
1778 { |
|
1779 void __iomem *ioaddr = tp->mmio_addr; |
|
1780 unsigned int i; |
|
1781 |
|
1782 tp->phy_reset_enable(ioaddr); |
|
1783 for (i = 0; i < 100; i++) { |
|
1784 if (!tp->phy_reset_pending(ioaddr)) |
|
1785 return; |
|
1786 msleep(1); |
|
1787 } |
|
1788 if (netif_msg_link(tp)) |
|
1789 printk(KERN_ERR "%s: PHY reset failed.\n", dev->name); |
|
1790 } |
|
1791 |
|
1792 static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp) |
|
1793 { |
|
1794 void __iomem *ioaddr = tp->mmio_addr; |
|
1795 |
|
1796 rtl_hw_phy_config(dev); |
|
1797 |
|
1798 if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
|
1799 dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
|
1800 RTL_W8(0x82, 0x01); |
|
1801 } |
|
1802 |
|
1803 pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); |
|
1804 |
|
1805 if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
|
1806 pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
|
1807 |
|
1808 if (tp->mac_version == RTL_GIGA_MAC_VER_02) { |
|
1809 dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
|
1810 RTL_W8(0x82, 0x01); |
|
1811 dprintk("Set PHY Reg 0x0bh = 0x00h\n"); |
|
1812 mdio_write(ioaddr, 0x0b, 0x0000); //w 0x0b 15 0 0 |
|
1813 } |
|
1814 |
|
1815 rtl8169_phy_reset(dev, tp); |
|
1816 |
|
1817 /* |
|
1818 * rtl8169_set_speed_xmii takes good care of the Fast Ethernet |
|
1819 * only 8101. Don't panic. |
|
1820 */ |
|
1821 rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL); |
|
1822 |
|
1823 if ((RTL_R8(PHYstatus) & TBI_Enable) && netif_msg_link(tp)) |
|
1824 printk(KERN_INFO PFX "%s: TBI auto-negotiating\n", dev->name); |
|
1825 } |
|
1826 |
|
1827 static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr) |
|
1828 { |
|
1829 void __iomem *ioaddr = tp->mmio_addr; |
|
1830 u32 high; |
|
1831 u32 low; |
|
1832 |
|
1833 low = addr[0] | (addr[1] << 8) | (addr[2] << 16) | (addr[3] << 24); |
|
1834 high = addr[4] | (addr[5] << 8); |
|
1835 |
|
1836 spin_lock_irq(&tp->lock); |
|
1837 |
|
1838 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
1839 RTL_W32(MAC0, low); |
|
1840 RTL_W32(MAC4, high); |
|
1841 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
1842 |
|
1843 spin_unlock_irq(&tp->lock); |
|
1844 } |
|
1845 |
|
1846 static int rtl_set_mac_address(struct net_device *dev, void *p) |
|
1847 { |
|
1848 struct rtl8169_private *tp = netdev_priv(dev); |
|
1849 struct sockaddr *addr = p; |
|
1850 |
|
1851 if (!is_valid_ether_addr(addr->sa_data)) |
|
1852 return -EADDRNOTAVAIL; |
|
1853 |
|
1854 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
|
1855 |
|
1856 rtl_rar_set(tp, dev->dev_addr); |
|
1857 |
|
1858 return 0; |
|
1859 } |
|
1860 |
|
1861 static int rtl8169_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
|
1862 { |
|
1863 struct rtl8169_private *tp = netdev_priv(dev); |
|
1864 struct mii_ioctl_data *data = if_mii(ifr); |
|
1865 |
|
1866 return netif_running(dev) ? tp->do_ioctl(tp, data, cmd) : -ENODEV; |
|
1867 } |
|
1868 |
|
1869 static int rtl_xmii_ioctl(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd) |
|
1870 { |
|
1871 switch (cmd) { |
|
1872 case SIOCGMIIPHY: |
|
1873 data->phy_id = 32; /* Internal PHY */ |
|
1874 return 0; |
|
1875 |
|
1876 case SIOCGMIIREG: |
|
1877 data->val_out = mdio_read(tp->mmio_addr, data->reg_num & 0x1f); |
|
1878 return 0; |
|
1879 |
|
1880 case SIOCSMIIREG: |
|
1881 if (!capable(CAP_NET_ADMIN)) |
|
1882 return -EPERM; |
|
1883 mdio_write(tp->mmio_addr, data->reg_num & 0x1f, data->val_in); |
|
1884 return 0; |
|
1885 } |
|
1886 return -EOPNOTSUPP; |
|
1887 } |
|
1888 |
|
1889 static int rtl_tbi_ioctl(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd) |
|
1890 { |
|
1891 return -EOPNOTSUPP; |
|
1892 } |
|
1893 |
|
1894 static const struct rtl_cfg_info { |
|
1895 void (*hw_start)(struct net_device *); |
|
1896 unsigned int region; |
|
1897 unsigned int align; |
|
1898 u16 intr_event; |
|
1899 u16 napi_event; |
|
1900 unsigned features; |
|
1901 u8 default_ver; |
|
1902 } rtl_cfg_infos [] = { |
|
1903 [RTL_CFG_0] = { |
|
1904 .hw_start = rtl_hw_start_8169, |
|
1905 .region = 1, |
|
1906 .align = 0, |
|
1907 .intr_event = SYSErr | LinkChg | RxOverflow | |
|
1908 RxFIFOOver | TxErr | TxOK | RxOK | RxErr, |
|
1909 .napi_event = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow, |
|
1910 .features = RTL_FEATURE_GMII, |
|
1911 .default_ver = RTL_GIGA_MAC_VER_01, |
|
1912 }, |
|
1913 [RTL_CFG_1] = { |
|
1914 .hw_start = rtl_hw_start_8168, |
|
1915 .region = 2, |
|
1916 .align = 8, |
|
1917 .intr_event = SYSErr | LinkChg | RxOverflow | |
|
1918 TxErr | TxOK | RxOK | RxErr, |
|
1919 .napi_event = TxErr | TxOK | RxOK | RxOverflow, |
|
1920 .features = RTL_FEATURE_GMII | RTL_FEATURE_MSI, |
|
1921 .default_ver = RTL_GIGA_MAC_VER_11, |
|
1922 }, |
|
1923 [RTL_CFG_2] = { |
|
1924 .hw_start = rtl_hw_start_8101, |
|
1925 .region = 2, |
|
1926 .align = 8, |
|
1927 .intr_event = SYSErr | LinkChg | RxOverflow | PCSTimeout | |
|
1928 RxFIFOOver | TxErr | TxOK | RxOK | RxErr, |
|
1929 .napi_event = RxFIFOOver | TxErr | TxOK | RxOK | RxOverflow, |
|
1930 .features = RTL_FEATURE_MSI, |
|
1931 .default_ver = RTL_GIGA_MAC_VER_13, |
|
1932 } |
|
1933 }; |
|
1934 |
|
1935 /* Cfg9346_Unlock assumed. */ |
|
1936 static unsigned rtl_try_msi(struct pci_dev *pdev, void __iomem *ioaddr, |
|
1937 const struct rtl_cfg_info *cfg) |
|
1938 { |
|
1939 unsigned msi = 0; |
|
1940 u8 cfg2; |
|
1941 |
|
1942 cfg2 = RTL_R8(Config2) & ~MSIEnable; |
|
1943 if (cfg->features & RTL_FEATURE_MSI) { |
|
1944 if (pci_enable_msi(pdev)) { |
|
1945 dev_info(&pdev->dev, "no MSI. Back to INTx.\n"); |
|
1946 } else { |
|
1947 cfg2 |= MSIEnable; |
|
1948 msi = RTL_FEATURE_MSI; |
|
1949 } |
|
1950 } |
|
1951 RTL_W8(Config2, cfg2); |
|
1952 return msi; |
|
1953 } |
|
1954 |
|
1955 static void rtl_disable_msi(struct pci_dev *pdev, struct rtl8169_private *tp) |
|
1956 { |
|
1957 if (tp->features & RTL_FEATURE_MSI) { |
|
1958 pci_disable_msi(pdev); |
|
1959 tp->features &= ~RTL_FEATURE_MSI; |
|
1960 } |
|
1961 } |
|
1962 |
|
1963 static const struct net_device_ops rtl8169_netdev_ops = { |
|
1964 .ndo_open = rtl8169_open, |
|
1965 .ndo_stop = rtl8169_close, |
|
1966 .ndo_get_stats = rtl8169_get_stats, |
|
1967 .ndo_start_xmit = rtl8169_start_xmit, |
|
1968 .ndo_tx_timeout = rtl8169_tx_timeout, |
|
1969 .ndo_validate_addr = eth_validate_addr, |
|
1970 .ndo_change_mtu = rtl8169_change_mtu, |
|
1971 .ndo_set_mac_address = rtl_set_mac_address, |
|
1972 .ndo_do_ioctl = rtl8169_ioctl, |
|
1973 .ndo_set_multicast_list = rtl_set_rx_mode, |
|
1974 #ifdef CONFIG_R8169_VLAN |
|
1975 .ndo_vlan_rx_register = rtl8169_vlan_rx_register, |
|
1976 #endif |
|
1977 #ifdef CONFIG_NET_POLL_CONTROLLER |
|
1978 .ndo_poll_controller = rtl8169_netpoll, |
|
1979 #endif |
|
1980 |
|
1981 }; |
|
1982 |
|
1983 static int __devinit |
|
1984 rtl8169_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
|
1985 { |
|
1986 const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data; |
|
1987 const unsigned int region = cfg->region; |
|
1988 struct rtl8169_private *tp; |
|
1989 struct mii_if_info *mii; |
|
1990 struct net_device *dev; |
|
1991 void __iomem *ioaddr; |
|
1992 unsigned int i; |
|
1993 int rc; |
|
1994 |
|
1995 if (netif_msg_drv(&debug)) { |
|
1996 printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n", |
|
1997 MODULENAME, RTL8169_VERSION); |
|
1998 } |
|
1999 |
|
2000 dev = alloc_etherdev(sizeof (*tp)); |
|
2001 if (!dev) { |
|
2002 if (netif_msg_drv(&debug)) |
|
2003 dev_err(&pdev->dev, "unable to alloc new ethernet\n"); |
|
2004 rc = -ENOMEM; |
|
2005 goto out; |
|
2006 } |
|
2007 |
|
2008 SET_NETDEV_DEV(dev, &pdev->dev); |
|
2009 dev->netdev_ops = &rtl8169_netdev_ops; |
|
2010 tp = netdev_priv(dev); |
|
2011 tp->dev = dev; |
|
2012 tp->pci_dev = pdev; |
|
2013 tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT); |
|
2014 |
|
2015 mii = &tp->mii; |
|
2016 mii->dev = dev; |
|
2017 mii->mdio_read = rtl_mdio_read; |
|
2018 mii->mdio_write = rtl_mdio_write; |
|
2019 mii->phy_id_mask = 0x1f; |
|
2020 mii->reg_num_mask = 0x1f; |
|
2021 mii->supports_gmii = !!(cfg->features & RTL_FEATURE_GMII); |
|
2022 |
|
2023 /* enable device (incl. PCI PM wakeup and hotplug setup) */ |
|
2024 rc = pci_enable_device(pdev); |
|
2025 if (rc < 0) { |
|
2026 if (netif_msg_probe(tp)) |
|
2027 dev_err(&pdev->dev, "enable failure\n"); |
|
2028 goto err_out_free_dev_1; |
|
2029 } |
|
2030 |
|
2031 rc = pci_set_mwi(pdev); |
|
2032 if (rc < 0) |
|
2033 goto err_out_disable_2; |
|
2034 |
|
2035 /* make sure PCI base addr 1 is MMIO */ |
|
2036 if (!(pci_resource_flags(pdev, region) & IORESOURCE_MEM)) { |
|
2037 if (netif_msg_probe(tp)) { |
|
2038 dev_err(&pdev->dev, |
|
2039 "region #%d not an MMIO resource, aborting\n", |
|
2040 region); |
|
2041 } |
|
2042 rc = -ENODEV; |
|
2043 goto err_out_mwi_3; |
|
2044 } |
|
2045 |
|
2046 /* check for weird/broken PCI region reporting */ |
|
2047 if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) { |
|
2048 if (netif_msg_probe(tp)) { |
|
2049 dev_err(&pdev->dev, |
|
2050 "Invalid PCI region size(s), aborting\n"); |
|
2051 } |
|
2052 rc = -ENODEV; |
|
2053 goto err_out_mwi_3; |
|
2054 } |
|
2055 |
|
2056 rc = pci_request_regions(pdev, MODULENAME); |
|
2057 if (rc < 0) { |
|
2058 if (netif_msg_probe(tp)) |
|
2059 dev_err(&pdev->dev, "could not request regions.\n"); |
|
2060 goto err_out_mwi_3; |
|
2061 } |
|
2062 |
|
2063 tp->cp_cmd = PCIMulRW | RxChkSum; |
|
2064 |
|
2065 if ((sizeof(dma_addr_t) > 4) && |
|
2066 !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && use_dac) { |
|
2067 tp->cp_cmd |= PCIDAC; |
|
2068 dev->features |= NETIF_F_HIGHDMA; |
|
2069 } else { |
|
2070 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
|
2071 if (rc < 0) { |
|
2072 if (netif_msg_probe(tp)) { |
|
2073 dev_err(&pdev->dev, |
|
2074 "DMA configuration failed.\n"); |
|
2075 } |
|
2076 goto err_out_free_res_4; |
|
2077 } |
|
2078 } |
|
2079 |
|
2080 /* ioremap MMIO region */ |
|
2081 ioaddr = ioremap(pci_resource_start(pdev, region), R8169_REGS_SIZE); |
|
2082 if (!ioaddr) { |
|
2083 if (netif_msg_probe(tp)) |
|
2084 dev_err(&pdev->dev, "cannot remap MMIO, aborting\n"); |
|
2085 rc = -EIO; |
|
2086 goto err_out_free_res_4; |
|
2087 } |
|
2088 |
|
2089 tp->pcie_cap = pci_find_capability(pdev, PCI_CAP_ID_EXP); |
|
2090 if (!tp->pcie_cap && netif_msg_probe(tp)) |
|
2091 dev_info(&pdev->dev, "no PCI Express capability\n"); |
|
2092 |
|
2093 RTL_W16(IntrMask, 0x0000); |
|
2094 |
|
2095 /* Soft reset the chip. */ |
|
2096 RTL_W8(ChipCmd, CmdReset); |
|
2097 |
|
2098 /* Check that the chip has finished the reset. */ |
|
2099 for (i = 0; i < 100; i++) { |
|
2100 if ((RTL_R8(ChipCmd) & CmdReset) == 0) |
|
2101 break; |
|
2102 msleep_interruptible(1); |
|
2103 } |
|
2104 |
|
2105 RTL_W16(IntrStatus, 0xffff); |
|
2106 |
|
2107 pci_set_master(pdev); |
|
2108 |
|
2109 /* Identify chip attached to board */ |
|
2110 rtl8169_get_mac_version(tp, ioaddr); |
|
2111 |
|
2112 /* Use appropriate default if unknown */ |
|
2113 if (tp->mac_version == RTL_GIGA_MAC_NONE) { |
|
2114 if (netif_msg_probe(tp)) { |
|
2115 dev_notice(&pdev->dev, |
|
2116 "unknown MAC, using family default\n"); |
|
2117 } |
|
2118 tp->mac_version = cfg->default_ver; |
|
2119 } |
|
2120 |
|
2121 rtl8169_print_mac_version(tp); |
|
2122 |
|
2123 for (i = 0; i < ARRAY_SIZE(rtl_chip_info); i++) { |
|
2124 if (tp->mac_version == rtl_chip_info[i].mac_version) |
|
2125 break; |
|
2126 } |
|
2127 if (i == ARRAY_SIZE(rtl_chip_info)) { |
|
2128 dev_err(&pdev->dev, |
|
2129 "driver bug, MAC version not found in rtl_chip_info\n"); |
|
2130 goto err_out_msi_5; |
|
2131 } |
|
2132 tp->chipset = i; |
|
2133 |
|
2134 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
2135 RTL_W8(Config1, RTL_R8(Config1) | PMEnable); |
|
2136 RTL_W8(Config5, RTL_R8(Config5) & PMEStatus); |
|
2137 if ((RTL_R8(Config3) & (LinkUp | MagicPacket)) != 0) |
|
2138 tp->features |= RTL_FEATURE_WOL; |
|
2139 if ((RTL_R8(Config5) & (UWF | BWF | MWF)) != 0) |
|
2140 tp->features |= RTL_FEATURE_WOL; |
|
2141 tp->features |= rtl_try_msi(pdev, ioaddr, cfg); |
|
2142 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
2143 |
|
2144 if ((tp->mac_version <= RTL_GIGA_MAC_VER_06) && |
|
2145 (RTL_R8(PHYstatus) & TBI_Enable)) { |
|
2146 tp->set_speed = rtl8169_set_speed_tbi; |
|
2147 tp->get_settings = rtl8169_gset_tbi; |
|
2148 tp->phy_reset_enable = rtl8169_tbi_reset_enable; |
|
2149 tp->phy_reset_pending = rtl8169_tbi_reset_pending; |
|
2150 tp->link_ok = rtl8169_tbi_link_ok; |
|
2151 tp->do_ioctl = rtl_tbi_ioctl; |
|
2152 |
|
2153 tp->phy_1000_ctrl_reg = ADVERTISE_1000FULL; /* Implied by TBI */ |
|
2154 } else { |
|
2155 tp->set_speed = rtl8169_set_speed_xmii; |
|
2156 tp->get_settings = rtl8169_gset_xmii; |
|
2157 tp->phy_reset_enable = rtl8169_xmii_reset_enable; |
|
2158 tp->phy_reset_pending = rtl8169_xmii_reset_pending; |
|
2159 tp->link_ok = rtl8169_xmii_link_ok; |
|
2160 tp->do_ioctl = rtl_xmii_ioctl; |
|
2161 } |
|
2162 |
|
2163 spin_lock_init(&tp->lock); |
|
2164 |
|
2165 tp->mmio_addr = ioaddr; |
|
2166 |
|
2167 /* Get MAC address */ |
|
2168 for (i = 0; i < MAC_ADDR_LEN; i++) |
|
2169 dev->dev_addr[i] = RTL_R8(MAC0 + i); |
|
2170 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
|
2171 |
|
2172 SET_ETHTOOL_OPS(dev, &rtl8169_ethtool_ops); |
|
2173 dev->watchdog_timeo = RTL8169_TX_TIMEOUT; |
|
2174 dev->irq = pdev->irq; |
|
2175 dev->base_addr = (unsigned long) ioaddr; |
|
2176 |
|
2177 netif_napi_add(dev, &tp->napi, rtl8169_poll, R8169_NAPI_WEIGHT); |
|
2178 |
|
2179 #ifdef CONFIG_R8169_VLAN |
|
2180 dev->features |= NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
|
2181 #endif |
|
2182 |
|
2183 tp->intr_mask = 0xffff; |
|
2184 tp->align = cfg->align; |
|
2185 tp->hw_start = cfg->hw_start; |
|
2186 tp->intr_event = cfg->intr_event; |
|
2187 tp->napi_event = cfg->napi_event; |
|
2188 |
|
2189 init_timer(&tp->timer); |
|
2190 tp->timer.data = (unsigned long) dev; |
|
2191 tp->timer.function = rtl8169_phy_timer; |
|
2192 |
|
2193 // offer device to EtherCAT master module |
|
2194 tp->ecdev = ecdev_offer(dev, ec_poll, THIS_MODULE); |
|
2195 |
|
2196 if (!tp->ecdev) { |
|
2197 rc = register_netdev(dev); |
|
2198 if (rc < 0) |
|
2199 goto err_out_msi_5; |
|
2200 } |
|
2201 |
|
2202 pci_set_drvdata(pdev, dev); |
|
2203 |
|
2204 if (netif_msg_probe(tp)) { |
|
2205 u32 xid = RTL_R32(TxConfig) & 0x7cf0f8ff; |
|
2206 |
|
2207 printk(KERN_INFO "%s: %s at 0x%lx, " |
|
2208 "%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x, " |
|
2209 "XID %08x IRQ %d\n", |
|
2210 dev->name, |
|
2211 rtl_chip_info[tp->chipset].name, |
|
2212 dev->base_addr, |
|
2213 dev->dev_addr[0], dev->dev_addr[1], |
|
2214 dev->dev_addr[2], dev->dev_addr[3], |
|
2215 dev->dev_addr[4], dev->dev_addr[5], xid, dev->irq); |
|
2216 } |
|
2217 |
|
2218 rtl8169_init_phy(dev, tp); |
|
2219 device_set_wakeup_enable(&pdev->dev, tp->features & RTL_FEATURE_WOL); |
|
2220 if (tp->ecdev && ecdev_open(tp->ecdev)) { |
|
2221 ecdev_withdraw(tp->ecdev); |
|
2222 goto err_out_msi_5; |
|
2223 } |
|
2224 |
|
2225 |
|
2226 out: |
|
2227 return rc; |
|
2228 |
|
2229 err_out_msi_5: |
|
2230 rtl_disable_msi(pdev, tp); |
|
2231 iounmap(ioaddr); |
|
2232 err_out_free_res_4: |
|
2233 pci_release_regions(pdev); |
|
2234 err_out_mwi_3: |
|
2235 pci_clear_mwi(pdev); |
|
2236 err_out_disable_2: |
|
2237 pci_disable_device(pdev); |
|
2238 err_out_free_dev_1: |
|
2239 free_netdev(dev); |
|
2240 goto out; |
|
2241 } |
|
2242 |
|
2243 static void __devexit rtl8169_remove_one(struct pci_dev *pdev) |
|
2244 { |
|
2245 struct net_device *dev = pci_get_drvdata(pdev); |
|
2246 struct rtl8169_private *tp = netdev_priv(dev); |
|
2247 |
|
2248 flush_scheduled_work(); |
|
2249 |
|
2250 if (tp->ecdev) { |
|
2251 ecdev_close(tp->ecdev); |
|
2252 ecdev_withdraw(tp->ecdev); |
|
2253 } else { |
|
2254 unregister_netdev(dev); |
|
2255 } |
|
2256 rtl_disable_msi(pdev, tp); |
|
2257 rtl8169_release_board(pdev, dev, tp->mmio_addr); |
|
2258 pci_set_drvdata(pdev, NULL); |
|
2259 } |
|
2260 |
|
2261 static void rtl8169_set_rxbufsize(struct rtl8169_private *tp, |
|
2262 struct net_device *dev) |
|
2263 { |
|
2264 unsigned int mtu = dev->mtu; |
|
2265 |
|
2266 tp->rx_buf_sz = (mtu > RX_BUF_SIZE) ? mtu + ETH_HLEN + 8 : RX_BUF_SIZE; |
|
2267 } |
|
2268 |
|
2269 static int rtl8169_open(struct net_device *dev) |
|
2270 { |
|
2271 struct rtl8169_private *tp = netdev_priv(dev); |
|
2272 struct pci_dev *pdev = tp->pci_dev; |
|
2273 int retval = -ENOMEM; |
|
2274 |
|
2275 |
|
2276 rtl8169_set_rxbufsize(tp, dev); |
|
2277 |
|
2278 /* |
|
2279 * Rx and Tx desscriptors needs 256 bytes alignment. |
|
2280 * pci_alloc_consistent provides more. |
|
2281 */ |
|
2282 tp->TxDescArray = pci_alloc_consistent(pdev, R8169_TX_RING_BYTES, |
|
2283 &tp->TxPhyAddr); |
|
2284 if (!tp->TxDescArray) |
|
2285 goto out; |
|
2286 |
|
2287 tp->RxDescArray = pci_alloc_consistent(pdev, R8169_RX_RING_BYTES, |
|
2288 &tp->RxPhyAddr); |
|
2289 if (!tp->RxDescArray) |
|
2290 goto err_free_tx_0; |
|
2291 |
|
2292 retval = rtl8169_init_ring(dev); |
|
2293 if (retval < 0) |
|
2294 goto err_free_rx_1; |
|
2295 |
|
2296 INIT_DELAYED_WORK(&tp->task, NULL); |
|
2297 |
|
2298 smp_mb(); |
|
2299 |
|
2300 if (!tp->ecdev) { |
|
2301 retval = request_irq(dev->irq, rtl8169_interrupt, |
|
2302 (tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED, |
|
2303 dev->name, dev); |
|
2304 if (retval < 0) |
|
2305 goto err_release_ring_2; |
|
2306 |
|
2307 napi_enable(&tp->napi); |
|
2308 |
|
2309 } |
|
2310 rtl_hw_start(dev); |
|
2311 |
|
2312 rtl8169_request_timer(dev); |
|
2313 |
|
2314 rtl8169_check_link_status(dev, tp, tp->mmio_addr); |
|
2315 out: |
|
2316 return retval; |
|
2317 |
|
2318 err_release_ring_2: |
|
2319 rtl8169_rx_clear(tp); |
|
2320 err_free_rx_1: |
|
2321 pci_free_consistent(pdev, R8169_RX_RING_BYTES, tp->RxDescArray, |
|
2322 tp->RxPhyAddr); |
|
2323 err_free_tx_0: |
|
2324 pci_free_consistent(pdev, R8169_TX_RING_BYTES, tp->TxDescArray, |
|
2325 tp->TxPhyAddr); |
|
2326 goto out; |
|
2327 } |
|
2328 |
|
2329 static void rtl8169_hw_reset(void __iomem *ioaddr) |
|
2330 { |
|
2331 /* Disable interrupts */ |
|
2332 rtl8169_irq_mask_and_ack(ioaddr); |
|
2333 |
|
2334 /* Reset the chipset */ |
|
2335 RTL_W8(ChipCmd, CmdReset); |
|
2336 |
|
2337 /* PCI commit */ |
|
2338 RTL_R8(ChipCmd); |
|
2339 } |
|
2340 |
|
2341 static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp) |
|
2342 { |
|
2343 void __iomem *ioaddr = tp->mmio_addr; |
|
2344 u32 cfg = rtl8169_rx_config; |
|
2345 |
|
2346 cfg |= (RTL_R32(RxConfig) & rtl_chip_info[tp->chipset].RxConfigMask); |
|
2347 RTL_W32(RxConfig, cfg); |
|
2348 |
|
2349 /* Set DMA burst size and Interframe Gap Time */ |
|
2350 RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) | |
|
2351 (InterFrameGap << TxInterFrameGapShift)); |
|
2352 } |
|
2353 |
|
2354 static void rtl_hw_start(struct net_device *dev) |
|
2355 { |
|
2356 struct rtl8169_private *tp = netdev_priv(dev); |
|
2357 void __iomem *ioaddr = tp->mmio_addr; |
|
2358 unsigned int i; |
|
2359 |
|
2360 /* Soft reset the chip. */ |
|
2361 RTL_W8(ChipCmd, CmdReset); |
|
2362 |
|
2363 /* Check that the chip has finished the reset. */ |
|
2364 for (i = 0; i < 100; i++) { |
|
2365 if ((RTL_R8(ChipCmd) & CmdReset) == 0) |
|
2366 break; |
|
2367 msleep_interruptible(1); |
|
2368 } |
|
2369 |
|
2370 tp->hw_start(dev); |
|
2371 |
|
2372 if (!tp->ecdev) |
|
2373 netif_start_queue(dev); |
|
2374 } |
|
2375 |
|
2376 |
|
2377 static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp, |
|
2378 void __iomem *ioaddr) |
|
2379 { |
|
2380 /* |
|
2381 * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh |
|
2382 * register to be written before TxDescAddrLow to work. |
|
2383 * Switching from MMIO to I/O access fixes the issue as well. |
|
2384 */ |
|
2385 RTL_W32(TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); |
|
2386 RTL_W32(TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); |
|
2387 RTL_W32(RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); |
|
2388 RTL_W32(RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); |
|
2389 } |
|
2390 |
|
2391 static u16 rtl_rw_cpluscmd(void __iomem *ioaddr) |
|
2392 { |
|
2393 u16 cmd; |
|
2394 |
|
2395 cmd = RTL_R16(CPlusCmd); |
|
2396 RTL_W16(CPlusCmd, cmd); |
|
2397 return cmd; |
|
2398 } |
|
2399 |
|
2400 static void rtl_set_rx_max_size(void __iomem *ioaddr, unsigned int rx_buf_sz) |
|
2401 { |
|
2402 /* Low hurts. Let's disable the filtering. */ |
|
2403 RTL_W16(RxMaxSize, rx_buf_sz); |
|
2404 } |
|
2405 |
|
2406 static void rtl8169_set_magic_reg(void __iomem *ioaddr, unsigned mac_version) |
|
2407 { |
|
2408 struct { |
|
2409 u32 mac_version; |
|
2410 u32 clk; |
|
2411 u32 val; |
|
2412 } cfg2_info [] = { |
|
2413 { RTL_GIGA_MAC_VER_05, PCI_Clock_33MHz, 0x000fff00 }, // 8110SCd |
|
2414 { RTL_GIGA_MAC_VER_05, PCI_Clock_66MHz, 0x000fffff }, |
|
2415 { RTL_GIGA_MAC_VER_06, PCI_Clock_33MHz, 0x00ffff00 }, // 8110SCe |
|
2416 { RTL_GIGA_MAC_VER_06, PCI_Clock_66MHz, 0x00ffffff } |
|
2417 }, *p = cfg2_info; |
|
2418 unsigned int i; |
|
2419 u32 clk; |
|
2420 |
|
2421 clk = RTL_R8(Config2) & PCI_Clock_66MHz; |
|
2422 for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) { |
|
2423 if ((p->mac_version == mac_version) && (p->clk == clk)) { |
|
2424 RTL_W32(0x7c, p->val); |
|
2425 break; |
|
2426 } |
|
2427 } |
|
2428 } |
|
2429 |
|
2430 static void rtl_hw_start_8169(struct net_device *dev) |
|
2431 { |
|
2432 struct rtl8169_private *tp = netdev_priv(dev); |
|
2433 void __iomem *ioaddr = tp->mmio_addr; |
|
2434 struct pci_dev *pdev = tp->pci_dev; |
|
2435 |
|
2436 printk(KERN_INFO "%s\n", __func__); |
|
2437 |
|
2438 if (tp->mac_version == RTL_GIGA_MAC_VER_05) { |
|
2439 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) | PCIMulRW); |
|
2440 pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, 0x08); |
|
2441 } |
|
2442 |
|
2443 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
2444 if ((tp->mac_version == RTL_GIGA_MAC_VER_01) || |
|
2445 (tp->mac_version == RTL_GIGA_MAC_VER_02) || |
|
2446 (tp->mac_version == RTL_GIGA_MAC_VER_03) || |
|
2447 (tp->mac_version == RTL_GIGA_MAC_VER_04)) |
|
2448 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
|
2449 |
|
2450 RTL_W8(EarlyTxThres, EarlyTxThld); |
|
2451 |
|
2452 rtl_set_rx_max_size(ioaddr, tp->rx_buf_sz); |
|
2453 |
|
2454 if ((tp->mac_version == RTL_GIGA_MAC_VER_01) || |
|
2455 (tp->mac_version == RTL_GIGA_MAC_VER_02) || |
|
2456 (tp->mac_version == RTL_GIGA_MAC_VER_03) || |
|
2457 (tp->mac_version == RTL_GIGA_MAC_VER_04)) |
|
2458 rtl_set_rx_tx_config_registers(tp); |
|
2459 |
|
2460 tp->cp_cmd |= rtl_rw_cpluscmd(ioaddr) | PCIMulRW; |
|
2461 |
|
2462 if ((tp->mac_version == RTL_GIGA_MAC_VER_02) || |
|
2463 (tp->mac_version == RTL_GIGA_MAC_VER_03)) { |
|
2464 dprintk("Set MAC Reg C+CR Offset 0xE0. " |
|
2465 "Bit-3 and bit-14 MUST be 1\n"); |
|
2466 tp->cp_cmd |= (1 << 14); |
|
2467 } |
|
2468 |
|
2469 RTL_W16(CPlusCmd, tp->cp_cmd); |
|
2470 |
|
2471 rtl8169_set_magic_reg(ioaddr, tp->mac_version); |
|
2472 |
|
2473 /* |
|
2474 * Undocumented corner. Supposedly: |
|
2475 * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets |
|
2476 */ |
|
2477 RTL_W16(IntrMitigate, 0x0000); |
|
2478 |
|
2479 rtl_set_rx_tx_desc_registers(tp, ioaddr); |
|
2480 |
|
2481 if ((tp->mac_version != RTL_GIGA_MAC_VER_01) && |
|
2482 (tp->mac_version != RTL_GIGA_MAC_VER_02) && |
|
2483 (tp->mac_version != RTL_GIGA_MAC_VER_03) && |
|
2484 (tp->mac_version != RTL_GIGA_MAC_VER_04)) { |
|
2485 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
|
2486 rtl_set_rx_tx_config_registers(tp); |
|
2487 } |
|
2488 |
|
2489 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
2490 |
|
2491 /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ |
|
2492 RTL_R8(IntrMask); |
|
2493 |
|
2494 RTL_W32(RxMissed, 0); |
|
2495 |
|
2496 rtl_set_rx_mode(dev); |
|
2497 |
|
2498 /* no early-rx interrupts */ |
|
2499 RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000); |
|
2500 |
|
2501 /* Enable all known interrupts by setting the interrupt mask. */ |
|
2502 if (!tp->ecdev) |
|
2503 RTL_W16(IntrMask, tp->intr_event); |
|
2504 } |
|
2505 |
|
2506 static void rtl_tx_performance_tweak(struct pci_dev *pdev, u16 force) |
|
2507 { |
|
2508 struct net_device *dev = pci_get_drvdata(pdev); |
|
2509 struct rtl8169_private *tp = netdev_priv(dev); |
|
2510 int cap = tp->pcie_cap; |
|
2511 |
|
2512 if (cap) { |
|
2513 u16 ctl; |
|
2514 |
|
2515 pci_read_config_word(pdev, cap + PCI_EXP_DEVCTL, &ctl); |
|
2516 ctl = (ctl & ~PCI_EXP_DEVCTL_READRQ) | force; |
|
2517 pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, ctl); |
|
2518 } |
|
2519 } |
|
2520 |
|
2521 static void rtl_csi_access_enable(void __iomem *ioaddr) |
|
2522 { |
|
2523 u32 csi; |
|
2524 |
|
2525 csi = rtl_csi_read(ioaddr, 0x070c) & 0x00ffffff; |
|
2526 rtl_csi_write(ioaddr, 0x070c, csi | 0x27000000); |
|
2527 } |
|
2528 |
|
2529 struct ephy_info { |
|
2530 unsigned int offset; |
|
2531 u16 mask; |
|
2532 u16 bits; |
|
2533 }; |
|
2534 |
|
2535 static void rtl_ephy_init(void __iomem *ioaddr, struct ephy_info *e, int len) |
|
2536 { |
|
2537 u16 w; |
|
2538 |
|
2539 while (len-- > 0) { |
|
2540 w = (rtl_ephy_read(ioaddr, e->offset) & ~e->mask) | e->bits; |
|
2541 rtl_ephy_write(ioaddr, e->offset, w); |
|
2542 e++; |
|
2543 } |
|
2544 } |
|
2545 |
|
2546 static void rtl_disable_clock_request(struct pci_dev *pdev) |
|
2547 { |
|
2548 struct net_device *dev = pci_get_drvdata(pdev); |
|
2549 struct rtl8169_private *tp = netdev_priv(dev); |
|
2550 int cap = tp->pcie_cap; |
|
2551 |
|
2552 if (cap) { |
|
2553 u16 ctl; |
|
2554 |
|
2555 pci_read_config_word(pdev, cap + PCI_EXP_LNKCTL, &ctl); |
|
2556 ctl &= ~PCI_EXP_LNKCTL_CLKREQ_EN; |
|
2557 pci_write_config_word(pdev, cap + PCI_EXP_LNKCTL, ctl); |
|
2558 } |
|
2559 } |
|
2560 |
|
2561 #define R8168_CPCMD_QUIRK_MASK (\ |
|
2562 EnableBist | \ |
|
2563 Mac_dbgo_oe | \ |
|
2564 Force_half_dup | \ |
|
2565 Force_rxflow_en | \ |
|
2566 Force_txflow_en | \ |
|
2567 Cxpl_dbg_sel | \ |
|
2568 ASF | \ |
|
2569 PktCntrDisable | \ |
|
2570 Mac_dbgo_sel) |
|
2571 |
|
2572 static void rtl_hw_start_8168bb(void __iomem *ioaddr, struct pci_dev *pdev) |
|
2573 { |
|
2574 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
2575 |
|
2576 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
|
2577 |
|
2578 rtl_tx_performance_tweak(pdev, |
|
2579 (0x5 << MAX_READ_REQUEST_SHIFT) | PCI_EXP_DEVCTL_NOSNOOP_EN); |
|
2580 } |
|
2581 |
|
2582 static void rtl_hw_start_8168bef(void __iomem *ioaddr, struct pci_dev *pdev) |
|
2583 { |
|
2584 rtl_hw_start_8168bb(ioaddr, pdev); |
|
2585 |
|
2586 RTL_W8(EarlyTxThres, EarlyTxThld); |
|
2587 |
|
2588 RTL_W8(Config4, RTL_R8(Config4) & ~(1 << 0)); |
|
2589 } |
|
2590 |
|
2591 static void __rtl_hw_start_8168cp(void __iomem *ioaddr, struct pci_dev *pdev) |
|
2592 { |
|
2593 RTL_W8(Config1, RTL_R8(Config1) | Speed_down); |
|
2594 |
|
2595 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
2596 |
|
2597 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
2598 |
|
2599 rtl_disable_clock_request(pdev); |
|
2600 |
|
2601 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
|
2602 } |
|
2603 |
|
2604 static void rtl_hw_start_8168cp_1(void __iomem *ioaddr, struct pci_dev *pdev) |
|
2605 { |
|
2606 static struct ephy_info e_info_8168cp[] = { |
|
2607 { 0x01, 0, 0x0001 }, |
|
2608 { 0x02, 0x0800, 0x1000 }, |
|
2609 { 0x03, 0, 0x0042 }, |
|
2610 { 0x06, 0x0080, 0x0000 }, |
|
2611 { 0x07, 0, 0x2000 } |
|
2612 }; |
|
2613 |
|
2614 rtl_csi_access_enable(ioaddr); |
|
2615 |
|
2616 rtl_ephy_init(ioaddr, e_info_8168cp, ARRAY_SIZE(e_info_8168cp)); |
|
2617 |
|
2618 __rtl_hw_start_8168cp(ioaddr, pdev); |
|
2619 } |
|
2620 |
|
2621 static void rtl_hw_start_8168cp_2(void __iomem *ioaddr, struct pci_dev *pdev) |
|
2622 { |
|
2623 rtl_csi_access_enable(ioaddr); |
|
2624 |
|
2625 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
2626 |
|
2627 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
2628 |
|
2629 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
|
2630 } |
|
2631 |
|
2632 static void rtl_hw_start_8168cp_3(void __iomem *ioaddr, struct pci_dev *pdev) |
|
2633 { |
|
2634 rtl_csi_access_enable(ioaddr); |
|
2635 |
|
2636 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
2637 |
|
2638 /* Magic. */ |
|
2639 RTL_W8(DBG_REG, 0x20); |
|
2640 |
|
2641 RTL_W8(EarlyTxThres, EarlyTxThld); |
|
2642 |
|
2643 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
2644 |
|
2645 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
|
2646 } |
|
2647 |
|
2648 static void rtl_hw_start_8168c_1(void __iomem *ioaddr, struct pci_dev *pdev) |
|
2649 { |
|
2650 static struct ephy_info e_info_8168c_1[] = { |
|
2651 { 0x02, 0x0800, 0x1000 }, |
|
2652 { 0x03, 0, 0x0002 }, |
|
2653 { 0x06, 0x0080, 0x0000 } |
|
2654 }; |
|
2655 |
|
2656 rtl_csi_access_enable(ioaddr); |
|
2657 |
|
2658 RTL_W8(DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2); |
|
2659 |
|
2660 rtl_ephy_init(ioaddr, e_info_8168c_1, ARRAY_SIZE(e_info_8168c_1)); |
|
2661 |
|
2662 __rtl_hw_start_8168cp(ioaddr, pdev); |
|
2663 } |
|
2664 |
|
2665 static void rtl_hw_start_8168c_2(void __iomem *ioaddr, struct pci_dev *pdev) |
|
2666 { |
|
2667 static struct ephy_info e_info_8168c_2[] = { |
|
2668 { 0x01, 0, 0x0001 }, |
|
2669 { 0x03, 0x0400, 0x0220 } |
|
2670 }; |
|
2671 |
|
2672 rtl_csi_access_enable(ioaddr); |
|
2673 |
|
2674 rtl_ephy_init(ioaddr, e_info_8168c_2, ARRAY_SIZE(e_info_8168c_2)); |
|
2675 |
|
2676 __rtl_hw_start_8168cp(ioaddr, pdev); |
|
2677 } |
|
2678 |
|
2679 static void rtl_hw_start_8168c_3(void __iomem *ioaddr, struct pci_dev *pdev) |
|
2680 { |
|
2681 rtl_hw_start_8168c_2(ioaddr, pdev); |
|
2682 } |
|
2683 |
|
2684 static void rtl_hw_start_8168c_4(void __iomem *ioaddr, struct pci_dev *pdev) |
|
2685 { |
|
2686 rtl_csi_access_enable(ioaddr); |
|
2687 |
|
2688 __rtl_hw_start_8168cp(ioaddr, pdev); |
|
2689 } |
|
2690 |
|
2691 static void rtl_hw_start_8168d(void __iomem *ioaddr, struct pci_dev *pdev) |
|
2692 { |
|
2693 rtl_csi_access_enable(ioaddr); |
|
2694 |
|
2695 rtl_disable_clock_request(pdev); |
|
2696 |
|
2697 RTL_W8(EarlyTxThres, EarlyTxThld); |
|
2698 |
|
2699 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
2700 |
|
2701 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
|
2702 } |
|
2703 |
|
2704 static void rtl_hw_start_8168(struct net_device *dev) |
|
2705 { |
|
2706 struct rtl8169_private *tp = netdev_priv(dev); |
|
2707 void __iomem *ioaddr = tp->mmio_addr; |
|
2708 struct pci_dev *pdev = tp->pci_dev; |
|
2709 |
|
2710 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
2711 |
|
2712 RTL_W8(EarlyTxThres, EarlyTxThld); |
|
2713 |
|
2714 rtl_set_rx_max_size(ioaddr, tp->rx_buf_sz); |
|
2715 |
|
2716 tp->cp_cmd |= RTL_R16(CPlusCmd) | PktCntrDisable | INTT_1; |
|
2717 |
|
2718 RTL_W16(CPlusCmd, tp->cp_cmd); |
|
2719 |
|
2720 RTL_W16(IntrMitigate, 0x5151); |
|
2721 |
|
2722 /* Work around for RxFIFO overflow. */ |
|
2723 if (tp->mac_version == RTL_GIGA_MAC_VER_11) { |
|
2724 tp->intr_event |= RxFIFOOver | PCSTimeout; |
|
2725 tp->intr_event &= ~RxOverflow; |
|
2726 } |
|
2727 |
|
2728 rtl_set_rx_tx_desc_registers(tp, ioaddr); |
|
2729 |
|
2730 rtl_set_rx_mode(dev); |
|
2731 |
|
2732 RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) | |
|
2733 (InterFrameGap << TxInterFrameGapShift)); |
|
2734 |
|
2735 RTL_R8(IntrMask); |
|
2736 |
|
2737 switch (tp->mac_version) { |
|
2738 case RTL_GIGA_MAC_VER_11: |
|
2739 rtl_hw_start_8168bb(ioaddr, pdev); |
|
2740 break; |
|
2741 |
|
2742 case RTL_GIGA_MAC_VER_12: |
|
2743 case RTL_GIGA_MAC_VER_17: |
|
2744 rtl_hw_start_8168bef(ioaddr, pdev); |
|
2745 break; |
|
2746 |
|
2747 case RTL_GIGA_MAC_VER_18: |
|
2748 rtl_hw_start_8168cp_1(ioaddr, pdev); |
|
2749 break; |
|
2750 |
|
2751 case RTL_GIGA_MAC_VER_19: |
|
2752 rtl_hw_start_8168c_1(ioaddr, pdev); |
|
2753 break; |
|
2754 |
|
2755 case RTL_GIGA_MAC_VER_20: |
|
2756 rtl_hw_start_8168c_2(ioaddr, pdev); |
|
2757 break; |
|
2758 |
|
2759 case RTL_GIGA_MAC_VER_21: |
|
2760 rtl_hw_start_8168c_3(ioaddr, pdev); |
|
2761 break; |
|
2762 |
|
2763 case RTL_GIGA_MAC_VER_22: |
|
2764 rtl_hw_start_8168c_4(ioaddr, pdev); |
|
2765 break; |
|
2766 |
|
2767 case RTL_GIGA_MAC_VER_23: |
|
2768 rtl_hw_start_8168cp_2(ioaddr, pdev); |
|
2769 break; |
|
2770 |
|
2771 case RTL_GIGA_MAC_VER_24: |
|
2772 rtl_hw_start_8168cp_3(ioaddr, pdev); |
|
2773 break; |
|
2774 |
|
2775 case RTL_GIGA_MAC_VER_25: |
|
2776 rtl_hw_start_8168d(ioaddr, pdev); |
|
2777 break; |
|
2778 |
|
2779 default: |
|
2780 printk(KERN_ERR PFX "%s: unknown chipset (mac_version = %d).\n", |
|
2781 dev->name, tp->mac_version); |
|
2782 break; |
|
2783 } |
|
2784 |
|
2785 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
|
2786 |
|
2787 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
2788 |
|
2789 RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000); |
|
2790 |
|
2791 if (!tp->ecdev) |
|
2792 RTL_W16(IntrMask, tp->intr_event); |
|
2793 } |
|
2794 |
|
2795 #define R810X_CPCMD_QUIRK_MASK (\ |
|
2796 EnableBist | \ |
|
2797 Mac_dbgo_oe | \ |
|
2798 Force_half_dup | \ |
|
2799 Force_half_dup | \ |
|
2800 Force_txflow_en | \ |
|
2801 Cxpl_dbg_sel | \ |
|
2802 ASF | \ |
|
2803 PktCntrDisable | \ |
|
2804 PCIDAC | \ |
|
2805 PCIMulRW) |
|
2806 |
|
2807 static void rtl_hw_start_8102e_1(void __iomem *ioaddr, struct pci_dev *pdev) |
|
2808 { |
|
2809 static struct ephy_info e_info_8102e_1[] = { |
|
2810 { 0x01, 0, 0x6e65 }, |
|
2811 { 0x02, 0, 0x091f }, |
|
2812 { 0x03, 0, 0xc2f9 }, |
|
2813 { 0x06, 0, 0xafb5 }, |
|
2814 { 0x07, 0, 0x0e00 }, |
|
2815 { 0x19, 0, 0xec80 }, |
|
2816 { 0x01, 0, 0x2e65 }, |
|
2817 { 0x01, 0, 0x6e65 } |
|
2818 }; |
|
2819 u8 cfg1; |
|
2820 |
|
2821 rtl_csi_access_enable(ioaddr); |
|
2822 |
|
2823 RTL_W8(DBG_REG, FIX_NAK_1); |
|
2824 |
|
2825 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
2826 |
|
2827 RTL_W8(Config1, |
|
2828 LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable); |
|
2829 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
2830 |
|
2831 cfg1 = RTL_R8(Config1); |
|
2832 if ((cfg1 & LEDS0) && (cfg1 & LEDS1)) |
|
2833 RTL_W8(Config1, cfg1 & ~LEDS0); |
|
2834 |
|
2835 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R810X_CPCMD_QUIRK_MASK); |
|
2836 |
|
2837 rtl_ephy_init(ioaddr, e_info_8102e_1, ARRAY_SIZE(e_info_8102e_1)); |
|
2838 } |
|
2839 |
|
2840 static void rtl_hw_start_8102e_2(void __iomem *ioaddr, struct pci_dev *pdev) |
|
2841 { |
|
2842 rtl_csi_access_enable(ioaddr); |
|
2843 |
|
2844 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
2845 |
|
2846 RTL_W8(Config1, MEMMAP | IOMAP | VPD | PMEnable); |
|
2847 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
2848 |
|
2849 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R810X_CPCMD_QUIRK_MASK); |
|
2850 } |
|
2851 |
|
2852 static void rtl_hw_start_8102e_3(void __iomem *ioaddr, struct pci_dev *pdev) |
|
2853 { |
|
2854 rtl_hw_start_8102e_2(ioaddr, pdev); |
|
2855 |
|
2856 rtl_ephy_write(ioaddr, 0x03, 0xc2f9); |
|
2857 } |
|
2858 |
|
2859 static void rtl_hw_start_8101(struct net_device *dev) |
|
2860 { |
|
2861 struct rtl8169_private *tp = netdev_priv(dev); |
|
2862 void __iomem *ioaddr = tp->mmio_addr; |
|
2863 struct pci_dev *pdev = tp->pci_dev; |
|
2864 |
|
2865 if ((tp->mac_version == RTL_GIGA_MAC_VER_13) || |
|
2866 (tp->mac_version == RTL_GIGA_MAC_VER_16)) { |
|
2867 int cap = tp->pcie_cap; |
|
2868 |
|
2869 if (cap) { |
|
2870 pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, |
|
2871 PCI_EXP_DEVCTL_NOSNOOP_EN); |
|
2872 } |
|
2873 } |
|
2874 |
|
2875 switch (tp->mac_version) { |
|
2876 case RTL_GIGA_MAC_VER_07: |
|
2877 rtl_hw_start_8102e_1(ioaddr, pdev); |
|
2878 break; |
|
2879 |
|
2880 case RTL_GIGA_MAC_VER_08: |
|
2881 rtl_hw_start_8102e_3(ioaddr, pdev); |
|
2882 break; |
|
2883 |
|
2884 case RTL_GIGA_MAC_VER_09: |
|
2885 rtl_hw_start_8102e_2(ioaddr, pdev); |
|
2886 break; |
|
2887 } |
|
2888 |
|
2889 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
2890 |
|
2891 RTL_W8(EarlyTxThres, EarlyTxThld); |
|
2892 |
|
2893 rtl_set_rx_max_size(ioaddr, tp->rx_buf_sz); |
|
2894 |
|
2895 tp->cp_cmd |= rtl_rw_cpluscmd(ioaddr) | PCIMulRW; |
|
2896 |
|
2897 RTL_W16(CPlusCmd, tp->cp_cmd); |
|
2898 |
|
2899 RTL_W16(IntrMitigate, 0x0000); |
|
2900 |
|
2901 rtl_set_rx_tx_desc_registers(tp, ioaddr); |
|
2902 |
|
2903 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
|
2904 rtl_set_rx_tx_config_registers(tp); |
|
2905 |
|
2906 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
2907 |
|
2908 RTL_R8(IntrMask); |
|
2909 |
|
2910 rtl_set_rx_mode(dev); |
|
2911 |
|
2912 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
|
2913 |
|
2914 RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000); |
|
2915 |
|
2916 if (!tp->ecdev) |
|
2917 RTL_W16(IntrMask, tp->intr_event); |
|
2918 } |
|
2919 |
|
2920 static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) |
|
2921 { |
|
2922 struct rtl8169_private *tp = netdev_priv(dev); |
|
2923 int ret = 0; |
|
2924 |
|
2925 if (new_mtu < ETH_ZLEN || new_mtu > SafeMtu) |
|
2926 return -EINVAL; |
|
2927 |
|
2928 dev->mtu = new_mtu; |
|
2929 |
|
2930 if (!netif_running(dev)) |
|
2931 goto out; |
|
2932 |
|
2933 rtl8169_down(dev); |
|
2934 |
|
2935 rtl8169_set_rxbufsize(tp, dev); |
|
2936 |
|
2937 ret = rtl8169_init_ring(dev); |
|
2938 if (ret < 0) |
|
2939 goto out; |
|
2940 |
|
2941 napi_enable(&tp->napi); |
|
2942 |
|
2943 rtl_hw_start(dev); |
|
2944 |
|
2945 rtl8169_request_timer(dev); |
|
2946 |
|
2947 out: |
|
2948 return ret; |
|
2949 } |
|
2950 |
|
2951 static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc) |
|
2952 { |
|
2953 desc->addr = cpu_to_le64(0x0badbadbadbadbadull); |
|
2954 desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask); |
|
2955 } |
|
2956 |
|
2957 static void rtl8169_free_rx_skb(struct rtl8169_private *tp, |
|
2958 struct sk_buff **sk_buff, struct RxDesc *desc) |
|
2959 { |
|
2960 struct pci_dev *pdev = tp->pci_dev; |
|
2961 |
|
2962 pci_unmap_single(pdev, le64_to_cpu(desc->addr), tp->rx_buf_sz, |
|
2963 PCI_DMA_FROMDEVICE); |
|
2964 dev_kfree_skb(*sk_buff); |
|
2965 *sk_buff = NULL; |
|
2966 rtl8169_make_unusable_by_asic(desc); |
|
2967 } |
|
2968 |
|
2969 static inline void rtl8169_mark_to_asic(struct RxDesc *desc, u32 rx_buf_sz) |
|
2970 { |
|
2971 u32 eor = le32_to_cpu(desc->opts1) & RingEnd; |
|
2972 |
|
2973 desc->opts1 = cpu_to_le32(DescOwn | eor | rx_buf_sz); |
|
2974 } |
|
2975 |
|
2976 static inline void rtl8169_map_to_asic(struct RxDesc *desc, dma_addr_t mapping, |
|
2977 u32 rx_buf_sz) |
|
2978 { |
|
2979 desc->addr = cpu_to_le64(mapping); |
|
2980 wmb(); |
|
2981 rtl8169_mark_to_asic(desc, rx_buf_sz); |
|
2982 } |
|
2983 |
|
2984 static struct sk_buff *rtl8169_alloc_rx_skb(struct pci_dev *pdev, |
|
2985 struct net_device *dev, |
|
2986 struct RxDesc *desc, int rx_buf_sz, |
|
2987 unsigned int align) |
|
2988 { |
|
2989 struct sk_buff *skb; |
|
2990 dma_addr_t mapping; |
|
2991 unsigned int pad; |
|
2992 |
|
2993 pad = align ? align : NET_IP_ALIGN; |
|
2994 |
|
2995 skb = netdev_alloc_skb(dev, rx_buf_sz + pad); |
|
2996 if (!skb) |
|
2997 goto err_out; |
|
2998 |
|
2999 skb_reserve(skb, align ? ((pad - 1) & (unsigned long)skb->data) : pad); |
|
3000 |
|
3001 mapping = pci_map_single(pdev, skb->data, rx_buf_sz, |
|
3002 PCI_DMA_FROMDEVICE); |
|
3003 |
|
3004 rtl8169_map_to_asic(desc, mapping, rx_buf_sz); |
|
3005 out: |
|
3006 return skb; |
|
3007 |
|
3008 err_out: |
|
3009 rtl8169_make_unusable_by_asic(desc); |
|
3010 goto out; |
|
3011 } |
|
3012 |
|
3013 static void rtl8169_rx_clear(struct rtl8169_private *tp) |
|
3014 { |
|
3015 unsigned int i; |
|
3016 |
|
3017 for (i = 0; i < NUM_RX_DESC; i++) { |
|
3018 if (tp->Rx_skbuff[i]) { |
|
3019 rtl8169_free_rx_skb(tp, tp->Rx_skbuff + i, |
|
3020 tp->RxDescArray + i); |
|
3021 } |
|
3022 } |
|
3023 } |
|
3024 |
|
3025 static u32 rtl8169_rx_fill(struct rtl8169_private *tp, struct net_device *dev, |
|
3026 u32 start, u32 end) |
|
3027 { |
|
3028 u32 cur; |
|
3029 |
|
3030 for (cur = start; end - cur != 0; cur++) { |
|
3031 struct sk_buff *skb; |
|
3032 unsigned int i = cur % NUM_RX_DESC; |
|
3033 |
|
3034 WARN_ON((s32)(end - cur) < 0); |
|
3035 |
|
3036 if (tp->Rx_skbuff[i]) |
|
3037 continue; |
|
3038 |
|
3039 skb = rtl8169_alloc_rx_skb(tp->pci_dev, dev, |
|
3040 tp->RxDescArray + i, |
|
3041 tp->rx_buf_sz, tp->align); |
|
3042 if (!skb) |
|
3043 break; |
|
3044 |
|
3045 tp->Rx_skbuff[i] = skb; |
|
3046 } |
|
3047 return cur - start; |
|
3048 } |
|
3049 |
|
3050 static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc) |
|
3051 { |
|
3052 desc->opts1 |= cpu_to_le32(RingEnd); |
|
3053 } |
|
3054 |
|
3055 static void rtl8169_init_ring_indexes(struct rtl8169_private *tp) |
|
3056 { |
|
3057 tp->dirty_tx = tp->dirty_rx = tp->cur_tx = tp->cur_rx = 0; |
|
3058 } |
|
3059 |
|
3060 static int rtl8169_init_ring(struct net_device *dev) |
|
3061 { |
|
3062 struct rtl8169_private *tp = netdev_priv(dev); |
|
3063 |
|
3064 rtl8169_init_ring_indexes(tp); |
|
3065 |
|
3066 memset(tp->tx_skb, 0x0, NUM_TX_DESC * sizeof(struct ring_info)); |
|
3067 memset(tp->Rx_skbuff, 0x0, NUM_RX_DESC * sizeof(struct sk_buff *)); |
|
3068 |
|
3069 if (rtl8169_rx_fill(tp, dev, 0, NUM_RX_DESC) != NUM_RX_DESC) |
|
3070 goto err_out; |
|
3071 |
|
3072 rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1); |
|
3073 |
|
3074 return 0; |
|
3075 |
|
3076 err_out: |
|
3077 rtl8169_rx_clear(tp); |
|
3078 return -ENOMEM; |
|
3079 } |
|
3080 |
|
3081 static void rtl8169_unmap_tx_skb(struct pci_dev *pdev, struct ring_info *tx_skb, |
|
3082 struct TxDesc *desc) |
|
3083 { |
|
3084 unsigned int len = tx_skb->len; |
|
3085 |
|
3086 pci_unmap_single(pdev, le64_to_cpu(desc->addr), len, PCI_DMA_TODEVICE); |
|
3087 desc->opts1 = 0x00; |
|
3088 desc->opts2 = 0x00; |
|
3089 desc->addr = 0x00; |
|
3090 tx_skb->len = 0; |
|
3091 } |
|
3092 |
|
3093 static void rtl8169_tx_clear(struct rtl8169_private *tp) |
|
3094 { |
|
3095 unsigned int i; |
|
3096 |
|
3097 for (i = tp->dirty_tx; i < tp->dirty_tx + NUM_TX_DESC; i++) { |
|
3098 unsigned int entry = i % NUM_TX_DESC; |
|
3099 struct ring_info *tx_skb = tp->tx_skb + entry; |
|
3100 unsigned int len = tx_skb->len; |
|
3101 |
|
3102 if (len) { |
|
3103 struct sk_buff *skb = tx_skb->skb; |
|
3104 |
|
3105 rtl8169_unmap_tx_skb(tp->pci_dev, tx_skb, |
|
3106 tp->TxDescArray + entry); |
|
3107 if (skb) { |
|
3108 if (!tp->ecdev) |
|
3109 dev_kfree_skb(skb); |
|
3110 tx_skb->skb = NULL; |
|
3111 } |
|
3112 tp->dev->stats.tx_dropped++; |
|
3113 } |
|
3114 } |
|
3115 tp->cur_tx = tp->dirty_tx = 0; |
|
3116 } |
|
3117 |
|
3118 static void rtl8169_schedule_work(struct net_device *dev, work_func_t task) |
|
3119 { |
|
3120 struct rtl8169_private *tp = netdev_priv(dev); |
|
3121 |
|
3122 PREPARE_DELAYED_WORK(&tp->task, task); |
|
3123 schedule_delayed_work(&tp->task, 4); |
|
3124 } |
|
3125 |
|
3126 static void rtl8169_wait_for_quiescence(struct net_device *dev) |
|
3127 { |
|
3128 struct rtl8169_private *tp = netdev_priv(dev); |
|
3129 void __iomem *ioaddr = tp->mmio_addr; |
|
3130 |
|
3131 synchronize_irq(dev->irq); |
|
3132 |
|
3133 /* Wait for any pending NAPI task to complete */ |
|
3134 napi_disable(&tp->napi); |
|
3135 |
|
3136 rtl8169_irq_mask_and_ack(ioaddr); |
|
3137 |
|
3138 tp->intr_mask = 0xffff; |
|
3139 RTL_W16(IntrMask, tp->intr_event); |
|
3140 napi_enable(&tp->napi); |
|
3141 } |
|
3142 |
|
3143 static void rtl8169_reinit_task(struct work_struct *work) |
|
3144 { |
|
3145 struct rtl8169_private *tp = |
|
3146 container_of(work, struct rtl8169_private, task.work); |
|
3147 struct net_device *dev = tp->dev; |
|
3148 int ret; |
|
3149 |
|
3150 rtnl_lock(); |
|
3151 |
|
3152 if (!netif_running(dev)) |
|
3153 goto out_unlock; |
|
3154 |
|
3155 rtl8169_wait_for_quiescence(dev); |
|
3156 rtl8169_close(dev); |
|
3157 |
|
3158 ret = rtl8169_open(dev); |
|
3159 if (unlikely(ret < 0)) { |
|
3160 if (net_ratelimit() && netif_msg_drv(tp)) { |
|
3161 printk(KERN_ERR PFX "%s: reinit failure (status = %d)." |
|
3162 " Rescheduling.\n", dev->name, ret); |
|
3163 } |
|
3164 rtl8169_schedule_work(dev, rtl8169_reinit_task); |
|
3165 } |
|
3166 |
|
3167 out_unlock: |
|
3168 rtnl_unlock(); |
|
3169 } |
|
3170 |
|
3171 static void rtl8169_reset_task(struct work_struct *work) |
|
3172 { |
|
3173 struct rtl8169_private *tp = |
|
3174 container_of(work, struct rtl8169_private, task.work); |
|
3175 struct net_device *dev = tp->dev; |
|
3176 |
|
3177 rtnl_lock(); |
|
3178 |
|
3179 if (!netif_running(dev)) |
|
3180 goto out_unlock; |
|
3181 |
|
3182 rtl8169_wait_for_quiescence(dev); |
|
3183 |
|
3184 rtl8169_rx_interrupt(dev, tp, tp->mmio_addr, ~(u32)0); |
|
3185 rtl8169_tx_clear(tp); |
|
3186 |
|
3187 if (tp->dirty_rx == tp->cur_rx) { |
|
3188 rtl8169_init_ring_indexes(tp); |
|
3189 rtl_hw_start(dev); |
|
3190 netif_wake_queue(dev); |
|
3191 rtl8169_check_link_status(dev, tp, tp->mmio_addr); |
|
3192 } else { |
|
3193 if (net_ratelimit() && netif_msg_intr(tp)) { |
|
3194 printk(KERN_EMERG PFX "%s: Rx buffers shortage\n", |
|
3195 dev->name); |
|
3196 } |
|
3197 rtl8169_schedule_work(dev, rtl8169_reset_task); |
|
3198 } |
|
3199 |
|
3200 out_unlock: |
|
3201 rtnl_unlock(); |
|
3202 } |
|
3203 |
|
3204 static void rtl8169_tx_timeout(struct net_device *dev) |
|
3205 { |
|
3206 struct rtl8169_private *tp = netdev_priv(dev); |
|
3207 |
|
3208 if (tp->ecdev) |
|
3209 return; |
|
3210 |
|
3211 rtl8169_hw_reset(tp->mmio_addr); |
|
3212 |
|
3213 /* Let's wait a bit while any (async) irq lands on */ |
|
3214 rtl8169_schedule_work(dev, rtl8169_reset_task); |
|
3215 } |
|
3216 |
|
3217 static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb, |
|
3218 u32 opts1) |
|
3219 { |
|
3220 struct skb_shared_info *info = skb_shinfo(skb); |
|
3221 unsigned int cur_frag, entry; |
|
3222 struct TxDesc * uninitialized_var(txd); |
|
3223 |
|
3224 entry = tp->cur_tx; |
|
3225 for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { |
|
3226 skb_frag_t *frag = info->frags + cur_frag; |
|
3227 dma_addr_t mapping; |
|
3228 u32 status, len; |
|
3229 void *addr; |
|
3230 |
|
3231 entry = (entry + 1) % NUM_TX_DESC; |
|
3232 |
|
3233 txd = tp->TxDescArray + entry; |
|
3234 len = frag->size; |
|
3235 addr = ((void *) page_address(frag->page)) + frag->page_offset; |
|
3236 mapping = pci_map_single(tp->pci_dev, addr, len, PCI_DMA_TODEVICE); |
|
3237 |
|
3238 /* anti gcc 2.95.3 bugware (sic) */ |
|
3239 status = opts1 | len | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
|
3240 |
|
3241 txd->opts1 = cpu_to_le32(status); |
|
3242 txd->addr = cpu_to_le64(mapping); |
|
3243 |
|
3244 tp->tx_skb[entry].len = len; |
|
3245 } |
|
3246 |
|
3247 if (cur_frag) { |
|
3248 tp->tx_skb[entry].skb = skb; |
|
3249 txd->opts1 |= cpu_to_le32(LastFrag); |
|
3250 } |
|
3251 |
|
3252 return cur_frag; |
|
3253 } |
|
3254 |
|
3255 static inline u32 rtl8169_tso_csum(struct sk_buff *skb, struct net_device *dev) |
|
3256 { |
|
3257 if (dev->features & NETIF_F_TSO) { |
|
3258 u32 mss = skb_shinfo(skb)->gso_size; |
|
3259 |
|
3260 if (mss) |
|
3261 return LargeSend | ((mss & MSSMask) << MSSShift); |
|
3262 } |
|
3263 if (skb->ip_summed == CHECKSUM_PARTIAL) { |
|
3264 const struct iphdr *ip = ip_hdr(skb); |
|
3265 |
|
3266 if (ip->protocol == IPPROTO_TCP) |
|
3267 return IPCS | TCPCS; |
|
3268 else if (ip->protocol == IPPROTO_UDP) |
|
3269 return IPCS | UDPCS; |
|
3270 WARN_ON(1); /* we need a WARN() */ |
|
3271 } |
|
3272 return 0; |
|
3273 } |
|
3274 |
|
3275 static int rtl8169_start_xmit(struct sk_buff *skb, struct net_device *dev) |
|
3276 { |
|
3277 struct rtl8169_private *tp = netdev_priv(dev); |
|
3278 unsigned int frags, entry = tp->cur_tx % NUM_TX_DESC; |
|
3279 struct TxDesc *txd = tp->TxDescArray + entry; |
|
3280 void __iomem *ioaddr = tp->mmio_addr; |
|
3281 dma_addr_t mapping; |
|
3282 u32 status, len; |
|
3283 u32 opts1; |
|
3284 int ret = NETDEV_TX_OK; |
|
3285 |
|
3286 if (unlikely(TX_BUFFS_AVAIL(tp) < skb_shinfo(skb)->nr_frags)) { |
|
3287 if (netif_msg_drv(tp)) { |
|
3288 printk(KERN_ERR |
|
3289 "%s: BUG! Tx Ring full when queue awake!\n", |
|
3290 dev->name); |
|
3291 } |
|
3292 goto err_stop; |
|
3293 } |
|
3294 |
|
3295 if (unlikely(le32_to_cpu(txd->opts1) & DescOwn)) |
|
3296 goto err_stop; |
|
3297 |
|
3298 opts1 = DescOwn | rtl8169_tso_csum(skb, dev); |
|
3299 |
|
3300 frags = rtl8169_xmit_frags(tp, skb, opts1); |
|
3301 if (frags) { |
|
3302 len = skb_headlen(skb); |
|
3303 opts1 |= FirstFrag; |
|
3304 } else { |
|
3305 len = skb->len; |
|
3306 opts1 |= FirstFrag | LastFrag; |
|
3307 tp->tx_skb[entry].skb = skb; |
|
3308 } |
|
3309 |
|
3310 mapping = pci_map_single(tp->pci_dev, skb->data, len, PCI_DMA_TODEVICE); |
|
3311 |
|
3312 tp->tx_skb[entry].len = len; |
|
3313 txd->addr = cpu_to_le64(mapping); |
|
3314 txd->opts2 = cpu_to_le32(rtl8169_tx_vlan_tag(tp, skb)); |
|
3315 |
|
3316 wmb(); |
|
3317 |
|
3318 /* anti gcc 2.95.3 bugware (sic) */ |
|
3319 status = opts1 | len | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
|
3320 txd->opts1 = cpu_to_le32(status); |
|
3321 |
|
3322 tp->cur_tx += frags + 1; |
|
3323 |
|
3324 smp_wmb(); |
|
3325 |
|
3326 RTL_W8(TxPoll, NPQ); /* set polling bit */ |
|
3327 |
|
3328 if (!tp->ecdev) { |
|
3329 if (TX_BUFFS_AVAIL(tp) < MAX_SKB_FRAGS) { |
|
3330 netif_stop_queue(dev); |
|
3331 smp_rmb(); |
|
3332 if (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS) |
|
3333 netif_wake_queue(dev); |
|
3334 } |
|
3335 } |
|
3336 |
|
3337 out: |
|
3338 return ret; |
|
3339 |
|
3340 err_stop: |
|
3341 if (!tp->ecdev) |
|
3342 netif_stop_queue(dev); |
|
3343 ret = NETDEV_TX_BUSY; |
|
3344 dev->stats.tx_dropped++; |
|
3345 goto out; |
|
3346 } |
|
3347 |
|
3348 static void rtl8169_pcierr_interrupt(struct net_device *dev) |
|
3349 { |
|
3350 struct rtl8169_private *tp = netdev_priv(dev); |
|
3351 struct pci_dev *pdev = tp->pci_dev; |
|
3352 void __iomem *ioaddr = tp->mmio_addr; |
|
3353 u16 pci_status, pci_cmd; |
|
3354 |
|
3355 pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); |
|
3356 pci_read_config_word(pdev, PCI_STATUS, &pci_status); |
|
3357 |
|
3358 if (netif_msg_intr(tp)) { |
|
3359 printk(KERN_ERR |
|
3360 "%s: PCI error (cmd = 0x%04x, status = 0x%04x).\n", |
|
3361 dev->name, pci_cmd, pci_status); |
|
3362 } |
|
3363 |
|
3364 /* |
|
3365 * The recovery sequence below admits a very elaborated explanation: |
|
3366 * - it seems to work; |
|
3367 * - I did not see what else could be done; |
|
3368 * - it makes iop3xx happy. |
|
3369 * |
|
3370 * Feel free to adjust to your needs. |
|
3371 */ |
|
3372 if (pdev->broken_parity_status) |
|
3373 pci_cmd &= ~PCI_COMMAND_PARITY; |
|
3374 else |
|
3375 pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; |
|
3376 |
|
3377 pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); |
|
3378 |
|
3379 pci_write_config_word(pdev, PCI_STATUS, |
|
3380 pci_status & (PCI_STATUS_DETECTED_PARITY | |
|
3381 PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT | |
|
3382 PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT)); |
|
3383 |
|
3384 /* The infamous DAC f*ckup only happens at boot time */ |
|
3385 if ((tp->cp_cmd & PCIDAC) && !tp->dirty_rx && !tp->cur_rx) { |
|
3386 if (netif_msg_intr(tp)) |
|
3387 printk(KERN_INFO "%s: disabling PCI DAC.\n", dev->name); |
|
3388 tp->cp_cmd &= ~PCIDAC; |
|
3389 RTL_W16(CPlusCmd, tp->cp_cmd); |
|
3390 dev->features &= ~NETIF_F_HIGHDMA; |
|
3391 } |
|
3392 |
|
3393 rtl8169_hw_reset(ioaddr); |
|
3394 |
|
3395 rtl8169_schedule_work(dev, rtl8169_reinit_task); |
|
3396 } |
|
3397 |
|
3398 static void rtl8169_tx_interrupt(struct net_device *dev, |
|
3399 struct rtl8169_private *tp, |
|
3400 void __iomem *ioaddr) |
|
3401 { |
|
3402 unsigned int dirty_tx, tx_left; |
|
3403 |
|
3404 dirty_tx = tp->dirty_tx; |
|
3405 smp_rmb(); |
|
3406 tx_left = tp->cur_tx - dirty_tx; |
|
3407 |
|
3408 while (tx_left > 0) { |
|
3409 unsigned int entry = dirty_tx % NUM_TX_DESC; |
|
3410 struct ring_info *tx_skb = tp->tx_skb + entry; |
|
3411 u32 len = tx_skb->len; |
|
3412 u32 status; |
|
3413 |
|
3414 rmb(); |
|
3415 status = le32_to_cpu(tp->TxDescArray[entry].opts1); |
|
3416 if (status & DescOwn) |
|
3417 break; |
|
3418 |
|
3419 dev->stats.tx_bytes += len; |
|
3420 dev->stats.tx_packets++; |
|
3421 |
|
3422 rtl8169_unmap_tx_skb(tp->pci_dev, tx_skb, tp->TxDescArray + entry); |
|
3423 |
|
3424 if (status & LastFrag) { |
|
3425 if (!tp->ecdev) |
|
3426 dev_kfree_skb(tx_skb->skb); |
|
3427 tx_skb->skb = NULL; |
|
3428 } |
|
3429 dirty_tx++; |
|
3430 tx_left--; |
|
3431 } |
|
3432 |
|
3433 if (tp->dirty_tx != dirty_tx) { |
|
3434 tp->dirty_tx = dirty_tx; |
|
3435 smp_wmb(); |
|
3436 if (!tp->ecdev && netif_queue_stopped(dev) && |
|
3437 (TX_BUFFS_AVAIL(tp) >= MAX_SKB_FRAGS)) { |
|
3438 netif_wake_queue(dev); |
|
3439 } |
|
3440 /* |
|
3441 * 8168 hack: TxPoll requests are lost when the Tx packets are |
|
3442 * too close. Let's kick an extra TxPoll request when a burst |
|
3443 * of start_xmit activity is detected (if it is not detected, |
|
3444 * it is slow enough). -- FR |
|
3445 */ |
|
3446 smp_rmb(); |
|
3447 if (tp->cur_tx != dirty_tx) |
|
3448 RTL_W8(TxPoll, NPQ); |
|
3449 } |
|
3450 } |
|
3451 |
|
3452 static inline int rtl8169_fragmented_frame(u32 status) |
|
3453 { |
|
3454 return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag); |
|
3455 } |
|
3456 |
|
3457 static inline void rtl8169_rx_csum(struct sk_buff *skb, struct RxDesc *desc) |
|
3458 { |
|
3459 u32 opts1 = le32_to_cpu(desc->opts1); |
|
3460 u32 status = opts1 & RxProtoMask; |
|
3461 |
|
3462 if (((status == RxProtoTCP) && !(opts1 & TCPFail)) || |
|
3463 ((status == RxProtoUDP) && !(opts1 & UDPFail)) || |
|
3464 ((status == RxProtoIP) && !(opts1 & IPFail))) |
|
3465 skb->ip_summed = CHECKSUM_UNNECESSARY; |
|
3466 else |
|
3467 skb->ip_summed = CHECKSUM_NONE; |
|
3468 } |
|
3469 |
|
3470 static inline bool rtl8169_try_rx_copy(struct sk_buff **sk_buff, |
|
3471 struct rtl8169_private *tp, int pkt_size, |
|
3472 dma_addr_t addr) |
|
3473 { |
|
3474 struct sk_buff *skb; |
|
3475 bool done = false; |
|
3476 |
|
3477 if (pkt_size >= rx_copybreak) |
|
3478 goto out; |
|
3479 |
|
3480 skb = netdev_alloc_skb(tp->dev, pkt_size + NET_IP_ALIGN); |
|
3481 if (!skb) |
|
3482 goto out; |
|
3483 |
|
3484 pci_dma_sync_single_for_cpu(tp->pci_dev, addr, pkt_size, |
|
3485 PCI_DMA_FROMDEVICE); |
|
3486 skb_reserve(skb, NET_IP_ALIGN); |
|
3487 skb_copy_from_linear_data(*sk_buff, skb->data, pkt_size); |
|
3488 *sk_buff = skb; |
|
3489 done = true; |
|
3490 out: |
|
3491 return done; |
|
3492 } |
|
3493 |
|
3494 static int rtl8169_rx_interrupt(struct net_device *dev, |
|
3495 struct rtl8169_private *tp, |
|
3496 void __iomem *ioaddr, u32 budget) |
|
3497 { |
|
3498 unsigned int cur_rx, rx_left; |
|
3499 unsigned int delta, count; |
|
3500 |
|
3501 cur_rx = tp->cur_rx; |
|
3502 rx_left = NUM_RX_DESC + tp->dirty_rx - cur_rx; |
|
3503 rx_left = min(rx_left, budget); |
|
3504 |
|
3505 for (; rx_left > 0; rx_left--, cur_rx++) { |
|
3506 unsigned int entry = cur_rx % NUM_RX_DESC; |
|
3507 struct RxDesc *desc = tp->RxDescArray + entry; |
|
3508 u32 status; |
|
3509 |
|
3510 rmb(); |
|
3511 status = le32_to_cpu(desc->opts1); |
|
3512 |
|
3513 if (status & DescOwn) |
|
3514 break; |
|
3515 if (unlikely(status & RxRES)) { |
|
3516 if (netif_msg_rx_err(tp)) { |
|
3517 printk(KERN_INFO |
|
3518 "%s: Rx ERROR. status = %08x\n", |
|
3519 dev->name, status); |
|
3520 } |
|
3521 dev->stats.rx_errors++; |
|
3522 if (status & (RxRWT | RxRUNT)) |
|
3523 dev->stats.rx_length_errors++; |
|
3524 if (status & RxCRC) |
|
3525 dev->stats.rx_crc_errors++; |
|
3526 if (status & RxFOVF) { |
|
3527 if (!tp->ecdev) |
|
3528 rtl8169_schedule_work(dev, rtl8169_reset_task); |
|
3529 dev->stats.rx_fifo_errors++; |
|
3530 } |
|
3531 rtl8169_mark_to_asic(desc, tp->rx_buf_sz); |
|
3532 } else { |
|
3533 struct sk_buff *skb = tp->Rx_skbuff[entry]; |
|
3534 dma_addr_t addr = le64_to_cpu(desc->addr); |
|
3535 int pkt_size = (status & 0x00001FFF) - 4; |
|
3536 struct pci_dev *pdev = tp->pci_dev; |
|
3537 |
|
3538 /* |
|
3539 * The driver does not support incoming fragmented |
|
3540 * frames. They are seen as a symptom of over-mtu |
|
3541 * sized frames. |
|
3542 */ |
|
3543 if (unlikely(rtl8169_fragmented_frame(status))) { |
|
3544 dev->stats.rx_dropped++; |
|
3545 dev->stats.rx_length_errors++; |
|
3546 rtl8169_mark_to_asic(desc, tp->rx_buf_sz); |
|
3547 continue; |
|
3548 } |
|
3549 |
|
3550 rtl8169_rx_csum(skb, desc); |
|
3551 |
|
3552 if (tp->ecdev) { |
|
3553 pci_dma_sync_single_for_cpu(pdev, addr, pkt_size, |
|
3554 PCI_DMA_FROMDEVICE); |
|
3555 |
|
3556 ecdev_receive(tp->ecdev, skb->data, pkt_size); |
|
3557 |
|
3558 pci_dma_sync_single_for_device(pdev, addr, |
|
3559 pkt_size, PCI_DMA_FROMDEVICE); |
|
3560 rtl8169_mark_to_asic(desc, tp->rx_buf_sz); |
|
3561 |
|
3562 // No need to detect link status as |
|
3563 // long as frames are received: Reset watchdog. |
|
3564 tp->ec_watchdog_jiffies = jiffies; |
|
3565 } else { |
|
3566 if (rtl8169_try_rx_copy(&skb, tp, pkt_size, addr)) { |
|
3567 pci_dma_sync_single_for_device(pdev, addr, |
|
3568 pkt_size, PCI_DMA_FROMDEVICE); |
|
3569 rtl8169_mark_to_asic(desc, tp->rx_buf_sz); |
|
3570 } else { |
|
3571 pci_unmap_single(pdev, addr, tp->rx_buf_sz, |
|
3572 PCI_DMA_FROMDEVICE); |
|
3573 tp->Rx_skbuff[entry] = NULL; |
|
3574 } |
|
3575 |
|
3576 skb_put(skb, pkt_size); |
|
3577 skb->protocol = eth_type_trans(skb, dev); |
|
3578 |
|
3579 if (rtl8169_rx_vlan_skb(tp, desc, skb) < 0) |
|
3580 netif_receive_skb(skb); |
|
3581 } |
|
3582 |
|
3583 dev->stats.rx_bytes += pkt_size; |
|
3584 dev->stats.rx_packets++; |
|
3585 } |
|
3586 |
|
3587 /* Work around for AMD plateform. */ |
|
3588 if ((desc->opts2 & cpu_to_le32(0xfffe000)) && |
|
3589 (tp->mac_version == RTL_GIGA_MAC_VER_05)) { |
|
3590 desc->opts2 = 0; |
|
3591 cur_rx++; |
|
3592 } |
|
3593 } |
|
3594 |
|
3595 count = cur_rx - tp->cur_rx; |
|
3596 tp->cur_rx = cur_rx; |
|
3597 |
|
3598 if (tp->ecdev) { |
|
3599 /* descriptors are cleaned up immediately. */ |
|
3600 tp->dirty_rx = tp->cur_rx; |
|
3601 } else { |
|
3602 delta = rtl8169_rx_fill(tp, dev, tp->dirty_rx, tp->cur_rx); |
|
3603 if (!delta && count && netif_msg_intr(tp)) |
|
3604 printk(KERN_INFO "%s: no Rx buffer allocated\n", dev->name); |
|
3605 tp->dirty_rx += delta; |
|
3606 |
|
3607 /* |
|
3608 * FIXME: until there is periodic timer to try and refill the ring, |
|
3609 * a temporary shortage may definitely kill the Rx process. |
|
3610 * - disable the asic to try and avoid an overflow and kick it again |
|
3611 * after refill ? |
|
3612 * - how do others driver handle this condition (Uh oh...). |
|
3613 */ |
|
3614 if ((tp->dirty_rx + NUM_RX_DESC == tp->cur_rx) && netif_msg_intr(tp)) |
|
3615 printk(KERN_EMERG "%s: Rx buffers exhausted\n", dev->name); |
|
3616 } |
|
3617 |
|
3618 return count; |
|
3619 } |
|
3620 |
|
3621 static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) |
|
3622 { |
|
3623 struct net_device *dev = dev_instance; |
|
3624 struct rtl8169_private *tp = netdev_priv(dev); |
|
3625 void __iomem *ioaddr = tp->mmio_addr; |
|
3626 int handled = 0; |
|
3627 int status; |
|
3628 |
|
3629 /* loop handling interrupts until we have no new ones or |
|
3630 * we hit a invalid/hotplug case. |
|
3631 */ |
|
3632 status = RTL_R16(IntrStatus); |
|
3633 while (status && status != 0xffff) { |
|
3634 handled = 1; |
|
3635 |
|
3636 /* Handle all of the error cases first. These will reset |
|
3637 * the chip, so just exit the loop. |
|
3638 */ |
|
3639 if (unlikely(!tp->ecdev && !netif_running(dev))) { |
|
3640 rtl8169_asic_down(ioaddr); |
|
3641 break; |
|
3642 } |
|
3643 |
|
3644 /* Work around for rx fifo overflow */ |
|
3645 if (unlikely(status & RxFIFOOver) && |
|
3646 (tp->mac_version == RTL_GIGA_MAC_VER_11)) { |
|
3647 netif_stop_queue(dev); |
|
3648 rtl8169_tx_timeout(dev); |
|
3649 break; |
|
3650 } |
|
3651 |
|
3652 if (unlikely(status & SYSErr)) { |
|
3653 rtl8169_pcierr_interrupt(dev); |
|
3654 break; |
|
3655 } |
|
3656 |
|
3657 if (status & LinkChg) |
|
3658 rtl8169_check_link_status(dev, tp, ioaddr); |
|
3659 |
|
3660 /* We need to see the lastest version of tp->intr_mask to |
|
3661 * avoid ignoring an MSI interrupt and having to wait for |
|
3662 * another event which may never come. |
|
3663 */ |
|
3664 smp_rmb(); |
|
3665 if (status & tp->intr_mask & tp->napi_event) { |
|
3666 RTL_W16(IntrMask, tp->intr_event & ~tp->napi_event); |
|
3667 tp->intr_mask = ~tp->napi_event; |
|
3668 |
|
3669 if (likely(napi_schedule_prep(&tp->napi))) |
|
3670 __napi_schedule(&tp->napi); |
|
3671 else if (netif_msg_intr(tp)) { |
|
3672 printk(KERN_INFO "%s: interrupt %04x in poll\n", |
|
3673 dev->name, status); |
|
3674 } |
|
3675 } |
|
3676 |
|
3677 /* We only get a new MSI interrupt when all active irq |
|
3678 * sources on the chip have been acknowledged. So, ack |
|
3679 * everything we've seen and check if new sources have become |
|
3680 * active to avoid blocking all interrupts from the chip. |
|
3681 */ |
|
3682 RTL_W16(IntrStatus, |
|
3683 (status & RxFIFOOver) ? (status | RxOverflow) : status); |
|
3684 status = RTL_R16(IntrStatus); |
|
3685 } |
|
3686 |
|
3687 return IRQ_RETVAL(handled); |
|
3688 } |
|
3689 |
|
3690 static void ec_poll(struct net_device *dev) |
|
3691 { |
|
3692 struct rtl8169_private *tp = netdev_priv(dev); |
|
3693 struct pci_dev *pdev = tp->pci_dev; |
|
3694 |
|
3695 rtl8169_interrupt(pdev->irq, dev); |
|
3696 rtl8169_rx_interrupt(dev, tp, tp->mmio_addr, 100); // FIXME |
|
3697 rtl8169_tx_interrupt(dev, tp, tp->mmio_addr); |
|
3698 |
|
3699 if (jiffies - tp->ec_watchdog_jiffies >= 2 * HZ) { |
|
3700 rtl8169_phy_timer((unsigned long) dev); |
|
3701 tp->ec_watchdog_jiffies = jiffies; |
|
3702 } |
|
3703 } |
|
3704 |
|
3705 static int rtl8169_poll(struct napi_struct *napi, int budget) |
|
3706 { |
|
3707 struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); |
|
3708 struct net_device *dev = tp->dev; |
|
3709 void __iomem *ioaddr = tp->mmio_addr; |
|
3710 int work_done; |
|
3711 |
|
3712 work_done = rtl8169_rx_interrupt(dev, tp, ioaddr, (u32) budget); |
|
3713 rtl8169_tx_interrupt(dev, tp, ioaddr); |
|
3714 |
|
3715 if (work_done < budget) { |
|
3716 napi_complete(napi); |
|
3717 |
|
3718 /* We need for force the visibility of tp->intr_mask |
|
3719 * for other CPUs, as we can loose an MSI interrupt |
|
3720 * and potentially wait for a retransmit timeout if we don't. |
|
3721 * The posted write to IntrMask is safe, as it will |
|
3722 * eventually make it to the chip and we won't loose anything |
|
3723 * until it does. |
|
3724 */ |
|
3725 tp->intr_mask = 0xffff; |
|
3726 smp_wmb(); |
|
3727 RTL_W16(IntrMask, tp->intr_event); |
|
3728 } |
|
3729 |
|
3730 return work_done; |
|
3731 } |
|
3732 |
|
3733 static void rtl8169_rx_missed(struct net_device *dev, void __iomem *ioaddr) |
|
3734 { |
|
3735 struct rtl8169_private *tp = netdev_priv(dev); |
|
3736 |
|
3737 if (tp->mac_version > RTL_GIGA_MAC_VER_06) |
|
3738 return; |
|
3739 |
|
3740 dev->stats.rx_missed_errors += (RTL_R32(RxMissed) & 0xffffff); |
|
3741 RTL_W32(RxMissed, 0); |
|
3742 } |
|
3743 |
|
3744 static void rtl8169_down(struct net_device *dev) |
|
3745 { |
|
3746 struct rtl8169_private *tp = netdev_priv(dev); |
|
3747 void __iomem *ioaddr = tp->mmio_addr; |
|
3748 unsigned int intrmask; |
|
3749 |
|
3750 rtl8169_delete_timer(dev); |
|
3751 |
|
3752 if (!tp->ecdev) { |
|
3753 netif_stop_queue(dev); |
|
3754 |
|
3755 napi_disable(&tp->napi); |
|
3756 |
|
3757 } |
|
3758 core_down: |
|
3759 if (!tp->ecdev) |
|
3760 spin_lock_irq(&tp->lock); |
|
3761 |
|
3762 rtl8169_asic_down(ioaddr); |
|
3763 |
|
3764 rtl8169_rx_missed(dev, ioaddr); |
|
3765 |
|
3766 if (!tp->ecdev) |
|
3767 spin_unlock_irq(&tp->lock); |
|
3768 |
|
3769 if (!tp->ecdev) |
|
3770 synchronize_irq(dev->irq); |
|
3771 |
|
3772 /* Give a racing hard_start_xmit a few cycles to complete. */ |
|
3773 synchronize_sched(); /* FIXME: should this be synchronize_irq()? */ |
|
3774 |
|
3775 /* |
|
3776 * And now for the 50k$ question: are IRQ disabled or not ? |
|
3777 * |
|
3778 * Two paths lead here: |
|
3779 * 1) dev->close |
|
3780 * -> netif_running() is available to sync the current code and the |
|
3781 * IRQ handler. See rtl8169_interrupt for details. |
|
3782 * 2) dev->change_mtu |
|
3783 * -> rtl8169_poll can not be issued again and re-enable the |
|
3784 * interruptions. Let's simply issue the IRQ down sequence again. |
|
3785 * |
|
3786 * No loop if hotpluged or major error (0xffff). |
|
3787 */ |
|
3788 intrmask = RTL_R16(IntrMask); |
|
3789 if (intrmask && (intrmask != 0xffff)) |
|
3790 goto core_down; |
|
3791 |
|
3792 rtl8169_tx_clear(tp); |
|
3793 |
|
3794 rtl8169_rx_clear(tp); |
|
3795 } |
|
3796 |
|
3797 static int rtl8169_close(struct net_device *dev) |
|
3798 { |
|
3799 struct rtl8169_private *tp = netdev_priv(dev); |
|
3800 struct pci_dev *pdev = tp->pci_dev; |
|
3801 |
|
3802 /* update counters before going down */ |
|
3803 rtl8169_update_counters(dev); |
|
3804 |
|
3805 rtl8169_down(dev); |
|
3806 |
|
3807 if (!tp->ecdev) |
|
3808 free_irq(dev->irq, dev); |
|
3809 |
|
3810 pci_free_consistent(pdev, R8169_RX_RING_BYTES, tp->RxDescArray, |
|
3811 tp->RxPhyAddr); |
|
3812 pci_free_consistent(pdev, R8169_TX_RING_BYTES, tp->TxDescArray, |
|
3813 tp->TxPhyAddr); |
|
3814 tp->TxDescArray = NULL; |
|
3815 tp->RxDescArray = NULL; |
|
3816 |
|
3817 return 0; |
|
3818 } |
|
3819 |
|
3820 static void rtl_set_rx_mode(struct net_device *dev) |
|
3821 { |
|
3822 struct rtl8169_private *tp = netdev_priv(dev); |
|
3823 void __iomem *ioaddr = tp->mmio_addr; |
|
3824 unsigned long flags; |
|
3825 u32 mc_filter[2]; /* Multicast hash filter */ |
|
3826 int rx_mode; |
|
3827 u32 tmp = 0; |
|
3828 |
|
3829 if (dev->flags & IFF_PROMISC) { |
|
3830 /* Unconditionally log net taps. */ |
|
3831 if (netif_msg_link(tp)) { |
|
3832 printk(KERN_NOTICE "%s: Promiscuous mode enabled.\n", |
|
3833 dev->name); |
|
3834 } |
|
3835 rx_mode = |
|
3836 AcceptBroadcast | AcceptMulticast | AcceptMyPhys | |
|
3837 AcceptAllPhys; |
|
3838 mc_filter[1] = mc_filter[0] = 0xffffffff; |
|
3839 } else if ((dev->mc_count > multicast_filter_limit) |
|
3840 || (dev->flags & IFF_ALLMULTI)) { |
|
3841 /* Too many to filter perfectly -- accept all multicasts. */ |
|
3842 rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; |
|
3843 mc_filter[1] = mc_filter[0] = 0xffffffff; |
|
3844 } else { |
|
3845 struct dev_mc_list *mclist; |
|
3846 unsigned int i; |
|
3847 |
|
3848 rx_mode = AcceptBroadcast | AcceptMyPhys; |
|
3849 mc_filter[1] = mc_filter[0] = 0; |
|
3850 for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count; |
|
3851 i++, mclist = mclist->next) { |
|
3852 int bit_nr = ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26; |
|
3853 mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); |
|
3854 rx_mode |= AcceptMulticast; |
|
3855 } |
|
3856 } |
|
3857 |
|
3858 spin_lock_irqsave(&tp->lock, flags); |
|
3859 |
|
3860 tmp = rtl8169_rx_config | rx_mode | |
|
3861 (RTL_R32(RxConfig) & rtl_chip_info[tp->chipset].RxConfigMask); |
|
3862 |
|
3863 if (tp->mac_version > RTL_GIGA_MAC_VER_06) { |
|
3864 u32 data = mc_filter[0]; |
|
3865 |
|
3866 mc_filter[0] = swab32(mc_filter[1]); |
|
3867 mc_filter[1] = swab32(data); |
|
3868 } |
|
3869 |
|
3870 RTL_W32(MAR0 + 0, mc_filter[0]); |
|
3871 RTL_W32(MAR0 + 4, mc_filter[1]); |
|
3872 |
|
3873 RTL_W32(RxConfig, tmp); |
|
3874 |
|
3875 spin_unlock_irqrestore(&tp->lock, flags); |
|
3876 } |
|
3877 |
|
3878 /** |
|
3879 * rtl8169_get_stats - Get rtl8169 read/write statistics |
|
3880 * @dev: The Ethernet Device to get statistics for |
|
3881 * |
|
3882 * Get TX/RX statistics for rtl8169 |
|
3883 */ |
|
3884 static struct net_device_stats *rtl8169_get_stats(struct net_device *dev) |
|
3885 { |
|
3886 struct rtl8169_private *tp = netdev_priv(dev); |
|
3887 void __iomem *ioaddr = tp->mmio_addr; |
|
3888 unsigned long flags; |
|
3889 |
|
3890 if (netif_running(dev)) { |
|
3891 spin_lock_irqsave(&tp->lock, flags); |
|
3892 rtl8169_rx_missed(dev, ioaddr); |
|
3893 spin_unlock_irqrestore(&tp->lock, flags); |
|
3894 } |
|
3895 |
|
3896 return &dev->stats; |
|
3897 } |
|
3898 |
|
3899 static void rtl8169_net_suspend(struct net_device *dev) |
|
3900 { |
|
3901 if (!netif_running(dev)) |
|
3902 return; |
|
3903 |
|
3904 netif_device_detach(dev); |
|
3905 netif_stop_queue(dev); |
|
3906 } |
|
3907 |
|
3908 #ifdef CONFIG_PM |
|
3909 |
|
3910 static int rtl8169_suspend(struct device *device) |
|
3911 { |
|
3912 struct pci_dev *pdev = to_pci_dev(device); |
|
3913 struct net_device *dev = pci_get_drvdata(pdev); |
|
3914 struct rtl8169_private *tp = netdev_priv(dev); |
|
3915 |
|
3916 if (tp->ecdev) |
|
3917 return -EBUSY; |
|
3918 |
|
3919 rtl8169_net_suspend(dev); |
|
3920 |
|
3921 return 0; |
|
3922 } |
|
3923 |
|
3924 static int rtl8169_resume(struct device *device) |
|
3925 { |
|
3926 struct pci_dev *pdev = to_pci_dev(device); |
|
3927 struct net_device *dev = pci_get_drvdata(pdev); |
|
3928 struct rtl8169_private *tp = netdev_priv(dev); |
|
3929 |
|
3930 if (tp->ecdev) |
|
3931 return -EBUSY; |
|
3932 |
|
3933 if (!netif_running(dev)) |
|
3934 goto out; |
|
3935 |
|
3936 netif_device_attach(dev); |
|
3937 |
|
3938 rtl8169_schedule_work(dev, rtl8169_reset_task); |
|
3939 out: |
|
3940 return 0; |
|
3941 } |
|
3942 |
|
3943 static struct dev_pm_ops rtl8169_pm_ops = { |
|
3944 .suspend = rtl8169_suspend, |
|
3945 .resume = rtl8169_resume, |
|
3946 .freeze = rtl8169_suspend, |
|
3947 .thaw = rtl8169_resume, |
|
3948 .poweroff = rtl8169_suspend, |
|
3949 .restore = rtl8169_resume, |
|
3950 }; |
|
3951 |
|
3952 #define RTL8169_PM_OPS (&rtl8169_pm_ops) |
|
3953 |
|
3954 #else /* !CONFIG_PM */ |
|
3955 |
|
3956 #define RTL8169_PM_OPS NULL |
|
3957 |
|
3958 #endif /* !CONFIG_PM */ |
|
3959 |
|
3960 static void rtl_shutdown(struct pci_dev *pdev) |
|
3961 { |
|
3962 struct net_device *dev = pci_get_drvdata(pdev); |
|
3963 struct rtl8169_private *tp = netdev_priv(dev); |
|
3964 void __iomem *ioaddr = tp->mmio_addr; |
|
3965 |
|
3966 rtl8169_net_suspend(dev); |
|
3967 |
|
3968 spin_lock_irq(&tp->lock); |
|
3969 |
|
3970 rtl8169_asic_down(ioaddr); |
|
3971 |
|
3972 spin_unlock_irq(&tp->lock); |
|
3973 |
|
3974 if (system_state == SYSTEM_POWER_OFF) { |
|
3975 /* WoL fails with some 8168 when the receiver is disabled. */ |
|
3976 if (tp->features & RTL_FEATURE_WOL) { |
|
3977 pci_clear_master(pdev); |
|
3978 |
|
3979 RTL_W8(ChipCmd, CmdRxEnb); |
|
3980 /* PCI commit */ |
|
3981 RTL_R8(ChipCmd); |
|
3982 } |
|
3983 |
|
3984 pci_wake_from_d3(pdev, true); |
|
3985 pci_set_power_state(pdev, PCI_D3hot); |
|
3986 } |
|
3987 } |
|
3988 |
|
3989 static struct pci_driver rtl8169_pci_driver = { |
|
3990 .name = MODULENAME, |
|
3991 .id_table = rtl8169_pci_tbl, |
|
3992 .probe = rtl8169_init_one, |
|
3993 .remove = __devexit_p(rtl8169_remove_one), |
|
3994 .shutdown = rtl_shutdown, |
|
3995 .driver.pm = RTL8169_PM_OPS, |
|
3996 }; |
|
3997 |
|
3998 static int __init rtl8169_init_module(void) |
|
3999 { |
|
4000 return pci_register_driver(&rtl8169_pci_driver); |
|
4001 } |
|
4002 |
|
4003 static void __exit rtl8169_cleanup_module(void) |
|
4004 { |
|
4005 pci_unregister_driver(&rtl8169_pci_driver); |
|
4006 } |
|
4007 |
|
4008 module_init(rtl8169_init_module); |
|
4009 module_exit(rtl8169_cleanup_module); |