88 #include <linux/module.h>
89 #include <linux/kernel.h>
90 #include <linux/string.h>
91 #include <linux/slab.h>
92 #include <linux/errno.h>
97 #include <linux/netdevice.h>
100 #include <linux/if_arp.h>
101 #include <linux/bitops.h>
119 #define DMA_RX_MODE 0x14
120 #define DMA_TX_MODE 0x18
121 #define dma_page_eq(ptr1, ptr2) ((long)(ptr1)>>17 == (long)(ptr2)>>17)
122 #define RX_BUF_SIZE 8192
123 #define TX_BUF_SIZE 8192
124 #define DMA_BUF_SIZE (RX_BUF_SIZE + 16)
126 #define TX_TIMEOUT (HZ/10)
142 #define NETIDBLK_MAGIC "NETIDBLK"
143 #define NETIDBLK_MAGIC_SIZE 8
167 static void update_stop_hit(
short ioaddr,
unsigned short rx_stop_offset);
200 static void znet_release_resources (
struct net_device *dev)
212 static void znet_transceiver_power (
struct net_device *dev,
int on)
231 static void znet_set_multicast_list (
struct net_device *dev)
339 if (znet_debug > 2) {
343 for (i = 0, c = (
char *) cfblk; i <
sizeof (*cfblk); i++)
358 .ndo_open = znet_open,
359 .ndo_stop = znet_close,
360 .ndo_start_xmit = znet_send_packet,
361 .ndo_set_rx_mode = znet_set_multicast_list,
362 .ndo_tx_timeout = znet_tx_timeout,
372 static int __init znet_probe (
void)
398 znet = netdev_priv(dev);
405 for (i = 0; i < 6; i++)
409 ", using IRQ %d DMA %d and %d.\n",
413 if (znet_debug > 1) {
414 printk(
KERN_INFO "%s: vendor '%16.16s' IRQ1 %d IRQ2 %d DMA1 %d DMA2 %d.\n",
418 printk(
KERN_INFO "%s: iobase1 %#x size %d iobase2 %#x size %d net type %2.2x.\n",
478 if (znet_request_resources (dev)) {
483 znet_transceiver_power (dev, 1);
501 if (
inb(ioaddr) != 0x10 &&
inb(ioaddr) != 0x00)
506 netif_start_queue (dev);
512 static void znet_tx_timeout (
struct net_device *dev)
518 event =
inb (ioaddr);
520 tx_status =
inw (ioaddr);
522 rx_offset =
inw (ioaddr);
524 state =
inb (ioaddr);
526 " resetting.\n", dev->
name, event, tx_status, rx_offset, state);
532 netif_wake_queue (dev);
551 netif_stop_queue (dev);
555 if (
inw(ioaddr) == 0x0010 &&
556 inw(ioaddr) == 0x0000 &&
557 inw(ioaddr) == 0x0010) {
561 znet_transceiver_power (dev, 1);
565 unsigned char *
buf = (
void *)skb->
data;
567 ushort rnd_len = (length + 1)>>1;
577 rnd_len -= semi_cnt>>1;
592 spin_unlock_irqrestore (&znet->
lock, flags);
594 netif_start_queue (dev);
612 spin_lock (&znet->
lock);
619 if (znet_debug > 5) {
622 result =
inw(ioaddr);
624 rx_ptr =
inw(ioaddr);
626 running =
inb(ioaddr);
627 printk(
KERN_DEBUG "%s: interrupt, status %02x, %04x %04x %02x serial %d.\n",
628 dev->
name, status, result, rx_ptr, running, boguscnt);
640 tx_status =
inw(ioaddr);
642 if (tx_status &
TX_OK) {
643 dev->
stats.tx_packets++;
647 dev->
stats.tx_carrier_errors++;
649 dev->
stats.tx_fifo_errors++;
651 dev->
stats.tx_heartbeat_errors++;
653 dev->
stats.tx_aborted_errors++;
656 dev->
stats.tx_errors++;
664 znet_transceiver_power (dev, 0);
665 znet_transceiver_power (dev, 1);
667 netif_wake_queue (dev);
676 }
while (boguscnt--);
678 spin_unlock (&znet->
lock);
688 short next_frame_end_offset = 0;
689 short *cur_frame_end;
690 short cur_frame_end_offset;
693 cur_frame_end_offset =
inw(ioaddr);
697 dev->
name, cur_frame_end_offset);
707 unsigned short hi_cnt, lo_cnt, hi_status, lo_status;
710 if (cur_frame_end_offset < 4) {
717 cur_frame_end = znet->
rx_start + cur_frame_end_offset - 4;
719 lo_status = *cur_frame_end++;
720 hi_status = *cur_frame_end++;
721 status = ((hi_status & 0xff) << 8) + (lo_status & 0xff);
722 lo_cnt = *cur_frame_end++;
723 hi_cnt = *cur_frame_end++;
724 count = ((hi_cnt & 0xff) << 8) + (lo_cnt & 0xff);
727 printk(
KERN_DEBUG "Constructing trailer at location %03x, %04x %04x %04x %04x"
728 " count %#x status %04x.\n",
729 cur_frame_end_offset<<1, lo_status, hi_status, lo_cnt, hi_cnt,
731 cur_frame_end[-4] =
status;
732 cur_frame_end[-3] = next_frame_end_offset;
733 cur_frame_end[-2] =
count;
734 next_frame_end_offset = cur_frame_end_offset;
735 cur_frame_end_offset -= ((count + 1)>>1) + 3;
736 if (cur_frame_end_offset < 0)
743 int status = this_rfp_ptr[-4];
744 int pkt_len = this_rfp_ptr[-2];
747 printk(
KERN_DEBUG "Looking at trailer ending at %04x status %04x length %03x"
748 " next %04x.\n", next_frame_end_offset<<1, status, pkt_len,
749 this_rfp_ptr[-3]<<1);
752 dev->
stats.rx_errors++;
756 if (status & 0x0200) dev->
stats.rx_over_errors++;
757 if (status & 0x0100) dev->
stats.rx_fifo_errors++;
763 }
else if (pkt_len > 1536) {
764 dev->
stats.rx_length_errors++;
769 skb = netdev_alloc_skb(dev, pkt_len);
773 dev->
stats.rx_dropped++;
784 if (znet_debug > 6) {
785 unsigned int *
packet = (
unsigned int *) skb->
data;
787 packet[1], packet[2], packet[3]);
792 dev->
stats.rx_packets++;
795 znet->
rx_cur = this_rfp_ptr;
799 next_frame_end_offset = this_rfp_ptr[-3];
800 if (next_frame_end_offset == 0)
802 this_rfp_ptr = znet->
rx_start + next_frame_end_offset;
803 }
while (--boguscount);
815 netif_stop_queue (dev);
822 znet_transceiver_power (dev, 0);
824 znet_release_resources (dev);
832 unsigned char stat =
inb (ioaddr);
839 addr |=
inb(dma_port) << 8;
842 if (znet_debug > 1) {
845 stat, addr<<1, residue);
852 static void hardware_init(
struct net_device *dev)
866 clear_dma_ff(znet->
rx_dma);
873 clear_dma_ff(znet->
tx_dma);
890 znet_set_multicast_list (dev);
899 update_stop_hit(ioaddr, 8192);
902 netif_start_queue (dev);
905 static void update_stop_hit(
short ioaddr,
unsigned short rx_stop_offset)
915 static __exit void znet_cleanup (
void)