51 #include <linux/module.h>
52 #include <linux/kernel.h>
53 #include <linux/types.h>
54 #include <linux/fcntl.h>
56 #include <linux/ptrace.h>
59 #include <linux/string.h>
60 #include <linux/errno.h>
62 #include <linux/netdevice.h>
65 #include <linux/if_arp.h>
66 #include <linux/if_ltalk.h>
68 #include <linux/atalk.h>
70 #include <linux/bitops.h>
85 static const char *cardname =
"cops";
87 #ifdef CONFIG_COPS_DAYNA
93 static int io = 0x240;
143 static unsigned int ports[] = {
144 0x240, 0x340, 0x200, 0x210, 0x220, 0x230, 0x260,
145 0x2A0, 0x300, 0x310, 0x320, 0x330, 0x350, 0x360,
153 static int cops_irqlist[] = {
166 #define COPS_IO_EXTENT 8
181 static int cops_irq (
int ioaddr,
int board);
190 static void cops_poll (
unsigned long ltdev);
232 if (base_addr > 0x1ff) {
233 err = cops_probe1(dev, base_addr);
234 }
else if (base_addr != 0) {
242 for (port =
ports; *port && cops_probe1(dev, *port) < 0; port++)
261 .ndo_open = cops_open,
262 .ndo_stop = cops_close,
263 .ndo_start_xmit = cops_send_packet,
264 .ndo_tx_timeout = cops_timeout,
265 .ndo_do_ioctl = cops_ioctl,
266 .ndo_set_rx_mode = set_multicast_list,
277 static unsigned version_printed;
281 if(cops_debug && version_printed++ == 0)
300 dev->
irq = cops_irq(ioaddr, board);
336 lp = netdev_priv(dev);
348 printk(
"%s: %s at %#3x, using IRQ %d, in Dayna mode.\n",
349 dev->
name, cardname, ioaddr, dev->
irq);
352 printk(
"%s: %s at %#3x, IRQ %d, in Tangent mode\n",
353 dev->
name, cardname, ioaddr, dev->
irq);
355 printk(
"%s: %s at %#3x, using polled IO, in Tangent mode.\n",
356 dev->
name, cardname, ioaddr);
366 static int __init cops_irq (
int ioaddr,
int board)
379 outb(0, ioaddr+DAYNA_RESET);
380 inb(ioaddr+DAYNA_RESET);
387 outb(0, ioaddr+TANG_RESET);
390 for(i=0; cops_irqlist[
i] !=0; i++)
392 irqaddr = cops_irqlist[
i];
393 for(x = 0xFFFF; x>0; x --)
397 status = (
inb(ioaddr+DAYNA_CARD_STATUS)&3);
403 if((
inb(ioaddr+TANG_CARD_STATUS)& TANG_TX_READY) !=0)
428 cops_timer.function = cops_poll;
429 cops_timer.data = (
unsigned long)dev;
442 netif_start_queue(dev);
449 static int cops_jumpstart(
struct net_device *dev)
472 static void tangent_wait_reset(
int ioaddr)
476 while(timeout++ < 5 && (
inb(ioaddr+TANG_CARD_STATUS)&TANG_TX_READY)==0)
483 static void cops_reset(
struct net_device *dev,
int sleep)
492 outb(0, ioaddr+TANG_RESET);
494 tangent_wait_reset(ioaddr);
495 outb(0, ioaddr+TANG_CLEAR_INT);
499 outb(0, ioaddr+DAYNA_RESET);
500 inb(ioaddr+DAYNA_RESET);
507 netif_wake_queue(dev);
510 static void cops_load (
struct net_device *dev)
518 strcpy(ifr.ifr_name,
"lt0");
521 #ifdef CONFIG_COPS_DAYNA
524 ltf->
length=
sizeof(ffdrv_code);
525 ltf->
data=ffdrv_code;
529 #ifdef CONFIG_COPS_TANGENT
532 ltf->
length=
sizeof(ltdrv_code);
533 ltf->
data=ltdrv_code;
562 if((
inb(ioaddr+DAYNA_CARD_STATUS)&3)==1)
582 printk(
"%s: Uploaded firmware - %d bytes of %d bytes.\n",
586 outb(1, ioaddr+DAYNA_INT_CARD);
592 tangent_wait_reset(ioaddr);
603 static int cops_nodeid (
struct net_device *dev,
int nodeid)
611 while((
inb(ioaddr+DAYNA_CARD_STATUS)&DAYNA_TX_READY)==0)
613 outb(0, ioaddr+COPS_CLEAR_INT);
614 if((
inb(ioaddr+DAYNA_CARD_STATUS)&0x03)==DAYNA_RX_REQUEST)
621 outb(LAP_INIT, ioaddr);
622 outb(nodeid, ioaddr);
628 while(
inb(ioaddr+TANG_CARD_STATUS)&TANG_RX_READY)
630 outb(0, ioaddr+COPS_CLEAR_INT);
640 outb(LAP_INIT, ioaddr);
641 outb(nodeid, ioaddr);
648 outb(0, ioaddr+COPS_CLEAR_INT);
652 if((
inb(ioaddr+DAYNA_CARD_STATUS)&0x03)==DAYNA_RX_REQUEST)
657 if(
inb(ioaddr+TANG_CARD_STATUS)&TANG_RX_READY)
676 static void cops_poll(
unsigned long ltdev)
690 status=
inb(ioaddr+TANG_CARD_STATUS);
691 if(status & TANG_RX_READY)
693 if(status & TANG_TX_READY)
694 netif_wake_queue(dev);
695 status =
inb(ioaddr+TANG_CARD_STATUS);
696 }
while((++boguscount < 20) && (status&(TANG_RX_READY|TANG_TX_READY)));
715 lp = netdev_priv(dev);
720 outb(0, ioaddr + COPS_CLEAR_INT);
721 status=
inb(ioaddr+DAYNA_CARD_STATUS);
722 if((status&0x03)==DAYNA_RX_REQUEST)
724 netif_wake_queue(dev);
725 }
while(++boguscount < 20);
730 status=
inb(ioaddr+TANG_CARD_STATUS);
731 if(status & TANG_RX_READY)
733 if(status & TANG_TX_READY)
734 netif_wake_queue(dev);
735 status=
inb(ioaddr+TANG_CARD_STATUS);
736 }
while((++boguscount < 20) && (status&(TANG_RX_READY|TANG_TX_READY)));
762 outb(DATA_READ, ioaddr);
765 while(++boguscount<1000000)
768 if((
inb(ioaddr+DAYNA_CARD_STATUS)&0x03)==DAYNA_RX_READY)
772 if(boguscount==1000000)
775 spin_unlock_irqrestore(&lp->
lock, flags);
782 pkt_len =
inb(ioaddr) & 0xFF;
784 pkt_len =
inb(ioaddr) & 0x00FF;
785 pkt_len |= (
inb(ioaddr) << 8);
787 rsp_type=
inb(ioaddr);
790 skb = dev_alloc_skb(pkt_len);
795 dev->
stats.rx_dropped++;
798 spin_unlock_irqrestore(&lp->
lock, flags);
808 outb(1, ioaddr+DAYNA_INT_CARD);
810 spin_unlock_irqrestore(&lp->
lock, flags);
813 if(pkt_len < 0 || pkt_len > MAX_LLAP_SIZE)
817 dev->
stats.tx_errors++;
823 if(rsp_type == LAP_INIT_RSP)
831 if(rsp_type != LAP_RESPONSE)
834 dev->
stats.tx_errors++;
839 skb_reset_mac_header(skb);
841 skb_reset_transport_header(skb);
844 dev->
stats.rx_packets++;
851 static void cops_timeout(
struct net_device *dev)
856 dev->
stats.tx_errors++;
859 if((
inb(ioaddr+TANG_CARD_STATUS)&TANG_TX_READY)==0)
865 netif_wake_queue(dev);
884 netif_stop_queue(dev);
888 while((
inb(ioaddr+DAYNA_CARD_STATUS)&DAYNA_TX_READY)==0)
891 while((
inb(ioaddr+TANG_CARD_STATUS)&TANG_TX_READY)==0)
899 outb((skb->
len >> 8)&0x0FF, ioaddr);
902 outb(LAP_WRITE, ioaddr);
905 while((
inb(ioaddr+DAYNA_CARD_STATUS)&DAYNA_TX_READY)==0);
910 outb(1, ioaddr+DAYNA_INT_CARD);
912 spin_unlock_irqrestore(&lp->
lock, flags);
915 dev->
stats.tx_packets++;
925 static void set_multicast_list(
struct net_device *dev)
928 printk(
"%s: set_multicast_list executed\n", dev->
name);
945 cops_nodeid(dev, sa->
sat_addr.s_node);
980 netif_stop_queue(dev);
993 static int __init cops_module_init(
void)
999 return PTR_RET(cops_dev);
1002 static void __exit cops_module_exit(
void)
1005 cleanup_card(cops_dev);