|
1 /* |
|
2 * r8169.c: RealTek 8169/8168/8101 ethernet driver. |
|
3 * |
|
4 * Copyright (c) 2002 ShuChen <shuchen@realtek.com.tw> |
|
5 * Copyright (c) 2003 - 2007 Francois Romieu <romieu@fr.zoreil.com> |
|
6 * Copyright (c) a lot of people too. Please respect their work. |
|
7 * |
|
8 * See MAINTAINERS file for support contact information. |
|
9 * |
|
10 * vim: noexpandtab |
|
11 */ |
|
12 |
|
13 #include <linux/module.h> |
|
14 #include <linux/moduleparam.h> |
|
15 #include <linux/pci.h> |
|
16 #include <linux/netdevice.h> |
|
17 #include <linux/etherdevice.h> |
|
18 #include <linux/delay.h> |
|
19 #include <linux/ethtool.h> |
|
20 #include <linux/mii.h> |
|
21 #include <linux/if_vlan.h> |
|
22 #include <linux/crc32.h> |
|
23 #include <linux/in.h> |
|
24 #include <linux/ip.h> |
|
25 #include <linux/tcp.h> |
|
26 #include <linux/init.h> |
|
27 #include <linux/interrupt.h> |
|
28 #include <linux/dma-mapping.h> |
|
29 #include <linux/pm_runtime.h> |
|
30 #include <linux/firmware.h> |
|
31 #include <linux/pci-aspm.h> |
|
32 #include <linux/prefetch.h> |
|
33 |
|
34 #include <asm/io.h> |
|
35 #include <asm/irq.h> |
|
36 |
|
37 #include "../globals.h" |
|
38 #include "ecdev.h" |
|
39 |
|
40 #define RTL8169_VERSION "2.3LK-NAPI" |
|
41 #define MODULENAME "ec_r8169" |
|
42 #define PFX MODULENAME ": " |
|
43 |
|
44 #define FIRMWARE_8168D_1 "rtl_nic/rtl8168d-1.fw" |
|
45 #define FIRMWARE_8168D_2 "rtl_nic/rtl8168d-2.fw" |
|
46 #define FIRMWARE_8168E_1 "rtl_nic/rtl8168e-1.fw" |
|
47 #define FIRMWARE_8168E_2 "rtl_nic/rtl8168e-2.fw" |
|
48 #define FIRMWARE_8168E_3 "rtl_nic/rtl8168e-3.fw" |
|
49 #define FIRMWARE_8168F_1 "rtl_nic/rtl8168f-1.fw" |
|
50 #define FIRMWARE_8168F_2 "rtl_nic/rtl8168f-2.fw" |
|
51 #define FIRMWARE_8105E_1 "rtl_nic/rtl8105e-1.fw" |
|
52 #define FIRMWARE_8402_1 "rtl_nic/rtl8402-1.fw" |
|
53 #define FIRMWARE_8411_1 "rtl_nic/rtl8411-1.fw" |
|
54 #define FIRMWARE_8411_2 "rtl_nic/rtl8411-2.fw" |
|
55 #define FIRMWARE_8106E_1 "rtl_nic/rtl8106e-1.fw" |
|
56 #define FIRMWARE_8106E_2 "rtl_nic/rtl8106e-2.fw" |
|
57 #define FIRMWARE_8168G_2 "rtl_nic/rtl8168g-2.fw" |
|
58 #define FIRMWARE_8168G_3 "rtl_nic/rtl8168g-3.fw" |
|
59 |
|
60 #ifdef RTL8169_DEBUG |
|
61 #define assert(expr) \ |
|
62 if (!(expr)) { \ |
|
63 printk( "Assertion failed! %s,%s,%s,line=%d\n", \ |
|
64 #expr,__FILE__,__func__,__LINE__); \ |
|
65 } |
|
66 #define dprintk(fmt, args...) \ |
|
67 do { printk(KERN_DEBUG PFX fmt, ## args); } while (0) |
|
68 #else |
|
69 #define assert(expr) do {} while (0) |
|
70 #define dprintk(fmt, args...) do {} while (0) |
|
71 #endif /* RTL8169_DEBUG */ |
|
72 |
|
73 #define R8169_MSG_DEFAULT \ |
|
74 (NETIF_MSG_DRV | NETIF_MSG_PROBE | NETIF_MSG_IFUP | NETIF_MSG_IFDOWN) |
|
75 |
|
76 #define TX_SLOTS_AVAIL(tp) \ |
|
77 (tp->dirty_tx + NUM_TX_DESC - tp->cur_tx) |
|
78 |
|
79 /* A skbuff with nr_frags needs nr_frags+1 entries in the tx queue */ |
|
80 #define TX_FRAGS_READY_FOR(tp,nr_frags) \ |
|
81 (TX_SLOTS_AVAIL(tp) >= (nr_frags + 1)) |
|
82 |
|
83 /* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). |
|
84 The RTL chips use a 64 element hash table based on the Ethernet CRC. */ |
|
85 static const int multicast_filter_limit = 32; |
|
86 |
|
87 #define MAX_READ_REQUEST_SHIFT 12 |
|
88 #define TX_DMA_BURST 7 /* Maximum PCI burst, '7' is unlimited */ |
|
89 #define InterFrameGap 0x03 /* 3 means InterFrameGap = the shortest one */ |
|
90 |
|
91 #define R8169_REGS_SIZE 256 |
|
92 #define R8169_NAPI_WEIGHT 64 |
|
93 #define NUM_TX_DESC 64 /* Number of Tx descriptor registers */ |
|
94 #define NUM_RX_DESC 256U /* Number of Rx descriptor registers */ |
|
95 #define R8169_TX_RING_BYTES (NUM_TX_DESC * sizeof(struct TxDesc)) |
|
96 #define R8169_RX_RING_BYTES (NUM_RX_DESC * sizeof(struct RxDesc)) |
|
97 |
|
98 #define RTL8169_TX_TIMEOUT (6*HZ) |
|
99 #define RTL8169_PHY_TIMEOUT (10*HZ) |
|
100 |
|
101 /* write/read MMIO register */ |
|
102 #define RTL_W8(reg, val8) writeb ((val8), ioaddr + (reg)) |
|
103 #define RTL_W16(reg, val16) writew ((val16), ioaddr + (reg)) |
|
104 #define RTL_W32(reg, val32) writel ((val32), ioaddr + (reg)) |
|
105 #define RTL_R8(reg) readb (ioaddr + (reg)) |
|
106 #define RTL_R16(reg) readw (ioaddr + (reg)) |
|
107 #define RTL_R32(reg) readl (ioaddr + (reg)) |
|
108 |
|
109 enum mac_version { |
|
110 RTL_GIGA_MAC_VER_01 = 0, |
|
111 RTL_GIGA_MAC_VER_02, |
|
112 RTL_GIGA_MAC_VER_03, |
|
113 RTL_GIGA_MAC_VER_04, |
|
114 RTL_GIGA_MAC_VER_05, |
|
115 RTL_GIGA_MAC_VER_06, |
|
116 RTL_GIGA_MAC_VER_07, |
|
117 RTL_GIGA_MAC_VER_08, |
|
118 RTL_GIGA_MAC_VER_09, |
|
119 RTL_GIGA_MAC_VER_10, |
|
120 RTL_GIGA_MAC_VER_11, |
|
121 RTL_GIGA_MAC_VER_12, |
|
122 RTL_GIGA_MAC_VER_13, |
|
123 RTL_GIGA_MAC_VER_14, |
|
124 RTL_GIGA_MAC_VER_15, |
|
125 RTL_GIGA_MAC_VER_16, |
|
126 RTL_GIGA_MAC_VER_17, |
|
127 RTL_GIGA_MAC_VER_18, |
|
128 RTL_GIGA_MAC_VER_19, |
|
129 RTL_GIGA_MAC_VER_20, |
|
130 RTL_GIGA_MAC_VER_21, |
|
131 RTL_GIGA_MAC_VER_22, |
|
132 RTL_GIGA_MAC_VER_23, |
|
133 RTL_GIGA_MAC_VER_24, |
|
134 RTL_GIGA_MAC_VER_25, |
|
135 RTL_GIGA_MAC_VER_26, |
|
136 RTL_GIGA_MAC_VER_27, |
|
137 RTL_GIGA_MAC_VER_28, |
|
138 RTL_GIGA_MAC_VER_29, |
|
139 RTL_GIGA_MAC_VER_30, |
|
140 RTL_GIGA_MAC_VER_31, |
|
141 RTL_GIGA_MAC_VER_32, |
|
142 RTL_GIGA_MAC_VER_33, |
|
143 RTL_GIGA_MAC_VER_34, |
|
144 RTL_GIGA_MAC_VER_35, |
|
145 RTL_GIGA_MAC_VER_36, |
|
146 RTL_GIGA_MAC_VER_37, |
|
147 RTL_GIGA_MAC_VER_38, |
|
148 RTL_GIGA_MAC_VER_39, |
|
149 RTL_GIGA_MAC_VER_40, |
|
150 RTL_GIGA_MAC_VER_41, |
|
151 RTL_GIGA_MAC_VER_42, |
|
152 RTL_GIGA_MAC_VER_43, |
|
153 RTL_GIGA_MAC_VER_44, |
|
154 RTL_GIGA_MAC_NONE = 0xff, |
|
155 }; |
|
156 |
|
157 enum rtl_tx_desc_version { |
|
158 RTL_TD_0 = 0, |
|
159 RTL_TD_1 = 1, |
|
160 }; |
|
161 |
|
162 #define JUMBO_1K ETH_DATA_LEN |
|
163 #define JUMBO_4K (4*1024 - ETH_HLEN - 2) |
|
164 #define JUMBO_6K (6*1024 - ETH_HLEN - 2) |
|
165 #define JUMBO_7K (7*1024 - ETH_HLEN - 2) |
|
166 #define JUMBO_9K (9*1024 - ETH_HLEN - 2) |
|
167 |
|
168 #define _R(NAME,TD,FW,SZ,B) { \ |
|
169 .name = NAME, \ |
|
170 .txd_version = TD, \ |
|
171 .fw_name = FW, \ |
|
172 .jumbo_max = SZ, \ |
|
173 .jumbo_tx_csum = B \ |
|
174 } |
|
175 |
|
176 static const struct { |
|
177 const char *name; |
|
178 enum rtl_tx_desc_version txd_version; |
|
179 const char *fw_name; |
|
180 u16 jumbo_max; |
|
181 bool jumbo_tx_csum; |
|
182 } rtl_chip_infos[] = { |
|
183 /* PCI devices. */ |
|
184 [RTL_GIGA_MAC_VER_01] = |
|
185 _R("RTL8169", RTL_TD_0, NULL, JUMBO_7K, true), |
|
186 [RTL_GIGA_MAC_VER_02] = |
|
187 _R("RTL8169s", RTL_TD_0, NULL, JUMBO_7K, true), |
|
188 [RTL_GIGA_MAC_VER_03] = |
|
189 _R("RTL8110s", RTL_TD_0, NULL, JUMBO_7K, true), |
|
190 [RTL_GIGA_MAC_VER_04] = |
|
191 _R("RTL8169sb/8110sb", RTL_TD_0, NULL, JUMBO_7K, true), |
|
192 [RTL_GIGA_MAC_VER_05] = |
|
193 _R("RTL8169sc/8110sc", RTL_TD_0, NULL, JUMBO_7K, true), |
|
194 [RTL_GIGA_MAC_VER_06] = |
|
195 _R("RTL8169sc/8110sc", RTL_TD_0, NULL, JUMBO_7K, true), |
|
196 /* PCI-E devices. */ |
|
197 [RTL_GIGA_MAC_VER_07] = |
|
198 _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K, true), |
|
199 [RTL_GIGA_MAC_VER_08] = |
|
200 _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K, true), |
|
201 [RTL_GIGA_MAC_VER_09] = |
|
202 _R("RTL8102e", RTL_TD_1, NULL, JUMBO_1K, true), |
|
203 [RTL_GIGA_MAC_VER_10] = |
|
204 _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), |
|
205 [RTL_GIGA_MAC_VER_11] = |
|
206 _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K, false), |
|
207 [RTL_GIGA_MAC_VER_12] = |
|
208 _R("RTL8168b/8111b", RTL_TD_0, NULL, JUMBO_4K, false), |
|
209 [RTL_GIGA_MAC_VER_13] = |
|
210 _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), |
|
211 [RTL_GIGA_MAC_VER_14] = |
|
212 _R("RTL8100e", RTL_TD_0, NULL, JUMBO_1K, true), |
|
213 [RTL_GIGA_MAC_VER_15] = |
|
214 _R("RTL8100e", RTL_TD_0, NULL, JUMBO_1K, true), |
|
215 [RTL_GIGA_MAC_VER_16] = |
|
216 _R("RTL8101e", RTL_TD_0, NULL, JUMBO_1K, true), |
|
217 [RTL_GIGA_MAC_VER_17] = |
|
218 _R("RTL8168b/8111b", RTL_TD_1, NULL, JUMBO_4K, false), |
|
219 [RTL_GIGA_MAC_VER_18] = |
|
220 _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), |
|
221 [RTL_GIGA_MAC_VER_19] = |
|
222 _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
|
223 [RTL_GIGA_MAC_VER_20] = |
|
224 _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
|
225 [RTL_GIGA_MAC_VER_21] = |
|
226 _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
|
227 [RTL_GIGA_MAC_VER_22] = |
|
228 _R("RTL8168c/8111c", RTL_TD_1, NULL, JUMBO_6K, false), |
|
229 [RTL_GIGA_MAC_VER_23] = |
|
230 _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), |
|
231 [RTL_GIGA_MAC_VER_24] = |
|
232 _R("RTL8168cp/8111cp", RTL_TD_1, NULL, JUMBO_6K, false), |
|
233 [RTL_GIGA_MAC_VER_25] = |
|
234 _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_1, |
|
235 JUMBO_9K, false), |
|
236 [RTL_GIGA_MAC_VER_26] = |
|
237 _R("RTL8168d/8111d", RTL_TD_1, FIRMWARE_8168D_2, |
|
238 JUMBO_9K, false), |
|
239 [RTL_GIGA_MAC_VER_27] = |
|
240 _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K, false), |
|
241 [RTL_GIGA_MAC_VER_28] = |
|
242 _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K, false), |
|
243 [RTL_GIGA_MAC_VER_29] = |
|
244 _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1, |
|
245 JUMBO_1K, true), |
|
246 [RTL_GIGA_MAC_VER_30] = |
|
247 _R("RTL8105e", RTL_TD_1, FIRMWARE_8105E_1, |
|
248 JUMBO_1K, true), |
|
249 [RTL_GIGA_MAC_VER_31] = |
|
250 _R("RTL8168dp/8111dp", RTL_TD_1, NULL, JUMBO_9K, false), |
|
251 [RTL_GIGA_MAC_VER_32] = |
|
252 _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_1, |
|
253 JUMBO_9K, false), |
|
254 [RTL_GIGA_MAC_VER_33] = |
|
255 _R("RTL8168e/8111e", RTL_TD_1, FIRMWARE_8168E_2, |
|
256 JUMBO_9K, false), |
|
257 [RTL_GIGA_MAC_VER_34] = |
|
258 _R("RTL8168evl/8111evl",RTL_TD_1, FIRMWARE_8168E_3, |
|
259 JUMBO_9K, false), |
|
260 [RTL_GIGA_MAC_VER_35] = |
|
261 _R("RTL8168f/8111f", RTL_TD_1, FIRMWARE_8168F_1, |
|
262 JUMBO_9K, false), |
|
263 [RTL_GIGA_MAC_VER_36] = |
|
264 _R("RTL8168f/8111f", RTL_TD_1, FIRMWARE_8168F_2, |
|
265 JUMBO_9K, false), |
|
266 [RTL_GIGA_MAC_VER_37] = |
|
267 _R("RTL8402", RTL_TD_1, FIRMWARE_8402_1, |
|
268 JUMBO_1K, true), |
|
269 [RTL_GIGA_MAC_VER_38] = |
|
270 _R("RTL8411", RTL_TD_1, FIRMWARE_8411_1, |
|
271 JUMBO_9K, false), |
|
272 [RTL_GIGA_MAC_VER_39] = |
|
273 _R("RTL8106e", RTL_TD_1, FIRMWARE_8106E_1, |
|
274 JUMBO_1K, true), |
|
275 [RTL_GIGA_MAC_VER_40] = |
|
276 _R("RTL8168g/8111g", RTL_TD_1, FIRMWARE_8168G_2, |
|
277 JUMBO_9K, false), |
|
278 [RTL_GIGA_MAC_VER_41] = |
|
279 _R("RTL8168g/8111g", RTL_TD_1, NULL, JUMBO_9K, false), |
|
280 [RTL_GIGA_MAC_VER_42] = |
|
281 _R("RTL8168g/8111g", RTL_TD_1, FIRMWARE_8168G_3, |
|
282 JUMBO_9K, false), |
|
283 [RTL_GIGA_MAC_VER_43] = |
|
284 _R("RTL8106e", RTL_TD_1, FIRMWARE_8106E_2, |
|
285 JUMBO_1K, true), |
|
286 [RTL_GIGA_MAC_VER_44] = |
|
287 _R("RTL8411", RTL_TD_1, FIRMWARE_8411_2, |
|
288 JUMBO_9K, false), |
|
289 }; |
|
290 #undef _R |
|
291 |
|
292 enum cfg_version { |
|
293 RTL_CFG_0 = 0x00, |
|
294 RTL_CFG_1, |
|
295 RTL_CFG_2 |
|
296 }; |
|
297 |
|
298 static DEFINE_PCI_DEVICE_TABLE(rtl8169_pci_tbl) = { |
|
299 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8129), 0, 0, RTL_CFG_0 }, |
|
300 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8136), 0, 0, RTL_CFG_2 }, |
|
301 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8167), 0, 0, RTL_CFG_0 }, |
|
302 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8168), 0, 0, RTL_CFG_1 }, |
|
303 { PCI_DEVICE(PCI_VENDOR_ID_REALTEK, 0x8169), 0, 0, RTL_CFG_0 }, |
|
304 { PCI_VENDOR_ID_DLINK, 0x4300, |
|
305 PCI_VENDOR_ID_DLINK, 0x4b10, 0, 0, RTL_CFG_1 }, |
|
306 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4300), 0, 0, RTL_CFG_0 }, |
|
307 { PCI_DEVICE(PCI_VENDOR_ID_DLINK, 0x4302), 0, 0, RTL_CFG_0 }, |
|
308 { PCI_DEVICE(PCI_VENDOR_ID_AT, 0xc107), 0, 0, RTL_CFG_0 }, |
|
309 { PCI_DEVICE(0x16ec, 0x0116), 0, 0, RTL_CFG_0 }, |
|
310 { PCI_VENDOR_ID_LINKSYS, 0x1032, |
|
311 PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 }, |
|
312 { 0x0001, 0x8168, |
|
313 PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 }, |
|
314 {0,}, |
|
315 }; |
|
316 |
|
317 /* prevent driver from being loaded automatically */ |
|
318 //MODULE_DEVICE_TABLE(pci, rtl8169_pci_tbl); |
|
319 |
|
320 static int rx_buf_sz = 16383; |
|
321 static int use_dac; |
|
322 static struct { |
|
323 u32 msg_enable; |
|
324 } debug = { -1 }; |
|
325 |
|
326 enum rtl_registers { |
|
327 MAC0 = 0, /* Ethernet hardware address. */ |
|
328 MAC4 = 4, |
|
329 MAR0 = 8, /* Multicast filter. */ |
|
330 CounterAddrLow = 0x10, |
|
331 CounterAddrHigh = 0x14, |
|
332 TxDescStartAddrLow = 0x20, |
|
333 TxDescStartAddrHigh = 0x24, |
|
334 TxHDescStartAddrLow = 0x28, |
|
335 TxHDescStartAddrHigh = 0x2c, |
|
336 FLASH = 0x30, |
|
337 ERSR = 0x36, |
|
338 ChipCmd = 0x37, |
|
339 TxPoll = 0x38, |
|
340 IntrMask = 0x3c, |
|
341 IntrStatus = 0x3e, |
|
342 |
|
343 TxConfig = 0x40, |
|
344 #define TXCFG_AUTO_FIFO (1 << 7) /* 8111e-vl */ |
|
345 #define TXCFG_EMPTY (1 << 11) /* 8111e-vl */ |
|
346 |
|
347 RxConfig = 0x44, |
|
348 #define RX128_INT_EN (1 << 15) /* 8111c and later */ |
|
349 #define RX_MULTI_EN (1 << 14) /* 8111c only */ |
|
350 #define RXCFG_FIFO_SHIFT 13 |
|
351 /* No threshold before first PCI xfer */ |
|
352 #define RX_FIFO_THRESH (7 << RXCFG_FIFO_SHIFT) |
|
353 #define RX_EARLY_OFF (1 << 11) |
|
354 #define RXCFG_DMA_SHIFT 8 |
|
355 /* Unlimited maximum PCI burst. */ |
|
356 #define RX_DMA_BURST (7 << RXCFG_DMA_SHIFT) |
|
357 |
|
358 RxMissed = 0x4c, |
|
359 Cfg9346 = 0x50, |
|
360 Config0 = 0x51, |
|
361 Config1 = 0x52, |
|
362 Config2 = 0x53, |
|
363 #define PME_SIGNAL (1 << 5) /* 8168c and later */ |
|
364 |
|
365 Config3 = 0x54, |
|
366 Config4 = 0x55, |
|
367 Config5 = 0x56, |
|
368 MultiIntr = 0x5c, |
|
369 PHYAR = 0x60, |
|
370 PHYstatus = 0x6c, |
|
371 RxMaxSize = 0xda, |
|
372 CPlusCmd = 0xe0, |
|
373 IntrMitigate = 0xe2, |
|
374 RxDescAddrLow = 0xe4, |
|
375 RxDescAddrHigh = 0xe8, |
|
376 EarlyTxThres = 0xec, /* 8169. Unit of 32 bytes. */ |
|
377 |
|
378 #define NoEarlyTx 0x3f /* Max value : no early transmit. */ |
|
379 |
|
380 MaxTxPacketSize = 0xec, /* 8101/8168. Unit of 128 bytes. */ |
|
381 |
|
382 #define TxPacketMax (8064 >> 7) |
|
383 #define EarlySize 0x27 |
|
384 |
|
385 FuncEvent = 0xf0, |
|
386 FuncEventMask = 0xf4, |
|
387 FuncPresetState = 0xf8, |
|
388 FuncForceEvent = 0xfc, |
|
389 }; |
|
390 |
|
391 enum rtl8110_registers { |
|
392 TBICSR = 0x64, |
|
393 TBI_ANAR = 0x68, |
|
394 TBI_LPAR = 0x6a, |
|
395 }; |
|
396 |
|
397 enum rtl8168_8101_registers { |
|
398 CSIDR = 0x64, |
|
399 CSIAR = 0x68, |
|
400 #define CSIAR_FLAG 0x80000000 |
|
401 #define CSIAR_WRITE_CMD 0x80000000 |
|
402 #define CSIAR_BYTE_ENABLE 0x0f |
|
403 #define CSIAR_BYTE_ENABLE_SHIFT 12 |
|
404 #define CSIAR_ADDR_MASK 0x0fff |
|
405 #define CSIAR_FUNC_CARD 0x00000000 |
|
406 #define CSIAR_FUNC_SDIO 0x00010000 |
|
407 #define CSIAR_FUNC_NIC 0x00020000 |
|
408 #define CSIAR_FUNC_NIC2 0x00010000 |
|
409 PMCH = 0x6f, |
|
410 EPHYAR = 0x80, |
|
411 #define EPHYAR_FLAG 0x80000000 |
|
412 #define EPHYAR_WRITE_CMD 0x80000000 |
|
413 #define EPHYAR_REG_MASK 0x1f |
|
414 #define EPHYAR_REG_SHIFT 16 |
|
415 #define EPHYAR_DATA_MASK 0xffff |
|
416 DLLPR = 0xd0, |
|
417 #define PFM_EN (1 << 6) |
|
418 DBG_REG = 0xd1, |
|
419 #define FIX_NAK_1 (1 << 4) |
|
420 #define FIX_NAK_2 (1 << 3) |
|
421 TWSI = 0xd2, |
|
422 MCU = 0xd3, |
|
423 #define NOW_IS_OOB (1 << 7) |
|
424 #define TX_EMPTY (1 << 5) |
|
425 #define RX_EMPTY (1 << 4) |
|
426 #define RXTX_EMPTY (TX_EMPTY | RX_EMPTY) |
|
427 #define EN_NDP (1 << 3) |
|
428 #define EN_OOB_RESET (1 << 2) |
|
429 #define LINK_LIST_RDY (1 << 1) |
|
430 EFUSEAR = 0xdc, |
|
431 #define EFUSEAR_FLAG 0x80000000 |
|
432 #define EFUSEAR_WRITE_CMD 0x80000000 |
|
433 #define EFUSEAR_READ_CMD 0x00000000 |
|
434 #define EFUSEAR_REG_MASK 0x03ff |
|
435 #define EFUSEAR_REG_SHIFT 8 |
|
436 #define EFUSEAR_DATA_MASK 0xff |
|
437 }; |
|
438 |
|
439 enum rtl8168_registers { |
|
440 LED_FREQ = 0x1a, |
|
441 EEE_LED = 0x1b, |
|
442 ERIDR = 0x70, |
|
443 ERIAR = 0x74, |
|
444 #define ERIAR_FLAG 0x80000000 |
|
445 #define ERIAR_WRITE_CMD 0x80000000 |
|
446 #define ERIAR_READ_CMD 0x00000000 |
|
447 #define ERIAR_ADDR_BYTE_ALIGN 4 |
|
448 #define ERIAR_TYPE_SHIFT 16 |
|
449 #define ERIAR_EXGMAC (0x00 << ERIAR_TYPE_SHIFT) |
|
450 #define ERIAR_MSIX (0x01 << ERIAR_TYPE_SHIFT) |
|
451 #define ERIAR_ASF (0x02 << ERIAR_TYPE_SHIFT) |
|
452 #define ERIAR_MASK_SHIFT 12 |
|
453 #define ERIAR_MASK_0001 (0x1 << ERIAR_MASK_SHIFT) |
|
454 #define ERIAR_MASK_0011 (0x3 << ERIAR_MASK_SHIFT) |
|
455 #define ERIAR_MASK_0101 (0x5 << ERIAR_MASK_SHIFT) |
|
456 #define ERIAR_MASK_1111 (0xf << ERIAR_MASK_SHIFT) |
|
457 EPHY_RXER_NUM = 0x7c, |
|
458 OCPDR = 0xb0, /* OCP GPHY access */ |
|
459 #define OCPDR_WRITE_CMD 0x80000000 |
|
460 #define OCPDR_READ_CMD 0x00000000 |
|
461 #define OCPDR_REG_MASK 0x7f |
|
462 #define OCPDR_GPHY_REG_SHIFT 16 |
|
463 #define OCPDR_DATA_MASK 0xffff |
|
464 OCPAR = 0xb4, |
|
465 #define OCPAR_FLAG 0x80000000 |
|
466 #define OCPAR_GPHY_WRITE_CMD 0x8000f060 |
|
467 #define OCPAR_GPHY_READ_CMD 0x0000f060 |
|
468 GPHY_OCP = 0xb8, |
|
469 RDSAR1 = 0xd0, /* 8168c only. Undocumented on 8168dp */ |
|
470 MISC = 0xf0, /* 8168e only. */ |
|
471 #define TXPLA_RST (1 << 29) |
|
472 #define DISABLE_LAN_EN (1 << 23) /* Enable GPIO pin */ |
|
473 #define PWM_EN (1 << 22) |
|
474 #define RXDV_GATED_EN (1 << 19) |
|
475 #define EARLY_TALLY_EN (1 << 16) |
|
476 }; |
|
477 |
|
478 enum rtl_register_content { |
|
479 /* InterruptStatusBits */ |
|
480 SYSErr = 0x8000, |
|
481 PCSTimeout = 0x4000, |
|
482 SWInt = 0x0100, |
|
483 TxDescUnavail = 0x0080, |
|
484 RxFIFOOver = 0x0040, |
|
485 LinkChg = 0x0020, |
|
486 RxOverflow = 0x0010, |
|
487 TxErr = 0x0008, |
|
488 TxOK = 0x0004, |
|
489 RxErr = 0x0002, |
|
490 RxOK = 0x0001, |
|
491 |
|
492 /* RxStatusDesc */ |
|
493 RxBOVF = (1 << 24), |
|
494 RxFOVF = (1 << 23), |
|
495 RxRWT = (1 << 22), |
|
496 RxRES = (1 << 21), |
|
497 RxRUNT = (1 << 20), |
|
498 RxCRC = (1 << 19), |
|
499 |
|
500 /* ChipCmdBits */ |
|
501 StopReq = 0x80, |
|
502 CmdReset = 0x10, |
|
503 CmdRxEnb = 0x08, |
|
504 CmdTxEnb = 0x04, |
|
505 RxBufEmpty = 0x01, |
|
506 |
|
507 /* TXPoll register p.5 */ |
|
508 HPQ = 0x80, /* Poll cmd on the high prio queue */ |
|
509 NPQ = 0x40, /* Poll cmd on the low prio queue */ |
|
510 FSWInt = 0x01, /* Forced software interrupt */ |
|
511 |
|
512 /* Cfg9346Bits */ |
|
513 Cfg9346_Lock = 0x00, |
|
514 Cfg9346_Unlock = 0xc0, |
|
515 |
|
516 /* rx_mode_bits */ |
|
517 AcceptErr = 0x20, |
|
518 AcceptRunt = 0x10, |
|
519 AcceptBroadcast = 0x08, |
|
520 AcceptMulticast = 0x04, |
|
521 AcceptMyPhys = 0x02, |
|
522 AcceptAllPhys = 0x01, |
|
523 #define RX_CONFIG_ACCEPT_MASK 0x3f |
|
524 |
|
525 /* TxConfigBits */ |
|
526 TxInterFrameGapShift = 24, |
|
527 TxDMAShift = 8, /* DMA burst value (0-7) is shift this many bits */ |
|
528 |
|
529 /* Config1 register p.24 */ |
|
530 LEDS1 = (1 << 7), |
|
531 LEDS0 = (1 << 6), |
|
532 Speed_down = (1 << 4), |
|
533 MEMMAP = (1 << 3), |
|
534 IOMAP = (1 << 2), |
|
535 VPD = (1 << 1), |
|
536 PMEnable = (1 << 0), /* Power Management Enable */ |
|
537 |
|
538 /* Config2 register p. 25 */ |
|
539 ClkReqEn = (1 << 7), /* Clock Request Enable */ |
|
540 MSIEnable = (1 << 5), /* 8169 only. Reserved in the 8168. */ |
|
541 PCI_Clock_66MHz = 0x01, |
|
542 PCI_Clock_33MHz = 0x00, |
|
543 |
|
544 /* Config3 register p.25 */ |
|
545 MagicPacket = (1 << 5), /* Wake up when receives a Magic Packet */ |
|
546 LinkUp = (1 << 4), /* Wake up when the cable connection is re-established */ |
|
547 Jumbo_En0 = (1 << 2), /* 8168 only. Reserved in the 8168b */ |
|
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 case RTL_GIGA_MAC_VER_41: |
|
4260 case RTL_GIGA_MAC_VER_42: |
|
4261 case RTL_GIGA_MAC_VER_43: |
|
4262 case RTL_GIGA_MAC_VER_44: |
|
4263 RTL_W32(RxConfig, RX128_INT_EN | RX_DMA_BURST | RX_EARLY_OFF); |
|
4264 break; |
|
4265 default: |
|
4266 RTL_W32(RxConfig, RX128_INT_EN | RX_DMA_BURST); |
|
4267 break; |
|
4268 } |
|
4269 } |
|
4270 |
|
4271 static void rtl8169_init_ring_indexes(struct rtl8169_private *tp) |
|
4272 { |
|
4273 tp->dirty_tx = tp->cur_tx = tp->cur_rx = 0; |
|
4274 } |
|
4275 |
|
4276 static void rtl_hw_jumbo_enable(struct rtl8169_private *tp) |
|
4277 { |
|
4278 void __iomem *ioaddr = tp->mmio_addr; |
|
4279 |
|
4280 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
4281 rtl_generic_op(tp, tp->jumbo_ops.enable); |
|
4282 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
4283 } |
|
4284 |
|
4285 static void rtl_hw_jumbo_disable(struct rtl8169_private *tp) |
|
4286 { |
|
4287 void __iomem *ioaddr = tp->mmio_addr; |
|
4288 |
|
4289 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
4290 rtl_generic_op(tp, tp->jumbo_ops.disable); |
|
4291 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
4292 } |
|
4293 |
|
4294 static void r8168c_hw_jumbo_enable(struct rtl8169_private *tp) |
|
4295 { |
|
4296 void __iomem *ioaddr = tp->mmio_addr; |
|
4297 |
|
4298 RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0); |
|
4299 RTL_W8(Config4, RTL_R8(Config4) | Jumbo_En1); |
|
4300 rtl_tx_performance_tweak(tp->pci_dev, 0x2 << MAX_READ_REQUEST_SHIFT); |
|
4301 } |
|
4302 |
|
4303 static void r8168c_hw_jumbo_disable(struct rtl8169_private *tp) |
|
4304 { |
|
4305 void __iomem *ioaddr = tp->mmio_addr; |
|
4306 |
|
4307 RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0); |
|
4308 RTL_W8(Config4, RTL_R8(Config4) & ~Jumbo_En1); |
|
4309 rtl_tx_performance_tweak(tp->pci_dev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
4310 } |
|
4311 |
|
4312 static void r8168dp_hw_jumbo_enable(struct rtl8169_private *tp) |
|
4313 { |
|
4314 void __iomem *ioaddr = tp->mmio_addr; |
|
4315 |
|
4316 RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0); |
|
4317 } |
|
4318 |
|
4319 static void r8168dp_hw_jumbo_disable(struct rtl8169_private *tp) |
|
4320 { |
|
4321 void __iomem *ioaddr = tp->mmio_addr; |
|
4322 |
|
4323 RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0); |
|
4324 } |
|
4325 |
|
4326 static void r8168e_hw_jumbo_enable(struct rtl8169_private *tp) |
|
4327 { |
|
4328 void __iomem *ioaddr = tp->mmio_addr; |
|
4329 |
|
4330 RTL_W8(MaxTxPacketSize, 0x3f); |
|
4331 RTL_W8(Config3, RTL_R8(Config3) | Jumbo_En0); |
|
4332 RTL_W8(Config4, RTL_R8(Config4) | 0x01); |
|
4333 rtl_tx_performance_tweak(tp->pci_dev, 0x2 << MAX_READ_REQUEST_SHIFT); |
|
4334 } |
|
4335 |
|
4336 static void r8168e_hw_jumbo_disable(struct rtl8169_private *tp) |
|
4337 { |
|
4338 void __iomem *ioaddr = tp->mmio_addr; |
|
4339 |
|
4340 RTL_W8(MaxTxPacketSize, 0x0c); |
|
4341 RTL_W8(Config3, RTL_R8(Config3) & ~Jumbo_En0); |
|
4342 RTL_W8(Config4, RTL_R8(Config4) & ~0x01); |
|
4343 rtl_tx_performance_tweak(tp->pci_dev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
4344 } |
|
4345 |
|
4346 static void r8168b_0_hw_jumbo_enable(struct rtl8169_private *tp) |
|
4347 { |
|
4348 rtl_tx_performance_tweak(tp->pci_dev, |
|
4349 (0x2 << MAX_READ_REQUEST_SHIFT) | PCI_EXP_DEVCTL_NOSNOOP_EN); |
|
4350 } |
|
4351 |
|
4352 static void r8168b_0_hw_jumbo_disable(struct rtl8169_private *tp) |
|
4353 { |
|
4354 rtl_tx_performance_tweak(tp->pci_dev, |
|
4355 (0x5 << MAX_READ_REQUEST_SHIFT) | PCI_EXP_DEVCTL_NOSNOOP_EN); |
|
4356 } |
|
4357 |
|
4358 static void r8168b_1_hw_jumbo_enable(struct rtl8169_private *tp) |
|
4359 { |
|
4360 void __iomem *ioaddr = tp->mmio_addr; |
|
4361 |
|
4362 r8168b_0_hw_jumbo_enable(tp); |
|
4363 |
|
4364 RTL_W8(Config4, RTL_R8(Config4) | (1 << 0)); |
|
4365 } |
|
4366 |
|
4367 static void r8168b_1_hw_jumbo_disable(struct rtl8169_private *tp) |
|
4368 { |
|
4369 void __iomem *ioaddr = tp->mmio_addr; |
|
4370 |
|
4371 r8168b_0_hw_jumbo_disable(tp); |
|
4372 |
|
4373 RTL_W8(Config4, RTL_R8(Config4) & ~(1 << 0)); |
|
4374 } |
|
4375 |
|
4376 static void rtl_init_jumbo_ops(struct rtl8169_private *tp) |
|
4377 { |
|
4378 struct jumbo_ops *ops = &tp->jumbo_ops; |
|
4379 |
|
4380 switch (tp->mac_version) { |
|
4381 case RTL_GIGA_MAC_VER_11: |
|
4382 ops->disable = r8168b_0_hw_jumbo_disable; |
|
4383 ops->enable = r8168b_0_hw_jumbo_enable; |
|
4384 break; |
|
4385 case RTL_GIGA_MAC_VER_12: |
|
4386 case RTL_GIGA_MAC_VER_17: |
|
4387 ops->disable = r8168b_1_hw_jumbo_disable; |
|
4388 ops->enable = r8168b_1_hw_jumbo_enable; |
|
4389 break; |
|
4390 case RTL_GIGA_MAC_VER_18: /* Wild guess. Needs info from Realtek. */ |
|
4391 case RTL_GIGA_MAC_VER_19: |
|
4392 case RTL_GIGA_MAC_VER_20: |
|
4393 case RTL_GIGA_MAC_VER_21: /* Wild guess. Needs info from Realtek. */ |
|
4394 case RTL_GIGA_MAC_VER_22: |
|
4395 case RTL_GIGA_MAC_VER_23: |
|
4396 case RTL_GIGA_MAC_VER_24: |
|
4397 case RTL_GIGA_MAC_VER_25: |
|
4398 case RTL_GIGA_MAC_VER_26: |
|
4399 ops->disable = r8168c_hw_jumbo_disable; |
|
4400 ops->enable = r8168c_hw_jumbo_enable; |
|
4401 break; |
|
4402 case RTL_GIGA_MAC_VER_27: |
|
4403 case RTL_GIGA_MAC_VER_28: |
|
4404 ops->disable = r8168dp_hw_jumbo_disable; |
|
4405 ops->enable = r8168dp_hw_jumbo_enable; |
|
4406 break; |
|
4407 case RTL_GIGA_MAC_VER_31: /* Wild guess. Needs info from Realtek. */ |
|
4408 case RTL_GIGA_MAC_VER_32: |
|
4409 case RTL_GIGA_MAC_VER_33: |
|
4410 case RTL_GIGA_MAC_VER_34: |
|
4411 ops->disable = r8168e_hw_jumbo_disable; |
|
4412 ops->enable = r8168e_hw_jumbo_enable; |
|
4413 break; |
|
4414 |
|
4415 /* |
|
4416 * No action needed for jumbo frames with 8169. |
|
4417 * No jumbo for 810x at all. |
|
4418 */ |
|
4419 case RTL_GIGA_MAC_VER_40: |
|
4420 case RTL_GIGA_MAC_VER_41: |
|
4421 case RTL_GIGA_MAC_VER_42: |
|
4422 case RTL_GIGA_MAC_VER_43: |
|
4423 case RTL_GIGA_MAC_VER_44: |
|
4424 default: |
|
4425 ops->disable = NULL; |
|
4426 ops->enable = NULL; |
|
4427 break; |
|
4428 } |
|
4429 } |
|
4430 |
|
4431 DECLARE_RTL_COND(rtl_chipcmd_cond) |
|
4432 { |
|
4433 void __iomem *ioaddr = tp->mmio_addr; |
|
4434 |
|
4435 return RTL_R8(ChipCmd) & CmdReset; |
|
4436 } |
|
4437 |
|
4438 static void rtl_hw_reset(struct rtl8169_private *tp) |
|
4439 { |
|
4440 void __iomem *ioaddr = tp->mmio_addr; |
|
4441 |
|
4442 RTL_W8(ChipCmd, CmdReset); |
|
4443 |
|
4444 rtl_udelay_loop_wait_low(tp, &rtl_chipcmd_cond, 100, 100); |
|
4445 } |
|
4446 |
|
4447 static void rtl_request_uncached_firmware(struct rtl8169_private *tp) |
|
4448 { |
|
4449 struct rtl_fw *rtl_fw; |
|
4450 const char *name; |
|
4451 int rc = -ENOMEM; |
|
4452 |
|
4453 name = rtl_lookup_firmware_name(tp); |
|
4454 if (!name) |
|
4455 goto out_no_firmware; |
|
4456 |
|
4457 rtl_fw = kzalloc(sizeof(*rtl_fw), GFP_KERNEL); |
|
4458 if (!rtl_fw) |
|
4459 goto err_warn; |
|
4460 |
|
4461 rc = request_firmware(&rtl_fw->fw, name, &tp->pci_dev->dev); |
|
4462 if (rc < 0) |
|
4463 goto err_free; |
|
4464 |
|
4465 rc = rtl_check_firmware(tp, rtl_fw); |
|
4466 if (rc < 0) |
|
4467 goto err_release_firmware; |
|
4468 |
|
4469 tp->rtl_fw = rtl_fw; |
|
4470 out: |
|
4471 return; |
|
4472 |
|
4473 err_release_firmware: |
|
4474 release_firmware(rtl_fw->fw); |
|
4475 err_free: |
|
4476 kfree(rtl_fw); |
|
4477 err_warn: |
|
4478 netif_warn(tp, ifup, tp->dev, "unable to load firmware patch %s (%d)\n", |
|
4479 name, rc); |
|
4480 out_no_firmware: |
|
4481 tp->rtl_fw = NULL; |
|
4482 goto out; |
|
4483 } |
|
4484 |
|
4485 static void rtl_request_firmware(struct rtl8169_private *tp) |
|
4486 { |
|
4487 if (IS_ERR(tp->rtl_fw)) |
|
4488 rtl_request_uncached_firmware(tp); |
|
4489 } |
|
4490 |
|
4491 static void rtl_rx_close(struct rtl8169_private *tp) |
|
4492 { |
|
4493 void __iomem *ioaddr = tp->mmio_addr; |
|
4494 |
|
4495 RTL_W32(RxConfig, RTL_R32(RxConfig) & ~RX_CONFIG_ACCEPT_MASK); |
|
4496 } |
|
4497 |
|
4498 DECLARE_RTL_COND(rtl_npq_cond) |
|
4499 { |
|
4500 void __iomem *ioaddr = tp->mmio_addr; |
|
4501 |
|
4502 return RTL_R8(TxPoll) & NPQ; |
|
4503 } |
|
4504 |
|
4505 DECLARE_RTL_COND(rtl_txcfg_empty_cond) |
|
4506 { |
|
4507 void __iomem *ioaddr = tp->mmio_addr; |
|
4508 |
|
4509 return RTL_R32(TxConfig) & TXCFG_EMPTY; |
|
4510 } |
|
4511 |
|
4512 static void rtl8169_hw_reset(struct rtl8169_private *tp) |
|
4513 { |
|
4514 void __iomem *ioaddr = tp->mmio_addr; |
|
4515 |
|
4516 /* Disable interrupts */ |
|
4517 rtl8169_irq_mask_and_ack(tp); |
|
4518 |
|
4519 rtl_rx_close(tp); |
|
4520 |
|
4521 if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
|
4522 tp->mac_version == RTL_GIGA_MAC_VER_28 || |
|
4523 tp->mac_version == RTL_GIGA_MAC_VER_31) { |
|
4524 rtl_udelay_loop_wait_low(tp, &rtl_npq_cond, 20, 42*42); |
|
4525 } else if (tp->mac_version == RTL_GIGA_MAC_VER_34 || |
|
4526 tp->mac_version == RTL_GIGA_MAC_VER_35 || |
|
4527 tp->mac_version == RTL_GIGA_MAC_VER_36 || |
|
4528 tp->mac_version == RTL_GIGA_MAC_VER_37 || |
|
4529 tp->mac_version == RTL_GIGA_MAC_VER_40 || |
|
4530 tp->mac_version == RTL_GIGA_MAC_VER_41 || |
|
4531 tp->mac_version == RTL_GIGA_MAC_VER_42 || |
|
4532 tp->mac_version == RTL_GIGA_MAC_VER_43 || |
|
4533 tp->mac_version == RTL_GIGA_MAC_VER_44 || |
|
4534 tp->mac_version == RTL_GIGA_MAC_VER_38) { |
|
4535 RTL_W8(ChipCmd, RTL_R8(ChipCmd) | StopReq); |
|
4536 rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 666); |
|
4537 } else { |
|
4538 RTL_W8(ChipCmd, RTL_R8(ChipCmd) | StopReq); |
|
4539 udelay(100); |
|
4540 } |
|
4541 |
|
4542 rtl_hw_reset(tp); |
|
4543 } |
|
4544 |
|
4545 static void rtl_set_rx_tx_config_registers(struct rtl8169_private *tp) |
|
4546 { |
|
4547 void __iomem *ioaddr = tp->mmio_addr; |
|
4548 |
|
4549 /* Set DMA burst size and Interframe Gap Time */ |
|
4550 RTL_W32(TxConfig, (TX_DMA_BURST << TxDMAShift) | |
|
4551 (InterFrameGap << TxInterFrameGapShift)); |
|
4552 } |
|
4553 |
|
4554 static void rtl_hw_start(struct net_device *dev) |
|
4555 { |
|
4556 struct rtl8169_private *tp = netdev_priv(dev); |
|
4557 |
|
4558 tp->hw_start(dev); |
|
4559 |
|
4560 if (!tp->ecdev) { |
|
4561 rtl_irq_enable_all(tp); |
|
4562 } |
|
4563 } |
|
4564 |
|
4565 static void rtl_set_rx_tx_desc_registers(struct rtl8169_private *tp, |
|
4566 void __iomem *ioaddr) |
|
4567 { |
|
4568 /* |
|
4569 * Magic spell: some iop3xx ARM board needs the TxDescAddrHigh |
|
4570 * register to be written before TxDescAddrLow to work. |
|
4571 * Switching from MMIO to I/O access fixes the issue as well. |
|
4572 */ |
|
4573 RTL_W32(TxDescStartAddrHigh, ((u64) tp->TxPhyAddr) >> 32); |
|
4574 RTL_W32(TxDescStartAddrLow, ((u64) tp->TxPhyAddr) & DMA_BIT_MASK(32)); |
|
4575 RTL_W32(RxDescAddrHigh, ((u64) tp->RxPhyAddr) >> 32); |
|
4576 RTL_W32(RxDescAddrLow, ((u64) tp->RxPhyAddr) & DMA_BIT_MASK(32)); |
|
4577 } |
|
4578 |
|
4579 static u16 rtl_rw_cpluscmd(void __iomem *ioaddr) |
|
4580 { |
|
4581 u16 cmd; |
|
4582 |
|
4583 cmd = RTL_R16(CPlusCmd); |
|
4584 RTL_W16(CPlusCmd, cmd); |
|
4585 return cmd; |
|
4586 } |
|
4587 |
|
4588 static void rtl_set_rx_max_size(void __iomem *ioaddr, unsigned int rx_buf_sz) |
|
4589 { |
|
4590 /* Low hurts. Let's disable the filtering. */ |
|
4591 RTL_W16(RxMaxSize, rx_buf_sz + 1); |
|
4592 } |
|
4593 |
|
4594 static void rtl8169_set_magic_reg(void __iomem *ioaddr, unsigned mac_version) |
|
4595 { |
|
4596 static const struct rtl_cfg2_info { |
|
4597 u32 mac_version; |
|
4598 u32 clk; |
|
4599 u32 val; |
|
4600 } cfg2_info [] = { |
|
4601 { RTL_GIGA_MAC_VER_05, PCI_Clock_33MHz, 0x000fff00 }, // 8110SCd |
|
4602 { RTL_GIGA_MAC_VER_05, PCI_Clock_66MHz, 0x000fffff }, |
|
4603 { RTL_GIGA_MAC_VER_06, PCI_Clock_33MHz, 0x00ffff00 }, // 8110SCe |
|
4604 { RTL_GIGA_MAC_VER_06, PCI_Clock_66MHz, 0x00ffffff } |
|
4605 }; |
|
4606 const struct rtl_cfg2_info *p = cfg2_info; |
|
4607 unsigned int i; |
|
4608 u32 clk; |
|
4609 |
|
4610 clk = RTL_R8(Config2) & PCI_Clock_66MHz; |
|
4611 for (i = 0; i < ARRAY_SIZE(cfg2_info); i++, p++) { |
|
4612 if ((p->mac_version == mac_version) && (p->clk == clk)) { |
|
4613 RTL_W32(0x7c, p->val); |
|
4614 break; |
|
4615 } |
|
4616 } |
|
4617 } |
|
4618 |
|
4619 static void rtl_set_rx_mode(struct net_device *dev) |
|
4620 { |
|
4621 struct rtl8169_private *tp = netdev_priv(dev); |
|
4622 void __iomem *ioaddr = tp->mmio_addr; |
|
4623 u32 mc_filter[2]; /* Multicast hash filter */ |
|
4624 int rx_mode; |
|
4625 u32 tmp = 0; |
|
4626 |
|
4627 if (dev->flags & IFF_PROMISC) { |
|
4628 /* Unconditionally log net taps. */ |
|
4629 netif_notice(tp, link, dev, "Promiscuous mode enabled\n"); |
|
4630 rx_mode = |
|
4631 AcceptBroadcast | AcceptMulticast | AcceptMyPhys | |
|
4632 AcceptAllPhys; |
|
4633 mc_filter[1] = mc_filter[0] = 0xffffffff; |
|
4634 } else if ((netdev_mc_count(dev) > multicast_filter_limit) || |
|
4635 (dev->flags & IFF_ALLMULTI)) { |
|
4636 /* Too many to filter perfectly -- accept all multicasts. */ |
|
4637 rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; |
|
4638 mc_filter[1] = mc_filter[0] = 0xffffffff; |
|
4639 } else { |
|
4640 struct netdev_hw_addr *ha; |
|
4641 |
|
4642 rx_mode = AcceptBroadcast | AcceptMyPhys; |
|
4643 mc_filter[1] = mc_filter[0] = 0; |
|
4644 netdev_for_each_mc_addr(ha, dev) { |
|
4645 int bit_nr = ether_crc(ETH_ALEN, ha->addr) >> 26; |
|
4646 mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); |
|
4647 rx_mode |= AcceptMulticast; |
|
4648 } |
|
4649 } |
|
4650 |
|
4651 if (dev->features & NETIF_F_RXALL) |
|
4652 rx_mode |= (AcceptErr | AcceptRunt); |
|
4653 |
|
4654 tmp = (RTL_R32(RxConfig) & ~RX_CONFIG_ACCEPT_MASK) | rx_mode; |
|
4655 |
|
4656 if (tp->mac_version > RTL_GIGA_MAC_VER_06) { |
|
4657 u32 data = mc_filter[0]; |
|
4658 |
|
4659 mc_filter[0] = swab32(mc_filter[1]); |
|
4660 mc_filter[1] = swab32(data); |
|
4661 } |
|
4662 |
|
4663 if (tp->mac_version == RTL_GIGA_MAC_VER_35) |
|
4664 mc_filter[1] = mc_filter[0] = 0xffffffff; |
|
4665 |
|
4666 RTL_W32(MAR0 + 4, mc_filter[1]); |
|
4667 RTL_W32(MAR0 + 0, mc_filter[0]); |
|
4668 |
|
4669 RTL_W32(RxConfig, tmp); |
|
4670 } |
|
4671 |
|
4672 static void rtl_hw_start_8169(struct net_device *dev) |
|
4673 { |
|
4674 struct rtl8169_private *tp = netdev_priv(dev); |
|
4675 void __iomem *ioaddr = tp->mmio_addr; |
|
4676 struct pci_dev *pdev = tp->pci_dev; |
|
4677 |
|
4678 if (tp->mac_version == RTL_GIGA_MAC_VER_05) { |
|
4679 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) | PCIMulRW); |
|
4680 pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE, 0x08); |
|
4681 } |
|
4682 |
|
4683 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
4684 if (tp->mac_version == RTL_GIGA_MAC_VER_01 || |
|
4685 tp->mac_version == RTL_GIGA_MAC_VER_02 || |
|
4686 tp->mac_version == RTL_GIGA_MAC_VER_03 || |
|
4687 tp->mac_version == RTL_GIGA_MAC_VER_04) |
|
4688 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
|
4689 |
|
4690 rtl_init_rxcfg(tp); |
|
4691 |
|
4692 RTL_W8(EarlyTxThres, NoEarlyTx); |
|
4693 |
|
4694 rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
|
4695 |
|
4696 if (tp->mac_version == RTL_GIGA_MAC_VER_01 || |
|
4697 tp->mac_version == RTL_GIGA_MAC_VER_02 || |
|
4698 tp->mac_version == RTL_GIGA_MAC_VER_03 || |
|
4699 tp->mac_version == RTL_GIGA_MAC_VER_04) |
|
4700 rtl_set_rx_tx_config_registers(tp); |
|
4701 |
|
4702 tp->cp_cmd |= rtl_rw_cpluscmd(ioaddr) | PCIMulRW; |
|
4703 |
|
4704 if (tp->mac_version == RTL_GIGA_MAC_VER_02 || |
|
4705 tp->mac_version == RTL_GIGA_MAC_VER_03) { |
|
4706 dprintk("Set MAC Reg C+CR Offset 0xE0. " |
|
4707 "Bit-3 and bit-14 MUST be 1\n"); |
|
4708 tp->cp_cmd |= (1 << 14); |
|
4709 } |
|
4710 |
|
4711 RTL_W16(CPlusCmd, tp->cp_cmd); |
|
4712 |
|
4713 rtl8169_set_magic_reg(ioaddr, tp->mac_version); |
|
4714 |
|
4715 /* |
|
4716 * Undocumented corner. Supposedly: |
|
4717 * (TxTimer << 12) | (TxPackets << 8) | (RxTimer << 4) | RxPackets |
|
4718 */ |
|
4719 RTL_W16(IntrMitigate, 0x0000); |
|
4720 |
|
4721 rtl_set_rx_tx_desc_registers(tp, ioaddr); |
|
4722 |
|
4723 if (tp->mac_version != RTL_GIGA_MAC_VER_01 && |
|
4724 tp->mac_version != RTL_GIGA_MAC_VER_02 && |
|
4725 tp->mac_version != RTL_GIGA_MAC_VER_03 && |
|
4726 tp->mac_version != RTL_GIGA_MAC_VER_04) { |
|
4727 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
|
4728 rtl_set_rx_tx_config_registers(tp); |
|
4729 } |
|
4730 |
|
4731 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
4732 |
|
4733 /* Initially a 10 us delay. Turned it into a PCI commit. - FR */ |
|
4734 RTL_R8(IntrMask); |
|
4735 |
|
4736 RTL_W32(RxMissed, 0); |
|
4737 |
|
4738 rtl_set_rx_mode(dev); |
|
4739 |
|
4740 /* no early-rx interrupts */ |
|
4741 RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000); |
|
4742 } |
|
4743 |
|
4744 static void rtl_csi_write(struct rtl8169_private *tp, int addr, int value) |
|
4745 { |
|
4746 if (tp->csi_ops.write) |
|
4747 tp->csi_ops.write(tp, addr, value); |
|
4748 } |
|
4749 |
|
4750 static u32 rtl_csi_read(struct rtl8169_private *tp, int addr) |
|
4751 { |
|
4752 return tp->csi_ops.read ? tp->csi_ops.read(tp, addr) : ~0; |
|
4753 } |
|
4754 |
|
4755 static void rtl_csi_access_enable(struct rtl8169_private *tp, u32 bits) |
|
4756 { |
|
4757 u32 csi; |
|
4758 |
|
4759 csi = rtl_csi_read(tp, 0x070c) & 0x00ffffff; |
|
4760 rtl_csi_write(tp, 0x070c, csi | bits); |
|
4761 } |
|
4762 |
|
4763 static void rtl_csi_access_enable_1(struct rtl8169_private *tp) |
|
4764 { |
|
4765 rtl_csi_access_enable(tp, 0x17000000); |
|
4766 } |
|
4767 |
|
4768 static void rtl_csi_access_enable_2(struct rtl8169_private *tp) |
|
4769 { |
|
4770 rtl_csi_access_enable(tp, 0x27000000); |
|
4771 } |
|
4772 |
|
4773 DECLARE_RTL_COND(rtl_csiar_cond) |
|
4774 { |
|
4775 void __iomem *ioaddr = tp->mmio_addr; |
|
4776 |
|
4777 return RTL_R32(CSIAR) & CSIAR_FLAG; |
|
4778 } |
|
4779 |
|
4780 static void r8169_csi_write(struct rtl8169_private *tp, int addr, int value) |
|
4781 { |
|
4782 void __iomem *ioaddr = tp->mmio_addr; |
|
4783 |
|
4784 RTL_W32(CSIDR, value); |
|
4785 RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
|
4786 CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
|
4787 |
|
4788 rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
|
4789 } |
|
4790 |
|
4791 static u32 r8169_csi_read(struct rtl8169_private *tp, int addr) |
|
4792 { |
|
4793 void __iomem *ioaddr = tp->mmio_addr; |
|
4794 |
|
4795 RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) | |
|
4796 CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
|
4797 |
|
4798 return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
|
4799 RTL_R32(CSIDR) : ~0; |
|
4800 } |
|
4801 |
|
4802 static void r8402_csi_write(struct rtl8169_private *tp, int addr, int value) |
|
4803 { |
|
4804 void __iomem *ioaddr = tp->mmio_addr; |
|
4805 |
|
4806 RTL_W32(CSIDR, value); |
|
4807 RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
|
4808 CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT | |
|
4809 CSIAR_FUNC_NIC); |
|
4810 |
|
4811 rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
|
4812 } |
|
4813 |
|
4814 static u32 r8402_csi_read(struct rtl8169_private *tp, int addr) |
|
4815 { |
|
4816 void __iomem *ioaddr = tp->mmio_addr; |
|
4817 |
|
4818 RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) | CSIAR_FUNC_NIC | |
|
4819 CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
|
4820 |
|
4821 return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
|
4822 RTL_R32(CSIDR) : ~0; |
|
4823 } |
|
4824 |
|
4825 static void r8411_csi_write(struct rtl8169_private *tp, int addr, int value) |
|
4826 { |
|
4827 void __iomem *ioaddr = tp->mmio_addr; |
|
4828 |
|
4829 RTL_W32(CSIDR, value); |
|
4830 RTL_W32(CSIAR, CSIAR_WRITE_CMD | (addr & CSIAR_ADDR_MASK) | |
|
4831 CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT | |
|
4832 CSIAR_FUNC_NIC2); |
|
4833 |
|
4834 rtl_udelay_loop_wait_low(tp, &rtl_csiar_cond, 10, 100); |
|
4835 } |
|
4836 |
|
4837 static u32 r8411_csi_read(struct rtl8169_private *tp, int addr) |
|
4838 { |
|
4839 void __iomem *ioaddr = tp->mmio_addr; |
|
4840 |
|
4841 RTL_W32(CSIAR, (addr & CSIAR_ADDR_MASK) | CSIAR_FUNC_NIC2 | |
|
4842 CSIAR_BYTE_ENABLE << CSIAR_BYTE_ENABLE_SHIFT); |
|
4843 |
|
4844 return rtl_udelay_loop_wait_high(tp, &rtl_csiar_cond, 10, 100) ? |
|
4845 RTL_R32(CSIDR) : ~0; |
|
4846 } |
|
4847 |
|
4848 static void rtl_init_csi_ops(struct rtl8169_private *tp) |
|
4849 { |
|
4850 struct csi_ops *ops = &tp->csi_ops; |
|
4851 |
|
4852 switch (tp->mac_version) { |
|
4853 case RTL_GIGA_MAC_VER_01: |
|
4854 case RTL_GIGA_MAC_VER_02: |
|
4855 case RTL_GIGA_MAC_VER_03: |
|
4856 case RTL_GIGA_MAC_VER_04: |
|
4857 case RTL_GIGA_MAC_VER_05: |
|
4858 case RTL_GIGA_MAC_VER_06: |
|
4859 case RTL_GIGA_MAC_VER_10: |
|
4860 case RTL_GIGA_MAC_VER_11: |
|
4861 case RTL_GIGA_MAC_VER_12: |
|
4862 case RTL_GIGA_MAC_VER_13: |
|
4863 case RTL_GIGA_MAC_VER_14: |
|
4864 case RTL_GIGA_MAC_VER_15: |
|
4865 case RTL_GIGA_MAC_VER_16: |
|
4866 case RTL_GIGA_MAC_VER_17: |
|
4867 ops->write = NULL; |
|
4868 ops->read = NULL; |
|
4869 break; |
|
4870 |
|
4871 case RTL_GIGA_MAC_VER_37: |
|
4872 case RTL_GIGA_MAC_VER_38: |
|
4873 ops->write = r8402_csi_write; |
|
4874 ops->read = r8402_csi_read; |
|
4875 break; |
|
4876 |
|
4877 case RTL_GIGA_MAC_VER_44: |
|
4878 ops->write = r8411_csi_write; |
|
4879 ops->read = r8411_csi_read; |
|
4880 break; |
|
4881 |
|
4882 default: |
|
4883 ops->write = r8169_csi_write; |
|
4884 ops->read = r8169_csi_read; |
|
4885 break; |
|
4886 } |
|
4887 } |
|
4888 |
|
4889 struct ephy_info { |
|
4890 unsigned int offset; |
|
4891 u16 mask; |
|
4892 u16 bits; |
|
4893 }; |
|
4894 |
|
4895 static void rtl_ephy_init(struct rtl8169_private *tp, const struct ephy_info *e, |
|
4896 int len) |
|
4897 { |
|
4898 u16 w; |
|
4899 |
|
4900 while (len-- > 0) { |
|
4901 w = (rtl_ephy_read(tp, e->offset) & ~e->mask) | e->bits; |
|
4902 rtl_ephy_write(tp, e->offset, w); |
|
4903 e++; |
|
4904 } |
|
4905 } |
|
4906 |
|
4907 static void rtl_disable_clock_request(struct pci_dev *pdev) |
|
4908 { |
|
4909 pcie_capability_clear_word(pdev, PCI_EXP_LNKCTL, |
|
4910 PCI_EXP_LNKCTL_CLKREQ_EN); |
|
4911 } |
|
4912 |
|
4913 static void rtl_enable_clock_request(struct pci_dev *pdev) |
|
4914 { |
|
4915 pcie_capability_set_word(pdev, PCI_EXP_LNKCTL, |
|
4916 PCI_EXP_LNKCTL_CLKREQ_EN); |
|
4917 } |
|
4918 |
|
4919 #define R8168_CPCMD_QUIRK_MASK (\ |
|
4920 EnableBist | \ |
|
4921 Mac_dbgo_oe | \ |
|
4922 Force_half_dup | \ |
|
4923 Force_rxflow_en | \ |
|
4924 Force_txflow_en | \ |
|
4925 Cxpl_dbg_sel | \ |
|
4926 ASF | \ |
|
4927 PktCntrDisable | \ |
|
4928 Mac_dbgo_sel) |
|
4929 |
|
4930 static void rtl_hw_start_8168bb(struct rtl8169_private *tp) |
|
4931 { |
|
4932 void __iomem *ioaddr = tp->mmio_addr; |
|
4933 struct pci_dev *pdev = tp->pci_dev; |
|
4934 |
|
4935 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
4936 |
|
4937 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
|
4938 |
|
4939 if (tp->dev->mtu <= ETH_DATA_LEN) { |
|
4940 rtl_tx_performance_tweak(pdev, (0x5 << MAX_READ_REQUEST_SHIFT) | |
|
4941 PCI_EXP_DEVCTL_NOSNOOP_EN); |
|
4942 } |
|
4943 } |
|
4944 |
|
4945 static void rtl_hw_start_8168bef(struct rtl8169_private *tp) |
|
4946 { |
|
4947 void __iomem *ioaddr = tp->mmio_addr; |
|
4948 |
|
4949 rtl_hw_start_8168bb(tp); |
|
4950 |
|
4951 RTL_W8(MaxTxPacketSize, TxPacketMax); |
|
4952 |
|
4953 RTL_W8(Config4, RTL_R8(Config4) & ~(1 << 0)); |
|
4954 } |
|
4955 |
|
4956 static void __rtl_hw_start_8168cp(struct rtl8169_private *tp) |
|
4957 { |
|
4958 void __iomem *ioaddr = tp->mmio_addr; |
|
4959 struct pci_dev *pdev = tp->pci_dev; |
|
4960 |
|
4961 RTL_W8(Config1, RTL_R8(Config1) | Speed_down); |
|
4962 |
|
4963 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
4964 |
|
4965 if (tp->dev->mtu <= ETH_DATA_LEN) |
|
4966 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
4967 |
|
4968 rtl_disable_clock_request(pdev); |
|
4969 |
|
4970 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
|
4971 } |
|
4972 |
|
4973 static void rtl_hw_start_8168cp_1(struct rtl8169_private *tp) |
|
4974 { |
|
4975 static const struct ephy_info e_info_8168cp[] = { |
|
4976 { 0x01, 0, 0x0001 }, |
|
4977 { 0x02, 0x0800, 0x1000 }, |
|
4978 { 0x03, 0, 0x0042 }, |
|
4979 { 0x06, 0x0080, 0x0000 }, |
|
4980 { 0x07, 0, 0x2000 } |
|
4981 }; |
|
4982 |
|
4983 rtl_csi_access_enable_2(tp); |
|
4984 |
|
4985 rtl_ephy_init(tp, e_info_8168cp, ARRAY_SIZE(e_info_8168cp)); |
|
4986 |
|
4987 __rtl_hw_start_8168cp(tp); |
|
4988 } |
|
4989 |
|
4990 static void rtl_hw_start_8168cp_2(struct rtl8169_private *tp) |
|
4991 { |
|
4992 void __iomem *ioaddr = tp->mmio_addr; |
|
4993 struct pci_dev *pdev = tp->pci_dev; |
|
4994 |
|
4995 rtl_csi_access_enable_2(tp); |
|
4996 |
|
4997 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
4998 |
|
4999 if (tp->dev->mtu <= ETH_DATA_LEN) |
|
5000 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
5001 |
|
5002 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
|
5003 } |
|
5004 |
|
5005 static void rtl_hw_start_8168cp_3(struct rtl8169_private *tp) |
|
5006 { |
|
5007 void __iomem *ioaddr = tp->mmio_addr; |
|
5008 struct pci_dev *pdev = tp->pci_dev; |
|
5009 |
|
5010 rtl_csi_access_enable_2(tp); |
|
5011 |
|
5012 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
5013 |
|
5014 /* Magic. */ |
|
5015 RTL_W8(DBG_REG, 0x20); |
|
5016 |
|
5017 RTL_W8(MaxTxPacketSize, TxPacketMax); |
|
5018 |
|
5019 if (tp->dev->mtu <= ETH_DATA_LEN) |
|
5020 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
5021 |
|
5022 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
|
5023 } |
|
5024 |
|
5025 static void rtl_hw_start_8168c_1(struct rtl8169_private *tp) |
|
5026 { |
|
5027 void __iomem *ioaddr = tp->mmio_addr; |
|
5028 static const struct ephy_info e_info_8168c_1[] = { |
|
5029 { 0x02, 0x0800, 0x1000 }, |
|
5030 { 0x03, 0, 0x0002 }, |
|
5031 { 0x06, 0x0080, 0x0000 } |
|
5032 }; |
|
5033 |
|
5034 rtl_csi_access_enable_2(tp); |
|
5035 |
|
5036 RTL_W8(DBG_REG, 0x06 | FIX_NAK_1 | FIX_NAK_2); |
|
5037 |
|
5038 rtl_ephy_init(tp, e_info_8168c_1, ARRAY_SIZE(e_info_8168c_1)); |
|
5039 |
|
5040 __rtl_hw_start_8168cp(tp); |
|
5041 } |
|
5042 |
|
5043 static void rtl_hw_start_8168c_2(struct rtl8169_private *tp) |
|
5044 { |
|
5045 static const struct ephy_info e_info_8168c_2[] = { |
|
5046 { 0x01, 0, 0x0001 }, |
|
5047 { 0x03, 0x0400, 0x0220 } |
|
5048 }; |
|
5049 |
|
5050 rtl_csi_access_enable_2(tp); |
|
5051 |
|
5052 rtl_ephy_init(tp, e_info_8168c_2, ARRAY_SIZE(e_info_8168c_2)); |
|
5053 |
|
5054 __rtl_hw_start_8168cp(tp); |
|
5055 } |
|
5056 |
|
5057 static void rtl_hw_start_8168c_3(struct rtl8169_private *tp) |
|
5058 { |
|
5059 rtl_hw_start_8168c_2(tp); |
|
5060 } |
|
5061 |
|
5062 static void rtl_hw_start_8168c_4(struct rtl8169_private *tp) |
|
5063 { |
|
5064 rtl_csi_access_enable_2(tp); |
|
5065 |
|
5066 __rtl_hw_start_8168cp(tp); |
|
5067 } |
|
5068 |
|
5069 static void rtl_hw_start_8168d(struct rtl8169_private *tp) |
|
5070 { |
|
5071 void __iomem *ioaddr = tp->mmio_addr; |
|
5072 struct pci_dev *pdev = tp->pci_dev; |
|
5073 |
|
5074 rtl_csi_access_enable_2(tp); |
|
5075 |
|
5076 rtl_disable_clock_request(pdev); |
|
5077 |
|
5078 RTL_W8(MaxTxPacketSize, TxPacketMax); |
|
5079 |
|
5080 if (tp->dev->mtu <= ETH_DATA_LEN) |
|
5081 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
5082 |
|
5083 RTL_W16(CPlusCmd, RTL_R16(CPlusCmd) & ~R8168_CPCMD_QUIRK_MASK); |
|
5084 } |
|
5085 |
|
5086 static void rtl_hw_start_8168dp(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_1(tp); |
|
5092 |
|
5093 if (tp->dev->mtu <= ETH_DATA_LEN) |
|
5094 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
5095 |
|
5096 RTL_W8(MaxTxPacketSize, TxPacketMax); |
|
5097 |
|
5098 rtl_disable_clock_request(pdev); |
|
5099 } |
|
5100 |
|
5101 static void rtl_hw_start_8168d_4(struct rtl8169_private *tp) |
|
5102 { |
|
5103 void __iomem *ioaddr = tp->mmio_addr; |
|
5104 struct pci_dev *pdev = tp->pci_dev; |
|
5105 static const struct ephy_info e_info_8168d_4[] = { |
|
5106 { 0x0b, ~0, 0x48 }, |
|
5107 { 0x19, 0x20, 0x50 }, |
|
5108 { 0x0c, ~0, 0x20 } |
|
5109 }; |
|
5110 int i; |
|
5111 |
|
5112 rtl_csi_access_enable_1(tp); |
|
5113 |
|
5114 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
5115 |
|
5116 RTL_W8(MaxTxPacketSize, TxPacketMax); |
|
5117 |
|
5118 for (i = 0; i < ARRAY_SIZE(e_info_8168d_4); i++) { |
|
5119 const struct ephy_info *e = e_info_8168d_4 + i; |
|
5120 u16 w; |
|
5121 |
|
5122 w = rtl_ephy_read(tp, e->offset); |
|
5123 rtl_ephy_write(tp, 0x03, (w & e->mask) | e->bits); |
|
5124 } |
|
5125 |
|
5126 rtl_enable_clock_request(pdev); |
|
5127 } |
|
5128 |
|
5129 static void rtl_hw_start_8168e_1(struct rtl8169_private *tp) |
|
5130 { |
|
5131 void __iomem *ioaddr = tp->mmio_addr; |
|
5132 struct pci_dev *pdev = tp->pci_dev; |
|
5133 static const struct ephy_info e_info_8168e_1[] = { |
|
5134 { 0x00, 0x0200, 0x0100 }, |
|
5135 { 0x00, 0x0000, 0x0004 }, |
|
5136 { 0x06, 0x0002, 0x0001 }, |
|
5137 { 0x06, 0x0000, 0x0030 }, |
|
5138 { 0x07, 0x0000, 0x2000 }, |
|
5139 { 0x00, 0x0000, 0x0020 }, |
|
5140 { 0x03, 0x5800, 0x2000 }, |
|
5141 { 0x03, 0x0000, 0x0001 }, |
|
5142 { 0x01, 0x0800, 0x1000 }, |
|
5143 { 0x07, 0x0000, 0x4000 }, |
|
5144 { 0x1e, 0x0000, 0x2000 }, |
|
5145 { 0x19, 0xffff, 0xfe6c }, |
|
5146 { 0x0a, 0x0000, 0x0040 } |
|
5147 }; |
|
5148 |
|
5149 rtl_csi_access_enable_2(tp); |
|
5150 |
|
5151 rtl_ephy_init(tp, e_info_8168e_1, ARRAY_SIZE(e_info_8168e_1)); |
|
5152 |
|
5153 if (tp->dev->mtu <= ETH_DATA_LEN) |
|
5154 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
5155 |
|
5156 RTL_W8(MaxTxPacketSize, TxPacketMax); |
|
5157 |
|
5158 rtl_disable_clock_request(pdev); |
|
5159 |
|
5160 /* Reset tx FIFO pointer */ |
|
5161 RTL_W32(MISC, RTL_R32(MISC) | TXPLA_RST); |
|
5162 RTL_W32(MISC, RTL_R32(MISC) & ~TXPLA_RST); |
|
5163 |
|
5164 RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en); |
|
5165 } |
|
5166 |
|
5167 static void rtl_hw_start_8168e_2(struct rtl8169_private *tp) |
|
5168 { |
|
5169 void __iomem *ioaddr = tp->mmio_addr; |
|
5170 struct pci_dev *pdev = tp->pci_dev; |
|
5171 static const struct ephy_info e_info_8168e_2[] = { |
|
5172 { 0x09, 0x0000, 0x0080 }, |
|
5173 { 0x19, 0x0000, 0x0224 } |
|
5174 }; |
|
5175 |
|
5176 rtl_csi_access_enable_1(tp); |
|
5177 |
|
5178 rtl_ephy_init(tp, e_info_8168e_2, ARRAY_SIZE(e_info_8168e_2)); |
|
5179 |
|
5180 if (tp->dev->mtu <= ETH_DATA_LEN) |
|
5181 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
5182 |
|
5183 rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
|
5184 rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
|
5185 rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
|
5186 rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
|
5187 rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
|
5188 rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x07ff0060, ERIAR_EXGMAC); |
|
5189 rtl_w1w0_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
|
5190 rtl_w1w0_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
|
5191 |
|
5192 RTL_W8(MaxTxPacketSize, EarlySize); |
|
5193 |
|
5194 rtl_disable_clock_request(pdev); |
|
5195 |
|
5196 RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
|
5197 RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB); |
|
5198 |
|
5199 /* Adjust EEE LED frequency */ |
|
5200 RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07); |
|
5201 |
|
5202 RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN); |
|
5203 RTL_W32(MISC, RTL_R32(MISC) | PWM_EN); |
|
5204 RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en); |
|
5205 } |
|
5206 |
|
5207 static void rtl_hw_start_8168f(struct rtl8169_private *tp) |
|
5208 { |
|
5209 void __iomem *ioaddr = tp->mmio_addr; |
|
5210 struct pci_dev *pdev = tp->pci_dev; |
|
5211 |
|
5212 rtl_csi_access_enable_2(tp); |
|
5213 |
|
5214 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
5215 |
|
5216 rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
|
5217 rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
|
5218 rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00100002, ERIAR_EXGMAC); |
|
5219 rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
|
5220 rtl_w1w0_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
|
5221 rtl_w1w0_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
|
5222 rtl_w1w0_eri(tp, 0x1b0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
|
5223 rtl_w1w0_eri(tp, 0x1d0, ERIAR_MASK_0001, 0x10, 0x00, ERIAR_EXGMAC); |
|
5224 rtl_eri_write(tp, 0xcc, ERIAR_MASK_1111, 0x00000050, ERIAR_EXGMAC); |
|
5225 rtl_eri_write(tp, 0xd0, ERIAR_MASK_1111, 0x00000060, ERIAR_EXGMAC); |
|
5226 |
|
5227 RTL_W8(MaxTxPacketSize, EarlySize); |
|
5228 |
|
5229 rtl_disable_clock_request(pdev); |
|
5230 |
|
5231 RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
|
5232 RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB); |
|
5233 RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN); |
|
5234 RTL_W32(MISC, RTL_R32(MISC) | PWM_EN); |
|
5235 RTL_W8(Config5, RTL_R8(Config5) & ~Spi_en); |
|
5236 } |
|
5237 |
|
5238 static void rtl_hw_start_8168f_1(struct rtl8169_private *tp) |
|
5239 { |
|
5240 void __iomem *ioaddr = tp->mmio_addr; |
|
5241 static const struct ephy_info e_info_8168f_1[] = { |
|
5242 { 0x06, 0x00c0, 0x0020 }, |
|
5243 { 0x08, 0x0001, 0x0002 }, |
|
5244 { 0x09, 0x0000, 0x0080 }, |
|
5245 { 0x19, 0x0000, 0x0224 } |
|
5246 }; |
|
5247 |
|
5248 rtl_hw_start_8168f(tp); |
|
5249 |
|
5250 rtl_ephy_init(tp, e_info_8168f_1, ARRAY_SIZE(e_info_8168f_1)); |
|
5251 |
|
5252 rtl_w1w0_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0xff00, ERIAR_EXGMAC); |
|
5253 |
|
5254 /* Adjust EEE LED frequency */ |
|
5255 RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07); |
|
5256 } |
|
5257 |
|
5258 static void rtl_hw_start_8411(struct rtl8169_private *tp) |
|
5259 { |
|
5260 static const struct ephy_info e_info_8168f_1[] = { |
|
5261 { 0x06, 0x00c0, 0x0020 }, |
|
5262 { 0x0f, 0xffff, 0x5200 }, |
|
5263 { 0x1e, 0x0000, 0x4000 }, |
|
5264 { 0x19, 0x0000, 0x0224 } |
|
5265 }; |
|
5266 |
|
5267 rtl_hw_start_8168f(tp); |
|
5268 |
|
5269 rtl_ephy_init(tp, e_info_8168f_1, ARRAY_SIZE(e_info_8168f_1)); |
|
5270 |
|
5271 rtl_w1w0_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0c00, 0x0000, ERIAR_EXGMAC); |
|
5272 } |
|
5273 |
|
5274 static void rtl_hw_start_8168g_1(struct rtl8169_private *tp) |
|
5275 { |
|
5276 void __iomem *ioaddr = tp->mmio_addr; |
|
5277 struct pci_dev *pdev = tp->pci_dev; |
|
5278 |
|
5279 RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
|
5280 |
|
5281 rtl_eri_write(tp, 0xc8, ERIAR_MASK_0101, 0x080002, ERIAR_EXGMAC); |
|
5282 rtl_eri_write(tp, 0xcc, ERIAR_MASK_0001, 0x38, ERIAR_EXGMAC); |
|
5283 rtl_eri_write(tp, 0xd0, ERIAR_MASK_0001, 0x48, ERIAR_EXGMAC); |
|
5284 rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00100006, ERIAR_EXGMAC); |
|
5285 |
|
5286 rtl_csi_access_enable_1(tp); |
|
5287 |
|
5288 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
5289 |
|
5290 rtl_w1w0_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
|
5291 rtl_w1w0_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
|
5292 rtl_eri_write(tp, 0x2f8, ERIAR_MASK_0011, 0x1d8f, ERIAR_EXGMAC); |
|
5293 |
|
5294 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
|
5295 RTL_W32(MISC, RTL_R32(MISC) & ~RXDV_GATED_EN); |
|
5296 RTL_W8(MaxTxPacketSize, EarlySize); |
|
5297 |
|
5298 rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
|
5299 rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
|
5300 |
|
5301 /* Adjust EEE LED frequency */ |
|
5302 RTL_W8(EEE_LED, RTL_R8(EEE_LED) & ~0x07); |
|
5303 |
|
5304 rtl_w1w0_eri(tp, 0x2fc, ERIAR_MASK_0001, 0x01, 0x06, ERIAR_EXGMAC); |
|
5305 rtl_w1w0_eri(tp, 0x1b0, ERIAR_MASK_0011, 0x0000, 0x1000, ERIAR_EXGMAC); |
|
5306 } |
|
5307 |
|
5308 static void rtl_hw_start_8168g_2(struct rtl8169_private *tp) |
|
5309 { |
|
5310 void __iomem *ioaddr = tp->mmio_addr; |
|
5311 static const struct ephy_info e_info_8168g_2[] = { |
|
5312 { 0x00, 0x0000, 0x0008 }, |
|
5313 { 0x0c, 0x3df0, 0x0200 }, |
|
5314 { 0x19, 0xffff, 0xfc00 }, |
|
5315 { 0x1e, 0xffff, 0x20eb } |
|
5316 }; |
|
5317 |
|
5318 rtl_hw_start_8168g_1(tp); |
|
5319 |
|
5320 /* disable aspm and clock request before access ephy */ |
|
5321 RTL_W8(Config2, RTL_R8(Config2) & ~ClkReqEn); |
|
5322 RTL_W8(Config5, RTL_R8(Config5) & ~ASPM_en); |
|
5323 rtl_ephy_init(tp, e_info_8168g_2, ARRAY_SIZE(e_info_8168g_2)); |
|
5324 } |
|
5325 |
|
5326 static void rtl_hw_start_8411_2(struct rtl8169_private *tp) |
|
5327 { |
|
5328 void __iomem *ioaddr = tp->mmio_addr; |
|
5329 static const struct ephy_info e_info_8411_2[] = { |
|
5330 { 0x00, 0x0000, 0x0008 }, |
|
5331 { 0x0c, 0x3df0, 0x0200 }, |
|
5332 { 0x0f, 0xffff, 0x5200 }, |
|
5333 { 0x19, 0x0020, 0x0000 }, |
|
5334 { 0x1e, 0x0000, 0x2000 } |
|
5335 }; |
|
5336 |
|
5337 rtl_hw_start_8168g_1(tp); |
|
5338 |
|
5339 /* disable aspm and clock request before access ephy */ |
|
5340 RTL_W8(Config2, RTL_R8(Config2) & ~ClkReqEn); |
|
5341 RTL_W8(Config5, RTL_R8(Config5) & ~ASPM_en); |
|
5342 rtl_ephy_init(tp, e_info_8411_2, ARRAY_SIZE(e_info_8411_2)); |
|
5343 } |
|
5344 |
|
5345 static void rtl_hw_start_8168(struct net_device *dev) |
|
5346 { |
|
5347 struct rtl8169_private *tp = netdev_priv(dev); |
|
5348 void __iomem *ioaddr = tp->mmio_addr; |
|
5349 |
|
5350 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
5351 |
|
5352 RTL_W8(MaxTxPacketSize, TxPacketMax); |
|
5353 |
|
5354 rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
|
5355 |
|
5356 tp->cp_cmd |= RTL_R16(CPlusCmd) | PktCntrDisable | INTT_1; |
|
5357 |
|
5358 RTL_W16(CPlusCmd, tp->cp_cmd); |
|
5359 |
|
5360 RTL_W16(IntrMitigate, 0x5151); |
|
5361 |
|
5362 /* Work around for RxFIFO overflow. */ |
|
5363 if (tp->mac_version == RTL_GIGA_MAC_VER_11) { |
|
5364 tp->event_slow |= RxFIFOOver | PCSTimeout; |
|
5365 tp->event_slow &= ~RxOverflow; |
|
5366 } |
|
5367 |
|
5368 rtl_set_rx_tx_desc_registers(tp, ioaddr); |
|
5369 |
|
5370 rtl_set_rx_tx_config_registers(tp); |
|
5371 |
|
5372 RTL_R8(IntrMask); |
|
5373 |
|
5374 switch (tp->mac_version) { |
|
5375 case RTL_GIGA_MAC_VER_11: |
|
5376 rtl_hw_start_8168bb(tp); |
|
5377 break; |
|
5378 |
|
5379 case RTL_GIGA_MAC_VER_12: |
|
5380 case RTL_GIGA_MAC_VER_17: |
|
5381 rtl_hw_start_8168bef(tp); |
|
5382 break; |
|
5383 |
|
5384 case RTL_GIGA_MAC_VER_18: |
|
5385 rtl_hw_start_8168cp_1(tp); |
|
5386 break; |
|
5387 |
|
5388 case RTL_GIGA_MAC_VER_19: |
|
5389 rtl_hw_start_8168c_1(tp); |
|
5390 break; |
|
5391 |
|
5392 case RTL_GIGA_MAC_VER_20: |
|
5393 rtl_hw_start_8168c_2(tp); |
|
5394 break; |
|
5395 |
|
5396 case RTL_GIGA_MAC_VER_21: |
|
5397 rtl_hw_start_8168c_3(tp); |
|
5398 break; |
|
5399 |
|
5400 case RTL_GIGA_MAC_VER_22: |
|
5401 rtl_hw_start_8168c_4(tp); |
|
5402 break; |
|
5403 |
|
5404 case RTL_GIGA_MAC_VER_23: |
|
5405 rtl_hw_start_8168cp_2(tp); |
|
5406 break; |
|
5407 |
|
5408 case RTL_GIGA_MAC_VER_24: |
|
5409 rtl_hw_start_8168cp_3(tp); |
|
5410 break; |
|
5411 |
|
5412 case RTL_GIGA_MAC_VER_25: |
|
5413 case RTL_GIGA_MAC_VER_26: |
|
5414 case RTL_GIGA_MAC_VER_27: |
|
5415 rtl_hw_start_8168d(tp); |
|
5416 break; |
|
5417 |
|
5418 case RTL_GIGA_MAC_VER_28: |
|
5419 rtl_hw_start_8168d_4(tp); |
|
5420 break; |
|
5421 |
|
5422 case RTL_GIGA_MAC_VER_31: |
|
5423 rtl_hw_start_8168dp(tp); |
|
5424 break; |
|
5425 |
|
5426 case RTL_GIGA_MAC_VER_32: |
|
5427 case RTL_GIGA_MAC_VER_33: |
|
5428 rtl_hw_start_8168e_1(tp); |
|
5429 break; |
|
5430 case RTL_GIGA_MAC_VER_34: |
|
5431 rtl_hw_start_8168e_2(tp); |
|
5432 break; |
|
5433 |
|
5434 case RTL_GIGA_MAC_VER_35: |
|
5435 case RTL_GIGA_MAC_VER_36: |
|
5436 rtl_hw_start_8168f_1(tp); |
|
5437 break; |
|
5438 |
|
5439 case RTL_GIGA_MAC_VER_38: |
|
5440 rtl_hw_start_8411(tp); |
|
5441 break; |
|
5442 |
|
5443 case RTL_GIGA_MAC_VER_40: |
|
5444 case RTL_GIGA_MAC_VER_41: |
|
5445 rtl_hw_start_8168g_1(tp); |
|
5446 break; |
|
5447 case RTL_GIGA_MAC_VER_42: |
|
5448 rtl_hw_start_8168g_2(tp); |
|
5449 break; |
|
5450 |
|
5451 case RTL_GIGA_MAC_VER_44: |
|
5452 rtl_hw_start_8411_2(tp); |
|
5453 break; |
|
5454 |
|
5455 default: |
|
5456 printk(KERN_ERR PFX "%s: unknown chipset (mac_version = %d).\n", |
|
5457 dev->name, tp->mac_version); |
|
5458 break; |
|
5459 } |
|
5460 |
|
5461 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
5462 |
|
5463 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
|
5464 |
|
5465 rtl_set_rx_mode(dev); |
|
5466 |
|
5467 RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xF000); |
|
5468 } |
|
5469 |
|
5470 #define R810X_CPCMD_QUIRK_MASK (\ |
|
5471 EnableBist | \ |
|
5472 Mac_dbgo_oe | \ |
|
5473 Force_half_dup | \ |
|
5474 Force_rxflow_en | \ |
|
5475 Force_txflow_en | \ |
|
5476 Cxpl_dbg_sel | \ |
|
5477 ASF | \ |
|
5478 PktCntrDisable | \ |
|
5479 Mac_dbgo_sel) |
|
5480 |
|
5481 static void rtl_hw_start_8102e_1(struct rtl8169_private *tp) |
|
5482 { |
|
5483 void __iomem *ioaddr = tp->mmio_addr; |
|
5484 struct pci_dev *pdev = tp->pci_dev; |
|
5485 static const struct ephy_info e_info_8102e_1[] = { |
|
5486 { 0x01, 0, 0x6e65 }, |
|
5487 { 0x02, 0, 0x091f }, |
|
5488 { 0x03, 0, 0xc2f9 }, |
|
5489 { 0x06, 0, 0xafb5 }, |
|
5490 { 0x07, 0, 0x0e00 }, |
|
5491 { 0x19, 0, 0xec80 }, |
|
5492 { 0x01, 0, 0x2e65 }, |
|
5493 { 0x01, 0, 0x6e65 } |
|
5494 }; |
|
5495 u8 cfg1; |
|
5496 |
|
5497 rtl_csi_access_enable_2(tp); |
|
5498 |
|
5499 RTL_W8(DBG_REG, FIX_NAK_1); |
|
5500 |
|
5501 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
5502 |
|
5503 RTL_W8(Config1, |
|
5504 LEDS1 | LEDS0 | Speed_down | MEMMAP | IOMAP | VPD | PMEnable); |
|
5505 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
5506 |
|
5507 cfg1 = RTL_R8(Config1); |
|
5508 if ((cfg1 & LEDS0) && (cfg1 & LEDS1)) |
|
5509 RTL_W8(Config1, cfg1 & ~LEDS0); |
|
5510 |
|
5511 rtl_ephy_init(tp, e_info_8102e_1, ARRAY_SIZE(e_info_8102e_1)); |
|
5512 } |
|
5513 |
|
5514 static void rtl_hw_start_8102e_2(struct rtl8169_private *tp) |
|
5515 { |
|
5516 void __iomem *ioaddr = tp->mmio_addr; |
|
5517 struct pci_dev *pdev = tp->pci_dev; |
|
5518 |
|
5519 rtl_csi_access_enable_2(tp); |
|
5520 |
|
5521 rtl_tx_performance_tweak(pdev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
5522 |
|
5523 RTL_W8(Config1, MEMMAP | IOMAP | VPD | PMEnable); |
|
5524 RTL_W8(Config3, RTL_R8(Config3) & ~Beacon_en); |
|
5525 } |
|
5526 |
|
5527 static void rtl_hw_start_8102e_3(struct rtl8169_private *tp) |
|
5528 { |
|
5529 rtl_hw_start_8102e_2(tp); |
|
5530 |
|
5531 rtl_ephy_write(tp, 0x03, 0xc2f9); |
|
5532 } |
|
5533 |
|
5534 static void rtl_hw_start_8105e_1(struct rtl8169_private *tp) |
|
5535 { |
|
5536 void __iomem *ioaddr = tp->mmio_addr; |
|
5537 static const struct ephy_info e_info_8105e_1[] = { |
|
5538 { 0x07, 0, 0x4000 }, |
|
5539 { 0x19, 0, 0x0200 }, |
|
5540 { 0x19, 0, 0x0020 }, |
|
5541 { 0x1e, 0, 0x2000 }, |
|
5542 { 0x03, 0, 0x0001 }, |
|
5543 { 0x19, 0, 0x0100 }, |
|
5544 { 0x19, 0, 0x0004 }, |
|
5545 { 0x0a, 0, 0x0020 } |
|
5546 }; |
|
5547 |
|
5548 /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
|
5549 RTL_W32(FuncEvent, RTL_R32(FuncEvent) | 0x002800); |
|
5550 |
|
5551 /* Disable Early Tally Counter */ |
|
5552 RTL_W32(FuncEvent, RTL_R32(FuncEvent) & ~0x010000); |
|
5553 |
|
5554 RTL_W8(MCU, RTL_R8(MCU) | EN_NDP | EN_OOB_RESET); |
|
5555 RTL_W8(DLLPR, RTL_R8(DLLPR) | PFM_EN); |
|
5556 |
|
5557 rtl_ephy_init(tp, e_info_8105e_1, ARRAY_SIZE(e_info_8105e_1)); |
|
5558 } |
|
5559 |
|
5560 static void rtl_hw_start_8105e_2(struct rtl8169_private *tp) |
|
5561 { |
|
5562 rtl_hw_start_8105e_1(tp); |
|
5563 rtl_ephy_write(tp, 0x1e, rtl_ephy_read(tp, 0x1e) | 0x8000); |
|
5564 } |
|
5565 |
|
5566 static void rtl_hw_start_8402(struct rtl8169_private *tp) |
|
5567 { |
|
5568 void __iomem *ioaddr = tp->mmio_addr; |
|
5569 static const struct ephy_info e_info_8402[] = { |
|
5570 { 0x19, 0xffff, 0xff64 }, |
|
5571 { 0x1e, 0, 0x4000 } |
|
5572 }; |
|
5573 |
|
5574 rtl_csi_access_enable_2(tp); |
|
5575 |
|
5576 /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
|
5577 RTL_W32(FuncEvent, RTL_R32(FuncEvent) | 0x002800); |
|
5578 |
|
5579 RTL_W32(TxConfig, RTL_R32(TxConfig) | TXCFG_AUTO_FIFO); |
|
5580 RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB); |
|
5581 |
|
5582 rtl_ephy_init(tp, e_info_8402, ARRAY_SIZE(e_info_8402)); |
|
5583 |
|
5584 rtl_tx_performance_tweak(tp->pci_dev, 0x5 << MAX_READ_REQUEST_SHIFT); |
|
5585 |
|
5586 rtl_eri_write(tp, 0xc8, ERIAR_MASK_1111, 0x00000002, ERIAR_EXGMAC); |
|
5587 rtl_eri_write(tp, 0xe8, ERIAR_MASK_1111, 0x00000006, ERIAR_EXGMAC); |
|
5588 rtl_w1w0_eri(tp, 0xdc, ERIAR_MASK_0001, 0x00, 0x01, ERIAR_EXGMAC); |
|
5589 rtl_w1w0_eri(tp, 0xdc, ERIAR_MASK_0001, 0x01, 0x00, ERIAR_EXGMAC); |
|
5590 rtl_eri_write(tp, 0xc0, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
|
5591 rtl_eri_write(tp, 0xb8, ERIAR_MASK_0011, 0x0000, ERIAR_EXGMAC); |
|
5592 rtl_w1w0_eri(tp, 0x0d4, ERIAR_MASK_0011, 0x0e00, 0xff00, ERIAR_EXGMAC); |
|
5593 } |
|
5594 |
|
5595 static void rtl_hw_start_8106(struct rtl8169_private *tp) |
|
5596 { |
|
5597 void __iomem *ioaddr = tp->mmio_addr; |
|
5598 |
|
5599 /* Force LAN exit from ASPM if Rx/Tx are not idle */ |
|
5600 RTL_W32(FuncEvent, RTL_R32(FuncEvent) | 0x002800); |
|
5601 |
|
5602 RTL_W32(MISC, (RTL_R32(MISC) | DISABLE_LAN_EN) & ~EARLY_TALLY_EN); |
|
5603 RTL_W8(MCU, RTL_R8(MCU) | EN_NDP | EN_OOB_RESET); |
|
5604 RTL_W8(DLLPR, RTL_R8(DLLPR) & ~PFM_EN); |
|
5605 } |
|
5606 |
|
5607 static void rtl_hw_start_8101(struct net_device *dev) |
|
5608 { |
|
5609 struct rtl8169_private *tp = netdev_priv(dev); |
|
5610 void __iomem *ioaddr = tp->mmio_addr; |
|
5611 struct pci_dev *pdev = tp->pci_dev; |
|
5612 |
|
5613 if (tp->mac_version >= RTL_GIGA_MAC_VER_30) |
|
5614 tp->event_slow &= ~RxFIFOOver; |
|
5615 |
|
5616 if (tp->mac_version == RTL_GIGA_MAC_VER_13 || |
|
5617 tp->mac_version == RTL_GIGA_MAC_VER_16) |
|
5618 pcie_capability_set_word(pdev, PCI_EXP_DEVCTL, |
|
5619 PCI_EXP_DEVCTL_NOSNOOP_EN); |
|
5620 |
|
5621 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
5622 |
|
5623 RTL_W8(MaxTxPacketSize, TxPacketMax); |
|
5624 |
|
5625 rtl_set_rx_max_size(ioaddr, rx_buf_sz); |
|
5626 |
|
5627 tp->cp_cmd &= ~R810X_CPCMD_QUIRK_MASK; |
|
5628 RTL_W16(CPlusCmd, tp->cp_cmd); |
|
5629 |
|
5630 rtl_set_rx_tx_desc_registers(tp, ioaddr); |
|
5631 |
|
5632 rtl_set_rx_tx_config_registers(tp); |
|
5633 |
|
5634 switch (tp->mac_version) { |
|
5635 case RTL_GIGA_MAC_VER_07: |
|
5636 rtl_hw_start_8102e_1(tp); |
|
5637 break; |
|
5638 |
|
5639 case RTL_GIGA_MAC_VER_08: |
|
5640 rtl_hw_start_8102e_3(tp); |
|
5641 break; |
|
5642 |
|
5643 case RTL_GIGA_MAC_VER_09: |
|
5644 rtl_hw_start_8102e_2(tp); |
|
5645 break; |
|
5646 |
|
5647 case RTL_GIGA_MAC_VER_29: |
|
5648 rtl_hw_start_8105e_1(tp); |
|
5649 break; |
|
5650 case RTL_GIGA_MAC_VER_30: |
|
5651 rtl_hw_start_8105e_2(tp); |
|
5652 break; |
|
5653 |
|
5654 case RTL_GIGA_MAC_VER_37: |
|
5655 rtl_hw_start_8402(tp); |
|
5656 break; |
|
5657 |
|
5658 case RTL_GIGA_MAC_VER_39: |
|
5659 rtl_hw_start_8106(tp); |
|
5660 break; |
|
5661 case RTL_GIGA_MAC_VER_43: |
|
5662 rtl_hw_start_8168g_2(tp); |
|
5663 break; |
|
5664 } |
|
5665 |
|
5666 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
5667 |
|
5668 RTL_W16(IntrMitigate, 0x0000); |
|
5669 |
|
5670 RTL_W8(ChipCmd, CmdTxEnb | CmdRxEnb); |
|
5671 |
|
5672 rtl_set_rx_mode(dev); |
|
5673 |
|
5674 RTL_R8(IntrMask); |
|
5675 |
|
5676 RTL_W16(MultiIntr, RTL_R16(MultiIntr) & 0xf000); |
|
5677 } |
|
5678 |
|
5679 static int rtl8169_change_mtu(struct net_device *dev, int new_mtu) |
|
5680 { |
|
5681 struct rtl8169_private *tp = netdev_priv(dev); |
|
5682 |
|
5683 if (new_mtu < ETH_ZLEN || |
|
5684 new_mtu > rtl_chip_infos[tp->mac_version].jumbo_max) |
|
5685 return -EINVAL; |
|
5686 |
|
5687 if (new_mtu > ETH_DATA_LEN) |
|
5688 rtl_hw_jumbo_enable(tp); |
|
5689 else |
|
5690 rtl_hw_jumbo_disable(tp); |
|
5691 |
|
5692 dev->mtu = new_mtu; |
|
5693 netdev_update_features(dev); |
|
5694 |
|
5695 return 0; |
|
5696 } |
|
5697 |
|
5698 static inline void rtl8169_make_unusable_by_asic(struct RxDesc *desc) |
|
5699 { |
|
5700 desc->addr = cpu_to_le64(0x0badbadbadbadbadull); |
|
5701 desc->opts1 &= ~cpu_to_le32(DescOwn | RsvdMask); |
|
5702 } |
|
5703 |
|
5704 static void rtl8169_free_rx_databuff(struct rtl8169_private *tp, |
|
5705 void **data_buff, struct RxDesc *desc) |
|
5706 { |
|
5707 dma_unmap_single(&tp->pci_dev->dev, le64_to_cpu(desc->addr), rx_buf_sz, |
|
5708 DMA_FROM_DEVICE); |
|
5709 |
|
5710 kfree(*data_buff); |
|
5711 *data_buff = NULL; |
|
5712 rtl8169_make_unusable_by_asic(desc); |
|
5713 } |
|
5714 |
|
5715 static inline void rtl8169_mark_to_asic(struct RxDesc *desc, u32 rx_buf_sz) |
|
5716 { |
|
5717 u32 eor = le32_to_cpu(desc->opts1) & RingEnd; |
|
5718 |
|
5719 desc->opts1 = cpu_to_le32(DescOwn | eor | rx_buf_sz); |
|
5720 } |
|
5721 |
|
5722 static inline void rtl8169_map_to_asic(struct RxDesc *desc, dma_addr_t mapping, |
|
5723 u32 rx_buf_sz) |
|
5724 { |
|
5725 desc->addr = cpu_to_le64(mapping); |
|
5726 wmb(); |
|
5727 rtl8169_mark_to_asic(desc, rx_buf_sz); |
|
5728 } |
|
5729 |
|
5730 static inline void *rtl8169_align(void *data) |
|
5731 { |
|
5732 return (void *)ALIGN((long)data, 16); |
|
5733 } |
|
5734 |
|
5735 static struct sk_buff *rtl8169_alloc_rx_data(struct rtl8169_private *tp, |
|
5736 struct RxDesc *desc) |
|
5737 { |
|
5738 void *data; |
|
5739 dma_addr_t mapping; |
|
5740 struct device *d = &tp->pci_dev->dev; |
|
5741 struct net_device *dev = tp->dev; |
|
5742 int node = dev->dev.parent ? dev_to_node(dev->dev.parent) : -1; |
|
5743 |
|
5744 data = kmalloc_node(rx_buf_sz, GFP_KERNEL, node); |
|
5745 if (!data) |
|
5746 return NULL; |
|
5747 |
|
5748 if (rtl8169_align(data) != data) { |
|
5749 kfree(data); |
|
5750 data = kmalloc_node(rx_buf_sz + 15, GFP_KERNEL, node); |
|
5751 if (!data) |
|
5752 return NULL; |
|
5753 } |
|
5754 |
|
5755 mapping = dma_map_single(d, rtl8169_align(data), rx_buf_sz, |
|
5756 DMA_FROM_DEVICE); |
|
5757 if (unlikely(dma_mapping_error(d, mapping))) { |
|
5758 if (net_ratelimit()) |
|
5759 netif_err(tp, drv, tp->dev, "Failed to map RX DMA!\n"); |
|
5760 goto err_out; |
|
5761 } |
|
5762 |
|
5763 rtl8169_map_to_asic(desc, mapping, rx_buf_sz); |
|
5764 return data; |
|
5765 |
|
5766 err_out: |
|
5767 kfree(data); |
|
5768 return NULL; |
|
5769 } |
|
5770 |
|
5771 static void rtl8169_rx_clear(struct rtl8169_private *tp) |
|
5772 { |
|
5773 unsigned int i; |
|
5774 |
|
5775 for (i = 0; i < NUM_RX_DESC; i++) { |
|
5776 if (tp->Rx_databuff[i]) { |
|
5777 rtl8169_free_rx_databuff(tp, tp->Rx_databuff + i, |
|
5778 tp->RxDescArray + i); |
|
5779 } |
|
5780 } |
|
5781 } |
|
5782 |
|
5783 static inline void rtl8169_mark_as_last_descriptor(struct RxDesc *desc) |
|
5784 { |
|
5785 desc->opts1 |= cpu_to_le32(RingEnd); |
|
5786 } |
|
5787 |
|
5788 static int rtl8169_rx_fill(struct rtl8169_private *tp) |
|
5789 { |
|
5790 unsigned int i; |
|
5791 |
|
5792 for (i = 0; i < NUM_RX_DESC; i++) { |
|
5793 void *data; |
|
5794 |
|
5795 if (tp->Rx_databuff[i]) |
|
5796 continue; |
|
5797 |
|
5798 data = rtl8169_alloc_rx_data(tp, tp->RxDescArray + i); |
|
5799 if (!data) { |
|
5800 rtl8169_make_unusable_by_asic(tp->RxDescArray + i); |
|
5801 goto err_out; |
|
5802 } |
|
5803 tp->Rx_databuff[i] = data; |
|
5804 } |
|
5805 |
|
5806 rtl8169_mark_as_last_descriptor(tp->RxDescArray + NUM_RX_DESC - 1); |
|
5807 return 0; |
|
5808 |
|
5809 err_out: |
|
5810 rtl8169_rx_clear(tp); |
|
5811 return -ENOMEM; |
|
5812 } |
|
5813 |
|
5814 static int rtl8169_init_ring(struct net_device *dev) |
|
5815 { |
|
5816 struct rtl8169_private *tp = netdev_priv(dev); |
|
5817 |
|
5818 rtl8169_init_ring_indexes(tp); |
|
5819 |
|
5820 memset(tp->tx_skb, 0x0, NUM_TX_DESC * sizeof(struct ring_info)); |
|
5821 memset(tp->Rx_databuff, 0x0, NUM_RX_DESC * sizeof(void *)); |
|
5822 |
|
5823 return rtl8169_rx_fill(tp); |
|
5824 } |
|
5825 |
|
5826 static void rtl8169_unmap_tx_skb(struct device *d, struct ring_info *tx_skb, |
|
5827 struct TxDesc *desc) |
|
5828 { |
|
5829 unsigned int len = tx_skb->len; |
|
5830 |
|
5831 dma_unmap_single(d, le64_to_cpu(desc->addr), len, DMA_TO_DEVICE); |
|
5832 |
|
5833 desc->opts1 = 0x00; |
|
5834 desc->opts2 = 0x00; |
|
5835 desc->addr = 0x00; |
|
5836 tx_skb->len = 0; |
|
5837 } |
|
5838 |
|
5839 static void rtl8169_tx_clear_range(struct rtl8169_private *tp, u32 start, |
|
5840 unsigned int n) |
|
5841 { |
|
5842 unsigned int i; |
|
5843 |
|
5844 for (i = 0; i < n; i++) { |
|
5845 unsigned int entry = (start + i) % NUM_TX_DESC; |
|
5846 struct ring_info *tx_skb = tp->tx_skb + entry; |
|
5847 unsigned int len = tx_skb->len; |
|
5848 |
|
5849 if (len) { |
|
5850 struct sk_buff *skb = tx_skb->skb; |
|
5851 |
|
5852 rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb, |
|
5853 tp->TxDescArray + entry); |
|
5854 if (skb) { |
|
5855 tp->dev->stats.tx_dropped++; |
|
5856 if (!tp->ecdev) { |
|
5857 dev_kfree_skb(skb); |
|
5858 } |
|
5859 tx_skb->skb = NULL; |
|
5860 } |
|
5861 } |
|
5862 } |
|
5863 } |
|
5864 |
|
5865 static void rtl8169_tx_clear(struct rtl8169_private *tp) |
|
5866 { |
|
5867 rtl8169_tx_clear_range(tp, tp->dirty_tx, NUM_TX_DESC); |
|
5868 tp->cur_tx = tp->dirty_tx = 0; |
|
5869 } |
|
5870 |
|
5871 static void rtl_reset_work(struct rtl8169_private *tp) |
|
5872 { |
|
5873 struct net_device *dev = tp->dev; |
|
5874 int i; |
|
5875 |
|
5876 napi_disable(&tp->napi); |
|
5877 netif_stop_queue(dev); |
|
5878 synchronize_sched(); |
|
5879 |
|
5880 rtl8169_hw_reset(tp); |
|
5881 |
|
5882 for (i = 0; i < NUM_RX_DESC; i++) |
|
5883 rtl8169_mark_to_asic(tp->RxDescArray + i, rx_buf_sz); |
|
5884 |
|
5885 rtl8169_tx_clear(tp); |
|
5886 rtl8169_init_ring_indexes(tp); |
|
5887 |
|
5888 napi_enable(&tp->napi); |
|
5889 rtl_hw_start(dev); |
|
5890 netif_wake_queue(dev); |
|
5891 rtl8169_check_link_status(dev, tp, tp->mmio_addr); |
|
5892 } |
|
5893 |
|
5894 static void rtl8169_tx_timeout(struct net_device *dev) |
|
5895 { |
|
5896 struct rtl8169_private *tp = netdev_priv(dev); |
|
5897 |
|
5898 if (!tp->ecdev) { |
|
5899 rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
|
5900 } |
|
5901 } |
|
5902 |
|
5903 static int rtl8169_xmit_frags(struct rtl8169_private *tp, struct sk_buff *skb, |
|
5904 u32 *opts) |
|
5905 { |
|
5906 struct skb_shared_info *info = skb_shinfo(skb); |
|
5907 unsigned int cur_frag, entry; |
|
5908 struct TxDesc * uninitialized_var(txd); |
|
5909 struct device *d = &tp->pci_dev->dev; |
|
5910 |
|
5911 entry = tp->cur_tx; |
|
5912 for (cur_frag = 0; cur_frag < info->nr_frags; cur_frag++) { |
|
5913 const skb_frag_t *frag = info->frags + cur_frag; |
|
5914 dma_addr_t mapping; |
|
5915 u32 status, len; |
|
5916 void *addr; |
|
5917 |
|
5918 entry = (entry + 1) % NUM_TX_DESC; |
|
5919 |
|
5920 txd = tp->TxDescArray + entry; |
|
5921 len = skb_frag_size(frag); |
|
5922 addr = skb_frag_address(frag); |
|
5923 mapping = dma_map_single(d, addr, len, DMA_TO_DEVICE); |
|
5924 if (unlikely(dma_mapping_error(d, mapping))) { |
|
5925 if (net_ratelimit()) |
|
5926 netif_err(tp, drv, tp->dev, |
|
5927 "Failed to map TX fragments DMA!\n"); |
|
5928 goto err_out; |
|
5929 } |
|
5930 |
|
5931 /* Anti gcc 2.95.3 bugware (sic) */ |
|
5932 status = opts[0] | len | |
|
5933 (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
|
5934 |
|
5935 txd->opts1 = cpu_to_le32(status); |
|
5936 txd->opts2 = cpu_to_le32(opts[1]); |
|
5937 txd->addr = cpu_to_le64(mapping); |
|
5938 |
|
5939 tp->tx_skb[entry].len = len; |
|
5940 } |
|
5941 |
|
5942 if (cur_frag) { |
|
5943 tp->tx_skb[entry].skb = skb; |
|
5944 txd->opts1 |= cpu_to_le32(LastFrag); |
|
5945 } |
|
5946 |
|
5947 return cur_frag; |
|
5948 |
|
5949 err_out: |
|
5950 rtl8169_tx_clear_range(tp, tp->cur_tx + 1, cur_frag); |
|
5951 return -EIO; |
|
5952 } |
|
5953 |
|
5954 static bool rtl_skb_pad(struct sk_buff *skb) |
|
5955 { |
|
5956 if (skb_padto(skb, ETH_ZLEN)) |
|
5957 return false; |
|
5958 skb_put(skb, ETH_ZLEN - skb->len); |
|
5959 return true; |
|
5960 } |
|
5961 |
|
5962 static bool rtl_test_hw_pad_bug(struct rtl8169_private *tp, struct sk_buff *skb) |
|
5963 { |
|
5964 return skb->len < ETH_ZLEN && tp->mac_version == RTL_GIGA_MAC_VER_34; |
|
5965 } |
|
5966 |
|
5967 static inline bool rtl8169_tso_csum(struct rtl8169_private *tp, |
|
5968 struct sk_buff *skb, u32 *opts) |
|
5969 { |
|
5970 const struct rtl_tx_desc_info *info = tx_desc_info + tp->txd_version; |
|
5971 u32 mss = skb_shinfo(skb)->gso_size; |
|
5972 int offset = info->opts_offset; |
|
5973 |
|
5974 if (mss) { |
|
5975 opts[0] |= TD_LSO; |
|
5976 opts[offset] |= min(mss, TD_MSS_MAX) << info->mss_shift; |
|
5977 } else if (skb->ip_summed == CHECKSUM_PARTIAL) { |
|
5978 const struct iphdr *ip = ip_hdr(skb); |
|
5979 |
|
5980 if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
|
5981 return skb_checksum_help(skb) == 0 && rtl_skb_pad(skb); |
|
5982 |
|
5983 if (ip->protocol == IPPROTO_TCP) |
|
5984 opts[offset] |= info->checksum.tcp; |
|
5985 else if (ip->protocol == IPPROTO_UDP) |
|
5986 opts[offset] |= info->checksum.udp; |
|
5987 else |
|
5988 WARN_ON_ONCE(1); |
|
5989 } else { |
|
5990 if (unlikely(rtl_test_hw_pad_bug(tp, skb))) |
|
5991 return rtl_skb_pad(skb); |
|
5992 } |
|
5993 return true; |
|
5994 } |
|
5995 |
|
5996 static netdev_tx_t rtl8169_start_xmit(struct sk_buff *skb, |
|
5997 struct net_device *dev) |
|
5998 { |
|
5999 struct rtl8169_private *tp = netdev_priv(dev); |
|
6000 unsigned int entry = tp->cur_tx % NUM_TX_DESC; |
|
6001 struct TxDesc *txd = tp->TxDescArray + entry; |
|
6002 void __iomem *ioaddr = tp->mmio_addr; |
|
6003 struct device *d = &tp->pci_dev->dev; |
|
6004 dma_addr_t mapping; |
|
6005 u32 status, len; |
|
6006 u32 opts[2]; |
|
6007 int frags; |
|
6008 |
|
6009 if (unlikely(!TX_FRAGS_READY_FOR(tp, skb_shinfo(skb)->nr_frags))) { |
|
6010 netif_err(tp, drv, dev, "BUG! Tx Ring full when queue awake!\n"); |
|
6011 goto err_stop_0; |
|
6012 } |
|
6013 |
|
6014 if (unlikely(le32_to_cpu(txd->opts1) & DescOwn)) |
|
6015 goto err_stop_0; |
|
6016 |
|
6017 opts[1] = cpu_to_le32(rtl8169_tx_vlan_tag(skb)); |
|
6018 opts[0] = DescOwn; |
|
6019 |
|
6020 if (!rtl8169_tso_csum(tp, skb, opts)) |
|
6021 goto err_update_stats; |
|
6022 |
|
6023 len = skb_headlen(skb); |
|
6024 mapping = dma_map_single(d, skb->data, len, DMA_TO_DEVICE); |
|
6025 if (unlikely(dma_mapping_error(d, mapping))) { |
|
6026 if (net_ratelimit()) |
|
6027 netif_err(tp, drv, dev, "Failed to map TX DMA!\n"); |
|
6028 goto err_dma_0; |
|
6029 } |
|
6030 |
|
6031 tp->tx_skb[entry].len = len; |
|
6032 txd->addr = cpu_to_le64(mapping); |
|
6033 |
|
6034 frags = rtl8169_xmit_frags(tp, skb, opts); |
|
6035 if (frags < 0) |
|
6036 goto err_dma_1; |
|
6037 else if (frags) |
|
6038 opts[0] |= FirstFrag; |
|
6039 else { |
|
6040 opts[0] |= FirstFrag | LastFrag; |
|
6041 tp->tx_skb[entry].skb = skb; |
|
6042 } |
|
6043 |
|
6044 txd->opts2 = cpu_to_le32(opts[1]); |
|
6045 |
|
6046 skb_tx_timestamp(skb); |
|
6047 |
|
6048 wmb(); |
|
6049 |
|
6050 /* Anti gcc 2.95.3 bugware (sic) */ |
|
6051 status = opts[0] | len | (RingEnd * !((entry + 1) % NUM_TX_DESC)); |
|
6052 txd->opts1 = cpu_to_le32(status); |
|
6053 |
|
6054 tp->cur_tx += frags + 1; |
|
6055 |
|
6056 wmb(); |
|
6057 |
|
6058 RTL_W8(TxPoll, NPQ); |
|
6059 |
|
6060 mmiowb(); |
|
6061 |
|
6062 if (!TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
|
6063 /* Avoid wrongly optimistic queue wake-up: rtl_tx thread must |
|
6064 * not miss a ring update when it notices a stopped queue. |
|
6065 */ |
|
6066 smp_wmb(); |
|
6067 if (!tp->ecdev) { |
|
6068 netif_stop_queue(dev); |
|
6069 } |
|
6070 /* Sync with rtl_tx: |
|
6071 * - publish queue status and cur_tx ring index (write barrier) |
|
6072 * - refresh dirty_tx ring index (read barrier). |
|
6073 * May the current thread have a pessimistic view of the ring |
|
6074 * status and forget to wake up queue, a racing rtl_tx thread |
|
6075 * can't. |
|
6076 */ |
|
6077 smp_mb(); |
|
6078 if (!tp->ecdev && TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) |
|
6079 netif_wake_queue(dev); |
|
6080 } |
|
6081 |
|
6082 return NETDEV_TX_OK; |
|
6083 |
|
6084 err_dma_1: |
|
6085 rtl8169_unmap_tx_skb(d, tp->tx_skb + entry, txd); |
|
6086 err_dma_0: |
|
6087 if (!tp->ecdev) { |
|
6088 dev_kfree_skb(skb); |
|
6089 } |
|
6090 err_update_stats: |
|
6091 dev->stats.tx_dropped++; |
|
6092 return NETDEV_TX_OK; |
|
6093 |
|
6094 err_stop_0: |
|
6095 if (!tp->ecdev) { |
|
6096 netif_stop_queue(dev); |
|
6097 } |
|
6098 dev->stats.tx_dropped++; |
|
6099 return NETDEV_TX_BUSY; |
|
6100 } |
|
6101 |
|
6102 static void rtl8169_pcierr_interrupt(struct net_device *dev) |
|
6103 { |
|
6104 struct rtl8169_private *tp = netdev_priv(dev); |
|
6105 struct pci_dev *pdev = tp->pci_dev; |
|
6106 u16 pci_status, pci_cmd; |
|
6107 |
|
6108 pci_read_config_word(pdev, PCI_COMMAND, &pci_cmd); |
|
6109 pci_read_config_word(pdev, PCI_STATUS, &pci_status); |
|
6110 |
|
6111 netif_err(tp, intr, dev, "PCI error (cmd = 0x%04x, status = 0x%04x)\n", |
|
6112 pci_cmd, pci_status); |
|
6113 |
|
6114 /* |
|
6115 * The recovery sequence below admits a very elaborated explanation: |
|
6116 * - it seems to work; |
|
6117 * - I did not see what else could be done; |
|
6118 * - it makes iop3xx happy. |
|
6119 * |
|
6120 * Feel free to adjust to your needs. |
|
6121 */ |
|
6122 if (pdev->broken_parity_status) |
|
6123 pci_cmd &= ~PCI_COMMAND_PARITY; |
|
6124 else |
|
6125 pci_cmd |= PCI_COMMAND_SERR | PCI_COMMAND_PARITY; |
|
6126 |
|
6127 pci_write_config_word(pdev, PCI_COMMAND, pci_cmd); |
|
6128 |
|
6129 pci_write_config_word(pdev, PCI_STATUS, |
|
6130 pci_status & (PCI_STATUS_DETECTED_PARITY | |
|
6131 PCI_STATUS_SIG_SYSTEM_ERROR | PCI_STATUS_REC_MASTER_ABORT | |
|
6132 PCI_STATUS_REC_TARGET_ABORT | PCI_STATUS_SIG_TARGET_ABORT)); |
|
6133 |
|
6134 /* The infamous DAC f*ckup only happens at boot time */ |
|
6135 if ((tp->cp_cmd & PCIDAC) && !tp->cur_rx) { |
|
6136 void __iomem *ioaddr = tp->mmio_addr; |
|
6137 |
|
6138 netif_info(tp, intr, dev, "disabling PCI DAC\n"); |
|
6139 tp->cp_cmd &= ~PCIDAC; |
|
6140 RTL_W16(CPlusCmd, tp->cp_cmd); |
|
6141 dev->features &= ~NETIF_F_HIGHDMA; |
|
6142 } |
|
6143 |
|
6144 rtl8169_hw_reset(tp); |
|
6145 |
|
6146 rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
|
6147 } |
|
6148 |
|
6149 static void rtl_tx(struct net_device *dev, struct rtl8169_private *tp) |
|
6150 { |
|
6151 unsigned int dirty_tx, tx_left; |
|
6152 |
|
6153 dirty_tx = tp->dirty_tx; |
|
6154 smp_rmb(); |
|
6155 tx_left = tp->cur_tx - dirty_tx; |
|
6156 |
|
6157 while (tx_left > 0) { |
|
6158 unsigned int entry = dirty_tx % NUM_TX_DESC; |
|
6159 struct ring_info *tx_skb = tp->tx_skb + entry; |
|
6160 u32 status; |
|
6161 |
|
6162 rmb(); |
|
6163 status = le32_to_cpu(tp->TxDescArray[entry].opts1); |
|
6164 if (status & DescOwn) |
|
6165 break; |
|
6166 |
|
6167 rtl8169_unmap_tx_skb(&tp->pci_dev->dev, tx_skb, |
|
6168 tp->TxDescArray + entry); |
|
6169 if (status & LastFrag) { |
|
6170 u64_stats_update_begin(&tp->tx_stats.syncp); |
|
6171 tp->tx_stats.packets++; |
|
6172 tp->tx_stats.bytes += tx_skb->skb->len; |
|
6173 u64_stats_update_end(&tp->tx_stats.syncp); |
|
6174 if (!tp->ecdev) { |
|
6175 dev_kfree_skb(tx_skb->skb); |
|
6176 } |
|
6177 tx_skb->skb = NULL; |
|
6178 } |
|
6179 dirty_tx++; |
|
6180 tx_left--; |
|
6181 } |
|
6182 |
|
6183 if (tp->dirty_tx != dirty_tx) { |
|
6184 tp->dirty_tx = dirty_tx; |
|
6185 /* Sync with rtl8169_start_xmit: |
|
6186 * - publish dirty_tx ring index (write barrier) |
|
6187 * - refresh cur_tx ring index and queue status (read barrier) |
|
6188 * May the current thread miss the stopped queue condition, |
|
6189 * a racing xmit thread can only have a right view of the |
|
6190 * ring status. |
|
6191 */ |
|
6192 smp_mb(); |
|
6193 if (!tp->ecdev && netif_queue_stopped(dev) && |
|
6194 TX_FRAGS_READY_FOR(tp, MAX_SKB_FRAGS)) { |
|
6195 netif_wake_queue(dev); |
|
6196 } |
|
6197 /* |
|
6198 * 8168 hack: TxPoll requests are lost when the Tx packets are |
|
6199 * too close. Let's kick an extra TxPoll request when a burst |
|
6200 * of start_xmit activity is detected (if it is not detected, |
|
6201 * it is slow enough). -- FR |
|
6202 */ |
|
6203 if (tp->cur_tx != dirty_tx) { |
|
6204 void __iomem *ioaddr = tp->mmio_addr; |
|
6205 |
|
6206 RTL_W8(TxPoll, NPQ); |
|
6207 } |
|
6208 } |
|
6209 } |
|
6210 |
|
6211 static inline int rtl8169_fragmented_frame(u32 status) |
|
6212 { |
|
6213 return (status & (FirstFrag | LastFrag)) != (FirstFrag | LastFrag); |
|
6214 } |
|
6215 |
|
6216 static inline void rtl8169_rx_csum(struct sk_buff *skb, u32 opts1) |
|
6217 { |
|
6218 u32 status = opts1 & RxProtoMask; |
|
6219 |
|
6220 if (((status == RxProtoTCP) && !(opts1 & TCPFail)) || |
|
6221 ((status == RxProtoUDP) && !(opts1 & UDPFail))) |
|
6222 skb->ip_summed = CHECKSUM_UNNECESSARY; |
|
6223 else |
|
6224 skb_checksum_none_assert(skb); |
|
6225 } |
|
6226 |
|
6227 static struct sk_buff *rtl8169_try_rx_copy(void *data, |
|
6228 struct rtl8169_private *tp, |
|
6229 int pkt_size, |
|
6230 dma_addr_t addr) |
|
6231 { |
|
6232 struct sk_buff *skb; |
|
6233 struct device *d = &tp->pci_dev->dev; |
|
6234 |
|
6235 data = rtl8169_align(data); |
|
6236 dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE); |
|
6237 prefetch(data); |
|
6238 skb = netdev_alloc_skb_ip_align(tp->dev, pkt_size); |
|
6239 if (skb) |
|
6240 memcpy(skb->data, data, pkt_size); |
|
6241 dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE); |
|
6242 |
|
6243 return skb; |
|
6244 } |
|
6245 |
|
6246 static int rtl_rx(struct net_device *dev, struct rtl8169_private *tp, u32 budget) |
|
6247 { |
|
6248 unsigned int cur_rx, rx_left; |
|
6249 unsigned int count; |
|
6250 |
|
6251 cur_rx = tp->cur_rx; |
|
6252 |
|
6253 for (rx_left = min(budget, NUM_RX_DESC); rx_left > 0; rx_left--, cur_rx++) { |
|
6254 unsigned int entry = cur_rx % NUM_RX_DESC; |
|
6255 struct RxDesc *desc = tp->RxDescArray + entry; |
|
6256 u32 status; |
|
6257 |
|
6258 rmb(); |
|
6259 status = le32_to_cpu(desc->opts1) & tp->opts1_mask; |
|
6260 |
|
6261 if (status & DescOwn) |
|
6262 break; |
|
6263 if (unlikely(status & RxRES)) { |
|
6264 netif_info(tp, rx_err, dev, "Rx ERROR. status = %08x\n", |
|
6265 status); |
|
6266 dev->stats.rx_errors++; |
|
6267 if (status & (RxRWT | RxRUNT)) |
|
6268 dev->stats.rx_length_errors++; |
|
6269 if (status & RxCRC) |
|
6270 dev->stats.rx_crc_errors++; |
|
6271 if (status & RxFOVF) { |
|
6272 if (!tp->ecdev) { |
|
6273 rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
|
6274 } |
|
6275 dev->stats.rx_fifo_errors++; |
|
6276 } |
|
6277 if ((status & (RxRUNT | RxCRC)) && |
|
6278 !(status & (RxRWT | RxFOVF)) && |
|
6279 (dev->features & NETIF_F_RXALL)) |
|
6280 goto process_pkt; |
|
6281 } else { |
|
6282 struct sk_buff *skb; |
|
6283 dma_addr_t addr; |
|
6284 int pkt_size; |
|
6285 |
|
6286 process_pkt: |
|
6287 addr = le64_to_cpu(desc->addr); |
|
6288 if (likely(!(dev->features & NETIF_F_RXFCS))) |
|
6289 pkt_size = (status & 0x00003fff) - 4; |
|
6290 else |
|
6291 pkt_size = status & 0x00003fff; |
|
6292 |
|
6293 /* |
|
6294 * The driver does not support incoming fragmented |
|
6295 * frames. They are seen as a symptom of over-mtu |
|
6296 * sized frames. |
|
6297 */ |
|
6298 if (unlikely(rtl8169_fragmented_frame(status))) { |
|
6299 dev->stats.rx_dropped++; |
|
6300 dev->stats.rx_length_errors++; |
|
6301 goto release_descriptor; |
|
6302 } |
|
6303 |
|
6304 if (tp->ecdev) { |
|
6305 struct device *d = &tp->pci_dev->dev; |
|
6306 |
|
6307 /* reusing parts of rtl8169_try_rx_copy() */ |
|
6308 tp->Rx_databuff[entry] = rtl8169_align(tp->Rx_databuff[entry]); |
|
6309 dma_sync_single_for_cpu(d, addr, pkt_size, DMA_FROM_DEVICE); |
|
6310 prefetch(tp->Rx_databuff[entry]); |
|
6311 |
|
6312 ecdev_receive(tp->ecdev, tp->Rx_databuff[entry], pkt_size); |
|
6313 |
|
6314 dma_sync_single_for_device(d, addr, pkt_size, DMA_FROM_DEVICE); |
|
6315 |
|
6316 // No need to detect link status as |
|
6317 // long as frames are received: Reset watchdog. |
|
6318 tp->ec_watchdog_jiffies = jiffies; |
|
6319 } |
|
6320 else { |
|
6321 skb = rtl8169_try_rx_copy(tp->Rx_databuff[entry], |
|
6322 tp, pkt_size, addr); |
|
6323 if (!skb) { |
|
6324 dev->stats.rx_dropped++; |
|
6325 goto release_descriptor; |
|
6326 } |
|
6327 |
|
6328 rtl8169_rx_csum(skb, status); |
|
6329 skb_put(skb, pkt_size); |
|
6330 skb->protocol = eth_type_trans(skb, dev); |
|
6331 |
|
6332 rtl8169_rx_vlan_tag(desc, skb); |
|
6333 |
|
6334 napi_gro_receive(&tp->napi, skb); |
|
6335 |
|
6336 u64_stats_update_begin(&tp->rx_stats.syncp); |
|
6337 tp->rx_stats.packets++; |
|
6338 tp->rx_stats.bytes += pkt_size; |
|
6339 u64_stats_update_end(&tp->rx_stats.syncp); |
|
6340 } |
|
6341 } |
|
6342 release_descriptor: |
|
6343 desc->opts2 = 0; |
|
6344 wmb(); |
|
6345 rtl8169_mark_to_asic(desc, rx_buf_sz); |
|
6346 } |
|
6347 |
|
6348 count = cur_rx - tp->cur_rx; |
|
6349 tp->cur_rx = cur_rx; |
|
6350 |
|
6351 return count; |
|
6352 } |
|
6353 |
|
6354 static irqreturn_t rtl8169_interrupt(int irq, void *dev_instance) |
|
6355 { |
|
6356 struct net_device *dev = dev_instance; |
|
6357 struct rtl8169_private *tp = netdev_priv(dev); |
|
6358 int handled = 0; |
|
6359 u16 status; |
|
6360 |
|
6361 status = rtl_get_events(tp); |
|
6362 if (status && status != 0xffff) { |
|
6363 status &= RTL_EVENT_NAPI | tp->event_slow; |
|
6364 if (status) { |
|
6365 handled = 1; |
|
6366 |
|
6367 rtl_irq_disable(tp); |
|
6368 napi_schedule(&tp->napi); |
|
6369 } |
|
6370 } |
|
6371 return IRQ_RETVAL(handled); |
|
6372 } |
|
6373 |
|
6374 /* |
|
6375 * Workqueue context. |
|
6376 */ |
|
6377 static void rtl_slow_event_work(struct rtl8169_private *tp) |
|
6378 { |
|
6379 struct net_device *dev = tp->dev; |
|
6380 u16 status; |
|
6381 |
|
6382 status = rtl_get_events(tp) & tp->event_slow; |
|
6383 rtl_ack_events(tp, status); |
|
6384 |
|
6385 if (unlikely(!tp->ecdev && (status & RxFIFOOver))) { |
|
6386 switch (tp->mac_version) { |
|
6387 /* Work around for rx fifo overflow */ |
|
6388 case RTL_GIGA_MAC_VER_11: |
|
6389 netif_stop_queue(dev); |
|
6390 /* XXX - Hack alert. See rtl_task(). */ |
|
6391 set_bit(RTL_FLAG_TASK_RESET_PENDING, tp->wk.flags); |
|
6392 default: |
|
6393 break; |
|
6394 } |
|
6395 } |
|
6396 |
|
6397 if (unlikely(!tp->ecdev && (status & SYSErr))) |
|
6398 rtl8169_pcierr_interrupt(dev); |
|
6399 |
|
6400 if (status & LinkChg) |
|
6401 __rtl8169_check_link_status(dev, tp, tp->mmio_addr, true); |
|
6402 |
|
6403 if (!tp->ecdev) { |
|
6404 rtl_irq_enable_all(tp); |
|
6405 } |
|
6406 } |
|
6407 |
|
6408 static void rtl_task(struct work_struct *work) |
|
6409 { |
|
6410 static const struct { |
|
6411 int bitnr; |
|
6412 void (*action)(struct rtl8169_private *); |
|
6413 } rtl_work[] = { |
|
6414 /* XXX - keep rtl_slow_event_work() as first element. */ |
|
6415 { RTL_FLAG_TASK_SLOW_PENDING, rtl_slow_event_work }, |
|
6416 { RTL_FLAG_TASK_RESET_PENDING, rtl_reset_work }, |
|
6417 { RTL_FLAG_TASK_PHY_PENDING, rtl_phy_work } |
|
6418 }; |
|
6419 struct rtl8169_private *tp = |
|
6420 container_of(work, struct rtl8169_private, wk.work); |
|
6421 struct net_device *dev = tp->dev; |
|
6422 int i; |
|
6423 |
|
6424 rtl_lock_work(tp); |
|
6425 |
|
6426 if (!netif_running(dev) || |
|
6427 !test_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags)) |
|
6428 goto out_unlock; |
|
6429 |
|
6430 for (i = 0; i < ARRAY_SIZE(rtl_work); i++) { |
|
6431 bool pending; |
|
6432 |
|
6433 pending = test_and_clear_bit(rtl_work[i].bitnr, tp->wk.flags); |
|
6434 if (pending) |
|
6435 rtl_work[i].action(tp); |
|
6436 } |
|
6437 |
|
6438 out_unlock: |
|
6439 rtl_unlock_work(tp); |
|
6440 } |
|
6441 |
|
6442 static void ec_poll(struct net_device *dev) |
|
6443 { |
|
6444 struct rtl8169_private *tp = netdev_priv(dev); |
|
6445 u16 status; |
|
6446 |
|
6447 status = rtl_get_events(tp); |
|
6448 rtl_ack_events(tp, status & ~tp->event_slow); |
|
6449 |
|
6450 if (status & RTL_EVENT_NAPI_RX) { |
|
6451 rtl_rx(dev, tp, 100); // FIXME |
|
6452 } |
|
6453 |
|
6454 if (status & RTL_EVENT_NAPI_TX) { |
|
6455 rtl_tx(dev, tp); |
|
6456 } |
|
6457 |
|
6458 if (jiffies - tp->ec_watchdog_jiffies >= 2 * HZ) { |
|
6459 void __iomem *ioaddr = tp->mmio_addr; |
|
6460 ecdev_set_link(tp->ecdev, tp->link_ok(ioaddr) ? 1 : 0); |
|
6461 tp->ec_watchdog_jiffies = jiffies; |
|
6462 } |
|
6463 } |
|
6464 |
|
6465 static int rtl8169_poll(struct napi_struct *napi, int budget) |
|
6466 { |
|
6467 struct rtl8169_private *tp = container_of(napi, struct rtl8169_private, napi); |
|
6468 struct net_device *dev = tp->dev; |
|
6469 u16 enable_mask = RTL_EVENT_NAPI | tp->event_slow; |
|
6470 int work_done= 0; |
|
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 work_done = rtl_rx(dev, tp, (u32) budget); |
|
6478 |
|
6479 if (status & RTL_EVENT_NAPI_TX) |
|
6480 rtl_tx(dev, tp); |
|
6481 |
|
6482 if (status & tp->event_slow) { |
|
6483 enable_mask &= ~tp->event_slow; |
|
6484 |
|
6485 rtl_schedule_task(tp, RTL_FLAG_TASK_SLOW_PENDING); |
|
6486 } |
|
6487 |
|
6488 if (work_done < budget) { |
|
6489 napi_complete(napi); |
|
6490 |
|
6491 rtl_irq_enable(tp, enable_mask); |
|
6492 mmiowb(); |
|
6493 } |
|
6494 |
|
6495 return work_done; |
|
6496 } |
|
6497 |
|
6498 static void rtl8169_rx_missed(struct net_device *dev, void __iomem *ioaddr) |
|
6499 { |
|
6500 struct rtl8169_private *tp = netdev_priv(dev); |
|
6501 |
|
6502 if (tp->mac_version > RTL_GIGA_MAC_VER_06) |
|
6503 return; |
|
6504 |
|
6505 dev->stats.rx_missed_errors += (RTL_R32(RxMissed) & 0xffffff); |
|
6506 RTL_W32(RxMissed, 0); |
|
6507 } |
|
6508 |
|
6509 static void rtl8169_down(struct net_device *dev) |
|
6510 { |
|
6511 struct rtl8169_private *tp = netdev_priv(dev); |
|
6512 void __iomem *ioaddr = tp->mmio_addr; |
|
6513 |
|
6514 if (!tp->ecdev) { |
|
6515 del_timer_sync(&tp->timer); |
|
6516 |
|
6517 napi_disable(&tp->napi); |
|
6518 netif_stop_queue(dev); |
|
6519 } |
|
6520 |
|
6521 rtl8169_hw_reset(tp); |
|
6522 /* |
|
6523 * At this point device interrupts can not be enabled in any function, |
|
6524 * as netif_running is not true (rtl8169_interrupt, rtl8169_reset_task) |
|
6525 * and napi is disabled (rtl8169_poll). |
|
6526 */ |
|
6527 rtl8169_rx_missed(dev, ioaddr); |
|
6528 |
|
6529 /* Give a racing hard_start_xmit a few cycles to complete. */ |
|
6530 synchronize_sched(); |
|
6531 |
|
6532 rtl8169_tx_clear(tp); |
|
6533 |
|
6534 rtl8169_rx_clear(tp); |
|
6535 |
|
6536 rtl_pll_power_down(tp); |
|
6537 } |
|
6538 |
|
6539 static int rtl8169_close(struct net_device *dev) |
|
6540 { |
|
6541 struct rtl8169_private *tp = netdev_priv(dev); |
|
6542 struct pci_dev *pdev = tp->pci_dev; |
|
6543 |
|
6544 pm_runtime_get_sync(&pdev->dev); |
|
6545 |
|
6546 /* Update counters before going down */ |
|
6547 rtl8169_update_counters(dev); |
|
6548 |
|
6549 rtl_lock_work(tp); |
|
6550 clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
|
6551 |
|
6552 rtl8169_down(dev); |
|
6553 rtl_unlock_work(tp); |
|
6554 |
|
6555 cancel_work_sync(&tp->wk.work); |
|
6556 |
|
6557 if (!tp->ecdev) { |
|
6558 free_irq(pdev->irq, dev); |
|
6559 } |
|
6560 |
|
6561 dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
|
6562 tp->RxPhyAddr); |
|
6563 dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
|
6564 tp->TxPhyAddr); |
|
6565 tp->TxDescArray = NULL; |
|
6566 tp->RxDescArray = NULL; |
|
6567 |
|
6568 pm_runtime_put_sync(&pdev->dev); |
|
6569 |
|
6570 return 0; |
|
6571 } |
|
6572 |
|
6573 #ifdef CONFIG_NET_POLL_CONTROLLER |
|
6574 static void rtl8169_netpoll(struct net_device *dev) |
|
6575 { |
|
6576 struct rtl8169_private *tp = netdev_priv(dev); |
|
6577 |
|
6578 rtl8169_interrupt(tp->pci_dev->irq, dev); |
|
6579 } |
|
6580 #endif |
|
6581 |
|
6582 static int rtl_open(struct net_device *dev) |
|
6583 { |
|
6584 struct rtl8169_private *tp = netdev_priv(dev); |
|
6585 void __iomem *ioaddr = tp->mmio_addr; |
|
6586 struct pci_dev *pdev = tp->pci_dev; |
|
6587 int retval = -ENOMEM; |
|
6588 |
|
6589 pm_runtime_get_sync(&pdev->dev); |
|
6590 |
|
6591 /* |
|
6592 * Rx and Tx descriptors needs 256 bytes alignment. |
|
6593 * dma_alloc_coherent provides more. |
|
6594 */ |
|
6595 tp->TxDescArray = dma_alloc_coherent(&pdev->dev, R8169_TX_RING_BYTES, |
|
6596 &tp->TxPhyAddr, GFP_KERNEL); |
|
6597 if (!tp->TxDescArray) |
|
6598 goto err_pm_runtime_put; |
|
6599 |
|
6600 tp->RxDescArray = dma_alloc_coherent(&pdev->dev, R8169_RX_RING_BYTES, |
|
6601 &tp->RxPhyAddr, GFP_KERNEL); |
|
6602 if (!tp->RxDescArray) |
|
6603 goto err_free_tx_0; |
|
6604 |
|
6605 retval = rtl8169_init_ring(dev); |
|
6606 if (retval < 0) |
|
6607 goto err_free_rx_1; |
|
6608 |
|
6609 INIT_WORK(&tp->wk.work, rtl_task); |
|
6610 |
|
6611 smp_mb(); |
|
6612 |
|
6613 rtl_request_firmware(tp); |
|
6614 |
|
6615 if (!tp->ecdev) { |
|
6616 retval = request_irq(pdev->irq, rtl8169_interrupt, |
|
6617 (tp->features & RTL_FEATURE_MSI) ? 0 : IRQF_SHARED, |
|
6618 dev->name, dev); |
|
6619 if (retval < 0) |
|
6620 goto err_release_fw_2; |
|
6621 } |
|
6622 |
|
6623 rtl_lock_work(tp); |
|
6624 |
|
6625 set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
|
6626 |
|
6627 if (!tp->ecdev) { |
|
6628 napi_enable(&tp->napi); |
|
6629 } |
|
6630 |
|
6631 rtl8169_init_phy(dev, tp); |
|
6632 |
|
6633 __rtl8169_set_features(dev, dev->features); |
|
6634 |
|
6635 rtl_pll_power_up(tp); |
|
6636 |
|
6637 rtl_hw_start(dev); |
|
6638 |
|
6639 if (!tp->ecdev) { |
|
6640 netif_start_queue(dev); |
|
6641 } |
|
6642 |
|
6643 rtl_unlock_work(tp); |
|
6644 |
|
6645 tp->saved_wolopts = 0; |
|
6646 pm_runtime_put_noidle(&pdev->dev); |
|
6647 |
|
6648 rtl8169_check_link_status(dev, tp, ioaddr); |
|
6649 out: |
|
6650 return retval; |
|
6651 |
|
6652 err_release_fw_2: |
|
6653 rtl_release_firmware(tp); |
|
6654 rtl8169_rx_clear(tp); |
|
6655 err_free_rx_1: |
|
6656 dma_free_coherent(&pdev->dev, R8169_RX_RING_BYTES, tp->RxDescArray, |
|
6657 tp->RxPhyAddr); |
|
6658 tp->RxDescArray = NULL; |
|
6659 err_free_tx_0: |
|
6660 dma_free_coherent(&pdev->dev, R8169_TX_RING_BYTES, tp->TxDescArray, |
|
6661 tp->TxPhyAddr); |
|
6662 tp->TxDescArray = NULL; |
|
6663 err_pm_runtime_put: |
|
6664 pm_runtime_put_noidle(&pdev->dev); |
|
6665 goto out; |
|
6666 } |
|
6667 |
|
6668 static struct rtnl_link_stats64 * |
|
6669 rtl8169_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *stats) |
|
6670 { |
|
6671 struct rtl8169_private *tp = netdev_priv(dev); |
|
6672 void __iomem *ioaddr = tp->mmio_addr; |
|
6673 unsigned int start; |
|
6674 |
|
6675 if (netif_running(dev)) |
|
6676 rtl8169_rx_missed(dev, ioaddr); |
|
6677 |
|
6678 do { |
|
6679 start = u64_stats_fetch_begin_bh(&tp->rx_stats.syncp); |
|
6680 stats->rx_packets = tp->rx_stats.packets; |
|
6681 stats->rx_bytes = tp->rx_stats.bytes; |
|
6682 } while (u64_stats_fetch_retry_bh(&tp->rx_stats.syncp, start)); |
|
6683 |
|
6684 |
|
6685 do { |
|
6686 start = u64_stats_fetch_begin_bh(&tp->tx_stats.syncp); |
|
6687 stats->tx_packets = tp->tx_stats.packets; |
|
6688 stats->tx_bytes = tp->tx_stats.bytes; |
|
6689 } while (u64_stats_fetch_retry_bh(&tp->tx_stats.syncp, start)); |
|
6690 |
|
6691 stats->rx_dropped = dev->stats.rx_dropped; |
|
6692 stats->tx_dropped = dev->stats.tx_dropped; |
|
6693 stats->rx_length_errors = dev->stats.rx_length_errors; |
|
6694 stats->rx_errors = dev->stats.rx_errors; |
|
6695 stats->rx_crc_errors = dev->stats.rx_crc_errors; |
|
6696 stats->rx_fifo_errors = dev->stats.rx_fifo_errors; |
|
6697 stats->rx_missed_errors = dev->stats.rx_missed_errors; |
|
6698 |
|
6699 return stats; |
|
6700 } |
|
6701 |
|
6702 static void rtl8169_net_suspend(struct net_device *dev) |
|
6703 { |
|
6704 struct rtl8169_private *tp = netdev_priv(dev); |
|
6705 |
|
6706 if (!netif_running(dev)) |
|
6707 return; |
|
6708 |
|
6709 netif_device_detach(dev); |
|
6710 netif_stop_queue(dev); |
|
6711 |
|
6712 rtl_lock_work(tp); |
|
6713 napi_disable(&tp->napi); |
|
6714 clear_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
|
6715 rtl_unlock_work(tp); |
|
6716 |
|
6717 rtl_pll_power_down(tp); |
|
6718 } |
|
6719 |
|
6720 #ifdef CONFIG_PM |
|
6721 |
|
6722 static int rtl8169_suspend(struct device *device) |
|
6723 { |
|
6724 struct pci_dev *pdev = to_pci_dev(device); |
|
6725 struct net_device *dev = pci_get_drvdata(pdev); |
|
6726 struct rtl8169_private *tp = netdev_priv(dev); |
|
6727 |
|
6728 if (tp->ecdev) { |
|
6729 return -EBUSY; |
|
6730 } |
|
6731 |
|
6732 rtl8169_net_suspend(dev); |
|
6733 |
|
6734 return 0; |
|
6735 } |
|
6736 |
|
6737 static void __rtl8169_resume(struct net_device *dev) |
|
6738 { |
|
6739 struct rtl8169_private *tp = netdev_priv(dev); |
|
6740 |
|
6741 netif_device_attach(dev); |
|
6742 |
|
6743 rtl_pll_power_up(tp); |
|
6744 |
|
6745 rtl_lock_work(tp); |
|
6746 napi_enable(&tp->napi); |
|
6747 set_bit(RTL_FLAG_TASK_ENABLED, tp->wk.flags); |
|
6748 rtl_unlock_work(tp); |
|
6749 |
|
6750 rtl_schedule_task(tp, RTL_FLAG_TASK_RESET_PENDING); |
|
6751 } |
|
6752 |
|
6753 static int rtl8169_resume(struct device *device) |
|
6754 { |
|
6755 struct pci_dev *pdev = to_pci_dev(device); |
|
6756 struct net_device *dev = pci_get_drvdata(pdev); |
|
6757 struct rtl8169_private *tp = netdev_priv(dev); |
|
6758 |
|
6759 if (tp->ecdev) { |
|
6760 return -EBUSY; |
|
6761 } |
|
6762 |
|
6763 rtl8169_init_phy(dev, tp); |
|
6764 |
|
6765 if (netif_running(dev)) |
|
6766 __rtl8169_resume(dev); |
|
6767 |
|
6768 return 0; |
|
6769 } |
|
6770 |
|
6771 static int rtl8169_runtime_suspend(struct device *device) |
|
6772 { |
|
6773 struct pci_dev *pdev = to_pci_dev(device); |
|
6774 struct net_device *dev = pci_get_drvdata(pdev); |
|
6775 struct rtl8169_private *tp = netdev_priv(dev); |
|
6776 |
|
6777 if (tp->ecdev) { |
|
6778 return -EBUSY; |
|
6779 } |
|
6780 |
|
6781 if (!tp->TxDescArray) |
|
6782 return 0; |
|
6783 |
|
6784 rtl_lock_work(tp); |
|
6785 tp->saved_wolopts = __rtl8169_get_wol(tp); |
|
6786 __rtl8169_set_wol(tp, WAKE_ANY); |
|
6787 rtl_unlock_work(tp); |
|
6788 |
|
6789 rtl8169_net_suspend(dev); |
|
6790 |
|
6791 return 0; |
|
6792 } |
|
6793 |
|
6794 static int rtl8169_runtime_resume(struct device *device) |
|
6795 { |
|
6796 struct pci_dev *pdev = to_pci_dev(device); |
|
6797 struct net_device *dev = pci_get_drvdata(pdev); |
|
6798 struct rtl8169_private *tp = netdev_priv(dev); |
|
6799 |
|
6800 if (tp->ecdev) { |
|
6801 return -EBUSY; |
|
6802 } |
|
6803 |
|
6804 if (!tp->TxDescArray) |
|
6805 return 0; |
|
6806 |
|
6807 rtl_lock_work(tp); |
|
6808 __rtl8169_set_wol(tp, tp->saved_wolopts); |
|
6809 tp->saved_wolopts = 0; |
|
6810 rtl_unlock_work(tp); |
|
6811 |
|
6812 rtl8169_init_phy(dev, tp); |
|
6813 |
|
6814 __rtl8169_resume(dev); |
|
6815 |
|
6816 return 0; |
|
6817 } |
|
6818 |
|
6819 static int rtl8169_runtime_idle(struct device *device) |
|
6820 { |
|
6821 struct pci_dev *pdev = to_pci_dev(device); |
|
6822 struct net_device *dev = pci_get_drvdata(pdev); |
|
6823 struct rtl8169_private *tp = netdev_priv(dev); |
|
6824 |
|
6825 return tp->TxDescArray ? -EBUSY : 0; |
|
6826 } |
|
6827 |
|
6828 static const struct dev_pm_ops rtl8169_pm_ops = { |
|
6829 .suspend = rtl8169_suspend, |
|
6830 .resume = rtl8169_resume, |
|
6831 .freeze = rtl8169_suspend, |
|
6832 .thaw = rtl8169_resume, |
|
6833 .poweroff = rtl8169_suspend, |
|
6834 .restore = rtl8169_resume, |
|
6835 .runtime_suspend = rtl8169_runtime_suspend, |
|
6836 .runtime_resume = rtl8169_runtime_resume, |
|
6837 .runtime_idle = rtl8169_runtime_idle, |
|
6838 }; |
|
6839 |
|
6840 #define RTL8169_PM_OPS (&rtl8169_pm_ops) |
|
6841 |
|
6842 #else /* !CONFIG_PM */ |
|
6843 |
|
6844 #define RTL8169_PM_OPS NULL |
|
6845 |
|
6846 #endif /* !CONFIG_PM */ |
|
6847 |
|
6848 static void rtl_wol_shutdown_quirk(struct rtl8169_private *tp) |
|
6849 { |
|
6850 void __iomem *ioaddr = tp->mmio_addr; |
|
6851 |
|
6852 /* WoL fails with 8168b when the receiver is disabled. */ |
|
6853 switch (tp->mac_version) { |
|
6854 case RTL_GIGA_MAC_VER_11: |
|
6855 case RTL_GIGA_MAC_VER_12: |
|
6856 case RTL_GIGA_MAC_VER_17: |
|
6857 pci_clear_master(tp->pci_dev); |
|
6858 |
|
6859 RTL_W8(ChipCmd, CmdRxEnb); |
|
6860 /* PCI commit */ |
|
6861 RTL_R8(ChipCmd); |
|
6862 break; |
|
6863 default: |
|
6864 break; |
|
6865 } |
|
6866 } |
|
6867 |
|
6868 static void rtl_shutdown(struct pci_dev *pdev) |
|
6869 { |
|
6870 struct net_device *dev = pci_get_drvdata(pdev); |
|
6871 struct rtl8169_private *tp = netdev_priv(dev); |
|
6872 struct device *d = &pdev->dev; |
|
6873 |
|
6874 pm_runtime_get_sync(d); |
|
6875 |
|
6876 rtl8169_net_suspend(dev); |
|
6877 |
|
6878 /* Restore original MAC address */ |
|
6879 rtl_rar_set(tp, dev->perm_addr); |
|
6880 |
|
6881 rtl8169_hw_reset(tp); |
|
6882 |
|
6883 if (system_state == SYSTEM_POWER_OFF) { |
|
6884 if (__rtl8169_get_wol(tp) & WAKE_ANY) { |
|
6885 rtl_wol_suspend_quirk(tp); |
|
6886 rtl_wol_shutdown_quirk(tp); |
|
6887 } |
|
6888 |
|
6889 pci_wake_from_d3(pdev, true); |
|
6890 pci_set_power_state(pdev, PCI_D3hot); |
|
6891 } |
|
6892 |
|
6893 pm_runtime_put_noidle(d); |
|
6894 } |
|
6895 |
|
6896 static void rtl_remove_one(struct pci_dev *pdev) |
|
6897 { |
|
6898 struct net_device *dev = pci_get_drvdata(pdev); |
|
6899 struct rtl8169_private *tp = netdev_priv(dev); |
|
6900 |
|
6901 if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
|
6902 tp->mac_version == RTL_GIGA_MAC_VER_28 || |
|
6903 tp->mac_version == RTL_GIGA_MAC_VER_31) { |
|
6904 rtl8168_driver_stop(tp); |
|
6905 } |
|
6906 |
|
6907 if (tp->ecdev) { |
|
6908 ecdev_close(tp->ecdev); |
|
6909 ecdev_withdraw(tp->ecdev); |
|
6910 } else { |
|
6911 netif_napi_del(&tp->napi); |
|
6912 |
|
6913 unregister_netdev(dev); |
|
6914 } |
|
6915 |
|
6916 rtl_release_firmware(tp); |
|
6917 |
|
6918 if (pci_dev_run_wake(pdev)) |
|
6919 pm_runtime_get_noresume(&pdev->dev); |
|
6920 |
|
6921 /* restore original MAC address */ |
|
6922 rtl_rar_set(tp, dev->perm_addr); |
|
6923 |
|
6924 rtl_disable_msi(pdev, tp); |
|
6925 rtl8169_release_board(pdev, dev, tp->mmio_addr); |
|
6926 pci_set_drvdata(pdev, NULL); |
|
6927 } |
|
6928 |
|
6929 static const struct net_device_ops rtl_netdev_ops = { |
|
6930 .ndo_open = rtl_open, |
|
6931 .ndo_stop = rtl8169_close, |
|
6932 .ndo_get_stats64 = rtl8169_get_stats64, |
|
6933 .ndo_start_xmit = rtl8169_start_xmit, |
|
6934 .ndo_tx_timeout = rtl8169_tx_timeout, |
|
6935 .ndo_validate_addr = eth_validate_addr, |
|
6936 .ndo_change_mtu = rtl8169_change_mtu, |
|
6937 .ndo_fix_features = rtl8169_fix_features, |
|
6938 .ndo_set_features = rtl8169_set_features, |
|
6939 .ndo_set_mac_address = rtl_set_mac_address, |
|
6940 .ndo_do_ioctl = rtl8169_ioctl, |
|
6941 .ndo_set_rx_mode = rtl_set_rx_mode, |
|
6942 #ifdef CONFIG_NET_POLL_CONTROLLER |
|
6943 .ndo_poll_controller = rtl8169_netpoll, |
|
6944 #endif |
|
6945 |
|
6946 }; |
|
6947 |
|
6948 static const struct rtl_cfg_info { |
|
6949 void (*hw_start)(struct net_device *); |
|
6950 unsigned int region; |
|
6951 unsigned int align; |
|
6952 u16 event_slow; |
|
6953 unsigned features; |
|
6954 u8 default_ver; |
|
6955 } rtl_cfg_infos [] = { |
|
6956 [RTL_CFG_0] = { |
|
6957 .hw_start = rtl_hw_start_8169, |
|
6958 .region = 1, |
|
6959 .align = 0, |
|
6960 .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver, |
|
6961 .features = RTL_FEATURE_GMII, |
|
6962 .default_ver = RTL_GIGA_MAC_VER_01, |
|
6963 }, |
|
6964 [RTL_CFG_1] = { |
|
6965 .hw_start = rtl_hw_start_8168, |
|
6966 .region = 2, |
|
6967 .align = 8, |
|
6968 .event_slow = SYSErr | LinkChg | RxOverflow, |
|
6969 .features = RTL_FEATURE_GMII | RTL_FEATURE_MSI, |
|
6970 .default_ver = RTL_GIGA_MAC_VER_11, |
|
6971 }, |
|
6972 [RTL_CFG_2] = { |
|
6973 .hw_start = rtl_hw_start_8101, |
|
6974 .region = 2, |
|
6975 .align = 8, |
|
6976 .event_slow = SYSErr | LinkChg | RxOverflow | RxFIFOOver | |
|
6977 PCSTimeout, |
|
6978 .features = RTL_FEATURE_MSI, |
|
6979 .default_ver = RTL_GIGA_MAC_VER_13, |
|
6980 } |
|
6981 }; |
|
6982 |
|
6983 /* Cfg9346_Unlock assumed. */ |
|
6984 static unsigned rtl_try_msi(struct rtl8169_private *tp, |
|
6985 const struct rtl_cfg_info *cfg) |
|
6986 { |
|
6987 void __iomem *ioaddr = tp->mmio_addr; |
|
6988 unsigned msi = 0; |
|
6989 u8 cfg2; |
|
6990 |
|
6991 cfg2 = RTL_R8(Config2) & ~MSIEnable; |
|
6992 if (cfg->features & RTL_FEATURE_MSI) { |
|
6993 if (pci_enable_msi(tp->pci_dev)) { |
|
6994 netif_info(tp, hw, tp->dev, "no MSI. Back to INTx.\n"); |
|
6995 } else { |
|
6996 cfg2 |= MSIEnable; |
|
6997 msi = RTL_FEATURE_MSI; |
|
6998 } |
|
6999 } |
|
7000 if (tp->mac_version <= RTL_GIGA_MAC_VER_06) |
|
7001 RTL_W8(Config2, cfg2); |
|
7002 return msi; |
|
7003 } |
|
7004 |
|
7005 DECLARE_RTL_COND(rtl_link_list_ready_cond) |
|
7006 { |
|
7007 void __iomem *ioaddr = tp->mmio_addr; |
|
7008 |
|
7009 return RTL_R8(MCU) & LINK_LIST_RDY; |
|
7010 } |
|
7011 |
|
7012 DECLARE_RTL_COND(rtl_rxtx_empty_cond) |
|
7013 { |
|
7014 void __iomem *ioaddr = tp->mmio_addr; |
|
7015 |
|
7016 return (RTL_R8(MCU) & RXTX_EMPTY) == RXTX_EMPTY; |
|
7017 } |
|
7018 |
|
7019 static void rtl_hw_init_8168g(struct rtl8169_private *tp) |
|
7020 { |
|
7021 void __iomem *ioaddr = tp->mmio_addr; |
|
7022 u32 data; |
|
7023 |
|
7024 tp->ocp_base = OCP_STD_PHY_BASE; |
|
7025 |
|
7026 RTL_W32(MISC, RTL_R32(MISC) | RXDV_GATED_EN); |
|
7027 |
|
7028 if (!rtl_udelay_loop_wait_high(tp, &rtl_txcfg_empty_cond, 100, 42)) |
|
7029 return; |
|
7030 |
|
7031 if (!rtl_udelay_loop_wait_high(tp, &rtl_rxtx_empty_cond, 100, 42)) |
|
7032 return; |
|
7033 |
|
7034 RTL_W8(ChipCmd, RTL_R8(ChipCmd) & ~(CmdTxEnb | CmdRxEnb)); |
|
7035 msleep(1); |
|
7036 RTL_W8(MCU, RTL_R8(MCU) & ~NOW_IS_OOB); |
|
7037 |
|
7038 data = r8168_mac_ocp_read(tp, 0xe8de); |
|
7039 data &= ~(1 << 14); |
|
7040 r8168_mac_ocp_write(tp, 0xe8de, data); |
|
7041 |
|
7042 if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
|
7043 return; |
|
7044 |
|
7045 data = r8168_mac_ocp_read(tp, 0xe8de); |
|
7046 data |= (1 << 15); |
|
7047 r8168_mac_ocp_write(tp, 0xe8de, data); |
|
7048 |
|
7049 if (!rtl_udelay_loop_wait_high(tp, &rtl_link_list_ready_cond, 100, 42)) |
|
7050 return; |
|
7051 } |
|
7052 |
|
7053 static void rtl_hw_initialize(struct rtl8169_private *tp) |
|
7054 { |
|
7055 switch (tp->mac_version) { |
|
7056 case RTL_GIGA_MAC_VER_40: |
|
7057 case RTL_GIGA_MAC_VER_41: |
|
7058 case RTL_GIGA_MAC_VER_42: |
|
7059 case RTL_GIGA_MAC_VER_43: |
|
7060 case RTL_GIGA_MAC_VER_44: |
|
7061 rtl_hw_init_8168g(tp); |
|
7062 break; |
|
7063 |
|
7064 default: |
|
7065 break; |
|
7066 } |
|
7067 } |
|
7068 |
|
7069 static int |
|
7070 rtl_init_one(struct pci_dev *pdev, const struct pci_device_id *ent) |
|
7071 { |
|
7072 const struct rtl_cfg_info *cfg = rtl_cfg_infos + ent->driver_data; |
|
7073 const unsigned int region = cfg->region; |
|
7074 struct rtl8169_private *tp; |
|
7075 struct mii_if_info *mii; |
|
7076 struct net_device *dev; |
|
7077 void __iomem *ioaddr; |
|
7078 int chipset, i; |
|
7079 int rc; |
|
7080 |
|
7081 if (netif_msg_drv(&debug)) { |
|
7082 printk(KERN_INFO "%s Gigabit Ethernet driver %s loaded\n", |
|
7083 MODULENAME, RTL8169_VERSION); |
|
7084 } |
|
7085 |
|
7086 dev = alloc_etherdev(sizeof (*tp)); |
|
7087 if (!dev) { |
|
7088 rc = -ENOMEM; |
|
7089 goto out; |
|
7090 } |
|
7091 |
|
7092 SET_NETDEV_DEV(dev, &pdev->dev); |
|
7093 dev->netdev_ops = &rtl_netdev_ops; |
|
7094 tp = netdev_priv(dev); |
|
7095 tp->dev = dev; |
|
7096 tp->pci_dev = pdev; |
|
7097 tp->msg_enable = netif_msg_init(debug.msg_enable, R8169_MSG_DEFAULT); |
|
7098 |
|
7099 mii = &tp->mii; |
|
7100 mii->dev = dev; |
|
7101 mii->mdio_read = rtl_mdio_read; |
|
7102 mii->mdio_write = rtl_mdio_write; |
|
7103 mii->phy_id_mask = 0x1f; |
|
7104 mii->reg_num_mask = 0x1f; |
|
7105 mii->supports_gmii = !!(cfg->features & RTL_FEATURE_GMII); |
|
7106 |
|
7107 /* disable ASPM completely as that cause random device stop working |
|
7108 * problems as well as full system hangs for some PCIe devices users */ |
|
7109 pci_disable_link_state(pdev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1 | |
|
7110 PCIE_LINK_STATE_CLKPM); |
|
7111 |
|
7112 /* enable device (incl. PCI PM wakeup and hotplug setup) */ |
|
7113 rc = pci_enable_device(pdev); |
|
7114 if (rc < 0) { |
|
7115 netif_err(tp, probe, dev, "enable failure\n"); |
|
7116 goto err_out_free_dev_1; |
|
7117 } |
|
7118 |
|
7119 if (pci_set_mwi(pdev) < 0) |
|
7120 netif_info(tp, probe, dev, "Mem-Wr-Inval unavailable\n"); |
|
7121 |
|
7122 /* make sure PCI base addr 1 is MMIO */ |
|
7123 if (!(pci_resource_flags(pdev, region) & IORESOURCE_MEM)) { |
|
7124 netif_err(tp, probe, dev, |
|
7125 "region #%d not an MMIO resource, aborting\n", |
|
7126 region); |
|
7127 rc = -ENODEV; |
|
7128 goto err_out_mwi_2; |
|
7129 } |
|
7130 |
|
7131 /* check for weird/broken PCI region reporting */ |
|
7132 if (pci_resource_len(pdev, region) < R8169_REGS_SIZE) { |
|
7133 netif_err(tp, probe, dev, |
|
7134 "Invalid PCI region size(s), aborting\n"); |
|
7135 rc = -ENODEV; |
|
7136 goto err_out_mwi_2; |
|
7137 } |
|
7138 |
|
7139 rc = pci_request_regions(pdev, MODULENAME); |
|
7140 if (rc < 0) { |
|
7141 netif_err(tp, probe, dev, "could not request regions\n"); |
|
7142 goto err_out_mwi_2; |
|
7143 } |
|
7144 |
|
7145 tp->cp_cmd = RxChkSum; |
|
7146 |
|
7147 if ((sizeof(dma_addr_t) > 4) && |
|
7148 !pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && use_dac) { |
|
7149 tp->cp_cmd |= PCIDAC; |
|
7150 dev->features |= NETIF_F_HIGHDMA; |
|
7151 } else { |
|
7152 rc = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
|
7153 if (rc < 0) { |
|
7154 netif_err(tp, probe, dev, "DMA configuration failed\n"); |
|
7155 goto err_out_free_res_3; |
|
7156 } |
|
7157 } |
|
7158 |
|
7159 /* ioremap MMIO region */ |
|
7160 ioaddr = ioremap(pci_resource_start(pdev, region), R8169_REGS_SIZE); |
|
7161 if (!ioaddr) { |
|
7162 netif_err(tp, probe, dev, "cannot remap MMIO, aborting\n"); |
|
7163 rc = -EIO; |
|
7164 goto err_out_free_res_3; |
|
7165 } |
|
7166 tp->mmio_addr = ioaddr; |
|
7167 |
|
7168 if (!pci_is_pcie(pdev)) |
|
7169 netif_info(tp, probe, dev, "not PCI Express\n"); |
|
7170 |
|
7171 /* Identify chip attached to board */ |
|
7172 rtl8169_get_mac_version(tp, dev, cfg->default_ver); |
|
7173 |
|
7174 rtl_init_rxcfg(tp); |
|
7175 |
|
7176 rtl_irq_disable(tp); |
|
7177 |
|
7178 rtl_hw_initialize(tp); |
|
7179 |
|
7180 rtl_hw_reset(tp); |
|
7181 |
|
7182 rtl_ack_events(tp, 0xffff); |
|
7183 |
|
7184 pci_set_master(pdev); |
|
7185 |
|
7186 /* |
|
7187 * Pretend we are using VLANs; This bypasses a nasty bug where |
|
7188 * Interrupts stop flowing on high load on 8110SCd controllers. |
|
7189 */ |
|
7190 if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
|
7191 tp->cp_cmd |= RxVlan; |
|
7192 |
|
7193 rtl_init_mdio_ops(tp); |
|
7194 rtl_init_pll_power_ops(tp); |
|
7195 rtl_init_jumbo_ops(tp); |
|
7196 rtl_init_csi_ops(tp); |
|
7197 |
|
7198 rtl8169_print_mac_version(tp); |
|
7199 |
|
7200 chipset = tp->mac_version; |
|
7201 tp->txd_version = rtl_chip_infos[chipset].txd_version; |
|
7202 |
|
7203 RTL_W8(Cfg9346, Cfg9346_Unlock); |
|
7204 RTL_W8(Config1, RTL_R8(Config1) | PMEnable); |
|
7205 RTL_W8(Config5, RTL_R8(Config5) & (BWF | MWF | UWF | LanWake | PMEStatus)); |
|
7206 if ((RTL_R8(Config3) & (LinkUp | MagicPacket)) != 0) |
|
7207 tp->features |= RTL_FEATURE_WOL; |
|
7208 if ((RTL_R8(Config5) & (UWF | BWF | MWF)) != 0) |
|
7209 tp->features |= RTL_FEATURE_WOL; |
|
7210 tp->features |= rtl_try_msi(tp, cfg); |
|
7211 RTL_W8(Cfg9346, Cfg9346_Lock); |
|
7212 |
|
7213 if (rtl_tbi_enabled(tp)) { |
|
7214 tp->set_speed = rtl8169_set_speed_tbi; |
|
7215 tp->get_settings = rtl8169_gset_tbi; |
|
7216 tp->phy_reset_enable = rtl8169_tbi_reset_enable; |
|
7217 tp->phy_reset_pending = rtl8169_tbi_reset_pending; |
|
7218 tp->link_ok = rtl8169_tbi_link_ok; |
|
7219 tp->do_ioctl = rtl_tbi_ioctl; |
|
7220 } else { |
|
7221 tp->set_speed = rtl8169_set_speed_xmii; |
|
7222 tp->get_settings = rtl8169_gset_xmii; |
|
7223 tp->phy_reset_enable = rtl8169_xmii_reset_enable; |
|
7224 tp->phy_reset_pending = rtl8169_xmii_reset_pending; |
|
7225 tp->link_ok = rtl8169_xmii_link_ok; |
|
7226 tp->do_ioctl = rtl_xmii_ioctl; |
|
7227 } |
|
7228 |
|
7229 mutex_init(&tp->wk.mutex); |
|
7230 |
|
7231 /* Get MAC address */ |
|
7232 for (i = 0; i < ETH_ALEN; i++) |
|
7233 dev->dev_addr[i] = RTL_R8(MAC0 + i); |
|
7234 |
|
7235 SET_ETHTOOL_OPS(dev, &rtl8169_ethtool_ops); |
|
7236 dev->watchdog_timeo = RTL8169_TX_TIMEOUT; |
|
7237 |
|
7238 netif_napi_add(dev, &tp->napi, rtl8169_poll, R8169_NAPI_WEIGHT); |
|
7239 |
|
7240 /* don't enable SG, IP_CSUM and TSO by default - it might not work |
|
7241 * properly for all devices */ |
|
7242 dev->features |= NETIF_F_RXCSUM | |
|
7243 NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX; |
|
7244 |
|
7245 dev->hw_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
|
7246 NETIF_F_RXCSUM | NETIF_F_HW_VLAN_CTAG_TX | |
|
7247 NETIF_F_HW_VLAN_CTAG_RX; |
|
7248 dev->vlan_features = NETIF_F_SG | NETIF_F_IP_CSUM | NETIF_F_TSO | |
|
7249 NETIF_F_HIGHDMA; |
|
7250 |
|
7251 if (tp->mac_version == RTL_GIGA_MAC_VER_05) |
|
7252 /* 8110SCd requires hardware Rx VLAN - disallow toggling */ |
|
7253 dev->hw_features &= ~NETIF_F_HW_VLAN_CTAG_RX; |
|
7254 |
|
7255 dev->hw_features |= NETIF_F_RXALL; |
|
7256 dev->hw_features |= NETIF_F_RXFCS; |
|
7257 |
|
7258 tp->hw_start = cfg->hw_start; |
|
7259 tp->event_slow = cfg->event_slow; |
|
7260 |
|
7261 tp->opts1_mask = (tp->mac_version != RTL_GIGA_MAC_VER_01) ? |
|
7262 ~(RxBOVF | RxFOVF) : ~0; |
|
7263 |
|
7264 init_timer(&tp->timer); |
|
7265 tp->timer.data = (unsigned long) dev; |
|
7266 tp->timer.function = rtl8169_phy_timer; |
|
7267 |
|
7268 tp->rtl_fw = RTL_FIRMWARE_UNKNOWN; |
|
7269 |
|
7270 // offer device to EtherCAT master module |
|
7271 tp->ecdev = ecdev_offer(dev, ec_poll, THIS_MODULE); |
|
7272 tp->ec_watchdog_jiffies = jiffies; |
|
7273 |
|
7274 if (!tp->ecdev) { |
|
7275 rc = register_netdev(dev); |
|
7276 if (rc < 0) |
|
7277 goto err_out_msi_4; |
|
7278 } |
|
7279 |
|
7280 pci_set_drvdata(pdev, dev); |
|
7281 |
|
7282 netif_info(tp, probe, dev, "%s at 0x%p, %pM, XID %08x IRQ %d\n", |
|
7283 rtl_chip_infos[chipset].name, ioaddr, dev->dev_addr, |
|
7284 (u32)(RTL_R32(TxConfig) & 0x9cf0f8ff), pdev->irq); |
|
7285 if (rtl_chip_infos[chipset].jumbo_max != JUMBO_1K) { |
|
7286 netif_info(tp, probe, dev, "jumbo features [frames: %d bytes, " |
|
7287 "tx checksumming: %s]\n", |
|
7288 rtl_chip_infos[chipset].jumbo_max, |
|
7289 rtl_chip_infos[chipset].jumbo_tx_csum ? "ok" : "ko"); |
|
7290 } |
|
7291 |
|
7292 if (tp->mac_version == RTL_GIGA_MAC_VER_27 || |
|
7293 tp->mac_version == RTL_GIGA_MAC_VER_28 || |
|
7294 tp->mac_version == RTL_GIGA_MAC_VER_31) { |
|
7295 rtl8168_driver_start(tp); |
|
7296 } |
|
7297 |
|
7298 device_set_wakeup_enable(&pdev->dev, tp->features & RTL_FEATURE_WOL); |
|
7299 |
|
7300 if (pci_dev_run_wake(pdev)) |
|
7301 pm_runtime_put_noidle(&pdev->dev); |
|
7302 |
|
7303 if (tp->ecdev) { |
|
7304 rc = ecdev_open(tp->ecdev); |
|
7305 if (rc) { |
|
7306 ecdev_withdraw(tp->ecdev); |
|
7307 goto err_out_msi_4; |
|
7308 } |
|
7309 } |
|
7310 else { |
|
7311 netif_carrier_off(dev); |
|
7312 } |
|
7313 |
|
7314 out: |
|
7315 return rc; |
|
7316 |
|
7317 err_out_msi_4: |
|
7318 netif_napi_del(&tp->napi); |
|
7319 rtl_disable_msi(pdev, tp); |
|
7320 iounmap(ioaddr); |
|
7321 err_out_free_res_3: |
|
7322 pci_release_regions(pdev); |
|
7323 err_out_mwi_2: |
|
7324 pci_clear_mwi(pdev); |
|
7325 pci_disable_device(pdev); |
|
7326 err_out_free_dev_1: |
|
7327 free_netdev(dev); |
|
7328 goto out; |
|
7329 } |
|
7330 |
|
7331 static struct pci_driver rtl8169_pci_driver = { |
|
7332 .name = MODULENAME, |
|
7333 .id_table = rtl8169_pci_tbl, |
|
7334 .probe = rtl_init_one, |
|
7335 .remove = rtl_remove_one, |
|
7336 .shutdown = rtl_shutdown, |
|
7337 .driver.pm = RTL8169_PM_OPS, |
|
7338 }; |
|
7339 |
|
7340 module_pci_driver(rtl8169_pci_driver); |