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