Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * forcedeth: Ethernet driver for NVIDIA nForce media access controllers. |
| 3 | * |
| 4 | * Note: This driver is a cleanroom reimplementation based on reverse |
| 5 | * engineered documentation written by Carl-Daniel Hailfinger |
| 6 | * and Andrew de Quincey. It's neither supported nor endorsed |
| 7 | * by NVIDIA Corp. Use at your own risk. |
| 8 | * |
| 9 | * NVIDIA, nForce and other NVIDIA marks are trademarks or registered |
| 10 | * trademarks of NVIDIA Corporation in the United States and other |
| 11 | * countries. |
| 12 | * |
Manfred Spraul | 1836098 | 2005-12-24 14:19:24 +0100 | [diff] [blame] | 13 | * Copyright (C) 2003,4,5 Manfred Spraul |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * Copyright (C) 2004 Andrew de Quincey (wol support) |
| 15 | * Copyright (C) 2004 Carl-Daniel Hailfinger (invalid MAC handling, insane |
| 16 | * IRQ rate fixes, bigendian fixes, cleanups, verification) |
| 17 | * Copyright (c) 2004 NVIDIA Corporation |
| 18 | * |
| 19 | * This program is free software; you can redistribute it and/or modify |
| 20 | * it under the terms of the GNU General Public License as published by |
| 21 | * the Free Software Foundation; either version 2 of the License, or |
| 22 | * (at your option) any later version. |
| 23 | * |
| 24 | * This program is distributed in the hope that it will be useful, |
| 25 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 26 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 27 | * GNU General Public License for more details. |
| 28 | * |
| 29 | * You should have received a copy of the GNU General Public License |
| 30 | * along with this program; if not, write to the Free Software |
| 31 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 32 | * |
| 33 | * Changelog: |
| 34 | * 0.01: 05 Oct 2003: First release that compiles without warnings. |
| 35 | * 0.02: 05 Oct 2003: Fix bug for nv_drain_tx: do not try to free NULL skbs. |
| 36 | * Check all PCI BARs for the register window. |
| 37 | * udelay added to mii_rw. |
| 38 | * 0.03: 06 Oct 2003: Initialize dev->irq. |
| 39 | * 0.04: 07 Oct 2003: Initialize np->lock, reduce handled irqs, add printks. |
| 40 | * 0.05: 09 Oct 2003: printk removed again, irq status print tx_timeout. |
| 41 | * 0.06: 10 Oct 2003: MAC Address read updated, pff flag generation updated, |
| 42 | * irq mask updated |
| 43 | * 0.07: 14 Oct 2003: Further irq mask updates. |
| 44 | * 0.08: 20 Oct 2003: rx_desc.Length initialization added, nv_alloc_rx refill |
| 45 | * added into irq handler, NULL check for drain_ring. |
| 46 | * 0.09: 20 Oct 2003: Basic link speed irq implementation. Only handle the |
| 47 | * requested interrupt sources. |
| 48 | * 0.10: 20 Oct 2003: First cleanup for release. |
| 49 | * 0.11: 21 Oct 2003: hexdump for tx added, rx buffer sizes increased. |
| 50 | * MAC Address init fix, set_multicast cleanup. |
| 51 | * 0.12: 23 Oct 2003: Cleanups for release. |
| 52 | * 0.13: 25 Oct 2003: Limit for concurrent tx packets increased to 10. |
| 53 | * Set link speed correctly. start rx before starting |
| 54 | * tx (nv_start_rx sets the link speed). |
| 55 | * 0.14: 25 Oct 2003: Nic dependant irq mask. |
| 56 | * 0.15: 08 Nov 2003: fix smp deadlock with set_multicast_list during |
| 57 | * open. |
| 58 | * 0.16: 15 Nov 2003: include file cleanup for ppc64, rx buffer size |
| 59 | * increased to 1628 bytes. |
| 60 | * 0.17: 16 Nov 2003: undo rx buffer size increase. Substract 1 from |
| 61 | * the tx length. |
| 62 | * 0.18: 17 Nov 2003: fix oops due to late initialization of dev_stats |
| 63 | * 0.19: 29 Nov 2003: Handle RxNoBuf, detect & handle invalid mac |
| 64 | * addresses, really stop rx if already running |
| 65 | * in nv_start_rx, clean up a bit. |
| 66 | * 0.20: 07 Dec 2003: alloc fixes |
| 67 | * 0.21: 12 Jan 2004: additional alloc fix, nic polling fix. |
| 68 | * 0.22: 19 Jan 2004: reprogram timer to a sane rate, avoid lockup |
| 69 | * on close. |
| 70 | * 0.23: 26 Jan 2004: various small cleanups |
| 71 | * 0.24: 27 Feb 2004: make driver even less anonymous in backtraces |
| 72 | * 0.25: 09 Mar 2004: wol support |
| 73 | * 0.26: 03 Jun 2004: netdriver specific annotation, sparse-related fixes |
| 74 | * 0.27: 19 Jun 2004: Gigabit support, new descriptor rings, |
| 75 | * added CK804/MCP04 device IDs, code fixes |
| 76 | * for registers, link status and other minor fixes. |
| 77 | * 0.28: 21 Jun 2004: Big cleanup, making driver mostly endian safe |
| 78 | * 0.29: 31 Aug 2004: Add backup timer for link change notification. |
| 79 | * 0.30: 25 Sep 2004: rx checksum support for nf 250 Gb. Add rx reset |
| 80 | * into nv_close, otherwise reenabling for wol can |
| 81 | * cause DMA to kfree'd memory. |
| 82 | * 0.31: 14 Nov 2004: ethtool support for getting/setting link |
Ayaz Abdulla | 4ea7f29 | 2005-11-11 08:29:59 -0500 | [diff] [blame] | 83 | * capabilities. |
Manfred Spraul | 22c6d14 | 2005-04-19 21:17:09 +0200 | [diff] [blame] | 84 | * 0.32: 16 Apr 2005: RX_ERROR4 handling added. |
Manfred Spraul | 8f767fc | 2005-06-18 16:27:19 +0200 | [diff] [blame] | 85 | * 0.33: 16 May 2005: Support for MCP51 added. |
| 86 | * 0.34: 18 Jun 2005: Add DEV_NEED_LINKTIMER to all nForce nics. |
Manfred Spraul | f49d16e | 2005-06-26 11:36:52 +0200 | [diff] [blame] | 87 | * 0.35: 26 Jun 2005: Support for MCP55 added. |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 88 | * 0.36: 28 Jun 2005: Add jumbo frame support. |
| 89 | * 0.37: 10 Jul 2005: Additional ethtool support, cleanup of pci id list |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 90 | * 0.38: 16 Jul 2005: tx irq rewrite: Use global flags instead of |
| 91 | * per-packet flags. |
Ayaz Abdulla | 4ea7f29 | 2005-11-11 08:29:59 -0500 | [diff] [blame] | 92 | * 0.39: 18 Jul 2005: Add 64bit descriptor support. |
| 93 | * 0.40: 19 Jul 2005: Add support for mac address change. |
| 94 | * 0.41: 30 Jul 2005: Write back original MAC in nv_close instead |
Manfred Spraul | b3df9f8 | 2005-07-31 18:38:58 +0200 | [diff] [blame] | 95 | * of nv_remove |
Ayaz Abdulla | 4ea7f29 | 2005-11-11 08:29:59 -0500 | [diff] [blame] | 96 | * 0.42: 06 Aug 2005: Fix lack of link speed initialization |
Manfred Spraul | 1b1b3c9 | 2005-08-06 23:47:55 +0200 | [diff] [blame] | 97 | * in the second (and later) nv_open call |
Ayaz Abdulla | 4ea7f29 | 2005-11-11 08:29:59 -0500 | [diff] [blame] | 98 | * 0.43: 10 Aug 2005: Add support for tx checksum. |
| 99 | * 0.44: 20 Aug 2005: Add support for scatter gather and segmentation. |
| 100 | * 0.45: 18 Sep 2005: Remove nv_stop/start_rx from every link check |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 101 | * 0.46: 20 Oct 2005: Add irq optimization modes. |
Ayaz Abdulla | 7a33e45 | 2005-11-11 08:31:11 -0500 | [diff] [blame] | 102 | * 0.47: 26 Oct 2005: Add phyaddr 0 in phy scan. |
Manfred Spraul | 1836098 | 2005-12-24 14:19:24 +0100 | [diff] [blame] | 103 | * 0.48: 24 Dec 2005: Disable TSO, bugfix for pci_map_single |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 104 | * 0.49: 10 Dec 2005: Fix tso for large buffers. |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame^] | 105 | * 0.50: 20 Jan 2006: Add 8021pq tagging support. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | * |
| 107 | * Known bugs: |
| 108 | * We suspect that on some hardware no TX done interrupts are generated. |
| 109 | * This means recovery from netif_stop_queue only happens if the hw timer |
| 110 | * interrupt fires (100 times/second, configurable with NVREG_POLL_DEFAULT) |
| 111 | * and the timer is active in the IRQMask, or if a rx packet arrives by chance. |
| 112 | * If your hardware reliably generates tx done interrupts, then you can remove |
| 113 | * DEV_NEED_TIMERIRQ from the driver_data flags. |
| 114 | * DEV_NEED_TIMERIRQ will not harm you on sane hardware, only generating a few |
| 115 | * superfluous timer interrupts from the nic. |
| 116 | */ |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame^] | 117 | #define FORCEDETH_VERSION "0.50" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | #define DRV_NAME "forcedeth" |
| 119 | |
| 120 | #include <linux/module.h> |
| 121 | #include <linux/types.h> |
| 122 | #include <linux/pci.h> |
| 123 | #include <linux/interrupt.h> |
| 124 | #include <linux/netdevice.h> |
| 125 | #include <linux/etherdevice.h> |
| 126 | #include <linux/delay.h> |
| 127 | #include <linux/spinlock.h> |
| 128 | #include <linux/ethtool.h> |
| 129 | #include <linux/timer.h> |
| 130 | #include <linux/skbuff.h> |
| 131 | #include <linux/mii.h> |
| 132 | #include <linux/random.h> |
| 133 | #include <linux/init.h> |
Manfred Spraul | 22c6d14 | 2005-04-19 21:17:09 +0200 | [diff] [blame] | 134 | #include <linux/if_vlan.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
| 136 | #include <asm/irq.h> |
| 137 | #include <asm/io.h> |
| 138 | #include <asm/uaccess.h> |
| 139 | #include <asm/system.h> |
| 140 | |
| 141 | #if 0 |
| 142 | #define dprintk printk |
| 143 | #else |
| 144 | #define dprintk(x...) do { } while (0) |
| 145 | #endif |
| 146 | |
| 147 | |
| 148 | /* |
| 149 | * Hardware access: |
| 150 | */ |
| 151 | |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 152 | #define DEV_NEED_TIMERIRQ 0x0001 /* set the timer irq flag in the irq mask */ |
| 153 | #define DEV_NEED_LINKTIMER 0x0002 /* poll link settings. Relies on the timer irq */ |
| 154 | #define DEV_HAS_LARGEDESC 0x0004 /* device supports jumbo frames and needs packet format 2 */ |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 155 | #define DEV_HAS_HIGH_DMA 0x0008 /* device supports 64bit dma */ |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 156 | #define DEV_HAS_CHECKSUM 0x0010 /* device supports tx and rx checksum offloads */ |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame^] | 157 | #define DEV_HAS_VLAN 0x0020 /* device supports vlan tagging and striping */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 158 | |
| 159 | enum { |
| 160 | NvRegIrqStatus = 0x000, |
| 161 | #define NVREG_IRQSTAT_MIIEVENT 0x040 |
| 162 | #define NVREG_IRQSTAT_MASK 0x1ff |
| 163 | NvRegIrqMask = 0x004, |
| 164 | #define NVREG_IRQ_RX_ERROR 0x0001 |
| 165 | #define NVREG_IRQ_RX 0x0002 |
| 166 | #define NVREG_IRQ_RX_NOBUF 0x0004 |
| 167 | #define NVREG_IRQ_TX_ERR 0x0008 |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 168 | #define NVREG_IRQ_TX_OK 0x0010 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | #define NVREG_IRQ_TIMER 0x0020 |
| 170 | #define NVREG_IRQ_LINK 0x0040 |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 171 | #define NVREG_IRQ_TX_ERROR 0x0080 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | #define NVREG_IRQ_TX1 0x0100 |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 173 | #define NVREG_IRQMASK_THROUGHPUT 0x00df |
| 174 | #define NVREG_IRQMASK_CPU 0x0040 |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 175 | |
| 176 | #define NVREG_IRQ_UNKNOWN (~(NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_TX_ERR| \ |
| 177 | NVREG_IRQ_TX_OK|NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_TX_ERROR| \ |
| 178 | NVREG_IRQ_TX1)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
| 180 | NvRegUnknownSetupReg6 = 0x008, |
| 181 | #define NVREG_UNKSETUP6_VAL 3 |
| 182 | |
| 183 | /* |
| 184 | * NVREG_POLL_DEFAULT is the interval length of the timer source on the nic |
| 185 | * NVREG_POLL_DEFAULT=97 would result in an interval length of 1 ms |
| 186 | */ |
| 187 | NvRegPollingInterval = 0x00c, |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 188 | #define NVREG_POLL_DEFAULT_THROUGHPUT 970 |
| 189 | #define NVREG_POLL_DEFAULT_CPU 13 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | NvRegMisc1 = 0x080, |
| 191 | #define NVREG_MISC1_HD 0x02 |
| 192 | #define NVREG_MISC1_FORCE 0x3b0f3c |
| 193 | |
| 194 | NvRegTransmitterControl = 0x084, |
| 195 | #define NVREG_XMITCTL_START 0x01 |
| 196 | NvRegTransmitterStatus = 0x088, |
| 197 | #define NVREG_XMITSTAT_BUSY 0x01 |
| 198 | |
| 199 | NvRegPacketFilterFlags = 0x8c, |
| 200 | #define NVREG_PFF_ALWAYS 0x7F0008 |
| 201 | #define NVREG_PFF_PROMISC 0x80 |
| 202 | #define NVREG_PFF_MYADDR 0x20 |
| 203 | |
| 204 | NvRegOffloadConfig = 0x90, |
| 205 | #define NVREG_OFFLOAD_HOMEPHY 0x601 |
| 206 | #define NVREG_OFFLOAD_NORMAL RX_NIC_BUFSIZE |
| 207 | NvRegReceiverControl = 0x094, |
| 208 | #define NVREG_RCVCTL_START 0x01 |
| 209 | NvRegReceiverStatus = 0x98, |
| 210 | #define NVREG_RCVSTAT_BUSY 0x01 |
| 211 | |
| 212 | NvRegRandomSeed = 0x9c, |
| 213 | #define NVREG_RNDSEED_MASK 0x00ff |
| 214 | #define NVREG_RNDSEED_FORCE 0x7f00 |
| 215 | #define NVREG_RNDSEED_FORCE2 0x2d00 |
| 216 | #define NVREG_RNDSEED_FORCE3 0x7400 |
| 217 | |
| 218 | NvRegUnknownSetupReg1 = 0xA0, |
| 219 | #define NVREG_UNKSETUP1_VAL 0x16070f |
| 220 | NvRegUnknownSetupReg2 = 0xA4, |
| 221 | #define NVREG_UNKSETUP2_VAL 0x16 |
| 222 | NvRegMacAddrA = 0xA8, |
| 223 | NvRegMacAddrB = 0xAC, |
| 224 | NvRegMulticastAddrA = 0xB0, |
| 225 | #define NVREG_MCASTADDRA_FORCE 0x01 |
| 226 | NvRegMulticastAddrB = 0xB4, |
| 227 | NvRegMulticastMaskA = 0xB8, |
| 228 | NvRegMulticastMaskB = 0xBC, |
| 229 | |
| 230 | NvRegPhyInterface = 0xC0, |
| 231 | #define PHY_RGMII 0x10000000 |
| 232 | |
| 233 | NvRegTxRingPhysAddr = 0x100, |
| 234 | NvRegRxRingPhysAddr = 0x104, |
| 235 | NvRegRingSizes = 0x108, |
| 236 | #define NVREG_RINGSZ_TXSHIFT 0 |
| 237 | #define NVREG_RINGSZ_RXSHIFT 16 |
| 238 | NvRegUnknownTransmitterReg = 0x10c, |
| 239 | NvRegLinkSpeed = 0x110, |
| 240 | #define NVREG_LINKSPEED_FORCE 0x10000 |
| 241 | #define NVREG_LINKSPEED_10 1000 |
| 242 | #define NVREG_LINKSPEED_100 100 |
| 243 | #define NVREG_LINKSPEED_1000 50 |
| 244 | #define NVREG_LINKSPEED_MASK (0xFFF) |
| 245 | NvRegUnknownSetupReg5 = 0x130, |
| 246 | #define NVREG_UNKSETUP5_BIT31 (1<<31) |
| 247 | NvRegUnknownSetupReg3 = 0x13c, |
| 248 | #define NVREG_UNKSETUP3_VAL1 0x200010 |
| 249 | NvRegTxRxControl = 0x144, |
| 250 | #define NVREG_TXRXCTL_KICK 0x0001 |
| 251 | #define NVREG_TXRXCTL_BIT1 0x0002 |
| 252 | #define NVREG_TXRXCTL_BIT2 0x0004 |
| 253 | #define NVREG_TXRXCTL_IDLE 0x0008 |
| 254 | #define NVREG_TXRXCTL_RESET 0x0010 |
| 255 | #define NVREG_TXRXCTL_RXCHECK 0x0400 |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 256 | #define NVREG_TXRXCTL_DESC_1 0 |
| 257 | #define NVREG_TXRXCTL_DESC_2 0x02100 |
| 258 | #define NVREG_TXRXCTL_DESC_3 0x02200 |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame^] | 259 | #define NVREG_TXRXCTL_VLANSTRIP 0x00040 |
| 260 | #define NVREG_TXRXCTL_VLANINS 0x00080 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | NvRegMIIStatus = 0x180, |
| 262 | #define NVREG_MIISTAT_ERROR 0x0001 |
| 263 | #define NVREG_MIISTAT_LINKCHANGE 0x0008 |
| 264 | #define NVREG_MIISTAT_MASK 0x000f |
| 265 | #define NVREG_MIISTAT_MASK2 0x000f |
| 266 | NvRegUnknownSetupReg4 = 0x184, |
| 267 | #define NVREG_UNKSETUP4_VAL 8 |
| 268 | |
| 269 | NvRegAdapterControl = 0x188, |
| 270 | #define NVREG_ADAPTCTL_START 0x02 |
| 271 | #define NVREG_ADAPTCTL_LINKUP 0x04 |
| 272 | #define NVREG_ADAPTCTL_PHYVALID 0x40000 |
| 273 | #define NVREG_ADAPTCTL_RUNNING 0x100000 |
| 274 | #define NVREG_ADAPTCTL_PHYSHIFT 24 |
| 275 | NvRegMIISpeed = 0x18c, |
| 276 | #define NVREG_MIISPEED_BIT8 (1<<8) |
| 277 | #define NVREG_MIIDELAY 5 |
| 278 | NvRegMIIControl = 0x190, |
| 279 | #define NVREG_MIICTL_INUSE 0x08000 |
| 280 | #define NVREG_MIICTL_WRITE 0x00400 |
| 281 | #define NVREG_MIICTL_ADDRSHIFT 5 |
| 282 | NvRegMIIData = 0x194, |
| 283 | NvRegWakeUpFlags = 0x200, |
| 284 | #define NVREG_WAKEUPFLAGS_VAL 0x7770 |
| 285 | #define NVREG_WAKEUPFLAGS_BUSYSHIFT 24 |
| 286 | #define NVREG_WAKEUPFLAGS_ENABLESHIFT 16 |
| 287 | #define NVREG_WAKEUPFLAGS_D3SHIFT 12 |
| 288 | #define NVREG_WAKEUPFLAGS_D2SHIFT 8 |
| 289 | #define NVREG_WAKEUPFLAGS_D1SHIFT 4 |
| 290 | #define NVREG_WAKEUPFLAGS_D0SHIFT 0 |
| 291 | #define NVREG_WAKEUPFLAGS_ACCEPT_MAGPAT 0x01 |
| 292 | #define NVREG_WAKEUPFLAGS_ACCEPT_WAKEUPPAT 0x02 |
| 293 | #define NVREG_WAKEUPFLAGS_ACCEPT_LINKCHANGE 0x04 |
| 294 | #define NVREG_WAKEUPFLAGS_ENABLE 0x1111 |
| 295 | |
| 296 | NvRegPatternCRC = 0x204, |
| 297 | NvRegPatternMask = 0x208, |
| 298 | NvRegPowerCap = 0x268, |
| 299 | #define NVREG_POWERCAP_D3SUPP (1<<30) |
| 300 | #define NVREG_POWERCAP_D2SUPP (1<<26) |
| 301 | #define NVREG_POWERCAP_D1SUPP (1<<25) |
| 302 | NvRegPowerState = 0x26c, |
| 303 | #define NVREG_POWERSTATE_POWEREDUP 0x8000 |
| 304 | #define NVREG_POWERSTATE_VALID 0x0100 |
| 305 | #define NVREG_POWERSTATE_MASK 0x0003 |
| 306 | #define NVREG_POWERSTATE_D0 0x0000 |
| 307 | #define NVREG_POWERSTATE_D1 0x0001 |
| 308 | #define NVREG_POWERSTATE_D2 0x0002 |
| 309 | #define NVREG_POWERSTATE_D3 0x0003 |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame^] | 310 | NvRegVlanControl = 0x300, |
| 311 | #define NVREG_VLANCONTROL_ENABLE 0x2000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | }; |
| 313 | |
| 314 | /* Big endian: should work, but is untested */ |
| 315 | struct ring_desc { |
| 316 | u32 PacketBuffer; |
| 317 | u32 FlagLen; |
| 318 | }; |
| 319 | |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 320 | struct ring_desc_ex { |
| 321 | u32 PacketBufferHigh; |
| 322 | u32 PacketBufferLow; |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame^] | 323 | u32 TxVlan; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 324 | u32 FlagLen; |
| 325 | }; |
| 326 | |
| 327 | typedef union _ring_type { |
| 328 | struct ring_desc* orig; |
| 329 | struct ring_desc_ex* ex; |
| 330 | } ring_type; |
| 331 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | #define FLAG_MASK_V1 0xffff0000 |
| 333 | #define FLAG_MASK_V2 0xffffc000 |
| 334 | #define LEN_MASK_V1 (0xffffffff ^ FLAG_MASK_V1) |
| 335 | #define LEN_MASK_V2 (0xffffffff ^ FLAG_MASK_V2) |
| 336 | |
| 337 | #define NV_TX_LASTPACKET (1<<16) |
| 338 | #define NV_TX_RETRYERROR (1<<19) |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 339 | #define NV_TX_FORCED_INTERRUPT (1<<24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | #define NV_TX_DEFERRED (1<<26) |
| 341 | #define NV_TX_CARRIERLOST (1<<27) |
| 342 | #define NV_TX_LATECOLLISION (1<<28) |
| 343 | #define NV_TX_UNDERFLOW (1<<29) |
| 344 | #define NV_TX_ERROR (1<<30) |
| 345 | #define NV_TX_VALID (1<<31) |
| 346 | |
| 347 | #define NV_TX2_LASTPACKET (1<<29) |
| 348 | #define NV_TX2_RETRYERROR (1<<18) |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 349 | #define NV_TX2_FORCED_INTERRUPT (1<<30) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | #define NV_TX2_DEFERRED (1<<25) |
| 351 | #define NV_TX2_CARRIERLOST (1<<26) |
| 352 | #define NV_TX2_LATECOLLISION (1<<27) |
| 353 | #define NV_TX2_UNDERFLOW (1<<28) |
| 354 | /* error and valid are the same for both */ |
| 355 | #define NV_TX2_ERROR (1<<30) |
| 356 | #define NV_TX2_VALID (1<<31) |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 357 | #define NV_TX2_TSO (1<<28) |
| 358 | #define NV_TX2_TSO_SHIFT 14 |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 359 | #define NV_TX2_TSO_MAX_SHIFT 14 |
| 360 | #define NV_TX2_TSO_MAX_SIZE (1<<NV_TX2_TSO_MAX_SHIFT) |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 361 | #define NV_TX2_CHECKSUM_L3 (1<<27) |
| 362 | #define NV_TX2_CHECKSUM_L4 (1<<26) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame^] | 364 | #define NV_TX3_VLAN_TAG_PRESENT (1<<18) |
| 365 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | #define NV_RX_DESCRIPTORVALID (1<<16) |
| 367 | #define NV_RX_MISSEDFRAME (1<<17) |
| 368 | #define NV_RX_SUBSTRACT1 (1<<18) |
| 369 | #define NV_RX_ERROR1 (1<<23) |
| 370 | #define NV_RX_ERROR2 (1<<24) |
| 371 | #define NV_RX_ERROR3 (1<<25) |
| 372 | #define NV_RX_ERROR4 (1<<26) |
| 373 | #define NV_RX_CRCERR (1<<27) |
| 374 | #define NV_RX_OVERFLOW (1<<28) |
| 375 | #define NV_RX_FRAMINGERR (1<<29) |
| 376 | #define NV_RX_ERROR (1<<30) |
| 377 | #define NV_RX_AVAIL (1<<31) |
| 378 | |
| 379 | #define NV_RX2_CHECKSUMMASK (0x1C000000) |
| 380 | #define NV_RX2_CHECKSUMOK1 (0x10000000) |
| 381 | #define NV_RX2_CHECKSUMOK2 (0x14000000) |
| 382 | #define NV_RX2_CHECKSUMOK3 (0x18000000) |
| 383 | #define NV_RX2_DESCRIPTORVALID (1<<29) |
| 384 | #define NV_RX2_SUBSTRACT1 (1<<25) |
| 385 | #define NV_RX2_ERROR1 (1<<18) |
| 386 | #define NV_RX2_ERROR2 (1<<19) |
| 387 | #define NV_RX2_ERROR3 (1<<20) |
| 388 | #define NV_RX2_ERROR4 (1<<21) |
| 389 | #define NV_RX2_CRCERR (1<<22) |
| 390 | #define NV_RX2_OVERFLOW (1<<23) |
| 391 | #define NV_RX2_FRAMINGERR (1<<24) |
| 392 | /* error and avail are the same for both */ |
| 393 | #define NV_RX2_ERROR (1<<30) |
| 394 | #define NV_RX2_AVAIL (1<<31) |
| 395 | |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame^] | 396 | #define NV_RX3_VLAN_TAG_PRESENT (1<<16) |
| 397 | #define NV_RX3_VLAN_TAG_MASK (0x0000FFFF) |
| 398 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 399 | /* Miscelaneous hardware related defines: */ |
| 400 | #define NV_PCI_REGSZ 0x270 |
| 401 | |
| 402 | /* various timeout delays: all in usec */ |
| 403 | #define NV_TXRX_RESET_DELAY 4 |
| 404 | #define NV_TXSTOP_DELAY1 10 |
| 405 | #define NV_TXSTOP_DELAY1MAX 500000 |
| 406 | #define NV_TXSTOP_DELAY2 100 |
| 407 | #define NV_RXSTOP_DELAY1 10 |
| 408 | #define NV_RXSTOP_DELAY1MAX 500000 |
| 409 | #define NV_RXSTOP_DELAY2 100 |
| 410 | #define NV_SETUP5_DELAY 5 |
| 411 | #define NV_SETUP5_DELAYMAX 50000 |
| 412 | #define NV_POWERUP_DELAY 5 |
| 413 | #define NV_POWERUP_DELAYMAX 5000 |
| 414 | #define NV_MIIBUSY_DELAY 50 |
| 415 | #define NV_MIIPHY_DELAY 10 |
| 416 | #define NV_MIIPHY_DELAYMAX 10000 |
| 417 | |
| 418 | #define NV_WAKEUPPATTERNS 5 |
| 419 | #define NV_WAKEUPMASKENTRIES 4 |
| 420 | |
| 421 | /* General driver defaults */ |
| 422 | #define NV_WATCHDOG_TIMEO (5*HZ) |
| 423 | |
| 424 | #define RX_RING 128 |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 425 | #define TX_RING 256 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | /* |
| 427 | * If your nic mysteriously hangs then try to reduce the limits |
| 428 | * to 1/0: It might be required to set NV_TX_LASTPACKET in the |
| 429 | * last valid ring entry. But this would be impossible to |
| 430 | * implement - probably a disassembly error. |
| 431 | */ |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 432 | #define TX_LIMIT_STOP 255 |
| 433 | #define TX_LIMIT_START 254 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | |
| 435 | /* rx/tx mac addr + type + vlan + align + slack*/ |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 436 | #define NV_RX_HEADERS (64) |
| 437 | /* even more slack. */ |
| 438 | #define NV_RX_ALLOC_PAD (64) |
| 439 | |
| 440 | /* maximum mtu size */ |
| 441 | #define NV_PKTLIMIT_1 ETH_DATA_LEN /* hard limit not known */ |
| 442 | #define NV_PKTLIMIT_2 9100 /* Actual limit according to NVidia: 9202 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | |
| 444 | #define OOM_REFILL (1+HZ/20) |
| 445 | #define POLL_WAIT (1+HZ/100) |
| 446 | #define LINK_TIMEOUT (3*HZ) |
| 447 | |
| 448 | /* |
| 449 | * desc_ver values: |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 450 | * The nic supports three different descriptor types: |
| 451 | * - DESC_VER_1: Original |
| 452 | * - DESC_VER_2: support for jumbo frames. |
| 453 | * - DESC_VER_3: 64-bit format. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | */ |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 455 | #define DESC_VER_1 1 |
| 456 | #define DESC_VER_2 2 |
| 457 | #define DESC_VER_3 3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | |
| 459 | /* PHY defines */ |
| 460 | #define PHY_OUI_MARVELL 0x5043 |
| 461 | #define PHY_OUI_CICADA 0x03f1 |
| 462 | #define PHYID1_OUI_MASK 0x03ff |
| 463 | #define PHYID1_OUI_SHFT 6 |
| 464 | #define PHYID2_OUI_MASK 0xfc00 |
| 465 | #define PHYID2_OUI_SHFT 10 |
| 466 | #define PHY_INIT1 0x0f000 |
| 467 | #define PHY_INIT2 0x0e00 |
| 468 | #define PHY_INIT3 0x01000 |
| 469 | #define PHY_INIT4 0x0200 |
| 470 | #define PHY_INIT5 0x0004 |
| 471 | #define PHY_INIT6 0x02000 |
| 472 | #define PHY_GIGABIT 0x0100 |
| 473 | |
| 474 | #define PHY_TIMEOUT 0x1 |
| 475 | #define PHY_ERROR 0x2 |
| 476 | |
| 477 | #define PHY_100 0x1 |
| 478 | #define PHY_1000 0x2 |
| 479 | #define PHY_HALF 0x100 |
| 480 | |
| 481 | /* FIXME: MII defines that should be added to <linux/mii.h> */ |
| 482 | #define MII_1000BT_CR 0x09 |
| 483 | #define MII_1000BT_SR 0x0a |
| 484 | #define ADVERTISE_1000FULL 0x0200 |
| 485 | #define ADVERTISE_1000HALF 0x0100 |
| 486 | #define LPA_1000FULL 0x0800 |
| 487 | #define LPA_1000HALF 0x0400 |
| 488 | |
| 489 | |
| 490 | /* |
| 491 | * SMP locking: |
| 492 | * All hardware access under dev->priv->lock, except the performance |
| 493 | * critical parts: |
| 494 | * - rx is (pseudo-) lockless: it relies on the single-threading provided |
| 495 | * by the arch code for interrupts. |
| 496 | * - tx setup is lockless: it relies on dev->xmit_lock. Actual submission |
| 497 | * needs dev->priv->lock :-( |
| 498 | * - set_multicast_list: preparation lockless, relies on dev->xmit_lock. |
| 499 | */ |
| 500 | |
| 501 | /* in dev: base, irq */ |
| 502 | struct fe_priv { |
| 503 | spinlock_t lock; |
| 504 | |
| 505 | /* General data: |
| 506 | * Locking: spin_lock(&np->lock); */ |
| 507 | struct net_device_stats stats; |
| 508 | int in_shutdown; |
| 509 | u32 linkspeed; |
| 510 | int duplex; |
| 511 | int autoneg; |
| 512 | int fixed_mode; |
| 513 | int phyaddr; |
| 514 | int wolenabled; |
| 515 | unsigned int phy_oui; |
| 516 | u16 gigabit; |
| 517 | |
| 518 | /* General data: RO fields */ |
| 519 | dma_addr_t ring_addr; |
| 520 | struct pci_dev *pci_dev; |
| 521 | u32 orig_mac[2]; |
| 522 | u32 irqmask; |
| 523 | u32 desc_ver; |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 524 | u32 txrxctl_bits; |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame^] | 525 | u32 vlanctl_bits; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | |
| 527 | void __iomem *base; |
| 528 | |
| 529 | /* rx specific fields. |
| 530 | * Locking: Within irq hander or disable_irq+spin_lock(&np->lock); |
| 531 | */ |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 532 | ring_type rx_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | unsigned int cur_rx, refill_rx; |
| 534 | struct sk_buff *rx_skbuff[RX_RING]; |
| 535 | dma_addr_t rx_dma[RX_RING]; |
| 536 | unsigned int rx_buf_sz; |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 537 | unsigned int pkt_limit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | struct timer_list oom_kick; |
| 539 | struct timer_list nic_poll; |
| 540 | |
| 541 | /* media detection workaround. |
| 542 | * Locking: Within irq hander or disable_irq+spin_lock(&np->lock); |
| 543 | */ |
| 544 | int need_linktimer; |
| 545 | unsigned long link_timeout; |
| 546 | /* |
| 547 | * tx specific fields. |
| 548 | */ |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 549 | ring_type tx_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 550 | unsigned int next_tx, nic_tx; |
| 551 | struct sk_buff *tx_skbuff[TX_RING]; |
| 552 | dma_addr_t tx_dma[TX_RING]; |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 553 | unsigned int tx_dma_len[TX_RING]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | u32 tx_flags; |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame^] | 555 | |
| 556 | /* vlan fields */ |
| 557 | struct vlan_group *vlangrp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | }; |
| 559 | |
| 560 | /* |
| 561 | * Maximum number of loops until we assume that a bit in the irq mask |
| 562 | * is stuck. Overridable with module param. |
| 563 | */ |
| 564 | static int max_interrupt_work = 5; |
| 565 | |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 566 | /* |
| 567 | * Optimization can be either throuput mode or cpu mode |
| 568 | * |
| 569 | * Throughput Mode: Every tx and rx packet will generate an interrupt. |
| 570 | * CPU Mode: Interrupts are controlled by a timer. |
| 571 | */ |
| 572 | #define NV_OPTIMIZATION_MODE_THROUGHPUT 0 |
| 573 | #define NV_OPTIMIZATION_MODE_CPU 1 |
| 574 | static int optimization_mode = NV_OPTIMIZATION_MODE_THROUGHPUT; |
| 575 | |
| 576 | /* |
| 577 | * Poll interval for timer irq |
| 578 | * |
| 579 | * This interval determines how frequent an interrupt is generated. |
| 580 | * The is value is determined by [(time_in_micro_secs * 100) / (2^10)] |
| 581 | * Min = 0, and Max = 65535 |
| 582 | */ |
| 583 | static int poll_interval = -1; |
| 584 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | static inline struct fe_priv *get_nvpriv(struct net_device *dev) |
| 586 | { |
| 587 | return netdev_priv(dev); |
| 588 | } |
| 589 | |
| 590 | static inline u8 __iomem *get_hwbase(struct net_device *dev) |
| 591 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 592 | return ((struct fe_priv *)netdev_priv(dev))->base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | } |
| 594 | |
| 595 | static inline void pci_push(u8 __iomem *base) |
| 596 | { |
| 597 | /* force out pending posted writes */ |
| 598 | readl(base); |
| 599 | } |
| 600 | |
| 601 | static inline u32 nv_descr_getlength(struct ring_desc *prd, u32 v) |
| 602 | { |
| 603 | return le32_to_cpu(prd->FlagLen) |
| 604 | & ((v == DESC_VER_1) ? LEN_MASK_V1 : LEN_MASK_V2); |
| 605 | } |
| 606 | |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 607 | static inline u32 nv_descr_getlength_ex(struct ring_desc_ex *prd, u32 v) |
| 608 | { |
| 609 | return le32_to_cpu(prd->FlagLen) & LEN_MASK_V2; |
| 610 | } |
| 611 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | static int reg_delay(struct net_device *dev, int offset, u32 mask, u32 target, |
| 613 | int delay, int delaymax, const char *msg) |
| 614 | { |
| 615 | u8 __iomem *base = get_hwbase(dev); |
| 616 | |
| 617 | pci_push(base); |
| 618 | do { |
| 619 | udelay(delay); |
| 620 | delaymax -= delay; |
| 621 | if (delaymax < 0) { |
| 622 | if (msg) |
| 623 | printk(msg); |
| 624 | return 1; |
| 625 | } |
| 626 | } while ((readl(base + offset) & mask) != target); |
| 627 | return 0; |
| 628 | } |
| 629 | |
| 630 | #define MII_READ (-1) |
| 631 | /* mii_rw: read/write a register on the PHY. |
| 632 | * |
| 633 | * Caller must guarantee serialization |
| 634 | */ |
| 635 | static int mii_rw(struct net_device *dev, int addr, int miireg, int value) |
| 636 | { |
| 637 | u8 __iomem *base = get_hwbase(dev); |
| 638 | u32 reg; |
| 639 | int retval; |
| 640 | |
| 641 | writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus); |
| 642 | |
| 643 | reg = readl(base + NvRegMIIControl); |
| 644 | if (reg & NVREG_MIICTL_INUSE) { |
| 645 | writel(NVREG_MIICTL_INUSE, base + NvRegMIIControl); |
| 646 | udelay(NV_MIIBUSY_DELAY); |
| 647 | } |
| 648 | |
| 649 | reg = (addr << NVREG_MIICTL_ADDRSHIFT) | miireg; |
| 650 | if (value != MII_READ) { |
| 651 | writel(value, base + NvRegMIIData); |
| 652 | reg |= NVREG_MIICTL_WRITE; |
| 653 | } |
| 654 | writel(reg, base + NvRegMIIControl); |
| 655 | |
| 656 | if (reg_delay(dev, NvRegMIIControl, NVREG_MIICTL_INUSE, 0, |
| 657 | NV_MIIPHY_DELAY, NV_MIIPHY_DELAYMAX, NULL)) { |
| 658 | dprintk(KERN_DEBUG "%s: mii_rw of reg %d at PHY %d timed out.\n", |
| 659 | dev->name, miireg, addr); |
| 660 | retval = -1; |
| 661 | } else if (value != MII_READ) { |
| 662 | /* it was a write operation - fewer failures are detectable */ |
| 663 | dprintk(KERN_DEBUG "%s: mii_rw wrote 0x%x to reg %d at PHY %d\n", |
| 664 | dev->name, value, miireg, addr); |
| 665 | retval = 0; |
| 666 | } else if (readl(base + NvRegMIIStatus) & NVREG_MIISTAT_ERROR) { |
| 667 | dprintk(KERN_DEBUG "%s: mii_rw of reg %d at PHY %d failed.\n", |
| 668 | dev->name, miireg, addr); |
| 669 | retval = -1; |
| 670 | } else { |
| 671 | retval = readl(base + NvRegMIIData); |
| 672 | dprintk(KERN_DEBUG "%s: mii_rw read from reg %d at PHY %d: 0x%x.\n", |
| 673 | dev->name, miireg, addr, retval); |
| 674 | } |
| 675 | |
| 676 | return retval; |
| 677 | } |
| 678 | |
| 679 | static int phy_reset(struct net_device *dev) |
| 680 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 681 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | u32 miicontrol; |
| 683 | unsigned int tries = 0; |
| 684 | |
| 685 | miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
| 686 | miicontrol |= BMCR_RESET; |
| 687 | if (mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol)) { |
| 688 | return -1; |
| 689 | } |
| 690 | |
| 691 | /* wait for 500ms */ |
| 692 | msleep(500); |
| 693 | |
| 694 | /* must wait till reset is deasserted */ |
| 695 | while (miicontrol & BMCR_RESET) { |
| 696 | msleep(10); |
| 697 | miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
| 698 | /* FIXME: 100 tries seem excessive */ |
| 699 | if (tries++ > 100) |
| 700 | return -1; |
| 701 | } |
| 702 | return 0; |
| 703 | } |
| 704 | |
| 705 | static int phy_init(struct net_device *dev) |
| 706 | { |
| 707 | struct fe_priv *np = get_nvpriv(dev); |
| 708 | u8 __iomem *base = get_hwbase(dev); |
| 709 | u32 phyinterface, phy_reserved, mii_status, mii_control, mii_control_1000,reg; |
| 710 | |
| 711 | /* set advertise register */ |
| 712 | reg = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ); |
| 713 | reg |= (ADVERTISE_10HALF|ADVERTISE_10FULL|ADVERTISE_100HALF|ADVERTISE_100FULL|0x800|0x400); |
| 714 | if (mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg)) { |
| 715 | printk(KERN_INFO "%s: phy write to advertise failed.\n", pci_name(np->pci_dev)); |
| 716 | return PHY_ERROR; |
| 717 | } |
| 718 | |
| 719 | /* get phy interface type */ |
| 720 | phyinterface = readl(base + NvRegPhyInterface); |
| 721 | |
| 722 | /* see if gigabit phy */ |
| 723 | mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ); |
| 724 | if (mii_status & PHY_GIGABIT) { |
| 725 | np->gigabit = PHY_GIGABIT; |
| 726 | mii_control_1000 = mii_rw(dev, np->phyaddr, MII_1000BT_CR, MII_READ); |
| 727 | mii_control_1000 &= ~ADVERTISE_1000HALF; |
| 728 | if (phyinterface & PHY_RGMII) |
| 729 | mii_control_1000 |= ADVERTISE_1000FULL; |
| 730 | else |
| 731 | mii_control_1000 &= ~ADVERTISE_1000FULL; |
| 732 | |
| 733 | if (mii_rw(dev, np->phyaddr, MII_1000BT_CR, mii_control_1000)) { |
| 734 | printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev)); |
| 735 | return PHY_ERROR; |
| 736 | } |
| 737 | } |
| 738 | else |
| 739 | np->gigabit = 0; |
| 740 | |
| 741 | /* reset the phy */ |
| 742 | if (phy_reset(dev)) { |
| 743 | printk(KERN_INFO "%s: phy reset failed\n", pci_name(np->pci_dev)); |
| 744 | return PHY_ERROR; |
| 745 | } |
| 746 | |
| 747 | /* phy vendor specific configuration */ |
| 748 | if ((np->phy_oui == PHY_OUI_CICADA) && (phyinterface & PHY_RGMII) ) { |
| 749 | phy_reserved = mii_rw(dev, np->phyaddr, MII_RESV1, MII_READ); |
| 750 | phy_reserved &= ~(PHY_INIT1 | PHY_INIT2); |
| 751 | phy_reserved |= (PHY_INIT3 | PHY_INIT4); |
| 752 | if (mii_rw(dev, np->phyaddr, MII_RESV1, phy_reserved)) { |
| 753 | printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev)); |
| 754 | return PHY_ERROR; |
| 755 | } |
| 756 | phy_reserved = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ); |
| 757 | phy_reserved |= PHY_INIT5; |
| 758 | if (mii_rw(dev, np->phyaddr, MII_NCONFIG, phy_reserved)) { |
| 759 | printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev)); |
| 760 | return PHY_ERROR; |
| 761 | } |
| 762 | } |
| 763 | if (np->phy_oui == PHY_OUI_CICADA) { |
| 764 | phy_reserved = mii_rw(dev, np->phyaddr, MII_SREVISION, MII_READ); |
| 765 | phy_reserved |= PHY_INIT6; |
| 766 | if (mii_rw(dev, np->phyaddr, MII_SREVISION, phy_reserved)) { |
| 767 | printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev)); |
| 768 | return PHY_ERROR; |
| 769 | } |
| 770 | } |
| 771 | |
| 772 | /* restart auto negotiation */ |
| 773 | mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
| 774 | mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE); |
| 775 | if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control)) { |
| 776 | return PHY_ERROR; |
| 777 | } |
| 778 | |
| 779 | return 0; |
| 780 | } |
| 781 | |
| 782 | static void nv_start_rx(struct net_device *dev) |
| 783 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 784 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | u8 __iomem *base = get_hwbase(dev); |
| 786 | |
| 787 | dprintk(KERN_DEBUG "%s: nv_start_rx\n", dev->name); |
| 788 | /* Already running? Stop it. */ |
| 789 | if (readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) { |
| 790 | writel(0, base + NvRegReceiverControl); |
| 791 | pci_push(base); |
| 792 | } |
| 793 | writel(np->linkspeed, base + NvRegLinkSpeed); |
| 794 | pci_push(base); |
| 795 | writel(NVREG_RCVCTL_START, base + NvRegReceiverControl); |
| 796 | dprintk(KERN_DEBUG "%s: nv_start_rx to duplex %d, speed 0x%08x.\n", |
| 797 | dev->name, np->duplex, np->linkspeed); |
| 798 | pci_push(base); |
| 799 | } |
| 800 | |
| 801 | static void nv_stop_rx(struct net_device *dev) |
| 802 | { |
| 803 | u8 __iomem *base = get_hwbase(dev); |
| 804 | |
| 805 | dprintk(KERN_DEBUG "%s: nv_stop_rx\n", dev->name); |
| 806 | writel(0, base + NvRegReceiverControl); |
| 807 | reg_delay(dev, NvRegReceiverStatus, NVREG_RCVSTAT_BUSY, 0, |
| 808 | NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX, |
| 809 | KERN_INFO "nv_stop_rx: ReceiverStatus remained busy"); |
| 810 | |
| 811 | udelay(NV_RXSTOP_DELAY2); |
| 812 | writel(0, base + NvRegLinkSpeed); |
| 813 | } |
| 814 | |
| 815 | static void nv_start_tx(struct net_device *dev) |
| 816 | { |
| 817 | u8 __iomem *base = get_hwbase(dev); |
| 818 | |
| 819 | dprintk(KERN_DEBUG "%s: nv_start_tx\n", dev->name); |
| 820 | writel(NVREG_XMITCTL_START, base + NvRegTransmitterControl); |
| 821 | pci_push(base); |
| 822 | } |
| 823 | |
| 824 | static void nv_stop_tx(struct net_device *dev) |
| 825 | { |
| 826 | u8 __iomem *base = get_hwbase(dev); |
| 827 | |
| 828 | dprintk(KERN_DEBUG "%s: nv_stop_tx\n", dev->name); |
| 829 | writel(0, base + NvRegTransmitterControl); |
| 830 | reg_delay(dev, NvRegTransmitterStatus, NVREG_XMITSTAT_BUSY, 0, |
| 831 | NV_TXSTOP_DELAY1, NV_TXSTOP_DELAY1MAX, |
| 832 | KERN_INFO "nv_stop_tx: TransmitterStatus remained busy"); |
| 833 | |
| 834 | udelay(NV_TXSTOP_DELAY2); |
| 835 | writel(0, base + NvRegUnknownTransmitterReg); |
| 836 | } |
| 837 | |
| 838 | static void nv_txrx_reset(struct net_device *dev) |
| 839 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 840 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | u8 __iomem *base = get_hwbase(dev); |
| 842 | |
| 843 | dprintk(KERN_DEBUG "%s: nv_txrx_reset\n", dev->name); |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 844 | writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 845 | pci_push(base); |
| 846 | udelay(NV_TXRX_RESET_DELAY); |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 847 | writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 848 | pci_push(base); |
| 849 | } |
| 850 | |
| 851 | /* |
| 852 | * nv_get_stats: dev->get_stats function |
| 853 | * Get latest stats value from the nic. |
| 854 | * Called with read_lock(&dev_base_lock) held for read - |
| 855 | * only synchronized against unregister_netdevice. |
| 856 | */ |
| 857 | static struct net_device_stats *nv_get_stats(struct net_device *dev) |
| 858 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 859 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | |
| 861 | /* It seems that the nic always generates interrupts and doesn't |
| 862 | * accumulate errors internally. Thus the current values in np->stats |
| 863 | * are already up to date. |
| 864 | */ |
| 865 | return &np->stats; |
| 866 | } |
| 867 | |
| 868 | /* |
| 869 | * nv_alloc_rx: fill rx ring entries. |
| 870 | * Return 1 if the allocations for the skbs failed and the |
| 871 | * rx engine is without Available descriptors |
| 872 | */ |
| 873 | static int nv_alloc_rx(struct net_device *dev) |
| 874 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 875 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | unsigned int refill_rx = np->refill_rx; |
| 877 | int nr; |
| 878 | |
| 879 | while (np->cur_rx != refill_rx) { |
| 880 | struct sk_buff *skb; |
| 881 | |
| 882 | nr = refill_rx % RX_RING; |
| 883 | if (np->rx_skbuff[nr] == NULL) { |
| 884 | |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 885 | skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 886 | if (!skb) |
| 887 | break; |
| 888 | |
| 889 | skb->dev = dev; |
| 890 | np->rx_skbuff[nr] = skb; |
| 891 | } else { |
| 892 | skb = np->rx_skbuff[nr]; |
| 893 | } |
Manfred Spraul | 1836098 | 2005-12-24 14:19:24 +0100 | [diff] [blame] | 894 | np->rx_dma[nr] = pci_map_single(np->pci_dev, skb->data, |
| 895 | skb->end-skb->data, PCI_DMA_FROMDEVICE); |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 896 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
| 897 | np->rx_ring.orig[nr].PacketBuffer = cpu_to_le32(np->rx_dma[nr]); |
| 898 | wmb(); |
| 899 | np->rx_ring.orig[nr].FlagLen = cpu_to_le32(np->rx_buf_sz | NV_RX_AVAIL); |
| 900 | } else { |
| 901 | np->rx_ring.ex[nr].PacketBufferHigh = cpu_to_le64(np->rx_dma[nr]) >> 32; |
| 902 | np->rx_ring.ex[nr].PacketBufferLow = cpu_to_le64(np->rx_dma[nr]) & 0x0FFFFFFFF; |
| 903 | wmb(); |
| 904 | np->rx_ring.ex[nr].FlagLen = cpu_to_le32(np->rx_buf_sz | NV_RX2_AVAIL); |
| 905 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 906 | dprintk(KERN_DEBUG "%s: nv_alloc_rx: Packet %d marked as Available\n", |
| 907 | dev->name, refill_rx); |
| 908 | refill_rx++; |
| 909 | } |
| 910 | np->refill_rx = refill_rx; |
| 911 | if (np->cur_rx - refill_rx == RX_RING) |
| 912 | return 1; |
| 913 | return 0; |
| 914 | } |
| 915 | |
| 916 | static void nv_do_rx_refill(unsigned long data) |
| 917 | { |
| 918 | struct net_device *dev = (struct net_device *) data; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 919 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | |
| 921 | disable_irq(dev->irq); |
| 922 | if (nv_alloc_rx(dev)) { |
| 923 | spin_lock(&np->lock); |
| 924 | if (!np->in_shutdown) |
| 925 | mod_timer(&np->oom_kick, jiffies + OOM_REFILL); |
| 926 | spin_unlock(&np->lock); |
| 927 | } |
| 928 | enable_irq(dev->irq); |
| 929 | } |
| 930 | |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 931 | static void nv_init_rx(struct net_device *dev) |
| 932 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 933 | struct fe_priv *np = netdev_priv(dev); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 934 | int i; |
| 935 | |
| 936 | np->cur_rx = RX_RING; |
| 937 | np->refill_rx = 0; |
| 938 | for (i = 0; i < RX_RING; i++) |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 939 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
| 940 | np->rx_ring.orig[i].FlagLen = 0; |
| 941 | else |
| 942 | np->rx_ring.ex[i].FlagLen = 0; |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 943 | } |
| 944 | |
| 945 | static void nv_init_tx(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 947 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | int i; |
| 949 | |
| 950 | np->next_tx = np->nic_tx = 0; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 951 | for (i = 0; i < TX_RING; i++) { |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 952 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
| 953 | np->tx_ring.orig[i].FlagLen = 0; |
| 954 | else |
| 955 | np->tx_ring.ex[i].FlagLen = 0; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 956 | np->tx_skbuff[i] = NULL; |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 957 | np->tx_dma[i] = 0; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 958 | } |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 959 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 961 | static int nv_init_ring(struct net_device *dev) |
| 962 | { |
| 963 | nv_init_tx(dev); |
| 964 | nv_init_rx(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 965 | return nv_alloc_rx(dev); |
| 966 | } |
| 967 | |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 968 | static int nv_release_txskb(struct net_device *dev, unsigned int skbnr) |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 969 | { |
| 970 | struct fe_priv *np = netdev_priv(dev); |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 971 | |
| 972 | dprintk(KERN_INFO "%s: nv_release_txskb for skbnr %d\n", |
| 973 | dev->name, skbnr); |
| 974 | |
| 975 | if (np->tx_dma[skbnr]) { |
| 976 | pci_unmap_page(np->pci_dev, np->tx_dma[skbnr], |
| 977 | np->tx_dma_len[skbnr], |
| 978 | PCI_DMA_TODEVICE); |
| 979 | np->tx_dma[skbnr] = 0; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 980 | } |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 981 | |
| 982 | if (np->tx_skbuff[skbnr]) { |
| 983 | dev_kfree_skb_irq(np->tx_skbuff[skbnr]); |
| 984 | np->tx_skbuff[skbnr] = NULL; |
| 985 | return 1; |
| 986 | } else { |
| 987 | return 0; |
| 988 | } |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 989 | } |
| 990 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 991 | static void nv_drain_tx(struct net_device *dev) |
| 992 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 993 | struct fe_priv *np = netdev_priv(dev); |
| 994 | unsigned int i; |
| 995 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | for (i = 0; i < TX_RING; i++) { |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 997 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
| 998 | np->tx_ring.orig[i].FlagLen = 0; |
| 999 | else |
| 1000 | np->tx_ring.ex[i].FlagLen = 0; |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1001 | if (nv_release_txskb(dev, i)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | np->stats.tx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1003 | } |
| 1004 | } |
| 1005 | |
| 1006 | static void nv_drain_rx(struct net_device *dev) |
| 1007 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1008 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | int i; |
| 1010 | for (i = 0; i < RX_RING; i++) { |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 1011 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
| 1012 | np->rx_ring.orig[i].FlagLen = 0; |
| 1013 | else |
| 1014 | np->rx_ring.ex[i].FlagLen = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1015 | wmb(); |
| 1016 | if (np->rx_skbuff[i]) { |
| 1017 | pci_unmap_single(np->pci_dev, np->rx_dma[i], |
Manfred Spraul | 1836098 | 2005-12-24 14:19:24 +0100 | [diff] [blame] | 1018 | np->rx_skbuff[i]->end-np->rx_skbuff[i]->data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | PCI_DMA_FROMDEVICE); |
| 1020 | dev_kfree_skb(np->rx_skbuff[i]); |
| 1021 | np->rx_skbuff[i] = NULL; |
| 1022 | } |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | static void drain_ring(struct net_device *dev) |
| 1027 | { |
| 1028 | nv_drain_tx(dev); |
| 1029 | nv_drain_rx(dev); |
| 1030 | } |
| 1031 | |
| 1032 | /* |
| 1033 | * nv_start_xmit: dev->hard_start_xmit function |
| 1034 | * Called with dev->xmit_lock held. |
| 1035 | */ |
| 1036 | static int nv_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 1037 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1038 | struct fe_priv *np = netdev_priv(dev); |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1039 | u32 tx_flags = 0; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1040 | u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET); |
| 1041 | unsigned int fragments = skb_shinfo(skb)->nr_frags; |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1042 | unsigned int nr = (np->next_tx - 1) % TX_RING; |
| 1043 | unsigned int start_nr = np->next_tx % TX_RING; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1044 | unsigned int i; |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1045 | u32 offset = 0; |
| 1046 | u32 bcnt; |
| 1047 | u32 size = skb->len-skb->data_len; |
| 1048 | u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0); |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame^] | 1049 | u32 tx_flags_vlan = 0; |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1050 | |
| 1051 | /* add fragments to entries count */ |
| 1052 | for (i = 0; i < fragments; i++) { |
| 1053 | entries += (skb_shinfo(skb)->frags[i].size >> NV_TX2_TSO_MAX_SHIFT) + |
| 1054 | ((skb_shinfo(skb)->frags[i].size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0); |
| 1055 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | |
| 1057 | spin_lock_irq(&np->lock); |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1058 | |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1059 | if ((np->next_tx - np->nic_tx + entries - 1) > TX_LIMIT_STOP) { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1060 | spin_unlock_irq(&np->lock); |
| 1061 | netif_stop_queue(dev); |
| 1062 | return NETDEV_TX_BUSY; |
| 1063 | } |
| 1064 | |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1065 | /* setup the header buffer */ |
| 1066 | do { |
| 1067 | bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size; |
| 1068 | nr = (nr + 1) % TX_RING; |
| 1069 | |
| 1070 | np->tx_dma[nr] = pci_map_single(np->pci_dev, skb->data + offset, bcnt, |
| 1071 | PCI_DMA_TODEVICE); |
| 1072 | np->tx_dma_len[nr] = bcnt; |
| 1073 | |
| 1074 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
| 1075 | np->tx_ring.orig[nr].PacketBuffer = cpu_to_le32(np->tx_dma[nr]); |
| 1076 | np->tx_ring.orig[nr].FlagLen = cpu_to_le32((bcnt-1) | tx_flags); |
| 1077 | } else { |
| 1078 | np->tx_ring.ex[nr].PacketBufferHigh = cpu_to_le64(np->tx_dma[nr]) >> 32; |
| 1079 | np->tx_ring.ex[nr].PacketBufferLow = cpu_to_le64(np->tx_dma[nr]) & 0x0FFFFFFFF; |
| 1080 | np->tx_ring.ex[nr].FlagLen = cpu_to_le32((bcnt-1) | tx_flags); |
| 1081 | } |
| 1082 | tx_flags = np->tx_flags; |
| 1083 | offset += bcnt; |
| 1084 | size -= bcnt; |
| 1085 | } while(size); |
| 1086 | |
| 1087 | /* setup the fragments */ |
| 1088 | for (i = 0; i < fragments; i++) { |
| 1089 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 1090 | u32 size = frag->size; |
| 1091 | offset = 0; |
| 1092 | |
| 1093 | do { |
| 1094 | bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size; |
| 1095 | nr = (nr + 1) % TX_RING; |
| 1096 | |
| 1097 | np->tx_dma[nr] = pci_map_page(np->pci_dev, frag->page, frag->page_offset+offset, bcnt, |
| 1098 | PCI_DMA_TODEVICE); |
| 1099 | np->tx_dma_len[nr] = bcnt; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1100 | |
| 1101 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
| 1102 | np->tx_ring.orig[nr].PacketBuffer = cpu_to_le32(np->tx_dma[nr]); |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1103 | np->tx_ring.orig[nr].FlagLen = cpu_to_le32((bcnt-1) | tx_flags); |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1104 | } else { |
| 1105 | np->tx_ring.ex[nr].PacketBufferHigh = cpu_to_le64(np->tx_dma[nr]) >> 32; |
| 1106 | np->tx_ring.ex[nr].PacketBufferLow = cpu_to_le64(np->tx_dma[nr]) & 0x0FFFFFFFF; |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1107 | np->tx_ring.ex[nr].FlagLen = cpu_to_le32((bcnt-1) | tx_flags); |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1108 | } |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1109 | offset += bcnt; |
| 1110 | size -= bcnt; |
| 1111 | } while (size); |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1112 | } |
| 1113 | |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1114 | /* set last fragment flag */ |
| 1115 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
| 1116 | np->tx_ring.orig[nr].FlagLen |= cpu_to_le32(tx_flags_extra); |
| 1117 | } else { |
| 1118 | np->tx_ring.ex[nr].FlagLen |= cpu_to_le32(tx_flags_extra); |
| 1119 | } |
| 1120 | |
| 1121 | np->tx_skbuff[nr] = skb; |
| 1122 | |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1123 | #ifdef NETIF_F_TSO |
| 1124 | if (skb_shinfo(skb)->tso_size) |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1125 | tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->tso_size << NV_TX2_TSO_SHIFT); |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 1126 | else |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1127 | #endif |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1128 | tx_flags_extra = (skb->ip_summed == CHECKSUM_HW ? (NV_TX2_CHECKSUM_L3|NV_TX2_CHECKSUM_L4) : 0); |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1129 | |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame^] | 1130 | /* vlan tag */ |
| 1131 | if (np->vlangrp && vlan_tx_tag_present(skb)) { |
| 1132 | tx_flags_vlan = NV_TX3_VLAN_TAG_PRESENT | vlan_tx_tag_get(skb); |
| 1133 | } |
| 1134 | |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1135 | /* set tx flags */ |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1136 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1137 | np->tx_ring.orig[start_nr].FlagLen |= cpu_to_le32(tx_flags | tx_flags_extra); |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1138 | } else { |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame^] | 1139 | np->tx_ring.ex[start_nr].TxVlan = cpu_to_le32(tx_flags_vlan); |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1140 | np->tx_ring.ex[start_nr].FlagLen |= cpu_to_le32(tx_flags | tx_flags_extra); |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1141 | } |
| 1142 | |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1143 | dprintk(KERN_DEBUG "%s: nv_start_xmit: packet %d (entries %d) queued for transmission. tx_flags_extra: %x\n", |
| 1144 | dev->name, np->next_tx, entries, tx_flags_extra); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1145 | { |
| 1146 | int j; |
| 1147 | for (j=0; j<64; j++) { |
| 1148 | if ((j%16) == 0) |
| 1149 | dprintk("\n%03x:", j); |
| 1150 | dprintk(" %02x", ((unsigned char*)skb->data)[j]); |
| 1151 | } |
| 1152 | dprintk("\n"); |
| 1153 | } |
| 1154 | |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1155 | np->next_tx += entries; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1156 | |
| 1157 | dev->trans_start = jiffies; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | spin_unlock_irq(&np->lock); |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 1159 | writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1160 | pci_push(get_hwbase(dev)); |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1161 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1162 | } |
| 1163 | |
| 1164 | /* |
| 1165 | * nv_tx_done: check for completed packets, release the skbs. |
| 1166 | * |
| 1167 | * Caller must own np->lock. |
| 1168 | */ |
| 1169 | static void nv_tx_done(struct net_device *dev) |
| 1170 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1171 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | u32 Flags; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1173 | unsigned int i; |
| 1174 | struct sk_buff *skb; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1175 | |
| 1176 | while (np->nic_tx != np->next_tx) { |
| 1177 | i = np->nic_tx % TX_RING; |
| 1178 | |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 1179 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
| 1180 | Flags = le32_to_cpu(np->tx_ring.orig[i].FlagLen); |
| 1181 | else |
| 1182 | Flags = le32_to_cpu(np->tx_ring.ex[i].FlagLen); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1183 | |
| 1184 | dprintk(KERN_DEBUG "%s: nv_tx_done: looking at packet %d, Flags 0x%x.\n", |
| 1185 | dev->name, np->nic_tx, Flags); |
| 1186 | if (Flags & NV_TX_VALID) |
| 1187 | break; |
| 1188 | if (np->desc_ver == DESC_VER_1) { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1189 | if (Flags & NV_TX_LASTPACKET) { |
| 1190 | skb = np->tx_skbuff[i]; |
| 1191 | if (Flags & (NV_TX_RETRYERROR|NV_TX_CARRIERLOST|NV_TX_LATECOLLISION| |
| 1192 | NV_TX_UNDERFLOW|NV_TX_ERROR)) { |
| 1193 | if (Flags & NV_TX_UNDERFLOW) |
| 1194 | np->stats.tx_fifo_errors++; |
| 1195 | if (Flags & NV_TX_CARRIERLOST) |
| 1196 | np->stats.tx_carrier_errors++; |
| 1197 | np->stats.tx_errors++; |
| 1198 | } else { |
| 1199 | np->stats.tx_packets++; |
| 1200 | np->stats.tx_bytes += skb->len; |
| 1201 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | } |
| 1203 | } else { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1204 | if (Flags & NV_TX2_LASTPACKET) { |
| 1205 | skb = np->tx_skbuff[i]; |
| 1206 | if (Flags & (NV_TX2_RETRYERROR|NV_TX2_CARRIERLOST|NV_TX2_LATECOLLISION| |
| 1207 | NV_TX2_UNDERFLOW|NV_TX2_ERROR)) { |
| 1208 | if (Flags & NV_TX2_UNDERFLOW) |
| 1209 | np->stats.tx_fifo_errors++; |
| 1210 | if (Flags & NV_TX2_CARRIERLOST) |
| 1211 | np->stats.tx_carrier_errors++; |
| 1212 | np->stats.tx_errors++; |
| 1213 | } else { |
| 1214 | np->stats.tx_packets++; |
| 1215 | np->stats.tx_bytes += skb->len; |
| 1216 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1217 | } |
| 1218 | } |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1219 | nv_release_txskb(dev, i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1220 | np->nic_tx++; |
| 1221 | } |
| 1222 | if (np->next_tx - np->nic_tx < TX_LIMIT_START) |
| 1223 | netif_wake_queue(dev); |
| 1224 | } |
| 1225 | |
| 1226 | /* |
| 1227 | * nv_tx_timeout: dev->tx_timeout function |
| 1228 | * Called with dev->xmit_lock held. |
| 1229 | */ |
| 1230 | static void nv_tx_timeout(struct net_device *dev) |
| 1231 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1232 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1233 | u8 __iomem *base = get_hwbase(dev); |
| 1234 | |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 1235 | printk(KERN_INFO "%s: Got tx_timeout. irq: %08x\n", dev->name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1236 | readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK); |
| 1237 | |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 1238 | { |
| 1239 | int i; |
| 1240 | |
| 1241 | printk(KERN_INFO "%s: Ring at %lx: next %d nic %d\n", |
| 1242 | dev->name, (unsigned long)np->ring_addr, |
| 1243 | np->next_tx, np->nic_tx); |
| 1244 | printk(KERN_INFO "%s: Dumping tx registers\n", dev->name); |
| 1245 | for (i=0;i<0x400;i+= 32) { |
| 1246 | printk(KERN_INFO "%3x: %08x %08x %08x %08x %08x %08x %08x %08x\n", |
| 1247 | i, |
| 1248 | readl(base + i + 0), readl(base + i + 4), |
| 1249 | readl(base + i + 8), readl(base + i + 12), |
| 1250 | readl(base + i + 16), readl(base + i + 20), |
| 1251 | readl(base + i + 24), readl(base + i + 28)); |
| 1252 | } |
| 1253 | printk(KERN_INFO "%s: Dumping tx ring\n", dev->name); |
| 1254 | for (i=0;i<TX_RING;i+= 4) { |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 1255 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
| 1256 | printk(KERN_INFO "%03x: %08x %08x // %08x %08x // %08x %08x // %08x %08x\n", |
| 1257 | i, |
| 1258 | le32_to_cpu(np->tx_ring.orig[i].PacketBuffer), |
| 1259 | le32_to_cpu(np->tx_ring.orig[i].FlagLen), |
| 1260 | le32_to_cpu(np->tx_ring.orig[i+1].PacketBuffer), |
| 1261 | le32_to_cpu(np->tx_ring.orig[i+1].FlagLen), |
| 1262 | le32_to_cpu(np->tx_ring.orig[i+2].PacketBuffer), |
| 1263 | le32_to_cpu(np->tx_ring.orig[i+2].FlagLen), |
| 1264 | le32_to_cpu(np->tx_ring.orig[i+3].PacketBuffer), |
| 1265 | le32_to_cpu(np->tx_ring.orig[i+3].FlagLen)); |
| 1266 | } else { |
| 1267 | printk(KERN_INFO "%03x: %08x %08x %08x // %08x %08x %08x // %08x %08x %08x // %08x %08x %08x\n", |
| 1268 | i, |
| 1269 | le32_to_cpu(np->tx_ring.ex[i].PacketBufferHigh), |
| 1270 | le32_to_cpu(np->tx_ring.ex[i].PacketBufferLow), |
| 1271 | le32_to_cpu(np->tx_ring.ex[i].FlagLen), |
| 1272 | le32_to_cpu(np->tx_ring.ex[i+1].PacketBufferHigh), |
| 1273 | le32_to_cpu(np->tx_ring.ex[i+1].PacketBufferLow), |
| 1274 | le32_to_cpu(np->tx_ring.ex[i+1].FlagLen), |
| 1275 | le32_to_cpu(np->tx_ring.ex[i+2].PacketBufferHigh), |
| 1276 | le32_to_cpu(np->tx_ring.ex[i+2].PacketBufferLow), |
| 1277 | le32_to_cpu(np->tx_ring.ex[i+2].FlagLen), |
| 1278 | le32_to_cpu(np->tx_ring.ex[i+3].PacketBufferHigh), |
| 1279 | le32_to_cpu(np->tx_ring.ex[i+3].PacketBufferLow), |
| 1280 | le32_to_cpu(np->tx_ring.ex[i+3].FlagLen)); |
| 1281 | } |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 1282 | } |
| 1283 | } |
| 1284 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1285 | spin_lock_irq(&np->lock); |
| 1286 | |
| 1287 | /* 1) stop tx engine */ |
| 1288 | nv_stop_tx(dev); |
| 1289 | |
| 1290 | /* 2) check that the packets were not sent already: */ |
| 1291 | nv_tx_done(dev); |
| 1292 | |
| 1293 | /* 3) if there are dead entries: clear everything */ |
| 1294 | if (np->next_tx != np->nic_tx) { |
| 1295 | printk(KERN_DEBUG "%s: tx_timeout: dead entries!\n", dev->name); |
| 1296 | nv_drain_tx(dev); |
| 1297 | np->next_tx = np->nic_tx = 0; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 1298 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
| 1299 | writel((u32) (np->ring_addr + RX_RING*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr); |
| 1300 | else |
| 1301 | writel((u32) (np->ring_addr + RX_RING*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1302 | netif_wake_queue(dev); |
| 1303 | } |
| 1304 | |
| 1305 | /* 4) restart tx engine */ |
| 1306 | nv_start_tx(dev); |
| 1307 | spin_unlock_irq(&np->lock); |
| 1308 | } |
| 1309 | |
Manfred Spraul | 22c6d14 | 2005-04-19 21:17:09 +0200 | [diff] [blame] | 1310 | /* |
| 1311 | * Called when the nic notices a mismatch between the actual data len on the |
| 1312 | * wire and the len indicated in the 802 header |
| 1313 | */ |
| 1314 | static int nv_getlen(struct net_device *dev, void *packet, int datalen) |
| 1315 | { |
| 1316 | int hdrlen; /* length of the 802 header */ |
| 1317 | int protolen; /* length as stored in the proto field */ |
| 1318 | |
| 1319 | /* 1) calculate len according to header */ |
| 1320 | if ( ((struct vlan_ethhdr *)packet)->h_vlan_proto == __constant_htons(ETH_P_8021Q)) { |
| 1321 | protolen = ntohs( ((struct vlan_ethhdr *)packet)->h_vlan_encapsulated_proto ); |
| 1322 | hdrlen = VLAN_HLEN; |
| 1323 | } else { |
| 1324 | protolen = ntohs( ((struct ethhdr *)packet)->h_proto); |
| 1325 | hdrlen = ETH_HLEN; |
| 1326 | } |
| 1327 | dprintk(KERN_DEBUG "%s: nv_getlen: datalen %d, protolen %d, hdrlen %d\n", |
| 1328 | dev->name, datalen, protolen, hdrlen); |
| 1329 | if (protolen > ETH_DATA_LEN) |
| 1330 | return datalen; /* Value in proto field not a len, no checks possible */ |
| 1331 | |
| 1332 | protolen += hdrlen; |
| 1333 | /* consistency checks: */ |
| 1334 | if (datalen > ETH_ZLEN) { |
| 1335 | if (datalen >= protolen) { |
| 1336 | /* more data on wire than in 802 header, trim of |
| 1337 | * additional data. |
| 1338 | */ |
| 1339 | dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n", |
| 1340 | dev->name, protolen); |
| 1341 | return protolen; |
| 1342 | } else { |
| 1343 | /* less data on wire than mentioned in header. |
| 1344 | * Discard the packet. |
| 1345 | */ |
| 1346 | dprintk(KERN_DEBUG "%s: nv_getlen: discarding long packet.\n", |
| 1347 | dev->name); |
| 1348 | return -1; |
| 1349 | } |
| 1350 | } else { |
| 1351 | /* short packet. Accept only if 802 values are also short */ |
| 1352 | if (protolen > ETH_ZLEN) { |
| 1353 | dprintk(KERN_DEBUG "%s: nv_getlen: discarding short packet.\n", |
| 1354 | dev->name); |
| 1355 | return -1; |
| 1356 | } |
| 1357 | dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n", |
| 1358 | dev->name, datalen); |
| 1359 | return datalen; |
| 1360 | } |
| 1361 | } |
| 1362 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1363 | static void nv_rx_process(struct net_device *dev) |
| 1364 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1365 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1366 | u32 Flags; |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame^] | 1367 | u32 vlanflags = 0; |
| 1368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1369 | |
| 1370 | for (;;) { |
| 1371 | struct sk_buff *skb; |
| 1372 | int len; |
| 1373 | int i; |
| 1374 | if (np->cur_rx - np->refill_rx >= RX_RING) |
| 1375 | break; /* we scanned the whole ring - do not continue */ |
| 1376 | |
| 1377 | i = np->cur_rx % RX_RING; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 1378 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
| 1379 | Flags = le32_to_cpu(np->rx_ring.orig[i].FlagLen); |
| 1380 | len = nv_descr_getlength(&np->rx_ring.orig[i], np->desc_ver); |
| 1381 | } else { |
| 1382 | Flags = le32_to_cpu(np->rx_ring.ex[i].FlagLen); |
| 1383 | len = nv_descr_getlength_ex(&np->rx_ring.ex[i], np->desc_ver); |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame^] | 1384 | vlanflags = le32_to_cpu(np->rx_ring.ex[i].PacketBufferLow); |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 1385 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1386 | |
| 1387 | dprintk(KERN_DEBUG "%s: nv_rx_process: looking at packet %d, Flags 0x%x.\n", |
| 1388 | dev->name, np->cur_rx, Flags); |
| 1389 | |
| 1390 | if (Flags & NV_RX_AVAIL) |
| 1391 | break; /* still owned by hardware, */ |
| 1392 | |
| 1393 | /* |
| 1394 | * the packet is for us - immediately tear down the pci mapping. |
| 1395 | * TODO: check if a prefetch of the first cacheline improves |
| 1396 | * the performance. |
| 1397 | */ |
| 1398 | pci_unmap_single(np->pci_dev, np->rx_dma[i], |
Manfred Spraul | 1836098 | 2005-12-24 14:19:24 +0100 | [diff] [blame] | 1399 | np->rx_skbuff[i]->end-np->rx_skbuff[i]->data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1400 | PCI_DMA_FROMDEVICE); |
| 1401 | |
| 1402 | { |
| 1403 | int j; |
| 1404 | dprintk(KERN_DEBUG "Dumping packet (flags 0x%x).",Flags); |
| 1405 | for (j=0; j<64; j++) { |
| 1406 | if ((j%16) == 0) |
| 1407 | dprintk("\n%03x:", j); |
| 1408 | dprintk(" %02x", ((unsigned char*)np->rx_skbuff[i]->data)[j]); |
| 1409 | } |
| 1410 | dprintk("\n"); |
| 1411 | } |
| 1412 | /* look at what we actually got: */ |
| 1413 | if (np->desc_ver == DESC_VER_1) { |
| 1414 | if (!(Flags & NV_RX_DESCRIPTORVALID)) |
| 1415 | goto next_pkt; |
| 1416 | |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 1417 | if (Flags & NV_RX_ERROR) { |
| 1418 | if (Flags & NV_RX_MISSEDFRAME) { |
| 1419 | np->stats.rx_missed_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1420 | np->stats.rx_errors++; |
| 1421 | goto next_pkt; |
| 1422 | } |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 1423 | if (Flags & (NV_RX_ERROR1|NV_RX_ERROR2|NV_RX_ERROR3)) { |
| 1424 | np->stats.rx_errors++; |
| 1425 | goto next_pkt; |
| 1426 | } |
| 1427 | if (Flags & NV_RX_CRCERR) { |
| 1428 | np->stats.rx_crc_errors++; |
| 1429 | np->stats.rx_errors++; |
| 1430 | goto next_pkt; |
| 1431 | } |
| 1432 | if (Flags & NV_RX_OVERFLOW) { |
| 1433 | np->stats.rx_over_errors++; |
| 1434 | np->stats.rx_errors++; |
| 1435 | goto next_pkt; |
| 1436 | } |
| 1437 | if (Flags & NV_RX_ERROR4) { |
| 1438 | len = nv_getlen(dev, np->rx_skbuff[i]->data, len); |
| 1439 | if (len < 0) { |
| 1440 | np->stats.rx_errors++; |
| 1441 | goto next_pkt; |
| 1442 | } |
| 1443 | } |
| 1444 | /* framing errors are soft errors. */ |
| 1445 | if (Flags & NV_RX_FRAMINGERR) { |
| 1446 | if (Flags & NV_RX_SUBSTRACT1) { |
| 1447 | len--; |
| 1448 | } |
Manfred Spraul | 22c6d14 | 2005-04-19 21:17:09 +0200 | [diff] [blame] | 1449 | } |
| 1450 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1451 | } else { |
| 1452 | if (!(Flags & NV_RX2_DESCRIPTORVALID)) |
| 1453 | goto next_pkt; |
| 1454 | |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 1455 | if (Flags & NV_RX2_ERROR) { |
| 1456 | if (Flags & (NV_RX2_ERROR1|NV_RX2_ERROR2|NV_RX2_ERROR3)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | np->stats.rx_errors++; |
| 1458 | goto next_pkt; |
| 1459 | } |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 1460 | if (Flags & NV_RX2_CRCERR) { |
| 1461 | np->stats.rx_crc_errors++; |
| 1462 | np->stats.rx_errors++; |
| 1463 | goto next_pkt; |
| 1464 | } |
| 1465 | if (Flags & NV_RX2_OVERFLOW) { |
| 1466 | np->stats.rx_over_errors++; |
| 1467 | np->stats.rx_errors++; |
| 1468 | goto next_pkt; |
| 1469 | } |
| 1470 | if (Flags & NV_RX2_ERROR4) { |
| 1471 | len = nv_getlen(dev, np->rx_skbuff[i]->data, len); |
| 1472 | if (len < 0) { |
| 1473 | np->stats.rx_errors++; |
| 1474 | goto next_pkt; |
| 1475 | } |
| 1476 | } |
| 1477 | /* framing errors are soft errors */ |
| 1478 | if (Flags & NV_RX2_FRAMINGERR) { |
| 1479 | if (Flags & NV_RX2_SUBSTRACT1) { |
| 1480 | len--; |
| 1481 | } |
Manfred Spraul | 22c6d14 | 2005-04-19 21:17:09 +0200 | [diff] [blame] | 1482 | } |
| 1483 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1484 | Flags &= NV_RX2_CHECKSUMMASK; |
| 1485 | if (Flags == NV_RX2_CHECKSUMOK1 || |
| 1486 | Flags == NV_RX2_CHECKSUMOK2 || |
| 1487 | Flags == NV_RX2_CHECKSUMOK3) { |
| 1488 | dprintk(KERN_DEBUG "%s: hw checksum hit!.\n", dev->name); |
| 1489 | np->rx_skbuff[i]->ip_summed = CHECKSUM_UNNECESSARY; |
| 1490 | } else { |
| 1491 | dprintk(KERN_DEBUG "%s: hwchecksum miss!.\n", dev->name); |
| 1492 | } |
| 1493 | } |
| 1494 | /* got a valid packet - forward it to the network core */ |
| 1495 | skb = np->rx_skbuff[i]; |
| 1496 | np->rx_skbuff[i] = NULL; |
| 1497 | |
| 1498 | skb_put(skb, len); |
| 1499 | skb->protocol = eth_type_trans(skb, dev); |
| 1500 | dprintk(KERN_DEBUG "%s: nv_rx_process: packet %d with %d bytes, proto %d accepted.\n", |
| 1501 | dev->name, np->cur_rx, len, skb->protocol); |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame^] | 1502 | if (np->vlangrp && (vlanflags & NV_RX3_VLAN_TAG_PRESENT)) { |
| 1503 | vlan_hwaccel_rx(skb, np->vlangrp, vlanflags & NV_RX3_VLAN_TAG_MASK); |
| 1504 | } else { |
| 1505 | netif_rx(skb); |
| 1506 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | dev->last_rx = jiffies; |
| 1508 | np->stats.rx_packets++; |
| 1509 | np->stats.rx_bytes += len; |
| 1510 | next_pkt: |
| 1511 | np->cur_rx++; |
| 1512 | } |
| 1513 | } |
| 1514 | |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 1515 | static void set_bufsize(struct net_device *dev) |
| 1516 | { |
| 1517 | struct fe_priv *np = netdev_priv(dev); |
| 1518 | |
| 1519 | if (dev->mtu <= ETH_DATA_LEN) |
| 1520 | np->rx_buf_sz = ETH_DATA_LEN + NV_RX_HEADERS; |
| 1521 | else |
| 1522 | np->rx_buf_sz = dev->mtu + NV_RX_HEADERS; |
| 1523 | } |
| 1524 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | /* |
| 1526 | * nv_change_mtu: dev->change_mtu function |
| 1527 | * Called with dev_base_lock held for read. |
| 1528 | */ |
| 1529 | static int nv_change_mtu(struct net_device *dev, int new_mtu) |
| 1530 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1531 | struct fe_priv *np = netdev_priv(dev); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 1532 | int old_mtu; |
| 1533 | |
| 1534 | if (new_mtu < 64 || new_mtu > np->pkt_limit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | return -EINVAL; |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 1536 | |
| 1537 | old_mtu = dev->mtu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1538 | dev->mtu = new_mtu; |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 1539 | |
| 1540 | /* return early if the buffer sizes will not change */ |
| 1541 | if (old_mtu <= ETH_DATA_LEN && new_mtu <= ETH_DATA_LEN) |
| 1542 | return 0; |
| 1543 | if (old_mtu == new_mtu) |
| 1544 | return 0; |
| 1545 | |
| 1546 | /* synchronized against open : rtnl_lock() held by caller */ |
| 1547 | if (netif_running(dev)) { |
viro@ftp.linux.org.uk | 25097d4 | 2005-09-06 01:36:58 +0100 | [diff] [blame] | 1548 | u8 __iomem *base = get_hwbase(dev); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 1549 | /* |
| 1550 | * It seems that the nic preloads valid ring entries into an |
| 1551 | * internal buffer. The procedure for flushing everything is |
| 1552 | * guessed, there is probably a simpler approach. |
| 1553 | * Changing the MTU is a rare event, it shouldn't matter. |
| 1554 | */ |
| 1555 | disable_irq(dev->irq); |
| 1556 | spin_lock_bh(&dev->xmit_lock); |
| 1557 | spin_lock(&np->lock); |
| 1558 | /* stop engines */ |
| 1559 | nv_stop_rx(dev); |
| 1560 | nv_stop_tx(dev); |
| 1561 | nv_txrx_reset(dev); |
| 1562 | /* drain rx queue */ |
| 1563 | nv_drain_rx(dev); |
| 1564 | nv_drain_tx(dev); |
| 1565 | /* reinit driver view of the rx queue */ |
| 1566 | nv_init_rx(dev); |
| 1567 | nv_init_tx(dev); |
| 1568 | /* alloc new rx buffers */ |
| 1569 | set_bufsize(dev); |
| 1570 | if (nv_alloc_rx(dev)) { |
| 1571 | if (!np->in_shutdown) |
| 1572 | mod_timer(&np->oom_kick, jiffies + OOM_REFILL); |
| 1573 | } |
| 1574 | /* reinit nic view of the rx queue */ |
| 1575 | writel(np->rx_buf_sz, base + NvRegOffloadConfig); |
| 1576 | writel((u32) np->ring_addr, base + NvRegRxRingPhysAddr); |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 1577 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
| 1578 | writel((u32) (np->ring_addr + RX_RING*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr); |
| 1579 | else |
| 1580 | writel((u32) (np->ring_addr + RX_RING*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 1581 | writel( ((RX_RING-1) << NVREG_RINGSZ_RXSHIFT) + ((TX_RING-1) << NVREG_RINGSZ_TXSHIFT), |
| 1582 | base + NvRegRingSizes); |
| 1583 | pci_push(base); |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 1584 | writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 1585 | pci_push(base); |
| 1586 | |
| 1587 | /* restart rx engine */ |
| 1588 | nv_start_rx(dev); |
| 1589 | nv_start_tx(dev); |
| 1590 | spin_unlock(&np->lock); |
| 1591 | spin_unlock_bh(&dev->xmit_lock); |
| 1592 | enable_irq(dev->irq); |
| 1593 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1594 | return 0; |
| 1595 | } |
| 1596 | |
Manfred Spraul | 72b3178 | 2005-07-31 18:33:34 +0200 | [diff] [blame] | 1597 | static void nv_copy_mac_to_hw(struct net_device *dev) |
| 1598 | { |
viro@ftp.linux.org.uk | 25097d4 | 2005-09-06 01:36:58 +0100 | [diff] [blame] | 1599 | u8 __iomem *base = get_hwbase(dev); |
Manfred Spraul | 72b3178 | 2005-07-31 18:33:34 +0200 | [diff] [blame] | 1600 | u32 mac[2]; |
| 1601 | |
| 1602 | mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) + |
| 1603 | (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24); |
| 1604 | mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8); |
| 1605 | |
| 1606 | writel(mac[0], base + NvRegMacAddrA); |
| 1607 | writel(mac[1], base + NvRegMacAddrB); |
| 1608 | } |
| 1609 | |
| 1610 | /* |
| 1611 | * nv_set_mac_address: dev->set_mac_address function |
| 1612 | * Called with rtnl_lock() held. |
| 1613 | */ |
| 1614 | static int nv_set_mac_address(struct net_device *dev, void *addr) |
| 1615 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1616 | struct fe_priv *np = netdev_priv(dev); |
Manfred Spraul | 72b3178 | 2005-07-31 18:33:34 +0200 | [diff] [blame] | 1617 | struct sockaddr *macaddr = (struct sockaddr*)addr; |
| 1618 | |
| 1619 | if(!is_valid_ether_addr(macaddr->sa_data)) |
| 1620 | return -EADDRNOTAVAIL; |
| 1621 | |
| 1622 | /* synchronized against open : rtnl_lock() held by caller */ |
| 1623 | memcpy(dev->dev_addr, macaddr->sa_data, ETH_ALEN); |
| 1624 | |
| 1625 | if (netif_running(dev)) { |
| 1626 | spin_lock_bh(&dev->xmit_lock); |
| 1627 | spin_lock_irq(&np->lock); |
| 1628 | |
| 1629 | /* stop rx engine */ |
| 1630 | nv_stop_rx(dev); |
| 1631 | |
| 1632 | /* set mac address */ |
| 1633 | nv_copy_mac_to_hw(dev); |
| 1634 | |
| 1635 | /* restart rx engine */ |
| 1636 | nv_start_rx(dev); |
| 1637 | spin_unlock_irq(&np->lock); |
| 1638 | spin_unlock_bh(&dev->xmit_lock); |
| 1639 | } else { |
| 1640 | nv_copy_mac_to_hw(dev); |
| 1641 | } |
| 1642 | return 0; |
| 1643 | } |
| 1644 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | /* |
| 1646 | * nv_set_multicast: dev->set_multicast function |
| 1647 | * Called with dev->xmit_lock held. |
| 1648 | */ |
| 1649 | static void nv_set_multicast(struct net_device *dev) |
| 1650 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1651 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1652 | u8 __iomem *base = get_hwbase(dev); |
| 1653 | u32 addr[2]; |
| 1654 | u32 mask[2]; |
| 1655 | u32 pff; |
| 1656 | |
| 1657 | memset(addr, 0, sizeof(addr)); |
| 1658 | memset(mask, 0, sizeof(mask)); |
| 1659 | |
| 1660 | if (dev->flags & IFF_PROMISC) { |
| 1661 | printk(KERN_NOTICE "%s: Promiscuous mode enabled.\n", dev->name); |
| 1662 | pff = NVREG_PFF_PROMISC; |
| 1663 | } else { |
| 1664 | pff = NVREG_PFF_MYADDR; |
| 1665 | |
| 1666 | if (dev->flags & IFF_ALLMULTI || dev->mc_list) { |
| 1667 | u32 alwaysOff[2]; |
| 1668 | u32 alwaysOn[2]; |
| 1669 | |
| 1670 | alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0xffffffff; |
| 1671 | if (dev->flags & IFF_ALLMULTI) { |
| 1672 | alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0; |
| 1673 | } else { |
| 1674 | struct dev_mc_list *walk; |
| 1675 | |
| 1676 | walk = dev->mc_list; |
| 1677 | while (walk != NULL) { |
| 1678 | u32 a, b; |
| 1679 | a = le32_to_cpu(*(u32 *) walk->dmi_addr); |
| 1680 | b = le16_to_cpu(*(u16 *) (&walk->dmi_addr[4])); |
| 1681 | alwaysOn[0] &= a; |
| 1682 | alwaysOff[0] &= ~a; |
| 1683 | alwaysOn[1] &= b; |
| 1684 | alwaysOff[1] &= ~b; |
| 1685 | walk = walk->next; |
| 1686 | } |
| 1687 | } |
| 1688 | addr[0] = alwaysOn[0]; |
| 1689 | addr[1] = alwaysOn[1]; |
| 1690 | mask[0] = alwaysOn[0] | alwaysOff[0]; |
| 1691 | mask[1] = alwaysOn[1] | alwaysOff[1]; |
| 1692 | } |
| 1693 | } |
| 1694 | addr[0] |= NVREG_MCASTADDRA_FORCE; |
| 1695 | pff |= NVREG_PFF_ALWAYS; |
| 1696 | spin_lock_irq(&np->lock); |
| 1697 | nv_stop_rx(dev); |
| 1698 | writel(addr[0], base + NvRegMulticastAddrA); |
| 1699 | writel(addr[1], base + NvRegMulticastAddrB); |
| 1700 | writel(mask[0], base + NvRegMulticastMaskA); |
| 1701 | writel(mask[1], base + NvRegMulticastMaskB); |
| 1702 | writel(pff, base + NvRegPacketFilterFlags); |
| 1703 | dprintk(KERN_INFO "%s: reconfiguration for multicast lists.\n", |
| 1704 | dev->name); |
| 1705 | nv_start_rx(dev); |
| 1706 | spin_unlock_irq(&np->lock); |
| 1707 | } |
| 1708 | |
Ayaz Abdulla | 4ea7f29 | 2005-11-11 08:29:59 -0500 | [diff] [blame] | 1709 | /** |
| 1710 | * nv_update_linkspeed: Setup the MAC according to the link partner |
| 1711 | * @dev: Network device to be configured |
| 1712 | * |
| 1713 | * The function queries the PHY and checks if there is a link partner. |
| 1714 | * If yes, then it sets up the MAC accordingly. Otherwise, the MAC is |
| 1715 | * set to 10 MBit HD. |
| 1716 | * |
| 1717 | * The function returns 0 if there is no link partner and 1 if there is |
| 1718 | * a good link partner. |
| 1719 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1720 | static int nv_update_linkspeed(struct net_device *dev) |
| 1721 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1722 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1723 | u8 __iomem *base = get_hwbase(dev); |
| 1724 | int adv, lpa; |
| 1725 | int newls = np->linkspeed; |
| 1726 | int newdup = np->duplex; |
| 1727 | int mii_status; |
| 1728 | int retval = 0; |
| 1729 | u32 control_1000, status_1000, phyreg; |
| 1730 | |
| 1731 | /* BMSR_LSTATUS is latched, read it twice: |
| 1732 | * we want the current value. |
| 1733 | */ |
| 1734 | mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ); |
| 1735 | mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ); |
| 1736 | |
| 1737 | if (!(mii_status & BMSR_LSTATUS)) { |
| 1738 | dprintk(KERN_DEBUG "%s: no link detected by phy - falling back to 10HD.\n", |
| 1739 | dev->name); |
| 1740 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 1741 | newdup = 0; |
| 1742 | retval = 0; |
| 1743 | goto set_speed; |
| 1744 | } |
| 1745 | |
| 1746 | if (np->autoneg == 0) { |
| 1747 | dprintk(KERN_DEBUG "%s: nv_update_linkspeed: autoneg off, PHY set to 0x%04x.\n", |
| 1748 | dev->name, np->fixed_mode); |
| 1749 | if (np->fixed_mode & LPA_100FULL) { |
| 1750 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100; |
| 1751 | newdup = 1; |
| 1752 | } else if (np->fixed_mode & LPA_100HALF) { |
| 1753 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100; |
| 1754 | newdup = 0; |
| 1755 | } else if (np->fixed_mode & LPA_10FULL) { |
| 1756 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 1757 | newdup = 1; |
| 1758 | } else { |
| 1759 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 1760 | newdup = 0; |
| 1761 | } |
| 1762 | retval = 1; |
| 1763 | goto set_speed; |
| 1764 | } |
| 1765 | /* check auto negotiation is complete */ |
| 1766 | if (!(mii_status & BMSR_ANEGCOMPLETE)) { |
| 1767 | /* still in autonegotiation - configure nic for 10 MBit HD and wait. */ |
| 1768 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 1769 | newdup = 0; |
| 1770 | retval = 0; |
| 1771 | dprintk(KERN_DEBUG "%s: autoneg not completed - falling back to 10HD.\n", dev->name); |
| 1772 | goto set_speed; |
| 1773 | } |
| 1774 | |
| 1775 | retval = 1; |
| 1776 | if (np->gigabit == PHY_GIGABIT) { |
| 1777 | control_1000 = mii_rw(dev, np->phyaddr, MII_1000BT_CR, MII_READ); |
| 1778 | status_1000 = mii_rw(dev, np->phyaddr, MII_1000BT_SR, MII_READ); |
| 1779 | |
| 1780 | if ((control_1000 & ADVERTISE_1000FULL) && |
| 1781 | (status_1000 & LPA_1000FULL)) { |
| 1782 | dprintk(KERN_DEBUG "%s: nv_update_linkspeed: GBit ethernet detected.\n", |
| 1783 | dev->name); |
| 1784 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_1000; |
| 1785 | newdup = 1; |
| 1786 | goto set_speed; |
| 1787 | } |
| 1788 | } |
| 1789 | |
| 1790 | adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ); |
| 1791 | lpa = mii_rw(dev, np->phyaddr, MII_LPA, MII_READ); |
| 1792 | dprintk(KERN_DEBUG "%s: nv_update_linkspeed: PHY advertises 0x%04x, lpa 0x%04x.\n", |
| 1793 | dev->name, adv, lpa); |
| 1794 | |
| 1795 | /* FIXME: handle parallel detection properly */ |
| 1796 | lpa = lpa & adv; |
| 1797 | if (lpa & LPA_100FULL) { |
| 1798 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100; |
| 1799 | newdup = 1; |
| 1800 | } else if (lpa & LPA_100HALF) { |
| 1801 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100; |
| 1802 | newdup = 0; |
| 1803 | } else if (lpa & LPA_10FULL) { |
| 1804 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 1805 | newdup = 1; |
| 1806 | } else if (lpa & LPA_10HALF) { |
| 1807 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 1808 | newdup = 0; |
| 1809 | } else { |
| 1810 | dprintk(KERN_DEBUG "%s: bad ability %04x - falling back to 10HD.\n", dev->name, lpa); |
| 1811 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 1812 | newdup = 0; |
| 1813 | } |
| 1814 | |
| 1815 | set_speed: |
| 1816 | if (np->duplex == newdup && np->linkspeed == newls) |
| 1817 | return retval; |
| 1818 | |
| 1819 | dprintk(KERN_INFO "%s: changing link setting from %d/%d to %d/%d.\n", |
| 1820 | dev->name, np->linkspeed, np->duplex, newls, newdup); |
| 1821 | |
| 1822 | np->duplex = newdup; |
| 1823 | np->linkspeed = newls; |
| 1824 | |
| 1825 | if (np->gigabit == PHY_GIGABIT) { |
| 1826 | phyreg = readl(base + NvRegRandomSeed); |
| 1827 | phyreg &= ~(0x3FF00); |
| 1828 | if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10) |
| 1829 | phyreg |= NVREG_RNDSEED_FORCE3; |
| 1830 | else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100) |
| 1831 | phyreg |= NVREG_RNDSEED_FORCE2; |
| 1832 | else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000) |
| 1833 | phyreg |= NVREG_RNDSEED_FORCE; |
| 1834 | writel(phyreg, base + NvRegRandomSeed); |
| 1835 | } |
| 1836 | |
| 1837 | phyreg = readl(base + NvRegPhyInterface); |
| 1838 | phyreg &= ~(PHY_HALF|PHY_100|PHY_1000); |
| 1839 | if (np->duplex == 0) |
| 1840 | phyreg |= PHY_HALF; |
| 1841 | if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100) |
| 1842 | phyreg |= PHY_100; |
| 1843 | else if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000) |
| 1844 | phyreg |= PHY_1000; |
| 1845 | writel(phyreg, base + NvRegPhyInterface); |
| 1846 | |
| 1847 | writel(NVREG_MISC1_FORCE | ( np->duplex ? 0 : NVREG_MISC1_HD), |
| 1848 | base + NvRegMisc1); |
| 1849 | pci_push(base); |
| 1850 | writel(np->linkspeed, base + NvRegLinkSpeed); |
| 1851 | pci_push(base); |
| 1852 | |
| 1853 | return retval; |
| 1854 | } |
| 1855 | |
| 1856 | static void nv_linkchange(struct net_device *dev) |
| 1857 | { |
| 1858 | if (nv_update_linkspeed(dev)) { |
Ayaz Abdulla | 4ea7f29 | 2005-11-11 08:29:59 -0500 | [diff] [blame] | 1859 | if (!netif_carrier_ok(dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1860 | netif_carrier_on(dev); |
| 1861 | printk(KERN_INFO "%s: link up.\n", dev->name); |
Ayaz Abdulla | 4ea7f29 | 2005-11-11 08:29:59 -0500 | [diff] [blame] | 1862 | nv_start_rx(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1863 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1864 | } else { |
| 1865 | if (netif_carrier_ok(dev)) { |
| 1866 | netif_carrier_off(dev); |
| 1867 | printk(KERN_INFO "%s: link down.\n", dev->name); |
| 1868 | nv_stop_rx(dev); |
| 1869 | } |
| 1870 | } |
| 1871 | } |
| 1872 | |
| 1873 | static void nv_link_irq(struct net_device *dev) |
| 1874 | { |
| 1875 | u8 __iomem *base = get_hwbase(dev); |
| 1876 | u32 miistat; |
| 1877 | |
| 1878 | miistat = readl(base + NvRegMIIStatus); |
| 1879 | writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus); |
| 1880 | dprintk(KERN_INFO "%s: link change irq, status 0x%x.\n", dev->name, miistat); |
| 1881 | |
| 1882 | if (miistat & (NVREG_MIISTAT_LINKCHANGE)) |
| 1883 | nv_linkchange(dev); |
| 1884 | dprintk(KERN_DEBUG "%s: link change notification done.\n", dev->name); |
| 1885 | } |
| 1886 | |
| 1887 | static irqreturn_t nv_nic_irq(int foo, void *data, struct pt_regs *regs) |
| 1888 | { |
| 1889 | struct net_device *dev = (struct net_device *) data; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1890 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1891 | u8 __iomem *base = get_hwbase(dev); |
| 1892 | u32 events; |
| 1893 | int i; |
| 1894 | |
| 1895 | dprintk(KERN_DEBUG "%s: nv_nic_irq\n", dev->name); |
| 1896 | |
| 1897 | for (i=0; ; i++) { |
| 1898 | events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK; |
| 1899 | writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus); |
| 1900 | pci_push(base); |
| 1901 | dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events); |
| 1902 | if (!(events & np->irqmask)) |
| 1903 | break; |
| 1904 | |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 1905 | spin_lock(&np->lock); |
| 1906 | nv_tx_done(dev); |
| 1907 | spin_unlock(&np->lock); |
| 1908 | |
| 1909 | nv_rx_process(dev); |
| 1910 | if (nv_alloc_rx(dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | spin_lock(&np->lock); |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 1912 | if (!np->in_shutdown) |
| 1913 | mod_timer(&np->oom_kick, jiffies + OOM_REFILL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1914 | spin_unlock(&np->lock); |
| 1915 | } |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 1916 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1917 | if (events & NVREG_IRQ_LINK) { |
| 1918 | spin_lock(&np->lock); |
| 1919 | nv_link_irq(dev); |
| 1920 | spin_unlock(&np->lock); |
| 1921 | } |
| 1922 | if (np->need_linktimer && time_after(jiffies, np->link_timeout)) { |
| 1923 | spin_lock(&np->lock); |
| 1924 | nv_linkchange(dev); |
| 1925 | spin_unlock(&np->lock); |
| 1926 | np->link_timeout = jiffies + LINK_TIMEOUT; |
| 1927 | } |
| 1928 | if (events & (NVREG_IRQ_TX_ERR)) { |
| 1929 | dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n", |
| 1930 | dev->name, events); |
| 1931 | } |
| 1932 | if (events & (NVREG_IRQ_UNKNOWN)) { |
| 1933 | printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n", |
| 1934 | dev->name, events); |
| 1935 | } |
| 1936 | if (i > max_interrupt_work) { |
| 1937 | spin_lock(&np->lock); |
| 1938 | /* disable interrupts on the nic */ |
| 1939 | writel(0, base + NvRegIrqMask); |
| 1940 | pci_push(base); |
| 1941 | |
| 1942 | if (!np->in_shutdown) |
| 1943 | mod_timer(&np->nic_poll, jiffies + POLL_WAIT); |
| 1944 | printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq.\n", dev->name, i); |
| 1945 | spin_unlock(&np->lock); |
| 1946 | break; |
| 1947 | } |
| 1948 | |
| 1949 | } |
| 1950 | dprintk(KERN_DEBUG "%s: nv_nic_irq completed\n", dev->name); |
| 1951 | |
| 1952 | return IRQ_RETVAL(i); |
| 1953 | } |
| 1954 | |
| 1955 | static void nv_do_nic_poll(unsigned long data) |
| 1956 | { |
| 1957 | struct net_device *dev = (struct net_device *) data; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1958 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1959 | u8 __iomem *base = get_hwbase(dev); |
| 1960 | |
| 1961 | disable_irq(dev->irq); |
| 1962 | /* FIXME: Do we need synchronize_irq(dev->irq) here? */ |
| 1963 | /* |
| 1964 | * reenable interrupts on the nic, we have to do this before calling |
| 1965 | * nv_nic_irq because that may decide to do otherwise |
| 1966 | */ |
| 1967 | writel(np->irqmask, base + NvRegIrqMask); |
| 1968 | pci_push(base); |
| 1969 | nv_nic_irq((int) 0, (void *) data, (struct pt_regs *) NULL); |
| 1970 | enable_irq(dev->irq); |
| 1971 | } |
| 1972 | |
Michal Schmidt | 2918c35 | 2005-05-12 19:42:06 -0400 | [diff] [blame] | 1973 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 1974 | static void nv_poll_controller(struct net_device *dev) |
| 1975 | { |
| 1976 | nv_do_nic_poll((unsigned long) dev); |
| 1977 | } |
| 1978 | #endif |
| 1979 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | static void nv_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
| 1981 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1982 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1983 | strcpy(info->driver, "forcedeth"); |
| 1984 | strcpy(info->version, FORCEDETH_VERSION); |
| 1985 | strcpy(info->bus_info, pci_name(np->pci_dev)); |
| 1986 | } |
| 1987 | |
| 1988 | static void nv_get_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo) |
| 1989 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1990 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1991 | wolinfo->supported = WAKE_MAGIC; |
| 1992 | |
| 1993 | spin_lock_irq(&np->lock); |
| 1994 | if (np->wolenabled) |
| 1995 | wolinfo->wolopts = WAKE_MAGIC; |
| 1996 | spin_unlock_irq(&np->lock); |
| 1997 | } |
| 1998 | |
| 1999 | static int nv_set_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo) |
| 2000 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2001 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2002 | u8 __iomem *base = get_hwbase(dev); |
| 2003 | |
| 2004 | spin_lock_irq(&np->lock); |
| 2005 | if (wolinfo->wolopts == 0) { |
| 2006 | writel(0, base + NvRegWakeUpFlags); |
| 2007 | np->wolenabled = 0; |
| 2008 | } |
| 2009 | if (wolinfo->wolopts & WAKE_MAGIC) { |
| 2010 | writel(NVREG_WAKEUPFLAGS_ENABLE, base + NvRegWakeUpFlags); |
| 2011 | np->wolenabled = 1; |
| 2012 | } |
| 2013 | spin_unlock_irq(&np->lock); |
| 2014 | return 0; |
| 2015 | } |
| 2016 | |
| 2017 | static int nv_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd) |
| 2018 | { |
| 2019 | struct fe_priv *np = netdev_priv(dev); |
| 2020 | int adv; |
| 2021 | |
| 2022 | spin_lock_irq(&np->lock); |
| 2023 | ecmd->port = PORT_MII; |
| 2024 | if (!netif_running(dev)) { |
| 2025 | /* We do not track link speed / duplex setting if the |
| 2026 | * interface is disabled. Force a link check */ |
| 2027 | nv_update_linkspeed(dev); |
| 2028 | } |
| 2029 | switch(np->linkspeed & (NVREG_LINKSPEED_MASK)) { |
| 2030 | case NVREG_LINKSPEED_10: |
| 2031 | ecmd->speed = SPEED_10; |
| 2032 | break; |
| 2033 | case NVREG_LINKSPEED_100: |
| 2034 | ecmd->speed = SPEED_100; |
| 2035 | break; |
| 2036 | case NVREG_LINKSPEED_1000: |
| 2037 | ecmd->speed = SPEED_1000; |
| 2038 | break; |
| 2039 | } |
| 2040 | ecmd->duplex = DUPLEX_HALF; |
| 2041 | if (np->duplex) |
| 2042 | ecmd->duplex = DUPLEX_FULL; |
| 2043 | |
| 2044 | ecmd->autoneg = np->autoneg; |
| 2045 | |
| 2046 | ecmd->advertising = ADVERTISED_MII; |
| 2047 | if (np->autoneg) { |
| 2048 | ecmd->advertising |= ADVERTISED_Autoneg; |
| 2049 | adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ); |
| 2050 | } else { |
| 2051 | adv = np->fixed_mode; |
| 2052 | } |
| 2053 | if (adv & ADVERTISE_10HALF) |
| 2054 | ecmd->advertising |= ADVERTISED_10baseT_Half; |
| 2055 | if (adv & ADVERTISE_10FULL) |
| 2056 | ecmd->advertising |= ADVERTISED_10baseT_Full; |
| 2057 | if (adv & ADVERTISE_100HALF) |
| 2058 | ecmd->advertising |= ADVERTISED_100baseT_Half; |
| 2059 | if (adv & ADVERTISE_100FULL) |
| 2060 | ecmd->advertising |= ADVERTISED_100baseT_Full; |
| 2061 | if (np->autoneg && np->gigabit == PHY_GIGABIT) { |
| 2062 | adv = mii_rw(dev, np->phyaddr, MII_1000BT_CR, MII_READ); |
| 2063 | if (adv & ADVERTISE_1000FULL) |
| 2064 | ecmd->advertising |= ADVERTISED_1000baseT_Full; |
| 2065 | } |
| 2066 | |
| 2067 | ecmd->supported = (SUPPORTED_Autoneg | |
| 2068 | SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full | |
| 2069 | SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full | |
| 2070 | SUPPORTED_MII); |
| 2071 | if (np->gigabit == PHY_GIGABIT) |
| 2072 | ecmd->supported |= SUPPORTED_1000baseT_Full; |
| 2073 | |
| 2074 | ecmd->phy_address = np->phyaddr; |
| 2075 | ecmd->transceiver = XCVR_EXTERNAL; |
| 2076 | |
| 2077 | /* ignore maxtxpkt, maxrxpkt for now */ |
| 2078 | spin_unlock_irq(&np->lock); |
| 2079 | return 0; |
| 2080 | } |
| 2081 | |
| 2082 | static int nv_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd) |
| 2083 | { |
| 2084 | struct fe_priv *np = netdev_priv(dev); |
| 2085 | |
| 2086 | if (ecmd->port != PORT_MII) |
| 2087 | return -EINVAL; |
| 2088 | if (ecmd->transceiver != XCVR_EXTERNAL) |
| 2089 | return -EINVAL; |
| 2090 | if (ecmd->phy_address != np->phyaddr) { |
| 2091 | /* TODO: support switching between multiple phys. Should be |
| 2092 | * trivial, but not enabled due to lack of test hardware. */ |
| 2093 | return -EINVAL; |
| 2094 | } |
| 2095 | if (ecmd->autoneg == AUTONEG_ENABLE) { |
| 2096 | u32 mask; |
| 2097 | |
| 2098 | mask = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 2099 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full; |
| 2100 | if (np->gigabit == PHY_GIGABIT) |
| 2101 | mask |= ADVERTISED_1000baseT_Full; |
| 2102 | |
| 2103 | if ((ecmd->advertising & mask) == 0) |
| 2104 | return -EINVAL; |
| 2105 | |
| 2106 | } else if (ecmd->autoneg == AUTONEG_DISABLE) { |
| 2107 | /* Note: autonegotiation disable, speed 1000 intentionally |
| 2108 | * forbidden - noone should need that. */ |
| 2109 | |
| 2110 | if (ecmd->speed != SPEED_10 && ecmd->speed != SPEED_100) |
| 2111 | return -EINVAL; |
| 2112 | if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL) |
| 2113 | return -EINVAL; |
| 2114 | } else { |
| 2115 | return -EINVAL; |
| 2116 | } |
| 2117 | |
| 2118 | spin_lock_irq(&np->lock); |
| 2119 | if (ecmd->autoneg == AUTONEG_ENABLE) { |
| 2120 | int adv, bmcr; |
| 2121 | |
| 2122 | np->autoneg = 1; |
| 2123 | |
| 2124 | /* advertise only what has been requested */ |
| 2125 | adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ); |
| 2126 | adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4); |
| 2127 | if (ecmd->advertising & ADVERTISED_10baseT_Half) |
| 2128 | adv |= ADVERTISE_10HALF; |
| 2129 | if (ecmd->advertising & ADVERTISED_10baseT_Full) |
| 2130 | adv |= ADVERTISE_10FULL; |
| 2131 | if (ecmd->advertising & ADVERTISED_100baseT_Half) |
| 2132 | adv |= ADVERTISE_100HALF; |
| 2133 | if (ecmd->advertising & ADVERTISED_100baseT_Full) |
| 2134 | adv |= ADVERTISE_100FULL; |
| 2135 | mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv); |
| 2136 | |
| 2137 | if (np->gigabit == PHY_GIGABIT) { |
| 2138 | adv = mii_rw(dev, np->phyaddr, MII_1000BT_CR, MII_READ); |
| 2139 | adv &= ~ADVERTISE_1000FULL; |
| 2140 | if (ecmd->advertising & ADVERTISED_1000baseT_Full) |
| 2141 | adv |= ADVERTISE_1000FULL; |
| 2142 | mii_rw(dev, np->phyaddr, MII_1000BT_CR, adv); |
| 2143 | } |
| 2144 | |
| 2145 | bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
| 2146 | bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART); |
| 2147 | mii_rw(dev, np->phyaddr, MII_BMCR, bmcr); |
| 2148 | |
| 2149 | } else { |
| 2150 | int adv, bmcr; |
| 2151 | |
| 2152 | np->autoneg = 0; |
| 2153 | |
| 2154 | adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ); |
| 2155 | adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4); |
| 2156 | if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_HALF) |
| 2157 | adv |= ADVERTISE_10HALF; |
| 2158 | if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_FULL) |
| 2159 | adv |= ADVERTISE_10FULL; |
| 2160 | if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_HALF) |
| 2161 | adv |= ADVERTISE_100HALF; |
| 2162 | if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_FULL) |
| 2163 | adv |= ADVERTISE_100FULL; |
| 2164 | mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv); |
| 2165 | np->fixed_mode = adv; |
| 2166 | |
| 2167 | if (np->gigabit == PHY_GIGABIT) { |
| 2168 | adv = mii_rw(dev, np->phyaddr, MII_1000BT_CR, MII_READ); |
| 2169 | adv &= ~ADVERTISE_1000FULL; |
| 2170 | mii_rw(dev, np->phyaddr, MII_1000BT_CR, adv); |
| 2171 | } |
| 2172 | |
| 2173 | bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
| 2174 | bmcr |= ~(BMCR_ANENABLE|BMCR_SPEED100|BMCR_FULLDPLX); |
| 2175 | if (adv & (ADVERTISE_10FULL|ADVERTISE_100FULL)) |
| 2176 | bmcr |= BMCR_FULLDPLX; |
| 2177 | if (adv & (ADVERTISE_100HALF|ADVERTISE_100FULL)) |
| 2178 | bmcr |= BMCR_SPEED100; |
| 2179 | mii_rw(dev, np->phyaddr, MII_BMCR, bmcr); |
| 2180 | |
| 2181 | if (netif_running(dev)) { |
| 2182 | /* Wait a bit and then reconfigure the nic. */ |
| 2183 | udelay(10); |
| 2184 | nv_linkchange(dev); |
| 2185 | } |
| 2186 | } |
| 2187 | spin_unlock_irq(&np->lock); |
| 2188 | |
| 2189 | return 0; |
| 2190 | } |
| 2191 | |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 2192 | #define FORCEDETH_REGS_VER 1 |
| 2193 | #define FORCEDETH_REGS_SIZE 0x400 /* 256 32-bit registers */ |
| 2194 | |
| 2195 | static int nv_get_regs_len(struct net_device *dev) |
| 2196 | { |
| 2197 | return FORCEDETH_REGS_SIZE; |
| 2198 | } |
| 2199 | |
| 2200 | static void nv_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *buf) |
| 2201 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2202 | struct fe_priv *np = netdev_priv(dev); |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 2203 | u8 __iomem *base = get_hwbase(dev); |
| 2204 | u32 *rbuf = buf; |
| 2205 | int i; |
| 2206 | |
| 2207 | regs->version = FORCEDETH_REGS_VER; |
| 2208 | spin_lock_irq(&np->lock); |
| 2209 | for (i=0;i<FORCEDETH_REGS_SIZE/sizeof(u32);i++) |
| 2210 | rbuf[i] = readl(base + i*sizeof(u32)); |
| 2211 | spin_unlock_irq(&np->lock); |
| 2212 | } |
| 2213 | |
| 2214 | static int nv_nway_reset(struct net_device *dev) |
| 2215 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2216 | struct fe_priv *np = netdev_priv(dev); |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 2217 | int ret; |
| 2218 | |
| 2219 | spin_lock_irq(&np->lock); |
| 2220 | if (np->autoneg) { |
| 2221 | int bmcr; |
| 2222 | |
| 2223 | bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
| 2224 | bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART); |
| 2225 | mii_rw(dev, np->phyaddr, MII_BMCR, bmcr); |
| 2226 | |
| 2227 | ret = 0; |
| 2228 | } else { |
| 2229 | ret = -EINVAL; |
| 2230 | } |
| 2231 | spin_unlock_irq(&np->lock); |
| 2232 | |
| 2233 | return ret; |
| 2234 | } |
| 2235 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2236 | static struct ethtool_ops ops = { |
| 2237 | .get_drvinfo = nv_get_drvinfo, |
| 2238 | .get_link = ethtool_op_get_link, |
| 2239 | .get_wol = nv_get_wol, |
| 2240 | .set_wol = nv_set_wol, |
| 2241 | .get_settings = nv_get_settings, |
| 2242 | .set_settings = nv_set_settings, |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 2243 | .get_regs_len = nv_get_regs_len, |
| 2244 | .get_regs = nv_get_regs, |
| 2245 | .nway_reset = nv_nway_reset, |
John W. Linville | c704b85 | 2005-09-12 10:48:56 -0400 | [diff] [blame] | 2246 | .get_perm_addr = ethtool_op_get_perm_addr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2247 | }; |
| 2248 | |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame^] | 2249 | static void nv_vlan_rx_register(struct net_device *dev, struct vlan_group *grp) |
| 2250 | { |
| 2251 | struct fe_priv *np = get_nvpriv(dev); |
| 2252 | |
| 2253 | spin_lock_irq(&np->lock); |
| 2254 | |
| 2255 | /* save vlan group */ |
| 2256 | np->vlangrp = grp; |
| 2257 | |
| 2258 | if (grp) { |
| 2259 | /* enable vlan on MAC */ |
| 2260 | np->txrxctl_bits |= NVREG_TXRXCTL_VLANSTRIP | NVREG_TXRXCTL_VLANINS; |
| 2261 | } else { |
| 2262 | /* disable vlan on MAC */ |
| 2263 | np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANSTRIP; |
| 2264 | np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANINS; |
| 2265 | } |
| 2266 | |
| 2267 | writel(np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl); |
| 2268 | |
| 2269 | spin_unlock_irq(&np->lock); |
| 2270 | }; |
| 2271 | |
| 2272 | static void nv_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid) |
| 2273 | { |
| 2274 | /* nothing to do */ |
| 2275 | }; |
| 2276 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2277 | static int nv_open(struct net_device *dev) |
| 2278 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2279 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2280 | u8 __iomem *base = get_hwbase(dev); |
| 2281 | int ret, oom, i; |
| 2282 | |
| 2283 | dprintk(KERN_DEBUG "nv_open: begin\n"); |
| 2284 | |
| 2285 | /* 1) erase previous misconfiguration */ |
| 2286 | /* 4.1-1: stop adapter: ignored, 4.3 seems to be overkill */ |
| 2287 | writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA); |
| 2288 | writel(0, base + NvRegMulticastAddrB); |
| 2289 | writel(0, base + NvRegMulticastMaskA); |
| 2290 | writel(0, base + NvRegMulticastMaskB); |
| 2291 | writel(0, base + NvRegPacketFilterFlags); |
| 2292 | |
| 2293 | writel(0, base + NvRegTransmitterControl); |
| 2294 | writel(0, base + NvRegReceiverControl); |
| 2295 | |
| 2296 | writel(0, base + NvRegAdapterControl); |
| 2297 | |
| 2298 | /* 2) initialize descriptor rings */ |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 2299 | set_bufsize(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2300 | oom = nv_init_ring(dev); |
| 2301 | |
| 2302 | writel(0, base + NvRegLinkSpeed); |
| 2303 | writel(0, base + NvRegUnknownTransmitterReg); |
| 2304 | nv_txrx_reset(dev); |
| 2305 | writel(0, base + NvRegUnknownSetupReg6); |
| 2306 | |
| 2307 | np->in_shutdown = 0; |
| 2308 | |
| 2309 | /* 3) set mac address */ |
Manfred Spraul | 72b3178 | 2005-07-31 18:33:34 +0200 | [diff] [blame] | 2310 | nv_copy_mac_to_hw(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2311 | |
| 2312 | /* 4) give hw rings */ |
| 2313 | writel((u32) np->ring_addr, base + NvRegRxRingPhysAddr); |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 2314 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
| 2315 | writel((u32) (np->ring_addr + RX_RING*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr); |
| 2316 | else |
| 2317 | writel((u32) (np->ring_addr + RX_RING*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2318 | writel( ((RX_RING-1) << NVREG_RINGSZ_RXSHIFT) + ((TX_RING-1) << NVREG_RINGSZ_TXSHIFT), |
| 2319 | base + NvRegRingSizes); |
| 2320 | |
| 2321 | /* 5) continue setup */ |
| 2322 | writel(np->linkspeed, base + NvRegLinkSpeed); |
| 2323 | writel(NVREG_UNKSETUP3_VAL1, base + NvRegUnknownSetupReg3); |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 2324 | writel(np->txrxctl_bits, base + NvRegTxRxControl); |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame^] | 2325 | writel(np->vlanctl_bits, base + NvRegVlanControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2326 | pci_push(base); |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 2327 | writel(NVREG_TXRXCTL_BIT1|np->txrxctl_bits, base + NvRegTxRxControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2328 | reg_delay(dev, NvRegUnknownSetupReg5, NVREG_UNKSETUP5_BIT31, NVREG_UNKSETUP5_BIT31, |
| 2329 | NV_SETUP5_DELAY, NV_SETUP5_DELAYMAX, |
| 2330 | KERN_INFO "open: SetupReg5, Bit 31 remained off\n"); |
| 2331 | |
| 2332 | writel(0, base + NvRegUnknownSetupReg4); |
| 2333 | writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus); |
| 2334 | writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus); |
| 2335 | |
| 2336 | /* 6) continue setup */ |
| 2337 | writel(NVREG_MISC1_FORCE | NVREG_MISC1_HD, base + NvRegMisc1); |
| 2338 | writel(readl(base + NvRegTransmitterStatus), base + NvRegTransmitterStatus); |
| 2339 | writel(NVREG_PFF_ALWAYS, base + NvRegPacketFilterFlags); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 2340 | writel(np->rx_buf_sz, base + NvRegOffloadConfig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2341 | |
| 2342 | writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus); |
| 2343 | get_random_bytes(&i, sizeof(i)); |
| 2344 | writel(NVREG_RNDSEED_FORCE | (i&NVREG_RNDSEED_MASK), base + NvRegRandomSeed); |
| 2345 | writel(NVREG_UNKSETUP1_VAL, base + NvRegUnknownSetupReg1); |
| 2346 | writel(NVREG_UNKSETUP2_VAL, base + NvRegUnknownSetupReg2); |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2347 | if (poll_interval == -1) { |
| 2348 | if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT) |
| 2349 | writel(NVREG_POLL_DEFAULT_THROUGHPUT, base + NvRegPollingInterval); |
| 2350 | else |
| 2351 | writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval); |
| 2352 | } |
| 2353 | else |
| 2354 | writel(poll_interval & 0xFFFF, base + NvRegPollingInterval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2355 | writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6); |
| 2356 | writel((np->phyaddr << NVREG_ADAPTCTL_PHYSHIFT)|NVREG_ADAPTCTL_PHYVALID|NVREG_ADAPTCTL_RUNNING, |
| 2357 | base + NvRegAdapterControl); |
| 2358 | writel(NVREG_MIISPEED_BIT8|NVREG_MIIDELAY, base + NvRegMIISpeed); |
| 2359 | writel(NVREG_UNKSETUP4_VAL, base + NvRegUnknownSetupReg4); |
| 2360 | writel(NVREG_WAKEUPFLAGS_VAL, base + NvRegWakeUpFlags); |
| 2361 | |
| 2362 | i = readl(base + NvRegPowerState); |
| 2363 | if ( (i & NVREG_POWERSTATE_POWEREDUP) == 0) |
| 2364 | writel(NVREG_POWERSTATE_POWEREDUP|i, base + NvRegPowerState); |
| 2365 | |
| 2366 | pci_push(base); |
| 2367 | udelay(10); |
| 2368 | writel(readl(base + NvRegPowerState) | NVREG_POWERSTATE_VALID, base + NvRegPowerState); |
| 2369 | |
| 2370 | writel(0, base + NvRegIrqMask); |
| 2371 | pci_push(base); |
| 2372 | writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus); |
| 2373 | writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus); |
| 2374 | pci_push(base); |
| 2375 | |
| 2376 | ret = request_irq(dev->irq, &nv_nic_irq, SA_SHIRQ, dev->name, dev); |
| 2377 | if (ret) |
| 2378 | goto out_drain; |
| 2379 | |
| 2380 | /* ask for interrupts */ |
| 2381 | writel(np->irqmask, base + NvRegIrqMask); |
| 2382 | |
| 2383 | spin_lock_irq(&np->lock); |
| 2384 | writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA); |
| 2385 | writel(0, base + NvRegMulticastAddrB); |
| 2386 | writel(0, base + NvRegMulticastMaskA); |
| 2387 | writel(0, base + NvRegMulticastMaskB); |
| 2388 | writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags); |
| 2389 | /* One manual link speed update: Interrupts are enabled, future link |
| 2390 | * speed changes cause interrupts and are handled by nv_link_irq(). |
| 2391 | */ |
| 2392 | { |
| 2393 | u32 miistat; |
| 2394 | miistat = readl(base + NvRegMIIStatus); |
| 2395 | writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus); |
| 2396 | dprintk(KERN_INFO "startup: got 0x%08x.\n", miistat); |
| 2397 | } |
Manfred Spraul | 1b1b3c9 | 2005-08-06 23:47:55 +0200 | [diff] [blame] | 2398 | /* set linkspeed to invalid value, thus force nv_update_linkspeed |
| 2399 | * to init hw */ |
| 2400 | np->linkspeed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2401 | ret = nv_update_linkspeed(dev); |
| 2402 | nv_start_rx(dev); |
| 2403 | nv_start_tx(dev); |
| 2404 | netif_start_queue(dev); |
| 2405 | if (ret) { |
| 2406 | netif_carrier_on(dev); |
| 2407 | } else { |
| 2408 | printk("%s: no link during initialization.\n", dev->name); |
| 2409 | netif_carrier_off(dev); |
| 2410 | } |
| 2411 | if (oom) |
| 2412 | mod_timer(&np->oom_kick, jiffies + OOM_REFILL); |
| 2413 | spin_unlock_irq(&np->lock); |
| 2414 | |
| 2415 | return 0; |
| 2416 | out_drain: |
| 2417 | drain_ring(dev); |
| 2418 | return ret; |
| 2419 | } |
| 2420 | |
| 2421 | static int nv_close(struct net_device *dev) |
| 2422 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2423 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2424 | u8 __iomem *base; |
| 2425 | |
| 2426 | spin_lock_irq(&np->lock); |
| 2427 | np->in_shutdown = 1; |
| 2428 | spin_unlock_irq(&np->lock); |
| 2429 | synchronize_irq(dev->irq); |
| 2430 | |
| 2431 | del_timer_sync(&np->oom_kick); |
| 2432 | del_timer_sync(&np->nic_poll); |
| 2433 | |
| 2434 | netif_stop_queue(dev); |
| 2435 | spin_lock_irq(&np->lock); |
| 2436 | nv_stop_tx(dev); |
| 2437 | nv_stop_rx(dev); |
| 2438 | nv_txrx_reset(dev); |
| 2439 | |
| 2440 | /* disable interrupts on the nic or we will lock up */ |
| 2441 | base = get_hwbase(dev); |
| 2442 | writel(0, base + NvRegIrqMask); |
| 2443 | pci_push(base); |
| 2444 | dprintk(KERN_INFO "%s: Irqmask is zero again\n", dev->name); |
| 2445 | |
| 2446 | spin_unlock_irq(&np->lock); |
| 2447 | |
| 2448 | free_irq(dev->irq, dev); |
| 2449 | |
| 2450 | drain_ring(dev); |
| 2451 | |
| 2452 | if (np->wolenabled) |
| 2453 | nv_start_rx(dev); |
| 2454 | |
Manfred Spraul | b3df9f8 | 2005-07-31 18:38:58 +0200 | [diff] [blame] | 2455 | /* special op: write back the misordered MAC address - otherwise |
| 2456 | * the next nv_probe would see a wrong address. |
| 2457 | */ |
| 2458 | writel(np->orig_mac[0], base + NvRegMacAddrA); |
| 2459 | writel(np->orig_mac[1], base + NvRegMacAddrB); |
| 2460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2461 | /* FIXME: power down nic */ |
| 2462 | |
| 2463 | return 0; |
| 2464 | } |
| 2465 | |
| 2466 | static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id) |
| 2467 | { |
| 2468 | struct net_device *dev; |
| 2469 | struct fe_priv *np; |
| 2470 | unsigned long addr; |
| 2471 | u8 __iomem *base; |
| 2472 | int err, i; |
| 2473 | |
| 2474 | dev = alloc_etherdev(sizeof(struct fe_priv)); |
| 2475 | err = -ENOMEM; |
| 2476 | if (!dev) |
| 2477 | goto out; |
| 2478 | |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2479 | np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2480 | np->pci_dev = pci_dev; |
| 2481 | spin_lock_init(&np->lock); |
| 2482 | SET_MODULE_OWNER(dev); |
| 2483 | SET_NETDEV_DEV(dev, &pci_dev->dev); |
| 2484 | |
| 2485 | init_timer(&np->oom_kick); |
| 2486 | np->oom_kick.data = (unsigned long) dev; |
| 2487 | np->oom_kick.function = &nv_do_rx_refill; /* timer handler */ |
| 2488 | init_timer(&np->nic_poll); |
| 2489 | np->nic_poll.data = (unsigned long) dev; |
| 2490 | np->nic_poll.function = &nv_do_nic_poll; /* timer handler */ |
| 2491 | |
| 2492 | err = pci_enable_device(pci_dev); |
| 2493 | if (err) { |
| 2494 | printk(KERN_INFO "forcedeth: pci_enable_dev failed (%d) for device %s\n", |
| 2495 | err, pci_name(pci_dev)); |
| 2496 | goto out_free; |
| 2497 | } |
| 2498 | |
| 2499 | pci_set_master(pci_dev); |
| 2500 | |
| 2501 | err = pci_request_regions(pci_dev, DRV_NAME); |
| 2502 | if (err < 0) |
| 2503 | goto out_disable; |
| 2504 | |
| 2505 | err = -EINVAL; |
| 2506 | addr = 0; |
| 2507 | for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { |
| 2508 | dprintk(KERN_DEBUG "%s: resource %d start %p len %ld flags 0x%08lx.\n", |
| 2509 | pci_name(pci_dev), i, (void*)pci_resource_start(pci_dev, i), |
| 2510 | pci_resource_len(pci_dev, i), |
| 2511 | pci_resource_flags(pci_dev, i)); |
| 2512 | if (pci_resource_flags(pci_dev, i) & IORESOURCE_MEM && |
| 2513 | pci_resource_len(pci_dev, i) >= NV_PCI_REGSZ) { |
| 2514 | addr = pci_resource_start(pci_dev, i); |
| 2515 | break; |
| 2516 | } |
| 2517 | } |
| 2518 | if (i == DEVICE_COUNT_RESOURCE) { |
| 2519 | printk(KERN_INFO "forcedeth: Couldn't find register window for device %s.\n", |
| 2520 | pci_name(pci_dev)); |
| 2521 | goto out_relreg; |
| 2522 | } |
| 2523 | |
| 2524 | /* handle different descriptor versions */ |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 2525 | if (id->driver_data & DEV_HAS_HIGH_DMA) { |
| 2526 | /* packet format 3: supports 40-bit addressing */ |
| 2527 | np->desc_ver = DESC_VER_3; |
| 2528 | if (pci_set_dma_mask(pci_dev, 0x0000007fffffffffULL)) { |
| 2529 | printk(KERN_INFO "forcedeth: 64-bit DMA failed, using 32-bit addressing for device %s.\n", |
| 2530 | pci_name(pci_dev)); |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2531 | } else { |
| 2532 | dev->features |= NETIF_F_HIGHDMA; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 2533 | } |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 2534 | np->txrxctl_bits = NVREG_TXRXCTL_DESC_3; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 2535 | } else if (id->driver_data & DEV_HAS_LARGEDESC) { |
| 2536 | /* packet format 2: supports jumbo frames */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2537 | np->desc_ver = DESC_VER_2; |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 2538 | np->txrxctl_bits = NVREG_TXRXCTL_DESC_2; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 2539 | } else { |
| 2540 | /* original packet format */ |
| 2541 | np->desc_ver = DESC_VER_1; |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 2542 | np->txrxctl_bits = NVREG_TXRXCTL_DESC_1; |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 2543 | } |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 2544 | |
| 2545 | np->pkt_limit = NV_PKTLIMIT_1; |
| 2546 | if (id->driver_data & DEV_HAS_LARGEDESC) |
| 2547 | np->pkt_limit = NV_PKTLIMIT_2; |
| 2548 | |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 2549 | if (id->driver_data & DEV_HAS_CHECKSUM) { |
| 2550 | np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2551 | dev->features |= NETIF_F_HW_CSUM | NETIF_F_SG; |
| 2552 | #ifdef NETIF_F_TSO |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 2553 | dev->features |= NETIF_F_TSO; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2554 | #endif |
| 2555 | } |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 2556 | |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame^] | 2557 | np->vlanctl_bits = 0; |
| 2558 | if (id->driver_data & DEV_HAS_VLAN) { |
| 2559 | np->vlanctl_bits = NVREG_VLANCONTROL_ENABLE; |
| 2560 | dev->features |= NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX; |
| 2561 | dev->vlan_rx_register = nv_vlan_rx_register; |
| 2562 | dev->vlan_rx_kill_vid = nv_vlan_rx_kill_vid; |
| 2563 | } |
| 2564 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2565 | err = -ENOMEM; |
| 2566 | np->base = ioremap(addr, NV_PCI_REGSZ); |
| 2567 | if (!np->base) |
| 2568 | goto out_relreg; |
| 2569 | dev->base_addr = (unsigned long)np->base; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 2570 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2571 | dev->irq = pci_dev->irq; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 2572 | |
| 2573 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
| 2574 | np->rx_ring.orig = pci_alloc_consistent(pci_dev, |
| 2575 | sizeof(struct ring_desc) * (RX_RING + TX_RING), |
| 2576 | &np->ring_addr); |
| 2577 | if (!np->rx_ring.orig) |
| 2578 | goto out_unmap; |
| 2579 | np->tx_ring.orig = &np->rx_ring.orig[RX_RING]; |
| 2580 | } else { |
| 2581 | np->rx_ring.ex = pci_alloc_consistent(pci_dev, |
| 2582 | sizeof(struct ring_desc_ex) * (RX_RING + TX_RING), |
| 2583 | &np->ring_addr); |
| 2584 | if (!np->rx_ring.ex) |
| 2585 | goto out_unmap; |
| 2586 | np->tx_ring.ex = &np->rx_ring.ex[RX_RING]; |
| 2587 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2588 | |
| 2589 | dev->open = nv_open; |
| 2590 | dev->stop = nv_close; |
| 2591 | dev->hard_start_xmit = nv_start_xmit; |
| 2592 | dev->get_stats = nv_get_stats; |
| 2593 | dev->change_mtu = nv_change_mtu; |
Manfred Spraul | 72b3178 | 2005-07-31 18:33:34 +0200 | [diff] [blame] | 2594 | dev->set_mac_address = nv_set_mac_address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2595 | dev->set_multicast_list = nv_set_multicast; |
Michal Schmidt | 2918c35 | 2005-05-12 19:42:06 -0400 | [diff] [blame] | 2596 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 2597 | dev->poll_controller = nv_poll_controller; |
| 2598 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2599 | SET_ETHTOOL_OPS(dev, &ops); |
| 2600 | dev->tx_timeout = nv_tx_timeout; |
| 2601 | dev->watchdog_timeo = NV_WATCHDOG_TIMEO; |
| 2602 | |
| 2603 | pci_set_drvdata(pci_dev, dev); |
| 2604 | |
| 2605 | /* read the mac address */ |
| 2606 | base = get_hwbase(dev); |
| 2607 | np->orig_mac[0] = readl(base + NvRegMacAddrA); |
| 2608 | np->orig_mac[1] = readl(base + NvRegMacAddrB); |
| 2609 | |
| 2610 | dev->dev_addr[0] = (np->orig_mac[1] >> 8) & 0xff; |
| 2611 | dev->dev_addr[1] = (np->orig_mac[1] >> 0) & 0xff; |
| 2612 | dev->dev_addr[2] = (np->orig_mac[0] >> 24) & 0xff; |
| 2613 | dev->dev_addr[3] = (np->orig_mac[0] >> 16) & 0xff; |
| 2614 | dev->dev_addr[4] = (np->orig_mac[0] >> 8) & 0xff; |
| 2615 | dev->dev_addr[5] = (np->orig_mac[0] >> 0) & 0xff; |
John W. Linville | c704b85 | 2005-09-12 10:48:56 -0400 | [diff] [blame] | 2616 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2617 | |
John W. Linville | c704b85 | 2005-09-12 10:48:56 -0400 | [diff] [blame] | 2618 | if (!is_valid_ether_addr(dev->perm_addr)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2619 | /* |
| 2620 | * Bad mac address. At least one bios sets the mac address |
| 2621 | * to 01:23:45:67:89:ab |
| 2622 | */ |
| 2623 | printk(KERN_ERR "%s: Invalid Mac address detected: %02x:%02x:%02x:%02x:%02x:%02x\n", |
| 2624 | pci_name(pci_dev), |
| 2625 | dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2], |
| 2626 | dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]); |
| 2627 | printk(KERN_ERR "Please complain to your hardware vendor. Switching to a random MAC.\n"); |
| 2628 | dev->dev_addr[0] = 0x00; |
| 2629 | dev->dev_addr[1] = 0x00; |
| 2630 | dev->dev_addr[2] = 0x6c; |
| 2631 | get_random_bytes(&dev->dev_addr[3], 3); |
| 2632 | } |
| 2633 | |
| 2634 | dprintk(KERN_DEBUG "%s: MAC Address %02x:%02x:%02x:%02x:%02x:%02x\n", pci_name(pci_dev), |
| 2635 | dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2], |
| 2636 | dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]); |
| 2637 | |
| 2638 | /* disable WOL */ |
| 2639 | writel(0, base + NvRegWakeUpFlags); |
| 2640 | np->wolenabled = 0; |
| 2641 | |
| 2642 | if (np->desc_ver == DESC_VER_1) { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2643 | np->tx_flags = NV_TX_VALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | } else { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2645 | np->tx_flags = NV_TX2_VALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2646 | } |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2647 | if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT) |
| 2648 | np->irqmask = NVREG_IRQMASK_THROUGHPUT; |
| 2649 | else |
| 2650 | np->irqmask = NVREG_IRQMASK_CPU; |
| 2651 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2652 | if (id->driver_data & DEV_NEED_TIMERIRQ) |
| 2653 | np->irqmask |= NVREG_IRQ_TIMER; |
| 2654 | if (id->driver_data & DEV_NEED_LINKTIMER) { |
| 2655 | dprintk(KERN_INFO "%s: link timer on.\n", pci_name(pci_dev)); |
| 2656 | np->need_linktimer = 1; |
| 2657 | np->link_timeout = jiffies + LINK_TIMEOUT; |
| 2658 | } else { |
| 2659 | dprintk(KERN_INFO "%s: link timer off.\n", pci_name(pci_dev)); |
| 2660 | np->need_linktimer = 0; |
| 2661 | } |
| 2662 | |
| 2663 | /* find a suitable phy */ |
Ayaz Abdulla | 7a33e45 | 2005-11-11 08:31:11 -0500 | [diff] [blame] | 2664 | for (i = 1; i <= 32; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2665 | int id1, id2; |
Ayaz Abdulla | 7a33e45 | 2005-11-11 08:31:11 -0500 | [diff] [blame] | 2666 | int phyaddr = i & 0x1F; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2667 | |
| 2668 | spin_lock_irq(&np->lock); |
Ayaz Abdulla | 7a33e45 | 2005-11-11 08:31:11 -0500 | [diff] [blame] | 2669 | id1 = mii_rw(dev, phyaddr, MII_PHYSID1, MII_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2670 | spin_unlock_irq(&np->lock); |
| 2671 | if (id1 < 0 || id1 == 0xffff) |
| 2672 | continue; |
| 2673 | spin_lock_irq(&np->lock); |
Ayaz Abdulla | 7a33e45 | 2005-11-11 08:31:11 -0500 | [diff] [blame] | 2674 | id2 = mii_rw(dev, phyaddr, MII_PHYSID2, MII_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2675 | spin_unlock_irq(&np->lock); |
| 2676 | if (id2 < 0 || id2 == 0xffff) |
| 2677 | continue; |
| 2678 | |
| 2679 | id1 = (id1 & PHYID1_OUI_MASK) << PHYID1_OUI_SHFT; |
| 2680 | id2 = (id2 & PHYID2_OUI_MASK) >> PHYID2_OUI_SHFT; |
| 2681 | dprintk(KERN_DEBUG "%s: open: Found PHY %04x:%04x at address %d.\n", |
Ayaz Abdulla | 7a33e45 | 2005-11-11 08:31:11 -0500 | [diff] [blame] | 2682 | pci_name(pci_dev), id1, id2, phyaddr); |
| 2683 | np->phyaddr = phyaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2684 | np->phy_oui = id1 | id2; |
| 2685 | break; |
| 2686 | } |
Ayaz Abdulla | 7a33e45 | 2005-11-11 08:31:11 -0500 | [diff] [blame] | 2687 | if (i == 33) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2688 | printk(KERN_INFO "%s: open: Could not find a valid PHY.\n", |
Ayaz Abdulla | 7a33e45 | 2005-11-11 08:31:11 -0500 | [diff] [blame] | 2689 | pci_name(pci_dev)); |
| 2690 | goto out_freering; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2691 | } |
Ayaz Abdulla | 7a33e45 | 2005-11-11 08:31:11 -0500 | [diff] [blame] | 2692 | |
| 2693 | /* reset it */ |
| 2694 | phy_init(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2695 | |
| 2696 | /* set default link speed settings */ |
| 2697 | np->linkspeed = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 2698 | np->duplex = 0; |
| 2699 | np->autoneg = 1; |
| 2700 | |
| 2701 | err = register_netdev(dev); |
| 2702 | if (err) { |
| 2703 | printk(KERN_INFO "forcedeth: unable to register netdev: %d\n", err); |
| 2704 | goto out_freering; |
| 2705 | } |
| 2706 | printk(KERN_INFO "%s: forcedeth.c: subsystem: %05x:%04x bound to %s\n", |
| 2707 | dev->name, pci_dev->subsystem_vendor, pci_dev->subsystem_device, |
| 2708 | pci_name(pci_dev)); |
| 2709 | |
| 2710 | return 0; |
| 2711 | |
| 2712 | out_freering: |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 2713 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
| 2714 | pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (RX_RING + TX_RING), |
| 2715 | np->rx_ring.orig, np->ring_addr); |
| 2716 | else |
| 2717 | pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (RX_RING + TX_RING), |
| 2718 | np->rx_ring.ex, np->ring_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2719 | pci_set_drvdata(pci_dev, NULL); |
| 2720 | out_unmap: |
| 2721 | iounmap(get_hwbase(dev)); |
| 2722 | out_relreg: |
| 2723 | pci_release_regions(pci_dev); |
| 2724 | out_disable: |
| 2725 | pci_disable_device(pci_dev); |
| 2726 | out_free: |
| 2727 | free_netdev(dev); |
| 2728 | out: |
| 2729 | return err; |
| 2730 | } |
| 2731 | |
| 2732 | static void __devexit nv_remove(struct pci_dev *pci_dev) |
| 2733 | { |
| 2734 | struct net_device *dev = pci_get_drvdata(pci_dev); |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2735 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2736 | |
| 2737 | unregister_netdev(dev); |
| 2738 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2739 | /* free all structures */ |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 2740 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
| 2741 | pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (RX_RING + TX_RING), np->rx_ring.orig, np->ring_addr); |
| 2742 | else |
| 2743 | pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (RX_RING + TX_RING), np->rx_ring.ex, np->ring_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2744 | iounmap(get_hwbase(dev)); |
| 2745 | pci_release_regions(pci_dev); |
| 2746 | pci_disable_device(pci_dev); |
| 2747 | free_netdev(dev); |
| 2748 | pci_set_drvdata(pci_dev, NULL); |
| 2749 | } |
| 2750 | |
| 2751 | static struct pci_device_id pci_tbl[] = { |
| 2752 | { /* nForce Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 2753 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_1), |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 2754 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2755 | }, |
| 2756 | { /* nForce2 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 2757 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_2), |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 2758 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2759 | }, |
| 2760 | { /* nForce3 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 2761 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_3), |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 2762 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2763 | }, |
| 2764 | { /* nForce3 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 2765 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_4), |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 2766 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2767 | }, |
| 2768 | { /* nForce3 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 2769 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_5), |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 2770 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2771 | }, |
| 2772 | { /* nForce3 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 2773 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_6), |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 2774 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2775 | }, |
| 2776 | { /* nForce3 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 2777 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_7), |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 2778 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2779 | }, |
| 2780 | { /* CK804 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 2781 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_8), |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 2782 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2783 | }, |
| 2784 | { /* CK804 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 2785 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_9), |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 2786 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2787 | }, |
| 2788 | { /* MCP04 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 2789 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_10), |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 2790 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2791 | }, |
| 2792 | { /* MCP04 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 2793 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_11), |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 2794 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA, |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 2795 | }, |
| 2796 | { /* MCP51 Ethernet Controller */ |
| 2797 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_12), |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 2798 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2799 | }, |
Manfred Spraul | 9992d4a | 2005-06-05 17:36:11 +0200 | [diff] [blame] | 2800 | { /* MCP51 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 2801 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_13), |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 2802 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA, |
Manfred Spraul | 9992d4a | 2005-06-05 17:36:11 +0200 | [diff] [blame] | 2803 | }, |
Manfred Spraul | f49d16e | 2005-06-26 11:36:52 +0200 | [diff] [blame] | 2804 | { /* MCP55 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 2805 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_14), |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame^] | 2806 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_VLAN, |
Manfred Spraul | f49d16e | 2005-06-26 11:36:52 +0200 | [diff] [blame] | 2807 | }, |
| 2808 | { /* MCP55 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 2809 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_15), |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame^] | 2810 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_VLAN, |
Manfred Spraul | f49d16e | 2005-06-26 11:36:52 +0200 | [diff] [blame] | 2811 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2812 | {0,}, |
| 2813 | }; |
| 2814 | |
| 2815 | static struct pci_driver driver = { |
| 2816 | .name = "forcedeth", |
| 2817 | .id_table = pci_tbl, |
| 2818 | .probe = nv_probe, |
| 2819 | .remove = __devexit_p(nv_remove), |
| 2820 | }; |
| 2821 | |
| 2822 | |
| 2823 | static int __init init_nic(void) |
| 2824 | { |
| 2825 | printk(KERN_INFO "forcedeth.c: Reverse Engineered nForce ethernet driver. Version %s.\n", FORCEDETH_VERSION); |
| 2826 | return pci_module_init(&driver); |
| 2827 | } |
| 2828 | |
| 2829 | static void __exit exit_nic(void) |
| 2830 | { |
| 2831 | pci_unregister_driver(&driver); |
| 2832 | } |
| 2833 | |
| 2834 | module_param(max_interrupt_work, int, 0); |
| 2835 | MODULE_PARM_DESC(max_interrupt_work, "forcedeth maximum events handled per interrupt"); |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2836 | module_param(optimization_mode, int, 0); |
| 2837 | MODULE_PARM_DESC(optimization_mode, "In throughput mode (0), every tx & rx packet will generate an interrupt. In CPU mode (1), interrupts are controlled by a timer."); |
| 2838 | module_param(poll_interval, int, 0); |
| 2839 | MODULE_PARM_DESC(poll_interval, "Interval determines how frequent timer interrupt is generated by [(time_in_micro_secs * 100) / (2^10)]. Min is 0 and Max is 65535."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2840 | |
| 2841 | MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>"); |
| 2842 | MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver"); |
| 2843 | MODULE_LICENSE("GPL"); |
| 2844 | |
| 2845 | MODULE_DEVICE_TABLE(pci, pci_tbl); |
| 2846 | |
| 2847 | module_init(init_nic); |
| 2848 | module_exit(exit_nic); |