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 printk("%s: timeout in middle of sending PCB\n", dev->name);
382
383 adapter_reset(dev);
384 return FALSE;
385 }
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400 static int
401 receive_pcb (struct device * dev, pcb_struct * pcb)
402 {
403 int i, j;
404 int total_length;
405 int stat;
406 int timeout;
407
408 CHECK_NULL(pcb);
409 CHECK_NULL(dev);
410
411 set_hsf(dev->base_addr,0);
412
413
414 timeout = jiffies + 2;
415 while (((stat = get_status(dev->base_addr))&ACRF) == 0 && jiffies < timeout)
416 ;
417 if (jiffies >= timeout) {
418 TIMEOUT_MSG(__LINE__);
419 return FALSE;
420 }
421
422 pcb->command = inb_command(dev->base_addr);
423
424
425 timeout = jiffies + 3;
426 while (((stat = get_status(dev->base_addr)) & ACRF) == 0 && jiffies < timeout)
427 ;
428 if (jiffies >= timeout) {
429 TIMEOUT_MSG(__LINE__);
430 return FALSE;
431 }
432 pcb->length = inb_command(dev->base_addr);
433
434 if (pcb->length > MAX_PCB_DATA) {
435 INVALID_PCB_MSG(pcb->length);
436 adapter_reset(dev);
437 return FALSE;
438 }
439
440
441 cli();
442 i = 0;
443 do {
444 j = 0;
445 while (((stat = get_status(dev->base_addr))&ACRF) == 0 && j++ < 20000)
446 ;
447 pcb->data.raw[i++] = inb_command(dev->base_addr);
448 if (i > MAX_PCB_DATA)
449 INVALID_PCB_MSG(i);
450 } while ((stat & ASF_PCB_MASK) != ASF_PCB_END && j < 20000);
451 sti();
452 if (j >= 20000) {
453 TIMEOUT_MSG(__LINE__);
454 return FALSE;
455 }
456
457
458 total_length = pcb->data.raw[--i];
459
460
461 if (total_length != (pcb->length + 2)) {
462 if (elp_debug >= 2)
463 printk("%s: mangled PCB received\n", dev->name);
464 set_hsf(dev->base_addr,HSF_PCB_NAK);
465 return FALSE;
466 }
467
468 set_hsf(dev->base_addr,HSF_PCB_ACK);
469 reset_count=0;
470 return TRUE;
471 }
472
473 static void
474 adapter_hard_reset (struct device * dev)
475 {
476 int timeout;
477
478 CHECK_NULL(dev);
479
480 if (elp_debug > 0)
481 printk("%s: Resetting the adapter, please wait (approx 20 s)\n",
482 dev->name);
483
484
485
486 outb_control(ATTN|FLSH, dev->base_addr);
487
488
489
490
491 for (timeout = jiffies + 20; jiffies <= timeout; )
492 ;
493
494
495
496
497 outb_control(0, dev->base_addr);
498
499
500
501
502 for (timeout = jiffies + 20; jiffies <= timeout; )
503 ;
504
505
506
507
508 for (timeout = jiffies + (100 * 15); jiffies <= timeout; )
509 if (GET_ASF(dev->base_addr) != ASF_PCB_END)
510 break;
511 }
512
513
514
515
516
517
518
519
520 static int
521 start_receive (struct device * dev, pcb_struct * tx_pcb)
522 {
523 CHECK_NULL(dev);
524 CHECK_NULL(tx_pcb);
525
526 if (elp_debug >= 3)
527 printk("%s: restarting receiver\n", dev->name);
528 tx_pcb->command = CMD_RECEIVE_PACKET;
529 tx_pcb->length = sizeof(struct Rcv_pkt);
530 tx_pcb->data.rcv_pkt.buf_seg
531 = tx_pcb->data.rcv_pkt.buf_ofs = 0;
532 tx_pcb->data.rcv_pkt.buf_len = 1600;
533 tx_pcb->data.rcv_pkt.timeout = 0;
534 return send_pcb(dev, tx_pcb);
535 }
536
537
538
539
540
541
542
543
544
545
546 static void
547 receive_packet (struct device * dev, int len)
548 {
549 register int i;
550 unsigned short * ptr;
551 int timeout;
552 int rlen;
553 struct sk_buff *skb;
554 elp_device * adapter;
555
556 CHECK_NULL(dev);
557 adapter=dev->priv;
558
559 if (len <= 0 || ((len & ~1) != len))
560 if (elp_debug >= 3) {
561 sti();
562 printk("*** bad packet len %d at %s(%d)\n",len,filename,__LINE__);
563 cli();
564 }
565
566 rlen = (len+1) & ~1;
567
568 skb = dev_alloc_skb(rlen+2);
569
570
571
572
573
574 outb_control(inb_control(dev->base_addr)|DIR, dev->base_addr);
575
576
577
578
579 if (skb == NULL) {
580 for (i = 0; i < (rlen/2); i++) {
581 timeout = 0;
582 while ((inb_status(dev->base_addr)&HRDY) == 0 && timeout++ < 20000)
583 ;
584 if (timeout >= 20000) {
585 sti();
586 TIMEOUT_MSG(__LINE__);
587 break;
588 }
589
590 inw_data(dev->base_addr);
591 }
592 adapter->stats.rx_dropped++;
593
594 } else {
595 skb_reserve(skb,2);
596 skb->dev = dev;
597
598
599
600
601 ptr = (unsigned short *)skb_put(skb,len);
602 for (i = 0; i < (rlen/2); i++) {
603 timeout = 0;
604 while ((inb_status(dev->base_addr)&HRDY) == 0 && timeout++ < 20000)
605 ;
606 if (timeout >= 20000) {
607 sti();
608 printk("*** timeout at %s(%d) reading word %d of %d ***\n",
609 filename,__LINE__, i, rlen/2);
610 kfree_skb(skb, FREE_WRITE);
611 return;
612 }
613
614 *ptr = inw_data(dev->base_addr);
615 ptr++;
616 }
617
618 sti();
619 skb->protocol=eth_type_trans(skb,dev);
620 netif_rx(skb);
621 }
622
623 outb_control(inb_control(dev->base_addr)&~DIR, dev->base_addr);
624 }
625
626
627
628
629
630
631
632
633 static void
634 elp_interrupt (int irq, struct pt_regs *reg_ptr)
635 {
636 int len;
637 int dlen;
638 struct device *dev;
639 elp_device * adapter;
640 int timeout;
641
642 if (irq < 0 || irq > 15) {
643 printk ("elp_interrupt(): illegal IRQ number found in interrupt routine (%i)\n", irq);
644 return;
645 }
646
647 dev = irq2dev_map[irq];
648
649 if (dev == NULL) {
650 printk ("elp_interrupt(): irq %d for unknown device.\n", irq);
651 return;
652 }
653
654 adapter = (elp_device *) dev->priv;
655
656 CHECK_NULL(adapter);
657
658 if (dev->interrupt)
659 if (elp_debug >= 2)
660 printk("%s: Re-entering the interrupt handler.\n", dev->name);
661 dev->interrupt = 1;
662
663
664
665
666 sti();
667
668
669
670
671 timeout = jiffies + 3;
672 while ((inb_status(dev->base_addr)&ACRF) != 0 && jiffies < timeout) {
673
674 if (receive_pcb(dev, &adapter->irx_pcb)) {
675
676 switch (adapter->irx_pcb.command) {
677
678
679
680
681 case CMD_RECEIVE_PACKET_COMPLETE:
682
683 if (dev->start == 0)
684 break;
685 cli();
686
687 outb_control(inb_control(dev->base_addr)|DIR,
688 dev->base_addr);
689 len = adapter->irx_pcb.data.rcv_resp.pkt_len;
690 dlen = adapter->irx_pcb.data.rcv_resp.buf_len;
691 if (adapter->irx_pcb.data.rcv_resp.timeout != 0) {
692 printk("%s: interrupt - packet not received correctly\n", dev->name);
693 sti();
694 } else {
695 if (elp_debug >= 3) {
696 sti();
697 printk("%s: interrupt - packet received of length %i (%i)\n", dev->name, len, dlen);
698 cli();
699 }
700 receive_packet(dev, dlen);
701 sti();
702 if (elp_debug >= 3)
703 printk("%s: packet received\n", dev->name);
704 }
705 if (dev->start && !start_receive(dev, &adapter->itx_pcb))
706 if (elp_debug >= 2)
707 printk("%s: interrupt - failed to send receive start PCB\n", dev->name);
708 if (elp_debug >= 3)
709 printk("%s: receive procedure complete\n", dev->name);
710
711 break;
712
713
714
715
716 case CMD_CONFIGURE_82586_RESPONSE:
717 adapter->got[CMD_CONFIGURE_82586] = 1;
718 if (elp_debug >= 3)
719 printk("%s: interrupt - configure response received\n", dev->name);
720 break;
721
722
723
724
725 case CMD_CONFIGURE_ADAPTER_RESPONSE:
726 adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] = 1;
727 if (elp_debug >= 3)
728 printk("%s: Adapter memory configuration %s.\n",dev->name,
729 adapter->irx_pcb.data.failed?"failed":"succeeded");
730 break;
731
732
733
734
735 case CMD_LOAD_MULTICAST_RESPONSE:
736 adapter->got[CMD_LOAD_MULTICAST_LIST] = 1;
737 if (elp_debug >= 3)
738 printk("%s: Multicast address list loading %s.\n",dev->name,
739 adapter->irx_pcb.data.failed?"failed":"succeeded");
740 break;
741
742
743
744
745 case CMD_SET_ADDRESS_RESPONSE:
746 adapter->got[CMD_SET_STATION_ADDRESS] = 1;
747 if (elp_debug >= 3)
748 printk("%s: Ethernet address setting %s.\n",dev->name,
749 adapter->irx_pcb.data.failed?"failed":"succeeded");
750 break;
751
752
753
754
755
756 case CMD_NETWORK_STATISTICS_RESPONSE:
757 adapter->stats.rx_packets += adapter->irx_pcb.data.netstat.tot_recv;
758 adapter->stats.tx_packets += adapter->irx_pcb.data.netstat.tot_xmit;
759 adapter->stats.rx_crc_errors += adapter->irx_pcb.data.netstat.err_CRC;
760 adapter->stats.rx_frame_errors += adapter->irx_pcb.data.netstat.err_align;
761 adapter->stats.rx_fifo_errors += adapter->irx_pcb.data.netstat.err_ovrrun;
762 adapter->got[CMD_NETWORK_STATISTICS] = 1;
763 if (elp_debug >= 3)
764 printk("%s: interrupt - statistics response received\n", dev->name);
765 break;
766
767
768
769
770 case CMD_TRANSMIT_PACKET_COMPLETE:
771 if (elp_debug >= 3)
772 printk("%s: interrupt - packet sent\n", dev->name);
773 if (dev->start == 0)
774 break;
775 if (adapter->irx_pcb.data.xmit_resp.c_stat != 0)
776 if (elp_debug >= 2)
777 printk("%s: interrupt - error sending packet %4.4x\n",
778 dev->name, adapter->irx_pcb.data.xmit_resp.c_stat);
779 dev->tbusy = 0;
780 mark_bh(NET_BH);
781 break;
782
783
784
785
786 default:
787 printk("%s: unknown PCB received - %2.2x\n", dev->name, adapter->irx_pcb.command);
788 break;
789 }
790 } else {
791 printk("%s: failed to read PCB on interrupt\n", dev->name);
792 adapter_reset(dev);
793 }
794 }
795
796
797
798
799 dev->interrupt = 0;
800 }
801
802
803
804
805
806
807
808
809 static int
810 elp_open (struct device *dev)
811 {
812 elp_device * adapter;
813
814 CHECK_NULL(dev);
815
816 adapter = dev->priv;
817
818 if (elp_debug >= 3)
819 printk("%s: request to open device\n", dev->name);
820
821
822
823
824 if (adapter == NULL) {
825 printk("%s: Opening a non-existent physical device\n", dev->name);
826 return -EAGAIN;
827 }
828
829
830
831
832 outb_control(0x00, dev->base_addr);
833
834
835
836
837 inb_command(dev->base_addr);
838 adapter_reset(dev);
839
840
841
842
843 dev->interrupt = 0;
844
845
846
847
848 dev->tbusy = 0;
849
850
851
852
853 irq2dev_map[dev->irq] = dev;
854
855
856
857
858 if (request_irq(dev->irq, &elp_interrupt, 0, "3c505")) {
859 irq2dev_map[dev->irq] = NULL;
860 return -EAGAIN;
861 }
862
863
864
865
866 outb_control(CMDE, dev->base_addr);
867
868
869
870
871 dev->start = 1;
872
873
874
875
876 if (elp_debug >= 3)
877 printk("%s: sending 3c505 memory configuration command\n", dev->name);
878 adapter->tx_pcb.command = CMD_CONFIGURE_ADAPTER_MEMORY;
879 adapter->tx_pcb.data.memconf.cmd_q = 10;
880 adapter->tx_pcb.data.memconf.rcv_q = 20;
881 adapter->tx_pcb.data.memconf.mcast = 10;
882 adapter->tx_pcb.data.memconf.frame = 20;
883 adapter->tx_pcb.data.memconf.rcv_b = 20;
884 adapter->tx_pcb.data.memconf.progs = 0;
885 adapter->tx_pcb.length = sizeof(struct Memconf);
886 adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] = 0;
887 if (!send_pcb(dev, &adapter->tx_pcb))
888 printk("%s: couldn't send memory configuration command\n", dev->name);
889 else {
890 int timeout = jiffies + TIMEOUT;
891 while (adapter->got[CMD_CONFIGURE_ADAPTER_MEMORY] == 0 && jiffies < timeout)
892 ;
893 if (jiffies >= timeout)
894 TIMEOUT_MSG(__LINE__);
895 }
896
897
898
899
900
901 if (elp_debug >= 3)
902 printk("%s: sending 82586 configure command\n", dev->name);
903 adapter->tx_pcb.command = CMD_CONFIGURE_82586;
904 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD;
905 adapter->tx_pcb.length = 2;
906 adapter->got[CMD_CONFIGURE_82586] = 0;
907 if (!send_pcb(dev, &adapter->tx_pcb))
908 printk("%s: couldn't send 82586 configure command\n", dev->name);
909 else {
910 int timeout = jiffies + TIMEOUT;
911 while (adapter->got[CMD_CONFIGURE_82586] == 0 && jiffies < timeout)
912 ;
913 if (jiffies >= timeout)
914 TIMEOUT_MSG(__LINE__);
915 }
916
917
918
919
920 if (!start_receive(dev, &adapter->tx_pcb))
921 printk("%s: start receive command failed \n", dev->name);
922 if (elp_debug >= 3)
923 printk("%s: start receive command sent\n", dev->name);
924
925 #ifdef MODULE
926 MOD_INC_USE_COUNT;
927 #endif
928
929 return 0;
930 }
931
932
933
934
935
936
937
938
939 static int
940 send_packet (struct device * dev, unsigned char * ptr, int len)
941 {
942 int i;
943 int timeout = 0;
944 elp_device * adapter;
945
946
947
948
949 unsigned int nlen = (((len < 60) ? 60 : len) + 1) & (~1);
950
951 CHECK_NULL(dev);
952 CHECK_NULL(ptr);
953
954 adapter = dev->priv;
955
956 if (nlen < len)
957 printk("Warning, bad length nlen=%d len=%d %s(%d)\n",nlen,len,filename,__LINE__);
958
959
960
961
962
963 adapter->tx_pcb.command = CMD_TRANSMIT_PACKET;
964 adapter->tx_pcb.length = sizeof(struct Xmit_pkt);
965 adapter->tx_pcb.data.xmit_pkt.buf_ofs
966 = adapter->tx_pcb.data.xmit_pkt.buf_seg = 0;
967 adapter->tx_pcb.data.xmit_pkt.pkt_len = nlen;
968 if (!send_pcb(dev, &adapter->tx_pcb)) {
969 return FALSE;
970 }
971
972
973
974
975 cli();
976 for (i = 0; i < (nlen/2);i++) {
977 while (((inb_status(dev->base_addr)&HRDY) == 0)
978 && (timeout++ < 20000))
979 ;
980 if (timeout >= 20000) {
981 sti();
982 printk("%s: timeout at %s(%d) writing word %d of %d ***\n",
983 dev->name,filename,__LINE__, i, nlen/2);
984 return FALSE;
985 }
986
987 outw_data(*(short *)ptr, dev->base_addr);
988 ptr +=2;
989 }
990 sti();
991
992 return TRUE;
993 }
994
995
996
997
998
999
1000
1001
1002 static int
1003 elp_start_xmit (struct sk_buff *skb, struct device *dev)
1004 {
1005 CHECK_NULL(dev);
1006
1007
1008
1009
1010 if (skb == NULL) {
1011 dev_tint(dev);
1012 return 0;
1013 }
1014
1015
1016
1017
1018 if (skb->len <= 0)
1019 return 0;
1020
1021 if (elp_debug >= 3)
1022 printk("%s: request to send packet of length %d\n", dev->name, (int)skb->len);
1023
1024
1025
1026
1027 if (dev->tbusy) {
1028 int tickssofar = jiffies - dev->trans_start;
1029 int stat;
1030 if (tickssofar < 50)
1031 return 1;
1032 printk("%s: transmit timed out, not resetting adapter\n", dev->name);
1033 if (((stat=inb_status(dev->base_addr))&ACRF) != 0)
1034 printk("%s: hmmm...seemed to have missed an interrupt!\n", dev->name);
1035 printk("%s: status %#02x\n", dev->name, stat);
1036 dev->trans_start = jiffies;
1037 dev->tbusy = 0;
1038 }
1039
1040
1041
1042
1043 if (!send_packet(dev, skb->data, skb->len)) {
1044 printk("%s: send packet PCB failed\n", dev->name);
1045 return 1;
1046 }
1047
1048 if (elp_debug >= 3)
1049 printk("%s: packet of length %d sent\n", dev->name, (int)skb->len);
1050
1051
1052
1053
1054
1055 dev->trans_start = jiffies;
1056
1057
1058
1059
1060 dev->tbusy = 1;
1061
1062
1063
1064
1065 dev_kfree_skb(skb, FREE_WRITE);
1066
1067 return 0;
1068 }
1069
1070
1071
1072
1073
1074
1075
1076 static struct enet_statistics *
1077 elp_get_stats (struct device *dev)
1078 {
1079 elp_device *adapter = (elp_device *) dev->priv;
1080
1081 if (elp_debug >= 3)
1082 printk("%s: request for stats\n", dev->name);
1083
1084
1085
1086 if (!dev->start)
1087 return &adapter->stats;
1088
1089
1090 adapter->tx_pcb.command = CMD_NETWORK_STATISTICS;
1091 adapter->tx_pcb.length = 0;
1092 adapter->got[CMD_NETWORK_STATISTICS] = 0;
1093 if (!send_pcb(dev, &adapter->tx_pcb))
1094 printk("%s: couldn't send get statistics command\n", dev->name);
1095 else {
1096 int timeout = jiffies + TIMEOUT;
1097 while (adapter->got[CMD_NETWORK_STATISTICS] == 0 && jiffies < timeout)
1098 ;
1099 if (jiffies >= timeout) {
1100 TIMEOUT_MSG(__LINE__);
1101 return &adapter->stats;
1102 }
1103 }
1104
1105
1106 return &adapter->stats;
1107 }
1108
1109
1110
1111
1112
1113
1114
1115 static int
1116 elp_close (struct device *dev)
1117 {
1118 elp_device * adapter;
1119
1120 CHECK_NULL(dev);
1121 adapter = dev->priv;
1122 CHECK_NULL(adapter);
1123
1124 if (elp_debug >= 3)
1125 printk("%s: request to close device\n", dev->name);
1126
1127
1128
1129
1130
1131 (void) elp_get_stats(dev);
1132
1133
1134
1135
1136 outb_control(0x00, dev->base_addr);
1137
1138
1139
1140
1141 dev->tbusy = 1;
1142
1143
1144
1145
1146 dev->start = 0;
1147
1148
1149
1150
1151 free_irq(dev->irq);
1152
1153
1154
1155
1156 irq2dev_map[dev->irq] = 0;
1157
1158 #ifdef MODULE
1159 MOD_DEC_USE_COUNT;
1160 #endif
1161
1162 return 0;
1163 }
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175 static void
1176 elp_set_mc_list (struct device *dev, int num_addrs, void *addrs)
1177 {
1178 elp_device *adapter = (elp_device *) dev->priv;
1179 int i;
1180
1181 if (elp_debug >= 3)
1182 printk("%s: request to set multicast list\n", dev->name);
1183
1184 if (num_addrs != -1) {
1185
1186
1187 adapter->tx_pcb.command = CMD_LOAD_MULTICAST_LIST;
1188 adapter->tx_pcb.length = 6*num_addrs;
1189 for (i=0;i<num_addrs;i++)
1190 memcpy(adapter->tx_pcb.data.multicast[i], addrs+6*i,6);
1191 adapter->got[CMD_LOAD_MULTICAST_LIST] = 0;
1192 if (!send_pcb(dev, &adapter->tx_pcb))
1193 printk("%s: couldn't send set_multicast command\n", dev->name);
1194 else {
1195 int timeout = jiffies + TIMEOUT;
1196 while (adapter->got[CMD_LOAD_MULTICAST_LIST] == 0 && jiffies < timeout)
1197 ;
1198 if (jiffies >= timeout) {
1199 TIMEOUT_MSG(__LINE__);
1200 }
1201 }
1202 if (num_addrs)
1203 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD | RECV_MULTI;
1204 else
1205 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_BROAD;
1206 } else
1207 adapter->tx_pcb.data.configure = NO_LOOPBACK | RECV_PROMISC;
1208
1209
1210
1211
1212 if (elp_debug >= 3)
1213 printk("%s: sending 82586 configure command\n", dev->name);
1214 adapter->tx_pcb.command = CMD_CONFIGURE_82586;
1215 adapter->tx_pcb.length = 2;
1216 adapter->got[CMD_CONFIGURE_82586] = 0;
1217 if (!send_pcb(dev, &adapter->tx_pcb))
1218 printk("%s: couldn't send 82586 configure command\n", dev->name);
1219 else {
1220 int timeout = jiffies + TIMEOUT;
1221 while (adapter->got[CMD_CONFIGURE_82586] == 0 && jiffies < timeout)
1222 ;
1223 if (jiffies >= timeout)
1224 TIMEOUT_MSG(__LINE__);
1225 }
1226 }
1227
1228
1229
1230
1231
1232
1233
1234 static void
1235 elp_init (struct device *dev)
1236 {
1237 elp_device * adapter;
1238
1239 CHECK_NULL(dev);
1240
1241
1242
1243
1244 dev->open = elp_open;
1245 dev->stop = elp_close;
1246 dev->get_stats = elp_get_stats;
1247 dev->hard_start_xmit = elp_start_xmit;
1248 dev->set_multicast_list = elp_set_mc_list;
1249
1250
1251 ether_setup(dev);
1252
1253
1254
1255
1256 adapter = (elp_device *)(dev->priv = kmalloc(sizeof(elp_device), GFP_KERNEL));
1257 CHECK_NULL(adapter);
1258 memset(&(adapter->stats), 0, sizeof(struct enet_statistics));
1259
1260
1261
1262
1263 dev->mem_start = dev->mem_end = dev->rmem_end = dev->rmem_start = 0;
1264 }
1265
1266
1267
1268
1269
1270
1271
1272 static int
1273 elp_sense (struct device * dev)
1274 {
1275 int timeout;
1276 int addr=dev->base_addr;
1277 const char *name=dev->name;
1278
1279 byte orig_HCR=inb_control(addr),
1280 orig_HSR=inb_status(addr);
1281
1282 if (elp_debug > 0)
1283 printk(search_msg, name, addr);
1284
1285 if (((orig_HCR==0xff) && (orig_HSR==0xff)) ||
1286 ((orig_HCR & DIR) != (orig_HSR & DIR))) {
1287 if (elp_debug > 0)
1288 printk(notfound_msg, 1);
1289 return -1;
1290 }
1291
1292
1293 if (elp_debug > 0)
1294 printk(stilllooking_msg);
1295 for (timeout = jiffies + (100 * 15); jiffies <= timeout; )
1296 if (GET_ASF(addr) != ASF_PCB_END)
1297 break;
1298
1299 if (orig_HCR & DIR) {
1300
1301 outb_control(orig_HCR & ~DIR,addr);
1302 timeout = jiffies+30;
1303 while (jiffies < timeout)
1304 ;
1305 if (inb_status(addr) & DIR) {
1306 outb_control(orig_HCR,addr);
1307 if (elp_debug > 0)
1308 printk(notfound_msg, 2);
1309 return -1;
1310 }
1311 } else {
1312
1313 outb_control(orig_HCR | DIR,addr);
1314 timeout = jiffies+300;
1315 while (jiffies < timeout)
1316 ;
1317 if (!(inb_status(addr) & DIR)) {
1318 outb_control(orig_HCR,addr);
1319 if (elp_debug > 0)
1320 printk(notfound_msg, 3);
1321 return -1;
1322 }
1323 }
1324
1325
1326
1327
1328 if (elp_debug > 0)
1329 printk(found_msg);
1330
1331 if (((orig_HCR==0x35) && (orig_HSR==0x5b)) || ELP_NEED_HARD_RESET)
1332 adapter_hard_reset(dev);
1333 return 0;
1334 }
1335
1336
1337
1338
1339
1340
1341
1342 static int
1343 elp_autodetect (struct device * dev)
1344 {
1345 int idx=0;
1346
1347
1348
1349 if (dev->base_addr != 0) {
1350 if (elp_sense(dev) == 0)
1351 return dev->base_addr;
1352 } else while ( (dev->base_addr=addr_list[idx++]) ) {
1353 if (elp_sense(dev) == 0)
1354 return dev->base_addr;
1355 }
1356
1357
1358 if (elp_debug > 0)
1359 printk(couldnot_msg, dev->name);
1360
1361 return 0;
1362 }
1363
1364
1365
1366
1367
1368
1369
1370 int
1371 elplus_probe (struct device *dev)
1372 {
1373 elp_device adapter;
1374 int i;
1375
1376 CHECK_NULL(dev);
1377
1378
1379
1380
1381
1382 dev->base_addr = elp_autodetect(dev);
1383 if ( !(dev->base_addr) )
1384 return -ENODEV;
1385
1386
1387
1388
1389
1390 outb_control(inb_control(dev->base_addr) | CMDE, dev->base_addr);
1391 autoirq_setup(0);
1392
1393
1394
1395
1396
1397 adapter.tx_pcb.command = CMD_STATION_ADDRESS;
1398 adapter.tx_pcb.length = 0;
1399 if (!send_pcb (dev, &adapter.tx_pcb) ||
1400 !receive_pcb(dev, &adapter.rx_pcb) ||
1401 (adapter.rx_pcb.command != CMD_ADDRESS_RESPONSE) ||
1402 (adapter.rx_pcb.length != 6)) {
1403 printk("%s: not responding to first PCB\n", dev->name);
1404 return -ENODEV;
1405 }
1406
1407 if (dev->irq) {
1408 if (dev->irq != autoirq_report(0)) {
1409 printk("%s: Detected IRQ doesn't match user-defined one.\n",dev->name);
1410 return -ENODEV;
1411 }
1412
1413 } else
1414 dev->irq=autoirq_report(0);
1415 switch (dev->irq) {
1416 case 0:
1417 printk("%s: No IRQ reported by autoirq_report().\n",dev->name);
1418 printk("%s: Check the jumpers of your 3c505 board.\n",dev->name);
1419 return -ENODEV;
1420 case 1:
1421 case 6:
1422 case 8:
1423 case 13:
1424 printk("%s: Impossible IRQ %d reported by autoirq_report().\n",
1425 dev->name, dev->irq);
1426 return -ENODEV;
1427 }
1428
1429
1430
1431
1432 outb_control(inb_control(dev->base_addr) & ~CMDE, dev->base_addr);
1433
1434
1435
1436
1437 for (i = 0; i < 6; i++)
1438 dev->dev_addr[i] = adapter.rx_pcb.data.eth_addr[i];
1439
1440
1441
1442
1443 printk("%s: 3c505 card found at I/O %#lx using IRQ%d"
1444 " has address %02x:%02x:%02x:%02x:%02x:%02x\n",
1445 dev->name, dev->base_addr, dev->irq,
1446 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
1447 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
1448
1449
1450
1451
1452 request_region(dev->base_addr,16,"3c505");
1453
1454
1455
1456
1457 elp_init(dev);
1458 return 0;
1459 }
1460 #ifdef MODULE
1461 char kernel_version[] = UTS_RELEASE;
1462 static struct device dev_3c505 = {
1463 " " , 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, elplus_probe };
1464
1465 int io = 0x300;
1466 int irq = 0;
1467
1468 int init_module(void)
1469 {
1470 if (io == 0)
1471 printk("3c505: You should not use auto-probing with insmod!\n");
1472 dev_3c505.base_addr = io;
1473 dev_3c505.irq = irq;
1474 if (register_netdev(&dev_3c505) != 0) {
1475 printk("3c505: register_netdev() returned non-zero.\n");
1476 return -EIO;
1477 }
1478 return 0;
1479 }
1480
1481 void
1482 cleanup_module(void)
1483 {
1484 if (MOD_IN_USE)
1485 printk("3c505: device busy, remove delayed\n");
1486 else
1487 {
1488 unregister_netdev(&dev_3c505);
1489 }
1490 }
1491 #endif