1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57static const char version[] =
58 "smc9194.c:v0.14 12/15/00 by Erik Stahlman (erik@vt.edu)";
59
60#include <linux/module.h>
61#include <linux/kernel.h>
62#include <linux/types.h>
63#include <linux/fcntl.h>
64#include <linux/interrupt.h>
65#include <linux/ioport.h>
66#include <linux/in.h>
67#include <linux/string.h>
68#include <linux/init.h>
69#include <linux/crc32.h>
70#include <linux/errno.h>
71#include <linux/netdevice.h>
72#include <linux/etherdevice.h>
73#include <linux/skbuff.h>
74#include <linux/bitops.h>
75
76#include <asm/io.h>
77
78#include "smc9194.h"
79
80#define DRV_NAME "smc9194"
81
82
83
84
85
86
87
88
89
90
91
92#ifdef __sh__
93#undef USE_32_BIT
94#else
95#define USE_32_BIT 1
96#endif
97
98
99
100
101
102
103
104struct devlist {
105 unsigned int port;
106 unsigned int irq;
107};
108
109static struct devlist smc_devlist[] __initdata = {
110 {.port = 0x200, .irq = 0},
111 {.port = 0x220, .irq = 0},
112 {.port = 0x240, .irq = 0},
113 {.port = 0x260, .irq = 0},
114 {.port = 0x280, .irq = 0},
115 {.port = 0x2A0, .irq = 0},
116 {.port = 0x2C0, .irq = 0},
117 {.port = 0x2E0, .irq = 0},
118 {.port = 0x300, .irq = 0},
119 {.port = 0x320, .irq = 0},
120 {.port = 0x340, .irq = 0},
121 {.port = 0x360, .irq = 0},
122 {.port = 0x380, .irq = 0},
123 {.port = 0x3A0, .irq = 0},
124 {.port = 0x3C0, .irq = 0},
125 {.port = 0x3E0, .irq = 0},
126 {.port = 0, .irq = 0},
127};
128
129
130
131
132
133#define MEMORY_WAIT_TIME 16
134
135
136
137
138
139
140
141
142
143
144#define SMC_DEBUG 0
145
146#if (SMC_DEBUG > 2 )
147#define PRINTK3(x) printk x
148#else
149#define PRINTK3(x)
150#endif
151
152#if SMC_DEBUG > 1
153#define PRINTK2(x) printk x
154#else
155#define PRINTK2(x)
156#endif
157
158#ifdef SMC_DEBUG
159#define PRINTK(x) printk x
160#else
161#define PRINTK(x)
162#endif
163
164
165
166
167
168
169
170
171
172#define CARDNAME "SMC9194"
173
174
175
176struct smc_local {
177
178
179
180
181
182 struct sk_buff * saved_skb;
183
184
185
186
187
188
189 int packets_waiting;
190};
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208struct net_device *smc_init(int unit);
209
210
211
212
213
214static int smc_open(struct net_device *dev);
215
216
217
218
219static void smc_timeout(struct net_device *dev);
220
221
222
223
224
225
226static int smc_close(struct net_device *dev);
227
228
229
230
231
232static void smc_set_multicast_list(struct net_device *dev);
233
234
235
236
237
238
239
240
241
242
243
244static irqreturn_t smc_interrupt(int irq, void *);
245
246
247
248
249static inline void smc_rcv( struct net_device *dev );
250
251
252
253
254static inline void smc_tx( struct net_device * dev );
255
256
257
258
259
260
261
262
263
264
265
266
267
268static int smc_probe(struct net_device *dev, int ioaddr);
269
270
271
272
273#if SMC_DEBUG > 2
274static void print_packet( byte *, int );
275#endif
276
277#define tx_done(dev) 1
278
279
280static void smc_hardware_send_packet( struct net_device * dev );
281
282
283
284
285
286static netdev_tx_t smc_wait_to_send_packet( struct sk_buff * skb,
287 struct net_device *dev );
288
289
290static void smc_reset( int ioaddr );
291
292
293static void smc_enable( int ioaddr );
294
295
296static void smc_shutdown( int ioaddr );
297
298
299
300static int smc_findirq( int ioaddr );
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319static void smc_reset( int ioaddr )
320{
321
322
323 SMC_SELECT_BANK( 0 );
324 outw( RCR_SOFTRESET, ioaddr + RCR );
325
326
327 SMC_DELAY( );
328
329
330
331 outw( RCR_CLEAR, ioaddr + RCR );
332 outw( TCR_CLEAR, ioaddr + TCR );
333
334
335
336
337 SMC_SELECT_BANK( 1 );
338 outw( inw( ioaddr + CONTROL ) | CTL_AUTO_RELEASE , ioaddr + CONTROL );
339
340
341 SMC_SELECT_BANK( 2 );
342 outw( MC_RESET, ioaddr + MMU_CMD );
343
344
345
346
347
348 outb( 0, ioaddr + INT_MASK );
349}
350
351
352
353
354
355
356
357
358
359static void smc_enable( int ioaddr )
360{
361 SMC_SELECT_BANK( 0 );
362
363 outw( TCR_NORMAL, ioaddr + TCR );
364 outw( RCR_NORMAL, ioaddr + RCR );
365
366
367 SMC_SELECT_BANK( 2 );
368 outb( SMC_INTERRUPT_MASK, ioaddr + INT_MASK );
369}
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385static void smc_shutdown( int ioaddr )
386{
387
388 SMC_SELECT_BANK( 2 );
389 outb( 0, ioaddr + INT_MASK );
390
391
392 SMC_SELECT_BANK( 0 );
393 outb( RCR_CLEAR, ioaddr + RCR );
394 outb( TCR_CLEAR, ioaddr + TCR );
395#if 0
396
397 SMC_SELECT_BANK( 1 );
398 outw( inw( ioaddr + CONTROL ), CTL_POWERDOWN, ioaddr + CONTROL );
399#endif
400}
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421static void smc_setmulticast(int ioaddr, struct net_device *dev)
422{
423 int i;
424 unsigned char multicast_table[ 8 ];
425 struct netdev_hw_addr *ha;
426
427 unsigned char invert3[] = { 0, 4, 2, 6, 1, 5, 3, 7 };
428
429
430 memset( multicast_table, 0, sizeof( multicast_table ) );
431
432 netdev_for_each_mc_addr(ha, dev) {
433 int position;
434
435
436 position = ether_crc_le(6, ha->addr) & 0x3f;
437
438
439 multicast_table[invert3[position&7]] |=
440 (1<<invert3[(position>>3)&7]);
441
442 }
443
444 SMC_SELECT_BANK( 3 );
445
446 for ( i = 0; i < 8 ; i++ ) {
447 outb( multicast_table[i], ioaddr + MULTICAST1 + i );
448 }
449}
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467static netdev_tx_t smc_wait_to_send_packet(struct sk_buff *skb,
468 struct net_device *dev)
469{
470 struct smc_local *lp = netdev_priv(dev);
471 unsigned int ioaddr = dev->base_addr;
472 word length;
473 unsigned short numPages;
474 word time_out;
475
476 netif_stop_queue(dev);
477
478
479
480 if ( lp->saved_skb) {
481
482 dev->stats.tx_aborted_errors++;
483 printk(CARDNAME": Bad Craziness - sent packet while busy.\n" );
484 return NETDEV_TX_BUSY;
485 }
486 lp->saved_skb = skb;
487
488 length = skb->len;
489
490 if (length < ETH_ZLEN) {
491 if (skb_padto(skb, ETH_ZLEN)) {
492 netif_wake_queue(dev);
493 return NETDEV_TX_OK;
494 }
495 length = ETH_ZLEN;
496 }
497
498
499
500
501
502
503
504
505 numPages = ((length & 0xfffe) + 6) / 256;
506
507 if (numPages > 7 ) {
508 printk(CARDNAME": Far too big packet error.\n");
509
510
511 dev_kfree_skb (skb);
512 lp->saved_skb = NULL;
513
514 netif_wake_queue(dev);
515 return NETDEV_TX_OK;
516 }
517
518 lp->packets_waiting++;
519
520
521 SMC_SELECT_BANK( 2 );
522 outw( MC_ALLOC | numPages, ioaddr + MMU_CMD );
523
524
525
526
527
528
529
530
531
532
533
534
535 time_out = MEMORY_WAIT_TIME;
536 do {
537 word status;
538
539 status = inb( ioaddr + INTERRUPT );
540 if ( status & IM_ALLOC_INT ) {
541
542 outb( IM_ALLOC_INT, ioaddr + INTERRUPT );
543 break;
544 }
545 } while ( -- time_out );
546
547 if ( !time_out ) {
548
549 SMC_ENABLE_INT( IM_ALLOC_INT );
550 PRINTK2((CARDNAME": memory allocation deferred.\n"));
551
552 return NETDEV_TX_OK;
553 }
554
555 smc_hardware_send_packet(dev);
556 netif_wake_queue(dev);
557 return NETDEV_TX_OK;
558}
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578static void smc_hardware_send_packet( struct net_device * dev )
579{
580 struct smc_local *lp = netdev_priv(dev);
581 byte packet_no;
582 struct sk_buff * skb = lp->saved_skb;
583 word length;
584 unsigned int ioaddr;
585 byte * buf;
586
587 ioaddr = dev->base_addr;
588
589 if ( !skb ) {
590 PRINTK((CARDNAME": In XMIT with no packet to send\n"));
591 return;
592 }
593 length = ETH_ZLEN < skb->len ? skb->len : ETH_ZLEN;
594 buf = skb->data;
595
596
597 packet_no = inb( ioaddr + PNR_ARR + 1 );
598 if ( packet_no & 0x80 ) {
599
600 netdev_dbg(dev, CARDNAME": Memory allocation failed.\n");
601 dev_kfree_skb_any(skb);
602 lp->saved_skb = NULL;
603 netif_wake_queue(dev);
604 return;
605 }
606
607
608 outb( packet_no, ioaddr + PNR_ARR );
609
610
611 outw( PTR_AUTOINC , ioaddr + POINTER );
612
613 PRINTK3((CARDNAME": Trying to xmit packet of length %x\n", length));
614#if SMC_DEBUG > 2
615 print_packet( buf, length );
616#endif
617
618
619
620#ifdef USE_32_BIT
621 outl( (length +6 ) << 16 , ioaddr + DATA_1 );
622#else
623 outw( 0, ioaddr + DATA_1 );
624
625 outb( (length+6) & 0xFF,ioaddr + DATA_1 );
626 outb( (length+6) >> 8 , ioaddr + DATA_1 );
627#endif
628
629
630
631
632
633
634
635
636#ifdef USE_32_BIT
637 if ( length & 0x2 ) {
638 outsl(ioaddr + DATA_1, buf, length >> 2 );
639 outw( *((word *)(buf + (length & 0xFFFFFFFC))),ioaddr +DATA_1);
640 }
641 else
642 outsl(ioaddr + DATA_1, buf, length >> 2 );
643#else
644 outsw(ioaddr + DATA_1 , buf, (length ) >> 1);
645#endif
646
647
648 if ( (length & 1) == 0 ) {
649 outw( 0, ioaddr + DATA_1 );
650 } else {
651 outb( buf[length -1 ], ioaddr + DATA_1 );
652 outb( 0x20, ioaddr + DATA_1);
653 }
654
655
656 SMC_ENABLE_INT( (IM_TX_INT | IM_TX_EMPTY_INT) );
657
658
659 outw( MC_ENQUEUE , ioaddr + MMU_CMD );
660
661 PRINTK2((CARDNAME": Sent packet of length %d\n", length));
662
663 lp->saved_skb = NULL;
664 dev_kfree_skb_any (skb);
665
666 dev->trans_start = jiffies;
667
668
669 netif_wake_queue(dev);
670}
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686static int io;
687static int irq;
688static int ifport;
689
690struct net_device * __init smc_init(int unit)
691{
692 struct net_device *dev = alloc_etherdev(sizeof(struct smc_local));
693 struct devlist *smcdev = smc_devlist;
694 int err = 0;
695
696 if (!dev)
697 return ERR_PTR(-ENODEV);
698
699 if (unit >= 0) {
700 sprintf(dev->name, "eth%d", unit);
701 netdev_boot_setup_check(dev);
702 io = dev->base_addr;
703 irq = dev->irq;
704 }
705
706 if (io > 0x1ff) {
707 err = smc_probe(dev, io);
708 } else if (io != 0) {
709 err = -ENXIO;
710 } else {
711 for (;smcdev->port; smcdev++) {
712 if (smc_probe(dev, smcdev->port) == 0)
713 break;
714 }
715 if (!smcdev->port)
716 err = -ENODEV;
717 }
718 if (err)
719 goto out;
720 err = register_netdev(dev);
721 if (err)
722 goto out1;
723 return dev;
724out1:
725 free_irq(dev->irq, dev);
726 release_region(dev->base_addr, SMC_IO_EXTENT);
727out:
728 free_netdev(dev);
729 return ERR_PTR(err);
730}
731
732
733
734
735
736
737
738
739static int __init smc_findirq(int ioaddr)
740{
741#ifndef NO_AUTOPROBE
742 int timeout = 20;
743 unsigned long cookie;
744
745
746 cookie = probe_irq_on();
747
748
749
750
751
752
753
754
755 SMC_SELECT_BANK(2);
756
757 outb( IM_ALLOC_INT, ioaddr + INT_MASK );
758
759
760
761
762
763 outw( MC_ALLOC | 1, ioaddr + MMU_CMD );
764
765
766
767
768 while ( timeout ) {
769 byte int_status;
770
771 int_status = inb( ioaddr + INTERRUPT );
772
773 if ( int_status & IM_ALLOC_INT )
774 break;
775 timeout--;
776 }
777
778
779
780
781
782
783
784
785
786
787
788 SMC_DELAY();
789 SMC_DELAY();
790
791
792 outb( 0, ioaddr + INT_MASK );
793
794
795 return probe_irq_off(cookie);
796#else
797 struct devlist *smcdev;
798 for (smcdev = smc_devlist; smcdev->port; smcdev++) {
799 if (smcdev->port == ioaddr)
800 return smcdev->irq;
801 }
802 return 0;
803#endif
804}
805
806static const struct net_device_ops smc_netdev_ops = {
807 .ndo_open = smc_open,
808 .ndo_stop = smc_close,
809 .ndo_start_xmit = smc_wait_to_send_packet,
810 .ndo_tx_timeout = smc_timeout,
811 .ndo_set_rx_mode = smc_set_multicast_list,
812 .ndo_change_mtu = eth_change_mtu,
813 .ndo_set_mac_address = eth_mac_addr,
814 .ndo_validate_addr = eth_validate_addr,
815};
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846static int __init smc_probe(struct net_device *dev, int ioaddr)
847{
848 int i, memory, retval;
849 unsigned int bank;
850
851 const char *version_string;
852 const char *if_string;
853
854
855 word revision_register;
856 word base_address_register;
857 word configuration_register;
858 word memory_info_register;
859 word memory_cfg_register;
860
861
862 if (!request_region(ioaddr, SMC_IO_EXTENT, DRV_NAME))
863 return -EBUSY;
864
865 dev->irq = irq;
866 dev->if_port = ifport;
867
868
869 bank = inw( ioaddr + BANK_SELECT );
870 if ( (bank & 0xFF00) != 0x3300 ) {
871 retval = -ENODEV;
872 goto err_out;
873 }
874
875
876 outw( 0x0, ioaddr + BANK_SELECT );
877 bank = inw( ioaddr + BANK_SELECT );
878 if ( (bank & 0xFF00 ) != 0x3300 ) {
879 retval = -ENODEV;
880 goto err_out;
881 }
882
883
884
885 SMC_SELECT_BANK(1);
886 base_address_register = inw( ioaddr + BASE );
887 if ( ioaddr != ( base_address_register >> 3 & 0x3E0 ) ) {
888 printk(CARDNAME ": IOADDR %x doesn't match configuration (%x). "
889 "Probably not a SMC chip\n",
890 ioaddr, base_address_register >> 3 & 0x3E0 );
891
892
893 retval = -ENODEV;
894 goto err_out;
895 }
896
897
898
899
900 SMC_SELECT_BANK(3);
901 revision_register = inw( ioaddr + REVISION );
902 if ( !chip_ids[ ( revision_register >> 4 ) & 0xF ] ) {
903
904 printk(CARDNAME ": IO %x: Unrecognized revision register:"
905 " %x, Contact author.\n", ioaddr, revision_register);
906
907 retval = -ENODEV;
908 goto err_out;
909 }
910
911
912
913
914
915 pr_info_once("%s\n", version);
916
917
918 dev->base_addr = ioaddr;
919
920
921
922
923 SMC_SELECT_BANK( 1 );
924 for ( i = 0; i < 6; i += 2 ) {
925 word address;
926
927 address = inw( ioaddr + ADDR0 + i );
928 dev->dev_addr[ i + 1] = address >> 8;
929 dev->dev_addr[ i ] = address & 0xFF;
930 }
931
932
933
934 SMC_SELECT_BANK( 0 );
935 memory_info_register = inw( ioaddr + MIR );
936 memory_cfg_register = inw( ioaddr + MCR );
937 memory = ( memory_cfg_register >> 9 ) & 0x7;
938 memory *= 256 * ( memory_info_register & 0xFF );
939
940
941
942
943
944
945 SMC_SELECT_BANK(3);
946 revision_register = inw( ioaddr + REVISION );
947 version_string = chip_ids[ ( revision_register >> 4 ) & 0xF ];
948 if ( !version_string ) {
949
950 retval = -ENODEV;
951 goto err_out;
952 }
953
954
955 if ( dev->if_port == 0 ) {
956 SMC_SELECT_BANK(1);
957 configuration_register = inw( ioaddr + CONFIG );
958 if ( configuration_register & CFG_AUI_SELECT )
959 dev->if_port = 2;
960 else
961 dev->if_port = 1;
962 }
963 if_string = interfaces[ dev->if_port - 1 ];
964
965
966 smc_reset( ioaddr );
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984 if ( dev->irq < 2 ) {
985 int trials;
986
987 trials = 3;
988 while ( trials-- ) {
989 dev->irq = smc_findirq( ioaddr );
990 if ( dev->irq )
991 break;
992
993 smc_reset( ioaddr );
994 }
995 }
996 if (dev->irq == 0 ) {
997 printk(CARDNAME": Couldn't autodetect your IRQ. Use irq=xx.\n");
998 retval = -ENODEV;
999 goto err_out;
1000 }
1001
1002
1003
1004 netdev_info(dev, "%s(r:%d) at %#3x IRQ:%d INTF:%s MEM:%db ",
1005 version_string, revision_register & 0xF, ioaddr, dev->irq,
1006 if_string, memory);
1007
1008
1009
1010 netdev_info(dev, "ADDR: %pM\n", dev->dev_addr);
1011
1012
1013 retval = request_irq(dev->irq, smc_interrupt, 0, DRV_NAME, dev);
1014 if (retval) {
1015 netdev_warn(dev, "%s: unable to get IRQ %d (irqval=%d).\n",
1016 DRV_NAME, dev->irq, retval);
1017 goto err_out;
1018 }
1019
1020 dev->netdev_ops = &smc_netdev_ops;
1021 dev->watchdog_timeo = HZ/20;
1022
1023 return 0;
1024
1025err_out:
1026 release_region(ioaddr, SMC_IO_EXTENT);
1027 return retval;
1028}
1029
1030#if SMC_DEBUG > 2
1031static void print_packet( byte * buf, int length )
1032{
1033#if 0
1034 print_hex_dump_debug(DRV_NAME, DUMP_PREFIX_OFFSET, 16, 1,
1035 buf, length, true);
1036#endif
1037}
1038#endif
1039
1040
1041
1042
1043
1044
1045
1046
1047static int smc_open(struct net_device *dev)
1048{
1049 int ioaddr = dev->base_addr;
1050
1051 int i;
1052
1053
1054 memset(netdev_priv(dev), 0, sizeof(struct smc_local));
1055
1056
1057
1058 smc_reset( ioaddr );
1059 smc_enable( ioaddr );
1060
1061
1062
1063 SMC_SELECT_BANK( 1 );
1064 if ( dev->if_port == 1 ) {
1065 outw( inw( ioaddr + CONFIG ) & ~CFG_AUI_SELECT,
1066 ioaddr + CONFIG );
1067 }
1068 else if ( dev->if_port == 2 ) {
1069 outw( inw( ioaddr + CONFIG ) | CFG_AUI_SELECT,
1070 ioaddr + CONFIG );
1071 }
1072
1073
1074
1075
1076
1077
1078 SMC_SELECT_BANK( 1 );
1079 for ( i = 0; i < 6; i += 2 ) {
1080 word address;
1081
1082 address = dev->dev_addr[ i + 1 ] << 8 ;
1083 address |= dev->dev_addr[ i ];
1084 outw( address, ioaddr + ADDR0 + i );
1085 }
1086
1087 netif_start_queue(dev);
1088 return 0;
1089}
1090
1091
1092
1093
1094
1095
1096
1097
1098static void smc_timeout(struct net_device *dev)
1099{
1100
1101
1102 netdev_warn(dev, CARDNAME": transmit timed out, %s?\n",
1103 tx_done(dev) ? "IRQ conflict" : "network cable problem");
1104
1105 smc_reset( dev->base_addr );
1106 smc_enable( dev->base_addr );
1107 dev->trans_start = jiffies;
1108
1109 ((struct smc_local *)netdev_priv(dev))->saved_skb = NULL;
1110 netif_wake_queue(dev);
1111}
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125static void smc_rcv(struct net_device *dev)
1126{
1127 int ioaddr = dev->base_addr;
1128 int packet_number;
1129 word status;
1130 word packet_length;
1131
1132
1133
1134 packet_number = inw( ioaddr + FIFO_PORTS );
1135
1136 if ( packet_number & FP_RXEMPTY ) {
1137
1138 PRINTK((CARDNAME ": WARNING: smc_rcv with nothing on FIFO.\n"));
1139
1140 return;
1141 }
1142
1143
1144 outw( PTR_READ | PTR_RCV | PTR_AUTOINC, ioaddr + POINTER );
1145
1146
1147 status = inw( ioaddr + DATA_1 );
1148 packet_length = inw( ioaddr + DATA_1 );
1149
1150 packet_length &= 0x07ff;
1151
1152 PRINTK2(("RCV: STATUS %4x LENGTH %4x\n", status, packet_length ));
1153
1154
1155
1156
1157 packet_length -= 6;
1158
1159 if ( !(status & RS_ERRORS ) ){
1160
1161 struct sk_buff * skb;
1162 byte * data;
1163
1164
1165 if ( status & RS_ODDFRAME )
1166 packet_length++;
1167
1168
1169 if ( status & RS_MULTICAST )
1170 dev->stats.multicast++;
1171
1172 skb = netdev_alloc_skb(dev, packet_length + 5);
1173 if ( skb == NULL ) {
1174 dev->stats.rx_dropped++;
1175 goto done;
1176 }
1177
1178
1179
1180
1181
1182
1183 skb_reserve( skb, 2 );
1184
1185 data = skb_put( skb, packet_length);
1186
1187#ifdef USE_32_BIT
1188
1189
1190
1191
1192 PRINTK3((" Reading %d dwords (and %d bytes)\n",
1193 packet_length >> 2, packet_length & 3 ));
1194 insl(ioaddr + DATA_1 , data, packet_length >> 2 );
1195
1196 insb( ioaddr + DATA_1, data + (packet_length & 0xFFFFFC),
1197 packet_length & 0x3 );
1198#else
1199 PRINTK3((" Reading %d words and %d byte(s)\n",
1200 (packet_length >> 1 ), packet_length & 1 ));
1201 insw(ioaddr + DATA_1 , data, packet_length >> 1);
1202 if ( packet_length & 1 ) {
1203 data += packet_length & ~1;
1204 *(data++) = inb( ioaddr + DATA_1 );
1205 }
1206#endif
1207#if SMC_DEBUG > 2
1208 print_packet( data, packet_length );
1209#endif
1210
1211 skb->protocol = eth_type_trans(skb, dev );
1212 netif_rx(skb);
1213 dev->stats.rx_packets++;
1214 dev->stats.rx_bytes += packet_length;
1215 } else {
1216
1217 dev->stats.rx_errors++;
1218
1219 if ( status & RS_ALGNERR ) dev->stats.rx_frame_errors++;
1220 if ( status & (RS_TOOSHORT | RS_TOOLONG ) )
1221 dev->stats.rx_length_errors++;
1222 if ( status & RS_BADCRC) dev->stats.rx_crc_errors++;
1223 }
1224
1225done:
1226
1227 outw( MC_RELEASE, ioaddr + MMU_CMD );
1228}
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246static void smc_tx( struct net_device * dev )
1247{
1248 int ioaddr = dev->base_addr;
1249 struct smc_local *lp = netdev_priv(dev);
1250 byte saved_packet;
1251 byte packet_no;
1252 word tx_status;
1253
1254
1255
1256
1257 saved_packet = inb( ioaddr + PNR_ARR );
1258 packet_no = inw( ioaddr + FIFO_PORTS );
1259 packet_no &= 0x7F;
1260
1261
1262 outb( packet_no, ioaddr + PNR_ARR );
1263
1264
1265 outw( PTR_AUTOINC | PTR_READ, ioaddr + POINTER );
1266
1267 tx_status = inw( ioaddr + DATA_1 );
1268 PRINTK3((CARDNAME": TX DONE STATUS: %4x\n", tx_status));
1269
1270 dev->stats.tx_errors++;
1271 if ( tx_status & TS_LOSTCAR ) dev->stats.tx_carrier_errors++;
1272 if ( tx_status & TS_LATCOL ) {
1273 netdev_dbg(dev, CARDNAME": Late collision occurred on last xmit.\n");
1274 dev->stats.tx_window_errors++;
1275 }
1276#if 0
1277 if ( tx_status & TS_16COL ) { ... }
1278#endif
1279
1280 if ( tx_status & TS_SUCCESS ) {
1281 netdev_info(dev, CARDNAME": Successful packet caused interrupt\n");
1282 }
1283
1284 SMC_SELECT_BANK( 0 );
1285 outw( inw( ioaddr + TCR ) | TCR_ENABLE, ioaddr + TCR );
1286
1287
1288 SMC_SELECT_BANK( 2 );
1289 outw( MC_FREEPKT, ioaddr + MMU_CMD );
1290
1291
1292 lp->packets_waiting--;
1293
1294 outb( saved_packet, ioaddr + PNR_ARR );
1295}
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310static irqreturn_t smc_interrupt(int irq, void * dev_id)
1311{
1312 struct net_device *dev = dev_id;
1313 int ioaddr = dev->base_addr;
1314 struct smc_local *lp = netdev_priv(dev);
1315
1316 byte status;
1317 word card_stats;
1318 byte mask;
1319 int timeout;
1320
1321 word saved_bank;
1322 word saved_pointer;
1323 int handled = 0;
1324
1325
1326 PRINTK3((CARDNAME": SMC interrupt started\n"));
1327
1328 saved_bank = inw( ioaddr + BANK_SELECT );
1329
1330 SMC_SELECT_BANK(2);
1331 saved_pointer = inw( ioaddr + POINTER );
1332
1333 mask = inb( ioaddr + INT_MASK );
1334
1335 outb( 0, ioaddr + INT_MASK );
1336
1337
1338
1339 timeout = 4;
1340
1341 PRINTK2((KERN_WARNING CARDNAME ": MASK IS %x\n", mask));
1342 do {
1343
1344 status = inb( ioaddr + INTERRUPT ) & mask;
1345 if (!status )
1346 break;
1347
1348 handled = 1;
1349
1350 PRINTK3((KERN_WARNING CARDNAME
1351 ": Handling interrupt status %x\n", status));
1352
1353 if (status & IM_RCV_INT) {
1354
1355 PRINTK2((KERN_WARNING CARDNAME
1356 ": Receive Interrupt\n"));
1357 smc_rcv(dev);
1358 } else if (status & IM_TX_INT ) {
1359 PRINTK2((KERN_WARNING CARDNAME
1360 ": TX ERROR handled\n"));
1361 smc_tx(dev);
1362 outb(IM_TX_INT, ioaddr + INTERRUPT );
1363 } else if (status & IM_TX_EMPTY_INT ) {
1364
1365 SMC_SELECT_BANK( 0 );
1366 card_stats = inw( ioaddr + COUNTER );
1367
1368 dev->stats.collisions += card_stats & 0xF;
1369 card_stats >>= 4;
1370
1371 dev->stats.collisions += card_stats & 0xF;
1372
1373
1374
1375 SMC_SELECT_BANK( 2 );
1376 PRINTK2((KERN_WARNING CARDNAME
1377 ": TX_BUFFER_EMPTY handled\n"));
1378 outb( IM_TX_EMPTY_INT, ioaddr + INTERRUPT );
1379 mask &= ~IM_TX_EMPTY_INT;
1380 dev->stats.tx_packets += lp->packets_waiting;
1381 lp->packets_waiting = 0;
1382
1383 } else if (status & IM_ALLOC_INT ) {
1384 PRINTK2((KERN_DEBUG CARDNAME
1385 ": Allocation interrupt\n"));
1386
1387 mask &= ~IM_ALLOC_INT;
1388
1389 smc_hardware_send_packet( dev );
1390
1391
1392 mask |= ( IM_TX_EMPTY_INT | IM_TX_INT );
1393
1394
1395 netif_wake_queue(dev);
1396
1397 PRINTK2((CARDNAME": Handoff done successfully.\n"));
1398 } else if (status & IM_RX_OVRN_INT ) {
1399 dev->stats.rx_errors++;
1400 dev->stats.rx_fifo_errors++;
1401 outb( IM_RX_OVRN_INT, ioaddr + INTERRUPT );
1402 } else if (status & IM_EPH_INT ) {
1403 PRINTK((CARDNAME ": UNSUPPORTED: EPH INTERRUPT\n"));
1404 } else if (status & IM_ERCV_INT ) {
1405 PRINTK((CARDNAME ": UNSUPPORTED: ERCV INTERRUPT\n"));
1406 outb( IM_ERCV_INT, ioaddr + INTERRUPT );
1407 }
1408 } while ( timeout -- );
1409
1410
1411
1412 SMC_SELECT_BANK( 2 );
1413 outb( mask, ioaddr + INT_MASK );
1414
1415 PRINTK3((KERN_WARNING CARDNAME ": MASK is now %x\n", mask));
1416 outw( saved_pointer, ioaddr + POINTER );
1417
1418 SMC_SELECT_BANK( saved_bank );
1419
1420 PRINTK3((CARDNAME ": Interrupt done\n"));
1421 return IRQ_RETVAL(handled);
1422}
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433static int smc_close(struct net_device *dev)
1434{
1435 netif_stop_queue(dev);
1436
1437 smc_shutdown( dev->base_addr );
1438
1439
1440 return 0;
1441}
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451static void smc_set_multicast_list(struct net_device *dev)
1452{
1453 short ioaddr = dev->base_addr;
1454
1455 SMC_SELECT_BANK(0);
1456 if ( dev->flags & IFF_PROMISC )
1457 outw( inw(ioaddr + RCR ) | RCR_PROMISC, ioaddr + RCR );
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468 else if (dev->flags & IFF_ALLMULTI)
1469 outw( inw(ioaddr + RCR ) | RCR_ALMUL, ioaddr + RCR );
1470
1471
1472
1473
1474 else if (!netdev_mc_empty(dev)) {
1475
1476
1477
1478 outw( inw( ioaddr + RCR ) & ~(RCR_PROMISC | RCR_ALMUL),
1479 ioaddr + RCR );
1480
1481
1482 smc_setmulticast(ioaddr, dev);
1483 }
1484 else {
1485 outw( inw( ioaddr + RCR ) & ~(RCR_PROMISC | RCR_ALMUL),
1486 ioaddr + RCR );
1487
1488
1489
1490
1491
1492 SMC_SELECT_BANK( 3 );
1493 outw( 0, ioaddr + MULTICAST1 );
1494 outw( 0, ioaddr + MULTICAST2 );
1495 outw( 0, ioaddr + MULTICAST3 );
1496 outw( 0, ioaddr + MULTICAST4 );
1497 }
1498}
1499
1500#ifdef MODULE
1501
1502static struct net_device *devSMC9194;
1503MODULE_LICENSE("GPL");
1504
1505module_param(io, int, 0);
1506module_param(irq, int, 0);
1507module_param(ifport, int, 0);
1508MODULE_PARM_DESC(io, "SMC 99194 I/O base address");
1509MODULE_PARM_DESC(irq, "SMC 99194 IRQ number");
1510MODULE_PARM_DESC(ifport, "SMC 99194 interface port (0-default, 1-TP, 2-AUI)");
1511
1512int __init init_module(void)
1513{
1514 if (io == 0)
1515 printk(KERN_WARNING
1516 CARDNAME": You shouldn't use auto-probing with insmod!\n" );
1517
1518
1519 devSMC9194 = smc_init(-1);
1520 return PTR_ERR_OR_ZERO(devSMC9194);
1521}
1522
1523void __exit cleanup_module(void)
1524{
1525 unregister_netdev(devSMC9194);
1526 free_irq(devSMC9194->irq, devSMC9194);
1527 release_region(devSMC9194->base_addr, SMC_IO_EXTENT);
1528 free_netdev(devSMC9194);
1529}
1530
1531#endif
1532