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