1 /*** ltpc.c -- a driver for the LocalTalk PC card.
5 * This software may be used and distributed according to the terms
6 * of the GNU General Public License, incorporated herein by reference.
8 * This is ALPHA code at best. It may not work for you. It may
9 * damage your equipment. It may damage your relations with other
10 * users of your network. Use it at your own risk!
13 * skeleton.c by Donald Becker
14 * dummy.c by Nick Holloway and Alan Cox
15 * loopback.c by Ross Biro, Fred van Kampen, Donald Becker
16 * the netatalk source code (UMICH)
17 * lots of work on the card...
19 * I do not have access to the (proprietary) SDK that goes with the card.
20 * If you do, I don't want to know about it, and you can probably write
21 * a better driver yourself anyway. This does mean that the pieces that
22 * talk to the card are guesswork on my part, so use at your own risk!
24 * This is my first try at writing Linux networking code, and is also
25 * guesswork. Again, use at your own risk! (Although on this part, I'd
26 * welcome suggestions)
28 * This is a loadable kernel module which seems to work at my site
29 * consisting of a 1.2.13 linux box running netatalk 1.3.3, and with
30 * the kernel support from 1.3.3b2 including patches routing.patch
31 * and ddp.disappears.from.chooser. In order to run it, you will need
32 * to patch ddp.c and aarp.c in the kernel, but only a little...
34 * I'm fairly confident that while this is arguably badly written, the
35 * problems that people experience will be "higher level", that is, with
36 * complications in the netatalk code. The driver itself doesn't do
37 * anything terribly complicated -- it pretends to be an ether device
38 * as far as netatalk is concerned, strips the DDP data out of the ether
39 * frame and builds a LLAP packet to send out the card. In the other
40 * direction, it receives LLAP frames from the card and builds a fake
41 * ether packet that it then tosses up to the networking code. You can
42 * argue (correctly) that this is an ugly way to do things, but it
43 * requires a minimal amount of fooling with the code in ddp.c and aarp.c.
45 * The card will do a lot more than is used here -- I *think* it has the
46 * layers up through ATP. Even if you knew how that part works (which I
47 * don't) it would be a big job to carve up the kernel ddp code to insert
48 * things at a higher level, and probably a bad idea...
50 * There are a number of other cards that do LocalTalk on the PC. If
51 * nobody finds any insurmountable (at the netatalk level) problems
52 * here, this driver should encourage people to put some work into the
53 * other cards (some of which I gather are still commercially available)
54 * and also to put hooks for LocalTalk into the official ddp code.
56 * I welcome comments and suggestions. This is my first try at Linux
57 * networking stuff, and there are probably lots of things that I did
65 * Revision 1.1.2.1 2000/03/01 05:35:07 jgarzik
68 * Revision 1.8 1997/01/28 05:44:54 bradford
69 * Clean up for non-module a little.
70 * Hacked about a bit to clean things up - Alan Cox
71 * Probably broken it from the origina 1.8
75 * Cleaned up the initialization code to use the standard autoirq methods,
76 and to probe for things in the standard order of i/o, irq, dma. This
77 removes the "reset the reset" hack, because I couldn't figure out an
78 easy way to get the card to trigger an interrupt after it.
79 * Added support for passing configuration parameters on the kernel command
80 line and through insmod
81 * Changed the device name from "ltalk0" to "lt0", both to conform with the
82 other localtalk driver, and to clear up the inconsistency between the
83 module and the non-module versions of the driver :-)
84 * Added a bunch of comments (I was going to make some enums for the state
85 codes and the register offsets, but I'm still not sure exactly what their
87 * Don't poll anymore in interrupt-driven mode
88 * It seems to work as a module now (as of 2.1.127), but I don't think
89 I'm responsible for that...
92 * Revision 1.7 1996/12/12 03:42:33 bradford
93 * DMA alloc cribbed from 3c505.c.
95 * Revision 1.6 1996/12/12 03:18:58 bradford
96 * Added virt_to_bus; works in 2.1.13.
98 * Revision 1.5 1996/12/12 03:13:22 root
99 * xmitQel initialization -- think through better though.
101 * Revision 1.4 1996/06/18 14:55:55 root
102 * Change names to ltpc. Tabs. Took a shot at dma alloc,
103 * although more needs to be done eventually.
105 * Revision 1.3 1996/05/22 14:59:39 root
106 * Change dev->open, dev->close to track dummy.c in 1.99.(around 7)
108 * Revision 1.2 1996/05/22 14:58:24 root
109 * Change tabs mostly.
111 * Revision 1.1 1996/04/23 04:45:09 root
114 * Revision 0.16 1996/03/05 15:59:56 root
115 * Change ARPHRD_LOCALTLK definition to the "real" one.
117 * Revision 0.15 1996/03/05 06:28:30 root
118 * Changes for kernel 1.3.70. Still need a few patches to kernel, but
119 * it's getting closer.
121 * Revision 0.14 1996/02/25 17:38:32 root
122 * More cleanups. Removed query to card on get_stats.
124 * Revision 0.13 1996/02/21 16:27:40 root
125 * Refix debug_print_skb. Fix mac.raw gotcha that appeared in 1.3.65.
126 * Clean up receive code a little.
128 * Revision 0.12 1996/02/19 16:34:53 root
129 * Fix debug_print_skb. Kludge outgoing snet to 0 when using startup
130 * range. Change debug to mask: 1 for verbose, 2 for higher level stuff
131 * including packet printing, 4 for lower level (card i/o) stuff.
133 * Revision 0.11 1996/02/12 15:53:38 root
134 * Added router sends (requires new aarp.c patch)
136 * Revision 0.10 1996/02/11 00:19:35 root
137 * Change source LTALK_LOGGING debug switch to insmod ... debug=2.
139 * Revision 0.9 1996/02/10 23:59:35 root
140 * Fixed those fixes for 1.2 -- DANGER! The at.h that comes with netatalk
141 * has a *different* definition of struct sockaddr_at than the Linux kernel
142 * does. This is an "insidious and invidious" bug...
143 * (Actually the preceding comment is false -- it's the atalk.h in the
144 * ancient atalk-0.06 that's the problem)
146 * Revision 0.8 1996/02/10 19:09:00 root
147 * Merge 1.3 changes. Tested OK under 1.3.60.
149 * Revision 0.7 1996/02/10 17:56:56 root
150 * Added debug=1 parameter on insmod for debugging prints. Tried
151 * to fix timer unload on rmmod, but I don't think that's the problem.
153 * Revision 0.6 1995/12/31 19:01:09 root
154 * Clean up rmmod, irq comments per feedback from Corin Anderson (Thanks Corey!)
155 * Clean up initial probing -- sometimes the card wakes up latched in reset.
157 * Revision 0.5 1995/12/22 06:03:44 root
158 * Added comments in front and cleaned up a bit.
159 * This version sent out to people.
161 * Revision 0.4 1995/12/18 03:46:44 root
162 * Return shortDDP to longDDP fake to 0/0. Added command structs.
168 * Interrupts -- set at most one. If none are set, the driver uses
169 * polled mode. Because the card was developed in the XT era, the
170 * original documentation refers to IRQ2. Since you'll be running
171 * this on an AT (or later) class machine, that really means IRQ9.
175 * SW3 IRQ 9 (2 in original card documentation only applies to XT)
178 * DMA -- choose DMA 1 or 3, and set both corresponding switches.
186 * I/O address -- choose one.
191 /* To have some stuff logged, do
192 * insmod ltpc.o debug=1
194 * For a whole bunch of stuff, use higher numbers.
196 * The default is 0, i.e. no messages except for the probe results.
199 /* insmod-tweakable variables */
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>
213 #include <linux/interrupt.h>
214 #include <linux/ptrace.h>
215 #include <linux/ioport.h>
216 #include <linux/spinlock.h>
217 #include <linux/in.h>
218 #include <linux/string.h>
219 #include <linux/errno.h>
220 #include <linux/init.h>
221 #include <linux/netdevice.h>
222 #include <linux/etherdevice.h>
223 #include <linux/skbuff.h>
224 #include <linux/if_arp.h>
225 #include <linux/if_ltalk.h>
226 #include <linux/delay.h>
227 #include <linux/timer.h>
228 #include <linux/atalk.h>
229 #include <linux/bitops.h>
230 #include <linux/gfp.h>
232 #include <net/Space.h>
240 static DEFINE_SPINLOCK(txqueue_lock);
241 static DEFINE_SPINLOCK(mbox_lock);
243 /* function prototypes */
244 static int do_read(struct net_device *dev, void *cbuf, int cbuflen,
245 void *dbuf, int dbuflen);
246 static int sendup_buffer (struct net_device *dev);
248 /* Dma Memory related stuff, cribbed directly from 3c505.c */
250 static unsigned long dma_mem_alloc(int size)
252 int order = get_order(size);
254 return __get_dma_pages(GFP_KERNEL, order);
257 /* DMA data buffer, DMA command buffer */
258 static unsigned char *ltdmabuf;
259 static unsigned char *ltdmacbuf;
261 /* private struct, holds our appletalk address */
265 struct atalk_addr my_addr;
268 /* transmit queue element struct */
271 struct xmitQel *next;
278 unsigned char QWrite; /* read or write data */
279 unsigned char mailbox;
282 /* the transmit queue itself */
284 static struct xmitQel *xmQhd, *xmQtl;
286 static void enQ(struct xmitQel *qel)
291 spin_lock_irqsave(&txqueue_lock, flags);
298 spin_unlock_irqrestore(&txqueue_lock, flags);
300 if (debug & DEBUG_LOWER)
301 printk("enqueued a 0x%02x command\n",qel->cbuf[0]);
304 static struct xmitQel *deQ(void)
308 struct xmitQel *qel=NULL;
310 spin_lock_irqsave(&txqueue_lock, flags);
314 if(!xmQhd) xmQtl = NULL;
316 spin_unlock_irqrestore(&txqueue_lock, flags);
318 if ((debug & DEBUG_LOWER) && qel) {
320 printk(KERN_DEBUG "ltpc: dequeued command ");
323 for(i=0;i<n;i++) printk("%02x ",qel->cbuf[i]);
330 /* and... the queue elements we'll be using */
331 static struct xmitQel qels[16];
333 /* and their corresponding mailboxes */
334 static unsigned char mailbox[16];
335 static unsigned char mboxinuse[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
337 static int wait_timeout(struct net_device *dev, int c)
339 /* returns true if it stayed c */
340 /* this uses base+6, but it's ok */
343 /* twenty second or so total */
345 for(i=0;i<200000;i++) {
346 if ( c != inb_p(dev->base_addr+6) ) return 0;
349 return 1; /* timed out */
352 /* get the first free mailbox */
354 static int getmbox(void)
359 spin_lock_irqsave(&mbox_lock, flags);
360 for(i=1;i<16;i++) if(!mboxinuse[i]) {
362 spin_unlock_irqrestore(&mbox_lock, flags);
365 spin_unlock_irqrestore(&mbox_lock, flags);
369 /* read a command from the card */
370 static void handlefc(struct net_device *dev)
372 /* called *only* from idle, non-reentrant */
374 int base = dev->base_addr;
378 flags=claim_dma_lock();
381 set_dma_mode(dma,DMA_MODE_READ);
382 set_dma_addr(dma,virt_to_bus(ltdmacbuf));
383 set_dma_count(dma,50);
385 release_dma_lock(flags);
390 if ( wait_timeout(dev,0xfc) ) printk("timed out in handlefc\n");
393 /* read data from the card */
394 static void handlefd(struct net_device *dev)
397 int base = dev->base_addr;
400 flags=claim_dma_lock();
403 set_dma_mode(dma,DMA_MODE_READ);
404 set_dma_addr(dma,virt_to_bus(ltdmabuf));
405 set_dma_count(dma,800);
407 release_dma_lock(flags);
412 if ( wait_timeout(dev,0xfd) ) printk("timed out in handlefd\n");
416 static void handlewrite(struct net_device *dev)
418 /* called *only* from idle, non-reentrant */
419 /* on entry, 0xfb and ltdmabuf holds data */
421 int base = dev->base_addr;
424 flags=claim_dma_lock();
427 set_dma_mode(dma,DMA_MODE_WRITE);
428 set_dma_addr(dma,virt_to_bus(ltdmabuf));
429 set_dma_count(dma,800);
431 release_dma_lock(flags);
436 if ( wait_timeout(dev,0xfb) ) {
437 flags=claim_dma_lock();
438 printk("timed out in handlewrite, dma res %d\n",
439 get_dma_residue(dev->dma) );
440 release_dma_lock(flags);
444 static void handleread(struct net_device *dev)
447 /* on exit, ltdmabuf holds data */
449 int base = dev->base_addr;
453 flags=claim_dma_lock();
456 set_dma_mode(dma,DMA_MODE_READ);
457 set_dma_addr(dma,virt_to_bus(ltdmabuf));
458 set_dma_count(dma,800);
460 release_dma_lock(flags);
464 if ( wait_timeout(dev,0xfb) ) printk("timed out in handleread\n");
467 static void handlecommand(struct net_device *dev)
469 /* on entry, 0xfa and ltdmacbuf holds command */
471 int base = dev->base_addr;
474 flags=claim_dma_lock();
477 set_dma_mode(dma,DMA_MODE_WRITE);
478 set_dma_addr(dma,virt_to_bus(ltdmacbuf));
479 set_dma_count(dma,50);
481 release_dma_lock(flags);
484 if ( wait_timeout(dev,0xfa) ) printk("timed out in handlecommand\n");
487 /* ready made command for getting the result from the card */
488 static unsigned char rescbuf[2] = {LT_GETRESULT,0};
489 static unsigned char resdbuf[2];
493 /* idle expects to be called with the IRQ line high -- either because of
494 * an interrupt, or because the line is tri-stated
497 static void idle(struct net_device *dev)
501 /* FIXME This is initialized to shut the warning up, but I need to
502 * think this through again.
504 struct xmitQel *q = NULL;
507 int base = dev->base_addr;
509 spin_lock_irqsave(&txqueue_lock, flags);
511 spin_unlock_irqrestore(&txqueue_lock, flags);
515 spin_unlock_irqrestore(&txqueue_lock, flags);
517 /* this tri-states the IRQ line */
518 (void) inb_p(base+6);
524 printk("idle: looped too many times\n");
528 state = inb_p(base+6);
529 if (state != inb_p(base+6)) goto loop;
533 /* incoming command */
534 if (debug & DEBUG_LOWER) printk("idle: fc\n");
539 if(debug & DEBUG_LOWER) printk("idle: fd\n");
544 if (debug & DEBUG_LOWER) printk("idle: f9\n");
547 qels[0].cbuf = rescbuf;
549 qels[0].dbuf = resdbuf;
555 inb_p(dev->base_addr+1);
556 inb_p(dev->base_addr+0);
557 if( wait_timeout(dev,0xf9) )
558 printk("timed out idle f9\n");
563 inb_p(dev->base_addr+1);
564 inb_p(dev->base_addr+0);
565 if(wait_timeout(dev,0xf8) )
566 printk("timed out idle f8\n");
572 /* waiting for command */
573 if(debug & DEBUG_LOWER) printk("idle: fa\n");
576 memcpy(ltdmacbuf,q->cbuf,q->cbuflen);
577 ltdmacbuf[1] = q->mailbox;
580 printk("ltpc: sent command ");
584 printk("%02x ",ltdmacbuf[i]);
590 if (0xfa == inb_p(base + 6)) {
591 /* we timed out, so return */
595 /* we don't seem to have a command */
598 qels[0].cbuf = rescbuf;
600 qels[0].dbuf = resdbuf;
606 printk("trouble: response command already queued\n");
612 /* data transfer ready */
613 if(debug & DEBUG_LOWER) printk("idle: fb\n");
615 memcpy(ltdmabuf,q->dbuf,q->dbuflen);
619 /* non-zero mailbox numbers are for
620 commmands, 0 is for GETRESULT
623 memcpy(q->dbuf,ltdmabuf,q->dbuflen);
625 /* this was a result */
626 mailbox[ 0x0f & ltdmabuf[0] ] = ltdmabuf[1];
637 /* now set the interrupts back as appropriate */
638 /* the first read takes it out of tri-state (but still high) */
639 /* the second resets it */
640 /* note that after this point, any read of base+6 will
641 trigger an interrupt */
650 static int do_write(struct net_device *dev, void *cbuf, int cbuflen,
651 void *dbuf, int dbuflen)
659 qels[i].cbuflen = cbuflen;
661 qels[i].dbuflen = dbuflen;
663 qels[i].mailbox = i; /* this should be initted rather */
670 printk("ltpc: could not allocate mbox\n");
674 static int do_read(struct net_device *dev, void *cbuf, int cbuflen,
675 void *dbuf, int dbuflen)
683 qels[i].cbuflen = cbuflen;
685 qels[i].dbuflen = dbuflen;
687 qels[i].mailbox = i; /* this should be initted rather */
694 printk("ltpc: could not allocate mbox\n");
698 /* end of idle handlers -- what should be seen is do_read, do_write */
700 static struct timer_list ltpc_timer;
701 static struct net_device *ltpc_timer_dev;
703 static netdev_tx_t ltpc_xmit(struct sk_buff *skb, struct net_device *dev);
705 static int read_30 ( struct net_device *dev)
708 c.getflags.command = LT_GETFLAGS;
709 return do_read(dev, &c, sizeof(c.getflags),&c,0);
712 static int set_30 (struct net_device *dev,int x)
715 c.setflags.command = LT_SETFLAGS;
716 c.setflags.flags = x;
717 return do_write(dev, &c, sizeof(c.setflags),&c,0);
720 /* LLAP to DDP translation */
722 static int sendup_buffer (struct net_device *dev)
724 /* on entry, command is in ltdmacbuf, data in ltdmabuf */
725 /* called from idle, non-reentrant */
727 int dnode, snode, llaptype, len;
730 struct lt_rcvlap *ltc = (struct lt_rcvlap *) ltdmacbuf;
732 if (ltc->command != LT_RCVLAP) {
733 printk("unknown command 0x%02x from ltpc card\n",ltc->command);
738 llaptype = ltc->laptype;
743 sklen += 8; /* correct for short ddp */
745 printk(KERN_INFO "%s: nonsense length in ltpc command 0x14: 0x%08x\n",
750 if ( (llaptype==0) || (llaptype>2) ) {
751 printk(KERN_INFO "%s: unknown LLAP type: %d\n",dev->name,llaptype);
756 skb = dev_alloc_skb(3+sklen);
759 printk("%s: dropping packet due to memory squeeze.\n",
768 skb->protocol = htons(ETH_P_LOCALTALK);
769 /* add LLAP header */
770 skb->data[0] = dnode;
771 skb->data[1] = snode;
772 skb->data[2] = llaptype;
773 skb_reset_mac_header(skb); /* save pointer to llap header */
776 /* copy ddp(s,e)hdr + contents */
777 skb_copy_to_linear_data(skb, ltdmabuf, len);
779 skb_reset_transport_header(skb);
781 dev->stats.rx_packets++;
782 dev->stats.rx_bytes += skb->len;
784 /* toss it onwards */
789 /* the handler for the board interrupt */
792 ltpc_interrupt(int irq, void *dev_id)
794 struct net_device *dev = dev_id;
797 printk("ltpc_interrupt: unknown device.\n");
801 inb_p(dev->base_addr+6); /* disable further interrupts from board */
803 idle(dev); /* handle whatever is coming in */
805 /* idle re-enables interrupts from board */
812 * The ioctls that the driver responds to are:
814 * SIOCSIFADDR -- do probe using the passed node hint.
815 * SIOCGIFADDR -- return net, node.
817 * some of this stuff should be done elsewhere.
821 static int ltpc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
823 struct sockaddr_at *sa = (struct sockaddr_at *) &ifr->ifr_addr;
824 /* we'll keep the localtalk node address in dev->pa_addr */
825 struct ltpc_private *ltpc_priv = netdev_priv(dev);
826 struct atalk_addr *aa = <pc_priv->my_addr;
830 if(debug & DEBUG_VERBOSE) printk("ltpc_ioctl called\n");
835 aa->s_net = sa->sat_addr.s_net;
837 /* this does the probe and returns the node addr */
839 c.hint = sa->sat_addr.s_node;
841 aa->s_node = do_read(dev,&c,sizeof(c),&c,0);
843 /* get all llap frames raw */
844 ltflags = read_30(dev);
845 ltflags |= LT_FLAG_ALLLAP;
846 set_30 (dev,ltflags);
848 dev->broadcast[0] = 0xFF;
850 dev_addr_set(dev, &aa->s_node);
856 sa->sat_addr.s_net = aa->s_net;
857 sa->sat_addr.s_node = aa->s_node;
866 static void set_multicast_list(struct net_device *dev)
868 /* This needs to be present to keep netatalk happy. */
869 /* Actually netatalk needs fixing! */
872 static int ltpc_poll_counter;
874 static void ltpc_poll(struct timer_list *unused)
876 del_timer(<pc_timer);
878 if(debug & DEBUG_VERBOSE) {
879 if (!ltpc_poll_counter) {
880 ltpc_poll_counter = 50;
881 printk("ltpc poll is alive\n");
886 /* poll 20 times per second */
887 idle(ltpc_timer_dev);
888 ltpc_timer.expires = jiffies + HZ/20;
889 add_timer(<pc_timer);
892 /* DDP to LLAP translation */
894 static netdev_tx_t ltpc_xmit(struct sk_buff *skb, struct net_device *dev)
896 /* in kernel 1.3.xx, on entry skb->data points to ddp header,
897 * and skb->len is the length of the ddp data + ddp header
900 struct lt_sendlap cbuf;
903 cbuf.command = LT_SENDLAP;
904 cbuf.dnode = skb->data[0];
905 cbuf.laptype = skb->data[2];
906 skb_pull(skb,3); /* skip past LLAP header */
907 cbuf.length = skb->len; /* this is host order */
908 skb_reset_transport_header(skb);
910 if(debug & DEBUG_UPPER) {
913 printk("%02x ",((unsigned char *)&cbuf)[i]);
917 hdr = skb_transport_header(skb);
918 do_write(dev, &cbuf, sizeof(cbuf), hdr, skb->len);
920 if(debug & DEBUG_UPPER) {
921 printk("sent %d ddp bytes\n",skb->len);
922 for (i = 0; i < skb->len; i++)
923 printk("%02x ", hdr[i]);
927 dev->stats.tx_packets++;
928 dev->stats.tx_bytes += skb->len;
934 /* initialization stuff */
936 static int __init ltpc_probe_dma(int base, int dma)
938 int want = (dma == 3) ? 2 : (dma == 1) ? 1 : 3;
939 unsigned long timeout;
943 if (request_dma(1,"ltpc")) {
949 set_dma_mode(1,DMA_MODE_WRITE);
950 set_dma_addr(1,virt_to_bus(ltdmabuf));
951 set_dma_count(1,sizeof(struct lt_mem));
957 if (request_dma(3,"ltpc")) {
963 set_dma_mode(3,DMA_MODE_WRITE);
964 set_dma_addr(3,virt_to_bus(ltdmabuf));
965 set_dma_count(3,sizeof(struct lt_mem));
972 /* FIXME -- do timings better! */
974 ltdmabuf[0] = LT_READMEM;
975 ltdmabuf[1] = 1; /* mailbox */
976 ltdmabuf[2] = 0; ltdmabuf[3] = 0; /* address */
977 ltdmabuf[4] = 0; ltdmabuf[5] = 1; /* read 0x0100 bytes */
978 ltdmabuf[6] = 0; /* dunno if this is necessary */
982 timeout = jiffies+100*HZ/100;
983 while(time_before(jiffies, timeout)) {
984 if ( 0xfa == inb_p(io+6) ) break;
989 while(time_before(jiffies, timeout)) {
990 if ( 0xfb == inb_p(io+6) ) break;
993 /* release the other dma channel (if we opened both of them) */
995 if ((want & 2) && (get_dma_residue(3)==sizeof(struct lt_mem))) {
1000 if ((want & 1) && (get_dma_residue(1)==sizeof(struct lt_mem))) {
1008 return (want & 2) ? 3 : 1;
1011 static const struct net_device_ops ltpc_netdev = {
1012 .ndo_start_xmit = ltpc_xmit,
1013 .ndo_do_ioctl = ltpc_ioctl,
1014 .ndo_set_rx_mode = set_multicast_list,
1017 static struct net_device * __init ltpc_probe(void)
1019 struct net_device *dev;
1024 unsigned long timeout;
1026 dev = alloc_ltalkdev(sizeof(struct ltpc_private));
1030 /* probe for the I/O port address */
1032 if (io != 0x240 && request_region(0x220,8,"ltpc")) {
1034 if ( (x!=0xff) && (x>=0xf0) ) {
1038 release_region(0x220,8);
1040 if (io != 0x220 && request_region(0x240,8,"ltpc")) {
1042 if ( (y!=0xff) && (y>=0xf0) ){
1046 release_region(0x240,8);
1049 /* give up in despair */
1050 printk(KERN_ERR "LocalTalk card not found; 220 = %02x, 240 = %02x.\n", x,y);
1055 /* probe for the IRQ line */
1057 unsigned long irq_mask;
1059 irq_mask = probe_irq_on();
1060 /* reset the interrupt line */
1063 /* trigger an interrupt (I hope) */
1066 autoirq = probe_irq_off(irq_mask);
1069 printk(KERN_ERR "ltpc: probe at %#x failed to detect IRQ line.\n", io);
1075 /* allocate a DMA buffer */
1076 ltdmabuf = (unsigned char *) dma_mem_alloc(1000);
1078 printk(KERN_ERR "ltpc: mem alloc failed\n");
1083 ltdmacbuf = <dmabuf[800];
1085 if(debug & DEBUG_VERBOSE) {
1086 printk("ltdmabuf pointer %08lx\n",(unsigned long) ltdmabuf);
1089 /* reset the card */
1098 inb_p(io+7); /* clear reset */
1101 inb_p(io+5); /* enable dma */
1102 inb_p(io+6); /* tri-state interrupt line */
1106 /* now, figure out which dma channel we're using, unless it's
1107 already been specified */
1108 /* well, 0 is a legal DMA channel, but the LTPC card doesn't
1110 dma = ltpc_probe_dma(io, dma);
1111 if (!dma) { /* no dma channel */
1112 printk(KERN_ERR "No DMA channel found on ltpc card.\n");
1117 /* print out friendly message */
1119 printk(KERN_INFO "Apple/Farallon LocalTalk-PC card at %03x, IR%d, DMA%d.\n",io,irq,dma);
1121 printk(KERN_INFO "Apple/Farallon LocalTalk-PC card at %03x, DMA%d. Using polled mode.\n",io,dma);
1123 dev->netdev_ops = <pc_netdev;
1124 dev->base_addr = io;
1128 /* the card will want to send a result at this point */
1129 /* (I think... leaving out this part makes the kernel crash,
1130 so I put it back in...) */
1135 set_dma_mode(dma,DMA_MODE_READ);
1136 set_dma_addr(dma,virt_to_bus(ltdmabuf));
1137 set_dma_count(dma,0x100);
1139 release_dma_lock(f);
1143 timeout = jiffies+100*HZ/100;
1145 while(time_before(jiffies, timeout)) {
1146 if( 0xf9 == inb_p(io+6))
1151 if(debug & DEBUG_VERBOSE) {
1152 printk("setting up timer and irq\n");
1155 /* grab it and don't let go :-) */
1156 if (irq && request_irq( irq, ltpc_interrupt, 0, "ltpc", dev) >= 0)
1158 (void) inb_p(io+7); /* enable interrupts from board */
1159 (void) inb_p(io+7); /* and reset irq line */
1162 printk(KERN_ERR "ltpc: IRQ already in use, using polled mode.\n");
1164 /* polled mode -- 20 times per second */
1165 /* this is really, really slow... should it poll more often? */
1166 ltpc_timer_dev = dev;
1167 timer_setup(<pc_timer, ltpc_poll, 0);
1169 ltpc_timer.expires = jiffies + HZ/20;
1170 add_timer(<pc_timer);
1172 err = register_netdev(dev);
1178 del_timer_sync(<pc_timer);
1180 free_irq(dev->irq, dev);
1182 free_pages((unsigned long)ltdmabuf, get_order(1000));
1184 release_region(io, 8);
1188 return ERR_PTR(err);
1192 /* handles "ltpc=io,irq,dma" kernel command lines */
1193 static int __init ltpc_setup(char *str)
1197 str = get_options(str, ARRAY_SIZE(ints), ints);
1200 if (str && !strncmp(str, "auto", 4)) {
1201 /* do nothing :-) */
1206 "ltpc: usage: ltpc=auto|iobase[,irq[,dma]]\n");
1217 /* ignore any other parameters */
1222 __setup("ltpc=", ltpc_setup);
1225 static struct net_device *dev_ltpc;
1227 MODULE_LICENSE("GPL");
1228 module_param(debug, int, 0);
1229 module_param_hw(io, int, ioport, 0);
1230 module_param_hw(irq, int, irq, 0);
1231 module_param_hw(dma, int, dma, 0);
1234 static int __init ltpc_module_init(void)
1238 "ltpc: Autoprobing is not recommended for modules\n");
1240 dev_ltpc = ltpc_probe();
1241 return PTR_ERR_OR_ZERO(dev_ltpc);
1243 module_init(ltpc_module_init);
1245 static void __exit ltpc_cleanup(void)
1248 if(debug & DEBUG_VERBOSE) printk("unregister_netdev\n");
1249 unregister_netdev(dev_ltpc);
1251 del_timer_sync(<pc_timer);
1253 if(debug & DEBUG_VERBOSE) printk("freeing irq\n");
1256 free_irq(dev_ltpc->irq, dev_ltpc);
1258 if(debug & DEBUG_VERBOSE) printk("freeing dma\n");
1261 free_dma(dev_ltpc->dma);
1263 if(debug & DEBUG_VERBOSE) printk("freeing ioaddr\n");
1265 if (dev_ltpc->base_addr)
1266 release_region(dev_ltpc->base_addr,8);
1268 free_netdev(dev_ltpc);
1270 if(debug & DEBUG_VERBOSE) printk("free_pages\n");
1272 free_pages( (unsigned long) ltdmabuf, get_order(1000));
1274 if(debug & DEBUG_VERBOSE) printk("returning from cleanup_module\n");
1277 module_exit(ltpc_cleanup);