1 /* 3c515.c: A 3Com ISA EtherLink XL "Corkscrew" ethernet driver for linux. */
3 Written 1997-1998 by Donald Becker.
5 This software may be used and distributed according to the terms
6 of the GNU Public License, incorporated herein by reference.
8 This driver is for the 3Com ISA EtherLink XL "Corkscrew" 3c515 ethercard.
10 The author may be reached as becker@CESDIS.gsfc.nasa.gov, or C/O
11 Center of Excellence in Space Data and Information Sciences
12 Code 930.5, Goddard Space Flight Center, Greenbelt MD 20771
14 2/2/00- Added support for kernel-level ISAPnP
15 by Stephen Frost <sfrost@snowman.net> and Alessandro Zummo
16 Cleaned up for 2.3.x/softnet by Jeff Garzik and Alan Cox.
19 static char *version
= "3c515.c:v0.99-sn 2000/02/12 becker@cesdis.gsfc.nasa.gov and others\n";
23 /* "Knobs" that adjust features and parameters. */
24 /* Set the copy breakpoint for the copy-only-tiny-frames scheme.
25 Setting to > 1512 effectively disables this feature. */
26 static const int rx_copybreak
= 200;
28 /* Allow setting MTU to a larger size, bypassing the normal ethernet setup. */
29 static const int mtu
= 1500;
31 /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
32 static int max_interrupt_work
= 20;
34 /* Enable the automatic media selection code -- usually set. */
37 /* Allow the use of fragment bus master transfers instead of only
38 programmed-I/O for Vortex cards. Full-bus-master transfers are always
39 enabled by default on Boomerang cards. If VORTEX_BUS_MASTER is defined,
40 the feature may be turned on using 'options'. */
41 #define VORTEX_BUS_MASTER
43 /* A few values that may be tweaked. */
44 /* Keep the ring sizes a power of two for efficiency. */
45 #define TX_RING_SIZE 16
46 #define RX_RING_SIZE 16
47 #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer. */
49 #include <linux/config.h>
50 #include <linux/module.h>
51 #include <linux/version.h>
52 #include <linux/isapnp.h>
54 #include <linux/kernel.h>
55 #include <linux/sched.h>
56 #include <linux/string.h>
57 #include <linux/ptrace.h>
58 #include <linux/errno.h>
60 #include <linux/ioport.h>
61 #include <linux/malloc.h>
62 #include <linux/interrupt.h>
63 #include <linux/timer.h>
64 #include <asm/bitops.h>
68 #include <linux/netdevice.h>
69 #include <linux/etherdevice.h>
70 #include <linux/skbuff.h>
73 #include <linux/delay.h>
75 /* Kernel version compatibility functions. */
76 #define RUN_AT(x) (jiffies + (x))
78 #define REQUEST_IRQ(i,h,f,n, instance) request_irq(i,h,f,n, instance)
79 #define IRQ(irq, dev_id, pt_regs) (irq, dev_id, pt_regs)
81 MODULE_AUTHOR("Donald Becker <becker@cesdis.gsfc.nasa.gov>");
82 MODULE_DESCRIPTION("3Com 3c515 Corkscrew driver");
83 MODULE_PARM(debug
, "i");
84 MODULE_PARM(options
, "1-" __MODULE_STRING(8) "i");
85 MODULE_PARM(full_duplex
, "1-" __MODULE_STRING(8) "i");
86 MODULE_PARM(rx_copybreak
, "i");
87 MODULE_PARM(max_interrupt_work
, "i");
89 /* "Knobs" for adjusting internal parameters. */
90 /* Put out somewhat more debugging messages. (0 - no msg, 1 minimal msgs). */
91 #define DRIVER_DEBUG 1
92 /* Some values here only for performance evaluation and path-coverage
94 static int rx_nocopy
= 0, rx_copy
= 0, queued_packet
= 0;
96 /* Number of times to check to see if the Tx FIFO has space, used in some
98 #define WAIT_TX_AVAIL 200
100 /* Operational parameter that usually are not changed. */
101 #define TX_TIMEOUT 40 /* Time in jiffies before concluding Tx hung */
103 /* The size here is somewhat misleading: the Corkscrew also uses the ISA
104 aliased registers at <base>+0x400.
106 #define CORKSCREW_TOTAL_SIZE 0x20
109 int corkscrew_debug
= DRIVER_DEBUG
;
111 int corkscrew_debug
= 1;
114 #define CORKSCREW_ID 10
119 I. Board Compatibility
121 This device driver is designed for the 3Com 3c515 ISA Fast EtherLink XL,
122 3Com's ISA bus adapter for Fast Ethernet. Due to the unique I/O port layout,
123 it's not practical to integrate this driver with the other EtherLink drivers.
125 II. Board-specific settings
127 The Corkscrew has an EEPROM for configuration, but no special settings are
130 III. Driver operation
132 The 3c515 series use an interface that's very similar to the 3c900 "Boomerang"
133 PCI cards, with the bus master interface extensively modified to work with
136 The card is capable of full-bus-master transfers with separate
137 lists of transmit and receive descriptors, similar to the AMD LANCE/PCnet,
138 DEC Tulip and Intel Speedo3.
140 This driver uses a "RX_COPYBREAK" scheme rather than a fixed intermediate
141 receive buffer. This scheme allocates full-sized skbuffs as receive
142 buffers. The value RX_COPYBREAK is used as the copying breakpoint: it is
143 chosen to trade-off the memory wasted by passing the full-sized skbuff to
144 the queue layer for all frames vs. the copying cost of copying a frame to a
145 correctly-sized skbuff.
148 IIIC. Synchronization
149 The driver runs as two independent, single-threaded flows of control. One
150 is the send-packet routine, which enforces single-threaded use by the netif
151 layer. The other thread is the interrupt handler, which is single
152 threaded by the hardware and other software.
156 Thanks to Terry Murphy of 3Com for providing documentation and a development
159 The names "Vortex", "Boomerang" and "Corkscrew" are the internal 3Com
160 project names. I use these names to eliminate confusion -- 3Com product
161 numbers and names are very similar and often confused.
163 The new chips support both ethernet (1.5K) and FDDI (4.5K) frame sizes!
164 This driver only supports ethernet frames because of the recent MTU limit
165 of 1.5K, but the changes to support 4.5K are minimal.
168 /* Operational definitions.
169 These are not used by other compilation units and thus are not
170 exported in a ".h" file.
172 First the windows. There are eight register windows, with the command
173 and status registers available in each.
175 #define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
177 #define EL3_STATUS 0x0e
179 /* The top five bits written to EL3_CMD are a command, the lower
180 11 bits are the parameter, if applicable.
181 Note that 11 parameters bits was fine for ethernet, but the new chips
182 can handle FDDI length frames (~4500 octets) and now parameters count
183 32-bit 'Dwords' rather than octets. */
186 TotalReset
= 0 << 11, SelectWindow
= 1 << 11, StartCoax
= 2 << 11,
187 RxDisable
= 3 << 11, RxEnable
= 4 << 11, RxReset
= 5 << 11,
188 UpStall
= 6 << 11, UpUnstall
= (6 << 11) + 1,
189 DownStall
= (6 << 11) + 2, DownUnstall
= (6 << 11) + 3,
190 RxDiscard
= 8 << 11, TxEnable
= 9 << 11, TxDisable
=
191 10 << 11, TxReset
= 11 << 11,
192 FakeIntr
= 12 << 11, AckIntr
= 13 << 11, SetIntrEnb
= 14 << 11,
193 SetStatusEnb
= 15 << 11, SetRxFilter
= 16 << 11, SetRxThreshold
=
195 SetTxThreshold
= 18 << 11, SetTxStart
= 19 << 11,
196 StartDMAUp
= 20 << 11, StartDMADown
= (20 << 11) + 1, StatsEnable
=
198 StatsDisable
= 22 << 11, StopCoax
= 23 << 11,
201 /* The SetRxFilter command accepts the following classes: */
203 RxStation
= 1, RxMulticast
= 2, RxBroadcast
= 4, RxProm
= 8
206 /* Bits in the general status register. */
207 enum corkscrew_status
{
208 IntLatch
= 0x0001, AdapterFailure
= 0x0002, TxComplete
= 0x0004,
209 TxAvailable
= 0x0008, RxComplete
= 0x0010, RxEarly
= 0x0020,
210 IntReq
= 0x0040, StatsFull
= 0x0080,
211 DMADone
= 1 << 8, DownComplete
= 1 << 9, UpComplete
= 1 << 10,
212 DMAInProgress
= 1 << 11, /* DMA controller is still busy. */
213 CmdInProgress
= 1 << 12, /* EL3_CMD is still busy. */
216 /* Register window 1 offsets, the window used in normal operation.
217 On the Corkscrew this window is always mapped at offsets 0x10-0x1f. */
219 TX_FIFO
= 0x10, RX_FIFO
= 0x10, RxErrors
= 0x14,
220 RxStatus
= 0x18, Timer
= 0x1A, TxStatus
= 0x1B,
221 TxFree
= 0x1C, /* Remaining free bytes in Tx buffer. */
225 #if defined(CORKSCREW)
226 Wn0EepromCmd
= 0x200A, /* Corkscrew EEPROM command register. */
227 Wn0EepromData
= 0x200C, /* Corkscrew EEPROM results register. */
229 Wn0EepromCmd
= 10, /* Window 0: EEPROM command register. */
230 Wn0EepromData
= 12, /* Window 0: EEPROM results register. */
233 enum Win0_EEPROM_bits
{
234 EEPROM_Read
= 0x80, EEPROM_WRITE
= 0x40, EEPROM_ERASE
= 0xC0,
235 EEPROM_EWENB
= 0x30, /* Enable erasing/writing for 10 msec. */
236 EEPROM_EWDIS
= 0x00, /* Disable EWENB before 10 msec timeout. */
239 /* EEPROM locations. */
241 PhysAddr01
= 0, PhysAddr23
= 1, PhysAddr45
= 2, ModelID
= 3,
245 enum Window3
{ /* Window 3: MAC/config bits. */
246 Wn3_Config
= 0, Wn3_MAC_Ctrl
= 6, Wn3_Options
= 8,
250 struct w3_config_fields
{
251 unsigned int ram_size
:3, ram_width
:1, ram_speed
:2,
254 unsigned int ram_split
:2, pad18
:2, xcvr
:3, pad21
:1,
261 Wn4_NetDiag
= 6, Wn4_Media
= 10, /* Window 4: Xcvr/media bits. */
263 enum Win4_Media_bits
{
264 Media_SQE
= 0x0008, /* Enable SQE error counting for AUI. */
265 Media_10TP
= 0x00C0, /* Enable link beat and jabber for 10baseT. */
266 Media_Lnk
= 0x0080, /* Enable just link beat for 100TX/100FX. */
267 Media_LnkBeat
= 0x0800,
269 enum Window7
{ /* Window 7: Bus Master control. */
270 Wn7_MasterAddr
= 0, Wn7_MasterLen
= 6, Wn7_MasterStatus
= 12,
273 /* Boomerang-style bus master control registers. Note ISA aliases! */
275 PktStatus
= 0x400, DownListPtr
= 0x404, FragAddr
= 0x408, FragLen
=
277 TxFreeThreshold
= 0x40f, UpPktStatus
= 0x410, UpListPtr
= 0x418,
280 /* The Rx and Tx descriptor lists.
281 Caution Alpha hackers: these types are 32 bits! Note also the 8 byte
282 alignment contraint on tx_ring[] and rx_ring[]. */
283 struct boom_rx_desc
{
290 /* Values for the Rx status entry. */
291 enum rx_desc_status
{
292 RxDComplete
= 0x00008000, RxDError
= 0x4000,
293 /* See boomerang_rx() for actual error bits */
296 struct boom_tx_desc
{
303 struct corkscrew_private
{
304 char devname
[8]; /* "ethN" string, also for kernel debug. */
305 const char *product_name
;
306 struct net_device
*next_module
;
307 /* The Rx and Tx rings are here to keep them quad-word-aligned. */
308 struct boom_rx_desc rx_ring
[RX_RING_SIZE
];
309 struct boom_tx_desc tx_ring
[TX_RING_SIZE
];
310 /* The addresses of transmit- and receive-in-place skbuffs. */
311 struct sk_buff
*rx_skbuff
[RX_RING_SIZE
];
312 struct sk_buff
*tx_skbuff
[TX_RING_SIZE
];
313 unsigned int cur_rx
, cur_tx
; /* The next free ring entry */
314 unsigned int dirty_rx
, dirty_tx
;/* The ring entries to be free()ed. */
315 struct enet_statistics stats
;
316 struct sk_buff
*tx_skb
; /* Packet being eaten by bus master ctrl. */
317 struct timer_list timer
; /* Media selection timer. */
318 int capabilities
; /* Adapter capabilities word. */
319 int options
; /* User-settable misc. driver options. */
320 int last_rx_packets
; /* For media autoselection. */
321 unsigned int available_media
:8, /* From Wn3_Options */
322 media_override
:3, /* Passed-in media type. */
323 default_media
:3, /* Read from the EEPROM. */
324 full_duplex
:1, autoselect
:1, bus_master
:1, /* Vortex can only do a fragment bus-m. */
325 full_bus_master_tx
:1, full_bus_master_rx
:1, /* Boomerang */
329 /* The action to take with a media selection timer tick.
330 Note that we deviate from the 3Com order by checking 10base2 before AUI.
334 0, XCVR_AUI
, XCVR_10baseTOnly
, XCVR_10base2
, XCVR_100baseTx
,
335 XCVR_100baseFx
, XCVR_MII
= 6, XCVR_Default
= 8,
338 static struct media_table
{
340 unsigned int media_bits
:16, /* Bits to set in Wn4_Media register. */
341 mask
:8, /* The transceiver-present bit in Wn3_Config. */
342 next
:8; /* The media type to try next. */
343 short wait
; /* Time before we check media status. */
345 { "10baseT", Media_10TP
, 0x08, XCVR_10base2
, (14 * HZ
) / 10 },
346 { "10Mbs AUI", Media_SQE
, 0x20, XCVR_Default
, (1 * HZ
) / 10},
347 { "undefined", 0, 0x80, XCVR_10baseT
, 10000},
348 { "10base2", 0, 0x10, XCVR_AUI
, (1 * HZ
) / 10},
349 { "100baseTX", Media_Lnk
, 0x02, XCVR_100baseFx
, (14 * HZ
) / 10},
350 { "100baseFX", Media_Lnk
, 0x04, XCVR_MII
, (14 * HZ
) / 10},
351 { "MII", 0, 0x40, XCVR_10baseT
, 3 * HZ
},
352 { "undefined", 0, 0x01, XCVR_10baseT
, 10000},
353 { "Default", 0, 0xFF, XCVR_10baseT
, 10000},
357 struct corkscrew_isapnp_adapters_struct
{
358 unsigned short vendor
, function
;
361 struct corkscrew_isapnp_adapters_struct corkscrew_isapnp_adapters
[] = {
362 {ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5051), "3Com Fast EtherLink ISA"},
365 int corkscrew_isapnp_phys_addr
[3] = {
369 static int nopnp
= 0;
371 static int corkscrew_scan(struct net_device
*dev
);
372 static struct net_device
*corkscrew_found_device(struct net_device
*dev
,
376 static int corkscrew_probe1(struct net_device
*dev
);
377 static int corkscrew_open(struct net_device
*dev
);
378 static void corkscrew_timer(unsigned long arg
);
379 static int corkscrew_start_xmit(struct sk_buff
*skb
,
380 struct net_device
*dev
);
381 static int corkscrew_rx(struct net_device
*dev
);
382 static void corkscrew_timeout(struct net_device
*dev
);
383 static int boomerang_rx(struct net_device
*dev
);
384 static void corkscrew_interrupt(int irq
, void *dev_id
,
385 struct pt_regs
*regs
);
386 static int corkscrew_close(struct net_device
*dev
);
387 static void update_stats(int addr
, struct net_device
*dev
);
388 static struct enet_statistics
*corkscrew_get_stats(struct net_device
*dev
);
389 static void set_rx_mode(struct net_device
*dev
);
393 Unfortunately maximizing the shared code between the integrated and
394 module version of the driver results in a complicated set of initialization
396 init_module() -- modules / tc59x_init() -- built-in
397 The wrappers for corkscrew_scan()
398 corkscrew_scan() The common routine that scans for PCI and EISA cards
399 corkscrew_found_device() Allocate a device structure when we find a card.
400 Different versions exist for modules and built-in.
401 corkscrew_probe1() Fill in the device structure -- this is separated
402 so that the modules code can put it in dev->init.
404 /* This driver uses 'options' to pass the media type, full-duplex flag, etc. */
405 /* Note: this is the only limit on the number of cards supported!! */
406 static int options
[8] = { -1, -1, -1, -1, -1, -1, -1, -1, };
409 static int debug
= -1;
410 /* A list of all installed Vortex devices, for removing the driver module. */
411 static struct net_device
*root_corkscrew_dev
= NULL
;
413 int init_module(void)
418 corkscrew_debug
= debug
;
422 root_corkscrew_dev
= NULL
;
423 cards_found
= corkscrew_scan(0);
424 return cards_found
? 0 : -ENODEV
;
428 int tc515_probe(struct net_device
*dev
)
432 cards_found
= corkscrew_scan(dev
);
434 if (corkscrew_debug
> 0 && cards_found
)
437 return cards_found
? 0 : -ENODEV
;
439 #endif /* not MODULE */
441 static int corkscrew_scan(struct net_device
*dev
)
446 static int pnp_cards
= 0;
451 for(i
=0; corkscrew_isapnp_adapters
[i
].vendor
!= 0; i
++) {
452 struct pci_dev
*idev
= NULL
;
454 while((idev
= isapnp_find_dev(NULL
,
455 corkscrew_isapnp_adapters
[i
].vendor
,
456 corkscrew_isapnp_adapters
[i
].function
,
459 if(idev
->active
) idev
->deactivate(idev
);
461 if(idev
->prepare(idev
)<0)
463 if (!(idev
->resource
[0].flags
& IORESOURCE_IO
))
465 if(idev
->activate(idev
)<0) {
466 printk("isapnp configure failed (out of resources?)\n");
469 if (!idev
->resource
[0].start
|| check_region(idev
->resource
[0].start
,16))
471 ioaddr
= idev
->resource
[0].start
;
472 irq
= idev
->irq_resource
[0].start
;
474 printk ("ISAPNP reports %s at i/o 0x%x, irq %d\n",
475 corkscrew_isapnp_adapters
[i
].name
,ioaddr
, irq
);
477 if ((inw(ioaddr
+ 0x2002) & 0x1f0) != (ioaddr
& 0x1f0))
479 /* Verify by reading the device ID from the EEPROM. */
482 outw(EEPROM_Read
+ 7, ioaddr
+ Wn0EepromCmd
);
483 /* Pause for at least 162 us. for the read to take place. */
484 for (timer
= 4; timer
>= 0; timer
--) {
486 if ((inw(ioaddr
+ Wn0EepromCmd
) & 0x0200)
490 if (inw(ioaddr
+ Wn0EepromData
) != 0x6d50)
493 printk(KERN_INFO
"3c515 Resource configuraiton register %#4.4x, DCR %4.4x.\n",
494 inl(ioaddr
+ 0x2002), inw(ioaddr
+ 0x2000));
495 /* irq = inw(ioaddr + 0x2002) & 15; */ /* Use the irq from isapnp */
496 corkscrew_isapnp_phys_addr
[pnp_cards
] = ioaddr
;
497 corkscrew_found_device(dev
, ioaddr
, irq
, CORKSCREW_ID
, dev
498 && dev
->mem_start
? dev
->
499 mem_start
: options
[cards_found
]);
506 #endif /* not CONFIG_ISAPNP */
508 /* Check all locations on the ISA bus -- evil! */
509 for (ioaddr
= 0x100; ioaddr
< 0x400; ioaddr
+= 0x20) {
512 /* Make sure this was not already picked up by isapnp */
513 if(ioaddr
== corkscrew_isapnp_phys_addr
[0]) continue;
514 if(ioaddr
== corkscrew_isapnp_phys_addr
[1]) continue;
515 if(ioaddr
== corkscrew_isapnp_phys_addr
[2]) continue;
517 if (check_region(ioaddr
, CORKSCREW_TOTAL_SIZE
))
519 /* Check the resource configuration for a matching ioaddr. */
520 if ((inw(ioaddr
+ 0x2002) & 0x1f0) != (ioaddr
& 0x1f0))
522 /* Verify by reading the device ID from the EEPROM. */
525 outw(EEPROM_Read
+ 7, ioaddr
+ Wn0EepromCmd
);
526 /* Pause for at least 162 us. for the read to take place. */
527 for (timer
= 4; timer
>= 0; timer
--) {
529 if ((inw(ioaddr
+ Wn0EepromCmd
) & 0x0200)
533 if (inw(ioaddr
+ Wn0EepromData
) != 0x6d50)
536 printk(KERN_INFO
"3c515 Resource configuraiton register %#4.4x, DCR %4.4x.\n",
537 inl(ioaddr
+ 0x2002), inw(ioaddr
+ 0x2000));
538 irq
= inw(ioaddr
+ 0x2002) & 15;
539 corkscrew_found_device(dev
, ioaddr
, irq
, CORKSCREW_ID
, dev
540 && dev
->mem_start
? dev
->
541 mem_start
: options
[cards_found
]);
546 printk(KERN_INFO
"%d 3c515 cards found.\n", cards_found
);
550 static struct net_device
*corkscrew_found_device(struct net_device
*dev
,
555 struct corkscrew_private
*vp
;
558 /* Allocate and fill new device structure. */
559 int dev_size
= sizeof(struct net_device
) +
560 sizeof(struct corkscrew_private
) + 15; /* Pad for alignment */
562 dev
= (struct net_device
*) kmalloc(dev_size
, GFP_KERNEL
);
563 memset(dev
, 0, dev_size
);
564 /* Align the Rx and Tx ring entries. */
566 (void *) (((long) dev
+ sizeof(struct net_device
) + 15) & ~15);
567 vp
= (struct corkscrew_private
*) dev
->priv
;
568 dev
->name
= vp
->devname
; /* An empty string. */
569 dev
->base_addr
= ioaddr
;
572 (product_index
== CORKSCREW_ID
? inw(ioaddr
+ 0x2000) & 7 : 0);
573 dev
->init
= corkscrew_probe1
;
574 vp
->product_name
= "3c515";
575 vp
->options
= options
;
578 ((options
& 7) == 2) ? 0 : options
& 7;
579 vp
->full_duplex
= (options
& 8) ? 1 : 0;
580 vp
->bus_master
= (options
& 16) ? 1 : 0;
582 vp
->media_override
= 7;
587 vp
->next_module
= root_corkscrew_dev
;
588 root_corkscrew_dev
= dev
;
589 if (register_netdev(dev
) != 0)
591 #else /* not a MODULE */
593 /* Caution: quad-word alignment required for rings! */
595 kmalloc(sizeof(struct corkscrew_private
), GFP_KERNEL
);
596 memset(dev
->priv
, 0, sizeof(struct corkscrew_private
));
598 dev
= init_etherdev(dev
, sizeof(struct corkscrew_private
));
599 dev
->base_addr
= ioaddr
;
602 (product_index
== CORKSCREW_ID
? inw(ioaddr
+ 0x2000) & 7 : 0);
603 vp
= (struct corkscrew_private
*) dev
->priv
;
604 vp
->product_name
= "3c515";
605 vp
->options
= options
;
608 ((options
& 7) == 2) ? 0 : options
& 7;
609 vp
->full_duplex
= (options
& 8) ? 1 : 0;
610 vp
->bus_master
= (options
& 16) ? 1 : 0;
612 vp
->media_override
= 7;
617 corkscrew_probe1(dev
);
622 static int corkscrew_probe1(struct net_device
*dev
)
624 int ioaddr
= dev
->base_addr
;
625 struct corkscrew_private
*vp
=
626 (struct corkscrew_private
*) dev
->priv
;
627 unsigned int eeprom
[0x40], checksum
= 0; /* EEPROM contents */
630 printk(KERN_INFO
"%s: 3Com %s at %#3x,", dev
->name
,
631 vp
->product_name
, ioaddr
);
633 /* Read the station address from the EEPROM. */
635 for (i
= 0; i
< 0x18; i
++) {
636 short *phys_addr
= (short *) dev
->dev_addr
;
638 outw(EEPROM_Read
+ i
, ioaddr
+ Wn0EepromCmd
);
639 /* Pause for at least 162 us. for the read to take place. */
640 for (timer
= 4; timer
>= 0; timer
--) {
642 if ((inw(ioaddr
+ Wn0EepromCmd
) & 0x0200) == 0)
645 eeprom
[i
] = inw(ioaddr
+ Wn0EepromData
);
646 checksum
^= eeprom
[i
];
648 phys_addr
[i
] = htons(eeprom
[i
]);
650 checksum
= (checksum
^ (checksum
>> 8)) & 0xff;
651 if (checksum
!= 0x00)
652 printk(" ***INVALID CHECKSUM %4.4x*** ", checksum
);
653 for (i
= 0; i
< 6; i
++)
654 printk("%c%2.2x", i
? ':' : ' ', dev
->dev_addr
[i
]);
655 if (eeprom
[16] == 0x11c7) { /* Corkscrew */
656 if (request_dma(dev
->dma
, "3c515")) {
657 printk(", DMA %d allocation failed", dev
->dma
);
660 printk(", DMA %d", dev
->dma
);
662 printk(", IRQ %d\n", dev
->irq
);
663 /* Tell them about an invalid IRQ. */
664 if (corkscrew_debug
&& (dev
->irq
<= 0 || dev
->irq
> 15))
665 printk(KERN_WARNING
" *** Warning: this IRQ is unlikely to work! ***\n");
668 char *ram_split
[] = { "5:3", "3:1", "1:1", "3:5" };
669 union wn3_config config
;
671 vp
->available_media
= inw(ioaddr
+ Wn3_Options
);
672 config
.i
= inl(ioaddr
+ Wn3_Config
);
673 if (corkscrew_debug
> 1)
674 printk(KERN_INFO
" Internal config register is %4.4x, transceivers %#x.\n",
675 config
.i
, inw(ioaddr
+ Wn3_Options
));
676 printk(KERN_INFO
" %dK %s-wide RAM %s Rx:Tx split, %s%s interface.\n",
677 8 << config
.u
.ram_size
,
678 config
.u
.ram_width
? "word" : "byte",
679 ram_split
[config
.u
.ram_split
],
680 config
.u
.autoselect
? "autoselect/" : "",
681 media_tbl
[config
.u
.xcvr
].name
);
682 dev
->if_port
= config
.u
.xcvr
;
683 vp
->default_media
= config
.u
.xcvr
;
684 vp
->autoselect
= config
.u
.autoselect
;
686 if (vp
->media_override
!= 7) {
687 printk(KERN_INFO
" Media override to transceiver type %d (%s).\n",
689 media_tbl
[vp
->media_override
].name
);
690 dev
->if_port
= vp
->media_override
;
693 vp
->capabilities
= eeprom
[16];
694 vp
->full_bus_master_tx
= (vp
->capabilities
& 0x20) ? 1 : 0;
695 /* Rx is broken at 10mbps, so we always disable it. */
696 /* vp->full_bus_master_rx = 0; */
697 vp
->full_bus_master_rx
= (vp
->capabilities
& 0x20) ? 1 : 0;
699 /* We do a request_region() to register /proc/ioports info. */
700 request_region(ioaddr
, CORKSCREW_TOTAL_SIZE
, vp
->product_name
);
702 /* The 3c51x-specific entries in the device structure. */
703 dev
->open
= &corkscrew_open
;
704 dev
->hard_start_xmit
= &corkscrew_start_xmit
;
705 dev
->tx_timeout
= &corkscrew_timeout
;
706 dev
->watchdog_timeo
= (400 * HZ
) / 1000;
707 dev
->stop
= &corkscrew_close
;
708 dev
->get_stats
= &corkscrew_get_stats
;
709 dev
->set_multicast_list
= &set_rx_mode
;
715 static int corkscrew_open(struct net_device
*dev
)
717 int ioaddr
= dev
->base_addr
;
718 struct corkscrew_private
*vp
=
719 (struct corkscrew_private
*) dev
->priv
;
720 union wn3_config config
;
723 /* Before initializing select the active media port. */
726 outb(0x20, ioaddr
+ Wn3_MAC_Ctrl
); /* Set the full-duplex bit. */
727 config
.i
= inl(ioaddr
+ Wn3_Config
);
729 if (vp
->media_override
!= 7) {
730 if (corkscrew_debug
> 1)
731 printk(KERN_INFO
"%s: Media override to transceiver %d (%s).\n",
732 dev
->name
, vp
->media_override
,
733 media_tbl
[vp
->media_override
].name
);
734 dev
->if_port
= vp
->media_override
;
735 } else if (vp
->autoselect
) {
736 /* Find first available media type, starting with 100baseTx. */
738 while (!(vp
->available_media
& media_tbl
[dev
->if_port
].mask
))
739 dev
->if_port
= media_tbl
[dev
->if_port
].next
;
741 if (corkscrew_debug
> 1)
742 printk("%s: Initial media type %s.\n",
743 dev
->name
, media_tbl
[dev
->if_port
].name
);
745 init_timer(&vp
->timer
);
746 vp
->timer
.expires
= RUN_AT(media_tbl
[dev
->if_port
].wait
);
747 vp
->timer
.data
= (unsigned long) dev
;
748 vp
->timer
.function
= &corkscrew_timer
; /* timer handler */
749 add_timer(&vp
->timer
);
751 dev
->if_port
= vp
->default_media
;
753 config
.u
.xcvr
= dev
->if_port
;
754 outl(config
.i
, ioaddr
+ Wn3_Config
);
756 if (corkscrew_debug
> 1) {
757 printk("%s: corkscrew_open() InternalConfig %8.8x.\n",
758 dev
->name
, config
.i
);
761 outw(TxReset
, ioaddr
+ EL3_CMD
);
762 for (i
= 20; i
>= 0; i
--)
763 if (!(inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
))
766 outw(RxReset
, ioaddr
+ EL3_CMD
);
767 /* Wait a few ticks for the RxReset command to complete. */
768 for (i
= 20; i
>= 0; i
--)
769 if (!(inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
))
772 outw(SetStatusEnb
| 0x00, ioaddr
+ EL3_CMD
);
774 /* Use the now-standard shared IRQ implementation. */
775 if (vp
->capabilities
== 0x11c7) {
776 /* Corkscrew: Cannot share ISA resources. */
779 || request_irq(dev
->irq
, &corkscrew_interrupt
, 0,
780 vp
->product_name
, dev
)) return -EAGAIN
;
781 enable_dma(dev
->dma
);
782 set_dma_mode(dev
->dma
, DMA_MODE_CASCADE
);
783 } else if (request_irq(dev
->irq
, &corkscrew_interrupt
, SA_SHIRQ
,
784 vp
->product_name
, dev
)) {
788 if (corkscrew_debug
> 1) {
790 printk("%s: corkscrew_open() irq %d media status %4.4x.\n",
791 dev
->name
, dev
->irq
, inw(ioaddr
+ Wn4_Media
));
794 /* Set the station address and mask in window 2 each time opened. */
796 for (i
= 0; i
< 6; i
++)
797 outb(dev
->dev_addr
[i
], ioaddr
+ i
);
798 for (; i
< 12; i
+= 2)
801 if (dev
->if_port
== 3)
802 /* Start the thinnet transceiver. We should really wait 50ms... */
803 outw(StartCoax
, ioaddr
+ EL3_CMD
);
805 outw((inw(ioaddr
+ Wn4_Media
) & ~(Media_10TP
| Media_SQE
)) |
806 media_tbl
[dev
->if_port
].media_bits
, ioaddr
+ Wn4_Media
);
808 /* Switch to the stats window, and clear all stats by reading. */
809 outw(StatsDisable
, ioaddr
+ EL3_CMD
);
811 for (i
= 0; i
< 10; i
++)
815 /* New: On the Vortex we must also clear the BadSSD counter. */
818 /* ..and on the Boomerang we enable the extra statistics bits. */
819 outw(0x0040, ioaddr
+ Wn4_NetDiag
);
821 /* Switch to register set 7 for normal use. */
824 if (vp
->full_bus_master_rx
) { /* Boomerang bus master. */
825 vp
->cur_rx
= vp
->dirty_rx
= 0;
826 if (corkscrew_debug
> 2)
827 printk("%s: Filling in the Rx ring.\n",
829 for (i
= 0; i
< RX_RING_SIZE
; i
++) {
831 if (i
< (RX_RING_SIZE
- 1))
832 vp
->rx_ring
[i
].next
=
833 virt_to_bus(&vp
->rx_ring
[i
+ 1]);
835 vp
->rx_ring
[i
].next
= 0;
836 vp
->rx_ring
[i
].status
= 0; /* Clear complete bit. */
837 vp
->rx_ring
[i
].length
= PKT_BUF_SZ
| 0x80000000;
838 skb
= dev_alloc_skb(PKT_BUF_SZ
);
839 vp
->rx_skbuff
[i
] = skb
;
841 break; /* Bad news! */
842 skb
->dev
= dev
; /* Mark as being used by this device. */
843 skb_reserve(skb
, 2); /* Align IP on 16 byte boundaries */
844 vp
->rx_ring
[i
].addr
= virt_to_bus(skb
->tail
);
846 vp
->rx_ring
[i
- 1].next
= virt_to_bus(&vp
->rx_ring
[0]); /* Wrap the ring. */
847 outl(virt_to_bus(&vp
->rx_ring
[0]), ioaddr
+ UpListPtr
);
849 if (vp
->full_bus_master_tx
) { /* Boomerang bus master Tx. */
850 vp
->cur_tx
= vp
->dirty_tx
= 0;
851 outb(PKT_BUF_SZ
>> 8, ioaddr
+ TxFreeThreshold
); /* Room for a packet. */
852 /* Clear the Tx ring. */
853 for (i
= 0; i
< TX_RING_SIZE
; i
++)
854 vp
->tx_skbuff
[i
] = 0;
855 outl(0, ioaddr
+ DownListPtr
);
857 /* Set receiver mode: presumably accept b-case and phys addr only. */
859 outw(StatsEnable
, ioaddr
+ EL3_CMD
); /* Turn on statistics. */
861 netif_start_queue(dev
);
863 outw(RxEnable
, ioaddr
+ EL3_CMD
); /* Enable the receiver. */
864 outw(TxEnable
, ioaddr
+ EL3_CMD
); /* Enable transmitter. */
865 /* Allow status bits to be seen. */
866 outw(SetStatusEnb
| AdapterFailure
| IntReq
| StatsFull
|
867 (vp
->full_bus_master_tx
? DownComplete
: TxAvailable
) |
868 (vp
->full_bus_master_rx
? UpComplete
: RxComplete
) |
869 (vp
->bus_master
? DMADone
: 0), ioaddr
+ EL3_CMD
);
870 /* Ack all pending events, and set active indicator mask. */
871 outw(AckIntr
| IntLatch
| TxAvailable
| RxEarly
| IntReq
,
873 outw(SetIntrEnb
| IntLatch
| TxAvailable
| RxComplete
| StatsFull
874 | (vp
->bus_master
? DMADone
: 0) | UpComplete
| DownComplete
,
882 static void corkscrew_timer(unsigned long data
)
885 struct net_device
*dev
= (struct net_device
*) data
;
886 struct corkscrew_private
*vp
=
887 (struct corkscrew_private
*) dev
->priv
;
888 int ioaddr
= dev
->base_addr
;
892 if (corkscrew_debug
> 1)
893 printk("%s: Media selection timer tick happened, %s.\n",
894 dev
->name
, media_tbl
[dev
->if_port
].name
);
898 int old_window
= inw(ioaddr
+ EL3_CMD
) >> 13;
901 media_status
= inw(ioaddr
+ Wn4_Media
);
902 switch (dev
->if_port
) {
905 case 5: /* 10baseT, 100baseTX, 100baseFX */
906 if (media_status
& Media_LnkBeat
) {
908 if (corkscrew_debug
> 1)
909 printk("%s: Media %s has link beat, %x.\n",
911 media_tbl
[dev
->if_port
].name
,
913 } else if (corkscrew_debug
> 1)
914 printk("%s: Media %s is has no link beat, %x.\n",
916 media_tbl
[dev
->if_port
].name
,
920 default: /* Other media types handled by Tx timeouts. */
921 if (corkscrew_debug
> 1)
922 printk("%s: Media %s is has no indication, %x.\n",
924 media_tbl
[dev
->if_port
].name
,
929 union wn3_config config
;
933 media_tbl
[dev
->if_port
].next
;
935 while (!(vp
->available_media
& media_tbl
[dev
->if_port
].mask
));
937 if (dev
->if_port
== 8) { /* Go back to default. */
938 dev
->if_port
= vp
->default_media
;
939 if (corkscrew_debug
> 1)
940 printk("%s: Media selection failing, using default %s port.\n",
942 media_tbl
[dev
->if_port
].name
);
944 if (corkscrew_debug
> 1)
945 printk("%s: Media selection failed, now trying %s port.\n",
947 media_tbl
[dev
->if_port
].name
);
948 vp
->timer
.expires
= RUN_AT(media_tbl
[dev
->if_port
].wait
);
949 add_timer(&vp
->timer
);
951 outw((media_status
& ~(Media_10TP
| Media_SQE
)) |
952 media_tbl
[dev
->if_port
].media_bits
,
956 config
.i
= inl(ioaddr
+ Wn3_Config
);
957 config
.u
.xcvr
= dev
->if_port
;
958 outl(config
.i
, ioaddr
+ Wn3_Config
);
960 outw(dev
->if_port
== 3 ? StartCoax
: StopCoax
,
963 EL3WINDOW(old_window
);
965 restore_flags(flags
);
966 if (corkscrew_debug
> 1)
967 printk("%s: Media selection timer finished, %s.\n",
968 dev
->name
, media_tbl
[dev
->if_port
].name
);
970 #endif /* AUTOMEDIA */
974 static void corkscrew_timeout(struct net_device
*dev
)
977 struct corkscrew_private
*vp
=
978 (struct corkscrew_private
*) dev
->priv
;
979 int ioaddr
= dev
->base_addr
;
982 "%s: transmit timed out, tx_status %2.2x status %4.4x.\n",
983 dev
->name
, inb(ioaddr
+ TxStatus
),
984 inw(ioaddr
+ EL3_STATUS
));
985 /* Slight code bloat to be user friendly. */
986 if ((inb(ioaddr
+ TxStatus
) & 0x88) == 0x88)
988 "%s: Transmitter encountered 16 collisions -- network"
989 " network cable problem?\n", dev
->name
);
990 #ifndef final_version
991 printk(" Flags; bus-master %d, full %d; dirty %d current %d.\n",
992 vp
->full_bus_master_tx
, vp
->tx_full
, vp
->dirty_tx
,
994 printk(" Down list %8.8x vs. %p.\n", inl(ioaddr
+ DownListPtr
),
996 for (i
= 0; i
< TX_RING_SIZE
; i
++) {
997 printk(" %d: %p length %8.8x status %8.8x\n", i
,
999 vp
->tx_ring
[i
].length
, vp
->tx_ring
[i
].status
);
1002 /* Issue TX_RESET and TX_START commands. */
1003 outw(TxReset
, ioaddr
+ EL3_CMD
);
1004 for (i
= 20; i
>= 0; i
--)
1005 if (!(inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
))
1007 outw(TxEnable
, ioaddr
+ EL3_CMD
);
1008 dev
->trans_start
= jiffies
;
1009 vp
->stats
.tx_errors
++;
1010 vp
->stats
.tx_dropped
++;
1011 netif_wake_queue(dev
);
1014 static int corkscrew_start_xmit(struct sk_buff
*skb
,
1015 struct net_device
*dev
)
1017 struct corkscrew_private
*vp
=
1018 (struct corkscrew_private
*) dev
->priv
;
1019 int ioaddr
= dev
->base_addr
;
1021 /* Block a timer-based transmit from overlapping. */
1023 netif_stop_queue(dev
);
1025 if (vp
->full_bus_master_tx
) { /* BOOMERANG bus-master */
1026 /* Calculate the next Tx descriptor entry. */
1027 int entry
= vp
->cur_tx
% TX_RING_SIZE
;
1028 struct boom_tx_desc
*prev_entry
;
1029 unsigned long flags
, i
;
1031 if (vp
->tx_full
) /* No room to transmit with */
1033 if (vp
->cur_tx
!= 0)
1035 &vp
->tx_ring
[(vp
->cur_tx
- 1) % TX_RING_SIZE
];
1038 if (corkscrew_debug
> 3)
1039 printk("%s: Trying to send a packet, Tx index %d.\n",
1040 dev
->name
, vp
->cur_tx
);
1041 /* vp->tx_full = 1; */
1042 vp
->tx_skbuff
[entry
] = skb
;
1043 vp
->tx_ring
[entry
].next
= 0;
1044 vp
->tx_ring
[entry
].addr
= virt_to_bus(skb
->data
);
1045 vp
->tx_ring
[entry
].length
= skb
->len
| 0x80000000;
1046 vp
->tx_ring
[entry
].status
= skb
->len
| 0x80000000;
1050 outw(DownStall
, ioaddr
+ EL3_CMD
);
1051 /* Wait for the stall to complete. */
1052 for (i
= 20; i
>= 0; i
--)
1053 if ((inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
) ==
1057 virt_to_bus(&vp
->tx_ring
[entry
]);
1058 if (inl(ioaddr
+ DownListPtr
) == 0) {
1059 outl(virt_to_bus(&vp
->tx_ring
[entry
]),
1060 ioaddr
+ DownListPtr
);
1063 outw(DownUnstall
, ioaddr
+ EL3_CMD
);
1064 restore_flags(flags
);
1067 if (vp
->cur_tx
- vp
->dirty_tx
> TX_RING_SIZE
- 1)
1069 else { /* Clear previous interrupt enable. */
1071 prev_entry
->status
&= ~0x80000000;
1072 netif_wake_queue(dev
);
1074 dev
->trans_start
= jiffies
;
1077 /* Put out the doubleword header... */
1078 outl(skb
->len
, ioaddr
+ TX_FIFO
);
1079 #ifdef VORTEX_BUS_MASTER
1080 if (vp
->bus_master
) {
1081 /* Set the bus-master controller to transfer the packet. */
1082 outl((int) (skb
->data
), ioaddr
+ Wn7_MasterAddr
);
1083 outw((skb
->len
+ 3) & ~3, ioaddr
+ Wn7_MasterLen
);
1085 outw(StartDMADown
, ioaddr
+ EL3_CMD
);
1086 /* queue will be woken at the DMADone interrupt. */
1088 /* ... and the packet rounded to a doubleword. */
1089 outsl(ioaddr
+ TX_FIFO
, skb
->data
, (skb
->len
+ 3) >> 2);
1091 if (inw(ioaddr
+ TxFree
) > 1536) {
1092 netif_wake_queue(dev
);
1094 /* Interrupt us when the FIFO has room for max-sized packet. */
1095 outw(SetTxThreshold
+ (1536 >> 2),
1099 /* ... and the packet rounded to a doubleword. */
1100 outsl(ioaddr
+ TX_FIFO
, skb
->data
, (skb
->len
+ 3) >> 2);
1102 if (inw(ioaddr
+ TxFree
) > 1536) {
1103 netif_wake_queue(dev
);
1105 /* Interrupt us when the FIFO has room for max-sized packet. */
1106 outw(SetTxThreshold
+ (1536 >> 2), ioaddr
+ EL3_CMD
);
1107 #endif /* bus master */
1109 dev
->trans_start
= jiffies
;
1111 /* Clear the Tx status stack. */
1116 while (--i
> 0 && (tx_status
= inb(ioaddr
+ TxStatus
)) > 0) {
1117 if (tx_status
& 0x3C) { /* A Tx-disabling error occurred. */
1118 if (corkscrew_debug
> 2)
1119 printk("%s: Tx error, status %2.2x.\n",
1120 dev
->name
, tx_status
);
1121 if (tx_status
& 0x04)
1122 vp
->stats
.tx_fifo_errors
++;
1123 if (tx_status
& 0x38)
1124 vp
->stats
.tx_aborted_errors
++;
1125 if (tx_status
& 0x30) {
1127 outw(TxReset
, ioaddr
+ EL3_CMD
);
1128 for (j
= 20; j
>= 0; j
--)
1129 if (!(inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
))
1132 outw(TxEnable
, ioaddr
+ EL3_CMD
);
1134 outb(0x00, ioaddr
+ TxStatus
); /* Pop the status stack. */
1137 vp
->stats
.tx_bytes
+= skb
->len
;
1141 /* The interrupt handler does all of the Rx thread work and cleans up
1142 after the Tx thread. */
1144 static void corkscrew_interrupt(int irq
, void *dev_id
,
1145 struct pt_regs
*regs
)
1147 /* Use the now-standard shared IRQ implementation. */
1148 struct net_device
*dev
= dev_id
;
1149 struct corkscrew_private
*lp
;
1152 int i
= max_interrupt_work
;
1154 ioaddr
= dev
->base_addr
;
1155 latency
= inb(ioaddr
+ Timer
);
1156 lp
= (struct corkscrew_private
*) dev
->priv
;
1158 status
= inw(ioaddr
+ EL3_STATUS
);
1160 if (corkscrew_debug
> 4)
1161 printk("%s: interrupt, status %4.4x, timer %d.\n",
1162 dev
->name
, status
, latency
);
1163 if ((status
& 0xE000) != 0xE000) {
1164 static int donedidthis
= 0;
1165 /* Some interrupt controllers store a bogus interrupt from boot-time.
1166 Ignore a single early interrupt, but don't hang the machine for
1167 other interrupt problems. */
1168 if (donedidthis
++ > 100) {
1169 printk(KERN_ERR
"%s: Bogus interrupt, bailing. Status %4.4x, start=%d.\n",
1170 dev
->name
, status
, netif_running(dev
));
1171 free_irq(dev
->irq
, dev
);
1176 if (corkscrew_debug
> 5)
1177 printk("%s: In interrupt loop, status %4.4x.\n",
1179 if (status
& RxComplete
)
1182 if (status
& TxAvailable
) {
1183 if (corkscrew_debug
> 5)
1185 (" TX room bit was handled.\n");
1186 /* There's room in the FIFO for a full-sized packet. */
1187 outw(AckIntr
| TxAvailable
, ioaddr
+ EL3_CMD
);
1188 netif_wake_queue(dev
);
1190 if (status
& DownComplete
) {
1191 unsigned int dirty_tx
= lp
->dirty_tx
;
1193 while (lp
->cur_tx
- dirty_tx
> 0) {
1194 int entry
= dirty_tx
% TX_RING_SIZE
;
1195 if (inl(ioaddr
+ DownListPtr
) ==
1196 virt_to_bus(&lp
->tx_ring
[entry
]))
1197 break; /* It still hasn't been processed. */
1198 if (lp
->tx_skbuff
[entry
]) {
1199 dev_kfree_skb_irq(lp
->
1202 lp
->tx_skbuff
[entry
] = 0;
1206 lp
->dirty_tx
= dirty_tx
;
1207 outw(AckIntr
| DownComplete
, ioaddr
+ EL3_CMD
);
1209 && (lp
->cur_tx
- dirty_tx
<= TX_RING_SIZE
- 1)) {
1211 netif_wake_queue(dev
);
1214 #ifdef VORTEX_BUS_MASTER
1215 if (status
& DMADone
) {
1216 outw(0x1000, ioaddr
+ Wn7_MasterStatus
); /* Ack the event. */
1217 dev_kfree_skb_irq(lp
->tx_skb
); /* Release the transfered buffer */
1218 netif_wake_queue(dev
);
1221 if (status
& UpComplete
) {
1223 outw(AckIntr
| UpComplete
, ioaddr
+ EL3_CMD
);
1225 if (status
& (AdapterFailure
| RxEarly
| StatsFull
)) {
1226 /* Handle all uncommon interrupts at once. */
1227 if (status
& RxEarly
) { /* Rx early is unused. */
1229 outw(AckIntr
| RxEarly
, ioaddr
+ EL3_CMD
);
1231 if (status
& StatsFull
) { /* Empty statistics. */
1232 static int DoneDidThat
= 0;
1233 if (corkscrew_debug
> 4)
1234 printk("%s: Updating stats.\n",
1236 update_stats(ioaddr
, dev
);
1237 /* DEBUG HACK: Disable statistics as an interrupt source. */
1238 /* This occurs when we have the wrong media type! */
1239 if (DoneDidThat
== 0 &&
1240 inw(ioaddr
+ EL3_STATUS
) & StatsFull
) {
1242 printk("%s: Updating stats failed, disabling stats as an"
1243 " interrupt source.\n",
1245 for (win
= 0; win
< 8; win
++) {
1247 printk("\n Vortex window %d:", win
);
1248 for (reg
= 0; reg
< 16; reg
++)
1253 outw(SetIntrEnb
| TxAvailable
|
1254 RxComplete
| AdapterFailure
|
1255 UpComplete
| DownComplete
|
1256 TxComplete
, ioaddr
+ EL3_CMD
);
1260 if (status
& AdapterFailure
) {
1261 /* Adapter failure requires Rx reset and reinit. */
1262 outw(RxReset
, ioaddr
+ EL3_CMD
);
1263 /* Set the Rx filter to the current state. */
1265 outw(RxEnable
, ioaddr
+ EL3_CMD
); /* Re-enable the receiver. */
1266 outw(AckIntr
| AdapterFailure
,
1272 printk(KERN_ERR
"%s: Too much work in interrupt, status %4.4x. "
1273 "Disabling functions (%4.4x).\n", dev
->name
,
1274 status
, SetStatusEnb
| ((~status
) & 0x7FE));
1275 /* Disable all pending interrupts. */
1276 outw(SetStatusEnb
| ((~status
) & 0x7FE),
1278 outw(AckIntr
| 0x7FF, ioaddr
+ EL3_CMD
);
1281 /* Acknowledge the IRQ. */
1282 outw(AckIntr
| IntReq
| IntLatch
, ioaddr
+ EL3_CMD
);
1284 } while ((status
= inw(ioaddr
+ EL3_STATUS
)) &
1285 (IntLatch
| RxComplete
));
1287 if (corkscrew_debug
> 4)
1288 printk("%s: exiting interrupt, status %4.4x.\n", dev
->name
,
1292 static int corkscrew_rx(struct net_device
*dev
)
1294 struct corkscrew_private
*vp
= (struct corkscrew_private
*) dev
->priv
;
1295 int ioaddr
= dev
->base_addr
;
1299 if (corkscrew_debug
> 5)
1300 printk(" In rx_packet(), status %4.4x, rx_status %4.4x.\n",
1301 inw(ioaddr
+ EL3_STATUS
), inw(ioaddr
+ RxStatus
));
1302 while ((rx_status
= inw(ioaddr
+ RxStatus
)) > 0) {
1303 if (rx_status
& 0x4000) { /* Error, update stats. */
1304 unsigned char rx_error
= inb(ioaddr
+ RxErrors
);
1305 if (corkscrew_debug
> 2)
1306 printk(" Rx error: status %2.2x.\n",
1308 vp
->stats
.rx_errors
++;
1309 if (rx_error
& 0x01)
1310 vp
->stats
.rx_over_errors
++;
1311 if (rx_error
& 0x02)
1312 vp
->stats
.rx_length_errors
++;
1313 if (rx_error
& 0x04)
1314 vp
->stats
.rx_frame_errors
++;
1315 if (rx_error
& 0x08)
1316 vp
->stats
.rx_crc_errors
++;
1317 if (rx_error
& 0x10)
1318 vp
->stats
.rx_length_errors
++;
1320 /* The packet length: up to 4.5K!. */
1321 short pkt_len
= rx_status
& 0x1fff;
1322 struct sk_buff
*skb
;
1324 skb
= dev_alloc_skb(pkt_len
+ 5 + 2);
1325 if (corkscrew_debug
> 4)
1326 printk("Receiving packet size %d status %4.4x.\n",
1327 pkt_len
, rx_status
);
1330 skb_reserve(skb
, 2); /* Align IP on 16 byte boundaries */
1331 /* 'skb_put()' points to the start of sk_buff data area. */
1332 insl(ioaddr
+ RX_FIFO
,
1333 skb_put(skb
, pkt_len
),
1334 (pkt_len
+ 3) >> 2);
1335 outw(RxDiscard
, ioaddr
+ EL3_CMD
); /* Pop top Rx packet. */
1336 skb
->protocol
= eth_type_trans(skb
, dev
);
1338 dev
->last_rx
= jiffies
;
1339 vp
->stats
.rx_packets
++;
1340 vp
->stats
.rx_bytes
+= skb
->len
;
1341 /* Wait a limited time to go to next packet. */
1342 for (i
= 200; i
>= 0; i
--)
1343 if (! (inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
))
1346 } else if (corkscrew_debug
)
1347 printk("%s: Couldn't allocate a sk_buff of size %d.\n", dev
->name
, pkt_len
);
1349 outw(RxDiscard
, ioaddr
+ EL3_CMD
);
1350 vp
->stats
.rx_dropped
++;
1351 /* Wait a limited time to skip this packet. */
1352 for (i
= 200; i
>= 0; i
--)
1353 if (!(inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
))
1359 static int boomerang_rx(struct net_device
*dev
)
1361 struct corkscrew_private
*vp
=
1362 (struct corkscrew_private
*) dev
->priv
;
1363 int entry
= vp
->cur_rx
% RX_RING_SIZE
;
1364 int ioaddr
= dev
->base_addr
;
1367 if (corkscrew_debug
> 5)
1368 printk(" In boomerang_rx(), status %4.4x, rx_status %4.4x.\n",
1369 inw(ioaddr
+ EL3_STATUS
), inw(ioaddr
+ RxStatus
));
1370 while ((rx_status
= vp
->rx_ring
[entry
].status
) & RxDComplete
) {
1371 if (rx_status
& RxDError
) { /* Error, update stats. */
1372 unsigned char rx_error
= rx_status
>> 16;
1373 if (corkscrew_debug
> 2)
1374 printk(" Rx error: status %2.2x.\n",
1376 vp
->stats
.rx_errors
++;
1377 if (rx_error
& 0x01)
1378 vp
->stats
.rx_over_errors
++;
1379 if (rx_error
& 0x02)
1380 vp
->stats
.rx_length_errors
++;
1381 if (rx_error
& 0x04)
1382 vp
->stats
.rx_frame_errors
++;
1383 if (rx_error
& 0x08)
1384 vp
->stats
.rx_crc_errors
++;
1385 if (rx_error
& 0x10)
1386 vp
->stats
.rx_length_errors
++;
1388 /* The packet length: up to 4.5K!. */
1389 short pkt_len
= rx_status
& 0x1fff;
1390 struct sk_buff
*skb
;
1392 vp
->stats
.rx_bytes
+= pkt_len
;
1393 if (corkscrew_debug
> 4)
1394 printk("Receiving packet size %d status %4.4x.\n",
1395 pkt_len
, rx_status
);
1397 /* Check if the packet is long enough to just accept without
1398 copying to a properly sized skbuff. */
1399 if (pkt_len
< rx_copybreak
1400 && (skb
= dev_alloc_skb(pkt_len
+ 4)) != 0) {
1402 skb_reserve(skb
, 2); /* Align IP on 16 byte boundaries */
1403 /* 'skb_put()' points to the start of sk_buff data area. */
1404 memcpy(skb_put(skb
, pkt_len
),
1405 bus_to_virt(vp
->rx_ring
[entry
].
1410 /* Pass up the skbuff already on the Rx ring. */
1411 skb
= vp
->rx_skbuff
[entry
];
1412 vp
->rx_skbuff
[entry
] = NULL
;
1413 temp
= skb_put(skb
, pkt_len
);
1414 /* Remove this checking code for final release. */
1415 if (bus_to_virt(vp
->rx_ring
[entry
].addr
) != temp
)
1416 printk("%s: Warning -- the skbuff addresses do not match"
1417 " in boomerang_rx: %p vs. %p / %p.\n",
1425 skb
->protocol
= eth_type_trans(skb
, dev
);
1427 dev
->last_rx
= jiffies
;
1428 vp
->stats
.rx_packets
++;
1430 entry
= (++vp
->cur_rx
) % RX_RING_SIZE
;
1432 /* Refill the Rx ring buffers. */
1433 for (; vp
->dirty_rx
< vp
->cur_rx
; vp
->dirty_rx
++) {
1434 struct sk_buff
*skb
;
1435 entry
= vp
->dirty_rx
% RX_RING_SIZE
;
1436 if (vp
->rx_skbuff
[entry
] == NULL
) {
1437 skb
= dev_alloc_skb(PKT_BUF_SZ
);
1439 break; /* Bad news! */
1440 skb
->dev
= dev
; /* Mark as being used by this device. */
1441 skb_reserve(skb
, 2); /* Align IP on 16 byte boundaries */
1442 vp
->rx_ring
[entry
].addr
= virt_to_bus(skb
->tail
);
1443 vp
->rx_skbuff
[entry
] = skb
;
1445 vp
->rx_ring
[entry
].status
= 0; /* Clear complete bit. */
1450 static int corkscrew_close(struct net_device
*dev
)
1452 struct corkscrew_private
*vp
=
1453 (struct corkscrew_private
*) dev
->priv
;
1454 int ioaddr
= dev
->base_addr
;
1457 netif_stop_queue(dev
);
1459 if (corkscrew_debug
> 1) {
1460 printk("%s: corkscrew_close() status %4.4x, Tx status %2.2x.\n",
1461 dev
->name
, inw(ioaddr
+ EL3_STATUS
),
1462 inb(ioaddr
+ TxStatus
));
1463 printk("%s: corkscrew close stats: rx_nocopy %d rx_copy %d"
1464 " tx_queued %d.\n", dev
->name
, rx_nocopy
, rx_copy
,
1468 del_timer(&vp
->timer
);
1470 /* Turn off statistics ASAP. We update lp->stats below. */
1471 outw(StatsDisable
, ioaddr
+ EL3_CMD
);
1473 /* Disable the receiver and transmitter. */
1474 outw(RxDisable
, ioaddr
+ EL3_CMD
);
1475 outw(TxDisable
, ioaddr
+ EL3_CMD
);
1477 if (dev
->if_port
== XCVR_10base2
)
1478 /* Turn off thinnet power. Green! */
1479 outw(StopCoax
, ioaddr
+ EL3_CMD
);
1481 free_irq(dev
->irq
, dev
);
1483 outw(SetIntrEnb
| 0x0000, ioaddr
+ EL3_CMD
);
1485 update_stats(ioaddr
, dev
);
1486 if (vp
->full_bus_master_rx
) { /* Free Boomerang bus master Rx buffers. */
1487 outl(0, ioaddr
+ UpListPtr
);
1488 for (i
= 0; i
< RX_RING_SIZE
; i
++)
1489 if (vp
->rx_skbuff
[i
]) {
1490 dev_kfree_skb(vp
->rx_skbuff
[i
]);
1491 vp
->rx_skbuff
[i
] = 0;
1494 if (vp
->full_bus_master_tx
) { /* Free Boomerang bus master Tx buffers. */
1495 outl(0, ioaddr
+ DownListPtr
);
1496 for (i
= 0; i
< TX_RING_SIZE
; i
++)
1497 if (vp
->tx_skbuff
[i
]) {
1498 dev_kfree_skb(vp
->tx_skbuff
[i
]);
1499 vp
->tx_skbuff
[i
] = 0;
1508 static struct enet_statistics
*corkscrew_get_stats(struct net_device
*dev
)
1510 struct corkscrew_private
*vp
=
1511 (struct corkscrew_private
*) dev
->priv
;
1512 unsigned long flags
;
1514 if (netif_running(dev
)) {
1517 update_stats(dev
->base_addr
, dev
);
1518 restore_flags(flags
);
1523 /* Update statistics.
1524 Unlike with the EL3 we need not worry about interrupts changing
1525 the window setting from underneath us, but we must still guard
1526 against a race condition with a StatsUpdate interrupt updating the
1527 table. This is done by checking that the ASM (!) code generated uses
1528 atomic updates with '+='.
1530 static void update_stats(int ioaddr
, struct net_device
*dev
)
1532 struct corkscrew_private
*vp
=
1533 (struct corkscrew_private
*) dev
->priv
;
1535 /* Unlike the 3c5x9 we need not turn off stats updates while reading. */
1536 /* Switch to the stats window, and read everything. */
1538 vp
->stats
.tx_carrier_errors
+= inb(ioaddr
+ 0);
1539 vp
->stats
.tx_heartbeat_errors
+= inb(ioaddr
+ 1);
1540 /* Multiple collisions. */ inb(ioaddr
+ 2);
1541 vp
->stats
.collisions
+= inb(ioaddr
+ 3);
1542 vp
->stats
.tx_window_errors
+= inb(ioaddr
+ 4);
1543 vp
->stats
.rx_fifo_errors
+= inb(ioaddr
+ 5);
1544 vp
->stats
.tx_packets
+= inb(ioaddr
+ 6);
1545 vp
->stats
.tx_packets
+= (inb(ioaddr
+ 9) & 0x30) << 4;
1546 /* Rx packets */ inb(ioaddr
+ 7);
1547 /* Must read to clear */
1548 /* Tx deferrals */ inb(ioaddr
+ 8);
1549 /* Don't bother with register 9, an extension of registers 6&7.
1550 If we do use the 6&7 values the atomic update assumption above
1552 inw(ioaddr
+ 10); /* Total Rx and Tx octets. */
1554 /* New: On the Vortex we must also clear the BadSSD counter. */
1558 /* We change back to window 7 (not 1) with the Vortex. */
1563 /* This new version of set_rx_mode() supports v1.4 kernels.
1564 The Vortex chip has no documented multicast filter, so the only
1565 multicast setting is to receive all multicast frames. At least
1566 the chip has a very clean way to set the mode, unlike many others. */
1567 static void set_rx_mode(struct net_device
*dev
)
1569 int ioaddr
= dev
->base_addr
;
1572 if (dev
->flags
& IFF_PROMISC
) {
1573 if (corkscrew_debug
> 3)
1574 printk("%s: Setting promiscuous mode.\n",
1576 new_mode
= SetRxFilter
| RxStation
| RxMulticast
| RxBroadcast
| RxProm
;
1577 } else if ((dev
->mc_list
) || (dev
->flags
& IFF_ALLMULTI
)) {
1578 new_mode
= SetRxFilter
| RxStation
| RxMulticast
| RxBroadcast
;
1580 new_mode
= SetRxFilter
| RxStation
| RxBroadcast
;
1582 outw(new_mode
, ioaddr
+ EL3_CMD
);
1586 void cleanup_module(void)
1588 struct net_device
*next_dev
;
1590 /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
1591 while (root_corkscrew_dev
) {
1593 ((struct corkscrew_private
*) root_corkscrew_dev
->
1595 if (root_corkscrew_dev
->dma
)
1596 free_dma(root_corkscrew_dev
->dma
);
1597 unregister_netdev(root_corkscrew_dev
);
1598 outw(TotalReset
, root_corkscrew_dev
->base_addr
+ EL3_CMD
);
1599 release_region(root_corkscrew_dev
->base_addr
,
1600 CORKSCREW_TOTAL_SIZE
);
1601 kfree(root_corkscrew_dev
);
1602 root_corkscrew_dev
= next_dev
;
1609 * compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c 3c515.c"