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