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