41 #define net_debug debug
44 static int max_interrupt_work = 15;
55 #define TX_TIMEOUT (400*HZ/1000)
125 #include <linux/kernel.h>
126 #include <linux/module.h>
127 #include <linux/types.h>
128 #include <linux/fcntl.h>
131 #include <linux/in.h>
132 #include <linux/string.h>
133 #include <linux/errno.h>
136 #include <linux/netdevice.h>
141 #include <linux/bitops.h>
157 MODULE_PARM_DESC(max_interrupt_work,
"ATP maximum events handled per interrupt");
164 #define ETHERCARD_TOTAL_SIZE 3
167 static char mux_8012[] = { 0xff, 0xf7, 0xff, 0xfb, 0xf3, 0xfb, 0xff, 0xf7,};
185 #define TIMED_CHECKER (HZ/4)
188 static void atp_timed_checker(
unsigned long ignored);
193 static int atp_probe1(
long ioaddr);
195 static unsigned short eeprom_op(
long ioaddr,
unsigned int cmd);
198 static void write_packet(
long ioaddr,
int length,
unsigned char *
packet,
int pad,
int mode);
199 static void trigger_send(
long ioaddr,
int length);
221 static int __init atp_init(
void)
223 int *
port,
ports[] = {0x378, 0x278, 0x3bc, 0};
226 if (base_addr > 0x1ff)
227 return atp_probe1(base_addr);
228 else if (base_addr == 1)
231 for (port = ports; *
port; port++) {
236 if (atp_probe1(ioaddr) == 0)
244 .ndo_open = net_open,
245 .ndo_stop = net_close,
246 .ndo_start_xmit = atp_send_packet,
247 .ndo_set_rx_mode = set_rx_mode,
254 static int __init atp_probe1(
long ioaddr)
266 printk(
"atp: Control register was %#2.2x.\n", saved_ctrl_reg);
269 #ifndef final_version
272 for (i = 0; i < 8; i++)
275 printk(
"atp: Registers are ");
276 for (i = 0; i < 32; i++)
277 printk(
" %2.2x", read_nibble(ioaddr, i));
282 for (i = 0; i < 8; i++)
286 status = read_nibble(ioaddr,
CMR1);
290 for (i = 0; i < 32; i++)
291 printk(
" %2.2x", read_nibble(ioaddr, i));
295 if ((status & 0x78) != 0x08) {
300 status = read_nibble(ioaddr,
CMR2_h);
301 if ((status & 0x78) != 0x10) {
306 dev = alloc_etherdev(
sizeof(
struct net_local));
311 write_reg_byte(ioaddr,
CMR2, 0x01);
317 else if (ioaddr == 0x378)
341 lp = netdev_priv(dev);
383 for (i = 0; i < 3; i++)
404 unsigned eedata_out = 0;
407 while (--num_bits >= 0) {
447 lp->
timer.function = atp_timed_checker;
450 netif_start_queue(dev);
456 static void hardware_init(
struct net_device *dev)
463 for (i = 0; i < 8; i++)
467 for (i = 0; i < 6; i++)
474 (read_nibble(ioaddr,
CMR2_h) >> 3) & 0x0f);
492 static void trigger_send(
long ioaddr,
int length)
494 write_reg_byte(ioaddr,
TxCNT0, length & 0xff);
508 if ((data_mode & 1) == 0) {
512 write_byte_mode0(ioaddr, *packet++);
513 }
while (--length > pad_len) ;
515 write_byte_mode0(ioaddr, 0);
516 }
while (--length > 0) ;
519 unsigned char outbyte = *packet++;
529 while (--length > pad_len)
530 write_byte_mode1(ioaddr, *packet++);
532 write_byte_mode1(ioaddr, 0);
546 dev->
stats.tx_errors++;
550 netif_wake_queue(dev);
551 dev->
stats.tx_errors++;
564 netif_stop_queue(dev);
571 write_reg_high(ioaddr,
IMR, 0);
572 spin_unlock_irqrestore(&lp->
lock, flags);
574 write_packet(ioaddr, length, skb->
data, length-skb->
len, dev->
if_port);
578 trigger_send(ioaddr, length);
595 static irqreturn_t atp_interrupt(
int irq,
void *dev_instance)
600 static int num_tx_since_rx;
601 int boguscount = max_interrupt_work;
605 lp = netdev_priv(dev);
607 spin_lock(&lp->
lock);
617 while (--boguscount > 0) {
618 int status = read_nibble(ioaddr,
ISR);
625 int read_status = read_nibble(ioaddr,
CMR1);
627 printk(
"handling Rx packet %02x..", read_status);
630 if (read_status & (
CMR1_IRQ << 3)) {
631 dev->
stats.rx_over_errors++;
638 }
else if ((read_status & (
CMR1_BufEnb << 3)) == 0) {
643 }
while (--boguscount > 0);
651 dev->
stats.collisions++;
652 if (++lp->
re_tx > 15) {
653 dev->
stats.tx_aborted_errors++;
662 dev->
stats.tx_packets++;
670 netif_wake_queue(dev);
673 }
else if (num_tx_since_rx > 8 &&
677 "%ld jiffies status %02x CMR1 %02x.\n", dev->
name,
678 num_tx_since_rx, jiffies - dev->
last_rx, status,
679 (read_nibble(ioaddr,
CMR1) >> 3) & 15);
680 dev->
stats.rx_missed_errors++;
692 for (i = 0; i < 6; i++)
694 #if 0 && defined(TIMED_CHECKER)
707 spin_unlock(&lp->
lock);
716 static void atp_timed_checker(
unsigned long data)
724 spin_lock(&lp->
lock);
725 if (tickssofar > 2*
HZ) {
727 for (i = 0; i < 6; i++)
731 for (i = 0; i < 6; i++)
732 if (read_cmd_byte(ioaddr,
PAR0 + i) != atp_timed_dev->dev_addr[i])
734 struct net_local *lp = netdev_priv(atp_timed_dev);
735 write_reg_byte(ioaddr,
PAR0 + i, atp_timed_dev->dev_addr[i]);
737 dev->
stats.tx_errors++;
739 dev->
stats.tx_dropped++;
741 dev->
stats.collisions++;
743 dev->
stats.rx_errors++;
747 spin_unlock(&lp->
lock);
762 read_block(ioaddr, 8, (
unsigned char*)&rx_head, dev->
if_port);
765 rx_head.rx_count, rx_head.rx_status, rx_head.cur_addr);
766 if ((rx_head.rx_status & 0x77) != 0x01) {
767 dev->
stats.rx_errors++;
768 if (rx_head.rx_status & 0x0004) dev->
stats.rx_frame_errors++;
769 else if (rx_head.rx_status & 0x0002) dev->
stats.rx_crc_errors++;
772 dev->
name, rx_head.rx_status);
773 if (rx_head.rx_status & 0x0020) {
774 dev->
stats.rx_fifo_errors++;
777 }
else if (rx_head.rx_status & 0x0050)
782 int pkt_len = (rx_head.rx_count & 0x7ff) - 4;
785 skb = netdev_alloc_skb(dev, pkt_len + 2);
789 dev->
stats.rx_dropped++;
798 dev->
stats.rx_packets++;
806 static void read_block(
long ioaddr,
int length,
unsigned char *
p,
int data_mode)
808 if (data_mode <= 3) {
812 if (data_mode <= 1) {
813 do { *p++ = read_byte_mode0(ioaddr); }
while (--length > 0);
815 do { *p++ = read_byte_mode2(ioaddr); }
while (--length > 0);
817 }
else if (data_mode <= 5) {
818 do { *p++ = read_byte_mode4(ioaddr); }
while (--length > 0);
820 do { *p++ = read_byte_mode6(ioaddr); }
while (--length > 0);
834 netif_stop_queue(dev);
855 static void set_rx_mode_8002(
struct net_device *dev)
867 static void set_rx_mode_8012(
struct net_device *dev)
879 memset(mc_filter, 0xff,
sizeof(mc_filter));
884 memset(mc_filter, 0,
sizeof(mc_filter));
887 mc_filter[filterbit >> 5] |= 1 << (filterbit & 31);
893 for (i = 0; i < 8; i++)
894 write_reg_byte(ioaddr, i, mc_filter[i]);
899 for (i = 0; i < 8; i++)
900 printk(
" %2.2x", mc_filter[i]);
908 static void set_rx_mode(
struct net_device *dev)
913 return set_rx_mode_8002(dev);
915 return set_rx_mode_8012(dev);
919 static int __init atp_init_module(
void) {
925 static void __exit atp_cleanup_module(
void) {
928 while (root_atp_dev) {
929 struct net_local *atp_local = netdev_priv(root_atp_dev);
934 root_atp_dev = next_dev;