Parcourir la source

[r8169] New rtl8169 family driver

This is a completely rewritten version of the rtl8169 family driver
using the gPXE driver API.
tags/v0.9.6
Marty Connor il y a 16 ans
Parent
révision
85f82f09e9
2 fichiers modifiés avec 2609 ajouts et 1084 suppressions
  1. 2043
    1084
      src/drivers/net/r8169.c
  2. 566
    0
      src/drivers/net/r8169.h

+ 2043
- 1084
src/drivers/net/r8169.c
Fichier diff supprimé car celui-ci est trop grand
Voir le fichier


+ 566
- 0
src/drivers/net/r8169.h Voir le fichier

@@ -0,0 +1,566 @@
1
+/*
2
+ * Copyright (c) 2008 Marty Connor <mdc@etherboot.org>
3
+ * Copyright (c) 2008 Entity Cyber, Inc.
4
+ *
5
+ * This program is free software; you can redistribute it and/or
6
+ * modify it under the terms of the GNU General Public License as
7
+ * published by the Free Software Foundation; either version 2 of the
8
+ * License, or any later version.
9
+ *
10
+ * This program is distributed in the hope that it will be useful, but
11
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13
+ * General Public License for more details.
14
+ *
15
+ * You should have received a copy of the GNU General Public License
16
+ * along with this program; if not, write to the Free Software
17
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18
+ *
19
+ * This driver is based on rtl8169 data sheets and work by:
20
+ *
21
+ * Copyright (c) 2002 ShuChen <shuchen@realtek.com.tw>
22
+ * Copyright (c) 2003 - 2007 Francois Romieu <romieu@fr.zoreil.com>
23
+ * Copyright (c) a lot of people too. Please respect their work.
24
+ *
25
+ */
26
+
27
+#ifndef _R8169_H_
28
+#define _R8169_H_
29
+
30
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
31
+
32
+/** FIXME: include/linux/pci_regs.h has these PCI regs, maybe
33
+	   we need such a file in gPXE?
34
+**/
35
+#define  PCI_EXP_DEVCTL	        8	/* Device Control */
36
+#define  PCI_EXP_DEVCTL_READRQ	0x7000	/* Max_Read_Request_Size */
37
+#define  PCI_EXP_LNKCTL		16	/* Link Control */
38
+#define  PCI_EXP_LNKCTL_CLKREQ_EN 0x100	/* Enable clkreq */
39
+#define  PCI_EXP_DEVCTL_NOSNOOP_EN 0x0800  /* Enable No Snoop */
40
+
41
+/** FIXME: update mii.h in src/include/mii.h from Linux sources
42
+	   so we don't have to include these definitiions.
43
+**/
44
+/* The forced speed, 10Mb, 100Mb, gigabit, 2.5Gb, 10GbE. */
45
+#define SPEED_10		10
46
+#define SPEED_100		100
47
+#define SPEED_1000		1000
48
+#define SPEED_2500		2500
49
+#define SPEED_10000		10000
50
+
51
+/* Duplex, half or full. */
52
+#define DUPLEX_HALF		0x00
53
+#define DUPLEX_FULL		0x01
54
+
55
+/* Generic MII registers. */
56
+
57
+#define MII_BMCR            0x00        /* Basic mode control register */
58
+#define MII_BMSR            0x01        /* Basic mode status register  */
59
+#define MII_PHYSID1         0x02        /* PHYS ID 1                   */
60
+#define MII_PHYSID2         0x03        /* PHYS ID 2                   */
61
+#define MII_ADVERTISE       0x04        /* Advertisement control reg   */
62
+#define MII_LPA             0x05        /* Link partner ability reg    */
63
+#define MII_EXPANSION       0x06        /* Expansion register          */
64
+#define MII_CTRL1000        0x09        /* 1000BASE-T control          */
65
+#define MII_STAT1000        0x0a        /* 1000BASE-T status           */
66
+#define MII_ESTATUS	    0x0f	/* Extended Status */
67
+#define MII_DCOUNTER        0x12        /* Disconnect counter          */
68
+#define MII_FCSCOUNTER      0x13        /* False carrier counter       */
69
+#define MII_NWAYTEST        0x14        /* N-way auto-neg test reg     */
70
+#define MII_RERRCOUNTER     0x15        /* Receive error counter       */
71
+#define MII_SREVISION       0x16        /* Silicon revision            */
72
+#define MII_RESV1           0x17        /* Reserved...                 */
73
+#define MII_LBRERROR        0x18        /* Lpback, rx, bypass error    */
74
+#define MII_PHYADDR         0x19        /* PHY address                 */
75
+#define MII_RESV2           0x1a        /* Reserved...                 */
76
+#define MII_TPISTATUS       0x1b        /* TPI status for 10mbps       */
77
+#define MII_NCONFIG         0x1c        /* Network interface config    */
78
+
79
+/* Basic mode control register. */
80
+#define BMCR_RESV               0x003f  /* Unused...                   */
81
+#define BMCR_SPEED1000		0x0040  /* MSB of Speed (1000)         */
82
+#define BMCR_CTST               0x0080  /* Collision test              */
83
+#define BMCR_FULLDPLX           0x0100  /* Full duplex                 */
84
+#define BMCR_ANRESTART          0x0200  /* Auto negotiation restart    */
85
+#define BMCR_ISOLATE            0x0400  /* Disconnect DP83840 from MII */
86
+#define BMCR_PDOWN              0x0800  /* Powerdown the DP83840       */
87
+#define BMCR_ANENABLE           0x1000  /* Enable auto negotiation     */
88
+#define BMCR_SPEED100           0x2000  /* Select 100Mbps              */
89
+#define BMCR_LOOPBACK           0x4000  /* TXD loopback bits           */
90
+#define BMCR_RESET              0x8000  /* Reset the DP83840           */
91
+
92
+/* Basic mode status register. */
93
+#define BMSR_ERCAP              0x0001  /* Ext-reg capability          */
94
+#define BMSR_JCD                0x0002  /* Jabber detected             */
95
+#define BMSR_LSTATUS            0x0004  /* Link status                 */
96
+#define BMSR_ANEGCAPABLE        0x0008  /* Able to do auto-negotiation */
97
+#define BMSR_RFAULT             0x0010  /* Remote fault detected       */
98
+#define BMSR_ANEGCOMPLETE       0x0020  /* Auto-negotiation complete   */
99
+#define BMSR_RESV               0x00c0  /* Unused...                   */
100
+#define BMSR_ESTATEN		0x0100	/* Extended Status in R15 */
101
+#define BMSR_100HALF2           0x0200  /* Can do 100BASE-T2 HDX */
102
+#define BMSR_100FULL2           0x0400  /* Can do 100BASE-T2 FDX */
103
+#define BMSR_10HALF             0x0800  /* Can do 10mbps, half-duplex  */
104
+#define BMSR_10FULL             0x1000  /* Can do 10mbps, full-duplex  */
105
+#define BMSR_100HALF            0x2000  /* Can do 100mbps, half-duplex */
106
+#define BMSR_100FULL            0x4000  /* Can do 100mbps, full-duplex */
107
+#define BMSR_100BASE4           0x8000  /* Can do 100mbps, 4k packets  */
108
+
109
+#define AUTONEG_DISABLE		0x00
110
+#define AUTONEG_ENABLE		0x01
111
+
112
+#define MII_ADVERTISE           0x04        /* Advertisement control reg   */
113
+#define ADVERTISE_SLCT          0x001f  /* Selector bits               */
114
+#define ADVERTISE_CSMA          0x0001  /* Only selector supported     */
115
+#define ADVERTISE_10HALF        0x0020  /* Try for 10mbps half-duplex  */
116
+#define ADVERTISE_1000XFULL     0x0020  /* Try for 1000BASE-X full-duplex */
117
+#define ADVERTISE_10FULL        0x0040  /* Try for 10mbps full-duplex  */
118
+#define ADVERTISE_1000XHALF     0x0040  /* Try for 1000BASE-X half-duplex */
119
+#define ADVERTISE_100HALF       0x0080  /* Try for 100mbps half-duplex */
120
+#define ADVERTISE_1000XPAUSE    0x0080  /* Try for 1000BASE-X pause    */
121
+#define ADVERTISE_100FULL       0x0100  /* Try for 100mbps full-duplex */
122
+#define ADVERTISE_1000XPSE_ASYM 0x0100  /* Try for 1000BASE-X asym pause */
123
+#define ADVERTISE_100BASE4      0x0200  /* Try for 100mbps 4k packets  */
124
+#define ADVERTISE_PAUSE_CAP     0x0400  /* Try for pause               */
125
+#define ADVERTISE_PAUSE_ASYM    0x0800  /* Try for asymetric pause     */
126
+#define ADVERTISE_RESV          0x1000  /* Unused...                   */
127
+#define ADVERTISE_RFAULT        0x2000  /* Say we can detect faults    */
128
+#define ADVERTISE_LPACK         0x4000  /* Ack link partners response  */
129
+#define ADVERTISE_NPAGE         0x8000  /* Next page bit               */
130
+#define ADVERTISE_FULL (ADVERTISE_100FULL | ADVERTISE_10FULL | \
131
+			ADVERTISE_CSMA)
132
+#define ADVERTISE_ALL (ADVERTISE_10HALF | ADVERTISE_10FULL | \
133
+		       ADVERTISE_100HALF | ADVERTISE_100FULL)
134
+
135
+/* 1000BASE-T Control register */
136
+#define ADVERTISE_1000FULL      0x0200  /* Advertise 1000BASE-T full duplex */
137
+#define ADVERTISE_1000HALF      0x0100  /* Advertise 1000BASE-T half duplex */
138
+
139
+/* MAC address length */
140
+#define MAC_ADDR_LEN	6
141
+
142
+#define MAX_READ_REQUEST_SHIFT	12
143
+#define RX_FIFO_THRESH	7	/* 7 means NO threshold, Rx buffer level before first PCI xfer. */
144
+#define RX_DMA_BURST	6	/* Maximum PCI burst, '6' is 1024 */
145
+#define TX_DMA_BURST	6	/* Maximum PCI burst, '6' is 1024 */
146
+#define EarlyTxThld	0x3F	/* 0x3F means NO early transmit */
147
+#define RxPacketMaxSize	0x3FE8	/* 16K - 1 - ETH_HLEN - VLAN - CRC... */
148
+#define SafeMtu		0x1c20	/* ... actually life sucks beyond ~7k */
149
+#define InterFrameGap	0x03	/* 3 means InterFrameGap = the shortest one */
150
+
151
+#define R8169_REGS_SIZE		256
152
+#define R8169_NAPI_WEIGHT	64
153
+#define NUM_TX_DESC	8	/* Number of Tx descriptor registers */
154
+#define NUM_RX_DESC	8	/* Number of Rx descriptor registers */
155
+#define RX_BUF_SIZE	1536	/* Rx Buffer size */
156
+#define R8169_TX_RING_BYTES	(NUM_TX_DESC * sizeof(struct TxDesc))
157
+#define R8169_RX_RING_BYTES	(NUM_RX_DESC * sizeof(struct RxDesc))
158
+
159
+#define TX_RING_ALIGN		256
160
+#define RX_RING_ALIGN		256
161
+
162
+#define RTL8169_TX_TIMEOUT	(6*HZ)
163
+#define RTL8169_PHY_TIMEOUT	(10*HZ)
164
+
165
+#define RTL_EEPROM_SIG		cpu_to_le32(0x8129)
166
+#define RTL_EEPROM_SIG_MASK	cpu_to_le32(0xffff)
167
+#define RTL_EEPROM_SIG_ADDR	0x0000
168
+
169
+/* write/read MMIO register */
170
+#define RTL_W8(reg, val8)	writeb ((val8), ioaddr + (reg))
171
+#define RTL_W16(reg, val16)	writew ((val16), ioaddr + (reg))
172
+#define RTL_W32(reg, val32)	writel ((val32), ioaddr + (reg))
173
+#define RTL_R8(reg)		readb (ioaddr + (reg))
174
+#define RTL_R16(reg)		readw (ioaddr + (reg))
175
+#define RTL_R32(reg)		((unsigned long) readl (ioaddr + (reg)))
176
+
177
+enum mac_version {
178
+	RTL_GIGA_MAC_VER_01 = 0x01, // 8169
179
+	RTL_GIGA_MAC_VER_02 = 0x02, // 8169S
180
+	RTL_GIGA_MAC_VER_03 = 0x03, // 8110S
181
+	RTL_GIGA_MAC_VER_04 = 0x04, // 8169SB
182
+	RTL_GIGA_MAC_VER_05 = 0x05, // 8110SCd
183
+	RTL_GIGA_MAC_VER_06 = 0x06, // 8110SCe
184
+	RTL_GIGA_MAC_VER_07 = 0x07, // 8102e
185
+	RTL_GIGA_MAC_VER_08 = 0x08, // 8102e
186
+	RTL_GIGA_MAC_VER_09 = 0x09, // 8102e
187
+	RTL_GIGA_MAC_VER_10 = 0x0a, // 8101e
188
+	RTL_GIGA_MAC_VER_11 = 0x0b, // 8168Bb
189
+	RTL_GIGA_MAC_VER_12 = 0x0c, // 8168Be
190
+	RTL_GIGA_MAC_VER_13 = 0x0d, // 8101Eb
191
+	RTL_GIGA_MAC_VER_14 = 0x0e, // 8101 ?
192
+	RTL_GIGA_MAC_VER_15 = 0x0f, // 8101 ?
193
+	RTL_GIGA_MAC_VER_16 = 0x11, // 8101Ec
194
+	RTL_GIGA_MAC_VER_17 = 0x10, // 8168Bf
195
+	RTL_GIGA_MAC_VER_18 = 0x12, // 8168CP
196
+	RTL_GIGA_MAC_VER_19 = 0x13, // 8168C
197
+	RTL_GIGA_MAC_VER_20 = 0x14, // 8168C
198
+	RTL_GIGA_MAC_VER_21 = 0x15, // 8168C
199
+	RTL_GIGA_MAC_VER_22 = 0x16, // 8168C
200
+	RTL_GIGA_MAC_VER_23 = 0x17, // 8168CP
201
+	RTL_GIGA_MAC_VER_24 = 0x18, // 8168CP
202
+	RTL_GIGA_MAC_VER_25 = 0x19, // 8168D
203
+};
204
+
205
+#define _R(NAME,MAC,MASK) \
206
+	{ .name = NAME, .mac_version = MAC, .RxConfigMask = MASK }
207
+
208
+static const struct {
209
+	const char *name;
210
+	u8 mac_version;
211
+	u32 RxConfigMask;	/* Clears the bits supported by this chip */
212
+} rtl_chip_info[] = {
213
+	_R("RTL8169",		RTL_GIGA_MAC_VER_01, 0xff7e1880), // 8169
214
+	_R("RTL8169s",		RTL_GIGA_MAC_VER_02, 0xff7e1880), // 8169S
215
+	_R("RTL8110s",		RTL_GIGA_MAC_VER_03, 0xff7e1880), // 8110S
216
+	_R("RTL8169sb/8110sb",	RTL_GIGA_MAC_VER_04, 0xff7e1880), // 8169SB
217
+	_R("RTL8169sc/8110sc",	RTL_GIGA_MAC_VER_05, 0xff7e1880), // 8110SCd
218
+	_R("RTL8169sc/8110sc",	RTL_GIGA_MAC_VER_06, 0xff7e1880), // 8110SCe
219
+	_R("RTL8102e",		RTL_GIGA_MAC_VER_07, 0xff7e1880), // PCI-E
220
+	_R("RTL8102e",		RTL_GIGA_MAC_VER_08, 0xff7e1880), // PCI-E
221
+	_R("RTL8102e",		RTL_GIGA_MAC_VER_09, 0xff7e1880), // PCI-E
222
+	_R("RTL8101e",		RTL_GIGA_MAC_VER_10, 0xff7e1880), // PCI-E
223
+	_R("RTL8168b/8111b",	RTL_GIGA_MAC_VER_11, 0xff7e1880), // PCI-E
224
+	_R("RTL8168b/8111b",	RTL_GIGA_MAC_VER_12, 0xff7e1880), // PCI-E
225
+	_R("RTL8101e",		RTL_GIGA_MAC_VER_13, 0xff7e1880), // PCI-E 8139
226
+	_R("RTL8100e",		RTL_GIGA_MAC_VER_14, 0xff7e1880), // PCI-E 8139
227
+	_R("RTL8100e",		RTL_GIGA_MAC_VER_15, 0xff7e1880), // PCI-E 8139
228
+	_R("RTL8168b/8111b",	RTL_GIGA_MAC_VER_17, 0xff7e1880), // PCI-E
229
+	_R("RTL8101e",		RTL_GIGA_MAC_VER_16, 0xff7e1880), // PCI-E
230
+	_R("RTL8168cp/8111cp",	RTL_GIGA_MAC_VER_18, 0xff7e1880), // PCI-E
231
+	_R("RTL8168c/8111c",	RTL_GIGA_MAC_VER_19, 0xff7e1880), // PCI-E
232
+	_R("RTL8168c/8111c",	RTL_GIGA_MAC_VER_20, 0xff7e1880), // PCI-E
233
+	_R("RTL8168c/8111c",	RTL_GIGA_MAC_VER_21, 0xff7e1880), // PCI-E
234
+	_R("RTL8168c/8111c",	RTL_GIGA_MAC_VER_22, 0xff7e1880), // PCI-E
235
+	_R("RTL8168cp/8111cp",	RTL_GIGA_MAC_VER_23, 0xff7e1880), // PCI-E
236
+	_R("RTL8168cp/8111cp",	RTL_GIGA_MAC_VER_24, 0xff7e1880), // PCI-E
237
+	_R("RTL8168d/8111d",	RTL_GIGA_MAC_VER_25, 0xff7e1880)  // PCI-E
238
+};
239
+#undef _R
240
+
241
+enum cfg_version {
242
+	RTL_CFG_0 = 0x00,
243
+	RTL_CFG_1,
244
+	RTL_CFG_2
245
+};
246
+
247
+#if 0
248
+/** Device Table from Linux Driver **/
249
+static struct pci_device_id rtl8169_pci_tbl[] = {
250
+	{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK,	0x8129), 0, 0, RTL_CFG_0 },
251
+	{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK,	0x8136), 0, 0, RTL_CFG_2 },
252
+	{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK,	0x8167), 0, 0, RTL_CFG_0 },
253
+	{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK,	0x8168), 0, 0, RTL_CFG_1 },
254
+	{ PCI_DEVICE(PCI_VENDOR_ID_REALTEK,	0x8169), 0, 0, RTL_CFG_0 },
255
+	{ PCI_DEVICE(PCI_VENDOR_ID_DLINK,	0x4300), 0, 0, RTL_CFG_0 },
256
+	{ PCI_DEVICE(PCI_VENDOR_ID_AT,		0xc107), 0, 0, RTL_CFG_0 },
257
+	{ PCI_DEVICE(0x16ec,			0x0116), 0, 0, RTL_CFG_0 },
258
+	{ PCI_VENDOR_ID_LINKSYS,		0x1032,
259
+		PCI_ANY_ID, 0x0024, 0, 0, RTL_CFG_0 },
260
+	{ 0x0001,				0x8168,
261
+		PCI_ANY_ID, 0x2410, 0, 0, RTL_CFG_2 },
262
+	{0,},
263
+};
264
+#endif
265
+
266
+enum rtl_registers {
267
+	MAC0		= 0,	/* Ethernet hardware address. */
268
+	MAC4		= 4,
269
+	MAR0		= 8,	/* Multicast filter. */
270
+	CounterAddrLow		= 0x10,
271
+	CounterAddrHigh		= 0x14,
272
+	TxDescStartAddrLow	= 0x20,
273
+	TxDescStartAddrHigh	= 0x24,
274
+	TxHDescStartAddrLow	= 0x28,
275
+	TxHDescStartAddrHigh	= 0x2c,
276
+	FLASH		= 0x30,
277
+	ERSR		= 0x36,
278
+	ChipCmd		= 0x37,
279
+	TxPoll		= 0x38,
280
+	IntrMask	= 0x3c,
281
+	IntrStatus	= 0x3e,
282
+	TxConfig	= 0x40,
283
+	RxConfig	= 0x44,
284
+	RxMissed	= 0x4c,
285
+	Cfg9346		= 0x50,
286
+	Config0		= 0x51,
287
+	Config1		= 0x52,
288
+	Config2		= 0x53,
289
+	Config3		= 0x54,
290
+	Config4		= 0x55,
291
+	Config5		= 0x56,
292
+	MultiIntr	= 0x5c,
293
+	PHYAR		= 0x60,
294
+	PHYstatus	= 0x6c,
295
+	RxMaxSize	= 0xda,
296
+	CPlusCmd	= 0xe0,
297
+	IntrMitigate	= 0xe2,
298
+	RxDescAddrLow	= 0xe4,
299
+	RxDescAddrHigh	= 0xe8,
300
+	EarlyTxThres	= 0xec,
301
+	FuncEvent	= 0xf0,
302
+	FuncEventMask	= 0xf4,
303
+	FuncPresetState	= 0xf8,
304
+	FuncForceEvent	= 0xfc,
305
+};
306
+
307
+enum rtl8110_registers {
308
+	TBICSR			= 0x64,
309
+	TBI_ANAR		= 0x68,
310
+	TBI_LPAR		= 0x6a,
311
+};
312
+
313
+enum rtl8168_8101_registers {
314
+	CSIDR			= 0x64,
315
+	CSIAR			= 0x68,
316
+#define	CSIAR_FLAG			0x80000000
317
+#define	CSIAR_WRITE_CMD			0x80000000
318
+#define	CSIAR_BYTE_ENABLE		0x0f
319
+#define	CSIAR_BYTE_ENABLE_SHIFT		12
320
+#define	CSIAR_ADDR_MASK			0x0fff
321
+
322
+	EPHYAR			= 0x80,
323
+#define	EPHYAR_FLAG			0x80000000
324
+#define	EPHYAR_WRITE_CMD		0x80000000
325
+#define	EPHYAR_REG_MASK			0x1f
326
+#define	EPHYAR_REG_SHIFT		16
327
+#define	EPHYAR_DATA_MASK		0xffff
328
+	DBG_REG			= 0xd1,
329
+#define	FIX_NAK_1			(1 << 4)
330
+#define	FIX_NAK_2			(1 << 3)
331
+};
332
+
333
+enum rtl_register_content {
334
+	/* InterruptStatusBits */
335
+	SYSErr		= 0x8000,
336
+	PCSTimeout	= 0x4000,
337
+	SWInt		= 0x0100,
338
+	TxDescUnavail	= 0x0080,
339
+	RxFIFOOver	= 0x0040,
340
+	LinkChg		= 0x0020,
341
+	RxOverflow	= 0x0010,
342
+	TxErr		= 0x0008,
343
+	TxOK		= 0x0004,
344
+	RxErr		= 0x0002,
345
+	RxOK		= 0x0001,
346
+
347
+	/* RxStatusDesc */
348
+	RxFOVF	= (1 << 23),
349
+	RxRWT	= (1 << 22),
350
+	RxRES	= (1 << 21),
351
+	RxRUNT	= (1 << 20),
352
+	RxCRC	= (1 << 19),
353
+
354
+	/* ChipCmdBits */
355
+	CmdReset	= 0x10,
356
+	CmdRxEnb	= 0x08,
357
+	CmdTxEnb	= 0x04,
358
+	RxBufEmpty	= 0x01,
359
+
360
+	/* TXPoll register p.5 */
361
+	HPQ		= 0x80,		/* Poll cmd on the high prio queue */
362
+	NPQ		= 0x40,		/* Poll cmd on the low prio queue */
363
+	FSWInt		= 0x01,		/* Forced software interrupt */
364
+
365
+	/* Cfg9346Bits */
366
+	Cfg9346_Lock	= 0x00,
367
+	Cfg9346_Unlock	= 0xc0,
368
+
369
+	/* rx_mode_bits */
370
+	AcceptErr	= 0x20,
371
+	AcceptRunt	= 0x10,
372
+	AcceptBroadcast	= 0x08,
373
+	AcceptMulticast	= 0x04,
374
+	AcceptMyPhys	= 0x02,
375
+	AcceptAllPhys	= 0x01,
376
+
377
+	/* RxConfigBits */
378
+	RxCfgFIFOShift	= 13,
379
+	RxCfgDMAShift	=  8,
380
+
381
+	/* TxConfigBits */
382
+	TxInterFrameGapShift = 24,
383
+	TxDMAShift = 8,	/* DMA burst value (0-7) is shift this many bits */
384
+
385
+	/* Config1 register p.24 */
386
+	LEDS1		= (1 << 7),
387
+	LEDS0		= (1 << 6),
388
+	MSIEnable	= (1 << 5),	/* Enable Message Signaled Interrupt */
389
+	Speed_down	= (1 << 4),
390
+	MEMMAP		= (1 << 3),
391
+	IOMAP		= (1 << 2),
392
+	VPD		= (1 << 1),
393
+	PMEnable	= (1 << 0),	/* Power Management Enable */
394
+
395
+	/* Config2 register p. 25 */
396
+	PCI_Clock_66MHz = 0x01,
397
+	PCI_Clock_33MHz = 0x00,
398
+
399
+	/* Config3 register p.25 */
400
+	MagicPacket	= (1 << 5),	/* Wake up when receives a Magic Packet */
401
+	LinkUp		= (1 << 4),	/* Wake up when the cable connection is re-established */
402
+	Beacon_en	= (1 << 0),	/* 8168 only. Reserved in the 8168b */
403
+
404
+	/* Config5 register p.27 */
405
+	BWF		= (1 << 6),	/* Accept Broadcast wakeup frame */
406
+	MWF		= (1 << 5),	/* Accept Multicast wakeup frame */
407
+	UWF		= (1 << 4),	/* Accept Unicast wakeup frame */
408
+	LanWake		= (1 << 1),	/* LanWake enable/disable */
409
+	PMEStatus	= (1 << 0),	/* PME status can be reset by PCI RST# */
410
+
411
+	/* TBICSR p.28 */
412
+	TBIReset	= 0x80000000,
413
+	TBILoopback	= 0x40000000,
414
+	TBINwEnable	= 0x20000000,
415
+	TBINwRestart	= 0x10000000,
416
+	TBILinkOk	= 0x02000000,
417
+	TBINwComplete	= 0x01000000,
418
+
419
+	/* CPlusCmd p.31 */
420
+	EnableBist	= (1 << 15),	// 8168 8101
421
+	Mac_dbgo_oe	= (1 << 14),	// 8168 8101
422
+	Normal_mode	= (1 << 13),	// unused
423
+	Force_half_dup	= (1 << 12),	// 8168 8101
424
+	Force_rxflow_en	= (1 << 11),	// 8168 8101
425
+	Force_txflow_en	= (1 << 10),	// 8168 8101
426
+	Cxpl_dbg_sel	= (1 << 9),	// 8168 8101
427
+	ASF		= (1 << 8),	// 8168 8101
428
+	PktCntrDisable	= (1 << 7),	// 8168 8101
429
+	Mac_dbgo_sel	= 0x001c,	// 8168
430
+	RxVlan		= (1 << 6),
431
+	RxChkSum	= (1 << 5),
432
+	PCIDAC		= (1 << 4),
433
+	PCIMulRW	= (1 << 3),
434
+	INTT_0		= 0x0000,	// 8168
435
+	INTT_1		= 0x0001,	// 8168
436
+	INTT_2		= 0x0002,	// 8168
437
+	INTT_3		= 0x0003,	// 8168
438
+
439
+	/* rtl8169_PHYstatus */
440
+	TBI_Enable	= 0x80,
441
+	TxFlowCtrl	= 0x40,
442
+	RxFlowCtrl	= 0x20,
443
+	_1000bpsF	= 0x10,
444
+	_100bps		= 0x08,
445
+	_10bps		= 0x04,
446
+	LinkStatus	= 0x02,
447
+	FullDup		= 0x01,
448
+
449
+	/* _TBICSRBit */
450
+	TBILinkOK	= 0x02000000,
451
+
452
+	/* DumpCounterCommand */
453
+	CounterDump	= 0x8,
454
+};
455
+
456
+enum desc_status_bit {
457
+	DescOwn		= (1 << 31), /* Descriptor is owned by NIC */
458
+	RingEnd		= (1 << 30), /* End of descriptor ring */
459
+	FirstFrag	= (1 << 29), /* First segment of a packet */
460
+	LastFrag	= (1 << 28), /* Final segment of a packet */
461
+
462
+	/* Tx private */
463
+	LargeSend	= (1 << 27), /* TCP Large Send Offload (TSO) */
464
+	MSSShift	= 16,        /* MSS value position */
465
+	MSSMask		= 0xfff,     /* MSS value + LargeSend bit: 12 bits */
466
+	IPCS		= (1 << 18), /* Calculate IP checksum */
467
+	UDPCS		= (1 << 17), /* Calculate UDP/IP checksum */
468
+	TCPCS		= (1 << 16), /* Calculate TCP/IP checksum */
469
+	TxVlanTag	= (1 << 17), /* Add VLAN tag */
470
+
471
+	/* Rx private */
472
+	PID1		= (1 << 18), /* Protocol ID bit 1/2 */
473
+	PID0		= (1 << 17), /* Protocol ID bit 2/2 */
474
+
475
+#define RxProtoUDP	(PID1)
476
+#define RxProtoTCP	(PID0)
477
+#define RxProtoIP	(PID1 | PID0)
478
+#define RxProtoMask	RxProtoIP
479
+
480
+	IPFail		= (1 << 16), /* IP checksum failed */
481
+	UDPFail		= (1 << 15), /* UDP/IP checksum failed */
482
+	TCPFail		= (1 << 14), /* TCP/IP checksum failed */
483
+	RxVlanTag	= (1 << 16), /* VLAN tag available */
484
+};
485
+
486
+#define RsvdMask	0x3fffc000
487
+
488
+struct TxDesc {
489
+	volatile uint32_t opts1;
490
+	volatile uint32_t opts2;
491
+	volatile uint32_t addr_lo;
492
+	volatile uint32_t addr_hi;
493
+};
494
+
495
+struct RxDesc {
496
+	volatile uint32_t opts1;
497
+	volatile uint32_t opts2;
498
+	volatile uint32_t addr_lo;
499
+	volatile uint32_t addr_hi;
500
+};
501
+
502
+enum features {
503
+	RTL_FEATURE_WOL		= (1 << 0),
504
+	RTL_FEATURE_MSI		= (1 << 1),
505
+	RTL_FEATURE_GMII	= (1 << 2),
506
+};
507
+
508
+static void rtl_hw_start_8169(struct net_device *);
509
+static void rtl_hw_start_8168(struct net_device *);
510
+static void rtl_hw_start_8101(struct net_device *);
511
+
512
+struct rtl8169_private {
513
+
514
+	struct pci_device *pci_dev;
515
+	struct net_device *netdev;
516
+	uint8_t *hw_addr;
517
+	void *mmio_addr;
518
+	uint32_t irqno;
519
+
520
+	int chipset;
521
+	int mac_version;
522
+	int cfg_index;
523
+	u16 intr_event;
524
+
525
+	struct io_buffer *tx_iobuf[NUM_TX_DESC];
526
+	struct io_buffer *rx_iobuf[NUM_RX_DESC];
527
+
528
+	struct TxDesc *tx_base;
529
+	struct RxDesc *rx_base;
530
+
531
+	uint32_t tx_curr;
532
+	uint32_t rx_curr;
533
+
534
+	uint32_t tx_tail;
535
+
536
+	uint32_t tx_fill_ctr;
537
+
538
+	u16 cp_cmd;
539
+
540
+	int phy_auto_nego_reg;
541
+	int phy_1000_ctrl_reg;
542
+
543
+	int ( *set_speed ) (struct net_device *, u8 autoneg, u16 speed, u8 duplex );
544
+	void ( *phy_reset_enable ) ( void *ioaddr );
545
+	void ( *hw_start ) ( struct net_device * );
546
+	unsigned int ( *phy_reset_pending ) ( void *ioaddr );
547
+	unsigned int ( *link_ok ) ( void *ioaddr );
548
+
549
+	int pcie_cap;
550
+
551
+	unsigned features;
552
+
553
+};
554
+
555
+static const unsigned int rtl8169_rx_config =
556
+	(RX_FIFO_THRESH << RxCfgFIFOShift) | (RX_DMA_BURST << RxCfgDMAShift);
557
+
558
+#endif /* _R8169_H_ */
559
+
560
+/*
561
+ * Local variables:
562
+ *  c-basic-offset: 8
563
+ *  c-indent-level: 8
564
+ *  tab-width: 8
565
+ * End:
566
+ */

Chargement…
Annuler
Enregistrer