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