|
|
1.1 ! root 1: /* starfire.c: Linux device driver for the Adaptec Starfire network adapter. */ ! 2: /* ! 3: Written/Copyright 1998-2003 by Donald Becker. ! 4: ! 5: This software may be used and distributed according to the terms of ! 6: the GNU General Public License (GPL), incorporated herein by reference. ! 7: Drivers based on or derived from this code fall under the GPL and must ! 8: retain the authorship, copyright and license notice. This file is not ! 9: a complete program and may only be used when the entire operating ! 10: system is licensed under the GPL. ! 11: ! 12: The author may be reached as [email protected], or C/O ! 13: Scyld Computing Corporation ! 14: 914 Bay Ridge Road, Suite 220 ! 15: Annapolis MD 21403 ! 16: ! 17: Support information and updates available at ! 18: http://www.scyld.com/network/starfire.html ! 19: */ ! 20: ! 21: /* These identify the driver base version and may not be removed. */ ! 22: static const char version1[] = ! 23: "starfire.c:v1.09 7/22/2003 Copyright by Donald Becker <[email protected]>\n"; ! 24: static const char version2[] = ! 25: " Updates and info at http://www.scyld.com/network/starfire.html\n"; ! 26: ! 27: /* The user-configurable values. ! 28: These may be modified when a driver module is loaded.*/ ! 29: ! 30: /* Used for tuning interrupt latency vs. overhead. */ ! 31: static int interrupt_mitigation = 0x0; ! 32: ! 33: /* Message enable level: 0..31 = no..all messages. See NETIF_MSG docs. */ ! 34: static int debug = 2; ! 35: ! 36: /* Maximum events (Rx packets, etc.) to handle at each interrupt. */ ! 37: static int max_interrupt_work = 20; ! 38: ! 39: /* Maximum number of multicast addresses to filter (vs. rx-all-multicast). ! 40: The Starfire has a 512 element hash table based on the Ethernet CRC. */ ! 41: static int multicast_filter_limit = 32; ! 42: ! 43: /* Set the copy breakpoint for the copy-only-tiny-frames scheme. ! 44: Setting to > 1518 effectively disables this feature. */ ! 45: static int rx_copybreak = 0; ! 46: ! 47: /* Used to pass the media type, etc. ! 48: Both 'options[]' and 'full_duplex[]' exist for driver interoperability, ! 49: however full_duplex[] should never be used in new configurations. ! 50: The media type is usually passed in 'options[]'. ! 51: The default is autonegotation for speed and duplex. ! 52: This should rarely be overridden. ! 53: Use option values 0x10/0x20 for 10Mbps, 0x100,0x200 for 100Mbps. ! 54: Use option values 0x10 and 0x100 for forcing half duplex fixed speed. ! 55: Use option values 0x20 and 0x200 for forcing full duplex operation. ! 56: */ ! 57: #define MAX_UNITS 8 /* More are supported, limit only on options */ ! 58: static int options[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1}; ! 59: static int full_duplex[MAX_UNITS] = {-1, -1, -1, -1, -1, -1, -1, -1}; ! 60: ! 61: /* Automatically extracted configuration info: ! 62: probe-func: starfire_probe ! 63: config-in: tristate 'Adaptec DuraLAN ("starfire") series PCI Ethernet support' CONFIG_DURLAN ! 64: ! 65: c-help-name: Adaptec DuraLAN ("starfire") series PCI Ethernet support ! 66: c-help-symbol: CONFIG_DURALAN ! 67: c-help: This driver is for the Adaptec DuraLAN series, the 6915, 62022 ! 68: c-help: and 62044 boards. ! 69: c-help: Design information, usage details and updates are available from ! 70: c-help: http://www.scyld.com/network/starfire.html ! 71: */ ! 72: ! 73: /* Operational parameters that are set at compile time. */ ! 74: ! 75: /* The "native" ring sizes are either 256 or 2048. ! 76: However in some modes a descriptor may be marked to wrap the ring earlier. ! 77: The driver allocates a single page for each descriptor ring, constraining ! 78: the maximum size in an architecture-dependent way. ! 79: */ ! 80: #define RX_RING_SIZE 256 ! 81: #define TX_RING_SIZE 32 ! 82: /* The completion queues are fixed at 1024 entries i.e. 4K or 8KB. */ ! 83: #define DONE_Q_SIZE 1024 ! 84: ! 85: /* Operational parameters that usually are not changed. */ ! 86: /* Time in jiffies before concluding the transmitter is hung. */ ! 87: #define TX_TIMEOUT (6*HZ) ! 88: ! 89: /* Allocation size of Rx buffers with normal sized Ethernet frames. ! 90: Do not change this value without good reason. This is not a limit, ! 91: but a way to keep a consistent allocation size among drivers. ! 92: */ ! 93: #define PKT_BUF_SZ 1536 ! 94: ! 95: #ifndef __KERNEL__ ! 96: #define __KERNEL__ ! 97: #endif ! 98: #if !defined(__OPTIMIZE__) ! 99: #warning You must compile this file with the correct options! ! 100: #warning See the last lines of the source file. ! 101: #error You must compile this driver with "-O". ! 102: #endif ! 103: ! 104: /* Include files, designed to support most kernel versions 2.0.0 and later. */ ! 105: #include <linux/config.h> ! 106: #if defined(CONFIG_SMP) && ! defined(__SMP__) ! 107: #define __SMP__ ! 108: #endif ! 109: #if defined(MODULE) && defined(CONFIG_MODVERSIONS) && ! defined(MODVERSIONS) ! 110: #define MODVERSIONS ! 111: #endif ! 112: ! 113: #include <linux/version.h> ! 114: #if defined(MODVERSIONS) ! 115: #include <linux/modversions.h> ! 116: #endif ! 117: #include <linux/module.h> ! 118: ! 119: #include <linux/kernel.h> ! 120: #include <linux/string.h> ! 121: #include <linux/timer.h> ! 122: #include <linux/errno.h> ! 123: #include <linux/ioport.h> ! 124: #if LINUX_VERSION_CODE >= 0x20400 ! 125: #include <linux/slab.h> ! 126: #else ! 127: #include <linux/malloc.h> ! 128: #endif ! 129: #include <linux/interrupt.h> ! 130: #include <linux/pci.h> ! 131: #include <linux/netdevice.h> ! 132: #include <linux/etherdevice.h> ! 133: #include <linux/skbuff.h> ! 134: #include <asm/processor.h> /* Processor type for cache alignment. */ ! 135: #include <asm/bitops.h> ! 136: #include <asm/io.h> ! 137: ! 138: #ifdef INLINE_PCISCAN ! 139: #include "k_compat.h" ! 140: #else ! 141: #include "pci-scan.h" ! 142: #include "kern_compat.h" ! 143: #endif ! 144: ! 145: /* Condensed operations for readability. ! 146: Compatibility defines are in kern_compat.h */ ! 147: ! 148: #define virt_to_le32desc(addr) cpu_to_le32(virt_to_bus(addr)) ! 149: #define le32desc_to_virt(addr) bus_to_virt(le32_to_cpu(addr)) ! 150: ! 151: #if (LINUX_VERSION_CODE >= 0x20100) && defined(MODULE) ! 152: char kernel_version[] = UTS_RELEASE; ! 153: #endif ! 154: ! 155: MODULE_AUTHOR("Donald Becker <[email protected]>"); ! 156: MODULE_DESCRIPTION("Adaptec Starfire Ethernet driver"); ! 157: MODULE_LICENSE("GPL"); ! 158: MODULE_PARM(debug, "i"); ! 159: MODULE_PARM(options, "1-" __MODULE_STRING(MAX_UNITS) "i"); ! 160: MODULE_PARM(rx_copybreak, "i"); ! 161: MODULE_PARM(full_duplex, "1-" __MODULE_STRING(MAX_UNITS) "i"); ! 162: MODULE_PARM(multicast_filter_limit, "i"); ! 163: MODULE_PARM(max_interrupt_work, "i"); ! 164: MODULE_PARM_DESC(debug, "Driver message enable level (0-31)"); ! 165: MODULE_PARM_DESC(options, "Force transceiver type or fixed speed+duplex"); ! 166: MODULE_PARM_DESC(max_interrupt_work, ! 167: "Driver maximum events handled per interrupt"); ! 168: MODULE_PARM_DESC(full_duplex, ! 169: "Non-zero to set forced full duplex (deprecated)."); ! 170: MODULE_PARM_DESC(rx_copybreak, ! 171: "Breakpoint in bytes for copy-only-tiny-frames"); ! 172: MODULE_PARM_DESC(multicast_filter_limit, ! 173: "Multicast addresses before switching to Rx-all-multicast"); ! 174: ! 175: /* ! 176: Theory of Operation ! 177: ! 178: I. Board Compatibility ! 179: ! 180: This driver is for the Adaptec 6915 DuraLAN "Starfire" 64 bit PCI Ethernet ! 181: adapter, and the multiport boards using the same chip. ! 182: ! 183: II. Board-specific settings ! 184: ! 185: III. Driver operation ! 186: ! 187: IIIa. Ring buffers ! 188: ! 189: The Starfire hardware uses multiple fixed-size descriptor queues/rings. The ! 190: ring sizes are set fixed by the hardware, but may optionally be wrapped ! 191: earlier by the END bit in the descriptor. ! 192: This driver uses that hardware queue size for the Rx ring, where a large ! 193: number of entries has no ill effect beyond increases the potential backlog. ! 194: The Tx ring is wrapped with the END bit, since a large hardware Tx queue ! 195: disables the queue layer priority ordering and we have no mechanism to ! 196: utilize the hardware two-level priority queue. When modifying the ! 197: RX/TX_RING_SIZE pay close attention to page sizes and the ring-empty warning ! 198: levels. ! 199: ! 200: IIIb/c. Transmit/Receive Structure ! 201: ! 202: See the Adaptec manual for the many possible structures, and options for ! 203: each structure. There are far too many to document here. ! 204: ! 205: For transmit this driver uses type 1 transmit descriptors, and relies on ! 206: automatic minimum-length padding. It does not use the completion queue ! 207: consumer index, but instead checks for non-zero status entries. ! 208: ! 209: For receive this driver uses type 0 receive descriptors. The driver ! 210: allocates full frame size skbuffs for the Rx ring buffers, so all frames ! 211: should fit in a single descriptor. The driver does not use the completion ! 212: queue consumer index, but instead checks for non-zero status entries. ! 213: ! 214: When an incoming frame is less than RX_COPYBREAK bytes long, a fresh skbuff ! 215: is allocated and the frame is copied to the new skbuff. When the incoming ! 216: frame is larger, the skbuff is passed directly up the protocol stack. ! 217: Buffers consumed this way are replaced by newly allocated skbuffs in a later ! 218: phase of receive. ! 219: ! 220: A notable aspect of operation is that unaligned buffers are not permitted by ! 221: the Starfire hardware. The IP header at offset 14 in an ethernet frame thus ! 222: isn't longword aligned, which may cause problems on some machine ! 223: e.g. Alphas. Copied frames are put into the skbuff at an offset of "+2", ! 224: 16-byte aligning the IP header. ! 225: ! 226: IIId. Synchronization ! 227: ! 228: The driver runs as two independent, single-threaded flows of control. One ! 229: is the send-packet routine, which enforces single-threaded use by the ! 230: dev->tbusy flag. The other thread is the interrupt handler, which is single ! 231: threaded by the hardware and interrupt handling software. ! 232: ! 233: The send packet thread has partial control over the Tx ring and 'dev->tbusy' ! 234: flag. It sets the tbusy flag whenever it's queuing a Tx packet. If the next ! 235: queue slot is empty, it clears the tbusy flag when finished otherwise it sets ! 236: the 'lp->tx_full' flag. ! 237: ! 238: The interrupt handler has exclusive control over the Rx ring and records stats ! 239: from the Tx ring. After reaping the stats, it marks the Tx queue entry as ! 240: empty by incrementing the dirty_tx mark. Iff the 'lp->tx_full' flag is set, it ! 241: clears both the tx_full and tbusy flags. ! 242: ! 243: IV. Notes ! 244: ! 245: IVb. References ! 246: ! 247: The Adaptec Starfire manuals, available only from Adaptec. ! 248: http://www.scyld.com/expert/100mbps.html ! 249: http://www.scyld.com/expert/NWay.html ! 250: ! 251: IVc. Errata ! 252: ! 253: */ ! 254: ! 255: ! 256: ! 257: static void *starfire_probe1(struct pci_dev *pdev, void *init_dev, ! 258: long ioaddr, int irq, int chip_idx, int find_cnt); ! 259: static int starfire_pwr_event(void *dev_instance, int event); ! 260: enum chip_capability_flags {CanHaveMII=1, }; ! 261: #define PCI_IOTYPE (PCI_USES_MASTER | PCI_USES_MEM | PCI_ADDR0) ! 262: /* And maps in 0.5MB(!) -- no I/O mapping here! */ ! 263: #define MEM_ADDR_SZ 0x80000 ! 264: ! 265: #if 0 && (defined(__x86_64) || defined(__alpha__)) ! 266: /* Enable 64 bit address modes. */ ! 267: #define STARFIRE_ADDR_64BITS 1 ! 268: #endif ! 269: ! 270: static struct pci_id_info pci_id_tbl[] = { ! 271: {"Adaptec Starfire 6915", { 0x69159004, 0xffffffff, }, ! 272: PCI_IOTYPE, MEM_ADDR_SZ, CanHaveMII}, ! 273: {0,}, /* 0 terminated list. */ ! 274: }; ! 275: ! 276: struct drv_id_info starfire_drv_id = { ! 277: "starfire", PCI_HOTSWAP, PCI_CLASS_NETWORK_ETHERNET<<8, pci_id_tbl, ! 278: starfire_probe1, starfire_pwr_event }; ! 279: ! 280: /* Offsets to the device registers. ! 281: Unlike software-only systems, device drivers interact with complex hardware. ! 282: It's not useful to define symbolic names for every register bit in the ! 283: device. The name can only partially document the semantics and make ! 284: the driver longer and more difficult to read. ! 285: In general, only the important configuration values or bits changed ! 286: multiple times should be defined symbolically. ! 287: */ ! 288: enum register_offsets { ! 289: PCIDeviceConfig=0x50040, GenCtrl=0x50070, IntrTimerCtrl=0x50074, ! 290: IntrClear=0x50080, IntrStatus=0x50084, IntrEnable=0x50088, ! 291: MIICtrl=0x52000, StationAddr=0x50120, EEPROMCtrl=0x51000, ! 292: TxDescCtrl=0x50090, ! 293: TxRingPtr=0x50098, HiPriTxRingPtr=0x50094, /* Low and High priority. */ ! 294: TxRingHiAddr=0x5009C, /* 64 bit address extension. */ ! 295: TxProducerIdx=0x500A0, TxConsumerIdx=0x500A4, ! 296: TxThreshold=0x500B0, ! 297: CompletionHiAddr=0x500B4, TxCompletionAddr=0x500B8, ! 298: RxCompletionAddr=0x500BC, RxCompletionQ2Addr=0x500C0, ! 299: CompletionQConsumerIdx=0x500C4, ! 300: RxDescQCtrl=0x500D4, RxDescQHiAddr=0x500DC, RxDescQAddr=0x500E0, ! 301: RxDescQIdx=0x500E8, RxDMAStatus=0x500F0, RxFilterMode=0x500F4, ! 302: TxMode=0x55000, ! 303: }; ! 304: ! 305: /* Bits in the interrupt status/mask registers. */ ! 306: enum intr_status_bits { ! 307: IntrNormalSummary=0x8000, IntrAbnormalSummary=0x02000000, ! 308: IntrRxDone=0x0300, IntrRxEmpty=0x10040, IntrRxPCIErr=0x80000, ! 309: IntrTxDone=0x4000, IntrTxEmpty=0x1000, IntrTxPCIErr=0x80000, ! 310: StatsMax=0x08000000, LinkChange=0xf0000000, ! 311: IntrTxDataLow=0x00040000, ! 312: IntrPCIPin=0x01, ! 313: }; ! 314: ! 315: /* Bits in the RxFilterMode register. */ ! 316: enum rx_mode_bits { ! 317: AcceptBroadcast=0x04, AcceptAllMulticast=0x02, AcceptAll=0x01, ! 318: AcceptMulticast=0x10, AcceptMyPhys=0xE040, ! 319: }; ! 320: ! 321: /* Misc. bits. Symbolic names so that may be searched for. */ ! 322: enum misc_bits { ! 323: ChipResetCmd=1, /* PCIDeviceConfig */ ! 324: PCIIntEnb=0x00800000, /* PCIDeviceConfig */ ! 325: TxEnable=0x0A, RxEnable=0x05, SoftIntr=0x100, /* GenCtrl */ ! 326: }; ! 327: ! 328: /* The Rx and Tx buffer descriptors. */ ! 329: struct starfire_rx_desc { ! 330: u32 rxaddr; /* Optionally 64 bits. */ ! 331: #if defined(STARFIRE_ADDR_64BITS) ! 332: u32 rxaddr_hi; /* Optionally 64 bits. */ ! 333: #endif ! 334: }; ! 335: enum rx_desc_bits { ! 336: RxDescValid=1, RxDescEndRing=2, ! 337: }; ! 338: ! 339: /* Completion queue entry. ! 340: You must update the page allocation, init_ring and the shift count in rx() ! 341: if using a larger format. */ ! 342: struct rx_done_desc { ! 343: u32 status; /* Low 16 bits is length. */ ! 344: #ifdef full_rx_status ! 345: u32 status2; ! 346: u16 vlanid; ! 347: u16 csum; /* partial checksum */ ! 348: u32 timestamp; ! 349: #endif ! 350: }; ! 351: enum rx_done_bits { ! 352: RxOK=0x20000000, RxFIFOErr=0x10000000, RxBufQ2=0x08000000, ! 353: }; ! 354: ! 355: /* Type 1 Tx descriptor. */ ! 356: struct starfire_tx_desc { ! 357: u32 status; /* Upper bits are status, lower 16 length. */ ! 358: u32 addr; ! 359: }; ! 360: enum tx_desc_bits { ! 361: TxDescID=0xB1010000, /* Also marks single fragment, add CRC. */ ! 362: TxDescIntr=0x08000000, TxRingWrap=0x04000000, ! 363: }; ! 364: struct tx_done_report { ! 365: u32 status; /* timestamp, index. */ ! 366: #if 0 ! 367: u32 intrstatus; /* interrupt status */ ! 368: #endif ! 369: }; ! 370: ! 371: #define PRIV_ALIGN 15 /* Required alignment mask */ ! 372: struct netdev_private { ! 373: /* Descriptor rings first for alignment. */ ! 374: struct starfire_rx_desc *rx_ring; ! 375: struct starfire_tx_desc *tx_ring; ! 376: struct net_device *next_module; /* Link for devices of this type. */ ! 377: void *priv_addr; /* Unaligned address for kfree */ ! 378: const char *product_name; ! 379: /* The addresses of rx/tx-in-place skbuffs. */ ! 380: struct sk_buff* rx_skbuff[RX_RING_SIZE]; ! 381: struct sk_buff* tx_skbuff[TX_RING_SIZE]; ! 382: u8 pad0[100]; /* Impact padding */ ! 383: /* Pointers to completion queues (full pages). Cache line pad.. */ ! 384: struct rx_done_desc *rx_done_q __attribute__((aligned (L1_CACHE_BYTES))); ! 385: unsigned int rx_done; ! 386: struct tx_done_report *tx_done_q __attribute__((aligned (L1_CACHE_BYTES))); ! 387: unsigned int tx_done; ! 388: ! 389: struct net_device_stats stats; ! 390: struct timer_list timer; /* Media monitoring timer. */ ! 391: int msg_level; ! 392: int chip_id, drv_flags; ! 393: struct pci_dev *pci_dev; ! 394: /* Frequently used values: keep some adjacent for cache effect. */ ! 395: int max_interrupt_work; ! 396: int intr_enable; ! 397: unsigned int restore_intr_enable:1; /* Set if temporarily masked. */ ! 398: unsigned int polling:1; /* Erk, IRQ err. */ ! 399: ! 400: unsigned int cur_rx, dirty_rx; /* Producer/consumer ring indices */ ! 401: unsigned int rx_buf_sz; /* Based on MTU+slack. */ ! 402: int rx_copybreak; ! 403: ! 404: unsigned int cur_tx, dirty_tx; ! 405: unsigned int tx_full:1; /* The Tx queue is full. */ ! 406: /* These values keep track of the transceiver/media in use. */ ! 407: unsigned int full_duplex:1, /* Full-duplex operation requested. */ ! 408: medialock:1, /* Xcvr set to fixed speed/duplex. */ ! 409: rx_flowctrl:1, ! 410: tx_flowctrl:1; /* Use 802.3x flow control. */ ! 411: unsigned int default_port; /* Last dev->if_port value. */ ! 412: u32 tx_mode; ! 413: u8 tx_threshold; ! 414: u32 cur_rx_mode; ! 415: u16 mc_filter[32]; ! 416: int multicast_filter_limit; ! 417: ! 418: /* MII transceiver section. */ ! 419: int mii_cnt; /* MII device addresses. */ ! 420: u16 advertising; /* NWay media advertisement */ ! 421: unsigned char phys[2]; /* MII device addresses. */ ! 422: }; ! 423: ! 424: static int mdio_read(struct net_device *dev, int phy_id, int location); ! 425: static void mdio_write(struct net_device *dev, int phy_id, int location, ! 426: int value); ! 427: static int netdev_open(struct net_device *dev); ! 428: static int change_mtu(struct net_device *dev, int new_mtu); ! 429: static void check_duplex(struct net_device *dev); ! 430: static void netdev_timer(unsigned long data); ! 431: static void tx_timeout(struct net_device *dev); ! 432: static void init_ring(struct net_device *dev); ! 433: static int start_tx(struct sk_buff *skb, struct net_device *dev); ! 434: static void intr_handler(int irq, void *dev_instance, struct pt_regs *regs); ! 435: static void netdev_error(struct net_device *dev, int intr_status); ! 436: static int netdev_rx(struct net_device *dev); ! 437: static void netdev_error(struct net_device *dev, int intr_status); ! 438: static void set_rx_mode(struct net_device *dev); ! 439: static struct net_device_stats *get_stats(struct net_device *dev); ! 440: static int mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd); ! 441: static int netdev_close(struct net_device *dev); ! 442: ! 443: ! 444: ! 445: /* A list of our installed devices, for removing the driver module. */ ! 446: static struct net_device *root_net_dev = NULL; ! 447: ! 448: #ifndef MODULE ! 449: int starfire_probe(struct net_device *dev) ! 450: { ! 451: if (pci_drv_register(&starfire_drv_id, dev) < 0) ! 452: return -ENODEV; ! 453: printk(KERN_INFO "%s" KERN_INFO "%s", version1, version2); ! 454: return 0; ! 455: } ! 456: #endif ! 457: ! 458: static void *starfire_probe1(struct pci_dev *pdev, void *init_dev, ! 459: long ioaddr, int irq, int chip_idx, int card_idx) ! 460: { ! 461: struct net_device *dev; ! 462: struct netdev_private *np; ! 463: void *priv_mem; ! 464: int i, option = card_idx < MAX_UNITS ? options[card_idx] : 0; ! 465: ! 466: dev = init_etherdev(init_dev, 0); ! 467: if (!dev) ! 468: return NULL; ! 469: ! 470: printk(KERN_INFO "%s: %s at 0x%lx, ", ! 471: dev->name, pci_id_tbl[chip_idx].name, ioaddr); ! 472: ! 473: /* Serial EEPROM reads are hidden by the hardware. */ ! 474: for (i = 0; i < 6; i++) ! 475: dev->dev_addr[i] = readb(ioaddr + EEPROMCtrl + 20-i); ! 476: for (i = 0; i < 5; i++) ! 477: printk("%2.2x:", dev->dev_addr[i]); ! 478: printk("%2.2x, IRQ %d.\n", dev->dev_addr[i], irq); ! 479: ! 480: /* Make certain elements e.g. descriptor lists are aligned. */ ! 481: priv_mem = kmalloc(sizeof(*np) + PRIV_ALIGN, GFP_KERNEL); ! 482: /* Check for the very unlikely case of no memory. */ ! 483: if (priv_mem == NULL) ! 484: return NULL; ! 485: ! 486: /* Reset the chip to erase previous misconfiguration. */ ! 487: writel(ChipResetCmd, ioaddr + PCIDeviceConfig); ! 488: ! 489: dev->base_addr = ioaddr; ! 490: dev->irq = irq; ! 491: ! 492: dev->priv = np = (void *)(((long)priv_mem + PRIV_ALIGN) & ~PRIV_ALIGN); ! 493: memset(np, 0, sizeof(*np)); ! 494: np->priv_addr = priv_mem; ! 495: ! 496: np->next_module = root_net_dev; ! 497: root_net_dev = dev; ! 498: ! 499: np->pci_dev = pdev; ! 500: np->chip_id = chip_idx; ! 501: np->drv_flags = pci_id_tbl[chip_idx].drv_flags; ! 502: np->msg_level = (1 << debug) - 1; ! 503: np->rx_copybreak = rx_copybreak; ! 504: np->max_interrupt_work = max_interrupt_work; ! 505: np->multicast_filter_limit = multicast_filter_limit; ! 506: ! 507: if (dev->mem_start) ! 508: option = dev->mem_start; ! 509: ! 510: if (card_idx < MAX_UNITS && full_duplex[card_idx] > 0) ! 511: np->full_duplex = 1; ! 512: ! 513: if (np->full_duplex) { ! 514: if (np->msg_level & NETIF_MSG_PROBE) ! 515: printk(KERN_INFO "%s: Set to forced full duplex, autonegotiation" ! 516: " disabled.\n", dev->name); ! 517: np->medialock = 1; ! 518: } ! 519: ! 520: /* The chip-specific entries in the device structure. */ ! 521: dev->open = &netdev_open; ! 522: dev->hard_start_xmit = &start_tx; ! 523: dev->stop = &netdev_close; ! 524: dev->get_stats = &get_stats; ! 525: dev->set_multicast_list = &set_rx_mode; ! 526: dev->do_ioctl = &mii_ioctl; ! 527: dev->change_mtu = &change_mtu; ! 528: ! 529: if (np->drv_flags & CanHaveMII) { ! 530: int phy, phy_idx = 0; ! 531: for (phy = 0; phy < 32 && phy_idx < 4; phy++) { ! 532: int mii_status = mdio_read(dev, phy, 1); ! 533: if (mii_status != 0xffff && mii_status != 0x0000) { ! 534: np->phys[phy_idx++] = phy; ! 535: np->advertising = mdio_read(dev, phy, 4); ! 536: if (np->msg_level & NETIF_MSG_PROBE) ! 537: printk(KERN_INFO "%s: MII PHY found at address %d, status " ! 538: "0x%4.4x advertising %4.4x.\n", ! 539: dev->name, phy, mii_status, np->advertising); ! 540: } ! 541: } ! 542: np->mii_cnt = phy_idx; ! 543: } ! 544: ! 545: /* Force the media type after detecting the transceiver. */ ! 546: if (option > 0) { ! 547: if (option & 0x220) ! 548: np->full_duplex = 1; ! 549: np->default_port = option & 0x3ff; ! 550: if (np->default_port & 0x330) { ! 551: np->medialock = 1; ! 552: if (np->msg_level & NETIF_MSG_PROBE) ! 553: printk(KERN_INFO " Forcing %dMbs %s-duplex operation.\n", ! 554: (option & 0x300 ? 100 : 10), ! 555: (np->full_duplex ? "full" : "half")); ! 556: mdio_write(dev, np->phys[0], 0, ! 557: ((option & 0x300) ? 0x2000 : 0) | /* 100mbps? */ ! 558: (np->full_duplex ? 0x0100 : 0)); /* Full duplex? */ ! 559: } ! 560: } ! 561: ! 562: return dev; ! 563: } ! 564: ! 565: ! 566: /* Read the MII Management Data I/O (MDIO) interfaces. */ ! 567: ! 568: static int mdio_read(struct net_device *dev, int phy_id, int location) ! 569: { ! 570: long mdio_addr = dev->base_addr + MIICtrl + (phy_id<<7) + (location<<2); ! 571: int result, boguscnt=1000; ! 572: /* ??? Should we add a busy-wait here? */ ! 573: do ! 574: result = readl(mdio_addr); ! 575: while ((result & 0xC0000000) != 0x80000000 && --boguscnt >= 0); ! 576: return result & 0xffff; ! 577: } ! 578: ! 579: static void mdio_write(struct net_device *dev, int phy_id, int location, int value) ! 580: { ! 581: long mdio_addr = dev->base_addr + MIICtrl + (phy_id<<7) + (location<<2); ! 582: writel(value, mdio_addr); ! 583: /* The busy-wait will occur before a read. */ ! 584: return; ! 585: } ! 586: ! 587: ! 588: static int netdev_open(struct net_device *dev) ! 589: { ! 590: struct netdev_private *np = (struct netdev_private *)dev->priv; ! 591: long ioaddr = dev->base_addr; ! 592: int i; ! 593: ! 594: MOD_INC_USE_COUNT; ! 595: ! 596: if (request_irq(dev->irq, &intr_handler, SA_SHIRQ, dev->name, dev)) { ! 597: MOD_DEC_USE_COUNT; ! 598: return -EAGAIN; ! 599: } ! 600: ! 601: /* We have no reports that indicate we need to reset the chip. ! 602: But to be on the safe side... */ ! 603: /* Disable the Rx and Tx, and reset the chip. */ ! 604: writel(0, ioaddr + GenCtrl); ! 605: writel(ChipResetCmd, ioaddr + PCIDeviceConfig); ! 606: if (np->msg_level & NETIF_MSG_IFUP) ! 607: printk(KERN_DEBUG "%s: netdev_open() irq %d.\n", ! 608: dev->name, dev->irq); ! 609: /* Allocate the various queues, failing gracefully. */ ! 610: if (np->tx_done_q == 0) ! 611: np->tx_done_q = (struct tx_done_report *)get_free_page(GFP_KERNEL); ! 612: if (np->rx_done_q == 0) ! 613: np->rx_done_q = (struct rx_done_desc *)get_free_page(GFP_KERNEL); ! 614: if (np->tx_ring == 0) ! 615: np->tx_ring = (struct starfire_tx_desc *)get_free_page(GFP_KERNEL); ! 616: if (np->rx_ring == 0) ! 617: np->rx_ring = (struct starfire_rx_desc *)get_free_page(GFP_KERNEL); ! 618: if (np->tx_done_q == 0 || np->rx_done_q == 0 ! 619: || np->rx_ring == 0 || np->tx_ring == 0) { ! 620: /* Retain the pages to increase our chances next time. */ ! 621: MOD_DEC_USE_COUNT; ! 622: return -ENOMEM; ! 623: } ! 624: ! 625: init_ring(dev); ! 626: /* Set the size of the Rx buffers. */ ! 627: writel((np->rx_buf_sz<<16) | 0xA000, ioaddr + RxDescQCtrl); ! 628: ! 629: /* Set Tx descriptor to type 1 and padding to 0 bytes. */ ! 630: writel(0x02000401, ioaddr + TxDescCtrl); ! 631: ! 632: #if defined(STARFIRE_ADDR_64BITS) ! 633: writel(virt_to_bus(np->rx_ring) >> 32, ioaddr + RxDescQHiAddr); ! 634: writel(virt_to_bus(np->tx_ring) >> 32, ioaddr + TxRingHiAddr); ! 635: #else ! 636: writel(0, ioaddr + RxDescQHiAddr); ! 637: writel(0, ioaddr + TxRingHiAddr); ! 638: writel(0, ioaddr + CompletionHiAddr); ! 639: #endif ! 640: writel(virt_to_bus(np->rx_ring), ioaddr + RxDescQAddr); ! 641: writel(virt_to_bus(np->tx_ring), ioaddr + TxRingPtr); ! 642: ! 643: writel(virt_to_bus(np->tx_done_q), ioaddr + TxCompletionAddr); ! 644: writel(virt_to_bus(np->rx_done_q), ioaddr + RxCompletionAddr); ! 645: ! 646: if (np->msg_level & NETIF_MSG_IFUP) ! 647: printk(KERN_DEBUG "%s: Filling in the station address.\n", dev->name); ! 648: ! 649: /* Fill both the unused Tx SA register and the Rx perfect filter. */ ! 650: for (i = 0; i < 6; i++) ! 651: writeb(dev->dev_addr[i], ioaddr + StationAddr + 5-i); ! 652: for (i = 0; i < 16; i++) { ! 653: u16 *eaddrs = (u16 *)dev->dev_addr; ! 654: long setup_frm = ioaddr + 0x56000 + i*16; ! 655: writew(cpu_to_be16(eaddrs[2]), setup_frm); setup_frm += 4; ! 656: writew(cpu_to_be16(eaddrs[1]), setup_frm); setup_frm += 4; ! 657: writew(cpu_to_be16(eaddrs[0]), setup_frm); setup_frm += 8; ! 658: } ! 659: ! 660: /* Initialize other registers. */ ! 661: /* Configure the PCI bus bursts and FIFO thresholds. */ ! 662: np->tx_mode = 0; /* Initialized when TxMode set. */ ! 663: np->tx_threshold = 4; ! 664: writel(np->tx_threshold, ioaddr + TxThreshold); ! 665: writel(interrupt_mitigation, ioaddr + IntrTimerCtrl); ! 666: ! 667: if (dev->if_port == 0) ! 668: dev->if_port = np->default_port; ! 669: ! 670: if (np->msg_level & NETIF_MSG_IFUP) ! 671: printk(KERN_DEBUG "%s: Setting the Rx and Tx modes.\n", dev->name); ! 672: set_rx_mode(dev); ! 673: ! 674: np->advertising = mdio_read(dev, np->phys[0], 4); ! 675: check_duplex(dev); ! 676: netif_start_tx_queue(dev); ! 677: ! 678: /* Set the interrupt mask and enable PCI interrupts. */ ! 679: np->intr_enable = IntrRxDone | IntrRxEmpty | IntrRxPCIErr | ! 680: IntrTxDone | IntrTxEmpty | IntrTxPCIErr | ! 681: StatsMax | LinkChange | IntrNormalSummary | IntrAbnormalSummary ! 682: | 0x0010; ! 683: writel(np->intr_enable, ioaddr + IntrEnable); ! 684: writel(PCIIntEnb | readl(ioaddr + PCIDeviceConfig), ! 685: ioaddr + PCIDeviceConfig); ! 686: ! 687: /* Enable the Rx and Tx units. */ ! 688: writel(TxEnable|RxEnable, ioaddr + GenCtrl); ! 689: ! 690: if (np->msg_level & NETIF_MSG_IFUP) ! 691: printk(KERN_DEBUG "%s: Done netdev_open().\n", ! 692: dev->name); ! 693: ! 694: /* Set the timer to check for link beat. */ ! 695: init_timer(&np->timer); ! 696: np->timer.expires = jiffies + 3*HZ; ! 697: np->timer.data = (unsigned long)dev; ! 698: np->timer.function = &netdev_timer; /* timer handler */ ! 699: add_timer(&np->timer); ! 700: ! 701: return 0; ! 702: } ! 703: ! 704: /* The starfire can handle frame sizes up to 64KB, but we arbitrarily ! 705: * limit the size. ! 706: */ ! 707: static int change_mtu(struct net_device *dev, int new_mtu) ! 708: { ! 709: if ((new_mtu < 68) || (new_mtu > 17268)) ! 710: return -EINVAL; ! 711: if (netif_running(dev)) ! 712: return -EBUSY; ! 713: dev->mtu = new_mtu; ! 714: return 0; ! 715: } ! 716: ! 717: static void check_duplex(struct net_device *dev) ! 718: { ! 719: struct netdev_private *np = (struct netdev_private *)dev->priv; ! 720: long ioaddr = dev->base_addr; ! 721: int new_tx_mode; ! 722: ! 723: new_tx_mode = 0x0C04 | (np->tx_flowctrl ? 0x0800:0) ! 724: | (np->rx_flowctrl ? 0x0400:0); ! 725: if (np->medialock) { ! 726: if (np->full_duplex) ! 727: new_tx_mode |= 2; ! 728: } else { ! 729: int mii_reg5 = mdio_read(dev, np->phys[0], 5); ! 730: int negotiated = mii_reg5 & np->advertising; ! 731: int duplex = (negotiated & 0x0100) || (negotiated & 0x01C0) == 0x0040; ! 732: if (duplex) ! 733: new_tx_mode |= 2; ! 734: if (np->full_duplex != duplex) { ! 735: np->full_duplex = duplex; ! 736: if (np->msg_level & NETIF_MSG_LINK) ! 737: printk(KERN_INFO "%s: Setting %s-duplex based on MII #%d" ! 738: " negotiated capability %4.4x.\n", dev->name, ! 739: duplex ? "full" : "half", np->phys[0], negotiated); ! 740: } ! 741: } ! 742: if (new_tx_mode != np->tx_mode) { ! 743: np->tx_mode = new_tx_mode; ! 744: writel(np->tx_mode | 0x8000, ioaddr + TxMode); ! 745: writel(np->tx_mode, ioaddr + TxMode); ! 746: } ! 747: } ! 748: ! 749: /* Check for duplex changes, but mostly check for failures. */ ! 750: static void netdev_timer(unsigned long data) ! 751: { ! 752: struct net_device *dev = (struct net_device *)data; ! 753: struct netdev_private *np = (struct netdev_private *)dev->priv; ! 754: long ioaddr = dev->base_addr; ! 755: int status = readl(ioaddr + IntrStatus); ! 756: static long last_msg = 0; ! 757: ! 758: /* Normally we check only every few seconds. */ ! 759: np->timer.expires = jiffies + 60*HZ; ! 760: ! 761: if (np->msg_level & NETIF_MSG_TIMER) { ! 762: printk(KERN_DEBUG "%s: Media selection timer tick, status %8.8x.\n", ! 763: dev->name, status); ! 764: } ! 765: ! 766: /* Check for a missing chip or failed interrupt line. ! 767: * The latter may be falsely triggered, so we check twice. */ ! 768: if (status == 0xffffffff) { ! 769: if (jiffies - last_msg > 10*HZ) { ! 770: last_msg = jiffies; ! 771: printk(KERN_ERR "%s: The Starfire chip is missing!\n", ! 772: dev->name); ! 773: } ! 774: } else if (np->polling) { ! 775: if (status & IntrPCIPin) { ! 776: intr_handler(dev->irq, dev, 0); ! 777: if (jiffies - last_msg > 10*HZ) { ! 778: printk(KERN_ERR "%s: IRQ %d is still blocked!\n", ! 779: dev->name, dev->irq); ! 780: last_msg = jiffies; ! 781: } ! 782: } else if (jiffies - last_msg > 10*HZ) ! 783: np->polling = 0; ! 784: np->timer.expires = jiffies + 2; ! 785: } else if (status & IntrPCIPin) { ! 786: int new_status = readl(ioaddr + IntrStatus); ! 787: /* Bogus hardware IRQ mapping: Fake an interrupt handler call. */ ! 788: if (new_status & IntrPCIPin) { ! 789: printk(KERN_ERR "%s: IRQ %d is not raising an interrupt! " ! 790: "Status %8.8x/%8.8x. \n", ! 791: dev->name, dev->irq, status, new_status); ! 792: intr_handler(dev->irq, dev, 0); ! 793: np->timer.expires = jiffies + 2; ! 794: np->polling = 1; ! 795: } ! 796: } else if (netif_queue_paused(dev) && ! 797: np->cur_tx - np->dirty_tx > 1 && ! 798: (jiffies - dev->trans_start) > TX_TIMEOUT) { ! 799: /* This will not catch tbusy incorrectly set when the queue is empty, ! 800: * but that state should never occur. */ ! 801: tx_timeout(dev); ! 802: } ! 803: ! 804: check_duplex(dev); ! 805: ! 806: add_timer(&np->timer); ! 807: } ! 808: ! 809: static void tx_timeout(struct net_device *dev) ! 810: { ! 811: struct netdev_private *np = (struct netdev_private *)dev->priv; ! 812: long ioaddr = dev->base_addr; ! 813: ! 814: printk(KERN_WARNING "%s: Transmit timed out, status %8.8x," ! 815: " resetting...\n", dev->name, (int)readl(ioaddr + IntrStatus)); ! 816: ! 817: #if defined(__i386__) ! 818: if (np->msg_level & NETIF_MSG_TX_ERR) { ! 819: int i; ! 820: printk("\n" KERN_DEBUG " Tx ring %p: ", np->tx_ring); ! 821: for (i = 0; i < TX_RING_SIZE; i++) ! 822: printk(" %4.4x", np->tx_ring[i].status); ! 823: printk("\n" KERN_DEBUG " Rx ring %p: ", np->rx_ring); ! 824: for (i = 0; i < RX_RING_SIZE; i++) ! 825: printk(" %8.8x", (unsigned int)np->rx_ring[i].rxaddr); ! 826: printk("\n"); ! 827: } ! 828: #endif ! 829: ! 830: /* If a specific problem is reported, reinitialize the hardware here. */ ! 831: dev->if_port = 0; ! 832: /* Stop and restart the chip's Tx processes . */ ! 833: writel(0, ioaddr + GenCtrl); ! 834: /* Enable the Rx and Tx units. */ ! 835: writel(TxEnable|RxEnable, ioaddr + GenCtrl); ! 836: ! 837: dev->trans_start = jiffies; ! 838: np->stats.tx_errors++; ! 839: return; ! 840: } ! 841: ! 842: ! 843: /* Initialize the Rx and Tx rings, along with various 'dev' bits. */ ! 844: static void init_ring(struct net_device *dev) ! 845: { ! 846: struct netdev_private *np = (struct netdev_private *)dev->priv; ! 847: int i; ! 848: ! 849: np->tx_full = 0; ! 850: np->cur_rx = np->cur_tx = 0; ! 851: np->dirty_rx = np->rx_done = np->dirty_tx = np->tx_done = 0; ! 852: ! 853: np->rx_buf_sz = (dev->mtu <= 1522 ? PKT_BUF_SZ : ! 854: (dev->mtu + 14 + 3) & ~3); /* Round to word. */ ! 855: ! 856: /* Fill in the Rx buffers. Handle allocation failure gracefully. */ ! 857: for (i = 0; i < RX_RING_SIZE; i++) { ! 858: struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz); ! 859: np->rx_skbuff[i] = skb; ! 860: if (skb == NULL) ! 861: break; ! 862: skb->dev = dev; /* Mark as being used by this device. */ ! 863: /* Grrr, we cannot offset to correctly align the IP header. */ ! 864: np->rx_ring[i].rxaddr = ! 865: virt_to_le32desc(skb->tail) | cpu_to_le32(RxDescValid); ! 866: } ! 867: writew(i - 1, dev->base_addr + RxDescQIdx); ! 868: np->dirty_rx = (unsigned int)(i - RX_RING_SIZE); ! 869: ! 870: /* Clear the remainder of the Rx buffer ring. */ ! 871: for ( ; i < RX_RING_SIZE; i++) { ! 872: np->rx_ring[i].rxaddr = 0; ! 873: np->rx_skbuff[i] = 0; ! 874: } ! 875: /* Mark the last entry as wrapping the ring. */ ! 876: np->rx_ring[i-1].rxaddr |= cpu_to_le32(RxDescEndRing); ! 877: ! 878: /* Clear the completion rings. */ ! 879: for (i = 0; i < DONE_Q_SIZE; i++) { ! 880: np->rx_done_q[i].status = 0; ! 881: np->tx_done_q[i].status = 0; ! 882: } ! 883: ! 884: for (i = 0; i < TX_RING_SIZE; i++) { ! 885: np->tx_skbuff[i] = 0; ! 886: np->tx_ring[i].status = 0; ! 887: } ! 888: return; ! 889: } ! 890: ! 891: static int start_tx(struct sk_buff *skb, struct net_device *dev) ! 892: { ! 893: struct netdev_private *np = (struct netdev_private *)dev->priv; ! 894: unsigned entry; ! 895: ! 896: /* Block a timer-based transmit from overlapping. This happens when ! 897: packets are presumed lost, and we use this check the Tx status. */ ! 898: if (netif_pause_tx_queue(dev) != 0) { ! 899: /* This watchdog code is redundant with the media monitor timer. */ ! 900: if (jiffies - dev->trans_start > TX_TIMEOUT) ! 901: tx_timeout(dev); ! 902: return 1; ! 903: } ! 904: ! 905: /* Caution: the write order is important here, set the field ! 906: with the "ownership" bits last. */ ! 907: ! 908: /* Calculate the next Tx descriptor entry. */ ! 909: entry = np->cur_tx % TX_RING_SIZE; ! 910: ! 911: np->tx_skbuff[entry] = skb; ! 912: ! 913: np->tx_ring[entry].addr = virt_to_le32desc(skb->data); ! 914: /* Add "| TxDescIntr" to generate Tx-done interrupts. */ ! 915: np->tx_ring[entry].status = cpu_to_le32(skb->len | TxDescID); ! 916: #if 1 ! 917: if (entry >= TX_RING_SIZE-1) { /* Wrap ring */ ! 918: np->tx_ring[entry].status |= cpu_to_le32(TxRingWrap | TxDescIntr); ! 919: entry = -1; ! 920: } ! 921: #endif ! 922: ! 923: /* On some architectures better performance results by explicitly ! 924: flushing cache lines: pci_flush_virt(skb->data, skb->len); */ ! 925: ! 926: np->cur_tx++; ! 927: /* Update the producer index. */ ! 928: writel(++entry, dev->base_addr + TxProducerIdx); ! 929: ! 930: /* cf. using TX_QUEUE_LEN instead of TX_RING_SIZE here. */ ! 931: if (np->cur_tx - np->dirty_tx >= TX_RING_SIZE - 1) { ! 932: np->tx_full = 1; ! 933: /* Check for the rare case of a just-cleared queue. */ ! 934: if (np->cur_tx - (volatile unsigned int)np->dirty_tx ! 935: < TX_RING_SIZE - 2) { ! 936: np->tx_full = 0; ! 937: netif_unpause_tx_queue(dev); ! 938: } else ! 939: netif_stop_tx_queue(dev); ! 940: } else ! 941: netif_unpause_tx_queue(dev); /* Typical path */ ! 942: ! 943: dev->trans_start = jiffies; ! 944: ! 945: if (np->msg_level & NETIF_MSG_TX_QUEUED) { ! 946: printk(KERN_DEBUG "%s: Tx frame #%d slot %d %8.8x %8.8x.\n", ! 947: dev->name, np->cur_tx, entry, ! 948: np->tx_ring[entry].status, np->tx_ring[entry].addr); ! 949: } ! 950: return 0; ! 951: } ! 952: ! 953: /* The interrupt handler does all of the Rx thread work and cleans up ! 954: after the Tx thread. */ ! 955: static void intr_handler(int irq, void *dev_instance, struct pt_regs *rgs) ! 956: { ! 957: struct net_device *dev = (struct net_device *)dev_instance; ! 958: struct netdev_private *np; ! 959: long ioaddr; ! 960: int boguscnt; ! 961: ! 962: #ifndef final_version /* Can never occur. */ ! 963: if (dev == NULL) { ! 964: printk (KERN_ERR "Netdev interrupt handler(): IRQ %d for unknown " ! 965: "device.\n", irq); ! 966: return; ! 967: } ! 968: #endif ! 969: ! 970: ioaddr = dev->base_addr; ! 971: np = (struct netdev_private *)dev->priv; ! 972: boguscnt = np->max_interrupt_work; ! 973: ! 974: do { ! 975: u32 intr_status = readl(ioaddr + IntrClear); ! 976: ! 977: if (np->msg_level & NETIF_MSG_INTR) ! 978: printk(KERN_DEBUG "%s: Interrupt status %4.4x.\n", ! 979: dev->name, intr_status); ! 980: ! 981: if (intr_status == 0 || intr_status == 0xffffffff) ! 982: break; ! 983: ! 984: if (intr_status & IntrRxDone) ! 985: netdev_rx(dev); ! 986: ! 987: /* Scavenge the skbuff list based on the Tx-done queue. ! 988: There are redundant checks here that may be cleaned up ! 989: after the driver has proven to be reliable. */ ! 990: { ! 991: int consumer = readl(ioaddr + TxConsumerIdx); ! 992: int tx_status; ! 993: if (np->msg_level & NETIF_MSG_INTR) ! 994: printk(KERN_DEBUG "%s: Tx Consumer index is %d.\n", ! 995: dev->name, consumer); ! 996: #if 0 ! 997: if (np->tx_done >= 250 || np->tx_done == 0) ! 998: printk(KERN_DEBUG "%s: Tx completion entry %d is %8.8x, " ! 999: "%d is %8.8x.\n", dev->name, ! 1000: np->tx_done, np->tx_done_q[np->tx_done].status, ! 1001: (np->tx_done+1) & (DONE_Q_SIZE-1), ! 1002: np->tx_done_q[(np->tx_done+1)&(DONE_Q_SIZE-1)].status); ! 1003: #endif ! 1004: while ((tx_status = cpu_to_le32(np->tx_done_q[np->tx_done].status)) ! 1005: != 0) { ! 1006: if (np->msg_level & NETIF_MSG_TX_DONE) ! 1007: printk(KERN_DEBUG "%s: Tx completion entry %d is %8.8x.\n", ! 1008: dev->name, np->tx_done, tx_status); ! 1009: if ((tx_status & 0xe0000000) == 0xa0000000) { ! 1010: np->stats.tx_packets++; ! 1011: } else if ((tx_status & 0xe0000000) == 0x80000000) { ! 1012: u16 entry = tx_status; /* Implicit truncate */ ! 1013: entry >>= 3; ! 1014: /* Scavenge the descriptor. */ ! 1015: if (np->tx_skbuff[entry]) { ! 1016: dev_free_skb_irq(np->tx_skbuff[entry]); ! 1017: } else ! 1018: printk(KERN_WARNING "%s: Null skbuff at entry %d!!!\n", ! 1019: dev->name, entry); ! 1020: np->tx_skbuff[entry] = 0; ! 1021: np->dirty_tx++; ! 1022: } ! 1023: np->tx_done_q[np->tx_done].status = 0; ! 1024: np->tx_done = (np->tx_done+1) & (DONE_Q_SIZE-1); ! 1025: } ! 1026: writew(np->tx_done, ioaddr + CompletionQConsumerIdx + 2); ! 1027: } ! 1028: if (np->tx_full && np->cur_tx - np->dirty_tx < TX_RING_SIZE - 4) { ! 1029: /* The ring is no longer full, allow new TX entries. */ ! 1030: np->tx_full = 0; ! 1031: netif_resume_tx_queue(dev); ! 1032: } ! 1033: ! 1034: /* Abnormal error summary/uncommon events handlers. */ ! 1035: if (intr_status & IntrAbnormalSummary) ! 1036: netdev_error(dev, intr_status); ! 1037: ! 1038: if (--boguscnt < 0) { ! 1039: printk(KERN_WARNING "%s: Too much work at interrupt, " ! 1040: "status=0x%4.4x.\n", ! 1041: dev->name, intr_status); ! 1042: writel(0x0021, ioaddr + IntrTimerCtrl); ! 1043: break; ! 1044: } ! 1045: } while (1); ! 1046: ! 1047: if (np->msg_level & NETIF_MSG_INTR) ! 1048: printk(KERN_DEBUG "%s: exiting interrupt, status=%#4.4x.\n", ! 1049: dev->name, (int)readl(ioaddr + IntrStatus)); ! 1050: ! 1051: return; ! 1052: } ! 1053: ! 1054: /* This routine is logically part of the interrupt handler, but separated ! 1055: for clarity and better register allocation. */ ! 1056: static int netdev_rx(struct net_device *dev) ! 1057: { ! 1058: struct netdev_private *np = (struct netdev_private *)dev->priv; ! 1059: int boguscnt = np->dirty_rx + RX_RING_SIZE - np->cur_rx; ! 1060: u32 desc_status; ! 1061: ! 1062: if (np->rx_done_q == 0) { ! 1063: printk(KERN_ERR "%s: rx_done_q is NULL! rx_done is %d. %p.\n", ! 1064: dev->name, np->rx_done, np->tx_done_q); ! 1065: return 0; ! 1066: } ! 1067: ! 1068: /* If EOP is set on the next entry, it's a new packet. Send it up. */ ! 1069: while ((desc_status = le32_to_cpu(np->rx_done_q[np->rx_done].status)) != 0) { ! 1070: if (np->msg_level & NETIF_MSG_RX_STATUS) ! 1071: printk(KERN_DEBUG " netdev_rx() status of %d was %8.8x.\n", ! 1072: np->rx_done, desc_status); ! 1073: if (--boguscnt < 0) ! 1074: break; ! 1075: if ( ! (desc_status & RxOK)) { ! 1076: /* There was a error. */ ! 1077: if (np->msg_level & NETIF_MSG_RX_ERR) ! 1078: printk(KERN_DEBUG " netdev_rx() Rx error was %8.8x.\n", ! 1079: desc_status); ! 1080: np->stats.rx_errors++; ! 1081: if (desc_status & RxFIFOErr) ! 1082: np->stats.rx_fifo_errors++; ! 1083: } else { ! 1084: struct sk_buff *skb; ! 1085: u16 pkt_len = desc_status; /* Implicitly Truncate */ ! 1086: int entry = (desc_status >> 16) & 0x7ff; ! 1087: ! 1088: #ifndef final_version ! 1089: if (np->msg_level & NETIF_MSG_RX_STATUS) ! 1090: printk(KERN_DEBUG " netdev_rx() normal Rx pkt length %d" ! 1091: ", bogus_cnt %d.\n", ! 1092: pkt_len, boguscnt); ! 1093: #endif ! 1094: /* Check if the packet is long enough to accept without copying ! 1095: to a minimally-sized skbuff. */ ! 1096: if (pkt_len < rx_copybreak ! 1097: && (skb = dev_alloc_skb(pkt_len + 2)) != NULL) { ! 1098: skb->dev = dev; ! 1099: skb_reserve(skb, 2); /* 16 byte align the IP header */ ! 1100: #if HAS_IP_COPYSUM /* Call copy + cksum if available. */ ! 1101: eth_copy_and_sum(skb, np->rx_skbuff[entry]->tail, pkt_len, 0); ! 1102: skb_put(skb, pkt_len); ! 1103: #else ! 1104: memcpy(skb_put(skb, pkt_len), np->rx_skbuff[entry]->tail, ! 1105: pkt_len); ! 1106: #endif ! 1107: } else { ! 1108: char *temp = skb_put(skb = np->rx_skbuff[entry], pkt_len); ! 1109: np->rx_skbuff[entry] = NULL; ! 1110: #ifndef final_version /* Remove after testing. */ ! 1111: if (le32desc_to_virt(np->rx_ring[entry].rxaddr & ~3) != temp) ! 1112: printk(KERN_ERR "%s: Internal fault: The skbuff addresses " ! 1113: "do not match in netdev_rx: %p vs. %p / %p.\n", ! 1114: dev->name, ! 1115: le32desc_to_virt(np->rx_ring[entry].rxaddr), ! 1116: skb->head, temp); ! 1117: #endif ! 1118: } ! 1119: skb->protocol = eth_type_trans(skb, dev); ! 1120: #ifdef full_rx_status ! 1121: if (np->rx_done_q[np->rx_done].status2 & cpu_to_le32(0x01000000)) ! 1122: skb->ip_summed = CHECKSUM_UNNECESSARY; ! 1123: #endif ! 1124: netif_rx(skb); ! 1125: dev->last_rx = jiffies; ! 1126: np->stats.rx_packets++; ! 1127: } ! 1128: np->cur_rx++; ! 1129: np->rx_done_q[np->rx_done].status = 0; ! 1130: np->rx_done = (np->rx_done + 1) & (DONE_Q_SIZE-1); ! 1131: } ! 1132: writew(np->rx_done, dev->base_addr + CompletionQConsumerIdx); ! 1133: ! 1134: /* Refill the Rx ring buffers. */ ! 1135: for (; np->cur_rx - np->dirty_rx > 0; np->dirty_rx++) { ! 1136: struct sk_buff *skb; ! 1137: int entry = np->dirty_rx % RX_RING_SIZE; ! 1138: if (np->rx_skbuff[entry] == NULL) { ! 1139: skb = dev_alloc_skb(np->rx_buf_sz); ! 1140: np->rx_skbuff[entry] = skb; ! 1141: if (skb == NULL) ! 1142: break; /* Better luck next round. */ ! 1143: skb->dev = dev; /* Mark as being used by this device. */ ! 1144: np->rx_ring[entry].rxaddr = ! 1145: virt_to_le32desc(skb->tail) | cpu_to_le32(RxDescValid); ! 1146: } ! 1147: if (entry == RX_RING_SIZE - 1) ! 1148: np->rx_ring[entry].rxaddr |= cpu_to_le32(RxDescEndRing); ! 1149: /* We could defer this until later... */ ! 1150: writew(entry, dev->base_addr + RxDescQIdx); ! 1151: } ! 1152: ! 1153: if ((np->msg_level & NETIF_MSG_RX_STATUS) ! 1154: || memcmp(np->pad0, np->pad0 + 1, sizeof(np->pad0) -1)) ! 1155: printk(KERN_DEBUG " exiting netdev_rx() status of %d was %8.8x %d.\n", ! 1156: np->rx_done, desc_status, ! 1157: memcmp(np->pad0, np->pad0 + 1, sizeof(np->pad0) -1)); ! 1158: ! 1159: return 0; ! 1160: } ! 1161: ! 1162: static void netdev_error(struct net_device *dev, int intr_status) ! 1163: { ! 1164: struct netdev_private *np = (struct netdev_private *)dev->priv; ! 1165: ! 1166: if (intr_status & LinkChange) { ! 1167: int phy_num = np->phys[0]; ! 1168: if (np->msg_level & NETIF_MSG_LINK) ! 1169: printk(KERN_NOTICE "%s: Link changed: Autonegotiation advertising" ! 1170: " %4.4x partner %4.4x.\n", dev->name, ! 1171: mdio_read(dev, phy_num, 4), ! 1172: mdio_read(dev, phy_num, 5)); ! 1173: /* Clear sticky bit. */ ! 1174: mdio_read(dev, phy_num, 1); ! 1175: /* If link beat has returned... */ ! 1176: if (mdio_read(dev, phy_num, 1) & 0x0004) ! 1177: netif_link_up(dev); ! 1178: else ! 1179: netif_link_down(dev); ! 1180: check_duplex(dev); ! 1181: } ! 1182: if (intr_status & StatsMax) { ! 1183: get_stats(dev); ! 1184: } ! 1185: /* Came close to underrunning the Tx FIFO, increase threshold. */ ! 1186: if (intr_status & IntrTxDataLow) ! 1187: writel(++np->tx_threshold, dev->base_addr + TxThreshold); ! 1188: /* Ingore expected normal events, and handled abnormal events. */ ! 1189: if ((intr_status & ! 1190: ~(IntrAbnormalSummary|LinkChange|StatsMax|IntrTxDataLow| 0xFF01)) ! 1191: && (np->msg_level & NETIF_MSG_DRV)) ! 1192: printk(KERN_ERR "%s: Something Wicked happened! %4.4x.\n", ! 1193: dev->name, intr_status); ! 1194: /* Hmmmmm, it's not clear how to recover from PCI faults. */ ! 1195: if (intr_status & IntrTxPCIErr) ! 1196: np->stats.tx_fifo_errors++; ! 1197: if (intr_status & IntrRxPCIErr) ! 1198: np->stats.rx_fifo_errors++; ! 1199: } ! 1200: ! 1201: static struct net_device_stats *get_stats(struct net_device *dev) ! 1202: { ! 1203: long ioaddr = dev->base_addr; ! 1204: struct netdev_private *np = (struct netdev_private *)dev->priv; ! 1205: ! 1206: /* This adapter architecture needs no SMP locks. */ ! 1207: #if LINUX_VERSION_CODE > 0x20119 ! 1208: np->stats.tx_bytes = readl(ioaddr + 0x57010); ! 1209: np->stats.rx_bytes = readl(ioaddr + 0x57044); ! 1210: #endif ! 1211: np->stats.tx_packets = readl(ioaddr + 0x57000); ! 1212: np->stats.tx_aborted_errors = ! 1213: readl(ioaddr + 0x57024) + readl(ioaddr + 0x57028); ! 1214: np->stats.tx_window_errors = readl(ioaddr + 0x57018); ! 1215: np->stats.collisions = readl(ioaddr + 0x57004) + readl(ioaddr + 0x57008); ! 1216: ! 1217: /* The chip only need report frame silently dropped. */ ! 1218: np->stats.rx_dropped += readw(ioaddr + RxDMAStatus); ! 1219: writew(0, ioaddr + RxDMAStatus); ! 1220: np->stats.rx_crc_errors = readl(ioaddr + 0x5703C); ! 1221: np->stats.rx_frame_errors = readl(ioaddr + 0x57040); ! 1222: np->stats.rx_length_errors = readl(ioaddr + 0x57058); ! 1223: np->stats.rx_missed_errors = readl(ioaddr + 0x5707C); ! 1224: ! 1225: return &np->stats; ! 1226: } ! 1227: ! 1228: /* The little-endian AUTODIN II ethernet CRC calculations. ! 1229: A big-endian version is also available. ! 1230: This is slow but compact code. Do not use this routine for bulk data, ! 1231: use a table-based routine instead. ! 1232: This is common code and should be moved to net/core/crc.c. ! 1233: Chips may use the upper or lower CRC bits, and may reverse and/or invert ! 1234: them. Select the endian-ness that results in minimal calculations. ! 1235: */ ! 1236: static unsigned const ethernet_polynomial_le = 0xedb88320U; ! 1237: static inline unsigned ether_crc_le(int length, unsigned char *data) ! 1238: { ! 1239: unsigned int crc = ~0; /* Initial value. */ ! 1240: while(--length >= 0) { ! 1241: unsigned char current_octet = *data++; ! 1242: int bit; ! 1243: for (bit = 8; --bit >= 0; current_octet >>= 1) { ! 1244: if ((crc ^ current_octet) & 1) { ! 1245: crc >>= 1; ! 1246: crc ^= ethernet_polynomial_le; ! 1247: } else ! 1248: crc >>= 1; ! 1249: } ! 1250: } ! 1251: return crc; ! 1252: } ! 1253: ! 1254: static void set_rx_mode(struct net_device *dev) ! 1255: { ! 1256: struct netdev_private *np = (struct netdev_private *)dev->priv; ! 1257: long ioaddr = dev->base_addr; ! 1258: u32 rx_mode; ! 1259: struct dev_mc_list *mclist; ! 1260: int i; ! 1261: ! 1262: if (dev->flags & IFF_PROMISC) { /* Set promiscuous. */ ! 1263: /* Unconditionally log net taps. */ ! 1264: printk(KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name); ! 1265: rx_mode = AcceptBroadcast|AcceptAllMulticast|AcceptAll|AcceptMyPhys; ! 1266: } else if ((dev->mc_count > np->multicast_filter_limit) ! 1267: || (dev->flags & IFF_ALLMULTI)) { ! 1268: /* Too many to match, or accept all multicasts. */ ! 1269: rx_mode = AcceptBroadcast|AcceptAllMulticast|AcceptMyPhys; ! 1270: } else if (dev->mc_count <= 15) { ! 1271: /* Use the 16 element perfect filter. */ ! 1272: long filter_addr = ioaddr + 0x56000 + 1*16; ! 1273: for (i = 1, mclist = dev->mc_list; mclist && i <= dev->mc_count; ! 1274: i++, mclist = mclist->next) { ! 1275: u16 *eaddrs = (u16 *)mclist->dmi_addr; ! 1276: writew(cpu_to_be16(eaddrs[2]), filter_addr); filter_addr += 4; ! 1277: writew(cpu_to_be16(eaddrs[1]), filter_addr); filter_addr += 4; ! 1278: writew(cpu_to_be16(eaddrs[0]), filter_addr); filter_addr += 8; ! 1279: } ! 1280: while (i++ < 16) { ! 1281: writew(0xffff, filter_addr); filter_addr += 4; ! 1282: writew(0xffff, filter_addr); filter_addr += 4; ! 1283: writew(0xffff, filter_addr); filter_addr += 8; ! 1284: } ! 1285: rx_mode = AcceptBroadcast | AcceptMyPhys; ! 1286: } else { ! 1287: /* Must use a multicast hash table. */ ! 1288: long filter_addr; ! 1289: u16 mc_filter[32]; /* Multicast hash filter */ ! 1290: ! 1291: memset(mc_filter, 0, sizeof(mc_filter)); ! 1292: for (i = 0, mclist = dev->mc_list; mclist && i < dev->mc_count; ! 1293: i++, mclist = mclist->next) { ! 1294: set_bit(ether_crc_le(ETH_ALEN, mclist->dmi_addr) >> 23, mc_filter); ! 1295: } ! 1296: /* Clear the perfect filter list. */ ! 1297: filter_addr = ioaddr + 0x56000 + 1*16; ! 1298: for (i = 1; i < 16; i++) { ! 1299: writew(0xffff, filter_addr); filter_addr += 4; ! 1300: writew(0xffff, filter_addr); filter_addr += 4; ! 1301: writew(0xffff, filter_addr); filter_addr += 8; ! 1302: } ! 1303: for (filter_addr=ioaddr + 0x56100, i=0; i < 32; filter_addr+= 16, i++){ ! 1304: np->mc_filter[i] = mc_filter[i]; ! 1305: writew(mc_filter[i], filter_addr); ! 1306: } ! 1307: rx_mode = AcceptBroadcast | AcceptMulticast | AcceptMyPhys; ! 1308: } ! 1309: writel(rx_mode, ioaddr + RxFilterMode); ! 1310: } ! 1311: ! 1312: /* ! 1313: Handle user-level ioctl() calls. ! 1314: We must use two numeric constants as the key because some clueless person ! 1315: changed the value for the symbolic name. ! 1316: */ ! 1317: static int mii_ioctl(struct net_device *dev, struct ifreq *rq, int cmd) ! 1318: { ! 1319: struct netdev_private *np = (struct netdev_private *)dev->priv; ! 1320: u16 *data = (u16 *)&rq->ifr_data; ! 1321: u32 *data32 = (void *)&rq->ifr_data; ! 1322: ! 1323: switch(cmd) { ! 1324: case 0x8947: case 0x89F0: ! 1325: /* SIOCGMIIPHY: Get the address of the PHY in use. */ ! 1326: data[0] = np->phys[0] & 0x1f; ! 1327: /* Fall Through */ ! 1328: case 0x8948: case 0x89F1: ! 1329: /* SIOCGMIIREG: Read the specified MII register. */ ! 1330: data[3] = mdio_read(dev, data[0] & 0x1f, data[1] & 0x1f); ! 1331: return 0; ! 1332: case 0x8949: case 0x89F2: ! 1333: /* SIOCSMIIREG: Write the specified MII register */ ! 1334: if (!capable(CAP_NET_ADMIN)) ! 1335: return -EPERM; ! 1336: if (data[0] == np->phys[0]) { ! 1337: u16 value = data[2]; ! 1338: switch (data[1]) { ! 1339: case 0: ! 1340: /* Check for autonegotiation on or reset. */ ! 1341: np->medialock = (value & 0x9000) ? 0 : 1; ! 1342: if (np->medialock) ! 1343: np->full_duplex = (value & 0x0100) ? 1 : 0; ! 1344: break; ! 1345: case 4: np->advertising = value; break; ! 1346: } ! 1347: check_duplex(dev); ! 1348: } ! 1349: mdio_write(dev, data[0] & 0x1f, data[1] & 0x1f, data[2]); ! 1350: return 0; ! 1351: case SIOCGPARAMS: ! 1352: data32[0] = np->msg_level; ! 1353: data32[1] = np->multicast_filter_limit; ! 1354: data32[2] = np->max_interrupt_work; ! 1355: data32[3] = np->rx_copybreak; ! 1356: return 0; ! 1357: case SIOCSPARAMS: ! 1358: if (!capable(CAP_NET_ADMIN)) ! 1359: return -EPERM; ! 1360: np->msg_level = data32[0]; ! 1361: np->multicast_filter_limit = data32[1]; ! 1362: np->max_interrupt_work = data32[2]; ! 1363: np->rx_copybreak = data32[3]; ! 1364: return 0; ! 1365: default: ! 1366: return -EOPNOTSUPP; ! 1367: } ! 1368: } ! 1369: ! 1370: static int netdev_close(struct net_device *dev) ! 1371: { ! 1372: long ioaddr = dev->base_addr; ! 1373: struct netdev_private *np = (struct netdev_private *)dev->priv; ! 1374: int i; ! 1375: ! 1376: netif_stop_tx_queue(dev); ! 1377: ! 1378: if (np->msg_level & NETIF_MSG_IFDOWN) { ! 1379: printk(KERN_DEBUG "%s: Shutting down ethercard, Intr status %4.4x.\n", ! 1380: dev->name, (int)readl(ioaddr + IntrStatus)); ! 1381: printk(KERN_DEBUG "%s: Queue pointers were Tx %d / %d, Rx %d / %d.\n", ! 1382: dev->name, np->cur_tx, np->dirty_tx, np->cur_rx, np->dirty_rx); ! 1383: } ! 1384: ! 1385: /* Disable interrupts by clearing the interrupt mask. */ ! 1386: writel(0, ioaddr + IntrEnable); ! 1387: ! 1388: /* Stop the chip's Tx and Rx processes. */ ! 1389: writel(0, ioaddr + GenCtrl); ! 1390: ! 1391: del_timer(&np->timer); ! 1392: ! 1393: #ifdef __i386__ ! 1394: if (np->msg_level & NETIF_MSG_IFDOWN) { ! 1395: printk("\n"KERN_DEBUG" Tx ring at %8.8x:\n", ! 1396: (int)virt_to_bus(np->tx_ring)); ! 1397: for (i = 0; i < 8 /* TX_RING_SIZE is huge! */; i++) ! 1398: printk(KERN_DEBUG " #%d desc. %8.8x %8.8x -> %8.8x.\n", ! 1399: i, np->tx_ring[i].status, np->tx_ring[i].addr, ! 1400: np->tx_done_q[i].status); ! 1401: printk(KERN_DEBUG " Rx ring at %8.8x -> %p:\n", ! 1402: (int)virt_to_bus(np->rx_ring), np->rx_done_q); ! 1403: if (np->rx_done_q) ! 1404: for (i = 0; i < 8 /* RX_RING_SIZE */; i++) { ! 1405: printk(KERN_DEBUG " #%d desc. %8.8x -> %8.8x\n", ! 1406: i, np->rx_ring[i].rxaddr, np->rx_done_q[i].status); ! 1407: } ! 1408: } ! 1409: #endif /* __i386__ debugging only */ ! 1410: ! 1411: free_irq(dev->irq, dev); ! 1412: ! 1413: /* Free all the skbuffs in the Rx queue. */ ! 1414: for (i = 0; i < RX_RING_SIZE; i++) { ! 1415: np->rx_ring[i].rxaddr = 0xBADF00D0; /* An invalid address. */ ! 1416: if (np->rx_skbuff[i]) { ! 1417: #if LINUX_VERSION_CODE < 0x20100 ! 1418: np->rx_skbuff[i]->free = 1; ! 1419: #endif ! 1420: dev_free_skb(np->rx_skbuff[i]); ! 1421: } ! 1422: np->rx_skbuff[i] = 0; ! 1423: } ! 1424: for (i = 0; i < TX_RING_SIZE; i++) { ! 1425: if (np->tx_skbuff[i]) ! 1426: dev_free_skb(np->tx_skbuff[i]); ! 1427: np->tx_skbuff[i] = 0; ! 1428: } ! 1429: ! 1430: MOD_DEC_USE_COUNT; ! 1431: ! 1432: return 0; ! 1433: } ! 1434: ! 1435: ! 1436: static int starfire_pwr_event(void *dev_instance, int event) ! 1437: { ! 1438: struct net_device *dev = dev_instance; ! 1439: struct netdev_private *np = (struct netdev_private *)dev->priv; ! 1440: long ioaddr = dev->base_addr; ! 1441: ! 1442: if (np->msg_level & NETIF_MSG_LINK) ! 1443: printk(KERN_DEBUG "%s: Handling power event %d.\n", dev->name, event); ! 1444: switch(event) { ! 1445: case DRV_ATTACH: ! 1446: MOD_INC_USE_COUNT; ! 1447: break; ! 1448: case DRV_SUSPEND: ! 1449: /* Disable interrupts, stop Tx and Rx. */ ! 1450: writel(0x0000, ioaddr + IntrEnable); ! 1451: writel(0, ioaddr + GenCtrl); ! 1452: break; ! 1453: case DRV_RESUME: ! 1454: /* This is incomplete: we must factor start_chip() out of open(). */ ! 1455: writel(np->tx_threshold, ioaddr + TxThreshold); ! 1456: writel(interrupt_mitigation, ioaddr + IntrTimerCtrl); ! 1457: set_rx_mode(dev); ! 1458: writel(np->intr_enable, ioaddr + IntrEnable); ! 1459: writel(TxEnable|RxEnable, ioaddr + GenCtrl); ! 1460: break; ! 1461: case DRV_DETACH: { ! 1462: struct net_device **devp, **next; ! 1463: if (dev->flags & IFF_UP) { ! 1464: /* Some, but not all, kernel versions close automatically. */ ! 1465: dev_close(dev); ! 1466: dev->flags &= ~(IFF_UP|IFF_RUNNING); ! 1467: } ! 1468: unregister_netdev(dev); ! 1469: release_region(dev->base_addr, pci_id_tbl[np->chip_id].io_size); ! 1470: #ifndef USE_IO_OPS ! 1471: iounmap((char *)dev->base_addr); ! 1472: #endif ! 1473: for (devp = &root_net_dev; *devp; devp = next) { ! 1474: next = &((struct netdev_private *)(*devp)->priv)->next_module; ! 1475: if (*devp == dev) { ! 1476: *devp = *next; ! 1477: break; ! 1478: } ! 1479: } ! 1480: if (np->priv_addr) ! 1481: kfree(np->priv_addr); ! 1482: kfree(dev); ! 1483: MOD_DEC_USE_COUNT; ! 1484: break; ! 1485: } ! 1486: } ! 1487: ! 1488: return 0; ! 1489: } ! 1490: ! 1491: ! 1492: #ifdef MODULE ! 1493: int init_module(void) ! 1494: { ! 1495: if (debug >= NETIF_MSG_DRV) /* Emit version even if no cards detected. */ ! 1496: printk(KERN_INFO "%s" KERN_INFO "%s", version1, version2); ! 1497: if (pci_drv_register(&starfire_drv_id, NULL)) { ! 1498: printk(KERN_INFO " No Starfire adapters detected, driver not loaded.\n"); ! 1499: return -ENODEV; ! 1500: } ! 1501: return 0; ! 1502: } ! 1503: ! 1504: void cleanup_module(void) ! 1505: { ! 1506: struct net_device *next_dev; ! 1507: ! 1508: pci_drv_unregister(&starfire_drv_id); ! 1509: ! 1510: /* No need to check MOD_IN_USE, as sys_delete_module() checks. */ ! 1511: while (root_net_dev) { ! 1512: struct netdev_private *np = (void *)(root_net_dev->priv); ! 1513: unregister_netdev(root_net_dev); ! 1514: iounmap((char *)(root_net_dev->base_addr)); ! 1515: next_dev = np->next_module; ! 1516: if (np->tx_done_q) free_page((long)np->tx_done_q); ! 1517: if (np->rx_done_q) free_page((long)np->rx_done_q); ! 1518: if (np->priv_addr) kfree(np->priv_addr); ! 1519: kfree(root_net_dev); ! 1520: root_net_dev = next_dev; ! 1521: } ! 1522: } ! 1523: ! 1524: #endif /* MODULE */ ! 1525: ! 1526: /* ! 1527: * Local variables: ! 1528: * compile-command: "make KERNVER=`uname -r` starfire.o" ! 1529: * compile-cmd: "gcc -DMODULE -Wall -Wstrict-prototypes -O6 -c starfire.c" ! 1530: * simple-compile-command: "gcc -DMODULE -O6 -c starfire.c" ! 1531: * c-indent-level: 4 ! 1532: * c-basic-offset: 4 ! 1533: * tab-width: 4 ! 1534: * End: ! 1535: */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.