100 #include <linux/module.h>
101 #include <linux/kernel.h>
102 #include <linux/types.h>
103 #include <linux/fcntl.h>
106 #include <linux/string.h>
107 #include <linux/in.h>
109 #include <linux/errno.h>
111 #include <linux/netdevice.h>
115 #include <linux/bitops.h>
127 #define EEXP_IO_EXTENT 16
161 static unsigned short start_code[] = {
164 0x0008,0x0000,0x0000,
176 #define CONF_LINK 0x20
189 #define CONF_PROMISC 0x2e
196 #define CONF_HWADDR 0x38
197 0x0000,0x0000,0x0000,
201 #define CONF_NR_MULTICAST 0x44
203 #define CONF_MULTICAST 0x46
204 0x0000, 0x0000, 0x0000,
205 0x0000, 0x0000, 0x0000,
206 0x0000, 0x0000, 0x0000,
207 0x0000, 0x0000, 0x0000,
208 0x0000, 0x0000, 0x0000,
209 0x0000, 0x0000, 0x0000,
210 0x0000, 0x0000, 0x0000,
211 0x0000, 0x0000, 0x0000,
213 #define CONF_DIAG_RESULT 0x76
219 #define CONF_TDR_RESULT 0x82
227 static char irqrmap[] = { 0,0,1,2,3,4,0,0,0,1,5,6,0,0,0,0 };
239 static irqreturn_t eexp_irq(
int irq,
void *dev_addr);
249 static int eexp_hw_probe(
struct net_device *
dev,
unsigned short ioaddr);
250 static unsigned short eexp_hw_readeeprom(
unsigned short ioaddr,
253 static unsigned short eexp_hw_lasttxstat(
struct net_device *
dev);
262 static char *eexp_ifmap[]={
"AUI",
"BNC",
"RJ45"};
277 static inline unsigned short scb_rdcmd(
struct net_device *
dev)
302 static inline void clear_loopback(
struct net_device *dev)
307 static inline unsigned short int SHADOW(
short int addr)
310 if (addr > 0xf) addr += 0x3ff0;
311 return addr + 0x4000;
324 unsigned short *
port;
325 static unsigned short ports[] = { 0x240,0x300,0x310,0x270,0x320,0x340,0 };
327 int dev_irq = dev->
irq;
335 err = eexp_hw_probe(dev,ioaddr);
341 for (port=&ports[0] ; *
port ; port++ )
343 unsigned short sum = 0;
347 for ( i=0 ; i<4 ; i++ )
351 sum |= (t>>4) << ((t & 0x03)<<2);
353 if (sum==0xbaba && !eexp_hw_probe(dev,*port)) {
375 err = do_express_probe(dev);
397 if (!dev->
irq || !irqrmap[dev->
irq])
426 printk(
"%s: forcing ASIC to 8-bit mode\n", dev->
name);
430 eexp_hw_init586(dev);
431 netif_start_queue(dev);
459 netif_stop_queue(dev);
480 static void unstick_cu(
struct net_device *dev)
491 unsigned short boguscount=200,rsst;
511 netif_wake_queue(dev);
518 unsigned short txstatus = eexp_hw_lasttxstat(dev);
519 printk(
KERN_WARNING "%s: Transmit timed out, CU not active status %04x %04x, restarting...\n",
520 dev->
name, status, txstatus);
521 eexp_hw_txrestart(dev);
525 unsigned short txstatus = eexp_hw_lasttxstat(dev);
526 if (netif_queue_stopped(dev) && !txstatus)
529 dev->
name,status,txstatus);
530 eexp_hw_init586(dev);
531 netif_wake_queue(dev);
548 eexp_hw_init586(dev);
549 netif_wake_queue(dev);
554 static void eexp_timeout(
struct net_device *dev)
578 dev->
stats.tx_errors++;
584 netif_wake_queue(dev);
586 spin_unlock_irqrestore(&lp->
lock, flags);
624 unsigned short *
data = (
unsigned short *)buf->
data;
626 dev->
stats.tx_bytes += length;
628 eexp_hw_tx_pio(dev,data,length);
632 spin_unlock_irqrestore(&lp->
lock, flags);
645 static unsigned short eexp_start_irq(
struct net_device *dev,
646 unsigned short status)
648 unsigned short ack_cmd =
SCB_ack(status);
656 printk(
"%s: CU went non-active (status %04x)\n",
660 outw(CONF_DIAG_RESULT & ~31, ioaddr +
SM_PTR);
661 diag_status =
inw(ioaddr + SHADOW(CONF_DIAG_RESULT));
662 if (diag_status & 1<<11) {
665 }
else if (!(diag_status & 1<<13)) {
670 tdr_status =
inw(ioaddr + SHADOW(CONF_TDR_RESULT));
682 printk(
"%s: TDR is ga-ga (status %04x)\n", dev->
name,
704 static void eexp_cmd_clear(
struct net_device *dev)
706 unsigned long int oldtime =
jiffies;
707 while (scb_rdcmd(dev) && (
time_before(jiffies, oldtime + 10)));
708 if (scb_rdcmd(dev)) {
709 printk(
"%s: command didn't clear\n", dev->
name);
717 unsigned short ioaddr,
status,ack_cmd;
718 unsigned short old_read_ptr, old_write_ptr;
720 lp = netdev_priv(dev);
723 spin_lock(&lp->
lock);
742 scb_command(dev, ack_cmd);
748 if (!eexp_hw_lasttxstat(dev)) {
749 printk(
"%s: tx interrupt but no status\n", dev->
name);
757 }
while (status & 0xc000);
774 dev->
stats.rx_errors++;
778 lp->cur_rfd = lp->first_rfd;
786 ack_cmd = eexp_start_irq(dev, status);
789 scb_command(dev, ack_cmd);
798 printk(
"%s: leaving eexp_irq()\n", dev->
name);
803 spin_unlock(&lp->
lock);
815 static void eexp_hw_set_interface(
struct net_device *dev)
836 static void eexp_hw_rx_pio(
struct net_device *dev)
839 unsigned short rx_block = lp->
rx_ptr;
849 unsigned short rfd_cmd, rx_next, pbuf,
pkt_len;
869 else if (pbuf!=rx_block+0x16)
872 dev->
name, rx_block+0x16, pbuf);
875 else if ((pkt_len & 0xc000)!=0xc000)
878 dev->
name, pkt_len & 0xc000);
881 else if (!
FD_OK(status))
883 dev->
stats.rx_errors++;
885 dev->
stats.rx_crc_errors++;
887 dev->
stats.rx_frame_errors++;
889 dev->
stats.rx_fifo_errors++;
891 dev->
stats.rx_over_errors++;
893 dev->
stats.rx_length_errors++;
899 skb = netdev_alloc_skb(dev, pkt_len + 16);
903 dev->
stats.rx_dropped++;
911 dev->
stats.rx_packets++;
919 }
while (
FD_Done(status) && boguscount--);
930 static void eexp_hw_tx_pio(
struct net_device *dev,
unsigned short *buf,
974 netif_wake_queue(dev);
983 dev->
stats.tx_packets++;
988 .ndo_open = eexp_open,
989 .ndo_stop = eexp_close,
990 .ndo_start_xmit = eexp_xmit,
991 .ndo_set_rx_mode = eexp_set_multicast,
992 .ndo_tx_timeout = eexp_timeout,
1005 static int __init eexp_hw_probe(
struct net_device *dev,
unsigned short ioaddr)
1007 unsigned short hw_addr[3];
1011 unsigned short xsum = 0;
1012 struct net_local *lp = netdev_priv(dev);
1014 printk(
"%s: EtherExpress 16 at %#x ",dev->
name,ioaddr);
1021 hw_addr[0] = eexp_hw_readeeprom(ioaddr,2);
1022 hw_addr[1] = eexp_hw_readeeprom(ioaddr,3);
1023 hw_addr[2] = eexp_hw_readeeprom(ioaddr,4);
1026 if (!((hw_addr[2]==0x00aa && ((hw_addr[1] & 0xff00)==0x0000)) ||
1027 (hw_addr[2]==0x0080 && ((hw_addr[1] & 0xff00)==0x5F00))))
1029 printk(
" rejected: invalid address %04x%04x%04x\n",
1030 hw_addr[2],hw_addr[1],hw_addr[0]);
1037 for (i = 0; i < 64; i++)
1038 xsum += eexp_hw_readeeprom(ioaddr, i);
1040 printk(
" (bad EEPROM xsum 0x%02x)", xsum);
1043 for ( i=0 ; i<6 ; i++ )
1044 dev->
dev_addr[i] = ((
unsigned char *)hw_addr)[5-
i];
1047 static const char irqmap[] = { 0, 9, 3, 4, 5, 10, 11, 0 };
1048 unsigned short setupval = eexp_hw_readeeprom(ioaddr,0);
1052 dev->
irq = irqmap[setupval>>13];
1056 eexp_hw_readeeprom(ioaddr,5) & 0x1 ?
TPE :
BNC;
1059 buswidth = !((setupval & 0x400) >> 10);
1065 printk(
"(IRQ %d, %s connector, %d-bit bus", dev->
irq,
1066 eexp_ifmap[dev->
if_port], buswidth?8:16);
1071 eexp_hw_set_interface(dev);
1077 for (i = 0; i < 32768; i++)
1080 for (memory_size = 0; memory_size < 64; memory_size++)
1097 switch (memory_size)
1107 printk(
", %dk RAM)\n", memory_size);
1110 printk(
") bad memory size (%dk).\n", memory_size);
1128 static unsigned short __init eexp_hw_readeeprom(
unsigned short ioaddr,
1131 unsigned short cmd = 0x180|(location&0x7f);
1136 for (i=0x100 ;
i ; i>>=1 )
1151 for (i=0x8000 ;
i ; i>>=1 )
1178 static unsigned short eexp_hw_lasttxstat(
struct net_device *dev)
1180 struct net_local *lp = netdev_priv(dev);
1181 unsigned short tx_block = lp->
tx_reap;
1202 char *whatsup =
NULL;
1203 dev->
stats.tx_errors++;
1205 dev->
stats.tx_aborted_errors++;
1207 whatsup =
"aborted, no carrier";
1208 dev->
stats.tx_carrier_errors++;
1211 whatsup =
"aborted, lost CTS";
1212 dev->
stats.tx_carrier_errors++;
1215 whatsup =
"FIFO underran";
1216 dev->
stats.tx_fifo_errors++;
1219 whatsup =
"aborted, too many collisions";
1220 dev->
stats.tx_aborted_errors++;
1224 dev->
name, whatsup);
1227 dev->
stats.tx_packets++;
1233 netif_wake_queue(dev);
1248 static void eexp_hw_txrestart(
struct net_device *dev)
1250 struct net_local *lp = netdev_priv(dev);
1259 unsigned short boguscount=50,failcount=5;
1275 eexp_hw_init586(dev);
1276 netif_wake_queue(dev);
1293 static void eexp_hw_txinit(
struct net_device *dev)
1295 struct net_local *lp = netdev_priv(dev);
1297 unsigned short curtbuf;
1300 for ( curtbuf=0 ; curtbuf<lp->
num_tx_bufs ; curtbuf++ )
1335 static void eexp_hw_rxinit(
struct net_device *dev)
1337 struct net_local *lp = netdev_priv(dev);
1394 static void eexp_hw_init586(
struct net_device *dev)
1396 struct net_local *lp = netdev_priv(dev);
1401 printk(
"%s: eexp_hw_init586()\n", dev->
name);
1412 outw(lp->
width?0x0001:0x0000, ioaddr + 0x8006);
1413 outw(0x0000, ioaddr + 0x8008);
1414 outw(0x0000, ioaddr + 0x800a);
1415 outw(0x0000, ioaddr + 0x800c);
1416 outw(0x0000, ioaddr + 0x800e);
1418 for (i = 0; i <
ARRAY_SIZE(start_code) * 2; i+=32) {
1421 for (j = 0; j < 16 && (i+
j)/2 <
ARRAY_SIZE(start_code); j+=2)
1422 outw(start_code[(i+j)/2],
1424 for (j = 0; j < 16 && (i+j+16)/2 <
ARRAY_SIZE(start_code); j+=2)
1425 outw(start_code[(i+j+16)/2],
1431 i =
inw(ioaddr+SHADOW(CONF_PROMISC));
1433 ioaddr+SHADOW(CONF_PROMISC));
1436 eexp_setup_filter(dev);
1441 outw(((
unsigned short *)dev->
dev_addr)[0], ioaddr+SHADOW(CONF_HWADDR));
1443 ioaddr+SHADOW(CONF_HWADDR+2));
1445 ioaddr+SHADOW(CONF_HWADDR+4));
1447 eexp_hw_txinit(dev);
1448 eexp_hw_rxinit(dev);
1453 scb_command(dev, 0xf000);
1459 unsigned short rboguscount=50,rfailcount=5;
1460 while (
inw(ioaddr+0x4000))
1466 scb_command(dev, 0);
1479 scb_wrcbl(dev, CONF_LINK);
1484 unsigned short iboguscount=50,ifailcount=5;
1493 scb_wrcbl(dev, CONF_LINK);
1507 clear_loopback(dev);
1512 printk(
"%s: leaving eexp_hw_init586()\n", dev->
name);
1516 static void eexp_setup_filter(
struct net_device *dev)
1528 outw(CONF_NR_MULTICAST & ~31, ioaddr+
SM_PTR);
1529 outw(6*count, ioaddr+SHADOW(CONF_NR_MULTICAST));
1532 unsigned short *
data = (
unsigned short *) ha->
addr;
1536 outw((CONF_MULTICAST+(6*i)) & ~31, ioaddr+
SM_PTR);
1537 outw(data[0], ioaddr+SHADOW(CONF_MULTICAST+(6*i)));
1538 outw((CONF_MULTICAST+(6*i)+2) & ~31, ioaddr+
SM_PTR);
1539 outw(data[1], ioaddr+SHADOW(CONF_MULTICAST+(6*i)+2));
1540 outw((CONF_MULTICAST+(6*i)+4) & ~31, ioaddr+
SM_PTR);
1541 outw(data[2], ioaddr+SHADOW(CONF_MULTICAST+(6*i)+4));
1553 struct net_local *lp = netdev_priv(dev);
1557 i =
inw(ioaddr+SHADOW(CONF_PROMISC));
1559 ioaddr+SHADOW(CONF_PROMISC));
1564 eexp_setup_filter(dev);
1576 printk(
"%s: waiting for CU to go suspended\n", dev->
name);
1582 printk(
"%s: warning, CU didn't stop\n", dev->
name);
1584 scb_wrcbl(dev, CONF_LINK);
1597 #define EEXP_MAX_CARDS 4
1599 static struct net_device *dev_eexp[EEXP_MAX_CARDS];
1600 static int irq[EEXP_MAX_CARDS];
1601 static int io[EEXP_MAX_CARDS];
1617 int this_dev, found = 0;
1619 for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {
1620 dev = alloc_etherdev(
sizeof(
struct net_local));
1621 dev->
irq = irq[this_dev];
1623 if (io[this_dev] == 0) {
1626 printk(
KERN_NOTICE "eexpress.c: Module autoprobe not recommended, give io=xx.\n");
1628 if (do_express_probe(dev) == 0) {
1629 dev_eexp[this_dev] =
dev;
1646 for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) {