This source file includes following definitions.
- arcnet_probe
- arcnet_ioprobe
- arcnet_memprobe
- arcnet_reset
- arcnetW_init
- arcnet_open
- arcnet_close
- arcnetA_send_packet
- arcnetA_continue_tx
- arcnetA_prepare_tx
- arcnetA_go_tx
- arcnetW_send_packet
- arcnet_interrupt
- arcnet_inthandler
- arcnet_rx
- arcnetA_rx
- arcnetW_rx
- arcnet_get_stats
- set_multicast_list
- arcnetA_header
- arcnetA_rebuild_header
- arcnetA_type_trans
- init_module
- cleanup_module
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 static char *version =
123 "arcnet.c:v1.92 ALPHA 95/07/11 Avery Pennarun <apenwarr@foxnet.net>\n";
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138 #define DETECT_RECONFIGS
139
140
141
142
143
144
145
146
147
148 #define VERIFY_ACK
149
150
151
152
153 #undef static
154
155
156
157
158 #include <linux/config.h>
159 #ifdef MODULE
160 #include <linux/module.h>
161 #include <linux/version.h>
162 #endif
163
164 #include <linux/kernel.h>
165 #include <linux/sched.h>
166 #include <linux/types.h>
167 #include <linux/fcntl.h>
168 #include <linux/interrupt.h>
169 #include <linux/ptrace.h>
170 #include <linux/ioport.h>
171 #include <linux/in.h>
172 #include <linux/malloc.h>
173 #include <linux/string.h>
174 #include <linux/timer.h>
175 #include <linux/errno.h>
176 #include <linux/delay.h>
177
178 #include <asm/system.h>
179 #include <asm/bitops.h>
180 #include <asm/io.h>
181 #include <asm/dma.h>
182
183 #include <linux/netdevice.h>
184 #include <linux/etherdevice.h>
185 #include <linux/skbuff.h>
186
187 #include <net/arp.h>
188
189
190
191
192
193
194
195
196
197
198 #define D_NORMAL 1
199 #define D_INIT 2
200 #define D_EXTRA 4
201
202 #define D_DURING 8
203 #define D_TX 16
204 #define D_RX 32
205 #define D_SKB 64
206
207 #ifndef NET_DEBUG
208 #define NET_DEBUG D_NORMAL|D_INIT|D_EXTRA
209 #endif
210 int arcnet_debug = NET_DEBUG;
211
212 #ifndef HAVE_AUTOIRQ
213
214 extern void autoirq_setup(int waittime);
215 extern int autoirq_report(int waittime);
216
217
218 extern struct device *irq2dev_map[16];
219 #endif
220
221 #ifndef HAVE_PORTRESERVE
222 #define check_region(ioaddr, size) 0
223 #define request_region(ioaddr, size) do ; while (0)
224 #endif
225
226
227 #define BUGLVL(x) if (arcnet_debug&(x))
228
229
230
231 #define TBUSY lp->adev->tbusy \
232 =lp->wdev->tbusy
233 #define IF_TBUSY (lp->adev->tbusy \
234 || lp->wdev->tbusy)
235 #define START lp->adev->start \
236 =lp->wdev->start
237
238
239
240 #define ARCNET_TOTAL_SIZE 16
241
242
243
244
245 #define INTMASK (ioaddr+0)
246 #define STATUS (ioaddr+0)
247 #define COMMAND (ioaddr+1)
248 #define RESET (ioaddr+8)
249
250
251
252 #define RESETtime 40
253 #define XMITtime 10
254 #define ACKtime 10
255
256
257
258
259
260
261
262
263
264 #define MTU 253
265 #define MinTU 257
266 #define XMTU 508
267
268
269 #define TXFREEflag 0x01
270 #define TXACKflag 0x02
271 #define RECONflag 0x04
272 #define TESTflag 0x08
273 #define RESETflag 0x10
274 #define RES1flag 0x20
275 #define RES2flag 0x40
276 #define NORXflag 0x80
277
278 #ifdef DETECT_RECONFIGS
279 #define RECON_flag RECONflag
280 #else
281 #define RECON_flag 0
282 #endif
283
284
285
286
287
288
289 #define NOTXcmd 0x01
290 #define NORXcmd 0x02
291 #define TXcmd 0x03
292 #define RXcmd 0x04
293 #define CONFIGcmd 0x05
294 #define CFLAGScmd 0x06
295 #define TESTcmd 0x07
296
297
298 #define RESETclear 0x08
299 #define CONFIGclear 0x10
300
301
302 #define TESTload 0x08
303
304
305 #define TESTvalue 0321
306
307
308 #define RXbcasts 0x80
309
310
311 #define NORMALconf 0x00
312 #define EXTconf 0x08
313
314
315
316 #define EnableReceiver() outb(RXcmd|(recbuf<<3)|RXbcasts,COMMAND)
317
318
319 #define ARC_P_IP 212
320 #define ARC_P_ARP 213
321 #define ARC_P_RARP 214
322 #define ARC_P_IPX 250
323
324
325 #define ARC_P_MS_TCPIP 0xE8
326
327
328 #define ARC_P_LANSOFT 251
329 #define ARC_P_ATALK 0xDD
330
331
332 #define NORMAL 0
333 #define EXTENDED 1
334 #define EXCEPTION 2
335
336
337 struct HardHeader
338 {
339 u_char source,
340 destination,
341 offset1,
342 offset2;
343 };
344
345
346 union ArcPacket
347 {
348 struct HardHeader hardheader;
349 u_char raw[512];
350 };
351
352
353
354
355
356 struct ClientData
357 {
358
359
360
361 u_char saddr,
362 daddr;
363
364
365 u_char protocol_id,
366 split_flag;
367 u_short sequence;
368 };
369 #define EXTRA_CLIENTDATA (sizeof(struct ClientData)-4)
370
371
372
373
374
375 struct Incoming
376 {
377 struct sk_buff *skb;
378 unsigned char lastpacket,
379 numpackets;
380 u_short sequence;
381 };
382
383 struct Outgoing
384 {
385 struct sk_buff *skb;
386 struct ClientData *hdr;
387 u_char *data;
388 short length,
389 dataleft,
390 segnum,
391 numsegs,
392 seglen;
393 #ifdef VERIFY_ACK
394 short lastload_dest,
395 lasttrans_dest;
396 #endif
397
398 };
399
400
401
402 struct arcnet_local {
403 struct enet_statistics stats;
404 u_char arcnum;
405 u_short sequence;
406 u_char recbuf,
407 txbuf,
408 txready;
409 short intx,
410 in_txhandler,
411 sending;
412 short tx_left;
413
414 struct timer_list timer;
415 struct Incoming incoming[256];
416 struct Outgoing outgoing;
417
418 struct device *adev;
419 struct device *wdev;
420 };
421
422
423
424 extern int arcnet_probe(struct device *dev);
425 #ifndef MODULE
426 static int arcnet_memprobe(struct device *dev,u_char *addr);
427 static int arcnet_ioprobe(struct device *dev, short ioaddr);
428 #endif
429 static int arcnetW_init(struct device *dev);
430
431 static int arcnet_open(struct device *dev);
432 static int arcnet_close(struct device *dev);
433 static int arcnet_reset(struct device *dev);
434
435 static int arcnetA_send_packet(struct sk_buff *skb, struct device *dev);
436 static void arcnetA_continue_tx(struct device *dev);
437 static void arcnetA_prepare_tx(struct device *dev,struct ClientData *hdr,
438 short length,char *data);
439 static void arcnetA_go_tx(struct device *dev);
440
441 static int arcnetW_send_packet(struct sk_buff *skb, struct device *dev);
442
443 static void arcnet_interrupt(int irq,struct pt_regs *regs);
444 static void arcnet_inthandler(struct device *dev);
445
446 static void arcnet_rx(struct device *dev,int recbuf);
447 static void arcnetA_rx(struct device *dev,struct ClientData *arcsoft,
448 int length,u_char saddr, u_char daddr);
449 static void arcnetW_rx(struct device *dev,u_char *arcsoft,
450 int length,u_char saddr, u_char daddr);
451
452 static struct enet_statistics *arcnet_get_stats(struct device *dev);
453 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
454
455
456 int arcnetA_header(struct sk_buff *skb,struct device *dev,unsigned short type,
457 void *daddr,void *saddr,unsigned len);
458 int arcnetA_rebuild_header(void *eth,struct device *dev,unsigned long raddr,
459 struct sk_buff *skb);
460 unsigned short arcnetA_type_trans(struct sk_buff *skb,struct device *dev);
461
462 #ifdef MODULE
463 int init_module(void);
464 void cleanup_module(void);
465 #endif
466
467 #define tx_done(dev) 1
468
469 #define JIFFER(time) for (delayval=0; delayval<(time*10); delayval++) \
470 udelay(1000);
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486 int
487 arcnet_probe(struct device *dev)
488 {
489 #ifndef MODULE
490
491
492
493 int *port, ports[] = {
494 0x300,0x2E0,0x2F0,0x2D0,
495
496 0x200,0x210,0x220,0x230,0x240,0x250,0x260,0x270,
497 0x280,0x290,0x2a0,0x2b0,0x2c0,
498 0x310,0x320,0x330,0x340,0x350,0x360,0x370,
499 0x380,0x390,0x3a0,0x3e0,0x3f0,
500
501 0};
502
503
504 unsigned long *addr, addrs[] = {0xD0000,0xE0000,0xA0000,0xB0000,
505 0xC0000,0xF0000,
506
507 0xE1000,
508 0xDD000,0xDC000,
509 0xD9000,0xD8000,0xD5000,0xD4000,0xD1000,
510 0xCD000,0xCC000,
511 0xC9000,0xC8000,0xC5000,0xC4000,
512
513 0};
514 int base_addr=dev->base_addr, status=0;
515 #endif
516 int delayval;
517 struct arcnet_local *lp;
518
519 BUGLVL(D_NORMAL)
520 {
521 printk(version);
522 printk("arcnet: ***\n");
523 printk("arcnet: * Read linux/drivers/net/README.arcnet for important release notes!\n");
524 printk("arcnet: *\n");
525 printk("arcnet: * This is an ALPHA version! (Last stable release: v1.02) E-mail me if\n");
526 printk("arcnet: * you have any questions, comments, or bug reports.\n");
527 printk("arcnet: ***\n");
528 }
529
530 BUGLVL(D_INIT)
531 printk("arcnet: given: base %lXh, IRQ %Xh, shmem %lXh\n",
532 dev->base_addr,dev->irq,dev->mem_start);
533
534 #ifndef MODULE
535 if (base_addr > 0x1ff)
536 status=arcnet_ioprobe(dev, base_addr);
537 else if (base_addr > 0)
538 return ENXIO;
539 else for (port = &ports[0]; *port; port++)
540 {
541 int ioaddr = *port;
542 if (check_region(ioaddr, ARCNET_TOTAL_SIZE))
543 {
544 BUGLVL(D_INIT)
545 printk("arcnet: Skipping %Xh because of check_region...\n",
546 ioaddr);
547 continue;
548 }
549
550 status=arcnet_ioprobe(dev, ioaddr);
551 if (!status) break;
552 }
553
554 if (status) return status;
555
556
557
558
559 BUGLVL(D_INIT)
560 printk("arcnet: ioprobe okay! Waiting for reset...\n");
561 JIFFER(100);
562
563
564 BUGLVL(D_INIT)
565 printk("arcnet: starting memory probe, given %lXh\n",
566 dev->mem_start);
567 if (dev->mem_start)
568 {
569 status=arcnet_memprobe(dev,(u_char *)dev->mem_start);
570 if (status) return status;
571 }
572 else
573 {
574 for (addr = &addrs[0]; *addr; addr++) {
575 status=arcnet_memprobe(dev,(u_char *)(*addr));
576 if (!status) break;
577 }
578
579 if (status) return status;
580 }
581 #else
582 if (!dev->base_addr || !dev->irq || !dev->mem_start
583 || !dev->rmem_start)
584 {
585 printk("arcnet: loadable modules can't autoprobe!\n");
586 printk("arcnet: try using io=, irqnum=, and shmem= on the insmod line.\n");
587 printk("arcnet: you may also need num= to change the device name. (ie. num=1 for arc1)\n");
588 return ENODEV;
589 }
590 #endif
591
592 {
593 int irqval = request_irq(dev->irq, &arcnet_interrupt, 0,
594 "arcnet");
595 if (irqval) {
596 printk("%s: unable to get IRQ %d (irqval=%d).\n",
597 dev->name,dev->irq, irqval);
598 return EAGAIN;
599 }
600 }
601
602
603 request_region(dev->base_addr, ARCNET_TOTAL_SIZE,"arcnet");
604
605 printk("%s: ARCnet card found at %03lXh, IRQ %d, ShMem at %lXh.\n",
606 dev->name, dev->base_addr, dev->irq, dev->mem_start);
607
608
609 dev->priv = kmalloc(sizeof(struct arcnet_local), GFP_KERNEL);
610 memset(dev->priv, 0, sizeof(struct arcnet_local));
611 lp=(struct arcnet_local *)(dev->priv);
612
613 dev->open=arcnet_open;
614 dev->stop=arcnet_close;
615 dev->hard_start_xmit=arcnetA_send_packet;
616 dev->get_stats=arcnet_get_stats;
617 #ifdef HAVE_MULTICAST
618 dev->set_multicast_list = &set_multicast_list;
619 #endif
620
621
622
623
624 ether_setup(dev);
625
626
627 dev->type=ARPHRD_ARCNET;
628 dev->hard_header_len=sizeof(struct ClientData);
629 BUGLVL(D_DURING)
630 printk("arcnet: ClientData header size is %d.\narcnet: HardHeader size is %d.\n",
631 sizeof(struct ClientData),sizeof(struct HardHeader));
632
633
634
635
636 dev->addr_len=1;
637 dev->broadcast[0]=0x00;
638
639 BUGLVL(D_INIT) printk("arcnet: arcnet_probe: resetting card.\n");
640 arcnet_reset(dev);
641 JIFFER(50);
642 BUGLVL(D_NORMAL)
643 printk("arcnet: We appear to be station %d (%02Xh)\n",
644 lp->arcnum,lp->arcnum);
645 if (lp->arcnum==0)
646 printk("arcnet: WARNING! Station address 0 is reserved for broadcasts!\n");
647 if (lp->arcnum==255)
648 printk("arcnet: WARNING! Station address 255 may confuse DOS networking programs!\n");
649 dev->dev_addr[0]=lp->arcnum;
650 lp->sequence=1;
651 lp->recbuf=0;
652
653 dev->hard_header=arcnetA_header;
654 dev->rebuild_header=arcnetA_rebuild_header;
655
656 return 0;
657 }
658
659 #ifndef MODULE
660
661 int arcnet_ioprobe(struct device *dev, short ioaddr)
662 {
663 int delayval,airq;
664
665 BUGLVL(D_INIT)
666 {
667 printk("arcnet: probing address %Xh\n",ioaddr);
668 printk("arcnet: status1=%Xh\n",inb(STATUS));
669 }
670
671
672
673
674
675
676
677
678 inb(RESET);
679 JIFFER(RESETtime);
680
681
682 if (inb(STATUS)==0xFF)
683 {
684 BUGLVL(D_INIT)
685 printk("arcnet: probe failed. Status port empty.\n");
686 return ENODEV;
687 }
688
689 #if 0
690
691
692
693
694
695 {
696 int initval,curval;
697
698 curval=initval=inb(COMMAND);
699 delayval=jiffies+5;
700 while (delayval>=jiffies && curval==initval)
701 curval=inb(COMMAND);
702
703 if (curval==initval)
704 {
705 printk("arcnet: probe failed. never-changing command port (%02Xh).\n",
706 initval);
707 return ENODEV;
708 }
709 }
710 #endif
711
712 BUGLVL(D_INIT)
713 printk("arcnet: status2=%Xh\n",inb(STATUS));
714
715
716 outb(CFLAGScmd|RESETclear|CONFIGclear,COMMAND);
717 if (inb(STATUS) & RESETflag)
718 {
719 BUGLVL(D_INIT)
720 printk("arcnet: probe failed. eternal reset flag1...(status=%Xh)\n",
721 inb(STATUS));
722 return ENODEV;
723 }
724
725
726 autoirq_setup(0);
727
728
729
730
731
732
733
734
735
736 outb(NORXflag,INTMASK);
737 JIFFER(RESETtime);
738 outb(0,INTMASK);
739
740
741 outb(CFLAGScmd|RESETclear|CONFIGclear,COMMAND);
742
743 airq = autoirq_report(0);
744 BUGLVL(D_INIT) if (airq)
745 printk("arcnet: autoirq is %d\n", airq);
746
747
748
749
750 if (!airq && !(dev->base_addr && dev->irq))
751 {
752 BUGLVL(D_INIT)
753 printk("arcnet: probe failed. no autoirq...\n");
754 return ENODEV;
755 }
756
757
758
759 if (inb(STATUS) & RESETflag)
760 {
761
762 outb(CFLAGScmd|RESETclear|CONFIGclear,COMMAND);
763 }
764
765 if (inb(STATUS) & RESETflag)
766 {
767 BUGLVL(D_INIT)
768 printk("arcnet: probe failed. eternal reset flag...(status=%Xh)\n",
769 inb(STATUS));
770 return ENODEV;
771 }
772
773
774 if (!dev->base_addr) dev->base_addr=ioaddr;
775
776 if (dev->irq < 2)
777 {
778
779 dev->irq=airq;
780 }
781 else if (dev->irq == 2)
782 {
783 BUGLVL(D_NORMAL)
784 printk("arcnet: IRQ2 == IRQ9, don't worry.\n");
785 dev->irq = 9;
786 }
787
788 BUGLVL(D_INIT)
789 printk("arcnet: irq and base address seem okay. (%lXh, IRQ %d)\n",
790 dev->base_addr,dev->irq);
791 return 0;
792 }
793
794
795
796
797
798
799 int arcnet_memprobe(struct device *dev,u_char *addr)
800 {
801 BUGLVL(D_INIT)
802 printk("arcnet: probing memory at %lXh\n",(u_long)addr);
803
804 dev->mem_start=0;
805
806
807 if (addr[0]!=TESTvalue)
808 {
809 BUGLVL(D_INIT)
810 printk("arcnet: probe failed. addr=%lXh, addr[0]=%Xh (not %Xh)\n",
811 (unsigned long)addr,addr[0],TESTvalue);
812 return ENODEV;
813 }
814
815
816 addr[0]=0x42;
817 if (addr[0]!=0x42)
818 {
819 BUGLVL(D_INIT)
820 printk("arcnet: probe failed. addr=%lXh, addr[0]=%Xh (not 42h)\n",
821 (unsigned long)addr,addr[0]);
822 return ENODEV;
823 }
824
825
826 dev->mem_start=(unsigned long)addr;
827 dev->mem_end=dev->mem_start+512*4-1;
828 dev->rmem_start=dev->mem_start+512*0;
829 dev->rmem_end=dev->mem_start+512*2-1;
830
831 return 0;
832 }
833
834 #endif
835
836
837 int arcnet_reset(struct device *dev)
838 {
839 struct arcnet_local *lp=(struct arcnet_local *)dev->priv;
840 short ioaddr=dev->base_addr;
841 int delayval,recbuf=lp->recbuf;
842 u_char *cardmem;
843
844 outb(0,INTMASK);
845
846 BUGLVL(D_INIT)
847 printk("arcnet: Resetting %s (status=%Xh)\n",
848 dev->name,inb(STATUS));
849
850 inb(RESET);
851 JIFFER(RESETtime);
852
853 outb(CFLAGScmd|RESETclear, COMMAND);
854 outb(CFLAGScmd|CONFIGclear,COMMAND);
855
856
857
858
859 cardmem = (u_char *) dev->mem_start;
860 if (cardmem[0] != TESTvalue)
861 {
862 BUGLVL(D_INIT)
863 printk("arcnet: reset failed: TESTvalue not present.\n");
864 return 1;
865 }
866 lp->arcnum=cardmem[1];
867
868
869 recbuf=lp->recbuf=0;
870 lp->txbuf=2;
871
872
873 outb(CONFIGcmd|EXTconf,COMMAND);
874
875
876 BUGLVL(D_DURING)
877 memset((void *)dev->mem_start,0x42,2048);
878
879
880 EnableReceiver();
881
882
883 outb(NORXflag|RECON_flag,INTMASK);
884
885
886 return 0;
887 }
888
889 static int arcnetW_init(struct device *dev)
890 {
891 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
892
893 ether_setup(lp->wdev);
894 dev->dev_addr[0]=0;
895 dev->dev_addr[5]=lp->arcnum;
896 dev->mtu=493;
897 lp->wdev->open=NULL;
898 lp->wdev->stop=NULL;
899 lp->wdev->hard_start_xmit=arcnetW_send_packet;
900
901 BUGLVL(D_EXTRA)
902 printk("%s: ARCnet \"Windows\" protocol initialized.\n",
903 lp->wdev->name);
904
905 return 0;
906 }
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923 static int
924 arcnet_open(struct device *dev)
925 {
926 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
927
928 if (dev->metric>=1000)
929 {
930 arcnet_debug=dev->metric-1000;
931 printk("arcnet: debug level set to %d\n",arcnet_debug);
932 dev->metric=1;
933 }
934
935 BUGLVL(D_NORMAL) printk(version);
936
937 irq2dev_map[dev->irq] = dev;
938
939 BUGLVL(D_EXTRA) printk("arcnet: arcnet_open: resetting card.\n");
940
941
942 if (arcnet_reset(dev) && arcnet_reset(dev))
943 return -ENODEV;
944
945 dev->tbusy=0;
946 dev->interrupt=0;
947 lp->intx=0;
948 lp->in_txhandler=0;
949
950
951 lp->adev=dev;
952 BUGLVL(D_EXTRA)
953 printk("%s: ARCnet RFC1201 protocol initialized.\n",
954 lp->adev->name);
955
956
957 lp->wdev=(struct device *)kmalloc(sizeof(struct device),GFP_KERNEL);
958 memcpy(lp->wdev,dev,sizeof(struct device));
959 lp->wdev->name=(char *)kmalloc(10,GFP_KERNEL);
960 sprintf(lp->wdev->name,"%sw",dev->name);
961 lp->wdev->init=arcnetW_init;
962 register_netdev(lp->wdev);
963
964
965 START=1;
966
967 #ifdef MODULE
968 MOD_INC_USE_COUNT;
969 #endif
970
971 return 0;
972 }
973
974
975
976
977 static int
978 arcnet_close(struct device *dev)
979 {
980 int ioaddr = dev->base_addr;
981 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
982
983 TBUSY=1;
984 START=0;
985
986
987
988 outb(0,INTMASK);
989 outb(NOTXcmd,COMMAND);
990 outb(NORXcmd,COMMAND);
991
992
993 lp->adev=NULL;
994
995
996 lp->wdev->start=0;
997 lp->wdev->priv=NULL;
998 unregister_netdev(lp->wdev);
999 kfree(lp->wdev->name);
1000 kfree(lp->wdev);
1001 lp->wdev=NULL;
1002
1003
1004
1005 #ifdef MODULE
1006 MOD_DEC_USE_COUNT;
1007 #endif
1008
1009 return 0;
1010 }
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023 static int
1024 arcnetA_send_packet(struct sk_buff *skb, struct device *dev)
1025 {
1026 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1027 int ioaddr=dev->base_addr;
1028
1029 lp->intx++;
1030
1031 BUGLVL(D_DURING)
1032 printk("arcnet: transmit requested (status=%Xh, inTX=%d)\n",
1033 inb(STATUS),lp->intx);
1034
1035 if (lp->in_txhandler)
1036 {
1037 printk("arcnet: send_packet called while in txhandler!\n");
1038 lp->intx--;
1039 return 1;
1040 }
1041
1042 if (IF_TBUSY)
1043 {
1044
1045
1046 int tickssofar = jiffies - dev->trans_start;
1047 int recbuf=lp->recbuf;
1048 int status=inb(STATUS);
1049
1050 if (tickssofar < 5)
1051 {
1052 BUGLVL(D_DURING)
1053 printk("arcnet: premature kickme! (status=%Xh ticks=%d o.skb=%ph numsegs=%d segnum=%d\n",
1054 status,tickssofar,lp->outgoing.skb,
1055 lp->outgoing.numsegs,
1056 lp->outgoing.segnum);
1057 lp->intx--;
1058 return 1;
1059 }
1060
1061 BUGLVL(D_EXTRA)
1062 printk("arcnet: transmit timed out (status=%Xh, inTX=%d, inTXh=%d, tickssofar=%d)\n",
1063 status,lp->intx,lp->in_txhandler,tickssofar);
1064
1065 lp->stats.tx_errors++;
1066
1067
1068
1069
1070 outb(0,INTMASK);
1071 if (status&NORXflag) EnableReceiver();
1072 if (!(status&TXFREEflag)) outb(NOTXcmd,COMMAND);
1073 dev->trans_start = jiffies;
1074
1075 if (lp->outgoing.skb)
1076 {
1077 dev_kfree_skb(lp->outgoing.skb,FREE_WRITE);
1078 lp->stats.tx_dropped++;
1079 }
1080 lp->outgoing.skb=NULL;
1081
1082 TBUSY=0;
1083 lp->intx--;
1084
1085
1086 lp->txready=0;
1087 lp->sending=0;
1088 mark_bh(NET_BH);
1089
1090 outb(NORXflag|RECON_flag,INTMASK);
1091
1092 return 1;
1093 }
1094
1095
1096
1097
1098 if (skb == NULL) {
1099 BUGLVL(D_NORMAL)
1100 printk("arcnet: tx passed null skb (status=%Xh, inTX=%d, tickssofar=%ld)\n",
1101 inb(STATUS),lp->intx,jiffies-dev->trans_start);
1102 dev_tint(dev);
1103 lp->intx--;
1104 return 0;
1105 }
1106
1107 if (lp->txready)
1108 {
1109 printk("arcnet: trying to start new packet while busy! (status=%Xh)\n",
1110 inb(STATUS));
1111
1112 outb(0,INTMASK);
1113 outb(NOTXcmd,COMMAND);
1114 arcnet_inthandler(dev);
1115 lp->stats.tx_errors++;
1116 lp->intx--;
1117 lp->txready=0;
1118
1119 return 1;
1120 }
1121
1122
1123
1124 if (set_bit(0, (void*)&dev->tbusy) != 0)
1125 {
1126 printk("arcnet: transmitter called with busy bit set! (status=%Xh, inTX=%d, tickssofar=%ld)\n",
1127 inb(STATUS),lp->intx,jiffies-dev->trans_start);
1128 lp->intx--;
1129 return -EBUSY;
1130 }
1131 else {
1132 struct Outgoing *out=&(lp->outgoing);
1133
1134 TBUSY=1;
1135
1136 out->length = 1 < skb->len ? skb->len : 1;
1137 out->hdr=(struct ClientData*)skb->data;
1138 out->skb=skb;
1139
1140 BUGLVL(D_SKB)
1141 {
1142 short i;
1143 for( i=0; i< skb->len; i++)
1144 {
1145 if( i%16 == 0 ) printk("\n[%04hX] ",i);
1146 printk("%02hX ",((unsigned char*)skb->data)[i]);
1147 }
1148 printk("\n");
1149 }
1150
1151 out->hdr->sequence=(lp->sequence++);
1152
1153 if (lp->txready && inb(STATUS)&TXFREEflag)
1154 arcnetA_go_tx(dev);
1155
1156
1157 if (out->length-EXTRA_CLIENTDATA<=XMTU)
1158 {
1159 BUGLVL(D_DURING)
1160 printk("arcnet: not splitting %d-byte packet. (split_flag=%d)\n",
1161 out->length,out->hdr->split_flag);
1162 BUGLVL(D_EXTRA) if (out->hdr->split_flag)
1163 printk("arcnet: short packet has split_flag set?! (split_flag=%d)\n",
1164 out->hdr->split_flag);
1165 out->numsegs=1;
1166 out->segnum=1;
1167 arcnetA_prepare_tx(dev,out->hdr,
1168 out->length-sizeof(struct ClientData),
1169 ((char *)skb->data)+sizeof(struct ClientData));
1170
1171
1172 dev_kfree_skb(out->skb,FREE_WRITE);
1173 out->skb=NULL;
1174
1175 if (!lp->sending)
1176 {
1177 arcnetA_go_tx(dev);
1178
1179
1180 TBUSY=0;
1181 mark_bh(NET_BH);
1182 }
1183 }
1184 else
1185 {
1186 int maxsegsize=XMTU-4;
1187
1188 out->data=(u_char *)skb->data
1189 + sizeof(struct ClientData);
1190 out->dataleft=out->length-sizeof(struct ClientData);
1191 out->numsegs=(out->dataleft+maxsegsize-1)/maxsegsize;
1192
1193 out->segnum=0;
1194
1195 BUGLVL(D_TX) printk("arcnet: packet (%d bytes) split into %d fragments:\n",
1196 out->length,out->numsegs);
1197
1198
1199 if (lp->txready && inb(STATUS)&TXFREEflag)
1200 arcnetA_go_tx(dev);
1201
1202 if (!lp->txready)
1203 {
1204
1205
1206
1207 arcnetA_continue_tx(dev);
1208 if (!lp->sending)
1209 {
1210 arcnetA_go_tx(dev);
1211 arcnetA_continue_tx(dev);
1212 if (!lp->sending)
1213 arcnetA_go_tx(dev);
1214 }
1215 }
1216
1217
1218
1219
1220 if (out->segnum==out->numsegs)
1221 {
1222
1223 out->segnum++;
1224 if (out->skb)
1225 dev_kfree_skb(out->skb,FREE_WRITE);
1226 out->skb=NULL;
1227 }
1228 }
1229 }
1230
1231 lp->intx--;
1232 lp->stats.tx_packets++;
1233 dev->trans_start=jiffies;
1234 return 0;
1235 }
1236
1237
1238
1239
1240
1241
1242 static void arcnetA_continue_tx(struct device *dev)
1243 {
1244 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1245 int maxsegsize=XMTU-4;
1246 struct Outgoing *out=&(lp->outgoing);
1247
1248 if (lp->txready)
1249 {
1250 printk("arcnet: continue_tx: called with packet in buffer!\n");
1251 return;
1252 }
1253
1254 if (out->segnum>=out->numsegs)
1255 {
1256 printk("arcnet: continue_tx: building segment %d of %d!\n",
1257 out->segnum+1,out->numsegs);
1258 }
1259
1260 if (!out->segnum)
1261 out->hdr->split_flag=((out->numsegs-2)<<1)+1;
1262 else
1263 out->hdr->split_flag=out->segnum<<1;
1264
1265 out->seglen=maxsegsize;
1266 if (out->seglen>out->dataleft) out->seglen=out->dataleft;
1267
1268 BUGLVL(D_TX) printk("arcnet: building packet #%d (%d bytes) of %d (%d total), splitflag=%d\n",
1269 out->segnum+1,out->seglen,out->numsegs,
1270 out->length,out->hdr->split_flag);
1271
1272 arcnetA_prepare_tx(dev,out->hdr,out->seglen,out->data);
1273
1274 out->dataleft-=out->seglen;
1275 out->data+=out->seglen;
1276 out->segnum++;
1277 }
1278
1279
1280
1281
1282
1283 static void
1284 arcnetA_prepare_tx(struct device *dev,struct ClientData *hdr,short length,
1285 char *data)
1286 {
1287 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1288 struct ClientData *arcsoft;
1289 union ArcPacket *arcpacket =
1290 (union ArcPacket *)(dev->mem_start+512*(lp->txbuf^1));
1291 u_char pkttype;
1292 int offset;
1293 short daddr;
1294
1295 lp->txbuf=lp->txbuf^1;
1296
1297 length+=4;
1298
1299 BUGLVL(D_TX)
1300 printk("arcnet: arcnetA_prep_tx: hdr:%ph, length:%d, data:%ph\n",
1301 hdr,length,data);
1302
1303
1304 BUGLVL(D_DURING)
1305 memset((void *)dev->mem_start+lp->txbuf*512,0x42,512);
1306
1307 daddr=arcpacket->hardheader.destination=hdr->daddr;
1308
1309
1310 if (length<=MTU)
1311 {
1312 pkttype=NORMAL;
1313
1314 arcpacket->hardheader.offset1=offset=256-length;
1315 arcsoft=(struct ClientData *)
1316 (&arcpacket->raw[offset-EXTRA_CLIENTDATA]);
1317 }
1318 else if (length>=MinTU)
1319 {
1320 pkttype=EXTENDED;
1321
1322 arcpacket->hardheader.offset1=0;
1323 arcpacket->hardheader.offset2=offset=512-length;
1324 arcsoft=(struct ClientData *)
1325 (&arcpacket->raw[offset-EXTRA_CLIENTDATA]);
1326 }
1327 else
1328 {
1329 pkttype=EXCEPTION;
1330
1331 arcpacket->hardheader.offset1=0;
1332 arcpacket->hardheader.offset2=offset=512-length-4;
1333 arcsoft=(struct ClientData *)
1334 (&arcpacket->raw[offset+4-EXTRA_CLIENTDATA]);
1335
1336
1337
1338
1339
1340 arcpacket->raw[offset+0]=hdr->protocol_id;
1341 arcpacket->raw[offset+1]=0xFF;
1342 arcpacket->raw[offset+2]=0xFF;
1343 arcpacket->raw[offset+3]=0xFF;
1344 }
1345
1346
1347
1348
1349
1350 memcpy((u_char*)arcsoft+EXTRA_CLIENTDATA,
1351 (u_char*)hdr+EXTRA_CLIENTDATA,4);
1352 memcpy((u_char*)arcsoft+sizeof(struct ClientData),
1353 data,length-4);
1354
1355 BUGLVL(D_DURING) printk("arcnet: transmitting packet to station %02Xh (%d bytes, type=%d)\n",
1356 daddr,length,pkttype);
1357
1358 BUGLVL(D_TX)
1359 {
1360 int countx,county;
1361
1362 printk("arcnet: packet dump [tx] follows:");
1363
1364 for (county=0; county<16+(pkttype!=NORMAL)*16; county++)
1365 {
1366 printk("\n[%04X] ",county*16);
1367 for (countx=0; countx<16; countx++)
1368 printk("%02X ",
1369 arcpacket->raw[county*16+countx]);
1370 }
1371
1372 printk("\n");
1373 }
1374
1375 #ifdef VERIFY_ACK
1376 lp->outgoing.lastload_dest=hdr->daddr;
1377 #endif
1378 lp->txready=lp->txbuf;
1379 }
1380
1381
1382
1383
1384 static void
1385 arcnetA_go_tx(struct device *dev)
1386 {
1387 struct arcnet_local *lp=(struct arcnet_local *)dev->priv;
1388 int ioaddr=dev->base_addr;
1389
1390 BUGLVL(D_DURING)
1391 printk("arcnet: go_tx: status=%Xh\n",
1392 inb(STATUS));
1393
1394 if (!(inb(STATUS)&TXFREEflag) || !lp->txready) return;
1395
1396
1397 outb(TXcmd|(lp->txready<<3),COMMAND);
1398
1399 outb(TXFREEflag|NORXflag|RECON_flag,INTMASK);
1400
1401 dev->trans_start = jiffies;
1402 lp->txready=0;
1403 lp->sending++;
1404 #ifdef VERIFY_ACK
1405 lp->outgoing.lasttrans_dest=lp->outgoing.lastload_dest;
1406 lp->outgoing.lastload_dest=0;
1407 #endif
1408 }
1409
1410
1411
1412
1413 static int
1414 arcnetW_send_packet(struct sk_buff *skb, struct device *dev)
1415 {
1416 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1417
1418 BUGLVL(D_DURING)
1419 printk("%s: in arcnetW_send_packet (skb=%p)\n",dev->name,skb);
1420
1421 if (IF_TBUSY)
1422 {
1423
1424
1425 int tickssofar = jiffies - dev->trans_start;
1426 if (tickssofar < 10)
1427 return 1;
1428 printk("%s: transmit timed out\n",dev->name);
1429
1430
1431 TBUSY=0;
1432 dev->trans_start = jiffies;
1433 return 0;
1434 }
1435
1436
1437
1438
1439 if (skb == NULL)
1440 {
1441 dev_tint(dev);
1442 return 0;
1443 }
1444
1445
1446
1447 if (set_bit(0, (void*)&dev->tbusy) != 0)
1448 printk("%s: Transmitter access conflict.\n", dev->name);
1449 else
1450 {
1451 union ArcPacket *arcpacket =
1452 (union ArcPacket *)(dev->mem_start+512*(lp->txbuf^1));
1453 u_char *arcsoft,daddr;
1454 short offset,length=skb->len+1;
1455
1456 TBUSY=1;
1457
1458 if (length>XMTU)
1459 {
1460 printk("arcnet: MTU for %s and %s must be <= 493 for Windows protocol.\n",
1461 lp->adev->name,lp->wdev->name);
1462 printk("arcnet: transmit aborted.\n");
1463
1464 dev_kfree_skb(skb,FREE_WRITE);
1465 return 0;
1466 }
1467
1468 BUGLVL(D_DURING)
1469 printk("arcnet: starting tx sequence...\n");
1470
1471 lp->txbuf=lp->txbuf^1;
1472
1473
1474 BUGLVL(D_DURING)
1475 memset((void *)dev->mem_start+lp->txbuf*512,0x42,512);
1476
1477
1478 if (((struct ethhdr*)(skb->data))->h_dest[0] == 0xFF)
1479 daddr=arcpacket->hardheader.destination=0;
1480 else
1481 daddr=arcpacket->hardheader.destination=
1482 ((struct ethhdr*)(skb->data))->h_dest[5];
1483
1484
1485 offset=512-length;
1486 if (length>MTU)
1487 {
1488 if (length<MinTU) offset-=3;
1489 arcpacket->hardheader.offset1=0;
1490 arcpacket->hardheader.offset2=offset;
1491 }
1492 else
1493 {
1494 arcpacket->hardheader.offset1=(offset-=256);
1495 }
1496
1497 BUGLVL(D_DURING)
1498 printk("arcnet: length=%Xh, offset=%Xh, offset1=%Xh, offset2=%Xh\n",
1499 length,offset,arcpacket->hardheader.offset1,
1500 arcpacket->hardheader.offset2);
1501
1502 arcsoft=&arcpacket->raw[offset];
1503 arcsoft[0]=ARC_P_MS_TCPIP;
1504 arcsoft++;
1505
1506
1507
1508
1509 BUGLVL(D_DURING) printk("arcnet: ready to memcpy\n");
1510
1511 memcpy(arcsoft,skb->data,skb->len);
1512
1513 BUGLVL(D_DURING)
1514 printk("arcnet: transmitting packet to station %02Xh (%d bytes)\n",
1515 daddr,length);
1516
1517 BUGLVL(D_TX)
1518 {
1519 int countx,county;
1520
1521 printk("arcnet: packet dump [tx] follows:");
1522
1523 for (county=0; county<16+(length>=240)*16; county++)
1524 {
1525 printk("\n[%04X] ",county*16);
1526 for (countx=0; countx<16; countx++)
1527 printk("%02X ",
1528 arcpacket->raw[county*16+countx]);
1529 }
1530
1531 printk("\n");
1532 }
1533
1534 #ifdef VERIFY_ACK
1535 lp->outgoing.lastload_dest=daddr;
1536 #endif
1537 lp->txready=lp->txbuf;
1538
1539 arcnetA_go_tx(dev);
1540 dev->trans_start = jiffies;
1541 }
1542
1543 dev_kfree_skb(skb,FREE_WRITE);
1544
1545 return 0;
1546 }
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561 static void
1562 arcnet_interrupt(int irq,struct pt_regs *regs)
1563 {
1564 struct device *dev = (struct device *)(irq2dev_map[irq]);
1565
1566 if (dev==NULL || !dev->start)
1567 {
1568 BUGLVL(D_EXTRA)
1569 printk("arcnet: irq %d for unknown device.\n", irq);
1570 return;
1571 }
1572
1573 arcnet_inthandler(dev);
1574 }
1575
1576
1577
1578
1579
1580 static void
1581 arcnet_inthandler(struct device *dev)
1582 {
1583 struct arcnet_local *lp;
1584 int ioaddr, status, boguscount = 3, didsomething;
1585
1586 if (dev->interrupt)
1587 printk("arcnet: DRIVER PROBLEM! Nested arcnet interrupts!\n");
1588
1589 dev->interrupt = 1;
1590
1591 ioaddr = dev->base_addr;
1592 lp = (struct arcnet_local *)dev->priv;
1593
1594 outb(0,INTMASK);
1595 sti();
1596
1597 BUGLVL(D_DURING)
1598 printk("arcnet: in net_interrupt (status=%Xh)\n",inb(STATUS));
1599
1600 do
1601 {
1602 status = inb(STATUS);
1603 didsomething=0;
1604
1605 if (!dev->start)
1606 {
1607 BUGLVL(D_DURING)
1608 printk("arcnet: ARCnet not yet initialized. irq ignored. (status=%Xh)\n",
1609 status);
1610 if (!(status&NORXflag))
1611 outb(NORXflag|RECON_flag,INTMASK);
1612
1613 dev->interrupt=0;
1614 return;
1615 }
1616
1617
1618
1619
1620 if (status & RESETflag)
1621 {
1622 outb(CFLAGScmd|RESETclear,COMMAND);
1623 BUGLVL(D_INIT)
1624 printk("arcnet: reset irq (status=%Xh)\n",
1625 status);
1626 }
1627 #ifdef DETECT_RECONFIGS
1628 if (status & RECONflag)
1629 {
1630 outb(CFLAGScmd|CONFIGclear,COMMAND);
1631 BUGLVL(D_EXTRA)
1632 printk("arcnet: Network reconfiguration detected (status=%Xh)\n",
1633 status);
1634 lp->stats.tx_carrier_errors++;
1635 }
1636 #endif
1637
1638
1639 if (status & NORXflag)
1640 {
1641 int recbuf=lp->recbuf=!lp->recbuf;
1642
1643 BUGLVL(D_DURING)
1644 printk("arcnet: receive irq (status=%Xh)\n",
1645 status);
1646
1647
1648 EnableReceiver();
1649
1650
1651 arcnet_rx(dev,!recbuf);
1652
1653 didsomething++;
1654 }
1655
1656
1657 if (status&TXFREEflag && !lp->in_txhandler && lp->sending)
1658 {
1659 struct Outgoing *out=&(lp->outgoing);
1660
1661 lp->in_txhandler++;
1662 lp->sending--;
1663
1664 BUGLVL(D_DURING)
1665 printk("arcnet: TX IRQ (stat=%Xh, numsegs=%d, segnum=%d, skb=%ph)\n",
1666 status,out->numsegs,out->segnum,out->skb);
1667
1668 #ifdef VERIFY_ACK
1669 if (!(status&TXACKflag))
1670 {
1671 if (lp->outgoing.lasttrans_dest != 0)
1672 {
1673 BUGLVL(D_NORMAL)
1674 printk("arcnet: transmit was not acknowledged! (status=%Xh, dest=%d)\n",
1675 status,
1676 lp->outgoing.lasttrans_dest);
1677 lp->stats.tx_errors++;
1678 }
1679 else
1680 {
1681 BUGLVL(D_DURING)
1682 printk("arcnet: broadcast was not acknowledged; that's normal (status=%Xh, dest=%d)\n",
1683 status,
1684 lp->outgoing.lasttrans_dest);
1685 }
1686 }
1687 #endif
1688
1689
1690 if (lp->txready)
1691 {
1692 arcnetA_go_tx(dev);
1693 didsomething++;
1694 }
1695
1696 if (lp->intx)
1697 {
1698 lp->in_txhandler--;
1699 continue;
1700 }
1701
1702 if (!lp->outgoing.skb)
1703 {
1704 BUGLVL(D_DURING)
1705 printk("arcnet: TX IRQ done: no split to continue.\n");
1706
1707
1708 if (!lp->txready && IF_TBUSY)
1709 {
1710 TBUSY=0;
1711 mark_bh(NET_BH);
1712 }
1713
1714 lp->in_txhandler--;
1715 continue;
1716 }
1717
1718
1719
1720
1721
1722
1723 if (out->segnum<out->numsegs)
1724 arcnetA_continue_tx(dev);
1725 if (lp->txready && !lp->sending)
1726 arcnetA_go_tx(dev);
1727
1728
1729
1730
1731 if (out->segnum>=out->numsegs)
1732 {
1733
1734 out->segnum++;
1735 if (out->skb)
1736 dev_kfree_skb(out->skb,FREE_WRITE);
1737 out->skb=NULL;
1738
1739
1740 if (!lp->txready && IF_TBUSY)
1741 {
1742 TBUSY=0;
1743 mark_bh(NET_BH);
1744 }
1745 }
1746 didsomething++;
1747
1748 lp->in_txhandler--;
1749 }
1750
1751 } while (--boguscount && didsomething);
1752
1753 BUGLVL(D_DURING)
1754 printk("arcnet: net_interrupt complete (status=%Xh)\n\n",
1755 inb(STATUS));
1756
1757 if (dev->start && lp->sending )
1758 outb(NORXflag|TXFREEflag|RECON_flag,INTMASK);
1759 else
1760 outb(NORXflag|RECON_flag,INTMASK);
1761
1762 dev->interrupt=0;
1763 }
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777 static void
1778 arcnet_rx(struct device *dev,int recbuf)
1779 {
1780 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1781 int ioaddr = dev->base_addr;
1782 union ArcPacket *arcpacket=
1783 (union ArcPacket *)(dev->mem_start+recbuf*512);
1784 u_char *arcsoft;
1785 short length,offset;
1786 u_char daddr,saddr;
1787
1788 saddr=arcpacket->hardheader.source;
1789 daddr=arcpacket->hardheader.destination;
1790
1791
1792 if (saddr==0)
1793 {
1794 printk("arcnet: discarding old packet. (status=%Xh)\n",
1795 inb(STATUS));
1796 lp->stats.rx_errors++;
1797 return;
1798 }
1799 arcpacket->hardheader.source=0;
1800
1801 if (arcpacket->hardheader.offset1)
1802 {
1803 offset=arcpacket->hardheader.offset1;
1804 arcsoft=&arcpacket->raw[offset];
1805 length=256-offset;
1806 }
1807 else
1808 {
1809 offset=arcpacket->hardheader.offset2;
1810 arcsoft=&arcpacket->raw[offset];
1811
1812 length=512-offset;
1813 }
1814
1815 BUGLVL(D_DURING)
1816 printk("arcnet: received packet from %02Xh to %02Xh (%d bytes)\n",
1817 saddr,daddr,length);
1818
1819
1820 switch (arcsoft[0])
1821 {
1822 case ARC_P_IP:
1823 case ARC_P_ARP:
1824 case ARC_P_RARP:
1825 case ARC_P_IPX:
1826 arcnetA_rx(dev,(struct ClientData*)arcsoft,
1827 length,saddr,daddr);
1828 break;
1829 case ARC_P_MS_TCPIP:
1830 arcnetW_rx(dev,arcsoft,length,saddr,daddr);
1831 break;
1832 default:
1833 printk("arcnet: received unknown protocol %d (%Xh)\n",
1834 arcsoft[0],arcsoft[0]);
1835 break;
1836 }
1837
1838 BUGLVL(D_RX)
1839 {
1840 int countx,county;
1841
1842 printk("arcnet: rx packet dump follows:");
1843
1844 for (county=0; county<16+(length>240)*16; county++)
1845 {
1846 printk("\n[%04X] ",county*16);
1847 for (countx=0; countx<16; countx++)
1848 printk("%02X ",
1849 arcpacket->raw[county*16+countx]);
1850 }
1851
1852 printk("\n");
1853 }
1854
1855
1856
1857
1858
1859
1860 }
1861
1862
1863
1864
1865 static void
1866 arcnetA_rx(struct device *dev,struct ClientData *arcsoft,
1867 int length,u_char saddr, u_char daddr)
1868 {
1869 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1870 struct sk_buff *skb;
1871 struct ClientData *soft;
1872
1873 BUGLVL(D_DURING)
1874 printk("arcnet: it's an RFC1201 packet (length=%d)\n",
1875 length);
1876
1877 arcsoft=(struct ClientData *)((u_char *)arcsoft-EXTRA_CLIENTDATA);
1878 length+=EXTRA_CLIENTDATA;
1879
1880 if (arcsoft->split_flag==0xFF)
1881 {
1882 BUGLVL(D_DURING)
1883 printk("arcnet: compensating for exception packet\n");
1884
1885
1886 arcsoft=(struct ClientData *)
1887 ((u_char *)arcsoft + 4);
1888 length-=4;
1889 }
1890
1891 if (!arcsoft->split_flag)
1892 {
1893 struct Incoming *in=&lp->incoming[saddr];
1894
1895 BUGLVL(D_RX) printk("arcnet: incoming is not split (splitflag=%d)\n",
1896 arcsoft->split_flag);
1897
1898 if (in->skb)
1899 {
1900 BUGLVL(D_EXTRA) printk("arcnet: aborting assembly (seq=%d) for unsplit packet (splitflag=%d, seq=%d)\n",
1901 in->sequence,arcsoft->split_flag,
1902 arcsoft->sequence);
1903 kfree_skb(in->skb,FREE_WRITE);
1904 lp->stats.tx_dropped++;
1905 lp->stats.rx_errors++;
1906 in->skb=NULL;
1907 }
1908
1909 in->sequence=arcsoft->sequence;
1910
1911 skb = alloc_skb(length, GFP_ATOMIC);
1912 if (skb == NULL) {
1913 printk("arcnet: Memory squeeze, dropping packet.\n");
1914 lp->stats.rx_dropped++;
1915 return;
1916 }
1917 soft=(struct ClientData *)skb->data;
1918
1919 skb->len = length;
1920 skb->dev = dev;
1921
1922 memcpy((u_char *)soft+EXTRA_CLIENTDATA,
1923 (u_char *)arcsoft+EXTRA_CLIENTDATA,
1924 length-EXTRA_CLIENTDATA);
1925 soft->daddr=daddr;
1926 soft->saddr=saddr;
1927
1928
1929
1930
1931
1932
1933 if (soft->protocol_id == ARC_P_ARP)
1934 {
1935 struct arphdr *arp=(struct arphdr *)
1936 ((char *)soft+sizeof(struct ClientData));
1937
1938
1939 if (arp->ar_hln==1 && arp->ar_pln==4)
1940 {
1941 char *cptr=(char *)(arp)+sizeof(struct arphdr);
1942
1943 if (!*cptr)
1944 {
1945 BUGLVL(D_EXTRA)
1946 printk("arcnet: ARP source address was 00h, set to %02Xh.\n",
1947 saddr);
1948 *cptr=saddr;
1949 }
1950 else BUGLVL(D_DURING)
1951 {
1952 printk("arcnet: ARP source address (%Xh) is fine.\n",
1953 *cptr);
1954 }
1955 }
1956 else
1957 {
1958 printk("arcnet: funny-shaped ARP packet. (%Xh, %Xh)\n",
1959 arp->ar_hln,arp->ar_pln);
1960 lp->stats.rx_frame_errors++;
1961 }
1962 }
1963
1964 BUGLVL(D_SKB)
1965 {
1966 short i;
1967 for( i=0; i< skb->len; i++)
1968 {
1969 if( i%16 == 0 ) printk("\n[%04hX] ",i);
1970 printk("%02hX ",((unsigned char*)skb->data)[i]);
1971 }
1972 printk("\n");
1973 }
1974
1975 skb->protocol=arcnetA_type_trans(skb,dev);
1976
1977 netif_rx(skb);
1978 lp->stats.rx_packets++;
1979 }
1980 else
1981 {
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999 struct Incoming *in=&lp->incoming[saddr];
2000
2001 BUGLVL(D_RX) printk("arcnet: packet is split (splitflag=%d, seq=%d)\n",
2002 arcsoft->split_flag,in->sequence);
2003
2004 if (in->skb && in->sequence!=arcsoft->sequence)
2005 {
2006 BUGLVL(D_EXTRA) printk("arcnet: wrong seq number, aborting assembly (expected=%d, seq=%d, splitflag=%d)\n",
2007 in->sequence,arcsoft->sequence,
2008 arcsoft->split_flag);
2009 kfree_skb(in->skb,FREE_WRITE);
2010 in->skb=NULL;
2011 lp->stats.tx_dropped++;
2012 lp->stats.rx_fifo_errors++;
2013 in->lastpacket=in->numpackets=0;
2014 }
2015
2016 if (arcsoft->split_flag & 1)
2017 {
2018 BUGLVL(D_RX) printk("arcnet: brand new splitpacket (splitflag=%d)\n",
2019 arcsoft->split_flag);
2020 if (in->skb)
2021 {
2022 BUGLVL(D_EXTRA) printk("arcnet: aborting previous (seq=%d) assembly (splitflag=%d, seq=%d)\n",
2023 in->sequence,arcsoft->split_flag,
2024 arcsoft->sequence);
2025 lp->stats.tx_dropped++;
2026 lp->stats.rx_over_errors++;
2027 kfree_skb(in->skb,FREE_WRITE);
2028 }
2029
2030 in->sequence=arcsoft->sequence;
2031 in->numpackets=((unsigned)arcsoft->split_flag>>1)+2;
2032 in->lastpacket=1;
2033
2034 if (in->numpackets>16)
2035 {
2036 BUGLVL(D_EXTRA) printk("arcnet: incoming packet more than 16 segments; dropping. (splitflag=%d)\n",
2037 arcsoft->split_flag);
2038 lp->stats.rx_dropped++;
2039 return;
2040 }
2041
2042 in->skb=skb=alloc_skb(508*in->numpackets
2043 + sizeof(struct ClientData),
2044 GFP_ATOMIC);
2045 if (skb == NULL) {
2046 printk("%s: (split) memory squeeze, dropping packet.\n",
2047 dev->name);
2048 lp->stats.rx_dropped++;
2049 return;
2050 }
2051
2052
2053
2054
2055 skb->free=1;
2056
2057 soft=(struct ClientData *)skb->data;
2058
2059 skb->len=sizeof(struct ClientData);
2060 skb->dev=dev;
2061
2062 memcpy((u_char *)soft+EXTRA_CLIENTDATA,
2063 (u_char *)arcsoft+EXTRA_CLIENTDATA,
2064 sizeof(struct ClientData)-EXTRA_CLIENTDATA);
2065 soft->split_flag=0;
2066 }
2067 else
2068 {
2069 int packetnum=((unsigned)arcsoft->split_flag>>1) + 1;
2070
2071
2072
2073
2074 if (!in->skb)
2075 {
2076 BUGLVL(D_EXTRA) printk("arcnet: can't continue split without starting first! (splitflag=%d, seq=%d)\n",
2077 arcsoft->split_flag,arcsoft->sequence);
2078 lp->stats.rx_errors++;
2079 return;
2080 }
2081
2082 in->lastpacket++;
2083 if (packetnum!=in->lastpacket)
2084 {
2085
2086 if (packetnum<=in->lastpacket-1)
2087 {
2088 BUGLVL(D_EXTRA) printk("arcnet: duplicate splitpacket ignored! (splitflag=%d)\n",
2089 arcsoft->split_flag);
2090 return;
2091 }
2092
2093
2094 BUGLVL(D_EXTRA) printk("arcnet: out-of-order splitpacket, reassembly (seq=%d) aborted (splitflag=%d, seq=%d)\n",
2095 in->sequence,arcsoft->split_flag,
2096 arcsoft->sequence);
2097 kfree_skb(in->skb,FREE_WRITE);
2098 in->skb=NULL;
2099 lp->stats.tx_dropped++;
2100 lp->stats.rx_fifo_errors++;
2101 in->lastpacket=in->numpackets=0;
2102 return;
2103 }
2104
2105 soft=(struct ClientData *)in->skb->data;
2106 }
2107
2108 skb=in->skb;
2109
2110 memcpy(skb->data+skb->len,
2111 (u_char *)arcsoft+sizeof(struct ClientData),
2112 length-sizeof(struct ClientData));
2113
2114 skb->len+=length-sizeof(struct ClientData);
2115
2116 soft->daddr=daddr;
2117 soft->saddr=saddr;
2118
2119
2120 if (in->lastpacket == in->numpackets)
2121 {
2122 if (!skb || !in->skb)
2123 printk("arcnet: ?!? done reassembling packet, no skb? (skb=%ph, in->skb=%ph)\n",
2124 skb,in->skb);
2125 in->skb=NULL;
2126 in->lastpacket=in->numpackets=0;
2127
2128 BUGLVL(D_SKB)
2129 {
2130 short i;
2131 for( i=0; i< skb->len; i++)
2132 {
2133 if( i%16 == 0 ) printk("\n[%04hX] ",i);
2134 printk("%02hX ",((unsigned char*)skb->data)[i]);
2135 }
2136 printk("\n");
2137 }
2138
2139 skb->protocol=arcnetA_type_trans(skb,dev);
2140
2141 netif_rx(skb);
2142 lp->stats.rx_packets++;
2143 }
2144 }
2145 }
2146
2147
2148
2149
2150 static void
2151 arcnetW_rx(struct device *dev,u_char *arcsoft,
2152 int length,u_char saddr, u_char daddr)
2153 {
2154 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
2155 struct sk_buff *skb;
2156
2157 BUGLVL(D_DURING)
2158 printk("arcnet: it's a Windows packet (length=%d)\n",
2159 length);
2160
2161 skb = alloc_skb(length, GFP_ATOMIC);
2162 if (skb == NULL) {
2163 printk("arcnet: Memory squeeze, dropping packet.\n");
2164 lp->stats.rx_dropped++;
2165 return;
2166 }
2167
2168 skb->len = length;
2169 skb->dev = lp->wdev;
2170
2171 memcpy(skb->data,(u_char *)arcsoft+1,length-1);
2172
2173 BUGLVL(D_SKB)
2174 {
2175 short i;
2176 printk("arcnet: rx skb dump follows:\n");
2177 for(i=0; i<skb->len; i++)
2178 {
2179 if (i%16==0)
2180 printk("\n[%04hX] ",i);
2181 else
2182 printk("%02hX ",((u_char *)skb->data)[i]);
2183 }
2184 printk("\n");
2185 }
2186
2187 skb->protocol=eth_type_trans(skb,dev);
2188
2189 netif_rx(skb);
2190 lp->stats.rx_packets++;
2191 }
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205 static struct enet_statistics *
2206 arcnet_get_stats(struct device *dev)
2207 {
2208 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
2209
2210 return &lp->stats;
2211 }
2212
2213
2214
2215
2216
2217
2218
2219 static void
2220 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
2221 {
2222 #if 0
2223 struct arcnet_local *lp=(struct arcnet_local *)(dev->priv);
2224
2225 short ioaddr = dev->base_addr;
2226 if (num_addrs) {
2227 outw(69, ioaddr);
2228 } else
2229 outw(99, ioaddr);
2230 #endif
2231 }
2232
2233
2234
2235
2236
2237
2238 int arcnetA_header(struct sk_buff *skb,struct device *dev,unsigned short type,
2239 void *daddr,void *saddr,unsigned len)
2240 {
2241 struct ClientData *head = (struct ClientData *)
2242 skb_push(skb,dev->hard_header_len);
2243
2244
2245
2246 switch(type)
2247 {
2248 case ETH_P_IP:
2249 head->protocol_id=ARC_P_IP;
2250 break;
2251 case ETH_P_ARP:
2252 head->protocol_id=ARC_P_ARP;
2253 break;
2254 case ETH_P_RARP:
2255 head->protocol_id=ARC_P_RARP;
2256 break;
2257 case ETH_P_IPX:
2258 head->protocol_id=ARC_P_IPX;
2259 break;
2260 case ETH_P_ATALK:
2261 head->protocol_id=ARC_P_ATALK;
2262 break;
2263 default:
2264 printk("arcnet: I don't understand protocol %d (%Xh)\n",
2265 type,type);
2266 return 0;
2267 }
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277 if(saddr)
2278 head->saddr=((u_char*)saddr)[0];
2279 else
2280 head->saddr=((u_char*)(dev->dev_addr))[0];
2281
2282 #if 0
2283
2284
2285
2286
2287
2288
2289 if (dev->flags & IFF_LOOPBACK)
2290 {
2291 head->daddr=0;
2292 return(dev->hard_header_len);
2293 }
2294 #endif
2295
2296 head->split_flag=0;
2297 head->sequence=0;
2298
2299
2300 if(daddr)
2301 {
2302 head->daddr=((u_char*)daddr)[0];
2303 return dev->hard_header_len;
2304 }
2305 else
2306 head->daddr=0;
2307
2308 return -dev->hard_header_len;
2309 }
2310
2311
2312
2313
2314
2315
2316 int arcnetA_rebuild_header(void *buff,struct device *dev,unsigned long dst,
2317 struct sk_buff *skb)
2318 {
2319 struct ClientData *head = (struct ClientData *)buff;
2320
2321
2322
2323
2324
2325 if(head->protocol_id != ARC_P_IP)
2326 {
2327 printk("arcnet: I don't understand resolve type %d (%Xh) addresses!\n",
2328 head->protocol_id,head->protocol_id);
2329 head->daddr=0;
2330
2331 return 0;
2332 }
2333
2334
2335
2336
2337 #ifdef CONFIG_INET
2338 return arp_find(&(head->daddr), dst, dev, dev->pa_addr, skb)? 1 : 0;
2339 #else
2340 return 0;
2341 #endif
2342 }
2343
2344
2345
2346
2347
2348 unsigned short arcnetA_type_trans(struct sk_buff *skb,struct device *dev)
2349 {
2350 struct ClientData *head = (struct ClientData *) skb->data;
2351 struct arcnet_local *lp=(struct arcnet_local *) (dev->priv);
2352
2353
2354 skb->mac.raw=skb->data;
2355 skb_pull(skb,dev->hard_header_len);
2356
2357 if (head->daddr==0)
2358 skb->pkt_type=PACKET_BROADCAST;
2359 else if (dev->flags&IFF_PROMISC)
2360 {
2361
2362 if (head->daddr != dev->dev_addr[0])
2363 skb->pkt_type=PACKET_OTHERHOST;
2364 }
2365
2366
2367 switch (head->protocol_id)
2368 {
2369 case ARC_P_IP: return htons(ETH_P_IP);
2370 case ARC_P_ARP: return htons(ETH_P_ARP);
2371 case ARC_P_RARP: return htons(ETH_P_RARP);
2372 case ARC_P_IPX: return htons(ETH_P_IPX);
2373 case ARC_P_ATALK: return htons(ETH_P_ATALK);
2374 case ARC_P_LANSOFT:
2375 default:
2376 BUGLVL(D_EXTRA)
2377 printk("arcnet: received packet of unknown protocol id %d (%Xh)\n",
2378 head->protocol_id,head->protocol_id);
2379 lp->stats.rx_frame_errors++;
2380 return 0;
2381 }
2382
2383 return htons(ETH_P_IP);
2384 }
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395 #ifdef MODULE
2396 char kernel_version[] = UTS_RELEASE;
2397 static struct device thiscard = {
2398 " ",
2399 0, 0, 0, 0,
2400 0, 0,
2401 0, 0, 0, NULL, arcnet_probe };
2402
2403
2404 int io=0x0;
2405 int irqnum=0;
2406 int shmem=0;
2407 int num=0;
2408
2409 int
2410 init_module(void)
2411 {
2412 sprintf(thiscard.name,"arc%d",num);
2413
2414 thiscard.base_addr=io;
2415
2416 thiscard.irq=irqnum;
2417 if (thiscard.irq==2) thiscard.irq=9;
2418
2419 if (shmem)
2420 {
2421 thiscard.mem_start=shmem;
2422 thiscard.mem_end=thiscard.mem_start+512*4-1;
2423 thiscard.rmem_start=thiscard.mem_start+512*0;
2424 thiscard.rmem_end=thiscard.mem_start+512*2-1;
2425 }
2426
2427 if (register_netdev(&thiscard) != 0)
2428 return -EIO;
2429 return 0;
2430 }
2431
2432 void
2433 cleanup_module(void)
2434 {
2435 if (MOD_IN_USE)
2436 {
2437 printk("%s: device busy, remove delayed\n",thiscard.name);
2438 }
2439 else
2440 {
2441 if (thiscard.start) arcnet_close(&thiscard);
2442 if (thiscard.irq) free_irq(thiscard.irq);
2443 if (thiscard.base_addr) release_region(thiscard.base_addr,
2444 ARCNET_TOTAL_SIZE);
2445 unregister_netdev(&thiscard);
2446 }
2447 }
2448
2449 #endif
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461