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