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