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