Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

eepro100.c

Go to the documentation of this file.
00001 /* drivers/net/eepro100.c: An Intel i82557-559 Ethernet driver for Linux. */
00002 /*
00003    NOTICE: this version of the driver is supposed to work with 2.2 kernels.
00004         Written 1996-1999 by Donald Becker.
00005 
00006         This software may be used and distributed according to the terms
00007         of the GNU Public License, incorporated herein by reference.
00008 
00009         This driver is for the Intel EtherExpress Pro100 (Speedo3) design.
00010         It should work with all i82557/558/559 boards.
00011 
00012         To use as a module, use the compile-command at the end of the file.
00013 
00014         The author may be reached as becker@CESDIS.usra.edu, or C/O
00015         Center of Excellence in Space Data and Information Sciences
00016            Code 930.5, NASA Goddard Space Flight Center, Greenbelt MD 20771
00017         For updates see
00018                 http://cesdis.gsfc.nasa.gov/linux/drivers/eepro100.html
00019         For installation instructions
00020                 http://cesdis.gsfc.nasa.gov/linux/misc/modules.html
00021         There is a Majordomo mailing list based at
00022                 linux-eepro100@cesdis.gsfc.nasa.gov
00023         
00024         The driver also contains updates by different kernel developers.
00025         This driver clone is maintained by Andrey V. Savochkin <saw@saw.sw.com.sg>.
00026         Please use this email address and linux-kernel mailing list for bug reports.
00027         
00028         Modification history:
00029         2000 Mar 24  Dragan Stancevic <visitor@valinux.com>
00030                 Disabled FC and ER, to avoid lockups when when we get FCP interrupts.
00031         2000 May 27  Andrey Moruga <moruga@sw.com.sg>
00032                 Code duplication for 82559ER support was removed.
00033                 Accurate handling of all supported chips was implemented.
00034                 Some fixes in 2.3 clone of the driver were ported.
00035         2000 May 30  Dragan Stancevic <visitor@valinux.com> and
00036                                  Andrey Moruga <moruga@sw.com.sg>
00037                 Honor PortReset timing specification.
00038         2000 Jul 25  Dragan Stancevic <visitor@valinux.com>
00039                 Changed to MMIO, resized FIFOs, resized rings, changed ISR timeout
00040                 Problem reported by:
00041                 Marc MERLIN <merlin@valinux.com>
00042         2000 Nov 15  Dragan Stancevic <visitor@valinux.com>
00043                 Changed command completion time and added debug info as to which
00044                 CMD timed out. Problem reported by:
00045                 "Ulrich Windl" <Ulrich.Windl@rz.uni-regensburg.de>
00046         2002 Jan 21  Neale Banks <neale@lowendale.com.au>
00047                 Gracefully handle the case where init_etherdev() returns NULL
00048 */
00049 
00050 /*#define USE_IO*/
00051 static const char *version =
00052 "eepro100.c:v1.09j-t 9/29/99 Donald Becker http://cesdis.gsfc.nasa.gov/linux/drivers/eepro100.html\n"
00053 "eepro100.c: $Revision: 1.20.2.10 $ 2000/05/31 Modified by Andrey V. Savochkin <saw@saw.sw.com.sg> and others\n"
00054 "eepro100.c: VA Linux custom, Dragan Stancevic <visitor@valinux.com> 2000/11/15\n";
00055 
00056 /* A few user-configurable values that apply to all boards.
00057    First set is undocumented and spelled per Intel recommendations. */
00058 
00059 static int congenb = 0;         /* Enable congestion control in the DP83840. */
00060 static int txfifo = 0;          /* Tx FIFO threshold in 4 byte units, 0-15 */
00061 static int rxfifo = 0xF;                /* Rx FIFO threshold, default 32 bytes. */
00062 /* Tx/Rx DMA burst length, 0-127, 0 == no preemption, tx==128 -> disabled. */
00063 static int txdmacount = 128;
00064 static int rxdmacount = 0;
00065 
00066 /* Set the copy breakpoint for the copy-only-tiny-buffer Rx method.
00067    Lower values use more memory, but are faster. */
00068 #if defined(__alpha__) || defined(__sparc__)
00069 /* force copying of all packets to avoid unaligned accesses on Alpha */
00070 static int rx_copybreak = 1518;
00071 #else
00072 static int rx_copybreak = 200;
00073 #endif
00074 
00075 /* Maximum events (Rx packets, etc.) to handle at each interrupt. */
00076 static int max_interrupt_work = 200;
00077 
00078 /* Maximum number of multicast addresses to filter (vs. rx-all-multicast) */
00079 static int multicast_filter_limit = 64;
00080 
00081 /* 'options' is used to pass a transceiver override or full-duplex flag
00082    e.g. "options=16" for FD, "options=32" for 100mbps-only. */
00083 static int full_duplex[] = {-1, -1, -1, -1, -1, -1, -1, -1};
00084 static int options[] = {-1, -1, -1, -1, -1, -1, -1, -1};
00085 #ifdef MODULE
00086 static int debug = -1;                  /* The debug level */
00087 #endif
00088 
00089 /* A few values that may be tweaked. */
00090 /* The ring sizes should be a power of two for efficiency. */
00091 #define TX_RING_SIZE    64
00092 #define RX_RING_SIZE    64
00093 /* How much slots multicast filter setup may take.
00094    Do not descrease without changing set_rx_mode() implementaion. */
00095 #define TX_MULTICAST_SIZE   2
00096 #define TX_MULTICAST_RESERV (TX_MULTICAST_SIZE*2)
00097 /* Actual number of TX packets queued, must be
00098    <= TX_RING_SIZE-TX_MULTICAST_RESERV. */
00099 #define TX_QUEUE_LIMIT  (TX_RING_SIZE-TX_MULTICAST_RESERV)
00100 /* Hysteresis marking queue as no longer full. */
00101 #define TX_QUEUE_UNFULL (TX_QUEUE_LIMIT-4)
00102 
00103 /* Operational parameters that usually are not changed. */
00104 
00105 /* Time in jiffies before concluding the transmitter is hung. */
00106 #define TX_TIMEOUT              (2*HZ)
00107 /* Size of an pre-allocated Rx buffer: <Ethernet MTU> + slack.*/
00108 #define PKT_BUF_SZ              1536
00109 
00110 #if !defined(__OPTIMIZE__)  ||  !defined(__KERNEL__)
00111 #warning  You must compile this file with the correct options!
00112 #warning  See the last lines of the source file.
00113 #error You must compile this driver with "-O".
00114 #endif
00115 
00116 #include <linux/version.h>
00117 #include <linux/module.h>
00118 #if defined(MODVERSIONS)
00119 #include <linux/modversions.h>
00120 #endif
00121 
00122 #include <linux/kernel.h>
00123 #include <linux/string.h>
00124 #include <linux/timer.h>
00125 #include <linux/errno.h>
00126 #include <linux/ioport.h>
00127 #include <linux/malloc.h>
00128 #include <linux/interrupt.h>
00129 #include <linux/pci.h>
00130 #include <asm/spinlock.h>
00131 
00132 #include <asm/bitops.h>
00133 #include <asm/io.h>
00134 
00135 #include <linux/netdevice.h>
00136 #include <linux/etherdevice.h>
00137 #include <linux/skbuff.h>
00138 #include <linux/delay.h>
00139 
00140 #if defined(MODULE)
00141 MODULE_AUTHOR("Maintainer: Andrey V. Savochkin <saw@saw.sw.com.sg>");
00142 MODULE_DESCRIPTION("Intel i82557/i82558 PCI EtherExpressPro driver");
00143 MODULE_PARM(debug, "i");
00144 MODULE_PARM(options, "1-" __MODULE_STRING(8) "i");
00145 MODULE_PARM(full_duplex, "1-" __MODULE_STRING(8) "i");
00146 MODULE_PARM(congenb, "i");
00147 MODULE_PARM(txfifo, "i");
00148 MODULE_PARM(rxfifo, "i");
00149 MODULE_PARM(txdmacount, "i");
00150 MODULE_PARM(rxdmacount, "i");
00151 MODULE_PARM(rx_copybreak, "i");
00152 MODULE_PARM(max_interrupt_work, "i");
00153 MODULE_PARM(multicast_filter_limit, "i");
00154 #endif
00155 
00156 #define RUN_AT(x) (jiffies + (x))
00157 /* Condensed bus+endian portability operations. */
00158 #define virt_to_le32desc(addr)  cpu_to_le32(virt_to_bus(addr))
00159 #define le32desc_to_virt(addr)  bus_to_virt(le32_to_cpu(addr))
00160 
00161 #define net_device              device
00162 #define pci_base_address(p, n)  (p)->base_address[n]
00163 
00164 #define dev_free_skb(skb)       dev_kfree_skb(skb);
00165 #define netif_wake_queue(dev)   do { \
00166                                                                         clear_bit(0, (void*)&dev->tbusy); \
00167                                                                         mark_bh(NET_BH); \
00168                                                                 } while(0)
00169 #define netif_start_queue(dev)  clear_bit(0, (void*)&dev->tbusy)
00170 #define netif_stop_queue(dev)   set_bit(0, (void*)&dev->tbusy)
00171 #ifndef PCI_DEVICE_ID_INTEL_82559ER
00172 #define PCI_DEVICE_ID_INTEL_82559ER 0x1209
00173 #endif
00174 #ifndef PCI_DEVICE_ID_INTEL_ID1029
00175 #define PCI_DEVICE_ID_INTEL_ID1029 0x1029
00176 #endif
00177 #ifndef PCI_DEVICE_ID_INTEL_ID1030
00178 #define PCI_DEVICE_ID_INTEL_ID1030 0x1030
00179 #endif
00180 #ifndef PCI_DEVICE_ID_INTEL_ID1031
00181 #define PCI_DEVICE_ID_INTEL_ID1031 0x1031
00182 #endif
00183 #ifndef PCI_DEVICE_ID_INTEL_ID2449
00184 #define PCI_DEVICE_ID_INTEL_ID2449 0x2449
00185 #endif
00186 
00187 /* The total I/O port extent of the board.
00188    The registers beyond 0x18 only exist on the i82558. */
00189 #define SPEEDO3_TOTAL_SIZE 0x20
00190 
00191 int speedo_debug = 1;
00192 
00193 /*
00194                                 Theory of Operation
00195 
00196 I. Board Compatibility
00197 
00198 This device driver is designed for the Intel i82557 "Speedo3" chip, Intel's
00199 single-chip fast Ethernet controller for PCI, as used on the Intel
00200 EtherExpress Pro 100 adapter.
00201 
00202 II. Board-specific settings
00203 
00204 PCI bus devices are configured by the system at boot time, so no jumpers
00205 need to be set on the board.  The system BIOS should be set to assign the
00206 PCI INTA signal to an otherwise unused system IRQ line.  While it's
00207 possible to share PCI interrupt lines, it negatively impacts performance and
00208 only recent kernels support it.
00209 
00210 III. Driver operation
00211 
00212 IIIA. General
00213 The Speedo3 is very similar to other Intel network chips, that is to say
00214 "apparently designed on a different planet".  This chips retains the complex
00215 Rx and Tx descriptors and multiple buffers pointers as previous chips, but
00216 also has simplified Tx and Rx buffer modes.  This driver uses the "flexible"
00217 Tx mode, but in a simplified lower-overhead manner: it associates only a
00218 single buffer descriptor with each frame descriptor.
00219 
00220 Despite the extra space overhead in each receive skbuff, the driver must use
00221 the simplified Rx buffer mode to assure that only a single data buffer is
00222 associated with each RxFD. The driver implements this by reserving space
00223 for the Rx descriptor at the head of each Rx skbuff.
00224 
00225 The Speedo-3 has receive and command unit base addresses that are added to
00226 almost all descriptor pointers.  The driver sets these to zero, so that all
00227 pointer fields are absolute addresses.
00228 
00229 The System Control Block (SCB) of some previous Intel chips exists on the
00230 chip in both PCI I/O and memory space.  This driver uses the I/O space
00231 registers, but might switch to memory mapped mode to better support non-x86
00232 processors.
00233 
00234 IIIB. Transmit structure
00235 
00236 The driver must use the complex Tx command+descriptor mode in order to
00237 have a indirect pointer to the skbuff data section.  Each Tx command block
00238 (TxCB) is associated with two immediately appended Tx Buffer Descriptor
00239 (TxBD).  A fixed ring of these TxCB+TxBD pairs are kept as part of the
00240 speedo_private data structure for each adapter instance.
00241 
00242 The newer i82558 explicitly supports this structure, and can read the two
00243 TxBDs in the same PCI burst as the TxCB.
00244 
00245 This ring structure is used for all normal transmit packets, but the
00246 transmit packet descriptors aren't long enough for most non-Tx commands such
00247 as CmdConfigure.  This is complicated by the possibility that the chip has
00248 already loaded the link address in the previous descriptor.  So for these
00249 commands we convert the next free descriptor on the ring to a NoOp, and point
00250 that descriptor's link to the complex command.
00251 
00252 An additional complexity of these non-transmit commands are that they may be
00253 added asynchronous to the normal transmit queue, so we disable interrupts
00254 whenever the Tx descriptor ring is manipulated.
00255 
00256 A notable aspect of these special configure commands is that they do
00257 work with the normal Tx ring entry scavenge method.  The Tx ring scavenge
00258 is done at interrupt time using the 'dirty_tx' index, and checking for the
00259 command-complete bit.  While the setup frames may have the NoOp command on the
00260 Tx ring marked as complete, but not have completed the setup command, this
00261 is not a problem.  The tx_ring entry can be still safely reused, as the
00262 tx_skbuff[] entry is always empty for config_cmd and mc_setup frames.
00263 
00264 Commands may have bits set e.g. CmdSuspend in the command word to either
00265 suspend or stop the transmit/command unit.  This driver always flags the last
00266 command with CmdSuspend, erases the CmdSuspend in the previous command, and
00267 then issues a CU_RESUME.
00268 Note: Watch out for the potential race condition here: imagine
00269         erasing the previous suspend
00270                 the chip processes the previous command
00271                 the chip processes the final command, and suspends
00272         doing the CU_RESUME
00273                 the chip processes the next-yet-valid post-final-command.
00274 So blindly sending a CU_RESUME is only safe if we do it immediately after
00275 after erasing the previous CmdSuspend, without the possibility of an
00276 intervening delay.  Thus the resume command is always within the
00277 interrupts-disabled region.  This is a timing dependence, but handling this
00278 condition in a timing-independent way would considerably complicate the code.
00279 
00280 Note: In previous generation Intel chips, restarting the command unit was a
00281 notoriously slow process.  This is presumably no longer true.
00282 
00283 IIIC. Receive structure
00284 
00285 Because of the bus-master support on the Speedo3 this driver uses the new
00286 SKBUFF_RX_COPYBREAK scheme, rather than a fixed intermediate receive buffer.
00287 This scheme allocates full-sized skbuffs as receive buffers.  The value
00288 SKBUFF_RX_COPYBREAK is used as the copying breakpoint: it is chosen to
00289 trade-off the memory wasted by passing the full-sized skbuff to the queue
00290 layer for all frames vs. the copying cost of copying a frame to a
00291 correctly-sized skbuff.
00292 
00293 For small frames the copying cost is negligible (esp. considering that we
00294 are pre-loading the cache with immediately useful header information), so we
00295 allocate a new, minimally-sized skbuff.  For large frames the copying cost
00296 is non-trivial, and the larger copy might flush the cache of useful data, so
00297 we pass up the skbuff the packet was received into.
00298 
00299 IV. Notes
00300 
00301 Thanks to Steve Williams of Intel for arranging the non-disclosure agreement
00302 that stated that I could disclose the information.  But I still resent
00303 having to sign an Intel NDA when I'm helping Intel sell their own product!
00304 
00305 */
00306 
00307 /* This table drives the PCI probe routines. */
00308 static struct net_device *speedo_found1(struct pci_dev *pdev, int pci_bus, 
00309                                                                                 int pci_devfn, long ioaddr, 
00310                                                                                 int chip_idx, int card_idx);
00311 
00312 #ifdef USE_IO
00313 #define SPEEDO_IOTYPE   PCI_USES_MASTER|PCI_USES_IO|PCI_ADDR1
00314 #define SPEEDO_SIZE             32
00315 #else
00316 #define SPEEDO_IOTYPE   PCI_USES_MASTER|PCI_USES_MEM|PCI_ADDR0
00317 #define SPEEDO_SIZE             0x1000
00318 #endif
00319 
00320 enum pci_flags_bit {
00321         PCI_USES_IO=1, PCI_USES_MEM=2, PCI_USES_MASTER=4,
00322         PCI_ADDR0=0x10<<0, PCI_ADDR1=0x10<<1, PCI_ADDR2=0x10<<2, PCI_ADDR3=0x10<<3,
00323 };
00324 struct pci_id_info {
00325         const char *name;
00326         u16     vendor_id, device_id;
00327         int pci_index;
00328 } static pci_tbl[] = {
00329         { "Intel PCI EtherExpress Pro100 82557",
00330           PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82557,
00331           0
00332         },
00333         { "Intel PCI EtherExpress Pro100 82559ER",
00334           PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82559ER,
00335           0
00336         },
00337         { "Intel PCI EtherExpress Pro100 ID1029",
00338           PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ID1029,
00339           0 
00340         },
00341         { "Intel Corporation 82559 InBusiness 10/100",
00342           PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ID1030,
00343           0
00344         },
00345         { "Intel Pro/100 VE",
00346           PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ID1031,
00347           0 
00348         },
00349         { "Intel PCI EtherExpress Pro100 82562EM",
00350           PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ID2449,
00351           0
00352         },
00353         {0,}                                            /* 0 terminated list. */
00354 };
00355 
00356 static inline unsigned int io_inw(unsigned long port)
00357 {
00358         return inw(port);
00359 }
00360 static inline void io_outw(unsigned int val, unsigned long port)
00361 {
00362         outw(val, port);
00363 }
00364 
00365 #ifndef USE_IO
00366 #undef inb
00367 #undef inw
00368 #undef inl
00369 #undef outb
00370 #undef outw
00371 #undef outl
00372 #define inb readb
00373 #define inw readw
00374 #define inl readl
00375 #define outb writeb
00376 #define outw writew
00377 #define outl writel
00378 #endif
00379 
00380 /* How to wait for the command unit to accept a command.
00381    Typically this takes 0 ticks. */
00382 static inline void wait_for_cmd_done(long cmd_ioaddr)
00383 {
00384         int wait = 20000;
00385         char cmd_reg1, cmd_reg2;
00386         do   ;
00387         while((cmd_reg1 = inb(cmd_ioaddr)) && (--wait >= 0));
00388 
00389         /* Last chance to change your mind --Dragan*/
00390         if (wait < 0){
00391                 cmd_reg2 = inb(cmd_ioaddr);
00392                 if(cmd_reg2){
00393                         printk(KERN_ALERT "eepro100: cmd_wait for(%#2.2x) timedout with(%#2.2x)!\n",
00394                                 cmd_reg1, cmd_reg2);
00395                 
00396                 }
00397         }
00398 
00399 }
00400 
00401 /* Offsets to the various registers.
00402    All accesses need not be longword aligned. */
00403 enum speedo_offsets {
00404         SCBStatus = 0, SCBCmd = 2,      /* Rx/Command Unit command and status. */
00405         SCBPointer = 4,                         /* General purpose pointer. */
00406         SCBPort = 8,                            /* Misc. commands and operands.  */
00407         SCBflash = 12, SCBeeprom = 14, /* EEPROM and flash memory control. */
00408         SCBCtrlMDI = 16,                        /* MDI interface control. */
00409         SCBEarlyRx = 20,                        /* Early receive byte count. */
00410 };
00411 /* Commands that can be put in a command list entry. */
00412 enum commands {
00413         CmdNOp = 0, CmdIASetup = 0x10000, CmdConfigure = 0x20000,
00414         CmdMulticastList = 0x30000, CmdTx = 0x40000, CmdTDR = 0x50000,
00415         CmdDump = 0x60000, CmdDiagnose = 0x70000,
00416         CmdSuspend = 0x40000000,        /* Suspend after completion. */
00417         CmdIntr = 0x20000000,           /* Interrupt after completion. */
00418         CmdTxFlex = 0x00080000,         /* Use "Flexible mode" for CmdTx command. */
00419 };
00420 /* Clear CmdSuspend (1<<30) avoiding interference with the card access to the
00421    status bits.  Previous driver versions used separate 16 bit fields for
00422    commands and statuses.  --SAW
00423  */
00424 #if defined(__LITTLE_ENDIAN)
00425 #define clear_suspend(cmd)  ((__u16 *)&(cmd)->cmd_status)[1] &= ~0x4000
00426 #elif defined(__BIG_ENDIAN)
00427 #define clear_suspend(cmd)  ((__u16 *)&(cmd)->cmd_status)[1] &= ~0x0040
00428 #else
00429 #error Unsupported byteorder
00430 #endif
00431 
00432 enum SCBCmdBits {
00433      SCBMaskCmdDone=0x8000, SCBMaskRxDone=0x4000, SCBMaskCmdIdle=0x2000,
00434      SCBMaskRxSuspend=0x1000, SCBMaskEarlyRx=0x0800, SCBMaskFlowCtl=0x0400,
00435      SCBTriggerIntr=0x0200, SCBMaskAll=0x0100,
00436      /* The rest are Rx and Tx commands. */
00437      CUStart=0x0010, CUResume=0x0020, CUStatsAddr=0x0040, CUShowStats=0x0050,
00438      CUCmdBase=0x0060,  /* CU Base address (set to zero) . */
00439      CUDumpStats=0x0070, /* Dump then reset stats counters. */
00440      RxStart=0x0001, RxResume=0x0002, RxAbort=0x0004, RxAddrLoad=0x0006,
00441      RxResumeNoResources=0x0007,
00442 };
00443 
00444 enum SCBPort_cmds {
00445         PortReset=0, PortSelfTest=1, PortPartialReset=2, PortDump=3,
00446 };
00447 
00448 /* The Speedo3 Rx and Tx frame/buffer descriptors. */
00449 struct descriptor {                         /* A generic descriptor. */
00450         s32 cmd_status;                         /* All command and status fields. */
00451         u32 link;                                   /* struct descriptor *  */
00452         unsigned char params[0];
00453 };
00454 
00455 /* The Speedo3 Rx and Tx buffer descriptors. */
00456 struct RxFD {                                   /* Receive frame descriptor. */
00457         s32 status;
00458         u32 link;                                       /* struct RxFD * */
00459         u32 rx_buf_addr;                        /* void * */
00460         u32 count;
00461 };
00462 
00463 /* Selected elements of the Tx/RxFD.status word. */
00464 enum RxFD_bits {
00465         RxComplete=0x8000, RxOK=0x2000,
00466         RxErrCRC=0x0800, RxErrAlign=0x0400, RxErrTooBig=0x0200, RxErrSymbol=0x0010,
00467         RxEth2Type=0x0020, RxNoMatch=0x0004, RxNoIAMatch=0x0002,
00468         TxUnderrun=0x1000,  StatusComplete=0x8000,
00469 };
00470 
00471 struct TxFD {                                   /* Transmit frame descriptor set. */
00472         s32 status;
00473         u32 link;                                       /* void * */
00474         u32 tx_desc_addr;                       /* Always points to the tx_buf_addr element. */
00475         s32 count;                                      /* # of TBD (=1), Tx start thresh., etc. */
00476         /* This constitutes two "TBD" entries -- we only use one. */
00477         u32 tx_buf_addr0;                       /* void *, frame to be transmitted.  */
00478         s32 tx_buf_size0;                       /* Length of Tx frame. */
00479         u32 tx_buf_addr1;                       /* void *, frame to be transmitted.  */
00480         s32 tx_buf_size1;                       /* Length of Tx frame. */
00481 };
00482 
00483 /* Multicast filter setting block.  --SAW */
00484 struct speedo_mc_block {
00485         struct speedo_mc_block *next;
00486         unsigned int tx;
00487         struct descriptor frame __attribute__ ((__aligned__(16)));
00488 };
00489 
00490 /* Elements of the dump_statistics block. This block must be lword aligned. */
00491 struct speedo_stats {
00492         u32 tx_good_frames;
00493         u32 tx_coll16_errs;
00494         u32 tx_late_colls;
00495         u32 tx_underruns;
00496         u32 tx_lost_carrier;
00497         u32 tx_deferred;
00498         u32 tx_one_colls;
00499         u32 tx_multi_colls;
00500         u32 tx_total_colls;
00501         u32 rx_good_frames;
00502         u32 rx_crc_errs;
00503         u32 rx_align_errs;
00504         u32 rx_resource_errs;
00505         u32 rx_overrun_errs;
00506         u32 rx_colls_errs;
00507         u32 rx_runt_errs;
00508         u32 done_marker;
00509 };
00510 
00511 enum Rx_ring_state_bits {
00512         RrNoMem=1, RrPostponed=2, RrNoResources=4, RrOOMReported=8,
00513 };
00514 
00515 /* Do not change the position (alignment) of the first few elements!
00516    The later elements are grouped for cache locality. */
00517 struct speedo_private {
00518         struct TxFD     tx_ring[TX_RING_SIZE];  /* Commands (usually CmdTxPacket). */
00519         struct RxFD *rx_ringp[RX_RING_SIZE];    /* Rx descriptor, used as ring. */
00520         /* The addresses of a Tx/Rx-in-place packets/buffers. */
00521         struct sk_buff* tx_skbuff[TX_RING_SIZE];
00522         struct sk_buff* rx_skbuff[RX_RING_SIZE];
00523         struct descriptor  *last_cmd;   /* Last command sent. */
00524         unsigned int cur_tx, dirty_tx;  /* The ring entries to be free()ed. */
00525         spinlock_t lock;                                /* Group with Tx control cache line. */
00526         u32 tx_threshold;                                       /* The value for txdesc.count. */
00527         struct RxFD *last_rxf;  /* Last command sent. */
00528         unsigned int cur_rx, dirty_rx;          /* The next free ring entry */
00529         long last_rx_time;                      /* Last Rx, in jiffies, to handle Rx hang. */
00530         const char *product_name;
00531         struct net_device *next_module;
00532         void *priv_addr;                                        /* Unaligned address for kfree */
00533         struct enet_statistics stats;
00534         struct speedo_stats lstats;
00535         int chip_id;
00536         unsigned char pci_bus, pci_devfn, acpi_pwr;
00537         struct timer_list timer;        /* Media selection timer. */
00538         struct speedo_mc_block *mc_setup_head;/* Multicast setup frame list head. */
00539         struct speedo_mc_block *mc_setup_tail;/* Multicast setup frame list tail. */
00540         int in_interrupt;                                       /* Word-aligned dev->interrupt */
00541         char rx_mode;                                           /* Current PROMISC/ALLMULTI setting. */
00542         unsigned int tx_full:1;                         /* The Tx queue is full. */
00543         unsigned int full_duplex:1;                     /* Full-duplex operation requested. */
00544         unsigned int flow_ctrl:1;                       /* Use 802.3x flow control. */
00545         unsigned int rx_bug:1;                          /* Work around receiver hang errata. */
00546         unsigned int rx_bug10:1;                        /* Receiver might hang at 10mbps. */
00547         unsigned int rx_bug100:1;                       /* Receiver might hang at 100mbps. */
00548         unsigned char default_port:8;           /* Last dev->if_port value. */
00549         unsigned char rx_ring_state;            /* RX ring status flags. */
00550         unsigned short phy[2];                          /* PHY media interfaces available. */
00551         unsigned short advertising;                     /* Current PHY advertised caps. */
00552         unsigned short partner;                         /* Link partner caps. */
00553 };
00554 
00555 /* The parameters for a CmdConfigure operation.
00556    There are so many options that it would be difficult to document each bit.
00557    We mostly use the default or recommended settings. */
00558 const char i82557_config_cmd[22] = {
00559         22, 0x08, 0, 0,  0, 0, 0x32, 0x03,  1, /* 1=Use MII  0=Use AUI */
00560         0, 0x2E, 0,  0x60, 0,
00561         0xf2, 0x48,   0, 0x40, 0xf2, 0x80,              /* 0x40=Force full-duplex */
00562         0x3f, 0x05, };
00563 const char i82558_config_cmd[22] = {
00564         22, 0x08, 0, 1,  0, 0, 0x22, 0x03,  1, /* 1=Use MII  0=Use AUI */
00565         0, 0x2E, 0,  0x60, 0x08, 0x88,
00566         0x68, 0, 0x40, 0xf2, 0x84,              /* Disable FC */
00567         0x31, 0x05, };
00568 
00569 /* PHY media interface chips. */
00570 static const char *phys[] = {
00571         "None", "i82553-A/B", "i82553-C", "i82503",
00572         "DP83840", "80c240", "80c24", "i82555",
00573         "unknown-8", "unknown-9", "DP83840A", "unknown-11",
00574         "unknown-12", "unknown-13", "unknown-14", "unknown-15", };
00575 enum phy_chips { NonSuchPhy=0, I82553AB, I82553C, I82503, DP83840, S80C240,
00576                                          S80C24, I82555, DP83840A=10, };
00577 static const char is_mii[] = { 0, 1, 1, 0, 1, 1, 0, 1 };
00578 #define EE_READ_CMD             (6)
00579 
00580 static int do_eeprom_cmd(long ioaddr, int cmd, int cmd_len);
00581 static int mdio_read(long ioaddr, int phy_id, int location);
00582 static int mdio_write(long ioaddr, int phy_id, int location, int value);
00583 static int speedo_open(struct net_device *dev);
00584 static void speedo_resume(struct net_device *dev);
00585 static void speedo_timer(unsigned long data);
00586 static void speedo_init_rx_ring(struct net_device *dev);
00587 static void speedo_tx_timeout(struct net_device *dev);
00588 static int speedo_start_xmit(struct sk_buff *skb, struct net_device *dev);
00589 static void speedo_refill_rx_buffers(struct net_device *dev, int force);
00590 static int speedo_rx(struct net_device *dev);
00591 static void speedo_tx_buffer_gc(struct net_device *dev);
00592 static void speedo_interrupt(int irq, void *dev_instance, struct pt_regs *regs);
00593 static int speedo_close(struct net_device *dev);
00594 static struct enet_statistics *speedo_get_stats(struct net_device *dev);
00595 static int speedo_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
00596 static void set_rx_mode(struct net_device *dev);
00597 static void speedo_show_state(struct net_device *dev);
00598 
00599 
00600 
00601 #ifdef honor_default_port
00602 /* Optional driver feature to allow forcing the transceiver setting.
00603    Not recommended. */
00604 static int mii_ctrl[8] = { 0x3300, 0x3100, 0x0000, 0x0100,
00605                                                    0x2000, 0x2100, 0x0400, 0x3100};
00606 #endif
00607 
00608 /* A list of all installed Speedo devices, for removing the driver module. */
00609 static struct net_device *root_speedo_dev = NULL;
00610 
00611 int eepro100_init(void)
00612 {
00613         int cards_found = 0;
00614         int chip_idx;
00615         struct pci_dev *pdev;
00616 
00617         if (! pcibios_present())
00618                 return cards_found;
00619 
00620         for (chip_idx = 0; pci_tbl[chip_idx].name; chip_idx++) {
00621                 for (; pci_tbl[chip_idx].pci_index < 8; pci_tbl[chip_idx].pci_index++) {
00622                         unsigned char pci_bus, pci_device_fn, pci_latency;
00623                         unsigned long pciaddr;
00624                         long ioaddr;
00625                         int irq;
00626 
00627                         u16 pci_command, new_command;
00628 
00629                         if (pcibios_find_device(pci_tbl[chip_idx].vendor_id,
00630                                                                         pci_tbl[chip_idx].device_id,
00631                                                                         pci_tbl[chip_idx].pci_index, &pci_bus,
00632                                                                         &pci_device_fn))
00633                                 break;
00634                         {
00635                                 pdev = pci_find_slot(pci_bus, pci_device_fn);
00636 #ifdef USE_IO
00637                                 pciaddr = pci_base_address(pdev, 1);    /* Use [0] to mem-map */
00638 #else
00639                                 pciaddr = pci_base_address(pdev, 0);
00640 #endif
00641                                 irq = pdev->irq;
00642                         }
00643                         /* Remove I/O space marker in bit 0. */
00644                         if (pciaddr & 1) {
00645                                 ioaddr = pciaddr & ~3UL;
00646                                 if (check_region(ioaddr, 32))
00647                                         continue;
00648                         } else {
00649 #ifdef __sparc__
00650                                 /* ioremap is hosed in 2.2.x on Sparc. */
00651                                 ioaddr = pciaddr & ~0xfUL;
00652 #else
00653                                 if ((ioaddr = (long)ioremap(pciaddr & ~0xfUL, 0x1000)) == 0) {
00654                                         printk(KERN_INFO "Failed to map PCI address %#lx.\n",
00655                                                    pciaddr);
00656                                         continue;
00657                                 }
00658 #endif
00659                         }
00660                         if (speedo_debug > 2)
00661                                 printk("Found Intel i82557 PCI Speedo at I/O %#lx, IRQ %d.\n",
00662                                            ioaddr, irq);
00663 
00664                         /* Get and check the bus-master and latency values. */
00665                         pcibios_read_config_word(pci_bus, pci_device_fn,
00666                                                                          PCI_COMMAND, &pci_command);
00667                         new_command = pci_command | PCI_COMMAND_MASTER|PCI_COMMAND_IO;
00668                         if (pci_command != new_command) {
00669                                 printk(KERN_INFO "  The PCI BIOS has not enabled this"
00670                                            " device!  Updating PCI command %4.4x->%4.4x.\n",
00671                                            pci_command, new_command);
00672                                 pcibios_write_config_word(pci_bus, pci_device_fn,
00673                                                                                   PCI_COMMAND, new_command);
00674                         }
00675                         pcibios_read_config_byte(pci_bus, pci_device_fn,
00676                                                                          PCI_LATENCY_TIMER, &pci_latency);
00677                         if (pci_latency < 32) {
00678                                 printk("  PCI latency timer (CFLT) is unreasonably low at %d."
00679                                            "  Setting to 32 clocks.\n", pci_latency);
00680                                 pcibios_write_config_byte(pci_bus, pci_device_fn,
00681                                                                                   PCI_LATENCY_TIMER, 32);
00682                         } else if (speedo_debug > 1)
00683                                 printk("  PCI latency timer (CFLT) is %#x.\n", pci_latency);
00684 
00685                         if (speedo_found1(pdev, pci_bus, pci_device_fn, ioaddr, chip_idx, cards_found))
00686                                 cards_found++;
00687                 }
00688         }
00689 
00690         return cards_found;
00691 }
00692 
00693 static struct net_device *speedo_found1(struct pci_dev *pdev, int pci_bus, 
00694                                                                                 int pci_devfn, long ioaddr, 
00695                                                                                 int chip_idx, int card_idx)
00696 {
00697         struct net_device *dev;
00698         struct speedo_private *sp;
00699         const char *product;
00700         int i, option;
00701         u16 eeprom[0x100];
00702         int acpi_idle_state = 0;
00703 #ifndef MODULE
00704         static int did_version = 0;                     /* Already printed version info. */
00705         if (speedo_debug > 0  &&  did_version++ == 0)
00706                 printk(version);
00707 #endif
00708 
00709         dev = init_etherdev(NULL, sizeof(struct speedo_private));
00710 
00711         if (dev == NULL) {
00712                 printk(KERN_ERR "eepro100: Unable to allocate net_device structure!\n");
00713                 return NULL;
00714         }
00715 
00716         if (dev->mem_start > 0)
00717                 option = dev->mem_start;
00718         else if (card_idx >= 0  &&  options[card_idx] >= 0)
00719                 option = options[card_idx];
00720         else
00721                 option = 0;
00722 
00723         /* Read the station address EEPROM before doing the reset.
00724            Nominally his should even be done before accepting the device, but
00725            then we wouldn't have a device name with which to report the error.
00726            The size test is for 6 bit vs. 8 bit address serial EEPROMs.
00727         */
00728         {
00729                 unsigned long iobase;
00730                 int read_cmd, ee_size;
00731                 u16 sum;
00732                 int j;
00733 
00734                 /* Use IO only to avoid postponed writes and satisfy EEPROM timing
00735                    requirements. */
00736                 iobase = pci_base_address(pdev, 1) & ~3UL;
00737                 if ((do_eeprom_cmd(iobase, EE_READ_CMD << 24, 27) & 0xffe0000)
00738                         == 0xffe0000) {
00739                         ee_size = 0x100;
00740                         read_cmd = EE_READ_CMD << 24;
00741                 } else {
00742                         ee_size = 0x40;
00743                         read_cmd = EE_READ_CMD << 22;
00744                 }
00745 
00746                 for (j = 0, i = 0, sum = 0; i < ee_size; i++) {
00747                         u16 value = do_eeprom_cmd(iobase, read_cmd | (i << 16), 27);
00748                         eeprom[i] = value;
00749                         sum += value;
00750                         if (i < 3) {
00751                                 dev->dev_addr[j++] = value;
00752                                 dev->dev_addr[j++] = value >> 8;
00753                         }
00754                 }
00755                 if (sum != 0xBABA)
00756                         printk(KERN_WARNING "%s: Invalid EEPROM checksum %#4.4x, "
00757                                    "check settings before activating this device!\n",
00758                                    dev->name, sum);
00759                 /* Don't  unregister_netdev(dev);  as the EEPro may actually be
00760                    usable, especially if the MAC address is set later.
00761                    On the other hand, it may be unusable if MDI data is corrupted. */
00762         }
00763 
00764         /* Reset the chip: stop Tx and Rx processes and clear counters.
00765            This takes less than 10usec and will easily finish before the next
00766            action. */
00767         outl(PortReset, ioaddr + SCBPort);
00768         inl(ioaddr + SCBPort);
00769         /* Honor PortReset timing. */
00770         udelay(10);
00771 
00772         if (eeprom[3] & 0x0100)
00773                 product = "OEM i82557/i82558 10/100 Ethernet";
00774         else
00775                 product = pci_tbl[chip_idx].name;
00776 
00777         printk(KERN_INFO "%s: %s, ", dev->name, product);
00778 
00779         for (i = 0; i < 5; i++)
00780                 printk("%2.2X:", dev->dev_addr[i]);
00781         printk("%2.2X, ", dev->dev_addr[i]);
00782 #ifdef USE_IO
00783         printk("I/O at %#3lx, ", ioaddr);
00784 #endif
00785         printk("IRQ %d.\n", pdev->irq);
00786 
00787 #if 1 || defined(kernel_bloat)
00788         /* OK, this is pure kernel bloat.  I don't like it when other drivers
00789            waste non-pageable kernel space to emit similar messages, but I need
00790            them for bug reports. */
00791         {
00792                 const char *connectors[] = {" RJ45", " BNC", " AUI", " MII"};
00793                 /* The self-test results must be paragraph aligned. */
00794                 s32 str[6], *volatile self_test_results;
00795                 int boguscnt = 16000;   /* Timeout for set-test. */
00796                 if ((eeprom[3] & 0x03) != 0x03)
00797                         printk(KERN_INFO "  Receiver lock-up bug exists -- enabling"
00798                                    " work-around.\n");
00799                 printk(KERN_INFO "  Board assembly %4.4x%2.2x-%3.3d, Physical"
00800                            " connectors present:",
00801                            eeprom[8], eeprom[9]>>8, eeprom[9] & 0xff);
00802                 for (i = 0; i < 4; i++)
00803                         if (eeprom[5] & (1<<i))
00804                                 printk(connectors[i]);
00805                 printk("\n"KERN_INFO"  Primary interface chip %s PHY #%d.\n",
00806                            phys[(eeprom[6]>>8)&15], eeprom[6] & 0x1f);
00807                 if (eeprom[7] & 0x0700)
00808                         printk(KERN_INFO "    Secondary interface chip %s.\n",
00809                                    phys[(eeprom[7]>>8)&7]);
00810                 if (((eeprom[6]>>8) & 0x3f) == DP83840
00811                         ||  ((eeprom[6]>>8) & 0x3f) == DP83840A) {
00812                         int mdi_reg23 = mdio_read(ioaddr, eeprom[6] & 0x1f, 23) | 0x0422;
00813                         if (congenb)
00814                           mdi_reg23 |= 0x0100;
00815                         printk(KERN_INFO"  DP83840 specific setup, setting register 23 to %4.4x.\n",
00816                                    mdi_reg23);
00817                         mdio_write(ioaddr, eeprom[6] & 0x1f, 23, mdi_reg23);
00818                 }
00819                 if ((option >= 0) && (option & 0x70)) {
00820                         printk(KERN_INFO "  Forcing %dMbs %s-duplex operation.\n",
00821                                    (option & 0x20 ? 100 : 10),
00822                                    (option & 0x10 ? "full" : "half"));
00823                         mdio_write(ioaddr, eeprom[6] & 0x1f, 0,
00824                                            ((option & 0x20) ? 0x2000 : 0) |     /* 100mbps? */
00825                                            ((option & 0x10) ? 0x0100 : 0)); /* Full duplex? */
00826                 }
00827 
00828                 /* Perform a system self-test. */
00829                 self_test_results = (s32*) ((((long) str) + 15) & ~0xf);
00830                 self_test_results[0] = 0;
00831                 self_test_results[1] = -1;
00832                 outl(virt_to_bus(self_test_results) | PortSelfTest, ioaddr + SCBPort);
00833                 do {
00834                         udelay(10);
00835                 } while (self_test_results[1] == -1  &&  --boguscnt >= 0);
00836 
00837                 if (boguscnt < 0) {             /* Test optimized out. */
00838                         printk(KERN_ERR "Self test failed, status %8.8x:\n"
00839                                    KERN_ERR " Failure to initialize the i82557.\n"
00840                                    KERN_ERR " Verify that the card is a bus-master"
00841                                    " capable slot.\n",
00842                                    self_test_results[1]);
00843                 } else
00844                         printk(KERN_INFO "  General self-test: %s.\n"
00845                                    KERN_INFO "  Serial sub-system self-test: %s.\n"
00846                                    KERN_INFO "  Internal registers self-test: %s.\n"
00847                                    KERN_INFO "  ROM checksum self-test: %s (%#8.8x).\n",
00848                                    self_test_results[1] & 0x1000 ? "failed" : "passed",
00849                                    self_test_results[1] & 0x0020 ? "failed" : "passed",
00850                                    self_test_results[1] & 0x0008 ? "failed" : "passed",
00851                                    self_test_results[1] & 0x0004 ? "failed" : "passed",
00852                                    self_test_results[0]);
00853         }
00854 #endif  /* kernel_bloat */
00855 
00856         outl(PortReset, ioaddr + SCBPort);
00857         inl(ioaddr + SCBPort);
00858         /* Honor PortReset timing. */
00859         udelay(10);
00860 
00861         /* We do a request_region() only to register /proc/ioports info. */
00862         request_region(ioaddr, SPEEDO3_TOTAL_SIZE, "Intel Speedo3 Ethernet");
00863 
00864         dev->base_addr = ioaddr;
00865         dev->irq = pdev->irq;
00866 
00867         sp = dev->priv;
00868         if (dev->priv == NULL) {
00869                 void *mem = kmalloc(sizeof(*sp), GFP_KERNEL);
00870                 dev->priv = sp = mem;           /* Cache align here if kmalloc does not. */
00871                 sp->priv_addr = mem;
00872         }
00873         memset(sp, 0, sizeof(*sp));
00874         sp->next_module = root_speedo_dev;
00875         root_speedo_dev = dev;
00876 
00877         sp->pci_bus = pci_bus;
00878         sp->pci_devfn = pci_devfn;
00879         sp->chip_id = chip_idx;
00880         sp->acpi_pwr = acpi_idle_state;
00881 
00882         sp->full_duplex = option >= 0 && (option & 0x10) ? 1 : 0;
00883         if (card_idx >= 0) {
00884                 if (full_duplex[card_idx] >= 0)
00885                         sp->full_duplex = full_duplex[card_idx];
00886         }
00887         sp->default_port = option >= 0 ? (option & 0x0f) : 0;
00888 
00889         sp->phy[0] = eeprom[6];
00890         sp->phy[1] = eeprom[7];
00891         sp->rx_bug = (eeprom[3] & 0x03) == 3 ? 0 : 1;
00892 
00893         if (sp->rx_bug)
00894                 printk(KERN_INFO "  Receiver lock-up workaround activated.\n");
00895 
00896         /* The Speedo-specific entries in the device structure. */
00897         dev->open = &speedo_open;
00898         dev->hard_start_xmit = &speedo_start_xmit;
00899 #if defined(HAS_NETIF_QUEUE)
00900         dev->tx_timeout = &speedo_tx_timeout;
00901         dev->watchdog_timeo = TX_TIMEOUT;
00902 #endif
00903         dev->stop = &speedo_close;
00904         dev->get_stats = &speedo_get_stats;
00905         dev->set_multicast_list = &set_rx_mode;
00906         dev->do_ioctl = &speedo_ioctl;
00907 
00908         return dev;
00909 }
00910 
00911 /* Serial EEPROM section.
00912    A "bit" grungy, but we work our way through bit-by-bit :->. */
00913 /*  EEPROM_Ctrl bits. */
00914 #define EE_SHIFT_CLK    0x01    /* EEPROM shift clock. */
00915 #define EE_CS                   0x02    /* EEPROM chip select. */
00916 #define EE_DATA_WRITE   0x04    /* EEPROM chip data in. */
00917 #define EE_DATA_READ    0x08    /* EEPROM chip data out. */
00918 #define EE_ENB                  (0x4800 | EE_CS)
00919 #define EE_WRITE_0              0x4802
00920 #define EE_WRITE_1              0x4806
00921 #define EE_OFFSET               SCBeeprom
00922 
00923 /* The fixes for the code were kindly provided by Dragan Stancevic
00924    <visitor@valinux.com> to strictly follow Intel specifications of EEPROM
00925    access timing.
00926    The publicly available sheet 64486302 (sec. 3.1) specifies 1us access
00927    interval for serial EEPROM.  However, it looks like that there is an
00928    additional requirement dictating larger udelay's in the code below.
00929    2000/05/24  SAW */
00930 static int do_eeprom_cmd(long ioaddr, int cmd, int cmd_len)
00931 {
00932         unsigned retval = 0;
00933         long ee_addr = ioaddr + SCBeeprom;
00934 
00935         io_outw(EE_ENB, ee_addr); udelay(2);
00936         io_outw(EE_ENB | EE_SHIFT_CLK, ee_addr); udelay(2);
00937 
00938         /* Shift the command bits out. */
00939         do {
00940                 short dataval = (cmd & (1 << cmd_len)) ? EE_WRITE_1 : EE_WRITE_0;
00941                 io_outw(dataval, ee_addr); udelay(2);
00942                 io_outw(dataval | EE_SHIFT_CLK, ee_addr); udelay(2);
00943                 retval = (retval << 1) | ((io_inw(ee_addr) & EE_DATA_READ) ? 1 : 0);
00944         } while (--cmd_len >= 0);
00945         io_outw(EE_ENB, ee_addr); udelay(2);
00946 
00947         /* Terminate the EEPROM access. */
00948         io_outw(EE_ENB & ~EE_CS, ee_addr);
00949         return retval;
00950 }
00951 
00952 static int mdio_read(long ioaddr, int phy_id, int location)
00953 {
00954         int val, boguscnt = 64*10;              /* <64 usec. to complete, typ 27 ticks */
00955         outl(0x08000000 | (location<<16) | (phy_id<<21), ioaddr + SCBCtrlMDI);
00956         do {
00957                 val = inl(ioaddr + SCBCtrlMDI);
00958                 if (--boguscnt < 0) {
00959                         printk(KERN_ERR " mdio_read() timed out with val = %8.8x.\n", val);
00960                         break;
00961                 }
00962         } while (! (val & 0x10000000));
00963         return val & 0xffff;
00964 }
00965 
00966 static int mdio_write(long ioaddr, int phy_id, int location, int value)
00967 {
00968         int val, boguscnt = 64*10;              /* <64 usec. to complete, typ 27 ticks */
00969         outl(0x04000000 | (location<<16) | (phy_id<<21) | value,
00970                  ioaddr + SCBCtrlMDI);
00971         do {
00972                 val = inl(ioaddr + SCBCtrlMDI);
00973                 if (--boguscnt < 0) {
00974                         printk(KERN_ERR" mdio_write() timed out with val = %8.8x.\n", val);
00975                         break;
00976                 }
00977         } while (! (val & 0x10000000));
00978         return val & 0xffff;
00979 }
00980 
00981 
00982 static int
00983 speedo_open(struct net_device *dev)
00984 {
00985         struct speedo_private *sp = (struct speedo_private *)dev->priv;
00986         long ioaddr = dev->base_addr;
00987 
00988         if (speedo_debug > 1)
00989                 printk(KERN_DEBUG "%s: speedo_open() irq %d.\n", dev->name, dev->irq);
00990 
00991         MOD_INC_USE_COUNT;
00992 
00993         /* Set up the Tx queue early.. */
00994         sp->cur_tx = 0;
00995         sp->dirty_tx = 0;
00996         sp->last_cmd = 0;
00997         sp->tx_full = 0;
00998         sp->lock = (spinlock_t) SPIN_LOCK_UNLOCKED;
00999         sp->in_interrupt = 0;
01000 
01001         /* .. we can safely take handler calls during init. */
01002         if (request_irq(dev->irq, &speedo_interrupt, SA_SHIRQ, dev->name, dev)) {
01003                 MOD_DEC_USE_COUNT;
01004                 return -EAGAIN;
01005         }
01006 
01007         dev->if_port = sp->default_port;
01008 
01009 #ifdef oh_no_you_dont_unless_you_honour_the_options_passed_in_to_us
01010         /* Retrigger negotiation to reset previous errors. */
01011         if ((sp->phy[0] & 0x8000) == 0) {
01012                 int phy_addr = sp->phy[0] & 0x1f ;
01013                 /* Use 0x3300 for restarting NWay, other values to force xcvr:
01014                    0x0000 10-HD
01015                    0x0100 10-FD
01016                    0x2000 100-HD
01017                    0x2100 100-FD
01018                 */
01019 #ifdef honor_default_port
01020                 mdio_write(ioaddr, phy_addr, 0, mii_ctrl[dev->default_port & 7]);
01021 #else
01022                 mdio_write(ioaddr, phy_addr, 0, 0x3300);
01023 #endif
01024         }
01025 #endif
01026 
01027         speedo_init_rx_ring(dev);
01028 
01029         /* Fire up the hardware. */
01030         outw(SCBMaskAll, ioaddr + SCBCmd);
01031         speedo_resume(dev);
01032 
01033         dev->interrupt = 0;
01034         dev->start = 1;
01035         netif_start_queue(dev);
01036 
01037         /* Setup the chip and configure the multicast list. */
01038         sp->mc_setup_head = NULL;
01039         sp->mc_setup_tail = NULL;
01040         sp->flow_ctrl = sp->partner = 0;
01041         sp->rx_mode = -1;                       /* Invalid -> always reset the mode. */
01042         set_rx_mode(dev);
01043         if ((sp->phy[0] & 0x8000) == 0)
01044                 sp->advertising = mdio_read(ioaddr, sp->phy[0] & 0x1f, 4);
01045 
01046         if (speedo_debug > 2) {
01047                 printk(KERN_DEBUG "%s: Done speedo_open(), status %8.8x.\n",
01048                            dev->name, inw(ioaddr + SCBStatus));
01049         }
01050 
01051         /* Set the timer.  The timer serves a dual purpose:
01052            1) to monitor the media interface (e.g. link beat) and perhaps switch
01053            to an alternate media type
01054            2) to monitor Rx activity, and restart the Rx process if the receiver
01055            hangs. */
01056         init_timer(&sp->timer);
01057         sp->timer.expires = RUN_AT((24*HZ)/10);                         /* 2.4 sec. */
01058         sp->timer.data = (unsigned long)dev;
01059         sp->timer.function = &speedo_timer;                                     /* timer handler */
01060         add_timer(&sp->timer);
01061 
01062         /* No need to wait for the command unit to accept here. */
01063         if ((sp->phy[0] & 0x8000) == 0)
01064                 mdio_read(ioaddr, sp->phy[0] & 0x1f, 0);
01065 
01066         return 0;
01067 }
01068 
01069 /* Start the chip hardware after a full reset. */
01070 static void speedo_resume(<