2 Written 1997-1998 by Donald Becker.
4 This software may be used and distributed according to the terms
5 of the GNU General Public License, incorporated herein by reference.
7 This driver is for the 3Com ISA EtherLink XL "Corkscrew" 3c515 ethercard.
9 The author may be reached as becker@scyld.com, or C/O
10 Scyld Computing Corporation
11 410 Severn Ave., Suite 210
15 2000/2/2- Added support for kernel-level ISAPnP
16 by Stephen Frost <sfrost@snowman.net> and Alessandro Zummo
17 Cleaned up for 2.3.x/softnet by Jeff Garzik and Alan Cox.
19 2001/11/17 - Added ethtool support (jgarzik)
21 2002/10/28 - Locking updates for 2.5 (alan@redhat.com)
25 #define DRV_NAME "3c515"
26 #define DRV_VERSION "0.99t-ac"
27 #define DRV_RELDATE "28-Oct-2002"
29 static char *version
=
30 DRV_NAME
".c:v" DRV_VERSION
" " DRV_RELDATE
" becker@scyld.com and others\n";
34 /* "Knobs" that adjust features and parameters. */
35 /* Set the copy breakpoint for the copy-only-tiny-frames scheme.
36 Setting to > 1512 effectively disables this feature. */
37 static const int rx_copybreak
= 200;
39 /* Allow setting MTU to a larger size, bypassing the normal ethernet setup. */
40 static const int mtu
= 1500;
42 /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
43 static int max_interrupt_work
= 20;
45 /* Enable the automatic media selection code -- usually set. */
48 /* Allow the use of fragment bus master transfers instead of only
49 programmed-I/O for Vortex cards. Full-bus-master transfers are always
50 enabled by default on Boomerang cards. If VORTEX_BUS_MASTER is defined,
51 the feature may be turned on using 'options'. */
52 #define VORTEX_BUS_MASTER
54 /* A few values that may be tweaked. */
55 /* Keep the ring sizes a power of two for efficiency. */
56 #define TX_RING_SIZE 16
57 #define RX_RING_SIZE 16
58 #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer. */
60 #include <linux/config.h>
61 #include <linux/module.h>
62 #include <linux/version.h>
63 #include <linux/isapnp.h>
64 #include <linux/kernel.h>
65 #include <linux/netdevice.h>
66 #include <linux/string.h>
67 #include <linux/errno.h>
69 #include <linux/ioport.h>
70 #include <linux/slab.h>
71 #include <linux/skbuff.h>
72 #include <linux/etherdevice.h>
73 #include <linux/interrupt.h>
74 #include <linux/timer.h>
75 #include <linux/ethtool.h>
77 #include <asm/uaccess.h>
78 #include <asm/bitops.h>
83 #include <linux/delay.h>
87 MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
88 MODULE_DESCRIPTION("3Com 3c515 Corkscrew driver");
89 MODULE_LICENSE("GPL");
91 MODULE_PARM(debug
, "i");
92 MODULE_PARM(options
, "1-" __MODULE_STRING(MAX_UNITS
) "i");
93 MODULE_PARM(rx_copybreak
, "i");
94 MODULE_PARM(max_interrupt_work
, "i");
95 MODULE_PARM_DESC(debug
, "3c515 debug level (0-6)");
96 MODULE_PARM_DESC(options
, "3c515: Bits 0-2: media type, bit 3: full duplex, bit 4: bus mastering");
97 MODULE_PARM_DESC(rx_copybreak
, "3c515 copy breakpoint for copy-only-tiny-frames");
98 MODULE_PARM_DESC(max_interrupt_work
, "3c515 maximum events handled per interrupt");
100 /* "Knobs" for adjusting internal parameters. */
101 /* Put out somewhat more debugging messages. (0 - no msg, 1 minimal msgs). */
102 #define DRIVER_DEBUG 1
103 /* Some values here only for performance evaluation and path-coverage
105 static int rx_nocopy
, rx_copy
, queued_packet
;
107 /* Number of times to check to see if the Tx FIFO has space, used in some
109 #define WAIT_TX_AVAIL 200
111 /* Operational parameter that usually are not changed. */
112 #define TX_TIMEOUT 40 /* Time in jiffies before concluding Tx hung */
114 /* The size here is somewhat misleading: the Corkscrew also uses the ISA
115 aliased registers at <base>+0x400.
117 #define CORKSCREW_TOTAL_SIZE 0x20
120 static int corkscrew_debug
= DRIVER_DEBUG
;
122 static int corkscrew_debug
= 1;
125 #define CORKSCREW_ID 10
130 I. Board Compatibility
132 This device driver is designed for the 3Com 3c515 ISA Fast EtherLink XL,
133 3Com's ISA bus adapter for Fast Ethernet. Due to the unique I/O port layout,
134 it's not practical to integrate this driver with the other EtherLink drivers.
136 II. Board-specific settings
138 The Corkscrew has an EEPROM for configuration, but no special settings are
141 III. Driver operation
143 The 3c515 series use an interface that's very similar to the 3c900 "Boomerang"
144 PCI cards, with the bus master interface extensively modified to work with
147 The card is capable of full-bus-master transfers with separate
148 lists of transmit and receive descriptors, similar to the AMD LANCE/PCnet,
149 DEC Tulip and Intel Speedo3.
151 This driver uses a "RX_COPYBREAK" scheme rather than a fixed intermediate
152 receive buffer. This scheme allocates full-sized skbuffs as receive
153 buffers. The value RX_COPYBREAK is used as the copying breakpoint: it is
154 chosen to trade-off the memory wasted by passing the full-sized skbuff to
155 the queue layer for all frames vs. the copying cost of copying a frame to a
156 correctly-sized skbuff.
159 IIIC. Synchronization
160 The driver runs as two independent, single-threaded flows of control. One
161 is the send-packet routine, which enforces single-threaded use by the netif
162 layer. The other thread is the interrupt handler, which is single
163 threaded by the hardware and other software.
167 Thanks to Terry Murphy of 3Com for providing documentation and a development
170 The names "Vortex", "Boomerang" and "Corkscrew" are the internal 3Com
171 project names. I use these names to eliminate confusion -- 3Com product
172 numbers and names are very similar and often confused.
174 The new chips support both ethernet (1.5K) and FDDI (4.5K) frame sizes!
175 This driver only supports ethernet frames because of the recent MTU limit
176 of 1.5K, but the changes to support 4.5K are minimal.
179 /* Operational definitions.
180 These are not used by other compilation units and thus are not
181 exported in a ".h" file.
183 First the windows. There are eight register windows, with the command
184 and status registers available in each.
186 #define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
188 #define EL3_STATUS 0x0e
190 /* The top five bits written to EL3_CMD are a command, the lower
191 11 bits are the parameter, if applicable.
192 Note that 11 parameters bits was fine for ethernet, but the new chips
193 can handle FDDI length frames (~4500 octets) and now parameters count
194 32-bit 'Dwords' rather than octets. */
197 TotalReset
= 0 << 11, SelectWindow
= 1 << 11, StartCoax
= 2 << 11,
198 RxDisable
= 3 << 11, RxEnable
= 4 << 11, RxReset
= 5 << 11,
199 UpStall
= 6 << 11, UpUnstall
= (6 << 11) + 1, DownStall
= (6 << 11) + 2,
200 DownUnstall
= (6 << 11) + 3, RxDiscard
= 8 << 11, TxEnable
= 9 << 11,
201 TxDisable
= 10 << 11, TxReset
= 11 << 11, FakeIntr
= 12 << 11,
202 AckIntr
= 13 << 11, SetIntrEnb
= 14 << 11, SetStatusEnb
= 15 << 11,
203 SetRxFilter
= 16 << 11, SetRxThreshold
= 17 << 11,
204 SetTxThreshold
= 18 << 11, SetTxStart
= 19 << 11, StartDMAUp
= 20 << 11,
205 StartDMADown
= (20 << 11) + 1, StatsEnable
= 21 << 11,
206 StatsDisable
= 22 << 11, StopCoax
= 23 << 11,
209 /* The SetRxFilter command accepts the following classes: */
211 RxStation
= 1, RxMulticast
= 2, RxBroadcast
= 4, RxProm
= 8
214 /* Bits in the general status register. */
215 enum corkscrew_status
{
216 IntLatch
= 0x0001, AdapterFailure
= 0x0002, TxComplete
= 0x0004,
217 TxAvailable
= 0x0008, RxComplete
= 0x0010, RxEarly
= 0x0020,
218 IntReq
= 0x0040, StatsFull
= 0x0080,
219 DMADone
= 1 << 8, DownComplete
= 1 << 9, UpComplete
= 1 << 10,
220 DMAInProgress
= 1 << 11, /* DMA controller is still busy. */
221 CmdInProgress
= 1 << 12, /* EL3_CMD is still busy. */
224 /* Register window 1 offsets, the window used in normal operation.
225 On the Corkscrew this window is always mapped at offsets 0x10-0x1f. */
227 TX_FIFO
= 0x10, RX_FIFO
= 0x10, RxErrors
= 0x14,
228 RxStatus
= 0x18, Timer
= 0x1A, TxStatus
= 0x1B,
229 TxFree
= 0x1C, /* Remaining free bytes in Tx buffer. */
233 #if defined(CORKSCREW)
234 Wn0EepromCmd
= 0x200A, /* Corkscrew EEPROM command register. */
235 Wn0EepromData
= 0x200C, /* Corkscrew EEPROM results register. */
237 Wn0EepromCmd
= 10, /* Window 0: EEPROM command register. */
238 Wn0EepromData
= 12, /* Window 0: EEPROM results register. */
241 enum Win0_EEPROM_bits
{
242 EEPROM_Read
= 0x80, EEPROM_WRITE
= 0x40, EEPROM_ERASE
= 0xC0,
243 EEPROM_EWENB
= 0x30, /* Enable erasing/writing for 10 msec. */
244 EEPROM_EWDIS
= 0x00, /* Disable EWENB before 10 msec timeout. */
247 /* EEPROM locations. */
249 PhysAddr01
= 0, PhysAddr23
= 1, PhysAddr45
= 2, ModelID
= 3,
253 enum Window3
{ /* Window 3: MAC/config bits. */
254 Wn3_Config
= 0, Wn3_MAC_Ctrl
= 6, Wn3_Options
= 8,
258 struct w3_config_fields
{
259 unsigned int ram_size
:3, ram_width
:1, ram_speed
:2, rom_size
:2;
261 unsigned int ram_split
:2, pad18
:2, xcvr
:3, pad21
:1, autoselect
:1;
267 Wn4_NetDiag
= 6, Wn4_Media
= 10, /* Window 4: Xcvr/media bits. */
269 enum Win4_Media_bits
{
270 Media_SQE
= 0x0008, /* Enable SQE error counting for AUI. */
271 Media_10TP
= 0x00C0, /* Enable link beat and jabber for 10baseT. */
272 Media_Lnk
= 0x0080, /* Enable just link beat for 100TX/100FX. */
273 Media_LnkBeat
= 0x0800,
275 enum Window7
{ /* Window 7: Bus Master control. */
276 Wn7_MasterAddr
= 0, Wn7_MasterLen
= 6, Wn7_MasterStatus
= 12,
279 /* Boomerang-style bus master control registers. Note ISA aliases! */
281 PktStatus
= 0x400, DownListPtr
= 0x404, FragAddr
= 0x408, FragLen
=
283 TxFreeThreshold
= 0x40f, UpPktStatus
= 0x410, UpListPtr
= 0x418,
286 /* The Rx and Tx descriptor lists.
287 Caution Alpha hackers: these types are 32 bits! Note also the 8 byte
288 alignment contraint on tx_ring[] and rx_ring[]. */
289 struct boom_rx_desc
{
296 /* Values for the Rx status entry. */
297 enum rx_desc_status
{
298 RxDComplete
= 0x00008000, RxDError
= 0x4000,
299 /* See boomerang_rx() for actual error bits */
302 struct boom_tx_desc
{
309 struct corkscrew_private
{
310 const char *product_name
;
311 struct net_device
*next_module
;
312 /* The Rx and Tx rings are here to keep them quad-word-aligned. */
313 struct boom_rx_desc rx_ring
[RX_RING_SIZE
];
314 struct boom_tx_desc tx_ring
[TX_RING_SIZE
];
315 /* The addresses of transmit- and receive-in-place skbuffs. */
316 struct sk_buff
*rx_skbuff
[RX_RING_SIZE
];
317 struct sk_buff
*tx_skbuff
[TX_RING_SIZE
];
318 unsigned int cur_rx
, cur_tx
; /* The next free ring entry */
319 unsigned int dirty_rx
, dirty_tx
;/* The ring entries to be free()ed. */
320 struct net_device_stats stats
;
321 struct sk_buff
*tx_skb
; /* Packet being eaten by bus master ctrl. */
322 struct timer_list timer
; /* Media selection timer. */
323 int capabilities
; /* Adapter capabilities word. */
324 int options
; /* User-settable misc. driver options. */
325 int last_rx_packets
; /* For media autoselection. */
326 unsigned int available_media
:8, /* From Wn3_Options */
327 media_override
:3, /* Passed-in media type. */
328 default_media
:3, /* Read from the EEPROM. */
329 full_duplex
:1, autoselect
:1, bus_master
:1, /* Vortex can only do a fragment bus-m. */
330 full_bus_master_tx
:1, full_bus_master_rx
:1, /* Boomerang */
335 /* The action to take with a media selection timer tick.
336 Note that we deviate from the 3Com order by checking 10base2 before AUI.
339 XCVR_10baseT
= 0, XCVR_AUI
, XCVR_10baseTOnly
, XCVR_10base2
, XCVR_100baseTx
,
340 XCVR_100baseFx
, XCVR_MII
= 6, XCVR_Default
= 8,
343 static struct media_table
{
345 unsigned int media_bits
:16, /* Bits to set in Wn4_Media register. */
346 mask
:8, /* The transceiver-present bit in Wn3_Config. */
347 next
:8; /* The media type to try next. */
348 short wait
; /* Time before we check media status. */
350 { "10baseT", Media_10TP
, 0x08, XCVR_10base2
, (14 * HZ
) / 10 },
351 { "10Mbs AUI", Media_SQE
, 0x20, XCVR_Default
, (1 * HZ
) / 10},
352 { "undefined", 0, 0x80, XCVR_10baseT
, 10000},
353 { "10base2", 0, 0x10, XCVR_AUI
, (1 * HZ
) / 10},
354 { "100baseTX", Media_Lnk
, 0x02, XCVR_100baseFx
, (14 * HZ
) / 10},
355 { "100baseFX", Media_Lnk
, 0x04, XCVR_MII
, (14 * HZ
) / 10},
356 { "MII", 0, 0x40, XCVR_10baseT
, 3 * HZ
},
357 { "undefined", 0, 0x01, XCVR_10baseT
, 10000},
358 { "Default", 0, 0xFF, XCVR_10baseT
, 10000},
362 static struct isapnp_device_id corkscrew_isapnp_adapters
[] = {
363 { ISAPNP_ANY_ID
, ISAPNP_ANY_ID
,
364 ISAPNP_VENDOR('T', 'C', 'M'), ISAPNP_FUNCTION(0x5051),
365 (long) "3Com Fast EtherLink ISA" },
366 { } /* terminate list */
369 MODULE_DEVICE_TABLE(isapnp
, corkscrew_isapnp_adapters
);
371 static int corkscrew_isapnp_phys_addr
[3];
374 #endif /* __ISAPNP__ */
376 static int corkscrew_scan(struct net_device
*dev
);
377 static struct net_device
*corkscrew_found_device(struct net_device
*dev
,
381 static int corkscrew_probe1(struct net_device
*dev
);
382 static int corkscrew_open(struct net_device
*dev
);
383 static void corkscrew_timer(unsigned long arg
);
384 static int corkscrew_start_xmit(struct sk_buff
*skb
,
385 struct net_device
*dev
);
386 static int corkscrew_rx(struct net_device
*dev
);
387 static void corkscrew_timeout(struct net_device
*dev
);
388 static int boomerang_rx(struct net_device
*dev
);
389 static irqreturn_t
corkscrew_interrupt(int irq
, void *dev_id
,
390 struct pt_regs
*regs
);
391 static int corkscrew_close(struct net_device
*dev
);
392 static void update_stats(int addr
, struct net_device
*dev
);
393 static struct net_device_stats
*corkscrew_get_stats(struct net_device
*dev
);
394 static void set_rx_mode(struct net_device
*dev
);
395 static int netdev_ioctl (struct net_device
*dev
, struct ifreq
*rq
, int cmd
);
399 Unfortunately maximizing the shared code between the integrated and
400 module version of the driver results in a complicated set of initialization
402 init_module() -- modules / tc59x_init() -- built-in
403 The wrappers for corkscrew_scan()
404 corkscrew_scan() The common routine that scans for PCI and EISA cards
405 corkscrew_found_device() Allocate a device structure when we find a card.
406 Different versions exist for modules and built-in.
407 corkscrew_probe1() Fill in the device structure -- this is separated
408 so that the modules code can put it in dev->init.
410 /* This driver uses 'options' to pass the media type, full-duplex flag, etc. */
411 /* Note: this is the only limit on the number of cards supported!! */
412 static int options
[MAX_UNITS
] = { -1, -1, -1, -1, -1, -1, -1, -1, };
415 static int debug
= -1;
416 /* A list of all installed Vortex devices, for removing the driver module. */
417 static struct net_device
*root_corkscrew_dev
;
419 int init_module(void)
424 corkscrew_debug
= debug
;
428 root_corkscrew_dev
= NULL
;
429 cards_found
= corkscrew_scan(NULL
);
430 return cards_found
? 0 : -ENODEV
;
434 int tc515_probe(struct net_device
*dev
)
438 SET_MODULE_OWNER(dev
);
440 cards_found
= corkscrew_scan(dev
);
442 if (corkscrew_debug
> 0 && cards_found
)
445 return cards_found
? 0 : -ENODEV
;
447 #endif /* not MODULE */
449 static int corkscrew_scan(struct net_device
*dev
)
455 static int pnp_cards
;
461 for(i
=0; corkscrew_isapnp_adapters
[i
].vendor
!= 0; i
++) {
462 struct pnp_dev
*idev
= NULL
;
464 while((idev
= pnp_find_dev(NULL
,
465 corkscrew_isapnp_adapters
[i
].vendor
,
466 corkscrew_isapnp_adapters
[i
].function
,
469 if (pnp_device_attach(idev
) < 0)
471 if (pnp_activate_dev(idev
) < 0) {
472 printk("pnp activate failed (out of resources?)\n");
473 pnp_device_detach(idev
);
476 if (!pnp_port_valid(idev
, 0) || !pnp_irq_valid(idev
, 0)) {
477 pnp_device_detach(idev
);
480 ioaddr
= pnp_port_start(idev
, 0);
481 irq
= pnp_irq(idev
, 0);
483 printk ("ISAPNP reports %s at i/o 0x%x, irq %d\n",
484 (char*) corkscrew_isapnp_adapters
[i
].driver_data
, ioaddr
, irq
);
486 if ((inw(ioaddr
+ 0x2002) & 0x1f0) != (ioaddr
& 0x1f0)) {
487 pnp_device_detach(idev
);
490 /* Verify by reading the device ID from the EEPROM. */
493 outw(EEPROM_Read
+ 7, ioaddr
+ Wn0EepromCmd
);
494 /* Pause for at least 162 us. for the read to take place. */
495 for (timer
= 4; timer
>= 0; timer
--) {
497 if ((inw(ioaddr
+ Wn0EepromCmd
) & 0x0200)
501 if (inw(ioaddr
+ Wn0EepromData
) != 0x6d50) {
502 pnp_device_detach(idev
);
506 printk(KERN_INFO
"3c515 Resource configuration register %#4.4x, DCR %4.4x.\n",
507 inl(ioaddr
+ 0x2002), inw(ioaddr
+ 0x2000));
508 /* irq = inw(ioaddr + 0x2002) & 15; */ /* Use the irq from isapnp */
509 corkscrew_isapnp_phys_addr
[pnp_cards
] = ioaddr
;
510 corkscrew_found_device(dev
, ioaddr
, irq
, CORKSCREW_ID
, dev
511 && dev
->mem_start
? dev
->
512 mem_start
: options
[cards_found
]);
519 #endif /* __ISAPNP__ */
521 /* Check all locations on the ISA bus -- evil! */
522 for (ioaddr
= 0x100; ioaddr
< 0x400; ioaddr
+= 0x20) {
525 /* Make sure this was not already picked up by isapnp */
526 if(ioaddr
== corkscrew_isapnp_phys_addr
[0]) continue;
527 if(ioaddr
== corkscrew_isapnp_phys_addr
[1]) continue;
528 if(ioaddr
== corkscrew_isapnp_phys_addr
[2]) continue;
529 #endif /* __ISAPNP__ */
530 if (check_region(ioaddr
, CORKSCREW_TOTAL_SIZE
))
532 /* Check the resource configuration for a matching ioaddr. */
533 if ((inw(ioaddr
+ 0x2002) & 0x1f0) != (ioaddr
& 0x1f0))
535 /* Verify by reading the device ID from the EEPROM. */
538 outw(EEPROM_Read
+ 7, ioaddr
+ Wn0EepromCmd
);
539 /* Pause for at least 162 us. for the read to take place. */
540 for (timer
= 4; timer
>= 0; timer
--) {
542 if ((inw(ioaddr
+ Wn0EepromCmd
) & 0x0200)
546 if (inw(ioaddr
+ Wn0EepromData
) != 0x6d50)
549 printk(KERN_INFO
"3c515 Resource configuration register %#4.4x, DCR %4.4x.\n",
550 inl(ioaddr
+ 0x2002), inw(ioaddr
+ 0x2000));
551 irq
= inw(ioaddr
+ 0x2002) & 15;
552 corkscrew_found_device(dev
, ioaddr
, irq
, CORKSCREW_ID
,
553 dev
&& dev
->mem_start
? dev
->mem_start
:
554 (cards_found
>= MAX_UNITS
? -1 :
555 options
[cards_found
]));
560 printk(KERN_INFO
"%d 3c515 cards found.\n", cards_found
);
564 static struct net_device
*corkscrew_found_device(struct net_device
*dev
,
569 struct corkscrew_private
*vp
;
572 /* Allocate and fill new device structure. */
573 int dev_size
= sizeof(struct net_device
) + sizeof(struct corkscrew_private
) + 15; /* Pad for alignment */
575 dev
= (struct net_device
*) kmalloc(dev_size
, GFP_KERNEL
);
578 memset(dev
, 0, dev_size
);
579 /* Align the Rx and Tx ring entries. */
580 dev
->priv
= (void *) (((long) dev
+ sizeof(struct net_device
) + 15) & ~15);
581 vp
= (struct corkscrew_private
*) dev
->priv
;
582 dev
->base_addr
= ioaddr
;
584 dev
->dma
= (product_index
== CORKSCREW_ID
? inw(ioaddr
+ 0x2000) & 7 : 0);
585 dev
->init
= corkscrew_probe1
;
586 vp
->product_name
= "3c515";
587 vp
->options
= options
;
589 vp
->media_override
= ((options
& 7) == 2) ? 0 : options
& 7;
590 vp
->full_duplex
= (options
& 8) ? 1 : 0;
591 vp
->bus_master
= (options
& 16) ? 1 : 0;
593 vp
->media_override
= 7;
598 vp
->next_module
= root_corkscrew_dev
;
599 root_corkscrew_dev
= dev
;
600 SET_MODULE_OWNER(dev
);
601 if (register_netdev(dev
) != 0) {
605 #else /* not a MODULE */
606 /* Caution: quad-word alignment required for rings! */
607 dev
->priv
= kmalloc(sizeof(struct corkscrew_private
), GFP_KERNEL
);
610 memset(dev
->priv
, 0, sizeof(struct corkscrew_private
));
611 dev
= init_etherdev(dev
, sizeof(struct corkscrew_private
));
612 dev
->base_addr
= ioaddr
;
614 dev
->dma
= (product_index
== CORKSCREW_ID
? inw(ioaddr
+ 0x2000) & 7 : 0);
615 vp
= (struct corkscrew_private
*) dev
->priv
;
616 vp
->product_name
= "3c515";
617 vp
->options
= options
;
619 vp
->media_override
= ((options
& 7) == 2) ? 0 : options
& 7;
620 vp
->full_duplex
= (options
& 8) ? 1 : 0;
621 vp
->bus_master
= (options
& 16) ? 1 : 0;
623 vp
->media_override
= 7;
628 corkscrew_probe1(dev
);
633 static int corkscrew_probe1(struct net_device
*dev
)
635 int ioaddr
= dev
->base_addr
;
636 struct corkscrew_private
*vp
= (struct corkscrew_private
*) dev
->priv
;
637 unsigned int eeprom
[0x40], checksum
= 0; /* EEPROM contents */
640 printk(KERN_INFO
"%s: 3Com %s at %#3x,", dev
->name
, vp
->product_name
, ioaddr
);
642 spin_lock_init(&vp
->lock
);
644 /* Read the station address from the EEPROM. */
646 for (i
= 0; i
< 0x18; i
++) {
647 short *phys_addr
= (short *) dev
->dev_addr
;
649 outw(EEPROM_Read
+ i
, ioaddr
+ Wn0EepromCmd
);
650 /* Pause for at least 162 us. for the read to take place. */
651 for (timer
= 4; timer
>= 0; timer
--) {
653 if ((inw(ioaddr
+ Wn0EepromCmd
) & 0x0200) == 0)
656 eeprom
[i
] = inw(ioaddr
+ Wn0EepromData
);
657 checksum
^= eeprom
[i
];
659 phys_addr
[i
] = htons(eeprom
[i
]);
661 checksum
= (checksum
^ (checksum
>> 8)) & 0xff;
662 if (checksum
!= 0x00)
663 printk(" ***INVALID CHECKSUM %4.4x*** ", checksum
);
664 for (i
= 0; i
< 6; i
++)
665 printk("%c%2.2x", i
? ':' : ' ', dev
->dev_addr
[i
]);
666 if (eeprom
[16] == 0x11c7) { /* Corkscrew */
667 if (request_dma(dev
->dma
, "3c515")) {
668 printk(", DMA %d allocation failed", dev
->dma
);
671 printk(", DMA %d", dev
->dma
);
673 printk(", IRQ %d\n", dev
->irq
);
674 /* Tell them about an invalid IRQ. */
675 if (corkscrew_debug
&& (dev
->irq
<= 0 || dev
->irq
> 15))
676 printk(KERN_WARNING
" *** Warning: this IRQ is unlikely to work! ***\n");
679 char *ram_split
[] = { "5:3", "3:1", "1:1", "3:5" };
680 union wn3_config config
;
682 vp
->available_media
= inw(ioaddr
+ Wn3_Options
);
683 config
.i
= inl(ioaddr
+ Wn3_Config
);
684 if (corkscrew_debug
> 1)
685 printk(KERN_INFO
" Internal config register is %4.4x, transceivers %#x.\n",
686 config
.i
, inw(ioaddr
+ Wn3_Options
));
687 printk(KERN_INFO
" %dK %s-wide RAM %s Rx:Tx split, %s%s interface.\n",
688 8 << config
.u
.ram_size
,
689 config
.u
.ram_width
? "word" : "byte",
690 ram_split
[config
.u
.ram_split
],
691 config
.u
.autoselect
? "autoselect/" : "",
692 media_tbl
[config
.u
.xcvr
].name
);
693 dev
->if_port
= config
.u
.xcvr
;
694 vp
->default_media
= config
.u
.xcvr
;
695 vp
->autoselect
= config
.u
.autoselect
;
697 if (vp
->media_override
!= 7) {
698 printk(KERN_INFO
" Media override to transceiver type %d (%s).\n",
700 media_tbl
[vp
->media_override
].name
);
701 dev
->if_port
= vp
->media_override
;
704 vp
->capabilities
= eeprom
[16];
705 vp
->full_bus_master_tx
= (vp
->capabilities
& 0x20) ? 1 : 0;
706 /* Rx is broken at 10mbps, so we always disable it. */
707 /* vp->full_bus_master_rx = 0; */
708 vp
->full_bus_master_rx
= (vp
->capabilities
& 0x20) ? 1 : 0;
710 /* We do a request_region() to register /proc/ioports info. */
711 request_region(ioaddr
, CORKSCREW_TOTAL_SIZE
, vp
->product_name
);
713 /* The 3c51x-specific entries in the device structure. */
714 dev
->open
= &corkscrew_open
;
715 dev
->hard_start_xmit
= &corkscrew_start_xmit
;
716 dev
->tx_timeout
= &corkscrew_timeout
;
717 dev
->watchdog_timeo
= (400 * HZ
) / 1000;
718 dev
->stop
= &corkscrew_close
;
719 dev
->get_stats
= &corkscrew_get_stats
;
720 dev
->set_multicast_list
= &set_rx_mode
;
721 dev
->do_ioctl
= netdev_ioctl
;
727 static int corkscrew_open(struct net_device
*dev
)
729 int ioaddr
= dev
->base_addr
;
730 struct corkscrew_private
*vp
=
731 (struct corkscrew_private
*) dev
->priv
;
732 union wn3_config config
;
735 /* Before initializing select the active media port. */
738 outb(0x20, ioaddr
+ Wn3_MAC_Ctrl
); /* Set the full-duplex bit. */
739 config
.i
= inl(ioaddr
+ Wn3_Config
);
741 if (vp
->media_override
!= 7) {
742 if (corkscrew_debug
> 1)
743 printk(KERN_INFO
"%s: Media override to transceiver %d (%s).\n",
744 dev
->name
, vp
->media_override
,
745 media_tbl
[vp
->media_override
].name
);
746 dev
->if_port
= vp
->media_override
;
747 } else if (vp
->autoselect
) {
748 /* Find first available media type, starting with 100baseTx. */
750 while (!(vp
->available_media
& media_tbl
[dev
->if_port
].mask
))
751 dev
->if_port
= media_tbl
[dev
->if_port
].next
;
753 if (corkscrew_debug
> 1)
754 printk("%s: Initial media type %s.\n",
755 dev
->name
, media_tbl
[dev
->if_port
].name
);
757 init_timer(&vp
->timer
);
758 vp
->timer
.expires
= jiffies
+ media_tbl
[dev
->if_port
].wait
;
759 vp
->timer
.data
= (unsigned long) dev
;
760 vp
->timer
.function
= &corkscrew_timer
; /* timer handler */
761 add_timer(&vp
->timer
);
763 dev
->if_port
= vp
->default_media
;
765 config
.u
.xcvr
= dev
->if_port
;
766 outl(config
.i
, ioaddr
+ Wn3_Config
);
768 if (corkscrew_debug
> 1) {
769 printk("%s: corkscrew_open() InternalConfig %8.8x.\n",
770 dev
->name
, config
.i
);
773 outw(TxReset
, ioaddr
+ EL3_CMD
);
774 for (i
= 20; i
>= 0; i
--)
775 if (!(inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
))
778 outw(RxReset
, ioaddr
+ EL3_CMD
);
779 /* Wait a few ticks for the RxReset command to complete. */
780 for (i
= 20; i
>= 0; i
--)
781 if (!(inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
))
784 outw(SetStatusEnb
| 0x00, ioaddr
+ EL3_CMD
);
786 /* Use the now-standard shared IRQ implementation. */
787 if (vp
->capabilities
== 0x11c7) {
788 /* Corkscrew: Cannot share ISA resources. */
791 || request_irq(dev
->irq
, &corkscrew_interrupt
, 0,
792 vp
->product_name
, dev
)) return -EAGAIN
;
793 enable_dma(dev
->dma
);
794 set_dma_mode(dev
->dma
, DMA_MODE_CASCADE
);
795 } else if (request_irq(dev
->irq
, &corkscrew_interrupt
, SA_SHIRQ
,
796 vp
->product_name
, dev
)) {
800 if (corkscrew_debug
> 1) {
802 printk("%s: corkscrew_open() irq %d media status %4.4x.\n",
803 dev
->name
, dev
->irq
, inw(ioaddr
+ Wn4_Media
));
806 /* Set the station address and mask in window 2 each time opened. */
808 for (i
= 0; i
< 6; i
++)
809 outb(dev
->dev_addr
[i
], ioaddr
+ i
);
810 for (; i
< 12; i
+= 2)
813 if (dev
->if_port
== 3)
814 /* Start the thinnet transceiver. We should really wait 50ms... */
815 outw(StartCoax
, ioaddr
+ EL3_CMD
);
817 outw((inw(ioaddr
+ Wn4_Media
) & ~(Media_10TP
| Media_SQE
)) |
818 media_tbl
[dev
->if_port
].media_bits
, ioaddr
+ Wn4_Media
);
820 /* Switch to the stats window, and clear all stats by reading. */
821 outw(StatsDisable
, ioaddr
+ EL3_CMD
);
823 for (i
= 0; i
< 10; i
++)
827 /* New: On the Vortex we must also clear the BadSSD counter. */
830 /* ..and on the Boomerang we enable the extra statistics bits. */
831 outw(0x0040, ioaddr
+ Wn4_NetDiag
);
833 /* Switch to register set 7 for normal use. */
836 if (vp
->full_bus_master_rx
) { /* Boomerang bus master. */
837 vp
->cur_rx
= vp
->dirty_rx
= 0;
838 if (corkscrew_debug
> 2)
839 printk("%s: Filling in the Rx ring.\n",
841 for (i
= 0; i
< RX_RING_SIZE
; i
++) {
843 if (i
< (RX_RING_SIZE
- 1))
844 vp
->rx_ring
[i
].next
=
845 isa_virt_to_bus(&vp
->rx_ring
[i
+ 1]);
847 vp
->rx_ring
[i
].next
= 0;
848 vp
->rx_ring
[i
].status
= 0; /* Clear complete bit. */
849 vp
->rx_ring
[i
].length
= PKT_BUF_SZ
| 0x80000000;
850 skb
= dev_alloc_skb(PKT_BUF_SZ
);
851 vp
->rx_skbuff
[i
] = skb
;
853 break; /* Bad news! */
854 skb
->dev
= dev
; /* Mark as being used by this device. */
855 skb_reserve(skb
, 2); /* Align IP on 16 byte boundaries */
856 vp
->rx_ring
[i
].addr
= isa_virt_to_bus(skb
->tail
);
858 vp
->rx_ring
[i
- 1].next
= isa_virt_to_bus(&vp
->rx_ring
[0]); /* Wrap the ring. */
859 outl(isa_virt_to_bus(&vp
->rx_ring
[0]), ioaddr
+ UpListPtr
);
861 if (vp
->full_bus_master_tx
) { /* Boomerang bus master Tx. */
862 vp
->cur_tx
= vp
->dirty_tx
= 0;
863 outb(PKT_BUF_SZ
>> 8, ioaddr
+ TxFreeThreshold
); /* Room for a packet. */
864 /* Clear the Tx ring. */
865 for (i
= 0; i
< TX_RING_SIZE
; i
++)
866 vp
->tx_skbuff
[i
] = 0;
867 outl(0, ioaddr
+ DownListPtr
);
869 /* Set receiver mode: presumably accept b-case and phys addr only. */
871 outw(StatsEnable
, ioaddr
+ EL3_CMD
); /* Turn on statistics. */
873 netif_start_queue(dev
);
875 outw(RxEnable
, ioaddr
+ EL3_CMD
); /* Enable the receiver. */
876 outw(TxEnable
, ioaddr
+ EL3_CMD
); /* Enable transmitter. */
877 /* Allow status bits to be seen. */
878 outw(SetStatusEnb
| AdapterFailure
| IntReq
| StatsFull
|
879 (vp
->full_bus_master_tx
? DownComplete
: TxAvailable
) |
880 (vp
->full_bus_master_rx
? UpComplete
: RxComplete
) |
881 (vp
->bus_master
? DMADone
: 0), ioaddr
+ EL3_CMD
);
882 /* Ack all pending events, and set active indicator mask. */
883 outw(AckIntr
| IntLatch
| TxAvailable
| RxEarly
| IntReq
,
885 outw(SetIntrEnb
| IntLatch
| TxAvailable
| RxComplete
| StatsFull
886 | (vp
->bus_master
? DMADone
: 0) | UpComplete
| DownComplete
,
892 static void corkscrew_timer(unsigned long data
)
895 struct net_device
*dev
= (struct net_device
*) data
;
896 struct corkscrew_private
*vp
= (struct corkscrew_private
*) dev
->priv
;
897 int ioaddr
= dev
->base_addr
;
901 if (corkscrew_debug
> 1)
902 printk("%s: Media selection timer tick happened, %s.\n",
903 dev
->name
, media_tbl
[dev
->if_port
].name
);
905 spin_lock_irqsave(&vp
->lock
, flags
);
908 int old_window
= inw(ioaddr
+ EL3_CMD
) >> 13;
911 media_status
= inw(ioaddr
+ Wn4_Media
);
912 switch (dev
->if_port
) {
915 case 5: /* 10baseT, 100baseTX, 100baseFX */
916 if (media_status
& Media_LnkBeat
) {
918 if (corkscrew_debug
> 1)
919 printk("%s: Media %s has link beat, %x.\n",
921 media_tbl
[dev
->if_port
].name
,
923 } else if (corkscrew_debug
> 1)
924 printk("%s: Media %s is has no link beat, %x.\n",
926 media_tbl
[dev
->if_port
].name
,
930 default: /* Other media types handled by Tx timeouts. */
931 if (corkscrew_debug
> 1)
932 printk("%s: Media %s is has no indication, %x.\n",
934 media_tbl
[dev
->if_port
].name
,
939 union wn3_config config
;
943 media_tbl
[dev
->if_port
].next
;
945 while (!(vp
->available_media
& media_tbl
[dev
->if_port
].mask
));
947 if (dev
->if_port
== 8) { /* Go back to default. */
948 dev
->if_port
= vp
->default_media
;
949 if (corkscrew_debug
> 1)
950 printk("%s: Media selection failing, using default %s port.\n",
952 media_tbl
[dev
->if_port
].name
);
954 if (corkscrew_debug
> 1)
955 printk("%s: Media selection failed, now trying %s port.\n",
957 media_tbl
[dev
->if_port
].name
);
958 vp
->timer
.expires
= jiffies
+ media_tbl
[dev
->if_port
].wait
;
959 add_timer(&vp
->timer
);
961 outw((media_status
& ~(Media_10TP
| Media_SQE
)) |
962 media_tbl
[dev
->if_port
].media_bits
,
966 config
.i
= inl(ioaddr
+ Wn3_Config
);
967 config
.u
.xcvr
= dev
->if_port
;
968 outl(config
.i
, ioaddr
+ Wn3_Config
);
970 outw(dev
->if_port
== 3 ? StartCoax
: StopCoax
,
973 EL3WINDOW(old_window
);
976 spin_unlock_irqrestore(&vp
->lock
, flags
);
977 if (corkscrew_debug
> 1)
978 printk("%s: Media selection timer finished, %s.\n",
979 dev
->name
, media_tbl
[dev
->if_port
].name
);
981 #endif /* AUTOMEDIA */
985 static void corkscrew_timeout(struct net_device
*dev
)
988 struct corkscrew_private
*vp
=
989 (struct corkscrew_private
*) dev
->priv
;
990 int ioaddr
= dev
->base_addr
;
993 "%s: transmit timed out, tx_status %2.2x status %4.4x.\n",
994 dev
->name
, inb(ioaddr
+ TxStatus
),
995 inw(ioaddr
+ EL3_STATUS
));
996 /* Slight code bloat to be user friendly. */
997 if ((inb(ioaddr
+ TxStatus
) & 0x88) == 0x88)
999 "%s: Transmitter encountered 16 collisions -- network"
1000 " network cable problem?\n", dev
->name
);
1001 #ifndef final_version
1002 printk(" Flags; bus-master %d, full %d; dirty %d current %d.\n",
1003 vp
->full_bus_master_tx
, vp
->tx_full
, vp
->dirty_tx
,
1005 printk(" Down list %8.8x vs. %p.\n", inl(ioaddr
+ DownListPtr
),
1007 for (i
= 0; i
< TX_RING_SIZE
; i
++) {
1008 printk(" %d: %p length %8.8x status %8.8x\n", i
,
1010 vp
->tx_ring
[i
].length
, vp
->tx_ring
[i
].status
);
1013 /* Issue TX_RESET and TX_START commands. */
1014 outw(TxReset
, ioaddr
+ EL3_CMD
);
1015 for (i
= 20; i
>= 0; i
--)
1016 if (!(inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
))
1018 outw(TxEnable
, ioaddr
+ EL3_CMD
);
1019 dev
->trans_start
= jiffies
;
1020 vp
->stats
.tx_errors
++;
1021 vp
->stats
.tx_dropped
++;
1022 netif_wake_queue(dev
);
1025 static int corkscrew_start_xmit(struct sk_buff
*skb
,
1026 struct net_device
*dev
)
1028 struct corkscrew_private
*vp
=
1029 (struct corkscrew_private
*) dev
->priv
;
1030 int ioaddr
= dev
->base_addr
;
1032 /* Block a timer-based transmit from overlapping. */
1034 netif_stop_queue(dev
);
1036 if (vp
->full_bus_master_tx
) { /* BOOMERANG bus-master */
1037 /* Calculate the next Tx descriptor entry. */
1038 int entry
= vp
->cur_tx
% TX_RING_SIZE
;
1039 struct boom_tx_desc
*prev_entry
;
1040 unsigned long flags
, i
;
1042 if (vp
->tx_full
) /* No room to transmit with */
1044 if (vp
->cur_tx
!= 0)
1045 prev_entry
= &vp
->tx_ring
[(vp
->cur_tx
- 1) % TX_RING_SIZE
];
1048 if (corkscrew_debug
> 3)
1049 printk("%s: Trying to send a packet, Tx index %d.\n",
1050 dev
->name
, vp
->cur_tx
);
1051 /* vp->tx_full = 1; */
1052 vp
->tx_skbuff
[entry
] = skb
;
1053 vp
->tx_ring
[entry
].next
= 0;
1054 vp
->tx_ring
[entry
].addr
= isa_virt_to_bus(skb
->data
);
1055 vp
->tx_ring
[entry
].length
= skb
->len
| 0x80000000;
1056 vp
->tx_ring
[entry
].status
= skb
->len
| 0x80000000;
1058 spin_lock_irqsave(&vp
->lock
, flags
);
1059 outw(DownStall
, ioaddr
+ EL3_CMD
);
1060 /* Wait for the stall to complete. */
1061 for (i
= 20; i
>= 0; i
--)
1062 if ((inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
) == 0)
1065 prev_entry
->next
= isa_virt_to_bus(&vp
->tx_ring
[entry
]);
1066 if (inl(ioaddr
+ DownListPtr
) == 0) {
1067 outl(isa_virt_to_bus(&vp
->tx_ring
[entry
]),
1068 ioaddr
+ DownListPtr
);
1071 outw(DownUnstall
, ioaddr
+ EL3_CMD
);
1072 spin_unlock_irqrestore(&vp
->lock
, flags
);
1075 if (vp
->cur_tx
- vp
->dirty_tx
> TX_RING_SIZE
- 1)
1077 else { /* Clear previous interrupt enable. */
1079 prev_entry
->status
&= ~0x80000000;
1080 netif_wake_queue(dev
);
1082 dev
->trans_start
= jiffies
;
1085 /* Put out the doubleword header... */
1086 outl(skb
->len
, ioaddr
+ TX_FIFO
);
1087 vp
->stats
.tx_bytes
+= skb
->len
;
1088 #ifdef VORTEX_BUS_MASTER
1089 if (vp
->bus_master
) {
1090 /* Set the bus-master controller to transfer the packet. */
1091 outl((int) (skb
->data
), ioaddr
+ Wn7_MasterAddr
);
1092 outw((skb
->len
+ 3) & ~3, ioaddr
+ Wn7_MasterLen
);
1094 outw(StartDMADown
, ioaddr
+ EL3_CMD
);
1095 /* queue will be woken at the DMADone interrupt. */
1097 /* ... and the packet rounded to a doubleword. */
1098 outsl(ioaddr
+ TX_FIFO
, skb
->data
, (skb
->len
+ 3) >> 2);
1100 if (inw(ioaddr
+ TxFree
) > 1536) {
1101 netif_wake_queue(dev
);
1103 /* Interrupt us when the FIFO has room for max-sized packet. */
1104 outw(SetTxThreshold
+ (1536 >> 2),
1108 /* ... and the packet rounded to a doubleword. */
1109 outsl(ioaddr
+ TX_FIFO
, skb
->data
, (skb
->len
+ 3) >> 2);
1111 if (inw(ioaddr
+ TxFree
) > 1536) {
1112 netif_wake_queue(dev
);
1114 /* Interrupt us when the FIFO has room for max-sized packet. */
1115 outw(SetTxThreshold
+ (1536 >> 2), ioaddr
+ EL3_CMD
);
1116 #endif /* bus master */
1118 dev
->trans_start
= jiffies
;
1120 /* Clear the Tx status stack. */
1125 while (--i
> 0 && (tx_status
= inb(ioaddr
+ TxStatus
)) > 0) {
1126 if (tx_status
& 0x3C) { /* A Tx-disabling error occurred. */
1127 if (corkscrew_debug
> 2)
1128 printk("%s: Tx error, status %2.2x.\n",
1129 dev
->name
, tx_status
);
1130 if (tx_status
& 0x04)
1131 vp
->stats
.tx_fifo_errors
++;
1132 if (tx_status
& 0x38)
1133 vp
->stats
.tx_aborted_errors
++;
1134 if (tx_status
& 0x30) {
1136 outw(TxReset
, ioaddr
+ EL3_CMD
);
1137 for (j
= 20; j
>= 0; j
--)
1138 if (!(inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
))
1141 outw(TxEnable
, ioaddr
+ EL3_CMD
);
1143 outb(0x00, ioaddr
+ TxStatus
); /* Pop the status stack. */
1149 /* The interrupt handler does all of the Rx thread work and cleans up
1150 after the Tx thread. */
1152 static irqreturn_t
corkscrew_interrupt(int irq
, void *dev_id
,
1153 struct pt_regs
*regs
)
1155 /* Use the now-standard shared IRQ implementation. */
1156 struct net_device
*dev
= dev_id
;
1157 struct corkscrew_private
*lp
;
1160 int i
= max_interrupt_work
;
1162 ioaddr
= dev
->base_addr
;
1163 latency
= inb(ioaddr
+ Timer
);
1164 lp
= (struct corkscrew_private
*) dev
->priv
;
1166 spin_lock(&lp
->lock
);
1168 status
= inw(ioaddr
+ EL3_STATUS
);
1170 if (corkscrew_debug
> 4)
1171 printk("%s: interrupt, status %4.4x, timer %d.\n",
1172 dev
->name
, status
, latency
);
1173 if ((status
& 0xE000) != 0xE000) {
1174 static int donedidthis
;
1175 /* Some interrupt controllers store a bogus interrupt from boot-time.
1176 Ignore a single early interrupt, but don't hang the machine for
1177 other interrupt problems. */
1178 if (donedidthis
++ > 100) {
1179 printk(KERN_ERR
"%s: Bogus interrupt, bailing. Status %4.4x, start=%d.\n",
1180 dev
->name
, status
, netif_running(dev
));
1181 free_irq(dev
->irq
, dev
);
1187 if (corkscrew_debug
> 5)
1188 printk("%s: In interrupt loop, status %4.4x.\n",
1190 if (status
& RxComplete
)
1193 if (status
& TxAvailable
) {
1194 if (corkscrew_debug
> 5)
1195 printk(" TX room bit was handled.\n");
1196 /* There's room in the FIFO for a full-sized packet. */
1197 outw(AckIntr
| TxAvailable
, ioaddr
+ EL3_CMD
);
1198 netif_wake_queue(dev
);
1200 if (status
& DownComplete
) {
1201 unsigned int dirty_tx
= lp
->dirty_tx
;
1203 while (lp
->cur_tx
- dirty_tx
> 0) {
1204 int entry
= dirty_tx
% TX_RING_SIZE
;
1205 if (inl(ioaddr
+ DownListPtr
) == isa_virt_to_bus(&lp
->tx_ring
[entry
]))
1206 break; /* It still hasn't been processed. */
1207 if (lp
->tx_skbuff
[entry
]) {
1208 dev_kfree_skb_irq(lp
->tx_skbuff
[entry
]);
1209 lp
->tx_skbuff
[entry
] = 0;
1213 lp
->dirty_tx
= dirty_tx
;
1214 outw(AckIntr
| DownComplete
, ioaddr
+ EL3_CMD
);
1215 if (lp
->tx_full
&& (lp
->cur_tx
- dirty_tx
<= TX_RING_SIZE
- 1)) {
1217 netif_wake_queue(dev
);
1220 #ifdef VORTEX_BUS_MASTER
1221 if (status
& DMADone
) {
1222 outw(0x1000, ioaddr
+ Wn7_MasterStatus
); /* Ack the event. */
1223 dev_kfree_skb_irq(lp
->tx_skb
); /* Release the transferred buffer */
1224 netif_wake_queue(dev
);
1227 if (status
& UpComplete
) {
1229 outw(AckIntr
| UpComplete
, ioaddr
+ EL3_CMD
);
1231 if (status
& (AdapterFailure
| RxEarly
| StatsFull
)) {
1232 /* Handle all uncommon interrupts at once. */
1233 if (status
& RxEarly
) { /* Rx early is unused. */
1235 outw(AckIntr
| RxEarly
, ioaddr
+ EL3_CMD
);
1237 if (status
& StatsFull
) { /* Empty statistics. */
1238 static int DoneDidThat
;
1239 if (corkscrew_debug
> 4)
1240 printk("%s: Updating stats.\n", dev
->name
);
1241 update_stats(ioaddr
, dev
);
1242 /* DEBUG HACK: Disable statistics as an interrupt source. */
1243 /* This occurs when we have the wrong media type! */
1244 if (DoneDidThat
== 0 && inw(ioaddr
+ EL3_STATUS
) & StatsFull
) {
1246 printk("%s: Updating stats failed, disabling stats as an"
1247 " interrupt source.\n", dev
->name
);
1248 for (win
= 0; win
< 8; win
++) {
1250 printk("\n Vortex window %d:", win
);
1251 for (reg
= 0; reg
< 16; reg
++)
1252 printk(" %2.2x", inb(ioaddr
+ reg
));
1255 outw(SetIntrEnb
| TxAvailable
|
1256 RxComplete
| AdapterFailure
|
1257 UpComplete
| DownComplete
|
1258 TxComplete
, ioaddr
+ EL3_CMD
);
1262 if (status
& AdapterFailure
) {
1263 /* Adapter failure requires Rx reset and reinit. */
1264 outw(RxReset
, ioaddr
+ EL3_CMD
);
1265 /* Set the Rx filter to the current state. */
1267 outw(RxEnable
, ioaddr
+ EL3_CMD
); /* Re-enable the receiver. */
1268 outw(AckIntr
| AdapterFailure
,
1274 printk(KERN_ERR
"%s: Too much work in interrupt, status %4.4x. "
1275 "Disabling functions (%4.4x).\n", dev
->name
,
1276 status
, SetStatusEnb
| ((~status
) & 0x7FE));
1277 /* Disable all pending interrupts. */
1278 outw(SetStatusEnb
| ((~status
) & 0x7FE), ioaddr
+ EL3_CMD
);
1279 outw(AckIntr
| 0x7FF, ioaddr
+ EL3_CMD
);
1282 /* Acknowledge the IRQ. */
1283 outw(AckIntr
| IntReq
| IntLatch
, ioaddr
+ EL3_CMD
);
1285 } while ((status
= inw(ioaddr
+ EL3_STATUS
)) & (IntLatch
| RxComplete
));
1287 spin_unlock(&lp
->lock
);
1289 if (corkscrew_debug
> 4)
1290 printk("%s: exiting interrupt, status %4.4x.\n", dev
->name
, status
);
1294 static int corkscrew_rx(struct net_device
*dev
)
1296 struct corkscrew_private
*vp
= (struct corkscrew_private
*) dev
->priv
;
1297 int ioaddr
= dev
->base_addr
;
1301 if (corkscrew_debug
> 5)
1302 printk(" In rx_packet(), status %4.4x, rx_status %4.4x.\n",
1303 inw(ioaddr
+ EL3_STATUS
), inw(ioaddr
+ RxStatus
));
1304 while ((rx_status
= inw(ioaddr
+ RxStatus
)) > 0) {
1305 if (rx_status
& 0x4000) { /* Error, update stats. */
1306 unsigned char rx_error
= inb(ioaddr
+ RxErrors
);
1307 if (corkscrew_debug
> 2)
1308 printk(" Rx error: status %2.2x.\n",
1310 vp
->stats
.rx_errors
++;
1311 if (rx_error
& 0x01)
1312 vp
->stats
.rx_over_errors
++;
1313 if (rx_error
& 0x02)
1314 vp
->stats
.rx_length_errors
++;
1315 if (rx_error
& 0x04)
1316 vp
->stats
.rx_frame_errors
++;
1317 if (rx_error
& 0x08)
1318 vp
->stats
.rx_crc_errors
++;
1319 if (rx_error
& 0x10)
1320 vp
->stats
.rx_length_errors
++;
1322 /* The packet length: up to 4.5K!. */
1323 short pkt_len
= rx_status
& 0x1fff;
1324 struct sk_buff
*skb
;
1326 skb
= dev_alloc_skb(pkt_len
+ 5 + 2);
1327 if (corkscrew_debug
> 4)
1328 printk("Receiving packet size %d status %4.4x.\n",
1329 pkt_len
, rx_status
);
1332 skb_reserve(skb
, 2); /* Align IP on 16 byte boundaries */
1333 /* 'skb_put()' points to the start of sk_buff data area. */
1334 insl(ioaddr
+ RX_FIFO
,
1335 skb_put(skb
, pkt_len
),
1336 (pkt_len
+ 3) >> 2);
1337 outw(RxDiscard
, ioaddr
+ EL3_CMD
); /* Pop top Rx packet. */
1338 skb
->protocol
= eth_type_trans(skb
, dev
);
1340 dev
->last_rx
= jiffies
;
1341 vp
->stats
.rx_packets
++;
1342 vp
->stats
.rx_bytes
+= pkt_len
;
1343 /* Wait a limited time to go to next packet. */
1344 for (i
= 200; i
>= 0; i
--)
1345 if (! (inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
))
1348 } else if (corkscrew_debug
)
1349 printk("%s: Couldn't allocate a sk_buff of size %d.\n", dev
->name
, pkt_len
);
1351 outw(RxDiscard
, ioaddr
+ EL3_CMD
);
1352 vp
->stats
.rx_dropped
++;
1353 /* Wait a limited time to skip this packet. */
1354 for (i
= 200; i
>= 0; i
--)
1355 if (!(inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
))
1361 static int boomerang_rx(struct net_device
*dev
)
1363 struct corkscrew_private
*vp
=
1364 (struct corkscrew_private
*) dev
->priv
;
1365 int entry
= vp
->cur_rx
% RX_RING_SIZE
;
1366 int ioaddr
= dev
->base_addr
;
1369 if (corkscrew_debug
> 5)
1370 printk(" In boomerang_rx(), status %4.4x, rx_status %4.4x.\n",
1371 inw(ioaddr
+ EL3_STATUS
), inw(ioaddr
+ RxStatus
));
1372 while ((rx_status
= vp
->rx_ring
[entry
].status
) & RxDComplete
) {
1373 if (rx_status
& RxDError
) { /* Error, update stats. */
1374 unsigned char rx_error
= rx_status
>> 16;
1375 if (corkscrew_debug
> 2)
1376 printk(" Rx error: status %2.2x.\n",
1378 vp
->stats
.rx_errors
++;
1379 if (rx_error
& 0x01)
1380 vp
->stats
.rx_over_errors
++;
1381 if (rx_error
& 0x02)
1382 vp
->stats
.rx_length_errors
++;
1383 if (rx_error
& 0x04)
1384 vp
->stats
.rx_frame_errors
++;
1385 if (rx_error
& 0x08)
1386 vp
->stats
.rx_crc_errors
++;
1387 if (rx_error
& 0x10)
1388 vp
->stats
.rx_length_errors
++;
1390 /* The packet length: up to 4.5K!. */
1391 short pkt_len
= rx_status
& 0x1fff;
1392 struct sk_buff
*skb
;
1394 vp
->stats
.rx_bytes
+= pkt_len
;
1395 if (corkscrew_debug
> 4)
1396 printk("Receiving packet size %d status %4.4x.\n",
1397 pkt_len
, rx_status
);
1399 /* Check if the packet is long enough to just accept without
1400 copying to a properly sized skbuff. */
1401 if (pkt_len
< rx_copybreak
1402 && (skb
= dev_alloc_skb(pkt_len
+ 4)) != 0) {
1404 skb_reserve(skb
, 2); /* Align IP on 16 byte boundaries */
1405 /* 'skb_put()' points to the start of sk_buff data area. */
1406 memcpy(skb_put(skb
, pkt_len
),
1407 isa_bus_to_virt(vp
->rx_ring
[entry
].
1412 /* Pass up the skbuff already on the Rx ring. */
1413 skb
= vp
->rx_skbuff
[entry
];
1414 vp
->rx_skbuff
[entry
] = NULL
;
1415 temp
= skb_put(skb
, pkt_len
);
1416 /* Remove this checking code for final release. */
1417 if (isa_bus_to_virt(vp
->rx_ring
[entry
].addr
) != temp
)
1418 printk("%s: Warning -- the skbuff addresses do not match"
1419 " in boomerang_rx: %p vs. %p / %p.\n",
1421 isa_bus_to_virt(vp
->
1427 skb
->protocol
= eth_type_trans(skb
, dev
);
1429 dev
->last_rx
= jiffies
;
1430 vp
->stats
.rx_packets
++;
1432 entry
= (++vp
->cur_rx
) % RX_RING_SIZE
;
1434 /* Refill the Rx ring buffers. */
1435 for (; vp
->cur_rx
- vp
->dirty_rx
> 0; vp
->dirty_rx
++) {
1436 struct sk_buff
*skb
;
1437 entry
= vp
->dirty_rx
% RX_RING_SIZE
;
1438 if (vp
->rx_skbuff
[entry
] == NULL
) {
1439 skb
= dev_alloc_skb(PKT_BUF_SZ
);
1441 break; /* Bad news! */
1442 skb
->dev
= dev
; /* Mark as being used by this device. */
1443 skb_reserve(skb
, 2); /* Align IP on 16 byte boundaries */
1444 vp
->rx_ring
[entry
].addr
= isa_virt_to_bus(skb
->tail
);
1445 vp
->rx_skbuff
[entry
] = skb
;
1447 vp
->rx_ring
[entry
].status
= 0; /* Clear complete bit. */
1452 static int corkscrew_close(struct net_device
*dev
)
1454 struct corkscrew_private
*vp
=
1455 (struct corkscrew_private
*) dev
->priv
;
1456 int ioaddr
= dev
->base_addr
;
1459 netif_stop_queue(dev
);
1461 if (corkscrew_debug
> 1) {
1462 printk("%s: corkscrew_close() status %4.4x, Tx status %2.2x.\n",
1463 dev
->name
, inw(ioaddr
+ EL3_STATUS
),
1464 inb(ioaddr
+ TxStatus
));
1465 printk("%s: corkscrew close stats: rx_nocopy %d rx_copy %d"
1466 " tx_queued %d.\n", dev
->name
, rx_nocopy
, rx_copy
,
1470 del_timer(&vp
->timer
);
1472 /* Turn off statistics ASAP. We update lp->stats below. */
1473 outw(StatsDisable
, ioaddr
+ EL3_CMD
);
1475 /* Disable the receiver and transmitter. */
1476 outw(RxDisable
, ioaddr
+ EL3_CMD
);
1477 outw(TxDisable
, ioaddr
+ EL3_CMD
);
1479 if (dev
->if_port
== XCVR_10base2
)
1480 /* Turn off thinnet power. Green! */
1481 outw(StopCoax
, ioaddr
+ EL3_CMD
);
1483 free_irq(dev
->irq
, dev
);
1485 outw(SetIntrEnb
| 0x0000, ioaddr
+ EL3_CMD
);
1487 update_stats(ioaddr
, dev
);
1488 if (vp
->full_bus_master_rx
) { /* Free Boomerang bus master Rx buffers. */
1489 outl(0, ioaddr
+ UpListPtr
);
1490 for (i
= 0; i
< RX_RING_SIZE
; i
++)
1491 if (vp
->rx_skbuff
[i
]) {
1492 dev_kfree_skb(vp
->rx_skbuff
[i
]);
1493 vp
->rx_skbuff
[i
] = 0;
1496 if (vp
->full_bus_master_tx
) { /* Free Boomerang bus master Tx buffers. */
1497 outl(0, ioaddr
+ DownListPtr
);
1498 for (i
= 0; i
< TX_RING_SIZE
; i
++)
1499 if (vp
->tx_skbuff
[i
]) {
1500 dev_kfree_skb(vp
->tx_skbuff
[i
]);
1501 vp
->tx_skbuff
[i
] = 0;
1508 static struct net_device_stats
*corkscrew_get_stats(struct net_device
*dev
)
1510 struct corkscrew_private
*vp
= (struct corkscrew_private
*) dev
->priv
;
1511 unsigned long flags
;
1513 if (netif_running(dev
)) {
1514 spin_lock_irqsave(&vp
->lock
, flags
);
1515 update_stats(dev
->base_addr
, dev
);
1516 spin_unlock_irqrestore(&vp
->lock
, flags
);
1521 /* Update statistics.
1522 Unlike with the EL3 we need not worry about interrupts changing
1523 the window setting from underneath us, but we must still guard
1524 against a race condition with a StatsUpdate interrupt updating the
1525 table. This is done by checking that the ASM (!) code generated uses
1526 atomic updates with '+='.
1528 static void update_stats(int ioaddr
, struct net_device
*dev
)
1530 struct corkscrew_private
*vp
=
1531 (struct corkscrew_private
*) dev
->priv
;
1533 /* Unlike the 3c5x9 we need not turn off stats updates while reading. */
1534 /* Switch to the stats window, and read everything. */
1536 vp
->stats
.tx_carrier_errors
+= inb(ioaddr
+ 0);
1537 vp
->stats
.tx_heartbeat_errors
+= inb(ioaddr
+ 1);
1538 /* Multiple collisions. */ inb(ioaddr
+ 2);
1539 vp
->stats
.collisions
+= inb(ioaddr
+ 3);
1540 vp
->stats
.tx_window_errors
+= inb(ioaddr
+ 4);
1541 vp
->stats
.rx_fifo_errors
+= inb(ioaddr
+ 5);
1542 vp
->stats
.tx_packets
+= inb(ioaddr
+ 6);
1543 vp
->stats
.tx_packets
+= (inb(ioaddr
+ 9) & 0x30) << 4;
1544 /* Rx packets */ inb(ioaddr
+ 7);
1545 /* Must read to clear */
1546 /* Tx deferrals */ inb(ioaddr
+ 8);
1547 /* Don't bother with register 9, an extension of registers 6&7.
1548 If we do use the 6&7 values the atomic update assumption above
1550 inw(ioaddr
+ 10); /* Total Rx and Tx octets. */
1552 /* New: On the Vortex we must also clear the BadSSD counter. */
1556 /* We change back to window 7 (not 1) with the Vortex. */
1561 /* This new version of set_rx_mode() supports v1.4 kernels.
1562 The Vortex chip has no documented multicast filter, so the only
1563 multicast setting is to receive all multicast frames. At least
1564 the chip has a very clean way to set the mode, unlike many others. */
1565 static void set_rx_mode(struct net_device
*dev
)
1567 int ioaddr
= dev
->base_addr
;
1570 if (dev
->flags
& IFF_PROMISC
) {
1571 if (corkscrew_debug
> 3)
1572 printk("%s: Setting promiscuous mode.\n",
1574 new_mode
= SetRxFilter
| RxStation
| RxMulticast
| RxBroadcast
| RxProm
;
1575 } else if ((dev
->mc_list
) || (dev
->flags
& IFF_ALLMULTI
)) {
1576 new_mode
= SetRxFilter
| RxStation
| RxMulticast
| RxBroadcast
;
1578 new_mode
= SetRxFilter
| RxStation
| RxBroadcast
;
1580 outw(new_mode
, ioaddr
+ EL3_CMD
);
1584 * netdev_ethtool_ioctl: Handle network interface SIOCETHTOOL ioctls
1585 * @dev: network interface on which out-of-band action is to be performed
1586 * @useraddr: userspace address to which data is to be read and returned
1588 * Process the various commands of the SIOCETHTOOL interface.
1591 static int netdev_ethtool_ioctl (struct net_device
*dev
, void *useraddr
)
1595 /* dev_ioctl() in ../../net/core/dev.c has already checked
1596 capable(CAP_NET_ADMIN), so don't bother with that here. */
1598 if (get_user(ethcmd
, (u32
*)useraddr
))
1603 case ETHTOOL_GDRVINFO
: {
1604 struct ethtool_drvinfo info
= { ETHTOOL_GDRVINFO
};
1605 strcpy (info
.driver
, DRV_NAME
);
1606 strcpy (info
.version
, DRV_VERSION
);
1607 sprintf(info
.bus_info
, "ISA 0x%lx", dev
->base_addr
);
1608 if (copy_to_user (useraddr
, &info
, sizeof (info
)))
1613 /* get message-level */
1614 case ETHTOOL_GMSGLVL
: {
1615 struct ethtool_value edata
= {ETHTOOL_GMSGLVL
};
1616 edata
.data
= corkscrew_debug
;
1617 if (copy_to_user(useraddr
, &edata
, sizeof(edata
)))
1621 /* set message-level */
1622 case ETHTOOL_SMSGLVL
: {
1623 struct ethtool_value edata
;
1624 if (copy_from_user(&edata
, useraddr
, sizeof(edata
)))
1626 corkscrew_debug
= edata
.data
;
1638 * netdev_ioctl: Handle network interface ioctls
1639 * @dev: network interface on which out-of-band action is to be performed
1640 * @rq: user request data
1641 * @cmd: command issued by user
1643 * Process the various out-of-band ioctls passed to this driver.
1646 static int netdev_ioctl (struct net_device
*dev
, struct ifreq
*rq
, int cmd
)
1652 rc
= netdev_ethtool_ioctl(dev
, (void *) rq
->ifr_data
);
1665 void cleanup_module(void)
1667 struct net_device
*next_dev
;
1669 while (root_corkscrew_dev
) {
1671 ((struct corkscrew_private
*) root_corkscrew_dev
->
1673 if (root_corkscrew_dev
->dma
)
1674 free_dma(root_corkscrew_dev
->dma
);
1675 unregister_netdev(root_corkscrew_dev
);
1676 outw(TotalReset
, root_corkscrew_dev
->base_addr
+ EL3_CMD
);
1677 release_region(root_corkscrew_dev
->base_addr
,
1678 CORKSCREW_TOTAL_SIZE
);
1679 kfree(root_corkscrew_dev
);
1680 root_corkscrew_dev
= next_dev
;
1687 * compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c 3c515.c"