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