This source file includes following definitions.
- inb_status
- inb_control
- inb_command
- outb_control
- outb_command
- inw_data
- outw_data
- get_status
- set_hsf
- wait_hcre
- wait_fast_hcre
- adapter_reset
- send_pcb
- receive_pcb
- adapter_hard_reset
- start_receive
- receive_packet
- elp_interrupt
- elp_open
- send_packet
- elp_start_xmit
- elp_get_stats
- elp_close
- elp_set_mc_list
- elp_init
- elp_sense
- elp_autodetect
- elplus_probe
- 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 #ifdef MODULE
37 #include <linux/module.h>
38 #include <linux/version.h>
39 #endif
40
41 #include <linux/kernel.h>
42 #include <linux/sched.h>
43 #include <linux/string.h>
44 #include <linux/interrupt.h>
45 #include <linux/ptrace.h>
46 #include <linux/errno.h>
47 #include <linux/in.h>
48 #include <linux/malloc.h>
49 #include <linux/ioport.h>
50 #include <asm/bitops.h>
51 #include <asm/io.h>
52
53 #include <linux/netdevice.h>
54 #include <linux/etherdevice.h>
55 #include <linux/skbuff.h>
56
57 #include "3c505.h"
58
59
60
61
62
63
64
65 static const char * filename = __FILE__;
66
67 static const char * null_msg = "*** NULL at %s:%s (line %d) ***\n";
68 #define CHECK_NULL(p) \
69 if (!p) printk(null_msg, filename,__FUNCTION__,__LINE__)
70
71 static const char * timeout_msg = "*** timeout at %s:%s (line %d) ***\n";
72 #define TIMEOUT_MSG(lineno) \
73 printk(timeout_msg, filename,__FUNCTION__,(lineno))
74
75 static const char * invalid_pcb_msg =
76 "*** invalid pcb length %d at %s:%s (line %d) ***\n";
77 #define INVALID_PCB_MSG(len) \
78 printk(invalid_pcb_msg, (len),filename,__FUNCTION__,__LINE__)
79
80 static const char * search_msg = "%s: Looking for 3c505 adapter at address %#x...";
81
82 static const char * stilllooking_msg = "still looking...";
83
84 static const char * found_msg = "found.\n";
85
86 static const char * notfound_msg = "not found (reason = %d)\n";
87
88 static const char * couldnot_msg = "%s: 3c505 not found\n";
89
90
91
92
93
94
95
96 #ifdef ELP_DEBUG
97 static int elp_debug = ELP_DEBUG;
98 #else
99 static int elp_debug = 0;
100 #endif
101
102
103
104
105
106
107
108
109 #define ELP_VERSION "0.8.1"
110
111
112
113
114
115
116
117 #ifndef TRUE
118 #define TRUE 1
119 #endif
120
121 #ifndef FALSE
122 #define FALSE 0
123 #endif
124
125
126
127
128
129
130
131
132 const int addr_list[]={0x300,0x280,0x310,0};
133
134
135
136
137
138
139
140 static inline unsigned char
141 inb_status (unsigned int base_addr)
142 {
143 return inb(base_addr+PORT_STATUS);
144 }
145
146 static inline unsigned char
147 inb_control (unsigned int base_addr)
148 {
149 return inb(base_addr+PORT_CONTROL);
150 }
151
152 static inline int
153 inb_command (unsigned int base_addr)
154 {
155 return inb(base_addr+PORT_COMMAND);
156 }
157
158 static inline void
159 outb_control (unsigned char val, unsigned int base_addr)
160 {
161 outb(val, base_addr+PORT_CONTROL);
162 }
163
164 static inline void
165 outb_command (unsigned char val, unsigned int base_addr)
166 {
167 outb(val, base_addr+PORT_COMMAND);
168 }
169
170 static inline unsigned int
171 inw_data (unsigned int base_addr)
172 {
173 return inw(base_addr+PORT_DATA);
174 }
175
176 static inline void
177 outw_data (unsigned int val, unsigned int base_addr)
178 {
179 outw(val, base_addr+PORT_DATA);
180 }
181
182
183
184
185
186
187
188
189 typedef struct {
190 volatile short got[NUM_TRANSMIT_CMDS];
191 pcb_struct tx_pcb;
192 pcb_struct rx_pcb;
193 pcb_struct itx_pcb;
194 pcb_struct irx_pcb;
195 struct enet_statistics stats;
196 } elp_device;
197
198 static int reset_count=0;
199
200
201
202
203
204
205
206
207
208
209
210
211
212 #define GET_ASF(addr) \
213 (get_status(addr)&ASF_PCB_MASK)
214
215 static inline int
216 get_status (unsigned int base_addr)
217 {
218 int timeout = jiffies + 10;
219 register int stat1;
220 do {
221 stat1 = inb_status(base_addr);
222 } while (stat1 != inb_status(base_addr) && jiffies < timeout);
223 if (jiffies >= timeout)
224 TIMEOUT_MSG(__LINE__);
225 return stat1;
226 }
227
228 static inline void
229 set_hsf (unsigned int base_addr, int hsf)
230 {
231 cli();
232 outb_control((inb_control(base_addr)&~HSF_PCB_MASK)|hsf, base_addr);
233 sti();
234 }
235
236 #define WAIT_HCRE(addr,toval) wait_hcre((addr),(toval),__LINE__)
237 static inline int
238 wait_hcre (unsigned int base_addr, int toval, int lineno)
239 {
240 int timeout = jiffies + toval;
241 while (((inb_status(base_addr)&HCRE)==0) && (jiffies <= timeout))
242 ;
243 if (jiffies >= timeout) {
244 TIMEOUT_MSG(lineno);
245 return FALSE;
246 }
247 return TRUE;
248 }
249
250 static inline int
251 wait_fast_hcre (unsigned int base_addr, int toval, int lineno)
252 {
253 int timeout = 0;
254 while (((inb_status(base_addr)&HCRE)==0) && (timeout++ < toval))
255 ;
256 if (timeout >= toval) {
257 sti();
258 TIMEOUT_MSG(lineno);
259 return FALSE;
260 }
261 return TRUE;
262 }
263
264 static int start_receive (struct device *, pcb_struct *);
265 static void adapter_hard_reset (struct device *);
266
267 inline static void
268 adapter_reset (struct device * dev)
269 {
270 int timeout;
271 unsigned char orig_hcr=inb_control(dev->base_addr);
272
273 elp_device * adapter=dev->priv;
274
275 outb_control(0,dev->base_addr);
276
277 if (inb_status(dev->base_addr)&ACRF) {
278 do {
279 inb_command(dev->base_addr);
280 timeout=jiffies+2;
281 while ((jiffies<=timeout) && !(inb_status(dev->base_addr)&ACRF))
282 ;
283 } while (inb_status(dev->base_addr)&ACRF);
284 set_hsf(dev->base_addr,HSF_PCB_NAK);
285 }
286
287 outb_control(inb_control(dev->base_addr)|ATTN|DIR,dev->base_addr);
288 timeout=jiffies+1;
289 while (jiffies<=timeout)
290 ;
291 outb_control(inb_control(dev->base_addr)&~ATTN,dev->base_addr);
292 timeout=jiffies+1;
293 while (jiffies<=timeout)
294 ;
295 outb_control(inb_control(dev->base_addr)|FLSH,dev->base_addr);
296 timeout=jiffies+1;
297 while (jiffies<=timeout)
298 ;
299 outb_control(inb_control(dev->base_addr)&~FLSH,dev->base_addr);
300 timeout=jiffies+1;
301 while (jiffies<=timeout)
302 ;
303
304 outb_control(orig_hcr, dev->base_addr);
305 if (!start_receive(dev, &adapter->tx_pcb))
306 printk("%s: start receive command failed \n", dev->name);
307 }
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324 static int
325 send_pcb (struct device * dev, pcb_struct * pcb)
326 {
327 int i;
328 int timeout;
329 int cont;
330
331
332
333
334
335
336 set_hsf(dev->base_addr,0);
337 if ((cont = WAIT_HCRE(dev->base_addr,5))) {
338 cli();
339 if (pcb->command==CMD_TRANSMIT_PACKET)
340 outb_control(inb_control(dev->base_addr)&~DIR,dev->base_addr);
341 outb_command(pcb->command, dev->base_addr);
342 sti();
343 cont = WAIT_HCRE(dev->base_addr,5);
344 }
345
346 if (cont) {
347 outb_command(pcb->length, dev->base_addr);
348 cont = WAIT_HCRE(dev->base_addr,5);
349 }
350
351 cli();
352 for (i = 0; cont && (i < pcb->length); i++) {
353 outb_command(pcb->data.raw[i], dev->base_addr);
354 cont = wait_fast_hcre(dev->base_addr,20000,__LINE__);
355 }
356
357
358
359
360 if (cont) {
361 set_hsf(dev->base_addr,HSF_PCB_END);
362 outb_command(2+pcb->length, dev->base_addr);
363 sti();
364 timeout = jiffies + 7;
365 while (jiffies < timeout) {
366 i = GET_ASF(dev->base_addr);
367 if ((i == ASF_PCB_ACK) || (i == ASF_PCB_NAK))
368 break;
369 }
370
371 if (i == ASF_PCB_ACK) {
372 reset_count=0;
373 return TRUE;
374 }
375 else if (i == ASF_PCB_NAK) {
376 printk("%s: PCB send was NAKed\n", dev->name);
377 } else {
378 printk("%s: timeout after sending PCB\n", dev->name);
379 }
380 } else {
381 sti();
382 printk("%s: timeout in middle of sending PCB\n", dev->name);
383 }
384
385 adapter_reset(dev);
386 return FALSE;
387 }
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402 static int
403 receive_pcb (struct device * dev, pcb_struct * pcb)
404 {
405 int i, j;
406 int total_length;
407 int stat;
408 int timeout;
409
410 CHECK_NULL(pcb);
411 CHECK_NULL(dev);
412
413 set_hsf(dev->base_addr,0);
414
415
416 timeout = jiffies + 2;
417 while (((stat = get_status(dev->base_addr))&ACRF) == 0 && jiffies < timeout)
418 ;
419 if (jiffies >= timeout) {
420 TIMEOUT_MSG(__LINE__);
421 return FALSE;
422 }
423
424 pcb->command = inb_command(dev->base_addr);
425
426
427 timeout = jiffies + 3;
428 while (((stat = get_status(dev->base_addr)) & ACRF) == 0 && jiffies < timeout)
429 ;
430 if (jiffies >= timeout) {
431 TIMEOUT_MSG(__LINE__);
432 return FALSE;
433 }
434 pcb->length = inb_command(dev->base_addr);
435
436 if (pcb->length > MAX_PCB_DATA) {
437 INVALID_PCB_MSG(pcb->length);
438 adapter_reset(dev);
439 return FALSE;
440 }
441
442
443 cli();
444 i = 0;
445 do {
446 j = 0;
447 while (((stat = get_status(dev->base_addr))&ACRF) == 0 && j++ < 20000)
448 ;
449 pcb->data.raw[i++] = inb_command(dev->base_addr);
450 if (i > MAX_PCB_DATA)
451 INVALID_PCB_MSG(i);
452 } while ((stat & ASF_PCB_MASK) != ASF_PCB_END && j < 20000);
453 sti();
454 if (j >= 20000) {
455 TIMEOUT_MSG(__LINE__);
456 return FALSE;
457 }
458
459
460 total_length = pcb->data.raw[--i];
461
462
463 if (total_length != (pcb->length + 2)) {
464 if (elp_debug >= 2)
465 printk("%s: mangled PCB received\n", dev->name);
466 set_hsf(dev->base_addr,HSF_PCB_NAK);
467 return FALSE;
468 }
469
470 set_hsf(dev->base_addr,HSF_PCB_ACK);
471 reset_count=0;
472 return TRUE;
473 }
474
475 static void
476 adapter_hard_reset (struct device * dev)
477 {
478 int timeout;
479
480 CHECK_NULL(dev);
481
482 if (elp_debug > 0)
483 printk("%s: Resetting the adapter, please wait (approx 20 s)\n",
484 dev->name);
485
486
487
488 outb_control(ATTN|FLSH, dev->base_addr);
489
490
491
492
493 for (timeout = jiffies + 20; jiffies <= timeout; )
494 ;
495
496
497
498
499 outb_control(0, dev->base_addr);
500
501
502
503
504 for (timeout = jiffies + 20; jiffies <= timeout; )
505 ;
506
507
508
509
510 for (timeout = jiffies + (100 * 15); jiffies <= timeout; )
511 if (GET_ASF(dev->base_addr) != ASF_PCB_END)
512 break;
513 }
514
515
516
517
518
519
520
521
522 static int
523 start_receive (struct device * dev, pcb_struct * tx_pcb)
524 {
525 CHECK_NULL(dev);
526 CHECK_NULL(tx_pcb);
527
528 if (elp_debug >= 3)
529 printk("%s: restarting receiver\n", dev->name);
530 tx_pcb->command = CMD_RECEIVE_PACKET;
531 tx_pcb->length = sizeof(struct Rcv_pkt);
532 tx_pcb->data.rcv_pkt.buf_seg
533 = tx_pcb->data.rcv_pkt.buf_ofs = 0;
534 tx_pcb->data.rcv_pkt.buf_len = 1600;
535 tx_pcb->data.rcv_pkt.timeout = 0;
536 return send_pcb(dev, tx_pcb);
537 }
538
539
540
541
542
543
544
545
546
547
548 static void
549 receive_packet (struct device * dev, int len)
550 {
551 register int i;
552 unsigned short * ptr;
553 int timeout;
554 int rlen;
555 struct sk_buff *skb;
556 elp_device * adapter;
557
558 CHECK_NULL(dev);
559 adapter=dev->priv;
560
561 if (len <= 0 || ((len & ~1) != len))
562 if (elp_debug >= 3) {
563 sti();
564 printk("*** bad packet len %d at %s(%d)\n",len,filename,__LINE__);
565 cli();
566 }
567
568 rlen = (len+1) & ~1;
569
570 skb = dev_alloc_skb(rlen+2);
571
572
573
574
575
576 outb_control(inb_control(dev->base_addr)|DIR, dev->base_addr);
577
578
579
580
581 if (skb == NULL) {
582 for (i = 0; i < (rlen/2); i++) {
583 timeout = 0;
584 while ((inb_status(dev->base_addr)&HRDY) == 0 && timeout++ < 20000)
585 ;
586 if (timeout >= 20000) {
587 sti();
588 TIMEOUT_MSG(__LINE__);
589 break;
590 }
591
592 inw_data(dev->base_addr);
593 }
594 adapter->stats.rx_dropped++;
595
596 } else {
597 skb_reserve(skb,2);
598 skb->dev = dev;
599
600
601
602
603 ptr = (unsigned short *)skb_put(skb,len);
604 for (i = 0; i < (rlen/2); i++) {
605 timeout = 0;
606 while ((inb_status(dev->base_addr)&HRDY) == 0 && timeout++ < 20000)
607 ;
608 if (timeout >= 20000) {
609 sti();
610 printk("*** timeout at %s(%d) reading word %d of %d ***\n",
611 filename,__LINE__, i, rlen/2);
612 kfree_skb(skb, FREE_WRITE);
613 return;
614 }
615
616 *ptr = inw_data(dev->base_addr);
617 ptr++;
618 }
619
620 sti();
621 skb->protocol=eth_type_trans(skb,dev);
622 netif_rx(skb);
623 }
624
625 outb_control(inb_control(dev->base_addr)&~DIR, dev->base_addr);
626 }
627
628
629
630
631
632
633
634
635 static void
636 elp_interrupt (int irq, struct pt_regs *reg_ptr)
637 {
638 int len;
639 int dlen;
640 struct device *dev;
641 elp_device * adapter;
642 int timeout;
643
644 if (irq < 0 || irq > 15) {
645 printk ("elp_interrupt(): illegal IRQ number found in interrupt routine (%i)\n", irq);
646 return;
647 }
648
649 dev = irq2dev_map[irq];
650
651 if (dev == NULL) {
652 printk ("elp_interrupt(): irq %d for unknown device.\n", irq);
653 return;
654 }
655
656 adapter = (elp_device *) dev->priv;
657
658 CHECK_NULL(adapter);
659
660 if (dev->interrupt)
661 if (elp_debug >= 2)
662 printk("%s: Re-entering the interrupt handler.\n", dev->name);
663 dev->interrupt = 1;
664
665
666
667
668 sti();
669
670
671
672
673 timeout = jiffies + 3;
674 while ((inb_status(dev->base_addr)&ACRF) != 0 && jiffies < timeout) {
675
676 if (receive_pcb(dev, &adapter->irx_pcb)) {
677
678 switch (adapter->irx_pcb.command) {
679
680
681
682
683 case CMD_RECEIVE_PACKET_COMPLETE:
684
685 if (dev->start == 0)
686 break;
687 cli();
688
689 outb_control(inb_control(dev->base_addr)|DIR,
690 dev->base_addr);
691 len = adapter->irx_pcb.data.rcv_resp.pkt_len;
692 dlen = adapter->irx_pcb.data.rcv_resp.buf_len;
693 if (adapter->irx_pcb.data.rcv_resp.timeout != 0) {
694 printk("%s: interrupt - packet not received correctly\n", dev->name);
695 sti();
696 } else {
697 if (elp_debug >= 3) {
698 sti();
699 printk("%s: interrupt - packet received of length %i (%i)\n", dev->name, len, dlen);
700 cli();
701 }
702 receive_packet(dev, dlen);
703 sti();
704 if (elp_debug >= 3)
705 printk("%s: packet received\n", dev->name);
706 }
707 if (dev->start && !start_receive(dev, &adapter->itx_pcb))
708 if (elp_debug >= 2)
709 printk("%s: interrupt - failed to send receive start PCB\n", dev->name);
710 if (elp_debug >= 3)
711 printk("%s: receive procedure complete\n", dev->name);
712
713 break;
714
715
716
717
718 case CMD_CONFIGURE_82586_RESPONSE:
719 adapter->got[CMD_CONFIGURE_82586] = 1;
720 if (elp_debug >= 3)
721 printk("%s: interrupt - configure response received\n", dev->name);
722 break;
723
724
725
726
727 case CMD_CONFIGURE_ADAPTER_RESPONSE:
728 adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] = 1;
729 if (elp_debug >= 3)
730 printk("%s: Adapter memory configuration %s.\n",dev->name,
731 adapter->irx_pcb.data.failed?"failed":"succeeded");
732 break;
733
734
735
736
737 case CMD_LOAD_MULTICAST_RESPONSE:
738 adapter->got[CMD_LOAD_MULTICAST_LIST] = 1;
739 if (elp_debug >= 3)
740 printk("%s: Multicast address list loading %s.\n",dev->name,
741 adapter->irx_pcb.data.failed?"failed":"succeeded");
742 break;
743
744
745
746
747 case CMD_SET_ADDRESS_RESPONSE:
748 adapter->got[CMD_SET_STATION_ADDRESS] = 1;
749 if (elp_debug >= 3)
750 printk("%s: Ethernet address setting %s.\n",dev->name,
751 adapter->irx_pcb.data.failed?"failed":"succeeded");
752 break;
753
754
755
756
757
758 case CMD_NETWORK_STATISTICS_RESPONSE:
759 adapter->stats.rx_packets += adapter->irx_pcb.data.netstat.tot_recv;
760 adapter->stats.tx_packets += adapter->irx_pcb.data.netstat.tot_xmit;
761 adapter->stats.rx_crc_errors += adapter->irx_pcb.data.netstat.err_CRC;
762 adapter->stats.rx_frame_errors += adapter->irx_pcb.data.netstat.err_align;
763 adapter->stats.rx_fifo_errors += adapter->irx_pcb.data.netstat.err_ovrrun;
764 adapter->got[CMD_NETWORK_STATISTICS] = 1;
765 if (elp_debug >= 3)
766 printk("%s: interrupt - statistics response received\n", dev->name);
767 break;
768
769
770
771
772 case CMD_TRANSMIT_PACKET_COMPLETE:
773 if (elp_debug >= 3)
774 printk("%s: interrupt - packet sent\n", dev->name);
775 if (dev->start == 0)
776 break;
777 if (adapter->irx_pcb.data.xmit_resp.c_stat != 0)
778 if (elp_debug >= 2)
779 printk("%s: interrupt - error sending packet %4.4x\n",
780 dev->name, adapter->irx_pcb.data.xmit_resp.c_stat);
781 dev->tbusy = 0;
782 mark_bh(NET_BH);
783 break;
784
785
786
787
788 default:
789 printk("%s: unknown PCB received - %2.2x\n", dev->name, adapter->irx_pcb.command);
790 break;
791 }
792 } else {
793 printk("%s: failed to read PCB on interrupt\n", dev->name);
794 adapter_reset(dev);
795 }
796 }
797
798
799
800
801 dev->interrupt = 0;
802 }
803
804
805
806
807
808
809
810
811 static int
812 elp_open (struct device *dev)
813 {
814 elp_device * adapter;
815
816 CHECK_NULL(dev);
817
818 adapter = dev->priv;
819
820 if (elp_debug >= 3)
821 printk("%s: request to open device\n", dev->name);
822
823
824
825
826 if (adapter == NULL) {
827 printk("%s: Opening a non-existent physical device\n", dev->name);
828 return -EAGAIN;
829 }
830
831
832
833
834 outb_control(0x00, dev->base_addr);
835
836
837
838
839 inb_command(dev->base_addr);
840 adapter_reset(dev);
841
842
843
844
845 dev->interrupt = 0;
846
847
848
849
850 dev->tbusy = 0;
851
852
853
854
855 irq2dev_map[dev->irq] = dev;
856
857
858
859
860 if (request_irq(dev->irq, &elp_interrupt, 0, "3c505")) {
861 irq2dev_map[dev->irq] = NULL;
862 return -EAGAIN;
863 }
864
865
866
867
868 outb_control(CMDE, dev->base_addr);
869
870
871
872
873 dev->start = 1;
874
875
876
877
878 if (elp_debug >= 3)
879 printk("%s: sending 3c505 memory configuration command\n", dev->name);
880 adapter->tx_pcb.command = CMD_CONFIGURE_ADAPTER_MEMORY;
881 adapter->tx_pcb.data.memconf.cmd_q = 10;
882 adapter->tx_pcb.data.memconf.rcv_q = 20;
883 adapter->tx_pcb.data.memconf.mcast = 10;
884 adapter->tx_pcb.data.memconf.frame = 20;
885 adapter->tx_pcb.data.memconf.rcv_b = 20;
886 adapter->tx_pcb.data.memconf.progs = 0;
887 adapter->tx_pcb.length = sizeof(struct Memconf);
888 adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] = 0;
889 if (!send_pcb(dev, &adapter->tx_pcb))
890 printk("%s: couldn't send memory configuration command\n", dev->name);
891 else {
892 int timeout = jiffies + TIMEOUT;
893 while (adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] == 0 && jiffies < timeout)
894 ;
895 if (jiffies >= timeout)
896 TIMEOUT_MSG(__LINE__);
897 }
898
899
900
901
902
903 if (elp_debug >= 3)
904 printk("%s: sending 82586 configure command\n", dev->name);
905 adapter->tx_pcb.command = CMD_CONFIGURE_82586;
906 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD;
907 adapter->tx_pcb.length = 2;
908 adapter->got[CMD_CONFIGURE_82586] = 0;
909 if (!send_pcb(dev, &adapter->tx_pcb))
910 printk("%s: couldn't send 82586 configure command\n", dev->name);
911 else {
912 int timeout = jiffies + TIMEOUT;
913 while (adapter->got[CMD_CONFIGURE_82586] == 0 && jiffies < timeout)
914 ;
915 if (jiffies >= timeout)
916 TIMEOUT_MSG(__LINE__);
917 }
918
919
920
921
922 if (!start_receive(dev, &adapter->tx_pcb))
923 printk("%s: start receive command failed \n", dev->name);
924 if (elp_debug >= 3)
925 printk("%s: start receive command sent\n", dev->name);
926
927 #ifdef MODULE
928 MOD_INC_USE_COUNT;
929 #endif
930
931 return 0;
932 }
933
934
935
936
937
938
939
940
941 static int
942 send_packet (struct device * dev, unsigned char * ptr, int len)
943 {
944 int i;
945 int timeout = 0;
946 elp_device * adapter;
947
948
949
950
951 unsigned int nlen = (((len < 60) ? 60 : len) + 1) & (~1);
952
953 CHECK_NULL(dev);
954 CHECK_NULL(ptr);
955
956 adapter = dev->priv;
957
958 if (nlen < len)
959 printk("Warning, bad length nlen=%d len=%d %s(%d)\n",nlen,len,filename,__LINE__);
960
961
962
963
964
965 adapter->tx_pcb.command = CMD_TRANSMIT_PACKET;
966 adapter->tx_pcb.length = sizeof(struct Xmit_pkt);
967 adapter->tx_pcb.data.xmit_pkt.buf_ofs
968 = adapter->tx_pcb.data.xmit_pkt.buf_seg = 0;
969 adapter->tx_pcb.data.xmit_pkt.pkt_len = nlen;
970 if (!send_pcb(dev, &adapter->tx_pcb)) {
971 return FALSE;
972 }
973
974
975
976
977 cli();
978 for (i = 0; i < (nlen/2);i++) {
979 while (((inb_status(dev->base_addr)&HRDY) == 0)
980 && (timeout++ < 20000))
981 ;
982 if (timeout >= 20000) {
983 sti();
984 printk("%s: timeout at %s(%d) writing word %d of %d ***\n",
985 dev->name,filename,__LINE__, i, nlen/2);
986 return FALSE;
987 }
988
989 outw_data(*(short *)ptr, dev->base_addr);
990 ptr +=2;
991 }
992 sti();
993
994 return TRUE;
995 }
996
997
998
999
1000
1001
1002
1003
1004 static int
1005 elp_start_xmit (struct sk_buff *skb, struct device *dev)
1006 {
1007 CHECK_NULL(dev);
1008
1009
1010
1011
1012 if (skb == NULL) {
1013 dev_tint(dev);
1014 return 0;
1015 }
1016
1017
1018
1019
1020 if (skb->len <= 0)
1021 return 0;
1022
1023 if (elp_debug >= 3)
1024 printk("%s: request to send packet of length %d\n", dev->name, (int)skb->len);
1025
1026
1027
1028
1029 if (dev->tbusy) {
1030 int tickssofar = jiffies - dev->trans_start;
1031 int stat;
1032 if (tickssofar < 50)
1033 return 1;
1034 printk("%s: transmit timed out, not resetting adapter\n", dev->name);
1035 if (((stat=inb_status(dev->base_addr))&ACRF) != 0)
1036 printk("%s: hmmm...seemed to have missed an interrupt!\n", dev->name);
1037 printk("%s: status %#02x\n", dev->name, stat);
1038 dev->trans_start = jiffies;
1039 dev->tbusy = 0;
1040 }
1041
1042
1043
1044
1045 if (!send_packet(dev, skb->data, skb->len)) {
1046 printk("%s: send packet PCB failed\n", dev->name);
1047 return 1;
1048 }
1049
1050 if (elp_debug >= 3)
1051 printk("%s: packet of length %d sent\n", dev->name, (int)skb->len);
1052
1053
1054
1055
1056
1057 dev->trans_start = jiffies;
1058
1059
1060
1061
1062 dev->tbusy = 1;
1063
1064
1065
1066
1067 dev_kfree_skb(skb, FREE_WRITE);
1068
1069 return 0;
1070 }
1071
1072
1073
1074
1075
1076
1077
1078 static struct enet_statistics *
1079 elp_get_stats (struct device *dev)
1080 {
1081 elp_device *adapter = (elp_device *) dev->priv;
1082
1083 if (elp_debug >= 3)
1084 printk("%s: request for stats\n", dev->name);
1085
1086
1087
1088 if (!dev->start)
1089 return &adapter->stats;
1090
1091
1092 adapter->tx_pcb.command = CMD_NETWORK_STATISTICS;
1093 adapter->tx_pcb.length = 0;
1094 adapter->got[CMD_NETWORK_STATISTICS] = 0;
1095 if (!send_pcb(dev, &adapter->tx_pcb))
1096 printk("%s: couldn't send get statistics command\n", dev->name);
1097 else {
1098 int timeout = jiffies + TIMEOUT;
1099 while (adapter->got[CMD_NETWORK_STATISTICS] == 0 && jiffies < timeout)
1100 ;
1101 if (jiffies >= timeout) {
1102 TIMEOUT_MSG(__LINE__);
1103 return &adapter->stats;
1104 }
1105 }
1106
1107
1108 return &adapter->stats;
1109 }
1110
1111
1112
1113
1114
1115
1116
1117 static int
1118 elp_close (struct device *dev)
1119 {
1120 elp_device * adapter;
1121
1122 CHECK_NULL(dev);
1123 adapter = dev->priv;
1124 CHECK_NULL(adapter);
1125
1126 if (elp_debug >= 3)
1127 printk("%s: request to close device\n", dev->name);
1128
1129
1130
1131
1132
1133 (void) elp_get_stats(dev);
1134
1135
1136
1137
1138 outb_control(0x00, dev->base_addr);
1139
1140
1141
1142
1143 dev->tbusy = 1;
1144
1145
1146
1147
1148 dev->start = 0;
1149
1150
1151
1152
1153 free_irq(dev->irq);
1154
1155
1156
1157
1158 irq2dev_map[dev->irq] = 0;
1159
1160 #ifdef MODULE
1161 MOD_DEC_USE_COUNT;
1162 #endif
1163
1164 return 0;
1165 }
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177 static void
1178 elp_set_mc_list (struct device *dev, int num_addrs, void *addrs)
1179 {
1180 elp_device *adapter = (elp_device *) dev->priv;
1181 int i;
1182
1183 if (elp_debug >= 3)
1184 printk("%s: request to set multicast list\n", dev->name);
1185
1186 if (num_addrs != -1) {
1187
1188
1189 adapter->tx_pcb.command = CMD_LOAD_MULTICAST_LIST;
1190 adapter->tx_pcb.length = 6*num_addrs;
1191 for (i=0;i<num_addrs;i++)
1192 memcpy(adapter->tx_pcb.data.multicast[i], addrs+6*i,6);
1193 adapter->got[CMD_LOAD_MULTICAST_LIST] = 0;
1194 if (!send_pcb(dev, &adapter->tx_pcb))
1195 printk("%s: couldn't send set_multicast command\n", dev->name);
1196 else {
1197 int timeout = jiffies + TIMEOUT;
1198 while (adapter->got[CMD_LOAD_MULTICAST_LIST] == 0 && jiffies < timeout)
1199 ;
1200 if (jiffies >= timeout) {
1201 TIMEOUT_MSG(__LINE__);
1202 }
1203 }
1204 if (num_addrs)
1205 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD | RECV_MULTI;
1206 else
1207 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD;
1208 } else
1209 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_PROMISC;
1210
1211
1212
1213
1214 if (elp_debug >= 3)
1215 printk("%s: sending 82586 configure command\n", dev->name);
1216 adapter->tx_pcb.command = CMD_CONFIGURE_82586;
1217 adapter->tx_pcb.length = 2;
1218 adapter->got[CMD_CONFIGURE_82586] = 0;
1219 if (!send_pcb(dev, &adapter->tx_pcb))
1220 printk("%s: couldn't send 82586 configure command\n", dev->name);
1221 else {
1222 int timeout = jiffies + TIMEOUT;
1223 while (adapter->got[CMD_CONFIGURE_82586] == 0 && jiffies < timeout)
1224 ;
1225 if (jiffies >= timeout)
1226 TIMEOUT_MSG(__LINE__);
1227 }
1228 }
1229
1230
1231
1232
1233
1234
1235
1236 static void
1237 elp_init (struct device *dev)
1238 {
1239 elp_device * adapter;
1240
1241 CHECK_NULL(dev);
1242
1243
1244
1245
1246 dev->open = elp_open;
1247 dev->stop = elp_close;
1248 dev->get_stats = elp_get_stats;
1249 dev->hard_start_xmit = elp_start_xmit;
1250 dev->set_multicast_list = elp_set_mc_list;
1251
1252
1253 ether_setup(dev);
1254
1255
1256
1257
1258 adapter = (elp_device *)(dev->priv = kmalloc(sizeof(elp_device), GFP_KERNEL));
1259 CHECK_NULL(adapter);
1260 if (adapter == NULL)
1261 return -ENOMEM;
1262 memset(&(adapter->stats), 0, sizeof(struct enet_statistics));
1263
1264
1265
1266
1267 dev->mem_start = dev->mem_end = dev->rmem_end = dev->rmem_start = 0;
1268 }
1269
1270
1271
1272
1273
1274
1275
1276 static int
1277 elp_sense (struct device * dev)
1278 {
1279 int timeout;
1280 int addr=dev->base_addr;
1281 const char *name=dev->name;
1282
1283 byte orig_HCR=inb_control(addr),
1284 orig_HSR=inb_status(addr);
1285
1286 if (elp_debug > 0)
1287 printk(search_msg, name, addr);
1288
1289 if (((orig_HCR==0xff) && (orig_HSR==0xff)) ||
1290 ((orig_HCR & DIR) != (orig_HSR & DIR))) {
1291 if (elp_debug > 0)
1292 printk(notfound_msg, 1);
1293 return -1;
1294 }
1295
1296
1297 if (elp_debug > 0)
1298 printk(stilllooking_msg);
1299 for (timeout = jiffies + (100 * 15); jiffies <= timeout; )
1300 if (GET_ASF(addr) != ASF_PCB_END)
1301 break;
1302
1303 if (orig_HCR & DIR) {
1304
1305 outb_control(orig_HCR & ~DIR,addr);
1306 timeout = jiffies+30;
1307 while (jiffies < timeout)
1308 ;
1309 if (inb_status(addr) & DIR) {
1310 outb_control(orig_HCR,addr);
1311 if (elp_debug > 0)
1312 printk(notfound_msg, 2);
1313 return -1;
1314 }
1315 } else {
1316
1317 outb_control(orig_HCR | DIR,addr);
1318 timeout = jiffies+300;
1319 while (jiffies < timeout)
1320 ;
1321 if (!(inb_status(addr) & DIR)) {
1322 outb_control(orig_HCR,addr);
1323 if (elp_debug > 0)
1324 printk(notfound_msg, 3);
1325 return -1;
1326 }
1327 }
1328
1329
1330
1331
1332 if (elp_debug > 0)
1333 printk(found_msg);
1334
1335 if (((orig_HCR==0x35) && (orig_HSR==0x5b)) || ELP_NEED_HARD_RESET)
1336 adapter_hard_reset(dev);
1337 return 0;
1338 }
1339
1340
1341
1342
1343
1344
1345
1346 static int
1347 elp_autodetect (struct device * dev)
1348 {
1349 int idx=0;
1350
1351
1352
1353 if (dev->base_addr != 0) {
1354 if (elp_sense(dev) == 0)
1355 return dev->base_addr;
1356 } else while ( (dev->base_addr=addr_list[idx++]) ) {
1357 if (elp_sense(dev) == 0)
1358 return dev->base_addr;
1359 }
1360
1361
1362 if (elp_debug > 0)
1363 printk(couldnot_msg, dev->name);
1364
1365 return 0;
1366 }
1367
1368
1369
1370
1371
1372
1373
1374 int
1375 elplus_probe (struct device *dev)
1376 {
1377 elp_device adapter;
1378 int i;
1379
1380 CHECK_NULL(dev);
1381
1382
1383
1384
1385
1386 dev->base_addr = elp_autodetect(dev);
1387 if ( !(dev->base_addr) )
1388 return -ENODEV;
1389
1390
1391
1392
1393
1394 outb_control(inb_control(dev->base_addr) | CMDE, dev->base_addr);
1395 autoirq_setup(0);
1396
1397
1398
1399
1400
1401 adapter.tx_pcb.command = CMD_STATION_ADDRESS;
1402 adapter.tx_pcb.length = 0;
1403 if (!send_pcb (dev, &adapter.tx_pcb) ||
1404 !receive_pcb(dev, &adapter.rx_pcb) ||
1405 (adapter.rx_pcb.command != CMD_ADDRESS_RESPONSE) ||
1406 (adapter.rx_pcb.length != 6)) {
1407 printk("%s: not responding to first PCB\n", dev->name);
1408 return -ENODEV;
1409 }
1410
1411 if (dev->irq) {
1412 if (dev->irq != autoirq_report(0)) {
1413 printk("%s: Detected IRQ doesn't match user-defined one.\n",dev->name);
1414 return -ENODEV;
1415 }
1416
1417 } else
1418 dev->irq=autoirq_report(0);
1419 switch (dev->irq) {
1420 case 0:
1421 printk("%s: No IRQ reported by autoirq_report().\n",dev->name);
1422 printk("%s: Check the jumpers of your 3c505 board.\n",dev->name);
1423 return -ENODEV;
1424 case 1:
1425 case 6:
1426 case 8:
1427 case 13:
1428 printk("%s: Impossible IRQ %d reported by autoirq_report().\n",
1429 dev->name, dev->irq);
1430 return -ENODEV;
1431 }
1432
1433
1434
1435
1436 outb_control(inb_control(dev->base_addr) & ~CMDE, dev->base_addr);
1437
1438
1439
1440
1441 for (i = 0; i < 6; i++)
1442 dev->dev_addr[i] = adapter.rx_pcb.data.eth_addr[i];
1443
1444
1445
1446
1447 printk("%s: 3c505 card found at I/O %#lx using IRQ%d"
1448 " has address %02x:%02x:%02x:%02x:%02x:%02x\n",
1449 dev->name, dev->base_addr, dev->irq,
1450 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
1451 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
1452
1453
1454
1455
1456 request_region(dev->base_addr, ELP_IO_EXTENT, "3c505");
1457
1458
1459
1460
1461 elp_init(dev);
1462 return 0;
1463 }
1464 #ifdef MODULE
1465 char kernel_version[] = UTS_RELEASE;
1466 static char devicename[9] = { 0, };
1467 static struct device dev_3c505 = {
1468 devicename,
1469 0, 0, 0, 0,
1470 0, 0,
1471 0, 0, 0, NULL, elplus_probe };
1472
1473 int io = 0x300;
1474 int irq = 0;
1475
1476 int init_module(void)
1477 {
1478 if (io == 0)
1479 printk("3c505: You should not use auto-probing with insmod!\n");
1480 dev_3c505.base_addr = io;
1481 dev_3c505.irq = irq;
1482 if (register_netdev(&dev_3c505) != 0) {
1483 printk("3c505: register_netdev() returned non-zero.\n");
1484 return -EIO;
1485 }
1486 return 0;
1487 }
1488
1489 void
1490 cleanup_module(void)
1491 {
1492 if (MOD_IN_USE)
1493 printk("3c505: device busy, remove delayed\n");
1494 else
1495 {
1496 unregister_netdev(&dev_3c505);
1497 kfree(dev_3c505.priv);
1498 dev_3c505.priv = NULL;
1499
1500
1501 release_region(dev_3c505.base_addr, ELP_IO_EXTENT);
1502 }
1503 }
1504 #endif