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