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