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