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