author | Florian Pose <fp@igh-essen.com> |
Fri, 11 Nov 2005 10:55:22 +0000 | |
changeset 10 | 67c739ece5d5 |
parent 5 | 6f2508af550c |
child 18 | 5a42f6d1085c |
permissions | -rw-r--r-- |
0 | 1 |
/****************************************************************************** |
2 |
* |
|
3 |
* drv_8139too.c |
|
4 |
* |
|
5 |
* EtherCAT-Treiber für RTL8139-kompatible Netzwerkkarten. |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
6 |
* |
0 | 7 |
* Autoren: Wilhelm Hagemeister, Florian Pose |
8 |
* |
|
9 |
* $Date$ |
|
10 |
* $Author$ |
|
11 |
* |
|
12 |
* (C) Copyright IgH 2005 |
|
13 |
* Ingenieurgemeinschaft IgH |
|
14 |
* Heinz-Bäcker Str. 34 |
|
15 |
* D-45356 Essen |
|
16 |
* Tel.: +49 201/61 99 31 |
|
17 |
* Fax.: +49 201/61 98 36 |
|
18 |
* E-mail: sp@igh-essen.com |
|
19 |
* |
|
20 |
******************************************************************************/ |
|
21 |
||
22 |
/* |
|
23 |
8139too.c: A RealTek RTL-8139 Fast Ethernet driver for Linux. |
|
24 |
||
25 |
Maintained by Jeff Garzik <jgarzik@mandrakesoft.com> |
|
26 |
Copyright 2000-2002 Jeff Garzik |
|
27 |
||
28 |
Much code comes from Donald Becker's rtl8139.c driver, |
|
29 |
versions 1.13 and older. This driver was originally based |
|
30 |
on rtl8139.c version 1.07. Header of rtl8139.c version 1.13: |
|
31 |
||
32 |
-----<snip>----- |
|
33 |
||
34 |
Written 1997-2001 by Donald Becker. |
|
35 |
This software may be used and distributed according to the |
|
36 |
terms of the GNU General Public License (GPL), incorporated |
|
37 |
herein by reference. Drivers based on or derived from this |
|
38 |
code fall under the GPL and must retain the authorship, |
|
39 |
copyright and license notice. This file is not a complete |
|
40 |
program and may only be used when the entire operating |
|
41 |
system is licensed under the GPL. |
|
42 |
||
43 |
This driver is for boards based on the RTL8129 and RTL8139 |
|
44 |
PCI ethernet chips. |
|
45 |
||
46 |
The author may be reached as becker@scyld.com, or C/O Scyld |
|
47 |
Computing Corporation 410 Severn Ave., Suite 210 Annapolis |
|
48 |
MD 21403 |
|
49 |
||
50 |
Support and updates available at |
|
51 |
http://www.scyld.com/network/rtl8139.html |
|
52 |
||
53 |
Twister-tuning table provided by Kinston |
|
54 |
<shangh@realtek.com.tw>. |
|
55 |
||
56 |
-----<snip>----- |
|
57 |
||
58 |
This software may be used and distributed according to the terms |
|
59 |
of the GNU General Public License, incorporated herein by reference. |
|
60 |
||
61 |
Contributors: |
|
62 |
||
63 |
Donald Becker - he wrote the original driver, kudos to him! |
|
64 |
(but please don't e-mail him for support, this isn't his driver) |
|
65 |
||
66 |
Tigran Aivazian - bug fixes, skbuff free cleanup |
|
67 |
||
68 |
Martin Mares - suggestions for PCI cleanup |
|
69 |
||
70 |
David S. Miller - PCI DMA and softnet updates |
|
71 |
||
72 |
Ernst Gill - fixes ported from BSD driver |
|
73 |
||
74 |
Daniel Kobras - identified specific locations of |
|
75 |
posted MMIO write bugginess |
|
76 |
||
77 |
Gerard Sharp - bug fix, testing and feedback |
|
78 |
||
79 |
David Ford - Rx ring wrap fix |
|
80 |
||
81 |
Dan DeMaggio - swapped RTL8139 cards with me, and allowed me |
|
82 |
to find and fix a crucial bug on older chipsets. |
|
83 |
||
84 |
Donald Becker/Chris Butterworth/Marcus Westergren - |
|
85 |
Noticed various Rx packet size-related buglets. |
|
86 |
||
87 |
Santiago Garcia Mantinan - testing and feedback |
|
88 |
||
89 |
Jens David - 2.2.x kernel backports |
|
90 |
||
91 |
Martin Dennett - incredibly helpful insight on undocumented |
|
92 |
features of the 8139 chips |
|
93 |
||
94 |
Jean-Jacques Michel - bug fix |
|
95 |
||
96 |
Tobias Ringström - Rx interrupt status checking suggestion |
|
97 |
||
98 |
Andrew Morton - Clear blocked signals, avoid |
|
99 |
buffer overrun setting current->comm. |
|
100 |
||
101 |
Kalle Olavi Niemitalo - Wake-on-LAN ioctls |
|
102 |
||
103 |
Robert Kuebel - Save kernel thread from dying on any signal. |
|
104 |
||
105 |
Submitting bug reports: |
|
106 |
||
107 |
"rtl8139-diag -mmmaaavvveefN" output |
|
108 |
enable RTL8139_DEBUG below, and look at 'dmesg' or kernel log |
|
109 |
||
110 |
See 8139too.txt for more details. |
|
111 |
||
112 |
*/ |
|
113 |
||
114 |
#define DRV_NAME "8139too_ecat" |
|
115 |
#define DRV_VERSION "0.9.26" |
|
116 |
||
117 |
||
118 |
#include <linux/config.h> |
|
119 |
#include <linux/module.h> |
|
120 |
#include <linux/kernel.h> |
|
121 |
#include <linux/compiler.h> |
|
122 |
#include <linux/pci.h> |
|
123 |
#include <linux/init.h> |
|
124 |
#include <linux/ioport.h> |
|
125 |
#include <linux/netdevice.h> |
|
126 |
#include <linux/etherdevice.h> |
|
127 |
#include <linux/rtnetlink.h> |
|
128 |
#include <linux/delay.h> |
|
129 |
#include <linux/ethtool.h> |
|
130 |
#include <linux/mii.h> |
|
131 |
#include <linux/completion.h> |
|
132 |
#include <linux/crc32.h> |
|
133 |
#include <asm/io.h> |
|
134 |
#include <asm/uaccess.h> |
|
135 |
||
136 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
137 |
||
138 |
#include "ec_device.h" |
|
139 |
#include "ec_dbg.h" |
|
140 |
||
141 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
142 |
||
143 |
#define RTL8139_DRIVER_NAME DRV_NAME " Fast Ethernet driver " DRV_VERSION |
|
144 |
#define PFX DRV_NAME ": " |
|
145 |
||
146 |
||
147 |
/* enable PIO instead of MMIO, if CONFIG_8139TOO_PIO is selected */ |
|
148 |
#ifdef CONFIG_8139TOO_PIO |
|
149 |
#define USE_IO_OPS 1 |
|
150 |
#endif |
|
151 |
||
152 |
/* define to 1 to enable copious debugging info */ |
|
153 |
//#define RTL8139_DEBUG 1 |
|
154 |
#undef RTL8139_DEBUG |
|
155 |
||
156 |
/* define to 1 to disable lightweight runtime debugging checks */ |
|
157 |
#undef RTL8139_NDEBUG |
|
158 |
||
159 |
||
160 |
#ifdef RTL8139_DEBUG |
|
161 |
/* note: prints function name for you */ |
|
162 |
# define DPRINTK(fmt, args...) EC_DBG(KERN_DEBUG "%s: " fmt, __FUNCTION__ , ## args) |
|
163 |
#else |
|
164 |
# define DPRINTK(fmt, args...) |
|
165 |
#endif |
|
166 |
||
167 |
#ifdef RTL8139_NDEBUG |
|
168 |
# define assert(expr) do {} while (0) |
|
169 |
#else |
|
170 |
# define assert(expr) \ |
|
171 |
if(!(expr)) { \ |
|
172 |
printk( "Assertion failed! %s,%s,%s,line=%d\n", \ |
|
173 |
#expr,__FILE__,__FUNCTION__,__LINE__); \ |
|
174 |
} |
|
175 |
#endif |
|
176 |
||
177 |
||
178 |
/* A few user-configurable values. */ |
|
179 |
/* media options */ |
|
180 |
#define MAX_UNITS 8 |
|
181 |
static int media[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1}; |
|
182 |
static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1}; |
|
183 |
||
184 |
/* Maximum events (Rx packets, etc.) to handle at each interrupt. */ |
|
185 |
static int max_interrupt_work = 20; |
|
186 |
||
187 |
/* Maximum number of multicast addresses to filter (vs. Rx-all-multicast). |
|
188 |
The RTL chips use a 64 element hash table based on the Ethernet CRC. */ |
|
189 |
static int multicast_filter_limit = 32; |
|
190 |
||
191 |
/* bitmapped message enable number */ |
|
192 |
static int debug = -1; |
|
193 |
||
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
194 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
195 |
|
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
196 |
// Device index for EtherCAT device selection |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
197 |
static int ec_device_index = -1; |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
198 |
|
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
199 |
//#define ECAT_DEBUG |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
200 |
|
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
201 |
EtherCAT_device_t rtl_ecat_dev; |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
202 |
|
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
203 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
204 |
|
0 | 205 |
/* Size of the in-memory receive ring. */ |
206 |
#define RX_BUF_LEN_IDX 2 /* 0==8K, 1==16K, 2==32K, 3==64K */ |
|
207 |
#define RX_BUF_LEN (8192 << RX_BUF_LEN_IDX) |
|
208 |
#define RX_BUF_PAD 16 |
|
209 |
#define RX_BUF_WRAP_PAD 2048 /* spare padding to handle lack of packet wrap */ |
|
210 |
#define RX_BUF_TOT_LEN (RX_BUF_LEN + RX_BUF_PAD + RX_BUF_WRAP_PAD) |
|
211 |
||
212 |
/* Number of Tx descriptor registers. */ |
|
213 |
#define NUM_TX_DESC 4 |
|
214 |
||
215 |
/* max supported ethernet frame size -- must be at least (dev->mtu+14+4).*/ |
|
216 |
#define MAX_ETH_FRAME_SIZE 1536 |
|
217 |
||
218 |
/* Size of the Tx bounce buffers -- must be at least (dev->mtu+14+4). */ |
|
219 |
#define TX_BUF_SIZE MAX_ETH_FRAME_SIZE |
|
220 |
#define TX_BUF_TOT_LEN (TX_BUF_SIZE * NUM_TX_DESC) |
|
221 |
||
222 |
/* PCI Tuning Parameters |
|
223 |
Threshold is bytes transferred to chip before transmission starts. */ |
|
224 |
#define TX_FIFO_THRESH 256 /* In bytes, rounded down to 32 byte units. */ |
|
225 |
||
226 |
/* The following settings are log_2(bytes)-4: 0 == 16 bytes .. 6==1024, 7==end of packet. */ |
|
227 |
#define RX_FIFO_THRESH 7 /* Rx buffer level before first PCI xfer. */ |
|
228 |
#define RX_DMA_BURST 7 /* Maximum PCI burst, '6' is 1024 */ |
|
229 |
#define TX_DMA_BURST 6 /* Maximum PCI burst, '6' is 1024 */ |
|
230 |
#define TX_RETRY 8 /* 0-15. retries = 16 + (TX_RETRY * 16) */ |
|
231 |
||
232 |
/* Operational parameters that usually are not changed. */ |
|
233 |
/* Time in jiffies before concluding the transmitter is hung. */ |
|
234 |
#define TX_TIMEOUT (6*HZ) |
|
235 |
||
236 |
||
237 |
enum { |
|
238 |
HAS_MII_XCVR = 0x010000, |
|
239 |
HAS_CHIP_XCVR = 0x020000, |
|
240 |
HAS_LNK_CHNG = 0x040000, |
|
241 |
}; |
|
242 |
||
243 |
#define RTL_NUM_STATS 4 /* number of ETHTOOL_GSTATS u64's */ |
|
244 |
#define RTL_REGS_VER 1 /* version of reg. data in ETHTOOL_GREGS */ |
|
245 |
#define RTL_MIN_IO_SIZE 0x80 |
|
246 |
#define RTL8139B_IO_SIZE 256 |
|
247 |
||
248 |
#define RTL8129_CAPS HAS_MII_XCVR |
|
249 |
#define RTL8139_CAPS HAS_CHIP_XCVR|HAS_LNK_CHNG |
|
250 |
||
251 |
typedef enum { |
|
252 |
RTL8139 = 0, |
|
253 |
RTL8139_CB, |
|
254 |
SMC1211TX, |
|
255 |
/*MPX5030,*/ |
|
256 |
DELTA8139, |
|
257 |
ADDTRON8139, |
|
258 |
DFE538TX, |
|
259 |
DFE690TXD, |
|
260 |
FE2000VX, |
|
261 |
ALLIED8139, |
|
262 |
RTL8129, |
|
263 |
FNW3603TX, |
|
264 |
FNW3800TX, |
|
265 |
} board_t; |
|
266 |
||
267 |
||
268 |
/* indexed by board_t, above */ |
|
269 |
static struct { |
|
270 |
const char *name; |
|
271 |
u32 hw_flags; |
|
272 |
} board_info[] __devinitdata = { |
|
273 |
{ "RealTek RTL8139 Fast Ethernet", RTL8139_CAPS }, |
|
274 |
{ "RealTek RTL8139B PCI/CardBus", RTL8139_CAPS }, |
|
275 |
{ "SMC1211TX EZCard 10/100 (RealTek RTL8139)", RTL8139_CAPS }, |
|
276 |
/* { MPX5030, "Accton MPX5030 (RealTek RTL8139)", RTL8139_CAPS },*/ |
|
277 |
{ "Delta Electronics 8139 10/100BaseTX", RTL8139_CAPS }, |
|
278 |
{ "Addtron Technolgy 8139 10/100BaseTX", RTL8139_CAPS }, |
|
279 |
{ "D-Link DFE-538TX (RealTek RTL8139)", RTL8139_CAPS }, |
|
280 |
{ "D-Link DFE-690TXD (RealTek RTL8139)", RTL8139_CAPS }, |
|
281 |
{ "AboCom FE2000VX (RealTek RTL8139)", RTL8139_CAPS }, |
|
282 |
{ "Allied Telesyn 8139 CardBus", RTL8139_CAPS }, |
|
283 |
{ "RealTek RTL8129", RTL8129_CAPS }, |
|
284 |
{ "Planex FNW-3603-TX 10/100 CardBus", RTL8139_CAPS }, |
|
285 |
{ "Planex FNW-3800-TX 10/100 CardBus", RTL8139_CAPS }, |
|
286 |
}; |
|
287 |
||
288 |
||
289 |
static struct pci_device_id rtl8139_pci_tbl[] __devinitdata = { |
|
290 |
{0x10ec, 0x8139, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139 }, |
|
291 |
{0x10ec, 0x8138, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8139_CB }, |
|
292 |
{0x1113, 0x1211, PCI_ANY_ID, PCI_ANY_ID, 0, 0, SMC1211TX }, |
|
293 |
/* {0x1113, 0x1211, PCI_ANY_ID, PCI_ANY_ID, 0, 0, MPX5030 },*/ |
|
294 |
{0x1500, 0x1360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DELTA8139 }, |
|
295 |
{0x4033, 0x1360, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ADDTRON8139 }, |
|
296 |
{0x1186, 0x1300, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DFE538TX }, |
|
297 |
{0x1186, 0x1340, PCI_ANY_ID, PCI_ANY_ID, 0, 0, DFE690TXD }, |
|
298 |
{0x13d1, 0xab06, PCI_ANY_ID, PCI_ANY_ID, 0, 0, FE2000VX }, |
|
299 |
{0x1259, 0xa117, PCI_ANY_ID, PCI_ANY_ID, 0, 0, ALLIED8139 }, |
|
300 |
{0x14ea, 0xab06, PCI_ANY_ID, PCI_ANY_ID, 0, 0, FNW3603TX }, |
|
301 |
{0x14ea, 0xab07, PCI_ANY_ID, PCI_ANY_ID, 0, 0, FNW3800TX }, |
|
302 |
||
303 |
#ifdef CONFIG_8139TOO_8129 |
|
304 |
{0x10ec, 0x8129, PCI_ANY_ID, PCI_ANY_ID, 0, 0, RTL8129 }, |
|
305 |
#endif |
|
306 |
||
307 |
/* some crazy cards report invalid vendor ids like |
|
308 |
* 0x0001 here. The other ids are valid and constant, |
|
309 |
* so we simply don't match on the main vendor id. |
|
310 |
*/ |
|
311 |
{PCI_ANY_ID, 0x8139, 0x10ec, 0x8139, 0, 0, RTL8139 }, |
|
312 |
{PCI_ANY_ID, 0x8139, 0x1186, 0x1300, 0, 0, DFE538TX }, |
|
313 |
{PCI_ANY_ID, 0x8139, 0x13d1, 0xab06, 0, 0, FE2000VX }, |
|
314 |
||
315 |
{0,} |
|
316 |
}; |
|
317 |
MODULE_DEVICE_TABLE (pci, rtl8139_pci_tbl); |
|
318 |
||
319 |
static struct { |
|
320 |
const char str[ETH_GSTRING_LEN]; |
|
321 |
} ethtool_stats_keys[] = { |
|
322 |
{ "early_rx" }, |
|
323 |
{ "tx_buf_mapped" }, |
|
324 |
{ "tx_timeouts" }, |
|
325 |
{ "rx_lost_in_ring" }, |
|
326 |
}; |
|
327 |
||
328 |
/* The rest of these values should never change. */ |
|
329 |
||
330 |
/* Symbolic offsets to registers. */ |
|
331 |
enum RTL8139_registers { |
|
332 |
MAC0 = 0, /* Ethernet hardware address. */ |
|
333 |
MAR0 = 8, /* Multicast filter. */ |
|
334 |
TxStatus0 = 0x10, /* Transmit status (Four 32bit registers). */ |
|
335 |
TxAddr0 = 0x20, /* Tx descriptors (also four 32bit). */ |
|
336 |
RxBuf = 0x30, |
|
337 |
ChipCmd = 0x37, |
|
338 |
RxBufPtr = 0x38, |
|
339 |
RxBufAddr = 0x3A, |
|
340 |
IntrMask = 0x3C, |
|
341 |
IntrStatus = 0x3E, |
|
342 |
TxConfig = 0x40, |
|
343 |
ChipVersion = 0x43, |
|
344 |
RxConfig = 0x44, |
|
345 |
Timer = 0x48, /* A general-purpose counter. */ |
|
346 |
RxMissed = 0x4C, /* 24 bits valid, write clears. */ |
|
347 |
Cfg9346 = 0x50, |
|
348 |
Config0 = 0x51, |
|
349 |
Config1 = 0x52, |
|
350 |
FlashReg = 0x54, |
|
351 |
MediaStatus = 0x58, |
|
352 |
Config3 = 0x59, |
|
353 |
Config4 = 0x5A, /* absent on RTL-8139A */ |
|
354 |
HltClk = 0x5B, |
|
355 |
MultiIntr = 0x5C, |
|
356 |
TxSummary = 0x60, |
|
357 |
BasicModeCtrl = 0x62, |
|
358 |
BasicModeStatus = 0x64, |
|
359 |
NWayAdvert = 0x66, |
|
360 |
NWayLPAR = 0x68, |
|
361 |
NWayExpansion = 0x6A, |
|
362 |
/* Undocumented registers, but required for proper operation. */ |
|
363 |
FIFOTMS = 0x70, /* FIFO Control and test. */ |
|
364 |
CSCR = 0x74, /* Chip Status and Configuration Register. */ |
|
365 |
PARA78 = 0x78, |
|
366 |
PARA7c = 0x7c, /* Magic transceiver parameter register. */ |
|
367 |
Config5 = 0xD8, /* absent on RTL-8139A */ |
|
368 |
}; |
|
369 |
||
370 |
enum ClearBitMasks { |
|
371 |
MultiIntrClear = 0xF000, |
|
372 |
ChipCmdClear = 0xE2, |
|
373 |
Config1Clear = (1<<7)|(1<<6)|(1<<3)|(1<<2)|(1<<1), |
|
374 |
}; |
|
375 |
||
376 |
enum ChipCmdBits { |
|
377 |
CmdReset = 0x10, |
|
378 |
CmdRxEnb = 0x08, |
|
379 |
CmdTxEnb = 0x04, |
|
380 |
RxBufEmpty = 0x01, |
|
381 |
}; |
|
382 |
||
383 |
/* Interrupt register bits, using my own meaningful names. */ |
|
384 |
enum IntrStatusBits { |
|
385 |
PCIErr = 0x8000, |
|
386 |
PCSTimeout = 0x4000, |
|
387 |
RxFIFOOver = 0x40, |
|
388 |
RxUnderrun = 0x20, |
|
389 |
RxOverflow = 0x10, |
|
390 |
TxErr = 0x08, |
|
391 |
TxOK = 0x04, |
|
392 |
RxErr = 0x02, |
|
393 |
RxOK = 0x01, |
|
394 |
||
395 |
RxAckBits = RxFIFOOver | RxOverflow | RxOK, |
|
396 |
}; |
|
397 |
||
398 |
enum TxStatusBits { |
|
399 |
TxHostOwns = 0x2000, |
|
400 |
TxUnderrun = 0x4000, |
|
401 |
TxStatOK = 0x8000, |
|
402 |
TxOutOfWindow = 0x20000000, |
|
403 |
TxAborted = 0x40000000, |
|
404 |
TxCarrierLost = 0x80000000, |
|
405 |
}; |
|
406 |
enum RxStatusBits { |
|
407 |
RxMulticast = 0x8000, |
|
408 |
RxPhysical = 0x4000, |
|
409 |
RxBroadcast = 0x2000, |
|
410 |
RxBadSymbol = 0x0020, |
|
411 |
RxRunt = 0x0010, |
|
412 |
RxTooLong = 0x0008, |
|
413 |
RxCRCErr = 0x0004, |
|
414 |
RxBadAlign = 0x0002, |
|
415 |
RxStatusOK = 0x0001, |
|
416 |
}; |
|
417 |
||
418 |
/* Bits in RxConfig. */ |
|
419 |
enum rx_mode_bits { |
|
420 |
AcceptErr = 0x20, |
|
421 |
AcceptRunt = 0x10, |
|
422 |
AcceptBroadcast = 0x08, |
|
423 |
AcceptMulticast = 0x04, |
|
424 |
AcceptMyPhys = 0x02, |
|
425 |
AcceptAllPhys = 0x01, |
|
426 |
}; |
|
427 |
||
428 |
/* Bits in TxConfig. */ |
|
429 |
enum tx_config_bits { |
|
430 |
TxIFG1 = (1 << 25), /* Interframe Gap Time */ |
|
431 |
TxIFG0 = (1 << 24), /* Enabling these bits violates IEEE 802.3 */ |
|
432 |
TxLoopBack = (1 << 18) | (1 << 17), /* enable loopback test mode */ |
|
433 |
TxCRC = (1 << 16), /* DISABLE appending CRC to end of Tx packets */ |
|
434 |
TxClearAbt = (1 << 0), /* Clear abort (WO) */ |
|
435 |
TxDMAShift = 8, /* DMA burst value (0-7) is shifted this many bits */ |
|
436 |
TxRetryShift = 4, /* TXRR value (0-15) is shifted this many bits */ |
|
437 |
||
438 |
TxVersionMask = 0x7C800000, /* mask out version bits 30-26, 23 */ |
|
439 |
}; |
|
440 |
||
441 |
/* Bits in Config1 */ |
|
442 |
enum Config1Bits { |
|
443 |
Cfg1_PM_Enable = 0x01, |
|
444 |
Cfg1_VPD_Enable = 0x02, |
|
445 |
Cfg1_PIO = 0x04, |
|
446 |
Cfg1_MMIO = 0x08, |
|
447 |
LWAKE = 0x10, /* not on 8139, 8139A */ |
|
448 |
Cfg1_Driver_Load = 0x20, |
|
449 |
Cfg1_LED0 = 0x40, |
|
450 |
Cfg1_LED1 = 0x80, |
|
451 |
SLEEP = (1 << 1), /* only on 8139, 8139A */ |
|
452 |
PWRDN = (1 << 0), /* only on 8139, 8139A */ |
|
453 |
}; |
|
454 |
||
455 |
/* Bits in Config3 */ |
|
456 |
enum Config3Bits { |
|
457 |
Cfg3_FBtBEn = (1 << 0), /* 1 = Fast Back to Back */ |
|
458 |
Cfg3_FuncRegEn = (1 << 1), /* 1 = enable CardBus Function registers */ |
|
459 |
Cfg3_CLKRUN_En = (1 << 2), /* 1 = enable CLKRUN */ |
|
460 |
Cfg3_CardB_En = (1 << 3), /* 1 = enable CardBus registers */ |
|
461 |
Cfg3_LinkUp = (1 << 4), /* 1 = wake up on link up */ |
|
462 |
Cfg3_Magic = (1 << 5), /* 1 = wake up on Magic Packet (tm) */ |
|
463 |
Cfg3_PARM_En = (1 << 6), /* 0 = software can set twister parameters */ |
|
464 |
Cfg3_GNTSel = (1 << 7), /* 1 = delay 1 clock from PCI GNT signal */ |
|
465 |
}; |
|
466 |
||
467 |
/* Bits in Config4 */ |
|
468 |
enum Config4Bits { |
|
469 |
LWPTN = (1 << 2), /* not on 8139, 8139A */ |
|
470 |
}; |
|
471 |
||
472 |
/* Bits in Config5 */ |
|
473 |
enum Config5Bits { |
|
474 |
Cfg5_PME_STS = (1 << 0), /* 1 = PCI reset resets PME_Status */ |
|
475 |
Cfg5_LANWake = (1 << 1), /* 1 = enable LANWake signal */ |
|
476 |
Cfg5_LDPS = (1 << 2), /* 0 = save power when link is down */ |
|
477 |
Cfg5_FIFOAddrPtr = (1 << 3), /* Realtek internal SRAM testing */ |
|
478 |
Cfg5_UWF = (1 << 4), /* 1 = accept unicast wakeup frame */ |
|
479 |
Cfg5_MWF = (1 << 5), /* 1 = accept multicast wakeup frame */ |
|
480 |
Cfg5_BWF = (1 << 6), /* 1 = accept broadcast wakeup frame */ |
|
481 |
}; |
|
482 |
||
483 |
enum RxConfigBits { |
|
484 |
/* rx fifo threshold */ |
|
485 |
RxCfgFIFOShift = 13, |
|
486 |
RxCfgFIFONone = (7 << RxCfgFIFOShift), |
|
487 |
||
488 |
/* Max DMA burst */ |
|
489 |
RxCfgDMAShift = 8, |
|
490 |
RxCfgDMAUnlimited = (7 << RxCfgDMAShift), |
|
491 |
||
492 |
/* rx ring buffer length */ |
|
493 |
RxCfgRcv8K = 0, |
|
494 |
RxCfgRcv16K = (1 << 11), |
|
495 |
RxCfgRcv32K = (1 << 12), |
|
496 |
RxCfgRcv64K = (1 << 11) | (1 << 12), |
|
497 |
||
498 |
/* Disable packet wrap at end of Rx buffer */ |
|
499 |
RxNoWrap = (1 << 7), |
|
500 |
}; |
|
501 |
||
502 |
||
503 |
/* Twister tuning parameters from RealTek. |
|
504 |
Completely undocumented, but required to tune bad links on some boards. */ |
|
505 |
enum CSCRBits { |
|
506 |
CSCR_LinkOKBit = 0x0400, |
|
507 |
CSCR_LinkChangeBit = 0x0800, |
|
508 |
CSCR_LinkStatusBits = 0x0f000, |
|
509 |
CSCR_LinkDownOffCmd = 0x003c0, |
|
510 |
CSCR_LinkDownCmd = 0x0f3c0, |
|
511 |
}; |
|
512 |
||
513 |
||
514 |
enum Cfg9346Bits { |
|
515 |
Cfg9346_Lock = 0x00, |
|
516 |
Cfg9346_Unlock = 0xC0, |
|
517 |
}; |
|
518 |
||
519 |
#ifdef CONFIG_8139TOO_TUNE_TWISTER |
|
520 |
||
521 |
enum TwisterParamVals { |
|
522 |
PARA78_default = 0x78fa8388, |
|
523 |
PARA7c_default = 0xcb38de43, /* param[0][3] */ |
|
524 |
PARA7c_xxx = 0xcb38de43, |
|
525 |
}; |
|
526 |
||
527 |
static const unsigned long param[4][4] = { |
|
528 |
{0xcb39de43, 0xcb39ce43, 0xfb38de03, 0xcb38de43}, |
|
529 |
{0xcb39de43, 0xcb39ce43, 0xcb39ce83, 0xcb39ce83}, |
|
530 |
{0xcb39de43, 0xcb39ce43, 0xcb39ce83, 0xcb39ce83}, |
|
531 |
{0xbb39de43, 0xbb39ce43, 0xbb39ce83, 0xbb39ce83} |
|
532 |
}; |
|
533 |
||
534 |
#endif /* CONFIG_8139TOO_TUNE_TWISTER */ |
|
535 |
||
536 |
typedef enum { |
|
537 |
CH_8139 = 0, |
|
538 |
CH_8139_K, |
|
539 |
CH_8139A, |
|
540 |
CH_8139B, |
|
541 |
CH_8130, |
|
542 |
CH_8139C, |
|
543 |
} chip_t; |
|
544 |
||
545 |
enum chip_flags { |
|
546 |
HasHltClk = (1 << 0), |
|
547 |
HasLWake = (1 << 1), |
|
548 |
}; |
|
549 |
||
550 |
||
551 |
/* directly indexed by chip_t, above */ |
|
552 |
const static struct { |
|
553 |
const char *name; |
|
554 |
u8 version; /* from RTL8139C docs */ |
|
555 |
u32 RxConfigMask; /* should clear the bits supported by this chip */ |
|
556 |
u32 flags; |
|
557 |
} rtl_chip_info[] = { |
|
558 |
{ "RTL-8139", |
|
559 |
0x40, |
|
560 |
0xf0fe0040, /* XXX copied from RTL8139A, verify */ |
|
561 |
HasHltClk, |
|
562 |
}, |
|
563 |
||
564 |
{ "RTL-8139 rev K", |
|
565 |
0x60, |
|
566 |
0xf0fe0040, |
|
567 |
HasHltClk, |
|
568 |
}, |
|
569 |
||
570 |
{ "RTL-8139A", |
|
571 |
0x70, |
|
572 |
0xf0fe0040, |
|
573 |
HasHltClk, /* XXX undocumented? */ |
|
574 |
}, |
|
575 |
||
576 |
{ "RTL-8139B", |
|
577 |
0x78, |
|
578 |
0xf0fc0040, |
|
579 |
HasLWake, |
|
580 |
}, |
|
581 |
||
582 |
{ "RTL-8130", |
|
583 |
0x7C, |
|
584 |
0xf0fe0040, /* XXX copied from RTL8139A, verify */ |
|
585 |
HasLWake, |
|
586 |
}, |
|
587 |
||
588 |
{ "RTL-8139C", |
|
589 |
0x74, |
|
590 |
0xf0fc0040, /* XXX copied from RTL8139B, verify */ |
|
591 |
HasLWake, |
|
592 |
}, |
|
593 |
||
594 |
}; |
|
595 |
||
596 |
struct rtl_extra_stats { |
|
597 |
unsigned long early_rx; |
|
598 |
unsigned long tx_buf_mapped; |
|
599 |
unsigned long tx_timeouts; |
|
600 |
unsigned long rx_lost_in_ring; |
|
601 |
}; |
|
602 |
||
603 |
struct rtl8139_private { |
|
604 |
void *mmio_addr; |
|
605 |
int drv_flags; |
|
606 |
struct pci_dev *pci_dev; |
|
607 |
struct net_device_stats stats; |
|
608 |
unsigned char *rx_ring; |
|
609 |
unsigned int cur_rx; /* Index into the Rx buffer of next Rx pkt. */ |
|
610 |
unsigned int tx_flag; |
|
611 |
unsigned long cur_tx; |
|
612 |
unsigned long dirty_tx; |
|
613 |
unsigned char *tx_buf[NUM_TX_DESC]; /* Tx bounce buffers */ |
|
614 |
unsigned char *tx_bufs; /* Tx bounce buffer region. */ |
|
615 |
dma_addr_t rx_ring_dma; |
|
616 |
dma_addr_t tx_bufs_dma; |
|
617 |
signed char phys[4]; /* MII device addresses. */ |
|
618 |
char twistie, twist_row, twist_col; /* Twister tune state. */ |
|
619 |
unsigned int default_port:4; /* Last dev->if_port value. */ |
|
620 |
spinlock_t lock; |
|
621 |
chip_t chipset; |
|
622 |
pid_t thr_pid; |
|
623 |
wait_queue_head_t thr_wait; |
|
624 |
struct completion thr_exited; |
|
625 |
u32 rx_config; |
|
626 |
struct rtl_extra_stats xstats; |
|
627 |
int time_to_die; |
|
628 |
struct mii_if_info mii; |
|
629 |
unsigned int regs_len; |
|
630 |
}; |
|
631 |
||
632 |
MODULE_AUTHOR ("Jeff Garzik <jgarzik@mandrakesoft.com>"); |
|
633 |
MODULE_DESCRIPTION ("RealTek RTL-8139 Fast Ethernet driver"); |
|
634 |
MODULE_LICENSE("GPL"); |
|
635 |
||
636 |
MODULE_PARM (multicast_filter_limit, "i"); |
|
637 |
MODULE_PARM (max_interrupt_work, "i"); |
|
638 |
MODULE_PARM (media, "1-" __MODULE_STRING(MAX_UNITS) "i"); |
|
639 |
MODULE_PARM (full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i"); |
|
640 |
MODULE_PARM (debug, "i"); |
|
641 |
MODULE_PARM_DESC (debug, "8139too bitmapped message enable number"); |
|
642 |
MODULE_PARM_DESC (multicast_filter_limit, "8139too maximum number of filtered multicast addresses"); |
|
643 |
MODULE_PARM_DESC (max_interrupt_work, "8139too maximum events handled per interrupt"); |
|
644 |
MODULE_PARM_DESC (media, "8139too: Bits 4+9: force full duplex, bit 5: 100Mbps"); |
|
645 |
MODULE_PARM_DESC (full_duplex, "8139too: Force full duplex for board(s) (1)"); |
|
646 |
||
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
647 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
648 |
|
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
649 |
MODULE_PARM(ec_device_index, "i"); |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
650 |
MODULE_PARM_DESC(ec_device_index, "Index of the device reserved for EtherCAT."); |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
651 |
|
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
652 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
653 |
|
0 | 654 |
static int read_eeprom (void *ioaddr, int location, int addr_len); |
655 |
static int rtl8139_open (struct net_device *dev); |
|
656 |
static int mdio_read (struct net_device *dev, int phy_id, int location); |
|
657 |
static void mdio_write (struct net_device *dev, int phy_id, int location, |
|
658 |
int val); |
|
659 |
static int rtl8139_thread (void *data); |
|
660 |
static void rtl8139_tx_timeout (struct net_device *dev); |
|
661 |
static void rtl8139_init_ring (struct net_device *dev); |
|
662 |
static int rtl8139_start_xmit (struct sk_buff *skb, |
|
663 |
struct net_device *dev); |
|
664 |
static void rtl8139_interrupt (int irq, void *dev_instance, |
|
665 |
struct pt_regs *regs); |
|
666 |
static int rtl8139_close (struct net_device *dev); |
|
667 |
static int netdev_ioctl (struct net_device *dev, struct ifreq *rq, int cmd); |
|
668 |
static struct net_device_stats *rtl8139_get_stats (struct net_device *dev); |
|
669 |
static void rtl8139_set_rx_mode (struct net_device *dev); |
|
670 |
static void __set_rx_mode (struct net_device *dev); |
|
671 |
static void rtl8139_hw_start (struct net_device *dev); |
|
672 |
||
673 |
#ifdef USE_IO_OPS |
|
674 |
||
675 |
#define RTL_R8(reg) inb (((unsigned long)ioaddr) + (reg)) |
|
676 |
#define RTL_R16(reg) inw (((unsigned long)ioaddr) + (reg)) |
|
677 |
#define RTL_R32(reg) ((unsigned long) inl (((unsigned long)ioaddr) + (reg))) |
|
678 |
#define RTL_W8(reg, val8) outb ((val8), ((unsigned long)ioaddr) + (reg)) |
|
679 |
#define RTL_W16(reg, val16) outw ((val16), ((unsigned long)ioaddr) + (reg)) |
|
680 |
#define RTL_W32(reg, val32) outl ((val32), ((unsigned long)ioaddr) + (reg)) |
|
681 |
#define RTL_W8_F RTL_W8 |
|
682 |
#define RTL_W16_F RTL_W16 |
|
683 |
#define RTL_W32_F RTL_W32 |
|
684 |
#undef readb |
|
685 |
#undef readw |
|
686 |
#undef readl |
|
687 |
#undef writeb |
|
688 |
#undef writew |
|
689 |
#undef writel |
|
690 |
#define readb(addr) inb((unsigned long)(addr)) |
|
691 |
#define readw(addr) inw((unsigned long)(addr)) |
|
692 |
#define readl(addr) inl((unsigned long)(addr)) |
|
693 |
#define writeb(val,addr) outb((val),(unsigned long)(addr)) |
|
694 |
#define writew(val,addr) outw((val),(unsigned long)(addr)) |
|
695 |
#define writel(val,addr) outl((val),(unsigned long)(addr)) |
|
696 |
||
697 |
#else |
|
698 |
||
699 |
/* write MMIO register, with flush */ |
|
700 |
/* Flush avoids rtl8139 bug w/ posted MMIO writes */ |
|
701 |
#define RTL_W8_F(reg, val8) do { writeb ((val8), ioaddr + (reg)); readb (ioaddr + (reg)); } while (0) |
|
702 |
#define RTL_W16_F(reg, val16) do { writew ((val16), ioaddr + (reg)); readw (ioaddr + (reg)); } while (0) |
|
703 |
#define RTL_W32_F(reg, val32) do { writel ((val32), ioaddr + (reg)); readl (ioaddr + (reg)); } while (0) |
|
704 |
||
705 |
||
706 |
#define MMIO_FLUSH_AUDIT_COMPLETE 1 |
|
707 |
#if MMIO_FLUSH_AUDIT_COMPLETE |
|
708 |
||
709 |
/* write MMIO register */ |
|
710 |
#define RTL_W8(reg, val8) writeb ((val8), ioaddr + (reg)) |
|
711 |
#define RTL_W16(reg, val16) writew ((val16), ioaddr + (reg)) |
|
712 |
#define RTL_W32(reg, val32) writel ((val32), ioaddr + (reg)) |
|
713 |
||
714 |
#else |
|
715 |
||
716 |
/* write MMIO register, then flush */ |
|
717 |
#define RTL_W8 RTL_W8_F |
|
718 |
#define RTL_W16 RTL_W16_F |
|
719 |
#define RTL_W32 RTL_W32_F |
|
720 |
||
721 |
#endif /* MMIO_FLUSH_AUDIT_COMPLETE */ |
|
722 |
||
723 |
/* read MMIO register */ |
|
724 |
#define RTL_R8(reg) readb (ioaddr + (reg)) |
|
725 |
#define RTL_R16(reg) readw (ioaddr + (reg)) |
|
726 |
#define RTL_R32(reg) ((unsigned long) readl (ioaddr + (reg))) |
|
727 |
||
728 |
#endif /* USE_IO_OPS */ |
|
729 |
||
730 |
static const u16 rtl8139_intr_mask = |
|
731 |
PCIErr | PCSTimeout | RxUnderrun | RxOverflow | RxFIFOOver | |
|
732 |
TxErr | TxOK | RxErr | RxOK; |
|
733 |
||
734 |
static const unsigned int rtl8139_rx_config = |
|
735 |
RxCfgRcv32K | RxNoWrap | |
|
736 |
(RX_FIFO_THRESH << RxCfgFIFOShift) | |
|
737 |
(RX_DMA_BURST << RxCfgDMAShift); |
|
738 |
||
739 |
static const unsigned int rtl8139_tx_config = |
|
740 |
(TX_DMA_BURST << TxDMAShift) | (TX_RETRY << TxRetryShift); |
|
741 |
||
742 |
static void __rtl8139_cleanup_dev (struct net_device *dev) |
|
743 |
{ |
|
744 |
struct rtl8139_private *tp; |
|
745 |
struct pci_dev *pdev; |
|
746 |
||
747 |
assert (dev != NULL); |
|
748 |
assert (dev->priv != NULL); |
|
749 |
||
750 |
tp = dev->priv; |
|
751 |
assert (tp->pci_dev != NULL); |
|
752 |
pdev = tp->pci_dev; |
|
753 |
||
754 |
#ifndef USE_IO_OPS |
|
755 |
if (tp->mmio_addr) |
|
756 |
iounmap (tp->mmio_addr); |
|
757 |
#endif /* !USE_IO_OPS */ |
|
758 |
||
759 |
/* it's ok to call this even if we have no regions to free */ |
|
760 |
pci_release_regions (pdev); |
|
761 |
||
762 |
#ifndef RTL8139_NDEBUG |
|
763 |
/* poison memory before freeing */ |
|
764 |
memset (dev, 0xBC, |
|
765 |
sizeof (struct net_device) + |
|
766 |
sizeof (struct rtl8139_private)); |
|
767 |
#endif /* RTL8139_NDEBUG */ |
|
768 |
||
769 |
kfree (dev); |
|
770 |
||
771 |
pci_set_drvdata (pdev, NULL); |
|
772 |
} |
|
773 |
||
774 |
||
775 |
static void rtl8139_chip_reset (void *ioaddr) |
|
776 |
{ |
|
777 |
int i; |
|
778 |
int succ = 0 ; |
|
779 |
/* Soft reset the chip. */ |
|
780 |
RTL_W8 (ChipCmd, CmdReset); |
|
781 |
||
782 |
/* Check that the chip has finished the reset. */ |
|
783 |
for (i = 1000; i > 0; i--) { |
|
784 |
barrier(); |
|
785 |
if ((RTL_R8 (ChipCmd) & CmdReset) == 0) { |
|
786 |
succ = 1; |
|
787 |
break; |
|
788 |
} |
|
789 |
udelay (10); |
|
790 |
} |
|
791 |
EC_DBG("rtl8139 chipreset"); |
|
792 |
if(succ == 0) |
|
793 |
EC_DBG("failed"); |
|
794 |
else |
|
795 |
EC_DBG("success at count %d",i); |
|
796 |
||
797 |
} |
|
798 |
||
799 |
||
800 |
static int __devinit rtl8139_init_board (struct pci_dev *pdev, |
|
801 |
struct net_device **dev_out) |
|
802 |
{ |
|
803 |
void *ioaddr; |
|
804 |
struct net_device *dev; |
|
805 |
struct rtl8139_private *tp; |
|
806 |
u8 tmp8; |
|
807 |
int rc; |
|
808 |
unsigned int i; |
|
809 |
u32 pio_start, pio_end, pio_flags, pio_len; |
|
810 |
unsigned long mmio_start, mmio_end, mmio_flags, mmio_len; |
|
811 |
u32 tmp; |
|
812 |
||
813 |
assert (pdev != NULL); |
|
814 |
||
815 |
*dev_out = NULL; |
|
816 |
||
817 |
/* dev and dev->priv zeroed in alloc_etherdev */ |
|
818 |
dev = alloc_etherdev (sizeof (*tp)); |
|
819 |
if (dev == NULL) { |
|
820 |
EC_DBG (KERN_ERR PFX "%s: Unable to alloc new net device\n", pdev->slot_name); |
|
821 |
return -ENOMEM; |
|
822 |
} |
|
823 |
SET_MODULE_OWNER(dev); |
|
824 |
tp = dev->priv; |
|
825 |
tp->pci_dev = pdev; |
|
826 |
||
827 |
/* enable device (incl. PCI PM wakeup and hotplug setup) */ |
|
828 |
rc = pci_enable_device (pdev); |
|
829 |
if (rc) |
|
830 |
goto err_out; |
|
831 |
||
832 |
pio_start = pci_resource_start (pdev, 0); |
|
833 |
pio_end = pci_resource_end (pdev, 0); |
|
834 |
pio_flags = pci_resource_flags (pdev, 0); |
|
835 |
pio_len = pci_resource_len (pdev, 0); |
|
836 |
||
837 |
mmio_start = pci_resource_start (pdev, 1); |
|
838 |
mmio_end = pci_resource_end (pdev, 1); |
|
839 |
mmio_flags = pci_resource_flags (pdev, 1); |
|
840 |
mmio_len = pci_resource_len (pdev, 1); |
|
841 |
||
842 |
/* set this immediately, we need to know before |
|
843 |
* we talk to the chip directly */ |
|
844 |
DPRINTK("PIO region size == 0x%02X\n", pio_len); |
|
845 |
DPRINTK("MMIO region size == 0x%02lX\n", mmio_len); |
|
846 |
||
847 |
#ifdef USE_IO_OPS |
|
848 |
/* make sure PCI base addr 0 is PIO */ |
|
849 |
if (!(pio_flags & IORESOURCE_IO)) { |
|
850 |
EC_DBG (KERN_ERR PFX "%s: region #0 not a PIO resource, aborting\n", pdev->slot_name); |
|
851 |
rc = -ENODEV; |
|
852 |
goto err_out; |
|
853 |
} |
|
854 |
/* check for weird/broken PCI region reporting */ |
|
855 |
if (pio_len < RTL_MIN_IO_SIZE) { |
|
856 |
EC_DBG (KERN_ERR PFX "%s: Invalid PCI I/O region size(s), aborting\n", pdev->slot_name); |
|
857 |
rc = -ENODEV; |
|
858 |
goto err_out; |
|
859 |
} |
|
860 |
#else |
|
861 |
/* make sure PCI base addr 1 is MMIO */ |
|
862 |
if (!(mmio_flags & IORESOURCE_MEM)) { |
|
863 |
EC_DBG (KERN_ERR PFX "%s: region #1 not an MMIO resource, aborting\n", pdev->slot_name); |
|
864 |
rc = -ENODEV; |
|
865 |
goto err_out; |
|
866 |
} |
|
867 |
if (mmio_len < RTL_MIN_IO_SIZE) { |
|
868 |
EC_DBG (KERN_ERR PFX "%s: Invalid PCI mem region size(s), aborting\n", pdev->slot_name); |
|
869 |
rc = -ENODEV; |
|
870 |
goto err_out; |
|
871 |
} |
|
872 |
#endif |
|
873 |
||
874 |
rc = pci_request_regions (pdev, "8139too"); |
|
875 |
if (rc) |
|
876 |
goto err_out; |
|
877 |
||
878 |
/* enable PCI bus-mastering */ |
|
879 |
pci_set_master (pdev); |
|
880 |
||
881 |
#ifdef USE_IO_OPS |
|
882 |
ioaddr = (void *) pio_start; |
|
883 |
dev->base_addr = pio_start; |
|
884 |
tp->mmio_addr = ioaddr; |
|
885 |
tp->regs_len = pio_len; |
|
886 |
#else |
|
887 |
/* ioremap MMIO region */ |
|
888 |
ioaddr = ioremap (mmio_start, mmio_len); |
|
889 |
if (ioaddr == NULL) { |
|
890 |
EC_DBG (KERN_ERR PFX "%s: cannot remap MMIO, aborting\n", pdev->slot_name); |
|
891 |
rc = -EIO; |
|
892 |
goto err_out; |
|
893 |
} |
|
894 |
dev->base_addr = (long) ioaddr; |
|
895 |
tp->mmio_addr = ioaddr; |
|
896 |
tp->regs_len = mmio_len; |
|
897 |
#endif /* USE_IO_OPS */ |
|
898 |
||
899 |
/* Bring old chips out of low-power mode. */ |
|
900 |
RTL_W8 (HltClk, 'R'); |
|
901 |
||
902 |
/* check for missing/broken hardware */ |
|
903 |
if (RTL_R32 (TxConfig) == 0xFFFFFFFF) { |
|
904 |
EC_DBG (KERN_ERR PFX "%s: Chip not responding, ignoring board\n", |
|
905 |
pdev->slot_name); |
|
906 |
rc = -EIO; |
|
907 |
goto err_out; |
|
908 |
} |
|
909 |
||
910 |
/* identify chip attached to board */ |
|
911 |
tmp = RTL_R8 (ChipVersion); |
|
912 |
for (i = 0; i < ARRAY_SIZE (rtl_chip_info); i++) |
|
913 |
if (tmp == rtl_chip_info[i].version) { |
|
914 |
tp->chipset = i; |
|
915 |
goto match; |
|
916 |
} |
|
917 |
||
918 |
/* if unknown chip, assume array element #0, original RTL-8139 in this case */ |
|
919 |
EC_DBG (KERN_DEBUG PFX "%s: unknown chip version, assuming RTL-8139\n", |
|
920 |
pdev->slot_name); |
|
921 |
EC_DBG (KERN_DEBUG PFX "%s: TxConfig = 0x%lx\n", pdev->slot_name, RTL_R32 (TxConfig)); |
|
922 |
tp->chipset = 0; |
|
923 |
||
924 |
match: |
|
925 |
DPRINTK ("chipset id (%d) == index %d, '%s'\n", |
|
926 |
tmp, |
|
927 |
tp->chipset, |
|
928 |
rtl_chip_info[tp->chipset].name); |
|
929 |
||
930 |
if (tp->chipset >= CH_8139B) { |
|
931 |
u8 new_tmp8 = tmp8 = RTL_R8 (Config1); |
|
932 |
DPRINTK("PCI PM wakeup\n"); |
|
933 |
if ((rtl_chip_info[tp->chipset].flags & HasLWake) && |
|
934 |
(tmp8 & LWAKE)) |
|
935 |
new_tmp8 &= ~LWAKE; |
|
936 |
new_tmp8 |= Cfg1_PM_Enable; |
|
937 |
if (new_tmp8 != tmp8) { |
|
938 |
RTL_W8 (Cfg9346, Cfg9346_Unlock); |
|
939 |
RTL_W8 (Config1, tmp8); |
|
940 |
RTL_W8 (Cfg9346, Cfg9346_Lock); |
|
941 |
} |
|
942 |
if (rtl_chip_info[tp->chipset].flags & HasLWake) { |
|
943 |
tmp8 = RTL_R8 (Config4); |
|
944 |
if (tmp8 & LWPTN) |
|
945 |
RTL_W8 (Config4, tmp8 & ~LWPTN); |
|
946 |
} |
|
947 |
} else { |
|
948 |
DPRINTK("Old chip wakeup\n"); |
|
949 |
tmp8 = RTL_R8 (Config1); |
|
950 |
tmp8 &= ~(SLEEP | PWRDN); |
|
951 |
RTL_W8 (Config1, tmp8); |
|
952 |
} |
|
953 |
||
954 |
rtl8139_chip_reset (ioaddr); |
|
955 |
||
956 |
*dev_out = dev; |
|
957 |
return 0; |
|
958 |
||
959 |
err_out: |
|
960 |
__rtl8139_cleanup_dev (dev); |
|
961 |
return rc; |
|
962 |
} |
|
963 |
||
964 |
||
965 |
static int __devinit rtl8139_init_one (struct pci_dev *pdev, |
|
966 |
const struct pci_device_id *ent) |
|
967 |
{ |
|
968 |
struct net_device *dev = NULL; |
|
969 |
struct rtl8139_private *tp; |
|
970 |
int i, addr_len, option; |
|
971 |
void *ioaddr; |
|
972 |
static int board_idx = -1; |
|
973 |
u8 pci_rev; |
|
974 |
||
975 |
assert (pdev != NULL); |
|
976 |
assert (ent != NULL); |
|
977 |
||
978 |
board_idx++; |
|
979 |
||
980 |
||
981 |
/* when we're built into the kernel, the driver version message |
|
982 |
* is only printed if at least one 8139 board has been found |
|
983 |
*/ |
|
984 |
#ifndef MODULE |
|
985 |
{ |
|
986 |
static int printed_version; |
|
987 |
if (!printed_version++) |
|
988 |
EC_DBG (KERN_INFO RTL8139_DRIVER_NAME "\n"); |
|
989 |
} |
|
990 |
#endif |
|
991 |
||
992 |
pci_read_config_byte(pdev, PCI_REVISION_ID, &pci_rev); |
|
993 |
||
994 |
if (pdev->vendor == PCI_VENDOR_ID_REALTEK && |
|
995 |
pdev->device == PCI_DEVICE_ID_REALTEK_8139 && pci_rev >= 0x20) { |
|
996 |
EC_DBG(KERN_INFO PFX "pci dev %s (id %04x:%04x rev %02x) is an enhanced 8139C+ chip\n", |
|
997 |
pdev->slot_name, pdev->vendor, pdev->device, pci_rev); |
|
998 |
EC_DBG(KERN_INFO PFX "Use the \"8139cp\" driver for improved performance and stability.\n"); |
|
999 |
} |
|
1000 |
||
1001 |
i = rtl8139_init_board (pdev, &dev); |
|
1002 |
if (i < 0) |
|
1003 |
return i; |
|
1004 |
||
1005 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1006 |
||
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1007 |
if (board_idx == ec_device_index) |
0 | 1008 |
{ |
1009 |
EC_DBG("EtherCAT registering board %d.\n", board_idx); |
|
1010 |
||
1011 |
if (EtherCAT_device_assign(&rtl_ecat_dev, dev) < 0) |
|
1012 |
goto err_out; |
|
1013 |
||
1014 |
strcpy(dev->name,"ECAT"); //device name überschreiben |
|
1015 |
} |
|
1016 |
||
1017 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1018 |
||
1019 |
tp = dev->priv; |
|
1020 |
ioaddr = tp->mmio_addr; |
|
1021 |
||
1022 |
assert (ioaddr != NULL); |
|
1023 |
assert (dev != NULL); |
|
1024 |
assert (tp != NULL); |
|
1025 |
||
1026 |
addr_len = read_eeprom (ioaddr, 0, 8) == 0x8129 ? 8 : 6; |
|
1027 |
for (i = 0; i < 3; i++) |
|
1028 |
((u16 *) (dev->dev_addr))[i] = |
|
1029 |
le16_to_cpu (read_eeprom (ioaddr, i + 7, addr_len)); |
|
1030 |
||
1031 |
/* The Rtl8139-specific entries in the device structure. */ |
|
1032 |
dev->open = rtl8139_open; |
|
1033 |
dev->hard_start_xmit = rtl8139_start_xmit; |
|
1034 |
dev->stop = rtl8139_close; |
|
1035 |
dev->get_stats = rtl8139_get_stats; |
|
1036 |
dev->set_multicast_list = rtl8139_set_rx_mode; |
|
1037 |
dev->do_ioctl = netdev_ioctl; |
|
1038 |
dev->tx_timeout = rtl8139_tx_timeout; |
|
1039 |
dev->watchdog_timeo = TX_TIMEOUT; |
|
1040 |
dev->features |= NETIF_F_SG|NETIF_F_HW_CSUM; |
|
1041 |
||
1042 |
dev->irq = pdev->irq; |
|
1043 |
||
1044 |
/* dev->priv/tp zeroed and aligned in init_etherdev */ |
|
1045 |
tp = dev->priv; |
|
1046 |
||
1047 |
/* note: tp->chipset set in rtl8139_init_board */ |
|
1048 |
tp->drv_flags = board_info[ent->driver_data].hw_flags; |
|
1049 |
tp->mmio_addr = ioaddr; |
|
1050 |
spin_lock_init (&tp->lock); |
|
1051 |
||
1052 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1053 |
||
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1054 |
if (board_idx == ec_device_index) |
0 | 1055 |
{ |
1056 |
rtl_ecat_dev.lock = &tp->lock; |
|
1057 |
} |
|
1058 |
||
1
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1059 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
0 | 1060 |
|
1061 |
init_waitqueue_head (&tp->thr_wait); |
|
1062 |
init_completion (&tp->thr_exited); |
|
1063 |
tp->mii.dev = dev; |
|
1064 |
tp->mii.mdio_read = mdio_read; |
|
1065 |
tp->mii.mdio_write = mdio_write; |
|
1066 |
tp->mii.phy_id_mask = 0x3f; |
|
1067 |
tp->mii.reg_num_mask = 0x1f; |
|
1068 |
||
1069 |
/* dev is fully set up and ready to use now */ |
|
1070 |
||
1071 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1072 |
||
1073 |
/* EtherCAT-Karten nicht beim Stack anmelden. */ |
|
1074 |
if (dev != rtl_ecat_dev.dev) |
|
1075 |
{ |
|
1076 |
DPRINTK("About to register device named %s (%p)...\n", dev->name, dev); |
|
1077 |
i = register_netdev (dev); |
|
1078 |
if (i) goto err_out; |
|
1079 |
} |
|
1080 |
||
1081 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1082 |
||
1083 |
pci_set_drvdata (pdev, dev); |
|
1084 |
||
1085 |
EC_DBG (KERN_INFO "%s: %s at 0x%lx, " |
|
1086 |
"%2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x, " |
|
1087 |
"IRQ %d\n", |
|
1088 |
dev->name, |
|
1089 |
board_info[ent->driver_data].name, |
|
1090 |
dev->base_addr, |
|
1091 |
dev->dev_addr[0], dev->dev_addr[1], |
|
1092 |
dev->dev_addr[2], dev->dev_addr[3], |
|
1093 |
dev->dev_addr[4], dev->dev_addr[5], |
|
1094 |
dev->irq); |
|
1095 |
||
1096 |
EC_DBG (KERN_DEBUG "%s: Identified 8139 chip type '%s'\n", |
|
1097 |
dev->name, rtl_chip_info[tp->chipset].name); |
|
1098 |
||
1099 |
/* Find the connected MII xcvrs. |
|
1100 |
Doing this in open() would allow detecting external xcvrs later, but |
|
1101 |
takes too much time. */ |
|
1102 |
#ifdef CONFIG_8139TOO_8129 |
|
1103 |
if (tp->drv_flags & HAS_MII_XCVR) { |
|
1104 |
int phy, phy_idx = 0; |
|
1105 |
for (phy = 0; phy < 32 && phy_idx < sizeof(tp->phys); phy++) { |
|
1106 |
int mii_status = mdio_read(dev, phy, 1); |
|
1107 |
if (mii_status != 0xffff && mii_status != 0x0000) { |
|
1108 |
u16 advertising = mdio_read(dev, phy, 4); |
|
1109 |
tp->phys[phy_idx++] = phy; |
|
1110 |
EC_DBG(KERN_INFO "%s: MII transceiver %d status 0x%4.4x " |
|
1111 |
"advertising %4.4x.\n", |
|
1112 |
dev->name, phy, mii_status, advertising); |
|
1113 |
} |
|
1114 |
} |
|
1115 |
if (phy_idx == 0) { |
|
1116 |
EC_DBG(KERN_INFO "%s: No MII transceivers found! Assuming SYM " |
|
1117 |
"transceiver.\n", |
|
1118 |
dev->name); |
|
1119 |
tp->phys[0] = 32; |
|
1120 |
} |
|
1121 |
} else |
|
1122 |
#endif |
|
1123 |
tp->phys[0] = 32; |
|
1124 |
tp->mii.phy_id = tp->phys[0]; |
|
1125 |
||
1126 |
/* The lower four bits are the media type. */ |
|
1127 |
option = (board_idx >= MAX_UNITS) ? 0 : media[board_idx]; |
|
1128 |
if (option > 0) { |
|
1129 |
tp->mii.full_duplex = (option & 0x210) ? 1 : 0; |
|
1130 |
tp->default_port = option & 0xFF; |
|
1131 |
if (tp->default_port) |
|
1132 |
tp->mii.force_media = 1; |
|
1133 |
} |
|
1134 |
if (board_idx < MAX_UNITS && full_duplex[board_idx] > 0) |
|
1135 |
tp->mii.full_duplex = full_duplex[board_idx]; |
|
1136 |
if (tp->mii.full_duplex) { |
|
1137 |
EC_DBG(KERN_INFO "%s: Media type forced to Full Duplex.\n", dev->name); |
|
1138 |
/* Changing the MII-advertised media because might prevent |
|
1139 |
re-connection. */ |
|
1140 |
tp->mii.force_media = 1; |
|
1141 |
} |
|
1142 |
if (tp->default_port) { |
|
1143 |
EC_DBG(KERN_INFO " Forcing %dMbps %s-duplex operation.\n", |
|
1144 |
(option & 0x20 ? 100 : 10), |
|
1145 |
(option & 0x10 ? "full" : "half")); |
|
1146 |
mdio_write(dev, tp->phys[0], 0, |
|
1147 |
((option & 0x20) ? 0x2000 : 0) | /* 100Mbps? */ |
|
1148 |
((option & 0x10) ? 0x0100 : 0)); /* Full duplex? */ |
|
1149 |
} |
|
1150 |
||
1151 |
/* Put the chip into low-power mode. */ |
|
1152 |
if (rtl_chip_info[tp->chipset].flags & HasHltClk) |
|
1153 |
RTL_W8 (HltClk, 'H'); /* 'R' would leave the clock running. */ |
|
1154 |
||
1155 |
return 0; |
|
1156 |
||
1157 |
err_out: |
|
1158 |
__rtl8139_cleanup_dev (dev); |
|
1159 |
return i; |
|
1160 |
} |
|
1161 |
||
1162 |
||
1163 |
static void __devexit rtl8139_remove_one (struct pci_dev *pdev) |
|
1164 |
{ |
|
1165 |
struct net_device *dev = pci_get_drvdata (pdev); |
|
1166 |
struct rtl8139_private *np; |
|
1167 |
||
1168 |
assert (dev != NULL); |
|
1169 |
np = dev->priv; |
|
1170 |
assert (np != NULL); |
|
1
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1171 |
|
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1172 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1173 |
|
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1174 |
if (dev != rtl_ecat_dev.dev) |
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1175 |
{ |
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1176 |
unregister_netdev (dev); |
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1177 |
} |
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1178 |
|
0 | 1179 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1180 |
||
1181 |
__rtl8139_cleanup_dev (dev); |
|
1182 |
} |
|
1183 |
||
1184 |
||
1185 |
/* Serial EEPROM section. */ |
|
1186 |
||
1187 |
/* EEPROM_Ctrl bits. */ |
|
1188 |
#define EE_SHIFT_CLK 0x04 /* EEPROM shift clock. */ |
|
1189 |
#define EE_CS 0x08 /* EEPROM chip select. */ |
|
1190 |
#define EE_DATA_WRITE 0x02 /* EEPROM chip data in. */ |
|
1191 |
#define EE_WRITE_0 0x00 |
|
1192 |
#define EE_WRITE_1 0x02 |
|
1193 |
#define EE_DATA_READ 0x01 /* EEPROM chip data out. */ |
|
1194 |
#define EE_ENB (0x80 | EE_CS) |
|
1195 |
||
1196 |
/* Delay between EEPROM clock transitions. |
|
1197 |
No extra delay is needed with 33Mhz PCI, but 66Mhz may change this. |
|
1198 |
*/ |
|
1199 |
||
1200 |
#define eeprom_delay() readl(ee_addr) |
|
1201 |
||
1202 |
/* The EEPROM commands include the alway-set leading bit. */ |
|
1203 |
#define EE_WRITE_CMD (5) |
|
1204 |
#define EE_READ_CMD (6) |
|
1205 |
#define EE_ERASE_CMD (7) |
|
1206 |
||
1207 |
static int __devinit read_eeprom (void *ioaddr, int location, int addr_len) |
|
1208 |
{ |
|
1209 |
int i; |
|
1210 |
unsigned retval = 0; |
|
1211 |
void *ee_addr = ioaddr + Cfg9346; |
|
1212 |
int read_cmd = location | (EE_READ_CMD << addr_len); |
|
1213 |
||
1214 |
writeb (EE_ENB & ~EE_CS, ee_addr); |
|
1215 |
writeb (EE_ENB, ee_addr); |
|
1216 |
eeprom_delay (); |
|
1217 |
||
1218 |
/* Shift the read command bits out. */ |
|
1219 |
for (i = 4 + addr_len; i >= 0; i--) { |
|
1220 |
int dataval = (read_cmd & (1 << i)) ? EE_DATA_WRITE : 0; |
|
1221 |
writeb (EE_ENB | dataval, ee_addr); |
|
1222 |
eeprom_delay (); |
|
1223 |
writeb (EE_ENB | dataval | EE_SHIFT_CLK, ee_addr); |
|
1224 |
eeprom_delay (); |
|
1225 |
} |
|
1226 |
writeb (EE_ENB, ee_addr); |
|
1227 |
eeprom_delay (); |
|
1228 |
||
1229 |
for (i = 16; i > 0; i--) { |
|
1230 |
writeb (EE_ENB | EE_SHIFT_CLK, ee_addr); |
|
1231 |
eeprom_delay (); |
|
1232 |
retval = |
|
1233 |
(retval << 1) | ((readb (ee_addr) & EE_DATA_READ) ? 1 : |
|
1234 |
0); |
|
1235 |
writeb (EE_ENB, ee_addr); |
|
1236 |
eeprom_delay (); |
|
1237 |
} |
|
1238 |
||
1239 |
/* Terminate the EEPROM access. */ |
|
1240 |
writeb (~EE_CS, ee_addr); |
|
1241 |
eeprom_delay (); |
|
1242 |
||
1243 |
return retval; |
|
1244 |
} |
|
1245 |
||
1246 |
/* MII serial management: mostly bogus for now. */ |
|
1247 |
/* Read and write the MII management registers using software-generated |
|
1248 |
serial MDIO protocol. |
|
1249 |
The maximum data clock rate is 2.5 Mhz. The minimum timing is usually |
|
1250 |
met by back-to-back PCI I/O cycles, but we insert a delay to avoid |
|
1251 |
"overclocking" issues. */ |
|
1252 |
#define MDIO_DIR 0x80 |
|
1253 |
#define MDIO_DATA_OUT 0x04 |
|
1254 |
#define MDIO_DATA_IN 0x02 |
|
1255 |
#define MDIO_CLK 0x01 |
|
1256 |
#define MDIO_WRITE0 (MDIO_DIR) |
|
1257 |
#define MDIO_WRITE1 (MDIO_DIR | MDIO_DATA_OUT) |
|
1258 |
||
1259 |
#define mdio_delay(mdio_addr) readb(mdio_addr) |
|
1260 |
||
1261 |
||
1262 |
static char mii_2_8139_map[8] = { |
|
1263 |
BasicModeCtrl, |
|
1264 |
BasicModeStatus, |
|
1265 |
0, |
|
1266 |
0, |
|
1267 |
NWayAdvert, |
|
1268 |
NWayLPAR, |
|
1269 |
NWayExpansion, |
|
1270 |
0 |
|
1271 |
}; |
|
1272 |
||
1273 |
||
1274 |
#ifdef CONFIG_8139TOO_8129 |
|
1275 |
/* Syncronize the MII management interface by shifting 32 one bits out. */ |
|
1276 |
static void mdio_sync (void *mdio_addr) |
|
1277 |
{ |
|
1278 |
int i; |
|
1279 |
||
1280 |
for (i = 32; i >= 0; i--) { |
|
1281 |
writeb (MDIO_WRITE1, mdio_addr); |
|
1282 |
mdio_delay (mdio_addr); |
|
1283 |
writeb (MDIO_WRITE1 | MDIO_CLK, mdio_addr); |
|
1284 |
mdio_delay (mdio_addr); |
|
1285 |
} |
|
1286 |
} |
|
1287 |
#endif |
|
1288 |
||
1289 |
static int mdio_read (struct net_device *dev, int phy_id, int location) |
|
1290 |
{ |
|
1291 |
struct rtl8139_private *tp = dev->priv; |
|
1292 |
int retval = 0; |
|
1293 |
#ifdef CONFIG_8139TOO_8129 |
|
1294 |
void *mdio_addr = tp->mmio_addr + Config4; |
|
1295 |
int mii_cmd = (0xf6 << 10) | (phy_id << 5) | location; |
|
1296 |
int i; |
|
1297 |
#endif |
|
1298 |
||
1299 |
if (phy_id > 31) { /* Really a 8139. Use internal registers. */ |
|
1300 |
return location < 8 && mii_2_8139_map[location] ? |
|
1301 |
readw (tp->mmio_addr + mii_2_8139_map[location]) : 0; |
|
1302 |
} |
|
1303 |
||
1304 |
#ifdef CONFIG_8139TOO_8129 |
|
1305 |
mdio_sync (mdio_addr); |
|
1306 |
/* Shift the read command bits out. */ |
|
1307 |
for (i = 15; i >= 0; i--) { |
|
1308 |
int dataval = (mii_cmd & (1 << i)) ? MDIO_DATA_OUT : 0; |
|
1309 |
||
1310 |
writeb (MDIO_DIR | dataval, mdio_addr); |
|
1311 |
mdio_delay (mdio_addr); |
|
1312 |
writeb (MDIO_DIR | dataval | MDIO_CLK, mdio_addr); |
|
1313 |
mdio_delay (mdio_addr); |
|
1314 |
} |
|
1315 |
||
1316 |
/* Read the two transition, 16 data, and wire-idle bits. */ |
|
1317 |
for (i = 19; i > 0; i--) { |
|
1318 |
writeb (0, mdio_addr); |
|
1319 |
mdio_delay (mdio_addr); |
|
1320 |
retval = (retval << 1) | ((readb (mdio_addr) & MDIO_DATA_IN) ? 1 : 0); |
|
1321 |
writeb (MDIO_CLK, mdio_addr); |
|
1322 |
mdio_delay (mdio_addr); |
|
1323 |
} |
|
1324 |
#endif |
|
1325 |
||
1326 |
return (retval >> 1) & 0xffff; |
|
1327 |
} |
|
1328 |
||
1329 |
||
1330 |
static void mdio_write (struct net_device *dev, int phy_id, int location, |
|
1331 |
int value) |
|
1332 |
{ |
|
1333 |
struct rtl8139_private *tp = dev->priv; |
|
1334 |
#ifdef CONFIG_8139TOO_8129 |
|
1335 |
void *mdio_addr = tp->mmio_addr + Config4; |
|
1336 |
int mii_cmd = (0x5002 << 16) | (phy_id << 23) | (location << 18) | value; |
|
1337 |
int i; |
|
1338 |
#endif |
|
1339 |
||
1340 |
if (phy_id > 31) { /* Really a 8139. Use internal registers. */ |
|
1341 |
void *ioaddr = tp->mmio_addr; |
|
1342 |
if (location == 0) { |
|
1343 |
RTL_W8 (Cfg9346, Cfg9346_Unlock); |
|
1344 |
RTL_W16 (BasicModeCtrl, value); |
|
1345 |
RTL_W8 (Cfg9346, Cfg9346_Lock); |
|
1346 |
} else if (location < 8 && mii_2_8139_map[location]) |
|
1347 |
RTL_W16 (mii_2_8139_map[location], value); |
|
1348 |
return; |
|
1349 |
} |
|
1350 |
||
1351 |
#ifdef CONFIG_8139TOO_8129 |
|
1352 |
mdio_sync (mdio_addr); |
|
1353 |
||
1354 |
/* Shift the command bits out. */ |
|
1355 |
for (i = 31; i >= 0; i--) { |
|
1356 |
int dataval = |
|
1357 |
(mii_cmd & (1 << i)) ? MDIO_WRITE1 : MDIO_WRITE0; |
|
1358 |
writeb (dataval, mdio_addr); |
|
1359 |
mdio_delay (mdio_addr); |
|
1360 |
writeb (dataval | MDIO_CLK, mdio_addr); |
|
1361 |
mdio_delay (mdio_addr); |
|
1362 |
} |
|
1363 |
/* Clear out extra bits. */ |
|
1364 |
for (i = 2; i > 0; i--) { |
|
1365 |
writeb (0, mdio_addr); |
|
1366 |
mdio_delay (mdio_addr); |
|
1367 |
writeb (MDIO_CLK, mdio_addr); |
|
1368 |
mdio_delay (mdio_addr); |
|
1369 |
} |
|
1370 |
#endif |
|
1371 |
} |
|
1372 |
||
1373 |
||
1374 |
static int rtl8139_open (struct net_device *dev) |
|
1375 |
{ |
|
1376 |
struct rtl8139_private *tp = dev->priv; |
|
1377 |
int retval; |
|
1378 |
#ifdef RTL8139_DEBUG |
|
1379 |
void *ioaddr = tp->mmio_addr; |
|
1380 |
#endif |
|
1381 |
||
1382 |
EC_DBG(KERN_DEBUG "%s: open\n", dev->name); |
|
1383 |
||
1384 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1385 |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1386 |
if (dev != rtl_ecat_dev.dev) |
1
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1387 |
{ |
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1388 |
retval = request_irq(dev->irq, rtl8139_interrupt, SA_SHIRQ, dev->name, dev); |
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1389 |
if (retval) |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1390 |
return retval; |
1
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1391 |
} |
0 | 1392 |
|
1393 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1394 |
||
1395 |
tp->tx_bufs = pci_alloc_consistent(tp->pci_dev, TX_BUF_TOT_LEN, |
|
1396 |
&tp->tx_bufs_dma); |
|
1397 |
tp->rx_ring = pci_alloc_consistent(tp->pci_dev, RX_BUF_TOT_LEN, |
|
1398 |
&tp->rx_ring_dma); |
|
1399 |
if (tp->tx_bufs == NULL || tp->rx_ring == NULL) |
|
1400 |
{ |
|
1401 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1402 |
||
1
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1403 |
if (dev != rtl_ecat_dev.dev) |
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1404 |
{ |
0 | 1405 |
free_irq(dev->irq, dev); |
1
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1406 |
} |
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1407 |
|
0 | 1408 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1409 |
||
1410 |
if (tp->tx_bufs) |
|
1411 |
pci_free_consistent(tp->pci_dev, TX_BUF_TOT_LEN, |
|
1412 |
tp->tx_bufs, tp->tx_bufs_dma); |
|
1413 |
if (tp->rx_ring) |
|
1414 |
pci_free_consistent(tp->pci_dev, RX_BUF_TOT_LEN, |
|
1415 |
tp->rx_ring, tp->rx_ring_dma); |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1416 |
|
0 | 1417 |
return -ENOMEM; |
1418 |
||
1419 |
} |
|
1420 |
||
1421 |
tp->mii.full_duplex = tp->mii.force_media; |
|
1422 |
tp->tx_flag = (TX_FIFO_THRESH << 11) & 0x003f0000; |
|
1423 |
tp->twistie = (tp->chipset == CH_8139_K) ? 1 : 0; |
|
1424 |
tp->time_to_die = 0; |
|
1425 |
||
1426 |
rtl8139_init_ring (dev); |
|
1427 |
rtl8139_hw_start (dev); |
|
1428 |
||
1429 |
DPRINTK ("%s: rtl8139_open() ioaddr %#lx IRQ %d" |
|
1430 |
" GP Pins %2.2x %s-duplex.\n", |
|
1431 |
dev->name, pci_resource_start (tp->pci_dev, 1), |
|
1432 |
dev->irq, RTL_R8 (MediaStatus), |
|
1433 |
tp->mii.full_duplex ? "full" : "half"); |
|
1434 |
||
1435 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1436 |
||
1437 |
if (dev != rtl_ecat_dev.dev) |
|
1438 |
{ |
|
1439 |
EC_DBG(KERN_DEBUG "%s: starting kernel thread...\n", dev->name); |
|
1440 |
tp->thr_pid = kernel_thread (rtl8139_thread, dev, CLONE_FS | CLONE_FILES); |
|
1441 |
||
1442 |
if (tp->thr_pid < 0) |
|
1443 |
EC_DBG (KERN_WARNING "%s: unable to start kernel thread\n", |
|
1444 |
dev->name); |
|
1445 |
} |
|
1446 |
||
1447 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1448 |
||
1449 |
EC_DBG(KERN_DEBUG "%s: open finished.\n", dev->name); |
|
1450 |
||
1451 |
return 0; |
|
1452 |
} |
|
1453 |
||
1454 |
||
1455 |
static void rtl_check_media (struct net_device *dev) |
|
1456 |
{ |
|
1457 |
struct rtl8139_private *tp = dev->priv; |
|
1458 |
||
1459 |
if (tp->phys[0] >= 0) { |
|
1460 |
u16 mii_lpa = mdio_read(dev, tp->phys[0], MII_LPA); |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1461 |
|
0 | 1462 |
if (mii_lpa == 0xffff) |
1463 |
; /* Not there */ |
|
1464 |
else if ((mii_lpa & LPA_100FULL) == LPA_100FULL |
|
1465 |
|| (mii_lpa & 0x00C0) == LPA_10FULL) |
|
1466 |
tp->mii.full_duplex = 1; |
|
1467 |
||
1468 |
EC_DBG (KERN_INFO "%s: Setting %s%s-duplex based on" |
|
1469 |
" auto-negotiated partner ability %4.4x.\n", |
|
1470 |
dev->name, mii_lpa == 0 ? "" : |
|
1471 |
(mii_lpa & 0x0180) ? "100mbps " : "10mbps ", |
|
1472 |
tp->mii.full_duplex ? "full" : "half", mii_lpa); |
|
1473 |
} |
|
1474 |
EC_DBG(KERN_DEBUG "rtl_check_media done.\n"); |
|
1475 |
} |
|
1476 |
||
1477 |
/* Start the hardware at open or resume. */ |
|
1478 |
static void rtl8139_hw_start (struct net_device *dev) |
|
1479 |
{ |
|
1480 |
struct rtl8139_private *tp = dev->priv; |
|
1481 |
void *ioaddr = tp->mmio_addr; |
|
1482 |
u32 i; |
|
1483 |
u8 tmp; |
|
1484 |
||
1485 |
EC_DBG(KERN_DEBUG "%s: rtl8139_hw_start\n", dev->name); |
|
1486 |
||
1487 |
/* Bring old chips out of low-power mode. */ |
|
1488 |
if (rtl_chip_info[tp->chipset].flags & HasHltClk) |
|
1489 |
RTL_W8 (HltClk, 'R'); |
|
1490 |
||
1491 |
rtl8139_chip_reset (ioaddr); |
|
1492 |
||
1493 |
/* unlock Config[01234] and BMCR register writes */ |
|
1494 |
RTL_W8_F (Cfg9346, Cfg9346_Unlock); |
|
1495 |
/* Restore our idea of the MAC address. */ |
|
1496 |
RTL_W32_F (MAC0 + 0, cpu_to_le32 (*(u32 *) (dev->dev_addr + 0))); |
|
1497 |
RTL_W32_F (MAC0 + 4, cpu_to_le32 (*(u32 *) (dev->dev_addr + 4))); |
|
1498 |
||
1499 |
/* Must enable Tx/Rx before setting transfer thresholds! */ |
|
1500 |
RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb); |
|
1501 |
||
1502 |
tp->rx_config = rtl8139_rx_config | AcceptBroadcast | AcceptMyPhys; |
|
1503 |
RTL_W32 (RxConfig, tp->rx_config); |
|
1504 |
||
1505 |
/* Check this value: the documentation for IFG contradicts ifself. */ |
|
1506 |
RTL_W32 (TxConfig, rtl8139_tx_config); |
|
1507 |
||
1508 |
tp->cur_rx = 0; |
|
1509 |
||
1510 |
rtl_check_media (dev); |
|
1511 |
||
1512 |
if (tp->chipset >= CH_8139B) { |
|
1513 |
/* Disable magic packet scanning, which is enabled |
|
1514 |
* when PM is enabled in Config1. It can be reenabled |
|
1515 |
* via ETHTOOL_SWOL if desired. */ |
|
1516 |
RTL_W8 (Config3, RTL_R8 (Config3) & ~Cfg3_Magic); |
|
1517 |
} |
|
1518 |
||
1519 |
DPRINTK("init buffer addresses\n"); |
|
1520 |
||
1521 |
/* Lock Config[01234] and BMCR register writes */ |
|
1522 |
RTL_W8 (Cfg9346, Cfg9346_Lock); |
|
1523 |
||
1524 |
/* init Rx ring buffer DMA address */ |
|
1525 |
RTL_W32_F (RxBuf, tp->rx_ring_dma); |
|
1526 |
||
1527 |
/* init Tx buffer DMA addresses */ |
|
1528 |
for (i = 0; i < NUM_TX_DESC; i++) |
|
1529 |
RTL_W32_F (TxAddr0 + (i * 4), tp->tx_bufs_dma + (tp->tx_buf[i] - tp->tx_bufs)); |
|
1530 |
||
1531 |
RTL_W32 (RxMissed, 0); |
|
1532 |
||
1533 |
rtl8139_set_rx_mode (dev); |
|
1534 |
||
1535 |
/* no early-rx interrupts */ |
|
1536 |
RTL_W16 (MultiIntr, RTL_R16 (MultiIntr) & MultiIntrClear); |
|
1537 |
||
1538 |
/* make sure RxTx has started */ |
|
1539 |
tmp = RTL_R8 (ChipCmd); |
|
1540 |
if ((!(tmp & CmdRxEnb)) || (!(tmp & CmdTxEnb))) |
|
1541 |
RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb); |
|
1542 |
||
1543 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1544 |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1545 |
if (dev != rtl_ecat_dev.dev) |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1546 |
{ |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1547 |
/* Enable all known interrupts by setting the interrupt mask. */ |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1548 |
RTL_W16 (IntrMask, rtl8139_intr_mask); |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1549 |
netif_start_queue (dev); |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1550 |
} |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1551 |
else |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1552 |
{ |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1553 |
RTL_W16 (IntrMask, 0x0000); |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1554 |
} |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1555 |
|
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1556 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
0 | 1557 |
|
1558 |
EC_DBG(KERN_DEBUG "%s: rtl8139_hw_start finished.\n", dev->name); |
|
1559 |
} |
|
1560 |
||
1561 |
||
1562 |
/* Initialize the Rx and Tx rings, along with various 'dev' bits. */ |
|
1563 |
static void rtl8139_init_ring (struct net_device *dev) |
|
1564 |
{ |
|
1565 |
struct rtl8139_private *tp = dev->priv; |
|
1566 |
int i; |
|
1567 |
||
1568 |
tp->cur_rx = 0; |
|
1569 |
tp->cur_tx = 0; |
|
1570 |
tp->dirty_tx = 0; |
|
1571 |
||
1572 |
for (i = 0; i < NUM_TX_DESC; i++) |
|
1573 |
tp->tx_buf[i] = &tp->tx_bufs[i * TX_BUF_SIZE]; |
|
1574 |
} |
|
1575 |
||
1576 |
||
1577 |
/* This must be global for CONFIG_8139TOO_TUNE_TWISTER case */ |
|
1578 |
static int next_tick = 3 * HZ; |
|
1579 |
||
1580 |
#ifndef CONFIG_8139TOO_TUNE_TWISTER |
|
1581 |
static inline void rtl8139_tune_twister (struct net_device *dev, |
|
1582 |
struct rtl8139_private *tp) {} |
|
1583 |
#else |
|
1584 |
static void rtl8139_tune_twister (struct net_device *dev, |
|
1585 |
struct rtl8139_private *tp) |
|
1586 |
{ |
|
1587 |
int linkcase; |
|
1588 |
void *ioaddr = tp->mmio_addr; |
|
1589 |
||
1590 |
/* This is a complicated state machine to configure the "twister" for |
|
1591 |
impedance/echos based on the cable length. |
|
1592 |
All of this is magic and undocumented. |
|
1593 |
*/ |
|
1594 |
switch (tp->twistie) { |
|
1595 |
case 1: |
|
1596 |
if (RTL_R16 (CSCR) & CSCR_LinkOKBit) { |
|
1597 |
/* We have link beat, let us tune the twister. */ |
|
1598 |
RTL_W16 (CSCR, CSCR_LinkDownOffCmd); |
|
1599 |
tp->twistie = 2; /* Change to state 2. */ |
|
1600 |
next_tick = HZ / 10; |
|
1601 |
} else { |
|
1602 |
/* Just put in some reasonable defaults for when beat returns. */ |
|
1603 |
RTL_W16 (CSCR, CSCR_LinkDownCmd); |
|
1604 |
RTL_W32 (FIFOTMS, 0x20); /* Turn on cable test mode. */ |
|
1605 |
RTL_W32 (PARA78, PARA78_default); |
|
1606 |
RTL_W32 (PARA7c, PARA7c_default); |
|
1607 |
tp->twistie = 0; /* Bail from future actions. */ |
|
1608 |
} |
|
1609 |
break; |
|
1610 |
case 2: |
|
1611 |
/* Read how long it took to hear the echo. */ |
|
1612 |
linkcase = RTL_R16 (CSCR) & CSCR_LinkStatusBits; |
|
1613 |
if (linkcase == 0x7000) |
|
1614 |
tp->twist_row = 3; |
|
1615 |
else if (linkcase == 0x3000) |
|
1616 |
tp->twist_row = 2; |
|
1617 |
else if (linkcase == 0x1000) |
|
1618 |
tp->twist_row = 1; |
|
1619 |
else |
|
1620 |
tp->twist_row = 0; |
|
1621 |
tp->twist_col = 0; |
|
1622 |
tp->twistie = 3; /* Change to state 2. */ |
|
1623 |
next_tick = HZ / 10; |
|
1624 |
break; |
|
1625 |
case 3: |
|
1626 |
/* Put out four tuning parameters, one per 100msec. */ |
|
1627 |
if (tp->twist_col == 0) |
|
1628 |
RTL_W16 (FIFOTMS, 0); |
|
1629 |
RTL_W32 (PARA7c, param[(int) tp->twist_row] |
|
1630 |
[(int) tp->twist_col]); |
|
1631 |
next_tick = HZ / 10; |
|
1632 |
if (++tp->twist_col >= 4) { |
|
1633 |
/* For short cables we are done. |
|
1634 |
For long cables (row == 3) check for mistune. */ |
|
1635 |
tp->twistie = |
|
1636 |
(tp->twist_row == 3) ? 4 : 0; |
|
1637 |
} |
|
1638 |
break; |
|
1639 |
case 4: |
|
1640 |
/* Special case for long cables: check for mistune. */ |
|
1641 |
if ((RTL_R16 (CSCR) & |
|
1642 |
CSCR_LinkStatusBits) == 0x7000) { |
|
1643 |
tp->twistie = 0; |
|
1644 |
break; |
|
1645 |
} else { |
|
1646 |
RTL_W32 (PARA7c, 0xfb38de03); |
|
1647 |
tp->twistie = 5; |
|
1648 |
next_tick = HZ / 10; |
|
1649 |
} |
|
1650 |
break; |
|
1651 |
case 5: |
|
1652 |
/* Retune for shorter cable (column 2). */ |
|
1653 |
RTL_W32 (FIFOTMS, 0x20); |
|
1654 |
RTL_W32 (PARA78, PARA78_default); |
|
1655 |
RTL_W32 (PARA7c, PARA7c_default); |
|
1656 |
RTL_W32 (FIFOTMS, 0x00); |
|
1657 |
tp->twist_row = 2; |
|
1658 |
tp->twist_col = 0; |
|
1659 |
tp->twistie = 3; |
|
1660 |
next_tick = HZ / 10; |
|
1661 |
break; |
|
1662 |
||
1663 |
default: |
|
1664 |
/* do nothing */ |
|
1665 |
break; |
|
1666 |
} |
|
1667 |
} |
|
1668 |
#endif /* CONFIG_8139TOO_TUNE_TWISTER */ |
|
1669 |
||
1670 |
||
1671 |
static inline void rtl8139_thread_iter (struct net_device *dev, |
|
1672 |
struct rtl8139_private *tp, |
|
1673 |
void *ioaddr) |
|
1674 |
{ |
|
1675 |
int mii_lpa; |
|
1676 |
||
1677 |
mii_lpa = mdio_read (dev, tp->phys[0], MII_LPA); |
|
1678 |
||
1679 |
if (!tp->mii.force_media && mii_lpa != 0xffff) { |
|
1680 |
int duplex = (mii_lpa & LPA_100FULL) |
|
1681 |
|| (mii_lpa & 0x01C0) == 0x0040; |
|
1682 |
if (tp->mii.full_duplex != duplex) { |
|
1683 |
tp->mii.full_duplex = duplex; |
|
1684 |
||
1685 |
if (mii_lpa) { |
|
1686 |
EC_DBG (KERN_INFO |
|
1687 |
"%s: Setting %s-duplex based on MII #%d link" |
|
1688 |
" partner ability of %4.4x.\n", |
|
1689 |
dev->name, |
|
1690 |
tp->mii.full_duplex ? "full" : "half", |
|
1691 |
tp->phys[0], mii_lpa); |
|
1692 |
} else { |
|
1693 |
EC_DBG(KERN_INFO"%s: media is unconnected, link down, or incompatible connection\n", |
|
1694 |
dev->name); |
|
1695 |
} |
|
1696 |
#if 0 |
|
1697 |
RTL_W8 (Cfg9346, Cfg9346_Unlock); |
|
1698 |
RTL_W8 (Config1, tp->mii.full_duplex ? 0x60 : 0x20); |
|
1699 |
RTL_W8 (Cfg9346, Cfg9346_Lock); |
|
1700 |
#endif |
|
1701 |
} |
|
1702 |
} |
|
1703 |
||
1704 |
next_tick = HZ * 60; |
|
1705 |
||
1706 |
rtl8139_tune_twister (dev, tp); |
|
1707 |
||
1708 |
DPRINTK ("%s: Media selection tick, Link partner %4.4x.\n", |
|
1709 |
dev->name, RTL_R16 (NWayLPAR)); |
|
1710 |
DPRINTK ("%s: Other registers are IntMask %4.4x IntStatus %4.4x\n", |
|
1711 |
dev->name, RTL_R16 (IntrMask), RTL_R16 (IntrStatus)); |
|
1712 |
DPRINTK ("%s: Chip config %2.2x %2.2x.\n", |
|
1713 |
dev->name, RTL_R8 (Config0), |
|
1714 |
RTL_R8 (Config1)); |
|
1715 |
} |
|
1716 |
||
1717 |
||
1718 |
static int rtl8139_thread (void *data) |
|
1719 |
{ |
|
1720 |
struct net_device *dev = data; |
|
1721 |
struct rtl8139_private *tp = dev->priv; |
|
1722 |
unsigned long timeout; |
|
1723 |
||
1724 |
EC_DBG(KERN_DEBUG "%s: thread\n", dev->name); |
|
1725 |
||
1726 |
daemonize (); |
|
1727 |
reparent_to_init(); |
|
1728 |
spin_lock_irq(¤t->sigmask_lock); |
|
1729 |
sigemptyset(¤t->blocked); |
|
1730 |
recalc_sigpending(current); |
|
1731 |
spin_unlock_irq(¤t->sigmask_lock); |
|
1732 |
||
1733 |
strncpy (current->comm, dev->name, sizeof(current->comm) - 1); |
|
1734 |
current->comm[sizeof(current->comm) - 1] = '\0'; |
|
1735 |
||
1736 |
EC_DBG(KERN_DEBUG "%s: thread entering loop...\n", dev->name); |
|
1737 |
||
1738 |
while (1) { |
|
1739 |
timeout = next_tick; |
|
1740 |
do { |
|
1741 |
timeout = interruptible_sleep_on_timeout (&tp->thr_wait, timeout); |
|
1742 |
} while (!signal_pending (current) && (timeout > 0)); |
|
1743 |
||
1744 |
if (signal_pending (current)) { |
|
1745 |
spin_lock_irq(¤t->sigmask_lock); |
|
1746 |
flush_signals(current); |
|
1747 |
spin_unlock_irq(¤t->sigmask_lock); |
|
1748 |
} |
|
1749 |
||
1750 |
if (tp->time_to_die) |
|
1751 |
break; |
|
1752 |
||
1753 |
rtnl_lock (); |
|
1754 |
EC_DBG(KERN_DEBUG "%s: thread iter\n", dev->name); |
|
1755 |
rtl8139_thread_iter (dev, tp, tp->mmio_addr); |
|
1756 |
EC_DBG(KERN_DEBUG "%s: thread iter finished.\n", dev->name); |
|
1757 |
rtnl_unlock (); |
|
1758 |
} |
|
1759 |
||
1760 |
EC_DBG(KERN_DEBUG "%s: thread exiting...\n", dev->name); |
|
1761 |
||
1762 |
complete_and_exit (&tp->thr_exited, 0); |
|
1763 |
||
1764 |
EC_DBG(KERN_DEBUG "%s: thread exit.\n", dev->name); |
|
1765 |
} |
|
1766 |
||
1767 |
||
1768 |
static void rtl8139_tx_clear (struct rtl8139_private *tp) |
|
1769 |
{ |
|
1770 |
tp->cur_tx = 0; |
|
1771 |
tp->dirty_tx = 0; |
|
1772 |
||
1773 |
/* XXX account for unsent Tx packets in tp->stats.tx_dropped */ |
|
1774 |
} |
|
1775 |
||
1776 |
||
1777 |
static void rtl8139_tx_timeout (struct net_device *dev) |
|
1778 |
{ |
|
1779 |
struct rtl8139_private *tp = dev->priv; |
|
1780 |
void *ioaddr = tp->mmio_addr; |
|
1781 |
int i; |
|
1782 |
u8 tmp8; |
|
1783 |
unsigned long flags; |
|
1784 |
||
1785 |
EC_DBG(KERN_DEBUG "%s: tx_timeout\n", dev->name); |
|
1786 |
||
1787 |
DPRINTK ("%s: Transmit timeout, status %2.2x %4.4x " |
|
1788 |
"media %2.2x.\n", dev->name, |
|
1789 |
RTL_R8 (ChipCmd), |
|
1790 |
RTL_R16 (IntrStatus), |
|
1791 |
RTL_R8 (MediaStatus)); |
|
1792 |
||
1793 |
tp->xstats.tx_timeouts++; |
|
1794 |
||
1795 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1796 |
||
1797 |
if (dev == rtl_ecat_dev.dev) |
|
1798 |
{ |
|
1799 |
if (rtl_ecat_dev.state != ECAT_DS_SENT) |
|
1800 |
{ |
|
3
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
1801 |
EC_DBG(KERN_WARNING "EtherCAT: Wrong status at timeout: %i\n", |
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
1802 |
rtl_ecat_dev.state); |
0 | 1803 |
} |
3
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
1804 |
|
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
1805 |
rtl_ecat_dev.state = ECAT_DS_TIMEOUT; |
0 | 1806 |
} |
1807 |
||
1808 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1809 |
||
1810 |
/* disable Tx ASAP, if not already */ |
|
1811 |
tmp8 = RTL_R8 (ChipCmd); |
|
1812 |
if (tmp8 & CmdTxEnb) |
|
1813 |
RTL_W8 (ChipCmd, CmdRxEnb); |
|
1814 |
||
1815 |
/* Disable interrupts by clearing the interrupt mask. */ |
|
1816 |
RTL_W16 (IntrMask, 0x0000); |
|
1817 |
||
1818 |
/* Emit info to figure out what went wrong. */ |
|
1819 |
EC_DBG (KERN_DEBUG "%s: Tx queue start entry %ld dirty entry %ld.\n", |
|
1820 |
dev->name, tp->cur_tx, tp->dirty_tx); |
|
1821 |
for (i = 0; i < NUM_TX_DESC; i++) |
|
1822 |
EC_DBG (KERN_DEBUG "%s: Tx descriptor %d is %8.8lx.%s\n", |
|
1823 |
dev->name, i, RTL_R32 (TxStatus0 + (i * 4)), |
|
1824 |
i == (int) (tp->dirty_tx % NUM_TX_DESC) ? |
|
1825 |
" (queue head)" : ""); |
|
1826 |
||
1827 |
/* Stop a shared interrupt from scavenging while we are. */ |
|
4
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
1828 |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1829 |
spin_lock_irqsave (&tp->lock, flags); |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1830 |
rtl8139_tx_clear (tp); |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1831 |
spin_unlock_irqrestore (&tp->lock, flags); |
4
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
1832 |
|
0 | 1833 |
/* ...and finally, reset everything */ |
1834 |
rtl8139_hw_start (dev); |
|
1835 |
||
1836 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1837 |
|
0 | 1838 |
if (dev != rtl_ecat_dev.dev) netif_wake_queue (dev); |
1
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1839 |
|
0 | 1840 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1841 |
||
1842 |
EC_DBG(KERN_DEBUG "%s: tx_timeout finished.\n", dev->name); |
|
1843 |
} |
|
1844 |
||
1845 |
static int rtl8139_start_xmit (struct sk_buff *skb, struct net_device *dev) |
|
1846 |
{ |
|
1847 |
struct rtl8139_private *tp = dev->priv; |
|
1848 |
void *ioaddr = tp->mmio_addr; |
|
1849 |
unsigned int entry; |
|
1850 |
unsigned int len = skb->len; |
|
1851 |
||
1852 |
/* Calculate the next Tx descriptor entry. */ |
|
1853 |
entry = tp->cur_tx % NUM_TX_DESC; |
|
1854 |
||
1855 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1856 |
||
1857 |
if (likely(len < TX_BUF_SIZE)) |
|
1858 |
{ |
|
1859 |
skb_copy_and_csum_dev(skb, tp->tx_buf[entry]); |
|
1860 |
||
1861 |
// Socket buffer nicht löschen, wenn vom EtherCAT-device |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1862 |
if (dev != rtl_ecat_dev.dev) dev_kfree_skb(skb); |
0 | 1863 |
} |
1864 |
else |
|
1865 |
{ |
|
1866 |
if (dev != rtl_ecat_dev.dev) dev_kfree_skb(skb); |
|
1867 |
tp->stats.tx_dropped++; |
|
1868 |
return 0; |
|
1869 |
} |
|
1870 |
||
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1871 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1872 |
|
3
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
1873 |
/* Note: the chip doesn't have auto-pad! */ |
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1874 |
spin_lock_irq(&tp->lock); |
0 | 1875 |
|
1876 |
RTL_W32_F (TxStatus0 + (entry * sizeof (u32)), |
|
1877 |
tp->tx_flag | max(len, (unsigned int)ETH_ZLEN)); |
|
1878 |
||
1879 |
dev->trans_start = jiffies; |
|
1880 |
||
1881 |
tp->cur_tx++; |
|
1882 |
wmb(); |
|
1883 |
||
1884 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1885 |
||
3
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
1886 |
if (dev != rtl_ecat_dev.dev |
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
1887 |
&& ((tp->cur_tx - NUM_TX_DESC) == tp->dirty_tx)) |
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
1888 |
{ |
0 | 1889 |
netif_stop_queue (dev); |
3
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
1890 |
} |
0 | 1891 |
|
1892 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1893 |
||
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1894 |
spin_unlock_irq(&tp->lock); |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1895 |
|
0 | 1896 |
DPRINTK ("%s: Queued Tx packet size %u to slot %d.\n", |
1897 |
dev->name, len, entry); |
|
1898 |
||
1899 |
return 0; |
|
1900 |
} |
|
1901 |
||
1902 |
||
1903 |
static void rtl8139_tx_interrupt (struct net_device *dev, |
|
1904 |
struct rtl8139_private *tp, |
|
1905 |
void *ioaddr) |
|
1906 |
{ |
|
1907 |
unsigned long dirty_tx, tx_left; |
|
1908 |
||
1909 |
assert (dev != NULL); |
|
1910 |
assert (tp != NULL); |
|
1911 |
assert (ioaddr != NULL); |
|
1912 |
||
1913 |
dirty_tx = tp->dirty_tx; |
|
1914 |
tx_left = tp->cur_tx - dirty_tx; |
|
1915 |
||
1916 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1917 |
|
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1918 |
if (dev == rtl_ecat_dev.dev) |
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
1919 |
{ |
3
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
1920 |
rtl_ecat_dev.tx_intr_cnt++; |
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
1921 |
rdtscl(rtl_ecat_dev.tx_time); // Get CPU cycles |
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
1922 |
} |
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
1923 |
|
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
1924 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
0 | 1925 |
|
1926 |
while (tx_left > 0) { |
|
1927 |
int entry = dirty_tx % NUM_TX_DESC; |
|
1928 |
int txstatus; |
|
1929 |
||
1930 |
txstatus = RTL_R32 (TxStatus0 + (entry * sizeof (u32))); |
|
1931 |
||
1932 |
if (!(txstatus & (TxStatOK | TxUnderrun | TxAborted))) |
|
1933 |
break; /* It still hasn't been Txed */ |
|
1934 |
||
1935 |
/* Note: TxCarrierLost is always asserted at 100mbps. */ |
|
1936 |
if (txstatus & (TxOutOfWindow | TxAborted)) { |
|
1937 |
/* There was an major error, log it. */ |
|
1938 |
DPRINTK ("%s: Transmit error, Tx status %8.8x.\n", |
|
1939 |
dev->name, txstatus); |
|
1940 |
tp->stats.tx_errors++; |
|
1941 |
if (txstatus & TxAborted) { |
|
1942 |
tp->stats.tx_aborted_errors++; |
|
1943 |
RTL_W32 (TxConfig, TxClearAbt); |
|
1944 |
RTL_W16 (IntrStatus, TxErr); |
|
1945 |
wmb(); |
|
1946 |
} |
|
1947 |
if (txstatus & TxCarrierLost) |
|
1948 |
tp->stats.tx_carrier_errors++; |
|
1949 |
if (txstatus & TxOutOfWindow) |
|
1950 |
tp->stats.tx_window_errors++; |
|
1951 |
||
1952 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1953 |
|
0 | 1954 |
if (dev == rtl_ecat_dev.dev) |
1955 |
{ |
|
1956 |
rtl_ecat_dev.state = ECAT_DS_ERROR; |
|
1957 |
} |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
1958 |
|
0 | 1959 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
1960 |
||
1961 |
} else { |
|
1962 |
if (txstatus & TxUnderrun) { |
|
1963 |
/* Add 64 to the Tx FIFO threshold. */ |
|
1964 |
if (tp->tx_flag < 0x00300000) |
|
1965 |
tp->tx_flag += 0x00020000; |
|
1966 |
tp->stats.tx_fifo_errors++; |
|
1967 |
} |
|
1968 |
tp->stats.collisions += (txstatus >> 24) & 15; |
|
1969 |
tp->stats.tx_bytes += txstatus & 0x7ff; |
|
1970 |
tp->stats.tx_packets++; |
|
1971 |
} |
|
1972 |
||
1973 |
dirty_tx++; |
|
1974 |
tx_left--; |
|
1975 |
} |
|
1976 |
||
1977 |
#ifndef RTL8139_NDEBUG |
|
1978 |
if (tp->cur_tx - dirty_tx > NUM_TX_DESC) { |
|
1979 |
EC_DBG (KERN_ERR "%s: Out-of-sync dirty pointer, %ld vs. %ld.\n", |
|
1980 |
dev->name, dirty_tx, tp->cur_tx); |
|
1981 |
dirty_tx += NUM_TX_DESC; |
|
1982 |
} |
|
1983 |
#endif /* RTL8139_NDEBUG */ |
|
1984 |
||
1985 |
/* only wake the queue if we did work, and the queue is stopped */ |
|
1986 |
if (tp->dirty_tx != dirty_tx) { |
|
1987 |
tp->dirty_tx = dirty_tx; |
|
1988 |
mb(); |
|
1989 |
||
1990 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1991 |
||
1992 |
if (dev != rtl_ecat_dev.dev && netif_queue_stopped (dev)) |
|
3
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
1993 |
{ |
0 | 1994 |
netif_wake_queue (dev); |
3
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
1995 |
} |
0 | 1996 |
|
1997 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
1998 |
} |
|
1999 |
} |
|
2000 |
||
2001 |
||
2002 |
/* TODO: clean this up! Rx reset need not be this intensive */ |
|
2003 |
static void rtl8139_rx_err (u32 rx_status, struct net_device *dev, |
|
2004 |
struct rtl8139_private *tp, void *ioaddr) |
|
2005 |
{ |
|
2006 |
u8 tmp8; |
|
2007 |
#ifdef CONFIG_8139_OLD_RX_RESET |
|
2008 |
int tmp_work; |
|
2009 |
#endif |
|
2010 |
||
2011 |
DPRINTK ("%s: Ethernet frame had errors, status %8.8x.\n", |
|
2012 |
dev->name, rx_status); |
|
2013 |
tp->stats.rx_errors++; |
|
2014 |
if (!(rx_status & RxStatusOK)) { |
|
2015 |
if (rx_status & RxTooLong) { |
|
2016 |
DPRINTK ("%s: Oversized Ethernet frame, status %4.4x!\n", |
|
2017 |
dev->name, rx_status); |
|
2018 |
/* A.C.: The chip hangs here. */ |
|
2019 |
} |
|
2020 |
if (rx_status & (RxBadSymbol | RxBadAlign)) |
|
2021 |
tp->stats.rx_frame_errors++; |
|
2022 |
if (rx_status & (RxRunt | RxTooLong)) |
|
2023 |
tp->stats.rx_length_errors++; |
|
2024 |
if (rx_status & RxCRCErr) |
|
2025 |
tp->stats.rx_crc_errors++; |
|
2026 |
} else { |
|
2027 |
tp->xstats.rx_lost_in_ring++; |
|
2028 |
} |
|
2029 |
||
2030 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
2031 |
|
0 | 2032 |
if (dev == rtl_ecat_dev.dev) |
2033 |
{ |
|
2034 |
rtl_ecat_dev.state = ECAT_DS_ERROR; |
|
2035 |
} |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
2036 |
|
0 | 2037 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2038 |
||
2039 |
#ifndef CONFIG_8139_OLD_RX_RESET |
|
2040 |
tmp8 = RTL_R8 (ChipCmd); |
|
2041 |
RTL_W8 (ChipCmd, tmp8 & ~CmdRxEnb); |
|
2042 |
RTL_W8 (ChipCmd, tmp8); |
|
2043 |
RTL_W32 (RxConfig, tp->rx_config); |
|
2044 |
tp->cur_rx = 0; |
|
2045 |
#else |
|
2046 |
/* Reset the receiver, based on RealTek recommendation. (Bug?) */ |
|
2047 |
||
2048 |
/* disable receive */ |
|
2049 |
RTL_W8_F (ChipCmd, CmdTxEnb); |
|
2050 |
tmp_work = 200; |
|
2051 |
while (--tmp_work > 0) { |
|
2052 |
udelay(1); |
|
2053 |
tmp8 = RTL_R8 (ChipCmd); |
|
2054 |
if (!(tmp8 & CmdRxEnb)) |
|
2055 |
break; |
|
2056 |
} |
|
2057 |
if (tmp_work <= 0) |
|
2058 |
EC_DBG (KERN_WARNING PFX "rx stop wait too long\n"); |
|
2059 |
/* restart receive */ |
|
2060 |
tmp_work = 200; |
|
2061 |
while (--tmp_work > 0) { |
|
2062 |
RTL_W8_F (ChipCmd, CmdRxEnb | CmdTxEnb); |
|
2063 |
udelay(1); |
|
2064 |
tmp8 = RTL_R8 (ChipCmd); |
|
2065 |
if ((tmp8 & CmdRxEnb) && (tmp8 & CmdTxEnb)) |
|
2066 |
break; |
|
2067 |
} |
|
2068 |
if (tmp_work <= 0) |
|
2069 |
EC_DBG (KERN_WARNING PFX "tx/rx enable wait too long\n"); |
|
2070 |
||
2071 |
/* and reinitialize all rx related registers */ |
|
2072 |
RTL_W8_F (Cfg9346, Cfg9346_Unlock); |
|
2073 |
/* Must enable Tx/Rx before setting transfer thresholds! */ |
|
2074 |
RTL_W8 (ChipCmd, CmdRxEnb | CmdTxEnb); |
|
2075 |
||
2076 |
tp->rx_config = rtl8139_rx_config | AcceptBroadcast | AcceptMyPhys; |
|
2077 |
RTL_W32 (RxConfig, tp->rx_config); |
|
2078 |
tp->cur_rx = 0; |
|
2079 |
||
2080 |
DPRINTK("init buffer addresses\n"); |
|
2081 |
||
2082 |
/* Lock Config[01234] and BMCR register writes */ |
|
2083 |
RTL_W8 (Cfg9346, Cfg9346_Lock); |
|
2084 |
||
2085 |
/* init Rx ring buffer DMA address */ |
|
2086 |
RTL_W32_F (RxBuf, tp->rx_ring_dma); |
|
2087 |
||
2088 |
/* A.C.: Reset the multicast list. */ |
|
2089 |
__set_rx_mode (dev); |
|
2090 |
#endif |
|
2091 |
} |
|
2092 |
||
2093 |
static void rtl8139_rx_interrupt (struct net_device *dev, |
|
2094 |
struct rtl8139_private *tp, void *ioaddr) |
|
2095 |
{ |
|
2096 |
unsigned char *rx_ring; |
|
2097 |
u16 cur_rx; |
|
2098 |
||
2099 |
assert (dev != NULL); |
|
2100 |
assert (tp != NULL); |
|
2101 |
assert (ioaddr != NULL); |
|
2102 |
||
2103 |
rx_ring = tp->rx_ring; |
|
2104 |
cur_rx = tp->cur_rx; |
|
2105 |
||
2106 |
DPRINTK ("%s: In rtl8139_rx(), current %4.4x BufAddr %4.4x," |
|
2107 |
" free to %4.4x, Cmd %2.2x.\n", dev->name, cur_rx, |
|
2108 |
RTL_R16 (RxBufAddr), |
|
2109 |
RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd)); |
|
2110 |
||
2111 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
2112 |
|
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
2113 |
if (dev == rtl_ecat_dev.dev) |
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
2114 |
{ |
3
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2115 |
rtl_ecat_dev.rx_intr_cnt++; |
1
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
2116 |
rdtscl(rtl_ecat_dev.rx_time); // Get CPU cycles |
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
2117 |
} |
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
2118 |
|
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
2119 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
0 | 2120 |
|
2121 |
while ((RTL_R8 (ChipCmd) & RxBufEmpty) == 0) { |
|
2122 |
int ring_offset = cur_rx % RX_BUF_LEN; |
|
2123 |
u32 rx_status; |
|
2124 |
unsigned int rx_size; |
|
2125 |
unsigned int pkt_size; |
|
2126 |
struct sk_buff *skb; |
|
2127 |
||
2128 |
rmb(); |
|
2129 |
||
2130 |
/* read size+status of next frame from DMA ring buffer */ |
|
2131 |
rx_status = le32_to_cpu (*(u32 *) (rx_ring + ring_offset)); |
|
2132 |
rx_size = rx_status >> 16; |
|
2133 |
pkt_size = rx_size - 4; |
|
2134 |
||
2135 |
||
2136 |
DPRINTK ("%s: rtl8139_rx() status %4.4x, size %4.4x," |
|
2137 |
" cur %4.4x.\n", dev->name, rx_status, |
|
2138 |
rx_size, cur_rx); |
|
2139 |
||
2140 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
2141 |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
2142 |
#if RTL8139_DEBUG > 2 |
0 | 2143 |
if (dev == rtl_ecat_dev.dev) |
2144 |
{ |
|
3
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2145 |
int i; |
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2146 |
DPRINTK("%s: Frame contents ", dev->name); |
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2147 |
for (i = 0; i < 70; i++) EC_DBG(" %2.2x", rx_ring[ring_offset + i]); |
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2148 |
EC_DBG(".\n"); |
0 | 2149 |
} |
1
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
2150 |
#endif |
0 | 2151 |
|
2152 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2153 |
||
2154 |
/* Packet copy from FIFO still in progress. |
|
2155 |
* Theoretically, this should never happen |
|
2156 |
* since EarlyRx is disabled. |
|
2157 |
*/ |
|
2158 |
if (rx_size == 0xfff0) { |
|
2159 |
tp->xstats.early_rx++; |
|
2160 |
break; |
|
2161 |
} |
|
2162 |
||
2163 |
/* If Rx err or invalid rx_size/rx_status received |
|
2164 |
* (which happens if we get lost in the ring), |
|
2165 |
* Rx process gets reset, so we abort any further |
|
2166 |
* Rx processing. |
|
2167 |
*/ |
|
2168 |
if ((rx_size > (MAX_ETH_FRAME_SIZE+4)) || |
|
2169 |
(rx_size < 8) || |
|
2170 |
(!(rx_status & RxStatusOK))) { |
|
2171 |
rtl8139_rx_err (rx_status, dev, tp, ioaddr); |
|
2172 |
return; |
|
2173 |
} |
|
2174 |
||
2175 |
/* Malloc up new buffer, compatible with net-2e. */ |
|
2176 |
/* Omit the four octet CRC from the length. */ |
|
2177 |
||
2178 |
/* TODO: consider allocating skb's outside of |
|
2179 |
* interrupt context, both to speed interrupt processing, |
|
2180 |
* and also to reduce the chances of having to |
|
2181 |
* drop packets here under memory pressure. |
|
2182 |
*/ |
|
2183 |
||
2184 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
2185 |
||
2186 |
if (dev != rtl_ecat_dev.dev) |
|
2187 |
{ |
|
2188 |
skb = dev_alloc_skb(pkt_size + 2); |
|
2189 |
||
2190 |
if (skb) |
|
2191 |
{ |
|
2192 |
skb->dev = dev; |
|
3
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2193 |
skb_reserve(skb, 2); /* 16 byte align the IP fields. */ |
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2194 |
eth_copy_and_sum(skb, &rx_ring[ring_offset + 4], pkt_size, 0); |
0 | 2195 |
skb_put (skb, pkt_size); |
3
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2196 |
skb->protocol = eth_type_trans(skb, dev); // Entfernt auch den Ethernet Header! |
0 | 2197 |
netif_rx(skb); |
3
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2198 |
|
0 | 2199 |
dev->last_rx = jiffies; |
2200 |
tp->stats.rx_bytes += pkt_size; |
|
2201 |
tp->stats.rx_packets++; |
|
2202 |
} |
|
2203 |
else |
|
2204 |
{ |
|
2205 |
EC_DBG (KERN_WARNING |
|
2206 |
"%s: Memory squeeze, dropping packet.\n", |
|
2207 |
dev->name); |
|
2208 |
tp->stats.rx_dropped++; |
|
2209 |
} |
|
2210 |
} |
|
2211 |
else |
|
2212 |
{ |
|
2213 |
if (rtl_ecat_dev.state != ECAT_DS_SENT) |
|
2214 |
{ |
|
2215 |
EC_DBG(KERN_WARNING "EtherCAT: Received frame while not in SENT state!\n"); |
|
2216 |
} |
|
2217 |
else |
|
2218 |
{ |
|
2219 |
// Copy received data to ethercat-device buffer, skip Ethernet-II header |
|
2220 |
memcpy(rtl_ecat_dev.rx_data, &rx_ring[ring_offset + 4] + ETH_HLEN, |
|
2221 |
pkt_size - ETH_HLEN); |
|
2222 |
rtl_ecat_dev.rx_data_length = pkt_size - ETH_HLEN; |
|
2223 |
||
2224 |
rtl_ecat_dev.state = ECAT_DS_RECEIVED; |
|
2225 |
||
2226 |
dev->last_rx = jiffies; |
|
2227 |
tp->stats.rx_bytes += pkt_size; |
|
2228 |
tp->stats.rx_packets++; |
|
2229 |
} |
|
2230 |
} |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
2231 |
|
0 | 2232 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2233 |
||
2234 |
cur_rx = (cur_rx + rx_size + 4 + 3) & ~3; |
|
2235 |
RTL_W16 (RxBufPtr, cur_rx - 16); |
|
2236 |
||
2237 |
if (RTL_R16 (IntrStatus) & RxAckBits) |
|
2238 |
RTL_W16_F (IntrStatus, RxAckBits); |
|
2239 |
} |
|
2240 |
||
2241 |
DPRINTK ("%s: Done rtl8139_rx(), current %4.4x BufAddr %4.4x," |
|
2242 |
" free to %4.4x, Cmd %2.2x.\n", dev->name, cur_rx, |
|
2243 |
RTL_R16 (RxBufAddr), |
|
2244 |
RTL_R16 (RxBufPtr), RTL_R8 (ChipCmd)); |
|
2245 |
||
2246 |
tp->cur_rx = cur_rx; |
|
2247 |
} |
|
2248 |
||
2249 |
||
2250 |
static void rtl8139_weird_interrupt (struct net_device *dev, |
|
2251 |
struct rtl8139_private *tp, |
|
2252 |
void *ioaddr, |
|
2253 |
int status, int link_changed) |
|
2254 |
{ |
|
2255 |
DPRINTK ("%s: Abnormal interrupt, status %8.8x.\n", |
|
2256 |
dev->name, status); |
|
2257 |
||
2258 |
assert (dev != NULL); |
|
2259 |
assert (tp != NULL); |
|
2260 |
assert (ioaddr != NULL); |
|
2261 |
||
2262 |
/* Update the error count. */ |
|
2263 |
tp->stats.rx_missed_errors += RTL_R32 (RxMissed); |
|
2264 |
RTL_W32 (RxMissed, 0); |
|
2265 |
||
2266 |
if ((status & RxUnderrun) && link_changed && |
|
2267 |
(tp->drv_flags & HAS_LNK_CHNG)) { |
|
2268 |
/* Really link-change on new chips. */ |
|
2269 |
int lpar = RTL_R16 (NWayLPAR); |
|
2270 |
int duplex = (lpar & LPA_100FULL) || (lpar & 0x01C0) == 0x0040 |
|
2271 |
|| tp->mii.force_media; |
|
2272 |
if (tp->mii.full_duplex != duplex) { |
|
2273 |
tp->mii.full_duplex = duplex; |
|
2274 |
#if 0 |
|
2275 |
RTL_W8 (Cfg9346, Cfg9346_Unlock); |
|
2276 |
RTL_W8 (Config1, tp->mii.full_duplex ? 0x60 : 0x20); |
|
2277 |
RTL_W8 (Cfg9346, Cfg9346_Lock); |
|
2278 |
#endif |
|
2279 |
} |
|
2280 |
status &= ~RxUnderrun; |
|
2281 |
} |
|
2282 |
||
2283 |
/* XXX along with rtl8139_rx_err, are we double-counting errors? */ |
|
2284 |
if (status & |
|
2285 |
(RxUnderrun | RxOverflow | RxErr | RxFIFOOver)) |
|
2286 |
tp->stats.rx_errors++; |
|
2287 |
||
2288 |
if (status & PCSTimeout) |
|
2289 |
tp->stats.rx_length_errors++; |
|
2290 |
if (status & (RxUnderrun | RxFIFOOver)) |
|
2291 |
tp->stats.rx_fifo_errors++; |
|
2292 |
if (status & PCIErr) { |
|
2293 |
u16 pci_cmd_status; |
|
2294 |
pci_read_config_word (tp->pci_dev, PCI_STATUS, &pci_cmd_status); |
|
2295 |
pci_write_config_word (tp->pci_dev, PCI_STATUS, pci_cmd_status); |
|
2296 |
||
2297 |
EC_DBG (KERN_ERR "%s: PCI Bus error %4.4x.\n", |
|
2298 |
dev->name, pci_cmd_status); |
|
2299 |
} |
|
2300 |
} |
|
2301 |
||
2302 |
/* The interrupt handler does all of the Rx thread work and cleans up |
|
2303 |
after the Tx thread. */ |
|
2304 |
static void rtl8139_interrupt (int irq, void *dev_instance, |
|
2305 |
struct pt_regs *regs) |
|
2306 |
{ |
|
2307 |
struct net_device *dev = (struct net_device *) dev_instance; |
|
2308 |
struct rtl8139_private *tp = dev->priv; |
|
2309 |
int boguscnt = max_interrupt_work; |
|
2310 |
void *ioaddr = tp->mmio_addr; |
|
2311 |
int ackstat, status; |
|
2312 |
int link_changed = 0; /* avoid bogus "uninit" warning */ |
|
2313 |
||
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
2314 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
4
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2315 |
|
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2316 |
if (dev == rtl_ecat_dev.dev) |
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2317 |
{ |
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2318 |
rtl_ecat_dev.intr_cnt++; |
0 | 2319 |
} |
2320 |
else |
|
4
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2321 |
{ |
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
2322 |
spin_lock(&tp->lock); |
4
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2323 |
} |
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2324 |
|
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2325 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
0 | 2326 |
|
2327 |
do { |
|
2328 |
status = RTL_R16 (IntrStatus); |
|
2329 |
||
2330 |
/* h/w no longer present (hotplug?) or major error, bail */ |
|
2331 |
if (status == 0xFFFF) |
|
2332 |
break; |
|
2333 |
||
2334 |
if ((status & |
|
2335 |
(PCIErr | PCSTimeout | RxUnderrun | RxOverflow | |
|
2336 |
RxFIFOOver | TxErr | TxOK | RxErr | RxOK)) == 0) |
|
2337 |
break; |
|
2338 |
||
2339 |
/* Acknowledge all of the current interrupt sources ASAP, but |
|
2340 |
an first get an additional status bit from CSCR. */ |
|
2341 |
if (status & RxUnderrun) |
|
2342 |
link_changed = RTL_R16 (CSCR) & CSCR_LinkChangeBit; |
|
2343 |
||
2344 |
/* The chip takes special action when we clear RxAckBits, |
|
2345 |
* so we clear them later in rtl8139_rx_interrupt |
|
2346 |
*/ |
|
2347 |
ackstat = status & ~(RxAckBits | TxErr); |
|
2348 |
RTL_W16 (IntrStatus, ackstat); |
|
2349 |
||
2350 |
DPRINTK ("%s: interrupt status=%#4.4x ackstat=%#4.4x new intstat=%#4.4x.\n", |
|
2351 |
dev->name, ackstat, status, RTL_R16 (IntrStatus)); |
|
2352 |
||
3
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2353 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2354 |
|
0 | 2355 |
if ((dev == rtl_ecat_dev.dev || netif_running (dev)) && (status & RxAckBits)) |
3
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2356 |
{ |
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2357 |
rtl8139_rx_interrupt (dev, tp, ioaddr); |
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2358 |
} |
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2359 |
|
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2360 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
0 | 2361 |
|
2362 |
/* Check uncommon events with one test. */ |
|
2363 |
if (status & (PCIErr | PCSTimeout | RxUnderrun | RxOverflow | |
|
2364 |
RxFIFOOver | RxErr)) |
|
2365 |
rtl8139_weird_interrupt (dev, tp, ioaddr, |
|
2366 |
status, link_changed); |
|
2367 |
||
3
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2368 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2369 |
|
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2370 |
if ((dev == rtl_ecat_dev.dev || netif_running (dev)) |
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2371 |
&& (status & (TxOK | TxErr))) |
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2372 |
{ |
0 | 2373 |
rtl8139_tx_interrupt (dev, tp, ioaddr); |
2374 |
if (status & TxErr) |
|
2375 |
RTL_W16 (IntrStatus, TxErr); |
|
2376 |
} |
|
2377 |
||
3
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2378 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2379 |
|
0 | 2380 |
boguscnt--; |
2381 |
} while (boguscnt > 0); |
|
2382 |
||
2383 |
if (boguscnt <= 0) { |
|
2384 |
EC_DBG (KERN_WARNING "%s: Too much work at interrupt, " |
|
2385 |
"IntrStatus=0x%4.4x.\n", dev->name, status); |
|
2386 |
||
2387 |
/* Clear all interrupt sources. */ |
|
2388 |
RTL_W16 (IntrStatus, 0xffff); |
|
2389 |
} |
|
2390 |
||
4
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2391 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2392 |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
2393 |
if (dev != rtl_ecat_dev.dev) |
4
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2394 |
{ |
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
2395 |
spin_unlock (&tp->lock); |
4
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2396 |
} |
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2397 |
|
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2398 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
0 | 2399 |
|
2400 |
DPRINTK ("%s: exiting interrupt, intr_status=%#4.4x.\n", |
|
2401 |
dev->name, RTL_R16 (IntrStatus)); |
|
2402 |
} |
|
2403 |
||
2404 |
static int rtl8139_close (struct net_device *dev) |
|
2405 |
{ |
|
2406 |
struct rtl8139_private *tp = dev->priv; |
|
2407 |
void *ioaddr = tp->mmio_addr; |
|
2408 |
int ret = 0; |
|
2409 |
unsigned long flags; |
|
2410 |
||
2411 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
2412 |
||
2413 |
if (dev != rtl_ecat_dev.dev) |
|
2414 |
{ |
|
2415 |
netif_stop_queue(dev); |
|
2416 |
||
2417 |
if (tp->thr_pid >= 0) { |
|
2418 |
tp->time_to_die = 1; |
|
2419 |
wmb(); |
|
2420 |
ret = kill_proc (tp->thr_pid, SIGTERM, 1); |
|
2421 |
if (ret) { |
|
2422 |
EC_DBG (KERN_ERR "%s: unable to signal thread\n", dev->name); |
|
2423 |
return ret; |
|
2424 |
} |
|
2425 |
wait_for_completion (&tp->thr_exited); |
|
2426 |
} |
|
2427 |
} |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
2428 |
|
0 | 2429 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2430 |
||
2431 |
DPRINTK ("%s: Shutting down ethercard, status was 0x%4.4x.\n", |
|
2432 |
dev->name, RTL_R16 (IntrStatus)); |
|
2433 |
||
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
2434 |
spin_lock_irqsave(&tp->lock, flags); |
0 | 2435 |
|
2436 |
/* Stop the chip's Tx and Rx DMA processes. */ |
|
2437 |
RTL_W8 (ChipCmd, 0); |
|
2438 |
||
2439 |
/* Disable interrupts by clearing the interrupt mask. */ |
|
2440 |
RTL_W16 (IntrMask, 0); |
|
2441 |
||
2442 |
/* Update the error counts. */ |
|
2443 |
tp->stats.rx_missed_errors += RTL_R32 (RxMissed); |
|
2444 |
RTL_W32 (RxMissed, 0); |
|
2445 |
||
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
2446 |
spin_unlock_irqrestore (&tp->lock, flags); |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
2447 |
synchronize_irq (); |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
2448 |
|
0 | 2449 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
1
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
2450 |
|
0 | 2451 |
if (dev != rtl_ecat_dev.dev) |
2452 |
{ |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
2453 |
free_irq(dev->irq, dev); |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
2454 |
} |
0 | 2455 |
|
2456 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2457 |
||
2458 |
rtl8139_tx_clear (tp); |
|
2459 |
||
2460 |
pci_free_consistent(tp->pci_dev, RX_BUF_TOT_LEN, |
|
2461 |
tp->rx_ring, tp->rx_ring_dma); |
|
2462 |
pci_free_consistent(tp->pci_dev, TX_BUF_TOT_LEN, |
|
2463 |
tp->tx_bufs, tp->tx_bufs_dma); |
|
2464 |
tp->rx_ring = NULL; |
|
2465 |
tp->tx_bufs = NULL; |
|
2466 |
||
2467 |
/* Green! Put the chip in low-power mode. */ |
|
2468 |
RTL_W8 (Cfg9346, Cfg9346_Unlock); |
|
2469 |
||
2470 |
if (rtl_chip_info[tp->chipset].flags & HasHltClk) |
|
2471 |
RTL_W8 (HltClk, 'H'); /* 'R' would leave the clock running. */ |
|
2472 |
||
2473 |
EC_DBG ("rtl8139: closing done\n"); |
|
2474 |
||
2475 |
return 0; |
|
2476 |
} |
|
2477 |
||
2478 |
||
2479 |
/* Get the ethtool Wake-on-LAN settings. Assumes that wol points to |
|
2480 |
kernel memory, *wol has been initialized as {ETHTOOL_GWOL}, and |
|
2481 |
other threads or interrupts aren't messing with the 8139. */ |
|
2482 |
static void netdev_get_wol (struct net_device *dev, struct ethtool_wolinfo *wol) |
|
2483 |
{ |
|
2484 |
struct rtl8139_private *np = dev->priv; |
|
2485 |
void *ioaddr = np->mmio_addr; |
|
2486 |
||
2487 |
if (rtl_chip_info[np->chipset].flags & HasLWake) { |
|
2488 |
u8 cfg3 = RTL_R8 (Config3); |
|
2489 |
u8 cfg5 = RTL_R8 (Config5); |
|
2490 |
||
2491 |
wol->supported = WAKE_PHY | WAKE_MAGIC |
|
2492 |
| WAKE_UCAST | WAKE_MCAST | WAKE_BCAST; |
|
2493 |
||
2494 |
wol->wolopts = 0; |
|
2495 |
if (cfg3 & Cfg3_LinkUp) |
|
2496 |
wol->wolopts |= WAKE_PHY; |
|
2497 |
if (cfg3 & Cfg3_Magic) |
|
2498 |
wol->wolopts |= WAKE_MAGIC; |
|
2499 |
/* (KON)FIXME: See how netdev_set_wol() handles the |
|
2500 |
following constants. */ |
|
2501 |
if (cfg5 & Cfg5_UWF) |
|
2502 |
wol->wolopts |= WAKE_UCAST; |
|
2503 |
if (cfg5 & Cfg5_MWF) |
|
2504 |
wol->wolopts |= WAKE_MCAST; |
|
2505 |
if (cfg5 & Cfg5_BWF) |
|
2506 |
wol->wolopts |= WAKE_BCAST; |
|
2507 |
} |
|
2508 |
} |
|
2509 |
||
2510 |
||
2511 |
/* Set the ethtool Wake-on-LAN settings. Return 0 or -errno. Assumes |
|
2512 |
that wol points to kernel memory and other threads or interrupts |
|
2513 |
aren't messing with the 8139. */ |
|
2514 |
static int netdev_set_wol (struct net_device *dev, |
|
2515 |
const struct ethtool_wolinfo *wol) |
|
2516 |
{ |
|
2517 |
struct rtl8139_private *np = dev->priv; |
|
2518 |
void *ioaddr = np->mmio_addr; |
|
2519 |
u32 support; |
|
2520 |
u8 cfg3, cfg5; |
|
2521 |
||
2522 |
support = ((rtl_chip_info[np->chipset].flags & HasLWake) |
|
2523 |
? (WAKE_PHY | WAKE_MAGIC |
|
2524 |
| WAKE_UCAST | WAKE_MCAST | WAKE_BCAST) |
|
2525 |
: 0); |
|
2526 |
if (wol->wolopts & ~support) |
|
2527 |
return -EINVAL; |
|
2528 |
||
2529 |
cfg3 = RTL_R8 (Config3) & ~(Cfg3_LinkUp | Cfg3_Magic); |
|
2530 |
if (wol->wolopts & WAKE_PHY) |
|
2531 |
cfg3 |= Cfg3_LinkUp; |
|
2532 |
if (wol->wolopts & WAKE_MAGIC) |
|
2533 |
cfg3 |= Cfg3_Magic; |
|
2534 |
RTL_W8 (Cfg9346, Cfg9346_Unlock); |
|
2535 |
RTL_W8 (Config3, cfg3); |
|
2536 |
RTL_W8 (Cfg9346, Cfg9346_Lock); |
|
2537 |
||
2538 |
cfg5 = RTL_R8 (Config5) & ~(Cfg5_UWF | Cfg5_MWF | Cfg5_BWF); |
|
2539 |
/* (KON)FIXME: These are untested. We may have to set the |
|
2540 |
CRC0, Wakeup0 and LSBCRC0 registers too, but I have no |
|
2541 |
documentation. */ |
|
2542 |
if (wol->wolopts & WAKE_UCAST) |
|
2543 |
cfg5 |= Cfg5_UWF; |
|
2544 |
if (wol->wolopts & WAKE_MCAST) |
|
2545 |
cfg5 |= Cfg5_MWF; |
|
2546 |
if (wol->wolopts & WAKE_BCAST) |
|
2547 |
cfg5 |= Cfg5_BWF; |
|
2548 |
RTL_W8 (Config5, cfg5); /* need not unlock via Cfg9346 */ |
|
2549 |
||
2550 |
return 0; |
|
2551 |
} |
|
2552 |
||
2553 |
static int netdev_ethtool_ioctl (struct net_device *dev, void *useraddr) |
|
2554 |
{ |
|
2555 |
struct rtl8139_private *np = dev->priv; |
|
2556 |
u32 ethcmd; |
|
2557 |
||
2558 |
/* dev_ioctl() in ../../net/core/dev.c has already checked |
|
2559 |
capable(CAP_NET_ADMIN), so don't bother with that here. */ |
|
2560 |
||
2561 |
if (get_user(ethcmd, (u32 *)useraddr)) |
|
2562 |
return -EFAULT; |
|
2563 |
||
2564 |
switch (ethcmd) { |
|
2565 |
||
2566 |
case ETHTOOL_GDRVINFO: { |
|
2567 |
struct ethtool_drvinfo info = { ETHTOOL_GDRVINFO }; |
|
2568 |
strcpy (info.driver, DRV_NAME); |
|
2569 |
strcpy (info.version, DRV_VERSION); |
|
2570 |
strcpy (info.bus_info, np->pci_dev->slot_name); |
|
2571 |
info.regdump_len = np->regs_len; |
|
2572 |
if (copy_to_user (useraddr, &info, sizeof (info))) |
|
2573 |
return -EFAULT; |
|
2574 |
return 0; |
|
2575 |
} |
|
2576 |
||
2577 |
/* get settings */ |
|
2578 |
case ETHTOOL_GSET: { |
|
2579 |
struct ethtool_cmd ecmd = { ETHTOOL_GSET }; |
|
2580 |
spin_lock_irq(&np->lock); |
|
2581 |
mii_ethtool_gset(&np->mii, &ecmd); |
|
2582 |
spin_unlock_irq(&np->lock); |
|
2583 |
if (copy_to_user(useraddr, &ecmd, sizeof(ecmd))) |
|
2584 |
return -EFAULT; |
|
2585 |
return 0; |
|
2586 |
} |
|
2587 |
/* set settings */ |
|
2588 |
case ETHTOOL_SSET: { |
|
2589 |
int r; |
|
2590 |
struct ethtool_cmd ecmd; |
|
2591 |
if (copy_from_user(&ecmd, useraddr, sizeof(ecmd))) |
|
2592 |
return -EFAULT; |
|
2593 |
spin_lock_irq(&np->lock); |
|
2594 |
r = mii_ethtool_sset(&np->mii, &ecmd); |
|
2595 |
spin_unlock_irq(&np->lock); |
|
2596 |
return r; |
|
2597 |
} |
|
2598 |
/* restart autonegotiation */ |
|
2599 |
case ETHTOOL_NWAY_RST: { |
|
2600 |
return mii_nway_restart(&np->mii); |
|
2601 |
} |
|
2602 |
/* get link status */ |
|
2603 |
case ETHTOOL_GLINK: { |
|
2604 |
struct ethtool_value edata = {ETHTOOL_GLINK}; |
|
2605 |
edata.data = mii_link_ok(&np->mii); |
|
2606 |
if (copy_to_user(useraddr, &edata, sizeof(edata))) |
|
2607 |
return -EFAULT; |
|
2608 |
return 0; |
|
2609 |
} |
|
2610 |
||
2611 |
/* get message-level */ |
|
2612 |
case ETHTOOL_GMSGLVL: { |
|
2613 |
struct ethtool_value edata = {ETHTOOL_GMSGLVL}; |
|
2614 |
edata.data = debug; |
|
2615 |
if (copy_to_user(useraddr, &edata, sizeof(edata))) |
|
2616 |
return -EFAULT; |
|
2617 |
return 0; |
|
2618 |
} |
|
2619 |
/* set message-level */ |
|
2620 |
case ETHTOOL_SMSGLVL: { |
|
2621 |
struct ethtool_value edata; |
|
2622 |
if (copy_from_user(&edata, useraddr, sizeof(edata))) |
|
2623 |
return -EFAULT; |
|
2624 |
debug = edata.data; |
|
2625 |
return 0; |
|
2626 |
} |
|
2627 |
||
2628 |
case ETHTOOL_GWOL: |
|
2629 |
{ |
|
2630 |
struct ethtool_wolinfo wol = { ETHTOOL_GWOL }; |
|
2631 |
spin_lock_irq (&np->lock); |
|
2632 |
netdev_get_wol (dev, &wol); |
|
2633 |
spin_unlock_irq (&np->lock); |
|
2634 |
if (copy_to_user (useraddr, &wol, sizeof (wol))) |
|
2635 |
return -EFAULT; |
|
2636 |
return 0; |
|
2637 |
} |
|
2638 |
||
2639 |
case ETHTOOL_SWOL: |
|
2640 |
{ |
|
2641 |
struct ethtool_wolinfo wol; |
|
2642 |
int rc; |
|
2643 |
if (copy_from_user (&wol, useraddr, sizeof (wol))) |
|
2644 |
return -EFAULT; |
|
2645 |
spin_lock_irq (&np->lock); |
|
2646 |
rc = netdev_set_wol (dev, &wol); |
|
2647 |
spin_unlock_irq (&np->lock); |
|
2648 |
return rc; |
|
2649 |
} |
|
2650 |
||
2651 |
/* TODO: we are too slack to do reg dumping for pio, for now */ |
|
2652 |
#ifndef CONFIG_8139TOO_PIO |
|
2653 |
/* NIC register dump */ |
|
2654 |
case ETHTOOL_GREGS: { |
|
2655 |
struct ethtool_regs regs; |
|
2656 |
unsigned int regs_len = np->regs_len; |
|
2657 |
u8 *regbuf = kmalloc(regs_len, GFP_KERNEL); |
|
2658 |
int rc; |
|
2659 |
||
2660 |
if (!regbuf) |
|
2661 |
return -ENOMEM; |
|
2662 |
memset(regbuf, 0, regs_len); |
|
2663 |
||
2664 |
rc = copy_from_user(®s, useraddr, sizeof(regs)); |
|
2665 |
if (rc) { |
|
2666 |
rc = -EFAULT; |
|
2667 |
goto err_out_gregs; |
|
2668 |
} |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
2669 |
|
0 | 2670 |
if (regs.len > regs_len) |
2671 |
regs.len = regs_len; |
|
2672 |
if (regs.len < regs_len) { |
|
2673 |
rc = -EINVAL; |
|
2674 |
goto err_out_gregs; |
|
2675 |
} |
|
2676 |
||
2677 |
regs.version = RTL_REGS_VER; |
|
2678 |
rc = copy_to_user(useraddr, ®s, sizeof(regs)); |
|
2679 |
if (rc) { |
|
2680 |
rc = -EFAULT; |
|
2681 |
goto err_out_gregs; |
|
2682 |
} |
|
2683 |
||
2684 |
useraddr += offsetof(struct ethtool_regs, data); |
|
2685 |
||
2686 |
spin_lock_irq(&np->lock); |
|
2687 |
memcpy_fromio(regbuf, np->mmio_addr, regs_len); |
|
2688 |
spin_unlock_irq(&np->lock); |
|
2689 |
||
2690 |
if (copy_to_user(useraddr, regbuf, regs_len)) |
|
2691 |
rc = -EFAULT; |
|
2692 |
||
2693 |
err_out_gregs: |
|
2694 |
kfree(regbuf); |
|
2695 |
return rc; |
|
2696 |
} |
|
2697 |
#endif /* CONFIG_8139TOO_PIO */ |
|
2698 |
||
2699 |
/* get string list(s) */ |
|
2700 |
case ETHTOOL_GSTRINGS: { |
|
2701 |
struct ethtool_gstrings estr = { ETHTOOL_GSTRINGS }; |
|
2702 |
||
2703 |
if (copy_from_user(&estr, useraddr, sizeof(estr))) |
|
2704 |
return -EFAULT; |
|
2705 |
if (estr.string_set != ETH_SS_STATS) |
|
2706 |
return -EINVAL; |
|
2707 |
||
2708 |
estr.len = RTL_NUM_STATS; |
|
2709 |
if (copy_to_user(useraddr, &estr, sizeof(estr))) |
|
2710 |
return -EFAULT; |
|
2711 |
if (copy_to_user(useraddr + sizeof(estr), |
|
2712 |
ðtool_stats_keys, |
|
2713 |
sizeof(ethtool_stats_keys))) |
|
2714 |
return -EFAULT; |
|
2715 |
return 0; |
|
2716 |
} |
|
2717 |
||
2718 |
/* get NIC-specific statistics */ |
|
2719 |
case ETHTOOL_GSTATS: { |
|
2720 |
struct ethtool_stats estats = { ETHTOOL_GSTATS }; |
|
2721 |
u64 *tmp_stats; |
|
2722 |
const unsigned int sz = sizeof(u64) * RTL_NUM_STATS; |
|
2723 |
int i; |
|
2724 |
||
2725 |
estats.n_stats = RTL_NUM_STATS; |
|
2726 |
if (copy_to_user(useraddr, &estats, sizeof(estats))) |
|
2727 |
return -EFAULT; |
|
2728 |
||
2729 |
tmp_stats = kmalloc(sz, GFP_KERNEL); |
|
2730 |
if (!tmp_stats) |
|
2731 |
return -ENOMEM; |
|
2732 |
memset(tmp_stats, 0, sz); |
|
2733 |
||
2734 |
i = 0; |
|
2735 |
tmp_stats[i++] = np->xstats.early_rx; |
|
2736 |
tmp_stats[i++] = np->xstats.tx_buf_mapped; |
|
2737 |
tmp_stats[i++] = np->xstats.tx_timeouts; |
|
2738 |
tmp_stats[i++] = np->xstats.rx_lost_in_ring; |
|
2739 |
if (i != RTL_NUM_STATS) |
|
2740 |
BUG(); |
|
2741 |
||
2742 |
i = copy_to_user(useraddr + sizeof(estats), tmp_stats, sz); |
|
2743 |
kfree(tmp_stats); |
|
2744 |
||
2745 |
if (i) |
|
2746 |
return -EFAULT; |
|
2747 |
return 0; |
|
2748 |
} |
|
2749 |
default: |
|
2750 |
break; |
|
2751 |
} |
|
2752 |
||
2753 |
return -EOPNOTSUPP; |
|
2754 |
} |
|
2755 |
||
2756 |
||
2757 |
static int netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) |
|
2758 |
{ |
|
2759 |
struct rtl8139_private *np = dev->priv; |
|
2760 |
struct mii_ioctl_data *data = (struct mii_ioctl_data *) & rq->ifr_data; |
|
2761 |
int rc; |
|
2762 |
||
3
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2763 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2764 |
|
0 | 2765 |
if (dev == rtl_ecat_dev.dev || !netif_running(dev)) |
2766 |
return -EINVAL; |
|
2767 |
||
3
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2768 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
3ea74844c2df
?nderungen der Kommentare und Einr?ckungen von drv_8139.c aus no_rtai 108:110 portiert.
Florian Pose <fp@igh-essen.com>
parents:
1
diff
changeset
|
2769 |
|
0 | 2770 |
if (cmd == SIOCETHTOOL) |
2771 |
rc = netdev_ethtool_ioctl(dev, (void *) rq->ifr_data); |
|
2772 |
||
2773 |
else { |
|
2774 |
spin_lock_irq(&np->lock); |
|
2775 |
rc = generic_mii_ioctl(&np->mii, data, cmd, NULL); |
|
2776 |
spin_unlock_irq(&np->lock); |
|
2777 |
} |
|
2778 |
||
2779 |
return rc; |
|
2780 |
} |
|
2781 |
||
2782 |
||
2783 |
static struct net_device_stats *rtl8139_get_stats (struct net_device *dev) |
|
2784 |
{ |
|
2785 |
struct rtl8139_private *tp = dev->priv; |
|
2786 |
void *ioaddr = tp->mmio_addr; |
|
2787 |
unsigned long flags; |
|
2788 |
||
2789 |
EC_DBG("%s: rtl8139 GETSTATS called...",dev->name); |
|
2790 |
||
4
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2791 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2792 |
|
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
2793 |
if (dev == rtl_ecat_dev.dev || netif_running(dev)) |
4
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2794 |
{ |
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
2795 |
spin_lock_irqsave (&tp->lock, flags); |
4
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2796 |
tp->stats.rx_missed_errors += RTL_R32 (RxMissed); |
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2797 |
RTL_W32 (RxMissed, 0); |
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
2798 |
spin_unlock_irqrestore (&tp->lock, flags); |
4
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2799 |
} |
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2800 |
|
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2801 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
0 | 2802 |
|
2803 |
return &tp->stats; |
|
2804 |
} |
|
2805 |
||
2806 |
/* Set or clear the multicast filter for this adaptor. |
|
2807 |
This routine is not state sensitive and need not be SMP locked. */ |
|
2808 |
||
2809 |
static void __set_rx_mode (struct net_device *dev) |
|
2810 |
{ |
|
2811 |
struct rtl8139_private *tp = dev->priv; |
|
2812 |
void *ioaddr = tp->mmio_addr; |
|
2813 |
u32 mc_filter[2]; /* Multicast hash filter */ |
|
2814 |
int i, rx_mode; |
|
2815 |
u32 tmp; |
|
2816 |
||
2817 |
DPRINTK ("%s: rtl8139_set_rx_mode(%4.4x) done -- Rx config %8.8lx.\n", |
|
2818 |
dev->name, dev->flags, RTL_R32 (RxConfig)); |
|
2819 |
||
2820 |
/* Note: do not reorder, GCC is clever about common statements. */ |
|
2821 |
if (dev->flags & IFF_PROMISC) { |
|
2822 |
/* Unconditionally log net taps. */ |
|
2823 |
EC_DBG (KERN_NOTICE "%s: Promiscuous mode enabled.\n", |
|
2824 |
dev->name); |
|
2825 |
rx_mode = |
|
2826 |
AcceptBroadcast | AcceptMulticast | AcceptMyPhys | |
|
2827 |
AcceptAllPhys; |
|
2828 |
mc_filter[1] = mc_filter[0] = 0xffffffff; |
|
2829 |
} else if ((dev->mc_count > multicast_filter_limit) |
|
2830 |
|| (dev->flags & IFF_ALLMULTI)) { |
|
2831 |
/* Too many to filter perfectly -- accept all multicasts. */ |
|
2832 |
rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; |
|
2833 |
mc_filter[1] = mc_filter[0] = 0xffffffff; |
|
2834 |
} else { |
|
2835 |
struct dev_mc_list *mclist; |
|
2836 |
rx_mode = AcceptBroadcast | AcceptMyPhys; |
|
2837 |
mc_filter[1] = mc_filter[0] = 0; |
|
2838 |
for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count; |
|
2839 |
i++, mclist = mclist->next) { |
|
2840 |
int bit_nr = ether_crc(ETH_ALEN, mclist->dmi_addr) >> 26; |
|
2841 |
||
2842 |
mc_filter[bit_nr >> 5] |= 1 << (bit_nr & 31); |
|
2843 |
rx_mode |= AcceptMulticast; |
|
2844 |
} |
|
2845 |
} |
|
2846 |
||
2847 |
/* We can safely update without stopping the chip. */ |
|
2848 |
tmp = rtl8139_rx_config | rx_mode; |
|
2849 |
if (tp->rx_config != tmp) { |
|
2850 |
RTL_W32_F (RxConfig, tmp); |
|
2851 |
tp->rx_config = tmp; |
|
2852 |
} |
|
2853 |
RTL_W32_F (MAR0 + 0, mc_filter[0]); |
|
2854 |
RTL_W32_F (MAR0 + 4, mc_filter[1]); |
|
2855 |
} |
|
2856 |
||
2857 |
static void rtl8139_set_rx_mode (struct net_device *dev) |
|
2858 |
{ |
|
2859 |
unsigned long flags; |
|
2860 |
struct rtl8139_private *tp = dev->priv; |
|
2861 |
||
5
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
2862 |
spin_lock_irqsave (&tp->lock, flags); |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
2863 |
__set_rx_mode(dev); |
6f2508af550c
Alle ?nderungen aus den Branches no_rtai und no_int nach Trunk portiert.
Florian Pose <fp@igh-essen.com>
parents:
4
diff
changeset
|
2864 |
spin_unlock_irqrestore (&tp->lock, flags); |
0 | 2865 |
} |
2866 |
||
2867 |
#ifdef CONFIG_PM |
|
2868 |
||
2869 |
static int rtl8139_suspend (struct pci_dev *pdev, u32 state) |
|
2870 |
{ |
|
2871 |
struct net_device *dev = pci_get_drvdata (pdev); |
|
2872 |
struct rtl8139_private *tp = dev->priv; |
|
2873 |
void *ioaddr = tp->mmio_addr; |
|
2874 |
unsigned long flags; |
|
2875 |
||
2876 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
2877 |
|
0 | 2878 |
if (dev == rtl_ecat_dev.dev || !netif_running (dev)) |
1
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
2879 |
return 0; |
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
2880 |
|
4
394c89f02e48
Weitere Kommentare in drv_8139too.c portiert.
Florian Pose <fp@igh-essen.com>
parents:
3
diff
changeset
|
2881 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
0 | 2882 |
|
2883 |
netif_device_detach (dev); |
|
2884 |
||
2885 |
spin_lock_irqsave (&tp->lock, flags); |
|
2886 |
||
2887 |
/* Disable interrupts, stop Tx and Rx. */ |
|
2888 |
RTL_W16 (IntrMask, 0); |
|
2889 |
RTL_W8 (ChipCmd, 0); |
|
2890 |
||
2891 |
/* Update the error counts. */ |
|
2892 |
tp->stats.rx_missed_errors += RTL_R32 (RxMissed); |
|
2893 |
RTL_W32 (RxMissed, 0); |
|
2894 |
||
2895 |
spin_unlock_irqrestore (&tp->lock, flags); |
|
2896 |
return 0; |
|
2897 |
} |
|
2898 |
||
2899 |
||
2900 |
static int rtl8139_resume (struct pci_dev *pdev) |
|
2901 |
{ |
|
2902 |
struct net_device *dev = pci_get_drvdata (pdev); |
|
2903 |
||
2904 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
1
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
2905 |
|
0 | 2906 |
if (dev == rtl_ecat_dev.dev || !netif_running (dev)) |
1
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
2907 |
return 0; |
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
2908 |
|
0 | 2909 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
2910 |
||
2911 |
netif_device_attach (dev); |
|
2912 |
||
2913 |
rtl8139_hw_start (dev); |
|
2914 |
return 0; |
|
2915 |
} |
|
2916 |
||
2917 |
#endif /* CONFIG_PM */ |
|
2918 |
||
2919 |
||
2920 |
static struct pci_driver rtl8139_pci_driver = { |
|
2921 |
.name = DRV_NAME, |
|
2922 |
.id_table = rtl8139_pci_tbl, |
|
2923 |
.probe = rtl8139_init_one, |
|
2924 |
.remove = __devexit_p(rtl8139_remove_one), |
|
2925 |
#ifdef CONFIG_PM |
|
2926 |
.suspend = rtl8139_suspend, |
|
2927 |
.resume = rtl8139_resume, |
|
2928 |
#endif /* CONFIG_PM */ |
|
2929 |
}; |
|
2930 |
||
2931 |
||
2932 |
static int rtl8139_init_module (void) |
|
2933 |
{ |
|
2934 |
/* when we're a module, we always print a version message, |
|
2935 |
* even if no 8139 board is found. |
|
2936 |
*/ |
|
2937 |
#ifdef MODULE |
|
2938 |
EC_DBG (KERN_INFO RTL8139_DRIVER_NAME "\n"); |
|
2939 |
#endif |
|
2940 |
||
2941 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
2942 |
||
2943 |
EtherCAT_device_init(&rtl_ecat_dev); |
|
2944 |
||
1
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
2945 |
printk(KERN_DEBUG "Driver rtl_ecat_dev has address %X.\n", |
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
2946 |
(unsigned) &rtl_ecat_dev); |
0 | 2947 |
|
2948 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2949 |
||
2950 |
return pci_module_init (&rtl8139_pci_driver); |
|
2951 |
} |
|
2952 |
||
2953 |
||
2954 |
static void rtl8139_cleanup_module (void) |
|
2955 |
{ |
|
2956 |
pci_unregister_driver (&rtl8139_pci_driver); |
|
2957 |
||
2958 |
/* EtherCAT >>>>>>>>>>>>>>>>>>>>>>>>>>>>*/ |
|
2959 |
||
1
98acc19c7594
Kommentare im 8139-Treiber ge?ndert.
Florian Pose <fp@igh-essen.com>
parents:
0
diff
changeset
|
2960 |
EtherCAT_device_clear(&rtl_ecat_dev); |
0 | 2961 |
|
2962 |
/* EtherCAT <<<<<<<<<<<<<<<<<<<<<<<<<<<<*/ |
|
2963 |
} |
|
2964 |
||
2965 |
||
2966 |
module_init(rtl8139_init_module); |
|
2967 |
module_exit(rtl8139_cleanup_module); |