23 #include <linux/kernel.h>
24 #include <linux/module.h>
25 #include <linux/netdevice.h>
28 #include <linux/string.h>
41 static char mac_mace_string[] =
"macmace";
43 #define N_TX_BUFF_ORDER 0
44 #define N_TX_RING (1 << N_TX_BUFF_ORDER)
45 #define N_RX_BUFF_ORDER 3
46 #define N_RX_RING (1 << N_RX_BUFF_ORDER)
50 #define MACE_BUFF_SIZE 0x800
53 #define BROKEN_ADDRCHG_REV 0x0941
57 #define MACE_BASE (void *)(0x50F1C000)
58 #define MACE_PROM (void *)(0x50F08001)
88 #define PRIV_BYTES sizeof(struct mace_data)
105 static void mace_load_rxdma_base(
struct net_device *
dev,
int set)
120 static void mace_rxdma_reset(
struct net_device *dev)
124 u8 maccc = mace->maccc;
126 mace->maccc = maccc & ~
ENRCV;
129 mace_load_rxdma_base(dev, 0x00);
133 mace_load_rxdma_base(dev, 0x10);
147 static void mace_txdma_reset(
struct net_device *dev)
156 mace->maccc = maccc & ~
ENXMT;
169 static void mace_dma_off(
struct net_device *dev)
183 .ndo_open = mace_open,
184 .ndo_stop = mace_close,
185 .ndo_start_xmit = mace_xmit_start,
186 .ndo_tx_timeout = mace_tx_timeout,
187 .ndo_set_rx_mode = mace_set_multicast,
188 .ndo_set_mac_address = mace_set_address,
211 mp = netdev_priv(dev);
233 for (j = 0; j < 6; ++
j) {
234 u8 v = bitrev8(addr[j<<4]);
239 checksum ^= bitrev8(addr[j<<4]);
242 if (checksum != 0xFF) {
265 static void mace_reset(
struct net_device *dev)
275 if (mb->biucc &
SWRST) {
298 __mace_set_address(dev, dev->
dev_addr);
305 while ((mb->iac &
ADDRCHG) != 0)
308 for (i = 0; i < 8; ++
i)
322 static void __mace_set_address(
struct net_device *dev,
void *addr)
325 volatile struct mace *mb = mp->
mace;
326 unsigned char *
p =
addr;
334 while ((mb->iac &
ADDRCHG) != 0)
337 for (i = 0; i < 6; ++
i)
343 static int mace_set_address(
struct net_device *dev,
void *addr)
346 volatile struct mace *mb = mp->
mace;
354 __mace_set_address(dev, addr);
371 volatile struct mace *mb = mp->
mace;
413 mace_rxdma_reset(dev);
414 mace_txdma_reset(dev);
438 volatile struct mace *mb = mp->
mace;
459 netif_stop_queue(dev);
461 printk(
KERN_ERR "macmace: tx queue running but no free buffers.\n");
468 dev->
stats.tx_packets++;
472 skb_copy_from_linear_data(skb, mp->
tx_ring, skb->
len);
487 static void mace_set_multicast(
struct net_device *dev)
490 volatile struct mace *mb = mp->
mace;
503 unsigned char multicast_filter[8];
507 for (i = 0; i < 8; i++) {
508 multicast_filter[
i] = 0xFF;
511 for (i = 0; i < 8; i++)
512 multicast_filter[i] = 0;
517 multicast_filter[i >> 3] |= 1 << (i & 7);
525 while ((mb->iac &
ADDRCHG) != 0)
528 for (i = 0; i < 8; ++
i)
529 mb->ladrf = multicast_filter[i];
538 static void mace_handle_misc_intrs(
struct net_device *dev,
int intr)
541 volatile struct mace *mb = mp->
mace;
542 static int mace_babbles, mace_jabbers;
545 dev->
stats.rx_missed_errors += 256;
546 dev->
stats.rx_missed_errors += mb->mpc;
548 dev->
stats.rx_length_errors += 256;
549 dev->
stats.rx_length_errors += mb->rntpc;
551 ++dev->
stats.tx_heartbeat_errors;
553 if (mace_babbles++ < 4)
556 if (mace_jabbers++ < 4)
564 volatile struct mace *mb = mp->
mace;
572 mace_handle_misc_intrs(dev, intr);
576 if ((fs &
XMTSV) == 0) {
590 ++dev->
stats.tx_errors;
592 ++dev->
stats.tx_carrier_errors;
594 ++dev->
stats.tx_aborted_errors;
595 if (mb->xmtfs &
UFLO) {
597 dev->
stats.tx_fifo_errors++;
598 mace_txdma_reset(dev);
605 netif_wake_queue(dev);
612 static void mace_tx_timeout(
struct net_device *dev)
615 volatile struct mace *mb = mp->
mace;
623 mace_txdma_reset(dev);
627 mace_rxdma_reset(dev);
630 netif_wake_queue(dev);
650 dev->
stats.rx_errors++;
653 dev->
stats.rx_fifo_errors++;
656 dev->
stats.collisions++;
658 dev->
stats.rx_frame_errors++;
660 dev->
stats.rx_crc_errors++;
664 skb = netdev_alloc_skb(dev, frame_length + 2);
666 dev->
stats.rx_dropped++;
674 dev->
stats.rx_packets++;
683 static irqreturn_t mace_dma_intr(
int irq,
void *dev_id)
694 if (!(baka & 0x60000000))
return IRQ_NONE;
702 if (status & 0x2000) {
703 mace_rxdma_reset(dev);
704 }
else if (status & 0x0100) {
722 mace_load_rxdma_base(dev, mp->
rx_slot);
735 if (status & 0x2000) {
736 mace_txdma_reset(dev);
737 }
else if (status & 0x0100) {
751 struct net_device *dev = platform_get_drvdata(pdev);
773 .name = mac_mace_string,
778 static int __init mac_mace_init_module(
void)
786 static void __exit mac_mace_cleanup_module(
void)