blob: 5d94c337dea23d684481289b615f43a0029b615c [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#include <asm/system.h>
73
Stephen Hemmingerbea33482007-10-03 16:41:36 -070074#define TX_WORK_PER_LOOP 64
75#define RX_WORK_PER_LOOP 64
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77/*
78 * Hardware access:
79 */
80
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +000081#define DEV_NEED_TIMERIRQ 0x0000001 /* set the timer irq flag in the irq mask */
82#define DEV_NEED_LINKTIMER 0x0000002 /* poll link settings. Relies on the timer irq */
83#define DEV_HAS_LARGEDESC 0x0000004 /* device supports jumbo frames and needs packet format 2 */
84#define DEV_HAS_HIGH_DMA 0x0000008 /* device supports 64bit dma */
85#define DEV_HAS_CHECKSUM 0x0000010 /* device supports tx and rx checksum offloads */
86#define DEV_HAS_VLAN 0x0000020 /* device supports vlan tagging and striping */
87#define DEV_HAS_MSI 0x0000040 /* device supports MSI */
88#define DEV_HAS_MSI_X 0x0000080 /* device supports MSI-X */
89#define DEV_HAS_POWER_CNTRL 0x0000100 /* device supports power savings */
90#define DEV_HAS_STATISTICS_V1 0x0000200 /* device supports hw statistics version 1 */
Mike Ditto7b5e0782010-07-25 21:54:28 -070091#define DEV_HAS_STATISTICS_V2 0x0000400 /* device supports hw statistics version 2 */
92#define DEV_HAS_STATISTICS_V3 0x0000800 /* device supports hw statistics version 3 */
93#define DEV_HAS_STATISTICS_V12 0x0000600 /* device supports hw statistics version 1 and 2 */
94#define DEV_HAS_STATISTICS_V123 0x0000e00 /* device supports hw statistics version 1, 2, and 3 */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +000095#define DEV_HAS_TEST_EXTENDED 0x0001000 /* device supports extended diagnostic test */
96#define DEV_HAS_MGMT_UNIT 0x0002000 /* device supports management unit */
97#define DEV_HAS_CORRECT_MACADDR 0x0004000 /* device supports correct mac address order */
98#define DEV_HAS_COLLISION_FIX 0x0008000 /* device supports tx collision fix */
99#define DEV_HAS_PAUSEFRAME_TX_V1 0x0010000 /* device supports tx pause frames version 1 */
100#define DEV_HAS_PAUSEFRAME_TX_V2 0x0020000 /* device supports tx pause frames version 2 */
101#define DEV_HAS_PAUSEFRAME_TX_V3 0x0040000 /* device supports tx pause frames version 3 */
102#define DEV_NEED_TX_LIMIT 0x0080000 /* device needs to limit tx */
103#define DEV_NEED_TX_LIMIT2 0x0180000 /* device needs to limit tx, expect for some revs */
104#define DEV_HAS_GEAR_MODE 0x0200000 /* device supports gear mode */
105#define DEV_NEED_PHY_INIT_FIX 0x0400000 /* device needs specific phy workaround */
106#define DEV_NEED_LOW_POWER_FIX 0x0800000 /* device needs special power up workaround */
107#define DEV_NEED_MSI_FIX 0x1000000 /* device needs msi workaround */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108
109enum {
110 NvRegIrqStatus = 0x000,
111#define NVREG_IRQSTAT_MIIEVENT 0x040
Ayaz Abdulladaa91a92009-02-07 00:25:00 -0800112#define NVREG_IRQSTAT_MASK 0x83ff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 NvRegIrqMask = 0x004,
114#define NVREG_IRQ_RX_ERROR 0x0001
115#define NVREG_IRQ_RX 0x0002
116#define NVREG_IRQ_RX_NOBUF 0x0004
117#define NVREG_IRQ_TX_ERR 0x0008
Manfred Spraulc2dba062005-07-31 18:29:47 +0200118#define NVREG_IRQ_TX_OK 0x0010
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119#define NVREG_IRQ_TIMER 0x0020
120#define NVREG_IRQ_LINK 0x0040
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500121#define NVREG_IRQ_RX_FORCED 0x0080
122#define NVREG_IRQ_TX_FORCED 0x0100
Ayaz Abdulladaa91a92009-02-07 00:25:00 -0800123#define NVREG_IRQ_RECOVER_ERROR 0x8200
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500124#define NVREG_IRQMASK_THROUGHPUT 0x00df
Ayaz Abdulla096a4582007-05-21 20:23:11 -0400125#define NVREG_IRQMASK_CPU 0x0060
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500126#define NVREG_IRQ_TX_ALL (NVREG_IRQ_TX_ERR|NVREG_IRQ_TX_OK|NVREG_IRQ_TX_FORCED)
127#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 -0500128#define NVREG_IRQ_OTHER (NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_RECOVER_ERROR)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200129
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 NvRegUnknownSetupReg6 = 0x008,
131#define NVREG_UNKSETUP6_VAL 3
132
133/*
134 * NVREG_POLL_DEFAULT is the interval length of the timer source on the nic
135 * NVREG_POLL_DEFAULT=97 would result in an interval length of 1 ms
136 */
137 NvRegPollingInterval = 0x00c,
Ayaz Abdulla6cef67a2009-03-05 08:02:30 +0000138#define NVREG_POLL_DEFAULT_THROUGHPUT 65535 /* backup tx cleanup if loop max reached */
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500139#define NVREG_POLL_DEFAULT_CPU 13
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500140 NvRegMSIMap0 = 0x020,
141 NvRegMSIMap1 = 0x024,
142 NvRegMSIIrqMask = 0x030,
143#define NVREG_MSI_VECTOR_0_ENABLED 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 NvRegMisc1 = 0x080,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400145#define NVREG_MISC1_PAUSE_TX 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146#define NVREG_MISC1_HD 0x02
147#define NVREG_MISC1_FORCE 0x3b0f3c
148
Ayaz Abdulla0a626772008-01-13 16:02:42 -0500149 NvRegMacReset = 0x34,
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400150#define NVREG_MAC_RESET_ASSERT 0x0F3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 NvRegTransmitterControl = 0x084,
152#define NVREG_XMITCTL_START 0x01
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500153#define NVREG_XMITCTL_MGMT_ST 0x40000000
154#define NVREG_XMITCTL_SYNC_MASK 0x000f0000
155#define NVREG_XMITCTL_SYNC_NOT_READY 0x0
156#define NVREG_XMITCTL_SYNC_PHY_INIT 0x00040000
157#define NVREG_XMITCTL_MGMT_SEMA_MASK 0x00000f00
158#define NVREG_XMITCTL_MGMT_SEMA_FREE 0x0
159#define NVREG_XMITCTL_HOST_SEMA_MASK 0x0000f000
160#define NVREG_XMITCTL_HOST_SEMA_ACQ 0x0000f000
161#define NVREG_XMITCTL_HOST_LOADED 0x00004000
Ayaz Abdullaf35723e2003-02-20 03:03:54 -0500162#define NVREG_XMITCTL_TX_PATH_EN 0x01000000
Ayaz Abdullacac1c522009-02-07 00:23:57 -0800163#define NVREG_XMITCTL_DATA_START 0x00100000
164#define NVREG_XMITCTL_DATA_READY 0x00010000
165#define NVREG_XMITCTL_DATA_ERROR 0x00020000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 NvRegTransmitterStatus = 0x088,
167#define NVREG_XMITSTAT_BUSY 0x01
168
169 NvRegPacketFilterFlags = 0x8c,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400170#define NVREG_PFF_PAUSE_RX 0x08
171#define NVREG_PFF_ALWAYS 0x7F0000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172#define NVREG_PFF_PROMISC 0x80
173#define NVREG_PFF_MYADDR 0x20
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400174#define NVREG_PFF_LOOPBACK 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
176 NvRegOffloadConfig = 0x90,
177#define NVREG_OFFLOAD_HOMEPHY 0x601
178#define NVREG_OFFLOAD_NORMAL RX_NIC_BUFSIZE
179 NvRegReceiverControl = 0x094,
180#define NVREG_RCVCTL_START 0x01
Ayaz Abdullaf35723e2003-02-20 03:03:54 -0500181#define NVREG_RCVCTL_RX_PATH_EN 0x01000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 NvRegReceiverStatus = 0x98,
183#define NVREG_RCVSTAT_BUSY 0x01
184
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700185 NvRegSlotTime = 0x9c,
186#define NVREG_SLOTTIME_LEGBF_ENABLED 0x80000000
187#define NVREG_SLOTTIME_10_100_FULL 0x00007f00
Szymon Janc78aea4f2010-11-27 08:39:43 +0000188#define NVREG_SLOTTIME_1000_FULL 0x0003ff00
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700189#define NVREG_SLOTTIME_HALF 0x0000ff00
Szymon Janc78aea4f2010-11-27 08:39:43 +0000190#define NVREG_SLOTTIME_DEFAULT 0x00007f00
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700191#define NVREG_SLOTTIME_MASK 0x000000ff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192
Ayaz Abdulla9744e212006-07-06 16:45:58 -0400193 NvRegTxDeferral = 0xA0,
Ayaz Abdullafd9b5582008-02-05 12:29:49 -0500194#define NVREG_TX_DEFERRAL_DEFAULT 0x15050f
195#define NVREG_TX_DEFERRAL_RGMII_10_100 0x16070f
196#define NVREG_TX_DEFERRAL_RGMII_1000 0x14050f
197#define NVREG_TX_DEFERRAL_RGMII_STRETCH_10 0x16190f
198#define NVREG_TX_DEFERRAL_RGMII_STRETCH_100 0x16300f
199#define NVREG_TX_DEFERRAL_MII_STRETCH 0x152000
Ayaz Abdulla9744e212006-07-06 16:45:58 -0400200 NvRegRxDeferral = 0xA4,
201#define NVREG_RX_DEFERRAL_DEFAULT 0x16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 NvRegMacAddrA = 0xA8,
203 NvRegMacAddrB = 0xAC,
204 NvRegMulticastAddrA = 0xB0,
205#define NVREG_MCASTADDRA_FORCE 0x01
206 NvRegMulticastAddrB = 0xB4,
207 NvRegMulticastMaskA = 0xB8,
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -0500208#define NVREG_MCASTMASKA_NONE 0xffffffff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 NvRegMulticastMaskB = 0xBC,
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -0500210#define NVREG_MCASTMASKB_NONE 0xffff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
212 NvRegPhyInterface = 0xC0,
213#define PHY_RGMII 0x10000000
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700214 NvRegBackOffControl = 0xC4,
215#define NVREG_BKOFFCTRL_DEFAULT 0x70000000
216#define NVREG_BKOFFCTRL_SEED_MASK 0x000003ff
217#define NVREG_BKOFFCTRL_SELECT 24
218#define NVREG_BKOFFCTRL_GEAR 12
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220 NvRegTxRingPhysAddr = 0x100,
221 NvRegRxRingPhysAddr = 0x104,
222 NvRegRingSizes = 0x108,
223#define NVREG_RINGSZ_TXSHIFT 0
224#define NVREG_RINGSZ_RXSHIFT 16
Ayaz Abdulla5070d342006-07-31 12:05:01 -0400225 NvRegTransmitPoll = 0x10c,
226#define NVREG_TRANSMITPOLL_MAC_ADDR_REV 0x00008000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 NvRegLinkSpeed = 0x110,
228#define NVREG_LINKSPEED_FORCE 0x10000
229#define NVREG_LINKSPEED_10 1000
230#define NVREG_LINKSPEED_100 100
231#define NVREG_LINKSPEED_1000 50
232#define NVREG_LINKSPEED_MASK (0xFFF)
233 NvRegUnknownSetupReg5 = 0x130,
234#define NVREG_UNKSETUP5_BIT31 (1<<31)
Ayaz Abdulla95d161c2006-07-06 16:46:25 -0400235 NvRegTxWatermark = 0x13c,
236#define NVREG_TX_WM_DESC1_DEFAULT 0x0200010
237#define NVREG_TX_WM_DESC2_3_DEFAULT 0x1e08000
238#define NVREG_TX_WM_DESC2_3_1000 0xfe08000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 NvRegTxRxControl = 0x144,
240#define NVREG_TXRXCTL_KICK 0x0001
241#define NVREG_TXRXCTL_BIT1 0x0002
242#define NVREG_TXRXCTL_BIT2 0x0004
243#define NVREG_TXRXCTL_IDLE 0x0008
244#define NVREG_TXRXCTL_RESET 0x0010
245#define NVREG_TXRXCTL_RXCHECK 0x0400
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400246#define NVREG_TXRXCTL_DESC_1 0
Ayaz Abdullad2f78412007-01-09 13:30:02 -0500247#define NVREG_TXRXCTL_DESC_2 0x002100
248#define NVREG_TXRXCTL_DESC_3 0xc02200
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500249#define NVREG_TXRXCTL_VLANSTRIP 0x00040
250#define NVREG_TXRXCTL_VLANINS 0x00080
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500251 NvRegTxRingPhysAddrHigh = 0x148,
252 NvRegRxRingPhysAddrHigh = 0x14C,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400253 NvRegTxPauseFrame = 0x170,
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -0500254#define NVREG_TX_PAUSEFRAME_DISABLE 0x0fff0080
255#define NVREG_TX_PAUSEFRAME_ENABLE_V1 0x01800010
256#define NVREG_TX_PAUSEFRAME_ENABLE_V2 0x056003f0
257#define NVREG_TX_PAUSEFRAME_ENABLE_V3 0x09f00880
Ayaz Abdulla9a33e882008-08-06 12:12:34 -0400258 NvRegTxPauseFrameLimit = 0x174,
259#define NVREG_TX_PAUSEFRAMELIMIT_ENABLE 0x00010000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 NvRegMIIStatus = 0x180,
261#define NVREG_MIISTAT_ERROR 0x0001
262#define NVREG_MIISTAT_LINKCHANGE 0x0008
Ayaz Abdullaeb798422008-02-04 15:14:04 -0500263#define NVREG_MIISTAT_MASK_RW 0x0007
264#define NVREG_MIISTAT_MASK_ALL 0x000f
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500265 NvRegMIIMask = 0x184,
266#define NVREG_MII_LINKCHANGE 0x0008
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
268 NvRegAdapterControl = 0x188,
269#define NVREG_ADAPTCTL_START 0x02
270#define NVREG_ADAPTCTL_LINKUP 0x04
271#define NVREG_ADAPTCTL_PHYVALID 0x40000
272#define NVREG_ADAPTCTL_RUNNING 0x100000
273#define NVREG_ADAPTCTL_PHYSHIFT 24
274 NvRegMIISpeed = 0x18c,
275#define NVREG_MIISPEED_BIT8 (1<<8)
276#define NVREG_MIIDELAY 5
277 NvRegMIIControl = 0x190,
278#define NVREG_MIICTL_INUSE 0x08000
279#define NVREG_MIICTL_WRITE 0x00400
280#define NVREG_MIICTL_ADDRSHIFT 5
281 NvRegMIIData = 0x194,
Ayaz Abdulla9c662432008-08-06 12:11:42 -0400282 NvRegTxUnicast = 0x1a0,
283 NvRegTxMulticast = 0x1a4,
284 NvRegTxBroadcast = 0x1a8,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 NvRegWakeUpFlags = 0x200,
286#define NVREG_WAKEUPFLAGS_VAL 0x7770
287#define NVREG_WAKEUPFLAGS_BUSYSHIFT 24
288#define NVREG_WAKEUPFLAGS_ENABLESHIFT 16
289#define NVREG_WAKEUPFLAGS_D3SHIFT 12
290#define NVREG_WAKEUPFLAGS_D2SHIFT 8
291#define NVREG_WAKEUPFLAGS_D1SHIFT 4
292#define NVREG_WAKEUPFLAGS_D0SHIFT 0
293#define NVREG_WAKEUPFLAGS_ACCEPT_MAGPAT 0x01
294#define NVREG_WAKEUPFLAGS_ACCEPT_WAKEUPPAT 0x02
295#define NVREG_WAKEUPFLAGS_ACCEPT_LINKCHANGE 0x04
296#define NVREG_WAKEUPFLAGS_ENABLE 0x1111
297
Ayaz Abdullacac1c522009-02-07 00:23:57 -0800298 NvRegMgmtUnitGetVersion = 0x204,
Szymon Janc78aea4f2010-11-27 08:39:43 +0000299#define NVREG_MGMTUNITGETVERSION 0x01
Ayaz Abdullacac1c522009-02-07 00:23:57 -0800300 NvRegMgmtUnitVersion = 0x208,
301#define NVREG_MGMTUNITVERSION 0x08
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 NvRegPowerCap = 0x268,
303#define NVREG_POWERCAP_D3SUPP (1<<30)
304#define NVREG_POWERCAP_D2SUPP (1<<26)
305#define NVREG_POWERCAP_D1SUPP (1<<25)
306 NvRegPowerState = 0x26c,
307#define NVREG_POWERSTATE_POWEREDUP 0x8000
308#define NVREG_POWERSTATE_VALID 0x0100
309#define NVREG_POWERSTATE_MASK 0x0003
310#define NVREG_POWERSTATE_D0 0x0000
311#define NVREG_POWERSTATE_D1 0x0001
312#define NVREG_POWERSTATE_D2 0x0002
313#define NVREG_POWERSTATE_D3 0x0003
Ayaz Abdullacac1c522009-02-07 00:23:57 -0800314 NvRegMgmtUnitControl = 0x278,
315#define NVREG_MGMTUNITCONTROL_INUSE 0x20000
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400316 NvRegTxCnt = 0x280,
317 NvRegTxZeroReXmt = 0x284,
318 NvRegTxOneReXmt = 0x288,
319 NvRegTxManyReXmt = 0x28c,
320 NvRegTxLateCol = 0x290,
321 NvRegTxUnderflow = 0x294,
322 NvRegTxLossCarrier = 0x298,
323 NvRegTxExcessDef = 0x29c,
324 NvRegTxRetryErr = 0x2a0,
325 NvRegRxFrameErr = 0x2a4,
326 NvRegRxExtraByte = 0x2a8,
327 NvRegRxLateCol = 0x2ac,
328 NvRegRxRunt = 0x2b0,
329 NvRegRxFrameTooLong = 0x2b4,
330 NvRegRxOverflow = 0x2b8,
331 NvRegRxFCSErr = 0x2bc,
332 NvRegRxFrameAlignErr = 0x2c0,
333 NvRegRxLenErr = 0x2c4,
334 NvRegRxUnicast = 0x2c8,
335 NvRegRxMulticast = 0x2cc,
336 NvRegRxBroadcast = 0x2d0,
337 NvRegTxDef = 0x2d4,
338 NvRegTxFrame = 0x2d8,
339 NvRegRxCnt = 0x2dc,
340 NvRegTxPause = 0x2e0,
341 NvRegRxPause = 0x2e4,
342 NvRegRxDropFrame = 0x2e8,
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500343 NvRegVlanControl = 0x300,
344#define NVREG_VLANCONTROL_ENABLE 0x2000
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500345 NvRegMSIXMap0 = 0x3e0,
346 NvRegMSIXMap1 = 0x3e4,
347 NvRegMSIXIrqStatus = 0x3f0,
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400348
349 NvRegPowerState2 = 0x600,
Ayaz Abdulla1545e202008-09-22 09:55:35 -0400350#define NVREG_POWERSTATE2_POWERUP_MASK 0x0F15
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400351#define NVREG_POWERSTATE2_POWERUP_REV_A3 0x0001
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -0400352#define NVREG_POWERSTATE2_PHY_RESET 0x0004
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +0000353#define NVREG_POWERSTATE2_GATE_CLOCKS 0x0F00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354};
355
356/* Big endian: should work, but is untested */
357struct ring_desc {
Stephen Hemmingera8bed492006-07-27 18:50:09 -0700358 __le32 buf;
359 __le32 flaglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360};
361
Manfred Spraulee733622005-07-31 18:32:26 +0200362struct ring_desc_ex {
Stephen Hemmingera8bed492006-07-27 18:50:09 -0700363 __le32 bufhigh;
364 __le32 buflow;
365 __le32 txvlan;
366 __le32 flaglen;
Manfred Spraulee733622005-07-31 18:32:26 +0200367};
368
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700369union ring_type {
Szymon Janc78aea4f2010-11-27 08:39:43 +0000370 struct ring_desc *orig;
371 struct ring_desc_ex *ex;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700372};
Manfred Spraulee733622005-07-31 18:32:26 +0200373
Linus Torvalds1da177e2005-04-16 15:20:36 -0700374#define FLAG_MASK_V1 0xffff0000
375#define FLAG_MASK_V2 0xffffc000
376#define LEN_MASK_V1 (0xffffffff ^ FLAG_MASK_V1)
377#define LEN_MASK_V2 (0xffffffff ^ FLAG_MASK_V2)
378
379#define NV_TX_LASTPACKET (1<<16)
380#define NV_TX_RETRYERROR (1<<19)
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700381#define NV_TX_RETRYCOUNT_MASK (0xF<<20)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200382#define NV_TX_FORCED_INTERRUPT (1<<24)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383#define NV_TX_DEFERRED (1<<26)
384#define NV_TX_CARRIERLOST (1<<27)
385#define NV_TX_LATECOLLISION (1<<28)
386#define NV_TX_UNDERFLOW (1<<29)
387#define NV_TX_ERROR (1<<30)
388#define NV_TX_VALID (1<<31)
389
390#define NV_TX2_LASTPACKET (1<<29)
391#define NV_TX2_RETRYERROR (1<<18)
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700392#define NV_TX2_RETRYCOUNT_MASK (0xF<<19)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200393#define NV_TX2_FORCED_INTERRUPT (1<<30)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394#define NV_TX2_DEFERRED (1<<25)
395#define NV_TX2_CARRIERLOST (1<<26)
396#define NV_TX2_LATECOLLISION (1<<27)
397#define NV_TX2_UNDERFLOW (1<<28)
398/* error and valid are the same for both */
399#define NV_TX2_ERROR (1<<30)
400#define NV_TX2_VALID (1<<31)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400401#define NV_TX2_TSO (1<<28)
402#define NV_TX2_TSO_SHIFT 14
Ayaz Abdullafa454592006-01-05 22:45:45 -0800403#define NV_TX2_TSO_MAX_SHIFT 14
404#define NV_TX2_TSO_MAX_SIZE (1<<NV_TX2_TSO_MAX_SHIFT)
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400405#define NV_TX2_CHECKSUM_L3 (1<<27)
406#define NV_TX2_CHECKSUM_L4 (1<<26)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500408#define NV_TX3_VLAN_TAG_PRESENT (1<<18)
409
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410#define NV_RX_DESCRIPTORVALID (1<<16)
411#define NV_RX_MISSEDFRAME (1<<17)
412#define NV_RX_SUBSTRACT1 (1<<18)
413#define NV_RX_ERROR1 (1<<23)
414#define NV_RX_ERROR2 (1<<24)
415#define NV_RX_ERROR3 (1<<25)
416#define NV_RX_ERROR4 (1<<26)
417#define NV_RX_CRCERR (1<<27)
418#define NV_RX_OVERFLOW (1<<28)
419#define NV_RX_FRAMINGERR (1<<29)
420#define NV_RX_ERROR (1<<30)
421#define NV_RX_AVAIL (1<<31)
Ayaz Abdulla1ef68412008-08-06 12:11:03 -0400422#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 -0700423
424#define NV_RX2_CHECKSUMMASK (0x1C000000)
Ayaz Abdullabfaffe82008-01-13 16:02:55 -0500425#define NV_RX2_CHECKSUM_IP (0x10000000)
426#define NV_RX2_CHECKSUM_IP_TCP (0x14000000)
427#define NV_RX2_CHECKSUM_IP_UDP (0x18000000)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700428#define NV_RX2_DESCRIPTORVALID (1<<29)
429#define NV_RX2_SUBSTRACT1 (1<<25)
430#define NV_RX2_ERROR1 (1<<18)
431#define NV_RX2_ERROR2 (1<<19)
432#define NV_RX2_ERROR3 (1<<20)
433#define NV_RX2_ERROR4 (1<<21)
434#define NV_RX2_CRCERR (1<<22)
435#define NV_RX2_OVERFLOW (1<<23)
436#define NV_RX2_FRAMINGERR (1<<24)
437/* error and avail are the same for both */
438#define NV_RX2_ERROR (1<<30)
439#define NV_RX2_AVAIL (1<<31)
Ayaz Abdulla1ef68412008-08-06 12:11:03 -0400440#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 -0700441
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500442#define NV_RX3_VLAN_TAG_PRESENT (1<<16)
443#define NV_RX3_VLAN_TAG_MASK (0x0000FFFF)
444
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300445/* Miscellaneous hardware related defines: */
Szymon Janc78aea4f2010-11-27 08:39:43 +0000446#define NV_PCI_REGSZ_VER1 0x270
447#define NV_PCI_REGSZ_VER2 0x2d4
448#define NV_PCI_REGSZ_VER3 0x604
449#define NV_PCI_REGSZ_MAX 0x604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450
451/* various timeout delays: all in usec */
452#define NV_TXRX_RESET_DELAY 4
453#define NV_TXSTOP_DELAY1 10
454#define NV_TXSTOP_DELAY1MAX 500000
455#define NV_TXSTOP_DELAY2 100
456#define NV_RXSTOP_DELAY1 10
457#define NV_RXSTOP_DELAY1MAX 500000
458#define NV_RXSTOP_DELAY2 100
459#define NV_SETUP5_DELAY 5
460#define NV_SETUP5_DELAYMAX 50000
461#define NV_POWERUP_DELAY 5
462#define NV_POWERUP_DELAYMAX 5000
463#define NV_MIIBUSY_DELAY 50
464#define NV_MIIPHY_DELAY 10
465#define NV_MIIPHY_DELAYMAX 10000
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400466#define NV_MAC_RESET_DELAY 64
Linus Torvalds1da177e2005-04-16 15:20:36 -0700467
468#define NV_WAKEUPPATTERNS 5
469#define NV_WAKEUPMASKENTRIES 4
470
471/* General driver defaults */
472#define NV_WATCHDOG_TIMEO (5*HZ)
473
Ayaz Abdulla6cef67a2009-03-05 08:02:30 +0000474#define RX_RING_DEFAULT 512
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400475#define TX_RING_DEFAULT 256
476#define RX_RING_MIN 128
477#define TX_RING_MIN 64
478#define RING_MAX_DESC_VER_1 1024
479#define RING_MAX_DESC_VER_2_3 16384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
481/* rx/tx mac addr + type + vlan + align + slack*/
Manfred Sprauld81c0982005-07-31 18:20:30 +0200482#define NV_RX_HEADERS (64)
483/* even more slack. */
484#define NV_RX_ALLOC_PAD (64)
485
486/* maximum mtu size */
487#define NV_PKTLIMIT_1 ETH_DATA_LEN /* hard limit not known */
488#define NV_PKTLIMIT_2 9100 /* Actual limit according to NVidia: 9202 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
490#define OOM_REFILL (1+HZ/20)
491#define POLL_WAIT (1+HZ/100)
492#define LINK_TIMEOUT (3*HZ)
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400493#define STATS_INTERVAL (10*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400495/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 * desc_ver values:
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400497 * The nic supports three different descriptor types:
498 * - DESC_VER_1: Original
499 * - DESC_VER_2: support for jumbo frames.
500 * - DESC_VER_3: 64-bit format.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 */
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400502#define DESC_VER_1 1
503#define DESC_VER_2 2
504#define DESC_VER_3 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505
506/* PHY defines */
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400507#define PHY_OUI_MARVELL 0x5043
508#define PHY_OUI_CICADA 0x03f1
509#define PHY_OUI_VITESSE 0x01c1
510#define PHY_OUI_REALTEK 0x0732
511#define PHY_OUI_REALTEK2 0x0020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700512#define PHYID1_OUI_MASK 0x03ff
513#define PHYID1_OUI_SHFT 6
514#define PHYID2_OUI_MASK 0xfc00
515#define PHYID2_OUI_SHFT 10
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -0400516#define PHYID2_MODEL_MASK 0x03f0
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400517#define PHY_MODEL_REALTEK_8211 0x0110
518#define PHY_REV_MASK 0x0001
519#define PHY_REV_REALTEK_8211B 0x0000
520#define PHY_REV_REALTEK_8211C 0x0001
521#define PHY_MODEL_REALTEK_8201 0x0200
522#define PHY_MODEL_MARVELL_E3016 0x0220
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -0400523#define PHY_MARVELL_E3016_INITMASK 0x0300
Ayaz Abdulla14a67f32007-07-15 06:50:28 -0400524#define PHY_CICADA_INIT1 0x0f000
525#define PHY_CICADA_INIT2 0x0e00
526#define PHY_CICADA_INIT3 0x01000
527#define PHY_CICADA_INIT4 0x0200
528#define PHY_CICADA_INIT5 0x0004
529#define PHY_CICADA_INIT6 0x02000
Ayaz Abdullad215d8a2007-07-15 06:50:53 -0400530#define PHY_VITESSE_INIT_REG1 0x1f
531#define PHY_VITESSE_INIT_REG2 0x10
532#define PHY_VITESSE_INIT_REG3 0x11
533#define PHY_VITESSE_INIT_REG4 0x12
534#define PHY_VITESSE_INIT_MSK1 0xc
535#define PHY_VITESSE_INIT_MSK2 0x0180
536#define PHY_VITESSE_INIT1 0x52b5
537#define PHY_VITESSE_INIT2 0xaf8a
538#define PHY_VITESSE_INIT3 0x8
539#define PHY_VITESSE_INIT4 0x8f8a
540#define PHY_VITESSE_INIT5 0xaf86
541#define PHY_VITESSE_INIT6 0x8f86
542#define PHY_VITESSE_INIT7 0xaf82
543#define PHY_VITESSE_INIT8 0x0100
544#define PHY_VITESSE_INIT9 0x8f82
545#define PHY_VITESSE_INIT10 0x0
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -0400546#define PHY_REALTEK_INIT_REG1 0x1f
547#define PHY_REALTEK_INIT_REG2 0x19
548#define PHY_REALTEK_INIT_REG3 0x13
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400549#define PHY_REALTEK_INIT_REG4 0x14
550#define PHY_REALTEK_INIT_REG5 0x18
551#define PHY_REALTEK_INIT_REG6 0x11
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -0400552#define PHY_REALTEK_INIT_REG7 0x01
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -0400553#define PHY_REALTEK_INIT1 0x0000
554#define PHY_REALTEK_INIT2 0x8e00
555#define PHY_REALTEK_INIT3 0x0001
556#define PHY_REALTEK_INIT4 0xad17
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400557#define PHY_REALTEK_INIT5 0xfb54
558#define PHY_REALTEK_INIT6 0xf5c7
559#define PHY_REALTEK_INIT7 0x1000
560#define PHY_REALTEK_INIT8 0x0003
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -0400561#define PHY_REALTEK_INIT9 0x0008
562#define PHY_REALTEK_INIT10 0x0005
563#define PHY_REALTEK_INIT11 0x0200
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400564#define PHY_REALTEK_INIT_MSK1 0x0003
Ayaz Abdullad215d8a2007-07-15 06:50:53 -0400565
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566#define PHY_GIGABIT 0x0100
567
568#define PHY_TIMEOUT 0x1
569#define PHY_ERROR 0x2
570
571#define PHY_100 0x1
572#define PHY_1000 0x2
573#define PHY_HALF 0x100
574
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400575#define NV_PAUSEFRAME_RX_CAPABLE 0x0001
576#define NV_PAUSEFRAME_TX_CAPABLE 0x0002
577#define NV_PAUSEFRAME_RX_ENABLE 0x0004
578#define NV_PAUSEFRAME_TX_ENABLE 0x0008
Ayaz Abdullab6d07732006-06-10 22:47:42 -0400579#define NV_PAUSEFRAME_RX_REQ 0x0010
580#define NV_PAUSEFRAME_TX_REQ 0x0020
581#define NV_PAUSEFRAME_AUTONEG 0x0040
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500583/* MSI/MSI-X defines */
584#define NV_MSI_X_MAX_VECTORS 8
585#define NV_MSI_X_VECTORS_MASK 0x000f
586#define NV_MSI_CAPABLE 0x0010
587#define NV_MSI_X_CAPABLE 0x0020
588#define NV_MSI_ENABLED 0x0040
589#define NV_MSI_X_ENABLED 0x0080
590
591#define NV_MSI_X_VECTOR_ALL 0x0
592#define NV_MSI_X_VECTOR_RX 0x0
593#define NV_MSI_X_VECTOR_TX 0x1
594#define NV_MSI_X_VECTOR_OTHER 0x2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
Ayaz Abdullab6e44052009-02-07 00:24:15 -0800596#define NV_MSI_PRIV_OFFSET 0x68
597#define NV_MSI_PRIV_VALUE 0xffffffff
598
Ayaz Abdullab2976d22008-02-04 15:13:59 -0500599#define NV_RESTART_TX 0x1
600#define NV_RESTART_RX 0x2
601
Ayaz Abdulla3b446c32008-03-10 14:58:21 -0500602#define NV_TX_LIMIT_COUNT 16
603
Ayaz Abdulla4145ade2009-03-05 08:02:26 +0000604#define NV_DYNAMIC_THRESHOLD 4
605#define NV_DYNAMIC_MAX_QUIET_COUNT 2048
606
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400607/* statistics */
608struct nv_ethtool_str {
609 char name[ETH_GSTRING_LEN];
610};
611
612static const struct nv_ethtool_str nv_estats_str[] = {
david decotigny674aee32011-11-16 12:15:07 +0000613 { "tx_bytes" }, /* includes Ethernet FCS CRC */
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400614 { "tx_zero_rexmt" },
615 { "tx_one_rexmt" },
616 { "tx_many_rexmt" },
617 { "tx_late_collision" },
618 { "tx_fifo_errors" },
619 { "tx_carrier_errors" },
620 { "tx_excess_deferral" },
621 { "tx_retry_error" },
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400622 { "rx_frame_error" },
623 { "rx_extra_byte" },
624 { "rx_late_collision" },
625 { "rx_runt" },
626 { "rx_frame_too_long" },
627 { "rx_over_errors" },
628 { "rx_crc_errors" },
629 { "rx_frame_align_error" },
630 { "rx_length_error" },
631 { "rx_unicast" },
632 { "rx_multicast" },
633 { "rx_broadcast" },
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400634 { "rx_packets" },
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500635 { "rx_errors_total" },
636 { "tx_errors_total" },
637
638 /* version 2 stats */
639 { "tx_deferral" },
640 { "tx_packets" },
david decotigny674aee32011-11-16 12:15:07 +0000641 { "rx_bytes" }, /* includes Ethernet FCS CRC */
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500642 { "tx_pause" },
643 { "rx_pause" },
Ayaz Abdulla9c662432008-08-06 12:11:42 -0400644 { "rx_drop_frame" },
645
646 /* version 3 stats */
647 { "tx_unicast" },
648 { "tx_multicast" },
649 { "tx_broadcast" }
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400650};
651
652struct nv_ethtool_stats {
david decotigny674aee32011-11-16 12:15:07 +0000653 u64 tx_bytes; /* should be ifconfig->tx_bytes + 4*tx_packets */
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400654 u64 tx_zero_rexmt;
655 u64 tx_one_rexmt;
656 u64 tx_many_rexmt;
657 u64 tx_late_collision;
658 u64 tx_fifo_errors;
659 u64 tx_carrier_errors;
660 u64 tx_excess_deferral;
661 u64 tx_retry_error;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400662 u64 rx_frame_error;
663 u64 rx_extra_byte;
664 u64 rx_late_collision;
665 u64 rx_runt;
666 u64 rx_frame_too_long;
667 u64 rx_over_errors;
668 u64 rx_crc_errors;
669 u64 rx_frame_align_error;
670 u64 rx_length_error;
671 u64 rx_unicast;
672 u64 rx_multicast;
673 u64 rx_broadcast;
david decotigny674aee32011-11-16 12:15:07 +0000674 u64 rx_packets; /* should be ifconfig->rx_packets */
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400675 u64 rx_errors_total;
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500676 u64 tx_errors_total;
677
678 /* version 2 stats */
679 u64 tx_deferral;
david decotigny674aee32011-11-16 12:15:07 +0000680 u64 tx_packets; /* should be ifconfig->tx_packets */
681 u64 rx_bytes; /* should be ifconfig->rx_bytes + 4*rx_packets */
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500682 u64 tx_pause;
683 u64 rx_pause;
684 u64 rx_drop_frame;
Ayaz Abdulla9c662432008-08-06 12:11:42 -0400685
686 /* version 3 stats */
687 u64 tx_unicast;
688 u64 tx_multicast;
689 u64 tx_broadcast;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400690};
691
Ayaz Abdulla9c662432008-08-06 12:11:42 -0400692#define NV_DEV_STATISTICS_V3_COUNT (sizeof(struct nv_ethtool_stats)/sizeof(u64))
693#define NV_DEV_STATISTICS_V2_COUNT (NV_DEV_STATISTICS_V3_COUNT - 3)
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500694#define NV_DEV_STATISTICS_V1_COUNT (NV_DEV_STATISTICS_V2_COUNT - 6)
695
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400696/* diagnostics */
697#define NV_TEST_COUNT_BASE 3
698#define NV_TEST_COUNT_EXTENDED 4
699
700static const struct nv_ethtool_str nv_etests_str[] = {
701 { "link (online/offline)" },
702 { "register (offline) " },
703 { "interrupt (offline) " },
704 { "loopback (offline) " }
705};
706
707struct register_test {
Al Viro5bb7ea22007-12-09 16:06:41 +0000708 __u32 reg;
709 __u32 mask;
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400710};
711
712static const struct register_test nv_registers_test[] = {
713 { NvRegUnknownSetupReg6, 0x01 },
714 { NvRegMisc1, 0x03c },
715 { NvRegOffloadConfig, 0x03ff },
716 { NvRegMulticastAddrA, 0xffffffff },
Ayaz Abdulla95d161c2006-07-06 16:46:25 -0400717 { NvRegTxWatermark, 0x0ff },
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400718 { NvRegWakeUpFlags, 0x07777 },
Szymon Janc78aea4f2010-11-27 08:39:43 +0000719 { 0, 0 }
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400720};
721
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500722struct nv_skb_map {
723 struct sk_buff *skb;
724 dma_addr_t dma;
Eric Dumazet73a37072009-06-17 21:17:59 +0000725 unsigned int dma_len:31;
726 unsigned int dma_single:1;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -0500727 struct ring_desc_ex *first_tx_desc;
728 struct nv_skb_map *next_tx_ctx;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500729};
730
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731/*
732 * SMP locking:
Wang Chenb74ca3a2008-12-08 01:14:16 -0800733 * All hardware access under netdev_priv(dev)->lock, except the performance
Linus Torvalds1da177e2005-04-16 15:20:36 -0700734 * critical parts:
735 * - rx is (pseudo-) lockless: it relies on the single-threading provided
736 * by the arch code for interrupts.
Herbert Xu932ff272006-06-09 12:20:56 -0700737 * - tx setup is lockless: it relies on netif_tx_lock. Actual submission
Wang Chenb74ca3a2008-12-08 01:14:16 -0800738 * needs netdev_priv(dev)->lock :-(
Herbert Xu932ff272006-06-09 12:20:56 -0700739 * - set_multicast_list: preparation lockless, relies on netif_tx_lock.
david decotignyf5d827a2011-11-16 12:15:13 +0000740 *
741 * Hardware stats updates are protected by hwstats_lock:
742 * - updated by nv_do_stats_poll (timer). This is meant to avoid
743 * integer wraparound in the NIC stats registers, at low frequency
744 * (0.1 Hz)
745 * - updated by nv_get_ethtool_stats + nv_get_stats64
746 *
747 * Software stats are accessed only through 64b synchronization points
748 * and are not subject to other synchronization techniques (single
749 * update thread on the TX or RX paths).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 */
751
752/* in dev: base, irq */
753struct fe_priv {
754 spinlock_t lock;
755
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700756 struct net_device *dev;
757 struct napi_struct napi;
758
david decotignyf5d827a2011-11-16 12:15:13 +0000759 /* hardware stats are updated in syscall and timer */
760 spinlock_t hwstats_lock;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400761 struct nv_ethtool_stats estats;
david decotignyf5d827a2011-11-16 12:15:13 +0000762
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 int in_shutdown;
764 u32 linkspeed;
765 int duplex;
766 int autoneg;
767 int fixed_mode;
768 int phyaddr;
769 int wolenabled;
770 unsigned int phy_oui;
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -0400771 unsigned int phy_model;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400772 unsigned int phy_rev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 u16 gigabit;
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400774 int intr_test;
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500775 int recover_error;
Ayaz Abdulla4145ade2009-03-05 08:02:26 +0000776 int quiet_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
778 /* General data: RO fields */
779 dma_addr_t ring_addr;
780 struct pci_dev *pci_dev;
781 u32 orig_mac[2];
Ayaz Abdulla582806b2009-03-05 08:02:03 +0000782 u32 events;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783 u32 irqmask;
784 u32 desc_ver;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400785 u32 txrxctl_bits;
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500786 u32 vlanctl_bits;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400787 u32 driver_data;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400788 u32 device_id;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400789 u32 register_size;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500790 u32 mac_in_use;
Ayaz Abdullacac1c522009-02-07 00:23:57 -0800791 int mgmt_version;
792 int mgmt_sema;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
794 void __iomem *base;
795
796 /* rx specific fields.
797 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
798 */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500799 union ring_type get_rx, put_rx, first_rx, last_rx;
800 struct nv_skb_map *get_rx_ctx, *put_rx_ctx;
801 struct nv_skb_map *first_rx_ctx, *last_rx_ctx;
802 struct nv_skb_map *rx_skb;
803
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700804 union ring_type rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 unsigned int rx_buf_sz;
Manfred Sprauld81c0982005-07-31 18:20:30 +0200806 unsigned int pkt_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 struct timer_list oom_kick;
808 struct timer_list nic_poll;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400809 struct timer_list stats_poll;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500810 u32 nic_poll_irq;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400811 int rx_ring_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
david decotignyf5d827a2011-11-16 12:15:13 +0000813 /* RX software stats */
814 struct u64_stats_sync swstats_rx_syncp;
815 u64 stat_rx_packets;
816 u64 stat_rx_bytes; /* not always available in HW */
817 u64 stat_rx_missed_errors;
818
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 {
1758 syncp_start = u64_stats_fetch_begin(&np->swstats_rx_syncp);
1759 storage->rx_packets = np->stat_rx_packets;
1760 storage->rx_bytes = np->stat_rx_bytes;
1761 storage->rx_missed_errors = np->stat_rx_missed_errors;
1762 } while (u64_stats_fetch_retry(&np->swstats_rx_syncp, syncp_start));
1763
1764 do {
1765 syncp_start = u64_stats_fetch_begin(&np->swstats_tx_syncp);
1766 storage->tx_packets = np->stat_tx_packets;
1767 storage->tx_bytes = np->stat_tx_bytes;
1768 storage->tx_dropped = np->stat_tx_dropped;
1769 } while (u64_stats_fetch_retry(&np->swstats_tx_syncp, syncp_start));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001770
Ayaz Abdulla21828162007-01-23 12:27:21 -05001771 /* If the nic supports hw counters then retrieve latest values */
david decotignyf5d827a2011-11-16 12:15:13 +00001772 if (np->driver_data & DEV_HAS_STATISTICS_V123) {
1773 spin_lock_bh(&np->hwstats_lock);
Ayaz Abdulla21828162007-01-23 12:27:21 -05001774
david decotignyf5d827a2011-11-16 12:15:13 +00001775 nv_update_stats(dev);
david decotigny674aee32011-11-16 12:15:07 +00001776
david decotignyf5d827a2011-11-16 12:15:13 +00001777 /* generic stats */
1778 storage->rx_errors = np->estats.rx_errors_total;
1779 storage->tx_errors = np->estats.tx_errors_total;
1780
1781 /* meaningful only when NIC supports stats v3 */
1782 storage->multicast = np->estats.rx_multicast;
1783
1784 /* detailed rx_errors */
1785 storage->rx_length_errors = np->estats.rx_length_error;
1786 storage->rx_over_errors = np->estats.rx_over_errors;
1787 storage->rx_crc_errors = np->estats.rx_crc_errors;
1788 storage->rx_frame_errors = np->estats.rx_frame_align_error;
1789 storage->rx_fifo_errors = np->estats.rx_drop_frame;
1790
1791 /* detailed tx_errors */
1792 storage->tx_carrier_errors = np->estats.tx_carrier_errors;
1793 storage->tx_fifo_errors = np->estats.tx_fifo_errors;
1794
1795 spin_unlock_bh(&np->hwstats_lock);
Ayaz Abdulla21828162007-01-23 12:27:21 -05001796 }
Jeff Garzik8148ff42007-10-16 20:56:09 -04001797
david decotignyf5d827a2011-11-16 12:15:13 +00001798 return storage;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799}
1800
1801/*
1802 * nv_alloc_rx: fill rx ring entries.
1803 * Return 1 if the allocations for the skbs failed and the
1804 * rx engine is without Available descriptors
1805 */
1806static int nv_alloc_rx(struct net_device *dev)
1807{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001808 struct fe_priv *np = netdev_priv(dev);
Szymon Janc78aea4f2010-11-27 08:39:43 +00001809 struct ring_desc *less_rx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001810
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001811 less_rx = np->get_rx.orig;
1812 if (less_rx-- == np->first_rx.orig)
1813 less_rx = np->last_rx.orig;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001814
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001815 while (np->put_rx.orig != less_rx) {
1816 struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001817 if (skb) {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001818 np->put_rx_ctx->skb = skb;
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001819 np->put_rx_ctx->dma = pci_map_single(np->pci_dev,
1820 skb->data,
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001821 skb_tailroom(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001822 PCI_DMA_FROMDEVICE);
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001823 np->put_rx_ctx->dma_len = skb_tailroom(skb);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001824 np->put_rx.orig->buf = cpu_to_le32(np->put_rx_ctx->dma);
1825 wmb();
1826 np->put_rx.orig->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX_AVAIL);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001827 if (unlikely(np->put_rx.orig++ == np->last_rx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001828 np->put_rx.orig = np->first_rx.orig;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001829 if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001830 np->put_rx_ctx = np->first_rx_ctx;
Szymon Janc78aea4f2010-11-27 08:39:43 +00001831 } else
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001832 return 1;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001833 }
1834 return 0;
1835}
1836
1837static int nv_alloc_rx_optimized(struct net_device *dev)
1838{
1839 struct fe_priv *np = netdev_priv(dev);
Szymon Janc78aea4f2010-11-27 08:39:43 +00001840 struct ring_desc_ex *less_rx;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001841
1842 less_rx = np->get_rx.ex;
1843 if (less_rx-- == np->first_rx.ex)
1844 less_rx = np->last_rx.ex;
1845
1846 while (np->put_rx.ex != less_rx) {
1847 struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD);
1848 if (skb) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001849 np->put_rx_ctx->skb = skb;
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001850 np->put_rx_ctx->dma = pci_map_single(np->pci_dev,
1851 skb->data,
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001852 skb_tailroom(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001853 PCI_DMA_FROMDEVICE);
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001854 np->put_rx_ctx->dma_len = skb_tailroom(skb);
Al Viro5bb7ea22007-12-09 16:06:41 +00001855 np->put_rx.ex->bufhigh = cpu_to_le32(dma_high(np->put_rx_ctx->dma));
1856 np->put_rx.ex->buflow = cpu_to_le32(dma_low(np->put_rx_ctx->dma));
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001857 wmb();
1858 np->put_rx.ex->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX2_AVAIL);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001859 if (unlikely(np->put_rx.ex++ == np->last_rx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001860 np->put_rx.ex = np->first_rx.ex;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001861 if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001862 np->put_rx_ctx = np->first_rx_ctx;
Szymon Janc78aea4f2010-11-27 08:39:43 +00001863 } else
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001864 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001865 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001866 return 0;
1867}
1868
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001869/* If rx bufs are exhausted called after 50ms to attempt to refresh */
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001870static void nv_do_rx_refill(unsigned long data)
1871{
1872 struct net_device *dev = (struct net_device *) data;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001873 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001874
1875 /* Just reschedule NAPI rx processing */
Ben Hutchings288379f2009-01-19 16:43:59 -08001876 napi_schedule(&np->napi);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001877}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001878
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001879static void nv_init_rx(struct net_device *dev)
Manfred Sprauld81c0982005-07-31 18:20:30 +02001880{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001881 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02001882 int i;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001883
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001884 np->get_rx = np->put_rx = np->first_rx = np->rx_ring;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001885
1886 if (!nv_optimized(np))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001887 np->last_rx.orig = &np->rx_ring.orig[np->rx_ring_size-1];
1888 else
1889 np->last_rx.ex = &np->rx_ring.ex[np->rx_ring_size-1];
1890 np->get_rx_ctx = np->put_rx_ctx = np->first_rx_ctx = np->rx_skb;
1891 np->last_rx_ctx = &np->rx_skb[np->rx_ring_size-1];
Manfred Sprauld81c0982005-07-31 18:20:30 +02001892
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001893 for (i = 0; i < np->rx_ring_size; i++) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001894 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001895 np->rx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001896 np->rx_ring.orig[i].buf = 0;
1897 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001898 np->rx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001899 np->rx_ring.ex[i].txvlan = 0;
1900 np->rx_ring.ex[i].bufhigh = 0;
1901 np->rx_ring.ex[i].buflow = 0;
1902 }
1903 np->rx_skb[i].skb = NULL;
1904 np->rx_skb[i].dma = 0;
1905 }
Manfred Sprauld81c0982005-07-31 18:20:30 +02001906}
1907
1908static void nv_init_tx(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001909{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001910 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001911 int i;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001912
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001913 np->get_tx = np->put_tx = np->first_tx = np->tx_ring;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001914
1915 if (!nv_optimized(np))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001916 np->last_tx.orig = &np->tx_ring.orig[np->tx_ring_size-1];
1917 else
1918 np->last_tx.ex = &np->tx_ring.ex[np->tx_ring_size-1];
1919 np->get_tx_ctx = np->put_tx_ctx = np->first_tx_ctx = np->tx_skb;
1920 np->last_tx_ctx = &np->tx_skb[np->tx_ring_size-1];
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001921 np->tx_pkts_in_progress = 0;
1922 np->tx_change_owner = NULL;
1923 np->tx_end_flip = NULL;
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00001924 np->tx_stop = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001925
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001926 for (i = 0; i < np->tx_ring_size; i++) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001927 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001928 np->tx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001929 np->tx_ring.orig[i].buf = 0;
1930 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001931 np->tx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001932 np->tx_ring.ex[i].txvlan = 0;
1933 np->tx_ring.ex[i].bufhigh = 0;
1934 np->tx_ring.ex[i].buflow = 0;
1935 }
1936 np->tx_skb[i].skb = NULL;
1937 np->tx_skb[i].dma = 0;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001938 np->tx_skb[i].dma_len = 0;
Eric Dumazet73a37072009-06-17 21:17:59 +00001939 np->tx_skb[i].dma_single = 0;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001940 np->tx_skb[i].first_tx_desc = NULL;
1941 np->tx_skb[i].next_tx_ctx = NULL;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001942 }
Manfred Sprauld81c0982005-07-31 18:20:30 +02001943}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001944
Manfred Sprauld81c0982005-07-31 18:20:30 +02001945static int nv_init_ring(struct net_device *dev)
1946{
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001947 struct fe_priv *np = netdev_priv(dev);
1948
Manfred Sprauld81c0982005-07-31 18:20:30 +02001949 nv_init_tx(dev);
1950 nv_init_rx(dev);
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001951
1952 if (!nv_optimized(np))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001953 return nv_alloc_rx(dev);
1954 else
1955 return nv_alloc_rx_optimized(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956}
1957
Eric Dumazet73a37072009-06-17 21:17:59 +00001958static void nv_unmap_txskb(struct fe_priv *np, struct nv_skb_map *tx_skb)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001959{
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001960 if (tx_skb->dma) {
Eric Dumazet73a37072009-06-17 21:17:59 +00001961 if (tx_skb->dma_single)
1962 pci_unmap_single(np->pci_dev, tx_skb->dma,
1963 tx_skb->dma_len,
1964 PCI_DMA_TODEVICE);
1965 else
1966 pci_unmap_page(np->pci_dev, tx_skb->dma,
1967 tx_skb->dma_len,
1968 PCI_DMA_TODEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001969 tx_skb->dma = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001970 }
Eric Dumazet73a37072009-06-17 21:17:59 +00001971}
1972
1973static int nv_release_txskb(struct fe_priv *np, struct nv_skb_map *tx_skb)
1974{
1975 nv_unmap_txskb(np, tx_skb);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001976 if (tx_skb->skb) {
1977 dev_kfree_skb_any(tx_skb->skb);
1978 tx_skb->skb = NULL;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001979 return 1;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001980 }
Eric Dumazet73a37072009-06-17 21:17:59 +00001981 return 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001982}
1983
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984static void nv_drain_tx(struct net_device *dev)
1985{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001986 struct fe_priv *np = netdev_priv(dev);
1987 unsigned int i;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001988
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001989 for (i = 0; i < np->tx_ring_size; i++) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001990 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001991 np->tx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001992 np->tx_ring.orig[i].buf = 0;
1993 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001994 np->tx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001995 np->tx_ring.ex[i].txvlan = 0;
1996 np->tx_ring.ex[i].bufhigh = 0;
1997 np->tx_ring.ex[i].buflow = 0;
1998 }
david decotignyf5d827a2011-11-16 12:15:13 +00001999 if (nv_release_txskb(np, &np->tx_skb[i])) {
2000 u64_stats_update_begin(&np->swstats_tx_syncp);
2001 np->stat_tx_dropped++;
2002 u64_stats_update_end(&np->swstats_tx_syncp);
2003 }
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002004 np->tx_skb[i].dma = 0;
2005 np->tx_skb[i].dma_len = 0;
Eric Dumazet73a37072009-06-17 21:17:59 +00002006 np->tx_skb[i].dma_single = 0;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002007 np->tx_skb[i].first_tx_desc = NULL;
2008 np->tx_skb[i].next_tx_ctx = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 }
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002010 np->tx_pkts_in_progress = 0;
2011 np->tx_change_owner = NULL;
2012 np->tx_end_flip = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002013}
2014
2015static void nv_drain_rx(struct net_device *dev)
2016{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002017 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018 int i;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002019
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04002020 for (i = 0; i < np->rx_ring_size; i++) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002021 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002022 np->rx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002023 np->rx_ring.orig[i].buf = 0;
2024 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002025 np->rx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002026 np->rx_ring.ex[i].txvlan = 0;
2027 np->rx_ring.ex[i].bufhigh = 0;
2028 np->rx_ring.ex[i].buflow = 0;
2029 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002030 wmb();
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002031 if (np->rx_skb[i].skb) {
2032 pci_unmap_single(np->pci_dev, np->rx_skb[i].dma,
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07002033 (skb_end_pointer(np->rx_skb[i].skb) -
2034 np->rx_skb[i].skb->data),
2035 PCI_DMA_FROMDEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002036 dev_kfree_skb(np->rx_skb[i].skb);
2037 np->rx_skb[i].skb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002038 }
2039 }
2040}
2041
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002042static void nv_drain_rxtx(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043{
2044 nv_drain_tx(dev);
2045 nv_drain_rx(dev);
2046}
2047
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002048static inline u32 nv_get_empty_tx_slots(struct fe_priv *np)
2049{
2050 return (u32)(np->tx_ring_size - ((np->tx_ring_size + (np->put_tx_ctx - np->get_tx_ctx)) % np->tx_ring_size));
2051}
2052
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002053static void nv_legacybackoff_reseed(struct net_device *dev)
2054{
2055 u8 __iomem *base = get_hwbase(dev);
2056 u32 reg;
2057 u32 low;
2058 int tx_status = 0;
2059
2060 reg = readl(base + NvRegSlotTime) & ~NVREG_SLOTTIME_MASK;
2061 get_random_bytes(&low, sizeof(low));
2062 reg |= low & NVREG_SLOTTIME_MASK;
2063
2064 /* Need to stop tx before change takes effect.
2065 * Caller has already gained np->lock.
2066 */
2067 tx_status = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_START;
2068 if (tx_status)
2069 nv_stop_tx(dev);
2070 nv_stop_rx(dev);
2071 writel(reg, base + NvRegSlotTime);
2072 if (tx_status)
2073 nv_start_tx(dev);
2074 nv_start_rx(dev);
2075}
2076
2077/* Gear Backoff Seeds */
2078#define BACKOFF_SEEDSET_ROWS 8
2079#define BACKOFF_SEEDSET_LFSRS 15
2080
2081/* Known Good seed sets */
2082static const u32 main_seedset[BACKOFF_SEEDSET_ROWS][BACKOFF_SEEDSET_LFSRS] = {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002083 {145, 155, 165, 175, 185, 196, 235, 245, 255, 265, 275, 285, 660, 690, 874},
2084 {245, 255, 265, 575, 385, 298, 335, 345, 355, 366, 375, 385, 761, 790, 974},
2085 {145, 155, 165, 175, 185, 196, 235, 245, 255, 265, 275, 285, 660, 690, 874},
2086 {245, 255, 265, 575, 385, 298, 335, 345, 355, 366, 375, 386, 761, 790, 974},
2087 {266, 265, 276, 585, 397, 208, 345, 355, 365, 376, 385, 396, 771, 700, 984},
2088 {266, 265, 276, 586, 397, 208, 346, 355, 365, 376, 285, 396, 771, 700, 984},
2089 {366, 365, 376, 686, 497, 308, 447, 455, 466, 476, 485, 496, 871, 800, 84},
2090 {466, 465, 476, 786, 597, 408, 547, 555, 566, 576, 585, 597, 971, 900, 184} };
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002091
2092static const u32 gear_seedset[BACKOFF_SEEDSET_ROWS][BACKOFF_SEEDSET_LFSRS] = {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002093 {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
2094 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
2095 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 397},
2096 {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
2097 {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
2098 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
2099 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
2100 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395} };
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002101
2102static void nv_gear_backoff_reseed(struct net_device *dev)
2103{
2104 u8 __iomem *base = get_hwbase(dev);
2105 u32 miniseed1, miniseed2, miniseed2_reversed, miniseed3, miniseed3_reversed;
2106 u32 temp, seedset, combinedSeed;
2107 int i;
2108
2109 /* Setup seed for free running LFSR */
2110 /* We are going to read the time stamp counter 3 times
2111 and swizzle bits around to increase randomness */
2112 get_random_bytes(&miniseed1, sizeof(miniseed1));
2113 miniseed1 &= 0x0fff;
2114 if (miniseed1 == 0)
2115 miniseed1 = 0xabc;
2116
2117 get_random_bytes(&miniseed2, sizeof(miniseed2));
2118 miniseed2 &= 0x0fff;
2119 if (miniseed2 == 0)
2120 miniseed2 = 0xabc;
2121 miniseed2_reversed =
2122 ((miniseed2 & 0xF00) >> 8) |
2123 (miniseed2 & 0x0F0) |
2124 ((miniseed2 & 0x00F) << 8);
2125
2126 get_random_bytes(&miniseed3, sizeof(miniseed3));
2127 miniseed3 &= 0x0fff;
2128 if (miniseed3 == 0)
2129 miniseed3 = 0xabc;
2130 miniseed3_reversed =
2131 ((miniseed3 & 0xF00) >> 8) |
2132 (miniseed3 & 0x0F0) |
2133 ((miniseed3 & 0x00F) << 8);
2134
2135 combinedSeed = ((miniseed1 ^ miniseed2_reversed) << 12) |
2136 (miniseed2 ^ miniseed3_reversed);
2137
2138 /* Seeds can not be zero */
2139 if ((combinedSeed & NVREG_BKOFFCTRL_SEED_MASK) == 0)
2140 combinedSeed |= 0x08;
2141 if ((combinedSeed & (NVREG_BKOFFCTRL_SEED_MASK << NVREG_BKOFFCTRL_GEAR)) == 0)
2142 combinedSeed |= 0x8000;
2143
2144 /* No need to disable tx here */
2145 temp = NVREG_BKOFFCTRL_DEFAULT | (0 << NVREG_BKOFFCTRL_SELECT);
2146 temp |= combinedSeed & NVREG_BKOFFCTRL_SEED_MASK;
2147 temp |= combinedSeed >> NVREG_BKOFFCTRL_GEAR;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002148 writel(temp, base + NvRegBackOffControl);
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002149
Szymon Janc78aea4f2010-11-27 08:39:43 +00002150 /* Setup seeds for all gear LFSRs. */
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002151 get_random_bytes(&seedset, sizeof(seedset));
2152 seedset = seedset % BACKOFF_SEEDSET_ROWS;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002153 for (i = 1; i <= BACKOFF_SEEDSET_LFSRS; i++) {
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002154 temp = NVREG_BKOFFCTRL_DEFAULT | (i << NVREG_BKOFFCTRL_SELECT);
2155 temp |= main_seedset[seedset][i-1] & 0x3ff;
2156 temp |= ((gear_seedset[seedset][i-1] & 0x3ff) << NVREG_BKOFFCTRL_GEAR);
2157 writel(temp, base + NvRegBackOffControl);
2158 }
2159}
2160
Linus Torvalds1da177e2005-04-16 15:20:36 -07002161/*
2162 * nv_start_xmit: dev->hard_start_xmit function
Herbert Xu932ff272006-06-09 12:20:56 -07002163 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002164 */
Stephen Hemminger613573252009-08-31 19:50:58 +00002165static netdev_tx_t nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002167 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002168 u32 tx_flags = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002169 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
2170 unsigned int fragments = skb_shinfo(skb)->nr_frags;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002171 unsigned int i;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002172 u32 offset = 0;
2173 u32 bcnt;
Eric Dumazete743d312010-04-14 15:59:40 -07002174 u32 size = skb_headlen(skb);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002175 u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002176 u32 empty_slots;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002177 struct ring_desc *put_tx;
2178 struct ring_desc *start_tx;
2179 struct ring_desc *prev_tx;
2180 struct nv_skb_map *prev_tx_ctx;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002181 unsigned long flags;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002182
2183 /* add fragments to entries count */
2184 for (i = 0; i < fragments; i++) {
david decotignye45a6182011-11-05 14:38:24 +00002185 u32 frag_size = skb_frag_size(&skb_shinfo(skb)->frags[i]);
Eric Dumazet9e903e02011-10-18 21:00:24 +00002186
david decotignye45a6182011-11-05 14:38:24 +00002187 entries += (frag_size >> NV_TX2_TSO_MAX_SHIFT) +
2188 ((frag_size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002189 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002190
Ayaz Abdulla001eb842009-01-09 11:03:44 +00002191 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002192 empty_slots = nv_get_empty_tx_slots(np);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002193 if (unlikely(empty_slots <= entries)) {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002194 netif_stop_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002195 np->tx_stop = 1;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002196 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002197 return NETDEV_TX_BUSY;
2198 }
Ayaz Abdulla001eb842009-01-09 11:03:44 +00002199 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002200
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002201 start_tx = put_tx = np->put_tx.orig;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002202
Ayaz Abdullafa454592006-01-05 22:45:45 -08002203 /* setup the header buffer */
2204 do {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002205 prev_tx = put_tx;
2206 prev_tx_ctx = np->put_tx_ctx;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002207 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002208 np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
Ayaz Abdullafa454592006-01-05 22:45:45 -08002209 PCI_DMA_TODEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002210 np->put_tx_ctx->dma_len = bcnt;
Eric Dumazet73a37072009-06-17 21:17:59 +00002211 np->put_tx_ctx->dma_single = 1;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002212 put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
2213 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002214
Ayaz Abdullafa454592006-01-05 22:45:45 -08002215 tx_flags = np->tx_flags;
2216 offset += bcnt;
2217 size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002218 if (unlikely(put_tx++ == np->last_tx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002219 put_tx = np->first_tx.orig;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002220 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002221 np->put_tx_ctx = np->first_tx_ctx;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002222 } while (size);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002223
2224 /* setup the fragments */
2225 for (i = 0; i < fragments; i++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00002226 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
david decotignye45a6182011-11-05 14:38:24 +00002227 u32 frag_size = skb_frag_size(frag);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002228 offset = 0;
2229
2230 do {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002231 prev_tx = put_tx;
2232 prev_tx_ctx = np->put_tx_ctx;
david decotignye45a6182011-11-05 14:38:24 +00002233 bcnt = (frag_size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : frag_size;
Ian Campbell671173c2011-08-29 23:18:28 +00002234 np->put_tx_ctx->dma = skb_frag_dma_map(
2235 &np->pci_dev->dev,
2236 frag, offset,
2237 bcnt,
Ian Campbell5d6bcdf2011-10-06 11:10:48 +01002238 DMA_TO_DEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002239 np->put_tx_ctx->dma_len = bcnt;
Eric Dumazet73a37072009-06-17 21:17:59 +00002240 np->put_tx_ctx->dma_single = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002241 put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
2242 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002243
Ayaz Abdullafa454592006-01-05 22:45:45 -08002244 offset += bcnt;
david decotignye45a6182011-11-05 14:38:24 +00002245 frag_size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002246 if (unlikely(put_tx++ == np->last_tx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002247 put_tx = np->first_tx.orig;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002248 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002249 np->put_tx_ctx = np->first_tx_ctx;
david decotignye45a6182011-11-05 14:38:24 +00002250 } while (frag_size);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002251 }
2252
Ayaz Abdullafa454592006-01-05 22:45:45 -08002253 /* set last fragment flag */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002254 prev_tx->flaglen |= cpu_to_le32(tx_flags_extra);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002255
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002256 /* save skb in this slot's context area */
2257 prev_tx_ctx->skb = skb;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002258
Herbert Xu89114af2006-07-08 13:34:32 -07002259 if (skb_is_gso(skb))
Herbert Xu79671682006-06-22 02:40:14 -07002260 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
Manfred Spraulee733622005-07-31 18:32:26 +02002261 else
Arjan van de Ven1d39ed52006-12-12 14:06:23 +01002262 tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
Patrick McHardy84fa7932006-08-29 16:44:56 -07002263 NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002264
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002265 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla164a86e2007-01-09 13:30:10 -05002266
Ayaz Abdullafa454592006-01-05 22:45:45 -08002267 /* set tx flags */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002268 start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
2269 np->put_tx.orig = put_tx;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002270
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002271 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002272
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002273 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002274 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275}
2276
Stephen Hemminger613573252009-08-31 19:50:58 +00002277static netdev_tx_t nv_start_xmit_optimized(struct sk_buff *skb,
2278 struct net_device *dev)
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002279{
2280 struct fe_priv *np = netdev_priv(dev);
2281 u32 tx_flags = 0;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002282 u32 tx_flags_extra;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002283 unsigned int fragments = skb_shinfo(skb)->nr_frags;
2284 unsigned int i;
2285 u32 offset = 0;
2286 u32 bcnt;
Eric Dumazete743d312010-04-14 15:59:40 -07002287 u32 size = skb_headlen(skb);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002288 u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
2289 u32 empty_slots;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002290 struct ring_desc_ex *put_tx;
2291 struct ring_desc_ex *start_tx;
2292 struct ring_desc_ex *prev_tx;
2293 struct nv_skb_map *prev_tx_ctx;
2294 struct nv_skb_map *start_tx_ctx;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002295 unsigned long flags;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002296
2297 /* add fragments to entries count */
2298 for (i = 0; i < fragments; i++) {
david decotignye45a6182011-11-05 14:38:24 +00002299 u32 frag_size = skb_frag_size(&skb_shinfo(skb)->frags[i]);
Eric Dumazet9e903e02011-10-18 21:00:24 +00002300
david decotignye45a6182011-11-05 14:38:24 +00002301 entries += (frag_size >> NV_TX2_TSO_MAX_SHIFT) +
2302 ((frag_size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002303 }
2304
Ayaz Abdulla001eb842009-01-09 11:03:44 +00002305 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002306 empty_slots = nv_get_empty_tx_slots(np);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002307 if (unlikely(empty_slots <= entries)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002308 netif_stop_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002309 np->tx_stop = 1;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002310 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002311 return NETDEV_TX_BUSY;
2312 }
Ayaz Abdulla001eb842009-01-09 11:03:44 +00002313 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002314
2315 start_tx = put_tx = np->put_tx.ex;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002316 start_tx_ctx = np->put_tx_ctx;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002317
2318 /* setup the header buffer */
2319 do {
2320 prev_tx = put_tx;
2321 prev_tx_ctx = np->put_tx_ctx;
2322 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
2323 np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
2324 PCI_DMA_TODEVICE);
2325 np->put_tx_ctx->dma_len = bcnt;
Eric Dumazet73a37072009-06-17 21:17:59 +00002326 np->put_tx_ctx->dma_single = 1;
Al Viro5bb7ea22007-12-09 16:06:41 +00002327 put_tx->bufhigh = cpu_to_le32(dma_high(np->put_tx_ctx->dma));
2328 put_tx->buflow = cpu_to_le32(dma_low(np->put_tx_ctx->dma));
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002329 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002330
2331 tx_flags = NV_TX2_VALID;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002332 offset += bcnt;
2333 size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002334 if (unlikely(put_tx++ == np->last_tx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002335 put_tx = np->first_tx.ex;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002336 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002337 np->put_tx_ctx = np->first_tx_ctx;
2338 } while (size);
2339
2340 /* setup the fragments */
2341 for (i = 0; i < fragments; i++) {
2342 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
david decotignye45a6182011-11-05 14:38:24 +00002343 u32 frag_size = skb_frag_size(frag);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002344 offset = 0;
2345
2346 do {
2347 prev_tx = put_tx;
2348 prev_tx_ctx = np->put_tx_ctx;
david decotignye45a6182011-11-05 14:38:24 +00002349 bcnt = (frag_size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : frag_size;
Ian Campbell671173c2011-08-29 23:18:28 +00002350 np->put_tx_ctx->dma = skb_frag_dma_map(
2351 &np->pci_dev->dev,
2352 frag, offset,
2353 bcnt,
Ian Campbell5d6bcdf2011-10-06 11:10:48 +01002354 DMA_TO_DEVICE);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002355 np->put_tx_ctx->dma_len = bcnt;
Eric Dumazet73a37072009-06-17 21:17:59 +00002356 np->put_tx_ctx->dma_single = 0;
Al Viro5bb7ea22007-12-09 16:06:41 +00002357 put_tx->bufhigh = cpu_to_le32(dma_high(np->put_tx_ctx->dma));
2358 put_tx->buflow = cpu_to_le32(dma_low(np->put_tx_ctx->dma));
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002359 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002360
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002361 offset += bcnt;
david decotignye45a6182011-11-05 14:38:24 +00002362 frag_size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002363 if (unlikely(put_tx++ == np->last_tx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002364 put_tx = np->first_tx.ex;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002365 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002366 np->put_tx_ctx = np->first_tx_ctx;
david decotignye45a6182011-11-05 14:38:24 +00002367 } while (frag_size);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002368 }
2369
2370 /* set last fragment flag */
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002371 prev_tx->flaglen |= cpu_to_le32(NV_TX2_LASTPACKET);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002372
2373 /* save skb in this slot's context area */
2374 prev_tx_ctx->skb = skb;
2375
2376 if (skb_is_gso(skb))
2377 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
2378 else
2379 tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
2380 NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
2381
2382 /* vlan tag */
Jesse Grosseab6d182010-10-20 13:56:03 +00002383 if (vlan_tx_tag_present(skb))
2384 start_tx->txvlan = cpu_to_le32(NV_TX3_VLAN_TAG_PRESENT |
2385 vlan_tx_tag_get(skb));
2386 else
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002387 start_tx->txvlan = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002388
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002389 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002390
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002391 if (np->tx_limit) {
2392 /* Limit the number of outstanding tx. Setup all fragments, but
2393 * do not set the VALID bit on the first descriptor. Save a pointer
2394 * to that descriptor and also for next skb_map element.
2395 */
2396
2397 if (np->tx_pkts_in_progress == NV_TX_LIMIT_COUNT) {
2398 if (!np->tx_change_owner)
2399 np->tx_change_owner = start_tx_ctx;
2400
2401 /* remove VALID bit */
2402 tx_flags &= ~NV_TX2_VALID;
2403 start_tx_ctx->first_tx_desc = start_tx;
2404 start_tx_ctx->next_tx_ctx = np->put_tx_ctx;
2405 np->tx_end_flip = np->put_tx_ctx;
2406 } else {
2407 np->tx_pkts_in_progress++;
2408 }
2409 }
2410
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002411 /* set tx flags */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002412 start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
2413 np->put_tx.ex = put_tx;
2414
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002415 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002416
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002417 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002418 return NETDEV_TX_OK;
2419}
2420
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002421static inline void nv_tx_flip_ownership(struct net_device *dev)
2422{
2423 struct fe_priv *np = netdev_priv(dev);
2424
2425 np->tx_pkts_in_progress--;
2426 if (np->tx_change_owner) {
Al Viro30ecce92008-03-26 05:57:12 +00002427 np->tx_change_owner->first_tx_desc->flaglen |=
2428 cpu_to_le32(NV_TX2_VALID);
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002429 np->tx_pkts_in_progress++;
2430
2431 np->tx_change_owner = np->tx_change_owner->next_tx_ctx;
2432 if (np->tx_change_owner == np->tx_end_flip)
2433 np->tx_change_owner = NULL;
2434
2435 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
2436 }
2437}
2438
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439/*
2440 * nv_tx_done: check for completed packets, release the skbs.
2441 *
2442 * Caller must own np->lock.
2443 */
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002444static int nv_tx_done(struct net_device *dev, int limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002445{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002446 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002447 u32 flags;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002448 int tx_work = 0;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002449 struct ring_desc *orig_get_tx = np->get_tx.orig;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002450
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002451 while ((np->get_tx.orig != np->put_tx.orig) &&
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002452 !((flags = le32_to_cpu(np->get_tx.orig->flaglen)) & NV_TX_VALID) &&
2453 (tx_work < limit)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002454
Eric Dumazet73a37072009-06-17 21:17:59 +00002455 nv_unmap_txskb(np, np->get_tx_ctx);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002456
Linus Torvalds1da177e2005-04-16 15:20:36 -07002457 if (np->desc_ver == DESC_VER_1) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002458 if (flags & NV_TX_LASTPACKET) {
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002459 if (flags & NV_TX_ERROR) {
david decotignyf5d827a2011-11-16 12:15:13 +00002460 if ((flags & NV_TX_RETRYERROR)
2461 && !(flags & NV_TX_RETRYCOUNT_MASK))
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002462 nv_legacybackoff_reseed(dev);
david decotigny674aee32011-11-16 12:15:07 +00002463 } else {
david decotignyf5d827a2011-11-16 12:15:13 +00002464 u64_stats_update_begin(&np->swstats_tx_syncp);
2465 np->stat_tx_packets++;
2466 np->stat_tx_bytes += np->get_tx_ctx->skb->len;
2467 u64_stats_update_end(&np->swstats_tx_syncp);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002468 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002469 dev_kfree_skb_any(np->get_tx_ctx->skb);
2470 np->get_tx_ctx->skb = NULL;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002471 tx_work++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472 }
2473 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002474 if (flags & NV_TX2_LASTPACKET) {
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002475 if (flags & NV_TX2_ERROR) {
david decotignyf5d827a2011-11-16 12:15:13 +00002476 if ((flags & NV_TX2_RETRYERROR)
2477 && !(flags & NV_TX2_RETRYCOUNT_MASK))
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002478 nv_legacybackoff_reseed(dev);
david decotigny674aee32011-11-16 12:15:07 +00002479 } else {
david decotignyf5d827a2011-11-16 12:15:13 +00002480 u64_stats_update_begin(&np->swstats_tx_syncp);
2481 np->stat_tx_packets++;
2482 np->stat_tx_bytes += np->get_tx_ctx->skb->len;
2483 u64_stats_update_end(&np->swstats_tx_syncp);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002484 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002485 dev_kfree_skb_any(np->get_tx_ctx->skb);
2486 np->get_tx_ctx->skb = NULL;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002487 tx_work++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488 }
2489 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002490 if (unlikely(np->get_tx.orig++ == np->last_tx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002491 np->get_tx.orig = np->first_tx.orig;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002492 if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002493 np->get_tx_ctx = np->first_tx_ctx;
2494 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002495 if (unlikely((np->tx_stop == 1) && (np->get_tx.orig != orig_get_tx))) {
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002496 np->tx_stop = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002497 netif_wake_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002498 }
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002499 return tx_work;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002500}
2501
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002502static int nv_tx_done_optimized(struct net_device *dev, int limit)
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002503{
2504 struct fe_priv *np = netdev_priv(dev);
2505 u32 flags;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002506 int tx_work = 0;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002507 struct ring_desc_ex *orig_get_tx = np->get_tx.ex;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002508
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002509 while ((np->get_tx.ex != np->put_tx.ex) &&
Julia Lawall217d32d2010-07-05 22:15:47 -07002510 !((flags = le32_to_cpu(np->get_tx.ex->flaglen)) & NV_TX2_VALID) &&
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002511 (tx_work < limit)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002512
Eric Dumazet73a37072009-06-17 21:17:59 +00002513 nv_unmap_txskb(np, np->get_tx_ctx);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002514
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002515 if (flags & NV_TX2_LASTPACKET) {
david decotigny4687f3f2011-11-05 14:38:22 +00002516 if (flags & NV_TX2_ERROR) {
david decotignyf5d827a2011-11-16 12:15:13 +00002517 if ((flags & NV_TX2_RETRYERROR)
2518 && !(flags & NV_TX2_RETRYCOUNT_MASK)) {
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002519 if (np->driver_data & DEV_HAS_GEAR_MODE)
2520 nv_gear_backoff_reseed(dev);
2521 else
2522 nv_legacybackoff_reseed(dev);
2523 }
david decotigny674aee32011-11-16 12:15:07 +00002524 } else {
david decotignyf5d827a2011-11-16 12:15:13 +00002525 u64_stats_update_begin(&np->swstats_tx_syncp);
2526 np->stat_tx_packets++;
2527 np->stat_tx_bytes += np->get_tx_ctx->skb->len;
2528 u64_stats_update_end(&np->swstats_tx_syncp);
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002529 }
2530
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002531 dev_kfree_skb_any(np->get_tx_ctx->skb);
2532 np->get_tx_ctx->skb = NULL;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002533 tx_work++;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002534
Szymon Janc78aea4f2010-11-27 08:39:43 +00002535 if (np->tx_limit)
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002536 nv_tx_flip_ownership(dev);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002537 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002538 if (unlikely(np->get_tx.ex++ == np->last_tx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002539 np->get_tx.ex = np->first_tx.ex;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002540 if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002541 np->get_tx_ctx = np->first_tx_ctx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002542 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002543 if (unlikely((np->tx_stop == 1) && (np->get_tx.ex != orig_get_tx))) {
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002544 np->tx_stop = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002545 netif_wake_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002546 }
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002547 return tx_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002548}
2549
2550/*
2551 * nv_tx_timeout: dev->tx_timeout function
Herbert Xu932ff272006-06-09 12:20:56 -07002552 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002553 */
2554static void nv_tx_timeout(struct net_device *dev)
2555{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002556 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002557 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002558 u32 status;
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002559 union ring_type put_tx;
2560 int saved_tx_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002561
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002562 if (np->msi_flags & NV_MSI_X_ENABLED)
2563 status = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
2564 else
2565 status = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
2566
Sameer Nanda1ec4f2d2011-11-16 12:15:12 +00002567 netdev_warn(dev, "Got tx_timeout. irq status: %08x\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002568
Sameer Nanda1ec4f2d2011-11-16 12:15:12 +00002569 if (unlikely(debug_tx_timeout)) {
2570 int i;
2571
2572 netdev_info(dev, "Ring at %lx\n", (unsigned long)np->ring_addr);
2573 netdev_info(dev, "Dumping tx registers\n");
2574 for (i = 0; i <= np->register_size; i += 32) {
Joe Perches1d397f32010-11-29 07:41:57 +00002575 netdev_info(dev,
Sameer Nanda1ec4f2d2011-11-16 12:15:12 +00002576 "%3x: %08x %08x %08x %08x "
2577 "%08x %08x %08x %08x\n",
Joe Perches1d397f32010-11-29 07:41:57 +00002578 i,
Sameer Nanda1ec4f2d2011-11-16 12:15:12 +00002579 readl(base + i + 0), readl(base + i + 4),
2580 readl(base + i + 8), readl(base + i + 12),
2581 readl(base + i + 16), readl(base + i + 20),
2582 readl(base + i + 24), readl(base + i + 28));
2583 }
2584 netdev_info(dev, "Dumping tx ring\n");
2585 for (i = 0; i < np->tx_ring_size; i += 4) {
2586 if (!nv_optimized(np)) {
2587 netdev_info(dev,
2588 "%03x: %08x %08x // %08x %08x "
2589 "// %08x %08x // %08x %08x\n",
2590 i,
2591 le32_to_cpu(np->tx_ring.orig[i].buf),
2592 le32_to_cpu(np->tx_ring.orig[i].flaglen),
2593 le32_to_cpu(np->tx_ring.orig[i+1].buf),
2594 le32_to_cpu(np->tx_ring.orig[i+1].flaglen),
2595 le32_to_cpu(np->tx_ring.orig[i+2].buf),
2596 le32_to_cpu(np->tx_ring.orig[i+2].flaglen),
2597 le32_to_cpu(np->tx_ring.orig[i+3].buf),
2598 le32_to_cpu(np->tx_ring.orig[i+3].flaglen));
2599 } else {
2600 netdev_info(dev,
2601 "%03x: %08x %08x %08x "
2602 "// %08x %08x %08x "
2603 "// %08x %08x %08x "
2604 "// %08x %08x %08x\n",
2605 i,
2606 le32_to_cpu(np->tx_ring.ex[i].bufhigh),
2607 le32_to_cpu(np->tx_ring.ex[i].buflow),
2608 le32_to_cpu(np->tx_ring.ex[i].flaglen),
2609 le32_to_cpu(np->tx_ring.ex[i+1].bufhigh),
2610 le32_to_cpu(np->tx_ring.ex[i+1].buflow),
2611 le32_to_cpu(np->tx_ring.ex[i+1].flaglen),
2612 le32_to_cpu(np->tx_ring.ex[i+2].bufhigh),
2613 le32_to_cpu(np->tx_ring.ex[i+2].buflow),
2614 le32_to_cpu(np->tx_ring.ex[i+2].flaglen),
2615 le32_to_cpu(np->tx_ring.ex[i+3].bufhigh),
2616 le32_to_cpu(np->tx_ring.ex[i+3].buflow),
2617 le32_to_cpu(np->tx_ring.ex[i+3].flaglen));
2618 }
Manfred Spraulc2dba062005-07-31 18:29:47 +02002619 }
2620 }
2621
Linus Torvalds1da177e2005-04-16 15:20:36 -07002622 spin_lock_irq(&np->lock);
2623
2624 /* 1) stop tx engine */
2625 nv_stop_tx(dev);
2626
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002627 /* 2) complete any outstanding tx and do not give HW any limited tx pkts */
2628 saved_tx_limit = np->tx_limit;
2629 np->tx_limit = 0; /* prevent giving HW any limited pkts */
2630 np->tx_stop = 0; /* prevent waking tx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002631 if (!nv_optimized(np))
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002632 nv_tx_done(dev, np->tx_ring_size);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002633 else
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05002634 nv_tx_done_optimized(dev, np->tx_ring_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002636 /* save current HW position */
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002637 if (np->tx_change_owner)
2638 put_tx.ex = np->tx_change_owner->first_tx_desc;
2639 else
2640 put_tx = np->put_tx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002641
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002642 /* 3) clear all tx state */
2643 nv_drain_tx(dev);
2644 nv_init_tx(dev);
Ayaz Abdulla3ba4d092007-03-23 05:50:02 -05002645
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002646 /* 4) restore state to current HW position */
2647 np->get_tx = np->put_tx = put_tx;
2648 np->tx_limit = saved_tx_limit;
2649
2650 /* 5) restart tx engine */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 nv_start_tx(dev);
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002652 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653 spin_unlock_irq(&np->lock);
2654}
2655
Manfred Spraul22c6d142005-04-19 21:17:09 +02002656/*
2657 * Called when the nic notices a mismatch between the actual data len on the
2658 * wire and the len indicated in the 802 header
2659 */
2660static int nv_getlen(struct net_device *dev, void *packet, int datalen)
2661{
2662 int hdrlen; /* length of the 802 header */
2663 int protolen; /* length as stored in the proto field */
2664
2665 /* 1) calculate len according to header */
Szymon Janc78aea4f2010-11-27 08:39:43 +00002666 if (((struct vlan_ethhdr *)packet)->h_vlan_proto == htons(ETH_P_8021Q)) {
2667 protolen = ntohs(((struct vlan_ethhdr *)packet)->h_vlan_encapsulated_proto);
Manfred Spraul22c6d142005-04-19 21:17:09 +02002668 hdrlen = VLAN_HLEN;
2669 } else {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002670 protolen = ntohs(((struct ethhdr *)packet)->h_proto);
Manfred Spraul22c6d142005-04-19 21:17:09 +02002671 hdrlen = ETH_HLEN;
2672 }
Manfred Spraul22c6d142005-04-19 21:17:09 +02002673 if (protolen > ETH_DATA_LEN)
2674 return datalen; /* Value in proto field not a len, no checks possible */
2675
2676 protolen += hdrlen;
2677 /* consistency checks: */
2678 if (datalen > ETH_ZLEN) {
2679 if (datalen >= protolen) {
2680 /* more data on wire than in 802 header, trim of
2681 * additional data.
2682 */
Manfred Spraul22c6d142005-04-19 21:17:09 +02002683 return protolen;
2684 } else {
2685 /* less data on wire than mentioned in header.
2686 * Discard the packet.
2687 */
Manfred Spraul22c6d142005-04-19 21:17:09 +02002688 return -1;
2689 }
2690 } else {
2691 /* short packet. Accept only if 802 values are also short */
2692 if (protolen > ETH_ZLEN) {
Manfred Spraul22c6d142005-04-19 21:17:09 +02002693 return -1;
2694 }
Manfred Spraul22c6d142005-04-19 21:17:09 +02002695 return datalen;
2696 }
2697}
2698
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002699static int nv_rx_process(struct net_device *dev, int limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002701 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002702 u32 flags;
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002703 int rx_work = 0;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002704 struct sk_buff *skb;
2705 int len;
Ayaz Abdullaee407b02006-02-04 13:13:17 -05002706
Szymon Janc78aea4f2010-11-27 08:39:43 +00002707 while ((np->get_rx.orig != np->put_rx.orig) &&
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002708 !((flags = le32_to_cpu(np->get_rx.orig->flaglen)) & NV_RX_AVAIL) &&
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002709 (rx_work < limit)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002710
Linus Torvalds1da177e2005-04-16 15:20:36 -07002711 /*
2712 * the packet is for us - immediately tear down the pci mapping.
2713 * TODO: check if a prefetch of the first cacheline improves
2714 * the performance.
2715 */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002716 pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma,
2717 np->get_rx_ctx->dma_len,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002718 PCI_DMA_FROMDEVICE);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002719 skb = np->get_rx_ctx->skb;
2720 np->get_rx_ctx->skb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722 /* look at what we actually got: */
2723 if (np->desc_ver == DESC_VER_1) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002724 if (likely(flags & NV_RX_DESCRIPTORVALID)) {
2725 len = flags & LEN_MASK_V1;
2726 if (unlikely(flags & NV_RX_ERROR)) {
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002727 if ((flags & NV_RX_ERROR_MASK) == NV_RX_ERROR4) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002728 len = nv_getlen(dev, skb->data, len);
2729 if (len < 0) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002730 dev_kfree_skb(skb);
2731 goto next_pkt;
2732 }
2733 }
2734 /* framing errors are soft errors */
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002735 else if ((flags & NV_RX_ERROR_MASK) == NV_RX_FRAMINGERR) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002736 if (flags & NV_RX_SUBSTRACT1)
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002737 len--;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002738 }
2739 /* the rest are hard errors */
2740 else {
david decotignyf5d827a2011-11-16 12:15:13 +00002741 if (flags & NV_RX_MISSEDFRAME) {
2742 u64_stats_update_begin(&np->swstats_rx_syncp);
2743 np->stat_rx_missed_errors++;
2744 u64_stats_update_end(&np->swstats_rx_syncp);
2745 }
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002746 dev_kfree_skb(skb);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002747 goto next_pkt;
2748 }
2749 }
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002750 } else {
2751 dev_kfree_skb(skb);
2752 goto next_pkt;
Manfred Spraul22c6d142005-04-19 21:17:09 +02002753 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 } else {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002755 if (likely(flags & NV_RX2_DESCRIPTORVALID)) {
2756 len = flags & LEN_MASK_V2;
2757 if (unlikely(flags & NV_RX2_ERROR)) {
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002758 if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_ERROR4) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002759 len = nv_getlen(dev, skb->data, len);
2760 if (len < 0) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002761 dev_kfree_skb(skb);
2762 goto next_pkt;
2763 }
2764 }
2765 /* framing errors are soft errors */
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002766 else if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_FRAMINGERR) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002767 if (flags & NV_RX2_SUBSTRACT1)
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002768 len--;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002769 }
2770 /* the rest are hard errors */
2771 else {
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002772 dev_kfree_skb(skb);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002773 goto next_pkt;
2774 }
2775 }
Ayaz Abdullabfaffe82008-01-13 16:02:55 -05002776 if (((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_TCP) || /*ip and tcp */
2777 ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_UDP)) /*ip and udp */
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002778 skb->ip_summed = CHECKSUM_UNNECESSARY;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002779 } else {
2780 dev_kfree_skb(skb);
2781 goto next_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 }
2783 }
2784 /* got a valid packet - forward it to the network core */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 skb_put(skb, len);
2786 skb->protocol = eth_type_trans(skb, dev);
Tom Herbert53f224c2010-05-03 19:08:45 +00002787 napi_gro_receive(&np->napi, skb);
david decotignyf5d827a2011-11-16 12:15:13 +00002788 u64_stats_update_begin(&np->swstats_rx_syncp);
2789 np->stat_rx_packets++;
2790 np->stat_rx_bytes += len;
2791 u64_stats_update_end(&np->swstats_rx_syncp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792next_pkt:
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002793 if (unlikely(np->get_rx.orig++ == np->last_rx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002794 np->get_rx.orig = np->first_rx.orig;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002795 if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002796 np->get_rx_ctx = np->first_rx_ctx;
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002797
2798 rx_work++;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002799 }
2800
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002801 return rx_work;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002802}
2803
2804static int nv_rx_process_optimized(struct net_device *dev, int limit)
2805{
2806 struct fe_priv *np = netdev_priv(dev);
2807 u32 flags;
2808 u32 vlanflags = 0;
Ingo Molnarc1b71512007-10-17 12:18:23 +02002809 int rx_work = 0;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002810 struct sk_buff *skb;
2811 int len;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002812
Szymon Janc78aea4f2010-11-27 08:39:43 +00002813 while ((np->get_rx.ex != np->put_rx.ex) &&
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002814 !((flags = le32_to_cpu(np->get_rx.ex->flaglen)) & NV_RX2_AVAIL) &&
Ingo Molnarc1b71512007-10-17 12:18:23 +02002815 (rx_work < limit)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002816
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002817 /*
2818 * the packet is for us - immediately tear down the pci mapping.
2819 * TODO: check if a prefetch of the first cacheline improves
2820 * the performance.
2821 */
2822 pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma,
2823 np->get_rx_ctx->dma_len,
2824 PCI_DMA_FROMDEVICE);
2825 skb = np->get_rx_ctx->skb;
2826 np->get_rx_ctx->skb = NULL;
2827
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002828 /* look at what we actually got: */
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002829 if (likely(flags & NV_RX2_DESCRIPTORVALID)) {
2830 len = flags & LEN_MASK_V2;
2831 if (unlikely(flags & NV_RX2_ERROR)) {
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002832 if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_ERROR4) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002833 len = nv_getlen(dev, skb->data, len);
2834 if (len < 0) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002835 dev_kfree_skb(skb);
2836 goto next_pkt;
2837 }
2838 }
2839 /* framing errors are soft errors */
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002840 else if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_FRAMINGERR) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002841 if (flags & NV_RX2_SUBSTRACT1)
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002842 len--;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002843 }
2844 /* the rest are hard errors */
2845 else {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002846 dev_kfree_skb(skb);
2847 goto next_pkt;
2848 }
2849 }
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002850
Ayaz Abdullabfaffe82008-01-13 16:02:55 -05002851 if (((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_TCP) || /*ip and tcp */
2852 ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_UDP)) /*ip and udp */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002853 skb->ip_summed = CHECKSUM_UNNECESSARY;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002854
2855 /* got a valid packet - forward it to the network core */
2856 skb_put(skb, len);
2857 skb->protocol = eth_type_trans(skb, dev);
2858 prefetch(skb->data);
2859
Jiri Pirko3326c782011-07-20 04:54:38 +00002860 vlanflags = le32_to_cpu(np->get_rx.ex->buflow);
Jiri Pirko0891b0e2011-07-26 10:19:28 +00002861
2862 /*
2863 * There's need to check for NETIF_F_HW_VLAN_RX here.
2864 * Even if vlan rx accel is disabled,
2865 * NV_RX3_VLAN_TAG_PRESENT is pseudo randomly set.
2866 */
2867 if (dev->features & NETIF_F_HW_VLAN_RX &&
2868 vlanflags & NV_RX3_VLAN_TAG_PRESENT) {
Jiri Pirko3326c782011-07-20 04:54:38 +00002869 u16 vid = vlanflags & NV_RX3_VLAN_TAG_MASK;
2870
2871 __vlan_hwaccel_put_tag(skb, vid);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002872 }
Jiri Pirko3326c782011-07-20 04:54:38 +00002873 napi_gro_receive(&np->napi, skb);
david decotignyf5d827a2011-11-16 12:15:13 +00002874 u64_stats_update_begin(&np->swstats_rx_syncp);
2875 np->stat_rx_packets++;
2876 np->stat_rx_bytes += len;
2877 u64_stats_update_end(&np->swstats_rx_syncp);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002878 } else {
2879 dev_kfree_skb(skb);
2880 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002881next_pkt:
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002882 if (unlikely(np->get_rx.ex++ == np->last_rx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002883 np->get_rx.ex = np->first_rx.ex;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002884 if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002885 np->get_rx_ctx = np->first_rx_ctx;
Ingo Molnarc1b71512007-10-17 12:18:23 +02002886
2887 rx_work++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002888 }
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002889
Ingo Molnarc1b71512007-10-17 12:18:23 +02002890 return rx_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002891}
2892
Manfred Sprauld81c0982005-07-31 18:20:30 +02002893static void set_bufsize(struct net_device *dev)
2894{
2895 struct fe_priv *np = netdev_priv(dev);
2896
2897 if (dev->mtu <= ETH_DATA_LEN)
2898 np->rx_buf_sz = ETH_DATA_LEN + NV_RX_HEADERS;
2899 else
2900 np->rx_buf_sz = dev->mtu + NV_RX_HEADERS;
2901}
2902
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903/*
2904 * nv_change_mtu: dev->change_mtu function
2905 * Called with dev_base_lock held for read.
2906 */
2907static int nv_change_mtu(struct net_device *dev, int new_mtu)
2908{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002909 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002910 int old_mtu;
2911
2912 if (new_mtu < 64 || new_mtu > np->pkt_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002913 return -EINVAL;
Manfred Sprauld81c0982005-07-31 18:20:30 +02002914
2915 old_mtu = dev->mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 dev->mtu = new_mtu;
Manfred Sprauld81c0982005-07-31 18:20:30 +02002917
2918 /* return early if the buffer sizes will not change */
2919 if (old_mtu <= ETH_DATA_LEN && new_mtu <= ETH_DATA_LEN)
2920 return 0;
2921 if (old_mtu == new_mtu)
2922 return 0;
2923
2924 /* synchronized against open : rtnl_lock() held by caller */
2925 if (netif_running(dev)) {
viro@ftp.linux.org.uk25097d42005-09-06 01:36:58 +01002926 u8 __iomem *base = get_hwbase(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002927 /*
2928 * It seems that the nic preloads valid ring entries into an
2929 * internal buffer. The procedure for flushing everything is
2930 * guessed, there is probably a simpler approach.
2931 * Changing the MTU is a rare event, it shouldn't matter.
2932 */
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002933 nv_disable_irq(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00002934 nv_napi_disable(dev);
Herbert Xu932ff272006-06-09 12:20:56 -07002935 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07002936 netif_addr_lock(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002937 spin_lock(&np->lock);
2938 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002939 nv_stop_rxtx(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002940 nv_txrx_reset(dev);
2941 /* drain rx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002942 nv_drain_rxtx(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002943 /* reinit driver view of the rx queue */
Manfred Sprauld81c0982005-07-31 18:20:30 +02002944 set_bufsize(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04002945 if (nv_init_ring(dev)) {
Manfred Sprauld81c0982005-07-31 18:20:30 +02002946 if (!np->in_shutdown)
2947 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2948 }
2949 /* reinit nic view of the rx queue */
2950 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
Ayaz Abdulla0832b252006-02-04 13:13:26 -05002951 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00002952 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Manfred Sprauld81c0982005-07-31 18:20:30 +02002953 base + NvRegRingSizes);
2954 pci_push(base);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002955 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002956 pci_push(base);
2957
2958 /* restart rx engine */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002959 nv_start_rxtx(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002960 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07002961 netif_addr_unlock(dev);
Herbert Xu932ff272006-06-09 12:20:56 -07002962 netif_tx_unlock_bh(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00002963 nv_napi_enable(dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002964 nv_enable_irq(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002965 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966 return 0;
2967}
2968
Manfred Spraul72b31782005-07-31 18:33:34 +02002969static void nv_copy_mac_to_hw(struct net_device *dev)
2970{
viro@ftp.linux.org.uk25097d42005-09-06 01:36:58 +01002971 u8 __iomem *base = get_hwbase(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002972 u32 mac[2];
2973
2974 mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) +
2975 (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24);
2976 mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8);
2977
2978 writel(mac[0], base + NvRegMacAddrA);
2979 writel(mac[1], base + NvRegMacAddrB);
2980}
2981
2982/*
2983 * nv_set_mac_address: dev->set_mac_address function
2984 * Called with rtnl_lock() held.
2985 */
2986static int nv_set_mac_address(struct net_device *dev, void *addr)
2987{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002988 struct fe_priv *np = netdev_priv(dev);
Szymon Janc78aea4f2010-11-27 08:39:43 +00002989 struct sockaddr *macaddr = (struct sockaddr *)addr;
Manfred Spraul72b31782005-07-31 18:33:34 +02002990
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002991 if (!is_valid_ether_addr(macaddr->sa_data))
Manfred Spraul72b31782005-07-31 18:33:34 +02002992 return -EADDRNOTAVAIL;
2993
2994 /* synchronized against open : rtnl_lock() held by caller */
2995 memcpy(dev->dev_addr, macaddr->sa_data, ETH_ALEN);
2996
2997 if (netif_running(dev)) {
Herbert Xu932ff272006-06-09 12:20:56 -07002998 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07002999 netif_addr_lock(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02003000 spin_lock_irq(&np->lock);
3001
3002 /* stop rx engine */
3003 nv_stop_rx(dev);
3004
3005 /* set mac address */
3006 nv_copy_mac_to_hw(dev);
3007
3008 /* restart rx engine */
3009 nv_start_rx(dev);
3010 spin_unlock_irq(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07003011 netif_addr_unlock(dev);
Herbert Xu932ff272006-06-09 12:20:56 -07003012 netif_tx_unlock_bh(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02003013 } else {
3014 nv_copy_mac_to_hw(dev);
3015 }
3016 return 0;
3017}
3018
Linus Torvalds1da177e2005-04-16 15:20:36 -07003019/*
3020 * nv_set_multicast: dev->set_multicast function
Herbert Xu932ff272006-06-09 12:20:56 -07003021 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003022 */
3023static void nv_set_multicast(struct net_device *dev)
3024{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003025 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003026 u8 __iomem *base = get_hwbase(dev);
3027 u32 addr[2];
3028 u32 mask[2];
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003029 u32 pff = readl(base + NvRegPacketFilterFlags) & NVREG_PFF_PAUSE_RX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003030
3031 memset(addr, 0, sizeof(addr));
3032 memset(mask, 0, sizeof(mask));
3033
3034 if (dev->flags & IFF_PROMISC) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003035 pff |= NVREG_PFF_PROMISC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003036 } else {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003037 pff |= NVREG_PFF_MYADDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038
Jiri Pirko48e2f182010-02-22 09:22:26 +00003039 if (dev->flags & IFF_ALLMULTI || !netdev_mc_empty(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003040 u32 alwaysOff[2];
3041 u32 alwaysOn[2];
3042
3043 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0xffffffff;
3044 if (dev->flags & IFF_ALLMULTI) {
3045 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0;
3046 } else {
Jiri Pirko22bedad32010-04-01 21:22:57 +00003047 struct netdev_hw_addr *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003048
Jiri Pirko22bedad32010-04-01 21:22:57 +00003049 netdev_for_each_mc_addr(ha, dev) {
david decotignye45a6182011-11-05 14:38:24 +00003050 unsigned char *hw_addr = ha->addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003051 u32 a, b;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003052
david decotignye45a6182011-11-05 14:38:24 +00003053 a = le32_to_cpu(*(__le32 *) hw_addr);
3054 b = le16_to_cpu(*(__le16 *) (&hw_addr[4]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 alwaysOn[0] &= a;
3056 alwaysOff[0] &= ~a;
3057 alwaysOn[1] &= b;
3058 alwaysOff[1] &= ~b;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003059 }
3060 }
3061 addr[0] = alwaysOn[0];
3062 addr[1] = alwaysOn[1];
3063 mask[0] = alwaysOn[0] | alwaysOff[0];
3064 mask[1] = alwaysOn[1] | alwaysOff[1];
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -05003065 } else {
3066 mask[0] = NVREG_MCASTMASKA_NONE;
3067 mask[1] = NVREG_MCASTMASKB_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 }
3069 }
3070 addr[0] |= NVREG_MCASTADDRA_FORCE;
3071 pff |= NVREG_PFF_ALWAYS;
3072 spin_lock_irq(&np->lock);
3073 nv_stop_rx(dev);
3074 writel(addr[0], base + NvRegMulticastAddrA);
3075 writel(addr[1], base + NvRegMulticastAddrB);
3076 writel(mask[0], base + NvRegMulticastMaskA);
3077 writel(mask[1], base + NvRegMulticastMaskB);
3078 writel(pff, base + NvRegPacketFilterFlags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 nv_start_rx(dev);
3080 spin_unlock_irq(&np->lock);
3081}
3082
Adrian Bunkc7985052006-06-22 12:03:29 +02003083static void nv_update_pause(struct net_device *dev, u32 pause_flags)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003084{
3085 struct fe_priv *np = netdev_priv(dev);
3086 u8 __iomem *base = get_hwbase(dev);
3087
3088 np->pause_flags &= ~(NV_PAUSEFRAME_TX_ENABLE | NV_PAUSEFRAME_RX_ENABLE);
3089
3090 if (np->pause_flags & NV_PAUSEFRAME_RX_CAPABLE) {
3091 u32 pff = readl(base + NvRegPacketFilterFlags) & ~NVREG_PFF_PAUSE_RX;
3092 if (pause_flags & NV_PAUSEFRAME_RX_ENABLE) {
3093 writel(pff|NVREG_PFF_PAUSE_RX, base + NvRegPacketFilterFlags);
3094 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3095 } else {
3096 writel(pff, base + NvRegPacketFilterFlags);
3097 }
3098 }
3099 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE) {
3100 u32 regmisc = readl(base + NvRegMisc1) & ~NVREG_MISC1_PAUSE_TX;
3101 if (pause_flags & NV_PAUSEFRAME_TX_ENABLE) {
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05003102 u32 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V1;
3103 if (np->driver_data & DEV_HAS_PAUSEFRAME_TX_V2)
3104 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V2;
Ayaz Abdulla9a33e882008-08-06 12:12:34 -04003105 if (np->driver_data & DEV_HAS_PAUSEFRAME_TX_V3) {
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05003106 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V3;
Ayaz Abdulla9a33e882008-08-06 12:12:34 -04003107 /* limit the number of tx pause frames to a default of 8 */
3108 writel(readl(base + NvRegTxPauseFrameLimit)|NVREG_TX_PAUSEFRAMELIMIT_ENABLE, base + NvRegTxPauseFrameLimit);
3109 }
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05003110 writel(pause_enable, base + NvRegTxPauseFrame);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003111 writel(regmisc|NVREG_MISC1_PAUSE_TX, base + NvRegMisc1);
3112 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3113 } else {
3114 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
3115 writel(regmisc, base + NvRegMisc1);
3116 }
3117 }
3118}
3119
Sanjay Hortikare19df762011-11-11 16:11:21 +00003120static void nv_force_linkspeed(struct net_device *dev, int speed, int duplex)
3121{
3122 struct fe_priv *np = netdev_priv(dev);
3123 u8 __iomem *base = get_hwbase(dev);
3124 u32 phyreg, txreg;
3125 int mii_status;
3126
3127 np->linkspeed = NVREG_LINKSPEED_FORCE|speed;
3128 np->duplex = duplex;
3129
3130 /* see if gigabit phy */
3131 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
3132 if (mii_status & PHY_GIGABIT) {
3133 np->gigabit = PHY_GIGABIT;
3134 phyreg = readl(base + NvRegSlotTime);
3135 phyreg &= ~(0x3FF00);
3136 if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10)
3137 phyreg |= NVREG_SLOTTIME_10_100_FULL;
3138 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100)
3139 phyreg |= NVREG_SLOTTIME_10_100_FULL;
3140 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000)
3141 phyreg |= NVREG_SLOTTIME_1000_FULL;
3142 writel(phyreg, base + NvRegSlotTime);
3143 }
3144
3145 phyreg = readl(base + NvRegPhyInterface);
3146 phyreg &= ~(PHY_HALF|PHY_100|PHY_1000);
3147 if (np->duplex == 0)
3148 phyreg |= PHY_HALF;
3149 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100)
3150 phyreg |= PHY_100;
3151 else if ((np->linkspeed & NVREG_LINKSPEED_MASK) ==
3152 NVREG_LINKSPEED_1000)
3153 phyreg |= PHY_1000;
3154 writel(phyreg, base + NvRegPhyInterface);
3155
3156 if (phyreg & PHY_RGMII) {
3157 if ((np->linkspeed & NVREG_LINKSPEED_MASK) ==
3158 NVREG_LINKSPEED_1000)
3159 txreg = NVREG_TX_DEFERRAL_RGMII_1000;
3160 else
3161 txreg = NVREG_TX_DEFERRAL_RGMII_10_100;
3162 } else {
3163 txreg = NVREG_TX_DEFERRAL_DEFAULT;
3164 }
3165 writel(txreg, base + NvRegTxDeferral);
3166
3167 if (np->desc_ver == DESC_VER_1) {
3168 txreg = NVREG_TX_WM_DESC1_DEFAULT;
3169 } else {
3170 if ((np->linkspeed & NVREG_LINKSPEED_MASK) ==
3171 NVREG_LINKSPEED_1000)
3172 txreg = NVREG_TX_WM_DESC2_3_1000;
3173 else
3174 txreg = NVREG_TX_WM_DESC2_3_DEFAULT;
3175 }
3176 writel(txreg, base + NvRegTxWatermark);
3177
3178 writel(NVREG_MISC1_FORCE | (np->duplex ? 0 : NVREG_MISC1_HD),
3179 base + NvRegMisc1);
3180 pci_push(base);
3181 writel(np->linkspeed, base + NvRegLinkSpeed);
3182 pci_push(base);
3183
3184 return;
3185}
3186
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05003187/**
3188 * nv_update_linkspeed: Setup the MAC according to the link partner
3189 * @dev: Network device to be configured
3190 *
3191 * The function queries the PHY and checks if there is a link partner.
3192 * If yes, then it sets up the MAC accordingly. Otherwise, the MAC is
3193 * set to 10 MBit HD.
3194 *
3195 * The function returns 0 if there is no link partner and 1 if there is
3196 * a good link partner.
3197 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003198static int nv_update_linkspeed(struct net_device *dev)
3199{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003200 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003201 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003202 int adv = 0;
3203 int lpa = 0;
3204 int adv_lpa, adv_pause, lpa_pause;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 int newls = np->linkspeed;
3206 int newdup = np->duplex;
3207 int mii_status;
Sanjay Hortikare19df762011-11-11 16:11:21 +00003208 u32 bmcr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003209 int retval = 0;
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003210 u32 control_1000, status_1000, phyreg, pause_flags, txreg;
Ayaz Abdullab2976d22008-02-04 15:13:59 -05003211 u32 txrxFlags = 0;
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003212 u32 phy_exp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003213
Sanjay Hortikare19df762011-11-11 16:11:21 +00003214 /* If device loopback is enabled, set carrier on and enable max link
3215 * speed.
3216 */
3217 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
3218 if (bmcr & BMCR_LOOPBACK) {
3219 if (netif_running(dev)) {
3220 nv_force_linkspeed(dev, NVREG_LINKSPEED_1000, 1);
3221 if (!netif_carrier_ok(dev))
3222 netif_carrier_on(dev);
3223 }
3224 return 1;
3225 }
3226
Linus Torvalds1da177e2005-04-16 15:20:36 -07003227 /* BMSR_LSTATUS is latched, read it twice:
3228 * we want the current value.
3229 */
3230 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
3231 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
3232
3233 if (!(mii_status & BMSR_LSTATUS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003234 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3235 newdup = 0;
3236 retval = 0;
3237 goto set_speed;
3238 }
3239
3240 if (np->autoneg == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 if (np->fixed_mode & LPA_100FULL) {
3242 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3243 newdup = 1;
3244 } else if (np->fixed_mode & LPA_100HALF) {
3245 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3246 newdup = 0;
3247 } else if (np->fixed_mode & LPA_10FULL) {
3248 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3249 newdup = 1;
3250 } else {
3251 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3252 newdup = 0;
3253 }
3254 retval = 1;
3255 goto set_speed;
3256 }
3257 /* check auto negotiation is complete */
3258 if (!(mii_status & BMSR_ANEGCOMPLETE)) {
3259 /* still in autonegotiation - configure nic for 10 MBit HD and wait. */
3260 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3261 newdup = 0;
3262 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003263 goto set_speed;
3264 }
3265
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003266 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
3267 lpa = mii_rw(dev, np->phyaddr, MII_LPA, MII_READ);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003268
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 retval = 1;
3270 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003271 control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
3272 status_1000 = mii_rw(dev, np->phyaddr, MII_STAT1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003273
3274 if ((control_1000 & ADVERTISE_1000FULL) &&
3275 (status_1000 & LPA_1000FULL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003276 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_1000;
3277 newdup = 1;
3278 goto set_speed;
3279 }
3280 }
3281
Linus Torvalds1da177e2005-04-16 15:20:36 -07003282 /* FIXME: handle parallel detection properly */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003283 adv_lpa = lpa & adv;
3284 if (adv_lpa & LPA_100FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003285 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3286 newdup = 1;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003287 } else if (adv_lpa & LPA_100HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003288 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3289 newdup = 0;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003290 } else if (adv_lpa & LPA_10FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3292 newdup = 1;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003293 } else if (adv_lpa & LPA_10HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003294 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3295 newdup = 0;
3296 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3298 newdup = 0;
3299 }
3300
3301set_speed:
3302 if (np->duplex == newdup && np->linkspeed == newls)
3303 return retval;
3304
Linus Torvalds1da177e2005-04-16 15:20:36 -07003305 np->duplex = newdup;
3306 np->linkspeed = newls;
3307
Ayaz Abdullab2976d22008-02-04 15:13:59 -05003308 /* The transmitter and receiver must be restarted for safe update */
3309 if (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_START) {
3310 txrxFlags |= NV_RESTART_TX;
3311 nv_stop_tx(dev);
3312 }
3313 if (readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) {
3314 txrxFlags |= NV_RESTART_RX;
3315 nv_stop_rx(dev);
3316 }
3317
Linus Torvalds1da177e2005-04-16 15:20:36 -07003318 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaa4336862008-04-18 13:50:43 -07003319 phyreg = readl(base + NvRegSlotTime);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003320 phyreg &= ~(0x3FF00);
Ayaz Abdullaa4336862008-04-18 13:50:43 -07003321 if (((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10) ||
3322 ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100))
3323 phyreg |= NVREG_SLOTTIME_10_100_FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003324 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000)
Ayaz Abdullaa4336862008-04-18 13:50:43 -07003325 phyreg |= NVREG_SLOTTIME_1000_FULL;
3326 writel(phyreg, base + NvRegSlotTime);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003327 }
3328
3329 phyreg = readl(base + NvRegPhyInterface);
3330 phyreg &= ~(PHY_HALF|PHY_100|PHY_1000);
3331 if (np->duplex == 0)
3332 phyreg |= PHY_HALF;
3333 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100)
3334 phyreg |= PHY_100;
3335 else if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
3336 phyreg |= PHY_1000;
3337 writel(phyreg, base + NvRegPhyInterface);
3338
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003339 phy_exp = mii_rw(dev, np->phyaddr, MII_EXPANSION, MII_READ) & EXPANSION_NWAY; /* autoneg capable */
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003340 if (phyreg & PHY_RGMII) {
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003341 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000) {
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003342 txreg = NVREG_TX_DEFERRAL_RGMII_1000;
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003343 } else {
3344 if (!phy_exp && !np->duplex && (np->driver_data & DEV_HAS_COLLISION_FIX)) {
3345 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_10)
3346 txreg = NVREG_TX_DEFERRAL_RGMII_STRETCH_10;
3347 else
3348 txreg = NVREG_TX_DEFERRAL_RGMII_STRETCH_100;
3349 } else {
3350 txreg = NVREG_TX_DEFERRAL_RGMII_10_100;
3351 }
3352 }
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003353 } else {
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003354 if (!phy_exp && !np->duplex && (np->driver_data & DEV_HAS_COLLISION_FIX))
3355 txreg = NVREG_TX_DEFERRAL_MII_STRETCH;
3356 else
3357 txreg = NVREG_TX_DEFERRAL_DEFAULT;
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003358 }
3359 writel(txreg, base + NvRegTxDeferral);
3360
Ayaz Abdulla95d161c2006-07-06 16:46:25 -04003361 if (np->desc_ver == DESC_VER_1) {
3362 txreg = NVREG_TX_WM_DESC1_DEFAULT;
3363 } else {
3364 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
3365 txreg = NVREG_TX_WM_DESC2_3_1000;
3366 else
3367 txreg = NVREG_TX_WM_DESC2_3_DEFAULT;
3368 }
3369 writel(txreg, base + NvRegTxWatermark);
3370
Szymon Janc78aea4f2010-11-27 08:39:43 +00003371 writel(NVREG_MISC1_FORCE | (np->duplex ? 0 : NVREG_MISC1_HD),
Linus Torvalds1da177e2005-04-16 15:20:36 -07003372 base + NvRegMisc1);
3373 pci_push(base);
3374 writel(np->linkspeed, base + NvRegLinkSpeed);
3375 pci_push(base);
3376
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003377 pause_flags = 0;
3378 /* setup pause frame */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003379 if (np->duplex != 0) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003380 if (np->autoneg && np->pause_flags & NV_PAUSEFRAME_AUTONEG) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003381 adv_pause = adv & (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
3382 lpa_pause = lpa & (LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003383
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003384 switch (adv_pause) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003385 case ADVERTISE_PAUSE_CAP:
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003386 if (lpa_pause & LPA_PAUSE_CAP) {
3387 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3388 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
3389 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3390 }
3391 break;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003392 case ADVERTISE_PAUSE_ASYM:
Szymon Janc78aea4f2010-11-27 08:39:43 +00003393 if (lpa_pause == (LPA_PAUSE_CAP | LPA_PAUSE_ASYM))
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003394 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003395 break;
Szymon Janc78aea4f2010-11-27 08:39:43 +00003396 case ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM:
3397 if (lpa_pause & LPA_PAUSE_CAP) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003398 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3399 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
3400 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3401 }
3402 if (lpa_pause == LPA_PAUSE_ASYM)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003403 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003404 break;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003405 }
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003406 } else {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003407 pause_flags = np->pause_flags;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003408 }
3409 }
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003410 nv_update_pause(dev, pause_flags);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003411
Ayaz Abdullab2976d22008-02-04 15:13:59 -05003412 if (txrxFlags & NV_RESTART_TX)
3413 nv_start_tx(dev);
3414 if (txrxFlags & NV_RESTART_RX)
3415 nv_start_rx(dev);
3416
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417 return retval;
3418}
3419
3420static void nv_linkchange(struct net_device *dev)
3421{
3422 if (nv_update_linkspeed(dev)) {
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05003423 if (!netif_carrier_ok(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003424 netif_carrier_on(dev);
Joe Perches1d397f32010-11-29 07:41:57 +00003425 netdev_info(dev, "link up\n");
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00003426 nv_txrx_gate(dev, false);
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05003427 nv_start_rx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003429 } else {
3430 if (netif_carrier_ok(dev)) {
3431 netif_carrier_off(dev);
Joe Perches1d397f32010-11-29 07:41:57 +00003432 netdev_info(dev, "link down\n");
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00003433 nv_txrx_gate(dev, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434 nv_stop_rx(dev);
3435 }
3436 }
3437}
3438
3439static void nv_link_irq(struct net_device *dev)
3440{
3441 u8 __iomem *base = get_hwbase(dev);
3442 u32 miistat;
3443
3444 miistat = readl(base + NvRegMIIStatus);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05003445 writel(NVREG_MIISTAT_LINKCHANGE, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003446
3447 if (miistat & (NVREG_MIISTAT_LINKCHANGE))
3448 nv_linkchange(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003449}
3450
Ayaz Abdulla4db0ee172008-06-09 16:51:06 -07003451static void nv_msi_workaround(struct fe_priv *np)
3452{
3453
3454 /* Need to toggle the msi irq mask within the ethernet device,
3455 * otherwise, future interrupts will not be detected.
3456 */
3457 if (np->msi_flags & NV_MSI_ENABLED) {
3458 u8 __iomem *base = np->base;
3459
3460 writel(0, base + NvRegMSIIrqMask);
3461 writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask);
3462 }
3463}
3464
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003465static inline int nv_change_interrupt_mode(struct net_device *dev, int total_work)
3466{
3467 struct fe_priv *np = netdev_priv(dev);
3468
3469 if (optimization_mode == NV_OPTIMIZATION_MODE_DYNAMIC) {
3470 if (total_work > NV_DYNAMIC_THRESHOLD) {
3471 /* transition to poll based interrupts */
3472 np->quiet_count = 0;
3473 if (np->irqmask != NVREG_IRQMASK_CPU) {
3474 np->irqmask = NVREG_IRQMASK_CPU;
3475 return 1;
3476 }
3477 } else {
3478 if (np->quiet_count < NV_DYNAMIC_MAX_QUIET_COUNT) {
3479 np->quiet_count++;
3480 } else {
3481 /* reached a period of low activity, switch
3482 to per tx/rx packet interrupts */
3483 if (np->irqmask != NVREG_IRQMASK_THROUGHPUT) {
3484 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
3485 return 1;
3486 }
3487 }
3488 }
3489 }
3490 return 0;
3491}
3492
David Howells7d12e782006-10-05 14:55:46 +01003493static irqreturn_t nv_nic_irq(int foo, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003494{
3495 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003496 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003497 u8 __iomem *base = get_hwbase(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003498
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003499 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3500 np->events = readl(base + NvRegIrqStatus);
Ayaz Abdulla1b2bb762009-03-05 08:02:34 +00003501 writel(np->events, base + NvRegIrqStatus);
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003502 } else {
3503 np->events = readl(base + NvRegMSIXIrqStatus);
Ayaz Abdulla1b2bb762009-03-05 08:02:34 +00003504 writel(np->events, base + NvRegMSIXIrqStatus);
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003505 }
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003506 if (!(np->events & np->irqmask))
3507 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003508
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003509 nv_msi_workaround(np);
Ayaz Abdulla4db0ee172008-06-09 16:51:06 -07003510
Eric Dumazet78c29bd2009-07-02 04:04:45 +00003511 if (napi_schedule_prep(&np->napi)) {
3512 /*
3513 * Disable further irq's (msix not enabled with napi)
3514 */
3515 writel(0, base + NvRegIrqMask);
3516 __napi_schedule(&np->napi);
3517 }
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003518
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003519 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003520}
3521
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003522/**
3523 * All _optimized functions are used to help increase performance
3524 * (reduce CPU and increase throughput). They use descripter version 3,
3525 * compiler directives, and reduce memory accesses.
3526 */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003527static irqreturn_t nv_nic_irq_optimized(int foo, void *data)
3528{
3529 struct net_device *dev = (struct net_device *) data;
3530 struct fe_priv *np = netdev_priv(dev);
3531 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003532
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003533 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3534 np->events = readl(base + NvRegIrqStatus);
Ayaz Abdulla1b2bb762009-03-05 08:02:34 +00003535 writel(np->events, base + NvRegIrqStatus);
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003536 } else {
3537 np->events = readl(base + NvRegMSIXIrqStatus);
Ayaz Abdulla1b2bb762009-03-05 08:02:34 +00003538 writel(np->events, base + NvRegMSIXIrqStatus);
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003539 }
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003540 if (!(np->events & np->irqmask))
3541 return IRQ_NONE;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003542
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003543 nv_msi_workaround(np);
Ayaz Abdulla4db0ee172008-06-09 16:51:06 -07003544
Eric Dumazet78c29bd2009-07-02 04:04:45 +00003545 if (napi_schedule_prep(&np->napi)) {
3546 /*
3547 * Disable further irq's (msix not enabled with napi)
3548 */
3549 writel(0, base + NvRegIrqMask);
3550 __napi_schedule(&np->napi);
3551 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003552
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003553 return IRQ_HANDLED;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003554}
3555
David Howells7d12e782006-10-05 14:55:46 +01003556static irqreturn_t nv_nic_irq_tx(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003557{
3558 struct net_device *dev = (struct net_device *) data;
3559 struct fe_priv *np = netdev_priv(dev);
3560 u8 __iomem *base = get_hwbase(dev);
3561 u32 events;
3562 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003563 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003564
Szymon Janc78aea4f2010-11-27 08:39:43 +00003565 for (i = 0;; i++) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003566 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_TX_ALL;
Mike Ditto2a4e7a02011-11-05 14:38:21 +00003567 writel(events, base + NvRegMSIXIrqStatus);
3568 netdev_dbg(dev, "tx irq events: %08x\n", events);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003569 if (!(events & np->irqmask))
3570 break;
3571
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003572 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05003573 nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003574 spin_unlock_irqrestore(&np->lock, flags);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003575
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003576 if (unlikely(i > max_interrupt_work)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003577 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003578 /* disable interrupts on the nic */
3579 writel(NVREG_IRQ_TX_ALL, base + NvRegIrqMask);
3580 pci_push(base);
3581
3582 if (!np->in_shutdown) {
3583 np->nic_poll_irq |= NVREG_IRQ_TX_ALL;
3584 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3585 }
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003586 spin_unlock_irqrestore(&np->lock, flags);
Joe Perchesc20ec762010-11-29 07:42:02 +00003587 netdev_dbg(dev, "%s: too many iterations (%d)\n",
3588 __func__, i);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003589 break;
3590 }
3591
3592 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003593
3594 return IRQ_RETVAL(i);
3595}
3596
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003597static int nv_napi_poll(struct napi_struct *napi, int budget)
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003598{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003599 struct fe_priv *np = container_of(napi, struct fe_priv, napi);
3600 struct net_device *dev = np->dev;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003601 u8 __iomem *base = get_hwbase(dev);
Francois Romieud15e9c42006-12-17 23:03:15 +01003602 unsigned long flags;
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003603 int retcode;
Szymon Janc78aea4f2010-11-27 08:39:43 +00003604 int rx_count, tx_work = 0, rx_work = 0;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003605
stephen hemminger81a2e362010-04-28 08:25:28 +00003606 do {
3607 if (!nv_optimized(np)) {
3608 spin_lock_irqsave(&np->lock, flags);
3609 tx_work += nv_tx_done(dev, np->tx_ring_size);
3610 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003611
Tom Herbertd951f722010-05-05 18:15:21 +00003612 rx_count = nv_rx_process(dev, budget - rx_work);
stephen hemminger81a2e362010-04-28 08:25:28 +00003613 retcode = nv_alloc_rx(dev);
3614 } else {
3615 spin_lock_irqsave(&np->lock, flags);
3616 tx_work += nv_tx_done_optimized(dev, np->tx_ring_size);
3617 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003618
Tom Herbertd951f722010-05-05 18:15:21 +00003619 rx_count = nv_rx_process_optimized(dev,
3620 budget - rx_work);
stephen hemminger81a2e362010-04-28 08:25:28 +00003621 retcode = nv_alloc_rx_optimized(dev);
3622 }
3623 } while (retcode == 0 &&
3624 rx_count > 0 && (rx_work += rx_count) < budget);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003625
Ayaz Abdullae0379a12007-02-20 03:34:30 -05003626 if (retcode) {
Francois Romieud15e9c42006-12-17 23:03:15 +01003627 spin_lock_irqsave(&np->lock, flags);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003628 if (!np->in_shutdown)
3629 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Francois Romieud15e9c42006-12-17 23:03:15 +01003630 spin_unlock_irqrestore(&np->lock, flags);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003631 }
3632
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003633 nv_change_interrupt_mode(dev, tx_work + rx_work);
3634
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003635 if (unlikely(np->events & NVREG_IRQ_LINK)) {
3636 spin_lock_irqsave(&np->lock, flags);
3637 nv_link_irq(dev);
3638 spin_unlock_irqrestore(&np->lock, flags);
3639 }
3640 if (unlikely(np->need_linktimer && time_after(jiffies, np->link_timeout))) {
3641 spin_lock_irqsave(&np->lock, flags);
3642 nv_linkchange(dev);
3643 spin_unlock_irqrestore(&np->lock, flags);
3644 np->link_timeout = jiffies + LINK_TIMEOUT;
3645 }
3646 if (unlikely(np->events & NVREG_IRQ_RECOVER_ERROR)) {
3647 spin_lock_irqsave(&np->lock, flags);
3648 if (!np->in_shutdown) {
3649 np->nic_poll_irq = np->irqmask;
3650 np->recover_error = 1;
3651 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3652 }
3653 spin_unlock_irqrestore(&np->lock, flags);
David S. Miller6c2da9c2009-04-09 01:09:33 -07003654 napi_complete(napi);
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003655 return rx_work;
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003656 }
3657
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003658 if (rx_work < budget) {
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003659 /* re-enable interrupts
3660 (msix not enabled in napi) */
David S. Miller6c2da9c2009-04-09 01:09:33 -07003661 napi_complete(napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003662
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003663 writel(np->irqmask, base + NvRegIrqMask);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003664 }
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003665 return rx_work;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003666}
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003667
David Howells7d12e782006-10-05 14:55:46 +01003668static irqreturn_t nv_nic_irq_rx(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003669{
3670 struct net_device *dev = (struct net_device *) data;
3671 struct fe_priv *np = netdev_priv(dev);
3672 u8 __iomem *base = get_hwbase(dev);
3673 u32 events;
3674 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003675 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003676
Szymon Janc78aea4f2010-11-27 08:39:43 +00003677 for (i = 0;; i++) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003678 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
Mike Ditto2a4e7a02011-11-05 14:38:21 +00003679 writel(events, base + NvRegMSIXIrqStatus);
3680 netdev_dbg(dev, "rx irq events: %08x\n", events);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003681 if (!(events & np->irqmask))
3682 break;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003683
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003684 if (nv_rx_process_optimized(dev, RX_WORK_PER_LOOP)) {
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003685 if (unlikely(nv_alloc_rx_optimized(dev))) {
3686 spin_lock_irqsave(&np->lock, flags);
3687 if (!np->in_shutdown)
3688 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3689 spin_unlock_irqrestore(&np->lock, flags);
3690 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003691 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003692
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003693 if (unlikely(i > max_interrupt_work)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003694 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003695 /* disable interrupts on the nic */
3696 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
3697 pci_push(base);
3698
3699 if (!np->in_shutdown) {
3700 np->nic_poll_irq |= NVREG_IRQ_RX_ALL;
3701 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3702 }
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003703 spin_unlock_irqrestore(&np->lock, flags);
Joe Perchesc20ec762010-11-29 07:42:02 +00003704 netdev_dbg(dev, "%s: too many iterations (%d)\n",
3705 __func__, i);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003706 break;
3707 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003708 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003709
3710 return IRQ_RETVAL(i);
3711}
3712
David Howells7d12e782006-10-05 14:55:46 +01003713static irqreturn_t nv_nic_irq_other(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003714{
3715 struct net_device *dev = (struct net_device *) data;
3716 struct fe_priv *np = netdev_priv(dev);
3717 u8 __iomem *base = get_hwbase(dev);
3718 u32 events;
3719 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003720 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003721
Szymon Janc78aea4f2010-11-27 08:39:43 +00003722 for (i = 0;; i++) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003723 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_OTHER;
Mike Ditto2a4e7a02011-11-05 14:38:21 +00003724 writel(events, base + NvRegMSIXIrqStatus);
3725 netdev_dbg(dev, "irq events: %08x\n", events);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003726 if (!(events & np->irqmask))
3727 break;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003728
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05003729 /* check tx in case we reached max loop limit in tx isr */
3730 spin_lock_irqsave(&np->lock, flags);
3731 nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
3732 spin_unlock_irqrestore(&np->lock, flags);
3733
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003734 if (events & NVREG_IRQ_LINK) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003735 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003736 nv_link_irq(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003737 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003738 }
3739 if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003740 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003741 nv_linkchange(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003742 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003743 np->link_timeout = jiffies + LINK_TIMEOUT;
3744 }
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003745 if (events & NVREG_IRQ_RECOVER_ERROR) {
3746 spin_lock_irq(&np->lock);
3747 /* disable interrupts on the nic */
3748 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
3749 pci_push(base);
3750
3751 if (!np->in_shutdown) {
3752 np->nic_poll_irq |= NVREG_IRQ_OTHER;
3753 np->recover_error = 1;
3754 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3755 }
3756 spin_unlock_irq(&np->lock);
3757 break;
3758 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003759 if (unlikely(i > max_interrupt_work)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003760 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003761 /* disable interrupts on the nic */
3762 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
3763 pci_push(base);
3764
3765 if (!np->in_shutdown) {
3766 np->nic_poll_irq |= NVREG_IRQ_OTHER;
3767 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3768 }
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003769 spin_unlock_irqrestore(&np->lock, flags);
Joe Perchesc20ec762010-11-29 07:42:02 +00003770 netdev_dbg(dev, "%s: too many iterations (%d)\n",
3771 __func__, i);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003772 break;
3773 }
3774
3775 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003776
3777 return IRQ_RETVAL(i);
3778}
3779
David Howells7d12e782006-10-05 14:55:46 +01003780static irqreturn_t nv_nic_irq_test(int foo, void *data)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003781{
3782 struct net_device *dev = (struct net_device *) data;
3783 struct fe_priv *np = netdev_priv(dev);
3784 u8 __iomem *base = get_hwbase(dev);
3785 u32 events;
3786
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003787 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3788 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
Mike Ditto2a4e7a02011-11-05 14:38:21 +00003789 writel(events & NVREG_IRQ_TIMER, base + NvRegIrqStatus);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003790 } else {
3791 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
Mike Ditto2a4e7a02011-11-05 14:38:21 +00003792 writel(events & NVREG_IRQ_TIMER, base + NvRegMSIXIrqStatus);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003793 }
3794 pci_push(base);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003795 if (!(events & NVREG_IRQ_TIMER))
3796 return IRQ_RETVAL(0);
3797
Ayaz Abdulla4db0ee172008-06-09 16:51:06 -07003798 nv_msi_workaround(np);
3799
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003800 spin_lock(&np->lock);
3801 np->intr_test = 1;
3802 spin_unlock(&np->lock);
3803
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003804 return IRQ_RETVAL(1);
3805}
3806
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003807static void set_msix_vector_map(struct net_device *dev, u32 vector, u32 irqmask)
3808{
3809 u8 __iomem *base = get_hwbase(dev);
3810 int i;
3811 u32 msixmap = 0;
3812
3813 /* Each interrupt bit can be mapped to a MSIX vector (4 bits).
3814 * MSIXMap0 represents the first 8 interrupts and MSIXMap1 represents
3815 * the remaining 8 interrupts.
3816 */
3817 for (i = 0; i < 8; i++) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003818 if ((irqmask >> i) & 0x1)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003819 msixmap |= vector << (i << 2);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003820 }
3821 writel(readl(base + NvRegMSIXMap0) | msixmap, base + NvRegMSIXMap0);
3822
3823 msixmap = 0;
3824 for (i = 0; i < 8; i++) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003825 if ((irqmask >> (i + 8)) & 0x1)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003826 msixmap |= vector << (i << 2);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003827 }
3828 writel(readl(base + NvRegMSIXMap1) | msixmap, base + NvRegMSIXMap1);
3829}
3830
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003831static int nv_request_irq(struct net_device *dev, int intr_test)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003832{
3833 struct fe_priv *np = get_nvpriv(dev);
3834 u8 __iomem *base = get_hwbase(dev);
3835 int ret = 1;
3836 int i;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003837 irqreturn_t (*handler)(int foo, void *data);
3838
3839 if (intr_test) {
3840 handler = nv_nic_irq_test;
3841 } else {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04003842 if (nv_optimized(np))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003843 handler = nv_nic_irq_optimized;
3844 else
3845 handler = nv_nic_irq;
3846 }
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003847
3848 if (np->msi_flags & NV_MSI_X_CAPABLE) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003849 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003850 np->msi_x_entry[i].entry = i;
Szymon Janc34cf97e2010-11-27 08:39:46 +00003851 ret = pci_enable_msix(np->pci_dev, np->msi_x_entry, (np->msi_flags & NV_MSI_X_VECTORS_MASK));
3852 if (ret == 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003853 np->msi_flags |= NV_MSI_X_ENABLED;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003854 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT && !intr_test) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003855 /* Request irq for rx handling */
Yinghai Luddb213f2009-02-06 01:29:23 -08003856 sprintf(np->name_rx, "%s-rx", dev->name);
3857 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08003858 nv_nic_irq_rx, IRQF_SHARED, np->name_rx, dev) != 0) {
Joe Perches1d397f32010-11-29 07:41:57 +00003859 netdev_info(dev,
3860 "request_irq failed for rx %d\n",
3861 ret);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003862 pci_disable_msix(np->pci_dev);
3863 np->msi_flags &= ~NV_MSI_X_ENABLED;
3864 goto out_err;
3865 }
3866 /* Request irq for tx handling */
Yinghai Luddb213f2009-02-06 01:29:23 -08003867 sprintf(np->name_tx, "%s-tx", dev->name);
3868 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08003869 nv_nic_irq_tx, IRQF_SHARED, np->name_tx, dev) != 0) {
Joe Perches1d397f32010-11-29 07:41:57 +00003870 netdev_info(dev,
3871 "request_irq failed for tx %d\n",
3872 ret);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003873 pci_disable_msix(np->pci_dev);
3874 np->msi_flags &= ~NV_MSI_X_ENABLED;
3875 goto out_free_rx;
3876 }
3877 /* Request irq for link and timer handling */
Yinghai Luddb213f2009-02-06 01:29:23 -08003878 sprintf(np->name_other, "%s-other", dev->name);
3879 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08003880 nv_nic_irq_other, IRQF_SHARED, np->name_other, dev) != 0) {
Joe Perches1d397f32010-11-29 07:41:57 +00003881 netdev_info(dev,
3882 "request_irq failed for link %d\n",
3883 ret);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003884 pci_disable_msix(np->pci_dev);
3885 np->msi_flags &= ~NV_MSI_X_ENABLED;
3886 goto out_free_tx;
3887 }
3888 /* map interrupts to their respective vector */
3889 writel(0, base + NvRegMSIXMap0);
3890 writel(0, base + NvRegMSIXMap1);
3891 set_msix_vector_map(dev, NV_MSI_X_VECTOR_RX, NVREG_IRQ_RX_ALL);
3892 set_msix_vector_map(dev, NV_MSI_X_VECTOR_TX, NVREG_IRQ_TX_ALL);
3893 set_msix_vector_map(dev, NV_MSI_X_VECTOR_OTHER, NVREG_IRQ_OTHER);
3894 } else {
3895 /* Request irq for all interrupts */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003896 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 +00003897 netdev_info(dev,
3898 "request_irq failed %d\n",
3899 ret);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003900 pci_disable_msix(np->pci_dev);
3901 np->msi_flags &= ~NV_MSI_X_ENABLED;
3902 goto out_err;
3903 }
3904
3905 /* map interrupts to vector 0 */
3906 writel(0, base + NvRegMSIXMap0);
3907 writel(0, base + NvRegMSIXMap1);
3908 }
Mike Ditto89328782011-11-16 12:15:11 +00003909 netdev_info(dev, "MSI-X enabled\n");
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003910 }
3911 }
3912 if (ret != 0 && np->msi_flags & NV_MSI_CAPABLE) {
Szymon Janc34cf97e2010-11-27 08:39:46 +00003913 ret = pci_enable_msi(np->pci_dev);
3914 if (ret == 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003915 np->msi_flags |= NV_MSI_ENABLED;
Manfred Spraula7475902007-10-17 21:52:33 +02003916 dev->irq = np->pci_dev->irq;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003917 if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0) {
Joe Perches1d397f32010-11-29 07:41:57 +00003918 netdev_info(dev, "request_irq failed %d\n",
3919 ret);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003920 pci_disable_msi(np->pci_dev);
3921 np->msi_flags &= ~NV_MSI_ENABLED;
Manfred Spraula7475902007-10-17 21:52:33 +02003922 dev->irq = np->pci_dev->irq;
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003923 goto out_err;
3924 }
3925
3926 /* map interrupts to vector 0 */
3927 writel(0, base + NvRegMSIMap0);
3928 writel(0, base + NvRegMSIMap1);
3929 /* enable msi vector 0 */
3930 writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask);
Mike Ditto89328782011-11-16 12:15:11 +00003931 netdev_info(dev, "MSI enabled\n");
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003932 }
3933 }
3934 if (ret != 0) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003935 if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003936 goto out_err;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003937
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003938 }
3939
3940 return 0;
3941out_free_tx:
3942 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector, dev);
3943out_free_rx:
3944 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector, dev);
3945out_err:
3946 return 1;
3947}
3948
3949static void nv_free_irq(struct net_device *dev)
3950{
3951 struct fe_priv *np = get_nvpriv(dev);
3952 int i;
3953
3954 if (np->msi_flags & NV_MSI_X_ENABLED) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003955 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003956 free_irq(np->msi_x_entry[i].vector, dev);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003957 pci_disable_msix(np->pci_dev);
3958 np->msi_flags &= ~NV_MSI_X_ENABLED;
3959 } else {
3960 free_irq(np->pci_dev->irq, dev);
3961 if (np->msi_flags & NV_MSI_ENABLED) {
3962 pci_disable_msi(np->pci_dev);
3963 np->msi_flags &= ~NV_MSI_ENABLED;
3964 }
3965 }
3966}
3967
Linus Torvalds1da177e2005-04-16 15:20:36 -07003968static void nv_do_nic_poll(unsigned long data)
3969{
3970 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003971 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003972 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003973 u32 mask = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003974
Linus Torvalds1da177e2005-04-16 15:20:36 -07003975 /*
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003976 * First disable irq(s) and then
Linus Torvalds1da177e2005-04-16 15:20:36 -07003977 * reenable interrupts on the nic, we have to do this before calling
3978 * nv_nic_irq because that may decide to do otherwise
3979 */
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003980
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003981 if (!using_multi_irqs(dev)) {
3982 if (np->msi_flags & NV_MSI_X_ENABLED)
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003983 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003984 else
Manfred Spraula7475902007-10-17 21:52:33 +02003985 disable_irq_lockdep(np->pci_dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003986 mask = np->irqmask;
3987 } else {
3988 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003989 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003990 mask |= NVREG_IRQ_RX_ALL;
3991 }
3992 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003993 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003994 mask |= NVREG_IRQ_TX_ALL;
3995 }
3996 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003997 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003998 mask |= NVREG_IRQ_OTHER;
3999 }
4000 }
Manfred Spraula7475902007-10-17 21:52:33 +02004001 /* disable_irq() contains synchronize_irq, thus no irq handler can run now */
4002
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004003 if (np->recover_error) {
4004 np->recover_error = 0;
Joe Perches1d397f32010-11-29 07:41:57 +00004005 netdev_info(dev, "MAC in recoverable error state\n");
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004006 if (netif_running(dev)) {
4007 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004008 netif_addr_lock(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004009 spin_lock(&np->lock);
4010 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004011 nv_stop_rxtx(dev);
Ayaz Abdulladaa91a92009-02-07 00:25:00 -08004012 if (np->driver_data & DEV_HAS_POWER_CNTRL)
4013 nv_mac_reset(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004014 nv_txrx_reset(dev);
4015 /* drain rx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004016 nv_drain_rxtx(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004017 /* reinit driver view of the rx queue */
4018 set_bufsize(dev);
4019 if (nv_init_ring(dev)) {
4020 if (!np->in_shutdown)
4021 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
4022 }
4023 /* reinit nic view of the rx queue */
4024 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4025 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00004026 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004027 base + NvRegRingSizes);
4028 pci_push(base);
4029 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4030 pci_push(base);
Ayaz Abdulladaa91a92009-02-07 00:25:00 -08004031 /* clear interrupts */
4032 if (!(np->msi_flags & NV_MSI_X_ENABLED))
4033 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4034 else
4035 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004036
4037 /* restart rx engine */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004038 nv_start_rxtx(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004039 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07004040 netif_addr_unlock(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004041 netif_tx_unlock_bh(dev);
4042 }
4043 }
4044
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004045 writel(mask, base + NvRegIrqMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004046 pci_push(base);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004047
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004048 if (!using_multi_irqs(dev)) {
Yinghai Lu79d30a52009-02-06 01:30:01 -08004049 np->nic_poll_irq = 0;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004050 if (nv_optimized(np))
Ayaz Abdullafcc5f262007-03-23 05:49:37 -05004051 nv_nic_irq_optimized(0, dev);
4052 else
4053 nv_nic_irq(0, dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004054 if (np->msi_flags & NV_MSI_X_ENABLED)
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004055 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004056 else
Manfred Spraula7475902007-10-17 21:52:33 +02004057 enable_irq_lockdep(np->pci_dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004058 } else {
4059 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
Yinghai Lu79d30a52009-02-06 01:30:01 -08004060 np->nic_poll_irq &= ~NVREG_IRQ_RX_ALL;
David Howells7d12e782006-10-05 14:55:46 +01004061 nv_nic_irq_rx(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004062 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004063 }
4064 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
Yinghai Lu79d30a52009-02-06 01:30:01 -08004065 np->nic_poll_irq &= ~NVREG_IRQ_TX_ALL;
David Howells7d12e782006-10-05 14:55:46 +01004066 nv_nic_irq_tx(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004067 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004068 }
4069 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
Yinghai Lu79d30a52009-02-06 01:30:01 -08004070 np->nic_poll_irq &= ~NVREG_IRQ_OTHER;
David Howells7d12e782006-10-05 14:55:46 +01004071 nv_nic_irq_other(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004072 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004073 }
4074 }
Yinghai Lu79d30a52009-02-06 01:30:01 -08004075
Linus Torvalds1da177e2005-04-16 15:20:36 -07004076}
4077
Michal Schmidt2918c352005-05-12 19:42:06 -04004078#ifdef CONFIG_NET_POLL_CONTROLLER
4079static void nv_poll_controller(struct net_device *dev)
4080{
4081 nv_do_nic_poll((unsigned long) dev);
4082}
4083#endif
4084
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004085static void nv_do_stats_poll(unsigned long data)
david decotignyf5d827a2011-11-16 12:15:13 +00004086 __acquires(&netdev_priv(dev)->hwstats_lock)
4087 __releases(&netdev_priv(dev)->hwstats_lock)
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004088{
4089 struct net_device *dev = (struct net_device *) data;
4090 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004091
david decotignyf5d827a2011-11-16 12:15:13 +00004092 /* If lock is currently taken, the stats are being refreshed
4093 * and hence fresh enough */
4094 if (spin_trylock(&np->hwstats_lock)) {
4095 nv_update_stats(dev);
4096 spin_unlock(&np->hwstats_lock);
4097 }
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004098
4099 if (!np->in_shutdown)
Daniel Drakebfebbb82008-03-18 11:07:18 +00004100 mod_timer(&np->stats_poll,
4101 round_jiffies(jiffies + STATS_INTERVAL));
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004102}
4103
Linus Torvalds1da177e2005-04-16 15:20:36 -07004104static void nv_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
4105{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004106 struct fe_priv *np = netdev_priv(dev);
Rick Jones68aad782011-11-07 13:29:27 +00004107 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
4108 strlcpy(info->version, FORCEDETH_VERSION, sizeof(info->version));
4109 strlcpy(info->bus_info, pci_name(np->pci_dev), sizeof(info->bus_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004110}
4111
4112static void nv_get_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
4113{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004114 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004115 wolinfo->supported = WAKE_MAGIC;
4116
4117 spin_lock_irq(&np->lock);
4118 if (np->wolenabled)
4119 wolinfo->wolopts = WAKE_MAGIC;
4120 spin_unlock_irq(&np->lock);
4121}
4122
4123static int nv_set_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
4124{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004125 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004126 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004127 u32 flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004128
Linus Torvalds1da177e2005-04-16 15:20:36 -07004129 if (wolinfo->wolopts == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004130 np->wolenabled = 0;
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004131 } else if (wolinfo->wolopts & WAKE_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132 np->wolenabled = 1;
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004133 flags = NVREG_WAKEUPFLAGS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004134 }
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004135 if (netif_running(dev)) {
4136 spin_lock_irq(&np->lock);
4137 writel(flags, base + NvRegWakeUpFlags);
4138 spin_unlock_irq(&np->lock);
4139 }
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00004140 device_set_wakeup_enable(&np->pci_dev->dev, np->wolenabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004141 return 0;
4142}
4143
4144static int nv_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
4145{
4146 struct fe_priv *np = netdev_priv(dev);
David Decotigny70739492011-04-27 18:32:40 +00004147 u32 speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004148 int adv;
4149
4150 spin_lock_irq(&np->lock);
4151 ecmd->port = PORT_MII;
4152 if (!netif_running(dev)) {
4153 /* We do not track link speed / duplex setting if the
4154 * interface is disabled. Force a link check */
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004155 if (nv_update_linkspeed(dev)) {
4156 if (!netif_carrier_ok(dev))
4157 netif_carrier_on(dev);
4158 } else {
4159 if (netif_carrier_ok(dev))
4160 netif_carrier_off(dev);
4161 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162 }
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004163
4164 if (netif_carrier_ok(dev)) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00004165 switch (np->linkspeed & (NVREG_LINKSPEED_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004166 case NVREG_LINKSPEED_10:
David Decotigny70739492011-04-27 18:32:40 +00004167 speed = SPEED_10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004168 break;
4169 case NVREG_LINKSPEED_100:
David Decotigny70739492011-04-27 18:32:40 +00004170 speed = SPEED_100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004171 break;
4172 case NVREG_LINKSPEED_1000:
David Decotigny70739492011-04-27 18:32:40 +00004173 speed = SPEED_1000;
4174 break;
4175 default:
4176 speed = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004177 break;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004178 }
4179 ecmd->duplex = DUPLEX_HALF;
4180 if (np->duplex)
4181 ecmd->duplex = DUPLEX_FULL;
4182 } else {
David Decotigny70739492011-04-27 18:32:40 +00004183 speed = -1;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004184 ecmd->duplex = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004185 }
David Decotigny70739492011-04-27 18:32:40 +00004186 ethtool_cmd_speed_set(ecmd, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004187 ecmd->autoneg = np->autoneg;
4188
4189 ecmd->advertising = ADVERTISED_MII;
4190 if (np->autoneg) {
4191 ecmd->advertising |= ADVERTISED_Autoneg;
4192 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004193 if (adv & ADVERTISE_10HALF)
4194 ecmd->advertising |= ADVERTISED_10baseT_Half;
4195 if (adv & ADVERTISE_10FULL)
4196 ecmd->advertising |= ADVERTISED_10baseT_Full;
4197 if (adv & ADVERTISE_100HALF)
4198 ecmd->advertising |= ADVERTISED_100baseT_Half;
4199 if (adv & ADVERTISE_100FULL)
4200 ecmd->advertising |= ADVERTISED_100baseT_Full;
4201 if (np->gigabit == PHY_GIGABIT) {
4202 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
4203 if (adv & ADVERTISE_1000FULL)
4204 ecmd->advertising |= ADVERTISED_1000baseT_Full;
4205 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004206 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004207 ecmd->supported = (SUPPORTED_Autoneg |
4208 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
4209 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
4210 SUPPORTED_MII);
4211 if (np->gigabit == PHY_GIGABIT)
4212 ecmd->supported |= SUPPORTED_1000baseT_Full;
4213
4214 ecmd->phy_address = np->phyaddr;
4215 ecmd->transceiver = XCVR_EXTERNAL;
4216
4217 /* ignore maxtxpkt, maxrxpkt for now */
4218 spin_unlock_irq(&np->lock);
4219 return 0;
4220}
4221
4222static int nv_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
4223{
4224 struct fe_priv *np = netdev_priv(dev);
David Decotigny25db0332011-04-27 18:32:39 +00004225 u32 speed = ethtool_cmd_speed(ecmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226
4227 if (ecmd->port != PORT_MII)
4228 return -EINVAL;
4229 if (ecmd->transceiver != XCVR_EXTERNAL)
4230 return -EINVAL;
4231 if (ecmd->phy_address != np->phyaddr) {
4232 /* TODO: support switching between multiple phys. Should be
4233 * trivial, but not enabled due to lack of test hardware. */
4234 return -EINVAL;
4235 }
4236 if (ecmd->autoneg == AUTONEG_ENABLE) {
4237 u32 mask;
4238
4239 mask = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
4240 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full;
4241 if (np->gigabit == PHY_GIGABIT)
4242 mask |= ADVERTISED_1000baseT_Full;
4243
4244 if ((ecmd->advertising & mask) == 0)
4245 return -EINVAL;
4246
4247 } else if (ecmd->autoneg == AUTONEG_DISABLE) {
4248 /* Note: autonegotiation disable, speed 1000 intentionally
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004249 * forbidden - no one should need that. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004250
David Decotigny25db0332011-04-27 18:32:39 +00004251 if (speed != SPEED_10 && speed != SPEED_100)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004252 return -EINVAL;
4253 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
4254 return -EINVAL;
4255 } else {
4256 return -EINVAL;
4257 }
4258
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004259 netif_carrier_off(dev);
4260 if (netif_running(dev)) {
Tobias Diedrich97bff092008-07-03 23:54:56 -07004261 unsigned long flags;
4262
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004263 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004264 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004265 netif_addr_lock(dev);
Tobias Diedrich97bff092008-07-03 23:54:56 -07004266 /* with plain spinlock lockdep complains */
4267 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004268 /* stop engines */
Tobias Diedrich97bff092008-07-03 23:54:56 -07004269 /* FIXME:
4270 * this can take some time, and interrupts are disabled
4271 * due to spin_lock_irqsave, but let's hope no daemon
4272 * is going to change the settings very often...
4273 * Worst case:
4274 * NV_RXSTOP_DELAY1MAX + NV_TXSTOP_DELAY1MAX
4275 * + some minor delays, which is up to a second approximately
4276 */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004277 nv_stop_rxtx(dev);
Tobias Diedrich97bff092008-07-03 23:54:56 -07004278 spin_unlock_irqrestore(&np->lock, flags);
David S. Millere308a5d2008-07-15 00:13:44 -07004279 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004280 netif_tx_unlock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004281 }
4282
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283 if (ecmd->autoneg == AUTONEG_ENABLE) {
4284 int adv, bmcr;
4285
4286 np->autoneg = 1;
4287
4288 /* advertise only what has been requested */
4289 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004290 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004291 if (ecmd->advertising & ADVERTISED_10baseT_Half)
4292 adv |= ADVERTISE_10HALF;
4293 if (ecmd->advertising & ADVERTISED_10baseT_Full)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004294 adv |= ADVERTISE_10FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004295 if (ecmd->advertising & ADVERTISED_100baseT_Half)
4296 adv |= ADVERTISE_100HALF;
4297 if (ecmd->advertising & ADVERTISED_100baseT_Full)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004298 adv |= ADVERTISE_100FULL;
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004299 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 -04004300 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4301 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
4302 adv |= ADVERTISE_PAUSE_ASYM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004303 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4304
4305 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004306 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004307 adv &= ~ADVERTISE_1000FULL;
4308 if (ecmd->advertising & ADVERTISED_1000baseT_Full)
4309 adv |= ADVERTISE_1000FULL;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004310 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311 }
4312
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004313 if (netif_running(dev))
Joe Perches1d397f32010-11-29 07:41:57 +00004314 netdev_info(dev, "link down\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004315 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004316 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
4317 bmcr |= BMCR_ANENABLE;
4318 /* reset the phy in order for settings to stick,
4319 * and cause autoneg to start */
4320 if (phy_reset(dev, bmcr)) {
Joe Perches1d397f32010-11-29 07:41:57 +00004321 netdev_info(dev, "phy reset failed\n");
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004322 return -EINVAL;
4323 }
4324 } else {
4325 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4326 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4327 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004328 } else {
4329 int adv, bmcr;
4330
4331 np->autoneg = 0;
4332
4333 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004334 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
David Decotigny25db0332011-04-27 18:32:39 +00004335 if (speed == SPEED_10 && ecmd->duplex == DUPLEX_HALF)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004336 adv |= ADVERTISE_10HALF;
David Decotigny25db0332011-04-27 18:32:39 +00004337 if (speed == SPEED_10 && ecmd->duplex == DUPLEX_FULL)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004338 adv |= ADVERTISE_10FULL;
David Decotigny25db0332011-04-27 18:32:39 +00004339 if (speed == SPEED_100 && ecmd->duplex == DUPLEX_HALF)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004340 adv |= ADVERTISE_100HALF;
David Decotigny25db0332011-04-27 18:32:39 +00004341 if (speed == SPEED_100 && ecmd->duplex == DUPLEX_FULL)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004342 adv |= ADVERTISE_100FULL;
4343 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004344 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 -04004345 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4346 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
4347 }
4348 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) {
4349 adv |= ADVERTISE_PAUSE_ASYM;
4350 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
4351 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004352 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4353 np->fixed_mode = adv;
4354
4355 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004356 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004357 adv &= ~ADVERTISE_1000FULL;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004358 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004359 }
4360
4361 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004362 bmcr &= ~(BMCR_ANENABLE|BMCR_SPEED100|BMCR_SPEED1000|BMCR_FULLDPLX);
4363 if (np->fixed_mode & (ADVERTISE_10FULL|ADVERTISE_100FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004364 bmcr |= BMCR_FULLDPLX;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004365 if (np->fixed_mode & (ADVERTISE_100HALF|ADVERTISE_100FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004366 bmcr |= BMCR_SPEED100;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004367 if (np->phy_oui == PHY_OUI_MARVELL) {
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004368 /* reset the phy in order for forced mode settings to stick */
4369 if (phy_reset(dev, bmcr)) {
Joe Perches1d397f32010-11-29 07:41:57 +00004370 netdev_info(dev, "phy reset failed\n");
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004371 return -EINVAL;
4372 }
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004373 } else {
4374 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4375 if (netif_running(dev)) {
4376 /* Wait a bit and then reconfigure the nic. */
4377 udelay(10);
4378 nv_linkchange(dev);
4379 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004380 }
4381 }
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004382
4383 if (netif_running(dev)) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004384 nv_start_rxtx(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004385 nv_enable_irq(dev);
4386 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004387
4388 return 0;
4389}
4390
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004391#define FORCEDETH_REGS_VER 1
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004392
4393static int nv_get_regs_len(struct net_device *dev)
4394{
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004395 struct fe_priv *np = netdev_priv(dev);
4396 return np->register_size;
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004397}
4398
4399static void nv_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *buf)
4400{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004401 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004402 u8 __iomem *base = get_hwbase(dev);
4403 u32 *rbuf = buf;
4404 int i;
4405
4406 regs->version = FORCEDETH_REGS_VER;
4407 spin_lock_irq(&np->lock);
Szymon Janc78aea4f2010-11-27 08:39:43 +00004408 for (i = 0; i <= np->register_size/sizeof(u32); i++)
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004409 rbuf[i] = readl(base + i*sizeof(u32));
4410 spin_unlock_irq(&np->lock);
4411}
4412
4413static int nv_nway_reset(struct net_device *dev)
4414{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004415 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004416 int ret;
4417
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004418 if (np->autoneg) {
4419 int bmcr;
4420
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004421 netif_carrier_off(dev);
4422 if (netif_running(dev)) {
4423 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004424 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004425 netif_addr_lock(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004426 spin_lock(&np->lock);
4427 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004428 nv_stop_rxtx(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004429 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07004430 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004431 netif_tx_unlock_bh(dev);
Joe Perches1d397f32010-11-29 07:41:57 +00004432 netdev_info(dev, "link down\n");
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004433 }
4434
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004435 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004436 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
4437 bmcr |= BMCR_ANENABLE;
4438 /* reset the phy in order for settings to stick*/
4439 if (phy_reset(dev, bmcr)) {
Joe Perches1d397f32010-11-29 07:41:57 +00004440 netdev_info(dev, "phy reset failed\n");
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004441 return -EINVAL;
4442 }
4443 } else {
4444 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4445 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4446 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004447
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004448 if (netif_running(dev)) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004449 nv_start_rxtx(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004450 nv_enable_irq(dev);
4451 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004452 ret = 0;
4453 } else {
4454 ret = -EINVAL;
4455 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004456
4457 return ret;
4458}
4459
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004460static void nv_get_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
4461{
4462 struct fe_priv *np = netdev_priv(dev);
4463
4464 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 -04004465 ring->tx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
4466
4467 ring->rx_pending = np->rx_ring_size;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004468 ring->tx_pending = np->tx_ring_size;
4469}
4470
4471static int nv_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
4472{
4473 struct fe_priv *np = netdev_priv(dev);
4474 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004475 u8 *rxtx_ring, *rx_skbuff, *tx_skbuff;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004476 dma_addr_t ring_addr;
4477
4478 if (ring->rx_pending < RX_RING_MIN ||
4479 ring->tx_pending < TX_RING_MIN ||
4480 ring->rx_mini_pending != 0 ||
4481 ring->rx_jumbo_pending != 0 ||
4482 (np->desc_ver == DESC_VER_1 &&
4483 (ring->rx_pending > RING_MAX_DESC_VER_1 ||
4484 ring->tx_pending > RING_MAX_DESC_VER_1)) ||
4485 (np->desc_ver != DESC_VER_1 &&
4486 (ring->rx_pending > RING_MAX_DESC_VER_2_3 ||
4487 ring->tx_pending > RING_MAX_DESC_VER_2_3))) {
4488 return -EINVAL;
4489 }
4490
4491 /* allocate new rings */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004492 if (!nv_optimized(np)) {
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004493 rxtx_ring = pci_alloc_consistent(np->pci_dev,
4494 sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
4495 &ring_addr);
4496 } else {
4497 rxtx_ring = pci_alloc_consistent(np->pci_dev,
4498 sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
4499 &ring_addr);
4500 }
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004501 rx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->rx_pending, GFP_KERNEL);
4502 tx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->tx_pending, GFP_KERNEL);
4503 if (!rxtx_ring || !rx_skbuff || !tx_skbuff) {
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004504 /* fall back to old rings */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004505 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004506 if (rxtx_ring)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004507 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
4508 rxtx_ring, ring_addr);
4509 } else {
4510 if (rxtx_ring)
4511 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
4512 rxtx_ring, ring_addr);
4513 }
Szymon Janc9b03b062010-11-27 08:39:44 +00004514
4515 kfree(rx_skbuff);
4516 kfree(tx_skbuff);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004517 goto exit;
4518 }
4519
4520 if (netif_running(dev)) {
4521 nv_disable_irq(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00004522 nv_napi_disable(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004523 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004524 netif_addr_lock(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004525 spin_lock(&np->lock);
4526 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004527 nv_stop_rxtx(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004528 nv_txrx_reset(dev);
4529 /* drain queues */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004530 nv_drain_rxtx(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004531 /* delete queues */
4532 free_rings(dev);
4533 }
4534
4535 /* set new values */
4536 np->rx_ring_size = ring->rx_pending;
4537 np->tx_ring_size = ring->tx_pending;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004538
4539 if (!nv_optimized(np)) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00004540 np->rx_ring.orig = (struct ring_desc *)rxtx_ring;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004541 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
4542 } else {
Szymon Janc78aea4f2010-11-27 08:39:43 +00004543 np->rx_ring.ex = (struct ring_desc_ex *)rxtx_ring;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004544 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
4545 }
Szymon Janc78aea4f2010-11-27 08:39:43 +00004546 np->rx_skb = (struct nv_skb_map *)rx_skbuff;
4547 np->tx_skb = (struct nv_skb_map *)tx_skbuff;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004548 np->ring_addr = ring_addr;
4549
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004550 memset(np->rx_skb, 0, sizeof(struct nv_skb_map) * np->rx_ring_size);
4551 memset(np->tx_skb, 0, sizeof(struct nv_skb_map) * np->tx_ring_size);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004552
4553 if (netif_running(dev)) {
4554 /* reinit driver view of the queues */
4555 set_bufsize(dev);
4556 if (nv_init_ring(dev)) {
4557 if (!np->in_shutdown)
4558 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
4559 }
4560
4561 /* reinit nic view of the queues */
4562 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4563 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00004564 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004565 base + NvRegRingSizes);
4566 pci_push(base);
4567 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4568 pci_push(base);
4569
4570 /* restart engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004571 nv_start_rxtx(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004572 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07004573 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004574 netif_tx_unlock_bh(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00004575 nv_napi_enable(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004576 nv_enable_irq(dev);
4577 }
4578 return 0;
4579exit:
4580 return -ENOMEM;
4581}
4582
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004583static void nv_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
4584{
4585 struct fe_priv *np = netdev_priv(dev);
4586
4587 pause->autoneg = (np->pause_flags & NV_PAUSEFRAME_AUTONEG) != 0;
4588 pause->rx_pause = (np->pause_flags & NV_PAUSEFRAME_RX_ENABLE) != 0;
4589 pause->tx_pause = (np->pause_flags & NV_PAUSEFRAME_TX_ENABLE) != 0;
4590}
4591
4592static int nv_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
4593{
4594 struct fe_priv *np = netdev_priv(dev);
4595 int adv, bmcr;
4596
4597 if ((!np->autoneg && np->duplex == 0) ||
4598 (np->autoneg && !pause->autoneg && np->duplex == 0)) {
Joe Perches1d397f32010-11-29 07:41:57 +00004599 netdev_info(dev, "can not set pause settings when forced link is in half duplex\n");
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004600 return -EINVAL;
4601 }
4602 if (pause->tx_pause && !(np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)) {
Joe Perches1d397f32010-11-29 07:41:57 +00004603 netdev_info(dev, "hardware does not support tx pause frames\n");
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004604 return -EINVAL;
4605 }
4606
4607 netif_carrier_off(dev);
4608 if (netif_running(dev)) {
4609 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004610 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004611 netif_addr_lock(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004612 spin_lock(&np->lock);
4613 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004614 nv_stop_rxtx(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004615 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07004616 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004617 netif_tx_unlock_bh(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004618 }
4619
4620 np->pause_flags &= ~(NV_PAUSEFRAME_RX_REQ|NV_PAUSEFRAME_TX_REQ);
4621 if (pause->rx_pause)
4622 np->pause_flags |= NV_PAUSEFRAME_RX_REQ;
4623 if (pause->tx_pause)
4624 np->pause_flags |= NV_PAUSEFRAME_TX_REQ;
4625
4626 if (np->autoneg && pause->autoneg) {
4627 np->pause_flags |= NV_PAUSEFRAME_AUTONEG;
4628
4629 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
4630 adv &= ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004631 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 -04004632 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4633 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
4634 adv |= ADVERTISE_PAUSE_ASYM;
4635 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4636
4637 if (netif_running(dev))
Joe Perches1d397f32010-11-29 07:41:57 +00004638 netdev_info(dev, "link down\n");
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004639 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
4640 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4641 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4642 } else {
4643 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
4644 if (pause->rx_pause)
4645 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
4646 if (pause->tx_pause)
4647 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
4648
4649 if (!netif_running(dev))
4650 nv_update_linkspeed(dev);
4651 else
4652 nv_update_pause(dev, np->pause_flags);
4653 }
4654
4655 if (netif_running(dev)) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004656 nv_start_rxtx(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004657 nv_enable_irq(dev);
4658 }
4659 return 0;
4660}
4661
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004662static int nv_set_loopback(struct net_device *dev, netdev_features_t features)
Sanjay Hortikare19df762011-11-11 16:11:21 +00004663{
4664 struct fe_priv *np = netdev_priv(dev);
4665 unsigned long flags;
4666 u32 miicontrol;
4667 int err, retval = 0;
4668
4669 spin_lock_irqsave(&np->lock, flags);
4670 miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
4671 if (features & NETIF_F_LOOPBACK) {
4672 if (miicontrol & BMCR_LOOPBACK) {
4673 spin_unlock_irqrestore(&np->lock, flags);
4674 netdev_info(dev, "Loopback already enabled\n");
4675 return 0;
4676 }
4677 nv_disable_irq(dev);
4678 /* Turn on loopback mode */
4679 miicontrol |= BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000;
4680 err = mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol);
4681 if (err) {
4682 retval = PHY_ERROR;
4683 spin_unlock_irqrestore(&np->lock, flags);
4684 phy_init(dev);
4685 } else {
4686 if (netif_running(dev)) {
4687 /* Force 1000 Mbps full-duplex */
4688 nv_force_linkspeed(dev, NVREG_LINKSPEED_1000,
4689 1);
4690 /* Force link up */
4691 netif_carrier_on(dev);
4692 }
4693 spin_unlock_irqrestore(&np->lock, flags);
4694 netdev_info(dev,
4695 "Internal PHY loopback mode enabled.\n");
4696 }
4697 } else {
4698 if (!(miicontrol & BMCR_LOOPBACK)) {
4699 spin_unlock_irqrestore(&np->lock, flags);
4700 netdev_info(dev, "Loopback already disabled\n");
4701 return 0;
4702 }
4703 nv_disable_irq(dev);
4704 /* Turn off loopback */
4705 spin_unlock_irqrestore(&np->lock, flags);
4706 netdev_info(dev, "Internal PHY loopback mode disabled.\n");
4707 phy_init(dev);
4708 }
4709 msleep(500);
4710 spin_lock_irqsave(&np->lock, flags);
4711 nv_enable_irq(dev);
4712 spin_unlock_irqrestore(&np->lock, flags);
4713
4714 return retval;
4715}
4716
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004717static netdev_features_t nv_fix_features(struct net_device *dev,
4718 netdev_features_t features)
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004719{
Michał Mirosław569e1462011-04-15 04:50:49 +00004720 /* vlan is dependent on rx checksum offload */
4721 if (features & (NETIF_F_HW_VLAN_TX|NETIF_F_HW_VLAN_RX))
4722 features |= NETIF_F_RXCSUM;
4723
4724 return features;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004725}
4726
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004727static void nv_vlan_mode(struct net_device *dev, netdev_features_t features)
Jiri Pirko3326c782011-07-20 04:54:38 +00004728{
4729 struct fe_priv *np = get_nvpriv(dev);
4730
4731 spin_lock_irq(&np->lock);
4732
4733 if (features & NETIF_F_HW_VLAN_RX)
4734 np->txrxctl_bits |= NVREG_TXRXCTL_VLANSTRIP;
4735 else
4736 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANSTRIP;
4737
4738 if (features & NETIF_F_HW_VLAN_TX)
4739 np->txrxctl_bits |= NVREG_TXRXCTL_VLANINS;
4740 else
4741 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANINS;
4742
4743 writel(np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4744
4745 spin_unlock_irq(&np->lock);
4746}
4747
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004748static int nv_set_features(struct net_device *dev, netdev_features_t features)
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004749{
4750 struct fe_priv *np = netdev_priv(dev);
4751 u8 __iomem *base = get_hwbase(dev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004752 netdev_features_t changed = dev->features ^ features;
Sanjay Hortikare19df762011-11-11 16:11:21 +00004753 int retval;
4754
4755 if ((changed & NETIF_F_LOOPBACK) && netif_running(dev)) {
4756 retval = nv_set_loopback(dev, features);
4757 if (retval != 0)
4758 return retval;
4759 }
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004760
Michał Mirosław569e1462011-04-15 04:50:49 +00004761 if (changed & NETIF_F_RXCSUM) {
4762 spin_lock_irq(&np->lock);
4763
4764 if (features & NETIF_F_RXCSUM)
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004765 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
Michał Mirosław569e1462011-04-15 04:50:49 +00004766 else
4767 np->txrxctl_bits &= ~NVREG_TXRXCTL_RXCHECK;
4768
4769 if (netif_running(dev))
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004770 writel(np->txrxctl_bits, base + NvRegTxRxControl);
Michał Mirosław569e1462011-04-15 04:50:49 +00004771
4772 spin_unlock_irq(&np->lock);
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004773 }
4774
Jiri Pirko3326c782011-07-20 04:54:38 +00004775 if (changed & (NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX))
4776 nv_vlan_mode(dev, features);
4777
Michał Mirosław569e1462011-04-15 04:50:49 +00004778 return 0;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004779}
4780
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004781static int nv_get_sset_count(struct net_device *dev, int sset)
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004782{
4783 struct fe_priv *np = netdev_priv(dev);
4784
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004785 switch (sset) {
4786 case ETH_SS_TEST:
4787 if (np->driver_data & DEV_HAS_TEST_EXTENDED)
4788 return NV_TEST_COUNT_EXTENDED;
4789 else
4790 return NV_TEST_COUNT_BASE;
4791 case ETH_SS_STATS:
Ayaz Abdulla8ed14542009-03-05 08:01:49 +00004792 if (np->driver_data & DEV_HAS_STATISTICS_V3)
4793 return NV_DEV_STATISTICS_V3_COUNT;
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004794 else if (np->driver_data & DEV_HAS_STATISTICS_V2)
4795 return NV_DEV_STATISTICS_V2_COUNT;
Ayaz Abdulla8ed14542009-03-05 08:01:49 +00004796 else if (np->driver_data & DEV_HAS_STATISTICS_V1)
4797 return NV_DEV_STATISTICS_V1_COUNT;
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004798 else
4799 return 0;
4800 default:
4801 return -EOPNOTSUPP;
4802 }
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004803}
4804
david decotignyf5d827a2011-11-16 12:15:13 +00004805static void nv_get_ethtool_stats(struct net_device *dev,
4806 struct ethtool_stats *estats, u64 *buffer)
4807 __acquires(&netdev_priv(dev)->hwstats_lock)
4808 __releases(&netdev_priv(dev)->hwstats_lock)
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004809{
4810 struct fe_priv *np = netdev_priv(dev);
4811
david decotignyf5d827a2011-11-16 12:15:13 +00004812 spin_lock_bh(&np->hwstats_lock);
4813 nv_update_stats(dev);
4814 memcpy(buffer, &np->estats,
4815 nv_get_sset_count(dev, ETH_SS_STATS)*sizeof(u64));
4816 spin_unlock_bh(&np->hwstats_lock);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004817}
4818
4819static int nv_link_test(struct net_device *dev)
4820{
4821 struct fe_priv *np = netdev_priv(dev);
4822 int mii_status;
4823
4824 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
4825 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
4826
4827 /* check phy link status */
4828 if (!(mii_status & BMSR_LSTATUS))
4829 return 0;
4830 else
4831 return 1;
4832}
4833
4834static int nv_register_test(struct net_device *dev)
4835{
4836 u8 __iomem *base = get_hwbase(dev);
4837 int i = 0;
4838 u32 orig_read, new_read;
4839
4840 do {
4841 orig_read = readl(base + nv_registers_test[i].reg);
4842
4843 /* xor with mask to toggle bits */
4844 orig_read ^= nv_registers_test[i].mask;
4845
4846 writel(orig_read, base + nv_registers_test[i].reg);
4847
4848 new_read = readl(base + nv_registers_test[i].reg);
4849
4850 if ((new_read & nv_registers_test[i].mask) != (orig_read & nv_registers_test[i].mask))
4851 return 0;
4852
4853 /* restore original value */
4854 orig_read ^= nv_registers_test[i].mask;
4855 writel(orig_read, base + nv_registers_test[i].reg);
4856
4857 } while (nv_registers_test[++i].reg != 0);
4858
4859 return 1;
4860}
4861
4862static int nv_interrupt_test(struct net_device *dev)
4863{
4864 struct fe_priv *np = netdev_priv(dev);
4865 u8 __iomem *base = get_hwbase(dev);
4866 int ret = 1;
4867 int testcnt;
4868 u32 save_msi_flags, save_poll_interval = 0;
4869
4870 if (netif_running(dev)) {
4871 /* free current irq */
4872 nv_free_irq(dev);
4873 save_poll_interval = readl(base+NvRegPollingInterval);
4874 }
4875
4876 /* flag to test interrupt handler */
4877 np->intr_test = 0;
4878
4879 /* setup test irq */
4880 save_msi_flags = np->msi_flags;
4881 np->msi_flags &= ~NV_MSI_X_VECTORS_MASK;
4882 np->msi_flags |= 0x001; /* setup 1 vector */
4883 if (nv_request_irq(dev, 1))
4884 return 0;
4885
4886 /* setup timer interrupt */
4887 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
4888 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
4889
4890 nv_enable_hw_interrupts(dev, NVREG_IRQ_TIMER);
4891
4892 /* wait for at least one interrupt */
4893 msleep(100);
4894
4895 spin_lock_irq(&np->lock);
4896
4897 /* flag should be set within ISR */
4898 testcnt = np->intr_test;
4899 if (!testcnt)
4900 ret = 2;
4901
4902 nv_disable_hw_interrupts(dev, NVREG_IRQ_TIMER);
4903 if (!(np->msi_flags & NV_MSI_X_ENABLED))
4904 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4905 else
4906 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
4907
4908 spin_unlock_irq(&np->lock);
4909
4910 nv_free_irq(dev);
4911
4912 np->msi_flags = save_msi_flags;
4913
4914 if (netif_running(dev)) {
4915 writel(save_poll_interval, base + NvRegPollingInterval);
4916 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
4917 /* restore original irq */
4918 if (nv_request_irq(dev, 0))
4919 return 0;
4920 }
4921
4922 return ret;
4923}
4924
4925static int nv_loopback_test(struct net_device *dev)
4926{
4927 struct fe_priv *np = netdev_priv(dev);
4928 u8 __iomem *base = get_hwbase(dev);
4929 struct sk_buff *tx_skb, *rx_skb;
4930 dma_addr_t test_dma_addr;
4931 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004932 u32 flags;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004933 int len, i, pkt_len;
4934 u8 *pkt_data;
4935 u32 filter_flags = 0;
4936 u32 misc1_flags = 0;
4937 int ret = 1;
4938
4939 if (netif_running(dev)) {
4940 nv_disable_irq(dev);
4941 filter_flags = readl(base + NvRegPacketFilterFlags);
4942 misc1_flags = readl(base + NvRegMisc1);
4943 } else {
4944 nv_txrx_reset(dev);
4945 }
4946
4947 /* reinit driver view of the rx queue */
4948 set_bufsize(dev);
4949 nv_init_ring(dev);
4950
4951 /* setup hardware for loopback */
4952 writel(NVREG_MISC1_FORCE, base + NvRegMisc1);
4953 writel(NVREG_PFF_ALWAYS | NVREG_PFF_LOOPBACK, base + NvRegPacketFilterFlags);
4954
4955 /* reinit nic view of the rx queue */
4956 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4957 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00004958 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004959 base + NvRegRingSizes);
4960 pci_push(base);
4961
4962 /* restart rx engine */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004963 nv_start_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004964
4965 /* setup packet for tx */
4966 pkt_len = ETH_DATA_LEN;
4967 tx_skb = dev_alloc_skb(pkt_len);
Jesper Juhl46798c82006-09-25 16:39:24 -07004968 if (!tx_skb) {
Joe Perches1d397f32010-11-29 07:41:57 +00004969 netdev_err(dev, "dev_alloc_skb() failed during loopback test\n");
Jesper Juhl46798c82006-09-25 16:39:24 -07004970 ret = 0;
4971 goto out;
4972 }
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03004973 test_dma_addr = pci_map_single(np->pci_dev, tx_skb->data,
4974 skb_tailroom(tx_skb),
4975 PCI_DMA_FROMDEVICE);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004976 pkt_data = skb_put(tx_skb, pkt_len);
4977 for (i = 0; i < pkt_len; i++)
4978 pkt_data[i] = (u8)(i & 0xff);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004979
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004980 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004981 np->tx_ring.orig[0].buf = cpu_to_le32(test_dma_addr);
4982 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 -04004983 } else {
Al Viro5bb7ea22007-12-09 16:06:41 +00004984 np->tx_ring.ex[0].bufhigh = cpu_to_le32(dma_high(test_dma_addr));
4985 np->tx_ring.ex[0].buflow = cpu_to_le32(dma_low(test_dma_addr));
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004986 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 -04004987 }
4988 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4989 pci_push(get_hwbase(dev));
4990
4991 msleep(500);
4992
4993 /* check for rx of the packet */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004994 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004995 flags = le32_to_cpu(np->rx_ring.orig[0].flaglen);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004996 len = nv_descr_getlength(&np->rx_ring.orig[0], np->desc_ver);
4997
4998 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004999 flags = le32_to_cpu(np->rx_ring.ex[0].flaglen);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005000 len = nv_descr_getlength_ex(&np->rx_ring.ex[0], np->desc_ver);
5001 }
5002
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07005003 if (flags & NV_RX_AVAIL) {
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005004 ret = 0;
5005 } else if (np->desc_ver == DESC_VER_1) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07005006 if (flags & NV_RX_ERROR)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005007 ret = 0;
5008 } else {
Szymon Janc78aea4f2010-11-27 08:39:43 +00005009 if (flags & NV_RX2_ERROR)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005010 ret = 0;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005011 }
5012
5013 if (ret) {
5014 if (len != pkt_len) {
5015 ret = 0;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005016 } else {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05005017 rx_skb = np->rx_skb[0].skb;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005018 for (i = 0; i < pkt_len; i++) {
5019 if (rx_skb->data[i] != (u8)(i & 0xff)) {
5020 ret = 0;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005021 break;
5022 }
5023 }
5024 }
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005025 }
5026
Eric Dumazet73a37072009-06-17 21:17:59 +00005027 pci_unmap_single(np->pci_dev, test_dma_addr,
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07005028 (skb_end_pointer(tx_skb) - tx_skb->data),
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005029 PCI_DMA_TODEVICE);
5030 dev_kfree_skb_any(tx_skb);
Jesper Juhl46798c82006-09-25 16:39:24 -07005031 out:
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005032 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005033 nv_stop_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005034 nv_txrx_reset(dev);
5035 /* drain rx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005036 nv_drain_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005037
5038 if (netif_running(dev)) {
5039 writel(misc1_flags, base + NvRegMisc1);
5040 writel(filter_flags, base + NvRegPacketFilterFlags);
5041 nv_enable_irq(dev);
5042 }
5043
5044 return ret;
5045}
5046
5047static void nv_self_test(struct net_device *dev, struct ethtool_test *test, u64 *buffer)
5048{
5049 struct fe_priv *np = netdev_priv(dev);
5050 u8 __iomem *base = get_hwbase(dev);
5051 int result;
Jeff Garzikb9f2c042007-10-03 18:07:32 -07005052 memset(buffer, 0, nv_get_sset_count(dev, ETH_SS_TEST)*sizeof(u64));
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005053
5054 if (!nv_link_test(dev)) {
5055 test->flags |= ETH_TEST_FL_FAILED;
5056 buffer[0] = 1;
5057 }
5058
5059 if (test->flags & ETH_TEST_FL_OFFLINE) {
5060 if (netif_running(dev)) {
5061 netif_stop_queue(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00005062 nv_napi_disable(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10005063 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07005064 netif_addr_lock(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005065 spin_lock_irq(&np->lock);
5066 nv_disable_hw_interrupts(dev, np->irqmask);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005067 if (!(np->msi_flags & NV_MSI_X_ENABLED))
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005068 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005069 else
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005070 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005071 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005072 nv_stop_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005073 nv_txrx_reset(dev);
5074 /* drain rx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005075 nv_drain_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005076 spin_unlock_irq(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07005077 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10005078 netif_tx_unlock_bh(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005079 }
5080
5081 if (!nv_register_test(dev)) {
5082 test->flags |= ETH_TEST_FL_FAILED;
5083 buffer[1] = 1;
5084 }
5085
5086 result = nv_interrupt_test(dev);
5087 if (result != 1) {
5088 test->flags |= ETH_TEST_FL_FAILED;
5089 buffer[2] = 1;
5090 }
5091 if (result == 0) {
5092 /* bail out */
5093 return;
5094 }
5095
5096 if (!nv_loopback_test(dev)) {
5097 test->flags |= ETH_TEST_FL_FAILED;
5098 buffer[3] = 1;
5099 }
5100
5101 if (netif_running(dev)) {
5102 /* reinit driver view of the rx queue */
5103 set_bufsize(dev);
5104 if (nv_init_ring(dev)) {
5105 if (!np->in_shutdown)
5106 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
5107 }
5108 /* reinit nic view of the rx queue */
5109 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
5110 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005111 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005112 base + NvRegRingSizes);
5113 pci_push(base);
5114 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
5115 pci_push(base);
5116 /* restart rx engine */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005117 nv_start_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005118 netif_start_queue(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00005119 nv_napi_enable(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005120 nv_enable_hw_interrupts(dev, np->irqmask);
5121 }
5122 }
5123}
5124
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005125static void nv_get_strings(struct net_device *dev, u32 stringset, u8 *buffer)
5126{
5127 switch (stringset) {
5128 case ETH_SS_STATS:
Jeff Garzikb9f2c042007-10-03 18:07:32 -07005129 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 -04005130 break;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005131 case ETH_SS_TEST:
Jeff Garzikb9f2c042007-10-03 18:07:32 -07005132 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 -04005133 break;
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005134 }
5135}
5136
Jeff Garzik7282d492006-09-13 14:30:00 -04005137static const struct ethtool_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005138 .get_drvinfo = nv_get_drvinfo,
5139 .get_link = ethtool_op_get_link,
5140 .get_wol = nv_get_wol,
5141 .set_wol = nv_set_wol,
5142 .get_settings = nv_get_settings,
5143 .set_settings = nv_set_settings,
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005144 .get_regs_len = nv_get_regs_len,
5145 .get_regs = nv_get_regs,
5146 .nway_reset = nv_nway_reset,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005147 .get_ringparam = nv_get_ringparam,
5148 .set_ringparam = nv_set_ringparam,
Ayaz Abdullab6d07732006-06-10 22:47:42 -04005149 .get_pauseparam = nv_get_pauseparam,
5150 .set_pauseparam = nv_set_pauseparam,
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005151 .get_strings = nv_get_strings,
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005152 .get_ethtool_stats = nv_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07005153 .get_sset_count = nv_get_sset_count,
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005154 .self_test = nv_self_test,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155};
5156
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005157/* The mgmt unit and driver use a semaphore to access the phy during init */
5158static int nv_mgmt_acquire_sema(struct net_device *dev)
5159{
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005160 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005161 u8 __iomem *base = get_hwbase(dev);
5162 int i;
5163 u32 tx_ctrl, mgmt_sema;
5164
5165 for (i = 0; i < 10; i++) {
5166 mgmt_sema = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_SEMA_MASK;
5167 if (mgmt_sema == NVREG_XMITCTL_MGMT_SEMA_FREE)
5168 break;
5169 msleep(500);
5170 }
5171
5172 if (mgmt_sema != NVREG_XMITCTL_MGMT_SEMA_FREE)
5173 return 0;
5174
5175 for (i = 0; i < 2; i++) {
5176 tx_ctrl = readl(base + NvRegTransmitterControl);
5177 tx_ctrl |= NVREG_XMITCTL_HOST_SEMA_ACQ;
5178 writel(tx_ctrl, base + NvRegTransmitterControl);
5179
5180 /* verify that semaphore was acquired */
5181 tx_ctrl = readl(base + NvRegTransmitterControl);
5182 if (((tx_ctrl & NVREG_XMITCTL_HOST_SEMA_MASK) == NVREG_XMITCTL_HOST_SEMA_ACQ) &&
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005183 ((tx_ctrl & NVREG_XMITCTL_MGMT_SEMA_MASK) == NVREG_XMITCTL_MGMT_SEMA_FREE)) {
5184 np->mgmt_sema = 1;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005185 return 1;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005186 } else
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005187 udelay(50);
5188 }
5189
5190 return 0;
5191}
5192
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005193static void nv_mgmt_release_sema(struct net_device *dev)
5194{
5195 struct fe_priv *np = netdev_priv(dev);
5196 u8 __iomem *base = get_hwbase(dev);
5197 u32 tx_ctrl;
5198
5199 if (np->driver_data & DEV_HAS_MGMT_UNIT) {
5200 if (np->mgmt_sema) {
5201 tx_ctrl = readl(base + NvRegTransmitterControl);
5202 tx_ctrl &= ~NVREG_XMITCTL_HOST_SEMA_ACQ;
5203 writel(tx_ctrl, base + NvRegTransmitterControl);
5204 }
5205 }
5206}
5207
5208
5209static int nv_mgmt_get_version(struct net_device *dev)
5210{
5211 struct fe_priv *np = netdev_priv(dev);
5212 u8 __iomem *base = get_hwbase(dev);
5213 u32 data_ready = readl(base + NvRegTransmitterControl);
5214 u32 data_ready2 = 0;
5215 unsigned long start;
5216 int ready = 0;
5217
5218 writel(NVREG_MGMTUNITGETVERSION, base + NvRegMgmtUnitGetVersion);
5219 writel(data_ready ^ NVREG_XMITCTL_DATA_START, base + NvRegTransmitterControl);
5220 start = jiffies;
5221 while (time_before(jiffies, start + 5*HZ)) {
5222 data_ready2 = readl(base + NvRegTransmitterControl);
5223 if ((data_ready & NVREG_XMITCTL_DATA_READY) != (data_ready2 & NVREG_XMITCTL_DATA_READY)) {
5224 ready = 1;
5225 break;
5226 }
5227 schedule_timeout_uninterruptible(1);
5228 }
5229
5230 if (!ready || (data_ready2 & NVREG_XMITCTL_DATA_ERROR))
5231 return 0;
5232
5233 np->mgmt_version = readl(base + NvRegMgmtUnitVersion) & NVREG_MGMTUNITVERSION;
5234
5235 return 1;
5236}
5237
Linus Torvalds1da177e2005-04-16 15:20:36 -07005238static int nv_open(struct net_device *dev)
5239{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005240 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005241 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005242 int ret = 1;
5243 int oom, i;
Ayaz Abdullaa4336862008-04-18 13:50:43 -07005244 u32 low;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005245
Ed Swierkcb52deb2008-12-01 12:24:43 +00005246 /* power up phy */
5247 mii_rw(dev, np->phyaddr, MII_BMCR,
5248 mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ) & ~BMCR_PDOWN);
5249
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00005250 nv_txrx_gate(dev, false);
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005251 /* erase previous misconfiguration */
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005252 if (np->driver_data & DEV_HAS_POWER_CNTRL)
5253 nv_mac_reset(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005254 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
5255 writel(0, base + NvRegMulticastAddrB);
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -05005256 writel(NVREG_MCASTMASKA_NONE, base + NvRegMulticastMaskA);
5257 writel(NVREG_MCASTMASKB_NONE, base + NvRegMulticastMaskB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005258 writel(0, base + NvRegPacketFilterFlags);
5259
5260 writel(0, base + NvRegTransmitterControl);
5261 writel(0, base + NvRegReceiverControl);
5262
5263 writel(0, base + NvRegAdapterControl);
5264
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04005265 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)
5266 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
5267
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005268 /* initialize descriptor rings */
Manfred Sprauld81c0982005-07-31 18:20:30 +02005269 set_bufsize(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005270 oom = nv_init_ring(dev);
5271
5272 writel(0, base + NvRegLinkSpeed);
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005273 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005274 nv_txrx_reset(dev);
5275 writel(0, base + NvRegUnknownSetupReg6);
5276
5277 np->in_shutdown = 0;
5278
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005279 /* give hw rings */
Ayaz Abdulla0832b252006-02-04 13:13:26 -05005280 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005281 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Linus Torvalds1da177e2005-04-16 15:20:36 -07005282 base + NvRegRingSizes);
5283
Linus Torvalds1da177e2005-04-16 15:20:36 -07005284 writel(np->linkspeed, base + NvRegLinkSpeed);
Ayaz Abdulla95d161c2006-07-06 16:46:25 -04005285 if (np->desc_ver == DESC_VER_1)
5286 writel(NVREG_TX_WM_DESC1_DEFAULT, base + NvRegTxWatermark);
5287 else
5288 writel(NVREG_TX_WM_DESC2_3_DEFAULT, base + NvRegTxWatermark);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005289 writel(np->txrxctl_bits, base + NvRegTxRxControl);
Ayaz Abdullaee407b02006-02-04 13:13:17 -05005290 writel(np->vlanctl_bits, base + NvRegVlanControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005291 pci_push(base);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005292 writel(NVREG_TXRXCTL_BIT1|np->txrxctl_bits, base + NvRegTxRxControl);
Joe Perches344d0dc2010-11-29 07:41:52 +00005293 if (reg_delay(dev, NvRegUnknownSetupReg5,
5294 NVREG_UNKSETUP5_BIT31, NVREG_UNKSETUP5_BIT31,
5295 NV_SETUP5_DELAY, NV_SETUP5_DELAYMAX))
Joe Perches1d397f32010-11-29 07:41:57 +00005296 netdev_info(dev,
5297 "%s: SetupReg5, Bit 31 remained off\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005298
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005299 writel(0, base + NvRegMIIMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005300 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005301 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005302
Linus Torvalds1da177e2005-04-16 15:20:36 -07005303 writel(NVREG_MISC1_FORCE | NVREG_MISC1_HD, base + NvRegMisc1);
5304 writel(readl(base + NvRegTransmitterStatus), base + NvRegTransmitterStatus);
5305 writel(NVREG_PFF_ALWAYS, base + NvRegPacketFilterFlags);
Manfred Sprauld81c0982005-07-31 18:20:30 +02005306 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005307
5308 writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus);
Ayaz Abdullaa4336862008-04-18 13:50:43 -07005309
5310 get_random_bytes(&low, sizeof(low));
5311 low &= NVREG_SLOTTIME_MASK;
5312 if (np->desc_ver == DESC_VER_1) {
5313 writel(low|NVREG_SLOTTIME_DEFAULT, base + NvRegSlotTime);
5314 } else {
5315 if (!(np->driver_data & DEV_HAS_GEAR_MODE)) {
5316 /* setup legacy backoff */
5317 writel(NVREG_SLOTTIME_LEGBF_ENABLED|NVREG_SLOTTIME_10_100_FULL|low, base + NvRegSlotTime);
5318 } else {
5319 writel(NVREG_SLOTTIME_10_100_FULL, base + NvRegSlotTime);
5320 nv_gear_backoff_reseed(dev);
5321 }
5322 }
Ayaz Abdulla9744e212006-07-06 16:45:58 -04005323 writel(NVREG_TX_DEFERRAL_DEFAULT, base + NvRegTxDeferral);
5324 writel(NVREG_RX_DEFERRAL_DEFAULT, base + NvRegRxDeferral);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005325 if (poll_interval == -1) {
5326 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT)
5327 writel(NVREG_POLL_DEFAULT_THROUGHPUT, base + NvRegPollingInterval);
5328 else
5329 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005330 } else
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005331 writel(poll_interval & 0xFFFF, base + NvRegPollingInterval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005332 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
5333 writel((np->phyaddr << NVREG_ADAPTCTL_PHYSHIFT)|NVREG_ADAPTCTL_PHYVALID|NVREG_ADAPTCTL_RUNNING,
5334 base + NvRegAdapterControl);
5335 writel(NVREG_MIISPEED_BIT8|NVREG_MIIDELAY, base + NvRegMIISpeed);
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005336 writel(NVREG_MII_LINKCHANGE, base + NvRegMIIMask);
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04005337 if (np->wolenabled)
5338 writel(NVREG_WAKEUPFLAGS_ENABLE , base + NvRegWakeUpFlags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005339
5340 i = readl(base + NvRegPowerState);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005341 if ((i & NVREG_POWERSTATE_POWEREDUP) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005342 writel(NVREG_POWERSTATE_POWEREDUP|i, base + NvRegPowerState);
5343
5344 pci_push(base);
5345 udelay(10);
5346 writel(readl(base + NvRegPowerState) | NVREG_POWERSTATE_VALID, base + NvRegPowerState);
5347
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005348 nv_disable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005349 pci_push(base);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005350 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005351 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
5352 pci_push(base);
5353
Szymon Janc78aea4f2010-11-27 08:39:43 +00005354 if (nv_request_irq(dev, 0))
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005355 goto out_drain;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005356
5357 /* ask for interrupts */
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005358 nv_enable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005359
5360 spin_lock_irq(&np->lock);
5361 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
5362 writel(0, base + NvRegMulticastAddrB);
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -05005363 writel(NVREG_MCASTMASKA_NONE, base + NvRegMulticastMaskA);
5364 writel(NVREG_MCASTMASKB_NONE, base + NvRegMulticastMaskB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005365 writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
5366 /* One manual link speed update: Interrupts are enabled, future link
5367 * speed changes cause interrupts and are handled by nv_link_irq().
5368 */
5369 {
5370 u32 miistat;
5371 miistat = readl(base + NvRegMIIStatus);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005372 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005373 }
Manfred Spraul1b1b3c92005-08-06 23:47:55 +02005374 /* set linkspeed to invalid value, thus force nv_update_linkspeed
5375 * to init hw */
5376 np->linkspeed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005377 ret = nv_update_linkspeed(dev);
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005378 nv_start_rxtx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005379 netif_start_queue(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00005380 nv_napi_enable(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07005381
Linus Torvalds1da177e2005-04-16 15:20:36 -07005382 if (ret) {
5383 netif_carrier_on(dev);
5384 } else {
Joe Perches1d397f32010-11-29 07:41:57 +00005385 netdev_info(dev, "no link during initialization\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005386 netif_carrier_off(dev);
5387 }
5388 if (oom)
5389 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005390
5391 /* start statistics timer */
Ayaz Abdulla9c662432008-08-06 12:11:42 -04005392 if (np->driver_data & (DEV_HAS_STATISTICS_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_STATISTICS_V3))
Daniel Drakebfebbb82008-03-18 11:07:18 +00005393 mod_timer(&np->stats_poll,
5394 round_jiffies(jiffies + STATS_INTERVAL));
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005395
Linus Torvalds1da177e2005-04-16 15:20:36 -07005396 spin_unlock_irq(&np->lock);
5397
Sanjay Hortikare19df762011-11-11 16:11:21 +00005398 /* If the loopback feature was set while the device was down, make sure
5399 * that it's set correctly now.
5400 */
5401 if (dev->features & NETIF_F_LOOPBACK)
5402 nv_set_loopback(dev, dev->features);
5403
Linus Torvalds1da177e2005-04-16 15:20:36 -07005404 return 0;
5405out_drain:
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005406 nv_drain_rxtx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005407 return ret;
5408}
5409
5410static int nv_close(struct net_device *dev)
5411{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005412 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005413 u8 __iomem *base;
5414
5415 spin_lock_irq(&np->lock);
5416 np->in_shutdown = 1;
5417 spin_unlock_irq(&np->lock);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00005418 nv_napi_disable(dev);
Manfred Spraula7475902007-10-17 21:52:33 +02005419 synchronize_irq(np->pci_dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005420
5421 del_timer_sync(&np->oom_kick);
5422 del_timer_sync(&np->nic_poll);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005423 del_timer_sync(&np->stats_poll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005424
5425 netif_stop_queue(dev);
5426 spin_lock_irq(&np->lock);
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005427 nv_stop_rxtx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005428 nv_txrx_reset(dev);
5429
5430 /* disable interrupts on the nic or we will lock up */
5431 base = get_hwbase(dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005432 nv_disable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005433 pci_push(base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005434
5435 spin_unlock_irq(&np->lock);
5436
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005437 nv_free_irq(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005438
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005439 nv_drain_rxtx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005440
Ed Swierk5a9a8e32009-06-02 00:19:52 -07005441 if (np->wolenabled || !phy_power_down) {
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00005442 nv_txrx_gate(dev, false);
Tim Mann2cc49a52007-06-14 13:16:38 -07005443 writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005444 nv_start_rx(dev);
Ed Swierkcb52deb2008-12-01 12:24:43 +00005445 } else {
5446 /* power down phy */
5447 mii_rw(dev, np->phyaddr, MII_BMCR,
5448 mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ)|BMCR_PDOWN);
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00005449 nv_txrx_gate(dev, true);
Tim Mann2cc49a52007-06-14 13:16:38 -07005450 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005451
5452 /* FIXME: power down nic */
5453
5454 return 0;
5455}
5456
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005457static const struct net_device_ops nv_netdev_ops = {
5458 .ndo_open = nv_open,
5459 .ndo_stop = nv_close,
david decotignyf5d827a2011-11-16 12:15:13 +00005460 .ndo_get_stats64 = nv_get_stats64,
Stephen Hemminger00829822008-11-20 20:14:53 -08005461 .ndo_start_xmit = nv_start_xmit,
5462 .ndo_tx_timeout = nv_tx_timeout,
5463 .ndo_change_mtu = nv_change_mtu,
Michał Mirosław569e1462011-04-15 04:50:49 +00005464 .ndo_fix_features = nv_fix_features,
5465 .ndo_set_features = nv_set_features,
Stephen Hemminger00829822008-11-20 20:14:53 -08005466 .ndo_validate_addr = eth_validate_addr,
5467 .ndo_set_mac_address = nv_set_mac_address,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00005468 .ndo_set_rx_mode = nv_set_multicast,
Stephen Hemminger00829822008-11-20 20:14:53 -08005469#ifdef CONFIG_NET_POLL_CONTROLLER
5470 .ndo_poll_controller = nv_poll_controller,
5471#endif
5472};
5473
5474static const struct net_device_ops nv_netdev_ops_optimized = {
5475 .ndo_open = nv_open,
5476 .ndo_stop = nv_close,
david decotignyf5d827a2011-11-16 12:15:13 +00005477 .ndo_get_stats64 = nv_get_stats64,
Stephen Hemminger00829822008-11-20 20:14:53 -08005478 .ndo_start_xmit = nv_start_xmit_optimized,
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005479 .ndo_tx_timeout = nv_tx_timeout,
5480 .ndo_change_mtu = nv_change_mtu,
Michał Mirosław569e1462011-04-15 04:50:49 +00005481 .ndo_fix_features = nv_fix_features,
5482 .ndo_set_features = nv_set_features,
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005483 .ndo_validate_addr = eth_validate_addr,
5484 .ndo_set_mac_address = nv_set_mac_address,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00005485 .ndo_set_rx_mode = nv_set_multicast,
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005486#ifdef CONFIG_NET_POLL_CONTROLLER
5487 .ndo_poll_controller = nv_poll_controller,
5488#endif
5489};
5490
Linus Torvalds1da177e2005-04-16 15:20:36 -07005491static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
5492{
5493 struct net_device *dev;
5494 struct fe_priv *np;
5495 unsigned long addr;
5496 u8 __iomem *base;
5497 int err, i;
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005498 u32 powerstate, txreg;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005499 u32 phystate_orig = 0, phystate;
5500 int phyinitialized = 0;
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005501 static int printed_version;
5502
5503 if (!printed_version++)
Joe Perches294a5542010-11-29 07:41:56 +00005504 pr_info("Reverse Engineered nForce ethernet driver. Version %s.\n",
5505 FORCEDETH_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005506
5507 dev = alloc_etherdev(sizeof(struct fe_priv));
5508 err = -ENOMEM;
5509 if (!dev)
5510 goto out;
5511
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005512 np = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07005513 np->dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005514 np->pci_dev = pci_dev;
5515 spin_lock_init(&np->lock);
david decotignyf5d827a2011-11-16 12:15:13 +00005516 spin_lock_init(&np->hwstats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005517 SET_NETDEV_DEV(dev, &pci_dev->dev);
5518
5519 init_timer(&np->oom_kick);
5520 np->oom_kick.data = (unsigned long) dev;
Joe Perchesc061b182010-08-23 18:20:03 +00005521 np->oom_kick.function = nv_do_rx_refill; /* timer handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005522 init_timer(&np->nic_poll);
5523 np->nic_poll.data = (unsigned long) dev;
Joe Perchesc061b182010-08-23 18:20:03 +00005524 np->nic_poll.function = nv_do_nic_poll; /* timer handler */
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005525 init_timer(&np->stats_poll);
5526 np->stats_poll.data = (unsigned long) dev;
Joe Perchesc061b182010-08-23 18:20:03 +00005527 np->stats_poll.function = nv_do_stats_poll; /* timer handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005528
5529 err = pci_enable_device(pci_dev);
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005530 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005531 goto out_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005532
5533 pci_set_master(pci_dev);
5534
5535 err = pci_request_regions(pci_dev, DRV_NAME);
5536 if (err < 0)
5537 goto out_disable;
5538
Ayaz Abdulla9c662432008-08-06 12:11:42 -04005539 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 -05005540 np->register_size = NV_PCI_REGSZ_VER3;
5541 else if (id->driver_data & DEV_HAS_STATISTICS_V1)
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005542 np->register_size = NV_PCI_REGSZ_VER2;
5543 else
5544 np->register_size = NV_PCI_REGSZ_VER1;
5545
Linus Torvalds1da177e2005-04-16 15:20:36 -07005546 err = -EINVAL;
5547 addr = 0;
5548 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005549 if (pci_resource_flags(pci_dev, i) & IORESOURCE_MEM &&
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005550 pci_resource_len(pci_dev, i) >= np->register_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005551 addr = pci_resource_start(pci_dev, i);
5552 break;
5553 }
5554 }
5555 if (i == DEVICE_COUNT_RESOURCE) {
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005556 dev_info(&pci_dev->dev, "Couldn't find register window\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005557 goto out_relreg;
5558 }
5559
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005560 /* copy of driver data */
5561 np->driver_data = id->driver_data;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04005562 /* copy of device id */
5563 np->device_id = id->device;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005564
Linus Torvalds1da177e2005-04-16 15:20:36 -07005565 /* handle different descriptor versions */
Manfred Spraulee733622005-07-31 18:32:26 +02005566 if (id->driver_data & DEV_HAS_HIGH_DMA) {
5567 /* packet format 3: supports 40-bit addressing */
5568 np->desc_ver = DESC_VER_3;
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005569 np->txrxctl_bits = NVREG_TXRXCTL_DESC_3;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005570 if (dma_64bit) {
Yang Hongyang6afd1422009-04-06 19:01:15 -07005571 if (pci_set_dma_mask(pci_dev, DMA_BIT_MASK(39)))
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005572 dev_info(&pci_dev->dev,
5573 "64-bit DMA failed, using 32-bit addressing\n");
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005574 else
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005575 dev->features |= NETIF_F_HIGHDMA;
Yang Hongyang6afd1422009-04-06 19:01:15 -07005576 if (pci_set_consistent_dma_mask(pci_dev, DMA_BIT_MASK(39))) {
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005577 dev_info(&pci_dev->dev,
5578 "64-bit DMA (consistent) failed, using 32-bit ring buffers\n");
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005579 }
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005580 }
Manfred Spraulee733622005-07-31 18:32:26 +02005581 } else if (id->driver_data & DEV_HAS_LARGEDESC) {
5582 /* packet format 2: supports jumbo frames */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005583 np->desc_ver = DESC_VER_2;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005584 np->txrxctl_bits = NVREG_TXRXCTL_DESC_2;
Manfred Spraulee733622005-07-31 18:32:26 +02005585 } else {
5586 /* original packet format */
5587 np->desc_ver = DESC_VER_1;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005588 np->txrxctl_bits = NVREG_TXRXCTL_DESC_1;
Manfred Sprauld81c0982005-07-31 18:20:30 +02005589 }
Manfred Spraulee733622005-07-31 18:32:26 +02005590
5591 np->pkt_limit = NV_PKTLIMIT_1;
5592 if (id->driver_data & DEV_HAS_LARGEDESC)
5593 np->pkt_limit = NV_PKTLIMIT_2;
5594
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005595 if (id->driver_data & DEV_HAS_CHECKSUM) {
5596 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
Michał Mirosław569e1462011-04-15 04:50:49 +00005597 dev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_SG |
5598 NETIF_F_TSO | NETIF_F_RXCSUM;
Ayaz Abdulla21828162007-01-23 12:27:21 -05005599 }
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005600
Ayaz Abdullaee407b02006-02-04 13:13:17 -05005601 np->vlanctl_bits = 0;
5602 if (id->driver_data & DEV_HAS_VLAN) {
5603 np->vlanctl_bits = NVREG_VLANCONTROL_ENABLE;
Jiri Pirko0891b0e2011-07-26 10:19:28 +00005604 dev->hw_features |= NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX;
Ayaz Abdullaee407b02006-02-04 13:13:17 -05005605 }
5606
Jiri Pirko0891b0e2011-07-26 10:19:28 +00005607 dev->features |= dev->hw_features;
5608
Sanjay Hortikare19df762011-11-11 16:11:21 +00005609 /* Add loopback capability to the device. */
5610 dev->hw_features |= NETIF_F_LOOPBACK;
5611
Ayaz Abdullab6d07732006-06-10 22:47:42 -04005612 np->pause_flags = NV_PAUSEFRAME_RX_CAPABLE | NV_PAUSEFRAME_RX_REQ | NV_PAUSEFRAME_AUTONEG;
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05005613 if ((id->driver_data & DEV_HAS_PAUSEFRAME_TX_V1) ||
5614 (id->driver_data & DEV_HAS_PAUSEFRAME_TX_V2) ||
5615 (id->driver_data & DEV_HAS_PAUSEFRAME_TX_V3)) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04005616 np->pause_flags |= NV_PAUSEFRAME_TX_CAPABLE | NV_PAUSEFRAME_TX_REQ;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04005617 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04005618
Linus Torvalds1da177e2005-04-16 15:20:36 -07005619 err = -ENOMEM;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005620 np->base = ioremap(addr, np->register_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005621 if (!np->base)
5622 goto out_relreg;
5623 dev->base_addr = (unsigned long)np->base;
Manfred Spraulee733622005-07-31 18:32:26 +02005624
Linus Torvalds1da177e2005-04-16 15:20:36 -07005625 dev->irq = pci_dev->irq;
Manfred Spraulee733622005-07-31 18:32:26 +02005626
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005627 np->rx_ring_size = RX_RING_DEFAULT;
5628 np->tx_ring_size = TX_RING_DEFAULT;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005629
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005630 if (!nv_optimized(np)) {
Manfred Spraulee733622005-07-31 18:32:26 +02005631 np->rx_ring.orig = pci_alloc_consistent(pci_dev,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005632 sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
Manfred Spraulee733622005-07-31 18:32:26 +02005633 &np->ring_addr);
5634 if (!np->rx_ring.orig)
5635 goto out_unmap;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005636 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
Manfred Spraulee733622005-07-31 18:32:26 +02005637 } else {
5638 np->rx_ring.ex = pci_alloc_consistent(pci_dev,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005639 sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
Manfred Spraulee733622005-07-31 18:32:26 +02005640 &np->ring_addr);
5641 if (!np->rx_ring.ex)
5642 goto out_unmap;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005643 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
Manfred Spraulee733622005-07-31 18:32:26 +02005644 }
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07005645 np->rx_skb = kcalloc(np->rx_ring_size, sizeof(struct nv_skb_map), GFP_KERNEL);
5646 np->tx_skb = kcalloc(np->tx_ring_size, sizeof(struct nv_skb_map), GFP_KERNEL);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05005647 if (!np->rx_skb || !np->tx_skb)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005648 goto out_freering;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005649
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005650 if (!nv_optimized(np))
Stephen Hemminger00829822008-11-20 20:14:53 -08005651 dev->netdev_ops = &nv_netdev_ops;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05005652 else
Stephen Hemminger00829822008-11-20 20:14:53 -08005653 dev->netdev_ops = &nv_netdev_ops_optimized;
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005654
Stephen Hemmingerbea33482007-10-03 16:41:36 -07005655 netif_napi_add(dev, &np->napi, nv_napi_poll, RX_WORK_PER_LOOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005656 SET_ETHTOOL_OPS(dev, &ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005657 dev->watchdog_timeo = NV_WATCHDOG_TIMEO;
5658
5659 pci_set_drvdata(pci_dev, dev);
5660
5661 /* read the mac address */
5662 base = get_hwbase(dev);
5663 np->orig_mac[0] = readl(base + NvRegMacAddrA);
5664 np->orig_mac[1] = readl(base + NvRegMacAddrB);
5665
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005666 /* check the workaround bit for correct mac address order */
5667 txreg = readl(base + NvRegTransmitPoll);
Ayaz Abdullaa376e792008-04-10 21:30:35 -07005668 if (id->driver_data & DEV_HAS_CORRECT_MACADDR) {
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005669 /* mac address is already in correct order */
5670 dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff;
5671 dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff;
5672 dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff;
5673 dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff;
5674 dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff;
5675 dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff;
Ayaz Abdullaa376e792008-04-10 21:30:35 -07005676 } else if (txreg & NVREG_TRANSMITPOLL_MAC_ADDR_REV) {
5677 /* mac address is already in correct order */
5678 dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff;
5679 dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff;
5680 dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff;
5681 dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff;
5682 dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff;
5683 dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff;
5684 /*
5685 * Set orig mac address back to the reversed version.
5686 * This flag will be cleared during low power transition.
5687 * Therefore, we should always put back the reversed address.
5688 */
5689 np->orig_mac[0] = (dev->dev_addr[5] << 0) + (dev->dev_addr[4] << 8) +
5690 (dev->dev_addr[3] << 16) + (dev->dev_addr[2] << 24);
5691 np->orig_mac[1] = (dev->dev_addr[1] << 0) + (dev->dev_addr[0] << 8);
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005692 } else {
5693 /* need to reverse mac address to correct order */
5694 dev->dev_addr[0] = (np->orig_mac[1] >> 8) & 0xff;
5695 dev->dev_addr[1] = (np->orig_mac[1] >> 0) & 0xff;
5696 dev->dev_addr[2] = (np->orig_mac[0] >> 24) & 0xff;
5697 dev->dev_addr[3] = (np->orig_mac[0] >> 16) & 0xff;
5698 dev->dev_addr[4] = (np->orig_mac[0] >> 8) & 0xff;
5699 dev->dev_addr[5] = (np->orig_mac[0] >> 0) & 0xff;
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005700 writel(txreg|NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
Joe Perchesc20ec762010-11-29 07:42:02 +00005701 dev_dbg(&pci_dev->dev,
5702 "%s: set workaround bit for reversed mac addr\n",
5703 __func__);
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005704 }
John W. Linvillec704b852005-09-12 10:48:56 -04005705 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005706
John W. Linvillec704b852005-09-12 10:48:56 -04005707 if (!is_valid_ether_addr(dev->perm_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005708 /*
5709 * Bad mac address. At least one bios sets the mac address
5710 * to 01:23:45:67:89:ab
5711 */
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005712 dev_err(&pci_dev->dev,
Joe Perchesc20ec762010-11-29 07:42:02 +00005713 "Invalid MAC address detected: %pM - Please complain to your hardware vendor.\n",
Szymon Janc78aea4f2010-11-27 08:39:43 +00005714 dev->dev_addr);
Stanislav O. Bezzubtsev655a6592009-11-15 21:17:02 -08005715 random_ether_addr(dev->dev_addr);
Joe Perchesc20ec762010-11-29 07:42:02 +00005716 dev_err(&pci_dev->dev,
5717 "Using random MAC address: %pM\n", dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005718 }
5719
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005720 /* set mac address */
5721 nv_copy_mac_to_hw(dev);
5722
Linus Torvalds1da177e2005-04-16 15:20:36 -07005723 /* disable WOL */
5724 writel(0, base + NvRegWakeUpFlags);
5725 np->wolenabled = 0;
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00005726 device_set_wakeup_enable(&pci_dev->dev, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005727
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005728 if (id->driver_data & DEV_HAS_POWER_CNTRL) {
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005729
5730 /* take phy and nic out of low power mode */
5731 powerstate = readl(base + NvRegPowerState2);
5732 powerstate &= ~NVREG_POWERSTATE2_POWERUP_MASK;
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00005733 if ((id->driver_data & DEV_NEED_LOW_POWER_FIX) &&
Auke Kok44c10132007-06-08 15:46:36 -07005734 pci_dev->revision >= 0xA3)
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005735 powerstate |= NVREG_POWERSTATE2_POWERUP_REV_A3;
5736 writel(powerstate, base + NvRegPowerState2);
5737 }
5738
Szymon Janc78aea4f2010-11-27 08:39:43 +00005739 if (np->desc_ver == DESC_VER_1)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005740 np->tx_flags = NV_TX_VALID;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005741 else
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005742 np->tx_flags = NV_TX2_VALID;
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005743
5744 np->msi_flags = 0;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005745 if ((id->driver_data & DEV_HAS_MSI) && msi)
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005746 np->msi_flags |= NV_MSI_CAPABLE;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005747
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005748 if ((id->driver_data & DEV_HAS_MSI_X) && msix) {
5749 /* msix has had reported issues when modifying irqmask
5750 as in the case of napi, therefore, disable for now
5751 */
David S. Miller0a127612010-05-03 23:33:05 -07005752#if 0
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005753 np->msi_flags |= NV_MSI_X_CAPABLE;
5754#endif
5755 }
5756
5757 if (optimization_mode == NV_OPTIMIZATION_MODE_CPU) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005758 np->irqmask = NVREG_IRQMASK_CPU;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005759 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
5760 np->msi_flags |= 0x0001;
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005761 } else if (optimization_mode == NV_OPTIMIZATION_MODE_DYNAMIC &&
5762 !(id->driver_data & DEV_NEED_TIMERIRQ)) {
5763 /* start off in throughput mode */
5764 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
5765 /* remove support for msix mode */
5766 np->msi_flags &= ~NV_MSI_X_CAPABLE;
5767 } else {
5768 optimization_mode = NV_OPTIMIZATION_MODE_THROUGHPUT;
5769 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
5770 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
5771 np->msi_flags |= 0x0003;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005772 }
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005773
Linus Torvalds1da177e2005-04-16 15:20:36 -07005774 if (id->driver_data & DEV_NEED_TIMERIRQ)
5775 np->irqmask |= NVREG_IRQ_TIMER;
5776 if (id->driver_data & DEV_NEED_LINKTIMER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005777 np->need_linktimer = 1;
5778 np->link_timeout = jiffies + LINK_TIMEOUT;
5779 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005780 np->need_linktimer = 0;
5781 }
5782
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005783 /* Limit the number of tx's outstanding for hw bug */
5784 if (id->driver_data & DEV_NEED_TX_LIMIT) {
5785 np->tx_limit = 1;
Ayaz Abdulla5c659322010-04-13 18:49:51 -07005786 if (((id->driver_data & DEV_NEED_TX_LIMIT2) == DEV_NEED_TX_LIMIT2) &&
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005787 pci_dev->revision >= 0xA2)
5788 np->tx_limit = 0;
5789 }
5790
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005791 /* clear phy state and temporarily halt phy interrupts */
5792 writel(0, base + NvRegMIIMask);
5793 phystate = readl(base + NvRegAdapterControl);
5794 if (phystate & NVREG_ADAPTCTL_RUNNING) {
5795 phystate_orig = 1;
5796 phystate &= ~NVREG_ADAPTCTL_RUNNING;
5797 writel(phystate, base + NvRegAdapterControl);
5798 }
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005799 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005800
5801 if (id->driver_data & DEV_HAS_MGMT_UNIT) {
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005802 /* management unit running on the mac? */
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005803 if ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_ST) &&
5804 (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_PHY_INIT) &&
5805 nv_mgmt_acquire_sema(dev) &&
5806 nv_mgmt_get_version(dev)) {
5807 np->mac_in_use = 1;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005808 if (np->mgmt_version > 0)
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005809 np->mac_in_use = readl(base + NvRegMgmtUnitControl) & NVREG_MGMTUNITCONTROL_INUSE;
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005810 /* management unit setup the phy already? */
5811 if (np->mac_in_use &&
5812 ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK) ==
5813 NVREG_XMITCTL_SYNC_PHY_INIT)) {
5814 /* phy is inited by mgmt unit */
5815 phyinitialized = 1;
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005816 } else {
5817 /* we need to init the phy */
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005818 }
5819 }
5820 }
5821
Linus Torvalds1da177e2005-04-16 15:20:36 -07005822 /* find a suitable phy */
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005823 for (i = 1; i <= 32; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005824 int id1, id2;
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005825 int phyaddr = i & 0x1F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005826
5827 spin_lock_irq(&np->lock);
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005828 id1 = mii_rw(dev, phyaddr, MII_PHYSID1, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005829 spin_unlock_irq(&np->lock);
5830 if (id1 < 0 || id1 == 0xffff)
5831 continue;
5832 spin_lock_irq(&np->lock);
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005833 id2 = mii_rw(dev, phyaddr, MII_PHYSID2, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005834 spin_unlock_irq(&np->lock);
5835 if (id2 < 0 || id2 == 0xffff)
5836 continue;
5837
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04005838 np->phy_model = id2 & PHYID2_MODEL_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005839 id1 = (id1 & PHYID1_OUI_MASK) << PHYID1_OUI_SHFT;
5840 id2 = (id2 & PHYID2_OUI_MASK) >> PHYID2_OUI_SHFT;
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005841 np->phyaddr = phyaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005842 np->phy_oui = id1 | id2;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04005843
5844 /* Realtek hardcoded phy id1 to all zero's on certain phys */
5845 if (np->phy_oui == PHY_OUI_REALTEK2)
5846 np->phy_oui = PHY_OUI_REALTEK;
5847 /* Setup phy revision for Realtek */
5848 if (np->phy_oui == PHY_OUI_REALTEK && np->phy_model == PHY_MODEL_REALTEK_8211)
5849 np->phy_rev = mii_rw(dev, phyaddr, MII_RESV1, MII_READ) & PHY_REV_MASK;
5850
Linus Torvalds1da177e2005-04-16 15:20:36 -07005851 break;
5852 }
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005853 if (i == 33) {
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005854 dev_info(&pci_dev->dev, "open: Could not find a valid PHY\n");
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005855 goto out_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005856 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04005857
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005858 if (!phyinitialized) {
5859 /* reset it */
5860 phy_init(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05005861 } else {
5862 /* see if it is a gigabit phy */
5863 u32 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005864 if (mii_status & PHY_GIGABIT)
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05005865 np->gigabit = PHY_GIGABIT;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005866 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005867
5868 /* set default link speed settings */
5869 np->linkspeed = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
5870 np->duplex = 0;
5871 np->autoneg = 1;
5872
5873 err = register_netdev(dev);
5874 if (err) {
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005875 dev_info(&pci_dev->dev, "unable to register netdev: %d\n", err);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005876 goto out_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005877 }
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005878
David S. Miller823dcd22011-08-20 10:39:12 -07005879 if (id->driver_data & DEV_HAS_VLAN)
5880 nv_vlan_mode(dev, dev->features);
Jiri Pirko0891b0e2011-07-26 10:19:28 +00005881
Ivan Vecera0d672e92011-02-15 02:08:39 +00005882 netif_carrier_off(dev);
5883
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005884 dev_info(&pci_dev->dev, "ifname %s, PHY OUI 0x%x @ %d, addr %pM\n",
5885 dev->name, np->phy_oui, np->phyaddr, dev->dev_addr);
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005886
Sanjay Hortikare19df762011-11-11 16:11:21 +00005887 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 +00005888 dev->features & NETIF_F_HIGHDMA ? "highdma " : "",
5889 dev->features & (NETIF_F_IP_CSUM | NETIF_F_SG) ?
Szymon Janc78aea4f2010-11-27 08:39:43 +00005890 "csum " : "",
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005891 dev->features & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX) ?
Szymon Janc78aea4f2010-11-27 08:39:43 +00005892 "vlan " : "",
Sanjay Hortikare19df762011-11-11 16:11:21 +00005893 dev->features & (NETIF_F_LOOPBACK) ?
5894 "loopback " : "",
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005895 id->driver_data & DEV_HAS_POWER_CNTRL ? "pwrctl " : "",
5896 id->driver_data & DEV_HAS_MGMT_UNIT ? "mgmt " : "",
5897 id->driver_data & DEV_NEED_TIMERIRQ ? "timirq " : "",
5898 np->gigabit == PHY_GIGABIT ? "gbit " : "",
5899 np->need_linktimer ? "lnktim " : "",
5900 np->msi_flags & NV_MSI_CAPABLE ? "msi " : "",
5901 np->msi_flags & NV_MSI_X_CAPABLE ? "msi-x " : "",
5902 np->desc_ver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005903
5904 return 0;
5905
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005906out_error:
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005907 if (phystate_orig)
5908 writel(phystate|NVREG_ADAPTCTL_RUNNING, base + NvRegAdapterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005909 pci_set_drvdata(pci_dev, NULL);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005910out_freering:
5911 free_rings(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005912out_unmap:
5913 iounmap(get_hwbase(dev));
5914out_relreg:
5915 pci_release_regions(pci_dev);
5916out_disable:
5917 pci_disable_device(pci_dev);
5918out_free:
5919 free_netdev(dev);
5920out:
5921 return err;
5922}
5923
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04005924static void nv_restore_phy(struct net_device *dev)
5925{
5926 struct fe_priv *np = netdev_priv(dev);
5927 u16 phy_reserved, mii_control;
5928
5929 if (np->phy_oui == PHY_OUI_REALTEK &&
5930 np->phy_model == PHY_MODEL_REALTEK_8201 &&
5931 phy_cross == NV_CROSSOVER_DETECTION_DISABLED) {
5932 mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3);
5933 phy_reserved = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, MII_READ);
5934 phy_reserved &= ~PHY_REALTEK_INIT_MSK1;
5935 phy_reserved |= PHY_REALTEK_INIT8;
5936 mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, phy_reserved);
5937 mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1);
5938
5939 /* restart auto negotiation */
5940 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
5941 mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE);
5942 mii_rw(dev, np->phyaddr, MII_BMCR, mii_control);
5943 }
5944}
5945
Yinghai Luf55c21f2008-09-13 13:10:31 -07005946static void nv_restore_mac_addr(struct pci_dev *pci_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005947{
5948 struct net_device *dev = pci_get_drvdata(pci_dev);
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005949 struct fe_priv *np = netdev_priv(dev);
5950 u8 __iomem *base = get_hwbase(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005951
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005952 /* special op: write back the misordered MAC address - otherwise
5953 * the next nv_probe would see a wrong address.
5954 */
5955 writel(np->orig_mac[0], base + NvRegMacAddrA);
5956 writel(np->orig_mac[1], base + NvRegMacAddrB);
Björn Steinbrink2e3884b2008-01-07 23:22:53 -08005957 writel(readl(base + NvRegTransmitPoll) & ~NVREG_TRANSMITPOLL_MAC_ADDR_REV,
5958 base + NvRegTransmitPoll);
Yinghai Luf55c21f2008-09-13 13:10:31 -07005959}
5960
5961static void __devexit nv_remove(struct pci_dev *pci_dev)
5962{
5963 struct net_device *dev = pci_get_drvdata(pci_dev);
5964
5965 unregister_netdev(dev);
5966
5967 nv_restore_mac_addr(pci_dev);
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005968
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04005969 /* restore any phy related changes */
5970 nv_restore_phy(dev);
5971
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005972 nv_mgmt_release_sema(dev);
5973
Linus Torvalds1da177e2005-04-16 15:20:36 -07005974 /* free all structures */
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005975 free_rings(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005976 iounmap(get_hwbase(dev));
5977 pci_release_regions(pci_dev);
5978 pci_disable_device(pci_dev);
5979 free_netdev(dev);
5980 pci_set_drvdata(pci_dev, NULL);
5981}
5982
Michel Lespinasse94252762011-03-06 16:14:50 +00005983#ifdef CONFIG_PM_SLEEP
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00005984static int nv_suspend(struct device *device)
Francois Romieua1893172006-10-10 14:33:27 -07005985{
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00005986 struct pci_dev *pdev = to_pci_dev(device);
Francois Romieua1893172006-10-10 14:33:27 -07005987 struct net_device *dev = pci_get_drvdata(pdev);
5988 struct fe_priv *np = netdev_priv(dev);
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02005989 u8 __iomem *base = get_hwbase(dev);
5990 int i;
Francois Romieua1893172006-10-10 14:33:27 -07005991
Tobias Diedrich25d90812008-05-18 15:04:29 +02005992 if (netif_running(dev)) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00005993 /* Gross. */
Tobias Diedrich25d90812008-05-18 15:04:29 +02005994 nv_close(dev);
5995 }
Francois Romieua1893172006-10-10 14:33:27 -07005996 netif_device_detach(dev);
5997
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02005998 /* save non-pci configuration space */
Szymon Janc78aea4f2010-11-27 08:39:43 +00005999 for (i = 0; i <= np->register_size/sizeof(u32); i++)
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006000 np->saved_config_space[i] = readl(base + i*sizeof(u32));
6001
Francois Romieua1893172006-10-10 14:33:27 -07006002 return 0;
6003}
6004
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006005static int nv_resume(struct device *device)
Francois Romieua1893172006-10-10 14:33:27 -07006006{
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006007 struct pci_dev *pdev = to_pci_dev(device);
Francois Romieua1893172006-10-10 14:33:27 -07006008 struct net_device *dev = pci_get_drvdata(pdev);
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006009 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullaa376e792008-04-10 21:30:35 -07006010 u8 __iomem *base = get_hwbase(dev);
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006011 int i, rc = 0;
Francois Romieua1893172006-10-10 14:33:27 -07006012
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006013 /* restore non-pci configuration space */
Szymon Janc78aea4f2010-11-27 08:39:43 +00006014 for (i = 0; i <= np->register_size/sizeof(u32); i++)
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006015 writel(np->saved_config_space[i], base+i*sizeof(u32));
Ayaz Abdullaa376e792008-04-10 21:30:35 -07006016
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006017 if (np->driver_data & DEV_NEED_MSI_FIX)
6018 pci_write_config_dword(pdev, NV_MSI_PRIV_OFFSET, NV_MSI_PRIV_VALUE);
Ayaz Abdullab6e44052009-02-07 00:24:15 -08006019
Ed Swierk35a74332009-04-06 17:49:12 -07006020 /* restore phy state, including autoneg */
6021 phy_init(dev);
6022
Tobias Diedrich25d90812008-05-18 15:04:29 +02006023 netif_device_attach(dev);
6024 if (netif_running(dev)) {
6025 rc = nv_open(dev);
6026 nv_set_multicast(dev);
6027 }
Francois Romieua1893172006-10-10 14:33:27 -07006028 return rc;
6029}
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006030
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006031static SIMPLE_DEV_PM_OPS(nv_pm_ops, nv_suspend, nv_resume);
6032#define NV_PM_OPS (&nv_pm_ops)
6033
Michel Lespinasse94252762011-03-06 16:14:50 +00006034#else
6035#define NV_PM_OPS NULL
6036#endif /* CONFIG_PM_SLEEP */
6037
6038#ifdef CONFIG_PM
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006039static void nv_shutdown(struct pci_dev *pdev)
6040{
6041 struct net_device *dev = pci_get_drvdata(pdev);
6042 struct fe_priv *np = netdev_priv(dev);
6043
6044 if (netif_running(dev))
6045 nv_close(dev);
6046
Tobias Diedrich34edaa82009-02-16 00:13:20 -08006047 /*
6048 * Restore the MAC so a kernel started by kexec won't get confused.
6049 * If we really go for poweroff, we must not restore the MAC,
6050 * otherwise the MAC for WOL will be reversed at least on some boards.
6051 */
Szymon Janc78aea4f2010-11-27 08:39:43 +00006052 if (system_state != SYSTEM_POWER_OFF)
Tobias Diedrich34edaa82009-02-16 00:13:20 -08006053 nv_restore_mac_addr(pdev);
Yinghai Luf55c21f2008-09-13 13:10:31 -07006054
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006055 pci_disable_device(pdev);
Tobias Diedrich34edaa82009-02-16 00:13:20 -08006056 /*
6057 * Apparently it is not possible to reinitialise from D3 hot,
6058 * only put the device into D3 if we really go for poweroff.
6059 */
Rafael J. Wysocki3cb55992008-09-05 14:00:19 -07006060 if (system_state == SYSTEM_POWER_OFF) {
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006061 pci_wake_from_d3(pdev, np->wolenabled);
Rafael J. Wysocki3cb55992008-09-05 14:00:19 -07006062 pci_set_power_state(pdev, PCI_D3hot);
6063 }
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006064}
Francois Romieua1893172006-10-10 14:33:27 -07006065#else
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006066#define nv_shutdown NULL
Francois Romieua1893172006-10-10 14:33:27 -07006067#endif /* CONFIG_PM */
6068
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006069static DEFINE_PCI_DEVICE_TABLE(pci_tbl) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006070 { /* nForce Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006071 PCI_DEVICE(0x10DE, 0x01C3),
Manfred Spraulc2dba062005-07-31 18:29:47 +02006072 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006073 },
6074 { /* nForce2 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006075 PCI_DEVICE(0x10DE, 0x0066),
Manfred Spraulc2dba062005-07-31 18:29:47 +02006076 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006077 },
6078 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006079 PCI_DEVICE(0x10DE, 0x00D6),
Manfred Spraulc2dba062005-07-31 18:29:47 +02006080 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006081 },
6082 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006083 PCI_DEVICE(0x10DE, 0x0086),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04006084 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006085 },
6086 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006087 PCI_DEVICE(0x10DE, 0x008C),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04006088 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006089 },
6090 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006091 PCI_DEVICE(0x10DE, 0x00E6),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04006092 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006093 },
6094 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006095 PCI_DEVICE(0x10DE, 0x00DF),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04006096 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006097 },
6098 { /* CK804 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006099 PCI_DEVICE(0x10DE, 0x0056),
Yinghai Lu033e97b2009-02-06 01:30:56 -08006100 .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 -07006101 },
6102 { /* CK804 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006103 PCI_DEVICE(0x10DE, 0x0057),
Yinghai Lu033e97b2009-02-06 01:30:56 -08006104 .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 -07006105 },
6106 { /* MCP04 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006107 PCI_DEVICE(0x10DE, 0x0037),
Ayaz Abdulla9e184762009-03-05 08:02:18 +00006108 .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 -07006109 },
6110 { /* MCP04 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006111 PCI_DEVICE(0x10DE, 0x0038),
Ayaz Abdulla9e184762009-03-05 08:02:18 +00006112 .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 +02006113 },
6114 { /* MCP51 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006115 PCI_DEVICE(0x10DE, 0x0268),
6116 .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 -07006117 },
Manfred Spraul9992d4a2005-06-05 17:36:11 +02006118 { /* MCP51 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006119 PCI_DEVICE(0x10DE, 0x0269),
6120 .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 +02006121 },
Manfred Spraulf49d16e2005-06-26 11:36:52 +02006122 { /* MCP55 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006123 PCI_DEVICE(0x10DE, 0x0372),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006124 .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 +02006125 },
6126 { /* MCP55 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006127 PCI_DEVICE(0x10DE, 0x0373),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006128 .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 +02006129 },
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04006130 { /* MCP61 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006131 PCI_DEVICE(0x10DE, 0x03E5),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006132 .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 -04006133 },
6134 { /* MCP61 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006135 PCI_DEVICE(0x10DE, 0x03E6),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006136 .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 -04006137 },
6138 { /* MCP61 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006139 PCI_DEVICE(0x10DE, 0x03EE),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006140 .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 -04006141 },
6142 { /* MCP61 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006143 PCI_DEVICE(0x10DE, 0x03EF),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006144 .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 -04006145 },
6146 { /* MCP65 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006147 PCI_DEVICE(0x10DE, 0x0450),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006148 .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 -04006149 },
6150 { /* MCP65 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006151 PCI_DEVICE(0x10DE, 0x0451),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006152 .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 -04006153 },
6154 { /* MCP65 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006155 PCI_DEVICE(0x10DE, 0x0452),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006156 .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 -04006157 },
6158 { /* MCP65 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006159 PCI_DEVICE(0x10DE, 0x0453),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006160 .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 -04006161 },
Ayaz Abdullaf4344842006-11-06 00:43:40 -08006162 { /* MCP67 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006163 PCI_DEVICE(0x10DE, 0x054C),
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_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdullaf4344842006-11-06 00:43:40 -08006165 },
6166 { /* MCP67 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006167 PCI_DEVICE(0x10DE, 0x054D),
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_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdullaf4344842006-11-06 00:43:40 -08006169 },
6170 { /* MCP67 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006171 PCI_DEVICE(0x10DE, 0x054E),
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_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdullaf4344842006-11-06 00:43:40 -08006173 },
6174 { /* MCP67 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006175 PCI_DEVICE(0x10DE, 0x054F),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006176 .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 -08006177 },
Ayaz Abdulla13986612007-07-22 20:43:26 -04006178 { /* MCP73 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006179 PCI_DEVICE(0x10DE, 0x07DC),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006180 .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 -04006181 },
6182 { /* MCP73 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006183 PCI_DEVICE(0x10DE, 0x07DD),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006184 .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 -04006185 },
6186 { /* MCP73 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006187 PCI_DEVICE(0x10DE, 0x07DE),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006188 .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 -04006189 },
6190 { /* MCP73 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006191 PCI_DEVICE(0x10DE, 0x07DF),
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_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdulla13986612007-07-22 20:43:26 -04006193 },
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04006194 { /* MCP77 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006195 PCI_DEVICE(0x10DE, 0x0760),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006196 .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 -04006197 },
6198 { /* MCP77 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006199 PCI_DEVICE(0x10DE, 0x0761),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006200 .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 -04006201 },
6202 { /* MCP77 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006203 PCI_DEVICE(0x10DE, 0x0762),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006204 .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 -04006205 },
6206 { /* MCP77 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006207 PCI_DEVICE(0x10DE, 0x0763),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006208 .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 -04006209 },
Ayaz Abdulla490dde82007-11-23 20:54:01 -05006210 { /* MCP79 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006211 PCI_DEVICE(0x10DE, 0x0AB0),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006212 .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 -05006213 },
6214 { /* MCP79 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006215 PCI_DEVICE(0x10DE, 0x0AB1),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006216 .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 -05006217 },
6218 { /* MCP79 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006219 PCI_DEVICE(0x10DE, 0x0AB2),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006220 .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 -05006221 },
6222 { /* MCP79 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006223 PCI_DEVICE(0x10DE, 0x0AB3),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006224 .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 -05006225 },
Ayaz Abdulla3df81c42009-06-03 15:05:35 +00006226 { /* MCP89 Ethernet Controller */
6227 PCI_DEVICE(0x10DE, 0x0D7D),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006228 .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 +00006229 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006230 {0,},
6231};
6232
6233static struct pci_driver driver = {
Jeff Garzik3f88ce42007-10-16 04:09:09 -04006234 .name = DRV_NAME,
6235 .id_table = pci_tbl,
6236 .probe = nv_probe,
6237 .remove = __devexit_p(nv_remove),
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006238 .shutdown = nv_shutdown,
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006239 .driver.pm = NV_PM_OPS,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006240};
6241
Linus Torvalds1da177e2005-04-16 15:20:36 -07006242static int __init init_nic(void)
6243{
Jeff Garzik29917622006-08-19 17:48:59 -04006244 return pci_register_driver(&driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006245}
6246
6247static void __exit exit_nic(void)
6248{
6249 pci_unregister_driver(&driver);
6250}
6251
6252module_param(max_interrupt_work, int, 0);
6253MODULE_PARM_DESC(max_interrupt_work, "forcedeth maximum events handled per interrupt");
Ayaz Abdullaa971c322005-11-11 08:30:38 -05006254module_param(optimization_mode, int, 0);
Ayaz Abdulla9e184762009-03-05 08:02:18 +00006255MODULE_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 -05006256module_param(poll_interval, int, 0);
6257MODULE_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 -04006258module_param(msi, int, 0);
6259MODULE_PARM_DESC(msi, "MSI interrupts are enabled by setting to 1 and disabled by setting to 0.");
6260module_param(msix, int, 0);
6261MODULE_PARM_DESC(msix, "MSIX interrupts are enabled by setting to 1 and disabled by setting to 0.");
6262module_param(dma_64bit, int, 0);
6263MODULE_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 -04006264module_param(phy_cross, int, 0);
6265MODULE_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 -07006266module_param(phy_power_down, int, 0);
6267MODULE_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 +00006268module_param(debug_tx_timeout, bool, 0);
6269MODULE_PARM_DESC(debug_tx_timeout,
6270 "Dump tx related registers and ring when tx_timeout happens");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006271
6272MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>");
6273MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver");
6274MODULE_LICENSE("GPL");
6275
6276MODULE_DEVICE_TABLE(pci, pci_tbl);
6277
6278module_init(init_nic);
6279module_exit(exit_nic);