This source file includes following definitions.
- arcnet_probe
- arcnet_ioprobe
- arcnet_memprobe
- arcnet_reset
- arcnet_setup
- arcnetE_init
- arcnetS_init
- arcnet_open
- arcnet_close
- arcnet_send_packet_bad
- arcnetA_send_packet
- arcnetE_send_packet
- arcnetS_send_packet
- arcnetA_continue_tx
- arcnetAS_prepare_tx
- arcnet_go_tx
- arcnet_interrupt
- arcnet_inthandler
- arcnet_rx
- arcnetA_rx
- arcnetE_rx
- arcnetS_rx
- arcnet_get_stats
- set_multicast_list
- arcnetA_header
- arcnetS_header
- arcnetA_rebuild_header
- arcnetS_rebuild_header
- arcnetA_type_trans
- arcnetS_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
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 static const char *version =
159 "arcnet.c: v2.20 ALPHA 95/11/12 Avery Pennarun <apenwarr@foxnet.net>\n";
160
161
162
163 #include <linux/module.h>
164 #include <linux/config.h>
165 #include <linux/version.h>
166
167
168 #if LINUX_VERSION_CODE < 0x10300
169 #define LINUX12
170 #endif
171
172
173 #include <linux/kernel.h>
174 #include <linux/sched.h>
175 #include <linux/types.h>
176 #include <linux/fcntl.h>
177 #include <linux/interrupt.h>
178 #include <linux/ptrace.h>
179 #include <linux/ioport.h>
180 #include <linux/in.h>
181 #include <linux/malloc.h>
182 #include <linux/string.h>
183 #include <linux/timer.h>
184 #include <linux/errno.h>
185 #include <linux/delay.h>
186 #include <linux/if_arp.h>
187 #include <linux/netdevice.h>
188 #include <linux/etherdevice.h>
189 #include <linux/skbuff.h>
190
191
192
193 #include <asm/system.h>
194 #include <asm/bitops.h>
195 #include <asm/io.h>
196 #include <asm/dma.h>
197
198 #ifdef LINUX12
199 #include "arp.h"
200 #else
201 #include <net/arp.h>
202 #endif
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220 #define DETECT_RECONFIGS
221 #undef SHOW_RECONFIGS
222
223
224
225
226
227
228
229
230
231
232
233 #define RECON_THRESHOLD 30
234
235
236
237
238
239
240
241
242
243 #define VERIFY_ACK
244
245
246
247
248
249
250 #define TX_TIMEOUT 20
251
252
253
254
255
256
257 #undef static
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274 #define D_NORMAL 1
275 #define D_INIT 2
276 #define D_EXTRA 4
277
278 #define D_DURING 8
279 #define D_TX 16
280 #define D_RX 32
281 #define D_SKB 64
282
283 #ifndef ARCNET_DEBUG_MAX
284 #define ARCNET_DEBUG_MAX (~0)
285
286
287 #endif
288
289 #ifndef ARCNET_DEBUG
290 #define ARCNET_DEBUG (D_NORMAL|D_INIT|D_EXTRA)
291
292 #endif
293 int arcnet_debug = ARCNET_DEBUG;
294
295
296 #define BUGLVL(x) if ((ARCNET_DEBUG_MAX)&arcnet_debug&(x))
297 #define BUGMSG(x,msg,args...) BUGLVL(x) printk("%6s: " msg, dev->name , ## args);
298
299 #ifndef HAVE_AUTOIRQ
300
301 extern void autoirq_setup(int waittime);
302 extern int autoirq_report(int waittime);
303
304
305 extern struct device *irq2dev_map[16];
306 #endif
307
308 #ifndef HAVE_PORTRESERVE
309 #define check_region(ioaddr, size) 0
310 #define request_region(ioaddr, size) do ; while (0)
311 #endif
312
313
314 #define TBUSY lp->adev->tbusy \
315 =lp->edev->tbusy \
316 =lp->sdev->tbusy
317 #define IF_TBUSY (lp->adev->tbusy \
318 || lp->edev->tbusy \
319 || lp->sdev->tbusy)
320
321 #define INTERRUPT lp->adev->interrupt \
322 =lp->edev->interrupt \
323 =lp->sdev->interrupt
324 #define IF_INTERRUPT (lp->adev->interrupt \
325 || lp->edev->interrupt \
326 || lp->sdev->interrupt)
327
328 #define START lp->adev->start \
329 =lp->edev->start \
330 =lp->sdev->start
331
332
333
334 #define ARCNET_TOTAL_SIZE 16
335
336
337
338
339 #define INTMASK (ioaddr+0)
340 #define STATUS (ioaddr+0)
341 #define COMMAND (ioaddr+1)
342 #define RESET (ioaddr+8)
343
344
345
346 #define RESETtime 40
347 #define XMITtime 10
348 #define ACKtime 10
349
350
351
352
353
354
355
356
357
358 #define MTU 253
359 #define MinTU 257
360 #define XMTU 508
361
362
363 #define TXFREEflag 0x01
364 #define TXACKflag 0x02
365 #define RECONflag 0x04
366 #define TESTflag 0x08
367 #define RESETflag 0x10
368 #define RES1flag 0x20
369 #define RES2flag 0x40
370 #define NORXflag 0x80
371
372 #ifdef DETECT_RECONFIGS
373 #define RECON_flag RECONflag
374 #else
375 #define RECON_flag 0
376 #endif
377
378
379
380
381
382
383 #define NOTXcmd 0x01
384 #define NORXcmd 0x02
385 #define TXcmd 0x03
386 #define RXcmd 0x04
387 #define CONFIGcmd 0x05
388 #define CFLAGScmd 0x06
389 #define TESTcmd 0x07
390
391
392 #define RESETclear 0x08
393 #define CONFIGclear 0x10
394
395
396 #define TESTload 0x08
397
398
399 #define TESTvalue 0321
400
401
402 #define RXbcasts 0x80
403
404
405 #define NORMALconf 0x00
406 #define EXTconf 0x08
407
408
409
410 #define EnableReceiver() outb(RXcmd|(recbuf<<3)|RXbcasts,COMMAND)
411
412
413 #define ARC_P_IP 212
414 #define ARC_P_ARP 213
415 #define ARC_P_RARP 214
416 #define ARC_P_IPX 250
417
418
419 #define ARC_P_IP_RFC1051 240
420 #define ARC_P_ARP_RFC1051 241
421
422
423 #define ARC_P_ETHER 0xE8
424
425
426 #define ARC_P_LANSOFT 251
427 #define ARC_P_ATALK 0xDD
428
429
430 struct HardHeader
431 {
432 u_char source,
433 destination,
434 offset1,
435 offset2;
436 };
437
438
439 union ArcPacket
440 {
441 struct HardHeader hardheader;
442 u_char raw[512];
443 };
444
445
446
447
448
449 struct ClientData
450 {
451
452
453
454 u_char saddr,
455 daddr;
456
457
458 u_char protocol_id,
459 split_flag;
460 u_short sequence;
461 };
462 #define EXTRA_CLIENTDATA (sizeof(struct ClientData)-4)
463
464
465
466
467
468
469 struct S_ClientData
470 {
471
472
473
474 u_char saddr,
475 daddr,
476 junk;
477
478
479 u_char protocol_id;
480 };
481 #define S_EXTRA_CLIENTDATA (sizeof(struct S_ClientData)-1)
482
483
484
485
486
487 struct Incoming
488 {
489 struct sk_buff *skb;
490 unsigned char lastpacket,
491 numpackets;
492 u_short sequence;
493 };
494
495 struct Outgoing
496 {
497 struct sk_buff *skb;
498 struct ClientData *hdr;
499 u_char *data;
500 short length,
501 dataleft,
502 segnum,
503 numsegs,
504 seglen;
505 #ifdef VERIFY_ACK
506 short lastload_dest,
507 lasttrans_dest;
508 #endif
509
510 };
511
512
513
514 struct arcnet_local {
515 struct enet_statistics stats;
516 u_char arcnum;
517 u_short sequence;
518 u_char recbuf,
519 txbuf,
520 txready;
521 short intx,
522 in_txhandler,
523 sending;
524 short tx_left;
525
526 #if defined(DETECT_RECONFIGS) && defined(RECON_THRESHOLD)
527 time_t first_recon,
528 last_recon;
529 int num_recons,
530 network_down;
531 #endif
532
533 struct timer_list timer;
534 struct Incoming incoming[256];
535 struct Outgoing outgoing;
536
537 struct device *adev,
538 *edev,
539 *sdev;
540 };
541
542
543
544 extern int arcnet_probe(struct device *dev);
545 #ifndef MODULE
546 static int arcnet_memprobe(struct device *dev,u_char *addr);
547 static int arcnet_ioprobe(struct device *dev, short ioaddr);
548 #endif
549 static void arcnet_setup(struct device *dev);
550 static int arcnetE_init(struct device *dev);
551 static int arcnetS_init(struct device *dev);
552
553 static int arcnet_open(struct device *dev);
554 static int arcnet_close(struct device *dev);
555 static int arcnet_reset(struct device *dev);
556
557 static int arcnet_send_packet_bad(struct sk_buff *skb,struct device *dev);
558 static int arcnetA_send_packet(struct sk_buff *skb, struct device *dev);
559 static int arcnetE_send_packet(struct sk_buff *skb, struct device *dev);
560 static int arcnetS_send_packet(struct sk_buff *skb, struct device *dev);
561 static void arcnetA_continue_tx(struct device *dev);
562 static void arcnetAS_prepare_tx(struct device *dev,u_char *hdr,int hdrlen,
563 char *data,int length,int daddr,int exceptA);
564 static int arcnet_go_tx(struct device *dev,int enable_irq);
565
566 static void arcnet_interrupt(int irq,struct pt_regs *regs);
567 static void arcnet_inthandler(struct device *dev);
568
569 static void arcnet_rx(struct device *dev,int recbuf);
570 static void arcnetA_rx(struct device *dev,u_char *buf,
571 int length,u_char saddr, u_char daddr);
572 static void arcnetE_rx(struct device *dev,u_char *arcsoft,
573 int length,u_char saddr, u_char daddr);
574 static void arcnetS_rx(struct device *dev,u_char *buf,
575 int length,u_char saddr, u_char daddr);
576
577 static struct enet_statistics *arcnet_get_stats(struct device *dev);
578 static void set_multicast_list(struct device *dev, int num_addrs, void *addrs);
579
580
581 #ifdef LINUX12
582 int arcnetA_header(unsigned char *buff,struct device *dev,
583 unsigned short type,void *daddr,void *saddr,unsigned len,
584 struct sk_buff *skb);
585 int arcnetS_header(unsigned char *buff,struct device *dev,
586 unsigned short type,void *daddr,void *saddr,unsigned len,
587 struct sk_buff *skb);
588 #else
589 int arcnetA_header(struct sk_buff *skb,struct device *dev,
590 unsigned short type,void *daddr,void *saddr,unsigned len);
591 int arcnetS_header(struct sk_buff *skb,struct device *dev,
592 unsigned short type,void *daddr,void *saddr,unsigned len);
593 #endif
594 int arcnetA_rebuild_header(void *eth,struct device *dev,unsigned long raddr,
595 struct sk_buff *skb);
596 int arcnetS_rebuild_header(void *eth,struct device *dev,unsigned long raddr,
597 struct sk_buff *skb);
598 unsigned short arcnetA_type_trans(struct sk_buff *skb,struct device *dev);
599 unsigned short arcnetS_type_trans(struct sk_buff *skb,struct device *dev);
600
601 #ifdef MODULE
602 int init_module(void);
603 void cleanup_module(void);
604 #endif
605
606 #define tx_done(dev) 1
607
608 #define JIFFER(time) for (delayval=0; delayval<(time*10); delayval++) \
609 udelay(1000);
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624 int
625 arcnet_probe(struct device *dev)
626 {
627 #ifndef MODULE
628
629
630
631 int *port, ports[] = {
632 0x300,0x2E0,0x2F0,0x2D0,
633
634 0x200,0x210,0x220,0x230,0x240,0x250,0x260,0x270,
635 0x280,0x290,0x2a0,0x2b0,0x2c0,
636 0x310,0x320,0x330,0x340,0x350,0x360,0x370,
637 0x380,0x390,0x3a0,0x3e0,0x3f0,
638
639 0};
640
641
642 unsigned long *addr, addrs[] = {0xD0000,0xE0000,0xA0000,0xB0000,
643 0xC0000,0xF0000,
644
645 0xE1000,
646 0xDD000,0xDC000,
647 0xD9000,0xD8000,0xD5000,0xD4000,0xD1000,
648 0xCD000,0xCC000,
649 0xC9000,0xC8000,0xC5000,0xC4000,
650
651 0};
652 int base_addr=dev->base_addr, status=0;
653 #endif
654 int delayval;
655 struct arcnet_local *lp;
656
657 printk(version);
658
659 #if 1
660 BUGLVL(D_NORMAL)
661 {
662 printk("arcnet: ***\n");
663 printk("arcnet: * Read README.arcnet for important release notes!\n");
664 printk("arcnet: *\n");
665 printk("arcnet: * This is an ALPHA version! (Last stable release: v2.00) E-mail me if\n");
666 printk("arcnet: * you have any questions, comments, or bug reports.\n");
667 printk("arcnet: ***\n");
668 }
669 #else
670 BUGLVL(D_INIT)
671 {
672 printk("arcnet: ***\n");
673 printk("arcnet: * Read README.arcnet for important release notes!\n");
674 printk("arcnet: *\n");
675 printk("arcnet: * This version should be stable, but please e-mail\n");
676 printk("arcnet: * me if you have any questions or comments.\n");
677 printk("arcnet: ***\n");
678 }
679 #endif
680
681 BUGMSG(D_INIT,"given: base %lXh, IRQ %Xh, shmem %lXh\n",
682 dev->base_addr,dev->irq,dev->mem_start);
683
684 #ifndef MODULE
685 if (base_addr > 0x1ff)
686 status=arcnet_ioprobe(dev, base_addr);
687 else if (base_addr > 0)
688 return ENXIO;
689 else for (port = &ports[0]; *port; port++)
690 {
691 int ioaddr = *port;
692 if (check_region(ioaddr, ARCNET_TOTAL_SIZE))
693 {
694 BUGMSG(D_INIT,"Skipping %Xh because of check_region...\n",
695 ioaddr);
696 continue;
697 }
698
699 status=arcnet_ioprobe(dev, ioaddr);
700 if (!status) break;
701 }
702
703 if (status) return status;
704
705
706
707
708 BUGMSG(D_INIT,"ioprobe okay! Waiting for reset...\n");
709 JIFFER(100);
710
711
712 BUGMSG(D_INIT,"starting memory probe, given %lXh\n",
713 dev->mem_start);
714 if (dev->mem_start)
715 {
716 status=arcnet_memprobe(dev,(u_char *)dev->mem_start);
717 if (status) return status;
718 }
719 else
720 {
721 for (addr = &addrs[0]; *addr; addr++) {
722 status=arcnet_memprobe(dev,(u_char *)(*addr));
723 if (!status) break;
724 }
725
726 if (status) return status;
727 }
728 #else
729 if (!dev->base_addr || !dev->irq || !dev->mem_start
730 || !dev->rmem_start)
731 {
732 printk("%6s: loadable modules can't autoprobe!\n",dev->name);
733 printk("%6s: try using io=, irqnum=, and shmem= on the insmod line.\n",
734 dev->name);
735 printk("%6s: you may also need num= to change the device name. (ie. num=1 for arc1)\n",
736 dev->name);
737 return ENODEV;
738 }
739 #endif
740
741 {
742 int irqval = request_irq(dev->irq, &arcnet_interrupt, 0,
743 "arcnet");
744 if (irqval) {
745 printk("%6s: unable to get IRQ %d (irqval=%d).\n",
746 dev->name,dev->irq, irqval);
747 return EAGAIN;
748 }
749 }
750
751
752 request_region(dev->base_addr, ARCNET_TOTAL_SIZE,"arcnet");
753
754 printk("%6s: ARCnet card found at %03lXh, IRQ %d, ShMem at %lXh.\n",
755 dev->name, dev->base_addr, dev->irq, dev->mem_start);
756
757
758 dev->priv = kmalloc(sizeof(struct arcnet_local), GFP_KERNEL);
759 if (dev->priv == NULL)
760 return -ENOMEM;
761 memset(dev->priv, 0, sizeof(struct arcnet_local));
762 lp=(struct arcnet_local *)(dev->priv);
763
764 dev->open=arcnet_open;
765 dev->stop=arcnet_close;
766 dev->hard_start_xmit=arcnetA_send_packet;
767 dev->get_stats=arcnet_get_stats;
768 #ifdef HAVE_MULTICAST
769 dev->set_multicast_list = &set_multicast_list;
770 #endif
771
772
773
774
775 arcnet_setup(dev);
776
777
778 dev->mtu=1500;
779 dev->hard_header_len=sizeof(struct ClientData);
780 BUGMSG(D_DURING,"ClientData header size is %d.\n",
781 sizeof(struct ClientData));
782 BUGMSG(D_DURING,"HardHeader size is %d.\n",
783 sizeof(struct HardHeader));
784
785
786
787
788
789 BUGMSG(D_INIT,"arcnet_probe: resetting card.\n");
790 arcnet_reset(dev);
791 JIFFER(50);
792 BUGMSG(D_NORMAL,"We appear to be station %d (%02Xh)\n",
793 lp->arcnum,lp->arcnum);
794 if (lp->arcnum==0)
795 printk("%6s: WARNING! Station address 0 is reserved for broadcasts!\n",
796 dev->name);
797 if (lp->arcnum==255)
798 printk("%6s: WARNING! Station address 255 may confuse DOS networking programs!\n",
799 dev->name);
800 dev->dev_addr[0]=lp->arcnum;
801 lp->sequence=1;
802 lp->recbuf=0;
803
804 dev->hard_header=arcnetA_header;
805 dev->rebuild_header=arcnetA_rebuild_header;
806
807 #ifdef LINUX12
808 dev->type_trans=arcnetA_type_trans;
809 #endif
810
811 return 0;
812 }
813
814 #ifndef MODULE
815
816 int arcnet_ioprobe(struct device *dev, short ioaddr)
817 {
818 int delayval,airq;
819
820 BUGMSG(D_INIT,"probing address %Xh\n",ioaddr);
821 BUGMSG(D_INIT," status1=%Xh\n",inb(STATUS));
822
823
824
825
826
827
828
829
830 inb(RESET);
831 JIFFER(RESETtime);
832
833
834 if (inb(STATUS)==0xFF)
835 {
836 BUGMSG(D_INIT," probe failed. Status port empty.\n");
837 return ENODEV;
838 }
839
840 #if 0
841
842
843
844
845
846 {
847 int initval,curval;
848
849 curval=initval=inb(COMMAND);
850 delayval=jiffies+5;
851 while (delayval>=jiffies && curval==initval)
852 curval=inb(COMMAND);
853
854 if (curval==initval)
855 {
856 BUGLVL(D_INIT," probe failed. never-changing command port (%02Xh).\n",
857 initval);
858 return ENODEV;
859 }
860 }
861 #endif
862
863 BUGMSG(D_INIT," status2=%Xh\n",inb(STATUS));
864
865
866 outb(CFLAGScmd|RESETclear|CONFIGclear,COMMAND);
867 if (inb(STATUS) & RESETflag)
868 {
869 BUGMSG(D_INIT," probe failed. eternal reset flag1...(status=%Xh)\n",
870 inb(STATUS));
871 return ENODEV;
872 }
873
874
875 autoirq_setup(0);
876
877
878
879
880
881
882
883
884
885 outb(NORXflag,INTMASK);
886 JIFFER(RESETtime);
887 outb(0,INTMASK);
888
889
890 outb(CFLAGScmd|RESETclear|CONFIGclear,COMMAND);
891
892 airq = autoirq_report(0);
893 BUGLVL(D_INIT) if (airq)
894 printk("%6s: autoirq is %d\n", dev->name, airq);
895
896
897
898
899 if (!airq && !(dev->base_addr && dev->irq))
900 {
901 BUGMSG(D_INIT," probe failed. no autoirq...\n");
902 return ENODEV;
903 }
904
905
906
907 if (inb(STATUS) & RESETflag)
908 {
909
910 outb(CFLAGScmd|RESETclear|CONFIGclear,COMMAND);
911 }
912
913 if (inb(STATUS) & RESETflag)
914 {
915 BUGMSG(D_INIT," probe failed. eternal reset flag...(status=%Xh)\n",
916 inb(STATUS));
917 return ENODEV;
918 }
919
920
921 if (!dev->base_addr) dev->base_addr=ioaddr;
922
923 if (dev->irq < 2)
924 {
925
926 dev->irq=airq;
927 }
928 else if (dev->irq == 2)
929 {
930 BUGMSG(D_NORMAL,"IRQ2 == IRQ9, don't worry.\n");
931 dev->irq = 9;
932 }
933
934 BUGMSG(D_INIT,"irq and base address seem okay. (%lXh, IRQ %d)\n",
935 dev->base_addr,dev->irq);
936 return 0;
937 }
938
939
940
941
942
943
944 int arcnet_memprobe(struct device *dev,u_char *addr)
945 {
946 BUGMSG(D_INIT,"probing memory at %lXh\n",(u_long)addr);
947
948 dev->mem_start=0;
949
950
951 if (addr[0]!=TESTvalue)
952 {
953 BUGMSG(D_INIT," probe failed. addr=%lXh, addr[0]=%Xh (not %Xh)\n",
954 (unsigned long)addr,addr[0],TESTvalue);
955 return ENODEV;
956 }
957
958
959 addr[0]=0x42;
960 if (addr[0]!=0x42)
961 {
962 BUGMSG(D_INIT," probe failed. addr=%lXh, addr[0]=%Xh (not 42h)\n",
963 (unsigned long)addr,addr[0]);
964 return ENODEV;
965 }
966
967
968 dev->mem_start=(unsigned long)addr;
969 dev->mem_end=dev->mem_start+512*4-1;
970 dev->rmem_start=dev->mem_start+512*0;
971 dev->rmem_end=dev->mem_start+512*2-1;
972
973 return 0;
974 }
975
976 #endif
977
978
979
980
981 int arcnet_reset(struct device *dev)
982 {
983 struct arcnet_local *lp=(struct arcnet_local *)dev->priv;
984 short ioaddr=dev->base_addr;
985 int delayval,recbuf=lp->recbuf;
986 u_char *cardmem;
987
988 outb(0,INTMASK);
989
990 BUGMSG(D_INIT,"Resetting %s (status=%Xh)\n",
991 dev->name,inb(STATUS));
992
993 inb(RESET);
994 JIFFER(RESETtime);
995
996 outb(CFLAGScmd|RESETclear, COMMAND);
997 outb(CFLAGScmd|CONFIGclear,COMMAND);
998
999
1000
1001
1002 cardmem = (u_char *) dev->mem_start;
1003 if (cardmem[0] != TESTvalue)
1004 {
1005 BUGMSG(D_INIT,"reset failed: TESTvalue not present.\n");
1006 return 1;
1007 }
1008 lp->arcnum=cardmem[1];
1009
1010
1011 recbuf=lp->recbuf=0;
1012 lp->txbuf=2;
1013
1014
1015 outb(CONFIGcmd|EXTconf,COMMAND);
1016
1017
1018 BUGLVL(D_DURING)
1019 memset((void *)dev->mem_start,0x42,2048);
1020
1021
1022 EnableReceiver();
1023
1024
1025 outb(NORXflag|RECON_flag,INTMASK);
1026
1027
1028 return 0;
1029 }
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040 void arcnet_setup(struct device *dev)
1041 {
1042 int i;
1043 for (i=0; i<DEV_NUMBUFFS; i++)
1044 skb_queue_head_init(&dev->buffs[i]);
1045
1046 dev->broadcast[0]=0x00;
1047 dev->addr_len=1;
1048 dev->type=ARPHRD_ARCNET;
1049
1050
1051 dev->flags = IFF_BROADCAST;
1052 dev->family = AF_INET;
1053 dev->pa_addr = 0;
1054 dev->pa_brdaddr = 0;
1055 dev->pa_mask = 0;
1056 dev->pa_alen = 4;
1057 }
1058
1059
1060
1061
1062 static int arcnetE_init(struct device *dev)
1063 {
1064 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1065
1066 ether_setup(dev);
1067 dev->dev_addr[0]=0;
1068 dev->dev_addr[5]=lp->arcnum;
1069 dev->mtu=512-sizeof(struct HardHeader)-dev->hard_header_len-1;
1070 dev->open=NULL;
1071 dev->stop=NULL;
1072 dev->hard_start_xmit=arcnetE_send_packet;
1073
1074 BUGMSG(D_EXTRA,"ARCnet Ethernet-Encap protocol initialized.\n");
1075
1076 return 0;
1077 }
1078
1079
1080
1081 static int arcnetS_init(struct device *dev)
1082 {
1083 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1084
1085 arcnet_setup(dev);
1086
1087
1088 dev->dev_addr[0]=lp->arcnum;
1089 dev->hard_header_len=sizeof(struct S_ClientData);
1090 dev->mtu=512-sizeof(struct HardHeader)-dev->hard_header_len
1091 + S_EXTRA_CLIENTDATA;
1092 dev->open=NULL;
1093 dev->stop=NULL;
1094 dev->hard_start_xmit=arcnetS_send_packet;
1095 dev->hard_header=arcnetS_header;
1096 dev->rebuild_header=arcnetS_rebuild_header;
1097 #ifdef LINUX12
1098 dev->type_trans=arcnetS_type_trans;
1099 #endif
1100 BUGMSG(D_EXTRA,"ARCnet RFC1051 (NetBsd, AmiTCP) protocol initialized.\n");
1101
1102 return 0;
1103 }
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120 static int
1121 arcnet_open(struct device *dev)
1122 {
1123 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1124 int ioaddr=dev->base_addr,delayval;
1125
1126 if (dev->metric>=1000)
1127 {
1128 arcnet_debug=dev->metric-1000;
1129 printk("%6s: debug level set to %d\n",dev->name,arcnet_debug);
1130 dev->metric=1;
1131 }
1132
1133 BUGLVL(D_EXTRA) printk(version);
1134
1135 irq2dev_map[dev->irq] = dev;
1136
1137 BUGMSG(D_EXTRA,"arcnet_open: resetting card.\n");
1138
1139
1140 if (arcnet_reset(dev) && arcnet_reset(dev))
1141 return -ENODEV;
1142
1143 dev->tbusy=0;
1144 dev->interrupt=0;
1145 lp->intx=0;
1146 lp->in_txhandler=0;
1147
1148
1149 lp->adev=dev;
1150 BUGMSG(D_EXTRA,"ARCnet RFC1201 protocol initialized.\n");
1151
1152
1153 lp->edev=(struct device *)kmalloc(sizeof(struct device),GFP_KERNEL);
1154 if (lp->edev == NULL)
1155 return -ENOMEM;
1156 memcpy(lp->edev,dev,sizeof(struct device));
1157 lp->edev->name=(char *)kmalloc(10,GFP_KERNEL);
1158 if (lp->edev->name == NULL) {
1159 kfree(lp->edev);
1160 lp->edev = NULL;
1161 return -ENOMEM;
1162 }
1163 sprintf(lp->edev->name,"%se",dev->name);
1164 lp->edev->init=arcnetE_init;
1165 register_netdev(lp->edev);
1166
1167
1168 lp->sdev=(struct device *)kmalloc(sizeof(struct device),GFP_KERNEL);
1169 memcpy(lp->sdev,dev,sizeof(struct device));
1170 lp->sdev->name=(char *)kmalloc(10,GFP_KERNEL);
1171 sprintf(lp->sdev->name,"%ss",dev->name);
1172 lp->sdev->init=arcnetS_init;
1173 register_netdev(lp->sdev);
1174
1175
1176 START=1;
1177
1178
1179
1180
1181
1182 outb(0,INTMASK);
1183 JIFFER(ACKtime);
1184 outb(NORXflag|RECON_flag,INTMASK);
1185
1186 MOD_INC_USE_COUNT;
1187 return 0;
1188 }
1189
1190
1191
1192
1193 static int
1194 arcnet_close(struct device *dev)
1195 {
1196 int ioaddr = dev->base_addr;
1197 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1198
1199 TBUSY=1;
1200 START=0;
1201
1202
1203 irq2dev_map[dev->irq] = NULL;
1204
1205
1206
1207 outb(0,INTMASK);
1208 outb(NOTXcmd,COMMAND);
1209 outb(NORXcmd,COMMAND);
1210
1211
1212 INTERRUPT=0;
1213
1214
1215 lp->adev=NULL;
1216
1217
1218 lp->edev->priv=NULL;
1219 dev_close(lp->edev);
1220 unregister_netdev(lp->edev);
1221 kfree(lp->edev->name);
1222 kfree(lp->edev);
1223 lp->edev=NULL;
1224
1225
1226 lp->sdev->priv=NULL;
1227 dev_close(lp->sdev);
1228 unregister_netdev(lp->sdev);
1229 kfree(lp->sdev->name);
1230 kfree(lp->sdev);
1231 lp->sdev=NULL;
1232
1233
1234
1235 MOD_DEC_USE_COUNT;
1236 return 0;
1237 }
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249 static int
1250 arcnet_send_packet_bad(struct sk_buff *skb, struct device *dev)
1251 {
1252 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1253 int ioaddr=dev->base_addr;
1254
1255 BUGMSG(D_DURING,"transmit requested (status=%Xh, inTX=%d)\n",
1256 inb(STATUS),lp->intx);
1257
1258 if (lp->in_txhandler)
1259 {
1260 BUGMSG(D_NORMAL,"send_packet called while in txhandler!\n");
1261 lp->stats.tx_dropped++;
1262 return 1;
1263 }
1264
1265 if (lp->intx>1)
1266 {
1267 BUGMSG(D_NORMAL,"send_packet called while intx!\n");
1268 lp->stats.tx_dropped++;
1269 return 1;
1270 }
1271
1272 if (IF_TBUSY)
1273 {
1274
1275
1276 int tickssofar = jiffies - dev->trans_start;
1277
1278 int status=inb(STATUS);
1279
1280 if (tickssofar < TX_TIMEOUT)
1281 {
1282 BUGMSG(D_DURING,"premature kickme! (status=%Xh ticks=%d o.skb=%ph numsegs=%d segnum=%d\n",
1283 status,tickssofar,lp->outgoing.skb,
1284 lp->outgoing.numsegs,
1285 lp->outgoing.segnum);
1286 return 1;
1287 }
1288
1289 outb(0,INTMASK);
1290
1291 if (status&TXFREEflag)
1292 {
1293 BUGMSG(D_EXTRA,"tx timed out - missed IRQ? (status=%Xh, inTX=%d, inTXh=%d, tickssofar=%d)\n",
1294 status,lp->intx,
1295 lp->in_txhandler,tickssofar);
1296 lp->stats.tx_errors++;
1297 }
1298 else
1299 {
1300 BUGMSG(D_NORMAL,"tx timed out (status=%Xh, inTX=%d, inTXh=%d, tickssofar=%d)\n",
1301 status,lp->intx,
1302 lp->in_txhandler,tickssofar);
1303 lp->stats.tx_errors++;
1304 lp->stats.tx_aborted_errors++;
1305
1306 outb(NOTXcmd,COMMAND);
1307 }
1308
1309 if (lp->outgoing.skb)
1310 {
1311 dev_kfree_skb(lp->outgoing.skb,FREE_WRITE);
1312 lp->stats.tx_dropped++;
1313 }
1314 lp->outgoing.skb=NULL;
1315
1316 TBUSY=0;
1317 lp->txready=0;
1318 lp->sending=0;
1319
1320 outb(NORXflag|RECON_flag,INTMASK);
1321
1322 return 1;
1323 }
1324
1325
1326
1327
1328 if (skb == NULL) {
1329 printk("%6s: tx passed null skb (status=%Xh, inTX=%d, tickssofar=%ld)\n",
1330 dev->name,inb(STATUS),lp->intx,jiffies-dev->trans_start);
1331 lp->stats.tx_errors++;
1332 dev_tint(dev);
1333 return 0;
1334 }
1335
1336 if (lp->txready)
1337 {
1338 printk("%6s: trying to start new packet while busy! (status=%Xh)\n",
1339 dev->name,inb(STATUS));
1340 outb(0,INTMASK);
1341 outb(NOTXcmd,COMMAND);
1342 arcnet_inthandler(dev);
1343 lp->stats.tx_errors++;
1344 lp->stats.tx_fifo_errors++;
1345 lp->txready=0;
1346
1347 return 1;
1348 }
1349
1350
1351
1352 if (set_bit(0, (void*)&dev->tbusy) != 0)
1353 {
1354 printk("%6s: transmitter called with busy bit set! (status=%Xh, inTX=%d, tickssofar=%ld)\n",
1355 dev->name,inb(STATUS),lp->intx,jiffies-dev->trans_start);
1356 lp->stats.tx_errors++;
1357 lp->stats.tx_fifo_errors++;
1358 return -EBUSY;
1359 }
1360
1361 return 0;
1362 }
1363
1364
1365
1366
1367 static int
1368 arcnetA_send_packet(struct sk_buff *skb, struct device *dev)
1369 {
1370 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1371 int ioaddr=dev->base_addr,bad;
1372 struct Outgoing *out=&(lp->outgoing);
1373
1374 BUGMSG(D_DURING,"transmit requested (status=%Xh, inTX=%d)\n",
1375 inb(STATUS),lp->intx);
1376
1377 lp->intx++;
1378
1379 bad=arcnet_send_packet_bad(skb,dev);
1380 if (bad)
1381 {
1382 lp->intx--;
1383 return bad;
1384 }
1385
1386 TBUSY=1;
1387
1388 out->length = 1 < skb->len ? skb->len : 1;
1389 out->hdr=(struct ClientData*)skb->data;
1390 out->skb=skb;
1391
1392 BUGLVL(D_SKB)
1393 {
1394 short i;
1395 for( i=0; i< skb->len; i++)
1396 {
1397 if( i%16 == 0 ) printk("\n[%04hX] ",i);
1398 printk("%02hX ",((unsigned char*)skb->data)[i]);
1399 }
1400 printk("\n");
1401 }
1402
1403 out->hdr->sequence=(lp->sequence++);
1404
1405
1406
1407
1408 if (out->length-EXTRA_CLIENTDATA<=XMTU)
1409 {
1410 BUGMSG(D_DURING,"not splitting %d-byte packet. (split_flag=%d)\n",
1411 out->length,out->hdr->split_flag);
1412 BUGLVL(D_EXTRA) if (out->hdr->split_flag)
1413 printk("%6s: short packet has split_flag set?! (split_flag=%d)\n",
1414 dev->name,out->hdr->split_flag);
1415 out->numsegs=1;
1416 out->segnum=1;
1417 arcnetAS_prepare_tx(dev,
1418 ((char *)out->hdr)+EXTRA_CLIENTDATA,
1419 sizeof(struct ClientData)-EXTRA_CLIENTDATA,
1420 ((char *)skb->data)+sizeof(struct ClientData),
1421 out->length-sizeof(struct ClientData),
1422 out->hdr->daddr,1);
1423
1424
1425 dev_kfree_skb(out->skb,FREE_WRITE);
1426 out->skb=NULL;
1427
1428 if (arcnet_go_tx(dev,1))
1429 {
1430
1431 TBUSY=0;
1432 mark_bh(NET_BH);
1433 }
1434 }
1435 else
1436 {
1437 int maxsegsize=XMTU-4;
1438
1439 out->data=(u_char *)skb->data
1440 + sizeof(struct ClientData);
1441 out->dataleft=out->length-sizeof(struct ClientData);
1442 out->numsegs=(out->dataleft+maxsegsize-1)/maxsegsize;
1443
1444 out->segnum=0;
1445
1446 BUGMSG(D_TX,"packet (%d bytes) split into %d fragments:\n",
1447 out->length,out->numsegs);
1448
1449
1450 arcnet_go_tx(dev,1);
1451
1452 if (!lp->txready)
1453 {
1454
1455
1456
1457 arcnetA_continue_tx(dev);
1458 if (arcnet_go_tx(dev,1))
1459 {
1460 arcnetA_continue_tx(dev);
1461 arcnet_go_tx(dev,1);
1462 }
1463 }
1464
1465
1466
1467
1468 if (out->segnum==out->numsegs)
1469 {
1470
1471 out->segnum++;
1472 if (out->skb)
1473 dev_kfree_skb(out->skb,FREE_WRITE);
1474 out->skb=NULL;
1475 }
1476 }
1477
1478 dev->trans_start=jiffies;
1479 lp->intx--;
1480 return 0;
1481 }
1482
1483
1484
1485
1486 static int
1487 arcnetE_send_packet(struct sk_buff *skb, struct device *dev)
1488 {
1489 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1490 int bad;
1491 union ArcPacket *arcpacket =
1492 (union ArcPacket *)(dev->mem_start+512*(lp->txbuf^1));
1493 u_char *arcsoft,daddr;
1494 short offset,length=skb->len+1;
1495
1496 BUGMSG(D_DURING,"in arcnetE_send_packet (skb=%p)\n",skb);
1497
1498 lp->intx++;
1499
1500 bad=arcnet_send_packet_bad(skb,dev);
1501 if (bad)
1502 {
1503 lp->intx--;
1504 return bad;
1505 }
1506
1507 TBUSY=1;
1508
1509 if (length>XMTU)
1510 {
1511 printk("%6s: MTU must be <= 493 for ethernet encap (length=%d).\n",
1512 dev->name,length);
1513 printk("%6s: transmit aborted.\n",dev->name);
1514
1515 dev_kfree_skb(skb,FREE_WRITE);
1516 return 0;
1517 }
1518
1519 BUGMSG(D_DURING,"starting tx sequence...\n");
1520
1521 lp->txbuf=lp->txbuf^1;
1522
1523
1524 BUGLVL(D_DURING)
1525 memset((void *)dev->mem_start+lp->txbuf*512,0x42,512);
1526
1527
1528 if (((struct ethhdr*)(skb->data))->h_dest[0] == 0xFF)
1529 daddr=arcpacket->hardheader.destination=0;
1530 else
1531 daddr=arcpacket->hardheader.destination=
1532 ((struct ethhdr*)(skb->data))->h_dest[5];
1533
1534
1535 offset=512-length;
1536 if (length>MTU)
1537 {
1538 if (length<MinTU) offset-=3;
1539 arcpacket->hardheader.offset1=0;
1540 arcpacket->hardheader.offset2=offset;
1541 }
1542 else
1543 {
1544 arcpacket->hardheader.offset1=(offset-=256);
1545 }
1546
1547 BUGMSG(D_DURING," length=%Xh, offset=%Xh, offset1=%Xh, offset2=%Xh\n",
1548 length,offset,arcpacket->hardheader.offset1,
1549 arcpacket->hardheader.offset2);
1550
1551 arcsoft=&arcpacket->raw[offset];
1552 arcsoft[0]=ARC_P_ETHER;
1553 arcsoft++;
1554
1555
1556
1557
1558 BUGMSG(D_DURING,"ready to memcpy\n");
1559
1560 memcpy(arcsoft,skb->data,skb->len);
1561
1562 BUGMSG(D_DURING,"transmitting packet to station %02Xh (%d bytes)\n",
1563 daddr,length);
1564
1565 BUGLVL(D_TX)
1566 {
1567 int countx,county;
1568
1569 printk("%6s: packet dump [tx] follows:",dev->name);
1570
1571 for (county=0; county<16+(length>=240)*16; county++)
1572 {
1573 printk("\n[%04X] ",county*16);
1574 for (countx=0; countx<16; countx++)
1575 printk("%02X ",
1576 arcpacket->raw[county*16+countx]);
1577 }
1578
1579 printk("\n");
1580 }
1581
1582 #ifdef VERIFY_ACK
1583 lp->outgoing.lastload_dest=daddr;
1584 #endif
1585 lp->txready=lp->txbuf;
1586
1587 dev_kfree_skb(skb,FREE_WRITE);
1588
1589 if (arcnet_go_tx(dev,1))
1590 {
1591
1592 TBUSY=0;
1593 mark_bh(NET_BH);
1594 }
1595
1596 dev->trans_start=jiffies;
1597 lp->intx--;
1598 return 0;
1599 }
1600
1601
1602
1603
1604 static int
1605 arcnetS_send_packet(struct sk_buff *skb, struct device *dev)
1606 {
1607 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1608 int ioaddr=dev->base_addr,bad,length;
1609 struct S_ClientData *hdr=(struct S_ClientData *)skb->data;
1610
1611 lp->intx++;
1612
1613 BUGMSG(D_DURING,"transmit requested (status=%Xh, inTX=%d)\n",
1614 inb(STATUS),lp->intx);
1615
1616 bad=arcnet_send_packet_bad(skb,dev);
1617 if (bad)
1618 {
1619 lp->intx--;
1620 return bad;
1621 }
1622
1623 TBUSY=1;
1624
1625 length = 1 < skb->len ? skb->len : 1;
1626
1627 BUGLVL(D_SKB)
1628 {
1629 short i;
1630 for(i=0; i<skb->len; i++)
1631 {
1632 if( i%16 == 0 ) printk("\n[%04hX] ",i);
1633 printk("%02hX ",((unsigned char*)skb->data)[i]);
1634 }
1635 printk("\n");
1636 }
1637
1638
1639
1640
1641
1642 if (length-S_EXTRA_CLIENTDATA<=XMTU)
1643 {
1644 arcnetAS_prepare_tx(dev,
1645 skb->data+S_EXTRA_CLIENTDATA,
1646 sizeof(struct S_ClientData)-S_EXTRA_CLIENTDATA,
1647 skb->data+sizeof(struct S_ClientData),
1648 length-sizeof(struct S_ClientData),
1649 hdr->daddr,0);
1650
1651
1652 dev_kfree_skb(skb,FREE_WRITE);
1653
1654 if (arcnet_go_tx(dev,1))
1655 {
1656
1657 TBUSY=0;
1658 mark_bh(NET_BH);
1659 }
1660 }
1661 else
1662 {
1663 printk("arcnetS: packet too long (length=%d)\n",
1664 length);
1665 dev_kfree_skb(skb,FREE_WRITE);
1666 lp->stats.tx_dropped++;
1667 TBUSY=0;
1668 mark_bh(NET_BH);
1669 }
1670
1671 dev->trans_start=jiffies;
1672 lp->intx--;
1673 return 0;
1674 }
1675
1676
1677
1678
1679
1680
1681 static void arcnetA_continue_tx(struct device *dev)
1682 {
1683 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1684 int maxsegsize=XMTU-4;
1685 struct Outgoing *out=&(lp->outgoing);
1686
1687 if (lp->txready)
1688 {
1689 printk("%6s: continue_tx: called with packet in buffer!\n",
1690 dev->name);
1691 return;
1692 }
1693
1694 if (out->segnum>=out->numsegs)
1695 {
1696 printk("%6s: continue_tx: building segment %d of %d!\n",
1697 dev->name,out->segnum+1,out->numsegs);
1698 }
1699
1700 if (!out->segnum)
1701 out->hdr->split_flag=((out->numsegs-2)<<1)+1;
1702 else
1703 out->hdr->split_flag=out->segnum<<1;
1704
1705 out->seglen=maxsegsize;
1706 if (out->seglen>out->dataleft) out->seglen=out->dataleft;
1707
1708 BUGMSG(D_TX,"building packet #%d (%d bytes) of %d (%d total), splitflag=%d\n",
1709 out->segnum+1,out->seglen,out->numsegs,
1710 out->length,out->hdr->split_flag);
1711
1712 arcnetAS_prepare_tx(dev,((char *)out->hdr)+EXTRA_CLIENTDATA,
1713 sizeof(struct ClientData)-EXTRA_CLIENTDATA,
1714 out->data,out->seglen,out->hdr->daddr,1);
1715
1716 out->dataleft-=out->seglen;
1717 out->data+=out->seglen;
1718 out->segnum++;
1719 }
1720
1721
1722
1723
1724
1725 static void
1726 arcnetAS_prepare_tx(struct device *dev,u_char *hdr,int hdrlen,
1727 char *data,int length,int daddr,int exceptA)
1728 {
1729 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
1730 struct ClientData *arcsoft;
1731 union ArcPacket *arcpacket =
1732 (union ArcPacket *)(dev->mem_start+512*(lp->txbuf^1));
1733 int offset;
1734
1735 lp->txbuf=lp->txbuf^1;
1736
1737 length+=hdrlen;
1738
1739 BUGMSG(D_TX,"arcnetAS_prep_tx: hdr:%ph, length:%d, data:%ph\n",
1740 hdr,length,data);
1741
1742
1743 BUGLVL(D_DURING)
1744 memset((void *)dev->mem_start+lp->txbuf*512,0x42,512);
1745
1746 arcpacket->hardheader.destination=daddr;
1747
1748
1749 if (length<=MTU)
1750 {
1751 arcpacket->hardheader.offset1=offset=256-length;
1752 arcsoft=(struct ClientData *)
1753 (&arcpacket->raw[offset]);
1754 }
1755 else if (length>=MinTU)
1756 {
1757 arcpacket->hardheader.offset1=0;
1758 arcpacket->hardheader.offset2=offset=512-length;
1759
1760 arcsoft=(struct ClientData *)
1761 (&arcpacket->raw[offset]);
1762 }
1763 else if (exceptA)
1764 {
1765 arcpacket->hardheader.offset1=0;
1766 arcpacket->hardheader.offset2=offset=512-length-4;
1767 arcsoft=(struct ClientData *)
1768 (&arcpacket->raw[offset+4]);
1769
1770
1771
1772
1773
1774 arcpacket->raw[offset+0]=hdr[0];
1775 arcpacket->raw[offset+1]=0xFF;
1776 arcpacket->raw[offset+2]=0xFF;
1777 arcpacket->raw[offset+3]=0xFF;
1778 }
1779 else
1780 {
1781
1782 memset(&arcpacket->raw[508],0,4);
1783
1784
1785 arcpacket->hardheader.offset1=0;
1786 arcpacket->hardheader.offset2=offset=512-MinTU;
1787 arcsoft=(struct ClientData *)(&arcpacket->raw[offset]);
1788 }
1789
1790
1791
1792
1793
1794 memcpy((u_char*)arcsoft,
1795 (u_char*)hdr,hdrlen);
1796 memcpy((u_char*)arcsoft+hdrlen,
1797 data,length-hdrlen);
1798
1799 BUGMSG(D_DURING,"transmitting packet to station %02Xh (%d bytes)\n",
1800 daddr,length);
1801
1802 BUGLVL(D_TX)
1803 {
1804 int countx,county;
1805
1806 printk("%6s: packet dump [tx] follows:",dev->name);
1807
1808 for (county=0; county<16+(length>MTU)*16; county++)
1809 {
1810 printk("\n[%04X] ",county*16);
1811 for (countx=0; countx<16; countx++)
1812 printk("%02X ",
1813 arcpacket->raw[county*16+countx]);
1814 }
1815
1816 printk("\n");
1817 }
1818
1819 #ifdef VERIFY_ACK
1820 lp->outgoing.lastload_dest=daddr;
1821 #endif
1822 lp->txready=lp->txbuf;
1823 }
1824
1825
1826
1827
1828 static int
1829 arcnet_go_tx(struct device *dev,int enable_irq)
1830 {
1831 struct arcnet_local *lp=(struct arcnet_local *)dev->priv;
1832 int ioaddr=dev->base_addr;
1833
1834 BUGMSG(D_DURING,"go_tx: status=%Xh\n",
1835 inb(STATUS));
1836
1837 outb(0,INTMASK);
1838
1839 if (lp->sending || !lp->txready)
1840 {
1841 if (enable_irq)
1842 {
1843 if (lp->sending)
1844 outb(TXFREEflag|NORXflag|RECON_flag,INTMASK);
1845 else
1846 outb(NORXflag|RECON_flag,INTMASK);
1847 }
1848 return 0;
1849 }
1850
1851
1852 outb(TXcmd|(lp->txready<<3),COMMAND);
1853
1854 lp->stats.tx_packets++;
1855 lp->txready=0;
1856 lp->sending++;
1857
1858 #ifdef VERIFY_ACK
1859 lp->outgoing.lasttrans_dest=lp->outgoing.lastload_dest;
1860 lp->outgoing.lastload_dest=0;
1861 #endif
1862
1863 if (enable_irq)
1864 outb(TXFREEflag|NORXflag|RECON_flag,INTMASK);
1865
1866 return 1;
1867 }
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882 static void
1883 arcnet_interrupt(int irq,struct pt_regs *regs)
1884 {
1885 struct device *dev = (struct device *)(irq2dev_map[irq]);
1886
1887 if (dev==NULL)
1888 {
1889 BUGLVL(D_EXTRA)
1890 printk("arcnet: irq %d for unknown device.\n", irq);
1891 return;
1892 }
1893
1894 if (!dev->start) return;
1895
1896 arcnet_inthandler(dev);
1897 }
1898
1899
1900
1901
1902
1903 static void
1904 arcnet_inthandler(struct device *dev)
1905 {
1906 struct arcnet_local *lp=(struct arcnet_local *)dev->priv;
1907 int ioaddr=dev->base_addr, status, boguscount = 3, didsomething;
1908
1909 if (IF_INTERRUPT)
1910 {
1911 printk("%6s: DRIVER PROBLEM! Nested arcnet interrupts!\n",
1912 dev->name);
1913 return;
1914 }
1915 outb(0,INTMASK);
1916 INTERRUPT = 1;
1917
1918 BUGMSG(D_DURING,"in net_interrupt (status=%Xh)\n",inb(STATUS));
1919
1920 #if 1
1921 do
1922 {
1923 status = inb(STATUS);
1924 didsomething=0;
1925
1926 #if 0
1927 if (!dev->start)
1928 {
1929 BUGMSG(D_DURING,"ARCnet not yet initialized. irq ignored. (status=%Xh)\n",
1930 status);
1931 if (!(status&NORXflag))
1932 outb(NORXflag|RECON_flag,INTMASK);
1933
1934
1935
1936
1937
1938 dev->interrupt=0;
1939 return;
1940 }
1941 #endif
1942
1943
1944
1945
1946 if (status & RESETflag)
1947 {
1948 outb(CFLAGScmd|RESETclear,COMMAND);
1949 BUGMSG(D_INIT,"reset irq (status=%Xh)\n",
1950 status);
1951 }
1952 #ifdef DETECT_RECONFIGS
1953 if (status & RECONflag)
1954 {
1955 outb(CFLAGScmd|CONFIGclear,COMMAND);
1956 lp->stats.tx_carrier_errors++;
1957
1958 #ifdef SHOW_RECONFIGS
1959 BUGMSG(D_NORMAL,"Network reconfiguration detected (status=%Xh)\n",
1960 status);
1961 #endif
1962
1963 #ifdef RECON_THRESHOLD
1964
1965 if (!lp->first_recon || !lp->last_recon ||
1966 jiffies-lp->last_recon > HZ*10)
1967 {
1968 if (lp->network_down)
1969 printk("%6s: reconfiguration detected: cabling restored?\n",
1970 dev->name);
1971 lp->first_recon=lp->last_recon=jiffies;
1972 lp->num_recons=lp->network_down=0;
1973
1974 BUGMSG(D_DURING,"recon: clearing counters.\n");
1975 }
1976 else
1977 {
1978 lp->last_recon=jiffies;
1979 lp->num_recons++;
1980
1981 BUGMSG(D_DURING,"recon: counter=%d, time=%lds, net=%d\n",
1982 lp->num_recons,
1983 (lp->last_recon-lp->first_recon)/HZ,
1984 lp->network_down);
1985
1986
1987
1988
1989
1990
1991
1992
1993 if (!lp->network_down
1994 && (lp->last_recon-lp->first_recon)<=HZ*60
1995 && lp->num_recons >= RECON_THRESHOLD)
1996 {
1997 lp->network_down=1;
1998 printk("%6s: many reconfigurations detected: cabling problem?\n",
1999 dev->name);
2000 }
2001 else if (!lp->network_down
2002 && lp->last_recon-lp->first_recon > HZ*60)
2003 {
2004
2005
2006
2007 lp->first_recon=lp->last_recon;
2008 lp->num_recons=1;
2009 }
2010 }
2011 #endif
2012 }
2013 #ifdef RECON_THRESHOLD
2014 else if (lp->network_down && jiffies-lp->last_recon > HZ*10)
2015 {
2016 if (lp->network_down)
2017 printk("%6s: cabling restored?\n",dev->name);
2018 lp->first_recon=lp->last_recon=0;
2019 lp->num_recons=lp->network_down=0;
2020
2021 BUGMSG(D_DURING,"not recon: clearing counters anyway.\n");
2022 }
2023 #endif
2024 #endif
2025
2026
2027 if (status & NORXflag)
2028 {
2029 int recbuf=lp->recbuf=!lp->recbuf;
2030
2031 BUGMSG(D_DURING,"receive irq (status=%Xh)\n",
2032 status);
2033
2034
2035 EnableReceiver();
2036
2037
2038 arcnet_rx(dev,!recbuf);
2039 didsomething++;
2040 }
2041
2042
2043 if (status&TXFREEflag && !lp->in_txhandler && lp->sending)
2044 {
2045 struct Outgoing *out=&(lp->outgoing);
2046
2047 lp->in_txhandler++;
2048 lp->sending--;
2049
2050 BUGMSG(D_DURING,"TX IRQ (stat=%Xh, numsegs=%d, segnum=%d, skb=%ph)\n",
2051 status,out->numsegs,out->segnum,out->skb);
2052
2053 #ifdef VERIFY_ACK
2054 if (!(status&TXACKflag))
2055 {
2056 if (lp->outgoing.lasttrans_dest != 0)
2057 {
2058 printk("%6s: transmit was not acknowledged! (status=%Xh, dest=%d)\n",
2059 dev->name,status,
2060 lp->outgoing.lasttrans_dest);
2061 lp->stats.tx_errors++;
2062 lp->stats.tx_carrier_errors++;
2063 }
2064 else
2065 {
2066 BUGMSG(D_DURING,"broadcast was not acknowledged; that's normal (status=%Xh, dest=%d)\n",
2067 status,
2068 lp->outgoing.lasttrans_dest);
2069 }
2070 }
2071 #endif
2072
2073 arcnet_go_tx(dev,0);
2074 didsomething++;
2075
2076 if (lp->intx)
2077 {
2078 lp->in_txhandler--;
2079 continue;
2080 }
2081
2082 if (!lp->outgoing.skb)
2083 {
2084 BUGMSG(D_DURING,"TX IRQ done: no split to continue.\n");
2085
2086
2087 if (!lp->txready && IF_TBUSY)
2088 {
2089 TBUSY=0;
2090 mark_bh(NET_BH);
2091 }
2092
2093 lp->in_txhandler--;
2094 continue;
2095 }
2096
2097
2098
2099
2100 if (out->segnum<out->numsegs)
2101 arcnetA_continue_tx(dev);
2102 arcnet_go_tx(dev,0);
2103
2104
2105
2106
2107 if (out->segnum>=out->numsegs)
2108 {
2109
2110 out->segnum++;
2111 if (out->skb)
2112 dev_kfree_skb(out->skb,FREE_WRITE);
2113 out->skb=NULL;
2114
2115
2116 if (!lp->txready && IF_TBUSY)
2117 {
2118 TBUSY=0;
2119 mark_bh(NET_BH);
2120 }
2121 }
2122 didsomething++;
2123
2124 lp->in_txhandler--;
2125 }
2126 else if (lp->txready && !lp->sending && !lp->intx)
2127 {
2128 BUGMSG(D_NORMAL,"recovery from silent TX (status=%Xh)\n",
2129 status);
2130 arcnet_go_tx(dev,0);
2131 didsomething++;
2132 }
2133 } while (--boguscount && didsomething);
2134
2135 BUGMSG(D_DURING,"net_interrupt complete (status=%Xh, count=%d)\n\n",
2136 inb(STATUS),boguscount);
2137
2138 if (dev->start && (lp->sending || (lp->txready && !lp->intx)))
2139 outb(NORXflag|TXFREEflag|RECON_flag,INTMASK);
2140 else
2141 outb(NORXflag|RECON_flag,INTMASK);
2142
2143 #else
2144
2145 outb(RXcmd|(0<<3)|RXbcasts,COMMAND);
2146 outb(NORXflag,INTMASK);
2147
2148 #endif
2149
2150 INTERRUPT=0;
2151 }
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165 static void
2166 arcnet_rx(struct device *dev,int recbuf)
2167 {
2168 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
2169 int ioaddr = dev->base_addr;
2170 union ArcPacket *arcpacket=
2171 (union ArcPacket *)(dev->mem_start+recbuf*512);
2172 u_char *arcsoft;
2173 short length,offset;
2174 u_char daddr,saddr;
2175
2176 lp->stats.rx_packets++;
2177
2178 saddr=arcpacket->hardheader.source;
2179 daddr=arcpacket->hardheader.destination;
2180
2181
2182 if (saddr==0)
2183 {
2184 printk("%6s: discarding old packet. (status=%Xh)\n",
2185 dev->name,inb(STATUS));
2186 lp->stats.rx_errors++;
2187 return;
2188 }
2189 arcpacket->hardheader.source=0;
2190
2191 if (arcpacket->hardheader.offset1)
2192 {
2193 offset=arcpacket->hardheader.offset1;
2194 arcsoft=&arcpacket->raw[offset];
2195 length=256-offset;
2196 }
2197 else
2198 {
2199 offset=arcpacket->hardheader.offset2;
2200 arcsoft=&arcpacket->raw[offset];
2201
2202 length=512-offset;
2203 }
2204
2205 BUGMSG(D_DURING,"received packet from %02Xh to %02Xh (%d bytes)\n",
2206 saddr,daddr,length);
2207
2208
2209 switch (arcsoft[0])
2210 {
2211 case ARC_P_IP:
2212 case ARC_P_ARP:
2213 case ARC_P_RARP:
2214 case ARC_P_IPX:
2215 arcnetA_rx(lp->adev,arcsoft,length,saddr,daddr);
2216 break;
2217 case ARC_P_ETHER:
2218 arcnetE_rx(lp->edev,arcsoft,length,saddr,daddr);
2219 break;
2220 case ARC_P_IP_RFC1051:
2221 case ARC_P_ARP_RFC1051:
2222 arcnetS_rx(lp->sdev,arcsoft,length,saddr,daddr);
2223 break;
2224 default:
2225 printk("%6s: received unknown protocol %d (%Xh)\n",
2226 dev->name,arcsoft[0],arcsoft[0]);
2227 lp->stats.rx_errors++;
2228 lp->stats.rx_crc_errors++;
2229 break;
2230 }
2231
2232 BUGLVL(D_RX)
2233 {
2234 int countx,county;
2235
2236 printk("%6s: packet dump [rx] follows:",dev->name);
2237
2238 for (county=0; county<16+(length>240)*16; county++)
2239 {
2240 printk("\n[%04X] ",county*16);
2241 for (countx=0; countx<16; countx++)
2242 printk("%02X ",
2243 arcpacket->raw[county*16+countx]);
2244 }
2245
2246 printk("\n");
2247 }
2248
2249
2250
2251 BUGLVL(D_DURING)
2252 memset((void *)arcpacket->raw,0x42,512);
2253
2254
2255
2256
2257
2258
2259 }
2260
2261
2262
2263
2264 static void
2265 arcnetA_rx(struct device *dev,u_char *buf,
2266 int length,u_char saddr, u_char daddr)
2267 {
2268 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
2269 struct sk_buff *skb;
2270 struct ClientData *arcsoft,*soft;
2271
2272 BUGMSG(D_DURING,"it's an RFC1201 packet (length=%d)\n",
2273 length);
2274
2275
2276
2277
2278 arcsoft=(struct ClientData *)(buf-EXTRA_CLIENTDATA);
2279 length+=EXTRA_CLIENTDATA;
2280
2281 if (arcsoft->split_flag==0xFF)
2282 {
2283 BUGMSG(D_DURING,"compensating for exception packet\n");
2284
2285
2286 arcsoft=(struct ClientData *)
2287 ((u_char *)arcsoft + 4);
2288 length-=4;
2289 }
2290
2291 if (!arcsoft->split_flag)
2292 {
2293 struct Incoming *in=&lp->incoming[saddr];
2294
2295 BUGMSG(D_RX,"incoming is not split (splitflag=%d)\n",
2296 arcsoft->split_flag);
2297
2298 if (in->skb)
2299 {
2300 BUGMSG(D_EXTRA,"aborting assembly (seq=%d) for unsplit packet (splitflag=%d, seq=%d)\n",
2301 in->sequence,arcsoft->split_flag,
2302 arcsoft->sequence);
2303 kfree_skb(in->skb,FREE_WRITE);
2304 lp->stats.rx_errors++;
2305 lp->stats.rx_missed_errors++;
2306 in->skb=NULL;
2307 }
2308
2309 in->sequence=arcsoft->sequence;
2310
2311 skb = alloc_skb(length, GFP_ATOMIC);
2312 if (skb == NULL) {
2313 printk("%6s: Memory squeeze, dropping packet.\n",
2314 dev->name);
2315 lp->stats.rx_dropped++;
2316 return;
2317 }
2318 soft=(struct ClientData *)skb->data;
2319
2320 skb->len = length;
2321 skb->dev = dev;
2322
2323 memcpy((u_char *)soft+EXTRA_CLIENTDATA,
2324 (u_char *)arcsoft+EXTRA_CLIENTDATA,
2325 length-EXTRA_CLIENTDATA);
2326 soft->daddr=daddr;
2327 soft->saddr=saddr;
2328
2329
2330
2331
2332
2333
2334 if (soft->protocol_id == ARC_P_ARP)
2335 {
2336 struct arphdr *arp=(struct arphdr *)
2337 ((char *)soft+sizeof(struct ClientData));
2338
2339
2340 if (arp->ar_hln==1 && arp->ar_pln==4)
2341 {
2342 char *cptr=(char *)(arp)+sizeof(struct arphdr);
2343
2344 if (!*cptr)
2345 {
2346 BUGMSG(D_EXTRA,"ARP source address was 00h, set to %02Xh.\n",
2347 saddr);
2348 lp->stats.rx_crc_errors++;
2349 *cptr=saddr;
2350 }
2351 else
2352 {
2353 BUGMSG(D_DURING,"ARP source address (%Xh) is fine.\n",
2354 *cptr);
2355 }
2356 }
2357 else
2358 {
2359 printk("%6s: funny-shaped ARP packet. (%Xh, %Xh)\n",
2360 dev->name,arp->ar_hln,arp->ar_pln);
2361 lp->stats.rx_errors++;
2362 lp->stats.rx_crc_errors++;
2363 }
2364 }
2365
2366 BUGLVL(D_SKB)
2367 {
2368 short i;
2369 for( i=0; i< skb->len; i++)
2370 {
2371 if( i%16 == 0 ) printk("\n[%04hX] ",i);
2372 printk("%02hX ",((unsigned char*)skb->data)[i]);
2373 }
2374 printk("\n");
2375 }
2376
2377 #ifndef LINUX12
2378 skb->protocol=arcnetA_type_trans(skb,dev);
2379 #endif
2380
2381 netif_rx(skb);
2382 }
2383 else
2384 {
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402 struct Incoming *in=&lp->incoming[saddr];
2403
2404 BUGMSG(D_RX,"packet is split (splitflag=%d, seq=%d)\n",
2405 arcsoft->split_flag,in->sequence);
2406
2407 if (in->skb && in->sequence!=arcsoft->sequence)
2408 {
2409 BUGMSG(D_EXTRA,"wrong seq number, aborting assembly (expected=%d, seq=%d, splitflag=%d)\n",
2410 in->sequence,arcsoft->sequence,
2411 arcsoft->split_flag);
2412 kfree_skb(in->skb,FREE_WRITE);
2413 in->skb=NULL;
2414 lp->stats.rx_errors++;
2415 lp->stats.rx_missed_errors++;
2416 in->lastpacket=in->numpackets=0;
2417 }
2418
2419 if (arcsoft->split_flag & 1)
2420 {
2421 BUGMSG(D_RX,"brand new splitpacket (splitflag=%d)\n",
2422 arcsoft->split_flag);
2423 if (in->skb)
2424 {
2425 BUGMSG(D_EXTRA,"aborting previous (seq=%d) assembly (splitflag=%d, seq=%d)\n",
2426 in->sequence,arcsoft->split_flag,
2427 arcsoft->sequence);
2428 lp->stats.rx_errors++;
2429 lp->stats.rx_missed_errors++;
2430 kfree_skb(in->skb,FREE_WRITE);
2431 }
2432
2433 in->sequence=arcsoft->sequence;
2434 in->numpackets=((unsigned)arcsoft->split_flag>>1)+2;
2435 in->lastpacket=1;
2436
2437 if (in->numpackets>16)
2438 {
2439 BUGMSG(D_EXTRA,"incoming packet more than 16 segments; dropping. (splitflag=%d)\n",
2440 arcsoft->split_flag);
2441 lp->stats.rx_errors++;
2442 lp->stats.rx_length_errors++;
2443 return;
2444 }
2445
2446 in->skb=skb=alloc_skb(508*in->numpackets
2447 + sizeof(struct ClientData),
2448 GFP_ATOMIC);
2449 if (skb == NULL) {
2450 printk("%6s: (split) memory squeeze, dropping packet.\n",
2451 dev->name);
2452 lp->stats.rx_dropped++;
2453 return;
2454 }
2455
2456
2457
2458
2459 skb->free=1;
2460
2461 soft=(struct ClientData *)skb->data;
2462
2463 skb->len=sizeof(struct ClientData);
2464 skb->dev=dev;
2465
2466 memcpy((u_char *)soft+EXTRA_CLIENTDATA,
2467 (u_char *)arcsoft+EXTRA_CLIENTDATA,
2468 sizeof(struct ClientData)-EXTRA_CLIENTDATA);
2469 soft->split_flag=0;
2470 }
2471 else
2472 {
2473 int packetnum=((unsigned)arcsoft->split_flag>>1) + 1;
2474
2475
2476
2477
2478 if (!in->skb)
2479 {
2480 BUGMSG(D_EXTRA,"can't continue split without starting first! (splitflag=%d, seq=%d)\n",
2481 arcsoft->split_flag,arcsoft->sequence);
2482 lp->stats.rx_errors++;
2483 lp->stats.rx_missed_errors++;
2484 return;
2485 }
2486
2487 in->lastpacket++;
2488 if (packetnum!=in->lastpacket)
2489 {
2490
2491 if (packetnum<=in->lastpacket-1)
2492 {
2493 BUGMSG(D_EXTRA,"duplicate splitpacket ignored! (splitflag=%d)\n",
2494 arcsoft->split_flag);
2495 lp->stats.rx_errors++;
2496 lp->stats.rx_frame_errors++;
2497 return;
2498 }
2499
2500
2501 BUGMSG(D_EXTRA,"out-of-order splitpacket, reassembly (seq=%d) aborted (splitflag=%d, seq=%d)\n",
2502 in->sequence,arcsoft->split_flag,
2503 arcsoft->sequence);
2504 kfree_skb(in->skb,FREE_WRITE);
2505 in->skb=NULL;
2506 lp->stats.rx_errors++;
2507 lp->stats.rx_missed_errors++;
2508 in->lastpacket=in->numpackets=0;
2509 return;
2510 }
2511
2512 soft=(struct ClientData *)in->skb->data;
2513 }
2514
2515 skb=in->skb;
2516
2517 memcpy(skb->data+skb->len,
2518 (u_char *)arcsoft+sizeof(struct ClientData),
2519 length-sizeof(struct ClientData));
2520
2521 skb->len+=length-sizeof(struct ClientData);
2522
2523 soft->daddr=daddr;
2524 soft->saddr=saddr;
2525
2526
2527 if (in->lastpacket == in->numpackets)
2528 {
2529 if (!skb || !in->skb)
2530 {
2531 printk("%6s: ?!? done reassembling packet, no skb? (skb=%ph, in->skb=%ph)\n",
2532 dev->name,skb,in->skb);
2533 }
2534 else
2535 {
2536 in->skb=NULL;
2537 in->lastpacket=in->numpackets=0;
2538
2539 BUGLVL(D_SKB)
2540 {
2541 short i;
2542 for(i=0; i<skb->len; i++)
2543 {
2544 if( i%16 == 0 ) printk("\n[%04hX] ",i);
2545 printk("%02hX ",((unsigned char*)skb->data)[i]);
2546 }
2547 printk("\n");
2548 }
2549
2550
2551 #ifndef LINUX12
2552 skb->protocol=arcnetA_type_trans(skb,dev);
2553 #endif
2554
2555 netif_rx(skb);
2556 }
2557 }
2558 }
2559 }
2560
2561
2562
2563
2564 static void
2565 arcnetE_rx(struct device *dev,u_char *arcsoft,
2566 int length,u_char saddr, u_char daddr)
2567 {
2568 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
2569 struct sk_buff *skb;
2570
2571 BUGMSG(D_DURING,"it's an ethernet-encap packet (length=%d)\n",
2572 length);
2573
2574 skb = alloc_skb(length, GFP_ATOMIC);
2575 if (skb == NULL) {
2576 printk("%6s: Memory squeeze, dropping packet.\n",dev->name);
2577 lp->stats.rx_dropped++;
2578 return;
2579 }
2580
2581 skb->len = length;
2582 skb->dev = dev;
2583
2584 memcpy(skb->data,(u_char *)arcsoft+1,length-1);
2585
2586 BUGLVL(D_SKB)
2587 {
2588 short i;
2589 printk("%6s: rx skb dump follows:\n",dev->name);
2590 for(i=0; i<skb->len; i++)
2591 {
2592 if (i%16==0)
2593 printk("\n[%04hX] ",i);
2594 else
2595 printk("%02hX ",((u_char *)skb->data)[i]);
2596 }
2597 printk("\n");
2598 }
2599
2600 #ifndef LINUX12
2601 skb->protocol=eth_type_trans(skb,dev);
2602 #endif
2603
2604 netif_rx(skb);
2605 }
2606
2607
2608
2609 static void
2610 arcnetS_rx(struct device *dev,u_char *buf,
2611 int length,u_char saddr, u_char daddr)
2612 {
2613 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
2614 struct sk_buff *skb;
2615 struct S_ClientData *arcsoft,*soft;
2616
2617 arcsoft=(struct S_ClientData *)(buf-S_EXTRA_CLIENTDATA);
2618 length+=S_EXTRA_CLIENTDATA;
2619
2620 BUGMSG(D_DURING,"it's an RFC1051 packet (length=%d)\n",
2621 length);
2622
2623
2624
2625 {
2626
2627 skb = alloc_skb(length, GFP_ATOMIC);
2628 if (skb == NULL) {
2629 printk("arcnetS: Memory squeeze, dropping packet.\n");
2630 lp->stats.rx_dropped++;
2631 return;
2632 }
2633 soft=(struct S_ClientData *)skb->data;
2634 skb->len = length;
2635 memcpy((u_char *)soft + sizeof(struct S_ClientData)
2636 - S_EXTRA_CLIENTDATA,
2637 (u_char *)arcsoft + sizeof(struct S_ClientData)
2638 - S_EXTRA_CLIENTDATA,
2639 length - sizeof(struct S_ClientData)
2640 + S_EXTRA_CLIENTDATA);
2641 soft->protocol_id=arcsoft->protocol_id;
2642 soft->daddr=daddr;
2643 soft->saddr=saddr;
2644 skb->dev = dev;
2645
2646 BUGLVL(D_SKB)
2647 {
2648 short i;
2649 for(i=0; i<skb->len; i++)
2650 {
2651 if( i%16 == 0 ) printk("\n[%04hX] ",i);
2652 printk("%02hX ",((unsigned char*)skb->data)[i]);
2653 }
2654 printk("\n");
2655 }
2656
2657 #ifndef LINUX12
2658 skb->protocol=arcnetS_type_trans(skb,dev);
2659 #endif
2660
2661 netif_rx(skb);
2662 }
2663 }
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678 static struct enet_statistics *
2679 arcnet_get_stats(struct device *dev)
2680 {
2681 struct arcnet_local *lp = (struct arcnet_local *)dev->priv;
2682
2683 return &lp->stats;
2684 }
2685
2686
2687
2688
2689
2690
2691
2692 static void
2693 set_multicast_list(struct device *dev, int num_addrs, void *addrs)
2694 {
2695 #if 0
2696 struct arcnet_local *lp=(struct arcnet_local *)(dev->priv);
2697
2698 short ioaddr = dev->base_addr;
2699 if (num_addrs) {
2700 outw(69, ioaddr);
2701 } else
2702 outw(99, ioaddr);
2703 #endif
2704 }
2705
2706
2707
2708
2709
2710
2711 #ifdef LINUX12
2712 int arcnetA_header(unsigned char *buff,struct device *dev,
2713 unsigned short type,void *daddr,void *saddr,unsigned len,
2714 struct sk_buff *skb)
2715 #else
2716 int arcnetA_header(struct sk_buff *skb,struct device *dev,
2717 unsigned short type,void *daddr,void *saddr,unsigned len)
2718 #endif
2719 {
2720 struct ClientData *head = (struct ClientData *)
2721 #ifdef LINUX12
2722 buff;
2723 #else
2724 skb_push(skb,dev->hard_header_len);
2725 #endif
2726 struct arcnet_local *lp=(struct arcnet_local *)(dev->priv);
2727
2728 BUGMSG(D_DURING,"create header from %d to %d; protocol %d (%Xh); size %u.\n",
2729 saddr ? *(u_char*)saddr : -1,
2730 daddr ? *(u_char*)daddr : -1,
2731 type,type,len);
2732
2733
2734 switch(type)
2735 {
2736 case ETH_P_IP:
2737 head->protocol_id=ARC_P_IP;
2738 break;
2739 case ETH_P_ARP:
2740 head->protocol_id=ARC_P_ARP;
2741 break;
2742 case ETH_P_RARP:
2743 head->protocol_id=ARC_P_RARP;
2744 break;
2745 case ETH_P_IPX:
2746 case ETH_P_802_3:
2747 case ETH_P_802_2:
2748 head->protocol_id=ARC_P_IPX;
2749 break;
2750 case ETH_P_ATALK:
2751 head->protocol_id=ARC_P_ATALK;
2752 break;
2753 default:
2754 printk("%6s: I don't understand protocol %d (%Xh)\n",
2755 dev->name,type,type);
2756 lp->stats.tx_errors++;
2757 lp->stats.tx_aborted_errors++;
2758 return 0;
2759 }
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769 if(saddr)
2770 head->saddr=((u_char*)saddr)[0];
2771 else
2772 head->saddr=((u_char*)(dev->dev_addr))[0];
2773
2774 head->split_flag=0;
2775 head->sequence=0;
2776
2777
2778 if(daddr)
2779 {
2780 head->daddr=((u_char*)daddr)[0];
2781 return dev->hard_header_len;
2782 }
2783 else
2784 head->daddr=0;
2785
2786 return -dev->hard_header_len;
2787 }
2788
2789
2790
2791
2792
2793
2794
2795 #ifdef LINUX12
2796 int arcnetS_header(unsigned char *buff,struct device *dev,
2797 unsigned short type,void *daddr,void *saddr,unsigned len,
2798 struct sk_buff *skb)
2799 #else
2800 int arcnetS_header(struct sk_buff *skb,struct device *dev,
2801 unsigned short type,void *daddr,void *saddr,unsigned len)
2802 #endif
2803 {
2804 struct S_ClientData *head = (struct S_ClientData *)
2805 #ifdef LINUX12
2806 buff;
2807 #else
2808 skb_push(skb,dev->hard_header_len);
2809 #endif
2810 struct arcnet_local *lp=(struct arcnet_local *)(dev->priv);
2811
2812
2813 switch(type)
2814 {
2815 case ETH_P_IP:
2816 head->protocol_id=ARC_P_IP_RFC1051;
2817 BUGMSG(D_DURING,"S_header: IP_RFC1051 packet.\n");
2818 break;
2819 case ETH_P_ARP:
2820 head->protocol_id=ARC_P_ARP_RFC1051;
2821 BUGMSG(D_DURING,"S_header: ARP_RFC1051 packet.\n");
2822 break;
2823 default:
2824 printk("arcnetS: I don't understand protocol %d (%Xh)\n",
2825 type,type);
2826 lp->stats.tx_errors++;
2827 lp->stats.tx_aborted_errors++;
2828 return 0;
2829 }
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839 if(saddr)
2840 head->saddr=((u_char*)saddr)[0];
2841 else
2842 head->saddr=((u_char*)(dev->dev_addr))[0];
2843
2844
2845 if(daddr)
2846 {
2847 head->daddr=((u_char*)daddr)[0];
2848 return dev->hard_header_len;
2849 }
2850 else
2851 head->daddr=0;
2852
2853 return -dev->hard_header_len;
2854 }
2855
2856
2857
2858
2859
2860
2861
2862 int arcnetA_rebuild_header(void *buff,struct device *dev,unsigned long dst,
2863 struct sk_buff *skb)
2864 {
2865 struct ClientData *head = (struct ClientData *)buff;
2866 struct arcnet_local *lp=(struct arcnet_local *)(dev->priv);
2867 int status;
2868
2869
2870
2871
2872
2873 if(head->protocol_id != ARC_P_IP)
2874 {
2875 printk("%6s: I don't understand protocol type %d (%Xh) addresses!\n",
2876 dev->name,head->protocol_id,head->protocol_id);
2877 lp->stats.tx_errors++;
2878 lp->stats.tx_aborted_errors++;
2879 head->daddr=0;
2880
2881 return 0;
2882 }
2883
2884
2885
2886
2887 #ifdef CONFIG_INET
2888 BUGMSG(D_DURING,"rebuild header from %d to %d; protocol %Xh\n",
2889 head->saddr,head->daddr,head->protocol_id);
2890 status=arp_find(&(head->daddr), dst, dev, dev->pa_addr, skb)? 1 : 0;
2891 BUGMSG(D_DURING," rebuilt: from %d to %d; protocol %Xh\n",
2892 head->saddr,head->daddr,head->protocol_id);
2893 return status;
2894 #else
2895 return 0;
2896 #endif
2897 }
2898
2899
2900 int arcnetS_rebuild_header(void *buff,struct device *dev,unsigned long dst,
2901 struct sk_buff *skb)
2902 {
2903 struct S_ClientData *head = (struct S_ClientData *)buff;
2904 struct arcnet_local *lp=(struct arcnet_local *)(dev->priv);
2905
2906
2907
2908
2909
2910 if(head->protocol_id != ARC_P_IP_RFC1051)
2911 {
2912 printk("arcnetS: I don't understand protocol type %d (%Xh) addresses!\n",
2913 head->protocol_id,head->protocol_id);
2914 lp->stats.tx_errors++;
2915 lp->stats.tx_aborted_errors++;
2916 head->daddr=0;
2917
2918 return 0;
2919 }
2920
2921
2922
2923
2924 #ifdef CONFIG_INET
2925 return arp_find(&(head->daddr), dst, dev, dev->pa_addr, skb)? 1 : 0;
2926 #else
2927 return 0;
2928 #endif
2929 }
2930
2931
2932
2933
2934
2935
2936 unsigned short arcnetA_type_trans(struct sk_buff *skb,struct device *dev)
2937 {
2938 struct ClientData *head;
2939 struct arcnet_local *lp=(struct arcnet_local *) (dev->priv);
2940
2941 #ifdef LINUX12
2942 head=(struct ClientData *)skb->data;
2943 #else
2944
2945 skb->mac.raw=skb->data;
2946 skb_pull(skb,dev->hard_header_len);
2947 head=(struct ClientData *)skb->mac.raw;
2948 #endif
2949
2950 if (head->daddr==0)
2951 skb->pkt_type=PACKET_BROADCAST;
2952 else if (dev->flags&IFF_PROMISC)
2953 {
2954
2955 if (head->daddr != dev->dev_addr[0])
2956 skb->pkt_type=PACKET_OTHERHOST;
2957 }
2958
2959
2960 switch (head->protocol_id)
2961 {
2962 case ARC_P_IP: return htons(ETH_P_IP);
2963 case ARC_P_ARP: return htons(ETH_P_ARP);
2964 case ARC_P_RARP: return htons(ETH_P_RARP);
2965 case ARC_P_IPX: return htons(ETH_P_802_3);
2966 case ARC_P_ATALK: return htons(ETH_P_ATALK);
2967 case ARC_P_LANSOFT:
2968 default:
2969 BUGMSG(D_EXTRA,"received packet of unknown protocol id %d (%Xh)\n",
2970 head->protocol_id,head->protocol_id);
2971 lp->stats.rx_errors++;
2972 lp->stats.rx_crc_errors++;
2973 return 0;
2974 }
2975
2976 return htons(ETH_P_IP);
2977 }
2978
2979
2980 unsigned short arcnetS_type_trans(struct sk_buff *skb,struct device *dev)
2981 {
2982 struct S_ClientData *head;
2983 struct arcnet_local *lp=(struct arcnet_local *) (dev->priv);
2984
2985 #ifdef LINUX12
2986 head=(struct S_ClientData *)skb->data;
2987 #else
2988
2989 skb->mac.raw=skb->data;
2990 skb_pull(skb,dev->hard_header_len);
2991 head=(struct S_ClientData *)skb->mac.raw;
2992 #endif
2993
2994 if (head->daddr==0)
2995 skb->pkt_type=PACKET_BROADCAST;
2996 else if (dev->flags&IFF_PROMISC)
2997 {
2998
2999 if (head->daddr != dev->dev_addr[0])
3000 skb->pkt_type=PACKET_OTHERHOST;
3001 }
3002
3003
3004 switch (head->protocol_id)
3005 {
3006 case ARC_P_IP_RFC1051: return htons(ETH_P_IP);
3007 case ARC_P_ARP_RFC1051: return htons(ETH_P_ARP);
3008 default:
3009 BUGMSG(D_EXTRA,"received packet of unknown protocol id %d (%Xh)\n",
3010 head->protocol_id,head->protocol_id);
3011 lp->stats.rx_errors++;
3012 lp->stats.rx_crc_errors++;
3013 return 0;
3014 }
3015
3016 return htons(ETH_P_IP);
3017 }
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028 #ifdef MODULE
3029 static char devicename[9] = { 0, };
3030 static struct device thiscard = {
3031 devicename,
3032 0, 0, 0, 0,
3033 0, 0,
3034 0, 0, 0, NULL, arcnet_probe
3035 };
3036
3037
3038 static int io=0x0;
3039 static int irqnum=0;
3040 static int shmem=0;
3041 static int num=0;
3042
3043 int
3044 init_module(void)
3045 {
3046 sprintf(thiscard.name,"arc%d",num);
3047
3048 thiscard.base_addr=io;
3049
3050 thiscard.irq=irqnum;
3051 if (thiscard.irq==2) thiscard.irq=9;
3052
3053 if (shmem)
3054 {
3055 thiscard.mem_start=shmem;
3056 thiscard.mem_end=thiscard.mem_start+512*4-1;
3057 thiscard.rmem_start=thiscard.mem_start+512*0;
3058 thiscard.rmem_end=thiscard.mem_start+512*2-1;
3059 }
3060
3061 if (register_netdev(&thiscard) != 0)
3062 return -EIO;
3063 return 0;
3064 }
3065
3066 void
3067 cleanup_module(void)
3068 {
3069 if (thiscard.start) arcnet_close(&thiscard);
3070 if (thiscard.irq) free_irq(thiscard.irq);
3071 if (thiscard.base_addr) release_region(thiscard.base_addr,
3072 ARCNET_TOTAL_SIZE);
3073 unregister_netdev(&thiscard);
3074 kfree(thiscard.priv);
3075 thiscard.priv = NULL;
3076 }
3077
3078 #endif
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090