201 #define DEBUG_VERBOSE 1
202 #define DEBUG_UPPER 2
203 #define DEBUG_LOWER 4
209 #include <linux/module.h>
210 #include <linux/kernel.h>
211 #include <linux/types.h>
212 #include <linux/fcntl.h>
214 #include <linux/ptrace.h>
217 #include <linux/in.h>
218 #include <linux/string.h>
219 #include <linux/errno.h>
221 #include <linux/netdevice.h>
224 #include <linux/if_arp.h>
225 #include <linux/if_ltalk.h>
228 #include <linux/atalk.h>
229 #include <linux/bitops.h>
243 void *dbuf,
int dbuflen);
248 static unsigned long dma_mem_alloc(
int size)
256 static unsigned char *ltdmabuf;
257 static unsigned char *ltdmacbuf;
282 static struct xmitQel *xmQhd, *xmQtl;
284 static void enQ(
struct xmitQel *qel)
296 spin_unlock_irqrestore(&txqueue_lock, flags);
299 printk(
"enqueued a 0x%02x command\n",qel->
cbuf[0]);
302 static struct xmitQel *deQ(
void)
312 if(!xmQhd) xmQtl =
NULL;
314 spin_unlock_irqrestore(&txqueue_lock, flags);
329 static struct xmitQel qels[16];
332 static unsigned char mailbox[16];
333 static unsigned char mboxinuse[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
343 for(i=0;i<200000;i++) {
352 static int getmbox(
void)
358 for(i=1;i<16;i++)
if(!mboxinuse[i]) {
360 spin_unlock_irqrestore(&mbox_lock, flags);
363 spin_unlock_irqrestore(&mbox_lock, flags);
414 static void handlewrite(
struct net_device *dev)
436 printk(
"timed out in handlewrite, dma res %d\n",
442 static void handleread(
struct net_device *dev)
465 static void handlecommand(
struct net_device *dev)
487 static unsigned char resdbuf[2];
509 spin_unlock_irqrestore(&txqueue_lock, flags);
513 spin_unlock_irqrestore(&txqueue_lock, flags);
522 printk(
"idle: looped too many times\n");
526 state =
inb_p(base+6);
527 if (state !=
inb_p(base+6))
goto loop;
545 qels[0].cbuf = rescbuf;
547 qels[0].dbuf = resdbuf;
556 printk(
"timed out idle f9\n");
564 printk(
"timed out idle f8\n");
578 printk(
"ltpc: sent command ");
582 printk(
"%02x ",ltdmacbuf[i]);
586 if(0xfa==
inb_p(base+6)) {
594 qels[0].cbuf = rescbuf;
596 qels[0].dbuf = resdbuf;
602 printk(
"trouble: response command already queued\n");
622 mailbox[ 0x0f & ltdmabuf[0] ] = ltdmabuf[1];
666 printk(
"ltpc: could not allocate mbox\n");
671 void *dbuf,
int dbuflen)
690 printk(
"ltpc: could not allocate mbox\n");
717 static int sendup_buffer (
struct net_device *dev)
728 printk(
"unknown command 0x%02x from ltpc card\n",ltc->
command);
745 if ( (llaptype==0) || (llaptype>2) ) {
751 skb = dev_alloc_skb(3+sklen);
754 printk(
"%s: dropping packet due to memory squeeze.\n",
767 skb->
data[2] = llaptype;
768 skb_reset_mac_header(skb);
772 skb_copy_to_linear_data(skb, ltdmabuf, len);
774 skb_reset_transport_header(skb);
776 dev->
stats.rx_packets++;
787 ltpc_interrupt(
int irq,
void *
dev_id)
792 printk(
"ltpc_interrupt: unknown device.\n");
839 ltflags = read_30(dev);
841 set_30 (dev,ltflags);
862 static void set_multicast_list(
struct net_device *dev)
868 static int ltpc_poll_counter;
870 static void ltpc_poll(
unsigned long l)
876 if(
debug & DEBUG_VERBOSE) {
877 if (!ltpc_poll_counter) {
878 ltpc_poll_counter = 50;
879 printk(
"ltpc poll is alive\n");
906 cbuf.dnode = skb->
data[0];
907 cbuf.laptype = skb->
data[2];
909 cbuf.length = skb->
len;
910 skb_reset_transport_header(skb);
915 printk(
"%02x ",((
unsigned char *)&cbuf)[i]);
919 hdr = skb_transport_header(skb);
922 if(
debug & DEBUG_UPPER) {
924 for (i = 0; i < skb->
len; i++)
929 dev->
stats.tx_packets++;
938 static int __init ltpc_probe_dma(
int base,
int dma)
940 int want = (dma == 3) ? 2 : (dma == 1) ? 1 : 3;
978 ltdmabuf[2] = 0; ltdmabuf[3] = 0;
979 ltdmabuf[4] = 0; ltdmabuf[5] = 1;
986 if ( 0xfa ==
inb_p(
io+6) )
break;
992 if ( 0xfb ==
inb_p(
io+6) )
break;
1010 return (want & 2) ? 3 : 1;
1014 .ndo_start_xmit = ltpc_xmit,
1015 .ndo_do_ioctl = ltpc_ioctl,
1016 .ndo_set_rx_mode = set_multicast_list,
1026 unsigned long timeout;
1036 if ( (x!=0xff) && (x>=0xf0) ) {
1044 if ( (
y!=0xff) && (
y>=0xf0) ){
1052 printk(
KERN_ERR "LocalTalk card not found; 220 = %02x, 240 = %02x.\n", x,
y);
1059 unsigned long irq_mask;
1078 ltdmabuf = (
unsigned char *) dma_mem_alloc(1000);
1085 ltdmacbuf = <dmabuf[800];
1087 if(
debug & DEBUG_VERBOSE) {
1088 printk(
"ltdmabuf pointer %08lx\n",(
unsigned long) ltdmabuf);
1112 dma = ltpc_probe_dma(
io, dma);
1121 printk(
KERN_INFO "Apple/Farallon LocalTalk-PC card at %03x, IR%d, DMA%d.\n",
io,irq,dma);
1123 printk(
KERN_INFO "Apple/Farallon LocalTalk-PC card at %03x, DMA%d. Using polled mode.\n",
io,dma);
1153 if(
debug & DEBUG_VERBOSE) {
1154 printk(
"setting up timer and irq\n");
1158 if (irq &&
request_irq( irq, ltpc_interrupt, 0,
"ltpc", dev) >= 0)
1164 printk(
KERN_ERR "ltpc: IRQ already in use, using polled mode.\n");
1169 ltpc_timer.function=ltpc_poll;
1170 ltpc_timer.data = (
unsigned long) dev;
1191 return ERR_PTR(err);
1203 if (str && !
strncmp(str,
"auto", 4)) {
1209 "ltpc: usage: ltpc=auto|iobase[,irq[,dma]]\n");
1239 static int __init ltpc_module_init(
void)
1243 "ltpc: Autoprobing is not recommended for modules\n");
1246 return PTR_RET(dev_ltpc);
1251 static void __exit ltpc_cleanup(
void)
1254 if(
debug & DEBUG_VERBOSE)
printk(
"unregister_netdev\n");
1257 ltpc_timer.data = 0;
1261 if(
debug & DEBUG_VERBOSE)
printk(
"freeing irq\n");
1266 if(
debug & DEBUG_VERBOSE)
printk(
"freeing dma\n");
1271 if(
debug & DEBUG_VERBOSE)
printk(
"freeing ioaddr\n");
1282 if(
debug & DEBUG_VERBOSE)
printk(
"returning from cleanup_module\n");