blob: 75906ade76f5fc050c57a4f11fc72e5c809dc06d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
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 Abdulla87046e52006-12-19 23:33:32 -05006 * and Andrew de Quincey.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
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 Spraul18360982005-12-24 14:19:24 +010012 * Copyright (C) 2003,4,5 Manfred Spraul
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * 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 Abdulla87046e52006-12-19 23:33:32 -050016 * Copyright (c) 2004,5,6 NVIDIA Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 *
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 Abdulla4ea7f292005-11-11 08:29:59 -050082 * capabilities.
Manfred Spraul22c6d142005-04-19 21:17:09 +020083 * 0.32: 16 Apr 2005: RX_ERROR4 handling added.
Manfred Spraul8f767fc2005-06-18 16:27:19 +020084 * 0.33: 16 May 2005: Support for MCP51 added.
85 * 0.34: 18 Jun 2005: Add DEV_NEED_LINKTIMER to all nForce nics.
Manfred Spraulf49d16e2005-06-26 11:36:52 +020086 * 0.35: 26 Jun 2005: Support for MCP55 added.
Manfred Sprauldc8216c2005-07-31 18:26:05 +020087 * 0.36: 28 Jun 2005: Add jumbo frame support.
88 * 0.37: 10 Jul 2005: Additional ethtool support, cleanup of pci id list
Manfred Spraulc2dba062005-07-31 18:29:47 +020089 * 0.38: 16 Jul 2005: tx irq rewrite: Use global flags instead of
90 * per-packet flags.
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -050091 * 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 Spraulb3df9f82005-07-31 18:38:58 +020094 * of nv_remove
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -050095 * 0.42: 06 Aug 2005: Fix lack of link speed initialization
Manfred Spraul1b1b3c92005-08-06 23:47:55 +020096 * in the second (and later) nv_open call
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -050097 * 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 Abdullaa971c322005-11-11 08:30:38 -0500100 * 0.46: 20 Oct 2005: Add irq optimization modes.
Ayaz Abdulla7a33e452005-11-11 08:31:11 -0500101 * 0.47: 26 Oct 2005: Add phyaddr 0 in phy scan.
Manfred Spraul18360982005-12-24 14:19:24 +0100102 * 0.48: 24 Dec 2005: Disable TSO, bugfix for pci_map_single
Ayaz Abdullafa454592006-01-05 22:45:45 -0800103 * 0.49: 10 Dec 2005: Fix tso for large buffers.
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500104 * 0.50: 20 Jan 2006: Add 8021pq tagging support.
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500105 * 0.51: 20 Jan 2006: Add 64bit consistent memory allocation for rings.
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500106 * 0.52: 20 Jan 2006: Add MSI/MSIX support.
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400107 * 0.53: 19 Mar 2006: Fix init from low power mode and add hw reset.
Ayaz Abdulla84b39322006-05-20 14:59:48 -0700108 * 0.54: 21 Mar 2006: Fix spin locks for multi irqs and cleanup.
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400109 * 0.55: 22 Mar 2006: Add flow control (pause frame).
Ayaz Abdullaebe611a2006-06-10 22:48:24 -0400110 * 0.56: 22 Mar 2006: Additional ethtool config and moduleparam support.
Ayaz Abdulla5070d342006-07-31 12:05:01 -0400111 * 0.57: 14 May 2006: Mac address set in probe/remove and order corrections.
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500112 * 0.58: 30 Oct 2006: Added support for sideband management unit.
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500113 * 0.59: 30 Oct 2006: Added support for recoverable error.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 *
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 Hemmingere27cdba2006-07-31 20:37:19 -0700125#ifdef CONFIG_FORCEDETH_NAPI
126#define DRIVERNAPI "-NAPI"
127#else
128#define DRIVERNAPI
129#endif
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500130#define FORCEDETH_VERSION "0.59"
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131#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 Spraul22c6d142005-04-19 21:17:09 +0200147#include <linux/if_vlan.h>
Matthias Gehre910638a2006-03-28 01:56:48 -0800148#include <linux/dma-mapping.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
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 Spraulc2dba062005-07-31 18:29:47 +0200166#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 Spraulee733622005-07-31 18:32:26 +0200169#define DEV_HAS_HIGH_DMA 0x0008 /* device supports 64bit dma */
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400170#define DEV_HAS_CHECKSUM 0x0010 /* device supports tx and rx checksum offloads */
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500171#define DEV_HAS_VLAN 0x0020 /* device supports vlan tagging and striping */
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500172#define DEV_HAS_MSI 0x0040 /* device supports MSI */
173#define DEV_HAS_MSI_X 0x0080 /* device supports MSI-X */
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400174#define DEV_HAS_POWER_CNTRL 0x0100 /* device supports power savings */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400175#define DEV_HAS_PAUSEFRAME_TX 0x0200 /* device supports tx pause frames */
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400176#define DEV_HAS_STATISTICS 0x0400 /* device supports hw statistics */
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400177#define DEV_HAS_TEST_EXTENDED 0x0800 /* device supports extended diagnostic test */
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500178#define DEV_HAS_MGMT_UNIT 0x1000 /* device supports management unit */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179
180enum {
181 NvRegIrqStatus = 0x000,
182#define NVREG_IRQSTAT_MIIEVENT 0x040
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500183#define NVREG_IRQSTAT_MASK 0x81ff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 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 Spraulc2dba062005-07-31 18:29:47 +0200189#define NVREG_IRQ_TX_OK 0x0010
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190#define NVREG_IRQ_TIMER 0x0020
191#define NVREG_IRQ_LINK 0x0040
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500192#define NVREG_IRQ_RX_FORCED 0x0080
193#define NVREG_IRQ_TX_FORCED 0x0100
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500194#define NVREG_IRQ_RECOVER_ERROR 0x8000
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500195#define NVREG_IRQMASK_THROUGHPUT 0x00df
196#define NVREG_IRQMASK_CPU 0x0040
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500197#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 Abdullac5cf9102006-10-30 17:32:01 -0500199#define NVREG_IRQ_OTHER (NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_RECOVER_ERROR)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200200
201#define NVREG_IRQ_UNKNOWN (~(NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_TX_ERR| \
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500202 NVREG_IRQ_TX_OK|NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_RX_FORCED| \
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500203 NVREG_IRQ_TX_FORCED|NVREG_IRQ_RECOVER_ERROR))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
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 Abdullaa971c322005-11-11 08:30:38 -0500213#define NVREG_POLL_DEFAULT_THROUGHPUT 970
214#define NVREG_POLL_DEFAULT_CPU 13
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500215 NvRegMSIMap0 = 0x020,
216 NvRegMSIMap1 = 0x024,
217 NvRegMSIIrqMask = 0x030,
218#define NVREG_MSI_VECTOR_0_ENABLED 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 NvRegMisc1 = 0x080,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400220#define NVREG_MISC1_PAUSE_TX 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221#define NVREG_MISC1_HD 0x02
222#define NVREG_MISC1_FORCE 0x3b0f3c
223
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400224 NvRegMacReset = 0x3c,
225#define NVREG_MAC_RESET_ASSERT 0x0F3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 NvRegTransmitterControl = 0x084,
227#define NVREG_XMITCTL_START 0x01
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500228#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 Abdullaf35723e2003-02-20 03:03:54 -0500237#define NVREG_XMITCTL_TX_PATH_EN 0x01000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 NvRegTransmitterStatus = 0x088,
239#define NVREG_XMITSTAT_BUSY 0x01
240
241 NvRegPacketFilterFlags = 0x8c,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400242#define NVREG_PFF_PAUSE_RX 0x08
243#define NVREG_PFF_ALWAYS 0x7F0000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244#define NVREG_PFF_PROMISC 0x80
245#define NVREG_PFF_MYADDR 0x20
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400246#define NVREG_PFF_LOOPBACK 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247
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 Abdullaf35723e2003-02-20 03:03:54 -0500253#define NVREG_RCVCTL_RX_PATH_EN 0x01000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 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 Abdulla9744e212006-07-06 16:45:58 -0400263 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 Torvalds1da177e2005-04-16 15:20:36 -0700269 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 Abdulla5070d342006-07-31 12:05:01 -0400285 NvRegTransmitPoll = 0x10c,
286#define NVREG_TRANSMITPOLL_MAC_ADDR_REV 0x00008000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287 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 Abdulla95d161c2006-07-06 16:46:25 -0400295 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 Torvalds1da177e2005-04-16 15:20:36 -0700299 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 Spraul8a4ae7f2005-09-21 23:22:10 -0400306#define NVREG_TXRXCTL_DESC_1 0
Ayaz Abdullad2f78412007-01-09 13:30:02 -0500307#define NVREG_TXRXCTL_DESC_2 0x002100
308#define NVREG_TXRXCTL_DESC_3 0xc02200
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500309#define NVREG_TXRXCTL_VLANSTRIP 0x00040
310#define NVREG_TXRXCTL_VLANINS 0x00080
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500311 NvRegTxRingPhysAddrHigh = 0x148,
312 NvRegRxRingPhysAddrHigh = 0x14C,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400313 NvRegTxPauseFrame = 0x170,
314#define NVREG_TX_PAUSEFRAME_DISABLE 0x1ff0080
315#define NVREG_TX_PAUSEFRAME_ENABLE 0x0c00030
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 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 Abdulla7e680c22006-10-30 17:31:51 -0500321 NvRegMIIMask = 0x184,
322#define NVREG_MII_LINKCHANGE 0x0008
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323
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 Abdulla52da3572006-06-10 22:48:04 -0400365 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 Abdullaee407b02006-02-04 13:13:17 -0500392 NvRegVlanControl = 0x300,
393#define NVREG_VLANCONTROL_ENABLE 0x2000
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500394 NvRegMSIXMap0 = 0x3e0,
395 NvRegMSIXMap1 = 0x3e4,
396 NvRegMSIXIrqStatus = 0x3f0,
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400397
398 NvRegPowerState2 = 0x600,
399#define NVREG_POWERSTATE2_POWERUP_MASK 0x0F11
400#define NVREG_POWERSTATE2_POWERUP_REV_A3 0x0001
Linus Torvalds1da177e2005-04-16 15:20:36 -0700401};
402
403/* Big endian: should work, but is untested */
404struct ring_desc {
Stephen Hemmingera8bed492006-07-27 18:50:09 -0700405 __le32 buf;
406 __le32 flaglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407};
408
Manfred Spraulee733622005-07-31 18:32:26 +0200409struct ring_desc_ex {
Stephen Hemmingera8bed492006-07-27 18:50:09 -0700410 __le32 bufhigh;
411 __le32 buflow;
412 __le32 txvlan;
413 __le32 flaglen;
Manfred Spraulee733622005-07-31 18:32:26 +0200414};
415
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700416union ring_type {
Manfred Spraulee733622005-07-31 18:32:26 +0200417 struct ring_desc* orig;
418 struct ring_desc_ex* ex;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700419};
Manfred Spraulee733622005-07-31 18:32:26 +0200420
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421#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 Spraulc2dba062005-07-31 18:29:47 +0200428#define NV_TX_FORCED_INTERRUPT (1<<24)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429#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 Spraulc2dba062005-07-31 18:29:47 +0200438#define NV_TX2_FORCED_INTERRUPT (1<<30)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439#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 Abdullaac9c1892005-10-26 00:51:24 -0400446#define NV_TX2_TSO (1<<28)
447#define NV_TX2_TSO_SHIFT 14
Ayaz Abdullafa454592006-01-05 22:45:45 -0800448#define NV_TX2_TSO_MAX_SHIFT 14
449#define NV_TX2_TSO_MAX_SIZE (1<<NV_TX2_TSO_MAX_SHIFT)
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400450#define NV_TX2_CHECKSUM_L3 (1<<27)
451#define NV_TX2_CHECKSUM_L4 (1<<26)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500453#define NV_TX3_VLAN_TAG_PRESENT (1<<18)
454
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455#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 Abdullaee407b02006-02-04 13:13:17 -0500485#define NV_RX3_VLAN_TAG_PRESENT (1<<16)
486#define NV_RX3_VLAN_TAG_MASK (0x0000FFFF)
487
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488/* Miscelaneous hardware related defines: */
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400489#define NV_PCI_REGSZ_VER1 0x270
490#define NV_PCI_REGSZ_VER2 0x604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
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 Abdulla86a0f042006-04-24 18:41:31 -0400507#define NV_MAC_RESET_DELAY 64
Linus Torvalds1da177e2005-04-16 15:20:36 -0700508
509#define NV_WAKEUPPATTERNS 5
510#define NV_WAKEUPMASKENTRIES 4
511
512/* General driver defaults */
513#define NV_WATCHDOG_TIMEO (5*HZ)
514
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400515#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 Torvalds1da177e2005-04-16 15:20:36 -0700521
522/* rx/tx mac addr + type + vlan + align + slack*/
Manfred Sprauld81c0982005-07-31 18:20:30 +0200523#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 Torvalds1da177e2005-04-16 15:20:36 -0700530
531#define OOM_REFILL (1+HZ/20)
532#define POLL_WAIT (1+HZ/100)
533#define LINK_TIMEOUT (3*HZ)
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400534#define STATS_INTERVAL (10*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400536/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 * desc_ver values:
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400538 * 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 Torvalds1da177e2005-04-16 15:20:36 -0700542 */
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400543#define DESC_VER_1 1
544#define DESC_VER_2 2
545#define DESC_VER_3 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
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 Abdullaedf7e5e2006-08-24 15:43:42 -0400554#define PHYID2_MODEL_MASK 0x03f0
555#define PHY_MODEL_MARVELL_E3016 0x220
556#define PHY_MARVELL_E3016_INITMASK 0x0300
Linus Torvalds1da177e2005-04-16 15:20:36 -0700557#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 Abdullaeb91f612006-05-24 18:13:19 -0400572#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 Abdullab6d07732006-06-10 22:47:42 -0400576#define NV_PAUSEFRAME_RX_REQ 0x0010
577#define NV_PAUSEFRAME_TX_REQ 0x0020
578#define NV_PAUSEFRAME_AUTONEG 0x0040
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500580/* 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 Torvalds1da177e2005-04-16 15:20:36 -0700592
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400593/* statistics */
594struct nv_ethtool_str {
595 char name[ETH_GSTRING_LEN];
596};
597
598static 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
630struct 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 Abdulla9589c772006-06-10 22:48:13 -0400662/* diagnostics */
663#define NV_TEST_COUNT_BASE 3
664#define NV_TEST_COUNT_EXTENDED 4
665
666static const struct nv_ethtool_str nv_etests_str[] = {
667 { "link (online/offline)" },
668 { "register (offline) " },
669 { "interrupt (offline) " },
670 { "loopback (offline) " }
671};
672
673struct register_test {
Stephen Hemmingera8bed492006-07-27 18:50:09 -0700674 __le32 reg;
675 __le32 mask;
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400676};
677
678static const struct register_test nv_registers_test[] = {
679 { NvRegUnknownSetupReg6, 0x01 },
680 { NvRegMisc1, 0x03c },
681 { NvRegOffloadConfig, 0x03ff },
682 { NvRegMulticastAddrA, 0xffffffff },
Ayaz Abdulla95d161c2006-07-06 16:46:25 -0400683 { NvRegTxWatermark, 0x0ff },
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400684 { NvRegWakeUpFlags, 0x07777 },
685 { 0,0 }
686};
687
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500688struct nv_skb_map {
689 struct sk_buff *skb;
690 dma_addr_t dma;
691 unsigned int dma_len;
692};
693
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694/*
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 Xu932ff272006-06-09 12:20:56 -0700700 * - tx setup is lockless: it relies on netif_tx_lock. Actual submission
Linus Torvalds1da177e2005-04-16 15:20:36 -0700701 * needs dev->priv->lock :-(
Herbert Xu932ff272006-06-09 12:20:56 -0700702 * - set_multicast_list: preparation lockless, relies on netif_tx_lock.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 */
704
705/* in dev: base, irq */
706struct fe_priv {
707 spinlock_t lock;
708
709 /* General data:
710 * Locking: spin_lock(&np->lock); */
711 struct net_device_stats stats;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400712 struct nv_ethtool_stats estats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713 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 Abdullaedf7e5e2006-08-24 15:43:42 -0400721 unsigned int phy_model;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722 u16 gigabit;
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400723 int intr_test;
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500724 int recover_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700725
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 Spraul8a4ae7f2005-09-21 23:22:10 -0400732 u32 txrxctl_bits;
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500733 u32 vlanctl_bits;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400734 u32 driver_data;
735 u32 register_size;
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -0400736 int rx_csum;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500737 u32 mac_in_use;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700738
739 void __iomem *base;
740
741 /* rx specific fields.
742 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
743 */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500744 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 Hemmingerf82a9352006-07-27 18:50:08 -0700749 union ring_type rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 unsigned int rx_buf_sz;
Manfred Sprauld81c0982005-07-31 18:20:30 +0200751 unsigned int pkt_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 struct timer_list oom_kick;
753 struct timer_list nic_poll;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400754 struct timer_list stats_poll;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500755 u32 nic_poll_irq;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400756 int rx_ring_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700757
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 Abdulla761fcd92007-01-09 13:30:07 -0500766 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 Hemmingerf82a9352006-07-27 18:50:08 -0700771 union ring_type tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 u32 tx_flags;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400773 int tx_ring_size;
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -0500774 int tx_stop;
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500775
776 /* vlan fields */
777 struct vlan_group *vlangrp;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500778
779 /* msi/msi-x fields */
780 u32 msi_flags;
781 struct msix_entry msi_x_entry[NV_MSI_X_MAX_VECTORS];
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400782
783 /* flow control */
784 u32 pause_flags;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785};
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 */
791static int max_interrupt_work = 5;
792
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500793/*
794 * Optimization can be either throuput mode or cpu mode
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400795 *
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500796 * Throughput Mode: Every tx and rx packet will generate an interrupt.
797 * CPU Mode: Interrupts are controlled by a timer.
798 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400799enum {
800 NV_OPTIMIZATION_MODE_THROUGHPUT,
801 NV_OPTIMIZATION_MODE_CPU
802};
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500803static 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 */
812static int poll_interval = -1;
813
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500814/*
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400815 * MSI interrupts
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500816 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400817enum {
818 NV_MSI_INT_DISABLED,
819 NV_MSI_INT_ENABLED
820};
821static int msi = NV_MSI_INT_ENABLED;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500822
823/*
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400824 * MSIX interrupts
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500825 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400826enum {
827 NV_MSIX_INT_DISABLED,
828 NV_MSIX_INT_ENABLED
829};
830static int msix = NV_MSIX_INT_ENABLED;
831
832/*
833 * DMA 64bit
834 */
835enum {
836 NV_DMA_64BIT_DISABLED,
837 NV_DMA_64BIT_ENABLED
838};
839static int dma_64bit = NV_DMA_64BIT_ENABLED;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500840
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841static inline struct fe_priv *get_nvpriv(struct net_device *dev)
842{
843 return netdev_priv(dev);
844}
845
846static inline u8 __iomem *get_hwbase(struct net_device *dev)
847{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400848 return ((struct fe_priv *)netdev_priv(dev))->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700849}
850
851static inline void pci_push(u8 __iomem *base)
852{
853 /* force out pending posted writes */
854 readl(base);
855}
856
857static inline u32 nv_descr_getlength(struct ring_desc *prd, u32 v)
858{
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700859 return le32_to_cpu(prd->flaglen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700860 & ((v == DESC_VER_1) ? LEN_MASK_V1 : LEN_MASK_V2);
861}
862
Manfred Spraulee733622005-07-31 18:32:26 +0200863static inline u32 nv_descr_getlength_ex(struct ring_desc_ex *prd, u32 v)
864{
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700865 return le32_to_cpu(prd->flaglen) & LEN_MASK_V2;
Manfred Spraulee733622005-07-31 18:32:26 +0200866}
867
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868static 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 Abdulla0832b252006-02-04 13:13:26 -0500886#define NV_SETUP_RX_RING 0x01
887#define NV_SETUP_TX_RING 0x02
888
889static 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 Abdullaeafa59f2006-06-10 22:47:34 -0400899 writel((u32) cpu_to_le64(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr);
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500900 }
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 Abdullaeafa59f2006-06-10 22:47:34 -0400907 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 Abdulla0832b252006-02-04 13:13:26 -0500909 }
910 }
911}
912
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400913static 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 Hemmingerf82a9352006-07-27 18:50:08 -0700918 if (np->rx_ring.orig)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400919 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 Abdulla761fcd92007-01-09 13:30:07 -0500926 if (np->rx_skb)
927 kfree(np->rx_skb);
928 if (np->tx_skb)
929 kfree(np->tx_skb);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400930}
931
Ayaz Abdulla84b39322006-05-20 14:59:48 -0700932static 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
944static 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
960static 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 */
977static 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
984static 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 Torvalds1da177e2005-04-16 15:20:36 -0700998#define MII_READ (-1)
999/* mii_rw: read/write a register on the PHY.
1000 *
1001 * Caller must guarantee serialization
1002 */
1003static 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 Abdullaedf7e5e2006-08-24 15:43:42 -04001047static int phy_reset(struct net_device *dev, u32 bmcr_setup)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001049 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001050 u32 miicontrol;
1051 unsigned int tries = 0;
1052
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001053 miicontrol = BMCR_RESET | bmcr_setup;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001054 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
1072static 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 Abdullaedf7e5e2006-08-24 15:43:42 -04001078 /* 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 Torvalds1da177e2005-04-16 15:20:36 -07001088 /* set advertise register */
1089 reg = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001090 reg |= (ADVERTISE_10HALF|ADVERTISE_10FULL|ADVERTISE_100HALF|ADVERTISE_100FULL|ADVERTISE_PAUSE_ASYM|ADVERTISE_PAUSE_CAP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091 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 Abdullaeb91f612006-05-24 18:13:19 -04001103 mii_control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104 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 Abdullaeb91f612006-05-24 18:13:19 -04001110 if (mii_rw(dev, np->phyaddr, MII_CTRL1000, mii_control_1000)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111 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 Abdullaedf7e5e2006-08-24 15:43:42 -04001118 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 Torvalds1da177e2005-04-16 15:20:36 -07001125 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 Abdullaeb91f612006-05-24 18:13:19 -04001153 /* some phys clear out pause advertisment on reset, set it back */
1154 mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001155
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
1166static void nv_start_rx(struct net_device *dev)
1167{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001168 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001170 u32 rx_ctrl = readl(base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171
1172 dprintk(KERN_DEBUG "%s: nv_start_rx\n", dev->name);
1173 /* Already running? Stop it. */
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001174 if ((readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) && !np->mac_in_use) {
1175 rx_ctrl &= ~NVREG_RCVCTL_START;
1176 writel(rx_ctrl, base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177 pci_push(base);
1178 }
1179 writel(np->linkspeed, base + NvRegLinkSpeed);
1180 pci_push(base);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001181 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 Torvalds1da177e2005-04-16 15:20:36 -07001185 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
1190static void nv_stop_rx(struct net_device *dev)
1191{
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001192 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001193 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001194 u32 rx_ctrl = readl(base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195
1196 dprintk(KERN_DEBUG "%s: nv_stop_rx\n", dev->name);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001197 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 Torvalds1da177e2005-04-16 15:20:36 -07001202 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 Abdullaf35723e2003-02-20 03:03:54 -05001207 if (!np->mac_in_use)
1208 writel(0, base + NvRegLinkSpeed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001209}
1210
1211static void nv_start_tx(struct net_device *dev)
1212{
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001213 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001214 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001215 u32 tx_ctrl = readl(base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001216
1217 dprintk(KERN_DEBUG "%s: nv_start_tx\n", dev->name);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001218 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 Torvalds1da177e2005-04-16 15:20:36 -07001222 pci_push(base);
1223}
1224
1225static void nv_stop_tx(struct net_device *dev)
1226{
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001227 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001228 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001229 u32 tx_ctrl = readl(base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001230
1231 dprintk(KERN_DEBUG "%s: nv_stop_tx\n", dev->name);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001232 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 Torvalds1da177e2005-04-16 15:20:36 -07001237 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 Abdullaf35723e2003-02-20 03:03:54 -05001242 if (!np->mac_in_use)
1243 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV,
1244 base + NvRegTransmitPoll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245}
1246
1247static void nv_txrx_reset(struct net_device *dev)
1248{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001249 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001250 u8 __iomem *base = get_hwbase(dev);
1251
1252 dprintk(KERN_DEBUG "%s: nv_txrx_reset\n", dev->name);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001253 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 pci_push(base);
1255 udelay(NV_TXRX_RESET_DELAY);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001256 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001257 pci_push(base);
1258}
1259
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001260static 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 Torvalds1da177e2005-04-16 15:20:36 -07001278/*
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 */
1284static struct net_device_stats *nv_get_stats(struct net_device *dev)
1285{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001286 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287
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 */
1300static int nv_alloc_rx(struct net_device *dev)
1301{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001302 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001303 struct ring_desc* less_rx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001304
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001305 less_rx = np->get_rx.orig;
1306 if (less_rx-- == np->first_rx.orig)
1307 less_rx = np->last_rx.orig;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001308
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001309 while (np->put_rx.orig != less_rx) {
1310 struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001311 if (skb) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001312 skb->dev = dev;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001313 np->put_rx_ctx->skb = skb;
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001314 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 Abdulla86b22b02007-01-21 18:10:37 -05001317 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
1331static 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 Abdulla0d63fb32007-01-09 13:30:13 -05001354 if (np->put_rx_ctx++ == np->last_rx_ctx)
1355 np->put_rx_ctx = np->first_rx_ctx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001356 } else {
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001357 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001359 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001360 return 0;
1361}
1362
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001363/* If rx bufs are exhausted called after 50ms to attempt to refresh */
1364#ifdef CONFIG_FORCEDETH_NAPI
1365static 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 Torvalds1da177e2005-04-16 15:20:36 -07001373static void nv_do_rx_refill(unsigned long data)
1374{
1375 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001376 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001377 int retcode;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001378
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001379 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 Abdullad33a73c82006-02-04 13:13:31 -05001384 } else {
1385 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1386 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001387 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 Abdulla84b39322006-05-20 14:59:48 -07001392 spin_lock_irq(&np->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393 if (!np->in_shutdown)
1394 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001395 spin_unlock_irq(&np->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001396 }
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001397 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 Abdullad33a73c82006-02-04 13:13:31 -05001402 } else {
1403 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1404 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001405}
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001406#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001407
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001408static void nv_init_rx(struct net_device *dev)
Manfred Sprauld81c0982005-07-31 18:20:30 +02001409{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001410 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02001411 int i;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001412 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 Sprauld81c0982005-07-31 18:20:30 +02001419
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001420 for (i = 0; i < np->rx_ring_size; i++) {
1421 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001422 np->rx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001423 np->rx_ring.orig[i].buf = 0;
1424 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001425 np->rx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001426 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 Sprauld81c0982005-07-31 18:20:30 +02001433}
1434
1435static void nv_init_tx(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001437 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001438 int i;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001439 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 Torvalds1da177e2005-04-16 15:20:36 -07001446
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001447 for (i = 0; i < np->tx_ring_size; i++) {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001448 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001449 np->tx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001450 np->tx_ring.orig[i].buf = 0;
1451 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001452 np->tx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001453 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 Abdullaac9c1892005-10-26 00:51:24 -04001459 }
Manfred Sprauld81c0982005-07-31 18:20:30 +02001460}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001461
Manfred Sprauld81c0982005-07-31 18:20:30 +02001462static int nv_init_ring(struct net_device *dev)
1463{
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001464 struct fe_priv *np = netdev_priv(dev);
1465
Manfred Sprauld81c0982005-07-31 18:20:30 +02001466 nv_init_tx(dev);
1467 nv_init_rx(dev);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001468 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 Torvalds1da177e2005-04-16 15:20:36 -07001472}
1473
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001474static int nv_release_txskb(struct net_device *dev, struct nv_skb_map* tx_skb)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001475{
1476 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001477
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001478 if (tx_skb->dma) {
1479 pci_unmap_page(np->pci_dev, tx_skb->dma,
1480 tx_skb->dma_len,
Ayaz Abdullafa454592006-01-05 22:45:45 -08001481 PCI_DMA_TODEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001482 tx_skb->dma = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001483 }
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001484 if (tx_skb->skb) {
1485 dev_kfree_skb_any(tx_skb->skb);
1486 tx_skb->skb = NULL;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001487 return 1;
1488 } else {
1489 return 0;
1490 }
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001491}
1492
Linus Torvalds1da177e2005-04-16 15:20:36 -07001493static void nv_drain_tx(struct net_device *dev)
1494{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001495 struct fe_priv *np = netdev_priv(dev);
1496 unsigned int i;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001497
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001498 for (i = 0; i < np->tx_ring_size; i++) {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001499 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001500 np->tx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001501 np->tx_ring.orig[i].buf = 0;
1502 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001503 np->tx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001504 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 Torvalds1da177e2005-04-16 15:20:36 -07001509 np->stats.tx_dropped++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001510 }
1511}
1512
1513static void nv_drain_rx(struct net_device *dev)
1514{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001515 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001516 int i;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001517
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001518 for (i = 0; i < np->rx_ring_size; i++) {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001519 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001520 np->rx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001521 np->rx_ring.orig[i].buf = 0;
1522 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001523 np->rx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001524 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 Torvalds1da177e2005-04-16 15:20:36 -07001528 wmb();
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001529 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 Torvalds1da177e2005-04-16 15:20:36 -07001532 PCI_DMA_FROMDEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001533 dev_kfree_skb(np->rx_skb[i].skb);
1534 np->rx_skb[i].skb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 }
1536 }
1537}
1538
1539static void drain_ring(struct net_device *dev)
1540{
1541 nv_drain_tx(dev);
1542 nv_drain_rx(dev);
1543}
1544
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001545static 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 Torvalds1da177e2005-04-16 15:20:36 -07001550/*
1551 * nv_start_xmit: dev->hard_start_xmit function
Herbert Xu932ff272006-06-09 12:20:56 -07001552 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001553 */
1554static int nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
1555{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001556 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001557 u32 tx_flags = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001558 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 Abdullaac9c1892005-10-26 00:51:24 -04001560 unsigned int i;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001561 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 Abdulla761fcd92007-01-09 13:30:07 -05001565 u32 empty_slots;
Ayaz Abdullaee407b02006-02-04 13:13:17 -05001566 u32 tx_flags_vlan = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001567 struct ring_desc* put_tx;
1568 struct ring_desc* start_tx;
1569 struct ring_desc* prev_tx;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001570 struct nv_skb_map* prev_tx_ctx;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001571
1572 /* add fragments to entries count */
1573 for (i = 0; i < fragments; i++) {
1574 entries += (skb_shinfo(skb)->frags[i].size >> NV_TX2_TSO_MAX_SHIFT) +
1575 ((skb_shinfo(skb)->frags[i].size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
1576 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001578 empty_slots = nv_get_empty_tx_slots(np);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05001579 if (empty_slots <= entries) {
Ayaz Abdulla164a86e2007-01-09 13:30:10 -05001580 spin_lock_irq(&np->lock);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001581 netif_stop_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05001582 np->tx_stop = 1;
Ayaz Abdulla164a86e2007-01-09 13:30:10 -05001583 spin_unlock_irq(&np->lock);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001584 return NETDEV_TX_BUSY;
1585 }
1586
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001587 start_tx = put_tx = np->put_tx.orig;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001588
Ayaz Abdullafa454592006-01-05 22:45:45 -08001589 /* setup the header buffer */
1590 do {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001591 prev_tx = put_tx;
1592 prev_tx_ctx = np->put_tx_ctx;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001593 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001594 np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
Ayaz Abdullafa454592006-01-05 22:45:45 -08001595 PCI_DMA_TODEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001596 np->put_tx_ctx->dma_len = bcnt;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001597 put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
1598 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001599 tx_flags = np->tx_flags;
1600 offset += bcnt;
1601 size -= bcnt;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001602 if (put_tx++ == np->last_tx.orig)
1603 put_tx = np->first_tx.orig;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001604 if (np->put_tx_ctx++ == np->last_tx_ctx)
1605 np->put_tx_ctx = np->first_tx_ctx;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001606 } while (size);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001607
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 Abdulla761fcd92007-01-09 13:30:07 -05001615 prev_tx = put_tx;
1616 prev_tx_ctx = np->put_tx_ctx;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001617 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001618 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 Abdullaac9c1892005-10-26 00:51:24 -04001621
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001622 put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
1623 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001624 offset += bcnt;
1625 size -= bcnt;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001626 if (put_tx++ == np->last_tx.orig)
1627 put_tx = np->first_tx.orig;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001628 if (np->put_tx_ctx++ == np->last_tx_ctx)
1629 np->put_tx_ctx = np->first_tx_ctx;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001630 } while (size);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001631 }
1632
Ayaz Abdullafa454592006-01-05 22:45:45 -08001633 /* set last fragment flag */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001634 prev_tx->flaglen |= cpu_to_le32(tx_flags_extra);
Ayaz Abdullafa454592006-01-05 22:45:45 -08001635
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001636 /* save skb in this slot's context area */
1637 prev_tx_ctx->skb = skb;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001638
Herbert Xu89114af2006-07-08 13:34:32 -07001639 if (skb_is_gso(skb))
Herbert Xu79671682006-06-22 02:40:14 -07001640 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
Manfred Spraulee733622005-07-31 18:32:26 +02001641 else
Arjan van de Ven1d39ed52006-12-12 14:06:23 +01001642 tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
Patrick McHardy84fa7932006-08-29 16:44:56 -07001643 NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001644
Ayaz Abdullaee407b02006-02-04 13:13:17 -05001645 /* vlan tag */
1646 if (np->vlangrp && vlan_tx_tag_present(skb)) {
1647 tx_flags_vlan = NV_TX3_VLAN_TAG_PRESENT | vlan_tx_tag_get(skb);
1648 }
1649
Ayaz Abdulla164a86e2007-01-09 13:30:10 -05001650 spin_lock_irq(&np->lock);
1651
Ayaz Abdullafa454592006-01-05 22:45:45 -08001652 /* set tx flags */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001653 start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
1654 np->put_tx.orig = put_tx;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001655
Ayaz Abdulla164a86e2007-01-09 13:30:10 -05001656 spin_unlock_irq(&np->lock);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001657
1658 dprintk(KERN_DEBUG "%s: nv_start_xmit: entries %d queued for transmission. tx_flags_extra: %x\n",
1659 dev->name, entries, tx_flags_extra);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001660 {
1661 int j;
1662 for (j=0; j<64; j++) {
1663 if ((j%16) == 0)
1664 dprintk("\n%03x:", j);
1665 dprintk(" %02x", ((unsigned char*)skb->data)[j]);
1666 }
1667 dprintk("\n");
1668 }
1669
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 dev->trans_start = jiffies;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001671 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672 pci_push(get_hwbase(dev));
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001673 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001674}
1675
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001676static int nv_start_xmit_optimized(struct sk_buff *skb, struct net_device *dev)
1677{
1678 struct fe_priv *np = netdev_priv(dev);
1679 u32 tx_flags = 0;
1680 u32 tx_flags_extra = NV_TX2_LASTPACKET;
1681 unsigned int fragments = skb_shinfo(skb)->nr_frags;
1682 unsigned int i;
1683 u32 offset = 0;
1684 u32 bcnt;
1685 u32 size = skb->len-skb->data_len;
1686 u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
1687 u32 empty_slots;
1688 u32 tx_flags_vlan = 0;
1689 struct ring_desc_ex* put_tx;
1690 struct ring_desc_ex* start_tx;
1691 struct ring_desc_ex* prev_tx;
1692 struct nv_skb_map* prev_tx_ctx;
1693
1694 /* add fragments to entries count */
1695 for (i = 0; i < fragments; i++) {
1696 entries += (skb_shinfo(skb)->frags[i].size >> NV_TX2_TSO_MAX_SHIFT) +
1697 ((skb_shinfo(skb)->frags[i].size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
1698 }
1699
1700 empty_slots = nv_get_empty_tx_slots(np);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05001701 if (empty_slots <= entries) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001702 spin_lock_irq(&np->lock);
1703 netif_stop_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05001704 np->tx_stop = 1;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001705 spin_unlock_irq(&np->lock);
1706 return NETDEV_TX_BUSY;
1707 }
1708
1709 start_tx = put_tx = np->put_tx.ex;
1710
1711 /* setup the header buffer */
1712 do {
1713 prev_tx = put_tx;
1714 prev_tx_ctx = np->put_tx_ctx;
1715 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
1716 np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
1717 PCI_DMA_TODEVICE);
1718 np->put_tx_ctx->dma_len = bcnt;
1719 put_tx->bufhigh = cpu_to_le64(np->put_tx_ctx->dma) >> 32;
1720 put_tx->buflow = cpu_to_le64(np->put_tx_ctx->dma) & 0x0FFFFFFFF;
1721 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
1722 tx_flags = np->tx_flags;
1723 offset += bcnt;
1724 size -= bcnt;
1725 if (put_tx++ == np->last_tx.ex)
1726 put_tx = np->first_tx.ex;
1727 if (np->put_tx_ctx++ == np->last_tx_ctx)
1728 np->put_tx_ctx = np->first_tx_ctx;
1729 } while (size);
1730
1731 /* setup the fragments */
1732 for (i = 0; i < fragments; i++) {
1733 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
1734 u32 size = frag->size;
1735 offset = 0;
1736
1737 do {
1738 prev_tx = put_tx;
1739 prev_tx_ctx = np->put_tx_ctx;
1740 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
1741 np->put_tx_ctx->dma = pci_map_page(np->pci_dev, frag->page, frag->page_offset+offset, bcnt,
1742 PCI_DMA_TODEVICE);
1743 np->put_tx_ctx->dma_len = bcnt;
1744
1745 put_tx->bufhigh = cpu_to_le64(np->put_tx_ctx->dma) >> 32;
1746 put_tx->buflow = cpu_to_le64(np->put_tx_ctx->dma) & 0x0FFFFFFFF;
1747 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
1748 offset += bcnt;
1749 size -= bcnt;
1750 if (put_tx++ == np->last_tx.ex)
1751 put_tx = np->first_tx.ex;
1752 if (np->put_tx_ctx++ == np->last_tx_ctx)
1753 np->put_tx_ctx = np->first_tx_ctx;
1754 } while (size);
1755 }
1756
1757 /* set last fragment flag */
1758 prev_tx->flaglen |= cpu_to_le32(tx_flags_extra);
1759
1760 /* save skb in this slot's context area */
1761 prev_tx_ctx->skb = skb;
1762
1763 if (skb_is_gso(skb))
1764 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
1765 else
1766 tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
1767 NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
1768
1769 /* vlan tag */
1770 if (np->vlangrp && vlan_tx_tag_present(skb)) {
1771 tx_flags_vlan = NV_TX3_VLAN_TAG_PRESENT | vlan_tx_tag_get(skb);
1772 }
1773
1774 spin_lock_irq(&np->lock);
1775
1776 /* set tx flags */
1777 start_tx->txvlan = cpu_to_le32(tx_flags_vlan);
1778 start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
1779 np->put_tx.ex = put_tx;
1780
1781 spin_unlock_irq(&np->lock);
1782
1783 dprintk(KERN_DEBUG "%s: nv_start_xmit_optimized: entries %d queued for transmission. tx_flags_extra: %x\n",
1784 dev->name, entries, tx_flags_extra);
1785 {
1786 int j;
1787 for (j=0; j<64; j++) {
1788 if ((j%16) == 0)
1789 dprintk("\n%03x:", j);
1790 dprintk(" %02x", ((unsigned char*)skb->data)[j]);
1791 }
1792 dprintk("\n");
1793 }
1794
1795 dev->trans_start = jiffies;
1796 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
1797 pci_push(get_hwbase(dev));
1798 return NETDEV_TX_OK;
1799}
1800
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801/*
1802 * nv_tx_done: check for completed packets, release the skbs.
1803 *
1804 * Caller must own np->lock.
1805 */
1806static void nv_tx_done(struct net_device *dev)
1807{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001808 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001809 u32 flags;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001810 struct sk_buff *skb;
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05001811 struct ring_desc* orig_get_tx = np->get_tx.orig;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001813 while (np->get_tx.orig != np->put_tx.orig) {
1814 flags = le32_to_cpu(np->get_tx.orig->flaglen);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001815
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001816 dprintk(KERN_DEBUG "%s: nv_tx_done: flags 0x%x.\n",
1817 dev->name, flags);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001818 if (flags & NV_TX_VALID)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819 break;
1820 if (np->desc_ver == DESC_VER_1) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001821 if (flags & NV_TX_LASTPACKET) {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001822 skb = np->get_tx_ctx->skb;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001823 if (flags & (NV_TX_RETRYERROR|NV_TX_CARRIERLOST|NV_TX_LATECOLLISION|
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001824 NV_TX_UNDERFLOW|NV_TX_ERROR)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001825 if (flags & NV_TX_UNDERFLOW)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001826 np->stats.tx_fifo_errors++;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001827 if (flags & NV_TX_CARRIERLOST)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001828 np->stats.tx_carrier_errors++;
1829 np->stats.tx_errors++;
1830 } else {
1831 np->stats.tx_packets++;
1832 np->stats.tx_bytes += skb->len;
1833 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834 }
1835 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001836 if (flags & NV_TX2_LASTPACKET) {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001837 skb = np->get_tx_ctx->skb;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001838 if (flags & (NV_TX2_RETRYERROR|NV_TX2_CARRIERLOST|NV_TX2_LATECOLLISION|
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001839 NV_TX2_UNDERFLOW|NV_TX2_ERROR)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001840 if (flags & NV_TX2_UNDERFLOW)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001841 np->stats.tx_fifo_errors++;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001842 if (flags & NV_TX2_CARRIERLOST)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001843 np->stats.tx_carrier_errors++;
1844 np->stats.tx_errors++;
1845 } else {
1846 np->stats.tx_packets++;
1847 np->stats.tx_bytes += skb->len;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001848 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001849 }
1850 }
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001851 nv_release_txskb(dev, np->get_tx_ctx);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001852 if (np->get_tx.orig++ == np->last_tx.orig)
1853 np->get_tx.orig = np->first_tx.orig;
1854 if (np->get_tx_ctx++ == np->last_tx_ctx)
1855 np->get_tx_ctx = np->first_tx_ctx;
1856 }
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05001857 if ((np->tx_stop == 1) && (np->get_tx.orig != orig_get_tx)) {
1858 np->tx_stop = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001859 netif_wake_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05001860 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001861}
1862
1863static void nv_tx_done_optimized(struct net_device *dev)
1864{
1865 struct fe_priv *np = netdev_priv(dev);
1866 u32 flags;
1867 struct sk_buff *skb;
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05001868 struct ring_desc_ex* orig_get_tx = np->get_tx.ex;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001869
1870 while (np->get_tx.ex == np->put_tx.ex) {
1871 flags = le32_to_cpu(np->get_tx.ex->flaglen);
1872
1873 dprintk(KERN_DEBUG "%s: nv_tx_done_optimized: flags 0x%x.\n",
1874 dev->name, flags);
1875 if (flags & NV_TX_VALID)
1876 break;
1877 if (flags & NV_TX2_LASTPACKET) {
1878 skb = np->get_tx_ctx->skb;
1879 if (flags & (NV_TX2_RETRYERROR|NV_TX2_CARRIERLOST|NV_TX2_LATECOLLISION|
1880 NV_TX2_UNDERFLOW|NV_TX2_ERROR)) {
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++;
1888 np->stats.tx_bytes += skb->len;
1889 }
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001890 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001891 nv_release_txskb(dev, np->get_tx_ctx);
1892 if (np->get_tx.ex++ == np->last_tx.ex)
1893 np->get_tx.ex = np->first_tx.ex;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001894 if (np->get_tx_ctx++ == np->last_tx_ctx)
1895 np->get_tx_ctx = np->first_tx_ctx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001896 }
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05001897 if ((np->tx_stop == 1) && (np->get_tx.ex != orig_get_tx)) {
1898 np->tx_stop = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899 netif_wake_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05001900 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001901}
1902
1903/*
1904 * nv_tx_timeout: dev->tx_timeout function
Herbert Xu932ff272006-06-09 12:20:56 -07001905 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001906 */
1907static void nv_tx_timeout(struct net_device *dev)
1908{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001909 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001910 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05001911 u32 status;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001912
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05001913 if (np->msi_flags & NV_MSI_X_ENABLED)
1914 status = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
1915 else
1916 status = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
1917
1918 printk(KERN_INFO "%s: Got tx_timeout. irq: %08x\n", dev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919
Manfred Spraulc2dba062005-07-31 18:29:47 +02001920 {
1921 int i;
1922
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001923 printk(KERN_INFO "%s: Ring at %lx\n",
1924 dev->name, (unsigned long)np->ring_addr);
Manfred Spraulc2dba062005-07-31 18:29:47 +02001925 printk(KERN_INFO "%s: Dumping tx registers\n", dev->name);
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001926 for (i=0;i<=np->register_size;i+= 32) {
Manfred Spraulc2dba062005-07-31 18:29:47 +02001927 printk(KERN_INFO "%3x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
1928 i,
1929 readl(base + i + 0), readl(base + i + 4),
1930 readl(base + i + 8), readl(base + i + 12),
1931 readl(base + i + 16), readl(base + i + 20),
1932 readl(base + i + 24), readl(base + i + 28));
1933 }
1934 printk(KERN_INFO "%s: Dumping tx ring\n", dev->name);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001935 for (i=0;i<np->tx_ring_size;i+= 4) {
Manfred Spraulee733622005-07-31 18:32:26 +02001936 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
1937 printk(KERN_INFO "%03x: %08x %08x // %08x %08x // %08x %08x // %08x %08x\n",
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001938 i,
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001939 le32_to_cpu(np->tx_ring.orig[i].buf),
1940 le32_to_cpu(np->tx_ring.orig[i].flaglen),
1941 le32_to_cpu(np->tx_ring.orig[i+1].buf),
1942 le32_to_cpu(np->tx_ring.orig[i+1].flaglen),
1943 le32_to_cpu(np->tx_ring.orig[i+2].buf),
1944 le32_to_cpu(np->tx_ring.orig[i+2].flaglen),
1945 le32_to_cpu(np->tx_ring.orig[i+3].buf),
1946 le32_to_cpu(np->tx_ring.orig[i+3].flaglen));
Manfred Spraulee733622005-07-31 18:32:26 +02001947 } else {
1948 printk(KERN_INFO "%03x: %08x %08x %08x // %08x %08x %08x // %08x %08x %08x // %08x %08x %08x\n",
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001949 i,
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001950 le32_to_cpu(np->tx_ring.ex[i].bufhigh),
1951 le32_to_cpu(np->tx_ring.ex[i].buflow),
1952 le32_to_cpu(np->tx_ring.ex[i].flaglen),
1953 le32_to_cpu(np->tx_ring.ex[i+1].bufhigh),
1954 le32_to_cpu(np->tx_ring.ex[i+1].buflow),
1955 le32_to_cpu(np->tx_ring.ex[i+1].flaglen),
1956 le32_to_cpu(np->tx_ring.ex[i+2].bufhigh),
1957 le32_to_cpu(np->tx_ring.ex[i+2].buflow),
1958 le32_to_cpu(np->tx_ring.ex[i+2].flaglen),
1959 le32_to_cpu(np->tx_ring.ex[i+3].bufhigh),
1960 le32_to_cpu(np->tx_ring.ex[i+3].buflow),
1961 le32_to_cpu(np->tx_ring.ex[i+3].flaglen));
Manfred Spraulee733622005-07-31 18:32:26 +02001962 }
Manfred Spraulc2dba062005-07-31 18:29:47 +02001963 }
1964 }
1965
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966 spin_lock_irq(&np->lock);
1967
1968 /* 1) stop tx engine */
1969 nv_stop_tx(dev);
1970
1971 /* 2) check that the packets were not sent already: */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001972 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
1973 nv_tx_done(dev);
1974 else
1975 nv_tx_done_optimized(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001976
1977 /* 3) if there are dead entries: clear everything */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001978 if (np->get_tx_ctx != np->put_tx_ctx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 printk(KERN_DEBUG "%s: tx_timeout: dead entries!\n", dev->name);
1980 nv_drain_tx(dev);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001981 nv_init_tx(dev);
Ayaz Abdulla0832b252006-02-04 13:13:26 -05001982 setup_hw_rings(dev, NV_SETUP_TX_RING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001983 netif_wake_queue(dev);
1984 }
1985
1986 /* 4) restart tx engine */
1987 nv_start_tx(dev);
1988 spin_unlock_irq(&np->lock);
1989}
1990
Manfred Spraul22c6d142005-04-19 21:17:09 +02001991/*
1992 * Called when the nic notices a mismatch between the actual data len on the
1993 * wire and the len indicated in the 802 header
1994 */
1995static int nv_getlen(struct net_device *dev, void *packet, int datalen)
1996{
1997 int hdrlen; /* length of the 802 header */
1998 int protolen; /* length as stored in the proto field */
1999
2000 /* 1) calculate len according to header */
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002001 if ( ((struct vlan_ethhdr *)packet)->h_vlan_proto == htons(ETH_P_8021Q)) {
Manfred Spraul22c6d142005-04-19 21:17:09 +02002002 protolen = ntohs( ((struct vlan_ethhdr *)packet)->h_vlan_encapsulated_proto );
2003 hdrlen = VLAN_HLEN;
2004 } else {
2005 protolen = ntohs( ((struct ethhdr *)packet)->h_proto);
2006 hdrlen = ETH_HLEN;
2007 }
2008 dprintk(KERN_DEBUG "%s: nv_getlen: datalen %d, protolen %d, hdrlen %d\n",
2009 dev->name, datalen, protolen, hdrlen);
2010 if (protolen > ETH_DATA_LEN)
2011 return datalen; /* Value in proto field not a len, no checks possible */
2012
2013 protolen += hdrlen;
2014 /* consistency checks: */
2015 if (datalen > ETH_ZLEN) {
2016 if (datalen >= protolen) {
2017 /* more data on wire than in 802 header, trim of
2018 * additional data.
2019 */
2020 dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n",
2021 dev->name, protolen);
2022 return protolen;
2023 } else {
2024 /* less data on wire than mentioned in header.
2025 * Discard the packet.
2026 */
2027 dprintk(KERN_DEBUG "%s: nv_getlen: discarding long packet.\n",
2028 dev->name);
2029 return -1;
2030 }
2031 } else {
2032 /* short packet. Accept only if 802 values are also short */
2033 if (protolen > ETH_ZLEN) {
2034 dprintk(KERN_DEBUG "%s: nv_getlen: discarding short packet.\n",
2035 dev->name);
2036 return -1;
2037 }
2038 dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n",
2039 dev->name, datalen);
2040 return datalen;
2041 }
2042}
2043
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002044static int nv_rx_process(struct net_device *dev, int limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002046 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002047 u32 flags;
Ayaz Abdullaee407b02006-02-04 13:13:17 -05002048 u32 vlanflags = 0;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002049 int count;
Ayaz Abdullaee407b02006-02-04 13:13:17 -05002050
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002051 for (count = 0; count < limit; ++count) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 struct sk_buff *skb;
2053 int len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002055 if (np->get_rx.orig == np->put_rx.orig)
2056 break; /* we scanned the whole ring - do not continue */
2057 flags = le32_to_cpu(np->get_rx.orig->flaglen);
2058 len = nv_descr_getlength(np->get_rx.orig, np->desc_ver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002059
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002060 dprintk(KERN_DEBUG "%s: nv_rx_process: flags 0x%x.\n",
2061 dev->name, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002063 if (flags & NV_RX_AVAIL)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002064 break; /* still owned by hardware, */
2065
2066 /*
2067 * the packet is for us - immediately tear down the pci mapping.
2068 * TODO: check if a prefetch of the first cacheline improves
2069 * the performance.
2070 */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002071 pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma,
2072 np->get_rx_ctx->dma_len,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073 PCI_DMA_FROMDEVICE);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002074 skb = np->get_rx_ctx->skb;
2075 np->get_rx_ctx->skb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002076
2077 {
2078 int j;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002079 dprintk(KERN_DEBUG "Dumping packet (flags 0x%x).",flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002080 for (j=0; j<64; j++) {
2081 if ((j%16) == 0)
2082 dprintk("\n%03x:", j);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002083 dprintk(" %02x", ((unsigned char*)skb->data)[j]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002084 }
2085 dprintk("\n");
2086 }
2087 /* look at what we actually got: */
2088 if (np->desc_ver == DESC_VER_1) {
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002089 if (!(flags & NV_RX_DESCRIPTORVALID)) {
2090 dev_kfree_skb(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091 goto next_pkt;
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002092 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002093
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002094 if (flags & NV_RX_ERROR) {
2095 if (flags & NV_RX_MISSEDFRAME) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002096 np->stats.rx_missed_errors++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002097 np->stats.rx_errors++;
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002098 dev_kfree_skb(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099 goto next_pkt;
2100 }
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002101 if (flags & (NV_RX_ERROR1|NV_RX_ERROR2|NV_RX_ERROR3)) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002102 np->stats.rx_errors++;
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002103 dev_kfree_skb(skb);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002104 goto next_pkt;
2105 }
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002106 if (flags & NV_RX_CRCERR) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002107 np->stats.rx_crc_errors++;
2108 np->stats.rx_errors++;
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002109 dev_kfree_skb(skb);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002110 goto next_pkt;
2111 }
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002112 if (flags & NV_RX_OVERFLOW) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002113 np->stats.rx_over_errors++;
2114 np->stats.rx_errors++;
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002115 dev_kfree_skb(skb);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002116 goto next_pkt;
2117 }
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002118 if (flags & NV_RX_ERROR4) {
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002119 len = nv_getlen(dev, skb->data, len);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002120 if (len < 0) {
2121 np->stats.rx_errors++;
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002122 dev_kfree_skb(skb);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002123 goto next_pkt;
2124 }
2125 }
2126 /* framing errors are soft errors. */
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002127 if (flags & NV_RX_FRAMINGERR) {
2128 if (flags & NV_RX_SUBSTRACT1) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002129 len--;
2130 }
Manfred Spraul22c6d142005-04-19 21:17:09 +02002131 }
2132 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133 } else {
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002134 if (!(flags & NV_RX2_DESCRIPTORVALID)) {
2135 dev_kfree_skb(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002136 goto next_pkt;
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002137 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002138
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002139 if (flags & NV_RX2_ERROR) {
2140 if (flags & (NV_RX2_ERROR1|NV_RX2_ERROR2|NV_RX2_ERROR3)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002141 np->stats.rx_errors++;
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002142 dev_kfree_skb(skb);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143 goto next_pkt;
2144 }
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002145 if (flags & NV_RX2_CRCERR) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002146 np->stats.rx_crc_errors++;
2147 np->stats.rx_errors++;
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002148 dev_kfree_skb(skb);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002149 goto next_pkt;
2150 }
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002151 if (flags & NV_RX2_OVERFLOW) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002152 np->stats.rx_over_errors++;
2153 np->stats.rx_errors++;
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002154 dev_kfree_skb(skb);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002155 goto next_pkt;
2156 }
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002157 if (flags & NV_RX2_ERROR4) {
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002158 len = nv_getlen(dev, skb->data, len);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002159 if (len < 0) {
2160 np->stats.rx_errors++;
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002161 dev_kfree_skb(skb);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002162 goto next_pkt;
2163 }
2164 }
2165 /* framing errors are soft errors */
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002166 if (flags & NV_RX2_FRAMINGERR) {
2167 if (flags & NV_RX2_SUBSTRACT1) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002168 len--;
2169 }
Manfred Spraul22c6d142005-04-19 21:17:09 +02002170 }
2171 }
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04002172 if (np->rx_csum) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002173 flags &= NV_RX2_CHECKSUMMASK;
2174 if (flags == NV_RX2_CHECKSUMOK1 ||
2175 flags == NV_RX2_CHECKSUMOK2 ||
2176 flags == NV_RX2_CHECKSUMOK3) {
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04002177 dprintk(KERN_DEBUG "%s: hw checksum hit!.\n", dev->name);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002178 skb->ip_summed = CHECKSUM_UNNECESSARY;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04002179 } else {
2180 dprintk(KERN_DEBUG "%s: hwchecksum miss!.\n", dev->name);
2181 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002182 }
2183 }
2184 /* got a valid packet - forward it to the network core */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002185 skb_put(skb, len);
2186 skb->protocol = eth_type_trans(skb, dev);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002187 dprintk(KERN_DEBUG "%s: nv_rx_process: %d bytes, proto %d accepted.\n",
2188 dev->name, len, skb->protocol);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002189#ifdef CONFIG_FORCEDETH_NAPI
2190 if (np->vlangrp && (vlanflags & NV_RX3_VLAN_TAG_PRESENT))
2191 vlan_hwaccel_receive_skb(skb, np->vlangrp,
2192 vlanflags & NV_RX3_VLAN_TAG_MASK);
2193 else
2194 netif_receive_skb(skb);
2195#else
2196 if (np->vlangrp && (vlanflags & NV_RX3_VLAN_TAG_PRESENT))
2197 vlan_hwaccel_rx(skb, np->vlangrp,
2198 vlanflags & NV_RX3_VLAN_TAG_MASK);
2199 else
Ayaz Abdullaee407b02006-02-04 13:13:17 -05002200 netif_rx(skb);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002201#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002202 dev->last_rx = jiffies;
2203 np->stats.rx_packets++;
2204 np->stats.rx_bytes += len;
2205next_pkt:
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002206 if (np->get_rx.orig++ == np->last_rx.orig)
2207 np->get_rx.orig = np->first_rx.orig;
2208 if (np->get_rx_ctx++ == np->last_rx_ctx)
2209 np->get_rx_ctx = np->first_rx_ctx;
2210 }
2211
2212 return count;
2213}
2214
2215static int nv_rx_process_optimized(struct net_device *dev, int limit)
2216{
2217 struct fe_priv *np = netdev_priv(dev);
2218 u32 flags;
2219 u32 vlanflags = 0;
2220 int count;
2221
2222 for (count = 0; count < limit; ++count) {
2223 struct sk_buff *skb;
2224 int len;
2225
2226 if (np->get_rx.ex == np->put_rx.ex)
2227 break; /* we scanned the whole ring - do not continue */
2228 flags = le32_to_cpu(np->get_rx.ex->flaglen);
2229 len = nv_descr_getlength_ex(np->get_rx.ex, np->desc_ver);
2230 vlanflags = le32_to_cpu(np->get_rx.ex->buflow);
2231
2232 dprintk(KERN_DEBUG "%s: nv_rx_process_optimized: flags 0x%x.\n",
2233 dev->name, flags);
2234
2235 if (flags & NV_RX_AVAIL)
2236 break; /* still owned by hardware, */
2237
2238 /*
2239 * the packet is for us - immediately tear down the pci mapping.
2240 * TODO: check if a prefetch of the first cacheline improves
2241 * the performance.
2242 */
2243 pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma,
2244 np->get_rx_ctx->dma_len,
2245 PCI_DMA_FROMDEVICE);
2246 skb = np->get_rx_ctx->skb;
2247 np->get_rx_ctx->skb = NULL;
2248
2249 {
2250 int j;
2251 dprintk(KERN_DEBUG "Dumping packet (flags 0x%x).",flags);
2252 for (j=0; j<64; j++) {
2253 if ((j%16) == 0)
2254 dprintk("\n%03x:", j);
2255 dprintk(" %02x", ((unsigned char*)skb->data)[j]);
2256 }
2257 dprintk("\n");
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002258 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002259 /* look at what we actually got: */
2260 if (!(flags & NV_RX2_DESCRIPTORVALID)) {
2261 dev_kfree_skb(skb);
2262 goto next_pkt;
2263 }
2264
2265 if (flags & NV_RX2_ERROR) {
2266 if (flags & (NV_RX2_ERROR1|NV_RX2_ERROR2|NV_RX2_ERROR3)) {
2267 np->stats.rx_errors++;
2268 dev_kfree_skb(skb);
2269 goto next_pkt;
2270 }
2271 if (flags & NV_RX2_CRCERR) {
2272 np->stats.rx_crc_errors++;
2273 np->stats.rx_errors++;
2274 dev_kfree_skb(skb);
2275 goto next_pkt;
2276 }
2277 if (flags & NV_RX2_OVERFLOW) {
2278 np->stats.rx_over_errors++;
2279 np->stats.rx_errors++;
2280 dev_kfree_skb(skb);
2281 goto next_pkt;
2282 }
2283 if (flags & NV_RX2_ERROR4) {
2284 len = nv_getlen(dev, skb->data, len);
2285 if (len < 0) {
2286 np->stats.rx_errors++;
2287 dev_kfree_skb(skb);
2288 goto next_pkt;
2289 }
2290 }
2291 /* framing errors are soft errors */
2292 if (flags & NV_RX2_FRAMINGERR) {
2293 if (flags & NV_RX2_SUBSTRACT1) {
2294 len--;
2295 }
2296 }
2297 }
2298 if (np->rx_csum) {
2299 flags &= NV_RX2_CHECKSUMMASK;
2300 if (flags == NV_RX2_CHECKSUMOK1 ||
2301 flags == NV_RX2_CHECKSUMOK2 ||
2302 flags == NV_RX2_CHECKSUMOK3) {
2303 dprintk(KERN_DEBUG "%s: hw checksum hit!.\n", dev->name);
2304 skb->ip_summed = CHECKSUM_UNNECESSARY;
2305 } else {
2306 dprintk(KERN_DEBUG "%s: hwchecksum miss!.\n", dev->name);
2307 }
2308 }
2309 /* got a valid packet - forward it to the network core */
2310 skb_put(skb, len);
2311 skb->protocol = eth_type_trans(skb, dev);
2312 dprintk(KERN_DEBUG "%s: nv_rx_process: %d bytes, proto %d accepted.\n",
2313 dev->name, len, skb->protocol);
2314#ifdef CONFIG_FORCEDETH_NAPI
2315 if (np->vlangrp && (vlanflags & NV_RX3_VLAN_TAG_PRESENT))
2316 vlan_hwaccel_receive_skb(skb, np->vlangrp,
2317 vlanflags & NV_RX3_VLAN_TAG_MASK);
2318 else
2319 netif_receive_skb(skb);
2320#else
2321 if (np->vlangrp && (vlanflags & NV_RX3_VLAN_TAG_PRESENT))
2322 vlan_hwaccel_rx(skb, np->vlangrp,
2323 vlanflags & NV_RX3_VLAN_TAG_MASK);
2324 else
2325 netif_rx(skb);
2326#endif
2327 dev->last_rx = jiffies;
2328 np->stats.rx_packets++;
2329 np->stats.rx_bytes += len;
2330next_pkt:
2331 if (np->get_rx.ex++ == np->last_rx.ex)
2332 np->get_rx.ex = np->first_rx.ex;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002333 if (np->get_rx_ctx++ == np->last_rx_ctx)
2334 np->get_rx_ctx = np->first_rx_ctx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002335 }
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002336
2337 return count;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002338}
2339
Manfred Sprauld81c0982005-07-31 18:20:30 +02002340static void set_bufsize(struct net_device *dev)
2341{
2342 struct fe_priv *np = netdev_priv(dev);
2343
2344 if (dev->mtu <= ETH_DATA_LEN)
2345 np->rx_buf_sz = ETH_DATA_LEN + NV_RX_HEADERS;
2346 else
2347 np->rx_buf_sz = dev->mtu + NV_RX_HEADERS;
2348}
2349
Linus Torvalds1da177e2005-04-16 15:20:36 -07002350/*
2351 * nv_change_mtu: dev->change_mtu function
2352 * Called with dev_base_lock held for read.
2353 */
2354static int nv_change_mtu(struct net_device *dev, int new_mtu)
2355{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002356 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002357 int old_mtu;
2358
2359 if (new_mtu < 64 || new_mtu > np->pkt_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002360 return -EINVAL;
Manfred Sprauld81c0982005-07-31 18:20:30 +02002361
2362 old_mtu = dev->mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002363 dev->mtu = new_mtu;
Manfred Sprauld81c0982005-07-31 18:20:30 +02002364
2365 /* return early if the buffer sizes will not change */
2366 if (old_mtu <= ETH_DATA_LEN && new_mtu <= ETH_DATA_LEN)
2367 return 0;
2368 if (old_mtu == new_mtu)
2369 return 0;
2370
2371 /* synchronized against open : rtnl_lock() held by caller */
2372 if (netif_running(dev)) {
viro@ftp.linux.org.uk25097d42005-09-06 01:36:58 +01002373 u8 __iomem *base = get_hwbase(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002374 /*
2375 * It seems that the nic preloads valid ring entries into an
2376 * internal buffer. The procedure for flushing everything is
2377 * guessed, there is probably a simpler approach.
2378 * Changing the MTU is a rare event, it shouldn't matter.
2379 */
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002380 nv_disable_irq(dev);
Herbert Xu932ff272006-06-09 12:20:56 -07002381 netif_tx_lock_bh(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002382 spin_lock(&np->lock);
2383 /* stop engines */
2384 nv_stop_rx(dev);
2385 nv_stop_tx(dev);
2386 nv_txrx_reset(dev);
2387 /* drain rx queue */
2388 nv_drain_rx(dev);
2389 nv_drain_tx(dev);
2390 /* reinit driver view of the rx queue */
Manfred Sprauld81c0982005-07-31 18:20:30 +02002391 set_bufsize(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04002392 if (nv_init_ring(dev)) {
Manfred Sprauld81c0982005-07-31 18:20:30 +02002393 if (!np->in_shutdown)
2394 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2395 }
2396 /* reinit nic view of the rx queue */
2397 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
Ayaz Abdulla0832b252006-02-04 13:13:26 -05002398 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04002399 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Manfred Sprauld81c0982005-07-31 18:20:30 +02002400 base + NvRegRingSizes);
2401 pci_push(base);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002402 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002403 pci_push(base);
2404
2405 /* restart rx engine */
2406 nv_start_rx(dev);
2407 nv_start_tx(dev);
2408 spin_unlock(&np->lock);
Herbert Xu932ff272006-06-09 12:20:56 -07002409 netif_tx_unlock_bh(dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002410 nv_enable_irq(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002411 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002412 return 0;
2413}
2414
Manfred Spraul72b31782005-07-31 18:33:34 +02002415static void nv_copy_mac_to_hw(struct net_device *dev)
2416{
viro@ftp.linux.org.uk25097d42005-09-06 01:36:58 +01002417 u8 __iomem *base = get_hwbase(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002418 u32 mac[2];
2419
2420 mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) +
2421 (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24);
2422 mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8);
2423
2424 writel(mac[0], base + NvRegMacAddrA);
2425 writel(mac[1], base + NvRegMacAddrB);
2426}
2427
2428/*
2429 * nv_set_mac_address: dev->set_mac_address function
2430 * Called with rtnl_lock() held.
2431 */
2432static int nv_set_mac_address(struct net_device *dev, void *addr)
2433{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002434 struct fe_priv *np = netdev_priv(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002435 struct sockaddr *macaddr = (struct sockaddr*)addr;
2436
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002437 if (!is_valid_ether_addr(macaddr->sa_data))
Manfred Spraul72b31782005-07-31 18:33:34 +02002438 return -EADDRNOTAVAIL;
2439
2440 /* synchronized against open : rtnl_lock() held by caller */
2441 memcpy(dev->dev_addr, macaddr->sa_data, ETH_ALEN);
2442
2443 if (netif_running(dev)) {
Herbert Xu932ff272006-06-09 12:20:56 -07002444 netif_tx_lock_bh(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002445 spin_lock_irq(&np->lock);
2446
2447 /* stop rx engine */
2448 nv_stop_rx(dev);
2449
2450 /* set mac address */
2451 nv_copy_mac_to_hw(dev);
2452
2453 /* restart rx engine */
2454 nv_start_rx(dev);
2455 spin_unlock_irq(&np->lock);
Herbert Xu932ff272006-06-09 12:20:56 -07002456 netif_tx_unlock_bh(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002457 } else {
2458 nv_copy_mac_to_hw(dev);
2459 }
2460 return 0;
2461}
2462
Linus Torvalds1da177e2005-04-16 15:20:36 -07002463/*
2464 * nv_set_multicast: dev->set_multicast function
Herbert Xu932ff272006-06-09 12:20:56 -07002465 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002466 */
2467static void nv_set_multicast(struct net_device *dev)
2468{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002469 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002470 u8 __iomem *base = get_hwbase(dev);
2471 u32 addr[2];
2472 u32 mask[2];
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002473 u32 pff = readl(base + NvRegPacketFilterFlags) & NVREG_PFF_PAUSE_RX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474
2475 memset(addr, 0, sizeof(addr));
2476 memset(mask, 0, sizeof(mask));
2477
2478 if (dev->flags & IFF_PROMISC) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002479 pff |= NVREG_PFF_PROMISC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002480 } else {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002481 pff |= NVREG_PFF_MYADDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002482
2483 if (dev->flags & IFF_ALLMULTI || dev->mc_list) {
2484 u32 alwaysOff[2];
2485 u32 alwaysOn[2];
2486
2487 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0xffffffff;
2488 if (dev->flags & IFF_ALLMULTI) {
2489 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0;
2490 } else {
2491 struct dev_mc_list *walk;
2492
2493 walk = dev->mc_list;
2494 while (walk != NULL) {
2495 u32 a, b;
2496 a = le32_to_cpu(*(u32 *) walk->dmi_addr);
2497 b = le16_to_cpu(*(u16 *) (&walk->dmi_addr[4]));
2498 alwaysOn[0] &= a;
2499 alwaysOff[0] &= ~a;
2500 alwaysOn[1] &= b;
2501 alwaysOff[1] &= ~b;
2502 walk = walk->next;
2503 }
2504 }
2505 addr[0] = alwaysOn[0];
2506 addr[1] = alwaysOn[1];
2507 mask[0] = alwaysOn[0] | alwaysOff[0];
2508 mask[1] = alwaysOn[1] | alwaysOff[1];
2509 }
2510 }
2511 addr[0] |= NVREG_MCASTADDRA_FORCE;
2512 pff |= NVREG_PFF_ALWAYS;
2513 spin_lock_irq(&np->lock);
2514 nv_stop_rx(dev);
2515 writel(addr[0], base + NvRegMulticastAddrA);
2516 writel(addr[1], base + NvRegMulticastAddrB);
2517 writel(mask[0], base + NvRegMulticastMaskA);
2518 writel(mask[1], base + NvRegMulticastMaskB);
2519 writel(pff, base + NvRegPacketFilterFlags);
2520 dprintk(KERN_INFO "%s: reconfiguration for multicast lists.\n",
2521 dev->name);
2522 nv_start_rx(dev);
2523 spin_unlock_irq(&np->lock);
2524}
2525
Adrian Bunkc7985052006-06-22 12:03:29 +02002526static void nv_update_pause(struct net_device *dev, u32 pause_flags)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002527{
2528 struct fe_priv *np = netdev_priv(dev);
2529 u8 __iomem *base = get_hwbase(dev);
2530
2531 np->pause_flags &= ~(NV_PAUSEFRAME_TX_ENABLE | NV_PAUSEFRAME_RX_ENABLE);
2532
2533 if (np->pause_flags & NV_PAUSEFRAME_RX_CAPABLE) {
2534 u32 pff = readl(base + NvRegPacketFilterFlags) & ~NVREG_PFF_PAUSE_RX;
2535 if (pause_flags & NV_PAUSEFRAME_RX_ENABLE) {
2536 writel(pff|NVREG_PFF_PAUSE_RX, base + NvRegPacketFilterFlags);
2537 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
2538 } else {
2539 writel(pff, base + NvRegPacketFilterFlags);
2540 }
2541 }
2542 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE) {
2543 u32 regmisc = readl(base + NvRegMisc1) & ~NVREG_MISC1_PAUSE_TX;
2544 if (pause_flags & NV_PAUSEFRAME_TX_ENABLE) {
2545 writel(NVREG_TX_PAUSEFRAME_ENABLE, base + NvRegTxPauseFrame);
2546 writel(regmisc|NVREG_MISC1_PAUSE_TX, base + NvRegMisc1);
2547 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
2548 } else {
2549 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
2550 writel(regmisc, base + NvRegMisc1);
2551 }
2552 }
2553}
2554
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05002555/**
2556 * nv_update_linkspeed: Setup the MAC according to the link partner
2557 * @dev: Network device to be configured
2558 *
2559 * The function queries the PHY and checks if there is a link partner.
2560 * If yes, then it sets up the MAC accordingly. Otherwise, the MAC is
2561 * set to 10 MBit HD.
2562 *
2563 * The function returns 0 if there is no link partner and 1 if there is
2564 * a good link partner.
2565 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566static int nv_update_linkspeed(struct net_device *dev)
2567{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002568 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002569 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002570 int adv = 0;
2571 int lpa = 0;
2572 int adv_lpa, adv_pause, lpa_pause;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 int newls = np->linkspeed;
2574 int newdup = np->duplex;
2575 int mii_status;
2576 int retval = 0;
Ayaz Abdulla9744e212006-07-06 16:45:58 -04002577 u32 control_1000, status_1000, phyreg, pause_flags, txreg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578
2579 /* BMSR_LSTATUS is latched, read it twice:
2580 * we want the current value.
2581 */
2582 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
2583 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
2584
2585 if (!(mii_status & BMSR_LSTATUS)) {
2586 dprintk(KERN_DEBUG "%s: no link detected by phy - falling back to 10HD.\n",
2587 dev->name);
2588 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2589 newdup = 0;
2590 retval = 0;
2591 goto set_speed;
2592 }
2593
2594 if (np->autoneg == 0) {
2595 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: autoneg off, PHY set to 0x%04x.\n",
2596 dev->name, np->fixed_mode);
2597 if (np->fixed_mode & LPA_100FULL) {
2598 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2599 newdup = 1;
2600 } else if (np->fixed_mode & LPA_100HALF) {
2601 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2602 newdup = 0;
2603 } else if (np->fixed_mode & LPA_10FULL) {
2604 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2605 newdup = 1;
2606 } else {
2607 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2608 newdup = 0;
2609 }
2610 retval = 1;
2611 goto set_speed;
2612 }
2613 /* check auto negotiation is complete */
2614 if (!(mii_status & BMSR_ANEGCOMPLETE)) {
2615 /* still in autonegotiation - configure nic for 10 MBit HD and wait. */
2616 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2617 newdup = 0;
2618 retval = 0;
2619 dprintk(KERN_DEBUG "%s: autoneg not completed - falling back to 10HD.\n", dev->name);
2620 goto set_speed;
2621 }
2622
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002623 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
2624 lpa = mii_rw(dev, np->phyaddr, MII_LPA, MII_READ);
2625 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: PHY advertises 0x%04x, lpa 0x%04x.\n",
2626 dev->name, adv, lpa);
2627
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 retval = 1;
2629 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002630 control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
2631 status_1000 = mii_rw(dev, np->phyaddr, MII_STAT1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002632
2633 if ((control_1000 & ADVERTISE_1000FULL) &&
2634 (status_1000 & LPA_1000FULL)) {
2635 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: GBit ethernet detected.\n",
2636 dev->name);
2637 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_1000;
2638 newdup = 1;
2639 goto set_speed;
2640 }
2641 }
2642
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643 /* FIXME: handle parallel detection properly */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002644 adv_lpa = lpa & adv;
2645 if (adv_lpa & LPA_100FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2647 newdup = 1;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002648 } else if (adv_lpa & LPA_100HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
2650 newdup = 0;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002651 } else if (adv_lpa & LPA_10FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002652 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2653 newdup = 1;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002654 } else if (adv_lpa & LPA_10HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002655 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2656 newdup = 0;
2657 } else {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002658 dprintk(KERN_DEBUG "%s: bad ability %04x - falling back to 10HD.\n", dev->name, adv_lpa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002659 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
2660 newdup = 0;
2661 }
2662
2663set_speed:
2664 if (np->duplex == newdup && np->linkspeed == newls)
2665 return retval;
2666
2667 dprintk(KERN_INFO "%s: changing link setting from %d/%d to %d/%d.\n",
2668 dev->name, np->linkspeed, np->duplex, newls, newdup);
2669
2670 np->duplex = newdup;
2671 np->linkspeed = newls;
2672
2673 if (np->gigabit == PHY_GIGABIT) {
2674 phyreg = readl(base + NvRegRandomSeed);
2675 phyreg &= ~(0x3FF00);
2676 if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10)
2677 phyreg |= NVREG_RNDSEED_FORCE3;
2678 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100)
2679 phyreg |= NVREG_RNDSEED_FORCE2;
2680 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000)
2681 phyreg |= NVREG_RNDSEED_FORCE;
2682 writel(phyreg, base + NvRegRandomSeed);
2683 }
2684
2685 phyreg = readl(base + NvRegPhyInterface);
2686 phyreg &= ~(PHY_HALF|PHY_100|PHY_1000);
2687 if (np->duplex == 0)
2688 phyreg |= PHY_HALF;
2689 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100)
2690 phyreg |= PHY_100;
2691 else if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
2692 phyreg |= PHY_1000;
2693 writel(phyreg, base + NvRegPhyInterface);
2694
Ayaz Abdulla9744e212006-07-06 16:45:58 -04002695 if (phyreg & PHY_RGMII) {
2696 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
2697 txreg = NVREG_TX_DEFERRAL_RGMII_1000;
2698 else
2699 txreg = NVREG_TX_DEFERRAL_RGMII_10_100;
2700 } else {
2701 txreg = NVREG_TX_DEFERRAL_DEFAULT;
2702 }
2703 writel(txreg, base + NvRegTxDeferral);
2704
Ayaz Abdulla95d161c2006-07-06 16:46:25 -04002705 if (np->desc_ver == DESC_VER_1) {
2706 txreg = NVREG_TX_WM_DESC1_DEFAULT;
2707 } else {
2708 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
2709 txreg = NVREG_TX_WM_DESC2_3_1000;
2710 else
2711 txreg = NVREG_TX_WM_DESC2_3_DEFAULT;
2712 }
2713 writel(txreg, base + NvRegTxWatermark);
2714
Linus Torvalds1da177e2005-04-16 15:20:36 -07002715 writel(NVREG_MISC1_FORCE | ( np->duplex ? 0 : NVREG_MISC1_HD),
2716 base + NvRegMisc1);
2717 pci_push(base);
2718 writel(np->linkspeed, base + NvRegLinkSpeed);
2719 pci_push(base);
2720
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002721 pause_flags = 0;
2722 /* setup pause frame */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002723 if (np->duplex != 0) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002724 if (np->autoneg && np->pause_flags & NV_PAUSEFRAME_AUTONEG) {
2725 adv_pause = adv & (ADVERTISE_PAUSE_CAP| ADVERTISE_PAUSE_ASYM);
2726 lpa_pause = lpa & (LPA_PAUSE_CAP| LPA_PAUSE_ASYM);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002727
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002728 switch (adv_pause) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002729 case ADVERTISE_PAUSE_CAP:
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002730 if (lpa_pause & LPA_PAUSE_CAP) {
2731 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
2732 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
2733 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
2734 }
2735 break;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002736 case ADVERTISE_PAUSE_ASYM:
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002737 if (lpa_pause == (LPA_PAUSE_CAP| LPA_PAUSE_ASYM))
2738 {
2739 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
2740 }
2741 break;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002742 case ADVERTISE_PAUSE_CAP| ADVERTISE_PAUSE_ASYM:
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002743 if (lpa_pause & LPA_PAUSE_CAP)
2744 {
2745 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
2746 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
2747 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
2748 }
2749 if (lpa_pause == LPA_PAUSE_ASYM)
2750 {
2751 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
2752 }
2753 break;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002754 }
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002755 } else {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002756 pause_flags = np->pause_flags;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002757 }
2758 }
Ayaz Abdullab6d07732006-06-10 22:47:42 -04002759 nv_update_pause(dev, pause_flags);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04002760
Linus Torvalds1da177e2005-04-16 15:20:36 -07002761 return retval;
2762}
2763
2764static void nv_linkchange(struct net_device *dev)
2765{
2766 if (nv_update_linkspeed(dev)) {
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05002767 if (!netif_carrier_ok(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002768 netif_carrier_on(dev);
2769 printk(KERN_INFO "%s: link up.\n", dev->name);
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05002770 nv_start_rx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002771 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002772 } else {
2773 if (netif_carrier_ok(dev)) {
2774 netif_carrier_off(dev);
2775 printk(KERN_INFO "%s: link down.\n", dev->name);
2776 nv_stop_rx(dev);
2777 }
2778 }
2779}
2780
2781static void nv_link_irq(struct net_device *dev)
2782{
2783 u8 __iomem *base = get_hwbase(dev);
2784 u32 miistat;
2785
2786 miistat = readl(base + NvRegMIIStatus);
2787 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
2788 dprintk(KERN_INFO "%s: link change irq, status 0x%x.\n", dev->name, miistat);
2789
2790 if (miistat & (NVREG_MIISTAT_LINKCHANGE))
2791 nv_linkchange(dev);
2792 dprintk(KERN_DEBUG "%s: link change notification done.\n", dev->name);
2793}
2794
David Howells7d12e782006-10-05 14:55:46 +01002795static irqreturn_t nv_nic_irq(int foo, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796{
2797 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002798 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 u8 __iomem *base = get_hwbase(dev);
2800 u32 events;
2801 int i;
2802
2803 dprintk(KERN_DEBUG "%s: nv_nic_irq\n", dev->name);
2804
2805 for (i=0; ; i++) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002806 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
2807 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
2808 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
2809 } else {
2810 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
2811 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
2812 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 pci_push(base);
2814 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
2815 if (!(events & np->irqmask))
2816 break;
2817
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002818 spin_lock(&np->lock);
2819 nv_tx_done(dev);
2820 spin_unlock(&np->lock);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002821
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822 if (events & NVREG_IRQ_LINK) {
2823 spin_lock(&np->lock);
2824 nv_link_irq(dev);
2825 spin_unlock(&np->lock);
2826 }
2827 if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
2828 spin_lock(&np->lock);
2829 nv_linkchange(dev);
2830 spin_unlock(&np->lock);
2831 np->link_timeout = jiffies + LINK_TIMEOUT;
2832 }
2833 if (events & (NVREG_IRQ_TX_ERR)) {
2834 dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
2835 dev->name, events);
2836 }
2837 if (events & (NVREG_IRQ_UNKNOWN)) {
2838 printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
2839 dev->name, events);
2840 }
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05002841 if (unlikely(events & NVREG_IRQ_RECOVER_ERROR)) {
2842 spin_lock(&np->lock);
2843 /* disable interrupts on the nic */
2844 if (!(np->msi_flags & NV_MSI_X_ENABLED))
2845 writel(0, base + NvRegIrqMask);
2846 else
2847 writel(np->irqmask, base + NvRegIrqMask);
2848 pci_push(base);
2849
2850 if (!np->in_shutdown) {
2851 np->nic_poll_irq = np->irqmask;
2852 np->recover_error = 1;
2853 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
2854 }
2855 spin_unlock(&np->lock);
2856 break;
2857 }
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002858#ifdef CONFIG_FORCEDETH_NAPI
2859 if (events & NVREG_IRQ_RX_ALL) {
2860 netif_rx_schedule(dev);
2861
2862 /* Disable furthur receive irq's */
2863 spin_lock(&np->lock);
2864 np->irqmask &= ~NVREG_IRQ_RX_ALL;
2865
2866 if (np->msi_flags & NV_MSI_X_ENABLED)
2867 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
2868 else
2869 writel(np->irqmask, base + NvRegIrqMask);
2870 spin_unlock(&np->lock);
2871 }
2872#else
2873 nv_rx_process(dev, dev->weight);
2874 if (nv_alloc_rx(dev)) {
2875 spin_lock(&np->lock);
2876 if (!np->in_shutdown)
2877 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2878 spin_unlock(&np->lock);
2879 }
2880#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 if (i > max_interrupt_work) {
2882 spin_lock(&np->lock);
2883 /* disable interrupts on the nic */
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002884 if (!(np->msi_flags & NV_MSI_X_ENABLED))
2885 writel(0, base + NvRegIrqMask);
2886 else
2887 writel(np->irqmask, base + NvRegIrqMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 pci_push(base);
2889
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002890 if (!np->in_shutdown) {
2891 np->nic_poll_irq = np->irqmask;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002892 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002893 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002894 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq.\n", dev->name, i);
2895 spin_unlock(&np->lock);
2896 break;
2897 }
2898
2899 }
2900 dprintk(KERN_DEBUG "%s: nv_nic_irq completed\n", dev->name);
2901
2902 return IRQ_RETVAL(i);
2903}
2904
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002905static irqreturn_t nv_nic_irq_optimized(int foo, void *data)
2906{
2907 struct net_device *dev = (struct net_device *) data;
2908 struct fe_priv *np = netdev_priv(dev);
2909 u8 __iomem *base = get_hwbase(dev);
2910 u32 events;
2911 int i;
2912
2913 dprintk(KERN_DEBUG "%s: nv_nic_irq_optimized\n", dev->name);
2914
2915 for (i=0; ; i++) {
2916 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
2917 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
2918 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
2919 } else {
2920 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
2921 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
2922 }
2923 pci_push(base);
2924 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
2925 if (!(events & np->irqmask))
2926 break;
2927
2928 spin_lock(&np->lock);
2929 nv_tx_done_optimized(dev);
2930 spin_unlock(&np->lock);
2931
2932 if (events & NVREG_IRQ_LINK) {
2933 spin_lock(&np->lock);
2934 nv_link_irq(dev);
2935 spin_unlock(&np->lock);
2936 }
2937 if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
2938 spin_lock(&np->lock);
2939 nv_linkchange(dev);
2940 spin_unlock(&np->lock);
2941 np->link_timeout = jiffies + LINK_TIMEOUT;
2942 }
2943 if (events & (NVREG_IRQ_TX_ERR)) {
2944 dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
2945 dev->name, events);
2946 }
2947 if (events & (NVREG_IRQ_UNKNOWN)) {
2948 printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
2949 dev->name, events);
2950 }
2951 if (unlikely(events & NVREG_IRQ_RECOVER_ERROR)) {
2952 spin_lock(&np->lock);
2953 /* disable interrupts on the nic */
2954 if (!(np->msi_flags & NV_MSI_X_ENABLED))
2955 writel(0, base + NvRegIrqMask);
2956 else
2957 writel(np->irqmask, base + NvRegIrqMask);
2958 pci_push(base);
2959
2960 if (!np->in_shutdown) {
2961 np->nic_poll_irq = np->irqmask;
2962 np->recover_error = 1;
2963 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
2964 }
2965 spin_unlock(&np->lock);
2966 break;
2967 }
2968
2969#ifdef CONFIG_FORCEDETH_NAPI
2970 if (events & NVREG_IRQ_RX_ALL) {
2971 netif_rx_schedule(dev);
2972
2973 /* Disable furthur receive irq's */
2974 spin_lock(&np->lock);
2975 np->irqmask &= ~NVREG_IRQ_RX_ALL;
2976
2977 if (np->msi_flags & NV_MSI_X_ENABLED)
2978 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
2979 else
2980 writel(np->irqmask, base + NvRegIrqMask);
2981 spin_unlock(&np->lock);
2982 }
2983#else
2984 nv_rx_process_optimized(dev, dev->weight);
2985 if (nv_alloc_rx_optimized(dev)) {
2986 spin_lock(&np->lock);
2987 if (!np->in_shutdown)
2988 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2989 spin_unlock(&np->lock);
2990 }
2991#endif
2992 if (i > max_interrupt_work) {
2993 spin_lock(&np->lock);
2994 /* disable interrupts on the nic */
2995 if (!(np->msi_flags & NV_MSI_X_ENABLED))
2996 writel(0, base + NvRegIrqMask);
2997 else
2998 writel(np->irqmask, base + NvRegIrqMask);
2999 pci_push(base);
3000
3001 if (!np->in_shutdown) {
3002 np->nic_poll_irq = np->irqmask;
3003 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3004 }
3005 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq.\n", dev->name, i);
3006 spin_unlock(&np->lock);
3007 break;
3008 }
3009
3010 }
3011 dprintk(KERN_DEBUG "%s: nv_nic_irq_optimized completed\n", dev->name);
3012
3013 return IRQ_RETVAL(i);
3014}
3015
David Howells7d12e782006-10-05 14:55:46 +01003016static irqreturn_t nv_nic_irq_tx(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003017{
3018 struct net_device *dev = (struct net_device *) data;
3019 struct fe_priv *np = netdev_priv(dev);
3020 u8 __iomem *base = get_hwbase(dev);
3021 u32 events;
3022 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003023 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003024
3025 dprintk(KERN_DEBUG "%s: nv_nic_irq_tx\n", dev->name);
3026
3027 for (i=0; ; i++) {
3028 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_TX_ALL;
3029 writel(NVREG_IRQ_TX_ALL, base + NvRegMSIXIrqStatus);
3030 pci_push(base);
3031 dprintk(KERN_DEBUG "%s: tx irq: %08x\n", dev->name, events);
3032 if (!(events & np->irqmask))
3033 break;
3034
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003035 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003036 nv_tx_done_optimized(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003037 spin_unlock_irqrestore(&np->lock, flags);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003038
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003039 if (events & (NVREG_IRQ_TX_ERR)) {
3040 dprintk(KERN_DEBUG "%s: received irq with events 0x%x. Probably TX fail.\n",
3041 dev->name, events);
3042 }
3043 if (i > max_interrupt_work) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003044 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003045 /* disable interrupts on the nic */
3046 writel(NVREG_IRQ_TX_ALL, base + NvRegIrqMask);
3047 pci_push(base);
3048
3049 if (!np->in_shutdown) {
3050 np->nic_poll_irq |= NVREG_IRQ_TX_ALL;
3051 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3052 }
3053 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_tx.\n", dev->name, i);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003054 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003055 break;
3056 }
3057
3058 }
3059 dprintk(KERN_DEBUG "%s: nv_nic_irq_tx completed\n", dev->name);
3060
3061 return IRQ_RETVAL(i);
3062}
3063
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003064#ifdef CONFIG_FORCEDETH_NAPI
3065static int nv_napi_poll(struct net_device *dev, int *budget)
3066{
3067 int pkts, limit = min(*budget, dev->quota);
3068 struct fe_priv *np = netdev_priv(dev);
3069 u8 __iomem *base = get_hwbase(dev);
Francois Romieud15e9c42006-12-17 23:03:15 +01003070 unsigned long flags;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003071
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003072 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
3073 pkts = nv_rx_process(dev, limit);
3074 else
3075 pkts = nv_rx_process_optimized(dev, limit);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003076
3077 if (nv_alloc_rx(dev)) {
Francois Romieud15e9c42006-12-17 23:03:15 +01003078 spin_lock_irqsave(&np->lock, flags);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003079 if (!np->in_shutdown)
3080 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Francois Romieud15e9c42006-12-17 23:03:15 +01003081 spin_unlock_irqrestore(&np->lock, flags);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003082 }
3083
3084 if (pkts < limit) {
3085 /* all done, no more packets present */
3086 netif_rx_complete(dev);
3087
3088 /* re-enable receive interrupts */
Francois Romieud15e9c42006-12-17 23:03:15 +01003089 spin_lock_irqsave(&np->lock, flags);
3090
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003091 np->irqmask |= NVREG_IRQ_RX_ALL;
3092 if (np->msi_flags & NV_MSI_X_ENABLED)
3093 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
3094 else
3095 writel(np->irqmask, base + NvRegIrqMask);
Francois Romieud15e9c42006-12-17 23:03:15 +01003096
3097 spin_unlock_irqrestore(&np->lock, flags);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003098 return 0;
3099 } else {
3100 /* used up our quantum, so reschedule */
3101 dev->quota -= pkts;
3102 *budget -= pkts;
3103 return 1;
3104 }
3105}
3106#endif
3107
3108#ifdef CONFIG_FORCEDETH_NAPI
David Howells7d12e782006-10-05 14:55:46 +01003109static irqreturn_t nv_nic_irq_rx(int foo, void *data)
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003110{
3111 struct net_device *dev = (struct net_device *) data;
3112 u8 __iomem *base = get_hwbase(dev);
3113 u32 events;
3114
3115 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
3116 writel(NVREG_IRQ_RX_ALL, base + NvRegMSIXIrqStatus);
3117
3118 if (events) {
3119 netif_rx_schedule(dev);
3120 /* disable receive interrupts on the nic */
3121 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
3122 pci_push(base);
3123 }
3124 return IRQ_HANDLED;
3125}
3126#else
David Howells7d12e782006-10-05 14:55:46 +01003127static irqreturn_t nv_nic_irq_rx(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003128{
3129 struct net_device *dev = (struct net_device *) data;
3130 struct fe_priv *np = netdev_priv(dev);
3131 u8 __iomem *base = get_hwbase(dev);
3132 u32 events;
3133 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003134 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003135
3136 dprintk(KERN_DEBUG "%s: nv_nic_irq_rx\n", dev->name);
3137
3138 for (i=0; ; i++) {
3139 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
3140 writel(NVREG_IRQ_RX_ALL, base + NvRegMSIXIrqStatus);
3141 pci_push(base);
3142 dprintk(KERN_DEBUG "%s: rx irq: %08x\n", dev->name, events);
3143 if (!(events & np->irqmask))
3144 break;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003145
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003146 nv_rx_process_optimized(dev, dev->weight);
3147 if (nv_alloc_rx_optimized(dev)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003148 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003149 if (!np->in_shutdown)
3150 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003151 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003152 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003153
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003154 if (i > max_interrupt_work) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003155 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003156 /* disable interrupts on the nic */
3157 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
3158 pci_push(base);
3159
3160 if (!np->in_shutdown) {
3161 np->nic_poll_irq |= NVREG_IRQ_RX_ALL;
3162 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3163 }
3164 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_rx.\n", dev->name, i);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003165 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003166 break;
3167 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003168 }
3169 dprintk(KERN_DEBUG "%s: nv_nic_irq_rx completed\n", dev->name);
3170
3171 return IRQ_RETVAL(i);
3172}
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003173#endif
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003174
David Howells7d12e782006-10-05 14:55:46 +01003175static irqreturn_t nv_nic_irq_other(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003176{
3177 struct net_device *dev = (struct net_device *) data;
3178 struct fe_priv *np = netdev_priv(dev);
3179 u8 __iomem *base = get_hwbase(dev);
3180 u32 events;
3181 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003182 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003183
3184 dprintk(KERN_DEBUG "%s: nv_nic_irq_other\n", dev->name);
3185
3186 for (i=0; ; i++) {
3187 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_OTHER;
3188 writel(NVREG_IRQ_OTHER, base + NvRegMSIXIrqStatus);
3189 pci_push(base);
3190 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
3191 if (!(events & np->irqmask))
3192 break;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003193
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003194 if (events & NVREG_IRQ_LINK) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003195 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003196 nv_link_irq(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003197 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003198 }
3199 if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003200 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003201 nv_linkchange(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003202 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003203 np->link_timeout = jiffies + LINK_TIMEOUT;
3204 }
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003205 if (events & NVREG_IRQ_RECOVER_ERROR) {
3206 spin_lock_irq(&np->lock);
3207 /* disable interrupts on the nic */
3208 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
3209 pci_push(base);
3210
3211 if (!np->in_shutdown) {
3212 np->nic_poll_irq |= NVREG_IRQ_OTHER;
3213 np->recover_error = 1;
3214 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3215 }
3216 spin_unlock_irq(&np->lock);
3217 break;
3218 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003219 if (events & (NVREG_IRQ_UNKNOWN)) {
3220 printk(KERN_DEBUG "%s: received irq with unknown events 0x%x. Please report\n",
3221 dev->name, events);
3222 }
3223 if (i > max_interrupt_work) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003224 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003225 /* disable interrupts on the nic */
3226 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
3227 pci_push(base);
3228
3229 if (!np->in_shutdown) {
3230 np->nic_poll_irq |= NVREG_IRQ_OTHER;
3231 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3232 }
3233 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_other.\n", dev->name, i);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003234 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003235 break;
3236 }
3237
3238 }
3239 dprintk(KERN_DEBUG "%s: nv_nic_irq_other completed\n", dev->name);
3240
3241 return IRQ_RETVAL(i);
3242}
3243
David Howells7d12e782006-10-05 14:55:46 +01003244static irqreturn_t nv_nic_irq_test(int foo, void *data)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003245{
3246 struct net_device *dev = (struct net_device *) data;
3247 struct fe_priv *np = netdev_priv(dev);
3248 u8 __iomem *base = get_hwbase(dev);
3249 u32 events;
3250
3251 dprintk(KERN_DEBUG "%s: nv_nic_irq_test\n", dev->name);
3252
3253 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3254 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
3255 writel(NVREG_IRQ_TIMER, base + NvRegIrqStatus);
3256 } else {
3257 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
3258 writel(NVREG_IRQ_TIMER, base + NvRegMSIXIrqStatus);
3259 }
3260 pci_push(base);
3261 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
3262 if (!(events & NVREG_IRQ_TIMER))
3263 return IRQ_RETVAL(0);
3264
3265 spin_lock(&np->lock);
3266 np->intr_test = 1;
3267 spin_unlock(&np->lock);
3268
3269 dprintk(KERN_DEBUG "%s: nv_nic_irq_test completed\n", dev->name);
3270
3271 return IRQ_RETVAL(1);
3272}
3273
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003274static void set_msix_vector_map(struct net_device *dev, u32 vector, u32 irqmask)
3275{
3276 u8 __iomem *base = get_hwbase(dev);
3277 int i;
3278 u32 msixmap = 0;
3279
3280 /* Each interrupt bit can be mapped to a MSIX vector (4 bits).
3281 * MSIXMap0 represents the first 8 interrupts and MSIXMap1 represents
3282 * the remaining 8 interrupts.
3283 */
3284 for (i = 0; i < 8; i++) {
3285 if ((irqmask >> i) & 0x1) {
3286 msixmap |= vector << (i << 2);
3287 }
3288 }
3289 writel(readl(base + NvRegMSIXMap0) | msixmap, base + NvRegMSIXMap0);
3290
3291 msixmap = 0;
3292 for (i = 0; i < 8; i++) {
3293 if ((irqmask >> (i + 8)) & 0x1) {
3294 msixmap |= vector << (i << 2);
3295 }
3296 }
3297 writel(readl(base + NvRegMSIXMap1) | msixmap, base + NvRegMSIXMap1);
3298}
3299
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003300static int nv_request_irq(struct net_device *dev, int intr_test)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003301{
3302 struct fe_priv *np = get_nvpriv(dev);
3303 u8 __iomem *base = get_hwbase(dev);
3304 int ret = 1;
3305 int i;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003306 irqreturn_t (*handler)(int foo, void *data);
3307
3308 if (intr_test) {
3309 handler = nv_nic_irq_test;
3310 } else {
3311 if (np->desc_ver == DESC_VER_3)
3312 handler = nv_nic_irq_optimized;
3313 else
3314 handler = nv_nic_irq;
3315 }
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003316
3317 if (np->msi_flags & NV_MSI_X_CAPABLE) {
3318 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++) {
3319 np->msi_x_entry[i].entry = i;
3320 }
3321 if ((ret = pci_enable_msix(np->pci_dev, np->msi_x_entry, (np->msi_flags & NV_MSI_X_VECTORS_MASK))) == 0) {
3322 np->msi_flags |= NV_MSI_X_ENABLED;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003323 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT && !intr_test) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003324 /* Request irq for rx handling */
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07003325 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector, &nv_nic_irq_rx, IRQF_SHARED, dev->name, dev) != 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003326 printk(KERN_INFO "forcedeth: request_irq failed for rx %d\n", ret);
3327 pci_disable_msix(np->pci_dev);
3328 np->msi_flags &= ~NV_MSI_X_ENABLED;
3329 goto out_err;
3330 }
3331 /* Request irq for tx handling */
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07003332 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector, &nv_nic_irq_tx, IRQF_SHARED, dev->name, dev) != 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003333 printk(KERN_INFO "forcedeth: request_irq failed for tx %d\n", ret);
3334 pci_disable_msix(np->pci_dev);
3335 np->msi_flags &= ~NV_MSI_X_ENABLED;
3336 goto out_free_rx;
3337 }
3338 /* Request irq for link and timer handling */
Thomas Gleixner1fb9df52006-07-01 19:29:39 -07003339 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector, &nv_nic_irq_other, IRQF_SHARED, dev->name, dev) != 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003340 printk(KERN_INFO "forcedeth: request_irq failed for link %d\n", ret);
3341 pci_disable_msix(np->pci_dev);
3342 np->msi_flags &= ~NV_MSI_X_ENABLED;
3343 goto out_free_tx;
3344 }
3345 /* map interrupts to their respective vector */
3346 writel(0, base + NvRegMSIXMap0);
3347 writel(0, base + NvRegMSIXMap1);
3348 set_msix_vector_map(dev, NV_MSI_X_VECTOR_RX, NVREG_IRQ_RX_ALL);
3349 set_msix_vector_map(dev, NV_MSI_X_VECTOR_TX, NVREG_IRQ_TX_ALL);
3350 set_msix_vector_map(dev, NV_MSI_X_VECTOR_OTHER, NVREG_IRQ_OTHER);
3351 } else {
3352 /* Request irq for all interrupts */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003353 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector, handler, IRQF_SHARED, dev->name, dev) != 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003354 printk(KERN_INFO "forcedeth: request_irq failed %d\n", ret);
3355 pci_disable_msix(np->pci_dev);
3356 np->msi_flags &= ~NV_MSI_X_ENABLED;
3357 goto out_err;
3358 }
3359
3360 /* map interrupts to vector 0 */
3361 writel(0, base + NvRegMSIXMap0);
3362 writel(0, base + NvRegMSIXMap1);
3363 }
3364 }
3365 }
3366 if (ret != 0 && np->msi_flags & NV_MSI_CAPABLE) {
3367 if ((ret = pci_enable_msi(np->pci_dev)) == 0) {
3368 np->msi_flags |= NV_MSI_ENABLED;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003369 if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003370 printk(KERN_INFO "forcedeth: request_irq failed %d\n", ret);
3371 pci_disable_msi(np->pci_dev);
3372 np->msi_flags &= ~NV_MSI_ENABLED;
3373 goto out_err;
3374 }
3375
3376 /* map interrupts to vector 0 */
3377 writel(0, base + NvRegMSIMap0);
3378 writel(0, base + NvRegMSIMap1);
3379 /* enable msi vector 0 */
3380 writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask);
3381 }
3382 }
3383 if (ret != 0) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003384 if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003385 goto out_err;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003386
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003387 }
3388
3389 return 0;
3390out_free_tx:
3391 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector, dev);
3392out_free_rx:
3393 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector, dev);
3394out_err:
3395 return 1;
3396}
3397
3398static void nv_free_irq(struct net_device *dev)
3399{
3400 struct fe_priv *np = get_nvpriv(dev);
3401 int i;
3402
3403 if (np->msi_flags & NV_MSI_X_ENABLED) {
3404 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++) {
3405 free_irq(np->msi_x_entry[i].vector, dev);
3406 }
3407 pci_disable_msix(np->pci_dev);
3408 np->msi_flags &= ~NV_MSI_X_ENABLED;
3409 } else {
3410 free_irq(np->pci_dev->irq, dev);
3411 if (np->msi_flags & NV_MSI_ENABLED) {
3412 pci_disable_msi(np->pci_dev);
3413 np->msi_flags &= ~NV_MSI_ENABLED;
3414 }
3415 }
3416}
3417
Linus Torvalds1da177e2005-04-16 15:20:36 -07003418static void nv_do_nic_poll(unsigned long data)
3419{
3420 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003421 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003422 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003423 u32 mask = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424
Linus Torvalds1da177e2005-04-16 15:20:36 -07003425 /*
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003426 * First disable irq(s) and then
Linus Torvalds1da177e2005-04-16 15:20:36 -07003427 * reenable interrupts on the nic, we have to do this before calling
3428 * nv_nic_irq because that may decide to do otherwise
3429 */
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003430
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003431 if (!using_multi_irqs(dev)) {
3432 if (np->msi_flags & NV_MSI_X_ENABLED)
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003433 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003434 else
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003435 disable_irq_lockdep(dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003436 mask = np->irqmask;
3437 } else {
3438 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003439 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003440 mask |= NVREG_IRQ_RX_ALL;
3441 }
3442 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003443 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003444 mask |= NVREG_IRQ_TX_ALL;
3445 }
3446 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003447 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003448 mask |= NVREG_IRQ_OTHER;
3449 }
3450 }
3451 np->nic_poll_irq = 0;
3452
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003453 if (np->recover_error) {
3454 np->recover_error = 0;
3455 printk(KERN_INFO "forcedeth: MAC in recoverable error state\n");
3456 if (netif_running(dev)) {
3457 netif_tx_lock_bh(dev);
3458 spin_lock(&np->lock);
3459 /* stop engines */
3460 nv_stop_rx(dev);
3461 nv_stop_tx(dev);
3462 nv_txrx_reset(dev);
3463 /* drain rx queue */
3464 nv_drain_rx(dev);
3465 nv_drain_tx(dev);
3466 /* reinit driver view of the rx queue */
3467 set_bufsize(dev);
3468 if (nv_init_ring(dev)) {
3469 if (!np->in_shutdown)
3470 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3471 }
3472 /* reinit nic view of the rx queue */
3473 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
3474 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
3475 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
3476 base + NvRegRingSizes);
3477 pci_push(base);
3478 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
3479 pci_push(base);
3480
3481 /* restart rx engine */
3482 nv_start_rx(dev);
3483 nv_start_tx(dev);
3484 spin_unlock(&np->lock);
3485 netif_tx_unlock_bh(dev);
3486 }
3487 }
3488
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003489 /* FIXME: Do we need synchronize_irq(dev->irq) here? */
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003490
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003491 writel(mask, base + NvRegIrqMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003492 pci_push(base);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003493
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003494 if (!using_multi_irqs(dev)) {
David Howells7d12e782006-10-05 14:55:46 +01003495 nv_nic_irq(0, dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003496 if (np->msi_flags & NV_MSI_X_ENABLED)
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003497 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003498 else
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003499 enable_irq_lockdep(dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003500 } else {
3501 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
David Howells7d12e782006-10-05 14:55:46 +01003502 nv_nic_irq_rx(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003503 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003504 }
3505 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
David Howells7d12e782006-10-05 14:55:46 +01003506 nv_nic_irq_tx(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003507 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003508 }
3509 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
David Howells7d12e782006-10-05 14:55:46 +01003510 nv_nic_irq_other(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003511 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003512 }
3513 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003514}
3515
Michal Schmidt2918c352005-05-12 19:42:06 -04003516#ifdef CONFIG_NET_POLL_CONTROLLER
3517static void nv_poll_controller(struct net_device *dev)
3518{
3519 nv_do_nic_poll((unsigned long) dev);
3520}
3521#endif
3522
Ayaz Abdulla52da3572006-06-10 22:48:04 -04003523static void nv_do_stats_poll(unsigned long data)
3524{
3525 struct net_device *dev = (struct net_device *) data;
3526 struct fe_priv *np = netdev_priv(dev);
3527 u8 __iomem *base = get_hwbase(dev);
3528
3529 np->estats.tx_bytes += readl(base + NvRegTxCnt);
3530 np->estats.tx_zero_rexmt += readl(base + NvRegTxZeroReXmt);
3531 np->estats.tx_one_rexmt += readl(base + NvRegTxOneReXmt);
3532 np->estats.tx_many_rexmt += readl(base + NvRegTxManyReXmt);
3533 np->estats.tx_late_collision += readl(base + NvRegTxLateCol);
3534 np->estats.tx_fifo_errors += readl(base + NvRegTxUnderflow);
3535 np->estats.tx_carrier_errors += readl(base + NvRegTxLossCarrier);
3536 np->estats.tx_excess_deferral += readl(base + NvRegTxExcessDef);
3537 np->estats.tx_retry_error += readl(base + NvRegTxRetryErr);
3538 np->estats.tx_deferral += readl(base + NvRegTxDef);
3539 np->estats.tx_packets += readl(base + NvRegTxFrame);
3540 np->estats.tx_pause += readl(base + NvRegTxPause);
3541 np->estats.rx_frame_error += readl(base + NvRegRxFrameErr);
3542 np->estats.rx_extra_byte += readl(base + NvRegRxExtraByte);
3543 np->estats.rx_late_collision += readl(base + NvRegRxLateCol);
3544 np->estats.rx_runt += readl(base + NvRegRxRunt);
3545 np->estats.rx_frame_too_long += readl(base + NvRegRxFrameTooLong);
3546 np->estats.rx_over_errors += readl(base + NvRegRxOverflow);
3547 np->estats.rx_crc_errors += readl(base + NvRegRxFCSErr);
3548 np->estats.rx_frame_align_error += readl(base + NvRegRxFrameAlignErr);
3549 np->estats.rx_length_error += readl(base + NvRegRxLenErr);
3550 np->estats.rx_unicast += readl(base + NvRegRxUnicast);
3551 np->estats.rx_multicast += readl(base + NvRegRxMulticast);
3552 np->estats.rx_broadcast += readl(base + NvRegRxBroadcast);
3553 np->estats.rx_bytes += readl(base + NvRegRxCnt);
3554 np->estats.rx_pause += readl(base + NvRegRxPause);
3555 np->estats.rx_drop_frame += readl(base + NvRegRxDropFrame);
3556 np->estats.rx_packets =
3557 np->estats.rx_unicast +
3558 np->estats.rx_multicast +
3559 np->estats.rx_broadcast;
3560 np->estats.rx_errors_total =
3561 np->estats.rx_crc_errors +
3562 np->estats.rx_over_errors +
3563 np->estats.rx_frame_error +
3564 (np->estats.rx_frame_align_error - np->estats.rx_extra_byte) +
3565 np->estats.rx_late_collision +
3566 np->estats.rx_runt +
3567 np->estats.rx_frame_too_long;
3568
3569 if (!np->in_shutdown)
3570 mod_timer(&np->stats_poll, jiffies + STATS_INTERVAL);
3571}
3572
Linus Torvalds1da177e2005-04-16 15:20:36 -07003573static void nv_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
3574{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003575 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003576 strcpy(info->driver, "forcedeth");
3577 strcpy(info->version, FORCEDETH_VERSION);
3578 strcpy(info->bus_info, pci_name(np->pci_dev));
3579}
3580
3581static void nv_get_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
3582{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003583 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003584 wolinfo->supported = WAKE_MAGIC;
3585
3586 spin_lock_irq(&np->lock);
3587 if (np->wolenabled)
3588 wolinfo->wolopts = WAKE_MAGIC;
3589 spin_unlock_irq(&np->lock);
3590}
3591
3592static int nv_set_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
3593{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003594 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003595 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04003596 u32 flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003597
Linus Torvalds1da177e2005-04-16 15:20:36 -07003598 if (wolinfo->wolopts == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599 np->wolenabled = 0;
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04003600 } else if (wolinfo->wolopts & WAKE_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003601 np->wolenabled = 1;
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04003602 flags = NVREG_WAKEUPFLAGS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003603 }
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04003604 if (netif_running(dev)) {
3605 spin_lock_irq(&np->lock);
3606 writel(flags, base + NvRegWakeUpFlags);
3607 spin_unlock_irq(&np->lock);
3608 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003609 return 0;
3610}
3611
3612static int nv_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
3613{
3614 struct fe_priv *np = netdev_priv(dev);
3615 int adv;
3616
3617 spin_lock_irq(&np->lock);
3618 ecmd->port = PORT_MII;
3619 if (!netif_running(dev)) {
3620 /* We do not track link speed / duplex setting if the
3621 * interface is disabled. Force a link check */
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003622 if (nv_update_linkspeed(dev)) {
3623 if (!netif_carrier_ok(dev))
3624 netif_carrier_on(dev);
3625 } else {
3626 if (netif_carrier_ok(dev))
3627 netif_carrier_off(dev);
3628 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003629 }
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003630
3631 if (netif_carrier_ok(dev)) {
3632 switch(np->linkspeed & (NVREG_LINKSPEED_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003633 case NVREG_LINKSPEED_10:
3634 ecmd->speed = SPEED_10;
3635 break;
3636 case NVREG_LINKSPEED_100:
3637 ecmd->speed = SPEED_100;
3638 break;
3639 case NVREG_LINKSPEED_1000:
3640 ecmd->speed = SPEED_1000;
3641 break;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003642 }
3643 ecmd->duplex = DUPLEX_HALF;
3644 if (np->duplex)
3645 ecmd->duplex = DUPLEX_FULL;
3646 } else {
3647 ecmd->speed = -1;
3648 ecmd->duplex = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003649 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003650
3651 ecmd->autoneg = np->autoneg;
3652
3653 ecmd->advertising = ADVERTISED_MII;
3654 if (np->autoneg) {
3655 ecmd->advertising |= ADVERTISED_Autoneg;
3656 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003657 if (adv & ADVERTISE_10HALF)
3658 ecmd->advertising |= ADVERTISED_10baseT_Half;
3659 if (adv & ADVERTISE_10FULL)
3660 ecmd->advertising |= ADVERTISED_10baseT_Full;
3661 if (adv & ADVERTISE_100HALF)
3662 ecmd->advertising |= ADVERTISED_100baseT_Half;
3663 if (adv & ADVERTISE_100FULL)
3664 ecmd->advertising |= ADVERTISED_100baseT_Full;
3665 if (np->gigabit == PHY_GIGABIT) {
3666 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
3667 if (adv & ADVERTISE_1000FULL)
3668 ecmd->advertising |= ADVERTISED_1000baseT_Full;
3669 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003670 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003671 ecmd->supported = (SUPPORTED_Autoneg |
3672 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
3673 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
3674 SUPPORTED_MII);
3675 if (np->gigabit == PHY_GIGABIT)
3676 ecmd->supported |= SUPPORTED_1000baseT_Full;
3677
3678 ecmd->phy_address = np->phyaddr;
3679 ecmd->transceiver = XCVR_EXTERNAL;
3680
3681 /* ignore maxtxpkt, maxrxpkt for now */
3682 spin_unlock_irq(&np->lock);
3683 return 0;
3684}
3685
3686static int nv_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
3687{
3688 struct fe_priv *np = netdev_priv(dev);
3689
3690 if (ecmd->port != PORT_MII)
3691 return -EINVAL;
3692 if (ecmd->transceiver != XCVR_EXTERNAL)
3693 return -EINVAL;
3694 if (ecmd->phy_address != np->phyaddr) {
3695 /* TODO: support switching between multiple phys. Should be
3696 * trivial, but not enabled due to lack of test hardware. */
3697 return -EINVAL;
3698 }
3699 if (ecmd->autoneg == AUTONEG_ENABLE) {
3700 u32 mask;
3701
3702 mask = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
3703 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full;
3704 if (np->gigabit == PHY_GIGABIT)
3705 mask |= ADVERTISED_1000baseT_Full;
3706
3707 if ((ecmd->advertising & mask) == 0)
3708 return -EINVAL;
3709
3710 } else if (ecmd->autoneg == AUTONEG_DISABLE) {
3711 /* Note: autonegotiation disable, speed 1000 intentionally
3712 * forbidden - noone should need that. */
3713
3714 if (ecmd->speed != SPEED_10 && ecmd->speed != SPEED_100)
3715 return -EINVAL;
3716 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
3717 return -EINVAL;
3718 } else {
3719 return -EINVAL;
3720 }
3721
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003722 netif_carrier_off(dev);
3723 if (netif_running(dev)) {
3724 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003725 netif_tx_lock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003726 spin_lock(&np->lock);
3727 /* stop engines */
3728 nv_stop_rx(dev);
3729 nv_stop_tx(dev);
3730 spin_unlock(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003731 netif_tx_unlock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003732 }
3733
Linus Torvalds1da177e2005-04-16 15:20:36 -07003734 if (ecmd->autoneg == AUTONEG_ENABLE) {
3735 int adv, bmcr;
3736
3737 np->autoneg = 1;
3738
3739 /* advertise only what has been requested */
3740 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003741 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003742 if (ecmd->advertising & ADVERTISED_10baseT_Half)
3743 adv |= ADVERTISE_10HALF;
3744 if (ecmd->advertising & ADVERTISED_10baseT_Full)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003745 adv |= ADVERTISE_10FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003746 if (ecmd->advertising & ADVERTISED_100baseT_Half)
3747 adv |= ADVERTISE_100HALF;
3748 if (ecmd->advertising & ADVERTISED_100baseT_Full)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003749 adv |= ADVERTISE_100FULL;
3750 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisments but disable tx pause */
3751 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
3752 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
3753 adv |= ADVERTISE_PAUSE_ASYM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003754 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
3755
3756 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003757 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003758 adv &= ~ADVERTISE_1000FULL;
3759 if (ecmd->advertising & ADVERTISED_1000baseT_Full)
3760 adv |= ADVERTISE_1000FULL;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003761 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003762 }
3763
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003764 if (netif_running(dev))
3765 printk(KERN_INFO "%s: link down.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003766 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04003767 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
3768 bmcr |= BMCR_ANENABLE;
3769 /* reset the phy in order for settings to stick,
3770 * and cause autoneg to start */
3771 if (phy_reset(dev, bmcr)) {
3772 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
3773 return -EINVAL;
3774 }
3775 } else {
3776 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
3777 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
3778 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003779 } else {
3780 int adv, bmcr;
3781
3782 np->autoneg = 0;
3783
3784 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003785 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003786 if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_HALF)
3787 adv |= ADVERTISE_10HALF;
3788 if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_FULL)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003789 adv |= ADVERTISE_10FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003790 if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_HALF)
3791 adv |= ADVERTISE_100HALF;
3792 if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_FULL)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003793 adv |= ADVERTISE_100FULL;
3794 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
3795 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) {/* for rx we set both advertisments but disable tx pause */
3796 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
3797 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3798 }
3799 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) {
3800 adv |= ADVERTISE_PAUSE_ASYM;
3801 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3802 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003803 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
3804 np->fixed_mode = adv;
3805
3806 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003807 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003808 adv &= ~ADVERTISE_1000FULL;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003809 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003810 }
3811
3812 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003813 bmcr &= ~(BMCR_ANENABLE|BMCR_SPEED100|BMCR_SPEED1000|BMCR_FULLDPLX);
3814 if (np->fixed_mode & (ADVERTISE_10FULL|ADVERTISE_100FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003815 bmcr |= BMCR_FULLDPLX;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003816 if (np->fixed_mode & (ADVERTISE_100HALF|ADVERTISE_100FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07003817 bmcr |= BMCR_SPEED100;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003818 if (np->phy_oui == PHY_OUI_MARVELL) {
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04003819 /* reset the phy in order for forced mode settings to stick */
3820 if (phy_reset(dev, bmcr)) {
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003821 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
3822 return -EINVAL;
3823 }
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04003824 } else {
3825 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
3826 if (netif_running(dev)) {
3827 /* Wait a bit and then reconfigure the nic. */
3828 udelay(10);
3829 nv_linkchange(dev);
3830 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003831 }
3832 }
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003833
3834 if (netif_running(dev)) {
3835 nv_start_rx(dev);
3836 nv_start_tx(dev);
3837 nv_enable_irq(dev);
3838 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003839
3840 return 0;
3841}
3842
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003843#define FORCEDETH_REGS_VER 1
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003844
3845static int nv_get_regs_len(struct net_device *dev)
3846{
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04003847 struct fe_priv *np = netdev_priv(dev);
3848 return np->register_size;
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003849}
3850
3851static void nv_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *buf)
3852{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003853 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003854 u8 __iomem *base = get_hwbase(dev);
3855 u32 *rbuf = buf;
3856 int i;
3857
3858 regs->version = FORCEDETH_REGS_VER;
3859 spin_lock_irq(&np->lock);
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04003860 for (i = 0;i <= np->register_size/sizeof(u32); i++)
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003861 rbuf[i] = readl(base + i*sizeof(u32));
3862 spin_unlock_irq(&np->lock);
3863}
3864
3865static int nv_nway_reset(struct net_device *dev)
3866{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003867 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003868 int ret;
3869
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003870 if (np->autoneg) {
3871 int bmcr;
3872
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003873 netif_carrier_off(dev);
3874 if (netif_running(dev)) {
3875 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003876 netif_tx_lock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003877 spin_lock(&np->lock);
3878 /* stop engines */
3879 nv_stop_rx(dev);
3880 nv_stop_tx(dev);
3881 spin_unlock(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003882 netif_tx_unlock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003883 printk(KERN_INFO "%s: link down.\n", dev->name);
3884 }
3885
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003886 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04003887 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
3888 bmcr |= BMCR_ANENABLE;
3889 /* reset the phy in order for settings to stick*/
3890 if (phy_reset(dev, bmcr)) {
3891 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
3892 return -EINVAL;
3893 }
3894 } else {
3895 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
3896 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
3897 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003898
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04003899 if (netif_running(dev)) {
3900 nv_start_rx(dev);
3901 nv_start_tx(dev);
3902 nv_enable_irq(dev);
3903 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003904 ret = 0;
3905 } else {
3906 ret = -EINVAL;
3907 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02003908
3909 return ret;
3910}
3911
Zachary Amsden0674d592006-06-04 02:51:38 -07003912static int nv_set_tso(struct net_device *dev, u32 value)
3913{
3914 struct fe_priv *np = netdev_priv(dev);
3915
3916 if ((np->driver_data & DEV_HAS_CHECKSUM))
3917 return ethtool_op_set_tso(dev, value);
3918 else
Ayaz Abdulla6a788142006-06-10 22:47:26 -04003919 return -EOPNOTSUPP;
Zachary Amsden0674d592006-06-04 02:51:38 -07003920}
Zachary Amsden0674d592006-06-04 02:51:38 -07003921
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04003922static void nv_get_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
3923{
3924 struct fe_priv *np = netdev_priv(dev);
3925
3926 ring->rx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
3927 ring->rx_mini_max_pending = 0;
3928 ring->rx_jumbo_max_pending = 0;
3929 ring->tx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
3930
3931 ring->rx_pending = np->rx_ring_size;
3932 ring->rx_mini_pending = 0;
3933 ring->rx_jumbo_pending = 0;
3934 ring->tx_pending = np->tx_ring_size;
3935}
3936
3937static int nv_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
3938{
3939 struct fe_priv *np = netdev_priv(dev);
3940 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05003941 u8 *rxtx_ring, *rx_skbuff, *tx_skbuff;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04003942 dma_addr_t ring_addr;
3943
3944 if (ring->rx_pending < RX_RING_MIN ||
3945 ring->tx_pending < TX_RING_MIN ||
3946 ring->rx_mini_pending != 0 ||
3947 ring->rx_jumbo_pending != 0 ||
3948 (np->desc_ver == DESC_VER_1 &&
3949 (ring->rx_pending > RING_MAX_DESC_VER_1 ||
3950 ring->tx_pending > RING_MAX_DESC_VER_1)) ||
3951 (np->desc_ver != DESC_VER_1 &&
3952 (ring->rx_pending > RING_MAX_DESC_VER_2_3 ||
3953 ring->tx_pending > RING_MAX_DESC_VER_2_3))) {
3954 return -EINVAL;
3955 }
3956
3957 /* allocate new rings */
3958 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
3959 rxtx_ring = pci_alloc_consistent(np->pci_dev,
3960 sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
3961 &ring_addr);
3962 } else {
3963 rxtx_ring = pci_alloc_consistent(np->pci_dev,
3964 sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
3965 &ring_addr);
3966 }
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05003967 rx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->rx_pending, GFP_KERNEL);
3968 tx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->tx_pending, GFP_KERNEL);
3969 if (!rxtx_ring || !rx_skbuff || !tx_skbuff) {
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04003970 /* fall back to old rings */
3971 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003972 if (rxtx_ring)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04003973 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
3974 rxtx_ring, ring_addr);
3975 } else {
3976 if (rxtx_ring)
3977 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
3978 rxtx_ring, ring_addr);
3979 }
3980 if (rx_skbuff)
3981 kfree(rx_skbuff);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04003982 if (tx_skbuff)
3983 kfree(tx_skbuff);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04003984 goto exit;
3985 }
3986
3987 if (netif_running(dev)) {
3988 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10003989 netif_tx_lock_bh(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04003990 spin_lock(&np->lock);
3991 /* stop engines */
3992 nv_stop_rx(dev);
3993 nv_stop_tx(dev);
3994 nv_txrx_reset(dev);
3995 /* drain queues */
3996 nv_drain_rx(dev);
3997 nv_drain_tx(dev);
3998 /* delete queues */
3999 free_rings(dev);
4000 }
4001
4002 /* set new values */
4003 np->rx_ring_size = ring->rx_pending;
4004 np->tx_ring_size = ring->tx_pending;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004005 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
4006 np->rx_ring.orig = (struct ring_desc*)rxtx_ring;
4007 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
4008 } else {
4009 np->rx_ring.ex = (struct ring_desc_ex*)rxtx_ring;
4010 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
4011 }
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004012 np->rx_skb = (struct nv_skb_map*)rx_skbuff;
4013 np->tx_skb = (struct nv_skb_map*)tx_skbuff;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004014 np->ring_addr = ring_addr;
4015
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004016 memset(np->rx_skb, 0, sizeof(struct nv_skb_map) * np->rx_ring_size);
4017 memset(np->tx_skb, 0, sizeof(struct nv_skb_map) * np->tx_ring_size);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004018
4019 if (netif_running(dev)) {
4020 /* reinit driver view of the queues */
4021 set_bufsize(dev);
4022 if (nv_init_ring(dev)) {
4023 if (!np->in_shutdown)
4024 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
4025 }
4026
4027 /* reinit nic view of the queues */
4028 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4029 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
4030 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
4031 base + NvRegRingSizes);
4032 pci_push(base);
4033 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4034 pci_push(base);
4035
4036 /* restart engines */
4037 nv_start_rx(dev);
4038 nv_start_tx(dev);
4039 spin_unlock(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004040 netif_tx_unlock_bh(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004041 nv_enable_irq(dev);
4042 }
4043 return 0;
4044exit:
4045 return -ENOMEM;
4046}
4047
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004048static void nv_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
4049{
4050 struct fe_priv *np = netdev_priv(dev);
4051
4052 pause->autoneg = (np->pause_flags & NV_PAUSEFRAME_AUTONEG) != 0;
4053 pause->rx_pause = (np->pause_flags & NV_PAUSEFRAME_RX_ENABLE) != 0;
4054 pause->tx_pause = (np->pause_flags & NV_PAUSEFRAME_TX_ENABLE) != 0;
4055}
4056
4057static int nv_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
4058{
4059 struct fe_priv *np = netdev_priv(dev);
4060 int adv, bmcr;
4061
4062 if ((!np->autoneg && np->duplex == 0) ||
4063 (np->autoneg && !pause->autoneg && np->duplex == 0)) {
4064 printk(KERN_INFO "%s: can not set pause settings when forced link is in half duplex.\n",
4065 dev->name);
4066 return -EINVAL;
4067 }
4068 if (pause->tx_pause && !(np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)) {
4069 printk(KERN_INFO "%s: hardware does not support tx pause frames.\n", dev->name);
4070 return -EINVAL;
4071 }
4072
4073 netif_carrier_off(dev);
4074 if (netif_running(dev)) {
4075 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004076 netif_tx_lock_bh(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004077 spin_lock(&np->lock);
4078 /* stop engines */
4079 nv_stop_rx(dev);
4080 nv_stop_tx(dev);
4081 spin_unlock(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004082 netif_tx_unlock_bh(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004083 }
4084
4085 np->pause_flags &= ~(NV_PAUSEFRAME_RX_REQ|NV_PAUSEFRAME_TX_REQ);
4086 if (pause->rx_pause)
4087 np->pause_flags |= NV_PAUSEFRAME_RX_REQ;
4088 if (pause->tx_pause)
4089 np->pause_flags |= NV_PAUSEFRAME_TX_REQ;
4090
4091 if (np->autoneg && pause->autoneg) {
4092 np->pause_flags |= NV_PAUSEFRAME_AUTONEG;
4093
4094 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
4095 adv &= ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
4096 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisments but disable tx pause */
4097 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4098 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
4099 adv |= ADVERTISE_PAUSE_ASYM;
4100 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4101
4102 if (netif_running(dev))
4103 printk(KERN_INFO "%s: link down.\n", dev->name);
4104 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
4105 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4106 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4107 } else {
4108 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
4109 if (pause->rx_pause)
4110 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
4111 if (pause->tx_pause)
4112 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
4113
4114 if (!netif_running(dev))
4115 nv_update_linkspeed(dev);
4116 else
4117 nv_update_pause(dev, np->pause_flags);
4118 }
4119
4120 if (netif_running(dev)) {
4121 nv_start_rx(dev);
4122 nv_start_tx(dev);
4123 nv_enable_irq(dev);
4124 }
4125 return 0;
4126}
4127
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004128static u32 nv_get_rx_csum(struct net_device *dev)
4129{
4130 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04004131 return (np->rx_csum) != 0;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004132}
4133
4134static int nv_set_rx_csum(struct net_device *dev, u32 data)
4135{
4136 struct fe_priv *np = netdev_priv(dev);
4137 u8 __iomem *base = get_hwbase(dev);
4138 int retcode = 0;
4139
4140 if (np->driver_data & DEV_HAS_CHECKSUM) {
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004141 if (data) {
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04004142 np->rx_csum = 1;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004143 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004144 } else {
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04004145 np->rx_csum = 0;
4146 /* vlan is dependent on rx checksum offload */
4147 if (!(np->vlanctl_bits & NVREG_VLANCONTROL_ENABLE))
4148 np->txrxctl_bits &= ~NVREG_TXRXCTL_RXCHECK;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004149 }
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004150 if (netif_running(dev)) {
4151 spin_lock_irq(&np->lock);
4152 writel(np->txrxctl_bits, base + NvRegTxRxControl);
4153 spin_unlock_irq(&np->lock);
4154 }
4155 } else {
4156 return -EINVAL;
4157 }
4158
4159 return retcode;
4160}
4161
4162static int nv_set_tx_csum(struct net_device *dev, u32 data)
4163{
4164 struct fe_priv *np = netdev_priv(dev);
4165
4166 if (np->driver_data & DEV_HAS_CHECKSUM)
4167 return ethtool_op_set_tx_hw_csum(dev, data);
4168 else
4169 return -EOPNOTSUPP;
4170}
4171
4172static int nv_set_sg(struct net_device *dev, u32 data)
4173{
4174 struct fe_priv *np = netdev_priv(dev);
4175
4176 if (np->driver_data & DEV_HAS_CHECKSUM)
4177 return ethtool_op_set_sg(dev, data);
4178 else
4179 return -EOPNOTSUPP;
4180}
4181
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004182static int nv_get_stats_count(struct net_device *dev)
4183{
4184 struct fe_priv *np = netdev_priv(dev);
4185
4186 if (np->driver_data & DEV_HAS_STATISTICS)
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004187 return sizeof(struct nv_ethtool_stats)/sizeof(u64);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004188 else
4189 return 0;
4190}
4191
4192static void nv_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *estats, u64 *buffer)
4193{
4194 struct fe_priv *np = netdev_priv(dev);
4195
4196 /* update stats */
4197 nv_do_stats_poll((unsigned long)dev);
4198
4199 memcpy(buffer, &np->estats, nv_get_stats_count(dev)*sizeof(u64));
4200}
4201
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004202static int nv_self_test_count(struct net_device *dev)
4203{
4204 struct fe_priv *np = netdev_priv(dev);
4205
4206 if (np->driver_data & DEV_HAS_TEST_EXTENDED)
4207 return NV_TEST_COUNT_EXTENDED;
4208 else
4209 return NV_TEST_COUNT_BASE;
4210}
4211
4212static int nv_link_test(struct net_device *dev)
4213{
4214 struct fe_priv *np = netdev_priv(dev);
4215 int mii_status;
4216
4217 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
4218 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
4219
4220 /* check phy link status */
4221 if (!(mii_status & BMSR_LSTATUS))
4222 return 0;
4223 else
4224 return 1;
4225}
4226
4227static int nv_register_test(struct net_device *dev)
4228{
4229 u8 __iomem *base = get_hwbase(dev);
4230 int i = 0;
4231 u32 orig_read, new_read;
4232
4233 do {
4234 orig_read = readl(base + nv_registers_test[i].reg);
4235
4236 /* xor with mask to toggle bits */
4237 orig_read ^= nv_registers_test[i].mask;
4238
4239 writel(orig_read, base + nv_registers_test[i].reg);
4240
4241 new_read = readl(base + nv_registers_test[i].reg);
4242
4243 if ((new_read & nv_registers_test[i].mask) != (orig_read & nv_registers_test[i].mask))
4244 return 0;
4245
4246 /* restore original value */
4247 orig_read ^= nv_registers_test[i].mask;
4248 writel(orig_read, base + nv_registers_test[i].reg);
4249
4250 } while (nv_registers_test[++i].reg != 0);
4251
4252 return 1;
4253}
4254
4255static int nv_interrupt_test(struct net_device *dev)
4256{
4257 struct fe_priv *np = netdev_priv(dev);
4258 u8 __iomem *base = get_hwbase(dev);
4259 int ret = 1;
4260 int testcnt;
4261 u32 save_msi_flags, save_poll_interval = 0;
4262
4263 if (netif_running(dev)) {
4264 /* free current irq */
4265 nv_free_irq(dev);
4266 save_poll_interval = readl(base+NvRegPollingInterval);
4267 }
4268
4269 /* flag to test interrupt handler */
4270 np->intr_test = 0;
4271
4272 /* setup test irq */
4273 save_msi_flags = np->msi_flags;
4274 np->msi_flags &= ~NV_MSI_X_VECTORS_MASK;
4275 np->msi_flags |= 0x001; /* setup 1 vector */
4276 if (nv_request_irq(dev, 1))
4277 return 0;
4278
4279 /* setup timer interrupt */
4280 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
4281 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
4282
4283 nv_enable_hw_interrupts(dev, NVREG_IRQ_TIMER);
4284
4285 /* wait for at least one interrupt */
4286 msleep(100);
4287
4288 spin_lock_irq(&np->lock);
4289
4290 /* flag should be set within ISR */
4291 testcnt = np->intr_test;
4292 if (!testcnt)
4293 ret = 2;
4294
4295 nv_disable_hw_interrupts(dev, NVREG_IRQ_TIMER);
4296 if (!(np->msi_flags & NV_MSI_X_ENABLED))
4297 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4298 else
4299 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
4300
4301 spin_unlock_irq(&np->lock);
4302
4303 nv_free_irq(dev);
4304
4305 np->msi_flags = save_msi_flags;
4306
4307 if (netif_running(dev)) {
4308 writel(save_poll_interval, base + NvRegPollingInterval);
4309 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
4310 /* restore original irq */
4311 if (nv_request_irq(dev, 0))
4312 return 0;
4313 }
4314
4315 return ret;
4316}
4317
4318static int nv_loopback_test(struct net_device *dev)
4319{
4320 struct fe_priv *np = netdev_priv(dev);
4321 u8 __iomem *base = get_hwbase(dev);
4322 struct sk_buff *tx_skb, *rx_skb;
4323 dma_addr_t test_dma_addr;
4324 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004325 u32 flags;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004326 int len, i, pkt_len;
4327 u8 *pkt_data;
4328 u32 filter_flags = 0;
4329 u32 misc1_flags = 0;
4330 int ret = 1;
4331
4332 if (netif_running(dev)) {
4333 nv_disable_irq(dev);
4334 filter_flags = readl(base + NvRegPacketFilterFlags);
4335 misc1_flags = readl(base + NvRegMisc1);
4336 } else {
4337 nv_txrx_reset(dev);
4338 }
4339
4340 /* reinit driver view of the rx queue */
4341 set_bufsize(dev);
4342 nv_init_ring(dev);
4343
4344 /* setup hardware for loopback */
4345 writel(NVREG_MISC1_FORCE, base + NvRegMisc1);
4346 writel(NVREG_PFF_ALWAYS | NVREG_PFF_LOOPBACK, base + NvRegPacketFilterFlags);
4347
4348 /* reinit nic view of the rx queue */
4349 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4350 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
4351 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
4352 base + NvRegRingSizes);
4353 pci_push(base);
4354
4355 /* restart rx engine */
4356 nv_start_rx(dev);
4357 nv_start_tx(dev);
4358
4359 /* setup packet for tx */
4360 pkt_len = ETH_DATA_LEN;
4361 tx_skb = dev_alloc_skb(pkt_len);
Jesper Juhl46798c82006-09-25 16:39:24 -07004362 if (!tx_skb) {
4363 printk(KERN_ERR "dev_alloc_skb() failed during loopback test"
4364 " of %s\n", dev->name);
4365 ret = 0;
4366 goto out;
4367 }
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004368 pkt_data = skb_put(tx_skb, pkt_len);
4369 for (i = 0; i < pkt_len; i++)
4370 pkt_data[i] = (u8)(i & 0xff);
4371 test_dma_addr = pci_map_single(np->pci_dev, tx_skb->data,
4372 tx_skb->end-tx_skb->data, PCI_DMA_FROMDEVICE);
4373
4374 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004375 np->tx_ring.orig[0].buf = cpu_to_le32(test_dma_addr);
4376 np->tx_ring.orig[0].flaglen = cpu_to_le32((pkt_len-1) | np->tx_flags | tx_flags_extra);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004377 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004378 np->tx_ring.ex[0].bufhigh = cpu_to_le64(test_dma_addr) >> 32;
4379 np->tx_ring.ex[0].buflow = cpu_to_le64(test_dma_addr) & 0x0FFFFFFFF;
4380 np->tx_ring.ex[0].flaglen = cpu_to_le32((pkt_len-1) | np->tx_flags | tx_flags_extra);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004381 }
4382 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4383 pci_push(get_hwbase(dev));
4384
4385 msleep(500);
4386
4387 /* check for rx of the packet */
4388 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004389 flags = le32_to_cpu(np->rx_ring.orig[0].flaglen);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004390 len = nv_descr_getlength(&np->rx_ring.orig[0], np->desc_ver);
4391
4392 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004393 flags = le32_to_cpu(np->rx_ring.ex[0].flaglen);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004394 len = nv_descr_getlength_ex(&np->rx_ring.ex[0], np->desc_ver);
4395 }
4396
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004397 if (flags & NV_RX_AVAIL) {
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004398 ret = 0;
4399 } else if (np->desc_ver == DESC_VER_1) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004400 if (flags & NV_RX_ERROR)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004401 ret = 0;
4402 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004403 if (flags & NV_RX2_ERROR) {
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004404 ret = 0;
4405 }
4406 }
4407
4408 if (ret) {
4409 if (len != pkt_len) {
4410 ret = 0;
4411 dprintk(KERN_DEBUG "%s: loopback len mismatch %d vs %d\n",
4412 dev->name, len, pkt_len);
4413 } else {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004414 rx_skb = np->rx_skb[0].skb;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004415 for (i = 0; i < pkt_len; i++) {
4416 if (rx_skb->data[i] != (u8)(i & 0xff)) {
4417 ret = 0;
4418 dprintk(KERN_DEBUG "%s: loopback pattern check failed on byte %d\n",
4419 dev->name, i);
4420 break;
4421 }
4422 }
4423 }
4424 } else {
4425 dprintk(KERN_DEBUG "%s: loopback - did not receive test packet\n", dev->name);
4426 }
4427
4428 pci_unmap_page(np->pci_dev, test_dma_addr,
4429 tx_skb->end-tx_skb->data,
4430 PCI_DMA_TODEVICE);
4431 dev_kfree_skb_any(tx_skb);
Jesper Juhl46798c82006-09-25 16:39:24 -07004432 out:
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004433 /* stop engines */
4434 nv_stop_rx(dev);
4435 nv_stop_tx(dev);
4436 nv_txrx_reset(dev);
4437 /* drain rx queue */
4438 nv_drain_rx(dev);
4439 nv_drain_tx(dev);
4440
4441 if (netif_running(dev)) {
4442 writel(misc1_flags, base + NvRegMisc1);
4443 writel(filter_flags, base + NvRegPacketFilterFlags);
4444 nv_enable_irq(dev);
4445 }
4446
4447 return ret;
4448}
4449
4450static void nv_self_test(struct net_device *dev, struct ethtool_test *test, u64 *buffer)
4451{
4452 struct fe_priv *np = netdev_priv(dev);
4453 u8 __iomem *base = get_hwbase(dev);
4454 int result;
4455 memset(buffer, 0, nv_self_test_count(dev)*sizeof(u64));
4456
4457 if (!nv_link_test(dev)) {
4458 test->flags |= ETH_TEST_FL_FAILED;
4459 buffer[0] = 1;
4460 }
4461
4462 if (test->flags & ETH_TEST_FL_OFFLINE) {
4463 if (netif_running(dev)) {
4464 netif_stop_queue(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07004465 netif_poll_disable(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004466 netif_tx_lock_bh(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004467 spin_lock_irq(&np->lock);
4468 nv_disable_hw_interrupts(dev, np->irqmask);
4469 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
4470 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4471 } else {
4472 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
4473 }
4474 /* stop engines */
4475 nv_stop_rx(dev);
4476 nv_stop_tx(dev);
4477 nv_txrx_reset(dev);
4478 /* drain rx queue */
4479 nv_drain_rx(dev);
4480 nv_drain_tx(dev);
4481 spin_unlock_irq(&np->lock);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004482 netif_tx_unlock_bh(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004483 }
4484
4485 if (!nv_register_test(dev)) {
4486 test->flags |= ETH_TEST_FL_FAILED;
4487 buffer[1] = 1;
4488 }
4489
4490 result = nv_interrupt_test(dev);
4491 if (result != 1) {
4492 test->flags |= ETH_TEST_FL_FAILED;
4493 buffer[2] = 1;
4494 }
4495 if (result == 0) {
4496 /* bail out */
4497 return;
4498 }
4499
4500 if (!nv_loopback_test(dev)) {
4501 test->flags |= ETH_TEST_FL_FAILED;
4502 buffer[3] = 1;
4503 }
4504
4505 if (netif_running(dev)) {
4506 /* reinit driver view of the rx queue */
4507 set_bufsize(dev);
4508 if (nv_init_ring(dev)) {
4509 if (!np->in_shutdown)
4510 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
4511 }
4512 /* reinit nic view of the rx queue */
4513 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4514 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
4515 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
4516 base + NvRegRingSizes);
4517 pci_push(base);
4518 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4519 pci_push(base);
4520 /* restart rx engine */
4521 nv_start_rx(dev);
4522 nv_start_tx(dev);
4523 netif_start_queue(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07004524 netif_poll_enable(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004525 nv_enable_hw_interrupts(dev, np->irqmask);
4526 }
4527 }
4528}
4529
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004530static void nv_get_strings(struct net_device *dev, u32 stringset, u8 *buffer)
4531{
4532 switch (stringset) {
4533 case ETH_SS_STATS:
4534 memcpy(buffer, &nv_estats_str, nv_get_stats_count(dev)*sizeof(struct nv_ethtool_str));
4535 break;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004536 case ETH_SS_TEST:
4537 memcpy(buffer, &nv_etests_str, nv_self_test_count(dev)*sizeof(struct nv_ethtool_str));
4538 break;
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004539 }
4540}
4541
Jeff Garzik7282d492006-09-13 14:30:00 -04004542static const struct ethtool_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004543 .get_drvinfo = nv_get_drvinfo,
4544 .get_link = ethtool_op_get_link,
4545 .get_wol = nv_get_wol,
4546 .set_wol = nv_set_wol,
4547 .get_settings = nv_get_settings,
4548 .set_settings = nv_set_settings,
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004549 .get_regs_len = nv_get_regs_len,
4550 .get_regs = nv_get_regs,
4551 .nway_reset = nv_nway_reset,
John W. Linvillec704b852005-09-12 10:48:56 -04004552 .get_perm_addr = ethtool_op_get_perm_addr,
Zachary Amsden0674d592006-06-04 02:51:38 -07004553 .get_tso = ethtool_op_get_tso,
Ayaz Abdulla6a788142006-06-10 22:47:26 -04004554 .set_tso = nv_set_tso,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004555 .get_ringparam = nv_get_ringparam,
4556 .set_ringparam = nv_set_ringparam,
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004557 .get_pauseparam = nv_get_pauseparam,
4558 .set_pauseparam = nv_set_pauseparam,
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004559 .get_rx_csum = nv_get_rx_csum,
4560 .set_rx_csum = nv_set_rx_csum,
4561 .get_tx_csum = ethtool_op_get_tx_csum,
4562 .set_tx_csum = nv_set_tx_csum,
4563 .get_sg = ethtool_op_get_sg,
4564 .set_sg = nv_set_sg,
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004565 .get_strings = nv_get_strings,
4566 .get_stats_count = nv_get_stats_count,
4567 .get_ethtool_stats = nv_get_ethtool_stats,
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004568 .self_test_count = nv_self_test_count,
4569 .self_test = nv_self_test,
Linus Torvalds1da177e2005-04-16 15:20:36 -07004570};
4571
Ayaz Abdullaee407b02006-02-04 13:13:17 -05004572static void nv_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
4573{
4574 struct fe_priv *np = get_nvpriv(dev);
4575
4576 spin_lock_irq(&np->lock);
4577
4578 /* save vlan group */
4579 np->vlangrp = grp;
4580
4581 if (grp) {
4582 /* enable vlan on MAC */
4583 np->txrxctl_bits |= NVREG_TXRXCTL_VLANSTRIP | NVREG_TXRXCTL_VLANINS;
4584 } else {
4585 /* disable vlan on MAC */
4586 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANSTRIP;
4587 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANINS;
4588 }
4589
4590 writel(np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4591
4592 spin_unlock_irq(&np->lock);
4593};
4594
4595static void nv_vlan_rx_kill_vid(struct net_device *dev, unsigned short vid)
4596{
4597 /* nothing to do */
4598};
4599
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004600/* The mgmt unit and driver use a semaphore to access the phy during init */
4601static int nv_mgmt_acquire_sema(struct net_device *dev)
4602{
4603 u8 __iomem *base = get_hwbase(dev);
4604 int i;
4605 u32 tx_ctrl, mgmt_sema;
4606
4607 for (i = 0; i < 10; i++) {
4608 mgmt_sema = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_SEMA_MASK;
4609 if (mgmt_sema == NVREG_XMITCTL_MGMT_SEMA_FREE)
4610 break;
4611 msleep(500);
4612 }
4613
4614 if (mgmt_sema != NVREG_XMITCTL_MGMT_SEMA_FREE)
4615 return 0;
4616
4617 for (i = 0; i < 2; i++) {
4618 tx_ctrl = readl(base + NvRegTransmitterControl);
4619 tx_ctrl |= NVREG_XMITCTL_HOST_SEMA_ACQ;
4620 writel(tx_ctrl, base + NvRegTransmitterControl);
4621
4622 /* verify that semaphore was acquired */
4623 tx_ctrl = readl(base + NvRegTransmitterControl);
4624 if (((tx_ctrl & NVREG_XMITCTL_HOST_SEMA_MASK) == NVREG_XMITCTL_HOST_SEMA_ACQ) &&
4625 ((tx_ctrl & NVREG_XMITCTL_MGMT_SEMA_MASK) == NVREG_XMITCTL_MGMT_SEMA_FREE))
4626 return 1;
4627 else
4628 udelay(50);
4629 }
4630
4631 return 0;
4632}
4633
Linus Torvalds1da177e2005-04-16 15:20:36 -07004634static int nv_open(struct net_device *dev)
4635{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004636 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004637 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004638 int ret = 1;
4639 int oom, i;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004640
4641 dprintk(KERN_DEBUG "nv_open: begin\n");
4642
Ayaz Abdullaf1489652006-07-31 12:04:45 -04004643 /* erase previous misconfiguration */
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004644 if (np->driver_data & DEV_HAS_POWER_CNTRL)
4645 nv_mac_reset(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004646 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
4647 writel(0, base + NvRegMulticastAddrB);
4648 writel(0, base + NvRegMulticastMaskA);
4649 writel(0, base + NvRegMulticastMaskB);
4650 writel(0, base + NvRegPacketFilterFlags);
4651
4652 writel(0, base + NvRegTransmitterControl);
4653 writel(0, base + NvRegReceiverControl);
4654
4655 writel(0, base + NvRegAdapterControl);
4656
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004657 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)
4658 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
4659
Ayaz Abdullaf1489652006-07-31 12:04:45 -04004660 /* initialize descriptor rings */
Manfred Sprauld81c0982005-07-31 18:20:30 +02004661 set_bufsize(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004662 oom = nv_init_ring(dev);
4663
4664 writel(0, base + NvRegLinkSpeed);
Ayaz Abdulla5070d342006-07-31 12:05:01 -04004665 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004666 nv_txrx_reset(dev);
4667 writel(0, base + NvRegUnknownSetupReg6);
4668
4669 np->in_shutdown = 0;
4670
Ayaz Abdullaf1489652006-07-31 12:04:45 -04004671 /* give hw rings */
Ayaz Abdulla0832b252006-02-04 13:13:26 -05004672 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004673 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Linus Torvalds1da177e2005-04-16 15:20:36 -07004674 base + NvRegRingSizes);
4675
Linus Torvalds1da177e2005-04-16 15:20:36 -07004676 writel(np->linkspeed, base + NvRegLinkSpeed);
Ayaz Abdulla95d161c2006-07-06 16:46:25 -04004677 if (np->desc_ver == DESC_VER_1)
4678 writel(NVREG_TX_WM_DESC1_DEFAULT, base + NvRegTxWatermark);
4679 else
4680 writel(NVREG_TX_WM_DESC2_3_DEFAULT, base + NvRegTxWatermark);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004681 writel(np->txrxctl_bits, base + NvRegTxRxControl);
Ayaz Abdullaee407b02006-02-04 13:13:17 -05004682 writel(np->vlanctl_bits, base + NvRegVlanControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004683 pci_push(base);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004684 writel(NVREG_TXRXCTL_BIT1|np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004685 reg_delay(dev, NvRegUnknownSetupReg5, NVREG_UNKSETUP5_BIT31, NVREG_UNKSETUP5_BIT31,
4686 NV_SETUP5_DELAY, NV_SETUP5_DELAYMAX,
4687 KERN_INFO "open: SetupReg5, Bit 31 remained off\n");
4688
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004689 writel(0, base + NvRegMIIMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004690 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4691 writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus);
4692
Linus Torvalds1da177e2005-04-16 15:20:36 -07004693 writel(NVREG_MISC1_FORCE | NVREG_MISC1_HD, base + NvRegMisc1);
4694 writel(readl(base + NvRegTransmitterStatus), base + NvRegTransmitterStatus);
4695 writel(NVREG_PFF_ALWAYS, base + NvRegPacketFilterFlags);
Manfred Sprauld81c0982005-07-31 18:20:30 +02004696 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004697
4698 writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus);
4699 get_random_bytes(&i, sizeof(i));
4700 writel(NVREG_RNDSEED_FORCE | (i&NVREG_RNDSEED_MASK), base + NvRegRandomSeed);
Ayaz Abdulla9744e212006-07-06 16:45:58 -04004701 writel(NVREG_TX_DEFERRAL_DEFAULT, base + NvRegTxDeferral);
4702 writel(NVREG_RX_DEFERRAL_DEFAULT, base + NvRegRxDeferral);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05004703 if (poll_interval == -1) {
4704 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT)
4705 writel(NVREG_POLL_DEFAULT_THROUGHPUT, base + NvRegPollingInterval);
4706 else
4707 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
4708 }
4709 else
4710 writel(poll_interval & 0xFFFF, base + NvRegPollingInterval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004711 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
4712 writel((np->phyaddr << NVREG_ADAPTCTL_PHYSHIFT)|NVREG_ADAPTCTL_PHYVALID|NVREG_ADAPTCTL_RUNNING,
4713 base + NvRegAdapterControl);
4714 writel(NVREG_MIISPEED_BIT8|NVREG_MIIDELAY, base + NvRegMIISpeed);
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004715 writel(NVREG_MII_LINKCHANGE, base + NvRegMIIMask);
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004716 if (np->wolenabled)
4717 writel(NVREG_WAKEUPFLAGS_ENABLE , base + NvRegWakeUpFlags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004718
4719 i = readl(base + NvRegPowerState);
4720 if ( (i & NVREG_POWERSTATE_POWEREDUP) == 0)
4721 writel(NVREG_POWERSTATE_POWEREDUP|i, base + NvRegPowerState);
4722
4723 pci_push(base);
4724 udelay(10);
4725 writel(readl(base + NvRegPowerState) | NVREG_POWERSTATE_VALID, base + NvRegPowerState);
4726
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004727 nv_disable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004728 pci_push(base);
4729 writel(NVREG_MIISTAT_MASK2, base + NvRegMIIStatus);
4730 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4731 pci_push(base);
4732
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004733 if (nv_request_irq(dev, 0)) {
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004734 goto out_drain;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004735 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004736
4737 /* ask for interrupts */
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004738 nv_enable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004739
4740 spin_lock_irq(&np->lock);
4741 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
4742 writel(0, base + NvRegMulticastAddrB);
4743 writel(0, base + NvRegMulticastMaskA);
4744 writel(0, base + NvRegMulticastMaskB);
4745 writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
4746 /* One manual link speed update: Interrupts are enabled, future link
4747 * speed changes cause interrupts and are handled by nv_link_irq().
4748 */
4749 {
4750 u32 miistat;
4751 miistat = readl(base + NvRegMIIStatus);
4752 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
4753 dprintk(KERN_INFO "startup: got 0x%08x.\n", miistat);
4754 }
Manfred Spraul1b1b3c92005-08-06 23:47:55 +02004755 /* set linkspeed to invalid value, thus force nv_update_linkspeed
4756 * to init hw */
4757 np->linkspeed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004758 ret = nv_update_linkspeed(dev);
4759 nv_start_rx(dev);
4760 nv_start_tx(dev);
4761 netif_start_queue(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07004762 netif_poll_enable(dev);
4763
Linus Torvalds1da177e2005-04-16 15:20:36 -07004764 if (ret) {
4765 netif_carrier_on(dev);
4766 } else {
4767 printk("%s: no link during initialization.\n", dev->name);
4768 netif_carrier_off(dev);
4769 }
4770 if (oom)
4771 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004772
4773 /* start statistics timer */
4774 if (np->driver_data & DEV_HAS_STATISTICS)
4775 mod_timer(&np->stats_poll, jiffies + STATS_INTERVAL);
4776
Linus Torvalds1da177e2005-04-16 15:20:36 -07004777 spin_unlock_irq(&np->lock);
4778
4779 return 0;
4780out_drain:
4781 drain_ring(dev);
4782 return ret;
4783}
4784
4785static int nv_close(struct net_device *dev)
4786{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004787 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004788 u8 __iomem *base;
4789
4790 spin_lock_irq(&np->lock);
4791 np->in_shutdown = 1;
4792 spin_unlock_irq(&np->lock);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07004793 netif_poll_disable(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004794 synchronize_irq(dev->irq);
4795
4796 del_timer_sync(&np->oom_kick);
4797 del_timer_sync(&np->nic_poll);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004798 del_timer_sync(&np->stats_poll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004799
4800 netif_stop_queue(dev);
4801 spin_lock_irq(&np->lock);
4802 nv_stop_tx(dev);
4803 nv_stop_rx(dev);
4804 nv_txrx_reset(dev);
4805
4806 /* disable interrupts on the nic or we will lock up */
4807 base = get_hwbase(dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004808 nv_disable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004809 pci_push(base);
4810 dprintk(KERN_INFO "%s: Irqmask is zero again\n", dev->name);
4811
4812 spin_unlock_irq(&np->lock);
4813
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004814 nv_free_irq(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004815
4816 drain_ring(dev);
4817
4818 if (np->wolenabled)
4819 nv_start_rx(dev);
4820
4821 /* FIXME: power down nic */
4822
4823 return 0;
4824}
4825
4826static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
4827{
4828 struct net_device *dev;
4829 struct fe_priv *np;
4830 unsigned long addr;
4831 u8 __iomem *base;
4832 int err, i;
Ayaz Abdulla5070d342006-07-31 12:05:01 -04004833 u32 powerstate, txreg;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05004834 u32 phystate_orig = 0, phystate;
4835 int phyinitialized = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004836
4837 dev = alloc_etherdev(sizeof(struct fe_priv));
4838 err = -ENOMEM;
4839 if (!dev)
4840 goto out;
4841
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004842 np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004843 np->pci_dev = pci_dev;
4844 spin_lock_init(&np->lock);
4845 SET_MODULE_OWNER(dev);
4846 SET_NETDEV_DEV(dev, &pci_dev->dev);
4847
4848 init_timer(&np->oom_kick);
4849 np->oom_kick.data = (unsigned long) dev;
4850 np->oom_kick.function = &nv_do_rx_refill; /* timer handler */
4851 init_timer(&np->nic_poll);
4852 np->nic_poll.data = (unsigned long) dev;
4853 np->nic_poll.function = &nv_do_nic_poll; /* timer handler */
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004854 init_timer(&np->stats_poll);
4855 np->stats_poll.data = (unsigned long) dev;
4856 np->stats_poll.function = &nv_do_stats_poll; /* timer handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004857
4858 err = pci_enable_device(pci_dev);
4859 if (err) {
4860 printk(KERN_INFO "forcedeth: pci_enable_dev failed (%d) for device %s\n",
4861 err, pci_name(pci_dev));
4862 goto out_free;
4863 }
4864
4865 pci_set_master(pci_dev);
4866
4867 err = pci_request_regions(pci_dev, DRV_NAME);
4868 if (err < 0)
4869 goto out_disable;
4870
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004871 if (id->driver_data & (DEV_HAS_VLAN|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS))
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004872 np->register_size = NV_PCI_REGSZ_VER2;
4873 else
4874 np->register_size = NV_PCI_REGSZ_VER1;
4875
Linus Torvalds1da177e2005-04-16 15:20:36 -07004876 err = -EINVAL;
4877 addr = 0;
4878 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
4879 dprintk(KERN_DEBUG "%s: resource %d start %p len %ld flags 0x%08lx.\n",
4880 pci_name(pci_dev), i, (void*)pci_resource_start(pci_dev, i),
4881 pci_resource_len(pci_dev, i),
4882 pci_resource_flags(pci_dev, i));
4883 if (pci_resource_flags(pci_dev, i) & IORESOURCE_MEM &&
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004884 pci_resource_len(pci_dev, i) >= np->register_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004885 addr = pci_resource_start(pci_dev, i);
4886 break;
4887 }
4888 }
4889 if (i == DEVICE_COUNT_RESOURCE) {
4890 printk(KERN_INFO "forcedeth: Couldn't find register window for device %s.\n",
4891 pci_name(pci_dev));
4892 goto out_relreg;
4893 }
4894
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004895 /* copy of driver data */
4896 np->driver_data = id->driver_data;
4897
Linus Torvalds1da177e2005-04-16 15:20:36 -07004898 /* handle different descriptor versions */
Manfred Spraulee733622005-07-31 18:32:26 +02004899 if (id->driver_data & DEV_HAS_HIGH_DMA) {
4900 /* packet format 3: supports 40-bit addressing */
4901 np->desc_ver = DESC_VER_3;
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004902 np->txrxctl_bits = NVREG_TXRXCTL_DESC_3;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04004903 if (dma_64bit) {
4904 if (pci_set_dma_mask(pci_dev, DMA_39BIT_MASK)) {
4905 printk(KERN_INFO "forcedeth: 64-bit DMA failed, using 32-bit addressing for device %s.\n",
4906 pci_name(pci_dev));
4907 } else {
4908 dev->features |= NETIF_F_HIGHDMA;
4909 printk(KERN_INFO "forcedeth: using HIGHDMA\n");
4910 }
4911 if (pci_set_consistent_dma_mask(pci_dev, DMA_39BIT_MASK)) {
4912 printk(KERN_INFO "forcedeth: 64-bit DMA (consistent) failed, using 32-bit ring buffers for device %s.\n",
4913 pci_name(pci_dev));
4914 }
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004915 }
Manfred Spraulee733622005-07-31 18:32:26 +02004916 } else if (id->driver_data & DEV_HAS_LARGEDESC) {
4917 /* packet format 2: supports jumbo frames */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004918 np->desc_ver = DESC_VER_2;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004919 np->txrxctl_bits = NVREG_TXRXCTL_DESC_2;
Manfred Spraulee733622005-07-31 18:32:26 +02004920 } else {
4921 /* original packet format */
4922 np->desc_ver = DESC_VER_1;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004923 np->txrxctl_bits = NVREG_TXRXCTL_DESC_1;
Manfred Sprauld81c0982005-07-31 18:20:30 +02004924 }
Manfred Spraulee733622005-07-31 18:32:26 +02004925
4926 np->pkt_limit = NV_PKTLIMIT_1;
4927 if (id->driver_data & DEV_HAS_LARGEDESC)
4928 np->pkt_limit = NV_PKTLIMIT_2;
4929
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004930 if (id->driver_data & DEV_HAS_CHECKSUM) {
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04004931 np->rx_csum = 1;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004932 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004933 dev->features |= NETIF_F_HW_CSUM | NETIF_F_SG;
Ayaz Abdullafa454592006-01-05 22:45:45 -08004934 dev->features |= NETIF_F_TSO;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004935 }
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04004936
Ayaz Abdullaee407b02006-02-04 13:13:17 -05004937 np->vlanctl_bits = 0;
4938 if (id->driver_data & DEV_HAS_VLAN) {
4939 np->vlanctl_bits = NVREG_VLANCONTROL_ENABLE;
4940 dev->features |= NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX;
4941 dev->vlan_rx_register = nv_vlan_rx_register;
4942 dev->vlan_rx_kill_vid = nv_vlan_rx_kill_vid;
4943 }
4944
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004945 np->msi_flags = 0;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04004946 if ((id->driver_data & DEV_HAS_MSI) && msi) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004947 np->msi_flags |= NV_MSI_CAPABLE;
4948 }
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04004949 if ((id->driver_data & DEV_HAS_MSI_X) && msix) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004950 np->msi_flags |= NV_MSI_X_CAPABLE;
4951 }
4952
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004953 np->pause_flags = NV_PAUSEFRAME_RX_CAPABLE | NV_PAUSEFRAME_RX_REQ | NV_PAUSEFRAME_AUTONEG;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004954 if (id->driver_data & DEV_HAS_PAUSEFRAME_TX) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004955 np->pause_flags |= NV_PAUSEFRAME_TX_CAPABLE | NV_PAUSEFRAME_TX_REQ;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004956 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04004957
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004958
Linus Torvalds1da177e2005-04-16 15:20:36 -07004959 err = -ENOMEM;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004960 np->base = ioremap(addr, np->register_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004961 if (!np->base)
4962 goto out_relreg;
4963 dev->base_addr = (unsigned long)np->base;
Manfred Spraulee733622005-07-31 18:32:26 +02004964
Linus Torvalds1da177e2005-04-16 15:20:36 -07004965 dev->irq = pci_dev->irq;
Manfred Spraulee733622005-07-31 18:32:26 +02004966
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004967 np->rx_ring_size = RX_RING_DEFAULT;
4968 np->tx_ring_size = TX_RING_DEFAULT;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004969
Manfred Spraulee733622005-07-31 18:32:26 +02004970 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) {
4971 np->rx_ring.orig = pci_alloc_consistent(pci_dev,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004972 sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
Manfred Spraulee733622005-07-31 18:32:26 +02004973 &np->ring_addr);
4974 if (!np->rx_ring.orig)
4975 goto out_unmap;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004976 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
Manfred Spraulee733622005-07-31 18:32:26 +02004977 } else {
4978 np->rx_ring.ex = pci_alloc_consistent(pci_dev,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004979 sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
Manfred Spraulee733622005-07-31 18:32:26 +02004980 &np->ring_addr);
4981 if (!np->rx_ring.ex)
4982 goto out_unmap;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004983 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
Manfred Spraulee733622005-07-31 18:32:26 +02004984 }
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004985 np->rx_skb = kmalloc(sizeof(struct nv_skb_map) * np->rx_ring_size, GFP_KERNEL);
4986 np->tx_skb = kmalloc(sizeof(struct nv_skb_map) * np->tx_ring_size, GFP_KERNEL);
4987 if (!np->rx_skb || !np->tx_skb)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004988 goto out_freering;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004989 memset(np->rx_skb, 0, sizeof(struct nv_skb_map) * np->rx_ring_size);
4990 memset(np->tx_skb, 0, sizeof(struct nv_skb_map) * np->tx_ring_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004991
4992 dev->open = nv_open;
4993 dev->stop = nv_close;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05004994 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
4995 dev->hard_start_xmit = nv_start_xmit;
4996 else
4997 dev->hard_start_xmit = nv_start_xmit_optimized;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004998 dev->get_stats = nv_get_stats;
4999 dev->change_mtu = nv_change_mtu;
Manfred Spraul72b31782005-07-31 18:33:34 +02005000 dev->set_mac_address = nv_set_mac_address;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005001 dev->set_multicast_list = nv_set_multicast;
Michal Schmidt2918c352005-05-12 19:42:06 -04005002#ifdef CONFIG_NET_POLL_CONTROLLER
5003 dev->poll_controller = nv_poll_controller;
5004#endif
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07005005 dev->weight = 64;
5006#ifdef CONFIG_FORCEDETH_NAPI
5007 dev->poll = nv_napi_poll;
5008#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009 SET_ETHTOOL_OPS(dev, &ops);
5010 dev->tx_timeout = nv_tx_timeout;
5011 dev->watchdog_timeo = NV_WATCHDOG_TIMEO;
5012
5013 pci_set_drvdata(pci_dev, dev);
5014
5015 /* read the mac address */
5016 base = get_hwbase(dev);
5017 np->orig_mac[0] = readl(base + NvRegMacAddrA);
5018 np->orig_mac[1] = readl(base + NvRegMacAddrB);
5019
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005020 /* check the workaround bit for correct mac address order */
5021 txreg = readl(base + NvRegTransmitPoll);
5022 if (txreg & NVREG_TRANSMITPOLL_MAC_ADDR_REV) {
5023 /* mac address is already in correct order */
5024 dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff;
5025 dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff;
5026 dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff;
5027 dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff;
5028 dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff;
5029 dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff;
5030 } else {
5031 /* need to reverse mac address to correct order */
5032 dev->dev_addr[0] = (np->orig_mac[1] >> 8) & 0xff;
5033 dev->dev_addr[1] = (np->orig_mac[1] >> 0) & 0xff;
5034 dev->dev_addr[2] = (np->orig_mac[0] >> 24) & 0xff;
5035 dev->dev_addr[3] = (np->orig_mac[0] >> 16) & 0xff;
5036 dev->dev_addr[4] = (np->orig_mac[0] >> 8) & 0xff;
5037 dev->dev_addr[5] = (np->orig_mac[0] >> 0) & 0xff;
5038 /* set permanent address to be correct aswell */
5039 np->orig_mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) +
5040 (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24);
5041 np->orig_mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8);
5042 writel(txreg|NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
5043 }
John W. Linvillec704b852005-09-12 10:48:56 -04005044 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005045
John W. Linvillec704b852005-09-12 10:48:56 -04005046 if (!is_valid_ether_addr(dev->perm_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005047 /*
5048 * Bad mac address. At least one bios sets the mac address
5049 * to 01:23:45:67:89:ab
5050 */
5051 printk(KERN_ERR "%s: Invalid Mac address detected: %02x:%02x:%02x:%02x:%02x:%02x\n",
5052 pci_name(pci_dev),
5053 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
5054 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
5055 printk(KERN_ERR "Please complain to your hardware vendor. Switching to a random MAC.\n");
5056 dev->dev_addr[0] = 0x00;
5057 dev->dev_addr[1] = 0x00;
5058 dev->dev_addr[2] = 0x6c;
5059 get_random_bytes(&dev->dev_addr[3], 3);
5060 }
5061
5062 dprintk(KERN_DEBUG "%s: MAC Address %02x:%02x:%02x:%02x:%02x:%02x\n", pci_name(pci_dev),
5063 dev->dev_addr[0], dev->dev_addr[1], dev->dev_addr[2],
5064 dev->dev_addr[3], dev->dev_addr[4], dev->dev_addr[5]);
5065
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005066 /* set mac address */
5067 nv_copy_mac_to_hw(dev);
5068
Linus Torvalds1da177e2005-04-16 15:20:36 -07005069 /* disable WOL */
5070 writel(0, base + NvRegWakeUpFlags);
5071 np->wolenabled = 0;
5072
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005073 if (id->driver_data & DEV_HAS_POWER_CNTRL) {
5074 u8 revision_id;
5075 pci_read_config_byte(pci_dev, PCI_REVISION_ID, &revision_id);
5076
5077 /* take phy and nic out of low power mode */
5078 powerstate = readl(base + NvRegPowerState2);
5079 powerstate &= ~NVREG_POWERSTATE2_POWERUP_MASK;
5080 if ((id->device == PCI_DEVICE_ID_NVIDIA_NVENET_12 ||
5081 id->device == PCI_DEVICE_ID_NVIDIA_NVENET_13) &&
5082 revision_id >= 0xA3)
5083 powerstate |= NVREG_POWERSTATE2_POWERUP_REV_A3;
5084 writel(powerstate, base + NvRegPowerState2);
5085 }
5086
Linus Torvalds1da177e2005-04-16 15:20:36 -07005087 if (np->desc_ver == DESC_VER_1) {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005088 np->tx_flags = NV_TX_VALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005089 } else {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005090 np->tx_flags = NV_TX2_VALID;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005091 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005092 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005093 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005094 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
5095 np->msi_flags |= 0x0003;
5096 } else {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005097 np->irqmask = NVREG_IRQMASK_CPU;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005098 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
5099 np->msi_flags |= 0x0001;
5100 }
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005101
Linus Torvalds1da177e2005-04-16 15:20:36 -07005102 if (id->driver_data & DEV_NEED_TIMERIRQ)
5103 np->irqmask |= NVREG_IRQ_TIMER;
5104 if (id->driver_data & DEV_NEED_LINKTIMER) {
5105 dprintk(KERN_INFO "%s: link timer on.\n", pci_name(pci_dev));
5106 np->need_linktimer = 1;
5107 np->link_timeout = jiffies + LINK_TIMEOUT;
5108 } else {
5109 dprintk(KERN_INFO "%s: link timer off.\n", pci_name(pci_dev));
5110 np->need_linktimer = 0;
5111 }
5112
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005113 /* clear phy state and temporarily halt phy interrupts */
5114 writel(0, base + NvRegMIIMask);
5115 phystate = readl(base + NvRegAdapterControl);
5116 if (phystate & NVREG_ADAPTCTL_RUNNING) {
5117 phystate_orig = 1;
5118 phystate &= ~NVREG_ADAPTCTL_RUNNING;
5119 writel(phystate, base + NvRegAdapterControl);
5120 }
5121 writel(NVREG_MIISTAT_MASK, base + NvRegMIIStatus);
5122
5123 if (id->driver_data & DEV_HAS_MGMT_UNIT) {
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005124 /* management unit running on the mac? */
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05005125 if (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_PHY_INIT) {
5126 np->mac_in_use = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_ST;
5127 dprintk(KERN_INFO "%s: mgmt unit is running. mac in use %x.\n", pci_name(pci_dev), np->mac_in_use);
5128 for (i = 0; i < 5000; i++) {
5129 msleep(1);
5130 if (nv_mgmt_acquire_sema(dev)) {
5131 /* management unit setup the phy already? */
5132 if ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK) ==
5133 NVREG_XMITCTL_SYNC_PHY_INIT) {
5134 /* phy is inited by mgmt unit */
5135 phyinitialized = 1;
5136 dprintk(KERN_INFO "%s: Phy already initialized by mgmt unit.\n", pci_name(pci_dev));
5137 } else {
5138 /* we need to init the phy */
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005139 }
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05005140 break;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005141 }
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005142 }
5143 }
5144 }
5145
Linus Torvalds1da177e2005-04-16 15:20:36 -07005146 /* find a suitable phy */
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005147 for (i = 1; i <= 32; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005148 int id1, id2;
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005149 int phyaddr = i & 0x1F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005150
5151 spin_lock_irq(&np->lock);
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005152 id1 = mii_rw(dev, phyaddr, MII_PHYSID1, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005153 spin_unlock_irq(&np->lock);
5154 if (id1 < 0 || id1 == 0xffff)
5155 continue;
5156 spin_lock_irq(&np->lock);
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005157 id2 = mii_rw(dev, phyaddr, MII_PHYSID2, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005158 spin_unlock_irq(&np->lock);
5159 if (id2 < 0 || id2 == 0xffff)
5160 continue;
5161
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04005162 np->phy_model = id2 & PHYID2_MODEL_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005163 id1 = (id1 & PHYID1_OUI_MASK) << PHYID1_OUI_SHFT;
5164 id2 = (id2 & PHYID2_OUI_MASK) >> PHYID2_OUI_SHFT;
5165 dprintk(KERN_DEBUG "%s: open: Found PHY %04x:%04x at address %d.\n",
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005166 pci_name(pci_dev), id1, id2, phyaddr);
5167 np->phyaddr = phyaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005168 np->phy_oui = id1 | id2;
5169 break;
5170 }
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005171 if (i == 33) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005172 printk(KERN_INFO "%s: open: Could not find a valid PHY.\n",
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005173 pci_name(pci_dev));
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005174 goto out_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005175 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04005176
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005177 if (!phyinitialized) {
5178 /* reset it */
5179 phy_init(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05005180 } else {
5181 /* see if it is a gigabit phy */
5182 u32 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
5183 if (mii_status & PHY_GIGABIT) {
5184 np->gigabit = PHY_GIGABIT;
5185 }
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005186 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005187
5188 /* set default link speed settings */
5189 np->linkspeed = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
5190 np->duplex = 0;
5191 np->autoneg = 1;
5192
5193 err = register_netdev(dev);
5194 if (err) {
5195 printk(KERN_INFO "forcedeth: unable to register netdev: %d\n", err);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005196 goto out_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005197 }
5198 printk(KERN_INFO "%s: forcedeth.c: subsystem: %05x:%04x bound to %s\n",
5199 dev->name, pci_dev->subsystem_vendor, pci_dev->subsystem_device,
5200 pci_name(pci_dev));
5201
5202 return 0;
5203
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005204out_error:
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005205 if (phystate_orig)
5206 writel(phystate|NVREG_ADAPTCTL_RUNNING, base + NvRegAdapterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005207 pci_set_drvdata(pci_dev, NULL);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005208out_freering:
5209 free_rings(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005210out_unmap:
5211 iounmap(get_hwbase(dev));
5212out_relreg:
5213 pci_release_regions(pci_dev);
5214out_disable:
5215 pci_disable_device(pci_dev);
5216out_free:
5217 free_netdev(dev);
5218out:
5219 return err;
5220}
5221
5222static void __devexit nv_remove(struct pci_dev *pci_dev)
5223{
5224 struct net_device *dev = pci_get_drvdata(pci_dev);
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005225 struct fe_priv *np = netdev_priv(dev);
5226 u8 __iomem *base = get_hwbase(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005227
5228 unregister_netdev(dev);
5229
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005230 /* special op: write back the misordered MAC address - otherwise
5231 * the next nv_probe would see a wrong address.
5232 */
5233 writel(np->orig_mac[0], base + NvRegMacAddrA);
5234 writel(np->orig_mac[1], base + NvRegMacAddrB);
5235
Linus Torvalds1da177e2005-04-16 15:20:36 -07005236 /* free all structures */
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005237 free_rings(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005238 iounmap(get_hwbase(dev));
5239 pci_release_regions(pci_dev);
5240 pci_disable_device(pci_dev);
5241 free_netdev(dev);
5242 pci_set_drvdata(pci_dev, NULL);
5243}
5244
Francois Romieua1893172006-10-10 14:33:27 -07005245#ifdef CONFIG_PM
5246static int nv_suspend(struct pci_dev *pdev, pm_message_t state)
5247{
5248 struct net_device *dev = pci_get_drvdata(pdev);
5249 struct fe_priv *np = netdev_priv(dev);
5250
5251 if (!netif_running(dev))
5252 goto out;
5253
5254 netif_device_detach(dev);
5255
5256 // Gross.
5257 nv_close(dev);
5258
5259 pci_save_state(pdev);
5260 pci_enable_wake(pdev, pci_choose_state(pdev, state), np->wolenabled);
5261 pci_set_power_state(pdev, pci_choose_state(pdev, state));
5262out:
5263 return 0;
5264}
5265
5266static int nv_resume(struct pci_dev *pdev)
5267{
5268 struct net_device *dev = pci_get_drvdata(pdev);
5269 int rc = 0;
5270
5271 if (!netif_running(dev))
5272 goto out;
5273
5274 netif_device_attach(dev);
5275
5276 pci_set_power_state(pdev, PCI_D0);
5277 pci_restore_state(pdev);
5278 pci_enable_wake(pdev, PCI_D0, 0);
5279
5280 rc = nv_open(dev);
5281out:
5282 return rc;
5283}
5284#else
5285#define nv_suspend NULL
5286#define nv_resume NULL
5287#endif /* CONFIG_PM */
5288
Linus Torvalds1da177e2005-04-16 15:20:36 -07005289static struct pci_device_id pci_tbl[] = {
5290 { /* nForce Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005291 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_1),
Manfred Spraulc2dba062005-07-31 18:29:47 +02005292 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005293 },
5294 { /* nForce2 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005295 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_2),
Manfred Spraulc2dba062005-07-31 18:29:47 +02005296 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005297 },
5298 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005299 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_3),
Manfred Spraulc2dba062005-07-31 18:29:47 +02005300 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005301 },
5302 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005303 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_4),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005304 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005305 },
5306 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005307 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_5),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005308 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005309 },
5310 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005311 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_6),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005312 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005313 },
5314 { /* nForce3 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005315 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_7),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005316 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005317 },
5318 { /* CK804 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005319 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_8),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005320 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005321 },
5322 { /* CK804 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005323 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_9),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005324 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005325 },
5326 { /* MCP04 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005327 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_10),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005328 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005329 },
5330 { /* MCP04 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005331 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_11),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005332 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA,
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005333 },
5334 { /* MCP51 Ethernet Controller */
5335 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_12),
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005336 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005337 },
Manfred Spraul9992d4a2005-06-05 17:36:11 +02005338 { /* MCP51 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005339 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_13),
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005340 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL,
Manfred Spraul9992d4a2005-06-05 17:36:11 +02005341 },
Manfred Spraulf49d16e2005-06-26 11:36:52 +02005342 { /* MCP55 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005343 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_14),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005344 .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 Spraulf49d16e2005-06-26 11:36:52 +02005345 },
5346 { /* MCP55 Ethernet Controller */
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005347 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_15),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005348 .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 Spraulf49d16e2005-06-26 11:36:52 +02005349 },
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04005350 { /* MCP61 Ethernet Controller */
5351 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_16),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005352 .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 Abdullac99ce7e2006-06-10 22:48:28 -04005353 },
5354 { /* MCP61 Ethernet Controller */
5355 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_17),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005356 .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 Abdullac99ce7e2006-06-10 22:48:28 -04005357 },
5358 { /* MCP61 Ethernet Controller */
5359 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_18),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005360 .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 Abdullac99ce7e2006-06-10 22:48:28 -04005361 },
5362 { /* MCP61 Ethernet Controller */
5363 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_19),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005364 .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 Abdullac99ce7e2006-06-10 22:48:28 -04005365 },
5366 { /* MCP65 Ethernet Controller */
5367 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_20),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005368 .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 Abdullac99ce7e2006-06-10 22:48:28 -04005369 },
5370 { /* MCP65 Ethernet Controller */
5371 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_21),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005372 .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 Abdullac99ce7e2006-06-10 22:48:28 -04005373 },
5374 { /* MCP65 Ethernet Controller */
5375 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_22),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005376 .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 Abdullac99ce7e2006-06-10 22:48:28 -04005377 },
5378 { /* MCP65 Ethernet Controller */
5379 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_23),
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005380 .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 Abdullac99ce7e2006-06-10 22:48:28 -04005381 },
Ayaz Abdullaf4344842006-11-06 00:43:40 -08005382 { /* MCP67 Ethernet Controller */
5383 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_24),
5384 .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,
5385 },
5386 { /* MCP67 Ethernet Controller */
5387 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_25),
5388 .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,
5389 },
5390 { /* MCP67 Ethernet Controller */
5391 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_26),
5392 .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,
5393 },
5394 { /* MCP67 Ethernet Controller */
5395 PCI_DEVICE(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_NVENET_27),
5396 .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,
5397 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07005398 {0,},
5399};
5400
5401static struct pci_driver driver = {
5402 .name = "forcedeth",
5403 .id_table = pci_tbl,
5404 .probe = nv_probe,
5405 .remove = __devexit_p(nv_remove),
Francois Romieua1893172006-10-10 14:33:27 -07005406 .suspend = nv_suspend,
5407 .resume = nv_resume,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005408};
5409
Linus Torvalds1da177e2005-04-16 15:20:36 -07005410static int __init init_nic(void)
5411{
5412 printk(KERN_INFO "forcedeth.c: Reverse Engineered nForce ethernet driver. Version %s.\n", FORCEDETH_VERSION);
Jeff Garzik29917622006-08-19 17:48:59 -04005413 return pci_register_driver(&driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005414}
5415
5416static void __exit exit_nic(void)
5417{
5418 pci_unregister_driver(&driver);
5419}
5420
5421module_param(max_interrupt_work, int, 0);
5422MODULE_PARM_DESC(max_interrupt_work, "forcedeth maximum events handled per interrupt");
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005423module_param(optimization_mode, int, 0);
5424MODULE_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.");
5425module_param(poll_interval, int, 0);
5426MODULE_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 Abdulla69fe3fd2006-06-10 22:48:18 -04005427module_param(msi, int, 0);
5428MODULE_PARM_DESC(msi, "MSI interrupts are enabled by setting to 1 and disabled by setting to 0.");
5429module_param(msix, int, 0);
5430MODULE_PARM_DESC(msix, "MSIX interrupts are enabled by setting to 1 and disabled by setting to 0.");
5431module_param(dma_64bit, int, 0);
5432MODULE_PARM_DESC(dma_64bit, "High DMA is enabled by setting to 1 and disabled by setting to 0.");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005433
5434MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>");
5435MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver");
5436MODULE_LICENSE("GPL");
5437
5438MODULE_DEVICE_TABLE(pci, pci_tbl);
5439
5440module_init(init_nic);
5441module_exit(exit_nic);