1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200static int debug;
201#define DEBUG_VERBOSE 1
202#define DEBUG_UPPER 2
203#define DEBUG_LOWER 4
204
205static int io;
206static int irq;
207static int dma;
208
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>
231
232#include <asm/system.h>
233#include <asm/dma.h>
234#include <asm/io.h>
235
236
237#include "ltpc.h"
238
239static DEFINE_SPINLOCK(txqueue_lock);
240static DEFINE_SPINLOCK(mbox_lock);
241
242
243static int do_read(struct net_device *dev, void *cbuf, int cbuflen,
244 void *dbuf, int dbuflen);
245static int sendup_buffer (struct net_device *dev);
246
247
248
249static unsigned long dma_mem_alloc(int size)
250{
251 int order = get_order(size);
252
253 return __get_dma_pages(GFP_KERNEL, order);
254}
255
256
257static unsigned char *ltdmabuf;
258static unsigned char *ltdmacbuf;
259
260
261
262struct ltpc_private
263{
264 struct atalk_addr my_addr;
265};
266
267
268
269struct xmitQel {
270 struct xmitQel *next;
271
272 unsigned char *cbuf;
273 short cbuflen;
274
275 unsigned char *dbuf;
276 short dbuflen;
277 unsigned char QWrite;
278 unsigned char mailbox;
279};
280
281
282
283static struct xmitQel *xmQhd, *xmQtl;
284
285static void enQ(struct xmitQel *qel)
286{
287 unsigned long flags;
288 qel->next = NULL;
289
290 spin_lock_irqsave(&txqueue_lock, flags);
291 if (xmQtl) {
292 xmQtl->next = qel;
293 } else {
294 xmQhd = qel;
295 }
296 xmQtl = qel;
297 spin_unlock_irqrestore(&txqueue_lock, flags);
298
299 if (debug & DEBUG_LOWER)
300 printk("enqueued a 0x%02x command\n",qel->cbuf[0]);
301}
302
303static struct xmitQel *deQ(void)
304{
305 unsigned long flags;
306 int i;
307 struct xmitQel *qel=NULL;
308
309 spin_lock_irqsave(&txqueue_lock, flags);
310 if (xmQhd) {
311 qel = xmQhd;
312 xmQhd = qel->next;
313 if(!xmQhd) xmQtl = NULL;
314 }
315 spin_unlock_irqrestore(&txqueue_lock, flags);
316
317 if ((debug & DEBUG_LOWER) && qel) {
318 int n;
319 printk(KERN_DEBUG "ltpc: dequeued command ");
320 n = qel->cbuflen;
321 if (n>100) n=100;
322 for(i=0;i<n;i++) printk("%02x ",qel->cbuf[i]);
323 printk("\n");
324 }
325
326 return qel;
327}
328
329
330static struct xmitQel qels[16];
331
332
333static unsigned char mailbox[16];
334static unsigned char mboxinuse[16] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
335
336static int wait_timeout(struct net_device *dev, int c)
337{
338
339
340 int i;
341
342
343
344 for(i=0;i<200000;i++) {
345 if ( c != inb_p(dev->base_addr+6) ) return 0;
346 udelay(100);
347 }
348 return 1;
349}
350
351
352
353static int getmbox(void)
354{
355 unsigned long flags;
356 int i;
357
358 spin_lock_irqsave(&mbox_lock, flags);
359 for(i=1;i<16;i++) if(!mboxinuse[i]) {
360 mboxinuse[i]=1;
361 spin_unlock_irqrestore(&mbox_lock, flags);
362 return i;
363 }
364 spin_unlock_irqrestore(&mbox_lock, flags);
365 return 0;
366}
367
368
369static void handlefc(struct net_device *dev)
370{
371
372 int dma = dev->dma;
373 int base = dev->base_addr;
374 unsigned long flags;
375
376
377 flags=claim_dma_lock();
378 disable_dma(dma);
379 clear_dma_ff(dma);
380 set_dma_mode(dma,DMA_MODE_READ);
381 set_dma_addr(dma,virt_to_bus(ltdmacbuf));
382 set_dma_count(dma,50);
383 enable_dma(dma);
384 release_dma_lock(flags);
385
386 inb_p(base+3);
387 inb_p(base+2);
388
389 if ( wait_timeout(dev,0xfc) ) printk("timed out in handlefc\n");
390}
391
392
393static void handlefd(struct net_device *dev)
394{
395 int dma = dev->dma;
396 int base = dev->base_addr;
397 unsigned long flags;
398
399 flags=claim_dma_lock();
400 disable_dma(dma);
401 clear_dma_ff(dma);
402 set_dma_mode(dma,DMA_MODE_READ);
403 set_dma_addr(dma,virt_to_bus(ltdmabuf));
404 set_dma_count(dma,800);
405 enable_dma(dma);
406 release_dma_lock(flags);
407
408 inb_p(base+3);
409 inb_p(base+2);
410
411 if ( wait_timeout(dev,0xfd) ) printk("timed out in handlefd\n");
412 sendup_buffer(dev);
413}
414
415static void handlewrite(struct net_device *dev)
416{
417
418
419 int dma = dev->dma;
420 int base = dev->base_addr;
421 unsigned long flags;
422
423 flags=claim_dma_lock();
424 disable_dma(dma);
425 clear_dma_ff(dma);
426 set_dma_mode(dma,DMA_MODE_WRITE);
427 set_dma_addr(dma,virt_to_bus(ltdmabuf));
428 set_dma_count(dma,800);
429 enable_dma(dma);
430 release_dma_lock(flags);
431
432 inb_p(base+3);
433 inb_p(base+2);
434
435 if ( wait_timeout(dev,0xfb) ) {
436 flags=claim_dma_lock();
437 printk("timed out in handlewrite, dma res %d\n",
438 get_dma_residue(dev->dma) );
439 release_dma_lock(flags);
440 }
441}
442
443static void handleread(struct net_device *dev)
444{
445
446
447 int dma = dev->dma;
448 int base = dev->base_addr;
449 unsigned long flags;
450
451
452 flags=claim_dma_lock();
453 disable_dma(dma);
454 clear_dma_ff(dma);
455 set_dma_mode(dma,DMA_MODE_READ);
456 set_dma_addr(dma,virt_to_bus(ltdmabuf));
457 set_dma_count(dma,800);
458 enable_dma(dma);
459 release_dma_lock(flags);
460
461 inb_p(base+3);
462 inb_p(base+2);
463 if ( wait_timeout(dev,0xfb) ) printk("timed out in handleread\n");
464}
465
466static void handlecommand(struct net_device *dev)
467{
468
469 int dma = dev->dma;
470 int base = dev->base_addr;
471 unsigned long flags;
472
473 flags=claim_dma_lock();
474 disable_dma(dma);
475 clear_dma_ff(dma);
476 set_dma_mode(dma,DMA_MODE_WRITE);
477 set_dma_addr(dma,virt_to_bus(ltdmacbuf));
478 set_dma_count(dma,50);
479 enable_dma(dma);
480 release_dma_lock(flags);
481 inb_p(base+3);
482 inb_p(base+2);
483 if ( wait_timeout(dev,0xfa) ) printk("timed out in handlecommand\n");
484}
485
486
487static unsigned char rescbuf[2] = {LT_GETRESULT,0};
488static unsigned char resdbuf[2];
489
490static int QInIdle;
491
492
493
494
495
496static void idle(struct net_device *dev)
497{
498 unsigned long flags;
499 int state;
500
501
502
503 struct xmitQel *q = NULL;
504 int oops;
505 int i;
506 int base = dev->base_addr;
507
508 spin_lock_irqsave(&txqueue_lock, flags);
509 if(QInIdle) {
510 spin_unlock_irqrestore(&txqueue_lock, flags);
511 return;
512 }
513 QInIdle = 1;
514 spin_unlock_irqrestore(&txqueue_lock, flags);
515
516
517 (void) inb_p(base+6);
518
519 oops = 100;
520
521loop:
522 if (0>oops--) {
523 printk("idle: looped too many times\n");
524 goto done;
525 }
526
527 state = inb_p(base+6);
528 if (state != inb_p(base+6)) goto loop;
529
530 switch(state) {
531 case 0xfc:
532
533 if (debug & DEBUG_LOWER) printk("idle: fc\n");
534 handlefc(dev);
535 break;
536 case 0xfd:
537
538 if(debug & DEBUG_LOWER) printk("idle: fd\n");
539 handlefd(dev);
540 break;
541 case 0xf9:
542
543 if (debug & DEBUG_LOWER) printk("idle: f9\n");
544 if(!mboxinuse[0]) {
545 mboxinuse[0] = 1;
546 qels[0].cbuf = rescbuf;
547 qels[0].cbuflen = 2;
548 qels[0].dbuf = resdbuf;
549 qels[0].dbuflen = 2;
550 qels[0].QWrite = 0;
551 qels[0].mailbox = 0;
552 enQ(&qels[0]);
553 }
554 inb_p(dev->base_addr+1);
555 inb_p(dev->base_addr+0);
556 if( wait_timeout(dev,0xf9) )
557 printk("timed out idle f9\n");
558 break;
559 case 0xf8:
560
561 if (xmQhd) {
562 inb_p(dev->base_addr+1);
563 inb_p(dev->base_addr+0);
564 if(wait_timeout(dev,0xf8) )
565 printk("timed out idle f8\n");
566 } else {
567 goto done;
568 }
569 break;
570 case 0xfa:
571
572 if(debug & DEBUG_LOWER) printk("idle: fa\n");
573 if (xmQhd) {
574 q=deQ();
575 memcpy(ltdmacbuf,q->cbuf,q->cbuflen);
576 ltdmacbuf[1] = q->mailbox;
577 if (debug>1) {
578 int n;
579 printk("ltpc: sent command ");
580 n = q->cbuflen;
581 if (n>100) n=100;
582 for(i=0;i<n;i++)
583 printk("%02x ",ltdmacbuf[i]);
584 printk("\n");
585 }
586 handlecommand(dev);
587 if(0xfa==inb_p(base+6)) {
588
589 goto done;
590 }
591 } else {
592
593 if (!mboxinuse[0]) {
594 mboxinuse[0] = 1;
595 qels[0].cbuf = rescbuf;
596 qels[0].cbuflen = 2;
597 qels[0].dbuf = resdbuf;
598 qels[0].dbuflen = 2;
599 qels[0].QWrite = 0;
600 qels[0].mailbox = 0;
601 enQ(&qels[0]);
602 } else {
603 printk("trouble: response command already queued\n");
604 goto done;
605 }
606 }
607 break;
608 case 0Xfb:
609
610 if(debug & DEBUG_LOWER) printk("idle: fb\n");
611 if(q->QWrite) {
612 memcpy(ltdmabuf,q->dbuf,q->dbuflen);
613 handlewrite(dev);
614 } else {
615 handleread(dev);
616
617
618
619 if(q->mailbox) {
620 memcpy(q->dbuf,ltdmabuf,q->dbuflen);
621 } else {
622
623 mailbox[ 0x0f & ltdmabuf[0] ] = ltdmabuf[1];
624 mboxinuse[0]=0;
625 }
626 }
627 break;
628 }
629 goto loop;
630
631done:
632 QInIdle=0;
633
634
635
636
637
638
639
640 if (dev->irq) {
641 inb_p(base+7);
642 inb_p(base+7);
643 }
644}
645
646
647static int do_write(struct net_device *dev, void *cbuf, int cbuflen,
648 void *dbuf, int dbuflen)
649{
650
651 int i = getmbox();
652 int ret;
653
654 if(i) {
655 qels[i].cbuf = cbuf;
656 qels[i].cbuflen = cbuflen;
657 qels[i].dbuf = dbuf;
658 qels[i].dbuflen = dbuflen;
659 qels[i].QWrite = 1;
660 qels[i].mailbox = i;
661 enQ(&qels[i]);
662 idle(dev);
663 ret = mailbox[i];
664 mboxinuse[i]=0;
665 return ret;
666 }
667 printk("ltpc: could not allocate mbox\n");
668 return -1;
669}
670
671static int do_read(struct net_device *dev, void *cbuf, int cbuflen,
672 void *dbuf, int dbuflen)
673{
674
675 int i = getmbox();
676 int ret;
677
678 if(i) {
679 qels[i].cbuf = cbuf;
680 qels[i].cbuflen = cbuflen;
681 qels[i].dbuf = dbuf;
682 qels[i].dbuflen = dbuflen;
683 qels[i].QWrite = 0;
684 qels[i].mailbox = i;
685 enQ(&qels[i]);
686 idle(dev);
687 ret = mailbox[i];
688 mboxinuse[i]=0;
689 return ret;
690 }
691 printk("ltpc: could not allocate mbox\n");
692 return -1;
693}
694
695
696
697static struct timer_list ltpc_timer;
698
699static netdev_tx_t ltpc_xmit(struct sk_buff *skb, struct net_device *dev);
700
701static int read_30 ( struct net_device *dev)
702{
703 lt_command c;
704 c.getflags.command = LT_GETFLAGS;
705 return do_read(dev, &c, sizeof(c.getflags),&c,0);
706}
707
708static int set_30 (struct net_device *dev,int x)
709{
710 lt_command c;
711 c.setflags.command = LT_SETFLAGS;
712 c.setflags.flags = x;
713 return do_write(dev, &c, sizeof(c.setflags),&c,0);
714}
715
716
717
718static int sendup_buffer (struct net_device *dev)
719{
720
721
722
723 int dnode, snode, llaptype, len;
724 int sklen;
725 struct sk_buff *skb;
726 struct lt_rcvlap *ltc = (struct lt_rcvlap *) ltdmacbuf;
727
728 if (ltc->command != LT_RCVLAP) {
729 printk("unknown command 0x%02x from ltpc card\n",ltc->command);
730 return -1;
731 }
732 dnode = ltc->dnode;
733 snode = ltc->snode;
734 llaptype = ltc->laptype;
735 len = ltc->length;
736
737 sklen = len;
738 if (llaptype == 1)
739 sklen += 8;
740 if(sklen > 800) {
741 printk(KERN_INFO "%s: nonsense length in ltpc command 0x14: 0x%08x\n",
742 dev->name,sklen);
743 return -1;
744 }
745
746 if ( (llaptype==0) || (llaptype>2) ) {
747 printk(KERN_INFO "%s: unknown LLAP type: %d\n",dev->name,llaptype);
748 return -1;
749 }
750
751
752 skb = dev_alloc_skb(3+sklen);
753 if (skb == NULL)
754 {
755 printk("%s: dropping packet due to memory squeeze.\n",
756 dev->name);
757 return -1;
758 }
759 skb->dev = dev;
760
761 if (sklen > len)
762 skb_reserve(skb,8);
763 skb_put(skb,len+3);
764 skb->protocol = htons(ETH_P_LOCALTALK);
765
766 skb->data[0] = dnode;
767 skb->data[1] = snode;
768 skb->data[2] = llaptype;
769 skb_reset_mac_header(skb);
770 skb_pull(skb,3);
771
772
773 skb_copy_to_linear_data(skb, ltdmabuf, len);
774
775 skb_reset_transport_header(skb);
776
777 dev->stats.rx_packets++;
778 dev->stats.rx_bytes += skb->len;
779
780
781 netif_rx(skb);
782 return 0;
783}
784
785
786
787static irqreturn_t
788ltpc_interrupt(int irq, void *dev_id)
789{
790 struct net_device *dev = dev_id;
791
792 if (dev==NULL) {
793 printk("ltpc_interrupt: unknown device.\n");
794 return IRQ_NONE;
795 }
796
797 inb_p(dev->base_addr+6);
798
799 idle(dev);
800
801
802
803 return IRQ_HANDLED;
804}
805
806
807
808
809
810
811
812
813
814
815
816
817static int ltpc_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
818{
819 struct sockaddr_at *sa = (struct sockaddr_at *) &ifr->ifr_addr;
820
821 struct ltpc_private *ltpc_priv = netdev_priv(dev);
822 struct atalk_addr *aa = <pc_priv->my_addr;
823 struct lt_init c;
824 int ltflags;
825
826 if(debug & DEBUG_VERBOSE) printk("ltpc_ioctl called\n");
827
828 switch(cmd) {
829 case SIOCSIFADDR:
830
831 aa->s_net = sa->sat_addr.s_net;
832
833
834 c.command = LT_INIT;
835 c.hint = sa->sat_addr.s_node;
836
837 aa->s_node = do_read(dev,&c,sizeof(c),&c,0);
838
839
840 ltflags = read_30(dev);
841 ltflags |= LT_FLAG_ALLLAP;
842 set_30 (dev,ltflags);
843
844 dev->broadcast[0] = 0xFF;
845 dev->dev_addr[0] = aa->s_node;
846
847 dev->addr_len=1;
848
849 return 0;
850
851 case SIOCGIFADDR:
852
853 sa->sat_addr.s_net = aa->s_net;
854 sa->sat_addr.s_node = aa->s_node;
855
856 return 0;
857
858 default:
859 return -EINVAL;
860 }
861}
862
863static void set_multicast_list(struct net_device *dev)
864{
865
866
867}
868
869static int ltpc_poll_counter;
870
871static void ltpc_poll(unsigned long l)
872{
873 struct net_device *dev = (struct net_device *) l;
874
875 del_timer(<pc_timer);
876
877 if(debug & DEBUG_VERBOSE) {
878 if (!ltpc_poll_counter) {
879 ltpc_poll_counter = 50;
880 printk("ltpc poll is alive\n");
881 }
882 ltpc_poll_counter--;
883 }
884
885 if (!dev)
886 return;
887
888
889 idle(dev);
890 ltpc_timer.expires = jiffies + HZ/20;
891
892 add_timer(<pc_timer);
893}
894
895
896
897static netdev_tx_t ltpc_xmit(struct sk_buff *skb, struct net_device *dev)
898{
899
900
901
902 int i;
903 struct lt_sendlap cbuf;
904 unsigned char *hdr;
905
906 cbuf.command = LT_SENDLAP;
907 cbuf.dnode = skb->data[0];
908 cbuf.laptype = skb->data[2];
909 skb_pull(skb,3);
910 cbuf.length = skb->len;
911 skb_reset_transport_header(skb);
912
913 if(debug & DEBUG_UPPER) {
914 printk("command ");
915 for(i=0;i<6;i++)
916 printk("%02x ",((unsigned char *)&cbuf)[i]);
917 printk("\n");
918 }
919
920 hdr = skb_transport_header(skb);
921 do_write(dev, &cbuf, sizeof(cbuf), hdr, skb->len);
922
923 if(debug & DEBUG_UPPER) {
924 printk("sent %d ddp bytes\n",skb->len);
925 for (i = 0; i < skb->len; i++)
926 printk("%02x ", hdr[i]);
927 printk("\n");
928 }
929
930 dev->stats.tx_packets++;
931 dev->stats.tx_bytes += skb->len;
932
933 dev_kfree_skb(skb);
934 return NETDEV_TX_OK;
935}
936
937
938
939static int __init ltpc_probe_dma(int base, int dma)
940{
941 int want = (dma == 3) ? 2 : (dma == 1) ? 1 : 3;
942 unsigned long timeout;
943 unsigned long f;
944
945 if (want & 1) {
946 if (request_dma(1,"ltpc")) {
947 want &= ~1;
948 } else {
949 f=claim_dma_lock();
950 disable_dma(1);
951 clear_dma_ff(1);
952 set_dma_mode(1,DMA_MODE_WRITE);
953 set_dma_addr(1,virt_to_bus(ltdmabuf));
954 set_dma_count(1,sizeof(struct lt_mem));
955 enable_dma(1);
956 release_dma_lock(f);
957 }
958 }
959 if (want & 2) {
960 if (request_dma(3,"ltpc")) {
961 want &= ~2;
962 } else {
963 f=claim_dma_lock();
964 disable_dma(3);
965 clear_dma_ff(3);
966 set_dma_mode(3,DMA_MODE_WRITE);
967 set_dma_addr(3,virt_to_bus(ltdmabuf));
968 set_dma_count(3,sizeof(struct lt_mem));
969 enable_dma(3);
970 release_dma_lock(f);
971 }
972 }
973
974
975
976
977 ltdmabuf[0] = LT_READMEM;
978 ltdmabuf[1] = 1;
979 ltdmabuf[2] = 0; ltdmabuf[3] = 0;
980 ltdmabuf[4] = 0; ltdmabuf[5] = 1;
981 ltdmabuf[6] = 0;
982
983 inb_p(io+1);
984 inb_p(io+0);
985 timeout = jiffies+100*HZ/100;
986 while(time_before(jiffies, timeout)) {
987 if ( 0xfa == inb_p(io+6) ) break;
988 }
989
990 inb_p(io+3);
991 inb_p(io+2);
992 while(time_before(jiffies, timeout)) {
993 if ( 0xfb == inb_p(io+6) ) break;
994 }
995
996
997
998 if ((want & 2) && (get_dma_residue(3)==sizeof(struct lt_mem))) {
999 want &= ~2;
1000 free_dma(3);
1001 }
1002
1003 if ((want & 1) && (get_dma_residue(1)==sizeof(struct lt_mem))) {
1004 want &= ~1;
1005 free_dma(1);
1006 }
1007
1008 if (!want)
1009 return 0;
1010
1011 return (want & 2) ? 3 : 1;
1012}
1013
1014static const struct net_device_ops ltpc_netdev = {
1015 .ndo_start_xmit = ltpc_xmit,
1016 .ndo_do_ioctl = ltpc_ioctl,
1017 .ndo_set_rx_mode = set_multicast_list,
1018};
1019
1020struct net_device * __init ltpc_probe(void)
1021{
1022 struct net_device *dev;
1023 int err = -ENOMEM;
1024 int x=0,y=0;
1025 int autoirq;
1026 unsigned long f;
1027 unsigned long timeout;
1028
1029 dev = alloc_ltalkdev(sizeof(struct ltpc_private));
1030 if (!dev)
1031 goto out;
1032
1033
1034
1035 if (io != 0x240 && request_region(0x220,8,"ltpc")) {
1036 x = inb_p(0x220+6);
1037 if ( (x!=0xff) && (x>=0xf0) ) {
1038 io = 0x220;
1039 goto got_port;
1040 }
1041 release_region(0x220,8);
1042 }
1043 if (io != 0x220 && request_region(0x240,8,"ltpc")) {
1044 y = inb_p(0x240+6);
1045 if ( (y!=0xff) && (y>=0xf0) ){
1046 io = 0x240;
1047 goto got_port;
1048 }
1049 release_region(0x240,8);
1050 }
1051
1052
1053 printk(KERN_ERR "LocalTalk card not found; 220 = %02x, 240 = %02x.\n", x,y);
1054 err = -ENODEV;
1055 goto out1;
1056
1057 got_port:
1058
1059 if (irq < 2) {
1060 unsigned long irq_mask;
1061
1062 irq_mask = probe_irq_on();
1063
1064 inb_p(io+7);
1065 inb_p(io+7);
1066
1067 inb_p(io+6);
1068 mdelay(2);
1069 autoirq = probe_irq_off(irq_mask);
1070
1071 if (autoirq == 0) {
1072 printk(KERN_ERR "ltpc: probe at %#x failed to detect IRQ line.\n", io);
1073 } else {
1074 irq = autoirq;
1075 }
1076 }
1077
1078
1079 ltdmabuf = (unsigned char *) dma_mem_alloc(1000);
1080 if (!ltdmabuf) {
1081 printk(KERN_ERR "ltpc: mem alloc failed\n");
1082 err = -ENOMEM;
1083 goto out2;
1084 }
1085
1086 ltdmacbuf = <dmabuf[800];
1087
1088 if(debug & DEBUG_VERBOSE) {
1089 printk("ltdmabuf pointer %08lx\n",(unsigned long) ltdmabuf);
1090 }
1091
1092
1093
1094 inb_p(io+1);
1095 inb_p(io+3);
1096
1097 msleep(20);
1098
1099 inb_p(io+0);
1100 inb_p(io+2);
1101 inb_p(io+7);
1102 inb_p(io+4);
1103 inb_p(io+5);
1104 inb_p(io+5);
1105 inb_p(io+6);
1106
1107 ssleep(1);
1108
1109
1110
1111
1112
1113 dma = ltpc_probe_dma(io, dma);
1114 if (!dma) {
1115 printk(KERN_ERR "No DMA channel found on ltpc card.\n");
1116 err = -ENODEV;
1117 goto out3;
1118 }
1119
1120
1121 if(irq)
1122 printk(KERN_INFO "Apple/Farallon LocalTalk-PC card at %03x, IR%d, DMA%d.\n",io,irq,dma);
1123 else
1124 printk(KERN_INFO "Apple/Farallon LocalTalk-PC card at %03x, DMA%d. Using polled mode.\n",io,dma);
1125
1126 dev->netdev_ops = <pc_netdev;
1127 dev->base_addr = io;
1128 dev->irq = irq;
1129 dev->dma = dma;
1130
1131
1132
1133
1134
1135 f=claim_dma_lock();
1136 disable_dma(dma);
1137 clear_dma_ff(dma);
1138 set_dma_mode(dma,DMA_MODE_READ);
1139 set_dma_addr(dma,virt_to_bus(ltdmabuf));
1140 set_dma_count(dma,0x100);
1141 enable_dma(dma);
1142 release_dma_lock(f);
1143
1144 (void) inb_p(io+3);
1145 (void) inb_p(io+2);
1146 timeout = jiffies+100*HZ/100;
1147
1148 while(time_before(jiffies, timeout)) {
1149 if( 0xf9 == inb_p(io+6))
1150 break;
1151 schedule();
1152 }
1153
1154 if(debug & DEBUG_VERBOSE) {
1155 printk("setting up timer and irq\n");
1156 }
1157
1158
1159 if (irq && request_irq( irq, ltpc_interrupt, 0, "ltpc", dev) >= 0)
1160 {
1161 (void) inb_p(io+7);
1162 (void) inb_p(io+7);
1163 } else {
1164 if( irq )
1165 printk(KERN_ERR "ltpc: IRQ already in use, using polled mode.\n");
1166 dev->irq = 0;
1167
1168
1169 init_timer(<pc_timer);
1170 ltpc_timer.function=ltpc_poll;
1171 ltpc_timer.data = (unsigned long) dev;
1172
1173 ltpc_timer.expires = jiffies + HZ/20;
1174 add_timer(<pc_timer);
1175 }
1176 err = register_netdev(dev);
1177 if (err)
1178 goto out4;
1179
1180 return NULL;
1181out4:
1182 del_timer_sync(<pc_timer);
1183 if (dev->irq)
1184 free_irq(dev->irq, dev);
1185out3:
1186 free_pages((unsigned long)ltdmabuf, get_order(1000));
1187out2:
1188 release_region(io, 8);
1189out1:
1190 free_netdev(dev);
1191out:
1192 return ERR_PTR(err);
1193}
1194
1195#ifndef MODULE
1196
1197static int __init ltpc_setup(char *str)
1198{
1199 int ints[5];
1200
1201 str = get_options(str, ARRAY_SIZE(ints), ints);
1202
1203 if (ints[0] == 0) {
1204 if (str && !strncmp(str, "auto", 4)) {
1205
1206 }
1207 else {
1208
1209 printk (KERN_ERR
1210 "ltpc: usage: ltpc=auto|iobase[,irq[,dma]]\n");
1211 return 0;
1212 }
1213 } else {
1214 io = ints[1];
1215 if (ints[0] > 1) {
1216 irq = ints[2];
1217 }
1218 if (ints[0] > 2) {
1219 dma = ints[3];
1220 }
1221
1222 }
1223 return 1;
1224}
1225
1226__setup("ltpc=", ltpc_setup);
1227#endif
1228
1229static struct net_device *dev_ltpc;
1230
1231#ifdef MODULE
1232
1233MODULE_LICENSE("GPL");
1234module_param(debug, int, 0);
1235module_param(io, int, 0);
1236module_param(irq, int, 0);
1237module_param(dma, int, 0);
1238
1239
1240static int __init ltpc_module_init(void)
1241{
1242 if(io == 0)
1243 printk(KERN_NOTICE
1244 "ltpc: Autoprobing is not recommended for modules\n");
1245
1246 dev_ltpc = ltpc_probe();
1247 if (IS_ERR(dev_ltpc))
1248 return PTR_ERR(dev_ltpc);
1249 return 0;
1250}
1251module_init(ltpc_module_init);
1252#endif
1253
1254static void __exit ltpc_cleanup(void)
1255{
1256
1257 if(debug & DEBUG_VERBOSE) printk("unregister_netdev\n");
1258 unregister_netdev(dev_ltpc);
1259
1260 ltpc_timer.data = 0;
1261
1262 del_timer_sync(<pc_timer);
1263
1264 if(debug & DEBUG_VERBOSE) printk("freeing irq\n");
1265
1266 if (dev_ltpc->irq)
1267 free_irq(dev_ltpc->irq, dev_ltpc);
1268
1269 if(debug & DEBUG_VERBOSE) printk("freeing dma\n");
1270
1271 if (dev_ltpc->dma)
1272 free_dma(dev_ltpc->dma);
1273
1274 if(debug & DEBUG_VERBOSE) printk("freeing ioaddr\n");
1275
1276 if (dev_ltpc->base_addr)
1277 release_region(dev_ltpc->base_addr,8);
1278
1279 free_netdev(dev_ltpc);
1280
1281 if(debug & DEBUG_VERBOSE) printk("free_pages\n");
1282
1283 free_pages( (unsigned long) ltdmabuf, get_order(1000));
1284
1285 if(debug & DEBUG_VERBOSE) printk("returning from cleanup_module\n");
1286}
1287
1288module_exit(ltpc_cleanup);
1289