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
15 static char *version
= "3c515.c:v0.99 4/7/98 becker@cesdis.gsfc.nasa.gov\n";
18 /* "Knobs" that adjust features and parameters. */
19 /* Set the copy breakpoint for the copy-only-tiny-frames scheme.
20 Setting to > 1512 effectively disables this feature. */
21 static const int rx_copybreak
= 200;
22 /* Allow setting MTU to a larger size, bypassing the normal ethernet setup. */
23 static const int mtu
= 1500;
24 /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
25 static int max_interrupt_work
= 20;
27 /* Enable the automatic media selection code -- usually set. */
30 /* Allow the use of fragment bus master transfers instead of only
31 programmed-I/O for Vortex cards. Full-bus-master transfers are always
32 enabled by default on Boomerang cards. If VORTEX_BUS_MASTER is defined,
33 the feature may be turned on using 'options'. */
34 #define VORTEX_BUS_MASTER
36 /* A few values that may be tweaked. */
37 /* Keep the ring sizes a power of two for efficiency. */
38 #define TX_RING_SIZE 16
39 #define RX_RING_SIZE 16
40 #define PKT_BUF_SZ 1536 /* Size of each temporary Rx buffer.*/
42 #include <linux/module.h>
43 #include <linux/version.h>
45 #include <linux/kernel.h>
46 #include <linux/sched.h>
47 #include <linux/string.h>
48 #include <linux/ptrace.h>
49 #include <linux/errno.h>
51 #include <linux/ioport.h>
52 #include <linux/malloc.h>
53 #include <linux/interrupt.h>
54 #include <linux/timer.h>
55 #include <asm/bitops.h>
59 #include <linux/netdevice.h>
60 #include <linux/etherdevice.h>
61 #include <linux/skbuff.h>
64 #include <linux/delay.h>
66 /* Kernel version compatibility functions. */
67 #define RUN_AT(x) (jiffies + (x))
68 #define DEV_ALLOC_SKB(len) dev_alloc_skb(len + 2)
70 #define FREE_IRQ(irqnum, dev) free_irq(irqnum, dev)
71 #define REQUEST_IRQ(i,h,f,n, instance) request_irq(i,h,f,n, instance)
72 #define IRQ(irq, dev_id, pt_regs) (irq, dev_id, pt_regs)
74 #if (LINUX_VERSION_CODE < 0x20123)
75 #define test_and_set_bit(val, addr) set_bit(val, addr)
77 MODULE_AUTHOR("Donald Becker <becker@cesdis.gsfc.nasa.gov>");
78 MODULE_DESCRIPTION("3Com 3c515 Corkscrew driver");
79 MODULE_PARM(debug
, "i");
80 MODULE_PARM(options
, "1-" __MODULE_STRING(8) "i");
81 MODULE_PARM(full_duplex
, "1-" __MODULE_STRING(8) "i");
82 MODULE_PARM(rx_copybreak
, "i");
83 MODULE_PARM(max_interrupt_work
, "i");
86 /* "Knobs" for adjusting internal parameters. */
87 /* Put out somewhat more debugging messages. (0 - no msg, 1 minimal msgs). */
88 #define DRIVER_DEBUG 1
89 /* Some values here only for performance evaluation and path-coverage
91 static int rx_nocopy
= 0, rx_copy
= 0, queued_packet
= 0;
93 /* Number of times to check to see if the Tx FIFO has space, used in some
95 #define WAIT_TX_AVAIL 200
97 /* Operational parameter that usually are not changed. */
98 #define TX_TIMEOUT 40 /* Time in jiffies before concluding Tx hung */
100 /* The size here is somewhat misleading: the Corkscrew also uses the ISA
101 aliased registers at <base>+0x400.
103 #define CORKSCREW_TOTAL_SIZE 0x20
106 struct netdev_entry tc515_drv
=
107 {"3c515", tc515_probe
, CORKSCREW_TOTAL_SIZE
, NULL
};
111 int vortex_debug
= DRIVER_DEBUG
;
113 int vortex_debug
= 1;
116 #define CORKSCREW_ID 10
121 I. Board Compatibility
123 This device driver is designed for the 3Com 3c515 ISA Fast EtherLink XL,
124 3Com's ISA bus adapter for Fast Ethernet. Due to the unique I/O port layout,
125 it's not practical to integrate this driver with the other EtherLink drivers.
127 II. Board-specific settings
129 The Corkscrew has an EEPROM for configuration, but no special settings are
132 III. Driver operation
134 The 3c515 series use an interface that's very similar to the 3c900 "Boomerang"
135 PCI cards, with the bus master interface extensively modified to work with
138 The card is capable of full-bus-master transfers with separate
139 lists of transmit and receive descriptors, similar to the AMD LANCE/PCnet,
140 DEC Tulip and Intel Speedo3.
142 This driver uses a "RX_COPYBREAK" scheme rather than a fixed intermediate
143 receive buffer. This scheme allocates full-sized skbuffs as receive
144 buffers. The value RX_COPYBREAK is used as the copying breakpoint: it is
145 chosen to trade-off the memory wasted by passing the full-sized skbuff to
146 the queue layer for all frames vs. the copying cost of copying a frame to a
147 correctly-sized skbuff.
150 IIIC. Synchronization
151 The driver runs as two independent, single-threaded flows of control. One
152 is the send-packet routine, which enforces single-threaded use by the
153 dev->tbusy flag. The other thread is the interrupt handler, which is single
154 threaded by the hardware and other software.
158 Thanks to Terry Murphy of 3Com for providing documentation and a development
161 The names "Vortex", "Boomerang" and "Corkscrew" are the internal 3Com
162 project names. I use these names to eliminate confusion -- 3Com product
163 numbers and names are very similar and often confused.
165 The new chips support both ethernet (1.5K) and FDDI (4.5K) frame sizes!
166 This driver only supports ethernet frames because of the recent MTU limit
167 of 1.5K, but the changes to support 4.5K are minimal.
170 /* Operational definitions.
171 These are not used by other compilation units and thus are not
172 exported in a ".h" file.
174 First the windows. There are eight register windows, with the command
175 and status registers available in each.
177 #define EL3WINDOW(win_num) outw(SelectWindow + (win_num), ioaddr + EL3_CMD)
179 #define EL3_STATUS 0x0e
181 /* The top five bits written to EL3_CMD are a command, the lower
182 11 bits are the parameter, if applicable.
183 Note that 11 parameters bits was fine for ethernet, but the new chips
184 can handle FDDI length frames (~4500 octets) and now parameters count
185 32-bit 'Dwords' rather than octets. */
188 TotalReset
= 0<<11, SelectWindow
= 1<<11, StartCoax
= 2<<11,
189 RxDisable
= 3<<11, RxEnable
= 4<<11, RxReset
= 5<<11,
190 UpStall
= 6<<11, UpUnstall
= (6<<11)+1,
191 DownStall
= (6<<11)+2, DownUnstall
= (6<<11)+3,
192 RxDiscard
= 8<<11, TxEnable
= 9<<11, TxDisable
= 10<<11, TxReset
= 11<<11,
193 FakeIntr
= 12<<11, AckIntr
= 13<<11, SetIntrEnb
= 14<<11,
194 SetStatusEnb
= 15<<11, SetRxFilter
= 16<<11, SetRxThreshold
= 17<<11,
195 SetTxThreshold
= 18<<11, SetTxStart
= 19<<11,
196 StartDMAUp
= 20<<11, StartDMADown
= (20<<11)+1, StatsEnable
= 21<<11,
197 StatsDisable
= 22<<11, StopCoax
= 23<<11,};
199 /* The SetRxFilter command accepts the following classes: */
201 RxStation
= 1, RxMulticast
= 2, RxBroadcast
= 4, RxProm
= 8 };
203 /* Bits in the general status register. */
205 IntLatch
= 0x0001, AdapterFailure
= 0x0002, TxComplete
= 0x0004,
206 TxAvailable
= 0x0008, RxComplete
= 0x0010, RxEarly
= 0x0020,
207 IntReq
= 0x0040, StatsFull
= 0x0080,
208 DMADone
= 1<<8, DownComplete
= 1<<9, UpComplete
= 1<<10,
209 DMAInProgress
= 1<<11, /* DMA controller is still busy.*/
210 CmdInProgress
= 1<<12, /* EL3_CMD is still busy.*/
213 /* Register window 1 offsets, the window used in normal operation.
214 On the Corkscrew this window is always mapped at offsets 0x10-0x1f. */
216 TX_FIFO
= 0x10, RX_FIFO
= 0x10, RxErrors
= 0x14,
217 RxStatus
= 0x18, Timer
=0x1A, TxStatus
= 0x1B,
218 TxFree
= 0x1C, /* Remaining free bytes in Tx buffer. */
222 #if defined(CORKSCREW)
223 Wn0EepromCmd
= 0x200A, /* Corkscrew EEPROM command register. */
224 Wn0EepromData
= 0x200C, /* Corkscrew EEPROM results register. */
226 Wn0EepromCmd
= 10, /* Window 0: EEPROM command register. */
227 Wn0EepromData
= 12, /* Window 0: EEPROM results register. */
230 enum Win0_EEPROM_bits
{
231 EEPROM_Read
= 0x80, EEPROM_WRITE
= 0x40, EEPROM_ERASE
= 0xC0,
232 EEPROM_EWENB
= 0x30, /* Enable erasing/writing for 10 msec. */
233 EEPROM_EWDIS
= 0x00, /* Disable EWENB before 10 msec timeout. */
235 /* EEPROM locations. */
237 PhysAddr01
=0, PhysAddr23
=1, PhysAddr45
=2, ModelID
=3,
240 enum Window3
{ /* Window 3: MAC/config bits. */
241 Wn3_Config
=0, Wn3_MAC_Ctrl
=6, Wn3_Options
=8,
245 struct w3_config_fields
{
246 unsigned int ram_size
:3, ram_width
:1, ram_speed
:2, rom_size
:2;
248 unsigned int ram_split
:2, pad18
:2, xcvr
:3, pad21
:1, autoselect
:1;
254 Wn4_NetDiag
= 6, Wn4_Media
= 10, /* Window 4: Xcvr/media bits. */
256 enum Win4_Media_bits
{
257 Media_SQE
= 0x0008, /* Enable SQE error counting for AUI. */
258 Media_10TP
= 0x00C0, /* Enable link beat and jabber for 10baseT. */
259 Media_Lnk
= 0x0080, /* Enable just link beat for 100TX/100FX. */
260 Media_LnkBeat
= 0x0800,
262 enum Window7
{ /* Window 7: Bus Master control. */
263 Wn7_MasterAddr
= 0, Wn7_MasterLen
= 6, Wn7_MasterStatus
= 12,
265 /* Boomerang-style bus master control registers. Note ISA aliases! */
267 PktStatus
= 0x400, DownListPtr
= 0x404, FragAddr
= 0x408, FragLen
= 0x40c,
268 TxFreeThreshold
= 0x40f, UpPktStatus
= 0x410, UpListPtr
= 0x418,
271 /* The Rx and Tx descriptor lists.
272 Caution Alpha hackers: these types are 32 bits! Note also the 8 byte
273 alignment contraint on tx_ring[] and rx_ring[]. */
274 struct boom_rx_desc
{
280 /* Values for the Rx status entry. */
281 enum rx_desc_status
{
282 RxDComplete
=0x00008000, RxDError
=0x4000,
283 /* See boomerang_rx() for actual error bits */
286 struct boom_tx_desc
{
293 struct vortex_private
{
294 char devname
[8]; /* "ethN" string, also for kernel debug. */
295 const char *product_name
;
296 struct net_device
*next_module
;
297 /* The Rx and Tx rings are here to keep them quad-word-aligned. */
298 struct boom_rx_desc rx_ring
[RX_RING_SIZE
];
299 struct boom_tx_desc tx_ring
[TX_RING_SIZE
];
300 /* The addresses of transmit- and receive-in-place skbuffs. */
301 struct sk_buff
* rx_skbuff
[RX_RING_SIZE
];
302 struct sk_buff
* tx_skbuff
[TX_RING_SIZE
];
303 unsigned int cur_rx
, cur_tx
; /* The next free ring entry */
304 unsigned int dirty_rx
, dirty_tx
; /* The ring entries to be free()ed. */
305 struct enet_statistics stats
;
306 struct sk_buff
*tx_skb
; /* Packet being eaten by bus master ctrl. */
307 struct timer_list timer
; /* Media selection timer. */
308 int capabilities
; /* Adapter capabilities word. */
309 int options
; /* User-settable misc. driver options. */
310 int last_rx_packets
; /* For media autoselection. */
311 unsigned int available_media
:8, /* From Wn3_Options */
312 media_override
:3, /* Passed-in media type. */
313 default_media
:3, /* Read from the EEPROM. */
314 full_duplex
:1, autoselect
:1,
315 bus_master
:1, /* Vortex can only do a fragment bus-m. */
316 full_bus_master_tx
:1, full_bus_master_rx
:1, /* Boomerang */
320 /* The action to take with a media selection timer tick.
321 Note that we deviate from the 3Com order by checking 10base2 before AUI.
324 XCVR_10baseT
=0, XCVR_AUI
, XCVR_10baseTOnly
, XCVR_10base2
, XCVR_100baseTx
,
325 XCVR_100baseFx
, XCVR_MII
=6, XCVR_Default
=8,
328 static struct media_table
{
330 unsigned int media_bits
:16, /* Bits to set in Wn4_Media register. */
331 mask
:8, /* The transceiver-present bit in Wn3_Config.*/
332 next
:8; /* The media type to try next. */
333 short wait
; /* Time before we check media status. */
335 { "10baseT", Media_10TP
,0x08, XCVR_10base2
, (14*HZ
)/10},
336 { "10Mbs AUI", Media_SQE
, 0x20, XCVR_Default
, (1*HZ
)/10},
337 { "undefined", 0, 0x80, XCVR_10baseT
, 10000},
338 { "10base2", 0, 0x10, XCVR_AUI
, (1*HZ
)/10},
339 { "100baseTX", Media_Lnk
, 0x02, XCVR_100baseFx
, (14*HZ
)/10},
340 { "100baseFX", Media_Lnk
, 0x04, XCVR_MII
, (14*HZ
)/10},
341 { "MII", 0, 0x40, XCVR_10baseT
, 3*HZ
},
342 { "undefined", 0, 0x01, XCVR_10baseT
, 10000},
343 { "Default", 0, 0xFF, XCVR_10baseT
, 10000},
346 static int vortex_scan(struct net_device
*dev
);
347 static struct net_device
*vortex_found_device(struct net_device
*dev
, int ioaddr
,
348 int irq
, int product_index
,
350 static int vortex_probe1(struct net_device
*dev
);
351 static int vortex_open(struct net_device
*dev
);
352 static void vortex_timer(unsigned long arg
);
353 static int vortex_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
);
354 static int vortex_rx(struct net_device
*dev
);
355 static int boomerang_rx(struct net_device
*dev
);
356 static void vortex_interrupt
IRQ(int irq
, void *dev_id
, struct pt_regs
*regs
);
357 static int vortex_close(struct net_device
*dev
);
358 static void update_stats(int addr
, struct net_device
*dev
);
359 static struct enet_statistics
*vortex_get_stats(struct net_device
*dev
);
360 static void set_rx_mode(struct net_device
*dev
);
363 /* Unlike the other PCI cards the 59x cards don't need a large contiguous
364 memory region, so making the driver a loadable module is feasible.
366 Unfortunately maximizing the shared code between the integrated and
367 module version of the driver results in a complicated set of initialization
369 init_module() -- modules / tc59x_init() -- built-in
370 The wrappers for vortex_scan()
371 vortex_scan() The common routine that scans for PCI and EISA cards
372 vortex_found_device() Allocate a device structure when we find a card.
373 Different versions exist for modules and built-in.
374 vortex_probe1() Fill in the device structure -- this is separated
375 so that the modules code can put it in dev->init.
377 /* This driver uses 'options' to pass the media type, full-duplex flag, etc. */
378 /* Note: this is the only limit on the number of cards supported!! */
379 static int options
[8] = { -1, -1, -1, -1, -1, -1, -1, -1,};
382 static int debug
= -1;
383 /* A list of all installed Vortex devices, for removing the driver module. */
384 static struct net_device
*root_vortex_dev
= NULL
;
392 vortex_debug
= debug
;
396 root_vortex_dev
= NULL
;
397 cards_found
= vortex_scan(0);
398 return cards_found
? 0 : -ENODEV
;
402 int tc515_probe(struct net_device
*dev
)
406 cards_found
= vortex_scan(dev
);
408 if (vortex_debug
> 0 && cards_found
)
411 return cards_found
? 0 : -ENODEV
;
413 #endif /* not MODULE */
415 static int vortex_scan(struct net_device
*dev
)
418 static int ioaddr
= 0x100;
420 /* Check all locations on the ISA bus -- evil! */
421 for (; ioaddr
< 0x400; ioaddr
+= 0x20) {
423 if (check_region(ioaddr
, CORKSCREW_TOTAL_SIZE
))
425 /* Check the resource configuration for a matching ioaddr. */
426 if ((inw(ioaddr
+ 0x2002) & 0x1f0) != (ioaddr
& 0x1f0))
428 /* Verify by reading the device ID from the EEPROM. */
431 outw(EEPROM_Read
+ 7, ioaddr
+ Wn0EepromCmd
);
432 /* Pause for at least 162 us. for the read to take place. */
433 for (timer
= 4; timer
>= 0; timer
--) {
435 if ((inw(ioaddr
+ Wn0EepromCmd
) & 0x0200) == 0)
438 if (inw(ioaddr
+ Wn0EepromData
) != 0x6d50)
441 printk("3c515 Resource configuraiton register %#4.4x, DCR %4.4x.\n",
442 inl(ioaddr
+ 0x2002), inw(ioaddr
+ 0x2000));
443 irq
= inw(ioaddr
+ 0x2002) & 15;
444 vortex_found_device(dev
, ioaddr
, irq
, CORKSCREW_ID
, dev
&& dev
->mem_start
445 ? dev
->mem_start
: options
[cards_found
]);
451 printk("%d 3c515 cards found.\n", cards_found
);
455 static struct net_device
*vortex_found_device(struct net_device
*dev
, int ioaddr
,
456 int irq
, int product_index
,
459 struct vortex_private
*vp
;
462 /* Allocate and fill new device structure. */
463 int dev_size
= sizeof(struct net_device
) +
464 sizeof(struct vortex_private
) + 15; /* Pad for alignment */
466 dev
= (struct net_device
*) kmalloc(dev_size
, GFP_KERNEL
);
467 memset(dev
, 0, dev_size
);
468 /* Align the Rx and Tx ring entries. */
469 dev
->priv
= (void *)(((long)dev
+ sizeof(struct net_device
) + 15) & ~15);
470 vp
= (struct vortex_private
*)dev
->priv
;
471 dev
->name
= vp
->devname
; /* An empty string. */
472 dev
->base_addr
= ioaddr
;
474 dev
->dma
= (product_index
== CORKSCREW_ID
? inw(ioaddr
+ 0x2000) & 7 : 0);
475 dev
->init
= vortex_probe1
;
476 vp
->product_name
= "3c515";
477 vp
->options
= options
;
479 vp
->media_override
= ((options
& 7) == 2) ? 0 : options
& 7;
480 vp
->full_duplex
= (options
& 8) ? 1 : 0;
481 vp
->bus_master
= (options
& 16) ? 1 : 0;
483 vp
->media_override
= 7;
488 vp
->next_module
= root_vortex_dev
;
489 root_vortex_dev
= dev
;
490 if (register_netdev(dev
) != 0)
492 #else /* not a MODULE */
494 /* Caution: quad-word alignment required for rings! */
495 dev
->priv
= kmalloc(sizeof (struct vortex_private
), GFP_KERNEL
);
496 memset(dev
->priv
, 0, sizeof (struct vortex_private
));
498 dev
= init_etherdev(dev
, sizeof(struct vortex_private
));
499 dev
->base_addr
= ioaddr
;
501 dev
->dma
= (product_index
== CORKSCREW_ID
? inw(ioaddr
+ 0x2000) & 7 : 0);
502 vp
= (struct vortex_private
*)dev
->priv
;
503 vp
->product_name
= "3c515";
504 vp
->options
= options
;
506 vp
->media_override
= ((options
& 7) == 2) ? 0 : options
& 7;
507 vp
->full_duplex
= (options
& 8) ? 1 : 0;
508 vp
->bus_master
= (options
& 16) ? 1 : 0;
510 vp
->media_override
= 7;
520 static int vortex_probe1(struct net_device
*dev
)
522 int ioaddr
= dev
->base_addr
;
523 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
;
524 unsigned int eeprom
[0x40], checksum
= 0; /* EEPROM contents */
527 printk("%s: 3Com %s at %#3x,", dev
->name
,
528 vp
->product_name
, ioaddr
);
530 /* Read the station address from the EEPROM. */
532 for (i
= 0; i
< 0x18; i
++) {
533 short *phys_addr
= (short *)dev
->dev_addr
;
535 outw(EEPROM_Read
+ i
, ioaddr
+ Wn0EepromCmd
);
536 /* Pause for at least 162 us. for the read to take place. */
537 for (timer
= 4; timer
>= 0; timer
--) {
539 if ((inw(ioaddr
+ Wn0EepromCmd
) & 0x0200) == 0)
542 eeprom
[i
] = inw(ioaddr
+ Wn0EepromData
);
543 checksum
^= eeprom
[i
];
545 phys_addr
[i
] = htons(eeprom
[i
]);
547 checksum
= (checksum
^ (checksum
>> 8)) & 0xff;
548 if (checksum
!= 0x00)
549 printk(" ***INVALID CHECKSUM %4.4x*** ", checksum
);
550 for (i
= 0; i
< 6; i
++)
551 printk("%c%2.2x", i
? ':' : ' ', dev
->dev_addr
[i
]);
552 if (eeprom
[16] == 0x11c7) { /* Corkscrew */
553 if (request_dma(dev
->dma
, "3c515")) {
554 printk(", DMA %d allocation failed", dev
->dma
);
557 printk(", DMA %d", dev
->dma
);
559 printk(", IRQ %d\n", dev
->irq
);
560 /* Tell them about an invalid IRQ. */
561 if (vortex_debug
&& (dev
->irq
<= 0 || dev
->irq
> 15))
562 printk(" *** Warning: this IRQ is unlikely to work! ***\n");
565 char *ram_split
[] = {"5:3", "3:1", "1:1", "3:5"};
566 union wn3_config config
;
568 vp
->available_media
= inw(ioaddr
+ Wn3_Options
);
569 config
.i
= inl(ioaddr
+ Wn3_Config
);
570 if (vortex_debug
> 1)
571 printk(" Internal config register is %4.4x, transceivers %#x.\n",
572 config
.i
, inw(ioaddr
+ Wn3_Options
));
573 printk(" %dK %s-wide RAM %s Rx:Tx split, %s%s interface.\n",
574 8 << config
.u
.ram_size
,
575 config
.u
.ram_width
? "word" : "byte",
576 ram_split
[config
.u
.ram_split
],
577 config
.u
.autoselect
? "autoselect/" : "",
578 media_tbl
[config
.u
.xcvr
].name
);
579 dev
->if_port
= config
.u
.xcvr
;
580 vp
->default_media
= config
.u
.xcvr
;
581 vp
->autoselect
= config
.u
.autoselect
;
583 if (vp
->media_override
!= 7) {
584 printk(" Media override to transceiver type %d (%s).\n",
585 vp
->media_override
, media_tbl
[vp
->media_override
].name
);
586 dev
->if_port
= vp
->media_override
;
589 vp
->capabilities
= eeprom
[16];
590 vp
->full_bus_master_tx
= (vp
->capabilities
& 0x20) ? 1 : 0;
591 /* Rx is broken at 10mbps, so we always disable it. */
592 /* vp->full_bus_master_rx = 0;*/
593 vp
->full_bus_master_rx
= (vp
->capabilities
& 0x20) ? 1 : 0;
595 /* We do a request_region() to register /proc/ioports info. */
596 request_region(ioaddr
, CORKSCREW_TOTAL_SIZE
, vp
->product_name
);
598 /* The 3c59x-specific entries in the device structure. */
599 dev
->open
= &vortex_open
;
600 dev
->hard_start_xmit
= &vortex_start_xmit
;
601 dev
->stop
= &vortex_close
;
602 dev
->get_stats
= &vortex_get_stats
;
603 dev
->set_multicast_list
= &set_rx_mode
;
610 vortex_open(struct net_device
*dev
)
612 int ioaddr
= dev
->base_addr
;
613 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
;
614 union wn3_config config
;
617 /* Before initializing select the active media port. */
620 outb(0x20, ioaddr
+ Wn3_MAC_Ctrl
); /* Set the full-duplex bit. */
621 config
.i
= inl(ioaddr
+ Wn3_Config
);
623 if (vp
->media_override
!= 7) {
624 if (vortex_debug
> 1)
625 printk("%s: Media override to transceiver %d (%s).\n",
626 dev
->name
, vp
->media_override
,
627 media_tbl
[vp
->media_override
].name
);
628 dev
->if_port
= vp
->media_override
;
629 } else if (vp
->autoselect
) {
630 /* Find first available media type, starting with 100baseTx. */
632 while (! (vp
->available_media
& media_tbl
[dev
->if_port
].mask
))
633 dev
->if_port
= media_tbl
[dev
->if_port
].next
;
635 if (vortex_debug
> 1)
636 printk("%s: Initial media type %s.\n",
637 dev
->name
, media_tbl
[dev
->if_port
].name
);
639 init_timer(&vp
->timer
);
640 vp
->timer
.expires
= RUN_AT(media_tbl
[dev
->if_port
].wait
);
641 vp
->timer
.data
= (unsigned long)dev
;
642 vp
->timer
.function
= &vortex_timer
; /* timer handler */
643 add_timer(&vp
->timer
);
645 dev
->if_port
= vp
->default_media
;
647 config
.u
.xcvr
= dev
->if_port
;
648 outl(config
.i
, ioaddr
+ Wn3_Config
);
650 if (vortex_debug
> 1) {
651 printk("%s: vortex_open() InternalConfig %8.8x.\n",
652 dev
->name
, config
.i
);
655 outw(TxReset
, ioaddr
+ EL3_CMD
);
656 for (i
= 20; i
>= 0 ; i
--)
657 if ( ! (inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
))
660 outw(RxReset
, ioaddr
+ EL3_CMD
);
661 /* Wait a few ticks for the RxReset command to complete. */
662 for (i
= 20; i
>= 0 ; i
--)
663 if ( ! (inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
))
666 outw(SetStatusEnb
| 0x00, ioaddr
+ EL3_CMD
);
668 /* Use the now-standard shared IRQ implementation. */
669 if (vp
->capabilities
== 0x11c7) {
670 /* Corkscrew: Cannot share ISA resources. */
673 || request_irq(dev
->irq
, &vortex_interrupt
, 0,
674 vp
->product_name
, dev
))
676 enable_dma(dev
->dma
);
677 set_dma_mode(dev
->dma
, DMA_MODE_CASCADE
);
678 } else if (request_irq(dev
->irq
, &vortex_interrupt
, SA_SHIRQ
,
679 vp
->product_name
, dev
)) {
683 if (vortex_debug
> 1) {
685 printk("%s: vortex_open() irq %d media status %4.4x.\n",
686 dev
->name
, dev
->irq
, inw(ioaddr
+ Wn4_Media
));
689 /* Set the station address and mask in window 2 each time opened. */
691 for (i
= 0; i
< 6; i
++)
692 outb(dev
->dev_addr
[i
], ioaddr
+ i
);
696 if (dev
->if_port
== 3)
697 /* Start the thinnet transceiver. We should really wait 50ms...*/
698 outw(StartCoax
, ioaddr
+ EL3_CMD
);
700 outw((inw(ioaddr
+ Wn4_Media
) & ~(Media_10TP
|Media_SQE
)) |
701 media_tbl
[dev
->if_port
].media_bits
, ioaddr
+ Wn4_Media
);
703 /* Switch to the stats window, and clear all stats by reading. */
704 outw(StatsDisable
, ioaddr
+ EL3_CMD
);
706 for (i
= 0; i
< 10; i
++)
710 /* New: On the Vortex we must also clear the BadSSD counter. */
713 /* ..and on the Boomerang we enable the extra statistics bits. */
714 outw(0x0040, ioaddr
+ Wn4_NetDiag
);
716 /* Switch to register set 7 for normal use. */
719 if (vp
->full_bus_master_rx
) { /* Boomerang bus master. */
720 vp
->cur_rx
= vp
->dirty_rx
= 0;
721 if (vortex_debug
> 2)
722 printk("%s: Filling in the Rx ring.\n", dev
->name
);
723 for (i
= 0; i
< RX_RING_SIZE
; i
++) {
725 if (i
< (RX_RING_SIZE
- 1))
726 vp
->rx_ring
[i
].next
= virt_to_bus(&vp
->rx_ring
[i
+1]);
728 vp
->rx_ring
[i
].next
= 0;
729 vp
->rx_ring
[i
].status
= 0; /* Clear complete bit. */
730 vp
->rx_ring
[i
].length
= PKT_BUF_SZ
| 0x80000000;
731 skb
= dev_alloc_skb(PKT_BUF_SZ
);
732 vp
->rx_skbuff
[i
] = skb
;
734 break; /* Bad news! */
735 skb
->dev
= dev
; /* Mark as being used by this device. */
736 skb_reserve(skb
, 2); /* Align IP on 16 byte boundaries */
737 vp
->rx_ring
[i
].addr
= virt_to_bus(skb
->tail
);
739 vp
->rx_ring
[i
-1].next
= virt_to_bus(&vp
->rx_ring
[0]); /* Wrap the ring. */
740 outl(virt_to_bus(&vp
->rx_ring
[0]), ioaddr
+ UpListPtr
);
742 if (vp
->full_bus_master_tx
) { /* Boomerang bus master Tx. */
743 vp
->cur_tx
= vp
->dirty_tx
= 0;
744 outb(PKT_BUF_SZ
>>8, ioaddr
+ TxFreeThreshold
); /* Room for a packet. */
745 /* Clear the Tx ring. */
746 for (i
= 0; i
< TX_RING_SIZE
; i
++)
747 vp
->tx_skbuff
[i
] = 0;
748 outl(0, ioaddr
+ DownListPtr
);
750 /* Set receiver mode: presumably accept b-case and phys addr only. */
752 outw(StatsEnable
, ioaddr
+ EL3_CMD
); /* Turn on statistics. */
758 outw(RxEnable
, ioaddr
+ EL3_CMD
); /* Enable the receiver. */
759 outw(TxEnable
, ioaddr
+ EL3_CMD
); /* Enable transmitter. */
760 /* Allow status bits to be seen. */
761 outw(SetStatusEnb
| AdapterFailure
|IntReq
|StatsFull
|
762 (vp
->full_bus_master_tx
? DownComplete
: TxAvailable
) |
763 (vp
->full_bus_master_rx
? UpComplete
: RxComplete
) |
764 (vp
->bus_master
? DMADone
: 0),
766 /* Ack all pending events, and set active indicator mask. */
767 outw(AckIntr
| IntLatch
| TxAvailable
| RxEarly
| IntReq
,
769 outw(SetIntrEnb
| IntLatch
| TxAvailable
| RxComplete
| StatsFull
770 | (vp
->bus_master
? DMADone
: 0) | UpComplete
| DownComplete
,
778 static void vortex_timer(unsigned long data
)
781 struct net_device
*dev
= (struct net_device
*)data
;
782 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
;
783 int ioaddr
= dev
->base_addr
;
787 if (vortex_debug
> 1)
788 printk("%s: Media selection timer tick happened, %s.\n",
789 dev
->name
, media_tbl
[dev
->if_port
].name
);
791 save_flags(flags
); cli(); {
792 int old_window
= inw(ioaddr
+ EL3_CMD
) >> 13;
795 media_status
= inw(ioaddr
+ Wn4_Media
);
796 switch (dev
->if_port
) {
797 case 0: case 4: case 5: /* 10baseT, 100baseTX, 100baseFX */
798 if (media_status
& Media_LnkBeat
) {
800 if (vortex_debug
> 1)
801 printk("%s: Media %s has link beat, %x.\n",
802 dev
->name
, media_tbl
[dev
->if_port
].name
, media_status
);
803 } else if (vortex_debug
> 1)
804 printk("%s: Media %s is has no link beat, %x.\n",
805 dev
->name
, media_tbl
[dev
->if_port
].name
, media_status
);
808 default: /* Other media types handled by Tx timeouts. */
809 if (vortex_debug
> 1)
810 printk("%s: Media %s is has no indication, %x.\n",
811 dev
->name
, media_tbl
[dev
->if_port
].name
, media_status
);
815 union wn3_config config
;
818 dev
->if_port
= media_tbl
[dev
->if_port
].next
;
819 } while ( ! (vp
->available_media
& media_tbl
[dev
->if_port
].mask
));
820 if (dev
->if_port
== 8) { /* Go back to default. */
821 dev
->if_port
= vp
->default_media
;
822 if (vortex_debug
> 1)
823 printk("%s: Media selection failing, using default %s port.\n",
824 dev
->name
, media_tbl
[dev
->if_port
].name
);
826 if (vortex_debug
> 1)
827 printk("%s: Media selection failed, now trying %s port.\n",
828 dev
->name
, media_tbl
[dev
->if_port
].name
);
829 vp
->timer
.expires
= RUN_AT(media_tbl
[dev
->if_port
].wait
);
830 add_timer(&vp
->timer
);
832 outw((media_status
& ~(Media_10TP
|Media_SQE
)) |
833 media_tbl
[dev
->if_port
].media_bits
, ioaddr
+ Wn4_Media
);
836 config
.i
= inl(ioaddr
+ Wn3_Config
);
837 config
.u
.xcvr
= dev
->if_port
;
838 outl(config
.i
, ioaddr
+ Wn3_Config
);
840 outw(dev
->if_port
== 3 ? StartCoax
: StopCoax
, ioaddr
+ EL3_CMD
);
842 EL3WINDOW(old_window
);
843 } restore_flags(flags
);
844 if (vortex_debug
> 1)
845 printk("%s: Media selection timer finished, %s.\n",
846 dev
->name
, media_tbl
[dev
->if_port
].name
);
848 #endif /* AUTOMEDIA*/
853 vortex_start_xmit(struct sk_buff
*skb
, struct net_device
*dev
)
855 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
;
856 int ioaddr
= dev
->base_addr
;
859 int tickssofar
= jiffies
- dev
->trans_start
;
862 /* Min. wait before assuming a Tx failed == 400ms. */
864 if (tickssofar
< 400*HZ
/1000) /* We probably aren't empty. */
866 printk("%s: transmit timed out, tx_status %2.2x status %4.4x.\n",
867 dev
->name
, inb(ioaddr
+ TxStatus
),
868 inw(ioaddr
+ EL3_STATUS
));
869 /* Slight code bloat to be user friendly. */
870 if ((inb(ioaddr
+ TxStatus
) & 0x88) == 0x88)
871 printk("%s: Transmitter encountered 16 collisions -- network"
872 " network cable problem?\n", dev
->name
);
873 #ifndef final_version
874 printk(" Flags; bus-master %d, full %d; dirty %d current %d.\n",
875 vp
->full_bus_master_tx
, vp
->tx_full
, vp
->dirty_tx
, vp
->cur_tx
);
876 printk(" Down list %8.8x vs. %p.\n", inl(ioaddr
+ DownListPtr
),
878 for (i
= 0; i
< TX_RING_SIZE
; i
++) {
879 printk(" %d: %p length %8.8x status %8.8x\n", i
,
881 vp
->tx_ring
[i
].length
,
882 vp
->tx_ring
[i
].status
);
885 /* Issue TX_RESET and TX_START commands. */
886 outw(TxReset
, ioaddr
+ EL3_CMD
);
887 for (i
= 20; i
>= 0 ; i
--)
888 if ( ! (inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
))
890 outw(TxEnable
, ioaddr
+ EL3_CMD
);
891 dev
->trans_start
= jiffies
;
893 vp
->stats
.tx_errors
++;
894 vp
->stats
.tx_dropped
++;
895 return 0; /* Yes, silently *drop* the packet! */
898 /* Block a timer-based transmit from overlapping. This could better be
899 done with atomic_swap(1, dev->tbusy), but set_bit() works as well.
900 If this ever occurs the queue layer is doing something evil! */
901 if (test_and_set_bit(0, (void*)&dev
->tbusy
) != 0) {
902 printk("%s: Transmitter access conflict.\n", dev
->name
);
906 if (vp
->full_bus_master_tx
) { /* BOOMERANG bus-master */
907 /* Calculate the next Tx descriptor entry. */
908 int entry
= vp
->cur_tx
% TX_RING_SIZE
;
909 struct boom_tx_desc
*prev_entry
;
910 unsigned long flags
, i
;
912 if (vp
->tx_full
) /* No room to transmit with */
915 prev_entry
= &vp
->tx_ring
[(vp
->cur_tx
-1) % TX_RING_SIZE
];
918 if (vortex_debug
> 3)
919 printk("%s: Trying to send a packet, Tx index %d.\n",
920 dev
->name
, vp
->cur_tx
);
921 /* vp->tx_full = 1; */
922 vp
->tx_skbuff
[entry
] = skb
;
923 vp
->tx_ring
[entry
].next
= 0;
924 vp
->tx_ring
[entry
].addr
= virt_to_bus(skb
->data
);
925 vp
->tx_ring
[entry
].length
= skb
->len
| 0x80000000;
926 vp
->tx_ring
[entry
].status
= skb
->len
| 0x80000000;
930 outw(DownStall
, ioaddr
+ EL3_CMD
);
931 /* Wait for the stall to complete. */
932 for (i
= 20; i
>= 0 ; i
--)
933 if ( (inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
) == 0)
936 prev_entry
->next
= virt_to_bus(&vp
->tx_ring
[entry
]);
937 if (inl(ioaddr
+ DownListPtr
) == 0) {
938 outl(virt_to_bus(&vp
->tx_ring
[entry
]), ioaddr
+ DownListPtr
);
941 outw(DownUnstall
, ioaddr
+ EL3_CMD
);
942 restore_flags(flags
);
945 if (vp
->cur_tx
- vp
->dirty_tx
> TX_RING_SIZE
- 1)
947 else { /* Clear previous interrupt enable. */
949 prev_entry
->status
&= ~0x80000000;
952 dev
->trans_start
= jiffies
;
955 /* Put out the doubleword header... */
956 outl(skb
->len
, ioaddr
+ TX_FIFO
);
957 #ifdef VORTEX_BUS_MASTER
958 if (vp
->bus_master
) {
959 /* Set the bus-master controller to transfer the packet. */
960 outl((int)(skb
->data
), ioaddr
+ Wn7_MasterAddr
);
961 outw((skb
->len
+ 3) & ~3, ioaddr
+ Wn7_MasterLen
);
963 outw(StartDMADown
, ioaddr
+ EL3_CMD
);
964 /* dev->tbusy will be cleared at the DMADone interrupt. */
966 /* ... and the packet rounded to a doubleword. */
967 outsl(ioaddr
+ TX_FIFO
, skb
->data
, (skb
->len
+ 3) >> 2);
969 if (inw(ioaddr
+ TxFree
) > 1536) {
972 /* Interrupt us when the FIFO has room for max-sized packet. */
973 outw(SetTxThreshold
+ (1536>>2), ioaddr
+ EL3_CMD
);
976 /* ... and the packet rounded to a doubleword. */
977 outsl(ioaddr
+ TX_FIFO
, skb
->data
, (skb
->len
+ 3) >> 2);
979 if (inw(ioaddr
+ TxFree
) > 1536) {
982 /* Interrupt us when the FIFO has room for max-sized packet. */
983 outw(SetTxThreshold
+ (1536>>2), ioaddr
+ EL3_CMD
);
984 #endif /* bus master */
986 dev
->trans_start
= jiffies
;
988 /* Clear the Tx status stack. */
993 while (--i
> 0 && (tx_status
= inb(ioaddr
+ TxStatus
)) > 0) {
994 if (tx_status
& 0x3C) { /* A Tx-disabling error occurred. */
995 if (vortex_debug
> 2)
996 printk("%s: Tx error, status %2.2x.\n",
997 dev
->name
, tx_status
);
998 if (tx_status
& 0x04) vp
->stats
.tx_fifo_errors
++;
999 if (tx_status
& 0x38) vp
->stats
.tx_aborted_errors
++;
1000 if (tx_status
& 0x30) {
1002 outw(TxReset
, ioaddr
+ EL3_CMD
);
1003 for (j
= 20; j
>= 0 ; j
--)
1004 if ( ! (inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
))
1007 outw(TxEnable
, ioaddr
+ EL3_CMD
);
1009 outb(0x00, ioaddr
+ TxStatus
); /* Pop the status stack. */
1012 vp
->stats
.tx_bytes
+=skb
->len
;
1016 /* The interrupt handler does all of the Rx thread work and cleans up
1017 after the Tx thread. */
1018 static void vortex_interrupt
IRQ(int irq
, void *dev_id
, struct pt_regs
*regs
)
1020 /* Use the now-standard shared IRQ implementation. */
1021 struct net_device
*dev
= dev_id
;
1022 struct vortex_private
*lp
;
1025 int i
= max_interrupt_work
;
1027 if (test_and_set_bit(0, (void*)&dev
->interrupt
)) {
1028 printk("%s: Re-entering the interrupt handler.\n", dev
->name
);
1032 ioaddr
= dev
->base_addr
;
1033 latency
= inb(ioaddr
+ Timer
);
1034 lp
= (struct vortex_private
*)dev
->priv
;
1036 status
= inw(ioaddr
+ EL3_STATUS
);
1038 if (vortex_debug
> 4)
1039 printk("%s: interrupt, status %4.4x, timer %d.\n", dev
->name
,
1041 if ((status
& 0xE000) != 0xE000) {
1042 static int donedidthis
=0;
1043 /* Some interrupt controllers store a bogus interrupt from boot-time.
1044 Ignore a single early interrupt, but don't hang the machine for
1045 other interrupt problems. */
1046 if (donedidthis
++ > 100) {
1047 printk("%s: Bogus interrupt, bailing. Status %4.4x, start=%d.\n",
1048 dev
->name
, status
, dev
->start
);
1049 FREE_IRQ(dev
->irq
, dev
);
1054 if (vortex_debug
> 5)
1055 printk("%s: In interrupt loop, status %4.4x.\n",
1057 if (status
& RxComplete
)
1060 if (status
& TxAvailable
) {
1061 if (vortex_debug
> 5)
1062 printk(" TX room bit was handled.\n");
1063 /* There's room in the FIFO for a full-sized packet. */
1064 outw(AckIntr
| TxAvailable
, ioaddr
+ EL3_CMD
);
1068 if (status
& DownComplete
) {
1069 unsigned int dirty_tx
= lp
->dirty_tx
;
1071 while (lp
->cur_tx
- dirty_tx
> 0) {
1072 int entry
= dirty_tx
% TX_RING_SIZE
;
1073 if (inl(ioaddr
+ DownListPtr
) ==
1074 virt_to_bus(&lp
->tx_ring
[entry
]))
1075 break; /* It still hasn't been processed. */
1076 if (lp
->tx_skbuff
[entry
]) {
1077 dev_kfree_skb(lp
->tx_skbuff
[entry
]);
1078 lp
->tx_skbuff
[entry
] = 0;
1082 lp
->dirty_tx
= dirty_tx
;
1083 outw(AckIntr
| DownComplete
, ioaddr
+ EL3_CMD
);
1084 if (lp
->tx_full
&& (lp
->cur_tx
- dirty_tx
<= TX_RING_SIZE
- 1)) {
1090 #ifdef VORTEX_BUS_MASTER
1091 if (status
& DMADone
) {
1092 outw(0x1000, ioaddr
+ Wn7_MasterStatus
); /* Ack the event. */
1094 dev_kfree_skb (lp
->tx_skb
); /* Release the transfered buffer */
1098 if (status
& UpComplete
) {
1100 outw(AckIntr
| UpComplete
, ioaddr
+ EL3_CMD
);
1102 if (status
& (AdapterFailure
| RxEarly
| StatsFull
)) {
1103 /* Handle all uncommon interrupts at once. */
1104 if (status
& RxEarly
) { /* Rx early is unused. */
1106 outw(AckIntr
| RxEarly
, ioaddr
+ EL3_CMD
);
1108 if (status
& StatsFull
) { /* Empty statistics. */
1109 static int DoneDidThat
= 0;
1110 if (vortex_debug
> 4)
1111 printk("%s: Updating stats.\n", dev
->name
);
1112 update_stats(ioaddr
, dev
);
1113 /* DEBUG HACK: Disable statistics as an interrupt source. */
1114 /* This occurs when we have the wrong media type! */
1115 if (DoneDidThat
== 0 &&
1116 inw(ioaddr
+ EL3_STATUS
) & StatsFull
) {
1118 printk("%s: Updating stats failed, disabling stats as an"
1119 " interrupt source.\n", dev
->name
);
1120 for (win
= 0; win
< 8; win
++) {
1122 printk("\n Vortex window %d:", win
);
1123 for (reg
= 0; reg
< 16; reg
++)
1124 printk(" %2.2x", inb(ioaddr
+reg
));
1127 outw(SetIntrEnb
| TxAvailable
| RxComplete
| AdapterFailure
1128 | UpComplete
| DownComplete
| TxComplete
,
1133 if (status
& AdapterFailure
) {
1134 /* Adapter failure requires Rx reset and reinit. */
1135 outw(RxReset
, ioaddr
+ EL3_CMD
);
1136 /* Set the Rx filter to the current state. */
1138 outw(RxEnable
, ioaddr
+ EL3_CMD
); /* Re-enable the receiver. */
1139 outw(AckIntr
| AdapterFailure
, ioaddr
+ EL3_CMD
);
1144 printk("%s: Too much work in interrupt, status %4.4x. "
1145 "Disabling functions (%4.4x).\n",
1146 dev
->name
, status
, SetStatusEnb
| ((~status
) & 0x7FE));
1147 /* Disable all pending interrupts. */
1148 outw(SetStatusEnb
| ((~status
) & 0x7FE), ioaddr
+ EL3_CMD
);
1149 outw(AckIntr
| 0x7FF, ioaddr
+ EL3_CMD
);
1152 /* Acknowledge the IRQ. */
1153 outw(AckIntr
| IntReq
| IntLatch
, ioaddr
+ EL3_CMD
);
1155 } while ((status
= inw(ioaddr
+ EL3_STATUS
)) & (IntLatch
| RxComplete
));
1157 if (vortex_debug
> 4)
1158 printk("%s: exiting interrupt, status %4.4x.\n", dev
->name
, status
);
1165 vortex_rx(struct net_device
*dev
)
1167 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
;
1168 int ioaddr
= dev
->base_addr
;
1172 if (vortex_debug
> 5)
1173 printk(" In rx_packet(), status %4.4x, rx_status %4.4x.\n",
1174 inw(ioaddr
+EL3_STATUS
), inw(ioaddr
+RxStatus
));
1175 while ((rx_status
= inw(ioaddr
+ RxStatus
)) > 0) {
1176 if (rx_status
& 0x4000) { /* Error, update stats. */
1177 unsigned char rx_error
= inb(ioaddr
+ RxErrors
);
1178 if (vortex_debug
> 2)
1179 printk(" Rx error: status %2.2x.\n", rx_error
);
1180 vp
->stats
.rx_errors
++;
1181 if (rx_error
& 0x01) vp
->stats
.rx_over_errors
++;
1182 if (rx_error
& 0x02) vp
->stats
.rx_length_errors
++;
1183 if (rx_error
& 0x04) vp
->stats
.rx_frame_errors
++;
1184 if (rx_error
& 0x08) vp
->stats
.rx_crc_errors
++;
1185 if (rx_error
& 0x10) vp
->stats
.rx_length_errors
++;
1187 /* The packet length: up to 4.5K!. */
1188 short pkt_len
= rx_status
& 0x1fff;
1189 struct sk_buff
*skb
;
1191 skb
= DEV_ALLOC_SKB(pkt_len
+ 5);
1192 if (vortex_debug
> 4)
1193 printk("Receiving packet size %d status %4.4x.\n",
1194 pkt_len
, rx_status
);
1197 #if LINUX_VERSION_CODE >= 0x10300
1198 skb_reserve(skb
, 2); /* Align IP on 16 byte boundaries */
1199 /* 'skb_put()' points to the start of sk_buff data area. */
1200 insl(ioaddr
+ RX_FIFO
, skb_put(skb
, pkt_len
),
1201 (pkt_len
+ 3) >> 2);
1202 outw(RxDiscard
, ioaddr
+ EL3_CMD
); /* Pop top Rx packet. */
1203 skb
->protocol
= eth_type_trans(skb
, dev
);
1206 /* 'skb->data' points to the start of sk_buff data area. */
1207 insl(ioaddr
+ RX_FIFO
, skb
->data
, (pkt_len
+ 3) >> 2);
1208 outw(RxDiscard
, ioaddr
+ EL3_CMD
); /* Pop top Rx packet. */
1209 #endif /* KERNEL_1_3_0 */
1211 dev
->last_rx
= jiffies
;
1212 vp
->stats
.rx_packets
++;
1213 vp
->stats
.rx_bytes
+=skb
->len
;
1214 /* Wait a limited time to go to next packet. */
1215 for (i
= 200; i
>= 0; i
--)
1216 if ( ! (inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
))
1219 } else if (vortex_debug
)
1220 printk("%s: Couldn't allocate a sk_buff of size %d.\n",
1221 dev
->name
, pkt_len
);
1223 outw(RxDiscard
, ioaddr
+ EL3_CMD
);
1224 vp
->stats
.rx_dropped
++;
1225 /* Wait a limited time to skip this packet. */
1226 for (i
= 200; i
>= 0; i
--)
1227 if ( ! (inw(ioaddr
+ EL3_STATUS
) & CmdInProgress
))
1235 boomerang_rx(struct net_device
*dev
)
1237 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
;
1238 int entry
= vp
->cur_rx
% RX_RING_SIZE
;
1239 int ioaddr
= dev
->base_addr
;
1242 if (vortex_debug
> 5)
1243 printk(" In boomerang_rx(), status %4.4x, rx_status %4.4x.\n",
1244 inw(ioaddr
+EL3_STATUS
), inw(ioaddr
+RxStatus
));
1245 while ((rx_status
= vp
->rx_ring
[entry
].status
) & RxDComplete
) {
1246 if (rx_status
& RxDError
) { /* Error, update stats. */
1247 unsigned char rx_error
= rx_status
>> 16;
1248 if (vortex_debug
> 2)
1249 printk(" Rx error: status %2.2x.\n", rx_error
);
1250 vp
->stats
.rx_errors
++;
1251 if (rx_error
& 0x01) vp
->stats
.rx_over_errors
++;
1252 if (rx_error
& 0x02) vp
->stats
.rx_length_errors
++;
1253 if (rx_error
& 0x04) vp
->stats
.rx_frame_errors
++;
1254 if (rx_error
& 0x08) vp
->stats
.rx_crc_errors
++;
1255 if (rx_error
& 0x10) vp
->stats
.rx_length_errors
++;
1257 /* The packet length: up to 4.5K!. */
1258 short pkt_len
= rx_status
& 0x1fff;
1259 struct sk_buff
*skb
;
1261 vp
->stats
.rx_bytes
+=pkt_len
;
1262 if (vortex_debug
> 4)
1263 printk("Receiving packet size %d status %4.4x.\n",
1264 pkt_len
, rx_status
);
1266 /* Check if the packet is long enough to just accept without
1267 copying to a properly sized skbuff. */
1268 if (pkt_len
< rx_copybreak
1269 && (skb
= DEV_ALLOC_SKB(pkt_len
+ 2)) != 0) {
1271 skb_reserve(skb
, 2); /* Align IP on 16 byte boundaries */
1272 /* 'skb_put()' points to the start of sk_buff data area. */
1273 memcpy(skb_put(skb
, pkt_len
),
1274 bus_to_virt(vp
->rx_ring
[entry
].addr
),
1279 /* Pass up the skbuff already on the Rx ring. */
1280 skb
= vp
->rx_skbuff
[entry
];
1281 vp
->rx_skbuff
[entry
] = NULL
;
1282 temp
= skb_put(skb
, pkt_len
);
1283 /* Remove this checking code for final release. */
1284 if (bus_to_virt(vp
->rx_ring
[entry
].addr
) != temp
)
1285 printk("%s: Warning -- the skbuff addresses do not match"
1286 " in boomerang_rx: %p vs. %p / %p.\n", dev
->name
,
1287 bus_to_virt(vp
->rx_ring
[entry
].addr
),
1291 #if LINUX_VERSION_CODE > 0x10300
1292 skb
->protocol
= eth_type_trans(skb
, dev
);
1297 dev
->last_rx
= jiffies
;
1298 vp
->stats
.rx_packets
++;
1300 entry
= (++vp
->cur_rx
) % RX_RING_SIZE
;
1302 /* Refill the Rx ring buffers. */
1303 for (; vp
->dirty_rx
< vp
->cur_rx
; vp
->dirty_rx
++) {
1304 struct sk_buff
*skb
;
1305 entry
= vp
->dirty_rx
% RX_RING_SIZE
;
1306 if (vp
->rx_skbuff
[entry
] == NULL
) {
1307 skb
= dev_alloc_skb(PKT_BUF_SZ
);
1309 break; /* Bad news! */
1310 skb
->dev
= dev
; /* Mark as being used by this device. */
1311 #if LINUX_VERSION_CODE > 0x10300
1312 skb_reserve(skb
, 2); /* Align IP on 16 byte boundaries */
1313 vp
->rx_ring
[entry
].addr
= virt_to_bus(skb
->tail
);
1315 vp
->rx_ring
[entry
].addr
= virt_to_bus(skb
->data
);
1317 vp
->rx_skbuff
[entry
] = skb
;
1319 vp
->rx_ring
[entry
].status
= 0; /* Clear complete bit. */
1325 vortex_close(struct net_device
*dev
)
1327 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
;
1328 int ioaddr
= dev
->base_addr
;
1334 if (vortex_debug
> 1) {
1335 printk("%s: vortex_close() status %4.4x, Tx status %2.2x.\n",
1336 dev
->name
, inw(ioaddr
+ EL3_STATUS
), inb(ioaddr
+ TxStatus
));
1337 printk("%s: vortex close stats: rx_nocopy %d rx_copy %d"
1339 dev
->name
, rx_nocopy
, rx_copy
, queued_packet
);
1342 del_timer(&vp
->timer
);
1344 /* Turn off statistics ASAP. We update lp->stats below. */
1345 outw(StatsDisable
, ioaddr
+ EL3_CMD
);
1347 /* Disable the receiver and transmitter. */
1348 outw(RxDisable
, ioaddr
+ EL3_CMD
);
1349 outw(TxDisable
, ioaddr
+ EL3_CMD
);
1351 if (dev
->if_port
== XCVR_10base2
)
1352 /* Turn off thinnet power. Green! */
1353 outw(StopCoax
, ioaddr
+ EL3_CMD
);
1356 free_irq(dev
->irq
, dev
);
1359 irq2dev_map
[dev
->irq
] = 0;
1362 outw(SetIntrEnb
| 0x0000, ioaddr
+ EL3_CMD
);
1364 update_stats(ioaddr
, dev
);
1365 if (vp
->full_bus_master_rx
) { /* Free Boomerang bus master Rx buffers. */
1366 outl(0, ioaddr
+ UpListPtr
);
1367 for (i
= 0; i
< RX_RING_SIZE
; i
++)
1368 if (vp
->rx_skbuff
[i
]) {
1369 #if LINUX_VERSION_CODE < 0x20100
1370 vp
->rx_skbuff
[i
]->free
= 1;
1372 dev_kfree_skb (vp
->rx_skbuff
[i
]);
1373 vp
->rx_skbuff
[i
] = 0;
1376 if (vp
->full_bus_master_tx
) { /* Free Boomerang bus master Tx buffers. */
1377 outl(0, ioaddr
+ DownListPtr
);
1378 for (i
= 0; i
< TX_RING_SIZE
; i
++)
1379 if (vp
->tx_skbuff
[i
]) {
1380 dev_kfree_skb(vp
->tx_skbuff
[i
]);
1381 vp
->tx_skbuff
[i
] = 0;
1390 static struct enet_statistics
*
1391 vortex_get_stats(struct net_device
*dev
)
1393 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
;
1394 unsigned long flags
;
1399 update_stats(dev
->base_addr
, dev
);
1400 restore_flags(flags
);
1405 /* Update statistics.
1406 Unlike with the EL3 we need not worry about interrupts changing
1407 the window setting from underneath us, but we must still guard
1408 against a race condition with a StatsUpdate interrupt updating the
1409 table. This is done by checking that the ASM (!) code generated uses
1410 atomic updates with '+='.
1412 static void update_stats(int ioaddr
, struct net_device
*dev
)
1414 struct vortex_private
*vp
= (struct vortex_private
*)dev
->priv
;
1416 /* Unlike the 3c5x9 we need not turn off stats updates while reading. */
1417 /* Switch to the stats window, and read everything. */
1419 vp
->stats
.tx_carrier_errors
+= inb(ioaddr
+ 0);
1420 vp
->stats
.tx_heartbeat_errors
+= inb(ioaddr
+ 1);
1421 /* Multiple collisions. */ inb(ioaddr
+ 2);
1422 vp
->stats
.collisions
+= inb(ioaddr
+ 3);
1423 vp
->stats
.tx_window_errors
+= inb(ioaddr
+ 4);
1424 vp
->stats
.rx_fifo_errors
+= inb(ioaddr
+ 5);
1425 vp
->stats
.tx_packets
+= inb(ioaddr
+ 6);
1426 vp
->stats
.tx_packets
+= (inb(ioaddr
+ 9)&0x30) << 4;
1427 /* Rx packets */ inb(ioaddr
+ 7); /* Must read to clear */
1428 /* Tx deferrals */ inb(ioaddr
+ 8);
1429 /* Don't bother with register 9, an extension of registers 6&7.
1430 If we do use the 6&7 values the atomic update assumption above
1432 inw(ioaddr
+ 10); /* Total Rx and Tx octets. */
1434 /* New: On the Vortex we must also clear the BadSSD counter. */
1438 /* We change back to window 7 (not 1) with the Vortex. */
1443 /* This new version of set_rx_mode() supports v1.4 kernels.
1444 The Vortex chip has no documented multicast filter, so the only
1445 multicast setting is to receive all multicast frames. At least
1446 the chip has a very clean way to set the mode, unlike many others. */
1448 set_rx_mode(struct net_device
*dev
)
1450 int ioaddr
= dev
->base_addr
;
1453 if (dev
->flags
& IFF_PROMISC
) {
1454 if (vortex_debug
> 3)
1455 printk("%s: Setting promiscuous mode.\n", dev
->name
);
1456 new_mode
= SetRxFilter
|RxStation
|RxMulticast
|RxBroadcast
|RxProm
;
1457 } else if ((dev
->mc_list
) || (dev
->flags
& IFF_ALLMULTI
)) {
1458 new_mode
= SetRxFilter
|RxStation
|RxMulticast
|RxBroadcast
;
1460 new_mode
= SetRxFilter
| RxStation
| RxBroadcast
;
1462 outw(new_mode
, ioaddr
+ EL3_CMD
);
1467 cleanup_module(void)
1469 struct net_device
*next_dev
;
1471 /* No need to check MOD_IN_USE, as sys_delete_module() checks. */
1472 while (root_vortex_dev
) {
1473 next_dev
= ((struct vortex_private
*)root_vortex_dev
->priv
)->next_module
;
1474 if (root_vortex_dev
->dma
)
1475 free_dma(root_vortex_dev
->dma
);
1476 unregister_netdev(root_vortex_dev
);
1477 outw(TotalReset
, root_vortex_dev
->base_addr
+ EL3_CMD
);
1478 release_region(root_vortex_dev
->base_addr
, CORKSCREW_TOTAL_SIZE
);
1479 kfree(root_vortex_dev
);
1480 root_vortex_dev
= next_dev
;
1487 * compile-command: "gcc -DMODULE -D__KERNEL__ -Wall -Wstrict-prototypes -O6 -c 3c515.c"