1/* Intel EtherExpress 16 device driver for Linux 2 * 3 * Written by John Sullivan, 1995 4 * based on original code by Donald Becker, with changes by 5 * Alan Cox and Pauline Middelink. 6 * 7 * Support for 8-bit mode by Zoltan Szilagyi <zoltans@cs.arizona.edu> 8 * 9 * Many modifications, and currently maintained, by 10 * Philip Blundell <philb@gnu.org> 11 * Added the Compaq LTE Alan Cox <alan@lxorguk.ukuu.org.uk> 12 * Added MCA support Adam Fritzler 13 * 14 * Note - this driver is experimental still - it has problems on faster 15 * machines. Someone needs to sit down and go through it line by line with 16 * a databook... 17 */ 18 19/* The EtherExpress 16 is a fairly simple card, based on a shared-memory 20 * design using the i82586 Ethernet coprocessor. It bears no relationship, 21 * as far as I know, to the similarly-named "EtherExpress Pro" range. 22 * 23 * Historically, Linux support for these cards has been very bad. However, 24 * things seem to be getting better slowly. 25 */ 26 27/* If your card is confused about what sort of interface it has (eg it 28 * persistently reports "10baseT" when none is fitted), running 'SOFTSET /BART' 29 * or 'SOFTSET /LISA' from DOS seems to help. 30 */ 31 32/* Here's the scoop on memory mapping. 33 * 34 * There are three ways to access EtherExpress card memory: either using the 35 * shared-memory mapping, or using PIO through the dataport, or using PIO 36 * through the "shadow memory" ports. 37 * 38 * The shadow memory system works by having the card map some of its memory 39 * as follows: 40 * 41 * (the low five bits of the SMPTR are ignored) 42 * 43 * base+0x4000..400f memory at SMPTR+0..15 44 * base+0x8000..800f memory at SMPTR+16..31 45 * base+0xc000..c007 dubious stuff (memory at SMPTR+16..23 apparently) 46 * base+0xc008..c00f memory at 0x0008..0x000f 47 * 48 * This last set (the one at c008) is particularly handy because the SCB 49 * lives at 0x0008. So that set of ports gives us easy random access to data 50 * in the SCB without having to mess around setting up pointers and the like. 51 * We always use this method to access the SCB (via the scb_xx() functions). 52 * 53 * Dataport access works by aiming the appropriate (read or write) pointer 54 * at the first address you're interested in, and then reading or writing from 55 * the dataport. The pointers auto-increment after each transfer. We use 56 * this for data transfer. 57 * 58 * We don't use the shared-memory system because it allegedly doesn't work on 59 * all cards, and because it's a bit more prone to go wrong (it's one more 60 * thing to configure...). 61 */ 62 63/* Known bugs: 64 * 65 * - The card seems to want to give us two interrupts every time something 66 * happens, where just one would be better. 67 */ 68 69/* 70 * 71 * Note by Zoltan Szilagyi 10-12-96: 72 * 73 * I've succeeded in eliminating the "CU wedged" messages, and hence the 74 * lockups, which were only occurring with cards running in 8-bit mode ("force 75 * 8-bit operation" in Intel's SoftSet utility). This version of the driver 76 * sets the 82586 and the ASIC to 8-bit mode at startup; it also stops the 77 * CU before submitting a packet for transmission, and then restarts it as soon 78 * as the process of handing the packet is complete. This is definitely an 79 * unnecessary slowdown if the card is running in 16-bit mode; therefore one 80 * should detect 16-bit vs 8-bit mode from the EEPROM settings and act 81 * accordingly. In 8-bit mode with this bugfix I'm getting about 150 K/s for 82 * ftp's, which is significantly better than I get in DOS, so the overhead of 83 * stopping and restarting the CU with each transmit is not prohibitive in 84 * practice. 85 * 86 * Update by David Woodhouse 11/5/99: 87 * 88 * I've seen "CU wedged" messages in 16-bit mode, on the Alpha architecture. 89 * I assume that this is because 16-bit accesses are actually handled as two 90 * 8-bit accesses. 91 */ 92 93#ifdef __alpha__ 94#define LOCKUP16 1 95#endif 96#ifndef LOCKUP16 97#define LOCKUP16 0 98#endif 99 100#include <linux/module.h> 101#include <linux/kernel.h> 102#include <linux/types.h> 103#include <linux/fcntl.h> 104#include <linux/interrupt.h> 105#include <linux/ioport.h> 106#include <linux/string.h> 107#include <linux/in.h> 108#include <linux/delay.h> 109#include <linux/errno.h> 110#include <linux/init.h> 111#include <linux/netdevice.h> 112#include <linux/etherdevice.h> 113#include <linux/skbuff.h> 114#include <linux/mca-legacy.h> 115#include <linux/spinlock.h> 116#include <linux/bitops.h> 117#include <linux/jiffies.h> 118 119#include <asm/system.h> 120#include <asm/io.h> 121#include <asm/irq.h> 122 123#ifndef NET_DEBUG 124#define NET_DEBUG 4 125#endif 126 127#include "eexpress.h" 128 129#define EEXP_IO_EXTENT 16 130 131/* 132 * Private data declarations 133 */ 134 135struct net_local 136{ 137 unsigned long last_tx; /* jiffies when last transmit started */ 138 unsigned long init_time; /* jiffies when eexp_hw_init586 called */ 139 unsigned short rx_first; /* first rx buf, same as RX_BUF_START */ 140 unsigned short rx_last; /* last rx buf */ 141 unsigned short rx_ptr; /* first rx buf to look at */ 142 unsigned short tx_head; /* next free tx buf */ 143 unsigned short tx_reap; /* first in-use tx buf */ 144 unsigned short tx_tail; /* previous tx buf to tx_head */ 145 unsigned short tx_link; /* last known-executing tx buf */ 146 unsigned short last_tx_restart; /* set to tx_link when we 147 restart the CU */ 148 unsigned char started; 149 unsigned short rx_buf_start; 150 unsigned short rx_buf_end; 151 unsigned short num_tx_bufs; 152 unsigned short num_rx_bufs; 153 unsigned char width; /* 0 for 16bit, 1 for 8bit */ 154 unsigned char was_promisc; 155 unsigned char old_mc_count; 156 spinlock_t lock; 157}; 158 159/* This is the code and data that is downloaded to the EtherExpress card's 160 * memory at boot time. 161 */ 162 163static unsigned short start_code[] = { 164/* 0x0000 */ 165 0x0001, /* ISCP: busy - cleared after reset */ 166 0x0008,0x0000,0x0000, /* offset,address (lo,hi) of SCB */ 167 168 0x0000,0x0000, /* SCB: status, commands */ 169 0x0000,0x0000, /* links to first command block, 170 first receive descriptor */ 171 0x0000,0x0000, /* CRC error, alignment error counts */ 172 0x0000,0x0000, /* out of resources, overrun error counts */ 173 174 0x0000,0x0000, /* pad */ 175 0x0000,0x0000, 176 177/* 0x20 -- start of 82586 CU program */ 178#define CONF_LINK 0x20 179 0x0000,Cmd_Config, 180 0x0032, /* link to next command */ 181 0x080c, /* 12 bytes follow : fifo threshold=8 */ 182 0x2e40, /* don't rx bad frames 183 * SRDY/ARDY => ext. sync. : preamble len=8 184 * take addresses from data buffers 185 * 6 bytes/address 186 */ 187 0x6000, /* default backoff method & priority 188 * interframe spacing = 0x60 */ 189 0xf200, /* slot time=0x200 190 * max collision retry = 0xf */ 191#define CONF_PROMISC 0x2e 192 0x0000, /* no HDLC : normal CRC : enable broadcast 193 * disable promiscuous/multicast modes */ 194 0x003c, /* minimum frame length = 60 octets) */ 195 196 0x0000,Cmd_SetAddr, 197 0x003e, /* link to next command */ 198#define CONF_HWADDR 0x38 199 0x0000,0x0000,0x0000, /* hardware address placed here */ 200 201 0x0000,Cmd_MCast, 202 0x0076, /* link to next command */ 203#define CONF_NR_MULTICAST 0x44 204 0x0000, /* number of bytes in multicast address(es) */ 205#define CONF_MULTICAST 0x46 206 0x0000, 0x0000, 0x0000, /* some addresses */ 207 0x0000, 0x0000, 0x0000, 208 0x0000, 0x0000, 0x0000, 209 0x0000, 0x0000, 0x0000, 210 0x0000, 0x0000, 0x0000, 211 0x0000, 0x0000, 0x0000, 212 0x0000, 0x0000, 0x0000, 213 0x0000, 0x0000, 0x0000, 214 215#define CONF_DIAG_RESULT 0x76 216 0x0000, Cmd_Diag, 217 0x007c, /* link to next command */ 218 219 0x0000,Cmd_TDR|Cmd_INT, 220 0x0084, 221#define CONF_TDR_RESULT 0x82 222 0x0000, 223 224 0x0000,Cmd_END|Cmd_Nop, /* end of configure sequence */ 225 0x0084 /* dummy link */ 226}; 227 228/* maps irq number to EtherExpress magic value */ 229static char irqrmap[] = { 0,0,1,2,3,4,0,0,0,1,5,6,0,0,0,0 }; 230 231#ifdef CONFIG_MCA_LEGACY 232/* mapping of the first four bits of the second POS register */ 233static unsigned short mca_iomap[] = { 234 0x270, 0x260, 0x250, 0x240, 0x230, 0x220, 0x210, 0x200, 235 0x370, 0x360, 0x350, 0x340, 0x330, 0x320, 0x310, 0x300 236}; 237/* bits 5-7 of the second POS register */ 238static char mca_irqmap[] = { 12, 9, 3, 4, 5, 10, 11, 15 }; 239#endif 240 241/* 242 * Prototypes for Linux interface 243 */ 244 245static int eexp_open(struct net_device *dev); 246static int eexp_close(struct net_device *dev); 247static void eexp_timeout(struct net_device *dev); 248static netdev_tx_t eexp_xmit(struct sk_buff *buf, 249 struct net_device *dev); 250 251static irqreturn_t eexp_irq(int irq, void *dev_addr); 252static void eexp_set_multicast(struct net_device *dev); 253 254/* 255 * Prototypes for hardware access functions 256 */ 257 258static void eexp_hw_rx_pio(struct net_device *dev); 259static void eexp_hw_tx_pio(struct net_device *dev, unsigned short *buf, 260 unsigned short len); 261static int eexp_hw_probe(struct net_device *dev,unsigned short ioaddr); 262static unsigned short eexp_hw_readeeprom(unsigned short ioaddr, 263 unsigned char location); 264 265static unsigned short eexp_hw_lasttxstat(struct net_device *dev); 266static void eexp_hw_txrestart(struct net_device *dev); 267 268static void eexp_hw_txinit (struct net_device *dev); 269static void eexp_hw_rxinit (struct net_device *dev); 270 271static void eexp_hw_init586 (struct net_device *dev); 272static void eexp_setup_filter (struct net_device *dev); 273 274static char *eexp_ifmap[]={"AUI", "BNC", "RJ45"}; 275enum eexp_iftype {AUI=0, BNC=1, TPE=2}; 276 277#define STARTED_RU 2 278#define STARTED_CU 1 279 280/* 281 * Primitive hardware access functions. 282 */ 283 284static inline unsigned short scb_status(struct net_device *dev) 285{ 286 return inw(dev->base_addr + 0xc008); 287} 288 289static inline unsigned short scb_rdcmd(struct net_device *dev) 290{ 291 return inw(dev->base_addr + 0xc00a); 292} 293 294static inline void scb_command(struct net_device *dev, unsigned short cmd) 295{ 296 outw(cmd, dev->base_addr + 0xc00a); 297} 298 299static inline void scb_wrcbl(struct net_device *dev, unsigned short val) 300{ 301 outw(val, dev->base_addr + 0xc00c); 302} 303 304static inline void scb_wrrfa(struct net_device *dev, unsigned short val) 305{ 306 outw(val, dev->base_addr + 0xc00e); 307} 308 309static inline void set_loopback(struct net_device *dev) 310{ 311 outb(inb(dev->base_addr + Config) | 2, dev->base_addr + Config); 312} 313 314static inline void clear_loopback(struct net_device *dev) 315{ 316 outb(inb(dev->base_addr + Config) & ~2, dev->base_addr + Config); 317} 318 319static inline unsigned short int SHADOW(short int addr) 320{ 321 addr &= 0x1f; 322 if (addr > 0xf) addr += 0x3ff0; 323 return addr + 0x4000; 324} 325 326/* 327 * Linux interface 328 */ 329 330/* 331 * checks for presence of EtherExpress card 332 */ 333 334static int __init do_express_probe(struct net_device *dev) 335{ 336 unsigned short *port; 337 static unsigned short ports[] = { 0x240,0x300,0x310,0x270,0x320,0x340,0 }; 338 unsigned short ioaddr = dev->base_addr; 339 int dev_irq = dev->irq; 340 int err; 341 342 dev->if_port = 0xff; /* not set */ 343 344#ifdef CONFIG_MCA_LEGACY 345 if (MCA_bus) { 346 int slot = 0; 347 348 /* 349 * Only find one card at a time. Subsequent calls 350 * will find others, however, proper multicard MCA 351 * probing and setup can't be done with the 352 * old-style Space.c init routines. -- ASF 353 */ 354 while (slot != MCA_NOTFOUND) { 355 int pos0, pos1; 356 357 slot = mca_find_unused_adapter(0x628B, slot); 358 if (slot == MCA_NOTFOUND) 359 break; 360 361 pos0 = mca_read_stored_pos(slot, 2); 362 pos1 = mca_read_stored_pos(slot, 3); 363 ioaddr = mca_iomap[pos1&0xf]; 364 365 dev->irq = mca_irqmap[(pos1>>4)&0x7]; 366 367 if ((pos0 & 0x7) == 0x1) 368 dev->if_port = AUI; 369 else if ((pos0 & 0x7) == 0x5) { 370 if (pos1 & 0x80) 371 dev->if_port = BNC; 372 else 373 dev->if_port = TPE; 374 } 375 376 mca_set_adapter_name(slot, "Intel EtherExpress 16 MCA"); 377 mca_set_adapter_procfn(slot, NULL, dev); 378 mca_mark_as_used(slot); 379 380 break; 381 } 382 } 383#endif 384 if (ioaddr&0xfe00) { 385 if (!request_region(ioaddr, EEXP_IO_EXTENT, "EtherExpress")) 386 return -EBUSY; 387 err = eexp_hw_probe(dev,ioaddr); 388 release_region(ioaddr, EEXP_IO_EXTENT); 389 return err; 390 } else if (ioaddr) 391 return -ENXIO; 392 393 for (port=&ports[0] ; *port ; port++ ) 394 { 395 unsigned short sum = 0; 396 int i; 397 if (!request_region(*port, EEXP_IO_EXTENT, "EtherExpress")) 398 continue; 399 for ( i=0 ; i<4 ; i++ ) 400 { 401 unsigned short t; 402 t = inb(*port + ID_PORT); 403 sum |= (t>>4) << ((t & 0x03)<<2); 404 } 405 if (sum==0xbaba && !eexp_hw_probe(dev,*port)) { 406 release_region(*port, EEXP_IO_EXTENT); 407 return 0; 408 } 409 release_region(*port, EEXP_IO_EXTENT); 410 dev->irq = dev_irq; 411 } 412 return -ENODEV; 413} 414 415#ifndef MODULE 416struct net_device * __init express_probe(int unit) 417{ 418 struct net_device *dev = alloc_etherdev(sizeof(struct net_local)); 419 int err; 420 421 if (!dev) 422 return ERR_PTR(-ENOMEM); 423 424 sprintf(dev->name, "eth%d", unit); 425 netdev_boot_setup_check(dev); 426 427 err = do_express_probe(dev); 428 if (!err) 429 return dev; 430 free_netdev(dev); 431 return ERR_PTR(err); 432} 433#endif 434 435/* 436 * open and initialize the adapter, ready for use 437 */ 438 439static int eexp_open(struct net_device *dev) 440{ 441 int ret; 442 unsigned short ioaddr = dev->base_addr; 443 struct net_local *lp = netdev_priv(dev); 444 445#if NET_DEBUG > 6 446 printk(KERN_DEBUG "%s: eexp_open()\n", dev->name); 447#endif 448 449 if (!dev->irq || !irqrmap[dev->irq]) 450 return -ENXIO; 451 452 ret = request_irq(dev->irq, eexp_irq, 0, dev->name, dev); 453 if (ret) 454 return ret; 455 456 if (!request_region(ioaddr, EEXP_IO_EXTENT, "EtherExpress")) { 457 printk(KERN_WARNING "EtherExpress io port %x, is busy.\n" 458 , ioaddr); 459 goto err_out1; 460 } 461 if (!request_region(ioaddr+0x4000, EEXP_IO_EXTENT, "EtherExpress shadow")) { 462 printk(KERN_WARNING "EtherExpress io port %x, is busy.\n" 463 , ioaddr+0x4000); 464 goto err_out2; 465 } 466 if (!request_region(ioaddr+0x8000, EEXP_IO_EXTENT, "EtherExpress shadow")) { 467 printk(KERN_WARNING "EtherExpress io port %x, is busy.\n" 468 , ioaddr+0x8000); 469 goto err_out3; 470 } 471 if (!request_region(ioaddr+0xc000, EEXP_IO_EXTENT, "EtherExpress shadow")) { 472 printk(KERN_WARNING "EtherExpress io port %x, is busy.\n" 473 , ioaddr+0xc000); 474 goto err_out4; 475 } 476 477 if (lp->width) { 478 printk("%s: forcing ASIC to 8-bit mode\n", dev->name); 479 outb(inb(dev->base_addr+Config)&~4, dev->base_addr+Config); 480 } 481 482 eexp_hw_init586(dev); 483 netif_start_queue(dev); 484#if NET_DEBUG > 6 485 printk(KERN_DEBUG "%s: leaving eexp_open()\n", dev->name); 486#endif 487 return 0; 488 489 err_out4: 490 release_region(ioaddr+0x8000, EEXP_IO_EXTENT); 491 err_out3: 492 release_region(ioaddr+0x4000, EEXP_IO_EXTENT); 493 err_out2: 494 release_region(ioaddr, EEXP_IO_EXTENT); 495 err_out1: 496 free_irq(dev->irq, dev); 497 return -EBUSY; 498} 499 500/* 501 * close and disable the interface, leaving the 586 in reset. 502 */ 503 504static int eexp_close(struct net_device *dev) 505{ 506 unsigned short ioaddr = dev->base_addr; 507 struct net_local *lp = netdev_priv(dev); 508 509 int irq = dev->irq; 510 511 netif_stop_queue(dev); 512 513 outb(SIRQ_dis|irqrmap[irq],ioaddr+SET_IRQ); 514 lp->started = 0; 515 scb_command(dev, SCB_CUsuspend|SCB_RUsuspend); 516 outb(0,ioaddr+SIGNAL_CA); 517 free_irq(irq,dev); 518 outb(i586_RST,ioaddr+EEPROM_Ctrl); 519 release_region(ioaddr, EEXP_IO_EXTENT); 520 release_region(ioaddr+0x4000, 16); 521 release_region(ioaddr+0x8000, 16); 522 release_region(ioaddr+0xc000, 16); 523 524 return 0; 525} 526 527/* 528 * This gets called when a higher level thinks we are broken. Check that 529 * nothing has become jammed in the CU. 530 */ 531 532static void unstick_cu(struct net_device *dev) 533{ 534 struct net_local *lp = netdev_priv(dev); 535 unsigned short ioaddr = dev->base_addr; 536 537 if (lp->started) 538 { 539 if (time_after(jiffies, dev_trans_start(dev) + HZ/2)) 540 { 541 if (lp->tx_link==lp->last_tx_restart) 542 { 543 unsigned short boguscount=200,rsst; 544 printk(KERN_WARNING "%s: Retransmit timed out, status %04x, resetting...\n", 545 dev->name, scb_status(dev)); 546 eexp_hw_txinit(dev); 547 lp->last_tx_restart = 0; 548 scb_wrcbl(dev, lp->tx_link); 549 scb_command(dev, SCB_CUstart); 550 outb(0,ioaddr+SIGNAL_CA); 551 while (!SCB_complete(rsst=scb_status(dev))) 552 { 553 if (!--boguscount) 554 { 555 boguscount=200; 556 printk(KERN_WARNING "%s: Reset timed out status %04x, retrying...\n", 557 dev->name,rsst); 558 scb_wrcbl(dev, lp->tx_link); 559 scb_command(dev, SCB_CUstart); 560 outb(0,ioaddr+SIGNAL_CA); 561 } 562 } 563 netif_wake_queue(dev); 564 } 565 else 566 { 567 unsigned short status = scb_status(dev); 568 if (SCB_CUdead(status)) 569 { 570 unsigned short txstatus = eexp_hw_lasttxstat(dev); 571 printk(KERN_WARNING "%s: Transmit timed out, CU not active status %04x %04x, restarting...\n", 572 dev->name, status, txstatus); 573 eexp_hw_txrestart(dev); 574 } 575 else 576 { 577 unsigned short txstatus = eexp_hw_lasttxstat(dev); 578 if (netif_queue_stopped(dev) && !txstatus) 579 { 580 printk(KERN_WARNING "%s: CU wedged, status %04x %04x, resetting...\n", 581 dev->name,status,txstatus); 582 eexp_hw_init586(dev); 583 netif_wake_queue(dev); 584 } 585 else 586 { 587 printk(KERN_WARNING "%s: transmit timed out\n", dev->name); 588 } 589 } 590 } 591 } 592 } 593 else 594 { 595 if (time_after(jiffies, lp->init_time + 10)) 596 { 597 unsigned short status = scb_status(dev); 598 printk(KERN_WARNING "%s: i82586 startup timed out, status %04x, resetting...\n", 599 dev->name, status); 600 eexp_hw_init586(dev); 601 netif_wake_queue(dev); 602 } 603 } 604} 605 606static void eexp_timeout(struct net_device *dev) 607{ 608 struct net_local *lp = netdev_priv(dev); 609#ifdef CONFIG_SMP 610 unsigned long flags; 611#endif 612 int status; 613 614 disable_irq(dev->irq); 615 616 /* 617 * Best would be to use synchronize_irq(); spin_lock() here 618 * lets make it work first.. 619 */ 620 621#ifdef CONFIG_SMP 622 spin_lock_irqsave(&lp->lock, flags); 623#endif 624 625 status = scb_status(dev); 626 unstick_cu(dev); 627 printk(KERN_INFO "%s: transmit timed out, %s?\n", dev->name, 628 (SCB_complete(status)?"lost interrupt": 629 "board on fire")); 630 dev->stats.tx_errors++; 631 lp->last_tx = jiffies; 632 if (!SCB_complete(status)) { 633 scb_command(dev, SCB_CUabort); 634 outb(0,dev->base_addr+SIGNAL_CA); 635 } 636 netif_wake_queue(dev); 637#ifdef CONFIG_SMP 638 spin_unlock_irqrestore(&lp->lock, flags); 639#endif 640} 641 642/* 643 * Called to transmit a packet, or to allow us to right ourselves 644 * if the kernel thinks we've died. 645 */ 646static netdev_tx_t eexp_xmit(struct sk_buff *buf, struct net_device *dev) 647{ 648 short length = buf->len; 649#ifdef CONFIG_SMP 650 struct net_local *lp = netdev_priv(dev); 651 unsigned long flags; 652#endif 653 654#if NET_DEBUG > 6 655 printk(KERN_DEBUG "%s: eexp_xmit()\n", dev->name); 656#endif 657 658 if (buf->len < ETH_ZLEN) { 659 if (skb_padto(buf, ETH_ZLEN)) 660 return NETDEV_TX_OK; 661 length = ETH_ZLEN; 662 } 663 664 disable_irq(dev->irq); 665 666 /* 667 * Best would be to use synchronize_irq(); spin_lock() here 668 * lets make it work first.. 669 */ 670 671#ifdef CONFIG_SMP 672 spin_lock_irqsave(&lp->lock, flags); 673#endif 674 675 { 676 unsigned short *data = (unsigned short *)buf->data; 677 678 dev->stats.tx_bytes += length; 679 680 eexp_hw_tx_pio(dev,data,length); 681 } 682 dev_kfree_skb(buf); 683#ifdef CONFIG_SMP 684 spin_unlock_irqrestore(&lp->lock, flags); 685#endif 686 enable_irq(dev->irq); 687 return NETDEV_TX_OK; 688} 689 690/* 691 * Handle an EtherExpress interrupt 692 * If we've finished initializing, start the RU and CU up. 693 * If we've already started, reap tx buffers, handle any received packets, 694 * check to make sure we've not become wedged. 695 */ 696 697static unsigned short eexp_start_irq(struct net_device *dev, 698 unsigned short status) 699{ 700 unsigned short ack_cmd = SCB_ack(status); 701 struct net_local *lp = netdev_priv(dev); 702 unsigned short ioaddr = dev->base_addr; 703 if ((dev->flags & IFF_UP) && !(lp->started & STARTED_CU)) { 704 short diag_status, tdr_status; 705 while (SCB_CUstat(status)==2) 706 status = scb_status(dev); 707#if NET_DEBUG > 4 708 printk("%s: CU went non-active (status %04x)\n", 709 dev->name, status); 710#endif 711 712 outw(CONF_DIAG_RESULT & ~31, ioaddr + SM_PTR); 713 diag_status = inw(ioaddr + SHADOW(CONF_DIAG_RESULT)); 714 if (diag_status & 1<<11) { 715 printk(KERN_WARNING "%s: 82586 failed self-test\n", 716 dev->name); 717 } else if (!(diag_status & 1<<13)) { 718 printk(KERN_WARNING "%s: 82586 self-test failed to complete\n", dev->name); 719 } 720 721 outw(CONF_TDR_RESULT & ~31, ioaddr + SM_PTR); 722 tdr_status = inw(ioaddr + SHADOW(CONF_TDR_RESULT)); 723 if (tdr_status & (TDR_SHORT|TDR_OPEN)) { 724 printk(KERN_WARNING "%s: TDR reports cable %s at %d tick%s\n", dev->name, (tdr_status & TDR_SHORT)?"short":"broken", tdr_status & TDR_TIME, ((tdr_status & TDR_TIME) != 1) ? "s" : ""); 725 } 726 else if (tdr_status & TDR_XCVRPROBLEM) { 727 printk(KERN_WARNING "%s: TDR reports transceiver problem\n", dev->name); 728 } 729 else if (tdr_status & TDR_LINKOK) { 730#if NET_DEBUG > 4 731 printk(KERN_DEBUG "%s: TDR reports link OK\n", dev->name); 732#endif 733 } else { 734 printk("%s: TDR is ga-ga (status %04x)\n", dev->name, 735 tdr_status); 736 } 737 738 lp->started |= STARTED_CU; 739 scb_wrcbl(dev, lp->tx_link); 740 /* if the RU isn't running, start it now */ 741 if (!(lp->started & STARTED_RU)) { 742 ack_cmd |= SCB_RUstart; 743 scb_wrrfa(dev, lp->rx_buf_start); 744 lp->rx_ptr = lp->rx_buf_start; 745 lp->started |= STARTED_RU; 746 } 747 ack_cmd |= SCB_CUstart | 0x2000; 748 } 749 750 if ((dev->flags & IFF_UP) && !(lp->started & STARTED_RU) && SCB_RUstat(status)==4) 751 lp->started|=STARTED_RU; 752 753 return ack_cmd; 754} 755 756static void eexp_cmd_clear(struct net_device *dev) 757{ 758 unsigned long int oldtime = jiffies; 759 while (scb_rdcmd(dev) && (time_before(jiffies, oldtime + 10))); 760 if (scb_rdcmd(dev)) { 761 printk("%s: command didn't clear\n", dev->name); 762 } 763} 764 765static irqreturn_t eexp_irq(int dummy, void *dev_info) 766{ 767 struct net_device *dev = dev_info; 768 struct net_local *lp; 769 unsigned short ioaddr,status,ack_cmd; 770 unsigned short old_read_ptr, old_write_ptr; 771 772 lp = netdev_priv(dev); 773 ioaddr = dev->base_addr; 774 775 spin_lock(&lp->lock); 776 777 old_read_ptr = inw(ioaddr+READ_PTR); 778 old_write_ptr = inw(ioaddr+WRITE_PTR); 779 780 outb(SIRQ_dis|irqrmap[dev->irq], ioaddr+SET_IRQ); 781 782 status = scb_status(dev); 783 784#if NET_DEBUG > 4 785 printk(KERN_DEBUG "%s: interrupt (status %x)\n", dev->name, status); 786#endif 787 788 if (lp->started == (STARTED_CU | STARTED_RU)) { 789 790 do { 791 eexp_cmd_clear(dev); 792 793 ack_cmd = SCB_ack(status); 794 scb_command(dev, ack_cmd); 795 outb(0,ioaddr+SIGNAL_CA); 796 797 eexp_cmd_clear(dev); 798 799 if (SCB_complete(status)) { 800 if (!eexp_hw_lasttxstat(dev)) { 801 printk("%s: tx interrupt but no status\n", dev->name); 802 } 803 } 804 805 if (SCB_rxdframe(status)) 806 eexp_hw_rx_pio(dev); 807 808 status = scb_status(dev); 809 } while (status & 0xc000); 810 811 if (SCB_RUdead(status)) 812 { 813 printk(KERN_WARNING "%s: RU stopped: status %04x\n", 814 dev->name,status); 815 dev->stats.rx_errors++; 816 eexp_hw_rxinit(dev); 817 scb_wrrfa(dev, lp->rx_buf_start); 818 scb_command(dev, SCB_RUstart); 819 outb(0,ioaddr+SIGNAL_CA); 820 } 821 } else { 822 if (status & 0x8000) 823 ack_cmd = eexp_start_irq(dev, status); 824 else 825 ack_cmd = SCB_ack(status); 826 scb_command(dev, ack_cmd); 827 outb(0,ioaddr+SIGNAL_CA); 828 } 829 830 eexp_cmd_clear(dev); 831 832 outb(SIRQ_en|irqrmap[dev->irq], ioaddr+SET_IRQ); 833 834#if NET_DEBUG > 6 835 printk("%s: leaving eexp_irq()\n", dev->name); 836#endif 837 outw(old_read_ptr, ioaddr+READ_PTR); 838 outw(old_write_ptr, ioaddr+WRITE_PTR); 839 840 spin_unlock(&lp->lock); 841 return IRQ_HANDLED; 842} 843 844/* 845 * Hardware access functions 846 */ 847 848/* 849 * Set the cable type to use. 850 */ 851 852static void eexp_hw_set_interface(struct net_device *dev) 853{ 854 unsigned char oldval = inb(dev->base_addr + 0x300e); 855 oldval &= ~0x82; 856 switch (dev->if_port) { 857 case TPE: 858 oldval |= 0x2; 859 case BNC: 860 oldval |= 0x80; 861 break; 862 } 863 outb(oldval, dev->base_addr+0x300e); 864 mdelay(20); 865} 866 867/* 868 * Check all the receive buffers, and hand any received packets 869 * to the upper levels. Basic sanity check on each frame 870 * descriptor, though we don't bother trying to fix broken ones. 871 */ 872 873static void eexp_hw_rx_pio(struct net_device *dev) 874{ 875 struct net_local *lp = netdev_priv(dev); 876 unsigned short rx_block = lp->rx_ptr; 877 unsigned short boguscount = lp->num_rx_bufs; 878 unsigned short ioaddr = dev->base_addr; 879 unsigned short status; 880 881#if NET_DEBUG > 6 882 printk(KERN_DEBUG "%s: eexp_hw_rx()\n", dev->name); 883#endif 884 885 do { 886 unsigned short rfd_cmd, rx_next, pbuf, pkt_len; 887 888 outw(rx_block, ioaddr + READ_PTR); 889 status = inw(ioaddr + DATAPORT); 890 891 if (FD_Done(status)) 892 { 893 rfd_cmd = inw(ioaddr + DATAPORT); 894 rx_next = inw(ioaddr + DATAPORT); 895 pbuf = inw(ioaddr + DATAPORT); 896 897 outw(pbuf, ioaddr + READ_PTR); 898 pkt_len = inw(ioaddr + DATAPORT); 899 900 if (rfd_cmd!=0x0000) 901 { 902 printk(KERN_WARNING "%s: rfd_cmd not zero:0x%04x\n", 903 dev->name, rfd_cmd); 904 continue; 905 } 906 else if (pbuf!=rx_block+0x16) 907 { 908 printk(KERN_WARNING "%s: rfd and rbd out of sync 0x%04x 0x%04x\n", 909 dev->name, rx_block+0x16, pbuf); 910 continue; 911 } 912 else if ((pkt_len & 0xc000)!=0xc000) 913 { 914 printk(KERN_WARNING "%s: EOF or F not set on received buffer (%04x)\n", 915 dev->name, pkt_len & 0xc000); 916 continue; 917 } 918 else if (!FD_OK(status)) 919 { 920 dev->stats.rx_errors++; 921 if (FD_CRC(status)) 922 dev->stats.rx_crc_errors++; 923 if (FD_Align(status)) 924 dev->stats.rx_frame_errors++; 925 if (FD_Resrc(status)) 926 dev->stats.rx_fifo_errors++; 927 if (FD_DMA(status)) 928 dev->stats.rx_over_errors++; 929 if (FD_Short(status)) 930 dev->stats.rx_length_errors++; 931 } 932 else 933 { 934 struct sk_buff *skb; 935 pkt_len &= 0x3fff; 936 skb = dev_alloc_skb(pkt_len+16); 937 if (skb == NULL) 938 { 939 printk(KERN_WARNING "%s: Memory squeeze, dropping packet\n",dev->name); 940 dev->stats.rx_dropped++; 941 break; 942 } 943 skb_reserve(skb, 2); 944 outw(pbuf+10, ioaddr+READ_PTR); 945 insw(ioaddr+DATAPORT, skb_put(skb,pkt_len),(pkt_len+1)>>1); 946 skb->protocol = eth_type_trans(skb,dev); 947 netif_rx(skb); 948 dev->stats.rx_packets++; 949 dev->stats.rx_bytes += pkt_len; 950 } 951 outw(rx_block, ioaddr+WRITE_PTR); 952 outw(0, ioaddr+DATAPORT); 953 outw(0, ioaddr+DATAPORT); 954 rx_block = rx_next; 955 } 956 } while (FD_Done(status) && boguscount--); 957 lp->rx_ptr = rx_block; 958} 959 960/* 961 * Hand a packet to the card for transmission 962 * If we get here, we MUST have already checked 963 * to make sure there is room in the transmit 964 * buffer region. 965 */ 966 967static void eexp_hw_tx_pio(struct net_device *dev, unsigned short *buf, 968 unsigned short len) 969{ 970 struct net_local *lp = netdev_priv(dev); 971 unsigned short ioaddr = dev->base_addr; 972 973 if (LOCKUP16 || lp->width) { 974 /* Stop the CU so that there is no chance that it 975 jumps off to a bogus address while we are writing the 976 pointer to the next transmit packet in 8-bit mode -- 977 this eliminates the "CU wedged" errors in 8-bit mode. 978 (Zoltan Szilagyi 10-12-96) */ 979 scb_command(dev, SCB_CUsuspend); 980 outw(0xFFFF, ioaddr+SIGNAL_CA); 981 } 982 983 outw(lp->tx_head, ioaddr + WRITE_PTR); 984 985 outw(0x0000, ioaddr + DATAPORT); 986 outw(Cmd_INT|Cmd_Xmit, ioaddr + DATAPORT); 987 outw(lp->tx_head+0x08, ioaddr + DATAPORT); 988 outw(lp->tx_head+0x0e, ioaddr + DATAPORT); 989 990 outw(0x0000, ioaddr + DATAPORT); 991 outw(0x0000, ioaddr + DATAPORT); 992 outw(lp->tx_head+0x08, ioaddr + DATAPORT); 993 994 outw(0x8000|len, ioaddr + DATAPORT); 995 outw(-1, ioaddr + DATAPORT); 996 outw(lp->tx_head+0x16, ioaddr + DATAPORT); 997 outw(0, ioaddr + DATAPORT); 998 999 outsw(ioaddr + DATAPORT, buf, (len+1)>>1); 1000 1001 outw(lp->tx_tail+0xc, ioaddr + WRITE_PTR); 1002 outw(lp->tx_head, ioaddr + DATAPORT); 1003 1004 dev->trans_start = jiffies; 1005 lp->tx_tail = lp->tx_head; 1006 if (lp->tx_head==TX_BUF_START+((lp->num_tx_bufs-1)*TX_BUF_SIZE)) 1007 lp->tx_head = TX_BUF_START; 1008 else 1009 lp->tx_head += TX_BUF_SIZE; 1010 if (lp->tx_head != lp->tx_reap) 1011 netif_wake_queue(dev); 1012 1013 if (LOCKUP16 || lp->width) { 1014 /* Restart the CU so that the packet can actually 1015 be transmitted. (Zoltan Szilagyi 10-12-96) */ 1016 scb_command(dev, SCB_CUresume); 1017 outw(0xFFFF, ioaddr+SIGNAL_CA); 1018 } 1019 1020 dev->stats.tx_packets++; 1021 lp->last_tx = jiffies; 1022} 1023 1024static const struct net_device_ops eexp_netdev_ops = { 1025 .ndo_open = eexp_open, 1026 .ndo_stop = eexp_close, 1027 .ndo_start_xmit = eexp_xmit, 1028 .ndo_set_multicast_list = eexp_set_multicast, 1029 .ndo_tx_timeout = eexp_timeout, 1030 .ndo_change_mtu = eth_change_mtu, 1031 .ndo_set_mac_address = eth_mac_addr, 1032 .ndo_validate_addr = eth_validate_addr, 1033}; 1034 1035/* 1036 * Sanity check the suspected EtherExpress card 1037 * Read hardware address, reset card, size memory and initialize buffer 1038 * memory pointers. These are held in netdev_priv(), in case someone has more 1039 * than one card in a machine. 1040 */ 1041 1042static int __init eexp_hw_probe(struct net_device *dev, unsigned short ioaddr) 1043{ 1044 unsigned short hw_addr[3]; 1045 unsigned char buswidth; 1046 unsigned int memory_size; 1047 int i; 1048 unsigned short xsum = 0; 1049 struct net_local *lp = netdev_priv(dev); 1050 1051 printk("%s: EtherExpress 16 at %#x ",dev->name,ioaddr); 1052 1053 outb(ASIC_RST, ioaddr+EEPROM_Ctrl); 1054 outb(0, ioaddr+EEPROM_Ctrl); 1055 udelay(500); 1056 outb(i586_RST, ioaddr+EEPROM_Ctrl); 1057 1058 hw_addr[0] = eexp_hw_readeeprom(ioaddr,2); 1059 hw_addr[1] = eexp_hw_readeeprom(ioaddr,3); 1060 hw_addr[2] = eexp_hw_readeeprom(ioaddr,4); 1061 1062 /* Standard Address or Compaq LTE Address */ 1063 if (!((hw_addr[2]==0x00aa && ((hw_addr[1] & 0xff00)==0x0000)) || 1064 (hw_addr[2]==0x0080 && ((hw_addr[1] & 0xff00)==0x5F00)))) 1065 { 1066 printk(" rejected: invalid address %04x%04x%04x\n", 1067 hw_addr[2],hw_addr[1],hw_addr[0]); 1068 return -ENODEV; 1069 } 1070 1071 /* Calculate the EEPROM checksum. Carry on anyway if it's bad, 1072 * though. 1073 */ 1074 for (i = 0; i < 64; i++) 1075 xsum += eexp_hw_readeeprom(ioaddr, i); 1076 if (xsum != 0xbaba) 1077 printk(" (bad EEPROM xsum 0x%02x)", xsum); 1078 1079 dev->base_addr = ioaddr; 1080 for ( i=0 ; i<6 ; i++ ) 1081 dev->dev_addr[i] = ((unsigned char *)hw_addr)[5-i]; 1082 1083 { 1084 static char irqmap[]={0, 9, 3, 4, 5, 10, 11, 0}; 1085 unsigned short setupval = eexp_hw_readeeprom(ioaddr,0); 1086 1087 /* Use the IRQ from EEPROM if none was given */ 1088 if (!dev->irq) 1089 dev->irq = irqmap[setupval>>13]; 1090 1091 if (dev->if_port == 0xff) { 1092 dev->if_port = !(setupval & 0x1000) ? AUI : 1093 eexp_hw_readeeprom(ioaddr,5) & 0x1 ? TPE : BNC; 1094 } 1095 1096 buswidth = !((setupval & 0x400) >> 10); 1097 } 1098 1099 memset(lp, 0, sizeof(struct net_local)); 1100 spin_lock_init(&lp->lock); 1101 1102 printk("(IRQ %d, %s connector, %d-bit bus", dev->irq, 1103 eexp_ifmap[dev->if_port], buswidth?8:16); 1104 1105 if (!request_region(dev->base_addr + 0x300e, 1, "EtherExpress")) 1106 return -EBUSY; 1107 1108 eexp_hw_set_interface(dev); 1109 1110 release_region(dev->base_addr + 0x300e, 1); 1111 1112 /* Find out how much RAM we have on the card */ 1113 outw(0, dev->base_addr + WRITE_PTR); 1114 for (i = 0; i < 32768; i++) 1115 outw(0, dev->base_addr + DATAPORT); 1116 1117 for (memory_size = 0; memory_size < 64; memory_size++) 1118 { 1119 outw(memory_size<<10, dev->base_addr + READ_PTR); 1120 if (inw(dev->base_addr+DATAPORT)) 1121 break; 1122 outw(memory_size<<10, dev->base_addr + WRITE_PTR); 1123 outw(memory_size | 0x5000, dev->base_addr+DATAPORT); 1124 outw(memory_size<<10, dev->base_addr + READ_PTR); 1125 if (inw(dev->base_addr+DATAPORT) != (memory_size | 0x5000)) 1126 break; 1127 } 1128 1129 /* Sort out the number of buffers. We may have 16, 32, 48 or 64k 1130 * of RAM to play with. 1131 */ 1132 lp->num_tx_bufs = 4; 1133 lp->rx_buf_end = 0x3ff6; 1134 switch (memory_size) 1135 { 1136 case 64: 1137 lp->rx_buf_end += 0x4000; 1138 case 48: 1139 lp->num_tx_bufs += 4; 1140 lp->rx_buf_end += 0x4000; 1141 case 32: 1142 lp->rx_buf_end += 0x4000; 1143 case 16: 1144 printk(", %dk RAM)\n", memory_size); 1145 break; 1146 default: 1147 printk(") bad memory size (%dk).\n", memory_size); 1148 return -ENODEV; 1149 break; 1150 } 1151 1152 lp->rx_buf_start = TX_BUF_START + (lp->num_tx_bufs*TX_BUF_SIZE); 1153 lp->width = buswidth; 1154 1155 dev->netdev_ops = &eexp_netdev_ops; 1156 dev->watchdog_timeo = 2*HZ; 1157 1158 return register_netdev(dev); 1159} 1160 1161/* 1162 * Read a word from the EtherExpress on-board serial EEPROM. 1163 * The EEPROM contains 64 words of 16 bits. 1164 */ 1165static unsigned short __init eexp_hw_readeeprom(unsigned short ioaddr, 1166 unsigned char location) 1167{ 1168 unsigned short cmd = 0x180|(location&0x7f); 1169 unsigned short rval = 0,wval = EC_CS|i586_RST; 1170 int i; 1171 1172 outb(EC_CS|i586_RST,ioaddr+EEPROM_Ctrl); 1173 for (i=0x100 ; i ; i>>=1 ) 1174 { 1175 if (cmd&i) 1176 wval |= EC_Wr; 1177 else 1178 wval &= ~EC_Wr; 1179 1180 outb(wval,ioaddr+EEPROM_Ctrl); 1181 outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl); 1182 eeprom_delay(); 1183 outb(wval,ioaddr+EEPROM_Ctrl); 1184 eeprom_delay(); 1185 } 1186 wval &= ~EC_Wr; 1187 outb(wval,ioaddr+EEPROM_Ctrl); 1188 for (i=0x8000 ; i ; i>>=1 ) 1189 { 1190 outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl); 1191 eeprom_delay(); 1192 if (inb(ioaddr+EEPROM_Ctrl)&EC_Rd) 1193 rval |= i; 1194 outb(wval,ioaddr+EEPROM_Ctrl); 1195 eeprom_delay(); 1196 } 1197 wval &= ~EC_CS; 1198 outb(wval|EC_Clk,ioaddr+EEPROM_Ctrl); 1199 eeprom_delay(); 1200 outb(wval,ioaddr+EEPROM_Ctrl); 1201 eeprom_delay(); 1202 return rval; 1203} 1204 1205/* 1206 * Reap tx buffers and return last transmit status. 1207 * if ==0 then either: 1208 * a) we're not transmitting anything, so why are we here? 1209 * b) we've died. 1210 * otherwise, Stat_Busy(return) means we've still got some packets 1211 * to transmit, Stat_Done(return) means our buffers should be empty 1212 * again 1213 */ 1214 1215static unsigned short eexp_hw_lasttxstat(struct net_device *dev) 1216{ 1217 struct net_local *lp = netdev_priv(dev); 1218 unsigned short tx_block = lp->tx_reap; 1219 unsigned short status; 1220 1221 if (!netif_queue_stopped(dev) && lp->tx_head==lp->tx_reap) 1222 return 0x0000; 1223 1224 do 1225 { 1226 outw(tx_block & ~31, dev->base_addr + SM_PTR); 1227 status = inw(dev->base_addr + SHADOW(tx_block)); 1228 if (!Stat_Done(status)) 1229 { 1230 lp->tx_link = tx_block; 1231 return status; 1232 } 1233 else 1234 { 1235 lp->last_tx_restart = 0; 1236 dev->stats.collisions += Stat_NoColl(status); 1237 if (!Stat_OK(status)) 1238 { 1239 char *whatsup = NULL; 1240 dev->stats.tx_errors++; 1241 if (Stat_Abort(status)) 1242 dev->stats.tx_aborted_errors++; 1243 if (Stat_TNoCar(status)) { 1244 whatsup = "aborted, no carrier"; 1245 dev->stats.tx_carrier_errors++; 1246 } 1247 if (Stat_TNoCTS(status)) { 1248 whatsup = "aborted, lost CTS"; 1249 dev->stats.tx_carrier_errors++; 1250 } 1251 if (Stat_TNoDMA(status)) { 1252 whatsup = "FIFO underran"; 1253 dev->stats.tx_fifo_errors++; 1254 } 1255 if (Stat_TXColl(status)) { 1256 whatsup = "aborted, too many collisions"; 1257 dev->stats.tx_aborted_errors++; 1258 } 1259 if (whatsup) 1260 printk(KERN_INFO "%s: transmit %s\n", 1261 dev->name, whatsup); 1262 } 1263 else 1264 dev->stats.tx_packets++; 1265 } 1266 if (tx_block == TX_BUF_START+((lp->num_tx_bufs-1)*TX_BUF_SIZE)) 1267 lp->tx_reap = tx_block = TX_BUF_START; 1268 else 1269 lp->tx_reap = tx_block += TX_BUF_SIZE; 1270 netif_wake_queue(dev); 1271 } 1272 while (lp->tx_reap != lp->tx_head); 1273 1274 lp->tx_link = lp->tx_tail + 0x08; 1275 1276 return status; 1277} 1278 1279/* 1280 * This should never happen. It is called when some higher routine detects 1281 * that the CU has stopped, to try to restart it from the last packet we knew 1282 * we were working on, or the idle loop if we had finished for the time. 1283 */ 1284 1285static void eexp_hw_txrestart(struct net_device *dev) 1286{ 1287 struct net_local *lp = netdev_priv(dev); 1288 unsigned short ioaddr = dev->base_addr; 1289 1290 lp->last_tx_restart = lp->tx_link; 1291 scb_wrcbl(dev, lp->tx_link); 1292 scb_command(dev, SCB_CUstart); 1293 outb(0,ioaddr+SIGNAL_CA); 1294 1295 { 1296 unsigned short boguscount=50,failcount=5; 1297 while (!scb_status(dev)) 1298 { 1299 if (!--boguscount) 1300 { 1301 if (--failcount) 1302 { 1303 printk(KERN_WARNING "%s: CU start timed out, status %04x, cmd %04x\n", dev->name, scb_status(dev), scb_rdcmd(dev)); 1304 scb_wrcbl(dev, lp->tx_link); 1305 scb_command(dev, SCB_CUstart); 1306 outb(0,ioaddr+SIGNAL_CA); 1307 boguscount = 100; 1308 } 1309 else 1310 { 1311 printk(KERN_WARNING "%s: Failed to restart CU, resetting board...\n",dev->name); 1312 eexp_hw_init586(dev); 1313 netif_wake_queue(dev); 1314 return; 1315 } 1316 } 1317 } 1318 } 1319} 1320 1321/* 1322 * Writes down the list of transmit buffers into card memory. Each 1323 * entry consists of an 82586 transmit command, followed by a jump 1324 * pointing to itself. When we want to transmit a packet, we write 1325 * the data into the appropriate transmit buffer and then modify the 1326 * preceding jump to point at the new transmit command. This means that 1327 * the 586 command unit is continuously active. 1328 */ 1329 1330static void eexp_hw_txinit(struct net_device *dev) 1331{ 1332 struct net_local *lp = netdev_priv(dev); 1333 unsigned short tx_block = TX_BUF_START; 1334 unsigned short curtbuf; 1335 unsigned short ioaddr = dev->base_addr; 1336 1337 for ( curtbuf=0 ; curtbuf<lp->num_tx_bufs ; curtbuf++ ) 1338 { 1339 outw(tx_block, ioaddr + WRITE_PTR); 1340 1341 outw(0x0000, ioaddr + DATAPORT); 1342 outw(Cmd_INT|Cmd_Xmit, ioaddr + DATAPORT); 1343 outw(tx_block+0x08, ioaddr + DATAPORT); 1344 outw(tx_block+0x0e, ioaddr + DATAPORT); 1345 1346 outw(0x0000, ioaddr + DATAPORT); 1347 outw(0x0000, ioaddr + DATAPORT); 1348 outw(tx_block+0x08, ioaddr + DATAPORT); 1349 1350 outw(0x8000, ioaddr + DATAPORT); 1351 outw(-1, ioaddr + DATAPORT); 1352 outw(tx_block+0x16, ioaddr + DATAPORT); 1353 outw(0x0000, ioaddr + DATAPORT); 1354 1355 tx_block += TX_BUF_SIZE; 1356 } 1357 lp->tx_head = TX_BUF_START; 1358 lp->tx_reap = TX_BUF_START; 1359 lp->tx_tail = tx_block - TX_BUF_SIZE; 1360 lp->tx_link = lp->tx_tail + 0x08; 1361 lp->rx_buf_start = tx_block; 1362 1363} 1364 1365/* 1366 * Write the circular list of receive buffer descriptors to card memory. 1367 * The end of the list isn't marked, which means that the 82586 receive 1368 * unit will loop until buffers become available (this avoids it giving us 1369 * "out of resources" messages). 1370 */ 1371 1372static void eexp_hw_rxinit(struct net_device *dev) 1373{ 1374 struct net_local *lp = netdev_priv(dev); 1375 unsigned short rx_block = lp->rx_buf_start; 1376 unsigned short ioaddr = dev->base_addr; 1377 1378 lp->num_rx_bufs = 0; 1379 lp->rx_first = lp->rx_ptr = rx_block; 1380 do 1381 { 1382 lp->num_rx_bufs++; 1383 1384 outw(rx_block, ioaddr + WRITE_PTR); 1385 1386 outw(0, ioaddr + DATAPORT); outw(0, ioaddr+DATAPORT); 1387 outw(rx_block + RX_BUF_SIZE, ioaddr+DATAPORT); 1388 outw(0xffff, ioaddr+DATAPORT); 1389 1390 outw(0x0000, ioaddr+DATAPORT); 1391 outw(0xdead, ioaddr+DATAPORT); 1392 outw(0xdead, ioaddr+DATAPORT); 1393 outw(0xdead, ioaddr+DATAPORT); 1394 outw(0xdead, ioaddr+DATAPORT); 1395 outw(0xdead, ioaddr+DATAPORT); 1396 outw(0xdead, ioaddr+DATAPORT); 1397 1398 outw(0x0000, ioaddr+DATAPORT); 1399 outw(rx_block + RX_BUF_SIZE + 0x16, ioaddr+DATAPORT); 1400 outw(rx_block + 0x20, ioaddr+DATAPORT); 1401 outw(0, ioaddr+DATAPORT); 1402 outw(RX_BUF_SIZE-0x20, ioaddr+DATAPORT); 1403 1404 lp->rx_last = rx_block; 1405 rx_block += RX_BUF_SIZE; 1406 } while (rx_block <= lp->rx_buf_end-RX_BUF_SIZE); 1407 1408 1409 /* Make first Rx frame descriptor point to first Rx buffer 1410 descriptor */ 1411 outw(lp->rx_first + 6, ioaddr+WRITE_PTR); 1412 outw(lp->rx_first + 0x16, ioaddr+DATAPORT); 1413 1414 /* Close Rx frame descriptor ring */ 1415 outw(lp->rx_last + 4, ioaddr+WRITE_PTR); 1416 outw(lp->rx_first, ioaddr+DATAPORT); 1417 1418 /* Close Rx buffer descriptor ring */ 1419 outw(lp->rx_last + 0x16 + 2, ioaddr+WRITE_PTR); 1420 outw(lp->rx_first + 0x16, ioaddr+DATAPORT); 1421 1422} 1423 1424/* 1425 * Un-reset the 586, and start the configuration sequence. We don't wait for 1426 * this to finish, but allow the interrupt handler to start the CU and RU for 1427 * us. We can't start the receive/transmission system up before we know that 1428 * the hardware is configured correctly. 1429 */ 1430 1431static void eexp_hw_init586(struct net_device *dev) 1432{ 1433 struct net_local *lp = netdev_priv(dev); 1434 unsigned short ioaddr = dev->base_addr; 1435 int i; 1436 1437#if NET_DEBUG > 6 1438 printk("%s: eexp_hw_init586()\n", dev->name); 1439#endif 1440 1441 lp->started = 0; 1442 1443 set_loopback(dev); 1444 1445 outb(SIRQ_dis|irqrmap[dev->irq],ioaddr+SET_IRQ); 1446 1447 /* Download the startup code */ 1448 outw(lp->rx_buf_end & ~31, ioaddr + SM_PTR); 1449 outw(lp->width?0x0001:0x0000, ioaddr + 0x8006); 1450 outw(0x0000, ioaddr + 0x8008); 1451 outw(0x0000, ioaddr + 0x800a); 1452 outw(0x0000, ioaddr + 0x800c); 1453 outw(0x0000, ioaddr + 0x800e); 1454 1455 for (i = 0; i < ARRAY_SIZE(start_code) * 2; i+=32) { 1456 int j; 1457 outw(i, ioaddr + SM_PTR); 1458 for (j = 0; j < 16 && (i+j)/2 < ARRAY_SIZE(start_code); j+=2) 1459 outw(start_code[(i+j)/2], 1460 ioaddr+0x4000+j); 1461 for (j = 0; j < 16 && (i+j+16)/2 < ARRAY_SIZE(start_code); j+=2) 1462 outw(start_code[(i+j+16)/2], 1463 ioaddr+0x8000+j); 1464 } 1465 1466 /* Do we want promiscuous mode or multicast? */ 1467 outw(CONF_PROMISC & ~31, ioaddr+SM_PTR); 1468 i = inw(ioaddr+SHADOW(CONF_PROMISC)); 1469 outw((dev->flags & IFF_PROMISC)?(i|1):(i & ~1), 1470 ioaddr+SHADOW(CONF_PROMISC)); 1471 lp->was_promisc = dev->flags & IFF_PROMISC; 1472 1473 /* Write our hardware address */ 1474 outw(CONF_HWADDR & ~31, ioaddr+SM_PTR); 1475 outw(((unsigned short *)dev->dev_addr)[0], ioaddr+SHADOW(CONF_HWADDR)); 1476 outw(((unsigned short *)dev->dev_addr)[1], 1477 ioaddr+SHADOW(CONF_HWADDR+2)); 1478 outw(((unsigned short *)dev->dev_addr)[2], 1479 ioaddr+SHADOW(CONF_HWADDR+4)); 1480 1481 eexp_hw_txinit(dev); 1482 eexp_hw_rxinit(dev); 1483 1484 outb(0,ioaddr+EEPROM_Ctrl); 1485 mdelay(5); 1486 1487 scb_command(dev, 0xf000); 1488 outb(0,ioaddr+SIGNAL_CA); 1489 1490 outw(0, ioaddr+SM_PTR); 1491 1492 { 1493 unsigned short rboguscount=50,rfailcount=5; 1494 while (inw(ioaddr+0x4000)) 1495 { 1496 if (!--rboguscount) 1497 { 1498 printk(KERN_WARNING "%s: i82586 reset timed out, kicking...\n", 1499 dev->name); 1500 scb_command(dev, 0); 1501 outb(0,ioaddr+SIGNAL_CA); 1502 rboguscount = 100; 1503 if (!--rfailcount) 1504 { 1505 printk(KERN_WARNING "%s: i82586 not responding, giving up.\n", 1506 dev->name); 1507 return; 1508 } 1509 } 1510 } 1511 } 1512 1513 scb_wrcbl(dev, CONF_LINK); 1514 scb_command(dev, 0xf000|SCB_CUstart); 1515 outb(0,ioaddr+SIGNAL_CA); 1516 1517 { 1518 unsigned short iboguscount=50,ifailcount=5; 1519 while (!scb_status(dev)) 1520 { 1521 if (!--iboguscount) 1522 { 1523 if (--ifailcount) 1524 { 1525 printk(KERN_WARNING "%s: i82586 initialization timed out, status %04x, cmd %04x\n", 1526 dev->name, scb_status(dev), scb_rdcmd(dev)); 1527 scb_wrcbl(dev, CONF_LINK); 1528 scb_command(dev, 0xf000|SCB_CUstart); 1529 outb(0,ioaddr+SIGNAL_CA); 1530 iboguscount = 100; 1531 } 1532 else 1533 { 1534 printk(KERN_WARNING "%s: Failed to initialize i82586, giving up.\n",dev->name); 1535 return; 1536 } 1537 } 1538 } 1539 } 1540 1541 clear_loopback(dev); 1542 outb(SIRQ_en|irqrmap[dev->irq],ioaddr+SET_IRQ); 1543 1544 lp->init_time = jiffies; 1545#if NET_DEBUG > 6 1546 printk("%s: leaving eexp_hw_init586()\n", dev->name); 1547#endif 1548} 1549 1550static void eexp_setup_filter(struct net_device *dev) 1551{ 1552 struct netdev_hw_addr *ha; 1553 unsigned short ioaddr = dev->base_addr; 1554 int count = netdev_mc_count(dev); 1555 int i; 1556 if (count > 8) { 1557 printk(KERN_INFO "%s: too many multicast addresses (%d)\n", 1558 dev->name, count); 1559 count = 8; 1560 } 1561 1562 outw(CONF_NR_MULTICAST & ~31, ioaddr+SM_PTR); 1563 outw(6*count, ioaddr+SHADOW(CONF_NR_MULTICAST)); 1564 i = 0; 1565 netdev_for_each_mc_addr(ha, dev) { 1566 unsigned short *data = (unsigned short *) ha->addr; 1567 1568 if (i == count) 1569 break; 1570 outw((CONF_MULTICAST+(6*i)) & ~31, ioaddr+SM_PTR); 1571 outw(data[0], ioaddr+SHADOW(CONF_MULTICAST+(6*i))); 1572 outw((CONF_MULTICAST+(6*i)+2) & ~31, ioaddr+SM_PTR); 1573 outw(data[1], ioaddr+SHADOW(CONF_MULTICAST+(6*i)+2)); 1574 outw((CONF_MULTICAST+(6*i)+4) & ~31, ioaddr+SM_PTR); 1575 outw(data[2], ioaddr+SHADOW(CONF_MULTICAST+(6*i)+4)); 1576 i++; 1577 } 1578} 1579 1580/* 1581 * Set or clear the multicast filter for this adaptor. 1582 */ 1583static void 1584eexp_set_multicast(struct net_device *dev) 1585{ 1586 unsigned short ioaddr = dev->base_addr; 1587 struct net_local *lp = netdev_priv(dev); 1588 int kick = 0, i; 1589 if ((dev->flags & IFF_PROMISC) != lp->was_promisc) { 1590 outw(CONF_PROMISC & ~31, ioaddr+SM_PTR); 1591 i = inw(ioaddr+SHADOW(CONF_PROMISC)); 1592 outw((dev->flags & IFF_PROMISC)?(i|1):(i & ~1), 1593 ioaddr+SHADOW(CONF_PROMISC)); 1594 lp->was_promisc = dev->flags & IFF_PROMISC; 1595 kick = 1; 1596 } 1597 if (!(dev->flags & IFF_PROMISC)) { 1598 eexp_setup_filter(dev); 1599 if (lp->old_mc_count != netdev_mc_count(dev)) { 1600 kick = 1; 1601 lp->old_mc_count = netdev_mc_count(dev); 1602 } 1603 } 1604 if (kick) { 1605 unsigned long oj; 1606 scb_command(dev, SCB_CUsuspend); 1607 outb(0, ioaddr+SIGNAL_CA); 1608 outb(0, ioaddr+SIGNAL_CA); 1609 oj = jiffies; 1610 while ((SCB_CUstat(scb_status(dev)) == 2) && 1611 (time_before(jiffies, oj + 2000))); 1612 if (SCB_CUstat(scb_status(dev)) == 2) 1613 printk("%s: warning, CU didn't stop\n", dev->name); 1614 lp->started &= ~(STARTED_CU); 1615 scb_wrcbl(dev, CONF_LINK); 1616 scb_command(dev, SCB_CUstart); 1617 outb(0, ioaddr+SIGNAL_CA); 1618 } 1619} 1620 1621 1622/* 1623 * MODULE stuff 1624 */ 1625 1626#ifdef MODULE 1627 1628#define EEXP_MAX_CARDS 4 /* max number of cards to support */ 1629 1630static struct net_device *dev_eexp[EEXP_MAX_CARDS]; 1631static int irq[EEXP_MAX_CARDS]; 1632static int io[EEXP_MAX_CARDS]; 1633 1634module_param_array(io, int, NULL, 0); 1635module_param_array(irq, int, NULL, 0); 1636MODULE_PARM_DESC(io, "EtherExpress 16 I/O base address(es)"); 1637MODULE_PARM_DESC(irq, "EtherExpress 16 IRQ number(s)"); 1638MODULE_LICENSE("GPL"); 1639 1640 1641/* Ideally the user would give us io=, irq= for every card. If any parameters 1642 * are specified, we verify and then use them. If no parameters are given, we 1643 * autoprobe for one card only. 1644 */ 1645int __init init_module(void) 1646{ 1647 struct net_device *dev; 1648 int this_dev, found = 0; 1649 1650 for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) { 1651 dev = alloc_etherdev(sizeof(struct net_local)); 1652 dev->irq = irq[this_dev]; 1653 dev->base_addr = io[this_dev]; 1654 if (io[this_dev] == 0) { 1655 if (this_dev) 1656 break; 1657 printk(KERN_NOTICE "eexpress.c: Module autoprobe not recommended, give io=xx.\n"); 1658 } 1659 if (do_express_probe(dev) == 0) { 1660 dev_eexp[this_dev] = dev; 1661 found++; 1662 continue; 1663 } 1664 printk(KERN_WARNING "eexpress.c: Failed to register card at 0x%x.\n", io[this_dev]); 1665 free_netdev(dev); 1666 break; 1667 } 1668 if (found) 1669 return 0; 1670 return -ENXIO; 1671} 1672 1673void __exit cleanup_module(void) 1674{ 1675 int this_dev; 1676 1677 for (this_dev = 0; this_dev < EEXP_MAX_CARDS; this_dev++) { 1678 struct net_device *dev = dev_eexp[this_dev]; 1679 if (dev) { 1680 unregister_netdev(dev); 1681 free_netdev(dev); 1682 } 1683 } 1684} 1685#endif 1686 1687/* 1688 * Local Variables: 1689 * c-file-style: "linux" 1690 * tab-width: 8 1691 * End: 1692 */ 1693