|
1 /* |
|
2 * r8169.c: RealTek 8169/8168/8101 ethernet driver. |
|
3 * |
|
4 * Copyright (c) 2002 ShuChen <shuchen@realtek.com.tw> |
|
5 * Copyright (c) 2003 - 2007 Francois Romieu <romieu@fr.zoreil.com> |
|
6 * Copyright (c) a lot of people too. Please respect their work. |
|
7 * |
|
8 * See MAINTAINERS file for support contact information. |
|
9 */ |
|
10 |
|
11 #include <linux/module.h> |
|
12 #include <linux/moduleparam.h> |
|
13 #include <linux/pci.h> |
|
14 #include <linux/netdevice.h> |
|
15 #include <linux/etherdevice.h> |
|
16 #include <linux/delay.h> |
|
17 #include <linux/ethtool.h> |
|
18 #include <linux/mii.h> |
|
19 #include <linux/if_vlan.h> |
|
20 #include <linux/crc32.h> |
|
21 #include <linux/in.h> |
|
22 #include <linux/ip.h> |
|
23 #include <linux/tcp.h> |
|
24 #include <linux/init.h> |
|
25 #include <linux/interrupt.h> |
|
26 #include <linux/dma-mapping.h> |
|
27 #include <linux/pm_runtime.h> |
|
28 #include <linux/firmware.h> |
|
29 #include <linux/pci-aspm.h> |
|
30 #include <linux/prefetch.h> |
|
31 |
|
32 #include <asm/io.h> |
|
33 #include <asm/irq.h> |
|
34 |
|
35 #define RTL8169_VERSION "2.3LK-NAPI" |
|
36 #define MODULENAME "r8169" |
|
37 #define PFX MODULENAME ": " |
|
38 |
|
39 #define FIRMWARE_8168D_1 "rtl_nic/rtl8168d-1.fw" |
|
40 #define FIRMWARE_8168D_2 "rtl_nic/rtl8168d-2.fw" |
|
41 #define FIRMWARE_8168E_1 "rtl_nic/rtl8168e-1.fw" |
|
42 #define FIRMWARE_8168E_2 "rtl_nic/rtl8168e-2.fw" |
|
43 #define FIRMWARE_8168E_3 "rtl_nic/rtl8168e-3.fw" |
|
44 #define FIRMWARE_8168F_1 "rtl_nic/rtl8168f-1.fw" |
|
45 #define FIRMWARE_8168F_2 "rtl_nic/rtl8168f-2.fw" |
|
46 #define FIRMWARE_8105E_1 "rtl_nic/rtl8105e-1.fw" |
|
47 |
|
48 #ifdef RTL8169_DEBUG |
|
49 #define assert(expr) \ |
|
50 if (!(expr)) { \ |
|
51 printk( "Assertion failed! %s,%s,%s,line=%d\n", \ |
|
52 #expr,__FILE__,__func__,__LINE__); \ |
|
53 } |
|
54 #define dprintk(fmt, args...) \ |
|
55 do { printk(KERN_DEBUG PFX fmt, ## args); } while (0) |
|
56 #else |
|
57 #define assert(expr) do {} while (0) |
|
58 #define dprintk(fmt, args...) do {} while (0) |
|
59 #endif /* RTL8169_DEBUG */ |
|
60 |
|
61 #define R8169_MSG_DEFAULT \ |
|
62 (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN) |
|
63 |
|
64 #define TX_SLOTS_AVAIL(tp) \ |
|
65 (tp->dirty_tx + NUM_TX_DESC - tp->cur_tx) |
|
66 |
|
67 /* A skbuff with nr_frags needs nr_frags+1 entries in the tx queue */ |
|
68 #define TX_FRAGS_READY_FOR(tp,nr_frags) \ |
|
69 (TX_SLOTS_AVAIL(tp) >= (nr_frags + 1)) |
|
70 |
|
71 /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). |
|
72 The RTL chips use a 64 element hash table based on the Ethernet CRC. */ |
|
73 static const int multicast_filter_limit = 32; |
|
74 |
|
75 #define MAX_READ_REQUEST_SHIFT 12 |
|
76 #define TX_DMA_BURST 7 /* Maximum PCI burst, '7' is unlimited */ |
|
77 #define SafeMtu 0x1c20 /* ... actually life sucks beyond ~7k */ |
|
78 #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */ |
|
79 |
|
80 #define R8169_REGS_SIZE 256 |
|
81 #define R8169_NAPI_WEIGHT 64 |
|
82 #define NUM_TX_DESC 64 /* Number of Tx descriptor registers */ |
|
83 #define NUM_RX_DESC 256 /* Number of Rx descriptor registers */ |
|
84 #define RX_BUF_SIZE 1536 /* Rx Buffer size */ |
|
85 #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc)) |
|
86 #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc)) |
|
87 |
|
88 #define RTL8169_TX_TIMEOUT (6*HZ) |
|
89 #define RTL8169_PHY_TIMEOUT (10*HZ) |
|
90 |
|
91 #define RTL_EEPROM_SIG cpu_to_le32(0x8129) |
|
92 #define RTL_EEPROM_SIG_MASK cpu_to_le32(0xffff) |
|
93 #define RTL_EEPROM_SIG_ADDR 0x0000 |
|
94 |
|
95 /* write/read MMIO register */ |
|
96 #define RTL_W8(reg, val8) writeb ((val8), ioaddr + (reg)) |
|
97 #define RTL_W16(reg, val16) writew ((val16), ioaddr + (reg)) |
|
98 #define RTL_W32(reg, val32) writel ((val32), ioaddr + (reg)) |
|
99 #define RTL_R8(reg) readb (ioaddr + (reg)) |
|
100 #define RTL_R16(reg) readw (ioaddr + (reg)) |
|
101 #define RTL_R32(reg) readl (ioaddr + (reg)) |
|
102 |
|
103 enum mac_version { |
|
104 RTL_GIGA_MAC_VER_01 = 0, |
|
105 RTL_GIGA_MAC_VER_02, |
|
106 RTL_GIGA_MAC_VER_03, |
|
107 RTL_GIGA_MAC_VER_04, |
|
108 RTL_GIGA_MAC_VER_05, |
|
109 RTL_GIGA_MAC_VER_06, |
|
110 RTL_GIGA_MAC_VER_07, |
|
111 RTL_GIGA_MAC_VER_08, |
|
112 RTL_GIGA_MAC_VER_09, |
|
113 RTL_GIGA_MAC_VER_10, |
|
114 RTL_GIGA_MAC_VER_11, |
|
115 RTL_GIGA_MAC_VER_12, |
|
116 RTL_GIGA_MAC_VER_13, |
|
117 RTL_GIGA_MAC_VER_14, |
|
118 RTL_GIGA_MAC_VER_15, |
|
119 RTL_GIGA_MAC_VER_16, |
|
120 RTL_GIGA_MAC_VER_17, |
|
121 RTL_GIGA_MAC_VER_18, |
|
122 RTL_GIGA_MAC_VER_19, |
|
123 RTL_GIGA_MAC_VER_20, |
|
124 RTL_GIGA_MAC_VER_21, |
|
125 RTL_GIGA_MAC_VER_22, |
|
126 RTL_GIGA_MAC_VER_23, |
|
127 RTL_GIGA_MAC_VER_24, |
|
128 RTL_GIGA_MAC_VER_25, |
|
129 RTL_GIGA_MAC_VER_26, |
|
130 RTL_GIGA_MAC_VER_27, |
|
131 RTL_GIGA_MAC_VER_28, |
|
132 RTL_GIGA_MAC_VER_29, |
|
133 RTL_GIGA_MAC_VER_30, |
|
134 RTL_GIGA_MAC_VER_31, |
|
135 RTL_GIGA_MAC_VER_32, |
|
136 RTL_GIGA_MAC_VER_33, |
|
137 RTL_GIGA_MAC_VER_34, |
|
138 RTL_GIGA_MAC_VER_35, |
|
139 RTL_GIGA_MAC_VER_36, |
|
140 RTL_GIGA_MAC_NONE = 0xff, |
|
141 }; |
|
142 |
|
143 enum rtl_tx_desc_version { |
|
144 RTL_TD_0 = 0, |
|
145 RTL_TD_1 = 1, |
|
146 }; |
|
147 |
|
148 #define JUMBO_1K ETH_DATA_LEN |
|
149 #define JUMBO_4K (4*1024 - ETH_HLEN - 2) |
|
150 #define JUMBO_6K (6*1024 - ETH_HLEN - 2) |
|
151 #define JUMBO_7K (7*1024 - ETH_HLEN - 2) |
|
152 #define JUMBO_9K (9*1024 - ETH_HLEN - 2) |
|
153 |
|
154 #define _R(NAME,TD,FW,SZ,B) { \ |
|
155 .name = NAME, \ |
|
156 .txd_version = TD, \ |
|
157 .fw_name = FW, \ |
|
158 .jumbo_max = SZ, \ |
|
159 .jumbo_tx_csum = B \ |
|
160 } |
|
161 |
|
162 static const struct { |
|
163 const char *name; |
|
164 enum rtl_tx_desc_version txd_version; |
|
165 const char *fw_name; |
|
166 u16 jumbo_max; |
|
167 bool jumbo_tx_csum; |
|
168 } rtl_chip_infos[] = { |
|
169 /* PCI devices. */ |
|
170 [RTL_GIGA_MAC_VER_01] = |
|
171 _R("RTL8169", RTL_TD_0, NULL, JUMBO_7K, true), |
|
172 [RTL_GIGA_MAC_VER_02] = |
|
173 _R("RTL8169s", RTL_TD_0, NULL, JUMBO_7K, true), |
|
174 [RTL_GIGA_MAC_VER_03] = |
|
175 _R("RTL8110s", RTL_TD_0, NULL, JUMBO_7K, true), |
|
176 [RTL_GIGA_MAC_VER_04] = |
|
177 _R("RTL8169sb/8110sb", RTL_TD_0, NULL, JUMBO_7K, true), |
|
178 [RTL_GIGA_MAC_VER_05] = |
|
179 _R("RTL8169sc/8110sc", RTL_TD_0, NULL, JUMBO_7K, true), |
|
180 [RTL_GIGA_MAC_VER_06] = |
|
181 _R("RTL8169sc/8110sc", RTL_TD_0, NULL, JUMBO_7K, true), |
|
182 /* PCI-E devices. */ |
|
183 [RTL_GIGA_MAC_VER_07] = |
|
184 _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K, true), |
|
185 [RTL_GIGA_MAC_VER_08] = |
|
186 _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K, true), |
|
187 [RTL_GIGA_MAC_VER_09] = |
|
188 _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K, true), |
|
189 [RTL_GIGA_MAC_VER_10] = |
|
190 _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), |
|
191 [RTL_GIGA_MAC_VER_11] = |
|
192 _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K, false), |
|
193 [RTL_GIGA_MAC_VER_12] = |
|
194 _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K, false), |
|
195 [RTL_GIGA_MAC_VER_13] = |
|
196 _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), |
|
197 [RTL_GIGA_MAC_VER_14] = |
|
198 _R("RTL8100e", RTL_TD_0, NULL, JUMBO_1K, true), |
|
199 [RTL_GIGA_MAC_VER_15] = |
|
200 _R("RTL8100e", RTL_TD_0, NULL, JUMBO_1K, true), |
|
201 [RTL_GIGA_MAC_VER_16] = |
|
202 _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), |
|
203 [RTL_GIGA_MAC_VER_17] = |
|
204 _R("RTL8168b/8111b", RTL_TD_1, NULL, JUMBO_4K, false), |
|
205 [RTL_GIGA_MAC_VER_18] = |
|
206 _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), |
|
207 [RTL_GIGA_MAC_VER_19] = |
|
208 _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
|
209 [RTL_GIGA_MAC_VER_20] = |
|
210 _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
|
211 [RTL_GIGA_MAC_VER_21] = |
|
212 _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
|
213 [RTL_GIGA_MAC_VER_22] = |
|
214 _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
|
215 [RTL_GIGA_MAC_VER_23] = |
|
216 _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), |
|
217 [RTL_GIGA_MAC_VER_24] = |
|
218 _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), |
|
219 [RTL_GIGA_MAC_VER_25] = |
|
220 _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_1, |
|
221 JUMBO_9K, false), |
|
222 [RTL_GIGA_MAC_VER_26] = |
|
223 _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_2, |
|
224 JUMBO_9K, false), |
|
225 [RTL_GIGA_MAC_VER_27] = |
|
226 _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K, false), |
|
227 [RTL_GIGA_MAC_VER_28] = |
|
228 _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K, false), |
|
229 [RTL_GIGA_MAC_VER_29] = |
|
230 _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1, |
|
231 JUMBO_1K, true), |
|
232 [RTL_GIGA_MAC_VER_30] = |
|
233 _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1, |
|
234 JUMBO_1K, true), |
|
235 [RTL_GIGA_MAC_VER_31] = |
|
236 _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K, false), |
|
237 [RTL_GIGA_MAC_VER_32] = |
|
238 _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_1, |
|
239 JUMBO_9K, false), |
|
240 [RTL_GIGA_MAC_VER_33] = |
|
241 _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_2, |
|
242 JUMBO_9K, false), |
|
243 [RTL_GIGA_MAC_VER_34] = |
|
244 _R("RTL8168evl/8111evl",RTL_TD_1, FIRMWARE_8168E_3, |
|
245 JUMBO_9K, false), |
|
246 [RTL_GIGA_MAC_VER_35] = |
|
247 _R("RTL8168f/8111f", RTL_TD_1, FIRMWARE_8168F_1, |
|
248 JUMBO_9K, false), |
|
249 [RTL_GIGA_MAC_VER_36] = |
|
250 _R("RTL8168f/8111f", RTL_TD_1, FIRMWARE_8168F_2, |
|
251 JUMBO_9K, false), |
|
252 }; |
|
253 #undef _R |
|
254 |
|
255 enum cfg_version { |
|
256 RTL_CFG_0 = 0x00, |
|
257 RTL_CFG_1, |
|
258 RTL_CFG_2 |
|
259 }; |
|
260 |
|
261 static DEFINE_PCI_DEVICE_TABLE(rtl8169_pci_tbl) = { |
|
262 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 }, |
|
263 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8136), 0, 0, RTL_CFG_2 }, |
|
264 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_0 }, |
|
265 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_1 }, |
|
266 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 }, |
|
267 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4300), 0, 0, RTL_CFG_0 }, |
|
268 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4302), 0, 0, RTL_CFG_0 }, |
|
269 { PCI_DEVICE(PCI_VENDOR_ID_AT, 0xc107), 0, 0, RTL_CFG_0 }, |
|
270 { PCI_DEVICE(0x16ec, 0x0116), 0, 0, RTL_CFG_0 }, |
|
271 { PCI_VENDOR_ID_LINKSYS, 0x1032, |
|
272 PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 }, |
|
273 { 0x0001, 0x8168, |
|
274 PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 }, |
|
275 {0,}, |
|
276 }; |
|
277 |
|
278 MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl); |
|
279 |
|
280 static int rx_buf_sz = 16383; |
|
281 static int use_dac; |
|
282 static struct { |
|
283 u32 msg_enable; |
|
284 } debug = { -1 }; |
|
285 |
|
286 enum rtl_registers { |
|
287 MAC0 = 0, /* Ethernet hardware address. */ |
|
288 MAC4 = 4, |
|
289 MAR0 = 8, /* Multicast filter. */ |
|
290 CounterAddrLow = 0x10, |
|
291 CounterAddrHigh = 0x14, |
|
292 TxDescStartAddrLow = 0x20, |
|
293 TxDescStartAddrHigh = 0x24, |
|
294 TxHDescStartAddrLow = 0x28, |
|
295 TxHDescStartAddrHigh = 0x2c, |
|
296 FLASH = 0x30, |
|
297 ERSR = 0x36, |
|
298 ChipCmd = 0x37, |
|
299 TxPoll = 0x38, |
|
300 IntrMask = 0x3c, |
|
301 IntrStatus = 0x3e, |
|
302 |
|
303 TxConfig = 0x40, |
|
304 #define TXCFG_AUTO_FIFO (1 << 7) /* 8111e-vl */ |
|
305 #define TXCFG_EMPTY (1 << 11) /* 8111e-vl */ |
|
306 |
|
307 RxConfig = 0x44, |
|
308 #define RX128_INT_EN (1 << 15) /* 8111c and later */ |
|
309 #define RX_MULTI_EN (1 << 14) /* 8111c only */ |
|
310 #define RXCFG_FIFO_SHIFT 13 |
|
311 /* No threshold before first PCI xfer */ |
|
312 #define RX_FIFO_THRESH (7 << RXCFG_FIFO_SHIFT) |
|
313 #define RXCFG_DMA_SHIFT 8 |
|
314 /* Unlimited maximum PCI burst. */ |
|
315 #define RX_DMA_BURST (7 << RXCFG_DMA_SHIFT) |
|
316 |
|
317 RxMissed = 0x4c, |
|
318 Cfg9346 = 0x50, |
|
319 Config0 = 0x51, |
|
320 Config1 = 0x52, |
|
321 Config2 = 0x53, |
|
322 #define PME_SIGNAL (1 << 5) /* 8168c and later */ |
|
323 |
|
324 Config3 = 0x54, |
|
325 Config4 = 0x55, |
|
326 Config5 = 0x56, |
|
327 MultiIntr = 0x5c, |
|
328 PHYAR = 0x60, |
|
329 PHYstatus = 0x6c, |
|
330 RxMaxSize = 0xda, |
|
331 CPlusCmd = 0xe0, |
|
332 IntrMitigate = 0xe2, |
|
333 RxDescAddrLow = 0xe4, |
|
334 RxDescAddrHigh = 0xe8, |
|
335 EarlyTxThres = 0xec, /* 8169. Unit of 32 bytes. */ |
|
336 |
|
337 #define NoEarlyTx 0x3f /* Max value : no early transmit. */ |
|
338 |
|
339 MaxTxPacketSize = 0xec, /* 8101/8168. Unit of 128 bytes. */ |
|
340 |
|
341 #define TxPacketMax (8064 >> 7) |
|
342 #define EarlySize 0x27 |
|
343 |
|
344 FuncEvent = 0xf0, |
|
345 FuncEventMask = 0xf4, |
|
346 FuncPresetState = 0xf8, |
|
347 FuncForceEvent = 0xfc, |
|
348 }; |
|
349 |
|
350 enum rtl8110_registers { |
|
351 TBICSR = 0x64, |
|
352 TBI_ANAR = 0x68, |
|
353 TBI_LPAR = 0x6a, |
|
354 }; |
|
355 |
|
356 enum rtl8168_8101_registers { |
|
357 CSIDR = 0x64, |
|
358 CSIAR = 0x68, |
|
359 #define CSIAR_FLAG 0x80000000 |
|
360 #define CSIAR_WRITE_CMD 0x80000000 |
|
361 #define CSIAR_BYTE_ENABLE 0x0f |
|
362 #define CSIAR_BYTE_ENABLE_SHIFT 12 |
|
363 #define CSIAR_ADDR_MASK 0x0fff |
|
364 PMCH = 0x6f, |
|
365 EPHYAR = 0x80, |
|
366 #define EPHYAR_FLAG 0x80000000 |
|
367 #define EPHYAR_WRITE_CMD 0x80000000 |
|
368 #define EPHYAR_REG_MASK 0x1f |
|
369 #define EPHYAR_REG_SHIFT 16 |
|
370 #define EPHYAR_DATA_MASK 0xffff |
|
371 DLLPR = 0xd0, |
|
372 #define PFM_EN (1 << 6) |
|
373 DBG_REG = 0xd1, |
|
374 #define FIX_NAK_1 (1 << 4) |
|
375 #define FIX_NAK_2 (1 << 3) |
|
376 TWSI = 0xd2, |
|
377 MCU = 0xd3, |
|
378 #define NOW_IS_OOB (1 << 7) |
|
379 #define EN_NDP (1 << 3) |
|
380 #define EN_OOB_RESET (1 << 2) |
|
381 EFUSEAR = 0xdc, |
|
382 #define EFUSEAR_FLAG 0x80000000 |
|
383 #define EFUSEAR_WRITE_CMD 0x80000000 |
|
384 #define EFUSEAR_READ_CMD 0x00000000 |
|
385 #define EFUSEAR_REG_MASK 0x03ff |
|
386 #define EFUSEAR_REG_SHIFT 8 |
|
387 #define EFUSEAR_DATA_MASK 0xff |
|
388 }; |
|
389 |
|
390 enum rtl8168_registers { |
|
391 LED_FREQ = 0x1a, |
|
392 EEE_LED = 0x1b, |
|
393 ERIDR = 0x70, |
|
394 ERIAR = 0x74, |
|
395 #define ERIAR_FLAG 0x80000000 |
|
396 #define ERIAR_WRITE_CMD 0x80000000 |
|
397 #define ERIAR_READ_CMD 0x00000000 |
|
398 #define ERIAR_ADDR_BYTE_ALIGN 4 |
|
399 #define ERIAR_TYPE_SHIFT 16 |
|
400 #define ERIAR_EXGMAC (0x00 << ERIAR_TYPE_SHIFT) |
|
401 #define ERIAR_MSIX (0x01 << ERIAR_TYPE_SHIFT) |
|
402 #define ERIAR_ASF (0x02 << ERIAR_TYPE_SHIFT) |
|
403 #define ERIAR_MASK_SHIFT 12 |
|
404 #define ERIAR_MASK_0001 (0x1 << ERIAR_MASK_SHIFT) |
|
405 #define ERIAR_MASK_0011 (0x3 << ERIAR_MASK_SHIFT) |
|
406 #define ERIAR_MASK_1111 (0xf << ERIAR_MASK_SHIFT) |
|
407 EPHY_RXER_NUM = 0x7c, |
|
408 OCPDR = 0xb0, /* OCP GPHY access */ |
|
409 #define OCPDR_WRITE_CMD 0x80000000 |
|
410 #define OCPDR_READ_CMD 0x00000000 |
|
411 #define OCPDR_REG_MASK 0x7f |
|
412 #define OCPDR_GPHY_REG_SHIFT 16 |
|
413 #define OCPDR_DATA_MASK 0xffff |
|
414 OCPAR = 0xb4, |
|
415 #define OCPAR_FLAG 0x80000000 |
|
416 #define OCPAR_GPHY_WRITE_CMD 0x8000f060 |
|
417 #define OCPAR_GPHY_READ_CMD 0x0000f060 |
|
418 RDSAR1 = 0xd0, /* 8168c only. Undocumented on 8168dp */ |
|
419 MISC = 0xf0, /* 8168e only. */ |
|
420 #define TXPLA_RST (1 << 29) |
|
421 #define PWM_EN (1 << 22) |
|
422 }; |
|
423 |
|
424 enum rtl_register_content { |
|
425 /* InterruptStatusBits */ |
|
426 SYSErr = 0x8000, |
|
427 PCSTimeout = 0x4000, |
|
428 SWInt = 0x0100, |
|
429 TxDescUnavail = 0x0080, |
|
430 RxFIFOOver = 0x0040, |
|
431 LinkChg = 0x0020, |
|
432 RxOverflow = 0x0010, |
|
433 TxErr = 0x0008, |
|
434 TxOK = 0x0004, |
|
435 RxErr = 0x0002, |
|
436 RxOK = 0x0001, |
|
437 |
|
438 /* RxStatusDesc */ |
|
439 RxBOVF = (1 << 24), |
|
440 RxFOVF = (1 << 23), |
|
441 RxRWT = (1 << 22), |
|
442 RxRES = (1 << 21), |
|
443 RxRUNT = (1 << 20), |
|
444 RxCRC = (1 << 19), |
|
445 |
|
446 /* ChipCmdBits */ |
|
447 StopReq = 0x80, |
|
448 CmdReset = 0x10, |
|
449 CmdRxEnb = 0x08, |
|
450 CmdTxEnb = 0x04, |
|
451 RxBufEmpty = 0x01, |
|
452 |
|
453 /* TXPoll register p.5 */ |
|
454 HPQ = 0x80, /* Poll cmd on the high prio queue */ |
|
455 NPQ = 0x40, /* Poll cmd on the low prio queue */ |
|
456 FSWInt = 0x01, /* Forced software interrupt */ |
|
457 |
|
458 /* Cfg9346Bits */ |
|
459 Cfg9346_Lock = 0x00, |
|
460 Cfg9346_Unlock = 0xc0, |
|
461 |
|
462 /* rx_mode_bits */ |
|
463 AcceptErr = 0x20, |
|
464 AcceptRunt = 0x10, |
|
465 AcceptBroadcast = 0x08, |
|
466 AcceptMulticast = 0x04, |
|
467 AcceptMyPhys = 0x02, |
|
468 AcceptAllPhys = 0x01, |
|
469 #define RX_CONFIG_ACCEPT_MASK 0x3f |
|
470 |
|
471 /* TxConfigBits */ |
|
472 TxInterFrameGapShift = 24, |
|
473 TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */ |
|
474 |
|
475 /* Config1 register p.24 */ |
|
476 LEDS1 = (1 << 7), |
|
477 LEDS0 = (1 << 6), |
|
478 Speed_down = (1 << 4), |
|
479 MEMMAP = (1 << 3), |
|
480 IOMAP = (1 << 2), |
|
481 VPD = (1 << 1), |
|
482 PMEnable = (1 << 0), /* Power Management Enable */ |
|
483 |
|
484 /* Config2 register p. 25 */ |
|
485 MSIEnable = (1 << 5), /* 8169 only. Reserved in the 8168. */ |
|
486 PCI_Clock_66MHz = 0x01, |
|
487 PCI_Clock_33MHz = 0x00, |
|
488 |
|
489 /* Config3 register p.25 */ |
|
490 MagicPacket = (1 << 5), /* Wake up when receives a Magic Packet */ |
|
491 LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */ |
|
492 Jumbo_En0 = (1 << 2), /* 8168 only. Reserved in the 8168b */ |
|
493 Beacon_en = (1 << 0), /* 8168 only. Reserved in the 8168b */ |
|
494 |
|
495 /* Config4 register */ |
|
496 Jumbo_En1 = (1 << 1), /* 8168 only. Reserved in the 8168b */ |
|
497 |
|
498 /* Config5 register p.27 */ |
|
499 BWF = (1 << 6), /* Accept Broadcast wakeup frame */ |
|
500 MWF = (1 << 5), /* Accept Multicast wakeup frame */ |
|
501 UWF = (1 << 4), /* Accept Unicast wakeup frame */ |
|
502 Spi_en = (1 << 3), |
|
503 LanWake = (1 << 1), /* LanWake enable/disable */ |
|
504 PMEStatus = (1 << 0), /* PME status can be reset by PCI RST# */ |
|
505 |
|
506 /* TBICSR p.28 */ |
|
507 TBIReset = 0x80000000, |
|
508 TBILoopback = 0x40000000, |
|
509 TBINwEnable = 0x20000000, |
|
510 TBINwRestart = 0x10000000, |
|
511 TBILinkOk = 0x02000000, |
|
512 TBINwComplete = 0x01000000, |
|
513 |
|
514 /* CPlusCmd p.31 */ |
|
515 EnableBist = (1 << 15), // 8168 8101 |
|
516 Mac_dbgo_oe = (1 << 14), // 8168 8101 |
|
517 Normal_mode = (1 << 13), // unused |
|
518 Force_half_dup = (1 << 12), // 8168 8101 |
|
519 Force_rxflow_en = (1 << 11), // 8168 8101 |
|
520 Force_txflow_en = (1 << 10), // 8168 8101 |
|
521 Cxpl_dbg_sel = (1 << 9), // 8168 8101 |
|
522 ASF = (1 << 8), // 8168 8101 |
|
523 PktCntrDisable = (1 << 7), // 8168 8101 |
|
524 Mac_dbgo_sel = 0x001c, // 8168 |
|
525 RxVlan = (1 << 6), |
|
526 RxChkSum = (1 << 5), |
|
527 PCIDAC = (1 << 4), |
|
528 PCIMulRW = (1 << 3), |
|
529 INTT_0 = 0x0000, // 8168 |
|
530 INTT_1 = 0x0001, // 8168 |
|
531 INTT_2 = 0x0002, // 8168 |
|
532 INTT_3 = 0x0003, // 8168 |
|
533 |
|
534 /* rtl8169_PHYstatus */ |
|
535 TBI_Enable = 0x80, |
|
536 TxFlowCtrl = 0x40, |
|
537 RxFlowCtrl = 0x20, |
|
538 _1000bpsF = 0x10, |
|
539 _100bps = 0x08, |
|
540 _10bps = 0x04, |
|
541 LinkStatus = 0x02, |
|
542 FullDup = 0x01, |
|
543 |
|
544 /* _TBICSRBit */ |
|
545 TBILinkOK = 0x02000000, |
|
546 |
|
547 /* DumpCounterCommand */ |
|
548 CounterDump = 0x8, |
|
549 }; |
|
550 |
|
551 enum rtl_desc_bit { |
|
552 /* First doubleword. */ |
|
553 DescOwn = (1 << 31), /* Descriptor is owned by NIC */ |
|
554 RingEnd = (1 << 30), /* End of descriptor ring */ |
|
555 FirstFrag = (1 << 29), /* First segment of a packet */ |
|
556 LastFrag = (1 << 28), /* Final segment of a packet */ |
|
557 }; |
|
558 |
|
559 /* Generic case. */ |
|
560 enum rtl_tx_desc_bit { |
|
561 /* First doubleword. */ |
|
562 TD_LSO = (1 << 27), /* Large Send Offload */ |
|
563 #define TD_MSS_MAX 0x07ffu /* MSS value */ |
|
564 |
|
565 /* Second doubleword. */ |
|
566 TxVlanTag = (1 << 17), /* Add VLAN tag */ |
|
567 }; |
|
568 |
|
569 /* 8169, 8168b and 810x except 8102e. */ |
|
570 enum rtl_tx_desc_bit_0 { |
|
571 /* First doubleword. */ |
|
572 #define TD0_MSS_SHIFT 16 /* MSS position (11 bits) */ |
|
573 TD0_TCP_CS = (1 << 16), /* Calculate TCP/IP checksum */ |
|
574 TD0_UDP_CS = (1 << 17), /* Calculate UDP/IP checksum */ |
|
575 TD0_IP_CS = (1 << 18), /* Calculate IP checksum */ |
|
576 }; |
|
577 |
|
578 /* 8102e, 8168c and beyond. */ |
|
579 enum rtl_tx_desc_bit_1 { |
|
580 /* Second doubleword. */ |
|
581 #define TD1_MSS_SHIFT 18 /* MSS position (11 bits) */ |
|
582 TD1_IP_CS = (1 << 29), /* Calculate IP checksum */ |
|
583 TD1_TCP_CS = (1 << 30), /* Calculate TCP/IP checksum */ |
|
584 TD1_UDP_CS = (1 << 31), /* Calculate UDP/IP checksum */ |
|
585 }; |
|
586 |
|
587 static const struct rtl_tx_desc_info { |
|
588 struct { |
|
589 u32 udp; |
|
590 u32 tcp; |
|
591 } checksum; |
|
592 u16 mss_shift; |
|
593 u16 opts_offset; |
|
594 } tx_desc_info [] = { |
|
595 [RTL_TD_0] = { |
|
596 .checksum = { |
|
597 .udp = TD0_IP_CS | TD0_UDP_CS, |
|
598 .tcp = TD0_IP_CS | TD0_TCP_CS |
|
599 }, |
|
600 .mss_shift = TD0_MSS_SHIFT, |
|
601 .opts_offset = 0 |
|
602 }, |
|
603 [RTL_TD_1] = { |
|
604 .checksum = { |
|
605 .udp = TD1_IP_CS | TD1_UDP_CS, |
|
606 .tcp = TD1_IP_CS | TD1_TCP_CS |
|
607 }, |
|
608 .mss_shift = TD1_MSS_SHIFT, |
|
609 .opts_offset = 1 |
|
610 } |
|
611 }; |
|
612 |
|
613 enum rtl_rx_desc_bit { |
|
614 /* Rx private */ |
|
615 PID1 = (1 << 18), /* Protocol ID bit 1/2 */ |
|
616 PID0 = (1 << 17), /* Protocol ID bit 2/2 */ |
|
617 |
|
618 #define RxProtoUDP (PID1) |
|
619 #define RxProtoTCP (PID0) |
|
620 #define RxProtoIP (PID1 | PID0) |
|
621 #define RxProtoMask RxProtoIP |
|
622 |
|
623 IPFail = (1 << 16), /* IP checksum failed */ |
|
624 UDPFail = (1 << 15), /* UDP/IP checksum failed */ |
|
625 TCPFail = (1 << 14), /* TCP/IP checksum failed */ |
|
626 RxVlanTag = (1 << 16), /* VLAN tag available */ |
|
627 }; |
|
628 |
|
629 #define RsvdMask 0x3fffc000 |
|
630 |
|
631 struct TxDesc { |
|
632 __le32 opts1; |
|
633 __le32 opts2; |
|
634 __le64 addr; |
|
635 }; |
|
636 |
|
637 struct RxDesc { |
|
638 __le32 opts1; |
|
639 __le32 opts2; |
|
640 __le64 addr; |
|
641 }; |
|
642 |
|
643 struct ring_info { |
|
644 struct sk_buff *skb; |
|
645 u32 len; |
|
646 u8 __pad[sizeof(void *) - sizeof(u32)]; |
|
647 }; |
|
648 |
|
649 enum features { |
|
650 RTL_FEATURE_WOL = (1 << 0), |
|
651 RTL_FEATURE_MSI = (1 << 1), |
|
652 RTL_FEATURE_GMII = (1 << 2), |
|
653 }; |
|
654 |
|
655 struct rtl8169_counters { |
|
656 __le64 tx_packets; |
|
657 __le64 rx_packets; |
|
658 __le64 tx_errors; |
|
659 __le32 rx_errors; |
|
660 __le16 rx_missed; |
|
661 __le16 align_errors; |
|
662 __le32 tx_one_collision; |
|
663 __le32 tx_multi_collision; |
|
664 __le64 rx_unicast; |
|
665 __le64 rx_broadcast; |
|
666 __le32 rx_multicast; |
|
667 __le16 tx_aborted; |
|
668 __le16 tx_underun; |
|
669 }; |
|
670 |
|
671 enum rtl_flag { |
|
672 RTL_FLAG_TASK_ENABLED, |
|
673 RTL_FLAG_TASK_SLOW_PENDING, |
|
674 RTL_FLAG_TASK_RESET_PENDING, |
|
675 RTL_FLAG_TASK_PHY_PENDING, |
|
676 RTL_FLAG_MAX |
|
677 }; |
|
678 |
|
679 struct rtl8169_stats { |
|
680 u64 packets; |
|
681 u64 bytes; |
|
682 struct u64_stats_sync syncp; |
|
683 }; |
|
684 |
|
685 struct rtl8169_private { |
|
686 void __iomem *mmio_addr; /* memory map physical address */ |
|
687 struct pci_dev *pci_dev; |
|
688 struct net_device *dev; |
|
689 struct napi_struct napi; |
|
690 u32 msg_enable; |
|
691 u16 txd_version; |
|
692 u16 mac_version; |
|
693 u32 cur_rx; /* Index into the Rx descriptor buffer of next Rx pkt. */ |
|
694 u32 cur_tx; /* Index into the Tx descriptor buffer of next Rx pkt. */ |
|
695 u32 dirty_rx; |
|
696 u32 dirty_tx; |
|
697 struct rtl8169_stats rx_stats; |
|
698 struct rtl8169_stats tx_stats; |
|
699 struct TxDesc *TxDescArray; /* 256-aligned Tx descriptor ring */ |
|
700 struct RxDesc *RxDescArray; /* 256-aligned Rx descriptor ring */ |
|
701 dma_addr_t TxPhyAddr; |
|
702 dma_addr_t RxPhyAddr; |
|
703 void *Rx_databuff[NUM_RX_DESC]; /* Rx data buffers */ |
|
704 struct ring_info tx_skb[NUM_TX_DESC]; /* Tx data buffers */ |
|
705 struct timer_list timer; |
|
706 u16 cp_cmd; |
|
707 |
|
708 u16 event_slow; |
|
709 |
|
710 struct mdio_ops { |
|
711 void (*write)(void __iomem *, int, int); |
|
712 int (*read)(void __iomem *, int); |
|
713 } mdio_ops; |
|
714 |
|
715 struct pll_power_ops { |
|
716 void (*down)(struct rtl8169_private *); |
|
717 void (*up)(struct rtl8169_private *); |
|
718 } pll_power_ops; |
|
719 |
|
720 struct jumbo_ops { |
|
721 void (*enable)(struct rtl8169_private *); |
|
722 void (*disable)(struct rtl8169_private *); |
|
723 } jumbo_ops; |
|
724 |
|
725 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv); |
|
726 int (*get_settings)(struct net_device *, struct ethtool_cmd *); |
|
727 void (*phy_reset_enable)(struct rtl8169_private *tp); |
|
728 void (*hw_start)(struct net_device *); |
|
729 unsigned int (*phy_reset_pending)(struct rtl8169_private *tp); |
|
730 unsigned int (*link_ok)(void __iomem *); |
|
731 int (*do_ioctl)(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd); |
|
732 |
|
733 struct { |
|
734 DECLARE_BITMAP(flags, RTL_FLAG_MAX); |
|
735 struct mutex mutex; |
|
736 struct work_struct work; |
|
737 } wk; |
|
738 |
|
739 unsigned features; |
|
740 |
|
741 struct mii_if_info mii; |
|
742 struct rtl8169_counters counters; |
|
743 u32 saved_wolopts; |
|
744 u32 opts1_mask; |
|
745 |
|
746 struct rtl_fw { |
|
747 const struct firmware *fw; |
|
748 |
|
749 #define RTL_VER_SIZE 32 |
|
750 |
|
751 char version[RTL_VER_SIZE]; |
|
752 |
|
753 struct rtl_fw_phy_action { |
|
754 __le32 *code; |
|
755 size_t size; |
|
756 } phy_action; |
|
757 } *rtl_fw; |
|
758 #define RTL_FIRMWARE_UNKNOWN ERR_PTR(-EAGAIN) |
|
759 }; |
|
760 |
|
761 MODULE_AUTHOR("Realtek and the Linux r8169 crew <netdev@vger.kernel.org>"); |
|
762 MODULE_DESCRIPTION("RealTek RTL-8169 Gigabit Ethernet driver"); |
|
763 module_param(use_dac, int, 0); |
|
764 MODULE_PARM_DESC(use_dac, "Enable PCI DAC. Unsafe on 32 bit PCI slot."); |
|
765 module_param_named(debug, debug.msg_enable, int, 0); |
|
766 MODULE_PARM_DESC(debug, "Debug verbosity level (0=none, ..., 16=all)"); |
|
767 MODULE_LICENSE("GPL"); |
|
768 MODULE_VERSION(RTL8169_VERSION); |
|
769 MODULE_FIRMWARE(FIRMWARE_8168D_1); |
|
770 MODULE_FIRMWARE(FIRMWARE_8168D_2); |
|
771 MODULE_FIRMWARE(FIRMWARE_8168E_1); |
|
772 MODULE_FIRMWARE(FIRMWARE_8168E_2); |
|
773 MODULE_FIRMWARE(FIRMWARE_8168E_3); |
|
774 MODULE_FIRMWARE(FIRMWARE_8105E_1); |
|
775 MODULE_FIRMWARE(FIRMWARE_8168F_1); |
|
776 MODULE_FIRMWARE(FIRMWARE_8168F_2); |
|
777 |
|
778 static void rtl_lock_work(struct rtl8169_private *tp) |
|
779 { |
|
780 mutex_lock(&tp->wk.mutex); |
|
781 } |
|
782 |
|
783 static void rtl_unlock_work(struct rtl8169_private *tp) |
|
784 { |
|
785 mutex_unlock(&tp->wk.mutex); |
|
786 } |
|
787 |
|
788 static void rtl_tx_performance_tweak(struct pci_dev *pdev, u16 force) |
|
789 { |
|
790 int cap = pci_pcie_cap(pdev); |
|
791 |
|
792 if (cap) { |
|
793 u16 ctl; |
|
794 |
|
795 pci_read_config_word(pdev, cap + PCI_EXP_DEVCTL, &ctl); |
|
796 ctl = (ctl & ~PCI_EXP_DEVCTL_READRQ) | force; |
|
797 pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, ctl); |
|
798 } |
|
799 } |
|
800 |
|
801 static u32 ocp_read(struct rtl8169_private *tp, u8 mask, u16 reg) |
|
802 { |
|
803 void __iomem *ioaddr = tp->mmio_addr; |
|
804 int i; |
|
805 |
|
806 RTL_W32(OCPAR, ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
|
807 for (i = 0; i < 20; i++) { |
|
808 udelay(100); |
|
809 if (RTL_R32(OCPAR) & OCPAR_FLAG) |
|
810 break; |
|
811 } |
|
812 return RTL_R32(OCPDR); |
|
813 } |
|
814 |
|
815 static void ocp_write(struct rtl8169_private *tp, u8 mask, u16 reg, u32 data) |
|
816 { |
|
817 void __iomem *ioaddr = tp->mmio_addr; |
|
818 int i; |
|
819 |
|
820 RTL_W32(OCPDR, data); |
|
821 RTL_W32(OCPAR, OCPAR_FLAG | ((u32)mask & 0x0f) << 12 | (reg & 0x0fff)); |
|
822 for (i = 0; i < 20; i++) { |
|
823 udelay(100); |
|
824 if ((RTL_R32(OCPAR) & OCPAR_FLAG) == 0) |
|
825 break; |
|
826 } |
|
827 } |
|
828 |
|
829 static void rtl8168_oob_notify(struct rtl8169_private *tp, u8 cmd) |
|
830 { |
|
831 void __iomem *ioaddr = tp->mmio_addr; |
|
832 int i; |
|
833 |
|
834 RTL_W8(ERIDR, cmd); |
|
835 RTL_W32(ERIAR, 0x800010e8); |
|
836 msleep(2); |
|
837 for (i = 0; i < 5; i++) { |
|
838 udelay(100); |
|
839 if (!(RTL_R32(ERIAR) & ERIAR_FLAG)) |
|
840 break; |
|
841 } |
|
842 |
|
843 ocp_write(tp, 0x1, 0x30, 0x00000001); |
|
844 } |
|
845 |
|
846 #define OOB_CMD_RESET 0x00 |
|
847 #define OOB_CMD_DRIVER_START 0x05 |
|
848 #define OOB_CMD_DRIVER_STOP 0x06 |
|
849 |
|
850 static u16 rtl8168_get_ocp_reg(struct rtl8169_private *tp) |
|
851 { |
|
852 return (tp->mac_version == RTL_GIGA_MAC_VER_31) ? 0xb8 : 0x10; |
|
853 } |
|
854 |
|
855 static void rtl8168_driver_start(struct rtl8169_private *tp) |
|
856 { |
|
857 u16 reg; |
|
858 int i; |
|
859 |
|
860 rtl8168_oob_notify(tp, OOB_CMD_DRIVER_START); |
|
861 |
|
862 reg = rtl8168_get_ocp_reg(tp); |
|
863 |
|
864 for (i = 0; i < 10; i++) { |
|
865 msleep(10); |
|
866 if (ocp_read(tp, 0x0f, reg) & 0x00000800) |
|
867 break; |
|
868 } |
|
869 } |
|
870 |
|
871 static void rtl8168_driver_stop(struct rtl8169_private *tp) |
|
872 { |
|
873 u16 reg; |
|
874 int i; |
|
875 |
|
876 rtl8168_oob_notify(tp, OOB_CMD_DRIVER_STOP); |
|
877 |
|
878 reg = rtl8168_get_ocp_reg(tp); |
|
879 |
|
880 for (i = 0; i < 10; i++) { |
|
881 msleep(10); |
|
882 if ((ocp_read(tp, 0x0f, reg) & 0x00000800) == 0) |
|
883 break; |
|
884 } |
|
885 } |
|
886 |
|
887 static int r8168dp_check_dash(struct rtl8169_private *tp) |
|
888 { |
|
889 u16 reg = rtl8168_get_ocp_reg(tp); |
|
890 |
|
891 return (ocp_read(tp, 0x0f, reg) & 0x00008000) ? 1 : 0; |
|
892 } |
|
893 |
|
894 static void r8169_mdio_write(void __iomem *ioaddr, int reg_addr, int value) |
|
895 { |
|
896 int i; |
|
897 |
|
898 RTL_W32(PHYAR, 0x80000000 | (reg_addr & 0x1f) << 16 | (value & 0xffff)); |
|
899 |
|
900 for (i = 20; i > 0; i--) { |
|
901 /* |
|
902 * Check if the RTL8169 has completed writing to the specified |
|
903 * MII register. |
|
904 */ |
|
905 if (!(RTL_R32(PHYAR) & 0x80000000)) |
|
906 break; |
|
907 udelay(25); |
|
908 } |
|
909 /* |
|
910 * According to hardware specs a 20us delay is required after write |
|
911 * complete indication, but before sending next command. |
|
912 */ |
|
913 udelay(20); |
|
914 } |
|
915 |
|
916 static int r8169_mdio_read(void __iomem *ioaddr, int reg_addr) |
|
917 { |
|
918 int i, value = -1; |
|
919 |
|
920 RTL_W32(PHYAR, 0x0 | (reg_addr & 0x1f) << 16); |
|
921 |
|
922 for (i = 20; i > 0; i--) { |
|
923 /* |
|
924 * Check if the RTL8169 has completed retrieving data from |
|
925 * the specified MII register. |
|
926 */ |
|
927 if (RTL_R32(PHYAR) & 0x80000000) { |
|
928 value = RTL_R32(PHYAR) & 0xffff; |
|
929 break; |
|
930 } |
|
931 udelay(25); |
|
932 } |
|
933 /* |
|
934 * According to hardware specs a 20us delay is required after read |
|
935 * complete indication, but before sending next command. |
|
936 */ |
|
937 udelay(20); |
|
938 |
|
939 return value; |
|
940 } |
|
941 |
|
942 static void r8168dp_1_mdio_access(void __iomem *ioaddr, int reg_addr, u32 data) |
|
943 { |
|
944 int i; |
|
945 |
|
946 RTL_W32(OCPDR, data | |
|
947 ((reg_addr & OCPDR_REG_MASK) << OCPDR_GPHY_REG_SHIFT)); |
|
948 RTL_W32(OCPAR, OCPAR_GPHY_WRITE_CMD); |
|
949 RTL_W32(EPHY_RXER_NUM, 0); |
|
950 |
|
951 for (i = 0; i < 100; i++) { |
|
952 mdelay(1); |
|
953 if (!(RTL_R32(OCPAR) & OCPAR_FLAG)) |
|
954 break; |
|
955 } |
|
956 } |
|
957 |
|
958 static void r8168dp_1_mdio_write(void __iomem *ioaddr, int reg_addr, int value) |
|
959 { |
|
960 r8168dp_1_mdio_access(ioaddr, reg_addr, OCPDR_WRITE_CMD | |
|
961 (value & OCPDR_DATA_MASK)); |
|
962 } |
|
963 |
|
964 static int r8168dp_1_mdio_read(void __iomem *ioaddr, int reg_addr) |
|
965 { |
|
966 int i; |
|
967 |
|
968 r8168dp_1_mdio_access(ioaddr, reg_addr, OCPDR_READ_CMD); |
|
969 |
|
970 mdelay(1); |
|
971 RTL_W32(OCPAR, OCPAR_GPHY_READ_CMD); |
|
972 RTL_W32(EPHY_RXER_NUM, 0); |
|
973 |
|
974 for (i = 0; i < 100; i++) { |
|
975 mdelay(1); |
|
976 if (RTL_R32(OCPAR) & OCPAR_FLAG) |
|
977 break; |
|
978 } |
|
979 |
|
980 return RTL_R32(OCPDR) & OCPDR_DATA_MASK; |
|
981 } |
|
982 |
|
983 #define R8168DP_1_MDIO_ACCESS_BIT 0x00020000 |
|
984 |
|
985 static void r8168dp_2_mdio_start(void __iomem *ioaddr) |
|
986 { |
|
987 RTL_W32(0xd0, RTL_R32(0xd0) & ~R8168DP_1_MDIO_ACCESS_BIT); |
|
988 } |
|
989 |
|
990 static void r8168dp_2_mdio_stop(void __iomem *ioaddr) |
|
991 { |
|
992 RTL_W32(0xd0, RTL_R32(0xd0) | R8168DP_1_MDIO_ACCESS_BIT); |
|
993 } |
|
994 |
|
995 static void r8168dp_2_mdio_write(void __iomem *ioaddr, int reg_addr, int value) |
|
996 { |
|
997 r8168dp_2_mdio_start(ioaddr); |
|
998 |
|
999 r8169_mdio_write(ioaddr, reg_addr, value); |
|
1000 |
|
1001 r8168dp_2_mdio_stop(ioaddr); |
|
1002 } |
|
1003 |
|
1004 static int r8168dp_2_mdio_read(void __iomem *ioaddr, int reg_addr) |
|
1005 { |
|
1006 int value; |
|
1007 |
|
1008 r8168dp_2_mdio_start(ioaddr); |
|
1009 |
|
1010 value = r8169_mdio_read(ioaddr, reg_addr); |
|
1011 |
|
1012 r8168dp_2_mdio_stop(ioaddr); |
|
1013 |
|
1014 return value; |
|
1015 } |
|
1016 |
|
1017 static void rtl_writephy(struct rtl8169_private *tp, int location, u32 val) |
|
1018 { |
|
1019 tp->mdio_ops.write(tp->mmio_addr, location, val); |
|
1020 } |
|
1021 |
|
1022 static int rtl_readphy(struct rtl8169_private *tp, int location) |
|
1023 { |
|
1024 return tp->mdio_ops.read(tp->mmio_addr, location); |
|
1025 } |
|
1026 |
|
1027 static void rtl_patchphy(struct rtl8169_private *tp, int reg_addr, int value) |
|
1028 { |
|
1029 rtl_writephy(tp, reg_addr, rtl_readphy(tp, reg_addr) | value); |
|
1030 } |
|
1031 |
|
1032 static void rtl_w1w0_phy(struct rtl8169_private *tp, int reg_addr, int p, int m) |
|
1033 { |
|
1034 int val; |
|
1035 |
|
1036 val = rtl_readphy(tp, reg_addr); |
|
1037 rtl_writephy(tp, reg_addr, (val | p) & ~m); |
|
1038 } |
|
1039 |
|
1040 static void rtl_mdio_write(struct net_device *dev, int phy_id, int location, |
|
1041 int val) |
|
1042 { |
|
1043 struct rtl8169_private *tp = netdev_priv(dev); |
|
1044 |
|
1045 rtl_writephy(tp, location, val); |
|
1046 } |
|
1047 |
|
1048 static int rtl_mdio_read(struct net_device *dev, int phy_id, int location) |
|
1049 { |
|
1050 struct rtl8169_private *tp = netdev_priv(dev); |
|
1051 |
|
1052 return rtl_readphy(tp, location); |
|
1053 } |
|
1054 |
|
1055 static void rtl_ephy_write(void __iomem *ioaddr, int reg_addr, int value) |
|
1056 { |
|
1057 unsigned int i; |
|
1058 |
|
1059 RTL_W32(EPHYAR, EPHYAR_WRITE_CMD | (value & EPHYAR_DATA_MASK) | |
|
1060 (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
|
1061 |
|
1062 for (i = 0; i < 100; i++) { |
|
1063 if (!(RTL_R32(EPHYAR) & EPHYAR_FLAG)) |
|
1064 break; |
|
1065 udelay(10); |
|
1066 } |
|
1067 } |
|
1068 |
|
1069 static u16 rtl_ephy_read(void __iomem *ioaddr, int reg_addr) |
|
1070 { |
|
1071 u16 value = 0xffff; |
|
1072 unsigned int i; |
|
1073 |
|
1074 RTL_W32(EPHYAR, (reg_addr & EPHYAR_REG_MASK) << EPHYAR_REG_SHIFT); |
|
1075 |
|
1076 for (i = 0; i < 100; i++) { |
|
1077 if (RTL_R32(EPHYAR) & EPHYAR_FLAG) { |
|
1078 value = RTL_R32(EPHYAR) & EPHYAR_DATA_MASK; |
|
1079 break; |
|
1080 } |
|
1081 udelay(10); |
|
1082 } |
|
1083 |
|
1084 return value; |
|
1085 } |
|
1086 |
|
1087 static void rtl_csi_write(void __iomem *ioaddr, int addr, int value) |
|
1088 { |
|
1089 unsigned int i; |
|
1090 |
|
1091 RTL_W32(CSIDR, value); |
|
1092 RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
|
1093 CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
|
1094 |
|
1095 for (i = 0; i < 100; i++) { |
|
1096 if (!(RTL_R32(CSIAR) & CSIAR_FLAG)) |
|
1097 break; |
|
1098 udelay(10); |
|
1099 } |
|
1100 } |
|
1101 |
|
1102 static u32 rtl_csi_read(void __iomem *ioaddr, int addr) |
|
1103 { |
|
1104 u32 value = ~0x00; |
|
1105 unsigned int i; |
|
1106 |
|
1107 RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) | |
|
1108 CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
|
1109 |
|
1110 for (i = 0; i < 100; i++) { |
|
1111 if (RTL_R32(CSIAR) & CSIAR_FLAG) { |
|
1112 value = RTL_R32(CSIDR); |
|
1113 break; |
|
1114 } |
|
1115 udelay(10); |
|
1116 } |
|
1117 |
|
1118 return value; |
|
1119 } |
|
1120 |
|
1121 static |
|
1122 void rtl_eri_write(void __iomem *ioaddr, int addr, u32 mask, u32 val, int type) |
|
1123 { |
|
1124 unsigned int i; |
|
1125 |
|
1126 BUG_ON((addr & 3) || (mask == 0)); |
|
1127 RTL_W32(ERIDR, val); |
|
1128 RTL_W32(ERIAR, ERIAR_WRITE_CMD | type | mask | addr); |
|
1129 |
|
1130 for (i = 0; i < 100; i++) { |
|
1131 if (!(RTL_R32(ERIAR) & ERIAR_FLAG)) |
|
1132 break; |
|
1133 udelay(100); |
|
1134 } |
|
1135 } |
|
1136 |
|
1137 static u32 rtl_eri_read(void __iomem *ioaddr, int addr, int type) |
|
1138 { |
|
1139 u32 value = ~0x00; |
|
1140 unsigned int i; |
|
1141 |
|
1142 RTL_W32(ERIAR, ERIAR_READ_CMD | type | ERIAR_MASK_1111 | addr); |
|
1143 |
|
1144 for (i = 0; i < 100; i++) { |
|
1145 if (RTL_R32(ERIAR) & ERIAR_FLAG) { |
|
1146 value = RTL_R32(ERIDR); |
|
1147 break; |
|
1148 } |
|
1149 udelay(100); |
|
1150 } |
|
1151 |
|
1152 return value; |
|
1153 } |
|
1154 |
|
1155 static void |
|
1156 rtl_w1w0_eri(void __iomem *ioaddr, int addr, u32 mask, u32 p, u32 m, int type) |
|
1157 { |
|
1158 u32 val; |
|
1159 |
|
1160 val = rtl_eri_read(ioaddr, addr, type); |
|
1161 rtl_eri_write(ioaddr, addr, mask, (val & ~m) | p, type); |
|
1162 } |
|
1163 |
|
1164 struct exgmac_reg { |
|
1165 u16 addr; |
|
1166 u16 mask; |
|
1167 u32 val; |
|
1168 }; |
|
1169 |
|
1170 static void rtl_write_exgmac_batch(void __iomem *ioaddr, |
|
1171 const struct exgmac_reg *r, int len) |
|
1172 { |
|
1173 while (len-- > 0) { |
|
1174 rtl_eri_write(ioaddr, r->addr, r->mask, r->val, ERIAR_EXGMAC); |
|
1175 r++; |
|
1176 } |
|
1177 } |
|
1178 |
|
1179 static u8 rtl8168d_efuse_read(void __iomem *ioaddr, int reg_addr) |
|
1180 { |
|
1181 u8 value = 0xff; |
|
1182 unsigned int i; |
|
1183 |
|
1184 RTL_W32(EFUSEAR, (reg_addr & EFUSEAR_REG_MASK) << EFUSEAR_REG_SHIFT); |
|
1185 |
|
1186 for (i = 0; i < 300; i++) { |
|
1187 if (RTL_R32(EFUSEAR) & EFUSEAR_FLAG) { |
|
1188 value = RTL_R32(EFUSEAR) & EFUSEAR_DATA_MASK; |
|
1189 break; |
|
1190 } |
|
1191 udelay(100); |
|
1192 } |
|
1193 |
|
1194 return value; |
|
1195 } |
|
1196 |
|
1197 static u16 rtl_get_events(struct rtl8169_private *tp) |
|
1198 { |
|
1199 void __iomem *ioaddr = tp->mmio_addr; |
|
1200 |
|
1201 return RTL_R16(IntrStatus); |
|
1202 } |
|
1203 |
|
1204 static void rtl_ack_events(struct rtl8169_private *tp, u16 bits) |
|
1205 { |
|
1206 void __iomem *ioaddr = tp->mmio_addr; |
|
1207 |
|
1208 RTL_W16(IntrStatus, bits); |
|
1209 mmiowb(); |
|
1210 } |
|
1211 |
|
1212 static void rtl_irq_disable(struct rtl8169_private *tp) |
|
1213 { |
|
1214 void __iomem *ioaddr = tp->mmio_addr; |
|
1215 |
|
1216 RTL_W16(IntrMask, 0); |
|
1217 mmiowb(); |
|
1218 } |
|
1219 |
|
1220 static void rtl_irq_enable(struct rtl8169_private *tp, u16 bits) |
|
1221 { |
|
1222 void __iomem *ioaddr = tp->mmio_addr; |
|
1223 |
|
1224 RTL_W16(IntrMask, bits); |
|
1225 } |
|
1226 |
|
1227 #define RTL_EVENT_NAPI_RX (RxOK | RxErr) |
|
1228 #define RTL_EVENT_NAPI_TX (TxOK | TxErr) |
|
1229 #define RTL_EVENT_NAPI (RTL_EVENT_NAPI_RX | RTL_EVENT_NAPI_TX) |
|
1230 |
|
1231 static void rtl_irq_enable_all(struct rtl8169_private *tp) |
|
1232 { |
|
1233 rtl_irq_enable(tp, RTL_EVENT_NAPI | tp->event_slow); |
|
1234 } |
|
1235 |
|
1236 static void rtl8169_irq_mask_and_ack(struct rtl8169_private *tp) |
|
1237 { |
|
1238 void __iomem *ioaddr = tp->mmio_addr; |
|
1239 |
|
1240 rtl_irq_disable(tp); |
|
1241 rtl_ack_events(tp, RTL_EVENT_NAPI | tp->event_slow); |
|
1242 RTL_R8(ChipCmd); |
|
1243 } |
|
1244 |
|
1245 static unsigned int rtl8169_tbi_reset_pending(struct rtl8169_private *tp) |
|
1246 { |
|
1247 void __iomem *ioaddr = tp->mmio_addr; |
|
1248 |
|
1249 return RTL_R32(TBICSR) & TBIReset; |
|
1250 } |
|
1251 |
|
1252 static unsigned int rtl8169_xmii_reset_pending(struct rtl8169_private *tp) |
|
1253 { |
|
1254 return rtl_readphy(tp, MII_BMCR) & BMCR_RESET; |
|
1255 } |
|
1256 |
|
1257 static unsigned int rtl8169_tbi_link_ok(void __iomem *ioaddr) |
|
1258 { |
|
1259 return RTL_R32(TBICSR) & TBILinkOk; |
|
1260 } |
|
1261 |
|
1262 static unsigned int rtl8169_xmii_link_ok(void __iomem *ioaddr) |
|
1263 { |
|
1264 return RTL_R8(PHYstatus) & LinkStatus; |
|
1265 } |
|
1266 |
|
1267 static void rtl8169_tbi_reset_enable(struct rtl8169_private *tp) |
|
1268 { |
|
1269 void __iomem *ioaddr = tp->mmio_addr; |
|
1270 |
|
1271 RTL_W32(TBICSR, RTL_R32(TBICSR) | TBIReset); |
|
1272 } |
|
1273 |
|
1274 static void rtl8169_xmii_reset_enable(struct rtl8169_private *tp) |
|
1275 { |
|
1276 unsigned int val; |
|
1277 |
|
1278 val = rtl_readphy(tp, MII_BMCR) | BMCR_RESET; |
|
1279 rtl_writephy(tp, MII_BMCR, val & 0xffff); |
|
1280 } |
|
1281 |
|
1282 static void rtl_link_chg_patch(struct rtl8169_private *tp) |
|
1283 { |
|
1284 void __iomem *ioaddr = tp->mmio_addr; |
|
1285 struct net_device *dev = tp->dev; |
|
1286 |
|
1287 if (!netif_running(dev)) |
|
1288 return; |
|
1289 |
|
1290 if (tp->mac_version == RTL_GIGA_MAC_VER_34) { |
|
1291 if (RTL_R8(PHYstatus) & _1000bpsF) { |
|
1292 rtl_eri_write(ioaddr, 0x1bc, ERIAR_MASK_1111, |
|
1293 0x00000011, ERIAR_EXGMAC); |
|
1294 rtl_eri_write(ioaddr, 0x1dc, ERIAR_MASK_1111, |
|
1295 0x00000005, ERIAR_EXGMAC); |
|
1296 } else if (RTL_R8(PHYstatus) & _100bps) { |
|
1297 rtl_eri_write(ioaddr, 0x1bc, ERIAR_MASK_1111, |
|
1298 0x0000001f, ERIAR_EXGMAC); |
|
1299 rtl_eri_write(ioaddr, 0x1dc, ERIAR_MASK_1111, |
|
1300 0x00000005, ERIAR_EXGMAC); |
|
1301 } else { |
|
1302 rtl_eri_write(ioaddr, 0x1bc, ERIAR_MASK_1111, |
|
1303 0x0000001f, ERIAR_EXGMAC); |
|
1304 rtl_eri_write(ioaddr, 0x1dc, ERIAR_MASK_1111, |
|
1305 0x0000003f, ERIAR_EXGMAC); |
|
1306 } |
|
1307 /* Reset packet filter */ |
|
1308 rtl_w1w0_eri(ioaddr, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, |
|
1309 ERIAR_EXGMAC); |
|
1310 rtl_w1w0_eri(ioaddr, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, |
|
1311 ERIAR_EXGMAC); |
|
1312 } else if (tp->mac_version == RTL_GIGA_MAC_VER_35 || |
|
1313 tp->mac_version == RTL_GIGA_MAC_VER_36) { |
|
1314 if (RTL_R8(PHYstatus) & _1000bpsF) { |
|
1315 rtl_eri_write(ioaddr, 0x1bc, ERIAR_MASK_1111, |
|
1316 0x00000011, ERIAR_EXGMAC); |
|
1317 rtl_eri_write(ioaddr, 0x1dc, ERIAR_MASK_1111, |
|
1318 0x00000005, ERIAR_EXGMAC); |
|
1319 } else { |
|
1320 rtl_eri_write(ioaddr, 0x1bc, ERIAR_MASK_1111, |
|
1321 0x0000001f, ERIAR_EXGMAC); |
|
1322 rtl_eri_write(ioaddr, 0x1dc, ERIAR_MASK_1111, |
|
1323 0x0000003f, ERIAR_EXGMAC); |
|
1324 } |
|
1325 } |
|
1326 } |
|
1327 |
|
1328 static void __rtl8169_check_link_status(struct net_device *dev, |
|
1329 struct rtl8169_private *tp, |
|
1330 void __iomem *ioaddr, bool pm) |
|
1331 { |
|
1332 if (tp->link_ok(ioaddr)) { |
|
1333 rtl_link_chg_patch(tp); |
|
1334 /* This is to cancel a scheduled suspend if there's one. */ |
|
1335 if (pm) |
|
1336 pm_request_resume(&tp->pci_dev->dev); |
|
1337 netif_carrier_on(dev); |
|
1338 if (net_ratelimit()) |
|
1339 netif_info(tp, ifup, dev, "link up\n"); |
|
1340 } else { |
|
1341 netif_carrier_off(dev); |
|
1342 netif_info(tp, ifdown, dev, "link down\n"); |
|
1343 if (pm) |
|
1344 pm_schedule_suspend(&tp->pci_dev->dev, 5000); |
|
1345 } |
|
1346 } |
|
1347 |
|
1348 static void rtl8169_check_link_status(struct net_device *dev, |
|
1349 struct rtl8169_private *tp, |
|
1350 void __iomem *ioaddr) |
|
1351 { |
|
1352 __rtl8169_check_link_status(dev, tp, ioaddr, false); |
|
1353 } |
|
1354 |
|
1355 #define WAKE_ANY (WAKE_PHY | WAKE_MAGIC | WAKE_UCAST | WAKE_BCAST | WAKE_MCAST) |
|
1356 |
|
1357 static u32 __rtl8169_get_wol(struct rtl8169_private *tp) |
|
1358 { |
|
1359 void __iomem *ioaddr = tp->mmio_addr; |
|
1360 u8 options; |
|
1361 u32 wolopts = 0; |
|
1362 |
|
1363 options = RTL_R8(Config1); |
|
1364 if (!(options & PMEnable)) |
|
1365 return 0; |
|
1366 |
|
1367 options = RTL_R8(Config3); |
|
1368 if (options & LinkUp) |
|
1369 wolopts |= WAKE_PHY; |
|
1370 if (options & MagicPacket) |
|
1371 wolopts |= WAKE_MAGIC; |
|
1372 |
|
1373 options = RTL_R8(Config5); |
|
1374 if (options & UWF) |
|
1375 wolopts |= WAKE_UCAST; |
|
1376 if (options & BWF) |
|
1377 wolopts |= WAKE_BCAST; |
|
1378 if (options & MWF) |
|
1379 wolopts |= WAKE_MCAST; |
|
1380 |
|
1381 return wolopts; |
|
1382 } |
|
1383 |
|
1384 static void rtl8169_get_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
|
1385 { |
|
1386 struct rtl8169_private *tp = netdev_priv(dev); |
|
1387 |
|
1388 rtl_lock_work(tp); |
|
1389 |
|
1390 wol->supported = WAKE_ANY; |
|
1391 wol->wolopts = __rtl8169_get_wol(tp); |
|
1392 |
|
1393 rtl_unlock_work(tp); |
|
1394 } |
|
1395 |
|
1396 static void __rtl8169_set_wol(struct rtl8169_private *tp, u32 wolopts) |
|
1397 { |
|
1398 void __iomem *ioaddr = tp->mmio_addr; |
|
1399 unsigned int i; |
|
1400 static const struct { |
|
1401 u32 opt; |
|
1402 u16 reg; |
|
1403 u8 mask; |
|
1404 } cfg[] = { |
|
1405 { WAKE_PHY, Config3, LinkUp }, |
|
1406 { WAKE_MAGIC, Config3, MagicPacket }, |
|
1407 { WAKE_UCAST, Config5, UWF }, |
|
1408 { WAKE_BCAST, Config5, BWF }, |
|
1409 { WAKE_MCAST, Config5, MWF }, |
|
1410 { WAKE_ANY, Config5, LanWake } |
|
1411 }; |
|
1412 u8 options; |
|
1413 |
|
1414 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
1415 |
|
1416 for (i = 0; i < ARRAY_SIZE(cfg); i++) { |
|
1417 options = RTL_R8(cfg[i].reg) & ~cfg[i].mask; |
|
1418 if (wolopts & cfg[i].opt) |
|
1419 options |= cfg[i].mask; |
|
1420 RTL_W8(cfg[i].reg, options); |
|
1421 } |
|
1422 |
|
1423 switch (tp->mac_version) { |
|
1424 case RTL_GIGA_MAC_VER_01 ... RTL_GIGA_MAC_VER_17: |
|
1425 options = RTL_R8(Config1) & ~PMEnable; |
|
1426 if (wolopts) |
|
1427 options |= PMEnable; |
|
1428 RTL_W8(Config1, options); |
|
1429 break; |
|
1430 default: |
|
1431 options = RTL_R8(Config2) & ~PME_SIGNAL; |
|
1432 if (wolopts) |
|
1433 options |= PME_SIGNAL; |
|
1434 RTL_W8(Config2, options); |
|
1435 break; |
|
1436 } |
|
1437 |
|
1438 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
1439 } |
|
1440 |
|
1441 static int rtl8169_set_wol(struct net_device *dev, struct ethtool_wolinfo *wol) |
|
1442 { |
|
1443 struct rtl8169_private *tp = netdev_priv(dev); |
|
1444 |
|
1445 rtl_lock_work(tp); |
|
1446 |
|
1447 if (wol->wolopts) |
|
1448 tp->features |= RTL_FEATURE_WOL; |
|
1449 else |
|
1450 tp->features &= ~RTL_FEATURE_WOL; |
|
1451 __rtl8169_set_wol(tp, wol->wolopts); |
|
1452 |
|
1453 rtl_unlock_work(tp); |
|
1454 |
|
1455 device_set_wakeup_enable(&tp->pci_dev->dev, wol->wolopts); |
|
1456 |
|
1457 return 0; |
|
1458 } |
|
1459 |
|
1460 static const char *rtl_lookup_firmware_name(struct rtl8169_private *tp) |
|
1461 { |
|
1462 return rtl_chip_infos[tp->mac_version].fw_name; |
|
1463 } |
|
1464 |
|
1465 static void rtl8169_get_drvinfo(struct net_device *dev, |
|
1466 struct ethtool_drvinfo *info) |
|
1467 { |
|
1468 struct rtl8169_private *tp = netdev_priv(dev); |
|
1469 struct rtl_fw *rtl_fw = tp->rtl_fw; |
|
1470 |
|
1471 strlcpy(info->driver, MODULENAME, sizeof(info->driver)); |
|
1472 strlcpy(info->version, RTL8169_VERSION, sizeof(info->version)); |
|
1473 strlcpy(info->bus_info, pci_name(tp->pci_dev), sizeof(info->bus_info)); |
|
1474 BUILD_BUG_ON(sizeof(info->fw_version) < sizeof(rtl_fw->version)); |
|
1475 if (!IS_ERR_OR_NULL(rtl_fw)) |
|
1476 strlcpy(info->fw_version, rtl_fw->version, |
|
1477 sizeof(info->fw_version)); |
|
1478 } |
|
1479 |
|
1480 static int rtl8169_get_regs_len(struct net_device *dev) |
|
1481 { |
|
1482 return R8169_REGS_SIZE; |
|
1483 } |
|
1484 |
|
1485 static int rtl8169_set_speed_tbi(struct net_device *dev, |
|
1486 u8 autoneg, u16 speed, u8 duplex, u32 ignored) |
|
1487 { |
|
1488 struct rtl8169_private *tp = netdev_priv(dev); |
|
1489 void __iomem *ioaddr = tp->mmio_addr; |
|
1490 int ret = 0; |
|
1491 u32 reg; |
|
1492 |
|
1493 reg = RTL_R32(TBICSR); |
|
1494 if ((autoneg == AUTONEG_DISABLE) && (speed == SPEED_1000) && |
|
1495 (duplex == DUPLEX_FULL)) { |
|
1496 RTL_W32(TBICSR, reg & ~(TBINwEnable | TBINwRestart)); |
|
1497 } else if (autoneg == AUTONEG_ENABLE) |
|
1498 RTL_W32(TBICSR, reg | TBINwEnable | TBINwRestart); |
|
1499 else { |
|
1500 netif_warn(tp, link, dev, |
|
1501 "incorrect speed setting refused in TBI mode\n"); |
|
1502 ret = -EOPNOTSUPP; |
|
1503 } |
|
1504 |
|
1505 return ret; |
|
1506 } |
|
1507 |
|
1508 static int rtl8169_set_speed_xmii(struct net_device *dev, |
|
1509 u8 autoneg, u16 speed, u8 duplex, u32 adv) |
|
1510 { |
|
1511 struct rtl8169_private *tp = netdev_priv(dev); |
|
1512 int giga_ctrl, bmcr; |
|
1513 int rc = -EINVAL; |
|
1514 |
|
1515 rtl_writephy(tp, 0x1f, 0x0000); |
|
1516 |
|
1517 if (autoneg == AUTONEG_ENABLE) { |
|
1518 int auto_nego; |
|
1519 |
|
1520 auto_nego = rtl_readphy(tp, MII_ADVERTISE); |
|
1521 auto_nego &= ~(ADVERTISE_10HALF | ADVERTISE_10FULL | |
|
1522 ADVERTISE_100HALF | ADVERTISE_100FULL); |
|
1523 |
|
1524 if (adv & ADVERTISED_10baseT_Half) |
|
1525 auto_nego |= ADVERTISE_10HALF; |
|
1526 if (adv & ADVERTISED_10baseT_Full) |
|
1527 auto_nego |= ADVERTISE_10FULL; |
|
1528 if (adv & ADVERTISED_100baseT_Half) |
|
1529 auto_nego |= ADVERTISE_100HALF; |
|
1530 if (adv & ADVERTISED_100baseT_Full) |
|
1531 auto_nego |= ADVERTISE_100FULL; |
|
1532 |
|
1533 auto_nego |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
|
1534 |
|
1535 giga_ctrl = rtl_readphy(tp, MII_CTRL1000); |
|
1536 giga_ctrl &= ~(ADVERTISE_1000FULL | ADVERTISE_1000HALF); |
|
1537 |
|
1538 /* The 8100e/8101e/8102e do Fast Ethernet only. */ |
|
1539 if (tp->mii.supports_gmii) { |
|
1540 if (adv & ADVERTISED_1000baseT_Half) |
|
1541 giga_ctrl |= ADVERTISE_1000HALF; |
|
1542 if (adv & ADVERTISED_1000baseT_Full) |
|
1543 giga_ctrl |= ADVERTISE_1000FULL; |
|
1544 } else if (adv & (ADVERTISED_1000baseT_Half | |
|
1545 ADVERTISED_1000baseT_Full)) { |
|
1546 netif_info(tp, link, dev, |
|
1547 "PHY does not support 1000Mbps\n"); |
|
1548 goto out; |
|
1549 } |
|
1550 |
|
1551 bmcr = BMCR_ANENABLE | BMCR_ANRESTART; |
|
1552 |
|
1553 rtl_writephy(tp, MII_ADVERTISE, auto_nego); |
|
1554 rtl_writephy(tp, MII_CTRL1000, giga_ctrl); |
|
1555 } else { |
|
1556 giga_ctrl = 0; |
|
1557 |
|
1558 if (speed == SPEED_10) |
|
1559 bmcr = 0; |
|
1560 else if (speed == SPEED_100) |
|
1561 bmcr = BMCR_SPEED100; |
|
1562 else |
|
1563 goto out; |
|
1564 |
|
1565 if (duplex == DUPLEX_FULL) |
|
1566 bmcr |= BMCR_FULLDPLX; |
|
1567 } |
|
1568 |
|
1569 rtl_writephy(tp, MII_BMCR, bmcr); |
|
1570 |
|
1571 if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
|
1572 tp->mac_version == RTL_GIGA_MAC_VER_03) { |
|
1573 if ((speed == SPEED_100) && (autoneg != AUTONEG_ENABLE)) { |
|
1574 rtl_writephy(tp, 0x17, 0x2138); |
|
1575 rtl_writephy(tp, 0x0e, 0x0260); |
|
1576 } else { |
|
1577 rtl_writephy(tp, 0x17, 0x2108); |
|
1578 rtl_writephy(tp, 0x0e, 0x0000); |
|
1579 } |
|
1580 } |
|
1581 |
|
1582 rc = 0; |
|
1583 out: |
|
1584 return rc; |
|
1585 } |
|
1586 |
|
1587 static int rtl8169_set_speed(struct net_device *dev, |
|
1588 u8 autoneg, u16 speed, u8 duplex, u32 advertising) |
|
1589 { |
|
1590 struct rtl8169_private *tp = netdev_priv(dev); |
|
1591 int ret; |
|
1592 |
|
1593 ret = tp->set_speed(dev, autoneg, speed, duplex, advertising); |
|
1594 if (ret < 0) |
|
1595 goto out; |
|
1596 |
|
1597 if (netif_running(dev) && (autoneg == AUTONEG_ENABLE) && |
|
1598 (advertising & ADVERTISED_1000baseT_Full)) { |
|
1599 mod_timer(&tp->timer, jiffies + RTL8169_PHY_TIMEOUT); |
|
1600 } |
|
1601 out: |
|
1602 return ret; |
|
1603 } |
|
1604 |
|
1605 static int rtl8169_set_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
|
1606 { |
|
1607 struct rtl8169_private *tp = netdev_priv(dev); |
|
1608 int ret; |
|
1609 |
|
1610 del_timer_sync(&tp->timer); |
|
1611 |
|
1612 rtl_lock_work(tp); |
|
1613 ret = rtl8169_set_speed(dev, cmd->autoneg, ethtool_cmd_speed(cmd), |
|
1614 cmd->duplex, cmd->advertising); |
|
1615 rtl_unlock_work(tp); |
|
1616 |
|
1617 return ret; |
|
1618 } |
|
1619 |
|
1620 static netdev_features_t rtl8169_fix_features(struct net_device *dev, |
|
1621 netdev_features_t features) |
|
1622 { |
|
1623 struct rtl8169_private *tp = netdev_priv(dev); |
|
1624 |
|
1625 if (dev->mtu > TD_MSS_MAX) |
|
1626 features &= ~NETIF_F_ALL_TSO; |
|
1627 |
|
1628 if (dev->mtu > JUMBO_1K && |
|
1629 !rtl_chip_infos[tp->mac_version].jumbo_tx_csum) |
|
1630 features &= ~NETIF_F_IP_CSUM; |
|
1631 |
|
1632 return features; |
|
1633 } |
|
1634 |
|
1635 static void __rtl8169_set_features(struct net_device *dev, |
|
1636 netdev_features_t features) |
|
1637 { |
|
1638 struct rtl8169_private *tp = netdev_priv(dev); |
|
1639 netdev_features_t changed = features ^ dev->features; |
|
1640 void __iomem *ioaddr = tp->mmio_addr; |
|
1641 |
|
1642 if (!(changed & (NETIF_F_RXALL | NETIF_F_RXCSUM | NETIF_F_HW_VLAN_RX))) |
|
1643 return; |
|
1644 |
|
1645 if (changed & (NETIF_F_RXCSUM | NETIF_F_HW_VLAN_RX)) { |
|
1646 if (features & NETIF_F_RXCSUM) |
|
1647 tp->cp_cmd |= RxChkSum; |
|
1648 else |
|
1649 tp->cp_cmd &= ~RxChkSum; |
|
1650 |
|
1651 if (dev->features & NETIF_F_HW_VLAN_RX) |
|
1652 tp->cp_cmd |= RxVlan; |
|
1653 else |
|
1654 tp->cp_cmd &= ~RxVlan; |
|
1655 |
|
1656 RTL_W16(CPlusCmd, tp->cp_cmd); |
|
1657 RTL_R16(CPlusCmd); |
|
1658 } |
|
1659 if (changed & NETIF_F_RXALL) { |
|
1660 int tmp = (RTL_R32(RxConfig) & ~(AcceptErr | AcceptRunt)); |
|
1661 if (features & NETIF_F_RXALL) |
|
1662 tmp |= (AcceptErr | AcceptRunt); |
|
1663 RTL_W32(RxConfig, tmp); |
|
1664 } |
|
1665 } |
|
1666 |
|
1667 static int rtl8169_set_features(struct net_device *dev, |
|
1668 netdev_features_t features) |
|
1669 { |
|
1670 struct rtl8169_private *tp = netdev_priv(dev); |
|
1671 |
|
1672 rtl_lock_work(tp); |
|
1673 __rtl8169_set_features(dev, features); |
|
1674 rtl_unlock_work(tp); |
|
1675 |
|
1676 return 0; |
|
1677 } |
|
1678 |
|
1679 |
|
1680 static inline u32 rtl8169_tx_vlan_tag(struct rtl8169_private *tp, |
|
1681 struct sk_buff *skb) |
|
1682 { |
|
1683 return (vlan_tx_tag_present(skb)) ? |
|
1684 TxVlanTag | swab16(vlan_tx_tag_get(skb)) : 0x00; |
|
1685 } |
|
1686 |
|
1687 static void rtl8169_rx_vlan_tag(struct RxDesc *desc, struct sk_buff *skb) |
|
1688 { |
|
1689 u32 opts2 = le32_to_cpu(desc->opts2); |
|
1690 |
|
1691 if (opts2 & RxVlanTag) |
|
1692 __vlan_hwaccel_put_tag(skb, swab16(opts2 & 0xffff)); |
|
1693 |
|
1694 desc->opts2 = 0; |
|
1695 } |
|
1696 |
|
1697 static int rtl8169_gset_tbi(struct net_device *dev, struct ethtool_cmd *cmd) |
|
1698 { |
|
1699 struct rtl8169_private *tp = netdev_priv(dev); |
|
1700 void __iomem *ioaddr = tp->mmio_addr; |
|
1701 u32 status; |
|
1702 |
|
1703 cmd->supported = |
|
1704 SUPPORTED_1000baseT_Full | SUPPORTED_Autoneg | SUPPORTED_FIBRE; |
|
1705 cmd->port = PORT_FIBRE; |
|
1706 cmd->transceiver = XCVR_INTERNAL; |
|
1707 |
|
1708 status = RTL_R32(TBICSR); |
|
1709 cmd->advertising = (status & TBINwEnable) ? ADVERTISED_Autoneg : 0; |
|
1710 cmd->autoneg = !!(status & TBINwEnable); |
|
1711 |
|
1712 ethtool_cmd_speed_set(cmd, SPEED_1000); |
|
1713 cmd->duplex = DUPLEX_FULL; /* Always set */ |
|
1714 |
|
1715 return 0; |
|
1716 } |
|
1717 |
|
1718 static int rtl8169_gset_xmii(struct net_device *dev, struct ethtool_cmd *cmd) |
|
1719 { |
|
1720 struct rtl8169_private *tp = netdev_priv(dev); |
|
1721 |
|
1722 return mii_ethtool_gset(&tp->mii, cmd); |
|
1723 } |
|
1724 |
|
1725 static int rtl8169_get_settings(struct net_device *dev, struct ethtool_cmd *cmd) |
|
1726 { |
|
1727 struct rtl8169_private *tp = netdev_priv(dev); |
|
1728 int rc; |
|
1729 |
|
1730 rtl_lock_work(tp); |
|
1731 rc = tp->get_settings(dev, cmd); |
|
1732 rtl_unlock_work(tp); |
|
1733 |
|
1734 return rc; |
|
1735 } |
|
1736 |
|
1737 static void rtl8169_get_regs(struct net_device *dev, struct ethtool_regs *regs, |
|
1738 void *p) |
|
1739 { |
|
1740 struct rtl8169_private *tp = netdev_priv(dev); |
|
1741 |
|
1742 if (regs->len > R8169_REGS_SIZE) |
|
1743 regs->len = R8169_REGS_SIZE; |
|
1744 |
|
1745 rtl_lock_work(tp); |
|
1746 memcpy_fromio(p, tp->mmio_addr, regs->len); |
|
1747 rtl_unlock_work(tp); |
|
1748 } |
|
1749 |
|
1750 static u32 rtl8169_get_msglevel(struct net_device *dev) |
|
1751 { |
|
1752 struct rtl8169_private *tp = netdev_priv(dev); |
|
1753 |
|
1754 return tp->msg_enable; |
|
1755 } |
|
1756 |
|
1757 static void rtl8169_set_msglevel(struct net_device *dev, u32 value) |
|
1758 { |
|
1759 struct rtl8169_private *tp = netdev_priv(dev); |
|
1760 |
|
1761 tp->msg_enable = value; |
|
1762 } |
|
1763 |
|
1764 static const char rtl8169_gstrings[][ETH_GSTRING_LEN] = { |
|
1765 "tx_packets", |
|
1766 "rx_packets", |
|
1767 "tx_errors", |
|
1768 "rx_errors", |
|
1769 "rx_missed", |
|
1770 "align_errors", |
|
1771 "tx_single_collisions", |
|
1772 "tx_multi_collisions", |
|
1773 "unicast", |
|
1774 "broadcast", |
|
1775 "multicast", |
|
1776 "tx_aborted", |
|
1777 "tx_underrun", |
|
1778 }; |
|
1779 |
|
1780 static int rtl8169_get_sset_count(struct net_device *dev, int sset) |
|
1781 { |
|
1782 switch (sset) { |
|
1783 case ETH_SS_STATS: |
|
1784 return ARRAY_SIZE(rtl8169_gstrings); |
|
1785 default: |
|
1786 return -EOPNOTSUPP; |
|
1787 } |
|
1788 } |
|
1789 |
|
1790 static void rtl8169_update_counters(struct net_device *dev) |
|
1791 { |
|
1792 struct rtl8169_private *tp = netdev_priv(dev); |
|
1793 void __iomem *ioaddr = tp->mmio_addr; |
|
1794 struct device *d = &tp->pci_dev->dev; |
|
1795 struct rtl8169_counters *counters; |
|
1796 dma_addr_t paddr; |
|
1797 u32 cmd; |
|
1798 int wait = 1000; |
|
1799 |
|
1800 /* |
|
1801 * Some chips are unable to dump tally counters when the receiver |
|
1802 * is disabled. |
|
1803 */ |
|
1804 if ((RTL_R8(ChipCmd) & CmdRxEnb) == 0) |
|
1805 return; |
|
1806 |
|
1807 counters = dma_alloc_coherent(d, sizeof(*counters), &paddr, GFP_KERNEL); |
|
1808 if (!counters) |
|
1809 return; |
|
1810 |
|
1811 RTL_W32(CounterAddrHigh, (u64)paddr >> 32); |
|
1812 cmd = (u64)paddr & DMA_BIT_MASK(32); |
|
1813 RTL_W32(CounterAddrLow, cmd); |
|
1814 RTL_W32(CounterAddrLow, cmd | CounterDump); |
|
1815 |
|
1816 while (wait--) { |
|
1817 if ((RTL_R32(CounterAddrLow) & CounterDump) == 0) { |
|
1818 memcpy(&tp->counters, counters, sizeof(*counters)); |
|
1819 break; |
|
1820 } |
|
1821 udelay(10); |
|
1822 } |
|
1823 |
|
1824 RTL_W32(CounterAddrLow, 0); |
|
1825 RTL_W32(CounterAddrHigh, 0); |
|
1826 |
|
1827 dma_free_coherent(d, sizeof(*counters), counters, paddr); |
|
1828 } |
|
1829 |
|
1830 static void rtl8169_get_ethtool_stats(struct net_device *dev, |
|
1831 struct ethtool_stats *stats, u64 *data) |
|
1832 { |
|
1833 struct rtl8169_private *tp = netdev_priv(dev); |
|
1834 |
|
1835 ASSERT_RTNL(); |
|
1836 |
|
1837 rtl8169_update_counters(dev); |
|
1838 |
|
1839 data[0] = le64_to_cpu(tp->counters.tx_packets); |
|
1840 data[1] = le64_to_cpu(tp->counters.rx_packets); |
|
1841 data[2] = le64_to_cpu(tp->counters.tx_errors); |
|
1842 data[3] = le32_to_cpu(tp->counters.rx_errors); |
|
1843 data[4] = le16_to_cpu(tp->counters.rx_missed); |
|
1844 data[5] = le16_to_cpu(tp->counters.align_errors); |
|
1845 data[6] = le32_to_cpu(tp->counters.tx_one_collision); |
|
1846 data[7] = le32_to_cpu(tp->counters.tx_multi_collision); |
|
1847 data[8] = le64_to_cpu(tp->counters.rx_unicast); |
|
1848 data[9] = le64_to_cpu(tp->counters.rx_broadcast); |
|
1849 data[10] = le32_to_cpu(tp->counters.rx_multicast); |
|
1850 data[11] = le16_to_cpu(tp->counters.tx_aborted); |
|
1851 data[12] = le16_to_cpu(tp->counters.tx_underun); |
|
1852 } |
|
1853 |
|
1854 static void rtl8169_get_strings(struct net_device *dev, u32 stringset, u8 *data) |
|
1855 { |
|
1856 switch(stringset) { |
|
1857 case ETH_SS_STATS: |
|
1858 memcpy(data, *rtl8169_gstrings, sizeof(rtl8169_gstrings)); |
|
1859 break; |
|
1860 } |
|
1861 } |
|
1862 |
|
1863 static const struct ethtool_ops rtl8169_ethtool_ops = { |
|
1864 .get_drvinfo = rtl8169_get_drvinfo, |
|
1865 .get_regs_len = rtl8169_get_regs_len, |
|
1866 .get_link = ethtool_op_get_link, |
|
1867 .get_settings = rtl8169_get_settings, |
|
1868 .set_settings = rtl8169_set_settings, |
|
1869 .get_msglevel = rtl8169_get_msglevel, |
|
1870 .set_msglevel = rtl8169_set_msglevel, |
|
1871 .get_regs = rtl8169_get_regs, |
|
1872 .get_wol = rtl8169_get_wol, |
|
1873 .set_wol = rtl8169_set_wol, |
|
1874 .get_strings = rtl8169_get_strings, |
|
1875 .get_sset_count = rtl8169_get_sset_count, |
|
1876 .get_ethtool_stats = rtl8169_get_ethtool_stats, |
|
1877 }; |
|
1878 |
|
1879 static void rtl8169_get_mac_version(struct rtl8169_private *tp, |
|
1880 struct net_device *dev, u8 default_version) |
|
1881 { |
|
1882 void __iomem *ioaddr = tp->mmio_addr; |
|
1883 /* |
|
1884 * The driver currently handles the 8168Bf and the 8168Be identically |
|
1885 * but they can be identified more specifically through the test below |
|
1886 * if needed: |
|
1887 * |
|
1888 * (RTL_R32(TxConfig) & 0x700000) == 0x500000 ? 8168Bf : 8168Be |
|
1889 * |
|
1890 * Same thing for the 8101Eb and the 8101Ec: |
|
1891 * |
|
1892 * (RTL_R32(TxConfig) & 0x700000) == 0x200000 ? 8101Eb : 8101Ec |
|
1893 */ |
|
1894 static const struct rtl_mac_info { |
|
1895 u32 mask; |
|
1896 u32 val; |
|
1897 int mac_version; |
|
1898 } mac_info[] = { |
|
1899 /* 8168F family. */ |
|
1900 { 0x7cf00000, 0x48100000, RTL_GIGA_MAC_VER_36 }, |
|
1901 { 0x7cf00000, 0x48000000, RTL_GIGA_MAC_VER_35 }, |
|
1902 |
|
1903 /* 8168E family. */ |
|
1904 { 0x7c800000, 0x2c800000, RTL_GIGA_MAC_VER_34 }, |
|
1905 { 0x7cf00000, 0x2c200000, RTL_GIGA_MAC_VER_33 }, |
|
1906 { 0x7cf00000, 0x2c100000, RTL_GIGA_MAC_VER_32 }, |
|
1907 { 0x7c800000, 0x2c000000, RTL_GIGA_MAC_VER_33 }, |
|
1908 |
|
1909 /* 8168D family. */ |
|
1910 { 0x7cf00000, 0x28300000, RTL_GIGA_MAC_VER_26 }, |
|
1911 { 0x7cf00000, 0x28100000, RTL_GIGA_MAC_VER_25 }, |
|
1912 { 0x7c800000, 0x28000000, RTL_GIGA_MAC_VER_26 }, |
|
1913 |
|
1914 /* 8168DP family. */ |
|
1915 { 0x7cf00000, 0x28800000, RTL_GIGA_MAC_VER_27 }, |
|
1916 { 0x7cf00000, 0x28a00000, RTL_GIGA_MAC_VER_28 }, |
|
1917 { 0x7cf00000, 0x28b00000, RTL_GIGA_MAC_VER_31 }, |
|
1918 |
|
1919 /* 8168C family. */ |
|
1920 { 0x7cf00000, 0x3cb00000, RTL_GIGA_MAC_VER_24 }, |
|
1921 { 0x7cf00000, 0x3c900000, RTL_GIGA_MAC_VER_23 }, |
|
1922 { 0x7cf00000, 0x3c800000, RTL_GIGA_MAC_VER_18 }, |
|
1923 { 0x7c800000, 0x3c800000, RTL_GIGA_MAC_VER_24 }, |
|
1924 { 0x7cf00000, 0x3c000000, RTL_GIGA_MAC_VER_19 }, |
|
1925 { 0x7cf00000, 0x3c200000, RTL_GIGA_MAC_VER_20 }, |
|
1926 { 0x7cf00000, 0x3c300000, RTL_GIGA_MAC_VER_21 }, |
|
1927 { 0x7cf00000, 0x3c400000, RTL_GIGA_MAC_VER_22 }, |
|
1928 { 0x7c800000, 0x3c000000, RTL_GIGA_MAC_VER_22 }, |
|
1929 |
|
1930 /* 8168B family. */ |
|
1931 { 0x7cf00000, 0x38000000, RTL_GIGA_MAC_VER_12 }, |
|
1932 { 0x7cf00000, 0x38500000, RTL_GIGA_MAC_VER_17 }, |
|
1933 { 0x7c800000, 0x38000000, RTL_GIGA_MAC_VER_17 }, |
|
1934 { 0x7c800000, 0x30000000, RTL_GIGA_MAC_VER_11 }, |
|
1935 |
|
1936 /* 8101 family. */ |
|
1937 { 0x7cf00000, 0x40b00000, RTL_GIGA_MAC_VER_30 }, |
|
1938 { 0x7cf00000, 0x40a00000, RTL_GIGA_MAC_VER_30 }, |
|
1939 { 0x7cf00000, 0x40900000, RTL_GIGA_MAC_VER_29 }, |
|
1940 { 0x7c800000, 0x40800000, RTL_GIGA_MAC_VER_30 }, |
|
1941 { 0x7cf00000, 0x34a00000, RTL_GIGA_MAC_VER_09 }, |
|
1942 { 0x7cf00000, 0x24a00000, RTL_GIGA_MAC_VER_09 }, |
|
1943 { 0x7cf00000, 0x34900000, RTL_GIGA_MAC_VER_08 }, |
|
1944 { 0x7cf00000, 0x24900000, RTL_GIGA_MAC_VER_08 }, |
|
1945 { 0x7cf00000, 0x34800000, RTL_GIGA_MAC_VER_07 }, |
|
1946 { 0x7cf00000, 0x24800000, RTL_GIGA_MAC_VER_07 }, |
|
1947 { 0x7cf00000, 0x34000000, RTL_GIGA_MAC_VER_13 }, |
|
1948 { 0x7cf00000, 0x34300000, RTL_GIGA_MAC_VER_10 }, |
|
1949 { 0x7cf00000, 0x34200000, RTL_GIGA_MAC_VER_16 }, |
|
1950 { 0x7c800000, 0x34800000, RTL_GIGA_MAC_VER_09 }, |
|
1951 { 0x7c800000, 0x24800000, RTL_GIGA_MAC_VER_09 }, |
|
1952 { 0x7c800000, 0x34000000, RTL_GIGA_MAC_VER_16 }, |
|
1953 /* FIXME: where did these entries come from ? -- FR */ |
|
1954 { 0xfc800000, 0x38800000, RTL_GIGA_MAC_VER_15 }, |
|
1955 { 0xfc800000, 0x30800000, RTL_GIGA_MAC_VER_14 }, |
|
1956 |
|
1957 /* 8110 family. */ |
|
1958 { 0xfc800000, 0x98000000, RTL_GIGA_MAC_VER_06 }, |
|
1959 { 0xfc800000, 0x18000000, RTL_GIGA_MAC_VER_05 }, |
|
1960 { 0xfc800000, 0x10000000, RTL_GIGA_MAC_VER_04 }, |
|
1961 { 0xfc800000, 0x04000000, RTL_GIGA_MAC_VER_03 }, |
|
1962 { 0xfc800000, 0x00800000, RTL_GIGA_MAC_VER_02 }, |
|
1963 { 0xfc800000, 0x00000000, RTL_GIGA_MAC_VER_01 }, |
|
1964 |
|
1965 /* Catch-all */ |
|
1966 { 0x00000000, 0x00000000, RTL_GIGA_MAC_NONE } |
|
1967 }; |
|
1968 const struct rtl_mac_info *p = mac_info; |
|
1969 u32 reg; |
|
1970 |
|
1971 reg = RTL_R32(TxConfig); |
|
1972 while ((reg & p->mask) != p->val) |
|
1973 p++; |
|
1974 tp->mac_version = p->mac_version; |
|
1975 |
|
1976 if (tp->mac_version == RTL_GIGA_MAC_NONE) { |
|
1977 netif_notice(tp, probe, dev, |
|
1978 "unknown MAC, using family default\n"); |
|
1979 tp->mac_version = default_version; |
|
1980 } |
|
1981 } |
|
1982 |
|
1983 static void rtl8169_print_mac_version(struct rtl8169_private *tp) |
|
1984 { |
|
1985 dprintk("mac_version = 0x%02x\n", tp->mac_version); |
|
1986 } |
|
1987 |
|
1988 struct phy_reg { |
|
1989 u16 reg; |
|
1990 u16 val; |
|
1991 }; |
|
1992 |
|
1993 static void rtl_writephy_batch(struct rtl8169_private *tp, |
|
1994 const struct phy_reg *regs, int len) |
|
1995 { |
|
1996 while (len-- > 0) { |
|
1997 rtl_writephy(tp, regs->reg, regs->val); |
|
1998 regs++; |
|
1999 } |
|
2000 } |
|
2001 |
|
2002 #define PHY_READ 0x00000000 |
|
2003 #define PHY_DATA_OR 0x10000000 |
|
2004 #define PHY_DATA_AND 0x20000000 |
|
2005 #define PHY_BJMPN 0x30000000 |
|
2006 #define PHY_READ_EFUSE 0x40000000 |
|
2007 #define PHY_READ_MAC_BYTE 0x50000000 |
|
2008 #define PHY_WRITE_MAC_BYTE 0x60000000 |
|
2009 #define PHY_CLEAR_READCOUNT 0x70000000 |
|
2010 #define PHY_WRITE 0x80000000 |
|
2011 #define PHY_READCOUNT_EQ_SKIP 0x90000000 |
|
2012 #define PHY_COMP_EQ_SKIPN 0xa0000000 |
|
2013 #define PHY_COMP_NEQ_SKIPN 0xb0000000 |
|
2014 #define PHY_WRITE_PREVIOUS 0xc0000000 |
|
2015 #define PHY_SKIPN 0xd0000000 |
|
2016 #define PHY_DELAY_MS 0xe0000000 |
|
2017 #define PHY_WRITE_ERI_WORD 0xf0000000 |
|
2018 |
|
2019 struct fw_info { |
|
2020 u32 magic; |
|
2021 char version[RTL_VER_SIZE]; |
|
2022 __le32 fw_start; |
|
2023 __le32 fw_len; |
|
2024 u8 chksum; |
|
2025 } __packed; |
|
2026 |
|
2027 #define FW_OPCODE_SIZE sizeof(typeof(*((struct rtl_fw_phy_action *)0)->code)) |
|
2028 |
|
2029 static bool rtl_fw_format_ok(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
|
2030 { |
|
2031 const struct firmware *fw = rtl_fw->fw; |
|
2032 struct fw_info *fw_info = (struct fw_info *)fw->data; |
|
2033 struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
|
2034 char *version = rtl_fw->version; |
|
2035 bool rc = false; |
|
2036 |
|
2037 if (fw->size < FW_OPCODE_SIZE) |
|
2038 goto out; |
|
2039 |
|
2040 if (!fw_info->magic) { |
|
2041 size_t i, size, start; |
|
2042 u8 checksum = 0; |
|
2043 |
|
2044 if (fw->size < sizeof(*fw_info)) |
|
2045 goto out; |
|
2046 |
|
2047 for (i = 0; i < fw->size; i++) |
|
2048 checksum += fw->data[i]; |
|
2049 if (checksum != 0) |
|
2050 goto out; |
|
2051 |
|
2052 start = le32_to_cpu(fw_info->fw_start); |
|
2053 if (start > fw->size) |
|
2054 goto out; |
|
2055 |
|
2056 size = le32_to_cpu(fw_info->fw_len); |
|
2057 if (size > (fw->size - start) / FW_OPCODE_SIZE) |
|
2058 goto out; |
|
2059 |
|
2060 memcpy(version, fw_info->version, RTL_VER_SIZE); |
|
2061 |
|
2062 pa->code = (__le32 *)(fw->data + start); |
|
2063 pa->size = size; |
|
2064 } else { |
|
2065 if (fw->size % FW_OPCODE_SIZE) |
|
2066 goto out; |
|
2067 |
|
2068 strlcpy(version, rtl_lookup_firmware_name(tp), RTL_VER_SIZE); |
|
2069 |
|
2070 pa->code = (__le32 *)fw->data; |
|
2071 pa->size = fw->size / FW_OPCODE_SIZE; |
|
2072 } |
|
2073 version[RTL_VER_SIZE - 1] = 0; |
|
2074 |
|
2075 rc = true; |
|
2076 out: |
|
2077 return rc; |
|
2078 } |
|
2079 |
|
2080 static bool rtl_fw_data_ok(struct rtl8169_private *tp, struct net_device *dev, |
|
2081 struct rtl_fw_phy_action *pa) |
|
2082 { |
|
2083 bool rc = false; |
|
2084 size_t index; |
|
2085 |
|
2086 for (index = 0; index < pa->size; index++) { |
|
2087 u32 action = le32_to_cpu(pa->code[index]); |
|
2088 u32 regno = (action & 0x0fff0000) >> 16; |
|
2089 |
|
2090 switch(action & 0xf0000000) { |
|
2091 case PHY_READ: |
|
2092 case PHY_DATA_OR: |
|
2093 case PHY_DATA_AND: |
|
2094 case PHY_READ_EFUSE: |
|
2095 case PHY_CLEAR_READCOUNT: |
|
2096 case PHY_WRITE: |
|
2097 case PHY_WRITE_PREVIOUS: |
|
2098 case PHY_DELAY_MS: |
|
2099 break; |
|
2100 |
|
2101 case PHY_BJMPN: |
|
2102 if (regno > index) { |
|
2103 netif_err(tp, ifup, tp->dev, |
|
2104 "Out of range of firmware\n"); |
|
2105 goto out; |
|
2106 } |
|
2107 break; |
|
2108 case PHY_READCOUNT_EQ_SKIP: |
|
2109 if (index + 2 >= pa->size) { |
|
2110 netif_err(tp, ifup, tp->dev, |
|
2111 "Out of range of firmware\n"); |
|
2112 goto out; |
|
2113 } |
|
2114 break; |
|
2115 case PHY_COMP_EQ_SKIPN: |
|
2116 case PHY_COMP_NEQ_SKIPN: |
|
2117 case PHY_SKIPN: |
|
2118 if (index + 1 + regno >= pa->size) { |
|
2119 netif_err(tp, ifup, tp->dev, |
|
2120 "Out of range of firmware\n"); |
|
2121 goto out; |
|
2122 } |
|
2123 break; |
|
2124 |
|
2125 case PHY_READ_MAC_BYTE: |
|
2126 case PHY_WRITE_MAC_BYTE: |
|
2127 case PHY_WRITE_ERI_WORD: |
|
2128 default: |
|
2129 netif_err(tp, ifup, tp->dev, |
|
2130 "Invalid action 0x%08x\n", action); |
|
2131 goto out; |
|
2132 } |
|
2133 } |
|
2134 rc = true; |
|
2135 out: |
|
2136 return rc; |
|
2137 } |
|
2138 |
|
2139 static int rtl_check_firmware(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
|
2140 { |
|
2141 struct net_device *dev = tp->dev; |
|
2142 int rc = -EINVAL; |
|
2143 |
|
2144 if (!rtl_fw_format_ok(tp, rtl_fw)) { |
|
2145 netif_err(tp, ifup, dev, "invalid firwmare\n"); |
|
2146 goto out; |
|
2147 } |
|
2148 |
|
2149 if (rtl_fw_data_ok(tp, dev, &rtl_fw->phy_action)) |
|
2150 rc = 0; |
|
2151 out: |
|
2152 return rc; |
|
2153 } |
|
2154 |
|
2155 static void rtl_phy_write_fw(struct rtl8169_private *tp, struct rtl_fw *rtl_fw) |
|
2156 { |
|
2157 struct rtl_fw_phy_action *pa = &rtl_fw->phy_action; |
|
2158 u32 predata, count; |
|
2159 size_t index; |
|
2160 |
|
2161 predata = count = 0; |
|
2162 |
|
2163 for (index = 0; index < pa->size; ) { |
|
2164 u32 action = le32_to_cpu(pa->code[index]); |
|
2165 u32 data = action & 0x0000ffff; |
|
2166 u32 regno = (action & 0x0fff0000) >> 16; |
|
2167 |
|
2168 if (!action) |
|
2169 break; |
|
2170 |
|
2171 switch(action & 0xf0000000) { |
|
2172 case PHY_READ: |
|
2173 predata = rtl_readphy(tp, regno); |
|
2174 count++; |
|
2175 index++; |
|
2176 break; |
|
2177 case PHY_DATA_OR: |
|
2178 predata |= data; |
|
2179 index++; |
|
2180 break; |
|
2181 case PHY_DATA_AND: |
|
2182 predata &= data; |
|
2183 index++; |
|
2184 break; |
|
2185 case PHY_BJMPN: |
|
2186 index -= regno; |
|
2187 break; |
|
2188 case PHY_READ_EFUSE: |
|
2189 predata = rtl8168d_efuse_read(tp->mmio_addr, regno); |
|
2190 index++; |
|
2191 break; |
|
2192 case PHY_CLEAR_READCOUNT: |
|
2193 count = 0; |
|
2194 index++; |
|
2195 break; |
|
2196 case PHY_WRITE: |
|
2197 rtl_writephy(tp, regno, data); |
|
2198 index++; |
|
2199 break; |
|
2200 case PHY_READCOUNT_EQ_SKIP: |
|
2201 index += (count == data) ? 2 : 1; |
|
2202 break; |
|
2203 case PHY_COMP_EQ_SKIPN: |
|
2204 if (predata == data) |
|
2205 index += regno; |
|
2206 index++; |
|
2207 break; |
|
2208 case PHY_COMP_NEQ_SKIPN: |
|
2209 if (predata != data) |
|
2210 index += regno; |
|
2211 index++; |
|
2212 break; |
|
2213 case PHY_WRITE_PREVIOUS: |
|
2214 rtl_writephy(tp, regno, predata); |
|
2215 index++; |
|
2216 break; |
|
2217 case PHY_SKIPN: |
|
2218 index += regno + 1; |
|
2219 break; |
|
2220 case PHY_DELAY_MS: |
|
2221 mdelay(data); |
|
2222 index++; |
|
2223 break; |
|
2224 |
|
2225 case PHY_READ_MAC_BYTE: |
|
2226 case PHY_WRITE_MAC_BYTE: |
|
2227 case PHY_WRITE_ERI_WORD: |
|
2228 default: |
|
2229 BUG(); |
|
2230 } |
|
2231 } |
|
2232 } |
|
2233 |
|
2234 static void rtl_release_firmware(struct rtl8169_private *tp) |
|
2235 { |
|
2236 if (!IS_ERR_OR_NULL(tp->rtl_fw)) { |
|
2237 release_firmware(tp->rtl_fw->fw); |
|
2238 kfree(tp->rtl_fw); |
|
2239 } |
|
2240 tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
|
2241 } |
|
2242 |
|
2243 static void rtl_apply_firmware(struct rtl8169_private *tp) |
|
2244 { |
|
2245 struct rtl_fw *rtl_fw = tp->rtl_fw; |
|
2246 |
|
2247 /* TODO: release firmware once rtl_phy_write_fw signals failures. */ |
|
2248 if (!IS_ERR_OR_NULL(rtl_fw)) |
|
2249 rtl_phy_write_fw(tp, rtl_fw); |
|
2250 } |
|
2251 |
|
2252 static void rtl_apply_firmware_cond(struct rtl8169_private *tp, u8 reg, u16 val) |
|
2253 { |
|
2254 if (rtl_readphy(tp, reg) != val) |
|
2255 netif_warn(tp, hw, tp->dev, "chipset not ready for firmware\n"); |
|
2256 else |
|
2257 rtl_apply_firmware(tp); |
|
2258 } |
|
2259 |
|
2260 static void rtl8169s_hw_phy_config(struct rtl8169_private *tp) |
|
2261 { |
|
2262 static const struct phy_reg phy_reg_init[] = { |
|
2263 { 0x1f, 0x0001 }, |
|
2264 { 0x06, 0x006e }, |
|
2265 { 0x08, 0x0708 }, |
|
2266 { 0x15, 0x4000 }, |
|
2267 { 0x18, 0x65c7 }, |
|
2268 |
|
2269 { 0x1f, 0x0001 }, |
|
2270 { 0x03, 0x00a1 }, |
|
2271 { 0x02, 0x0008 }, |
|
2272 { 0x01, 0x0120 }, |
|
2273 { 0x00, 0x1000 }, |
|
2274 { 0x04, 0x0800 }, |
|
2275 { 0x04, 0x0000 }, |
|
2276 |
|
2277 { 0x03, 0xff41 }, |
|
2278 { 0x02, 0xdf60 }, |
|
2279 { 0x01, 0x0140 }, |
|
2280 { 0x00, 0x0077 }, |
|
2281 { 0x04, 0x7800 }, |
|
2282 { 0x04, 0x7000 }, |
|
2283 |
|
2284 { 0x03, 0x802f }, |
|
2285 { 0x02, 0x4f02 }, |
|
2286 { 0x01, 0x0409 }, |
|
2287 { 0x00, 0xf0f9 }, |
|
2288 { 0x04, 0x9800 }, |
|
2289 { 0x04, 0x9000 }, |
|
2290 |
|
2291 { 0x03, 0xdf01 }, |
|
2292 { 0x02, 0xdf20 }, |
|
2293 { 0x01, 0xff95 }, |
|
2294 { 0x00, 0xba00 }, |
|
2295 { 0x04, 0xa800 }, |
|
2296 { 0x04, 0xa000 }, |
|
2297 |
|
2298 { 0x03, 0xff41 }, |
|
2299 { 0x02, 0xdf20 }, |
|
2300 { 0x01, 0x0140 }, |
|
2301 { 0x00, 0x00bb }, |
|
2302 { 0x04, 0xb800 }, |
|
2303 { 0x04, 0xb000 }, |
|
2304 |
|
2305 { 0x03, 0xdf41 }, |
|
2306 { 0x02, 0xdc60 }, |
|
2307 { 0x01, 0x6340 }, |
|
2308 { 0x00, 0x007d }, |
|
2309 { 0x04, 0xd800 }, |
|
2310 { 0x04, 0xd000 }, |
|
2311 |
|
2312 { 0x03, 0xdf01 }, |
|
2313 { 0x02, 0xdf20 }, |
|
2314 { 0x01, 0x100a }, |
|
2315 { 0x00, 0xa0ff }, |
|
2316 { 0x04, 0xf800 }, |
|
2317 { 0x04, 0xf000 }, |
|
2318 |
|
2319 { 0x1f, 0x0000 }, |
|
2320 { 0x0b, 0x0000 }, |
|
2321 { 0x00, 0x9200 } |
|
2322 }; |
|
2323 |
|
2324 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2325 } |
|
2326 |
|
2327 static void rtl8169sb_hw_phy_config(struct rtl8169_private *tp) |
|
2328 { |
|
2329 static const struct phy_reg phy_reg_init[] = { |
|
2330 { 0x1f, 0x0002 }, |
|
2331 { 0x01, 0x90d0 }, |
|
2332 { 0x1f, 0x0000 } |
|
2333 }; |
|
2334 |
|
2335 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2336 } |
|
2337 |
|
2338 static void rtl8169scd_hw_phy_config_quirk(struct rtl8169_private *tp) |
|
2339 { |
|
2340 struct pci_dev *pdev = tp->pci_dev; |
|
2341 |
|
2342 if ((pdev->subsystem_vendor != PCI_VENDOR_ID_GIGABYTE) || |
|
2343 (pdev->subsystem_device != 0xe000)) |
|
2344 return; |
|
2345 |
|
2346 rtl_writephy(tp, 0x1f, 0x0001); |
|
2347 rtl_writephy(tp, 0x10, 0xf01b); |
|
2348 rtl_writephy(tp, 0x1f, 0x0000); |
|
2349 } |
|
2350 |
|
2351 static void rtl8169scd_hw_phy_config(struct rtl8169_private *tp) |
|
2352 { |
|
2353 static const struct phy_reg phy_reg_init[] = { |
|
2354 { 0x1f, 0x0001 }, |
|
2355 { 0x04, 0x0000 }, |
|
2356 { 0x03, 0x00a1 }, |
|
2357 { 0x02, 0x0008 }, |
|
2358 { 0x01, 0x0120 }, |
|
2359 { 0x00, 0x1000 }, |
|
2360 { 0x04, 0x0800 }, |
|
2361 { 0x04, 0x9000 }, |
|
2362 { 0x03, 0x802f }, |
|
2363 { 0x02, 0x4f02 }, |
|
2364 { 0x01, 0x0409 }, |
|
2365 { 0x00, 0xf099 }, |
|
2366 { 0x04, 0x9800 }, |
|
2367 { 0x04, 0xa000 }, |
|
2368 { 0x03, 0xdf01 }, |
|
2369 { 0x02, 0xdf20 }, |
|
2370 { 0x01, 0xff95 }, |
|
2371 { 0x00, 0xba00 }, |
|
2372 { 0x04, 0xa800 }, |
|
2373 { 0x04, 0xf000 }, |
|
2374 { 0x03, 0xdf01 }, |
|
2375 { 0x02, 0xdf20 }, |
|
2376 { 0x01, 0x101a }, |
|
2377 { 0x00, 0xa0ff }, |
|
2378 { 0x04, 0xf800 }, |
|
2379 { 0x04, 0x0000 }, |
|
2380 { 0x1f, 0x0000 }, |
|
2381 |
|
2382 { 0x1f, 0x0001 }, |
|
2383 { 0x10, 0xf41b }, |
|
2384 { 0x14, 0xfb54 }, |
|
2385 { 0x18, 0xf5c7 }, |
|
2386 { 0x1f, 0x0000 }, |
|
2387 |
|
2388 { 0x1f, 0x0001 }, |
|
2389 { 0x17, 0x0cc0 }, |
|
2390 { 0x1f, 0x0000 } |
|
2391 }; |
|
2392 |
|
2393 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2394 |
|
2395 rtl8169scd_hw_phy_config_quirk(tp); |
|
2396 } |
|
2397 |
|
2398 static void rtl8169sce_hw_phy_config(struct rtl8169_private *tp) |
|
2399 { |
|
2400 static const struct phy_reg phy_reg_init[] = { |
|
2401 { 0x1f, 0x0001 }, |
|
2402 { 0x04, 0x0000 }, |
|
2403 { 0x03, 0x00a1 }, |
|
2404 { 0x02, 0x0008 }, |
|
2405 { 0x01, 0x0120 }, |
|
2406 { 0x00, 0x1000 }, |
|
2407 { 0x04, 0x0800 }, |
|
2408 { 0x04, 0x9000 }, |
|
2409 { 0x03, 0x802f }, |
|
2410 { 0x02, 0x4f02 }, |
|
2411 { 0x01, 0x0409 }, |
|
2412 { 0x00, 0xf099 }, |
|
2413 { 0x04, 0x9800 }, |
|
2414 { 0x04, 0xa000 }, |
|
2415 { 0x03, 0xdf01 }, |
|
2416 { 0x02, 0xdf20 }, |
|
2417 { 0x01, 0xff95 }, |
|
2418 { 0x00, 0xba00 }, |
|
2419 { 0x04, 0xa800 }, |
|
2420 { 0x04, 0xf000 }, |
|
2421 { 0x03, 0xdf01 }, |
|
2422 { 0x02, 0xdf20 }, |
|
2423 { 0x01, 0x101a }, |
|
2424 { 0x00, 0xa0ff }, |
|
2425 { 0x04, 0xf800 }, |
|
2426 { 0x04, 0x0000 }, |
|
2427 { 0x1f, 0x0000 }, |
|
2428 |
|
2429 { 0x1f, 0x0001 }, |
|
2430 { 0x0b, 0x8480 }, |
|
2431 { 0x1f, 0x0000 }, |
|
2432 |
|
2433 { 0x1f, 0x0001 }, |
|
2434 { 0x18, 0x67c7 }, |
|
2435 { 0x04, 0x2000 }, |
|
2436 { 0x03, 0x002f }, |
|
2437 { 0x02, 0x4360 }, |
|
2438 { 0x01, 0x0109 }, |
|
2439 { 0x00, 0x3022 }, |
|
2440 { 0x04, 0x2800 }, |
|
2441 { 0x1f, 0x0000 }, |
|
2442 |
|
2443 { 0x1f, 0x0001 }, |
|
2444 { 0x17, 0x0cc0 }, |
|
2445 { 0x1f, 0x0000 } |
|
2446 }; |
|
2447 |
|
2448 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2449 } |
|
2450 |
|
2451 static void rtl8168bb_hw_phy_config(struct rtl8169_private *tp) |
|
2452 { |
|
2453 static const struct phy_reg phy_reg_init[] = { |
|
2454 { 0x10, 0xf41b }, |
|
2455 { 0x1f, 0x0000 } |
|
2456 }; |
|
2457 |
|
2458 rtl_writephy(tp, 0x1f, 0x0001); |
|
2459 rtl_patchphy(tp, 0x16, 1 << 0); |
|
2460 |
|
2461 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2462 } |
|
2463 |
|
2464 static void rtl8168bef_hw_phy_config(struct rtl8169_private *tp) |
|
2465 { |
|
2466 static const struct phy_reg phy_reg_init[] = { |
|
2467 { 0x1f, 0x0001 }, |
|
2468 { 0x10, 0xf41b }, |
|
2469 { 0x1f, 0x0000 } |
|
2470 }; |
|
2471 |
|
2472 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2473 } |
|
2474 |
|
2475 static void rtl8168cp_1_hw_phy_config(struct rtl8169_private *tp) |
|
2476 { |
|
2477 static const struct phy_reg phy_reg_init[] = { |
|
2478 { 0x1f, 0x0000 }, |
|
2479 { 0x1d, 0x0f00 }, |
|
2480 { 0x1f, 0x0002 }, |
|
2481 { 0x0c, 0x1ec8 }, |
|
2482 { 0x1f, 0x0000 } |
|
2483 }; |
|
2484 |
|
2485 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2486 } |
|
2487 |
|
2488 static void rtl8168cp_2_hw_phy_config(struct rtl8169_private *tp) |
|
2489 { |
|
2490 static const struct phy_reg phy_reg_init[] = { |
|
2491 { 0x1f, 0x0001 }, |
|
2492 { 0x1d, 0x3d98 }, |
|
2493 { 0x1f, 0x0000 } |
|
2494 }; |
|
2495 |
|
2496 rtl_writephy(tp, 0x1f, 0x0000); |
|
2497 rtl_patchphy(tp, 0x14, 1 << 5); |
|
2498 rtl_patchphy(tp, 0x0d, 1 << 5); |
|
2499 |
|
2500 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2501 } |
|
2502 |
|
2503 static void rtl8168c_1_hw_phy_config(struct rtl8169_private *tp) |
|
2504 { |
|
2505 static const struct phy_reg phy_reg_init[] = { |
|
2506 { 0x1f, 0x0001 }, |
|
2507 { 0x12, 0x2300 }, |
|
2508 { 0x1f, 0x0002 }, |
|
2509 { 0x00, 0x88d4 }, |
|
2510 { 0x01, 0x82b1 }, |
|
2511 { 0x03, 0x7002 }, |
|
2512 { 0x08, 0x9e30 }, |
|
2513 { 0x09, 0x01f0 }, |
|
2514 { 0x0a, 0x5500 }, |
|
2515 { 0x0c, 0x00c8 }, |
|
2516 { 0x1f, 0x0003 }, |
|
2517 { 0x12, 0xc096 }, |
|
2518 { 0x16, 0x000a }, |
|
2519 { 0x1f, 0x0000 }, |
|
2520 { 0x1f, 0x0000 }, |
|
2521 { 0x09, 0x2000 }, |
|
2522 { 0x09, 0x0000 } |
|
2523 }; |
|
2524 |
|
2525 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2526 |
|
2527 rtl_patchphy(tp, 0x14, 1 << 5); |
|
2528 rtl_patchphy(tp, 0x0d, 1 << 5); |
|
2529 rtl_writephy(tp, 0x1f, 0x0000); |
|
2530 } |
|
2531 |
|
2532 static void rtl8168c_2_hw_phy_config(struct rtl8169_private *tp) |
|
2533 { |
|
2534 static const struct phy_reg phy_reg_init[] = { |
|
2535 { 0x1f, 0x0001 }, |
|
2536 { 0x12, 0x2300 }, |
|
2537 { 0x03, 0x802f }, |
|
2538 { 0x02, 0x4f02 }, |
|
2539 { 0x01, 0x0409 }, |
|
2540 { 0x00, 0xf099 }, |
|
2541 { 0x04, 0x9800 }, |
|
2542 { 0x04, 0x9000 }, |
|
2543 { 0x1d, 0x3d98 }, |
|
2544 { 0x1f, 0x0002 }, |
|
2545 { 0x0c, 0x7eb8 }, |
|
2546 { 0x06, 0x0761 }, |
|
2547 { 0x1f, 0x0003 }, |
|
2548 { 0x16, 0x0f0a }, |
|
2549 { 0x1f, 0x0000 } |
|
2550 }; |
|
2551 |
|
2552 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2553 |
|
2554 rtl_patchphy(tp, 0x16, 1 << 0); |
|
2555 rtl_patchphy(tp, 0x14, 1 << 5); |
|
2556 rtl_patchphy(tp, 0x0d, 1 << 5); |
|
2557 rtl_writephy(tp, 0x1f, 0x0000); |
|
2558 } |
|
2559 |
|
2560 static void rtl8168c_3_hw_phy_config(struct rtl8169_private *tp) |
|
2561 { |
|
2562 static const struct phy_reg phy_reg_init[] = { |
|
2563 { 0x1f, 0x0001 }, |
|
2564 { 0x12, 0x2300 }, |
|
2565 { 0x1d, 0x3d98 }, |
|
2566 { 0x1f, 0x0002 }, |
|
2567 { 0x0c, 0x7eb8 }, |
|
2568 { 0x06, 0x5461 }, |
|
2569 { 0x1f, 0x0003 }, |
|
2570 { 0x16, 0x0f0a }, |
|
2571 { 0x1f, 0x0000 } |
|
2572 }; |
|
2573 |
|
2574 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2575 |
|
2576 rtl_patchphy(tp, 0x16, 1 << 0); |
|
2577 rtl_patchphy(tp, 0x14, 1 << 5); |
|
2578 rtl_patchphy(tp, 0x0d, 1 << 5); |
|
2579 rtl_writephy(tp, 0x1f, 0x0000); |
|
2580 } |
|
2581 |
|
2582 static void rtl8168c_4_hw_phy_config(struct rtl8169_private *tp) |
|
2583 { |
|
2584 rtl8168c_3_hw_phy_config(tp); |
|
2585 } |
|
2586 |
|
2587 static void rtl8168d_1_hw_phy_config(struct rtl8169_private *tp) |
|
2588 { |
|
2589 static const struct phy_reg phy_reg_init_0[] = { |
|
2590 /* Channel Estimation */ |
|
2591 { 0x1f, 0x0001 }, |
|
2592 { 0x06, 0x4064 }, |
|
2593 { 0x07, 0x2863 }, |
|
2594 { 0x08, 0x059c }, |
|
2595 { 0x09, 0x26b4 }, |
|
2596 { 0x0a, 0x6a19 }, |
|
2597 { 0x0b, 0xdcc8 }, |
|
2598 { 0x10, 0xf06d }, |
|
2599 { 0x14, 0x7f68 }, |
|
2600 { 0x18, 0x7fd9 }, |
|
2601 { 0x1c, 0xf0ff }, |
|
2602 { 0x1d, 0x3d9c }, |
|
2603 { 0x1f, 0x0003 }, |
|
2604 { 0x12, 0xf49f }, |
|
2605 { 0x13, 0x070b }, |
|
2606 { 0x1a, 0x05ad }, |
|
2607 { 0x14, 0x94c0 }, |
|
2608 |
|
2609 /* |
|
2610 * Tx Error Issue |
|
2611 * Enhance line driver power |
|
2612 */ |
|
2613 { 0x1f, 0x0002 }, |
|
2614 { 0x06, 0x5561 }, |
|
2615 { 0x1f, 0x0005 }, |
|
2616 { 0x05, 0x8332 }, |
|
2617 { 0x06, 0x5561 }, |
|
2618 |
|
2619 /* |
|
2620 * Can not link to 1Gbps with bad cable |
|
2621 * Decrease SNR threshold form 21.07dB to 19.04dB |
|
2622 */ |
|
2623 { 0x1f, 0x0001 }, |
|
2624 { 0x17, 0x0cc0 }, |
|
2625 |
|
2626 { 0x1f, 0x0000 }, |
|
2627 { 0x0d, 0xf880 } |
|
2628 }; |
|
2629 void __iomem *ioaddr = tp->mmio_addr; |
|
2630 |
|
2631 rtl_writephy_batch(tp, phy_reg_init_0, ARRAY_SIZE(phy_reg_init_0)); |
|
2632 |
|
2633 /* |
|
2634 * Rx Error Issue |
|
2635 * Fine Tune Switching regulator parameter |
|
2636 */ |
|
2637 rtl_writephy(tp, 0x1f, 0x0002); |
|
2638 rtl_w1w0_phy(tp, 0x0b, 0x0010, 0x00ef); |
|
2639 rtl_w1w0_phy(tp, 0x0c, 0xa200, 0x5d00); |
|
2640 |
|
2641 if (rtl8168d_efuse_read(ioaddr, 0x01) == 0xb1) { |
|
2642 static const struct phy_reg phy_reg_init[] = { |
|
2643 { 0x1f, 0x0002 }, |
|
2644 { 0x05, 0x669a }, |
|
2645 { 0x1f, 0x0005 }, |
|
2646 { 0x05, 0x8330 }, |
|
2647 { 0x06, 0x669a }, |
|
2648 { 0x1f, 0x0002 } |
|
2649 }; |
|
2650 int val; |
|
2651 |
|
2652 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2653 |
|
2654 val = rtl_readphy(tp, 0x0d); |
|
2655 |
|
2656 if ((val & 0x00ff) != 0x006c) { |
|
2657 static const u32 set[] = { |
|
2658 0x0065, 0x0066, 0x0067, 0x0068, |
|
2659 0x0069, 0x006a, 0x006b, 0x006c |
|
2660 }; |
|
2661 int i; |
|
2662 |
|
2663 rtl_writephy(tp, 0x1f, 0x0002); |
|
2664 |
|
2665 val &= 0xff00; |
|
2666 for (i = 0; i < ARRAY_SIZE(set); i++) |
|
2667 rtl_writephy(tp, 0x0d, val | set[i]); |
|
2668 } |
|
2669 } else { |
|
2670 static const struct phy_reg phy_reg_init[] = { |
|
2671 { 0x1f, 0x0002 }, |
|
2672 { 0x05, 0x6662 }, |
|
2673 { 0x1f, 0x0005 }, |
|
2674 { 0x05, 0x8330 }, |
|
2675 { 0x06, 0x6662 } |
|
2676 }; |
|
2677 |
|
2678 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2679 } |
|
2680 |
|
2681 /* RSET couple improve */ |
|
2682 rtl_writephy(tp, 0x1f, 0x0002); |
|
2683 rtl_patchphy(tp, 0x0d, 0x0300); |
|
2684 rtl_patchphy(tp, 0x0f, 0x0010); |
|
2685 |
|
2686 /* Fine tune PLL performance */ |
|
2687 rtl_writephy(tp, 0x1f, 0x0002); |
|
2688 rtl_w1w0_phy(tp, 0x02, 0x0100, 0x0600); |
|
2689 rtl_w1w0_phy(tp, 0x03, 0x0000, 0xe000); |
|
2690 |
|
2691 rtl_writephy(tp, 0x1f, 0x0005); |
|
2692 rtl_writephy(tp, 0x05, 0x001b); |
|
2693 |
|
2694 rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xbf00); |
|
2695 |
|
2696 rtl_writephy(tp, 0x1f, 0x0000); |
|
2697 } |
|
2698 |
|
2699 static void rtl8168d_2_hw_phy_config(struct rtl8169_private *tp) |
|
2700 { |
|
2701 static const struct phy_reg phy_reg_init_0[] = { |
|
2702 /* Channel Estimation */ |
|
2703 { 0x1f, 0x0001 }, |
|
2704 { 0x06, 0x4064 }, |
|
2705 { 0x07, 0x2863 }, |
|
2706 { 0x08, 0x059c }, |
|
2707 { 0x09, 0x26b4 }, |
|
2708 { 0x0a, 0x6a19 }, |
|
2709 { 0x0b, 0xdcc8 }, |
|
2710 { 0x10, 0xf06d }, |
|
2711 { 0x14, 0x7f68 }, |
|
2712 { 0x18, 0x7fd9 }, |
|
2713 { 0x1c, 0xf0ff }, |
|
2714 { 0x1d, 0x3d9c }, |
|
2715 { 0x1f, 0x0003 }, |
|
2716 { 0x12, 0xf49f }, |
|
2717 { 0x13, 0x070b }, |
|
2718 { 0x1a, 0x05ad }, |
|
2719 { 0x14, 0x94c0 }, |
|
2720 |
|
2721 /* |
|
2722 * Tx Error Issue |
|
2723 * Enhance line driver power |
|
2724 */ |
|
2725 { 0x1f, 0x0002 }, |
|
2726 { 0x06, 0x5561 }, |
|
2727 { 0x1f, 0x0005 }, |
|
2728 { 0x05, 0x8332 }, |
|
2729 { 0x06, 0x5561 }, |
|
2730 |
|
2731 /* |
|
2732 * Can not link to 1Gbps with bad cable |
|
2733 * Decrease SNR threshold form 21.07dB to 19.04dB |
|
2734 */ |
|
2735 { 0x1f, 0x0001 }, |
|
2736 { 0x17, 0x0cc0 }, |
|
2737 |
|
2738 { 0x1f, 0x0000 }, |
|
2739 { 0x0d, 0xf880 } |
|
2740 }; |
|
2741 void __iomem *ioaddr = tp->mmio_addr; |
|
2742 |
|
2743 rtl_writephy_batch(tp, phy_reg_init_0, ARRAY_SIZE(phy_reg_init_0)); |
|
2744 |
|
2745 if (rtl8168d_efuse_read(ioaddr, 0x01) == 0xb1) { |
|
2746 static const struct phy_reg phy_reg_init[] = { |
|
2747 { 0x1f, 0x0002 }, |
|
2748 { 0x05, 0x669a }, |
|
2749 { 0x1f, 0x0005 }, |
|
2750 { 0x05, 0x8330 }, |
|
2751 { 0x06, 0x669a }, |
|
2752 |
|
2753 { 0x1f, 0x0002 } |
|
2754 }; |
|
2755 int val; |
|
2756 |
|
2757 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2758 |
|
2759 val = rtl_readphy(tp, 0x0d); |
|
2760 if ((val & 0x00ff) != 0x006c) { |
|
2761 static const u32 set[] = { |
|
2762 0x0065, 0x0066, 0x0067, 0x0068, |
|
2763 0x0069, 0x006a, 0x006b, 0x006c |
|
2764 }; |
|
2765 int i; |
|
2766 |
|
2767 rtl_writephy(tp, 0x1f, 0x0002); |
|
2768 |
|
2769 val &= 0xff00; |
|
2770 for (i = 0; i < ARRAY_SIZE(set); i++) |
|
2771 rtl_writephy(tp, 0x0d, val | set[i]); |
|
2772 } |
|
2773 } else { |
|
2774 static const struct phy_reg phy_reg_init[] = { |
|
2775 { 0x1f, 0x0002 }, |
|
2776 { 0x05, 0x2642 }, |
|
2777 { 0x1f, 0x0005 }, |
|
2778 { 0x05, 0x8330 }, |
|
2779 { 0x06, 0x2642 } |
|
2780 }; |
|
2781 |
|
2782 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2783 } |
|
2784 |
|
2785 /* Fine tune PLL performance */ |
|
2786 rtl_writephy(tp, 0x1f, 0x0002); |
|
2787 rtl_w1w0_phy(tp, 0x02, 0x0100, 0x0600); |
|
2788 rtl_w1w0_phy(tp, 0x03, 0x0000, 0xe000); |
|
2789 |
|
2790 /* Switching regulator Slew rate */ |
|
2791 rtl_writephy(tp, 0x1f, 0x0002); |
|
2792 rtl_patchphy(tp, 0x0f, 0x0017); |
|
2793 |
|
2794 rtl_writephy(tp, 0x1f, 0x0005); |
|
2795 rtl_writephy(tp, 0x05, 0x001b); |
|
2796 |
|
2797 rtl_apply_firmware_cond(tp, MII_EXPANSION, 0xb300); |
|
2798 |
|
2799 rtl_writephy(tp, 0x1f, 0x0000); |
|
2800 } |
|
2801 |
|
2802 static void rtl8168d_3_hw_phy_config(struct rtl8169_private *tp) |
|
2803 { |
|
2804 static const struct phy_reg phy_reg_init[] = { |
|
2805 { 0x1f, 0x0002 }, |
|
2806 { 0x10, 0x0008 }, |
|
2807 { 0x0d, 0x006c }, |
|
2808 |
|
2809 { 0x1f, 0x0000 }, |
|
2810 { 0x0d, 0xf880 }, |
|
2811 |
|
2812 { 0x1f, 0x0001 }, |
|
2813 { 0x17, 0x0cc0 }, |
|
2814 |
|
2815 { 0x1f, 0x0001 }, |
|
2816 { 0x0b, 0xa4d8 }, |
|
2817 { 0x09, 0x281c }, |
|
2818 { 0x07, 0x2883 }, |
|
2819 { 0x0a, 0x6b35 }, |
|
2820 { 0x1d, 0x3da4 }, |
|
2821 { 0x1c, 0xeffd }, |
|
2822 { 0x14, 0x7f52 }, |
|
2823 { 0x18, 0x7fc6 }, |
|
2824 { 0x08, 0x0601 }, |
|
2825 { 0x06, 0x4063 }, |
|
2826 { 0x10, 0xf074 }, |
|
2827 { 0x1f, 0x0003 }, |
|
2828 { 0x13, 0x0789 }, |
|
2829 { 0x12, 0xf4bd }, |
|
2830 { 0x1a, 0x04fd }, |
|
2831 { 0x14, 0x84b0 }, |
|
2832 { 0x1f, 0x0000 }, |
|
2833 { 0x00, 0x9200 }, |
|
2834 |
|
2835 { 0x1f, 0x0005 }, |
|
2836 { 0x01, 0x0340 }, |
|
2837 { 0x1f, 0x0001 }, |
|
2838 { 0x04, 0x4000 }, |
|
2839 { 0x03, 0x1d21 }, |
|
2840 { 0x02, 0x0c32 }, |
|
2841 { 0x01, 0x0200 }, |
|
2842 { 0x00, 0x5554 }, |
|
2843 { 0x04, 0x4800 }, |
|
2844 { 0x04, 0x4000 }, |
|
2845 { 0x04, 0xf000 }, |
|
2846 { 0x03, 0xdf01 }, |
|
2847 { 0x02, 0xdf20 }, |
|
2848 { 0x01, 0x101a }, |
|
2849 { 0x00, 0xa0ff }, |
|
2850 { 0x04, 0xf800 }, |
|
2851 { 0x04, 0xf000 }, |
|
2852 { 0x1f, 0x0000 }, |
|
2853 |
|
2854 { 0x1f, 0x0007 }, |
|
2855 { 0x1e, 0x0023 }, |
|
2856 { 0x16, 0x0000 }, |
|
2857 { 0x1f, 0x0000 } |
|
2858 }; |
|
2859 |
|
2860 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2861 } |
|
2862 |
|
2863 static void rtl8168d_4_hw_phy_config(struct rtl8169_private *tp) |
|
2864 { |
|
2865 static const struct phy_reg phy_reg_init[] = { |
|
2866 { 0x1f, 0x0001 }, |
|
2867 { 0x17, 0x0cc0 }, |
|
2868 |
|
2869 { 0x1f, 0x0007 }, |
|
2870 { 0x1e, 0x002d }, |
|
2871 { 0x18, 0x0040 }, |
|
2872 { 0x1f, 0x0000 } |
|
2873 }; |
|
2874 |
|
2875 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2876 rtl_patchphy(tp, 0x0d, 1 << 5); |
|
2877 } |
|
2878 |
|
2879 static void rtl8168e_1_hw_phy_config(struct rtl8169_private *tp) |
|
2880 { |
|
2881 static const struct phy_reg phy_reg_init[] = { |
|
2882 /* Enable Delay cap */ |
|
2883 { 0x1f, 0x0005 }, |
|
2884 { 0x05, 0x8b80 }, |
|
2885 { 0x06, 0xc896 }, |
|
2886 { 0x1f, 0x0000 }, |
|
2887 |
|
2888 /* Channel estimation fine tune */ |
|
2889 { 0x1f, 0x0001 }, |
|
2890 { 0x0b, 0x6c20 }, |
|
2891 { 0x07, 0x2872 }, |
|
2892 { 0x1c, 0xefff }, |
|
2893 { 0x1f, 0x0003 }, |
|
2894 { 0x14, 0x6420 }, |
|
2895 { 0x1f, 0x0000 }, |
|
2896 |
|
2897 /* Update PFM & 10M TX idle timer */ |
|
2898 { 0x1f, 0x0007 }, |
|
2899 { 0x1e, 0x002f }, |
|
2900 { 0x15, 0x1919 }, |
|
2901 { 0x1f, 0x0000 }, |
|
2902 |
|
2903 { 0x1f, 0x0007 }, |
|
2904 { 0x1e, 0x00ac }, |
|
2905 { 0x18, 0x0006 }, |
|
2906 { 0x1f, 0x0000 } |
|
2907 }; |
|
2908 |
|
2909 rtl_apply_firmware(tp); |
|
2910 |
|
2911 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2912 |
|
2913 /* DCO enable for 10M IDLE Power */ |
|
2914 rtl_writephy(tp, 0x1f, 0x0007); |
|
2915 rtl_writephy(tp, 0x1e, 0x0023); |
|
2916 rtl_w1w0_phy(tp, 0x17, 0x0006, 0x0000); |
|
2917 rtl_writephy(tp, 0x1f, 0x0000); |
|
2918 |
|
2919 /* For impedance matching */ |
|
2920 rtl_writephy(tp, 0x1f, 0x0002); |
|
2921 rtl_w1w0_phy(tp, 0x08, 0x8000, 0x7f00); |
|
2922 rtl_writephy(tp, 0x1f, 0x0000); |
|
2923 |
|
2924 /* PHY auto speed down */ |
|
2925 rtl_writephy(tp, 0x1f, 0x0007); |
|
2926 rtl_writephy(tp, 0x1e, 0x002d); |
|
2927 rtl_w1w0_phy(tp, 0x18, 0x0050, 0x0000); |
|
2928 rtl_writephy(tp, 0x1f, 0x0000); |
|
2929 rtl_w1w0_phy(tp, 0x14, 0x8000, 0x0000); |
|
2930 |
|
2931 rtl_writephy(tp, 0x1f, 0x0005); |
|
2932 rtl_writephy(tp, 0x05, 0x8b86); |
|
2933 rtl_w1w0_phy(tp, 0x06, 0x0001, 0x0000); |
|
2934 rtl_writephy(tp, 0x1f, 0x0000); |
|
2935 |
|
2936 rtl_writephy(tp, 0x1f, 0x0005); |
|
2937 rtl_writephy(tp, 0x05, 0x8b85); |
|
2938 rtl_w1w0_phy(tp, 0x06, 0x0000, 0x2000); |
|
2939 rtl_writephy(tp, 0x1f, 0x0007); |
|
2940 rtl_writephy(tp, 0x1e, 0x0020); |
|
2941 rtl_w1w0_phy(tp, 0x15, 0x0000, 0x1100); |
|
2942 rtl_writephy(tp, 0x1f, 0x0006); |
|
2943 rtl_writephy(tp, 0x00, 0x5a00); |
|
2944 rtl_writephy(tp, 0x1f, 0x0000); |
|
2945 rtl_writephy(tp, 0x0d, 0x0007); |
|
2946 rtl_writephy(tp, 0x0e, 0x003c); |
|
2947 rtl_writephy(tp, 0x0d, 0x4007); |
|
2948 rtl_writephy(tp, 0x0e, 0x0000); |
|
2949 rtl_writephy(tp, 0x0d, 0x0000); |
|
2950 } |
|
2951 |
|
2952 static void rtl8168e_2_hw_phy_config(struct rtl8169_private *tp) |
|
2953 { |
|
2954 static const struct phy_reg phy_reg_init[] = { |
|
2955 /* Enable Delay cap */ |
|
2956 { 0x1f, 0x0004 }, |
|
2957 { 0x1f, 0x0007 }, |
|
2958 { 0x1e, 0x00ac }, |
|
2959 { 0x18, 0x0006 }, |
|
2960 { 0x1f, 0x0002 }, |
|
2961 { 0x1f, 0x0000 }, |
|
2962 { 0x1f, 0x0000 }, |
|
2963 |
|
2964 /* Channel estimation fine tune */ |
|
2965 { 0x1f, 0x0003 }, |
|
2966 { 0x09, 0xa20f }, |
|
2967 { 0x1f, 0x0000 }, |
|
2968 { 0x1f, 0x0000 }, |
|
2969 |
|
2970 /* Green Setting */ |
|
2971 { 0x1f, 0x0005 }, |
|
2972 { 0x05, 0x8b5b }, |
|
2973 { 0x06, 0x9222 }, |
|
2974 { 0x05, 0x8b6d }, |
|
2975 { 0x06, 0x8000 }, |
|
2976 { 0x05, 0x8b76 }, |
|
2977 { 0x06, 0x8000 }, |
|
2978 { 0x1f, 0x0000 } |
|
2979 }; |
|
2980 |
|
2981 rtl_apply_firmware(tp); |
|
2982 |
|
2983 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
2984 |
|
2985 /* For 4-corner performance improve */ |
|
2986 rtl_writephy(tp, 0x1f, 0x0005); |
|
2987 rtl_writephy(tp, 0x05, 0x8b80); |
|
2988 rtl_w1w0_phy(tp, 0x17, 0x0006, 0x0000); |
|
2989 rtl_writephy(tp, 0x1f, 0x0000); |
|
2990 |
|
2991 /* PHY auto speed down */ |
|
2992 rtl_writephy(tp, 0x1f, 0x0004); |
|
2993 rtl_writephy(tp, 0x1f, 0x0007); |
|
2994 rtl_writephy(tp, 0x1e, 0x002d); |
|
2995 rtl_w1w0_phy(tp, 0x18, 0x0010, 0x0000); |
|
2996 rtl_writephy(tp, 0x1f, 0x0002); |
|
2997 rtl_writephy(tp, 0x1f, 0x0000); |
|
2998 rtl_w1w0_phy(tp, 0x14, 0x8000, 0x0000); |
|
2999 |
|
3000 /* improve 10M EEE waveform */ |
|
3001 rtl_writephy(tp, 0x1f, 0x0005); |
|
3002 rtl_writephy(tp, 0x05, 0x8b86); |
|
3003 rtl_w1w0_phy(tp, 0x06, 0x0001, 0x0000); |
|
3004 rtl_writephy(tp, 0x1f, 0x0000); |
|
3005 |
|
3006 /* Improve 2-pair detection performance */ |
|
3007 rtl_writephy(tp, 0x1f, 0x0005); |
|
3008 rtl_writephy(tp, 0x05, 0x8b85); |
|
3009 rtl_w1w0_phy(tp, 0x06, 0x4000, 0x0000); |
|
3010 rtl_writephy(tp, 0x1f, 0x0000); |
|
3011 |
|
3012 /* EEE setting */ |
|
3013 rtl_w1w0_eri(tp->mmio_addr, 0x1b0, ERIAR_MASK_1111, 0x0000, 0x0003, |
|
3014 ERIAR_EXGMAC); |
|
3015 rtl_writephy(tp, 0x1f, 0x0005); |
|
3016 rtl_writephy(tp, 0x05, 0x8b85); |
|
3017 rtl_w1w0_phy(tp, 0x06, 0x0000, 0x2000); |
|
3018 rtl_writephy(tp, 0x1f, 0x0004); |
|
3019 rtl_writephy(tp, 0x1f, 0x0007); |
|
3020 rtl_writephy(tp, 0x1e, 0x0020); |
|
3021 rtl_w1w0_phy(tp, 0x15, 0x0000, 0x0100); |
|
3022 rtl_writephy(tp, 0x1f, 0x0002); |
|
3023 rtl_writephy(tp, 0x1f, 0x0000); |
|
3024 rtl_writephy(tp, 0x0d, 0x0007); |
|
3025 rtl_writephy(tp, 0x0e, 0x003c); |
|
3026 rtl_writephy(tp, 0x0d, 0x4007); |
|
3027 rtl_writephy(tp, 0x0e, 0x0000); |
|
3028 rtl_writephy(tp, 0x0d, 0x0000); |
|
3029 |
|
3030 /* Green feature */ |
|
3031 rtl_writephy(tp, 0x1f, 0x0003); |
|
3032 rtl_w1w0_phy(tp, 0x19, 0x0000, 0x0001); |
|
3033 rtl_w1w0_phy(tp, 0x10, 0x0000, 0x0400); |
|
3034 rtl_writephy(tp, 0x1f, 0x0000); |
|
3035 } |
|
3036 |
|
3037 static void rtl8168f_1_hw_phy_config(struct rtl8169_private *tp) |
|
3038 { |
|
3039 static const struct phy_reg phy_reg_init[] = { |
|
3040 /* Channel estimation fine tune */ |
|
3041 { 0x1f, 0x0003 }, |
|
3042 { 0x09, 0xa20f }, |
|
3043 { 0x1f, 0x0000 }, |
|
3044 |
|
3045 /* Modify green table for giga & fnet */ |
|
3046 { 0x1f, 0x0005 }, |
|
3047 { 0x05, 0x8b55 }, |
|
3048 { 0x06, 0x0000 }, |
|
3049 { 0x05, 0x8b5e }, |
|
3050 { 0x06, 0x0000 }, |
|
3051 { 0x05, 0x8b67 }, |
|
3052 { 0x06, 0x0000 }, |
|
3053 { 0x05, 0x8b70 }, |
|
3054 { 0x06, 0x0000 }, |
|
3055 { 0x1f, 0x0000 }, |
|
3056 { 0x1f, 0x0007 }, |
|
3057 { 0x1e, 0x0078 }, |
|
3058 { 0x17, 0x0000 }, |
|
3059 { 0x19, 0x00fb }, |
|
3060 { 0x1f, 0x0000 }, |
|
3061 |
|
3062 /* Modify green table for 10M */ |
|
3063 { 0x1f, 0x0005 }, |
|
3064 { 0x05, 0x8b79 }, |
|
3065 { 0x06, 0xaa00 }, |
|
3066 { 0x1f, 0x0000 }, |
|
3067 |
|
3068 /* Disable hiimpedance detection (RTCT) */ |
|
3069 { 0x1f, 0x0003 }, |
|
3070 { 0x01, 0x328a }, |
|
3071 { 0x1f, 0x0000 } |
|
3072 }; |
|
3073 |
|
3074 rtl_apply_firmware(tp); |
|
3075 |
|
3076 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
3077 |
|
3078 /* For 4-corner performance improve */ |
|
3079 rtl_writephy(tp, 0x1f, 0x0005); |
|
3080 rtl_writephy(tp, 0x05, 0x8b80); |
|
3081 rtl_w1w0_phy(tp, 0x06, 0x0006, 0x0000); |
|
3082 rtl_writephy(tp, 0x1f, 0x0000); |
|
3083 |
|
3084 /* PHY auto speed down */ |
|
3085 rtl_writephy(tp, 0x1f, 0x0007); |
|
3086 rtl_writephy(tp, 0x1e, 0x002d); |
|
3087 rtl_w1w0_phy(tp, 0x18, 0x0010, 0x0000); |
|
3088 rtl_writephy(tp, 0x1f, 0x0000); |
|
3089 rtl_w1w0_phy(tp, 0x14, 0x8000, 0x0000); |
|
3090 |
|
3091 /* Improve 10M EEE waveform */ |
|
3092 rtl_writephy(tp, 0x1f, 0x0005); |
|
3093 rtl_writephy(tp, 0x05, 0x8b86); |
|
3094 rtl_w1w0_phy(tp, 0x06, 0x0001, 0x0000); |
|
3095 rtl_writephy(tp, 0x1f, 0x0000); |
|
3096 |
|
3097 /* Improve 2-pair detection performance */ |
|
3098 rtl_writephy(tp, 0x1f, 0x0005); |
|
3099 rtl_writephy(tp, 0x05, 0x8b85); |
|
3100 rtl_w1w0_phy(tp, 0x06, 0x4000, 0x0000); |
|
3101 rtl_writephy(tp, 0x1f, 0x0000); |
|
3102 } |
|
3103 |
|
3104 static void rtl8168f_2_hw_phy_config(struct rtl8169_private *tp) |
|
3105 { |
|
3106 rtl_apply_firmware(tp); |
|
3107 |
|
3108 /* For 4-corner performance improve */ |
|
3109 rtl_writephy(tp, 0x1f, 0x0005); |
|
3110 rtl_writephy(tp, 0x05, 0x8b80); |
|
3111 rtl_w1w0_phy(tp, 0x06, 0x0006, 0x0000); |
|
3112 rtl_writephy(tp, 0x1f, 0x0000); |
|
3113 |
|
3114 /* PHY auto speed down */ |
|
3115 rtl_writephy(tp, 0x1f, 0x0007); |
|
3116 rtl_writephy(tp, 0x1e, 0x002d); |
|
3117 rtl_w1w0_phy(tp, 0x18, 0x0010, 0x0000); |
|
3118 rtl_writephy(tp, 0x1f, 0x0000); |
|
3119 rtl_w1w0_phy(tp, 0x14, 0x8000, 0x0000); |
|
3120 |
|
3121 /* Improve 10M EEE waveform */ |
|
3122 rtl_writephy(tp, 0x1f, 0x0005); |
|
3123 rtl_writephy(tp, 0x05, 0x8b86); |
|
3124 rtl_w1w0_phy(tp, 0x06, 0x0001, 0x0000); |
|
3125 rtl_writephy(tp, 0x1f, 0x0000); |
|
3126 } |
|
3127 |
|
3128 static void rtl8102e_hw_phy_config(struct rtl8169_private *tp) |
|
3129 { |
|
3130 static const struct phy_reg phy_reg_init[] = { |
|
3131 { 0x1f, 0x0003 }, |
|
3132 { 0x08, 0x441d }, |
|
3133 { 0x01, 0x9100 }, |
|
3134 { 0x1f, 0x0000 } |
|
3135 }; |
|
3136 |
|
3137 rtl_writephy(tp, 0x1f, 0x0000); |
|
3138 rtl_patchphy(tp, 0x11, 1 << 12); |
|
3139 rtl_patchphy(tp, 0x19, 1 << 13); |
|
3140 rtl_patchphy(tp, 0x10, 1 << 15); |
|
3141 |
|
3142 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
3143 } |
|
3144 |
|
3145 static void rtl8105e_hw_phy_config(struct rtl8169_private *tp) |
|
3146 { |
|
3147 static const struct phy_reg phy_reg_init[] = { |
|
3148 { 0x1f, 0x0005 }, |
|
3149 { 0x1a, 0x0000 }, |
|
3150 { 0x1f, 0x0000 }, |
|
3151 |
|
3152 { 0x1f, 0x0004 }, |
|
3153 { 0x1c, 0x0000 }, |
|
3154 { 0x1f, 0x0000 }, |
|
3155 |
|
3156 { 0x1f, 0x0001 }, |
|
3157 { 0x15, 0x7701 }, |
|
3158 { 0x1f, 0x0000 } |
|
3159 }; |
|
3160 |
|
3161 /* Disable ALDPS before ram code */ |
|
3162 rtl_writephy(tp, 0x1f, 0x0000); |
|
3163 rtl_writephy(tp, 0x18, 0x0310); |
|
3164 msleep(100); |
|
3165 |
|
3166 rtl_apply_firmware(tp); |
|
3167 |
|
3168 rtl_writephy_batch(tp, phy_reg_init, ARRAY_SIZE(phy_reg_init)); |
|
3169 } |
|
3170 |
|
3171 static void rtl_hw_phy_config(struct net_device *dev) |
|
3172 { |
|
3173 struct rtl8169_private *tp = netdev_priv(dev); |
|
3174 |
|
3175 rtl8169_print_mac_version(tp); |
|
3176 |
|
3177 switch (tp->mac_version) { |
|
3178 case RTL_GIGA_MAC_VER_01: |
|
3179 break; |
|
3180 case RTL_GIGA_MAC_VER_02: |
|
3181 case RTL_GIGA_MAC_VER_03: |
|
3182 rtl8169s_hw_phy_config(tp); |
|
3183 break; |
|
3184 case RTL_GIGA_MAC_VER_04: |
|
3185 rtl8169sb_hw_phy_config(tp); |
|
3186 break; |
|
3187 case RTL_GIGA_MAC_VER_05: |
|
3188 rtl8169scd_hw_phy_config(tp); |
|
3189 break; |
|
3190 case RTL_GIGA_MAC_VER_06: |
|
3191 rtl8169sce_hw_phy_config(tp); |
|
3192 break; |
|
3193 case RTL_GIGA_MAC_VER_07: |
|
3194 case RTL_GIGA_MAC_VER_08: |
|
3195 case RTL_GIGA_MAC_VER_09: |
|
3196 rtl8102e_hw_phy_config(tp); |
|
3197 break; |
|
3198 case RTL_GIGA_MAC_VER_11: |
|
3199 rtl8168bb_hw_phy_config(tp); |
|
3200 break; |
|
3201 case RTL_GIGA_MAC_VER_12: |
|
3202 rtl8168bef_hw_phy_config(tp); |
|
3203 break; |
|
3204 case RTL_GIGA_MAC_VER_17: |
|
3205 rtl8168bef_hw_phy_config(tp); |
|
3206 break; |
|
3207 case RTL_GIGA_MAC_VER_18: |
|
3208 rtl8168cp_1_hw_phy_config(tp); |
|
3209 break; |
|
3210 case RTL_GIGA_MAC_VER_19: |
|
3211 rtl8168c_1_hw_phy_config(tp); |
|
3212 break; |
|
3213 case RTL_GIGA_MAC_VER_20: |
|
3214 rtl8168c_2_hw_phy_config(tp); |
|
3215 break; |
|
3216 case RTL_GIGA_MAC_VER_21: |
|
3217 rtl8168c_3_hw_phy_config(tp); |
|
3218 break; |
|
3219 case RTL_GIGA_MAC_VER_22: |
|
3220 rtl8168c_4_hw_phy_config(tp); |
|
3221 break; |
|
3222 case RTL_GIGA_MAC_VER_23: |
|
3223 case RTL_GIGA_MAC_VER_24: |
|
3224 rtl8168cp_2_hw_phy_config(tp); |
|
3225 break; |
|
3226 case RTL_GIGA_MAC_VER_25: |
|
3227 rtl8168d_1_hw_phy_config(tp); |
|
3228 break; |
|
3229 case RTL_GIGA_MAC_VER_26: |
|
3230 rtl8168d_2_hw_phy_config(tp); |
|
3231 break; |
|
3232 case RTL_GIGA_MAC_VER_27: |
|
3233 rtl8168d_3_hw_phy_config(tp); |
|
3234 break; |
|
3235 case RTL_GIGA_MAC_VER_28: |
|
3236 rtl8168d_4_hw_phy_config(tp); |
|
3237 break; |
|
3238 case RTL_GIGA_MAC_VER_29: |
|
3239 case RTL_GIGA_MAC_VER_30: |
|
3240 rtl8105e_hw_phy_config(tp); |
|
3241 break; |
|
3242 case RTL_GIGA_MAC_VER_31: |
|
3243 /* None. */ |
|
3244 break; |
|
3245 case RTL_GIGA_MAC_VER_32: |
|
3246 case RTL_GIGA_MAC_VER_33: |
|
3247 rtl8168e_1_hw_phy_config(tp); |
|
3248 break; |
|
3249 case RTL_GIGA_MAC_VER_34: |
|
3250 rtl8168e_2_hw_phy_config(tp); |
|
3251 break; |
|
3252 case RTL_GIGA_MAC_VER_35: |
|
3253 rtl8168f_1_hw_phy_config(tp); |
|
3254 break; |
|
3255 case RTL_GIGA_MAC_VER_36: |
|
3256 rtl8168f_2_hw_phy_config(tp); |
|
3257 break; |
|
3258 |
|
3259 default: |
|
3260 break; |
|
3261 } |
|
3262 } |
|
3263 |
|
3264 static void rtl_phy_work(struct rtl8169_private *tp) |
|
3265 { |
|
3266 struct timer_list *timer = &tp->timer; |
|
3267 void __iomem *ioaddr = tp->mmio_addr; |
|
3268 unsigned long timeout = RTL8169_PHY_TIMEOUT; |
|
3269 |
|
3270 assert(tp->mac_version > RTL_GIGA_MAC_VER_01); |
|
3271 |
|
3272 if (tp->phy_reset_pending(tp)) { |
|
3273 /* |
|
3274 * A busy loop could burn quite a few cycles on nowadays CPU. |
|
3275 * Let's delay the execution of the timer for a few ticks. |
|
3276 */ |
|
3277 timeout = HZ/10; |
|
3278 goto out_mod_timer; |
|
3279 } |
|
3280 |
|
3281 if (tp->link_ok(ioaddr)) |
|
3282 return; |
|
3283 |
|
3284 netif_warn(tp, link, tp->dev, "PHY reset until link up\n"); |
|
3285 |
|
3286 tp->phy_reset_enable(tp); |
|
3287 |
|
3288 out_mod_timer: |
|
3289 mod_timer(timer, jiffies + timeout); |
|
3290 } |
|
3291 |
|
3292 static void rtl_schedule_task(struct rtl8169_private *tp, enum rtl_flag flag) |
|
3293 { |
|
3294 if (!test_and_set_bit(flag, tp->wk.flags)) |
|
3295 schedule_work(&tp->wk.work); |
|
3296 } |
|
3297 |
|
3298 static void rtl8169_phy_timer(unsigned long __opaque) |
|
3299 { |
|
3300 struct net_device *dev = (struct net_device *)__opaque; |
|
3301 struct rtl8169_private *tp = netdev_priv(dev); |
|
3302 |
|
3303 rtl_schedule_task(tp, RTL_FLAG_TASK_PHY_PENDING); |
|
3304 } |
|
3305 |
|
3306 static void rtl8169_release_board(struct pci_dev *pdev, struct net_device *dev, |
|
3307 void __iomem *ioaddr) |
|
3308 { |
|
3309 iounmap(ioaddr); |
|
3310 pci_release_regions(pdev); |
|
3311 pci_clear_mwi(pdev); |
|
3312 pci_disable_device(pdev); |
|
3313 free_netdev(dev); |
|
3314 } |
|
3315 |
|
3316 static void rtl8169_phy_reset(struct net_device *dev, |
|
3317 struct rtl8169_private *tp) |
|
3318 { |
|
3319 unsigned int i; |
|
3320 |
|
3321 tp->phy_reset_enable(tp); |
|
3322 for (i = 0; i < 100; i++) { |
|
3323 if (!tp->phy_reset_pending(tp)) |
|
3324 return; |
|
3325 msleep(1); |
|
3326 } |
|
3327 netif_err(tp, link, dev, "PHY reset failed\n"); |
|
3328 } |
|
3329 |
|
3330 static bool rtl_tbi_enabled(struct rtl8169_private *tp) |
|
3331 { |
|
3332 void __iomem *ioaddr = tp->mmio_addr; |
|
3333 |
|
3334 return (tp->mac_version == RTL_GIGA_MAC_VER_01) && |
|
3335 (RTL_R8(PHYstatus) & TBI_Enable); |
|
3336 } |
|
3337 |
|
3338 static void rtl8169_init_phy(struct net_device *dev, struct rtl8169_private *tp) |
|
3339 { |
|
3340 void __iomem *ioaddr = tp->mmio_addr; |
|
3341 |
|
3342 rtl_hw_phy_config(dev); |
|
3343 |
|
3344 if (tp->mac_version <= RTL_GIGA_MAC_VER_06) { |
|
3345 dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
|
3346 RTL_W8(0x82, 0x01); |
|
3347 } |
|
3348 |
|
3349 pci_write_config_byte(tp->pci_dev, PCI_LATENCY_TIMER, 0x40); |
|
3350 |
|
3351 if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
|
3352 pci_write_config_byte(tp->pci_dev, PCI_CACHE_LINE_SIZE, 0x08); |
|
3353 |
|
3354 if (tp->mac_version == RTL_GIGA_MAC_VER_02) { |
|
3355 dprintk("Set MAC Reg C+CR Offset 0x82h = 0x01h\n"); |
|
3356 RTL_W8(0x82, 0x01); |
|
3357 dprintk("Set PHY Reg 0x0bh = 0x00h\n"); |
|
3358 rtl_writephy(tp, 0x0b, 0x0000); //w 0x0b 15 0 0 |
|
3359 } |
|
3360 |
|
3361 rtl8169_phy_reset(dev, tp); |
|
3362 |
|
3363 rtl8169_set_speed(dev, AUTONEG_ENABLE, SPEED_1000, DUPLEX_FULL, |
|
3364 ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
|
3365 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full | |
|
3366 (tp->mii.supports_gmii ? |
|
3367 ADVERTISED_1000baseT_Half | |
|
3368 ADVERTISED_1000baseT_Full : 0)); |
|
3369 |
|
3370 if (rtl_tbi_enabled(tp)) |
|
3371 netif_info(tp, link, dev, "TBI auto-negotiating\n"); |
|
3372 } |
|
3373 |
|
3374 static void rtl_rar_set(struct rtl8169_private *tp, u8 *addr) |
|
3375 { |
|
3376 void __iomem *ioaddr = tp->mmio_addr; |
|
3377 u32 high; |
|
3378 u32 low; |
|
3379 |
|
3380 low = addr[0] | (addr[1] << 8) | (addr[2] << 16) | (addr[3] << 24); |
|
3381 high = addr[4] | (addr[5] << 8); |
|
3382 |
|
3383 rtl_lock_work(tp); |
|
3384 |
|
3385 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
3386 |
|
3387 RTL_W32(MAC4, high); |
|
3388 RTL_R32(MAC4); |
|
3389 |
|
3390 RTL_W32(MAC0, low); |
|
3391 RTL_R32(MAC0); |
|
3392 |
|
3393 if (tp->mac_version == RTL_GIGA_MAC_VER_34) { |
|
3394 const struct exgmac_reg e[] = { |
|
3395 { .addr = 0xe0, ERIAR_MASK_1111, .val = low }, |
|
3396 { .addr = 0xe4, ERIAR_MASK_1111, .val = high }, |
|
3397 { .addr = 0xf0, ERIAR_MASK_1111, .val = low << 16 }, |
|
3398 { .addr = 0xf4, ERIAR_MASK_1111, .val = high << 16 | |
|
3399 low >> 16 }, |
|
3400 }; |
|
3401 |
|
3402 rtl_write_exgmac_batch(ioaddr, e, ARRAY_SIZE(e)); |
|
3403 } |
|
3404 |
|
3405 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
3406 |
|
3407 rtl_unlock_work(tp); |
|
3408 } |
|
3409 |
|
3410 static int rtl_set_mac_address(struct net_device *dev, void *p) |
|
3411 { |
|
3412 struct rtl8169_private *tp = netdev_priv(dev); |
|
3413 struct sockaddr *addr = p; |
|
3414 |
|
3415 if (!is_valid_ether_addr(addr->sa_data)) |
|
3416 return -EADDRNOTAVAIL; |
|
3417 |
|
3418 memcpy(dev->dev_addr, addr->sa_data, dev->addr_len); |
|
3419 |
|
3420 rtl_rar_set(tp, dev->dev_addr); |
|
3421 |
|
3422 return 0; |
|
3423 } |
|
3424 |
|
3425 static int rtl8169_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd) |
|
3426 { |
|
3427 struct rtl8169_private *tp = netdev_priv(dev); |
|
3428 struct mii_ioctl_data *data = if_mii(ifr); |
|
3429 |
|
3430 return netif_running(dev) ? tp->do_ioctl(tp, data, cmd) : -ENODEV; |
|
3431 } |
|
3432 |
|
3433 static int rtl_xmii_ioctl(struct rtl8169_private *tp, |
|
3434 struct mii_ioctl_data *data, int cmd) |
|
3435 { |
|
3436 switch (cmd) { |
|
3437 case SIOCGMIIPHY: |
|
3438 data->phy_id = 32; /* Internal PHY */ |
|
3439 return 0; |
|
3440 |
|
3441 case SIOCGMIIREG: |
|
3442 data->val_out = rtl_readphy(tp, data->reg_num & 0x1f); |
|
3443 return 0; |
|
3444 |
|
3445 case SIOCSMIIREG: |
|
3446 rtl_writephy(tp, data->reg_num & 0x1f, data->val_in); |
|
3447 return 0; |
|
3448 } |
|
3449 return -EOPNOTSUPP; |
|
3450 } |
|
3451 |
|
3452 static int rtl_tbi_ioctl(struct rtl8169_private *tp, struct mii_ioctl_data *data, int cmd) |
|
3453 { |
|
3454 return -EOPNOTSUPP; |
|
3455 } |
|
3456 |
|
3457 static void rtl_disable_msi(struct pci_dev *pdev, struct rtl8169_private *tp) |
|
3458 { |
|
3459 if (tp->features & RTL_FEATURE_MSI) { |
|
3460 pci_disable_msi(pdev); |
|
3461 tp->features &= ~RTL_FEATURE_MSI; |
|
3462 } |
|
3463 } |
|
3464 |
|
3465 static void __devinit rtl_init_mdio_ops(struct rtl8169_private *tp) |
|
3466 { |
|
3467 struct mdio_ops *ops = &tp->mdio_ops; |
|
3468 |
|
3469 switch (tp->mac_version) { |
|
3470 case RTL_GIGA_MAC_VER_27: |
|
3471 ops->write = r8168dp_1_mdio_write; |
|
3472 ops->read = r8168dp_1_mdio_read; |
|
3473 break; |
|
3474 case RTL_GIGA_MAC_VER_28: |
|
3475 case RTL_GIGA_MAC_VER_31: |
|
3476 ops->write = r8168dp_2_mdio_write; |
|
3477 ops->read = r8168dp_2_mdio_read; |
|
3478 break; |
|
3479 default: |
|
3480 ops->write = r8169_mdio_write; |
|
3481 ops->read = r8169_mdio_read; |
|
3482 break; |
|
3483 } |
|
3484 } |
|
3485 |
|
3486 static void rtl_wol_suspend_quirk(struct rtl8169_private *tp) |
|
3487 { |
|
3488 void __iomem *ioaddr = tp->mmio_addr; |
|
3489 |
|
3490 switch (tp->mac_version) { |
|
3491 case RTL_GIGA_MAC_VER_25: |
|
3492 case RTL_GIGA_MAC_VER_26: |
|
3493 case RTL_GIGA_MAC_VER_29: |
|
3494 case RTL_GIGA_MAC_VER_30: |
|
3495 case RTL_GIGA_MAC_VER_32: |
|
3496 case RTL_GIGA_MAC_VER_33: |
|
3497 case RTL_GIGA_MAC_VER_34: |
|
3498 RTL_W32(RxConfig, RTL_R32(RxConfig) | |
|
3499 AcceptBroadcast | AcceptMulticast | AcceptMyPhys); |
|
3500 break; |
|
3501 default: |
|
3502 break; |
|
3503 } |
|
3504 } |
|
3505 |
|
3506 static bool rtl_wol_pll_power_down(struct rtl8169_private *tp) |
|
3507 { |
|
3508 if (!(__rtl8169_get_wol(tp) & WAKE_ANY)) |
|
3509 return false; |
|
3510 |
|
3511 rtl_writephy(tp, 0x1f, 0x0000); |
|
3512 rtl_writephy(tp, MII_BMCR, 0x0000); |
|
3513 |
|
3514 rtl_wol_suspend_quirk(tp); |
|
3515 |
|
3516 return true; |
|
3517 } |
|
3518 |
|
3519 static void r810x_phy_power_down(struct rtl8169_private *tp) |
|
3520 { |
|
3521 rtl_writephy(tp, 0x1f, 0x0000); |
|
3522 rtl_writephy(tp, MII_BMCR, BMCR_PDOWN); |
|
3523 } |
|
3524 |
|
3525 static void r810x_phy_power_up(struct rtl8169_private *tp) |
|
3526 { |
|
3527 rtl_writephy(tp, 0x1f, 0x0000); |
|
3528 rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE); |
|
3529 } |
|
3530 |
|
3531 static void r810x_pll_power_down(struct rtl8169_private *tp) |
|
3532 { |
|
3533 if (rtl_wol_pll_power_down(tp)) |
|
3534 return; |
|
3535 |
|
3536 r810x_phy_power_down(tp); |
|
3537 } |
|
3538 |
|
3539 static void r810x_pll_power_up(struct rtl8169_private *tp) |
|
3540 { |
|
3541 r810x_phy_power_up(tp); |
|
3542 } |
|
3543 |
|
3544 static void r8168_phy_power_up(struct rtl8169_private *tp) |
|
3545 { |
|
3546 rtl_writephy(tp, 0x1f, 0x0000); |
|
3547 switch (tp->mac_version) { |
|
3548 case RTL_GIGA_MAC_VER_11: |
|
3549 case RTL_GIGA_MAC_VER_12: |
|
3550 case RTL_GIGA_MAC_VER_17: |
|
3551 case RTL_GIGA_MAC_VER_18: |
|
3552 case RTL_GIGA_MAC_VER_19: |
|
3553 case RTL_GIGA_MAC_VER_20: |
|
3554 case RTL_GIGA_MAC_VER_21: |
|
3555 case RTL_GIGA_MAC_VER_22: |
|
3556 case RTL_GIGA_MAC_VER_23: |
|
3557 case RTL_GIGA_MAC_VER_24: |
|
3558 case RTL_GIGA_MAC_VER_25: |
|
3559 case RTL_GIGA_MAC_VER_26: |
|
3560 case RTL_GIGA_MAC_VER_27: |
|
3561 case RTL_GIGA_MAC_VER_28: |
|
3562 case RTL_GIGA_MAC_VER_31: |
|
3563 rtl_writephy(tp, 0x0e, 0x0000); |
|
3564 break; |
|
3565 default: |
|
3566 break; |
|
3567 } |
|
3568 rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE); |
|
3569 } |
|
3570 |
|
3571 static void r8168_phy_power_down(struct rtl8169_private *tp) |
|
3572 { |
|
3573 rtl_writephy(tp, 0x1f, 0x0000); |
|
3574 switch (tp->mac_version) { |
|
3575 case RTL_GIGA_MAC_VER_32: |
|
3576 case RTL_GIGA_MAC_VER_33: |
|
3577 rtl_writephy(tp, MII_BMCR, BMCR_ANENABLE | BMCR_PDOWN); |
|
3578 break; |
|
3579 |
|
3580 case RTL_GIGA_MAC_VER_11: |
|
3581 case RTL_GIGA_MAC_VER_12: |
|
3582 case RTL_GIGA_MAC_VER_17: |
|
3583 case RTL_GIGA_MAC_VER_18: |
|
3584 case RTL_GIGA_MAC_VER_19: |
|
3585 case RTL_GIGA_MAC_VER_20: |
|
3586 case RTL_GIGA_MAC_VER_21: |
|
3587 case RTL_GIGA_MAC_VER_22: |
|
3588 case RTL_GIGA_MAC_VER_23: |
|
3589 case RTL_GIGA_MAC_VER_24: |
|
3590 case RTL_GIGA_MAC_VER_25: |
|
3591 case RTL_GIGA_MAC_VER_26: |
|
3592 case RTL_GIGA_MAC_VER_27: |
|
3593 case RTL_GIGA_MAC_VER_28: |
|
3594 case RTL_GIGA_MAC_VER_31: |
|
3595 rtl_writephy(tp, 0x0e, 0x0200); |
|
3596 default: |
|
3597 rtl_writephy(tp, MII_BMCR, BMCR_PDOWN); |
|
3598 break; |
|
3599 } |
|
3600 } |
|
3601 |
|
3602 static void r8168_pll_power_down(struct rtl8169_private *tp) |
|
3603 { |
|
3604 void __iomem *ioaddr = tp->mmio_addr; |
|
3605 |
|
3606 if ((tp->mac_version == RTL_GIGA_MAC_VER_27 || |
|
3607 tp->mac_version == RTL_GIGA_MAC_VER_28 || |
|
3608 tp->mac_version == RTL_GIGA_MAC_VER_31) && |
|
3609 r8168dp_check_dash(tp)) { |
|
3610 return; |
|
3611 } |
|
3612 |
|
3613 if ((tp->mac_version == RTL_GIGA_MAC_VER_23 || |
|
3614 tp->mac_version == RTL_GIGA_MAC_VER_24) && |
|
3615 (RTL_R16(CPlusCmd) & ASF)) { |
|
3616 return; |
|
3617 } |
|
3618 |
|
3619 if (tp->mac_version == RTL_GIGA_MAC_VER_32 || |
|
3620 tp->mac_version == RTL_GIGA_MAC_VER_33) |
|
3621 rtl_ephy_write(ioaddr, 0x19, 0xff64); |
|
3622 |
|
3623 if (rtl_wol_pll_power_down(tp)) |
|
3624 return; |
|
3625 |
|
3626 r8168_phy_power_down(tp); |
|
3627 |
|
3628 switch (tp->mac_version) { |
|
3629 case RTL_GIGA_MAC_VER_25: |
|
3630 case RTL_GIGA_MAC_VER_26: |
|
3631 case RTL_GIGA_MAC_VER_27: |
|
3632 case RTL_GIGA_MAC_VER_28: |
|
3633 case RTL_GIGA_MAC_VER_31: |
|
3634 case RTL_GIGA_MAC_VER_32: |
|
3635 case RTL_GIGA_MAC_VER_33: |
|
3636 RTL_W8(PMCH, RTL_R8(PMCH) & ~0x80); |
|
3637 break; |
|
3638 } |
|
3639 } |
|
3640 |
|
3641 static void r8168_pll_power_up(struct rtl8169_private *tp) |
|
3642 { |
|
3643 void __iomem *ioaddr = tp->mmio_addr; |
|
3644 |
|
3645 if ((tp->mac_version == RTL_GIGA_MAC_VER_27 || |
|
3646 tp->mac_version == RTL_GIGA_MAC_VER_28 || |
|
3647 tp->mac_version == RTL_GIGA_MAC_VER_31) && |
|
3648 r8168dp_check_dash(tp)) { |
|
3649 return; |
|
3650 } |
|
3651 |
|
3652 switch (tp->mac_version) { |
|
3653 case RTL_GIGA_MAC_VER_25: |
|
3654 case RTL_GIGA_MAC_VER_26: |
|
3655 case RTL_GIGA_MAC_VER_27: |
|
3656 case RTL_GIGA_MAC_VER_28: |
|
3657 case RTL_GIGA_MAC_VER_31: |
|
3658 case RTL_GIGA_MAC_VER_32: |
|
3659 case RTL_GIGA_MAC_VER_33: |
|
3660 RTL_W8(PMCH, RTL_R8(PMCH) | 0x80); |
|
3661 break; |
|
3662 } |
|
3663 |
|
3664 r8168_phy_power_up(tp); |
|
3665 } |
|
3666 |
|
3667 static void rtl_generic_op(struct rtl8169_private *tp, |
|
3668 void (*op)(struct rtl8169_private *)) |
|
3669 { |
|
3670 if (op) |
|
3671 op(tp); |
|
3672 } |
|
3673 |
|
3674 static void rtl_pll_power_down(struct rtl8169_private *tp) |
|
3675 { |
|
3676 rtl_generic_op(tp, tp->pll_power_ops.down); |
|
3677 } |
|
3678 |
|
3679 static void rtl_pll_power_up(struct rtl8169_private *tp) |
|
3680 { |
|
3681 rtl_generic_op(tp, tp->pll_power_ops.up); |
|
3682 } |
|
3683 |
|
3684 static void __devinit rtl_init_pll_power_ops(struct rtl8169_private *tp) |
|
3685 { |
|
3686 struct pll_power_ops *ops = &tp->pll_power_ops; |
|
3687 |
|
3688 switch (tp->mac_version) { |
|
3689 case RTL_GIGA_MAC_VER_07: |
|
3690 case RTL_GIGA_MAC_VER_08: |
|
3691 case RTL_GIGA_MAC_VER_09: |
|
3692 case RTL_GIGA_MAC_VER_10: |
|
3693 case RTL_GIGA_MAC_VER_16: |
|
3694 case RTL_GIGA_MAC_VER_29: |
|
3695 case RTL_GIGA_MAC_VER_30: |
|
3696 ops->down = r810x_pll_power_down; |
|
3697 ops->up = r810x_pll_power_up; |
|
3698 break; |
|
3699 |
|
3700 case RTL_GIGA_MAC_VER_11: |
|
3701 case RTL_GIGA_MAC_VER_12: |
|
3702 case RTL_GIGA_MAC_VER_17: |
|
3703 case RTL_GIGA_MAC_VER_18: |
|
3704 case RTL_GIGA_MAC_VER_19: |
|
3705 case RTL_GIGA_MAC_VER_20: |
|
3706 case RTL_GIGA_MAC_VER_21: |
|
3707 case RTL_GIGA_MAC_VER_22: |
|
3708 case RTL_GIGA_MAC_VER_23: |
|
3709 case RTL_GIGA_MAC_VER_24: |
|
3710 case RTL_GIGA_MAC_VER_25: |
|
3711 case RTL_GIGA_MAC_VER_26: |
|
3712 case RTL_GIGA_MAC_VER_27: |
|
3713 case RTL_GIGA_MAC_VER_28: |
|
3714 case RTL_GIGA_MAC_VER_31: |
|
3715 case RTL_GIGA_MAC_VER_32: |
|
3716 case RTL_GIGA_MAC_VER_33: |
|
3717 case RTL_GIGA_MAC_VER_34: |
|
3718 case RTL_GIGA_MAC_VER_35: |
|
3719 case RTL_GIGA_MAC_VER_36: |
|
3720 ops->down = r8168_pll_power_down; |
|
3721 ops->up = r8168_pll_power_up; |
|
3722 break; |
|
3723 |
|
3724 default: |
|
3725 ops->down = NULL; |
|
3726 ops->up = NULL; |
|
3727 break; |
|
3728 } |
|
3729 } |
|
3730 |
|
3731 static void rtl_init_rxcfg(struct rtl8169_private *tp) |
|
3732 { |
|
3733 void __iomem *ioaddr = tp->mmio_addr; |
|
3734 |
|
3735 switch (tp->mac_version) { |
|
3736 case RTL_GIGA_MAC_VER_01: |
|
3737 case RTL_GIGA_MAC_VER_02: |
|
3738 case RTL_GIGA_MAC_VER_03: |
|
3739 case RTL_GIGA_MAC_VER_04: |
|
3740 case RTL_GIGA_MAC_VER_05: |
|
3741 case RTL_GIGA_MAC_VER_06: |
|
3742 case RTL_GIGA_MAC_VER_10: |
|
3743 case RTL_GIGA_MAC_VER_11: |
|
3744 case RTL_GIGA_MAC_VER_12: |
|
3745 case RTL_GIGA_MAC_VER_13: |
|
3746 case RTL_GIGA_MAC_VER_14: |
|
3747 case RTL_GIGA_MAC_VER_15: |
|
3748 case RTL_GIGA_MAC_VER_16: |
|
3749 case RTL_GIGA_MAC_VER_17: |
|
3750 RTL_W32(RxConfig, RX_FIFO_THRESH | RX_DMA_BURST); |
|
3751 break; |
|
3752 case RTL_GIGA_MAC_VER_18: |
|
3753 case RTL_GIGA_MAC_VER_19: |
|
3754 case RTL_GIGA_MAC_VER_20: |
|
3755 case RTL_GIGA_MAC_VER_21: |
|
3756 case RTL_GIGA_MAC_VER_22: |
|
3757 case RTL_GIGA_MAC_VER_23: |
|
3758 case RTL_GIGA_MAC_VER_24: |
|
3759 case RTL_GIGA_MAC_VER_34: |
|
3760 RTL_W32(RxConfig, RX128_INT_EN | RX_MULTI_EN | RX_DMA_BURST); |
|
3761 break; |
|
3762 default: |
|
3763 RTL_W32(RxConfig, RX128_INT_EN | RX_DMA_BURST); |
|
3764 break; |
|
3765 } |
|
3766 } |
|
3767 |
|
3768 static void rtl8169_init_ring_indexes(struct rtl8169_private *tp) |
|
3769 { |
|
3770 tp->dirty_tx = tp->dirty_rx = tp->cur_tx = tp->cur_rx = 0; |
|
3771 } |
|
3772 |
|
3773 static void rtl_hw_jumbo_enable(struct rtl8169_private *tp) |
|
3774 { |
|
3775 void __iomem *ioaddr = tp->mmio_addr; |
|
3776 |
|
3777 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
3778 rtl_generic_op(tp, tp->jumbo_ops.enable); |
|
3779 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
3780 } |
|
3781 |
|
3782 static void rtl_hw_jumbo_disable(struct rtl8169_private *tp) |
|
3783 { |
|
3784 void __iomem *ioaddr = tp->mmio_addr; |
|
3785 |
|
3786 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
3787 rtl_generic_op(tp, tp->jumbo_ops.disable); |
|
3788 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
3789 } |
|
3790 |
|
3791 static void r8168c_hw_jumbo_enable(struct rtl8169_private *tp) |
|
3792 { |
|
3793 void __iomem *ioaddr = tp->mmio_addr; |
|
3794 |
|
3795 RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0); |
|
3796 RTL_W8(Config4, RTL_R8(Config4) | Jumbo_En1); |
|
3797 rtl_tx_performance_tweak(tp->pci_dev, 0x2 << MAX_READ_REQUEST_SHIFT); |
|
3798 } |
|
3799 |
|
3800 static void r8168c_hw_jumbo_disable(struct rtl8169_private *tp) |
|
3801 { |
|
3802 void __iomem *ioaddr = tp->mmio_addr; |
|
3803 |
|
3804 RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0); |
|
3805 RTL_W8(Config4, RTL_R8(Config4) & ~Jumbo_En1); |
|
3806 rtl_tx_performance_tweak(tp->pci_dev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
3807 } |
|
3808 |
|
3809 static void r8168dp_hw_jumbo_enable(struct rtl8169_private *tp) |
|
3810 { |
|
3811 void __iomem *ioaddr = tp->mmio_addr; |
|
3812 |
|
3813 RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0); |
|
3814 } |
|
3815 |
|
3816 static void r8168dp_hw_jumbo_disable(struct rtl8169_private *tp) |
|
3817 { |
|
3818 void __iomem *ioaddr = tp->mmio_addr; |
|
3819 |
|
3820 RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0); |
|
3821 } |
|
3822 |
|
3823 static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp) |
|
3824 { |
|
3825 void __iomem *ioaddr = tp->mmio_addr; |
|
3826 |
|
3827 RTL_W8(MaxTxPacketSize, 0x3f); |
|
3828 RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0); |
|
3829 RTL_W8(Config4, RTL_R8(Config4) | 0x01); |
|
3830 rtl_tx_performance_tweak(tp->pci_dev, 0x2 << MAX_READ_REQUEST_SHIFT); |
|
3831 } |
|
3832 |
|
3833 static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp) |
|
3834 { |
|
3835 void __iomem *ioaddr = tp->mmio_addr; |
|
3836 |
|
3837 RTL_W8(MaxTxPacketSize, 0x0c); |
|
3838 RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0); |
|
3839 RTL_W8(Config4, RTL_R8(Config4) & ~0x01); |
|
3840 rtl_tx_performance_tweak(tp->pci_dev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
3841 } |
|
3842 |
|
3843 static void r8168b_0_hw_jumbo_enable(struct rtl8169_private *tp) |
|
3844 { |
|
3845 rtl_tx_performance_tweak(tp->pci_dev, |
|
3846 (0x2 << MAX_READ_REQUEST_SHIFT) | PCI_EXP_DEVCTL_NOSNOOP_EN); |
|
3847 } |
|
3848 |
|
3849 static void r8168b_0_hw_jumbo_disable(struct rtl8169_private *tp) |
|
3850 { |
|
3851 rtl_tx_performance_tweak(tp->pci_dev, |
|
3852 (0x5 << MAX_READ_REQUEST_SHIFT) | PCI_EXP_DEVCTL_NOSNOOP_EN); |
|
3853 } |
|
3854 |
|
3855 static void r8168b_1_hw_jumbo_enable(struct rtl8169_private *tp) |
|
3856 { |
|
3857 void __iomem *ioaddr = tp->mmio_addr; |
|
3858 |
|
3859 r8168b_0_hw_jumbo_enable(tp); |
|
3860 |
|
3861 RTL_W8(Config4, RTL_R8(Config4) | (1 << 0)); |
|
3862 } |
|
3863 |
|
3864 static void r8168b_1_hw_jumbo_disable(struct rtl8169_private *tp) |
|
3865 { |
|
3866 void __iomem *ioaddr = tp->mmio_addr; |
|
3867 |
|
3868 r8168b_0_hw_jumbo_disable(tp); |
|
3869 |
|
3870 RTL_W8(Config4, RTL_R8(Config4) & ~(1 << 0)); |
|
3871 } |
|
3872 |
|
3873 static void __devinit rtl_init_jumbo_ops(struct rtl8169_private *tp) |
|
3874 { |
|
3875 struct jumbo_ops *ops = &tp->jumbo_ops; |
|
3876 |
|
3877 switch (tp->mac_version) { |
|
3878 case RTL_GIGA_MAC_VER_11: |
|
3879 ops->disable = r8168b_0_hw_jumbo_disable; |
|
3880 ops->enable = r8168b_0_hw_jumbo_enable; |
|
3881 break; |
|
3882 case RTL_GIGA_MAC_VER_12: |
|
3883 case RTL_GIGA_MAC_VER_17: |
|
3884 ops->disable = r8168b_1_hw_jumbo_disable; |
|
3885 ops->enable = r8168b_1_hw_jumbo_enable; |
|
3886 break; |
|
3887 case RTL_GIGA_MAC_VER_18: /* Wild guess. Needs info from Realtek. */ |
|
3888 case RTL_GIGA_MAC_VER_19: |
|
3889 case RTL_GIGA_MAC_VER_20: |
|
3890 case RTL_GIGA_MAC_VER_21: /* Wild guess. Needs info from Realtek. */ |
|
3891 case RTL_GIGA_MAC_VER_22: |
|
3892 case RTL_GIGA_MAC_VER_23: |
|
3893 case RTL_GIGA_MAC_VER_24: |
|
3894 case RTL_GIGA_MAC_VER_25: |
|
3895 case RTL_GIGA_MAC_VER_26: |
|
3896 ops->disable = r8168c_hw_jumbo_disable; |
|
3897 ops->enable = r8168c_hw_jumbo_enable; |
|
3898 break; |
|
3899 case RTL_GIGA_MAC_VER_27: |
|
3900 case RTL_GIGA_MAC_VER_28: |
|
3901 ops->disable = r8168dp_hw_jumbo_disable; |
|
3902 ops->enable = r8168dp_hw_jumbo_enable; |
|
3903 break; |
|
3904 case RTL_GIGA_MAC_VER_31: /* Wild guess. Needs info from Realtek. */ |
|
3905 case RTL_GIGA_MAC_VER_32: |
|
3906 case RTL_GIGA_MAC_VER_33: |
|
3907 case RTL_GIGA_MAC_VER_34: |
|
3908 ops->disable = r8168e_hw_jumbo_disable; |
|
3909 ops->enable = r8168e_hw_jumbo_enable; |
|
3910 break; |
|
3911 |
|
3912 /* |
|
3913 * No action needed for jumbo frames with 8169. |
|
3914 * No jumbo for 810x at all. |
|
3915 */ |
|
3916 default: |
|
3917 ops->disable = NULL; |
|
3918 ops->enable = NULL; |
|
3919 break; |
|
3920 } |
|
3921 } |
|
3922 |
|
3923 static void rtl_hw_reset(struct rtl8169_private *tp) |
|
3924 { |
|
3925 void __iomem *ioaddr = tp->mmio_addr; |
|
3926 int i; |
|
3927 |
|
3928 /* Soft reset the chip. */ |
|
3929 RTL_W8(ChipCmd, CmdReset); |
|
3930 |
|
3931 /* Check that the chip has finished the reset. */ |
|
3932 for (i = 0; i < 100; i++) { |
|
3933 if ((RTL_R8(ChipCmd) & CmdReset) == 0) |
|
3934 break; |
|
3935 udelay(100); |
|
3936 } |
|
3937 } |
|
3938 |
|
3939 static void rtl_request_uncached_firmware(struct rtl8169_private *tp) |
|
3940 { |
|
3941 struct rtl_fw *rtl_fw; |
|
3942 const char *name; |
|
3943 int rc = -ENOMEM; |
|
3944 |
|
3945 name = rtl_lookup_firmware_name(tp); |
|
3946 if (!name) |
|
3947 goto out_no_firmware; |
|
3948 |
|
3949 rtl_fw = kzalloc(sizeof(*rtl_fw), GFP_KERNEL); |
|
3950 if (!rtl_fw) |
|
3951 goto err_warn; |
|
3952 |
|
3953 rc = request_firmware(&rtl_fw->fw, name, &tp->pci_dev->dev); |
|
3954 if (rc < 0) |
|
3955 goto err_free; |
|
3956 |
|
3957 rc = rtl_check_firmware(tp, rtl_fw); |
|
3958 if (rc < 0) |
|
3959 goto err_release_firmware; |
|
3960 |
|
3961 tp->rtl_fw = rtl_fw; |
|
3962 out: |
|
3963 return; |
|
3964 |
|
3965 err_release_firmware: |
|
3966 release_firmware(rtl_fw->fw); |
|
3967 err_free: |
|
3968 kfree(rtl_fw); |
|
3969 err_warn: |
|
3970 netif_warn(tp, ifup, tp->dev, "unable to load firmware patch %s (%d)\n", |
|
3971 name, rc); |
|
3972 out_no_firmware: |
|
3973 tp->rtl_fw = NULL; |
|
3974 goto out; |
|
3975 } |
|
3976 |
|
3977 static void rtl_request_firmware(struct rtl8169_private *tp) |
|
3978 { |
|
3979 if (IS_ERR(tp->rtl_fw)) |
|
3980 rtl_request_uncached_firmware(tp); |
|
3981 } |
|
3982 |
|
3983 static void rtl_rx_close(struct rtl8169_private *tp) |
|
3984 { |
|
3985 void __iomem *ioaddr = tp->mmio_addr; |
|
3986 |
|
3987 RTL_W32(RxConfig, RTL_R32(RxConfig) & ~RX_CONFIG_ACCEPT_MASK); |
|
3988 } |
|
3989 |
|
3990 static void rtl8169_hw_reset(struct rtl8169_private *tp) |
|
3991 { |
|
3992 void __iomem *ioaddr = tp->mmio_addr; |
|
3993 |
|
3994 /* Disable interrupts */ |
|
3995 rtl8169_irq_mask_and_ack(tp); |
|
3996 |
|
3997 rtl_rx_close(tp); |
|
3998 |
|
3999 if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
|
4000 tp->mac_version == RTL_GIGA_MAC_VER_28 || |
|
4001 tp->mac_version == RTL_GIGA_MAC_VER_31) { |
|
4002 while (RTL_R8(TxPoll) & NPQ) |
|
4003 udelay(20); |
|
4004 } else if (tp->mac_version == RTL_GIGA_MAC_VER_34 || |
|
4005 tp->mac_version == RTL_GIGA_MAC_VER_35 || |
|
4006 tp->mac_version == RTL_GIGA_MAC_VER_36) { |
|
4007 RTL_W8(ChipCmd, RTL_R8(ChipCmd) | StopReq); |
|
4008 while (!(RTL_R32(TxConfig) & TXCFG_EMPTY)) |
|
4009 udelay(100); |
|
4010 } else { |
|
4011 RTL_W8(ChipCmd, RTL_R8(ChipCmd) | StopReq); |
|
4012 udelay(100); |
|
4013 } |
|
4014 |
|
4015 rtl_hw_reset(tp); |
|
4016 } |
|
4017 |
|
4018 static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp) |
|
4019 { |
|
4020 void __iomem *ioaddr = tp->mmio_addr; |
|
4021 |
|
4022 /* Set DMA burst size and Interframe Gap Time */ |
|
4023 RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) | |
|
4024 (InterFrameGap << TxInterFrameGapShift)); |
|
4025 } |
|
4026 |
|
4027 static void rtl_hw_start(struct net_device *dev) |
|
4028 { |
|
4029 struct rtl8169_private *tp = netdev_priv(dev); |
|
4030 |
|
4031 tp->hw_start(dev); |
|
4032 |
|
4033 rtl_irq_enable_all(tp); |
|
4034 } |
|
4035 |
|
4036 static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp, |
|
4037 void __iomem *ioaddr) |
|
4038 { |
|
4039 /* |
|
4040 * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh |
|
4041 * register to be written before TxDescAddrLow to work. |
|
4042 * Switching from MMIO to I/O access fixes the issue as well. |
|
4043 */ |
|
4044 RTL_W32(TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); |
|
4045 RTL_W32(TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); |
|
4046 RTL_W32(RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); |
|
4047 RTL_W32(RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); |
|
4048 } |
|
4049 |
|
4050 static u16 rtl_rw_cpluscmd(void __iomem *ioaddr) |
|
4051 { |
|
4052 u16 cmd; |
|
4053 |
|
4054 cmd = RTL_R16(CPlusCmd); |
|
4055 RTL_W16(CPlusCmd, cmd); |
|
4056 return cmd; |
|
4057 } |
|
4058 |
|
4059 static void rtl_set_rx_max_size(void __iomem *ioaddr, unsigned int rx_buf_sz) |
|
4060 { |
|
4061 /* Low hurts. Let's disable the filtering. */ |
|
4062 RTL_W16(RxMaxSize, rx_buf_sz + 1); |
|
4063 } |
|
4064 |
|
4065 static void rtl8169_set_magic_reg(void __iomem *ioaddr, unsigned mac_version) |
|
4066 { |
|
4067 static const struct rtl_cfg2_info { |
|
4068 u32 mac_version; |
|
4069 u32 clk; |
|
4070 u32 val; |
|
4071 } cfg2_info [] = { |
|
4072 { RTL_GIGA_MAC_VER_05, PCI_Clock_33MHz, 0x000fff00 }, // 8110SCd |
|
4073 { RTL_GIGA_MAC_VER_05, PCI_Clock_66MHz, 0x000fffff }, |
|
4074 { RTL_GIGA_MAC_VER_06, PCI_Clock_33MHz, 0x00ffff00 }, // 8110SCe |
|
4075 { RTL_GIGA_MAC_VER_06, PCI_Clock_66MHz, 0x00ffffff } |
|
4076 }; |
|
4077 const struct rtl_cfg2_info *p = cfg2_info; |
|
4078 unsigned int i; |
|
4079 u32 clk; |
|
4080 |
|
4081 clk = RTL_R8(Config2) & PCI_Clock_66MHz; |
|
4082 for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) { |
|
4083 if ((p->mac_version == mac_version) && (p->clk == clk)) { |
|
4084 RTL_W32(0x7c, p->val); |
|
4085 break; |
|
4086 } |
|
4087 } |
|
4088 } |
|
4089 |
|
4090 static void rtl_set_rx_mode(struct net_device *dev) |
|
4091 { |
|
4092 struct rtl8169_private *tp = netdev_priv(dev); |
|
4093 void __iomem *ioaddr = tp->mmio_addr; |
|
4094 u32 mc_filter[2]; /* Multicast hash filter */ |
|
4095 int rx_mode; |
|
4096 u32 tmp = 0; |
|
4097 |
|
4098 if (dev->flags & IFF_PROMISC) { |
|
4099 /* Unconditionally log net taps. */ |
|
4100 netif_notice(tp, link, dev, "Promiscuous mode enabled\n"); |
|
4101 rx_mode = |
|
4102 AcceptBroadcast | AcceptMulticast | AcceptMyPhys | |
|
4103 AcceptAllPhys; |
|
4104 mc_filter[1] = mc_filter[0] = 0xffffffff; |
|
4105 } else if ((netdev_mc_count(dev) > multicast_filter_limit) || |
|
4106 (dev->flags & IFF_ALLMULTI)) { |
|
4107 /* Too many to filter perfectly -- accept all multicasts. */ |
|
4108 rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; |
|
4109 mc_filter[1] = mc_filter[0] = 0xffffffff; |
|
4110 } else { |
|
4111 struct netdev_hw_addr *ha; |
|
4112 |
|
4113 rx_mode = AcceptBroadcast | AcceptMyPhys; |
|
4114 mc_filter[1] = mc_filter[0] = 0; |
|
4115 netdev_for_each_mc_addr(ha, dev) { |
|
4116 int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; |
|
4117 mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); |
|
4118 rx_mode |= AcceptMulticast; |
|
4119 } |
|
4120 } |
|
4121 |
|
4122 if (dev->features & NETIF_F_RXALL) |
|
4123 rx_mode |= (AcceptErr | AcceptRunt); |
|
4124 |
|
4125 tmp = (RTL_R32(RxConfig) & ~RX_CONFIG_ACCEPT_MASK) | rx_mode; |
|
4126 |
|
4127 if (tp->mac_version > RTL_GIGA_MAC_VER_06) { |
|
4128 u32 data = mc_filter[0]; |
|
4129 |
|
4130 mc_filter[0] = swab32(mc_filter[1]); |
|
4131 mc_filter[1] = swab32(data); |
|
4132 } |
|
4133 |
|
4134 if (tp->mac_version == RTL_GIGA_MAC_VER_35) |
|
4135 mc_filter[1] = mc_filter[0] = 0xffffffff; |
|
4136 |
|
4137 RTL_W32(MAR0 + 4, mc_filter[1]); |
|
4138 RTL_W32(MAR0 + 0, mc_filter[0]); |
|
4139 |
|
4140 RTL_W32(RxConfig, tmp); |
|
4141 } |
|
4142 |
|
4143 static void rtl_hw_start_8169(struct net_device *dev) |
|
4144 { |
|
4145 struct rtl8169_private *tp = netdev_priv(dev); |
|
4146 void __iomem *ioaddr = tp->mmio_addr; |
|
4147 struct pci_dev *pdev = tp->pci_dev; |
|
4148 |
|
4149 if (tp->mac_version == RTL_GIGA_MAC_VER_05) { |
|
4150 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) | PCIMulRW); |
|
4151 pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, 0x08); |
|
4152 } |
|
4153 |
|
4154 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
4155 if (tp->mac_version == RTL_GIGA_MAC_VER_01 || |
|
4156 tp->mac_version == RTL_GIGA_MAC_VER_02 || |
|
4157 tp->mac_version == RTL_GIGA_MAC_VER_03 || |
|
4158 tp->mac_version == RTL_GIGA_MAC_VER_04) |
|
4159 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
|
4160 |
|
4161 rtl_init_rxcfg(tp); |
|
4162 |
|
4163 RTL_W8(EarlyTxThres, NoEarlyTx); |
|
4164 |
|
4165 rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
|
4166 |
|
4167 if (tp->mac_version == RTL_GIGA_MAC_VER_01 || |
|
4168 tp->mac_version == RTL_GIGA_MAC_VER_02 || |
|
4169 tp->mac_version == RTL_GIGA_MAC_VER_03 || |
|
4170 tp->mac_version == RTL_GIGA_MAC_VER_04) |
|
4171 rtl_set_rx_tx_config_registers(tp); |
|
4172 |
|
4173 tp->cp_cmd |= rtl_rw_cpluscmd(ioaddr) | PCIMulRW; |
|
4174 |
|
4175 if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
|
4176 tp->mac_version == RTL_GIGA_MAC_VER_03) { |
|
4177 dprintk("Set MAC Reg C+CR Offset 0xE0. " |
|
4178 "Bit-3 and bit-14 MUST be 1\n"); |
|
4179 tp->cp_cmd |= (1 << 14); |
|
4180 } |
|
4181 |
|
4182 RTL_W16(CPlusCmd, tp->cp_cmd); |
|
4183 |
|
4184 rtl8169_set_magic_reg(ioaddr, tp->mac_version); |
|
4185 |
|
4186 /* |
|
4187 * Undocumented corner. Supposedly: |
|
4188 * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets |
|
4189 */ |
|
4190 RTL_W16(IntrMitigate, 0x0000); |
|
4191 |
|
4192 rtl_set_rx_tx_desc_registers(tp, ioaddr); |
|
4193 |
|
4194 if (tp->mac_version != RTL_GIGA_MAC_VER_01 && |
|
4195 tp->mac_version != RTL_GIGA_MAC_VER_02 && |
|
4196 tp->mac_version != RTL_GIGA_MAC_VER_03 && |
|
4197 tp->mac_version != RTL_GIGA_MAC_VER_04) { |
|
4198 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
|
4199 rtl_set_rx_tx_config_registers(tp); |
|
4200 } |
|
4201 |
|
4202 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
4203 |
|
4204 /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ |
|
4205 RTL_R8(IntrMask); |
|
4206 |
|
4207 RTL_W32(RxMissed, 0); |
|
4208 |
|
4209 rtl_set_rx_mode(dev); |
|
4210 |
|
4211 /* no early-rx interrupts */ |
|
4212 RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000); |
|
4213 } |
|
4214 |
|
4215 static void rtl_csi_access_enable(void __iomem *ioaddr, u32 bits) |
|
4216 { |
|
4217 u32 csi; |
|
4218 |
|
4219 csi = rtl_csi_read(ioaddr, 0x070c) & 0x00ffffff; |
|
4220 rtl_csi_write(ioaddr, 0x070c, csi | bits); |
|
4221 } |
|
4222 |
|
4223 static void rtl_csi_access_enable_1(void __iomem *ioaddr) |
|
4224 { |
|
4225 rtl_csi_access_enable(ioaddr, 0x17000000); |
|
4226 } |
|
4227 |
|
4228 static void rtl_csi_access_enable_2(void __iomem *ioaddr) |
|
4229 { |
|
4230 rtl_csi_access_enable(ioaddr, 0x27000000); |
|
4231 } |
|
4232 |
|
4233 struct ephy_info { |
|
4234 unsigned int offset; |
|
4235 u16 mask; |
|
4236 u16 bits; |
|
4237 }; |
|
4238 |
|
4239 static void rtl_ephy_init(void __iomem *ioaddr, const struct ephy_info *e, int len) |
|
4240 { |
|
4241 u16 w; |
|
4242 |
|
4243 while (len-- > 0) { |
|
4244 w = (rtl_ephy_read(ioaddr, e->offset) & ~e->mask) | e->bits; |
|
4245 rtl_ephy_write(ioaddr, e->offset, w); |
|
4246 e++; |
|
4247 } |
|
4248 } |
|
4249 |
|
4250 static void rtl_disable_clock_request(struct pci_dev *pdev) |
|
4251 { |
|
4252 int cap = pci_pcie_cap(pdev); |
|
4253 |
|
4254 if (cap) { |
|
4255 u16 ctl; |
|
4256 |
|
4257 pci_read_config_word(pdev, cap + PCI_EXP_LNKCTL, &ctl); |
|
4258 ctl &= ~PCI_EXP_LNKCTL_CLKREQ_EN; |
|
4259 pci_write_config_word(pdev, cap + PCI_EXP_LNKCTL, ctl); |
|
4260 } |
|
4261 } |
|
4262 |
|
4263 static void rtl_enable_clock_request(struct pci_dev *pdev) |
|
4264 { |
|
4265 int cap = pci_pcie_cap(pdev); |
|
4266 |
|
4267 if (cap) { |
|
4268 u16 ctl; |
|
4269 |
|
4270 pci_read_config_word(pdev, cap + PCI_EXP_LNKCTL, &ctl); |
|
4271 ctl |= PCI_EXP_LNKCTL_CLKREQ_EN; |
|
4272 pci_write_config_word(pdev, cap + PCI_EXP_LNKCTL, ctl); |
|
4273 } |
|
4274 } |
|
4275 |
|
4276 #define R8168_CPCMD_QUIRK_MASK (\ |
|
4277 EnableBist | \ |
|
4278 Mac_dbgo_oe | \ |
|
4279 Force_half_dup | \ |
|
4280 Force_rxflow_en | \ |
|
4281 Force_txflow_en | \ |
|
4282 Cxpl_dbg_sel | \ |
|
4283 ASF | \ |
|
4284 PktCntrDisable | \ |
|
4285 Mac_dbgo_sel) |
|
4286 |
|
4287 static void rtl_hw_start_8168bb(void __iomem *ioaddr, struct pci_dev *pdev) |
|
4288 { |
|
4289 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
4290 |
|
4291 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
|
4292 |
|
4293 rtl_tx_performance_tweak(pdev, |
|
4294 (0x5 << MAX_READ_REQUEST_SHIFT) | PCI_EXP_DEVCTL_NOSNOOP_EN); |
|
4295 } |
|
4296 |
|
4297 static void rtl_hw_start_8168bef(void __iomem *ioaddr, struct pci_dev *pdev) |
|
4298 { |
|
4299 rtl_hw_start_8168bb(ioaddr, pdev); |
|
4300 |
|
4301 RTL_W8(MaxTxPacketSize, TxPacketMax); |
|
4302 |
|
4303 RTL_W8(Config4, RTL_R8(Config4) & ~(1 << 0)); |
|
4304 } |
|
4305 |
|
4306 static void __rtl_hw_start_8168cp(void __iomem *ioaddr, struct pci_dev *pdev) |
|
4307 { |
|
4308 RTL_W8(Config1, RTL_R8(Config1) | Speed_down); |
|
4309 |
|
4310 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
4311 |
|
4312 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
4313 |
|
4314 rtl_disable_clock_request(pdev); |
|
4315 |
|
4316 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
|
4317 } |
|
4318 |
|
4319 static void rtl_hw_start_8168cp_1(void __iomem *ioaddr, struct pci_dev *pdev) |
|
4320 { |
|
4321 static const struct ephy_info e_info_8168cp[] = { |
|
4322 { 0x01, 0, 0x0001 }, |
|
4323 { 0x02, 0x0800, 0x1000 }, |
|
4324 { 0x03, 0, 0x0042 }, |
|
4325 { 0x06, 0x0080, 0x0000 }, |
|
4326 { 0x07, 0, 0x2000 } |
|
4327 }; |
|
4328 |
|
4329 rtl_csi_access_enable_2(ioaddr); |
|
4330 |
|
4331 rtl_ephy_init(ioaddr, e_info_8168cp, ARRAY_SIZE(e_info_8168cp)); |
|
4332 |
|
4333 __rtl_hw_start_8168cp(ioaddr, pdev); |
|
4334 } |
|
4335 |
|
4336 static void rtl_hw_start_8168cp_2(void __iomem *ioaddr, struct pci_dev *pdev) |
|
4337 { |
|
4338 rtl_csi_access_enable_2(ioaddr); |
|
4339 |
|
4340 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
4341 |
|
4342 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
4343 |
|
4344 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
|
4345 } |
|
4346 |
|
4347 static void rtl_hw_start_8168cp_3(void __iomem *ioaddr, struct pci_dev *pdev) |
|
4348 { |
|
4349 rtl_csi_access_enable_2(ioaddr); |
|
4350 |
|
4351 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
4352 |
|
4353 /* Magic. */ |
|
4354 RTL_W8(DBG_REG, 0x20); |
|
4355 |
|
4356 RTL_W8(MaxTxPacketSize, TxPacketMax); |
|
4357 |
|
4358 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
4359 |
|
4360 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
|
4361 } |
|
4362 |
|
4363 static void rtl_hw_start_8168c_1(void __iomem *ioaddr, struct pci_dev *pdev) |
|
4364 { |
|
4365 static const struct ephy_info e_info_8168c_1[] = { |
|
4366 { 0x02, 0x0800, 0x1000 }, |
|
4367 { 0x03, 0, 0x0002 }, |
|
4368 { 0x06, 0x0080, 0x0000 } |
|
4369 }; |
|
4370 |
|
4371 rtl_csi_access_enable_2(ioaddr); |
|
4372 |
|
4373 RTL_W8(DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2); |
|
4374 |
|
4375 rtl_ephy_init(ioaddr, e_info_8168c_1, ARRAY_SIZE(e_info_8168c_1)); |
|
4376 |
|
4377 __rtl_hw_start_8168cp(ioaddr, pdev); |
|
4378 } |
|
4379 |
|
4380 static void rtl_hw_start_8168c_2(void __iomem *ioaddr, struct pci_dev *pdev) |
|
4381 { |
|
4382 static const struct ephy_info e_info_8168c_2[] = { |
|
4383 { 0x01, 0, 0x0001 }, |
|
4384 { 0x03, 0x0400, 0x0220 } |
|
4385 }; |
|
4386 |
|
4387 rtl_csi_access_enable_2(ioaddr); |
|
4388 |
|
4389 rtl_ephy_init(ioaddr, e_info_8168c_2, ARRAY_SIZE(e_info_8168c_2)); |
|
4390 |
|
4391 __rtl_hw_start_8168cp(ioaddr, pdev); |
|
4392 } |
|
4393 |
|
4394 static void rtl_hw_start_8168c_3(void __iomem *ioaddr, struct pci_dev *pdev) |
|
4395 { |
|
4396 rtl_hw_start_8168c_2(ioaddr, pdev); |
|
4397 } |
|
4398 |
|
4399 static void rtl_hw_start_8168c_4(void __iomem *ioaddr, struct pci_dev *pdev) |
|
4400 { |
|
4401 rtl_csi_access_enable_2(ioaddr); |
|
4402 |
|
4403 __rtl_hw_start_8168cp(ioaddr, pdev); |
|
4404 } |
|
4405 |
|
4406 static void rtl_hw_start_8168d(void __iomem *ioaddr, struct pci_dev *pdev) |
|
4407 { |
|
4408 rtl_csi_access_enable_2(ioaddr); |
|
4409 |
|
4410 rtl_disable_clock_request(pdev); |
|
4411 |
|
4412 RTL_W8(MaxTxPacketSize, TxPacketMax); |
|
4413 |
|
4414 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
4415 |
|
4416 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
|
4417 } |
|
4418 |
|
4419 static void rtl_hw_start_8168dp(void __iomem *ioaddr, struct pci_dev *pdev) |
|
4420 { |
|
4421 rtl_csi_access_enable_1(ioaddr); |
|
4422 |
|
4423 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
4424 |
|
4425 RTL_W8(MaxTxPacketSize, TxPacketMax); |
|
4426 |
|
4427 rtl_disable_clock_request(pdev); |
|
4428 } |
|
4429 |
|
4430 static void rtl_hw_start_8168d_4(void __iomem *ioaddr, struct pci_dev *pdev) |
|
4431 { |
|
4432 static const struct ephy_info e_info_8168d_4[] = { |
|
4433 { 0x0b, ~0, 0x48 }, |
|
4434 { 0x19, 0x20, 0x50 }, |
|
4435 { 0x0c, ~0, 0x20 } |
|
4436 }; |
|
4437 int i; |
|
4438 |
|
4439 rtl_csi_access_enable_1(ioaddr); |
|
4440 |
|
4441 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
4442 |
|
4443 RTL_W8(MaxTxPacketSize, TxPacketMax); |
|
4444 |
|
4445 for (i = 0; i < ARRAY_SIZE(e_info_8168d_4); i++) { |
|
4446 const struct ephy_info *e = e_info_8168d_4 + i; |
|
4447 u16 w; |
|
4448 |
|
4449 w = rtl_ephy_read(ioaddr, e->offset); |
|
4450 rtl_ephy_write(ioaddr, 0x03, (w & e->mask) | e->bits); |
|
4451 } |
|
4452 |
|
4453 rtl_enable_clock_request(pdev); |
|
4454 } |
|
4455 |
|
4456 static void rtl_hw_start_8168e_1(void __iomem *ioaddr, struct pci_dev *pdev) |
|
4457 { |
|
4458 static const struct ephy_info e_info_8168e_1[] = { |
|
4459 { 0x00, 0x0200, 0x0100 }, |
|
4460 { 0x00, 0x0000, 0x0004 }, |
|
4461 { 0x06, 0x0002, 0x0001 }, |
|
4462 { 0x06, 0x0000, 0x0030 }, |
|
4463 { 0x07, 0x0000, 0x2000 }, |
|
4464 { 0x00, 0x0000, 0x0020 }, |
|
4465 { 0x03, 0x5800, 0x2000 }, |
|
4466 { 0x03, 0x0000, 0x0001 }, |
|
4467 { 0x01, 0x0800, 0x1000 }, |
|
4468 { 0x07, 0x0000, 0x4000 }, |
|
4469 { 0x1e, 0x0000, 0x2000 }, |
|
4470 { 0x19, 0xffff, 0xfe6c }, |
|
4471 { 0x0a, 0x0000, 0x0040 } |
|
4472 }; |
|
4473 |
|
4474 rtl_csi_access_enable_2(ioaddr); |
|
4475 |
|
4476 rtl_ephy_init(ioaddr, e_info_8168e_1, ARRAY_SIZE(e_info_8168e_1)); |
|
4477 |
|
4478 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
4479 |
|
4480 RTL_W8(MaxTxPacketSize, TxPacketMax); |
|
4481 |
|
4482 rtl_disable_clock_request(pdev); |
|
4483 |
|
4484 /* Reset tx FIFO pointer */ |
|
4485 RTL_W32(MISC, RTL_R32(MISC) | TXPLA_RST); |
|
4486 RTL_W32(MISC, RTL_R32(MISC) & ~TXPLA_RST); |
|
4487 |
|
4488 RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en); |
|
4489 } |
|
4490 |
|
4491 static void rtl_hw_start_8168e_2(void __iomem *ioaddr, struct pci_dev *pdev) |
|
4492 { |
|
4493 static const struct ephy_info e_info_8168e_2[] = { |
|
4494 { 0x09, 0x0000, 0x0080 }, |
|
4495 { 0x19, 0x0000, 0x0224 } |
|
4496 }; |
|
4497 |
|
4498 rtl_csi_access_enable_1(ioaddr); |
|
4499 |
|
4500 rtl_ephy_init(ioaddr, e_info_8168e_2, ARRAY_SIZE(e_info_8168e_2)); |
|
4501 |
|
4502 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
4503 |
|
4504 rtl_eri_write(ioaddr, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
|
4505 rtl_eri_write(ioaddr, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
|
4506 rtl_eri_write(ioaddr, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
|
4507 rtl_eri_write(ioaddr, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
|
4508 rtl_eri_write(ioaddr, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
|
4509 rtl_eri_write(ioaddr, 0xd0, ERIAR_MASK_1111, 0x07ff0060, ERIAR_EXGMAC); |
|
4510 rtl_w1w0_eri(ioaddr, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
|
4511 rtl_w1w0_eri(ioaddr, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, |
|
4512 ERIAR_EXGMAC); |
|
4513 |
|
4514 RTL_W8(MaxTxPacketSize, EarlySize); |
|
4515 |
|
4516 rtl_disable_clock_request(pdev); |
|
4517 |
|
4518 RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
|
4519 RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB); |
|
4520 |
|
4521 /* Adjust EEE LED frequency */ |
|
4522 RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07); |
|
4523 |
|
4524 RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN); |
|
4525 RTL_W32(MISC, RTL_R32(MISC) | PWM_EN); |
|
4526 RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en); |
|
4527 } |
|
4528 |
|
4529 static void rtl_hw_start_8168f_1(void __iomem *ioaddr, struct pci_dev *pdev) |
|
4530 { |
|
4531 static const struct ephy_info e_info_8168f_1[] = { |
|
4532 { 0x06, 0x00c0, 0x0020 }, |
|
4533 { 0x08, 0x0001, 0x0002 }, |
|
4534 { 0x09, 0x0000, 0x0080 }, |
|
4535 { 0x19, 0x0000, 0x0224 } |
|
4536 }; |
|
4537 |
|
4538 rtl_csi_access_enable_1(ioaddr); |
|
4539 |
|
4540 rtl_ephy_init(ioaddr, e_info_8168f_1, ARRAY_SIZE(e_info_8168f_1)); |
|
4541 |
|
4542 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
4543 |
|
4544 rtl_eri_write(ioaddr, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
|
4545 rtl_eri_write(ioaddr, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
|
4546 rtl_eri_write(ioaddr, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
|
4547 rtl_eri_write(ioaddr, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
|
4548 rtl_w1w0_eri(ioaddr, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
|
4549 rtl_w1w0_eri(ioaddr, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
|
4550 rtl_w1w0_eri(ioaddr, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
|
4551 rtl_w1w0_eri(ioaddr, 0x1d0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
|
4552 rtl_eri_write(ioaddr, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
|
4553 rtl_eri_write(ioaddr, 0xd0, ERIAR_MASK_1111, 0x00000060, ERIAR_EXGMAC); |
|
4554 rtl_w1w0_eri(ioaddr, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, |
|
4555 ERIAR_EXGMAC); |
|
4556 |
|
4557 RTL_W8(MaxTxPacketSize, EarlySize); |
|
4558 |
|
4559 rtl_disable_clock_request(pdev); |
|
4560 |
|
4561 RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
|
4562 RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB); |
|
4563 |
|
4564 /* Adjust EEE LED frequency */ |
|
4565 RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07); |
|
4566 |
|
4567 RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN); |
|
4568 RTL_W32(MISC, RTL_R32(MISC) | PWM_EN); |
|
4569 RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en); |
|
4570 } |
|
4571 |
|
4572 static void rtl_hw_start_8168(struct net_device *dev) |
|
4573 { |
|
4574 struct rtl8169_private *tp = netdev_priv(dev); |
|
4575 void __iomem *ioaddr = tp->mmio_addr; |
|
4576 struct pci_dev *pdev = tp->pci_dev; |
|
4577 |
|
4578 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
4579 |
|
4580 RTL_W8(MaxTxPacketSize, TxPacketMax); |
|
4581 |
|
4582 rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
|
4583 |
|
4584 tp->cp_cmd |= RTL_R16(CPlusCmd) | PktCntrDisable | INTT_1; |
|
4585 |
|
4586 RTL_W16(CPlusCmd, tp->cp_cmd); |
|
4587 |
|
4588 RTL_W16(IntrMitigate, 0x5151); |
|
4589 |
|
4590 /* Work around for RxFIFO overflow. */ |
|
4591 if (tp->mac_version == RTL_GIGA_MAC_VER_11) { |
|
4592 tp->event_slow |= RxFIFOOver | PCSTimeout; |
|
4593 tp->event_slow &= ~RxOverflow; |
|
4594 } |
|
4595 |
|
4596 rtl_set_rx_tx_desc_registers(tp, ioaddr); |
|
4597 |
|
4598 rtl_set_rx_mode(dev); |
|
4599 |
|
4600 RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) | |
|
4601 (InterFrameGap << TxInterFrameGapShift)); |
|
4602 |
|
4603 RTL_R8(IntrMask); |
|
4604 |
|
4605 switch (tp->mac_version) { |
|
4606 case RTL_GIGA_MAC_VER_11: |
|
4607 rtl_hw_start_8168bb(ioaddr, pdev); |
|
4608 break; |
|
4609 |
|
4610 case RTL_GIGA_MAC_VER_12: |
|
4611 case RTL_GIGA_MAC_VER_17: |
|
4612 rtl_hw_start_8168bef(ioaddr, pdev); |
|
4613 break; |
|
4614 |
|
4615 case RTL_GIGA_MAC_VER_18: |
|
4616 rtl_hw_start_8168cp_1(ioaddr, pdev); |
|
4617 break; |
|
4618 |
|
4619 case RTL_GIGA_MAC_VER_19: |
|
4620 rtl_hw_start_8168c_1(ioaddr, pdev); |
|
4621 break; |
|
4622 |
|
4623 case RTL_GIGA_MAC_VER_20: |
|
4624 rtl_hw_start_8168c_2(ioaddr, pdev); |
|
4625 break; |
|
4626 |
|
4627 case RTL_GIGA_MAC_VER_21: |
|
4628 rtl_hw_start_8168c_3(ioaddr, pdev); |
|
4629 break; |
|
4630 |
|
4631 case RTL_GIGA_MAC_VER_22: |
|
4632 rtl_hw_start_8168c_4(ioaddr, pdev); |
|
4633 break; |
|
4634 |
|
4635 case RTL_GIGA_MAC_VER_23: |
|
4636 rtl_hw_start_8168cp_2(ioaddr, pdev); |
|
4637 break; |
|
4638 |
|
4639 case RTL_GIGA_MAC_VER_24: |
|
4640 rtl_hw_start_8168cp_3(ioaddr, pdev); |
|
4641 break; |
|
4642 |
|
4643 case RTL_GIGA_MAC_VER_25: |
|
4644 case RTL_GIGA_MAC_VER_26: |
|
4645 case RTL_GIGA_MAC_VER_27: |
|
4646 rtl_hw_start_8168d(ioaddr, pdev); |
|
4647 break; |
|
4648 |
|
4649 case RTL_GIGA_MAC_VER_28: |
|
4650 rtl_hw_start_8168d_4(ioaddr, pdev); |
|
4651 break; |
|
4652 |
|
4653 case RTL_GIGA_MAC_VER_31: |
|
4654 rtl_hw_start_8168dp(ioaddr, pdev); |
|
4655 break; |
|
4656 |
|
4657 case RTL_GIGA_MAC_VER_32: |
|
4658 case RTL_GIGA_MAC_VER_33: |
|
4659 rtl_hw_start_8168e_1(ioaddr, pdev); |
|
4660 break; |
|
4661 case RTL_GIGA_MAC_VER_34: |
|
4662 rtl_hw_start_8168e_2(ioaddr, pdev); |
|
4663 break; |
|
4664 |
|
4665 case RTL_GIGA_MAC_VER_35: |
|
4666 case RTL_GIGA_MAC_VER_36: |
|
4667 rtl_hw_start_8168f_1(ioaddr, pdev); |
|
4668 break; |
|
4669 |
|
4670 default: |
|
4671 printk(KERN_ERR PFX "%s: unknown chipset (mac_version = %d).\n", |
|
4672 dev->name, tp->mac_version); |
|
4673 break; |
|
4674 } |
|
4675 |
|
4676 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
|
4677 |
|
4678 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
4679 |
|
4680 RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000); |
|
4681 } |
|
4682 |
|
4683 #define R810X_CPCMD_QUIRK_MASK (\ |
|
4684 EnableBist | \ |
|
4685 Mac_dbgo_oe | \ |
|
4686 Force_half_dup | \ |
|
4687 Force_rxflow_en | \ |
|
4688 Force_txflow_en | \ |
|
4689 Cxpl_dbg_sel | \ |
|
4690 ASF | \ |
|
4691 PktCntrDisable | \ |
|
4692 Mac_dbgo_sel) |
|
4693 |
|
4694 static void rtl_hw_start_8102e_1(void __iomem *ioaddr, struct pci_dev *pdev) |
|
4695 { |
|
4696 static const struct ephy_info e_info_8102e_1[] = { |
|
4697 { 0x01, 0, 0x6e65 }, |
|
4698 { 0x02, 0, 0x091f }, |
|
4699 { 0x03, 0, 0xc2f9 }, |
|
4700 { 0x06, 0, 0xafb5 }, |
|
4701 { 0x07, 0, 0x0e00 }, |
|
4702 { 0x19, 0, 0xec80 }, |
|
4703 { 0x01, 0, 0x2e65 }, |
|
4704 { 0x01, 0, 0x6e65 } |
|
4705 }; |
|
4706 u8 cfg1; |
|
4707 |
|
4708 rtl_csi_access_enable_2(ioaddr); |
|
4709 |
|
4710 RTL_W8(DBG_REG, FIX_NAK_1); |
|
4711 |
|
4712 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
4713 |
|
4714 RTL_W8(Config1, |
|
4715 LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable); |
|
4716 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
4717 |
|
4718 cfg1 = RTL_R8(Config1); |
|
4719 if ((cfg1 & LEDS0) && (cfg1 & LEDS1)) |
|
4720 RTL_W8(Config1, cfg1 & ~LEDS0); |
|
4721 |
|
4722 rtl_ephy_init(ioaddr, e_info_8102e_1, ARRAY_SIZE(e_info_8102e_1)); |
|
4723 } |
|
4724 |
|
4725 static void rtl_hw_start_8102e_2(void __iomem *ioaddr, struct pci_dev *pdev) |
|
4726 { |
|
4727 rtl_csi_access_enable_2(ioaddr); |
|
4728 |
|
4729 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
4730 |
|
4731 RTL_W8(Config1, MEMMAP | IOMAP | VPD | PMEnable); |
|
4732 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
4733 } |
|
4734 |
|
4735 static void rtl_hw_start_8102e_3(void __iomem *ioaddr, struct pci_dev *pdev) |
|
4736 { |
|
4737 rtl_hw_start_8102e_2(ioaddr, pdev); |
|
4738 |
|
4739 rtl_ephy_write(ioaddr, 0x03, 0xc2f9); |
|
4740 } |
|
4741 |
|
4742 static void rtl_hw_start_8105e_1(void __iomem *ioaddr, struct pci_dev *pdev) |
|
4743 { |
|
4744 static const struct ephy_info e_info_8105e_1[] = { |
|
4745 { 0x07, 0, 0x4000 }, |
|
4746 { 0x19, 0, 0x0200 }, |
|
4747 { 0x19, 0, 0x0020 }, |
|
4748 { 0x1e, 0, 0x2000 }, |
|
4749 { 0x03, 0, 0x0001 }, |
|
4750 { 0x19, 0, 0x0100 }, |
|
4751 { 0x19, 0, 0x0004 }, |
|
4752 { 0x0a, 0, 0x0020 } |
|
4753 }; |
|
4754 |
|
4755 /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
|
4756 RTL_W32(FuncEvent, RTL_R32(FuncEvent) | 0x002800); |
|
4757 |
|
4758 /* Disable Early Tally Counter */ |
|
4759 RTL_W32(FuncEvent, RTL_R32(FuncEvent) & ~0x010000); |
|
4760 |
|
4761 RTL_W8(MCU, RTL_R8(MCU) | EN_NDP | EN_OOB_RESET); |
|
4762 RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN); |
|
4763 |
|
4764 rtl_ephy_init(ioaddr, e_info_8105e_1, ARRAY_SIZE(e_info_8105e_1)); |
|
4765 } |
|
4766 |
|
4767 static void rtl_hw_start_8105e_2(void __iomem *ioaddr, struct pci_dev *pdev) |
|
4768 { |
|
4769 rtl_hw_start_8105e_1(ioaddr, pdev); |
|
4770 rtl_ephy_write(ioaddr, 0x1e, rtl_ephy_read(ioaddr, 0x1e) | 0x8000); |
|
4771 } |
|
4772 |
|
4773 static void rtl_hw_start_8101(struct net_device *dev) |
|
4774 { |
|
4775 struct rtl8169_private *tp = netdev_priv(dev); |
|
4776 void __iomem *ioaddr = tp->mmio_addr; |
|
4777 struct pci_dev *pdev = tp->pci_dev; |
|
4778 |
|
4779 if (tp->mac_version >= RTL_GIGA_MAC_VER_30) |
|
4780 tp->event_slow &= ~RxFIFOOver; |
|
4781 |
|
4782 if (tp->mac_version == RTL_GIGA_MAC_VER_13 || |
|
4783 tp->mac_version == RTL_GIGA_MAC_VER_16) { |
|
4784 int cap = pci_pcie_cap(pdev); |
|
4785 |
|
4786 if (cap) { |
|
4787 pci_write_config_word(pdev, cap + PCI_EXP_DEVCTL, |
|
4788 PCI_EXP_DEVCTL_NOSNOOP_EN); |
|
4789 } |
|
4790 } |
|
4791 |
|
4792 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
4793 |
|
4794 switch (tp->mac_version) { |
|
4795 case RTL_GIGA_MAC_VER_07: |
|
4796 rtl_hw_start_8102e_1(ioaddr, pdev); |
|
4797 break; |
|
4798 |
|
4799 case RTL_GIGA_MAC_VER_08: |
|
4800 rtl_hw_start_8102e_3(ioaddr, pdev); |
|
4801 break; |
|
4802 |
|
4803 case RTL_GIGA_MAC_VER_09: |
|
4804 rtl_hw_start_8102e_2(ioaddr, pdev); |
|
4805 break; |
|
4806 |
|
4807 case RTL_GIGA_MAC_VER_29: |
|
4808 rtl_hw_start_8105e_1(ioaddr, pdev); |
|
4809 break; |
|
4810 case RTL_GIGA_MAC_VER_30: |
|
4811 rtl_hw_start_8105e_2(ioaddr, pdev); |
|
4812 break; |
|
4813 } |
|
4814 |
|
4815 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
4816 |
|
4817 RTL_W8(MaxTxPacketSize, TxPacketMax); |
|
4818 |
|
4819 rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
|
4820 |
|
4821 tp->cp_cmd &= ~R810X_CPCMD_QUIRK_MASK; |
|
4822 RTL_W16(CPlusCmd, tp->cp_cmd); |
|
4823 |
|
4824 RTL_W16(IntrMitigate, 0x0000); |
|
4825 |
|
4826 rtl_set_rx_tx_desc_registers(tp, ioaddr); |
|
4827 |
|
4828 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
|
4829 rtl_set_rx_tx_config_registers(tp); |
|
4830 |
|
4831 RTL_R8(IntrMask); |
|
4832 |
|
4833 rtl_set_rx_mode(dev); |
|
4834 |
|
4835 RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000); |
|
4836 } |
|
4837 |
|
4838 static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) |
|
4839 { |
|
4840 struct rtl8169_private *tp = netdev_priv(dev); |
|
4841 |
|
4842 if (new_mtu < ETH_ZLEN || |
|
4843 new_mtu > rtl_chip_infos[tp->mac_version].jumbo_max) |
|
4844 return -EINVAL; |
|
4845 |
|
4846 if (new_mtu > ETH_DATA_LEN) |
|
4847 rtl_hw_jumbo_enable(tp); |
|
4848 else |
|
4849 rtl_hw_jumbo_disable(tp); |
|
4850 |
|
4851 dev->mtu = new_mtu; |
|
4852 netdev_update_features(dev); |
|
4853 |
|
4854 return 0; |
|
4855 } |
|
4856 |
|
4857 static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc) |
|
4858 { |
|
4859 desc->addr = cpu_to_le64(0x0badbadbadbadbadull); |
|
4860 desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask); |
|
4861 } |
|
4862 |
|
4863 static void rtl8169_free_rx_databuff(struct rtl8169_private *tp, |
|
4864 void **data_buff, struct RxDesc *desc) |
|
4865 { |
|
4866 dma_unmap_single(&tp->pci_dev->dev, le64_to_cpu(desc->addr), rx_buf_sz, |
|
4867 DMA_FROM_DEVICE); |
|
4868 |
|
4869 kfree(*data_buff); |
|
4870 *data_buff = NULL; |
|
4871 rtl8169_make_unusable_by_asic(desc); |
|
4872 } |
|
4873 |
|
4874 static inline void rtl8169_mark_to_asic(struct RxDesc *desc, u32 rx_buf_sz) |
|
4875 { |
|
4876 u32 eor = le32_to_cpu(desc->opts1) & RingEnd; |
|
4877 |
|
4878 desc->opts1 = cpu_to_le32(DescOwn | eor | rx_buf_sz); |
|
4879 } |
|
4880 |
|
4881 static inline void rtl8169_map_to_asic(struct RxDesc *desc, dma_addr_t mapping, |
|
4882 u32 rx_buf_sz) |
|
4883 { |
|
4884 desc->addr = cpu_to_le64(mapping); |
|
4885 wmb(); |
|
4886 rtl8169_mark_to_asic(desc, rx_buf_sz); |
|
4887 } |
|
4888 |
|
4889 static inline void *rtl8169_align(void *data) |
|
4890 { |
|
4891 return (void *)ALIGN((long)data, 16); |
|
4892 } |
|
4893 |
|
4894 static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp, |
|
4895 struct RxDesc *desc) |
|
4896 { |
|
4897 void *data; |
|
4898 dma_addr_t mapping; |
|
4899 struct device *d = &tp->pci_dev->dev; |
|
4900 struct net_device *dev = tp->dev; |
|
4901 int node = dev->dev.parent ? dev_to_node(dev->dev.parent) : -1; |
|
4902 |
|
4903 data = kmalloc_node(rx_buf_sz, GFP_KERNEL, node); |
|
4904 if (!data) |
|
4905 return NULL; |
|
4906 |
|
4907 if (rtl8169_align(data) != data) { |
|
4908 kfree(data); |
|
4909 data = kmalloc_node(rx_buf_sz + 15, GFP_KERNEL, node); |
|
4910 if (!data) |
|
4911 return NULL; |
|
4912 } |
|
4913 |
|
4914 mapping = dma_map_single(d, rtl8169_align(data), rx_buf_sz, |
|
4915 DMA_FROM_DEVICE); |
|
4916 if (unlikely(dma_mapping_error(d, mapping))) { |
|
4917 if (net_ratelimit()) |
|
4918 netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n"); |
|
4919 goto err_out; |
|
4920 } |
|
4921 |
|
4922 rtl8169_map_to_asic(desc, mapping, rx_buf_sz); |
|
4923 return data; |
|
4924 |
|
4925 err_out: |
|
4926 kfree(data); |
|
4927 return NULL; |
|
4928 } |
|
4929 |
|
4930 static void rtl8169_rx_clear(struct rtl8169_private *tp) |
|
4931 { |
|
4932 unsigned int i; |
|
4933 |
|
4934 for (i = 0; i < NUM_RX_DESC; i++) { |
|
4935 if (tp->Rx_databuff[i]) { |
|
4936 rtl8169_free_rx_databuff(tp, tp->Rx_databuff + i, |
|
4937 tp->RxDescArray + i); |
|
4938 } |
|
4939 } |
|
4940 } |
|
4941 |
|
4942 static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc) |
|
4943 { |
|
4944 desc->opts1 |= cpu_to_le32(RingEnd); |
|
4945 } |
|
4946 |
|
4947 static int rtl8169_rx_fill(struct rtl8169_private *tp) |
|
4948 { |
|
4949 unsigned int i; |
|
4950 |
|
4951 for (i = 0; i < NUM_RX_DESC; i++) { |
|
4952 void *data; |
|
4953 |
|
4954 if (tp->Rx_databuff[i]) |
|
4955 continue; |
|
4956 |
|
4957 data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); |
|
4958 if (!data) { |
|
4959 rtl8169_make_unusable_by_asic(tp->RxDescArray + i); |
|
4960 goto err_out; |
|
4961 } |
|
4962 tp->Rx_databuff[i] = data; |
|
4963 } |
|
4964 |
|
4965 rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1); |
|
4966 return 0; |
|
4967 |
|
4968 err_out: |
|
4969 rtl8169_rx_clear(tp); |
|
4970 return -ENOMEM; |
|
4971 } |
|
4972 |
|
4973 static int rtl8169_init_ring(struct net_device *dev) |
|
4974 { |
|
4975 struct rtl8169_private *tp = netdev_priv(dev); |
|
4976 |
|
4977 rtl8169_init_ring_indexes(tp); |
|
4978 |
|
4979 memset(tp->tx_skb, 0x0, NUM_TX_DESC * sizeof(struct ring_info)); |
|
4980 memset(tp->Rx_databuff, 0x0, NUM_RX_DESC * sizeof(void *)); |
|
4981 |
|
4982 return rtl8169_rx_fill(tp); |
|
4983 } |
|
4984 |
|
4985 static void rtl8169_unmap_tx_skb(struct device *d, struct ring_info *tx_skb, |
|
4986 struct TxDesc *desc) |
|
4987 { |
|
4988 unsigned int len = tx_skb->len; |
|
4989 |
|
4990 dma_unmap_single(d, le64_to_cpu(desc->addr), len, DMA_TO_DEVICE); |
|
4991 |
|
4992 desc->opts1 = 0x00; |
|
4993 desc->opts2 = 0x00; |
|
4994 desc->addr = 0x00; |
|
4995 tx_skb->len = 0; |
|
4996 } |
|
4997 |
|
4998 static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, |
|
4999 unsigned int n) |
|
5000 { |
|
5001 unsigned int i; |
|
5002 |
|
5003 for (i = 0; i < n; i++) { |
|
5004 unsigned int entry = (start + i) % NUM_TX_DESC; |
|
5005 struct ring_info *tx_skb = tp->tx_skb + entry; |
|
5006 unsigned int len = tx_skb->len; |
|
5007 |
|
5008 if (len) { |
|
5009 struct sk_buff *skb = tx_skb->skb; |
|
5010 |
|
5011 rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb, |
|
5012 tp->TxDescArray + entry); |
|
5013 if (skb) { |
|
5014 tp->dev->stats.tx_dropped++; |
|
5015 dev_kfree_skb(skb); |
|
5016 tx_skb->skb = NULL; |
|
5017 } |
|
5018 } |
|
5019 } |
|
5020 } |
|
5021 |
|
5022 static void rtl8169_tx_clear(struct rtl8169_private *tp) |
|
5023 { |
|
5024 rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); |
|
5025 tp->cur_tx = tp->dirty_tx = 0; |
|
5026 } |
|
5027 |
|
5028 static void rtl_reset_work(struct rtl8169_private *tp) |
|
5029 { |
|
5030 struct net_device *dev = tp->dev; |
|
5031 int i; |
|
5032 |
|
5033 napi_disable(&tp->napi); |
|
5034 netif_stop_queue(dev); |
|
5035 synchronize_sched(); |
|
5036 |
|
5037 rtl8169_hw_reset(tp); |
|
5038 |
|
5039 for (i = 0; i < NUM_RX_DESC; i++) |
|
5040 rtl8169_mark_to_asic(tp->RxDescArray + i, rx_buf_sz); |
|
5041 |
|
5042 rtl8169_tx_clear(tp); |
|
5043 rtl8169_init_ring_indexes(tp); |
|
5044 |
|
5045 napi_enable(&tp->napi); |
|
5046 rtl_hw_start(dev); |
|
5047 netif_wake_queue(dev); |
|
5048 rtl8169_check_link_status(dev, tp, tp->mmio_addr); |
|
5049 } |
|
5050 |
|
5051 static void rtl8169_tx_timeout(struct net_device *dev) |
|
5052 { |
|
5053 struct rtl8169_private *tp = netdev_priv(dev); |
|
5054 |
|
5055 rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
|
5056 } |
|
5057 |
|
5058 static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb, |
|
5059 u32 *opts) |
|
5060 { |
|
5061 struct skb_shared_info *info = skb_shinfo(skb); |
|
5062 unsigned int cur_frag, entry; |
|
5063 struct TxDesc * uninitialized_var(txd); |
|
5064 struct device *d = &tp->pci_dev->dev; |
|
5065 |
|
5066 entry = tp->cur_tx; |
|
5067 for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { |
|
5068 const skb_frag_t *frag = info->frags + cur_frag; |
|
5069 dma_addr_t mapping; |
|
5070 u32 status, len; |
|
5071 void *addr; |
|
5072 |
|
5073 entry = (entry + 1) % NUM_TX_DESC; |
|
5074 |
|
5075 txd = tp->TxDescArray + entry; |
|
5076 len = skb_frag_size(frag); |
|
5077 addr = skb_frag_address(frag); |
|
5078 mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE); |
|
5079 if (unlikely(dma_mapping_error(d, mapping))) { |
|
5080 if (net_ratelimit()) |
|
5081 netif_err(tp, drv, tp->dev, |
|
5082 "Failed to map TX fragments DMA!\n"); |
|
5083 goto err_out; |
|
5084 } |
|
5085 |
|
5086 /* Anti gcc 2.95.3 bugware (sic) */ |
|
5087 status = opts[0] | len | |
|
5088 (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
|
5089 |
|
5090 txd->opts1 = cpu_to_le32(status); |
|
5091 txd->opts2 = cpu_to_le32(opts[1]); |
|
5092 txd->addr = cpu_to_le64(mapping); |
|
5093 |
|
5094 tp->tx_skb[entry].len = len; |
|
5095 } |
|
5096 |
|
5097 if (cur_frag) { |
|
5098 tp->tx_skb[entry].skb = skb; |
|
5099 txd->opts1 |= cpu_to_le32(LastFrag); |
|
5100 } |
|
5101 |
|
5102 return cur_frag; |
|
5103 |
|
5104 err_out: |
|
5105 rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag); |
|
5106 return -EIO; |
|
5107 } |
|
5108 |
|
5109 static inline void rtl8169_tso_csum(struct rtl8169_private *tp, |
|
5110 struct sk_buff *skb, u32 *opts) |
|
5111 { |
|
5112 const struct rtl_tx_desc_info *info = tx_desc_info + tp->txd_version; |
|
5113 u32 mss = skb_shinfo(skb)->gso_size; |
|
5114 int offset = info->opts_offset; |
|
5115 |
|
5116 if (mss) { |
|
5117 opts[0] |= TD_LSO; |
|
5118 opts[offset] |= min(mss, TD_MSS_MAX) << info->mss_shift; |
|
5119 } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
|
5120 const struct iphdr *ip = ip_hdr(skb); |
|
5121 |
|
5122 if (ip->protocol == IPPROTO_TCP) |
|
5123 opts[offset] |= info->checksum.tcp; |
|
5124 else if (ip->protocol == IPPROTO_UDP) |
|
5125 opts[offset] |= info->checksum.udp; |
|
5126 else |
|
5127 WARN_ON_ONCE(1); |
|
5128 } |
|
5129 } |
|
5130 |
|
5131 static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
|
5132 struct net_device *dev) |
|
5133 { |
|
5134 struct rtl8169_private *tp = netdev_priv(dev); |
|
5135 unsigned int entry = tp->cur_tx % NUM_TX_DESC; |
|
5136 struct TxDesc *txd = tp->TxDescArray + entry; |
|
5137 void __iomem *ioaddr = tp->mmio_addr; |
|
5138 struct device *d = &tp->pci_dev->dev; |
|
5139 dma_addr_t mapping; |
|
5140 u32 status, len; |
|
5141 u32 opts[2]; |
|
5142 int frags; |
|
5143 |
|
5144 if (unlikely(!TX_FRAGS_READY_FOR(tp, skb_shinfo(skb)->nr_frags))) { |
|
5145 netif_err(tp, drv, dev, "BUG! Tx Ring full when queue awake!\n"); |
|
5146 goto err_stop_0; |
|
5147 } |
|
5148 |
|
5149 if (unlikely(le32_to_cpu(txd->opts1) & DescOwn)) |
|
5150 goto err_stop_0; |
|
5151 |
|
5152 len = skb_headlen(skb); |
|
5153 mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE); |
|
5154 if (unlikely(dma_mapping_error(d, mapping))) { |
|
5155 if (net_ratelimit()) |
|
5156 netif_err(tp, drv, dev, "Failed to map TX DMA!\n"); |
|
5157 goto err_dma_0; |
|
5158 } |
|
5159 |
|
5160 tp->tx_skb[entry].len = len; |
|
5161 txd->addr = cpu_to_le64(mapping); |
|
5162 |
|
5163 opts[1] = cpu_to_le32(rtl8169_tx_vlan_tag(tp, skb)); |
|
5164 opts[0] = DescOwn; |
|
5165 |
|
5166 rtl8169_tso_csum(tp, skb, opts); |
|
5167 |
|
5168 frags = rtl8169_xmit_frags(tp, skb, opts); |
|
5169 if (frags < 0) |
|
5170 goto err_dma_1; |
|
5171 else if (frags) |
|
5172 opts[0] |= FirstFrag; |
|
5173 else { |
|
5174 opts[0] |= FirstFrag | LastFrag; |
|
5175 tp->tx_skb[entry].skb = skb; |
|
5176 } |
|
5177 |
|
5178 txd->opts2 = cpu_to_le32(opts[1]); |
|
5179 |
|
5180 skb_tx_timestamp(skb); |
|
5181 |
|
5182 wmb(); |
|
5183 |
|
5184 /* Anti gcc 2.95.3 bugware (sic) */ |
|
5185 status = opts[0] | len | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
|
5186 txd->opts1 = cpu_to_le32(status); |
|
5187 |
|
5188 tp->cur_tx += frags + 1; |
|
5189 |
|
5190 wmb(); |
|
5191 |
|
5192 RTL_W8(TxPoll, NPQ); |
|
5193 |
|
5194 mmiowb(); |
|
5195 |
|
5196 if (!TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
|
5197 /* Avoid wrongly optimistic queue wake-up: rtl_tx thread must |
|
5198 * not miss a ring update when it notices a stopped queue. |
|
5199 */ |
|
5200 smp_wmb(); |
|
5201 netif_stop_queue(dev); |
|
5202 /* Sync with rtl_tx: |
|
5203 * - publish queue status and cur_tx ring index (write barrier) |
|
5204 * - refresh dirty_tx ring index (read barrier). |
|
5205 * May the current thread have a pessimistic view of the ring |
|
5206 * status and forget to wake up queue, a racing rtl_tx thread |
|
5207 * can't. |
|
5208 */ |
|
5209 smp_mb(); |
|
5210 if (TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) |
|
5211 netif_wake_queue(dev); |
|
5212 } |
|
5213 |
|
5214 return NETDEV_TX_OK; |
|
5215 |
|
5216 err_dma_1: |
|
5217 rtl8169_unmap_tx_skb(d, tp->tx_skb + entry, txd); |
|
5218 err_dma_0: |
|
5219 dev_kfree_skb(skb); |
|
5220 dev->stats.tx_dropped++; |
|
5221 return NETDEV_TX_OK; |
|
5222 |
|
5223 err_stop_0: |
|
5224 netif_stop_queue(dev); |
|
5225 dev->stats.tx_dropped++; |
|
5226 return NETDEV_TX_BUSY; |
|
5227 } |
|
5228 |
|
5229 static void rtl8169_pcierr_interrupt(struct net_device *dev) |
|
5230 { |
|
5231 struct rtl8169_private *tp = netdev_priv(dev); |
|
5232 struct pci_dev *pdev = tp->pci_dev; |
|
5233 u16 pci_status, pci_cmd; |
|
5234 |
|
5235 pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); |
|
5236 pci_read_config_word(pdev, PCI_STATUS, &pci_status); |
|
5237 |
|
5238 netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n", |
|
5239 pci_cmd, pci_status); |
|
5240 |
|
5241 /* |
|
5242 * The recovery sequence below admits a very elaborated explanation: |
|
5243 * - it seems to work; |
|
5244 * - I did not see what else could be done; |
|
5245 * - it makes iop3xx happy. |
|
5246 * |
|
5247 * Feel free to adjust to your needs. |
|
5248 */ |
|
5249 if (pdev->broken_parity_status) |
|
5250 pci_cmd &= ~PCI_COMMAND_PARITY; |
|
5251 else |
|
5252 pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; |
|
5253 |
|
5254 pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); |
|
5255 |
|
5256 pci_write_config_word(pdev, PCI_STATUS, |
|
5257 pci_status & (PCI_STATUS_DETECTED_PARITY | |
|
5258 PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT | |
|
5259 PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT)); |
|
5260 |
|
5261 /* The infamous DAC f*ckup only happens at boot time */ |
|
5262 if ((tp->cp_cmd & PCIDAC) && !tp->dirty_rx && !tp->cur_rx) { |
|
5263 void __iomem *ioaddr = tp->mmio_addr; |
|
5264 |
|
5265 netif_info(tp, intr, dev, "disabling PCI DAC\n"); |
|
5266 tp->cp_cmd &= ~PCIDAC; |
|
5267 RTL_W16(CPlusCmd, tp->cp_cmd); |
|
5268 dev->features &= ~NETIF_F_HIGHDMA; |
|
5269 } |
|
5270 |
|
5271 rtl8169_hw_reset(tp); |
|
5272 |
|
5273 rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
|
5274 } |
|
5275 |
|
5276 static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp) |
|
5277 { |
|
5278 unsigned int dirty_tx, tx_left; |
|
5279 |
|
5280 dirty_tx = tp->dirty_tx; |
|
5281 smp_rmb(); |
|
5282 tx_left = tp->cur_tx - dirty_tx; |
|
5283 |
|
5284 while (tx_left > 0) { |
|
5285 unsigned int entry = dirty_tx % NUM_TX_DESC; |
|
5286 struct ring_info *tx_skb = tp->tx_skb + entry; |
|
5287 u32 status; |
|
5288 |
|
5289 rmb(); |
|
5290 status = le32_to_cpu(tp->TxDescArray[entry].opts1); |
|
5291 if (status & DescOwn) |
|
5292 break; |
|
5293 |
|
5294 rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb, |
|
5295 tp->TxDescArray + entry); |
|
5296 if (status & LastFrag) { |
|
5297 u64_stats_update_begin(&tp->tx_stats.syncp); |
|
5298 tp->tx_stats.packets++; |
|
5299 tp->tx_stats.bytes += tx_skb->skb->len; |
|
5300 u64_stats_update_end(&tp->tx_stats.syncp); |
|
5301 dev_kfree_skb(tx_skb->skb); |
|
5302 tx_skb->skb = NULL; |
|
5303 } |
|
5304 dirty_tx++; |
|
5305 tx_left--; |
|
5306 } |
|
5307 |
|
5308 if (tp->dirty_tx != dirty_tx) { |
|
5309 tp->dirty_tx = dirty_tx; |
|
5310 /* Sync with rtl8169_start_xmit: |
|
5311 * - publish dirty_tx ring index (write barrier) |
|
5312 * - refresh cur_tx ring index and queue status (read barrier) |
|
5313 * May the current thread miss the stopped queue condition, |
|
5314 * a racing xmit thread can only have a right view of the |
|
5315 * ring status. |
|
5316 */ |
|
5317 smp_mb(); |
|
5318 if (netif_queue_stopped(dev) && |
|
5319 TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
|
5320 netif_wake_queue(dev); |
|
5321 } |
|
5322 /* |
|
5323 * 8168 hack: TxPoll requests are lost when the Tx packets are |
|
5324 * too close. Let's kick an extra TxPoll request when a burst |
|
5325 * of start_xmit activity is detected (if it is not detected, |
|
5326 * it is slow enough). -- FR |
|
5327 */ |
|
5328 if (tp->cur_tx != dirty_tx) { |
|
5329 void __iomem *ioaddr = tp->mmio_addr; |
|
5330 |
|
5331 RTL_W8(TxPoll, NPQ); |
|
5332 } |
|
5333 } |
|
5334 } |
|
5335 |
|
5336 static inline int rtl8169_fragmented_frame(u32 status) |
|
5337 { |
|
5338 return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag); |
|
5339 } |
|
5340 |
|
5341 static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) |
|
5342 { |
|
5343 u32 status = opts1 & RxProtoMask; |
|
5344 |
|
5345 if (((status == RxProtoTCP) && !(opts1 & TCPFail)) || |
|
5346 ((status == RxProtoUDP) && !(opts1 & UDPFail))) |
|
5347 skb->ip_summed = CHECKSUM_UNNECESSARY; |
|
5348 else |
|
5349 skb_checksum_none_assert(skb); |
|
5350 } |
|
5351 |
|
5352 static struct sk_buff *rtl8169_try_rx_copy(void *data, |
|
5353 struct rtl8169_private *tp, |
|
5354 int pkt_size, |
|
5355 dma_addr_t addr) |
|
5356 { |
|
5357 struct sk_buff *skb; |
|
5358 struct device *d = &tp->pci_dev->dev; |
|
5359 |
|
5360 data = rtl8169_align(data); |
|
5361 dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE); |
|
5362 prefetch(data); |
|
5363 skb = netdev_alloc_skb_ip_align(tp->dev, pkt_size); |
|
5364 if (skb) |
|
5365 memcpy(skb->data, data, pkt_size); |
|
5366 dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE); |
|
5367 |
|
5368 return skb; |
|
5369 } |
|
5370 |
|
5371 static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, u32 budget) |
|
5372 { |
|
5373 unsigned int cur_rx, rx_left; |
|
5374 unsigned int count; |
|
5375 |
|
5376 cur_rx = tp->cur_rx; |
|
5377 rx_left = NUM_RX_DESC + tp->dirty_rx - cur_rx; |
|
5378 rx_left = min(rx_left, budget); |
|
5379 |
|
5380 for (; rx_left > 0; rx_left--, cur_rx++) { |
|
5381 unsigned int entry = cur_rx % NUM_RX_DESC; |
|
5382 struct RxDesc *desc = tp->RxDescArray + entry; |
|
5383 u32 status; |
|
5384 |
|
5385 rmb(); |
|
5386 status = le32_to_cpu(desc->opts1) & tp->opts1_mask; |
|
5387 |
|
5388 if (status & DescOwn) |
|
5389 break; |
|
5390 if (unlikely(status & RxRES)) { |
|
5391 netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n", |
|
5392 status); |
|
5393 dev->stats.rx_errors++; |
|
5394 if (status & (RxRWT | RxRUNT)) |
|
5395 dev->stats.rx_length_errors++; |
|
5396 if (status & RxCRC) |
|
5397 dev->stats.rx_crc_errors++; |
|
5398 if (status & RxFOVF) { |
|
5399 rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
|
5400 dev->stats.rx_fifo_errors++; |
|
5401 } |
|
5402 if ((status & (RxRUNT | RxCRC)) && |
|
5403 !(status & (RxRWT | RxFOVF)) && |
|
5404 (dev->features & NETIF_F_RXALL)) |
|
5405 goto process_pkt; |
|
5406 |
|
5407 rtl8169_mark_to_asic(desc, rx_buf_sz); |
|
5408 } else { |
|
5409 struct sk_buff *skb; |
|
5410 dma_addr_t addr; |
|
5411 int pkt_size; |
|
5412 |
|
5413 process_pkt: |
|
5414 addr = le64_to_cpu(desc->addr); |
|
5415 if (likely(!(dev->features & NETIF_F_RXFCS))) |
|
5416 pkt_size = (status & 0x00003fff) - 4; |
|
5417 else |
|
5418 pkt_size = status & 0x00003fff; |
|
5419 |
|
5420 /* |
|
5421 * The driver does not support incoming fragmented |
|
5422 * frames. They are seen as a symptom of over-mtu |
|
5423 * sized frames. |
|
5424 */ |
|
5425 if (unlikely(rtl8169_fragmented_frame(status))) { |
|
5426 dev->stats.rx_dropped++; |
|
5427 dev->stats.rx_length_errors++; |
|
5428 rtl8169_mark_to_asic(desc, rx_buf_sz); |
|
5429 continue; |
|
5430 } |
|
5431 |
|
5432 skb = rtl8169_try_rx_copy(tp->Rx_databuff[entry], |
|
5433 tp, pkt_size, addr); |
|
5434 rtl8169_mark_to_asic(desc, rx_buf_sz); |
|
5435 if (!skb) { |
|
5436 dev->stats.rx_dropped++; |
|
5437 continue; |
|
5438 } |
|
5439 |
|
5440 rtl8169_rx_csum(skb, status); |
|
5441 skb_put(skb, pkt_size); |
|
5442 skb->protocol = eth_type_trans(skb, dev); |
|
5443 |
|
5444 rtl8169_rx_vlan_tag(desc, skb); |
|
5445 |
|
5446 napi_gro_receive(&tp->napi, skb); |
|
5447 |
|
5448 u64_stats_update_begin(&tp->rx_stats.syncp); |
|
5449 tp->rx_stats.packets++; |
|
5450 tp->rx_stats.bytes += pkt_size; |
|
5451 u64_stats_update_end(&tp->rx_stats.syncp); |
|
5452 } |
|
5453 |
|
5454 /* Work around for AMD plateform. */ |
|
5455 if ((desc->opts2 & cpu_to_le32(0xfffe000)) && |
|
5456 (tp->mac_version == RTL_GIGA_MAC_VER_05)) { |
|
5457 desc->opts2 = 0; |
|
5458 cur_rx++; |
|
5459 } |
|
5460 } |
|
5461 |
|
5462 count = cur_rx - tp->cur_rx; |
|
5463 tp->cur_rx = cur_rx; |
|
5464 |
|
5465 tp->dirty_rx += count; |
|
5466 |
|
5467 return count; |
|
5468 } |
|
5469 |
|
5470 static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) |
|
5471 { |
|
5472 struct net_device *dev = dev_instance; |
|
5473 struct rtl8169_private *tp = netdev_priv(dev); |
|
5474 int handled = 0; |
|
5475 u16 status; |
|
5476 |
|
5477 status = rtl_get_events(tp); |
|
5478 if (status && status != 0xffff) { |
|
5479 status &= RTL_EVENT_NAPI | tp->event_slow; |
|
5480 if (status) { |
|
5481 handled = 1; |
|
5482 |
|
5483 rtl_irq_disable(tp); |
|
5484 napi_schedule(&tp->napi); |
|
5485 } |
|
5486 } |
|
5487 return IRQ_RETVAL(handled); |
|
5488 } |
|
5489 |
|
5490 /* |
|
5491 * Workqueue context. |
|
5492 */ |
|
5493 static void rtl_slow_event_work(struct rtl8169_private *tp) |
|
5494 { |
|
5495 struct net_device *dev = tp->dev; |
|
5496 u16 status; |
|
5497 |
|
5498 status = rtl_get_events(tp) & tp->event_slow; |
|
5499 rtl_ack_events(tp, status); |
|
5500 |
|
5501 if (unlikely(status & RxFIFOOver)) { |
|
5502 switch (tp->mac_version) { |
|
5503 /* Work around for rx fifo overflow */ |
|
5504 case RTL_GIGA_MAC_VER_11: |
|
5505 netif_stop_queue(dev); |
|
5506 /* XXX - Hack alert. See rtl_task(). */ |
|
5507 set_bit(RTL_FLAG_TASK_RESET_PENDING, tp->wk.flags); |
|
5508 default: |
|
5509 break; |
|
5510 } |
|
5511 } |
|
5512 |
|
5513 if (unlikely(status & SYSErr)) |
|
5514 rtl8169_pcierr_interrupt(dev); |
|
5515 |
|
5516 if (status & LinkChg) |
|
5517 __rtl8169_check_link_status(dev, tp, tp->mmio_addr, true); |
|
5518 |
|
5519 napi_disable(&tp->napi); |
|
5520 rtl_irq_disable(tp); |
|
5521 |
|
5522 napi_enable(&tp->napi); |
|
5523 napi_schedule(&tp->napi); |
|
5524 } |
|
5525 |
|
5526 static void rtl_task(struct work_struct *work) |
|
5527 { |
|
5528 static const struct { |
|
5529 int bitnr; |
|
5530 void (*action)(struct rtl8169_private *); |
|
5531 } rtl_work[] = { |
|
5532 /* XXX - keep rtl_slow_event_work() as first element. */ |
|
5533 { RTL_FLAG_TASK_SLOW_PENDING, rtl_slow_event_work }, |
|
5534 { RTL_FLAG_TASK_RESET_PENDING, rtl_reset_work }, |
|
5535 { RTL_FLAG_TASK_PHY_PENDING, rtl_phy_work } |
|
5536 }; |
|
5537 struct rtl8169_private *tp = |
|
5538 container_of(work, struct rtl8169_private, wk.work); |
|
5539 struct net_device *dev = tp->dev; |
|
5540 int i; |
|
5541 |
|
5542 rtl_lock_work(tp); |
|
5543 |
|
5544 if (!netif_running(dev) || |
|
5545 !test_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags)) |
|
5546 goto out_unlock; |
|
5547 |
|
5548 for (i = 0; i < ARRAY_SIZE(rtl_work); i++) { |
|
5549 bool pending; |
|
5550 |
|
5551 pending = test_and_clear_bit(rtl_work[i].bitnr, tp->wk.flags); |
|
5552 if (pending) |
|
5553 rtl_work[i].action(tp); |
|
5554 } |
|
5555 |
|
5556 out_unlock: |
|
5557 rtl_unlock_work(tp); |
|
5558 } |
|
5559 |
|
5560 static int rtl8169_poll(struct napi_struct *napi, int budget) |
|
5561 { |
|
5562 struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); |
|
5563 struct net_device *dev = tp->dev; |
|
5564 u16 enable_mask = RTL_EVENT_NAPI | tp->event_slow; |
|
5565 int work_done= 0; |
|
5566 u16 status; |
|
5567 |
|
5568 status = rtl_get_events(tp); |
|
5569 rtl_ack_events(tp, status & ~tp->event_slow); |
|
5570 |
|
5571 if (status & RTL_EVENT_NAPI_RX) |
|
5572 work_done = rtl_rx(dev, tp, (u32) budget); |
|
5573 |
|
5574 if (status & RTL_EVENT_NAPI_TX) |
|
5575 rtl_tx(dev, tp); |
|
5576 |
|
5577 if (status & tp->event_slow) { |
|
5578 enable_mask &= ~tp->event_slow; |
|
5579 |
|
5580 rtl_schedule_task(tp, RTL_FLAG_TASK_SLOW_PENDING); |
|
5581 } |
|
5582 |
|
5583 if (work_done < budget) { |
|
5584 napi_complete(napi); |
|
5585 |
|
5586 rtl_irq_enable(tp, enable_mask); |
|
5587 mmiowb(); |
|
5588 } |
|
5589 |
|
5590 return work_done; |
|
5591 } |
|
5592 |
|
5593 static void rtl8169_rx_missed(struct net_device *dev, void __iomem *ioaddr) |
|
5594 { |
|
5595 struct rtl8169_private *tp = netdev_priv(dev); |
|
5596 |
|
5597 if (tp->mac_version > RTL_GIGA_MAC_VER_06) |
|
5598 return; |
|
5599 |
|
5600 dev->stats.rx_missed_errors += (RTL_R32(RxMissed) & 0xffffff); |
|
5601 RTL_W32(RxMissed, 0); |
|
5602 } |
|
5603 |
|
5604 static void rtl8169_down(struct net_device *dev) |
|
5605 { |
|
5606 struct rtl8169_private *tp = netdev_priv(dev); |
|
5607 void __iomem *ioaddr = tp->mmio_addr; |
|
5608 |
|
5609 del_timer_sync(&tp->timer); |
|
5610 |
|
5611 napi_disable(&tp->napi); |
|
5612 netif_stop_queue(dev); |
|
5613 |
|
5614 rtl8169_hw_reset(tp); |
|
5615 /* |
|
5616 * At this point device interrupts can not be enabled in any function, |
|
5617 * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task) |
|
5618 * and napi is disabled (rtl8169_poll). |
|
5619 */ |
|
5620 rtl8169_rx_missed(dev, ioaddr); |
|
5621 |
|
5622 /* Give a racing hard_start_xmit a few cycles to complete. */ |
|
5623 synchronize_sched(); |
|
5624 |
|
5625 rtl8169_tx_clear(tp); |
|
5626 |
|
5627 rtl8169_rx_clear(tp); |
|
5628 |
|
5629 rtl_pll_power_down(tp); |
|
5630 } |
|
5631 |
|
5632 static int rtl8169_close(struct net_device *dev) |
|
5633 { |
|
5634 struct rtl8169_private *tp = netdev_priv(dev); |
|
5635 struct pci_dev *pdev = tp->pci_dev; |
|
5636 |
|
5637 pm_runtime_get_sync(&pdev->dev); |
|
5638 |
|
5639 /* Update counters before going down */ |
|
5640 rtl8169_update_counters(dev); |
|
5641 |
|
5642 rtl_lock_work(tp); |
|
5643 clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
|
5644 |
|
5645 rtl8169_down(dev); |
|
5646 rtl_unlock_work(tp); |
|
5647 |
|
5648 free_irq(pdev->irq, dev); |
|
5649 |
|
5650 dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
|
5651 tp->RxPhyAddr); |
|
5652 dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
|
5653 tp->TxPhyAddr); |
|
5654 tp->TxDescArray = NULL; |
|
5655 tp->RxDescArray = NULL; |
|
5656 |
|
5657 pm_runtime_put_sync(&pdev->dev); |
|
5658 |
|
5659 return 0; |
|
5660 } |
|
5661 |
|
5662 #ifdef CONFIG_NET_POLL_CONTROLLER |
|
5663 static void rtl8169_netpoll(struct net_device *dev) |
|
5664 { |
|
5665 struct rtl8169_private *tp = netdev_priv(dev); |
|
5666 |
|
5667 rtl8169_interrupt(tp->pci_dev->irq, dev); |
|
5668 } |
|
5669 #endif |
|
5670 |
|
5671 static int rtl_open(struct net_device *dev) |
|
5672 { |
|
5673 struct rtl8169_private *tp = netdev_priv(dev); |
|
5674 void __iomem *ioaddr = tp->mmio_addr; |
|
5675 struct pci_dev *pdev = tp->pci_dev; |
|
5676 int retval = -ENOMEM; |
|
5677 |
|
5678 pm_runtime_get_sync(&pdev->dev); |
|
5679 |
|
5680 /* |
|
5681 * Rx and Tx desscriptors needs 256 bytes alignment. |
|
5682 * dma_alloc_coherent provides more. |
|
5683 */ |
|
5684 tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES, |
|
5685 &tp->TxPhyAddr, GFP_KERNEL); |
|
5686 if (!tp->TxDescArray) |
|
5687 goto err_pm_runtime_put; |
|
5688 |
|
5689 tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, |
|
5690 &tp->RxPhyAddr, GFP_KERNEL); |
|
5691 if (!tp->RxDescArray) |
|
5692 goto err_free_tx_0; |
|
5693 |
|
5694 retval = rtl8169_init_ring(dev); |
|
5695 if (retval < 0) |
|
5696 goto err_free_rx_1; |
|
5697 |
|
5698 INIT_WORK(&tp->wk.work, rtl_task); |
|
5699 |
|
5700 smp_mb(); |
|
5701 |
|
5702 rtl_request_firmware(tp); |
|
5703 |
|
5704 retval = request_irq(pdev->irq, rtl8169_interrupt, |
|
5705 (tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED, |
|
5706 dev->name, dev); |
|
5707 if (retval < 0) |
|
5708 goto err_release_fw_2; |
|
5709 |
|
5710 rtl_lock_work(tp); |
|
5711 |
|
5712 set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
|
5713 |
|
5714 napi_enable(&tp->napi); |
|
5715 |
|
5716 rtl8169_init_phy(dev, tp); |
|
5717 |
|
5718 __rtl8169_set_features(dev, dev->features); |
|
5719 |
|
5720 rtl_pll_power_up(tp); |
|
5721 |
|
5722 rtl_hw_start(dev); |
|
5723 |
|
5724 netif_start_queue(dev); |
|
5725 |
|
5726 rtl_unlock_work(tp); |
|
5727 |
|
5728 tp->saved_wolopts = 0; |
|
5729 pm_runtime_put_noidle(&pdev->dev); |
|
5730 |
|
5731 rtl8169_check_link_status(dev, tp, ioaddr); |
|
5732 out: |
|
5733 return retval; |
|
5734 |
|
5735 err_release_fw_2: |
|
5736 rtl_release_firmware(tp); |
|
5737 rtl8169_rx_clear(tp); |
|
5738 err_free_rx_1: |
|
5739 dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
|
5740 tp->RxPhyAddr); |
|
5741 tp->RxDescArray = NULL; |
|
5742 err_free_tx_0: |
|
5743 dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
|
5744 tp->TxPhyAddr); |
|
5745 tp->TxDescArray = NULL; |
|
5746 err_pm_runtime_put: |
|
5747 pm_runtime_put_noidle(&pdev->dev); |
|
5748 goto out; |
|
5749 } |
|
5750 |
|
5751 static struct rtnl_link_stats64 * |
|
5752 rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
|
5753 { |
|
5754 struct rtl8169_private *tp = netdev_priv(dev); |
|
5755 void __iomem *ioaddr = tp->mmio_addr; |
|
5756 unsigned int start; |
|
5757 |
|
5758 if (netif_running(dev)) |
|
5759 rtl8169_rx_missed(dev, ioaddr); |
|
5760 |
|
5761 do { |
|
5762 start = u64_stats_fetch_begin_bh(&tp->rx_stats.syncp); |
|
5763 stats->rx_packets = tp->rx_stats.packets; |
|
5764 stats->rx_bytes = tp->rx_stats.bytes; |
|
5765 } while (u64_stats_fetch_retry_bh(&tp->rx_stats.syncp, start)); |
|
5766 |
|
5767 |
|
5768 do { |
|
5769 start = u64_stats_fetch_begin_bh(&tp->tx_stats.syncp); |
|
5770 stats->tx_packets = tp->tx_stats.packets; |
|
5771 stats->tx_bytes = tp->tx_stats.bytes; |
|
5772 } while (u64_stats_fetch_retry_bh(&tp->tx_stats.syncp, start)); |
|
5773 |
|
5774 stats->rx_dropped = dev->stats.rx_dropped; |
|
5775 stats->tx_dropped = dev->stats.tx_dropped; |
|
5776 stats->rx_length_errors = dev->stats.rx_length_errors; |
|
5777 stats->rx_errors = dev->stats.rx_errors; |
|
5778 stats->rx_crc_errors = dev->stats.rx_crc_errors; |
|
5779 stats->rx_fifo_errors = dev->stats.rx_fifo_errors; |
|
5780 stats->rx_missed_errors = dev->stats.rx_missed_errors; |
|
5781 |
|
5782 return stats; |
|
5783 } |
|
5784 |
|
5785 static void rtl8169_net_suspend(struct net_device *dev) |
|
5786 { |
|
5787 struct rtl8169_private *tp = netdev_priv(dev); |
|
5788 |
|
5789 if (!netif_running(dev)) |
|
5790 return; |
|
5791 |
|
5792 netif_device_detach(dev); |
|
5793 netif_stop_queue(dev); |
|
5794 |
|
5795 rtl_lock_work(tp); |
|
5796 napi_disable(&tp->napi); |
|
5797 clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
|
5798 rtl_unlock_work(tp); |
|
5799 |
|
5800 rtl_pll_power_down(tp); |
|
5801 } |
|
5802 |
|
5803 #ifdef CONFIG_PM |
|
5804 |
|
5805 static int rtl8169_suspend(struct device *device) |
|
5806 { |
|
5807 struct pci_dev *pdev = to_pci_dev(device); |
|
5808 struct net_device *dev = pci_get_drvdata(pdev); |
|
5809 |
|
5810 rtl8169_net_suspend(dev); |
|
5811 |
|
5812 return 0; |
|
5813 } |
|
5814 |
|
5815 static void __rtl8169_resume(struct net_device *dev) |
|
5816 { |
|
5817 struct rtl8169_private *tp = netdev_priv(dev); |
|
5818 |
|
5819 netif_device_attach(dev); |
|
5820 |
|
5821 rtl_pll_power_up(tp); |
|
5822 |
|
5823 rtl_lock_work(tp); |
|
5824 napi_enable(&tp->napi); |
|
5825 set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
|
5826 rtl_unlock_work(tp); |
|
5827 |
|
5828 rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
|
5829 } |
|
5830 |
|
5831 static int rtl8169_resume(struct device *device) |
|
5832 { |
|
5833 struct pci_dev *pdev = to_pci_dev(device); |
|
5834 struct net_device *dev = pci_get_drvdata(pdev); |
|
5835 struct rtl8169_private *tp = netdev_priv(dev); |
|
5836 |
|
5837 rtl8169_init_phy(dev, tp); |
|
5838 |
|
5839 if (netif_running(dev)) |
|
5840 __rtl8169_resume(dev); |
|
5841 |
|
5842 return 0; |
|
5843 } |
|
5844 |
|
5845 static int rtl8169_runtime_suspend(struct device *device) |
|
5846 { |
|
5847 struct pci_dev *pdev = to_pci_dev(device); |
|
5848 struct net_device *dev = pci_get_drvdata(pdev); |
|
5849 struct rtl8169_private *tp = netdev_priv(dev); |
|
5850 |
|
5851 if (!tp->TxDescArray) |
|
5852 return 0; |
|
5853 |
|
5854 rtl_lock_work(tp); |
|
5855 tp->saved_wolopts = __rtl8169_get_wol(tp); |
|
5856 __rtl8169_set_wol(tp, WAKE_ANY); |
|
5857 rtl_unlock_work(tp); |
|
5858 |
|
5859 rtl8169_net_suspend(dev); |
|
5860 |
|
5861 return 0; |
|
5862 } |
|
5863 |
|
5864 static int rtl8169_runtime_resume(struct device *device) |
|
5865 { |
|
5866 struct pci_dev *pdev = to_pci_dev(device); |
|
5867 struct net_device *dev = pci_get_drvdata(pdev); |
|
5868 struct rtl8169_private *tp = netdev_priv(dev); |
|
5869 |
|
5870 if (!tp->TxDescArray) |
|
5871 return 0; |
|
5872 |
|
5873 rtl_lock_work(tp); |
|
5874 __rtl8169_set_wol(tp, tp->saved_wolopts); |
|
5875 tp->saved_wolopts = 0; |
|
5876 rtl_unlock_work(tp); |
|
5877 |
|
5878 rtl8169_init_phy(dev, tp); |
|
5879 |
|
5880 __rtl8169_resume(dev); |
|
5881 |
|
5882 return 0; |
|
5883 } |
|
5884 |
|
5885 static int rtl8169_runtime_idle(struct device *device) |
|
5886 { |
|
5887 struct pci_dev *pdev = to_pci_dev(device); |
|
5888 struct net_device *dev = pci_get_drvdata(pdev); |
|
5889 struct rtl8169_private *tp = netdev_priv(dev); |
|
5890 |
|
5891 return tp->TxDescArray ? -EBUSY : 0; |
|
5892 } |
|
5893 |
|
5894 static const struct dev_pm_ops rtl8169_pm_ops = { |
|
5895 .suspend = rtl8169_suspend, |
|
5896 .resume = rtl8169_resume, |
|
5897 .freeze = rtl8169_suspend, |
|
5898 .thaw = rtl8169_resume, |
|
5899 .poweroff = rtl8169_suspend, |
|
5900 .restore = rtl8169_resume, |
|
5901 .runtime_suspend = rtl8169_runtime_suspend, |
|
5902 .runtime_resume = rtl8169_runtime_resume, |
|
5903 .runtime_idle = rtl8169_runtime_idle, |
|
5904 }; |
|
5905 |
|
5906 #define RTL8169_PM_OPS (&rtl8169_pm_ops) |
|
5907 |
|
5908 #else /* !CONFIG_PM */ |
|
5909 |
|
5910 #define RTL8169_PM_OPS NULL |
|
5911 |
|
5912 #endif /* !CONFIG_PM */ |
|
5913 |
|
5914 static void rtl_wol_shutdown_quirk(struct rtl8169_private *tp) |
|
5915 { |
|
5916 void __iomem *ioaddr = tp->mmio_addr; |
|
5917 |
|
5918 /* WoL fails with 8168b when the receiver is disabled. */ |
|
5919 switch (tp->mac_version) { |
|
5920 case RTL_GIGA_MAC_VER_11: |
|
5921 case RTL_GIGA_MAC_VER_12: |
|
5922 case RTL_GIGA_MAC_VER_17: |
|
5923 pci_clear_master(tp->pci_dev); |
|
5924 |
|
5925 RTL_W8(ChipCmd, CmdRxEnb); |
|
5926 /* PCI commit */ |
|
5927 RTL_R8(ChipCmd); |
|
5928 break; |
|
5929 default: |
|
5930 break; |
|
5931 } |
|
5932 } |
|
5933 |
|
5934 static void rtl_shutdown(struct pci_dev *pdev) |
|
5935 { |
|
5936 struct net_device *dev = pci_get_drvdata(pdev); |
|
5937 struct rtl8169_private *tp = netdev_priv(dev); |
|
5938 struct device *d = &pdev->dev; |
|
5939 |
|
5940 pm_runtime_get_sync(d); |
|
5941 |
|
5942 rtl8169_net_suspend(dev); |
|
5943 |
|
5944 /* Restore original MAC address */ |
|
5945 rtl_rar_set(tp, dev->perm_addr); |
|
5946 |
|
5947 rtl8169_hw_reset(tp); |
|
5948 |
|
5949 if (system_state == SYSTEM_POWER_OFF) { |
|
5950 if (__rtl8169_get_wol(tp) & WAKE_ANY) { |
|
5951 rtl_wol_suspend_quirk(tp); |
|
5952 rtl_wol_shutdown_quirk(tp); |
|
5953 } |
|
5954 |
|
5955 pci_wake_from_d3(pdev, true); |
|
5956 pci_set_power_state(pdev, PCI_D3hot); |
|
5957 } |
|
5958 |
|
5959 pm_runtime_put_noidle(d); |
|
5960 } |
|
5961 |
|
5962 static void __devexit rtl_remove_one(struct pci_dev *pdev) |
|
5963 { |
|
5964 struct net_device *dev = pci_get_drvdata(pdev); |
|
5965 struct rtl8169_private *tp = netdev_priv(dev); |
|
5966 |
|
5967 if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
|
5968 tp->mac_version == RTL_GIGA_MAC_VER_28 || |
|
5969 tp->mac_version == RTL_GIGA_MAC_VER_31) { |
|
5970 rtl8168_driver_stop(tp); |
|
5971 } |
|
5972 |
|
5973 cancel_work_sync(&tp->wk.work); |
|
5974 |
|
5975 netif_napi_del(&tp->napi); |
|
5976 |
|
5977 unregister_netdev(dev); |
|
5978 |
|
5979 rtl_release_firmware(tp); |
|
5980 |
|
5981 if (pci_dev_run_wake(pdev)) |
|
5982 pm_runtime_get_noresume(&pdev->dev); |
|
5983 |
|
5984 /* restore original MAC address */ |
|
5985 rtl_rar_set(tp, dev->perm_addr); |
|
5986 |
|
5987 rtl_disable_msi(pdev, tp); |
|
5988 rtl8169_release_board(pdev, dev, tp->mmio_addr); |
|
5989 pci_set_drvdata(pdev, NULL); |
|
5990 } |
|
5991 |
|
5992 static const struct net_device_ops rtl_netdev_ops = { |
|
5993 .ndo_open = rtl_open, |
|
5994 .ndo_stop = rtl8169_close, |
|
5995 .ndo_get_stats64 = rtl8169_get_stats64, |
|
5996 .ndo_start_xmit = rtl8169_start_xmit, |
|
5997 .ndo_tx_timeout = rtl8169_tx_timeout, |
|
5998 .ndo_validate_addr = eth_validate_addr, |
|
5999 .ndo_change_mtu = rtl8169_change_mtu, |
|
6000 .ndo_fix_features = rtl8169_fix_features, |
|
6001 .ndo_set_features = rtl8169_set_features, |
|
6002 .ndo_set_mac_address = rtl_set_mac_address, |
|
6003 .ndo_do_ioctl = rtl8169_ioctl, |
|
6004 .ndo_set_rx_mode = rtl_set_rx_mode, |
|
6005 #ifdef CONFIG_NET_POLL_CONTROLLER |
|
6006 .ndo_poll_controller = rtl8169_netpoll, |
|
6007 #endif |
|
6008 |
|
6009 }; |
|
6010 |
|
6011 static const struct rtl_cfg_info { |
|
6012 void (*hw_start)(struct net_device *); |
|
6013 unsigned int region; |
|
6014 unsigned int align; |
|
6015 u16 event_slow; |
|
6016 unsigned features; |
|
6017 u8 default_ver; |
|
6018 } rtl_cfg_infos [] = { |
|
6019 [RTL_CFG_0] = { |
|
6020 .hw_start = rtl_hw_start_8169, |
|
6021 .region = 1, |
|
6022 .align = 0, |
|
6023 .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver, |
|
6024 .features = RTL_FEATURE_GMII, |
|
6025 .default_ver = RTL_GIGA_MAC_VER_01, |
|
6026 }, |
|
6027 [RTL_CFG_1] = { |
|
6028 .hw_start = rtl_hw_start_8168, |
|
6029 .region = 2, |
|
6030 .align = 8, |
|
6031 .event_slow = SYSErr | LinkChg | RxOverflow, |
|
6032 .features = RTL_FEATURE_GMII | RTL_FEATURE_MSI, |
|
6033 .default_ver = RTL_GIGA_MAC_VER_11, |
|
6034 }, |
|
6035 [RTL_CFG_2] = { |
|
6036 .hw_start = rtl_hw_start_8101, |
|
6037 .region = 2, |
|
6038 .align = 8, |
|
6039 .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver | |
|
6040 PCSTimeout, |
|
6041 .features = RTL_FEATURE_MSI, |
|
6042 .default_ver = RTL_GIGA_MAC_VER_13, |
|
6043 } |
|
6044 }; |
|
6045 |
|
6046 /* Cfg9346_Unlock assumed. */ |
|
6047 static unsigned rtl_try_msi(struct rtl8169_private *tp, |
|
6048 const struct rtl_cfg_info *cfg) |
|
6049 { |
|
6050 void __iomem *ioaddr = tp->mmio_addr; |
|
6051 unsigned msi = 0; |
|
6052 u8 cfg2; |
|
6053 |
|
6054 cfg2 = RTL_R8(Config2) & ~MSIEnable; |
|
6055 if (cfg->features & RTL_FEATURE_MSI) { |
|
6056 if (pci_enable_msi(tp->pci_dev)) { |
|
6057 netif_info(tp, hw, tp->dev, "no MSI. Back to INTx.\n"); |
|
6058 } else { |
|
6059 cfg2 |= MSIEnable; |
|
6060 msi = RTL_FEATURE_MSI; |
|
6061 } |
|
6062 } |
|
6063 if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
|
6064 RTL_W8(Config2, cfg2); |
|
6065 return msi; |
|
6066 } |
|
6067 |
|
6068 static int __devinit |
|
6069 rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
|
6070 { |
|
6071 const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data; |
|
6072 const unsigned int region = cfg->region; |
|
6073 struct rtl8169_private *tp; |
|
6074 struct mii_if_info *mii; |
|
6075 struct net_device *dev; |
|
6076 void __iomem *ioaddr; |
|
6077 int chipset, i; |
|
6078 int rc; |
|
6079 |
|
6080 if (netif_msg_drv(&debug)) { |
|
6081 printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n", |
|
6082 MODULENAME, RTL8169_VERSION); |
|
6083 } |
|
6084 |
|
6085 dev = alloc_etherdev(sizeof (*tp)); |
|
6086 if (!dev) { |
|
6087 rc = -ENOMEM; |
|
6088 goto out; |
|
6089 } |
|
6090 |
|
6091 SET_NETDEV_DEV(dev, &pdev->dev); |
|
6092 dev->netdev_ops = &rtl_netdev_ops; |
|
6093 tp = netdev_priv(dev); |
|
6094 tp->dev = dev; |
|
6095 tp->pci_dev = pdev; |
|
6096 tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT); |
|
6097 |
|
6098 mii = &tp->mii; |
|
6099 mii->dev = dev; |
|
6100 mii->mdio_read = rtl_mdio_read; |
|
6101 mii->mdio_write = rtl_mdio_write; |
|
6102 mii->phy_id_mask = 0x1f; |
|
6103 mii->reg_num_mask = 0x1f; |
|
6104 mii->supports_gmii = !!(cfg->features & RTL_FEATURE_GMII); |
|
6105 |
|
6106 /* disable ASPM completely as that cause random device stop working |
|
6107 * problems as well as full system hangs for some PCIe devices users */ |
|
6108 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 | |
|
6109 PCIE_LINK_STATE_CLKPM); |
|
6110 |
|
6111 /* enable device (incl. PCI PM wakeup and hotplug setup) */ |
|
6112 rc = pci_enable_device(pdev); |
|
6113 if (rc < 0) { |
|
6114 netif_err(tp, probe, dev, "enable failure\n"); |
|
6115 goto err_out_free_dev_1; |
|
6116 } |
|
6117 |
|
6118 if (pci_set_mwi(pdev) < 0) |
|
6119 netif_info(tp, probe, dev, "Mem-Wr-Inval unavailable\n"); |
|
6120 |
|
6121 /* make sure PCI base addr 1 is MMIO */ |
|
6122 if (!(pci_resource_flags(pdev, region) & IORESOURCE_MEM)) { |
|
6123 netif_err(tp, probe, dev, |
|
6124 "region #%d not an MMIO resource, aborting\n", |
|
6125 region); |
|
6126 rc = -ENODEV; |
|
6127 goto err_out_mwi_2; |
|
6128 } |
|
6129 |
|
6130 /* check for weird/broken PCI region reporting */ |
|
6131 if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) { |
|
6132 netif_err(tp, probe, dev, |
|
6133 "Invalid PCI region size(s), aborting\n"); |
|
6134 rc = -ENODEV; |
|
6135 goto err_out_mwi_2; |
|
6136 } |
|
6137 |
|
6138 rc = pci_request_regions(pdev, MODULENAME); |
|
6139 if (rc < 0) { |
|
6140 netif_err(tp, probe, dev, "could not request regions\n"); |
|
6141 goto err_out_mwi_2; |
|
6142 } |
|
6143 |
|
6144 tp->cp_cmd = RxChkSum; |
|
6145 |
|
6146 if ((sizeof(dma_addr_t) > 4) && |
|
6147 !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && use_dac) { |
|
6148 tp->cp_cmd |= PCIDAC; |
|
6149 dev->features |= NETIF_F_HIGHDMA; |
|
6150 } else { |
|
6151 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
|
6152 if (rc < 0) { |
|
6153 netif_err(tp, probe, dev, "DMA configuration failed\n"); |
|
6154 goto err_out_free_res_3; |
|
6155 } |
|
6156 } |
|
6157 |
|
6158 /* ioremap MMIO region */ |
|
6159 ioaddr = ioremap(pci_resource_start(pdev, region), R8169_REGS_SIZE); |
|
6160 if (!ioaddr) { |
|
6161 netif_err(tp, probe, dev, "cannot remap MMIO, aborting\n"); |
|
6162 rc = -EIO; |
|
6163 goto err_out_free_res_3; |
|
6164 } |
|
6165 tp->mmio_addr = ioaddr; |
|
6166 |
|
6167 if (!pci_is_pcie(pdev)) |
|
6168 netif_info(tp, probe, dev, "not PCI Express\n"); |
|
6169 |
|
6170 /* Identify chip attached to board */ |
|
6171 rtl8169_get_mac_version(tp, dev, cfg->default_ver); |
|
6172 |
|
6173 rtl_init_rxcfg(tp); |
|
6174 |
|
6175 rtl_irq_disable(tp); |
|
6176 |
|
6177 rtl_hw_reset(tp); |
|
6178 |
|
6179 rtl_ack_events(tp, 0xffff); |
|
6180 |
|
6181 pci_set_master(pdev); |
|
6182 |
|
6183 /* |
|
6184 * Pretend we are using VLANs; This bypasses a nasty bug where |
|
6185 * Interrupts stop flowing on high load on 8110SCd controllers. |
|
6186 */ |
|
6187 if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
|
6188 tp->cp_cmd |= RxVlan; |
|
6189 |
|
6190 rtl_init_mdio_ops(tp); |
|
6191 rtl_init_pll_power_ops(tp); |
|
6192 rtl_init_jumbo_ops(tp); |
|
6193 |
|
6194 rtl8169_print_mac_version(tp); |
|
6195 |
|
6196 chipset = tp->mac_version; |
|
6197 tp->txd_version = rtl_chip_infos[chipset].txd_version; |
|
6198 |
|
6199 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
6200 RTL_W8(Config1, RTL_R8(Config1) | PMEnable); |
|
6201 RTL_W8(Config5, RTL_R8(Config5) & PMEStatus); |
|
6202 if ((RTL_R8(Config3) & (LinkUp | MagicPacket)) != 0) |
|
6203 tp->features |= RTL_FEATURE_WOL; |
|
6204 if ((RTL_R8(Config5) & (UWF | BWF | MWF)) != 0) |
|
6205 tp->features |= RTL_FEATURE_WOL; |
|
6206 tp->features |= rtl_try_msi(tp, cfg); |
|
6207 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
6208 |
|
6209 if (rtl_tbi_enabled(tp)) { |
|
6210 tp->set_speed = rtl8169_set_speed_tbi; |
|
6211 tp->get_settings = rtl8169_gset_tbi; |
|
6212 tp->phy_reset_enable = rtl8169_tbi_reset_enable; |
|
6213 tp->phy_reset_pending = rtl8169_tbi_reset_pending; |
|
6214 tp->link_ok = rtl8169_tbi_link_ok; |
|
6215 tp->do_ioctl = rtl_tbi_ioctl; |
|
6216 } else { |
|
6217 tp->set_speed = rtl8169_set_speed_xmii; |
|
6218 tp->get_settings = rtl8169_gset_xmii; |
|
6219 tp->phy_reset_enable = rtl8169_xmii_reset_enable; |
|
6220 tp->phy_reset_pending = rtl8169_xmii_reset_pending; |
|
6221 tp->link_ok = rtl8169_xmii_link_ok; |
|
6222 tp->do_ioctl = rtl_xmii_ioctl; |
|
6223 } |
|
6224 |
|
6225 mutex_init(&tp->wk.mutex); |
|
6226 |
|
6227 /* Get MAC address */ |
|
6228 for (i = 0; i < ETH_ALEN; i++) |
|
6229 dev->dev_addr[i] = RTL_R8(MAC0 + i); |
|
6230 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
|
6231 |
|
6232 SET_ETHTOOL_OPS(dev, &rtl8169_ethtool_ops); |
|
6233 dev->watchdog_timeo = RTL8169_TX_TIMEOUT; |
|
6234 |
|
6235 netif_napi_add(dev, &tp->napi, rtl8169_poll, R8169_NAPI_WEIGHT); |
|
6236 |
|
6237 /* don't enable SG, IP_CSUM and TSO by default - it might not work |
|
6238 * properly for all devices */ |
|
6239 dev->features |= NETIF_F_RXCSUM | |
|
6240 NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
|
6241 |
|
6242 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
|
6243 NETIF_F_RXCSUM | NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX; |
|
6244 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
|
6245 NETIF_F_HIGHDMA; |
|
6246 |
|
6247 if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
|
6248 /* 8110SCd requires hardware Rx VLAN - disallow toggling */ |
|
6249 dev->hw_features &= ~NETIF_F_HW_VLAN_RX; |
|
6250 |
|
6251 dev->hw_features |= NETIF_F_RXALL; |
|
6252 dev->hw_features |= NETIF_F_RXFCS; |
|
6253 |
|
6254 tp->hw_start = cfg->hw_start; |
|
6255 tp->event_slow = cfg->event_slow; |
|
6256 |
|
6257 tp->opts1_mask = (tp->mac_version != RTL_GIGA_MAC_VER_01) ? |
|
6258 ~(RxBOVF | RxFOVF) : ~0; |
|
6259 |
|
6260 init_timer(&tp->timer); |
|
6261 tp->timer.data = (unsigned long) dev; |
|
6262 tp->timer.function = rtl8169_phy_timer; |
|
6263 |
|
6264 tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
|
6265 |
|
6266 rc = register_netdev(dev); |
|
6267 if (rc < 0) |
|
6268 goto err_out_msi_4; |
|
6269 |
|
6270 pci_set_drvdata(pdev, dev); |
|
6271 |
|
6272 netif_info(tp, probe, dev, "%s at 0x%p, %pM, XID %08x IRQ %d\n", |
|
6273 rtl_chip_infos[chipset].name, ioaddr, dev->dev_addr, |
|
6274 (u32)(RTL_R32(TxConfig) & 0x9cf0f8ff), pdev->irq); |
|
6275 if (rtl_chip_infos[chipset].jumbo_max != JUMBO_1K) { |
|
6276 netif_info(tp, probe, dev, "jumbo features [frames: %d bytes, " |
|
6277 "tx checksumming: %s]\n", |
|
6278 rtl_chip_infos[chipset].jumbo_max, |
|
6279 rtl_chip_infos[chipset].jumbo_tx_csum ? "ok" : "ko"); |
|
6280 } |
|
6281 |
|
6282 if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
|
6283 tp->mac_version == RTL_GIGA_MAC_VER_28 || |
|
6284 tp->mac_version == RTL_GIGA_MAC_VER_31) { |
|
6285 rtl8168_driver_start(tp); |
|
6286 } |
|
6287 |
|
6288 device_set_wakeup_enable(&pdev->dev, tp->features & RTL_FEATURE_WOL); |
|
6289 |
|
6290 if (pci_dev_run_wake(pdev)) |
|
6291 pm_runtime_put_noidle(&pdev->dev); |
|
6292 |
|
6293 netif_carrier_off(dev); |
|
6294 |
|
6295 out: |
|
6296 return rc; |
|
6297 |
|
6298 err_out_msi_4: |
|
6299 netif_napi_del(&tp->napi); |
|
6300 rtl_disable_msi(pdev, tp); |
|
6301 iounmap(ioaddr); |
|
6302 err_out_free_res_3: |
|
6303 pci_release_regions(pdev); |
|
6304 err_out_mwi_2: |
|
6305 pci_clear_mwi(pdev); |
|
6306 pci_disable_device(pdev); |
|
6307 err_out_free_dev_1: |
|
6308 free_netdev(dev); |
|
6309 goto out; |
|
6310 } |
|
6311 |
|
6312 static struct pci_driver rtl8169_pci_driver = { |
|
6313 .name = MODULENAME, |
|
6314 .id_table = rtl8169_pci_tbl, |
|
6315 .probe = rtl_init_one, |
|
6316 .remove = __devexit_p(rtl_remove_one), |
|
6317 .shutdown = rtl_shutdown, |
|
6318 .driver.pm = RTL8169_PM_OPS, |
|
6319 }; |
|
6320 |
|
6321 static int __init rtl8169_init_module(void) |
|
6322 { |
|
6323 return pci_register_driver(&rtl8169_pci_driver); |
|
6324 } |
|
6325 |
|
6326 static void __exit rtl8169_cleanup_module(void) |
|
6327 { |
|
6328 pci_unregister_driver(&rtl8169_pci_driver); |
|
6329 } |
|
6330 |
|
6331 module_init(rtl8169_init_module); |
|
6332 module_exit(rtl8169_cleanup_module); |