1 // SPDX-License-Identifier: GPL-2.0-only
3 * linux/drivers/acorn/net/ether3.c
5 * Copyright (C) 1995-2000 Russell King
7 * SEEQ nq8005 ethernet driver for Acorn/ANT Ether3 card
10 * By Russell King, with some suggestions from borris@ant.co.uk
13 * 1.04 RMK 29/02/1996 Won't pass packets that are from our ethernet
14 * address up to the higher levels - they're
15 * silently ignored. I/F can now be put into
16 * multicast mode. Receiver routine optimised.
17 * 1.05 RMK 30/02/1996 Now claims interrupt at open when part of
18 * the kernel rather than when a module.
19 * 1.06 RMK 02/03/1996 Various code cleanups
20 * 1.07 RMK 13/10/1996 Optimised interrupt routine and transmit
22 * 1.08 RMK 14/10/1996 Fixed problem with too many packets,
23 * prevented the kernel message about dropped
24 * packets appearing too many times a second.
25 * Now does not disable all IRQs, only the IRQ
27 * 1.09 RMK 10/11/1996 Only enables TX irq when buffer space is low,
28 * but we still service the TX queue if we get a
30 * 1.10 RMK 15/07/1997 Fixed autoprobing of NQ8004.
31 * 1.11 RMK 16/11/1997 Fixed autoprobing of NQ8005A.
32 * 1.12 RMK 31/12/1997 Removed reference to dev_tint for Linux 2.1.
33 * RMK 27/06/1998 Changed asm/delay.h to linux/delay.h.
34 * 1.13 RMK 29/06/1998 Fixed problem with transmission of packets.
35 * Chip seems to have a bug in, whereby if the
36 * packet starts two bytes from the end of the
37 * buffer, it corrupts the receiver chain, and
38 * never updates the transmit status correctly.
39 * 1.14 RMK 07/01/1998 Added initial code for ETHERB addressing.
40 * 1.15 RMK 30/04/1999 More fixes to the transmit routine for buggy
42 * 1.16 RMK 10/02/2000 Updated for 2.3.43
43 * 1.17 RMK 13/05/2000 Updated for 2.3.99-pre8
46 #include <linux/module.h>
47 #include <linux/kernel.h>
48 #include <linux/types.h>
49 #include <linux/fcntl.h>
50 #include <linux/interrupt.h>
51 #include <linux/ioport.h>
53 #include <linux/slab.h>
54 #include <linux/string.h>
55 #include <linux/errno.h>
56 #include <linux/netdevice.h>
57 #include <linux/etherdevice.h>
58 #include <linux/skbuff.h>
59 #include <linux/device.h>
60 #include <linux/init.h>
61 #include <linux/delay.h>
62 #include <linux/bitops.h>
64 #include <asm/ecard.h>
67 static char version
[] = "ether3 ethernet driver (c) 1995-2000 R.M.King v1.17\n";
71 static unsigned int net_debug
= NET_DEBUG
;
73 static void ether3_setmulticastlist(struct net_device
*dev
);
74 static int ether3_rx(struct net_device
*dev
, unsigned int maxcnt
);
75 static void ether3_tx(struct net_device
*dev
);
76 static int ether3_open (struct net_device
*dev
);
77 static netdev_tx_t
ether3_sendpacket(struct sk_buff
*skb
,
78 struct net_device
*dev
);
79 static irqreturn_t
ether3_interrupt (int irq
, void *dev_id
);
80 static int ether3_close (struct net_device
*dev
);
81 static void ether3_setmulticastlist (struct net_device
*dev
);
82 static void ether3_timeout(struct net_device
*dev
, unsigned int txqueue
);
88 /* --------------------------------------------------------------------------- */
96 * ether3 read/write. Slow things down a bit...
97 * The SEEQ8005 doesn't like us writing to its registers
100 static inline void ether3_outb(int v
, void __iomem
*r
)
106 static inline void ether3_outw(int v
, void __iomem
*r
)
111 #define ether3_inb(r) ({ unsigned int __v = readb((r)); udelay(1); __v; })
112 #define ether3_inw(r) ({ unsigned int __v = readw((r)); udelay(1); __v; })
115 ether3_setbuffer(struct net_device
*dev
, buffer_rw_t read
, int start
)
119 ether3_outw(priv(dev
)->regs
.config1
| CFG1_LOCBUFMEM
, REG_CONFIG1
);
120 ether3_outw(priv(dev
)->regs
.command
| CMD_FIFOWRITE
, REG_COMMAND
);
122 while ((ether3_inw(REG_STATUS
) & STAT_FIFOEMPTY
) == 0) {
124 printk("%s: setbuffer broken\n", dev
->name
);
125 priv(dev
)->broken
= 1;
131 if (read
== buffer_read
) {
132 ether3_outw(start
, REG_DMAADDR
);
133 ether3_outw(priv(dev
)->regs
.command
| CMD_FIFOREAD
, REG_COMMAND
);
135 ether3_outw(priv(dev
)->regs
.command
| CMD_FIFOWRITE
, REG_COMMAND
);
136 ether3_outw(start
, REG_DMAADDR
);
142 * write data to the buffer memory
144 #define ether3_writebuffer(dev,data,length) \
145 writesw(REG_BUFWIN, (data), (length) >> 1)
147 #define ether3_writeword(dev,data) \
148 writew((data), REG_BUFWIN)
150 #define ether3_writelong(dev,data) { \
151 void __iomem *reg_bufwin = REG_BUFWIN; \
152 writew((data), reg_bufwin); \
153 writew((data) >> 16, reg_bufwin); \
157 * read data from the buffer memory
159 #define ether3_readbuffer(dev,data,length) \
160 readsw(REG_BUFWIN, (data), (length) >> 1)
162 #define ether3_readword(dev) \
165 #define ether3_readlong(dev) \
166 readw(REG_BUFWIN) | (readw(REG_BUFWIN) << 16)
171 static void ether3_ledoff(struct timer_list
*t
)
173 struct dev_priv
*private = from_timer(private, t
, timer
);
174 struct net_device
*dev
= private->dev
;
176 ether3_outw(priv(dev
)->regs
.config2
|= CFG2_CTRLO
, REG_CONFIG2
);
182 static inline void ether3_ledon(struct net_device
*dev
)
184 del_timer(&priv(dev
)->timer
);
185 priv(dev
)->timer
.expires
= jiffies
+ HZ
/ 50; /* leave on for 1/50th second */
186 add_timer(&priv(dev
)->timer
);
187 if (priv(dev
)->regs
.config2
& CFG2_CTRLO
)
188 ether3_outw(priv(dev
)->regs
.config2
&= ~CFG2_CTRLO
, REG_CONFIG2
);
192 * Read the ethernet address string from the on board rom.
193 * This is an ascii string!!!
196 ether3_addr(char *addr
, struct expansion_card
*ec
)
198 struct in_chunk_dir cd
;
201 if (ecard_readchunk(&cd
, ec
, 0xf5, 0) && (s
= strchr(cd
.d
.string
, '('))) {
203 for (i
= 0; i
<6; i
++) {
204 addr
[i
] = simple_strtoul(s
+ 1, &s
, 0x10);
205 if (*s
!= (i
==5?')' : ':' ))
211 /* I wonder if we should even let the user continue in this case
212 * - no, it would be better to disable the device
214 printk(KERN_ERR
"ether3: Couldn't read a valid MAC address from card.\n");
218 /* --------------------------------------------------------------------------- */
221 ether3_ramtest(struct net_device
*dev
, unsigned char byte
)
223 unsigned char *buffer
= kmalloc(RX_END
, GFP_KERNEL
);
231 memset(buffer
, byte
, RX_END
);
232 ether3_setbuffer(dev
, buffer_write
, 0);
233 ether3_writebuffer(dev
, buffer
, TX_END
);
234 ether3_setbuffer(dev
, buffer_write
, RX_START
);
235 ether3_writebuffer(dev
, buffer
+ RX_START
, RX_LEN
);
236 memset(buffer
, byte
^ 0xff, RX_END
);
237 ether3_setbuffer(dev
, buffer_read
, 0);
238 ether3_readbuffer(dev
, buffer
, TX_END
);
239 ether3_setbuffer(dev
, buffer_read
, RX_START
);
240 ether3_readbuffer(dev
, buffer
+ RX_START
, RX_LEN
);
242 for (i
= 0; i
< RX_END
; i
++) {
243 if (buffer
[i
] != byte
) {
244 if (max_errors
> 0 && bad
!= buffer
[i
]) {
245 printk("%s: RAM failed with (%02X instead of %02X) at 0x%04X",
246 dev
->name
, buffer
[i
], byte
, i
);
254 printk(" - 0x%04X\n", i
- 1);
261 printk(" - 0xffff\n");
267 /* ------------------------------------------------------------------------------- */
269 static int ether3_init_2(struct net_device
*dev
)
273 priv(dev
)->regs
.config1
= CFG1_RECVCOMPSTAT0
|CFG1_DMABURST8
;
274 priv(dev
)->regs
.config2
= CFG2_CTRLO
|CFG2_RECVCRC
|CFG2_ERRENCRC
;
275 priv(dev
)->regs
.command
= 0;
278 * Set up our hardware address
280 ether3_outw(priv(dev
)->regs
.config1
| CFG1_BUFSELSTAT0
, REG_CONFIG1
);
281 for (i
= 0; i
< 6; i
++)
282 ether3_outb(dev
->dev_addr
[i
], REG_BUFWIN
);
284 if (dev
->flags
& IFF_PROMISC
)
285 priv(dev
)->regs
.config1
|= CFG1_RECVPROMISC
;
286 else if (dev
->flags
& IFF_MULTICAST
)
287 priv(dev
)->regs
.config1
|= CFG1_RECVSPECBRMULTI
;
289 priv(dev
)->regs
.config1
|= CFG1_RECVSPECBROAD
;
292 * There is a problem with the NQ8005 in that it occasionally loses the
293 * last two bytes. To get round this problem, we receive the CRC as
294 * well. That way, if we do lose the last two, then it doesn't matter.
296 ether3_outw(priv(dev
)->regs
.config1
| CFG1_TRANSEND
, REG_CONFIG1
);
297 ether3_outw((TX_END
>>8) - 1, REG_BUFWIN
);
298 ether3_outw(priv(dev
)->rx_head
, REG_RECVPTR
);
299 ether3_outw(0, REG_TRANSMITPTR
);
300 ether3_outw(priv(dev
)->rx_head
>> 8, REG_RECVEND
);
301 ether3_outw(priv(dev
)->regs
.config2
, REG_CONFIG2
);
302 ether3_outw(priv(dev
)->regs
.config1
| CFG1_LOCBUFMEM
, REG_CONFIG1
);
303 ether3_outw(priv(dev
)->regs
.command
, REG_COMMAND
);
305 i
= ether3_ramtest(dev
, 0x5A);
308 i
= ether3_ramtest(dev
, 0x1E);
312 ether3_setbuffer(dev
, buffer_write
, 0);
313 ether3_writelong(dev
, 0);
318 ether3_init_for_open(struct net_device
*dev
)
323 ether3_outw(CFG2_RESET
, REG_CONFIG2
);
326 priv(dev
)->regs
.command
= 0;
327 ether3_outw(CMD_RXOFF
|CMD_TXOFF
, REG_COMMAND
);
328 while (ether3_inw(REG_STATUS
) & (STAT_RXON
|STAT_TXON
))
331 ether3_outw(priv(dev
)->regs
.config1
| CFG1_BUFSELSTAT0
, REG_CONFIG1
);
332 for (i
= 0; i
< 6; i
++)
333 ether3_outb(dev
->dev_addr
[i
], REG_BUFWIN
);
335 priv(dev
)->tx_head
= 0;
336 priv(dev
)->tx_tail
= 0;
337 priv(dev
)->regs
.config2
|= CFG2_CTRLO
;
338 priv(dev
)->rx_head
= RX_START
;
340 ether3_outw(priv(dev
)->regs
.config1
| CFG1_TRANSEND
, REG_CONFIG1
);
341 ether3_outw((TX_END
>>8) - 1, REG_BUFWIN
);
342 ether3_outw(priv(dev
)->rx_head
, REG_RECVPTR
);
343 ether3_outw(priv(dev
)->rx_head
>> 8, REG_RECVEND
);
344 ether3_outw(0, REG_TRANSMITPTR
);
345 ether3_outw(priv(dev
)->regs
.config2
, REG_CONFIG2
);
346 ether3_outw(priv(dev
)->regs
.config1
| CFG1_LOCBUFMEM
, REG_CONFIG1
);
348 ether3_setbuffer(dev
, buffer_write
, 0);
349 ether3_writelong(dev
, 0);
351 priv(dev
)->regs
.command
= CMD_ENINTRX
| CMD_ENINTTX
;
352 ether3_outw(priv(dev
)->regs
.command
| CMD_RXON
, REG_COMMAND
);
356 ether3_probe_bus_8(struct net_device
*dev
, int val
)
358 int write_low
, write_high
, read_low
, read_high
;
360 write_low
= val
& 255;
361 write_high
= val
>> 8;
363 printk(KERN_DEBUG
"ether3_probe: write8 [%02X:%02X]", write_high
, write_low
);
365 ether3_outb(write_low
, REG_RECVPTR
);
366 ether3_outb(write_high
, REG_RECVPTR
+ 4);
368 read_low
= ether3_inb(REG_RECVPTR
);
369 read_high
= ether3_inb(REG_RECVPTR
+ 4);
371 printk(", read8 [%02X:%02X]\n", read_high
, read_low
);
373 return read_low
== write_low
&& read_high
== write_high
;
377 ether3_probe_bus_16(struct net_device
*dev
, int val
)
381 ether3_outw(val
, REG_RECVPTR
);
382 read_val
= ether3_inw(REG_RECVPTR
);
384 printk(KERN_DEBUG
"ether3_probe: write16 [%04X], read16 [%04X]\n", val
, read_val
);
386 return read_val
== val
;
390 * Open/initialize the board. This is called (in the current kernel)
391 * sometime after booting when the 'ifconfig' program is run.
393 * This routine should set everything up anew at each open, even
394 * registers that "should" only need to be set once at boot, so that
395 * there is non-reboot way to recover if something goes wrong.
398 ether3_open(struct net_device
*dev
)
400 if (request_irq(dev
->irq
, ether3_interrupt
, 0, "ether3", dev
))
403 ether3_init_for_open(dev
);
405 netif_start_queue(dev
);
411 * The inverse routine to ether3_open().
414 ether3_close(struct net_device
*dev
)
416 netif_stop_queue(dev
);
418 disable_irq(dev
->irq
);
420 ether3_outw(CMD_RXOFF
|CMD_TXOFF
, REG_COMMAND
);
421 priv(dev
)->regs
.command
= 0;
422 while (ether3_inw(REG_STATUS
) & (STAT_RXON
|STAT_TXON
))
424 ether3_outb(0x80, REG_CONFIG2
+ 4);
425 ether3_outw(0, REG_COMMAND
);
427 free_irq(dev
->irq
, dev
);
433 * Set or clear promiscuous/multicast mode filter for this adaptor.
435 * We don't attempt any packet filtering. The card may have a SEEQ 8004
436 * in which does not have the other ethernet address registers present...
438 static void ether3_setmulticastlist(struct net_device
*dev
)
440 priv(dev
)->regs
.config1
&= ~CFG1_RECVPROMISC
;
442 if (dev
->flags
& IFF_PROMISC
) {
443 /* promiscuous mode */
444 priv(dev
)->regs
.config1
|= CFG1_RECVPROMISC
;
445 } else if (dev
->flags
& IFF_ALLMULTI
|| !netdev_mc_empty(dev
)) {
446 priv(dev
)->regs
.config1
|= CFG1_RECVSPECBRMULTI
;
448 priv(dev
)->regs
.config1
|= CFG1_RECVSPECBROAD
;
450 ether3_outw(priv(dev
)->regs
.config1
| CFG1_LOCBUFMEM
, REG_CONFIG1
);
453 static void ether3_timeout(struct net_device
*dev
, unsigned int txqueue
)
457 del_timer(&priv(dev
)->timer
);
459 local_irq_save(flags
);
460 printk(KERN_ERR
"%s: transmit timed out, network cable problem?\n", dev
->name
);
461 printk(KERN_ERR
"%s: state: { status=%04X cfg1=%04X cfg2=%04X }\n", dev
->name
,
462 ether3_inw(REG_STATUS
), ether3_inw(REG_CONFIG1
), ether3_inw(REG_CONFIG2
));
463 printk(KERN_ERR
"%s: { rpr=%04X rea=%04X tpr=%04X }\n", dev
->name
,
464 ether3_inw(REG_RECVPTR
), ether3_inw(REG_RECVEND
), ether3_inw(REG_TRANSMITPTR
));
465 printk(KERN_ERR
"%s: tx head=%X tx tail=%X\n", dev
->name
,
466 priv(dev
)->tx_head
, priv(dev
)->tx_tail
);
467 ether3_setbuffer(dev
, buffer_read
, priv(dev
)->tx_tail
);
468 printk(KERN_ERR
"%s: packet status = %08X\n", dev
->name
, ether3_readlong(dev
));
469 local_irq_restore(flags
);
471 priv(dev
)->regs
.config2
|= CFG2_CTRLO
;
472 dev
->stats
.tx_errors
+= 1;
473 ether3_outw(priv(dev
)->regs
.config2
, REG_CONFIG2
);
474 priv(dev
)->tx_head
= priv(dev
)->tx_tail
= 0;
476 netif_wake_queue(dev
);
483 ether3_sendpacket(struct sk_buff
*skb
, struct net_device
*dev
)
486 unsigned int length
= ETH_ZLEN
< skb
->len
? skb
->len
: ETH_ZLEN
;
487 unsigned int ptr
, next_ptr
;
489 if (priv(dev
)->broken
) {
491 dev
->stats
.tx_dropped
++;
492 netif_start_queue(dev
);
496 length
= (length
+ 1) & ~1;
497 if (length
!= skb
->len
) {
498 if (skb_padto(skb
, length
))
502 next_ptr
= (priv(dev
)->tx_head
+ 1) & 15;
504 local_irq_save(flags
);
506 if (priv(dev
)->tx_tail
== next_ptr
) {
507 local_irq_restore(flags
);
508 return NETDEV_TX_BUSY
; /* unable to queue */
511 ptr
= 0x600 * priv(dev
)->tx_head
;
512 priv(dev
)->tx_head
= next_ptr
;
515 #define TXHDR_FLAGS (TXHDR_TRANSMIT|TXHDR_CHAINCONTINUE|TXHDR_DATAFOLLOWS|TXHDR_ENSUCCESS)
517 ether3_setbuffer(dev
, buffer_write
, next_ptr
);
518 ether3_writelong(dev
, 0);
519 ether3_setbuffer(dev
, buffer_write
, ptr
);
520 ether3_writelong(dev
, 0);
521 ether3_writebuffer(dev
, skb
->data
, length
);
522 ether3_writeword(dev
, htons(next_ptr
));
523 ether3_writeword(dev
, TXHDR_CHAINCONTINUE
>> 16);
524 ether3_setbuffer(dev
, buffer_write
, ptr
);
525 ether3_writeword(dev
, htons((ptr
+ length
+ 4)));
526 ether3_writeword(dev
, TXHDR_FLAGS
>> 16);
529 if (!(ether3_inw(REG_STATUS
) & STAT_TXON
)) {
530 ether3_outw(ptr
, REG_TRANSMITPTR
);
531 ether3_outw(priv(dev
)->regs
.command
| CMD_TXON
, REG_COMMAND
);
534 next_ptr
= (priv(dev
)->tx_head
+ 1) & 15;
535 local_irq_restore(flags
);
539 if (priv(dev
)->tx_tail
== next_ptr
)
540 netif_stop_queue(dev
);
547 ether3_interrupt(int irq
, void *dev_id
)
549 struct net_device
*dev
= (struct net_device
*)dev_id
;
550 unsigned int status
, handled
= IRQ_NONE
;
553 if(net_debug
& DEBUG_INT
)
554 printk("eth3irq: %d ", irq
);
557 status
= ether3_inw(REG_STATUS
);
559 if (status
& STAT_INTRX
) {
560 ether3_outw(CMD_ACKINTRX
| priv(dev
)->regs
.command
, REG_COMMAND
);
562 handled
= IRQ_HANDLED
;
565 if (status
& STAT_INTTX
) {
566 ether3_outw(CMD_ACKINTTX
| priv(dev
)->regs
.command
, REG_COMMAND
);
568 handled
= IRQ_HANDLED
;
572 if(net_debug
& DEBUG_INT
)
579 * If we have a good packet(s), get it/them out of the buffers.
581 static int ether3_rx(struct net_device
*dev
, unsigned int maxcnt
)
583 unsigned int next_ptr
= priv(dev
)->rx_head
, received
= 0;
588 unsigned int this_ptr
, status
;
589 unsigned char addrs
[16];
592 * read the first 16 bytes from the buffer.
593 * This contains the status bytes etc and ethernet addresses,
594 * and we also check the source ethernet address to see if
595 * it originated from us.
598 unsigned int temp_ptr
;
599 ether3_setbuffer(dev
, buffer_read
, next_ptr
);
600 temp_ptr
= ether3_readword(dev
);
601 status
= ether3_readword(dev
);
602 if ((status
& (RXSTAT_DONE
| RXHDR_CHAINCONTINUE
| RXHDR_RECEIVE
)) !=
603 (RXSTAT_DONE
| RXHDR_CHAINCONTINUE
) || !temp_ptr
)
606 this_ptr
= next_ptr
+ 4;
607 next_ptr
= ntohs(temp_ptr
);
609 ether3_setbuffer(dev
, buffer_read
, this_ptr
);
610 ether3_readbuffer(dev
, addrs
+2, 12);
612 if (next_ptr
< RX_START
|| next_ptr
>= RX_END
) {
614 printk("%s: bad next pointer @%04X: ", dev
->name
, priv(dev
)->rx_head
);
615 printk("%02X %02X %02X %02X ", next_ptr
>> 8, next_ptr
& 255, status
& 255, status
>> 8);
616 for (i
= 2; i
< 14; i
++)
617 printk("%02X ", addrs
[i
]);
619 next_ptr
= priv(dev
)->rx_head
;
623 * ignore our own packets...
625 if (!(*(unsigned long *)&dev
->dev_addr
[0] ^ *(unsigned long *)&addrs
[2+6]) &&
626 !(*(unsigned short *)&dev
->dev_addr
[4] ^ *(unsigned short *)&addrs
[2+10])) {
627 maxcnt
++; /* compensate for loopedback packet */
628 ether3_outw(next_ptr
>> 8, REG_RECVEND
);
630 if (!(status
& (RXSTAT_OVERSIZE
|RXSTAT_CRCERROR
|RXSTAT_DRIBBLEERROR
|RXSTAT_SHORTPACKET
))) {
631 unsigned int length
= next_ptr
- this_ptr
;
634 if (next_ptr
<= this_ptr
)
635 length
+= RX_END
- RX_START
;
637 skb
= netdev_alloc_skb(dev
, length
+ 2);
642 buf
= skb_put(skb
, length
);
643 ether3_readbuffer(dev
, buf
+ 12, length
- 12);
644 ether3_outw(next_ptr
>> 8, REG_RECVEND
);
645 *(unsigned short *)(buf
+ 0) = *(unsigned short *)(addrs
+ 2);
646 *(unsigned long *)(buf
+ 2) = *(unsigned long *)(addrs
+ 4);
647 *(unsigned long *)(buf
+ 6) = *(unsigned long *)(addrs
+ 8);
648 *(unsigned short *)(buf
+ 10) = *(unsigned short *)(addrs
+ 12);
649 skb
->protocol
= eth_type_trans(skb
, dev
);
653 ether3_outw(next_ptr
>> 8, REG_RECVEND
);
654 dev
->stats
.rx_dropped
++;
658 struct net_device_stats
*stats
= &dev
->stats
;
659 ether3_outw(next_ptr
>> 8, REG_RECVEND
);
660 if (status
& RXSTAT_OVERSIZE
) stats
->rx_over_errors
++;
661 if (status
& RXSTAT_CRCERROR
) stats
->rx_crc_errors
++;
662 if (status
& RXSTAT_DRIBBLEERROR
) stats
->rx_fifo_errors
++;
663 if (status
& RXSTAT_SHORTPACKET
) stats
->rx_length_errors
++;
670 dev
->stats
.rx_packets
+= received
;
671 priv(dev
)->rx_head
= next_ptr
;
673 * If rx went off line, then that means that the buffer may be full. We
674 * have dropped at least one packet.
676 if (!(ether3_inw(REG_STATUS
) & STAT_RXON
)) {
677 dev
->stats
.rx_dropped
++;
678 ether3_outw(next_ptr
, REG_RECVPTR
);
679 ether3_outw(priv(dev
)->regs
.command
| CMD_RXON
, REG_COMMAND
);
686 * Update stats for the transmitted packet(s)
688 static void ether3_tx(struct net_device
*dev
)
690 unsigned int tx_tail
= priv(dev
)->tx_tail
;
694 unsigned long status
;
697 * Read the packet header
699 ether3_setbuffer(dev
, buffer_read
, tx_tail
* 0x600);
700 status
= ether3_readlong(dev
);
703 * Check to see if this packet has been transmitted
705 if ((status
& (TXSTAT_DONE
| TXHDR_TRANSMIT
)) !=
706 (TXSTAT_DONE
| TXHDR_TRANSMIT
))
712 if (!(status
& (TXSTAT_BABBLED
| TXSTAT_16COLLISIONS
)))
713 dev
->stats
.tx_packets
++;
715 dev
->stats
.tx_errors
++;
716 if (status
& TXSTAT_16COLLISIONS
)
717 dev
->stats
.collisions
+= 16;
718 if (status
& TXSTAT_BABBLED
)
719 dev
->stats
.tx_fifo_errors
++;
722 tx_tail
= (tx_tail
+ 1) & 15;
723 } while (--max_work
);
725 if (priv(dev
)->tx_tail
!= tx_tail
) {
726 priv(dev
)->tx_tail
= tx_tail
;
727 netif_wake_queue(dev
);
731 static void ether3_banner(void)
733 static unsigned version_printed
= 0;
735 if (net_debug
&& version_printed
++ == 0)
736 printk(KERN_INFO
"%s", version
);
739 static const struct net_device_ops ether3_netdev_ops
= {
740 .ndo_open
= ether3_open
,
741 .ndo_stop
= ether3_close
,
742 .ndo_start_xmit
= ether3_sendpacket
,
743 .ndo_set_rx_mode
= ether3_setmulticastlist
,
744 .ndo_tx_timeout
= ether3_timeout
,
745 .ndo_validate_addr
= eth_validate_addr
,
746 .ndo_set_mac_address
= eth_mac_addr
,
750 ether3_probe(struct expansion_card
*ec
, const struct ecard_id
*id
)
752 const struct ether3_data
*data
= id
->data
;
753 struct net_device
*dev
;
758 ret
= ecard_request_resources(ec
);
762 dev
= alloc_etherdev(sizeof(struct dev_priv
));
768 SET_NETDEV_DEV(dev
, &ec
->dev
);
770 priv(dev
)->base
= ecardm_iomap(ec
, ECARD_RES_MEMC
, 0, 0);
771 if (!priv(dev
)->base
) {
776 ec
->irqaddr
= priv(dev
)->base
+ data
->base_offset
;
779 priv(dev
)->seeq
= priv(dev
)->base
+ data
->base_offset
;
782 ether3_addr(dev
->dev_addr
, ec
);
784 priv(dev
)->dev
= dev
;
785 timer_setup(&priv(dev
)->timer
, ether3_ledoff
, 0);
789 ether3_outb(0x80, REG_CONFIG2
+ 4);
790 bus_type
= BUS_UNKNOWN
;
793 /* Test using Receive Pointer (16-bit register) to find out
794 * how the ether3 is connected to the bus...
796 if (ether3_probe_bus_8(dev
, 0x100) &&
797 ether3_probe_bus_8(dev
, 0x201))
800 if (bus_type
== BUS_UNKNOWN
&&
801 ether3_probe_bus_16(dev
, 0x101) &&
802 ether3_probe_bus_16(dev
, 0x201))
807 printk(KERN_ERR
"%s: unable to identify bus width\n", dev
->name
);
812 printk(KERN_ERR
"%s: %s found, but is an unsupported "
813 "8-bit card\n", dev
->name
, data
->name
);
821 if (ether3_init_2(dev
)) {
826 dev
->netdev_ops
= ðer3_netdev_ops
;
827 dev
->watchdog_timeo
= 5 * HZ
/ 100;
829 ret
= register_netdev(dev
);
833 printk("%s: %s in slot %d, %pM\n",
834 dev
->name
, data
->name
, ec
->slot_no
, dev
->dev_addr
);
836 ecard_set_drvdata(ec
, dev
);
842 ecard_release_resources(ec
);
847 static void ether3_remove(struct expansion_card
*ec
)
849 struct net_device
*dev
= ecard_get_drvdata(ec
);
851 ecard_set_drvdata(ec
, NULL
);
853 unregister_netdev(dev
);
855 ecard_release_resources(ec
);
858 static struct ether3_data ether3
= {
863 static struct ether3_data etherb
= {
865 .base_offset
= 0x800,
868 static const struct ecard_id ether3_ids
[] = {
869 { MANU_ANT2
, PROD_ANT_ETHER3
, ðer3
},
870 { MANU_ANT
, PROD_ANT_ETHER3
, ðer3
},
871 { MANU_ANT
, PROD_ANT_ETHERB
, ðerb
},
875 static struct ecard_driver ether3_driver
= {
876 .probe
= ether3_probe
,
877 .remove
= ether3_remove
,
878 .id_table
= ether3_ids
,
884 static int __init
ether3_init(void)
886 return ecard_register_driver(ðer3_driver
);
889 static void __exit
ether3_exit(void)
891 ecard_remove_driver(ðer3_driver
);
894 module_init(ether3_init
);
895 module_exit(ether3_exit
);
897 MODULE_LICENSE("GPL");