16 #include <linux/kernel.h>
17 #include <linux/types.h>
20 #include <linux/slab.h>
21 #include <linux/string.h>
22 #include <linux/errno.h>
23 #include <linux/netdevice.h>
28 #include <linux/bitops.h>
32 #include <mach/hardware.h>
40 am79c961_interrupt (
int irq,
void *
dev_id);
45 "am79c961 ethernet driver (C) 1995-2001 Russell King v0.04\n";
53 "str%?h %1, [%2] @ NET_RAP\n\t"
54 "str%?h %0, [%2, #-4] @ NET_RDP"
59 static inline unsigned short read_rreg(
u_long base_addr,
u_int reg)
63 "str%?h %1, [%2] @ NET_RAP\n\t"
64 "ldr%?h %0, [%2, #-4] @ NET_RDP"
73 "str%?h %1, [%2] @ NET_RAP\n\t"
74 "str%?h %0, [%2, #8] @ NET_IDP"
79 static inline unsigned short read_ireg(
u_long base_addr,
u_int reg)
83 "str%?h %1, [%2] @ NAT_RAP\n\t"
84 "ldr%?h %0, [%2, #8] @ NET_IDP\n\t"
90 #define am_writeword(dev,off,val) __raw_writew(val, ISAMEM_BASE + ((off) << 1))
91 #define am_readword(dev,off) __raw_readw(ISAMEM_BASE + ((off) << 1))
97 length = (length + 1) & ~1;
99 asm volatile(
"str%?h %2, [%0], #4"
100 :
"=&r" (
offset) :
"0" (offset),
"r" (buf[0] | (buf[1] << 8)));
105 register unsigned int tmp asm(
"r2"), tmp2
asm(
"r3");
107 "ldm%?ia %0!, {%1, %2}"
108 :
"+r" (
buf),
"=&r" (
tmp),
"=&r" (tmp2));
111 "str%?h %1, [%0], #4\n\t"
112 "mov%? %1, %1, lsr #16\n\t"
113 "str%?h %1, [%0], #4\n\t"
114 "str%?h %2, [%0], #4\n\t"
115 "mov%? %2, %2, lsr #16\n\t"
116 "str%?h %2, [%0], #4"
117 :
"+r" (
offset),
"=&r" (
tmp),
"=&r" (tmp2));
120 asm volatile(
"str%?h %2, [%0], #4"
121 :
"=&r" (
offset) :
"0" (offset),
"r" (buf[0] | (buf[1] << 8)));
128 am_readbuffer(
struct net_device *dev,
u_int offset,
unsigned char *buf,
unsigned int length)
131 length = (length + 1) & ~1;
135 "ldr%?h %2, [%0], #4\n\t"
136 "str%?b %2, [%1], #1\n\t"
137 "mov%? %2, %2, lsr #8\n\t"
138 "str%?b %2, [%1], #1"
139 :
"=&r" (
offset),
"=&r" (buf),
"=r" (
tmp):
"0" (offset),
"1" (
buf));
143 register unsigned int tmp
asm(
"r2"), tmp2
asm(
"r3"), tmp3;
145 "ldr%?h %2, [%0], #4\n\t"
146 "ldr%?h %4, [%0], #4\n\t"
147 "ldr%?h %3, [%0], #4\n\t"
148 "orr%? %2, %2, %4, lsl #16\n\t"
149 "ldr%?h %4, [%0], #4\n\t"
150 "orr%? %3, %3, %4, lsl #16\n\t"
151 "stm%?ia %1!, {%2, %3}"
152 :
"=&r" (
offset),
"=&r" (buf),
"=r" (
tmp),
"=r" (tmp2),
"=r" (tmp3)
153 :
"0" (offset),
"1" (
buf));
159 "ldr%?h %2, [%0], #4\n\t"
160 "str%?b %2, [%1], #1\n\t"
161 "mov%? %2, %2, lsr #8\n\t"
162 "str%?b %2, [%1], #1"
163 :
"=&r" (
offset),
"=&r" (buf),
"=r" (
tmp) :
"0" (offset),
"1" (
buf));
168 #error Not compatible
172 am79c961_ramtest(
struct net_device *dev,
unsigned int val)
175 int i,
error = 0, errorcount = 0;
179 memset (buffer, val, 65536);
180 am_writebuffer(dev, 0, buffer, 65536);
181 memset (buffer, val ^ 255, 65536);
182 am_readbuffer(dev, 0, buffer, 65536);
183 for (i = 0; i < 65536; i++) {
184 if (buffer[i] != val && !error) {
185 printk (
"%s: buffer error (%02X %02X) %05X - ", dev->
name, val, buffer[i], i);
188 }
else if (error && buffer[i] == val) {
199 static void am79c961_mc_hash(
char *
addr,
u16 *
hash)
207 bit = (crc >> 26) & 15;
218 memset(hash, 0xff, 4 *
sizeof(*hash));
220 memset(hash, 0xff, 4 *
sizeof(*hash));
224 memset(hash, 0, 4 *
sizeof(*hash));
227 am79c961_mc_hash(ha->
addr, hash);
239 u_int hdr_addr, first_free_addr;
240 u16 multi_hash[4], mode = am79c961_get_rx_mode(dev, multi_hash);
248 spin_unlock_irqrestore(&priv->
chip_lock, flags);
250 write_ireg (dev->base_addr, 5, 0x00a0);
251 write_ireg (dev->base_addr, 6, 0x0081);
252 write_ireg (dev->base_addr, 7, 0x0090);
253 write_ireg (dev->base_addr, 2, 0x0000);
256 write_rreg (dev->base_addr, i, multi_hash[i -
LADRL]);
258 for (i =
PADRL, p = dev->dev_addr; i <=
PADRH; i++, p += 2)
259 write_rreg (dev->base_addr, i, p[0] | (p[1] << 8));
261 write_rreg (dev->base_addr,
MODE, mode);
262 write_rreg (dev->base_addr,
POLLINT, 0);
271 priv->
rxhdr = hdr_addr;
275 am_writeword (dev, hdr_addr, first_free_addr);
276 am_writeword (dev, hdr_addr + 2,
RMD_OWN);
277 am_writeword (dev, hdr_addr + 4, (-1600));
278 am_writeword (dev, hdr_addr + 6, 0);
279 first_free_addr += 1600;
284 priv->
txhdr = hdr_addr;
287 am_writeword (dev, hdr_addr, first_free_addr);
289 am_writeword (dev, hdr_addr + 4, 0xf000);
290 am_writeword (dev, hdr_addr + 6, 0);
291 first_free_addr += 1600;
296 write_rreg (dev->base_addr,
BASERXH, 0);
298 write_rreg (dev->base_addr,
BASERXH, 0);
305 static void am79c961_timer(
unsigned long data)
308 struct dev_priv *priv = netdev_priv(dev);
309 unsigned int lnkstat, carrier;
314 spin_unlock_irqrestore(&priv->
chip_lock, flags);
315 carrier = netif_carrier_ok(dev);
317 if (lnkstat && !carrier) {
320 }
else if (!lnkstat && carrier) {
334 struct dev_priv *priv = netdev_priv(dev);
341 am79c961_init_for_open(dev);
348 netif_start_queue(dev);
359 struct dev_priv *priv = netdev_priv(dev);
364 netif_stop_queue(dev);
370 spin_unlock_irqrestore(&priv->
chip_lock, flags);
380 static void am79c961_setmulticastlist (
struct net_device *dev)
382 struct dev_priv *priv = netdev_priv(dev);
384 u16 multi_hash[4], mode = am79c961_get_rx_mode(dev, multi_hash);
401 spin_unlock_irqrestore(&priv->
chip_lock, flags);
425 spin_unlock_irqrestore(&priv->
chip_lock, flags);
428 static void am79c961_timeout(
struct net_device *dev)
437 netif_wake_queue(dev);
446 struct dev_priv *priv = netdev_priv(dev);
447 unsigned int hdraddr, bufaddr;
452 hdraddr = priv->
txhdr + (head << 3);
455 if (head >= TX_BUFFERS)
458 am_writebuffer (dev, bufaddr, skb->
data, skb->
len);
459 am_writeword (dev, hdraddr + 4, -skb->
len);
465 spin_unlock_irqrestore(&priv->
chip_lock, flags);
473 netif_stop_queue(dev);
496 status = am_readword (dev, hdraddr + 2);
501 if (priv->
rxtail >= RX_BUFFERS)
505 am_writeword (dev, hdraddr + 2, RMD_OWN);
506 dev->
stats.rx_errors++;
509 dev->
stats.rx_frame_errors++;
511 dev->
stats.rx_crc_errors++;
513 dev->
stats.rx_length_errors++;
517 len = am_readword(dev, hdraddr + 6);
518 skb = netdev_alloc_skb(dev, len + 2);
523 am_readbuffer(dev, pktaddr,
skb_put(skb, len), len);
524 am_writeword(dev, hdraddr + 2, RMD_OWN);
528 dev->
stats.rx_packets++;
530 am_writeword (dev, hdraddr + 2, RMD_OWN);
532 dev->
stats.rx_dropped++;
550 status = am_readword (dev, hdraddr + 2);
555 if (priv->
txtail >= TX_BUFFERS)
561 dev->
stats.tx_errors++;
563 status2 = am_readword (dev, hdraddr + 6);
568 am_writeword (dev, hdraddr + 6, 0);
571 dev->
stats.collisions += 16;
573 dev->
stats.tx_window_errors++;
575 dev->
stats.tx_carrier_errors++;
577 dev->
stats.tx_fifo_errors++;
580 dev->
stats.tx_packets++;
581 len = am_readword (dev, hdraddr + 4);
585 netif_wake_queue(dev);
589 am79c961_interrupt(
int irq,
void *
dev_id)
592 struct dev_priv *priv = netdev_priv(dev);
604 am79c961_rx(dev, priv);
608 am79c961_tx(dev, priv);
612 dev->
stats.rx_dropped++;
618 }
while (--n && status & (CSR0_RINT | CSR0_TINT));
623 #ifdef CONFIG_NET_POLL_CONTROLLER
624 static void am79c961_poll_controller(
struct net_device *dev)
628 am79c961_interrupt(dev->
irq, dev);
640 struct dev_priv *priv = netdev_priv(dev);
647 am79c961_ramtest(dev, 0x66);
648 am79c961_ramtest(dev, 0x99);
653 static void __init am79c961_banner(
void)
655 static unsigned version_printed;
661 .ndo_open = am79c961_open,
662 .ndo_stop = am79c961_close,
663 .ndo_start_xmit = am79c961_sendpacket,
664 .ndo_set_rx_mode = am79c961_setmulticastlist,
665 .ndo_tx_timeout = am79c961_timeout,
669 #ifdef CONFIG_NET_POLL_CONTROLLER
670 .ndo_poll_controller = am79c961_poll_controller,
685 dev = alloc_etherdev(
sizeof(
struct dev_priv));
692 priv = netdev_priv(dev);
727 for (i = 0; i < 6; i++)
735 priv->
timer.function = am79c961_timer;
737 if (am79c961_hw_init(dev))
758 .probe = am79c961_probe,
764 static int __init am79c961_init(
void)