blob: b003fe53c8e2508e3de8f2c2a118060b57ac02ac [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * forcedeth: Ethernet driver for NVIDIA nForce media access controllers.
3 *
4 * Note: This driver is a cleanroom reimplementation based on reverse
5 * engineered documentation written by Carl-Daniel Hailfinger
Ayaz Abdulla87046e52006-12-19 23:33:32 -05006 * and Andrew de Quincey.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
8 * NVIDIA, nForce and other NVIDIA marks are trademarks or registered
9 * trademarks of NVIDIA Corporation in the United States and other
10 * countries.
11 *
Manfred Spraul18360982005-12-24 14:19:24 +010012 * Copyright (C) 2003,4,5 Manfred Spraul
Linus Torvalds1da177e2005-04-16 15:20:36 -070013 * Copyright (C) 2004 Andrew de Quincey (wol support)
14 * Copyright (C) 2004 Carl-Daniel Hailfinger (invalid MAC handling, insane
15 * IRQ rate fixes, bigendian fixes, cleanups, verification)
Ayaz Abdullaf1405d322009-01-09 11:03:54 +000016 * Copyright (c) 2004,2005,2006,2007,2008,2009 NVIDIA Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -070017 *
18 * This program is free software; you can redistribute it and/or modify
19 * it under the terms of the GNU General Public License as published by
20 * the Free Software Foundation; either version 2 of the License, or
21 * (at your option) any later version.
22 *
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
27 *
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070032 * Known bugs:
33 * We suspect that on some hardware no TX done interrupts are generated.
34 * This means recovery from netif_stop_queue only happens if the hw timer
35 * interrupt fires (100 times/second, configurable with NVREG_POLL_DEFAULT)
36 * and the timer is active in the IRQMask, or if a rx packet arrives by chance.
37 * If your hardware reliably generates tx done interrupts, then you can remove
38 * DEV_NEED_TIMERIRQ from the driver_data flags.
39 * DEV_NEED_TIMERIRQ will not harm you on sane hardware, only generating a few
40 * superfluous timer interrupts from the nic.
41 */
Joe Perches294a5542010-11-29 07:41:56 +000042
43#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
44
Ayaz Abdulla3e1a3ce2009-03-05 08:02:38 +000045#define FORCEDETH_VERSION "0.64"
Linus Torvalds1da177e2005-04-16 15:20:36 -070046#define DRV_NAME "forcedeth"
47
48#include <linux/module.h>
49#include <linux/types.h>
50#include <linux/pci.h>
51#include <linux/interrupt.h>
52#include <linux/netdevice.h>
53#include <linux/etherdevice.h>
54#include <linux/delay.h>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040055#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070056#include <linux/spinlock.h>
57#include <linux/ethtool.h>
58#include <linux/timer.h>
59#include <linux/skbuff.h>
60#include <linux/mii.h>
61#include <linux/random.h>
62#include <linux/init.h>
Manfred Spraul22c6d142005-04-19 21:17:09 +020063#include <linux/if_vlan.h>
Matthias Gehre910638a2006-03-28 01:56:48 -080064#include <linux/dma-mapping.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090065#include <linux/slab.h>
Szymon Janc5504e132010-11-27 08:39:45 +000066#include <linux/uaccess.h>
Paul Gortmaker70c71602011-05-22 16:47:17 -040067#include <linux/prefetch.h>
david decotignyf5d827a2011-11-16 12:15:13 +000068#include <linux/u64_stats_sync.h>
69#include <linux/io.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070070
71#include <asm/irq.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070072
Stephen Hemmingerbea33482007-10-03 16:41:36 -070073#define TX_WORK_PER_LOOP 64
74#define RX_WORK_PER_LOOP 64
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
76/*
77 * Hardware access:
78 */
79
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +000080#define DEV_NEED_TIMERIRQ 0x0000001 /* set the timer irq flag in the irq mask */
81#define DEV_NEED_LINKTIMER 0x0000002 /* poll link settings. Relies on the timer irq */
82#define DEV_HAS_LARGEDESC 0x0000004 /* device supports jumbo frames and needs packet format 2 */
83#define DEV_HAS_HIGH_DMA 0x0000008 /* device supports 64bit dma */
84#define DEV_HAS_CHECKSUM 0x0000010 /* device supports tx and rx checksum offloads */
85#define DEV_HAS_VLAN 0x0000020 /* device supports vlan tagging and striping */
86#define DEV_HAS_MSI 0x0000040 /* device supports MSI */
87#define DEV_HAS_MSI_X 0x0000080 /* device supports MSI-X */
88#define DEV_HAS_POWER_CNTRL 0x0000100 /* device supports power savings */
89#define DEV_HAS_STATISTICS_V1 0x0000200 /* device supports hw statistics version 1 */
Mike Ditto7b5e0782010-07-25 21:54:28 -070090#define DEV_HAS_STATISTICS_V2 0x0000400 /* device supports hw statistics version 2 */
91#define DEV_HAS_STATISTICS_V3 0x0000800 /* device supports hw statistics version 3 */
92#define DEV_HAS_STATISTICS_V12 0x0000600 /* device supports hw statistics version 1 and 2 */
93#define DEV_HAS_STATISTICS_V123 0x0000e00 /* device supports hw statistics version 1, 2, and 3 */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +000094#define DEV_HAS_TEST_EXTENDED 0x0001000 /* device supports extended diagnostic test */
95#define DEV_HAS_MGMT_UNIT 0x0002000 /* device supports management unit */
96#define DEV_HAS_CORRECT_MACADDR 0x0004000 /* device supports correct mac address order */
97#define DEV_HAS_COLLISION_FIX 0x0008000 /* device supports tx collision fix */
98#define DEV_HAS_PAUSEFRAME_TX_V1 0x0010000 /* device supports tx pause frames version 1 */
99#define DEV_HAS_PAUSEFRAME_TX_V2 0x0020000 /* device supports tx pause frames version 2 */
100#define DEV_HAS_PAUSEFRAME_TX_V3 0x0040000 /* device supports tx pause frames version 3 */
101#define DEV_NEED_TX_LIMIT 0x0080000 /* device needs to limit tx */
102#define DEV_NEED_TX_LIMIT2 0x0180000 /* device needs to limit tx, expect for some revs */
103#define DEV_HAS_GEAR_MODE 0x0200000 /* device supports gear mode */
104#define DEV_NEED_PHY_INIT_FIX 0x0400000 /* device needs specific phy workaround */
105#define DEV_NEED_LOW_POWER_FIX 0x0800000 /* device needs special power up workaround */
106#define DEV_NEED_MSI_FIX 0x1000000 /* device needs msi workaround */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108enum {
109 NvRegIrqStatus = 0x000,
110#define NVREG_IRQSTAT_MIIEVENT 0x040
Ayaz Abdulladaa91a92009-02-07 00:25:00 -0800111#define NVREG_IRQSTAT_MASK 0x83ff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 NvRegIrqMask = 0x004,
113#define NVREG_IRQ_RX_ERROR 0x0001
114#define NVREG_IRQ_RX 0x0002
115#define NVREG_IRQ_RX_NOBUF 0x0004
116#define NVREG_IRQ_TX_ERR 0x0008
Manfred Spraulc2dba062005-07-31 18:29:47 +0200117#define NVREG_IRQ_TX_OK 0x0010
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118#define NVREG_IRQ_TIMER 0x0020
119#define NVREG_IRQ_LINK 0x0040
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500120#define NVREG_IRQ_RX_FORCED 0x0080
121#define NVREG_IRQ_TX_FORCED 0x0100
Ayaz Abdulladaa91a92009-02-07 00:25:00 -0800122#define NVREG_IRQ_RECOVER_ERROR 0x8200
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500123#define NVREG_IRQMASK_THROUGHPUT 0x00df
Ayaz Abdulla096a4582007-05-21 20:23:11 -0400124#define NVREG_IRQMASK_CPU 0x0060
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500125#define NVREG_IRQ_TX_ALL (NVREG_IRQ_TX_ERR|NVREG_IRQ_TX_OK|NVREG_IRQ_TX_FORCED)
126#define NVREG_IRQ_RX_ALL (NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_RX_FORCED)
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500127#define NVREG_IRQ_OTHER (NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_RECOVER_ERROR)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200128
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129 NvRegUnknownSetupReg6 = 0x008,
130#define NVREG_UNKSETUP6_VAL 3
131
132/*
133 * NVREG_POLL_DEFAULT is the interval length of the timer source on the nic
134 * NVREG_POLL_DEFAULT=97 would result in an interval length of 1 ms
135 */
136 NvRegPollingInterval = 0x00c,
Ayaz Abdulla6cef67a2009-03-05 08:02:30 +0000137#define NVREG_POLL_DEFAULT_THROUGHPUT 65535 /* backup tx cleanup if loop max reached */
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500138#define NVREG_POLL_DEFAULT_CPU 13
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500139 NvRegMSIMap0 = 0x020,
140 NvRegMSIMap1 = 0x024,
141 NvRegMSIIrqMask = 0x030,
142#define NVREG_MSI_VECTOR_0_ENABLED 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 NvRegMisc1 = 0x080,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400144#define NVREG_MISC1_PAUSE_TX 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145#define NVREG_MISC1_HD 0x02
146#define NVREG_MISC1_FORCE 0x3b0f3c
147
Ayaz Abdulla0a626772008-01-13 16:02:42 -0500148 NvRegMacReset = 0x34,
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400149#define NVREG_MAC_RESET_ASSERT 0x0F3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 NvRegTransmitterControl = 0x084,
151#define NVREG_XMITCTL_START 0x01
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500152#define NVREG_XMITCTL_MGMT_ST 0x40000000
153#define NVREG_XMITCTL_SYNC_MASK 0x000f0000
154#define NVREG_XMITCTL_SYNC_NOT_READY 0x0
155#define NVREG_XMITCTL_SYNC_PHY_INIT 0x00040000
156#define NVREG_XMITCTL_MGMT_SEMA_MASK 0x00000f00
157#define NVREG_XMITCTL_MGMT_SEMA_FREE 0x0
158#define NVREG_XMITCTL_HOST_SEMA_MASK 0x0000f000
159#define NVREG_XMITCTL_HOST_SEMA_ACQ 0x0000f000
160#define NVREG_XMITCTL_HOST_LOADED 0x00004000
Ayaz Abdullaf35723e2003-02-20 03:03:54 -0500161#define NVREG_XMITCTL_TX_PATH_EN 0x01000000
Ayaz Abdullacac1c522009-02-07 00:23:57 -0800162#define NVREG_XMITCTL_DATA_START 0x00100000
163#define NVREG_XMITCTL_DATA_READY 0x00010000
164#define NVREG_XMITCTL_DATA_ERROR 0x00020000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 NvRegTransmitterStatus = 0x088,
166#define NVREG_XMITSTAT_BUSY 0x01
167
168 NvRegPacketFilterFlags = 0x8c,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400169#define NVREG_PFF_PAUSE_RX 0x08
170#define NVREG_PFF_ALWAYS 0x7F0000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171#define NVREG_PFF_PROMISC 0x80
172#define NVREG_PFF_MYADDR 0x20
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400173#define NVREG_PFF_LOOPBACK 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
175 NvRegOffloadConfig = 0x90,
176#define NVREG_OFFLOAD_HOMEPHY 0x601
177#define NVREG_OFFLOAD_NORMAL RX_NIC_BUFSIZE
178 NvRegReceiverControl = 0x094,
179#define NVREG_RCVCTL_START 0x01
Ayaz Abdullaf35723e2003-02-20 03:03:54 -0500180#define NVREG_RCVCTL_RX_PATH_EN 0x01000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 NvRegReceiverStatus = 0x98,
182#define NVREG_RCVSTAT_BUSY 0x01
183
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700184 NvRegSlotTime = 0x9c,
185#define NVREG_SLOTTIME_LEGBF_ENABLED 0x80000000
186#define NVREG_SLOTTIME_10_100_FULL 0x00007f00
Szymon Janc78aea4f2010-11-27 08:39:43 +0000187#define NVREG_SLOTTIME_1000_FULL 0x0003ff00
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700188#define NVREG_SLOTTIME_HALF 0x0000ff00
Szymon Janc78aea4f2010-11-27 08:39:43 +0000189#define NVREG_SLOTTIME_DEFAULT 0x00007f00
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700190#define NVREG_SLOTTIME_MASK 0x000000ff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191
Ayaz Abdulla9744e212006-07-06 16:45:58 -0400192 NvRegTxDeferral = 0xA0,
Ayaz Abdullafd9b5582008-02-05 12:29:49 -0500193#define NVREG_TX_DEFERRAL_DEFAULT 0x15050f
194#define NVREG_TX_DEFERRAL_RGMII_10_100 0x16070f
195#define NVREG_TX_DEFERRAL_RGMII_1000 0x14050f
196#define NVREG_TX_DEFERRAL_RGMII_STRETCH_10 0x16190f
197#define NVREG_TX_DEFERRAL_RGMII_STRETCH_100 0x16300f
198#define NVREG_TX_DEFERRAL_MII_STRETCH 0x152000
Ayaz Abdulla9744e212006-07-06 16:45:58 -0400199 NvRegRxDeferral = 0xA4,
200#define NVREG_RX_DEFERRAL_DEFAULT 0x16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 NvRegMacAddrA = 0xA8,
202 NvRegMacAddrB = 0xAC,
203 NvRegMulticastAddrA = 0xB0,
204#define NVREG_MCASTADDRA_FORCE 0x01
205 NvRegMulticastAddrB = 0xB4,
206 NvRegMulticastMaskA = 0xB8,
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -0500207#define NVREG_MCASTMASKA_NONE 0xffffffff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 NvRegMulticastMaskB = 0xBC,
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -0500209#define NVREG_MCASTMASKB_NONE 0xffff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
211 NvRegPhyInterface = 0xC0,
212#define PHY_RGMII 0x10000000
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700213 NvRegBackOffControl = 0xC4,
214#define NVREG_BKOFFCTRL_DEFAULT 0x70000000
215#define NVREG_BKOFFCTRL_SEED_MASK 0x000003ff
216#define NVREG_BKOFFCTRL_SELECT 24
217#define NVREG_BKOFFCTRL_GEAR 12
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218
219 NvRegTxRingPhysAddr = 0x100,
220 NvRegRxRingPhysAddr = 0x104,
221 NvRegRingSizes = 0x108,
222#define NVREG_RINGSZ_TXSHIFT 0
223#define NVREG_RINGSZ_RXSHIFT 16
Ayaz Abdulla5070d342006-07-31 12:05:01 -0400224 NvRegTransmitPoll = 0x10c,
225#define NVREG_TRANSMITPOLL_MAC_ADDR_REV 0x00008000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 NvRegLinkSpeed = 0x110,
227#define NVREG_LINKSPEED_FORCE 0x10000
228#define NVREG_LINKSPEED_10 1000
229#define NVREG_LINKSPEED_100 100
230#define NVREG_LINKSPEED_1000 50
231#define NVREG_LINKSPEED_MASK (0xFFF)
232 NvRegUnknownSetupReg5 = 0x130,
233#define NVREG_UNKSETUP5_BIT31 (1<<31)
Ayaz Abdulla95d161c2006-07-06 16:46:25 -0400234 NvRegTxWatermark = 0x13c,
235#define NVREG_TX_WM_DESC1_DEFAULT 0x0200010
236#define NVREG_TX_WM_DESC2_3_DEFAULT 0x1e08000
237#define NVREG_TX_WM_DESC2_3_1000 0xfe08000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 NvRegTxRxControl = 0x144,
239#define NVREG_TXRXCTL_KICK 0x0001
240#define NVREG_TXRXCTL_BIT1 0x0002
241#define NVREG_TXRXCTL_BIT2 0x0004
242#define NVREG_TXRXCTL_IDLE 0x0008
243#define NVREG_TXRXCTL_RESET 0x0010
244#define NVREG_TXRXCTL_RXCHECK 0x0400
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400245#define NVREG_TXRXCTL_DESC_1 0
Ayaz Abdullad2f78412007-01-09 13:30:02 -0500246#define NVREG_TXRXCTL_DESC_2 0x002100
247#define NVREG_TXRXCTL_DESC_3 0xc02200
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500248#define NVREG_TXRXCTL_VLANSTRIP 0x00040
249#define NVREG_TXRXCTL_VLANINS 0x00080
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500250 NvRegTxRingPhysAddrHigh = 0x148,
251 NvRegRxRingPhysAddrHigh = 0x14C,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400252 NvRegTxPauseFrame = 0x170,
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -0500253#define NVREG_TX_PAUSEFRAME_DISABLE 0x0fff0080
254#define NVREG_TX_PAUSEFRAME_ENABLE_V1 0x01800010
255#define NVREG_TX_PAUSEFRAME_ENABLE_V2 0x056003f0
256#define NVREG_TX_PAUSEFRAME_ENABLE_V3 0x09f00880
Ayaz Abdulla9a33e882008-08-06 12:12:34 -0400257 NvRegTxPauseFrameLimit = 0x174,
258#define NVREG_TX_PAUSEFRAMELIMIT_ENABLE 0x00010000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259 NvRegMIIStatus = 0x180,
260#define NVREG_MIISTAT_ERROR 0x0001
261#define NVREG_MIISTAT_LINKCHANGE 0x0008
Ayaz Abdullaeb798422008-02-04 15:14:04 -0500262#define NVREG_MIISTAT_MASK_RW 0x0007
263#define NVREG_MIISTAT_MASK_ALL 0x000f
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500264 NvRegMIIMask = 0x184,
265#define NVREG_MII_LINKCHANGE 0x0008
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266
267 NvRegAdapterControl = 0x188,
268#define NVREG_ADAPTCTL_START 0x02
269#define NVREG_ADAPTCTL_LINKUP 0x04
270#define NVREG_ADAPTCTL_PHYVALID 0x40000
271#define NVREG_ADAPTCTL_RUNNING 0x100000
272#define NVREG_ADAPTCTL_PHYSHIFT 24
273 NvRegMIISpeed = 0x18c,
274#define NVREG_MIISPEED_BIT8 (1<<8)
275#define NVREG_MIIDELAY 5
276 NvRegMIIControl = 0x190,
277#define NVREG_MIICTL_INUSE 0x08000
278#define NVREG_MIICTL_WRITE 0x00400
279#define NVREG_MIICTL_ADDRSHIFT 5
280 NvRegMIIData = 0x194,
Ayaz Abdulla9c662432008-08-06 12:11:42 -0400281 NvRegTxUnicast = 0x1a0,
282 NvRegTxMulticast = 0x1a4,
283 NvRegTxBroadcast = 0x1a8,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284 NvRegWakeUpFlags = 0x200,
285#define NVREG_WAKEUPFLAGS_VAL 0x7770
286#define NVREG_WAKEUPFLAGS_BUSYSHIFT 24
287#define NVREG_WAKEUPFLAGS_ENABLESHIFT 16
288#define NVREG_WAKEUPFLAGS_D3SHIFT 12
289#define NVREG_WAKEUPFLAGS_D2SHIFT 8
290#define NVREG_WAKEUPFLAGS_D1SHIFT 4
291#define NVREG_WAKEUPFLAGS_D0SHIFT 0
292#define NVREG_WAKEUPFLAGS_ACCEPT_MAGPAT 0x01
293#define NVREG_WAKEUPFLAGS_ACCEPT_WAKEUPPAT 0x02
294#define NVREG_WAKEUPFLAGS_ACCEPT_LINKCHANGE 0x04
295#define NVREG_WAKEUPFLAGS_ENABLE 0x1111
296
Ayaz Abdullacac1c522009-02-07 00:23:57 -0800297 NvRegMgmtUnitGetVersion = 0x204,
Szymon Janc78aea4f2010-11-27 08:39:43 +0000298#define NVREG_MGMTUNITGETVERSION 0x01
Ayaz Abdullacac1c522009-02-07 00:23:57 -0800299 NvRegMgmtUnitVersion = 0x208,
300#define NVREG_MGMTUNITVERSION 0x08
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 NvRegPowerCap = 0x268,
302#define NVREG_POWERCAP_D3SUPP (1<<30)
303#define NVREG_POWERCAP_D2SUPP (1<<26)
304#define NVREG_POWERCAP_D1SUPP (1<<25)
305 NvRegPowerState = 0x26c,
306#define NVREG_POWERSTATE_POWEREDUP 0x8000
307#define NVREG_POWERSTATE_VALID 0x0100
308#define NVREG_POWERSTATE_MASK 0x0003
309#define NVREG_POWERSTATE_D0 0x0000
310#define NVREG_POWERSTATE_D1 0x0001
311#define NVREG_POWERSTATE_D2 0x0002
312#define NVREG_POWERSTATE_D3 0x0003
Ayaz Abdullacac1c522009-02-07 00:23:57 -0800313 NvRegMgmtUnitControl = 0x278,
314#define NVREG_MGMTUNITCONTROL_INUSE 0x20000
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400315 NvRegTxCnt = 0x280,
316 NvRegTxZeroReXmt = 0x284,
317 NvRegTxOneReXmt = 0x288,
318 NvRegTxManyReXmt = 0x28c,
319 NvRegTxLateCol = 0x290,
320 NvRegTxUnderflow = 0x294,
321 NvRegTxLossCarrier = 0x298,
322 NvRegTxExcessDef = 0x29c,
323 NvRegTxRetryErr = 0x2a0,
324 NvRegRxFrameErr = 0x2a4,
325 NvRegRxExtraByte = 0x2a8,
326 NvRegRxLateCol = 0x2ac,
327 NvRegRxRunt = 0x2b0,
328 NvRegRxFrameTooLong = 0x2b4,
329 NvRegRxOverflow = 0x2b8,
330 NvRegRxFCSErr = 0x2bc,
331 NvRegRxFrameAlignErr = 0x2c0,
332 NvRegRxLenErr = 0x2c4,
333 NvRegRxUnicast = 0x2c8,
334 NvRegRxMulticast = 0x2cc,
335 NvRegRxBroadcast = 0x2d0,
336 NvRegTxDef = 0x2d4,
337 NvRegTxFrame = 0x2d8,
338 NvRegRxCnt = 0x2dc,
339 NvRegTxPause = 0x2e0,
340 NvRegRxPause = 0x2e4,
341 NvRegRxDropFrame = 0x2e8,
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500342 NvRegVlanControl = 0x300,
343#define NVREG_VLANCONTROL_ENABLE 0x2000
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500344 NvRegMSIXMap0 = 0x3e0,
345 NvRegMSIXMap1 = 0x3e4,
346 NvRegMSIXIrqStatus = 0x3f0,
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400347
348 NvRegPowerState2 = 0x600,
Ayaz Abdulla1545e202008-09-22 09:55:35 -0400349#define NVREG_POWERSTATE2_POWERUP_MASK 0x0F15
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400350#define NVREG_POWERSTATE2_POWERUP_REV_A3 0x0001
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -0400351#define NVREG_POWERSTATE2_PHY_RESET 0x0004
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +0000352#define NVREG_POWERSTATE2_GATE_CLOCKS 0x0F00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353};
354
355/* Big endian: should work, but is untested */
356struct ring_desc {
Stephen Hemmingera8bed492006-07-27 18:50:09 -0700357 __le32 buf;
358 __le32 flaglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359};
360
Manfred Spraulee733622005-07-31 18:32:26 +0200361struct ring_desc_ex {
Stephen Hemmingera8bed492006-07-27 18:50:09 -0700362 __le32 bufhigh;
363 __le32 buflow;
364 __le32 txvlan;
365 __le32 flaglen;
Manfred Spraulee733622005-07-31 18:32:26 +0200366};
367
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700368union ring_type {
Szymon Janc78aea4f2010-11-27 08:39:43 +0000369 struct ring_desc *orig;
370 struct ring_desc_ex *ex;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700371};
Manfred Spraulee733622005-07-31 18:32:26 +0200372
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373#define FLAG_MASK_V1 0xffff0000
374#define FLAG_MASK_V2 0xffffc000
375#define LEN_MASK_V1 (0xffffffff ^ FLAG_MASK_V1)
376#define LEN_MASK_V2 (0xffffffff ^ FLAG_MASK_V2)
377
378#define NV_TX_LASTPACKET (1<<16)
379#define NV_TX_RETRYERROR (1<<19)
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700380#define NV_TX_RETRYCOUNT_MASK (0xF<<20)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200381#define NV_TX_FORCED_INTERRUPT (1<<24)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382#define NV_TX_DEFERRED (1<<26)
383#define NV_TX_CARRIERLOST (1<<27)
384#define NV_TX_LATECOLLISION (1<<28)
385#define NV_TX_UNDERFLOW (1<<29)
386#define NV_TX_ERROR (1<<30)
387#define NV_TX_VALID (1<<31)
388
389#define NV_TX2_LASTPACKET (1<<29)
390#define NV_TX2_RETRYERROR (1<<18)
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700391#define NV_TX2_RETRYCOUNT_MASK (0xF<<19)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200392#define NV_TX2_FORCED_INTERRUPT (1<<30)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393#define NV_TX2_DEFERRED (1<<25)
394#define NV_TX2_CARRIERLOST (1<<26)
395#define NV_TX2_LATECOLLISION (1<<27)
396#define NV_TX2_UNDERFLOW (1<<28)
397/* error and valid are the same for both */
398#define NV_TX2_ERROR (1<<30)
399#define NV_TX2_VALID (1<<31)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400400#define NV_TX2_TSO (1<<28)
401#define NV_TX2_TSO_SHIFT 14
Ayaz Abdullafa454592006-01-05 22:45:45 -0800402#define NV_TX2_TSO_MAX_SHIFT 14
403#define NV_TX2_TSO_MAX_SIZE (1<<NV_TX2_TSO_MAX_SHIFT)
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400404#define NV_TX2_CHECKSUM_L3 (1<<27)
405#define NV_TX2_CHECKSUM_L4 (1<<26)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500407#define NV_TX3_VLAN_TAG_PRESENT (1<<18)
408
Linus Torvalds1da177e2005-04-16 15:20:36 -0700409#define NV_RX_DESCRIPTORVALID (1<<16)
410#define NV_RX_MISSEDFRAME (1<<17)
411#define NV_RX_SUBSTRACT1 (1<<18)
412#define NV_RX_ERROR1 (1<<23)
413#define NV_RX_ERROR2 (1<<24)
414#define NV_RX_ERROR3 (1<<25)
415#define NV_RX_ERROR4 (1<<26)
416#define NV_RX_CRCERR (1<<27)
417#define NV_RX_OVERFLOW (1<<28)
418#define NV_RX_FRAMINGERR (1<<29)
419#define NV_RX_ERROR (1<<30)
420#define NV_RX_AVAIL (1<<31)
Ayaz Abdulla1ef68412008-08-06 12:11:03 -0400421#define NV_RX_ERROR_MASK (NV_RX_ERROR1|NV_RX_ERROR2|NV_RX_ERROR3|NV_RX_ERROR4|NV_RX_CRCERR|NV_RX_OVERFLOW|NV_RX_FRAMINGERR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422
423#define NV_RX2_CHECKSUMMASK (0x1C000000)
Ayaz Abdullabfaffe82008-01-13 16:02:55 -0500424#define NV_RX2_CHECKSUM_IP (0x10000000)
425#define NV_RX2_CHECKSUM_IP_TCP (0x14000000)
426#define NV_RX2_CHECKSUM_IP_UDP (0x18000000)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427#define NV_RX2_DESCRIPTORVALID (1<<29)
428#define NV_RX2_SUBSTRACT1 (1<<25)
429#define NV_RX2_ERROR1 (1<<18)
430#define NV_RX2_ERROR2 (1<<19)
431#define NV_RX2_ERROR3 (1<<20)
432#define NV_RX2_ERROR4 (1<<21)
433#define NV_RX2_CRCERR (1<<22)
434#define NV_RX2_OVERFLOW (1<<23)
435#define NV_RX2_FRAMINGERR (1<<24)
436/* error and avail are the same for both */
437#define NV_RX2_ERROR (1<<30)
438#define NV_RX2_AVAIL (1<<31)
Ayaz Abdulla1ef68412008-08-06 12:11:03 -0400439#define NV_RX2_ERROR_MASK (NV_RX2_ERROR1|NV_RX2_ERROR2|NV_RX2_ERROR3|NV_RX2_ERROR4|NV_RX2_CRCERR|NV_RX2_OVERFLOW|NV_RX2_FRAMINGERR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500441#define NV_RX3_VLAN_TAG_PRESENT (1<<16)
442#define NV_RX3_VLAN_TAG_MASK (0x0000FFFF)
443
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300444/* Miscellaneous hardware related defines: */
Szymon Janc78aea4f2010-11-27 08:39:43 +0000445#define NV_PCI_REGSZ_VER1 0x270
446#define NV_PCI_REGSZ_VER2 0x2d4
447#define NV_PCI_REGSZ_VER3 0x604
448#define NV_PCI_REGSZ_MAX 0x604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449
450/* various timeout delays: all in usec */
451#define NV_TXRX_RESET_DELAY 4
452#define NV_TXSTOP_DELAY1 10
453#define NV_TXSTOP_DELAY1MAX 500000
454#define NV_TXSTOP_DELAY2 100
455#define NV_RXSTOP_DELAY1 10
456#define NV_RXSTOP_DELAY1MAX 500000
457#define NV_RXSTOP_DELAY2 100
458#define NV_SETUP5_DELAY 5
459#define NV_SETUP5_DELAYMAX 50000
460#define NV_POWERUP_DELAY 5
461#define NV_POWERUP_DELAYMAX 5000
462#define NV_MIIBUSY_DELAY 50
463#define NV_MIIPHY_DELAY 10
464#define NV_MIIPHY_DELAYMAX 10000
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400465#define NV_MAC_RESET_DELAY 64
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466
467#define NV_WAKEUPPATTERNS 5
468#define NV_WAKEUPMASKENTRIES 4
469
470/* General driver defaults */
471#define NV_WATCHDOG_TIMEO (5*HZ)
472
Ayaz Abdulla6cef67a2009-03-05 08:02:30 +0000473#define RX_RING_DEFAULT 512
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400474#define TX_RING_DEFAULT 256
475#define RX_RING_MIN 128
476#define TX_RING_MIN 64
477#define RING_MAX_DESC_VER_1 1024
478#define RING_MAX_DESC_VER_2_3 16384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479
480/* rx/tx mac addr + type + vlan + align + slack*/
Manfred Sprauld81c0982005-07-31 18:20:30 +0200481#define NV_RX_HEADERS (64)
482/* even more slack. */
483#define NV_RX_ALLOC_PAD (64)
484
485/* maximum mtu size */
486#define NV_PKTLIMIT_1 ETH_DATA_LEN /* hard limit not known */
487#define NV_PKTLIMIT_2 9100 /* Actual limit according to NVidia: 9202 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488
489#define OOM_REFILL (1+HZ/20)
490#define POLL_WAIT (1+HZ/100)
491#define LINK_TIMEOUT (3*HZ)
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400492#define STATS_INTERVAL (10*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400494/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495 * desc_ver values:
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400496 * The nic supports three different descriptor types:
497 * - DESC_VER_1: Original
498 * - DESC_VER_2: support for jumbo frames.
499 * - DESC_VER_3: 64-bit format.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 */
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400501#define DESC_VER_1 1
502#define DESC_VER_2 2
503#define DESC_VER_3 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504
505/* PHY defines */
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400506#define PHY_OUI_MARVELL 0x5043
507#define PHY_OUI_CICADA 0x03f1
508#define PHY_OUI_VITESSE 0x01c1
509#define PHY_OUI_REALTEK 0x0732
510#define PHY_OUI_REALTEK2 0x0020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511#define PHYID1_OUI_MASK 0x03ff
512#define PHYID1_OUI_SHFT 6
513#define PHYID2_OUI_MASK 0xfc00
514#define PHYID2_OUI_SHFT 10
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -0400515#define PHYID2_MODEL_MASK 0x03f0
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400516#define PHY_MODEL_REALTEK_8211 0x0110
517#define PHY_REV_MASK 0x0001
518#define PHY_REV_REALTEK_8211B 0x0000
519#define PHY_REV_REALTEK_8211C 0x0001
520#define PHY_MODEL_REALTEK_8201 0x0200
521#define PHY_MODEL_MARVELL_E3016 0x0220
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -0400522#define PHY_MARVELL_E3016_INITMASK 0x0300
Ayaz Abdulla14a67f32007-07-15 06:50:28 -0400523#define PHY_CICADA_INIT1 0x0f000
524#define PHY_CICADA_INIT2 0x0e00
525#define PHY_CICADA_INIT3 0x01000
526#define PHY_CICADA_INIT4 0x0200
527#define PHY_CICADA_INIT5 0x0004
528#define PHY_CICADA_INIT6 0x02000
Ayaz Abdullad215d8a2007-07-15 06:50:53 -0400529#define PHY_VITESSE_INIT_REG1 0x1f
530#define PHY_VITESSE_INIT_REG2 0x10
531#define PHY_VITESSE_INIT_REG3 0x11
532#define PHY_VITESSE_INIT_REG4 0x12
533#define PHY_VITESSE_INIT_MSK1 0xc
534#define PHY_VITESSE_INIT_MSK2 0x0180
535#define PHY_VITESSE_INIT1 0x52b5
536#define PHY_VITESSE_INIT2 0xaf8a
537#define PHY_VITESSE_INIT3 0x8
538#define PHY_VITESSE_INIT4 0x8f8a
539#define PHY_VITESSE_INIT5 0xaf86
540#define PHY_VITESSE_INIT6 0x8f86
541#define PHY_VITESSE_INIT7 0xaf82
542#define PHY_VITESSE_INIT8 0x0100
543#define PHY_VITESSE_INIT9 0x8f82
544#define PHY_VITESSE_INIT10 0x0
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -0400545#define PHY_REALTEK_INIT_REG1 0x1f
546#define PHY_REALTEK_INIT_REG2 0x19
547#define PHY_REALTEK_INIT_REG3 0x13
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400548#define PHY_REALTEK_INIT_REG4 0x14
549#define PHY_REALTEK_INIT_REG5 0x18
550#define PHY_REALTEK_INIT_REG6 0x11
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -0400551#define PHY_REALTEK_INIT_REG7 0x01
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -0400552#define PHY_REALTEK_INIT1 0x0000
553#define PHY_REALTEK_INIT2 0x8e00
554#define PHY_REALTEK_INIT3 0x0001
555#define PHY_REALTEK_INIT4 0xad17
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400556#define PHY_REALTEK_INIT5 0xfb54
557#define PHY_REALTEK_INIT6 0xf5c7
558#define PHY_REALTEK_INIT7 0x1000
559#define PHY_REALTEK_INIT8 0x0003
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -0400560#define PHY_REALTEK_INIT9 0x0008
561#define PHY_REALTEK_INIT10 0x0005
562#define PHY_REALTEK_INIT11 0x0200
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400563#define PHY_REALTEK_INIT_MSK1 0x0003
Ayaz Abdullad215d8a2007-07-15 06:50:53 -0400564
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565#define PHY_GIGABIT 0x0100
566
567#define PHY_TIMEOUT 0x1
568#define PHY_ERROR 0x2
569
570#define PHY_100 0x1
571#define PHY_1000 0x2
572#define PHY_HALF 0x100
573
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400574#define NV_PAUSEFRAME_RX_CAPABLE 0x0001
575#define NV_PAUSEFRAME_TX_CAPABLE 0x0002
576#define NV_PAUSEFRAME_RX_ENABLE 0x0004
577#define NV_PAUSEFRAME_TX_ENABLE 0x0008
Ayaz Abdullab6d07732006-06-10 22:47:42 -0400578#define NV_PAUSEFRAME_RX_REQ 0x0010
579#define NV_PAUSEFRAME_TX_REQ 0x0020
580#define NV_PAUSEFRAME_AUTONEG 0x0040
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500582/* MSI/MSI-X defines */
583#define NV_MSI_X_MAX_VECTORS 8
584#define NV_MSI_X_VECTORS_MASK 0x000f
585#define NV_MSI_CAPABLE 0x0010
586#define NV_MSI_X_CAPABLE 0x0020
587#define NV_MSI_ENABLED 0x0040
588#define NV_MSI_X_ENABLED 0x0080
589
590#define NV_MSI_X_VECTOR_ALL 0x0
591#define NV_MSI_X_VECTOR_RX 0x0
592#define NV_MSI_X_VECTOR_TX 0x1
593#define NV_MSI_X_VECTOR_OTHER 0x2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Ayaz Abdullab6e44052009-02-07 00:24:15 -0800595#define NV_MSI_PRIV_OFFSET 0x68
596#define NV_MSI_PRIV_VALUE 0xffffffff
597
Ayaz Abdullab2976d22008-02-04 15:13:59 -0500598#define NV_RESTART_TX 0x1
599#define NV_RESTART_RX 0x2
600
Ayaz Abdulla3b446c32008-03-10 14:58:21 -0500601#define NV_TX_LIMIT_COUNT 16
602
Ayaz Abdulla4145ade2009-03-05 08:02:26 +0000603#define NV_DYNAMIC_THRESHOLD 4
604#define NV_DYNAMIC_MAX_QUIET_COUNT 2048
605
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400606/* statistics */
607struct nv_ethtool_str {
608 char name[ETH_GSTRING_LEN];
609};
610
611static const struct nv_ethtool_str nv_estats_str[] = {
david decotigny674aee32011-11-16 12:15:07 +0000612 { "tx_bytes" }, /* includes Ethernet FCS CRC */
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400613 { "tx_zero_rexmt" },
614 { "tx_one_rexmt" },
615 { "tx_many_rexmt" },
616 { "tx_late_collision" },
617 { "tx_fifo_errors" },
618 { "tx_carrier_errors" },
619 { "tx_excess_deferral" },
620 { "tx_retry_error" },
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400621 { "rx_frame_error" },
622 { "rx_extra_byte" },
623 { "rx_late_collision" },
624 { "rx_runt" },
625 { "rx_frame_too_long" },
626 { "rx_over_errors" },
627 { "rx_crc_errors" },
628 { "rx_frame_align_error" },
629 { "rx_length_error" },
630 { "rx_unicast" },
631 { "rx_multicast" },
632 { "rx_broadcast" },
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400633 { "rx_packets" },
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500634 { "rx_errors_total" },
635 { "tx_errors_total" },
636
637 /* version 2 stats */
638 { "tx_deferral" },
639 { "tx_packets" },
david decotigny674aee32011-11-16 12:15:07 +0000640 { "rx_bytes" }, /* includes Ethernet FCS CRC */
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500641 { "tx_pause" },
642 { "rx_pause" },
Ayaz Abdulla9c662432008-08-06 12:11:42 -0400643 { "rx_drop_frame" },
644
645 /* version 3 stats */
646 { "tx_unicast" },
647 { "tx_multicast" },
648 { "tx_broadcast" }
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400649};
650
651struct nv_ethtool_stats {
david decotigny674aee32011-11-16 12:15:07 +0000652 u64 tx_bytes; /* should be ifconfig->tx_bytes + 4*tx_packets */
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400653 u64 tx_zero_rexmt;
654 u64 tx_one_rexmt;
655 u64 tx_many_rexmt;
656 u64 tx_late_collision;
657 u64 tx_fifo_errors;
658 u64 tx_carrier_errors;
659 u64 tx_excess_deferral;
660 u64 tx_retry_error;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400661 u64 rx_frame_error;
662 u64 rx_extra_byte;
663 u64 rx_late_collision;
664 u64 rx_runt;
665 u64 rx_frame_too_long;
666 u64 rx_over_errors;
667 u64 rx_crc_errors;
668 u64 rx_frame_align_error;
669 u64 rx_length_error;
670 u64 rx_unicast;
671 u64 rx_multicast;
672 u64 rx_broadcast;
david decotigny674aee32011-11-16 12:15:07 +0000673 u64 rx_packets; /* should be ifconfig->rx_packets */
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400674 u64 rx_errors_total;
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500675 u64 tx_errors_total;
676
677 /* version 2 stats */
678 u64 tx_deferral;
david decotigny674aee32011-11-16 12:15:07 +0000679 u64 tx_packets; /* should be ifconfig->tx_packets */
680 u64 rx_bytes; /* should be ifconfig->rx_bytes + 4*rx_packets */
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500681 u64 tx_pause;
682 u64 rx_pause;
683 u64 rx_drop_frame;
Ayaz Abdulla9c662432008-08-06 12:11:42 -0400684
685 /* version 3 stats */
686 u64 tx_unicast;
687 u64 tx_multicast;
688 u64 tx_broadcast;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400689};
690
Ayaz Abdulla9c662432008-08-06 12:11:42 -0400691#define NV_DEV_STATISTICS_V3_COUNT (sizeof(struct nv_ethtool_stats)/sizeof(u64))
692#define NV_DEV_STATISTICS_V2_COUNT (NV_DEV_STATISTICS_V3_COUNT - 3)
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500693#define NV_DEV_STATISTICS_V1_COUNT (NV_DEV_STATISTICS_V2_COUNT - 6)
694
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400695/* diagnostics */
696#define NV_TEST_COUNT_BASE 3
697#define NV_TEST_COUNT_EXTENDED 4
698
699static const struct nv_ethtool_str nv_etests_str[] = {
700 { "link (online/offline)" },
701 { "register (offline) " },
702 { "interrupt (offline) " },
703 { "loopback (offline) " }
704};
705
706struct register_test {
Al Viro5bb7ea22007-12-09 16:06:41 +0000707 __u32 reg;
708 __u32 mask;
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400709};
710
711static const struct register_test nv_registers_test[] = {
712 { NvRegUnknownSetupReg6, 0x01 },
713 { NvRegMisc1, 0x03c },
714 { NvRegOffloadConfig, 0x03ff },
715 { NvRegMulticastAddrA, 0xffffffff },
Ayaz Abdulla95d161c2006-07-06 16:46:25 -0400716 { NvRegTxWatermark, 0x0ff },
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400717 { NvRegWakeUpFlags, 0x07777 },
Szymon Janc78aea4f2010-11-27 08:39:43 +0000718 { 0, 0 }
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400719};
720
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500721struct nv_skb_map {
722 struct sk_buff *skb;
723 dma_addr_t dma;
Eric Dumazet73a37072009-06-17 21:17:59 +0000724 unsigned int dma_len:31;
725 unsigned int dma_single:1;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -0500726 struct ring_desc_ex *first_tx_desc;
727 struct nv_skb_map *next_tx_ctx;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500728};
729
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730/*
731 * SMP locking:
Wang Chenb74ca3a2008-12-08 01:14:16 -0800732 * All hardware access under netdev_priv(dev)->lock, except the performance
Linus Torvalds1da177e2005-04-16 15:20:36 -0700733 * critical parts:
734 * - rx is (pseudo-) lockless: it relies on the single-threading provided
735 * by the arch code for interrupts.
Herbert Xu932ff272006-06-09 12:20:56 -0700736 * - tx setup is lockless: it relies on netif_tx_lock. Actual submission
Wang Chenb74ca3a2008-12-08 01:14:16 -0800737 * needs netdev_priv(dev)->lock :-(
Herbert Xu932ff272006-06-09 12:20:56 -0700738 * - set_multicast_list: preparation lockless, relies on netif_tx_lock.
david decotignyf5d827a2011-11-16 12:15:13 +0000739 *
740 * Hardware stats updates are protected by hwstats_lock:
741 * - updated by nv_do_stats_poll (timer). This is meant to avoid
742 * integer wraparound in the NIC stats registers, at low frequency
743 * (0.1 Hz)
744 * - updated by nv_get_ethtool_stats + nv_get_stats64
745 *
746 * Software stats are accessed only through 64b synchronization points
747 * and are not subject to other synchronization techniques (single
748 * update thread on the TX or RX paths).
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749 */
750
751/* in dev: base, irq */
752struct fe_priv {
753 spinlock_t lock;
754
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700755 struct net_device *dev;
756 struct napi_struct napi;
757
david decotignyf5d827a2011-11-16 12:15:13 +0000758 /* hardware stats are updated in syscall and timer */
759 spinlock_t hwstats_lock;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400760 struct nv_ethtool_stats estats;
david decotignyf5d827a2011-11-16 12:15:13 +0000761
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762 int in_shutdown;
763 u32 linkspeed;
764 int duplex;
765 int autoneg;
766 int fixed_mode;
767 int phyaddr;
768 int wolenabled;
769 unsigned int phy_oui;
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -0400770 unsigned int phy_model;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400771 unsigned int phy_rev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700772 u16 gigabit;
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400773 int intr_test;
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500774 int recover_error;
Ayaz Abdulla4145ade2009-03-05 08:02:26 +0000775 int quiet_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
777 /* General data: RO fields */
778 dma_addr_t ring_addr;
779 struct pci_dev *pci_dev;
780 u32 orig_mac[2];
Ayaz Abdulla582806b2009-03-05 08:02:03 +0000781 u32 events;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700782 u32 irqmask;
783 u32 desc_ver;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400784 u32 txrxctl_bits;
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500785 u32 vlanctl_bits;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400786 u32 driver_data;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400787 u32 device_id;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400788 u32 register_size;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500789 u32 mac_in_use;
Ayaz Abdullacac1c522009-02-07 00:23:57 -0800790 int mgmt_version;
791 int mgmt_sema;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700792
793 void __iomem *base;
794
795 /* rx specific fields.
796 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
797 */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500798 union ring_type get_rx, put_rx, first_rx, last_rx;
799 struct nv_skb_map *get_rx_ctx, *put_rx_ctx;
800 struct nv_skb_map *first_rx_ctx, *last_rx_ctx;
801 struct nv_skb_map *rx_skb;
802
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700803 union ring_type rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 unsigned int rx_buf_sz;
Manfred Sprauld81c0982005-07-31 18:20:30 +0200805 unsigned int pkt_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700806 struct timer_list oom_kick;
807 struct timer_list nic_poll;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400808 struct timer_list stats_poll;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500809 u32 nic_poll_irq;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400810 int rx_ring_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700811
david decotignyf5d827a2011-11-16 12:15:13 +0000812 /* RX software stats */
813 struct u64_stats_sync swstats_rx_syncp;
814 u64 stat_rx_packets;
815 u64 stat_rx_bytes; /* not always available in HW */
816 u64 stat_rx_missed_errors;
david decotigny0a1f2222011-11-16 12:15:14 +0000817 u64 stat_rx_dropped;
david decotignyf5d827a2011-11-16 12:15:13 +0000818
Linus Torvalds1da177e2005-04-16 15:20:36 -0700819 /* media detection workaround.
820 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
821 */
822 int need_linktimer;
823 unsigned long link_timeout;
824 /*
825 * tx specific fields.
826 */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500827 union ring_type get_tx, put_tx, first_tx, last_tx;
828 struct nv_skb_map *get_tx_ctx, *put_tx_ctx;
829 struct nv_skb_map *first_tx_ctx, *last_tx_ctx;
830 struct nv_skb_map *tx_skb;
831
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700832 union ring_type tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700833 u32 tx_flags;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400834 int tx_ring_size;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -0500835 int tx_limit;
836 u32 tx_pkts_in_progress;
837 struct nv_skb_map *tx_change_owner;
838 struct nv_skb_map *tx_end_flip;
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -0500839 int tx_stop;
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500840
david decotignyf5d827a2011-11-16 12:15:13 +0000841 /* TX software stats */
842 struct u64_stats_sync swstats_tx_syncp;
843 u64 stat_tx_packets; /* not always available in HW */
844 u64 stat_tx_bytes;
845 u64 stat_tx_dropped;
846
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500847 /* msi/msi-x fields */
848 u32 msi_flags;
849 struct msix_entry msi_x_entry[NV_MSI_X_MAX_VECTORS];
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400850
851 /* flow control */
852 u32 pause_flags;
Tobias Diedrich1a1ca862008-05-18 15:03:44 +0200853
854 /* power saved state */
855 u32 saved_config_space[NV_PCI_REGSZ_MAX/4];
Yinghai Luddb213f2009-02-06 01:29:23 -0800856
857 /* for different msi-x irq type */
858 char name_rx[IFNAMSIZ + 3]; /* -rx */
859 char name_tx[IFNAMSIZ + 3]; /* -tx */
860 char name_other[IFNAMSIZ + 6]; /* -other */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861};
862
863/*
864 * Maximum number of loops until we assume that a bit in the irq mask
865 * is stuck. Overridable with module param.
866 */
Ayaz Abdulla4145ade2009-03-05 08:02:26 +0000867static int max_interrupt_work = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500869/*
870 * Optimization can be either throuput mode or cpu mode
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400871 *
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500872 * Throughput Mode: Every tx and rx packet will generate an interrupt.
873 * CPU Mode: Interrupts are controlled by a timer.
874 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400875enum {
876 NV_OPTIMIZATION_MODE_THROUGHPUT,
Ayaz Abdulla9e184762009-03-05 08:02:18 +0000877 NV_OPTIMIZATION_MODE_CPU,
878 NV_OPTIMIZATION_MODE_DYNAMIC
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400879};
Ayaz Abdulla9e184762009-03-05 08:02:18 +0000880static int optimization_mode = NV_OPTIMIZATION_MODE_DYNAMIC;
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500881
882/*
883 * Poll interval for timer irq
884 *
885 * This interval determines how frequent an interrupt is generated.
886 * The is value is determined by [(time_in_micro_secs * 100) / (2^10)]
887 * Min = 0, and Max = 65535
888 */
889static int poll_interval = -1;
890
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500891/*
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400892 * MSI interrupts
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500893 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400894enum {
895 NV_MSI_INT_DISABLED,
896 NV_MSI_INT_ENABLED
897};
898static int msi = NV_MSI_INT_ENABLED;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500899
900/*
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400901 * MSIX interrupts
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500902 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400903enum {
904 NV_MSIX_INT_DISABLED,
905 NV_MSIX_INT_ENABLED
906};
Yinghai Lu39482792009-02-06 01:31:12 -0800907static int msix = NV_MSIX_INT_ENABLED;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400908
909/*
910 * DMA 64bit
911 */
912enum {
913 NV_DMA_64BIT_DISABLED,
914 NV_DMA_64BIT_ENABLED
915};
916static int dma_64bit = NV_DMA_64BIT_ENABLED;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500917
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400918/*
Sameer Nanda1ec4f2d2011-11-16 12:15:12 +0000919 * Debug output control for tx_timeout
920 */
921static bool debug_tx_timeout = false;
922
923/*
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400924 * Crossover Detection
925 * Realtek 8201 phy + some OEM boards do not work properly.
926 */
927enum {
928 NV_CROSSOVER_DETECTION_DISABLED,
929 NV_CROSSOVER_DETECTION_ENABLED
930};
931static int phy_cross = NV_CROSSOVER_DETECTION_DISABLED;
932
Ed Swierk5a9a8e32009-06-02 00:19:52 -0700933/*
934 * Power down phy when interface is down (persists through reboot;
935 * older Linux and other OSes may not power it up again)
936 */
Szymon Janc78aea4f2010-11-27 08:39:43 +0000937static int phy_power_down;
Ed Swierk5a9a8e32009-06-02 00:19:52 -0700938
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939static inline struct fe_priv *get_nvpriv(struct net_device *dev)
940{
941 return netdev_priv(dev);
942}
943
944static inline u8 __iomem *get_hwbase(struct net_device *dev)
945{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400946 return ((struct fe_priv *)netdev_priv(dev))->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947}
948
949static inline void pci_push(u8 __iomem *base)
950{
951 /* force out pending posted writes */
952 readl(base);
953}
954
955static inline u32 nv_descr_getlength(struct ring_desc *prd, u32 v)
956{
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700957 return le32_to_cpu(prd->flaglen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 & ((v == DESC_VER_1) ? LEN_MASK_V1 : LEN_MASK_V2);
959}
960
Manfred Spraulee733622005-07-31 18:32:26 +0200961static inline u32 nv_descr_getlength_ex(struct ring_desc_ex *prd, u32 v)
962{
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700963 return le32_to_cpu(prd->flaglen) & LEN_MASK_V2;
Manfred Spraulee733622005-07-31 18:32:26 +0200964}
965
Jeff Garzik36b30ea2007-10-16 01:40:30 -0400966static bool nv_optimized(struct fe_priv *np)
967{
968 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
969 return false;
970 return true;
971}
972
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973static int reg_delay(struct net_device *dev, int offset, u32 mask, u32 target,
Joe Perches344d0dc2010-11-29 07:41:52 +0000974 int delay, int delaymax)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700975{
976 u8 __iomem *base = get_hwbase(dev);
977
978 pci_push(base);
979 do {
980 udelay(delay);
981 delaymax -= delay;
Joe Perches344d0dc2010-11-29 07:41:52 +0000982 if (delaymax < 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 } while ((readl(base + offset) & mask) != target);
985 return 0;
986}
987
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500988#define NV_SETUP_RX_RING 0x01
989#define NV_SETUP_TX_RING 0x02
990
Al Viro5bb7ea22007-12-09 16:06:41 +0000991static inline u32 dma_low(dma_addr_t addr)
992{
993 return addr;
994}
995
996static inline u32 dma_high(dma_addr_t addr)
997{
998 return addr>>31>>1; /* 0 if 32bit, shift down by 32 if 64bit */
999}
1000
Ayaz Abdulla0832b252006-02-04 13:13:26 -05001001static void setup_hw_rings(struct net_device *dev, int rxtx_flags)
1002{
1003 struct fe_priv *np = get_nvpriv(dev);
1004 u8 __iomem *base = get_hwbase(dev);
1005
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001006 if (!nv_optimized(np)) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00001007 if (rxtx_flags & NV_SETUP_RX_RING)
Al Viro5bb7ea22007-12-09 16:06:41 +00001008 writel(dma_low(np->ring_addr), base + NvRegRxRingPhysAddr);
Szymon Janc78aea4f2010-11-27 08:39:43 +00001009 if (rxtx_flags & NV_SETUP_TX_RING)
Al Viro5bb7ea22007-12-09 16:06:41 +00001010 writel(dma_low(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr);
Ayaz Abdulla0832b252006-02-04 13:13:26 -05001011 } else {
1012 if (rxtx_flags & NV_SETUP_RX_RING) {
Al Viro5bb7ea22007-12-09 16:06:41 +00001013 writel(dma_low(np->ring_addr), base + NvRegRxRingPhysAddr);
1014 writel(dma_high(np->ring_addr), base + NvRegRxRingPhysAddrHigh);
Ayaz Abdulla0832b252006-02-04 13:13:26 -05001015 }
1016 if (rxtx_flags & NV_SETUP_TX_RING) {
Al Viro5bb7ea22007-12-09 16:06:41 +00001017 writel(dma_low(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr);
1018 writel(dma_high(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddrHigh);
Ayaz Abdulla0832b252006-02-04 13:13:26 -05001019 }
1020 }
1021}
1022
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001023static void free_rings(struct net_device *dev)
1024{
1025 struct fe_priv *np = get_nvpriv(dev);
1026
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001027 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001028 if (np->rx_ring.orig)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001029 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
1030 np->rx_ring.orig, np->ring_addr);
1031 } else {
1032 if (np->rx_ring.ex)
1033 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
1034 np->rx_ring.ex, np->ring_addr);
1035 }
Szymon Janc9b03b062010-11-27 08:39:44 +00001036 kfree(np->rx_skb);
1037 kfree(np->tx_skb);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001038}
1039
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001040static int using_multi_irqs(struct net_device *dev)
1041{
1042 struct fe_priv *np = get_nvpriv(dev);
1043
1044 if (!(np->msi_flags & NV_MSI_X_ENABLED) ||
1045 ((np->msi_flags & NV_MSI_X_ENABLED) &&
1046 ((np->msi_flags & NV_MSI_X_VECTORS_MASK) == 0x1)))
1047 return 0;
1048 else
1049 return 1;
1050}
1051
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00001052static void nv_txrx_gate(struct net_device *dev, bool gate)
1053{
1054 struct fe_priv *np = get_nvpriv(dev);
1055 u8 __iomem *base = get_hwbase(dev);
1056 u32 powerstate;
1057
1058 if (!np->mac_in_use &&
1059 (np->driver_data & DEV_HAS_POWER_CNTRL)) {
1060 powerstate = readl(base + NvRegPowerState2);
1061 if (gate)
1062 powerstate |= NVREG_POWERSTATE2_GATE_CLOCKS;
1063 else
1064 powerstate &= ~NVREG_POWERSTATE2_GATE_CLOCKS;
1065 writel(powerstate, base + NvRegPowerState2);
1066 }
1067}
1068
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001069static void nv_enable_irq(struct net_device *dev)
1070{
1071 struct fe_priv *np = get_nvpriv(dev);
1072
1073 if (!using_multi_irqs(dev)) {
1074 if (np->msi_flags & NV_MSI_X_ENABLED)
1075 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1076 else
Manfred Spraula7475902007-10-17 21:52:33 +02001077 enable_irq(np->pci_dev->irq);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001078 } else {
1079 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1080 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
1081 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
1082 }
1083}
1084
1085static void nv_disable_irq(struct net_device *dev)
1086{
1087 struct fe_priv *np = get_nvpriv(dev);
1088
1089 if (!using_multi_irqs(dev)) {
1090 if (np->msi_flags & NV_MSI_X_ENABLED)
1091 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1092 else
Manfred Spraula7475902007-10-17 21:52:33 +02001093 disable_irq(np->pci_dev->irq);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001094 } else {
1095 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1096 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
1097 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
1098 }
1099}
1100
1101/* In MSIX mode, a write to irqmask behaves as XOR */
1102static void nv_enable_hw_interrupts(struct net_device *dev, u32 mask)
1103{
1104 u8 __iomem *base = get_hwbase(dev);
1105
1106 writel(mask, base + NvRegIrqMask);
1107}
1108
1109static void nv_disable_hw_interrupts(struct net_device *dev, u32 mask)
1110{
1111 struct fe_priv *np = get_nvpriv(dev);
1112 u8 __iomem *base = get_hwbase(dev);
1113
1114 if (np->msi_flags & NV_MSI_X_ENABLED) {
1115 writel(mask, base + NvRegIrqMask);
1116 } else {
1117 if (np->msi_flags & NV_MSI_ENABLED)
1118 writel(0, base + NvRegMSIIrqMask);
1119 writel(0, base + NvRegIrqMask);
1120 }
1121}
1122
Ayaz Abdulla08d93572009-03-05 08:01:55 +00001123static void nv_napi_enable(struct net_device *dev)
1124{
Ayaz Abdulla08d93572009-03-05 08:01:55 +00001125 struct fe_priv *np = get_nvpriv(dev);
1126
1127 napi_enable(&np->napi);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00001128}
1129
1130static void nv_napi_disable(struct net_device *dev)
1131{
Ayaz Abdulla08d93572009-03-05 08:01:55 +00001132 struct fe_priv *np = get_nvpriv(dev);
1133
1134 napi_disable(&np->napi);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00001135}
1136
Linus Torvalds1da177e2005-04-16 15:20:36 -07001137#define MII_READ (-1)
1138/* mii_rw: read/write a register on the PHY.
1139 *
1140 * Caller must guarantee serialization
1141 */
1142static int mii_rw(struct net_device *dev, int addr, int miireg, int value)
1143{
1144 u8 __iomem *base = get_hwbase(dev);
1145 u32 reg;
1146 int retval;
1147
Ayaz Abdullaeb798422008-02-04 15:14:04 -05001148 writel(NVREG_MIISTAT_MASK_RW, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149
1150 reg = readl(base + NvRegMIIControl);
1151 if (reg & NVREG_MIICTL_INUSE) {
1152 writel(NVREG_MIICTL_INUSE, base + NvRegMIIControl);
1153 udelay(NV_MIIBUSY_DELAY);
1154 }
1155
1156 reg = (addr << NVREG_MIICTL_ADDRSHIFT) | miireg;
1157 if (value != MII_READ) {
1158 writel(value, base + NvRegMIIData);
1159 reg |= NVREG_MIICTL_WRITE;
1160 }
1161 writel(reg, base + NvRegMIIControl);
1162
1163 if (reg_delay(dev, NvRegMIIControl, NVREG_MIICTL_INUSE, 0,
Joe Perches344d0dc2010-11-29 07:41:52 +00001164 NV_MIIPHY_DELAY, NV_MIIPHY_DELAYMAX)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001165 retval = -1;
1166 } else if (value != MII_READ) {
1167 /* it was a write operation - fewer failures are detectable */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001168 retval = 0;
1169 } else if (readl(base + NvRegMIIStatus) & NVREG_MIISTAT_ERROR) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001170 retval = -1;
1171 } else {
1172 retval = readl(base + NvRegMIIData);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001173 }
1174
1175 return retval;
1176}
1177
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001178static int phy_reset(struct net_device *dev, u32 bmcr_setup)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001180 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 u32 miicontrol;
1182 unsigned int tries = 0;
1183
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001184 miicontrol = BMCR_RESET | bmcr_setup;
Szymon Janc78aea4f2010-11-27 08:39:43 +00001185 if (mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001187
1188 /* wait for 500ms */
1189 msleep(500);
1190
1191 /* must wait till reset is deasserted */
1192 while (miicontrol & BMCR_RESET) {
Szymon Jancde855b92010-11-27 08:39:48 +00001193 usleep_range(10000, 20000);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194 miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1195 /* FIXME: 100 tries seem excessive */
1196 if (tries++ > 100)
1197 return -1;
1198 }
1199 return 0;
1200}
1201
Joe Perchesc41d41e2010-11-29 07:41:58 +00001202static int init_realtek_8211b(struct net_device *dev, struct fe_priv *np)
1203{
1204 static const struct {
1205 int reg;
1206 int init;
1207 } ri[] = {
1208 { PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1 },
1209 { PHY_REALTEK_INIT_REG2, PHY_REALTEK_INIT2 },
1210 { PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3 },
1211 { PHY_REALTEK_INIT_REG3, PHY_REALTEK_INIT4 },
1212 { PHY_REALTEK_INIT_REG4, PHY_REALTEK_INIT5 },
1213 { PHY_REALTEK_INIT_REG5, PHY_REALTEK_INIT6 },
1214 { PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1 },
1215 };
1216 int i;
1217
1218 for (i = 0; i < ARRAY_SIZE(ri); i++) {
Joe Perchescd663282010-11-29 07:41:59 +00001219 if (mii_rw(dev, np->phyaddr, ri[i].reg, ri[i].init))
Joe Perchesc41d41e2010-11-29 07:41:58 +00001220 return PHY_ERROR;
Joe Perchesc41d41e2010-11-29 07:41:58 +00001221 }
1222
1223 return 0;
1224}
1225
Joe Perchescd663282010-11-29 07:41:59 +00001226static int init_realtek_8211c(struct net_device *dev, struct fe_priv *np)
1227{
1228 u32 reg;
1229 u8 __iomem *base = get_hwbase(dev);
1230 u32 powerstate = readl(base + NvRegPowerState2);
1231
1232 /* need to perform hw phy reset */
1233 powerstate |= NVREG_POWERSTATE2_PHY_RESET;
1234 writel(powerstate, base + NvRegPowerState2);
1235 msleep(25);
1236
1237 powerstate &= ~NVREG_POWERSTATE2_PHY_RESET;
1238 writel(powerstate, base + NvRegPowerState2);
1239 msleep(25);
1240
1241 reg = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, MII_READ);
1242 reg |= PHY_REALTEK_INIT9;
1243 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, reg))
1244 return PHY_ERROR;
1245 if (mii_rw(dev, np->phyaddr,
1246 PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT10))
1247 return PHY_ERROR;
1248 reg = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG7, MII_READ);
1249 if (!(reg & PHY_REALTEK_INIT11)) {
1250 reg |= PHY_REALTEK_INIT11;
1251 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG7, reg))
1252 return PHY_ERROR;
1253 }
1254 if (mii_rw(dev, np->phyaddr,
1255 PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1))
1256 return PHY_ERROR;
1257
1258 return 0;
1259}
1260
1261static int init_realtek_8201(struct net_device *dev, struct fe_priv *np)
1262{
1263 u32 phy_reserved;
1264
1265 if (np->driver_data & DEV_NEED_PHY_INIT_FIX) {
1266 phy_reserved = mii_rw(dev, np->phyaddr,
1267 PHY_REALTEK_INIT_REG6, MII_READ);
1268 phy_reserved |= PHY_REALTEK_INIT7;
1269 if (mii_rw(dev, np->phyaddr,
1270 PHY_REALTEK_INIT_REG6, phy_reserved))
1271 return PHY_ERROR;
1272 }
1273
1274 return 0;
1275}
1276
1277static int init_realtek_8201_cross(struct net_device *dev, struct fe_priv *np)
1278{
1279 u32 phy_reserved;
1280
1281 if (phy_cross == NV_CROSSOVER_DETECTION_DISABLED) {
1282 if (mii_rw(dev, np->phyaddr,
1283 PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3))
1284 return PHY_ERROR;
1285 phy_reserved = mii_rw(dev, np->phyaddr,
1286 PHY_REALTEK_INIT_REG2, MII_READ);
1287 phy_reserved &= ~PHY_REALTEK_INIT_MSK1;
1288 phy_reserved |= PHY_REALTEK_INIT3;
1289 if (mii_rw(dev, np->phyaddr,
1290 PHY_REALTEK_INIT_REG2, phy_reserved))
1291 return PHY_ERROR;
1292 if (mii_rw(dev, np->phyaddr,
1293 PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1))
1294 return PHY_ERROR;
1295 }
1296
1297 return 0;
1298}
1299
1300static int init_cicada(struct net_device *dev, struct fe_priv *np,
1301 u32 phyinterface)
1302{
1303 u32 phy_reserved;
1304
1305 if (phyinterface & PHY_RGMII) {
1306 phy_reserved = mii_rw(dev, np->phyaddr, MII_RESV1, MII_READ);
1307 phy_reserved &= ~(PHY_CICADA_INIT1 | PHY_CICADA_INIT2);
1308 phy_reserved |= (PHY_CICADA_INIT3 | PHY_CICADA_INIT4);
1309 if (mii_rw(dev, np->phyaddr, MII_RESV1, phy_reserved))
1310 return PHY_ERROR;
1311 phy_reserved = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
1312 phy_reserved |= PHY_CICADA_INIT5;
1313 if (mii_rw(dev, np->phyaddr, MII_NCONFIG, phy_reserved))
1314 return PHY_ERROR;
1315 }
1316 phy_reserved = mii_rw(dev, np->phyaddr, MII_SREVISION, MII_READ);
1317 phy_reserved |= PHY_CICADA_INIT6;
1318 if (mii_rw(dev, np->phyaddr, MII_SREVISION, phy_reserved))
1319 return PHY_ERROR;
1320
1321 return 0;
1322}
1323
1324static int init_vitesse(struct net_device *dev, struct fe_priv *np)
1325{
1326 u32 phy_reserved;
1327
1328 if (mii_rw(dev, np->phyaddr,
1329 PHY_VITESSE_INIT_REG1, PHY_VITESSE_INIT1))
1330 return PHY_ERROR;
1331 if (mii_rw(dev, np->phyaddr,
1332 PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT2))
1333 return PHY_ERROR;
1334 phy_reserved = mii_rw(dev, np->phyaddr,
1335 PHY_VITESSE_INIT_REG4, MII_READ);
1336 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved))
1337 return PHY_ERROR;
1338 phy_reserved = mii_rw(dev, np->phyaddr,
1339 PHY_VITESSE_INIT_REG3, MII_READ);
1340 phy_reserved &= ~PHY_VITESSE_INIT_MSK1;
1341 phy_reserved |= PHY_VITESSE_INIT3;
1342 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved))
1343 return PHY_ERROR;
1344 if (mii_rw(dev, np->phyaddr,
1345 PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT4))
1346 return PHY_ERROR;
1347 if (mii_rw(dev, np->phyaddr,
1348 PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT5))
1349 return PHY_ERROR;
1350 phy_reserved = mii_rw(dev, np->phyaddr,
1351 PHY_VITESSE_INIT_REG4, MII_READ);
1352 phy_reserved &= ~PHY_VITESSE_INIT_MSK1;
1353 phy_reserved |= PHY_VITESSE_INIT3;
1354 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved))
1355 return PHY_ERROR;
1356 phy_reserved = mii_rw(dev, np->phyaddr,
1357 PHY_VITESSE_INIT_REG3, MII_READ);
1358 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved))
1359 return PHY_ERROR;
1360 if (mii_rw(dev, np->phyaddr,
1361 PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT6))
1362 return PHY_ERROR;
1363 if (mii_rw(dev, np->phyaddr,
1364 PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT7))
1365 return PHY_ERROR;
1366 phy_reserved = mii_rw(dev, np->phyaddr,
1367 PHY_VITESSE_INIT_REG4, MII_READ);
1368 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved))
1369 return PHY_ERROR;
1370 phy_reserved = mii_rw(dev, np->phyaddr,
1371 PHY_VITESSE_INIT_REG3, MII_READ);
1372 phy_reserved &= ~PHY_VITESSE_INIT_MSK2;
1373 phy_reserved |= PHY_VITESSE_INIT8;
1374 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved))
1375 return PHY_ERROR;
1376 if (mii_rw(dev, np->phyaddr,
1377 PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT9))
1378 return PHY_ERROR;
1379 if (mii_rw(dev, np->phyaddr,
1380 PHY_VITESSE_INIT_REG1, PHY_VITESSE_INIT10))
1381 return PHY_ERROR;
1382
1383 return 0;
1384}
1385
Linus Torvalds1da177e2005-04-16 15:20:36 -07001386static int phy_init(struct net_device *dev)
1387{
1388 struct fe_priv *np = get_nvpriv(dev);
1389 u8 __iomem *base = get_hwbase(dev);
Joe Perchescd663282010-11-29 07:41:59 +00001390 u32 phyinterface;
1391 u32 mii_status, mii_control, mii_control_1000, reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001392
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001393 /* phy errata for E3016 phy */
1394 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
1395 reg = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
1396 reg &= ~PHY_MARVELL_E3016_INITMASK;
1397 if (mii_rw(dev, np->phyaddr, MII_NCONFIG, reg)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001398 netdev_info(dev, "%s: phy write to errata reg failed\n",
1399 pci_name(np->pci_dev));
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001400 return PHY_ERROR;
1401 }
1402 }
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -04001403 if (np->phy_oui == PHY_OUI_REALTEK) {
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001404 if (np->phy_model == PHY_MODEL_REALTEK_8211 &&
1405 np->phy_rev == PHY_REV_REALTEK_8211B) {
Joe Perchescd663282010-11-29 07:41:59 +00001406 if (init_realtek_8211b(dev, np)) {
1407 netdev_info(dev, "%s: phy init failed\n",
1408 pci_name(np->pci_dev));
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001409 return PHY_ERROR;
Joe Perchescd663282010-11-29 07:41:59 +00001410 }
Joe Perchesc41d41e2010-11-29 07:41:58 +00001411 } else if (np->phy_model == PHY_MODEL_REALTEK_8211 &&
1412 np->phy_rev == PHY_REV_REALTEK_8211C) {
Joe Perchescd663282010-11-29 07:41:59 +00001413 if (init_realtek_8211c(dev, np)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001414 netdev_info(dev, "%s: phy init failed\n",
1415 pci_name(np->pci_dev));
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -04001416 return PHY_ERROR;
1417 }
Joe Perchescd663282010-11-29 07:41:59 +00001418 } else if (np->phy_model == PHY_MODEL_REALTEK_8201) {
1419 if (init_realtek_8201(dev, np)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001420 netdev_info(dev, "%s: phy init failed\n",
1421 pci_name(np->pci_dev));
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -04001422 return PHY_ERROR;
1423 }
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -04001424 }
1425 }
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001426
Linus Torvalds1da177e2005-04-16 15:20:36 -07001427 /* set advertise register */
1428 reg = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Joe Perchescd663282010-11-29 07:41:59 +00001429 reg |= (ADVERTISE_10HALF | ADVERTISE_10FULL |
1430 ADVERTISE_100HALF | ADVERTISE_100FULL |
1431 ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001432 if (mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001433 netdev_info(dev, "%s: phy write to advertise failed\n",
1434 pci_name(np->pci_dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001435 return PHY_ERROR;
1436 }
1437
1438 /* get phy interface type */
1439 phyinterface = readl(base + NvRegPhyInterface);
1440
1441 /* see if gigabit phy */
1442 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
1443 if (mii_status & PHY_GIGABIT) {
1444 np->gigabit = PHY_GIGABIT;
Joe Perchescd663282010-11-29 07:41:59 +00001445 mii_control_1000 = mii_rw(dev, np->phyaddr,
1446 MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001447 mii_control_1000 &= ~ADVERTISE_1000HALF;
1448 if (phyinterface & PHY_RGMII)
1449 mii_control_1000 |= ADVERTISE_1000FULL;
1450 else
1451 mii_control_1000 &= ~ADVERTISE_1000FULL;
1452
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001453 if (mii_rw(dev, np->phyaddr, MII_CTRL1000, mii_control_1000)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001454 netdev_info(dev, "%s: phy init failed\n",
1455 pci_name(np->pci_dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456 return PHY_ERROR;
1457 }
Szymon Janc78aea4f2010-11-27 08:39:43 +00001458 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001459 np->gigabit = 0;
1460
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001461 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1462 mii_control |= BMCR_ANENABLE;
1463
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -04001464 if (np->phy_oui == PHY_OUI_REALTEK &&
1465 np->phy_model == PHY_MODEL_REALTEK_8211 &&
1466 np->phy_rev == PHY_REV_REALTEK_8211C) {
1467 /* start autoneg since we already performed hw reset above */
1468 mii_control |= BMCR_ANRESTART;
1469 if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001470 netdev_info(dev, "%s: phy init failed\n",
1471 pci_name(np->pci_dev));
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -04001472 return PHY_ERROR;
1473 }
1474 } else {
1475 /* reset the phy
1476 * (certain phys need bmcr to be setup with reset)
1477 */
1478 if (phy_reset(dev, mii_control)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001479 netdev_info(dev, "%s: phy reset failed\n",
1480 pci_name(np->pci_dev));
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -04001481 return PHY_ERROR;
1482 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001483 }
1484
1485 /* phy vendor specific configuration */
Joe Perchescd663282010-11-29 07:41:59 +00001486 if ((np->phy_oui == PHY_OUI_CICADA)) {
1487 if (init_cicada(dev, np, phyinterface)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001488 netdev_info(dev, "%s: phy init failed\n",
1489 pci_name(np->pci_dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001490 return PHY_ERROR;
1491 }
Joe Perchescd663282010-11-29 07:41:59 +00001492 } else if (np->phy_oui == PHY_OUI_VITESSE) {
1493 if (init_vitesse(dev, np)) {
Joe Perches1d397f32010-11-29 07:41:57 +00001494 netdev_info(dev, "%s: phy init failed\n",
1495 pci_name(np->pci_dev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496 return PHY_ERROR;
1497 }
Joe Perchescd663282010-11-29 07:41:59 +00001498 } else if (np->phy_oui == PHY_OUI_REALTEK) {
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001499 if (np->phy_model == PHY_MODEL_REALTEK_8211 &&
1500 np->phy_rev == PHY_REV_REALTEK_8211B) {
1501 /* reset could have cleared these out, set them back */
Joe Perchescd663282010-11-29 07:41:59 +00001502 if (init_realtek_8211b(dev, np)) {
1503 netdev_info(dev, "%s: phy init failed\n",
1504 pci_name(np->pci_dev));
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001505 return PHY_ERROR;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001506 }
Joe Perchescd663282010-11-29 07:41:59 +00001507 } else if (np->phy_model == PHY_MODEL_REALTEK_8201) {
1508 if (init_realtek_8201(dev, np) ||
1509 init_realtek_8201_cross(dev, np)) {
1510 netdev_info(dev, "%s: phy init failed\n",
1511 pci_name(np->pci_dev));
1512 return PHY_ERROR;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001513 }
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -04001514 }
1515 }
1516
Lucas De Marchi25985ed2011-03-30 22:57:33 -03001517 /* some phys clear out pause advertisement on reset, set it back */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001518 mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
Ed Swierkcb52deb2008-12-01 12:24:43 +00001520 /* restart auto negotiation, power down phy */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001521 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ed Swierk5a9a8e32009-06-02 00:19:52 -07001522 mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE);
Szymon Janc78aea4f2010-11-27 08:39:43 +00001523 if (phy_power_down)
Ed Swierk5a9a8e32009-06-02 00:19:52 -07001524 mii_control |= BMCR_PDOWN;
Szymon Janc78aea4f2010-11-27 08:39:43 +00001525 if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001526 return PHY_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527
1528 return 0;
1529}
1530
1531static void nv_start_rx(struct net_device *dev)
1532{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001533 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001535 u32 rx_ctrl = readl(base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537 /* Already running? Stop it. */
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001538 if ((readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) && !np->mac_in_use) {
1539 rx_ctrl &= ~NVREG_RCVCTL_START;
1540 writel(rx_ctrl, base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001541 pci_push(base);
1542 }
1543 writel(np->linkspeed, base + NvRegLinkSpeed);
1544 pci_push(base);
Szymon Janc78aea4f2010-11-27 08:39:43 +00001545 rx_ctrl |= NVREG_RCVCTL_START;
1546 if (np->mac_in_use)
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001547 rx_ctrl &= ~NVREG_RCVCTL_RX_PATH_EN;
1548 writel(rx_ctrl, base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001549 pci_push(base);
1550}
1551
1552static void nv_stop_rx(struct net_device *dev)
1553{
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001554 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001555 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001556 u32 rx_ctrl = readl(base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001557
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001558 if (!np->mac_in_use)
1559 rx_ctrl &= ~NVREG_RCVCTL_START;
1560 else
1561 rx_ctrl |= NVREG_RCVCTL_RX_PATH_EN;
1562 writel(rx_ctrl, base + NvRegReceiverControl);
Joe Perches344d0dc2010-11-29 07:41:52 +00001563 if (reg_delay(dev, NvRegReceiverStatus, NVREG_RCVSTAT_BUSY, 0,
1564 NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX))
Joe Perches1d397f32010-11-29 07:41:57 +00001565 netdev_info(dev, "%s: ReceiverStatus remained busy\n",
1566 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567
1568 udelay(NV_RXSTOP_DELAY2);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001569 if (!np->mac_in_use)
1570 writel(0, base + NvRegLinkSpeed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001571}
1572
1573static void nv_start_tx(struct net_device *dev)
1574{
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001575 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001577 u32 tx_ctrl = readl(base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001578
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001579 tx_ctrl |= NVREG_XMITCTL_START;
1580 if (np->mac_in_use)
1581 tx_ctrl &= ~NVREG_XMITCTL_TX_PATH_EN;
1582 writel(tx_ctrl, base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001583 pci_push(base);
1584}
1585
1586static void nv_stop_tx(struct net_device *dev)
1587{
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001588 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001590 u32 tx_ctrl = readl(base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001591
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001592 if (!np->mac_in_use)
1593 tx_ctrl &= ~NVREG_XMITCTL_START;
1594 else
1595 tx_ctrl |= NVREG_XMITCTL_TX_PATH_EN;
1596 writel(tx_ctrl, base + NvRegTransmitterControl);
Joe Perches344d0dc2010-11-29 07:41:52 +00001597 if (reg_delay(dev, NvRegTransmitterStatus, NVREG_XMITSTAT_BUSY, 0,
1598 NV_TXSTOP_DELAY1, NV_TXSTOP_DELAY1MAX))
Joe Perches1d397f32010-11-29 07:41:57 +00001599 netdev_info(dev, "%s: TransmitterStatus remained busy\n",
1600 __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601
1602 udelay(NV_TXSTOP_DELAY2);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001603 if (!np->mac_in_use)
1604 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV,
1605 base + NvRegTransmitPoll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001606}
1607
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001608static void nv_start_rxtx(struct net_device *dev)
1609{
1610 nv_start_rx(dev);
1611 nv_start_tx(dev);
1612}
1613
1614static void nv_stop_rxtx(struct net_device *dev)
1615{
1616 nv_stop_rx(dev);
1617 nv_stop_tx(dev);
1618}
1619
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620static void nv_txrx_reset(struct net_device *dev)
1621{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001622 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001623 u8 __iomem *base = get_hwbase(dev);
1624
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001625 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001626 pci_push(base);
1627 udelay(NV_TXRX_RESET_DELAY);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001628 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 pci_push(base);
1630}
1631
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001632static void nv_mac_reset(struct net_device *dev)
1633{
1634 struct fe_priv *np = netdev_priv(dev);
1635 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdulla4e84f9b2008-02-04 15:14:09 -05001636 u32 temp1, temp2, temp3;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001637
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001638 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
1639 pci_push(base);
Ayaz Abdulla4e84f9b2008-02-04 15:14:09 -05001640
1641 /* save registers since they will be cleared on reset */
1642 temp1 = readl(base + NvRegMacAddrA);
1643 temp2 = readl(base + NvRegMacAddrB);
1644 temp3 = readl(base + NvRegTransmitPoll);
1645
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001646 writel(NVREG_MAC_RESET_ASSERT, base + NvRegMacReset);
1647 pci_push(base);
1648 udelay(NV_MAC_RESET_DELAY);
1649 writel(0, base + NvRegMacReset);
1650 pci_push(base);
1651 udelay(NV_MAC_RESET_DELAY);
Ayaz Abdulla4e84f9b2008-02-04 15:14:09 -05001652
1653 /* restore saved registers */
1654 writel(temp1, base + NvRegMacAddrA);
1655 writel(temp2, base + NvRegMacAddrB);
1656 writel(temp3, base + NvRegTransmitPoll);
1657
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001658 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
1659 pci_push(base);
1660}
1661
david decotignyf5d827a2011-11-16 12:15:13 +00001662/* Caller must appropriately lock netdev_priv(dev)->hwstats_lock */
1663static void nv_update_stats(struct net_device *dev)
Ayaz Abdulla57fff692007-01-23 12:27:00 -05001664{
1665 struct fe_priv *np = netdev_priv(dev);
1666 u8 __iomem *base = get_hwbase(dev);
1667
david decotignyf5d827a2011-11-16 12:15:13 +00001668 /* If it happens that this is run in top-half context, then
1669 * replace the spin_lock of hwstats_lock with
1670 * spin_lock_irqsave() in calling functions. */
1671 WARN_ONCE(in_irq(), "forcedeth: estats spin_lock(_bh) from top-half");
1672 assert_spin_locked(&np->hwstats_lock);
1673
1674 /* query hardware */
Ayaz Abdulla57fff692007-01-23 12:27:00 -05001675 np->estats.tx_bytes += readl(base + NvRegTxCnt);
1676 np->estats.tx_zero_rexmt += readl(base + NvRegTxZeroReXmt);
1677 np->estats.tx_one_rexmt += readl(base + NvRegTxOneReXmt);
1678 np->estats.tx_many_rexmt += readl(base + NvRegTxManyReXmt);
1679 np->estats.tx_late_collision += readl(base + NvRegTxLateCol);
1680 np->estats.tx_fifo_errors += readl(base + NvRegTxUnderflow);
1681 np->estats.tx_carrier_errors += readl(base + NvRegTxLossCarrier);
1682 np->estats.tx_excess_deferral += readl(base + NvRegTxExcessDef);
1683 np->estats.tx_retry_error += readl(base + NvRegTxRetryErr);
1684 np->estats.rx_frame_error += readl(base + NvRegRxFrameErr);
1685 np->estats.rx_extra_byte += readl(base + NvRegRxExtraByte);
1686 np->estats.rx_late_collision += readl(base + NvRegRxLateCol);
1687 np->estats.rx_runt += readl(base + NvRegRxRunt);
1688 np->estats.rx_frame_too_long += readl(base + NvRegRxFrameTooLong);
1689 np->estats.rx_over_errors += readl(base + NvRegRxOverflow);
1690 np->estats.rx_crc_errors += readl(base + NvRegRxFCSErr);
1691 np->estats.rx_frame_align_error += readl(base + NvRegRxFrameAlignErr);
1692 np->estats.rx_length_error += readl(base + NvRegRxLenErr);
1693 np->estats.rx_unicast += readl(base + NvRegRxUnicast);
1694 np->estats.rx_multicast += readl(base + NvRegRxMulticast);
1695 np->estats.rx_broadcast += readl(base + NvRegRxBroadcast);
1696 np->estats.rx_packets =
1697 np->estats.rx_unicast +
1698 np->estats.rx_multicast +
1699 np->estats.rx_broadcast;
1700 np->estats.rx_errors_total =
1701 np->estats.rx_crc_errors +
1702 np->estats.rx_over_errors +
1703 np->estats.rx_frame_error +
1704 (np->estats.rx_frame_align_error - np->estats.rx_extra_byte) +
1705 np->estats.rx_late_collision +
1706 np->estats.rx_runt +
1707 np->estats.rx_frame_too_long;
1708 np->estats.tx_errors_total =
1709 np->estats.tx_late_collision +
1710 np->estats.tx_fifo_errors +
1711 np->estats.tx_carrier_errors +
1712 np->estats.tx_excess_deferral +
1713 np->estats.tx_retry_error;
1714
1715 if (np->driver_data & DEV_HAS_STATISTICS_V2) {
1716 np->estats.tx_deferral += readl(base + NvRegTxDef);
1717 np->estats.tx_packets += readl(base + NvRegTxFrame);
1718 np->estats.rx_bytes += readl(base + NvRegRxCnt);
1719 np->estats.tx_pause += readl(base + NvRegTxPause);
1720 np->estats.rx_pause += readl(base + NvRegRxPause);
1721 np->estats.rx_drop_frame += readl(base + NvRegRxDropFrame);
Mandeep Baines0bdfea82011-11-05 14:38:23 +00001722 np->estats.rx_errors_total += np->estats.rx_drop_frame;
Ayaz Abdulla57fff692007-01-23 12:27:00 -05001723 }
Ayaz Abdulla9c662432008-08-06 12:11:42 -04001724
1725 if (np->driver_data & DEV_HAS_STATISTICS_V3) {
1726 np->estats.tx_unicast += readl(base + NvRegTxUnicast);
1727 np->estats.tx_multicast += readl(base + NvRegTxMulticast);
1728 np->estats.tx_broadcast += readl(base + NvRegTxBroadcast);
1729 }
Ayaz Abdulla57fff692007-01-23 12:27:00 -05001730}
1731
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732/*
david decotignyf5d827a2011-11-16 12:15:13 +00001733 * nv_get_stats64: dev->ndo_get_stats64 function
Linus Torvalds1da177e2005-04-16 15:20:36 -07001734 * Get latest stats value from the nic.
1735 * Called with read_lock(&dev_base_lock) held for read -
1736 * only synchronized against unregister_netdevice.
1737 */
david decotignyf5d827a2011-11-16 12:15:13 +00001738static struct rtnl_link_stats64*
1739nv_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *storage)
1740 __acquires(&netdev_priv(dev)->hwstats_lock)
1741 __releases(&netdev_priv(dev)->hwstats_lock)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001742{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001743 struct fe_priv *np = netdev_priv(dev);
david decotignyf5d827a2011-11-16 12:15:13 +00001744 unsigned int syncp_start;
1745
1746 /*
1747 * Note: because HW stats are not always available and for
1748 * consistency reasons, the following ifconfig stats are
1749 * managed by software: rx_bytes, tx_bytes, rx_packets and
1750 * tx_packets. The related hardware stats reported by ethtool
1751 * should be equivalent to these ifconfig stats, with 4
1752 * additional bytes per packet (Ethernet FCS CRC), except for
1753 * tx_packets when TSO kicks in.
1754 */
1755
1756 /* software stats */
1757 do {
david decotigny505a4672011-11-17 09:38:23 +00001758 syncp_start = u64_stats_fetch_begin_bh(&np->swstats_rx_syncp);
david decotignyf5d827a2011-11-16 12:15:13 +00001759 storage->rx_packets = np->stat_rx_packets;
1760 storage->rx_bytes = np->stat_rx_bytes;
david decotigny0a1f2222011-11-16 12:15:14 +00001761 storage->rx_dropped = np->stat_rx_dropped;
david decotignyf5d827a2011-11-16 12:15:13 +00001762 storage->rx_missed_errors = np->stat_rx_missed_errors;
david decotigny505a4672011-11-17 09:38:23 +00001763 } while (u64_stats_fetch_retry_bh(&np->swstats_rx_syncp, syncp_start));
david decotignyf5d827a2011-11-16 12:15:13 +00001764
1765 do {
david decotigny505a4672011-11-17 09:38:23 +00001766 syncp_start = u64_stats_fetch_begin_bh(&np->swstats_tx_syncp);
david decotignyf5d827a2011-11-16 12:15:13 +00001767 storage->tx_packets = np->stat_tx_packets;
1768 storage->tx_bytes = np->stat_tx_bytes;
1769 storage->tx_dropped = np->stat_tx_dropped;
david decotigny505a4672011-11-17 09:38:23 +00001770 } while (u64_stats_fetch_retry_bh(&np->swstats_tx_syncp, syncp_start));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001771
Ayaz Abdulla21828162007-01-23 12:27:21 -05001772 /* If the nic supports hw counters then retrieve latest values */
david decotignyf5d827a2011-11-16 12:15:13 +00001773 if (np->driver_data & DEV_HAS_STATISTICS_V123) {
1774 spin_lock_bh(&np->hwstats_lock);
Ayaz Abdulla21828162007-01-23 12:27:21 -05001775
david decotignyf5d827a2011-11-16 12:15:13 +00001776 nv_update_stats(dev);
david decotigny674aee32011-11-16 12:15:07 +00001777
david decotignyf5d827a2011-11-16 12:15:13 +00001778 /* generic stats */
1779 storage->rx_errors = np->estats.rx_errors_total;
1780 storage->tx_errors = np->estats.tx_errors_total;
1781
1782 /* meaningful only when NIC supports stats v3 */
1783 storage->multicast = np->estats.rx_multicast;
1784
1785 /* detailed rx_errors */
1786 storage->rx_length_errors = np->estats.rx_length_error;
1787 storage->rx_over_errors = np->estats.rx_over_errors;
1788 storage->rx_crc_errors = np->estats.rx_crc_errors;
1789 storage->rx_frame_errors = np->estats.rx_frame_align_error;
1790 storage->rx_fifo_errors = np->estats.rx_drop_frame;
1791
1792 /* detailed tx_errors */
1793 storage->tx_carrier_errors = np->estats.tx_carrier_errors;
1794 storage->tx_fifo_errors = np->estats.tx_fifo_errors;
1795
1796 spin_unlock_bh(&np->hwstats_lock);
Ayaz Abdulla21828162007-01-23 12:27:21 -05001797 }
Jeff Garzik8148ff42007-10-16 20:56:09 -04001798
david decotignyf5d827a2011-11-16 12:15:13 +00001799 return storage;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001800}
1801
1802/*
1803 * nv_alloc_rx: fill rx ring entries.
1804 * Return 1 if the allocations for the skbs failed and the
1805 * rx engine is without Available descriptors
1806 */
1807static int nv_alloc_rx(struct net_device *dev)
1808{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001809 struct fe_priv *np = netdev_priv(dev);
Szymon Janc78aea4f2010-11-27 08:39:43 +00001810 struct ring_desc *less_rx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001812 less_rx = np->get_rx.orig;
1813 if (less_rx-- == np->first_rx.orig)
1814 less_rx = np->last_rx.orig;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001815
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001816 while (np->put_rx.orig != less_rx) {
Pradeep A. Dalvidae2e9f2012-02-06 11:16:13 +00001817 struct sk_buff *skb = netdev_alloc_skb(dev, np->rx_buf_sz + NV_RX_ALLOC_PAD);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001818 if (skb) {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001819 np->put_rx_ctx->skb = skb;
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001820 np->put_rx_ctx->dma = pci_map_single(np->pci_dev,
1821 skb->data,
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001822 skb_tailroom(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001823 PCI_DMA_FROMDEVICE);
Larry Finger612a7c42012-12-27 17:25:41 +00001824 if (pci_dma_mapping_error(np->pci_dev,
1825 np->put_rx_ctx->dma)) {
1826 kfree_skb(skb);
1827 goto packet_dropped;
1828 }
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001829 np->put_rx_ctx->dma_len = skb_tailroom(skb);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001830 np->put_rx.orig->buf = cpu_to_le32(np->put_rx_ctx->dma);
1831 wmb();
1832 np->put_rx.orig->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX_AVAIL);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001833 if (unlikely(np->put_rx.orig++ == np->last_rx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001834 np->put_rx.orig = np->first_rx.orig;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001835 if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001836 np->put_rx_ctx = np->first_rx_ctx;
david decotigny0a1f2222011-11-16 12:15:14 +00001837 } else {
Larry Finger612a7c42012-12-27 17:25:41 +00001838packet_dropped:
david decotigny0a1f2222011-11-16 12:15:14 +00001839 u64_stats_update_begin(&np->swstats_rx_syncp);
1840 np->stat_rx_dropped++;
1841 u64_stats_update_end(&np->swstats_rx_syncp);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001842 return 1;
david decotigny0a1f2222011-11-16 12:15:14 +00001843 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001844 }
1845 return 0;
1846}
1847
1848static int nv_alloc_rx_optimized(struct net_device *dev)
1849{
1850 struct fe_priv *np = netdev_priv(dev);
Szymon Janc78aea4f2010-11-27 08:39:43 +00001851 struct ring_desc_ex *less_rx;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001852
1853 less_rx = np->get_rx.ex;
1854 if (less_rx-- == np->first_rx.ex)
1855 less_rx = np->last_rx.ex;
1856
1857 while (np->put_rx.ex != less_rx) {
Pradeep A. Dalvidae2e9f2012-02-06 11:16:13 +00001858 struct sk_buff *skb = netdev_alloc_skb(dev, np->rx_buf_sz + NV_RX_ALLOC_PAD);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001859 if (skb) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001860 np->put_rx_ctx->skb = skb;
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001861 np->put_rx_ctx->dma = pci_map_single(np->pci_dev,
1862 skb->data,
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001863 skb_tailroom(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001864 PCI_DMA_FROMDEVICE);
Larry Finger612a7c42012-12-27 17:25:41 +00001865 if (pci_dma_mapping_error(np->pci_dev,
1866 np->put_rx_ctx->dma)) {
1867 kfree_skb(skb);
1868 goto packet_dropped;
1869 }
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001870 np->put_rx_ctx->dma_len = skb_tailroom(skb);
Al Viro5bb7ea22007-12-09 16:06:41 +00001871 np->put_rx.ex->bufhigh = cpu_to_le32(dma_high(np->put_rx_ctx->dma));
1872 np->put_rx.ex->buflow = cpu_to_le32(dma_low(np->put_rx_ctx->dma));
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001873 wmb();
1874 np->put_rx.ex->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX2_AVAIL);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001875 if (unlikely(np->put_rx.ex++ == np->last_rx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001876 np->put_rx.ex = np->first_rx.ex;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001877 if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001878 np->put_rx_ctx = np->first_rx_ctx;
david decotigny0a1f2222011-11-16 12:15:14 +00001879 } else {
Larry Finger612a7c42012-12-27 17:25:41 +00001880packet_dropped:
david decotigny0a1f2222011-11-16 12:15:14 +00001881 u64_stats_update_begin(&np->swstats_rx_syncp);
1882 np->stat_rx_dropped++;
1883 u64_stats_update_end(&np->swstats_rx_syncp);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001884 return 1;
david decotigny0a1f2222011-11-16 12:15:14 +00001885 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001887 return 0;
1888}
1889
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001890/* If rx bufs are exhausted called after 50ms to attempt to refresh */
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001891static void nv_do_rx_refill(unsigned long data)
1892{
1893 struct net_device *dev = (struct net_device *) data;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001894 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001895
1896 /* Just reschedule NAPI rx processing */
Ben Hutchings288379f2009-01-19 16:43:59 -08001897 napi_schedule(&np->napi);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001898}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001899
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001900static void nv_init_rx(struct net_device *dev)
Manfred Sprauld81c0982005-07-31 18:20:30 +02001901{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001902 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02001903 int i;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001904
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001905 np->get_rx = np->put_rx = np->first_rx = np->rx_ring;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001906
1907 if (!nv_optimized(np))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001908 np->last_rx.orig = &np->rx_ring.orig[np->rx_ring_size-1];
1909 else
1910 np->last_rx.ex = &np->rx_ring.ex[np->rx_ring_size-1];
1911 np->get_rx_ctx = np->put_rx_ctx = np->first_rx_ctx = np->rx_skb;
1912 np->last_rx_ctx = &np->rx_skb[np->rx_ring_size-1];
Manfred Sprauld81c0982005-07-31 18:20:30 +02001913
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001914 for (i = 0; i < np->rx_ring_size; i++) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001915 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001916 np->rx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001917 np->rx_ring.orig[i].buf = 0;
1918 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001919 np->rx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001920 np->rx_ring.ex[i].txvlan = 0;
1921 np->rx_ring.ex[i].bufhigh = 0;
1922 np->rx_ring.ex[i].buflow = 0;
1923 }
1924 np->rx_skb[i].skb = NULL;
1925 np->rx_skb[i].dma = 0;
1926 }
Manfred Sprauld81c0982005-07-31 18:20:30 +02001927}
1928
1929static void nv_init_tx(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001930{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001931 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932 int i;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001933
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001934 np->get_tx = np->put_tx = np->first_tx = np->tx_ring;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001935
1936 if (!nv_optimized(np))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001937 np->last_tx.orig = &np->tx_ring.orig[np->tx_ring_size-1];
1938 else
1939 np->last_tx.ex = &np->tx_ring.ex[np->tx_ring_size-1];
1940 np->get_tx_ctx = np->put_tx_ctx = np->first_tx_ctx = np->tx_skb;
1941 np->last_tx_ctx = &np->tx_skb[np->tx_ring_size-1];
Tom Herbertb8bfca92011-11-28 16:33:23 +00001942 netdev_reset_queue(np->dev);
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001943 np->tx_pkts_in_progress = 0;
1944 np->tx_change_owner = NULL;
1945 np->tx_end_flip = NULL;
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00001946 np->tx_stop = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001948 for (i = 0; i < np->tx_ring_size; i++) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001949 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001950 np->tx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001951 np->tx_ring.orig[i].buf = 0;
1952 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001953 np->tx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001954 np->tx_ring.ex[i].txvlan = 0;
1955 np->tx_ring.ex[i].bufhigh = 0;
1956 np->tx_ring.ex[i].buflow = 0;
1957 }
1958 np->tx_skb[i].skb = NULL;
1959 np->tx_skb[i].dma = 0;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001960 np->tx_skb[i].dma_len = 0;
Eric Dumazet73a37072009-06-17 21:17:59 +00001961 np->tx_skb[i].dma_single = 0;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001962 np->tx_skb[i].first_tx_desc = NULL;
1963 np->tx_skb[i].next_tx_ctx = NULL;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001964 }
Manfred Sprauld81c0982005-07-31 18:20:30 +02001965}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966
Manfred Sprauld81c0982005-07-31 18:20:30 +02001967static int nv_init_ring(struct net_device *dev)
1968{
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001969 struct fe_priv *np = netdev_priv(dev);
1970
Manfred Sprauld81c0982005-07-31 18:20:30 +02001971 nv_init_tx(dev);
1972 nv_init_rx(dev);
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001973
1974 if (!nv_optimized(np))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001975 return nv_alloc_rx(dev);
1976 else
1977 return nv_alloc_rx_optimized(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001978}
1979
Eric Dumazet73a37072009-06-17 21:17:59 +00001980static void nv_unmap_txskb(struct fe_priv *np, struct nv_skb_map *tx_skb)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001981{
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001982 if (tx_skb->dma) {
Eric Dumazet73a37072009-06-17 21:17:59 +00001983 if (tx_skb->dma_single)
1984 pci_unmap_single(np->pci_dev, tx_skb->dma,
1985 tx_skb->dma_len,
1986 PCI_DMA_TODEVICE);
1987 else
1988 pci_unmap_page(np->pci_dev, tx_skb->dma,
1989 tx_skb->dma_len,
1990 PCI_DMA_TODEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001991 tx_skb->dma = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001992 }
Eric Dumazet73a37072009-06-17 21:17:59 +00001993}
1994
1995static int nv_release_txskb(struct fe_priv *np, struct nv_skb_map *tx_skb)
1996{
1997 nv_unmap_txskb(np, tx_skb);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001998 if (tx_skb->skb) {
1999 dev_kfree_skb_any(tx_skb->skb);
2000 tx_skb->skb = NULL;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002001 return 1;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002002 }
Eric Dumazet73a37072009-06-17 21:17:59 +00002003 return 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002004}
2005
Linus Torvalds1da177e2005-04-16 15:20:36 -07002006static void nv_drain_tx(struct net_device *dev)
2007{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002008 struct fe_priv *np = netdev_priv(dev);
2009 unsigned int i;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002010
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04002011 for (i = 0; i < np->tx_ring_size; i++) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002012 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002013 np->tx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002014 np->tx_ring.orig[i].buf = 0;
2015 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002016 np->tx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002017 np->tx_ring.ex[i].txvlan = 0;
2018 np->tx_ring.ex[i].bufhigh = 0;
2019 np->tx_ring.ex[i].buflow = 0;
2020 }
david decotignyf5d827a2011-11-16 12:15:13 +00002021 if (nv_release_txskb(np, &np->tx_skb[i])) {
2022 u64_stats_update_begin(&np->swstats_tx_syncp);
2023 np->stat_tx_dropped++;
2024 u64_stats_update_end(&np->swstats_tx_syncp);
2025 }
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002026 np->tx_skb[i].dma = 0;
2027 np->tx_skb[i].dma_len = 0;
Eric Dumazet73a37072009-06-17 21:17:59 +00002028 np->tx_skb[i].dma_single = 0;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002029 np->tx_skb[i].first_tx_desc = NULL;
2030 np->tx_skb[i].next_tx_ctx = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031 }
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002032 np->tx_pkts_in_progress = 0;
2033 np->tx_change_owner = NULL;
2034 np->tx_end_flip = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035}
2036
2037static void nv_drain_rx(struct net_device *dev)
2038{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002039 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002040 int i;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002041
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04002042 for (i = 0; i < np->rx_ring_size; i++) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002043 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002044 np->rx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002045 np->rx_ring.orig[i].buf = 0;
2046 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002047 np->rx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002048 np->rx_ring.ex[i].txvlan = 0;
2049 np->rx_ring.ex[i].bufhigh = 0;
2050 np->rx_ring.ex[i].buflow = 0;
2051 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052 wmb();
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002053 if (np->rx_skb[i].skb) {
2054 pci_unmap_single(np->pci_dev, np->rx_skb[i].dma,
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07002055 (skb_end_pointer(np->rx_skb[i].skb) -
2056 np->rx_skb[i].skb->data),
2057 PCI_DMA_FROMDEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002058 dev_kfree_skb(np->rx_skb[i].skb);
2059 np->rx_skb[i].skb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060 }
2061 }
2062}
2063
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002064static void nv_drain_rxtx(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065{
2066 nv_drain_tx(dev);
2067 nv_drain_rx(dev);
2068}
2069
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002070static inline u32 nv_get_empty_tx_slots(struct fe_priv *np)
2071{
2072 return (u32)(np->tx_ring_size - ((np->tx_ring_size + (np->put_tx_ctx - np->get_tx_ctx)) % np->tx_ring_size));
2073}
2074
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002075static void nv_legacybackoff_reseed(struct net_device *dev)
2076{
2077 u8 __iomem *base = get_hwbase(dev);
2078 u32 reg;
2079 u32 low;
2080 int tx_status = 0;
2081
2082 reg = readl(base + NvRegSlotTime) & ~NVREG_SLOTTIME_MASK;
2083 get_random_bytes(&low, sizeof(low));
2084 reg |= low & NVREG_SLOTTIME_MASK;
2085
2086 /* Need to stop tx before change takes effect.
2087 * Caller has already gained np->lock.
2088 */
2089 tx_status = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_START;
2090 if (tx_status)
2091 nv_stop_tx(dev);
2092 nv_stop_rx(dev);
2093 writel(reg, base + NvRegSlotTime);
2094 if (tx_status)
2095 nv_start_tx(dev);
2096 nv_start_rx(dev);
2097}
2098
2099/* Gear Backoff Seeds */
2100#define BACKOFF_SEEDSET_ROWS 8
2101#define BACKOFF_SEEDSET_LFSRS 15
2102
2103/* Known Good seed sets */
2104static const u32 main_seedset[BACKOFF_SEEDSET_ROWS][BACKOFF_SEEDSET_LFSRS] = {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002105 {145, 155, 165, 175, 185, 196, 235, 245, 255, 265, 275, 285, 660, 690, 874},
2106 {245, 255, 265, 575, 385, 298, 335, 345, 355, 366, 375, 385, 761, 790, 974},
2107 {145, 155, 165, 175, 185, 196, 235, 245, 255, 265, 275, 285, 660, 690, 874},
2108 {245, 255, 265, 575, 385, 298, 335, 345, 355, 366, 375, 386, 761, 790, 974},
2109 {266, 265, 276, 585, 397, 208, 345, 355, 365, 376, 385, 396, 771, 700, 984},
2110 {266, 265, 276, 586, 397, 208, 346, 355, 365, 376, 285, 396, 771, 700, 984},
2111 {366, 365, 376, 686, 497, 308, 447, 455, 466, 476, 485, 496, 871, 800, 84},
2112 {466, 465, 476, 786, 597, 408, 547, 555, 566, 576, 585, 597, 971, 900, 184} };
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002113
2114static const u32 gear_seedset[BACKOFF_SEEDSET_ROWS][BACKOFF_SEEDSET_LFSRS] = {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002115 {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
2116 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
2117 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 397},
2118 {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
2119 {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
2120 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
2121 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
2122 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395} };
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002123
2124static void nv_gear_backoff_reseed(struct net_device *dev)
2125{
2126 u8 __iomem *base = get_hwbase(dev);
2127 u32 miniseed1, miniseed2, miniseed2_reversed, miniseed3, miniseed3_reversed;
2128 u32 temp, seedset, combinedSeed;
2129 int i;
2130
2131 /* Setup seed for free running LFSR */
2132 /* We are going to read the time stamp counter 3 times
2133 and swizzle bits around to increase randomness */
2134 get_random_bytes(&miniseed1, sizeof(miniseed1));
2135 miniseed1 &= 0x0fff;
2136 if (miniseed1 == 0)
2137 miniseed1 = 0xabc;
2138
2139 get_random_bytes(&miniseed2, sizeof(miniseed2));
2140 miniseed2 &= 0x0fff;
2141 if (miniseed2 == 0)
2142 miniseed2 = 0xabc;
2143 miniseed2_reversed =
2144 ((miniseed2 & 0xF00) >> 8) |
2145 (miniseed2 & 0x0F0) |
2146 ((miniseed2 & 0x00F) << 8);
2147
2148 get_random_bytes(&miniseed3, sizeof(miniseed3));
2149 miniseed3 &= 0x0fff;
2150 if (miniseed3 == 0)
2151 miniseed3 = 0xabc;
2152 miniseed3_reversed =
2153 ((miniseed3 & 0xF00) >> 8) |
2154 (miniseed3 & 0x0F0) |
2155 ((miniseed3 & 0x00F) << 8);
2156
2157 combinedSeed = ((miniseed1 ^ miniseed2_reversed) << 12) |
2158 (miniseed2 ^ miniseed3_reversed);
2159
2160 /* Seeds can not be zero */
2161 if ((combinedSeed & NVREG_BKOFFCTRL_SEED_MASK) == 0)
2162 combinedSeed |= 0x08;
2163 if ((combinedSeed & (NVREG_BKOFFCTRL_SEED_MASK << NVREG_BKOFFCTRL_GEAR)) == 0)
2164 combinedSeed |= 0x8000;
2165
2166 /* No need to disable tx here */
2167 temp = NVREG_BKOFFCTRL_DEFAULT | (0 << NVREG_BKOFFCTRL_SELECT);
2168 temp |= combinedSeed & NVREG_BKOFFCTRL_SEED_MASK;
2169 temp |= combinedSeed >> NVREG_BKOFFCTRL_GEAR;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002170 writel(temp, base + NvRegBackOffControl);
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002171
Szymon Janc78aea4f2010-11-27 08:39:43 +00002172 /* Setup seeds for all gear LFSRs. */
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002173 get_random_bytes(&seedset, sizeof(seedset));
2174 seedset = seedset % BACKOFF_SEEDSET_ROWS;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002175 for (i = 1; i <= BACKOFF_SEEDSET_LFSRS; i++) {
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002176 temp = NVREG_BKOFFCTRL_DEFAULT | (i << NVREG_BKOFFCTRL_SELECT);
2177 temp |= main_seedset[seedset][i-1] & 0x3ff;
2178 temp |= ((gear_seedset[seedset][i-1] & 0x3ff) << NVREG_BKOFFCTRL_GEAR);
2179 writel(temp, base + NvRegBackOffControl);
2180 }
2181}
2182
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183/*
2184 * nv_start_xmit: dev->hard_start_xmit function
Herbert Xu932ff272006-06-09 12:20:56 -07002185 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002186 */
Stephen Hemminger613573252009-08-31 19:50:58 +00002187static netdev_tx_t nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002188{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002189 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002190 u32 tx_flags = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002191 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
2192 unsigned int fragments = skb_shinfo(skb)->nr_frags;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002193 unsigned int i;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002194 u32 offset = 0;
2195 u32 bcnt;
Eric Dumazete743d312010-04-14 15:59:40 -07002196 u32 size = skb_headlen(skb);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002197 u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002198 u32 empty_slots;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002199 struct ring_desc *put_tx;
2200 struct ring_desc *start_tx;
2201 struct ring_desc *prev_tx;
2202 struct nv_skb_map *prev_tx_ctx;
Neil Hormanf7f22872013-04-01 04:31:58 +00002203 struct nv_skb_map *tmp_tx_ctx = NULL, *start_tx_ctx = NULL;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002204 unsigned long flags;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002205
2206 /* add fragments to entries count */
2207 for (i = 0; i < fragments; i++) {
david decotignye45a6182011-11-05 14:38:24 +00002208 u32 frag_size = skb_frag_size(&skb_shinfo(skb)->frags[i]);
Eric Dumazet9e903e02011-10-18 21:00:24 +00002209
david decotignye45a6182011-11-05 14:38:24 +00002210 entries += (frag_size >> NV_TX2_TSO_MAX_SHIFT) +
2211 ((frag_size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002212 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002213
Ayaz Abdulla001eb842009-01-09 11:03:44 +00002214 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002215 empty_slots = nv_get_empty_tx_slots(np);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002216 if (unlikely(empty_slots <= entries)) {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002217 netif_stop_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002218 np->tx_stop = 1;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002219 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002220 return NETDEV_TX_BUSY;
2221 }
Ayaz Abdulla001eb842009-01-09 11:03:44 +00002222 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002223
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002224 start_tx = put_tx = np->put_tx.orig;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002225
Ayaz Abdullafa454592006-01-05 22:45:45 -08002226 /* setup the header buffer */
2227 do {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002228 prev_tx = put_tx;
2229 prev_tx_ctx = np->put_tx_ctx;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002230 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002231 np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
Ayaz Abdullafa454592006-01-05 22:45:45 -08002232 PCI_DMA_TODEVICE);
Larry Finger612a7c42012-12-27 17:25:41 +00002233 if (pci_dma_mapping_error(np->pci_dev,
2234 np->put_tx_ctx->dma)) {
2235 /* on DMA mapping error - drop the packet */
2236 kfree_skb(skb);
2237 u64_stats_update_begin(&np->swstats_tx_syncp);
2238 np->stat_tx_dropped++;
2239 u64_stats_update_end(&np->swstats_tx_syncp);
2240 return NETDEV_TX_OK;
2241 }
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002242 np->put_tx_ctx->dma_len = bcnt;
Eric Dumazet73a37072009-06-17 21:17:59 +00002243 np->put_tx_ctx->dma_single = 1;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002244 put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
2245 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002246
Ayaz Abdullafa454592006-01-05 22:45:45 -08002247 tx_flags = np->tx_flags;
2248 offset += bcnt;
2249 size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002250 if (unlikely(put_tx++ == np->last_tx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002251 put_tx = np->first_tx.orig;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002252 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002253 np->put_tx_ctx = np->first_tx_ctx;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002254 } while (size);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002255
2256 /* setup the fragments */
2257 for (i = 0; i < fragments; i++) {
Eric Dumazet9e903e02011-10-18 21:00:24 +00002258 const skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
david decotignye45a6182011-11-05 14:38:24 +00002259 u32 frag_size = skb_frag_size(frag);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002260 offset = 0;
2261
2262 do {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002263 prev_tx = put_tx;
2264 prev_tx_ctx = np->put_tx_ctx;
Neil Hormanf7f22872013-04-01 04:31:58 +00002265 if (!start_tx_ctx)
2266 start_tx_ctx = tmp_tx_ctx = np->put_tx_ctx;
2267
david decotignye45a6182011-11-05 14:38:24 +00002268 bcnt = (frag_size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : frag_size;
Ian Campbell671173c2011-08-29 23:18:28 +00002269 np->put_tx_ctx->dma = skb_frag_dma_map(
2270 &np->pci_dev->dev,
2271 frag, offset,
2272 bcnt,
Ian Campbell5d6bcdf2011-10-06 11:10:48 +01002273 DMA_TO_DEVICE);
Neil Hormanf7f22872013-04-01 04:31:58 +00002274 if (dma_mapping_error(&np->pci_dev->dev, np->put_tx_ctx->dma)) {
2275
2276 /* Unwind the mapped fragments */
2277 do {
2278 nv_unmap_txskb(np, start_tx_ctx);
2279 if (unlikely(tmp_tx_ctx++ == np->last_tx_ctx))
2280 tmp_tx_ctx = np->first_tx_ctx;
2281 } while (tmp_tx_ctx != np->put_tx_ctx);
2282 kfree_skb(skb);
2283 np->put_tx_ctx = start_tx_ctx;
2284 u64_stats_update_begin(&np->swstats_tx_syncp);
2285 np->stat_tx_dropped++;
2286 u64_stats_update_end(&np->swstats_tx_syncp);
2287 return NETDEV_TX_OK;
2288 }
2289
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002290 np->put_tx_ctx->dma_len = bcnt;
Eric Dumazet73a37072009-06-17 21:17:59 +00002291 np->put_tx_ctx->dma_single = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002292 put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
2293 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002294
Ayaz Abdullafa454592006-01-05 22:45:45 -08002295 offset += bcnt;
david decotignye45a6182011-11-05 14:38:24 +00002296 frag_size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002297 if (unlikely(put_tx++ == np->last_tx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002298 put_tx = np->first_tx.orig;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002299 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002300 np->put_tx_ctx = np->first_tx_ctx;
david decotignye45a6182011-11-05 14:38:24 +00002301 } while (frag_size);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002302 }
2303
Ayaz Abdullafa454592006-01-05 22:45:45 -08002304 /* set last fragment flag */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002305 prev_tx->flaglen |= cpu_to_le32(tx_flags_extra);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002306
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002307 /* save skb in this slot's context area */
2308 prev_tx_ctx->skb = skb;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002309
Herbert Xu89114af2006-07-08 13:34:32 -07002310 if (skb_is_gso(skb))
Herbert Xu79671682006-06-22 02:40:14 -07002311 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
Manfred Spraulee733622005-07-31 18:32:26 +02002312 else
Arjan van de Ven1d39ed52006-12-12 14:06:23 +01002313 tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
Patrick McHardy84fa7932006-08-29 16:44:56 -07002314 NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002315
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002316 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla164a86e2007-01-09 13:30:10 -05002317
Ayaz Abdullafa454592006-01-05 22:45:45 -08002318 /* set tx flags */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002319 start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
Tom Herbertb8bfca92011-11-28 16:33:23 +00002320
2321 netdev_sent_queue(np->dev, skb->len);
2322
Willem de Bruijn49cbb1c2012-04-27 09:04:07 +00002323 skb_tx_timestamp(skb);
2324
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002325 np->put_tx.orig = put_tx;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002326
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002327 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002328
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002329 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002330 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002331}
2332
Stephen Hemminger613573252009-08-31 19:50:58 +00002333static netdev_tx_t nv_start_xmit_optimized(struct sk_buff *skb,
2334 struct net_device *dev)
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002335{
2336 struct fe_priv *np = netdev_priv(dev);
2337 u32 tx_flags = 0;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002338 u32 tx_flags_extra;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002339 unsigned int fragments = skb_shinfo(skb)->nr_frags;
2340 unsigned int i;
2341 u32 offset = 0;
2342 u32 bcnt;
Eric Dumazete743d312010-04-14 15:59:40 -07002343 u32 size = skb_headlen(skb);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002344 u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
2345 u32 empty_slots;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002346 struct ring_desc_ex *put_tx;
2347 struct ring_desc_ex *start_tx;
2348 struct ring_desc_ex *prev_tx;
2349 struct nv_skb_map *prev_tx_ctx;
Neil Hormanf7f22872013-04-01 04:31:58 +00002350 struct nv_skb_map *start_tx_ctx = NULL;
2351 struct nv_skb_map *tmp_tx_ctx = NULL;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002352 unsigned long flags;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002353
2354 /* add fragments to entries count */
2355 for (i = 0; i < fragments; i++) {
david decotignye45a6182011-11-05 14:38:24 +00002356 u32 frag_size = skb_frag_size(&skb_shinfo(skb)->frags[i]);
Eric Dumazet9e903e02011-10-18 21:00:24 +00002357
david decotignye45a6182011-11-05 14:38:24 +00002358 entries += (frag_size >> NV_TX2_TSO_MAX_SHIFT) +
2359 ((frag_size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002360 }
2361
Ayaz Abdulla001eb842009-01-09 11:03:44 +00002362 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002363 empty_slots = nv_get_empty_tx_slots(np);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002364 if (unlikely(empty_slots <= entries)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002365 netif_stop_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002366 np->tx_stop = 1;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002367 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002368 return NETDEV_TX_BUSY;
2369 }
Ayaz Abdulla001eb842009-01-09 11:03:44 +00002370 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002371
2372 start_tx = put_tx = np->put_tx.ex;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002373 start_tx_ctx = np->put_tx_ctx;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002374
2375 /* setup the header buffer */
2376 do {
2377 prev_tx = put_tx;
2378 prev_tx_ctx = np->put_tx_ctx;
2379 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
2380 np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
2381 PCI_DMA_TODEVICE);
Larry Finger612a7c42012-12-27 17:25:41 +00002382 if (pci_dma_mapping_error(np->pci_dev,
2383 np->put_tx_ctx->dma)) {
2384 /* on DMA mapping error - drop the packet */
2385 kfree_skb(skb);
2386 u64_stats_update_begin(&np->swstats_tx_syncp);
2387 np->stat_tx_dropped++;
2388 u64_stats_update_end(&np->swstats_tx_syncp);
2389 return NETDEV_TX_OK;
2390 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002391 np->put_tx_ctx->dma_len = bcnt;
Eric Dumazet73a37072009-06-17 21:17:59 +00002392 np->put_tx_ctx->dma_single = 1;
Al Viro5bb7ea22007-12-09 16:06:41 +00002393 put_tx->bufhigh = cpu_to_le32(dma_high(np->put_tx_ctx->dma));
2394 put_tx->buflow = cpu_to_le32(dma_low(np->put_tx_ctx->dma));
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002395 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002396
2397 tx_flags = NV_TX2_VALID;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002398 offset += bcnt;
2399 size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002400 if (unlikely(put_tx++ == np->last_tx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002401 put_tx = np->first_tx.ex;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002402 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002403 np->put_tx_ctx = np->first_tx_ctx;
2404 } while (size);
2405
2406 /* setup the fragments */
2407 for (i = 0; i < fragments; i++) {
2408 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
david decotignye45a6182011-11-05 14:38:24 +00002409 u32 frag_size = skb_frag_size(frag);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002410 offset = 0;
2411
2412 do {
2413 prev_tx = put_tx;
2414 prev_tx_ctx = np->put_tx_ctx;
david decotignye45a6182011-11-05 14:38:24 +00002415 bcnt = (frag_size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : frag_size;
Neil Hormanf7f22872013-04-01 04:31:58 +00002416 if (!start_tx_ctx)
2417 start_tx_ctx = tmp_tx_ctx = np->put_tx_ctx;
Ian Campbell671173c2011-08-29 23:18:28 +00002418 np->put_tx_ctx->dma = skb_frag_dma_map(
2419 &np->pci_dev->dev,
2420 frag, offset,
2421 bcnt,
Ian Campbell5d6bcdf2011-10-06 11:10:48 +01002422 DMA_TO_DEVICE);
Neil Hormanf7f22872013-04-01 04:31:58 +00002423
2424 if (dma_mapping_error(&np->pci_dev->dev, np->put_tx_ctx->dma)) {
2425
2426 /* Unwind the mapped fragments */
2427 do {
2428 nv_unmap_txskb(np, start_tx_ctx);
2429 if (unlikely(tmp_tx_ctx++ == np->last_tx_ctx))
2430 tmp_tx_ctx = np->first_tx_ctx;
2431 } while (tmp_tx_ctx != np->put_tx_ctx);
2432 kfree_skb(skb);
2433 np->put_tx_ctx = start_tx_ctx;
2434 u64_stats_update_begin(&np->swstats_tx_syncp);
2435 np->stat_tx_dropped++;
2436 u64_stats_update_end(&np->swstats_tx_syncp);
2437 return NETDEV_TX_OK;
2438 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002439 np->put_tx_ctx->dma_len = bcnt;
Eric Dumazet73a37072009-06-17 21:17:59 +00002440 np->put_tx_ctx->dma_single = 0;
Al Viro5bb7ea22007-12-09 16:06:41 +00002441 put_tx->bufhigh = cpu_to_le32(dma_high(np->put_tx_ctx->dma));
2442 put_tx->buflow = cpu_to_le32(dma_low(np->put_tx_ctx->dma));
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002443 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002444
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002445 offset += bcnt;
david decotignye45a6182011-11-05 14:38:24 +00002446 frag_size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002447 if (unlikely(put_tx++ == np->last_tx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002448 put_tx = np->first_tx.ex;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002449 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002450 np->put_tx_ctx = np->first_tx_ctx;
david decotignye45a6182011-11-05 14:38:24 +00002451 } while (frag_size);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002452 }
2453
2454 /* set last fragment flag */
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002455 prev_tx->flaglen |= cpu_to_le32(NV_TX2_LASTPACKET);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002456
2457 /* save skb in this slot's context area */
2458 prev_tx_ctx->skb = skb;
2459
2460 if (skb_is_gso(skb))
2461 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
2462 else
2463 tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
2464 NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
2465
2466 /* vlan tag */
Jesse Grosseab6d182010-10-20 13:56:03 +00002467 if (vlan_tx_tag_present(skb))
2468 start_tx->txvlan = cpu_to_le32(NV_TX3_VLAN_TAG_PRESENT |
2469 vlan_tx_tag_get(skb));
2470 else
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002471 start_tx->txvlan = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002472
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002473 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002474
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002475 if (np->tx_limit) {
2476 /* Limit the number of outstanding tx. Setup all fragments, but
2477 * do not set the VALID bit on the first descriptor. Save a pointer
2478 * to that descriptor and also for next skb_map element.
2479 */
2480
2481 if (np->tx_pkts_in_progress == NV_TX_LIMIT_COUNT) {
2482 if (!np->tx_change_owner)
2483 np->tx_change_owner = start_tx_ctx;
2484
2485 /* remove VALID bit */
2486 tx_flags &= ~NV_TX2_VALID;
2487 start_tx_ctx->first_tx_desc = start_tx;
2488 start_tx_ctx->next_tx_ctx = np->put_tx_ctx;
2489 np->tx_end_flip = np->put_tx_ctx;
2490 } else {
2491 np->tx_pkts_in_progress++;
2492 }
2493 }
2494
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002495 /* set tx flags */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002496 start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
Tom Herbertb8bfca92011-11-28 16:33:23 +00002497
2498 netdev_sent_queue(np->dev, skb->len);
2499
Willem de Bruijn49cbb1c2012-04-27 09:04:07 +00002500 skb_tx_timestamp(skb);
2501
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002502 np->put_tx.ex = put_tx;
2503
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002504 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002505
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002506 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002507 return NETDEV_TX_OK;
2508}
2509
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002510static inline void nv_tx_flip_ownership(struct net_device *dev)
2511{
2512 struct fe_priv *np = netdev_priv(dev);
2513
2514 np->tx_pkts_in_progress--;
2515 if (np->tx_change_owner) {
Al Viro30ecce92008-03-26 05:57:12 +00002516 np->tx_change_owner->first_tx_desc->flaglen |=
2517 cpu_to_le32(NV_TX2_VALID);
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002518 np->tx_pkts_in_progress++;
2519
2520 np->tx_change_owner = np->tx_change_owner->next_tx_ctx;
2521 if (np->tx_change_owner == np->tx_end_flip)
2522 np->tx_change_owner = NULL;
2523
2524 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
2525 }
2526}
2527
Linus Torvalds1da177e2005-04-16 15:20:36 -07002528/*
2529 * nv_tx_done: check for completed packets, release the skbs.
2530 *
2531 * Caller must own np->lock.
2532 */
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002533static int nv_tx_done(struct net_device *dev, int limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002534{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002535 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002536 u32 flags;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002537 int tx_work = 0;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002538 struct ring_desc *orig_get_tx = np->get_tx.orig;
Tom Herbertb8bfca92011-11-28 16:33:23 +00002539 unsigned int bytes_compl = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002540
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002541 while ((np->get_tx.orig != np->put_tx.orig) &&
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002542 !((flags = le32_to_cpu(np->get_tx.orig->flaglen)) & NV_TX_VALID) &&
2543 (tx_work < limit)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002544
Eric Dumazet73a37072009-06-17 21:17:59 +00002545 nv_unmap_txskb(np, np->get_tx_ctx);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002546
Linus Torvalds1da177e2005-04-16 15:20:36 -07002547 if (np->desc_ver == DESC_VER_1) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002548 if (flags & NV_TX_LASTPACKET) {
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002549 if (flags & NV_TX_ERROR) {
david decotignyf5d827a2011-11-16 12:15:13 +00002550 if ((flags & NV_TX_RETRYERROR)
2551 && !(flags & NV_TX_RETRYCOUNT_MASK))
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002552 nv_legacybackoff_reseed(dev);
david decotigny674aee32011-11-16 12:15:07 +00002553 } else {
david decotignyf5d827a2011-11-16 12:15:13 +00002554 u64_stats_update_begin(&np->swstats_tx_syncp);
2555 np->stat_tx_packets++;
2556 np->stat_tx_bytes += np->get_tx_ctx->skb->len;
2557 u64_stats_update_end(&np->swstats_tx_syncp);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002558 }
Tom Herbertb8bfca92011-11-28 16:33:23 +00002559 bytes_compl += np->get_tx_ctx->skb->len;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002560 dev_kfree_skb_any(np->get_tx_ctx->skb);
2561 np->get_tx_ctx->skb = NULL;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002562 tx_work++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002563 }
2564 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002565 if (flags & NV_TX2_LASTPACKET) {
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002566 if (flags & NV_TX2_ERROR) {
david decotignyf5d827a2011-11-16 12:15:13 +00002567 if ((flags & NV_TX2_RETRYERROR)
2568 && !(flags & NV_TX2_RETRYCOUNT_MASK))
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002569 nv_legacybackoff_reseed(dev);
david decotigny674aee32011-11-16 12:15:07 +00002570 } else {
david decotignyf5d827a2011-11-16 12:15:13 +00002571 u64_stats_update_begin(&np->swstats_tx_syncp);
2572 np->stat_tx_packets++;
2573 np->stat_tx_bytes += np->get_tx_ctx->skb->len;
2574 u64_stats_update_end(&np->swstats_tx_syncp);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002575 }
Tom Herbertb8bfca92011-11-28 16:33:23 +00002576 bytes_compl += np->get_tx_ctx->skb->len;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002577 dev_kfree_skb_any(np->get_tx_ctx->skb);
2578 np->get_tx_ctx->skb = NULL;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002579 tx_work++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002580 }
2581 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002582 if (unlikely(np->get_tx.orig++ == np->last_tx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002583 np->get_tx.orig = np->first_tx.orig;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002584 if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002585 np->get_tx_ctx = np->first_tx_ctx;
2586 }
Tom Herbertb8bfca92011-11-28 16:33:23 +00002587
2588 netdev_completed_queue(np->dev, tx_work, bytes_compl);
2589
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002590 if (unlikely((np->tx_stop == 1) && (np->get_tx.orig != orig_get_tx))) {
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002591 np->tx_stop = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002592 netif_wake_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002593 }
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002594 return tx_work;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002595}
2596
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002597static int nv_tx_done_optimized(struct net_device *dev, int limit)
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002598{
2599 struct fe_priv *np = netdev_priv(dev);
2600 u32 flags;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002601 int tx_work = 0;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002602 struct ring_desc_ex *orig_get_tx = np->get_tx.ex;
Tom Herbertb8bfca92011-11-28 16:33:23 +00002603 unsigned long bytes_cleaned = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002604
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002605 while ((np->get_tx.ex != np->put_tx.ex) &&
Julia Lawall217d32d2010-07-05 22:15:47 -07002606 !((flags = le32_to_cpu(np->get_tx.ex->flaglen)) & NV_TX2_VALID) &&
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002607 (tx_work < limit)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002608
Eric Dumazet73a37072009-06-17 21:17:59 +00002609 nv_unmap_txskb(np, np->get_tx_ctx);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002610
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002611 if (flags & NV_TX2_LASTPACKET) {
david decotigny4687f3f2011-11-05 14:38:22 +00002612 if (flags & NV_TX2_ERROR) {
david decotignyf5d827a2011-11-16 12:15:13 +00002613 if ((flags & NV_TX2_RETRYERROR)
2614 && !(flags & NV_TX2_RETRYCOUNT_MASK)) {
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002615 if (np->driver_data & DEV_HAS_GEAR_MODE)
2616 nv_gear_backoff_reseed(dev);
2617 else
2618 nv_legacybackoff_reseed(dev);
2619 }
david decotigny674aee32011-11-16 12:15:07 +00002620 } else {
David S. Millerefd0bf92011-11-21 13:50:33 -05002621 u64_stats_update_begin(&np->swstats_tx_syncp);
2622 np->stat_tx_packets++;
2623 np->stat_tx_bytes += np->get_tx_ctx->skb->len;
2624 u64_stats_update_end(&np->swstats_tx_syncp);
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002625 }
2626
Tom Herbertb8bfca92011-11-28 16:33:23 +00002627 bytes_cleaned += np->get_tx_ctx->skb->len;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002628 dev_kfree_skb_any(np->get_tx_ctx->skb);
2629 np->get_tx_ctx->skb = NULL;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002630 tx_work++;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002631
Szymon Janc78aea4f2010-11-27 08:39:43 +00002632 if (np->tx_limit)
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002633 nv_tx_flip_ownership(dev);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002634 }
Tom Herbertb8bfca92011-11-28 16:33:23 +00002635
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002636 if (unlikely(np->get_tx.ex++ == np->last_tx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002637 np->get_tx.ex = np->first_tx.ex;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002638 if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002639 np->get_tx_ctx = np->first_tx_ctx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002640 }
Igor Maravic7505afe2011-12-01 23:48:20 +00002641
2642 netdev_completed_queue(np->dev, tx_work, bytes_cleaned);
2643
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002644 if (unlikely((np->tx_stop == 1) && (np->get_tx.ex != orig_get_tx))) {
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002645 np->tx_stop = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002646 netif_wake_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002647 }
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002648 return tx_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002649}
2650
2651/*
2652 * nv_tx_timeout: dev->tx_timeout function
Herbert Xu932ff272006-06-09 12:20:56 -07002653 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002654 */
2655static void nv_tx_timeout(struct net_device *dev)
2656{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002657 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002659 u32 status;
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002660 union ring_type put_tx;
2661 int saved_tx_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002663 if (np->msi_flags & NV_MSI_X_ENABLED)
2664 status = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
2665 else
2666 status = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
2667
Sameer Nanda1ec4f2d2011-11-16 12:15:12 +00002668 netdev_warn(dev, "Got tx_timeout. irq status: %08x\n", status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669
Sameer Nanda1ec4f2d2011-11-16 12:15:12 +00002670 if (unlikely(debug_tx_timeout)) {
2671 int i;
2672
2673 netdev_info(dev, "Ring at %lx\n", (unsigned long)np->ring_addr);
2674 netdev_info(dev, "Dumping tx registers\n");
2675 for (i = 0; i <= np->register_size; i += 32) {
Joe Perches1d397f32010-11-29 07:41:57 +00002676 netdev_info(dev,
Sameer Nanda1ec4f2d2011-11-16 12:15:12 +00002677 "%3x: %08x %08x %08x %08x "
2678 "%08x %08x %08x %08x\n",
Joe Perches1d397f32010-11-29 07:41:57 +00002679 i,
Sameer Nanda1ec4f2d2011-11-16 12:15:12 +00002680 readl(base + i + 0), readl(base + i + 4),
2681 readl(base + i + 8), readl(base + i + 12),
2682 readl(base + i + 16), readl(base + i + 20),
2683 readl(base + i + 24), readl(base + i + 28));
2684 }
2685 netdev_info(dev, "Dumping tx ring\n");
2686 for (i = 0; i < np->tx_ring_size; i += 4) {
2687 if (!nv_optimized(np)) {
2688 netdev_info(dev,
2689 "%03x: %08x %08x // %08x %08x "
2690 "// %08x %08x // %08x %08x\n",
2691 i,
2692 le32_to_cpu(np->tx_ring.orig[i].buf),
2693 le32_to_cpu(np->tx_ring.orig[i].flaglen),
2694 le32_to_cpu(np->tx_ring.orig[i+1].buf),
2695 le32_to_cpu(np->tx_ring.orig[i+1].flaglen),
2696 le32_to_cpu(np->tx_ring.orig[i+2].buf),
2697 le32_to_cpu(np->tx_ring.orig[i+2].flaglen),
2698 le32_to_cpu(np->tx_ring.orig[i+3].buf),
2699 le32_to_cpu(np->tx_ring.orig[i+3].flaglen));
2700 } else {
2701 netdev_info(dev,
2702 "%03x: %08x %08x %08x "
2703 "// %08x %08x %08x "
2704 "// %08x %08x %08x "
2705 "// %08x %08x %08x\n",
2706 i,
2707 le32_to_cpu(np->tx_ring.ex[i].bufhigh),
2708 le32_to_cpu(np->tx_ring.ex[i].buflow),
2709 le32_to_cpu(np->tx_ring.ex[i].flaglen),
2710 le32_to_cpu(np->tx_ring.ex[i+1].bufhigh),
2711 le32_to_cpu(np->tx_ring.ex[i+1].buflow),
2712 le32_to_cpu(np->tx_ring.ex[i+1].flaglen),
2713 le32_to_cpu(np->tx_ring.ex[i+2].bufhigh),
2714 le32_to_cpu(np->tx_ring.ex[i+2].buflow),
2715 le32_to_cpu(np->tx_ring.ex[i+2].flaglen),
2716 le32_to_cpu(np->tx_ring.ex[i+3].bufhigh),
2717 le32_to_cpu(np->tx_ring.ex[i+3].buflow),
2718 le32_to_cpu(np->tx_ring.ex[i+3].flaglen));
2719 }
Manfred Spraulc2dba062005-07-31 18:29:47 +02002720 }
2721 }
2722
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 spin_lock_irq(&np->lock);
2724
2725 /* 1) stop tx engine */
2726 nv_stop_tx(dev);
2727
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002728 /* 2) complete any outstanding tx and do not give HW any limited tx pkts */
2729 saved_tx_limit = np->tx_limit;
2730 np->tx_limit = 0; /* prevent giving HW any limited pkts */
2731 np->tx_stop = 0; /* prevent waking tx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002732 if (!nv_optimized(np))
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002733 nv_tx_done(dev, np->tx_ring_size);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002734 else
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05002735 nv_tx_done_optimized(dev, np->tx_ring_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002736
Lucas De Marchi25985ed2011-03-30 22:57:33 -03002737 /* save current HW position */
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002738 if (np->tx_change_owner)
2739 put_tx.ex = np->tx_change_owner->first_tx_desc;
2740 else
2741 put_tx = np->put_tx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002742
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002743 /* 3) clear all tx state */
2744 nv_drain_tx(dev);
2745 nv_init_tx(dev);
Ayaz Abdulla3ba4d092007-03-23 05:50:02 -05002746
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002747 /* 4) restore state to current HW position */
2748 np->get_tx = np->put_tx = put_tx;
2749 np->tx_limit = saved_tx_limit;
2750
2751 /* 5) restart tx engine */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002752 nv_start_tx(dev);
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002753 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002754 spin_unlock_irq(&np->lock);
2755}
2756
Manfred Spraul22c6d142005-04-19 21:17:09 +02002757/*
2758 * Called when the nic notices a mismatch between the actual data len on the
2759 * wire and the len indicated in the 802 header
2760 */
2761static int nv_getlen(struct net_device *dev, void *packet, int datalen)
2762{
2763 int hdrlen; /* length of the 802 header */
2764 int protolen; /* length as stored in the proto field */
2765
2766 /* 1) calculate len according to header */
Szymon Janc78aea4f2010-11-27 08:39:43 +00002767 if (((struct vlan_ethhdr *)packet)->h_vlan_proto == htons(ETH_P_8021Q)) {
2768 protolen = ntohs(((struct vlan_ethhdr *)packet)->h_vlan_encapsulated_proto);
Manfred Spraul22c6d142005-04-19 21:17:09 +02002769 hdrlen = VLAN_HLEN;
2770 } else {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002771 protolen = ntohs(((struct ethhdr *)packet)->h_proto);
Manfred Spraul22c6d142005-04-19 21:17:09 +02002772 hdrlen = ETH_HLEN;
2773 }
Manfred Spraul22c6d142005-04-19 21:17:09 +02002774 if (protolen > ETH_DATA_LEN)
2775 return datalen; /* Value in proto field not a len, no checks possible */
2776
2777 protolen += hdrlen;
2778 /* consistency checks: */
2779 if (datalen > ETH_ZLEN) {
2780 if (datalen >= protolen) {
2781 /* more data on wire than in 802 header, trim of
2782 * additional data.
2783 */
Manfred Spraul22c6d142005-04-19 21:17:09 +02002784 return protolen;
2785 } else {
2786 /* less data on wire than mentioned in header.
2787 * Discard the packet.
2788 */
Manfred Spraul22c6d142005-04-19 21:17:09 +02002789 return -1;
2790 }
2791 } else {
2792 /* short packet. Accept only if 802 values are also short */
2793 if (protolen > ETH_ZLEN) {
Manfred Spraul22c6d142005-04-19 21:17:09 +02002794 return -1;
2795 }
Manfred Spraul22c6d142005-04-19 21:17:09 +02002796 return datalen;
2797 }
2798}
2799
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002800static int nv_rx_process(struct net_device *dev, int limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002801{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002802 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002803 u32 flags;
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002804 int rx_work = 0;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002805 struct sk_buff *skb;
2806 int len;
Ayaz Abdullaee407b02006-02-04 13:13:17 -05002807
Szymon Janc78aea4f2010-11-27 08:39:43 +00002808 while ((np->get_rx.orig != np->put_rx.orig) &&
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002809 !((flags = le32_to_cpu(np->get_rx.orig->flaglen)) & NV_RX_AVAIL) &&
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002810 (rx_work < limit)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811
Linus Torvalds1da177e2005-04-16 15:20:36 -07002812 /*
2813 * the packet is for us - immediately tear down the pci mapping.
2814 * TODO: check if a prefetch of the first cacheline improves
2815 * the performance.
2816 */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002817 pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma,
2818 np->get_rx_ctx->dma_len,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002819 PCI_DMA_FROMDEVICE);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002820 skb = np->get_rx_ctx->skb;
2821 np->get_rx_ctx->skb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002822
Linus Torvalds1da177e2005-04-16 15:20:36 -07002823 /* look at what we actually got: */
2824 if (np->desc_ver == DESC_VER_1) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002825 if (likely(flags & NV_RX_DESCRIPTORVALID)) {
2826 len = flags & LEN_MASK_V1;
2827 if (unlikely(flags & NV_RX_ERROR)) {
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002828 if ((flags & NV_RX_ERROR_MASK) == NV_RX_ERROR4) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002829 len = nv_getlen(dev, skb->data, len);
2830 if (len < 0) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002831 dev_kfree_skb(skb);
2832 goto next_pkt;
2833 }
2834 }
2835 /* framing errors are soft errors */
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002836 else if ((flags & NV_RX_ERROR_MASK) == NV_RX_FRAMINGERR) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002837 if (flags & NV_RX_SUBSTRACT1)
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002838 len--;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002839 }
2840 /* the rest are hard errors */
2841 else {
david decotignyf5d827a2011-11-16 12:15:13 +00002842 if (flags & NV_RX_MISSEDFRAME) {
2843 u64_stats_update_begin(&np->swstats_rx_syncp);
2844 np->stat_rx_missed_errors++;
2845 u64_stats_update_end(&np->swstats_rx_syncp);
2846 }
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002847 dev_kfree_skb(skb);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002848 goto next_pkt;
2849 }
2850 }
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002851 } else {
2852 dev_kfree_skb(skb);
2853 goto next_pkt;
Manfred Spraul22c6d142005-04-19 21:17:09 +02002854 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002855 } else {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002856 if (likely(flags & NV_RX2_DESCRIPTORVALID)) {
2857 len = flags & LEN_MASK_V2;
2858 if (unlikely(flags & NV_RX2_ERROR)) {
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002859 if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_ERROR4) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002860 len = nv_getlen(dev, skb->data, len);
2861 if (len < 0) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002862 dev_kfree_skb(skb);
2863 goto next_pkt;
2864 }
2865 }
2866 /* framing errors are soft errors */
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002867 else if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_FRAMINGERR) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002868 if (flags & NV_RX2_SUBSTRACT1)
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002869 len--;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002870 }
2871 /* the rest are hard errors */
2872 else {
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002873 dev_kfree_skb(skb);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002874 goto next_pkt;
2875 }
2876 }
Ayaz Abdullabfaffe82008-01-13 16:02:55 -05002877 if (((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_TCP) || /*ip and tcp */
2878 ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_UDP)) /*ip and udp */
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002879 skb->ip_summed = CHECKSUM_UNNECESSARY;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002880 } else {
2881 dev_kfree_skb(skb);
2882 goto next_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002883 }
2884 }
2885 /* got a valid packet - forward it to the network core */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886 skb_put(skb, len);
2887 skb->protocol = eth_type_trans(skb, dev);
Tom Herbert53f224c2010-05-03 19:08:45 +00002888 napi_gro_receive(&np->napi, skb);
david decotignyf5d827a2011-11-16 12:15:13 +00002889 u64_stats_update_begin(&np->swstats_rx_syncp);
2890 np->stat_rx_packets++;
2891 np->stat_rx_bytes += len;
2892 u64_stats_update_end(&np->swstats_rx_syncp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893next_pkt:
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002894 if (unlikely(np->get_rx.orig++ == np->last_rx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002895 np->get_rx.orig = np->first_rx.orig;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002896 if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002897 np->get_rx_ctx = np->first_rx_ctx;
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002898
2899 rx_work++;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002900 }
2901
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002902 return rx_work;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002903}
2904
2905static int nv_rx_process_optimized(struct net_device *dev, int limit)
2906{
2907 struct fe_priv *np = netdev_priv(dev);
2908 u32 flags;
2909 u32 vlanflags = 0;
Ingo Molnarc1b71512007-10-17 12:18:23 +02002910 int rx_work = 0;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002911 struct sk_buff *skb;
2912 int len;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002913
Szymon Janc78aea4f2010-11-27 08:39:43 +00002914 while ((np->get_rx.ex != np->put_rx.ex) &&
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002915 !((flags = le32_to_cpu(np->get_rx.ex->flaglen)) & NV_RX2_AVAIL) &&
Ingo Molnarc1b71512007-10-17 12:18:23 +02002916 (rx_work < limit)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002917
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002918 /*
2919 * the packet is for us - immediately tear down the pci mapping.
2920 * TODO: check if a prefetch of the first cacheline improves
2921 * the performance.
2922 */
2923 pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma,
2924 np->get_rx_ctx->dma_len,
2925 PCI_DMA_FROMDEVICE);
2926 skb = np->get_rx_ctx->skb;
2927 np->get_rx_ctx->skb = NULL;
2928
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002929 /* look at what we actually got: */
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002930 if (likely(flags & NV_RX2_DESCRIPTORVALID)) {
2931 len = flags & LEN_MASK_V2;
2932 if (unlikely(flags & NV_RX2_ERROR)) {
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002933 if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_ERROR4) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002934 len = nv_getlen(dev, skb->data, len);
2935 if (len < 0) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002936 dev_kfree_skb(skb);
2937 goto next_pkt;
2938 }
2939 }
2940 /* framing errors are soft errors */
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002941 else if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_FRAMINGERR) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002942 if (flags & NV_RX2_SUBSTRACT1)
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002943 len--;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002944 }
2945 /* the rest are hard errors */
2946 else {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002947 dev_kfree_skb(skb);
2948 goto next_pkt;
2949 }
2950 }
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002951
Ayaz Abdullabfaffe82008-01-13 16:02:55 -05002952 if (((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_TCP) || /*ip and tcp */
2953 ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_UDP)) /*ip and udp */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002954 skb->ip_summed = CHECKSUM_UNNECESSARY;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002955
2956 /* got a valid packet - forward it to the network core */
2957 skb_put(skb, len);
2958 skb->protocol = eth_type_trans(skb, dev);
2959 prefetch(skb->data);
2960
Jiri Pirko3326c782011-07-20 04:54:38 +00002961 vlanflags = le32_to_cpu(np->get_rx.ex->buflow);
Jiri Pirko0891b0e2011-07-26 10:19:28 +00002962
2963 /*
Patrick McHardyf6469682013-04-19 02:04:27 +00002964 * There's need to check for NETIF_F_HW_VLAN_CTAG_RX
2965 * here. Even if vlan rx accel is disabled,
Jiri Pirko0891b0e2011-07-26 10:19:28 +00002966 * NV_RX3_VLAN_TAG_PRESENT is pseudo randomly set.
2967 */
Patrick McHardyf6469682013-04-19 02:04:27 +00002968 if (dev->features & NETIF_F_HW_VLAN_CTAG_RX &&
Jiri Pirko0891b0e2011-07-26 10:19:28 +00002969 vlanflags & NV_RX3_VLAN_TAG_PRESENT) {
Jiri Pirko3326c782011-07-20 04:54:38 +00002970 u16 vid = vlanflags & NV_RX3_VLAN_TAG_MASK;
2971
Patrick McHardy86a9bad2013-04-19 02:04:30 +00002972 __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002973 }
Jiri Pirko3326c782011-07-20 04:54:38 +00002974 napi_gro_receive(&np->napi, skb);
david decotignyf5d827a2011-11-16 12:15:13 +00002975 u64_stats_update_begin(&np->swstats_rx_syncp);
2976 np->stat_rx_packets++;
2977 np->stat_rx_bytes += len;
2978 u64_stats_update_end(&np->swstats_rx_syncp);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002979 } else {
2980 dev_kfree_skb(skb);
2981 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002982next_pkt:
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002983 if (unlikely(np->get_rx.ex++ == np->last_rx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002984 np->get_rx.ex = np->first_rx.ex;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002985 if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002986 np->get_rx_ctx = np->first_rx_ctx;
Ingo Molnarc1b71512007-10-17 12:18:23 +02002987
2988 rx_work++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002989 }
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002990
Ingo Molnarc1b71512007-10-17 12:18:23 +02002991 return rx_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002992}
2993
Manfred Sprauld81c0982005-07-31 18:20:30 +02002994static void set_bufsize(struct net_device *dev)
2995{
2996 struct fe_priv *np = netdev_priv(dev);
2997
2998 if (dev->mtu <= ETH_DATA_LEN)
2999 np->rx_buf_sz = ETH_DATA_LEN + NV_RX_HEADERS;
3000 else
3001 np->rx_buf_sz = dev->mtu + NV_RX_HEADERS;
3002}
3003
Linus Torvalds1da177e2005-04-16 15:20:36 -07003004/*
3005 * nv_change_mtu: dev->change_mtu function
3006 * Called with dev_base_lock held for read.
3007 */
3008static int nv_change_mtu(struct net_device *dev, int new_mtu)
3009{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003010 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02003011 int old_mtu;
3012
3013 if (new_mtu < 64 || new_mtu > np->pkt_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003014 return -EINVAL;
Manfred Sprauld81c0982005-07-31 18:20:30 +02003015
3016 old_mtu = dev->mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017 dev->mtu = new_mtu;
Manfred Sprauld81c0982005-07-31 18:20:30 +02003018
3019 /* return early if the buffer sizes will not change */
3020 if (old_mtu <= ETH_DATA_LEN && new_mtu <= ETH_DATA_LEN)
3021 return 0;
3022 if (old_mtu == new_mtu)
3023 return 0;
3024
3025 /* synchronized against open : rtnl_lock() held by caller */
3026 if (netif_running(dev)) {
viro@ftp.linux.org.uk25097d42005-09-06 01:36:58 +01003027 u8 __iomem *base = get_hwbase(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02003028 /*
3029 * It seems that the nic preloads valid ring entries into an
3030 * internal buffer. The procedure for flushing everything is
3031 * guessed, there is probably a simpler approach.
3032 * Changing the MTU is a rare event, it shouldn't matter.
3033 */
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003034 nv_disable_irq(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00003035 nv_napi_disable(dev);
Herbert Xu932ff272006-06-09 12:20:56 -07003036 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07003037 netif_addr_lock(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02003038 spin_lock(&np->lock);
3039 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04003040 nv_stop_rxtx(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02003041 nv_txrx_reset(dev);
3042 /* drain rx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04003043 nv_drain_rxtx(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02003044 /* reinit driver view of the rx queue */
Manfred Sprauld81c0982005-07-31 18:20:30 +02003045 set_bufsize(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04003046 if (nv_init_ring(dev)) {
Manfred Sprauld81c0982005-07-31 18:20:30 +02003047 if (!np->in_shutdown)
3048 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3049 }
3050 /* reinit nic view of the rx queue */
3051 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
Ayaz Abdulla0832b252006-02-04 13:13:26 -05003052 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00003053 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Manfred Sprauld81c0982005-07-31 18:20:30 +02003054 base + NvRegRingSizes);
3055 pci_push(base);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04003056 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Manfred Sprauld81c0982005-07-31 18:20:30 +02003057 pci_push(base);
3058
3059 /* restart rx engine */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04003060 nv_start_rxtx(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02003061 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07003062 netif_addr_unlock(dev);
Herbert Xu932ff272006-06-09 12:20:56 -07003063 netif_tx_unlock_bh(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00003064 nv_napi_enable(dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003065 nv_enable_irq(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02003066 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003067 return 0;
3068}
3069
Manfred Spraul72b31782005-07-31 18:33:34 +02003070static void nv_copy_mac_to_hw(struct net_device *dev)
3071{
viro@ftp.linux.org.uk25097d42005-09-06 01:36:58 +01003072 u8 __iomem *base = get_hwbase(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02003073 u32 mac[2];
3074
3075 mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) +
3076 (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24);
3077 mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8);
3078
3079 writel(mac[0], base + NvRegMacAddrA);
3080 writel(mac[1], base + NvRegMacAddrB);
3081}
3082
3083/*
3084 * nv_set_mac_address: dev->set_mac_address function
3085 * Called with rtnl_lock() held.
3086 */
3087static int nv_set_mac_address(struct net_device *dev, void *addr)
3088{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003089 struct fe_priv *np = netdev_priv(dev);
Szymon Janc78aea4f2010-11-27 08:39:43 +00003090 struct sockaddr *macaddr = (struct sockaddr *)addr;
Manfred Spraul72b31782005-07-31 18:33:34 +02003091
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003092 if (!is_valid_ether_addr(macaddr->sa_data))
Manfred Spraul72b31782005-07-31 18:33:34 +02003093 return -EADDRNOTAVAIL;
3094
3095 /* synchronized against open : rtnl_lock() held by caller */
3096 memcpy(dev->dev_addr, macaddr->sa_data, ETH_ALEN);
3097
3098 if (netif_running(dev)) {
Herbert Xu932ff272006-06-09 12:20:56 -07003099 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07003100 netif_addr_lock(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02003101 spin_lock_irq(&np->lock);
3102
3103 /* stop rx engine */
3104 nv_stop_rx(dev);
3105
3106 /* set mac address */
3107 nv_copy_mac_to_hw(dev);
3108
3109 /* restart rx engine */
3110 nv_start_rx(dev);
3111 spin_unlock_irq(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07003112 netif_addr_unlock(dev);
Herbert Xu932ff272006-06-09 12:20:56 -07003113 netif_tx_unlock_bh(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02003114 } else {
3115 nv_copy_mac_to_hw(dev);
3116 }
3117 return 0;
3118}
3119
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120/*
3121 * nv_set_multicast: dev->set_multicast function
Herbert Xu932ff272006-06-09 12:20:56 -07003122 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 */
3124static void nv_set_multicast(struct net_device *dev)
3125{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003126 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 u8 __iomem *base = get_hwbase(dev);
3128 u32 addr[2];
3129 u32 mask[2];
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003130 u32 pff = readl(base + NvRegPacketFilterFlags) & NVREG_PFF_PAUSE_RX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003131
3132 memset(addr, 0, sizeof(addr));
3133 memset(mask, 0, sizeof(mask));
3134
3135 if (dev->flags & IFF_PROMISC) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003136 pff |= NVREG_PFF_PROMISC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003137 } else {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003138 pff |= NVREG_PFF_MYADDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139
Jiri Pirko48e2f182010-02-22 09:22:26 +00003140 if (dev->flags & IFF_ALLMULTI || !netdev_mc_empty(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003141 u32 alwaysOff[2];
3142 u32 alwaysOn[2];
3143
3144 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0xffffffff;
3145 if (dev->flags & IFF_ALLMULTI) {
3146 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0;
3147 } else {
Jiri Pirko22bedad32010-04-01 21:22:57 +00003148 struct netdev_hw_addr *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003149
Jiri Pirko22bedad32010-04-01 21:22:57 +00003150 netdev_for_each_mc_addr(ha, dev) {
david decotignye45a6182011-11-05 14:38:24 +00003151 unsigned char *hw_addr = ha->addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003152 u32 a, b;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003153
david decotignye45a6182011-11-05 14:38:24 +00003154 a = le32_to_cpu(*(__le32 *) hw_addr);
3155 b = le16_to_cpu(*(__le16 *) (&hw_addr[4]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003156 alwaysOn[0] &= a;
3157 alwaysOff[0] &= ~a;
3158 alwaysOn[1] &= b;
3159 alwaysOff[1] &= ~b;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003160 }
3161 }
3162 addr[0] = alwaysOn[0];
3163 addr[1] = alwaysOn[1];
3164 mask[0] = alwaysOn[0] | alwaysOff[0];
3165 mask[1] = alwaysOn[1] | alwaysOff[1];
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -05003166 } else {
3167 mask[0] = NVREG_MCASTMASKA_NONE;
3168 mask[1] = NVREG_MCASTMASKB_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003169 }
3170 }
3171 addr[0] |= NVREG_MCASTADDRA_FORCE;
3172 pff |= NVREG_PFF_ALWAYS;
3173 spin_lock_irq(&np->lock);
3174 nv_stop_rx(dev);
3175 writel(addr[0], base + NvRegMulticastAddrA);
3176 writel(addr[1], base + NvRegMulticastAddrB);
3177 writel(mask[0], base + NvRegMulticastMaskA);
3178 writel(mask[1], base + NvRegMulticastMaskB);
3179 writel(pff, base + NvRegPacketFilterFlags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003180 nv_start_rx(dev);
3181 spin_unlock_irq(&np->lock);
3182}
3183
Adrian Bunkc7985052006-06-22 12:03:29 +02003184static void nv_update_pause(struct net_device *dev, u32 pause_flags)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003185{
3186 struct fe_priv *np = netdev_priv(dev);
3187 u8 __iomem *base = get_hwbase(dev);
3188
3189 np->pause_flags &= ~(NV_PAUSEFRAME_TX_ENABLE | NV_PAUSEFRAME_RX_ENABLE);
3190
3191 if (np->pause_flags & NV_PAUSEFRAME_RX_CAPABLE) {
3192 u32 pff = readl(base + NvRegPacketFilterFlags) & ~NVREG_PFF_PAUSE_RX;
3193 if (pause_flags & NV_PAUSEFRAME_RX_ENABLE) {
3194 writel(pff|NVREG_PFF_PAUSE_RX, base + NvRegPacketFilterFlags);
3195 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3196 } else {
3197 writel(pff, base + NvRegPacketFilterFlags);
3198 }
3199 }
3200 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE) {
3201 u32 regmisc = readl(base + NvRegMisc1) & ~NVREG_MISC1_PAUSE_TX;
3202 if (pause_flags & NV_PAUSEFRAME_TX_ENABLE) {
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05003203 u32 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V1;
3204 if (np->driver_data & DEV_HAS_PAUSEFRAME_TX_V2)
3205 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V2;
Ayaz Abdulla9a33e882008-08-06 12:12:34 -04003206 if (np->driver_data & DEV_HAS_PAUSEFRAME_TX_V3) {
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05003207 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V3;
Ayaz Abdulla9a33e882008-08-06 12:12:34 -04003208 /* limit the number of tx pause frames to a default of 8 */
3209 writel(readl(base + NvRegTxPauseFrameLimit)|NVREG_TX_PAUSEFRAMELIMIT_ENABLE, base + NvRegTxPauseFrameLimit);
3210 }
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05003211 writel(pause_enable, base + NvRegTxPauseFrame);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003212 writel(regmisc|NVREG_MISC1_PAUSE_TX, base + NvRegMisc1);
3213 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3214 } else {
3215 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
3216 writel(regmisc, base + NvRegMisc1);
3217 }
3218 }
3219}
3220
Sanjay Hortikare19df762011-11-11 16:11:21 +00003221static void nv_force_linkspeed(struct net_device *dev, int speed, int duplex)
3222{
3223 struct fe_priv *np = netdev_priv(dev);
3224 u8 __iomem *base = get_hwbase(dev);
3225 u32 phyreg, txreg;
3226 int mii_status;
3227
3228 np->linkspeed = NVREG_LINKSPEED_FORCE|speed;
3229 np->duplex = duplex;
3230
3231 /* see if gigabit phy */
3232 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
3233 if (mii_status & PHY_GIGABIT) {
3234 np->gigabit = PHY_GIGABIT;
3235 phyreg = readl(base + NvRegSlotTime);
3236 phyreg &= ~(0x3FF00);
3237 if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10)
3238 phyreg |= NVREG_SLOTTIME_10_100_FULL;
3239 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100)
3240 phyreg |= NVREG_SLOTTIME_10_100_FULL;
3241 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000)
3242 phyreg |= NVREG_SLOTTIME_1000_FULL;
3243 writel(phyreg, base + NvRegSlotTime);
3244 }
3245
3246 phyreg = readl(base + NvRegPhyInterface);
3247 phyreg &= ~(PHY_HALF|PHY_100|PHY_1000);
3248 if (np->duplex == 0)
3249 phyreg |= PHY_HALF;
3250 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100)
3251 phyreg |= PHY_100;
3252 else if ((np->linkspeed & NVREG_LINKSPEED_MASK) ==
3253 NVREG_LINKSPEED_1000)
3254 phyreg |= PHY_1000;
3255 writel(phyreg, base + NvRegPhyInterface);
3256
3257 if (phyreg & PHY_RGMII) {
3258 if ((np->linkspeed & NVREG_LINKSPEED_MASK) ==
3259 NVREG_LINKSPEED_1000)
3260 txreg = NVREG_TX_DEFERRAL_RGMII_1000;
3261 else
3262 txreg = NVREG_TX_DEFERRAL_RGMII_10_100;
3263 } else {
3264 txreg = NVREG_TX_DEFERRAL_DEFAULT;
3265 }
3266 writel(txreg, base + NvRegTxDeferral);
3267
3268 if (np->desc_ver == DESC_VER_1) {
3269 txreg = NVREG_TX_WM_DESC1_DEFAULT;
3270 } else {
3271 if ((np->linkspeed & NVREG_LINKSPEED_MASK) ==
3272 NVREG_LINKSPEED_1000)
3273 txreg = NVREG_TX_WM_DESC2_3_1000;
3274 else
3275 txreg = NVREG_TX_WM_DESC2_3_DEFAULT;
3276 }
3277 writel(txreg, base + NvRegTxWatermark);
3278
3279 writel(NVREG_MISC1_FORCE | (np->duplex ? 0 : NVREG_MISC1_HD),
3280 base + NvRegMisc1);
3281 pci_push(base);
3282 writel(np->linkspeed, base + NvRegLinkSpeed);
3283 pci_push(base);
3284
3285 return;
3286}
3287
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05003288/**
Ben Hutchings49ce9c22012-07-10 10:56:00 +00003289 * nv_update_linkspeed - Setup the MAC according to the link partner
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05003290 * @dev: Network device to be configured
3291 *
3292 * The function queries the PHY and checks if there is a link partner.
3293 * If yes, then it sets up the MAC accordingly. Otherwise, the MAC is
3294 * set to 10 MBit HD.
3295 *
3296 * The function returns 0 if there is no link partner and 1 if there is
3297 * a good link partner.
3298 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003299static int nv_update_linkspeed(struct net_device *dev)
3300{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003301 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003302 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003303 int adv = 0;
3304 int lpa = 0;
3305 int adv_lpa, adv_pause, lpa_pause;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003306 int newls = np->linkspeed;
3307 int newdup = np->duplex;
3308 int mii_status;
Sanjay Hortikare19df762011-11-11 16:11:21 +00003309 u32 bmcr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003310 int retval = 0;
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003311 u32 control_1000, status_1000, phyreg, pause_flags, txreg;
Ayaz Abdullab2976d22008-02-04 15:13:59 -05003312 u32 txrxFlags = 0;
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003313 u32 phy_exp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003314
Sanjay Hortikare19df762011-11-11 16:11:21 +00003315 /* If device loopback is enabled, set carrier on and enable max link
3316 * speed.
3317 */
3318 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
3319 if (bmcr & BMCR_LOOPBACK) {
3320 if (netif_running(dev)) {
3321 nv_force_linkspeed(dev, NVREG_LINKSPEED_1000, 1);
3322 if (!netif_carrier_ok(dev))
3323 netif_carrier_on(dev);
3324 }
3325 return 1;
3326 }
3327
Linus Torvalds1da177e2005-04-16 15:20:36 -07003328 /* BMSR_LSTATUS is latched, read it twice:
3329 * we want the current value.
3330 */
3331 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
3332 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
3333
3334 if (!(mii_status & BMSR_LSTATUS)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003335 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3336 newdup = 0;
3337 retval = 0;
3338 goto set_speed;
3339 }
3340
3341 if (np->autoneg == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003342 if (np->fixed_mode & LPA_100FULL) {
3343 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3344 newdup = 1;
3345 } else if (np->fixed_mode & LPA_100HALF) {
3346 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3347 newdup = 0;
3348 } else if (np->fixed_mode & LPA_10FULL) {
3349 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3350 newdup = 1;
3351 } else {
3352 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3353 newdup = 0;
3354 }
3355 retval = 1;
3356 goto set_speed;
3357 }
3358 /* check auto negotiation is complete */
3359 if (!(mii_status & BMSR_ANEGCOMPLETE)) {
3360 /* still in autonegotiation - configure nic for 10 MBit HD and wait. */
3361 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3362 newdup = 0;
3363 retval = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003364 goto set_speed;
3365 }
3366
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003367 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
3368 lpa = mii_rw(dev, np->phyaddr, MII_LPA, MII_READ);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003369
Linus Torvalds1da177e2005-04-16 15:20:36 -07003370 retval = 1;
3371 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003372 control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
3373 status_1000 = mii_rw(dev, np->phyaddr, MII_STAT1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003374
3375 if ((control_1000 & ADVERTISE_1000FULL) &&
3376 (status_1000 & LPA_1000FULL)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003377 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_1000;
3378 newdup = 1;
3379 goto set_speed;
3380 }
3381 }
3382
Linus Torvalds1da177e2005-04-16 15:20:36 -07003383 /* FIXME: handle parallel detection properly */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003384 adv_lpa = lpa & adv;
3385 if (adv_lpa & LPA_100FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003386 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3387 newdup = 1;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003388 } else if (adv_lpa & LPA_100HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003389 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3390 newdup = 0;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003391 } else if (adv_lpa & LPA_10FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003392 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3393 newdup = 1;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003394 } else if (adv_lpa & LPA_10HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003395 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3396 newdup = 0;
3397 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003398 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3399 newdup = 0;
3400 }
3401
3402set_speed:
3403 if (np->duplex == newdup && np->linkspeed == newls)
3404 return retval;
3405
Linus Torvalds1da177e2005-04-16 15:20:36 -07003406 np->duplex = newdup;
3407 np->linkspeed = newls;
3408
Ayaz Abdullab2976d22008-02-04 15:13:59 -05003409 /* The transmitter and receiver must be restarted for safe update */
3410 if (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_START) {
3411 txrxFlags |= NV_RESTART_TX;
3412 nv_stop_tx(dev);
3413 }
3414 if (readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) {
3415 txrxFlags |= NV_RESTART_RX;
3416 nv_stop_rx(dev);
3417 }
3418
Linus Torvalds1da177e2005-04-16 15:20:36 -07003419 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaa4336862008-04-18 13:50:43 -07003420 phyreg = readl(base + NvRegSlotTime);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421 phyreg &= ~(0x3FF00);
Ayaz Abdullaa4336862008-04-18 13:50:43 -07003422 if (((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10) ||
3423 ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100))
3424 phyreg |= NVREG_SLOTTIME_10_100_FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003425 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000)
Ayaz Abdullaa4336862008-04-18 13:50:43 -07003426 phyreg |= NVREG_SLOTTIME_1000_FULL;
3427 writel(phyreg, base + NvRegSlotTime);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003428 }
3429
3430 phyreg = readl(base + NvRegPhyInterface);
3431 phyreg &= ~(PHY_HALF|PHY_100|PHY_1000);
3432 if (np->duplex == 0)
3433 phyreg |= PHY_HALF;
3434 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100)
3435 phyreg |= PHY_100;
3436 else if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
3437 phyreg |= PHY_1000;
3438 writel(phyreg, base + NvRegPhyInterface);
3439
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003440 phy_exp = mii_rw(dev, np->phyaddr, MII_EXPANSION, MII_READ) & EXPANSION_NWAY; /* autoneg capable */
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003441 if (phyreg & PHY_RGMII) {
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003442 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000) {
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003443 txreg = NVREG_TX_DEFERRAL_RGMII_1000;
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003444 } else {
3445 if (!phy_exp && !np->duplex && (np->driver_data & DEV_HAS_COLLISION_FIX)) {
3446 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_10)
3447 txreg = NVREG_TX_DEFERRAL_RGMII_STRETCH_10;
3448 else
3449 txreg = NVREG_TX_DEFERRAL_RGMII_STRETCH_100;
3450 } else {
3451 txreg = NVREG_TX_DEFERRAL_RGMII_10_100;
3452 }
3453 }
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003454 } else {
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003455 if (!phy_exp && !np->duplex && (np->driver_data & DEV_HAS_COLLISION_FIX))
3456 txreg = NVREG_TX_DEFERRAL_MII_STRETCH;
3457 else
3458 txreg = NVREG_TX_DEFERRAL_DEFAULT;
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003459 }
3460 writel(txreg, base + NvRegTxDeferral);
3461
Ayaz Abdulla95d161c2006-07-06 16:46:25 -04003462 if (np->desc_ver == DESC_VER_1) {
3463 txreg = NVREG_TX_WM_DESC1_DEFAULT;
3464 } else {
3465 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
3466 txreg = NVREG_TX_WM_DESC2_3_1000;
3467 else
3468 txreg = NVREG_TX_WM_DESC2_3_DEFAULT;
3469 }
3470 writel(txreg, base + NvRegTxWatermark);
3471
Szymon Janc78aea4f2010-11-27 08:39:43 +00003472 writel(NVREG_MISC1_FORCE | (np->duplex ? 0 : NVREG_MISC1_HD),
Linus Torvalds1da177e2005-04-16 15:20:36 -07003473 base + NvRegMisc1);
3474 pci_push(base);
3475 writel(np->linkspeed, base + NvRegLinkSpeed);
3476 pci_push(base);
3477
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003478 pause_flags = 0;
3479 /* setup pause frame */
david decotigny1ff39eb2012-08-24 17:22:52 +00003480 if (netif_running(dev) && (np->duplex != 0)) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003481 if (np->autoneg && np->pause_flags & NV_PAUSEFRAME_AUTONEG) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003482 adv_pause = adv & (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
3483 lpa_pause = lpa & (LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003484
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003485 switch (adv_pause) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003486 case ADVERTISE_PAUSE_CAP:
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003487 if (lpa_pause & LPA_PAUSE_CAP) {
3488 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3489 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
3490 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3491 }
3492 break;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003493 case ADVERTISE_PAUSE_ASYM:
Szymon Janc78aea4f2010-11-27 08:39:43 +00003494 if (lpa_pause == (LPA_PAUSE_CAP | LPA_PAUSE_ASYM))
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003495 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003496 break;
Szymon Janc78aea4f2010-11-27 08:39:43 +00003497 case ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM:
3498 if (lpa_pause & LPA_PAUSE_CAP) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003499 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3500 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
3501 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3502 }
3503 if (lpa_pause == LPA_PAUSE_ASYM)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003504 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003505 break;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003506 }
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003507 } else {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003508 pause_flags = np->pause_flags;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003509 }
3510 }
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003511 nv_update_pause(dev, pause_flags);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003512
Ayaz Abdullab2976d22008-02-04 15:13:59 -05003513 if (txrxFlags & NV_RESTART_TX)
3514 nv_start_tx(dev);
3515 if (txrxFlags & NV_RESTART_RX)
3516 nv_start_rx(dev);
3517
Linus Torvalds1da177e2005-04-16 15:20:36 -07003518 return retval;
3519}
3520
3521static void nv_linkchange(struct net_device *dev)
3522{
3523 if (nv_update_linkspeed(dev)) {
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05003524 if (!netif_carrier_ok(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003525 netif_carrier_on(dev);
Joe Perches1d397f32010-11-29 07:41:57 +00003526 netdev_info(dev, "link up\n");
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00003527 nv_txrx_gate(dev, false);
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05003528 nv_start_rx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003529 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003530 } else {
3531 if (netif_carrier_ok(dev)) {
3532 netif_carrier_off(dev);
Joe Perches1d397f32010-11-29 07:41:57 +00003533 netdev_info(dev, "link down\n");
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00003534 nv_txrx_gate(dev, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003535 nv_stop_rx(dev);
3536 }
3537 }
3538}
3539
3540static void nv_link_irq(struct net_device *dev)
3541{
3542 u8 __iomem *base = get_hwbase(dev);
3543 u32 miistat;
3544
3545 miistat = readl(base + NvRegMIIStatus);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05003546 writel(NVREG_MIISTAT_LINKCHANGE, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003547
3548 if (miistat & (NVREG_MIISTAT_LINKCHANGE))
3549 nv_linkchange(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003550}
3551
Ayaz Abdulla4db0ee172008-06-09 16:51:06 -07003552static void nv_msi_workaround(struct fe_priv *np)
3553{
3554
3555 /* Need to toggle the msi irq mask within the ethernet device,
3556 * otherwise, future interrupts will not be detected.
3557 */
3558 if (np->msi_flags & NV_MSI_ENABLED) {
3559 u8 __iomem *base = np->base;
3560
3561 writel(0, base + NvRegMSIIrqMask);
3562 writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask);
3563 }
3564}
3565
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003566static inline int nv_change_interrupt_mode(struct net_device *dev, int total_work)
3567{
3568 struct fe_priv *np = netdev_priv(dev);
3569
3570 if (optimization_mode == NV_OPTIMIZATION_MODE_DYNAMIC) {
3571 if (total_work > NV_DYNAMIC_THRESHOLD) {
3572 /* transition to poll based interrupts */
3573 np->quiet_count = 0;
3574 if (np->irqmask != NVREG_IRQMASK_CPU) {
3575 np->irqmask = NVREG_IRQMASK_CPU;
3576 return 1;
3577 }
3578 } else {
3579 if (np->quiet_count < NV_DYNAMIC_MAX_QUIET_COUNT) {
3580 np->quiet_count++;
3581 } else {
3582 /* reached a period of low activity, switch
3583 to per tx/rx packet interrupts */
3584 if (np->irqmask != NVREG_IRQMASK_THROUGHPUT) {
3585 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
3586 return 1;
3587 }
3588 }
3589 }
3590 }
3591 return 0;
3592}
3593
David Howells7d12e782006-10-05 14:55:46 +01003594static irqreturn_t nv_nic_irq(int foo, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003595{
3596 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003597 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003598 u8 __iomem *base = get_hwbase(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003599
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003600 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3601 np->events = readl(base + NvRegIrqStatus);
Ayaz Abdulla1b2bb762009-03-05 08:02:34 +00003602 writel(np->events, base + NvRegIrqStatus);
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003603 } else {
3604 np->events = readl(base + NvRegMSIXIrqStatus);
Ayaz Abdulla1b2bb762009-03-05 08:02:34 +00003605 writel(np->events, base + NvRegMSIXIrqStatus);
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003606 }
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003607 if (!(np->events & np->irqmask))
3608 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003609
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003610 nv_msi_workaround(np);
Ayaz Abdulla4db0ee172008-06-09 16:51:06 -07003611
Eric Dumazet78c29bd2009-07-02 04:04:45 +00003612 if (napi_schedule_prep(&np->napi)) {
3613 /*
3614 * Disable further irq's (msix not enabled with napi)
3615 */
3616 writel(0, base + NvRegIrqMask);
3617 __napi_schedule(&np->napi);
3618 }
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003619
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003620 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003621}
3622
Ben Hutchings1aa8b472012-07-10 10:56:59 +00003623/* All _optimized functions are used to help increase performance
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003624 * (reduce CPU and increase throughput). They use descripter version 3,
3625 * compiler directives, and reduce memory accesses.
3626 */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003627static irqreturn_t nv_nic_irq_optimized(int foo, void *data)
3628{
3629 struct net_device *dev = (struct net_device *) data;
3630 struct fe_priv *np = netdev_priv(dev);
3631 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003632
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003633 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3634 np->events = readl(base + NvRegIrqStatus);
Ayaz Abdulla1b2bb762009-03-05 08:02:34 +00003635 writel(np->events, base + NvRegIrqStatus);
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003636 } else {
3637 np->events = readl(base + NvRegMSIXIrqStatus);
Ayaz Abdulla1b2bb762009-03-05 08:02:34 +00003638 writel(np->events, base + NvRegMSIXIrqStatus);
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003639 }
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003640 if (!(np->events & np->irqmask))
3641 return IRQ_NONE;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003642
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003643 nv_msi_workaround(np);
Ayaz Abdulla4db0ee172008-06-09 16:51:06 -07003644
Eric Dumazet78c29bd2009-07-02 04:04:45 +00003645 if (napi_schedule_prep(&np->napi)) {
3646 /*
3647 * Disable further irq's (msix not enabled with napi)
3648 */
3649 writel(0, base + NvRegIrqMask);
3650 __napi_schedule(&np->napi);
3651 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003652
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003653 return IRQ_HANDLED;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003654}
3655
David Howells7d12e782006-10-05 14:55:46 +01003656static irqreturn_t nv_nic_irq_tx(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003657{
3658 struct net_device *dev = (struct net_device *) data;
3659 struct fe_priv *np = netdev_priv(dev);
3660 u8 __iomem *base = get_hwbase(dev);
3661 u32 events;
3662 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003663 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003664
Szymon Janc78aea4f2010-11-27 08:39:43 +00003665 for (i = 0;; i++) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003666 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_TX_ALL;
Mike Ditto2a4e7a02011-11-05 14:38:21 +00003667 writel(events, base + NvRegMSIXIrqStatus);
3668 netdev_dbg(dev, "tx irq events: %08x\n", events);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003669 if (!(events & np->irqmask))
3670 break;
3671
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003672 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05003673 nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003674 spin_unlock_irqrestore(&np->lock, flags);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003675
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003676 if (unlikely(i > max_interrupt_work)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003677 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003678 /* disable interrupts on the nic */
3679 writel(NVREG_IRQ_TX_ALL, base + NvRegIrqMask);
3680 pci_push(base);
3681
3682 if (!np->in_shutdown) {
3683 np->nic_poll_irq |= NVREG_IRQ_TX_ALL;
3684 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3685 }
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003686 spin_unlock_irqrestore(&np->lock, flags);
Joe Perchesc20ec762010-11-29 07:42:02 +00003687 netdev_dbg(dev, "%s: too many iterations (%d)\n",
3688 __func__, i);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003689 break;
3690 }
3691
3692 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003693
3694 return IRQ_RETVAL(i);
3695}
3696
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003697static int nv_napi_poll(struct napi_struct *napi, int budget)
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003698{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003699 struct fe_priv *np = container_of(napi, struct fe_priv, napi);
3700 struct net_device *dev = np->dev;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003701 u8 __iomem *base = get_hwbase(dev);
Francois Romieud15e9c42006-12-17 23:03:15 +01003702 unsigned long flags;
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003703 int retcode;
Szymon Janc78aea4f2010-11-27 08:39:43 +00003704 int rx_count, tx_work = 0, rx_work = 0;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003705
stephen hemminger81a2e362010-04-28 08:25:28 +00003706 do {
3707 if (!nv_optimized(np)) {
3708 spin_lock_irqsave(&np->lock, flags);
3709 tx_work += nv_tx_done(dev, np->tx_ring_size);
3710 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003711
Tom Herbertd951f722010-05-05 18:15:21 +00003712 rx_count = nv_rx_process(dev, budget - rx_work);
stephen hemminger81a2e362010-04-28 08:25:28 +00003713 retcode = nv_alloc_rx(dev);
3714 } else {
3715 spin_lock_irqsave(&np->lock, flags);
3716 tx_work += nv_tx_done_optimized(dev, np->tx_ring_size);
3717 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003718
Tom Herbertd951f722010-05-05 18:15:21 +00003719 rx_count = nv_rx_process_optimized(dev,
3720 budget - rx_work);
stephen hemminger81a2e362010-04-28 08:25:28 +00003721 retcode = nv_alloc_rx_optimized(dev);
3722 }
3723 } while (retcode == 0 &&
3724 rx_count > 0 && (rx_work += rx_count) < budget);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003725
Ayaz Abdullae0379a12007-02-20 03:34:30 -05003726 if (retcode) {
Francois Romieud15e9c42006-12-17 23:03:15 +01003727 spin_lock_irqsave(&np->lock, flags);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003728 if (!np->in_shutdown)
3729 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Francois Romieud15e9c42006-12-17 23:03:15 +01003730 spin_unlock_irqrestore(&np->lock, flags);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003731 }
3732
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003733 nv_change_interrupt_mode(dev, tx_work + rx_work);
3734
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003735 if (unlikely(np->events & NVREG_IRQ_LINK)) {
3736 spin_lock_irqsave(&np->lock, flags);
3737 nv_link_irq(dev);
3738 spin_unlock_irqrestore(&np->lock, flags);
3739 }
3740 if (unlikely(np->need_linktimer && time_after(jiffies, np->link_timeout))) {
3741 spin_lock_irqsave(&np->lock, flags);
3742 nv_linkchange(dev);
3743 spin_unlock_irqrestore(&np->lock, flags);
3744 np->link_timeout = jiffies + LINK_TIMEOUT;
3745 }
3746 if (unlikely(np->events & NVREG_IRQ_RECOVER_ERROR)) {
3747 spin_lock_irqsave(&np->lock, flags);
3748 if (!np->in_shutdown) {
3749 np->nic_poll_irq = np->irqmask;
3750 np->recover_error = 1;
3751 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3752 }
3753 spin_unlock_irqrestore(&np->lock, flags);
David S. Miller6c2da9c2009-04-09 01:09:33 -07003754 napi_complete(napi);
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003755 return rx_work;
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003756 }
3757
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003758 if (rx_work < budget) {
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003759 /* re-enable interrupts
3760 (msix not enabled in napi) */
David S. Miller6c2da9c2009-04-09 01:09:33 -07003761 napi_complete(napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003762
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003763 writel(np->irqmask, base + NvRegIrqMask);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003764 }
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003765 return rx_work;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003766}
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003767
David Howells7d12e782006-10-05 14:55:46 +01003768static irqreturn_t nv_nic_irq_rx(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003769{
3770 struct net_device *dev = (struct net_device *) data;
3771 struct fe_priv *np = netdev_priv(dev);
3772 u8 __iomem *base = get_hwbase(dev);
3773 u32 events;
3774 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003775 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003776
Szymon Janc78aea4f2010-11-27 08:39:43 +00003777 for (i = 0;; i++) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003778 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
Mike Ditto2a4e7a02011-11-05 14:38:21 +00003779 writel(events, base + NvRegMSIXIrqStatus);
3780 netdev_dbg(dev, "rx irq events: %08x\n", events);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003781 if (!(events & np->irqmask))
3782 break;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003783
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003784 if (nv_rx_process_optimized(dev, RX_WORK_PER_LOOP)) {
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003785 if (unlikely(nv_alloc_rx_optimized(dev))) {
3786 spin_lock_irqsave(&np->lock, flags);
3787 if (!np->in_shutdown)
3788 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3789 spin_unlock_irqrestore(&np->lock, flags);
3790 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003791 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003792
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003793 if (unlikely(i > max_interrupt_work)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003794 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003795 /* disable interrupts on the nic */
3796 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
3797 pci_push(base);
3798
3799 if (!np->in_shutdown) {
3800 np->nic_poll_irq |= NVREG_IRQ_RX_ALL;
3801 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3802 }
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003803 spin_unlock_irqrestore(&np->lock, flags);
Joe Perchesc20ec762010-11-29 07:42:02 +00003804 netdev_dbg(dev, "%s: too many iterations (%d)\n",
3805 __func__, i);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003806 break;
3807 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003808 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003809
3810 return IRQ_RETVAL(i);
3811}
3812
David Howells7d12e782006-10-05 14:55:46 +01003813static irqreturn_t nv_nic_irq_other(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003814{
3815 struct net_device *dev = (struct net_device *) data;
3816 struct fe_priv *np = netdev_priv(dev);
3817 u8 __iomem *base = get_hwbase(dev);
3818 u32 events;
3819 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003820 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003821
Szymon Janc78aea4f2010-11-27 08:39:43 +00003822 for (i = 0;; i++) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003823 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_OTHER;
Mike Ditto2a4e7a02011-11-05 14:38:21 +00003824 writel(events, base + NvRegMSIXIrqStatus);
3825 netdev_dbg(dev, "irq events: %08x\n", events);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003826 if (!(events & np->irqmask))
3827 break;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003828
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05003829 /* check tx in case we reached max loop limit in tx isr */
3830 spin_lock_irqsave(&np->lock, flags);
3831 nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
3832 spin_unlock_irqrestore(&np->lock, flags);
3833
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003834 if (events & NVREG_IRQ_LINK) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003835 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003836 nv_link_irq(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003837 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003838 }
3839 if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003840 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003841 nv_linkchange(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003842 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003843 np->link_timeout = jiffies + LINK_TIMEOUT;
3844 }
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003845 if (events & NVREG_IRQ_RECOVER_ERROR) {
Denis Efremov186e8682012-07-21 01:54:34 +04003846 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003847 /* disable interrupts on the nic */
3848 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
3849 pci_push(base);
3850
3851 if (!np->in_shutdown) {
3852 np->nic_poll_irq |= NVREG_IRQ_OTHER;
3853 np->recover_error = 1;
3854 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3855 }
Denis Efremov186e8682012-07-21 01:54:34 +04003856 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003857 break;
3858 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003859 if (unlikely(i > max_interrupt_work)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003860 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003861 /* disable interrupts on the nic */
3862 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
3863 pci_push(base);
3864
3865 if (!np->in_shutdown) {
3866 np->nic_poll_irq |= NVREG_IRQ_OTHER;
3867 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3868 }
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003869 spin_unlock_irqrestore(&np->lock, flags);
Joe Perchesc20ec762010-11-29 07:42:02 +00003870 netdev_dbg(dev, "%s: too many iterations (%d)\n",
3871 __func__, i);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003872 break;
3873 }
3874
3875 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003876
3877 return IRQ_RETVAL(i);
3878}
3879
David Howells7d12e782006-10-05 14:55:46 +01003880static irqreturn_t nv_nic_irq_test(int foo, void *data)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003881{
3882 struct net_device *dev = (struct net_device *) data;
3883 struct fe_priv *np = netdev_priv(dev);
3884 u8 __iomem *base = get_hwbase(dev);
3885 u32 events;
3886
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003887 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3888 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
Mike Ditto2a4e7a02011-11-05 14:38:21 +00003889 writel(events & NVREG_IRQ_TIMER, base + NvRegIrqStatus);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003890 } else {
3891 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
Mike Ditto2a4e7a02011-11-05 14:38:21 +00003892 writel(events & NVREG_IRQ_TIMER, base + NvRegMSIXIrqStatus);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003893 }
3894 pci_push(base);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003895 if (!(events & NVREG_IRQ_TIMER))
3896 return IRQ_RETVAL(0);
3897
Ayaz Abdulla4db0ee172008-06-09 16:51:06 -07003898 nv_msi_workaround(np);
3899
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003900 spin_lock(&np->lock);
3901 np->intr_test = 1;
3902 spin_unlock(&np->lock);
3903
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003904 return IRQ_RETVAL(1);
3905}
3906
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003907static void set_msix_vector_map(struct net_device *dev, u32 vector, u32 irqmask)
3908{
3909 u8 __iomem *base = get_hwbase(dev);
3910 int i;
3911 u32 msixmap = 0;
3912
3913 /* Each interrupt bit can be mapped to a MSIX vector (4 bits).
3914 * MSIXMap0 represents the first 8 interrupts and MSIXMap1 represents
3915 * the remaining 8 interrupts.
3916 */
3917 for (i = 0; i < 8; i++) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003918 if ((irqmask >> i) & 0x1)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003919 msixmap |= vector << (i << 2);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003920 }
3921 writel(readl(base + NvRegMSIXMap0) | msixmap, base + NvRegMSIXMap0);
3922
3923 msixmap = 0;
3924 for (i = 0; i < 8; i++) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003925 if ((irqmask >> (i + 8)) & 0x1)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003926 msixmap |= vector << (i << 2);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003927 }
3928 writel(readl(base + NvRegMSIXMap1) | msixmap, base + NvRegMSIXMap1);
3929}
3930
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003931static int nv_request_irq(struct net_device *dev, int intr_test)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003932{
3933 struct fe_priv *np = get_nvpriv(dev);
3934 u8 __iomem *base = get_hwbase(dev);
3935 int ret = 1;
3936 int i;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003937 irqreturn_t (*handler)(int foo, void *data);
3938
3939 if (intr_test) {
3940 handler = nv_nic_irq_test;
3941 } else {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04003942 if (nv_optimized(np))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003943 handler = nv_nic_irq_optimized;
3944 else
3945 handler = nv_nic_irq;
3946 }
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003947
3948 if (np->msi_flags & NV_MSI_X_CAPABLE) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003949 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003950 np->msi_x_entry[i].entry = i;
Szymon Janc34cf97e2010-11-27 08:39:46 +00003951 ret = pci_enable_msix(np->pci_dev, np->msi_x_entry, (np->msi_flags & NV_MSI_X_VECTORS_MASK));
3952 if (ret == 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003953 np->msi_flags |= NV_MSI_X_ENABLED;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003954 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT && !intr_test) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003955 /* Request irq for rx handling */
Yinghai Luddb213f2009-02-06 01:29:23 -08003956 sprintf(np->name_rx, "%s-rx", dev->name);
3957 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08003958 nv_nic_irq_rx, IRQF_SHARED, np->name_rx, dev) != 0) {
Joe Perches1d397f32010-11-29 07:41:57 +00003959 netdev_info(dev,
3960 "request_irq failed for rx %d\n",
3961 ret);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003962 pci_disable_msix(np->pci_dev);
3963 np->msi_flags &= ~NV_MSI_X_ENABLED;
3964 goto out_err;
3965 }
3966 /* Request irq for tx handling */
Yinghai Luddb213f2009-02-06 01:29:23 -08003967 sprintf(np->name_tx, "%s-tx", dev->name);
3968 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08003969 nv_nic_irq_tx, IRQF_SHARED, np->name_tx, dev) != 0) {
Joe Perches1d397f32010-11-29 07:41:57 +00003970 netdev_info(dev,
3971 "request_irq failed for tx %d\n",
3972 ret);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003973 pci_disable_msix(np->pci_dev);
3974 np->msi_flags &= ~NV_MSI_X_ENABLED;
3975 goto out_free_rx;
3976 }
3977 /* Request irq for link and timer handling */
Yinghai Luddb213f2009-02-06 01:29:23 -08003978 sprintf(np->name_other, "%s-other", dev->name);
3979 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08003980 nv_nic_irq_other, IRQF_SHARED, np->name_other, dev) != 0) {
Joe Perches1d397f32010-11-29 07:41:57 +00003981 netdev_info(dev,
3982 "request_irq failed for link %d\n",
3983 ret);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003984 pci_disable_msix(np->pci_dev);
3985 np->msi_flags &= ~NV_MSI_X_ENABLED;
3986 goto out_free_tx;
3987 }
3988 /* map interrupts to their respective vector */
3989 writel(0, base + NvRegMSIXMap0);
3990 writel(0, base + NvRegMSIXMap1);
3991 set_msix_vector_map(dev, NV_MSI_X_VECTOR_RX, NVREG_IRQ_RX_ALL);
3992 set_msix_vector_map(dev, NV_MSI_X_VECTOR_TX, NVREG_IRQ_TX_ALL);
3993 set_msix_vector_map(dev, NV_MSI_X_VECTOR_OTHER, NVREG_IRQ_OTHER);
3994 } else {
3995 /* Request irq for all interrupts */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003996 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 +00003997 netdev_info(dev,
3998 "request_irq failed %d\n",
3999 ret);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04004000 pci_disable_msix(np->pci_dev);
4001 np->msi_flags &= ~NV_MSI_X_ENABLED;
4002 goto out_err;
4003 }
4004
4005 /* map interrupts to vector 0 */
4006 writel(0, base + NvRegMSIXMap0);
4007 writel(0, base + NvRegMSIXMap1);
4008 }
Mike Ditto89328782011-11-16 12:15:11 +00004009 netdev_info(dev, "MSI-X enabled\n");
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04004010 }
4011 }
4012 if (ret != 0 && np->msi_flags & NV_MSI_CAPABLE) {
Szymon Janc34cf97e2010-11-27 08:39:46 +00004013 ret = pci_enable_msi(np->pci_dev);
4014 if (ret == 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04004015 np->msi_flags |= NV_MSI_ENABLED;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05004016 if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0) {
Joe Perches1d397f32010-11-29 07:41:57 +00004017 netdev_info(dev, "request_irq failed %d\n",
4018 ret);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04004019 pci_disable_msi(np->pci_dev);
4020 np->msi_flags &= ~NV_MSI_ENABLED;
4021 goto out_err;
4022 }
4023
4024 /* map interrupts to vector 0 */
4025 writel(0, base + NvRegMSIMap0);
4026 writel(0, base + NvRegMSIMap1);
4027 /* enable msi vector 0 */
4028 writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask);
Mike Ditto89328782011-11-16 12:15:11 +00004029 netdev_info(dev, "MSI enabled\n");
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04004030 }
4031 }
4032 if (ret != 0) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05004033 if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04004034 goto out_err;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004035
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04004036 }
4037
4038 return 0;
4039out_free_tx:
4040 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector, dev);
4041out_free_rx:
4042 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector, dev);
4043out_err:
4044 return 1;
4045}
4046
4047static void nv_free_irq(struct net_device *dev)
4048{
4049 struct fe_priv *np = get_nvpriv(dev);
4050 int i;
4051
4052 if (np->msi_flags & NV_MSI_X_ENABLED) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00004053 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04004054 free_irq(np->msi_x_entry[i].vector, dev);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04004055 pci_disable_msix(np->pci_dev);
4056 np->msi_flags &= ~NV_MSI_X_ENABLED;
4057 } else {
4058 free_irq(np->pci_dev->irq, dev);
4059 if (np->msi_flags & NV_MSI_ENABLED) {
4060 pci_disable_msi(np->pci_dev);
4061 np->msi_flags &= ~NV_MSI_ENABLED;
4062 }
4063 }
4064}
4065
Linus Torvalds1da177e2005-04-16 15:20:36 -07004066static void nv_do_nic_poll(unsigned long data)
4067{
4068 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004069 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004070 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004071 u32 mask = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004072
Linus Torvalds1da177e2005-04-16 15:20:36 -07004073 /*
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004074 * First disable irq(s) and then
Linus Torvalds1da177e2005-04-16 15:20:36 -07004075 * reenable interrupts on the nic, we have to do this before calling
4076 * nv_nic_irq because that may decide to do otherwise
4077 */
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004078
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004079 if (!using_multi_irqs(dev)) {
4080 if (np->msi_flags & NV_MSI_X_ENABLED)
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004081 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004082 else
Manfred Spraula7475902007-10-17 21:52:33 +02004083 disable_irq_lockdep(np->pci_dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004084 mask = np->irqmask;
4085 } else {
4086 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004087 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004088 mask |= NVREG_IRQ_RX_ALL;
4089 }
4090 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004091 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004092 mask |= NVREG_IRQ_TX_ALL;
4093 }
4094 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004095 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004096 mask |= NVREG_IRQ_OTHER;
4097 }
4098 }
Manfred Spraula7475902007-10-17 21:52:33 +02004099 /* disable_irq() contains synchronize_irq, thus no irq handler can run now */
4100
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004101 if (np->recover_error) {
4102 np->recover_error = 0;
Joe Perches1d397f32010-11-29 07:41:57 +00004103 netdev_info(dev, "MAC in recoverable error state\n");
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004104 if (netif_running(dev)) {
4105 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004106 netif_addr_lock(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004107 spin_lock(&np->lock);
4108 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004109 nv_stop_rxtx(dev);
Ayaz Abdulladaa91a92009-02-07 00:25:00 -08004110 if (np->driver_data & DEV_HAS_POWER_CNTRL)
4111 nv_mac_reset(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004112 nv_txrx_reset(dev);
4113 /* drain rx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004114 nv_drain_rxtx(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004115 /* reinit driver view of the rx queue */
4116 set_bufsize(dev);
4117 if (nv_init_ring(dev)) {
4118 if (!np->in_shutdown)
4119 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
4120 }
4121 /* reinit nic view of the rx queue */
4122 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4123 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00004124 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004125 base + NvRegRingSizes);
4126 pci_push(base);
4127 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4128 pci_push(base);
Ayaz Abdulladaa91a92009-02-07 00:25:00 -08004129 /* clear interrupts */
4130 if (!(np->msi_flags & NV_MSI_X_ENABLED))
4131 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4132 else
4133 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004134
4135 /* restart rx engine */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004136 nv_start_rxtx(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004137 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07004138 netif_addr_unlock(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05004139 netif_tx_unlock_bh(dev);
4140 }
4141 }
4142
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004143 writel(mask, base + NvRegIrqMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004144 pci_push(base);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004145
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004146 if (!using_multi_irqs(dev)) {
Yinghai Lu79d30a52009-02-06 01:30:01 -08004147 np->nic_poll_irq = 0;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004148 if (nv_optimized(np))
Ayaz Abdullafcc5f262007-03-23 05:49:37 -05004149 nv_nic_irq_optimized(0, dev);
4150 else
4151 nv_nic_irq(0, dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004152 if (np->msi_flags & NV_MSI_X_ENABLED)
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004153 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07004154 else
Manfred Spraula7475902007-10-17 21:52:33 +02004155 enable_irq_lockdep(np->pci_dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004156 } else {
4157 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
Yinghai Lu79d30a52009-02-06 01:30:01 -08004158 np->nic_poll_irq &= ~NVREG_IRQ_RX_ALL;
David Howells7d12e782006-10-05 14:55:46 +01004159 nv_nic_irq_rx(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004160 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004161 }
4162 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
Yinghai Lu79d30a52009-02-06 01:30:01 -08004163 np->nic_poll_irq &= ~NVREG_IRQ_TX_ALL;
David Howells7d12e782006-10-05 14:55:46 +01004164 nv_nic_irq_tx(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004165 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004166 }
4167 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
Yinghai Lu79d30a52009-02-06 01:30:01 -08004168 np->nic_poll_irq &= ~NVREG_IRQ_OTHER;
David Howells7d12e782006-10-05 14:55:46 +01004169 nv_nic_irq_other(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004170 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004171 }
4172 }
Yinghai Lu79d30a52009-02-06 01:30:01 -08004173
Linus Torvalds1da177e2005-04-16 15:20:36 -07004174}
4175
Michal Schmidt2918c352005-05-12 19:42:06 -04004176#ifdef CONFIG_NET_POLL_CONTROLLER
4177static void nv_poll_controller(struct net_device *dev)
4178{
4179 nv_do_nic_poll((unsigned long) dev);
4180}
4181#endif
4182
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004183static void nv_do_stats_poll(unsigned long data)
david decotignyf5d827a2011-11-16 12:15:13 +00004184 __acquires(&netdev_priv(dev)->hwstats_lock)
4185 __releases(&netdev_priv(dev)->hwstats_lock)
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004186{
4187 struct net_device *dev = (struct net_device *) data;
4188 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004189
david decotignyf5d827a2011-11-16 12:15:13 +00004190 /* If lock is currently taken, the stats are being refreshed
4191 * and hence fresh enough */
4192 if (spin_trylock(&np->hwstats_lock)) {
4193 nv_update_stats(dev);
4194 spin_unlock(&np->hwstats_lock);
4195 }
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004196
4197 if (!np->in_shutdown)
Daniel Drakebfebbb82008-03-18 11:07:18 +00004198 mod_timer(&np->stats_poll,
4199 round_jiffies(jiffies + STATS_INTERVAL));
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004200}
4201
Linus Torvalds1da177e2005-04-16 15:20:36 -07004202static void nv_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
4203{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004204 struct fe_priv *np = netdev_priv(dev);
Rick Jones68aad782011-11-07 13:29:27 +00004205 strlcpy(info->driver, DRV_NAME, sizeof(info->driver));
4206 strlcpy(info->version, FORCEDETH_VERSION, sizeof(info->version));
4207 strlcpy(info->bus_info, pci_name(np->pci_dev), sizeof(info->bus_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208}
4209
4210static void nv_get_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
4211{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004212 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004213 wolinfo->supported = WAKE_MAGIC;
4214
4215 spin_lock_irq(&np->lock);
4216 if (np->wolenabled)
4217 wolinfo->wolopts = WAKE_MAGIC;
4218 spin_unlock_irq(&np->lock);
4219}
4220
4221static int nv_set_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
4222{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004223 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004225 u32 flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004226
Linus Torvalds1da177e2005-04-16 15:20:36 -07004227 if (wolinfo->wolopts == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228 np->wolenabled = 0;
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004229 } else if (wolinfo->wolopts & WAKE_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004230 np->wolenabled = 1;
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004231 flags = NVREG_WAKEUPFLAGS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232 }
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004233 if (netif_running(dev)) {
4234 spin_lock_irq(&np->lock);
4235 writel(flags, base + NvRegWakeUpFlags);
4236 spin_unlock_irq(&np->lock);
4237 }
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00004238 device_set_wakeup_enable(&np->pci_dev->dev, np->wolenabled);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004239 return 0;
4240}
4241
4242static int nv_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
4243{
4244 struct fe_priv *np = netdev_priv(dev);
David Decotigny70739492011-04-27 18:32:40 +00004245 u32 speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004246 int adv;
4247
4248 spin_lock_irq(&np->lock);
4249 ecmd->port = PORT_MII;
4250 if (!netif_running(dev)) {
4251 /* We do not track link speed / duplex setting if the
4252 * interface is disabled. Force a link check */
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004253 if (nv_update_linkspeed(dev)) {
4254 if (!netif_carrier_ok(dev))
4255 netif_carrier_on(dev);
4256 } else {
4257 if (netif_carrier_ok(dev))
4258 netif_carrier_off(dev);
4259 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004260 }
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004261
4262 if (netif_carrier_ok(dev)) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00004263 switch (np->linkspeed & (NVREG_LINKSPEED_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004264 case NVREG_LINKSPEED_10:
David Decotigny70739492011-04-27 18:32:40 +00004265 speed = SPEED_10;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004266 break;
4267 case NVREG_LINKSPEED_100:
David Decotigny70739492011-04-27 18:32:40 +00004268 speed = SPEED_100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004269 break;
4270 case NVREG_LINKSPEED_1000:
David Decotigny70739492011-04-27 18:32:40 +00004271 speed = SPEED_1000;
4272 break;
4273 default:
4274 speed = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004275 break;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004276 }
4277 ecmd->duplex = DUPLEX_HALF;
4278 if (np->duplex)
4279 ecmd->duplex = DUPLEX_FULL;
4280 } else {
David Decotigny70739492011-04-27 18:32:40 +00004281 speed = -1;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004282 ecmd->duplex = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283 }
David Decotigny70739492011-04-27 18:32:40 +00004284 ethtool_cmd_speed_set(ecmd, speed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004285 ecmd->autoneg = np->autoneg;
4286
4287 ecmd->advertising = ADVERTISED_MII;
4288 if (np->autoneg) {
4289 ecmd->advertising |= ADVERTISED_Autoneg;
4290 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004291 if (adv & ADVERTISE_10HALF)
4292 ecmd->advertising |= ADVERTISED_10baseT_Half;
4293 if (adv & ADVERTISE_10FULL)
4294 ecmd->advertising |= ADVERTISED_10baseT_Full;
4295 if (adv & ADVERTISE_100HALF)
4296 ecmd->advertising |= ADVERTISED_100baseT_Half;
4297 if (adv & ADVERTISE_100FULL)
4298 ecmd->advertising |= ADVERTISED_100baseT_Full;
4299 if (np->gigabit == PHY_GIGABIT) {
4300 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
4301 if (adv & ADVERTISE_1000FULL)
4302 ecmd->advertising |= ADVERTISED_1000baseT_Full;
4303 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004304 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004305 ecmd->supported = (SUPPORTED_Autoneg |
4306 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
4307 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
4308 SUPPORTED_MII);
4309 if (np->gigabit == PHY_GIGABIT)
4310 ecmd->supported |= SUPPORTED_1000baseT_Full;
4311
4312 ecmd->phy_address = np->phyaddr;
4313 ecmd->transceiver = XCVR_EXTERNAL;
4314
4315 /* ignore maxtxpkt, maxrxpkt for now */
4316 spin_unlock_irq(&np->lock);
4317 return 0;
4318}
4319
4320static int nv_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
4321{
4322 struct fe_priv *np = netdev_priv(dev);
David Decotigny25db0332011-04-27 18:32:39 +00004323 u32 speed = ethtool_cmd_speed(ecmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004324
4325 if (ecmd->port != PORT_MII)
4326 return -EINVAL;
4327 if (ecmd->transceiver != XCVR_EXTERNAL)
4328 return -EINVAL;
4329 if (ecmd->phy_address != np->phyaddr) {
4330 /* TODO: support switching between multiple phys. Should be
4331 * trivial, but not enabled due to lack of test hardware. */
4332 return -EINVAL;
4333 }
4334 if (ecmd->autoneg == AUTONEG_ENABLE) {
4335 u32 mask;
4336
4337 mask = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
4338 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full;
4339 if (np->gigabit == PHY_GIGABIT)
4340 mask |= ADVERTISED_1000baseT_Full;
4341
4342 if ((ecmd->advertising & mask) == 0)
4343 return -EINVAL;
4344
4345 } else if (ecmd->autoneg == AUTONEG_DISABLE) {
4346 /* Note: autonegotiation disable, speed 1000 intentionally
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004347 * forbidden - no one should need that. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07004348
David Decotigny25db0332011-04-27 18:32:39 +00004349 if (speed != SPEED_10 && speed != SPEED_100)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004350 return -EINVAL;
4351 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
4352 return -EINVAL;
4353 } else {
4354 return -EINVAL;
4355 }
4356
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004357 netif_carrier_off(dev);
4358 if (netif_running(dev)) {
Tobias Diedrich97bff092008-07-03 23:54:56 -07004359 unsigned long flags;
4360
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004361 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004362 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004363 netif_addr_lock(dev);
Tobias Diedrich97bff092008-07-03 23:54:56 -07004364 /* with plain spinlock lockdep complains */
4365 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004366 /* stop engines */
Tobias Diedrich97bff092008-07-03 23:54:56 -07004367 /* FIXME:
4368 * this can take some time, and interrupts are disabled
4369 * due to spin_lock_irqsave, but let's hope no daemon
4370 * is going to change the settings very often...
4371 * Worst case:
4372 * NV_RXSTOP_DELAY1MAX + NV_TXSTOP_DELAY1MAX
4373 * + some minor delays, which is up to a second approximately
4374 */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004375 nv_stop_rxtx(dev);
Tobias Diedrich97bff092008-07-03 23:54:56 -07004376 spin_unlock_irqrestore(&np->lock, flags);
David S. Millere308a5d2008-07-15 00:13:44 -07004377 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004378 netif_tx_unlock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004379 }
4380
Linus Torvalds1da177e2005-04-16 15:20:36 -07004381 if (ecmd->autoneg == AUTONEG_ENABLE) {
4382 int adv, bmcr;
4383
4384 np->autoneg = 1;
4385
4386 /* advertise only what has been requested */
4387 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004388 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004389 if (ecmd->advertising & ADVERTISED_10baseT_Half)
4390 adv |= ADVERTISE_10HALF;
4391 if (ecmd->advertising & ADVERTISED_10baseT_Full)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004392 adv |= ADVERTISE_10FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004393 if (ecmd->advertising & ADVERTISED_100baseT_Half)
4394 adv |= ADVERTISE_100HALF;
4395 if (ecmd->advertising & ADVERTISED_100baseT_Full)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004396 adv |= ADVERTISE_100FULL;
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004397 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 -04004398 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4399 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
4400 adv |= ADVERTISE_PAUSE_ASYM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004401 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4402
4403 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004404 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004405 adv &= ~ADVERTISE_1000FULL;
4406 if (ecmd->advertising & ADVERTISED_1000baseT_Full)
4407 adv |= ADVERTISE_1000FULL;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004408 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004409 }
4410
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004411 if (netif_running(dev))
Joe Perches1d397f32010-11-29 07:41:57 +00004412 netdev_info(dev, "link down\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07004413 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004414 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
4415 bmcr |= BMCR_ANENABLE;
4416 /* reset the phy in order for settings to stick,
4417 * and cause autoneg to start */
4418 if (phy_reset(dev, bmcr)) {
Joe Perches1d397f32010-11-29 07:41:57 +00004419 netdev_info(dev, "phy reset failed\n");
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004420 return -EINVAL;
4421 }
4422 } else {
4423 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4424 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4425 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004426 } else {
4427 int adv, bmcr;
4428
4429 np->autoneg = 0;
4430
4431 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004432 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
David Decotigny25db0332011-04-27 18:32:39 +00004433 if (speed == SPEED_10 && ecmd->duplex == DUPLEX_HALF)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004434 adv |= ADVERTISE_10HALF;
David Decotigny25db0332011-04-27 18:32:39 +00004435 if (speed == SPEED_10 && ecmd->duplex == DUPLEX_FULL)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004436 adv |= ADVERTISE_10FULL;
David Decotigny25db0332011-04-27 18:32:39 +00004437 if (speed == SPEED_100 && ecmd->duplex == DUPLEX_HALF)
Linus Torvalds1da177e2005-04-16 15:20:36 -07004438 adv |= ADVERTISE_100HALF;
David Decotigny25db0332011-04-27 18:32:39 +00004439 if (speed == SPEED_100 && ecmd->duplex == DUPLEX_FULL)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004440 adv |= ADVERTISE_100FULL;
4441 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004442 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 -04004443 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4444 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
4445 }
4446 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) {
4447 adv |= ADVERTISE_PAUSE_ASYM;
4448 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
4449 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004450 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4451 np->fixed_mode = adv;
4452
4453 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004454 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004455 adv &= ~ADVERTISE_1000FULL;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004456 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004457 }
4458
4459 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004460 bmcr &= ~(BMCR_ANENABLE|BMCR_SPEED100|BMCR_SPEED1000|BMCR_FULLDPLX);
4461 if (np->fixed_mode & (ADVERTISE_10FULL|ADVERTISE_100FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004462 bmcr |= BMCR_FULLDPLX;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004463 if (np->fixed_mode & (ADVERTISE_100HALF|ADVERTISE_100FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004464 bmcr |= BMCR_SPEED100;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004465 if (np->phy_oui == PHY_OUI_MARVELL) {
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004466 /* reset the phy in order for forced mode 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 Abdullaf9430a02006-06-10 22:47:47 -04004469 return -EINVAL;
4470 }
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004471 } else {
4472 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4473 if (netif_running(dev)) {
4474 /* Wait a bit and then reconfigure the nic. */
4475 udelay(10);
4476 nv_linkchange(dev);
4477 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004478 }
4479 }
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004480
4481 if (netif_running(dev)) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004482 nv_start_rxtx(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004483 nv_enable_irq(dev);
4484 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004485
4486 return 0;
4487}
4488
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004489#define FORCEDETH_REGS_VER 1
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004490
4491static int nv_get_regs_len(struct net_device *dev)
4492{
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004493 struct fe_priv *np = netdev_priv(dev);
4494 return np->register_size;
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004495}
4496
4497static void nv_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *buf)
4498{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004499 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004500 u8 __iomem *base = get_hwbase(dev);
4501 u32 *rbuf = buf;
4502 int i;
4503
4504 regs->version = FORCEDETH_REGS_VER;
4505 spin_lock_irq(&np->lock);
david decotignyba9aa132012-08-24 17:22:51 +00004506 for (i = 0; i < np->register_size/sizeof(u32); i++)
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004507 rbuf[i] = readl(base + i*sizeof(u32));
4508 spin_unlock_irq(&np->lock);
4509}
4510
4511static int nv_nway_reset(struct net_device *dev)
4512{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004513 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004514 int ret;
4515
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004516 if (np->autoneg) {
4517 int bmcr;
4518
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004519 netif_carrier_off(dev);
4520 if (netif_running(dev)) {
4521 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004522 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004523 netif_addr_lock(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004524 spin_lock(&np->lock);
4525 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004526 nv_stop_rxtx(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004527 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07004528 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004529 netif_tx_unlock_bh(dev);
Joe Perches1d397f32010-11-29 07:41:57 +00004530 netdev_info(dev, "link down\n");
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004531 }
4532
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004533 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004534 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
4535 bmcr |= BMCR_ANENABLE;
4536 /* reset the phy in order for settings to stick*/
4537 if (phy_reset(dev, bmcr)) {
Joe Perches1d397f32010-11-29 07:41:57 +00004538 netdev_info(dev, "phy reset failed\n");
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004539 return -EINVAL;
4540 }
4541 } else {
4542 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4543 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4544 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004545
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004546 if (netif_running(dev)) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004547 nv_start_rxtx(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004548 nv_enable_irq(dev);
4549 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004550 ret = 0;
4551 } else {
4552 ret = -EINVAL;
4553 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004554
4555 return ret;
4556}
4557
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004558static void nv_get_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
4559{
4560 struct fe_priv *np = netdev_priv(dev);
4561
4562 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 -04004563 ring->tx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
4564
4565 ring->rx_pending = np->rx_ring_size;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004566 ring->tx_pending = np->tx_ring_size;
4567}
4568
4569static int nv_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
4570{
4571 struct fe_priv *np = netdev_priv(dev);
4572 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004573 u8 *rxtx_ring, *rx_skbuff, *tx_skbuff;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004574 dma_addr_t ring_addr;
4575
4576 if (ring->rx_pending < RX_RING_MIN ||
4577 ring->tx_pending < TX_RING_MIN ||
4578 ring->rx_mini_pending != 0 ||
4579 ring->rx_jumbo_pending != 0 ||
4580 (np->desc_ver == DESC_VER_1 &&
4581 (ring->rx_pending > RING_MAX_DESC_VER_1 ||
4582 ring->tx_pending > RING_MAX_DESC_VER_1)) ||
4583 (np->desc_ver != DESC_VER_1 &&
4584 (ring->rx_pending > RING_MAX_DESC_VER_2_3 ||
4585 ring->tx_pending > RING_MAX_DESC_VER_2_3))) {
4586 return -EINVAL;
4587 }
4588
4589 /* allocate new rings */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004590 if (!nv_optimized(np)) {
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004591 rxtx_ring = pci_alloc_consistent(np->pci_dev,
4592 sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
4593 &ring_addr);
4594 } else {
4595 rxtx_ring = pci_alloc_consistent(np->pci_dev,
4596 sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
4597 &ring_addr);
4598 }
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004599 rx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->rx_pending, GFP_KERNEL);
4600 tx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->tx_pending, GFP_KERNEL);
4601 if (!rxtx_ring || !rx_skbuff || !tx_skbuff) {
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004602 /* fall back to old rings */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004603 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004604 if (rxtx_ring)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004605 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
4606 rxtx_ring, ring_addr);
4607 } else {
4608 if (rxtx_ring)
4609 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
4610 rxtx_ring, ring_addr);
4611 }
Szymon Janc9b03b062010-11-27 08:39:44 +00004612
4613 kfree(rx_skbuff);
4614 kfree(tx_skbuff);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004615 goto exit;
4616 }
4617
4618 if (netif_running(dev)) {
4619 nv_disable_irq(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00004620 nv_napi_disable(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004621 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004622 netif_addr_lock(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004623 spin_lock(&np->lock);
4624 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004625 nv_stop_rxtx(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004626 nv_txrx_reset(dev);
4627 /* drain queues */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004628 nv_drain_rxtx(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004629 /* delete queues */
4630 free_rings(dev);
4631 }
4632
4633 /* set new values */
4634 np->rx_ring_size = ring->rx_pending;
4635 np->tx_ring_size = ring->tx_pending;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004636
4637 if (!nv_optimized(np)) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00004638 np->rx_ring.orig = (struct ring_desc *)rxtx_ring;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004639 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
4640 } else {
Szymon Janc78aea4f2010-11-27 08:39:43 +00004641 np->rx_ring.ex = (struct ring_desc_ex *)rxtx_ring;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004642 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
4643 }
Szymon Janc78aea4f2010-11-27 08:39:43 +00004644 np->rx_skb = (struct nv_skb_map *)rx_skbuff;
4645 np->tx_skb = (struct nv_skb_map *)tx_skbuff;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004646 np->ring_addr = ring_addr;
4647
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004648 memset(np->rx_skb, 0, sizeof(struct nv_skb_map) * np->rx_ring_size);
4649 memset(np->tx_skb, 0, sizeof(struct nv_skb_map) * np->tx_ring_size);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004650
4651 if (netif_running(dev)) {
4652 /* reinit driver view of the queues */
4653 set_bufsize(dev);
4654 if (nv_init_ring(dev)) {
4655 if (!np->in_shutdown)
4656 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
4657 }
4658
4659 /* reinit nic view of the queues */
4660 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4661 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00004662 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004663 base + NvRegRingSizes);
4664 pci_push(base);
4665 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4666 pci_push(base);
4667
4668 /* restart engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004669 nv_start_rxtx(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004670 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07004671 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004672 netif_tx_unlock_bh(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00004673 nv_napi_enable(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004674 nv_enable_irq(dev);
4675 }
4676 return 0;
4677exit:
4678 return -ENOMEM;
4679}
4680
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004681static void nv_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
4682{
4683 struct fe_priv *np = netdev_priv(dev);
4684
4685 pause->autoneg = (np->pause_flags & NV_PAUSEFRAME_AUTONEG) != 0;
4686 pause->rx_pause = (np->pause_flags & NV_PAUSEFRAME_RX_ENABLE) != 0;
4687 pause->tx_pause = (np->pause_flags & NV_PAUSEFRAME_TX_ENABLE) != 0;
4688}
4689
4690static int nv_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
4691{
4692 struct fe_priv *np = netdev_priv(dev);
4693 int adv, bmcr;
4694
4695 if ((!np->autoneg && np->duplex == 0) ||
4696 (np->autoneg && !pause->autoneg && np->duplex == 0)) {
Joe Perches1d397f32010-11-29 07:41:57 +00004697 netdev_info(dev, "can not set pause settings when forced link is in half duplex\n");
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004698 return -EINVAL;
4699 }
4700 if (pause->tx_pause && !(np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)) {
Joe Perches1d397f32010-11-29 07:41:57 +00004701 netdev_info(dev, "hardware does not support tx pause frames\n");
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004702 return -EINVAL;
4703 }
4704
4705 netif_carrier_off(dev);
4706 if (netif_running(dev)) {
4707 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004708 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004709 netif_addr_lock(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004710 spin_lock(&np->lock);
4711 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004712 nv_stop_rxtx(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004713 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07004714 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004715 netif_tx_unlock_bh(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004716 }
4717
4718 np->pause_flags &= ~(NV_PAUSEFRAME_RX_REQ|NV_PAUSEFRAME_TX_REQ);
4719 if (pause->rx_pause)
4720 np->pause_flags |= NV_PAUSEFRAME_RX_REQ;
4721 if (pause->tx_pause)
4722 np->pause_flags |= NV_PAUSEFRAME_TX_REQ;
4723
4724 if (np->autoneg && pause->autoneg) {
4725 np->pause_flags |= NV_PAUSEFRAME_AUTONEG;
4726
4727 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
4728 adv &= ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
Lucas De Marchi25985ed2011-03-30 22:57:33 -03004729 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 -04004730 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4731 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
4732 adv |= ADVERTISE_PAUSE_ASYM;
4733 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4734
4735 if (netif_running(dev))
Joe Perches1d397f32010-11-29 07:41:57 +00004736 netdev_info(dev, "link down\n");
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004737 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
4738 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4739 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4740 } else {
4741 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
4742 if (pause->rx_pause)
4743 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
4744 if (pause->tx_pause)
4745 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
4746
4747 if (!netif_running(dev))
4748 nv_update_linkspeed(dev);
4749 else
4750 nv_update_pause(dev, np->pause_flags);
4751 }
4752
4753 if (netif_running(dev)) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004754 nv_start_rxtx(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004755 nv_enable_irq(dev);
4756 }
4757 return 0;
4758}
4759
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004760static int nv_set_loopback(struct net_device *dev, netdev_features_t features)
Sanjay Hortikare19df762011-11-11 16:11:21 +00004761{
4762 struct fe_priv *np = netdev_priv(dev);
4763 unsigned long flags;
4764 u32 miicontrol;
4765 int err, retval = 0;
4766
4767 spin_lock_irqsave(&np->lock, flags);
4768 miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
4769 if (features & NETIF_F_LOOPBACK) {
4770 if (miicontrol & BMCR_LOOPBACK) {
4771 spin_unlock_irqrestore(&np->lock, flags);
4772 netdev_info(dev, "Loopback already enabled\n");
4773 return 0;
4774 }
4775 nv_disable_irq(dev);
4776 /* Turn on loopback mode */
4777 miicontrol |= BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000;
4778 err = mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol);
4779 if (err) {
4780 retval = PHY_ERROR;
4781 spin_unlock_irqrestore(&np->lock, flags);
4782 phy_init(dev);
4783 } else {
4784 if (netif_running(dev)) {
4785 /* Force 1000 Mbps full-duplex */
4786 nv_force_linkspeed(dev, NVREG_LINKSPEED_1000,
4787 1);
4788 /* Force link up */
4789 netif_carrier_on(dev);
4790 }
4791 spin_unlock_irqrestore(&np->lock, flags);
4792 netdev_info(dev,
4793 "Internal PHY loopback mode enabled.\n");
4794 }
4795 } else {
4796 if (!(miicontrol & BMCR_LOOPBACK)) {
4797 spin_unlock_irqrestore(&np->lock, flags);
4798 netdev_info(dev, "Loopback already disabled\n");
4799 return 0;
4800 }
4801 nv_disable_irq(dev);
4802 /* Turn off loopback */
4803 spin_unlock_irqrestore(&np->lock, flags);
4804 netdev_info(dev, "Internal PHY loopback mode disabled.\n");
4805 phy_init(dev);
4806 }
4807 msleep(500);
4808 spin_lock_irqsave(&np->lock, flags);
4809 nv_enable_irq(dev);
4810 spin_unlock_irqrestore(&np->lock, flags);
4811
4812 return retval;
4813}
4814
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004815static netdev_features_t nv_fix_features(struct net_device *dev,
4816 netdev_features_t features)
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004817{
Michał Mirosław569e1462011-04-15 04:50:49 +00004818 /* vlan is dependent on rx checksum offload */
Patrick McHardyf6469682013-04-19 02:04:27 +00004819 if (features & (NETIF_F_HW_VLAN_CTAG_TX|NETIF_F_HW_VLAN_CTAG_RX))
Michał Mirosław569e1462011-04-15 04:50:49 +00004820 features |= NETIF_F_RXCSUM;
4821
4822 return features;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004823}
4824
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004825static void nv_vlan_mode(struct net_device *dev, netdev_features_t features)
Jiri Pirko3326c782011-07-20 04:54:38 +00004826{
4827 struct fe_priv *np = get_nvpriv(dev);
4828
4829 spin_lock_irq(&np->lock);
4830
Patrick McHardyf6469682013-04-19 02:04:27 +00004831 if (features & NETIF_F_HW_VLAN_CTAG_RX)
Jiri Pirko3326c782011-07-20 04:54:38 +00004832 np->txrxctl_bits |= NVREG_TXRXCTL_VLANSTRIP;
4833 else
4834 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANSTRIP;
4835
Patrick McHardyf6469682013-04-19 02:04:27 +00004836 if (features & NETIF_F_HW_VLAN_CTAG_TX)
Jiri Pirko3326c782011-07-20 04:54:38 +00004837 np->txrxctl_bits |= NVREG_TXRXCTL_VLANINS;
4838 else
4839 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANINS;
4840
4841 writel(np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4842
4843 spin_unlock_irq(&np->lock);
4844}
4845
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004846static int nv_set_features(struct net_device *dev, netdev_features_t features)
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004847{
4848 struct fe_priv *np = netdev_priv(dev);
4849 u8 __iomem *base = get_hwbase(dev);
Michał Mirosławc8f44af2011-11-15 15:29:55 +00004850 netdev_features_t changed = dev->features ^ features;
Sanjay Hortikare19df762011-11-11 16:11:21 +00004851 int retval;
4852
4853 if ((changed & NETIF_F_LOOPBACK) && netif_running(dev)) {
4854 retval = nv_set_loopback(dev, features);
4855 if (retval != 0)
4856 return retval;
4857 }
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004858
Michał Mirosław569e1462011-04-15 04:50:49 +00004859 if (changed & NETIF_F_RXCSUM) {
4860 spin_lock_irq(&np->lock);
4861
4862 if (features & NETIF_F_RXCSUM)
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004863 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
Michał Mirosław569e1462011-04-15 04:50:49 +00004864 else
4865 np->txrxctl_bits &= ~NVREG_TXRXCTL_RXCHECK;
4866
4867 if (netif_running(dev))
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004868 writel(np->txrxctl_bits, base + NvRegTxRxControl);
Michał Mirosław569e1462011-04-15 04:50:49 +00004869
4870 spin_unlock_irq(&np->lock);
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004871 }
4872
Patrick McHardyf6469682013-04-19 02:04:27 +00004873 if (changed & (NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX))
Jiri Pirko3326c782011-07-20 04:54:38 +00004874 nv_vlan_mode(dev, features);
4875
Michał Mirosław569e1462011-04-15 04:50:49 +00004876 return 0;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004877}
4878
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004879static int nv_get_sset_count(struct net_device *dev, int sset)
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004880{
4881 struct fe_priv *np = netdev_priv(dev);
4882
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004883 switch (sset) {
4884 case ETH_SS_TEST:
4885 if (np->driver_data & DEV_HAS_TEST_EXTENDED)
4886 return NV_TEST_COUNT_EXTENDED;
4887 else
4888 return NV_TEST_COUNT_BASE;
4889 case ETH_SS_STATS:
Ayaz Abdulla8ed14542009-03-05 08:01:49 +00004890 if (np->driver_data & DEV_HAS_STATISTICS_V3)
4891 return NV_DEV_STATISTICS_V3_COUNT;
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004892 else if (np->driver_data & DEV_HAS_STATISTICS_V2)
4893 return NV_DEV_STATISTICS_V2_COUNT;
Ayaz Abdulla8ed14542009-03-05 08:01:49 +00004894 else if (np->driver_data & DEV_HAS_STATISTICS_V1)
4895 return NV_DEV_STATISTICS_V1_COUNT;
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004896 else
4897 return 0;
4898 default:
4899 return -EOPNOTSUPP;
4900 }
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004901}
4902
david decotignyf5d827a2011-11-16 12:15:13 +00004903static void nv_get_ethtool_stats(struct net_device *dev,
4904 struct ethtool_stats *estats, u64 *buffer)
4905 __acquires(&netdev_priv(dev)->hwstats_lock)
4906 __releases(&netdev_priv(dev)->hwstats_lock)
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004907{
4908 struct fe_priv *np = netdev_priv(dev);
4909
david decotignyf5d827a2011-11-16 12:15:13 +00004910 spin_lock_bh(&np->hwstats_lock);
4911 nv_update_stats(dev);
4912 memcpy(buffer, &np->estats,
4913 nv_get_sset_count(dev, ETH_SS_STATS)*sizeof(u64));
4914 spin_unlock_bh(&np->hwstats_lock);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004915}
4916
4917static int nv_link_test(struct net_device *dev)
4918{
4919 struct fe_priv *np = netdev_priv(dev);
4920 int mii_status;
4921
4922 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
4923 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
4924
4925 /* check phy link status */
4926 if (!(mii_status & BMSR_LSTATUS))
4927 return 0;
4928 else
4929 return 1;
4930}
4931
4932static int nv_register_test(struct net_device *dev)
4933{
4934 u8 __iomem *base = get_hwbase(dev);
4935 int i = 0;
4936 u32 orig_read, new_read;
4937
4938 do {
4939 orig_read = readl(base + nv_registers_test[i].reg);
4940
4941 /* xor with mask to toggle bits */
4942 orig_read ^= nv_registers_test[i].mask;
4943
4944 writel(orig_read, base + nv_registers_test[i].reg);
4945
4946 new_read = readl(base + nv_registers_test[i].reg);
4947
4948 if ((new_read & nv_registers_test[i].mask) != (orig_read & nv_registers_test[i].mask))
4949 return 0;
4950
4951 /* restore original value */
4952 orig_read ^= nv_registers_test[i].mask;
4953 writel(orig_read, base + nv_registers_test[i].reg);
4954
4955 } while (nv_registers_test[++i].reg != 0);
4956
4957 return 1;
4958}
4959
4960static int nv_interrupt_test(struct net_device *dev)
4961{
4962 struct fe_priv *np = netdev_priv(dev);
4963 u8 __iomem *base = get_hwbase(dev);
4964 int ret = 1;
4965 int testcnt;
4966 u32 save_msi_flags, save_poll_interval = 0;
4967
4968 if (netif_running(dev)) {
4969 /* free current irq */
4970 nv_free_irq(dev);
4971 save_poll_interval = readl(base+NvRegPollingInterval);
4972 }
4973
4974 /* flag to test interrupt handler */
4975 np->intr_test = 0;
4976
4977 /* setup test irq */
4978 save_msi_flags = np->msi_flags;
4979 np->msi_flags &= ~NV_MSI_X_VECTORS_MASK;
4980 np->msi_flags |= 0x001; /* setup 1 vector */
4981 if (nv_request_irq(dev, 1))
4982 return 0;
4983
4984 /* setup timer interrupt */
4985 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
4986 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
4987
4988 nv_enable_hw_interrupts(dev, NVREG_IRQ_TIMER);
4989
4990 /* wait for at least one interrupt */
4991 msleep(100);
4992
4993 spin_lock_irq(&np->lock);
4994
4995 /* flag should be set within ISR */
4996 testcnt = np->intr_test;
4997 if (!testcnt)
4998 ret = 2;
4999
5000 nv_disable_hw_interrupts(dev, NVREG_IRQ_TIMER);
5001 if (!(np->msi_flags & NV_MSI_X_ENABLED))
5002 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
5003 else
5004 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
5005
5006 spin_unlock_irq(&np->lock);
5007
5008 nv_free_irq(dev);
5009
5010 np->msi_flags = save_msi_flags;
5011
5012 if (netif_running(dev)) {
5013 writel(save_poll_interval, base + NvRegPollingInterval);
5014 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
5015 /* restore original irq */
5016 if (nv_request_irq(dev, 0))
5017 return 0;
5018 }
5019
5020 return ret;
5021}
5022
5023static int nv_loopback_test(struct net_device *dev)
5024{
5025 struct fe_priv *np = netdev_priv(dev);
5026 u8 __iomem *base = get_hwbase(dev);
5027 struct sk_buff *tx_skb, *rx_skb;
5028 dma_addr_t test_dma_addr;
5029 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07005030 u32 flags;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005031 int len, i, pkt_len;
5032 u8 *pkt_data;
5033 u32 filter_flags = 0;
5034 u32 misc1_flags = 0;
5035 int ret = 1;
5036
5037 if (netif_running(dev)) {
5038 nv_disable_irq(dev);
5039 filter_flags = readl(base + NvRegPacketFilterFlags);
5040 misc1_flags = readl(base + NvRegMisc1);
5041 } else {
5042 nv_txrx_reset(dev);
5043 }
5044
5045 /* reinit driver view of the rx queue */
5046 set_bufsize(dev);
5047 nv_init_ring(dev);
5048
5049 /* setup hardware for loopback */
5050 writel(NVREG_MISC1_FORCE, base + NvRegMisc1);
5051 writel(NVREG_PFF_ALWAYS | NVREG_PFF_LOOPBACK, base + NvRegPacketFilterFlags);
5052
5053 /* reinit nic view of the rx queue */
5054 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
5055 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005056 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005057 base + NvRegRingSizes);
5058 pci_push(base);
5059
5060 /* restart rx engine */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005061 nv_start_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005062
5063 /* setup packet for tx */
5064 pkt_len = ETH_DATA_LEN;
Pradeep A. Dalvidae2e9f2012-02-06 11:16:13 +00005065 tx_skb = netdev_alloc_skb(dev, pkt_len);
Jesper Juhl46798c82006-09-25 16:39:24 -07005066 if (!tx_skb) {
Jesper Juhl46798c82006-09-25 16:39:24 -07005067 ret = 0;
5068 goto out;
5069 }
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03005070 test_dma_addr = pci_map_single(np->pci_dev, tx_skb->data,
5071 skb_tailroom(tx_skb),
5072 PCI_DMA_FROMDEVICE);
Larry Finger612a7c42012-12-27 17:25:41 +00005073 if (pci_dma_mapping_error(np->pci_dev,
5074 test_dma_addr)) {
5075 dev_kfree_skb_any(tx_skb);
5076 goto out;
5077 }
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005078 pkt_data = skb_put(tx_skb, pkt_len);
5079 for (i = 0; i < pkt_len; i++)
5080 pkt_data[i] = (u8)(i & 0xff);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005081
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005082 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07005083 np->tx_ring.orig[0].buf = cpu_to_le32(test_dma_addr);
5084 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 -04005085 } else {
Al Viro5bb7ea22007-12-09 16:06:41 +00005086 np->tx_ring.ex[0].bufhigh = cpu_to_le32(dma_high(test_dma_addr));
5087 np->tx_ring.ex[0].buflow = cpu_to_le32(dma_low(test_dma_addr));
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07005088 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 -04005089 }
5090 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
5091 pci_push(get_hwbase(dev));
5092
5093 msleep(500);
5094
5095 /* check for rx of the packet */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005096 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07005097 flags = le32_to_cpu(np->rx_ring.orig[0].flaglen);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005098 len = nv_descr_getlength(&np->rx_ring.orig[0], np->desc_ver);
5099
5100 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07005101 flags = le32_to_cpu(np->rx_ring.ex[0].flaglen);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005102 len = nv_descr_getlength_ex(&np->rx_ring.ex[0], np->desc_ver);
5103 }
5104
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07005105 if (flags & NV_RX_AVAIL) {
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005106 ret = 0;
5107 } else if (np->desc_ver == DESC_VER_1) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07005108 if (flags & NV_RX_ERROR)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005109 ret = 0;
5110 } else {
Szymon Janc78aea4f2010-11-27 08:39:43 +00005111 if (flags & NV_RX2_ERROR)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005112 ret = 0;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005113 }
5114
5115 if (ret) {
5116 if (len != pkt_len) {
5117 ret = 0;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005118 } else {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05005119 rx_skb = np->rx_skb[0].skb;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005120 for (i = 0; i < pkt_len; i++) {
5121 if (rx_skb->data[i] != (u8)(i & 0xff)) {
5122 ret = 0;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005123 break;
5124 }
5125 }
5126 }
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005127 }
5128
Eric Dumazet73a37072009-06-17 21:17:59 +00005129 pci_unmap_single(np->pci_dev, test_dma_addr,
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07005130 (skb_end_pointer(tx_skb) - tx_skb->data),
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005131 PCI_DMA_TODEVICE);
5132 dev_kfree_skb_any(tx_skb);
Jesper Juhl46798c82006-09-25 16:39:24 -07005133 out:
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005134 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005135 nv_stop_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005136 nv_txrx_reset(dev);
5137 /* drain rx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005138 nv_drain_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005139
5140 if (netif_running(dev)) {
5141 writel(misc1_flags, base + NvRegMisc1);
5142 writel(filter_flags, base + NvRegPacketFilterFlags);
5143 nv_enable_irq(dev);
5144 }
5145
5146 return ret;
5147}
5148
5149static void nv_self_test(struct net_device *dev, struct ethtool_test *test, u64 *buffer)
5150{
5151 struct fe_priv *np = netdev_priv(dev);
5152 u8 __iomem *base = get_hwbase(dev);
5153 int result;
Jeff Garzikb9f2c042007-10-03 18:07:32 -07005154 memset(buffer, 0, nv_get_sset_count(dev, ETH_SS_TEST)*sizeof(u64));
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005155
5156 if (!nv_link_test(dev)) {
5157 test->flags |= ETH_TEST_FL_FAILED;
5158 buffer[0] = 1;
5159 }
5160
5161 if (test->flags & ETH_TEST_FL_OFFLINE) {
5162 if (netif_running(dev)) {
5163 netif_stop_queue(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00005164 nv_napi_disable(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10005165 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07005166 netif_addr_lock(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005167 spin_lock_irq(&np->lock);
5168 nv_disable_hw_interrupts(dev, np->irqmask);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005169 if (!(np->msi_flags & NV_MSI_X_ENABLED))
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005170 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005171 else
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005172 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005173 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005174 nv_stop_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005175 nv_txrx_reset(dev);
5176 /* drain rx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005177 nv_drain_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005178 spin_unlock_irq(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07005179 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10005180 netif_tx_unlock_bh(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005181 }
5182
5183 if (!nv_register_test(dev)) {
5184 test->flags |= ETH_TEST_FL_FAILED;
5185 buffer[1] = 1;
5186 }
5187
5188 result = nv_interrupt_test(dev);
5189 if (result != 1) {
5190 test->flags |= ETH_TEST_FL_FAILED;
5191 buffer[2] = 1;
5192 }
5193 if (result == 0) {
5194 /* bail out */
5195 return;
5196 }
5197
5198 if (!nv_loopback_test(dev)) {
5199 test->flags |= ETH_TEST_FL_FAILED;
5200 buffer[3] = 1;
5201 }
5202
5203 if (netif_running(dev)) {
5204 /* reinit driver view of the rx queue */
5205 set_bufsize(dev);
5206 if (nv_init_ring(dev)) {
5207 if (!np->in_shutdown)
5208 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
5209 }
5210 /* reinit nic view of the rx queue */
5211 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
5212 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005213 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005214 base + NvRegRingSizes);
5215 pci_push(base);
5216 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
5217 pci_push(base);
5218 /* restart rx engine */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005219 nv_start_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005220 netif_start_queue(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00005221 nv_napi_enable(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005222 nv_enable_hw_interrupts(dev, np->irqmask);
5223 }
5224 }
5225}
5226
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005227static void nv_get_strings(struct net_device *dev, u32 stringset, u8 *buffer)
5228{
5229 switch (stringset) {
5230 case ETH_SS_STATS:
Jeff Garzikb9f2c042007-10-03 18:07:32 -07005231 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 -04005232 break;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005233 case ETH_SS_TEST:
Jeff Garzikb9f2c042007-10-03 18:07:32 -07005234 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 -04005235 break;
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005236 }
5237}
5238
Jeff Garzik7282d492006-09-13 14:30:00 -04005239static const struct ethtool_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005240 .get_drvinfo = nv_get_drvinfo,
5241 .get_link = ethtool_op_get_link,
5242 .get_wol = nv_get_wol,
5243 .set_wol = nv_set_wol,
5244 .get_settings = nv_get_settings,
5245 .set_settings = nv_set_settings,
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005246 .get_regs_len = nv_get_regs_len,
5247 .get_regs = nv_get_regs,
5248 .nway_reset = nv_nway_reset,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005249 .get_ringparam = nv_get_ringparam,
5250 .set_ringparam = nv_set_ringparam,
Ayaz Abdullab6d07732006-06-10 22:47:42 -04005251 .get_pauseparam = nv_get_pauseparam,
5252 .set_pauseparam = nv_set_pauseparam,
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005253 .get_strings = nv_get_strings,
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005254 .get_ethtool_stats = nv_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07005255 .get_sset_count = nv_get_sset_count,
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005256 .self_test = nv_self_test,
Richard Cochran74913022012-07-22 07:15:42 +00005257 .get_ts_info = ethtool_op_get_ts_info,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005258};
5259
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005260/* The mgmt unit and driver use a semaphore to access the phy during init */
5261static int nv_mgmt_acquire_sema(struct net_device *dev)
5262{
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005263 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005264 u8 __iomem *base = get_hwbase(dev);
5265 int i;
5266 u32 tx_ctrl, mgmt_sema;
5267
5268 for (i = 0; i < 10; i++) {
5269 mgmt_sema = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_SEMA_MASK;
5270 if (mgmt_sema == NVREG_XMITCTL_MGMT_SEMA_FREE)
5271 break;
5272 msleep(500);
5273 }
5274
5275 if (mgmt_sema != NVREG_XMITCTL_MGMT_SEMA_FREE)
5276 return 0;
5277
5278 for (i = 0; i < 2; i++) {
5279 tx_ctrl = readl(base + NvRegTransmitterControl);
5280 tx_ctrl |= NVREG_XMITCTL_HOST_SEMA_ACQ;
5281 writel(tx_ctrl, base + NvRegTransmitterControl);
5282
5283 /* verify that semaphore was acquired */
5284 tx_ctrl = readl(base + NvRegTransmitterControl);
5285 if (((tx_ctrl & NVREG_XMITCTL_HOST_SEMA_MASK) == NVREG_XMITCTL_HOST_SEMA_ACQ) &&
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005286 ((tx_ctrl & NVREG_XMITCTL_MGMT_SEMA_MASK) == NVREG_XMITCTL_MGMT_SEMA_FREE)) {
5287 np->mgmt_sema = 1;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005288 return 1;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005289 } else
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005290 udelay(50);
5291 }
5292
5293 return 0;
5294}
5295
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005296static void nv_mgmt_release_sema(struct net_device *dev)
5297{
5298 struct fe_priv *np = netdev_priv(dev);
5299 u8 __iomem *base = get_hwbase(dev);
5300 u32 tx_ctrl;
5301
5302 if (np->driver_data & DEV_HAS_MGMT_UNIT) {
5303 if (np->mgmt_sema) {
5304 tx_ctrl = readl(base + NvRegTransmitterControl);
5305 tx_ctrl &= ~NVREG_XMITCTL_HOST_SEMA_ACQ;
5306 writel(tx_ctrl, base + NvRegTransmitterControl);
5307 }
5308 }
5309}
5310
5311
5312static int nv_mgmt_get_version(struct net_device *dev)
5313{
5314 struct fe_priv *np = netdev_priv(dev);
5315 u8 __iomem *base = get_hwbase(dev);
5316 u32 data_ready = readl(base + NvRegTransmitterControl);
5317 u32 data_ready2 = 0;
5318 unsigned long start;
5319 int ready = 0;
5320
5321 writel(NVREG_MGMTUNITGETVERSION, base + NvRegMgmtUnitGetVersion);
5322 writel(data_ready ^ NVREG_XMITCTL_DATA_START, base + NvRegTransmitterControl);
5323 start = jiffies;
5324 while (time_before(jiffies, start + 5*HZ)) {
5325 data_ready2 = readl(base + NvRegTransmitterControl);
5326 if ((data_ready & NVREG_XMITCTL_DATA_READY) != (data_ready2 & NVREG_XMITCTL_DATA_READY)) {
5327 ready = 1;
5328 break;
5329 }
5330 schedule_timeout_uninterruptible(1);
5331 }
5332
5333 if (!ready || (data_ready2 & NVREG_XMITCTL_DATA_ERROR))
5334 return 0;
5335
5336 np->mgmt_version = readl(base + NvRegMgmtUnitVersion) & NVREG_MGMTUNITVERSION;
5337
5338 return 1;
5339}
5340
Linus Torvalds1da177e2005-04-16 15:20:36 -07005341static int nv_open(struct net_device *dev)
5342{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005343 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005344 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005345 int ret = 1;
5346 int oom, i;
Ayaz Abdullaa4336862008-04-18 13:50:43 -07005347 u32 low;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005348
Ed Swierkcb52deb2008-12-01 12:24:43 +00005349 /* power up phy */
5350 mii_rw(dev, np->phyaddr, MII_BMCR,
5351 mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ) & ~BMCR_PDOWN);
5352
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00005353 nv_txrx_gate(dev, false);
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005354 /* erase previous misconfiguration */
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005355 if (np->driver_data & DEV_HAS_POWER_CNTRL)
5356 nv_mac_reset(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005357 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
5358 writel(0, base + NvRegMulticastAddrB);
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -05005359 writel(NVREG_MCASTMASKA_NONE, base + NvRegMulticastMaskA);
5360 writel(NVREG_MCASTMASKB_NONE, base + NvRegMulticastMaskB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005361 writel(0, base + NvRegPacketFilterFlags);
5362
5363 writel(0, base + NvRegTransmitterControl);
5364 writel(0, base + NvRegReceiverControl);
5365
5366 writel(0, base + NvRegAdapterControl);
5367
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04005368 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)
5369 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
5370
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005371 /* initialize descriptor rings */
Manfred Sprauld81c0982005-07-31 18:20:30 +02005372 set_bufsize(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005373 oom = nv_init_ring(dev);
5374
5375 writel(0, base + NvRegLinkSpeed);
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005376 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005377 nv_txrx_reset(dev);
5378 writel(0, base + NvRegUnknownSetupReg6);
5379
5380 np->in_shutdown = 0;
5381
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005382 /* give hw rings */
Ayaz Abdulla0832b252006-02-04 13:13:26 -05005383 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005384 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Linus Torvalds1da177e2005-04-16 15:20:36 -07005385 base + NvRegRingSizes);
5386
Linus Torvalds1da177e2005-04-16 15:20:36 -07005387 writel(np->linkspeed, base + NvRegLinkSpeed);
Ayaz Abdulla95d161c2006-07-06 16:46:25 -04005388 if (np->desc_ver == DESC_VER_1)
5389 writel(NVREG_TX_WM_DESC1_DEFAULT, base + NvRegTxWatermark);
5390 else
5391 writel(NVREG_TX_WM_DESC2_3_DEFAULT, base + NvRegTxWatermark);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005392 writel(np->txrxctl_bits, base + NvRegTxRxControl);
Ayaz Abdullaee407b02006-02-04 13:13:17 -05005393 writel(np->vlanctl_bits, base + NvRegVlanControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005394 pci_push(base);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005395 writel(NVREG_TXRXCTL_BIT1|np->txrxctl_bits, base + NvRegTxRxControl);
Joe Perches344d0dc2010-11-29 07:41:52 +00005396 if (reg_delay(dev, NvRegUnknownSetupReg5,
5397 NVREG_UNKSETUP5_BIT31, NVREG_UNKSETUP5_BIT31,
5398 NV_SETUP5_DELAY, NV_SETUP5_DELAYMAX))
Joe Perches1d397f32010-11-29 07:41:57 +00005399 netdev_info(dev,
5400 "%s: SetupReg5, Bit 31 remained off\n", __func__);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005401
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005402 writel(0, base + NvRegMIIMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005403 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005404 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005405
Linus Torvalds1da177e2005-04-16 15:20:36 -07005406 writel(NVREG_MISC1_FORCE | NVREG_MISC1_HD, base + NvRegMisc1);
5407 writel(readl(base + NvRegTransmitterStatus), base + NvRegTransmitterStatus);
5408 writel(NVREG_PFF_ALWAYS, base + NvRegPacketFilterFlags);
Manfred Sprauld81c0982005-07-31 18:20:30 +02005409 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005410
5411 writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus);
Ayaz Abdullaa4336862008-04-18 13:50:43 -07005412
5413 get_random_bytes(&low, sizeof(low));
5414 low &= NVREG_SLOTTIME_MASK;
5415 if (np->desc_ver == DESC_VER_1) {
5416 writel(low|NVREG_SLOTTIME_DEFAULT, base + NvRegSlotTime);
5417 } else {
5418 if (!(np->driver_data & DEV_HAS_GEAR_MODE)) {
5419 /* setup legacy backoff */
5420 writel(NVREG_SLOTTIME_LEGBF_ENABLED|NVREG_SLOTTIME_10_100_FULL|low, base + NvRegSlotTime);
5421 } else {
5422 writel(NVREG_SLOTTIME_10_100_FULL, base + NvRegSlotTime);
5423 nv_gear_backoff_reseed(dev);
5424 }
5425 }
Ayaz Abdulla9744e212006-07-06 16:45:58 -04005426 writel(NVREG_TX_DEFERRAL_DEFAULT, base + NvRegTxDeferral);
5427 writel(NVREG_RX_DEFERRAL_DEFAULT, base + NvRegRxDeferral);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005428 if (poll_interval == -1) {
5429 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT)
5430 writel(NVREG_POLL_DEFAULT_THROUGHPUT, base + NvRegPollingInterval);
5431 else
5432 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005433 } else
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005434 writel(poll_interval & 0xFFFF, base + NvRegPollingInterval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005435 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
5436 writel((np->phyaddr << NVREG_ADAPTCTL_PHYSHIFT)|NVREG_ADAPTCTL_PHYVALID|NVREG_ADAPTCTL_RUNNING,
5437 base + NvRegAdapterControl);
5438 writel(NVREG_MIISPEED_BIT8|NVREG_MIIDELAY, base + NvRegMIISpeed);
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005439 writel(NVREG_MII_LINKCHANGE, base + NvRegMIIMask);
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04005440 if (np->wolenabled)
5441 writel(NVREG_WAKEUPFLAGS_ENABLE , base + NvRegWakeUpFlags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005442
5443 i = readl(base + NvRegPowerState);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005444 if ((i & NVREG_POWERSTATE_POWEREDUP) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005445 writel(NVREG_POWERSTATE_POWEREDUP|i, base + NvRegPowerState);
5446
5447 pci_push(base);
5448 udelay(10);
5449 writel(readl(base + NvRegPowerState) | NVREG_POWERSTATE_VALID, base + NvRegPowerState);
5450
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005451 nv_disable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005452 pci_push(base);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005453 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005454 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
5455 pci_push(base);
5456
Szymon Janc78aea4f2010-11-27 08:39:43 +00005457 if (nv_request_irq(dev, 0))
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005458 goto out_drain;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005459
5460 /* ask for interrupts */
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005461 nv_enable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005462
5463 spin_lock_irq(&np->lock);
5464 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
5465 writel(0, base + NvRegMulticastAddrB);
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -05005466 writel(NVREG_MCASTMASKA_NONE, base + NvRegMulticastMaskA);
5467 writel(NVREG_MCASTMASKB_NONE, base + NvRegMulticastMaskB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005468 writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
5469 /* One manual link speed update: Interrupts are enabled, future link
5470 * speed changes cause interrupts and are handled by nv_link_irq().
5471 */
5472 {
5473 u32 miistat;
5474 miistat = readl(base + NvRegMIIStatus);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005475 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005476 }
Manfred Spraul1b1b3c92005-08-06 23:47:55 +02005477 /* set linkspeed to invalid value, thus force nv_update_linkspeed
5478 * to init hw */
5479 np->linkspeed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005480 ret = nv_update_linkspeed(dev);
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005481 nv_start_rxtx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005482 netif_start_queue(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00005483 nv_napi_enable(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07005484
Linus Torvalds1da177e2005-04-16 15:20:36 -07005485 if (ret) {
5486 netif_carrier_on(dev);
5487 } else {
Joe Perches1d397f32010-11-29 07:41:57 +00005488 netdev_info(dev, "no link during initialization\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005489 netif_carrier_off(dev);
5490 }
5491 if (oom)
5492 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005493
5494 /* start statistics timer */
Ayaz Abdulla9c662432008-08-06 12:11:42 -04005495 if (np->driver_data & (DEV_HAS_STATISTICS_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_STATISTICS_V3))
Daniel Drakebfebbb82008-03-18 11:07:18 +00005496 mod_timer(&np->stats_poll,
5497 round_jiffies(jiffies + STATS_INTERVAL));
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005498
Linus Torvalds1da177e2005-04-16 15:20:36 -07005499 spin_unlock_irq(&np->lock);
5500
Sanjay Hortikare19df762011-11-11 16:11:21 +00005501 /* If the loopback feature was set while the device was down, make sure
5502 * that it's set correctly now.
5503 */
5504 if (dev->features & NETIF_F_LOOPBACK)
5505 nv_set_loopback(dev, dev->features);
5506
Linus Torvalds1da177e2005-04-16 15:20:36 -07005507 return 0;
5508out_drain:
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005509 nv_drain_rxtx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005510 return ret;
5511}
5512
5513static int nv_close(struct net_device *dev)
5514{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005515 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005516 u8 __iomem *base;
5517
5518 spin_lock_irq(&np->lock);
5519 np->in_shutdown = 1;
5520 spin_unlock_irq(&np->lock);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00005521 nv_napi_disable(dev);
Manfred Spraula7475902007-10-17 21:52:33 +02005522 synchronize_irq(np->pci_dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005523
5524 del_timer_sync(&np->oom_kick);
5525 del_timer_sync(&np->nic_poll);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005526 del_timer_sync(&np->stats_poll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005527
5528 netif_stop_queue(dev);
5529 spin_lock_irq(&np->lock);
david decotigny1ff39eb2012-08-24 17:22:52 +00005530 nv_update_pause(dev, 0); /* otherwise stop_tx bricks NIC */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005531 nv_stop_rxtx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005532 nv_txrx_reset(dev);
5533
5534 /* disable interrupts on the nic or we will lock up */
5535 base = get_hwbase(dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005536 nv_disable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005537 pci_push(base);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005538
5539 spin_unlock_irq(&np->lock);
5540
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005541 nv_free_irq(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005542
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005543 nv_drain_rxtx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005544
Ed Swierk5a9a8e32009-06-02 00:19:52 -07005545 if (np->wolenabled || !phy_power_down) {
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00005546 nv_txrx_gate(dev, false);
Tim Mann2cc49a52007-06-14 13:16:38 -07005547 writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005548 nv_start_rx(dev);
Ed Swierkcb52deb2008-12-01 12:24:43 +00005549 } else {
5550 /* power down phy */
5551 mii_rw(dev, np->phyaddr, MII_BMCR,
5552 mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ)|BMCR_PDOWN);
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00005553 nv_txrx_gate(dev, true);
Tim Mann2cc49a52007-06-14 13:16:38 -07005554 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005555
5556 /* FIXME: power down nic */
5557
5558 return 0;
5559}
5560
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005561static const struct net_device_ops nv_netdev_ops = {
5562 .ndo_open = nv_open,
5563 .ndo_stop = nv_close,
david decotignyf5d827a2011-11-16 12:15:13 +00005564 .ndo_get_stats64 = nv_get_stats64,
Stephen Hemminger00829822008-11-20 20:14:53 -08005565 .ndo_start_xmit = nv_start_xmit,
5566 .ndo_tx_timeout = nv_tx_timeout,
5567 .ndo_change_mtu = nv_change_mtu,
Michał Mirosław569e1462011-04-15 04:50:49 +00005568 .ndo_fix_features = nv_fix_features,
5569 .ndo_set_features = nv_set_features,
Stephen Hemminger00829822008-11-20 20:14:53 -08005570 .ndo_validate_addr = eth_validate_addr,
5571 .ndo_set_mac_address = nv_set_mac_address,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00005572 .ndo_set_rx_mode = nv_set_multicast,
Stephen Hemminger00829822008-11-20 20:14:53 -08005573#ifdef CONFIG_NET_POLL_CONTROLLER
5574 .ndo_poll_controller = nv_poll_controller,
5575#endif
5576};
5577
5578static const struct net_device_ops nv_netdev_ops_optimized = {
5579 .ndo_open = nv_open,
5580 .ndo_stop = nv_close,
david decotignyf5d827a2011-11-16 12:15:13 +00005581 .ndo_get_stats64 = nv_get_stats64,
Stephen Hemminger00829822008-11-20 20:14:53 -08005582 .ndo_start_xmit = nv_start_xmit_optimized,
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005583 .ndo_tx_timeout = nv_tx_timeout,
5584 .ndo_change_mtu = nv_change_mtu,
Michał Mirosław569e1462011-04-15 04:50:49 +00005585 .ndo_fix_features = nv_fix_features,
5586 .ndo_set_features = nv_set_features,
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005587 .ndo_validate_addr = eth_validate_addr,
5588 .ndo_set_mac_address = nv_set_mac_address,
Jiri Pirkoafc4b132011-08-16 06:29:01 +00005589 .ndo_set_rx_mode = nv_set_multicast,
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005590#ifdef CONFIG_NET_POLL_CONTROLLER
5591 .ndo_poll_controller = nv_poll_controller,
5592#endif
5593};
5594
Bill Pembertond05919a2012-12-03 09:23:20 -05005595static int nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005596{
5597 struct net_device *dev;
5598 struct fe_priv *np;
5599 unsigned long addr;
5600 u8 __iomem *base;
5601 int err, i;
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005602 u32 powerstate, txreg;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005603 u32 phystate_orig = 0, phystate;
5604 int phyinitialized = 0;
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005605 static int printed_version;
5606
5607 if (!printed_version++)
Joe Perches294a5542010-11-29 07:41:56 +00005608 pr_info("Reverse Engineered nForce ethernet driver. Version %s.\n",
5609 FORCEDETH_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005610
5611 dev = alloc_etherdev(sizeof(struct fe_priv));
5612 err = -ENOMEM;
5613 if (!dev)
5614 goto out;
5615
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005616 np = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07005617 np->dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005618 np->pci_dev = pci_dev;
5619 spin_lock_init(&np->lock);
david decotignyf5d827a2011-11-16 12:15:13 +00005620 spin_lock_init(&np->hwstats_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005621 SET_NETDEV_DEV(dev, &pci_dev->dev);
5622
5623 init_timer(&np->oom_kick);
5624 np->oom_kick.data = (unsigned long) dev;
Joe Perchesc061b182010-08-23 18:20:03 +00005625 np->oom_kick.function = nv_do_rx_refill; /* timer handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005626 init_timer(&np->nic_poll);
5627 np->nic_poll.data = (unsigned long) dev;
Joe Perchesc061b182010-08-23 18:20:03 +00005628 np->nic_poll.function = nv_do_nic_poll; /* timer handler */
david decotigny8f5f6982011-11-16 12:15:15 +00005629 init_timer_deferrable(&np->stats_poll);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005630 np->stats_poll.data = (unsigned long) dev;
Joe Perchesc061b182010-08-23 18:20:03 +00005631 np->stats_poll.function = nv_do_stats_poll; /* timer handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005632
5633 err = pci_enable_device(pci_dev);
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005634 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005635 goto out_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005636
5637 pci_set_master(pci_dev);
5638
5639 err = pci_request_regions(pci_dev, DRV_NAME);
5640 if (err < 0)
5641 goto out_disable;
5642
Ayaz Abdulla9c662432008-08-06 12:11:42 -04005643 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 -05005644 np->register_size = NV_PCI_REGSZ_VER3;
5645 else if (id->driver_data & DEV_HAS_STATISTICS_V1)
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005646 np->register_size = NV_PCI_REGSZ_VER2;
5647 else
5648 np->register_size = NV_PCI_REGSZ_VER1;
5649
Linus Torvalds1da177e2005-04-16 15:20:36 -07005650 err = -EINVAL;
5651 addr = 0;
5652 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005653 if (pci_resource_flags(pci_dev, i) & IORESOURCE_MEM &&
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005654 pci_resource_len(pci_dev, i) >= np->register_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005655 addr = pci_resource_start(pci_dev, i);
5656 break;
5657 }
5658 }
5659 if (i == DEVICE_COUNT_RESOURCE) {
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005660 dev_info(&pci_dev->dev, "Couldn't find register window\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005661 goto out_relreg;
5662 }
5663
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005664 /* copy of driver data */
5665 np->driver_data = id->driver_data;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04005666 /* copy of device id */
5667 np->device_id = id->device;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005668
Linus Torvalds1da177e2005-04-16 15:20:36 -07005669 /* handle different descriptor versions */
Manfred Spraulee733622005-07-31 18:32:26 +02005670 if (id->driver_data & DEV_HAS_HIGH_DMA) {
5671 /* packet format 3: supports 40-bit addressing */
5672 np->desc_ver = DESC_VER_3;
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005673 np->txrxctl_bits = NVREG_TXRXCTL_DESC_3;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005674 if (dma_64bit) {
Yang Hongyang6afd1422009-04-06 19:01:15 -07005675 if (pci_set_dma_mask(pci_dev, DMA_BIT_MASK(39)))
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005676 dev_info(&pci_dev->dev,
5677 "64-bit DMA failed, using 32-bit addressing\n");
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005678 else
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005679 dev->features |= NETIF_F_HIGHDMA;
Yang Hongyang6afd1422009-04-06 19:01:15 -07005680 if (pci_set_consistent_dma_mask(pci_dev, DMA_BIT_MASK(39))) {
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005681 dev_info(&pci_dev->dev,
5682 "64-bit DMA (consistent) failed, using 32-bit ring buffers\n");
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005683 }
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005684 }
Manfred Spraulee733622005-07-31 18:32:26 +02005685 } else if (id->driver_data & DEV_HAS_LARGEDESC) {
5686 /* packet format 2: supports jumbo frames */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005687 np->desc_ver = DESC_VER_2;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005688 np->txrxctl_bits = NVREG_TXRXCTL_DESC_2;
Manfred Spraulee733622005-07-31 18:32:26 +02005689 } else {
5690 /* original packet format */
5691 np->desc_ver = DESC_VER_1;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005692 np->txrxctl_bits = NVREG_TXRXCTL_DESC_1;
Manfred Sprauld81c0982005-07-31 18:20:30 +02005693 }
Manfred Spraulee733622005-07-31 18:32:26 +02005694
5695 np->pkt_limit = NV_PKTLIMIT_1;
5696 if (id->driver_data & DEV_HAS_LARGEDESC)
5697 np->pkt_limit = NV_PKTLIMIT_2;
5698
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005699 if (id->driver_data & DEV_HAS_CHECKSUM) {
5700 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
Michał Mirosław569e1462011-04-15 04:50:49 +00005701 dev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_SG |
5702 NETIF_F_TSO | NETIF_F_RXCSUM;
Ayaz Abdulla21828162007-01-23 12:27:21 -05005703 }
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005704
Ayaz Abdullaee407b02006-02-04 13:13:17 -05005705 np->vlanctl_bits = 0;
5706 if (id->driver_data & DEV_HAS_VLAN) {
5707 np->vlanctl_bits = NVREG_VLANCONTROL_ENABLE;
Patrick McHardyf6469682013-04-19 02:04:27 +00005708 dev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX |
5709 NETIF_F_HW_VLAN_CTAG_TX;
Ayaz Abdullaee407b02006-02-04 13:13:17 -05005710 }
5711
Jiri Pirko0891b0e2011-07-26 10:19:28 +00005712 dev->features |= dev->hw_features;
5713
Sanjay Hortikare19df762011-11-11 16:11:21 +00005714 /* Add loopback capability to the device. */
5715 dev->hw_features |= NETIF_F_LOOPBACK;
5716
Ayaz Abdullab6d07732006-06-10 22:47:42 -04005717 np->pause_flags = NV_PAUSEFRAME_RX_CAPABLE | NV_PAUSEFRAME_RX_REQ | NV_PAUSEFRAME_AUTONEG;
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05005718 if ((id->driver_data & DEV_HAS_PAUSEFRAME_TX_V1) ||
5719 (id->driver_data & DEV_HAS_PAUSEFRAME_TX_V2) ||
5720 (id->driver_data & DEV_HAS_PAUSEFRAME_TX_V3)) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04005721 np->pause_flags |= NV_PAUSEFRAME_TX_CAPABLE | NV_PAUSEFRAME_TX_REQ;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04005722 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04005723
Linus Torvalds1da177e2005-04-16 15:20:36 -07005724 err = -ENOMEM;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005725 np->base = ioremap(addr, np->register_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005726 if (!np->base)
5727 goto out_relreg;
Manfred Spraulee733622005-07-31 18:32:26 +02005728
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005729 np->rx_ring_size = RX_RING_DEFAULT;
5730 np->tx_ring_size = TX_RING_DEFAULT;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005731
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005732 if (!nv_optimized(np)) {
Manfred Spraulee733622005-07-31 18:32:26 +02005733 np->rx_ring.orig = pci_alloc_consistent(pci_dev,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005734 sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
Manfred Spraulee733622005-07-31 18:32:26 +02005735 &np->ring_addr);
5736 if (!np->rx_ring.orig)
5737 goto out_unmap;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005738 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
Manfred Spraulee733622005-07-31 18:32:26 +02005739 } else {
5740 np->rx_ring.ex = pci_alloc_consistent(pci_dev,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005741 sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
Manfred Spraulee733622005-07-31 18:32:26 +02005742 &np->ring_addr);
5743 if (!np->rx_ring.ex)
5744 goto out_unmap;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005745 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
Manfred Spraulee733622005-07-31 18:32:26 +02005746 }
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07005747 np->rx_skb = kcalloc(np->rx_ring_size, sizeof(struct nv_skb_map), GFP_KERNEL);
5748 np->tx_skb = kcalloc(np->tx_ring_size, sizeof(struct nv_skb_map), GFP_KERNEL);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05005749 if (!np->rx_skb || !np->tx_skb)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005750 goto out_freering;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005751
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005752 if (!nv_optimized(np))
Stephen Hemminger00829822008-11-20 20:14:53 -08005753 dev->netdev_ops = &nv_netdev_ops;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05005754 else
Stephen Hemminger00829822008-11-20 20:14:53 -08005755 dev->netdev_ops = &nv_netdev_ops_optimized;
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005756
Stephen Hemmingerbea33482007-10-03 16:41:36 -07005757 netif_napi_add(dev, &np->napi, nv_napi_poll, RX_WORK_PER_LOOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005758 SET_ETHTOOL_OPS(dev, &ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005759 dev->watchdog_timeo = NV_WATCHDOG_TIMEO;
5760
5761 pci_set_drvdata(pci_dev, dev);
5762
5763 /* read the mac address */
5764 base = get_hwbase(dev);
5765 np->orig_mac[0] = readl(base + NvRegMacAddrA);
5766 np->orig_mac[1] = readl(base + NvRegMacAddrB);
5767
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005768 /* check the workaround bit for correct mac address order */
5769 txreg = readl(base + NvRegTransmitPoll);
Ayaz Abdullaa376e792008-04-10 21:30:35 -07005770 if (id->driver_data & DEV_HAS_CORRECT_MACADDR) {
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005771 /* mac address is already in correct order */
5772 dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff;
5773 dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff;
5774 dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff;
5775 dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff;
5776 dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff;
5777 dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff;
Ayaz Abdullaa376e792008-04-10 21:30:35 -07005778 } else if (txreg & NVREG_TRANSMITPOLL_MAC_ADDR_REV) {
5779 /* mac address is already in correct order */
5780 dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff;
5781 dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff;
5782 dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff;
5783 dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff;
5784 dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff;
5785 dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff;
5786 /*
5787 * Set orig mac address back to the reversed version.
5788 * This flag will be cleared during low power transition.
5789 * Therefore, we should always put back the reversed address.
5790 */
5791 np->orig_mac[0] = (dev->dev_addr[5] << 0) + (dev->dev_addr[4] << 8) +
5792 (dev->dev_addr[3] << 16) + (dev->dev_addr[2] << 24);
5793 np->orig_mac[1] = (dev->dev_addr[1] << 0) + (dev->dev_addr[0] << 8);
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005794 } else {
5795 /* need to reverse mac address to correct order */
5796 dev->dev_addr[0] = (np->orig_mac[1] >> 8) & 0xff;
5797 dev->dev_addr[1] = (np->orig_mac[1] >> 0) & 0xff;
5798 dev->dev_addr[2] = (np->orig_mac[0] >> 24) & 0xff;
5799 dev->dev_addr[3] = (np->orig_mac[0] >> 16) & 0xff;
5800 dev->dev_addr[4] = (np->orig_mac[0] >> 8) & 0xff;
5801 dev->dev_addr[5] = (np->orig_mac[0] >> 0) & 0xff;
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005802 writel(txreg|NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
Joe Perchesc20ec762010-11-29 07:42:02 +00005803 dev_dbg(&pci_dev->dev,
5804 "%s: set workaround bit for reversed mac addr\n",
5805 __func__);
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005806 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005807
Jiri Pirkoaaeb6cd2013-01-08 01:38:26 +00005808 if (!is_valid_ether_addr(dev->dev_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005809 /*
5810 * Bad mac address. At least one bios sets the mac address
5811 * to 01:23:45:67:89:ab
5812 */
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005813 dev_err(&pci_dev->dev,
Joe Perchesc20ec762010-11-29 07:42:02 +00005814 "Invalid MAC address detected: %pM - Please complain to your hardware vendor.\n",
Szymon Janc78aea4f2010-11-27 08:39:43 +00005815 dev->dev_addr);
Danny Kukawka7ce5d222012-02-15 06:45:40 +00005816 eth_hw_addr_random(dev);
Joe Perchesc20ec762010-11-29 07:42:02 +00005817 dev_err(&pci_dev->dev,
5818 "Using random MAC address: %pM\n", dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005819 }
5820
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005821 /* set mac address */
5822 nv_copy_mac_to_hw(dev);
5823
Linus Torvalds1da177e2005-04-16 15:20:36 -07005824 /* disable WOL */
5825 writel(0, base + NvRegWakeUpFlags);
5826 np->wolenabled = 0;
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00005827 device_set_wakeup_enable(&pci_dev->dev, false);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005828
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005829 if (id->driver_data & DEV_HAS_POWER_CNTRL) {
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005830
5831 /* take phy and nic out of low power mode */
5832 powerstate = readl(base + NvRegPowerState2);
5833 powerstate &= ~NVREG_POWERSTATE2_POWERUP_MASK;
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00005834 if ((id->driver_data & DEV_NEED_LOW_POWER_FIX) &&
Auke Kok44c10132007-06-08 15:46:36 -07005835 pci_dev->revision >= 0xA3)
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005836 powerstate |= NVREG_POWERSTATE2_POWERUP_REV_A3;
5837 writel(powerstate, base + NvRegPowerState2);
5838 }
5839
Szymon Janc78aea4f2010-11-27 08:39:43 +00005840 if (np->desc_ver == DESC_VER_1)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005841 np->tx_flags = NV_TX_VALID;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005842 else
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005843 np->tx_flags = NV_TX2_VALID;
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005844
5845 np->msi_flags = 0;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005846 if ((id->driver_data & DEV_HAS_MSI) && msi)
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005847 np->msi_flags |= NV_MSI_CAPABLE;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005848
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005849 if ((id->driver_data & DEV_HAS_MSI_X) && msix) {
5850 /* msix has had reported issues when modifying irqmask
5851 as in the case of napi, therefore, disable for now
5852 */
David S. Miller0a127612010-05-03 23:33:05 -07005853#if 0
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005854 np->msi_flags |= NV_MSI_X_CAPABLE;
5855#endif
5856 }
5857
5858 if (optimization_mode == NV_OPTIMIZATION_MODE_CPU) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005859 np->irqmask = NVREG_IRQMASK_CPU;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005860 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
5861 np->msi_flags |= 0x0001;
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005862 } else if (optimization_mode == NV_OPTIMIZATION_MODE_DYNAMIC &&
5863 !(id->driver_data & DEV_NEED_TIMERIRQ)) {
5864 /* start off in throughput mode */
5865 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
5866 /* remove support for msix mode */
5867 np->msi_flags &= ~NV_MSI_X_CAPABLE;
5868 } else {
5869 optimization_mode = NV_OPTIMIZATION_MODE_THROUGHPUT;
5870 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
5871 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
5872 np->msi_flags |= 0x0003;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005873 }
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005874
Linus Torvalds1da177e2005-04-16 15:20:36 -07005875 if (id->driver_data & DEV_NEED_TIMERIRQ)
5876 np->irqmask |= NVREG_IRQ_TIMER;
5877 if (id->driver_data & DEV_NEED_LINKTIMER) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005878 np->need_linktimer = 1;
5879 np->link_timeout = jiffies + LINK_TIMEOUT;
5880 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005881 np->need_linktimer = 0;
5882 }
5883
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005884 /* Limit the number of tx's outstanding for hw bug */
5885 if (id->driver_data & DEV_NEED_TX_LIMIT) {
5886 np->tx_limit = 1;
Ayaz Abdulla5c659322010-04-13 18:49:51 -07005887 if (((id->driver_data & DEV_NEED_TX_LIMIT2) == DEV_NEED_TX_LIMIT2) &&
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005888 pci_dev->revision >= 0xA2)
5889 np->tx_limit = 0;
5890 }
5891
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005892 /* clear phy state and temporarily halt phy interrupts */
5893 writel(0, base + NvRegMIIMask);
5894 phystate = readl(base + NvRegAdapterControl);
5895 if (phystate & NVREG_ADAPTCTL_RUNNING) {
5896 phystate_orig = 1;
5897 phystate &= ~NVREG_ADAPTCTL_RUNNING;
5898 writel(phystate, base + NvRegAdapterControl);
5899 }
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005900 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005901
5902 if (id->driver_data & DEV_HAS_MGMT_UNIT) {
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005903 /* management unit running on the mac? */
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005904 if ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_ST) &&
5905 (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_PHY_INIT) &&
5906 nv_mgmt_acquire_sema(dev) &&
5907 nv_mgmt_get_version(dev)) {
5908 np->mac_in_use = 1;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005909 if (np->mgmt_version > 0)
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005910 np->mac_in_use = readl(base + NvRegMgmtUnitControl) & NVREG_MGMTUNITCONTROL_INUSE;
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005911 /* management unit setup the phy already? */
5912 if (np->mac_in_use &&
5913 ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK) ==
5914 NVREG_XMITCTL_SYNC_PHY_INIT)) {
5915 /* phy is inited by mgmt unit */
5916 phyinitialized = 1;
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005917 } else {
5918 /* we need to init the phy */
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005919 }
5920 }
5921 }
5922
Linus Torvalds1da177e2005-04-16 15:20:36 -07005923 /* find a suitable phy */
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005924 for (i = 1; i <= 32; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005925 int id1, id2;
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005926 int phyaddr = i & 0x1F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005927
5928 spin_lock_irq(&np->lock);
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005929 id1 = mii_rw(dev, phyaddr, MII_PHYSID1, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005930 spin_unlock_irq(&np->lock);
5931 if (id1 < 0 || id1 == 0xffff)
5932 continue;
5933 spin_lock_irq(&np->lock);
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005934 id2 = mii_rw(dev, phyaddr, MII_PHYSID2, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005935 spin_unlock_irq(&np->lock);
5936 if (id2 < 0 || id2 == 0xffff)
5937 continue;
5938
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04005939 np->phy_model = id2 & PHYID2_MODEL_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005940 id1 = (id1 & PHYID1_OUI_MASK) << PHYID1_OUI_SHFT;
5941 id2 = (id2 & PHYID2_OUI_MASK) >> PHYID2_OUI_SHFT;
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005942 np->phyaddr = phyaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005943 np->phy_oui = id1 | id2;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04005944
5945 /* Realtek hardcoded phy id1 to all zero's on certain phys */
5946 if (np->phy_oui == PHY_OUI_REALTEK2)
5947 np->phy_oui = PHY_OUI_REALTEK;
5948 /* Setup phy revision for Realtek */
5949 if (np->phy_oui == PHY_OUI_REALTEK && np->phy_model == PHY_MODEL_REALTEK_8211)
5950 np->phy_rev = mii_rw(dev, phyaddr, MII_RESV1, MII_READ) & PHY_REV_MASK;
5951
Linus Torvalds1da177e2005-04-16 15:20:36 -07005952 break;
5953 }
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005954 if (i == 33) {
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005955 dev_info(&pci_dev->dev, "open: Could not find a valid PHY\n");
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005956 goto out_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005957 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04005958
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005959 if (!phyinitialized) {
5960 /* reset it */
5961 phy_init(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05005962 } else {
5963 /* see if it is a gigabit phy */
5964 u32 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005965 if (mii_status & PHY_GIGABIT)
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05005966 np->gigabit = PHY_GIGABIT;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005967 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005968
5969 /* set default link speed settings */
5970 np->linkspeed = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
5971 np->duplex = 0;
5972 np->autoneg = 1;
5973
5974 err = register_netdev(dev);
5975 if (err) {
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005976 dev_info(&pci_dev->dev, "unable to register netdev: %d\n", err);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005977 goto out_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005978 }
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005979
david decotigny3f0a1b52012-08-24 17:22:53 +00005980 netif_carrier_off(dev);
5981
5982 /* Some NICs freeze when TX pause is enabled while NIC is
5983 * down, and this stays across warm reboots. The sequence
5984 * below should be enough to recover from that state.
5985 */
5986 nv_update_pause(dev, 0);
5987 nv_start_tx(dev);
5988 nv_stop_tx(dev);
5989
David S. Miller823dcd22011-08-20 10:39:12 -07005990 if (id->driver_data & DEV_HAS_VLAN)
5991 nv_vlan_mode(dev, dev->features);
Jiri Pirko0891b0e2011-07-26 10:19:28 +00005992
Joe Perchesb2ba08e2010-11-29 07:42:00 +00005993 dev_info(&pci_dev->dev, "ifname %s, PHY OUI 0x%x @ %d, addr %pM\n",
5994 dev->name, np->phy_oui, np->phyaddr, dev->dev_addr);
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005995
Sanjay Hortikare19df762011-11-11 16:11:21 +00005996 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 +00005997 dev->features & NETIF_F_HIGHDMA ? "highdma " : "",
5998 dev->features & (NETIF_F_IP_CSUM | NETIF_F_SG) ?
Szymon Janc78aea4f2010-11-27 08:39:43 +00005999 "csum " : "",
Patrick McHardyf6469682013-04-19 02:04:27 +00006000 dev->features & (NETIF_F_HW_VLAN_CTAG_RX |
6001 NETIF_F_HW_VLAN_CTAG_TX) ?
Szymon Janc78aea4f2010-11-27 08:39:43 +00006002 "vlan " : "",
Sanjay Hortikare19df762011-11-11 16:11:21 +00006003 dev->features & (NETIF_F_LOOPBACK) ?
6004 "loopback " : "",
Joe Perchesb2ba08e2010-11-29 07:42:00 +00006005 id->driver_data & DEV_HAS_POWER_CNTRL ? "pwrctl " : "",
6006 id->driver_data & DEV_HAS_MGMT_UNIT ? "mgmt " : "",
6007 id->driver_data & DEV_NEED_TIMERIRQ ? "timirq " : "",
6008 np->gigabit == PHY_GIGABIT ? "gbit " : "",
6009 np->need_linktimer ? "lnktim " : "",
6010 np->msi_flags & NV_MSI_CAPABLE ? "msi " : "",
6011 np->msi_flags & NV_MSI_X_CAPABLE ? "msi-x " : "",
6012 np->desc_ver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006013
6014 return 0;
6015
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04006016out_error:
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05006017 if (phystate_orig)
6018 writel(phystate|NVREG_ADAPTCTL_RUNNING, base + NvRegAdapterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006019 pci_set_drvdata(pci_dev, NULL);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04006020out_freering:
6021 free_rings(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006022out_unmap:
6023 iounmap(get_hwbase(dev));
6024out_relreg:
6025 pci_release_regions(pci_dev);
6026out_disable:
6027 pci_disable_device(pci_dev);
6028out_free:
6029 free_netdev(dev);
6030out:
6031 return err;
6032}
6033
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04006034static void nv_restore_phy(struct net_device *dev)
6035{
6036 struct fe_priv *np = netdev_priv(dev);
6037 u16 phy_reserved, mii_control;
6038
6039 if (np->phy_oui == PHY_OUI_REALTEK &&
6040 np->phy_model == PHY_MODEL_REALTEK_8201 &&
6041 phy_cross == NV_CROSSOVER_DETECTION_DISABLED) {
6042 mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3);
6043 phy_reserved = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, MII_READ);
6044 phy_reserved &= ~PHY_REALTEK_INIT_MSK1;
6045 phy_reserved |= PHY_REALTEK_INIT8;
6046 mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, phy_reserved);
6047 mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1);
6048
6049 /* restart auto negotiation */
6050 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
6051 mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE);
6052 mii_rw(dev, np->phyaddr, MII_BMCR, mii_control);
6053 }
6054}
6055
Yinghai Luf55c21f2008-09-13 13:10:31 -07006056static void nv_restore_mac_addr(struct pci_dev *pci_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07006057{
6058 struct net_device *dev = pci_get_drvdata(pci_dev);
Ayaz Abdullaf1489652006-07-31 12:04:45 -04006059 struct fe_priv *np = netdev_priv(dev);
6060 u8 __iomem *base = get_hwbase(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006061
Ayaz Abdullaf1489652006-07-31 12:04:45 -04006062 /* special op: write back the misordered MAC address - otherwise
6063 * the next nv_probe would see a wrong address.
6064 */
6065 writel(np->orig_mac[0], base + NvRegMacAddrA);
6066 writel(np->orig_mac[1], base + NvRegMacAddrB);
Björn Steinbrink2e3884b2008-01-07 23:22:53 -08006067 writel(readl(base + NvRegTransmitPoll) & ~NVREG_TRANSMITPOLL_MAC_ADDR_REV,
6068 base + NvRegTransmitPoll);
Yinghai Luf55c21f2008-09-13 13:10:31 -07006069}
6070
Bill Pembertond05919a2012-12-03 09:23:20 -05006071static void nv_remove(struct pci_dev *pci_dev)
Yinghai Luf55c21f2008-09-13 13:10:31 -07006072{
6073 struct net_device *dev = pci_get_drvdata(pci_dev);
6074
6075 unregister_netdev(dev);
6076
6077 nv_restore_mac_addr(pci_dev);
Ayaz Abdullaf1489652006-07-31 12:04:45 -04006078
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04006079 /* restore any phy related changes */
6080 nv_restore_phy(dev);
6081
Ayaz Abdullacac1c522009-02-07 00:23:57 -08006082 nv_mgmt_release_sema(dev);
6083
Linus Torvalds1da177e2005-04-16 15:20:36 -07006084 /* free all structures */
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04006085 free_rings(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006086 iounmap(get_hwbase(dev));
6087 pci_release_regions(pci_dev);
6088 pci_disable_device(pci_dev);
6089 free_netdev(dev);
6090 pci_set_drvdata(pci_dev, NULL);
6091}
6092
Michel Lespinasse94252762011-03-06 16:14:50 +00006093#ifdef CONFIG_PM_SLEEP
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006094static int nv_suspend(struct device *device)
Francois Romieua1893172006-10-10 14:33:27 -07006095{
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006096 struct pci_dev *pdev = to_pci_dev(device);
Francois Romieua1893172006-10-10 14:33:27 -07006097 struct net_device *dev = pci_get_drvdata(pdev);
6098 struct fe_priv *np = netdev_priv(dev);
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006099 u8 __iomem *base = get_hwbase(dev);
6100 int i;
Francois Romieua1893172006-10-10 14:33:27 -07006101
Tobias Diedrich25d90812008-05-18 15:04:29 +02006102 if (netif_running(dev)) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00006103 /* Gross. */
Tobias Diedrich25d90812008-05-18 15:04:29 +02006104 nv_close(dev);
6105 }
Francois Romieua1893172006-10-10 14:33:27 -07006106 netif_device_detach(dev);
6107
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006108 /* save non-pci configuration space */
Szymon Janc78aea4f2010-11-27 08:39:43 +00006109 for (i = 0; i <= np->register_size/sizeof(u32); i++)
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006110 np->saved_config_space[i] = readl(base + i*sizeof(u32));
6111
Francois Romieua1893172006-10-10 14:33:27 -07006112 return 0;
6113}
6114
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006115static int nv_resume(struct device *device)
Francois Romieua1893172006-10-10 14:33:27 -07006116{
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006117 struct pci_dev *pdev = to_pci_dev(device);
Francois Romieua1893172006-10-10 14:33:27 -07006118 struct net_device *dev = pci_get_drvdata(pdev);
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006119 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullaa376e792008-04-10 21:30:35 -07006120 u8 __iomem *base = get_hwbase(dev);
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006121 int i, rc = 0;
Francois Romieua1893172006-10-10 14:33:27 -07006122
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006123 /* restore non-pci configuration space */
Szymon Janc78aea4f2010-11-27 08:39:43 +00006124 for (i = 0; i <= np->register_size/sizeof(u32); i++)
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02006125 writel(np->saved_config_space[i], base+i*sizeof(u32));
Ayaz Abdullaa376e792008-04-10 21:30:35 -07006126
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006127 if (np->driver_data & DEV_NEED_MSI_FIX)
6128 pci_write_config_dword(pdev, NV_MSI_PRIV_OFFSET, NV_MSI_PRIV_VALUE);
Ayaz Abdullab6e44052009-02-07 00:24:15 -08006129
Ed Swierk35a74332009-04-06 17:49:12 -07006130 /* restore phy state, including autoneg */
6131 phy_init(dev);
6132
Tobias Diedrich25d90812008-05-18 15:04:29 +02006133 netif_device_attach(dev);
6134 if (netif_running(dev)) {
6135 rc = nv_open(dev);
6136 nv_set_multicast(dev);
6137 }
Francois Romieua1893172006-10-10 14:33:27 -07006138 return rc;
6139}
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006140
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006141static SIMPLE_DEV_PM_OPS(nv_pm_ops, nv_suspend, nv_resume);
6142#define NV_PM_OPS (&nv_pm_ops)
6143
Michel Lespinasse94252762011-03-06 16:14:50 +00006144#else
6145#define NV_PM_OPS NULL
6146#endif /* CONFIG_PM_SLEEP */
6147
6148#ifdef CONFIG_PM
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006149static void nv_shutdown(struct pci_dev *pdev)
6150{
6151 struct net_device *dev = pci_get_drvdata(pdev);
6152 struct fe_priv *np = netdev_priv(dev);
6153
6154 if (netif_running(dev))
6155 nv_close(dev);
6156
Tobias Diedrich34edaa82009-02-16 00:13:20 -08006157 /*
6158 * Restore the MAC so a kernel started by kexec won't get confused.
6159 * If we really go for poweroff, we must not restore the MAC,
6160 * otherwise the MAC for WOL will be reversed at least on some boards.
6161 */
Szymon Janc78aea4f2010-11-27 08:39:43 +00006162 if (system_state != SYSTEM_POWER_OFF)
Tobias Diedrich34edaa82009-02-16 00:13:20 -08006163 nv_restore_mac_addr(pdev);
Yinghai Luf55c21f2008-09-13 13:10:31 -07006164
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006165 pci_disable_device(pdev);
Tobias Diedrich34edaa82009-02-16 00:13:20 -08006166 /*
6167 * Apparently it is not possible to reinitialise from D3 hot,
6168 * only put the device into D3 if we really go for poweroff.
6169 */
Rafael J. Wysocki3cb55992008-09-05 14:00:19 -07006170 if (system_state == SYSTEM_POWER_OFF) {
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006171 pci_wake_from_d3(pdev, np->wolenabled);
Rafael J. Wysocki3cb55992008-09-05 14:00:19 -07006172 pci_set_power_state(pdev, PCI_D3hot);
6173 }
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006174}
Francois Romieua1893172006-10-10 14:33:27 -07006175#else
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006176#define nv_shutdown NULL
Francois Romieua1893172006-10-10 14:33:27 -07006177#endif /* CONFIG_PM */
6178
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00006179static DEFINE_PCI_DEVICE_TABLE(pci_tbl) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07006180 { /* nForce Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006181 PCI_DEVICE(0x10DE, 0x01C3),
Manfred Spraulc2dba062005-07-31 18:29:47 +02006182 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006183 },
6184 { /* nForce2 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006185 PCI_DEVICE(0x10DE, 0x0066),
Manfred Spraulc2dba062005-07-31 18:29:47 +02006186 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006187 },
6188 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006189 PCI_DEVICE(0x10DE, 0x00D6),
Manfred Spraulc2dba062005-07-31 18:29:47 +02006190 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006191 },
6192 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006193 PCI_DEVICE(0x10DE, 0x0086),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04006194 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006195 },
6196 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006197 PCI_DEVICE(0x10DE, 0x008C),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04006198 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006199 },
6200 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006201 PCI_DEVICE(0x10DE, 0x00E6),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04006202 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006203 },
6204 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006205 PCI_DEVICE(0x10DE, 0x00DF),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04006206 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006207 },
6208 { /* CK804 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006209 PCI_DEVICE(0x10DE, 0x0056),
Yinghai Lu033e97b2009-02-06 01:30:56 -08006210 .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 -07006211 },
6212 { /* CK804 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006213 PCI_DEVICE(0x10DE, 0x0057),
Yinghai Lu033e97b2009-02-06 01:30:56 -08006214 .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 -07006215 },
6216 { /* MCP04 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006217 PCI_DEVICE(0x10DE, 0x0037),
Ayaz Abdulla9e184762009-03-05 08:02:18 +00006218 .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 -07006219 },
6220 { /* MCP04 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006221 PCI_DEVICE(0x10DE, 0x0038),
Ayaz Abdulla9e184762009-03-05 08:02:18 +00006222 .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 +02006223 },
6224 { /* MCP51 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006225 PCI_DEVICE(0x10DE, 0x0268),
6226 .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 -07006227 },
Manfred Spraul9992d4a2005-06-05 17:36:11 +02006228 { /* MCP51 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006229 PCI_DEVICE(0x10DE, 0x0269),
6230 .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 +02006231 },
Manfred Spraulf49d16e2005-06-26 11:36:52 +02006232 { /* MCP55 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006233 PCI_DEVICE(0x10DE, 0x0372),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006234 .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 +02006235 },
6236 { /* MCP55 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006237 PCI_DEVICE(0x10DE, 0x0373),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006238 .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 +02006239 },
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04006240 { /* MCP61 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006241 PCI_DEVICE(0x10DE, 0x03E5),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006242 .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 -04006243 },
6244 { /* MCP61 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006245 PCI_DEVICE(0x10DE, 0x03E6),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006246 .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 -04006247 },
6248 { /* MCP61 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006249 PCI_DEVICE(0x10DE, 0x03EE),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006250 .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 -04006251 },
6252 { /* MCP61 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006253 PCI_DEVICE(0x10DE, 0x03EF),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006254 .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 -04006255 },
6256 { /* MCP65 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006257 PCI_DEVICE(0x10DE, 0x0450),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006258 .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 -04006259 },
6260 { /* MCP65 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006261 PCI_DEVICE(0x10DE, 0x0451),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006262 .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 -04006263 },
6264 { /* MCP65 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006265 PCI_DEVICE(0x10DE, 0x0452),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006266 .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 -04006267 },
6268 { /* MCP65 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006269 PCI_DEVICE(0x10DE, 0x0453),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006270 .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 -04006271 },
Ayaz Abdullaf4344842006-11-06 00:43:40 -08006272 { /* MCP67 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006273 PCI_DEVICE(0x10DE, 0x054C),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006274 .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 -08006275 },
6276 { /* MCP67 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006277 PCI_DEVICE(0x10DE, 0x054D),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006278 .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 -08006279 },
6280 { /* MCP67 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006281 PCI_DEVICE(0x10DE, 0x054E),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006282 .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 -08006283 },
6284 { /* MCP67 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006285 PCI_DEVICE(0x10DE, 0x054F),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006286 .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 -08006287 },
Ayaz Abdulla13986612007-07-22 20:43:26 -04006288 { /* MCP73 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006289 PCI_DEVICE(0x10DE, 0x07DC),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006290 .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 -04006291 },
6292 { /* MCP73 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006293 PCI_DEVICE(0x10DE, 0x07DD),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006294 .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 -04006295 },
6296 { /* MCP73 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006297 PCI_DEVICE(0x10DE, 0x07DE),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006298 .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 -04006299 },
6300 { /* MCP73 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006301 PCI_DEVICE(0x10DE, 0x07DF),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006302 .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 -04006303 },
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04006304 { /* MCP77 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006305 PCI_DEVICE(0x10DE, 0x0760),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006306 .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 -04006307 },
6308 { /* MCP77 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006309 PCI_DEVICE(0x10DE, 0x0761),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006310 .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 -04006311 },
6312 { /* MCP77 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006313 PCI_DEVICE(0x10DE, 0x0762),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006314 .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 -04006315 },
6316 { /* MCP77 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006317 PCI_DEVICE(0x10DE, 0x0763),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006318 .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 -04006319 },
Ayaz Abdulla490dde82007-11-23 20:54:01 -05006320 { /* MCP79 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006321 PCI_DEVICE(0x10DE, 0x0AB0),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006322 .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 -05006323 },
6324 { /* MCP79 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006325 PCI_DEVICE(0x10DE, 0x0AB1),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006326 .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 -05006327 },
6328 { /* MCP79 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006329 PCI_DEVICE(0x10DE, 0x0AB2),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006330 .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 -05006331 },
6332 { /* MCP79 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006333 PCI_DEVICE(0x10DE, 0x0AB3),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006334 .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 -05006335 },
Ayaz Abdulla3df81c42009-06-03 15:05:35 +00006336 { /* MCP89 Ethernet Controller */
6337 PCI_DEVICE(0x10DE, 0x0D7D),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006338 .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 +00006339 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006340 {0,},
6341};
6342
6343static struct pci_driver driver = {
Jeff Garzik3f88ce42007-10-16 04:09:09 -04006344 .name = DRV_NAME,
6345 .id_table = pci_tbl,
6346 .probe = nv_probe,
Bill Pembertond05919a2012-12-03 09:23:20 -05006347 .remove = nv_remove,
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006348 .shutdown = nv_shutdown,
Rafael J. Wysockidba5a682011-01-07 11:12:05 +00006349 .driver.pm = NV_PM_OPS,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006350};
6351
Linus Torvalds1da177e2005-04-16 15:20:36 -07006352static int __init init_nic(void)
6353{
Jeff Garzik29917622006-08-19 17:48:59 -04006354 return pci_register_driver(&driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006355}
6356
6357static void __exit exit_nic(void)
6358{
6359 pci_unregister_driver(&driver);
6360}
6361
6362module_param(max_interrupt_work, int, 0);
6363MODULE_PARM_DESC(max_interrupt_work, "forcedeth maximum events handled per interrupt");
Ayaz Abdullaa971c322005-11-11 08:30:38 -05006364module_param(optimization_mode, int, 0);
Ayaz Abdulla9e184762009-03-05 08:02:18 +00006365MODULE_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 -05006366module_param(poll_interval, int, 0);
6367MODULE_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 -04006368module_param(msi, int, 0);
6369MODULE_PARM_DESC(msi, "MSI interrupts are enabled by setting to 1 and disabled by setting to 0.");
6370module_param(msix, int, 0);
6371MODULE_PARM_DESC(msix, "MSIX interrupts are enabled by setting to 1 and disabled by setting to 0.");
6372module_param(dma_64bit, int, 0);
6373MODULE_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 -04006374module_param(phy_cross, int, 0);
6375MODULE_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 -07006376module_param(phy_power_down, int, 0);
6377MODULE_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 +00006378module_param(debug_tx_timeout, bool, 0);
6379MODULE_PARM_DESC(debug_tx_timeout,
6380 "Dump tx related registers and ring when tx_timeout happens");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006381
6382MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>");
6383MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver");
6384MODULE_LICENSE("GPL");
6385
6386MODULE_DEVICE_TABLE(pci, pci_tbl);
6387
6388module_init(init_nic);
6389module_exit(exit_nic);