60 #include <linux/module.h>
61 #include <linux/kernel.h>
62 #include <linux/types.h>
63 #include <linux/fcntl.h>
67 #include <linux/string.h>
70 #include <linux/errno.h>
71 #include <linux/netdevice.h>
74 #include <linux/bitops.h>
80 #define DRV_NAME "smc9194"
98 #if defined(__H8300H__) || defined(__H8300S__)
102 #define insl(a,b,l) io_insl_noswap(a,b,l)
103 #define outsl(a,b,l) io_outsl_noswap(a,b,l)
117 #if defined(CONFIG_H8S_EDOSK2674)
119 {.port = 0xf80000, .irq = 16},
120 {.port = 0, .irq = 0 },
123 static struct devlist smc_devlist[] __initdata = {
124 {.
port = 0x200, .irq = 0},
125 {.port = 0x220, .irq = 0},
126 {.port = 0x240, .irq = 0},
127 {.port = 0x260, .irq = 0},
128 {.port = 0x280, .irq = 0},
129 {.port = 0x2A0, .irq = 0},
130 {.port = 0x2C0, .irq = 0},
131 {.port = 0x2E0, .irq = 0},
132 {.port = 0x300, .irq = 0},
133 {.port = 0x320, .irq = 0},
134 {.port = 0x340, .irq = 0},
135 {.port = 0x360, .irq = 0},
136 {.port = 0x380, .irq = 0},
137 {.port = 0x3A0, .irq = 0},
138 {.port = 0x3C0, .irq = 0},
139 {.port = 0x3E0, .irq = 0},
140 {.port = 0, .irq = 0},
148 #define MEMORY_WAIT_TIME 16
162 #define PRINTK3(x) printk x
168 #define PRINTK2(x) printk x
174 #define PRINTK(x) printk x
187 #define CARDNAME "SMC9194"
289 static void print_packet(
byte *,
int );
292 #define tx_done(dev) 1
295 static void smc_hardware_send_packet(
struct net_device *
dev );
305 static void smc_reset(
int ioaddr );
308 static void smc_enable(
int ioaddr );
311 static void smc_shutdown(
int ioaddr );
315 static int smc_findirq(
int ioaddr );
334 static void smc_reset(
int ioaddr )
374 static void smc_enable(
int ioaddr )
400 static void smc_shutdown(
int ioaddr )
436 static void smc_setmulticast(
int ioaddr,
struct net_device *
dev)
439 unsigned char multicast_table[ 8 ];
442 unsigned char invert3[] = { 0, 4, 2, 6, 1, 5, 3, 7 };
445 memset( multicast_table, 0,
sizeof( multicast_table ) );
454 multicast_table[invert3[position&7]] |=
455 (1<<invert3[(position>>3)&7]);
461 for ( i = 0; i < 8 ; i++ ) {
488 unsigned short numPages;
491 netif_stop_queue(dev);
497 dev->
stats.tx_aborted_errors++;
507 netif_wake_queue(dev);
520 numPages = ((length & 0xfffe) + 6) / 256;
529 netif_wake_queue(dev);
560 }
while ( -- time_out );
570 smc_hardware_send_packet(dev);
571 netif_wake_queue(dev);
593 static void smc_hardware_send_packet(
struct net_device * dev )
613 if ( packet_no & 0x80 ) {
618 netif_wake_queue(dev);
630 print_packet( buf, length );
652 if ( length & 0x2 ) {
654 #if !defined(__H8300H__) && !defined(__H8300S__)
657 ctrl_outw( *((
word *)(buf + (length & 0xFFFFFFFC))),ioaddr +
DATA_1);
667 if ( (length & 1) == 0 ) {
688 netif_wake_queue(dev);
712 struct devlist *smcdev = smc_devlist;
726 err = smc_probe(dev, io);
727 }
else if (io != 0) {
730 for (;smcdev->
port; smcdev++) {
731 if (smc_probe(dev, smcdev->
port) == 0)
758 static int __init smc_findirq(
int ioaddr)
817 for (smcdev = smc_devlist; smcdev->
port; smcdev++) {
818 if (smcdev->
port == ioaddr)
826 .ndo_open = smc_open,
827 .ndo_stop = smc_close,
828 .ndo_start_xmit = smc_wait_to_send_packet,
829 .ndo_tx_timeout = smc_timeout,
830 .ndo_set_rx_mode = smc_set_multicast_list,
868 static unsigned version_printed;
872 const char *if_string;
875 word revision_register;
876 word base_address_register;
877 word configuration_register;
878 word memory_info_register;
879 word memory_cfg_register;
890 if ( (bank & 0xFF00) != 0x3300 ) {
898 if ( (bank & 0xFF00 ) != 0x3300 ) {
902 #if !defined(CONFIG_H8S_EDOSK2674)
907 base_address_register =
inw( ioaddr +
BASE );
908 if ( ioaddr != ( base_address_register >> 3 & 0x3E0 ) ) {
910 "Probably not a SMC chip\n",
911 ioaddr, base_address_register >> 3 & 0x3E0 );
918 (
void)base_address_register;
927 if ( !chip_ids[ ( revision_register >> 4 ) & 0xF ] ) {
930 " %x, Contact author.\n", ioaddr, revision_register);
940 if (version_printed++ == 0)
950 for ( i = 0; i < 6; i += 2 ) {
953 address =
inw( ioaddr +
ADDR0 + i );
954 dev->
dev_addr[ i + 1] = address >> 8;
961 memory_info_register =
inw( ioaddr +
MIR );
962 memory_cfg_register =
inw( ioaddr +
MCR );
963 memory = ( memory_cfg_register >> 9 ) & 0x7;
964 memory *= 256 * ( memory_info_register & 0xFF );
973 version_string = chip_ids[ ( revision_register >> 4 ) & 0xF ];
974 if ( !version_string ) {
983 configuration_register =
inw( ioaddr +
CONFIG );
989 if_string = interfaces[ dev->
if_port - 1 ];
1010 if ( dev->
irq < 2 ) {
1014 while ( trials-- ) {
1015 dev->
irq = smc_findirq( ioaddr );
1019 smc_reset( ioaddr );
1022 if (dev->
irq == 0 ) {
1030 printk(
"%s: %s(r:%d) at %#3x IRQ:%d INTF:%s MEM:%db ", dev->
name,
1031 version_string, revision_register & 0xF, ioaddr, dev->
irq,
1032 if_string, memory );
1057 static void print_packet(
byte * buf,
int length )
1064 printk(
"Packet of length %d\n", length);
1065 lines = length / 16;
1066 remainder = length % 16;
1068 for ( i = 0; i < lines ; i ++ ) {
1071 for ( cur = 0; cur < 8; cur ++ ) {
1076 printk(
"%02x%02x ", a, b );
1080 for ( i = 0; i < remainder/2 ; i++ ) {
1085 printk(
"%02x%02x ", a, b );
1110 smc_reset( ioaddr );
1111 smc_enable( ioaddr );
1120 else if ( dev->
if_port == 2 ) {
1131 for ( i = 0; i < 6; i += 2 ) {
1134 address = dev->
dev_addr[ i + 1 ] << 8 ;
1139 netif_start_queue(dev);
1150 static void smc_timeout(
struct net_device *dev)
1155 tx_done(dev) ?
"IRQ conflict" :
1156 "network cable problem");
1163 netif_wake_queue(dev);
1191 PRINTK((CARDNAME
": WARNING: smc_rcv with nothing on FIFO.\n"));
1203 packet_length &= 0x07ff;
1205 PRINTK2((
"RCV: STATUS %4x LENGTH %4x\n", status, packet_length ));
1223 dev->
stats.multicast++;
1225 skb = netdev_alloc_skb(dev, packet_length + 5);
1227 if ( skb ==
NULL ) {
1229 dev->
stats.rx_dropped++;
1238 skb_reserve( skb, 2 );
1240 data =
skb_put( skb, packet_length);
1247 PRINTK3((
" Reading %d dwords (and %d bytes)\n",
1248 packet_length >> 2, packet_length & 3 ));
1249 insl(ioaddr +
DATA_1 , data, packet_length >> 2 );
1251 insb( ioaddr +
DATA_1, data + (packet_length & 0xFFFFFC),
1252 packet_length & 0x3 );
1254 PRINTK3((
" Reading %d words and %d byte(s)\n",
1255 (packet_length >> 1 ), packet_length & 1 ));
1256 insw(ioaddr +
DATA_1 , data, packet_length >> 1);
1257 if ( packet_length & 1 ) {
1258 data += packet_length & ~1;
1263 print_packet( data, packet_length );
1268 dev->
stats.rx_packets++;
1269 dev->
stats.rx_bytes += packet_length;
1272 dev->
stats.rx_errors++;
1276 dev->
stats.rx_length_errors++;
1301 static void smc_tx(
struct net_device * dev )
1304 struct smc_local *lp = netdev_priv(dev);
1323 PRINTK3((CARDNAME
": TX DONE STATUS: %4x\n", tx_status));
1325 dev->
stats.tx_errors++;
1329 ": Late collision occurred on last xmit.\n");
1330 dev->
stats.tx_window_errors++;
1333 if ( tx_status &
TS_16COL ) { ... }
1337 printk(CARDNAME
": Successful packet caused interrupt\n");
1370 struct smc_local *lp = netdev_priv(dev);
1382 PRINTK3((CARDNAME
": SMC interrupt started\n"));
1407 ": Handling interrupt status %x\n", status));
1412 ": Receive Interrupt\n"));
1416 ": TX ERROR handled\n"));
1424 dev->
stats.collisions += card_stats & 0xF;
1427 dev->
stats.collisions += card_stats & 0xF;
1433 ": TX_BUFFER_EMPTY handled\n"));
1435 mask &= ~IM_TX_EMPTY_INT;
1441 ": Allocation interrupt\n"));
1443 mask &= ~IM_ALLOC_INT;
1445 smc_hardware_send_packet( dev );
1448 mask |= ( IM_TX_EMPTY_INT |
IM_TX_INT );
1451 netif_wake_queue(dev);
1453 PRINTK2((CARDNAME
": Handoff done successfully.\n"));
1455 dev->
stats.rx_errors++;
1456 dev->
stats.rx_fifo_errors++;
1459 PRINTK((CARDNAME
": UNSUPPORTED: EPH INTERRUPT\n"));
1461 PRINTK((CARDNAME
": UNSUPPORTED: ERCV INTERRUPT\n"));
1464 }
while ( timeout -- );
1476 PRINTK3((CARDNAME
": Interrupt done\n"));
1491 netif_stop_queue(dev);
1507 static void smc_set_multicast_list(
struct net_device *dev)
1538 smc_setmulticast(ioaddr, dev);
1566 MODULE_PARM_DESC(ifport,
"SMC 99194 interface port (0-default, 1-TP, 2-AUI)");
1572 CARDNAME
": You shouldn't use auto-probing with insmod!\n" );
1576 if (IS_ERR(devSMC9194))
1577 return PTR_ERR(devSMC9194);