34 #include <linux/module.h>
35 #include <linux/kernel.h>
36 #include <linux/types.h>
37 #include <linux/fcntl.h>
41 #include <linux/slab.h>
42 #include <linux/string.h>
43 #include <linux/errno.h>
44 #include <linux/device.h>
46 #include <linux/netdevice.h>
49 #include <linux/bitops.h>
60 #define BUFFER_SIZE 0x10000
61 #define TX_AREA_START 0x00100
62 #define TX_AREA_END 0x05000
63 #define RX_AREA_START 0x05000
64 #define RX_AREA_END 0x0fc00
85 #define ether1_readw(dev, addr, type, offset, svflgs) ether1_inw_p (dev, addr + (int)(&((type *)0)->offset), svflgs)
86 #define ether1_writew(dev, val, addr, type, offset, svflgs) ether1_outw_p (dev, val, addr + (int)(&((type *)0)->offset), svflgs)
88 static inline unsigned short
97 writeb(addr >> 12, REG_PAGE);
98 ret =
readw(ETHER1_RAM + ((addr & 4095) << 1));
112 writeb(addr >> 12, REG_PAGE);
113 writew(val, ETHER1_RAM + ((addr & 4095) << 1));
133 offset = start & 4095;
135 addr = ETHER1_RAM + (offset << 1);
137 if (offset + length > 4096)
151 1: ldr %0, [%1], #2\n\
152 mov %0, %0, lsl #16\n\
153 orr %0, %0, %0, lsr #16\n\
158 mov %0, %0, lsl #16\n\
159 orr %0, %0, %0, lsr #16\n\
164 mov %0, %0, lsl #16\n\
165 orr %0, %0, %0, lsr #16\n\
170 mov %0, %0, lsl #16\n\
171 orr %0, %0, %0, lsr #16\n\
175 2: adds %3, %3, #1\n\
178 :
"=&r" (used),
"=&r" (data)
179 :
"r" (addr),
"r" (thislen),
"1" (data));
191 ether1_readbuffer (
struct net_device *dev,
void *data,
unsigned int start,
unsigned int length)
196 offset = start & 4095;
198 addr = ETHER1_RAM + (offset << 1);
200 if (offset + length > 4096)
214 1: ldr %0, [%2], #4\n\
216 mov %0, %0, lsr #8\n\
222 mov %0, %0, lsr #8\n\
228 mov %0, %0, lsr #8\n\
234 mov %0, %0, lsr #8\n\
238 2: adds %3, %3, #1\n\
241 :
"=&r" (used),
"=&r" (data)
242 :
"r" (addr),
"r" (thislen),
"1" (data));
271 if (buffer[i] != byte) {
272 if (max_errors >= 0 && bad != buffer[i]) {
275 printk (
KERN_CRIT "%s: RAM failed with (%02X instead of %02X) at 0x%04X",
276 dev->
name, buffer[i], byte, i);
284 if (bad_start == i - 1)
287 printk (
" - 0x%04X\n", i - 1);
294 printk (
" - 0x%04X\n", BUFFER_SIZE);
313 i = ether1_ramtest (dev, 0x5a);
316 i = ether1_ramtest (dev, 0x1e);
331 #define NOP_ADDR (TX_AREA_START)
332 #define NOP_SIZE (0x06)
333 static nop_t init_nop = {
340 #define TDR_ADDR (0x003a)
341 #define TDR_SIZE (0x08)
342 static tdr_t init_tdr = {
350 #define MC_ADDR (0x002e)
351 #define MC_SIZE (0x0c)
352 static mc_t init_mc = {
361 #define SA_ADDR (0x0022)
362 #define SA_SIZE (0x0c)
363 static sa_t init_sa = {
371 #define CFG_ADDR (0x0010)
372 #define CFG_SIZE (0x12)
373 static cfg_t init_cfg = {
380 CFG9_PREAMB8 | CFG9_ADDRLENBUF | CFG9_ADDRLEN(6),
384 CFG13_RETRY(15) | CFG13_SLOTH(2),
389 #define SCB_ADDR (0x0000)
390 #define SCB_SIZE (0x10)
391 static scb_t init_scb = {
393 SCB_CMDACKRNR | SCB_CMDACKCNA | SCB_CMDACKFR | SCB_CMDACKCX,
403 #define ISCP_ADDR (0xffee)
404 #define ISCP_SIZE (0x08)
405 static iscp_t init_iscp = {
413 #define SCP_ADDR (0xfff6)
414 #define SCP_SIZE (0x0a)
415 static scp_t init_scp = {
422 #define RFD_SIZE (0x16)
423 static rfd_t init_rfd = {
433 #define RBD_SIZE (0x0a)
434 static rbd_t init_rbd = {
442 #define TX_SIZE (0x08)
443 #define TBD_SIZE (0x08)
454 for (i = 0; i < 6; i++)
455 init_sa.sa_addr[i] = dev->
dev_addr[i];
468 printk (
KERN_ERR "%s: detected either RAM fault or compiler bug\n",
486 init_rfd.rfd_command = RFD_CMDEL | RFD_CMDSUSPEND;
489 init_rfd.rfd_command = 0;
491 init_rfd.rfd_rbdoffset = addr +
RFD_SIZE;
493 init_rfd.rfd_rbdoffset = 0;
494 init_rfd.rfd_link =
next;
495 init_rbd.rbd_link = next +
RFD_SIZE;
496 init_rbd.rbd_bufl = addr + RFD_SIZE +
RBD_SIZE;
498 ether1_writebuffer (dev, &init_rfd, addr, RFD_SIZE);
499 ether1_writebuffer (dev, &init_rbd, addr + RFD_SIZE, RBD_SIZE);
509 priv(dev)->resetting = 1;
510 priv(dev)->initialising = 1;
527 & STAT_COMPLETE) == 0) {
532 if ((status & (STAT_COMPLETE |
STAT_OK)) != (STAT_COMPLETE |
STAT_OK)) {
544 & STAT_COMPLETE) == 0) {
549 if ((status & (STAT_COMPLETE |
STAT_OK)) != (STAT_COMPLETE |
STAT_OK)) {
561 & STAT_COMPLETE) == 0) {
566 if ((status & (STAT_COMPLETE |
STAT_OK)) != (STAT_COMPLETE |
STAT_OK)) {
578 & STAT_COMPLETE) == 0) {
583 if ((status & (STAT_COMPLETE |
STAT_OK)) != (STAT_COMPLETE |
STAT_OK)) {
592 if (status & TDR_XCVRPROB)
597 status &
TDR_SHORT ?
"short" :
"open", (status & TDR_TIME) / 10,
598 (status & TDR_TIME) % 10);
601 status & TDR_SHORT ?
"short" :
"open", (status & TDR_TIME));
608 return failures ? 1 : 0;
618 size = (size + 1) & ~1;
619 tail =
priv(dev)->tx_tail;
622 if (tail >
priv(dev)->tx_head)
625 if (start + size > tail)
629 if (
priv(dev)->tx_head < tail && (
priv(dev)->tx_head + size) > tail)
631 start =
priv(dev)->tx_head;
641 if (!is_valid_ether_addr(dev->
dev_addr)) {
650 if (ether1_init_for_open (dev)) {
655 netif_start_queue(dev);
669 if (ether1_init_for_open (dev))
672 dev->
stats.tx_errors++;
673 netif_wake_queue(dev);
679 int tmp,
tst, nopaddr, txaddr, tbdaddr, dataddr;
690 if (ether1_init_for_open(dev))
693 priv(dev)->restart = 0;
704 txaddr = ether1_txalloc (dev,
TX_SIZE);
705 tbdaddr = ether1_txalloc (dev,
TBD_SIZE);
706 dataddr = ether1_txalloc (dev, skb->
len);
707 nopaddr = ether1_txalloc (dev,
NOP_SIZE);
711 tx.tx_link = nopaddr;
712 tx.tx_tbdoffset = tbdaddr;
713 tbd.tbd_opts = TBD_EOL | skb->
len;
714 tbd.tbd_link = I82586_NULL;
715 tbd.tbd_bufl = dataddr;
719 nop.nop_link = nopaddr;
722 ether1_writebuffer (dev, &tx, txaddr,
TX_SIZE);
723 ether1_writebuffer (dev, &tbd, tbdaddr,
TBD_SIZE);
724 ether1_writebuffer (dev, skb->
data, dataddr, skb->
len);
725 ether1_writebuffer (dev, &nop, nopaddr,
NOP_SIZE);
726 tmp =
priv(dev)->tx_link;
727 priv(dev)->tx_link = nopaddr;
737 tmp =
priv(dev)->tx_head;
743 netif_stop_queue(dev);
755 caddr =
priv(dev)->tx_tail;
758 ether1_readbuffer (dev, &nop, caddr,
NOP_SIZE);
760 switch (nop.nop_command &
CMD_MASK) {
764 != (
unsigned short)I82586_NULL) {
773 if (nop.nop_link == caddr) {
774 if (
priv(dev)->initialising == 0)
777 priv(dev)->initialising = 0;
780 if (caddr == nop.nop_link)
782 caddr = nop.nop_link;
786 if (nop.nop_status & STAT_COMPLETE)
788 printk (
KERN_ERR "%s: strange command complete without completed command\n", dev->
name);
789 priv(dev)->restart = 1;
795 priv(dev)->restart = 1;
799 while (nop.nop_status & STAT_COMPLETE) {
800 if (nop.nop_status &
STAT_OK) {
801 dev->
stats.tx_packets++;
802 dev->
stats.collisions += (nop.nop_status & STAT_COLLISIONS);
804 dev->
stats.tx_errors++;
806 if (nop.nop_status & STAT_COLLAFTERTX)
807 dev->
stats.collisions++;
808 if (nop.nop_status & STAT_NOCARRIER)
809 dev->
stats.tx_carrier_errors++;
810 if (nop.nop_status & STAT_TXLOSTCTS)
812 if (nop.nop_status & STAT_TXSLOWDMA)
813 dev->
stats.tx_fifo_errors++;
814 if (nop.nop_status & STAT_COLLEXCESSIVE)
815 dev->
stats.collisions += 16;
818 if (nop.nop_link == caddr) {
819 printk (
KERN_ERR "%s: tx buffer chaining error: tx command points to itself\n", dev->
name);
823 caddr = nop.nop_link;
824 ether1_readbuffer (dev, &nop, caddr,
NOP_SIZE);
826 printk (
KERN_ERR "%s: tx buffer chaining error: no nop after tx command\n", dev->
name);
830 if (caddr == nop.nop_link)
833 caddr = nop.nop_link;
834 ether1_readbuffer (dev, &nop, caddr,
NOP_SIZE);
836 printk (
KERN_ERR "%s: tx buffer chaining error: no tx command after nop\n", dev->
name);
840 priv(dev)->tx_tail = caddr;
842 caddr =
priv(dev)->tx_head;
844 priv(dev)->tx_head = caddr;
846 netif_wake_queue(dev);
853 int nexttail, rbdaddr;
858 if ((status & RFD_COMPLETE) == 0)
862 ether1_readbuffer (dev, &rbd, rbdaddr,
RBD_SIZE);
864 if ((rbd.rbd_status & (
RBD_EOF | RBD_ACNTVALID)) == (
RBD_EOF | RBD_ACNTVALID)) {
865 int length = rbd.rbd_status & RBD_ACNT;
868 length = (length + 1) & ~1;
869 skb = netdev_alloc_skb(dev, length + 2);
872 skb_reserve (skb, 2);
874 ether1_readbuffer (dev,
skb_put (skb, length), rbd.rbd_bufl, length);
878 dev->
stats.rx_packets++;
880 dev->
stats.rx_dropped++;
883 (rbd.rbd_status &
RBD_EOF) ?
"oversized packet" :
"acnt not valid");
884 dev->
stats.rx_dropped++;
889 if (nexttail !=
priv(dev)->rx_head)
890 printk(
KERN_ERR "%s: receiver buffer chaining error (%04X != %04X)\n",
891 dev->
name, nexttail,
priv(dev)->rx_head);
897 priv(dev)->rx_tail = nexttail;
903 ether1_interrupt (
int irq,
void *
dev_id)
911 ether1_writew(dev, status & (SCB_STRNR | SCB_STCNA | SCB_STFR | SCB_STCX),
914 if (status & SCB_STCX) {
915 ether1_xmit_done (dev);
917 if (status & SCB_STCNA) {
921 priv(dev)->resetting += 1;
923 != (
unsigned short)I82586_NULL) {
928 priv(dev)->resetting = 0;
930 if (status & SCB_STFR) {
931 ether1_recv_done (dev);
933 if (status & SCB_STRNR) {
938 dev->
stats.rx_dropped++;
969 ether1_setmulticastlist (
struct net_device *dev)
975 static void __devinit ether1_banner(
void)
977 static unsigned int version_printed = 0;
984 .ndo_open = ether1_open,
985 .ndo_stop = ether1_close,
986 .ndo_start_xmit = ether1_sendpacket,
987 .ndo_set_rx_mode = ether1_setmulticastlist,
988 .ndo_tx_timeout = ether1_timeout,
1006 dev = alloc_etherdev(
sizeof(
struct ether1_priv));
1016 if (!
priv(dev)->base) {
1026 for (i = 0; i < 6; i++)
1029 if (ether1_init_2(dev)) {
1066 static const struct ecard_id ether1_ids[] = {
1072 .probe = ether1_probe,
1074 .id_table = ether1_ids,
1080 static int __init ether1_init(
void)
1085 static void __exit ether1_exit(
void)