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 |
Ayaz Abdulla | 87046e5 | 2006-12-19 23:33:32 -0500 | [diff] [blame] | 6 | * and Andrew de Quincey. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * NVIDIA, nForce and other NVIDIA marks are trademarks or registered |
| 9 | * trademarks of NVIDIA Corporation in the United States and other |
| 10 | * countries. |
| 11 | * |
Manfred Spraul | 1836098 | 2005-12-24 14:19:24 +0100 | [diff] [blame] | 12 | * Copyright (C) 2003,4,5 Manfred Spraul |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | * Copyright (C) 2004 Andrew de Quincey (wol support) |
| 14 | * Copyright (C) 2004 Carl-Daniel Hailfinger (invalid MAC handling, insane |
| 15 | * IRQ rate fixes, bigendian fixes, cleanups, verification) |
Ayaz Abdulla | 87046e5 | 2006-12-19 23:33:32 -0500 | [diff] [blame] | 16 | * Copyright (c) 2004,5,6 NVIDIA Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | * |
| 18 | * This program is free software; you can redistribute it and/or modify |
| 19 | * it under the terms of the GNU General Public License as published by |
| 20 | * the Free Software Foundation; either version 2 of the License, or |
| 21 | * (at your option) any later version. |
| 22 | * |
| 23 | * This program is distributed in the hope that it will be useful, |
| 24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 26 | * GNU General Public License for more details. |
| 27 | * |
| 28 | * You should have received a copy of the GNU General Public License |
| 29 | * along with this program; if not, write to the Free Software |
| 30 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 31 | * |
| 32 | * Changelog: |
| 33 | * 0.01: 05 Oct 2003: First release that compiles without warnings. |
| 34 | * 0.02: 05 Oct 2003: Fix bug for nv_drain_tx: do not try to free NULL skbs. |
| 35 | * Check all PCI BARs for the register window. |
| 36 | * udelay added to mii_rw. |
| 37 | * 0.03: 06 Oct 2003: Initialize dev->irq. |
| 38 | * 0.04: 07 Oct 2003: Initialize np->lock, reduce handled irqs, add printks. |
| 39 | * 0.05: 09 Oct 2003: printk removed again, irq status print tx_timeout. |
| 40 | * 0.06: 10 Oct 2003: MAC Address read updated, pff flag generation updated, |
| 41 | * irq mask updated |
| 42 | * 0.07: 14 Oct 2003: Further irq mask updates. |
| 43 | * 0.08: 20 Oct 2003: rx_desc.Length initialization added, nv_alloc_rx refill |
| 44 | * added into irq handler, NULL check for drain_ring. |
| 45 | * 0.09: 20 Oct 2003: Basic link speed irq implementation. Only handle the |
| 46 | * requested interrupt sources. |
| 47 | * 0.10: 20 Oct 2003: First cleanup for release. |
| 48 | * 0.11: 21 Oct 2003: hexdump for tx added, rx buffer sizes increased. |
| 49 | * MAC Address init fix, set_multicast cleanup. |
| 50 | * 0.12: 23 Oct 2003: Cleanups for release. |
| 51 | * 0.13: 25 Oct 2003: Limit for concurrent tx packets increased to 10. |
| 52 | * Set link speed correctly. start rx before starting |
| 53 | * tx (nv_start_rx sets the link speed). |
| 54 | * 0.14: 25 Oct 2003: Nic dependant irq mask. |
| 55 | * 0.15: 08 Nov 2003: fix smp deadlock with set_multicast_list during |
| 56 | * open. |
| 57 | * 0.16: 15 Nov 2003: include file cleanup for ppc64, rx buffer size |
| 58 | * increased to 1628 bytes. |
| 59 | * 0.17: 16 Nov 2003: undo rx buffer size increase. Substract 1 from |
| 60 | * the tx length. |
| 61 | * 0.18: 17 Nov 2003: fix oops due to late initialization of dev_stats |
| 62 | * 0.19: 29 Nov 2003: Handle RxNoBuf, detect & handle invalid mac |
| 63 | * addresses, really stop rx if already running |
| 64 | * in nv_start_rx, clean up a bit. |
| 65 | * 0.20: 07 Dec 2003: alloc fixes |
| 66 | * 0.21: 12 Jan 2004: additional alloc fix, nic polling fix. |
| 67 | * 0.22: 19 Jan 2004: reprogram timer to a sane rate, avoid lockup |
| 68 | * on close. |
| 69 | * 0.23: 26 Jan 2004: various small cleanups |
| 70 | * 0.24: 27 Feb 2004: make driver even less anonymous in backtraces |
| 71 | * 0.25: 09 Mar 2004: wol support |
| 72 | * 0.26: 03 Jun 2004: netdriver specific annotation, sparse-related fixes |
| 73 | * 0.27: 19 Jun 2004: Gigabit support, new descriptor rings, |
| 74 | * added CK804/MCP04 device IDs, code fixes |
| 75 | * for registers, link status and other minor fixes. |
| 76 | * 0.28: 21 Jun 2004: Big cleanup, making driver mostly endian safe |
| 77 | * 0.29: 31 Aug 2004: Add backup timer for link change notification. |
| 78 | * 0.30: 25 Sep 2004: rx checksum support for nf 250 Gb. Add rx reset |
| 79 | * into nv_close, otherwise reenabling for wol can |
| 80 | * cause DMA to kfree'd memory. |
| 81 | * 0.31: 14 Nov 2004: ethtool support for getting/setting link |
Ayaz Abdulla | 4ea7f29 | 2005-11-11 08:29:59 -0500 | [diff] [blame] | 82 | * capabilities. |
Manfred Spraul | 22c6d14 | 2005-04-19 21:17:09 +0200 | [diff] [blame] | 83 | * 0.32: 16 Apr 2005: RX_ERROR4 handling added. |
Manfred Spraul | 8f767fc | 2005-06-18 16:27:19 +0200 | [diff] [blame] | 84 | * 0.33: 16 May 2005: Support for MCP51 added. |
| 85 | * 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] | 86 | * 0.35: 26 Jun 2005: Support for MCP55 added. |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 87 | * 0.36: 28 Jun 2005: Add jumbo frame support. |
| 88 | * 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] | 89 | * 0.38: 16 Jul 2005: tx irq rewrite: Use global flags instead of |
| 90 | * per-packet flags. |
Ayaz Abdulla | 4ea7f29 | 2005-11-11 08:29:59 -0500 | [diff] [blame] | 91 | * 0.39: 18 Jul 2005: Add 64bit descriptor support. |
| 92 | * 0.40: 19 Jul 2005: Add support for mac address change. |
| 93 | * 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] | 94 | * of nv_remove |
Ayaz Abdulla | 4ea7f29 | 2005-11-11 08:29:59 -0500 | [diff] [blame] | 95 | * 0.42: 06 Aug 2005: Fix lack of link speed initialization |
Manfred Spraul | 1b1b3c9 | 2005-08-06 23:47:55 +0200 | [diff] [blame] | 96 | * in the second (and later) nv_open call |
Ayaz Abdulla | 4ea7f29 | 2005-11-11 08:29:59 -0500 | [diff] [blame] | 97 | * 0.43: 10 Aug 2005: Add support for tx checksum. |
| 98 | * 0.44: 20 Aug 2005: Add support for scatter gather and segmentation. |
| 99 | * 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] | 100 | * 0.46: 20 Oct 2005: Add irq optimization modes. |
Ayaz Abdulla | 7a33e45 | 2005-11-11 08:31:11 -0500 | [diff] [blame] | 101 | * 0.47: 26 Oct 2005: Add phyaddr 0 in phy scan. |
Manfred Spraul | 1836098 | 2005-12-24 14:19:24 +0100 | [diff] [blame] | 102 | * 0.48: 24 Dec 2005: Disable TSO, bugfix for pci_map_single |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 103 | * 0.49: 10 Dec 2005: Fix tso for large buffers. |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 104 | * 0.50: 20 Jan 2006: Add 8021pq tagging support. |
Ayaz Abdulla | 0832b25 | 2006-02-04 13:13:26 -0500 | [diff] [blame] | 105 | * 0.51: 20 Jan 2006: Add 64bit consistent memory allocation for rings. |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 106 | * 0.52: 20 Jan 2006: Add MSI/MSIX support. |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 107 | * 0.53: 19 Mar 2006: Fix init from low power mode and add hw reset. |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 108 | * 0.54: 21 Mar 2006: Fix spin locks for multi irqs and cleanup. |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 109 | * 0.55: 22 Mar 2006: Add flow control (pause frame). |
Ayaz Abdulla | ebe611a | 2006-06-10 22:48:24 -0400 | [diff] [blame] | 110 | * 0.56: 22 Mar 2006: Additional ethtool config and moduleparam support. |
Ayaz Abdulla | 5070d34 | 2006-07-31 12:05:01 -0400 | [diff] [blame] | 111 | * 0.57: 14 May 2006: Mac address set in probe/remove and order corrections. |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 112 | * 0.58: 30 Oct 2006: Added support for sideband management unit. |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 113 | * 0.59: 30 Oct 2006: Added support for recoverable error. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | * |
| 115 | * Known bugs: |
| 116 | * We suspect that on some hardware no TX done interrupts are generated. |
| 117 | * This means recovery from netif_stop_queue only happens if the hw timer |
| 118 | * interrupt fires (100 times/second, configurable with NVREG_POLL_DEFAULT) |
| 119 | * and the timer is active in the IRQMask, or if a rx packet arrives by chance. |
| 120 | * If your hardware reliably generates tx done interrupts, then you can remove |
| 121 | * DEV_NEED_TIMERIRQ from the driver_data flags. |
| 122 | * DEV_NEED_TIMERIRQ will not harm you on sane hardware, only generating a few |
| 123 | * superfluous timer interrupts from the nic. |
| 124 | */ |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 125 | #ifdef CONFIG_FORCEDETH_NAPI |
| 126 | #define DRIVERNAPI "-NAPI" |
| 127 | #else |
| 128 | #define DRIVERNAPI |
| 129 | #endif |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 130 | #define FORCEDETH_VERSION "0.59" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | #define DRV_NAME "forcedeth" |
| 132 | |
| 133 | #include <linux/module.h> |
| 134 | #include <linux/types.h> |
| 135 | #include <linux/pci.h> |
| 136 | #include <linux/interrupt.h> |
| 137 | #include <linux/netdevice.h> |
| 138 | #include <linux/etherdevice.h> |
| 139 | #include <linux/delay.h> |
| 140 | #include <linux/spinlock.h> |
| 141 | #include <linux/ethtool.h> |
| 142 | #include <linux/timer.h> |
| 143 | #include <linux/skbuff.h> |
| 144 | #include <linux/mii.h> |
| 145 | #include <linux/random.h> |
| 146 | #include <linux/init.h> |
Manfred Spraul | 22c6d14 | 2005-04-19 21:17:09 +0200 | [diff] [blame] | 147 | #include <linux/if_vlan.h> |
Matthias Gehre | 910638a | 2006-03-28 01:56:48 -0800 | [diff] [blame] | 148 | #include <linux/dma-mapping.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | #include <asm/irq.h> |
| 151 | #include <asm/io.h> |
| 152 | #include <asm/uaccess.h> |
| 153 | #include <asm/system.h> |
| 154 | |
| 155 | #if 0 |
| 156 | #define dprintk printk |
| 157 | #else |
| 158 | #define dprintk(x...) do { } while (0) |
| 159 | #endif |
| 160 | |
| 161 | |
| 162 | /* |
| 163 | * Hardware access: |
| 164 | */ |
| 165 | |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 166 | #define DEV_NEED_TIMERIRQ 0x0001 /* set the timer irq flag in the irq mask */ |
| 167 | #define DEV_NEED_LINKTIMER 0x0002 /* poll link settings. Relies on the timer irq */ |
| 168 | #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] | 169 | #define DEV_HAS_HIGH_DMA 0x0008 /* device supports 64bit dma */ |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 170 | #define DEV_HAS_CHECKSUM 0x0010 /* device supports tx and rx checksum offloads */ |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 171 | #define DEV_HAS_VLAN 0x0020 /* device supports vlan tagging and striping */ |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 172 | #define DEV_HAS_MSI 0x0040 /* device supports MSI */ |
| 173 | #define DEV_HAS_MSI_X 0x0080 /* device supports MSI-X */ |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 174 | #define DEV_HAS_POWER_CNTRL 0x0100 /* device supports power savings */ |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 175 | #define DEV_HAS_PAUSEFRAME_TX 0x0200 /* device supports tx pause frames */ |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 176 | #define DEV_HAS_STATISTICS 0x0400 /* device supports hw statistics */ |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 177 | #define DEV_HAS_TEST_EXTENDED 0x0800 /* device supports extended diagnostic test */ |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 178 | #define DEV_HAS_MGMT_UNIT 0x1000 /* device supports management unit */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | |
| 180 | enum { |
| 181 | NvRegIrqStatus = 0x000, |
| 182 | #define NVREG_IRQSTAT_MIIEVENT 0x040 |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 183 | #define NVREG_IRQSTAT_MASK 0x81ff |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | NvRegIrqMask = 0x004, |
| 185 | #define NVREG_IRQ_RX_ERROR 0x0001 |
| 186 | #define NVREG_IRQ_RX 0x0002 |
| 187 | #define NVREG_IRQ_RX_NOBUF 0x0004 |
| 188 | #define NVREG_IRQ_TX_ERR 0x0008 |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 189 | #define NVREG_IRQ_TX_OK 0x0010 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | #define NVREG_IRQ_TIMER 0x0020 |
| 191 | #define NVREG_IRQ_LINK 0x0040 |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 192 | #define NVREG_IRQ_RX_FORCED 0x0080 |
| 193 | #define NVREG_IRQ_TX_FORCED 0x0100 |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 194 | #define NVREG_IRQ_RECOVER_ERROR 0x8000 |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 195 | #define NVREG_IRQMASK_THROUGHPUT 0x00df |
| 196 | #define NVREG_IRQMASK_CPU 0x0040 |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 197 | #define NVREG_IRQ_TX_ALL (NVREG_IRQ_TX_ERR|NVREG_IRQ_TX_OK|NVREG_IRQ_TX_FORCED) |
| 198 | #define NVREG_IRQ_RX_ALL (NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_RX_FORCED) |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 199 | #define NVREG_IRQ_OTHER (NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_RECOVER_ERROR) |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 200 | |
| 201 | #define NVREG_IRQ_UNKNOWN (~(NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_TX_ERR| \ |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 202 | NVREG_IRQ_TX_OK|NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_RX_FORCED| \ |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 203 | NVREG_IRQ_TX_FORCED|NVREG_IRQ_RECOVER_ERROR)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | |
| 205 | NvRegUnknownSetupReg6 = 0x008, |
| 206 | #define NVREG_UNKSETUP6_VAL 3 |
| 207 | |
| 208 | /* |
| 209 | * NVREG_POLL_DEFAULT is the interval length of the timer source on the nic |
| 210 | * NVREG_POLL_DEFAULT=97 would result in an interval length of 1 ms |
| 211 | */ |
| 212 | NvRegPollingInterval = 0x00c, |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 213 | #define NVREG_POLL_DEFAULT_THROUGHPUT 970 |
| 214 | #define NVREG_POLL_DEFAULT_CPU 13 |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 215 | NvRegMSIMap0 = 0x020, |
| 216 | NvRegMSIMap1 = 0x024, |
| 217 | NvRegMSIIrqMask = 0x030, |
| 218 | #define NVREG_MSI_VECTOR_0_ENABLED 0x01 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | NvRegMisc1 = 0x080, |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 220 | #define NVREG_MISC1_PAUSE_TX 0x01 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | #define NVREG_MISC1_HD 0x02 |
| 222 | #define NVREG_MISC1_FORCE 0x3b0f3c |
| 223 | |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 224 | NvRegMacReset = 0x3c, |
| 225 | #define NVREG_MAC_RESET_ASSERT 0x0F3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | NvRegTransmitterControl = 0x084, |
| 227 | #define NVREG_XMITCTL_START 0x01 |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 228 | #define NVREG_XMITCTL_MGMT_ST 0x40000000 |
| 229 | #define NVREG_XMITCTL_SYNC_MASK 0x000f0000 |
| 230 | #define NVREG_XMITCTL_SYNC_NOT_READY 0x0 |
| 231 | #define NVREG_XMITCTL_SYNC_PHY_INIT 0x00040000 |
| 232 | #define NVREG_XMITCTL_MGMT_SEMA_MASK 0x00000f00 |
| 233 | #define NVREG_XMITCTL_MGMT_SEMA_FREE 0x0 |
| 234 | #define NVREG_XMITCTL_HOST_SEMA_MASK 0x0000f000 |
| 235 | #define NVREG_XMITCTL_HOST_SEMA_ACQ 0x0000f000 |
| 236 | #define NVREG_XMITCTL_HOST_LOADED 0x00004000 |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 237 | #define NVREG_XMITCTL_TX_PATH_EN 0x01000000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | NvRegTransmitterStatus = 0x088, |
| 239 | #define NVREG_XMITSTAT_BUSY 0x01 |
| 240 | |
| 241 | NvRegPacketFilterFlags = 0x8c, |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 242 | #define NVREG_PFF_PAUSE_RX 0x08 |
| 243 | #define NVREG_PFF_ALWAYS 0x7F0000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | #define NVREG_PFF_PROMISC 0x80 |
| 245 | #define NVREG_PFF_MYADDR 0x20 |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 246 | #define NVREG_PFF_LOOPBACK 0x10 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | |
| 248 | NvRegOffloadConfig = 0x90, |
| 249 | #define NVREG_OFFLOAD_HOMEPHY 0x601 |
| 250 | #define NVREG_OFFLOAD_NORMAL RX_NIC_BUFSIZE |
| 251 | NvRegReceiverControl = 0x094, |
| 252 | #define NVREG_RCVCTL_START 0x01 |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 253 | #define NVREG_RCVCTL_RX_PATH_EN 0x01000000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | NvRegReceiverStatus = 0x98, |
| 255 | #define NVREG_RCVSTAT_BUSY 0x01 |
| 256 | |
| 257 | NvRegRandomSeed = 0x9c, |
| 258 | #define NVREG_RNDSEED_MASK 0x00ff |
| 259 | #define NVREG_RNDSEED_FORCE 0x7f00 |
| 260 | #define NVREG_RNDSEED_FORCE2 0x2d00 |
| 261 | #define NVREG_RNDSEED_FORCE3 0x7400 |
| 262 | |
Ayaz Abdulla | 9744e21 | 2006-07-06 16:45:58 -0400 | [diff] [blame] | 263 | NvRegTxDeferral = 0xA0, |
| 264 | #define NVREG_TX_DEFERRAL_DEFAULT 0x15050f |
| 265 | #define NVREG_TX_DEFERRAL_RGMII_10_100 0x16070f |
| 266 | #define NVREG_TX_DEFERRAL_RGMII_1000 0x14050f |
| 267 | NvRegRxDeferral = 0xA4, |
| 268 | #define NVREG_RX_DEFERRAL_DEFAULT 0x16 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | NvRegMacAddrA = 0xA8, |
| 270 | NvRegMacAddrB = 0xAC, |
| 271 | NvRegMulticastAddrA = 0xB0, |
| 272 | #define NVREG_MCASTADDRA_FORCE 0x01 |
| 273 | NvRegMulticastAddrB = 0xB4, |
| 274 | NvRegMulticastMaskA = 0xB8, |
| 275 | NvRegMulticastMaskB = 0xBC, |
| 276 | |
| 277 | NvRegPhyInterface = 0xC0, |
| 278 | #define PHY_RGMII 0x10000000 |
| 279 | |
| 280 | NvRegTxRingPhysAddr = 0x100, |
| 281 | NvRegRxRingPhysAddr = 0x104, |
| 282 | NvRegRingSizes = 0x108, |
| 283 | #define NVREG_RINGSZ_TXSHIFT 0 |
| 284 | #define NVREG_RINGSZ_RXSHIFT 16 |
Ayaz Abdulla | 5070d34 | 2006-07-31 12:05:01 -0400 | [diff] [blame] | 285 | NvRegTransmitPoll = 0x10c, |
| 286 | #define NVREG_TRANSMITPOLL_MAC_ADDR_REV 0x00008000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | NvRegLinkSpeed = 0x110, |
| 288 | #define NVREG_LINKSPEED_FORCE 0x10000 |
| 289 | #define NVREG_LINKSPEED_10 1000 |
| 290 | #define NVREG_LINKSPEED_100 100 |
| 291 | #define NVREG_LINKSPEED_1000 50 |
| 292 | #define NVREG_LINKSPEED_MASK (0xFFF) |
| 293 | NvRegUnknownSetupReg5 = 0x130, |
| 294 | #define NVREG_UNKSETUP5_BIT31 (1<<31) |
Ayaz Abdulla | 95d161c | 2006-07-06 16:46:25 -0400 | [diff] [blame] | 295 | NvRegTxWatermark = 0x13c, |
| 296 | #define NVREG_TX_WM_DESC1_DEFAULT 0x0200010 |
| 297 | #define NVREG_TX_WM_DESC2_3_DEFAULT 0x1e08000 |
| 298 | #define NVREG_TX_WM_DESC2_3_1000 0xfe08000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | NvRegTxRxControl = 0x144, |
| 300 | #define NVREG_TXRXCTL_KICK 0x0001 |
| 301 | #define NVREG_TXRXCTL_BIT1 0x0002 |
| 302 | #define NVREG_TXRXCTL_BIT2 0x0004 |
| 303 | #define NVREG_TXRXCTL_IDLE 0x0008 |
| 304 | #define NVREG_TXRXCTL_RESET 0x0010 |
| 305 | #define NVREG_TXRXCTL_RXCHECK 0x0400 |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 306 | #define NVREG_TXRXCTL_DESC_1 0 |
Ayaz Abdulla | d2f7841 | 2007-01-09 13:30:02 -0500 | [diff] [blame] | 307 | #define NVREG_TXRXCTL_DESC_2 0x002100 |
| 308 | #define NVREG_TXRXCTL_DESC_3 0xc02200 |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 309 | #define NVREG_TXRXCTL_VLANSTRIP 0x00040 |
| 310 | #define NVREG_TXRXCTL_VLANINS 0x00080 |
Ayaz Abdulla | 0832b25 | 2006-02-04 13:13:26 -0500 | [diff] [blame] | 311 | NvRegTxRingPhysAddrHigh = 0x148, |
| 312 | NvRegRxRingPhysAddrHigh = 0x14C, |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 313 | NvRegTxPauseFrame = 0x170, |
| 314 | #define NVREG_TX_PAUSEFRAME_DISABLE 0x1ff0080 |
| 315 | #define NVREG_TX_PAUSEFRAME_ENABLE 0x0c00030 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | NvRegMIIStatus = 0x180, |
| 317 | #define NVREG_MIISTAT_ERROR 0x0001 |
| 318 | #define NVREG_MIISTAT_LINKCHANGE 0x0008 |
| 319 | #define NVREG_MIISTAT_MASK 0x000f |
| 320 | #define NVREG_MIISTAT_MASK2 0x000f |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 321 | NvRegMIIMask = 0x184, |
| 322 | #define NVREG_MII_LINKCHANGE 0x0008 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | |
| 324 | NvRegAdapterControl = 0x188, |
| 325 | #define NVREG_ADAPTCTL_START 0x02 |
| 326 | #define NVREG_ADAPTCTL_LINKUP 0x04 |
| 327 | #define NVREG_ADAPTCTL_PHYVALID 0x40000 |
| 328 | #define NVREG_ADAPTCTL_RUNNING 0x100000 |
| 329 | #define NVREG_ADAPTCTL_PHYSHIFT 24 |
| 330 | NvRegMIISpeed = 0x18c, |
| 331 | #define NVREG_MIISPEED_BIT8 (1<<8) |
| 332 | #define NVREG_MIIDELAY 5 |
| 333 | NvRegMIIControl = 0x190, |
| 334 | #define NVREG_MIICTL_INUSE 0x08000 |
| 335 | #define NVREG_MIICTL_WRITE 0x00400 |
| 336 | #define NVREG_MIICTL_ADDRSHIFT 5 |
| 337 | NvRegMIIData = 0x194, |
| 338 | NvRegWakeUpFlags = 0x200, |
| 339 | #define NVREG_WAKEUPFLAGS_VAL 0x7770 |
| 340 | #define NVREG_WAKEUPFLAGS_BUSYSHIFT 24 |
| 341 | #define NVREG_WAKEUPFLAGS_ENABLESHIFT 16 |
| 342 | #define NVREG_WAKEUPFLAGS_D3SHIFT 12 |
| 343 | #define NVREG_WAKEUPFLAGS_D2SHIFT 8 |
| 344 | #define NVREG_WAKEUPFLAGS_D1SHIFT 4 |
| 345 | #define NVREG_WAKEUPFLAGS_D0SHIFT 0 |
| 346 | #define NVREG_WAKEUPFLAGS_ACCEPT_MAGPAT 0x01 |
| 347 | #define NVREG_WAKEUPFLAGS_ACCEPT_WAKEUPPAT 0x02 |
| 348 | #define NVREG_WAKEUPFLAGS_ACCEPT_LINKCHANGE 0x04 |
| 349 | #define NVREG_WAKEUPFLAGS_ENABLE 0x1111 |
| 350 | |
| 351 | NvRegPatternCRC = 0x204, |
| 352 | NvRegPatternMask = 0x208, |
| 353 | NvRegPowerCap = 0x268, |
| 354 | #define NVREG_POWERCAP_D3SUPP (1<<30) |
| 355 | #define NVREG_POWERCAP_D2SUPP (1<<26) |
| 356 | #define NVREG_POWERCAP_D1SUPP (1<<25) |
| 357 | NvRegPowerState = 0x26c, |
| 358 | #define NVREG_POWERSTATE_POWEREDUP 0x8000 |
| 359 | #define NVREG_POWERSTATE_VALID 0x0100 |
| 360 | #define NVREG_POWERSTATE_MASK 0x0003 |
| 361 | #define NVREG_POWERSTATE_D0 0x0000 |
| 362 | #define NVREG_POWERSTATE_D1 0x0001 |
| 363 | #define NVREG_POWERSTATE_D2 0x0002 |
| 364 | #define NVREG_POWERSTATE_D3 0x0003 |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 365 | NvRegTxCnt = 0x280, |
| 366 | NvRegTxZeroReXmt = 0x284, |
| 367 | NvRegTxOneReXmt = 0x288, |
| 368 | NvRegTxManyReXmt = 0x28c, |
| 369 | NvRegTxLateCol = 0x290, |
| 370 | NvRegTxUnderflow = 0x294, |
| 371 | NvRegTxLossCarrier = 0x298, |
| 372 | NvRegTxExcessDef = 0x29c, |
| 373 | NvRegTxRetryErr = 0x2a0, |
| 374 | NvRegRxFrameErr = 0x2a4, |
| 375 | NvRegRxExtraByte = 0x2a8, |
| 376 | NvRegRxLateCol = 0x2ac, |
| 377 | NvRegRxRunt = 0x2b0, |
| 378 | NvRegRxFrameTooLong = 0x2b4, |
| 379 | NvRegRxOverflow = 0x2b8, |
| 380 | NvRegRxFCSErr = 0x2bc, |
| 381 | NvRegRxFrameAlignErr = 0x2c0, |
| 382 | NvRegRxLenErr = 0x2c4, |
| 383 | NvRegRxUnicast = 0x2c8, |
| 384 | NvRegRxMulticast = 0x2cc, |
| 385 | NvRegRxBroadcast = 0x2d0, |
| 386 | NvRegTxDef = 0x2d4, |
| 387 | NvRegTxFrame = 0x2d8, |
| 388 | NvRegRxCnt = 0x2dc, |
| 389 | NvRegTxPause = 0x2e0, |
| 390 | NvRegRxPause = 0x2e4, |
| 391 | NvRegRxDropFrame = 0x2e8, |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 392 | NvRegVlanControl = 0x300, |
| 393 | #define NVREG_VLANCONTROL_ENABLE 0x2000 |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 394 | NvRegMSIXMap0 = 0x3e0, |
| 395 | NvRegMSIXMap1 = 0x3e4, |
| 396 | NvRegMSIXIrqStatus = 0x3f0, |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 397 | |
| 398 | NvRegPowerState2 = 0x600, |
| 399 | #define NVREG_POWERSTATE2_POWERUP_MASK 0x0F11 |
| 400 | #define NVREG_POWERSTATE2_POWERUP_REV_A3 0x0001 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | }; |
| 402 | |
| 403 | /* Big endian: should work, but is untested */ |
| 404 | struct ring_desc { |
Stephen Hemminger | a8bed49 | 2006-07-27 18:50:09 -0700 | [diff] [blame] | 405 | __le32 buf; |
| 406 | __le32 flaglen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | }; |
| 408 | |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 409 | struct ring_desc_ex { |
Stephen Hemminger | a8bed49 | 2006-07-27 18:50:09 -0700 | [diff] [blame] | 410 | __le32 bufhigh; |
| 411 | __le32 buflow; |
| 412 | __le32 txvlan; |
| 413 | __le32 flaglen; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 414 | }; |
| 415 | |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 416 | union ring_type { |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 417 | struct ring_desc* orig; |
| 418 | struct ring_desc_ex* ex; |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 419 | }; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | #define FLAG_MASK_V1 0xffff0000 |
| 422 | #define FLAG_MASK_V2 0xffffc000 |
| 423 | #define LEN_MASK_V1 (0xffffffff ^ FLAG_MASK_V1) |
| 424 | #define LEN_MASK_V2 (0xffffffff ^ FLAG_MASK_V2) |
| 425 | |
| 426 | #define NV_TX_LASTPACKET (1<<16) |
| 427 | #define NV_TX_RETRYERROR (1<<19) |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 428 | #define NV_TX_FORCED_INTERRUPT (1<<24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | #define NV_TX_DEFERRED (1<<26) |
| 430 | #define NV_TX_CARRIERLOST (1<<27) |
| 431 | #define NV_TX_LATECOLLISION (1<<28) |
| 432 | #define NV_TX_UNDERFLOW (1<<29) |
| 433 | #define NV_TX_ERROR (1<<30) |
| 434 | #define NV_TX_VALID (1<<31) |
| 435 | |
| 436 | #define NV_TX2_LASTPACKET (1<<29) |
| 437 | #define NV_TX2_RETRYERROR (1<<18) |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 438 | #define NV_TX2_FORCED_INTERRUPT (1<<30) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | #define NV_TX2_DEFERRED (1<<25) |
| 440 | #define NV_TX2_CARRIERLOST (1<<26) |
| 441 | #define NV_TX2_LATECOLLISION (1<<27) |
| 442 | #define NV_TX2_UNDERFLOW (1<<28) |
| 443 | /* error and valid are the same for both */ |
| 444 | #define NV_TX2_ERROR (1<<30) |
| 445 | #define NV_TX2_VALID (1<<31) |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 446 | #define NV_TX2_TSO (1<<28) |
| 447 | #define NV_TX2_TSO_SHIFT 14 |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 448 | #define NV_TX2_TSO_MAX_SHIFT 14 |
| 449 | #define NV_TX2_TSO_MAX_SIZE (1<<NV_TX2_TSO_MAX_SHIFT) |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 450 | #define NV_TX2_CHECKSUM_L3 (1<<27) |
| 451 | #define NV_TX2_CHECKSUM_L4 (1<<26) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 453 | #define NV_TX3_VLAN_TAG_PRESENT (1<<18) |
| 454 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | #define NV_RX_DESCRIPTORVALID (1<<16) |
| 456 | #define NV_RX_MISSEDFRAME (1<<17) |
| 457 | #define NV_RX_SUBSTRACT1 (1<<18) |
| 458 | #define NV_RX_ERROR1 (1<<23) |
| 459 | #define NV_RX_ERROR2 (1<<24) |
| 460 | #define NV_RX_ERROR3 (1<<25) |
| 461 | #define NV_RX_ERROR4 (1<<26) |
| 462 | #define NV_RX_CRCERR (1<<27) |
| 463 | #define NV_RX_OVERFLOW (1<<28) |
| 464 | #define NV_RX_FRAMINGERR (1<<29) |
| 465 | #define NV_RX_ERROR (1<<30) |
| 466 | #define NV_RX_AVAIL (1<<31) |
| 467 | |
| 468 | #define NV_RX2_CHECKSUMMASK (0x1C000000) |
| 469 | #define NV_RX2_CHECKSUMOK1 (0x10000000) |
| 470 | #define NV_RX2_CHECKSUMOK2 (0x14000000) |
| 471 | #define NV_RX2_CHECKSUMOK3 (0x18000000) |
| 472 | #define NV_RX2_DESCRIPTORVALID (1<<29) |
| 473 | #define NV_RX2_SUBSTRACT1 (1<<25) |
| 474 | #define NV_RX2_ERROR1 (1<<18) |
| 475 | #define NV_RX2_ERROR2 (1<<19) |
| 476 | #define NV_RX2_ERROR3 (1<<20) |
| 477 | #define NV_RX2_ERROR4 (1<<21) |
| 478 | #define NV_RX2_CRCERR (1<<22) |
| 479 | #define NV_RX2_OVERFLOW (1<<23) |
| 480 | #define NV_RX2_FRAMINGERR (1<<24) |
| 481 | /* error and avail are the same for both */ |
| 482 | #define NV_RX2_ERROR (1<<30) |
| 483 | #define NV_RX2_AVAIL (1<<31) |
| 484 | |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 485 | #define NV_RX3_VLAN_TAG_PRESENT (1<<16) |
| 486 | #define NV_RX3_VLAN_TAG_MASK (0x0000FFFF) |
| 487 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | /* Miscelaneous hardware related defines: */ |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 489 | #define NV_PCI_REGSZ_VER1 0x270 |
| 490 | #define NV_PCI_REGSZ_VER2 0x604 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
| 492 | /* various timeout delays: all in usec */ |
| 493 | #define NV_TXRX_RESET_DELAY 4 |
| 494 | #define NV_TXSTOP_DELAY1 10 |
| 495 | #define NV_TXSTOP_DELAY1MAX 500000 |
| 496 | #define NV_TXSTOP_DELAY2 100 |
| 497 | #define NV_RXSTOP_DELAY1 10 |
| 498 | #define NV_RXSTOP_DELAY1MAX 500000 |
| 499 | #define NV_RXSTOP_DELAY2 100 |
| 500 | #define NV_SETUP5_DELAY 5 |
| 501 | #define NV_SETUP5_DELAYMAX 50000 |
| 502 | #define NV_POWERUP_DELAY 5 |
| 503 | #define NV_POWERUP_DELAYMAX 5000 |
| 504 | #define NV_MIIBUSY_DELAY 50 |
| 505 | #define NV_MIIPHY_DELAY 10 |
| 506 | #define NV_MIIPHY_DELAYMAX 10000 |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 507 | #define NV_MAC_RESET_DELAY 64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
| 509 | #define NV_WAKEUPPATTERNS 5 |
| 510 | #define NV_WAKEUPMASKENTRIES 4 |
| 511 | |
| 512 | /* General driver defaults */ |
| 513 | #define NV_WATCHDOG_TIMEO (5*HZ) |
| 514 | |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 515 | #define RX_RING_DEFAULT 128 |
| 516 | #define TX_RING_DEFAULT 256 |
| 517 | #define RX_RING_MIN 128 |
| 518 | #define TX_RING_MIN 64 |
| 519 | #define RING_MAX_DESC_VER_1 1024 |
| 520 | #define RING_MAX_DESC_VER_2_3 16384 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | |
| 522 | /* rx/tx mac addr + type + vlan + align + slack*/ |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 523 | #define NV_RX_HEADERS (64) |
| 524 | /* even more slack. */ |
| 525 | #define NV_RX_ALLOC_PAD (64) |
| 526 | |
| 527 | /* maximum mtu size */ |
| 528 | #define NV_PKTLIMIT_1 ETH_DATA_LEN /* hard limit not known */ |
| 529 | #define NV_PKTLIMIT_2 9100 /* Actual limit according to NVidia: 9202 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
| 531 | #define OOM_REFILL (1+HZ/20) |
| 532 | #define POLL_WAIT (1+HZ/100) |
| 533 | #define LINK_TIMEOUT (3*HZ) |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 534 | #define STATS_INTERVAL (10*HZ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 536 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | * desc_ver values: |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 538 | * The nic supports three different descriptor types: |
| 539 | * - DESC_VER_1: Original |
| 540 | * - DESC_VER_2: support for jumbo frames. |
| 541 | * - DESC_VER_3: 64-bit format. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | */ |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 543 | #define DESC_VER_1 1 |
| 544 | #define DESC_VER_2 2 |
| 545 | #define DESC_VER_3 3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | |
| 547 | /* PHY defines */ |
| 548 | #define PHY_OUI_MARVELL 0x5043 |
| 549 | #define PHY_OUI_CICADA 0x03f1 |
| 550 | #define PHYID1_OUI_MASK 0x03ff |
| 551 | #define PHYID1_OUI_SHFT 6 |
| 552 | #define PHYID2_OUI_MASK 0xfc00 |
| 553 | #define PHYID2_OUI_SHFT 10 |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 554 | #define PHYID2_MODEL_MASK 0x03f0 |
| 555 | #define PHY_MODEL_MARVELL_E3016 0x220 |
| 556 | #define PHY_MARVELL_E3016_INITMASK 0x0300 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | #define PHY_INIT1 0x0f000 |
| 558 | #define PHY_INIT2 0x0e00 |
| 559 | #define PHY_INIT3 0x01000 |
| 560 | #define PHY_INIT4 0x0200 |
| 561 | #define PHY_INIT5 0x0004 |
| 562 | #define PHY_INIT6 0x02000 |
| 563 | #define PHY_GIGABIT 0x0100 |
| 564 | |
| 565 | #define PHY_TIMEOUT 0x1 |
| 566 | #define PHY_ERROR 0x2 |
| 567 | |
| 568 | #define PHY_100 0x1 |
| 569 | #define PHY_1000 0x2 |
| 570 | #define PHY_HALF 0x100 |
| 571 | |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 572 | #define NV_PAUSEFRAME_RX_CAPABLE 0x0001 |
| 573 | #define NV_PAUSEFRAME_TX_CAPABLE 0x0002 |
| 574 | #define NV_PAUSEFRAME_RX_ENABLE 0x0004 |
| 575 | #define NV_PAUSEFRAME_TX_ENABLE 0x0008 |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 576 | #define NV_PAUSEFRAME_RX_REQ 0x0010 |
| 577 | #define NV_PAUSEFRAME_TX_REQ 0x0020 |
| 578 | #define NV_PAUSEFRAME_AUTONEG 0x0040 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 580 | /* MSI/MSI-X defines */ |
| 581 | #define NV_MSI_X_MAX_VECTORS 8 |
| 582 | #define NV_MSI_X_VECTORS_MASK 0x000f |
| 583 | #define NV_MSI_CAPABLE 0x0010 |
| 584 | #define NV_MSI_X_CAPABLE 0x0020 |
| 585 | #define NV_MSI_ENABLED 0x0040 |
| 586 | #define NV_MSI_X_ENABLED 0x0080 |
| 587 | |
| 588 | #define NV_MSI_X_VECTOR_ALL 0x0 |
| 589 | #define NV_MSI_X_VECTOR_RX 0x0 |
| 590 | #define NV_MSI_X_VECTOR_TX 0x1 |
| 591 | #define NV_MSI_X_VECTOR_OTHER 0x2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 | |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 593 | /* statistics */ |
| 594 | struct nv_ethtool_str { |
| 595 | char name[ETH_GSTRING_LEN]; |
| 596 | }; |
| 597 | |
| 598 | static const struct nv_ethtool_str nv_estats_str[] = { |
| 599 | { "tx_bytes" }, |
| 600 | { "tx_zero_rexmt" }, |
| 601 | { "tx_one_rexmt" }, |
| 602 | { "tx_many_rexmt" }, |
| 603 | { "tx_late_collision" }, |
| 604 | { "tx_fifo_errors" }, |
| 605 | { "tx_carrier_errors" }, |
| 606 | { "tx_excess_deferral" }, |
| 607 | { "tx_retry_error" }, |
| 608 | { "tx_deferral" }, |
| 609 | { "tx_packets" }, |
| 610 | { "tx_pause" }, |
| 611 | { "rx_frame_error" }, |
| 612 | { "rx_extra_byte" }, |
| 613 | { "rx_late_collision" }, |
| 614 | { "rx_runt" }, |
| 615 | { "rx_frame_too_long" }, |
| 616 | { "rx_over_errors" }, |
| 617 | { "rx_crc_errors" }, |
| 618 | { "rx_frame_align_error" }, |
| 619 | { "rx_length_error" }, |
| 620 | { "rx_unicast" }, |
| 621 | { "rx_multicast" }, |
| 622 | { "rx_broadcast" }, |
| 623 | { "rx_bytes" }, |
| 624 | { "rx_pause" }, |
| 625 | { "rx_drop_frame" }, |
| 626 | { "rx_packets" }, |
| 627 | { "rx_errors_total" } |
| 628 | }; |
| 629 | |
| 630 | struct nv_ethtool_stats { |
| 631 | u64 tx_bytes; |
| 632 | u64 tx_zero_rexmt; |
| 633 | u64 tx_one_rexmt; |
| 634 | u64 tx_many_rexmt; |
| 635 | u64 tx_late_collision; |
| 636 | u64 tx_fifo_errors; |
| 637 | u64 tx_carrier_errors; |
| 638 | u64 tx_excess_deferral; |
| 639 | u64 tx_retry_error; |
| 640 | u64 tx_deferral; |
| 641 | u64 tx_packets; |
| 642 | u64 tx_pause; |
| 643 | u64 rx_frame_error; |
| 644 | u64 rx_extra_byte; |
| 645 | u64 rx_late_collision; |
| 646 | u64 rx_runt; |
| 647 | u64 rx_frame_too_long; |
| 648 | u64 rx_over_errors; |
| 649 | u64 rx_crc_errors; |
| 650 | u64 rx_frame_align_error; |
| 651 | u64 rx_length_error; |
| 652 | u64 rx_unicast; |
| 653 | u64 rx_multicast; |
| 654 | u64 rx_broadcast; |
| 655 | u64 rx_bytes; |
| 656 | u64 rx_pause; |
| 657 | u64 rx_drop_frame; |
| 658 | u64 rx_packets; |
| 659 | u64 rx_errors_total; |
| 660 | }; |
| 661 | |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 662 | /* diagnostics */ |
| 663 | #define NV_TEST_COUNT_BASE 3 |
| 664 | #define NV_TEST_COUNT_EXTENDED 4 |
| 665 | |
| 666 | static const struct nv_ethtool_str nv_etests_str[] = { |
| 667 | { "link (online/offline)" }, |
| 668 | { "register (offline) " }, |
| 669 | { "interrupt (offline) " }, |
| 670 | { "loopback (offline) " } |
| 671 | }; |
| 672 | |
| 673 | struct register_test { |
Stephen Hemminger | a8bed49 | 2006-07-27 18:50:09 -0700 | [diff] [blame] | 674 | __le32 reg; |
| 675 | __le32 mask; |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 676 | }; |
| 677 | |
| 678 | static const struct register_test nv_registers_test[] = { |
| 679 | { NvRegUnknownSetupReg6, 0x01 }, |
| 680 | { NvRegMisc1, 0x03c }, |
| 681 | { NvRegOffloadConfig, 0x03ff }, |
| 682 | { NvRegMulticastAddrA, 0xffffffff }, |
Ayaz Abdulla | 95d161c | 2006-07-06 16:46:25 -0400 | [diff] [blame] | 683 | { NvRegTxWatermark, 0x0ff }, |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 684 | { NvRegWakeUpFlags, 0x07777 }, |
| 685 | { 0,0 } |
| 686 | }; |
| 687 | |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 688 | struct nv_skb_map { |
| 689 | struct sk_buff *skb; |
| 690 | dma_addr_t dma; |
| 691 | unsigned int dma_len; |
| 692 | }; |
| 693 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | /* |
| 695 | * SMP locking: |
| 696 | * All hardware access under dev->priv->lock, except the performance |
| 697 | * critical parts: |
| 698 | * - rx is (pseudo-) lockless: it relies on the single-threading provided |
| 699 | * by the arch code for interrupts. |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 700 | * - tx setup is lockless: it relies on netif_tx_lock. Actual submission |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 701 | * needs dev->priv->lock :-( |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 702 | * - set_multicast_list: preparation lockless, relies on netif_tx_lock. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | */ |
| 704 | |
| 705 | /* in dev: base, irq */ |
| 706 | struct fe_priv { |
| 707 | spinlock_t lock; |
| 708 | |
| 709 | /* General data: |
| 710 | * Locking: spin_lock(&np->lock); */ |
| 711 | struct net_device_stats stats; |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 712 | struct nv_ethtool_stats estats; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | int in_shutdown; |
| 714 | u32 linkspeed; |
| 715 | int duplex; |
| 716 | int autoneg; |
| 717 | int fixed_mode; |
| 718 | int phyaddr; |
| 719 | int wolenabled; |
| 720 | unsigned int phy_oui; |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 721 | unsigned int phy_model; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 722 | u16 gigabit; |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 723 | int intr_test; |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 724 | int recover_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | |
| 726 | /* General data: RO fields */ |
| 727 | dma_addr_t ring_addr; |
| 728 | struct pci_dev *pci_dev; |
| 729 | u32 orig_mac[2]; |
| 730 | u32 irqmask; |
| 731 | u32 desc_ver; |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 732 | u32 txrxctl_bits; |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 733 | u32 vlanctl_bits; |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 734 | u32 driver_data; |
| 735 | u32 register_size; |
Ayaz Abdulla | f2ad2d9 | 2006-08-24 17:35:41 -0400 | [diff] [blame] | 736 | int rx_csum; |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 737 | u32 mac_in_use; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 738 | |
| 739 | void __iomem *base; |
| 740 | |
| 741 | /* rx specific fields. |
| 742 | * Locking: Within irq hander or disable_irq+spin_lock(&np->lock); |
| 743 | */ |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 744 | union ring_type get_rx, put_rx, first_rx, last_rx; |
| 745 | struct nv_skb_map *get_rx_ctx, *put_rx_ctx; |
| 746 | struct nv_skb_map *first_rx_ctx, *last_rx_ctx; |
| 747 | struct nv_skb_map *rx_skb; |
| 748 | |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 749 | union ring_type rx_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 750 | unsigned int rx_buf_sz; |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 751 | unsigned int pkt_limit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 752 | struct timer_list oom_kick; |
| 753 | struct timer_list nic_poll; |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 754 | struct timer_list stats_poll; |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 755 | u32 nic_poll_irq; |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 756 | int rx_ring_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | |
| 758 | /* media detection workaround. |
| 759 | * Locking: Within irq hander or disable_irq+spin_lock(&np->lock); |
| 760 | */ |
| 761 | int need_linktimer; |
| 762 | unsigned long link_timeout; |
| 763 | /* |
| 764 | * tx specific fields. |
| 765 | */ |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 766 | union ring_type get_tx, put_tx, first_tx, last_tx; |
| 767 | struct nv_skb_map *get_tx_ctx, *put_tx_ctx; |
| 768 | struct nv_skb_map *first_tx_ctx, *last_tx_ctx; |
| 769 | struct nv_skb_map *tx_skb; |
| 770 | |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 771 | union ring_type tx_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | u32 tx_flags; |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 773 | int tx_ring_size; |
Ayaz Abdulla | aaa37d2 | 2007-01-21 18:10:42 -0500 | [diff] [blame] | 774 | int tx_stop; |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 775 | |
| 776 | /* vlan fields */ |
| 777 | struct vlan_group *vlangrp; |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 778 | |
| 779 | /* msi/msi-x fields */ |
| 780 | u32 msi_flags; |
| 781 | struct msix_entry msi_x_entry[NV_MSI_X_MAX_VECTORS]; |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 782 | |
| 783 | /* flow control */ |
| 784 | u32 pause_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 785 | }; |
| 786 | |
| 787 | /* |
| 788 | * Maximum number of loops until we assume that a bit in the irq mask |
| 789 | * is stuck. Overridable with module param. |
| 790 | */ |
| 791 | static int max_interrupt_work = 5; |
| 792 | |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 793 | /* |
| 794 | * Optimization can be either throuput mode or cpu mode |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 795 | * |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 796 | * Throughput Mode: Every tx and rx packet will generate an interrupt. |
| 797 | * CPU Mode: Interrupts are controlled by a timer. |
| 798 | */ |
Ayaz Abdulla | 69fe3fd | 2006-06-10 22:48:18 -0400 | [diff] [blame] | 799 | enum { |
| 800 | NV_OPTIMIZATION_MODE_THROUGHPUT, |
| 801 | NV_OPTIMIZATION_MODE_CPU |
| 802 | }; |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 803 | static int optimization_mode = NV_OPTIMIZATION_MODE_THROUGHPUT; |
| 804 | |
| 805 | /* |
| 806 | * Poll interval for timer irq |
| 807 | * |
| 808 | * This interval determines how frequent an interrupt is generated. |
| 809 | * The is value is determined by [(time_in_micro_secs * 100) / (2^10)] |
| 810 | * Min = 0, and Max = 65535 |
| 811 | */ |
| 812 | static int poll_interval = -1; |
| 813 | |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 814 | /* |
Ayaz Abdulla | 69fe3fd | 2006-06-10 22:48:18 -0400 | [diff] [blame] | 815 | * MSI interrupts |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 816 | */ |
Ayaz Abdulla | 69fe3fd | 2006-06-10 22:48:18 -0400 | [diff] [blame] | 817 | enum { |
| 818 | NV_MSI_INT_DISABLED, |
| 819 | NV_MSI_INT_ENABLED |
| 820 | }; |
| 821 | static int msi = NV_MSI_INT_ENABLED; |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 822 | |
| 823 | /* |
Ayaz Abdulla | 69fe3fd | 2006-06-10 22:48:18 -0400 | [diff] [blame] | 824 | * MSIX interrupts |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 825 | */ |
Ayaz Abdulla | 69fe3fd | 2006-06-10 22:48:18 -0400 | [diff] [blame] | 826 | enum { |
| 827 | NV_MSIX_INT_DISABLED, |
| 828 | NV_MSIX_INT_ENABLED |
| 829 | }; |
| 830 | static int msix = NV_MSIX_INT_ENABLED; |
| 831 | |
| 832 | /* |
| 833 | * DMA 64bit |
| 834 | */ |
| 835 | enum { |
| 836 | NV_DMA_64BIT_DISABLED, |
| 837 | NV_DMA_64BIT_ENABLED |
| 838 | }; |
| 839 | static int dma_64bit = NV_DMA_64BIT_ENABLED; |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 840 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 841 | static inline struct fe_priv *get_nvpriv(struct net_device *dev) |
| 842 | { |
| 843 | return netdev_priv(dev); |
| 844 | } |
| 845 | |
| 846 | static inline u8 __iomem *get_hwbase(struct net_device *dev) |
| 847 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 848 | return ((struct fe_priv *)netdev_priv(dev))->base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 849 | } |
| 850 | |
| 851 | static inline void pci_push(u8 __iomem *base) |
| 852 | { |
| 853 | /* force out pending posted writes */ |
| 854 | readl(base); |
| 855 | } |
| 856 | |
| 857 | static inline u32 nv_descr_getlength(struct ring_desc *prd, u32 v) |
| 858 | { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 859 | return le32_to_cpu(prd->flaglen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | & ((v == DESC_VER_1) ? LEN_MASK_V1 : LEN_MASK_V2); |
| 861 | } |
| 862 | |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 863 | static inline u32 nv_descr_getlength_ex(struct ring_desc_ex *prd, u32 v) |
| 864 | { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 865 | return le32_to_cpu(prd->flaglen) & LEN_MASK_V2; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 866 | } |
| 867 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 868 | static int reg_delay(struct net_device *dev, int offset, u32 mask, u32 target, |
| 869 | int delay, int delaymax, const char *msg) |
| 870 | { |
| 871 | u8 __iomem *base = get_hwbase(dev); |
| 872 | |
| 873 | pci_push(base); |
| 874 | do { |
| 875 | udelay(delay); |
| 876 | delaymax -= delay; |
| 877 | if (delaymax < 0) { |
| 878 | if (msg) |
| 879 | printk(msg); |
| 880 | return 1; |
| 881 | } |
| 882 | } while ((readl(base + offset) & mask) != target); |
| 883 | return 0; |
| 884 | } |
| 885 | |
Ayaz Abdulla | 0832b25 | 2006-02-04 13:13:26 -0500 | [diff] [blame] | 886 | #define NV_SETUP_RX_RING 0x01 |
| 887 | #define NV_SETUP_TX_RING 0x02 |
| 888 | |
| 889 | static void setup_hw_rings(struct net_device *dev, int rxtx_flags) |
| 890 | { |
| 891 | struct fe_priv *np = get_nvpriv(dev); |
| 892 | u8 __iomem *base = get_hwbase(dev); |
| 893 | |
| 894 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
| 895 | if (rxtx_flags & NV_SETUP_RX_RING) { |
| 896 | writel((u32) cpu_to_le64(np->ring_addr), base + NvRegRxRingPhysAddr); |
| 897 | } |
| 898 | if (rxtx_flags & NV_SETUP_TX_RING) { |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 899 | writel((u32) cpu_to_le64(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr); |
Ayaz Abdulla | 0832b25 | 2006-02-04 13:13:26 -0500 | [diff] [blame] | 900 | } |
| 901 | } else { |
| 902 | if (rxtx_flags & NV_SETUP_RX_RING) { |
| 903 | writel((u32) cpu_to_le64(np->ring_addr), base + NvRegRxRingPhysAddr); |
| 904 | writel((u32) (cpu_to_le64(np->ring_addr) >> 32), base + NvRegRxRingPhysAddrHigh); |
| 905 | } |
| 906 | if (rxtx_flags & NV_SETUP_TX_RING) { |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 907 | writel((u32) cpu_to_le64(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr); |
| 908 | writel((u32) (cpu_to_le64(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)) >> 32), base + NvRegTxRingPhysAddrHigh); |
Ayaz Abdulla | 0832b25 | 2006-02-04 13:13:26 -0500 | [diff] [blame] | 909 | } |
| 910 | } |
| 911 | } |
| 912 | |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 913 | static void free_rings(struct net_device *dev) |
| 914 | { |
| 915 | struct fe_priv *np = get_nvpriv(dev); |
| 916 | |
| 917 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 918 | if (np->rx_ring.orig) |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 919 | pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size), |
| 920 | np->rx_ring.orig, np->ring_addr); |
| 921 | } else { |
| 922 | if (np->rx_ring.ex) |
| 923 | pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size), |
| 924 | np->rx_ring.ex, np->ring_addr); |
| 925 | } |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 926 | if (np->rx_skb) |
| 927 | kfree(np->rx_skb); |
| 928 | if (np->tx_skb) |
| 929 | kfree(np->tx_skb); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 930 | } |
| 931 | |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 932 | static int using_multi_irqs(struct net_device *dev) |
| 933 | { |
| 934 | struct fe_priv *np = get_nvpriv(dev); |
| 935 | |
| 936 | if (!(np->msi_flags & NV_MSI_X_ENABLED) || |
| 937 | ((np->msi_flags & NV_MSI_X_ENABLED) && |
| 938 | ((np->msi_flags & NV_MSI_X_VECTORS_MASK) == 0x1))) |
| 939 | return 0; |
| 940 | else |
| 941 | return 1; |
| 942 | } |
| 943 | |
| 944 | static void nv_enable_irq(struct net_device *dev) |
| 945 | { |
| 946 | struct fe_priv *np = get_nvpriv(dev); |
| 947 | |
| 948 | if (!using_multi_irqs(dev)) { |
| 949 | if (np->msi_flags & NV_MSI_X_ENABLED) |
| 950 | enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector); |
| 951 | else |
| 952 | enable_irq(dev->irq); |
| 953 | } else { |
| 954 | enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector); |
| 955 | enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector); |
| 956 | enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector); |
| 957 | } |
| 958 | } |
| 959 | |
| 960 | static void nv_disable_irq(struct net_device *dev) |
| 961 | { |
| 962 | struct fe_priv *np = get_nvpriv(dev); |
| 963 | |
| 964 | if (!using_multi_irqs(dev)) { |
| 965 | if (np->msi_flags & NV_MSI_X_ENABLED) |
| 966 | disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector); |
| 967 | else |
| 968 | disable_irq(dev->irq); |
| 969 | } else { |
| 970 | disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector); |
| 971 | disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector); |
| 972 | disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector); |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | /* In MSIX mode, a write to irqmask behaves as XOR */ |
| 977 | static void nv_enable_hw_interrupts(struct net_device *dev, u32 mask) |
| 978 | { |
| 979 | u8 __iomem *base = get_hwbase(dev); |
| 980 | |
| 981 | writel(mask, base + NvRegIrqMask); |
| 982 | } |
| 983 | |
| 984 | static void nv_disable_hw_interrupts(struct net_device *dev, u32 mask) |
| 985 | { |
| 986 | struct fe_priv *np = get_nvpriv(dev); |
| 987 | u8 __iomem *base = get_hwbase(dev); |
| 988 | |
| 989 | if (np->msi_flags & NV_MSI_X_ENABLED) { |
| 990 | writel(mask, base + NvRegIrqMask); |
| 991 | } else { |
| 992 | if (np->msi_flags & NV_MSI_ENABLED) |
| 993 | writel(0, base + NvRegMSIIrqMask); |
| 994 | writel(0, base + NvRegIrqMask); |
| 995 | } |
| 996 | } |
| 997 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 998 | #define MII_READ (-1) |
| 999 | /* mii_rw: read/write a register on the PHY. |
| 1000 | * |
| 1001 | * Caller must guarantee serialization |
| 1002 | */ |
| 1003 | static int mii_rw(struct net_device *dev, int addr, int miireg, int value) |
| 1004 | { |
| 1005 | u8 __iomem *base = get_hwbase(dev); |
| 1006 | u32 reg; |
| 1007 | int retval; |
| 1008 | |
| 1009 | writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus); |
| 1010 | |
| 1011 | reg = readl(base + NvRegMIIControl); |
| 1012 | if (reg & NVREG_MIICTL_INUSE) { |
| 1013 | writel(NVREG_MIICTL_INUSE, base + NvRegMIIControl); |
| 1014 | udelay(NV_MIIBUSY_DELAY); |
| 1015 | } |
| 1016 | |
| 1017 | reg = (addr << NVREG_MIICTL_ADDRSHIFT) | miireg; |
| 1018 | if (value != MII_READ) { |
| 1019 | writel(value, base + NvRegMIIData); |
| 1020 | reg |= NVREG_MIICTL_WRITE; |
| 1021 | } |
| 1022 | writel(reg, base + NvRegMIIControl); |
| 1023 | |
| 1024 | if (reg_delay(dev, NvRegMIIControl, NVREG_MIICTL_INUSE, 0, |
| 1025 | NV_MIIPHY_DELAY, NV_MIIPHY_DELAYMAX, NULL)) { |
| 1026 | dprintk(KERN_DEBUG "%s: mii_rw of reg %d at PHY %d timed out.\n", |
| 1027 | dev->name, miireg, addr); |
| 1028 | retval = -1; |
| 1029 | } else if (value != MII_READ) { |
| 1030 | /* it was a write operation - fewer failures are detectable */ |
| 1031 | dprintk(KERN_DEBUG "%s: mii_rw wrote 0x%x to reg %d at PHY %d\n", |
| 1032 | dev->name, value, miireg, addr); |
| 1033 | retval = 0; |
| 1034 | } else if (readl(base + NvRegMIIStatus) & NVREG_MIISTAT_ERROR) { |
| 1035 | dprintk(KERN_DEBUG "%s: mii_rw of reg %d at PHY %d failed.\n", |
| 1036 | dev->name, miireg, addr); |
| 1037 | retval = -1; |
| 1038 | } else { |
| 1039 | retval = readl(base + NvRegMIIData); |
| 1040 | dprintk(KERN_DEBUG "%s: mii_rw read from reg %d at PHY %d: 0x%x.\n", |
| 1041 | dev->name, miireg, addr, retval); |
| 1042 | } |
| 1043 | |
| 1044 | return retval; |
| 1045 | } |
| 1046 | |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 1047 | static int phy_reset(struct net_device *dev, u32 bmcr_setup) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1048 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1049 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | u32 miicontrol; |
| 1051 | unsigned int tries = 0; |
| 1052 | |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 1053 | miicontrol = BMCR_RESET | bmcr_setup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1054 | if (mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol)) { |
| 1055 | return -1; |
| 1056 | } |
| 1057 | |
| 1058 | /* wait for 500ms */ |
| 1059 | msleep(500); |
| 1060 | |
| 1061 | /* must wait till reset is deasserted */ |
| 1062 | while (miicontrol & BMCR_RESET) { |
| 1063 | msleep(10); |
| 1064 | miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
| 1065 | /* FIXME: 100 tries seem excessive */ |
| 1066 | if (tries++ > 100) |
| 1067 | return -1; |
| 1068 | } |
| 1069 | return 0; |
| 1070 | } |
| 1071 | |
| 1072 | static int phy_init(struct net_device *dev) |
| 1073 | { |
| 1074 | struct fe_priv *np = get_nvpriv(dev); |
| 1075 | u8 __iomem *base = get_hwbase(dev); |
| 1076 | u32 phyinterface, phy_reserved, mii_status, mii_control, mii_control_1000,reg; |
| 1077 | |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 1078 | /* phy errata for E3016 phy */ |
| 1079 | if (np->phy_model == PHY_MODEL_MARVELL_E3016) { |
| 1080 | reg = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ); |
| 1081 | reg &= ~PHY_MARVELL_E3016_INITMASK; |
| 1082 | if (mii_rw(dev, np->phyaddr, MII_NCONFIG, reg)) { |
| 1083 | printk(KERN_INFO "%s: phy write to errata reg failed.\n", pci_name(np->pci_dev)); |
| 1084 | return PHY_ERROR; |
| 1085 | } |
| 1086 | } |
| 1087 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1088 | /* set advertise register */ |
| 1089 | reg = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ); |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 1090 | reg |= (ADVERTISE_10HALF|ADVERTISE_10FULL|ADVERTISE_100HALF|ADVERTISE_100FULL|ADVERTISE_PAUSE_ASYM|ADVERTISE_PAUSE_CAP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1091 | if (mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg)) { |
| 1092 | printk(KERN_INFO "%s: phy write to advertise failed.\n", pci_name(np->pci_dev)); |
| 1093 | return PHY_ERROR; |
| 1094 | } |
| 1095 | |
| 1096 | /* get phy interface type */ |
| 1097 | phyinterface = readl(base + NvRegPhyInterface); |
| 1098 | |
| 1099 | /* see if gigabit phy */ |
| 1100 | mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ); |
| 1101 | if (mii_status & PHY_GIGABIT) { |
| 1102 | np->gigabit = PHY_GIGABIT; |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 1103 | mii_control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1104 | mii_control_1000 &= ~ADVERTISE_1000HALF; |
| 1105 | if (phyinterface & PHY_RGMII) |
| 1106 | mii_control_1000 |= ADVERTISE_1000FULL; |
| 1107 | else |
| 1108 | mii_control_1000 &= ~ADVERTISE_1000FULL; |
| 1109 | |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 1110 | if (mii_rw(dev, np->phyaddr, MII_CTRL1000, mii_control_1000)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1111 | printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev)); |
| 1112 | return PHY_ERROR; |
| 1113 | } |
| 1114 | } |
| 1115 | else |
| 1116 | np->gigabit = 0; |
| 1117 | |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 1118 | mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
| 1119 | mii_control |= BMCR_ANENABLE; |
| 1120 | |
| 1121 | /* reset the phy |
| 1122 | * (certain phys need bmcr to be setup with reset) |
| 1123 | */ |
| 1124 | if (phy_reset(dev, mii_control)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1125 | printk(KERN_INFO "%s: phy reset failed\n", pci_name(np->pci_dev)); |
| 1126 | return PHY_ERROR; |
| 1127 | } |
| 1128 | |
| 1129 | /* phy vendor specific configuration */ |
| 1130 | if ((np->phy_oui == PHY_OUI_CICADA) && (phyinterface & PHY_RGMII) ) { |
| 1131 | phy_reserved = mii_rw(dev, np->phyaddr, MII_RESV1, MII_READ); |
| 1132 | phy_reserved &= ~(PHY_INIT1 | PHY_INIT2); |
| 1133 | phy_reserved |= (PHY_INIT3 | PHY_INIT4); |
| 1134 | if (mii_rw(dev, np->phyaddr, MII_RESV1, phy_reserved)) { |
| 1135 | printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev)); |
| 1136 | return PHY_ERROR; |
| 1137 | } |
| 1138 | phy_reserved = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ); |
| 1139 | phy_reserved |= PHY_INIT5; |
| 1140 | if (mii_rw(dev, np->phyaddr, MII_NCONFIG, phy_reserved)) { |
| 1141 | printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev)); |
| 1142 | return PHY_ERROR; |
| 1143 | } |
| 1144 | } |
| 1145 | if (np->phy_oui == PHY_OUI_CICADA) { |
| 1146 | phy_reserved = mii_rw(dev, np->phyaddr, MII_SREVISION, MII_READ); |
| 1147 | phy_reserved |= PHY_INIT6; |
| 1148 | if (mii_rw(dev, np->phyaddr, MII_SREVISION, phy_reserved)) { |
| 1149 | printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev)); |
| 1150 | return PHY_ERROR; |
| 1151 | } |
| 1152 | } |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 1153 | /* some phys clear out pause advertisment on reset, set it back */ |
| 1154 | mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1155 | |
| 1156 | /* restart auto negotiation */ |
| 1157 | mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
| 1158 | mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE); |
| 1159 | if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control)) { |
| 1160 | return PHY_ERROR; |
| 1161 | } |
| 1162 | |
| 1163 | return 0; |
| 1164 | } |
| 1165 | |
| 1166 | static void nv_start_rx(struct net_device *dev) |
| 1167 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1168 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | u8 __iomem *base = get_hwbase(dev); |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1170 | u32 rx_ctrl = readl(base + NvRegReceiverControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | |
| 1172 | dprintk(KERN_DEBUG "%s: nv_start_rx\n", dev->name); |
| 1173 | /* Already running? Stop it. */ |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1174 | if ((readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) && !np->mac_in_use) { |
| 1175 | rx_ctrl &= ~NVREG_RCVCTL_START; |
| 1176 | writel(rx_ctrl, base + NvRegReceiverControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1177 | pci_push(base); |
| 1178 | } |
| 1179 | writel(np->linkspeed, base + NvRegLinkSpeed); |
| 1180 | pci_push(base); |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1181 | rx_ctrl |= NVREG_RCVCTL_START; |
| 1182 | if (np->mac_in_use) |
| 1183 | rx_ctrl &= ~NVREG_RCVCTL_RX_PATH_EN; |
| 1184 | writel(rx_ctrl, base + NvRegReceiverControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | dprintk(KERN_DEBUG "%s: nv_start_rx to duplex %d, speed 0x%08x.\n", |
| 1186 | dev->name, np->duplex, np->linkspeed); |
| 1187 | pci_push(base); |
| 1188 | } |
| 1189 | |
| 1190 | static void nv_stop_rx(struct net_device *dev) |
| 1191 | { |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1192 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | u8 __iomem *base = get_hwbase(dev); |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1194 | u32 rx_ctrl = readl(base + NvRegReceiverControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1195 | |
| 1196 | dprintk(KERN_DEBUG "%s: nv_stop_rx\n", dev->name); |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1197 | if (!np->mac_in_use) |
| 1198 | rx_ctrl &= ~NVREG_RCVCTL_START; |
| 1199 | else |
| 1200 | rx_ctrl |= NVREG_RCVCTL_RX_PATH_EN; |
| 1201 | writel(rx_ctrl, base + NvRegReceiverControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1202 | reg_delay(dev, NvRegReceiverStatus, NVREG_RCVSTAT_BUSY, 0, |
| 1203 | NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX, |
| 1204 | KERN_INFO "nv_stop_rx: ReceiverStatus remained busy"); |
| 1205 | |
| 1206 | udelay(NV_RXSTOP_DELAY2); |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1207 | if (!np->mac_in_use) |
| 1208 | writel(0, base + NvRegLinkSpeed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1209 | } |
| 1210 | |
| 1211 | static void nv_start_tx(struct net_device *dev) |
| 1212 | { |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1213 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | u8 __iomem *base = get_hwbase(dev); |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1215 | u32 tx_ctrl = readl(base + NvRegTransmitterControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1216 | |
| 1217 | dprintk(KERN_DEBUG "%s: nv_start_tx\n", dev->name); |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1218 | tx_ctrl |= NVREG_XMITCTL_START; |
| 1219 | if (np->mac_in_use) |
| 1220 | tx_ctrl &= ~NVREG_XMITCTL_TX_PATH_EN; |
| 1221 | writel(tx_ctrl, base + NvRegTransmitterControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1222 | pci_push(base); |
| 1223 | } |
| 1224 | |
| 1225 | static void nv_stop_tx(struct net_device *dev) |
| 1226 | { |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1227 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | u8 __iomem *base = get_hwbase(dev); |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1229 | u32 tx_ctrl = readl(base + NvRegTransmitterControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | |
| 1231 | dprintk(KERN_DEBUG "%s: nv_stop_tx\n", dev->name); |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1232 | if (!np->mac_in_use) |
| 1233 | tx_ctrl &= ~NVREG_XMITCTL_START; |
| 1234 | else |
| 1235 | tx_ctrl |= NVREG_XMITCTL_TX_PATH_EN; |
| 1236 | writel(tx_ctrl, base + NvRegTransmitterControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1237 | reg_delay(dev, NvRegTransmitterStatus, NVREG_XMITSTAT_BUSY, 0, |
| 1238 | NV_TXSTOP_DELAY1, NV_TXSTOP_DELAY1MAX, |
| 1239 | KERN_INFO "nv_stop_tx: TransmitterStatus remained busy"); |
| 1240 | |
| 1241 | udelay(NV_TXSTOP_DELAY2); |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1242 | if (!np->mac_in_use) |
| 1243 | writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV, |
| 1244 | base + NvRegTransmitPoll); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1245 | } |
| 1246 | |
| 1247 | static void nv_txrx_reset(struct net_device *dev) |
| 1248 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1249 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | u8 __iomem *base = get_hwbase(dev); |
| 1251 | |
| 1252 | dprintk(KERN_DEBUG "%s: nv_txrx_reset\n", dev->name); |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 1253 | writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1254 | pci_push(base); |
| 1255 | udelay(NV_TXRX_RESET_DELAY); |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 1256 | writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | pci_push(base); |
| 1258 | } |
| 1259 | |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 1260 | static void nv_mac_reset(struct net_device *dev) |
| 1261 | { |
| 1262 | struct fe_priv *np = netdev_priv(dev); |
| 1263 | u8 __iomem *base = get_hwbase(dev); |
| 1264 | |
| 1265 | dprintk(KERN_DEBUG "%s: nv_mac_reset\n", dev->name); |
| 1266 | writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl); |
| 1267 | pci_push(base); |
| 1268 | writel(NVREG_MAC_RESET_ASSERT, base + NvRegMacReset); |
| 1269 | pci_push(base); |
| 1270 | udelay(NV_MAC_RESET_DELAY); |
| 1271 | writel(0, base + NvRegMacReset); |
| 1272 | pci_push(base); |
| 1273 | udelay(NV_MAC_RESET_DELAY); |
| 1274 | writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl); |
| 1275 | pci_push(base); |
| 1276 | } |
| 1277 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | /* |
| 1279 | * nv_get_stats: dev->get_stats function |
| 1280 | * Get latest stats value from the nic. |
| 1281 | * Called with read_lock(&dev_base_lock) held for read - |
| 1282 | * only synchronized against unregister_netdevice. |
| 1283 | */ |
| 1284 | static struct net_device_stats *nv_get_stats(struct net_device *dev) |
| 1285 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1286 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1287 | |
| 1288 | /* It seems that the nic always generates interrupts and doesn't |
| 1289 | * accumulate errors internally. Thus the current values in np->stats |
| 1290 | * are already up to date. |
| 1291 | */ |
| 1292 | return &np->stats; |
| 1293 | } |
| 1294 | |
| 1295 | /* |
| 1296 | * nv_alloc_rx: fill rx ring entries. |
| 1297 | * Return 1 if the allocations for the skbs failed and the |
| 1298 | * rx engine is without Available descriptors |
| 1299 | */ |
| 1300 | static int nv_alloc_rx(struct net_device *dev) |
| 1301 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1302 | struct fe_priv *np = netdev_priv(dev); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1303 | struct ring_desc* less_rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1304 | |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1305 | less_rx = np->get_rx.orig; |
| 1306 | if (less_rx-- == np->first_rx.orig) |
| 1307 | less_rx = np->last_rx.orig; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1308 | |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1309 | while (np->put_rx.orig != less_rx) { |
| 1310 | struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD); |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 1311 | if (skb) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | skb->dev = dev; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1313 | np->put_rx_ctx->skb = skb; |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 1314 | np->put_rx_ctx->dma = pci_map_single(np->pci_dev, skb->data, |
| 1315 | skb->end-skb->data, PCI_DMA_FROMDEVICE); |
| 1316 | np->put_rx_ctx->dma_len = skb->end-skb->data; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1317 | np->put_rx.orig->buf = cpu_to_le32(np->put_rx_ctx->dma); |
| 1318 | wmb(); |
| 1319 | np->put_rx.orig->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX_AVAIL); |
| 1320 | if (np->put_rx.orig++ == np->last_rx.orig) |
| 1321 | np->put_rx.orig = np->first_rx.orig; |
| 1322 | if (np->put_rx_ctx++ == np->last_rx_ctx) |
| 1323 | np->put_rx_ctx = np->first_rx_ctx; |
| 1324 | } else { |
| 1325 | return 1; |
| 1326 | } |
| 1327 | } |
| 1328 | return 0; |
| 1329 | } |
| 1330 | |
| 1331 | static int nv_alloc_rx_optimized(struct net_device *dev) |
| 1332 | { |
| 1333 | struct fe_priv *np = netdev_priv(dev); |
| 1334 | struct ring_desc_ex* less_rx; |
| 1335 | |
| 1336 | less_rx = np->get_rx.ex; |
| 1337 | if (less_rx-- == np->first_rx.ex) |
| 1338 | less_rx = np->last_rx.ex; |
| 1339 | |
| 1340 | while (np->put_rx.ex != less_rx) { |
| 1341 | struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD); |
| 1342 | if (skb) { |
| 1343 | skb->dev = dev; |
| 1344 | np->put_rx_ctx->skb = skb; |
| 1345 | np->put_rx_ctx->dma = pci_map_single(np->pci_dev, skb->data, |
| 1346 | skb->end-skb->data, PCI_DMA_FROMDEVICE); |
| 1347 | np->put_rx_ctx->dma_len = skb->end-skb->data; |
| 1348 | np->put_rx.ex->bufhigh = cpu_to_le64(np->put_rx_ctx->dma) >> 32; |
| 1349 | np->put_rx.ex->buflow = cpu_to_le64(np->put_rx_ctx->dma) & 0x0FFFFFFFF; |
| 1350 | wmb(); |
| 1351 | np->put_rx.ex->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX2_AVAIL); |
| 1352 | if (np->put_rx.ex++ == np->last_rx.ex) |
| 1353 | np->put_rx.ex = np->first_rx.ex; |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 1354 | if (np->put_rx_ctx++ == np->last_rx_ctx) |
| 1355 | np->put_rx_ctx = np->first_rx_ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1356 | } else { |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 1357 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1358 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1359 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1360 | return 0; |
| 1361 | } |
| 1362 | |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 1363 | /* If rx bufs are exhausted called after 50ms to attempt to refresh */ |
| 1364 | #ifdef CONFIG_FORCEDETH_NAPI |
| 1365 | static void nv_do_rx_refill(unsigned long data) |
| 1366 | { |
| 1367 | struct net_device *dev = (struct net_device *) data; |
| 1368 | |
| 1369 | /* Just reschedule NAPI rx processing */ |
| 1370 | netif_rx_schedule(dev); |
| 1371 | } |
| 1372 | #else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | static void nv_do_rx_refill(unsigned long data) |
| 1374 | { |
| 1375 | struct net_device *dev = (struct net_device *) data; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1376 | struct fe_priv *np = netdev_priv(dev); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1377 | int retcode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1378 | |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 1379 | if (!using_multi_irqs(dev)) { |
| 1380 | if (np->msi_flags & NV_MSI_X_ENABLED) |
| 1381 | disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector); |
| 1382 | else |
| 1383 | disable_irq(dev->irq); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 1384 | } else { |
| 1385 | disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector); |
| 1386 | } |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1387 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
| 1388 | retcode = nv_alloc_rx(dev); |
| 1389 | else |
| 1390 | retcode = nv_alloc_rx_optimized(dev); |
| 1391 | if (retcode) { |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 1392 | spin_lock_irq(&np->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1393 | if (!np->in_shutdown) |
| 1394 | mod_timer(&np->oom_kick, jiffies + OOM_REFILL); |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 1395 | spin_unlock_irq(&np->lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1396 | } |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 1397 | if (!using_multi_irqs(dev)) { |
| 1398 | if (np->msi_flags & NV_MSI_X_ENABLED) |
| 1399 | enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector); |
| 1400 | else |
| 1401 | enable_irq(dev->irq); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 1402 | } else { |
| 1403 | enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector); |
| 1404 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1405 | } |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 1406 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1407 | |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 1408 | static void nv_init_rx(struct net_device *dev) |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 1409 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1410 | struct fe_priv *np = netdev_priv(dev); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 1411 | int i; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1412 | np->get_rx = np->put_rx = np->first_rx = np->rx_ring; |
| 1413 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
| 1414 | np->last_rx.orig = &np->rx_ring.orig[np->rx_ring_size-1]; |
| 1415 | else |
| 1416 | np->last_rx.ex = &np->rx_ring.ex[np->rx_ring_size-1]; |
| 1417 | np->get_rx_ctx = np->put_rx_ctx = np->first_rx_ctx = np->rx_skb; |
| 1418 | np->last_rx_ctx = &np->rx_skb[np->rx_ring_size-1]; |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 1419 | |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1420 | for (i = 0; i < np->rx_ring_size; i++) { |
| 1421 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1422 | np->rx_ring.orig[i].flaglen = 0; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1423 | np->rx_ring.orig[i].buf = 0; |
| 1424 | } else { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1425 | np->rx_ring.ex[i].flaglen = 0; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1426 | np->rx_ring.ex[i].txvlan = 0; |
| 1427 | np->rx_ring.ex[i].bufhigh = 0; |
| 1428 | np->rx_ring.ex[i].buflow = 0; |
| 1429 | } |
| 1430 | np->rx_skb[i].skb = NULL; |
| 1431 | np->rx_skb[i].dma = 0; |
| 1432 | } |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 1433 | } |
| 1434 | |
| 1435 | static void nv_init_tx(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1436 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1437 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | int i; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1439 | np->get_tx = np->put_tx = np->first_tx = np->tx_ring; |
| 1440 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
| 1441 | np->last_tx.orig = &np->tx_ring.orig[np->tx_ring_size-1]; |
| 1442 | else |
| 1443 | np->last_tx.ex = &np->tx_ring.ex[np->tx_ring_size-1]; |
| 1444 | np->get_tx_ctx = np->put_tx_ctx = np->first_tx_ctx = np->tx_skb; |
| 1445 | np->last_tx_ctx = &np->tx_skb[np->tx_ring_size-1]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 1447 | for (i = 0; i < np->tx_ring_size; i++) { |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1448 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1449 | np->tx_ring.orig[i].flaglen = 0; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1450 | np->tx_ring.orig[i].buf = 0; |
| 1451 | } else { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1452 | np->tx_ring.ex[i].flaglen = 0; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1453 | np->tx_ring.ex[i].txvlan = 0; |
| 1454 | np->tx_ring.ex[i].bufhigh = 0; |
| 1455 | np->tx_ring.ex[i].buflow = 0; |
| 1456 | } |
| 1457 | np->tx_skb[i].skb = NULL; |
| 1458 | np->tx_skb[i].dma = 0; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1459 | } |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 1460 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1461 | |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 1462 | static int nv_init_ring(struct net_device *dev) |
| 1463 | { |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1464 | struct fe_priv *np = netdev_priv(dev); |
| 1465 | |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 1466 | nv_init_tx(dev); |
| 1467 | nv_init_rx(dev); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1468 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
| 1469 | return nv_alloc_rx(dev); |
| 1470 | else |
| 1471 | return nv_alloc_rx_optimized(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1472 | } |
| 1473 | |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1474 | static int nv_release_txskb(struct net_device *dev, struct nv_skb_map* tx_skb) |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1475 | { |
| 1476 | struct fe_priv *np = netdev_priv(dev); |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1477 | |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1478 | if (tx_skb->dma) { |
| 1479 | pci_unmap_page(np->pci_dev, tx_skb->dma, |
| 1480 | tx_skb->dma_len, |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1481 | PCI_DMA_TODEVICE); |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1482 | tx_skb->dma = 0; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1483 | } |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1484 | if (tx_skb->skb) { |
| 1485 | dev_kfree_skb_any(tx_skb->skb); |
| 1486 | tx_skb->skb = NULL; |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1487 | return 1; |
| 1488 | } else { |
| 1489 | return 0; |
| 1490 | } |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1491 | } |
| 1492 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1493 | static void nv_drain_tx(struct net_device *dev) |
| 1494 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1495 | struct fe_priv *np = netdev_priv(dev); |
| 1496 | unsigned int i; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 1497 | |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 1498 | for (i = 0; i < np->tx_ring_size; i++) { |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1499 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1500 | np->tx_ring.orig[i].flaglen = 0; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1501 | np->tx_ring.orig[i].buf = 0; |
| 1502 | } else { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1503 | np->tx_ring.ex[i].flaglen = 0; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1504 | np->tx_ring.ex[i].txvlan = 0; |
| 1505 | np->tx_ring.ex[i].bufhigh = 0; |
| 1506 | np->tx_ring.ex[i].buflow = 0; |
| 1507 | } |
| 1508 | if (nv_release_txskb(dev, &np->tx_skb[i])) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1509 | np->stats.tx_dropped++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1510 | } |
| 1511 | } |
| 1512 | |
| 1513 | static void nv_drain_rx(struct net_device *dev) |
| 1514 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1515 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1516 | int i; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1517 | |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 1518 | for (i = 0; i < np->rx_ring_size; i++) { |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1519 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1520 | np->rx_ring.orig[i].flaglen = 0; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1521 | np->rx_ring.orig[i].buf = 0; |
| 1522 | } else { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1523 | np->rx_ring.ex[i].flaglen = 0; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1524 | np->rx_ring.ex[i].txvlan = 0; |
| 1525 | np->rx_ring.ex[i].bufhigh = 0; |
| 1526 | np->rx_ring.ex[i].buflow = 0; |
| 1527 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | wmb(); |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1529 | if (np->rx_skb[i].skb) { |
| 1530 | pci_unmap_single(np->pci_dev, np->rx_skb[i].dma, |
| 1531 | np->rx_skb[i].skb->end-np->rx_skb[i].skb->data, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1532 | PCI_DMA_FROMDEVICE); |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1533 | dev_kfree_skb(np->rx_skb[i].skb); |
| 1534 | np->rx_skb[i].skb = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | } |
| 1536 | } |
| 1537 | } |
| 1538 | |
| 1539 | static void drain_ring(struct net_device *dev) |
| 1540 | { |
| 1541 | nv_drain_tx(dev); |
| 1542 | nv_drain_rx(dev); |
| 1543 | } |
| 1544 | |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1545 | static inline u32 nv_get_empty_tx_slots(struct fe_priv *np) |
| 1546 | { |
| 1547 | return (u32)(np->tx_ring_size - ((np->tx_ring_size + (np->put_tx_ctx - np->get_tx_ctx)) % np->tx_ring_size)); |
| 1548 | } |
| 1549 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1550 | /* |
| 1551 | * nv_start_xmit: dev->hard_start_xmit function |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 1552 | * Called with netif_tx_lock held. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1553 | */ |
| 1554 | static int nv_start_xmit(struct sk_buff *skb, struct net_device *dev) |
| 1555 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1556 | struct fe_priv *np = netdev_priv(dev); |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1557 | u32 tx_flags = 0; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1558 | u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET); |
| 1559 | unsigned int fragments = skb_shinfo(skb)->nr_frags; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1560 | unsigned int i; |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1561 | u32 offset = 0; |
| 1562 | u32 bcnt; |
| 1563 | u32 size = skb->len-skb->data_len; |
| 1564 | u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0); |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1565 | u32 empty_slots; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1566 | struct ring_desc* put_tx; |
| 1567 | struct ring_desc* start_tx; |
| 1568 | struct ring_desc* prev_tx; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1569 | struct nv_skb_map* prev_tx_ctx; |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1570 | |
| 1571 | /* add fragments to entries count */ |
| 1572 | for (i = 0; i < fragments; i++) { |
| 1573 | entries += (skb_shinfo(skb)->frags[i].size >> NV_TX2_TSO_MAX_SHIFT) + |
| 1574 | ((skb_shinfo(skb)->frags[i].size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0); |
| 1575 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1576 | |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1577 | empty_slots = nv_get_empty_tx_slots(np); |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1578 | if (unlikely(empty_slots <= entries)) { |
Ayaz Abdulla | 164a86e | 2007-01-09 13:30:10 -0500 | [diff] [blame] | 1579 | spin_lock_irq(&np->lock); |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1580 | netif_stop_queue(dev); |
Ayaz Abdulla | aaa37d2 | 2007-01-21 18:10:42 -0500 | [diff] [blame] | 1581 | np->tx_stop = 1; |
Ayaz Abdulla | 164a86e | 2007-01-09 13:30:10 -0500 | [diff] [blame] | 1582 | spin_unlock_irq(&np->lock); |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1583 | return NETDEV_TX_BUSY; |
| 1584 | } |
| 1585 | |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1586 | start_tx = put_tx = np->put_tx.orig; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1587 | |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1588 | /* setup the header buffer */ |
| 1589 | do { |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1590 | prev_tx = put_tx; |
| 1591 | prev_tx_ctx = np->put_tx_ctx; |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1592 | bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1593 | np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt, |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1594 | PCI_DMA_TODEVICE); |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1595 | np->put_tx_ctx->dma_len = bcnt; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1596 | put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma); |
| 1597 | put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags); |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1598 | |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1599 | tx_flags = np->tx_flags; |
| 1600 | offset += bcnt; |
| 1601 | size -= bcnt; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1602 | if (unlikely(put_tx++ == np->last_tx.orig)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1603 | put_tx = np->first_tx.orig; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1604 | if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx)) |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1605 | np->put_tx_ctx = np->first_tx_ctx; |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1606 | } while (size); |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1607 | |
| 1608 | /* setup the fragments */ |
| 1609 | for (i = 0; i < fragments; i++) { |
| 1610 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 1611 | u32 size = frag->size; |
| 1612 | offset = 0; |
| 1613 | |
| 1614 | do { |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1615 | prev_tx = put_tx; |
| 1616 | prev_tx_ctx = np->put_tx_ctx; |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1617 | bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1618 | np->put_tx_ctx->dma = pci_map_page(np->pci_dev, frag->page, frag->page_offset+offset, bcnt, |
| 1619 | PCI_DMA_TODEVICE); |
| 1620 | np->put_tx_ctx->dma_len = bcnt; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1621 | put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma); |
| 1622 | put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags); |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1623 | |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1624 | offset += bcnt; |
| 1625 | size -= bcnt; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1626 | if (unlikely(put_tx++ == np->last_tx.orig)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1627 | put_tx = np->first_tx.orig; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1628 | if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx)) |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1629 | np->put_tx_ctx = np->first_tx_ctx; |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1630 | } while (size); |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1631 | } |
| 1632 | |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1633 | /* set last fragment flag */ |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1634 | prev_tx->flaglen |= cpu_to_le32(tx_flags_extra); |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1635 | |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1636 | /* save skb in this slot's context area */ |
| 1637 | prev_tx_ctx->skb = skb; |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1638 | |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 1639 | if (skb_is_gso(skb)) |
Herbert Xu | 7967168 | 2006-06-22 02:40:14 -0700 | [diff] [blame] | 1640 | tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT); |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 1641 | else |
Arjan van de Ven | 1d39ed5 | 2006-12-12 14:06:23 +0100 | [diff] [blame] | 1642 | tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ? |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 1643 | NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1644 | |
Ayaz Abdulla | 164a86e | 2007-01-09 13:30:10 -0500 | [diff] [blame] | 1645 | spin_lock_irq(&np->lock); |
| 1646 | |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 1647 | /* set tx flags */ |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1648 | start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra); |
| 1649 | np->put_tx.orig = put_tx; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1650 | |
Ayaz Abdulla | 164a86e | 2007-01-09 13:30:10 -0500 | [diff] [blame] | 1651 | spin_unlock_irq(&np->lock); |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1652 | |
| 1653 | dprintk(KERN_DEBUG "%s: nv_start_xmit: entries %d queued for transmission. tx_flags_extra: %x\n", |
| 1654 | dev->name, entries, tx_flags_extra); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1655 | { |
| 1656 | int j; |
| 1657 | for (j=0; j<64; j++) { |
| 1658 | if ((j%16) == 0) |
| 1659 | dprintk("\n%03x:", j); |
| 1660 | dprintk(" %02x", ((unsigned char*)skb->data)[j]); |
| 1661 | } |
| 1662 | dprintk("\n"); |
| 1663 | } |
| 1664 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1665 | dev->trans_start = jiffies; |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 1666 | writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl); |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1667 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1668 | } |
| 1669 | |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1670 | static int nv_start_xmit_optimized(struct sk_buff *skb, struct net_device *dev) |
| 1671 | { |
| 1672 | struct fe_priv *np = netdev_priv(dev); |
| 1673 | u32 tx_flags = 0; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1674 | u32 tx_flags_extra; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1675 | unsigned int fragments = skb_shinfo(skb)->nr_frags; |
| 1676 | unsigned int i; |
| 1677 | u32 offset = 0; |
| 1678 | u32 bcnt; |
| 1679 | u32 size = skb->len-skb->data_len; |
| 1680 | u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0); |
| 1681 | u32 empty_slots; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1682 | struct ring_desc_ex* put_tx; |
| 1683 | struct ring_desc_ex* start_tx; |
| 1684 | struct ring_desc_ex* prev_tx; |
| 1685 | struct nv_skb_map* prev_tx_ctx; |
| 1686 | |
| 1687 | /* add fragments to entries count */ |
| 1688 | for (i = 0; i < fragments; i++) { |
| 1689 | entries += (skb_shinfo(skb)->frags[i].size >> NV_TX2_TSO_MAX_SHIFT) + |
| 1690 | ((skb_shinfo(skb)->frags[i].size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0); |
| 1691 | } |
| 1692 | |
| 1693 | empty_slots = nv_get_empty_tx_slots(np); |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1694 | if (unlikely(empty_slots <= entries)) { |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1695 | spin_lock_irq(&np->lock); |
| 1696 | netif_stop_queue(dev); |
Ayaz Abdulla | aaa37d2 | 2007-01-21 18:10:42 -0500 | [diff] [blame] | 1697 | np->tx_stop = 1; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1698 | spin_unlock_irq(&np->lock); |
| 1699 | return NETDEV_TX_BUSY; |
| 1700 | } |
| 1701 | |
| 1702 | start_tx = put_tx = np->put_tx.ex; |
| 1703 | |
| 1704 | /* setup the header buffer */ |
| 1705 | do { |
| 1706 | prev_tx = put_tx; |
| 1707 | prev_tx_ctx = np->put_tx_ctx; |
| 1708 | bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size; |
| 1709 | np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt, |
| 1710 | PCI_DMA_TODEVICE); |
| 1711 | np->put_tx_ctx->dma_len = bcnt; |
| 1712 | put_tx->bufhigh = cpu_to_le64(np->put_tx_ctx->dma) >> 32; |
| 1713 | put_tx->buflow = cpu_to_le64(np->put_tx_ctx->dma) & 0x0FFFFFFFF; |
| 1714 | put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags); |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1715 | |
| 1716 | tx_flags = NV_TX2_VALID; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1717 | offset += bcnt; |
| 1718 | size -= bcnt; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1719 | if (unlikely(put_tx++ == np->last_tx.ex)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1720 | put_tx = np->first_tx.ex; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1721 | if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1722 | np->put_tx_ctx = np->first_tx_ctx; |
| 1723 | } while (size); |
| 1724 | |
| 1725 | /* setup the fragments */ |
| 1726 | for (i = 0; i < fragments; i++) { |
| 1727 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
| 1728 | u32 size = frag->size; |
| 1729 | offset = 0; |
| 1730 | |
| 1731 | do { |
| 1732 | prev_tx = put_tx; |
| 1733 | prev_tx_ctx = np->put_tx_ctx; |
| 1734 | bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size; |
| 1735 | np->put_tx_ctx->dma = pci_map_page(np->pci_dev, frag->page, frag->page_offset+offset, bcnt, |
| 1736 | PCI_DMA_TODEVICE); |
| 1737 | np->put_tx_ctx->dma_len = bcnt; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1738 | put_tx->bufhigh = cpu_to_le64(np->put_tx_ctx->dma) >> 32; |
| 1739 | put_tx->buflow = cpu_to_le64(np->put_tx_ctx->dma) & 0x0FFFFFFFF; |
| 1740 | put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags); |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1741 | |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1742 | offset += bcnt; |
| 1743 | size -= bcnt; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1744 | if (unlikely(put_tx++ == np->last_tx.ex)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1745 | put_tx = np->first_tx.ex; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1746 | if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1747 | np->put_tx_ctx = np->first_tx_ctx; |
| 1748 | } while (size); |
| 1749 | } |
| 1750 | |
| 1751 | /* set last fragment flag */ |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1752 | prev_tx->flaglen |= cpu_to_le32(NV_TX2_LASTPACKET); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1753 | |
| 1754 | /* save skb in this slot's context area */ |
| 1755 | prev_tx_ctx->skb = skb; |
| 1756 | |
| 1757 | if (skb_is_gso(skb)) |
| 1758 | tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT); |
| 1759 | else |
| 1760 | tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ? |
| 1761 | NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0; |
| 1762 | |
| 1763 | /* vlan tag */ |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1764 | if (likely(!np->vlangrp)) { |
| 1765 | start_tx->txvlan = 0; |
| 1766 | } else { |
| 1767 | if (vlan_tx_tag_present(skb)) |
| 1768 | start_tx->txvlan = cpu_to_le32(NV_TX3_VLAN_TAG_PRESENT | vlan_tx_tag_get(skb)); |
| 1769 | else |
| 1770 | start_tx->txvlan = 0; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1771 | } |
| 1772 | |
| 1773 | spin_lock_irq(&np->lock); |
| 1774 | |
| 1775 | /* set tx flags */ |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1776 | start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra); |
| 1777 | np->put_tx.ex = put_tx; |
| 1778 | |
| 1779 | spin_unlock_irq(&np->lock); |
| 1780 | |
| 1781 | dprintk(KERN_DEBUG "%s: nv_start_xmit_optimized: entries %d queued for transmission. tx_flags_extra: %x\n", |
| 1782 | dev->name, entries, tx_flags_extra); |
| 1783 | { |
| 1784 | int j; |
| 1785 | for (j=0; j<64; j++) { |
| 1786 | if ((j%16) == 0) |
| 1787 | dprintk("\n%03x:", j); |
| 1788 | dprintk(" %02x", ((unsigned char*)skb->data)[j]); |
| 1789 | } |
| 1790 | dprintk("\n"); |
| 1791 | } |
| 1792 | |
| 1793 | dev->trans_start = jiffies; |
| 1794 | writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1795 | return NETDEV_TX_OK; |
| 1796 | } |
| 1797 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1798 | /* |
| 1799 | * nv_tx_done: check for completed packets, release the skbs. |
| 1800 | * |
| 1801 | * Caller must own np->lock. |
| 1802 | */ |
| 1803 | static void nv_tx_done(struct net_device *dev) |
| 1804 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1805 | struct fe_priv *np = netdev_priv(dev); |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1806 | u32 flags; |
Ayaz Abdulla | aaa37d2 | 2007-01-21 18:10:42 -0500 | [diff] [blame] | 1807 | struct ring_desc* orig_get_tx = np->get_tx.orig; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1808 | |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1809 | while ((np->get_tx.orig != np->put_tx.orig) && |
| 1810 | !((flags = le32_to_cpu(np->get_tx.orig->flaglen)) & NV_TX_VALID)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1811 | |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1812 | dprintk(KERN_DEBUG "%s: nv_tx_done: flags 0x%x.\n", |
| 1813 | dev->name, flags); |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1814 | |
| 1815 | pci_unmap_page(np->pci_dev, np->get_tx_ctx->dma, |
| 1816 | np->get_tx_ctx->dma_len, |
| 1817 | PCI_DMA_TODEVICE); |
| 1818 | np->get_tx_ctx->dma = 0; |
| 1819 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1820 | if (np->desc_ver == DESC_VER_1) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1821 | if (flags & NV_TX_LASTPACKET) { |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1822 | if (flags & NV_TX_ERROR) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1823 | if (flags & NV_TX_UNDERFLOW) |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1824 | np->stats.tx_fifo_errors++; |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1825 | if (flags & NV_TX_CARRIERLOST) |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1826 | np->stats.tx_carrier_errors++; |
| 1827 | np->stats.tx_errors++; |
| 1828 | } else { |
| 1829 | np->stats.tx_packets++; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1830 | np->stats.tx_bytes += np->get_tx_ctx->skb->len; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1831 | } |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1832 | dev_kfree_skb_any(np->get_tx_ctx->skb); |
| 1833 | np->get_tx_ctx->skb = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1834 | } |
| 1835 | } else { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1836 | if (flags & NV_TX2_LASTPACKET) { |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1837 | if (flags & NV_TX2_ERROR) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1838 | if (flags & NV_TX2_UNDERFLOW) |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1839 | np->stats.tx_fifo_errors++; |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1840 | if (flags & NV_TX2_CARRIERLOST) |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1841 | np->stats.tx_carrier_errors++; |
| 1842 | np->stats.tx_errors++; |
| 1843 | } else { |
| 1844 | np->stats.tx_packets++; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1845 | np->stats.tx_bytes += np->get_tx_ctx->skb->len; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 1846 | } |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1847 | dev_kfree_skb_any(np->get_tx_ctx->skb); |
| 1848 | np->get_tx_ctx->skb = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1849 | } |
| 1850 | } |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1851 | if (unlikely(np->get_tx.orig++ == np->last_tx.orig)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1852 | np->get_tx.orig = np->first_tx.orig; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1853 | if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1854 | np->get_tx_ctx = np->first_tx_ctx; |
| 1855 | } |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1856 | if (unlikely((np->tx_stop == 1) && (np->get_tx.orig != orig_get_tx))) { |
Ayaz Abdulla | aaa37d2 | 2007-01-21 18:10:42 -0500 | [diff] [blame] | 1857 | np->tx_stop = 0; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1858 | netif_wake_queue(dev); |
Ayaz Abdulla | aaa37d2 | 2007-01-21 18:10:42 -0500 | [diff] [blame] | 1859 | } |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1860 | } |
| 1861 | |
| 1862 | static void nv_tx_done_optimized(struct net_device *dev) |
| 1863 | { |
| 1864 | struct fe_priv *np = netdev_priv(dev); |
| 1865 | u32 flags; |
Ayaz Abdulla | aaa37d2 | 2007-01-21 18:10:42 -0500 | [diff] [blame] | 1866 | struct ring_desc_ex* orig_get_tx = np->get_tx.ex; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1867 | |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1868 | while ((np->get_tx.ex != np->put_tx.ex) && |
| 1869 | !((flags = le32_to_cpu(np->get_tx.ex->flaglen)) & NV_TX_VALID)) { |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1870 | |
| 1871 | dprintk(KERN_DEBUG "%s: nv_tx_done_optimized: flags 0x%x.\n", |
| 1872 | dev->name, flags); |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1873 | |
| 1874 | pci_unmap_page(np->pci_dev, np->get_tx_ctx->dma, |
| 1875 | np->get_tx_ctx->dma_len, |
| 1876 | PCI_DMA_TODEVICE); |
| 1877 | np->get_tx_ctx->dma = 0; |
| 1878 | |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1879 | if (flags & NV_TX2_LASTPACKET) { |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1880 | if (flags & NV_TX2_ERROR) { |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1881 | if (flags & NV_TX2_UNDERFLOW) |
| 1882 | np->stats.tx_fifo_errors++; |
| 1883 | if (flags & NV_TX2_CARRIERLOST) |
| 1884 | np->stats.tx_carrier_errors++; |
| 1885 | np->stats.tx_errors++; |
| 1886 | } else { |
| 1887 | np->stats.tx_packets++; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1888 | np->stats.tx_bytes += np->get_tx_ctx->skb->len; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1889 | } |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1890 | dev_kfree_skb_any(np->get_tx_ctx->skb); |
| 1891 | np->get_tx_ctx->skb = NULL; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1892 | } |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1893 | if (unlikely(np->get_tx.ex++ == np->last_tx.ex)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1894 | np->get_tx.ex = np->first_tx.ex; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1895 | if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx)) |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1896 | np->get_tx_ctx = np->first_tx_ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1897 | } |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame^] | 1898 | if (unlikely((np->tx_stop == 1) && (np->get_tx.ex != orig_get_tx))) { |
Ayaz Abdulla | aaa37d2 | 2007-01-21 18:10:42 -0500 | [diff] [blame] | 1899 | np->tx_stop = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1900 | netif_wake_queue(dev); |
Ayaz Abdulla | aaa37d2 | 2007-01-21 18:10:42 -0500 | [diff] [blame] | 1901 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1902 | } |
| 1903 | |
| 1904 | /* |
| 1905 | * nv_tx_timeout: dev->tx_timeout function |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 1906 | * Called with netif_tx_lock held. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1907 | */ |
| 1908 | static void nv_tx_timeout(struct net_device *dev) |
| 1909 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1910 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1911 | u8 __iomem *base = get_hwbase(dev); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 1912 | u32 status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1913 | |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 1914 | if (np->msi_flags & NV_MSI_X_ENABLED) |
| 1915 | status = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK; |
| 1916 | else |
| 1917 | status = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK; |
| 1918 | |
| 1919 | printk(KERN_INFO "%s: Got tx_timeout. irq: %08x\n", dev->name, status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1920 | |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 1921 | { |
| 1922 | int i; |
| 1923 | |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1924 | printk(KERN_INFO "%s: Ring at %lx\n", |
| 1925 | dev->name, (unsigned long)np->ring_addr); |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 1926 | printk(KERN_INFO "%s: Dumping tx registers\n", dev->name); |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 1927 | for (i=0;i<=np->register_size;i+= 32) { |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 1928 | printk(KERN_INFO "%3x: %08x %08x %08x %08x %08x %08x %08x %08x\n", |
| 1929 | i, |
| 1930 | readl(base + i + 0), readl(base + i + 4), |
| 1931 | readl(base + i + 8), readl(base + i + 12), |
| 1932 | readl(base + i + 16), readl(base + i + 20), |
| 1933 | readl(base + i + 24), readl(base + i + 28)); |
| 1934 | } |
| 1935 | printk(KERN_INFO "%s: Dumping tx ring\n", dev->name); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 1936 | for (i=0;i<np->tx_ring_size;i+= 4) { |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 1937 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
| 1938 | printk(KERN_INFO "%03x: %08x %08x // %08x %08x // %08x %08x // %08x %08x\n", |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 1939 | i, |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1940 | le32_to_cpu(np->tx_ring.orig[i].buf), |
| 1941 | le32_to_cpu(np->tx_ring.orig[i].flaglen), |
| 1942 | le32_to_cpu(np->tx_ring.orig[i+1].buf), |
| 1943 | le32_to_cpu(np->tx_ring.orig[i+1].flaglen), |
| 1944 | le32_to_cpu(np->tx_ring.orig[i+2].buf), |
| 1945 | le32_to_cpu(np->tx_ring.orig[i+2].flaglen), |
| 1946 | le32_to_cpu(np->tx_ring.orig[i+3].buf), |
| 1947 | le32_to_cpu(np->tx_ring.orig[i+3].flaglen)); |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 1948 | } else { |
| 1949 | printk(KERN_INFO "%03x: %08x %08x %08x // %08x %08x %08x // %08x %08x %08x // %08x %08x %08x\n", |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 1950 | i, |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1951 | le32_to_cpu(np->tx_ring.ex[i].bufhigh), |
| 1952 | le32_to_cpu(np->tx_ring.ex[i].buflow), |
| 1953 | le32_to_cpu(np->tx_ring.ex[i].flaglen), |
| 1954 | le32_to_cpu(np->tx_ring.ex[i+1].bufhigh), |
| 1955 | le32_to_cpu(np->tx_ring.ex[i+1].buflow), |
| 1956 | le32_to_cpu(np->tx_ring.ex[i+1].flaglen), |
| 1957 | le32_to_cpu(np->tx_ring.ex[i+2].bufhigh), |
| 1958 | le32_to_cpu(np->tx_ring.ex[i+2].buflow), |
| 1959 | le32_to_cpu(np->tx_ring.ex[i+2].flaglen), |
| 1960 | le32_to_cpu(np->tx_ring.ex[i+3].bufhigh), |
| 1961 | le32_to_cpu(np->tx_ring.ex[i+3].buflow), |
| 1962 | le32_to_cpu(np->tx_ring.ex[i+3].flaglen)); |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 1963 | } |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 1964 | } |
| 1965 | } |
| 1966 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1967 | spin_lock_irq(&np->lock); |
| 1968 | |
| 1969 | /* 1) stop tx engine */ |
| 1970 | nv_stop_tx(dev); |
| 1971 | |
| 1972 | /* 2) check that the packets were not sent already: */ |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1973 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
| 1974 | nv_tx_done(dev); |
| 1975 | else |
| 1976 | nv_tx_done_optimized(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | |
| 1978 | /* 3) if there are dead entries: clear everything */ |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1979 | if (np->get_tx_ctx != np->put_tx_ctx) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1980 | printk(KERN_DEBUG "%s: tx_timeout: dead entries!\n", dev->name); |
| 1981 | nv_drain_tx(dev); |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1982 | nv_init_tx(dev); |
Ayaz Abdulla | 0832b25 | 2006-02-04 13:13:26 -0500 | [diff] [blame] | 1983 | setup_hw_rings(dev, NV_SETUP_TX_RING); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1984 | netif_wake_queue(dev); |
| 1985 | } |
| 1986 | |
| 1987 | /* 4) restart tx engine */ |
| 1988 | nv_start_tx(dev); |
| 1989 | spin_unlock_irq(&np->lock); |
| 1990 | } |
| 1991 | |
Manfred Spraul | 22c6d14 | 2005-04-19 21:17:09 +0200 | [diff] [blame] | 1992 | /* |
| 1993 | * Called when the nic notices a mismatch between the actual data len on the |
| 1994 | * wire and the len indicated in the 802 header |
| 1995 | */ |
| 1996 | static int nv_getlen(struct net_device *dev, void *packet, int datalen) |
| 1997 | { |
| 1998 | int hdrlen; /* length of the 802 header */ |
| 1999 | int protolen; /* length as stored in the proto field */ |
| 2000 | |
| 2001 | /* 1) calculate len according to header */ |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2002 | if ( ((struct vlan_ethhdr *)packet)->h_vlan_proto == htons(ETH_P_8021Q)) { |
Manfred Spraul | 22c6d14 | 2005-04-19 21:17:09 +0200 | [diff] [blame] | 2003 | protolen = ntohs( ((struct vlan_ethhdr *)packet)->h_vlan_encapsulated_proto ); |
| 2004 | hdrlen = VLAN_HLEN; |
| 2005 | } else { |
| 2006 | protolen = ntohs( ((struct ethhdr *)packet)->h_proto); |
| 2007 | hdrlen = ETH_HLEN; |
| 2008 | } |
| 2009 | dprintk(KERN_DEBUG "%s: nv_getlen: datalen %d, protolen %d, hdrlen %d\n", |
| 2010 | dev->name, datalen, protolen, hdrlen); |
| 2011 | if (protolen > ETH_DATA_LEN) |
| 2012 | return datalen; /* Value in proto field not a len, no checks possible */ |
| 2013 | |
| 2014 | protolen += hdrlen; |
| 2015 | /* consistency checks: */ |
| 2016 | if (datalen > ETH_ZLEN) { |
| 2017 | if (datalen >= protolen) { |
| 2018 | /* more data on wire than in 802 header, trim of |
| 2019 | * additional data. |
| 2020 | */ |
| 2021 | dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n", |
| 2022 | dev->name, protolen); |
| 2023 | return protolen; |
| 2024 | } else { |
| 2025 | /* less data on wire than mentioned in header. |
| 2026 | * Discard the packet. |
| 2027 | */ |
| 2028 | dprintk(KERN_DEBUG "%s: nv_getlen: discarding long packet.\n", |
| 2029 | dev->name); |
| 2030 | return -1; |
| 2031 | } |
| 2032 | } else { |
| 2033 | /* short packet. Accept only if 802 values are also short */ |
| 2034 | if (protolen > ETH_ZLEN) { |
| 2035 | dprintk(KERN_DEBUG "%s: nv_getlen: discarding short packet.\n", |
| 2036 | dev->name); |
| 2037 | return -1; |
| 2038 | } |
| 2039 | dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n", |
| 2040 | dev->name, datalen); |
| 2041 | return datalen; |
| 2042 | } |
| 2043 | } |
| 2044 | |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 2045 | static int nv_rx_process(struct net_device *dev, int limit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2046 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2047 | struct fe_priv *np = netdev_priv(dev); |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2048 | u32 flags; |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 2049 | u32 vlanflags = 0; |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 2050 | int count; |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 2051 | |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2052 | for (count = 0; count < limit; ++count) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2053 | struct sk_buff *skb; |
| 2054 | int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2055 | |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2056 | if (np->get_rx.orig == np->put_rx.orig) |
| 2057 | break; /* we scanned the whole ring - do not continue */ |
| 2058 | flags = le32_to_cpu(np->get_rx.orig->flaglen); |
| 2059 | len = nv_descr_getlength(np->get_rx.orig, np->desc_ver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2060 | |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2061 | dprintk(KERN_DEBUG "%s: nv_rx_process: flags 0x%x.\n", |
| 2062 | dev->name, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2063 | |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2064 | if (flags & NV_RX_AVAIL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2065 | break; /* still owned by hardware, */ |
| 2066 | |
| 2067 | /* |
| 2068 | * the packet is for us - immediately tear down the pci mapping. |
| 2069 | * TODO: check if a prefetch of the first cacheline improves |
| 2070 | * the performance. |
| 2071 | */ |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2072 | pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma, |
| 2073 | np->get_rx_ctx->dma_len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2074 | PCI_DMA_FROMDEVICE); |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 2075 | skb = np->get_rx_ctx->skb; |
| 2076 | np->get_rx_ctx->skb = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2077 | |
| 2078 | { |
| 2079 | int j; |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2080 | dprintk(KERN_DEBUG "Dumping packet (flags 0x%x).",flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2081 | for (j=0; j<64; j++) { |
| 2082 | if ((j%16) == 0) |
| 2083 | dprintk("\n%03x:", j); |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 2084 | dprintk(" %02x", ((unsigned char*)skb->data)[j]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2085 | } |
| 2086 | dprintk("\n"); |
| 2087 | } |
| 2088 | /* look at what we actually got: */ |
| 2089 | if (np->desc_ver == DESC_VER_1) { |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 2090 | if (!(flags & NV_RX_DESCRIPTORVALID)) { |
| 2091 | dev_kfree_skb(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2092 | goto next_pkt; |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 2093 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2094 | |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2095 | if (flags & NV_RX_ERROR) { |
| 2096 | if (flags & NV_RX_MISSEDFRAME) { |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2097 | np->stats.rx_missed_errors++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2098 | np->stats.rx_errors++; |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 2099 | dev_kfree_skb(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2100 | goto next_pkt; |
| 2101 | } |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2102 | if (flags & (NV_RX_ERROR1|NV_RX_ERROR2|NV_RX_ERROR3)) { |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2103 | np->stats.rx_errors++; |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 2104 | dev_kfree_skb(skb); |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2105 | goto next_pkt; |
| 2106 | } |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2107 | if (flags & NV_RX_CRCERR) { |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2108 | np->stats.rx_crc_errors++; |
| 2109 | np->stats.rx_errors++; |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 2110 | dev_kfree_skb(skb); |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2111 | goto next_pkt; |
| 2112 | } |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2113 | if (flags & NV_RX_OVERFLOW) { |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2114 | np->stats.rx_over_errors++; |
| 2115 | np->stats.rx_errors++; |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 2116 | dev_kfree_skb(skb); |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2117 | goto next_pkt; |
| 2118 | } |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2119 | if (flags & NV_RX_ERROR4) { |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 2120 | len = nv_getlen(dev, skb->data, len); |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2121 | if (len < 0) { |
| 2122 | np->stats.rx_errors++; |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 2123 | dev_kfree_skb(skb); |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2124 | goto next_pkt; |
| 2125 | } |
| 2126 | } |
| 2127 | /* framing errors are soft errors. */ |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2128 | if (flags & NV_RX_FRAMINGERR) { |
| 2129 | if (flags & NV_RX_SUBSTRACT1) { |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2130 | len--; |
| 2131 | } |
Manfred Spraul | 22c6d14 | 2005-04-19 21:17:09 +0200 | [diff] [blame] | 2132 | } |
| 2133 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2134 | } else { |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 2135 | if (!(flags & NV_RX2_DESCRIPTORVALID)) { |
| 2136 | dev_kfree_skb(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2137 | goto next_pkt; |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 2138 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2139 | |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2140 | if (flags & NV_RX2_ERROR) { |
| 2141 | if (flags & (NV_RX2_ERROR1|NV_RX2_ERROR2|NV_RX2_ERROR3)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2142 | np->stats.rx_errors++; |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 2143 | dev_kfree_skb(skb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2144 | goto next_pkt; |
| 2145 | } |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2146 | if (flags & NV_RX2_CRCERR) { |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2147 | np->stats.rx_crc_errors++; |
| 2148 | np->stats.rx_errors++; |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 2149 | dev_kfree_skb(skb); |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2150 | goto next_pkt; |
| 2151 | } |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2152 | if (flags & NV_RX2_OVERFLOW) { |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2153 | np->stats.rx_over_errors++; |
| 2154 | np->stats.rx_errors++; |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 2155 | dev_kfree_skb(skb); |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2156 | goto next_pkt; |
| 2157 | } |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2158 | if (flags & NV_RX2_ERROR4) { |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 2159 | len = nv_getlen(dev, skb->data, len); |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2160 | if (len < 0) { |
| 2161 | np->stats.rx_errors++; |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 2162 | dev_kfree_skb(skb); |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2163 | goto next_pkt; |
| 2164 | } |
| 2165 | } |
| 2166 | /* framing errors are soft errors */ |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2167 | if (flags & NV_RX2_FRAMINGERR) { |
| 2168 | if (flags & NV_RX2_SUBSTRACT1) { |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2169 | len--; |
| 2170 | } |
Manfred Spraul | 22c6d14 | 2005-04-19 21:17:09 +0200 | [diff] [blame] | 2171 | } |
| 2172 | } |
Ayaz Abdulla | f2ad2d9 | 2006-08-24 17:35:41 -0400 | [diff] [blame] | 2173 | if (np->rx_csum) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2174 | flags &= NV_RX2_CHECKSUMMASK; |
| 2175 | if (flags == NV_RX2_CHECKSUMOK1 || |
| 2176 | flags == NV_RX2_CHECKSUMOK2 || |
| 2177 | flags == NV_RX2_CHECKSUMOK3) { |
Ayaz Abdulla | 5ed2616 | 2006-06-10 22:47:59 -0400 | [diff] [blame] | 2178 | dprintk(KERN_DEBUG "%s: hw checksum hit!.\n", dev->name); |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 2179 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Ayaz Abdulla | 5ed2616 | 2006-06-10 22:47:59 -0400 | [diff] [blame] | 2180 | } else { |
| 2181 | dprintk(KERN_DEBUG "%s: hwchecksum miss!.\n", dev->name); |
| 2182 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2183 | } |
| 2184 | } |
| 2185 | /* got a valid packet - forward it to the network core */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2186 | skb_put(skb, len); |
| 2187 | skb->protocol = eth_type_trans(skb, dev); |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2188 | dprintk(KERN_DEBUG "%s: nv_rx_process: %d bytes, proto %d accepted.\n", |
| 2189 | dev->name, len, skb->protocol); |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 2190 | #ifdef CONFIG_FORCEDETH_NAPI |
| 2191 | if (np->vlangrp && (vlanflags & NV_RX3_VLAN_TAG_PRESENT)) |
| 2192 | vlan_hwaccel_receive_skb(skb, np->vlangrp, |
| 2193 | vlanflags & NV_RX3_VLAN_TAG_MASK); |
| 2194 | else |
| 2195 | netif_receive_skb(skb); |
| 2196 | #else |
| 2197 | if (np->vlangrp && (vlanflags & NV_RX3_VLAN_TAG_PRESENT)) |
| 2198 | vlan_hwaccel_rx(skb, np->vlangrp, |
| 2199 | vlanflags & NV_RX3_VLAN_TAG_MASK); |
| 2200 | else |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 2201 | netif_rx(skb); |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 2202 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2203 | dev->last_rx = jiffies; |
| 2204 | np->stats.rx_packets++; |
| 2205 | np->stats.rx_bytes += len; |
| 2206 | next_pkt: |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2207 | if (np->get_rx.orig++ == np->last_rx.orig) |
| 2208 | np->get_rx.orig = np->first_rx.orig; |
| 2209 | if (np->get_rx_ctx++ == np->last_rx_ctx) |
| 2210 | np->get_rx_ctx = np->first_rx_ctx; |
| 2211 | } |
| 2212 | |
| 2213 | return count; |
| 2214 | } |
| 2215 | |
| 2216 | static int nv_rx_process_optimized(struct net_device *dev, int limit) |
| 2217 | { |
| 2218 | struct fe_priv *np = netdev_priv(dev); |
| 2219 | u32 flags; |
| 2220 | u32 vlanflags = 0; |
| 2221 | int count; |
| 2222 | |
| 2223 | for (count = 0; count < limit; ++count) { |
| 2224 | struct sk_buff *skb; |
| 2225 | int len; |
| 2226 | |
| 2227 | if (np->get_rx.ex == np->put_rx.ex) |
| 2228 | break; /* we scanned the whole ring - do not continue */ |
| 2229 | flags = le32_to_cpu(np->get_rx.ex->flaglen); |
| 2230 | len = nv_descr_getlength_ex(np->get_rx.ex, np->desc_ver); |
| 2231 | vlanflags = le32_to_cpu(np->get_rx.ex->buflow); |
| 2232 | |
| 2233 | dprintk(KERN_DEBUG "%s: nv_rx_process_optimized: flags 0x%x.\n", |
| 2234 | dev->name, flags); |
| 2235 | |
| 2236 | if (flags & NV_RX_AVAIL) |
| 2237 | break; /* still owned by hardware, */ |
| 2238 | |
| 2239 | /* |
| 2240 | * the packet is for us - immediately tear down the pci mapping. |
| 2241 | * TODO: check if a prefetch of the first cacheline improves |
| 2242 | * the performance. |
| 2243 | */ |
| 2244 | pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma, |
| 2245 | np->get_rx_ctx->dma_len, |
| 2246 | PCI_DMA_FROMDEVICE); |
| 2247 | skb = np->get_rx_ctx->skb; |
| 2248 | np->get_rx_ctx->skb = NULL; |
| 2249 | |
| 2250 | { |
| 2251 | int j; |
| 2252 | dprintk(KERN_DEBUG "Dumping packet (flags 0x%x).",flags); |
| 2253 | for (j=0; j<64; j++) { |
| 2254 | if ((j%16) == 0) |
| 2255 | dprintk("\n%03x:", j); |
| 2256 | dprintk(" %02x", ((unsigned char*)skb->data)[j]); |
| 2257 | } |
| 2258 | dprintk("\n"); |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2259 | } |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2260 | /* look at what we actually got: */ |
| 2261 | if (!(flags & NV_RX2_DESCRIPTORVALID)) { |
| 2262 | dev_kfree_skb(skb); |
| 2263 | goto next_pkt; |
| 2264 | } |
| 2265 | |
| 2266 | if (flags & NV_RX2_ERROR) { |
| 2267 | if (flags & (NV_RX2_ERROR1|NV_RX2_ERROR2|NV_RX2_ERROR3)) { |
| 2268 | np->stats.rx_errors++; |
| 2269 | dev_kfree_skb(skb); |
| 2270 | goto next_pkt; |
| 2271 | } |
| 2272 | if (flags & NV_RX2_CRCERR) { |
| 2273 | np->stats.rx_crc_errors++; |
| 2274 | np->stats.rx_errors++; |
| 2275 | dev_kfree_skb(skb); |
| 2276 | goto next_pkt; |
| 2277 | } |
| 2278 | if (flags & NV_RX2_OVERFLOW) { |
| 2279 | np->stats.rx_over_errors++; |
| 2280 | np->stats.rx_errors++; |
| 2281 | dev_kfree_skb(skb); |
| 2282 | goto next_pkt; |
| 2283 | } |
| 2284 | if (flags & NV_RX2_ERROR4) { |
| 2285 | len = nv_getlen(dev, skb->data, len); |
| 2286 | if (len < 0) { |
| 2287 | np->stats.rx_errors++; |
| 2288 | dev_kfree_skb(skb); |
| 2289 | goto next_pkt; |
| 2290 | } |
| 2291 | } |
| 2292 | /* framing errors are soft errors */ |
| 2293 | if (flags & NV_RX2_FRAMINGERR) { |
| 2294 | if (flags & NV_RX2_SUBSTRACT1) { |
| 2295 | len--; |
| 2296 | } |
| 2297 | } |
| 2298 | } |
| 2299 | if (np->rx_csum) { |
| 2300 | flags &= NV_RX2_CHECKSUMMASK; |
| 2301 | if (flags == NV_RX2_CHECKSUMOK1 || |
| 2302 | flags == NV_RX2_CHECKSUMOK2 || |
| 2303 | flags == NV_RX2_CHECKSUMOK3) { |
| 2304 | dprintk(KERN_DEBUG "%s: hw checksum hit!.\n", dev->name); |
| 2305 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
| 2306 | } else { |
| 2307 | dprintk(KERN_DEBUG "%s: hwchecksum miss!.\n", dev->name); |
| 2308 | } |
| 2309 | } |
| 2310 | /* got a valid packet - forward it to the network core */ |
| 2311 | skb_put(skb, len); |
| 2312 | skb->protocol = eth_type_trans(skb, dev); |
| 2313 | dprintk(KERN_DEBUG "%s: nv_rx_process: %d bytes, proto %d accepted.\n", |
| 2314 | dev->name, len, skb->protocol); |
| 2315 | #ifdef CONFIG_FORCEDETH_NAPI |
| 2316 | if (np->vlangrp && (vlanflags & NV_RX3_VLAN_TAG_PRESENT)) |
| 2317 | vlan_hwaccel_receive_skb(skb, np->vlangrp, |
| 2318 | vlanflags & NV_RX3_VLAN_TAG_MASK); |
| 2319 | else |
| 2320 | netif_receive_skb(skb); |
| 2321 | #else |
| 2322 | if (np->vlangrp && (vlanflags & NV_RX3_VLAN_TAG_PRESENT)) |
| 2323 | vlan_hwaccel_rx(skb, np->vlangrp, |
| 2324 | vlanflags & NV_RX3_VLAN_TAG_MASK); |
| 2325 | else |
| 2326 | netif_rx(skb); |
| 2327 | #endif |
| 2328 | dev->last_rx = jiffies; |
| 2329 | np->stats.rx_packets++; |
| 2330 | np->stats.rx_bytes += len; |
| 2331 | next_pkt: |
| 2332 | if (np->get_rx.ex++ == np->last_rx.ex) |
| 2333 | np->get_rx.ex = np->first_rx.ex; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2334 | if (np->get_rx_ctx++ == np->last_rx_ctx) |
| 2335 | np->get_rx_ctx = np->first_rx_ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2336 | } |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 2337 | |
| 2338 | return count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2339 | } |
| 2340 | |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 2341 | static void set_bufsize(struct net_device *dev) |
| 2342 | { |
| 2343 | struct fe_priv *np = netdev_priv(dev); |
| 2344 | |
| 2345 | if (dev->mtu <= ETH_DATA_LEN) |
| 2346 | np->rx_buf_sz = ETH_DATA_LEN + NV_RX_HEADERS; |
| 2347 | else |
| 2348 | np->rx_buf_sz = dev->mtu + NV_RX_HEADERS; |
| 2349 | } |
| 2350 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2351 | /* |
| 2352 | * nv_change_mtu: dev->change_mtu function |
| 2353 | * Called with dev_base_lock held for read. |
| 2354 | */ |
| 2355 | static int nv_change_mtu(struct net_device *dev, int new_mtu) |
| 2356 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2357 | struct fe_priv *np = netdev_priv(dev); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 2358 | int old_mtu; |
| 2359 | |
| 2360 | if (new_mtu < 64 || new_mtu > np->pkt_limit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2361 | return -EINVAL; |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 2362 | |
| 2363 | old_mtu = dev->mtu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2364 | dev->mtu = new_mtu; |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 2365 | |
| 2366 | /* return early if the buffer sizes will not change */ |
| 2367 | if (old_mtu <= ETH_DATA_LEN && new_mtu <= ETH_DATA_LEN) |
| 2368 | return 0; |
| 2369 | if (old_mtu == new_mtu) |
| 2370 | return 0; |
| 2371 | |
| 2372 | /* synchronized against open : rtnl_lock() held by caller */ |
| 2373 | if (netif_running(dev)) { |
viro@ftp.linux.org.uk | 25097d4 | 2005-09-06 01:36:58 +0100 | [diff] [blame] | 2374 | u8 __iomem *base = get_hwbase(dev); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 2375 | /* |
| 2376 | * It seems that the nic preloads valid ring entries into an |
| 2377 | * internal buffer. The procedure for flushing everything is |
| 2378 | * guessed, there is probably a simpler approach. |
| 2379 | * Changing the MTU is a rare event, it shouldn't matter. |
| 2380 | */ |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 2381 | nv_disable_irq(dev); |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 2382 | netif_tx_lock_bh(dev); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 2383 | spin_lock(&np->lock); |
| 2384 | /* stop engines */ |
| 2385 | nv_stop_rx(dev); |
| 2386 | nv_stop_tx(dev); |
| 2387 | nv_txrx_reset(dev); |
| 2388 | /* drain rx queue */ |
| 2389 | nv_drain_rx(dev); |
| 2390 | nv_drain_tx(dev); |
| 2391 | /* reinit driver view of the rx queue */ |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 2392 | set_bufsize(dev); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 2393 | if (nv_init_ring(dev)) { |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 2394 | if (!np->in_shutdown) |
| 2395 | mod_timer(&np->oom_kick, jiffies + OOM_REFILL); |
| 2396 | } |
| 2397 | /* reinit nic view of the rx queue */ |
| 2398 | writel(np->rx_buf_sz, base + NvRegOffloadConfig); |
Ayaz Abdulla | 0832b25 | 2006-02-04 13:13:26 -0500 | [diff] [blame] | 2399 | setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 2400 | writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT), |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 2401 | base + NvRegRingSizes); |
| 2402 | pci_push(base); |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 2403 | writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 2404 | pci_push(base); |
| 2405 | |
| 2406 | /* restart rx engine */ |
| 2407 | nv_start_rx(dev); |
| 2408 | nv_start_tx(dev); |
| 2409 | spin_unlock(&np->lock); |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 2410 | netif_tx_unlock_bh(dev); |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 2411 | nv_enable_irq(dev); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 2412 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2413 | return 0; |
| 2414 | } |
| 2415 | |
Manfred Spraul | 72b3178 | 2005-07-31 18:33:34 +0200 | [diff] [blame] | 2416 | static void nv_copy_mac_to_hw(struct net_device *dev) |
| 2417 | { |
viro@ftp.linux.org.uk | 25097d4 | 2005-09-06 01:36:58 +0100 | [diff] [blame] | 2418 | u8 __iomem *base = get_hwbase(dev); |
Manfred Spraul | 72b3178 | 2005-07-31 18:33:34 +0200 | [diff] [blame] | 2419 | u32 mac[2]; |
| 2420 | |
| 2421 | mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) + |
| 2422 | (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24); |
| 2423 | mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8); |
| 2424 | |
| 2425 | writel(mac[0], base + NvRegMacAddrA); |
| 2426 | writel(mac[1], base + NvRegMacAddrB); |
| 2427 | } |
| 2428 | |
| 2429 | /* |
| 2430 | * nv_set_mac_address: dev->set_mac_address function |
| 2431 | * Called with rtnl_lock() held. |
| 2432 | */ |
| 2433 | static int nv_set_mac_address(struct net_device *dev, void *addr) |
| 2434 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2435 | struct fe_priv *np = netdev_priv(dev); |
Manfred Spraul | 72b3178 | 2005-07-31 18:33:34 +0200 | [diff] [blame] | 2436 | struct sockaddr *macaddr = (struct sockaddr*)addr; |
| 2437 | |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2438 | if (!is_valid_ether_addr(macaddr->sa_data)) |
Manfred Spraul | 72b3178 | 2005-07-31 18:33:34 +0200 | [diff] [blame] | 2439 | return -EADDRNOTAVAIL; |
| 2440 | |
| 2441 | /* synchronized against open : rtnl_lock() held by caller */ |
| 2442 | memcpy(dev->dev_addr, macaddr->sa_data, ETH_ALEN); |
| 2443 | |
| 2444 | if (netif_running(dev)) { |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 2445 | netif_tx_lock_bh(dev); |
Manfred Spraul | 72b3178 | 2005-07-31 18:33:34 +0200 | [diff] [blame] | 2446 | spin_lock_irq(&np->lock); |
| 2447 | |
| 2448 | /* stop rx engine */ |
| 2449 | nv_stop_rx(dev); |
| 2450 | |
| 2451 | /* set mac address */ |
| 2452 | nv_copy_mac_to_hw(dev); |
| 2453 | |
| 2454 | /* restart rx engine */ |
| 2455 | nv_start_rx(dev); |
| 2456 | spin_unlock_irq(&np->lock); |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 2457 | netif_tx_unlock_bh(dev); |
Manfred Spraul | 72b3178 | 2005-07-31 18:33:34 +0200 | [diff] [blame] | 2458 | } else { |
| 2459 | nv_copy_mac_to_hw(dev); |
| 2460 | } |
| 2461 | return 0; |
| 2462 | } |
| 2463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2464 | /* |
| 2465 | * nv_set_multicast: dev->set_multicast function |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 2466 | * Called with netif_tx_lock held. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2467 | */ |
| 2468 | static void nv_set_multicast(struct net_device *dev) |
| 2469 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2470 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2471 | u8 __iomem *base = get_hwbase(dev); |
| 2472 | u32 addr[2]; |
| 2473 | u32 mask[2]; |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 2474 | u32 pff = readl(base + NvRegPacketFilterFlags) & NVREG_PFF_PAUSE_RX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2475 | |
| 2476 | memset(addr, 0, sizeof(addr)); |
| 2477 | memset(mask, 0, sizeof(mask)); |
| 2478 | |
| 2479 | if (dev->flags & IFF_PROMISC) { |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 2480 | pff |= NVREG_PFF_PROMISC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2481 | } else { |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 2482 | pff |= NVREG_PFF_MYADDR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2483 | |
| 2484 | if (dev->flags & IFF_ALLMULTI || dev->mc_list) { |
| 2485 | u32 alwaysOff[2]; |
| 2486 | u32 alwaysOn[2]; |
| 2487 | |
| 2488 | alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0xffffffff; |
| 2489 | if (dev->flags & IFF_ALLMULTI) { |
| 2490 | alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0; |
| 2491 | } else { |
| 2492 | struct dev_mc_list *walk; |
| 2493 | |
| 2494 | walk = dev->mc_list; |
| 2495 | while (walk != NULL) { |
| 2496 | u32 a, b; |
| 2497 | a = le32_to_cpu(*(u32 *) walk->dmi_addr); |
| 2498 | b = le16_to_cpu(*(u16 *) (&walk->dmi_addr[4])); |
| 2499 | alwaysOn[0] &= a; |
| 2500 | alwaysOff[0] &= ~a; |
| 2501 | alwaysOn[1] &= b; |
| 2502 | alwaysOff[1] &= ~b; |
| 2503 | walk = walk->next; |
| 2504 | } |
| 2505 | } |
| 2506 | addr[0] = alwaysOn[0]; |
| 2507 | addr[1] = alwaysOn[1]; |
| 2508 | mask[0] = alwaysOn[0] | alwaysOff[0]; |
| 2509 | mask[1] = alwaysOn[1] | alwaysOff[1]; |
| 2510 | } |
| 2511 | } |
| 2512 | addr[0] |= NVREG_MCASTADDRA_FORCE; |
| 2513 | pff |= NVREG_PFF_ALWAYS; |
| 2514 | spin_lock_irq(&np->lock); |
| 2515 | nv_stop_rx(dev); |
| 2516 | writel(addr[0], base + NvRegMulticastAddrA); |
| 2517 | writel(addr[1], base + NvRegMulticastAddrB); |
| 2518 | writel(mask[0], base + NvRegMulticastMaskA); |
| 2519 | writel(mask[1], base + NvRegMulticastMaskB); |
| 2520 | writel(pff, base + NvRegPacketFilterFlags); |
| 2521 | dprintk(KERN_INFO "%s: reconfiguration for multicast lists.\n", |
| 2522 | dev->name); |
| 2523 | nv_start_rx(dev); |
| 2524 | spin_unlock_irq(&np->lock); |
| 2525 | } |
| 2526 | |
Adrian Bunk | c798505 | 2006-06-22 12:03:29 +0200 | [diff] [blame] | 2527 | static void nv_update_pause(struct net_device *dev, u32 pause_flags) |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 2528 | { |
| 2529 | struct fe_priv *np = netdev_priv(dev); |
| 2530 | u8 __iomem *base = get_hwbase(dev); |
| 2531 | |
| 2532 | np->pause_flags &= ~(NV_PAUSEFRAME_TX_ENABLE | NV_PAUSEFRAME_RX_ENABLE); |
| 2533 | |
| 2534 | if (np->pause_flags & NV_PAUSEFRAME_RX_CAPABLE) { |
| 2535 | u32 pff = readl(base + NvRegPacketFilterFlags) & ~NVREG_PFF_PAUSE_RX; |
| 2536 | if (pause_flags & NV_PAUSEFRAME_RX_ENABLE) { |
| 2537 | writel(pff|NVREG_PFF_PAUSE_RX, base + NvRegPacketFilterFlags); |
| 2538 | np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE; |
| 2539 | } else { |
| 2540 | writel(pff, base + NvRegPacketFilterFlags); |
| 2541 | } |
| 2542 | } |
| 2543 | if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE) { |
| 2544 | u32 regmisc = readl(base + NvRegMisc1) & ~NVREG_MISC1_PAUSE_TX; |
| 2545 | if (pause_flags & NV_PAUSEFRAME_TX_ENABLE) { |
| 2546 | writel(NVREG_TX_PAUSEFRAME_ENABLE, base + NvRegTxPauseFrame); |
| 2547 | writel(regmisc|NVREG_MISC1_PAUSE_TX, base + NvRegMisc1); |
| 2548 | np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE; |
| 2549 | } else { |
| 2550 | writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame); |
| 2551 | writel(regmisc, base + NvRegMisc1); |
| 2552 | } |
| 2553 | } |
| 2554 | } |
| 2555 | |
Ayaz Abdulla | 4ea7f29 | 2005-11-11 08:29:59 -0500 | [diff] [blame] | 2556 | /** |
| 2557 | * nv_update_linkspeed: Setup the MAC according to the link partner |
| 2558 | * @dev: Network device to be configured |
| 2559 | * |
| 2560 | * The function queries the PHY and checks if there is a link partner. |
| 2561 | * If yes, then it sets up the MAC accordingly. Otherwise, the MAC is |
| 2562 | * set to 10 MBit HD. |
| 2563 | * |
| 2564 | * The function returns 0 if there is no link partner and 1 if there is |
| 2565 | * a good link partner. |
| 2566 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2567 | static int nv_update_linkspeed(struct net_device *dev) |
| 2568 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2569 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2570 | u8 __iomem *base = get_hwbase(dev); |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 2571 | int adv = 0; |
| 2572 | int lpa = 0; |
| 2573 | int adv_lpa, adv_pause, lpa_pause; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2574 | int newls = np->linkspeed; |
| 2575 | int newdup = np->duplex; |
| 2576 | int mii_status; |
| 2577 | int retval = 0; |
Ayaz Abdulla | 9744e21 | 2006-07-06 16:45:58 -0400 | [diff] [blame] | 2578 | u32 control_1000, status_1000, phyreg, pause_flags, txreg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | |
| 2580 | /* BMSR_LSTATUS is latched, read it twice: |
| 2581 | * we want the current value. |
| 2582 | */ |
| 2583 | mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ); |
| 2584 | mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ); |
| 2585 | |
| 2586 | if (!(mii_status & BMSR_LSTATUS)) { |
| 2587 | dprintk(KERN_DEBUG "%s: no link detected by phy - falling back to 10HD.\n", |
| 2588 | dev->name); |
| 2589 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 2590 | newdup = 0; |
| 2591 | retval = 0; |
| 2592 | goto set_speed; |
| 2593 | } |
| 2594 | |
| 2595 | if (np->autoneg == 0) { |
| 2596 | dprintk(KERN_DEBUG "%s: nv_update_linkspeed: autoneg off, PHY set to 0x%04x.\n", |
| 2597 | dev->name, np->fixed_mode); |
| 2598 | if (np->fixed_mode & LPA_100FULL) { |
| 2599 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100; |
| 2600 | newdup = 1; |
| 2601 | } else if (np->fixed_mode & LPA_100HALF) { |
| 2602 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100; |
| 2603 | newdup = 0; |
| 2604 | } else if (np->fixed_mode & LPA_10FULL) { |
| 2605 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 2606 | newdup = 1; |
| 2607 | } else { |
| 2608 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 2609 | newdup = 0; |
| 2610 | } |
| 2611 | retval = 1; |
| 2612 | goto set_speed; |
| 2613 | } |
| 2614 | /* check auto negotiation is complete */ |
| 2615 | if (!(mii_status & BMSR_ANEGCOMPLETE)) { |
| 2616 | /* still in autonegotiation - configure nic for 10 MBit HD and wait. */ |
| 2617 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 2618 | newdup = 0; |
| 2619 | retval = 0; |
| 2620 | dprintk(KERN_DEBUG "%s: autoneg not completed - falling back to 10HD.\n", dev->name); |
| 2621 | goto set_speed; |
| 2622 | } |
| 2623 | |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 2624 | adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ); |
| 2625 | lpa = mii_rw(dev, np->phyaddr, MII_LPA, MII_READ); |
| 2626 | dprintk(KERN_DEBUG "%s: nv_update_linkspeed: PHY advertises 0x%04x, lpa 0x%04x.\n", |
| 2627 | dev->name, adv, lpa); |
| 2628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2629 | retval = 1; |
| 2630 | if (np->gigabit == PHY_GIGABIT) { |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 2631 | control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ); |
| 2632 | status_1000 = mii_rw(dev, np->phyaddr, MII_STAT1000, MII_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2633 | |
| 2634 | if ((control_1000 & ADVERTISE_1000FULL) && |
| 2635 | (status_1000 & LPA_1000FULL)) { |
| 2636 | dprintk(KERN_DEBUG "%s: nv_update_linkspeed: GBit ethernet detected.\n", |
| 2637 | dev->name); |
| 2638 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_1000; |
| 2639 | newdup = 1; |
| 2640 | goto set_speed; |
| 2641 | } |
| 2642 | } |
| 2643 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2644 | /* FIXME: handle parallel detection properly */ |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 2645 | adv_lpa = lpa & adv; |
| 2646 | if (adv_lpa & LPA_100FULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2647 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100; |
| 2648 | newdup = 1; |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 2649 | } else if (adv_lpa & LPA_100HALF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2650 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100; |
| 2651 | newdup = 0; |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 2652 | } else if (adv_lpa & LPA_10FULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 2654 | newdup = 1; |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 2655 | } else if (adv_lpa & LPA_10HALF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2656 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 2657 | newdup = 0; |
| 2658 | } else { |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 2659 | dprintk(KERN_DEBUG "%s: bad ability %04x - falling back to 10HD.\n", dev->name, adv_lpa); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2660 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 2661 | newdup = 0; |
| 2662 | } |
| 2663 | |
| 2664 | set_speed: |
| 2665 | if (np->duplex == newdup && np->linkspeed == newls) |
| 2666 | return retval; |
| 2667 | |
| 2668 | dprintk(KERN_INFO "%s: changing link setting from %d/%d to %d/%d.\n", |
| 2669 | dev->name, np->linkspeed, np->duplex, newls, newdup); |
| 2670 | |
| 2671 | np->duplex = newdup; |
| 2672 | np->linkspeed = newls; |
| 2673 | |
| 2674 | if (np->gigabit == PHY_GIGABIT) { |
| 2675 | phyreg = readl(base + NvRegRandomSeed); |
| 2676 | phyreg &= ~(0x3FF00); |
| 2677 | if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10) |
| 2678 | phyreg |= NVREG_RNDSEED_FORCE3; |
| 2679 | else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100) |
| 2680 | phyreg |= NVREG_RNDSEED_FORCE2; |
| 2681 | else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000) |
| 2682 | phyreg |= NVREG_RNDSEED_FORCE; |
| 2683 | writel(phyreg, base + NvRegRandomSeed); |
| 2684 | } |
| 2685 | |
| 2686 | phyreg = readl(base + NvRegPhyInterface); |
| 2687 | phyreg &= ~(PHY_HALF|PHY_100|PHY_1000); |
| 2688 | if (np->duplex == 0) |
| 2689 | phyreg |= PHY_HALF; |
| 2690 | if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100) |
| 2691 | phyreg |= PHY_100; |
| 2692 | else if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000) |
| 2693 | phyreg |= PHY_1000; |
| 2694 | writel(phyreg, base + NvRegPhyInterface); |
| 2695 | |
Ayaz Abdulla | 9744e21 | 2006-07-06 16:45:58 -0400 | [diff] [blame] | 2696 | if (phyreg & PHY_RGMII) { |
| 2697 | if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000) |
| 2698 | txreg = NVREG_TX_DEFERRAL_RGMII_1000; |
| 2699 | else |
| 2700 | txreg = NVREG_TX_DEFERRAL_RGMII_10_100; |
| 2701 | } else { |
| 2702 | txreg = NVREG_TX_DEFERRAL_DEFAULT; |
| 2703 | } |
| 2704 | writel(txreg, base + NvRegTxDeferral); |
| 2705 | |
Ayaz Abdulla | 95d161c | 2006-07-06 16:46:25 -0400 | [diff] [blame] | 2706 | if (np->desc_ver == DESC_VER_1) { |
| 2707 | txreg = NVREG_TX_WM_DESC1_DEFAULT; |
| 2708 | } else { |
| 2709 | if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000) |
| 2710 | txreg = NVREG_TX_WM_DESC2_3_1000; |
| 2711 | else |
| 2712 | txreg = NVREG_TX_WM_DESC2_3_DEFAULT; |
| 2713 | } |
| 2714 | writel(txreg, base + NvRegTxWatermark); |
| 2715 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2716 | writel(NVREG_MISC1_FORCE | ( np->duplex ? 0 : NVREG_MISC1_HD), |
| 2717 | base + NvRegMisc1); |
| 2718 | pci_push(base); |
| 2719 | writel(np->linkspeed, base + NvRegLinkSpeed); |
| 2720 | pci_push(base); |
| 2721 | |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 2722 | pause_flags = 0; |
| 2723 | /* setup pause frame */ |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 2724 | if (np->duplex != 0) { |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 2725 | if (np->autoneg && np->pause_flags & NV_PAUSEFRAME_AUTONEG) { |
| 2726 | adv_pause = adv & (ADVERTISE_PAUSE_CAP| ADVERTISE_PAUSE_ASYM); |
| 2727 | lpa_pause = lpa & (LPA_PAUSE_CAP| LPA_PAUSE_ASYM); |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 2728 | |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 2729 | switch (adv_pause) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2730 | case ADVERTISE_PAUSE_CAP: |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 2731 | if (lpa_pause & LPA_PAUSE_CAP) { |
| 2732 | pause_flags |= NV_PAUSEFRAME_RX_ENABLE; |
| 2733 | if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) |
| 2734 | pause_flags |= NV_PAUSEFRAME_TX_ENABLE; |
| 2735 | } |
| 2736 | break; |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2737 | case ADVERTISE_PAUSE_ASYM: |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 2738 | if (lpa_pause == (LPA_PAUSE_CAP| LPA_PAUSE_ASYM)) |
| 2739 | { |
| 2740 | pause_flags |= NV_PAUSEFRAME_TX_ENABLE; |
| 2741 | } |
| 2742 | break; |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2743 | case ADVERTISE_PAUSE_CAP| ADVERTISE_PAUSE_ASYM: |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 2744 | if (lpa_pause & LPA_PAUSE_CAP) |
| 2745 | { |
| 2746 | pause_flags |= NV_PAUSEFRAME_RX_ENABLE; |
| 2747 | if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) |
| 2748 | pause_flags |= NV_PAUSEFRAME_TX_ENABLE; |
| 2749 | } |
| 2750 | if (lpa_pause == LPA_PAUSE_ASYM) |
| 2751 | { |
| 2752 | pause_flags |= NV_PAUSEFRAME_RX_ENABLE; |
| 2753 | } |
| 2754 | break; |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 2755 | } |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 2756 | } else { |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 2757 | pause_flags = np->pause_flags; |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 2758 | } |
| 2759 | } |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 2760 | nv_update_pause(dev, pause_flags); |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 2761 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2762 | return retval; |
| 2763 | } |
| 2764 | |
| 2765 | static void nv_linkchange(struct net_device *dev) |
| 2766 | { |
| 2767 | if (nv_update_linkspeed(dev)) { |
Ayaz Abdulla | 4ea7f29 | 2005-11-11 08:29:59 -0500 | [diff] [blame] | 2768 | if (!netif_carrier_ok(dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2769 | netif_carrier_on(dev); |
| 2770 | printk(KERN_INFO "%s: link up.\n", dev->name); |
Ayaz Abdulla | 4ea7f29 | 2005-11-11 08:29:59 -0500 | [diff] [blame] | 2771 | nv_start_rx(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2772 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2773 | } else { |
| 2774 | if (netif_carrier_ok(dev)) { |
| 2775 | netif_carrier_off(dev); |
| 2776 | printk(KERN_INFO "%s: link down.\n", dev->name); |
| 2777 | nv_stop_rx(dev); |
| 2778 | } |
| 2779 | } |
| 2780 | } |
| 2781 | |
| 2782 | static void nv_link_irq(struct net_device *dev) |
| 2783 | { |
| 2784 | u8 __iomem *base = get_hwbase(dev); |
| 2785 | u32 miistat; |
| 2786 | |
| 2787 | miistat = readl(base + NvRegMIIStatus); |
| 2788 | writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus); |
| 2789 | dprintk(KERN_INFO "%s: link change irq, status 0x%x.\n", dev->name, miistat); |
| 2790 | |
| 2791 | if (miistat & (NVREG_MIISTAT_LINKCHANGE)) |
| 2792 | nv_linkchange(dev); |
| 2793 | dprintk(KERN_DEBUG "%s: link change notification done.\n", dev->name); |
| 2794 | } |
| 2795 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 2796 | static irqreturn_t nv_nic_irq(int foo, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2797 | { |
| 2798 | struct net_device *dev = (struct net_device *) data; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2799 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 | u8 __iomem *base = get_hwbase(dev); |
| 2801 | u32 events; |
| 2802 | int i; |
| 2803 | |
| 2804 | dprintk(KERN_DEBUG "%s: nv_nic_irq\n", dev->name); |
| 2805 | |
| 2806 | for (i=0; ; i++) { |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 2807 | if (!(np->msi_flags & NV_MSI_X_ENABLED)) { |
| 2808 | events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK; |
| 2809 | writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus); |
| 2810 | } else { |
| 2811 | events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK; |
| 2812 | writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus); |
| 2813 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2814 | pci_push(base); |
| 2815 | dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events); |
| 2816 | if (!(events & np->irqmask)) |
| 2817 | break; |
| 2818 | |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2819 | spin_lock(&np->lock); |
| 2820 | nv_tx_done(dev); |
| 2821 | spin_unlock(&np->lock); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 2822 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2823 | if (events & NVREG_IRQ_LINK) { |
| 2824 | spin_lock(&np->lock); |
| 2825 | nv_link_irq(dev); |
| 2826 | spin_unlock(&np->lock); |
| 2827 | } |
| 2828 | if (np->need_linktimer && time_after(jiffies, np->link_timeout)) { |
| 2829 | spin_lock(&np->lock); |
| 2830 | nv_linkchange(dev); |
| 2831 | spin_unlock(&np->lock); |
| 2832 | np->link_timeout = jiffies + LINK_TIMEOUT; |
| 2833 | } |
| 2834 | if (events & (NVREG_IRQ_TX_ERR)) { |
| 2835 | dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n", |
| 2836 | dev->name, events); |
| 2837 | } |
| 2838 | if (events & (NVREG_IRQ_UNKNOWN)) { |
| 2839 | printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n", |
| 2840 | dev->name, events); |
| 2841 | } |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 2842 | if (unlikely(events & NVREG_IRQ_RECOVER_ERROR)) { |
| 2843 | spin_lock(&np->lock); |
| 2844 | /* disable interrupts on the nic */ |
| 2845 | if (!(np->msi_flags & NV_MSI_X_ENABLED)) |
| 2846 | writel(0, base + NvRegIrqMask); |
| 2847 | else |
| 2848 | writel(np->irqmask, base + NvRegIrqMask); |
| 2849 | pci_push(base); |
| 2850 | |
| 2851 | if (!np->in_shutdown) { |
| 2852 | np->nic_poll_irq = np->irqmask; |
| 2853 | np->recover_error = 1; |
| 2854 | mod_timer(&np->nic_poll, jiffies + POLL_WAIT); |
| 2855 | } |
| 2856 | spin_unlock(&np->lock); |
| 2857 | break; |
| 2858 | } |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 2859 | #ifdef CONFIG_FORCEDETH_NAPI |
| 2860 | if (events & NVREG_IRQ_RX_ALL) { |
| 2861 | netif_rx_schedule(dev); |
| 2862 | |
| 2863 | /* Disable furthur receive irq's */ |
| 2864 | spin_lock(&np->lock); |
| 2865 | np->irqmask &= ~NVREG_IRQ_RX_ALL; |
| 2866 | |
| 2867 | if (np->msi_flags & NV_MSI_X_ENABLED) |
| 2868 | writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask); |
| 2869 | else |
| 2870 | writel(np->irqmask, base + NvRegIrqMask); |
| 2871 | spin_unlock(&np->lock); |
| 2872 | } |
| 2873 | #else |
| 2874 | nv_rx_process(dev, dev->weight); |
| 2875 | if (nv_alloc_rx(dev)) { |
| 2876 | spin_lock(&np->lock); |
| 2877 | if (!np->in_shutdown) |
| 2878 | mod_timer(&np->oom_kick, jiffies + OOM_REFILL); |
| 2879 | spin_unlock(&np->lock); |
| 2880 | } |
| 2881 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | if (i > max_interrupt_work) { |
| 2883 | spin_lock(&np->lock); |
| 2884 | /* disable interrupts on the nic */ |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 2885 | if (!(np->msi_flags & NV_MSI_X_ENABLED)) |
| 2886 | writel(0, base + NvRegIrqMask); |
| 2887 | else |
| 2888 | writel(np->irqmask, base + NvRegIrqMask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2889 | pci_push(base); |
| 2890 | |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 2891 | if (!np->in_shutdown) { |
| 2892 | np->nic_poll_irq = np->irqmask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2893 | mod_timer(&np->nic_poll, jiffies + POLL_WAIT); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 2894 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2895 | printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq.\n", dev->name, i); |
| 2896 | spin_unlock(&np->lock); |
| 2897 | break; |
| 2898 | } |
| 2899 | |
| 2900 | } |
| 2901 | dprintk(KERN_DEBUG "%s: nv_nic_irq completed\n", dev->name); |
| 2902 | |
| 2903 | return IRQ_RETVAL(i); |
| 2904 | } |
| 2905 | |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2906 | static irqreturn_t nv_nic_irq_optimized(int foo, void *data) |
| 2907 | { |
| 2908 | struct net_device *dev = (struct net_device *) data; |
| 2909 | struct fe_priv *np = netdev_priv(dev); |
| 2910 | u8 __iomem *base = get_hwbase(dev); |
| 2911 | u32 events; |
| 2912 | int i; |
| 2913 | |
| 2914 | dprintk(KERN_DEBUG "%s: nv_nic_irq_optimized\n", dev->name); |
| 2915 | |
| 2916 | for (i=0; ; i++) { |
| 2917 | if (!(np->msi_flags & NV_MSI_X_ENABLED)) { |
| 2918 | events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK; |
| 2919 | writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus); |
| 2920 | } else { |
| 2921 | events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK; |
| 2922 | writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus); |
| 2923 | } |
| 2924 | pci_push(base); |
| 2925 | dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events); |
| 2926 | if (!(events & np->irqmask)) |
| 2927 | break; |
| 2928 | |
| 2929 | spin_lock(&np->lock); |
| 2930 | nv_tx_done_optimized(dev); |
| 2931 | spin_unlock(&np->lock); |
| 2932 | |
| 2933 | if (events & NVREG_IRQ_LINK) { |
| 2934 | spin_lock(&np->lock); |
| 2935 | nv_link_irq(dev); |
| 2936 | spin_unlock(&np->lock); |
| 2937 | } |
| 2938 | if (np->need_linktimer && time_after(jiffies, np->link_timeout)) { |
| 2939 | spin_lock(&np->lock); |
| 2940 | nv_linkchange(dev); |
| 2941 | spin_unlock(&np->lock); |
| 2942 | np->link_timeout = jiffies + LINK_TIMEOUT; |
| 2943 | } |
| 2944 | if (events & (NVREG_IRQ_TX_ERR)) { |
| 2945 | dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n", |
| 2946 | dev->name, events); |
| 2947 | } |
| 2948 | if (events & (NVREG_IRQ_UNKNOWN)) { |
| 2949 | printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n", |
| 2950 | dev->name, events); |
| 2951 | } |
| 2952 | if (unlikely(events & NVREG_IRQ_RECOVER_ERROR)) { |
| 2953 | spin_lock(&np->lock); |
| 2954 | /* disable interrupts on the nic */ |
| 2955 | if (!(np->msi_flags & NV_MSI_X_ENABLED)) |
| 2956 | writel(0, base + NvRegIrqMask); |
| 2957 | else |
| 2958 | writel(np->irqmask, base + NvRegIrqMask); |
| 2959 | pci_push(base); |
| 2960 | |
| 2961 | if (!np->in_shutdown) { |
| 2962 | np->nic_poll_irq = np->irqmask; |
| 2963 | np->recover_error = 1; |
| 2964 | mod_timer(&np->nic_poll, jiffies + POLL_WAIT); |
| 2965 | } |
| 2966 | spin_unlock(&np->lock); |
| 2967 | break; |
| 2968 | } |
| 2969 | |
| 2970 | #ifdef CONFIG_FORCEDETH_NAPI |
| 2971 | if (events & NVREG_IRQ_RX_ALL) { |
| 2972 | netif_rx_schedule(dev); |
| 2973 | |
| 2974 | /* Disable furthur receive irq's */ |
| 2975 | spin_lock(&np->lock); |
| 2976 | np->irqmask &= ~NVREG_IRQ_RX_ALL; |
| 2977 | |
| 2978 | if (np->msi_flags & NV_MSI_X_ENABLED) |
| 2979 | writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask); |
| 2980 | else |
| 2981 | writel(np->irqmask, base + NvRegIrqMask); |
| 2982 | spin_unlock(&np->lock); |
| 2983 | } |
| 2984 | #else |
| 2985 | nv_rx_process_optimized(dev, dev->weight); |
| 2986 | if (nv_alloc_rx_optimized(dev)) { |
| 2987 | spin_lock(&np->lock); |
| 2988 | if (!np->in_shutdown) |
| 2989 | mod_timer(&np->oom_kick, jiffies + OOM_REFILL); |
| 2990 | spin_unlock(&np->lock); |
| 2991 | } |
| 2992 | #endif |
| 2993 | if (i > max_interrupt_work) { |
| 2994 | spin_lock(&np->lock); |
| 2995 | /* disable interrupts on the nic */ |
| 2996 | if (!(np->msi_flags & NV_MSI_X_ENABLED)) |
| 2997 | writel(0, base + NvRegIrqMask); |
| 2998 | else |
| 2999 | writel(np->irqmask, base + NvRegIrqMask); |
| 3000 | pci_push(base); |
| 3001 | |
| 3002 | if (!np->in_shutdown) { |
| 3003 | np->nic_poll_irq = np->irqmask; |
| 3004 | mod_timer(&np->nic_poll, jiffies + POLL_WAIT); |
| 3005 | } |
| 3006 | printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq.\n", dev->name, i); |
| 3007 | spin_unlock(&np->lock); |
| 3008 | break; |
| 3009 | } |
| 3010 | |
| 3011 | } |
| 3012 | dprintk(KERN_DEBUG "%s: nv_nic_irq_optimized completed\n", dev->name); |
| 3013 | |
| 3014 | return IRQ_RETVAL(i); |
| 3015 | } |
| 3016 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3017 | static irqreturn_t nv_nic_irq_tx(int foo, void *data) |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3018 | { |
| 3019 | struct net_device *dev = (struct net_device *) data; |
| 3020 | struct fe_priv *np = netdev_priv(dev); |
| 3021 | u8 __iomem *base = get_hwbase(dev); |
| 3022 | u32 events; |
| 3023 | int i; |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3024 | unsigned long flags; |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3025 | |
| 3026 | dprintk(KERN_DEBUG "%s: nv_nic_irq_tx\n", dev->name); |
| 3027 | |
| 3028 | for (i=0; ; i++) { |
| 3029 | events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_TX_ALL; |
| 3030 | writel(NVREG_IRQ_TX_ALL, base + NvRegMSIXIrqStatus); |
| 3031 | pci_push(base); |
| 3032 | dprintk(KERN_DEBUG "%s: tx irq: %08x\n", dev->name, events); |
| 3033 | if (!(events & np->irqmask)) |
| 3034 | break; |
| 3035 | |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3036 | spin_lock_irqsave(&np->lock, flags); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 3037 | nv_tx_done_optimized(dev); |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3038 | spin_unlock_irqrestore(&np->lock, flags); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 3039 | |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3040 | if (events & (NVREG_IRQ_TX_ERR)) { |
| 3041 | dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n", |
| 3042 | dev->name, events); |
| 3043 | } |
| 3044 | if (i > max_interrupt_work) { |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3045 | spin_lock_irqsave(&np->lock, flags); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3046 | /* disable interrupts on the nic */ |
| 3047 | writel(NVREG_IRQ_TX_ALL, base + NvRegIrqMask); |
| 3048 | pci_push(base); |
| 3049 | |
| 3050 | if (!np->in_shutdown) { |
| 3051 | np->nic_poll_irq |= NVREG_IRQ_TX_ALL; |
| 3052 | mod_timer(&np->nic_poll, jiffies + POLL_WAIT); |
| 3053 | } |
| 3054 | printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_tx.\n", dev->name, i); |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3055 | spin_unlock_irqrestore(&np->lock, flags); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3056 | break; |
| 3057 | } |
| 3058 | |
| 3059 | } |
| 3060 | dprintk(KERN_DEBUG "%s: nv_nic_irq_tx completed\n", dev->name); |
| 3061 | |
| 3062 | return IRQ_RETVAL(i); |
| 3063 | } |
| 3064 | |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 3065 | #ifdef CONFIG_FORCEDETH_NAPI |
| 3066 | static int nv_napi_poll(struct net_device *dev, int *budget) |
| 3067 | { |
| 3068 | int pkts, limit = min(*budget, dev->quota); |
| 3069 | struct fe_priv *np = netdev_priv(dev); |
| 3070 | u8 __iomem *base = get_hwbase(dev); |
Francois Romieu | d15e9c4 | 2006-12-17 23:03:15 +0100 | [diff] [blame] | 3071 | unsigned long flags; |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 3072 | |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 3073 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
| 3074 | pkts = nv_rx_process(dev, limit); |
| 3075 | else |
| 3076 | pkts = nv_rx_process_optimized(dev, limit); |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 3077 | |
| 3078 | if (nv_alloc_rx(dev)) { |
Francois Romieu | d15e9c4 | 2006-12-17 23:03:15 +0100 | [diff] [blame] | 3079 | spin_lock_irqsave(&np->lock, flags); |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 3080 | if (!np->in_shutdown) |
| 3081 | mod_timer(&np->oom_kick, jiffies + OOM_REFILL); |
Francois Romieu | d15e9c4 | 2006-12-17 23:03:15 +0100 | [diff] [blame] | 3082 | spin_unlock_irqrestore(&np->lock, flags); |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 3083 | } |
| 3084 | |
| 3085 | if (pkts < limit) { |
| 3086 | /* all done, no more packets present */ |
| 3087 | netif_rx_complete(dev); |
| 3088 | |
| 3089 | /* re-enable receive interrupts */ |
Francois Romieu | d15e9c4 | 2006-12-17 23:03:15 +0100 | [diff] [blame] | 3090 | spin_lock_irqsave(&np->lock, flags); |
| 3091 | |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 3092 | np->irqmask |= NVREG_IRQ_RX_ALL; |
| 3093 | if (np->msi_flags & NV_MSI_X_ENABLED) |
| 3094 | writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask); |
| 3095 | else |
| 3096 | writel(np->irqmask, base + NvRegIrqMask); |
Francois Romieu | d15e9c4 | 2006-12-17 23:03:15 +0100 | [diff] [blame] | 3097 | |
| 3098 | spin_unlock_irqrestore(&np->lock, flags); |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 3099 | return 0; |
| 3100 | } else { |
| 3101 | /* used up our quantum, so reschedule */ |
| 3102 | dev->quota -= pkts; |
| 3103 | *budget -= pkts; |
| 3104 | return 1; |
| 3105 | } |
| 3106 | } |
| 3107 | #endif |
| 3108 | |
| 3109 | #ifdef CONFIG_FORCEDETH_NAPI |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3110 | static irqreturn_t nv_nic_irq_rx(int foo, void *data) |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 3111 | { |
| 3112 | struct net_device *dev = (struct net_device *) data; |
| 3113 | u8 __iomem *base = get_hwbase(dev); |
| 3114 | u32 events; |
| 3115 | |
| 3116 | events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL; |
| 3117 | writel(NVREG_IRQ_RX_ALL, base + NvRegMSIXIrqStatus); |
| 3118 | |
| 3119 | if (events) { |
| 3120 | netif_rx_schedule(dev); |
| 3121 | /* disable receive interrupts on the nic */ |
| 3122 | writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask); |
| 3123 | pci_push(base); |
| 3124 | } |
| 3125 | return IRQ_HANDLED; |
| 3126 | } |
| 3127 | #else |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3128 | static irqreturn_t nv_nic_irq_rx(int foo, void *data) |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3129 | { |
| 3130 | struct net_device *dev = (struct net_device *) data; |
| 3131 | struct fe_priv *np = netdev_priv(dev); |
| 3132 | u8 __iomem *base = get_hwbase(dev); |
| 3133 | u32 events; |
| 3134 | int i; |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3135 | unsigned long flags; |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3136 | |
| 3137 | dprintk(KERN_DEBUG "%s: nv_nic_irq_rx\n", dev->name); |
| 3138 | |
| 3139 | for (i=0; ; i++) { |
| 3140 | events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL; |
| 3141 | writel(NVREG_IRQ_RX_ALL, base + NvRegMSIXIrqStatus); |
| 3142 | pci_push(base); |
| 3143 | dprintk(KERN_DEBUG "%s: rx irq: %08x\n", dev->name, events); |
| 3144 | if (!(events & np->irqmask)) |
| 3145 | break; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 3146 | |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 3147 | nv_rx_process_optimized(dev, dev->weight); |
| 3148 | if (nv_alloc_rx_optimized(dev)) { |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3149 | spin_lock_irqsave(&np->lock, flags); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3150 | if (!np->in_shutdown) |
| 3151 | mod_timer(&np->oom_kick, jiffies + OOM_REFILL); |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3152 | spin_unlock_irqrestore(&np->lock, flags); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3153 | } |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 3154 | |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3155 | if (i > max_interrupt_work) { |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3156 | spin_lock_irqsave(&np->lock, flags); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3157 | /* disable interrupts on the nic */ |
| 3158 | writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask); |
| 3159 | pci_push(base); |
| 3160 | |
| 3161 | if (!np->in_shutdown) { |
| 3162 | np->nic_poll_irq |= NVREG_IRQ_RX_ALL; |
| 3163 | mod_timer(&np->nic_poll, jiffies + POLL_WAIT); |
| 3164 | } |
| 3165 | printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_rx.\n", dev->name, i); |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3166 | spin_unlock_irqrestore(&np->lock, flags); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3167 | break; |
| 3168 | } |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3169 | } |
| 3170 | dprintk(KERN_DEBUG "%s: nv_nic_irq_rx completed\n", dev->name); |
| 3171 | |
| 3172 | return IRQ_RETVAL(i); |
| 3173 | } |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 3174 | #endif |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3175 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3176 | static irqreturn_t nv_nic_irq_other(int foo, void *data) |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3177 | { |
| 3178 | struct net_device *dev = (struct net_device *) data; |
| 3179 | struct fe_priv *np = netdev_priv(dev); |
| 3180 | u8 __iomem *base = get_hwbase(dev); |
| 3181 | u32 events; |
| 3182 | int i; |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3183 | unsigned long flags; |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3184 | |
| 3185 | dprintk(KERN_DEBUG "%s: nv_nic_irq_other\n", dev->name); |
| 3186 | |
| 3187 | for (i=0; ; i++) { |
| 3188 | events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_OTHER; |
| 3189 | writel(NVREG_IRQ_OTHER, base + NvRegMSIXIrqStatus); |
| 3190 | pci_push(base); |
| 3191 | dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events); |
| 3192 | if (!(events & np->irqmask)) |
| 3193 | break; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 3194 | |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3195 | if (events & NVREG_IRQ_LINK) { |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3196 | spin_lock_irqsave(&np->lock, flags); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3197 | nv_link_irq(dev); |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3198 | spin_unlock_irqrestore(&np->lock, flags); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3199 | } |
| 3200 | if (np->need_linktimer && time_after(jiffies, np->link_timeout)) { |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3201 | spin_lock_irqsave(&np->lock, flags); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3202 | nv_linkchange(dev); |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3203 | spin_unlock_irqrestore(&np->lock, flags); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3204 | np->link_timeout = jiffies + LINK_TIMEOUT; |
| 3205 | } |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 3206 | if (events & NVREG_IRQ_RECOVER_ERROR) { |
| 3207 | spin_lock_irq(&np->lock); |
| 3208 | /* disable interrupts on the nic */ |
| 3209 | writel(NVREG_IRQ_OTHER, base + NvRegIrqMask); |
| 3210 | pci_push(base); |
| 3211 | |
| 3212 | if (!np->in_shutdown) { |
| 3213 | np->nic_poll_irq |= NVREG_IRQ_OTHER; |
| 3214 | np->recover_error = 1; |
| 3215 | mod_timer(&np->nic_poll, jiffies + POLL_WAIT); |
| 3216 | } |
| 3217 | spin_unlock_irq(&np->lock); |
| 3218 | break; |
| 3219 | } |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3220 | if (events & (NVREG_IRQ_UNKNOWN)) { |
| 3221 | printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n", |
| 3222 | dev->name, events); |
| 3223 | } |
| 3224 | if (i > max_interrupt_work) { |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3225 | spin_lock_irqsave(&np->lock, flags); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3226 | /* disable interrupts on the nic */ |
| 3227 | writel(NVREG_IRQ_OTHER, base + NvRegIrqMask); |
| 3228 | pci_push(base); |
| 3229 | |
| 3230 | if (!np->in_shutdown) { |
| 3231 | np->nic_poll_irq |= NVREG_IRQ_OTHER; |
| 3232 | mod_timer(&np->nic_poll, jiffies + POLL_WAIT); |
| 3233 | } |
| 3234 | printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_other.\n", dev->name, i); |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3235 | spin_unlock_irqrestore(&np->lock, flags); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3236 | break; |
| 3237 | } |
| 3238 | |
| 3239 | } |
| 3240 | dprintk(KERN_DEBUG "%s: nv_nic_irq_other completed\n", dev->name); |
| 3241 | |
| 3242 | return IRQ_RETVAL(i); |
| 3243 | } |
| 3244 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3245 | static irqreturn_t nv_nic_irq_test(int foo, void *data) |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 3246 | { |
| 3247 | struct net_device *dev = (struct net_device *) data; |
| 3248 | struct fe_priv *np = netdev_priv(dev); |
| 3249 | u8 __iomem *base = get_hwbase(dev); |
| 3250 | u32 events; |
| 3251 | |
| 3252 | dprintk(KERN_DEBUG "%s: nv_nic_irq_test\n", dev->name); |
| 3253 | |
| 3254 | if (!(np->msi_flags & NV_MSI_X_ENABLED)) { |
| 3255 | events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK; |
| 3256 | writel(NVREG_IRQ_TIMER, base + NvRegIrqStatus); |
| 3257 | } else { |
| 3258 | events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK; |
| 3259 | writel(NVREG_IRQ_TIMER, base + NvRegMSIXIrqStatus); |
| 3260 | } |
| 3261 | pci_push(base); |
| 3262 | dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events); |
| 3263 | if (!(events & NVREG_IRQ_TIMER)) |
| 3264 | return IRQ_RETVAL(0); |
| 3265 | |
| 3266 | spin_lock(&np->lock); |
| 3267 | np->intr_test = 1; |
| 3268 | spin_unlock(&np->lock); |
| 3269 | |
| 3270 | dprintk(KERN_DEBUG "%s: nv_nic_irq_test completed\n", dev->name); |
| 3271 | |
| 3272 | return IRQ_RETVAL(1); |
| 3273 | } |
| 3274 | |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3275 | static void set_msix_vector_map(struct net_device *dev, u32 vector, u32 irqmask) |
| 3276 | { |
| 3277 | u8 __iomem *base = get_hwbase(dev); |
| 3278 | int i; |
| 3279 | u32 msixmap = 0; |
| 3280 | |
| 3281 | /* Each interrupt bit can be mapped to a MSIX vector (4 bits). |
| 3282 | * MSIXMap0 represents the first 8 interrupts and MSIXMap1 represents |
| 3283 | * the remaining 8 interrupts. |
| 3284 | */ |
| 3285 | for (i = 0; i < 8; i++) { |
| 3286 | if ((irqmask >> i) & 0x1) { |
| 3287 | msixmap |= vector << (i << 2); |
| 3288 | } |
| 3289 | } |
| 3290 | writel(readl(base + NvRegMSIXMap0) | msixmap, base + NvRegMSIXMap0); |
| 3291 | |
| 3292 | msixmap = 0; |
| 3293 | for (i = 0; i < 8; i++) { |
| 3294 | if ((irqmask >> (i + 8)) & 0x1) { |
| 3295 | msixmap |= vector << (i << 2); |
| 3296 | } |
| 3297 | } |
| 3298 | writel(readl(base + NvRegMSIXMap1) | msixmap, base + NvRegMSIXMap1); |
| 3299 | } |
| 3300 | |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 3301 | static int nv_request_irq(struct net_device *dev, int intr_test) |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3302 | { |
| 3303 | struct fe_priv *np = get_nvpriv(dev); |
| 3304 | u8 __iomem *base = get_hwbase(dev); |
| 3305 | int ret = 1; |
| 3306 | int i; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 3307 | irqreturn_t (*handler)(int foo, void *data); |
| 3308 | |
| 3309 | if (intr_test) { |
| 3310 | handler = nv_nic_irq_test; |
| 3311 | } else { |
| 3312 | if (np->desc_ver == DESC_VER_3) |
| 3313 | handler = nv_nic_irq_optimized; |
| 3314 | else |
| 3315 | handler = nv_nic_irq; |
| 3316 | } |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3317 | |
| 3318 | if (np->msi_flags & NV_MSI_X_CAPABLE) { |
| 3319 | for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++) { |
| 3320 | np->msi_x_entry[i].entry = i; |
| 3321 | } |
| 3322 | if ((ret = pci_enable_msix(np->pci_dev, np->msi_x_entry, (np->msi_flags & NV_MSI_X_VECTORS_MASK))) == 0) { |
| 3323 | np->msi_flags |= NV_MSI_X_ENABLED; |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 3324 | if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT && !intr_test) { |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3325 | /* Request irq for rx handling */ |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 3326 | if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector, &nv_nic_irq_rx, IRQF_SHARED, dev->name, dev) != 0) { |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3327 | printk(KERN_INFO "forcedeth: request_irq failed for rx %d\n", ret); |
| 3328 | pci_disable_msix(np->pci_dev); |
| 3329 | np->msi_flags &= ~NV_MSI_X_ENABLED; |
| 3330 | goto out_err; |
| 3331 | } |
| 3332 | /* Request irq for tx handling */ |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 3333 | if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector, &nv_nic_irq_tx, IRQF_SHARED, dev->name, dev) != 0) { |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3334 | printk(KERN_INFO "forcedeth: request_irq failed for tx %d\n", ret); |
| 3335 | pci_disable_msix(np->pci_dev); |
| 3336 | np->msi_flags &= ~NV_MSI_X_ENABLED; |
| 3337 | goto out_free_rx; |
| 3338 | } |
| 3339 | /* Request irq for link and timer handling */ |
Thomas Gleixner | 1fb9df5 | 2006-07-01 19:29:39 -0700 | [diff] [blame] | 3340 | if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector, &nv_nic_irq_other, IRQF_SHARED, dev->name, dev) != 0) { |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3341 | printk(KERN_INFO "forcedeth: request_irq failed for link %d\n", ret); |
| 3342 | pci_disable_msix(np->pci_dev); |
| 3343 | np->msi_flags &= ~NV_MSI_X_ENABLED; |
| 3344 | goto out_free_tx; |
| 3345 | } |
| 3346 | /* map interrupts to their respective vector */ |
| 3347 | writel(0, base + NvRegMSIXMap0); |
| 3348 | writel(0, base + NvRegMSIXMap1); |
| 3349 | set_msix_vector_map(dev, NV_MSI_X_VECTOR_RX, NVREG_IRQ_RX_ALL); |
| 3350 | set_msix_vector_map(dev, NV_MSI_X_VECTOR_TX, NVREG_IRQ_TX_ALL); |
| 3351 | set_msix_vector_map(dev, NV_MSI_X_VECTOR_OTHER, NVREG_IRQ_OTHER); |
| 3352 | } else { |
| 3353 | /* Request irq for all interrupts */ |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 3354 | if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector, handler, IRQF_SHARED, dev->name, dev) != 0) { |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3355 | printk(KERN_INFO "forcedeth: request_irq failed %d\n", ret); |
| 3356 | pci_disable_msix(np->pci_dev); |
| 3357 | np->msi_flags &= ~NV_MSI_X_ENABLED; |
| 3358 | goto out_err; |
| 3359 | } |
| 3360 | |
| 3361 | /* map interrupts to vector 0 */ |
| 3362 | writel(0, base + NvRegMSIXMap0); |
| 3363 | writel(0, base + NvRegMSIXMap1); |
| 3364 | } |
| 3365 | } |
| 3366 | } |
| 3367 | if (ret != 0 && np->msi_flags & NV_MSI_CAPABLE) { |
| 3368 | if ((ret = pci_enable_msi(np->pci_dev)) == 0) { |
| 3369 | np->msi_flags |= NV_MSI_ENABLED; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 3370 | if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0) { |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3371 | printk(KERN_INFO "forcedeth: request_irq failed %d\n", ret); |
| 3372 | pci_disable_msi(np->pci_dev); |
| 3373 | np->msi_flags &= ~NV_MSI_ENABLED; |
| 3374 | goto out_err; |
| 3375 | } |
| 3376 | |
| 3377 | /* map interrupts to vector 0 */ |
| 3378 | writel(0, base + NvRegMSIMap0); |
| 3379 | writel(0, base + NvRegMSIMap1); |
| 3380 | /* enable msi vector 0 */ |
| 3381 | writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask); |
| 3382 | } |
| 3383 | } |
| 3384 | if (ret != 0) { |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 3385 | if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0) |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3386 | goto out_err; |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 3387 | |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3388 | } |
| 3389 | |
| 3390 | return 0; |
| 3391 | out_free_tx: |
| 3392 | free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector, dev); |
| 3393 | out_free_rx: |
| 3394 | free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector, dev); |
| 3395 | out_err: |
| 3396 | return 1; |
| 3397 | } |
| 3398 | |
| 3399 | static void nv_free_irq(struct net_device *dev) |
| 3400 | { |
| 3401 | struct fe_priv *np = get_nvpriv(dev); |
| 3402 | int i; |
| 3403 | |
| 3404 | if (np->msi_flags & NV_MSI_X_ENABLED) { |
| 3405 | for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++) { |
| 3406 | free_irq(np->msi_x_entry[i].vector, dev); |
| 3407 | } |
| 3408 | pci_disable_msix(np->pci_dev); |
| 3409 | np->msi_flags &= ~NV_MSI_X_ENABLED; |
| 3410 | } else { |
| 3411 | free_irq(np->pci_dev->irq, dev); |
| 3412 | if (np->msi_flags & NV_MSI_ENABLED) { |
| 3413 | pci_disable_msi(np->pci_dev); |
| 3414 | np->msi_flags &= ~NV_MSI_ENABLED; |
| 3415 | } |
| 3416 | } |
| 3417 | } |
| 3418 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3419 | static void nv_do_nic_poll(unsigned long data) |
| 3420 | { |
| 3421 | struct net_device *dev = (struct net_device *) data; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 3422 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3423 | u8 __iomem *base = get_hwbase(dev); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3424 | u32 mask = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3426 | /* |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3427 | * First disable irq(s) and then |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3428 | * reenable interrupts on the nic, we have to do this before calling |
| 3429 | * nv_nic_irq because that may decide to do otherwise |
| 3430 | */ |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3431 | |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 3432 | if (!using_multi_irqs(dev)) { |
| 3433 | if (np->msi_flags & NV_MSI_X_ENABLED) |
Ingo Molnar | 8688cfc | 2006-07-03 00:25:39 -0700 | [diff] [blame] | 3434 | disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector); |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 3435 | else |
Ingo Molnar | 8688cfc | 2006-07-03 00:25:39 -0700 | [diff] [blame] | 3436 | disable_irq_lockdep(dev->irq); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3437 | mask = np->irqmask; |
| 3438 | } else { |
| 3439 | if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) { |
Ingo Molnar | 8688cfc | 2006-07-03 00:25:39 -0700 | [diff] [blame] | 3440 | disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3441 | mask |= NVREG_IRQ_RX_ALL; |
| 3442 | } |
| 3443 | if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) { |
Ingo Molnar | 8688cfc | 2006-07-03 00:25:39 -0700 | [diff] [blame] | 3444 | disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3445 | mask |= NVREG_IRQ_TX_ALL; |
| 3446 | } |
| 3447 | if (np->nic_poll_irq & NVREG_IRQ_OTHER) { |
Ingo Molnar | 8688cfc | 2006-07-03 00:25:39 -0700 | [diff] [blame] | 3448 | disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3449 | mask |= NVREG_IRQ_OTHER; |
| 3450 | } |
| 3451 | } |
| 3452 | np->nic_poll_irq = 0; |
| 3453 | |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 3454 | if (np->recover_error) { |
| 3455 | np->recover_error = 0; |
| 3456 | printk(KERN_INFO "forcedeth: MAC in recoverable error state\n"); |
| 3457 | if (netif_running(dev)) { |
| 3458 | netif_tx_lock_bh(dev); |
| 3459 | spin_lock(&np->lock); |
| 3460 | /* stop engines */ |
| 3461 | nv_stop_rx(dev); |
| 3462 | nv_stop_tx(dev); |
| 3463 | nv_txrx_reset(dev); |
| 3464 | /* drain rx queue */ |
| 3465 | nv_drain_rx(dev); |
| 3466 | nv_drain_tx(dev); |
| 3467 | /* reinit driver view of the rx queue */ |
| 3468 | set_bufsize(dev); |
| 3469 | if (nv_init_ring(dev)) { |
| 3470 | if (!np->in_shutdown) |
| 3471 | mod_timer(&np->oom_kick, jiffies + OOM_REFILL); |
| 3472 | } |
| 3473 | /* reinit nic view of the rx queue */ |
| 3474 | writel(np->rx_buf_sz, base + NvRegOffloadConfig); |
| 3475 | setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING); |
| 3476 | writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT), |
| 3477 | base + NvRegRingSizes); |
| 3478 | pci_push(base); |
| 3479 | writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl); |
| 3480 | pci_push(base); |
| 3481 | |
| 3482 | /* restart rx engine */ |
| 3483 | nv_start_rx(dev); |
| 3484 | nv_start_tx(dev); |
| 3485 | spin_unlock(&np->lock); |
| 3486 | netif_tx_unlock_bh(dev); |
| 3487 | } |
| 3488 | } |
| 3489 | |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3490 | /* FIXME: Do we need synchronize_irq(dev->irq) here? */ |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 3491 | |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3492 | writel(mask, base + NvRegIrqMask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3493 | pci_push(base); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3494 | |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 3495 | if (!using_multi_irqs(dev)) { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3496 | nv_nic_irq(0, dev); |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 3497 | if (np->msi_flags & NV_MSI_X_ENABLED) |
Ingo Molnar | 8688cfc | 2006-07-03 00:25:39 -0700 | [diff] [blame] | 3498 | enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector); |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 3499 | else |
Ingo Molnar | 8688cfc | 2006-07-03 00:25:39 -0700 | [diff] [blame] | 3500 | enable_irq_lockdep(dev->irq); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3501 | } else { |
| 3502 | if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3503 | nv_nic_irq_rx(0, dev); |
Ingo Molnar | 8688cfc | 2006-07-03 00:25:39 -0700 | [diff] [blame] | 3504 | enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3505 | } |
| 3506 | if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3507 | nv_nic_irq_tx(0, dev); |
Ingo Molnar | 8688cfc | 2006-07-03 00:25:39 -0700 | [diff] [blame] | 3508 | enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3509 | } |
| 3510 | if (np->nic_poll_irq & NVREG_IRQ_OTHER) { |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3511 | nv_nic_irq_other(0, dev); |
Ingo Molnar | 8688cfc | 2006-07-03 00:25:39 -0700 | [diff] [blame] | 3512 | enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3513 | } |
| 3514 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3515 | } |
| 3516 | |
Michal Schmidt | 2918c35 | 2005-05-12 19:42:06 -0400 | [diff] [blame] | 3517 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 3518 | static void nv_poll_controller(struct net_device *dev) |
| 3519 | { |
| 3520 | nv_do_nic_poll((unsigned long) dev); |
| 3521 | } |
| 3522 | #endif |
| 3523 | |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 3524 | static void nv_do_stats_poll(unsigned long data) |
| 3525 | { |
| 3526 | struct net_device *dev = (struct net_device *) data; |
| 3527 | struct fe_priv *np = netdev_priv(dev); |
| 3528 | u8 __iomem *base = get_hwbase(dev); |
| 3529 | |
| 3530 | np->estats.tx_bytes += readl(base + NvRegTxCnt); |
| 3531 | np->estats.tx_zero_rexmt += readl(base + NvRegTxZeroReXmt); |
| 3532 | np->estats.tx_one_rexmt += readl(base + NvRegTxOneReXmt); |
| 3533 | np->estats.tx_many_rexmt += readl(base + NvRegTxManyReXmt); |
| 3534 | np->estats.tx_late_collision += readl(base + NvRegTxLateCol); |
| 3535 | np->estats.tx_fifo_errors += readl(base + NvRegTxUnderflow); |
| 3536 | np->estats.tx_carrier_errors += readl(base + NvRegTxLossCarrier); |
| 3537 | np->estats.tx_excess_deferral += readl(base + NvRegTxExcessDef); |
| 3538 | np->estats.tx_retry_error += readl(base + NvRegTxRetryErr); |
| 3539 | np->estats.tx_deferral += readl(base + NvRegTxDef); |
| 3540 | np->estats.tx_packets += readl(base + NvRegTxFrame); |
| 3541 | np->estats.tx_pause += readl(base + NvRegTxPause); |
| 3542 | np->estats.rx_frame_error += readl(base + NvRegRxFrameErr); |
| 3543 | np->estats.rx_extra_byte += readl(base + NvRegRxExtraByte); |
| 3544 | np->estats.rx_late_collision += readl(base + NvRegRxLateCol); |
| 3545 | np->estats.rx_runt += readl(base + NvRegRxRunt); |
| 3546 | np->estats.rx_frame_too_long += readl(base + NvRegRxFrameTooLong); |
| 3547 | np->estats.rx_over_errors += readl(base + NvRegRxOverflow); |
| 3548 | np->estats.rx_crc_errors += readl(base + NvRegRxFCSErr); |
| 3549 | np->estats.rx_frame_align_error += readl(base + NvRegRxFrameAlignErr); |
| 3550 | np->estats.rx_length_error += readl(base + NvRegRxLenErr); |
| 3551 | np->estats.rx_unicast += readl(base + NvRegRxUnicast); |
| 3552 | np->estats.rx_multicast += readl(base + NvRegRxMulticast); |
| 3553 | np->estats.rx_broadcast += readl(base + NvRegRxBroadcast); |
| 3554 | np->estats.rx_bytes += readl(base + NvRegRxCnt); |
| 3555 | np->estats.rx_pause += readl(base + NvRegRxPause); |
| 3556 | np->estats.rx_drop_frame += readl(base + NvRegRxDropFrame); |
| 3557 | np->estats.rx_packets = |
| 3558 | np->estats.rx_unicast + |
| 3559 | np->estats.rx_multicast + |
| 3560 | np->estats.rx_broadcast; |
| 3561 | np->estats.rx_errors_total = |
| 3562 | np->estats.rx_crc_errors + |
| 3563 | np->estats.rx_over_errors + |
| 3564 | np->estats.rx_frame_error + |
| 3565 | (np->estats.rx_frame_align_error - np->estats.rx_extra_byte) + |
| 3566 | np->estats.rx_late_collision + |
| 3567 | np->estats.rx_runt + |
| 3568 | np->estats.rx_frame_too_long; |
| 3569 | |
| 3570 | if (!np->in_shutdown) |
| 3571 | mod_timer(&np->stats_poll, jiffies + STATS_INTERVAL); |
| 3572 | } |
| 3573 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3574 | static void nv_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
| 3575 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 3576 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3577 | strcpy(info->driver, "forcedeth"); |
| 3578 | strcpy(info->version, FORCEDETH_VERSION); |
| 3579 | strcpy(info->bus_info, pci_name(np->pci_dev)); |
| 3580 | } |
| 3581 | |
| 3582 | static void nv_get_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo) |
| 3583 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 3584 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3585 | wolinfo->supported = WAKE_MAGIC; |
| 3586 | |
| 3587 | spin_lock_irq(&np->lock); |
| 3588 | if (np->wolenabled) |
| 3589 | wolinfo->wolopts = WAKE_MAGIC; |
| 3590 | spin_unlock_irq(&np->lock); |
| 3591 | } |
| 3592 | |
| 3593 | static int nv_set_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo) |
| 3594 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 3595 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3596 | u8 __iomem *base = get_hwbase(dev); |
Ayaz Abdulla | c42d9df | 2006-06-10 22:47:52 -0400 | [diff] [blame] | 3597 | u32 flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3598 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3599 | if (wolinfo->wolopts == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3600 | np->wolenabled = 0; |
Ayaz Abdulla | c42d9df | 2006-06-10 22:47:52 -0400 | [diff] [blame] | 3601 | } else if (wolinfo->wolopts & WAKE_MAGIC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3602 | np->wolenabled = 1; |
Ayaz Abdulla | c42d9df | 2006-06-10 22:47:52 -0400 | [diff] [blame] | 3603 | flags = NVREG_WAKEUPFLAGS_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3604 | } |
Ayaz Abdulla | c42d9df | 2006-06-10 22:47:52 -0400 | [diff] [blame] | 3605 | if (netif_running(dev)) { |
| 3606 | spin_lock_irq(&np->lock); |
| 3607 | writel(flags, base + NvRegWakeUpFlags); |
| 3608 | spin_unlock_irq(&np->lock); |
| 3609 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3610 | return 0; |
| 3611 | } |
| 3612 | |
| 3613 | static int nv_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd) |
| 3614 | { |
| 3615 | struct fe_priv *np = netdev_priv(dev); |
| 3616 | int adv; |
| 3617 | |
| 3618 | spin_lock_irq(&np->lock); |
| 3619 | ecmd->port = PORT_MII; |
| 3620 | if (!netif_running(dev)) { |
| 3621 | /* We do not track link speed / duplex setting if the |
| 3622 | * interface is disabled. Force a link check */ |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 3623 | if (nv_update_linkspeed(dev)) { |
| 3624 | if (!netif_carrier_ok(dev)) |
| 3625 | netif_carrier_on(dev); |
| 3626 | } else { |
| 3627 | if (netif_carrier_ok(dev)) |
| 3628 | netif_carrier_off(dev); |
| 3629 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3630 | } |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 3631 | |
| 3632 | if (netif_carrier_ok(dev)) { |
| 3633 | switch(np->linkspeed & (NVREG_LINKSPEED_MASK)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3634 | case NVREG_LINKSPEED_10: |
| 3635 | ecmd->speed = SPEED_10; |
| 3636 | break; |
| 3637 | case NVREG_LINKSPEED_100: |
| 3638 | ecmd->speed = SPEED_100; |
| 3639 | break; |
| 3640 | case NVREG_LINKSPEED_1000: |
| 3641 | ecmd->speed = SPEED_1000; |
| 3642 | break; |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 3643 | } |
| 3644 | ecmd->duplex = DUPLEX_HALF; |
| 3645 | if (np->duplex) |
| 3646 | ecmd->duplex = DUPLEX_FULL; |
| 3647 | } else { |
| 3648 | ecmd->speed = -1; |
| 3649 | ecmd->duplex = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3650 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3651 | |
| 3652 | ecmd->autoneg = np->autoneg; |
| 3653 | |
| 3654 | ecmd->advertising = ADVERTISED_MII; |
| 3655 | if (np->autoneg) { |
| 3656 | ecmd->advertising |= ADVERTISED_Autoneg; |
| 3657 | adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ); |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 3658 | if (adv & ADVERTISE_10HALF) |
| 3659 | ecmd->advertising |= ADVERTISED_10baseT_Half; |
| 3660 | if (adv & ADVERTISE_10FULL) |
| 3661 | ecmd->advertising |= ADVERTISED_10baseT_Full; |
| 3662 | if (adv & ADVERTISE_100HALF) |
| 3663 | ecmd->advertising |= ADVERTISED_100baseT_Half; |
| 3664 | if (adv & ADVERTISE_100FULL) |
| 3665 | ecmd->advertising |= ADVERTISED_100baseT_Full; |
| 3666 | if (np->gigabit == PHY_GIGABIT) { |
| 3667 | adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ); |
| 3668 | if (adv & ADVERTISE_1000FULL) |
| 3669 | ecmd->advertising |= ADVERTISED_1000baseT_Full; |
| 3670 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3671 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3672 | ecmd->supported = (SUPPORTED_Autoneg | |
| 3673 | SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full | |
| 3674 | SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full | |
| 3675 | SUPPORTED_MII); |
| 3676 | if (np->gigabit == PHY_GIGABIT) |
| 3677 | ecmd->supported |= SUPPORTED_1000baseT_Full; |
| 3678 | |
| 3679 | ecmd->phy_address = np->phyaddr; |
| 3680 | ecmd->transceiver = XCVR_EXTERNAL; |
| 3681 | |
| 3682 | /* ignore maxtxpkt, maxrxpkt for now */ |
| 3683 | spin_unlock_irq(&np->lock); |
| 3684 | return 0; |
| 3685 | } |
| 3686 | |
| 3687 | static int nv_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd) |
| 3688 | { |
| 3689 | struct fe_priv *np = netdev_priv(dev); |
| 3690 | |
| 3691 | if (ecmd->port != PORT_MII) |
| 3692 | return -EINVAL; |
| 3693 | if (ecmd->transceiver != XCVR_EXTERNAL) |
| 3694 | return -EINVAL; |
| 3695 | if (ecmd->phy_address != np->phyaddr) { |
| 3696 | /* TODO: support switching between multiple phys. Should be |
| 3697 | * trivial, but not enabled due to lack of test hardware. */ |
| 3698 | return -EINVAL; |
| 3699 | } |
| 3700 | if (ecmd->autoneg == AUTONEG_ENABLE) { |
| 3701 | u32 mask; |
| 3702 | |
| 3703 | mask = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 3704 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full; |
| 3705 | if (np->gigabit == PHY_GIGABIT) |
| 3706 | mask |= ADVERTISED_1000baseT_Full; |
| 3707 | |
| 3708 | if ((ecmd->advertising & mask) == 0) |
| 3709 | return -EINVAL; |
| 3710 | |
| 3711 | } else if (ecmd->autoneg == AUTONEG_DISABLE) { |
| 3712 | /* Note: autonegotiation disable, speed 1000 intentionally |
| 3713 | * forbidden - noone should need that. */ |
| 3714 | |
| 3715 | if (ecmd->speed != SPEED_10 && ecmd->speed != SPEED_100) |
| 3716 | return -EINVAL; |
| 3717 | if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL) |
| 3718 | return -EINVAL; |
| 3719 | } else { |
| 3720 | return -EINVAL; |
| 3721 | } |
| 3722 | |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 3723 | netif_carrier_off(dev); |
| 3724 | if (netif_running(dev)) { |
| 3725 | nv_disable_irq(dev); |
Herbert Xu | 58dfd9c | 2006-06-21 10:53:54 +1000 | [diff] [blame] | 3726 | netif_tx_lock_bh(dev); |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 3727 | spin_lock(&np->lock); |
| 3728 | /* stop engines */ |
| 3729 | nv_stop_rx(dev); |
| 3730 | nv_stop_tx(dev); |
| 3731 | spin_unlock(&np->lock); |
Herbert Xu | 58dfd9c | 2006-06-21 10:53:54 +1000 | [diff] [blame] | 3732 | netif_tx_unlock_bh(dev); |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 3733 | } |
| 3734 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3735 | if (ecmd->autoneg == AUTONEG_ENABLE) { |
| 3736 | int adv, bmcr; |
| 3737 | |
| 3738 | np->autoneg = 1; |
| 3739 | |
| 3740 | /* advertise only what has been requested */ |
| 3741 | adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ); |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 3742 | adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3743 | if (ecmd->advertising & ADVERTISED_10baseT_Half) |
| 3744 | adv |= ADVERTISE_10HALF; |
| 3745 | if (ecmd->advertising & ADVERTISED_10baseT_Full) |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 3746 | adv |= ADVERTISE_10FULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3747 | if (ecmd->advertising & ADVERTISED_100baseT_Half) |
| 3748 | adv |= ADVERTISE_100HALF; |
| 3749 | if (ecmd->advertising & ADVERTISED_100baseT_Full) |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 3750 | adv |= ADVERTISE_100FULL; |
| 3751 | if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisments but disable tx pause */ |
| 3752 | adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 3753 | if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) |
| 3754 | adv |= ADVERTISE_PAUSE_ASYM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3755 | mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv); |
| 3756 | |
| 3757 | if (np->gigabit == PHY_GIGABIT) { |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 3758 | adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3759 | adv &= ~ADVERTISE_1000FULL; |
| 3760 | if (ecmd->advertising & ADVERTISED_1000baseT_Full) |
| 3761 | adv |= ADVERTISE_1000FULL; |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 3762 | mii_rw(dev, np->phyaddr, MII_CTRL1000, adv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3763 | } |
| 3764 | |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 3765 | if (netif_running(dev)) |
| 3766 | printk(KERN_INFO "%s: link down.\n", dev->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3767 | bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 3768 | if (np->phy_model == PHY_MODEL_MARVELL_E3016) { |
| 3769 | bmcr |= BMCR_ANENABLE; |
| 3770 | /* reset the phy in order for settings to stick, |
| 3771 | * and cause autoneg to start */ |
| 3772 | if (phy_reset(dev, bmcr)) { |
| 3773 | printk(KERN_INFO "%s: phy reset failed\n", dev->name); |
| 3774 | return -EINVAL; |
| 3775 | } |
| 3776 | } else { |
| 3777 | bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART); |
| 3778 | mii_rw(dev, np->phyaddr, MII_BMCR, bmcr); |
| 3779 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3780 | } else { |
| 3781 | int adv, bmcr; |
| 3782 | |
| 3783 | np->autoneg = 0; |
| 3784 | |
| 3785 | adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ); |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 3786 | adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3787 | if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_HALF) |
| 3788 | adv |= ADVERTISE_10HALF; |
| 3789 | if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_FULL) |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 3790 | adv |= ADVERTISE_10FULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3791 | if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_HALF) |
| 3792 | adv |= ADVERTISE_100HALF; |
| 3793 | if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_FULL) |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 3794 | adv |= ADVERTISE_100FULL; |
| 3795 | np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE); |
| 3796 | if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) {/* for rx we set both advertisments but disable tx pause */ |
| 3797 | adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 3798 | np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE; |
| 3799 | } |
| 3800 | if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) { |
| 3801 | adv |= ADVERTISE_PAUSE_ASYM; |
| 3802 | np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE; |
| 3803 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3804 | mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv); |
| 3805 | np->fixed_mode = adv; |
| 3806 | |
| 3807 | if (np->gigabit == PHY_GIGABIT) { |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 3808 | adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3809 | adv &= ~ADVERTISE_1000FULL; |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 3810 | mii_rw(dev, np->phyaddr, MII_CTRL1000, adv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3811 | } |
| 3812 | |
| 3813 | bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 3814 | bmcr &= ~(BMCR_ANENABLE|BMCR_SPEED100|BMCR_SPEED1000|BMCR_FULLDPLX); |
| 3815 | if (np->fixed_mode & (ADVERTISE_10FULL|ADVERTISE_100FULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3816 | bmcr |= BMCR_FULLDPLX; |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 3817 | if (np->fixed_mode & (ADVERTISE_100HALF|ADVERTISE_100FULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3818 | bmcr |= BMCR_SPEED100; |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 3819 | if (np->phy_oui == PHY_OUI_MARVELL) { |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 3820 | /* reset the phy in order for forced mode settings to stick */ |
| 3821 | if (phy_reset(dev, bmcr)) { |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 3822 | printk(KERN_INFO "%s: phy reset failed\n", dev->name); |
| 3823 | return -EINVAL; |
| 3824 | } |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 3825 | } else { |
| 3826 | mii_rw(dev, np->phyaddr, MII_BMCR, bmcr); |
| 3827 | if (netif_running(dev)) { |
| 3828 | /* Wait a bit and then reconfigure the nic. */ |
| 3829 | udelay(10); |
| 3830 | nv_linkchange(dev); |
| 3831 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3832 | } |
| 3833 | } |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 3834 | |
| 3835 | if (netif_running(dev)) { |
| 3836 | nv_start_rx(dev); |
| 3837 | nv_start_tx(dev); |
| 3838 | nv_enable_irq(dev); |
| 3839 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3840 | |
| 3841 | return 0; |
| 3842 | } |
| 3843 | |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 3844 | #define FORCEDETH_REGS_VER 1 |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 3845 | |
| 3846 | static int nv_get_regs_len(struct net_device *dev) |
| 3847 | { |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 3848 | struct fe_priv *np = netdev_priv(dev); |
| 3849 | return np->register_size; |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 3850 | } |
| 3851 | |
| 3852 | static void nv_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *buf) |
| 3853 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 3854 | struct fe_priv *np = netdev_priv(dev); |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 3855 | u8 __iomem *base = get_hwbase(dev); |
| 3856 | u32 *rbuf = buf; |
| 3857 | int i; |
| 3858 | |
| 3859 | regs->version = FORCEDETH_REGS_VER; |
| 3860 | spin_lock_irq(&np->lock); |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 3861 | for (i = 0;i <= np->register_size/sizeof(u32); i++) |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 3862 | rbuf[i] = readl(base + i*sizeof(u32)); |
| 3863 | spin_unlock_irq(&np->lock); |
| 3864 | } |
| 3865 | |
| 3866 | static int nv_nway_reset(struct net_device *dev) |
| 3867 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 3868 | struct fe_priv *np = netdev_priv(dev); |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 3869 | int ret; |
| 3870 | |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 3871 | if (np->autoneg) { |
| 3872 | int bmcr; |
| 3873 | |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 3874 | netif_carrier_off(dev); |
| 3875 | if (netif_running(dev)) { |
| 3876 | nv_disable_irq(dev); |
Herbert Xu | 58dfd9c | 2006-06-21 10:53:54 +1000 | [diff] [blame] | 3877 | netif_tx_lock_bh(dev); |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 3878 | spin_lock(&np->lock); |
| 3879 | /* stop engines */ |
| 3880 | nv_stop_rx(dev); |
| 3881 | nv_stop_tx(dev); |
| 3882 | spin_unlock(&np->lock); |
Herbert Xu | 58dfd9c | 2006-06-21 10:53:54 +1000 | [diff] [blame] | 3883 | netif_tx_unlock_bh(dev); |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 3884 | printk(KERN_INFO "%s: link down.\n", dev->name); |
| 3885 | } |
| 3886 | |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 3887 | bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 3888 | if (np->phy_model == PHY_MODEL_MARVELL_E3016) { |
| 3889 | bmcr |= BMCR_ANENABLE; |
| 3890 | /* reset the phy in order for settings to stick*/ |
| 3891 | if (phy_reset(dev, bmcr)) { |
| 3892 | printk(KERN_INFO "%s: phy reset failed\n", dev->name); |
| 3893 | return -EINVAL; |
| 3894 | } |
| 3895 | } else { |
| 3896 | bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART); |
| 3897 | mii_rw(dev, np->phyaddr, MII_BMCR, bmcr); |
| 3898 | } |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 3899 | |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 3900 | if (netif_running(dev)) { |
| 3901 | nv_start_rx(dev); |
| 3902 | nv_start_tx(dev); |
| 3903 | nv_enable_irq(dev); |
| 3904 | } |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 3905 | ret = 0; |
| 3906 | } else { |
| 3907 | ret = -EINVAL; |
| 3908 | } |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 3909 | |
| 3910 | return ret; |
| 3911 | } |
| 3912 | |
Zachary Amsden | 0674d59 | 2006-06-04 02:51:38 -0700 | [diff] [blame] | 3913 | static int nv_set_tso(struct net_device *dev, u32 value) |
| 3914 | { |
| 3915 | struct fe_priv *np = netdev_priv(dev); |
| 3916 | |
| 3917 | if ((np->driver_data & DEV_HAS_CHECKSUM)) |
| 3918 | return ethtool_op_set_tso(dev, value); |
| 3919 | else |
Ayaz Abdulla | 6a78814 | 2006-06-10 22:47:26 -0400 | [diff] [blame] | 3920 | return -EOPNOTSUPP; |
Zachary Amsden | 0674d59 | 2006-06-04 02:51:38 -0700 | [diff] [blame] | 3921 | } |
Zachary Amsden | 0674d59 | 2006-06-04 02:51:38 -0700 | [diff] [blame] | 3922 | |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 3923 | static void nv_get_ringparam(struct net_device *dev, struct ethtool_ringparam* ring) |
| 3924 | { |
| 3925 | struct fe_priv *np = netdev_priv(dev); |
| 3926 | |
| 3927 | ring->rx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3; |
| 3928 | ring->rx_mini_max_pending = 0; |
| 3929 | ring->rx_jumbo_max_pending = 0; |
| 3930 | ring->tx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3; |
| 3931 | |
| 3932 | ring->rx_pending = np->rx_ring_size; |
| 3933 | ring->rx_mini_pending = 0; |
| 3934 | ring->rx_jumbo_pending = 0; |
| 3935 | ring->tx_pending = np->tx_ring_size; |
| 3936 | } |
| 3937 | |
| 3938 | static int nv_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ring) |
| 3939 | { |
| 3940 | struct fe_priv *np = netdev_priv(dev); |
| 3941 | u8 __iomem *base = get_hwbase(dev); |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 3942 | u8 *rxtx_ring, *rx_skbuff, *tx_skbuff; |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 3943 | dma_addr_t ring_addr; |
| 3944 | |
| 3945 | if (ring->rx_pending < RX_RING_MIN || |
| 3946 | ring->tx_pending < TX_RING_MIN || |
| 3947 | ring->rx_mini_pending != 0 || |
| 3948 | ring->rx_jumbo_pending != 0 || |
| 3949 | (np->desc_ver == DESC_VER_1 && |
| 3950 | (ring->rx_pending > RING_MAX_DESC_VER_1 || |
| 3951 | ring->tx_pending > RING_MAX_DESC_VER_1)) || |
| 3952 | (np->desc_ver != DESC_VER_1 && |
| 3953 | (ring->rx_pending > RING_MAX_DESC_VER_2_3 || |
| 3954 | ring->tx_pending > RING_MAX_DESC_VER_2_3))) { |
| 3955 | return -EINVAL; |
| 3956 | } |
| 3957 | |
| 3958 | /* allocate new rings */ |
| 3959 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
| 3960 | rxtx_ring = pci_alloc_consistent(np->pci_dev, |
| 3961 | sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending), |
| 3962 | &ring_addr); |
| 3963 | } else { |
| 3964 | rxtx_ring = pci_alloc_consistent(np->pci_dev, |
| 3965 | sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending), |
| 3966 | &ring_addr); |
| 3967 | } |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 3968 | rx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->rx_pending, GFP_KERNEL); |
| 3969 | tx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->tx_pending, GFP_KERNEL); |
| 3970 | if (!rxtx_ring || !rx_skbuff || !tx_skbuff) { |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 3971 | /* fall back to old rings */ |
| 3972 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 3973 | if (rxtx_ring) |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 3974 | pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending), |
| 3975 | rxtx_ring, ring_addr); |
| 3976 | } else { |
| 3977 | if (rxtx_ring) |
| 3978 | pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending), |
| 3979 | rxtx_ring, ring_addr); |
| 3980 | } |
| 3981 | if (rx_skbuff) |
| 3982 | kfree(rx_skbuff); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 3983 | if (tx_skbuff) |
| 3984 | kfree(tx_skbuff); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 3985 | goto exit; |
| 3986 | } |
| 3987 | |
| 3988 | if (netif_running(dev)) { |
| 3989 | nv_disable_irq(dev); |
Herbert Xu | 58dfd9c | 2006-06-21 10:53:54 +1000 | [diff] [blame] | 3990 | netif_tx_lock_bh(dev); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 3991 | spin_lock(&np->lock); |
| 3992 | /* stop engines */ |
| 3993 | nv_stop_rx(dev); |
| 3994 | nv_stop_tx(dev); |
| 3995 | nv_txrx_reset(dev); |
| 3996 | /* drain queues */ |
| 3997 | nv_drain_rx(dev); |
| 3998 | nv_drain_tx(dev); |
| 3999 | /* delete queues */ |
| 4000 | free_rings(dev); |
| 4001 | } |
| 4002 | |
| 4003 | /* set new values */ |
| 4004 | np->rx_ring_size = ring->rx_pending; |
| 4005 | np->tx_ring_size = ring->tx_pending; |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4006 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
| 4007 | np->rx_ring.orig = (struct ring_desc*)rxtx_ring; |
| 4008 | np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size]; |
| 4009 | } else { |
| 4010 | np->rx_ring.ex = (struct ring_desc_ex*)rxtx_ring; |
| 4011 | np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size]; |
| 4012 | } |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 4013 | np->rx_skb = (struct nv_skb_map*)rx_skbuff; |
| 4014 | np->tx_skb = (struct nv_skb_map*)tx_skbuff; |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4015 | np->ring_addr = ring_addr; |
| 4016 | |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 4017 | memset(np->rx_skb, 0, sizeof(struct nv_skb_map) * np->rx_ring_size); |
| 4018 | memset(np->tx_skb, 0, sizeof(struct nv_skb_map) * np->tx_ring_size); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4019 | |
| 4020 | if (netif_running(dev)) { |
| 4021 | /* reinit driver view of the queues */ |
| 4022 | set_bufsize(dev); |
| 4023 | if (nv_init_ring(dev)) { |
| 4024 | if (!np->in_shutdown) |
| 4025 | mod_timer(&np->oom_kick, jiffies + OOM_REFILL); |
| 4026 | } |
| 4027 | |
| 4028 | /* reinit nic view of the queues */ |
| 4029 | writel(np->rx_buf_sz, base + NvRegOffloadConfig); |
| 4030 | setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING); |
| 4031 | writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT), |
| 4032 | base + NvRegRingSizes); |
| 4033 | pci_push(base); |
| 4034 | writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl); |
| 4035 | pci_push(base); |
| 4036 | |
| 4037 | /* restart engines */ |
| 4038 | nv_start_rx(dev); |
| 4039 | nv_start_tx(dev); |
| 4040 | spin_unlock(&np->lock); |
Herbert Xu | 58dfd9c | 2006-06-21 10:53:54 +1000 | [diff] [blame] | 4041 | netif_tx_unlock_bh(dev); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4042 | nv_enable_irq(dev); |
| 4043 | } |
| 4044 | return 0; |
| 4045 | exit: |
| 4046 | return -ENOMEM; |
| 4047 | } |
| 4048 | |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 4049 | static void nv_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause) |
| 4050 | { |
| 4051 | struct fe_priv *np = netdev_priv(dev); |
| 4052 | |
| 4053 | pause->autoneg = (np->pause_flags & NV_PAUSEFRAME_AUTONEG) != 0; |
| 4054 | pause->rx_pause = (np->pause_flags & NV_PAUSEFRAME_RX_ENABLE) != 0; |
| 4055 | pause->tx_pause = (np->pause_flags & NV_PAUSEFRAME_TX_ENABLE) != 0; |
| 4056 | } |
| 4057 | |
| 4058 | static int nv_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause) |
| 4059 | { |
| 4060 | struct fe_priv *np = netdev_priv(dev); |
| 4061 | int adv, bmcr; |
| 4062 | |
| 4063 | if ((!np->autoneg && np->duplex == 0) || |
| 4064 | (np->autoneg && !pause->autoneg && np->duplex == 0)) { |
| 4065 | printk(KERN_INFO "%s: can not set pause settings when forced link is in half duplex.\n", |
| 4066 | dev->name); |
| 4067 | return -EINVAL; |
| 4068 | } |
| 4069 | if (pause->tx_pause && !(np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)) { |
| 4070 | printk(KERN_INFO "%s: hardware does not support tx pause frames.\n", dev->name); |
| 4071 | return -EINVAL; |
| 4072 | } |
| 4073 | |
| 4074 | netif_carrier_off(dev); |
| 4075 | if (netif_running(dev)) { |
| 4076 | nv_disable_irq(dev); |
Herbert Xu | 58dfd9c | 2006-06-21 10:53:54 +1000 | [diff] [blame] | 4077 | netif_tx_lock_bh(dev); |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 4078 | spin_lock(&np->lock); |
| 4079 | /* stop engines */ |
| 4080 | nv_stop_rx(dev); |
| 4081 | nv_stop_tx(dev); |
| 4082 | spin_unlock(&np->lock); |
Herbert Xu | 58dfd9c | 2006-06-21 10:53:54 +1000 | [diff] [blame] | 4083 | netif_tx_unlock_bh(dev); |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 4084 | } |
| 4085 | |
| 4086 | np->pause_flags &= ~(NV_PAUSEFRAME_RX_REQ|NV_PAUSEFRAME_TX_REQ); |
| 4087 | if (pause->rx_pause) |
| 4088 | np->pause_flags |= NV_PAUSEFRAME_RX_REQ; |
| 4089 | if (pause->tx_pause) |
| 4090 | np->pause_flags |= NV_PAUSEFRAME_TX_REQ; |
| 4091 | |
| 4092 | if (np->autoneg && pause->autoneg) { |
| 4093 | np->pause_flags |= NV_PAUSEFRAME_AUTONEG; |
| 4094 | |
| 4095 | adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ); |
| 4096 | adv &= ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM); |
| 4097 | if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisments but disable tx pause */ |
| 4098 | adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 4099 | if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) |
| 4100 | adv |= ADVERTISE_PAUSE_ASYM; |
| 4101 | mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv); |
| 4102 | |
| 4103 | if (netif_running(dev)) |
| 4104 | printk(KERN_INFO "%s: link down.\n", dev->name); |
| 4105 | bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
| 4106 | bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART); |
| 4107 | mii_rw(dev, np->phyaddr, MII_BMCR, bmcr); |
| 4108 | } else { |
| 4109 | np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE); |
| 4110 | if (pause->rx_pause) |
| 4111 | np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE; |
| 4112 | if (pause->tx_pause) |
| 4113 | np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE; |
| 4114 | |
| 4115 | if (!netif_running(dev)) |
| 4116 | nv_update_linkspeed(dev); |
| 4117 | else |
| 4118 | nv_update_pause(dev, np->pause_flags); |
| 4119 | } |
| 4120 | |
| 4121 | if (netif_running(dev)) { |
| 4122 | nv_start_rx(dev); |
| 4123 | nv_start_tx(dev); |
| 4124 | nv_enable_irq(dev); |
| 4125 | } |
| 4126 | return 0; |
| 4127 | } |
| 4128 | |
Ayaz Abdulla | 5ed2616 | 2006-06-10 22:47:59 -0400 | [diff] [blame] | 4129 | static u32 nv_get_rx_csum(struct net_device *dev) |
| 4130 | { |
| 4131 | struct fe_priv *np = netdev_priv(dev); |
Ayaz Abdulla | f2ad2d9 | 2006-08-24 17:35:41 -0400 | [diff] [blame] | 4132 | return (np->rx_csum) != 0; |
Ayaz Abdulla | 5ed2616 | 2006-06-10 22:47:59 -0400 | [diff] [blame] | 4133 | } |
| 4134 | |
| 4135 | static int nv_set_rx_csum(struct net_device *dev, u32 data) |
| 4136 | { |
| 4137 | struct fe_priv *np = netdev_priv(dev); |
| 4138 | u8 __iomem *base = get_hwbase(dev); |
| 4139 | int retcode = 0; |
| 4140 | |
| 4141 | if (np->driver_data & DEV_HAS_CHECKSUM) { |
Ayaz Abdulla | 5ed2616 | 2006-06-10 22:47:59 -0400 | [diff] [blame] | 4142 | if (data) { |
Ayaz Abdulla | f2ad2d9 | 2006-08-24 17:35:41 -0400 | [diff] [blame] | 4143 | np->rx_csum = 1; |
Ayaz Abdulla | 5ed2616 | 2006-06-10 22:47:59 -0400 | [diff] [blame] | 4144 | np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK; |
Ayaz Abdulla | 5ed2616 | 2006-06-10 22:47:59 -0400 | [diff] [blame] | 4145 | } else { |
Ayaz Abdulla | f2ad2d9 | 2006-08-24 17:35:41 -0400 | [diff] [blame] | 4146 | np->rx_csum = 0; |
| 4147 | /* vlan is dependent on rx checksum offload */ |
| 4148 | if (!(np->vlanctl_bits & NVREG_VLANCONTROL_ENABLE)) |
| 4149 | np->txrxctl_bits &= ~NVREG_TXRXCTL_RXCHECK; |
Ayaz Abdulla | 5ed2616 | 2006-06-10 22:47:59 -0400 | [diff] [blame] | 4150 | } |
Ayaz Abdulla | 5ed2616 | 2006-06-10 22:47:59 -0400 | [diff] [blame] | 4151 | if (netif_running(dev)) { |
| 4152 | spin_lock_irq(&np->lock); |
| 4153 | writel(np->txrxctl_bits, base + NvRegTxRxControl); |
| 4154 | spin_unlock_irq(&np->lock); |
| 4155 | } |
| 4156 | } else { |
| 4157 | return -EINVAL; |
| 4158 | } |
| 4159 | |
| 4160 | return retcode; |
| 4161 | } |
| 4162 | |
| 4163 | static int nv_set_tx_csum(struct net_device *dev, u32 data) |
| 4164 | { |
| 4165 | struct fe_priv *np = netdev_priv(dev); |
| 4166 | |
| 4167 | if (np->driver_data & DEV_HAS_CHECKSUM) |
| 4168 | return ethtool_op_set_tx_hw_csum(dev, data); |
| 4169 | else |
| 4170 | return -EOPNOTSUPP; |
| 4171 | } |
| 4172 | |
| 4173 | static int nv_set_sg(struct net_device *dev, u32 data) |
| 4174 | { |
| 4175 | struct fe_priv *np = netdev_priv(dev); |
| 4176 | |
| 4177 | if (np->driver_data & DEV_HAS_CHECKSUM) |
| 4178 | return ethtool_op_set_sg(dev, data); |
| 4179 | else |
| 4180 | return -EOPNOTSUPP; |
| 4181 | } |
| 4182 | |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 4183 | static int nv_get_stats_count(struct net_device *dev) |
| 4184 | { |
| 4185 | struct fe_priv *np = netdev_priv(dev); |
| 4186 | |
| 4187 | if (np->driver_data & DEV_HAS_STATISTICS) |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 4188 | return sizeof(struct nv_ethtool_stats)/sizeof(u64); |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 4189 | else |
| 4190 | return 0; |
| 4191 | } |
| 4192 | |
| 4193 | static void nv_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *estats, u64 *buffer) |
| 4194 | { |
| 4195 | struct fe_priv *np = netdev_priv(dev); |
| 4196 | |
| 4197 | /* update stats */ |
| 4198 | nv_do_stats_poll((unsigned long)dev); |
| 4199 | |
| 4200 | memcpy(buffer, &np->estats, nv_get_stats_count(dev)*sizeof(u64)); |
| 4201 | } |
| 4202 | |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 4203 | static int nv_self_test_count(struct net_device *dev) |
| 4204 | { |
| 4205 | struct fe_priv *np = netdev_priv(dev); |
| 4206 | |
| 4207 | if (np->driver_data & DEV_HAS_TEST_EXTENDED) |
| 4208 | return NV_TEST_COUNT_EXTENDED; |
| 4209 | else |
| 4210 | return NV_TEST_COUNT_BASE; |
| 4211 | } |
| 4212 | |
| 4213 | static int nv_link_test(struct net_device *dev) |
| 4214 | { |
| 4215 | struct fe_priv *np = netdev_priv(dev); |
| 4216 | int mii_status; |
| 4217 | |
| 4218 | mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ); |
| 4219 | mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ); |
| 4220 | |
| 4221 | /* check phy link status */ |
| 4222 | if (!(mii_status & BMSR_LSTATUS)) |
| 4223 | return 0; |
| 4224 | else |
| 4225 | return 1; |
| 4226 | } |
| 4227 | |
| 4228 | static int nv_register_test(struct net_device *dev) |
| 4229 | { |
| 4230 | u8 __iomem *base = get_hwbase(dev); |
| 4231 | int i = 0; |
| 4232 | u32 orig_read, new_read; |
| 4233 | |
| 4234 | do { |
| 4235 | orig_read = readl(base + nv_registers_test[i].reg); |
| 4236 | |
| 4237 | /* xor with mask to toggle bits */ |
| 4238 | orig_read ^= nv_registers_test[i].mask; |
| 4239 | |
| 4240 | writel(orig_read, base + nv_registers_test[i].reg); |
| 4241 | |
| 4242 | new_read = readl(base + nv_registers_test[i].reg); |
| 4243 | |
| 4244 | if ((new_read & nv_registers_test[i].mask) != (orig_read & nv_registers_test[i].mask)) |
| 4245 | return 0; |
| 4246 | |
| 4247 | /* restore original value */ |
| 4248 | orig_read ^= nv_registers_test[i].mask; |
| 4249 | writel(orig_read, base + nv_registers_test[i].reg); |
| 4250 | |
| 4251 | } while (nv_registers_test[++i].reg != 0); |
| 4252 | |
| 4253 | return 1; |
| 4254 | } |
| 4255 | |
| 4256 | static int nv_interrupt_test(struct net_device *dev) |
| 4257 | { |
| 4258 | struct fe_priv *np = netdev_priv(dev); |
| 4259 | u8 __iomem *base = get_hwbase(dev); |
| 4260 | int ret = 1; |
| 4261 | int testcnt; |
| 4262 | u32 save_msi_flags, save_poll_interval = 0; |
| 4263 | |
| 4264 | if (netif_running(dev)) { |
| 4265 | /* free current irq */ |
| 4266 | nv_free_irq(dev); |
| 4267 | save_poll_interval = readl(base+NvRegPollingInterval); |
| 4268 | } |
| 4269 | |
| 4270 | /* flag to test interrupt handler */ |
| 4271 | np->intr_test = 0; |
| 4272 | |
| 4273 | /* setup test irq */ |
| 4274 | save_msi_flags = np->msi_flags; |
| 4275 | np->msi_flags &= ~NV_MSI_X_VECTORS_MASK; |
| 4276 | np->msi_flags |= 0x001; /* setup 1 vector */ |
| 4277 | if (nv_request_irq(dev, 1)) |
| 4278 | return 0; |
| 4279 | |
| 4280 | /* setup timer interrupt */ |
| 4281 | writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval); |
| 4282 | writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6); |
| 4283 | |
| 4284 | nv_enable_hw_interrupts(dev, NVREG_IRQ_TIMER); |
| 4285 | |
| 4286 | /* wait for at least one interrupt */ |
| 4287 | msleep(100); |
| 4288 | |
| 4289 | spin_lock_irq(&np->lock); |
| 4290 | |
| 4291 | /* flag should be set within ISR */ |
| 4292 | testcnt = np->intr_test; |
| 4293 | if (!testcnt) |
| 4294 | ret = 2; |
| 4295 | |
| 4296 | nv_disable_hw_interrupts(dev, NVREG_IRQ_TIMER); |
| 4297 | if (!(np->msi_flags & NV_MSI_X_ENABLED)) |
| 4298 | writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus); |
| 4299 | else |
| 4300 | writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus); |
| 4301 | |
| 4302 | spin_unlock_irq(&np->lock); |
| 4303 | |
| 4304 | nv_free_irq(dev); |
| 4305 | |
| 4306 | np->msi_flags = save_msi_flags; |
| 4307 | |
| 4308 | if (netif_running(dev)) { |
| 4309 | writel(save_poll_interval, base + NvRegPollingInterval); |
| 4310 | writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6); |
| 4311 | /* restore original irq */ |
| 4312 | if (nv_request_irq(dev, 0)) |
| 4313 | return 0; |
| 4314 | } |
| 4315 | |
| 4316 | return ret; |
| 4317 | } |
| 4318 | |
| 4319 | static int nv_loopback_test(struct net_device *dev) |
| 4320 | { |
| 4321 | struct fe_priv *np = netdev_priv(dev); |
| 4322 | u8 __iomem *base = get_hwbase(dev); |
| 4323 | struct sk_buff *tx_skb, *rx_skb; |
| 4324 | dma_addr_t test_dma_addr; |
| 4325 | u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET); |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 4326 | u32 flags; |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 4327 | int len, i, pkt_len; |
| 4328 | u8 *pkt_data; |
| 4329 | u32 filter_flags = 0; |
| 4330 | u32 misc1_flags = 0; |
| 4331 | int ret = 1; |
| 4332 | |
| 4333 | if (netif_running(dev)) { |
| 4334 | nv_disable_irq(dev); |
| 4335 | filter_flags = readl(base + NvRegPacketFilterFlags); |
| 4336 | misc1_flags = readl(base + NvRegMisc1); |
| 4337 | } else { |
| 4338 | nv_txrx_reset(dev); |
| 4339 | } |
| 4340 | |
| 4341 | /* reinit driver view of the rx queue */ |
| 4342 | set_bufsize(dev); |
| 4343 | nv_init_ring(dev); |
| 4344 | |
| 4345 | /* setup hardware for loopback */ |
| 4346 | writel(NVREG_MISC1_FORCE, base + NvRegMisc1); |
| 4347 | writel(NVREG_PFF_ALWAYS | NVREG_PFF_LOOPBACK, base + NvRegPacketFilterFlags); |
| 4348 | |
| 4349 | /* reinit nic view of the rx queue */ |
| 4350 | writel(np->rx_buf_sz, base + NvRegOffloadConfig); |
| 4351 | setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING); |
| 4352 | writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT), |
| 4353 | base + NvRegRingSizes); |
| 4354 | pci_push(base); |
| 4355 | |
| 4356 | /* restart rx engine */ |
| 4357 | nv_start_rx(dev); |
| 4358 | nv_start_tx(dev); |
| 4359 | |
| 4360 | /* setup packet for tx */ |
| 4361 | pkt_len = ETH_DATA_LEN; |
| 4362 | tx_skb = dev_alloc_skb(pkt_len); |
Jesper Juhl | 46798c8 | 2006-09-25 16:39:24 -0700 | [diff] [blame] | 4363 | if (!tx_skb) { |
| 4364 | printk(KERN_ERR "dev_alloc_skb() failed during loopback test" |
| 4365 | " of %s\n", dev->name); |
| 4366 | ret = 0; |
| 4367 | goto out; |
| 4368 | } |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 4369 | pkt_data = skb_put(tx_skb, pkt_len); |
| 4370 | for (i = 0; i < pkt_len; i++) |
| 4371 | pkt_data[i] = (u8)(i & 0xff); |
| 4372 | test_dma_addr = pci_map_single(np->pci_dev, tx_skb->data, |
| 4373 | tx_skb->end-tx_skb->data, PCI_DMA_FROMDEVICE); |
| 4374 | |
| 4375 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 4376 | np->tx_ring.orig[0].buf = cpu_to_le32(test_dma_addr); |
| 4377 | np->tx_ring.orig[0].flaglen = cpu_to_le32((pkt_len-1) | np->tx_flags | tx_flags_extra); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 4378 | } else { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 4379 | np->tx_ring.ex[0].bufhigh = cpu_to_le64(test_dma_addr) >> 32; |
| 4380 | np->tx_ring.ex[0].buflow = cpu_to_le64(test_dma_addr) & 0x0FFFFFFFF; |
| 4381 | np->tx_ring.ex[0].flaglen = cpu_to_le32((pkt_len-1) | np->tx_flags | tx_flags_extra); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 4382 | } |
| 4383 | writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl); |
| 4384 | pci_push(get_hwbase(dev)); |
| 4385 | |
| 4386 | msleep(500); |
| 4387 | |
| 4388 | /* check for rx of the packet */ |
| 4389 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 4390 | flags = le32_to_cpu(np->rx_ring.orig[0].flaglen); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 4391 | len = nv_descr_getlength(&np->rx_ring.orig[0], np->desc_ver); |
| 4392 | |
| 4393 | } else { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 4394 | flags = le32_to_cpu(np->rx_ring.ex[0].flaglen); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 4395 | len = nv_descr_getlength_ex(&np->rx_ring.ex[0], np->desc_ver); |
| 4396 | } |
| 4397 | |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 4398 | if (flags & NV_RX_AVAIL) { |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 4399 | ret = 0; |
| 4400 | } else if (np->desc_ver == DESC_VER_1) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 4401 | if (flags & NV_RX_ERROR) |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 4402 | ret = 0; |
| 4403 | } else { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 4404 | if (flags & NV_RX2_ERROR) { |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 4405 | ret = 0; |
| 4406 | } |
| 4407 | } |
| 4408 | |
| 4409 | if (ret) { |
| 4410 | if (len != pkt_len) { |
| 4411 | ret = 0; |
| 4412 | dprintk(KERN_DEBUG "%s: loopback len mismatch %d vs %d\n", |
| 4413 | dev->name, len, pkt_len); |
| 4414 | } else { |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 4415 | rx_skb = np->rx_skb[0].skb; |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 4416 | for (i = 0; i < pkt_len; i++) { |
| 4417 | if (rx_skb->data[i] != (u8)(i & 0xff)) { |
| 4418 | ret = 0; |
| 4419 | dprintk(KERN_DEBUG "%s: loopback pattern check failed on byte %d\n", |
| 4420 | dev->name, i); |
| 4421 | break; |
| 4422 | } |
| 4423 | } |
| 4424 | } |
| 4425 | } else { |
| 4426 | dprintk(KERN_DEBUG "%s: loopback - did not receive test packet\n", dev->name); |
| 4427 | } |
| 4428 | |
| 4429 | pci_unmap_page(np->pci_dev, test_dma_addr, |
| 4430 | tx_skb->end-tx_skb->data, |
| 4431 | PCI_DMA_TODEVICE); |
| 4432 | dev_kfree_skb_any(tx_skb); |
Jesper Juhl | 46798c8 | 2006-09-25 16:39:24 -0700 | [diff] [blame] | 4433 | out: |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 4434 | /* stop engines */ |
| 4435 | nv_stop_rx(dev); |
| 4436 | nv_stop_tx(dev); |
| 4437 | nv_txrx_reset(dev); |
| 4438 | /* drain rx queue */ |
| 4439 | nv_drain_rx(dev); |
| 4440 | nv_drain_tx(dev); |
| 4441 | |
| 4442 | if (netif_running(dev)) { |
| 4443 | writel(misc1_flags, base + NvRegMisc1); |
| 4444 | writel(filter_flags, base + NvRegPacketFilterFlags); |
| 4445 | nv_enable_irq(dev); |
| 4446 | } |
| 4447 | |
| 4448 | return ret; |
| 4449 | } |
| 4450 | |
| 4451 | static void nv_self_test(struct net_device *dev, struct ethtool_test *test, u64 *buffer) |
| 4452 | { |
| 4453 | struct fe_priv *np = netdev_priv(dev); |
| 4454 | u8 __iomem *base = get_hwbase(dev); |
| 4455 | int result; |
| 4456 | memset(buffer, 0, nv_self_test_count(dev)*sizeof(u64)); |
| 4457 | |
| 4458 | if (!nv_link_test(dev)) { |
| 4459 | test->flags |= ETH_TEST_FL_FAILED; |
| 4460 | buffer[0] = 1; |
| 4461 | } |
| 4462 | |
| 4463 | if (test->flags & ETH_TEST_FL_OFFLINE) { |
| 4464 | if (netif_running(dev)) { |
| 4465 | netif_stop_queue(dev); |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 4466 | netif_poll_disable(dev); |
Herbert Xu | 58dfd9c | 2006-06-21 10:53:54 +1000 | [diff] [blame] | 4467 | netif_tx_lock_bh(dev); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 4468 | spin_lock_irq(&np->lock); |
| 4469 | nv_disable_hw_interrupts(dev, np->irqmask); |
| 4470 | if (!(np->msi_flags & NV_MSI_X_ENABLED)) { |
| 4471 | writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus); |
| 4472 | } else { |
| 4473 | writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus); |
| 4474 | } |
| 4475 | /* stop engines */ |
| 4476 | nv_stop_rx(dev); |
| 4477 | nv_stop_tx(dev); |
| 4478 | nv_txrx_reset(dev); |
| 4479 | /* drain rx queue */ |
| 4480 | nv_drain_rx(dev); |
| 4481 | nv_drain_tx(dev); |
| 4482 | spin_unlock_irq(&np->lock); |
Herbert Xu | 58dfd9c | 2006-06-21 10:53:54 +1000 | [diff] [blame] | 4483 | netif_tx_unlock_bh(dev); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 4484 | } |
| 4485 | |
| 4486 | if (!nv_register_test(dev)) { |
| 4487 | test->flags |= ETH_TEST_FL_FAILED; |
| 4488 | buffer[1] = 1; |
| 4489 | } |
| 4490 | |
| 4491 | result = nv_interrupt_test(dev); |
| 4492 | if (result != 1) { |
| 4493 | test->flags |= ETH_TEST_FL_FAILED; |
| 4494 | buffer[2] = 1; |
| 4495 | } |
| 4496 | if (result == 0) { |
| 4497 | /* bail out */ |
| 4498 | return; |
| 4499 | } |
| 4500 | |
| 4501 | if (!nv_loopback_test(dev)) { |
| 4502 | test->flags |= ETH_TEST_FL_FAILED; |
| 4503 | buffer[3] = 1; |
| 4504 | } |
| 4505 | |
| 4506 | if (netif_running(dev)) { |
| 4507 | /* reinit driver view of the rx queue */ |
| 4508 | set_bufsize(dev); |
| 4509 | if (nv_init_ring(dev)) { |
| 4510 | if (!np->in_shutdown) |
| 4511 | mod_timer(&np->oom_kick, jiffies + OOM_REFILL); |
| 4512 | } |
| 4513 | /* reinit nic view of the rx queue */ |
| 4514 | writel(np->rx_buf_sz, base + NvRegOffloadConfig); |
| 4515 | setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING); |
| 4516 | writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT), |
| 4517 | base + NvRegRingSizes); |
| 4518 | pci_push(base); |
| 4519 | writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl); |
| 4520 | pci_push(base); |
| 4521 | /* restart rx engine */ |
| 4522 | nv_start_rx(dev); |
| 4523 | nv_start_tx(dev); |
| 4524 | netif_start_queue(dev); |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 4525 | netif_poll_enable(dev); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 4526 | nv_enable_hw_interrupts(dev, np->irqmask); |
| 4527 | } |
| 4528 | } |
| 4529 | } |
| 4530 | |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 4531 | static void nv_get_strings(struct net_device *dev, u32 stringset, u8 *buffer) |
| 4532 | { |
| 4533 | switch (stringset) { |
| 4534 | case ETH_SS_STATS: |
| 4535 | memcpy(buffer, &nv_estats_str, nv_get_stats_count(dev)*sizeof(struct nv_ethtool_str)); |
| 4536 | break; |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 4537 | case ETH_SS_TEST: |
| 4538 | memcpy(buffer, &nv_etests_str, nv_self_test_count(dev)*sizeof(struct nv_ethtool_str)); |
| 4539 | break; |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 4540 | } |
| 4541 | } |
| 4542 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 4543 | static const struct ethtool_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4544 | .get_drvinfo = nv_get_drvinfo, |
| 4545 | .get_link = ethtool_op_get_link, |
| 4546 | .get_wol = nv_get_wol, |
| 4547 | .set_wol = nv_set_wol, |
| 4548 | .get_settings = nv_get_settings, |
| 4549 | .set_settings = nv_set_settings, |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 4550 | .get_regs_len = nv_get_regs_len, |
| 4551 | .get_regs = nv_get_regs, |
| 4552 | .nway_reset = nv_nway_reset, |
John W. Linville | c704b85 | 2005-09-12 10:48:56 -0400 | [diff] [blame] | 4553 | .get_perm_addr = ethtool_op_get_perm_addr, |
Zachary Amsden | 0674d59 | 2006-06-04 02:51:38 -0700 | [diff] [blame] | 4554 | .get_tso = ethtool_op_get_tso, |
Ayaz Abdulla | 6a78814 | 2006-06-10 22:47:26 -0400 | [diff] [blame] | 4555 | .set_tso = nv_set_tso, |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4556 | .get_ringparam = nv_get_ringparam, |
| 4557 | .set_ringparam = nv_set_ringparam, |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 4558 | .get_pauseparam = nv_get_pauseparam, |
| 4559 | .set_pauseparam = nv_set_pauseparam, |
Ayaz Abdulla | 5ed2616 | 2006-06-10 22:47:59 -0400 | [diff] [blame] | 4560 | .get_rx_csum = nv_get_rx_csum, |
| 4561 | .set_rx_csum = nv_set_rx_csum, |
| 4562 | .get_tx_csum = ethtool_op_get_tx_csum, |
| 4563 | .set_tx_csum = nv_set_tx_csum, |
| 4564 | .get_sg = ethtool_op_get_sg, |
| 4565 | .set_sg = nv_set_sg, |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 4566 | .get_strings = nv_get_strings, |
| 4567 | .get_stats_count = nv_get_stats_count, |
| 4568 | .get_ethtool_stats = nv_get_ethtool_stats, |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 4569 | .self_test_count = nv_self_test_count, |
| 4570 | .self_test = nv_self_test, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4571 | }; |
| 4572 | |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 4573 | static void nv_vlan_rx_register(struct net_device *dev, struct vlan_group *grp) |
| 4574 | { |
| 4575 | struct fe_priv *np = get_nvpriv(dev); |
| 4576 | |
| 4577 | spin_lock_irq(&np->lock); |
| 4578 | |
| 4579 | /* save vlan group */ |
| 4580 | np->vlangrp = grp; |
| 4581 | |
| 4582 | if (grp) { |
| 4583 | /* enable vlan on MAC */ |
| 4584 | np->txrxctl_bits |= NVREG_TXRXCTL_VLANSTRIP | NVREG_TXRXCTL_VLANINS; |
| 4585 | } else { |
| 4586 | /* disable vlan on MAC */ |
| 4587 | np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANSTRIP; |
| 4588 | np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANINS; |
| 4589 | } |
| 4590 | |
| 4591 | writel(np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl); |
| 4592 | |
| 4593 | spin_unlock_irq(&np->lock); |
| 4594 | }; |
| 4595 | |
| 4596 | static void nv_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid) |
| 4597 | { |
| 4598 | /* nothing to do */ |
| 4599 | }; |
| 4600 | |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 4601 | /* The mgmt unit and driver use a semaphore to access the phy during init */ |
| 4602 | static int nv_mgmt_acquire_sema(struct net_device *dev) |
| 4603 | { |
| 4604 | u8 __iomem *base = get_hwbase(dev); |
| 4605 | int i; |
| 4606 | u32 tx_ctrl, mgmt_sema; |
| 4607 | |
| 4608 | for (i = 0; i < 10; i++) { |
| 4609 | mgmt_sema = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_SEMA_MASK; |
| 4610 | if (mgmt_sema == NVREG_XMITCTL_MGMT_SEMA_FREE) |
| 4611 | break; |
| 4612 | msleep(500); |
| 4613 | } |
| 4614 | |
| 4615 | if (mgmt_sema != NVREG_XMITCTL_MGMT_SEMA_FREE) |
| 4616 | return 0; |
| 4617 | |
| 4618 | for (i = 0; i < 2; i++) { |
| 4619 | tx_ctrl = readl(base + NvRegTransmitterControl); |
| 4620 | tx_ctrl |= NVREG_XMITCTL_HOST_SEMA_ACQ; |
| 4621 | writel(tx_ctrl, base + NvRegTransmitterControl); |
| 4622 | |
| 4623 | /* verify that semaphore was acquired */ |
| 4624 | tx_ctrl = readl(base + NvRegTransmitterControl); |
| 4625 | if (((tx_ctrl & NVREG_XMITCTL_HOST_SEMA_MASK) == NVREG_XMITCTL_HOST_SEMA_ACQ) && |
| 4626 | ((tx_ctrl & NVREG_XMITCTL_MGMT_SEMA_MASK) == NVREG_XMITCTL_MGMT_SEMA_FREE)) |
| 4627 | return 1; |
| 4628 | else |
| 4629 | udelay(50); |
| 4630 | } |
| 4631 | |
| 4632 | return 0; |
| 4633 | } |
| 4634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4635 | static int nv_open(struct net_device *dev) |
| 4636 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 4637 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4638 | u8 __iomem *base = get_hwbase(dev); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 4639 | int ret = 1; |
| 4640 | int oom, i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4641 | |
| 4642 | dprintk(KERN_DEBUG "nv_open: begin\n"); |
| 4643 | |
Ayaz Abdulla | f148965 | 2006-07-31 12:04:45 -0400 | [diff] [blame] | 4644 | /* erase previous misconfiguration */ |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 4645 | if (np->driver_data & DEV_HAS_POWER_CNTRL) |
| 4646 | nv_mac_reset(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4647 | writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA); |
| 4648 | writel(0, base + NvRegMulticastAddrB); |
| 4649 | writel(0, base + NvRegMulticastMaskA); |
| 4650 | writel(0, base + NvRegMulticastMaskB); |
| 4651 | writel(0, base + NvRegPacketFilterFlags); |
| 4652 | |
| 4653 | writel(0, base + NvRegTransmitterControl); |
| 4654 | writel(0, base + NvRegReceiverControl); |
| 4655 | |
| 4656 | writel(0, base + NvRegAdapterControl); |
| 4657 | |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 4658 | if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE) |
| 4659 | writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame); |
| 4660 | |
Ayaz Abdulla | f148965 | 2006-07-31 12:04:45 -0400 | [diff] [blame] | 4661 | /* initialize descriptor rings */ |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 4662 | set_bufsize(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4663 | oom = nv_init_ring(dev); |
| 4664 | |
| 4665 | writel(0, base + NvRegLinkSpeed); |
Ayaz Abdulla | 5070d34 | 2006-07-31 12:05:01 -0400 | [diff] [blame] | 4666 | writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4667 | nv_txrx_reset(dev); |
| 4668 | writel(0, base + NvRegUnknownSetupReg6); |
| 4669 | |
| 4670 | np->in_shutdown = 0; |
| 4671 | |
Ayaz Abdulla | f148965 | 2006-07-31 12:04:45 -0400 | [diff] [blame] | 4672 | /* give hw rings */ |
Ayaz Abdulla | 0832b25 | 2006-02-04 13:13:26 -0500 | [diff] [blame] | 4673 | setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4674 | writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4675 | base + NvRegRingSizes); |
| 4676 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4677 | writel(np->linkspeed, base + NvRegLinkSpeed); |
Ayaz Abdulla | 95d161c | 2006-07-06 16:46:25 -0400 | [diff] [blame] | 4678 | if (np->desc_ver == DESC_VER_1) |
| 4679 | writel(NVREG_TX_WM_DESC1_DEFAULT, base + NvRegTxWatermark); |
| 4680 | else |
| 4681 | writel(NVREG_TX_WM_DESC2_3_DEFAULT, base + NvRegTxWatermark); |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 4682 | writel(np->txrxctl_bits, base + NvRegTxRxControl); |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 4683 | writel(np->vlanctl_bits, base + NvRegVlanControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4684 | pci_push(base); |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 4685 | writel(NVREG_TXRXCTL_BIT1|np->txrxctl_bits, base + NvRegTxRxControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4686 | reg_delay(dev, NvRegUnknownSetupReg5, NVREG_UNKSETUP5_BIT31, NVREG_UNKSETUP5_BIT31, |
| 4687 | NV_SETUP5_DELAY, NV_SETUP5_DELAYMAX, |
| 4688 | KERN_INFO "open: SetupReg5, Bit 31 remained off\n"); |
| 4689 | |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 4690 | writel(0, base + NvRegMIIMask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4691 | writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus); |
| 4692 | writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus); |
| 4693 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4694 | writel(NVREG_MISC1_FORCE | NVREG_MISC1_HD, base + NvRegMisc1); |
| 4695 | writel(readl(base + NvRegTransmitterStatus), base + NvRegTransmitterStatus); |
| 4696 | writel(NVREG_PFF_ALWAYS, base + NvRegPacketFilterFlags); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 4697 | writel(np->rx_buf_sz, base + NvRegOffloadConfig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4698 | |
| 4699 | writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus); |
| 4700 | get_random_bytes(&i, sizeof(i)); |
| 4701 | writel(NVREG_RNDSEED_FORCE | (i&NVREG_RNDSEED_MASK), base + NvRegRandomSeed); |
Ayaz Abdulla | 9744e21 | 2006-07-06 16:45:58 -0400 | [diff] [blame] | 4702 | writel(NVREG_TX_DEFERRAL_DEFAULT, base + NvRegTxDeferral); |
| 4703 | writel(NVREG_RX_DEFERRAL_DEFAULT, base + NvRegRxDeferral); |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 4704 | if (poll_interval == -1) { |
| 4705 | if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT) |
| 4706 | writel(NVREG_POLL_DEFAULT_THROUGHPUT, base + NvRegPollingInterval); |
| 4707 | else |
| 4708 | writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval); |
| 4709 | } |
| 4710 | else |
| 4711 | writel(poll_interval & 0xFFFF, base + NvRegPollingInterval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4712 | writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6); |
| 4713 | writel((np->phyaddr << NVREG_ADAPTCTL_PHYSHIFT)|NVREG_ADAPTCTL_PHYVALID|NVREG_ADAPTCTL_RUNNING, |
| 4714 | base + NvRegAdapterControl); |
| 4715 | writel(NVREG_MIISPEED_BIT8|NVREG_MIIDELAY, base + NvRegMIISpeed); |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 4716 | writel(NVREG_MII_LINKCHANGE, base + NvRegMIIMask); |
Ayaz Abdulla | c42d9df | 2006-06-10 22:47:52 -0400 | [diff] [blame] | 4717 | if (np->wolenabled) |
| 4718 | writel(NVREG_WAKEUPFLAGS_ENABLE , base + NvRegWakeUpFlags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4719 | |
| 4720 | i = readl(base + NvRegPowerState); |
| 4721 | if ( (i & NVREG_POWERSTATE_POWEREDUP) == 0) |
| 4722 | writel(NVREG_POWERSTATE_POWEREDUP|i, base + NvRegPowerState); |
| 4723 | |
| 4724 | pci_push(base); |
| 4725 | udelay(10); |
| 4726 | writel(readl(base + NvRegPowerState) | NVREG_POWERSTATE_VALID, base + NvRegPowerState); |
| 4727 | |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 4728 | nv_disable_hw_interrupts(dev, np->irqmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4729 | pci_push(base); |
| 4730 | writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus); |
| 4731 | writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus); |
| 4732 | pci_push(base); |
| 4733 | |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 4734 | if (nv_request_irq(dev, 0)) { |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 4735 | goto out_drain; |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 4736 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4737 | |
| 4738 | /* ask for interrupts */ |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 4739 | nv_enable_hw_interrupts(dev, np->irqmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4740 | |
| 4741 | spin_lock_irq(&np->lock); |
| 4742 | writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA); |
| 4743 | writel(0, base + NvRegMulticastAddrB); |
| 4744 | writel(0, base + NvRegMulticastMaskA); |
| 4745 | writel(0, base + NvRegMulticastMaskB); |
| 4746 | writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags); |
| 4747 | /* One manual link speed update: Interrupts are enabled, future link |
| 4748 | * speed changes cause interrupts and are handled by nv_link_irq(). |
| 4749 | */ |
| 4750 | { |
| 4751 | u32 miistat; |
| 4752 | miistat = readl(base + NvRegMIIStatus); |
| 4753 | writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus); |
| 4754 | dprintk(KERN_INFO "startup: got 0x%08x.\n", miistat); |
| 4755 | } |
Manfred Spraul | 1b1b3c9 | 2005-08-06 23:47:55 +0200 | [diff] [blame] | 4756 | /* set linkspeed to invalid value, thus force nv_update_linkspeed |
| 4757 | * to init hw */ |
| 4758 | np->linkspeed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4759 | ret = nv_update_linkspeed(dev); |
| 4760 | nv_start_rx(dev); |
| 4761 | nv_start_tx(dev); |
| 4762 | netif_start_queue(dev); |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 4763 | netif_poll_enable(dev); |
| 4764 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4765 | if (ret) { |
| 4766 | netif_carrier_on(dev); |
| 4767 | } else { |
| 4768 | printk("%s: no link during initialization.\n", dev->name); |
| 4769 | netif_carrier_off(dev); |
| 4770 | } |
| 4771 | if (oom) |
| 4772 | mod_timer(&np->oom_kick, jiffies + OOM_REFILL); |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 4773 | |
| 4774 | /* start statistics timer */ |
| 4775 | if (np->driver_data & DEV_HAS_STATISTICS) |
| 4776 | mod_timer(&np->stats_poll, jiffies + STATS_INTERVAL); |
| 4777 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4778 | spin_unlock_irq(&np->lock); |
| 4779 | |
| 4780 | return 0; |
| 4781 | out_drain: |
| 4782 | drain_ring(dev); |
| 4783 | return ret; |
| 4784 | } |
| 4785 | |
| 4786 | static int nv_close(struct net_device *dev) |
| 4787 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 4788 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4789 | u8 __iomem *base; |
| 4790 | |
| 4791 | spin_lock_irq(&np->lock); |
| 4792 | np->in_shutdown = 1; |
| 4793 | spin_unlock_irq(&np->lock); |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 4794 | netif_poll_disable(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4795 | synchronize_irq(dev->irq); |
| 4796 | |
| 4797 | del_timer_sync(&np->oom_kick); |
| 4798 | del_timer_sync(&np->nic_poll); |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 4799 | del_timer_sync(&np->stats_poll); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4800 | |
| 4801 | netif_stop_queue(dev); |
| 4802 | spin_lock_irq(&np->lock); |
| 4803 | nv_stop_tx(dev); |
| 4804 | nv_stop_rx(dev); |
| 4805 | nv_txrx_reset(dev); |
| 4806 | |
| 4807 | /* disable interrupts on the nic or we will lock up */ |
| 4808 | base = get_hwbase(dev); |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 4809 | nv_disable_hw_interrupts(dev, np->irqmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4810 | pci_push(base); |
| 4811 | dprintk(KERN_INFO "%s: Irqmask is zero again\n", dev->name); |
| 4812 | |
| 4813 | spin_unlock_irq(&np->lock); |
| 4814 | |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 4815 | nv_free_irq(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4816 | |
| 4817 | drain_ring(dev); |
| 4818 | |
| 4819 | if (np->wolenabled) |
| 4820 | nv_start_rx(dev); |
| 4821 | |
| 4822 | /* FIXME: power down nic */ |
| 4823 | |
| 4824 | return 0; |
| 4825 | } |
| 4826 | |
| 4827 | static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id) |
| 4828 | { |
| 4829 | struct net_device *dev; |
| 4830 | struct fe_priv *np; |
| 4831 | unsigned long addr; |
| 4832 | u8 __iomem *base; |
| 4833 | int err, i; |
Ayaz Abdulla | 5070d34 | 2006-07-31 12:05:01 -0400 | [diff] [blame] | 4834 | u32 powerstate, txreg; |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 4835 | u32 phystate_orig = 0, phystate; |
| 4836 | int phyinitialized = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4837 | |
| 4838 | dev = alloc_etherdev(sizeof(struct fe_priv)); |
| 4839 | err = -ENOMEM; |
| 4840 | if (!dev) |
| 4841 | goto out; |
| 4842 | |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 4843 | np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4844 | np->pci_dev = pci_dev; |
| 4845 | spin_lock_init(&np->lock); |
| 4846 | SET_MODULE_OWNER(dev); |
| 4847 | SET_NETDEV_DEV(dev, &pci_dev->dev); |
| 4848 | |
| 4849 | init_timer(&np->oom_kick); |
| 4850 | np->oom_kick.data = (unsigned long) dev; |
| 4851 | np->oom_kick.function = &nv_do_rx_refill; /* timer handler */ |
| 4852 | init_timer(&np->nic_poll); |
| 4853 | np->nic_poll.data = (unsigned long) dev; |
| 4854 | np->nic_poll.function = &nv_do_nic_poll; /* timer handler */ |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 4855 | init_timer(&np->stats_poll); |
| 4856 | np->stats_poll.data = (unsigned long) dev; |
| 4857 | np->stats_poll.function = &nv_do_stats_poll; /* timer handler */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4858 | |
| 4859 | err = pci_enable_device(pci_dev); |
| 4860 | if (err) { |
| 4861 | printk(KERN_INFO "forcedeth: pci_enable_dev failed (%d) for device %s\n", |
| 4862 | err, pci_name(pci_dev)); |
| 4863 | goto out_free; |
| 4864 | } |
| 4865 | |
| 4866 | pci_set_master(pci_dev); |
| 4867 | |
| 4868 | err = pci_request_regions(pci_dev, DRV_NAME); |
| 4869 | if (err < 0) |
| 4870 | goto out_disable; |
| 4871 | |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 4872 | if (id->driver_data & (DEV_HAS_VLAN|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS)) |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 4873 | np->register_size = NV_PCI_REGSZ_VER2; |
| 4874 | else |
| 4875 | np->register_size = NV_PCI_REGSZ_VER1; |
| 4876 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4877 | err = -EINVAL; |
| 4878 | addr = 0; |
| 4879 | for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { |
| 4880 | dprintk(KERN_DEBUG "%s: resource %d start %p len %ld flags 0x%08lx.\n", |
| 4881 | pci_name(pci_dev), i, (void*)pci_resource_start(pci_dev, i), |
| 4882 | pci_resource_len(pci_dev, i), |
| 4883 | pci_resource_flags(pci_dev, i)); |
| 4884 | if (pci_resource_flags(pci_dev, i) & IORESOURCE_MEM && |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 4885 | pci_resource_len(pci_dev, i) >= np->register_size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4886 | addr = pci_resource_start(pci_dev, i); |
| 4887 | break; |
| 4888 | } |
| 4889 | } |
| 4890 | if (i == DEVICE_COUNT_RESOURCE) { |
| 4891 | printk(KERN_INFO "forcedeth: Couldn't find register window for device %s.\n", |
| 4892 | pci_name(pci_dev)); |
| 4893 | goto out_relreg; |
| 4894 | } |
| 4895 | |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 4896 | /* copy of driver data */ |
| 4897 | np->driver_data = id->driver_data; |
| 4898 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4899 | /* handle different descriptor versions */ |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 4900 | if (id->driver_data & DEV_HAS_HIGH_DMA) { |
| 4901 | /* packet format 3: supports 40-bit addressing */ |
| 4902 | np->desc_ver = DESC_VER_3; |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 4903 | np->txrxctl_bits = NVREG_TXRXCTL_DESC_3; |
Ayaz Abdulla | 69fe3fd | 2006-06-10 22:48:18 -0400 | [diff] [blame] | 4904 | if (dma_64bit) { |
| 4905 | if (pci_set_dma_mask(pci_dev, DMA_39BIT_MASK)) { |
| 4906 | printk(KERN_INFO "forcedeth: 64-bit DMA failed, using 32-bit addressing for device %s.\n", |
| 4907 | pci_name(pci_dev)); |
| 4908 | } else { |
| 4909 | dev->features |= NETIF_F_HIGHDMA; |
| 4910 | printk(KERN_INFO "forcedeth: using HIGHDMA\n"); |
| 4911 | } |
| 4912 | if (pci_set_consistent_dma_mask(pci_dev, DMA_39BIT_MASK)) { |
| 4913 | printk(KERN_INFO "forcedeth: 64-bit DMA (consistent) failed, using 32-bit ring buffers for device %s.\n", |
| 4914 | pci_name(pci_dev)); |
| 4915 | } |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 4916 | } |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 4917 | } else if (id->driver_data & DEV_HAS_LARGEDESC) { |
| 4918 | /* packet format 2: supports jumbo frames */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4919 | np->desc_ver = DESC_VER_2; |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 4920 | np->txrxctl_bits = NVREG_TXRXCTL_DESC_2; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 4921 | } else { |
| 4922 | /* original packet format */ |
| 4923 | np->desc_ver = DESC_VER_1; |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 4924 | np->txrxctl_bits = NVREG_TXRXCTL_DESC_1; |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 4925 | } |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 4926 | |
| 4927 | np->pkt_limit = NV_PKTLIMIT_1; |
| 4928 | if (id->driver_data & DEV_HAS_LARGEDESC) |
| 4929 | np->pkt_limit = NV_PKTLIMIT_2; |
| 4930 | |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 4931 | if (id->driver_data & DEV_HAS_CHECKSUM) { |
Ayaz Abdulla | f2ad2d9 | 2006-08-24 17:35:41 -0400 | [diff] [blame] | 4932 | np->rx_csum = 1; |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 4933 | np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 4934 | dev->features |= NETIF_F_HW_CSUM | NETIF_F_SG; |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 4935 | dev->features |= NETIF_F_TSO; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 4936 | } |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 4937 | |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 4938 | np->vlanctl_bits = 0; |
| 4939 | if (id->driver_data & DEV_HAS_VLAN) { |
| 4940 | np->vlanctl_bits = NVREG_VLANCONTROL_ENABLE; |
| 4941 | dev->features |= NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX; |
| 4942 | dev->vlan_rx_register = nv_vlan_rx_register; |
| 4943 | dev->vlan_rx_kill_vid = nv_vlan_rx_kill_vid; |
| 4944 | } |
| 4945 | |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 4946 | np->msi_flags = 0; |
Ayaz Abdulla | 69fe3fd | 2006-06-10 22:48:18 -0400 | [diff] [blame] | 4947 | if ((id->driver_data & DEV_HAS_MSI) && msi) { |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 4948 | np->msi_flags |= NV_MSI_CAPABLE; |
| 4949 | } |
Ayaz Abdulla | 69fe3fd | 2006-06-10 22:48:18 -0400 | [diff] [blame] | 4950 | if ((id->driver_data & DEV_HAS_MSI_X) && msix) { |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 4951 | np->msi_flags |= NV_MSI_X_CAPABLE; |
| 4952 | } |
| 4953 | |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 4954 | np->pause_flags = NV_PAUSEFRAME_RX_CAPABLE | NV_PAUSEFRAME_RX_REQ | NV_PAUSEFRAME_AUTONEG; |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 4955 | if (id->driver_data & DEV_HAS_PAUSEFRAME_TX) { |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 4956 | np->pause_flags |= NV_PAUSEFRAME_TX_CAPABLE | NV_PAUSEFRAME_TX_REQ; |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 4957 | } |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 4958 | |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 4959 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4960 | err = -ENOMEM; |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 4961 | np->base = ioremap(addr, np->register_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4962 | if (!np->base) |
| 4963 | goto out_relreg; |
| 4964 | dev->base_addr = (unsigned long)np->base; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 4965 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4966 | dev->irq = pci_dev->irq; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 4967 | |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4968 | np->rx_ring_size = RX_RING_DEFAULT; |
| 4969 | np->tx_ring_size = TX_RING_DEFAULT; |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4970 | |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 4971 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) { |
| 4972 | np->rx_ring.orig = pci_alloc_consistent(pci_dev, |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4973 | sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size), |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 4974 | &np->ring_addr); |
| 4975 | if (!np->rx_ring.orig) |
| 4976 | goto out_unmap; |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4977 | np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size]; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 4978 | } else { |
| 4979 | np->rx_ring.ex = pci_alloc_consistent(pci_dev, |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4980 | sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size), |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 4981 | &np->ring_addr); |
| 4982 | if (!np->rx_ring.ex) |
| 4983 | goto out_unmap; |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4984 | np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size]; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 4985 | } |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 4986 | np->rx_skb = kmalloc(sizeof(struct nv_skb_map) * np->rx_ring_size, GFP_KERNEL); |
| 4987 | np->tx_skb = kmalloc(sizeof(struct nv_skb_map) * np->tx_ring_size, GFP_KERNEL); |
| 4988 | if (!np->rx_skb || !np->tx_skb) |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4989 | goto out_freering; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 4990 | memset(np->rx_skb, 0, sizeof(struct nv_skb_map) * np->rx_ring_size); |
| 4991 | memset(np->tx_skb, 0, sizeof(struct nv_skb_map) * np->tx_ring_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4992 | |
| 4993 | dev->open = nv_open; |
| 4994 | dev->stop = nv_close; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 4995 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
| 4996 | dev->hard_start_xmit = nv_start_xmit; |
| 4997 | else |
| 4998 | dev->hard_start_xmit = nv_start_xmit_optimized; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4999 | dev->get_stats = nv_get_stats; |
| 5000 | dev->change_mtu = nv_change_mtu; |
Manfred Spraul | 72b3178 | 2005-07-31 18:33:34 +0200 | [diff] [blame] | 5001 | dev->set_mac_address = nv_set_mac_address; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5002 | dev->set_multicast_list = nv_set_multicast; |
Michal Schmidt | 2918c35 | 2005-05-12 19:42:06 -0400 | [diff] [blame] | 5003 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5004 | dev->poll_controller = nv_poll_controller; |
| 5005 | #endif |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 5006 | dev->weight = 64; |
| 5007 | #ifdef CONFIG_FORCEDETH_NAPI |
| 5008 | dev->poll = nv_napi_poll; |
| 5009 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5010 | SET_ETHTOOL_OPS(dev, &ops); |
| 5011 | dev->tx_timeout = nv_tx_timeout; |
| 5012 | dev->watchdog_timeo = NV_WATCHDOG_TIMEO; |
| 5013 | |
| 5014 | pci_set_drvdata(pci_dev, dev); |
| 5015 | |
| 5016 | /* read the mac address */ |
| 5017 | base = get_hwbase(dev); |
| 5018 | np->orig_mac[0] = readl(base + NvRegMacAddrA); |
| 5019 | np->orig_mac[1] = readl(base + NvRegMacAddrB); |
| 5020 | |
Ayaz Abdulla | 5070d34 | 2006-07-31 12:05:01 -0400 | [diff] [blame] | 5021 | /* check the workaround bit for correct mac address order */ |
| 5022 | txreg = readl(base + NvRegTransmitPoll); |
| 5023 | if (txreg & NVREG_TRANSMITPOLL_MAC_ADDR_REV) { |
| 5024 | /* mac address is already in correct order */ |
| 5025 | dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff; |
| 5026 | dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff; |
| 5027 | dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff; |
| 5028 | dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff; |
| 5029 | dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff; |
| 5030 | dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff; |
| 5031 | } else { |
| 5032 | /* need to reverse mac address to correct order */ |
| 5033 | dev->dev_addr[0] = (np->orig_mac[1] >> 8) & 0xff; |
| 5034 | dev->dev_addr[1] = (np->orig_mac[1] >> 0) & 0xff; |
| 5035 | dev->dev_addr[2] = (np->orig_mac[0] >> 24) & 0xff; |
| 5036 | dev->dev_addr[3] = (np->orig_mac[0] >> 16) & 0xff; |
| 5037 | dev->dev_addr[4] = (np->orig_mac[0] >> 8) & 0xff; |
| 5038 | dev->dev_addr[5] = (np->orig_mac[0] >> 0) & 0xff; |
| 5039 | /* set permanent address to be correct aswell */ |
| 5040 | np->orig_mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) + |
| 5041 | (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24); |
| 5042 | np->orig_mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8); |
| 5043 | writel(txreg|NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll); |
| 5044 | } |
John W. Linville | c704b85 | 2005-09-12 10:48:56 -0400 | [diff] [blame] | 5045 | memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5046 | |
John W. Linville | c704b85 | 2005-09-12 10:48:56 -0400 | [diff] [blame] | 5047 | if (!is_valid_ether_addr(dev->perm_addr)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5048 | /* |
| 5049 | * Bad mac address. At least one bios sets the mac address |
| 5050 | * to 01:23:45:67:89:ab |
| 5051 | */ |
| 5052 | printk(KERN_ERR "%s: Invalid Mac address detected: %02x:%02x:%02x:%02x:%02x:%02x\n", |
| 5053 | pci_name(pci_dev), |
| 5054 | dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2], |
| 5055 | dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]); |
| 5056 | printk(KERN_ERR "Please complain to your hardware vendor. Switching to a random MAC.\n"); |
| 5057 | dev->dev_addr[0] = 0x00; |
| 5058 | dev->dev_addr[1] = 0x00; |
| 5059 | dev->dev_addr[2] = 0x6c; |
| 5060 | get_random_bytes(&dev->dev_addr[3], 3); |
| 5061 | } |
| 5062 | |
| 5063 | dprintk(KERN_DEBUG "%s: MAC Address %02x:%02x:%02x:%02x:%02x:%02x\n", pci_name(pci_dev), |
| 5064 | dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2], |
| 5065 | dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]); |
| 5066 | |
Ayaz Abdulla | f148965 | 2006-07-31 12:04:45 -0400 | [diff] [blame] | 5067 | /* set mac address */ |
| 5068 | nv_copy_mac_to_hw(dev); |
| 5069 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5070 | /* disable WOL */ |
| 5071 | writel(0, base + NvRegWakeUpFlags); |
| 5072 | np->wolenabled = 0; |
| 5073 | |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 5074 | if (id->driver_data & DEV_HAS_POWER_CNTRL) { |
| 5075 | u8 revision_id; |
| 5076 | pci_read_config_byte(pci_dev, PCI_REVISION_ID, &revision_id); |
| 5077 | |
| 5078 | /* take phy and nic out of low power mode */ |
| 5079 | powerstate = readl(base + NvRegPowerState2); |
| 5080 | powerstate &= ~NVREG_POWERSTATE2_POWERUP_MASK; |
| 5081 | if ((id->device == PCI_DEVICE_ID_NVIDIA_NVENET_12 || |
| 5082 | id->device == PCI_DEVICE_ID_NVIDIA_NVENET_13) && |
| 5083 | revision_id >= 0xA3) |
| 5084 | powerstate |= NVREG_POWERSTATE2_POWERUP_REV_A3; |
| 5085 | writel(powerstate, base + NvRegPowerState2); |
| 5086 | } |
| 5087 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5088 | if (np->desc_ver == DESC_VER_1) { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 5089 | np->tx_flags = NV_TX_VALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5090 | } else { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 5091 | np->tx_flags = NV_TX2_VALID; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5092 | } |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 5093 | if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT) { |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 5094 | np->irqmask = NVREG_IRQMASK_THROUGHPUT; |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 5095 | if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */ |
| 5096 | np->msi_flags |= 0x0003; |
| 5097 | } else { |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 5098 | np->irqmask = NVREG_IRQMASK_CPU; |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 5099 | if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */ |
| 5100 | np->msi_flags |= 0x0001; |
| 5101 | } |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 5102 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5103 | if (id->driver_data & DEV_NEED_TIMERIRQ) |
| 5104 | np->irqmask |= NVREG_IRQ_TIMER; |
| 5105 | if (id->driver_data & DEV_NEED_LINKTIMER) { |
| 5106 | dprintk(KERN_INFO "%s: link timer on.\n", pci_name(pci_dev)); |
| 5107 | np->need_linktimer = 1; |
| 5108 | np->link_timeout = jiffies + LINK_TIMEOUT; |
| 5109 | } else { |
| 5110 | dprintk(KERN_INFO "%s: link timer off.\n", pci_name(pci_dev)); |
| 5111 | np->need_linktimer = 0; |
| 5112 | } |
| 5113 | |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5114 | /* clear phy state and temporarily halt phy interrupts */ |
| 5115 | writel(0, base + NvRegMIIMask); |
| 5116 | phystate = readl(base + NvRegAdapterControl); |
| 5117 | if (phystate & NVREG_ADAPTCTL_RUNNING) { |
| 5118 | phystate_orig = 1; |
| 5119 | phystate &= ~NVREG_ADAPTCTL_RUNNING; |
| 5120 | writel(phystate, base + NvRegAdapterControl); |
| 5121 | } |
| 5122 | writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus); |
| 5123 | |
| 5124 | if (id->driver_data & DEV_HAS_MGMT_UNIT) { |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5125 | /* management unit running on the mac? */ |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 5126 | if (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_PHY_INIT) { |
| 5127 | np->mac_in_use = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_ST; |
| 5128 | dprintk(KERN_INFO "%s: mgmt unit is running. mac in use %x.\n", pci_name(pci_dev), np->mac_in_use); |
| 5129 | for (i = 0; i < 5000; i++) { |
| 5130 | msleep(1); |
| 5131 | if (nv_mgmt_acquire_sema(dev)) { |
| 5132 | /* management unit setup the phy already? */ |
| 5133 | if ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK) == |
| 5134 | NVREG_XMITCTL_SYNC_PHY_INIT) { |
| 5135 | /* phy is inited by mgmt unit */ |
| 5136 | phyinitialized = 1; |
| 5137 | dprintk(KERN_INFO "%s: Phy already initialized by mgmt unit.\n", pci_name(pci_dev)); |
| 5138 | } else { |
| 5139 | /* we need to init the phy */ |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5140 | } |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 5141 | break; |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5142 | } |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5143 | } |
| 5144 | } |
| 5145 | } |
| 5146 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5147 | /* find a suitable phy */ |
Ayaz Abdulla | 7a33e45 | 2005-11-11 08:31:11 -0500 | [diff] [blame] | 5148 | for (i = 1; i <= 32; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5149 | int id1, id2; |
Ayaz Abdulla | 7a33e45 | 2005-11-11 08:31:11 -0500 | [diff] [blame] | 5150 | int phyaddr = i & 0x1F; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5151 | |
| 5152 | spin_lock_irq(&np->lock); |
Ayaz Abdulla | 7a33e45 | 2005-11-11 08:31:11 -0500 | [diff] [blame] | 5153 | id1 = mii_rw(dev, phyaddr, MII_PHYSID1, MII_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5154 | spin_unlock_irq(&np->lock); |
| 5155 | if (id1 < 0 || id1 == 0xffff) |
| 5156 | continue; |
| 5157 | spin_lock_irq(&np->lock); |
Ayaz Abdulla | 7a33e45 | 2005-11-11 08:31:11 -0500 | [diff] [blame] | 5158 | id2 = mii_rw(dev, phyaddr, MII_PHYSID2, MII_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5159 | spin_unlock_irq(&np->lock); |
| 5160 | if (id2 < 0 || id2 == 0xffff) |
| 5161 | continue; |
| 5162 | |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 5163 | np->phy_model = id2 & PHYID2_MODEL_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5164 | id1 = (id1 & PHYID1_OUI_MASK) << PHYID1_OUI_SHFT; |
| 5165 | id2 = (id2 & PHYID2_OUI_MASK) >> PHYID2_OUI_SHFT; |
| 5166 | 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] | 5167 | pci_name(pci_dev), id1, id2, phyaddr); |
| 5168 | np->phyaddr = phyaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5169 | np->phy_oui = id1 | id2; |
| 5170 | break; |
| 5171 | } |
Ayaz Abdulla | 7a33e45 | 2005-11-11 08:31:11 -0500 | [diff] [blame] | 5172 | if (i == 33) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5173 | printk(KERN_INFO "%s: open: Could not find a valid PHY.\n", |
Ayaz Abdulla | 7a33e45 | 2005-11-11 08:31:11 -0500 | [diff] [blame] | 5174 | pci_name(pci_dev)); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 5175 | goto out_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5176 | } |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 5177 | |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5178 | if (!phyinitialized) { |
| 5179 | /* reset it */ |
| 5180 | phy_init(dev); |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 5181 | } else { |
| 5182 | /* see if it is a gigabit phy */ |
| 5183 | u32 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ); |
| 5184 | if (mii_status & PHY_GIGABIT) { |
| 5185 | np->gigabit = PHY_GIGABIT; |
| 5186 | } |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5187 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5188 | |
| 5189 | /* set default link speed settings */ |
| 5190 | np->linkspeed = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 5191 | np->duplex = 0; |
| 5192 | np->autoneg = 1; |
| 5193 | |
| 5194 | err = register_netdev(dev); |
| 5195 | if (err) { |
| 5196 | printk(KERN_INFO "forcedeth: unable to register netdev: %d\n", err); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 5197 | goto out_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5198 | } |
| 5199 | printk(KERN_INFO "%s: forcedeth.c: subsystem: %05x:%04x bound to %s\n", |
| 5200 | dev->name, pci_dev->subsystem_vendor, pci_dev->subsystem_device, |
| 5201 | pci_name(pci_dev)); |
| 5202 | |
| 5203 | return 0; |
| 5204 | |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 5205 | out_error: |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5206 | if (phystate_orig) |
| 5207 | writel(phystate|NVREG_ADAPTCTL_RUNNING, base + NvRegAdapterControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5208 | pci_set_drvdata(pci_dev, NULL); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 5209 | out_freering: |
| 5210 | free_rings(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5211 | out_unmap: |
| 5212 | iounmap(get_hwbase(dev)); |
| 5213 | out_relreg: |
| 5214 | pci_release_regions(pci_dev); |
| 5215 | out_disable: |
| 5216 | pci_disable_device(pci_dev); |
| 5217 | out_free: |
| 5218 | free_netdev(dev); |
| 5219 | out: |
| 5220 | return err; |
| 5221 | } |
| 5222 | |
| 5223 | static void __devexit nv_remove(struct pci_dev *pci_dev) |
| 5224 | { |
| 5225 | struct net_device *dev = pci_get_drvdata(pci_dev); |
Ayaz Abdulla | f148965 | 2006-07-31 12:04:45 -0400 | [diff] [blame] | 5226 | struct fe_priv *np = netdev_priv(dev); |
| 5227 | u8 __iomem *base = get_hwbase(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5228 | |
| 5229 | unregister_netdev(dev); |
| 5230 | |
Ayaz Abdulla | f148965 | 2006-07-31 12:04:45 -0400 | [diff] [blame] | 5231 | /* special op: write back the misordered MAC address - otherwise |
| 5232 | * the next nv_probe would see a wrong address. |
| 5233 | */ |
| 5234 | writel(np->orig_mac[0], base + NvRegMacAddrA); |
| 5235 | writel(np->orig_mac[1], base + NvRegMacAddrB); |
| 5236 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5237 | /* free all structures */ |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 5238 | free_rings(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5239 | iounmap(get_hwbase(dev)); |
| 5240 | pci_release_regions(pci_dev); |
| 5241 | pci_disable_device(pci_dev); |
| 5242 | free_netdev(dev); |
| 5243 | pci_set_drvdata(pci_dev, NULL); |
| 5244 | } |
| 5245 | |
Francois Romieu | a189317 | 2006-10-10 14:33:27 -0700 | [diff] [blame] | 5246 | #ifdef CONFIG_PM |
| 5247 | static int nv_suspend(struct pci_dev *pdev, pm_message_t state) |
| 5248 | { |
| 5249 | struct net_device *dev = pci_get_drvdata(pdev); |
| 5250 | struct fe_priv *np = netdev_priv(dev); |
| 5251 | |
| 5252 | if (!netif_running(dev)) |
| 5253 | goto out; |
| 5254 | |
| 5255 | netif_device_detach(dev); |
| 5256 | |
| 5257 | // Gross. |
| 5258 | nv_close(dev); |
| 5259 | |
| 5260 | pci_save_state(pdev); |
| 5261 | pci_enable_wake(pdev, pci_choose_state(pdev, state), np->wolenabled); |
| 5262 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 5263 | out: |
| 5264 | return 0; |
| 5265 | } |
| 5266 | |
| 5267 | static int nv_resume(struct pci_dev *pdev) |
| 5268 | { |
| 5269 | struct net_device *dev = pci_get_drvdata(pdev); |
| 5270 | int rc = 0; |
| 5271 | |
| 5272 | if (!netif_running(dev)) |
| 5273 | goto out; |
| 5274 | |
| 5275 | netif_device_attach(dev); |
| 5276 | |
| 5277 | pci_set_power_state(pdev, PCI_D0); |
| 5278 | pci_restore_state(pdev); |
| 5279 | pci_enable_wake(pdev, PCI_D0, 0); |
| 5280 | |
| 5281 | rc = nv_open(dev); |
| 5282 | out: |
| 5283 | return rc; |
| 5284 | } |
| 5285 | #else |
| 5286 | #define nv_suspend NULL |
| 5287 | #define nv_resume NULL |
| 5288 | #endif /* CONFIG_PM */ |
| 5289 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5290 | static struct pci_device_id pci_tbl[] = { |
| 5291 | { /* nForce Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 5292 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_1), |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 5293 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5294 | }, |
| 5295 | { /* nForce2 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 5296 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_2), |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 5297 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5298 | }, |
| 5299 | { /* nForce3 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 5300 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_3), |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 5301 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5302 | }, |
| 5303 | { /* nForce3 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 5304 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_4), |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 5305 | .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] | 5306 | }, |
| 5307 | { /* nForce3 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 5308 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_5), |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 5309 | .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] | 5310 | }, |
| 5311 | { /* nForce3 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 5312 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_6), |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 5313 | .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] | 5314 | }, |
| 5315 | { /* nForce3 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 5316 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_7), |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 5317 | .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] | 5318 | }, |
| 5319 | { /* CK804 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 5320 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_8), |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 5321 | .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] | 5322 | }, |
| 5323 | { /* CK804 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 5324 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_9), |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 5325 | .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] | 5326 | }, |
| 5327 | { /* MCP04 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 5328 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_10), |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 5329 | .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] | 5330 | }, |
| 5331 | { /* MCP04 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 5332 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_11), |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 5333 | .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] | 5334 | }, |
| 5335 | { /* MCP51 Ethernet Controller */ |
| 5336 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_12), |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 5337 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5338 | }, |
Manfred Spraul | 9992d4a | 2005-06-05 17:36:11 +0200 | [diff] [blame] | 5339 | { /* MCP51 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 5340 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_13), |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 5341 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL, |
Manfred Spraul | 9992d4a | 2005-06-05 17:36:11 +0200 | [diff] [blame] | 5342 | }, |
Manfred Spraul | f49d16e | 2005-06-26 11:36:52 +0200 | [diff] [blame] | 5343 | { /* MCP55 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 5344 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_14), |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5345 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_VLAN|DEV_HAS_MSI|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT, |
Manfred Spraul | f49d16e | 2005-06-26 11:36:52 +0200 | [diff] [blame] | 5346 | }, |
| 5347 | { /* MCP55 Ethernet Controller */ |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 5348 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_15), |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5349 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_VLAN|DEV_HAS_MSI|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT, |
Manfred Spraul | f49d16e | 2005-06-26 11:36:52 +0200 | [diff] [blame] | 5350 | }, |
Ayaz Abdulla | c99ce7e | 2006-06-10 22:48:28 -0400 | [diff] [blame] | 5351 | { /* MCP61 Ethernet Controller */ |
| 5352 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_16), |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5353 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT, |
Ayaz Abdulla | c99ce7e | 2006-06-10 22:48:28 -0400 | [diff] [blame] | 5354 | }, |
| 5355 | { /* MCP61 Ethernet Controller */ |
| 5356 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_17), |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5357 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT, |
Ayaz Abdulla | c99ce7e | 2006-06-10 22:48:28 -0400 | [diff] [blame] | 5358 | }, |
| 5359 | { /* MCP61 Ethernet Controller */ |
| 5360 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_18), |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5361 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT, |
Ayaz Abdulla | c99ce7e | 2006-06-10 22:48:28 -0400 | [diff] [blame] | 5362 | }, |
| 5363 | { /* MCP61 Ethernet Controller */ |
| 5364 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_19), |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5365 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT, |
Ayaz Abdulla | c99ce7e | 2006-06-10 22:48:28 -0400 | [diff] [blame] | 5366 | }, |
| 5367 | { /* MCP65 Ethernet Controller */ |
| 5368 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_20), |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5369 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT, |
Ayaz Abdulla | c99ce7e | 2006-06-10 22:48:28 -0400 | [diff] [blame] | 5370 | }, |
| 5371 | { /* MCP65 Ethernet Controller */ |
| 5372 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_21), |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5373 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT, |
Ayaz Abdulla | c99ce7e | 2006-06-10 22:48:28 -0400 | [diff] [blame] | 5374 | }, |
| 5375 | { /* MCP65 Ethernet Controller */ |
| 5376 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_22), |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5377 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT, |
Ayaz Abdulla | c99ce7e | 2006-06-10 22:48:28 -0400 | [diff] [blame] | 5378 | }, |
| 5379 | { /* MCP65 Ethernet Controller */ |
| 5380 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_23), |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5381 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT, |
Ayaz Abdulla | c99ce7e | 2006-06-10 22:48:28 -0400 | [diff] [blame] | 5382 | }, |
Ayaz Abdulla | f434484 | 2006-11-06 00:43:40 -0800 | [diff] [blame] | 5383 | { /* MCP67 Ethernet Controller */ |
| 5384 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_24), |
| 5385 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT, |
| 5386 | }, |
| 5387 | { /* MCP67 Ethernet Controller */ |
| 5388 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_25), |
| 5389 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT, |
| 5390 | }, |
| 5391 | { /* MCP67 Ethernet Controller */ |
| 5392 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_26), |
| 5393 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT, |
| 5394 | }, |
| 5395 | { /* MCP67 Ethernet Controller */ |
| 5396 | PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_27), |
| 5397 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX|DEV_HAS_STATISTICS|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT, |
| 5398 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5399 | {0,}, |
| 5400 | }; |
| 5401 | |
| 5402 | static struct pci_driver driver = { |
| 5403 | .name = "forcedeth", |
| 5404 | .id_table = pci_tbl, |
| 5405 | .probe = nv_probe, |
| 5406 | .remove = __devexit_p(nv_remove), |
Francois Romieu | a189317 | 2006-10-10 14:33:27 -0700 | [diff] [blame] | 5407 | .suspend = nv_suspend, |
| 5408 | .resume = nv_resume, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5409 | }; |
| 5410 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5411 | static int __init init_nic(void) |
| 5412 | { |
| 5413 | printk(KERN_INFO "forcedeth.c: Reverse Engineered nForce ethernet driver. Version %s.\n", FORCEDETH_VERSION); |
Jeff Garzik | 2991762 | 2006-08-19 17:48:59 -0400 | [diff] [blame] | 5414 | return pci_register_driver(&driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5415 | } |
| 5416 | |
| 5417 | static void __exit exit_nic(void) |
| 5418 | { |
| 5419 | pci_unregister_driver(&driver); |
| 5420 | } |
| 5421 | |
| 5422 | module_param(max_interrupt_work, int, 0); |
| 5423 | MODULE_PARM_DESC(max_interrupt_work, "forcedeth maximum events handled per interrupt"); |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 5424 | module_param(optimization_mode, int, 0); |
| 5425 | 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."); |
| 5426 | module_param(poll_interval, int, 0); |
| 5427 | 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."); |
Ayaz Abdulla | 69fe3fd | 2006-06-10 22:48:18 -0400 | [diff] [blame] | 5428 | module_param(msi, int, 0); |
| 5429 | MODULE_PARM_DESC(msi, "MSI interrupts are enabled by setting to 1 and disabled by setting to 0."); |
| 5430 | module_param(msix, int, 0); |
| 5431 | MODULE_PARM_DESC(msix, "MSIX interrupts are enabled by setting to 1 and disabled by setting to 0."); |
| 5432 | module_param(dma_64bit, int, 0); |
| 5433 | MODULE_PARM_DESC(dma_64bit, "High DMA is enabled by setting to 1 and disabled by setting to 0."); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5434 | |
| 5435 | MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>"); |
| 5436 | MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver"); |
| 5437 | MODULE_LICENSE("GPL"); |
| 5438 | |
| 5439 | MODULE_DEVICE_TABLE(pci, pci_tbl); |
| 5440 | |
| 5441 | module_init(init_nic); |
| 5442 | module_exit(exit_nic); |