blob: 5245dacc3a491e02825edf9ef313e12b4dd040bc [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;
david decotigny0a1f2222011-11-16 12:15:14 +0000818 u64 stat_rx_dropped;
david decotignyf5d827a2011-11-16 12:15:13 +0000819
Linus Torvalds1da177e2005-04-16 15:20:36 -0700820 /* media detection workaround.
821 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
822 */
823 int need_linktimer;
824 unsigned long link_timeout;
825 /*
826 * tx specific fields.
827 */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500828 union ring_type get_tx, put_tx, first_tx, last_tx;
829 struct nv_skb_map *get_tx_ctx, *put_tx_ctx;
830 struct nv_skb_map *first_tx_ctx, *last_tx_ctx;
831 struct nv_skb_map *tx_skb;
832
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700833 union ring_type tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834 u32 tx_flags;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400835 int tx_ring_size;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -0500836 int tx_limit;
837 u32 tx_pkts_in_progress;
838 struct nv_skb_map *tx_change_owner;
839 struct nv_skb_map *tx_end_flip;
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -0500840 int tx_stop;
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500841
david decotignyf5d827a2011-11-16 12:15:13 +0000842 /* TX software stats */
843 struct u64_stats_sync swstats_tx_syncp;
844 u64 stat_tx_packets; /* not always available in HW */
845 u64 stat_tx_bytes;
846 u64 stat_tx_dropped;
847
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500848 /* msi/msi-x fields */
849 u32 msi_flags;
850 struct msix_entry msi_x_entry[NV_MSI_X_MAX_VECTORS];
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400851
852 /* flow control */
853 u32 pause_flags;
Tobias Diedrich1a1ca862008-05-18 15:03:44 +0200854
855 /* power saved state */
856 u32 saved_config_space[NV_PCI_REGSZ_MAX/4];
Yinghai Luddb213f2009-02-06 01:29:23 -0800857
858 /* for different msi-x irq type */
859 char name_rx[IFNAMSIZ + 3]; /* -rx */
860 char name_tx[IFNAMSIZ + 3]; /* -tx */
861 char name_other[IFNAMSIZ + 6]; /* -other */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862};
863
864/*
865 * Maximum number of loops until we assume that a bit in the irq mask
866 * is stuck. Overridable with module param.
867 */
Ayaz Abdulla4145ade2009-03-05 08:02:26 +0000868static int max_interrupt_work = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700869
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500870/*
871 * Optimization can be either throuput mode or cpu mode
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400872 *
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500873 * Throughput Mode: Every tx and rx packet will generate an interrupt.
874 * CPU Mode: Interrupts are controlled by a timer.
875 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400876enum {
877 NV_OPTIMIZATION_MODE_THROUGHPUT,
Ayaz Abdulla9e184762009-03-05 08:02:18 +0000878 NV_OPTIMIZATION_MODE_CPU,
879 NV_OPTIMIZATION_MODE_DYNAMIC
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400880};
Ayaz Abdulla9e184762009-03-05 08:02:18 +0000881static int optimization_mode = NV_OPTIMIZATION_MODE_DYNAMIC;
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500882
883/*
884 * Poll interval for timer irq
885 *
886 * This interval determines how frequent an interrupt is generated.
887 * The is value is determined by [(time_in_micro_secs * 100) / (2^10)]
888 * Min = 0, and Max = 65535
889 */
890static int poll_interval = -1;
891
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500892/*
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400893 * MSI interrupts
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500894 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400895enum {
896 NV_MSI_INT_DISABLED,
897 NV_MSI_INT_ENABLED
898};
899static int msi = NV_MSI_INT_ENABLED;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500900
901/*
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400902 * MSIX interrupts
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500903 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400904enum {
905 NV_MSIX_INT_DISABLED,
906 NV_MSIX_INT_ENABLED
907};
Yinghai Lu39482792009-02-06 01:31:12 -0800908static int msix = NV_MSIX_INT_ENABLED;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400909
910/*
911 * DMA 64bit
912 */
913enum {
914 NV_DMA_64BIT_DISABLED,
915 NV_DMA_64BIT_ENABLED
916};
917static int dma_64bit = NV_DMA_64BIT_ENABLED;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500918
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400919/*
Sameer Nanda1ec4f2d2011-11-16 12:15:12 +0000920 * Debug output control for tx_timeout
921 */
922static bool debug_tx_timeout = false;
923
924/*
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400925 * Crossover Detection
926 * Realtek 8201 phy + some OEM boards do not work properly.
927 */
928enum {
929 NV_CROSSOVER_DETECTION_DISABLED,
930 NV_CROSSOVER_DETECTION_ENABLED
931};
932static int phy_cross = NV_CROSSOVER_DETECTION_DISABLED;
933
Ed Swierk5a9a8e32009-06-02 00:19:52 -0700934/*
935 * Power down phy when interface is down (persists through reboot;
936 * older Linux and other OSes may not power it up again)
937 */
Szymon Janc78aea4f2010-11-27 08:39:43 +0000938static int phy_power_down;
Ed Swierk5a9a8e32009-06-02 00:19:52 -0700939
Linus Torvalds1da177e2005-04-16 15:20:36 -0700940static inline struct fe_priv *get_nvpriv(struct net_device *dev)
941{
942 return netdev_priv(dev);
943}
944
945static inline u8 __iomem *get_hwbase(struct net_device *dev)
946{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400947 return ((struct fe_priv *)netdev_priv(dev))->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948}
949
950static inline void pci_push(u8 __iomem *base)
951{
952 /* force out pending posted writes */
953 readl(base);
954}
955
956static inline u32 nv_descr_getlength(struct ring_desc *prd, u32 v)
957{
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700958 return le32_to_cpu(prd->flaglen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700959 & ((v == DESC_VER_1) ? LEN_MASK_V1 : LEN_MASK_V2);
960}
961
Manfred Spraulee733622005-07-31 18:32:26 +0200962static inline u32 nv_descr_getlength_ex(struct ring_desc_ex *prd, u32 v)
963{
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700964 return le32_to_cpu(prd->flaglen) & LEN_MASK_V2;
Manfred Spraulee733622005-07-31 18:32:26 +0200965}
966
Jeff Garzik36b30ea2007-10-16 01:40:30 -0400967static bool nv_optimized(struct fe_priv *np)
968{
969 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
970 return false;
971 return true;
972}
973
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974static int reg_delay(struct net_device *dev, int offset, u32 mask, u32 target,
Joe Perches344d0dc2010-11-29 07:41:52 +0000975 int delay, int delaymax)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700976{
977 u8 __iomem *base = get_hwbase(dev);
978
979 pci_push(base);
980 do {
981 udelay(delay);
982 delaymax -= delay;
Joe Perches344d0dc2010-11-29 07:41:52 +0000983 if (delaymax < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985 } while ((readl(base + offset) & mask) != target);
986 return 0;
987}
988
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500989#define NV_SETUP_RX_RING 0x01
990#define NV_SETUP_TX_RING 0x02
991
Al Viro5bb7ea22007-12-09 16:06:41 +0000992static inline u32 dma_low(dma_addr_t addr)
993{
994 return addr;
995}
996
997static inline u32 dma_high(dma_addr_t addr)
998{
999 return addr>>31>>1; /* 0 if 32bit, shift down by 32 if 64bit */
1000}
1001
Ayaz Abdulla0832b252006-02-04 13:13:26 -05001002static void setup_hw_rings(struct net_device *dev, int rxtx_flags)
1003{
1004 struct fe_priv *np = get_nvpriv(dev);
1005 u8 __iomem *base = get_hwbase(dev);
1006
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001007 if (!nv_optimized(np)) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00001008 if (rxtx_flags & NV_SETUP_RX_RING)
Al Viro5bb7ea22007-12-09 16:06:41 +00001009 writel(dma_low(np->ring_addr), base + NvRegRxRingPhysAddr);
Szymon Janc78aea4f2010-11-27 08:39:43 +00001010 if (rxtx_flags & NV_SETUP_TX_RING)
Al Viro5bb7ea22007-12-09 16:06:41 +00001011 writel(dma_low(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr);
Ayaz Abdulla0832b252006-02-04 13:13:26 -05001012 } else {
1013 if (rxtx_flags & NV_SETUP_RX_RING) {
Al Viro5bb7ea22007-12-09 16:06:41 +00001014 writel(dma_low(np->ring_addr), base + NvRegRxRingPhysAddr);
1015 writel(dma_high(np->ring_addr), base + NvRegRxRingPhysAddrHigh);
Ayaz Abdulla0832b252006-02-04 13:13:26 -05001016 }
1017 if (rxtx_flags & NV_SETUP_TX_RING) {
Al Viro5bb7ea22007-12-09 16:06:41 +00001018 writel(dma_low(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr);
1019 writel(dma_high(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddrHigh);
Ayaz Abdulla0832b252006-02-04 13:13:26 -05001020 }
1021 }
1022}
1023
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001024static void free_rings(struct net_device *dev)
1025{
1026 struct fe_priv *np = get_nvpriv(dev);
1027
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001028 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001029 if (np->rx_ring.orig)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001030 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
1031 np->rx_ring.orig, np->ring_addr);
1032 } else {
1033 if (np->rx_ring.ex)
1034 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
1035 np->rx_ring.ex, np->ring_addr);
1036 }
Szymon Janc9b03b062010-11-27 08:39:44 +00001037 kfree(np->rx_skb);
1038 kfree(np->tx_skb);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001039}
1040
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001041static int using_multi_irqs(struct net_device *dev)
1042{
1043 struct fe_priv *np = get_nvpriv(dev);
1044
1045 if (!(np->msi_flags & NV_MSI_X_ENABLED) ||
1046 ((np->msi_flags & NV_MSI_X_ENABLED) &&
1047 ((np->msi_flags & NV_MSI_X_VECTORS_MASK) == 0x1)))
1048 return 0;
1049 else
1050 return 1;
1051}
1052
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00001053static void nv_txrx_gate(struct net_device *dev, bool gate)
1054{
1055 struct fe_priv *np = get_nvpriv(dev);
1056 u8 __iomem *base = get_hwbase(dev);
1057 u32 powerstate;
1058
1059 if (!np->mac_in_use &&
1060 (np->driver_data & DEV_HAS_POWER_CNTRL)) {
1061 powerstate = readl(base + NvRegPowerState2);
1062 if (gate)
1063 powerstate |= NVREG_POWERSTATE2_GATE_CLOCKS;
1064 else
1065 powerstate &= ~NVREG_POWERSTATE2_GATE_CLOCKS;
1066 writel(powerstate, base + NvRegPowerState2);
1067 }
1068}
1069
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001070static void nv_enable_irq(struct net_device *dev)
1071{
1072 struct fe_priv *np = get_nvpriv(dev);
1073
1074 if (!using_multi_irqs(dev)) {
1075 if (np->msi_flags & NV_MSI_X_ENABLED)
1076 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1077 else
Manfred Spraula7475902007-10-17 21:52:33 +02001078 enable_irq(np->pci_dev->irq);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001079 } else {
1080 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1081 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
1082 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
1083 }
1084}
1085
1086static void nv_disable_irq(struct net_device *dev)
1087{
1088 struct fe_priv *np = get_nvpriv(dev);
1089
1090 if (!using_multi_irqs(dev)) {
1091 if (np->msi_flags & NV_MSI_X_ENABLED)
1092 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1093 else
Manfred Spraula7475902007-10-17 21:52:33 +02001094 disable_irq(np->pci_dev->irq);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001095 } else {
1096 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1097 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
1098 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
1099 }
1100}
1101
1102/* In MSIX mode, a write to irqmask behaves as XOR */
1103static void nv_enable_hw_interrupts(struct net_device *dev, u32 mask)
1104{
1105 u8 __iomem *base = get_hwbase(dev);
1106
1107 writel(mask, base + NvRegIrqMask);
1108}
1109
1110static void nv_disable_hw_interrupts(struct net_device *dev, u32 mask)
1111{
1112 struct fe_priv *np = get_nvpriv(dev);
1113 u8 __iomem *base = get_hwbase(dev);
1114
1115 if (np->msi_flags & NV_MSI_X_ENABLED) {
1116 writel(mask, base + NvRegIrqMask);
1117 } else {
1118 if (np->msi_flags & NV_MSI_ENABLED)
1119 writel(0, base + NvRegMSIIrqMask);
1120 writel(0, base + NvRegIrqMask);
1121 }
1122}
1123
Ayaz Abdulla08d93572009-03-05 08:01:55 +00001124static void nv_napi_enable(struct net_device *dev)
1125{
Ayaz Abdulla08d93572009-03-05 08:01:55 +00001126 struct fe_priv *np = get_nvpriv(dev);
1127
1128 napi_enable(&np->napi);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00001129}
1130
1131static void nv_napi_disable(struct net_device *dev)
1132{
Ayaz Abdulla08d93572009-03-05 08:01:55 +00001133 struct fe_priv *np = get_nvpriv(dev);
1134
1135 napi_disable(&np->napi);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00001136}
1137
Linus Torvalds1da177e2005-04-16 15:20:36 -07001138#define MII_READ (-1)
1139/* mii_rw: read/write a register on the PHY.
1140 *
1141 * Caller must guarantee serialization
1142 */
1143static int mii_rw(struct net_device *dev, int addr, int miireg, int value)
1144{
1145 u8 __iomem *base = get_hwbase(dev);
1146 u32 reg;
1147 int retval;
1148
Ayaz Abdullaeb798422008-02-04 15:14:04 -05001149 writel(NVREG_MIISTAT_MASK_RW, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001150
1151 reg = readl(base + NvRegMIIControl);
1152 if (reg & NVREG_MIICTL_INUSE) {
1153 writel(NVREG_MIICTL_INUSE, base + NvRegMIIControl);
1154 udelay(NV_MIIBUSY_DELAY);
1155 }
1156
1157 reg = (addr << NVREG_MIICTL_ADDRSHIFT) | miireg;
1158 if (value != MII_READ) {
1159 writel(value, base + NvRegMIIData);
1160 reg |= NVREG_MIICTL_WRITE;
1161 }
1162 writel(reg, base + NvRegMIIControl);
1163
1164 if (reg_delay(dev, NvRegMIIControl, NVREG_MIICTL_INUSE, 0,
Joe Perches344d0dc2010-11-29 07:41:52 +00001165 NV_MIIPHY_DELAY, NV_MIIPHY_DELAYMAX)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001166 retval = -1;
1167 } else if (value != MII_READ) {
1168 /* it was a write operation - fewer failures are detectable */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169 retval = 0;
1170 } else if (readl(base + NvRegMIIStatus) & NVREG_MIISTAT_ERROR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 retval = -1;
1172 } else {
1173 retval = readl(base + NvRegMIIData);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 }
1175
1176 return retval;
1177}
1178
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001179static int phy_reset(struct net_device *dev, u32 bmcr_setup)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001180{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001181 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001182 u32 miicontrol;
1183 unsigned int tries = 0;
1184
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001185 miicontrol = BMCR_RESET | bmcr_setup;
Szymon Janc78aea4f2010-11-27 08:39:43 +00001186 if (mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001188
1189 /* wait for 500ms */
1190 msleep(500);
1191
1192 /* must wait till reset is deasserted */
1193 while (miicontrol & BMCR_RESET) {
Szymon Jancde855b92010-11-27 08:39:48 +00001194 usleep_range(10000, 20000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001195 miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1196 /* FIXME: 100 tries seem excessive */
1197 if (tries++ > 100)
1198 return -1;
1199 }
1200 return 0;
1201}
1202
Joe Perchesc41d41e2010-11-29 07:41:58 +00001203static int init_realtek_8211b(struct net_device *dev, struct fe_priv *np)
1204{
1205 static const struct {
1206 int reg;
1207 int init;
1208 } ri[] = {
1209 { PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1 },
1210 { PHY_REALTEK_INIT_REG2, PHY_REALTEK_INIT2 },
1211 { PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3 },
1212 { PHY_REALTEK_INIT_REG3, PHY_REALTEK_INIT4 },
1213 { PHY_REALTEK_INIT_REG4, PHY_REALTEK_INIT5 },
1214 { PHY_REALTEK_INIT_REG5, PHY_REALTEK_INIT6 },
1215 { PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1 },
1216 };
1217 int i;
1218
1219 for (i = 0; i < ARRAY_SIZE(ri); i++) {
Joe Perchescd663282010-11-29 07:41:59 +00001220 if (mii_rw(dev, np->phyaddr, ri[i].reg, ri[i].init))
Joe Perchesc41d41e2010-11-29 07:41:58 +00001221 return PHY_ERROR;
Joe Perchesc41d41e2010-11-29 07:41:58 +00001222 }
1223
1224 return 0;
1225}
1226
Joe Perchescd663282010-11-29 07:41:59 +00001227static int init_realtek_8211c(struct net_device *dev, struct fe_priv *np)
1228{
1229 u32 reg;
1230 u8 __iomem *base = get_hwbase(dev);
1231 u32 powerstate = readl(base + NvRegPowerState2);
1232
1233 /* need to perform hw phy reset */
1234 powerstate |= NVREG_POWERSTATE2_PHY_RESET;
1235 writel(powerstate, base + NvRegPowerState2);
1236 msleep(25);
1237
1238 powerstate &= ~NVREG_POWERSTATE2_PHY_RESET;
1239 writel(powerstate, base + NvRegPowerState2);
1240 msleep(25);
1241
1242 reg = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, MII_READ);
1243 reg |= PHY_REALTEK_INIT9;
1244 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, reg))
1245 return PHY_ERROR;
1246 if (mii_rw(dev, np->phyaddr,
1247 PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT10))
1248 return PHY_ERROR;
1249 reg = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG7, MII_READ);
1250 if (!(reg & PHY_REALTEK_INIT11)) {
1251 reg |= PHY_REALTEK_INIT11;
1252 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG7, reg))
1253 return PHY_ERROR;
1254 }
1255 if (mii_rw(dev, np->phyaddr,
1256 PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1))
1257 return PHY_ERROR;
1258
1259 return 0;
1260}
1261
1262static int init_realtek_8201(struct net_device *dev, struct fe_priv *np)
1263{
1264 u32 phy_reserved;
1265
1266 if (np->driver_data & DEV_NEED_PHY_INIT_FIX) {
1267 phy_reserved = mii_rw(dev, np->phyaddr,
1268 PHY_REALTEK_INIT_REG6, MII_READ);
1269 phy_reserved |= PHY_REALTEK_INIT7;
1270 if (mii_rw(dev, np->phyaddr,
1271 PHY_REALTEK_INIT_REG6, phy_reserved))
1272 return PHY_ERROR;
1273 }
1274
1275 return 0;
1276}
1277
1278static int init_realtek_8201_cross(struct net_device *dev, struct fe_priv *np)
1279{
1280 u32 phy_reserved;
1281
1282 if (phy_cross == NV_CROSSOVER_DETECTION_DISABLED) {
1283 if (mii_rw(dev, np->phyaddr,
1284 PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3))
1285 return PHY_ERROR;
1286 phy_reserved = mii_rw(dev, np->phyaddr,
1287 PHY_REALTEK_INIT_REG2, MII_READ);
1288 phy_reserved &= ~PHY_REALTEK_INIT_MSK1;
1289 phy_reserved |= PHY_REALTEK_INIT3;
1290 if (mii_rw(dev, np->phyaddr,
1291 PHY_REALTEK_INIT_REG2, phy_reserved))
1292 return PHY_ERROR;
1293 if (mii_rw(dev, np->phyaddr,
1294 PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1))
1295 return PHY_ERROR;
1296 }
1297
1298 return 0;
1299}
1300
1301static int init_cicada(struct net_device *dev, struct fe_priv *np,
1302 u32 phyinterface)
1303{
1304 u32 phy_reserved;
1305
1306 if (phyinterface & PHY_RGMII) {
1307 phy_reserved = mii_rw(dev, np->phyaddr, MII_RESV1, MII_READ);
1308 phy_reserved &= ~(PHY_CICADA_INIT1 | PHY_CICADA_INIT2);
1309 phy_reserved |= (PHY_CICADA_INIT3 | PHY_CICADA_INIT4);
1310 if (mii_rw(dev, np->phyaddr, MII_RESV1, phy_reserved))
1311 return PHY_ERROR;
1312 phy_reserved = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
1313 phy_reserved |= PHY_CICADA_INIT5;
1314 if (mii_rw(dev, np->phyaddr, MII_NCONFIG, phy_reserved))
1315 return PHY_ERROR;
1316 }
1317 phy_reserved = mii_rw(dev, np->phyaddr, MII_SREVISION, MII_READ);
1318 phy_reserved |= PHY_CICADA_INIT6;
1319 if (mii_rw(dev, np->phyaddr, MII_SREVISION, phy_reserved))
1320 return PHY_ERROR;
1321
1322 return 0;
1323}
1324
1325static int init_vitesse(struct net_device *dev, struct fe_priv *np)
1326{
1327 u32 phy_reserved;
1328
1329 if (mii_rw(dev, np->phyaddr,
1330 PHY_VITESSE_INIT_REG1, PHY_VITESSE_INIT1))
1331 return PHY_ERROR;
1332 if (mii_rw(dev, np->phyaddr,
1333 PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT2))
1334 return PHY_ERROR;
1335 phy_reserved = mii_rw(dev, np->phyaddr,
1336 PHY_VITESSE_INIT_REG4, MII_READ);
1337 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved))
1338 return PHY_ERROR;
1339 phy_reserved = mii_rw(dev, np->phyaddr,
1340 PHY_VITESSE_INIT_REG3, MII_READ);
1341 phy_reserved &= ~PHY_VITESSE_INIT_MSK1;
1342 phy_reserved |= PHY_VITESSE_INIT3;
1343 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved))
1344 return PHY_ERROR;
1345 if (mii_rw(dev, np->phyaddr,
1346 PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT4))
1347 return PHY_ERROR;
1348 if (mii_rw(dev, np->phyaddr,
1349 PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT5))
1350 return PHY_ERROR;
1351 phy_reserved = mii_rw(dev, np->phyaddr,
1352 PHY_VITESSE_INIT_REG4, MII_READ);
1353 phy_reserved &= ~PHY_VITESSE_INIT_MSK1;
1354 phy_reserved |= PHY_VITESSE_INIT3;
1355 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved))
1356 return PHY_ERROR;
1357 phy_reserved = mii_rw(dev, np->phyaddr,
1358 PHY_VITESSE_INIT_REG3, MII_READ);
1359 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved))
1360 return PHY_ERROR;
1361 if (mii_rw(dev, np->phyaddr,
1362 PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT6))
1363 return PHY_ERROR;
1364 if (mii_rw(dev, np->phyaddr,
1365 PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT7))
1366 return PHY_ERROR;
1367 phy_reserved = mii_rw(dev, np->phyaddr,
1368 PHY_VITESSE_INIT_REG4, MII_READ);
1369 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved))
1370 return PHY_ERROR;
1371 phy_reserved = mii_rw(dev, np->phyaddr,
1372 PHY_VITESSE_INIT_REG3, MII_READ);
1373 phy_reserved &= ~PHY_VITESSE_INIT_MSK2;
1374 phy_reserved |= PHY_VITESSE_INIT8;
1375 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved))
1376 return PHY_ERROR;
1377 if (mii_rw(dev, np->phyaddr,
1378 PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT9))
1379 return PHY_ERROR;
1380 if (mii_rw(dev, np->phyaddr,
1381 PHY_VITESSE_INIT_REG1, PHY_VITESSE_INIT10))
1382 return PHY_ERROR;
1383
1384 return 0;
1385}
1386
Linus Torvalds1da177e2005-04-16 15:20:36 -07001387static int phy_init(struct net_device *dev)
1388{
1389 struct fe_priv *np = get_nvpriv(dev);
1390 u8 __iomem *base = get_hwbase(dev);
Joe Perchescd663282010-11-29 07:41:59 +00001391 u32 phyinterface;
1392 u32 mii_status, mii_control, mii_control_1000, reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001393
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001394 /* phy errata for E3016 phy */
1395 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
1396 reg = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
1397 reg &= ~PHY_MARVELL_E3016_INITMASK;
1398 if (mii_rw(dev, np->phyaddr, MII_NCONFIG, reg)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001399 netdev_info(dev, "%s: phy write to errata reg failed\n",
1400 pci_name(np->pci_dev));
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001401 return PHY_ERROR;
1402 }
1403 }
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -04001404 if (np->phy_oui == PHY_OUI_REALTEK) {
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001405 if (np->phy_model == PHY_MODEL_REALTEK_8211 &&
1406 np->phy_rev == PHY_REV_REALTEK_8211B) {
Joe Perchescd663282010-11-29 07:41:59 +00001407 if (init_realtek_8211b(dev, np)) {
1408 netdev_info(dev, "%s: phy init failed\n",
1409 pci_name(np->pci_dev));
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001410 return PHY_ERROR;
Joe Perchescd663282010-11-29 07:41:59 +00001411 }
Joe Perchesc41d41e2010-11-29 07:41:58 +00001412 } else if (np->phy_model == PHY_MODEL_REALTEK_8211 &&
1413 np->phy_rev == PHY_REV_REALTEK_8211C) {
Joe Perchescd663282010-11-29 07:41:59 +00001414 if (init_realtek_8211c(dev, np)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001415 netdev_info(dev, "%s: phy init failed\n",
1416 pci_name(np->pci_dev));
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -04001417 return PHY_ERROR;
1418 }
Joe Perchescd663282010-11-29 07:41:59 +00001419 } else if (np->phy_model == PHY_MODEL_REALTEK_8201) {
1420 if (init_realtek_8201(dev, np)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001421 netdev_info(dev, "%s: phy init failed\n",
1422 pci_name(np->pci_dev));
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -04001423 return PHY_ERROR;
1424 }
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -04001425 }
1426 }
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001427
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428 /* set advertise register */
1429 reg = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Joe Perchescd663282010-11-29 07:41:59 +00001430 reg |= (ADVERTISE_10HALF | ADVERTISE_10FULL |
1431 ADVERTISE_100HALF | ADVERTISE_100FULL |
1432 ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001433 if (mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001434 netdev_info(dev, "%s: phy write to advertise failed\n",
1435 pci_name(np->pci_dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001436 return PHY_ERROR;
1437 }
1438
1439 /* get phy interface type */
1440 phyinterface = readl(base + NvRegPhyInterface);
1441
1442 /* see if gigabit phy */
1443 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
1444 if (mii_status & PHY_GIGABIT) {
1445 np->gigabit = PHY_GIGABIT;
Joe Perchescd663282010-11-29 07:41:59 +00001446 mii_control_1000 = mii_rw(dev, np->phyaddr,
1447 MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001448 mii_control_1000 &= ~ADVERTISE_1000HALF;
1449 if (phyinterface & PHY_RGMII)
1450 mii_control_1000 |= ADVERTISE_1000FULL;
1451 else
1452 mii_control_1000 &= ~ADVERTISE_1000FULL;
1453
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001454 if (mii_rw(dev, np->phyaddr, MII_CTRL1000, mii_control_1000)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001455 netdev_info(dev, "%s: phy init failed\n",
1456 pci_name(np->pci_dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001457 return PHY_ERROR;
1458 }
Szymon Janc78aea4f2010-11-27 08:39:43 +00001459 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001460 np->gigabit = 0;
1461
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001462 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1463 mii_control |= BMCR_ANENABLE;
1464
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -04001465 if (np->phy_oui == PHY_OUI_REALTEK &&
1466 np->phy_model == PHY_MODEL_REALTEK_8211 &&
1467 np->phy_rev == PHY_REV_REALTEK_8211C) {
1468 /* start autoneg since we already performed hw reset above */
1469 mii_control |= BMCR_ANRESTART;
1470 if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001471 netdev_info(dev, "%s: phy init failed\n",
1472 pci_name(np->pci_dev));
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -04001473 return PHY_ERROR;
1474 }
1475 } else {
1476 /* reset the phy
1477 * (certain phys need bmcr to be setup with reset)
1478 */
1479 if (phy_reset(dev, mii_control)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001480 netdev_info(dev, "%s: phy reset failed\n",
1481 pci_name(np->pci_dev));
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -04001482 return PHY_ERROR;
1483 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484 }
1485
1486 /* phy vendor specific configuration */
Joe Perchescd663282010-11-29 07:41:59 +00001487 if ((np->phy_oui == PHY_OUI_CICADA)) {
1488 if (init_cicada(dev, np, phyinterface)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001489 netdev_info(dev, "%s: phy init failed\n",
1490 pci_name(np->pci_dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001491 return PHY_ERROR;
1492 }
Joe Perchescd663282010-11-29 07:41:59 +00001493 } else if (np->phy_oui == PHY_OUI_VITESSE) {
1494 if (init_vitesse(dev, np)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001495 netdev_info(dev, "%s: phy init failed\n",
1496 pci_name(np->pci_dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001497 return PHY_ERROR;
1498 }
Joe Perchescd663282010-11-29 07:41:59 +00001499 } else if (np->phy_oui == PHY_OUI_REALTEK) {
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001500 if (np->phy_model == PHY_MODEL_REALTEK_8211 &&
1501 np->phy_rev == PHY_REV_REALTEK_8211B) {
1502 /* reset could have cleared these out, set them back */
Joe Perchescd663282010-11-29 07:41:59 +00001503 if (init_realtek_8211b(dev, np)) {
1504 netdev_info(dev, "%s: phy init failed\n",
1505 pci_name(np->pci_dev));
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001506 return PHY_ERROR;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001507 }
Joe Perchescd663282010-11-29 07:41:59 +00001508 } else if (np->phy_model == PHY_MODEL_REALTEK_8201) {
1509 if (init_realtek_8201(dev, np) ||
1510 init_realtek_8201_cross(dev, np)) {
1511 netdev_info(dev, "%s: phy init failed\n",
1512 pci_name(np->pci_dev));
1513 return PHY_ERROR;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001514 }
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -04001515 }
1516 }
1517
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001518 /* some phys clear out pause advertisement on reset, set it back */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001519 mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
Ed Swierkcb52deb2008-12-01 12:24:43 +00001521 /* restart auto negotiation, power down phy */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001522 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ed Swierk5a9a8e32009-06-02 00:19:52 -07001523 mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE);
Szymon Janc78aea4f2010-11-27 08:39:43 +00001524 if (phy_power_down)
Ed Swierk5a9a8e32009-06-02 00:19:52 -07001525 mii_control |= BMCR_PDOWN;
Szymon Janc78aea4f2010-11-27 08:39:43 +00001526 if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 return PHY_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001528
1529 return 0;
1530}
1531
1532static void nv_start_rx(struct net_device *dev)
1533{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001534 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001536 u32 rx_ctrl = readl(base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
Linus Torvalds1da177e2005-04-16 15:20:36 -07001538 /* Already running? Stop it. */
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001539 if ((readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) && !np->mac_in_use) {
1540 rx_ctrl &= ~NVREG_RCVCTL_START;
1541 writel(rx_ctrl, base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001542 pci_push(base);
1543 }
1544 writel(np->linkspeed, base + NvRegLinkSpeed);
1545 pci_push(base);
Szymon Janc78aea4f2010-11-27 08:39:43 +00001546 rx_ctrl |= NVREG_RCVCTL_START;
1547 if (np->mac_in_use)
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001548 rx_ctrl &= ~NVREG_RCVCTL_RX_PATH_EN;
1549 writel(rx_ctrl, base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 pci_push(base);
1551}
1552
1553static void nv_stop_rx(struct net_device *dev)
1554{
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001555 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001557 u32 rx_ctrl = readl(base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001559 if (!np->mac_in_use)
1560 rx_ctrl &= ~NVREG_RCVCTL_START;
1561 else
1562 rx_ctrl |= NVREG_RCVCTL_RX_PATH_EN;
1563 writel(rx_ctrl, base + NvRegReceiverControl);
Joe Perches344d0dc2010-11-29 07:41:52 +00001564 if (reg_delay(dev, NvRegReceiverStatus, NVREG_RCVSTAT_BUSY, 0,
1565 NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX))
Joe Perches1d397f32010-11-29 07:41:57 +00001566 netdev_info(dev, "%s: ReceiverStatus remained busy\n",
1567 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001568
1569 udelay(NV_RXSTOP_DELAY2);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001570 if (!np->mac_in_use)
1571 writel(0, base + NvRegLinkSpeed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572}
1573
1574static void nv_start_tx(struct net_device *dev)
1575{
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001576 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001577 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001578 u32 tx_ctrl = readl(base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001580 tx_ctrl |= NVREG_XMITCTL_START;
1581 if (np->mac_in_use)
1582 tx_ctrl &= ~NVREG_XMITCTL_TX_PATH_EN;
1583 writel(tx_ctrl, base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001584 pci_push(base);
1585}
1586
1587static void nv_stop_tx(struct net_device *dev)
1588{
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001589 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001590 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001591 u32 tx_ctrl = readl(base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001592
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001593 if (!np->mac_in_use)
1594 tx_ctrl &= ~NVREG_XMITCTL_START;
1595 else
1596 tx_ctrl |= NVREG_XMITCTL_TX_PATH_EN;
1597 writel(tx_ctrl, base + NvRegTransmitterControl);
Joe Perches344d0dc2010-11-29 07:41:52 +00001598 if (reg_delay(dev, NvRegTransmitterStatus, NVREG_XMITSTAT_BUSY, 0,
1599 NV_TXSTOP_DELAY1, NV_TXSTOP_DELAY1MAX))
Joe Perches1d397f32010-11-29 07:41:57 +00001600 netdev_info(dev, "%s: TransmitterStatus remained busy\n",
1601 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602
1603 udelay(NV_TXSTOP_DELAY2);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001604 if (!np->mac_in_use)
1605 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV,
1606 base + NvRegTransmitPoll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607}
1608
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001609static void nv_start_rxtx(struct net_device *dev)
1610{
1611 nv_start_rx(dev);
1612 nv_start_tx(dev);
1613}
1614
1615static void nv_stop_rxtx(struct net_device *dev)
1616{
1617 nv_stop_rx(dev);
1618 nv_stop_tx(dev);
1619}
1620
Linus Torvalds1da177e2005-04-16 15:20:36 -07001621static void nv_txrx_reset(struct net_device *dev)
1622{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001623 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 u8 __iomem *base = get_hwbase(dev);
1625
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001626 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627 pci_push(base);
1628 udelay(NV_TXRX_RESET_DELAY);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001629 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001630 pci_push(base);
1631}
1632
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001633static void nv_mac_reset(struct net_device *dev)
1634{
1635 struct fe_priv *np = netdev_priv(dev);
1636 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdulla4e84f9b2008-02-04 15:14:09 -05001637 u32 temp1, temp2, temp3;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001638
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001639 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
1640 pci_push(base);
Ayaz Abdulla4e84f9b2008-02-04 15:14:09 -05001641
1642 /* save registers since they will be cleared on reset */
1643 temp1 = readl(base + NvRegMacAddrA);
1644 temp2 = readl(base + NvRegMacAddrB);
1645 temp3 = readl(base + NvRegTransmitPoll);
1646
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001647 writel(NVREG_MAC_RESET_ASSERT, base + NvRegMacReset);
1648 pci_push(base);
1649 udelay(NV_MAC_RESET_DELAY);
1650 writel(0, base + NvRegMacReset);
1651 pci_push(base);
1652 udelay(NV_MAC_RESET_DELAY);
Ayaz Abdulla4e84f9b2008-02-04 15:14:09 -05001653
1654 /* restore saved registers */
1655 writel(temp1, base + NvRegMacAddrA);
1656 writel(temp2, base + NvRegMacAddrB);
1657 writel(temp3, base + NvRegTransmitPoll);
1658
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001659 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
1660 pci_push(base);
1661}
1662
david decotignyf5d827a2011-11-16 12:15:13 +00001663/* Caller must appropriately lock netdev_priv(dev)->hwstats_lock */
1664static void nv_update_stats(struct net_device *dev)
Ayaz Abdulla57fff692007-01-23 12:27:00 -05001665{
1666 struct fe_priv *np = netdev_priv(dev);
1667 u8 __iomem *base = get_hwbase(dev);
1668
david decotignyf5d827a2011-11-16 12:15:13 +00001669 /* If it happens that this is run in top-half context, then
1670 * replace the spin_lock of hwstats_lock with
1671 * spin_lock_irqsave() in calling functions. */
1672 WARN_ONCE(in_irq(), "forcedeth: estats spin_lock(_bh) from top-half");
1673 assert_spin_locked(&np->hwstats_lock);
1674
1675 /* query hardware */
Ayaz Abdulla57fff692007-01-23 12:27:00 -05001676 np->estats.tx_bytes += readl(base + NvRegTxCnt);
1677 np->estats.tx_zero_rexmt += readl(base + NvRegTxZeroReXmt);
1678 np->estats.tx_one_rexmt += readl(base + NvRegTxOneReXmt);
1679 np->estats.tx_many_rexmt += readl(base + NvRegTxManyReXmt);
1680 np->estats.tx_late_collision += readl(base + NvRegTxLateCol);
1681 np->estats.tx_fifo_errors += readl(base + NvRegTxUnderflow);
1682 np->estats.tx_carrier_errors += readl(base + NvRegTxLossCarrier);
1683 np->estats.tx_excess_deferral += readl(base + NvRegTxExcessDef);
1684 np->estats.tx_retry_error += readl(base + NvRegTxRetryErr);
1685 np->estats.rx_frame_error += readl(base + NvRegRxFrameErr);
1686 np->estats.rx_extra_byte += readl(base + NvRegRxExtraByte);
1687 np->estats.rx_late_collision += readl(base + NvRegRxLateCol);
1688 np->estats.rx_runt += readl(base + NvRegRxRunt);
1689 np->estats.rx_frame_too_long += readl(base + NvRegRxFrameTooLong);
1690 np->estats.rx_over_errors += readl(base + NvRegRxOverflow);
1691 np->estats.rx_crc_errors += readl(base + NvRegRxFCSErr);
1692 np->estats.rx_frame_align_error += readl(base + NvRegRxFrameAlignErr);
1693 np->estats.rx_length_error += readl(base + NvRegRxLenErr);
1694 np->estats.rx_unicast += readl(base + NvRegRxUnicast);
1695 np->estats.rx_multicast += readl(base + NvRegRxMulticast);
1696 np->estats.rx_broadcast += readl(base + NvRegRxBroadcast);
1697 np->estats.rx_packets =
1698 np->estats.rx_unicast +
1699 np->estats.rx_multicast +
1700 np->estats.rx_broadcast;
1701 np->estats.rx_errors_total =
1702 np->estats.rx_crc_errors +
1703 np->estats.rx_over_errors +
1704 np->estats.rx_frame_error +
1705 (np->estats.rx_frame_align_error - np->estats.rx_extra_byte) +
1706 np->estats.rx_late_collision +
1707 np->estats.rx_runt +
1708 np->estats.rx_frame_too_long;
1709 np->estats.tx_errors_total =
1710 np->estats.tx_late_collision +
1711 np->estats.tx_fifo_errors +
1712 np->estats.tx_carrier_errors +
1713 np->estats.tx_excess_deferral +
1714 np->estats.tx_retry_error;
1715
1716 if (np->driver_data & DEV_HAS_STATISTICS_V2) {
1717 np->estats.tx_deferral += readl(base + NvRegTxDef);
1718 np->estats.tx_packets += readl(base + NvRegTxFrame);
1719 np->estats.rx_bytes += readl(base + NvRegRxCnt);
1720 np->estats.tx_pause += readl(base + NvRegTxPause);
1721 np->estats.rx_pause += readl(base + NvRegRxPause);
1722 np->estats.rx_drop_frame += readl(base + NvRegRxDropFrame);
Mandeep Baines0bdfea82011-11-05 14:38:23 +00001723 np->estats.rx_errors_total += np->estats.rx_drop_frame;
Ayaz Abdulla57fff692007-01-23 12:27:00 -05001724 }
Ayaz Abdulla9c662432008-08-06 12:11:42 -04001725
1726 if (np->driver_data & DEV_HAS_STATISTICS_V3) {
1727 np->estats.tx_unicast += readl(base + NvRegTxUnicast);
1728 np->estats.tx_multicast += readl(base + NvRegTxMulticast);
1729 np->estats.tx_broadcast += readl(base + NvRegTxBroadcast);
1730 }
Ayaz Abdulla57fff692007-01-23 12:27:00 -05001731}
1732
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733/*
david decotignyf5d827a2011-11-16 12:15:13 +00001734 * nv_get_stats64: dev->ndo_get_stats64 function
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 * Get latest stats value from the nic.
1736 * Called with read_lock(&dev_base_lock) held for read -
1737 * only synchronized against unregister_netdevice.
1738 */
david decotignyf5d827a2011-11-16 12:15:13 +00001739static struct rtnl_link_stats64*
1740nv_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *storage)
1741 __acquires(&netdev_priv(dev)->hwstats_lock)
1742 __releases(&netdev_priv(dev)->hwstats_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001744 struct fe_priv *np = netdev_priv(dev);
david decotignyf5d827a2011-11-16 12:15:13 +00001745 unsigned int syncp_start;
1746
1747 /*
1748 * Note: because HW stats are not always available and for
1749 * consistency reasons, the following ifconfig stats are
1750 * managed by software: rx_bytes, tx_bytes, rx_packets and
1751 * tx_packets. The related hardware stats reported by ethtool
1752 * should be equivalent to these ifconfig stats, with 4
1753 * additional bytes per packet (Ethernet FCS CRC), except for
1754 * tx_packets when TSO kicks in.
1755 */
1756
1757 /* software stats */
1758 do {
david decotigny505a4672011-11-17 09:38:23 +00001759 syncp_start = u64_stats_fetch_begin_bh(&np->swstats_rx_syncp);
david decotignyf5d827a2011-11-16 12:15:13 +00001760 storage->rx_packets = np->stat_rx_packets;
1761 storage->rx_bytes = np->stat_rx_bytes;
david decotigny0a1f2222011-11-16 12:15:14 +00001762 storage->rx_dropped = np->stat_rx_dropped;
david decotignyf5d827a2011-11-16 12:15:13 +00001763 storage->rx_missed_errors = np->stat_rx_missed_errors;
david decotigny505a4672011-11-17 09:38:23 +00001764 } while (u64_stats_fetch_retry_bh(&np->swstats_rx_syncp, syncp_start));
david decotignyf5d827a2011-11-16 12:15:13 +00001765
1766 do {
david decotigny505a4672011-11-17 09:38:23 +00001767 syncp_start = u64_stats_fetch_begin_bh(&np->swstats_tx_syncp);
david decotignyf5d827a2011-11-16 12:15:13 +00001768 storage->tx_packets = np->stat_tx_packets;
1769 storage->tx_bytes = np->stat_tx_bytes;
1770 storage->tx_dropped = np->stat_tx_dropped;
david decotigny505a4672011-11-17 09:38:23 +00001771 } while (u64_stats_fetch_retry_bh(&np->swstats_tx_syncp, syncp_start));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772
Ayaz Abdulla21828162007-01-23 12:27:21 -05001773 /* If the nic supports hw counters then retrieve latest values */
david decotignyf5d827a2011-11-16 12:15:13 +00001774 if (np->driver_data & DEV_HAS_STATISTICS_V123) {
1775 spin_lock_bh(&np->hwstats_lock);
Ayaz Abdulla21828162007-01-23 12:27:21 -05001776
david decotignyf5d827a2011-11-16 12:15:13 +00001777 nv_update_stats(dev);
david decotigny674aee32011-11-16 12:15:07 +00001778
david decotignyf5d827a2011-11-16 12:15:13 +00001779 /* generic stats */
1780 storage->rx_errors = np->estats.rx_errors_total;
1781 storage->tx_errors = np->estats.tx_errors_total;
1782
1783 /* meaningful only when NIC supports stats v3 */
1784 storage->multicast = np->estats.rx_multicast;
1785
1786 /* detailed rx_errors */
1787 storage->rx_length_errors = np->estats.rx_length_error;
1788 storage->rx_over_errors = np->estats.rx_over_errors;
1789 storage->rx_crc_errors = np->estats.rx_crc_errors;
1790 storage->rx_frame_errors = np->estats.rx_frame_align_error;
1791 storage->rx_fifo_errors = np->estats.rx_drop_frame;
1792
1793 /* detailed tx_errors */
1794 storage->tx_carrier_errors = np->estats.tx_carrier_errors;
1795 storage->tx_fifo_errors = np->estats.tx_fifo_errors;
1796
1797 spin_unlock_bh(&np->hwstats_lock);
Ayaz Abdulla21828162007-01-23 12:27:21 -05001798 }
Jeff Garzik8148ff42007-10-16 20:56:09 -04001799
david decotignyf5d827a2011-11-16 12:15:13 +00001800 return storage;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001801}
1802
1803/*
1804 * nv_alloc_rx: fill rx ring entries.
1805 * Return 1 if the allocations for the skbs failed and the
1806 * rx engine is without Available descriptors
1807 */
1808static int nv_alloc_rx(struct net_device *dev)
1809{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001810 struct fe_priv *np = netdev_priv(dev);
Szymon Janc78aea4f2010-11-27 08:39:43 +00001811 struct ring_desc *less_rx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001812
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001813 less_rx = np->get_rx.orig;
1814 if (less_rx-- == np->first_rx.orig)
1815 less_rx = np->last_rx.orig;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001816
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001817 while (np->put_rx.orig != less_rx) {
1818 struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001819 if (skb) {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001820 np->put_rx_ctx->skb = skb;
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001821 np->put_rx_ctx->dma = pci_map_single(np->pci_dev,
1822 skb->data,
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001823 skb_tailroom(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001824 PCI_DMA_FROMDEVICE);
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001825 np->put_rx_ctx->dma_len = skb_tailroom(skb);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001826 np->put_rx.orig->buf = cpu_to_le32(np->put_rx_ctx->dma);
1827 wmb();
1828 np->put_rx.orig->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX_AVAIL);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001829 if (unlikely(np->put_rx.orig++ == np->last_rx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001830 np->put_rx.orig = np->first_rx.orig;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001831 if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001832 np->put_rx_ctx = np->first_rx_ctx;
david decotigny0a1f2222011-11-16 12:15:14 +00001833 } else {
1834 u64_stats_update_begin(&np->swstats_rx_syncp);
1835 np->stat_rx_dropped++;
1836 u64_stats_update_end(&np->swstats_rx_syncp);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001837 return 1;
david decotigny0a1f2222011-11-16 12:15:14 +00001838 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001839 }
1840 return 0;
1841}
1842
1843static int nv_alloc_rx_optimized(struct net_device *dev)
1844{
1845 struct fe_priv *np = netdev_priv(dev);
Szymon Janc78aea4f2010-11-27 08:39:43 +00001846 struct ring_desc_ex *less_rx;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001847
1848 less_rx = np->get_rx.ex;
1849 if (less_rx-- == np->first_rx.ex)
1850 less_rx = np->last_rx.ex;
1851
1852 while (np->put_rx.ex != less_rx) {
1853 struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD);
1854 if (skb) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001855 np->put_rx_ctx->skb = skb;
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001856 np->put_rx_ctx->dma = pci_map_single(np->pci_dev,
1857 skb->data,
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001858 skb_tailroom(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001859 PCI_DMA_FROMDEVICE);
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001860 np->put_rx_ctx->dma_len = skb_tailroom(skb);
Al Viro5bb7ea22007-12-09 16:06:41 +00001861 np->put_rx.ex->bufhigh = cpu_to_le32(dma_high(np->put_rx_ctx->dma));
1862 np->put_rx.ex->buflow = cpu_to_le32(dma_low(np->put_rx_ctx->dma));
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001863 wmb();
1864 np->put_rx.ex->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX2_AVAIL);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001865 if (unlikely(np->put_rx.ex++ == np->last_rx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001866 np->put_rx.ex = np->first_rx.ex;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001867 if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001868 np->put_rx_ctx = np->first_rx_ctx;
david decotigny0a1f2222011-11-16 12:15:14 +00001869 } else {
1870 u64_stats_update_begin(&np->swstats_rx_syncp);
1871 np->stat_rx_dropped++;
1872 u64_stats_update_end(&np->swstats_rx_syncp);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001873 return 1;
david decotigny0a1f2222011-11-16 12:15:14 +00001874 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001875 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001876 return 0;
1877}
1878
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001879/* If rx bufs are exhausted called after 50ms to attempt to refresh */
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001880static void nv_do_rx_refill(unsigned long data)
1881{
1882 struct net_device *dev = (struct net_device *) data;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001883 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001884
1885 /* Just reschedule NAPI rx processing */
Ben Hutchings288379f2009-01-19 16:43:59 -08001886 napi_schedule(&np->napi);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001887}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001888
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001889static void nv_init_rx(struct net_device *dev)
Manfred Sprauld81c0982005-07-31 18:20:30 +02001890{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001891 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02001892 int i;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001893
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001894 np->get_rx = np->put_rx = np->first_rx = np->rx_ring;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001895
1896 if (!nv_optimized(np))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001897 np->last_rx.orig = &np->rx_ring.orig[np->rx_ring_size-1];
1898 else
1899 np->last_rx.ex = &np->rx_ring.ex[np->rx_ring_size-1];
1900 np->get_rx_ctx = np->put_rx_ctx = np->first_rx_ctx = np->rx_skb;
1901 np->last_rx_ctx = &np->rx_skb[np->rx_ring_size-1];
Manfred Sprauld81c0982005-07-31 18:20:30 +02001902
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001903 for (i = 0; i < np->rx_ring_size; i++) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001904 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001905 np->rx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001906 np->rx_ring.orig[i].buf = 0;
1907 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001908 np->rx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001909 np->rx_ring.ex[i].txvlan = 0;
1910 np->rx_ring.ex[i].bufhigh = 0;
1911 np->rx_ring.ex[i].buflow = 0;
1912 }
1913 np->rx_skb[i].skb = NULL;
1914 np->rx_skb[i].dma = 0;
1915 }
Manfred Sprauld81c0982005-07-31 18:20:30 +02001916}
1917
1918static void nv_init_tx(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001919{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001920 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001921 int i;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001922
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001923 np->get_tx = np->put_tx = np->first_tx = np->tx_ring;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001924
1925 if (!nv_optimized(np))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001926 np->last_tx.orig = &np->tx_ring.orig[np->tx_ring_size-1];
1927 else
1928 np->last_tx.ex = &np->tx_ring.ex[np->tx_ring_size-1];
1929 np->get_tx_ctx = np->put_tx_ctx = np->first_tx_ctx = np->tx_skb;
1930 np->last_tx_ctx = &np->tx_skb[np->tx_ring_size-1];
Tom Herbertb8bfca92011-11-28 16:33:23 +00001931 netdev_reset_queue(np->dev);
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001932 np->tx_pkts_in_progress = 0;
1933 np->tx_change_owner = NULL;
1934 np->tx_end_flip = NULL;
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00001935 np->tx_stop = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001936
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001937 for (i = 0; i < np->tx_ring_size; i++) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001938 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001939 np->tx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001940 np->tx_ring.orig[i].buf = 0;
1941 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001942 np->tx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001943 np->tx_ring.ex[i].txvlan = 0;
1944 np->tx_ring.ex[i].bufhigh = 0;
1945 np->tx_ring.ex[i].buflow = 0;
1946 }
1947 np->tx_skb[i].skb = NULL;
1948 np->tx_skb[i].dma = 0;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001949 np->tx_skb[i].dma_len = 0;
Eric Dumazet73a37072009-06-17 21:17:59 +00001950 np->tx_skb[i].dma_single = 0;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001951 np->tx_skb[i].first_tx_desc = NULL;
1952 np->tx_skb[i].next_tx_ctx = NULL;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001953 }
Manfred Sprauld81c0982005-07-31 18:20:30 +02001954}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001955
Manfred Sprauld81c0982005-07-31 18:20:30 +02001956static int nv_init_ring(struct net_device *dev)
1957{
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001958 struct fe_priv *np = netdev_priv(dev);
1959
Manfred Sprauld81c0982005-07-31 18:20:30 +02001960 nv_init_tx(dev);
1961 nv_init_rx(dev);
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001962
1963 if (!nv_optimized(np))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001964 return nv_alloc_rx(dev);
1965 else
1966 return nv_alloc_rx_optimized(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001967}
1968
Eric Dumazet73a37072009-06-17 21:17:59 +00001969static void nv_unmap_txskb(struct fe_priv *np, struct nv_skb_map *tx_skb)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001970{
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001971 if (tx_skb->dma) {
Eric Dumazet73a37072009-06-17 21:17:59 +00001972 if (tx_skb->dma_single)
1973 pci_unmap_single(np->pci_dev, tx_skb->dma,
1974 tx_skb->dma_len,
1975 PCI_DMA_TODEVICE);
1976 else
1977 pci_unmap_page(np->pci_dev, tx_skb->dma,
1978 tx_skb->dma_len,
1979 PCI_DMA_TODEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001980 tx_skb->dma = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001981 }
Eric Dumazet73a37072009-06-17 21:17:59 +00001982}
1983
1984static int nv_release_txskb(struct fe_priv *np, struct nv_skb_map *tx_skb)
1985{
1986 nv_unmap_txskb(np, tx_skb);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001987 if (tx_skb->skb) {
1988 dev_kfree_skb_any(tx_skb->skb);
1989 tx_skb->skb = NULL;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001990 return 1;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001991 }
Eric Dumazet73a37072009-06-17 21:17:59 +00001992 return 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001993}
1994
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995static void nv_drain_tx(struct net_device *dev)
1996{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001997 struct fe_priv *np = netdev_priv(dev);
1998 unsigned int i;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001999
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04002000 for (i = 0; i < np->tx_ring_size; i++) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002001 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002002 np->tx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002003 np->tx_ring.orig[i].buf = 0;
2004 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002005 np->tx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002006 np->tx_ring.ex[i].txvlan = 0;
2007 np->tx_ring.ex[i].bufhigh = 0;
2008 np->tx_ring.ex[i].buflow = 0;
2009 }
david decotignyf5d827a2011-11-16 12:15:13 +00002010 if (nv_release_txskb(np, &np->tx_skb[i])) {
2011 u64_stats_update_begin(&np->swstats_tx_syncp);
2012 np->stat_tx_dropped++;
2013 u64_stats_update_end(&np->swstats_tx_syncp);
2014 }
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002015 np->tx_skb[i].dma = 0;
2016 np->tx_skb[i].dma_len = 0;
Eric Dumazet73a37072009-06-17 21:17:59 +00002017 np->tx_skb[i].dma_single = 0;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002018 np->tx_skb[i].first_tx_desc = NULL;
2019 np->tx_skb[i].next_tx_ctx = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002020 }
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002021 np->tx_pkts_in_progress = 0;
2022 np->tx_change_owner = NULL;
2023 np->tx_end_flip = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024}
2025
2026static void nv_drain_rx(struct net_device *dev)
2027{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002028 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002029 int i;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002030
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04002031 for (i = 0; i < np->rx_ring_size; i++) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002032 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002033 np->rx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002034 np->rx_ring.orig[i].buf = 0;
2035 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002036 np->rx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002037 np->rx_ring.ex[i].txvlan = 0;
2038 np->rx_ring.ex[i].bufhigh = 0;
2039 np->rx_ring.ex[i].buflow = 0;
2040 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041 wmb();
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002042 if (np->rx_skb[i].skb) {
2043 pci_unmap_single(np->pci_dev, np->rx_skb[i].dma,
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07002044 (skb_end_pointer(np->rx_skb[i].skb) -
2045 np->rx_skb[i].skb->data),
2046 PCI_DMA_FROMDEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002047 dev_kfree_skb(np->rx_skb[i].skb);
2048 np->rx_skb[i].skb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049 }
2050 }
2051}
2052
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002053static void nv_drain_rxtx(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002054{
2055 nv_drain_tx(dev);
2056 nv_drain_rx(dev);
2057}
2058
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002059static inline u32 nv_get_empty_tx_slots(struct fe_priv *np)
2060{
2061 return (u32)(np->tx_ring_size - ((np->tx_ring_size + (np->put_tx_ctx - np->get_tx_ctx)) % np->tx_ring_size));
2062}
2063
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002064static void nv_legacybackoff_reseed(struct net_device *dev)
2065{
2066 u8 __iomem *base = get_hwbase(dev);
2067 u32 reg;
2068 u32 low;
2069 int tx_status = 0;
2070
2071 reg = readl(base + NvRegSlotTime) & ~NVREG_SLOTTIME_MASK;
2072 get_random_bytes(&low, sizeof(low));
2073 reg |= low & NVREG_SLOTTIME_MASK;
2074
2075 /* Need to stop tx before change takes effect.
2076 * Caller has already gained np->lock.
2077 */
2078 tx_status = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_START;
2079 if (tx_status)
2080 nv_stop_tx(dev);
2081 nv_stop_rx(dev);
2082 writel(reg, base + NvRegSlotTime);
2083 if (tx_status)
2084 nv_start_tx(dev);
2085 nv_start_rx(dev);
2086}
2087
2088/* Gear Backoff Seeds */
2089#define BACKOFF_SEEDSET_ROWS 8
2090#define BACKOFF_SEEDSET_LFSRS 15
2091
2092/* Known Good seed sets */
2093static const u32 main_seedset[BACKOFF_SEEDSET_ROWS][BACKOFF_SEEDSET_LFSRS] = {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002094 {145, 155, 165, 175, 185, 196, 235, 245, 255, 265, 275, 285, 660, 690, 874},
2095 {245, 255, 265, 575, 385, 298, 335, 345, 355, 366, 375, 385, 761, 790, 974},
2096 {145, 155, 165, 175, 185, 196, 235, 245, 255, 265, 275, 285, 660, 690, 874},
2097 {245, 255, 265, 575, 385, 298, 335, 345, 355, 366, 375, 386, 761, 790, 974},
2098 {266, 265, 276, 585, 397, 208, 345, 355, 365, 376, 385, 396, 771, 700, 984},
2099 {266, 265, 276, 586, 397, 208, 346, 355, 365, 376, 285, 396, 771, 700, 984},
2100 {366, 365, 376, 686, 497, 308, 447, 455, 466, 476, 485, 496, 871, 800, 84},
2101 {466, 465, 476, 786, 597, 408, 547, 555, 566, 576, 585, 597, 971, 900, 184} };
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002102
2103static const u32 gear_seedset[BACKOFF_SEEDSET_ROWS][BACKOFF_SEEDSET_LFSRS] = {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002104 {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
2105 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
2106 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 397},
2107 {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
2108 {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
2109 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
2110 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
2111 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395} };
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002112
2113static void nv_gear_backoff_reseed(struct net_device *dev)
2114{
2115 u8 __iomem *base = get_hwbase(dev);
2116 u32 miniseed1, miniseed2, miniseed2_reversed, miniseed3, miniseed3_reversed;
2117 u32 temp, seedset, combinedSeed;
2118 int i;
2119
2120 /* Setup seed for free running LFSR */
2121 /* We are going to read the time stamp counter 3 times
2122 and swizzle bits around to increase randomness */
2123 get_random_bytes(&miniseed1, sizeof(miniseed1));
2124 miniseed1 &= 0x0fff;
2125 if (miniseed1 == 0)
2126 miniseed1 = 0xabc;
2127
2128 get_random_bytes(&miniseed2, sizeof(miniseed2));
2129 miniseed2 &= 0x0fff;
2130 if (miniseed2 == 0)
2131 miniseed2 = 0xabc;
2132 miniseed2_reversed =
2133 ((miniseed2 & 0xF00) >> 8) |
2134 (miniseed2 & 0x0F0) |
2135 ((miniseed2 & 0x00F) << 8);
2136
2137 get_random_bytes(&miniseed3, sizeof(miniseed3));
2138 miniseed3 &= 0x0fff;
2139 if (miniseed3 == 0)
2140 miniseed3 = 0xabc;
2141 miniseed3_reversed =
2142 ((miniseed3 & 0xF00) >> 8) |
2143 (miniseed3 & 0x0F0) |
2144 ((miniseed3 & 0x00F) << 8);
2145
2146 combinedSeed = ((miniseed1 ^ miniseed2_reversed) << 12) |
2147 (miniseed2 ^ miniseed3_reversed);
2148
2149 /* Seeds can not be zero */
2150 if ((combinedSeed & NVREG_BKOFFCTRL_SEED_MASK) == 0)
2151 combinedSeed |= 0x08;
2152 if ((combinedSeed & (NVREG_BKOFFCTRL_SEED_MASK << NVREG_BKOFFCTRL_GEAR)) == 0)
2153 combinedSeed |= 0x8000;
2154
2155 /* No need to disable tx here */
2156 temp = NVREG_BKOFFCTRL_DEFAULT | (0 << NVREG_BKOFFCTRL_SELECT);
2157 temp |= combinedSeed & NVREG_BKOFFCTRL_SEED_MASK;
2158 temp |= combinedSeed >> NVREG_BKOFFCTRL_GEAR;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002159 writel(temp, base + NvRegBackOffControl);
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002160
Szymon Janc78aea4f2010-11-27 08:39:43 +00002161 /* Setup seeds for all gear LFSRs. */
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002162 get_random_bytes(&seedset, sizeof(seedset));
2163 seedset = seedset % BACKOFF_SEEDSET_ROWS;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002164 for (i = 1; i <= BACKOFF_SEEDSET_LFSRS; i++) {
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002165 temp = NVREG_BKOFFCTRL_DEFAULT | (i << NVREG_BKOFFCTRL_SELECT);
2166 temp |= main_seedset[seedset][i-1] & 0x3ff;
2167 temp |= ((gear_seedset[seedset][i-1] & 0x3ff) << NVREG_BKOFFCTRL_GEAR);
2168 writel(temp, base + NvRegBackOffControl);
2169 }
2170}
2171
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172/*
2173 * nv_start_xmit: dev->hard_start_xmit function
Herbert Xu932ff272006-06-09 12:20:56 -07002174 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002175 */
Stephen Hemminger613573252009-08-31 19:50:58 +00002176static netdev_tx_t nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002177{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002178 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002179 u32 tx_flags = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002180 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
2181 unsigned int fragments = skb_shinfo(skb)->nr_frags;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002182 unsigned int i;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002183 u32 offset = 0;
2184 u32 bcnt;
Eric Dumazete743d312010-04-14 15:59:40 -07002185 u32 size = skb_headlen(skb);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002186 u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002187 u32 empty_slots;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002188 struct ring_desc *put_tx;
2189 struct ring_desc *start_tx;
2190 struct ring_desc *prev_tx;
2191 struct nv_skb_map *prev_tx_ctx;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002192 unsigned long flags;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002193
2194 /* add fragments to entries count */
2195 for (i = 0; i < fragments; i++) {
david decotignye45a6182011-11-05 14:38:24 +00002196 u32 frag_size = skb_frag_size(&skb_shinfo(skb)->frags[i]);
Eric Dumazet9e903e02011-10-18 21:00:24 +00002197
david decotignye45a6182011-11-05 14:38:24 +00002198 entries += (frag_size >> NV_TX2_TSO_MAX_SHIFT) +
2199 ((frag_size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002200 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002201
Ayaz Abdulla001eb842009-01-09 11:03:44 +00002202 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002203 empty_slots = nv_get_empty_tx_slots(np);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002204 if (unlikely(empty_slots <= entries)) {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002205 netif_stop_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002206 np->tx_stop = 1;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002207 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002208 return NETDEV_TX_BUSY;
2209 }
Ayaz Abdulla001eb842009-01-09 11:03:44 +00002210 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002211
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002212 start_tx = put_tx = np->put_tx.orig;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002213
Ayaz Abdullafa454592006-01-05 22:45:45 -08002214 /* setup the header buffer */
2215 do {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002216 prev_tx = put_tx;
2217 prev_tx_ctx = np->put_tx_ctx;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002218 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002219 np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
Ayaz Abdullafa454592006-01-05 22:45:45 -08002220 PCI_DMA_TODEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002221 np->put_tx_ctx->dma_len = bcnt;
Eric Dumazet73a37072009-06-17 21:17:59 +00002222 np->put_tx_ctx->dma_single = 1;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002223 put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
2224 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002225
Ayaz Abdullafa454592006-01-05 22:45:45 -08002226 tx_flags = np->tx_flags;
2227 offset += bcnt;
2228 size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002229 if (unlikely(put_tx++ == np->last_tx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002230 put_tx = np->first_tx.orig;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002231 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002232 np->put_tx_ctx = np->first_tx_ctx;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002233 } while (size);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002234
2235 /* setup the fragments */
2236 for (i = 0; i < fragments; i++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00002237 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
david decotignye45a6182011-11-05 14:38:24 +00002238 u32 frag_size = skb_frag_size(frag);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002239 offset = 0;
2240
2241 do {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002242 prev_tx = put_tx;
2243 prev_tx_ctx = np->put_tx_ctx;
david decotignye45a6182011-11-05 14:38:24 +00002244 bcnt = (frag_size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : frag_size;
Ian Campbell671173c2011-08-29 23:18:28 +00002245 np->put_tx_ctx->dma = skb_frag_dma_map(
2246 &np->pci_dev->dev,
2247 frag, offset,
2248 bcnt,
Ian Campbell5d6bcdf2011-10-06 11:10:48 +01002249 DMA_TO_DEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002250 np->put_tx_ctx->dma_len = bcnt;
Eric Dumazet73a37072009-06-17 21:17:59 +00002251 np->put_tx_ctx->dma_single = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002252 put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
2253 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002254
Ayaz Abdullafa454592006-01-05 22:45:45 -08002255 offset += bcnt;
david decotignye45a6182011-11-05 14:38:24 +00002256 frag_size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002257 if (unlikely(put_tx++ == np->last_tx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002258 put_tx = np->first_tx.orig;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002259 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002260 np->put_tx_ctx = np->first_tx_ctx;
david decotignye45a6182011-11-05 14:38:24 +00002261 } while (frag_size);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002262 }
2263
Ayaz Abdullafa454592006-01-05 22:45:45 -08002264 /* set last fragment flag */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002265 prev_tx->flaglen |= cpu_to_le32(tx_flags_extra);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002266
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002267 /* save skb in this slot's context area */
2268 prev_tx_ctx->skb = skb;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002269
Herbert Xu89114af2006-07-08 13:34:32 -07002270 if (skb_is_gso(skb))
Herbert Xu79671682006-06-22 02:40:14 -07002271 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
Manfred Spraulee733622005-07-31 18:32:26 +02002272 else
Arjan van de Ven1d39ed52006-12-12 14:06:23 +01002273 tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
Patrick McHardy84fa7932006-08-29 16:44:56 -07002274 NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002275
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002276 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla164a86e2007-01-09 13:30:10 -05002277
Ayaz Abdullafa454592006-01-05 22:45:45 -08002278 /* set tx flags */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002279 start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
Tom Herbertb8bfca92011-11-28 16:33:23 +00002280
2281 netdev_sent_queue(np->dev, skb->len);
2282
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002283 np->put_tx.orig = put_tx;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002284
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002285 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002286
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002287 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002288 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002289}
2290
Stephen Hemminger613573252009-08-31 19:50:58 +00002291static netdev_tx_t nv_start_xmit_optimized(struct sk_buff *skb,
2292 struct net_device *dev)
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002293{
2294 struct fe_priv *np = netdev_priv(dev);
2295 u32 tx_flags = 0;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002296 u32 tx_flags_extra;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002297 unsigned int fragments = skb_shinfo(skb)->nr_frags;
2298 unsigned int i;
2299 u32 offset = 0;
2300 u32 bcnt;
Eric Dumazete743d312010-04-14 15:59:40 -07002301 u32 size = skb_headlen(skb);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002302 u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
2303 u32 empty_slots;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002304 struct ring_desc_ex *put_tx;
2305 struct ring_desc_ex *start_tx;
2306 struct ring_desc_ex *prev_tx;
2307 struct nv_skb_map *prev_tx_ctx;
2308 struct nv_skb_map *start_tx_ctx;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002309 unsigned long flags;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002310
2311 /* add fragments to entries count */
2312 for (i = 0; i < fragments; i++) {
david decotignye45a6182011-11-05 14:38:24 +00002313 u32 frag_size = skb_frag_size(&skb_shinfo(skb)->frags[i]);
Eric Dumazet9e903e02011-10-18 21:00:24 +00002314
david decotignye45a6182011-11-05 14:38:24 +00002315 entries += (frag_size >> NV_TX2_TSO_MAX_SHIFT) +
2316 ((frag_size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002317 }
2318
Ayaz Abdulla001eb842009-01-09 11:03:44 +00002319 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002320 empty_slots = nv_get_empty_tx_slots(np);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002321 if (unlikely(empty_slots <= entries)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002322 netif_stop_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002323 np->tx_stop = 1;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002324 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002325 return NETDEV_TX_BUSY;
2326 }
Ayaz Abdulla001eb842009-01-09 11:03:44 +00002327 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002328
2329 start_tx = put_tx = np->put_tx.ex;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002330 start_tx_ctx = np->put_tx_ctx;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002331
2332 /* setup the header buffer */
2333 do {
2334 prev_tx = put_tx;
2335 prev_tx_ctx = np->put_tx_ctx;
2336 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
2337 np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
2338 PCI_DMA_TODEVICE);
2339 np->put_tx_ctx->dma_len = bcnt;
Eric Dumazet73a37072009-06-17 21:17:59 +00002340 np->put_tx_ctx->dma_single = 1;
Al Viro5bb7ea22007-12-09 16:06:41 +00002341 put_tx->bufhigh = cpu_to_le32(dma_high(np->put_tx_ctx->dma));
2342 put_tx->buflow = cpu_to_le32(dma_low(np->put_tx_ctx->dma));
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002343 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002344
2345 tx_flags = NV_TX2_VALID;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002346 offset += bcnt;
2347 size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002348 if (unlikely(put_tx++ == np->last_tx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002349 put_tx = np->first_tx.ex;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002350 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002351 np->put_tx_ctx = np->first_tx_ctx;
2352 } while (size);
2353
2354 /* setup the fragments */
2355 for (i = 0; i < fragments; i++) {
2356 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
david decotignye45a6182011-11-05 14:38:24 +00002357 u32 frag_size = skb_frag_size(frag);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002358 offset = 0;
2359
2360 do {
2361 prev_tx = put_tx;
2362 prev_tx_ctx = np->put_tx_ctx;
david decotignye45a6182011-11-05 14:38:24 +00002363 bcnt = (frag_size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : frag_size;
Ian Campbell671173c2011-08-29 23:18:28 +00002364 np->put_tx_ctx->dma = skb_frag_dma_map(
2365 &np->pci_dev->dev,
2366 frag, offset,
2367 bcnt,
Ian Campbell5d6bcdf2011-10-06 11:10:48 +01002368 DMA_TO_DEVICE);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002369 np->put_tx_ctx->dma_len = bcnt;
Eric Dumazet73a37072009-06-17 21:17:59 +00002370 np->put_tx_ctx->dma_single = 0;
Al Viro5bb7ea22007-12-09 16:06:41 +00002371 put_tx->bufhigh = cpu_to_le32(dma_high(np->put_tx_ctx->dma));
2372 put_tx->buflow = cpu_to_le32(dma_low(np->put_tx_ctx->dma));
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002373 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002374
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002375 offset += bcnt;
david decotignye45a6182011-11-05 14:38:24 +00002376 frag_size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002377 if (unlikely(put_tx++ == np->last_tx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002378 put_tx = np->first_tx.ex;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002379 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002380 np->put_tx_ctx = np->first_tx_ctx;
david decotignye45a6182011-11-05 14:38:24 +00002381 } while (frag_size);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002382 }
2383
2384 /* set last fragment flag */
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002385 prev_tx->flaglen |= cpu_to_le32(NV_TX2_LASTPACKET);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002386
2387 /* save skb in this slot's context area */
2388 prev_tx_ctx->skb = skb;
2389
2390 if (skb_is_gso(skb))
2391 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
2392 else
2393 tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
2394 NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
2395
2396 /* vlan tag */
Jesse Grosseab6d182010-10-20 13:56:03 +00002397 if (vlan_tx_tag_present(skb))
2398 start_tx->txvlan = cpu_to_le32(NV_TX3_VLAN_TAG_PRESENT |
2399 vlan_tx_tag_get(skb));
2400 else
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002401 start_tx->txvlan = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002402
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002403 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002404
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002405 if (np->tx_limit) {
2406 /* Limit the number of outstanding tx. Setup all fragments, but
2407 * do not set the VALID bit on the first descriptor. Save a pointer
2408 * to that descriptor and also for next skb_map element.
2409 */
2410
2411 if (np->tx_pkts_in_progress == NV_TX_LIMIT_COUNT) {
2412 if (!np->tx_change_owner)
2413 np->tx_change_owner = start_tx_ctx;
2414
2415 /* remove VALID bit */
2416 tx_flags &= ~NV_TX2_VALID;
2417 start_tx_ctx->first_tx_desc = start_tx;
2418 start_tx_ctx->next_tx_ctx = np->put_tx_ctx;
2419 np->tx_end_flip = np->put_tx_ctx;
2420 } else {
2421 np->tx_pkts_in_progress++;
2422 }
2423 }
2424
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002425 /* set tx flags */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002426 start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
Tom Herbertb8bfca92011-11-28 16:33:23 +00002427
2428 netdev_sent_queue(np->dev, skb->len);
2429
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002430 np->put_tx.ex = put_tx;
2431
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002432 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002433
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002434 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002435 return NETDEV_TX_OK;
2436}
2437
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002438static inline void nv_tx_flip_ownership(struct net_device *dev)
2439{
2440 struct fe_priv *np = netdev_priv(dev);
2441
2442 np->tx_pkts_in_progress--;
2443 if (np->tx_change_owner) {
Al Viro30ecce92008-03-26 05:57:12 +00002444 np->tx_change_owner->first_tx_desc->flaglen |=
2445 cpu_to_le32(NV_TX2_VALID);
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002446 np->tx_pkts_in_progress++;
2447
2448 np->tx_change_owner = np->tx_change_owner->next_tx_ctx;
2449 if (np->tx_change_owner == np->tx_end_flip)
2450 np->tx_change_owner = NULL;
2451
2452 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
2453 }
2454}
2455
Linus Torvalds1da177e2005-04-16 15:20:36 -07002456/*
2457 * nv_tx_done: check for completed packets, release the skbs.
2458 *
2459 * Caller must own np->lock.
2460 */
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002461static int nv_tx_done(struct net_device *dev, int limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002462{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002463 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002464 u32 flags;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002465 int tx_work = 0;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002466 struct ring_desc *orig_get_tx = np->get_tx.orig;
Tom Herbertb8bfca92011-11-28 16:33:23 +00002467 unsigned int bytes_compl = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002468
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002469 while ((np->get_tx.orig != np->put_tx.orig) &&
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002470 !((flags = le32_to_cpu(np->get_tx.orig->flaglen)) & NV_TX_VALID) &&
2471 (tx_work < limit)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002472
Eric Dumazet73a37072009-06-17 21:17:59 +00002473 nv_unmap_txskb(np, np->get_tx_ctx);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002474
Linus Torvalds1da177e2005-04-16 15:20:36 -07002475 if (np->desc_ver == DESC_VER_1) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002476 if (flags & NV_TX_LASTPACKET) {
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002477 if (flags & NV_TX_ERROR) {
david decotignyf5d827a2011-11-16 12:15:13 +00002478 if ((flags & NV_TX_RETRYERROR)
2479 && !(flags & NV_TX_RETRYCOUNT_MASK))
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002480 nv_legacybackoff_reseed(dev);
david decotigny674aee32011-11-16 12:15:07 +00002481 } else {
david decotignyf5d827a2011-11-16 12:15:13 +00002482 u64_stats_update_begin(&np->swstats_tx_syncp);
2483 np->stat_tx_packets++;
2484 np->stat_tx_bytes += np->get_tx_ctx->skb->len;
2485 u64_stats_update_end(&np->swstats_tx_syncp);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002486 }
Tom Herbertb8bfca92011-11-28 16:33:23 +00002487 bytes_compl += np->get_tx_ctx->skb->len;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002488 dev_kfree_skb_any(np->get_tx_ctx->skb);
2489 np->get_tx_ctx->skb = NULL;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002490 tx_work++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 }
2492 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002493 if (flags & NV_TX2_LASTPACKET) {
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002494 if (flags & NV_TX2_ERROR) {
david decotignyf5d827a2011-11-16 12:15:13 +00002495 if ((flags & NV_TX2_RETRYERROR)
2496 && !(flags & NV_TX2_RETRYCOUNT_MASK))
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002497 nv_legacybackoff_reseed(dev);
david decotigny674aee32011-11-16 12:15:07 +00002498 } else {
david decotignyf5d827a2011-11-16 12:15:13 +00002499 u64_stats_update_begin(&np->swstats_tx_syncp);
2500 np->stat_tx_packets++;
2501 np->stat_tx_bytes += np->get_tx_ctx->skb->len;
2502 u64_stats_update_end(&np->swstats_tx_syncp);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002503 }
Tom Herbertb8bfca92011-11-28 16:33:23 +00002504 bytes_compl += np->get_tx_ctx->skb->len;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002505 dev_kfree_skb_any(np->get_tx_ctx->skb);
2506 np->get_tx_ctx->skb = NULL;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002507 tx_work++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002508 }
2509 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002510 if (unlikely(np->get_tx.orig++ == np->last_tx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002511 np->get_tx.orig = np->first_tx.orig;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002512 if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002513 np->get_tx_ctx = np->first_tx_ctx;
2514 }
Tom Herbertb8bfca92011-11-28 16:33:23 +00002515
2516 netdev_completed_queue(np->dev, tx_work, bytes_compl);
2517
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002518 if (unlikely((np->tx_stop == 1) && (np->get_tx.orig != orig_get_tx))) {
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002519 np->tx_stop = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002520 netif_wake_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002521 }
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002522 return tx_work;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002523}
2524
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002525static int nv_tx_done_optimized(struct net_device *dev, int limit)
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002526{
2527 struct fe_priv *np = netdev_priv(dev);
2528 u32 flags;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002529 int tx_work = 0;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002530 struct ring_desc_ex *orig_get_tx = np->get_tx.ex;
Tom Herbertb8bfca92011-11-28 16:33:23 +00002531 unsigned long bytes_cleaned = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002532
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002533 while ((np->get_tx.ex != np->put_tx.ex) &&
Julia Lawall217d32d2010-07-05 22:15:47 -07002534 !((flags = le32_to_cpu(np->get_tx.ex->flaglen)) & NV_TX2_VALID) &&
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002535 (tx_work < limit)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002536
Eric Dumazet73a37072009-06-17 21:17:59 +00002537 nv_unmap_txskb(np, np->get_tx_ctx);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002538
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002539 if (flags & NV_TX2_LASTPACKET) {
david decotigny4687f3f2011-11-05 14:38:22 +00002540 if (flags & NV_TX2_ERROR) {
david decotignyf5d827a2011-11-16 12:15:13 +00002541 if ((flags & NV_TX2_RETRYERROR)
2542 && !(flags & NV_TX2_RETRYCOUNT_MASK)) {
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002543 if (np->driver_data & DEV_HAS_GEAR_MODE)
2544 nv_gear_backoff_reseed(dev);
2545 else
2546 nv_legacybackoff_reseed(dev);
2547 }
david decotigny674aee32011-11-16 12:15:07 +00002548 } else {
David S. Millerefd0bf92011-11-21 13:50:33 -05002549 u64_stats_update_begin(&np->swstats_tx_syncp);
2550 np->stat_tx_packets++;
2551 np->stat_tx_bytes += np->get_tx_ctx->skb->len;
2552 u64_stats_update_end(&np->swstats_tx_syncp);
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002553 }
2554
Tom Herbertb8bfca92011-11-28 16:33:23 +00002555 bytes_cleaned += np->get_tx_ctx->skb->len;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002556 dev_kfree_skb_any(np->get_tx_ctx->skb);
2557 np->get_tx_ctx->skb = NULL;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002558 tx_work++;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002559
Szymon Janc78aea4f2010-11-27 08:39:43 +00002560 if (np->tx_limit)
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002561 nv_tx_flip_ownership(dev);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002562 }
Tom Herbertb8bfca92011-11-28 16:33:23 +00002563
2564 netdev_completed_queue(np->dev, tx_work, bytes_cleaned);
2565
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002566 if (unlikely(np->get_tx.ex++ == np->last_tx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002567 np->get_tx.ex = np->first_tx.ex;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002568 if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002569 np->get_tx_ctx = np->first_tx_ctx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002570 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002571 if (unlikely((np->tx_stop == 1) && (np->get_tx.ex != orig_get_tx))) {
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002572 np->tx_stop = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002573 netif_wake_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002574 }
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002575 return tx_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002576}
2577
2578/*
2579 * nv_tx_timeout: dev->tx_timeout function
Herbert Xu932ff272006-06-09 12:20:56 -07002580 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002581 */
2582static void nv_tx_timeout(struct net_device *dev)
2583{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002584 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002585 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002586 u32 status;
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002587 union ring_type put_tx;
2588 int saved_tx_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002590 if (np->msi_flags & NV_MSI_X_ENABLED)
2591 status = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
2592 else
2593 status = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
2594
Sameer Nanda1ec4f2d2011-11-16 12:15:12 +00002595 netdev_warn(dev, "Got tx_timeout. irq status: %08x\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596
Sameer Nanda1ec4f2d2011-11-16 12:15:12 +00002597 if (unlikely(debug_tx_timeout)) {
2598 int i;
2599
2600 netdev_info(dev, "Ring at %lx\n", (unsigned long)np->ring_addr);
2601 netdev_info(dev, "Dumping tx registers\n");
2602 for (i = 0; i <= np->register_size; i += 32) {
Joe Perches1d397f32010-11-29 07:41:57 +00002603 netdev_info(dev,
Sameer Nanda1ec4f2d2011-11-16 12:15:12 +00002604 "%3x: %08x %08x %08x %08x "
2605 "%08x %08x %08x %08x\n",
Joe Perches1d397f32010-11-29 07:41:57 +00002606 i,
Sameer Nanda1ec4f2d2011-11-16 12:15:12 +00002607 readl(base + i + 0), readl(base + i + 4),
2608 readl(base + i + 8), readl(base + i + 12),
2609 readl(base + i + 16), readl(base + i + 20),
2610 readl(base + i + 24), readl(base + i + 28));
2611 }
2612 netdev_info(dev, "Dumping tx ring\n");
2613 for (i = 0; i < np->tx_ring_size; i += 4) {
2614 if (!nv_optimized(np)) {
2615 netdev_info(dev,
2616 "%03x: %08x %08x // %08x %08x "
2617 "// %08x %08x // %08x %08x\n",
2618 i,
2619 le32_to_cpu(np->tx_ring.orig[i].buf),
2620 le32_to_cpu(np->tx_ring.orig[i].flaglen),
2621 le32_to_cpu(np->tx_ring.orig[i+1].buf),
2622 le32_to_cpu(np->tx_ring.orig[i+1].flaglen),
2623 le32_to_cpu(np->tx_ring.orig[i+2].buf),
2624 le32_to_cpu(np->tx_ring.orig[i+2].flaglen),
2625 le32_to_cpu(np->tx_ring.orig[i+3].buf),
2626 le32_to_cpu(np->tx_ring.orig[i+3].flaglen));
2627 } else {
2628 netdev_info(dev,
2629 "%03x: %08x %08x %08x "
2630 "// %08x %08x %08x "
2631 "// %08x %08x %08x "
2632 "// %08x %08x %08x\n",
2633 i,
2634 le32_to_cpu(np->tx_ring.ex[i].bufhigh),
2635 le32_to_cpu(np->tx_ring.ex[i].buflow),
2636 le32_to_cpu(np->tx_ring.ex[i].flaglen),
2637 le32_to_cpu(np->tx_ring.ex[i+1].bufhigh),
2638 le32_to_cpu(np->tx_ring.ex[i+1].buflow),
2639 le32_to_cpu(np->tx_ring.ex[i+1].flaglen),
2640 le32_to_cpu(np->tx_ring.ex[i+2].bufhigh),
2641 le32_to_cpu(np->tx_ring.ex[i+2].buflow),
2642 le32_to_cpu(np->tx_ring.ex[i+2].flaglen),
2643 le32_to_cpu(np->tx_ring.ex[i+3].bufhigh),
2644 le32_to_cpu(np->tx_ring.ex[i+3].buflow),
2645 le32_to_cpu(np->tx_ring.ex[i+3].flaglen));
2646 }
Manfred Spraulc2dba062005-07-31 18:29:47 +02002647 }
2648 }
2649
Linus Torvalds1da177e2005-04-16 15:20:36 -07002650 spin_lock_irq(&np->lock);
2651
2652 /* 1) stop tx engine */
2653 nv_stop_tx(dev);
2654
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002655 /* 2) complete any outstanding tx and do not give HW any limited tx pkts */
2656 saved_tx_limit = np->tx_limit;
2657 np->tx_limit = 0; /* prevent giving HW any limited pkts */
2658 np->tx_stop = 0; /* prevent waking tx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002659 if (!nv_optimized(np))
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002660 nv_tx_done(dev, np->tx_ring_size);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002661 else
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05002662 nv_tx_done_optimized(dev, np->tx_ring_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002664 /* save current HW position */
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002665 if (np->tx_change_owner)
2666 put_tx.ex = np->tx_change_owner->first_tx_desc;
2667 else
2668 put_tx = np->put_tx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002670 /* 3) clear all tx state */
2671 nv_drain_tx(dev);
2672 nv_init_tx(dev);
Ayaz Abdulla3ba4d092007-03-23 05:50:02 -05002673
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002674 /* 4) restore state to current HW position */
2675 np->get_tx = np->put_tx = put_tx;
2676 np->tx_limit = saved_tx_limit;
2677
2678 /* 5) restart tx engine */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002679 nv_start_tx(dev);
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002680 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002681 spin_unlock_irq(&np->lock);
2682}
2683
Manfred Spraul22c6d142005-04-19 21:17:09 +02002684/*
2685 * Called when the nic notices a mismatch between the actual data len on the
2686 * wire and the len indicated in the 802 header
2687 */
2688static int nv_getlen(struct net_device *dev, void *packet, int datalen)
2689{
2690 int hdrlen; /* length of the 802 header */
2691 int protolen; /* length as stored in the proto field */
2692
2693 /* 1) calculate len according to header */
Szymon Janc78aea4f2010-11-27 08:39:43 +00002694 if (((struct vlan_ethhdr *)packet)->h_vlan_proto == htons(ETH_P_8021Q)) {
2695 protolen = ntohs(((struct vlan_ethhdr *)packet)->h_vlan_encapsulated_proto);
Manfred Spraul22c6d142005-04-19 21:17:09 +02002696 hdrlen = VLAN_HLEN;
2697 } else {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002698 protolen = ntohs(((struct ethhdr *)packet)->h_proto);
Manfred Spraul22c6d142005-04-19 21:17:09 +02002699 hdrlen = ETH_HLEN;
2700 }
Manfred Spraul22c6d142005-04-19 21:17:09 +02002701 if (protolen > ETH_DATA_LEN)
2702 return datalen; /* Value in proto field not a len, no checks possible */
2703
2704 protolen += hdrlen;
2705 /* consistency checks: */
2706 if (datalen > ETH_ZLEN) {
2707 if (datalen >= protolen) {
2708 /* more data on wire than in 802 header, trim of
2709 * additional data.
2710 */
Manfred Spraul22c6d142005-04-19 21:17:09 +02002711 return protolen;
2712 } else {
2713 /* less data on wire than mentioned in header.
2714 * Discard the packet.
2715 */
Manfred Spraul22c6d142005-04-19 21:17:09 +02002716 return -1;
2717 }
2718 } else {
2719 /* short packet. Accept only if 802 values are also short */
2720 if (protolen > ETH_ZLEN) {
Manfred Spraul22c6d142005-04-19 21:17:09 +02002721 return -1;
2722 }
Manfred Spraul22c6d142005-04-19 21:17:09 +02002723 return datalen;
2724 }
2725}
2726
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002727static int nv_rx_process(struct net_device *dev, int limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002728{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002729 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002730 u32 flags;
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002731 int rx_work = 0;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002732 struct sk_buff *skb;
2733 int len;
Ayaz Abdullaee407b02006-02-04 13:13:17 -05002734
Szymon Janc78aea4f2010-11-27 08:39:43 +00002735 while ((np->get_rx.orig != np->put_rx.orig) &&
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002736 !((flags = le32_to_cpu(np->get_rx.orig->flaglen)) & NV_RX_AVAIL) &&
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002737 (rx_work < limit)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002738
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739 /*
2740 * the packet is for us - immediately tear down the pci mapping.
2741 * TODO: check if a prefetch of the first cacheline improves
2742 * the performance.
2743 */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002744 pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma,
2745 np->get_rx_ctx->dma_len,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002746 PCI_DMA_FROMDEVICE);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002747 skb = np->get_rx_ctx->skb;
2748 np->get_rx_ctx->skb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002749
Linus Torvalds1da177e2005-04-16 15:20:36 -07002750 /* look at what we actually got: */
2751 if (np->desc_ver == DESC_VER_1) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002752 if (likely(flags & NV_RX_DESCRIPTORVALID)) {
2753 len = flags & LEN_MASK_V1;
2754 if (unlikely(flags & NV_RX_ERROR)) {
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002755 if ((flags & NV_RX_ERROR_MASK) == NV_RX_ERROR4) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002756 len = nv_getlen(dev, skb->data, len);
2757 if (len < 0) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002758 dev_kfree_skb(skb);
2759 goto next_pkt;
2760 }
2761 }
2762 /* framing errors are soft errors */
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002763 else if ((flags & NV_RX_ERROR_MASK) == NV_RX_FRAMINGERR) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002764 if (flags & NV_RX_SUBSTRACT1)
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002765 len--;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002766 }
2767 /* the rest are hard errors */
2768 else {
david decotignyf5d827a2011-11-16 12:15:13 +00002769 if (flags & NV_RX_MISSEDFRAME) {
2770 u64_stats_update_begin(&np->swstats_rx_syncp);
2771 np->stat_rx_missed_errors++;
2772 u64_stats_update_end(&np->swstats_rx_syncp);
2773 }
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002774 dev_kfree_skb(skb);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002775 goto next_pkt;
2776 }
2777 }
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002778 } else {
2779 dev_kfree_skb(skb);
2780 goto next_pkt;
Manfred Spraul22c6d142005-04-19 21:17:09 +02002781 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002782 } else {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002783 if (likely(flags & NV_RX2_DESCRIPTORVALID)) {
2784 len = flags & LEN_MASK_V2;
2785 if (unlikely(flags & NV_RX2_ERROR)) {
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002786 if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_ERROR4) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002787 len = nv_getlen(dev, skb->data, len);
2788 if (len < 0) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002789 dev_kfree_skb(skb);
2790 goto next_pkt;
2791 }
2792 }
2793 /* framing errors are soft errors */
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002794 else if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_FRAMINGERR) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002795 if (flags & NV_RX2_SUBSTRACT1)
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002796 len--;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002797 }
2798 /* the rest are hard errors */
2799 else {
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002800 dev_kfree_skb(skb);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002801 goto next_pkt;
2802 }
2803 }
Ayaz Abdullabfaffe82008-01-13 16:02:55 -05002804 if (((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_TCP) || /*ip and tcp */
2805 ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_UDP)) /*ip and udp */
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002806 skb->ip_summed = CHECKSUM_UNNECESSARY;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002807 } else {
2808 dev_kfree_skb(skb);
2809 goto next_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002810 }
2811 }
2812 /* got a valid packet - forward it to the network core */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 skb_put(skb, len);
2814 skb->protocol = eth_type_trans(skb, dev);
Tom Herbert53f224c2010-05-03 19:08:45 +00002815 napi_gro_receive(&np->napi, skb);
david decotignyf5d827a2011-11-16 12:15:13 +00002816 u64_stats_update_begin(&np->swstats_rx_syncp);
2817 np->stat_rx_packets++;
2818 np->stat_rx_bytes += len;
2819 u64_stats_update_end(&np->swstats_rx_syncp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002820next_pkt:
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002821 if (unlikely(np->get_rx.orig++ == np->last_rx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002822 np->get_rx.orig = np->first_rx.orig;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002823 if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002824 np->get_rx_ctx = np->first_rx_ctx;
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002825
2826 rx_work++;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002827 }
2828
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002829 return rx_work;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002830}
2831
2832static int nv_rx_process_optimized(struct net_device *dev, int limit)
2833{
2834 struct fe_priv *np = netdev_priv(dev);
2835 u32 flags;
2836 u32 vlanflags = 0;
Ingo Molnarc1b71512007-10-17 12:18:23 +02002837 int rx_work = 0;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002838 struct sk_buff *skb;
2839 int len;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002840
Szymon Janc78aea4f2010-11-27 08:39:43 +00002841 while ((np->get_rx.ex != np->put_rx.ex) &&
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002842 !((flags = le32_to_cpu(np->get_rx.ex->flaglen)) & NV_RX2_AVAIL) &&
Ingo Molnarc1b71512007-10-17 12:18:23 +02002843 (rx_work < limit)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002844
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002845 /*
2846 * the packet is for us - immediately tear down the pci mapping.
2847 * TODO: check if a prefetch of the first cacheline improves
2848 * the performance.
2849 */
2850 pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma,
2851 np->get_rx_ctx->dma_len,
2852 PCI_DMA_FROMDEVICE);
2853 skb = np->get_rx_ctx->skb;
2854 np->get_rx_ctx->skb = NULL;
2855
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002856 /* look at what we actually got: */
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002857 if (likely(flags & NV_RX2_DESCRIPTORVALID)) {
2858 len = flags & LEN_MASK_V2;
2859 if (unlikely(flags & NV_RX2_ERROR)) {
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002860 if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_ERROR4) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002861 len = nv_getlen(dev, skb->data, len);
2862 if (len < 0) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002863 dev_kfree_skb(skb);
2864 goto next_pkt;
2865 }
2866 }
2867 /* framing errors are soft errors */
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002868 else if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_FRAMINGERR) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002869 if (flags & NV_RX2_SUBSTRACT1)
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002870 len--;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002871 }
2872 /* the rest are hard errors */
2873 else {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002874 dev_kfree_skb(skb);
2875 goto next_pkt;
2876 }
2877 }
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002878
Ayaz Abdullabfaffe82008-01-13 16:02:55 -05002879 if (((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_TCP) || /*ip and tcp */
2880 ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_UDP)) /*ip and udp */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002881 skb->ip_summed = CHECKSUM_UNNECESSARY;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002882
2883 /* got a valid packet - forward it to the network core */
2884 skb_put(skb, len);
2885 skb->protocol = eth_type_trans(skb, dev);
2886 prefetch(skb->data);
2887
Jiri Pirko3326c782011-07-20 04:54:38 +00002888 vlanflags = le32_to_cpu(np->get_rx.ex->buflow);
Jiri Pirko0891b0e2011-07-26 10:19:28 +00002889
2890 /*
2891 * There's need to check for NETIF_F_HW_VLAN_RX here.
2892 * Even if vlan rx accel is disabled,
2893 * NV_RX3_VLAN_TAG_PRESENT is pseudo randomly set.
2894 */
2895 if (dev->features & NETIF_F_HW_VLAN_RX &&
2896 vlanflags & NV_RX3_VLAN_TAG_PRESENT) {
Jiri Pirko3326c782011-07-20 04:54:38 +00002897 u16 vid = vlanflags & NV_RX3_VLAN_TAG_MASK;
2898
2899 __vlan_hwaccel_put_tag(skb, vid);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002900 }
Jiri Pirko3326c782011-07-20 04:54:38 +00002901 napi_gro_receive(&np->napi, skb);
david decotignyf5d827a2011-11-16 12:15:13 +00002902 u64_stats_update_begin(&np->swstats_rx_syncp);
2903 np->stat_rx_packets++;
2904 np->stat_rx_bytes += len;
2905 u64_stats_update_end(&np->swstats_rx_syncp);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002906 } else {
2907 dev_kfree_skb(skb);
2908 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002909next_pkt:
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002910 if (unlikely(np->get_rx.ex++ == np->last_rx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002911 np->get_rx.ex = np->first_rx.ex;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002912 if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002913 np->get_rx_ctx = np->first_rx_ctx;
Ingo Molnarc1b71512007-10-17 12:18:23 +02002914
2915 rx_work++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002916 }
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002917
Ingo Molnarc1b71512007-10-17 12:18:23 +02002918 return rx_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002919}
2920
Manfred Sprauld81c0982005-07-31 18:20:30 +02002921static void set_bufsize(struct net_device *dev)
2922{
2923 struct fe_priv *np = netdev_priv(dev);
2924
2925 if (dev->mtu <= ETH_DATA_LEN)
2926 np->rx_buf_sz = ETH_DATA_LEN + NV_RX_HEADERS;
2927 else
2928 np->rx_buf_sz = dev->mtu + NV_RX_HEADERS;
2929}
2930
Linus Torvalds1da177e2005-04-16 15:20:36 -07002931/*
2932 * nv_change_mtu: dev->change_mtu function
2933 * Called with dev_base_lock held for read.
2934 */
2935static int nv_change_mtu(struct net_device *dev, int new_mtu)
2936{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002937 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002938 int old_mtu;
2939
2940 if (new_mtu < 64 || new_mtu > np->pkt_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941 return -EINVAL;
Manfred Sprauld81c0982005-07-31 18:20:30 +02002942
2943 old_mtu = dev->mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002944 dev->mtu = new_mtu;
Manfred Sprauld81c0982005-07-31 18:20:30 +02002945
2946 /* return early if the buffer sizes will not change */
2947 if (old_mtu <= ETH_DATA_LEN && new_mtu <= ETH_DATA_LEN)
2948 return 0;
2949 if (old_mtu == new_mtu)
2950 return 0;
2951
2952 /* synchronized against open : rtnl_lock() held by caller */
2953 if (netif_running(dev)) {
viro@ftp.linux.org.uk25097d42005-09-06 01:36:58 +01002954 u8 __iomem *base = get_hwbase(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002955 /*
2956 * It seems that the nic preloads valid ring entries into an
2957 * internal buffer. The procedure for flushing everything is
2958 * guessed, there is probably a simpler approach.
2959 * Changing the MTU is a rare event, it shouldn't matter.
2960 */
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002961 nv_disable_irq(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00002962 nv_napi_disable(dev);
Herbert Xu932ff272006-06-09 12:20:56 -07002963 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07002964 netif_addr_lock(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002965 spin_lock(&np->lock);
2966 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002967 nv_stop_rxtx(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002968 nv_txrx_reset(dev);
2969 /* drain rx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002970 nv_drain_rxtx(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002971 /* reinit driver view of the rx queue */
Manfred Sprauld81c0982005-07-31 18:20:30 +02002972 set_bufsize(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04002973 if (nv_init_ring(dev)) {
Manfred Sprauld81c0982005-07-31 18:20:30 +02002974 if (!np->in_shutdown)
2975 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2976 }
2977 /* reinit nic view of the rx queue */
2978 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
Ayaz Abdulla0832b252006-02-04 13:13:26 -05002979 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00002980 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Manfred Sprauld81c0982005-07-31 18:20:30 +02002981 base + NvRegRingSizes);
2982 pci_push(base);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002983 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002984 pci_push(base);
2985
2986 /* restart rx engine */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002987 nv_start_rxtx(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002988 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07002989 netif_addr_unlock(dev);
Herbert Xu932ff272006-06-09 12:20:56 -07002990 netif_tx_unlock_bh(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00002991 nv_napi_enable(dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002992 nv_enable_irq(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002993 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002994 return 0;
2995}
2996
Manfred Spraul72b31782005-07-31 18:33:34 +02002997static void nv_copy_mac_to_hw(struct net_device *dev)
2998{
viro@ftp.linux.org.uk25097d42005-09-06 01:36:58 +01002999 u8 __iomem *base = get_hwbase(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02003000 u32 mac[2];
3001
3002 mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) +
3003 (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24);
3004 mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8);
3005
3006 writel(mac[0], base + NvRegMacAddrA);
3007 writel(mac[1], base + NvRegMacAddrB);
3008}
3009
3010/*
3011 * nv_set_mac_address: dev->set_mac_address function
3012 * Called with rtnl_lock() held.
3013 */
3014static int nv_set_mac_address(struct net_device *dev, void *addr)
3015{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003016 struct fe_priv *np = netdev_priv(dev);
Szymon Janc78aea4f2010-11-27 08:39:43 +00003017 struct sockaddr *macaddr = (struct sockaddr *)addr;
Manfred Spraul72b31782005-07-31 18:33:34 +02003018
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003019 if (!is_valid_ether_addr(macaddr->sa_data))
Manfred Spraul72b31782005-07-31 18:33:34 +02003020 return -EADDRNOTAVAIL;
3021
3022 /* synchronized against open : rtnl_lock() held by caller */
3023 memcpy(dev->dev_addr, macaddr->sa_data, ETH_ALEN);
3024
3025 if (netif_running(dev)) {
Herbert Xu932ff272006-06-09 12:20:56 -07003026 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07003027 netif_addr_lock(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02003028 spin_lock_irq(&np->lock);
3029
3030 /* stop rx engine */
3031 nv_stop_rx(dev);
3032
3033 /* set mac address */
3034 nv_copy_mac_to_hw(dev);
3035
3036 /* restart rx engine */
3037 nv_start_rx(dev);
3038 spin_unlock_irq(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07003039 netif_addr_unlock(dev);
Herbert Xu932ff272006-06-09 12:20:56 -07003040 netif_tx_unlock_bh(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02003041 } else {
3042 nv_copy_mac_to_hw(dev);
3043 }
3044 return 0;
3045}
3046
Linus Torvalds1da177e2005-04-16 15:20:36 -07003047/*
3048 * nv_set_multicast: dev->set_multicast function
Herbert Xu932ff272006-06-09 12:20:56 -07003049 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003050 */
3051static void nv_set_multicast(struct net_device *dev)
3052{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003053 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003054 u8 __iomem *base = get_hwbase(dev);
3055 u32 addr[2];
3056 u32 mask[2];
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003057 u32 pff = readl(base + NvRegPacketFilterFlags) & NVREG_PFF_PAUSE_RX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003058
3059 memset(addr, 0, sizeof(addr));
3060 memset(mask, 0, sizeof(mask));
3061
3062 if (dev->flags & IFF_PROMISC) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003063 pff |= NVREG_PFF_PROMISC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003064 } else {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003065 pff |= NVREG_PFF_MYADDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003066
Jiri Pirko48e2f182010-02-22 09:22:26 +00003067 if (dev->flags & IFF_ALLMULTI || !netdev_mc_empty(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003068 u32 alwaysOff[2];
3069 u32 alwaysOn[2];
3070
3071 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0xffffffff;
3072 if (dev->flags & IFF_ALLMULTI) {
3073 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0;
3074 } else {
Jiri Pirko22bedad32010-04-01 21:22:57 +00003075 struct netdev_hw_addr *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003076
Jiri Pirko22bedad32010-04-01 21:22:57 +00003077 netdev_for_each_mc_addr(ha, dev) {
david decotignye45a6182011-11-05 14:38:24 +00003078 unsigned char *hw_addr = ha->addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003079 u32 a, b;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003080
david decotignye45a6182011-11-05 14:38:24 +00003081 a = le32_to_cpu(*(__le32 *) hw_addr);
3082 b = le16_to_cpu(*(__le16 *) (&hw_addr[4]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003083 alwaysOn[0] &= a;
3084 alwaysOff[0] &= ~a;
3085 alwaysOn[1] &= b;
3086 alwaysOff[1] &= ~b;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003087 }
3088 }
3089 addr[0] = alwaysOn[0];
3090 addr[1] = alwaysOn[1];
3091 mask[0] = alwaysOn[0] | alwaysOff[0];
3092 mask[1] = alwaysOn[1] | alwaysOff[1];
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -05003093 } else {
3094 mask[0] = NVREG_MCASTMASKA_NONE;
3095 mask[1] = NVREG_MCASTMASKB_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003096 }
3097 }
3098 addr[0] |= NVREG_MCASTADDRA_FORCE;
3099 pff |= NVREG_PFF_ALWAYS;
3100 spin_lock_irq(&np->lock);
3101 nv_stop_rx(dev);
3102 writel(addr[0], base + NvRegMulticastAddrA);
3103 writel(addr[1], base + NvRegMulticastAddrB);
3104 writel(mask[0], base + NvRegMulticastMaskA);
3105 writel(mask[1], base + NvRegMulticastMaskB);
3106 writel(pff, base + NvRegPacketFilterFlags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003107 nv_start_rx(dev);
3108 spin_unlock_irq(&np->lock);
3109}
3110
Adrian Bunkc7985052006-06-22 12:03:29 +02003111static void nv_update_pause(struct net_device *dev, u32 pause_flags)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003112{
3113 struct fe_priv *np = netdev_priv(dev);
3114 u8 __iomem *base = get_hwbase(dev);
3115
3116 np->pause_flags &= ~(NV_PAUSEFRAME_TX_ENABLE | NV_PAUSEFRAME_RX_ENABLE);
3117
3118 if (np->pause_flags & NV_PAUSEFRAME_RX_CAPABLE) {
3119 u32 pff = readl(base + NvRegPacketFilterFlags) & ~NVREG_PFF_PAUSE_RX;
3120 if (pause_flags & NV_PAUSEFRAME_RX_ENABLE) {
3121 writel(pff|NVREG_PFF_PAUSE_RX, base + NvRegPacketFilterFlags);
3122 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3123 } else {
3124 writel(pff, base + NvRegPacketFilterFlags);
3125 }
3126 }
3127 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE) {
3128 u32 regmisc = readl(base + NvRegMisc1) & ~NVREG_MISC1_PAUSE_TX;
3129 if (pause_flags & NV_PAUSEFRAME_TX_ENABLE) {
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05003130 u32 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V1;
3131 if (np->driver_data & DEV_HAS_PAUSEFRAME_TX_V2)
3132 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V2;
Ayaz Abdulla9a33e882008-08-06 12:12:34 -04003133 if (np->driver_data & DEV_HAS_PAUSEFRAME_TX_V3) {
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05003134 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V3;
Ayaz Abdulla9a33e882008-08-06 12:12:34 -04003135 /* limit the number of tx pause frames to a default of 8 */
3136 writel(readl(base + NvRegTxPauseFrameLimit)|NVREG_TX_PAUSEFRAMELIMIT_ENABLE, base + NvRegTxPauseFrameLimit);
3137 }
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05003138 writel(pause_enable, base + NvRegTxPauseFrame);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003139 writel(regmisc|NVREG_MISC1_PAUSE_TX, base + NvRegMisc1);
3140 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3141 } else {
3142 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
3143 writel(regmisc, base + NvRegMisc1);
3144 }
3145 }
3146}
3147
Sanjay Hortikare19df762011-11-11 16:11:21 +00003148static void nv_force_linkspeed(struct net_device *dev, int speed, int duplex)
3149{
3150 struct fe_priv *np = netdev_priv(dev);
3151 u8 __iomem *base = get_hwbase(dev);
3152 u32 phyreg, txreg;
3153 int mii_status;
3154
3155 np->linkspeed = NVREG_LINKSPEED_FORCE|speed;
3156 np->duplex = duplex;
3157
3158 /* see if gigabit phy */
3159 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
3160 if (mii_status & PHY_GIGABIT) {
3161 np->gigabit = PHY_GIGABIT;
3162 phyreg = readl(base + NvRegSlotTime);
3163 phyreg &= ~(0x3FF00);
3164 if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10)
3165 phyreg |= NVREG_SLOTTIME_10_100_FULL;
3166 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100)
3167 phyreg |= NVREG_SLOTTIME_10_100_FULL;
3168 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000)
3169 phyreg |= NVREG_SLOTTIME_1000_FULL;
3170 writel(phyreg, base + NvRegSlotTime);
3171 }
3172
3173 phyreg = readl(base + NvRegPhyInterface);
3174 phyreg &= ~(PHY_HALF|PHY_100|PHY_1000);
3175 if (np->duplex == 0)
3176 phyreg |= PHY_HALF;
3177 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100)
3178 phyreg |= PHY_100;
3179 else if ((np->linkspeed & NVREG_LINKSPEED_MASK) ==
3180 NVREG_LINKSPEED_1000)
3181 phyreg |= PHY_1000;
3182 writel(phyreg, base + NvRegPhyInterface);
3183
3184 if (phyreg & PHY_RGMII) {
3185 if ((np->linkspeed & NVREG_LINKSPEED_MASK) ==
3186 NVREG_LINKSPEED_1000)
3187 txreg = NVREG_TX_DEFERRAL_RGMII_1000;
3188 else
3189 txreg = NVREG_TX_DEFERRAL_RGMII_10_100;
3190 } else {
3191 txreg = NVREG_TX_DEFERRAL_DEFAULT;
3192 }
3193 writel(txreg, base + NvRegTxDeferral);
3194
3195 if (np->desc_ver == DESC_VER_1) {
3196 txreg = NVREG_TX_WM_DESC1_DEFAULT;
3197 } else {
3198 if ((np->linkspeed & NVREG_LINKSPEED_MASK) ==
3199 NVREG_LINKSPEED_1000)
3200 txreg = NVREG_TX_WM_DESC2_3_1000;
3201 else
3202 txreg = NVREG_TX_WM_DESC2_3_DEFAULT;
3203 }
3204 writel(txreg, base + NvRegTxWatermark);
3205
3206 writel(NVREG_MISC1_FORCE | (np->duplex ? 0 : NVREG_MISC1_HD),
3207 base + NvRegMisc1);
3208 pci_push(base);
3209 writel(np->linkspeed, base + NvRegLinkSpeed);
3210 pci_push(base);
3211
3212 return;
3213}
3214
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05003215/**
3216 * nv_update_linkspeed: Setup the MAC according to the link partner
3217 * @dev: Network device to be configured
3218 *
3219 * The function queries the PHY and checks if there is a link partner.
3220 * If yes, then it sets up the MAC accordingly. Otherwise, the MAC is
3221 * set to 10 MBit HD.
3222 *
3223 * The function returns 0 if there is no link partner and 1 if there is
3224 * a good link partner.
3225 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003226static int nv_update_linkspeed(struct net_device *dev)
3227{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003228 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003229 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003230 int adv = 0;
3231 int lpa = 0;
3232 int adv_lpa, adv_pause, lpa_pause;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003233 int newls = np->linkspeed;
3234 int newdup = np->duplex;
3235 int mii_status;
Sanjay Hortikare19df762011-11-11 16:11:21 +00003236 u32 bmcr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003237 int retval = 0;
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003238 u32 control_1000, status_1000, phyreg, pause_flags, txreg;
Ayaz Abdullab2976d22008-02-04 15:13:59 -05003239 u32 txrxFlags = 0;
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003240 u32 phy_exp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241
Sanjay Hortikare19df762011-11-11 16:11:21 +00003242 /* If device loopback is enabled, set carrier on and enable max link
3243 * speed.
3244 */
3245 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
3246 if (bmcr & BMCR_LOOPBACK) {
3247 if (netif_running(dev)) {
3248 nv_force_linkspeed(dev, NVREG_LINKSPEED_1000, 1);
3249 if (!netif_carrier_ok(dev))
3250 netif_carrier_on(dev);
3251 }
3252 return 1;
3253 }
3254
Linus Torvalds1da177e2005-04-16 15:20:36 -07003255 /* BMSR_LSTATUS is latched, read it twice:
3256 * we want the current value.
3257 */
3258 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
3259 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
3260
3261 if (!(mii_status & BMSR_LSTATUS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003262 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3263 newdup = 0;
3264 retval = 0;
3265 goto set_speed;
3266 }
3267
3268 if (np->autoneg == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003269 if (np->fixed_mode & LPA_100FULL) {
3270 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3271 newdup = 1;
3272 } else if (np->fixed_mode & LPA_100HALF) {
3273 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3274 newdup = 0;
3275 } else if (np->fixed_mode & LPA_10FULL) {
3276 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3277 newdup = 1;
3278 } else {
3279 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3280 newdup = 0;
3281 }
3282 retval = 1;
3283 goto set_speed;
3284 }
3285 /* check auto negotiation is complete */
3286 if (!(mii_status & BMSR_ANEGCOMPLETE)) {
3287 /* still in autonegotiation - configure nic for 10 MBit HD and wait. */
3288 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3289 newdup = 0;
3290 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003291 goto set_speed;
3292 }
3293
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003294 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
3295 lpa = mii_rw(dev, np->phyaddr, MII_LPA, MII_READ);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003296
Linus Torvalds1da177e2005-04-16 15:20:36 -07003297 retval = 1;
3298 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003299 control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
3300 status_1000 = mii_rw(dev, np->phyaddr, MII_STAT1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003301
3302 if ((control_1000 & ADVERTISE_1000FULL) &&
3303 (status_1000 & LPA_1000FULL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003304 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_1000;
3305 newdup = 1;
3306 goto set_speed;
3307 }
3308 }
3309
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310 /* FIXME: handle parallel detection properly */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003311 adv_lpa = lpa & adv;
3312 if (adv_lpa & LPA_100FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003313 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3314 newdup = 1;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003315 } else if (adv_lpa & LPA_100HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003316 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3317 newdup = 0;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003318 } else if (adv_lpa & LPA_10FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003319 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3320 newdup = 1;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003321 } else if (adv_lpa & LPA_10HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003322 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3323 newdup = 0;
3324 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003325 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3326 newdup = 0;
3327 }
3328
3329set_speed:
3330 if (np->duplex == newdup && np->linkspeed == newls)
3331 return retval;
3332
Linus Torvalds1da177e2005-04-16 15:20:36 -07003333 np->duplex = newdup;
3334 np->linkspeed = newls;
3335
Ayaz Abdullab2976d22008-02-04 15:13:59 -05003336 /* The transmitter and receiver must be restarted for safe update */
3337 if (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_START) {
3338 txrxFlags |= NV_RESTART_TX;
3339 nv_stop_tx(dev);
3340 }
3341 if (readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) {
3342 txrxFlags |= NV_RESTART_RX;
3343 nv_stop_rx(dev);
3344 }
3345
Linus Torvalds1da177e2005-04-16 15:20:36 -07003346 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaa4336862008-04-18 13:50:43 -07003347 phyreg = readl(base + NvRegSlotTime);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003348 phyreg &= ~(0x3FF00);
Ayaz Abdullaa4336862008-04-18 13:50:43 -07003349 if (((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10) ||
3350 ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100))
3351 phyreg |= NVREG_SLOTTIME_10_100_FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003352 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000)
Ayaz Abdullaa4336862008-04-18 13:50:43 -07003353 phyreg |= NVREG_SLOTTIME_1000_FULL;
3354 writel(phyreg, base + NvRegSlotTime);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 }
3356
3357 phyreg = readl(base + NvRegPhyInterface);
3358 phyreg &= ~(PHY_HALF|PHY_100|PHY_1000);
3359 if (np->duplex == 0)
3360 phyreg |= PHY_HALF;
3361 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100)
3362 phyreg |= PHY_100;
3363 else if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
3364 phyreg |= PHY_1000;
3365 writel(phyreg, base + NvRegPhyInterface);
3366
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003367 phy_exp = mii_rw(dev, np->phyaddr, MII_EXPANSION, MII_READ) & EXPANSION_NWAY; /* autoneg capable */
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003368 if (phyreg & PHY_RGMII) {
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003369 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000) {
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003370 txreg = NVREG_TX_DEFERRAL_RGMII_1000;
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003371 } else {
3372 if (!phy_exp && !np->duplex && (np->driver_data & DEV_HAS_COLLISION_FIX)) {
3373 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_10)
3374 txreg = NVREG_TX_DEFERRAL_RGMII_STRETCH_10;
3375 else
3376 txreg = NVREG_TX_DEFERRAL_RGMII_STRETCH_100;
3377 } else {
3378 txreg = NVREG_TX_DEFERRAL_RGMII_10_100;
3379 }
3380 }
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003381 } else {
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003382 if (!phy_exp && !np->duplex && (np->driver_data & DEV_HAS_COLLISION_FIX))
3383 txreg = NVREG_TX_DEFERRAL_MII_STRETCH;
3384 else
3385 txreg = NVREG_TX_DEFERRAL_DEFAULT;
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003386 }
3387 writel(txreg, base + NvRegTxDeferral);
3388
Ayaz Abdulla95d161c2006-07-06 16:46:25 -04003389 if (np->desc_ver == DESC_VER_1) {
3390 txreg = NVREG_TX_WM_DESC1_DEFAULT;
3391 } else {
3392 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
3393 txreg = NVREG_TX_WM_DESC2_3_1000;
3394 else
3395 txreg = NVREG_TX_WM_DESC2_3_DEFAULT;
3396 }
3397 writel(txreg, base + NvRegTxWatermark);
3398
Szymon Janc78aea4f2010-11-27 08:39:43 +00003399 writel(NVREG_MISC1_FORCE | (np->duplex ? 0 : NVREG_MISC1_HD),
Linus Torvalds1da177e2005-04-16 15:20:36 -07003400 base + NvRegMisc1);
3401 pci_push(base);
3402 writel(np->linkspeed, base + NvRegLinkSpeed);
3403 pci_push(base);
3404
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003405 pause_flags = 0;
3406 /* setup pause frame */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003407 if (np->duplex != 0) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003408 if (np->autoneg && np->pause_flags & NV_PAUSEFRAME_AUTONEG) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003409 adv_pause = adv & (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
3410 lpa_pause = lpa & (LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003411
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003412 switch (adv_pause) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003413 case ADVERTISE_PAUSE_CAP:
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003414 if (lpa_pause & LPA_PAUSE_CAP) {
3415 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3416 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
3417 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3418 }
3419 break;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003420 case ADVERTISE_PAUSE_ASYM:
Szymon Janc78aea4f2010-11-27 08:39:43 +00003421 if (lpa_pause == (LPA_PAUSE_CAP | LPA_PAUSE_ASYM))
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003422 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003423 break;
Szymon Janc78aea4f2010-11-27 08:39:43 +00003424 case ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM:
3425 if (lpa_pause & LPA_PAUSE_CAP) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003426 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3427 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
3428 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3429 }
3430 if (lpa_pause == LPA_PAUSE_ASYM)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003431 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003432 break;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003433 }
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003434 } else {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003435 pause_flags = np->pause_flags;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003436 }
3437 }
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003438 nv_update_pause(dev, pause_flags);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003439
Ayaz Abdullab2976d22008-02-04 15:13:59 -05003440 if (txrxFlags & NV_RESTART_TX)
3441 nv_start_tx(dev);
3442 if (txrxFlags & NV_RESTART_RX)
3443 nv_start_rx(dev);
3444
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 return retval;
3446}
3447
3448static void nv_linkchange(struct net_device *dev)
3449{
3450 if (nv_update_linkspeed(dev)) {
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05003451 if (!netif_carrier_ok(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003452 netif_carrier_on(dev);
Joe Perches1d397f32010-11-29 07:41:57 +00003453 netdev_info(dev, "link up\n");
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00003454 nv_txrx_gate(dev, false);
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05003455 nv_start_rx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003456 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003457 } else {
3458 if (netif_carrier_ok(dev)) {
3459 netif_carrier_off(dev);
Joe Perches1d397f32010-11-29 07:41:57 +00003460 netdev_info(dev, "link down\n");
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00003461 nv_txrx_gate(dev, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003462 nv_stop_rx(dev);
3463 }
3464 }
3465}
3466
3467static void nv_link_irq(struct net_device *dev)
3468{
3469 u8 __iomem *base = get_hwbase(dev);
3470 u32 miistat;
3471
3472 miistat = readl(base + NvRegMIIStatus);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05003473 writel(NVREG_MIISTAT_LINKCHANGE, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003474
3475 if (miistat & (NVREG_MIISTAT_LINKCHANGE))
3476 nv_linkchange(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003477}
3478
Ayaz Abdulla4db0ee172008-06-09 16:51:06 -07003479static void nv_msi_workaround(struct fe_priv *np)
3480{
3481
3482 /* Need to toggle the msi irq mask within the ethernet device,
3483 * otherwise, future interrupts will not be detected.
3484 */
3485 if (np->msi_flags & NV_MSI_ENABLED) {
3486 u8 __iomem *base = np->base;
3487
3488 writel(0, base + NvRegMSIIrqMask);
3489 writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask);
3490 }
3491}
3492
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003493static inline int nv_change_interrupt_mode(struct net_device *dev, int total_work)
3494{
3495 struct fe_priv *np = netdev_priv(dev);
3496
3497 if (optimization_mode == NV_OPTIMIZATION_MODE_DYNAMIC) {
3498 if (total_work > NV_DYNAMIC_THRESHOLD) {
3499 /* transition to poll based interrupts */
3500 np->quiet_count = 0;
3501 if (np->irqmask != NVREG_IRQMASK_CPU) {
3502 np->irqmask = NVREG_IRQMASK_CPU;
3503 return 1;
3504 }
3505 } else {
3506 if (np->quiet_count < NV_DYNAMIC_MAX_QUIET_COUNT) {
3507 np->quiet_count++;
3508 } else {
3509 /* reached a period of low activity, switch
3510 to per tx/rx packet interrupts */
3511 if (np->irqmask != NVREG_IRQMASK_THROUGHPUT) {
3512 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
3513 return 1;
3514 }
3515 }
3516 }
3517 }
3518 return 0;
3519}
3520
David Howells7d12e782006-10-05 14:55:46 +01003521static irqreturn_t nv_nic_irq(int foo, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003522{
3523 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003524 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525 u8 __iomem *base = get_hwbase(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003526
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003527 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3528 np->events = readl(base + NvRegIrqStatus);
Ayaz Abdulla1b2bb762009-03-05 08:02:34 +00003529 writel(np->events, base + NvRegIrqStatus);
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003530 } else {
3531 np->events = readl(base + NvRegMSIXIrqStatus);
Ayaz Abdulla1b2bb762009-03-05 08:02:34 +00003532 writel(np->events, base + NvRegMSIXIrqStatus);
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003533 }
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003534 if (!(np->events & np->irqmask))
3535 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003536
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003537 nv_msi_workaround(np);
Ayaz Abdulla4db0ee172008-06-09 16:51:06 -07003538
Eric Dumazet78c29bd2009-07-02 04:04:45 +00003539 if (napi_schedule_prep(&np->napi)) {
3540 /*
3541 * Disable further irq's (msix not enabled with napi)
3542 */
3543 writel(0, base + NvRegIrqMask);
3544 __napi_schedule(&np->napi);
3545 }
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003546
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003547 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003548}
3549
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003550/**
3551 * All _optimized functions are used to help increase performance
3552 * (reduce CPU and increase throughput). They use descripter version 3,
3553 * compiler directives, and reduce memory accesses.
3554 */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003555static irqreturn_t nv_nic_irq_optimized(int foo, void *data)
3556{
3557 struct net_device *dev = (struct net_device *) data;
3558 struct fe_priv *np = netdev_priv(dev);
3559 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003560
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003561 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3562 np->events = readl(base + NvRegIrqStatus);
Ayaz Abdulla1b2bb762009-03-05 08:02:34 +00003563 writel(np->events, base + NvRegIrqStatus);
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003564 } else {
3565 np->events = readl(base + NvRegMSIXIrqStatus);
Ayaz Abdulla1b2bb762009-03-05 08:02:34 +00003566 writel(np->events, base + NvRegMSIXIrqStatus);
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003567 }
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003568 if (!(np->events & np->irqmask))
3569 return IRQ_NONE;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003570
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003571 nv_msi_workaround(np);
Ayaz Abdulla4db0ee172008-06-09 16:51:06 -07003572
Eric Dumazet78c29bd2009-07-02 04:04:45 +00003573 if (napi_schedule_prep(&np->napi)) {
3574 /*
3575 * Disable further irq's (msix not enabled with napi)
3576 */
3577 writel(0, base + NvRegIrqMask);
3578 __napi_schedule(&np->napi);
3579 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003580
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003581 return IRQ_HANDLED;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003582}
3583
David Howells7d12e782006-10-05 14:55:46 +01003584static irqreturn_t nv_nic_irq_tx(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003585{
3586 struct net_device *dev = (struct net_device *) data;
3587 struct fe_priv *np = netdev_priv(dev);
3588 u8 __iomem *base = get_hwbase(dev);
3589 u32 events;
3590 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003591 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003592
Szymon Janc78aea4f2010-11-27 08:39:43 +00003593 for (i = 0;; i++) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003594 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_TX_ALL;
Mike Ditto2a4e7a02011-11-05 14:38:21 +00003595 writel(events, base + NvRegMSIXIrqStatus);
3596 netdev_dbg(dev, "tx irq events: %08x\n", events);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003597 if (!(events & np->irqmask))
3598 break;
3599
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003600 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05003601 nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003602 spin_unlock_irqrestore(&np->lock, flags);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003603
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003604 if (unlikely(i > max_interrupt_work)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003605 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003606 /* disable interrupts on the nic */
3607 writel(NVREG_IRQ_TX_ALL, base + NvRegIrqMask);
3608 pci_push(base);
3609
3610 if (!np->in_shutdown) {
3611 np->nic_poll_irq |= NVREG_IRQ_TX_ALL;
3612 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3613 }
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003614 spin_unlock_irqrestore(&np->lock, flags);
Joe Perchesc20ec762010-11-29 07:42:02 +00003615 netdev_dbg(dev, "%s: too many iterations (%d)\n",
3616 __func__, i);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003617 break;
3618 }
3619
3620 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003621
3622 return IRQ_RETVAL(i);
3623}
3624
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003625static int nv_napi_poll(struct napi_struct *napi, int budget)
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003626{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003627 struct fe_priv *np = container_of(napi, struct fe_priv, napi);
3628 struct net_device *dev = np->dev;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003629 u8 __iomem *base = get_hwbase(dev);
Francois Romieud15e9c42006-12-17 23:03:15 +01003630 unsigned long flags;
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003631 int retcode;
Szymon Janc78aea4f2010-11-27 08:39:43 +00003632 int rx_count, tx_work = 0, rx_work = 0;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003633
stephen hemminger81a2e362010-04-28 08:25:28 +00003634 do {
3635 if (!nv_optimized(np)) {
3636 spin_lock_irqsave(&np->lock, flags);
3637 tx_work += nv_tx_done(dev, np->tx_ring_size);
3638 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003639
Tom Herbertd951f722010-05-05 18:15:21 +00003640 rx_count = nv_rx_process(dev, budget - rx_work);
stephen hemminger81a2e362010-04-28 08:25:28 +00003641 retcode = nv_alloc_rx(dev);
3642 } else {
3643 spin_lock_irqsave(&np->lock, flags);
3644 tx_work += nv_tx_done_optimized(dev, np->tx_ring_size);
3645 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003646
Tom Herbertd951f722010-05-05 18:15:21 +00003647 rx_count = nv_rx_process_optimized(dev,
3648 budget - rx_work);
stephen hemminger81a2e362010-04-28 08:25:28 +00003649 retcode = nv_alloc_rx_optimized(dev);
3650 }
3651 } while (retcode == 0 &&
3652 rx_count > 0 && (rx_work += rx_count) < budget);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003653
Ayaz Abdullae0379a12007-02-20 03:34:30 -05003654 if (retcode) {
Francois Romieud15e9c42006-12-17 23:03:15 +01003655 spin_lock_irqsave(&np->lock, flags);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003656 if (!np->in_shutdown)
3657 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Francois Romieud15e9c42006-12-17 23:03:15 +01003658 spin_unlock_irqrestore(&np->lock, flags);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003659 }
3660
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003661 nv_change_interrupt_mode(dev, tx_work + rx_work);
3662
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003663 if (unlikely(np->events & NVREG_IRQ_LINK)) {
3664 spin_lock_irqsave(&np->lock, flags);
3665 nv_link_irq(dev);
3666 spin_unlock_irqrestore(&np->lock, flags);
3667 }
3668 if (unlikely(np->need_linktimer && time_after(jiffies, np->link_timeout))) {
3669 spin_lock_irqsave(&np->lock, flags);
3670 nv_linkchange(dev);
3671 spin_unlock_irqrestore(&np->lock, flags);
3672 np->link_timeout = jiffies + LINK_TIMEOUT;
3673 }
3674 if (unlikely(np->events & NVREG_IRQ_RECOVER_ERROR)) {
3675 spin_lock_irqsave(&np->lock, flags);
3676 if (!np->in_shutdown) {
3677 np->nic_poll_irq = np->irqmask;
3678 np->recover_error = 1;
3679 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3680 }
3681 spin_unlock_irqrestore(&np->lock, flags);
David S. Miller6c2da9c2009-04-09 01:09:33 -07003682 napi_complete(napi);
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003683 return rx_work;
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003684 }
3685
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003686 if (rx_work < budget) {
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003687 /* re-enable interrupts
3688 (msix not enabled in napi) */
David S. Miller6c2da9c2009-04-09 01:09:33 -07003689 napi_complete(napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003690
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003691 writel(np->irqmask, base + NvRegIrqMask);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003692 }
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003693 return rx_work;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003694}
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003695
David Howells7d12e782006-10-05 14:55:46 +01003696static irqreturn_t nv_nic_irq_rx(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003697{
3698 struct net_device *dev = (struct net_device *) data;
3699 struct fe_priv *np = netdev_priv(dev);
3700 u8 __iomem *base = get_hwbase(dev);
3701 u32 events;
3702 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003703 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003704
Szymon Janc78aea4f2010-11-27 08:39:43 +00003705 for (i = 0;; i++) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003706 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
Mike Ditto2a4e7a02011-11-05 14:38:21 +00003707 writel(events, base + NvRegMSIXIrqStatus);
3708 netdev_dbg(dev, "rx irq events: %08x\n", events);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003709 if (!(events & np->irqmask))
3710 break;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003711
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003712 if (nv_rx_process_optimized(dev, RX_WORK_PER_LOOP)) {
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003713 if (unlikely(nv_alloc_rx_optimized(dev))) {
3714 spin_lock_irqsave(&np->lock, flags);
3715 if (!np->in_shutdown)
3716 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3717 spin_unlock_irqrestore(&np->lock, flags);
3718 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003719 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003720
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003721 if (unlikely(i > max_interrupt_work)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003722 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003723 /* disable interrupts on the nic */
3724 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
3725 pci_push(base);
3726
3727 if (!np->in_shutdown) {
3728 np->nic_poll_irq |= NVREG_IRQ_RX_ALL;
3729 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3730 }
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003731 spin_unlock_irqrestore(&np->lock, flags);
Joe Perchesc20ec762010-11-29 07:42:02 +00003732 netdev_dbg(dev, "%s: too many iterations (%d)\n",
3733 __func__, i);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003734 break;
3735 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003736 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003737
3738 return IRQ_RETVAL(i);
3739}
3740
David Howells7d12e782006-10-05 14:55:46 +01003741static irqreturn_t nv_nic_irq_other(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003742{
3743 struct net_device *dev = (struct net_device *) data;
3744 struct fe_priv *np = netdev_priv(dev);
3745 u8 __iomem *base = get_hwbase(dev);
3746 u32 events;
3747 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003748 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003749
Szymon Janc78aea4f2010-11-27 08:39:43 +00003750 for (i = 0;; i++) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003751 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_OTHER;
Mike Ditto2a4e7a02011-11-05 14:38:21 +00003752 writel(events, base + NvRegMSIXIrqStatus);
3753 netdev_dbg(dev, "irq events: %08x\n", events);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003754 if (!(events & np->irqmask))
3755 break;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003756
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05003757 /* check tx in case we reached max loop limit in tx isr */
3758 spin_lock_irqsave(&np->lock, flags);
3759 nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
3760 spin_unlock_irqrestore(&np->lock, flags);
3761
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003762 if (events & NVREG_IRQ_LINK) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003763 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003764 nv_link_irq(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003765 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003766 }
3767 if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003768 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003769 nv_linkchange(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003770 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003771 np->link_timeout = jiffies + LINK_TIMEOUT;
3772 }
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003773 if (events & NVREG_IRQ_RECOVER_ERROR) {
3774 spin_lock_irq(&np->lock);
3775 /* disable interrupts on the nic */
3776 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
3777 pci_push(base);
3778
3779 if (!np->in_shutdown) {
3780 np->nic_poll_irq |= NVREG_IRQ_OTHER;
3781 np->recover_error = 1;
3782 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3783 }
3784 spin_unlock_irq(&np->lock);
3785 break;
3786 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003787 if (unlikely(i > max_interrupt_work)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003788 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003789 /* disable interrupts on the nic */
3790 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
3791 pci_push(base);
3792
3793 if (!np->in_shutdown) {
3794 np->nic_poll_irq |= NVREG_IRQ_OTHER;
3795 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3796 }
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003797 spin_unlock_irqrestore(&np->lock, flags);
Joe Perchesc20ec762010-11-29 07:42:02 +00003798 netdev_dbg(dev, "%s: too many iterations (%d)\n",
3799 __func__, i);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003800 break;
3801 }
3802
3803 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003804
3805 return IRQ_RETVAL(i);
3806}
3807
David Howells7d12e782006-10-05 14:55:46 +01003808static irqreturn_t nv_nic_irq_test(int foo, void *data)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003809{
3810 struct net_device *dev = (struct net_device *) data;
3811 struct fe_priv *np = netdev_priv(dev);
3812 u8 __iomem *base = get_hwbase(dev);
3813 u32 events;
3814
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003815 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3816 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
Mike Ditto2a4e7a02011-11-05 14:38:21 +00003817 writel(events & NVREG_IRQ_TIMER, base + NvRegIrqStatus);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003818 } else {
3819 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
Mike Ditto2a4e7a02011-11-05 14:38:21 +00003820 writel(events & NVREG_IRQ_TIMER, base + NvRegMSIXIrqStatus);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003821 }
3822 pci_push(base);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003823 if (!(events & NVREG_IRQ_TIMER))
3824 return IRQ_RETVAL(0);
3825
Ayaz Abdulla4db0ee172008-06-09 16:51:06 -07003826 nv_msi_workaround(np);
3827
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003828 spin_lock(&np->lock);
3829 np->intr_test = 1;
3830 spin_unlock(&np->lock);
3831
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003832 return IRQ_RETVAL(1);
3833}
3834
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003835static void set_msix_vector_map(struct net_device *dev, u32 vector, u32 irqmask)
3836{
3837 u8 __iomem *base = get_hwbase(dev);
3838 int i;
3839 u32 msixmap = 0;
3840
3841 /* Each interrupt bit can be mapped to a MSIX vector (4 bits).
3842 * MSIXMap0 represents the first 8 interrupts and MSIXMap1 represents
3843 * the remaining 8 interrupts.
3844 */
3845 for (i = 0; i < 8; i++) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003846 if ((irqmask >> i) & 0x1)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003847 msixmap |= vector << (i << 2);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003848 }
3849 writel(readl(base + NvRegMSIXMap0) | msixmap, base + NvRegMSIXMap0);
3850
3851 msixmap = 0;
3852 for (i = 0; i < 8; i++) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003853 if ((irqmask >> (i + 8)) & 0x1)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003854 msixmap |= vector << (i << 2);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003855 }
3856 writel(readl(base + NvRegMSIXMap1) | msixmap, base + NvRegMSIXMap1);
3857}
3858
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003859static int nv_request_irq(struct net_device *dev, int intr_test)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003860{
3861 struct fe_priv *np = get_nvpriv(dev);
3862 u8 __iomem *base = get_hwbase(dev);
3863 int ret = 1;
3864 int i;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003865 irqreturn_t (*handler)(int foo, void *data);
3866
3867 if (intr_test) {
3868 handler = nv_nic_irq_test;
3869 } else {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04003870 if (nv_optimized(np))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003871 handler = nv_nic_irq_optimized;
3872 else
3873 handler = nv_nic_irq;
3874 }
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003875
3876 if (np->msi_flags & NV_MSI_X_CAPABLE) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003877 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003878 np->msi_x_entry[i].entry = i;
Szymon Janc34cf97e2010-11-27 08:39:46 +00003879 ret = pci_enable_msix(np->pci_dev, np->msi_x_entry, (np->msi_flags & NV_MSI_X_VECTORS_MASK));
3880 if (ret == 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003881 np->msi_flags |= NV_MSI_X_ENABLED;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003882 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT && !intr_test) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003883 /* Request irq for rx handling */
Yinghai Luddb213f2009-02-06 01:29:23 -08003884 sprintf(np->name_rx, "%s-rx", dev->name);
3885 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08003886 nv_nic_irq_rx, IRQF_SHARED, np->name_rx, dev) != 0) {
Joe Perches1d397f32010-11-29 07:41:57 +00003887 netdev_info(dev,
3888 "request_irq failed for rx %d\n",
3889 ret);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003890 pci_disable_msix(np->pci_dev);
3891 np->msi_flags &= ~NV_MSI_X_ENABLED;
3892 goto out_err;
3893 }
3894 /* Request irq for tx handling */
Yinghai Luddb213f2009-02-06 01:29:23 -08003895 sprintf(np->name_tx, "%s-tx", dev->name);
3896 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08003897 nv_nic_irq_tx, IRQF_SHARED, np->name_tx, dev) != 0) {
Joe Perches1d397f32010-11-29 07:41:57 +00003898 netdev_info(dev,
3899 "request_irq failed for tx %d\n",
3900 ret);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003901 pci_disable_msix(np->pci_dev);
3902 np->msi_flags &= ~NV_MSI_X_ENABLED;
3903 goto out_free_rx;
3904 }
3905 /* Request irq for link and timer handling */
Yinghai Luddb213f2009-02-06 01:29:23 -08003906 sprintf(np->name_other, "%s-other", dev->name);
3907 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08003908 nv_nic_irq_other, IRQF_SHARED, np->name_other, dev) != 0) {
Joe Perches1d397f32010-11-29 07:41:57 +00003909 netdev_info(dev,
3910 "request_irq failed for link %d\n",
3911 ret);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003912 pci_disable_msix(np->pci_dev);
3913 np->msi_flags &= ~NV_MSI_X_ENABLED;
3914 goto out_free_tx;
3915 }
3916 /* map interrupts to their respective vector */
3917 writel(0, base + NvRegMSIXMap0);
3918 writel(0, base + NvRegMSIXMap1);
3919 set_msix_vector_map(dev, NV_MSI_X_VECTOR_RX, NVREG_IRQ_RX_ALL);
3920 set_msix_vector_map(dev, NV_MSI_X_VECTOR_TX, NVREG_IRQ_TX_ALL);
3921 set_msix_vector_map(dev, NV_MSI_X_VECTOR_OTHER, NVREG_IRQ_OTHER);
3922 } else {
3923 /* Request irq for all interrupts */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003924 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 +00003925 netdev_info(dev,
3926 "request_irq failed %d\n",
3927 ret);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003928 pci_disable_msix(np->pci_dev);
3929 np->msi_flags &= ~NV_MSI_X_ENABLED;
3930 goto out_err;
3931 }
3932
3933 /* map interrupts to vector 0 */
3934 writel(0, base + NvRegMSIXMap0);
3935 writel(0, base + NvRegMSIXMap1);
3936 }
Mike Ditto89328782011-11-16 12:15:11 +00003937 netdev_info(dev, "MSI-X enabled\n");
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003938 }
3939 }
3940 if (ret != 0 && np->msi_flags & NV_MSI_CAPABLE) {
Szymon Janc34cf97e2010-11-27 08:39:46 +00003941 ret = pci_enable_msi(np->pci_dev);
3942 if (ret == 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003943 np->msi_flags |= NV_MSI_ENABLED;
Manfred Spraula7475902007-10-17 21:52:33 +02003944 dev->irq = np->pci_dev->irq;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003945 if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0) {
Joe Perches1d397f32010-11-29 07:41:57 +00003946 netdev_info(dev, "request_irq failed %d\n",
3947 ret);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003948 pci_disable_msi(np->pci_dev);
3949 np->msi_flags &= ~NV_MSI_ENABLED;
Manfred Spraula7475902007-10-17 21:52:33 +02003950 dev->irq = np->pci_dev->irq;
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003951 goto out_err;
3952 }
3953
3954 /* map interrupts to vector 0 */
3955 writel(0, base + NvRegMSIMap0);
3956 writel(0, base + NvRegMSIMap1);
3957 /* enable msi vector 0 */
3958 writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask);
Mike Ditto89328782011-11-16 12:15:11 +00003959 netdev_info(dev, "MSI enabled\n");
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003960 }
3961 }
3962 if (ret != 0) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003963 if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003964 goto out_err;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003965
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003966 }
3967
3968 return 0;
3969out_free_tx:
3970 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector, dev);
3971out_free_rx:
3972 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector, dev);
3973out_err:
3974 return 1;
3975}
3976
3977static void nv_free_irq(struct net_device *dev)
3978{
3979 struct fe_priv *np = get_nvpriv(dev);
3980 int i;
3981
3982 if (np->msi_flags & NV_MSI_X_ENABLED) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003983 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003984 free_irq(np->msi_x_entry[i].vector, dev);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003985 pci_disable_msix(np->pci_dev);
3986 np->msi_flags &= ~NV_MSI_X_ENABLED;
3987 } else {
3988 free_irq(np->pci_dev->irq, dev);
3989 if (np->msi_flags & NV_MSI_ENABLED) {
3990 pci_disable_msi(np->pci_dev);
3991 np->msi_flags &= ~NV_MSI_ENABLED;
3992 }
3993 }
3994}
3995
Linus Torvalds1da177e2005-04-16 15:20:36 -07003996static void nv_do_nic_poll(unsigned long data)
3997{
3998 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003999 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004000 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004001 u32 mask = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004002
Linus Torvalds1da177e2005-04-16 15:20:36 -07004003 /*
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004004 * First disable irq(s) and then
Linus Torvalds1da177e2005-04-16 15:20:36 -07004005 * reenable interrupts on the nic, we have to do this before calling
4006 * nv_nic_irq because that may decide to do otherwise
4007 */
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004008
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004009 if (!using_multi_irqs(dev)) {
4010 if (np->msi_flags & NV_MSI_X_ENABLED)
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004011 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004012 else
Manfred Spraula7475902007-10-17 21:52:33 +02004013 disable_irq_lockdep(np->pci_dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004014 mask = np->irqmask;
4015 } else {
4016 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004017 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004018 mask |= NVREG_IRQ_RX_ALL;
4019 }
4020 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004021 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004022 mask |= NVREG_IRQ_TX_ALL;
4023 }
4024 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004025 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004026 mask |= NVREG_IRQ_OTHER;
4027 }
4028 }
Manfred Spraula7475902007-10-17 21:52:33 +02004029 /* disable_irq() contains synchronize_irq, thus no irq handler can run now */
4030
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004031 if (np->recover_error) {
4032 np->recover_error = 0;
Joe Perches1d397f32010-11-29 07:41:57 +00004033 netdev_info(dev, "MAC in recoverable error state\n");
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004034 if (netif_running(dev)) {
4035 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004036 netif_addr_lock(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004037 spin_lock(&np->lock);
4038 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004039 nv_stop_rxtx(dev);
Ayaz Abdulladaa91a92009-02-07 00:25:00 -08004040 if (np->driver_data & DEV_HAS_POWER_CNTRL)
4041 nv_mac_reset(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004042 nv_txrx_reset(dev);
4043 /* drain rx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004044 nv_drain_rxtx(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004045 /* reinit driver view of the rx queue */
4046 set_bufsize(dev);
4047 if (nv_init_ring(dev)) {
4048 if (!np->in_shutdown)
4049 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
4050 }
4051 /* reinit nic view of the rx queue */
4052 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4053 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00004054 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004055 base + NvRegRingSizes);
4056 pci_push(base);
4057 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4058 pci_push(base);
Ayaz Abdulladaa91a92009-02-07 00:25:00 -08004059 /* clear interrupts */
4060 if (!(np->msi_flags & NV_MSI_X_ENABLED))
4061 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4062 else
4063 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004064
4065 /* restart rx engine */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004066 nv_start_rxtx(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004067 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07004068 netif_addr_unlock(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004069 netif_tx_unlock_bh(dev);
4070 }
4071 }
4072
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004073 writel(mask, base + NvRegIrqMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004074 pci_push(base);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004075
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004076 if (!using_multi_irqs(dev)) {
Yinghai Lu79d30a52009-02-06 01:30:01 -08004077 np->nic_poll_irq = 0;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004078 if (nv_optimized(np))
Ayaz Abdullafcc5f262007-03-23 05:49:37 -05004079 nv_nic_irq_optimized(0, dev);
4080 else
4081 nv_nic_irq(0, dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004082 if (np->msi_flags & NV_MSI_X_ENABLED)
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004083 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004084 else
Manfred Spraula7475902007-10-17 21:52:33 +02004085 enable_irq_lockdep(np->pci_dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004086 } else {
4087 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
Yinghai Lu79d30a52009-02-06 01:30:01 -08004088 np->nic_poll_irq &= ~NVREG_IRQ_RX_ALL;
David Howells7d12e782006-10-05 14:55:46 +01004089 nv_nic_irq_rx(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004090 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004091 }
4092 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
Yinghai Lu79d30a52009-02-06 01:30:01 -08004093 np->nic_poll_irq &= ~NVREG_IRQ_TX_ALL;
David Howells7d12e782006-10-05 14:55:46 +01004094 nv_nic_irq_tx(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004095 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004096 }
4097 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
Yinghai Lu79d30a52009-02-06 01:30:01 -08004098 np->nic_poll_irq &= ~NVREG_IRQ_OTHER;
David Howells7d12e782006-10-05 14:55:46 +01004099 nv_nic_irq_other(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004100 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004101 }
4102 }
Yinghai Lu79d30a52009-02-06 01:30:01 -08004103
Linus Torvalds1da177e2005-04-16 15:20:36 -07004104}
4105
Michal Schmidt2918c352005-05-12 19:42:06 -04004106#ifdef CONFIG_NET_POLL_CONTROLLER
4107static void nv_poll_controller(struct net_device *dev)
4108{
4109 nv_do_nic_poll((unsigned long) dev);
4110}
4111#endif
4112
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004113static void nv_do_stats_poll(unsigned long data)
david decotignyf5d827a2011-11-16 12:15:13 +00004114 __acquires(&netdev_priv(dev)->hwstats_lock)
4115 __releases(&netdev_priv(dev)->hwstats_lock)
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004116{
4117 struct net_device *dev = (struct net_device *) data;
4118 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004119
david decotignyf5d827a2011-11-16 12:15:13 +00004120 /* If lock is currently taken, the stats are being refreshed
4121 * and hence fresh enough */
4122 if (spin_trylock(&np->hwstats_lock)) {
4123 nv_update_stats(dev);
4124 spin_unlock(&np->hwstats_lock);
4125 }
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004126
4127 if (!np->in_shutdown)
Daniel Drakebfebbb82008-03-18 11:07:18 +00004128 mod_timer(&np->stats_poll,
4129 round_jiffies(jiffies + STATS_INTERVAL));
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004130}
4131
Linus Torvalds1da177e2005-04-16 15:20:36 -07004132static void nv_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
4133{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004134 struct fe_priv *np = netdev_priv(dev);
Rick Jones68aad782011-11-07 13:29:27 +00004135 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
4136 strlcpy(info->version, FORCEDETH_VERSION, sizeof(info->version));
4137 strlcpy(info->bus_info, pci_name(np->pci_dev), sizeof(info->bus_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004138}
4139
4140static void nv_get_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
4141{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004142 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004143 wolinfo->supported = WAKE_MAGIC;
4144
4145 spin_lock_irq(&np->lock);
4146 if (np->wolenabled)
4147 wolinfo->wolopts = WAKE_MAGIC;
4148 spin_unlock_irq(&np->lock);
4149}
4150
4151static int nv_set_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
4152{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004153 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004154 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004155 u32 flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004156
Linus Torvalds1da177e2005-04-16 15:20:36 -07004157 if (wolinfo->wolopts == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004158 np->wolenabled = 0;
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004159 } else if (wolinfo->wolopts & WAKE_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004160 np->wolenabled = 1;
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004161 flags = NVREG_WAKEUPFLAGS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004162 }
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004163 if (netif_running(dev)) {
4164 spin_lock_irq(&np->lock);
4165 writel(flags, base + NvRegWakeUpFlags);
4166 spin_unlock_irq(&np->lock);
4167 }
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00004168 device_set_wakeup_enable(&np->pci_dev->dev, np->wolenabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004169 return 0;
4170}
4171
4172static int nv_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
4173{
4174 struct fe_priv *np = netdev_priv(dev);
David Decotigny70739492011-04-27 18:32:40 +00004175 u32 speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004176 int adv;
4177
4178 spin_lock_irq(&np->lock);
4179 ecmd->port = PORT_MII;
4180 if (!netif_running(dev)) {
4181 /* We do not track link speed / duplex setting if the
4182 * interface is disabled. Force a link check */
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004183 if (nv_update_linkspeed(dev)) {
4184 if (!netif_carrier_ok(dev))
4185 netif_carrier_on(dev);
4186 } else {
4187 if (netif_carrier_ok(dev))
4188 netif_carrier_off(dev);
4189 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004190 }
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004191
4192 if (netif_carrier_ok(dev)) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00004193 switch (np->linkspeed & (NVREG_LINKSPEED_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004194 case NVREG_LINKSPEED_10:
David Decotigny70739492011-04-27 18:32:40 +00004195 speed = SPEED_10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004196 break;
4197 case NVREG_LINKSPEED_100:
David Decotigny70739492011-04-27 18:32:40 +00004198 speed = SPEED_100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004199 break;
4200 case NVREG_LINKSPEED_1000:
David Decotigny70739492011-04-27 18:32:40 +00004201 speed = SPEED_1000;
4202 break;
4203 default:
4204 speed = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004205 break;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004206 }
4207 ecmd->duplex = DUPLEX_HALF;
4208 if (np->duplex)
4209 ecmd->duplex = DUPLEX_FULL;
4210 } else {
David Decotigny70739492011-04-27 18:32:40 +00004211 speed = -1;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004212 ecmd->duplex = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213 }
David Decotigny70739492011-04-27 18:32:40 +00004214 ethtool_cmd_speed_set(ecmd, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004215 ecmd->autoneg = np->autoneg;
4216
4217 ecmd->advertising = ADVERTISED_MII;
4218 if (np->autoneg) {
4219 ecmd->advertising |= ADVERTISED_Autoneg;
4220 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004221 if (adv & ADVERTISE_10HALF)
4222 ecmd->advertising |= ADVERTISED_10baseT_Half;
4223 if (adv & ADVERTISE_10FULL)
4224 ecmd->advertising |= ADVERTISED_10baseT_Full;
4225 if (adv & ADVERTISE_100HALF)
4226 ecmd->advertising |= ADVERTISED_100baseT_Half;
4227 if (adv & ADVERTISE_100FULL)
4228 ecmd->advertising |= ADVERTISED_100baseT_Full;
4229 if (np->gigabit == PHY_GIGABIT) {
4230 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
4231 if (adv & ADVERTISE_1000FULL)
4232 ecmd->advertising |= ADVERTISED_1000baseT_Full;
4233 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004234 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004235 ecmd->supported = (SUPPORTED_Autoneg |
4236 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
4237 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
4238 SUPPORTED_MII);
4239 if (np->gigabit == PHY_GIGABIT)
4240 ecmd->supported |= SUPPORTED_1000baseT_Full;
4241
4242 ecmd->phy_address = np->phyaddr;
4243 ecmd->transceiver = XCVR_EXTERNAL;
4244
4245 /* ignore maxtxpkt, maxrxpkt for now */
4246 spin_unlock_irq(&np->lock);
4247 return 0;
4248}
4249
4250static int nv_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
4251{
4252 struct fe_priv *np = netdev_priv(dev);
David Decotigny25db0332011-04-27 18:32:39 +00004253 u32 speed = ethtool_cmd_speed(ecmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004254
4255 if (ecmd->port != PORT_MII)
4256 return -EINVAL;
4257 if (ecmd->transceiver != XCVR_EXTERNAL)
4258 return -EINVAL;
4259 if (ecmd->phy_address != np->phyaddr) {
4260 /* TODO: support switching between multiple phys. Should be
4261 * trivial, but not enabled due to lack of test hardware. */
4262 return -EINVAL;
4263 }
4264 if (ecmd->autoneg == AUTONEG_ENABLE) {
4265 u32 mask;
4266
4267 mask = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
4268 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full;
4269 if (np->gigabit == PHY_GIGABIT)
4270 mask |= ADVERTISED_1000baseT_Full;
4271
4272 if ((ecmd->advertising & mask) == 0)
4273 return -EINVAL;
4274
4275 } else if (ecmd->autoneg == AUTONEG_DISABLE) {
4276 /* Note: autonegotiation disable, speed 1000 intentionally
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004277 * forbidden - no one should need that. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004278
David Decotigny25db0332011-04-27 18:32:39 +00004279 if (speed != SPEED_10 && speed != SPEED_100)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004280 return -EINVAL;
4281 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
4282 return -EINVAL;
4283 } else {
4284 return -EINVAL;
4285 }
4286
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004287 netif_carrier_off(dev);
4288 if (netif_running(dev)) {
Tobias Diedrich97bff092008-07-03 23:54:56 -07004289 unsigned long flags;
4290
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004291 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004292 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004293 netif_addr_lock(dev);
Tobias Diedrich97bff092008-07-03 23:54:56 -07004294 /* with plain spinlock lockdep complains */
4295 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004296 /* stop engines */
Tobias Diedrich97bff092008-07-03 23:54:56 -07004297 /* FIXME:
4298 * this can take some time, and interrupts are disabled
4299 * due to spin_lock_irqsave, but let's hope no daemon
4300 * is going to change the settings very often...
4301 * Worst case:
4302 * NV_RXSTOP_DELAY1MAX + NV_TXSTOP_DELAY1MAX
4303 * + some minor delays, which is up to a second approximately
4304 */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004305 nv_stop_rxtx(dev);
Tobias Diedrich97bff092008-07-03 23:54:56 -07004306 spin_unlock_irqrestore(&np->lock, flags);
David S. Millere308a5d2008-07-15 00:13:44 -07004307 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004308 netif_tx_unlock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004309 }
4310
Linus Torvalds1da177e2005-04-16 15:20:36 -07004311 if (ecmd->autoneg == AUTONEG_ENABLE) {
4312 int adv, bmcr;
4313
4314 np->autoneg = 1;
4315
4316 /* advertise only what has been requested */
4317 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004318 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004319 if (ecmd->advertising & ADVERTISED_10baseT_Half)
4320 adv |= ADVERTISE_10HALF;
4321 if (ecmd->advertising & ADVERTISED_10baseT_Full)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004322 adv |= ADVERTISE_10FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004323 if (ecmd->advertising & ADVERTISED_100baseT_Half)
4324 adv |= ADVERTISE_100HALF;
4325 if (ecmd->advertising & ADVERTISED_100baseT_Full)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004326 adv |= ADVERTISE_100FULL;
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004327 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 -04004328 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4329 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
4330 adv |= ADVERTISE_PAUSE_ASYM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004331 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4332
4333 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004334 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004335 adv &= ~ADVERTISE_1000FULL;
4336 if (ecmd->advertising & ADVERTISED_1000baseT_Full)
4337 adv |= ADVERTISE_1000FULL;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004338 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004339 }
4340
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004341 if (netif_running(dev))
Joe Perches1d397f32010-11-29 07:41:57 +00004342 netdev_info(dev, "link down\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004343 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004344 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
4345 bmcr |= BMCR_ANENABLE;
4346 /* reset the phy in order for settings to stick,
4347 * and cause autoneg to start */
4348 if (phy_reset(dev, bmcr)) {
Joe Perches1d397f32010-11-29 07:41:57 +00004349 netdev_info(dev, "phy reset failed\n");
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004350 return -EINVAL;
4351 }
4352 } else {
4353 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4354 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4355 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004356 } else {
4357 int adv, bmcr;
4358
4359 np->autoneg = 0;
4360
4361 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004362 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
David Decotigny25db0332011-04-27 18:32:39 +00004363 if (speed == SPEED_10 && ecmd->duplex == DUPLEX_HALF)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004364 adv |= ADVERTISE_10HALF;
David Decotigny25db0332011-04-27 18:32:39 +00004365 if (speed == SPEED_10 && ecmd->duplex == DUPLEX_FULL)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004366 adv |= ADVERTISE_10FULL;
David Decotigny25db0332011-04-27 18:32:39 +00004367 if (speed == SPEED_100 && ecmd->duplex == DUPLEX_HALF)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004368 adv |= ADVERTISE_100HALF;
David Decotigny25db0332011-04-27 18:32:39 +00004369 if (speed == SPEED_100 && ecmd->duplex == DUPLEX_FULL)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004370 adv |= ADVERTISE_100FULL;
4371 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004372 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 -04004373 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4374 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
4375 }
4376 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) {
4377 adv |= ADVERTISE_PAUSE_ASYM;
4378 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
4379 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004380 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4381 np->fixed_mode = adv;
4382
4383 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004384 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004385 adv &= ~ADVERTISE_1000FULL;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004386 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004387 }
4388
4389 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004390 bmcr &= ~(BMCR_ANENABLE|BMCR_SPEED100|BMCR_SPEED1000|BMCR_FULLDPLX);
4391 if (np->fixed_mode & (ADVERTISE_10FULL|ADVERTISE_100FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004392 bmcr |= BMCR_FULLDPLX;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004393 if (np->fixed_mode & (ADVERTISE_100HALF|ADVERTISE_100FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004394 bmcr |= BMCR_SPEED100;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004395 if (np->phy_oui == PHY_OUI_MARVELL) {
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004396 /* reset the phy in order for forced mode settings to stick */
4397 if (phy_reset(dev, bmcr)) {
Joe Perches1d397f32010-11-29 07:41:57 +00004398 netdev_info(dev, "phy reset failed\n");
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004399 return -EINVAL;
4400 }
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004401 } else {
4402 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4403 if (netif_running(dev)) {
4404 /* Wait a bit and then reconfigure the nic. */
4405 udelay(10);
4406 nv_linkchange(dev);
4407 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004408 }
4409 }
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004410
4411 if (netif_running(dev)) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004412 nv_start_rxtx(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004413 nv_enable_irq(dev);
4414 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004415
4416 return 0;
4417}
4418
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004419#define FORCEDETH_REGS_VER 1
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004420
4421static int nv_get_regs_len(struct net_device *dev)
4422{
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004423 struct fe_priv *np = netdev_priv(dev);
4424 return np->register_size;
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004425}
4426
4427static void nv_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *buf)
4428{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004429 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004430 u8 __iomem *base = get_hwbase(dev);
4431 u32 *rbuf = buf;
4432 int i;
4433
4434 regs->version = FORCEDETH_REGS_VER;
4435 spin_lock_irq(&np->lock);
Szymon Janc78aea4f2010-11-27 08:39:43 +00004436 for (i = 0; i <= np->register_size/sizeof(u32); i++)
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004437 rbuf[i] = readl(base + i*sizeof(u32));
4438 spin_unlock_irq(&np->lock);
4439}
4440
4441static int nv_nway_reset(struct net_device *dev)
4442{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004443 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004444 int ret;
4445
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004446 if (np->autoneg) {
4447 int bmcr;
4448
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004449 netif_carrier_off(dev);
4450 if (netif_running(dev)) {
4451 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004452 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004453 netif_addr_lock(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004454 spin_lock(&np->lock);
4455 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004456 nv_stop_rxtx(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004457 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07004458 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004459 netif_tx_unlock_bh(dev);
Joe Perches1d397f32010-11-29 07:41:57 +00004460 netdev_info(dev, "link down\n");
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004461 }
4462
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004463 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004464 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
4465 bmcr |= BMCR_ANENABLE;
4466 /* reset the phy in order for settings to stick*/
4467 if (phy_reset(dev, bmcr)) {
Joe Perches1d397f32010-11-29 07:41:57 +00004468 netdev_info(dev, "phy reset failed\n");
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004469 return -EINVAL;
4470 }
4471 } else {
4472 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4473 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4474 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004475
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004476 if (netif_running(dev)) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004477 nv_start_rxtx(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004478 nv_enable_irq(dev);
4479 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004480 ret = 0;
4481 } else {
4482 ret = -EINVAL;
4483 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004484
4485 return ret;
4486}
4487
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004488static void nv_get_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
4489{
4490 struct fe_priv *np = netdev_priv(dev);
4491
4492 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 -04004493 ring->tx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
4494
4495 ring->rx_pending = np->rx_ring_size;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004496 ring->tx_pending = np->tx_ring_size;
4497}
4498
4499static int nv_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
4500{
4501 struct fe_priv *np = netdev_priv(dev);
4502 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004503 u8 *rxtx_ring, *rx_skbuff, *tx_skbuff;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004504 dma_addr_t ring_addr;
4505
4506 if (ring->rx_pending < RX_RING_MIN ||
4507 ring->tx_pending < TX_RING_MIN ||
4508 ring->rx_mini_pending != 0 ||
4509 ring->rx_jumbo_pending != 0 ||
4510 (np->desc_ver == DESC_VER_1 &&
4511 (ring->rx_pending > RING_MAX_DESC_VER_1 ||
4512 ring->tx_pending > RING_MAX_DESC_VER_1)) ||
4513 (np->desc_ver != DESC_VER_1 &&
4514 (ring->rx_pending > RING_MAX_DESC_VER_2_3 ||
4515 ring->tx_pending > RING_MAX_DESC_VER_2_3))) {
4516 return -EINVAL;
4517 }
4518
4519 /* allocate new rings */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004520 if (!nv_optimized(np)) {
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004521 rxtx_ring = pci_alloc_consistent(np->pci_dev,
4522 sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
4523 &ring_addr);
4524 } else {
4525 rxtx_ring = pci_alloc_consistent(np->pci_dev,
4526 sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
4527 &ring_addr);
4528 }
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004529 rx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->rx_pending, GFP_KERNEL);
4530 tx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->tx_pending, GFP_KERNEL);
4531 if (!rxtx_ring || !rx_skbuff || !tx_skbuff) {
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004532 /* fall back to old rings */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004533 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004534 if (rxtx_ring)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004535 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
4536 rxtx_ring, ring_addr);
4537 } else {
4538 if (rxtx_ring)
4539 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
4540 rxtx_ring, ring_addr);
4541 }
Szymon Janc9b03b062010-11-27 08:39:44 +00004542
4543 kfree(rx_skbuff);
4544 kfree(tx_skbuff);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004545 goto exit;
4546 }
4547
4548 if (netif_running(dev)) {
4549 nv_disable_irq(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00004550 nv_napi_disable(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004551 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004552 netif_addr_lock(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004553 spin_lock(&np->lock);
4554 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004555 nv_stop_rxtx(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004556 nv_txrx_reset(dev);
4557 /* drain queues */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004558 nv_drain_rxtx(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004559 /* delete queues */
4560 free_rings(dev);
4561 }
4562
4563 /* set new values */
4564 np->rx_ring_size = ring->rx_pending;
4565 np->tx_ring_size = ring->tx_pending;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004566
4567 if (!nv_optimized(np)) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00004568 np->rx_ring.orig = (struct ring_desc *)rxtx_ring;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004569 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
4570 } else {
Szymon Janc78aea4f2010-11-27 08:39:43 +00004571 np->rx_ring.ex = (struct ring_desc_ex *)rxtx_ring;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004572 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
4573 }
Szymon Janc78aea4f2010-11-27 08:39:43 +00004574 np->rx_skb = (struct nv_skb_map *)rx_skbuff;
4575 np->tx_skb = (struct nv_skb_map *)tx_skbuff;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004576 np->ring_addr = ring_addr;
4577
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004578 memset(np->rx_skb, 0, sizeof(struct nv_skb_map) * np->rx_ring_size);
4579 memset(np->tx_skb, 0, sizeof(struct nv_skb_map) * np->tx_ring_size);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004580
4581 if (netif_running(dev)) {
4582 /* reinit driver view of the queues */
4583 set_bufsize(dev);
4584 if (nv_init_ring(dev)) {
4585 if (!np->in_shutdown)
4586 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
4587 }
4588
4589 /* reinit nic view of the queues */
4590 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4591 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00004592 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004593 base + NvRegRingSizes);
4594 pci_push(base);
4595 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4596 pci_push(base);
4597
4598 /* restart engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004599 nv_start_rxtx(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004600 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07004601 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004602 netif_tx_unlock_bh(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00004603 nv_napi_enable(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004604 nv_enable_irq(dev);
4605 }
4606 return 0;
4607exit:
4608 return -ENOMEM;
4609}
4610
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004611static void nv_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
4612{
4613 struct fe_priv *np = netdev_priv(dev);
4614
4615 pause->autoneg = (np->pause_flags & NV_PAUSEFRAME_AUTONEG) != 0;
4616 pause->rx_pause = (np->pause_flags & NV_PAUSEFRAME_RX_ENABLE) != 0;
4617 pause->tx_pause = (np->pause_flags & NV_PAUSEFRAME_TX_ENABLE) != 0;
4618}
4619
4620static int nv_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
4621{
4622 struct fe_priv *np = netdev_priv(dev);
4623 int adv, bmcr;
4624
4625 if ((!np->autoneg && np->duplex == 0) ||
4626 (np->autoneg && !pause->autoneg && np->duplex == 0)) {
Joe Perches1d397f32010-11-29 07:41:57 +00004627 netdev_info(dev, "can not set pause settings when forced link is in half duplex\n");
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004628 return -EINVAL;
4629 }
4630 if (pause->tx_pause && !(np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)) {
Joe Perches1d397f32010-11-29 07:41:57 +00004631 netdev_info(dev, "hardware does not support tx pause frames\n");
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004632 return -EINVAL;
4633 }
4634
4635 netif_carrier_off(dev);
4636 if (netif_running(dev)) {
4637 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004638 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004639 netif_addr_lock(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004640 spin_lock(&np->lock);
4641 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004642 nv_stop_rxtx(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004643 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07004644 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004645 netif_tx_unlock_bh(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004646 }
4647
4648 np->pause_flags &= ~(NV_PAUSEFRAME_RX_REQ|NV_PAUSEFRAME_TX_REQ);
4649 if (pause->rx_pause)
4650 np->pause_flags |= NV_PAUSEFRAME_RX_REQ;
4651 if (pause->tx_pause)
4652 np->pause_flags |= NV_PAUSEFRAME_TX_REQ;
4653
4654 if (np->autoneg && pause->autoneg) {
4655 np->pause_flags |= NV_PAUSEFRAME_AUTONEG;
4656
4657 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
4658 adv &= ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004659 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 -04004660 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4661 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
4662 adv |= ADVERTISE_PAUSE_ASYM;
4663 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4664
4665 if (netif_running(dev))
Joe Perches1d397f32010-11-29 07:41:57 +00004666 netdev_info(dev, "link down\n");
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004667 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
4668 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4669 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4670 } else {
4671 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
4672 if (pause->rx_pause)
4673 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
4674 if (pause->tx_pause)
4675 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
4676
4677 if (!netif_running(dev))
4678 nv_update_linkspeed(dev);
4679 else
4680 nv_update_pause(dev, np->pause_flags);
4681 }
4682
4683 if (netif_running(dev)) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004684 nv_start_rxtx(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004685 nv_enable_irq(dev);
4686 }
4687 return 0;
4688}
4689
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004690static int nv_set_loopback(struct net_device *dev, netdev_features_t features)
Sanjay Hortikare19df762011-11-11 16:11:21 +00004691{
4692 struct fe_priv *np = netdev_priv(dev);
4693 unsigned long flags;
4694 u32 miicontrol;
4695 int err, retval = 0;
4696
4697 spin_lock_irqsave(&np->lock, flags);
4698 miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
4699 if (features & NETIF_F_LOOPBACK) {
4700 if (miicontrol & BMCR_LOOPBACK) {
4701 spin_unlock_irqrestore(&np->lock, flags);
4702 netdev_info(dev, "Loopback already enabled\n");
4703 return 0;
4704 }
4705 nv_disable_irq(dev);
4706 /* Turn on loopback mode */
4707 miicontrol |= BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000;
4708 err = mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol);
4709 if (err) {
4710 retval = PHY_ERROR;
4711 spin_unlock_irqrestore(&np->lock, flags);
4712 phy_init(dev);
4713 } else {
4714 if (netif_running(dev)) {
4715 /* Force 1000 Mbps full-duplex */
4716 nv_force_linkspeed(dev, NVREG_LINKSPEED_1000,
4717 1);
4718 /* Force link up */
4719 netif_carrier_on(dev);
4720 }
4721 spin_unlock_irqrestore(&np->lock, flags);
4722 netdev_info(dev,
4723 "Internal PHY loopback mode enabled.\n");
4724 }
4725 } else {
4726 if (!(miicontrol & BMCR_LOOPBACK)) {
4727 spin_unlock_irqrestore(&np->lock, flags);
4728 netdev_info(dev, "Loopback already disabled\n");
4729 return 0;
4730 }
4731 nv_disable_irq(dev);
4732 /* Turn off loopback */
4733 spin_unlock_irqrestore(&np->lock, flags);
4734 netdev_info(dev, "Internal PHY loopback mode disabled.\n");
4735 phy_init(dev);
4736 }
4737 msleep(500);
4738 spin_lock_irqsave(&np->lock, flags);
4739 nv_enable_irq(dev);
4740 spin_unlock_irqrestore(&np->lock, flags);
4741
4742 return retval;
4743}
4744
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004745static netdev_features_t nv_fix_features(struct net_device *dev,
4746 netdev_features_t features)
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004747{
Michał Mirosław569e1462011-04-15 04:50:49 +00004748 /* vlan is dependent on rx checksum offload */
4749 if (features & (NETIF_F_HW_VLAN_TX|NETIF_F_HW_VLAN_RX))
4750 features |= NETIF_F_RXCSUM;
4751
4752 return features;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004753}
4754
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004755static void nv_vlan_mode(struct net_device *dev, netdev_features_t features)
Jiri Pirko3326c782011-07-20 04:54:38 +00004756{
4757 struct fe_priv *np = get_nvpriv(dev);
4758
4759 spin_lock_irq(&np->lock);
4760
4761 if (features & NETIF_F_HW_VLAN_RX)
4762 np->txrxctl_bits |= NVREG_TXRXCTL_VLANSTRIP;
4763 else
4764 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANSTRIP;
4765
4766 if (features & NETIF_F_HW_VLAN_TX)
4767 np->txrxctl_bits |= NVREG_TXRXCTL_VLANINS;
4768 else
4769 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANINS;
4770
4771 writel(np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4772
4773 spin_unlock_irq(&np->lock);
4774}
4775
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004776static int nv_set_features(struct net_device *dev, netdev_features_t features)
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004777{
4778 struct fe_priv *np = netdev_priv(dev);
4779 u8 __iomem *base = get_hwbase(dev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004780 netdev_features_t changed = dev->features ^ features;
Sanjay Hortikare19df762011-11-11 16:11:21 +00004781 int retval;
4782
4783 if ((changed & NETIF_F_LOOPBACK) && netif_running(dev)) {
4784 retval = nv_set_loopback(dev, features);
4785 if (retval != 0)
4786 return retval;
4787 }
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004788
Michał Mirosław569e1462011-04-15 04:50:49 +00004789 if (changed & NETIF_F_RXCSUM) {
4790 spin_lock_irq(&np->lock);
4791
4792 if (features & NETIF_F_RXCSUM)
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004793 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
Michał Mirosław569e1462011-04-15 04:50:49 +00004794 else
4795 np->txrxctl_bits &= ~NVREG_TXRXCTL_RXCHECK;
4796
4797 if (netif_running(dev))
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004798 writel(np->txrxctl_bits, base + NvRegTxRxControl);
Michał Mirosław569e1462011-04-15 04:50:49 +00004799
4800 spin_unlock_irq(&np->lock);
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004801 }
4802
Jiri Pirko3326c782011-07-20 04:54:38 +00004803 if (changed & (NETIF_F_HW_VLAN_TX | NETIF_F_HW_VLAN_RX))
4804 nv_vlan_mode(dev, features);
4805
Michał Mirosław569e1462011-04-15 04:50:49 +00004806 return 0;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004807}
4808
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004809static int nv_get_sset_count(struct net_device *dev, int sset)
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004810{
4811 struct fe_priv *np = netdev_priv(dev);
4812
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004813 switch (sset) {
4814 case ETH_SS_TEST:
4815 if (np->driver_data & DEV_HAS_TEST_EXTENDED)
4816 return NV_TEST_COUNT_EXTENDED;
4817 else
4818 return NV_TEST_COUNT_BASE;
4819 case ETH_SS_STATS:
Ayaz Abdulla8ed14542009-03-05 08:01:49 +00004820 if (np->driver_data & DEV_HAS_STATISTICS_V3)
4821 return NV_DEV_STATISTICS_V3_COUNT;
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004822 else if (np->driver_data & DEV_HAS_STATISTICS_V2)
4823 return NV_DEV_STATISTICS_V2_COUNT;
Ayaz Abdulla8ed14542009-03-05 08:01:49 +00004824 else if (np->driver_data & DEV_HAS_STATISTICS_V1)
4825 return NV_DEV_STATISTICS_V1_COUNT;
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004826 else
4827 return 0;
4828 default:
4829 return -EOPNOTSUPP;
4830 }
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004831}
4832
david decotignyf5d827a2011-11-16 12:15:13 +00004833static void nv_get_ethtool_stats(struct net_device *dev,
4834 struct ethtool_stats *estats, u64 *buffer)
4835 __acquires(&netdev_priv(dev)->hwstats_lock)
4836 __releases(&netdev_priv(dev)->hwstats_lock)
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004837{
4838 struct fe_priv *np = netdev_priv(dev);
4839
david decotignyf5d827a2011-11-16 12:15:13 +00004840 spin_lock_bh(&np->hwstats_lock);
4841 nv_update_stats(dev);
4842 memcpy(buffer, &np->estats,
4843 nv_get_sset_count(dev, ETH_SS_STATS)*sizeof(u64));
4844 spin_unlock_bh(&np->hwstats_lock);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004845}
4846
4847static int nv_link_test(struct net_device *dev)
4848{
4849 struct fe_priv *np = netdev_priv(dev);
4850 int mii_status;
4851
4852 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
4853 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
4854
4855 /* check phy link status */
4856 if (!(mii_status & BMSR_LSTATUS))
4857 return 0;
4858 else
4859 return 1;
4860}
4861
4862static int nv_register_test(struct net_device *dev)
4863{
4864 u8 __iomem *base = get_hwbase(dev);
4865 int i = 0;
4866 u32 orig_read, new_read;
4867
4868 do {
4869 orig_read = readl(base + nv_registers_test[i].reg);
4870
4871 /* xor with mask to toggle bits */
4872 orig_read ^= nv_registers_test[i].mask;
4873
4874 writel(orig_read, base + nv_registers_test[i].reg);
4875
4876 new_read = readl(base + nv_registers_test[i].reg);
4877
4878 if ((new_read & nv_registers_test[i].mask) != (orig_read & nv_registers_test[i].mask))
4879 return 0;
4880
4881 /* restore original value */
4882 orig_read ^= nv_registers_test[i].mask;
4883 writel(orig_read, base + nv_registers_test[i].reg);
4884
4885 } while (nv_registers_test[++i].reg != 0);
4886
4887 return 1;
4888}
4889
4890static int nv_interrupt_test(struct net_device *dev)
4891{
4892 struct fe_priv *np = netdev_priv(dev);
4893 u8 __iomem *base = get_hwbase(dev);
4894 int ret = 1;
4895 int testcnt;
4896 u32 save_msi_flags, save_poll_interval = 0;
4897
4898 if (netif_running(dev)) {
4899 /* free current irq */
4900 nv_free_irq(dev);
4901 save_poll_interval = readl(base+NvRegPollingInterval);
4902 }
4903
4904 /* flag to test interrupt handler */
4905 np->intr_test = 0;
4906
4907 /* setup test irq */
4908 save_msi_flags = np->msi_flags;
4909 np->msi_flags &= ~NV_MSI_X_VECTORS_MASK;
4910 np->msi_flags |= 0x001; /* setup 1 vector */
4911 if (nv_request_irq(dev, 1))
4912 return 0;
4913
4914 /* setup timer interrupt */
4915 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
4916 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
4917
4918 nv_enable_hw_interrupts(dev, NVREG_IRQ_TIMER);
4919
4920 /* wait for at least one interrupt */
4921 msleep(100);
4922
4923 spin_lock_irq(&np->lock);
4924
4925 /* flag should be set within ISR */
4926 testcnt = np->intr_test;
4927 if (!testcnt)
4928 ret = 2;
4929
4930 nv_disable_hw_interrupts(dev, NVREG_IRQ_TIMER);
4931 if (!(np->msi_flags & NV_MSI_X_ENABLED))
4932 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4933 else
4934 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
4935
4936 spin_unlock_irq(&np->lock);
4937
4938 nv_free_irq(dev);
4939
4940 np->msi_flags = save_msi_flags;
4941
4942 if (netif_running(dev)) {
4943 writel(save_poll_interval, base + NvRegPollingInterval);
4944 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
4945 /* restore original irq */
4946 if (nv_request_irq(dev, 0))
4947 return 0;
4948 }
4949
4950 return ret;
4951}
4952
4953static int nv_loopback_test(struct net_device *dev)
4954{
4955 struct fe_priv *np = netdev_priv(dev);
4956 u8 __iomem *base = get_hwbase(dev);
4957 struct sk_buff *tx_skb, *rx_skb;
4958 dma_addr_t test_dma_addr;
4959 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004960 u32 flags;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004961 int len, i, pkt_len;
4962 u8 *pkt_data;
4963 u32 filter_flags = 0;
4964 u32 misc1_flags = 0;
4965 int ret = 1;
4966
4967 if (netif_running(dev)) {
4968 nv_disable_irq(dev);
4969 filter_flags = readl(base + NvRegPacketFilterFlags);
4970 misc1_flags = readl(base + NvRegMisc1);
4971 } else {
4972 nv_txrx_reset(dev);
4973 }
4974
4975 /* reinit driver view of the rx queue */
4976 set_bufsize(dev);
4977 nv_init_ring(dev);
4978
4979 /* setup hardware for loopback */
4980 writel(NVREG_MISC1_FORCE, base + NvRegMisc1);
4981 writel(NVREG_PFF_ALWAYS | NVREG_PFF_LOOPBACK, base + NvRegPacketFilterFlags);
4982
4983 /* reinit nic view of the rx queue */
4984 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4985 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00004986 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004987 base + NvRegRingSizes);
4988 pci_push(base);
4989
4990 /* restart rx engine */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004991 nv_start_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004992
4993 /* setup packet for tx */
4994 pkt_len = ETH_DATA_LEN;
4995 tx_skb = dev_alloc_skb(pkt_len);
Jesper Juhl46798c82006-09-25 16:39:24 -07004996 if (!tx_skb) {
Joe Perches1d397f32010-11-29 07:41:57 +00004997 netdev_err(dev, "dev_alloc_skb() failed during loopback test\n");
Jesper Juhl46798c82006-09-25 16:39:24 -07004998 ret = 0;
4999 goto out;
5000 }
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03005001 test_dma_addr = pci_map_single(np->pci_dev, tx_skb->data,
5002 skb_tailroom(tx_skb),
5003 PCI_DMA_FROMDEVICE);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005004 pkt_data = skb_put(tx_skb, pkt_len);
5005 for (i = 0; i < pkt_len; i++)
5006 pkt_data[i] = (u8)(i & 0xff);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005007
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005008 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07005009 np->tx_ring.orig[0].buf = cpu_to_le32(test_dma_addr);
5010 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 -04005011 } else {
Al Viro5bb7ea22007-12-09 16:06:41 +00005012 np->tx_ring.ex[0].bufhigh = cpu_to_le32(dma_high(test_dma_addr));
5013 np->tx_ring.ex[0].buflow = cpu_to_le32(dma_low(test_dma_addr));
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07005014 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 -04005015 }
5016 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
5017 pci_push(get_hwbase(dev));
5018
5019 msleep(500);
5020
5021 /* check for rx of the packet */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005022 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07005023 flags = le32_to_cpu(np->rx_ring.orig[0].flaglen);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005024 len = nv_descr_getlength(&np->rx_ring.orig[0], np->desc_ver);
5025
5026 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07005027 flags = le32_to_cpu(np->rx_ring.ex[0].flaglen);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005028 len = nv_descr_getlength_ex(&np->rx_ring.ex[0], np->desc_ver);
5029 }
5030
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07005031 if (flags & NV_RX_AVAIL) {
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005032 ret = 0;
5033 } else if (np->desc_ver == DESC_VER_1) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07005034 if (flags & NV_RX_ERROR)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005035 ret = 0;
5036 } else {
Szymon Janc78aea4f2010-11-27 08:39:43 +00005037 if (flags & NV_RX2_ERROR)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005038 ret = 0;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005039 }
5040
5041 if (ret) {
5042 if (len != pkt_len) {
5043 ret = 0;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005044 } else {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05005045 rx_skb = np->rx_skb[0].skb;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005046 for (i = 0; i < pkt_len; i++) {
5047 if (rx_skb->data[i] != (u8)(i & 0xff)) {
5048 ret = 0;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005049 break;
5050 }
5051 }
5052 }
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005053 }
5054
Eric Dumazet73a37072009-06-17 21:17:59 +00005055 pci_unmap_single(np->pci_dev, test_dma_addr,
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07005056 (skb_end_pointer(tx_skb) - tx_skb->data),
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005057 PCI_DMA_TODEVICE);
5058 dev_kfree_skb_any(tx_skb);
Jesper Juhl46798c82006-09-25 16:39:24 -07005059 out:
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005060 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005061 nv_stop_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005062 nv_txrx_reset(dev);
5063 /* drain rx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005064 nv_drain_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005065
5066 if (netif_running(dev)) {
5067 writel(misc1_flags, base + NvRegMisc1);
5068 writel(filter_flags, base + NvRegPacketFilterFlags);
5069 nv_enable_irq(dev);
5070 }
5071
5072 return ret;
5073}
5074
5075static void nv_self_test(struct net_device *dev, struct ethtool_test *test, u64 *buffer)
5076{
5077 struct fe_priv *np = netdev_priv(dev);
5078 u8 __iomem *base = get_hwbase(dev);
5079 int result;
Jeff Garzikb9f2c042007-10-03 18:07:32 -07005080 memset(buffer, 0, nv_get_sset_count(dev, ETH_SS_TEST)*sizeof(u64));
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005081
5082 if (!nv_link_test(dev)) {
5083 test->flags |= ETH_TEST_FL_FAILED;
5084 buffer[0] = 1;
5085 }
5086
5087 if (test->flags & ETH_TEST_FL_OFFLINE) {
5088 if (netif_running(dev)) {
5089 netif_stop_queue(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00005090 nv_napi_disable(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10005091 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07005092 netif_addr_lock(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005093 spin_lock_irq(&np->lock);
5094 nv_disable_hw_interrupts(dev, np->irqmask);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005095 if (!(np->msi_flags & NV_MSI_X_ENABLED))
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005096 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005097 else
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005098 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005099 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005100 nv_stop_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005101 nv_txrx_reset(dev);
5102 /* drain rx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005103 nv_drain_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005104 spin_unlock_irq(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07005105 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10005106 netif_tx_unlock_bh(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005107 }
5108
5109 if (!nv_register_test(dev)) {
5110 test->flags |= ETH_TEST_FL_FAILED;
5111 buffer[1] = 1;
5112 }
5113
5114 result = nv_interrupt_test(dev);
5115 if (result != 1) {
5116 test->flags |= ETH_TEST_FL_FAILED;
5117 buffer[2] = 1;
5118 }
5119 if (result == 0) {
5120 /* bail out */
5121 return;
5122 }
5123
5124 if (!nv_loopback_test(dev)) {
5125 test->flags |= ETH_TEST_FL_FAILED;
5126 buffer[3] = 1;
5127 }
5128
5129 if (netif_running(dev)) {
5130 /* reinit driver view of the rx queue */
5131 set_bufsize(dev);
5132 if (nv_init_ring(dev)) {
5133 if (!np->in_shutdown)
5134 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
5135 }
5136 /* reinit nic view of the rx queue */
5137 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
5138 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005139 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005140 base + NvRegRingSizes);
5141 pci_push(base);
5142 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
5143 pci_push(base);
5144 /* restart rx engine */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005145 nv_start_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005146 netif_start_queue(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00005147 nv_napi_enable(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005148 nv_enable_hw_interrupts(dev, np->irqmask);
5149 }
5150 }
5151}
5152
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005153static void nv_get_strings(struct net_device *dev, u32 stringset, u8 *buffer)
5154{
5155 switch (stringset) {
5156 case ETH_SS_STATS:
Jeff Garzikb9f2c042007-10-03 18:07:32 -07005157 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 -04005158 break;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005159 case ETH_SS_TEST:
Jeff Garzikb9f2c042007-10-03 18:07:32 -07005160 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 -04005161 break;
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005162 }
5163}
5164
Jeff Garzik7282d492006-09-13 14:30:00 -04005165static const struct ethtool_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005166 .get_drvinfo = nv_get_drvinfo,
5167 .get_link = ethtool_op_get_link,
5168 .get_wol = nv_get_wol,
5169 .set_wol = nv_set_wol,
5170 .get_settings = nv_get_settings,
5171 .set_settings = nv_set_settings,
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005172 .get_regs_len = nv_get_regs_len,
5173 .get_regs = nv_get_regs,
5174 .nway_reset = nv_nway_reset,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005175 .get_ringparam = nv_get_ringparam,
5176 .set_ringparam = nv_set_ringparam,
Ayaz Abdullab6d07732006-06-10 22:47:42 -04005177 .get_pauseparam = nv_get_pauseparam,
5178 .set_pauseparam = nv_set_pauseparam,
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005179 .get_strings = nv_get_strings,
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005180 .get_ethtool_stats = nv_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07005181 .get_sset_count = nv_get_sset_count,
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005182 .self_test = nv_self_test,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005183};
5184
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005185/* The mgmt unit and driver use a semaphore to access the phy during init */
5186static int nv_mgmt_acquire_sema(struct net_device *dev)
5187{
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005188 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005189 u8 __iomem *base = get_hwbase(dev);
5190 int i;
5191 u32 tx_ctrl, mgmt_sema;
5192
5193 for (i = 0; i < 10; i++) {
5194 mgmt_sema = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_SEMA_MASK;
5195 if (mgmt_sema == NVREG_XMITCTL_MGMT_SEMA_FREE)
5196 break;
5197 msleep(500);
5198 }
5199
5200 if (mgmt_sema != NVREG_XMITCTL_MGMT_SEMA_FREE)
5201 return 0;
5202
5203 for (i = 0; i < 2; i++) {
5204 tx_ctrl = readl(base + NvRegTransmitterControl);
5205 tx_ctrl |= NVREG_XMITCTL_HOST_SEMA_ACQ;
5206 writel(tx_ctrl, base + NvRegTransmitterControl);
5207
5208 /* verify that semaphore was acquired */
5209 tx_ctrl = readl(base + NvRegTransmitterControl);
5210 if (((tx_ctrl & NVREG_XMITCTL_HOST_SEMA_MASK) == NVREG_XMITCTL_HOST_SEMA_ACQ) &&
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005211 ((tx_ctrl & NVREG_XMITCTL_MGMT_SEMA_MASK) == NVREG_XMITCTL_MGMT_SEMA_FREE)) {
5212 np->mgmt_sema = 1;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005213 return 1;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005214 } else
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005215 udelay(50);
5216 }
5217
5218 return 0;
5219}
5220
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005221static void nv_mgmt_release_sema(struct net_device *dev)
5222{
5223 struct fe_priv *np = netdev_priv(dev);
5224 u8 __iomem *base = get_hwbase(dev);
5225 u32 tx_ctrl;
5226
5227 if (np->driver_data & DEV_HAS_MGMT_UNIT) {
5228 if (np->mgmt_sema) {
5229 tx_ctrl = readl(base + NvRegTransmitterControl);
5230 tx_ctrl &= ~NVREG_XMITCTL_HOST_SEMA_ACQ;
5231 writel(tx_ctrl, base + NvRegTransmitterControl);
5232 }
5233 }
5234}
5235
5236
5237static int nv_mgmt_get_version(struct net_device *dev)
5238{
5239 struct fe_priv *np = netdev_priv(dev);
5240 u8 __iomem *base = get_hwbase(dev);
5241 u32 data_ready = readl(base + NvRegTransmitterControl);
5242 u32 data_ready2 = 0;
5243 unsigned long start;
5244 int ready = 0;
5245
5246 writel(NVREG_MGMTUNITGETVERSION, base + NvRegMgmtUnitGetVersion);
5247 writel(data_ready ^ NVREG_XMITCTL_DATA_START, base + NvRegTransmitterControl);
5248 start = jiffies;
5249 while (time_before(jiffies, start + 5*HZ)) {
5250 data_ready2 = readl(base + NvRegTransmitterControl);
5251 if ((data_ready & NVREG_XMITCTL_DATA_READY) != (data_ready2 & NVREG_XMITCTL_DATA_READY)) {
5252 ready = 1;
5253 break;
5254 }
5255 schedule_timeout_uninterruptible(1);
5256 }
5257
5258 if (!ready || (data_ready2 & NVREG_XMITCTL_DATA_ERROR))
5259 return 0;
5260
5261 np->mgmt_version = readl(base + NvRegMgmtUnitVersion) & NVREG_MGMTUNITVERSION;
5262
5263 return 1;
5264}
5265
Linus Torvalds1da177e2005-04-16 15:20:36 -07005266static int nv_open(struct net_device *dev)
5267{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005268 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005269 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005270 int ret = 1;
5271 int oom, i;
Ayaz Abdullaa4336862008-04-18 13:50:43 -07005272 u32 low;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005273
Ed Swierkcb52deb2008-12-01 12:24:43 +00005274 /* power up phy */
5275 mii_rw(dev, np->phyaddr, MII_BMCR,
5276 mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ) & ~BMCR_PDOWN);
5277
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00005278 nv_txrx_gate(dev, false);
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005279 /* erase previous misconfiguration */
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005280 if (np->driver_data & DEV_HAS_POWER_CNTRL)
5281 nv_mac_reset(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005282 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
5283 writel(0, base + NvRegMulticastAddrB);
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -05005284 writel(NVREG_MCASTMASKA_NONE, base + NvRegMulticastMaskA);
5285 writel(NVREG_MCASTMASKB_NONE, base + NvRegMulticastMaskB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005286 writel(0, base + NvRegPacketFilterFlags);
5287
5288 writel(0, base + NvRegTransmitterControl);
5289 writel(0, base + NvRegReceiverControl);
5290
5291 writel(0, base + NvRegAdapterControl);
5292
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04005293 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)
5294 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
5295
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005296 /* initialize descriptor rings */
Manfred Sprauld81c0982005-07-31 18:20:30 +02005297 set_bufsize(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005298 oom = nv_init_ring(dev);
5299
5300 writel(0, base + NvRegLinkSpeed);
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005301 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005302 nv_txrx_reset(dev);
5303 writel(0, base + NvRegUnknownSetupReg6);
5304
5305 np->in_shutdown = 0;
5306
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005307 /* give hw rings */
Ayaz Abdulla0832b252006-02-04 13:13:26 -05005308 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005309 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Linus Torvalds1da177e2005-04-16 15:20:36 -07005310 base + NvRegRingSizes);
5311
Linus Torvalds1da177e2005-04-16 15:20:36 -07005312 writel(np->linkspeed, base + NvRegLinkSpeed);
Ayaz Abdulla95d161c2006-07-06 16:46:25 -04005313 if (np->desc_ver == DESC_VER_1)
5314 writel(NVREG_TX_WM_DESC1_DEFAULT, base + NvRegTxWatermark);
5315 else
5316 writel(NVREG_TX_WM_DESC2_3_DEFAULT, base + NvRegTxWatermark);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005317 writel(np->txrxctl_bits, base + NvRegTxRxControl);
Ayaz Abdullaee407b02006-02-04 13:13:17 -05005318 writel(np->vlanctl_bits, base + NvRegVlanControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005319 pci_push(base);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005320 writel(NVREG_TXRXCTL_BIT1|np->txrxctl_bits, base + NvRegTxRxControl);
Joe Perches344d0dc2010-11-29 07:41:52 +00005321 if (reg_delay(dev, NvRegUnknownSetupReg5,
5322 NVREG_UNKSETUP5_BIT31, NVREG_UNKSETUP5_BIT31,
5323 NV_SETUP5_DELAY, NV_SETUP5_DELAYMAX))
Joe Perches1d397f32010-11-29 07:41:57 +00005324 netdev_info(dev,
5325 "%s: SetupReg5, Bit 31 remained off\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005326
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005327 writel(0, base + NvRegMIIMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005328 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005329 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005330
Linus Torvalds1da177e2005-04-16 15:20:36 -07005331 writel(NVREG_MISC1_FORCE | NVREG_MISC1_HD, base + NvRegMisc1);
5332 writel(readl(base + NvRegTransmitterStatus), base + NvRegTransmitterStatus);
5333 writel(NVREG_PFF_ALWAYS, base + NvRegPacketFilterFlags);
Manfred Sprauld81c0982005-07-31 18:20:30 +02005334 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005335
5336 writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus);
Ayaz Abdullaa4336862008-04-18 13:50:43 -07005337
5338 get_random_bytes(&low, sizeof(low));
5339 low &= NVREG_SLOTTIME_MASK;
5340 if (np->desc_ver == DESC_VER_1) {
5341 writel(low|NVREG_SLOTTIME_DEFAULT, base + NvRegSlotTime);
5342 } else {
5343 if (!(np->driver_data & DEV_HAS_GEAR_MODE)) {
5344 /* setup legacy backoff */
5345 writel(NVREG_SLOTTIME_LEGBF_ENABLED|NVREG_SLOTTIME_10_100_FULL|low, base + NvRegSlotTime);
5346 } else {
5347 writel(NVREG_SLOTTIME_10_100_FULL, base + NvRegSlotTime);
5348 nv_gear_backoff_reseed(dev);
5349 }
5350 }
Ayaz Abdulla9744e212006-07-06 16:45:58 -04005351 writel(NVREG_TX_DEFERRAL_DEFAULT, base + NvRegTxDeferral);
5352 writel(NVREG_RX_DEFERRAL_DEFAULT, base + NvRegRxDeferral);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005353 if (poll_interval == -1) {
5354 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT)
5355 writel(NVREG_POLL_DEFAULT_THROUGHPUT, base + NvRegPollingInterval);
5356 else
5357 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005358 } else
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005359 writel(poll_interval & 0xFFFF, base + NvRegPollingInterval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005360 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
5361 writel((np->phyaddr << NVREG_ADAPTCTL_PHYSHIFT)|NVREG_ADAPTCTL_PHYVALID|NVREG_ADAPTCTL_RUNNING,
5362 base + NvRegAdapterControl);
5363 writel(NVREG_MIISPEED_BIT8|NVREG_MIIDELAY, base + NvRegMIISpeed);
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005364 writel(NVREG_MII_LINKCHANGE, base + NvRegMIIMask);
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04005365 if (np->wolenabled)
5366 writel(NVREG_WAKEUPFLAGS_ENABLE , base + NvRegWakeUpFlags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005367
5368 i = readl(base + NvRegPowerState);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005369 if ((i & NVREG_POWERSTATE_POWEREDUP) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005370 writel(NVREG_POWERSTATE_POWEREDUP|i, base + NvRegPowerState);
5371
5372 pci_push(base);
5373 udelay(10);
5374 writel(readl(base + NvRegPowerState) | NVREG_POWERSTATE_VALID, base + NvRegPowerState);
5375
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005376 nv_disable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005377 pci_push(base);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005378 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005379 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
5380 pci_push(base);
5381
Szymon Janc78aea4f2010-11-27 08:39:43 +00005382 if (nv_request_irq(dev, 0))
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005383 goto out_drain;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005384
5385 /* ask for interrupts */
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005386 nv_enable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005387
5388 spin_lock_irq(&np->lock);
5389 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
5390 writel(0, base + NvRegMulticastAddrB);
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -05005391 writel(NVREG_MCASTMASKA_NONE, base + NvRegMulticastMaskA);
5392 writel(NVREG_MCASTMASKB_NONE, base + NvRegMulticastMaskB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005393 writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
5394 /* One manual link speed update: Interrupts are enabled, future link
5395 * speed changes cause interrupts and are handled by nv_link_irq().
5396 */
5397 {
5398 u32 miistat;
5399 miistat = readl(base + NvRegMIIStatus);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005400 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005401 }
Manfred Spraul1b1b3c92005-08-06 23:47:55 +02005402 /* set linkspeed to invalid value, thus force nv_update_linkspeed
5403 * to init hw */
5404 np->linkspeed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005405 ret = nv_update_linkspeed(dev);
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005406 nv_start_rxtx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005407 netif_start_queue(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00005408 nv_napi_enable(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07005409
Linus Torvalds1da177e2005-04-16 15:20:36 -07005410 if (ret) {
5411 netif_carrier_on(dev);
5412 } else {
Joe Perches1d397f32010-11-29 07:41:57 +00005413 netdev_info(dev, "no link during initialization\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005414 netif_carrier_off(dev);
5415 }
5416 if (oom)
5417 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005418
5419 /* start statistics timer */
Ayaz Abdulla9c662432008-08-06 12:11:42 -04005420 if (np->driver_data & (DEV_HAS_STATISTICS_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_STATISTICS_V3))
Daniel Drakebfebbb82008-03-18 11:07:18 +00005421 mod_timer(&np->stats_poll,
5422 round_jiffies(jiffies + STATS_INTERVAL));
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005423
Linus Torvalds1da177e2005-04-16 15:20:36 -07005424 spin_unlock_irq(&np->lock);
5425
Sanjay Hortikare19df762011-11-11 16:11:21 +00005426 /* If the loopback feature was set while the device was down, make sure
5427 * that it's set correctly now.
5428 */
5429 if (dev->features & NETIF_F_LOOPBACK)
5430 nv_set_loopback(dev, dev->features);
5431
Linus Torvalds1da177e2005-04-16 15:20:36 -07005432 return 0;
5433out_drain:
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005434 nv_drain_rxtx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005435 return ret;
5436}
5437
5438static int nv_close(struct net_device *dev)
5439{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005440 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005441 u8 __iomem *base;
5442
5443 spin_lock_irq(&np->lock);
5444 np->in_shutdown = 1;
5445 spin_unlock_irq(&np->lock);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00005446 nv_napi_disable(dev);
Manfred Spraula7475902007-10-17 21:52:33 +02005447 synchronize_irq(np->pci_dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005448
5449 del_timer_sync(&np->oom_kick);
5450 del_timer_sync(&np->nic_poll);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005451 del_timer_sync(&np->stats_poll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005452
5453 netif_stop_queue(dev);
5454 spin_lock_irq(&np->lock);
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005455 nv_stop_rxtx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005456 nv_txrx_reset(dev);
5457
5458 /* disable interrupts on the nic or we will lock up */
5459 base = get_hwbase(dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005460 nv_disable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005461 pci_push(base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005462
5463 spin_unlock_irq(&np->lock);
5464
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005465 nv_free_irq(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005466
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005467 nv_drain_rxtx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005468
Ed Swierk5a9a8e32009-06-02 00:19:52 -07005469 if (np->wolenabled || !phy_power_down) {
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00005470 nv_txrx_gate(dev, false);
Tim Mann2cc49a52007-06-14 13:16:38 -07005471 writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005472 nv_start_rx(dev);
Ed Swierkcb52deb2008-12-01 12:24:43 +00005473 } else {
5474 /* power down phy */
5475 mii_rw(dev, np->phyaddr, MII_BMCR,
5476 mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ)|BMCR_PDOWN);
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00005477 nv_txrx_gate(dev, true);
Tim Mann2cc49a52007-06-14 13:16:38 -07005478 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005479
5480 /* FIXME: power down nic */
5481
5482 return 0;
5483}
5484
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005485static const struct net_device_ops nv_netdev_ops = {
5486 .ndo_open = nv_open,
5487 .ndo_stop = nv_close,
david decotignyf5d827a2011-11-16 12:15:13 +00005488 .ndo_get_stats64 = nv_get_stats64,
Stephen Hemminger00829822008-11-20 20:14:53 -08005489 .ndo_start_xmit = nv_start_xmit,
5490 .ndo_tx_timeout = nv_tx_timeout,
5491 .ndo_change_mtu = nv_change_mtu,
Michał Mirosław569e1462011-04-15 04:50:49 +00005492 .ndo_fix_features = nv_fix_features,
5493 .ndo_set_features = nv_set_features,
Stephen Hemminger00829822008-11-20 20:14:53 -08005494 .ndo_validate_addr = eth_validate_addr,
5495 .ndo_set_mac_address = nv_set_mac_address,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00005496 .ndo_set_rx_mode = nv_set_multicast,
Stephen Hemminger00829822008-11-20 20:14:53 -08005497#ifdef CONFIG_NET_POLL_CONTROLLER
5498 .ndo_poll_controller = nv_poll_controller,
5499#endif
5500};
5501
5502static const struct net_device_ops nv_netdev_ops_optimized = {
5503 .ndo_open = nv_open,
5504 .ndo_stop = nv_close,
david decotignyf5d827a2011-11-16 12:15:13 +00005505 .ndo_get_stats64 = nv_get_stats64,
Stephen Hemminger00829822008-11-20 20:14:53 -08005506 .ndo_start_xmit = nv_start_xmit_optimized,
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005507 .ndo_tx_timeout = nv_tx_timeout,
5508 .ndo_change_mtu = nv_change_mtu,
Michał Mirosław569e1462011-04-15 04:50:49 +00005509 .ndo_fix_features = nv_fix_features,
5510 .ndo_set_features = nv_set_features,
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005511 .ndo_validate_addr = eth_validate_addr,
5512 .ndo_set_mac_address = nv_set_mac_address,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00005513 .ndo_set_rx_mode = nv_set_multicast,
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005514#ifdef CONFIG_NET_POLL_CONTROLLER
5515 .ndo_poll_controller = nv_poll_controller,
5516#endif
5517};
5518
Linus Torvalds1da177e2005-04-16 15:20:36 -07005519static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
5520{
5521 struct net_device *dev;
5522 struct fe_priv *np;
5523 unsigned long addr;
5524 u8 __iomem *base;
5525 int err, i;
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005526 u32 powerstate, txreg;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005527 u32 phystate_orig = 0, phystate;
5528 int phyinitialized = 0;
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005529 static int printed_version;
5530
5531 if (!printed_version++)
Joe Perches294a5542010-11-29 07:41:56 +00005532 pr_info("Reverse Engineered nForce ethernet driver. Version %s.\n",
5533 FORCEDETH_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005534
5535 dev = alloc_etherdev(sizeof(struct fe_priv));
5536 err = -ENOMEM;
5537 if (!dev)
5538 goto out;
5539
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005540 np = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07005541 np->dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005542 np->pci_dev = pci_dev;
5543 spin_lock_init(&np->lock);
david decotignyf5d827a2011-11-16 12:15:13 +00005544 spin_lock_init(&np->hwstats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005545 SET_NETDEV_DEV(dev, &pci_dev->dev);
5546
5547 init_timer(&np->oom_kick);
5548 np->oom_kick.data = (unsigned long) dev;
Joe Perchesc061b182010-08-23 18:20:03 +00005549 np->oom_kick.function = nv_do_rx_refill; /* timer handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005550 init_timer(&np->nic_poll);
5551 np->nic_poll.data = (unsigned long) dev;
Joe Perchesc061b182010-08-23 18:20:03 +00005552 np->nic_poll.function = nv_do_nic_poll; /* timer handler */
david decotigny8f5f6982011-11-16 12:15:15 +00005553 init_timer_deferrable(&np->stats_poll);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005554 np->stats_poll.data = (unsigned long) dev;
Joe Perchesc061b182010-08-23 18:20:03 +00005555 np->stats_poll.function = nv_do_stats_poll; /* timer handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005556
5557 err = pci_enable_device(pci_dev);
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005558 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005559 goto out_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005560
5561 pci_set_master(pci_dev);
5562
5563 err = pci_request_regions(pci_dev, DRV_NAME);
5564 if (err < 0)
5565 goto out_disable;
5566
Ayaz Abdulla9c662432008-08-06 12:11:42 -04005567 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 -05005568 np->register_size = NV_PCI_REGSZ_VER3;
5569 else if (id->driver_data & DEV_HAS_STATISTICS_V1)
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005570 np->register_size = NV_PCI_REGSZ_VER2;
5571 else
5572 np->register_size = NV_PCI_REGSZ_VER1;
5573
Linus Torvalds1da177e2005-04-16 15:20:36 -07005574 err = -EINVAL;
5575 addr = 0;
5576 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005577 if (pci_resource_flags(pci_dev, i) & IORESOURCE_MEM &&
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005578 pci_resource_len(pci_dev, i) >= np->register_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005579 addr = pci_resource_start(pci_dev, i);
5580 break;
5581 }
5582 }
5583 if (i == DEVICE_COUNT_RESOURCE) {
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005584 dev_info(&pci_dev->dev, "Couldn't find register window\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005585 goto out_relreg;
5586 }
5587
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005588 /* copy of driver data */
5589 np->driver_data = id->driver_data;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04005590 /* copy of device id */
5591 np->device_id = id->device;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005592
Linus Torvalds1da177e2005-04-16 15:20:36 -07005593 /* handle different descriptor versions */
Manfred Spraulee733622005-07-31 18:32:26 +02005594 if (id->driver_data & DEV_HAS_HIGH_DMA) {
5595 /* packet format 3: supports 40-bit addressing */
5596 np->desc_ver = DESC_VER_3;
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005597 np->txrxctl_bits = NVREG_TXRXCTL_DESC_3;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005598 if (dma_64bit) {
Yang Hongyang6afd1422009-04-06 19:01:15 -07005599 if (pci_set_dma_mask(pci_dev, DMA_BIT_MASK(39)))
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005600 dev_info(&pci_dev->dev,
5601 "64-bit DMA failed, using 32-bit addressing\n");
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005602 else
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005603 dev->features |= NETIF_F_HIGHDMA;
Yang Hongyang6afd1422009-04-06 19:01:15 -07005604 if (pci_set_consistent_dma_mask(pci_dev, DMA_BIT_MASK(39))) {
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005605 dev_info(&pci_dev->dev,
5606 "64-bit DMA (consistent) failed, using 32-bit ring buffers\n");
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005607 }
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005608 }
Manfred Spraulee733622005-07-31 18:32:26 +02005609 } else if (id->driver_data & DEV_HAS_LARGEDESC) {
5610 /* packet format 2: supports jumbo frames */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005611 np->desc_ver = DESC_VER_2;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005612 np->txrxctl_bits = NVREG_TXRXCTL_DESC_2;
Manfred Spraulee733622005-07-31 18:32:26 +02005613 } else {
5614 /* original packet format */
5615 np->desc_ver = DESC_VER_1;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005616 np->txrxctl_bits = NVREG_TXRXCTL_DESC_1;
Manfred Sprauld81c0982005-07-31 18:20:30 +02005617 }
Manfred Spraulee733622005-07-31 18:32:26 +02005618
5619 np->pkt_limit = NV_PKTLIMIT_1;
5620 if (id->driver_data & DEV_HAS_LARGEDESC)
5621 np->pkt_limit = NV_PKTLIMIT_2;
5622
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005623 if (id->driver_data & DEV_HAS_CHECKSUM) {
5624 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
Michał Mirosław569e1462011-04-15 04:50:49 +00005625 dev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_SG |
5626 NETIF_F_TSO | NETIF_F_RXCSUM;
Ayaz Abdulla21828162007-01-23 12:27:21 -05005627 }
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005628
Ayaz Abdullaee407b02006-02-04 13:13:17 -05005629 np->vlanctl_bits = 0;
5630 if (id->driver_data & DEV_HAS_VLAN) {
5631 np->vlanctl_bits = NVREG_VLANCONTROL_ENABLE;
Jiri Pirko0891b0e2011-07-26 10:19:28 +00005632 dev->hw_features |= NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX;
Ayaz Abdullaee407b02006-02-04 13:13:17 -05005633 }
5634
Jiri Pirko0891b0e2011-07-26 10:19:28 +00005635 dev->features |= dev->hw_features;
5636
Sanjay Hortikare19df762011-11-11 16:11:21 +00005637 /* Add loopback capability to the device. */
5638 dev->hw_features |= NETIF_F_LOOPBACK;
5639
Ayaz Abdullab6d07732006-06-10 22:47:42 -04005640 np->pause_flags = NV_PAUSEFRAME_RX_CAPABLE | NV_PAUSEFRAME_RX_REQ | NV_PAUSEFRAME_AUTONEG;
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05005641 if ((id->driver_data & DEV_HAS_PAUSEFRAME_TX_V1) ||
5642 (id->driver_data & DEV_HAS_PAUSEFRAME_TX_V2) ||
5643 (id->driver_data & DEV_HAS_PAUSEFRAME_TX_V3)) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04005644 np->pause_flags |= NV_PAUSEFRAME_TX_CAPABLE | NV_PAUSEFRAME_TX_REQ;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04005645 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04005646
Linus Torvalds1da177e2005-04-16 15:20:36 -07005647 err = -ENOMEM;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005648 np->base = ioremap(addr, np->register_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005649 if (!np->base)
5650 goto out_relreg;
5651 dev->base_addr = (unsigned long)np->base;
Manfred Spraulee733622005-07-31 18:32:26 +02005652
Linus Torvalds1da177e2005-04-16 15:20:36 -07005653 dev->irq = pci_dev->irq;
Manfred Spraulee733622005-07-31 18:32:26 +02005654
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005655 np->rx_ring_size = RX_RING_DEFAULT;
5656 np->tx_ring_size = TX_RING_DEFAULT;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005657
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005658 if (!nv_optimized(np)) {
Manfred Spraulee733622005-07-31 18:32:26 +02005659 np->rx_ring.orig = pci_alloc_consistent(pci_dev,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005660 sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
Manfred Spraulee733622005-07-31 18:32:26 +02005661 &np->ring_addr);
5662 if (!np->rx_ring.orig)
5663 goto out_unmap;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005664 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
Manfred Spraulee733622005-07-31 18:32:26 +02005665 } else {
5666 np->rx_ring.ex = pci_alloc_consistent(pci_dev,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005667 sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
Manfred Spraulee733622005-07-31 18:32:26 +02005668 &np->ring_addr);
5669 if (!np->rx_ring.ex)
5670 goto out_unmap;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005671 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
Manfred Spraulee733622005-07-31 18:32:26 +02005672 }
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07005673 np->rx_skb = kcalloc(np->rx_ring_size, sizeof(struct nv_skb_map), GFP_KERNEL);
5674 np->tx_skb = kcalloc(np->tx_ring_size, sizeof(struct nv_skb_map), GFP_KERNEL);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05005675 if (!np->rx_skb || !np->tx_skb)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005676 goto out_freering;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005677
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005678 if (!nv_optimized(np))
Stephen Hemminger00829822008-11-20 20:14:53 -08005679 dev->netdev_ops = &nv_netdev_ops;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05005680 else
Stephen Hemminger00829822008-11-20 20:14:53 -08005681 dev->netdev_ops = &nv_netdev_ops_optimized;
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005682
Stephen Hemmingerbea33482007-10-03 16:41:36 -07005683 netif_napi_add(dev, &np->napi, nv_napi_poll, RX_WORK_PER_LOOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005684 SET_ETHTOOL_OPS(dev, &ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005685 dev->watchdog_timeo = NV_WATCHDOG_TIMEO;
5686
5687 pci_set_drvdata(pci_dev, dev);
5688
5689 /* read the mac address */
5690 base = get_hwbase(dev);
5691 np->orig_mac[0] = readl(base + NvRegMacAddrA);
5692 np->orig_mac[1] = readl(base + NvRegMacAddrB);
5693
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005694 /* check the workaround bit for correct mac address order */
5695 txreg = readl(base + NvRegTransmitPoll);
Ayaz Abdullaa376e792008-04-10 21:30:35 -07005696 if (id->driver_data & DEV_HAS_CORRECT_MACADDR) {
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005697 /* mac address is already in correct order */
5698 dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff;
5699 dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff;
5700 dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff;
5701 dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff;
5702 dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff;
5703 dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff;
Ayaz Abdullaa376e792008-04-10 21:30:35 -07005704 } else if (txreg & NVREG_TRANSMITPOLL_MAC_ADDR_REV) {
5705 /* mac address is already in correct order */
5706 dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff;
5707 dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff;
5708 dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff;
5709 dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff;
5710 dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff;
5711 dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff;
5712 /*
5713 * Set orig mac address back to the reversed version.
5714 * This flag will be cleared during low power transition.
5715 * Therefore, we should always put back the reversed address.
5716 */
5717 np->orig_mac[0] = (dev->dev_addr[5] << 0) + (dev->dev_addr[4] << 8) +
5718 (dev->dev_addr[3] << 16) + (dev->dev_addr[2] << 24);
5719 np->orig_mac[1] = (dev->dev_addr[1] << 0) + (dev->dev_addr[0] << 8);
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005720 } else {
5721 /* need to reverse mac address to correct order */
5722 dev->dev_addr[0] = (np->orig_mac[1] >> 8) & 0xff;
5723 dev->dev_addr[1] = (np->orig_mac[1] >> 0) & 0xff;
5724 dev->dev_addr[2] = (np->orig_mac[0] >> 24) & 0xff;
5725 dev->dev_addr[3] = (np->orig_mac[0] >> 16) & 0xff;
5726 dev->dev_addr[4] = (np->orig_mac[0] >> 8) & 0xff;
5727 dev->dev_addr[5] = (np->orig_mac[0] >> 0) & 0xff;
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005728 writel(txreg|NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
Joe Perchesc20ec762010-11-29 07:42:02 +00005729 dev_dbg(&pci_dev->dev,
5730 "%s: set workaround bit for reversed mac addr\n",
5731 __func__);
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005732 }
John W. Linvillec704b852005-09-12 10:48:56 -04005733 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005734
John W. Linvillec704b852005-09-12 10:48:56 -04005735 if (!is_valid_ether_addr(dev->perm_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005736 /*
5737 * Bad mac address. At least one bios sets the mac address
5738 * to 01:23:45:67:89:ab
5739 */
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005740 dev_err(&pci_dev->dev,
Joe Perchesc20ec762010-11-29 07:42:02 +00005741 "Invalid MAC address detected: %pM - Please complain to your hardware vendor.\n",
Szymon Janc78aea4f2010-11-27 08:39:43 +00005742 dev->dev_addr);
Stanislav O. Bezzubtsev655a6592009-11-15 21:17:02 -08005743 random_ether_addr(dev->dev_addr);
Joe Perchesc20ec762010-11-29 07:42:02 +00005744 dev_err(&pci_dev->dev,
5745 "Using random MAC address: %pM\n", dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005746 }
5747
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005748 /* set mac address */
5749 nv_copy_mac_to_hw(dev);
5750
Linus Torvalds1da177e2005-04-16 15:20:36 -07005751 /* disable WOL */
5752 writel(0, base + NvRegWakeUpFlags);
5753 np->wolenabled = 0;
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00005754 device_set_wakeup_enable(&pci_dev->dev, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005755
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005756 if (id->driver_data & DEV_HAS_POWER_CNTRL) {
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005757
5758 /* take phy and nic out of low power mode */
5759 powerstate = readl(base + NvRegPowerState2);
5760 powerstate &= ~NVREG_POWERSTATE2_POWERUP_MASK;
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00005761 if ((id->driver_data & DEV_NEED_LOW_POWER_FIX) &&
Auke Kok44c10132007-06-08 15:46:36 -07005762 pci_dev->revision >= 0xA3)
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005763 powerstate |= NVREG_POWERSTATE2_POWERUP_REV_A3;
5764 writel(powerstate, base + NvRegPowerState2);
5765 }
5766
Szymon Janc78aea4f2010-11-27 08:39:43 +00005767 if (np->desc_ver == DESC_VER_1)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005768 np->tx_flags = NV_TX_VALID;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005769 else
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005770 np->tx_flags = NV_TX2_VALID;
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005771
5772 np->msi_flags = 0;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005773 if ((id->driver_data & DEV_HAS_MSI) && msi)
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005774 np->msi_flags |= NV_MSI_CAPABLE;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005775
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005776 if ((id->driver_data & DEV_HAS_MSI_X) && msix) {
5777 /* msix has had reported issues when modifying irqmask
5778 as in the case of napi, therefore, disable for now
5779 */
David S. Miller0a127612010-05-03 23:33:05 -07005780#if 0
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005781 np->msi_flags |= NV_MSI_X_CAPABLE;
5782#endif
5783 }
5784
5785 if (optimization_mode == NV_OPTIMIZATION_MODE_CPU) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005786 np->irqmask = NVREG_IRQMASK_CPU;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005787 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
5788 np->msi_flags |= 0x0001;
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005789 } else if (optimization_mode == NV_OPTIMIZATION_MODE_DYNAMIC &&
5790 !(id->driver_data & DEV_NEED_TIMERIRQ)) {
5791 /* start off in throughput mode */
5792 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
5793 /* remove support for msix mode */
5794 np->msi_flags &= ~NV_MSI_X_CAPABLE;
5795 } else {
5796 optimization_mode = NV_OPTIMIZATION_MODE_THROUGHPUT;
5797 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
5798 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
5799 np->msi_flags |= 0x0003;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005800 }
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005801
Linus Torvalds1da177e2005-04-16 15:20:36 -07005802 if (id->driver_data & DEV_NEED_TIMERIRQ)
5803 np->irqmask |= NVREG_IRQ_TIMER;
5804 if (id->driver_data & DEV_NEED_LINKTIMER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005805 np->need_linktimer = 1;
5806 np->link_timeout = jiffies + LINK_TIMEOUT;
5807 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005808 np->need_linktimer = 0;
5809 }
5810
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005811 /* Limit the number of tx's outstanding for hw bug */
5812 if (id->driver_data & DEV_NEED_TX_LIMIT) {
5813 np->tx_limit = 1;
Ayaz Abdulla5c659322010-04-13 18:49:51 -07005814 if (((id->driver_data & DEV_NEED_TX_LIMIT2) == DEV_NEED_TX_LIMIT2) &&
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005815 pci_dev->revision >= 0xA2)
5816 np->tx_limit = 0;
5817 }
5818
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005819 /* clear phy state and temporarily halt phy interrupts */
5820 writel(0, base + NvRegMIIMask);
5821 phystate = readl(base + NvRegAdapterControl);
5822 if (phystate & NVREG_ADAPTCTL_RUNNING) {
5823 phystate_orig = 1;
5824 phystate &= ~NVREG_ADAPTCTL_RUNNING;
5825 writel(phystate, base + NvRegAdapterControl);
5826 }
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005827 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005828
5829 if (id->driver_data & DEV_HAS_MGMT_UNIT) {
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005830 /* management unit running on the mac? */
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005831 if ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_ST) &&
5832 (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_PHY_INIT) &&
5833 nv_mgmt_acquire_sema(dev) &&
5834 nv_mgmt_get_version(dev)) {
5835 np->mac_in_use = 1;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005836 if (np->mgmt_version > 0)
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005837 np->mac_in_use = readl(base + NvRegMgmtUnitControl) & NVREG_MGMTUNITCONTROL_INUSE;
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005838 /* management unit setup the phy already? */
5839 if (np->mac_in_use &&
5840 ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK) ==
5841 NVREG_XMITCTL_SYNC_PHY_INIT)) {
5842 /* phy is inited by mgmt unit */
5843 phyinitialized = 1;
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005844 } else {
5845 /* we need to init the phy */
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005846 }
5847 }
5848 }
5849
Linus Torvalds1da177e2005-04-16 15:20:36 -07005850 /* find a suitable phy */
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005851 for (i = 1; i <= 32; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005852 int id1, id2;
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005853 int phyaddr = i & 0x1F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005854
5855 spin_lock_irq(&np->lock);
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005856 id1 = mii_rw(dev, phyaddr, MII_PHYSID1, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005857 spin_unlock_irq(&np->lock);
5858 if (id1 < 0 || id1 == 0xffff)
5859 continue;
5860 spin_lock_irq(&np->lock);
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005861 id2 = mii_rw(dev, phyaddr, MII_PHYSID2, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005862 spin_unlock_irq(&np->lock);
5863 if (id2 < 0 || id2 == 0xffff)
5864 continue;
5865
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04005866 np->phy_model = id2 & PHYID2_MODEL_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005867 id1 = (id1 & PHYID1_OUI_MASK) << PHYID1_OUI_SHFT;
5868 id2 = (id2 & PHYID2_OUI_MASK) >> PHYID2_OUI_SHFT;
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005869 np->phyaddr = phyaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005870 np->phy_oui = id1 | id2;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04005871
5872 /* Realtek hardcoded phy id1 to all zero's on certain phys */
5873 if (np->phy_oui == PHY_OUI_REALTEK2)
5874 np->phy_oui = PHY_OUI_REALTEK;
5875 /* Setup phy revision for Realtek */
5876 if (np->phy_oui == PHY_OUI_REALTEK && np->phy_model == PHY_MODEL_REALTEK_8211)
5877 np->phy_rev = mii_rw(dev, phyaddr, MII_RESV1, MII_READ) & PHY_REV_MASK;
5878
Linus Torvalds1da177e2005-04-16 15:20:36 -07005879 break;
5880 }
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005881 if (i == 33) {
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005882 dev_info(&pci_dev->dev, "open: Could not find a valid PHY\n");
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005883 goto out_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005884 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04005885
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005886 if (!phyinitialized) {
5887 /* reset it */
5888 phy_init(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05005889 } else {
5890 /* see if it is a gigabit phy */
5891 u32 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005892 if (mii_status & PHY_GIGABIT)
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05005893 np->gigabit = PHY_GIGABIT;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005894 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005895
5896 /* set default link speed settings */
5897 np->linkspeed = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
5898 np->duplex = 0;
5899 np->autoneg = 1;
5900
5901 err = register_netdev(dev);
5902 if (err) {
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005903 dev_info(&pci_dev->dev, "unable to register netdev: %d\n", err);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005904 goto out_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005905 }
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005906
David S. Miller823dcd22011-08-20 10:39:12 -07005907 if (id->driver_data & DEV_HAS_VLAN)
5908 nv_vlan_mode(dev, dev->features);
Jiri Pirko0891b0e2011-07-26 10:19:28 +00005909
Ivan Vecera0d672e92011-02-15 02:08:39 +00005910 netif_carrier_off(dev);
5911
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005912 dev_info(&pci_dev->dev, "ifname %s, PHY OUI 0x%x @ %d, addr %pM\n",
5913 dev->name, np->phy_oui, np->phyaddr, dev->dev_addr);
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005914
Sanjay Hortikare19df762011-11-11 16:11:21 +00005915 dev_info(&pci_dev->dev, "%s%s%s%s%s%s%s%s%s%s%sdesc-v%u\n",
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005916 dev->features & NETIF_F_HIGHDMA ? "highdma " : "",
5917 dev->features & (NETIF_F_IP_CSUM | NETIF_F_SG) ?
Szymon Janc78aea4f2010-11-27 08:39:43 +00005918 "csum " : "",
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005919 dev->features & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX) ?
Szymon Janc78aea4f2010-11-27 08:39:43 +00005920 "vlan " : "",
Sanjay Hortikare19df762011-11-11 16:11:21 +00005921 dev->features & (NETIF_F_LOOPBACK) ?
5922 "loopback " : "",
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005923 id->driver_data & DEV_HAS_POWER_CNTRL ? "pwrctl " : "",
5924 id->driver_data & DEV_HAS_MGMT_UNIT ? "mgmt " : "",
5925 id->driver_data & DEV_NEED_TIMERIRQ ? "timirq " : "",
5926 np->gigabit == PHY_GIGABIT ? "gbit " : "",
5927 np->need_linktimer ? "lnktim " : "",
5928 np->msi_flags & NV_MSI_CAPABLE ? "msi " : "",
5929 np->msi_flags & NV_MSI_X_CAPABLE ? "msi-x " : "",
5930 np->desc_ver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005931
5932 return 0;
5933
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005934out_error:
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005935 if (phystate_orig)
5936 writel(phystate|NVREG_ADAPTCTL_RUNNING, base + NvRegAdapterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005937 pci_set_drvdata(pci_dev, NULL);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005938out_freering:
5939 free_rings(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005940out_unmap:
5941 iounmap(get_hwbase(dev));
5942out_relreg:
5943 pci_release_regions(pci_dev);
5944out_disable:
5945 pci_disable_device(pci_dev);
5946out_free:
5947 free_netdev(dev);
5948out:
5949 return err;
5950}
5951
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04005952static void nv_restore_phy(struct net_device *dev)
5953{
5954 struct fe_priv *np = netdev_priv(dev);
5955 u16 phy_reserved, mii_control;
5956
5957 if (np->phy_oui == PHY_OUI_REALTEK &&
5958 np->phy_model == PHY_MODEL_REALTEK_8201 &&
5959 phy_cross == NV_CROSSOVER_DETECTION_DISABLED) {
5960 mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3);
5961 phy_reserved = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, MII_READ);
5962 phy_reserved &= ~PHY_REALTEK_INIT_MSK1;
5963 phy_reserved |= PHY_REALTEK_INIT8;
5964 mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, phy_reserved);
5965 mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1);
5966
5967 /* restart auto negotiation */
5968 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
5969 mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE);
5970 mii_rw(dev, np->phyaddr, MII_BMCR, mii_control);
5971 }
5972}
5973
Yinghai Luf55c21f2008-09-13 13:10:31 -07005974static void nv_restore_mac_addr(struct pci_dev *pci_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005975{
5976 struct net_device *dev = pci_get_drvdata(pci_dev);
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005977 struct fe_priv *np = netdev_priv(dev);
5978 u8 __iomem *base = get_hwbase(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005979
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005980 /* special op: write back the misordered MAC address - otherwise
5981 * the next nv_probe would see a wrong address.
5982 */
5983 writel(np->orig_mac[0], base + NvRegMacAddrA);
5984 writel(np->orig_mac[1], base + NvRegMacAddrB);
Björn Steinbrink2e3884b2008-01-07 23:22:53 -08005985 writel(readl(base + NvRegTransmitPoll) & ~NVREG_TRANSMITPOLL_MAC_ADDR_REV,
5986 base + NvRegTransmitPoll);
Yinghai Luf55c21f2008-09-13 13:10:31 -07005987}
5988
5989static void __devexit nv_remove(struct pci_dev *pci_dev)
5990{
5991 struct net_device *dev = pci_get_drvdata(pci_dev);
5992
5993 unregister_netdev(dev);
5994
5995 nv_restore_mac_addr(pci_dev);
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005996
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04005997 /* restore any phy related changes */
5998 nv_restore_phy(dev);
5999
Ayaz Abdullacac1c522009-02-07 00:23:57 -08006000 nv_mgmt_release_sema(dev);
6001
Linus Torvalds1da177e2005-04-16 15:20:36 -07006002 /* free all structures */
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04006003 free_rings(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006004 iounmap(get_hwbase(dev));
6005 pci_release_regions(pci_dev);
6006 pci_disable_device(pci_dev);
6007 free_netdev(dev);
6008 pci_set_drvdata(pci_dev, NULL);
6009}
6010
Michel Lespinasse94252762011-03-06 16:14:50 +00006011#ifdef CONFIG_PM_SLEEP
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006012static int nv_suspend(struct device *device)
Francois Romieua1893172006-10-10 14:33:27 -07006013{
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006014 struct pci_dev *pdev = to_pci_dev(device);
Francois Romieua1893172006-10-10 14:33:27 -07006015 struct net_device *dev = pci_get_drvdata(pdev);
6016 struct fe_priv *np = netdev_priv(dev);
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006017 u8 __iomem *base = get_hwbase(dev);
6018 int i;
Francois Romieua1893172006-10-10 14:33:27 -07006019
Tobias Diedrich25d90812008-05-18 15:04:29 +02006020 if (netif_running(dev)) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00006021 /* Gross. */
Tobias Diedrich25d90812008-05-18 15:04:29 +02006022 nv_close(dev);
6023 }
Francois Romieua1893172006-10-10 14:33:27 -07006024 netif_device_detach(dev);
6025
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006026 /* save non-pci configuration space */
Szymon Janc78aea4f2010-11-27 08:39:43 +00006027 for (i = 0; i <= np->register_size/sizeof(u32); i++)
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006028 np->saved_config_space[i] = readl(base + i*sizeof(u32));
6029
Francois Romieua1893172006-10-10 14:33:27 -07006030 return 0;
6031}
6032
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006033static int nv_resume(struct device *device)
Francois Romieua1893172006-10-10 14:33:27 -07006034{
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006035 struct pci_dev *pdev = to_pci_dev(device);
Francois Romieua1893172006-10-10 14:33:27 -07006036 struct net_device *dev = pci_get_drvdata(pdev);
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006037 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullaa376e792008-04-10 21:30:35 -07006038 u8 __iomem *base = get_hwbase(dev);
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006039 int i, rc = 0;
Francois Romieua1893172006-10-10 14:33:27 -07006040
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006041 /* restore non-pci configuration space */
Szymon Janc78aea4f2010-11-27 08:39:43 +00006042 for (i = 0; i <= np->register_size/sizeof(u32); i++)
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006043 writel(np->saved_config_space[i], base+i*sizeof(u32));
Ayaz Abdullaa376e792008-04-10 21:30:35 -07006044
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006045 if (np->driver_data & DEV_NEED_MSI_FIX)
6046 pci_write_config_dword(pdev, NV_MSI_PRIV_OFFSET, NV_MSI_PRIV_VALUE);
Ayaz Abdullab6e44052009-02-07 00:24:15 -08006047
Ed Swierk35a74332009-04-06 17:49:12 -07006048 /* restore phy state, including autoneg */
6049 phy_init(dev);
6050
Tobias Diedrich25d90812008-05-18 15:04:29 +02006051 netif_device_attach(dev);
6052 if (netif_running(dev)) {
6053 rc = nv_open(dev);
6054 nv_set_multicast(dev);
6055 }
Francois Romieua1893172006-10-10 14:33:27 -07006056 return rc;
6057}
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006058
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006059static SIMPLE_DEV_PM_OPS(nv_pm_ops, nv_suspend, nv_resume);
6060#define NV_PM_OPS (&nv_pm_ops)
6061
Michel Lespinasse94252762011-03-06 16:14:50 +00006062#else
6063#define NV_PM_OPS NULL
6064#endif /* CONFIG_PM_SLEEP */
6065
6066#ifdef CONFIG_PM
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006067static void nv_shutdown(struct pci_dev *pdev)
6068{
6069 struct net_device *dev = pci_get_drvdata(pdev);
6070 struct fe_priv *np = netdev_priv(dev);
6071
6072 if (netif_running(dev))
6073 nv_close(dev);
6074
Tobias Diedrich34edaa82009-02-16 00:13:20 -08006075 /*
6076 * Restore the MAC so a kernel started by kexec won't get confused.
6077 * If we really go for poweroff, we must not restore the MAC,
6078 * otherwise the MAC for WOL will be reversed at least on some boards.
6079 */
Szymon Janc78aea4f2010-11-27 08:39:43 +00006080 if (system_state != SYSTEM_POWER_OFF)
Tobias Diedrich34edaa82009-02-16 00:13:20 -08006081 nv_restore_mac_addr(pdev);
Yinghai Luf55c21f2008-09-13 13:10:31 -07006082
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006083 pci_disable_device(pdev);
Tobias Diedrich34edaa82009-02-16 00:13:20 -08006084 /*
6085 * Apparently it is not possible to reinitialise from D3 hot,
6086 * only put the device into D3 if we really go for poweroff.
6087 */
Rafael J. Wysocki3cb55992008-09-05 14:00:19 -07006088 if (system_state == SYSTEM_POWER_OFF) {
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006089 pci_wake_from_d3(pdev, np->wolenabled);
Rafael J. Wysocki3cb55992008-09-05 14:00:19 -07006090 pci_set_power_state(pdev, PCI_D3hot);
6091 }
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006092}
Francois Romieua1893172006-10-10 14:33:27 -07006093#else
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006094#define nv_shutdown NULL
Francois Romieua1893172006-10-10 14:33:27 -07006095#endif /* CONFIG_PM */
6096
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006097static DEFINE_PCI_DEVICE_TABLE(pci_tbl) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006098 { /* nForce Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006099 PCI_DEVICE(0x10DE, 0x01C3),
Manfred Spraulc2dba062005-07-31 18:29:47 +02006100 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006101 },
6102 { /* nForce2 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006103 PCI_DEVICE(0x10DE, 0x0066),
Manfred Spraulc2dba062005-07-31 18:29:47 +02006104 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006105 },
6106 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006107 PCI_DEVICE(0x10DE, 0x00D6),
Manfred Spraulc2dba062005-07-31 18:29:47 +02006108 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006109 },
6110 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006111 PCI_DEVICE(0x10DE, 0x0086),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04006112 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006113 },
6114 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006115 PCI_DEVICE(0x10DE, 0x008C),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04006116 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006117 },
6118 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006119 PCI_DEVICE(0x10DE, 0x00E6),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04006120 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006121 },
6122 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006123 PCI_DEVICE(0x10DE, 0x00DF),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04006124 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006125 },
6126 { /* CK804 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006127 PCI_DEVICE(0x10DE, 0x0056),
Yinghai Lu033e97b2009-02-06 01:30:56 -08006128 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006129 },
6130 { /* CK804 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006131 PCI_DEVICE(0x10DE, 0x0057),
Yinghai Lu033e97b2009-02-06 01:30:56 -08006132 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006133 },
6134 { /* MCP04 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006135 PCI_DEVICE(0x10DE, 0x0037),
Ayaz Abdulla9e184762009-03-05 08:02:18 +00006136 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006137 },
6138 { /* MCP04 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006139 PCI_DEVICE(0x10DE, 0x0038),
Ayaz Abdulla9e184762009-03-05 08:02:18 +00006140 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT,
Manfred Sprauldc8216c2005-07-31 18:26:05 +02006141 },
6142 { /* MCP51 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006143 PCI_DEVICE(0x10DE, 0x0268),
6144 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS_V1|DEV_NEED_LOW_POWER_FIX,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006145 },
Manfred Spraul9992d4a2005-06-05 17:36:11 +02006146 { /* MCP51 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006147 PCI_DEVICE(0x10DE, 0x0269),
6148 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS_V1|DEV_NEED_LOW_POWER_FIX,
Manfred Spraul9992d4a2005-06-05 17:36:11 +02006149 },
Manfred Spraulf49d16e2005-06-26 11:36:52 +02006150 { /* MCP55 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006151 PCI_DEVICE(0x10DE, 0x0372),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006152 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_VLAN|DEV_HAS_MSI|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_NEED_TX_LIMIT|DEV_NEED_MSI_FIX,
Manfred Spraulf49d16e2005-06-26 11:36:52 +02006153 },
6154 { /* MCP55 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006155 PCI_DEVICE(0x10DE, 0x0373),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006156 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_VLAN|DEV_HAS_MSI|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_NEED_TX_LIMIT|DEV_NEED_MSI_FIX,
Manfred Spraulf49d16e2005-06-26 11:36:52 +02006157 },
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04006158 { /* MCP61 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006159 PCI_DEVICE(0x10DE, 0x03E5),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006160 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_MSI_FIX,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04006161 },
6162 { /* MCP61 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006163 PCI_DEVICE(0x10DE, 0x03E6),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006164 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_MSI_FIX,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04006165 },
6166 { /* MCP61 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006167 PCI_DEVICE(0x10DE, 0x03EE),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006168 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_MSI_FIX,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04006169 },
6170 { /* MCP61 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006171 PCI_DEVICE(0x10DE, 0x03EF),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006172 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_MSI_FIX,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04006173 },
6174 { /* MCP65 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006175 PCI_DEVICE(0x10DE, 0x0450),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006176 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04006177 },
6178 { /* MCP65 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006179 PCI_DEVICE(0x10DE, 0x0451),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006180 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04006181 },
6182 { /* MCP65 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006183 PCI_DEVICE(0x10DE, 0x0452),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006184 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04006185 },
6186 { /* MCP65 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006187 PCI_DEVICE(0x10DE, 0x0453),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006188 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04006189 },
Ayaz Abdullaf4344842006-11-06 00:43:40 -08006190 { /* MCP67 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006191 PCI_DEVICE(0x10DE, 0x054C),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006192 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdullaf4344842006-11-06 00:43:40 -08006193 },
6194 { /* MCP67 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006195 PCI_DEVICE(0x10DE, 0x054D),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006196 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdullaf4344842006-11-06 00:43:40 -08006197 },
6198 { /* MCP67 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006199 PCI_DEVICE(0x10DE, 0x054E),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006200 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdullaf4344842006-11-06 00:43:40 -08006201 },
6202 { /* MCP67 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006203 PCI_DEVICE(0x10DE, 0x054F),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006204 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdullaf4344842006-11-06 00:43:40 -08006205 },
Ayaz Abdulla13986612007-07-22 20:43:26 -04006206 { /* MCP73 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006207 PCI_DEVICE(0x10DE, 0x07DC),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006208 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdulla13986612007-07-22 20:43:26 -04006209 },
6210 { /* MCP73 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006211 PCI_DEVICE(0x10DE, 0x07DD),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006212 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdulla13986612007-07-22 20:43:26 -04006213 },
6214 { /* MCP73 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006215 PCI_DEVICE(0x10DE, 0x07DE),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006216 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdulla13986612007-07-22 20:43:26 -04006217 },
6218 { /* MCP73 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006219 PCI_DEVICE(0x10DE, 0x07DF),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006220 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
Ayaz Abdulla13986612007-07-22 20:43:26 -04006221 },
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04006222 { /* MCP77 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006223 PCI_DEVICE(0x10DE, 0x0760),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006224 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04006225 },
6226 { /* MCP77 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006227 PCI_DEVICE(0x10DE, 0x0761),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006228 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04006229 },
6230 { /* MCP77 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006231 PCI_DEVICE(0x10DE, 0x0762),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006232 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04006233 },
6234 { /* MCP77 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006235 PCI_DEVICE(0x10DE, 0x0763),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006236 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04006237 },
Ayaz Abdulla490dde82007-11-23 20:54:01 -05006238 { /* MCP79 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006239 PCI_DEVICE(0x10DE, 0x0AB0),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006240 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
Ayaz Abdulla490dde82007-11-23 20:54:01 -05006241 },
6242 { /* MCP79 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006243 PCI_DEVICE(0x10DE, 0x0AB1),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006244 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
Ayaz Abdulla490dde82007-11-23 20:54:01 -05006245 },
6246 { /* MCP79 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006247 PCI_DEVICE(0x10DE, 0x0AB2),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006248 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
Ayaz Abdulla490dde82007-11-23 20:54:01 -05006249 },
6250 { /* MCP79 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006251 PCI_DEVICE(0x10DE, 0x0AB3),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006252 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX,
Ayaz Abdulla490dde82007-11-23 20:54:01 -05006253 },
Ayaz Abdulla3df81c42009-06-03 15:05:35 +00006254 { /* MCP89 Ethernet Controller */
6255 PCI_DEVICE(0x10DE, 0x0D7D),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006256 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX,
Ayaz Abdulla3df81c42009-06-03 15:05:35 +00006257 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006258 {0,},
6259};
6260
6261static struct pci_driver driver = {
Jeff Garzik3f88ce42007-10-16 04:09:09 -04006262 .name = DRV_NAME,
6263 .id_table = pci_tbl,
6264 .probe = nv_probe,
6265 .remove = __devexit_p(nv_remove),
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006266 .shutdown = nv_shutdown,
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006267 .driver.pm = NV_PM_OPS,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006268};
6269
Linus Torvalds1da177e2005-04-16 15:20:36 -07006270static int __init init_nic(void)
6271{
Jeff Garzik29917622006-08-19 17:48:59 -04006272 return pci_register_driver(&driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006273}
6274
6275static void __exit exit_nic(void)
6276{
6277 pci_unregister_driver(&driver);
6278}
6279
6280module_param(max_interrupt_work, int, 0);
6281MODULE_PARM_DESC(max_interrupt_work, "forcedeth maximum events handled per interrupt");
Ayaz Abdullaa971c322005-11-11 08:30:38 -05006282module_param(optimization_mode, int, 0);
Ayaz Abdulla9e184762009-03-05 08:02:18 +00006283MODULE_PARM_DESC(optimization_mode, "In throughput mode (0), every tx & rx packet will generate an interrupt. In CPU mode (1), interrupts are controlled by a timer. In dynamic mode (2), the mode toggles between throughput and CPU mode based on network load.");
Ayaz Abdullaa971c322005-11-11 08:30:38 -05006284module_param(poll_interval, int, 0);
6285MODULE_PARM_DESC(poll_interval, "Interval determines how frequent timer interrupt is generated by [(time_in_micro_secs * 100) / (2^10)]. Min is 0 and Max is 65535.");
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04006286module_param(msi, int, 0);
6287MODULE_PARM_DESC(msi, "MSI interrupts are enabled by setting to 1 and disabled by setting to 0.");
6288module_param(msix, int, 0);
6289MODULE_PARM_DESC(msix, "MSIX interrupts are enabled by setting to 1 and disabled by setting to 0.");
6290module_param(dma_64bit, int, 0);
6291MODULE_PARM_DESC(dma_64bit, "High DMA is enabled by setting to 1 and disabled by setting to 0.");
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04006292module_param(phy_cross, int, 0);
6293MODULE_PARM_DESC(phy_cross, "Phy crossover detection for Realtek 8201 phy is enabled by setting to 1 and disabled by setting to 0.");
Ed Swierk5a9a8e32009-06-02 00:19:52 -07006294module_param(phy_power_down, int, 0);
6295MODULE_PARM_DESC(phy_power_down, "Power down phy and disable link when interface is down (1), or leave phy powered up (0).");
Sameer Nanda1ec4f2d2011-11-16 12:15:12 +00006296module_param(debug_tx_timeout, bool, 0);
6297MODULE_PARM_DESC(debug_tx_timeout,
6298 "Dump tx related registers and ring when tx_timeout happens");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006299
6300MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>");
6301MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver");
6302MODULE_LICENSE("GPL");
6303
6304MODULE_DEVICE_TABLE(pci, pci_tbl);
6305
6306module_init(init_nic);
6307module_exit(exit_nic);