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

drivers/net/starfire.c

Go to the documentation of this file.
00001 /* starfire.c: Linux device driver for the Adaptec Starfire network adapter. */
00002 /*
00003         Written 1998-2000 by Donald Becker.
00004 
00005         Current maintainer is Ion Badulescu <ionut@cs.columbia.edu>. Please
00006         send all bug reports to me, and not to Donald Becker, as this code
00007         has been modified quite a bit from Donald's original version.
00008 
00009         This software may be used and distributed according to the terms of
00010         the GNU General Public License (GPL), incorporated herein by reference.
00011         Drivers based on or derived from this code fall under the GPL and must
00012         retain the authorship, copyright and license notice.  This file is not
00013         a complete program and may only be used when the entire operating
00014         system is licensed under the GPL.
00015 
00016         The author may be reached as becker@scyld.com, or C/O
00017         Scyld Computing Corporation
00018         410 Severn Ave., Suite 210
00019         Annapolis MD 21403
00020 
00021         Support and updates available at
00022         http://www.scyld.com/network/starfire.html
00023 
00024         -----------------------------------------------------------
00025 
00026         Linux kernel-specific changes:
00027 
00028         LK1.1.1 (jgarzik):
00029         - Use PCI driver interface
00030         - Fix MOD_xxx races
00031         - softnet fixups
00032 
00033         LK1.1.2 (jgarzik):
00034         - Merge Becker version 0.15
00035 
00036         LK1.1.3 (Andrew Morton)
00037         - Timer cleanups
00038 
00039         LK1.1.4 (jgarzik):
00040         - Merge Becker version 1.03
00041 
00042         LK1.2.1 (Ion Badulescu <ionut@cs.columbia.edu>)
00043         - Support hardware Rx/Tx checksumming
00044         - Use the GFP firmware taken from Adaptec's Netware driver
00045 
00046         LK1.2.2 (Ion Badulescu)
00047         - Backported to 2.2.x
00048 
00049         LK1.2.3 (Ion Badulescu)
00050         - Fix the flaky mdio interface
00051         - More compat clean-ups
00052 
00053         LK1.2.4 (Ion Badulescu)
00054         - More 2.2.x initialization fixes
00055 
00056         LK1.2.5 (Ion Badulescu)
00057         - Several fixes from Manfred Spraul
00058 
00059         LK1.2.6 (Ion Badulescu)
00060         - Fixed ifup/ifdown/ifup problem in 2.4.x
00061 
00062         LK1.2.7 (Ion Badulescu)
00063         - Removed unused code
00064         - Made more functions static and __init
00065 
00066         LK1.2.8 (Ion Badulescu)
00067         - Quell bogus error messages, inform about the Tx threshold
00068         - Removed #ifdef CONFIG_PCI, this driver is PCI only
00069 
00070         LK1.2.9 (Ion Badulescu)
00071         - Merged Jeff Garzik's changes from 2.4.4-pre5
00072         - Added 2.2.x compatibility stuff required by the above changes
00073 
00074         LK1.2.9a (Ion Badulescu)
00075         - More updates from Jeff Garzik
00076 
00077         LK1.3.0 (Ion Badulescu)
00078         - Merged zerocopy support
00079 
00080         LK1.3.1 (Ion Badulescu)
00081         - Added ethtool support
00082         - Added GPIO (media change) interrupt support
00083 
00084         LK1.3.2 (Ion Badulescu)
00085         - Fixed 2.2.x compatibility issues introduced in 1.3.1
00086         - Fixed ethtool ioctl returning uninitialized memory
00087 
00088         LK1.3.3 (Ion Badulescu)
00089         - Initialize the TxMode register properly
00090         - Don't dereference dev->priv after freeing it
00091 
00092         LK1.3.4 (Ion Badulescu)
00093         - Fixed initialization timing problems
00094         - Fixed interrupt mask definitions
00095 
00096         LK1.3.5 (jgarzik)
00097         - ethtool NWAY_RST, GLINK, [GS]MSGLVL support
00098 
00099         LK1.3.6 (Ion Badulescu)
00100         - Sparc64 support and fixes
00101         - Better stats and error handling
00102 
00103 TODO:
00104         - implement tx_timeout() properly
00105         - VLAN support
00106 */
00107 
00108 #define DRV_NAME        "starfire"
00109 #define DRV_VERSION     "1.03+LK1.3.6"
00110 #define DRV_RELDATE     "March 6, 2002"
00111 
00112 #include <linux/version.h>
00113 #include <linux/module.h>
00114 #include <linux/kernel.h>
00115 #include <linux/pci.h>
00116 #include <linux/netdevice.h>
00117 #include <linux/etherdevice.h>
00118 #include <linux/init.h>
00119 #include <linux/delay.h>
00120 #include <asm/processor.h>              /* Processor type for cache alignment. */
00121 #include <asm/uaccess.h>
00122 #include <asm/io.h>
00123 
00124 /*
00125  * Adaptec's license for their Novell drivers (which is where I got the
00126  * firmware files) does not allow one to redistribute them. Thus, we can't
00127  * include the firmware with this driver.
00128  *
00129  * However, an end-user is allowed to download and use it, after
00130  * converting it to C header files using starfire_firmware.pl.
00131  * Once that's done, the #undef below must be changed into a #define
00132  * for this driver to really use the firmware. Note that Rx/Tx
00133  * hardware TCP checksumming is not possible without the firmware.
00134  *
00135  * If Adaptec could allow redistribution of the firmware (even in binary
00136  * format), life would become a lot easier. Unfortunately, I've lost my
00137  * Adaptec contacts, so progress on this front is rather unlikely to
00138  * occur. If anybody from Adaptec reads this and can help with this matter,
00139  * please let me know...
00140  */
00141 #undef HAS_FIRMWARE
00142 /*
00143  * The current frame processor firmware fails to checksum a fragment
00144  * of length 1. If and when this is fixed, the #define below can be removed.
00145  */
00146 #define HAS_BROKEN_FIRMWARE
00147 /*
00148  * Define this if using the driver with the zero-copy patch
00149  */
00150 #if defined(HAS_FIRMWARE) && defined(MAX_SKB_FRAGS)
00151 #define ZEROCOPY
00152 #endif
00153 
00154 #ifdef HAS_FIRMWARE
00155 #include "starfire_firmware.h"
00156 #endif /* HAS_FIRMWARE */
00157 
00158 /* The user-configurable values.
00159    These may be modified when a driver module is loaded.*/
00160 
00161 /* Used for tuning interrupt latency vs. overhead. */
00162 static int interrupt_mitigation;
00163 
00164 static int debug = 1;                   /* 1 normal messages, 0 quiet .. 7 verbose. */
00165 static int max_interrupt_work = 20;
00166 static int mtu;
00167 /* Maximum number of multicast addresses to filter (vs. rx-all-multicast).
00168    The Starfire has a 512 element hash table based on the Ethernet CRC. */
00169 static int multicast_filter_limit = 512;
00170 
00171 #define PKT_BUF_SZ      1536            /* Size of each temporary Rx buffer.*/
00172 /*
00173  * Set the copy breakpoint for the copy-only-tiny-frames scheme.
00174  * Setting to > 1518 effectively disables this feature.
00175  *
00176  * NOTE:
00177  * The ia64 doesn't allow for unaligned loads even of integers being
00178  * misaligned on a 2 byte boundary. Thus always force copying of
00179  * packets as the starfire doesn't allow for misaligned DMAs ;-(
00180  * 23/10/2000 - Jes
00181  *
00182  * The Alpha and the Sparc don't allow unaligned loads, either. -Ion
00183  */
00184 #if defined(__ia64__) || defined(__alpha__) || defined(__sparc__)
00185 static int rx_copybreak = PKT_BUF_SZ;
00186 #else
00187 static int rx_copybreak /* = 0 */;
00188 #endif
00189 
00190 /* Used to pass the media type, etc.
00191    Both 'options[]' and 'full_duplex[]' exist for driver interoperability.
00192    The media type is usually passed in 'options[]'.
00193 */
00194 #define MAX_UNITS 8             /* More are supported, limit only on options */
00195 static int options[MAX_UNITS] = {0, };
00196 static int full_duplex[MAX_UNITS] = {0, };
00197 
00198 /* Operational parameters that are set at compile time. */
00199 
00200 /* The "native" ring sizes are either 256 or 2048.
00201    However in some modes a descriptor may be marked to wrap the ring earlier.
00202    The driver allocates a single page for each descriptor ring, constraining
00203    the maximum size in an architecture-dependent way.
00204 */
00205 #define RX_RING_SIZE    256
00206 #define TX_RING_SIZE    32
00207 /* The completion queues are fixed at 1024 entries i.e. 4K or 8KB. */
00208 #define DONE_Q_SIZE     1024
00209 
00210 /* Operational parameters that usually are not changed. */
00211 /* Time in jiffies before concluding the transmitter is hung. */
00212 #define TX_TIMEOUT      (2 * HZ)
00213 
00214 #ifdef ZEROCOPY
00215 #if MAX_SKB_FRAGS <= 6
00216 #define MAX_STARFIRE_FRAGS 6
00217 #else  /* MAX_STARFIRE_FRAGS > 6 */
00218 #warning This driver will not work with more than 6 skb fragments.
00219 #warning Turning off zerocopy support.
00220 #undef ZEROCOPY
00221 #endif /* MAX_STARFIRE_FRAGS > 6 */
00222 #endif /* ZEROCOPY */
00223 
00224 #ifdef ZEROCOPY
00225 #define skb_first_frag_len(skb) skb_headlen(skb)
00226 #else  /* not ZEROCOPY */
00227 #define skb_first_frag_len(skb) (skb->len)
00228 #endif /* not ZEROCOPY */
00229 
00230 /* 2.2.x compatibility code */
00231 #if LINUX_VERSION_CODE < 0x20300
00232 
00233 #include "starfire-kcomp22.h"
00234 
00235 #else  /* LINUX_VERSION_CODE > 0x20300 */
00236 
00237 #include <linux/ethtool.h>
00238 #include <linux/mii.h>
00239 
00240 #define COMPAT_MOD_INC_USE_COUNT
00241 #define COMPAT_MOD_DEC_USE_COUNT
00242 
00243 #define init_tx_timer(dev, func, timeout) \
00244         dev->tx_timeout = func; \
00245         dev->watchdog_timeo = timeout;
00246 #define kick_tx_timer(dev, func, timeout)
00247 
00248 #define netif_start_if(dev)
00249 #define netif_stop_if(dev)
00250 
00251 #define PCI_SLOT_NAME(pci_dev)  (pci_dev)->slot_name
00252 
00253 #endif /* LINUX_VERSION_CODE > 0x20300 */
00254 /* end of compatibility code */
00255 
00256 
00257 /* These identify the driver base version and may not be removed. */
00258 static char version[] __devinitdata =
00259 KERN_INFO "starfire.c:v1.03 7/26/2000  Written by Donald Becker <becker@scyld.com>\n"
00260 KERN_INFO " (unofficial 2.2/2.4 kernel port, version " DRV_VERSION ", " DRV_RELDATE ")\n";
00261 
00262 MODULE_AUTHOR("Donald Becker <becker@scyld.com>");
00263 MODULE_DESCRIPTION("Adaptec Starfire Ethernet driver");
00264 MODULE_LICENSE("GPL");
00265 
00266 MODULE_PARM(max_interrupt_work, "i");
00267 MODULE_PARM(mtu, "i");
00268 MODULE_PARM(debug, "i");
00269 MODULE_PARM(rx_copybreak, "i");
00270 MODULE_PARM(interrupt_mitigation, "i");
00271 MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i");
00272 MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i");
00273 MODULE_PARM_DESC(max_interrupt_work, "Starfire maximum events handled per interrupt");
00274 MODULE_PARM_DESC(mtu, "Starfire MTU (all boards)");
00275 MODULE_PARM_DESC(debug, "Starfire debug level (0-6)");
00276 MODULE_PARM_DESC(rx_copybreak, "Starfire copy breakpoint for copy-only-tiny-frames");
00277 MODULE_PARM_DESC(options, "Starfire: Bits 0-3: media type, bit 17: full duplex");
00278 MODULE_PARM_DESC(full_duplex, "Starfire full duplex setting(s) (1)");
00279 
00280 /*
00281                                 Theory of Operation
00282 
00283 I. Board Compatibility
00284 
00285 This driver is for the Adaptec 6915 "Starfire" 64 bit PCI Ethernet adapter.
00286 
00287 II. Board-specific settings
00288 
00289 III. Driver operation
00290 
00291 IIIa. Ring buffers
00292 
00293 The Starfire hardware uses multiple fixed-size descriptor queues/rings.  The
00294 ring sizes are set fixed by the hardware, but may optionally be wrapped
00295 earlier by the END bit in the descriptor.
00296 This driver uses that hardware queue size for the Rx ring, where a large
00297 number of entries has no ill effect beyond increases the potential backlog.
00298 The Tx ring is wrapped with the END bit, since a large hardware Tx queue
00299 disables the queue layer priority ordering and we have no mechanism to
00300 utilize the hardware two-level priority queue.  When modifying the
00301 RX/TX_RING_SIZE pay close attention to page sizes and the ring-empty warning
00302 levels.
00303 
00304 IIIb/c. Transmit/Receive Structure
00305 
00306 See the Adaptec manual for the many possible structures, and options for
00307 each structure.  There are far too many to document here.
00308 
00309 For transmit this driver uses type 0/1 transmit descriptors (depending
00310 on the presence of the zerocopy infrastructure), and relies on automatic
00311 minimum-length padding.  It does not use the completion queue
00312 consumer index, but instead checks for non-zero status entries.
00313 
00314 For receive this driver uses type 0 receive descriptors.  The driver
00315 allocates full frame size skbuffs for the Rx ring buffers, so all frames
00316 should fit in a single descriptor.  The driver does not use the completion
00317 queue consumer index, but instead checks for non-zero status entries.
00318 
00319 When an incoming frame is less than RX_COPYBREAK bytes long, a fresh skbuff
00320 is allocated and the frame is copied to the new skbuff.  When the incoming
00321 frame is larger, the skbuff is passed directly up the protocol stack.
00322 Buffers consumed this way are replaced by newly allocated skbuffs in a later
00323 phase of receive.
00324 
00325 A notable aspect of operation is that unaligned buffers are not permitted by
00326 the Starfire hardware.  Thus the IP header at offset 14 in an ethernet frame
00327 isn't longword aligned, which may cause problems on some machine
00328 e.g. Alphas and IA64. For these architectures, the driver is forced to copy
00329 the frame into a new skbuff unconditionally. Copied frames are put into the
00330 skbuff at an offset of "+2", thus 16-byte aligning the IP header.
00331 
00332 IIId. Synchronization
00333 
00334 The driver runs as two independent, single-threaded flows of control.  One
00335 is the send-packet routine, which enforces single-threaded use by the
00336 dev->tbusy flag.  The other thread is the interrupt handler, which is single
00337 threaded by the hardware and interrupt handling software.
00338 
00339 The send packet thread has partial control over the Tx ring and 'dev->tbusy'
00340 flag.  It sets the tbusy flag whenever it's queuing a Tx packet. If the next
00341 queue slot is empty, it clears the tbusy flag when finished otherwise it sets
00342 the 'lp->tx_full' flag.
00343 
00344 The interrupt handler has exclusive control over the Rx ring and records stats
00345 from the Tx ring.  After reaping the stats, it marks the Tx queue entry as
00346 empty by incrementing the dirty_tx mark. Iff the 'lp->tx_full' flag is set, it
00347 clears both the tx_full and tbusy flags.
00348 
00349 IV. Notes
00350 
00351 IVb. References
00352 
00353 The Adaptec Starfire manuals, available only from Adaptec.
00354 http://www.scyld.com/expert/100mbps.html
00355 http://www.scyld.com/expert/NWay.html
00356 
00357 IVc. Errata
00358 
00359 */
00360 
00361 
00362 
00363 enum chip_capability_flags {CanHaveMII=1, };
00364 #define PCI_IOTYPE (PCI_USES_MASTER | PCI_USES_MEM | PCI_ADDR0)
00365 
00366 #if 0
00367 #define ADDR_64BITS 1                   /* This chip uses 64 bit addresses. */
00368 #endif
00369 
00370 #define HAS_IP_COPYSUM 1
00371 
00372 enum chipset {
00373         CH_6915 = 0,
00374 };
00375 
00376 static struct pci_device_id starfire_pci_tbl[] __devinitdata = {
00377         { 0x9004, 0x6915, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CH_6915 },
00378         { 0, }
00379 };
00380 MODULE_DEVICE_TABLE(pci, starfire_pci_tbl);
00381 
00382 /* A chip capabilities table, matching the CH_xxx entries in xxx_pci_tbl[] above. */
00383 static struct chip_info {
00384         const char *name;
00385         int drv_flags;
00386 } netdrv_tbl[] __devinitdata = {
00387         { "Adaptec Starfire 6915", CanHaveMII },
00388 };
00389 
00390 
00391 /* Offsets to the device registers.
00392    Unlike software-only systems, device drivers interact with complex hardware.
00393    It's not useful to define symbolic names for every register bit in the
00394    device.  The name can only partially document the semantics and make
00395    the driver longer and more difficult to read.
00396    In general, only the important configuration values or bits changed
00397    multiple times should be defined symbolically.
00398 */
00399 enum register_offsets {
00400         PCIDeviceConfig=0x50040, GenCtrl=0x50070, IntrTimerCtrl=0x50074,
00401         IntrClear=0x50080, IntrStatus=0x50084, IntrEnable=0x50088,
00402         MIICtrl=0x52000, StationAddr=0x50120, EEPROMCtrl=0x51000,
00403         GPIOCtrl=0x5008C, TxDescCtrl=0x50090,
00404         TxRingPtr=0x50098, HiPriTxRingPtr=0x50094, /* Low and High priority. */
00405         TxRingHiAddr=0x5009C,           /* 64 bit address extension. */
00406         TxProducerIdx=0x500A0, TxConsumerIdx=0x500A4,
00407         TxThreshold=0x500B0,
00408         CompletionHiAddr=0x500B4, TxCompletionAddr=0x500B8,
00409         RxCompletionAddr=0x500BC, RxCompletionQ2Addr=0x500C0,
00410         CompletionQConsumerIdx=0x500C4, RxDMACtrl=0x500D0,
00411         RxDescQCtrl=0x500D4, RxDescQHiAddr=0x500DC, RxDescQAddr=0x500E0,
00412         RxDescQIdx=0x500E8, RxDMAStatus=0x500F0, RxFilterMode=0x500F4,
00413         TxMode=0x55000, PerfFilterTable=0x56000, HashTable=0x56100,
00414         TxGfpMem=0x58000, RxGfpMem=0x5a000,
00415 };
00416 
00417 /* Bits in the interrupt status/mask registers. */
00418 enum intr_status_bits {
00419         IntrLinkChange=0xf0000000, IntrStatsMax=0x08000000,
00420         IntrAbnormalSummary=0x02000000, IntrGeneralTimer=0x01000000,
00421         IntrSoftware=0x800000, IntrRxComplQ1Low=0x400000,
00422         IntrTxComplQLow=0x200000, IntrPCI=0x100000,
00423         IntrDMAErr=0x080000, IntrTxDataLow=0x040000,
00424         IntrRxComplQ2Low=0x020000, IntrRxDescQ1Low=0x010000,
00425         IntrNormalSummary=0x8000, IntrTxDone=0x4000,
00426         IntrTxDMADone=0x2000, IntrTxEmpty=0x1000,
00427         IntrEarlyRxQ2=0x0800, IntrEarlyRxQ1=0x0400,
00428         IntrRxQ2Done=0x0200, IntrRxQ1Done=0x0100,
00429         IntrRxGFPDead=0x80, IntrRxDescQ2Low=0x40,
00430         IntrNoTxCsum=0x20, IntrTxBadID=0x10,
00431         IntrHiPriTxBadID=0x08, IntrRxGfp=0x04,
00432         IntrTxGfp=0x02, IntrPCIPad=0x01,
00433         /* not quite bits */
00434         IntrRxDone=IntrRxQ2Done | IntrRxQ1Done,
00435         IntrRxEmpty=IntrRxDescQ1Low | IntrRxDescQ2Low,
00436         IntrNormalMask=0xff00, IntrAbnormalMask=0x3ff00fe,
00437 };
00438 
00439 /* Bits in the RxFilterMode register. */
00440 enum rx_mode_bits {
00441         AcceptBroadcast=0x04, AcceptAllMulticast=0x02, AcceptAll=0x01,
00442         AcceptMulticast=0x10, AcceptMyPhys=0xE040,
00443 };
00444 
00445 /* Bits in the TxDescCtrl register. */
00446 enum tx_ctrl_bits {
00447         TxDescSpaceUnlim=0x00, TxDescSpace32=0x10, TxDescSpace64=0x20,
00448         TxDescSpace128=0x30, TxDescSpace256=0x40,
00449         TxDescType0=0x00, TxDescType1=0x01, TxDescType2=0x02,
00450         TxDescType3=0x03, TxDescType4=0x04,
00451         TxNoDMACompletion=0x08, TxDescQ64bit=0x80,
00452         TxHiPriFIFOThreshShift=24, TxPadLenShift=16,
00453         TxDMABurstSizeShift=8,
00454 };
00455 
00456 /* Bits in the RxDescQCtrl register. */
00457 enum rx_ctrl_bits {
00458         RxBufferLenShift=16, RxMinDescrThreshShift=0,
00459         RxPrefetchMode=0x8000, Rx2048QEntries=0x4000,
00460         RxVariableQ=0x2000, RxDesc64bit=0x1000,
00461         RxDescQAddr64bit=0x0100,
00462         RxDescSpace4=0x000, RxDescSpace8=0x100,
00463         RxDescSpace16=0x200, RxDescSpace32=0x300,
00464         RxDescSpace64=0x400, RxDescSpace128=0x500,
00465         RxConsumerWrEn=0x80,
00466 };
00467 
00468 /* Bits in the RxCompletionAddr register */
00469 enum rx_compl_bits {
00470         RxComplQAddr64bit=0x80, TxComplProducerWrEn=0x40,
00471         RxComplType0=0x00, RxComplType1=0x10,
00472         RxComplType2=0x20, RxComplType3=0x30,
00473         RxComplThreshShift=0,
00474 };
00475 
00476 /* The Rx and Tx buffer descriptors. */
00477 struct starfire_rx_desc {
00478         u32 rxaddr;                     /* Optionally 64 bits. */
00479 };
00480 enum rx_desc_bits {
00481         RxDescValid=1, RxDescEndRing=2,
00482 };
00483 
00484 /* Completion queue entry.
00485    You must update the page allocation, init_ring and the shift count in rx()
00486    if using a larger format. */
00487 #ifdef HAS_FIRMWARE
00488 #define csum_rx_status
00489 #endif /* HAS_FIRMWARE */
00490 struct rx_done_desc {
00491         u32 status;                     /* Low 16 bits is length. */
00492 #ifdef csum_rx_status
00493         u32 status2;                    /* Low 16 bits is csum */
00494 #endif /* csum_rx_status */
00495 #ifdef full_rx_status
00496         u32 status2;
00497         u16 vlanid;
00498         u16 csum;                       /* partial checksum */
00499         u32 timestamp;
00500 #endif /* full_rx_status */
00501 };
00502 enum rx_done_bits {
00503         RxOK=0x20000000, RxFIFOErr=0x10000000, RxBufQ2=0x08000000,
00504 };
00505 
00506 #ifdef ZEROCOPY
00507 /* Type 0 Tx descriptor. */
00508 /* If more fragments are needed, don't forget to change the
00509    descriptor spacing as well! */
00510 struct starfire_tx_desc {
00511         u32 status;
00512         u32 nbufs;
00513         u32 first_addr;
00514         u16 first_len;
00515         u16 total_len;
00516         struct {
00517                 u32 addr;
00518                 u32 len;
00519         } frag[MAX_STARFIRE_FRAGS];
00520 };
00521 #else  /* not ZEROCOPY */
00522 /* Type 1 Tx descriptor. */
00523 struct starfire_tx_desc {
00524         u32 status;                     /* Upper bits are status, lower 16 length. */
00525         u32 first_addr;
00526 };
00527 #endif /* not ZEROCOPY */
00528 enum tx_desc_bits {
00529         TxDescID=0xB0000000,
00530         TxCRCEn=0x01000000, TxDescIntr=0x08000000,
00531         TxRingWrap=0x04000000, TxCalTCP=0x02000000,
00532 };
00533 struct tx_done_report {
00534         u32 status;                     /* timestamp, index. */
00535 #if 0
00536         u32 intrstatus;                 /* interrupt status */
00537 #endif
00538 };
00539 
00540 struct rx_ring_info {
00541         struct sk_buff *skb;
00542         dma_addr_t mapping;
00543 };
00544 struct tx_ring_info {
00545         struct sk_buff *skb;
00546         dma_addr_t first_mapping;
00547 #ifdef ZEROCOPY
00548         dma_addr_t frag_mapping[MAX_STARFIRE_FRAGS];
00549 #endif /* ZEROCOPY */
00550 };
00551 
00552 #define PHY_CNT         2
00553 struct netdev_private {
00554         /* Descriptor rings first for alignment. */
00555         struct starfire_rx_desc *rx_ring;
00556         struct starfire_tx_desc *tx_ring;
00557         dma_addr_t rx_ring_dma;
00558         dma_addr_t tx_ring_dma;
00559         /* The addresses of rx/tx-in-place skbuffs. */
00560         struct rx_ring_info rx_info[RX_RING_SIZE];
00561         struct tx_ring_info tx_info[TX_RING_SIZE];
00562         /* Pointers to completion queues (full pages). */
00563         struct rx_done_desc *rx_done_q;
00564         dma_addr_t rx_done_q_dma;
00565         unsigned int rx_done;
00566         struct tx_done_report *tx_done_q;
00567         dma_addr_t tx_done_q_dma;
00568         unsigned int tx_done;
00569         struct net_device_stats stats;
00570         struct pci_dev *pci_dev;
00571         /* Frequently used values: keep some adjacent for cache effect. */
00572         unsigned int cur_rx, dirty_rx;  /* Producer/consumer ring indices */
00573         unsigned int cur_tx, dirty_tx;
00574         unsigned int rx_buf_sz;         /* Based on MTU+slack. */
00575         unsigned int tx_full:1,         /* The Tx queue is full. */
00576         /* These values keep track of the transceiver/media in use. */
00577                 autoneg:1,              /* Autonegotiation allowed. */
00578                 full_duplex:1,          /* Full-duplex operation. */
00579                 speed100:1;             /* Set if speed == 100MBit. */
00580         unsigned int intr_mitigation;
00581         u32 tx_mode;
00582         u8 tx_threshold;
00583         /* MII transceiver section. */
00584         u16 advertising;                /* NWay media advertisement */
00585         int phy_cnt;                    /* MII device addresses. */
00586         unsigned char phys[PHY_CNT];    /* MII device addresses. */
00587 };
00588 
00589 
00590 static int      mdio_read(struct net_device *dev, int phy_id, int location);
00591 static void     mdio_write(struct net_device *dev, int phy_id, int location, int value);
00592 static int      netdev_open(struct net_device *dev);
00593 static void     check_duplex(struct net_device *dev);
00594 static void     tx_timeout(struct net_device *dev);
00595 static void     init_ring(struct net_device *dev);
00596 static int      start_tx(struct sk_buff *skb, struct net_device *dev);
00597 static void     intr_handler(int irq, void *dev_instance, struct pt_regs *regs);
00598 static void     netdev_error(struct net_device *dev, int intr_status);
00599 static int      netdev_rx(struct net_device *dev);
00600 static void     netdev_error(struct net_device *dev, int intr_status);
00601 static void     set_rx_mode(struct net_device *dev);
00602 static struct net_device_stats *get_stats(struct net_device *dev);
00603 static int      netdev_ioctl(struct net_device *dev, struct ifreq *rq, int cmd);
00604 static int      netdev_close(struct net_device *dev);
00605 static void     netdev_media_change(struct net_device *dev);
00606 
00607 
00608 
00609 static int __devinit starfire_init_one(struct pci_dev *pdev,
00610                                        const struct pci_device_id *ent)
00611 {
00612         struct netdev_private *np;
00613         int i, irq, option, chip_idx = ent->driver_data;
00614         struct net_device *dev;
00615         static int card_idx = -1;
00616         long ioaddr;
00617         int drv_flags, io_size;
00618         int boguscnt;
00619         u16 cmd;
00620         u8 cache;
00621 
00622 /* when built into the kernel, we only print version if device is found */
00623 #ifndef MODULE
00624         static int printed_version;
00625         if (!printed_version++)
00626                 printk(version);
00627 #endif
00628 
00629         card_idx++;
00630 
00631         if (pci_enable_device (pdev))
00632                 return -EIO;
00633 
00634         ioaddr = pci_resource_start(pdev, 0);
00635         io_size = pci_resource_len(pdev, 0);
00636         if (!ioaddr || ((pci_resource_flags(pdev, 0) & IORESOURCE_MEM) == 0)) {
00637                 printk (KERN_ERR DRV_NAME " %d: no PCI MEM resources, aborting\n", card_idx);
00638                 return -ENODEV;
00639         }
00640 
00641         dev = alloc_etherdev(sizeof(*np));
00642         if (!dev) {
00643                 printk (KERN_ERR DRV_NAME " %d: cannot alloc etherdev, aborting\n", card_idx);
00644                 return -ENOMEM;
00645         }
00646         SET_MODULE_OWNER(dev);
00647 
00648         irq = pdev->irq;
00649 
00650         if (pci_request_regions (pdev, dev->name)) {
00651                 printk (KERN_ERR DRV_NAME " %d: cannot reserve PCI resources, aborting\n", card_idx);
00652                 goto err_out_free_netdev;
00653         }
00654 
00655         /* ioremap is borken in Linux-2.2.x/sparc64 */
00656 #if !defined(CONFIG_SPARC64) || LINUX_VERSION_CODE > 0x20300
00657         ioaddr = (long) ioremap(ioaddr, io_size);
00658         if (!ioaddr) {
00659                 printk (KERN_ERR DRV_NAME " %d: cannot remap 0x%x @ 0x%lx, aborting\n",
00660                         card_idx, io_size, ioaddr);
00661                 goto err_out_free_res;
00662         }
00663 #endif /* !CONFIG_SPARC64 || Linux 2.3.0+ */
00664 
00665         pci_set_master(pdev);
00666 
00667         /* enable MWI -- it vastly improves Rx performance on sparc64 */
00668         pci_read_config_word(pdev, PCI_COMMAND, &cmd);
00669         cmd |= PCI_COMMAND_INVALIDATE;
00670         pci_write_config_word(pdev, PCI_COMMAND, cmd);
00671 
00672         /* set PCI cache size */
00673         pci_read_config_byte(pdev, PCI_CACHE_LINE_SIZE, &cache);
00674         if ((cache << 2) != SMP_CACHE_BYTES) {
00675                 printk(KERN_INFO "  PCI cache line size set incorrectly "
00676                        "(%i bytes) by BIOS/FW, correcting to %i\n",
00677                        (cache << 2), SMP_CACHE_BYTES);
00678                 pci_write_config_byte(pdev, PCI_CACHE_LINE_SIZE,
00679                                       SMP_CACHE_BYTES >> 2);
00680         }
00681 
00682 #ifdef ZEROCOPY
00683         /* Starfire can do SG and TCP/UDP checksumming */
00684         dev->features |= NETIF_F_SG | NETIF_F_IP_CSUM;
00685 #endif /* ZEROCOPY */
00686 
00687         /* Serial EEPROM reads are hidden by the hardware. */
00688         for (i = 0; i < 6; i++)
00689                 dev->dev_addr[i] = readb(ioaddr + EEPROMCtrl + 20 - i);
00690 
00691 #if ! defined(final_version) /* Dump the EEPROM contents during development. */
00692         if (debug > 4)
00693                 for (i = 0; i < 0x20; i++)
00694                         printk("%2.2x%s",
00695                                (unsigned int)readb(ioaddr + EEPROMCtrl + i),
00696                                i % 16 != 15 ? " " : "\n");
00697 #endif
00698 
00699         /* Issue soft reset */
00700         writel(0x8000, ioaddr + TxMode);
00701         udelay(1000);
00702         writel(0, ioaddr + TxMode);
00703 
00704         /* Reset the chip to erase previous misconfiguration. */
00705         writel(1, ioaddr + PCIDeviceConfig);
00706         boguscnt = 1000;
00707         while (--boguscnt > 0) {
00708                 udelay(10);
00709                 if ((readl(ioaddr + PCIDeviceConfig) & 1) == 0)
00710                         break;
00711         }
00712         if (boguscnt == 0)
00713                 printk("%s: chipset reset never completed!\n", dev->name);
00714         /* wait a little longer */
00715         udelay(1000);
00716 
00717         dev->base_addr = ioaddr;
00718         dev->irq = irq;
00719 
00720         np = dev->priv;
00721         pci_set_drvdata(pdev, dev);
00722 
00723         np->pci_dev = pdev;
00724         drv_flags = netdrv_tbl[chip_idx].drv_flags;
00725 
00726         option = card_idx < MAX_UNITS ? options[card_idx] : 0;
00727         if (dev->mem_start)
00728                 option = dev->mem_start;
00729 
00730         /* The lower four bits are the media type. */
00731         if (option & 0x200)
00732                 np->full_duplex = 1;
00733 
00734         if (card_idx < MAX_UNITS && full_duplex[card_idx] > 0)
00735                 np->full_duplex = 1;
00736 
00737         if (np->full_duplex)
00738                 np->autoneg = 0;
00739         else
00740                 np->autoneg = 1;
00741         np->speed100 = 1;
00742 
00743         /* The chip-specific entries in the device structure. */
00744         dev->open = &netdev_open;
00745         dev->hard_start_xmit = &start_tx;
00746         init_tx_timer(dev, tx_timeout, TX_TIMEOUT);
00747         dev->stop = &netdev_close;
00748         dev->get_stats = &get_stats;
00749         dev->set_multicast_list = &set_rx_mode;
00750         dev->do_ioctl = &netdev_ioctl;
00751 
00752         if (mtu)
00753                 dev->mtu = mtu;
00754 
00755         i = register_netdev(dev);
00756         if (i)
00757                 goto err_out_cleardev;
00758 
00759         printk(KERN_INFO "%s: %s at 0x%lx, ",
00760                    dev->name, netdrv_tbl[chip_idx].name, ioaddr);
00761         for (i = 0; i < 5; i++)
00762                 printk("%2.2x:", dev->dev_addr[i]);
00763         printk("%2.2x, IRQ %d.\n", dev->dev_addr[i], irq);
00764 
00765         if (drv_flags & CanHaveMII) {
00766                 int phy, phy_idx = 0;
00767                 int mii_status;
00768                 for (phy = 0; phy < 32 && phy_idx < PHY_CNT; phy++) {
00769                         mdio_write(dev, phy, MII_BMCR, BMCR_RESET);
00770                         mdelay(100);
00771                         boguscnt = 1000;
00772                         while (--boguscnt > 0)
00773                                 if ((mdio_read(dev, phy, MII_BMCR) & BMCR_RESET) == 0)
00774                                         break;
00775                         if (boguscnt == 0) {
00776                                 printk("%s: PHY reset never completed!\n", dev->name);
00777                                 continue;
00778                         }
00779                         mii_status = mdio_read(dev, phy, MII_BMSR);
00780                         if (mii_status != 0) {
00781                                 np->phys[phy_idx++] = phy;
00782                                 np->advertising = mdio_read(dev, phy, MII_ADVERTISE);
00783                                 printk(KERN_INFO "%s: MII PHY found at address %d, status "
00784                                            "0x%4.4x advertising %4.4x.\n",
00785                                            dev->name, phy, mii_status, np->advertising);
00786                                 /* there can be only one PHY on-board */
00787                                 break;
00788                         }
00789                 }
00790                 np->phy_cnt = phy_idx;
00791         }
00792 
00793 #ifdef ZEROCOPY
00794         printk(KERN_INFO "%s: scatter-gather and hardware TCP cksumming enabled.\n",
00795                dev->name);
00796 #else  /* not ZEROCOPY */
00797         printk(KERN_INFO "%s: scatter-gather and hardware TCP cksumming disabled.\n",
00798                dev->name);
00799 #endif /* not ZEROCOPY */
00800 
00801         return 0;
00802 
00803 err_out_cleardev:
00804         pci_set_drvdata(pdev, NULL);
00805         iounmap((void *)ioaddr);
00806 err_out_free_res:
00807         pci_release_regions (pdev);
00808 err_out_free_netdev:
00809         unregister_netdev(dev);
00810         kfree(dev);
00811         return -ENODEV;
00812 }
00813 
00814 
00815 /* Read the MII Management Data I/O (MDIO) interfaces. */
00816 static int mdio_read(struct net_device *dev, int phy_id, int location)
00817 {
00818         long mdio_addr = dev->base_addr + MIICtrl + (phy_id<<7) + (location<<2);
00819         int result, boguscnt=1000;
00820         /* ??? Should we add a busy-wait here? */
00821         do
00822                 result = readl(mdio_addr);
00823         while ((result & 0xC0000000) != 0x80000000 && --boguscnt > 0);
00824         if (boguscnt == 0)
00825                 return 0;
00826         if ((result & 0xffff) == 0xffff)
00827                 return 0;
00828         return result & 0xffff;
00829 }
00830 
00831 
00832 static void mdio_write(struct net_device *dev, int phy_id, int location, int value)
00833 {
00834         long mdio_addr = dev->base_addr + MIICtrl + (phy_id<<7) + (location<<2);
00835         writel(value, mdio_addr);
00836         /* The busy-wait will occur before a read. */
00837         return;
00838 }
00839 
00840 
00841 static int netdev_open(struct net_device *dev)
00842 {
00843         struct netdev_private *np = dev->priv;
00844         long ioaddr = dev->base_addr;
00845         int i, retval;
00846 
00847         /* Do we ever need to reset the chip??? */
00848 
00849         COMPAT_MOD_INC_USE_COUNT;
00850 
00851         retval = request_irq(dev->irq, &intr_handler, SA_SHIRQ, dev->name, dev);
00852         if (retval) {
00853                 COMPAT_MOD_DEC_USE_COUNT;
00854                 return retval;
00855         }
00856 
00857         /* Disable the Rx and Tx, and reset the chip. */
00858         writel(0, ioaddr + GenCtrl);
00859         writel(1, ioaddr + PCIDeviceConfig);
00860         if (debug > 1)
00861                 printk(KERN_DEBUG "%s: netdev_open() irq %d.\n",
00862                        dev->name, dev->irq);
00863         /* Allocate the various queues, failing gracefully. */
00864         if (np->tx_done_q == 0)
00865                 np->tx_done_q = pci_alloc_consistent(np->pci_dev, PAGE_SIZE, &np->tx_done_q_dma);
00866         if (np->rx_done_q == 0)
00867                 np->rx_done_q = pci_alloc_consistent(np->pci_dev, sizeof(struct rx_done_desc) * DONE_Q_SIZE, &np->rx_done_q_dma);
00868         if (np->tx_ring == 0)
00869                 np->tx_ring = pci_alloc_consistent(np->pci_dev, PAGE_SIZE, &np->tx_ring_dma);
00870         if (np->rx_ring == 0)
00871                 np->rx_ring = pci_alloc_consistent(np->pci_dev, PAGE_SIZE, &np->rx_ring_dma);
00872         if (np->tx_done_q == 0 || np->rx_done_q == 0
00873                 || np->rx_ring == 0 || np->tx_ring == 0) {
00874                 if (np->tx_done_q)
00875                         pci_free_consistent(np->pci_dev, PAGE_SIZE,
00876                                             np->tx_done_q, np->tx_done_q_dma);
00877                 if (np->rx_done_q)
00878                         pci_free_consistent(np->pci_dev, sizeof(struct rx_done_desc) * DONE_Q_SIZE,
00879                                             np->rx_done_q, np->rx_done_q_dma);
00880                 if (np->tx_ring)
00881                         pci_free_consistent(np->pci_dev, PAGE_SIZE,
00882                                             np->tx_ring, np->tx_ring_dma);
00883                 if (np->rx_ring)
00884                         pci_free_consistent(np->pci_dev, PAGE_SIZE,
00885                                             np->rx_ring, np->rx_ring_dma);
00886                 COMPAT_MOD_DEC_USE_COUNT;
00887                 return -ENOMEM;
00888         }
00889 
00890         init_ring(dev);
00891         /* Set the size of the Rx buffers. */
00892         writel((np->rx_buf_sz << RxBufferLenShift) |
00893                (0 << RxMinDescrThreshShift) |
00894                RxPrefetchMode | RxVariableQ |
00895                RxDescSpace4,
00896                ioaddr + RxDescQCtrl);
00897 
00898 #ifdef ZEROCOPY
00899         /* Set Tx descriptor to type 0 and spacing to 64 bytes. */
00900         writel((2 << TxHiPriFIFOThreshShift) |
00901                (0 << TxPadLenShift) |
00902                (4 << TxDMABurstSizeShift) |
00903                TxDescSpace64 | TxDescType0,
00904                ioaddr + TxDescCtrl);
00905 #else  /* not ZEROCOPY */
00906         /* Set Tx descriptor to type 1 and padding to 0 bytes. */
00907         writel((2 << TxHiPriFIFOThreshShift) |
00908                (0 << TxPadLenShift) |
00909                (4 << TxDMABurstSizeShift) |
00910                TxDescSpaceUnlim | TxDescType1,
00911                ioaddr + TxDescCtrl);
00912 #endif /* not ZEROCOPY */
00913 
00914 #if defined(ADDR_64BITS) && defined(__alpha__)
00915         /* XXX We really need a 64-bit PCI dma interfaces too... -DaveM */
00916         writel(np->rx_ring_dma >> 32, ioaddr + RxDescQHiAddr);
00917         writel(np->tx_ring_dma >> 32, ioaddr + TxRingHiAddr);
00918 #else
00919         writel(0, ioaddr + RxDescQHiAddr);
00920         writel(0, ioaddr + TxRingHiAddr);
00921         writel(0, ioaddr + CompletionHiAddr);
00922 #endif
00923         writel(np->rx_ring_dma, ioaddr + RxDescQAddr);
00924         writel(np->tx_ring_dma, ioaddr + TxRingPtr);
00925 
00926         writel(np->tx_done_q_dma, ioaddr + TxCompletionAddr);
00927 #ifdef full_rx_status
00928         writel(np->rx_done_q_dma |
00929                RxComplType3 |
00930                (0 << RxComplThreshShift),
00931                ioaddr + RxCompletionAddr);
00932 #else  /* not full_rx_status */
00933 #ifdef csum_rx_status
00934         writel(np->rx_done_q_dma |
00935                RxComplType2 |
00936                (0 << RxComplThreshShift),
00937                ioaddr + RxCompletionAddr);
00938 #else  /* not csum_rx_status */
00939         writel(np->rx_done_q_dma |
00940                RxComplType0 |
00941                (0 << RxComplThreshShift),
00942                ioaddr + RxCompletionAddr);
00943 #endif /* not csum_rx_status */
00944 #endif /* not full_rx_status */
00945 
00946         if (debug > 1)
00947                 printk(KERN_DEBUG "%s: Filling in the station address.\n", dev->name);
00948 
00949         /* Fill both the unused Tx SA register and the Rx perfect filter. */
00950         for (i = 0; i < 6; i++)
00951                 writeb(dev->dev_addr[i], ioaddr + StationAddr + 5 - i);
00952         for (i = 0; i < 16; i++) {
00953                 u16 *eaddrs = (u16 *)dev->dev_addr;
00954                 long setup_frm = ioaddr + PerfFilterTable + i * 16;
00955                 writew(cpu_to_be16(eaddrs[2]), setup_frm); setup_frm += 4;
00956                 writew(cpu_to_be16(eaddrs[1]), setup_frm); setup_frm += 4;
00957                 writew(cpu_to_be16(eaddrs[0]), setup_frm); setup_frm += 8;
00958         }
00959 
00960         /* Initialize other registers. */
00961         /* Configure the PCI bus bursts and FIFO thresholds. */
00962         np->tx_mode = 0x0C04;           /* modified when link is up. */
00963         writel(0x8000 | np->tx_mode, ioaddr + TxMode);
00964         udelay(1000);
00965         writel(np->tx_mode, ioaddr + TxMode);
00966         np->tx_threshold = 4;
00967         writel(np->tx_threshold, ioaddr + TxThreshold);
00968 
00969         interrupt_mitigation &= 0x1f;
00970         np->intr_mitigation = interrupt_mitigation;
00971         writel(np->intr_mitigation, ioaddr + IntrTimerCtrl);
00972 
00973         netif_start_if(dev);
00974         netif_start_queue(dev);
00975 
00976         if (debug > 1)
00977                 printk(KERN_DEBUG "%s: Setting the Rx and Tx modes.\n", dev->name);
00978         set_rx_mode(dev);
00979 
00980         np->advertising = mdio_read(dev, np->phys[0], MII_ADVERTISE);
00981         check_duplex(dev);
00982 
00983         /* Enable GPIO interrupts on link change */
00984         writel(0x0f00ff00, ioaddr + GPIOCtrl);
00985 
00986         /* Set the interrupt mask and enable PCI interrupts. */
00987         writel(IntrRxDone | IntrRxEmpty | IntrDMAErr |
00988                IntrTxDone | IntrStatsMax | IntrLinkChange |
00989                IntrNormalSummary | IntrAbnormalSummary |
00990                IntrRxGFPDead | IntrNoTxCsum | IntrTxBadID,
00991                ioaddr + IntrEnable);
00992         writel(0x00800000 | readl(ioaddr + PCIDeviceConfig),
00993                ioaddr + PCIDeviceConfig);
00994 
00995 #ifdef HAS_FIRMWARE
00996         /* Load Rx/Tx firmware into the frame processors */
00997         for (i = 0; i < FIRMWARE_RX_SIZE * 2; i++)
00998                 writel(firmware_rx[i], ioaddr + RxGfpMem + i * 4);
00999         for (i = 0; i < FIRMWARE_TX_SIZE * 2; i++)
01000                 writel(firmware_tx[i], ioaddr + TxGfpMem + i * 4);
01001         /* Enable the Rx and Tx units, and the Rx/Tx frame processors. */
01002         writel(0x003F, ioaddr + GenCtrl);
01003 #else  /* not HAS_FIRMWARE */
01004         /* Enable the Rx and Tx units only. */
01005         writel(0x000F, ioaddr + GenCtrl);
01006 #endif /* not HAS_FIRMWARE */
01007 
01008         if (debug > 2)
01009                 printk(KERN_DEBUG "%s: Done netdev_open().\n",
01010                        dev->name);
01011 
01012         return 0;
01013 }
01014 
01015 
01016 static void check_duplex(struct net_device *dev)
01017 {
01018         struct netdev_private *np = dev->priv;
01019         u16 reg0;
01020 
01021         mdio_write(dev, np->phys[0], MII_ADVERTISE, np->advertising);
01022         mdio_write(dev, np->phys[0], MII_BMCR, BMCR_RESET);
01023         udelay(500);
01024         while (mdio_read(dev, np->phys[0], MII_BMCR) & BMCR_RESET);
01025 
01026         reg0 = mdio_read(dev, np->phys[0], MII_BMCR);
01027 
01028         if (np->autoneg) {
01029                 reg0 |= BMCR_ANENABLE | BMCR_ANRESTART;
01030         } else {
01031                 reg0 &= ~(BMCR_ANENABLE | BMCR_ANRESTART);
01032                 if (np->speed100)
01033                         reg0 |= BMCR_SPEED100;
01034                 if (np->full_duplex)
01035                         reg0 |= BMCR_FULLDPLX;
01036                 printk(KERN_DEBUG "%s: Link forced to %sMbit %s-duplex\n",
01037                        dev->name,
01038                        np->speed100 ? "100" : "10",
01039                        np->full_duplex ? "full" : "half");
01040         }
01041         mdio_write(dev, np->phys[0], MII_BMCR, reg0);
01042 }
01043 
01044 
01045 static void tx_timeout(struct net_device *dev)
01046 {
01047         struct netdev_private *np = dev->priv;
01048         long ioaddr = dev->base_addr;
01049         int old_debug;
01050 
01051         printk(KERN_WARNING "%s: Transmit timed out, status %8.8x,"
01052                " resetting...\n", dev->name, (int)readl(ioaddr + IntrStatus));
01053 
01054         /* Perhaps we should reinitialize the hardware here. */
01055 
01056         /*
01057          * Stop and restart the chip's Tx processes.
01058          * Cheat and increase the debug level temporarily.
01059          */
01060         old_debug = debug;
01061         debug = 2;
01062         netdev_close(dev);
01063         netdev_open(dev);
01064         debug = old_debug;
01065 
01066         /* Trigger an immediate transmit demand. */
01067 
01068         dev->trans_start = jiffies;
01069         np->stats.tx_errors++;
01070         netif_wake_queue(dev);
01071 }
01072 
01073 
01074 /* Initialize the Rx and Tx rings, along with various 'dev' bits. */
01075 static void init_ring(struct net_device *dev)
01076 {
01077         struct netdev_private *np = dev->priv;
01078         int i;
01079 
01080         np->tx_full = 0;
01081         np->cur_rx = np->cur_tx = 0;
01082         np->dirty_rx = np->rx_done = np->dirty_tx = np->tx_done = 0;
01083 
01084         np->rx_buf_sz = (dev->mtu <= 1500 ? PKT_BUF_SZ : dev->mtu + 32);
01085 
01086         /* Fill in the Rx buffers.  Handle allocation failure gracefully. */
01087         for (i = 0; i < RX_RING_SIZE; i++) {
01088                 struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz);
01089                 np->rx_info[i].skb = skb;
01090                 if (skb == NULL)
01091                         break;
01092                 np->rx_info[i].mapping = pci_map_single(np->pci_dev, skb->tail, np->rx_buf_sz, PCI_DMA_FROMDEVICE);
01093                 skb->dev = dev;                 /* Mark as being used by this device. */
01094                 /* Grrr, we cannot offset to correctly align the IP header. */
01095                 np->rx_ring[i].rxaddr = cpu_to_le32(np->rx_info[i].mapping | RxDescValid);
01096         }
01097         writew(i - 1, dev->base_addr + RxDescQIdx);
01098         np->dirty_rx = (unsigned int)(i - RX_RING_SIZE);
01099 
01100         /* Clear the remainder of the Rx buffer ring. */
01101         for (  ; i < RX_RING_SIZE; i++) {
01102                 np->rx_ring[i].rxaddr = 0;
01103                 np->rx_info[i].skb = NULL;
01104                 np->rx_info[i].mapping = 0;
01105         }
01106         /* Mark the last entry as wrapping the ring. */
01107         np->rx_ring[i-1].rxaddr |= cpu_to_le32(RxDescEndRing);
01108 
01109         /* Clear the completion rings. */
01110         for (i = 0; i < DONE_Q_SIZE; i++) {
01111                 np->rx_done_q[i].status = 0;
01112                 np->tx_done_q[i].status = 0;
01113         }
01114 
01115         for (i = 0; i < TX_RING_SIZE; i++) {
01116                 np->tx_info[i].skb = NULL;
01117                 np->tx_info[i].first_mapping = 0;
01118 #ifdef ZEROCOPY
01119                 {
01120                         int j;
01121                         for (j = 0; j < MAX_STARFIRE_FRAGS; j++)
01122                                 np->tx_info[i].frag_mapping[j] = 0;
01123                 }
01124 #endif /* ZEROCOPY */
01125                 np->tx_ring[i].status = 0;
01126         }
01127         return;
01128 }
01129 
01130 
01131 static int start_tx(struct sk_buff *skb, struct net_device *dev)
01132 {
01133         struct netdev_private *np = dev->priv;
01134         unsigned int entry;
01135 #ifdef ZEROCOPY
01136         int i;
01137 #endif
01138 
01139         kick_tx_timer(dev, tx_timeout, TX_TIMEOUT);
01140 
01141         /* Caution: the write order is important here, set the field
01142            with the "ownership" bits last. */
01143 
01144         /* Calculate the next Tx descriptor entry. */
01145         entry = np->