blob: c503fbebdf7e23af7c2584ea3053fffb82ea5a11 [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 Abdullaf1405d322009-01-09 11:03:54 +000016 * Copyright (c) 2004,2005,2006,2007,2008,2009 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 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 * Known bugs:
33 * We suspect that on some hardware no TX done interrupts are generated.
34 * This means recovery from netif_stop_queue only happens if the hw timer
35 * interrupt fires (100 times/second, configurable with NVREG_POLL_DEFAULT)
36 * and the timer is active in the IRQMask, or if a rx packet arrives by chance.
37 * If your hardware reliably generates tx done interrupts, then you can remove
38 * DEV_NEED_TIMERIRQ from the driver_data flags.
39 * DEV_NEED_TIMERIRQ will not harm you on sane hardware, only generating a few
40 * superfluous timer interrupts from the nic.
41 */
Joe Perches294a5542010-11-29 07:41:56 +000042
43#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
44
Ayaz Abdulla3e1a3ce2009-03-05 08:02:38 +000045#define FORCEDETH_VERSION "0.64"
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#define DRV_NAME "forcedeth"
47
48#include <linux/module.h>
49#include <linux/types.h>
50#include <linux/pci.h>
51#include <linux/interrupt.h>
52#include <linux/netdevice.h>
53#include <linux/etherdevice.h>
54#include <linux/delay.h>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040055#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#include <linux/spinlock.h>
57#include <linux/ethtool.h>
58#include <linux/timer.h>
59#include <linux/skbuff.h>
60#include <linux/mii.h>
61#include <linux/random.h>
62#include <linux/init.h>
Manfred Spraul22c6d142005-04-19 21:17:09 +020063#include <linux/if_vlan.h>
Matthias Gehre910638a2006-03-28 01:56:48 -080064#include <linux/dma-mapping.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090065#include <linux/slab.h>
Szymon Janc5504e132010-11-27 08:39:45 +000066#include <linux/uaccess.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040067#include <linux/prefetch.h>
david decotignyf5d827a2011-11-16 12:15:13 +000068#include <linux/u64_stats_sync.h>
69#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Stephen Hemmingerbea33482007-10-03 16:41:36 -070073#define TX_WORK_PER_LOOP 64
74#define RX_WORK_PER_LOOP 64
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76/*
77 * Hardware access:
78 */
79
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +000080#define DEV_NEED_TIMERIRQ 0x0000001 /* set the timer irq flag in the irq mask */
81#define DEV_NEED_LINKTIMER 0x0000002 /* poll link settings. Relies on the timer irq */
82#define DEV_HAS_LARGEDESC 0x0000004 /* device supports jumbo frames and needs packet format 2 */
83#define DEV_HAS_HIGH_DMA 0x0000008 /* device supports 64bit dma */
84#define DEV_HAS_CHECKSUM 0x0000010 /* device supports tx and rx checksum offloads */
85#define DEV_HAS_VLAN 0x0000020 /* device supports vlan tagging and striping */
86#define DEV_HAS_MSI 0x0000040 /* device supports MSI */
87#define DEV_HAS_MSI_X 0x0000080 /* device supports MSI-X */
88#define DEV_HAS_POWER_CNTRL 0x0000100 /* device supports power savings */
89#define DEV_HAS_STATISTICS_V1 0x0000200 /* device supports hw statistics version 1 */
Mike Ditto7b5e0782010-07-25 21:54:28 -070090#define DEV_HAS_STATISTICS_V2 0x0000400 /* device supports hw statistics version 2 */
91#define DEV_HAS_STATISTICS_V3 0x0000800 /* device supports hw statistics version 3 */
92#define DEV_HAS_STATISTICS_V12 0x0000600 /* device supports hw statistics version 1 and 2 */
93#define DEV_HAS_STATISTICS_V123 0x0000e00 /* device supports hw statistics version 1, 2, and 3 */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +000094#define DEV_HAS_TEST_EXTENDED 0x0001000 /* device supports extended diagnostic test */
95#define DEV_HAS_MGMT_UNIT 0x0002000 /* device supports management unit */
96#define DEV_HAS_CORRECT_MACADDR 0x0004000 /* device supports correct mac address order */
97#define DEV_HAS_COLLISION_FIX 0x0008000 /* device supports tx collision fix */
98#define DEV_HAS_PAUSEFRAME_TX_V1 0x0010000 /* device supports tx pause frames version 1 */
99#define DEV_HAS_PAUSEFRAME_TX_V2 0x0020000 /* device supports tx pause frames version 2 */
100#define DEV_HAS_PAUSEFRAME_TX_V3 0x0040000 /* device supports tx pause frames version 3 */
101#define DEV_NEED_TX_LIMIT 0x0080000 /* device needs to limit tx */
102#define DEV_NEED_TX_LIMIT2 0x0180000 /* device needs to limit tx, expect for some revs */
103#define DEV_HAS_GEAR_MODE 0x0200000 /* device supports gear mode */
104#define DEV_NEED_PHY_INIT_FIX 0x0400000 /* device needs specific phy workaround */
105#define DEV_NEED_LOW_POWER_FIX 0x0800000 /* device needs special power up workaround */
106#define DEV_NEED_MSI_FIX 0x1000000 /* device needs msi workaround */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108enum {
109 NvRegIrqStatus = 0x000,
110#define NVREG_IRQSTAT_MIIEVENT 0x040
Ayaz Abdulladaa91a92009-02-07 00:25:00 -0800111#define NVREG_IRQSTAT_MASK 0x83ff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 NvRegIrqMask = 0x004,
113#define NVREG_IRQ_RX_ERROR 0x0001
114#define NVREG_IRQ_RX 0x0002
115#define NVREG_IRQ_RX_NOBUF 0x0004
116#define NVREG_IRQ_TX_ERR 0x0008
Manfred Spraulc2dba062005-07-31 18:29:47 +0200117#define NVREG_IRQ_TX_OK 0x0010
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#define NVREG_IRQ_TIMER 0x0020
119#define NVREG_IRQ_LINK 0x0040
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500120#define NVREG_IRQ_RX_FORCED 0x0080
121#define NVREG_IRQ_TX_FORCED 0x0100
Ayaz Abdulladaa91a92009-02-07 00:25:00 -0800122#define NVREG_IRQ_RECOVER_ERROR 0x8200
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500123#define NVREG_IRQMASK_THROUGHPUT 0x00df
Ayaz Abdulla096a4582007-05-21 20:23:11 -0400124#define NVREG_IRQMASK_CPU 0x0060
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500125#define NVREG_IRQ_TX_ALL (NVREG_IRQ_TX_ERR|NVREG_IRQ_TX_OK|NVREG_IRQ_TX_FORCED)
126#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 -0500127#define NVREG_IRQ_OTHER (NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_RECOVER_ERROR)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 NvRegUnknownSetupReg6 = 0x008,
130#define NVREG_UNKSETUP6_VAL 3
131
132/*
133 * NVREG_POLL_DEFAULT is the interval length of the timer source on the nic
134 * NVREG_POLL_DEFAULT=97 would result in an interval length of 1 ms
135 */
136 NvRegPollingInterval = 0x00c,
Ayaz Abdulla6cef67a2009-03-05 08:02:30 +0000137#define NVREG_POLL_DEFAULT_THROUGHPUT 65535 /* backup tx cleanup if loop max reached */
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500138#define NVREG_POLL_DEFAULT_CPU 13
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500139 NvRegMSIMap0 = 0x020,
140 NvRegMSIMap1 = 0x024,
141 NvRegMSIIrqMask = 0x030,
142#define NVREG_MSI_VECTOR_0_ENABLED 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 NvRegMisc1 = 0x080,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400144#define NVREG_MISC1_PAUSE_TX 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#define NVREG_MISC1_HD 0x02
146#define NVREG_MISC1_FORCE 0x3b0f3c
147
Ayaz Abdulla0a626772008-01-13 16:02:42 -0500148 NvRegMacReset = 0x34,
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400149#define NVREG_MAC_RESET_ASSERT 0x0F3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 NvRegTransmitterControl = 0x084,
151#define NVREG_XMITCTL_START 0x01
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500152#define NVREG_XMITCTL_MGMT_ST 0x40000000
153#define NVREG_XMITCTL_SYNC_MASK 0x000f0000
154#define NVREG_XMITCTL_SYNC_NOT_READY 0x0
155#define NVREG_XMITCTL_SYNC_PHY_INIT 0x00040000
156#define NVREG_XMITCTL_MGMT_SEMA_MASK 0x00000f00
157#define NVREG_XMITCTL_MGMT_SEMA_FREE 0x0
158#define NVREG_XMITCTL_HOST_SEMA_MASK 0x0000f000
159#define NVREG_XMITCTL_HOST_SEMA_ACQ 0x0000f000
160#define NVREG_XMITCTL_HOST_LOADED 0x00004000
Ayaz Abdullaf35723e2003-02-20 03:03:54 -0500161#define NVREG_XMITCTL_TX_PATH_EN 0x01000000
Ayaz Abdullacac1c522009-02-07 00:23:57 -0800162#define NVREG_XMITCTL_DATA_START 0x00100000
163#define NVREG_XMITCTL_DATA_READY 0x00010000
164#define NVREG_XMITCTL_DATA_ERROR 0x00020000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 NvRegTransmitterStatus = 0x088,
166#define NVREG_XMITSTAT_BUSY 0x01
167
168 NvRegPacketFilterFlags = 0x8c,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400169#define NVREG_PFF_PAUSE_RX 0x08
170#define NVREG_PFF_ALWAYS 0x7F0000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171#define NVREG_PFF_PROMISC 0x80
172#define NVREG_PFF_MYADDR 0x20
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400173#define NVREG_PFF_LOOPBACK 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 NvRegOffloadConfig = 0x90,
176#define NVREG_OFFLOAD_HOMEPHY 0x601
177#define NVREG_OFFLOAD_NORMAL RX_NIC_BUFSIZE
178 NvRegReceiverControl = 0x094,
179#define NVREG_RCVCTL_START 0x01
Ayaz Abdullaf35723e2003-02-20 03:03:54 -0500180#define NVREG_RCVCTL_RX_PATH_EN 0x01000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 NvRegReceiverStatus = 0x98,
182#define NVREG_RCVSTAT_BUSY 0x01
183
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700184 NvRegSlotTime = 0x9c,
185#define NVREG_SLOTTIME_LEGBF_ENABLED 0x80000000
186#define NVREG_SLOTTIME_10_100_FULL 0x00007f00
Szymon Janc78aea4f2010-11-27 08:39:43 +0000187#define NVREG_SLOTTIME_1000_FULL 0x0003ff00
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700188#define NVREG_SLOTTIME_HALF 0x0000ff00
Szymon Janc78aea4f2010-11-27 08:39:43 +0000189#define NVREG_SLOTTIME_DEFAULT 0x00007f00
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700190#define NVREG_SLOTTIME_MASK 0x000000ff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Ayaz Abdulla9744e212006-07-06 16:45:58 -0400192 NvRegTxDeferral = 0xA0,
Ayaz Abdullafd9b5582008-02-05 12:29:49 -0500193#define NVREG_TX_DEFERRAL_DEFAULT 0x15050f
194#define NVREG_TX_DEFERRAL_RGMII_10_100 0x16070f
195#define NVREG_TX_DEFERRAL_RGMII_1000 0x14050f
196#define NVREG_TX_DEFERRAL_RGMII_STRETCH_10 0x16190f
197#define NVREG_TX_DEFERRAL_RGMII_STRETCH_100 0x16300f
198#define NVREG_TX_DEFERRAL_MII_STRETCH 0x152000
Ayaz Abdulla9744e212006-07-06 16:45:58 -0400199 NvRegRxDeferral = 0xA4,
200#define NVREG_RX_DEFERRAL_DEFAULT 0x16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 NvRegMacAddrA = 0xA8,
202 NvRegMacAddrB = 0xAC,
203 NvRegMulticastAddrA = 0xB0,
204#define NVREG_MCASTADDRA_FORCE 0x01
205 NvRegMulticastAddrB = 0xB4,
206 NvRegMulticastMaskA = 0xB8,
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -0500207#define NVREG_MCASTMASKA_NONE 0xffffffff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 NvRegMulticastMaskB = 0xBC,
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -0500209#define NVREG_MCASTMASKB_NONE 0xffff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211 NvRegPhyInterface = 0xC0,
212#define PHY_RGMII 0x10000000
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700213 NvRegBackOffControl = 0xC4,
214#define NVREG_BKOFFCTRL_DEFAULT 0x70000000
215#define NVREG_BKOFFCTRL_SEED_MASK 0x000003ff
216#define NVREG_BKOFFCTRL_SELECT 24
217#define NVREG_BKOFFCTRL_GEAR 12
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219 NvRegTxRingPhysAddr = 0x100,
220 NvRegRxRingPhysAddr = 0x104,
221 NvRegRingSizes = 0x108,
222#define NVREG_RINGSZ_TXSHIFT 0
223#define NVREG_RINGSZ_RXSHIFT 16
Ayaz Abdulla5070d342006-07-31 12:05:01 -0400224 NvRegTransmitPoll = 0x10c,
225#define NVREG_TRANSMITPOLL_MAC_ADDR_REV 0x00008000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 NvRegLinkSpeed = 0x110,
227#define NVREG_LINKSPEED_FORCE 0x10000
228#define NVREG_LINKSPEED_10 1000
229#define NVREG_LINKSPEED_100 100
230#define NVREG_LINKSPEED_1000 50
231#define NVREG_LINKSPEED_MASK (0xFFF)
232 NvRegUnknownSetupReg5 = 0x130,
233#define NVREG_UNKSETUP5_BIT31 (1<<31)
Ayaz Abdulla95d161c2006-07-06 16:46:25 -0400234 NvRegTxWatermark = 0x13c,
235#define NVREG_TX_WM_DESC1_DEFAULT 0x0200010
236#define NVREG_TX_WM_DESC2_3_DEFAULT 0x1e08000
237#define NVREG_TX_WM_DESC2_3_1000 0xfe08000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 NvRegTxRxControl = 0x144,
239#define NVREG_TXRXCTL_KICK 0x0001
240#define NVREG_TXRXCTL_BIT1 0x0002
241#define NVREG_TXRXCTL_BIT2 0x0004
242#define NVREG_TXRXCTL_IDLE 0x0008
243#define NVREG_TXRXCTL_RESET 0x0010
244#define NVREG_TXRXCTL_RXCHECK 0x0400
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400245#define NVREG_TXRXCTL_DESC_1 0
Ayaz Abdullad2f78412007-01-09 13:30:02 -0500246#define NVREG_TXRXCTL_DESC_2 0x002100
247#define NVREG_TXRXCTL_DESC_3 0xc02200
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500248#define NVREG_TXRXCTL_VLANSTRIP 0x00040
249#define NVREG_TXRXCTL_VLANINS 0x00080
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500250 NvRegTxRingPhysAddrHigh = 0x148,
251 NvRegRxRingPhysAddrHigh = 0x14C,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400252 NvRegTxPauseFrame = 0x170,
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -0500253#define NVREG_TX_PAUSEFRAME_DISABLE 0x0fff0080
254#define NVREG_TX_PAUSEFRAME_ENABLE_V1 0x01800010
255#define NVREG_TX_PAUSEFRAME_ENABLE_V2 0x056003f0
256#define NVREG_TX_PAUSEFRAME_ENABLE_V3 0x09f00880
Ayaz Abdulla9a33e882008-08-06 12:12:34 -0400257 NvRegTxPauseFrameLimit = 0x174,
258#define NVREG_TX_PAUSEFRAMELIMIT_ENABLE 0x00010000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 NvRegMIIStatus = 0x180,
260#define NVREG_MIISTAT_ERROR 0x0001
261#define NVREG_MIISTAT_LINKCHANGE 0x0008
Ayaz Abdullaeb798422008-02-04 15:14:04 -0500262#define NVREG_MIISTAT_MASK_RW 0x0007
263#define NVREG_MIISTAT_MASK_ALL 0x000f
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500264 NvRegMIIMask = 0x184,
265#define NVREG_MII_LINKCHANGE 0x0008
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267 NvRegAdapterControl = 0x188,
268#define NVREG_ADAPTCTL_START 0x02
269#define NVREG_ADAPTCTL_LINKUP 0x04
270#define NVREG_ADAPTCTL_PHYVALID 0x40000
271#define NVREG_ADAPTCTL_RUNNING 0x100000
272#define NVREG_ADAPTCTL_PHYSHIFT 24
273 NvRegMIISpeed = 0x18c,
274#define NVREG_MIISPEED_BIT8 (1<<8)
275#define NVREG_MIIDELAY 5
276 NvRegMIIControl = 0x190,
277#define NVREG_MIICTL_INUSE 0x08000
278#define NVREG_MIICTL_WRITE 0x00400
279#define NVREG_MIICTL_ADDRSHIFT 5
280 NvRegMIIData = 0x194,
Ayaz Abdulla9c662432008-08-06 12:11:42 -0400281 NvRegTxUnicast = 0x1a0,
282 NvRegTxMulticast = 0x1a4,
283 NvRegTxBroadcast = 0x1a8,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 NvRegWakeUpFlags = 0x200,
285#define NVREG_WAKEUPFLAGS_VAL 0x7770
286#define NVREG_WAKEUPFLAGS_BUSYSHIFT 24
287#define NVREG_WAKEUPFLAGS_ENABLESHIFT 16
288#define NVREG_WAKEUPFLAGS_D3SHIFT 12
289#define NVREG_WAKEUPFLAGS_D2SHIFT 8
290#define NVREG_WAKEUPFLAGS_D1SHIFT 4
291#define NVREG_WAKEUPFLAGS_D0SHIFT 0
292#define NVREG_WAKEUPFLAGS_ACCEPT_MAGPAT 0x01
293#define NVREG_WAKEUPFLAGS_ACCEPT_WAKEUPPAT 0x02
294#define NVREG_WAKEUPFLAGS_ACCEPT_LINKCHANGE 0x04
295#define NVREG_WAKEUPFLAGS_ENABLE 0x1111
296
Ayaz Abdullacac1c522009-02-07 00:23:57 -0800297 NvRegMgmtUnitGetVersion = 0x204,
Szymon Janc78aea4f2010-11-27 08:39:43 +0000298#define NVREG_MGMTUNITGETVERSION 0x01
Ayaz Abdullacac1c522009-02-07 00:23:57 -0800299 NvRegMgmtUnitVersion = 0x208,
300#define NVREG_MGMTUNITVERSION 0x08
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 NvRegPowerCap = 0x268,
302#define NVREG_POWERCAP_D3SUPP (1<<30)
303#define NVREG_POWERCAP_D2SUPP (1<<26)
304#define NVREG_POWERCAP_D1SUPP (1<<25)
305 NvRegPowerState = 0x26c,
306#define NVREG_POWERSTATE_POWEREDUP 0x8000
307#define NVREG_POWERSTATE_VALID 0x0100
308#define NVREG_POWERSTATE_MASK 0x0003
309#define NVREG_POWERSTATE_D0 0x0000
310#define NVREG_POWERSTATE_D1 0x0001
311#define NVREG_POWERSTATE_D2 0x0002
312#define NVREG_POWERSTATE_D3 0x0003
Ayaz Abdullacac1c522009-02-07 00:23:57 -0800313 NvRegMgmtUnitControl = 0x278,
314#define NVREG_MGMTUNITCONTROL_INUSE 0x20000
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400315 NvRegTxCnt = 0x280,
316 NvRegTxZeroReXmt = 0x284,
317 NvRegTxOneReXmt = 0x288,
318 NvRegTxManyReXmt = 0x28c,
319 NvRegTxLateCol = 0x290,
320 NvRegTxUnderflow = 0x294,
321 NvRegTxLossCarrier = 0x298,
322 NvRegTxExcessDef = 0x29c,
323 NvRegTxRetryErr = 0x2a0,
324 NvRegRxFrameErr = 0x2a4,
325 NvRegRxExtraByte = 0x2a8,
326 NvRegRxLateCol = 0x2ac,
327 NvRegRxRunt = 0x2b0,
328 NvRegRxFrameTooLong = 0x2b4,
329 NvRegRxOverflow = 0x2b8,
330 NvRegRxFCSErr = 0x2bc,
331 NvRegRxFrameAlignErr = 0x2c0,
332 NvRegRxLenErr = 0x2c4,
333 NvRegRxUnicast = 0x2c8,
334 NvRegRxMulticast = 0x2cc,
335 NvRegRxBroadcast = 0x2d0,
336 NvRegTxDef = 0x2d4,
337 NvRegTxFrame = 0x2d8,
338 NvRegRxCnt = 0x2dc,
339 NvRegTxPause = 0x2e0,
340 NvRegRxPause = 0x2e4,
341 NvRegRxDropFrame = 0x2e8,
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500342 NvRegVlanControl = 0x300,
343#define NVREG_VLANCONTROL_ENABLE 0x2000
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500344 NvRegMSIXMap0 = 0x3e0,
345 NvRegMSIXMap1 = 0x3e4,
346 NvRegMSIXIrqStatus = 0x3f0,
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400347
348 NvRegPowerState2 = 0x600,
Ayaz Abdulla1545e202008-09-22 09:55:35 -0400349#define NVREG_POWERSTATE2_POWERUP_MASK 0x0F15
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400350#define NVREG_POWERSTATE2_POWERUP_REV_A3 0x0001
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -0400351#define NVREG_POWERSTATE2_PHY_RESET 0x0004
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +0000352#define NVREG_POWERSTATE2_GATE_CLOCKS 0x0F00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353};
354
355/* Big endian: should work, but is untested */
356struct ring_desc {
Stephen Hemmingera8bed492006-07-27 18:50:09 -0700357 __le32 buf;
358 __le32 flaglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359};
360
Manfred Spraulee733622005-07-31 18:32:26 +0200361struct ring_desc_ex {
Stephen Hemmingera8bed492006-07-27 18:50:09 -0700362 __le32 bufhigh;
363 __le32 buflow;
364 __le32 txvlan;
365 __le32 flaglen;
Manfred Spraulee733622005-07-31 18:32:26 +0200366};
367
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700368union ring_type {
Szymon Janc78aea4f2010-11-27 08:39:43 +0000369 struct ring_desc *orig;
370 struct ring_desc_ex *ex;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700371};
Manfred Spraulee733622005-07-31 18:32:26 +0200372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373#define FLAG_MASK_V1 0xffff0000
374#define FLAG_MASK_V2 0xffffc000
375#define LEN_MASK_V1 (0xffffffff ^ FLAG_MASK_V1)
376#define LEN_MASK_V2 (0xffffffff ^ FLAG_MASK_V2)
377
378#define NV_TX_LASTPACKET (1<<16)
379#define NV_TX_RETRYERROR (1<<19)
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700380#define NV_TX_RETRYCOUNT_MASK (0xF<<20)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200381#define NV_TX_FORCED_INTERRUPT (1<<24)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382#define NV_TX_DEFERRED (1<<26)
383#define NV_TX_CARRIERLOST (1<<27)
384#define NV_TX_LATECOLLISION (1<<28)
385#define NV_TX_UNDERFLOW (1<<29)
386#define NV_TX_ERROR (1<<30)
387#define NV_TX_VALID (1<<31)
388
389#define NV_TX2_LASTPACKET (1<<29)
390#define NV_TX2_RETRYERROR (1<<18)
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700391#define NV_TX2_RETRYCOUNT_MASK (0xF<<19)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200392#define NV_TX2_FORCED_INTERRUPT (1<<30)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393#define NV_TX2_DEFERRED (1<<25)
394#define NV_TX2_CARRIERLOST (1<<26)
395#define NV_TX2_LATECOLLISION (1<<27)
396#define NV_TX2_UNDERFLOW (1<<28)
397/* error and valid are the same for both */
398#define NV_TX2_ERROR (1<<30)
399#define NV_TX2_VALID (1<<31)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400400#define NV_TX2_TSO (1<<28)
401#define NV_TX2_TSO_SHIFT 14
Ayaz Abdullafa454592006-01-05 22:45:45 -0800402#define NV_TX2_TSO_MAX_SHIFT 14
403#define NV_TX2_TSO_MAX_SIZE (1<<NV_TX2_TSO_MAX_SHIFT)
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400404#define NV_TX2_CHECKSUM_L3 (1<<27)
405#define NV_TX2_CHECKSUM_L4 (1<<26)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500407#define NV_TX3_VLAN_TAG_PRESENT (1<<18)
408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409#define NV_RX_DESCRIPTORVALID (1<<16)
410#define NV_RX_MISSEDFRAME (1<<17)
411#define NV_RX_SUBSTRACT1 (1<<18)
412#define NV_RX_ERROR1 (1<<23)
413#define NV_RX_ERROR2 (1<<24)
414#define NV_RX_ERROR3 (1<<25)
415#define NV_RX_ERROR4 (1<<26)
416#define NV_RX_CRCERR (1<<27)
417#define NV_RX_OVERFLOW (1<<28)
418#define NV_RX_FRAMINGERR (1<<29)
419#define NV_RX_ERROR (1<<30)
420#define NV_RX_AVAIL (1<<31)
Ayaz Abdulla1ef68412008-08-06 12:11:03 -0400421#define NV_RX_ERROR_MASK (NV_RX_ERROR1|NV_RX_ERROR2|NV_RX_ERROR3|NV_RX_ERROR4|NV_RX_CRCERR|NV_RX_OVERFLOW|NV_RX_FRAMINGERR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423#define NV_RX2_CHECKSUMMASK (0x1C000000)
Ayaz Abdullabfaffe82008-01-13 16:02:55 -0500424#define NV_RX2_CHECKSUM_IP (0x10000000)
425#define NV_RX2_CHECKSUM_IP_TCP (0x14000000)
426#define NV_RX2_CHECKSUM_IP_UDP (0x18000000)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427#define NV_RX2_DESCRIPTORVALID (1<<29)
428#define NV_RX2_SUBSTRACT1 (1<<25)
429#define NV_RX2_ERROR1 (1<<18)
430#define NV_RX2_ERROR2 (1<<19)
431#define NV_RX2_ERROR3 (1<<20)
432#define NV_RX2_ERROR4 (1<<21)
433#define NV_RX2_CRCERR (1<<22)
434#define NV_RX2_OVERFLOW (1<<23)
435#define NV_RX2_FRAMINGERR (1<<24)
436/* error and avail are the same for both */
437#define NV_RX2_ERROR (1<<30)
438#define NV_RX2_AVAIL (1<<31)
Ayaz Abdulla1ef68412008-08-06 12:11:03 -0400439#define NV_RX2_ERROR_MASK (NV_RX2_ERROR1|NV_RX2_ERROR2|NV_RX2_ERROR3|NV_RX2_ERROR4|NV_RX2_CRCERR|NV_RX2_OVERFLOW|NV_RX2_FRAMINGERR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500441#define NV_RX3_VLAN_TAG_PRESENT (1<<16)
442#define NV_RX3_VLAN_TAG_MASK (0x0000FFFF)
443
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300444/* Miscellaneous hardware related defines: */
Szymon Janc78aea4f2010-11-27 08:39:43 +0000445#define NV_PCI_REGSZ_VER1 0x270
446#define NV_PCI_REGSZ_VER2 0x2d4
447#define NV_PCI_REGSZ_VER3 0x604
448#define NV_PCI_REGSZ_MAX 0x604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450/* various timeout delays: all in usec */
451#define NV_TXRX_RESET_DELAY 4
452#define NV_TXSTOP_DELAY1 10
453#define NV_TXSTOP_DELAY1MAX 500000
454#define NV_TXSTOP_DELAY2 100
455#define NV_RXSTOP_DELAY1 10
456#define NV_RXSTOP_DELAY1MAX 500000
457#define NV_RXSTOP_DELAY2 100
458#define NV_SETUP5_DELAY 5
459#define NV_SETUP5_DELAYMAX 50000
460#define NV_POWERUP_DELAY 5
461#define NV_POWERUP_DELAYMAX 5000
462#define NV_MIIBUSY_DELAY 50
463#define NV_MIIPHY_DELAY 10
464#define NV_MIIPHY_DELAYMAX 10000
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400465#define NV_MAC_RESET_DELAY 64
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
467#define NV_WAKEUPPATTERNS 5
468#define NV_WAKEUPMASKENTRIES 4
469
470/* General driver defaults */
471#define NV_WATCHDOG_TIMEO (5*HZ)
472
Ayaz Abdulla6cef67a2009-03-05 08:02:30 +0000473#define RX_RING_DEFAULT 512
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400474#define TX_RING_DEFAULT 256
475#define RX_RING_MIN 128
476#define TX_RING_MIN 64
477#define RING_MAX_DESC_VER_1 1024
478#define RING_MAX_DESC_VER_2_3 16384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
480/* rx/tx mac addr + type + vlan + align + slack*/
Manfred Sprauld81c0982005-07-31 18:20:30 +0200481#define NV_RX_HEADERS (64)
482/* even more slack. */
483#define NV_RX_ALLOC_PAD (64)
484
485/* maximum mtu size */
486#define NV_PKTLIMIT_1 ETH_DATA_LEN /* hard limit not known */
487#define NV_PKTLIMIT_2 9100 /* Actual limit according to NVidia: 9202 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
489#define OOM_REFILL (1+HZ/20)
490#define POLL_WAIT (1+HZ/100)
491#define LINK_TIMEOUT (3*HZ)
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400492#define STATS_INTERVAL (10*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400494/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 * desc_ver values:
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400496 * The nic supports three different descriptor types:
497 * - DESC_VER_1: Original
498 * - DESC_VER_2: support for jumbo frames.
499 * - DESC_VER_3: 64-bit format.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 */
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400501#define DESC_VER_1 1
502#define DESC_VER_2 2
503#define DESC_VER_3 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
505/* PHY defines */
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400506#define PHY_OUI_MARVELL 0x5043
507#define PHY_OUI_CICADA 0x03f1
508#define PHY_OUI_VITESSE 0x01c1
509#define PHY_OUI_REALTEK 0x0732
510#define PHY_OUI_REALTEK2 0x0020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511#define PHYID1_OUI_MASK 0x03ff
512#define PHYID1_OUI_SHFT 6
513#define PHYID2_OUI_MASK 0xfc00
514#define PHYID2_OUI_SHFT 10
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -0400515#define PHYID2_MODEL_MASK 0x03f0
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400516#define PHY_MODEL_REALTEK_8211 0x0110
517#define PHY_REV_MASK 0x0001
518#define PHY_REV_REALTEK_8211B 0x0000
519#define PHY_REV_REALTEK_8211C 0x0001
520#define PHY_MODEL_REALTEK_8201 0x0200
521#define PHY_MODEL_MARVELL_E3016 0x0220
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -0400522#define PHY_MARVELL_E3016_INITMASK 0x0300
Ayaz Abdulla14a67f32007-07-15 06:50:28 -0400523#define PHY_CICADA_INIT1 0x0f000
524#define PHY_CICADA_INIT2 0x0e00
525#define PHY_CICADA_INIT3 0x01000
526#define PHY_CICADA_INIT4 0x0200
527#define PHY_CICADA_INIT5 0x0004
528#define PHY_CICADA_INIT6 0x02000
Ayaz Abdullad215d8a2007-07-15 06:50:53 -0400529#define PHY_VITESSE_INIT_REG1 0x1f
530#define PHY_VITESSE_INIT_REG2 0x10
531#define PHY_VITESSE_INIT_REG3 0x11
532#define PHY_VITESSE_INIT_REG4 0x12
533#define PHY_VITESSE_INIT_MSK1 0xc
534#define PHY_VITESSE_INIT_MSK2 0x0180
535#define PHY_VITESSE_INIT1 0x52b5
536#define PHY_VITESSE_INIT2 0xaf8a
537#define PHY_VITESSE_INIT3 0x8
538#define PHY_VITESSE_INIT4 0x8f8a
539#define PHY_VITESSE_INIT5 0xaf86
540#define PHY_VITESSE_INIT6 0x8f86
541#define PHY_VITESSE_INIT7 0xaf82
542#define PHY_VITESSE_INIT8 0x0100
543#define PHY_VITESSE_INIT9 0x8f82
544#define PHY_VITESSE_INIT10 0x0
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -0400545#define PHY_REALTEK_INIT_REG1 0x1f
546#define PHY_REALTEK_INIT_REG2 0x19
547#define PHY_REALTEK_INIT_REG3 0x13
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400548#define PHY_REALTEK_INIT_REG4 0x14
549#define PHY_REALTEK_INIT_REG5 0x18
550#define PHY_REALTEK_INIT_REG6 0x11
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -0400551#define PHY_REALTEK_INIT_REG7 0x01
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -0400552#define PHY_REALTEK_INIT1 0x0000
553#define PHY_REALTEK_INIT2 0x8e00
554#define PHY_REALTEK_INIT3 0x0001
555#define PHY_REALTEK_INIT4 0xad17
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400556#define PHY_REALTEK_INIT5 0xfb54
557#define PHY_REALTEK_INIT6 0xf5c7
558#define PHY_REALTEK_INIT7 0x1000
559#define PHY_REALTEK_INIT8 0x0003
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -0400560#define PHY_REALTEK_INIT9 0x0008
561#define PHY_REALTEK_INIT10 0x0005
562#define PHY_REALTEK_INIT11 0x0200
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400563#define PHY_REALTEK_INIT_MSK1 0x0003
Ayaz Abdullad215d8a2007-07-15 06:50:53 -0400564
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#define PHY_GIGABIT 0x0100
566
567#define PHY_TIMEOUT 0x1
568#define PHY_ERROR 0x2
569
570#define PHY_100 0x1
571#define PHY_1000 0x2
572#define PHY_HALF 0x100
573
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400574#define NV_PAUSEFRAME_RX_CAPABLE 0x0001
575#define NV_PAUSEFRAME_TX_CAPABLE 0x0002
576#define NV_PAUSEFRAME_RX_ENABLE 0x0004
577#define NV_PAUSEFRAME_TX_ENABLE 0x0008
Ayaz Abdullab6d07732006-06-10 22:47:42 -0400578#define NV_PAUSEFRAME_RX_REQ 0x0010
579#define NV_PAUSEFRAME_TX_REQ 0x0020
580#define NV_PAUSEFRAME_AUTONEG 0x0040
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500582/* MSI/MSI-X defines */
583#define NV_MSI_X_MAX_VECTORS 8
584#define NV_MSI_X_VECTORS_MASK 0x000f
585#define NV_MSI_CAPABLE 0x0010
586#define NV_MSI_X_CAPABLE 0x0020
587#define NV_MSI_ENABLED 0x0040
588#define NV_MSI_X_ENABLED 0x0080
589
590#define NV_MSI_X_VECTOR_ALL 0x0
591#define NV_MSI_X_VECTOR_RX 0x0
592#define NV_MSI_X_VECTOR_TX 0x1
593#define NV_MSI_X_VECTOR_OTHER 0x2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Ayaz Abdullab6e44052009-02-07 00:24:15 -0800595#define NV_MSI_PRIV_OFFSET 0x68
596#define NV_MSI_PRIV_VALUE 0xffffffff
597
Ayaz Abdullab2976d22008-02-04 15:13:59 -0500598#define NV_RESTART_TX 0x1
599#define NV_RESTART_RX 0x2
600
Ayaz Abdulla3b446c32008-03-10 14:58:21 -0500601#define NV_TX_LIMIT_COUNT 16
602
Ayaz Abdulla4145ade2009-03-05 08:02:26 +0000603#define NV_DYNAMIC_THRESHOLD 4
604#define NV_DYNAMIC_MAX_QUIET_COUNT 2048
605
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400606/* statistics */
607struct nv_ethtool_str {
608 char name[ETH_GSTRING_LEN];
609};
610
611static const struct nv_ethtool_str nv_estats_str[] = {
david decotigny674aee32011-11-16 12:15:07 +0000612 { "tx_bytes" }, /* includes Ethernet FCS CRC */
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400613 { "tx_zero_rexmt" },
614 { "tx_one_rexmt" },
615 { "tx_many_rexmt" },
616 { "tx_late_collision" },
617 { "tx_fifo_errors" },
618 { "tx_carrier_errors" },
619 { "tx_excess_deferral" },
620 { "tx_retry_error" },
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400621 { "rx_frame_error" },
622 { "rx_extra_byte" },
623 { "rx_late_collision" },
624 { "rx_runt" },
625 { "rx_frame_too_long" },
626 { "rx_over_errors" },
627 { "rx_crc_errors" },
628 { "rx_frame_align_error" },
629 { "rx_length_error" },
630 { "rx_unicast" },
631 { "rx_multicast" },
632 { "rx_broadcast" },
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400633 { "rx_packets" },
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500634 { "rx_errors_total" },
635 { "tx_errors_total" },
636
637 /* version 2 stats */
638 { "tx_deferral" },
639 { "tx_packets" },
david decotigny674aee32011-11-16 12:15:07 +0000640 { "rx_bytes" }, /* includes Ethernet FCS CRC */
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500641 { "tx_pause" },
642 { "rx_pause" },
Ayaz Abdulla9c662432008-08-06 12:11:42 -0400643 { "rx_drop_frame" },
644
645 /* version 3 stats */
646 { "tx_unicast" },
647 { "tx_multicast" },
648 { "tx_broadcast" }
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400649};
650
651struct nv_ethtool_stats {
david decotigny674aee32011-11-16 12:15:07 +0000652 u64 tx_bytes; /* should be ifconfig->tx_bytes + 4*tx_packets */
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400653 u64 tx_zero_rexmt;
654 u64 tx_one_rexmt;
655 u64 tx_many_rexmt;
656 u64 tx_late_collision;
657 u64 tx_fifo_errors;
658 u64 tx_carrier_errors;
659 u64 tx_excess_deferral;
660 u64 tx_retry_error;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400661 u64 rx_frame_error;
662 u64 rx_extra_byte;
663 u64 rx_late_collision;
664 u64 rx_runt;
665 u64 rx_frame_too_long;
666 u64 rx_over_errors;
667 u64 rx_crc_errors;
668 u64 rx_frame_align_error;
669 u64 rx_length_error;
670 u64 rx_unicast;
671 u64 rx_multicast;
672 u64 rx_broadcast;
david decotigny674aee32011-11-16 12:15:07 +0000673 u64 rx_packets; /* should be ifconfig->rx_packets */
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400674 u64 rx_errors_total;
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500675 u64 tx_errors_total;
676
677 /* version 2 stats */
678 u64 tx_deferral;
david decotigny674aee32011-11-16 12:15:07 +0000679 u64 tx_packets; /* should be ifconfig->tx_packets */
680 u64 rx_bytes; /* should be ifconfig->rx_bytes + 4*rx_packets */
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500681 u64 tx_pause;
682 u64 rx_pause;
683 u64 rx_drop_frame;
Ayaz Abdulla9c662432008-08-06 12:11:42 -0400684
685 /* version 3 stats */
686 u64 tx_unicast;
687 u64 tx_multicast;
688 u64 tx_broadcast;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400689};
690
Ayaz Abdulla9c662432008-08-06 12:11:42 -0400691#define NV_DEV_STATISTICS_V3_COUNT (sizeof(struct nv_ethtool_stats)/sizeof(u64))
692#define NV_DEV_STATISTICS_V2_COUNT (NV_DEV_STATISTICS_V3_COUNT - 3)
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500693#define NV_DEV_STATISTICS_V1_COUNT (NV_DEV_STATISTICS_V2_COUNT - 6)
694
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400695/* diagnostics */
696#define NV_TEST_COUNT_BASE 3
697#define NV_TEST_COUNT_EXTENDED 4
698
699static const struct nv_ethtool_str nv_etests_str[] = {
700 { "link (online/offline)" },
701 { "register (offline) " },
702 { "interrupt (offline) " },
703 { "loopback (offline) " }
704};
705
706struct register_test {
Al Viro5bb7ea22007-12-09 16:06:41 +0000707 __u32 reg;
708 __u32 mask;
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400709};
710
711static const struct register_test nv_registers_test[] = {
712 { NvRegUnknownSetupReg6, 0x01 },
713 { NvRegMisc1, 0x03c },
714 { NvRegOffloadConfig, 0x03ff },
715 { NvRegMulticastAddrA, 0xffffffff },
Ayaz Abdulla95d161c2006-07-06 16:46:25 -0400716 { NvRegTxWatermark, 0x0ff },
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400717 { NvRegWakeUpFlags, 0x07777 },
Szymon Janc78aea4f2010-11-27 08:39:43 +0000718 { 0, 0 }
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400719};
720
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500721struct nv_skb_map {
722 struct sk_buff *skb;
723 dma_addr_t dma;
Eric Dumazet73a37072009-06-17 21:17:59 +0000724 unsigned int dma_len:31;
725 unsigned int dma_single:1;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -0500726 struct ring_desc_ex *first_tx_desc;
727 struct nv_skb_map *next_tx_ctx;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500728};
729
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730/*
731 * SMP locking:
Wang Chenb74ca3a2008-12-08 01:14:16 -0800732 * All hardware access under netdev_priv(dev)->lock, except the performance
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 * critical parts:
734 * - rx is (pseudo-) lockless: it relies on the single-threading provided
735 * by the arch code for interrupts.
Herbert Xu932ff272006-06-09 12:20:56 -0700736 * - tx setup is lockless: it relies on netif_tx_lock. Actual submission
Wang Chenb74ca3a2008-12-08 01:14:16 -0800737 * needs netdev_priv(dev)->lock :-(
Herbert Xu932ff272006-06-09 12:20:56 -0700738 * - set_multicast_list: preparation lockless, relies on netif_tx_lock.
david decotignyf5d827a2011-11-16 12:15:13 +0000739 *
740 * Hardware stats updates are protected by hwstats_lock:
741 * - updated by nv_do_stats_poll (timer). This is meant to avoid
742 * integer wraparound in the NIC stats registers, at low frequency
743 * (0.1 Hz)
744 * - updated by nv_get_ethtool_stats + nv_get_stats64
745 *
746 * Software stats are accessed only through 64b synchronization points
747 * and are not subject to other synchronization techniques (single
748 * update thread on the TX or RX paths).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 */
750
751/* in dev: base, irq */
752struct fe_priv {
753 spinlock_t lock;
754
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700755 struct net_device *dev;
756 struct napi_struct napi;
757
david decotignyf5d827a2011-11-16 12:15:13 +0000758 /* hardware stats are updated in syscall and timer */
759 spinlock_t hwstats_lock;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400760 struct nv_ethtool_stats estats;
david decotignyf5d827a2011-11-16 12:15:13 +0000761
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 int in_shutdown;
763 u32 linkspeed;
764 int duplex;
765 int autoneg;
766 int fixed_mode;
767 int phyaddr;
768 int wolenabled;
769 unsigned int phy_oui;
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -0400770 unsigned int phy_model;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400771 unsigned int phy_rev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 u16 gigabit;
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400773 int intr_test;
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500774 int recover_error;
Ayaz Abdulla4145ade2009-03-05 08:02:26 +0000775 int quiet_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
777 /* General data: RO fields */
778 dma_addr_t ring_addr;
779 struct pci_dev *pci_dev;
780 u32 orig_mac[2];
Ayaz Abdulla582806b2009-03-05 08:02:03 +0000781 u32 events;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 u32 irqmask;
783 u32 desc_ver;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400784 u32 txrxctl_bits;
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500785 u32 vlanctl_bits;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400786 u32 driver_data;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400787 u32 device_id;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400788 u32 register_size;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500789 u32 mac_in_use;
Ayaz Abdullacac1c522009-02-07 00:23:57 -0800790 int mgmt_version;
791 int mgmt_sema;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
793 void __iomem *base;
794
795 /* rx specific fields.
796 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
797 */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500798 union ring_type get_rx, put_rx, first_rx, last_rx;
799 struct nv_skb_map *get_rx_ctx, *put_rx_ctx;
800 struct nv_skb_map *first_rx_ctx, *last_rx_ctx;
801 struct nv_skb_map *rx_skb;
802
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700803 union ring_type rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 unsigned int rx_buf_sz;
Manfred Sprauld81c0982005-07-31 18:20:30 +0200805 unsigned int pkt_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 struct timer_list oom_kick;
807 struct timer_list nic_poll;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400808 struct timer_list stats_poll;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500809 u32 nic_poll_irq;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400810 int rx_ring_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
david decotignyf5d827a2011-11-16 12:15:13 +0000812 /* RX software stats */
813 struct u64_stats_sync swstats_rx_syncp;
814 u64 stat_rx_packets;
815 u64 stat_rx_bytes; /* not always available in HW */
816 u64 stat_rx_missed_errors;
david decotigny0a1f2222011-11-16 12:15:14 +0000817 u64 stat_rx_dropped;
david decotignyf5d827a2011-11-16 12:15:13 +0000818
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 /* media detection workaround.
820 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
821 */
822 int need_linktimer;
823 unsigned long link_timeout;
824 /*
825 * tx specific fields.
826 */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500827 union ring_type get_tx, put_tx, first_tx, last_tx;
828 struct nv_skb_map *get_tx_ctx, *put_tx_ctx;
829 struct nv_skb_map *first_tx_ctx, *last_tx_ctx;
830 struct nv_skb_map *tx_skb;
831
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700832 union ring_type tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 u32 tx_flags;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400834 int tx_ring_size;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -0500835 int tx_limit;
836 u32 tx_pkts_in_progress;
837 struct nv_skb_map *tx_change_owner;
838 struct nv_skb_map *tx_end_flip;
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -0500839 int tx_stop;
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500840
david decotignyf5d827a2011-11-16 12:15:13 +0000841 /* TX software stats */
842 struct u64_stats_sync swstats_tx_syncp;
843 u64 stat_tx_packets; /* not always available in HW */
844 u64 stat_tx_bytes;
845 u64 stat_tx_dropped;
846
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500847 /* msi/msi-x fields */
848 u32 msi_flags;
849 struct msix_entry msi_x_entry[NV_MSI_X_MAX_VECTORS];
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400850
851 /* flow control */
852 u32 pause_flags;
Tobias Diedrich1a1ca862008-05-18 15:03:44 +0200853
854 /* power saved state */
855 u32 saved_config_space[NV_PCI_REGSZ_MAX/4];
Yinghai Luddb213f2009-02-06 01:29:23 -0800856
857 /* for different msi-x irq type */
858 char name_rx[IFNAMSIZ + 3]; /* -rx */
859 char name_tx[IFNAMSIZ + 3]; /* -tx */
860 char name_other[IFNAMSIZ + 6]; /* -other */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861};
862
863/*
864 * Maximum number of loops until we assume that a bit in the irq mask
865 * is stuck. Overridable with module param.
866 */
Ayaz Abdulla4145ade2009-03-05 08:02:26 +0000867static int max_interrupt_work = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500869/*
870 * Optimization can be either throuput mode or cpu mode
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400871 *
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500872 * Throughput Mode: Every tx and rx packet will generate an interrupt.
873 * CPU Mode: Interrupts are controlled by a timer.
874 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400875enum {
876 NV_OPTIMIZATION_MODE_THROUGHPUT,
Ayaz Abdulla9e184762009-03-05 08:02:18 +0000877 NV_OPTIMIZATION_MODE_CPU,
878 NV_OPTIMIZATION_MODE_DYNAMIC
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400879};
Ayaz Abdulla9e184762009-03-05 08:02:18 +0000880static int optimization_mode = NV_OPTIMIZATION_MODE_DYNAMIC;
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500881
882/*
883 * Poll interval for timer irq
884 *
885 * This interval determines how frequent an interrupt is generated.
886 * The is value is determined by [(time_in_micro_secs * 100) / (2^10)]
887 * Min = 0, and Max = 65535
888 */
889static int poll_interval = -1;
890
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500891/*
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400892 * MSI interrupts
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500893 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400894enum {
895 NV_MSI_INT_DISABLED,
896 NV_MSI_INT_ENABLED
897};
898static int msi = NV_MSI_INT_ENABLED;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500899
900/*
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400901 * MSIX interrupts
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500902 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400903enum {
904 NV_MSIX_INT_DISABLED,
905 NV_MSIX_INT_ENABLED
906};
Yinghai Lu39482792009-02-06 01:31:12 -0800907static int msix = NV_MSIX_INT_ENABLED;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400908
909/*
910 * DMA 64bit
911 */
912enum {
913 NV_DMA_64BIT_DISABLED,
914 NV_DMA_64BIT_ENABLED
915};
916static int dma_64bit = NV_DMA_64BIT_ENABLED;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500917
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400918/*
Sameer Nanda1ec4f2d2011-11-16 12:15:12 +0000919 * Debug output control for tx_timeout
920 */
921static bool debug_tx_timeout = false;
922
923/*
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400924 * Crossover Detection
925 * Realtek 8201 phy + some OEM boards do not work properly.
926 */
927enum {
928 NV_CROSSOVER_DETECTION_DISABLED,
929 NV_CROSSOVER_DETECTION_ENABLED
930};
931static int phy_cross = NV_CROSSOVER_DETECTION_DISABLED;
932
Ed Swierk5a9a8e32009-06-02 00:19:52 -0700933/*
934 * Power down phy when interface is down (persists through reboot;
935 * older Linux and other OSes may not power it up again)
936 */
Szymon Janc78aea4f2010-11-27 08:39:43 +0000937static int phy_power_down;
Ed Swierk5a9a8e32009-06-02 00:19:52 -0700938
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939static inline struct fe_priv *get_nvpriv(struct net_device *dev)
940{
941 return netdev_priv(dev);
942}
943
944static inline u8 __iomem *get_hwbase(struct net_device *dev)
945{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400946 return ((struct fe_priv *)netdev_priv(dev))->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947}
948
949static inline void pci_push(u8 __iomem *base)
950{
951 /* force out pending posted writes */
952 readl(base);
953}
954
955static inline u32 nv_descr_getlength(struct ring_desc *prd, u32 v)
956{
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700957 return le32_to_cpu(prd->flaglen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 & ((v == DESC_VER_1) ? LEN_MASK_V1 : LEN_MASK_V2);
959}
960
Manfred Spraulee733622005-07-31 18:32:26 +0200961static inline u32 nv_descr_getlength_ex(struct ring_desc_ex *prd, u32 v)
962{
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700963 return le32_to_cpu(prd->flaglen) & LEN_MASK_V2;
Manfred Spraulee733622005-07-31 18:32:26 +0200964}
965
Jeff Garzik36b30ea2007-10-16 01:40:30 -0400966static bool nv_optimized(struct fe_priv *np)
967{
968 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
969 return false;
970 return true;
971}
972
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973static int reg_delay(struct net_device *dev, int offset, u32 mask, u32 target,
Joe Perches344d0dc2010-11-29 07:41:52 +0000974 int delay, int delaymax)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975{
976 u8 __iomem *base = get_hwbase(dev);
977
978 pci_push(base);
979 do {
980 udelay(delay);
981 delaymax -= delay;
Joe Perches344d0dc2010-11-29 07:41:52 +0000982 if (delaymax < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 } while ((readl(base + offset) & mask) != target);
985 return 0;
986}
987
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500988#define NV_SETUP_RX_RING 0x01
989#define NV_SETUP_TX_RING 0x02
990
Al Viro5bb7ea22007-12-09 16:06:41 +0000991static inline u32 dma_low(dma_addr_t addr)
992{
993 return addr;
994}
995
996static inline u32 dma_high(dma_addr_t addr)
997{
998 return addr>>31>>1; /* 0 if 32bit, shift down by 32 if 64bit */
999}
1000
Ayaz Abdulla0832b252006-02-04 13:13:26 -05001001static void setup_hw_rings(struct net_device *dev, int rxtx_flags)
1002{
1003 struct fe_priv *np = get_nvpriv(dev);
1004 u8 __iomem *base = get_hwbase(dev);
1005
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001006 if (!nv_optimized(np)) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00001007 if (rxtx_flags & NV_SETUP_RX_RING)
Al Viro5bb7ea22007-12-09 16:06:41 +00001008 writel(dma_low(np->ring_addr), base + NvRegRxRingPhysAddr);
Szymon Janc78aea4f2010-11-27 08:39:43 +00001009 if (rxtx_flags & NV_SETUP_TX_RING)
Al Viro5bb7ea22007-12-09 16:06:41 +00001010 writel(dma_low(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr);
Ayaz Abdulla0832b252006-02-04 13:13:26 -05001011 } else {
1012 if (rxtx_flags & NV_SETUP_RX_RING) {
Al Viro5bb7ea22007-12-09 16:06:41 +00001013 writel(dma_low(np->ring_addr), base + NvRegRxRingPhysAddr);
1014 writel(dma_high(np->ring_addr), base + NvRegRxRingPhysAddrHigh);
Ayaz Abdulla0832b252006-02-04 13:13:26 -05001015 }
1016 if (rxtx_flags & NV_SETUP_TX_RING) {
Al Viro5bb7ea22007-12-09 16:06:41 +00001017 writel(dma_low(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr);
1018 writel(dma_high(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddrHigh);
Ayaz Abdulla0832b252006-02-04 13:13:26 -05001019 }
1020 }
1021}
1022
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001023static void free_rings(struct net_device *dev)
1024{
1025 struct fe_priv *np = get_nvpriv(dev);
1026
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001027 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001028 if (np->rx_ring.orig)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001029 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
1030 np->rx_ring.orig, np->ring_addr);
1031 } else {
1032 if (np->rx_ring.ex)
1033 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
1034 np->rx_ring.ex, np->ring_addr);
1035 }
Szymon Janc9b03b062010-11-27 08:39:44 +00001036 kfree(np->rx_skb);
1037 kfree(np->tx_skb);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001038}
1039
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001040static int using_multi_irqs(struct net_device *dev)
1041{
1042 struct fe_priv *np = get_nvpriv(dev);
1043
1044 if (!(np->msi_flags & NV_MSI_X_ENABLED) ||
1045 ((np->msi_flags & NV_MSI_X_ENABLED) &&
1046 ((np->msi_flags & NV_MSI_X_VECTORS_MASK) == 0x1)))
1047 return 0;
1048 else
1049 return 1;
1050}
1051
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00001052static void nv_txrx_gate(struct net_device *dev, bool gate)
1053{
1054 struct fe_priv *np = get_nvpriv(dev);
1055 u8 __iomem *base = get_hwbase(dev);
1056 u32 powerstate;
1057
1058 if (!np->mac_in_use &&
1059 (np->driver_data & DEV_HAS_POWER_CNTRL)) {
1060 powerstate = readl(base + NvRegPowerState2);
1061 if (gate)
1062 powerstate |= NVREG_POWERSTATE2_GATE_CLOCKS;
1063 else
1064 powerstate &= ~NVREG_POWERSTATE2_GATE_CLOCKS;
1065 writel(powerstate, base + NvRegPowerState2);
1066 }
1067}
1068
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001069static void nv_enable_irq(struct net_device *dev)
1070{
1071 struct fe_priv *np = get_nvpriv(dev);
1072
1073 if (!using_multi_irqs(dev)) {
1074 if (np->msi_flags & NV_MSI_X_ENABLED)
1075 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1076 else
Manfred Spraula7475902007-10-17 21:52:33 +02001077 enable_irq(np->pci_dev->irq);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001078 } else {
1079 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1080 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
1081 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
1082 }
1083}
1084
1085static void nv_disable_irq(struct net_device *dev)
1086{
1087 struct fe_priv *np = get_nvpriv(dev);
1088
1089 if (!using_multi_irqs(dev)) {
1090 if (np->msi_flags & NV_MSI_X_ENABLED)
1091 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1092 else
Manfred Spraula7475902007-10-17 21:52:33 +02001093 disable_irq(np->pci_dev->irq);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001094 } else {
1095 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1096 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
1097 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
1098 }
1099}
1100
1101/* In MSIX mode, a write to irqmask behaves as XOR */
1102static void nv_enable_hw_interrupts(struct net_device *dev, u32 mask)
1103{
1104 u8 __iomem *base = get_hwbase(dev);
1105
1106 writel(mask, base + NvRegIrqMask);
1107}
1108
1109static void nv_disable_hw_interrupts(struct net_device *dev, u32 mask)
1110{
1111 struct fe_priv *np = get_nvpriv(dev);
1112 u8 __iomem *base = get_hwbase(dev);
1113
1114 if (np->msi_flags & NV_MSI_X_ENABLED) {
1115 writel(mask, base + NvRegIrqMask);
1116 } else {
1117 if (np->msi_flags & NV_MSI_ENABLED)
1118 writel(0, base + NvRegMSIIrqMask);
1119 writel(0, base + NvRegIrqMask);
1120 }
1121}
1122
Ayaz Abdulla08d93572009-03-05 08:01:55 +00001123static void nv_napi_enable(struct net_device *dev)
1124{
Ayaz Abdulla08d93572009-03-05 08:01:55 +00001125 struct fe_priv *np = get_nvpriv(dev);
1126
1127 napi_enable(&np->napi);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00001128}
1129
1130static void nv_napi_disable(struct net_device *dev)
1131{
Ayaz Abdulla08d93572009-03-05 08:01:55 +00001132 struct fe_priv *np = get_nvpriv(dev);
1133
1134 napi_disable(&np->napi);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00001135}
1136
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137#define MII_READ (-1)
1138/* mii_rw: read/write a register on the PHY.
1139 *
1140 * Caller must guarantee serialization
1141 */
1142static int mii_rw(struct net_device *dev, int addr, int miireg, int value)
1143{
1144 u8 __iomem *base = get_hwbase(dev);
1145 u32 reg;
1146 int retval;
1147
Ayaz Abdullaeb798422008-02-04 15:14:04 -05001148 writel(NVREG_MIISTAT_MASK_RW, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
1150 reg = readl(base + NvRegMIIControl);
1151 if (reg & NVREG_MIICTL_INUSE) {
1152 writel(NVREG_MIICTL_INUSE, base + NvRegMIIControl);
1153 udelay(NV_MIIBUSY_DELAY);
1154 }
1155
1156 reg = (addr << NVREG_MIICTL_ADDRSHIFT) | miireg;
1157 if (value != MII_READ) {
1158 writel(value, base + NvRegMIIData);
1159 reg |= NVREG_MIICTL_WRITE;
1160 }
1161 writel(reg, base + NvRegMIIControl);
1162
1163 if (reg_delay(dev, NvRegMIIControl, NVREG_MIICTL_INUSE, 0,
Joe Perches344d0dc2010-11-29 07:41:52 +00001164 NV_MIIPHY_DELAY, NV_MIIPHY_DELAYMAX)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 retval = -1;
1166 } else if (value != MII_READ) {
1167 /* it was a write operation - fewer failures are detectable */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 retval = 0;
1169 } else if (readl(base + NvRegMIIStatus) & NVREG_MIISTAT_ERROR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 retval = -1;
1171 } else {
1172 retval = readl(base + NvRegMIIData);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 }
1174
1175 return retval;
1176}
1177
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001178static int phy_reset(struct net_device *dev, u32 bmcr_setup)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001180 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 u32 miicontrol;
1182 unsigned int tries = 0;
1183
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001184 miicontrol = BMCR_RESET | bmcr_setup;
Szymon Janc78aea4f2010-11-27 08:39:43 +00001185 if (mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
1188 /* wait for 500ms */
1189 msleep(500);
1190
1191 /* must wait till reset is deasserted */
1192 while (miicontrol & BMCR_RESET) {
Szymon Jancde855b92010-11-27 08:39:48 +00001193 usleep_range(10000, 20000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1195 /* FIXME: 100 tries seem excessive */
1196 if (tries++ > 100)
1197 return -1;
1198 }
1199 return 0;
1200}
1201
Joe Perchesc41d41e2010-11-29 07:41:58 +00001202static int init_realtek_8211b(struct net_device *dev, struct fe_priv *np)
1203{
1204 static const struct {
1205 int reg;
1206 int init;
1207 } ri[] = {
1208 { PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1 },
1209 { PHY_REALTEK_INIT_REG2, PHY_REALTEK_INIT2 },
1210 { PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3 },
1211 { PHY_REALTEK_INIT_REG3, PHY_REALTEK_INIT4 },
1212 { PHY_REALTEK_INIT_REG4, PHY_REALTEK_INIT5 },
1213 { PHY_REALTEK_INIT_REG5, PHY_REALTEK_INIT6 },
1214 { PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1 },
1215 };
1216 int i;
1217
1218 for (i = 0; i < ARRAY_SIZE(ri); i++) {
Joe Perchescd663282010-11-29 07:41:59 +00001219 if (mii_rw(dev, np->phyaddr, ri[i].reg, ri[i].init))
Joe Perchesc41d41e2010-11-29 07:41:58 +00001220 return PHY_ERROR;
Joe Perchesc41d41e2010-11-29 07:41:58 +00001221 }
1222
1223 return 0;
1224}
1225
Joe Perchescd663282010-11-29 07:41:59 +00001226static int init_realtek_8211c(struct net_device *dev, struct fe_priv *np)
1227{
1228 u32 reg;
1229 u8 __iomem *base = get_hwbase(dev);
1230 u32 powerstate = readl(base + NvRegPowerState2);
1231
1232 /* need to perform hw phy reset */
1233 powerstate |= NVREG_POWERSTATE2_PHY_RESET;
1234 writel(powerstate, base + NvRegPowerState2);
1235 msleep(25);
1236
1237 powerstate &= ~NVREG_POWERSTATE2_PHY_RESET;
1238 writel(powerstate, base + NvRegPowerState2);
1239 msleep(25);
1240
1241 reg = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, MII_READ);
1242 reg |= PHY_REALTEK_INIT9;
1243 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, reg))
1244 return PHY_ERROR;
1245 if (mii_rw(dev, np->phyaddr,
1246 PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT10))
1247 return PHY_ERROR;
1248 reg = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG7, MII_READ);
1249 if (!(reg & PHY_REALTEK_INIT11)) {
1250 reg |= PHY_REALTEK_INIT11;
1251 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG7, reg))
1252 return PHY_ERROR;
1253 }
1254 if (mii_rw(dev, np->phyaddr,
1255 PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1))
1256 return PHY_ERROR;
1257
1258 return 0;
1259}
1260
1261static int init_realtek_8201(struct net_device *dev, struct fe_priv *np)
1262{
1263 u32 phy_reserved;
1264
1265 if (np->driver_data & DEV_NEED_PHY_INIT_FIX) {
1266 phy_reserved = mii_rw(dev, np->phyaddr,
1267 PHY_REALTEK_INIT_REG6, MII_READ);
1268 phy_reserved |= PHY_REALTEK_INIT7;
1269 if (mii_rw(dev, np->phyaddr,
1270 PHY_REALTEK_INIT_REG6, phy_reserved))
1271 return PHY_ERROR;
1272 }
1273
1274 return 0;
1275}
1276
1277static int init_realtek_8201_cross(struct net_device *dev, struct fe_priv *np)
1278{
1279 u32 phy_reserved;
1280
1281 if (phy_cross == NV_CROSSOVER_DETECTION_DISABLED) {
1282 if (mii_rw(dev, np->phyaddr,
1283 PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3))
1284 return PHY_ERROR;
1285 phy_reserved = mii_rw(dev, np->phyaddr,
1286 PHY_REALTEK_INIT_REG2, MII_READ);
1287 phy_reserved &= ~PHY_REALTEK_INIT_MSK1;
1288 phy_reserved |= PHY_REALTEK_INIT3;
1289 if (mii_rw(dev, np->phyaddr,
1290 PHY_REALTEK_INIT_REG2, phy_reserved))
1291 return PHY_ERROR;
1292 if (mii_rw(dev, np->phyaddr,
1293 PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1))
1294 return PHY_ERROR;
1295 }
1296
1297 return 0;
1298}
1299
1300static int init_cicada(struct net_device *dev, struct fe_priv *np,
1301 u32 phyinterface)
1302{
1303 u32 phy_reserved;
1304
1305 if (phyinterface & PHY_RGMII) {
1306 phy_reserved = mii_rw(dev, np->phyaddr, MII_RESV1, MII_READ);
1307 phy_reserved &= ~(PHY_CICADA_INIT1 | PHY_CICADA_INIT2);
1308 phy_reserved |= (PHY_CICADA_INIT3 | PHY_CICADA_INIT4);
1309 if (mii_rw(dev, np->phyaddr, MII_RESV1, phy_reserved))
1310 return PHY_ERROR;
1311 phy_reserved = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
1312 phy_reserved |= PHY_CICADA_INIT5;
1313 if (mii_rw(dev, np->phyaddr, MII_NCONFIG, phy_reserved))
1314 return PHY_ERROR;
1315 }
1316 phy_reserved = mii_rw(dev, np->phyaddr, MII_SREVISION, MII_READ);
1317 phy_reserved |= PHY_CICADA_INIT6;
1318 if (mii_rw(dev, np->phyaddr, MII_SREVISION, phy_reserved))
1319 return PHY_ERROR;
1320
1321 return 0;
1322}
1323
1324static int init_vitesse(struct net_device *dev, struct fe_priv *np)
1325{
1326 u32 phy_reserved;
1327
1328 if (mii_rw(dev, np->phyaddr,
1329 PHY_VITESSE_INIT_REG1, PHY_VITESSE_INIT1))
1330 return PHY_ERROR;
1331 if (mii_rw(dev, np->phyaddr,
1332 PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT2))
1333 return PHY_ERROR;
1334 phy_reserved = mii_rw(dev, np->phyaddr,
1335 PHY_VITESSE_INIT_REG4, MII_READ);
1336 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved))
1337 return PHY_ERROR;
1338 phy_reserved = mii_rw(dev, np->phyaddr,
1339 PHY_VITESSE_INIT_REG3, MII_READ);
1340 phy_reserved &= ~PHY_VITESSE_INIT_MSK1;
1341 phy_reserved |= PHY_VITESSE_INIT3;
1342 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved))
1343 return PHY_ERROR;
1344 if (mii_rw(dev, np->phyaddr,
1345 PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT4))
1346 return PHY_ERROR;
1347 if (mii_rw(dev, np->phyaddr,
1348 PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT5))
1349 return PHY_ERROR;
1350 phy_reserved = mii_rw(dev, np->phyaddr,
1351 PHY_VITESSE_INIT_REG4, MII_READ);
1352 phy_reserved &= ~PHY_VITESSE_INIT_MSK1;
1353 phy_reserved |= PHY_VITESSE_INIT3;
1354 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved))
1355 return PHY_ERROR;
1356 phy_reserved = mii_rw(dev, np->phyaddr,
1357 PHY_VITESSE_INIT_REG3, MII_READ);
1358 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved))
1359 return PHY_ERROR;
1360 if (mii_rw(dev, np->phyaddr,
1361 PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT6))
1362 return PHY_ERROR;
1363 if (mii_rw(dev, np->phyaddr,
1364 PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT7))
1365 return PHY_ERROR;
1366 phy_reserved = mii_rw(dev, np->phyaddr,
1367 PHY_VITESSE_INIT_REG4, MII_READ);
1368 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved))
1369 return PHY_ERROR;
1370 phy_reserved = mii_rw(dev, np->phyaddr,
1371 PHY_VITESSE_INIT_REG3, MII_READ);
1372 phy_reserved &= ~PHY_VITESSE_INIT_MSK2;
1373 phy_reserved |= PHY_VITESSE_INIT8;
1374 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved))
1375 return PHY_ERROR;
1376 if (mii_rw(dev, np->phyaddr,
1377 PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT9))
1378 return PHY_ERROR;
1379 if (mii_rw(dev, np->phyaddr,
1380 PHY_VITESSE_INIT_REG1, PHY_VITESSE_INIT10))
1381 return PHY_ERROR;
1382
1383 return 0;
1384}
1385
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386static int phy_init(struct net_device *dev)
1387{
1388 struct fe_priv *np = get_nvpriv(dev);
1389 u8 __iomem *base = get_hwbase(dev);
Joe Perchescd663282010-11-29 07:41:59 +00001390 u32 phyinterface;
1391 u32 mii_status, mii_control, mii_control_1000, reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001393 /* phy errata for E3016 phy */
1394 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
1395 reg = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
1396 reg &= ~PHY_MARVELL_E3016_INITMASK;
1397 if (mii_rw(dev, np->phyaddr, MII_NCONFIG, reg)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001398 netdev_info(dev, "%s: phy write to errata reg failed\n",
1399 pci_name(np->pci_dev));
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001400 return PHY_ERROR;
1401 }
1402 }
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -04001403 if (np->phy_oui == PHY_OUI_REALTEK) {
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001404 if (np->phy_model == PHY_MODEL_REALTEK_8211 &&
1405 np->phy_rev == PHY_REV_REALTEK_8211B) {
Joe Perchescd663282010-11-29 07:41:59 +00001406 if (init_realtek_8211b(dev, np)) {
1407 netdev_info(dev, "%s: phy init failed\n",
1408 pci_name(np->pci_dev));
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001409 return PHY_ERROR;
Joe Perchescd663282010-11-29 07:41:59 +00001410 }
Joe Perchesc41d41e2010-11-29 07:41:58 +00001411 } else if (np->phy_model == PHY_MODEL_REALTEK_8211 &&
1412 np->phy_rev == PHY_REV_REALTEK_8211C) {
Joe Perchescd663282010-11-29 07:41:59 +00001413 if (init_realtek_8211c(dev, np)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001414 netdev_info(dev, "%s: phy init failed\n",
1415 pci_name(np->pci_dev));
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -04001416 return PHY_ERROR;
1417 }
Joe Perchescd663282010-11-29 07:41:59 +00001418 } else if (np->phy_model == PHY_MODEL_REALTEK_8201) {
1419 if (init_realtek_8201(dev, np)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001420 netdev_info(dev, "%s: phy init failed\n",
1421 pci_name(np->pci_dev));
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -04001422 return PHY_ERROR;
1423 }
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -04001424 }
1425 }
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001426
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 /* set advertise register */
1428 reg = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Joe Perchescd663282010-11-29 07:41:59 +00001429 reg |= (ADVERTISE_10HALF | ADVERTISE_10FULL |
1430 ADVERTISE_100HALF | ADVERTISE_100FULL |
1431 ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 if (mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001433 netdev_info(dev, "%s: phy write to advertise failed\n",
1434 pci_name(np->pci_dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 return PHY_ERROR;
1436 }
1437
1438 /* get phy interface type */
1439 phyinterface = readl(base + NvRegPhyInterface);
1440
1441 /* see if gigabit phy */
1442 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
1443 if (mii_status & PHY_GIGABIT) {
1444 np->gigabit = PHY_GIGABIT;
Joe Perchescd663282010-11-29 07:41:59 +00001445 mii_control_1000 = mii_rw(dev, np->phyaddr,
1446 MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 mii_control_1000 &= ~ADVERTISE_1000HALF;
1448 if (phyinterface & PHY_RGMII)
1449 mii_control_1000 |= ADVERTISE_1000FULL;
1450 else
1451 mii_control_1000 &= ~ADVERTISE_1000FULL;
1452
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001453 if (mii_rw(dev, np->phyaddr, MII_CTRL1000, mii_control_1000)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001454 netdev_info(dev, "%s: phy init failed\n",
1455 pci_name(np->pci_dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 return PHY_ERROR;
1457 }
Szymon Janc78aea4f2010-11-27 08:39:43 +00001458 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 np->gigabit = 0;
1460
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001461 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1462 mii_control |= BMCR_ANENABLE;
1463
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -04001464 if (np->phy_oui == PHY_OUI_REALTEK &&
1465 np->phy_model == PHY_MODEL_REALTEK_8211 &&
1466 np->phy_rev == PHY_REV_REALTEK_8211C) {
1467 /* start autoneg since we already performed hw reset above */
1468 mii_control |= BMCR_ANRESTART;
1469 if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001470 netdev_info(dev, "%s: phy init failed\n",
1471 pci_name(np->pci_dev));
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -04001472 return PHY_ERROR;
1473 }
1474 } else {
1475 /* reset the phy
1476 * (certain phys need bmcr to be setup with reset)
1477 */
1478 if (phy_reset(dev, mii_control)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001479 netdev_info(dev, "%s: phy reset failed\n",
1480 pci_name(np->pci_dev));
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -04001481 return PHY_ERROR;
1482 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 }
1484
1485 /* phy vendor specific configuration */
Joe Perchescd663282010-11-29 07:41:59 +00001486 if ((np->phy_oui == PHY_OUI_CICADA)) {
1487 if (init_cicada(dev, np, phyinterface)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001488 netdev_info(dev, "%s: phy init failed\n",
1489 pci_name(np->pci_dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 return PHY_ERROR;
1491 }
Joe Perchescd663282010-11-29 07:41:59 +00001492 } else if (np->phy_oui == PHY_OUI_VITESSE) {
1493 if (init_vitesse(dev, np)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001494 netdev_info(dev, "%s: phy init failed\n",
1495 pci_name(np->pci_dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 return PHY_ERROR;
1497 }
Joe Perchescd663282010-11-29 07:41:59 +00001498 } else if (np->phy_oui == PHY_OUI_REALTEK) {
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001499 if (np->phy_model == PHY_MODEL_REALTEK_8211 &&
1500 np->phy_rev == PHY_REV_REALTEK_8211B) {
1501 /* reset could have cleared these out, set them back */
Joe Perchescd663282010-11-29 07:41:59 +00001502 if (init_realtek_8211b(dev, np)) {
1503 netdev_info(dev, "%s: phy init failed\n",
1504 pci_name(np->pci_dev));
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001505 return PHY_ERROR;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001506 }
Joe Perchescd663282010-11-29 07:41:59 +00001507 } else if (np->phy_model == PHY_MODEL_REALTEK_8201) {
1508 if (init_realtek_8201(dev, np) ||
1509 init_realtek_8201_cross(dev, np)) {
1510 netdev_info(dev, "%s: phy init failed\n",
1511 pci_name(np->pci_dev));
1512 return PHY_ERROR;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001513 }
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -04001514 }
1515 }
1516
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001517 /* some phys clear out pause advertisement on reset, set it back */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001518 mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
Ed Swierkcb52deb2008-12-01 12:24:43 +00001520 /* restart auto negotiation, power down phy */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ed Swierk5a9a8e32009-06-02 00:19:52 -07001522 mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE);
Szymon Janc78aea4f2010-11-27 08:39:43 +00001523 if (phy_power_down)
Ed Swierk5a9a8e32009-06-02 00:19:52 -07001524 mii_control |= BMCR_PDOWN;
Szymon Janc78aea4f2010-11-27 08:39:43 +00001525 if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 return PHY_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
1528 return 0;
1529}
1530
1531static void nv_start_rx(struct net_device *dev)
1532{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001533 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001535 u32 rx_ctrl = readl(base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 /* Already running? Stop it. */
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001538 if ((readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) && !np->mac_in_use) {
1539 rx_ctrl &= ~NVREG_RCVCTL_START;
1540 writel(rx_ctrl, base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 pci_push(base);
1542 }
1543 writel(np->linkspeed, base + NvRegLinkSpeed);
1544 pci_push(base);
Szymon Janc78aea4f2010-11-27 08:39:43 +00001545 rx_ctrl |= NVREG_RCVCTL_START;
1546 if (np->mac_in_use)
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001547 rx_ctrl &= ~NVREG_RCVCTL_RX_PATH_EN;
1548 writel(rx_ctrl, base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 pci_push(base);
1550}
1551
1552static void nv_stop_rx(struct net_device *dev)
1553{
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001554 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001556 u32 rx_ctrl = readl(base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001558 if (!np->mac_in_use)
1559 rx_ctrl &= ~NVREG_RCVCTL_START;
1560 else
1561 rx_ctrl |= NVREG_RCVCTL_RX_PATH_EN;
1562 writel(rx_ctrl, base + NvRegReceiverControl);
Joe Perches344d0dc2010-11-29 07:41:52 +00001563 if (reg_delay(dev, NvRegReceiverStatus, NVREG_RCVSTAT_BUSY, 0,
1564 NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX))
Joe Perches1d397f32010-11-29 07:41:57 +00001565 netdev_info(dev, "%s: ReceiverStatus remained busy\n",
1566 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567
1568 udelay(NV_RXSTOP_DELAY2);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001569 if (!np->mac_in_use)
1570 writel(0, base + NvRegLinkSpeed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571}
1572
1573static void nv_start_tx(struct net_device *dev)
1574{
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001575 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001577 u32 tx_ctrl = readl(base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001579 tx_ctrl |= NVREG_XMITCTL_START;
1580 if (np->mac_in_use)
1581 tx_ctrl &= ~NVREG_XMITCTL_TX_PATH_EN;
1582 writel(tx_ctrl, base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 pci_push(base);
1584}
1585
1586static void nv_stop_tx(struct net_device *dev)
1587{
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001588 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001590 u32 tx_ctrl = readl(base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001592 if (!np->mac_in_use)
1593 tx_ctrl &= ~NVREG_XMITCTL_START;
1594 else
1595 tx_ctrl |= NVREG_XMITCTL_TX_PATH_EN;
1596 writel(tx_ctrl, base + NvRegTransmitterControl);
Joe Perches344d0dc2010-11-29 07:41:52 +00001597 if (reg_delay(dev, NvRegTransmitterStatus, NVREG_XMITSTAT_BUSY, 0,
1598 NV_TXSTOP_DELAY1, NV_TXSTOP_DELAY1MAX))
Joe Perches1d397f32010-11-29 07:41:57 +00001599 netdev_info(dev, "%s: TransmitterStatus remained busy\n",
1600 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601
1602 udelay(NV_TXSTOP_DELAY2);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001603 if (!np->mac_in_use)
1604 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV,
1605 base + NvRegTransmitPoll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606}
1607
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001608static void nv_start_rxtx(struct net_device *dev)
1609{
1610 nv_start_rx(dev);
1611 nv_start_tx(dev);
1612}
1613
1614static void nv_stop_rxtx(struct net_device *dev)
1615{
1616 nv_stop_rx(dev);
1617 nv_stop_tx(dev);
1618}
1619
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620static void nv_txrx_reset(struct net_device *dev)
1621{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001622 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 u8 __iomem *base = get_hwbase(dev);
1624
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001625 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 pci_push(base);
1627 udelay(NV_TXRX_RESET_DELAY);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001628 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 pci_push(base);
1630}
1631
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001632static void nv_mac_reset(struct net_device *dev)
1633{
1634 struct fe_priv *np = netdev_priv(dev);
1635 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdulla4e84f9b2008-02-04 15:14:09 -05001636 u32 temp1, temp2, temp3;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001637
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001638 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
1639 pci_push(base);
Ayaz Abdulla4e84f9b2008-02-04 15:14:09 -05001640
1641 /* save registers since they will be cleared on reset */
1642 temp1 = readl(base + NvRegMacAddrA);
1643 temp2 = readl(base + NvRegMacAddrB);
1644 temp3 = readl(base + NvRegTransmitPoll);
1645
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001646 writel(NVREG_MAC_RESET_ASSERT, base + NvRegMacReset);
1647 pci_push(base);
1648 udelay(NV_MAC_RESET_DELAY);
1649 writel(0, base + NvRegMacReset);
1650 pci_push(base);
1651 udelay(NV_MAC_RESET_DELAY);
Ayaz Abdulla4e84f9b2008-02-04 15:14:09 -05001652
1653 /* restore saved registers */
1654 writel(temp1, base + NvRegMacAddrA);
1655 writel(temp2, base + NvRegMacAddrB);
1656 writel(temp3, base + NvRegTransmitPoll);
1657
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001658 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
1659 pci_push(base);
1660}
1661
david decotignyf5d827a2011-11-16 12:15:13 +00001662/* Caller must appropriately lock netdev_priv(dev)->hwstats_lock */
1663static void nv_update_stats(struct net_device *dev)
Ayaz Abdulla57fff692007-01-23 12:27:00 -05001664{
1665 struct fe_priv *np = netdev_priv(dev);
1666 u8 __iomem *base = get_hwbase(dev);
1667
david decotignyf5d827a2011-11-16 12:15:13 +00001668 /* If it happens that this is run in top-half context, then
1669 * replace the spin_lock of hwstats_lock with
1670 * spin_lock_irqsave() in calling functions. */
1671 WARN_ONCE(in_irq(), "forcedeth: estats spin_lock(_bh) from top-half");
1672 assert_spin_locked(&np->hwstats_lock);
1673
1674 /* query hardware */
Ayaz Abdulla57fff692007-01-23 12:27:00 -05001675 np->estats.tx_bytes += readl(base + NvRegTxCnt);
1676 np->estats.tx_zero_rexmt += readl(base + NvRegTxZeroReXmt);
1677 np->estats.tx_one_rexmt += readl(base + NvRegTxOneReXmt);
1678 np->estats.tx_many_rexmt += readl(base + NvRegTxManyReXmt);
1679 np->estats.tx_late_collision += readl(base + NvRegTxLateCol);
1680 np->estats.tx_fifo_errors += readl(base + NvRegTxUnderflow);
1681 np->estats.tx_carrier_errors += readl(base + NvRegTxLossCarrier);
1682 np->estats.tx_excess_deferral += readl(base + NvRegTxExcessDef);
1683 np->estats.tx_retry_error += readl(base + NvRegTxRetryErr);
1684 np->estats.rx_frame_error += readl(base + NvRegRxFrameErr);
1685 np->estats.rx_extra_byte += readl(base + NvRegRxExtraByte);
1686 np->estats.rx_late_collision += readl(base + NvRegRxLateCol);
1687 np->estats.rx_runt += readl(base + NvRegRxRunt);
1688 np->estats.rx_frame_too_long += readl(base + NvRegRxFrameTooLong);
1689 np->estats.rx_over_errors += readl(base + NvRegRxOverflow);
1690 np->estats.rx_crc_errors += readl(base + NvRegRxFCSErr);
1691 np->estats.rx_frame_align_error += readl(base + NvRegRxFrameAlignErr);
1692 np->estats.rx_length_error += readl(base + NvRegRxLenErr);
1693 np->estats.rx_unicast += readl(base + NvRegRxUnicast);
1694 np->estats.rx_multicast += readl(base + NvRegRxMulticast);
1695 np->estats.rx_broadcast += readl(base + NvRegRxBroadcast);
1696 np->estats.rx_packets =
1697 np->estats.rx_unicast +
1698 np->estats.rx_multicast +
1699 np->estats.rx_broadcast;
1700 np->estats.rx_errors_total =
1701 np->estats.rx_crc_errors +
1702 np->estats.rx_over_errors +
1703 np->estats.rx_frame_error +
1704 (np->estats.rx_frame_align_error - np->estats.rx_extra_byte) +
1705 np->estats.rx_late_collision +
1706 np->estats.rx_runt +
1707 np->estats.rx_frame_too_long;
1708 np->estats.tx_errors_total =
1709 np->estats.tx_late_collision +
1710 np->estats.tx_fifo_errors +
1711 np->estats.tx_carrier_errors +
1712 np->estats.tx_excess_deferral +
1713 np->estats.tx_retry_error;
1714
1715 if (np->driver_data & DEV_HAS_STATISTICS_V2) {
1716 np->estats.tx_deferral += readl(base + NvRegTxDef);
1717 np->estats.tx_packets += readl(base + NvRegTxFrame);
1718 np->estats.rx_bytes += readl(base + NvRegRxCnt);
1719 np->estats.tx_pause += readl(base + NvRegTxPause);
1720 np->estats.rx_pause += readl(base + NvRegRxPause);
1721 np->estats.rx_drop_frame += readl(base + NvRegRxDropFrame);
Mandeep Baines0bdfea82011-11-05 14:38:23 +00001722 np->estats.rx_errors_total += np->estats.rx_drop_frame;
Ayaz Abdulla57fff692007-01-23 12:27:00 -05001723 }
Ayaz Abdulla9c662432008-08-06 12:11:42 -04001724
1725 if (np->driver_data & DEV_HAS_STATISTICS_V3) {
1726 np->estats.tx_unicast += readl(base + NvRegTxUnicast);
1727 np->estats.tx_multicast += readl(base + NvRegTxMulticast);
1728 np->estats.tx_broadcast += readl(base + NvRegTxBroadcast);
1729 }
Ayaz Abdulla57fff692007-01-23 12:27:00 -05001730}
1731
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732/*
david decotignyf5d827a2011-11-16 12:15:13 +00001733 * nv_get_stats64: dev->ndo_get_stats64 function
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 * Get latest stats value from the nic.
1735 * Called with read_lock(&dev_base_lock) held for read -
1736 * only synchronized against unregister_netdevice.
1737 */
david decotignyf5d827a2011-11-16 12:15:13 +00001738static struct rtnl_link_stats64*
1739nv_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *storage)
1740 __acquires(&netdev_priv(dev)->hwstats_lock)
1741 __releases(&netdev_priv(dev)->hwstats_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001743 struct fe_priv *np = netdev_priv(dev);
david decotignyf5d827a2011-11-16 12:15:13 +00001744 unsigned int syncp_start;
1745
1746 /*
1747 * Note: because HW stats are not always available and for
1748 * consistency reasons, the following ifconfig stats are
1749 * managed by software: rx_bytes, tx_bytes, rx_packets and
1750 * tx_packets. The related hardware stats reported by ethtool
1751 * should be equivalent to these ifconfig stats, with 4
1752 * additional bytes per packet (Ethernet FCS CRC), except for
1753 * tx_packets when TSO kicks in.
1754 */
1755
1756 /* software stats */
1757 do {
david decotigny505a4672011-11-17 09:38:23 +00001758 syncp_start = u64_stats_fetch_begin_bh(&np->swstats_rx_syncp);
david decotignyf5d827a2011-11-16 12:15:13 +00001759 storage->rx_packets = np->stat_rx_packets;
1760 storage->rx_bytes = np->stat_rx_bytes;
david decotigny0a1f2222011-11-16 12:15:14 +00001761 storage->rx_dropped = np->stat_rx_dropped;
david decotignyf5d827a2011-11-16 12:15:13 +00001762 storage->rx_missed_errors = np->stat_rx_missed_errors;
david decotigny505a4672011-11-17 09:38:23 +00001763 } while (u64_stats_fetch_retry_bh(&np->swstats_rx_syncp, syncp_start));
david decotignyf5d827a2011-11-16 12:15:13 +00001764
1765 do {
david decotigny505a4672011-11-17 09:38:23 +00001766 syncp_start = u64_stats_fetch_begin_bh(&np->swstats_tx_syncp);
david decotignyf5d827a2011-11-16 12:15:13 +00001767 storage->tx_packets = np->stat_tx_packets;
1768 storage->tx_bytes = np->stat_tx_bytes;
1769 storage->tx_dropped = np->stat_tx_dropped;
david decotigny505a4672011-11-17 09:38:23 +00001770 } while (u64_stats_fetch_retry_bh(&np->swstats_tx_syncp, syncp_start));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771
Ayaz Abdulla21828162007-01-23 12:27:21 -05001772 /* If the nic supports hw counters then retrieve latest values */
david decotignyf5d827a2011-11-16 12:15:13 +00001773 if (np->driver_data & DEV_HAS_STATISTICS_V123) {
1774 spin_lock_bh(&np->hwstats_lock);
Ayaz Abdulla21828162007-01-23 12:27:21 -05001775
david decotignyf5d827a2011-11-16 12:15:13 +00001776 nv_update_stats(dev);
david decotigny674aee32011-11-16 12:15:07 +00001777
david decotignyf5d827a2011-11-16 12:15:13 +00001778 /* generic stats */
1779 storage->rx_errors = np->estats.rx_errors_total;
1780 storage->tx_errors = np->estats.tx_errors_total;
1781
1782 /* meaningful only when NIC supports stats v3 */
1783 storage->multicast = np->estats.rx_multicast;
1784
1785 /* detailed rx_errors */
1786 storage->rx_length_errors = np->estats.rx_length_error;
1787 storage->rx_over_errors = np->estats.rx_over_errors;
1788 storage->rx_crc_errors = np->estats.rx_crc_errors;
1789 storage->rx_frame_errors = np->estats.rx_frame_align_error;
1790 storage->rx_fifo_errors = np->estats.rx_drop_frame;
1791
1792 /* detailed tx_errors */
1793 storage->tx_carrier_errors = np->estats.tx_carrier_errors;
1794 storage->tx_fifo_errors = np->estats.tx_fifo_errors;
1795
1796 spin_unlock_bh(&np->hwstats_lock);
Ayaz Abdulla21828162007-01-23 12:27:21 -05001797 }
Jeff Garzik8148ff42007-10-16 20:56:09 -04001798
david decotignyf5d827a2011-11-16 12:15:13 +00001799 return storage;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800}
1801
1802/*
1803 * nv_alloc_rx: fill rx ring entries.
1804 * Return 1 if the allocations for the skbs failed and the
1805 * rx engine is without Available descriptors
1806 */
1807static int nv_alloc_rx(struct net_device *dev)
1808{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001809 struct fe_priv *np = netdev_priv(dev);
Szymon Janc78aea4f2010-11-27 08:39:43 +00001810 struct ring_desc *less_rx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001812 less_rx = np->get_rx.orig;
1813 if (less_rx-- == np->first_rx.orig)
1814 less_rx = np->last_rx.orig;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001815
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001816 while (np->put_rx.orig != less_rx) {
Pradeep A. Dalvidae2e9f2012-02-06 11:16:13 +00001817 struct sk_buff *skb = netdev_alloc_skb(dev, np->rx_buf_sz + NV_RX_ALLOC_PAD);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001818 if (skb) {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001819 np->put_rx_ctx->skb = skb;
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001820 np->put_rx_ctx->dma = pci_map_single(np->pci_dev,
1821 skb->data,
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001822 skb_tailroom(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001823 PCI_DMA_FROMDEVICE);
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001824 np->put_rx_ctx->dma_len = skb_tailroom(skb);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001825 np->put_rx.orig->buf = cpu_to_le32(np->put_rx_ctx->dma);
1826 wmb();
1827 np->put_rx.orig->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX_AVAIL);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001828 if (unlikely(np->put_rx.orig++ == np->last_rx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001829 np->put_rx.orig = np->first_rx.orig;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001830 if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001831 np->put_rx_ctx = np->first_rx_ctx;
david decotigny0a1f2222011-11-16 12:15:14 +00001832 } else {
1833 u64_stats_update_begin(&np->swstats_rx_syncp);
1834 np->stat_rx_dropped++;
1835 u64_stats_update_end(&np->swstats_rx_syncp);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001836 return 1;
david decotigny0a1f2222011-11-16 12:15:14 +00001837 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001838 }
1839 return 0;
1840}
1841
1842static int nv_alloc_rx_optimized(struct net_device *dev)
1843{
1844 struct fe_priv *np = netdev_priv(dev);
Szymon Janc78aea4f2010-11-27 08:39:43 +00001845 struct ring_desc_ex *less_rx;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001846
1847 less_rx = np->get_rx.ex;
1848 if (less_rx-- == np->first_rx.ex)
1849 less_rx = np->last_rx.ex;
1850
1851 while (np->put_rx.ex != less_rx) {
Pradeep A. Dalvidae2e9f2012-02-06 11:16:13 +00001852 struct sk_buff *skb = netdev_alloc_skb(dev, np->rx_buf_sz + NV_RX_ALLOC_PAD);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001853 if (skb) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001854 np->put_rx_ctx->skb = skb;
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001855 np->put_rx_ctx->dma = pci_map_single(np->pci_dev,
1856 skb->data,
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001857 skb_tailroom(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001858 PCI_DMA_FROMDEVICE);
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001859 np->put_rx_ctx->dma_len = skb_tailroom(skb);
Al Viro5bb7ea22007-12-09 16:06:41 +00001860 np->put_rx.ex->bufhigh = cpu_to_le32(dma_high(np->put_rx_ctx->dma));
1861 np->put_rx.ex->buflow = cpu_to_le32(dma_low(np->put_rx_ctx->dma));
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001862 wmb();
1863 np->put_rx.ex->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX2_AVAIL);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001864 if (unlikely(np->put_rx.ex++ == np->last_rx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001865 np->put_rx.ex = np->first_rx.ex;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001866 if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001867 np->put_rx_ctx = np->first_rx_ctx;
david decotigny0a1f2222011-11-16 12:15:14 +00001868 } else {
1869 u64_stats_update_begin(&np->swstats_rx_syncp);
1870 np->stat_rx_dropped++;
1871 u64_stats_update_end(&np->swstats_rx_syncp);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001872 return 1;
david decotigny0a1f2222011-11-16 12:15:14 +00001873 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001874 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 return 0;
1876}
1877
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001878/* If rx bufs are exhausted called after 50ms to attempt to refresh */
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001879static void nv_do_rx_refill(unsigned long data)
1880{
1881 struct net_device *dev = (struct net_device *) data;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001882 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001883
1884 /* Just reschedule NAPI rx processing */
Ben Hutchings288379f2009-01-19 16:43:59 -08001885 napi_schedule(&np->napi);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001886}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001888static void nv_init_rx(struct net_device *dev)
Manfred Sprauld81c0982005-07-31 18:20:30 +02001889{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001890 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02001891 int i;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001892
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001893 np->get_rx = np->put_rx = np->first_rx = np->rx_ring;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001894
1895 if (!nv_optimized(np))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001896 np->last_rx.orig = &np->rx_ring.orig[np->rx_ring_size-1];
1897 else
1898 np->last_rx.ex = &np->rx_ring.ex[np->rx_ring_size-1];
1899 np->get_rx_ctx = np->put_rx_ctx = np->first_rx_ctx = np->rx_skb;
1900 np->last_rx_ctx = &np->rx_skb[np->rx_ring_size-1];
Manfred Sprauld81c0982005-07-31 18:20:30 +02001901
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001902 for (i = 0; i < np->rx_ring_size; i++) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001903 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001904 np->rx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001905 np->rx_ring.orig[i].buf = 0;
1906 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001907 np->rx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001908 np->rx_ring.ex[i].txvlan = 0;
1909 np->rx_ring.ex[i].bufhigh = 0;
1910 np->rx_ring.ex[i].buflow = 0;
1911 }
1912 np->rx_skb[i].skb = NULL;
1913 np->rx_skb[i].dma = 0;
1914 }
Manfred Sprauld81c0982005-07-31 18:20:30 +02001915}
1916
1917static void nv_init_tx(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001918{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001919 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920 int i;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001921
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001922 np->get_tx = np->put_tx = np->first_tx = np->tx_ring;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001923
1924 if (!nv_optimized(np))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001925 np->last_tx.orig = &np->tx_ring.orig[np->tx_ring_size-1];
1926 else
1927 np->last_tx.ex = &np->tx_ring.ex[np->tx_ring_size-1];
1928 np->get_tx_ctx = np->put_tx_ctx = np->first_tx_ctx = np->tx_skb;
1929 np->last_tx_ctx = &np->tx_skb[np->tx_ring_size-1];
Tom Herbertb8bfca92011-11-28 16:33:23 +00001930 netdev_reset_queue(np->dev);
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001931 np->tx_pkts_in_progress = 0;
1932 np->tx_change_owner = NULL;
1933 np->tx_end_flip = NULL;
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00001934 np->tx_stop = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001935
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001936 for (i = 0; i < np->tx_ring_size; i++) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001937 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001938 np->tx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001939 np->tx_ring.orig[i].buf = 0;
1940 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001941 np->tx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001942 np->tx_ring.ex[i].txvlan = 0;
1943 np->tx_ring.ex[i].bufhigh = 0;
1944 np->tx_ring.ex[i].buflow = 0;
1945 }
1946 np->tx_skb[i].skb = NULL;
1947 np->tx_skb[i].dma = 0;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001948 np->tx_skb[i].dma_len = 0;
Eric Dumazet73a37072009-06-17 21:17:59 +00001949 np->tx_skb[i].dma_single = 0;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001950 np->tx_skb[i].first_tx_desc = NULL;
1951 np->tx_skb[i].next_tx_ctx = NULL;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001952 }
Manfred Sprauld81c0982005-07-31 18:20:30 +02001953}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001954
Manfred Sprauld81c0982005-07-31 18:20:30 +02001955static int nv_init_ring(struct net_device *dev)
1956{
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001957 struct fe_priv *np = netdev_priv(dev);
1958
Manfred Sprauld81c0982005-07-31 18:20:30 +02001959 nv_init_tx(dev);
1960 nv_init_rx(dev);
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001961
1962 if (!nv_optimized(np))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001963 return nv_alloc_rx(dev);
1964 else
1965 return nv_alloc_rx_optimized(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966}
1967
Eric Dumazet73a37072009-06-17 21:17:59 +00001968static void nv_unmap_txskb(struct fe_priv *np, struct nv_skb_map *tx_skb)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001969{
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001970 if (tx_skb->dma) {
Eric Dumazet73a37072009-06-17 21:17:59 +00001971 if (tx_skb->dma_single)
1972 pci_unmap_single(np->pci_dev, tx_skb->dma,
1973 tx_skb->dma_len,
1974 PCI_DMA_TODEVICE);
1975 else
1976 pci_unmap_page(np->pci_dev, tx_skb->dma,
1977 tx_skb->dma_len,
1978 PCI_DMA_TODEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001979 tx_skb->dma = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001980 }
Eric Dumazet73a37072009-06-17 21:17:59 +00001981}
1982
1983static int nv_release_txskb(struct fe_priv *np, struct nv_skb_map *tx_skb)
1984{
1985 nv_unmap_txskb(np, tx_skb);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001986 if (tx_skb->skb) {
1987 dev_kfree_skb_any(tx_skb->skb);
1988 tx_skb->skb = NULL;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001989 return 1;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001990 }
Eric Dumazet73a37072009-06-17 21:17:59 +00001991 return 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001992}
1993
Linus Torvalds1da177e2005-04-16 15:20:36 -07001994static void nv_drain_tx(struct net_device *dev)
1995{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001996 struct fe_priv *np = netdev_priv(dev);
1997 unsigned int i;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001998
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001999 for (i = 0; i < np->tx_ring_size; i++) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002000 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002001 np->tx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002002 np->tx_ring.orig[i].buf = 0;
2003 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002004 np->tx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002005 np->tx_ring.ex[i].txvlan = 0;
2006 np->tx_ring.ex[i].bufhigh = 0;
2007 np->tx_ring.ex[i].buflow = 0;
2008 }
david decotignyf5d827a2011-11-16 12:15:13 +00002009 if (nv_release_txskb(np, &np->tx_skb[i])) {
2010 u64_stats_update_begin(&np->swstats_tx_syncp);
2011 np->stat_tx_dropped++;
2012 u64_stats_update_end(&np->swstats_tx_syncp);
2013 }
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002014 np->tx_skb[i].dma = 0;
2015 np->tx_skb[i].dma_len = 0;
Eric Dumazet73a37072009-06-17 21:17:59 +00002016 np->tx_skb[i].dma_single = 0;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002017 np->tx_skb[i].first_tx_desc = NULL;
2018 np->tx_skb[i].next_tx_ctx = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019 }
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002020 np->tx_pkts_in_progress = 0;
2021 np->tx_change_owner = NULL;
2022 np->tx_end_flip = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002023}
2024
2025static void nv_drain_rx(struct net_device *dev)
2026{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002027 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002028 int i;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002029
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04002030 for (i = 0; i < np->rx_ring_size; i++) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002031 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002032 np->rx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002033 np->rx_ring.orig[i].buf = 0;
2034 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002035 np->rx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002036 np->rx_ring.ex[i].txvlan = 0;
2037 np->rx_ring.ex[i].bufhigh = 0;
2038 np->rx_ring.ex[i].buflow = 0;
2039 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 wmb();
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002041 if (np->rx_skb[i].skb) {
2042 pci_unmap_single(np->pci_dev, np->rx_skb[i].dma,
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07002043 (skb_end_pointer(np->rx_skb[i].skb) -
2044 np->rx_skb[i].skb->data),
2045 PCI_DMA_FROMDEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002046 dev_kfree_skb(np->rx_skb[i].skb);
2047 np->rx_skb[i].skb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002048 }
2049 }
2050}
2051
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002052static void nv_drain_rxtx(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002053{
2054 nv_drain_tx(dev);
2055 nv_drain_rx(dev);
2056}
2057
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002058static inline u32 nv_get_empty_tx_slots(struct fe_priv *np)
2059{
2060 return (u32)(np->tx_ring_size - ((np->tx_ring_size + (np->put_tx_ctx - np->get_tx_ctx)) % np->tx_ring_size));
2061}
2062
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002063static void nv_legacybackoff_reseed(struct net_device *dev)
2064{
2065 u8 __iomem *base = get_hwbase(dev);
2066 u32 reg;
2067 u32 low;
2068 int tx_status = 0;
2069
2070 reg = readl(base + NvRegSlotTime) & ~NVREG_SLOTTIME_MASK;
2071 get_random_bytes(&low, sizeof(low));
2072 reg |= low & NVREG_SLOTTIME_MASK;
2073
2074 /* Need to stop tx before change takes effect.
2075 * Caller has already gained np->lock.
2076 */
2077 tx_status = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_START;
2078 if (tx_status)
2079 nv_stop_tx(dev);
2080 nv_stop_rx(dev);
2081 writel(reg, base + NvRegSlotTime);
2082 if (tx_status)
2083 nv_start_tx(dev);
2084 nv_start_rx(dev);
2085}
2086
2087/* Gear Backoff Seeds */
2088#define BACKOFF_SEEDSET_ROWS 8
2089#define BACKOFF_SEEDSET_LFSRS 15
2090
2091/* Known Good seed sets */
2092static const u32 main_seedset[BACKOFF_SEEDSET_ROWS][BACKOFF_SEEDSET_LFSRS] = {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002093 {145, 155, 165, 175, 185, 196, 235, 245, 255, 265, 275, 285, 660, 690, 874},
2094 {245, 255, 265, 575, 385, 298, 335, 345, 355, 366, 375, 385, 761, 790, 974},
2095 {145, 155, 165, 175, 185, 196, 235, 245, 255, 265, 275, 285, 660, 690, 874},
2096 {245, 255, 265, 575, 385, 298, 335, 345, 355, 366, 375, 386, 761, 790, 974},
2097 {266, 265, 276, 585, 397, 208, 345, 355, 365, 376, 385, 396, 771, 700, 984},
2098 {266, 265, 276, 586, 397, 208, 346, 355, 365, 376, 285, 396, 771, 700, 984},
2099 {366, 365, 376, 686, 497, 308, 447, 455, 466, 476, 485, 496, 871, 800, 84},
2100 {466, 465, 476, 786, 597, 408, 547, 555, 566, 576, 585, 597, 971, 900, 184} };
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002101
2102static const u32 gear_seedset[BACKOFF_SEEDSET_ROWS][BACKOFF_SEEDSET_LFSRS] = {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002103 {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
2104 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
2105 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 397},
2106 {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
2107 {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
2108 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
2109 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
2110 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395} };
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002111
2112static void nv_gear_backoff_reseed(struct net_device *dev)
2113{
2114 u8 __iomem *base = get_hwbase(dev);
2115 u32 miniseed1, miniseed2, miniseed2_reversed, miniseed3, miniseed3_reversed;
2116 u32 temp, seedset, combinedSeed;
2117 int i;
2118
2119 /* Setup seed for free running LFSR */
2120 /* We are going to read the time stamp counter 3 times
2121 and swizzle bits around to increase randomness */
2122 get_random_bytes(&miniseed1, sizeof(miniseed1));
2123 miniseed1 &= 0x0fff;
2124 if (miniseed1 == 0)
2125 miniseed1 = 0xabc;
2126
2127 get_random_bytes(&miniseed2, sizeof(miniseed2));
2128 miniseed2 &= 0x0fff;
2129 if (miniseed2 == 0)
2130 miniseed2 = 0xabc;
2131 miniseed2_reversed =
2132 ((miniseed2 & 0xF00) >> 8) |
2133 (miniseed2 & 0x0F0) |
2134 ((miniseed2 & 0x00F) << 8);
2135
2136 get_random_bytes(&miniseed3, sizeof(miniseed3));
2137 miniseed3 &= 0x0fff;
2138 if (miniseed3 == 0)
2139 miniseed3 = 0xabc;
2140 miniseed3_reversed =
2141 ((miniseed3 & 0xF00) >> 8) |
2142 (miniseed3 & 0x0F0) |
2143 ((miniseed3 & 0x00F) << 8);
2144
2145 combinedSeed = ((miniseed1 ^ miniseed2_reversed) << 12) |
2146 (miniseed2 ^ miniseed3_reversed);
2147
2148 /* Seeds can not be zero */
2149 if ((combinedSeed & NVREG_BKOFFCTRL_SEED_MASK) == 0)
2150 combinedSeed |= 0x08;
2151 if ((combinedSeed & (NVREG_BKOFFCTRL_SEED_MASK << NVREG_BKOFFCTRL_GEAR)) == 0)
2152 combinedSeed |= 0x8000;
2153
2154 /* No need to disable tx here */
2155 temp = NVREG_BKOFFCTRL_DEFAULT | (0 << NVREG_BKOFFCTRL_SELECT);
2156 temp |= combinedSeed & NVREG_BKOFFCTRL_SEED_MASK;
2157 temp |= combinedSeed >> NVREG_BKOFFCTRL_GEAR;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002158 writel(temp, base + NvRegBackOffControl);
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002159
Szymon Janc78aea4f2010-11-27 08:39:43 +00002160 /* Setup seeds for all gear LFSRs. */
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002161 get_random_bytes(&seedset, sizeof(seedset));
2162 seedset = seedset % BACKOFF_SEEDSET_ROWS;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002163 for (i = 1; i <= BACKOFF_SEEDSET_LFSRS; i++) {
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002164 temp = NVREG_BKOFFCTRL_DEFAULT | (i << NVREG_BKOFFCTRL_SELECT);
2165 temp |= main_seedset[seedset][i-1] & 0x3ff;
2166 temp |= ((gear_seedset[seedset][i-1] & 0x3ff) << NVREG_BKOFFCTRL_GEAR);
2167 writel(temp, base + NvRegBackOffControl);
2168 }
2169}
2170
Linus Torvalds1da177e2005-04-16 15:20:36 -07002171/*
2172 * nv_start_xmit: dev->hard_start_xmit function
Herbert Xu932ff272006-06-09 12:20:56 -07002173 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002174 */
Stephen Hemminger613573252009-08-31 19:50:58 +00002175static netdev_tx_t nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002177 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002178 u32 tx_flags = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002179 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
2180 unsigned int fragments = skb_shinfo(skb)->nr_frags;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002181 unsigned int i;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002182 u32 offset = 0;
2183 u32 bcnt;
Eric Dumazete743d312010-04-14 15:59:40 -07002184 u32 size = skb_headlen(skb);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002185 u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002186 u32 empty_slots;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002187 struct ring_desc *put_tx;
2188 struct ring_desc *start_tx;
2189 struct ring_desc *prev_tx;
2190 struct nv_skb_map *prev_tx_ctx;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002191 unsigned long flags;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002192
2193 /* add fragments to entries count */
2194 for (i = 0; i < fragments; i++) {
david decotignye45a6182011-11-05 14:38:24 +00002195 u32 frag_size = skb_frag_size(&skb_shinfo(skb)->frags[i]);
Eric Dumazet9e903e02011-10-18 21:00:24 +00002196
david decotignye45a6182011-11-05 14:38:24 +00002197 entries += (frag_size >> NV_TX2_TSO_MAX_SHIFT) +
2198 ((frag_size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002199 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200
Ayaz Abdulla001eb842009-01-09 11:03:44 +00002201 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002202 empty_slots = nv_get_empty_tx_slots(np);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002203 if (unlikely(empty_slots <= entries)) {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002204 netif_stop_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002205 np->tx_stop = 1;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002206 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002207 return NETDEV_TX_BUSY;
2208 }
Ayaz Abdulla001eb842009-01-09 11:03:44 +00002209 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002210
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002211 start_tx = put_tx = np->put_tx.orig;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002212
Ayaz Abdullafa454592006-01-05 22:45:45 -08002213 /* setup the header buffer */
2214 do {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002215 prev_tx = put_tx;
2216 prev_tx_ctx = np->put_tx_ctx;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002217 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002218 np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
Ayaz Abdullafa454592006-01-05 22:45:45 -08002219 PCI_DMA_TODEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002220 np->put_tx_ctx->dma_len = bcnt;
Eric Dumazet73a37072009-06-17 21:17:59 +00002221 np->put_tx_ctx->dma_single = 1;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002222 put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
2223 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002224
Ayaz Abdullafa454592006-01-05 22:45:45 -08002225 tx_flags = np->tx_flags;
2226 offset += bcnt;
2227 size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002228 if (unlikely(put_tx++ == np->last_tx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002229 put_tx = np->first_tx.orig;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002230 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002231 np->put_tx_ctx = np->first_tx_ctx;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002232 } while (size);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002233
2234 /* setup the fragments */
2235 for (i = 0; i < fragments; i++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00002236 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
david decotignye45a6182011-11-05 14:38:24 +00002237 u32 frag_size = skb_frag_size(frag);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002238 offset = 0;
2239
2240 do {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002241 prev_tx = put_tx;
2242 prev_tx_ctx = np->put_tx_ctx;
david decotignye45a6182011-11-05 14:38:24 +00002243 bcnt = (frag_size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : frag_size;
Ian Campbell671173c2011-08-29 23:18:28 +00002244 np->put_tx_ctx->dma = skb_frag_dma_map(
2245 &np->pci_dev->dev,
2246 frag, offset,
2247 bcnt,
Ian Campbell5d6bcdf2011-10-06 11:10:48 +01002248 DMA_TO_DEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002249 np->put_tx_ctx->dma_len = bcnt;
Eric Dumazet73a37072009-06-17 21:17:59 +00002250 np->put_tx_ctx->dma_single = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002251 put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
2252 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002253
Ayaz Abdullafa454592006-01-05 22:45:45 -08002254 offset += bcnt;
david decotignye45a6182011-11-05 14:38:24 +00002255 frag_size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002256 if (unlikely(put_tx++ == np->last_tx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002257 put_tx = np->first_tx.orig;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002258 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002259 np->put_tx_ctx = np->first_tx_ctx;
david decotignye45a6182011-11-05 14:38:24 +00002260 } while (frag_size);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002261 }
2262
Ayaz Abdullafa454592006-01-05 22:45:45 -08002263 /* set last fragment flag */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002264 prev_tx->flaglen |= cpu_to_le32(tx_flags_extra);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002265
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002266 /* save skb in this slot's context area */
2267 prev_tx_ctx->skb = skb;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002268
Herbert Xu89114af2006-07-08 13:34:32 -07002269 if (skb_is_gso(skb))
Herbert Xu79671682006-06-22 02:40:14 -07002270 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
Manfred Spraulee733622005-07-31 18:32:26 +02002271 else
Arjan van de Ven1d39ed52006-12-12 14:06:23 +01002272 tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
Patrick McHardy84fa7932006-08-29 16:44:56 -07002273 NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002274
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002275 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla164a86e2007-01-09 13:30:10 -05002276
Ayaz Abdullafa454592006-01-05 22:45:45 -08002277 /* set tx flags */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002278 start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
Tom Herbertb8bfca92011-11-28 16:33:23 +00002279
2280 netdev_sent_queue(np->dev, skb->len);
2281
Willem de Bruijn49cbb1c2012-04-27 09:04:07 +00002282 skb_tx_timestamp(skb);
2283
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002284 np->put_tx.orig = put_tx;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002285
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002286 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002287
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002288 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002289 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002290}
2291
Stephen Hemminger613573252009-08-31 19:50:58 +00002292static netdev_tx_t nv_start_xmit_optimized(struct sk_buff *skb,
2293 struct net_device *dev)
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002294{
2295 struct fe_priv *np = netdev_priv(dev);
2296 u32 tx_flags = 0;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002297 u32 tx_flags_extra;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002298 unsigned int fragments = skb_shinfo(skb)->nr_frags;
2299 unsigned int i;
2300 u32 offset = 0;
2301 u32 bcnt;
Eric Dumazete743d312010-04-14 15:59:40 -07002302 u32 size = skb_headlen(skb);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002303 u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
2304 u32 empty_slots;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002305 struct ring_desc_ex *put_tx;
2306 struct ring_desc_ex *start_tx;
2307 struct ring_desc_ex *prev_tx;
2308 struct nv_skb_map *prev_tx_ctx;
2309 struct nv_skb_map *start_tx_ctx;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002310 unsigned long flags;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002311
2312 /* add fragments to entries count */
2313 for (i = 0; i < fragments; i++) {
david decotignye45a6182011-11-05 14:38:24 +00002314 u32 frag_size = skb_frag_size(&skb_shinfo(skb)->frags[i]);
Eric Dumazet9e903e02011-10-18 21:00:24 +00002315
david decotignye45a6182011-11-05 14:38:24 +00002316 entries += (frag_size >> NV_TX2_TSO_MAX_SHIFT) +
2317 ((frag_size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002318 }
2319
Ayaz Abdulla001eb842009-01-09 11:03:44 +00002320 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002321 empty_slots = nv_get_empty_tx_slots(np);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002322 if (unlikely(empty_slots <= entries)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002323 netif_stop_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002324 np->tx_stop = 1;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002325 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002326 return NETDEV_TX_BUSY;
2327 }
Ayaz Abdulla001eb842009-01-09 11:03:44 +00002328 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002329
2330 start_tx = put_tx = np->put_tx.ex;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002331 start_tx_ctx = np->put_tx_ctx;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002332
2333 /* setup the header buffer */
2334 do {
2335 prev_tx = put_tx;
2336 prev_tx_ctx = np->put_tx_ctx;
2337 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
2338 np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
2339 PCI_DMA_TODEVICE);
2340 np->put_tx_ctx->dma_len = bcnt;
Eric Dumazet73a37072009-06-17 21:17:59 +00002341 np->put_tx_ctx->dma_single = 1;
Al Viro5bb7ea22007-12-09 16:06:41 +00002342 put_tx->bufhigh = cpu_to_le32(dma_high(np->put_tx_ctx->dma));
2343 put_tx->buflow = cpu_to_le32(dma_low(np->put_tx_ctx->dma));
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002344 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002345
2346 tx_flags = NV_TX2_VALID;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002347 offset += bcnt;
2348 size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002349 if (unlikely(put_tx++ == np->last_tx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002350 put_tx = np->first_tx.ex;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002351 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002352 np->put_tx_ctx = np->first_tx_ctx;
2353 } while (size);
2354
2355 /* setup the fragments */
2356 for (i = 0; i < fragments; i++) {
2357 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
david decotignye45a6182011-11-05 14:38:24 +00002358 u32 frag_size = skb_frag_size(frag);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002359 offset = 0;
2360
2361 do {
2362 prev_tx = put_tx;
2363 prev_tx_ctx = np->put_tx_ctx;
david decotignye45a6182011-11-05 14:38:24 +00002364 bcnt = (frag_size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : frag_size;
Ian Campbell671173c2011-08-29 23:18:28 +00002365 np->put_tx_ctx->dma = skb_frag_dma_map(
2366 &np->pci_dev->dev,
2367 frag, offset,
2368 bcnt,
Ian Campbell5d6bcdf2011-10-06 11:10:48 +01002369 DMA_TO_DEVICE);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002370 np->put_tx_ctx->dma_len = bcnt;
Eric Dumazet73a37072009-06-17 21:17:59 +00002371 np->put_tx_ctx->dma_single = 0;
Al Viro5bb7ea22007-12-09 16:06:41 +00002372 put_tx->bufhigh = cpu_to_le32(dma_high(np->put_tx_ctx->dma));
2373 put_tx->buflow = cpu_to_le32(dma_low(np->put_tx_ctx->dma));
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002374 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002375
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002376 offset += bcnt;
david decotignye45a6182011-11-05 14:38:24 +00002377 frag_size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002378 if (unlikely(put_tx++ == np->last_tx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002379 put_tx = np->first_tx.ex;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002380 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002381 np->put_tx_ctx = np->first_tx_ctx;
david decotignye45a6182011-11-05 14:38:24 +00002382 } while (frag_size);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002383 }
2384
2385 /* set last fragment flag */
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002386 prev_tx->flaglen |= cpu_to_le32(NV_TX2_LASTPACKET);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002387
2388 /* save skb in this slot's context area */
2389 prev_tx_ctx->skb = skb;
2390
2391 if (skb_is_gso(skb))
2392 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
2393 else
2394 tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
2395 NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
2396
2397 /* vlan tag */
Jesse Grosseab6d182010-10-20 13:56:03 +00002398 if (vlan_tx_tag_present(skb))
2399 start_tx->txvlan = cpu_to_le32(NV_TX3_VLAN_TAG_PRESENT |
2400 vlan_tx_tag_get(skb));
2401 else
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002402 start_tx->txvlan = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002403
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002404 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002405
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002406 if (np->tx_limit) {
2407 /* Limit the number of outstanding tx. Setup all fragments, but
2408 * do not set the VALID bit on the first descriptor. Save a pointer
2409 * to that descriptor and also for next skb_map element.
2410 */
2411
2412 if (np->tx_pkts_in_progress == NV_TX_LIMIT_COUNT) {
2413 if (!np->tx_change_owner)
2414 np->tx_change_owner = start_tx_ctx;
2415
2416 /* remove VALID bit */
2417 tx_flags &= ~NV_TX2_VALID;
2418 start_tx_ctx->first_tx_desc = start_tx;
2419 start_tx_ctx->next_tx_ctx = np->put_tx_ctx;
2420 np->tx_end_flip = np->put_tx_ctx;
2421 } else {
2422 np->tx_pkts_in_progress++;
2423 }
2424 }
2425
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002426 /* set tx flags */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002427 start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
Tom Herbertb8bfca92011-11-28 16:33:23 +00002428
2429 netdev_sent_queue(np->dev, skb->len);
2430
Willem de Bruijn49cbb1c2012-04-27 09:04:07 +00002431 skb_tx_timestamp(skb);
2432
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002433 np->put_tx.ex = put_tx;
2434
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002435 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002436
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002437 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002438 return NETDEV_TX_OK;
2439}
2440
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002441static inline void nv_tx_flip_ownership(struct net_device *dev)
2442{
2443 struct fe_priv *np = netdev_priv(dev);
2444
2445 np->tx_pkts_in_progress--;
2446 if (np->tx_change_owner) {
Al Viro30ecce92008-03-26 05:57:12 +00002447 np->tx_change_owner->first_tx_desc->flaglen |=
2448 cpu_to_le32(NV_TX2_VALID);
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002449 np->tx_pkts_in_progress++;
2450
2451 np->tx_change_owner = np->tx_change_owner->next_tx_ctx;
2452 if (np->tx_change_owner == np->tx_end_flip)
2453 np->tx_change_owner = NULL;
2454
2455 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
2456 }
2457}
2458
Linus Torvalds1da177e2005-04-16 15:20:36 -07002459/*
2460 * nv_tx_done: check for completed packets, release the skbs.
2461 *
2462 * Caller must own np->lock.
2463 */
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002464static int nv_tx_done(struct net_device *dev, int limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002465{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002466 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002467 u32 flags;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002468 int tx_work = 0;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002469 struct ring_desc *orig_get_tx = np->get_tx.orig;
Tom Herbertb8bfca92011-11-28 16:33:23 +00002470 unsigned int bytes_compl = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002471
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002472 while ((np->get_tx.orig != np->put_tx.orig) &&
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002473 !((flags = le32_to_cpu(np->get_tx.orig->flaglen)) & NV_TX_VALID) &&
2474 (tx_work < limit)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475
Eric Dumazet73a37072009-06-17 21:17:59 +00002476 nv_unmap_txskb(np, np->get_tx_ctx);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002477
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 if (np->desc_ver == DESC_VER_1) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002479 if (flags & NV_TX_LASTPACKET) {
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002480 if (flags & NV_TX_ERROR) {
david decotignyf5d827a2011-11-16 12:15:13 +00002481 if ((flags & NV_TX_RETRYERROR)
2482 && !(flags & NV_TX_RETRYCOUNT_MASK))
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002483 nv_legacybackoff_reseed(dev);
david decotigny674aee32011-11-16 12:15:07 +00002484 } else {
david decotignyf5d827a2011-11-16 12:15:13 +00002485 u64_stats_update_begin(&np->swstats_tx_syncp);
2486 np->stat_tx_packets++;
2487 np->stat_tx_bytes += np->get_tx_ctx->skb->len;
2488 u64_stats_update_end(&np->swstats_tx_syncp);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002489 }
Tom Herbertb8bfca92011-11-28 16:33:23 +00002490 bytes_compl += np->get_tx_ctx->skb->len;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002491 dev_kfree_skb_any(np->get_tx_ctx->skb);
2492 np->get_tx_ctx->skb = NULL;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002493 tx_work++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 }
2495 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002496 if (flags & NV_TX2_LASTPACKET) {
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002497 if (flags & NV_TX2_ERROR) {
david decotignyf5d827a2011-11-16 12:15:13 +00002498 if ((flags & NV_TX2_RETRYERROR)
2499 && !(flags & NV_TX2_RETRYCOUNT_MASK))
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002500 nv_legacybackoff_reseed(dev);
david decotigny674aee32011-11-16 12:15:07 +00002501 } else {
david decotignyf5d827a2011-11-16 12:15:13 +00002502 u64_stats_update_begin(&np->swstats_tx_syncp);
2503 np->stat_tx_packets++;
2504 np->stat_tx_bytes += np->get_tx_ctx->skb->len;
2505 u64_stats_update_end(&np->swstats_tx_syncp);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002506 }
Tom Herbertb8bfca92011-11-28 16:33:23 +00002507 bytes_compl += np->get_tx_ctx->skb->len;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002508 dev_kfree_skb_any(np->get_tx_ctx->skb);
2509 np->get_tx_ctx->skb = NULL;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002510 tx_work++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511 }
2512 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002513 if (unlikely(np->get_tx.orig++ == np->last_tx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002514 np->get_tx.orig = np->first_tx.orig;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002515 if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002516 np->get_tx_ctx = np->first_tx_ctx;
2517 }
Tom Herbertb8bfca92011-11-28 16:33:23 +00002518
2519 netdev_completed_queue(np->dev, tx_work, bytes_compl);
2520
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002521 if (unlikely((np->tx_stop == 1) && (np->get_tx.orig != orig_get_tx))) {
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002522 np->tx_stop = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002523 netif_wake_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002524 }
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002525 return tx_work;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002526}
2527
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002528static int nv_tx_done_optimized(struct net_device *dev, int limit)
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002529{
2530 struct fe_priv *np = netdev_priv(dev);
2531 u32 flags;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002532 int tx_work = 0;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002533 struct ring_desc_ex *orig_get_tx = np->get_tx.ex;
Tom Herbertb8bfca92011-11-28 16:33:23 +00002534 unsigned long bytes_cleaned = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002535
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002536 while ((np->get_tx.ex != np->put_tx.ex) &&
Julia Lawall217d32d2010-07-05 22:15:47 -07002537 !((flags = le32_to_cpu(np->get_tx.ex->flaglen)) & NV_TX2_VALID) &&
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002538 (tx_work < limit)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002539
Eric Dumazet73a37072009-06-17 21:17:59 +00002540 nv_unmap_txskb(np, np->get_tx_ctx);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002541
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002542 if (flags & NV_TX2_LASTPACKET) {
david decotigny4687f3f2011-11-05 14:38:22 +00002543 if (flags & NV_TX2_ERROR) {
david decotignyf5d827a2011-11-16 12:15:13 +00002544 if ((flags & NV_TX2_RETRYERROR)
2545 && !(flags & NV_TX2_RETRYCOUNT_MASK)) {
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002546 if (np->driver_data & DEV_HAS_GEAR_MODE)
2547 nv_gear_backoff_reseed(dev);
2548 else
2549 nv_legacybackoff_reseed(dev);
2550 }
david decotigny674aee32011-11-16 12:15:07 +00002551 } else {
David S. Millerefd0bf92011-11-21 13:50:33 -05002552 u64_stats_update_begin(&np->swstats_tx_syncp);
2553 np->stat_tx_packets++;
2554 np->stat_tx_bytes += np->get_tx_ctx->skb->len;
2555 u64_stats_update_end(&np->swstats_tx_syncp);
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002556 }
2557
Tom Herbertb8bfca92011-11-28 16:33:23 +00002558 bytes_cleaned += np->get_tx_ctx->skb->len;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002559 dev_kfree_skb_any(np->get_tx_ctx->skb);
2560 np->get_tx_ctx->skb = NULL;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002561 tx_work++;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002562
Szymon Janc78aea4f2010-11-27 08:39:43 +00002563 if (np->tx_limit)
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002564 nv_tx_flip_ownership(dev);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002565 }
Tom Herbertb8bfca92011-11-28 16:33:23 +00002566
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002567 if (unlikely(np->get_tx.ex++ == np->last_tx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002568 np->get_tx.ex = np->first_tx.ex;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002569 if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002570 np->get_tx_ctx = np->first_tx_ctx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002571 }
Igor Maravic7505afe2011-12-01 23:48:20 +00002572
2573 netdev_completed_queue(np->dev, tx_work, bytes_cleaned);
2574
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002575 if (unlikely((np->tx_stop == 1) && (np->get_tx.ex != orig_get_tx))) {
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002576 np->tx_stop = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002577 netif_wake_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002578 }
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002579 return tx_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580}
2581
2582/*
2583 * nv_tx_timeout: dev->tx_timeout function
Herbert Xu932ff272006-06-09 12:20:56 -07002584 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 */
2586static void nv_tx_timeout(struct net_device *dev)
2587{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002588 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002590 u32 status;
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002591 union ring_type put_tx;
2592 int saved_tx_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002593
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002594 if (np->msi_flags & NV_MSI_X_ENABLED)
2595 status = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
2596 else
2597 status = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
2598
Sameer Nanda1ec4f2d2011-11-16 12:15:12 +00002599 netdev_warn(dev, "Got tx_timeout. irq status: %08x\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002600
Sameer Nanda1ec4f2d2011-11-16 12:15:12 +00002601 if (unlikely(debug_tx_timeout)) {
2602 int i;
2603
2604 netdev_info(dev, "Ring at %lx\n", (unsigned long)np->ring_addr);
2605 netdev_info(dev, "Dumping tx registers\n");
2606 for (i = 0; i <= np->register_size; i += 32) {
Joe Perches1d397f32010-11-29 07:41:57 +00002607 netdev_info(dev,
Sameer Nanda1ec4f2d2011-11-16 12:15:12 +00002608 "%3x: %08x %08x %08x %08x "
2609 "%08x %08x %08x %08x\n",
Joe Perches1d397f32010-11-29 07:41:57 +00002610 i,
Sameer Nanda1ec4f2d2011-11-16 12:15:12 +00002611 readl(base + i + 0), readl(base + i + 4),
2612 readl(base + i + 8), readl(base + i + 12),
2613 readl(base + i + 16), readl(base + i + 20),
2614 readl(base + i + 24), readl(base + i + 28));
2615 }
2616 netdev_info(dev, "Dumping tx ring\n");
2617 for (i = 0; i < np->tx_ring_size; i += 4) {
2618 if (!nv_optimized(np)) {
2619 netdev_info(dev,
2620 "%03x: %08x %08x // %08x %08x "
2621 "// %08x %08x // %08x %08x\n",
2622 i,
2623 le32_to_cpu(np->tx_ring.orig[i].buf),
2624 le32_to_cpu(np->tx_ring.orig[i].flaglen),
2625 le32_to_cpu(np->tx_ring.orig[i+1].buf),
2626 le32_to_cpu(np->tx_ring.orig[i+1].flaglen),
2627 le32_to_cpu(np->tx_ring.orig[i+2].buf),
2628 le32_to_cpu(np->tx_ring.orig[i+2].flaglen),
2629 le32_to_cpu(np->tx_ring.orig[i+3].buf),
2630 le32_to_cpu(np->tx_ring.orig[i+3].flaglen));
2631 } else {
2632 netdev_info(dev,
2633 "%03x: %08x %08x %08x "
2634 "// %08x %08x %08x "
2635 "// %08x %08x %08x "
2636 "// %08x %08x %08x\n",
2637 i,
2638 le32_to_cpu(np->tx_ring.ex[i].bufhigh),
2639 le32_to_cpu(np->tx_ring.ex[i].buflow),
2640 le32_to_cpu(np->tx_ring.ex[i].flaglen),
2641 le32_to_cpu(np->tx_ring.ex[i+1].bufhigh),
2642 le32_to_cpu(np->tx_ring.ex[i+1].buflow),
2643 le32_to_cpu(np->tx_ring.ex[i+1].flaglen),
2644 le32_to_cpu(np->tx_ring.ex[i+2].bufhigh),
2645 le32_to_cpu(np->tx_ring.ex[i+2].buflow),
2646 le32_to_cpu(np->tx_ring.ex[i+2].flaglen),
2647 le32_to_cpu(np->tx_ring.ex[i+3].bufhigh),
2648 le32_to_cpu(np->tx_ring.ex[i+3].buflow),
2649 le32_to_cpu(np->tx_ring.ex[i+3].flaglen));
2650 }
Manfred Spraulc2dba062005-07-31 18:29:47 +02002651 }
2652 }
2653
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 spin_lock_irq(&np->lock);
2655
2656 /* 1) stop tx engine */
2657 nv_stop_tx(dev);
2658
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002659 /* 2) complete any outstanding tx and do not give HW any limited tx pkts */
2660 saved_tx_limit = np->tx_limit;
2661 np->tx_limit = 0; /* prevent giving HW any limited pkts */
2662 np->tx_stop = 0; /* prevent waking tx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002663 if (!nv_optimized(np))
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002664 nv_tx_done(dev, np->tx_ring_size);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002665 else
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05002666 nv_tx_done_optimized(dev, np->tx_ring_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002668 /* save current HW position */
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002669 if (np->tx_change_owner)
2670 put_tx.ex = np->tx_change_owner->first_tx_desc;
2671 else
2672 put_tx = np->put_tx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002673
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002674 /* 3) clear all tx state */
2675 nv_drain_tx(dev);
2676 nv_init_tx(dev);
Ayaz Abdulla3ba4d092007-03-23 05:50:02 -05002677
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002678 /* 4) restore state to current HW position */
2679 np->get_tx = np->put_tx = put_tx;
2680 np->tx_limit = saved_tx_limit;
2681
2682 /* 5) restart tx engine */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002683 nv_start_tx(dev);
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002684 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 spin_unlock_irq(&np->lock);
2686}
2687
Manfred Spraul22c6d142005-04-19 21:17:09 +02002688/*
2689 * Called when the nic notices a mismatch between the actual data len on the
2690 * wire and the len indicated in the 802 header
2691 */
2692static int nv_getlen(struct net_device *dev, void *packet, int datalen)
2693{
2694 int hdrlen; /* length of the 802 header */
2695 int protolen; /* length as stored in the proto field */
2696
2697 /* 1) calculate len according to header */
Szymon Janc78aea4f2010-11-27 08:39:43 +00002698 if (((struct vlan_ethhdr *)packet)->h_vlan_proto == htons(ETH_P_8021Q)) {
2699 protolen = ntohs(((struct vlan_ethhdr *)packet)->h_vlan_encapsulated_proto);
Manfred Spraul22c6d142005-04-19 21:17:09 +02002700 hdrlen = VLAN_HLEN;
2701 } else {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002702 protolen = ntohs(((struct ethhdr *)packet)->h_proto);
Manfred Spraul22c6d142005-04-19 21:17:09 +02002703 hdrlen = ETH_HLEN;
2704 }
Manfred Spraul22c6d142005-04-19 21:17:09 +02002705 if (protolen > ETH_DATA_LEN)
2706 return datalen; /* Value in proto field not a len, no checks possible */
2707
2708 protolen += hdrlen;
2709 /* consistency checks: */
2710 if (datalen > ETH_ZLEN) {
2711 if (datalen >= protolen) {
2712 /* more data on wire than in 802 header, trim of
2713 * additional data.
2714 */
Manfred Spraul22c6d142005-04-19 21:17:09 +02002715 return protolen;
2716 } else {
2717 /* less data on wire than mentioned in header.
2718 * Discard the packet.
2719 */
Manfred Spraul22c6d142005-04-19 21:17:09 +02002720 return -1;
2721 }
2722 } else {
2723 /* short packet. Accept only if 802 values are also short */
2724 if (protolen > ETH_ZLEN) {
Manfred Spraul22c6d142005-04-19 21:17:09 +02002725 return -1;
2726 }
Manfred Spraul22c6d142005-04-19 21:17:09 +02002727 return datalen;
2728 }
2729}
2730
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002731static int nv_rx_process(struct net_device *dev, int limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002732{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002733 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002734 u32 flags;
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002735 int rx_work = 0;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002736 struct sk_buff *skb;
2737 int len;
Ayaz Abdullaee407b02006-02-04 13:13:17 -05002738
Szymon Janc78aea4f2010-11-27 08:39:43 +00002739 while ((np->get_rx.orig != np->put_rx.orig) &&
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002740 !((flags = le32_to_cpu(np->get_rx.orig->flaglen)) & NV_RX_AVAIL) &&
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002741 (rx_work < limit)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742
Linus Torvalds1da177e2005-04-16 15:20:36 -07002743 /*
2744 * the packet is for us - immediately tear down the pci mapping.
2745 * TODO: check if a prefetch of the first cacheline improves
2746 * the performance.
2747 */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002748 pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma,
2749 np->get_rx_ctx->dma_len,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 PCI_DMA_FROMDEVICE);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002751 skb = np->get_rx_ctx->skb;
2752 np->get_rx_ctx->skb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002753
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 /* look at what we actually got: */
2755 if (np->desc_ver == DESC_VER_1) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002756 if (likely(flags & NV_RX_DESCRIPTORVALID)) {
2757 len = flags & LEN_MASK_V1;
2758 if (unlikely(flags & NV_RX_ERROR)) {
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002759 if ((flags & NV_RX_ERROR_MASK) == NV_RX_ERROR4) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002760 len = nv_getlen(dev, skb->data, len);
2761 if (len < 0) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002762 dev_kfree_skb(skb);
2763 goto next_pkt;
2764 }
2765 }
2766 /* framing errors are soft errors */
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002767 else if ((flags & NV_RX_ERROR_MASK) == NV_RX_FRAMINGERR) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002768 if (flags & NV_RX_SUBSTRACT1)
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002769 len--;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002770 }
2771 /* the rest are hard errors */
2772 else {
david decotignyf5d827a2011-11-16 12:15:13 +00002773 if (flags & NV_RX_MISSEDFRAME) {
2774 u64_stats_update_begin(&np->swstats_rx_syncp);
2775 np->stat_rx_missed_errors++;
2776 u64_stats_update_end(&np->swstats_rx_syncp);
2777 }
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002778 dev_kfree_skb(skb);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002779 goto next_pkt;
2780 }
2781 }
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002782 } else {
2783 dev_kfree_skb(skb);
2784 goto next_pkt;
Manfred Spraul22c6d142005-04-19 21:17:09 +02002785 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002786 } else {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002787 if (likely(flags & NV_RX2_DESCRIPTORVALID)) {
2788 len = flags & LEN_MASK_V2;
2789 if (unlikely(flags & NV_RX2_ERROR)) {
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002790 if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_ERROR4) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002791 len = nv_getlen(dev, skb->data, len);
2792 if (len < 0) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002793 dev_kfree_skb(skb);
2794 goto next_pkt;
2795 }
2796 }
2797 /* framing errors are soft errors */
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002798 else if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_FRAMINGERR) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002799 if (flags & NV_RX2_SUBSTRACT1)
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002800 len--;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002801 }
2802 /* the rest are hard errors */
2803 else {
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002804 dev_kfree_skb(skb);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002805 goto next_pkt;
2806 }
2807 }
Ayaz Abdullabfaffe82008-01-13 16:02:55 -05002808 if (((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_TCP) || /*ip and tcp */
2809 ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_UDP)) /*ip and udp */
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002810 skb->ip_summed = CHECKSUM_UNNECESSARY;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002811 } else {
2812 dev_kfree_skb(skb);
2813 goto next_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002814 }
2815 }
2816 /* got a valid packet - forward it to the network core */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817 skb_put(skb, len);
2818 skb->protocol = eth_type_trans(skb, dev);
Tom Herbert53f224c2010-05-03 19:08:45 +00002819 napi_gro_receive(&np->napi, skb);
david decotignyf5d827a2011-11-16 12:15:13 +00002820 u64_stats_update_begin(&np->swstats_rx_syncp);
2821 np->stat_rx_packets++;
2822 np->stat_rx_bytes += len;
2823 u64_stats_update_end(&np->swstats_rx_syncp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002824next_pkt:
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002825 if (unlikely(np->get_rx.orig++ == np->last_rx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002826 np->get_rx.orig = np->first_rx.orig;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002827 if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002828 np->get_rx_ctx = np->first_rx_ctx;
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002829
2830 rx_work++;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002831 }
2832
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002833 return rx_work;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002834}
2835
2836static int nv_rx_process_optimized(struct net_device *dev, int limit)
2837{
2838 struct fe_priv *np = netdev_priv(dev);
2839 u32 flags;
2840 u32 vlanflags = 0;
Ingo Molnarc1b71512007-10-17 12:18:23 +02002841 int rx_work = 0;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002842 struct sk_buff *skb;
2843 int len;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002844
Szymon Janc78aea4f2010-11-27 08:39:43 +00002845 while ((np->get_rx.ex != np->put_rx.ex) &&
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002846 !((flags = le32_to_cpu(np->get_rx.ex->flaglen)) & NV_RX2_AVAIL) &&
Ingo Molnarc1b71512007-10-17 12:18:23 +02002847 (rx_work < limit)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002848
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002849 /*
2850 * the packet is for us - immediately tear down the pci mapping.
2851 * TODO: check if a prefetch of the first cacheline improves
2852 * the performance.
2853 */
2854 pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma,
2855 np->get_rx_ctx->dma_len,
2856 PCI_DMA_FROMDEVICE);
2857 skb = np->get_rx_ctx->skb;
2858 np->get_rx_ctx->skb = NULL;
2859
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002860 /* look at what we actually got: */
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002861 if (likely(flags & NV_RX2_DESCRIPTORVALID)) {
2862 len = flags & LEN_MASK_V2;
2863 if (unlikely(flags & NV_RX2_ERROR)) {
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002864 if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_ERROR4) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002865 len = nv_getlen(dev, skb->data, len);
2866 if (len < 0) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002867 dev_kfree_skb(skb);
2868 goto next_pkt;
2869 }
2870 }
2871 /* framing errors are soft errors */
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002872 else if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_FRAMINGERR) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002873 if (flags & NV_RX2_SUBSTRACT1)
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002874 len--;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002875 }
2876 /* the rest are hard errors */
2877 else {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002878 dev_kfree_skb(skb);
2879 goto next_pkt;
2880 }
2881 }
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002882
Ayaz Abdullabfaffe82008-01-13 16:02:55 -05002883 if (((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_TCP) || /*ip and tcp */
2884 ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_UDP)) /*ip and udp */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002885 skb->ip_summed = CHECKSUM_UNNECESSARY;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002886
2887 /* got a valid packet - forward it to the network core */
2888 skb_put(skb, len);
2889 skb->protocol = eth_type_trans(skb, dev);
2890 prefetch(skb->data);
2891
Jiri Pirko3326c782011-07-20 04:54:38 +00002892 vlanflags = le32_to_cpu(np->get_rx.ex->buflow);
Jiri Pirko0891b0e2011-07-26 10:19:28 +00002893
2894 /*
2895 * There's need to check for NETIF_F_HW_VLAN_RX here.
2896 * Even if vlan rx accel is disabled,
2897 * NV_RX3_VLAN_TAG_PRESENT is pseudo randomly set.
2898 */
2899 if (dev->features & NETIF_F_HW_VLAN_RX &&
2900 vlanflags & NV_RX3_VLAN_TAG_PRESENT) {
Jiri Pirko3326c782011-07-20 04:54:38 +00002901 u16 vid = vlanflags & NV_RX3_VLAN_TAG_MASK;
2902
2903 __vlan_hwaccel_put_tag(skb, vid);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002904 }
Jiri Pirko3326c782011-07-20 04:54:38 +00002905 napi_gro_receive(&np->napi, skb);
david decotignyf5d827a2011-11-16 12:15:13 +00002906 u64_stats_update_begin(&np->swstats_rx_syncp);
2907 np->stat_rx_packets++;
2908 np->stat_rx_bytes += len;
2909 u64_stats_update_end(&np->swstats_rx_syncp);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002910 } else {
2911 dev_kfree_skb(skb);
2912 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002913next_pkt:
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002914 if (unlikely(np->get_rx.ex++ == np->last_rx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002915 np->get_rx.ex = np->first_rx.ex;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002916 if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002917 np->get_rx_ctx = np->first_rx_ctx;
Ingo Molnarc1b71512007-10-17 12:18:23 +02002918
2919 rx_work++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002920 }
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002921
Ingo Molnarc1b71512007-10-17 12:18:23 +02002922 return rx_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923}
2924
Manfred Sprauld81c0982005-07-31 18:20:30 +02002925static void set_bufsize(struct net_device *dev)
2926{
2927 struct fe_priv *np = netdev_priv(dev);
2928
2929 if (dev->mtu <= ETH_DATA_LEN)
2930 np->rx_buf_sz = ETH_DATA_LEN + NV_RX_HEADERS;
2931 else
2932 np->rx_buf_sz = dev->mtu + NV_RX_HEADERS;
2933}
2934
Linus Torvalds1da177e2005-04-16 15:20:36 -07002935/*
2936 * nv_change_mtu: dev->change_mtu function
2937 * Called with dev_base_lock held for read.
2938 */
2939static int nv_change_mtu(struct net_device *dev, int new_mtu)
2940{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002941 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002942 int old_mtu;
2943
2944 if (new_mtu < 64 || new_mtu > np->pkt_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945 return -EINVAL;
Manfred Sprauld81c0982005-07-31 18:20:30 +02002946
2947 old_mtu = dev->mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948 dev->mtu = new_mtu;
Manfred Sprauld81c0982005-07-31 18:20:30 +02002949
2950 /* return early if the buffer sizes will not change */
2951 if (old_mtu <= ETH_DATA_LEN && new_mtu <= ETH_DATA_LEN)
2952 return 0;
2953 if (old_mtu == new_mtu)
2954 return 0;
2955
2956 /* synchronized against open : rtnl_lock() held by caller */
2957 if (netif_running(dev)) {
viro@ftp.linux.org.uk25097d42005-09-06 01:36:58 +01002958 u8 __iomem *base = get_hwbase(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002959 /*
2960 * It seems that the nic preloads valid ring entries into an
2961 * internal buffer. The procedure for flushing everything is
2962 * guessed, there is probably a simpler approach.
2963 * Changing the MTU is a rare event, it shouldn't matter.
2964 */
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002965 nv_disable_irq(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00002966 nv_napi_disable(dev);
Herbert Xu932ff272006-06-09 12:20:56 -07002967 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07002968 netif_addr_lock(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002969 spin_lock(&np->lock);
2970 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002971 nv_stop_rxtx(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002972 nv_txrx_reset(dev);
2973 /* drain rx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002974 nv_drain_rxtx(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002975 /* reinit driver view of the rx queue */
Manfred Sprauld81c0982005-07-31 18:20:30 +02002976 set_bufsize(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04002977 if (nv_init_ring(dev)) {
Manfred Sprauld81c0982005-07-31 18:20:30 +02002978 if (!np->in_shutdown)
2979 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2980 }
2981 /* reinit nic view of the rx queue */
2982 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
Ayaz Abdulla0832b252006-02-04 13:13:26 -05002983 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00002984 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Manfred Sprauld81c0982005-07-31 18:20:30 +02002985 base + NvRegRingSizes);
2986 pci_push(base);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002987 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002988 pci_push(base);
2989
2990 /* restart rx engine */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002991 nv_start_rxtx(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002992 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07002993 netif_addr_unlock(dev);
Herbert Xu932ff272006-06-09 12:20:56 -07002994 netif_tx_unlock_bh(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00002995 nv_napi_enable(dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002996 nv_enable_irq(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002997 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002998 return 0;
2999}
3000
Manfred Spraul72b31782005-07-31 18:33:34 +02003001static void nv_copy_mac_to_hw(struct net_device *dev)
3002{
viro@ftp.linux.org.uk25097d42005-09-06 01:36:58 +01003003 u8 __iomem *base = get_hwbase(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02003004 u32 mac[2];
3005
3006 mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) +
3007 (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24);
3008 mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8);
3009
3010 writel(mac[0], base + NvRegMacAddrA);
3011 writel(mac[1], base + NvRegMacAddrB);
3012}
3013
3014/*
3015 * nv_set_mac_address: dev->set_mac_address function
3016 * Called with rtnl_lock() held.
3017 */
3018static int nv_set_mac_address(struct net_device *dev, void *addr)
3019{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003020 struct fe_priv *np = netdev_priv(dev);
Szymon Janc78aea4f2010-11-27 08:39:43 +00003021 struct sockaddr *macaddr = (struct sockaddr *)addr;
Manfred Spraul72b31782005-07-31 18:33:34 +02003022
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003023 if (!is_valid_ether_addr(macaddr->sa_data))
Manfred Spraul72b31782005-07-31 18:33:34 +02003024 return -EADDRNOTAVAIL;
3025
3026 /* synchronized against open : rtnl_lock() held by caller */
3027 memcpy(dev->dev_addr, macaddr->sa_data, ETH_ALEN);
Danny Kukawka7ce5d222012-02-15 06:45:40 +00003028 dev->addr_assign_type &= ~NET_ADDR_RANDOM;
Manfred Spraul72b31782005-07-31 18:33:34 +02003029
3030 if (netif_running(dev)) {
Herbert Xu932ff272006-06-09 12:20:56 -07003031 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07003032 netif_addr_lock(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02003033 spin_lock_irq(&np->lock);
3034
3035 /* stop rx engine */
3036 nv_stop_rx(dev);
3037
3038 /* set mac address */
3039 nv_copy_mac_to_hw(dev);
3040
3041 /* restart rx engine */
3042 nv_start_rx(dev);
3043 spin_unlock_irq(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07003044 netif_addr_unlock(dev);
Herbert Xu932ff272006-06-09 12:20:56 -07003045 netif_tx_unlock_bh(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02003046 } else {
3047 nv_copy_mac_to_hw(dev);
3048 }
3049 return 0;
3050}
3051
Linus Torvalds1da177e2005-04-16 15:20:36 -07003052/*
3053 * nv_set_multicast: dev->set_multicast function
Herbert Xu932ff272006-06-09 12:20:56 -07003054 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 */
3056static void nv_set_multicast(struct net_device *dev)
3057{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003058 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 u8 __iomem *base = get_hwbase(dev);
3060 u32 addr[2];
3061 u32 mask[2];
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003062 u32 pff = readl(base + NvRegPacketFilterFlags) & NVREG_PFF_PAUSE_RX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003063
3064 memset(addr, 0, sizeof(addr));
3065 memset(mask, 0, sizeof(mask));
3066
3067 if (dev->flags & IFF_PROMISC) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003068 pff |= NVREG_PFF_PROMISC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003069 } else {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003070 pff |= NVREG_PFF_MYADDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003071
Jiri Pirko48e2f182010-02-22 09:22:26 +00003072 if (dev->flags & IFF_ALLMULTI || !netdev_mc_empty(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003073 u32 alwaysOff[2];
3074 u32 alwaysOn[2];
3075
3076 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0xffffffff;
3077 if (dev->flags & IFF_ALLMULTI) {
3078 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0;
3079 } else {
Jiri Pirko22bedad32010-04-01 21:22:57 +00003080 struct netdev_hw_addr *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003081
Jiri Pirko22bedad32010-04-01 21:22:57 +00003082 netdev_for_each_mc_addr(ha, dev) {
david decotignye45a6182011-11-05 14:38:24 +00003083 unsigned char *hw_addr = ha->addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003084 u32 a, b;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003085
david decotignye45a6182011-11-05 14:38:24 +00003086 a = le32_to_cpu(*(__le32 *) hw_addr);
3087 b = le16_to_cpu(*(__le16 *) (&hw_addr[4]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003088 alwaysOn[0] &= a;
3089 alwaysOff[0] &= ~a;
3090 alwaysOn[1] &= b;
3091 alwaysOff[1] &= ~b;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003092 }
3093 }
3094 addr[0] = alwaysOn[0];
3095 addr[1] = alwaysOn[1];
3096 mask[0] = alwaysOn[0] | alwaysOff[0];
3097 mask[1] = alwaysOn[1] | alwaysOff[1];
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -05003098 } else {
3099 mask[0] = NVREG_MCASTMASKA_NONE;
3100 mask[1] = NVREG_MCASTMASKB_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003101 }
3102 }
3103 addr[0] |= NVREG_MCASTADDRA_FORCE;
3104 pff |= NVREG_PFF_ALWAYS;
3105 spin_lock_irq(&np->lock);
3106 nv_stop_rx(dev);
3107 writel(addr[0], base + NvRegMulticastAddrA);
3108 writel(addr[1], base + NvRegMulticastAddrB);
3109 writel(mask[0], base + NvRegMulticastMaskA);
3110 writel(mask[1], base + NvRegMulticastMaskB);
3111 writel(pff, base + NvRegPacketFilterFlags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003112 nv_start_rx(dev);
3113 spin_unlock_irq(&np->lock);
3114}
3115
Adrian Bunkc7985052006-06-22 12:03:29 +02003116static void nv_update_pause(struct net_device *dev, u32 pause_flags)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003117{
3118 struct fe_priv *np = netdev_priv(dev);
3119 u8 __iomem *base = get_hwbase(dev);
3120
3121 np->pause_flags &= ~(NV_PAUSEFRAME_TX_ENABLE | NV_PAUSEFRAME_RX_ENABLE);
3122
3123 if (np->pause_flags & NV_PAUSEFRAME_RX_CAPABLE) {
3124 u32 pff = readl(base + NvRegPacketFilterFlags) & ~NVREG_PFF_PAUSE_RX;
3125 if (pause_flags & NV_PAUSEFRAME_RX_ENABLE) {
3126 writel(pff|NVREG_PFF_PAUSE_RX, base + NvRegPacketFilterFlags);
3127 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3128 } else {
3129 writel(pff, base + NvRegPacketFilterFlags);
3130 }
3131 }
3132 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE) {
3133 u32 regmisc = readl(base + NvRegMisc1) & ~NVREG_MISC1_PAUSE_TX;
3134 if (pause_flags & NV_PAUSEFRAME_TX_ENABLE) {
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05003135 u32 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V1;
3136 if (np->driver_data & DEV_HAS_PAUSEFRAME_TX_V2)
3137 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V2;
Ayaz Abdulla9a33e882008-08-06 12:12:34 -04003138 if (np->driver_data & DEV_HAS_PAUSEFRAME_TX_V3) {
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05003139 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V3;
Ayaz Abdulla9a33e882008-08-06 12:12:34 -04003140 /* limit the number of tx pause frames to a default of 8 */
3141 writel(readl(base + NvRegTxPauseFrameLimit)|NVREG_TX_PAUSEFRAMELIMIT_ENABLE, base + NvRegTxPauseFrameLimit);
3142 }
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05003143 writel(pause_enable, base + NvRegTxPauseFrame);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003144 writel(regmisc|NVREG_MISC1_PAUSE_TX, base + NvRegMisc1);
3145 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3146 } else {
3147 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
3148 writel(regmisc, base + NvRegMisc1);
3149 }
3150 }
3151}
3152
Sanjay Hortikare19df762011-11-11 16:11:21 +00003153static void nv_force_linkspeed(struct net_device *dev, int speed, int duplex)
3154{
3155 struct fe_priv *np = netdev_priv(dev);
3156 u8 __iomem *base = get_hwbase(dev);
3157 u32 phyreg, txreg;
3158 int mii_status;
3159
3160 np->linkspeed = NVREG_LINKSPEED_FORCE|speed;
3161 np->duplex = duplex;
3162
3163 /* see if gigabit phy */
3164 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
3165 if (mii_status & PHY_GIGABIT) {
3166 np->gigabit = PHY_GIGABIT;
3167 phyreg = readl(base + NvRegSlotTime);
3168 phyreg &= ~(0x3FF00);
3169 if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10)
3170 phyreg |= NVREG_SLOTTIME_10_100_FULL;
3171 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100)
3172 phyreg |= NVREG_SLOTTIME_10_100_FULL;
3173 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000)
3174 phyreg |= NVREG_SLOTTIME_1000_FULL;
3175 writel(phyreg, base + NvRegSlotTime);
3176 }
3177
3178 phyreg = readl(base + NvRegPhyInterface);
3179 phyreg &= ~(PHY_HALF|PHY_100|PHY_1000);
3180 if (np->duplex == 0)
3181 phyreg |= PHY_HALF;
3182 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100)
3183 phyreg |= PHY_100;
3184 else if ((np->linkspeed & NVREG_LINKSPEED_MASK) ==
3185 NVREG_LINKSPEED_1000)
3186 phyreg |= PHY_1000;
3187 writel(phyreg, base + NvRegPhyInterface);
3188
3189 if (phyreg & PHY_RGMII) {
3190 if ((np->linkspeed & NVREG_LINKSPEED_MASK) ==
3191 NVREG_LINKSPEED_1000)
3192 txreg = NVREG_TX_DEFERRAL_RGMII_1000;
3193 else
3194 txreg = NVREG_TX_DEFERRAL_RGMII_10_100;
3195 } else {
3196 txreg = NVREG_TX_DEFERRAL_DEFAULT;
3197 }
3198 writel(txreg, base + NvRegTxDeferral);
3199
3200 if (np->desc_ver == DESC_VER_1) {
3201 txreg = NVREG_TX_WM_DESC1_DEFAULT;
3202 } else {
3203 if ((np->linkspeed & NVREG_LINKSPEED_MASK) ==
3204 NVREG_LINKSPEED_1000)
3205 txreg = NVREG_TX_WM_DESC2_3_1000;
3206 else
3207 txreg = NVREG_TX_WM_DESC2_3_DEFAULT;
3208 }
3209 writel(txreg, base + NvRegTxWatermark);
3210
3211 writel(NVREG_MISC1_FORCE | (np->duplex ? 0 : NVREG_MISC1_HD),
3212 base + NvRegMisc1);
3213 pci_push(base);
3214 writel(np->linkspeed, base + NvRegLinkSpeed);
3215 pci_push(base);
3216
3217 return;
3218}
3219
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05003220/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003221 * nv_update_linkspeed - Setup the MAC according to the link partner
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05003222 * @dev: Network device to be configured
3223 *
3224 * The function queries the PHY and checks if there is a link partner.
3225 * If yes, then it sets up the MAC accordingly. Otherwise, the MAC is
3226 * set to 10 MBit HD.
3227 *
3228 * The function returns 0 if there is no link partner and 1 if there is
3229 * a good link partner.
3230 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003231static int nv_update_linkspeed(struct net_device *dev)
3232{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003233 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003235 int adv = 0;
3236 int lpa = 0;
3237 int adv_lpa, adv_pause, lpa_pause;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003238 int newls = np->linkspeed;
3239 int newdup = np->duplex;
3240 int mii_status;
Sanjay Hortikare19df762011-11-11 16:11:21 +00003241 u32 bmcr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242 int retval = 0;
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003243 u32 control_1000, status_1000, phyreg, pause_flags, txreg;
Ayaz Abdullab2976d22008-02-04 15:13:59 -05003244 u32 txrxFlags = 0;
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003245 u32 phy_exp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003246
Sanjay Hortikare19df762011-11-11 16:11:21 +00003247 /* If device loopback is enabled, set carrier on and enable max link
3248 * speed.
3249 */
3250 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
3251 if (bmcr & BMCR_LOOPBACK) {
3252 if (netif_running(dev)) {
3253 nv_force_linkspeed(dev, NVREG_LINKSPEED_1000, 1);
3254 if (!netif_carrier_ok(dev))
3255 netif_carrier_on(dev);
3256 }
3257 return 1;
3258 }
3259
Linus Torvalds1da177e2005-04-16 15:20:36 -07003260 /* BMSR_LSTATUS is latched, read it twice:
3261 * we want the current value.
3262 */
3263 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
3264 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
3265
3266 if (!(mii_status & BMSR_LSTATUS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003267 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3268 newdup = 0;
3269 retval = 0;
3270 goto set_speed;
3271 }
3272
3273 if (np->autoneg == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003274 if (np->fixed_mode & LPA_100FULL) {
3275 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3276 newdup = 1;
3277 } else if (np->fixed_mode & LPA_100HALF) {
3278 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3279 newdup = 0;
3280 } else if (np->fixed_mode & LPA_10FULL) {
3281 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3282 newdup = 1;
3283 } else {
3284 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3285 newdup = 0;
3286 }
3287 retval = 1;
3288 goto set_speed;
3289 }
3290 /* check auto negotiation is complete */
3291 if (!(mii_status & BMSR_ANEGCOMPLETE)) {
3292 /* still in autonegotiation - configure nic for 10 MBit HD and wait. */
3293 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3294 newdup = 0;
3295 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003296 goto set_speed;
3297 }
3298
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003299 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
3300 lpa = mii_rw(dev, np->phyaddr, MII_LPA, MII_READ);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003301
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302 retval = 1;
3303 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003304 control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
3305 status_1000 = mii_rw(dev, np->phyaddr, MII_STAT1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306
3307 if ((control_1000 & ADVERTISE_1000FULL) &&
3308 (status_1000 & LPA_1000FULL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003309 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_1000;
3310 newdup = 1;
3311 goto set_speed;
3312 }
3313 }
3314
Linus Torvalds1da177e2005-04-16 15:20:36 -07003315 /* FIXME: handle parallel detection properly */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003316 adv_lpa = lpa & adv;
3317 if (adv_lpa & LPA_100FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3319 newdup = 1;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003320 } else if (adv_lpa & LPA_100HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003321 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3322 newdup = 0;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003323 } else if (adv_lpa & LPA_10FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3325 newdup = 1;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003326 } else if (adv_lpa & LPA_10HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3328 newdup = 0;
3329 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003330 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3331 newdup = 0;
3332 }
3333
3334set_speed:
3335 if (np->duplex == newdup && np->linkspeed == newls)
3336 return retval;
3337
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338 np->duplex = newdup;
3339 np->linkspeed = newls;
3340
Ayaz Abdullab2976d22008-02-04 15:13:59 -05003341 /* The transmitter and receiver must be restarted for safe update */
3342 if (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_START) {
3343 txrxFlags |= NV_RESTART_TX;
3344 nv_stop_tx(dev);
3345 }
3346 if (readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) {
3347 txrxFlags |= NV_RESTART_RX;
3348 nv_stop_rx(dev);
3349 }
3350
Linus Torvalds1da177e2005-04-16 15:20:36 -07003351 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaa4336862008-04-18 13:50:43 -07003352 phyreg = readl(base + NvRegSlotTime);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003353 phyreg &= ~(0x3FF00);
Ayaz Abdullaa4336862008-04-18 13:50:43 -07003354 if (((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10) ||
3355 ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100))
3356 phyreg |= NVREG_SLOTTIME_10_100_FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003357 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000)
Ayaz Abdullaa4336862008-04-18 13:50:43 -07003358 phyreg |= NVREG_SLOTTIME_1000_FULL;
3359 writel(phyreg, base + NvRegSlotTime);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003360 }
3361
3362 phyreg = readl(base + NvRegPhyInterface);
3363 phyreg &= ~(PHY_HALF|PHY_100|PHY_1000);
3364 if (np->duplex == 0)
3365 phyreg |= PHY_HALF;
3366 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100)
3367 phyreg |= PHY_100;
3368 else if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
3369 phyreg |= PHY_1000;
3370 writel(phyreg, base + NvRegPhyInterface);
3371
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003372 phy_exp = mii_rw(dev, np->phyaddr, MII_EXPANSION, MII_READ) & EXPANSION_NWAY; /* autoneg capable */
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003373 if (phyreg & PHY_RGMII) {
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003374 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000) {
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003375 txreg = NVREG_TX_DEFERRAL_RGMII_1000;
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003376 } else {
3377 if (!phy_exp && !np->duplex && (np->driver_data & DEV_HAS_COLLISION_FIX)) {
3378 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_10)
3379 txreg = NVREG_TX_DEFERRAL_RGMII_STRETCH_10;
3380 else
3381 txreg = NVREG_TX_DEFERRAL_RGMII_STRETCH_100;
3382 } else {
3383 txreg = NVREG_TX_DEFERRAL_RGMII_10_100;
3384 }
3385 }
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003386 } else {
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003387 if (!phy_exp && !np->duplex && (np->driver_data & DEV_HAS_COLLISION_FIX))
3388 txreg = NVREG_TX_DEFERRAL_MII_STRETCH;
3389 else
3390 txreg = NVREG_TX_DEFERRAL_DEFAULT;
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003391 }
3392 writel(txreg, base + NvRegTxDeferral);
3393
Ayaz Abdulla95d161c2006-07-06 16:46:25 -04003394 if (np->desc_ver == DESC_VER_1) {
3395 txreg = NVREG_TX_WM_DESC1_DEFAULT;
3396 } else {
3397 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
3398 txreg = NVREG_TX_WM_DESC2_3_1000;
3399 else
3400 txreg = NVREG_TX_WM_DESC2_3_DEFAULT;
3401 }
3402 writel(txreg, base + NvRegTxWatermark);
3403
Szymon Janc78aea4f2010-11-27 08:39:43 +00003404 writel(NVREG_MISC1_FORCE | (np->duplex ? 0 : NVREG_MISC1_HD),
Linus Torvalds1da177e2005-04-16 15:20:36 -07003405 base + NvRegMisc1);
3406 pci_push(base);
3407 writel(np->linkspeed, base + NvRegLinkSpeed);
3408 pci_push(base);
3409
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003410 pause_flags = 0;
3411 /* setup pause frame */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003412 if (np->duplex != 0) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003413 if (np->autoneg && np->pause_flags & NV_PAUSEFRAME_AUTONEG) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003414 adv_pause = adv & (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
3415 lpa_pause = lpa & (LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003416
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003417 switch (adv_pause) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003418 case ADVERTISE_PAUSE_CAP:
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003419 if (lpa_pause & LPA_PAUSE_CAP) {
3420 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3421 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
3422 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3423 }
3424 break;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003425 case ADVERTISE_PAUSE_ASYM:
Szymon Janc78aea4f2010-11-27 08:39:43 +00003426 if (lpa_pause == (LPA_PAUSE_CAP | LPA_PAUSE_ASYM))
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003427 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003428 break;
Szymon Janc78aea4f2010-11-27 08:39:43 +00003429 case ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM:
3430 if (lpa_pause & LPA_PAUSE_CAP) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003431 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3432 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
3433 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3434 }
3435 if (lpa_pause == LPA_PAUSE_ASYM)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003436 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003437 break;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003438 }
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003439 } else {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003440 pause_flags = np->pause_flags;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003441 }
3442 }
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003443 nv_update_pause(dev, pause_flags);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003444
Ayaz Abdullab2976d22008-02-04 15:13:59 -05003445 if (txrxFlags & NV_RESTART_TX)
3446 nv_start_tx(dev);
3447 if (txrxFlags & NV_RESTART_RX)
3448 nv_start_rx(dev);
3449
Linus Torvalds1da177e2005-04-16 15:20:36 -07003450 return retval;
3451}
3452
3453static void nv_linkchange(struct net_device *dev)
3454{
3455 if (nv_update_linkspeed(dev)) {
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05003456 if (!netif_carrier_ok(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 netif_carrier_on(dev);
Joe Perches1d397f32010-11-29 07:41:57 +00003458 netdev_info(dev, "link up\n");
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00003459 nv_txrx_gate(dev, false);
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05003460 nv_start_rx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003461 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462 } else {
3463 if (netif_carrier_ok(dev)) {
3464 netif_carrier_off(dev);
Joe Perches1d397f32010-11-29 07:41:57 +00003465 netdev_info(dev, "link down\n");
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00003466 nv_txrx_gate(dev, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003467 nv_stop_rx(dev);
3468 }
3469 }
3470}
3471
3472static void nv_link_irq(struct net_device *dev)
3473{
3474 u8 __iomem *base = get_hwbase(dev);
3475 u32 miistat;
3476
3477 miistat = readl(base + NvRegMIIStatus);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05003478 writel(NVREG_MIISTAT_LINKCHANGE, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003479
3480 if (miistat & (NVREG_MIISTAT_LINKCHANGE))
3481 nv_linkchange(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003482}
3483
Ayaz Abdulla4db0ee172008-06-09 16:51:06 -07003484static void nv_msi_workaround(struct fe_priv *np)
3485{
3486
3487 /* Need to toggle the msi irq mask within the ethernet device,
3488 * otherwise, future interrupts will not be detected.
3489 */
3490 if (np->msi_flags & NV_MSI_ENABLED) {
3491 u8 __iomem *base = np->base;
3492
3493 writel(0, base + NvRegMSIIrqMask);
3494 writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask);
3495 }
3496}
3497
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003498static inline int nv_change_interrupt_mode(struct net_device *dev, int total_work)
3499{
3500 struct fe_priv *np = netdev_priv(dev);
3501
3502 if (optimization_mode == NV_OPTIMIZATION_MODE_DYNAMIC) {
3503 if (total_work > NV_DYNAMIC_THRESHOLD) {
3504 /* transition to poll based interrupts */
3505 np->quiet_count = 0;
3506 if (np->irqmask != NVREG_IRQMASK_CPU) {
3507 np->irqmask = NVREG_IRQMASK_CPU;
3508 return 1;
3509 }
3510 } else {
3511 if (np->quiet_count < NV_DYNAMIC_MAX_QUIET_COUNT) {
3512 np->quiet_count++;
3513 } else {
3514 /* reached a period of low activity, switch
3515 to per tx/rx packet interrupts */
3516 if (np->irqmask != NVREG_IRQMASK_THROUGHPUT) {
3517 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
3518 return 1;
3519 }
3520 }
3521 }
3522 }
3523 return 0;
3524}
3525
David Howells7d12e782006-10-05 14:55:46 +01003526static irqreturn_t nv_nic_irq(int foo, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003527{
3528 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003529 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 u8 __iomem *base = get_hwbase(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003531
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003532 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3533 np->events = readl(base + NvRegIrqStatus);
Ayaz Abdulla1b2bb762009-03-05 08:02:34 +00003534 writel(np->events, base + NvRegIrqStatus);
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003535 } else {
3536 np->events = readl(base + NvRegMSIXIrqStatus);
Ayaz Abdulla1b2bb762009-03-05 08:02:34 +00003537 writel(np->events, base + NvRegMSIXIrqStatus);
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003538 }
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003539 if (!(np->events & np->irqmask))
3540 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003541
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003542 nv_msi_workaround(np);
Ayaz Abdulla4db0ee172008-06-09 16:51:06 -07003543
Eric Dumazet78c29bd2009-07-02 04:04:45 +00003544 if (napi_schedule_prep(&np->napi)) {
3545 /*
3546 * Disable further irq's (msix not enabled with napi)
3547 */
3548 writel(0, base + NvRegIrqMask);
3549 __napi_schedule(&np->napi);
3550 }
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003551
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003552 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003553}
3554
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003555/**
3556 * All _optimized functions are used to help increase performance
3557 * (reduce CPU and increase throughput). They use descripter version 3,
3558 * compiler directives, and reduce memory accesses.
3559 */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003560static irqreturn_t nv_nic_irq_optimized(int foo, void *data)
3561{
3562 struct net_device *dev = (struct net_device *) data;
3563 struct fe_priv *np = netdev_priv(dev);
3564 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003565
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003566 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3567 np->events = readl(base + NvRegIrqStatus);
Ayaz Abdulla1b2bb762009-03-05 08:02:34 +00003568 writel(np->events, base + NvRegIrqStatus);
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003569 } else {
3570 np->events = readl(base + NvRegMSIXIrqStatus);
Ayaz Abdulla1b2bb762009-03-05 08:02:34 +00003571 writel(np->events, base + NvRegMSIXIrqStatus);
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003572 }
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003573 if (!(np->events & np->irqmask))
3574 return IRQ_NONE;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003575
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003576 nv_msi_workaround(np);
Ayaz Abdulla4db0ee172008-06-09 16:51:06 -07003577
Eric Dumazet78c29bd2009-07-02 04:04:45 +00003578 if (napi_schedule_prep(&np->napi)) {
3579 /*
3580 * Disable further irq's (msix not enabled with napi)
3581 */
3582 writel(0, base + NvRegIrqMask);
3583 __napi_schedule(&np->napi);
3584 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003585
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003586 return IRQ_HANDLED;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003587}
3588
David Howells7d12e782006-10-05 14:55:46 +01003589static irqreturn_t nv_nic_irq_tx(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003590{
3591 struct net_device *dev = (struct net_device *) data;
3592 struct fe_priv *np = netdev_priv(dev);
3593 u8 __iomem *base = get_hwbase(dev);
3594 u32 events;
3595 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003596 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003597
Szymon Janc78aea4f2010-11-27 08:39:43 +00003598 for (i = 0;; i++) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003599 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_TX_ALL;
Mike Ditto2a4e7a02011-11-05 14:38:21 +00003600 writel(events, base + NvRegMSIXIrqStatus);
3601 netdev_dbg(dev, "tx irq events: %08x\n", events);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003602 if (!(events & np->irqmask))
3603 break;
3604
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003605 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05003606 nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003607 spin_unlock_irqrestore(&np->lock, flags);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003608
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003609 if (unlikely(i > max_interrupt_work)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003610 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003611 /* disable interrupts on the nic */
3612 writel(NVREG_IRQ_TX_ALL, base + NvRegIrqMask);
3613 pci_push(base);
3614
3615 if (!np->in_shutdown) {
3616 np->nic_poll_irq |= NVREG_IRQ_TX_ALL;
3617 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3618 }
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003619 spin_unlock_irqrestore(&np->lock, flags);
Joe Perchesc20ec762010-11-29 07:42:02 +00003620 netdev_dbg(dev, "%s: too many iterations (%d)\n",
3621 __func__, i);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003622 break;
3623 }
3624
3625 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003626
3627 return IRQ_RETVAL(i);
3628}
3629
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003630static int nv_napi_poll(struct napi_struct *napi, int budget)
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003631{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003632 struct fe_priv *np = container_of(napi, struct fe_priv, napi);
3633 struct net_device *dev = np->dev;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003634 u8 __iomem *base = get_hwbase(dev);
Francois Romieud15e9c42006-12-17 23:03:15 +01003635 unsigned long flags;
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003636 int retcode;
Szymon Janc78aea4f2010-11-27 08:39:43 +00003637 int rx_count, tx_work = 0, rx_work = 0;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003638
stephen hemminger81a2e362010-04-28 08:25:28 +00003639 do {
3640 if (!nv_optimized(np)) {
3641 spin_lock_irqsave(&np->lock, flags);
3642 tx_work += nv_tx_done(dev, np->tx_ring_size);
3643 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003644
Tom Herbertd951f722010-05-05 18:15:21 +00003645 rx_count = nv_rx_process(dev, budget - rx_work);
stephen hemminger81a2e362010-04-28 08:25:28 +00003646 retcode = nv_alloc_rx(dev);
3647 } else {
3648 spin_lock_irqsave(&np->lock, flags);
3649 tx_work += nv_tx_done_optimized(dev, np->tx_ring_size);
3650 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003651
Tom Herbertd951f722010-05-05 18:15:21 +00003652 rx_count = nv_rx_process_optimized(dev,
3653 budget - rx_work);
stephen hemminger81a2e362010-04-28 08:25:28 +00003654 retcode = nv_alloc_rx_optimized(dev);
3655 }
3656 } while (retcode == 0 &&
3657 rx_count > 0 && (rx_work += rx_count) < budget);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003658
Ayaz Abdullae0379a12007-02-20 03:34:30 -05003659 if (retcode) {
Francois Romieud15e9c42006-12-17 23:03:15 +01003660 spin_lock_irqsave(&np->lock, flags);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003661 if (!np->in_shutdown)
3662 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Francois Romieud15e9c42006-12-17 23:03:15 +01003663 spin_unlock_irqrestore(&np->lock, flags);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003664 }
3665
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003666 nv_change_interrupt_mode(dev, tx_work + rx_work);
3667
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003668 if (unlikely(np->events & NVREG_IRQ_LINK)) {
3669 spin_lock_irqsave(&np->lock, flags);
3670 nv_link_irq(dev);
3671 spin_unlock_irqrestore(&np->lock, flags);
3672 }
3673 if (unlikely(np->need_linktimer && time_after(jiffies, np->link_timeout))) {
3674 spin_lock_irqsave(&np->lock, flags);
3675 nv_linkchange(dev);
3676 spin_unlock_irqrestore(&np->lock, flags);
3677 np->link_timeout = jiffies + LINK_TIMEOUT;
3678 }
3679 if (unlikely(np->events & NVREG_IRQ_RECOVER_ERROR)) {
3680 spin_lock_irqsave(&np->lock, flags);
3681 if (!np->in_shutdown) {
3682 np->nic_poll_irq = np->irqmask;
3683 np->recover_error = 1;
3684 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3685 }
3686 spin_unlock_irqrestore(&np->lock, flags);
David S. Miller6c2da9c2009-04-09 01:09:33 -07003687 napi_complete(napi);
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003688 return rx_work;
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003689 }
3690
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003691 if (rx_work < budget) {
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003692 /* re-enable interrupts
3693 (msix not enabled in napi) */
David S. Miller6c2da9c2009-04-09 01:09:33 -07003694 napi_complete(napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003695
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003696 writel(np->irqmask, base + NvRegIrqMask);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003697 }
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003698 return rx_work;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003699}
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003700
David Howells7d12e782006-10-05 14:55:46 +01003701static irqreturn_t nv_nic_irq_rx(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003702{
3703 struct net_device *dev = (struct net_device *) data;
3704 struct fe_priv *np = netdev_priv(dev);
3705 u8 __iomem *base = get_hwbase(dev);
3706 u32 events;
3707 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003708 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003709
Szymon Janc78aea4f2010-11-27 08:39:43 +00003710 for (i = 0;; i++) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003711 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
Mike Ditto2a4e7a02011-11-05 14:38:21 +00003712 writel(events, base + NvRegMSIXIrqStatus);
3713 netdev_dbg(dev, "rx irq events: %08x\n", events);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003714 if (!(events & np->irqmask))
3715 break;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003716
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003717 if (nv_rx_process_optimized(dev, RX_WORK_PER_LOOP)) {
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003718 if (unlikely(nv_alloc_rx_optimized(dev))) {
3719 spin_lock_irqsave(&np->lock, flags);
3720 if (!np->in_shutdown)
3721 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3722 spin_unlock_irqrestore(&np->lock, flags);
3723 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003724 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003725
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003726 if (unlikely(i > max_interrupt_work)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003727 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003728 /* disable interrupts on the nic */
3729 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
3730 pci_push(base);
3731
3732 if (!np->in_shutdown) {
3733 np->nic_poll_irq |= NVREG_IRQ_RX_ALL;
3734 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3735 }
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003736 spin_unlock_irqrestore(&np->lock, flags);
Joe Perchesc20ec762010-11-29 07:42:02 +00003737 netdev_dbg(dev, "%s: too many iterations (%d)\n",
3738 __func__, i);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003739 break;
3740 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003741 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003742
3743 return IRQ_RETVAL(i);
3744}
3745
David Howells7d12e782006-10-05 14:55:46 +01003746static irqreturn_t nv_nic_irq_other(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003747{
3748 struct net_device *dev = (struct net_device *) data;
3749 struct fe_priv *np = netdev_priv(dev);
3750 u8 __iomem *base = get_hwbase(dev);
3751 u32 events;
3752 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003753 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003754
Szymon Janc78aea4f2010-11-27 08:39:43 +00003755 for (i = 0;; i++) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003756 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_OTHER;
Mike Ditto2a4e7a02011-11-05 14:38:21 +00003757 writel(events, base + NvRegMSIXIrqStatus);
3758 netdev_dbg(dev, "irq events: %08x\n", events);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003759 if (!(events & np->irqmask))
3760 break;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003761
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05003762 /* check tx in case we reached max loop limit in tx isr */
3763 spin_lock_irqsave(&np->lock, flags);
3764 nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
3765 spin_unlock_irqrestore(&np->lock, flags);
3766
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003767 if (events & NVREG_IRQ_LINK) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003768 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003769 nv_link_irq(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003770 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003771 }
3772 if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003773 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003774 nv_linkchange(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003775 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003776 np->link_timeout = jiffies + LINK_TIMEOUT;
3777 }
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003778 if (events & NVREG_IRQ_RECOVER_ERROR) {
3779 spin_lock_irq(&np->lock);
3780 /* disable interrupts on the nic */
3781 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
3782 pci_push(base);
3783
3784 if (!np->in_shutdown) {
3785 np->nic_poll_irq |= NVREG_IRQ_OTHER;
3786 np->recover_error = 1;
3787 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3788 }
3789 spin_unlock_irq(&np->lock);
3790 break;
3791 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003792 if (unlikely(i > max_interrupt_work)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003793 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003794 /* disable interrupts on the nic */
3795 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
3796 pci_push(base);
3797
3798 if (!np->in_shutdown) {
3799 np->nic_poll_irq |= NVREG_IRQ_OTHER;
3800 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3801 }
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003802 spin_unlock_irqrestore(&np->lock, flags);
Joe Perchesc20ec762010-11-29 07:42:02 +00003803 netdev_dbg(dev, "%s: too many iterations (%d)\n",
3804 __func__, i);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003805 break;
3806 }
3807
3808 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003809
3810 return IRQ_RETVAL(i);
3811}
3812
David Howells7d12e782006-10-05 14:55:46 +01003813static irqreturn_t nv_nic_irq_test(int foo, void *data)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003814{
3815 struct net_device *dev = (struct net_device *) data;
3816 struct fe_priv *np = netdev_priv(dev);
3817 u8 __iomem *base = get_hwbase(dev);
3818 u32 events;
3819
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003820 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3821 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
Mike Ditto2a4e7a02011-11-05 14:38:21 +00003822 writel(events & NVREG_IRQ_TIMER, base + NvRegIrqStatus);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003823 } else {
3824 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
Mike Ditto2a4e7a02011-11-05 14:38:21 +00003825 writel(events & NVREG_IRQ_TIMER, base + NvRegMSIXIrqStatus);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003826 }
3827 pci_push(base);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003828 if (!(events & NVREG_IRQ_TIMER))
3829 return IRQ_RETVAL(0);
3830
Ayaz Abdulla4db0ee172008-06-09 16:51:06 -07003831 nv_msi_workaround(np);
3832
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003833 spin_lock(&np->lock);
3834 np->intr_test = 1;
3835 spin_unlock(&np->lock);
3836
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003837 return IRQ_RETVAL(1);
3838}
3839
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003840static void set_msix_vector_map(struct net_device *dev, u32 vector, u32 irqmask)
3841{
3842 u8 __iomem *base = get_hwbase(dev);
3843 int i;
3844 u32 msixmap = 0;
3845
3846 /* Each interrupt bit can be mapped to a MSIX vector (4 bits).
3847 * MSIXMap0 represents the first 8 interrupts and MSIXMap1 represents
3848 * the remaining 8 interrupts.
3849 */
3850 for (i = 0; i < 8; i++) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003851 if ((irqmask >> i) & 0x1)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003852 msixmap |= vector << (i << 2);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003853 }
3854 writel(readl(base + NvRegMSIXMap0) | msixmap, base + NvRegMSIXMap0);
3855
3856 msixmap = 0;
3857 for (i = 0; i < 8; i++) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003858 if ((irqmask >> (i + 8)) & 0x1)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003859 msixmap |= vector << (i << 2);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003860 }
3861 writel(readl(base + NvRegMSIXMap1) | msixmap, base + NvRegMSIXMap1);
3862}
3863
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003864static int nv_request_irq(struct net_device *dev, int intr_test)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003865{
3866 struct fe_priv *np = get_nvpriv(dev);
3867 u8 __iomem *base = get_hwbase(dev);
3868 int ret = 1;
3869 int i;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003870 irqreturn_t (*handler)(int foo, void *data);
3871
3872 if (intr_test) {
3873 handler = nv_nic_irq_test;
3874 } else {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04003875 if (nv_optimized(np))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003876 handler = nv_nic_irq_optimized;
3877 else
3878 handler = nv_nic_irq;
3879 }
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003880
3881 if (np->msi_flags & NV_MSI_X_CAPABLE) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003882 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003883 np->msi_x_entry[i].entry = i;
Szymon Janc34cf97e2010-11-27 08:39:46 +00003884 ret = pci_enable_msix(np->pci_dev, np->msi_x_entry, (np->msi_flags & NV_MSI_X_VECTORS_MASK));
3885 if (ret == 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003886 np->msi_flags |= NV_MSI_X_ENABLED;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003887 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT && !intr_test) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003888 /* Request irq for rx handling */
Yinghai Luddb213f2009-02-06 01:29:23 -08003889 sprintf(np->name_rx, "%s-rx", dev->name);
3890 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08003891 nv_nic_irq_rx, IRQF_SHARED, np->name_rx, dev) != 0) {
Joe Perches1d397f32010-11-29 07:41:57 +00003892 netdev_info(dev,
3893 "request_irq failed for rx %d\n",
3894 ret);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003895 pci_disable_msix(np->pci_dev);
3896 np->msi_flags &= ~NV_MSI_X_ENABLED;
3897 goto out_err;
3898 }
3899 /* Request irq for tx handling */
Yinghai Luddb213f2009-02-06 01:29:23 -08003900 sprintf(np->name_tx, "%s-tx", dev->name);
3901 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08003902 nv_nic_irq_tx, IRQF_SHARED, np->name_tx, dev) != 0) {
Joe Perches1d397f32010-11-29 07:41:57 +00003903 netdev_info(dev,
3904 "request_irq failed for tx %d\n",
3905 ret);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003906 pci_disable_msix(np->pci_dev);
3907 np->msi_flags &= ~NV_MSI_X_ENABLED;
3908 goto out_free_rx;
3909 }
3910 /* Request irq for link and timer handling */
Yinghai Luddb213f2009-02-06 01:29:23 -08003911 sprintf(np->name_other, "%s-other", dev->name);
3912 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08003913 nv_nic_irq_other, IRQF_SHARED, np->name_other, dev) != 0) {
Joe Perches1d397f32010-11-29 07:41:57 +00003914 netdev_info(dev,
3915 "request_irq failed for link %d\n",
3916 ret);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003917 pci_disable_msix(np->pci_dev);
3918 np->msi_flags &= ~NV_MSI_X_ENABLED;
3919 goto out_free_tx;
3920 }
3921 /* map interrupts to their respective vector */
3922 writel(0, base + NvRegMSIXMap0);
3923 writel(0, base + NvRegMSIXMap1);
3924 set_msix_vector_map(dev, NV_MSI_X_VECTOR_RX, NVREG_IRQ_RX_ALL);
3925 set_msix_vector_map(dev, NV_MSI_X_VECTOR_TX, NVREG_IRQ_TX_ALL);
3926 set_msix_vector_map(dev, NV_MSI_X_VECTOR_OTHER, NVREG_IRQ_OTHER);
3927 } else {
3928 /* Request irq for all interrupts */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003929 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector, handler, IRQF_SHARED, dev->name, dev) != 0) {
Joe Perches1d397f32010-11-29 07:41:57 +00003930 netdev_info(dev,
3931 "request_irq failed %d\n",
3932 ret);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003933 pci_disable_msix(np->pci_dev);
3934 np->msi_flags &= ~NV_MSI_X_ENABLED;
3935 goto out_err;
3936 }
3937
3938 /* map interrupts to vector 0 */
3939 writel(0, base + NvRegMSIXMap0);
3940 writel(0, base + NvRegMSIXMap1);
3941 }
Mike Ditto89328782011-11-16 12:15:11 +00003942 netdev_info(dev, "MSI-X enabled\n");
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003943 }
3944 }
3945 if (ret != 0 && np->msi_flags & NV_MSI_CAPABLE) {
Szymon Janc34cf97e2010-11-27 08:39:46 +00003946 ret = pci_enable_msi(np->pci_dev);
3947 if (ret == 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003948 np->msi_flags |= NV_MSI_ENABLED;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003949 if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0) {
Joe Perches1d397f32010-11-29 07:41:57 +00003950 netdev_info(dev, "request_irq failed %d\n",
3951 ret);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003952 pci_disable_msi(np->pci_dev);
3953 np->msi_flags &= ~NV_MSI_ENABLED;
3954 goto out_err;
3955 }
3956
3957 /* map interrupts to vector 0 */
3958 writel(0, base + NvRegMSIMap0);
3959 writel(0, base + NvRegMSIMap1);
3960 /* enable msi vector 0 */
3961 writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask);
Mike Ditto89328782011-11-16 12:15:11 +00003962 netdev_info(dev, "MSI enabled\n");
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003963 }
3964 }
3965 if (ret != 0) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003966 if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003967 goto out_err;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003968
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003969 }
3970
3971 return 0;
3972out_free_tx:
3973 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector, dev);
3974out_free_rx:
3975 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector, dev);
3976out_err:
3977 return 1;
3978}
3979
3980static void nv_free_irq(struct net_device *dev)
3981{
3982 struct fe_priv *np = get_nvpriv(dev);
3983 int i;
3984
3985 if (np->msi_flags & NV_MSI_X_ENABLED) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003986 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003987 free_irq(np->msi_x_entry[i].vector, dev);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003988 pci_disable_msix(np->pci_dev);
3989 np->msi_flags &= ~NV_MSI_X_ENABLED;
3990 } else {
3991 free_irq(np->pci_dev->irq, dev);
3992 if (np->msi_flags & NV_MSI_ENABLED) {
3993 pci_disable_msi(np->pci_dev);
3994 np->msi_flags &= ~NV_MSI_ENABLED;
3995 }
3996 }
3997}
3998
Linus Torvalds1da177e2005-04-16 15:20:36 -07003999static void nv_do_nic_poll(unsigned long data)
4000{
4001 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004002 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004003 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004004 u32 mask = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006 /*
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004007 * First disable irq(s) and then
Linus Torvalds1da177e2005-04-16 15:20:36 -07004008 * reenable interrupts on the nic, we have to do this before calling
4009 * nv_nic_irq because that may decide to do otherwise
4010 */
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004011
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004012 if (!using_multi_irqs(dev)) {
4013 if (np->msi_flags & NV_MSI_X_ENABLED)
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004014 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004015 else
Manfred Spraula7475902007-10-17 21:52:33 +02004016 disable_irq_lockdep(np->pci_dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004017 mask = np->irqmask;
4018 } else {
4019 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004020 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004021 mask |= NVREG_IRQ_RX_ALL;
4022 }
4023 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004024 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004025 mask |= NVREG_IRQ_TX_ALL;
4026 }
4027 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004028 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004029 mask |= NVREG_IRQ_OTHER;
4030 }
4031 }
Manfred Spraula7475902007-10-17 21:52:33 +02004032 /* disable_irq() contains synchronize_irq, thus no irq handler can run now */
4033
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004034 if (np->recover_error) {
4035 np->recover_error = 0;
Joe Perches1d397f32010-11-29 07:41:57 +00004036 netdev_info(dev, "MAC in recoverable error state\n");
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004037 if (netif_running(dev)) {
4038 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004039 netif_addr_lock(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004040 spin_lock(&np->lock);
4041 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004042 nv_stop_rxtx(dev);
Ayaz Abdulladaa91a92009-02-07 00:25:00 -08004043 if (np->driver_data & DEV_HAS_POWER_CNTRL)
4044 nv_mac_reset(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004045 nv_txrx_reset(dev);
4046 /* drain rx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004047 nv_drain_rxtx(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004048 /* reinit driver view of the rx queue */
4049 set_bufsize(dev);
4050 if (nv_init_ring(dev)) {
4051 if (!np->in_shutdown)
4052 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
4053 }
4054 /* reinit nic view of the rx queue */
4055 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4056 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00004057 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004058 base + NvRegRingSizes);
4059 pci_push(base);
4060 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4061 pci_push(base);
Ayaz Abdulladaa91a92009-02-07 00:25:00 -08004062 /* clear interrupts */
4063 if (!(np->msi_flags & NV_MSI_X_ENABLED))
4064 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4065 else
4066 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004067
4068 /* restart rx engine */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004069 nv_start_rxtx(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004070 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07004071 netif_addr_unlock(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004072 netif_tx_unlock_bh(dev);
4073 }
4074 }
4075
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004076 writel(mask, base + NvRegIrqMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004077 pci_push(base);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004078
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004079 if (!using_multi_irqs(dev)) {
Yinghai Lu79d30a52009-02-06 01:30:01 -08004080 np->nic_poll_irq = 0;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004081 if (nv_optimized(np))
Ayaz Abdullafcc5f262007-03-23 05:49:37 -05004082 nv_nic_irq_optimized(0, dev);
4083 else
4084 nv_nic_irq(0, dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004085 if (np->msi_flags & NV_MSI_X_ENABLED)
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004086 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004087 else
Manfred Spraula7475902007-10-17 21:52:33 +02004088 enable_irq_lockdep(np->pci_dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004089 } else {
4090 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
Yinghai Lu79d30a52009-02-06 01:30:01 -08004091 np->nic_poll_irq &= ~NVREG_IRQ_RX_ALL;
David Howells7d12e782006-10-05 14:55:46 +01004092 nv_nic_irq_rx(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004093 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004094 }
4095 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
Yinghai Lu79d30a52009-02-06 01:30:01 -08004096 np->nic_poll_irq &= ~NVREG_IRQ_TX_ALL;
David Howells7d12e782006-10-05 14:55:46 +01004097 nv_nic_irq_tx(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004098 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004099 }
4100 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
Yinghai Lu79d30a52009-02-06 01:30:01 -08004101 np->nic_poll_irq &= ~NVREG_IRQ_OTHER;
David Howells7d12e782006-10-05 14:55:46 +01004102 nv_nic_irq_other(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004103 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004104 }
4105 }
Yinghai Lu79d30a52009-02-06 01:30:01 -08004106
Linus Torvalds1da177e2005-04-16 15:20:36 -07004107}
4108
Michal Schmidt2918c352005-05-12 19:42:06 -04004109#ifdef CONFIG_NET_POLL_CONTROLLER
4110static void nv_poll_controller(struct net_device *dev)
4111{
4112 nv_do_nic_poll((unsigned long) dev);
4113}
4114#endif
4115
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004116static void nv_do_stats_poll(unsigned long data)
david decotignyf5d827a2011-11-16 12:15:13 +00004117 __acquires(&netdev_priv(dev)->hwstats_lock)
4118 __releases(&netdev_priv(dev)->hwstats_lock)
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004119{
4120 struct net_device *dev = (struct net_device *) data;
4121 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004122
david decotignyf5d827a2011-11-16 12:15:13 +00004123 /* If lock is currently taken, the stats are being refreshed
4124 * and hence fresh enough */
4125 if (spin_trylock(&np->hwstats_lock)) {
4126 nv_update_stats(dev);
4127 spin_unlock(&np->hwstats_lock);
4128 }
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004129
4130 if (!np->in_shutdown)
Daniel Drakebfebbb82008-03-18 11:07:18 +00004131 mod_timer(&np->stats_poll,
4132 round_jiffies(jiffies + STATS_INTERVAL));
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004133}
4134
Linus Torvalds1da177e2005-04-16 15:20:36 -07004135static void nv_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
4136{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004137 struct fe_priv *np = netdev_priv(dev);
Rick Jones68aad782011-11-07 13:29:27 +00004138 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
4139 strlcpy(info->version, FORCEDETH_VERSION, sizeof(info->version));
4140 strlcpy(info->bus_info, pci_name(np->pci_dev), sizeof(info->bus_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141}
4142
4143static void nv_get_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
4144{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004145 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004146 wolinfo->supported = WAKE_MAGIC;
4147
4148 spin_lock_irq(&np->lock);
4149 if (np->wolenabled)
4150 wolinfo->wolopts = WAKE_MAGIC;
4151 spin_unlock_irq(&np->lock);
4152}
4153
4154static int nv_set_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
4155{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004156 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004158 u32 flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004159
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160 if (wolinfo->wolopts == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004161 np->wolenabled = 0;
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004162 } else if (wolinfo->wolopts & WAKE_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004163 np->wolenabled = 1;
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004164 flags = NVREG_WAKEUPFLAGS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004165 }
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004166 if (netif_running(dev)) {
4167 spin_lock_irq(&np->lock);
4168 writel(flags, base + NvRegWakeUpFlags);
4169 spin_unlock_irq(&np->lock);
4170 }
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00004171 device_set_wakeup_enable(&np->pci_dev->dev, np->wolenabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004172 return 0;
4173}
4174
4175static int nv_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
4176{
4177 struct fe_priv *np = netdev_priv(dev);
David Decotigny70739492011-04-27 18:32:40 +00004178 u32 speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004179 int adv;
4180
4181 spin_lock_irq(&np->lock);
4182 ecmd->port = PORT_MII;
4183 if (!netif_running(dev)) {
4184 /* We do not track link speed / duplex setting if the
4185 * interface is disabled. Force a link check */
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004186 if (nv_update_linkspeed(dev)) {
4187 if (!netif_carrier_ok(dev))
4188 netif_carrier_on(dev);
4189 } else {
4190 if (netif_carrier_ok(dev))
4191 netif_carrier_off(dev);
4192 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004193 }
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004194
4195 if (netif_carrier_ok(dev)) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00004196 switch (np->linkspeed & (NVREG_LINKSPEED_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004197 case NVREG_LINKSPEED_10:
David Decotigny70739492011-04-27 18:32:40 +00004198 speed = SPEED_10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199 break;
4200 case NVREG_LINKSPEED_100:
David Decotigny70739492011-04-27 18:32:40 +00004201 speed = SPEED_100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202 break;
4203 case NVREG_LINKSPEED_1000:
David Decotigny70739492011-04-27 18:32:40 +00004204 speed = SPEED_1000;
4205 break;
4206 default:
4207 speed = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208 break;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004209 }
4210 ecmd->duplex = DUPLEX_HALF;
4211 if (np->duplex)
4212 ecmd->duplex = DUPLEX_FULL;
4213 } else {
David Decotigny70739492011-04-27 18:32:40 +00004214 speed = -1;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004215 ecmd->duplex = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004216 }
David Decotigny70739492011-04-27 18:32:40 +00004217 ethtool_cmd_speed_set(ecmd, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004218 ecmd->autoneg = np->autoneg;
4219
4220 ecmd->advertising = ADVERTISED_MII;
4221 if (np->autoneg) {
4222 ecmd->advertising |= ADVERTISED_Autoneg;
4223 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004224 if (adv & ADVERTISE_10HALF)
4225 ecmd->advertising |= ADVERTISED_10baseT_Half;
4226 if (adv & ADVERTISE_10FULL)
4227 ecmd->advertising |= ADVERTISED_10baseT_Full;
4228 if (adv & ADVERTISE_100HALF)
4229 ecmd->advertising |= ADVERTISED_100baseT_Half;
4230 if (adv & ADVERTISE_100FULL)
4231 ecmd->advertising |= ADVERTISED_100baseT_Full;
4232 if (np->gigabit == PHY_GIGABIT) {
4233 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
4234 if (adv & ADVERTISE_1000FULL)
4235 ecmd->advertising |= ADVERTISED_1000baseT_Full;
4236 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004237 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004238 ecmd->supported = (SUPPORTED_Autoneg |
4239 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
4240 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
4241 SUPPORTED_MII);
4242 if (np->gigabit == PHY_GIGABIT)
4243 ecmd->supported |= SUPPORTED_1000baseT_Full;
4244
4245 ecmd->phy_address = np->phyaddr;
4246 ecmd->transceiver = XCVR_EXTERNAL;
4247
4248 /* ignore maxtxpkt, maxrxpkt for now */
4249 spin_unlock_irq(&np->lock);
4250 return 0;
4251}
4252
4253static int nv_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
4254{
4255 struct fe_priv *np = netdev_priv(dev);
David Decotigny25db0332011-04-27 18:32:39 +00004256 u32 speed = ethtool_cmd_speed(ecmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004257
4258 if (ecmd->port != PORT_MII)
4259 return -EINVAL;
4260 if (ecmd->transceiver != XCVR_EXTERNAL)
4261 return -EINVAL;
4262 if (ecmd->phy_address != np->phyaddr) {
4263 /* TODO: support switching between multiple phys. Should be
4264 * trivial, but not enabled due to lack of test hardware. */
4265 return -EINVAL;
4266 }
4267 if (ecmd->autoneg == AUTONEG_ENABLE) {
4268 u32 mask;
4269
4270 mask = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
4271 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full;
4272 if (np->gigabit == PHY_GIGABIT)
4273 mask |= ADVERTISED_1000baseT_Full;
4274
4275 if ((ecmd->advertising & mask) == 0)
4276 return -EINVAL;
4277
4278 } else if (ecmd->autoneg == AUTONEG_DISABLE) {
4279 /* Note: autonegotiation disable, speed 1000 intentionally
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004280 * forbidden - no one should need that. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281
David Decotigny25db0332011-04-27 18:32:39 +00004282 if (speed != SPEED_10 && speed != SPEED_100)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283 return -EINVAL;
4284 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
4285 return -EINVAL;
4286 } else {
4287 return -EINVAL;
4288 }
4289
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004290 netif_carrier_off(dev);
4291 if (netif_running(dev)) {
Tobias Diedrich97bff092008-07-03 23:54:56 -07004292 unsigned long flags;
4293
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004294 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004295 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004296 netif_addr_lock(dev);
Tobias Diedrich97bff092008-07-03 23:54:56 -07004297 /* with plain spinlock lockdep complains */
4298 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004299 /* stop engines */
Tobias Diedrich97bff092008-07-03 23:54:56 -07004300 /* FIXME:
4301 * this can take some time, and interrupts are disabled
4302 * due to spin_lock_irqsave, but let's hope no daemon
4303 * is going to change the settings very often...
4304 * Worst case:
4305 * NV_RXSTOP_DELAY1MAX + NV_TXSTOP_DELAY1MAX
4306 * + some minor delays, which is up to a second approximately
4307 */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004308 nv_stop_rxtx(dev);
Tobias Diedrich97bff092008-07-03 23:54:56 -07004309 spin_unlock_irqrestore(&np->lock, flags);
David S. Millere308a5d2008-07-15 00:13:44 -07004310 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004311 netif_tx_unlock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004312 }
4313
Linus Torvalds1da177e2005-04-16 15:20:36 -07004314 if (ecmd->autoneg == AUTONEG_ENABLE) {
4315 int adv, bmcr;
4316
4317 np->autoneg = 1;
4318
4319 /* advertise only what has been requested */
4320 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004321 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004322 if (ecmd->advertising & ADVERTISED_10baseT_Half)
4323 adv |= ADVERTISE_10HALF;
4324 if (ecmd->advertising & ADVERTISED_10baseT_Full)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004325 adv |= ADVERTISE_10FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004326 if (ecmd->advertising & ADVERTISED_100baseT_Half)
4327 adv |= ADVERTISE_100HALF;
4328 if (ecmd->advertising & ADVERTISED_100baseT_Full)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004329 adv |= ADVERTISE_100FULL;
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004330 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisements but disable tx pause */
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004331 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4332 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
4333 adv |= ADVERTISE_PAUSE_ASYM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004334 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4335
4336 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004337 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004338 adv &= ~ADVERTISE_1000FULL;
4339 if (ecmd->advertising & ADVERTISED_1000baseT_Full)
4340 adv |= ADVERTISE_1000FULL;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004341 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004342 }
4343
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004344 if (netif_running(dev))
Joe Perches1d397f32010-11-29 07:41:57 +00004345 netdev_info(dev, "link down\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004346 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004347 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
4348 bmcr |= BMCR_ANENABLE;
4349 /* reset the phy in order for settings to stick,
4350 * and cause autoneg to start */
4351 if (phy_reset(dev, bmcr)) {
Joe Perches1d397f32010-11-29 07:41:57 +00004352 netdev_info(dev, "phy reset failed\n");
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004353 return -EINVAL;
4354 }
4355 } else {
4356 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4357 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4358 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359 } else {
4360 int adv, bmcr;
4361
4362 np->autoneg = 0;
4363
4364 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004365 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
David Decotigny25db0332011-04-27 18:32:39 +00004366 if (speed == SPEED_10 && ecmd->duplex == DUPLEX_HALF)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004367 adv |= ADVERTISE_10HALF;
David Decotigny25db0332011-04-27 18:32:39 +00004368 if (speed == SPEED_10 && ecmd->duplex == DUPLEX_FULL)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004369 adv |= ADVERTISE_10FULL;
David Decotigny25db0332011-04-27 18:32:39 +00004370 if (speed == SPEED_100 && ecmd->duplex == DUPLEX_HALF)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004371 adv |= ADVERTISE_100HALF;
David Decotigny25db0332011-04-27 18:32:39 +00004372 if (speed == SPEED_100 && ecmd->duplex == DUPLEX_FULL)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004373 adv |= ADVERTISE_100FULL;
4374 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004375 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) {/* for rx we set both advertisements but disable tx pause */
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004376 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4377 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
4378 }
4379 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) {
4380 adv |= ADVERTISE_PAUSE_ASYM;
4381 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
4382 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004383 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4384 np->fixed_mode = adv;
4385
4386 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004387 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004388 adv &= ~ADVERTISE_1000FULL;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004389 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004390 }
4391
4392 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004393 bmcr &= ~(BMCR_ANENABLE|BMCR_SPEED100|BMCR_SPEED1000|BMCR_FULLDPLX);
4394 if (np->fixed_mode & (ADVERTISE_10FULL|ADVERTISE_100FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004395 bmcr |= BMCR_FULLDPLX;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004396 if (np->fixed_mode & (ADVERTISE_100HALF|ADVERTISE_100FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004397 bmcr |= BMCR_SPEED100;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004398 if (np->phy_oui == PHY_OUI_MARVELL) {
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004399 /* reset the phy in order for forced mode settings to stick */
4400 if (phy_reset(dev, bmcr)) {
Joe Perches1d397f32010-11-29 07:41:57 +00004401 netdev_info(dev, "phy reset failed\n");
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004402 return -EINVAL;
4403 }
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004404 } else {
4405 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4406 if (netif_running(dev)) {
4407 /* Wait a bit and then reconfigure the nic. */
4408 udelay(10);
4409 nv_linkchange(dev);
4410 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004411 }
4412 }
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004413
4414 if (netif_running(dev)) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004415 nv_start_rxtx(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004416 nv_enable_irq(dev);
4417 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004418
4419 return 0;
4420}
4421
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004422#define FORCEDETH_REGS_VER 1
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004423
4424static int nv_get_regs_len(struct net_device *dev)
4425{
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004426 struct fe_priv *np = netdev_priv(dev);
4427 return np->register_size;
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004428}
4429
4430static void nv_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *buf)
4431{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004432 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004433 u8 __iomem *base = get_hwbase(dev);
4434 u32 *rbuf = buf;
4435 int i;
4436
4437 regs->version = FORCEDETH_REGS_VER;
4438 spin_lock_irq(&np->lock);
Szymon Janc78aea4f2010-11-27 08:39:43 +00004439 for (i = 0; i <= np->register_size/sizeof(u32); i++)
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004440 rbuf[i] = readl(base + i*sizeof(u32));
4441 spin_unlock_irq(&np->lock);
4442}
4443
4444static int nv_nway_reset(struct net_device *dev)
4445{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004446 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004447 int ret;
4448
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004449 if (np->autoneg) {
4450 int bmcr;
4451
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004452 netif_carrier_off(dev);
4453 if (netif_running(dev)) {
4454 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004455 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004456 netif_addr_lock(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004457 spin_lock(&np->lock);
4458 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004459 nv_stop_rxtx(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004460 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07004461 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004462 netif_tx_unlock_bh(dev);
Joe Perches1d397f32010-11-29 07:41:57 +00004463 netdev_info(dev, "link down\n");
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004464 }
4465
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004466 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004467 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
4468 bmcr |= BMCR_ANENABLE;
4469 /* reset the phy in order for settings to stick*/
4470 if (phy_reset(dev, bmcr)) {
Joe Perches1d397f32010-11-29 07:41:57 +00004471 netdev_info(dev, "phy reset failed\n");
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004472 return -EINVAL;
4473 }
4474 } else {
4475 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4476 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4477 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004478
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004479 if (netif_running(dev)) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004480 nv_start_rxtx(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004481 nv_enable_irq(dev);
4482 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004483 ret = 0;
4484 } else {
4485 ret = -EINVAL;
4486 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004487
4488 return ret;
4489}
4490
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004491static void nv_get_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
4492{
4493 struct fe_priv *np = netdev_priv(dev);
4494
4495 ring->rx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004496 ring->tx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
4497
4498 ring->rx_pending = np->rx_ring_size;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004499 ring->tx_pending = np->tx_ring_size;
4500}
4501
4502static int nv_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
4503{
4504 struct fe_priv *np = netdev_priv(dev);
4505 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004506 u8 *rxtx_ring, *rx_skbuff, *tx_skbuff;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004507 dma_addr_t ring_addr;
4508
4509 if (ring->rx_pending < RX_RING_MIN ||
4510 ring->tx_pending < TX_RING_MIN ||
4511 ring->rx_mini_pending != 0 ||
4512 ring->rx_jumbo_pending != 0 ||
4513 (np->desc_ver == DESC_VER_1 &&
4514 (ring->rx_pending > RING_MAX_DESC_VER_1 ||
4515 ring->tx_pending > RING_MAX_DESC_VER_1)) ||
4516 (np->desc_ver != DESC_VER_1 &&
4517 (ring->rx_pending > RING_MAX_DESC_VER_2_3 ||
4518 ring->tx_pending > RING_MAX_DESC_VER_2_3))) {
4519 return -EINVAL;
4520 }
4521
4522 /* allocate new rings */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004523 if (!nv_optimized(np)) {
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004524 rxtx_ring = pci_alloc_consistent(np->pci_dev,
4525 sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
4526 &ring_addr);
4527 } else {
4528 rxtx_ring = pci_alloc_consistent(np->pci_dev,
4529 sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
4530 &ring_addr);
4531 }
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004532 rx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->rx_pending, GFP_KERNEL);
4533 tx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->tx_pending, GFP_KERNEL);
4534 if (!rxtx_ring || !rx_skbuff || !tx_skbuff) {
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004535 /* fall back to old rings */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004536 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004537 if (rxtx_ring)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004538 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
4539 rxtx_ring, ring_addr);
4540 } else {
4541 if (rxtx_ring)
4542 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
4543 rxtx_ring, ring_addr);
4544 }
Szymon Janc9b03b062010-11-27 08:39:44 +00004545
4546 kfree(rx_skbuff);
4547 kfree(tx_skbuff);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004548 goto exit;
4549 }
4550
4551 if (netif_running(dev)) {
4552 nv_disable_irq(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00004553 nv_napi_disable(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004554 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004555 netif_addr_lock(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004556 spin_lock(&np->lock);
4557 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004558 nv_stop_rxtx(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004559 nv_txrx_reset(dev);
4560 /* drain queues */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004561 nv_drain_rxtx(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004562 /* delete queues */
4563 free_rings(dev);
4564 }
4565
4566 /* set new values */
4567 np->rx_ring_size = ring->rx_pending;
4568 np->tx_ring_size = ring->tx_pending;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004569
4570 if (!nv_optimized(np)) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00004571 np->rx_ring.orig = (struct ring_desc *)rxtx_ring;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004572 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
4573 } else {
Szymon Janc78aea4f2010-11-27 08:39:43 +00004574 np->rx_ring.ex = (struct ring_desc_ex *)rxtx_ring;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004575 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
4576 }
Szymon Janc78aea4f2010-11-27 08:39:43 +00004577 np->rx_skb = (struct nv_skb_map *)rx_skbuff;
4578 np->tx_skb = (struct nv_skb_map *)tx_skbuff;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004579 np->ring_addr = ring_addr;
4580
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004581 memset(np->rx_skb, 0, sizeof(struct nv_skb_map) * np->rx_ring_size);
4582 memset(np->tx_skb, 0, sizeof(struct nv_skb_map) * np->tx_ring_size);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004583
4584 if (netif_running(dev)) {
4585 /* reinit driver view of the queues */
4586 set_bufsize(dev);
4587 if (nv_init_ring(dev)) {
4588 if (!np->in_shutdown)
4589 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
4590 }
4591
4592 /* reinit nic view of the queues */
4593 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4594 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00004595 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004596 base + NvRegRingSizes);
4597 pci_push(base);
4598 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4599 pci_push(base);
4600
4601 /* restart engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004602 nv_start_rxtx(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004603 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07004604 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004605 netif_tx_unlock_bh(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00004606 nv_napi_enable(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004607 nv_enable_irq(dev);
4608 }
4609 return 0;
4610exit:
4611 return -ENOMEM;
4612}
4613
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004614static void nv_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
4615{
4616 struct fe_priv *np = netdev_priv(dev);
4617
4618 pause->autoneg = (np->pause_flags & NV_PAUSEFRAME_AUTONEG) != 0;
4619 pause->rx_pause = (np->pause_flags & NV_PAUSEFRAME_RX_ENABLE) != 0;
4620 pause->tx_pause = (np->pause_flags & NV_PAUSEFRAME_TX_ENABLE) != 0;
4621}
4622
4623static int nv_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
4624{
4625 struct fe_priv *np = netdev_priv(dev);
4626 int adv, bmcr;
4627
4628 if ((!np->autoneg && np->duplex == 0) ||
4629 (np->autoneg && !pause->autoneg && np->duplex == 0)) {
Joe Perches1d397f32010-11-29 07:41:57 +00004630 netdev_info(dev, "can not set pause settings when forced link is in half duplex\n");
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004631 return -EINVAL;
4632 }
4633 if (pause->tx_pause && !(np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)) {
Joe Perches1d397f32010-11-29 07:41:57 +00004634 netdev_info(dev, "hardware does not support tx pause frames\n");
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004635 return -EINVAL;
4636 }
4637
4638 netif_carrier_off(dev);
4639 if (netif_running(dev)) {
4640 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004641 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004642 netif_addr_lock(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004643 spin_lock(&np->lock);
4644 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004645 nv_stop_rxtx(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004646 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07004647 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004648 netif_tx_unlock_bh(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004649 }
4650
4651 np->pause_flags &= ~(NV_PAUSEFRAME_RX_REQ|NV_PAUSEFRAME_TX_REQ);
4652 if (pause->rx_pause)
4653 np->pause_flags |= NV_PAUSEFRAME_RX_REQ;
4654 if (pause->tx_pause)
4655 np->pause_flags |= NV_PAUSEFRAME_TX_REQ;
4656
4657 if (np->autoneg && pause->autoneg) {
4658 np->pause_flags |= NV_PAUSEFRAME_AUTONEG;
4659
4660 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
4661 adv &= ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004662 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisements but disable tx pause */
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004663 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4664 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
4665 adv |= ADVERTISE_PAUSE_ASYM;
4666 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4667
4668 if (netif_running(dev))
Joe Perches1d397f32010-11-29 07:41:57 +00004669 netdev_info(dev, "link down\n");
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004670 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
4671 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4672 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4673 } else {
4674 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
4675 if (pause->rx_pause)
4676 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
4677 if (pause->tx_pause)
4678 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
4679
4680 if (!netif_running(dev))
4681 nv_update_linkspeed(dev);
4682 else
4683 nv_update_pause(dev, np->pause_flags);
4684 }
4685
4686 if (netif_running(dev)) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004687 nv_start_rxtx(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004688 nv_enable_irq(dev);
4689 }
4690 return 0;
4691}
4692
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004693static int nv_set_loopback(struct net_device *dev, netdev_features_t features)
Sanjay Hortikare19df762011-11-11 16:11:21 +00004694{
4695 struct fe_priv *np = netdev_priv(dev);
4696 unsigned long flags;
4697 u32 miicontrol;
4698 int err, retval = 0;
4699
4700 spin_lock_irqsave(&np->lock, flags);
4701 miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
4702 if (features & NETIF_F_LOOPBACK) {
4703 if (miicontrol & BMCR_LOOPBACK) {
4704 spin_unlock_irqrestore(&np->lock, flags);
4705 netdev_info(dev, "Loopback already enabled\n");
4706 return 0;
4707 }
4708 nv_disable_irq(dev);
4709 /* Turn on loopback mode */
4710 miicontrol |= BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000;
4711 err = mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol);
4712 if (err) {
4713 retval = PHY_ERROR;
4714 spin_unlock_irqrestore(&np->lock, flags);
4715 phy_init(dev);
4716 } else {
4717 if (netif_running(dev)) {
4718 /* Force 1000 Mbps full-duplex */
4719 nv_force_linkspeed(dev, NVREG_LINKSPEED_1000,
4720 1);
4721 /* Force link up */
4722 netif_carrier_on(dev);
4723 }
4724 spin_unlock_irqrestore(&np->lock, flags);
4725 netdev_info(dev,
4726 "Internal PHY loopback mode enabled.\n");
4727 }
4728 } else {
4729 if (!(miicontrol & BMCR_LOOPBACK)) {
4730 spin_unlock_irqrestore(&np->lock, flags);
4731 netdev_info(dev, "Loopback already disabled\n");
4732 return 0;
4733 }
4734 nv_disable_irq(dev);
4735 /* Turn off loopback */
4736 spin_unlock_irqrestore(&np->lock, flags);
4737 netdev_info(dev, "Internal PHY loopback mode disabled.\n");
4738 phy_init(dev);
4739 }
4740 msleep(500);
4741 spin_lock_irqsave(&np->lock, flags);
4742 nv_enable_irq(dev);
4743 spin_unlock_irqrestore(&np->lock, flags);
4744
4745 return retval;
4746}
4747
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004748static netdev_features_t nv_fix_features(struct net_device *dev,
4749 netdev_features_t features)
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004750{
Michał Mirosław569e1462011-04-15 04:50:49 +00004751 /* vlan is dependent on rx checksum offload */
4752 if (features & (NETIF_F_HW_VLAN_TX|NETIF_F_HW_VLAN_RX))
4753 features |= NETIF_F_RXCSUM;
4754
4755 return features;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004756}
4757
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004758static void nv_vlan_mode(struct net_device *dev, netdev_features_t features)
Jiri Pirko3326c782011-07-20 04:54:38 +00004759{
4760 struct fe_priv *np = get_nvpriv(dev);
4761
4762 spin_lock_irq(&np->lock);
4763
4764 if (features & NETIF_F_HW_VLAN_RX)
4765 np->txrxctl_bits |= NVREG_TXRXCTL_VLANSTRIP;
4766 else
4767 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANSTRIP;
4768
4769 if (features & NETIF_F_HW_VLAN_TX)
4770 np->txrxctl_bits |= NVREG_TXRXCTL_VLANINS;
4771 else
4772 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANINS;
4773
4774 writel(np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4775
4776 spin_unlock_irq(&np->lock);
4777}
4778
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004779static int nv_set_features(struct net_device *dev, netdev_features_t features)
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004780{
4781 struct fe_priv *np = netdev_priv(dev);
4782 u8 __iomem *base = get_hwbase(dev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004783 netdev_features_t changed = dev->features ^ features;
Sanjay Hortikare19df762011-11-11 16:11:21 +00004784 int retval;
4785
4786 if ((changed & NETIF_F_LOOPBACK) && netif_running(dev)) {
4787 retval = nv_set_loopback(dev, features);
4788 if (retval != 0)
4789 return retval;
4790 }
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004791
Michał Mirosław569e1462011-04-15 04:50:49 +00004792 if (changed & NETIF_F_RXCSUM) {
4793 spin_lock_irq(&np->lock);
4794
4795 if (features & NETIF_F_RXCSUM)
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004796 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
Michał Mirosław569e1462011-04-15 04:50:49 +00004797 else
4798 np->txrxctl_bits &= ~NVREG_TXRXCTL_RXCHECK;
4799
4800 if (netif_running(dev))
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004801 writel(np->txrxctl_bits, base + NvRegTxRxControl);
Michał Mirosław569e1462011-04-15 04:50:49 +00004802
4803 spin_unlock_irq(&np->lock);
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004804 }
4805
Jiri Pirko3326c782011-07-20 04:54:38 +00004806 if (changed & (NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX))
4807 nv_vlan_mode(dev, features);
4808
Michał Mirosław569e1462011-04-15 04:50:49 +00004809 return 0;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004810}
4811
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004812static int nv_get_sset_count(struct net_device *dev, int sset)
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004813{
4814 struct fe_priv *np = netdev_priv(dev);
4815
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004816 switch (sset) {
4817 case ETH_SS_TEST:
4818 if (np->driver_data & DEV_HAS_TEST_EXTENDED)
4819 return NV_TEST_COUNT_EXTENDED;
4820 else
4821 return NV_TEST_COUNT_BASE;
4822 case ETH_SS_STATS:
Ayaz Abdulla8ed14542009-03-05 08:01:49 +00004823 if (np->driver_data & DEV_HAS_STATISTICS_V3)
4824 return NV_DEV_STATISTICS_V3_COUNT;
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004825 else if (np->driver_data & DEV_HAS_STATISTICS_V2)
4826 return NV_DEV_STATISTICS_V2_COUNT;
Ayaz Abdulla8ed14542009-03-05 08:01:49 +00004827 else if (np->driver_data & DEV_HAS_STATISTICS_V1)
4828 return NV_DEV_STATISTICS_V1_COUNT;
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004829 else
4830 return 0;
4831 default:
4832 return -EOPNOTSUPP;
4833 }
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004834}
4835
david decotignyf5d827a2011-11-16 12:15:13 +00004836static void nv_get_ethtool_stats(struct net_device *dev,
4837 struct ethtool_stats *estats, u64 *buffer)
4838 __acquires(&netdev_priv(dev)->hwstats_lock)
4839 __releases(&netdev_priv(dev)->hwstats_lock)
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004840{
4841 struct fe_priv *np = netdev_priv(dev);
4842
david decotignyf5d827a2011-11-16 12:15:13 +00004843 spin_lock_bh(&np->hwstats_lock);
4844 nv_update_stats(dev);
4845 memcpy(buffer, &np->estats,
4846 nv_get_sset_count(dev, ETH_SS_STATS)*sizeof(u64));
4847 spin_unlock_bh(&np->hwstats_lock);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004848}
4849
4850static int nv_link_test(struct net_device *dev)
4851{
4852 struct fe_priv *np = netdev_priv(dev);
4853 int mii_status;
4854
4855 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
4856 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
4857
4858 /* check phy link status */
4859 if (!(mii_status & BMSR_LSTATUS))
4860 return 0;
4861 else
4862 return 1;
4863}
4864
4865static int nv_register_test(struct net_device *dev)
4866{
4867 u8 __iomem *base = get_hwbase(dev);
4868 int i = 0;
4869 u32 orig_read, new_read;
4870
4871 do {
4872 orig_read = readl(base + nv_registers_test[i].reg);
4873
4874 /* xor with mask to toggle bits */
4875 orig_read ^= nv_registers_test[i].mask;
4876
4877 writel(orig_read, base + nv_registers_test[i].reg);
4878
4879 new_read = readl(base + nv_registers_test[i].reg);
4880
4881 if ((new_read & nv_registers_test[i].mask) != (orig_read & nv_registers_test[i].mask))
4882 return 0;
4883
4884 /* restore original value */
4885 orig_read ^= nv_registers_test[i].mask;
4886 writel(orig_read, base + nv_registers_test[i].reg);
4887
4888 } while (nv_registers_test[++i].reg != 0);
4889
4890 return 1;
4891}
4892
4893static int nv_interrupt_test(struct net_device *dev)
4894{
4895 struct fe_priv *np = netdev_priv(dev);
4896 u8 __iomem *base = get_hwbase(dev);
4897 int ret = 1;
4898 int testcnt;
4899 u32 save_msi_flags, save_poll_interval = 0;
4900
4901 if (netif_running(dev)) {
4902 /* free current irq */
4903 nv_free_irq(dev);
4904 save_poll_interval = readl(base+NvRegPollingInterval);
4905 }
4906
4907 /* flag to test interrupt handler */
4908 np->intr_test = 0;
4909
4910 /* setup test irq */
4911 save_msi_flags = np->msi_flags;
4912 np->msi_flags &= ~NV_MSI_X_VECTORS_MASK;
4913 np->msi_flags |= 0x001; /* setup 1 vector */
4914 if (nv_request_irq(dev, 1))
4915 return 0;
4916
4917 /* setup timer interrupt */
4918 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
4919 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
4920
4921 nv_enable_hw_interrupts(dev, NVREG_IRQ_TIMER);
4922
4923 /* wait for at least one interrupt */
4924 msleep(100);
4925
4926 spin_lock_irq(&np->lock);
4927
4928 /* flag should be set within ISR */
4929 testcnt = np->intr_test;
4930 if (!testcnt)
4931 ret = 2;
4932
4933 nv_disable_hw_interrupts(dev, NVREG_IRQ_TIMER);
4934 if (!(np->msi_flags & NV_MSI_X_ENABLED))
4935 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4936 else
4937 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
4938
4939 spin_unlock_irq(&np->lock);
4940
4941 nv_free_irq(dev);
4942
4943 np->msi_flags = save_msi_flags;
4944
4945 if (netif_running(dev)) {
4946 writel(save_poll_interval, base + NvRegPollingInterval);
4947 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
4948 /* restore original irq */
4949 if (nv_request_irq(dev, 0))
4950 return 0;
4951 }
4952
4953 return ret;
4954}
4955
4956static int nv_loopback_test(struct net_device *dev)
4957{
4958 struct fe_priv *np = netdev_priv(dev);
4959 u8 __iomem *base = get_hwbase(dev);
4960 struct sk_buff *tx_skb, *rx_skb;
4961 dma_addr_t test_dma_addr;
4962 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004963 u32 flags;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004964 int len, i, pkt_len;
4965 u8 *pkt_data;
4966 u32 filter_flags = 0;
4967 u32 misc1_flags = 0;
4968 int ret = 1;
4969
4970 if (netif_running(dev)) {
4971 nv_disable_irq(dev);
4972 filter_flags = readl(base + NvRegPacketFilterFlags);
4973 misc1_flags = readl(base + NvRegMisc1);
4974 } else {
4975 nv_txrx_reset(dev);
4976 }
4977
4978 /* reinit driver view of the rx queue */
4979 set_bufsize(dev);
4980 nv_init_ring(dev);
4981
4982 /* setup hardware for loopback */
4983 writel(NVREG_MISC1_FORCE, base + NvRegMisc1);
4984 writel(NVREG_PFF_ALWAYS | NVREG_PFF_LOOPBACK, base + NvRegPacketFilterFlags);
4985
4986 /* reinit nic view of the rx queue */
4987 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4988 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00004989 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004990 base + NvRegRingSizes);
4991 pci_push(base);
4992
4993 /* restart rx engine */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004994 nv_start_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004995
4996 /* setup packet for tx */
4997 pkt_len = ETH_DATA_LEN;
Pradeep A. Dalvidae2e9f2012-02-06 11:16:13 +00004998 tx_skb = netdev_alloc_skb(dev, pkt_len);
Jesper Juhl46798c82006-09-25 16:39:24 -07004999 if (!tx_skb) {
Pradeep A. Dalvidae2e9f2012-02-06 11:16:13 +00005000 netdev_err(dev, "netdev_alloc_skb() failed during loopback test\n");
Jesper Juhl46798c82006-09-25 16:39:24 -07005001 ret = 0;
5002 goto out;
5003 }
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03005004 test_dma_addr = pci_map_single(np->pci_dev, tx_skb->data,
5005 skb_tailroom(tx_skb),
5006 PCI_DMA_FROMDEVICE);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005007 pkt_data = skb_put(tx_skb, pkt_len);
5008 for (i = 0; i < pkt_len; i++)
5009 pkt_data[i] = (u8)(i & 0xff);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005010
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005011 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07005012 np->tx_ring.orig[0].buf = cpu_to_le32(test_dma_addr);
5013 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 -04005014 } else {
Al Viro5bb7ea22007-12-09 16:06:41 +00005015 np->tx_ring.ex[0].bufhigh = cpu_to_le32(dma_high(test_dma_addr));
5016 np->tx_ring.ex[0].buflow = cpu_to_le32(dma_low(test_dma_addr));
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07005017 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 -04005018 }
5019 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
5020 pci_push(get_hwbase(dev));
5021
5022 msleep(500);
5023
5024 /* check for rx of the packet */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005025 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07005026 flags = le32_to_cpu(np->rx_ring.orig[0].flaglen);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005027 len = nv_descr_getlength(&np->rx_ring.orig[0], np->desc_ver);
5028
5029 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07005030 flags = le32_to_cpu(np->rx_ring.ex[0].flaglen);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005031 len = nv_descr_getlength_ex(&np->rx_ring.ex[0], np->desc_ver);
5032 }
5033
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07005034 if (flags & NV_RX_AVAIL) {
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005035 ret = 0;
5036 } else if (np->desc_ver == DESC_VER_1) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07005037 if (flags & NV_RX_ERROR)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005038 ret = 0;
5039 } else {
Szymon Janc78aea4f2010-11-27 08:39:43 +00005040 if (flags & NV_RX2_ERROR)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005041 ret = 0;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005042 }
5043
5044 if (ret) {
5045 if (len != pkt_len) {
5046 ret = 0;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005047 } else {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05005048 rx_skb = np->rx_skb[0].skb;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005049 for (i = 0; i < pkt_len; i++) {
5050 if (rx_skb->data[i] != (u8)(i & 0xff)) {
5051 ret = 0;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005052 break;
5053 }
5054 }
5055 }
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005056 }
5057
Eric Dumazet73a37072009-06-17 21:17:59 +00005058 pci_unmap_single(np->pci_dev, test_dma_addr,
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07005059 (skb_end_pointer(tx_skb) - tx_skb->data),
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005060 PCI_DMA_TODEVICE);
5061 dev_kfree_skb_any(tx_skb);
Jesper Juhl46798c82006-09-25 16:39:24 -07005062 out:
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005063 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005064 nv_stop_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005065 nv_txrx_reset(dev);
5066 /* drain rx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005067 nv_drain_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005068
5069 if (netif_running(dev)) {
5070 writel(misc1_flags, base + NvRegMisc1);
5071 writel(filter_flags, base + NvRegPacketFilterFlags);
5072 nv_enable_irq(dev);
5073 }
5074
5075 return ret;
5076}
5077
5078static void nv_self_test(struct net_device *dev, struct ethtool_test *test, u64 *buffer)
5079{
5080 struct fe_priv *np = netdev_priv(dev);
5081 u8 __iomem *base = get_hwbase(dev);
5082 int result;
Jeff Garzikb9f2c042007-10-03 18:07:32 -07005083 memset(buffer, 0, nv_get_sset_count(dev, ETH_SS_TEST)*sizeof(u64));
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005084
5085 if (!nv_link_test(dev)) {
5086 test->flags |= ETH_TEST_FL_FAILED;
5087 buffer[0] = 1;
5088 }
5089
5090 if (test->flags & ETH_TEST_FL_OFFLINE) {
5091 if (netif_running(dev)) {
5092 netif_stop_queue(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00005093 nv_napi_disable(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10005094 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07005095 netif_addr_lock(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005096 spin_lock_irq(&np->lock);
5097 nv_disable_hw_interrupts(dev, np->irqmask);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005098 if (!(np->msi_flags & NV_MSI_X_ENABLED))
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005099 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005100 else
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005101 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005102 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005103 nv_stop_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005104 nv_txrx_reset(dev);
5105 /* drain rx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005106 nv_drain_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005107 spin_unlock_irq(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07005108 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10005109 netif_tx_unlock_bh(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005110 }
5111
5112 if (!nv_register_test(dev)) {
5113 test->flags |= ETH_TEST_FL_FAILED;
5114 buffer[1] = 1;
5115 }
5116
5117 result = nv_interrupt_test(dev);
5118 if (result != 1) {
5119 test->flags |= ETH_TEST_FL_FAILED;
5120 buffer[2] = 1;
5121 }
5122 if (result == 0) {
5123 /* bail out */
5124 return;
5125 }
5126
5127 if (!nv_loopback_test(dev)) {
5128 test->flags |= ETH_TEST_FL_FAILED;
5129 buffer[3] = 1;
5130 }
5131
5132 if (netif_running(dev)) {
5133 /* reinit driver view of the rx queue */
5134 set_bufsize(dev);
5135 if (nv_init_ring(dev)) {
5136 if (!np->in_shutdown)
5137 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
5138 }
5139 /* reinit nic view of the rx queue */
5140 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
5141 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005142 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005143 base + NvRegRingSizes);
5144 pci_push(base);
5145 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
5146 pci_push(base);
5147 /* restart rx engine */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005148 nv_start_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005149 netif_start_queue(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00005150 nv_napi_enable(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005151 nv_enable_hw_interrupts(dev, np->irqmask);
5152 }
5153 }
5154}
5155
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005156static void nv_get_strings(struct net_device *dev, u32 stringset, u8 *buffer)
5157{
5158 switch (stringset) {
5159 case ETH_SS_STATS:
Jeff Garzikb9f2c042007-10-03 18:07:32 -07005160 memcpy(buffer, &nv_estats_str, nv_get_sset_count(dev, ETH_SS_STATS)*sizeof(struct nv_ethtool_str));
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005161 break;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005162 case ETH_SS_TEST:
Jeff Garzikb9f2c042007-10-03 18:07:32 -07005163 memcpy(buffer, &nv_etests_str, nv_get_sset_count(dev, ETH_SS_TEST)*sizeof(struct nv_ethtool_str));
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005164 break;
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005165 }
5166}
5167
Jeff Garzik7282d492006-09-13 14:30:00 -04005168static const struct ethtool_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005169 .get_drvinfo = nv_get_drvinfo,
5170 .get_link = ethtool_op_get_link,
5171 .get_wol = nv_get_wol,
5172 .set_wol = nv_set_wol,
5173 .get_settings = nv_get_settings,
5174 .set_settings = nv_set_settings,
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005175 .get_regs_len = nv_get_regs_len,
5176 .get_regs = nv_get_regs,
5177 .nway_reset = nv_nway_reset,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005178 .get_ringparam = nv_get_ringparam,
5179 .set_ringparam = nv_set_ringparam,
Ayaz Abdullab6d07732006-06-10 22:47:42 -04005180 .get_pauseparam = nv_get_pauseparam,
5181 .set_pauseparam = nv_set_pauseparam,
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005182 .get_strings = nv_get_strings,
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005183 .get_ethtool_stats = nv_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07005184 .get_sset_count = nv_get_sset_count,
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005185 .self_test = nv_self_test,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005186};
5187
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005188/* The mgmt unit and driver use a semaphore to access the phy during init */
5189static int nv_mgmt_acquire_sema(struct net_device *dev)
5190{
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005191 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005192 u8 __iomem *base = get_hwbase(dev);
5193 int i;
5194 u32 tx_ctrl, mgmt_sema;
5195
5196 for (i = 0; i < 10; i++) {
5197 mgmt_sema = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_SEMA_MASK;
5198 if (mgmt_sema == NVREG_XMITCTL_MGMT_SEMA_FREE)
5199 break;
5200 msleep(500);
5201 }
5202
5203 if (mgmt_sema != NVREG_XMITCTL_MGMT_SEMA_FREE)
5204 return 0;
5205
5206 for (i = 0; i < 2; i++) {
5207 tx_ctrl = readl(base + NvRegTransmitterControl);
5208 tx_ctrl |= NVREG_XMITCTL_HOST_SEMA_ACQ;
5209 writel(tx_ctrl, base + NvRegTransmitterControl);
5210
5211 /* verify that semaphore was acquired */
5212 tx_ctrl = readl(base + NvRegTransmitterControl);
5213 if (((tx_ctrl & NVREG_XMITCTL_HOST_SEMA_MASK) == NVREG_XMITCTL_HOST_SEMA_ACQ) &&
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005214 ((tx_ctrl & NVREG_XMITCTL_MGMT_SEMA_MASK) == NVREG_XMITCTL_MGMT_SEMA_FREE)) {
5215 np->mgmt_sema = 1;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005216 return 1;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005217 } else
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005218 udelay(50);
5219 }
5220
5221 return 0;
5222}
5223
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005224static void nv_mgmt_release_sema(struct net_device *dev)
5225{
5226 struct fe_priv *np = netdev_priv(dev);
5227 u8 __iomem *base = get_hwbase(dev);
5228 u32 tx_ctrl;
5229
5230 if (np->driver_data & DEV_HAS_MGMT_UNIT) {
5231 if (np->mgmt_sema) {
5232 tx_ctrl = readl(base + NvRegTransmitterControl);
5233 tx_ctrl &= ~NVREG_XMITCTL_HOST_SEMA_ACQ;
5234 writel(tx_ctrl, base + NvRegTransmitterControl);
5235 }
5236 }
5237}
5238
5239
5240static int nv_mgmt_get_version(struct net_device *dev)
5241{
5242 struct fe_priv *np = netdev_priv(dev);
5243 u8 __iomem *base = get_hwbase(dev);
5244 u32 data_ready = readl(base + NvRegTransmitterControl);
5245 u32 data_ready2 = 0;
5246 unsigned long start;
5247 int ready = 0;
5248
5249 writel(NVREG_MGMTUNITGETVERSION, base + NvRegMgmtUnitGetVersion);
5250 writel(data_ready ^ NVREG_XMITCTL_DATA_START, base + NvRegTransmitterControl);
5251 start = jiffies;
5252 while (time_before(jiffies, start + 5*HZ)) {
5253 data_ready2 = readl(base + NvRegTransmitterControl);
5254 if ((data_ready & NVREG_XMITCTL_DATA_READY) != (data_ready2 & NVREG_XMITCTL_DATA_READY)) {
5255 ready = 1;
5256 break;
5257 }
5258 schedule_timeout_uninterruptible(1);
5259 }
5260
5261 if (!ready || (data_ready2 & NVREG_XMITCTL_DATA_ERROR))
5262 return 0;
5263
5264 np->mgmt_version = readl(base + NvRegMgmtUnitVersion) & NVREG_MGMTUNITVERSION;
5265
5266 return 1;
5267}
5268
Linus Torvalds1da177e2005-04-16 15:20:36 -07005269static int nv_open(struct net_device *dev)
5270{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005271 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005272 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005273 int ret = 1;
5274 int oom, i;
Ayaz Abdullaa4336862008-04-18 13:50:43 -07005275 u32 low;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005276
Ed Swierkcb52deb2008-12-01 12:24:43 +00005277 /* power up phy */
5278 mii_rw(dev, np->phyaddr, MII_BMCR,
5279 mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ) & ~BMCR_PDOWN);
5280
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00005281 nv_txrx_gate(dev, false);
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005282 /* erase previous misconfiguration */
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005283 if (np->driver_data & DEV_HAS_POWER_CNTRL)
5284 nv_mac_reset(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005285 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
5286 writel(0, base + NvRegMulticastAddrB);
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -05005287 writel(NVREG_MCASTMASKA_NONE, base + NvRegMulticastMaskA);
5288 writel(NVREG_MCASTMASKB_NONE, base + NvRegMulticastMaskB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005289 writel(0, base + NvRegPacketFilterFlags);
5290
5291 writel(0, base + NvRegTransmitterControl);
5292 writel(0, base + NvRegReceiverControl);
5293
5294 writel(0, base + NvRegAdapterControl);
5295
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04005296 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)
5297 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
5298
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005299 /* initialize descriptor rings */
Manfred Sprauld81c0982005-07-31 18:20:30 +02005300 set_bufsize(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005301 oom = nv_init_ring(dev);
5302
5303 writel(0, base + NvRegLinkSpeed);
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005304 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005305 nv_txrx_reset(dev);
5306 writel(0, base + NvRegUnknownSetupReg6);
5307
5308 np->in_shutdown = 0;
5309
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005310 /* give hw rings */
Ayaz Abdulla0832b252006-02-04 13:13:26 -05005311 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005312 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Linus Torvalds1da177e2005-04-16 15:20:36 -07005313 base + NvRegRingSizes);
5314
Linus Torvalds1da177e2005-04-16 15:20:36 -07005315 writel(np->linkspeed, base + NvRegLinkSpeed);
Ayaz Abdulla95d161c2006-07-06 16:46:25 -04005316 if (np->desc_ver == DESC_VER_1)
5317 writel(NVREG_TX_WM_DESC1_DEFAULT, base + NvRegTxWatermark);
5318 else
5319 writel(NVREG_TX_WM_DESC2_3_DEFAULT, base + NvRegTxWatermark);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005320 writel(np->txrxctl_bits, base + NvRegTxRxControl);
Ayaz Abdullaee407b02006-02-04 13:13:17 -05005321 writel(np->vlanctl_bits, base + NvRegVlanControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005322 pci_push(base);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005323 writel(NVREG_TXRXCTL_BIT1|np->txrxctl_bits, base + NvRegTxRxControl);
Joe Perches344d0dc2010-11-29 07:41:52 +00005324 if (reg_delay(dev, NvRegUnknownSetupReg5,
5325 NVREG_UNKSETUP5_BIT31, NVREG_UNKSETUP5_BIT31,
5326 NV_SETUP5_DELAY, NV_SETUP5_DELAYMAX))
Joe Perches1d397f32010-11-29 07:41:57 +00005327 netdev_info(dev,
5328 "%s: SetupReg5, Bit 31 remained off\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005329
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005330 writel(0, base + NvRegMIIMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005331 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005332 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005333
Linus Torvalds1da177e2005-04-16 15:20:36 -07005334 writel(NVREG_MISC1_FORCE | NVREG_MISC1_HD, base + NvRegMisc1);
5335 writel(readl(base + NvRegTransmitterStatus), base + NvRegTransmitterStatus);
5336 writel(NVREG_PFF_ALWAYS, base + NvRegPacketFilterFlags);
Manfred Sprauld81c0982005-07-31 18:20:30 +02005337 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005338
5339 writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus);
Ayaz Abdullaa4336862008-04-18 13:50:43 -07005340
5341 get_random_bytes(&low, sizeof(low));
5342 low &= NVREG_SLOTTIME_MASK;
5343 if (np->desc_ver == DESC_VER_1) {
5344 writel(low|NVREG_SLOTTIME_DEFAULT, base + NvRegSlotTime);
5345 } else {
5346 if (!(np->driver_data & DEV_HAS_GEAR_MODE)) {
5347 /* setup legacy backoff */
5348 writel(NVREG_SLOTTIME_LEGBF_ENABLED|NVREG_SLOTTIME_10_100_FULL|low, base + NvRegSlotTime);
5349 } else {
5350 writel(NVREG_SLOTTIME_10_100_FULL, base + NvRegSlotTime);
5351 nv_gear_backoff_reseed(dev);
5352 }
5353 }
Ayaz Abdulla9744e212006-07-06 16:45:58 -04005354 writel(NVREG_TX_DEFERRAL_DEFAULT, base + NvRegTxDeferral);
5355 writel(NVREG_RX_DEFERRAL_DEFAULT, base + NvRegRxDeferral);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005356 if (poll_interval == -1) {
5357 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT)
5358 writel(NVREG_POLL_DEFAULT_THROUGHPUT, base + NvRegPollingInterval);
5359 else
5360 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005361 } else
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005362 writel(poll_interval & 0xFFFF, base + NvRegPollingInterval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005363 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
5364 writel((np->phyaddr << NVREG_ADAPTCTL_PHYSHIFT)|NVREG_ADAPTCTL_PHYVALID|NVREG_ADAPTCTL_RUNNING,
5365 base + NvRegAdapterControl);
5366 writel(NVREG_MIISPEED_BIT8|NVREG_MIIDELAY, base + NvRegMIISpeed);
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005367 writel(NVREG_MII_LINKCHANGE, base + NvRegMIIMask);
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04005368 if (np->wolenabled)
5369 writel(NVREG_WAKEUPFLAGS_ENABLE , base + NvRegWakeUpFlags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005370
5371 i = readl(base + NvRegPowerState);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005372 if ((i & NVREG_POWERSTATE_POWEREDUP) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005373 writel(NVREG_POWERSTATE_POWEREDUP|i, base + NvRegPowerState);
5374
5375 pci_push(base);
5376 udelay(10);
5377 writel(readl(base + NvRegPowerState) | NVREG_POWERSTATE_VALID, base + NvRegPowerState);
5378
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005379 nv_disable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005380 pci_push(base);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005381 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005382 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
5383 pci_push(base);
5384
Szymon Janc78aea4f2010-11-27 08:39:43 +00005385 if (nv_request_irq(dev, 0))
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005386 goto out_drain;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005387
5388 /* ask for interrupts */
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005389 nv_enable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005390
5391 spin_lock_irq(&np->lock);
5392 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
5393 writel(0, base + NvRegMulticastAddrB);
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -05005394 writel(NVREG_MCASTMASKA_NONE, base + NvRegMulticastMaskA);
5395 writel(NVREG_MCASTMASKB_NONE, base + NvRegMulticastMaskB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005396 writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
5397 /* One manual link speed update: Interrupts are enabled, future link
5398 * speed changes cause interrupts and are handled by nv_link_irq().
5399 */
5400 {
5401 u32 miistat;
5402 miistat = readl(base + NvRegMIIStatus);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005403 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005404 }
Manfred Spraul1b1b3c92005-08-06 23:47:55 +02005405 /* set linkspeed to invalid value, thus force nv_update_linkspeed
5406 * to init hw */
5407 np->linkspeed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005408 ret = nv_update_linkspeed(dev);
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005409 nv_start_rxtx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005410 netif_start_queue(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00005411 nv_napi_enable(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07005412
Linus Torvalds1da177e2005-04-16 15:20:36 -07005413 if (ret) {
5414 netif_carrier_on(dev);
5415 } else {
Joe Perches1d397f32010-11-29 07:41:57 +00005416 netdev_info(dev, "no link during initialization\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005417 netif_carrier_off(dev);
5418 }
5419 if (oom)
5420 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005421
5422 /* start statistics timer */
Ayaz Abdulla9c662432008-08-06 12:11:42 -04005423 if (np->driver_data & (DEV_HAS_STATISTICS_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_STATISTICS_V3))
Daniel Drakebfebbb82008-03-18 11:07:18 +00005424 mod_timer(&np->stats_poll,
5425 round_jiffies(jiffies + STATS_INTERVAL));
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005426
Linus Torvalds1da177e2005-04-16 15:20:36 -07005427 spin_unlock_irq(&np->lock);
5428
Sanjay Hortikare19df762011-11-11 16:11:21 +00005429 /* If the loopback feature was set while the device was down, make sure
5430 * that it's set correctly now.
5431 */
5432 if (dev->features & NETIF_F_LOOPBACK)
5433 nv_set_loopback(dev, dev->features);
5434
Linus Torvalds1da177e2005-04-16 15:20:36 -07005435 return 0;
5436out_drain:
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005437 nv_drain_rxtx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005438 return ret;
5439}
5440
5441static int nv_close(struct net_device *dev)
5442{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005443 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005444 u8 __iomem *base;
5445
5446 spin_lock_irq(&np->lock);
5447 np->in_shutdown = 1;
5448 spin_unlock_irq(&np->lock);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00005449 nv_napi_disable(dev);
Manfred Spraula7475902007-10-17 21:52:33 +02005450 synchronize_irq(np->pci_dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005451
5452 del_timer_sync(&np->oom_kick);
5453 del_timer_sync(&np->nic_poll);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005454 del_timer_sync(&np->stats_poll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005455
5456 netif_stop_queue(dev);
5457 spin_lock_irq(&np->lock);
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005458 nv_stop_rxtx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005459 nv_txrx_reset(dev);
5460
5461 /* disable interrupts on the nic or we will lock up */
5462 base = get_hwbase(dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005463 nv_disable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005464 pci_push(base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005465
5466 spin_unlock_irq(&np->lock);
5467
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005468 nv_free_irq(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005469
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005470 nv_drain_rxtx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005471
Ed Swierk5a9a8e32009-06-02 00:19:52 -07005472 if (np->wolenabled || !phy_power_down) {
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00005473 nv_txrx_gate(dev, false);
Tim Mann2cc49a52007-06-14 13:16:38 -07005474 writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005475 nv_start_rx(dev);
Ed Swierkcb52deb2008-12-01 12:24:43 +00005476 } else {
5477 /* power down phy */
5478 mii_rw(dev, np->phyaddr, MII_BMCR,
5479 mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ)|BMCR_PDOWN);
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00005480 nv_txrx_gate(dev, true);
Tim Mann2cc49a52007-06-14 13:16:38 -07005481 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005482
5483 /* FIXME: power down nic */
5484
5485 return 0;
5486}
5487
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005488static const struct net_device_ops nv_netdev_ops = {
5489 .ndo_open = nv_open,
5490 .ndo_stop = nv_close,
david decotignyf5d827a2011-11-16 12:15:13 +00005491 .ndo_get_stats64 = nv_get_stats64,
Stephen Hemminger00829822008-11-20 20:14:53 -08005492 .ndo_start_xmit = nv_start_xmit,
5493 .ndo_tx_timeout = nv_tx_timeout,
5494 .ndo_change_mtu = nv_change_mtu,
Michał Mirosław569e1462011-04-15 04:50:49 +00005495 .ndo_fix_features = nv_fix_features,
5496 .ndo_set_features = nv_set_features,
Stephen Hemminger00829822008-11-20 20:14:53 -08005497 .ndo_validate_addr = eth_validate_addr,
5498 .ndo_set_mac_address = nv_set_mac_address,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00005499 .ndo_set_rx_mode = nv_set_multicast,
Stephen Hemminger00829822008-11-20 20:14:53 -08005500#ifdef CONFIG_NET_POLL_CONTROLLER
5501 .ndo_poll_controller = nv_poll_controller,
5502#endif
5503};
5504
5505static const struct net_device_ops nv_netdev_ops_optimized = {
5506 .ndo_open = nv_open,
5507 .ndo_stop = nv_close,
david decotignyf5d827a2011-11-16 12:15:13 +00005508 .ndo_get_stats64 = nv_get_stats64,
Stephen Hemminger00829822008-11-20 20:14:53 -08005509 .ndo_start_xmit = nv_start_xmit_optimized,
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005510 .ndo_tx_timeout = nv_tx_timeout,
5511 .ndo_change_mtu = nv_change_mtu,
Michał Mirosław569e1462011-04-15 04:50:49 +00005512 .ndo_fix_features = nv_fix_features,
5513 .ndo_set_features = nv_set_features,
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005514 .ndo_validate_addr = eth_validate_addr,
5515 .ndo_set_mac_address = nv_set_mac_address,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00005516 .ndo_set_rx_mode = nv_set_multicast,
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005517#ifdef CONFIG_NET_POLL_CONTROLLER
5518 .ndo_poll_controller = nv_poll_controller,
5519#endif
5520};
5521
Linus Torvalds1da177e2005-04-16 15:20:36 -07005522static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
5523{
5524 struct net_device *dev;
5525 struct fe_priv *np;
5526 unsigned long addr;
5527 u8 __iomem *base;
5528 int err, i;
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005529 u32 powerstate, txreg;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005530 u32 phystate_orig = 0, phystate;
5531 int phyinitialized = 0;
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005532 static int printed_version;
5533
5534 if (!printed_version++)
Joe Perches294a5542010-11-29 07:41:56 +00005535 pr_info("Reverse Engineered nForce ethernet driver. Version %s.\n",
5536 FORCEDETH_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005537
5538 dev = alloc_etherdev(sizeof(struct fe_priv));
5539 err = -ENOMEM;
5540 if (!dev)
5541 goto out;
5542
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005543 np = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07005544 np->dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005545 np->pci_dev = pci_dev;
5546 spin_lock_init(&np->lock);
david decotignyf5d827a2011-11-16 12:15:13 +00005547 spin_lock_init(&np->hwstats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005548 SET_NETDEV_DEV(dev, &pci_dev->dev);
5549
5550 init_timer(&np->oom_kick);
5551 np->oom_kick.data = (unsigned long) dev;
Joe Perchesc061b182010-08-23 18:20:03 +00005552 np->oom_kick.function = nv_do_rx_refill; /* timer handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005553 init_timer(&np->nic_poll);
5554 np->nic_poll.data = (unsigned long) dev;
Joe Perchesc061b182010-08-23 18:20:03 +00005555 np->nic_poll.function = nv_do_nic_poll; /* timer handler */
david decotigny8f5f6982011-11-16 12:15:15 +00005556 init_timer_deferrable(&np->stats_poll);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005557 np->stats_poll.data = (unsigned long) dev;
Joe Perchesc061b182010-08-23 18:20:03 +00005558 np->stats_poll.function = nv_do_stats_poll; /* timer handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005559
5560 err = pci_enable_device(pci_dev);
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005561 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005562 goto out_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005563
5564 pci_set_master(pci_dev);
5565
5566 err = pci_request_regions(pci_dev, DRV_NAME);
5567 if (err < 0)
5568 goto out_disable;
5569
Ayaz Abdulla9c662432008-08-06 12:11:42 -04005570 if (id->driver_data & (DEV_HAS_VLAN|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS_V2|DEV_HAS_STATISTICS_V3))
Ayaz Abdulla57fff692007-01-23 12:27:00 -05005571 np->register_size = NV_PCI_REGSZ_VER3;
5572 else if (id->driver_data & DEV_HAS_STATISTICS_V1)
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005573 np->register_size = NV_PCI_REGSZ_VER2;
5574 else
5575 np->register_size = NV_PCI_REGSZ_VER1;
5576
Linus Torvalds1da177e2005-04-16 15:20:36 -07005577 err = -EINVAL;
5578 addr = 0;
5579 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005580 if (pci_resource_flags(pci_dev, i) & IORESOURCE_MEM &&
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005581 pci_resource_len(pci_dev, i) >= np->register_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005582 addr = pci_resource_start(pci_dev, i);
5583 break;
5584 }
5585 }
5586 if (i == DEVICE_COUNT_RESOURCE) {
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005587 dev_info(&pci_dev->dev, "Couldn't find register window\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005588 goto out_relreg;
5589 }
5590
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005591 /* copy of driver data */
5592 np->driver_data = id->driver_data;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04005593 /* copy of device id */
5594 np->device_id = id->device;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005595
Linus Torvalds1da177e2005-04-16 15:20:36 -07005596 /* handle different descriptor versions */
Manfred Spraulee733622005-07-31 18:32:26 +02005597 if (id->driver_data & DEV_HAS_HIGH_DMA) {
5598 /* packet format 3: supports 40-bit addressing */
5599 np->desc_ver = DESC_VER_3;
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005600 np->txrxctl_bits = NVREG_TXRXCTL_DESC_3;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005601 if (dma_64bit) {
Yang Hongyang6afd1422009-04-06 19:01:15 -07005602 if (pci_set_dma_mask(pci_dev, DMA_BIT_MASK(39)))
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005603 dev_info(&pci_dev->dev,
5604 "64-bit DMA failed, using 32-bit addressing\n");
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005605 else
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005606 dev->features |= NETIF_F_HIGHDMA;
Yang Hongyang6afd1422009-04-06 19:01:15 -07005607 if (pci_set_consistent_dma_mask(pci_dev, DMA_BIT_MASK(39))) {
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005608 dev_info(&pci_dev->dev,
5609 "64-bit DMA (consistent) failed, using 32-bit ring buffers\n");
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005610 }
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005611 }
Manfred Spraulee733622005-07-31 18:32:26 +02005612 } else if (id->driver_data & DEV_HAS_LARGEDESC) {
5613 /* packet format 2: supports jumbo frames */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005614 np->desc_ver = DESC_VER_2;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005615 np->txrxctl_bits = NVREG_TXRXCTL_DESC_2;
Manfred Spraulee733622005-07-31 18:32:26 +02005616 } else {
5617 /* original packet format */
5618 np->desc_ver = DESC_VER_1;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005619 np->txrxctl_bits = NVREG_TXRXCTL_DESC_1;
Manfred Sprauld81c0982005-07-31 18:20:30 +02005620 }
Manfred Spraulee733622005-07-31 18:32:26 +02005621
5622 np->pkt_limit = NV_PKTLIMIT_1;
5623 if (id->driver_data & DEV_HAS_LARGEDESC)
5624 np->pkt_limit = NV_PKTLIMIT_2;
5625
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005626 if (id->driver_data & DEV_HAS_CHECKSUM) {
5627 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
Michał Mirosław569e1462011-04-15 04:50:49 +00005628 dev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_SG |
5629 NETIF_F_TSO | NETIF_F_RXCSUM;
Ayaz Abdulla21828162007-01-23 12:27:21 -05005630 }
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005631
Ayaz Abdullaee407b02006-02-04 13:13:17 -05005632 np->vlanctl_bits = 0;
5633 if (id->driver_data & DEV_HAS_VLAN) {
5634 np->vlanctl_bits = NVREG_VLANCONTROL_ENABLE;
Jiri Pirko0891b0e2011-07-26 10:19:28 +00005635 dev->hw_features |= NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX;
Ayaz Abdullaee407b02006-02-04 13:13:17 -05005636 }
5637
Jiri Pirko0891b0e2011-07-26 10:19:28 +00005638 dev->features |= dev->hw_features;
5639
Sanjay Hortikare19df762011-11-11 16:11:21 +00005640 /* Add loopback capability to the device. */
5641 dev->hw_features |= NETIF_F_LOOPBACK;
5642
Ayaz Abdullab6d07732006-06-10 22:47:42 -04005643 np->pause_flags = NV_PAUSEFRAME_RX_CAPABLE | NV_PAUSEFRAME_RX_REQ | NV_PAUSEFRAME_AUTONEG;
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05005644 if ((id->driver_data & DEV_HAS_PAUSEFRAME_TX_V1) ||
5645 (id->driver_data & DEV_HAS_PAUSEFRAME_TX_V2) ||
5646 (id->driver_data & DEV_HAS_PAUSEFRAME_TX_V3)) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04005647 np->pause_flags |= NV_PAUSEFRAME_TX_CAPABLE | NV_PAUSEFRAME_TX_REQ;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04005648 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04005649
Linus Torvalds1da177e2005-04-16 15:20:36 -07005650 err = -ENOMEM;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005651 np->base = ioremap(addr, np->register_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005652 if (!np->base)
5653 goto out_relreg;
Manfred Spraulee733622005-07-31 18:32:26 +02005654
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005655 np->rx_ring_size = RX_RING_DEFAULT;
5656 np->tx_ring_size = TX_RING_DEFAULT;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005657
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005658 if (!nv_optimized(np)) {
Manfred Spraulee733622005-07-31 18:32:26 +02005659 np->rx_ring.orig = pci_alloc_consistent(pci_dev,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005660 sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
Manfred Spraulee733622005-07-31 18:32:26 +02005661 &np->ring_addr);
5662 if (!np->rx_ring.orig)
5663 goto out_unmap;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005664 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
Manfred Spraulee733622005-07-31 18:32:26 +02005665 } else {
5666 np->rx_ring.ex = pci_alloc_consistent(pci_dev,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005667 sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
Manfred Spraulee733622005-07-31 18:32:26 +02005668 &np->ring_addr);
5669 if (!np->rx_ring.ex)
5670 goto out_unmap;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005671 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
Manfred Spraulee733622005-07-31 18:32:26 +02005672 }
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07005673 np->rx_skb = kcalloc(np->rx_ring_size, sizeof(struct nv_skb_map), GFP_KERNEL);
5674 np->tx_skb = kcalloc(np->tx_ring_size, sizeof(struct nv_skb_map), GFP_KERNEL);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05005675 if (!np->rx_skb || !np->tx_skb)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005676 goto out_freering;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005677
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005678 if (!nv_optimized(np))
Stephen Hemminger00829822008-11-20 20:14:53 -08005679 dev->netdev_ops = &nv_netdev_ops;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05005680 else
Stephen Hemminger00829822008-11-20 20:14:53 -08005681 dev->netdev_ops = &nv_netdev_ops_optimized;
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005682
Stephen Hemmingerbea33482007-10-03 16:41:36 -07005683 netif_napi_add(dev, &np->napi, nv_napi_poll, RX_WORK_PER_LOOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005684 SET_ETHTOOL_OPS(dev, &ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005685 dev->watchdog_timeo = NV_WATCHDOG_TIMEO;
5686
5687 pci_set_drvdata(pci_dev, dev);
5688
5689 /* read the mac address */
5690 base = get_hwbase(dev);
5691 np->orig_mac[0] = readl(base + NvRegMacAddrA);
5692 np->orig_mac[1] = readl(base + NvRegMacAddrB);
5693
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005694 /* check the workaround bit for correct mac address order */
5695 txreg = readl(base + NvRegTransmitPoll);
Ayaz Abdullaa376e792008-04-10 21:30:35 -07005696 if (id->driver_data & DEV_HAS_CORRECT_MACADDR) {
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005697 /* mac address is already in correct order */
5698 dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff;
5699 dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff;
5700 dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff;
5701 dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff;
5702 dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff;
5703 dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff;
Ayaz Abdullaa376e792008-04-10 21:30:35 -07005704 } else if (txreg & NVREG_TRANSMITPOLL_MAC_ADDR_REV) {
5705 /* mac address is already in correct order */
5706 dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff;
5707 dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff;
5708 dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff;
5709 dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff;
5710 dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff;
5711 dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff;
5712 /*
5713 * Set orig mac address back to the reversed version.
5714 * This flag will be cleared during low power transition.
5715 * Therefore, we should always put back the reversed address.
5716 */
5717 np->orig_mac[0] = (dev->dev_addr[5] << 0) + (dev->dev_addr[4] << 8) +
5718 (dev->dev_addr[3] << 16) + (dev->dev_addr[2] << 24);
5719 np->orig_mac[1] = (dev->dev_addr[1] << 0) + (dev->dev_addr[0] << 8);
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005720 } else {
5721 /* need to reverse mac address to correct order */
5722 dev->dev_addr[0] = (np->orig_mac[1] >> 8) & 0xff;
5723 dev->dev_addr[1] = (np->orig_mac[1] >> 0) & 0xff;
5724 dev->dev_addr[2] = (np->orig_mac[0] >> 24) & 0xff;
5725 dev->dev_addr[3] = (np->orig_mac[0] >> 16) & 0xff;
5726 dev->dev_addr[4] = (np->orig_mac[0] >> 8) & 0xff;
5727 dev->dev_addr[5] = (np->orig_mac[0] >> 0) & 0xff;
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005728 writel(txreg|NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
Joe Perchesc20ec762010-11-29 07:42:02 +00005729 dev_dbg(&pci_dev->dev,
5730 "%s: set workaround bit for reversed mac addr\n",
5731 __func__);
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005732 }
John W. Linvillec704b852005-09-12 10:48:56 -04005733 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005734
John W. Linvillec704b852005-09-12 10:48:56 -04005735 if (!is_valid_ether_addr(dev->perm_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005736 /*
5737 * Bad mac address. At least one bios sets the mac address
5738 * to 01:23:45:67:89:ab
5739 */
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005740 dev_err(&pci_dev->dev,
Joe Perchesc20ec762010-11-29 07:42:02 +00005741 "Invalid MAC address detected: %pM - Please complain to your hardware vendor.\n",
Szymon Janc78aea4f2010-11-27 08:39:43 +00005742 dev->dev_addr);
Danny Kukawka7ce5d222012-02-15 06:45:40 +00005743 eth_hw_addr_random(dev);
Joe Perchesc20ec762010-11-29 07:42:02 +00005744 dev_err(&pci_dev->dev,
5745 "Using random MAC address: %pM\n", dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005746 }
5747
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005748 /* set mac address */
5749 nv_copy_mac_to_hw(dev);
5750
Linus Torvalds1da177e2005-04-16 15:20:36 -07005751 /* disable WOL */
5752 writel(0, base + NvRegWakeUpFlags);
5753 np->wolenabled = 0;
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00005754 device_set_wakeup_enable(&pci_dev->dev, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005755
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005756 if (id->driver_data & DEV_HAS_POWER_CNTRL) {
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005757
5758 /* take phy and nic out of low power mode */
5759 powerstate = readl(base + NvRegPowerState2);
5760 powerstate &= ~NVREG_POWERSTATE2_POWERUP_MASK;
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00005761 if ((id->driver_data & DEV_NEED_LOW_POWER_FIX) &&
Auke Kok44c10132007-06-08 15:46:36 -07005762 pci_dev->revision >= 0xA3)
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005763 powerstate |= NVREG_POWERSTATE2_POWERUP_REV_A3;
5764 writel(powerstate, base + NvRegPowerState2);
5765 }
5766
Szymon Janc78aea4f2010-11-27 08:39:43 +00005767 if (np->desc_ver == DESC_VER_1)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005768 np->tx_flags = NV_TX_VALID;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005769 else
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005770 np->tx_flags = NV_TX2_VALID;
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005771
5772 np->msi_flags = 0;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005773 if ((id->driver_data & DEV_HAS_MSI) && msi)
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005774 np->msi_flags |= NV_MSI_CAPABLE;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005775
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005776 if ((id->driver_data & DEV_HAS_MSI_X) && msix) {
5777 /* msix has had reported issues when modifying irqmask
5778 as in the case of napi, therefore, disable for now
5779 */
David S. Miller0a127612010-05-03 23:33:05 -07005780#if 0
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005781 np->msi_flags |= NV_MSI_X_CAPABLE;
5782#endif
5783 }
5784
5785 if (optimization_mode == NV_OPTIMIZATION_MODE_CPU) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005786 np->irqmask = NVREG_IRQMASK_CPU;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005787 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
5788 np->msi_flags |= 0x0001;
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005789 } else if (optimization_mode == NV_OPTIMIZATION_MODE_DYNAMIC &&
5790 !(id->driver_data & DEV_NEED_TIMERIRQ)) {
5791 /* start off in throughput mode */
5792 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
5793 /* remove support for msix mode */
5794 np->msi_flags &= ~NV_MSI_X_CAPABLE;
5795 } else {
5796 optimization_mode = NV_OPTIMIZATION_MODE_THROUGHPUT;
5797 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
5798 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
5799 np->msi_flags |= 0x0003;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005800 }
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005801
Linus Torvalds1da177e2005-04-16 15:20:36 -07005802 if (id->driver_data & DEV_NEED_TIMERIRQ)
5803 np->irqmask |= NVREG_IRQ_TIMER;
5804 if (id->driver_data & DEV_NEED_LINKTIMER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005805 np->need_linktimer = 1;
5806 np->link_timeout = jiffies + LINK_TIMEOUT;
5807 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005808 np->need_linktimer = 0;
5809 }
5810
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005811 /* Limit the number of tx's outstanding for hw bug */
5812 if (id->driver_data & DEV_NEED_TX_LIMIT) {
5813 np->tx_limit = 1;
Ayaz Abdulla5c659322010-04-13 18:49:51 -07005814 if (((id->driver_data & DEV_NEED_TX_LIMIT2) == DEV_NEED_TX_LIMIT2) &&
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005815 pci_dev->revision >= 0xA2)
5816 np->tx_limit = 0;
5817 }
5818
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005819 /* clear phy state and temporarily halt phy interrupts */
5820 writel(0, base + NvRegMIIMask);
5821 phystate = readl(base + NvRegAdapterControl);
5822 if (phystate & NVREG_ADAPTCTL_RUNNING) {
5823 phystate_orig = 1;
5824 phystate &= ~NVREG_ADAPTCTL_RUNNING;
5825 writel(phystate, base + NvRegAdapterControl);
5826 }
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005827 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005828
5829 if (id->driver_data & DEV_HAS_MGMT_UNIT) {
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005830 /* management unit running on the mac? */
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005831 if ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_ST) &&
5832 (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_PHY_INIT) &&
5833 nv_mgmt_acquire_sema(dev) &&
5834 nv_mgmt_get_version(dev)) {
5835 np->mac_in_use = 1;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005836 if (np->mgmt_version > 0)
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005837 np->mac_in_use = readl(base + NvRegMgmtUnitControl) & NVREG_MGMTUNITCONTROL_INUSE;
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005838 /* management unit setup the phy already? */
5839 if (np->mac_in_use &&
5840 ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK) ==
5841 NVREG_XMITCTL_SYNC_PHY_INIT)) {
5842 /* phy is inited by mgmt unit */
5843 phyinitialized = 1;
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005844 } else {
5845 /* we need to init the phy */
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005846 }
5847 }
5848 }
5849
Linus Torvalds1da177e2005-04-16 15:20:36 -07005850 /* find a suitable phy */
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005851 for (i = 1; i <= 32; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005852 int id1, id2;
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005853 int phyaddr = i & 0x1F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005854
5855 spin_lock_irq(&np->lock);
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005856 id1 = mii_rw(dev, phyaddr, MII_PHYSID1, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005857 spin_unlock_irq(&np->lock);
5858 if (id1 < 0 || id1 == 0xffff)
5859 continue;
5860 spin_lock_irq(&np->lock);
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005861 id2 = mii_rw(dev, phyaddr, MII_PHYSID2, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005862 spin_unlock_irq(&np->lock);
5863 if (id2 < 0 || id2 == 0xffff)
5864 continue;
5865
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04005866 np->phy_model = id2 & PHYID2_MODEL_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005867 id1 = (id1 & PHYID1_OUI_MASK) << PHYID1_OUI_SHFT;
5868 id2 = (id2 & PHYID2_OUI_MASK) >> PHYID2_OUI_SHFT;
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005869 np->phyaddr = phyaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005870 np->phy_oui = id1 | id2;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04005871
5872 /* Realtek hardcoded phy id1 to all zero's on certain phys */
5873 if (np->phy_oui == PHY_OUI_REALTEK2)
5874 np->phy_oui = PHY_OUI_REALTEK;
5875 /* Setup phy revision for Realtek */
5876 if (np->phy_oui == PHY_OUI_REALTEK && np->phy_model == PHY_MODEL_REALTEK_8211)
5877 np->phy_rev = mii_rw(dev, phyaddr, MII_RESV1, MII_READ) & PHY_REV_MASK;
5878
Linus Torvalds1da177e2005-04-16 15:20:36 -07005879 break;
5880 }
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005881 if (i == 33) {
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005882 dev_info(&pci_dev->dev, "open: Could not find a valid PHY\n");
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005883 goto out_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005884 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04005885
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005886 if (!phyinitialized) {
5887 /* reset it */
5888 phy_init(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05005889 } else {
5890 /* see if it is a gigabit phy */
5891 u32 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005892 if (mii_status & PHY_GIGABIT)
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05005893 np->gigabit = PHY_GIGABIT;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005894 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005895
5896 /* set default link speed settings */
5897 np->linkspeed = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
5898 np->duplex = 0;
5899 np->autoneg = 1;
5900
5901 err = register_netdev(dev);
5902 if (err) {
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005903 dev_info(&pci_dev->dev, "unable to register netdev: %d\n", err);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005904 goto out_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005905 }
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005906
David S. Miller823dcd22011-08-20 10:39:12 -07005907 if (id->driver_data & DEV_HAS_VLAN)
5908 nv_vlan_mode(dev, dev->features);
Jiri Pirko0891b0e2011-07-26 10:19:28 +00005909
Ivan Vecera0d672e92011-02-15 02:08:39 +00005910 netif_carrier_off(dev);
5911
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005912 dev_info(&pci_dev->dev, "ifname %s, PHY OUI 0x%x @ %d, addr %pM\n",
5913 dev->name, np->phy_oui, np->phyaddr, dev->dev_addr);
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005914
Sanjay Hortikare19df762011-11-11 16:11:21 +00005915 dev_info(&pci_dev->dev, "%s%s%s%s%s%s%s%s%s%s%sdesc-v%u\n",
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005916 dev->features & NETIF_F_HIGHDMA ? "highdma " : "",
5917 dev->features & (NETIF_F_IP_CSUM | NETIF_F_SG) ?
Szymon Janc78aea4f2010-11-27 08:39:43 +00005918 "csum " : "",
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005919 dev->features & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX) ?
Szymon Janc78aea4f2010-11-27 08:39:43 +00005920 "vlan " : "",
Sanjay Hortikare19df762011-11-11 16:11:21 +00005921 dev->features & (NETIF_F_LOOPBACK) ?
5922 "loopback " : "",
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005923 id->driver_data & DEV_HAS_POWER_CNTRL ? "pwrctl " : "",
5924 id->driver_data & DEV_HAS_MGMT_UNIT ? "mgmt " : "",
5925 id->driver_data & DEV_NEED_TIMERIRQ ? "timirq " : "",
5926 np->gigabit == PHY_GIGABIT ? "gbit " : "",
5927 np->need_linktimer ? "lnktim " : "",
5928 np->msi_flags & NV_MSI_CAPABLE ? "msi " : "",
5929 np->msi_flags & NV_MSI_X_CAPABLE ? "msi-x " : "",
5930 np->desc_ver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005931
5932 return 0;
5933
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005934out_error:
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005935 if (phystate_orig)
5936 writel(phystate|NVREG_ADAPTCTL_RUNNING, base + NvRegAdapterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005937 pci_set_drvdata(pci_dev, NULL);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005938out_freering:
5939 free_rings(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005940out_unmap:
5941 iounmap(get_hwbase(dev));
5942out_relreg:
5943 pci_release_regions(pci_dev);
5944out_disable:
5945 pci_disable_device(pci_dev);
5946out_free:
5947 free_netdev(dev);
5948out:
5949 return err;
5950}
5951
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04005952static void nv_restore_phy(struct net_device *dev)
5953{
5954 struct fe_priv *np = netdev_priv(dev);
5955 u16 phy_reserved, mii_control;
5956
5957 if (np->phy_oui == PHY_OUI_REALTEK &&
5958 np->phy_model == PHY_MODEL_REALTEK_8201 &&
5959 phy_cross == NV_CROSSOVER_DETECTION_DISABLED) {
5960 mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3);
5961 phy_reserved = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, MII_READ);
5962 phy_reserved &= ~PHY_REALTEK_INIT_MSK1;
5963 phy_reserved |= PHY_REALTEK_INIT8;
5964 mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, phy_reserved);
5965 mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1);
5966
5967 /* restart auto negotiation */
5968 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
5969 mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE);
5970 mii_rw(dev, np->phyaddr, MII_BMCR, mii_control);
5971 }
5972}
5973
Yinghai Luf55c21f2008-09-13 13:10:31 -07005974static void nv_restore_mac_addr(struct pci_dev *pci_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005975{
5976 struct net_device *dev = pci_get_drvdata(pci_dev);
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005977 struct fe_priv *np = netdev_priv(dev);
5978 u8 __iomem *base = get_hwbase(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005979
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005980 /* special op: write back the misordered MAC address - otherwise
5981 * the next nv_probe would see a wrong address.
5982 */
5983 writel(np->orig_mac[0], base + NvRegMacAddrA);
5984 writel(np->orig_mac[1], base + NvRegMacAddrB);
Björn Steinbrink2e3884b2008-01-07 23:22:53 -08005985 writel(readl(base + NvRegTransmitPoll) & ~NVREG_TRANSMITPOLL_MAC_ADDR_REV,
5986 base + NvRegTransmitPoll);
Yinghai Luf55c21f2008-09-13 13:10:31 -07005987}
5988
5989static void __devexit nv_remove(struct pci_dev *pci_dev)
5990{
5991 struct net_device *dev = pci_get_drvdata(pci_dev);
5992
5993 unregister_netdev(dev);
5994
5995 nv_restore_mac_addr(pci_dev);
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005996
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04005997 /* restore any phy related changes */
5998 nv_restore_phy(dev);
5999
Ayaz Abdullacac1c522009-02-07 00:23:57 -08006000 nv_mgmt_release_sema(dev);
6001
Linus Torvalds1da177e2005-04-16 15:20:36 -07006002 /* free all structures */
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04006003 free_rings(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006004 iounmap(get_hwbase(dev));
6005 pci_release_regions(pci_dev);
6006 pci_disable_device(pci_dev);
6007 free_netdev(dev);
6008 pci_set_drvdata(pci_dev, NULL);
6009}
6010
Michel Lespinasse94252762011-03-06 16:14:50 +00006011#ifdef CONFIG_PM_SLEEP
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006012static int nv_suspend(struct device *device)
Francois Romieua1893172006-10-10 14:33:27 -07006013{
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006014 struct pci_dev *pdev = to_pci_dev(device);
Francois Romieua1893172006-10-10 14:33:27 -07006015 struct net_device *dev = pci_get_drvdata(pdev);
6016 struct fe_priv *np = netdev_priv(dev);
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006017 u8 __iomem *base = get_hwbase(dev);
6018 int i;
Francois Romieua1893172006-10-10 14:33:27 -07006019
Tobias Diedrich25d90812008-05-18 15:04:29 +02006020 if (netif_running(dev)) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00006021 /* Gross. */
Tobias Diedrich25d90812008-05-18 15:04:29 +02006022 nv_close(dev);
6023 }
Francois Romieua1893172006-10-10 14:33:27 -07006024 netif_device_detach(dev);
6025
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006026 /* save non-pci configuration space */
Szymon Janc78aea4f2010-11-27 08:39:43 +00006027 for (i = 0; i <= np->register_size/sizeof(u32); i++)
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006028 np->saved_config_space[i] = readl(base + i*sizeof(u32));
6029
Francois Romieua1893172006-10-10 14:33:27 -07006030 return 0;
6031}
6032
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006033static int nv_resume(struct device *device)
Francois Romieua1893172006-10-10 14:33:27 -07006034{
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006035 struct pci_dev *pdev = to_pci_dev(device);
Francois Romieua1893172006-10-10 14:33:27 -07006036 struct net_device *dev = pci_get_drvdata(pdev);
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006037 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullaa376e792008-04-10 21:30:35 -07006038 u8 __iomem *base = get_hwbase(dev);
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006039 int i, rc = 0;
Francois Romieua1893172006-10-10 14:33:27 -07006040
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006041 /* restore non-pci configuration space */
Szymon Janc78aea4f2010-11-27 08:39:43 +00006042 for (i = 0; i <= np->register_size/sizeof(u32); i++)
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006043 writel(np->saved_config_space[i], base+i*sizeof(u32));
Ayaz Abdullaa376e792008-04-10 21:30:35 -07006044
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006045 if (np->driver_data & DEV_NEED_MSI_FIX)
6046 pci_write_config_dword(pdev, NV_MSI_PRIV_OFFSET, NV_MSI_PRIV_VALUE);
Ayaz Abdullab6e44052009-02-07 00:24:15 -08006047
Ed Swierk35a74332009-04-06 17:49:12 -07006048 /* restore phy state, including autoneg */
6049 phy_init(dev);
6050
Tobias Diedrich25d90812008-05-18 15:04:29 +02006051 netif_device_attach(dev);
6052 if (netif_running(dev)) {
6053 rc = nv_open(dev);
6054 nv_set_multicast(dev);
6055 }
Francois Romieua1893172006-10-10 14:33:27 -07006056 return rc;
6057}
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006058
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006059static SIMPLE_DEV_PM_OPS(nv_pm_ops, nv_suspend, nv_resume);
6060#define NV_PM_OPS (&nv_pm_ops)
6061
Michel Lespinasse94252762011-03-06 16:14:50 +00006062#else
6063#define NV_PM_OPS NULL
6064#endif /* CONFIG_PM_SLEEP */
6065
6066#ifdef CONFIG_PM
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006067static void nv_shutdown(struct pci_dev *pdev)
6068{
6069 struct net_device *dev = pci_get_drvdata(pdev);
6070 struct fe_priv *np = netdev_priv(dev);
6071
6072 if (netif_running(dev))
6073 nv_close(dev);
6074
Tobias Diedrich34edaa82009-02-16 00:13:20 -08006075 /*
6076 * Restore the MAC so a kernel started by kexec won't get confused.
6077 * If we really go for poweroff, we must not restore the MAC,
6078 * otherwise the MAC for WOL will be reversed at least on some boards.
6079 */
Szymon Janc78aea4f2010-11-27 08:39:43 +00006080 if (system_state != SYSTEM_POWER_OFF)
Tobias Diedrich34edaa82009-02-16 00:13:20 -08006081 nv_restore_mac_addr(pdev);
Yinghai Luf55c21f2008-09-13 13:10:31 -07006082
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006083 pci_disable_device(pdev);
Tobias Diedrich34edaa82009-02-16 00:13:20 -08006084 /*
6085 * Apparently it is not possible to reinitialise from D3 hot,
6086 * only put the device into D3 if we really go for poweroff.
6087 */
Rafael J. Wysocki3cb55992008-09-05 14:00:19 -07006088 if (system_state == SYSTEM_POWER_OFF) {
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006089 pci_wake_from_d3(pdev, np->wolenabled);
Rafael J. Wysocki3cb55992008-09-05 14:00:19 -07006090 pci_set_power_state(pdev, PCI_D3hot);
6091 }
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006092}
Francois Romieua1893172006-10-10 14:33:27 -07006093#else
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006094#define nv_shutdown NULL
Francois Romieua1893172006-10-10 14:33:27 -07006095#endif /* CONFIG_PM */
6096
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006097static DEFINE_PCI_DEVICE_TABLE(pci_tbl) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006098 { /* nForce Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006099 PCI_DEVICE(0x10DE, 0x01C3),
Manfred Spraulc2dba062005-07-31 18:29:47 +02006100 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006101 },
6102 { /* nForce2 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006103 PCI_DEVICE(0x10DE, 0x0066),
Manfred Spraulc2dba062005-07-31 18:29:47 +02006104 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006105 },
6106 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006107 PCI_DEVICE(0x10DE, 0x00D6),
Manfred Spraulc2dba062005-07-31 18:29:47 +02006108 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006109 },
6110 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006111 PCI_DEVICE(0x10DE, 0x0086),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04006112 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006113 },
6114 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006115 PCI_DEVICE(0x10DE, 0x008C),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04006116 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006117 },
6118 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006119 PCI_DEVICE(0x10DE, 0x00E6),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04006120 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006121 },
6122 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006123 PCI_DEVICE(0x10DE, 0x00DF),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04006124 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006125 },
6126 { /* CK804 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006127 PCI_DEVICE(0x10DE, 0x0056),
Yinghai Lu033e97b2009-02-06 01:30:56 -08006128 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006129 },
6130 { /* CK804 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006131 PCI_DEVICE(0x10DE, 0x0057),
Yinghai Lu033e97b2009-02-06 01:30:56 -08006132 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006133 },
6134 { /* MCP04 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006135 PCI_DEVICE(0x10DE, 0x0037),
Ayaz Abdulla9e184762009-03-05 08:02:18 +00006136 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006137 },
6138 { /* MCP04 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006139 PCI_DEVICE(0x10DE, 0x0038),
Ayaz Abdulla9e184762009-03-05 08:02:18 +00006140 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT,
Manfred Sprauldc8216c2005-07-31 18:26:05 +02006141 },
6142 { /* MCP51 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006143 PCI_DEVICE(0x10DE, 0x0268),
6144 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS_V1|DEV_NEED_LOW_POWER_FIX,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006145 },
Manfred Spraul9992d4a2005-06-05 17:36:11 +02006146 { /* MCP51 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006147 PCI_DEVICE(0x10DE, 0x0269),
6148 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS_V1|DEV_NEED_LOW_POWER_FIX,
Manfred Spraul9992d4a2005-06-05 17:36:11 +02006149 },
Manfred Spraulf49d16e2005-06-26 11:36:52 +02006150 { /* MCP55 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006151 PCI_DEVICE(0x10DE, 0x0372),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006152 .driver_data = 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_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_NEED_TX_LIMIT|DEV_NEED_MSI_FIX,
Manfred Spraulf49d16e2005-06-26 11:36:52 +02006153 },
6154 { /* MCP55 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006155 PCI_DEVICE(0x10DE, 0x0373),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006156 .driver_data = 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_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_NEED_TX_LIMIT|DEV_NEED_MSI_FIX,
Manfred Spraulf49d16e2005-06-26 11:36:52 +02006157 },
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04006158 { /* MCP61 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006159 PCI_DEVICE(0x10DE, 0x03E5),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006160 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_MSI_FIX,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04006161 },
6162 { /* MCP61 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006163 PCI_DEVICE(0x10DE, 0x03E6),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006164 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_MSI_FIX,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04006165 },
6166 { /* MCP61 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006167 PCI_DEVICE(0x10DE, 0x03EE),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006168 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_MSI_FIX,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04006169 },
6170 { /* MCP61 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006171 PCI_DEVICE(0x10DE, 0x03EF),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006172 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_MSI_FIX,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04006173 },
6174 { /* MCP65 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006175 PCI_DEVICE(0x10DE, 0x0450),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006176 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04006177 },
6178 { /* MCP65 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006179 PCI_DEVICE(0x10DE, 0x0451),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006180 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04006181 },
6182 { /* MCP65 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006183 PCI_DEVICE(0x10DE, 0x0452),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006184 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04006185 },
6186 { /* MCP65 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006187 PCI_DEVICE(0x10DE, 0x0453),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006188 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04006189 },
Ayaz Abdullaf4344842006-11-06 00:43:40 -08006190 { /* MCP67 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006191 PCI_DEVICE(0x10DE, 0x054C),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006192 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdullaf4344842006-11-06 00:43:40 -08006193 },
6194 { /* MCP67 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006195 PCI_DEVICE(0x10DE, 0x054D),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006196 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdullaf4344842006-11-06 00:43:40 -08006197 },
6198 { /* MCP67 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006199 PCI_DEVICE(0x10DE, 0x054E),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006200 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdullaf4344842006-11-06 00:43:40 -08006201 },
6202 { /* MCP67 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006203 PCI_DEVICE(0x10DE, 0x054F),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006204 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdullaf4344842006-11-06 00:43:40 -08006205 },
Ayaz Abdulla13986612007-07-22 20:43:26 -04006206 { /* MCP73 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006207 PCI_DEVICE(0x10DE, 0x07DC),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006208 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdulla13986612007-07-22 20:43:26 -04006209 },
6210 { /* MCP73 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006211 PCI_DEVICE(0x10DE, 0x07DD),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006212 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdulla13986612007-07-22 20:43:26 -04006213 },
6214 { /* MCP73 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006215 PCI_DEVICE(0x10DE, 0x07DE),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006216 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdulla13986612007-07-22 20:43:26 -04006217 },
6218 { /* MCP73 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006219 PCI_DEVICE(0x10DE, 0x07DF),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006220 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdulla13986612007-07-22 20:43:26 -04006221 },
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04006222 { /* MCP77 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006223 PCI_DEVICE(0x10DE, 0x0760),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006224 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04006225 },
6226 { /* MCP77 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006227 PCI_DEVICE(0x10DE, 0x0761),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006228 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04006229 },
6230 { /* MCP77 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006231 PCI_DEVICE(0x10DE, 0x0762),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006232 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04006233 },
6234 { /* MCP77 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006235 PCI_DEVICE(0x10DE, 0x0763),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006236 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04006237 },
Ayaz Abdulla490dde82007-11-23 20:54:01 -05006238 { /* MCP79 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006239 PCI_DEVICE(0x10DE, 0x0AB0),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006240 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
Ayaz Abdulla490dde82007-11-23 20:54:01 -05006241 },
6242 { /* MCP79 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006243 PCI_DEVICE(0x10DE, 0x0AB1),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006244 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
Ayaz Abdulla490dde82007-11-23 20:54:01 -05006245 },
6246 { /* MCP79 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006247 PCI_DEVICE(0x10DE, 0x0AB2),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006248 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
Ayaz Abdulla490dde82007-11-23 20:54:01 -05006249 },
6250 { /* MCP79 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006251 PCI_DEVICE(0x10DE, 0x0AB3),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006252 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
Ayaz Abdulla490dde82007-11-23 20:54:01 -05006253 },
Ayaz Abdulla3df81c42009-06-03 15:05:35 +00006254 { /* MCP89 Ethernet Controller */
6255 PCI_DEVICE(0x10DE, 0x0D7D),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006256 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX,
Ayaz Abdulla3df81c42009-06-03 15:05:35 +00006257 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006258 {0,},
6259};
6260
6261static struct pci_driver driver = {
Jeff Garzik3f88ce42007-10-16 04:09:09 -04006262 .name = DRV_NAME,
6263 .id_table = pci_tbl,
6264 .probe = nv_probe,
6265 .remove = __devexit_p(nv_remove),
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006266 .shutdown = nv_shutdown,
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006267 .driver.pm = NV_PM_OPS,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006268};
6269
Linus Torvalds1da177e2005-04-16 15:20:36 -07006270static int __init init_nic(void)
6271{
Jeff Garzik29917622006-08-19 17:48:59 -04006272 return pci_register_driver(&driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006273}
6274
6275static void __exit exit_nic(void)
6276{
6277 pci_unregister_driver(&driver);
6278}
6279
6280module_param(max_interrupt_work, int, 0);
6281MODULE_PARM_DESC(max_interrupt_work, "forcedeth maximum events handled per interrupt");
Ayaz Abdullaa971c322005-11-11 08:30:38 -05006282module_param(optimization_mode, int, 0);
Ayaz Abdulla9e184762009-03-05 08:02:18 +00006283MODULE_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. In dynamic mode (2), the mode toggles between throughput and CPU mode based on network load.");
Ayaz Abdullaa971c322005-11-11 08:30:38 -05006284module_param(poll_interval, int, 0);
6285MODULE_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 -04006286module_param(msi, int, 0);
6287MODULE_PARM_DESC(msi, "MSI interrupts are enabled by setting to 1 and disabled by setting to 0.");
6288module_param(msix, int, 0);
6289MODULE_PARM_DESC(msix, "MSIX interrupts are enabled by setting to 1 and disabled by setting to 0.");
6290module_param(dma_64bit, int, 0);
6291MODULE_PARM_DESC(dma_64bit, "High DMA is enabled by setting to 1 and disabled by setting to 0.");
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04006292module_param(phy_cross, int, 0);
6293MODULE_PARM_DESC(phy_cross, "Phy crossover detection for Realtek 8201 phy is enabled by setting to 1 and disabled by setting to 0.");
Ed Swierk5a9a8e32009-06-02 00:19:52 -07006294module_param(phy_power_down, int, 0);
6295MODULE_PARM_DESC(phy_power_down, "Power down phy and disable link when interface is down (1), or leave phy powered up (0).");
Sameer Nanda1ec4f2d2011-11-16 12:15:12 +00006296module_param(debug_tx_timeout, bool, 0);
6297MODULE_PARM_DESC(debug_tx_timeout,
6298 "Dump tx related registers and ring when tx_timeout happens");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006299
6300MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>");
6301MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver");
6302MODULE_LICENSE("GPL");
6303
6304MODULE_DEVICE_TABLE(pci, pci_tbl);
6305
6306module_init(init_nic);
6307module_exit(exit_nic);