1 |
1626 |
jcastillo |
/* EtherLinkXL.c: A 3Com EtherLink PCI III/XL ethernet driver for linux. */
|
2 |
|
|
/*
|
3 |
|
|
Written 1996-1998 by Donald Becker.
|
4 |
|
|
|
5 |
|
|
This software may be used and distributed according to the terms
|
6 |
|
|
of the GNU Public License, incorporated herein by reference.
|
7 |
|
|
|
8 |
|
|
This driver is for the 3Com "Vortex" and "Boomerang" series ethercards.
|
9 |
|
|
Members of the series include Fast EtherLink 3c590/3c592/3c595/3c597
|
10 |
|
|
and the EtherLink XL 3c900 and 3c905 cards.
|
11 |
|
|
|
12 |
|
|
The author may be reached as becker@CESDIS.gsfc.nasa.gov, or C/O
|
13 |
|
|
Center of Excellence in Space Data and Information Sciences
|
14 |
|
|
Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
|
15 |
|
|
*/
|
16 |
|
|
|
17 |
|
|
static char *version =
|
18 |
|
|
"3c59x.c:v0.99H 11/17/98 Donald Becker http://cesdis.gsfc.nasa.gov/linux/drivers/vortex.html\n";
|
19 |
|
|
|
20 |
|
|
/* "Knobs" that adjust features and parameters. */
|
21 |
|
|
/* Set the copy breakpoint for the copy-only-tiny-frames scheme.
|
22 |
|
|
Setting to > 1512 effectively disables this feature. */
|
23 |
|
|
static const int rx_copybreak = 200;
|
24 |
|
|
/* Allow setting MTU to a larger size, bypassing the normal ethernet setup. */
|
25 |
|
|
static const int mtu = 1500;
|
26 |
|
|
/* Maximum events (Rx packets, etc.) to handle at each interrupt. */
|
27 |
|
|
static int max_interrupt_work = 20;
|
28 |
|
|
|
29 |
|
|
/* Put out somewhat more debugging messages. (0: no msg, 1 minimal .. 6). */
|
30 |
|
|
#define vortex_debug debug
|
31 |
|
|
#ifdef VORTEX_DEBUG
|
32 |
|
|
static int vortex_debug = VORTEX_DEBUG;
|
33 |
|
|
#else
|
34 |
|
|
static int vortex_debug = 1;
|
35 |
|
|
#endif
|
36 |
|
|
|
37 |
|
|
/* Some values here only for performance evaluation and path-coverage
|
38 |
|
|
debugging. */
|
39 |
|
|
static int rx_nocopy = 0, rx_copy = 0, queued_packet = 0, rx_csumhits;
|
40 |
|
|
|
41 |
|
|
/* A few values that may be tweaked. */
|
42 |
|
|
/* Time in jiffies before concluding the transmitter is hung. */
|
43 |
|
|
#define TX_TIMEOUT ((400*HZ)/1000)
|
44 |
|
|
|
45 |
|
|
/* Keep the ring sizes a power of two for efficiency. */
|
46 |
|
|
#define TX_RING_SIZE 16
|
47 |
|
|
#define RX_RING_SIZE 32
|
48 |
|
|
#define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/
|
49 |
|
|
|
50 |
|
|
#include <linux/config.h>
|
51 |
|
|
#include <linux/version.h>
|
52 |
|
|
#ifdef MODULE
|
53 |
|
|
#ifdef MODVERSIONS
|
54 |
|
|
#include <linux/modversions.h>
|
55 |
|
|
#endif
|
56 |
|
|
#include <linux/module.h>
|
57 |
|
|
#else
|
58 |
|
|
#define MOD_INC_USE_COUNT
|
59 |
|
|
#define MOD_DEC_USE_COUNT
|
60 |
|
|
#endif
|
61 |
|
|
|
62 |
|
|
#include <linux/kernel.h>
|
63 |
|
|
#include <linux/sched.h>
|
64 |
|
|
#include <linux/string.h>
|
65 |
|
|
#include <linux/timer.h>
|
66 |
|
|
#include <linux/errno.h>
|
67 |
|
|
#include <linux/in.h>
|
68 |
|
|
#include <linux/ioport.h>
|
69 |
|
|
#include <linux/malloc.h>
|
70 |
|
|
#include <linux/interrupt.h>
|
71 |
|
|
#include <linux/pci.h>
|
72 |
|
|
#include <linux/netdevice.h>
|
73 |
|
|
#include <linux/etherdevice.h>
|
74 |
|
|
#include <linux/skbuff.h>
|
75 |
|
|
#if LINUX_VERSION_CODE < 0x20155 || defined(CARDBUS)
|
76 |
|
|
#include <linux/bios32.h>
|
77 |
|
|
#endif
|
78 |
|
|
#include <asm/irq.h> /* For NR_IRQS only. */
|
79 |
|
|
#include <asm/bitops.h>
|
80 |
|
|
#include <asm/io.h>
|
81 |
|
|
|
82 |
|
|
/* Kernel compatibility defines, some common to David Hinds' PCMCIA package.
|
83 |
|
|
This is only in the support-all-kernels source code. */
|
84 |
|
|
|
85 |
|
|
#define RUN_AT(x) (jiffies + (x))
|
86 |
|
|
|
87 |
|
|
#include <linux/delay.h>
|
88 |
|
|
|
89 |
|
|
#if (LINUX_VERSION_CODE >= 0x20100)
|
90 |
|
|
char kernel_version[] = UTS_RELEASE;
|
91 |
|
|
#else
|
92 |
|
|
#ifndef __alpha__
|
93 |
|
|
#define ioremap(a,b) \
|
94 |
|
|
(((a)<0x100000) ? (void *)((u_long)(a)) : vremap(a,b))
|
95 |
|
|
#define iounmap(v) \
|
96 |
|
|
do { if ((u_long)(v) > 0x100000) vfree(v); } while (0)
|
97 |
|
|
#endif
|
98 |
|
|
#endif
|
99 |
|
|
#if LINUX_VERSION_CODE <= 0x20139
|
100 |
|
|
#define net_device_stats enet_statistics
|
101 |
|
|
#define NETSTATS_VER2
|
102 |
|
|
#endif
|
103 |
|
|
#if LINUX_VERSION_CODE < 0x20138
|
104 |
|
|
#define test_and_set_bit(val, addr) set_bit(val, addr)
|
105 |
|
|
#define le32_to_cpu(val) (val)
|
106 |
|
|
#define cpu_to_le32(val) (val)
|
107 |
|
|
#endif
|
108 |
|
|
#if LINUX_VERSION_CODE < 0x20155
|
109 |
|
|
#define PCI_SUPPORT_VER1
|
110 |
|
|
#else
|
111 |
|
|
#define PCI_SUPPORT_VER2
|
112 |
|
|
#endif
|
113 |
|
|
#if LINUX_VERSION_CODE < 0x20159
|
114 |
|
|
#define DEV_FREE_SKB(skb) dev_kfree_skb (skb, FREE_WRITE);
|
115 |
|
|
#else /* Grrr, unneeded incompatible change. */
|
116 |
|
|
#define DEV_FREE_SKB(skb) dev_kfree_skb(skb);
|
117 |
|
|
#endif
|
118 |
|
|
|
119 |
|
|
#if defined(MODULE) && LINUX_VERSION_CODE > 0x20115
|
120 |
|
|
MODULE_AUTHOR("Donald Becker <becker@cesdis.gsfc.nasa.gov>");
|
121 |
|
|
MODULE_DESCRIPTION("3Com 3c590/3c900 series Vortex/Boomerang driver");
|
122 |
|
|
MODULE_PARM(debug, "i");
|
123 |
|
|
MODULE_PARM(options, "1-" __MODULE_STRING(8) "i");
|
124 |
|
|
MODULE_PARM(full_duplex, "1-" __MODULE_STRING(8) "i");
|
125 |
|
|
MODULE_PARM(rx_copybreak, "i");
|
126 |
|
|
MODULE_PARM(max_interrupt_work, "i");
|
127 |
|
|
MODULE_PARM(compaq_ioaddr, "i");
|
128 |
|
|
MODULE_PARM(compaq_irq, "i");
|
129 |
|
|
MODULE_PARM(compaq_device_id, "i");
|
130 |
|
|
#endif
|
131 |
|
|
|
132 |
|
|
/* Operational parameter that usually are not changed. */
|
133 |
|
|
|
134 |
|
|
/* The Vortex size is twice that of the original EtherLinkIII series: the
|
135 |
|
|
runtime register window, window 1, is now always mapped in.
|
136 |
|
|
The Boomerang size is twice as large as the Vortex -- it has additional
|
137 |
|
|
bus master control registers. */
|
138 |
|
|
#define VORTEX_TOTAL_SIZE 0x20
|
139 |
|
|
#define BOOMERANG_TOTAL_SIZE 0x40
|
140 |
|
|
|
141 |
|
|
/* Set iff a MII transceiver on any interface requires mdio preamble.
|
142 |
|
|
This only set with the original DP83840 on older 3c905 boards, so the extra
|
143 |
|
|
code size of a per-interface flag is not worthwhile. */
|
144 |
|
|
static char mii_preamble_required = 0;
|
145 |
|
|
|
146 |
|
|
/*
|
147 |
|
|
Theory of Operation
|
148 |
|
|
|
149 |
|
|
I. Board Compatibility
|
150 |
|
|
|
151 |
|
|
This device driver is designed for the 3Com FastEtherLink and FastEtherLink
|
152 |
|
|
XL, 3Com's PCI to 10/100baseT adapters. It also works with the 10Mbs
|
153 |
|
|
versions of the FastEtherLink cards. The supported product IDs are
|
154 |
|
|
3c590, 3c592, 3c595, 3c597, 3c900, 3c905
|
155 |
|
|
|
156 |
|
|
The related ISA 3c515 is supported with a separate driver, 3c515.c, included
|
157 |
|
|
with the kernel source or available from
|
158 |
|
|
cesdis.gsfc.nasa.gov:/pub/linux/drivers/3c515.html
|
159 |
|
|
|
160 |
|
|
II. Board-specific settings
|
161 |
|
|
|
162 |
|
|
PCI bus devices are configured by the system at boot time, so no jumpers
|
163 |
|
|
need to be set on the board. The system BIOS should be set to assign the
|
164 |
|
|
PCI INTA signal to an otherwise unused system IRQ line.
|
165 |
|
|
|
166 |
|
|
The EEPROM settings for media type and forced-full-duplex are observed.
|
167 |
|
|
The EEPROM media type should be left at the default "autoselect" unless using
|
168 |
|
|
10base2 or AUI connections which cannot be reliably detected.
|
169 |
|
|
|
170 |
|
|
III. Driver operation
|
171 |
|
|
|
172 |
|
|
The 3c59x series use an interface that's very similar to the previous 3c5x9
|
173 |
|
|
series. The primary interface is two programmed-I/O FIFOs, with an
|
174 |
|
|
alternate single-contiguous-region bus-master transfer (see next).
|
175 |
|
|
|
176 |
|
|
The 3c900 "Boomerang" series uses a full-bus-master interface with separate
|
177 |
|
|
lists of transmit and receive descriptors, similar to the AMD LANCE/PCnet,
|
178 |
|
|
DEC Tulip and Intel Speedo3. The first chip version retains a compatible
|
179 |
|
|
programmed-I/O interface that has been removed in 'B' and subsequent board
|
180 |
|
|
revisions.
|
181 |
|
|
|
182 |
|
|
One extension that is advertised in a very large font is that the adapters
|
183 |
|
|
are capable of being bus masters. On the Vortex chip this capability was
|
184 |
|
|
only for a single contiguous region making it far less useful than the full
|
185 |
|
|
bus master capability. There is a significant performance impact of taking
|
186 |
|
|
an extra interrupt or polling for the completion of each transfer, as well
|
187 |
|
|
as difficulty sharing the single transfer engine between the transmit and
|
188 |
|
|
receive threads. Using DMA transfers is a win only with large blocks or
|
189 |
|
|
with the flawed versions of the Intel Orion motherboard PCI controller.
|
190 |
|
|
|
191 |
|
|
The Boomerang chip's full-bus-master interface is useful, and has the
|
192 |
|
|
currently-unused advantages over other similar chips that queued transmit
|
193 |
|
|
packets may be reordered and receive buffer groups are associated with a
|
194 |
|
|
single frame.
|
195 |
|
|
|
196 |
|
|
With full-bus-master support, this driver uses a "RX_COPYBREAK" scheme.
|
197 |
|
|
Rather than a fixed intermediate receive buffer, this scheme allocates
|
198 |
|
|
full-sized skbuffs as receive buffers. The value RX_COPYBREAK is used as
|
199 |
|
|
the copying breakpoint: it is chosen to trade-off the memory wasted by
|
200 |
|
|
passing the full-sized skbuff to the queue layer for all frames vs. the
|
201 |
|
|
copying cost of copying a frame to a correctly-sized skbuff.
|
202 |
|
|
|
203 |
|
|
|
204 |
|
|
IIIC. Synchronization
|
205 |
|
|
The driver runs as two independent, single-threaded flows of control. One
|
206 |
|
|
is the send-packet routine, which enforces single-threaded use by the
|
207 |
|
|
dev->tbusy flag. The other thread is the interrupt handler, which is single
|
208 |
|
|
threaded by the hardware and other software.
|
209 |
|
|
|
210 |
|
|
IV. Notes
|
211 |
|
|
|
212 |
|
|
Thanks to Cameron Spitzer and Terry Murphy of 3Com for providing development
|
213 |
|
|
3c590, 3c595, and 3c900 boards.
|
214 |
|
|
The name "Vortex" is the internal 3Com project name for the PCI ASIC, and
|
215 |
|
|
the EISA version is called "Demon". According to Terry these names come
|
216 |
|
|
from rides at the local amusement park.
|
217 |
|
|
|
218 |
|
|
The new chips support both ethernet (1.5K) and FDDI (4.5K) packet sizes!
|
219 |
|
|
This driver only supports ethernet packets because of the skbuff allocation
|
220 |
|
|
limit of 4K.
|
221 |
|
|
*/
|
222 |
|
|
|
223 |
|
|
/* This table drives the PCI probe routines. It's mostly boilerplate in all
|
224 |
|
|
of the drivers, and will likely be provided by some future kernel.
|
225 |
|
|
*/
|
226 |
|
|
enum pci_flags_bit {
|
227 |
|
|
PCI_USES_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4,
|
228 |
|
|
PCI_ADDR0=0x10<<0, PCI_ADDR1=0x10<<1, PCI_ADDR2=0x10<<2, PCI_ADDR3=0x10<<3,
|
229 |
|
|
};
|
230 |
|
|
struct pci_id_info {
|
231 |
|
|
const char *name;
|
232 |
|
|
u16 vendor_id, device_id, device_id_mask, flags;
|
233 |
|
|
int drv_flags, io_size;
|
234 |
|
|
struct device *(*probe1)(int pci_bus, int pci_devfn, struct device *dev,
|
235 |
|
|
long ioaddr, int irq, int chip_idx, int fnd_cnt);
|
236 |
|
|
};
|
237 |
|
|
|
238 |
|
|
enum { IS_VORTEX=1, IS_BOOMERANG=2, IS_CYCLONE=4,
|
239 |
|
|
HAS_PWR_CTRL=0x10, HAS_MII=0x20, HAS_NWAY=0x40, HAS_CB_FNS=0x80, };
|
240 |
|
|
static struct device *vortex_probe1(int pci_bus, int pci_devfn,
|
241 |
|
|
struct device *dev, long ioaddr,
|
242 |
|
|
int irq, int dev_id, int card_idx);
|
243 |
|
|
static struct pci_id_info pci_tbl[] = {
|
244 |
|
|
{"3c590 Vortex 10Mbps", 0x10B7, 0x5900, 0xffff,
|
245 |
|
|
PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, vortex_probe1},
|
246 |
|
|
{"3c595 Vortex 100baseTx", 0x10B7, 0x5950, 0xffff,
|
247 |
|
|
PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, vortex_probe1},
|
248 |
|
|
{"3c595 Vortex 100baseT4", 0x10B7, 0x5951, 0xffff,
|
249 |
|
|
PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, vortex_probe1},
|
250 |
|
|
{"3c595 Vortex 100base-MII", 0x10B7, 0x5952, 0xffff,
|
251 |
|
|
PCI_USES_IO|PCI_USES_MASTER, IS_VORTEX, 32, vortex_probe1},
|
252 |
|
|
{"3Com Vortex", 0x10B7, 0x5900, 0xff00,
|
253 |
|
|
PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG, 64, vortex_probe1},
|
254 |
|
|
{"3c900 Boomerang 10baseT", 0x10B7, 0x9000, 0xffff,
|
255 |
|
|
PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG, 64, vortex_probe1},
|
256 |
|
|
{"3c900 Boomerang 10Mbps Combo", 0x10B7, 0x9001, 0xffff,
|
257 |
|
|
PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG, 64, vortex_probe1},
|
258 |
|
|
{"3c900 Cyclone 10Mbps Combo", 0x10B7, 0x9005, 0xffff,
|
259 |
|
|
PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, vortex_probe1},
|
260 |
|
|
{"3c900B-FL Cyclone 10base-FL", 0x10B7, 0x900A, 0xffff,
|
261 |
|
|
PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, vortex_probe1},
|
262 |
|
|
{"3c905 Boomerang 100baseTx", 0x10B7, 0x9050, 0xffff,
|
263 |
|
|
PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII, 64, vortex_probe1},
|
264 |
|
|
{"3c905 Boomerang 100baseT4", 0x10B7, 0x9051, 0xffff,
|
265 |
|
|
PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII, 64, vortex_probe1},
|
266 |
|
|
{"3c905B Cyclone 100baseTx", 0x10B7, 0x9055, 0xffff,
|
267 |
|
|
PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY, 128, vortex_probe1},
|
268 |
|
|
{"3c905B-FX Cyclone 100baseFx", 0x10B7, 0x905A, 0xffff,
|
269 |
|
|
PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, vortex_probe1},
|
270 |
|
|
{"3c980 Cyclone", 0x10B7, 0x9800, 0xfff0,
|
271 |
|
|
PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE, 128, vortex_probe1},
|
272 |
|
|
{"3c575 Boomerang CardBus", 0x10B7, 0x5057, 0xffff,
|
273 |
|
|
PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII, 64, vortex_probe1},
|
274 |
|
|
{"3CCFE575 Cyclone CardBus", 0x10B7, 0x5157, 0xffff,
|
275 |
|
|
PCI_USES_IO|PCI_USES_MASTER, IS_CYCLONE|HAS_NWAY|HAS_CB_FNS,
|
276 |
|
|
128, vortex_probe1},
|
277 |
|
|
{"3c575 series CardBus (unknown version)", 0x10B7, 0x5057, 0xf0ff,
|
278 |
|
|
PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG|HAS_MII, 64, vortex_probe1},
|
279 |
|
|
{"3Com Boomerang (unknown version)", 0x10B7, 0x9000, 0xff00,
|
280 |
|
|
PCI_USES_IO|PCI_USES_MASTER, IS_BOOMERANG, 64, vortex_probe1},
|
281 |
|
|
{0,}, /* 0 terminated list. */
|
282 |
|
|
};
|
283 |
|
|
|
284 |
|
|
/* Operational definitions.
|
285 |
|
|
These are not used by other compilation units and thus are not
|
286 |
|
|
exported in a ".h" file.
|
287 |
|
|
|
288 |
|
|
First the windows. There are eight register windows, with the command
|
289 |
|
|
and status registers available in each.
|
290 |
|
|
*/
|
291 |
|
|
#define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
|
292 |
|
|
#define EL3_CMD 0x0e
|
293 |
|
|
#define EL3_STATUS 0x0e
|
294 |
|
|
|
295 |
|
|
/* The top five bits written to EL3_CMD are a command, the lower
|
296 |
|
|
11 bits are the parameter, if applicable.
|
297 |
|
|
Note that 11 parameters bits was fine for ethernet, but the new chip
|
298 |
|
|
can handle FDDI length frames (~4500 octets) and now parameters count
|
299 |
|
|
32-bit 'Dwords' rather than octets. */
|
300 |
|
|
|
301 |
|
|
enum vortex_cmd {
|
302 |
|
|
TotalReset = 0<<11, SelectWindow = 1<<11, StartCoax = 2<<11,
|
303 |
|
|
RxDisable = 3<<11, RxEnable = 4<<11, RxReset = 5<<11,
|
304 |
|
|
UpStall = 6<<11, UpUnstall = (6<<11)+1,
|
305 |
|
|
DownStall = (6<<11)+2, DownUnstall = (6<<11)+3,
|
306 |
|
|
RxDiscard = 8<<11, TxEnable = 9<<11, TxDisable = 10<<11, TxReset = 11<<11,
|
307 |
|
|
FakeIntr = 12<<11, AckIntr = 13<<11, SetIntrEnb = 14<<11,
|
308 |
|
|
SetStatusEnb = 15<<11, SetRxFilter = 16<<11, SetRxThreshold = 17<<11,
|
309 |
|
|
SetTxThreshold = 18<<11, SetTxStart = 19<<11,
|
310 |
|
|
StartDMAUp = 20<<11, StartDMADown = (20<<11)+1, StatsEnable = 21<<11,
|
311 |
|
|
StatsDisable = 22<<11, StopCoax = 23<<11, SetFilterBit = 25<<11,};
|
312 |
|
|
|
313 |
|
|
/* The SetRxFilter command accepts the following classes: */
|
314 |
|
|
enum RxFilter {
|
315 |
|
|
RxStation = 1, RxMulticast = 2, RxBroadcast = 4, RxProm = 8 };
|
316 |
|
|
|
317 |
|
|
/* Bits in the general status register. */
|
318 |
|
|
enum vortex_status {
|
319 |
|
|
IntLatch = 0x0001, HostError = 0x0002, TxComplete = 0x0004,
|
320 |
|
|
TxAvailable = 0x0008, RxComplete = 0x0010, RxEarly = 0x0020,
|
321 |
|
|
IntReq = 0x0040, StatsFull = 0x0080,
|
322 |
|
|
DMADone = 1<<8, DownComplete = 1<<9, UpComplete = 1<<10,
|
323 |
|
|
DMAInProgress = 1<<11, /* DMA controller is still busy.*/
|
324 |
|
|
CmdInProgress = 1<<12, /* EL3_CMD is still busy.*/
|
325 |
|
|
};
|
326 |
|
|
|
327 |
|
|
/* Register window 1 offsets, the window used in normal operation.
|
328 |
|
|
On the Vortex this window is always mapped at offsets 0x10-0x1f. */
|
329 |
|
|
enum Window1 {
|
330 |
|
|
TX_FIFO = 0x10, RX_FIFO = 0x10, RxErrors = 0x14,
|
331 |
|
|
RxStatus = 0x18, Timer=0x1A, TxStatus = 0x1B,
|
332 |
|
|
TxFree = 0x1C, /* Remaining free bytes in Tx buffer. */
|
333 |
|
|
};
|
334 |
|
|
enum Window0 {
|
335 |
|
|
Wn0EepromCmd = 10, /* Window 0: EEPROM command register. */
|
336 |
|
|
Wn0EepromData = 12, /* Window 0: EEPROM results register. */
|
337 |
|
|
IntrStatus=0x0E, /* Valid in all windows. */
|
338 |
|
|
};
|
339 |
|
|
enum Win0_EEPROM_bits {
|
340 |
|
|
EEPROM_Read = 0x80, EEPROM_WRITE = 0x40, EEPROM_ERASE = 0xC0,
|
341 |
|
|
EEPROM_EWENB = 0x30, /* Enable erasing/writing for 10 msec. */
|
342 |
|
|
EEPROM_EWDIS = 0x00, /* Disable EWENB before 10 msec timeout. */
|
343 |
|
|
};
|
344 |
|
|
/* EEPROM locations. */
|
345 |
|
|
enum eeprom_offset {
|
346 |
|
|
PhysAddr01=0, PhysAddr23=1, PhysAddr45=2, ModelID=3,
|
347 |
|
|
EtherLink3ID=7, IFXcvrIO=8, IRQLine=9,
|
348 |
|
|
NodeAddr01=10, NodeAddr23=11, NodeAddr45=12,
|
349 |
|
|
DriverTune=13, Checksum=15};
|
350 |
|
|
|
351 |
|
|
enum Window2 { /* Window 2. */
|
352 |
|
|
Wn2_ResetOptions=12,
|
353 |
|
|
};
|
354 |
|
|
enum Window3 { /* Window 3: MAC/config bits. */
|
355 |
|
|
Wn3_Config=0, Wn3_MAC_Ctrl=6, Wn3_Options=8,
|
356 |
|
|
};
|
357 |
|
|
union wn3_config {
|
358 |
|
|
int i;
|
359 |
|
|
struct w3_config_fields {
|
360 |
|
|
unsigned int ram_size:3, ram_width:1, ram_speed:2, rom_size:2;
|
361 |
|
|
int pad8:8;
|
362 |
|
|
unsigned int ram_split:2, pad18:2, xcvr:4, autoselect:1;
|
363 |
|
|
int pad24:7;
|
364 |
|
|
} u;
|
365 |
|
|
};
|
366 |
|
|
|
367 |
|
|
enum Window4 { /* Window 4: Xcvr/media bits. */
|
368 |
|
|
Wn4_FIFODiag = 4, Wn4_NetDiag = 6, Wn4_PhysicalMgmt=8, Wn4_Media = 10,
|
369 |
|
|
};
|
370 |
|
|
enum Win4_Media_bits {
|
371 |
|
|
Media_SQE = 0x0008, /* Enable SQE error counting for AUI. */
|
372 |
|
|
Media_10TP = 0x00C0, /* Enable link beat and jabber for 10baseT. */
|
373 |
|
|
Media_Lnk = 0x0080, /* Enable just link beat for 100TX/100FX. */
|
374 |
|
|
Media_LnkBeat = 0x0800,
|
375 |
|
|
};
|
376 |
|
|
enum Window7 { /* Window 7: Bus Master control. */
|
377 |
|
|
Wn7_MasterAddr = 0, Wn7_MasterLen = 6, Wn7_MasterStatus = 12,
|
378 |
|
|
};
|
379 |
|
|
/* Boomerang bus master control registers. */
|
380 |
|
|
enum MasterCtrl {
|
381 |
|
|
PktStatus = 0x20, DownListPtr = 0x24, FragAddr = 0x28, FragLen = 0x2c,
|
382 |
|
|
TxFreeThreshold = 0x2f, UpPktStatus = 0x30, UpListPtr = 0x38,
|
383 |
|
|
};
|
384 |
|
|
|
385 |
|
|
/* The Rx and Tx descriptor lists.
|
386 |
|
|
Caution Alpha hackers: these types are 32 bits! Note also the 8 byte
|
387 |
|
|
alignment contraint on tx_ring[] and rx_ring[]. */
|
388 |
|
|
#define LAST_FRAG 0x80000000 /* Last Addr/Len pair in descriptor. */
|
389 |
|
|
struct boom_rx_desc {
|
390 |
|
|
u32 next; /* Last entry points to 0. */
|
391 |
|
|
s32 status;
|
392 |
|
|
u32 addr; /* Up to 63 addr/len pairs possible. */
|
393 |
|
|
s32 length; /* Set LAST_FRAG to indicate last pair. */
|
394 |
|
|
};
|
395 |
|
|
/* Values for the Rx status entry. */
|
396 |
|
|
enum rx_desc_status {
|
397 |
|
|
RxDComplete=0x00008000, RxDError=0x4000,
|
398 |
|
|
/* See boomerang_rx() for actual error bits */
|
399 |
|
|
IPChksumErr=1<<25, TCPChksumErr=1<<26, UDPChksumErr=1<<27,
|
400 |
|
|
IPChksumValid=1<<29, TCPChksumValid=1<<30, UDPChksumValid=1<<31,
|
401 |
|
|
};
|
402 |
|
|
|
403 |
|
|
struct boom_tx_desc {
|
404 |
|
|
u32 next; /* Last entry points to 0. */
|
405 |
|
|
s32 status; /* bits 0:12 length, others see below. */
|
406 |
|
|
u32 addr;
|
407 |
|
|
s32 length;
|
408 |
|
|
};
|
409 |
|
|
|
410 |
|
|
/* Values for the Tx status entry. */
|
411 |
|
|
enum tx_desc_status {
|
412 |
|
|
CRCDisable=0x2000, TxDComplete=0x8000,
|
413 |
|
|
AddIPChksum=0x02000000, AddTCPChksum=0x04000000, AddUDPChksum=0x08000000,
|
414 |
|
|
TxIntrUploaded=0x80000000, /* IRQ when in FIFO, but maybe not sent. */
|
415 |
|
|
};
|
416 |
|
|
|
417 |
|
|
/* Chip features we care about in vp->capabilities, read from the EEPROM. */
|
418 |
|
|
enum ChipCaps { CapBusMaster=0x20 };
|
419 |
|
|
|
420 |
|
|
struct vortex_private {
|
421 |
|
|
/* The Rx and Tx rings should be quad-word-aligned. */
|
422 |
|
|
struct boom_rx_desc rx_ring[RX_RING_SIZE];
|
423 |
|
|
struct boom_tx_desc tx_ring[TX_RING_SIZE];
|
424 |
|
|
/* The addresses of transmit- and receive-in-place skbuffs. */
|
425 |
|
|
struct sk_buff* rx_skbuff[RX_RING_SIZE];
|
426 |
|
|
struct sk_buff* tx_skbuff[TX_RING_SIZE];
|
427 |
|
|
struct device *next_module;
|
428 |
|
|
void *priv_addr;
|
429 |
|
|
unsigned int cur_rx, cur_tx; /* The next free ring entry */
|
430 |
|
|
unsigned int dirty_rx, dirty_tx; /* The ring entries to be free()ed. */
|
431 |
|
|
struct net_device_stats stats;
|
432 |
|
|
struct sk_buff *tx_skb; /* Packet being eaten by bus master ctrl. */
|
433 |
|
|
|
434 |
|
|
/* PCI configuration space information. */
|
435 |
|
|
u8 pci_bus, pci_devfn; /* PCI bus location, for power management. */
|
436 |
|
|
char *cb_fn_base; /* CardBus function status addr space. */
|
437 |
|
|
int chip_id;
|
438 |
|
|
|
439 |
|
|
/* The remainder are related to chip state, mostly media selection. */
|
440 |
|
|
unsigned long in_interrupt;
|
441 |
|
|
struct timer_list timer; /* Media selection timer. */
|
442 |
|
|
int options; /* User-settable misc. driver options. */
|
443 |
|
|
unsigned int media_override:3, /* Passed-in media type. */
|
444 |
|
|
default_media:4, /* Read from the EEPROM/Wn3_Config. */
|
445 |
|
|
full_duplex:1, force_fd:1, autoselect:1,
|
446 |
|
|
bus_master:1, /* Vortex can only do a fragment bus-m. */
|
447 |
|
|
full_bus_master_tx:1, full_bus_master_rx:2, /* Boomerang */
|
448 |
|
|
hw_csums:1, /* Has hardware checksums. */
|
449 |
|
|
tx_full:1;
|
450 |
|
|
u16 status_enable;
|
451 |
|
|
u16 intr_enable;
|
452 |
|
|
u16 available_media; /* From Wn3_Options. */
|
453 |
|
|
u16 capabilities, info1, info2; /* Various, from EEPROM. */
|
454 |
|
|
u16 advertising; /* NWay media advertisement */
|
455 |
|
|
unsigned char phys[2]; /* MII device addresses. */
|
456 |
|
|
};
|
457 |
|
|
|
458 |
|
|
/* The action to take with a media selection timer tick.
|
459 |
|
|
Note that we deviate from the 3Com order by checking 10base2 before AUI.
|
460 |
|
|
*/
|
461 |
|
|
enum xcvr_types {
|
462 |
|
|
XCVR_10baseT=0, XCVR_AUI, XCVR_10baseTOnly, XCVR_10base2, XCVR_100baseTx,
|
463 |
|
|
XCVR_100baseFx, XCVR_MII=6, XCVR_NWAY=8, XCVR_ExtMII=9, XCVR_Default=10,
|
464 |
|
|
};
|
465 |
|
|
|
466 |
|
|
static struct media_table {
|
467 |
|
|
char *name;
|
468 |
|
|
unsigned int media_bits:16, /* Bits to set in Wn4_Media register. */
|
469 |
|
|
mask:8, /* The transceiver-present bit in Wn3_Config.*/
|
470 |
|
|
next:8; /* The media type to try next. */
|
471 |
|
|
int wait; /* Time before we check media status. */
|
472 |
|
|
} media_tbl[] = {
|
473 |
|
|
{ "10baseT", Media_10TP,0x08, XCVR_10base2, (14*HZ)/10},
|
474 |
|
|
{ "10Mbs AUI", Media_SQE, 0x20, XCVR_Default, (1*HZ)/10},
|
475 |
|
|
{ "undefined", 0, 0x80, XCVR_10baseT, 10000},
|
476 |
|
|
{ "10base2", 0, 0x10, XCVR_AUI, (1*HZ)/10},
|
477 |
|
|
{ "100baseTX", Media_Lnk, 0x02, XCVR_100baseFx, (14*HZ)/10},
|
478 |
|
|
{ "100baseFX", Media_Lnk, 0x04, XCVR_MII, (14*HZ)/10},
|
479 |
|
|
{ "MII", 0, 0x41, XCVR_10baseT, 3*HZ },
|
480 |
|
|
{ "undefined", 0, 0x01, XCVR_10baseT, 10000},
|
481 |
|
|
{ "Autonegotiate", 0, 0x41, XCVR_10baseT, 3*HZ},
|
482 |
|
|
{ "MII-External", 0, 0x41, XCVR_10baseT, 3*HZ },
|
483 |
|
|
{ "Default", 0, 0xFF, XCVR_10baseT, 10000},
|
484 |
|
|
};
|
485 |
|
|
|
486 |
|
|
#ifndef CARDBUS
|
487 |
|
|
static int vortex_scan(struct device *dev, struct pci_id_info pci_tbl[]);
|
488 |
|
|
#endif
|
489 |
|
|
static int vortex_open(struct device *dev);
|
490 |
|
|
static void mdio_sync(long ioaddr, int bits);
|
491 |
|
|
static int mdio_read(long ioaddr, int phy_id, int location);
|
492 |
|
|
static void mdio_write(long ioaddr, int phy_id, int location, int value);
|
493 |
|
|
static void vortex_timer(unsigned long arg);
|
494 |
|
|
static int vortex_start_xmit(struct sk_buff *skb, struct device *dev);
|
495 |
|
|
static int boomerang_start_xmit(struct sk_buff *skb, struct device *dev);
|
496 |
|
|
static int vortex_rx(struct device *dev);
|
497 |
|
|
static int boomerang_rx(struct device *dev);
|
498 |
|
|
static void vortex_interrupt(int irq, void *dev_id, struct pt_regs *regs);
|
499 |
|
|
static int vortex_close(struct device *dev);
|
500 |
|
|
static void update_stats(long ioaddr, struct device *dev);
|
501 |
|
|
static struct net_device_stats *vortex_get_stats(struct device *dev);
|
502 |
|
|
static void set_rx_mode(struct device *dev);
|
503 |
|
|
static int vortex_ioctl(struct device *dev, struct ifreq *rq, int cmd);
|
504 |
|
|
|
505 |
|
|
|
506 |
|
|
/* This driver uses 'options' to pass the media type, full-duplex flag, etc. */
|
507 |
|
|
/* Option count limit only -- unlimited interfaces are supported. */
|
508 |
|
|
#define MAX_UNITS 8
|
509 |
|
|
static int options[MAX_UNITS] = { -1, -1, -1, -1, -1, -1, -1, -1,};
|
510 |
|
|
static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1};
|
511 |
|
|
/* A list of all installed Vortex devices, for removing the driver module. */
|
512 |
|
|
static struct device *root_vortex_dev = NULL;
|
513 |
|
|
|
514 |
|
|
#ifdef MODULE
|
515 |
|
|
#ifndef CARDBUS
|
516 |
|
|
/* Variables to work-around the Compaq PCI BIOS32 problem. */
|
517 |
|
|
static int compaq_ioaddr = 0, compaq_irq = 0, compaq_device_id = 0x5900;
|
518 |
|
|
#endif
|
519 |
|
|
|
520 |
|
|
#ifdef CARDBUS
|
521 |
|
|
|
522 |
|
|
#include <pcmcia/driver_ops.h>
|
523 |
|
|
|
524 |
|
|
static dev_node_t *vortex_attach(dev_locator_t *loc)
|
525 |
|
|
{
|
526 |
|
|
u16 dev_id, vendor_id;
|
527 |
|
|
u32 io;
|
528 |
|
|
u8 bus, devfn, irq;
|
529 |
|
|
struct device *dev;
|
530 |
|
|
int chip_idx;
|
531 |
|
|
|
532 |
|
|
if (loc->bus != LOC_PCI) return NULL;
|
533 |
|
|
bus = loc->b.pci.bus; devfn = loc->b.pci.devfn;
|
534 |
|
|
pcibios_read_config_dword(bus, devfn, PCI_BASE_ADDRESS_0, &io);
|
535 |
|
|
pcibios_read_config_byte(bus, devfn, PCI_INTERRUPT_LINE, &irq);
|
536 |
|
|
pcibios_read_config_word(bus, devfn, PCI_VENDOR_ID, &vendor_id);
|
537 |
|
|
pcibios_read_config_word(bus, devfn, PCI_DEVICE_ID, &dev_id);
|
538 |
|
|
printk(KERN_INFO "vortex_attach(bus %d, function %d, device %4.4x)\n",
|
539 |
|
|
bus, devfn, dev_id);
|
540 |
|
|
io &= ~3;
|
541 |
|
|
if (io == 0 || irq == 0) {
|
542 |
|
|
printk(KERN_ERR "The 3Com CardBus Ethernet interface was not "
|
543 |
|
|
"assigned an %s.\n" KERN_ERR " It will not be activated.\n",
|
544 |
|
|
io == 0 ? "I/O address" : "IRQ");
|
545 |
|
|
return NULL;
|
546 |
|
|
}
|
547 |
|
|
for (chip_idx = 0; pci_tbl[chip_idx].vendor_id; chip_idx++)
|
548 |
|
|
if (vendor_id == pci_tbl[chip_idx].vendor_id
|
549 |
|
|
&& (dev_id & pci_tbl[chip_idx].device_id_mask) ==
|
550 |
|
|
pci_tbl[chip_idx].device_id)
|
551 |
|
|
break;
|
552 |
|
|
if (pci_tbl[chip_idx].vendor_id == 0) { /* Compiled out! */
|
553 |
|
|
printk(KERN_INFO "Unable to match chip type %4.4x %4.4x in "
|
554 |
|
|
"vortex_attach().\n", vendor_id, dev_id);
|
555 |
|
|
return NULL;
|
556 |
|
|
}
|
557 |
|
|
dev = vortex_probe1(bus, devfn, NULL, io, irq, chip_idx, MAX_UNITS+1);
|
558 |
|
|
if (dev) {
|
559 |
|
|
dev_node_t *node = kmalloc(sizeof(dev_node_t), GFP_KERNEL);
|
560 |
|
|
strcpy(node->dev_name, dev->name);
|
561 |
|
|
node->major = node->minor = 0;
|
562 |
|
|
node->next = NULL;
|
563 |
|
|
MOD_INC_USE_COUNT;
|
564 |
|
|
return node;
|
565 |
|
|
}
|
566 |
|
|
return NULL;
|
567 |
|
|
}
|
568 |
|
|
|
569 |
|
|
static void vortex_detach(dev_node_t *node)
|
570 |
|
|
{
|
571 |
|
|
struct device **devp, **next;
|
572 |
|
|
printk(KERN_INFO "vortex_detach(%s)\n", node->dev_name);
|
573 |
|
|
for (devp = &root_vortex_dev; *devp; devp = next) {
|
574 |
|
|
next = &((struct vortex_private *)(*devp)->priv)->next_module;
|
575 |
|
|
if (strcmp((*devp)->name, node->dev_name) == 0) break;
|
576 |
|
|
}
|
577 |
|
|
if (*devp) {
|
578 |
|
|
struct device *dev = *devp;
|
579 |
|
|
struct vortex_private *vp = dev->priv;
|
580 |
|
|
if (dev->flags & IFF_UP)
|
581 |
|
|
vortex_close(dev);
|
582 |
|
|
dev->flags &= ~(IFF_UP|IFF_RUNNING);
|
583 |
|
|
unregister_netdev(dev);
|
584 |
|
|
if (vp->cb_fn_base) iounmap(vp->cb_fn_base);
|
585 |
|
|
kfree(dev);
|
586 |
|
|
*devp = *next;
|
587 |
|
|
kfree(vp);
|
588 |
|
|
kfree(node);
|
589 |
|
|
MOD_DEC_USE_COUNT;
|
590 |
|
|
}
|
591 |
|
|
}
|
592 |
|
|
|
593 |
|
|
struct driver_operations vortex_ops = {
|
594 |
|
|
"3c575_cb", vortex_attach, NULL, NULL, vortex_detach
|
595 |
|
|
};
|
596 |
|
|
|
597 |
|
|
#endif /* Cardbus support */
|
598 |
|
|
|
599 |
|
|
|
600 |
|
|
int init_module(void)
|
601 |
|
|
{
|
602 |
|
|
if (vortex_debug)
|
603 |
|
|
printk(KERN_INFO "%s", version);
|
604 |
|
|
#ifdef CARDBUS
|
605 |
|
|
register_driver(&vortex_ops);
|
606 |
|
|
return 0;
|
607 |
|
|
#else
|
608 |
|
|
return vortex_scan(0, pci_tbl);
|
609 |
|
|
#endif
|
610 |
|
|
}
|
611 |
|
|
|
612 |
|
|
#else
|
613 |
|
|
int tc59x_probe(struct device *dev)
|
614 |
|
|
{
|
615 |
|
|
printk(KERN_INFO "%s", version);
|
616 |
|
|
return vortex_scan(dev, pci_tbl);
|
617 |
|
|
}
|
618 |
|
|
#endif /* not MODULE */
|
619 |
|
|
|
620 |
|
|
#ifndef CARDBUS
|
621 |
|
|
static int vortex_scan(struct device *dev, struct pci_id_info pci_tbl[])
|
622 |
|
|
{
|
623 |
|
|
int cards_found = 0;
|
624 |
|
|
|
625 |
|
|
/* Allow an EISA-only driver. */
|
626 |
|
|
#if defined(CONFIG_PCI) || (defined(MODULE) && !defined(NO_PCI))
|
627 |
|
|
/* Ideally we would detect all cards in slot order. That would
|
628 |
|
|
be best done a central PCI probe dispatch, which wouldn't work
|
629 |
|
|
well with the current structure. So instead we detect 3Com cards
|
630 |
|
|
in slot order. */
|
631 |
|
|
if (pcibios_present()) {
|
632 |
|
|
static int pci_index = 0;
|
633 |
|
|
unsigned char pci_bus, pci_device_fn;
|
634 |
|
|
|
635 |
|
|
for (;pci_index < 0xff; pci_index++) {
|
636 |
|
|
u16 vendor, device, pci_command, new_command, pwr_cmd;
|
637 |
|
|
int chip_idx, irq;
|
638 |
|
|
long ioaddr;
|
639 |
|
|
|
640 |
|
|
if (pcibios_find_class (PCI_CLASS_NETWORK_ETHERNET << 8, pci_index,
|
641 |
|
|
&pci_bus, &pci_device_fn)
|
642 |
|
|
!= PCIBIOS_SUCCESSFUL)
|
643 |
|
|
break;
|
644 |
|
|
pcibios_read_config_word(pci_bus, pci_device_fn,
|
645 |
|
|
PCI_VENDOR_ID, &vendor);
|
646 |
|
|
pcibios_read_config_word(pci_bus, pci_device_fn,
|
647 |
|
|
PCI_DEVICE_ID, &device);
|
648 |
|
|
for (chip_idx = 0; pci_tbl[chip_idx].vendor_id; chip_idx++)
|
649 |
|
|
if (vendor == pci_tbl[chip_idx].vendor_id
|
650 |
|
|
&& (device & pci_tbl[chip_idx].device_id_mask) ==
|
651 |
|
|
pci_tbl[chip_idx].device_id)
|
652 |
|
|
break;
|
653 |
|
|
if (pci_tbl[chip_idx].vendor_id == 0) /* Compiled out! */
|
654 |
|
|
continue;
|
655 |
|
|
|
656 |
|
|
{
|
657 |
|
|
#if LINUX_VERSION_CODE >= 0x20155
|
658 |
|
|
struct pci_dev *pdev = pci_find_slot(pci_bus, pci_device_fn);
|
659 |
|
|
ioaddr = pdev->base_address[0] & ~3;
|
660 |
|
|
irq = pdev->irq;
|
661 |
|
|
#else
|
662 |
|
|
u32 pci_ioaddr;
|
663 |
|
|
u8 pci_irq_line;
|
664 |
|
|
pcibios_read_config_byte(pci_bus, pci_device_fn,
|
665 |
|
|
PCI_INTERRUPT_LINE, &pci_irq_line);
|
666 |
|
|
pcibios_read_config_dword(pci_bus, pci_device_fn,
|
667 |
|
|
PCI_BASE_ADDRESS_0, &pci_ioaddr);
|
668 |
|
|
ioaddr = pci_ioaddr & ~3;;
|
669 |
|
|
irq = pci_irq_line;
|
670 |
|
|
#endif
|
671 |
|
|
}
|
672 |
|
|
|
673 |
|
|
/* Power-up the card. */
|
674 |
|
|
pcibios_read_config_word(pci_bus, pci_device_fn,
|
675 |
|
|
0xe0, &pwr_cmd);
|
676 |
|
|
if (pwr_cmd & 0x3) {
|
677 |
|
|
/* Save the ioaddr and IRQ info! */
|
678 |
|
|
printk(KERN_INFO " A 3Com network adapter is powered down!"
|
679 |
|
|
" Setting the power state %4.4x->%4.4x.\n",
|
680 |
|
|
pwr_cmd, pwr_cmd & ~3);
|
681 |
|
|
pcibios_write_config_word(pci_bus, pci_device_fn,
|
682 |
|
|
0xe0, pwr_cmd & ~3);
|
683 |
|
|
printk(KERN_INFO " Setting the IRQ to %d, IOADDR to %#lx.\n",
|
684 |
|
|
irq, ioaddr);
|
685 |
|
|
pcibios_write_config_byte(pci_bus, pci_device_fn,
|
686 |
|
|
PCI_INTERRUPT_LINE, irq);
|
687 |
|
|
pcibios_write_config_dword(pci_bus, pci_device_fn,
|
688 |
|
|
PCI_BASE_ADDRESS_0, ioaddr);
|
689 |
|
|
}
|
690 |
|
|
|
691 |
|
|
if (ioaddr == 0) {
|
692 |
|
|
printk(KERN_WARNING " A 3Com network adapter has been found, "
|
693 |
|
|
"however it has not been assigned an I/O address.\n"
|
694 |
|
|
" You may need to power-cycle the machine for this "
|
695 |
|
|
"device to work!\n");
|
696 |
|
|
continue;
|
697 |
|
|
}
|
698 |
|
|
|
699 |
|
|
if (check_region(ioaddr, pci_tbl[chip_idx].io_size))
|
700 |
|
|
continue;
|
701 |
|
|
|
702 |
|
|
/* Activate the card. */
|
703 |
|
|
pcibios_read_config_word(pci_bus, pci_device_fn,
|
704 |
|
|
PCI_COMMAND, &pci_command);
|
705 |
|
|
new_command = pci_command | PCI_COMMAND_MASTER|PCI_COMMAND_IO;
|
706 |
|
|
if (pci_command != new_command) {
|
707 |
|
|
printk(KERN_INFO " The PCI BIOS has not enabled the device "
|
708 |
|
|
"at %d/%d. Updating PCI command %4.4x->%4.4x.\n",
|
709 |
|
|
pci_bus, pci_device_fn, pci_command, new_command);
|
710 |
|
|
pcibios_write_config_word(pci_bus, pci_device_fn,
|
711 |
|
|
PCI_COMMAND, new_command);
|
712 |
|
|
}
|
713 |
|
|
|
714 |
|
|
dev = vortex_probe1(pci_bus, pci_device_fn, dev, ioaddr, irq,
|
715 |
|
|
chip_idx, cards_found);
|
716 |
|
|
|
717 |
|
|
if (dev) {
|
718 |
|
|
/* Get and check the latency values. On the 3c590 series
|
719 |
|
|
the latency timer must be set to the maximum value to avoid
|
720 |
|
|
data corruption that occurs when the timer expires during
|
721 |
|
|
a transfer -- a bug in the Vortex chip only. */
|
722 |
|
|
u8 pci_latency;
|
723 |
|
|
u8 new_latency = (device & 0xff00) == 0x5900 ? 248 : 32;
|
724 |
|
|
|
725 |
|
|
pcibios_read_config_byte(pci_bus, pci_device_fn,
|
726 |
|
|
PCI_LATENCY_TIMER, &pci_latency);
|
727 |
|
|
if (pci_latency < new_latency) {
|
728 |
|
|
printk(KERN_INFO "%s: Overriding PCI latency"
|
729 |
|
|
" timer (CFLT) setting of %d, new value is %d.\n",
|
730 |
|
|
dev->name, pci_latency, new_latency);
|
731 |
|
|
pcibios_write_config_byte(pci_bus, pci_device_fn,
|
732 |
|
|
PCI_LATENCY_TIMER, new_latency);
|
733 |
|
|
}
|
734 |
|
|
dev = 0;
|
735 |
|
|
cards_found++;
|
736 |
|
|
}
|
737 |
|
|
}
|
738 |
|
|
}
|
739 |
|
|
#endif /* NO_PCI */
|
740 |
|
|
|
741 |
|
|
/* Now check all slots of the EISA bus. */
|
742 |
|
|
if (EISA_bus) {
|
743 |
|
|
static long ioaddr = 0x1000;
|
744 |
|
|
for ( ; ioaddr < 0x9000; ioaddr += 0x1000) {
|
745 |
|
|
int device_id;
|
746 |
|
|
if (check_region(ioaddr, VORTEX_TOTAL_SIZE))
|
747 |
|
|
continue;
|
748 |
|
|
/* Check the standard EISA ID register for an encoded '3Com'. */
|
749 |
|
|
if (inw(ioaddr + 0xC80) != 0x6d50)
|
750 |
|
|
continue;
|
751 |
|
|
/* Check for a product that we support, 3c59{2,7} any rev. */
|
752 |
|
|
device_id = (inb(ioaddr + 0xC82)<<8) + inb(ioaddr + 0xC83);
|
753 |
|
|
if ((device_id & 0xFF00) != 0x5900)
|
754 |
|
|
continue;
|
755 |
|
|
vortex_probe1(0, 0, dev, ioaddr, inw(ioaddr + 0xC88) >> 12,
|
756 |
|
|
4, cards_found);
|
757 |
|
|
dev = 0;
|
758 |
|
|
cards_found++;
|
759 |
|
|
}
|
760 |
|
|
}
|
761 |
|
|
|
762 |
|
|
#ifdef MODULE
|
763 |
|
|
/* Special code to work-around the Compaq PCI BIOS32 problem. */
|
764 |
|
|
if (compaq_ioaddr) {
|
765 |
|
|
vortex_probe1(0, 0, dev, compaq_ioaddr, compaq_irq,
|
766 |
|
|
compaq_device_id, cards_found++);
|
767 |
|
|
dev = 0;
|
768 |
|
|
}
|
769 |
|
|
#endif
|
770 |
|
|
|
771 |
|
|
return cards_found ? 0 : -ENODEV;
|
772 |
|
|
}
|
773 |
|
|
#endif /* ! Cardbus */
|
774 |
|
|
|
775 |
|
|
static struct device *vortex_probe1(int pci_bus, int pci_devfn,
|
776 |
|
|
struct device *dev, long ioaddr,
|
777 |
|
|
int irq, int chip_idx, int card_idx)
|
778 |
|
|
{
|
779 |
|
|
struct vortex_private *vp;
|
780 |
|
|
int option;
|
781 |
|
|
unsigned int eeprom[0x40], checksum = 0; /* EEPROM contents */
|
782 |
|
|
int i;
|
783 |
|
|
|
784 |
|
|
dev = init_etherdev(dev, 0);
|
785 |
|
|
|
786 |
|
|
printk(KERN_INFO "%s: 3Com %s at 0x%lx, ",
|
787 |
|
|
dev->name, pci_tbl[chip_idx].name, ioaddr);
|
788 |
|
|
|
789 |
|
|
dev->base_addr = ioaddr;
|
790 |
|
|
dev->irq = irq;
|
791 |
|
|
dev->mtu = mtu;
|
792 |
|
|
|
793 |
|
|
/* Make certain the descriptor lists are aligned. */
|
794 |
|
|
{
|
795 |
|
|
void *mem = kmalloc(sizeof(*vp) + 15, GFP_KERNEL);
|
796 |
|
|
vp = (void *)(((long)mem + 15) & ~15);
|
797 |
|
|
vp->priv_addr = mem;
|
798 |
|
|
}
|
799 |
|
|
memset(vp, 0, sizeof(*vp));
|
800 |
|
|
dev->priv = vp;
|
801 |
|
|
|
802 |
|
|
vp->next_module = root_vortex_dev;
|
803 |
|
|
root_vortex_dev = dev;
|
804 |
|
|
|
805 |
|
|
vp->chip_id = chip_idx;
|
806 |
|
|
vp->pci_bus = pci_bus;
|
807 |
|
|
vp->pci_devfn = pci_devfn;
|
808 |
|
|
|
809 |
|
|
/* The lower four bits are the media type. */
|
810 |
|
|
if (dev->mem_start)
|
811 |
|
|
option = dev->mem_start;
|
812 |
|
|
else if (card_idx < MAX_UNITS)
|
813 |
|
|
option = options[card_idx];
|
814 |
|
|
else
|
815 |
|
|
option = -1;
|
816 |
|
|
|
817 |
|
|
if (option >= 0) {
|
818 |
|
|
vp->media_override = ((option & 7) == 2) ? 0 : option & 7;
|
819 |
|
|
vp->full_duplex = (option & 8) ? 1 : 0;
|
820 |
|
|
vp->bus_master = (option & 16) ? 1 : 0;
|
821 |
|
|
} else {
|
822 |
|
|
vp->media_override = 7;
|
823 |
|
|
vp->full_duplex = 0;
|
824 |
|
|
vp->bus_master = 0;
|
825 |
|
|
}
|
826 |
|
|
if (card_idx < MAX_UNITS && full_duplex[card_idx] > 0)
|
827 |
|
|
vp->full_duplex = 1;
|
828 |
|
|
|
829 |
|
|
vp->force_fd = vp->full_duplex;
|
830 |
|
|
vp->options = option;
|
831 |
|
|
|
832 |
|
|
/* Read the station address from the EEPROM. */
|
833 |
|
|
EL3WINDOW(0);
|
834 |
|
|
for (i = 0; i < 0x40; i++) {
|
835 |
|
|
int timer;
|
836 |
|
|
#ifdef CARDBUS
|
837 |
|
|
outw(0x230 + i, ioaddr + Wn0EepromCmd);
|
838 |
|
|
#else
|
839 |
|
|
outw(EEPROM_Read + i, ioaddr + Wn0EepromCmd);
|
840 |
|
|
#endif
|
841 |
|
|
/* Pause for at least 162 us. for the read to take place. */
|
842 |
|
|
for (timer = 10; timer >= 0; timer--) {
|
843 |
|
|
udelay(162);
|
844 |
|
|
if ((inw(ioaddr + Wn0EepromCmd) & 0x8000) == 0)
|
845 |
|
|
break;
|
846 |
|
|
}
|
847 |
|
|
eeprom[i] = inw(ioaddr + Wn0EepromData);
|
848 |
|
|
}
|
849 |
|
|
for (i = 0; i < 0x18; i++)
|
850 |
|
|
checksum ^= eeprom[i];
|
851 |
|
|
checksum = (checksum ^ (checksum >> 8)) & 0xff;
|
852 |
|
|
if (checksum != 0x00) { /* Grrr, needless incompatible change 3Com. */
|
853 |
|
|
while (i < 0x21)
|
854 |
|
|
checksum ^= eeprom[i++];
|
855 |
|
|
checksum = (checksum ^ (checksum >> 8)) & 0xff;
|
856 |
|
|
}
|
857 |
|
|
if (checksum != 0x00)
|
858 |
|
|
printk(" ***INVALID CHECKSUM %4.4x*** ", checksum);
|
859 |
|
|
|
860 |
|
|
for (i = 0; i < 3; i++)
|
861 |
|
|
((u16 *)dev->dev_addr)[i] = htons(eeprom[i + 10]);
|
862 |
|
|
for (i = 0; i < 6; i++)
|
863 |
|
|
printk("%c%2.2x", i ? ':' : ' ', dev->dev_addr[i]);
|
864 |
|
|
#ifdef __sparc__
|
865 |
|
|
printk(", IRQ %s\n", __irq_itoa(dev->irq));
|
866 |
|
|
#else
|
867 |
|
|
printk(", IRQ %d\n", dev->irq);
|
868 |
|
|
/* Tell them about an invalid IRQ. */
|
869 |
|
|
if (vortex_debug && (dev->irq <= 0 || dev->irq >= NR_IRQS))
|
870 |
|
|
printk(KERN_WARNING " *** Warning: IRQ %d is unlikely to work! ***\n",
|
871 |
|
|
dev->irq);
|
872 |
|
|
#endif
|
873 |
|
|
|
874 |
|
|
if (pci_tbl[vp->chip_id].drv_flags & HAS_CB_FNS) {
|
875 |
|
|
u32 fn_st_addr; /* Cardbus function status space */
|
876 |
|
|
pcibios_read_config_dword(pci_bus, pci_devfn, PCI_BASE_ADDRESS_2,
|
877 |
|
|
&fn_st_addr);
|
878 |
|
|
if (fn_st_addr)
|
879 |
|
|
vp->cb_fn_base = ioremap(fn_st_addr & ~3, 128);
|
880 |
|
|
printk("%s: CardBus functions mapped %8.8x->%p (PCMCIA committee"
|
881 |
|
|
" brain-damage).\n", dev->name, fn_st_addr, vp->cb_fn_base);
|
882 |
|
|
EL3WINDOW(2);
|
883 |
|
|
outw(0x10 | inw(ioaddr + Wn2_ResetOptions), ioaddr + Wn2_ResetOptions);
|
884 |
|
|
}
|
885 |
|
|
|
886 |
|
|
/* Extract our information from the EEPROM data. */
|
887 |
|
|
vp->info1 = eeprom[13];
|
888 |
|
|
vp->info2 = eeprom[15];
|
889 |
|
|
vp->capabilities = eeprom[16];
|
890 |
|
|
|
891 |
|
|
if (vp->info1 & 0x8000)
|
892 |
|
|
vp->full_duplex = 1;
|
893 |
|
|
|
894 |
|
|
{
|
895 |
|
|
char *ram_split[] = {"5:3", "3:1", "1:1", "3:5"};
|
896 |
|
|
union wn3_config config;
|
897 |
|
|
EL3WINDOW(3);
|
898 |
|
|
vp->available_media = inw(ioaddr + Wn3_Options);
|
899 |
|
|
if ((vp->available_media & 0xff) == 0) /* Broken 3c916 */
|
900 |
|
|
vp->available_media = 0x40;
|
901 |
|
|
config.i = inl(ioaddr + Wn3_Config);
|
902 |
|
|
if (vortex_debug > 1)
|
903 |
|
|
printk(KERN_DEBUG " Internal config register is %4.4x, "
|
904 |
|
|
"transceivers %#x.\n", config.i, inw(ioaddr + Wn3_Options));
|
905 |
|
|
printk(KERN_INFO " %dK %s-wide RAM %s Rx:Tx split, %s%s interface.\n",
|
906 |
|
|
8 << config.u.ram_size,
|
907 |
|
|
config.u.ram_width ? "word" : "byte",
|
908 |
|
|
ram_split[config.u.ram_split],
|
909 |
|
|
config.u.autoselect ? "autoselect/" : "",
|
910 |
|
|
config.u.xcvr > XCVR_ExtMII ? "<invalid transceiver>" :
|
911 |
|
|
media_tbl[config.u.xcvr].name);
|
912 |
|
|
vp->default_media = config.u.xcvr;
|
913 |
|
|
vp->autoselect = config.u.autoselect;
|
914 |
|
|
}
|
915 |
|
|
|
916 |
|
|
if (vp->media_override != 7) {
|
917 |
|
|
printk(KERN_INFO " Media override to transceiver type %d (%s).\n",
|
918 |
|
|
vp->media_override, media_tbl[vp->media_override].name);
|
919 |
|
|
dev->if_port = vp->media_override;
|
920 |
|
|
} else
|
921 |
|
|
dev->if_port = vp->default_media;
|
922 |
|
|
|
923 |
|
|
if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
|
924 |
|
|
int phy, phy_idx = 0;
|
925 |
|
|
EL3WINDOW(4);
|
926 |
|
|
mii_preamble_required++;
|
927 |
|
|
mii_preamble_required++;
|
928 |
|
|
mdio_read(ioaddr, 24, 1);
|
929 |
|
|
for (phy = 1; phy <= 32 && phy_idx < sizeof(vp->phys); phy++) {
|
930 |
|
|
int mii_status, phyx = phy & 0x1f;
|
931 |
|
|
mii_status = mdio_read(ioaddr, phyx, 1);
|
932 |
|
|
if (mii_status && mii_status != 0xffff) {
|
933 |
|
|
vp->phys[phy_idx++] = phyx;
|
934 |
|
|
printk(KERN_INFO " MII transceiver found at address %d,"
|
935 |
|
|
" status %4x.\n", phyx, mii_status);
|
936 |
|
|
if ((mii_status & 0x0040) == 0)
|
937 |
|
|
mii_preamble_required++;
|
938 |
|
|
}
|
939 |
|
|
}
|
940 |
|
|
mii_preamble_required--;
|
941 |
|
|
if (phy_idx == 0) {
|
942 |
|
|
printk(KERN_WARNING" ***WARNING*** No MII transceivers found!\n");
|
943 |
|
|
vp->phys[0] = 24;
|
944 |
|
|
} else {
|
945 |
|
|
vp->advertising = mdio_read(ioaddr, vp->phys[0], 4);
|
946 |
|
|
if (vp->full_duplex) {
|
947 |
|
|
/* Only advertise the FD media types. */
|
948 |
|
|
vp->advertising &= ~0x02A0;
|
949 |
|
|
mdio_write(ioaddr, vp->phys[0], 4, vp->advertising);
|
950 |
|
|
}
|
951 |
|
|
}
|
952 |
|
|
}
|
953 |
|
|
|
954 |
|
|
if (vp->capabilities & CapBusMaster) {
|
955 |
|
|
vp->full_bus_master_tx = 1;
|
956 |
|
|
printk(KERN_INFO" Enabling bus-master transmits and %s receives.\n",
|
957 |
|
|
(vp->info2 & 1) ? "early" : "whole-frame" );
|
958 |
|
|
vp->full_bus_master_rx = (vp->info2 & 1) ? 1 : 2;
|
959 |
|
|
}
|
960 |
|
|
|
961 |
|
|
/* We do a request_region() to register /proc/ioports info. */
|
962 |
|
|
request_region(ioaddr, pci_tbl[chip_idx].io_size, dev->name);
|
963 |
|
|
|
964 |
|
|
/* The 3c59x-specific entries in the device structure. */
|
965 |
|
|
dev->open = &vortex_open;
|
966 |
|
|
dev->hard_start_xmit = &vortex_start_xmit;
|
967 |
|
|
dev->stop = &vortex_close;
|
968 |
|
|
dev->get_stats = &vortex_get_stats;
|
969 |
|
|
dev->do_ioctl = &vortex_ioctl;
|
970 |
|
|
dev->set_multicast_list = &set_rx_mode;
|
971 |
|
|
|
972 |
|
|
return dev;
|
973 |
|
|
}
|
974 |
|
|
|
975 |
|
|
|
976 |
|
|
static int
|
977 |
|
|
vortex_open(struct device *dev)
|
978 |
|
|
{
|
979 |
|
|
long ioaddr = dev->base_addr;
|
980 |
|
|
struct vortex_private *vp = (struct vortex_private *)dev->priv;
|
981 |
|
|
union wn3_config config;
|
982 |
|
|
int i;
|
983 |
|
|
|
984 |
|
|
/* Before initializing select the active media port. */
|
985 |
|
|
EL3WINDOW(3);
|
986 |
|
|
config.i = inl(ioaddr + Wn3_Config);
|
987 |
|
|
|
988 |
|
|
if (vp->media_override != 7) {
|
989 |
|
|
if (vortex_debug > 1)
|
990 |
|
|
printk(KERN_INFO "%s: Media override to transceiver %d (%s).\n",
|
991 |
|
|
dev->name, vp->media_override,
|
992 |
|
|
media_tbl[vp->media_override].name);
|
993 |
|
|
dev->if_port = vp->media_override;
|
994 |
|
|
} else if (vp->autoselect && pci_tbl[vp->chip_id].drv_flags & HAS_NWAY) {
|
995 |
|
|
dev->if_port = XCVR_NWAY;
|
996 |
|
|
} else if (vp->autoselect) {
|
997 |
|
|
/* Find first available media type, starting with 100baseTx. */
|
998 |
|
|
dev->if_port = XCVR_100baseTx;
|
999 |
|
|
while (! (vp->available_media & media_tbl[dev->if_port].mask))
|
1000 |
|
|
dev->if_port = media_tbl[dev->if_port].next;
|
1001 |
|
|
} else
|
1002 |
|
|
dev->if_port = vp->default_media;
|
1003 |
|
|
|
1004 |
|
|
init_timer(&vp->timer);
|
1005 |
|
|
vp->timer.expires = RUN_AT(media_tbl[dev->if_port].wait);
|
1006 |
|
|
vp->timer.data = (unsigned long)dev;
|
1007 |
|
|
vp->timer.function = &vortex_timer; /* timer handler */
|
1008 |
|
|
add_timer(&vp->timer);
|
1009 |
|
|
|
1010 |
|
|
if (vortex_debug > 1)
|
1011 |
|
|
printk(KERN_DEBUG "%s: Initial media type %s.\n",
|
1012 |
|
|
dev->name, media_tbl[dev->if_port].name);
|
1013 |
|
|
|
1014 |
|
|
vp->full_duplex = vp->force_fd;
|
1015 |
|
|
config.u.xcvr = dev->if_port;
|
1016 |
|
|
outl(config.i, ioaddr + Wn3_Config);
|
1017 |
|
|
|
1018 |
|
|
if (dev->if_port == XCVR_MII || dev->if_port == XCVR_NWAY) {
|
1019 |
|
|
int mii_reg1, mii_reg5;
|
1020 |
|
|
EL3WINDOW(4);
|
1021 |
|
|
/* Read BMSR (reg1) only to clear old status. */
|
1022 |
|
|
mii_reg1 = mdio_read(ioaddr, vp->phys[0], 1);
|
1023 |
|
|
mii_reg5 = mdio_read(ioaddr, vp->phys[0], 5);
|
1024 |
|
|
if (mii_reg5 == 0xffff || mii_reg5 == 0x0000)
|
1025 |
|
|
; /* No MII device or no link partner report */
|
1026 |
|
|
else if ((mii_reg5 & 0x0100) != 0 /* 100baseTx-FD */
|
1027 |
|
|
|| (mii_reg5 & 0x00C0) == 0x0040) /* 10T-FD, but not 100-HD */
|
1028 |
|
|
vp->full_duplex = 1;
|
1029 |
|
|
if (vortex_debug > 1)
|
1030 |
|
|
printk(KERN_INFO "%s: MII #%d status %4.4x, link partner capability %4.4x,"
|
1031 |
|
|
" setting %s-duplex.\n", dev->name, vp->phys[0],
|
1032 |
|
|
mii_reg1, mii_reg5, vp->full_duplex ? "full" : "half");
|
1033 |
|
|
EL3WINDOW(3);
|
1034 |
|
|
}
|
1035 |
|
|
|
1036 |
|
|
/* Set the full-duplex bit. */
|
1037 |
|
|
outb(((vp->info1 & 0x8000) || vp->full_duplex ? 0x20 : 0) |
|
1038 |
|
|
(dev->mtu > 1500 ? 0x40 : 0), ioaddr + Wn3_MAC_Ctrl);
|
1039 |
|
|
|
1040 |
|
|
if (vortex_debug > 1) {
|
1041 |
|
|
printk(KERN_DEBUG "%s: vortex_open() InternalConfig %8.8x.\n",
|
1042 |
|
|
dev->name, config.i);
|
1043 |
|
|
}
|
1044 |
|
|
|
1045 |
|
|
outw(TxReset, ioaddr + EL3_CMD);
|
1046 |
|
|
for (i = 2000; i >= 0 ; i--)
|
1047 |
|
|
if ( ! (inw(ioaddr + EL3_STATUS) & CmdInProgress))
|
1048 |
|
|
break;
|
1049 |
|
|
|
1050 |
|
|
outw(RxReset, ioaddr + EL3_CMD);
|
1051 |
|
|
/* Wait a few ticks for the RxReset command to complete. */
|
1052 |
|
|
for (i = 2000; i >= 0 ; i--)
|
1053 |
|
|
if ( ! (inw(ioaddr + EL3_STATUS) & CmdInProgress))
|
1054 |
|
|
break;
|
1055 |
|
|
|
1056 |
|
|
outw(SetStatusEnb | 0x00, ioaddr + EL3_CMD);
|
1057 |
|
|
|
1058 |
|
|
/* Use the now-standard shared IRQ implementation. */
|
1059 |
|
|
if (request_irq(dev->irq, &vortex_interrupt, SA_SHIRQ, dev->name, dev)) {
|
1060 |
|
|
return -EAGAIN;
|
1061 |
|
|
}
|
1062 |
|
|
|
1063 |
|
|
if (vortex_debug > 1) {
|
1064 |
|
|
EL3WINDOW(4);
|
1065 |
|
|
printk(KERN_DEBUG "%s: vortex_open() irq %d media status %4.4x.\n",
|
1066 |
|
|
dev->name, dev->irq, inw(ioaddr + Wn4_Media));
|
1067 |
|
|
}
|
1068 |
|
|
|
1069 |
|
|
/* Set the station address and mask in window 2 each time opened. */
|
1070 |
|
|
EL3WINDOW(2);
|
1071 |
|
|
for (i = 0; i < 6; i++)
|
1072 |
|
|
outb(dev->dev_addr[i], ioaddr + i);
|
1073 |
|
|
for (; i < 12; i+=2)
|
1074 |
|
|
outw(0, ioaddr + i);
|
1075 |
|
|
|
1076 |
|
|
if (dev->if_port == XCVR_10base2)
|
1077 |
|
|
/* Start the thinnet transceiver. We should really wait 50ms...*/
|
1078 |
|
|
outw(StartCoax, ioaddr + EL3_CMD);
|
1079 |
|
|
if (dev->if_port != XCVR_NWAY) {
|
1080 |
|
|
EL3WINDOW(4);
|
1081 |
|
|
outw((inw(ioaddr + Wn4_Media) & ~(Media_10TP|Media_SQE)) |
|
1082 |
|
|
media_tbl[dev->if_port].media_bits, ioaddr + Wn4_Media);
|
1083 |
|
|
}
|
1084 |
|
|
|
1085 |
|
|
/* Switch to the stats window, and clear all stats by reading. */
|
1086 |
|
|
outw(StatsDisable, ioaddr + EL3_CMD);
|
1087 |
|
|
EL3WINDOW(6);
|
1088 |
|
|
for (i = 0; i < 10; i++)
|
1089 |
|
|
inb(ioaddr + i);
|
1090 |
|
|
inw(ioaddr + 10);
|
1091 |
|
|
inw(ioaddr + 12);
|
1092 |
|
|
/* New: On the Vortex we must also clear the BadSSD counter. */
|
1093 |
|
|
EL3WINDOW(4);
|
1094 |
|
|
inb(ioaddr + 12);
|
1095 |
|
|
/* ..and on the Boomerang we enable the extra statistics bits. */
|
1096 |
|
|
outw(0x0040, ioaddr + Wn4_NetDiag);
|
1097 |
|
|
|
1098 |
|
|
/* Switch to register set 7 for normal use. */
|
1099 |
|
|
EL3WINDOW(7);
|
1100 |
|
|
|
1101 |
|
|
if (vp->full_bus_master_rx) { /* Boomerang bus master. */
|
1102 |
|
|
vp->cur_rx = vp->dirty_rx = 0;
|
1103 |
|
|
/* Initialize the RxEarly register as recommended. */
|
1104 |
|
|
outw(SetRxThreshold + (1536>>2), ioaddr + EL3_CMD);
|
1105 |
|
|
outl(0x0020, ioaddr + PktStatus);
|
1106 |
|
|
if (vortex_debug > 2)
|
1107 |
|
|
printk(KERN_DEBUG "%s: Filling in the Rx ring.\n", dev->name);
|
1108 |
|
|
for (i = 0; i < RX_RING_SIZE; i++) {
|
1109 |
|
|
struct sk_buff *skb;
|
1110 |
|
|
vp->rx_ring[i].next = cpu_to_le32(virt_to_bus(&vp->rx_ring[i+1]));
|
1111 |
|
|
vp->rx_ring[i].status = 0; /* Clear complete bit. */
|
1112 |
|
|
vp->rx_ring[i].length = cpu_to_le32(PKT_BUF_SZ | LAST_FRAG);
|
1113 |
|
|
skb = dev_alloc_skb(PKT_BUF_SZ);
|
1114 |
|
|
vp->rx_skbuff[i] = skb;
|
1115 |
|
|
if (skb == NULL)
|
1116 |
|
|
break; /* Bad news! */
|
1117 |
|
|
skb->dev = dev; /* Mark as being used by this device. */
|
1118 |
|
|
#if LINUX_VERSION_CODE >= 0x10300
|
1119 |
|
|
skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
|
1120 |
|
|
vp->rx_ring[i].addr = cpu_to_le32(virt_to_bus(skb->tail));
|
1121 |
|
|
#else
|
1122 |
|
|
vp->rx_ring[i].addr = virt_to_bus(skb->data);
|
1123 |
|
|
#endif
|
1124 |
|
|
}
|
1125 |
|
|
/* Wrap the ring. */
|
1126 |
|
|
vp->rx_ring[i-1].next = cpu_to_le32(virt_to_bus(&vp->rx_ring[0]));
|
1127 |
|
|
outl(virt_to_bus(&vp->rx_ring[0]), ioaddr + UpListPtr);
|
1128 |
|
|
}
|
1129 |
|
|
if (vp->full_bus_master_tx) { /* Boomerang bus master Tx. */
|
1130 |
|
|
dev->hard_start_xmit = &boomerang_start_xmit;
|
1131 |
|
|
vp->cur_tx = vp->dirty_tx = 0;
|
1132 |
|
|
outb(PKT_BUF_SZ>>8, ioaddr + TxFreeThreshold); /* Room for a packet. */
|
1133 |
|
|
/* Clear the Tx ring. */
|
1134 |
|
|
for (i = 0; i < TX_RING_SIZE; i++)
|
1135 |
|
|
vp->tx_skbuff[i] = 0;
|
1136 |
|
|
outl(0, ioaddr + DownListPtr);
|
1137 |
|
|
}
|
1138 |
|
|
/* Set reciever mode: presumably accept b-case and phys addr only. */
|
1139 |
|
|
set_rx_mode(dev);
|
1140 |
|
|
outw(StatsEnable, ioaddr + EL3_CMD); /* Turn on statistics. */
|
1141 |
|
|
|
1142 |
|
|
vp->in_interrupt = 0;
|
1143 |
|
|
dev->tbusy = 0;
|
1144 |
|
|
dev->interrupt = 0;
|
1145 |
|
|
dev->start = 1;
|
1146 |
|
|
|
1147 |
|
|
outw(RxEnable, ioaddr + EL3_CMD); /* Enable the receiver. */
|
1148 |
|
|
outw(TxEnable, ioaddr + EL3_CMD); /* Enable transmitter. */
|
1149 |
|
|
/* Allow status bits to be seen. */
|
1150 |
|
|
vp->status_enable = SetStatusEnb | HostError|IntReq|StatsFull|TxComplete|
|
1151 |
|
|
(vp->full_bus_master_tx ? DownComplete : TxAvailable) |
|
1152 |
|
|
(vp->full_bus_master_rx ? UpComplete : RxComplete) |
|
1153 |
|
|
(vp->bus_master ? DMADone : 0);
|
1154 |
|
|
vp->intr_enable = SetIntrEnb | IntLatch | TxAvailable | RxComplete |
|
1155 |
|
|
StatsFull | HostError | TxComplete | IntReq
|
1156 |
|
|
| (vp->bus_master ? DMADone : 0) | UpComplete | DownComplete;
|
1157 |
|
|
outw(vp->status_enable, ioaddr + EL3_CMD);
|
1158 |
|
|
/* Ack all pending events, and set active indicator mask. */
|
1159 |
|
|
outw(AckIntr | IntLatch | TxAvailable | RxEarly | IntReq,
|
1160 |
|
|
ioaddr + EL3_CMD);
|
1161 |
|
|
outw(vp->intr_enable, ioaddr + EL3_CMD);
|
1162 |
|
|
if (vp->cb_fn_base) /* The PCMCIA people are idiots. */
|
1163 |
|
|
writel(0x8000, vp->cb_fn_base + 4);
|
1164 |
|
|
|
1165 |
|
|
MOD_INC_USE_COUNT;
|
1166 |
|
|
|
1167 |
|
|
return 0;
|
1168 |
|
|
}
|
1169 |
|
|
|
1170 |
|
|
static void vortex_timer(unsigned long data)
|
1171 |
|
|
{
|
1172 |
|
|
struct device *dev = (struct device *)data;
|
1173 |
|
|
struct vortex_private *vp = (struct vortex_private *)dev->priv;
|
1174 |
|
|
long ioaddr = dev->base_addr;
|
1175 |
|
|
int next_tick = 0;
|
1176 |
|
|
int ok = 0;
|
1177 |
|
|
int media_status, mii_status, old_window;
|
1178 |
|
|
|
1179 |
|
|
if (vortex_debug > 1)
|
1180 |
|
|
printk(KERN_DEBUG "%s: Media selection timer tick happened, %s.\n",
|
1181 |
|
|
dev->name, media_tbl[dev->if_port].name);
|
1182 |
|
|
|
1183 |
|
|
disable_irq(dev->irq);
|
1184 |
|
|
old_window = inw(ioaddr + EL3_CMD) >> 13;
|
1185 |
|
|
EL3WINDOW(4);
|
1186 |
|
|
media_status = inw(ioaddr + Wn4_Media);
|
1187 |
|
|
switch (dev->if_port) {
|
1188 |
|
|
case XCVR_10baseT: case XCVR_100baseTx: case XCVR_100baseFx:
|
1189 |
|
|
if (media_status & Media_LnkBeat) {
|
1190 |
|
|
ok = 1;
|
1191 |
|
|
if (vortex_debug > 1)
|
1192 |
|
|
printk(KERN_DEBUG "%s: Media %s has link beat, %x.\n",
|
1193 |
|
|
dev->name, media_tbl[dev->if_port].name, media_status);
|
1194 |
|
|
} else if (vortex_debug > 1)
|
1195 |
|
|
printk(KERN_DEBUG "%s: Media %s is has no link beat, %x.\n",
|
1196 |
|
|
dev->name, media_tbl[dev->if_port].name, media_status);
|
1197 |
|
|
break;
|
1198 |
|
|
case XCVR_MII: case XCVR_NWAY:
|
1199 |
|
|
mii_status = mdio_read(ioaddr, vp->phys[0], 1);
|
1200 |
|
|
ok = 1;
|
1201 |
|
|
if (debug > 1)
|
1202 |
|
|
printk(KERN_DEBUG "%s: MII transceiver has status %4.4x.\n",
|
1203 |
|
|
dev->name, mii_status);
|
1204 |
|
|
if (mii_status & 0x0004) {
|
1205 |
|
|
int mii_reg5 = mdio_read(ioaddr, vp->phys[0], 5);
|
1206 |
|
|
if (! vp->force_fd && mii_reg5 != 0xffff) {
|
1207 |
|
|
int duplex = (mii_reg5&0x0100) ||
|
1208 |
|
|
(mii_reg5 & 0x01C0) == 0x0040;
|
1209 |
|
|
if (vp->full_duplex != duplex) {
|
1210 |
|
|
vp->full_duplex = duplex;
|
1211 |
|
|
printk(KERN_INFO "%s: Setting %s-duplex based on MII "
|
1212 |
|
|
"#%d link partner capability of %4.4x.\n",
|
1213 |
|
|
dev->name, vp->full_duplex ? "full" : "half",
|
1214 |
|
|
vp->phys[0], mii_reg5);
|
1215 |
|
|
/* Set the full-duplex bit. */
|
1216 |
|
|
outb((vp->full_duplex ? 0x20 : 0) |
|
1217 |
|
|
(dev->mtu > 1500 ? 0x40 : 0),
|
1218 |
|
|
ioaddr + Wn3_MAC_Ctrl);
|
1219 |
|
|
}
|
1220 |
|
|
next_tick = 60*HZ;
|
1221 |
|
|
}
|
1222 |
|
|
}
|
1223 |
|
|
break;
|
1224 |
|
|
default: /* Other media types handled by Tx timeouts. */
|
1225 |
|
|
if (vortex_debug > 1)
|
1226 |
|
|
printk(KERN_DEBUG "%s: Media %s is has no indication, %x.\n",
|
1227 |
|
|
dev->name, media_tbl[dev->if_port].name, media_status);
|
1228 |
|
|
ok = 1;
|
1229 |
|
|
}
|
1230 |
|
|
if ( ! ok) {
|
1231 |
|
|
union wn3_config config;
|
1232 |
|
|
|
1233 |
|
|
do {
|
1234 |
|
|
dev->if_port = media_tbl[dev->if_port].next;
|
1235 |
|
|
} while ( ! (vp->available_media & media_tbl[dev->if_port].mask));
|
1236 |
|
|
if (dev->if_port == XCVR_Default) { /* Go back to default. */
|
1237 |
|
|
dev->if_port = vp->default_media;
|
1238 |
|
|
if (vortex_debug > 1)
|
1239 |
|
|
printk(KERN_DEBUG "%s: Media selection failing, using default "
|
1240 |
|
|
"%s port.\n",
|
1241 |
|
|
dev->name, media_tbl[dev->if_port].name);
|
1242 |
|
|
} else {
|
1243 |
|
|
if (vortex_debug > 1)
|
1244 |
|
|
printk(KERN_DEBUG "%s: Media selection failed, now trying "
|
1245 |
|
|
"%s port.\n",
|
1246 |
|
|
dev->name, media_tbl[dev->if_port].name);
|
1247 |
|
|
next_tick = RUN_AT(media_tbl[dev->if_port].wait);
|
1248 |
|
|
}
|
1249 |
|
|
outw((media_status & ~(Media_10TP|Media_SQE)) |
|
1250 |
|
|
media_tbl[dev->if_port].media_bits, ioaddr + Wn4_Media);
|
1251 |
|
|
|
1252 |
|
|
EL3WINDOW(3);
|
1253 |
|
|
config.i = inl(ioaddr + Wn3_Config);
|
1254 |
|
|
config.u.xcvr = dev->if_port;
|
1255 |
|
|
outl(config.i, ioaddr + Wn3_Config);
|
1256 |
|
|
|
1257 |
|
|
outw(dev->if_port == XCVR_10base2 ? StartCoax : StopCoax,
|
1258 |
|
|
ioaddr + EL3_CMD);
|
1259 |
|
|
}
|
1260 |
|
|
EL3WINDOW(old_window);
|
1261 |
|
|
enable_irq(dev->irq);
|
1262 |
|
|
|
1263 |
|
|
if (vortex_debug > 2)
|
1264 |
|
|
printk(KERN_DEBUG "%s: Media selection timer finished, %s.\n",
|
1265 |
|
|
dev->name, media_tbl[dev->if_port].name);
|
1266 |
|
|
|
1267 |
|
|
if (next_tick) {
|
1268 |
|
|
vp->timer.expires = RUN_AT(next_tick);
|
1269 |
|
|
add_timer(&vp->timer);
|
1270 |
|
|
}
|
1271 |
|
|
return;
|
1272 |
|
|
}
|
1273 |
|
|
|
1274 |
|
|
static void vortex_tx_timeout(struct device *dev)
|
1275 |
|
|
{
|
1276 |
|
|
struct vortex_private *vp = (struct vortex_private *)dev->priv;
|
1277 |
|
|
long ioaddr = dev->base_addr;
|
1278 |
|
|
int j;
|
1279 |
|
|
|
1280 |
|
|
printk(KERN_ERR "%s: transmit timed out, tx_status %2.2x status %4.4x.\n",
|
1281 |
|
|
dev->name, inb(ioaddr + TxStatus),
|
1282 |
|
|
inw(ioaddr + EL3_STATUS));
|
1283 |
|
|
/* Slight code bloat to be user friendly. */
|
1284 |
|
|
if ((inb(ioaddr + TxStatus) & 0x88) == 0x88)
|
1285 |
|
|
printk(KERN_ERR "%s: Transmitter encountered 16 collisions --"
|
1286 |
|
|
" network cable problem?\n", dev->name);
|
1287 |
|
|
if (inw(ioaddr + EL3_STATUS) & IntLatch) {
|
1288 |
|
|
printk(KERN_ERR "%s: Interrupt posted but not delivered --"
|
1289 |
|
|
" IRQ blocked by another device?\n", dev->name);
|
1290 |
|
|
/* Bad idea here.. but we might as well handle a few events. */
|
1291 |
|
|
vortex_interrupt(dev->irq, dev, 0);
|
1292 |
|
|
}
|
1293 |
|
|
outw(TxReset, ioaddr + EL3_CMD);
|
1294 |
|
|
for (j = 200; j >= 0 ; j--)
|
1295 |
|
|
if ( ! (inw(ioaddr + EL3_STATUS) & CmdInProgress))
|
1296 |
|
|
break;
|
1297 |
|
|
|
1298 |
|
|
#if ! defined(final_version) && LINUX_VERSION_CODE >= 0x10300
|
1299 |
|
|
if (vp->full_bus_master_tx) {
|
1300 |
|
|
int i;
|
1301 |
|
|
printk(KERN_DEBUG " Flags; bus-master %d, full %d; dirty %d "
|
1302 |
|
|
"current %d.\n",
|
1303 |
|
|
vp->full_bus_master_tx, vp->tx_full, vp->dirty_tx, vp->cur_tx);
|
1304 |
|
|
printk(KERN_DEBUG " Transmit list %8.8x vs. %p.\n",
|
1305 |
|
|
inl(ioaddr + DownListPtr),
|
1306 |
|
|
&vp->tx_ring[vp->dirty_tx % TX_RING_SIZE]);
|
1307 |
|
|
for (i = 0; i < TX_RING_SIZE; i++) {
|
1308 |
|
|
printk(KERN_DEBUG " %d: @%p length %8.8x status %8.8x\n", i,
|
1309 |
|
|
&vp->tx_ring[i],
|
1310 |
|
|
le32_to_cpu(vp->tx_ring[i].length),
|
1311 |
|
|
le32_to_cpu(vp->tx_ring[i].status));
|
1312 |
|
|
}
|
1313 |
|
|
}
|
1314 |
|
|
#endif
|
1315 |
|
|
vp->stats.tx_errors++;
|
1316 |
|
|
if (vp->full_bus_master_tx) {
|
1317 |
|
|
if (vortex_debug > 0)
|
1318 |
|
|
printk(KERN_DEBUG "%s: Resetting the Tx ring pointer.\n",
|
1319 |
|
|
dev->name);
|
1320 |
|
|
if (vp->cur_tx - vp->dirty_tx > 0 && inl(ioaddr + DownListPtr) == 0)
|
1321 |
|
|
outl(virt_to_bus(&vp->tx_ring[vp->dirty_tx % TX_RING_SIZE]),
|
1322 |
|
|
ioaddr + DownListPtr);
|
1323 |
|
|
if (vp->tx_full && (vp->cur_tx - vp->dirty_tx <= TX_RING_SIZE - 1)) {
|
1324 |
|
|
vp->tx_full = 0;
|
1325 |
|
|
clear_bit(0, (void*)&dev->tbusy);
|
1326 |
|
|
}
|
1327 |
|
|
outb(PKT_BUF_SZ>>8, ioaddr + TxFreeThreshold);
|
1328 |
|
|
outw(DownUnstall, ioaddr + EL3_CMD);
|
1329 |
|
|
} else
|
1330 |
|
|
vp->stats.tx_dropped++;
|
1331 |
|
|
|
1332 |
|
|
/* Issue Tx Enable */
|
1333 |
|
|
outw(TxEnable, ioaddr + EL3_CMD);
|
1334 |
|
|
dev->trans_start = jiffies;
|
1335 |
|
|
|
1336 |
|
|
/* Switch to register set 7 for normal use. */
|
1337 |
|
|
EL3WINDOW(7);
|
1338 |
|
|
}
|
1339 |
|
|
|
1340 |
|
|
/*
|
1341 |
|
|
* Handle uncommon interrupt sources. This is a separate routine to minimize
|
1342 |
|
|
* the cache impact.
|
1343 |
|
|
*/
|
1344 |
|
|
static void
|
1345 |
|
|
vortex_error(struct device *dev, int status)
|
1346 |
|
|
{
|
1347 |
|
|
struct vortex_private *vp = (struct vortex_private *)dev->priv;
|
1348 |
|
|
long ioaddr = dev->base_addr;
|
1349 |
|
|
int do_tx_reset = 0;
|
1350 |
|
|
int i;
|
1351 |
|
|
|
1352 |
|
|
if (status & TxComplete) { /* Really "TxError" for us. */
|
1353 |
|
|
unsigned char tx_status = inb(ioaddr + TxStatus);
|
1354 |
|
|
/* Presumably a tx-timeout. We must merely re-enable. */
|
1355 |
|
|
if (vortex_debug > 2
|
1356 |
|
|
|| (tx_status != 0x88 && vortex_debug > 0))
|
1357 |
|
|
printk(KERN_DEBUG"%s: Transmit error, Tx status register %2.2x.\n",
|
1358 |
|
|
dev->name, tx_status);
|
1359 |
|
|
if (tx_status & 0x14) vp->stats.tx_fifo_errors++;
|
1360 |
|
|
if (tx_status & 0x38) vp->stats.tx_aborted_errors++;
|
1361 |
|
|
outb(0, ioaddr + TxStatus);
|
1362 |
|
|
if (tx_status & 0x30)
|
1363 |
|
|
do_tx_reset = 1;
|
1364 |
|
|
else /* Merely re-enable the transmitter. */
|
1365 |
|
|
outw(TxEnable, ioaddr + EL3_CMD);
|
1366 |
|
|
}
|
1367 |
|
|
if (status & RxEarly) { /* Rx early is unused. */
|
1368 |
|
|
vortex_rx(dev);
|
1369 |
|
|
outw(AckIntr | RxEarly, ioaddr + EL3_CMD);
|
1370 |
|
|
}
|
1371 |
|
|
if (status & StatsFull) { /* Empty statistics. */
|
1372 |
|
|
static int DoneDidThat = 0;
|
1373 |
|
|
if (vortex_debug > 4)
|
1374 |
|
|
printk(KERN_DEBUG "%s: Updating stats.\n", dev->name);
|
1375 |
|
|
update_stats(ioaddr, dev);
|
1376 |
|
|
/* HACK: Disable statistics as an interrupt source. */
|
1377 |
|
|
/* This occurs when we have the wrong media type! */
|
1378 |
|
|
if (DoneDidThat == 0 &&
|
1379 |
|
|
inw(ioaddr + EL3_STATUS) & StatsFull) {
|
1380 |
|
|
printk(KERN_WARNING "%s: Updating statistics failed, disabling "
|
1381 |
|
|
"stats as an interrupt source.\n", dev->name);
|
1382 |
|
|
EL3WINDOW(5);
|
1383 |
|
|
outw(SetIntrEnb | (inw(ioaddr + 10) & ~StatsFull), ioaddr + EL3_CMD);
|
1384 |
|
|
EL3WINDOW(7);
|
1385 |
|
|
DoneDidThat++;
|
1386 |
|
|
}
|
1387 |
|
|
}
|
1388 |
|
|
if (status & IntReq) { /* Restore all interrupt sources. */
|
1389 |
|
|
outw(vp->status_enable, ioaddr + EL3_CMD);
|
1390 |
|
|
outw(vp->intr_enable, ioaddr + EL3_CMD);
|
1391 |
|
|
}
|
1392 |
|
|
if (status & HostError) {
|
1393 |
|
|
u16 fifo_diag;
|
1394 |
|
|
EL3WINDOW(4);
|
1395 |
|
|
fifo_diag = inw(ioaddr + Wn4_FIFODiag);
|
1396 |
|
|
if (vortex_debug > 0)
|
1397 |
|
|
printk(KERN_ERR "%s: Host error, FIFO diagnostic register %4.4x.\n",
|
1398 |
|
|
dev->name, fifo_diag);
|
1399 |
|
|
/* Adapter failure requires Tx/Rx reset and reinit. */
|
1400 |
|
|
if (vp->full_bus_master_tx) {
|
1401 |
|
|
outw(TotalReset | 0xff, ioaddr + EL3_CMD);
|
1402 |
|
|
for (i = 2000; i >= 0 ; i--)
|
1403 |
|
|
if ( ! (inw(ioaddr + EL3_STATUS) & CmdInProgress))
|
1404 |
|
|
break;
|
1405 |
|
|
/* Re-enable the receiver. */
|
1406 |
|
|
outw(RxEnable, ioaddr + EL3_CMD);
|
1407 |
|
|
outw(TxEnable, ioaddr + EL3_CMD);
|
1408 |
|
|
} else if (fifo_diag & 0x0400)
|
1409 |
|
|
do_tx_reset = 1;
|
1410 |
|
|
if (fifo_diag & 0x3000) {
|
1411 |
|
|
outw(RxReset, ioaddr + EL3_CMD);
|
1412 |
|
|
for (i = 2000; i >= 0 ; i--)
|
1413 |
|
|
if ( ! (inw(ioaddr + EL3_STATUS) & CmdInProgress))
|
1414 |
|
|
break;
|
1415 |
|
|
/* Set the Rx filter to the current state. */
|
1416 |
|
|
set_rx_mode(dev);
|
1417 |
|
|
outw(RxEnable, ioaddr + EL3_CMD); /* Re-enable the receiver. */
|
1418 |
|
|
outw(AckIntr | HostError, ioaddr + EL3_CMD);
|
1419 |
|
|
}
|
1420 |
|
|
}
|
1421 |
|
|
if (do_tx_reset) {
|
1422 |
|
|
int j;
|
1423 |
|
|
outw(TxReset, ioaddr + EL3_CMD);
|
1424 |
|
|
for (j = 200; j >= 0 ; j--)
|
1425 |
|
|
if ( ! (inw(ioaddr + EL3_STATUS) & CmdInProgress))
|
1426 |
|
|
break;
|
1427 |
|
|
outw(TxEnable, ioaddr + EL3_CMD);
|
1428 |
|
|
}
|
1429 |
|
|
|
1430 |
|
|
}
|
1431 |
|
|
|
1432 |
|
|
|
1433 |
|
|
static int
|
1434 |
|
|
vortex_start_xmit(struct sk_buff *skb, struct device *dev)
|
1435 |
|
|
{
|
1436 |
|
|
struct vortex_private *vp = (struct vortex_private *)dev->priv;
|
1437 |
|
|
long ioaddr = dev->base_addr;
|
1438 |
|
|
|
1439 |
|
|
if (test_and_set_bit(0, (void*)&dev->tbusy) != 0) {
|
1440 |
|
|
if (jiffies - dev->trans_start >= TX_TIMEOUT)
|
1441 |
|
|
vortex_tx_timeout(dev);
|
1442 |
|
|
return 1;
|
1443 |
|
|
}
|
1444 |
|
|
|
1445 |
|
|
/* Put out the doubleword header... */
|
1446 |
|
|
outl(skb->len, ioaddr + TX_FIFO);
|
1447 |
|
|
if (vp->bus_master) {
|
1448 |
|
|
/* Set the bus-master controller to transfer the packet. */
|
1449 |
|
|
outl(virt_to_bus(skb->data), ioaddr + Wn7_MasterAddr);
|
1450 |
|
|
outw((skb->len + 3) & ~3, ioaddr + Wn7_MasterLen);
|
1451 |
|
|
vp->tx_skb = skb;
|
1452 |
|
|
outw(StartDMADown, ioaddr + EL3_CMD);
|
1453 |
|
|
/* dev->tbusy will be cleared at the DMADone interrupt. */
|
1454 |
|
|
} else {
|
1455 |
|
|
/* ... and the packet rounded to a doubleword. */
|
1456 |
|
|
outsl(ioaddr + TX_FIFO, skb->data, (skb->len + 3) >> 2);
|
1457 |
|
|
DEV_FREE_SKB(skb);
|
1458 |
|
|
if (inw(ioaddr + TxFree) > 1536) {
|
1459 |
|
|
clear_bit(0, (void*)&dev->tbusy);
|
1460 |
|
|
} else
|
1461 |
|
|
/* Interrupt us when the FIFO has room for max-sized packet. */
|
1462 |
|
|
outw(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD);
|
1463 |
|
|
}
|
1464 |
|
|
|
1465 |
|
|
dev->trans_start = jiffies;
|
1466 |
|
|
|
1467 |
|
|
/* Clear the Tx status stack. */
|
1468 |
|
|
{
|
1469 |
|
|
int tx_status;
|
1470 |
|
|
int i = 32;
|
1471 |
|
|
|
1472 |
|
|
while (--i > 0 && (tx_status = inb(ioaddr + TxStatus)) > 0) {
|
1473 |
|
|
if (tx_status & 0x3C) { /* A Tx-disabling error occurred. */
|
1474 |
|
|
if (vortex_debug > 2)
|
1475 |
|
|
printk(KERN_DEBUG "%s: Tx error, status %2.2x.\n",
|
1476 |
|
|
dev->name, tx_status);
|
1477 |
|
|
if (tx_status & 0x04) vp->stats.tx_fifo_errors++;
|
1478 |
|
|
if (tx_status & 0x38) vp->stats.tx_aborted_errors++;
|
1479 |
|
|
if (tx_status & 0x30) {
|
1480 |
|
|
int j;
|
1481 |
|
|
outw(TxReset, ioaddr + EL3_CMD);
|
1482 |
|
|
for (j = 200; j >= 0 ; j--)
|
1483 |
|
|
if ( ! (inw(ioaddr + EL3_STATUS) & CmdInProgress))
|
1484 |
|
|
break;
|
1485 |
|
|
}
|
1486 |
|
|
outw(TxEnable, ioaddr + EL3_CMD);
|
1487 |
|
|
}
|
1488 |
|
|
outb(0x00, ioaddr + TxStatus); /* Pop the status stack. */
|
1489 |
|
|
}
|
1490 |
|
|
}
|
1491 |
|
|
return 0;
|
1492 |
|
|
}
|
1493 |
|
|
|
1494 |
|
|
static int
|
1495 |
|
|
boomerang_start_xmit(struct sk_buff *skb, struct device *dev)
|
1496 |
|
|
{
|
1497 |
|
|
struct vortex_private *vp = (struct vortex_private *)dev->priv;
|
1498 |
|
|
long ioaddr = dev->base_addr;
|
1499 |
|
|
|
1500 |
|
|
if (test_and_set_bit(0, (void*)&dev->tbusy) != 0) {
|
1501 |
|
|
if (jiffies - dev->trans_start >= TX_TIMEOUT)
|
1502 |
|
|
vortex_tx_timeout(dev);
|
1503 |
|
|
return 1;
|
1504 |
|
|
} else {
|
1505 |
|
|
/* Calculate the next Tx descriptor entry. */
|
1506 |
|
|
int entry = vp->cur_tx % TX_RING_SIZE;
|
1507 |
|
|
struct boom_tx_desc *prev_entry =
|
1508 |
|
|
&vp->tx_ring[(vp->cur_tx-1) % TX_RING_SIZE];
|
1509 |
|
|
unsigned long flags;
|
1510 |
|
|
int i;
|
1511 |
|
|
|
1512 |
|
|
if (vortex_debug > 3)
|
1513 |
|
|
printk(KERN_DEBUG "%s: Trying to send a packet, Tx index %d.\n",
|
1514 |
|
|
dev->name, vp->cur_tx);
|
1515 |
|
|
if (vp->tx_full) {
|
1516 |
|
|
if (vortex_debug >0)
|
1517 |
|
|
printk(KERN_WARNING "%s: Tx Ring full, refusing to send buffer.\n",
|
1518 |
|
|
dev->name);
|
1519 |
|
|
return 1;
|
1520 |
|
|
}
|
1521 |
|
|
vp->tx_skbuff[entry] = skb;
|
1522 |
|
|
vp->tx_ring[entry].next = 0;
|
1523 |
|
|
vp->tx_ring[entry].addr = cpu_to_le32(virt_to_bus(skb->data));
|
1524 |
|
|
vp->tx_ring[entry].length = cpu_to_le32(skb->len | LAST_FRAG);
|
1525 |
|
|
vp->tx_ring[entry].status = cpu_to_le32(skb->len | TxIntrUploaded);
|
1526 |
|
|
|
1527 |
|
|
save_flags(flags);
|
1528 |
|
|
cli();
|
1529 |
|
|
outw(DownStall, ioaddr + EL3_CMD);
|
1530 |
|
|
/* Wait for the stall to complete. */
|
1531 |
|
|
for (i = 600; i >= 0 ; i--)
|
1532 |
|
|
if ( (inw(ioaddr + EL3_STATUS) & CmdInProgress) == 0)
|
1533 |
|
|
break;
|
1534 |
|
|
prev_entry->next = cpu_to_le32(virt_to_bus(&vp->tx_ring[entry]));
|
1535 |
|
|
if (inl(ioaddr + DownListPtr) == 0) {
|
1536 |
|
|
outl(virt_to_bus(&vp->tx_ring[entry]), ioaddr + DownListPtr);
|
1537 |
|
|
queued_packet++;
|
1538 |
|
|
}
|
1539 |
|
|
outw(DownUnstall, ioaddr + EL3_CMD);
|
1540 |
|
|
restore_flags(flags);
|
1541 |
|
|
|
1542 |
|
|
vp->cur_tx++;
|
1543 |
|
|
if (vp->cur_tx - vp->dirty_tx > TX_RING_SIZE - 1)
|
1544 |
|
|
vp->tx_full = 1;
|
1545 |
|
|
else { /* Clear previous interrupt enable. */
|
1546 |
|
|
prev_entry->status &= cpu_to_le32(~TxIntrUploaded);
|
1547 |
|
|
clear_bit(0, (void*)&dev->tbusy);
|
1548 |
|
|
}
|
1549 |
|
|
dev->trans_start = jiffies;
|
1550 |
|
|
return 0;
|
1551 |
|
|
}
|
1552 |
|
|
}
|
1553 |
|
|
|
1554 |
|
|
/* The interrupt handler does all of the Rx thread work and cleans up
|
1555 |
|
|
after the Tx thread. */
|
1556 |
|
|
static void vortex_interrupt(int irq, void *dev_id, struct pt_regs *regs)
|
1557 |
|
|
{
|
1558 |
|
|
struct device *dev = dev_id;
|
1559 |
|
|
struct vortex_private *vp = (struct vortex_private *)dev->priv;
|
1560 |
|
|
long ioaddr;
|
1561 |
|
|
int latency, status;
|
1562 |
|
|
int work_done = max_interrupt_work;
|
1563 |
|
|
|
1564 |
|
|
#if defined(__i386__)
|
1565 |
|
|
/* A lock to prevent simultaneous entry bug on Intel SMP machines. */
|
1566 |
|
|
if (test_and_set_bit(0, (void*)&dev->interrupt)) {
|
1567 |
|
|
printk(KERN_ERR"%s: SMP simultaneous entry of an interrupt handler.\n",
|
1568 |
|
|
dev->name);
|
1569 |
|
|
dev->interrupt = 0; /* Avoid halting machine. */
|
1570 |
|
|
return;
|
1571 |
|
|
}
|
1572 |
|
|
#else
|
1573 |
|
|
if (dev->interrupt) {
|
1574 |
|
|
printk(KERN_ERR "%s: Re-entering the interrupt handler.\n", dev->name);
|
1575 |
|
|
return;
|
1576 |
|
|
}
|
1577 |
|
|
dev->interrupt = 1;
|
1578 |
|
|
#endif
|
1579 |
|
|
|
1580 |
|
|
dev->interrupt = 1;
|
1581 |
|
|
ioaddr = dev->base_addr;
|
1582 |
|
|
latency = inb(ioaddr + Timer);
|
1583 |
|
|
status = inw(ioaddr + EL3_STATUS);
|
1584 |
|
|
|
1585 |
|
|
if (vortex_debug > 4)
|
1586 |
|
|
printk(KERN_DEBUG "%s: interrupt, status %4.4x, latency %d ticks.\n",
|
1587 |
|
|
dev->name, status, latency);
|
1588 |
|
|
do {
|
1589 |
|
|
if (vortex_debug > 5)
|
1590 |
|
|
printk(KERN_DEBUG "%s: In interrupt loop, status %4.4x.\n",
|
1591 |
|
|
dev->name, status);
|
1592 |
|
|
if (status & RxComplete)
|
1593 |
|
|
vortex_rx(dev);
|
1594 |
|
|
if (status & UpComplete) {
|
1595 |
|
|
outw(AckIntr | UpComplete, ioaddr + EL3_CMD);
|
1596 |
|
|
boomerang_rx(dev);
|
1597 |
|
|
}
|
1598 |
|
|
|
1599 |
|
|
if (status & TxAvailable) {
|
1600 |
|
|
if (vortex_debug > 5)
|
1601 |
|
|
printk(KERN_DEBUG " TX room bit was handled.\n");
|
1602 |
|
|
/* There's room in the FIFO for a full-sized packet. */
|
1603 |
|
|
outw(AckIntr | TxAvailable, ioaddr + EL3_CMD);
|
1604 |
|
|
clear_bit(0, (void*)&dev->tbusy);
|
1605 |
|
|
mark_bh(NET_BH);
|
1606 |
|
|
}
|
1607 |
|
|
|
1608 |
|
|
if (status & DownComplete) {
|
1609 |
|
|
unsigned int dirty_tx = vp->dirty_tx;
|
1610 |
|
|
|
1611 |
|
|
while (vp->cur_tx - dirty_tx > 0) {
|
1612 |
|
|
int entry = dirty_tx % TX_RING_SIZE;
|
1613 |
|
|
if (inl(ioaddr + DownListPtr) ==
|
1614 |
|
|
virt_to_bus(&vp->tx_ring[entry]))
|
1615 |
|
|
break; /* It still hasn't been processed. */
|
1616 |
|
|
if (vp->tx_skbuff[entry]) {
|
1617 |
|
|
DEV_FREE_SKB(vp->tx_skbuff[entry]);
|
1618 |
|
|
vp->tx_skbuff[entry] = 0;
|
1619 |
|
|
}
|
1620 |
|
|
/* vp->stats.tx_packets++; Counted below. */
|
1621 |
|
|
dirty_tx++;
|
1622 |
|
|
}
|
1623 |
|
|
vp->dirty_tx = dirty_tx;
|
1624 |
|
|
outw(AckIntr | DownComplete, ioaddr + EL3_CMD);
|
1625 |
|
|
if (vp->tx_full && (vp->cur_tx - dirty_tx <= TX_RING_SIZE - 1)) {
|
1626 |
|
|
vp->tx_full= 0;
|
1627 |
|
|
clear_bit(0, (void*)&dev->tbusy);
|
1628 |
|
|
mark_bh(NET_BH);
|
1629 |
|
|
}
|
1630 |
|
|
}
|
1631 |
|
|
if (status & DMADone) {
|
1632 |
|
|
if (inw(ioaddr + Wn7_MasterStatus) & 0x1000) {
|
1633 |
|
|
outw(0x1000, ioaddr + Wn7_MasterStatus); /* Ack the event. */
|
1634 |
|
|
DEV_FREE_SKB(vp->tx_skb); /* Release the transfered buffer */
|
1635 |
|
|
if (inw(ioaddr + TxFree) > 1536) {
|
1636 |
|
|
clear_bit(0, (void*)&dev->tbusy);
|
1637 |
|
|
mark_bh(NET_BH);
|
1638 |
|
|
} else /* Interrupt when FIFO has room for max-sized packet. */
|
1639 |
|
|
outw(SetTxThreshold + (1536>>2), ioaddr + EL3_CMD);
|
1640 |
|
|
}
|
1641 |
|
|
}
|
1642 |
|
|
/* Check for all uncommon interrupts at once. */
|
1643 |
|
|
if (status & (HostError | RxEarly | StatsFull | TxComplete | IntReq)) {
|
1644 |
|
|
if (status == 0xffff)
|
1645 |
|
|
break;
|
1646 |
|
|
vortex_error(dev, status);
|
1647 |
|
|
}
|
1648 |
|
|
|
1649 |
|
|
if (--work_done < 0) {
|
1650 |
|
|
if ((status & (0x7fe - (UpComplete | DownComplete))) == 0) {
|
1651 |
|
|
/* Just ack these and return. */
|
1652 |
|
|
outw(AckIntr | UpComplete | DownComplete, ioaddr + EL3_CMD);
|
1653 |
|
|
} else {
|
1654 |
|
|
printk(KERN_WARNING "%s: Too much work in interrupt, status "
|
1655 |
|
|
"%4.4x. Temporarily disabling functions (%4.4x).\n",
|
1656 |
|
|
dev->name, status, SetStatusEnb | ((~status) & 0x7FE));
|
1657 |
|
|
/* Disable all pending interrupts. */
|
1658 |
|
|
outw(SetStatusEnb | ((~status) & 0x7FE), ioaddr + EL3_CMD);
|
1659 |
|
|
outw(AckIntr | 0x7FF, ioaddr + EL3_CMD);
|
1660 |
|
|
/* The timer will reenable interrupts. */
|
1661 |
|
|
break;
|
1662 |
|
|
}
|
1663 |
|
|
}
|
1664 |
|
|
/* Acknowledge the IRQ. */
|
1665 |
|
|
outw(AckIntr | IntReq | IntLatch, ioaddr + EL3_CMD);
|
1666 |
|
|
if (vp->cb_fn_base) /* The PCMCIA people are idiots. */
|
1667 |
|
|
writel(0x8000, vp->cb_fn_base + 4);
|
1668 |
|
|
|
1669 |
|
|
} while ((status = inw(ioaddr + EL3_STATUS)) & (IntLatch | RxComplete));
|
1670 |
|
|
|
1671 |
|
|
if (vortex_debug > 4)
|
1672 |
|
|
printk(KERN_DEBUG "%s: exiting interrupt, status %4.4x.\n",
|
1673 |
|
|
dev->name, status);
|
1674 |
|
|
|
1675 |
|
|
#if defined(__i386__)
|
1676 |
|
|
clear_bit(0, (void*)&dev->interrupt);
|
1677 |
|
|
#else
|
1678 |
|
|
dev->interrupt = 0;
|
1679 |
|
|
#endif
|
1680 |
|
|
return;
|
1681 |
|
|
}
|
1682 |
|
|
|
1683 |
|
|
static int vortex_rx(struct device *dev)
|
1684 |
|
|
{
|
1685 |
|
|
struct vortex_private *vp = (struct vortex_private *)dev->priv;
|
1686 |
|
|
long ioaddr = dev->base_addr;
|
1687 |
|
|
int i;
|
1688 |
|
|
short rx_status;
|
1689 |
|
|
|
1690 |
|
|
if (vortex_debug > 5)
|
1691 |
|
|
printk(KERN_DEBUG" In rx_packet(), status %4.4x, rx_status %4.4x.\n",
|
1692 |
|
|
inw(ioaddr+EL3_STATUS), inw(ioaddr+RxStatus));
|
1693 |
|
|
while ((rx_status = inw(ioaddr + RxStatus)) > 0) {
|
1694 |
|
|
if (rx_status & 0x4000) { /* Error, update stats. */
|
1695 |
|
|
unsigned char rx_error = inb(ioaddr + RxErrors);
|
1696 |
|
|
if (vortex_debug > 2)
|
1697 |
|
|
printk(KERN_DEBUG " Rx error: status %2.2x.\n", rx_error);
|
1698 |
|
|
vp->stats.rx_errors++;
|
1699 |
|
|
if (rx_error & 0x01) vp->stats.rx_over_errors++;
|
1700 |
|
|
if (rx_error & 0x02) vp->stats.rx_length_errors++;
|
1701 |
|
|
if (rx_error & 0x04) vp->stats.rx_frame_errors++;
|
1702 |
|
|
if (rx_error & 0x08) vp->stats.rx_crc_errors++;
|
1703 |
|
|
if (rx_error & 0x10) vp->stats.rx_length_errors++;
|
1704 |
|
|
} else {
|
1705 |
|
|
/* The packet length: up to 4.5K!. */
|
1706 |
|
|
int pkt_len = rx_status & 0x1fff;
|
1707 |
|
|
struct sk_buff *skb;
|
1708 |
|
|
|
1709 |
|
|
skb = dev_alloc_skb(pkt_len + 5);
|
1710 |
|
|
if (vortex_debug > 4)
|
1711 |
|
|
printk(KERN_DEBUG "Receiving packet size %d status %4.4x.\n",
|
1712 |
|
|
pkt_len, rx_status);
|
1713 |
|
|
if (skb != NULL) {
|
1714 |
|
|
skb->dev = dev;
|
1715 |
|
|
skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
|
1716 |
|
|
/* 'skb_put()' points to the start of sk_buff data area. */
|
1717 |
|
|
if (vp->bus_master &&
|
1718 |
|
|
! (inw(ioaddr + Wn7_MasterStatus) & 0x8000)) {
|
1719 |
|
|
outl(virt_to_bus(skb_put(skb, pkt_len)),
|
1720 |
|
|
ioaddr + Wn7_MasterAddr);
|
1721 |
|
|
outw((skb->len + 3) & ~3, ioaddr + Wn7_MasterLen);
|
1722 |
|
|
outw(StartDMAUp, ioaddr + EL3_CMD);
|
1723 |
|
|
while (inw(ioaddr + Wn7_MasterStatus) & 0x8000)
|
1724 |
|
|
;
|
1725 |
|
|
} else {
|
1726 |
|
|
insl(ioaddr + RX_FIFO, skb_put(skb, pkt_len),
|
1727 |
|
|
(pkt_len + 3) >> 2);
|
1728 |
|
|
}
|
1729 |
|
|
outw(RxDiscard, ioaddr + EL3_CMD); /* Pop top Rx packet. */
|
1730 |
|
|
skb->protocol = eth_type_trans(skb, dev);
|
1731 |
|
|
netif_rx(skb);
|
1732 |
|
|
dev->last_rx = jiffies;
|
1733 |
|
|
vp->stats.rx_packets++;
|
1734 |
|
|
/* Wait a limited time to go to next packet. */
|
1735 |
|
|
for (i = 200; i >= 0; i--)
|
1736 |
|
|
if ( ! (inw(ioaddr + EL3_STATUS) & CmdInProgress))
|
1737 |
|
|
break;
|
1738 |
|
|
continue;
|
1739 |
|
|
} else if (vortex_debug)
|
1740 |
|
|
printk(KERN_NOTICE "%s: No memory to allocate a sk_buff of "
|
1741 |
|
|
"size %d.\n", dev->name, pkt_len);
|
1742 |
|
|
}
|
1743 |
|
|
outw(RxDiscard, ioaddr + EL3_CMD);
|
1744 |
|
|
vp->stats.rx_dropped++;
|
1745 |
|
|
/* Wait a limited time to skip this packet. */
|
1746 |
|
|
for (i = 200; i >= 0; i--)
|
1747 |
|
|
if ( ! (inw(ioaddr + EL3_STATUS) & CmdInProgress))
|
1748 |
|
|
break;
|
1749 |
|
|
}
|
1750 |
|
|
|
1751 |
|
|
return 0;
|
1752 |
|
|
}
|
1753 |
|
|
|
1754 |
|
|
static int
|
1755 |
|
|
boomerang_rx(struct device *dev)
|
1756 |
|
|
{
|
1757 |
|
|
struct vortex_private *vp = (struct vortex_private *)dev->priv;
|
1758 |
|
|
int entry = vp->cur_rx % RX_RING_SIZE;
|
1759 |
|
|
long ioaddr = dev->base_addr;
|
1760 |
|
|
int rx_status;
|
1761 |
|
|
int rx_work_limit = vp->dirty_rx + RX_RING_SIZE - vp->cur_rx;
|
1762 |
|
|
|
1763 |
|
|
if (vortex_debug > 5)
|
1764 |
|
|
printk(KERN_DEBUG " In boomerang_rx(), status %4.4x, rx_status "
|
1765 |
|
|
"%4.4x.\n",
|
1766 |
|
|
inw(ioaddr+EL3_STATUS), inw(ioaddr+RxStatus));
|
1767 |
|
|
while ((rx_status = le32_to_cpu(vp->rx_ring[entry].status)) & RxDComplete){
|
1768 |
|
|
if (--rx_work_limit < 0)
|
1769 |
|
|
break;
|
1770 |
|
|
if (rx_status & RxDError) { /* Error, update stats. */
|
1771 |
|
|
unsigned char rx_error = rx_status >> 16;
|
1772 |
|
|
if (vortex_debug > 2)
|
1773 |
|
|
printk(KERN_DEBUG " Rx error: status %2.2x.\n", rx_error);
|
1774 |
|
|
vp->stats.rx_errors++;
|
1775 |
|
|
if (rx_error & 0x01) vp->stats.rx_over_errors++;
|
1776 |
|
|
if (rx_error & 0x02) vp->stats.rx_length_errors++;
|
1777 |
|
|
if (rx_error & 0x04) vp->stats.rx_frame_errors++;
|
1778 |
|
|
if (rx_error & 0x08) vp->stats.rx_crc_errors++;
|
1779 |
|
|
if (rx_error & 0x10) vp->stats.rx_length_errors++;
|
1780 |
|
|
} else {
|
1781 |
|
|
/* The packet length: up to 4.5K!. */
|
1782 |
|
|
int pkt_len = rx_status & 0x1fff;
|
1783 |
|
|
struct sk_buff *skb;
|
1784 |
|
|
|
1785 |
|
|
if (vortex_debug > 4)
|
1786 |
|
|
printk(KERN_DEBUG "Receiving packet size %d status %4.4x.\n",
|
1787 |
|
|
pkt_len, rx_status);
|
1788 |
|
|
|
1789 |
|
|
/* Check if the packet is long enough to just accept without
|
1790 |
|
|
copying to a properly sized skbuff. */
|
1791 |
|
|
if (pkt_len < rx_copybreak
|
1792 |
|
|
&& (skb = dev_alloc_skb(pkt_len + 2)) != 0) {
|
1793 |
|
|
skb->dev = dev;
|
1794 |
|
|
skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
|
1795 |
|
|
/* 'skb_put()' points to the start of sk_buff data area. */
|
1796 |
|
|
memcpy(skb_put(skb, pkt_len),
|
1797 |
|
|
bus_to_virt(le32_to_cpu(vp->rx_ring[entry].addr)),
|
1798 |
|
|
pkt_len);
|
1799 |
|
|
rx_copy++;
|
1800 |
|
|
} else {
|
1801 |
|
|
void *temp;
|
1802 |
|
|
/* Pass up the skbuff already on the Rx ring. */
|
1803 |
|
|
skb = vp->rx_skbuff[entry];
|
1804 |
|
|
vp->rx_skbuff[entry] = NULL;
|
1805 |
|
|
temp = skb_put(skb, pkt_len);
|
1806 |
|
|
/* Remove this checking code for final release. */
|
1807 |
|
|
if (bus_to_virt(le32_to_cpu(vp->rx_ring[entry].addr)) != temp)
|
1808 |
|
|
printk(KERN_ERR "%s: Warning -- the skbuff addresses do not match"
|
1809 |
|
|
" in boomerang_rx: %p vs. %p.\n", dev->name,
|
1810 |
|
|
bus_to_virt(le32_to_cpu(vp->rx_ring[entry].addr)),
|
1811 |
|
|
temp);
|
1812 |
|
|
rx_nocopy++;
|
1813 |
|
|
}
|
1814 |
|
|
skb->protocol = eth_type_trans(skb, dev);
|
1815 |
|
|
{ /* Use hardware checksum info. */
|
1816 |
|
|
int csum_bits = rx_status & 0xee000000;
|
1817 |
|
|
if (csum_bits &&
|
1818 |
|
|
(csum_bits == (IPChksumValid | TCPChksumValid) ||
|
1819 |
|
|
csum_bits == (IPChksumValid | UDPChksumValid))) {
|
1820 |
|
|
skb->ip_summed = CHECKSUM_UNNECESSARY;
|
1821 |
|
|
rx_csumhits++;
|
1822 |
|
|
}
|
1823 |
|
|
}
|
1824 |
|
|
netif_rx(skb);
|
1825 |
|
|
dev->last_rx = jiffies;
|
1826 |
|
|
vp->stats.rx_packets++;
|
1827 |
|
|
}
|
1828 |
|
|
entry = (++vp->cur_rx) % RX_RING_SIZE;
|
1829 |
|
|
}
|
1830 |
|
|
/* Refill the Rx ring buffers. */
|
1831 |
|
|
for (; vp->dirty_rx < vp->cur_rx; vp->dirty_rx++) {
|
1832 |
|
|
struct sk_buff *skb;
|
1833 |
|
|
entry = vp->dirty_rx % RX_RING_SIZE;
|
1834 |
|
|
if (vp->rx_skbuff[entry] == NULL) {
|
1835 |
|
|
skb = dev_alloc_skb(PKT_BUF_SZ);
|
1836 |
|
|
if (skb == NULL)
|
1837 |
|
|
break; /* Bad news! */
|
1838 |
|
|
skb->dev = dev; /* Mark as being used by this device. */
|
1839 |
|
|
skb_reserve(skb, 2); /* Align IP on 16 byte boundaries */
|
1840 |
|
|
vp->rx_ring[entry].addr = cpu_to_le32(virt_to_bus(skb->tail));
|
1841 |
|
|
vp->rx_skbuff[entry] = skb;
|
1842 |
|
|
}
|
1843 |
|
|
vp->rx_ring[entry].status = 0; /* Clear complete bit. */
|
1844 |
|
|
outw(UpUnstall, ioaddr + EL3_CMD);
|
1845 |
|
|
}
|
1846 |
|
|
return 0;
|
1847 |
|
|
}
|
1848 |
|
|
|
1849 |
|
|
static int
|
1850 |
|
|
vortex_close(struct device *dev)
|
1851 |
|
|
{
|
1852 |
|
|
struct vortex_private *vp = (struct vortex_private *)dev->priv;
|
1853 |
|
|
long ioaddr = dev->base_addr;
|
1854 |
|
|
int i;
|
1855 |
|
|
|
1856 |
|
|
dev->start = 0;
|
1857 |
|
|
dev->tbusy = 1;
|
1858 |
|
|
|
1859 |
|
|
if (vortex_debug > 1) {
|
1860 |
|
|
printk(KERN_DEBUG"%s: vortex_close() status %4.4x, Tx status %2.2x.\n",
|
1861 |
|
|
dev->name, inw(ioaddr + EL3_STATUS), inb(ioaddr + TxStatus));
|
1862 |
|
|
printk(KERN_DEBUG "%s: vortex close stats: rx_nocopy %d rx_copy %d"
|
1863 |
|
|
" tx_queued %d Rx pre-checksummed %d.\n",
|
1864 |
|
|
dev->name, rx_nocopy, rx_copy, queued_packet, rx_csumhits);
|
1865 |
|
|
}
|
1866 |
|
|
|
1867 |
|
|
del_timer(&vp->timer);
|
1868 |
|
|
|
1869 |
|
|
/* Turn off statistics ASAP. We update vp->stats below. */
|
1870 |
|
|
outw(StatsDisable, ioaddr + EL3_CMD);
|
1871 |
|
|
|
1872 |
|
|
/* Disable the receiver and transmitter. */
|
1873 |
|
|
outw(RxDisable, ioaddr + EL3_CMD);
|
1874 |
|
|
outw(TxDisable, ioaddr + EL3_CMD);
|
1875 |
|
|
|
1876 |
|
|
if (dev->if_port == XCVR_10base2)
|
1877 |
|
|
/* Turn off thinnet power. Green! */
|
1878 |
|
|
outw(StopCoax, ioaddr + EL3_CMD);
|
1879 |
|
|
|
1880 |
|
|
free_irq(dev->irq, dev);
|
1881 |
|
|
|
1882 |
|
|
outw(SetIntrEnb | 0x0000, ioaddr + EL3_CMD);
|
1883 |
|
|
|
1884 |
|
|
update_stats(ioaddr, dev);
|
1885 |
|
|
if (vp->full_bus_master_rx) { /* Free Boomerang bus master Rx buffers. */
|
1886 |
|
|
outl(0, ioaddr + UpListPtr);
|
1887 |
|
|
for (i = 0; i < RX_RING_SIZE; i++)
|
1888 |
|
|
if (vp->rx_skbuff[i]) {
|
1889 |
|
|
#if LINUX_VERSION_CODE < 0x20100
|
1890 |
|
|
vp->rx_skbuff[i]->free = 1;
|
1891 |
|
|
#endif
|
1892 |
|
|
DEV_FREE_SKB(vp->rx_skbuff[i]);
|
1893 |
|
|
vp->rx_skbuff[i] = 0;
|
1894 |
|
|
}
|
1895 |
|
|
}
|
1896 |
|
|
if (vp->full_bus_master_tx) { /* Free Boomerang bus master Tx buffers. */
|
1897 |
|
|
outl(0, ioaddr + DownListPtr);
|
1898 |
|
|
for (i = 0; i < TX_RING_SIZE; i++)
|
1899 |
|
|
if (vp->tx_skbuff[i]) {
|
1900 |
|
|
DEV_FREE_SKB(vp->tx_skbuff[i]);
|
1901 |
|
|
vp->tx_skbuff[i] = 0;
|
1902 |
|
|
}
|
1903 |
|
|
}
|
1904 |
|
|
|
1905 |
|
|
MOD_DEC_USE_COUNT;
|
1906 |
|
|
|
1907 |
|
|
return 0;
|
1908 |
|
|
}
|
1909 |
|
|
|
1910 |
|
|
static struct net_device_stats *vortex_get_stats(struct device *dev)
|
1911 |
|
|
{
|
1912 |
|
|
struct vortex_private *vp = (struct vortex_private *)dev->priv;
|
1913 |
|
|
unsigned long flags;
|
1914 |
|
|
|
1915 |
|
|
if (dev->start) {
|
1916 |
|
|
save_flags(flags);
|
1917 |
|
|
cli();
|
1918 |
|
|
update_stats(dev->base_addr, dev);
|
1919 |
|
|
restore_flags(flags);
|
1920 |
|
|
}
|
1921 |
|
|
return &vp->stats;
|
1922 |
|
|
}
|
1923 |
|
|
|
1924 |
|
|
/* Update statistics.
|
1925 |
|
|
Unlike with the EL3 we need not worry about interrupts changing
|
1926 |
|
|
the window setting from underneath us, but we must still guard
|
1927 |
|
|
against a race condition with a StatsUpdate interrupt updating the
|
1928 |
|
|
table. This is done by checking that the ASM (!) code generated uses
|
1929 |
|
|
atomic updates with '+='.
|
1930 |
|
|
*/
|
1931 |
|
|
static void update_stats(long ioaddr, struct device *dev)
|
1932 |
|
|
{
|
1933 |
|
|
struct vortex_private *vp = (struct vortex_private *)dev->priv;
|
1934 |
|
|
|
1935 |
|
|
/* Unlike the 3c5x9 we need not turn off stats updates while reading. */
|
1936 |
|
|
/* Switch to the stats window, and read everything. */
|
1937 |
|
|
EL3WINDOW(6);
|
1938 |
|
|
vp->stats.tx_carrier_errors += inb(ioaddr + 0);
|
1939 |
|
|
vp->stats.tx_heartbeat_errors += inb(ioaddr + 1);
|
1940 |
|
|
/* Multiple collisions. */ inb(ioaddr + 2);
|
1941 |
|
|
vp->stats.collisions += inb(ioaddr + 3);
|
1942 |
|
|
vp->stats.tx_window_errors += inb(ioaddr + 4);
|
1943 |
|
|
vp->stats.rx_fifo_errors += inb(ioaddr + 5);
|
1944 |
|
|
vp->stats.tx_packets += inb(ioaddr + 6);
|
1945 |
|
|
vp->stats.tx_packets += (inb(ioaddr + 9)&0x30) << 4;
|
1946 |
|
|
/* Rx packets */ inb(ioaddr + 7); /* Must read to clear */
|
1947 |
|
|
/* Tx deferrals */ inb(ioaddr + 8);
|
1948 |
|
|
/* Don't bother with register 9, an extension of registers 6&7.
|
1949 |
|
|
If we do use the 6&7 values the atomic update assumption above
|
1950 |
|
|
is invalid. */
|
1951 |
|
|
inw(ioaddr + 10); /* Total Rx and Tx octets. */
|
1952 |
|
|
inw(ioaddr + 12);
|
1953 |
|
|
/* New: On the Vortex we must also clear the BadSSD counter. */
|
1954 |
|
|
EL3WINDOW(4);
|
1955 |
|
|
inb(ioaddr + 12);
|
1956 |
|
|
|
1957 |
|
|
/* We change back to window 7 (not 1) with the Vortex. */
|
1958 |
|
|
EL3WINDOW(7);
|
1959 |
|
|
return;
|
1960 |
|
|
}
|
1961 |
|
|
|
1962 |
|
|
static int vortex_ioctl(struct device *dev, struct ifreq *rq, int cmd)
|
1963 |
|
|
{
|
1964 |
|
|
struct vortex_private *vp = (struct vortex_private *)dev->priv;
|
1965 |
|
|
long ioaddr = dev->base_addr;
|
1966 |
|
|
u16 *data = (u16 *)&rq->ifr_data;
|
1967 |
|
|
int phy = vp->phys[0] & 0x1f;
|
1968 |
|
|
|
1969 |
|
|
switch(cmd) {
|
1970 |
|
|
case SIOCDEVPRIVATE: /* Get the address of the PHY in use. */
|
1971 |
|
|
data[0] = phy;
|
1972 |
|
|
case SIOCDEVPRIVATE+1: /* Read the specified MII register. */
|
1973 |
|
|
EL3WINDOW(4);
|
1974 |
|
|
data[3] = mdio_read(ioaddr, data[0] & 0x1f, data[1] & 0x1f);
|
1975 |
|
|
return 0;
|
1976 |
|
|
case SIOCDEVPRIVATE+2: /* Write the specified MII register */
|
1977 |
|
|
if (!suser())
|
1978 |
|
|
return -EPERM;
|
1979 |
|
|
EL3WINDOW(4);
|
1980 |
|
|
mdio_write(ioaddr, data[0] & 0x1f, data[1] & 0x1f, data[2]);
|
1981 |
|
|
return 0;
|
1982 |
|
|
default:
|
1983 |
|
|
return -EOPNOTSUPP;
|
1984 |
|
|
}
|
1985 |
|
|
}
|
1986 |
|
|
|
1987 |
|
|
/* Pre-Cyclone chips have no documented multicast filter, so the only
|
1988 |
|
|
multicast setting is to receive all multicast frames. At least
|
1989 |
|
|
the chip has a very clean way to set the mode, unlike many others. */
|
1990 |
|
|
static void set_rx_mode(struct device *dev)
|
1991 |
|
|
{
|
1992 |
|
|
long ioaddr = dev->base_addr;
|
1993 |
|
|
int new_mode;
|
1994 |
|
|
|
1995 |
|
|
if (dev->flags & IFF_PROMISC) {
|
1996 |
|
|
if (vortex_debug > 0)
|
1997 |
|
|
printk(KERN_NOTICE "%s: Setting promiscuous mode.\n", dev->name);
|
1998 |
|
|
new_mode = SetRxFilter|RxStation|RxMulticast|RxBroadcast|RxProm;
|
1999 |
|
|
} else if ((dev->mc_list) || (dev->flags & IFF_ALLMULTI)) {
|
2000 |
|
|
new_mode = SetRxFilter|RxStation|RxMulticast|RxBroadcast;
|
2001 |
|
|
} else
|
2002 |
|
|
new_mode = SetRxFilter | RxStation | RxBroadcast;
|
2003 |
|
|
|
2004 |
|
|
outw(new_mode, ioaddr + EL3_CMD);
|
2005 |
|
|
}
|
2006 |
|
|
|
2007 |
|
|
|
2008 |
|
|
/* MII transceiver control section.
|
2009 |
|
|
Read and write the MII registers using software-generated serial
|
2010 |
|
|
MDIO protocol. See the MII specifications or DP83840A data sheet
|
2011 |
|
|
for details. */
|
2012 |
|
|
|
2013 |
|
|
/* The maximum data clock rate is 2.5 Mhz. The minimum timing is usually
|
2014 |
|
|
met by back-to-back PCI I/O cycles, but we insert a delay to avoid
|
2015 |
|
|
"overclocking" issues. */
|
2016 |
|
|
#define mdio_delay() inl(mdio_addr)
|
2017 |
|
|
|
2018 |
|
|
#define MDIO_SHIFT_CLK 0x01
|
2019 |
|
|
#define MDIO_DIR_WRITE 0x04
|
2020 |
|
|
#define MDIO_DATA_WRITE0 (0x00 | MDIO_DIR_WRITE)
|
2021 |
|
|
#define MDIO_DATA_WRITE1 (0x02 | MDIO_DIR_WRITE)
|
2022 |
|
|
#define MDIO_DATA_READ 0x02
|
2023 |
|
|
#define MDIO_ENB_IN 0x00
|
2024 |
|
|
|
2025 |
|
|
/* Generate the preamble required for initial synchronization and
|
2026 |
|
|
a few older transceivers. */
|
2027 |
|
|
static void mdio_sync(long ioaddr, int bits)
|
2028 |
|
|
{
|
2029 |
|
|
long mdio_addr = ioaddr + Wn4_PhysicalMgmt;
|
2030 |
|
|
|
2031 |
|
|
/* Establish sync by sending at least 32 logic ones. */
|
2032 |
|
|
while (-- bits >= 0) {
|
2033 |
|
|
outw(MDIO_DATA_WRITE1, mdio_addr);
|
2034 |
|
|
mdio_delay();
|
2035 |
|
|
outw(MDIO_DATA_WRITE1 | MDIO_SHIFT_CLK, mdio_addr);
|
2036 |
|
|
mdio_delay();
|
2037 |
|
|
}
|
2038 |
|
|
}
|
2039 |
|
|
|
2040 |
|
|
static int mdio_read(long ioaddr, int phy_id, int location)
|
2041 |
|
|
{
|
2042 |
|
|
int i;
|
2043 |
|
|
int read_cmd = (0xf6 << 10) | (phy_id << 5) | location;
|
2044 |
|
|
unsigned int retval = 0;
|
2045 |
|
|
long mdio_addr = ioaddr + Wn4_PhysicalMgmt;
|
2046 |
|
|
|
2047 |
|
|
if (mii_preamble_required)
|
2048 |
|
|
mdio_sync(ioaddr, 32);
|
2049 |
|
|
|
2050 |
|
|
/* Shift the read command bits out. */
|
2051 |
|
|
for (i = 14; i >= 0; i--) {
|
2052 |
|
|
int dataval = (read_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
|
2053 |
|
|
outw(dataval, mdio_addr);
|
2054 |
|
|
mdio_delay();
|
2055 |
|
|
outw(dataval | MDIO_SHIFT_CLK, mdio_addr);
|
2056 |
|
|
mdio_delay();
|
2057 |
|
|
}
|
2058 |
|
|
/* Read the two transition, 16 data, and wire-idle bits. */
|
2059 |
|
|
for (i = 19; i > 0; i--) {
|
2060 |
|
|
outw(MDIO_ENB_IN, mdio_addr);
|
2061 |
|
|
mdio_delay();
|
2062 |
|
|
retval = (retval << 1) | ((inw(mdio_addr) & MDIO_DATA_READ) ? 1 : 0);
|
2063 |
|
|
outw(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
|
2064 |
|
|
mdio_delay();
|
2065 |
|
|
}
|
2066 |
|
|
#if 0
|
2067 |
|
|
return (retval>>1) & 0x1ffff;
|
2068 |
|
|
#else
|
2069 |
|
|
return retval & 0x20000 ? 0xffff : retval>>1 & 0xffff;
|
2070 |
|
|
#endif
|
2071 |
|
|
}
|
2072 |
|
|
|
2073 |
|
|
static void mdio_write(long ioaddr, int phy_id, int location, int value)
|
2074 |
|
|
{
|
2075 |
|
|
int write_cmd = 0x50020000 | (phy_id << 23) | (location << 18) | value;
|
2076 |
|
|
long mdio_addr = ioaddr + Wn4_PhysicalMgmt;
|
2077 |
|
|
int i;
|
2078 |
|
|
|
2079 |
|
|
if (mii_preamble_required)
|
2080 |
|
|
mdio_sync(ioaddr, 32);
|
2081 |
|
|
|
2082 |
|
|
/* Shift the command bits out. */
|
2083 |
|
|
for (i = 31; i >= 0; i--) {
|
2084 |
|
|
int dataval = (write_cmd&(1<<i)) ? MDIO_DATA_WRITE1 : MDIO_DATA_WRITE0;
|
2085 |
|
|
outw(dataval, mdio_addr);
|
2086 |
|
|
mdio_delay();
|
2087 |
|
|
outw(dataval | MDIO_SHIFT_CLK, mdio_addr);
|
2088 |
|
|
mdio_delay();
|
2089 |
|
|
}
|
2090 |
|
|
/* Leave the interface idle. */
|
2091 |
|
|
for (i = 1; i >= 0; i--) {
|
2092 |
|
|
outw(MDIO_ENB_IN, mdio_addr);
|
2093 |
|
|
mdio_delay();
|
2094 |
|
|
outw(MDIO_ENB_IN | MDIO_SHIFT_CLK, mdio_addr);
|
2095 |
|
|
mdio_delay();
|
2096 |
|
|
}
|
2097 |
|
|
|
2098 |
|
|
return;
|
2099 |
|
|
}
|
2100 |
|
|
|
2101 |
|
|
|
2102 |
|
|
#ifdef MODULE
|
2103 |
|
|
void cleanup_module(void)
|
2104 |
|
|
{
|
2105 |
|
|
struct device *next_dev;
|
2106 |
|
|
|
2107 |
|
|
#ifdef CARDBUS
|
2108 |
|
|
unregister_driver(&vortex_ops);
|
2109 |
|
|
#endif
|
2110 |
|
|
|
2111 |
|
|
/* No need to check MOD_IN_USE, as sys_delete_module() checks. */
|
2112 |
|
|
while (root_vortex_dev) {
|
2113 |
|
|
struct vortex_private *vp=(void *)(root_vortex_dev->priv);
|
2114 |
|
|
next_dev = vp->next_module;
|
2115 |
|
|
unregister_netdev(root_vortex_dev);
|
2116 |
|
|
outw(TotalReset, root_vortex_dev->base_addr + EL3_CMD);
|
2117 |
|
|
release_region(root_vortex_dev->base_addr,
|
2118 |
|
|
pci_tbl[vp->chip_id].io_size);
|
2119 |
|
|
kfree(root_vortex_dev);
|
2120 |
|
|
kfree(vp->priv_addr);
|
2121 |
|
|
root_vortex_dev = next_dev;
|
2122 |
|
|
}
|
2123 |
|
|
}
|
2124 |
|
|
|
2125 |
|
|
#endif /* MODULE */
|
2126 |
|
|
|
2127 |
|
|
/*
|
2128 |
|
|
* Local variables:
|
2129 |
|
|
* compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c 3c59x.c `[ -f /usr/include/linux/modversions.h ] && echo -DMODVERSIONS`"
|
2130 |
|
|
* SMP-compile-command: "gcc -D__SMP__ -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c 3c59x.c"
|
2131 |
|
|
* cardbus-compile-command: "gcc -DCARDBUS -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c 3c59x.c -o 3c575_cb.o -I/usr/src/pcmcia-cs-3.0.5/include/"
|
2132 |
|
|
* c-indent-level: 4
|
2133 |
|
|
* c-basic-offset: 4
|
2134 |
|
|
* tab-width: 4
|
2135 |
|
|
* End:
|
2136 |
|
|
*/
|