blob: 87757c89caef77551dbd020aeaec779debd3f817 [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 */
Ayaz Abdulla3e1a3ce2009-03-05 08:02:38 +000042#define FORCEDETH_VERSION "0.64"
Linus Torvalds1da177e2005-04-16 15:20:36 -070043#define DRV_NAME "forcedeth"
44
45#include <linux/module.h>
46#include <linux/types.h>
47#include <linux/pci.h>
48#include <linux/interrupt.h>
49#include <linux/netdevice.h>
50#include <linux/etherdevice.h>
51#include <linux/delay.h>
Alexey Dobriyand43c36d2009-10-07 17:09:06 +040052#include <linux/sched.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070053#include <linux/spinlock.h>
54#include <linux/ethtool.h>
55#include <linux/timer.h>
56#include <linux/skbuff.h>
57#include <linux/mii.h>
58#include <linux/random.h>
59#include <linux/init.h>
Manfred Spraul22c6d142005-04-19 21:17:09 +020060#include <linux/if_vlan.h>
Matthias Gehre910638a2006-03-28 01:56:48 -080061#include <linux/dma-mapping.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090062#include <linux/slab.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
64#include <asm/irq.h>
65#include <asm/io.h>
66#include <asm/uaccess.h>
67#include <asm/system.h>
68
69#if 0
70#define dprintk printk
71#else
72#define dprintk(x...) do { } while (0)
73#endif
74
Stephen Hemmingerbea33482007-10-03 16:41:36 -070075#define TX_WORK_PER_LOOP 64
76#define RX_WORK_PER_LOOP 64
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78/*
79 * Hardware access:
80 */
81
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +000082#define DEV_NEED_TIMERIRQ 0x0000001 /* set the timer irq flag in the irq mask */
83#define DEV_NEED_LINKTIMER 0x0000002 /* poll link settings. Relies on the timer irq */
84#define DEV_HAS_LARGEDESC 0x0000004 /* device supports jumbo frames and needs packet format 2 */
85#define DEV_HAS_HIGH_DMA 0x0000008 /* device supports 64bit dma */
86#define DEV_HAS_CHECKSUM 0x0000010 /* device supports tx and rx checksum offloads */
87#define DEV_HAS_VLAN 0x0000020 /* device supports vlan tagging and striping */
88#define DEV_HAS_MSI 0x0000040 /* device supports MSI */
89#define DEV_HAS_MSI_X 0x0000080 /* device supports MSI-X */
90#define DEV_HAS_POWER_CNTRL 0x0000100 /* device supports power savings */
91#define DEV_HAS_STATISTICS_V1 0x0000200 /* device supports hw statistics version 1 */
Mike Ditto7b5e0782010-07-25 21:54:28 -070092#define DEV_HAS_STATISTICS_V2 0x0000400 /* device supports hw statistics version 2 */
93#define DEV_HAS_STATISTICS_V3 0x0000800 /* device supports hw statistics version 3 */
94#define DEV_HAS_STATISTICS_V12 0x0000600 /* device supports hw statistics version 1 and 2 */
95#define DEV_HAS_STATISTICS_V123 0x0000e00 /* device supports hw statistics version 1, 2, and 3 */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +000096#define DEV_HAS_TEST_EXTENDED 0x0001000 /* device supports extended diagnostic test */
97#define DEV_HAS_MGMT_UNIT 0x0002000 /* device supports management unit */
98#define DEV_HAS_CORRECT_MACADDR 0x0004000 /* device supports correct mac address order */
99#define DEV_HAS_COLLISION_FIX 0x0008000 /* device supports tx collision fix */
100#define DEV_HAS_PAUSEFRAME_TX_V1 0x0010000 /* device supports tx pause frames version 1 */
101#define DEV_HAS_PAUSEFRAME_TX_V2 0x0020000 /* device supports tx pause frames version 2 */
102#define DEV_HAS_PAUSEFRAME_TX_V3 0x0040000 /* device supports tx pause frames version 3 */
103#define DEV_NEED_TX_LIMIT 0x0080000 /* device needs to limit tx */
104#define DEV_NEED_TX_LIMIT2 0x0180000 /* device needs to limit tx, expect for some revs */
105#define DEV_HAS_GEAR_MODE 0x0200000 /* device supports gear mode */
106#define DEV_NEED_PHY_INIT_FIX 0x0400000 /* device needs specific phy workaround */
107#define DEV_NEED_LOW_POWER_FIX 0x0800000 /* device needs special power up workaround */
108#define DEV_NEED_MSI_FIX 0x1000000 /* device needs msi workaround */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109
110enum {
111 NvRegIrqStatus = 0x000,
112#define NVREG_IRQSTAT_MIIEVENT 0x040
Ayaz Abdulladaa91a92009-02-07 00:25:00 -0800113#define NVREG_IRQSTAT_MASK 0x83ff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 NvRegIrqMask = 0x004,
115#define NVREG_IRQ_RX_ERROR 0x0001
116#define NVREG_IRQ_RX 0x0002
117#define NVREG_IRQ_RX_NOBUF 0x0004
118#define NVREG_IRQ_TX_ERR 0x0008
Manfred Spraulc2dba062005-07-31 18:29:47 +0200119#define NVREG_IRQ_TX_OK 0x0010
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120#define NVREG_IRQ_TIMER 0x0020
121#define NVREG_IRQ_LINK 0x0040
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500122#define NVREG_IRQ_RX_FORCED 0x0080
123#define NVREG_IRQ_TX_FORCED 0x0100
Ayaz Abdulladaa91a92009-02-07 00:25:00 -0800124#define NVREG_IRQ_RECOVER_ERROR 0x8200
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500125#define NVREG_IRQMASK_THROUGHPUT 0x00df
Ayaz Abdulla096a4582007-05-21 20:23:11 -0400126#define NVREG_IRQMASK_CPU 0x0060
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500127#define NVREG_IRQ_TX_ALL (NVREG_IRQ_TX_ERR|NVREG_IRQ_TX_OK|NVREG_IRQ_TX_FORCED)
128#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 -0500129#define NVREG_IRQ_OTHER (NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_RECOVER_ERROR)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200130
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 NvRegUnknownSetupReg6 = 0x008,
132#define NVREG_UNKSETUP6_VAL 3
133
134/*
135 * NVREG_POLL_DEFAULT is the interval length of the timer source on the nic
136 * NVREG_POLL_DEFAULT=97 would result in an interval length of 1 ms
137 */
138 NvRegPollingInterval = 0x00c,
Ayaz Abdulla6cef67a2009-03-05 08:02:30 +0000139#define NVREG_POLL_DEFAULT_THROUGHPUT 65535 /* backup tx cleanup if loop max reached */
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500140#define NVREG_POLL_DEFAULT_CPU 13
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500141 NvRegMSIMap0 = 0x020,
142 NvRegMSIMap1 = 0x024,
143 NvRegMSIIrqMask = 0x030,
144#define NVREG_MSI_VECTOR_0_ENABLED 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 NvRegMisc1 = 0x080,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400146#define NVREG_MISC1_PAUSE_TX 0x01
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147#define NVREG_MISC1_HD 0x02
148#define NVREG_MISC1_FORCE 0x3b0f3c
149
Ayaz Abdulla0a626772008-01-13 16:02:42 -0500150 NvRegMacReset = 0x34,
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400151#define NVREG_MAC_RESET_ASSERT 0x0F3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 NvRegTransmitterControl = 0x084,
153#define NVREG_XMITCTL_START 0x01
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500154#define NVREG_XMITCTL_MGMT_ST 0x40000000
155#define NVREG_XMITCTL_SYNC_MASK 0x000f0000
156#define NVREG_XMITCTL_SYNC_NOT_READY 0x0
157#define NVREG_XMITCTL_SYNC_PHY_INIT 0x00040000
158#define NVREG_XMITCTL_MGMT_SEMA_MASK 0x00000f00
159#define NVREG_XMITCTL_MGMT_SEMA_FREE 0x0
160#define NVREG_XMITCTL_HOST_SEMA_MASK 0x0000f000
161#define NVREG_XMITCTL_HOST_SEMA_ACQ 0x0000f000
162#define NVREG_XMITCTL_HOST_LOADED 0x00004000
Ayaz Abdullaf35723e2003-02-20 03:03:54 -0500163#define NVREG_XMITCTL_TX_PATH_EN 0x01000000
Ayaz Abdullacac1c522009-02-07 00:23:57 -0800164#define NVREG_XMITCTL_DATA_START 0x00100000
165#define NVREG_XMITCTL_DATA_READY 0x00010000
166#define NVREG_XMITCTL_DATA_ERROR 0x00020000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 NvRegTransmitterStatus = 0x088,
168#define NVREG_XMITSTAT_BUSY 0x01
169
170 NvRegPacketFilterFlags = 0x8c,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400171#define NVREG_PFF_PAUSE_RX 0x08
172#define NVREG_PFF_ALWAYS 0x7F0000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173#define NVREG_PFF_PROMISC 0x80
174#define NVREG_PFF_MYADDR 0x20
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400175#define NVREG_PFF_LOOPBACK 0x10
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176
177 NvRegOffloadConfig = 0x90,
178#define NVREG_OFFLOAD_HOMEPHY 0x601
179#define NVREG_OFFLOAD_NORMAL RX_NIC_BUFSIZE
180 NvRegReceiverControl = 0x094,
181#define NVREG_RCVCTL_START 0x01
Ayaz Abdullaf35723e2003-02-20 03:03:54 -0500182#define NVREG_RCVCTL_RX_PATH_EN 0x01000000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 NvRegReceiverStatus = 0x98,
184#define NVREG_RCVSTAT_BUSY 0x01
185
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700186 NvRegSlotTime = 0x9c,
187#define NVREG_SLOTTIME_LEGBF_ENABLED 0x80000000
188#define NVREG_SLOTTIME_10_100_FULL 0x00007f00
Szymon Janc78aea4f2010-11-27 08:39:43 +0000189#define NVREG_SLOTTIME_1000_FULL 0x0003ff00
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700190#define NVREG_SLOTTIME_HALF 0x0000ff00
Szymon Janc78aea4f2010-11-27 08:39:43 +0000191#define NVREG_SLOTTIME_DEFAULT 0x00007f00
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700192#define NVREG_SLOTTIME_MASK 0x000000ff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Ayaz Abdulla9744e212006-07-06 16:45:58 -0400194 NvRegTxDeferral = 0xA0,
Ayaz Abdullafd9b5582008-02-05 12:29:49 -0500195#define NVREG_TX_DEFERRAL_DEFAULT 0x15050f
196#define NVREG_TX_DEFERRAL_RGMII_10_100 0x16070f
197#define NVREG_TX_DEFERRAL_RGMII_1000 0x14050f
198#define NVREG_TX_DEFERRAL_RGMII_STRETCH_10 0x16190f
199#define NVREG_TX_DEFERRAL_RGMII_STRETCH_100 0x16300f
200#define NVREG_TX_DEFERRAL_MII_STRETCH 0x152000
Ayaz Abdulla9744e212006-07-06 16:45:58 -0400201 NvRegRxDeferral = 0xA4,
202#define NVREG_RX_DEFERRAL_DEFAULT 0x16
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 NvRegMacAddrA = 0xA8,
204 NvRegMacAddrB = 0xAC,
205 NvRegMulticastAddrA = 0xB0,
206#define NVREG_MCASTADDRA_FORCE 0x01
207 NvRegMulticastAddrB = 0xB4,
208 NvRegMulticastMaskA = 0xB8,
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -0500209#define NVREG_MCASTMASKA_NONE 0xffffffff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210 NvRegMulticastMaskB = 0xBC,
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -0500211#define NVREG_MCASTMASKB_NONE 0xffff
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212
213 NvRegPhyInterface = 0xC0,
214#define PHY_RGMII 0x10000000
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700215 NvRegBackOffControl = 0xC4,
216#define NVREG_BKOFFCTRL_DEFAULT 0x70000000
217#define NVREG_BKOFFCTRL_SEED_MASK 0x000003ff
218#define NVREG_BKOFFCTRL_SELECT 24
219#define NVREG_BKOFFCTRL_GEAR 12
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220
221 NvRegTxRingPhysAddr = 0x100,
222 NvRegRxRingPhysAddr = 0x104,
223 NvRegRingSizes = 0x108,
224#define NVREG_RINGSZ_TXSHIFT 0
225#define NVREG_RINGSZ_RXSHIFT 16
Ayaz Abdulla5070d342006-07-31 12:05:01 -0400226 NvRegTransmitPoll = 0x10c,
227#define NVREG_TRANSMITPOLL_MAC_ADDR_REV 0x00008000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 NvRegLinkSpeed = 0x110,
229#define NVREG_LINKSPEED_FORCE 0x10000
230#define NVREG_LINKSPEED_10 1000
231#define NVREG_LINKSPEED_100 100
232#define NVREG_LINKSPEED_1000 50
233#define NVREG_LINKSPEED_MASK (0xFFF)
234 NvRegUnknownSetupReg5 = 0x130,
235#define NVREG_UNKSETUP5_BIT31 (1<<31)
Ayaz Abdulla95d161c2006-07-06 16:46:25 -0400236 NvRegTxWatermark = 0x13c,
237#define NVREG_TX_WM_DESC1_DEFAULT 0x0200010
238#define NVREG_TX_WM_DESC2_3_DEFAULT 0x1e08000
239#define NVREG_TX_WM_DESC2_3_1000 0xfe08000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 NvRegTxRxControl = 0x144,
241#define NVREG_TXRXCTL_KICK 0x0001
242#define NVREG_TXRXCTL_BIT1 0x0002
243#define NVREG_TXRXCTL_BIT2 0x0004
244#define NVREG_TXRXCTL_IDLE 0x0008
245#define NVREG_TXRXCTL_RESET 0x0010
246#define NVREG_TXRXCTL_RXCHECK 0x0400
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400247#define NVREG_TXRXCTL_DESC_1 0
Ayaz Abdullad2f78412007-01-09 13:30:02 -0500248#define NVREG_TXRXCTL_DESC_2 0x002100
249#define NVREG_TXRXCTL_DESC_3 0xc02200
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500250#define NVREG_TXRXCTL_VLANSTRIP 0x00040
251#define NVREG_TXRXCTL_VLANINS 0x00080
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500252 NvRegTxRingPhysAddrHigh = 0x148,
253 NvRegRxRingPhysAddrHigh = 0x14C,
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400254 NvRegTxPauseFrame = 0x170,
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -0500255#define NVREG_TX_PAUSEFRAME_DISABLE 0x0fff0080
256#define NVREG_TX_PAUSEFRAME_ENABLE_V1 0x01800010
257#define NVREG_TX_PAUSEFRAME_ENABLE_V2 0x056003f0
258#define NVREG_TX_PAUSEFRAME_ENABLE_V3 0x09f00880
Ayaz Abdulla9a33e882008-08-06 12:12:34 -0400259 NvRegTxPauseFrameLimit = 0x174,
260#define NVREG_TX_PAUSEFRAMELIMIT_ENABLE 0x00010000
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261 NvRegMIIStatus = 0x180,
262#define NVREG_MIISTAT_ERROR 0x0001
263#define NVREG_MIISTAT_LINKCHANGE 0x0008
Ayaz Abdullaeb798422008-02-04 15:14:04 -0500264#define NVREG_MIISTAT_MASK_RW 0x0007
265#define NVREG_MIISTAT_MASK_ALL 0x000f
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500266 NvRegMIIMask = 0x184,
267#define NVREG_MII_LINKCHANGE 0x0008
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268
269 NvRegAdapterControl = 0x188,
270#define NVREG_ADAPTCTL_START 0x02
271#define NVREG_ADAPTCTL_LINKUP 0x04
272#define NVREG_ADAPTCTL_PHYVALID 0x40000
273#define NVREG_ADAPTCTL_RUNNING 0x100000
274#define NVREG_ADAPTCTL_PHYSHIFT 24
275 NvRegMIISpeed = 0x18c,
276#define NVREG_MIISPEED_BIT8 (1<<8)
277#define NVREG_MIIDELAY 5
278 NvRegMIIControl = 0x190,
279#define NVREG_MIICTL_INUSE 0x08000
280#define NVREG_MIICTL_WRITE 0x00400
281#define NVREG_MIICTL_ADDRSHIFT 5
282 NvRegMIIData = 0x194,
Ayaz Abdulla9c662432008-08-06 12:11:42 -0400283 NvRegTxUnicast = 0x1a0,
284 NvRegTxMulticast = 0x1a4,
285 NvRegTxBroadcast = 0x1a8,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 NvRegWakeUpFlags = 0x200,
287#define NVREG_WAKEUPFLAGS_VAL 0x7770
288#define NVREG_WAKEUPFLAGS_BUSYSHIFT 24
289#define NVREG_WAKEUPFLAGS_ENABLESHIFT 16
290#define NVREG_WAKEUPFLAGS_D3SHIFT 12
291#define NVREG_WAKEUPFLAGS_D2SHIFT 8
292#define NVREG_WAKEUPFLAGS_D1SHIFT 4
293#define NVREG_WAKEUPFLAGS_D0SHIFT 0
294#define NVREG_WAKEUPFLAGS_ACCEPT_MAGPAT 0x01
295#define NVREG_WAKEUPFLAGS_ACCEPT_WAKEUPPAT 0x02
296#define NVREG_WAKEUPFLAGS_ACCEPT_LINKCHANGE 0x04
297#define NVREG_WAKEUPFLAGS_ENABLE 0x1111
298
Ayaz Abdullacac1c522009-02-07 00:23:57 -0800299 NvRegMgmtUnitGetVersion = 0x204,
Szymon Janc78aea4f2010-11-27 08:39:43 +0000300#define NVREG_MGMTUNITGETVERSION 0x01
Ayaz Abdullacac1c522009-02-07 00:23:57 -0800301 NvRegMgmtUnitVersion = 0x208,
302#define NVREG_MGMTUNITVERSION 0x08
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 NvRegPowerCap = 0x268,
304#define NVREG_POWERCAP_D3SUPP (1<<30)
305#define NVREG_POWERCAP_D2SUPP (1<<26)
306#define NVREG_POWERCAP_D1SUPP (1<<25)
307 NvRegPowerState = 0x26c,
308#define NVREG_POWERSTATE_POWEREDUP 0x8000
309#define NVREG_POWERSTATE_VALID 0x0100
310#define NVREG_POWERSTATE_MASK 0x0003
311#define NVREG_POWERSTATE_D0 0x0000
312#define NVREG_POWERSTATE_D1 0x0001
313#define NVREG_POWERSTATE_D2 0x0002
314#define NVREG_POWERSTATE_D3 0x0003
Ayaz Abdullacac1c522009-02-07 00:23:57 -0800315 NvRegMgmtUnitControl = 0x278,
316#define NVREG_MGMTUNITCONTROL_INUSE 0x20000
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400317 NvRegTxCnt = 0x280,
318 NvRegTxZeroReXmt = 0x284,
319 NvRegTxOneReXmt = 0x288,
320 NvRegTxManyReXmt = 0x28c,
321 NvRegTxLateCol = 0x290,
322 NvRegTxUnderflow = 0x294,
323 NvRegTxLossCarrier = 0x298,
324 NvRegTxExcessDef = 0x29c,
325 NvRegTxRetryErr = 0x2a0,
326 NvRegRxFrameErr = 0x2a4,
327 NvRegRxExtraByte = 0x2a8,
328 NvRegRxLateCol = 0x2ac,
329 NvRegRxRunt = 0x2b0,
330 NvRegRxFrameTooLong = 0x2b4,
331 NvRegRxOverflow = 0x2b8,
332 NvRegRxFCSErr = 0x2bc,
333 NvRegRxFrameAlignErr = 0x2c0,
334 NvRegRxLenErr = 0x2c4,
335 NvRegRxUnicast = 0x2c8,
336 NvRegRxMulticast = 0x2cc,
337 NvRegRxBroadcast = 0x2d0,
338 NvRegTxDef = 0x2d4,
339 NvRegTxFrame = 0x2d8,
340 NvRegRxCnt = 0x2dc,
341 NvRegTxPause = 0x2e0,
342 NvRegRxPause = 0x2e4,
343 NvRegRxDropFrame = 0x2e8,
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500344 NvRegVlanControl = 0x300,
345#define NVREG_VLANCONTROL_ENABLE 0x2000
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500346 NvRegMSIXMap0 = 0x3e0,
347 NvRegMSIXMap1 = 0x3e4,
348 NvRegMSIXIrqStatus = 0x3f0,
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400349
350 NvRegPowerState2 = 0x600,
Ayaz Abdulla1545e202008-09-22 09:55:35 -0400351#define NVREG_POWERSTATE2_POWERUP_MASK 0x0F15
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400352#define NVREG_POWERSTATE2_POWERUP_REV_A3 0x0001
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -0400353#define NVREG_POWERSTATE2_PHY_RESET 0x0004
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +0000354#define NVREG_POWERSTATE2_GATE_CLOCKS 0x0F00
Linus Torvalds1da177e2005-04-16 15:20:36 -0700355};
356
357/* Big endian: should work, but is untested */
358struct ring_desc {
Stephen Hemmingera8bed492006-07-27 18:50:09 -0700359 __le32 buf;
360 __le32 flaglen;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361};
362
Manfred Spraulee733622005-07-31 18:32:26 +0200363struct ring_desc_ex {
Stephen Hemmingera8bed492006-07-27 18:50:09 -0700364 __le32 bufhigh;
365 __le32 buflow;
366 __le32 txvlan;
367 __le32 flaglen;
Manfred Spraulee733622005-07-31 18:32:26 +0200368};
369
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700370union ring_type {
Szymon Janc78aea4f2010-11-27 08:39:43 +0000371 struct ring_desc *orig;
372 struct ring_desc_ex *ex;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700373};
Manfred Spraulee733622005-07-31 18:32:26 +0200374
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375#define FLAG_MASK_V1 0xffff0000
376#define FLAG_MASK_V2 0xffffc000
377#define LEN_MASK_V1 (0xffffffff ^ FLAG_MASK_V1)
378#define LEN_MASK_V2 (0xffffffff ^ FLAG_MASK_V2)
379
380#define NV_TX_LASTPACKET (1<<16)
381#define NV_TX_RETRYERROR (1<<19)
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700382#define NV_TX_RETRYCOUNT_MASK (0xF<<20)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200383#define NV_TX_FORCED_INTERRUPT (1<<24)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384#define NV_TX_DEFERRED (1<<26)
385#define NV_TX_CARRIERLOST (1<<27)
386#define NV_TX_LATECOLLISION (1<<28)
387#define NV_TX_UNDERFLOW (1<<29)
388#define NV_TX_ERROR (1<<30)
389#define NV_TX_VALID (1<<31)
390
391#define NV_TX2_LASTPACKET (1<<29)
392#define NV_TX2_RETRYERROR (1<<18)
Ayaz Abdullaa4336862008-04-18 13:50:43 -0700393#define NV_TX2_RETRYCOUNT_MASK (0xF<<19)
Manfred Spraulc2dba062005-07-31 18:29:47 +0200394#define NV_TX2_FORCED_INTERRUPT (1<<30)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395#define NV_TX2_DEFERRED (1<<25)
396#define NV_TX2_CARRIERLOST (1<<26)
397#define NV_TX2_LATECOLLISION (1<<27)
398#define NV_TX2_UNDERFLOW (1<<28)
399/* error and valid are the same for both */
400#define NV_TX2_ERROR (1<<30)
401#define NV_TX2_VALID (1<<31)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400402#define NV_TX2_TSO (1<<28)
403#define NV_TX2_TSO_SHIFT 14
Ayaz Abdullafa454592006-01-05 22:45:45 -0800404#define NV_TX2_TSO_MAX_SHIFT 14
405#define NV_TX2_TSO_MAX_SIZE (1<<NV_TX2_TSO_MAX_SHIFT)
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400406#define NV_TX2_CHECKSUM_L3 (1<<27)
407#define NV_TX2_CHECKSUM_L4 (1<<26)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700408
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500409#define NV_TX3_VLAN_TAG_PRESENT (1<<18)
410
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411#define NV_RX_DESCRIPTORVALID (1<<16)
412#define NV_RX_MISSEDFRAME (1<<17)
413#define NV_RX_SUBSTRACT1 (1<<18)
414#define NV_RX_ERROR1 (1<<23)
415#define NV_RX_ERROR2 (1<<24)
416#define NV_RX_ERROR3 (1<<25)
417#define NV_RX_ERROR4 (1<<26)
418#define NV_RX_CRCERR (1<<27)
419#define NV_RX_OVERFLOW (1<<28)
420#define NV_RX_FRAMINGERR (1<<29)
421#define NV_RX_ERROR (1<<30)
422#define NV_RX_AVAIL (1<<31)
Ayaz Abdulla1ef68412008-08-06 12:11:03 -0400423#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 -0700424
425#define NV_RX2_CHECKSUMMASK (0x1C000000)
Ayaz Abdullabfaffe82008-01-13 16:02:55 -0500426#define NV_RX2_CHECKSUM_IP (0x10000000)
427#define NV_RX2_CHECKSUM_IP_TCP (0x14000000)
428#define NV_RX2_CHECKSUM_IP_UDP (0x18000000)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429#define NV_RX2_DESCRIPTORVALID (1<<29)
430#define NV_RX2_SUBSTRACT1 (1<<25)
431#define NV_RX2_ERROR1 (1<<18)
432#define NV_RX2_ERROR2 (1<<19)
433#define NV_RX2_ERROR3 (1<<20)
434#define NV_RX2_ERROR4 (1<<21)
435#define NV_RX2_CRCERR (1<<22)
436#define NV_RX2_OVERFLOW (1<<23)
437#define NV_RX2_FRAMINGERR (1<<24)
438/* error and avail are the same for both */
439#define NV_RX2_ERROR (1<<30)
440#define NV_RX2_AVAIL (1<<31)
Ayaz Abdulla1ef68412008-08-06 12:11:03 -0400441#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 -0700442
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500443#define NV_RX3_VLAN_TAG_PRESENT (1<<16)
444#define NV_RX3_VLAN_TAG_MASK (0x0000FFFF)
445
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446/* Miscelaneous hardware related defines: */
Szymon Janc78aea4f2010-11-27 08:39:43 +0000447#define NV_PCI_REGSZ_VER1 0x270
448#define NV_PCI_REGSZ_VER2 0x2d4
449#define NV_PCI_REGSZ_VER3 0x604
450#define NV_PCI_REGSZ_MAX 0x604
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451
452/* various timeout delays: all in usec */
453#define NV_TXRX_RESET_DELAY 4
454#define NV_TXSTOP_DELAY1 10
455#define NV_TXSTOP_DELAY1MAX 500000
456#define NV_TXSTOP_DELAY2 100
457#define NV_RXSTOP_DELAY1 10
458#define NV_RXSTOP_DELAY1MAX 500000
459#define NV_RXSTOP_DELAY2 100
460#define NV_SETUP5_DELAY 5
461#define NV_SETUP5_DELAYMAX 50000
462#define NV_POWERUP_DELAY 5
463#define NV_POWERUP_DELAYMAX 5000
464#define NV_MIIBUSY_DELAY 50
465#define NV_MIIPHY_DELAY 10
466#define NV_MIIPHY_DELAYMAX 10000
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400467#define NV_MAC_RESET_DELAY 64
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468
469#define NV_WAKEUPPATTERNS 5
470#define NV_WAKEUPMASKENTRIES 4
471
472/* General driver defaults */
473#define NV_WATCHDOG_TIMEO (5*HZ)
474
Ayaz Abdulla6cef67a2009-03-05 08:02:30 +0000475#define RX_RING_DEFAULT 512
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400476#define TX_RING_DEFAULT 256
477#define RX_RING_MIN 128
478#define TX_RING_MIN 64
479#define RING_MAX_DESC_VER_1 1024
480#define RING_MAX_DESC_VER_2_3 16384
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
482/* rx/tx mac addr + type + vlan + align + slack*/
Manfred Sprauld81c0982005-07-31 18:20:30 +0200483#define NV_RX_HEADERS (64)
484/* even more slack. */
485#define NV_RX_ALLOC_PAD (64)
486
487/* maximum mtu size */
488#define NV_PKTLIMIT_1 ETH_DATA_LEN /* hard limit not known */
489#define NV_PKTLIMIT_2 9100 /* Actual limit according to NVidia: 9202 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700490
491#define OOM_REFILL (1+HZ/20)
492#define POLL_WAIT (1+HZ/100)
493#define LINK_TIMEOUT (3*HZ)
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400494#define STATS_INTERVAL (10*HZ)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400496/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497 * desc_ver values:
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400498 * The nic supports three different descriptor types:
499 * - DESC_VER_1: Original
500 * - DESC_VER_2: support for jumbo frames.
501 * - DESC_VER_3: 64-bit format.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502 */
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400503#define DESC_VER_1 1
504#define DESC_VER_2 2
505#define DESC_VER_3 3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506
507/* PHY defines */
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400508#define PHY_OUI_MARVELL 0x5043
509#define PHY_OUI_CICADA 0x03f1
510#define PHY_OUI_VITESSE 0x01c1
511#define PHY_OUI_REALTEK 0x0732
512#define PHY_OUI_REALTEK2 0x0020
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513#define PHYID1_OUI_MASK 0x03ff
514#define PHYID1_OUI_SHFT 6
515#define PHYID2_OUI_MASK 0xfc00
516#define PHYID2_OUI_SHFT 10
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -0400517#define PHYID2_MODEL_MASK 0x03f0
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400518#define PHY_MODEL_REALTEK_8211 0x0110
519#define PHY_REV_MASK 0x0001
520#define PHY_REV_REALTEK_8211B 0x0000
521#define PHY_REV_REALTEK_8211C 0x0001
522#define PHY_MODEL_REALTEK_8201 0x0200
523#define PHY_MODEL_MARVELL_E3016 0x0220
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -0400524#define PHY_MARVELL_E3016_INITMASK 0x0300
Ayaz Abdulla14a67f32007-07-15 06:50:28 -0400525#define PHY_CICADA_INIT1 0x0f000
526#define PHY_CICADA_INIT2 0x0e00
527#define PHY_CICADA_INIT3 0x01000
528#define PHY_CICADA_INIT4 0x0200
529#define PHY_CICADA_INIT5 0x0004
530#define PHY_CICADA_INIT6 0x02000
Ayaz Abdullad215d8a2007-07-15 06:50:53 -0400531#define PHY_VITESSE_INIT_REG1 0x1f
532#define PHY_VITESSE_INIT_REG2 0x10
533#define PHY_VITESSE_INIT_REG3 0x11
534#define PHY_VITESSE_INIT_REG4 0x12
535#define PHY_VITESSE_INIT_MSK1 0xc
536#define PHY_VITESSE_INIT_MSK2 0x0180
537#define PHY_VITESSE_INIT1 0x52b5
538#define PHY_VITESSE_INIT2 0xaf8a
539#define PHY_VITESSE_INIT3 0x8
540#define PHY_VITESSE_INIT4 0x8f8a
541#define PHY_VITESSE_INIT5 0xaf86
542#define PHY_VITESSE_INIT6 0x8f86
543#define PHY_VITESSE_INIT7 0xaf82
544#define PHY_VITESSE_INIT8 0x0100
545#define PHY_VITESSE_INIT9 0x8f82
546#define PHY_VITESSE_INIT10 0x0
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -0400547#define PHY_REALTEK_INIT_REG1 0x1f
548#define PHY_REALTEK_INIT_REG2 0x19
549#define PHY_REALTEK_INIT_REG3 0x13
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400550#define PHY_REALTEK_INIT_REG4 0x14
551#define PHY_REALTEK_INIT_REG5 0x18
552#define PHY_REALTEK_INIT_REG6 0x11
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -0400553#define PHY_REALTEK_INIT_REG7 0x01
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -0400554#define PHY_REALTEK_INIT1 0x0000
555#define PHY_REALTEK_INIT2 0x8e00
556#define PHY_REALTEK_INIT3 0x0001
557#define PHY_REALTEK_INIT4 0xad17
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400558#define PHY_REALTEK_INIT5 0xfb54
559#define PHY_REALTEK_INIT6 0xf5c7
560#define PHY_REALTEK_INIT7 0x1000
561#define PHY_REALTEK_INIT8 0x0003
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -0400562#define PHY_REALTEK_INIT9 0x0008
563#define PHY_REALTEK_INIT10 0x0005
564#define PHY_REALTEK_INIT11 0x0200
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400565#define PHY_REALTEK_INIT_MSK1 0x0003
Ayaz Abdullad215d8a2007-07-15 06:50:53 -0400566
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567#define PHY_GIGABIT 0x0100
568
569#define PHY_TIMEOUT 0x1
570#define PHY_ERROR 0x2
571
572#define PHY_100 0x1
573#define PHY_1000 0x2
574#define PHY_HALF 0x100
575
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400576#define NV_PAUSEFRAME_RX_CAPABLE 0x0001
577#define NV_PAUSEFRAME_TX_CAPABLE 0x0002
578#define NV_PAUSEFRAME_RX_ENABLE 0x0004
579#define NV_PAUSEFRAME_TX_ENABLE 0x0008
Ayaz Abdullab6d07732006-06-10 22:47:42 -0400580#define NV_PAUSEFRAME_RX_REQ 0x0010
581#define NV_PAUSEFRAME_TX_REQ 0x0020
582#define NV_PAUSEFRAME_AUTONEG 0x0040
Linus Torvalds1da177e2005-04-16 15:20:36 -0700583
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500584/* MSI/MSI-X defines */
585#define NV_MSI_X_MAX_VECTORS 8
586#define NV_MSI_X_VECTORS_MASK 0x000f
587#define NV_MSI_CAPABLE 0x0010
588#define NV_MSI_X_CAPABLE 0x0020
589#define NV_MSI_ENABLED 0x0040
590#define NV_MSI_X_ENABLED 0x0080
591
592#define NV_MSI_X_VECTOR_ALL 0x0
593#define NV_MSI_X_VECTOR_RX 0x0
594#define NV_MSI_X_VECTOR_TX 0x1
595#define NV_MSI_X_VECTOR_OTHER 0x2
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Ayaz Abdullab6e44052009-02-07 00:24:15 -0800597#define NV_MSI_PRIV_OFFSET 0x68
598#define NV_MSI_PRIV_VALUE 0xffffffff
599
Ayaz Abdullab2976d22008-02-04 15:13:59 -0500600#define NV_RESTART_TX 0x1
601#define NV_RESTART_RX 0x2
602
Ayaz Abdulla3b446c32008-03-10 14:58:21 -0500603#define NV_TX_LIMIT_COUNT 16
604
Ayaz Abdulla4145ade2009-03-05 08:02:26 +0000605#define NV_DYNAMIC_THRESHOLD 4
606#define NV_DYNAMIC_MAX_QUIET_COUNT 2048
607
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400608/* statistics */
609struct nv_ethtool_str {
610 char name[ETH_GSTRING_LEN];
611};
612
613static const struct nv_ethtool_str nv_estats_str[] = {
614 { "tx_bytes" },
615 { "tx_zero_rexmt" },
616 { "tx_one_rexmt" },
617 { "tx_many_rexmt" },
618 { "tx_late_collision" },
619 { "tx_fifo_errors" },
620 { "tx_carrier_errors" },
621 { "tx_excess_deferral" },
622 { "tx_retry_error" },
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400623 { "rx_frame_error" },
624 { "rx_extra_byte" },
625 { "rx_late_collision" },
626 { "rx_runt" },
627 { "rx_frame_too_long" },
628 { "rx_over_errors" },
629 { "rx_crc_errors" },
630 { "rx_frame_align_error" },
631 { "rx_length_error" },
632 { "rx_unicast" },
633 { "rx_multicast" },
634 { "rx_broadcast" },
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400635 { "rx_packets" },
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500636 { "rx_errors_total" },
637 { "tx_errors_total" },
638
639 /* version 2 stats */
640 { "tx_deferral" },
641 { "tx_packets" },
642 { "rx_bytes" },
643 { "tx_pause" },
644 { "rx_pause" },
Ayaz Abdulla9c662432008-08-06 12:11:42 -0400645 { "rx_drop_frame" },
646
647 /* version 3 stats */
648 { "tx_unicast" },
649 { "tx_multicast" },
650 { "tx_broadcast" }
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400651};
652
653struct nv_ethtool_stats {
654 u64 tx_bytes;
655 u64 tx_zero_rexmt;
656 u64 tx_one_rexmt;
657 u64 tx_many_rexmt;
658 u64 tx_late_collision;
659 u64 tx_fifo_errors;
660 u64 tx_carrier_errors;
661 u64 tx_excess_deferral;
662 u64 tx_retry_error;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400663 u64 rx_frame_error;
664 u64 rx_extra_byte;
665 u64 rx_late_collision;
666 u64 rx_runt;
667 u64 rx_frame_too_long;
668 u64 rx_over_errors;
669 u64 rx_crc_errors;
670 u64 rx_frame_align_error;
671 u64 rx_length_error;
672 u64 rx_unicast;
673 u64 rx_multicast;
674 u64 rx_broadcast;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400675 u64 rx_packets;
676 u64 rx_errors_total;
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500677 u64 tx_errors_total;
678
679 /* version 2 stats */
680 u64 tx_deferral;
681 u64 tx_packets;
682 u64 rx_bytes;
683 u64 tx_pause;
684 u64 rx_pause;
685 u64 rx_drop_frame;
Ayaz Abdulla9c662432008-08-06 12:11:42 -0400686
687 /* version 3 stats */
688 u64 tx_unicast;
689 u64 tx_multicast;
690 u64 tx_broadcast;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400691};
692
Ayaz Abdulla9c662432008-08-06 12:11:42 -0400693#define NV_DEV_STATISTICS_V3_COUNT (sizeof(struct nv_ethtool_stats)/sizeof(u64))
694#define NV_DEV_STATISTICS_V2_COUNT (NV_DEV_STATISTICS_V3_COUNT - 3)
Ayaz Abdulla57fff692007-01-23 12:27:00 -0500695#define NV_DEV_STATISTICS_V1_COUNT (NV_DEV_STATISTICS_V2_COUNT - 6)
696
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400697/* diagnostics */
698#define NV_TEST_COUNT_BASE 3
699#define NV_TEST_COUNT_EXTENDED 4
700
701static const struct nv_ethtool_str nv_etests_str[] = {
702 { "link (online/offline)" },
703 { "register (offline) " },
704 { "interrupt (offline) " },
705 { "loopback (offline) " }
706};
707
708struct register_test {
Al Viro5bb7ea22007-12-09 16:06:41 +0000709 __u32 reg;
710 __u32 mask;
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400711};
712
713static const struct register_test nv_registers_test[] = {
714 { NvRegUnknownSetupReg6, 0x01 },
715 { NvRegMisc1, 0x03c },
716 { NvRegOffloadConfig, 0x03ff },
717 { NvRegMulticastAddrA, 0xffffffff },
Ayaz Abdulla95d161c2006-07-06 16:46:25 -0400718 { NvRegTxWatermark, 0x0ff },
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400719 { NvRegWakeUpFlags, 0x07777 },
Szymon Janc78aea4f2010-11-27 08:39:43 +0000720 { 0, 0 }
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400721};
722
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500723struct nv_skb_map {
724 struct sk_buff *skb;
725 dma_addr_t dma;
Eric Dumazet73a37072009-06-17 21:17:59 +0000726 unsigned int dma_len:31;
727 unsigned int dma_single:1;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -0500728 struct ring_desc_ex *first_tx_desc;
729 struct nv_skb_map *next_tx_ctx;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500730};
731
Linus Torvalds1da177e2005-04-16 15:20:36 -0700732/*
733 * SMP locking:
Wang Chenb74ca3a2008-12-08 01:14:16 -0800734 * All hardware access under netdev_priv(dev)->lock, except the performance
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 * critical parts:
736 * - rx is (pseudo-) lockless: it relies on the single-threading provided
737 * by the arch code for interrupts.
Herbert Xu932ff272006-06-09 12:20:56 -0700738 * - tx setup is lockless: it relies on netif_tx_lock. Actual submission
Wang Chenb74ca3a2008-12-08 01:14:16 -0800739 * needs netdev_priv(dev)->lock :-(
Herbert Xu932ff272006-06-09 12:20:56 -0700740 * - set_multicast_list: preparation lockless, relies on netif_tx_lock.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 */
742
743/* in dev: base, irq */
744struct fe_priv {
745 spinlock_t lock;
746
Stephen Hemmingerbea33482007-10-03 16:41:36 -0700747 struct net_device *dev;
748 struct napi_struct napi;
749
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750 /* General data:
751 * Locking: spin_lock(&np->lock); */
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400752 struct nv_ethtool_stats estats;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753 int in_shutdown;
754 u32 linkspeed;
755 int duplex;
756 int autoneg;
757 int fixed_mode;
758 int phyaddr;
759 int wolenabled;
760 unsigned int phy_oui;
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -0400761 unsigned int phy_model;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400762 unsigned int phy_rev;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763 u16 gigabit;
Ayaz Abdulla9589c772006-06-10 22:48:13 -0400764 int intr_test;
Ayaz Abdullac5cf9102006-10-30 17:32:01 -0500765 int recover_error;
Ayaz Abdulla4145ade2009-03-05 08:02:26 +0000766 int quiet_count;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700767
768 /* General data: RO fields */
769 dma_addr_t ring_addr;
770 struct pci_dev *pci_dev;
771 u32 orig_mac[2];
Ayaz Abdulla582806b2009-03-05 08:02:03 +0000772 u32 events;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700773 u32 irqmask;
774 u32 desc_ver;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -0400775 u32 txrxctl_bits;
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500776 u32 vlanctl_bits;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400777 u32 driver_data;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400778 u32 device_id;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -0400779 u32 register_size;
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -0400780 int rx_csum;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -0500781 u32 mac_in_use;
Ayaz Abdullacac1c522009-02-07 00:23:57 -0800782 int mgmt_version;
783 int mgmt_sema;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
785 void __iomem *base;
786
787 /* rx specific fields.
788 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
789 */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500790 union ring_type get_rx, put_rx, first_rx, last_rx;
791 struct nv_skb_map *get_rx_ctx, *put_rx_ctx;
792 struct nv_skb_map *first_rx_ctx, *last_rx_ctx;
793 struct nv_skb_map *rx_skb;
794
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700795 union ring_type rx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700796 unsigned int rx_buf_sz;
Manfred Sprauld81c0982005-07-31 18:20:30 +0200797 unsigned int pkt_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 struct timer_list oom_kick;
799 struct timer_list nic_poll;
Ayaz Abdulla52da3572006-06-10 22:48:04 -0400800 struct timer_list stats_poll;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500801 u32 nic_poll_irq;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400802 int rx_ring_size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700803
804 /* media detection workaround.
805 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
806 */
807 int need_linktimer;
808 unsigned long link_timeout;
809 /*
810 * tx specific fields.
811 */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -0500812 union ring_type get_tx, put_tx, first_tx, last_tx;
813 struct nv_skb_map *get_tx_ctx, *put_tx_ctx;
814 struct nv_skb_map *first_tx_ctx, *last_tx_ctx;
815 struct nv_skb_map *tx_skb;
816
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700817 union ring_type tx_ring;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700818 u32 tx_flags;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -0400819 int tx_ring_size;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -0500820 int tx_limit;
821 u32 tx_pkts_in_progress;
822 struct nv_skb_map *tx_change_owner;
823 struct nv_skb_map *tx_end_flip;
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -0500824 int tx_stop;
Ayaz Abdullaee407b02006-02-04 13:13:17 -0500825
826 /* vlan fields */
827 struct vlan_group *vlangrp;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500828
829 /* msi/msi-x fields */
830 u32 msi_flags;
831 struct msix_entry msi_x_entry[NV_MSI_X_MAX_VECTORS];
Ayaz Abdullaeb91f612006-05-24 18:13:19 -0400832
833 /* flow control */
834 u32 pause_flags;
Tobias Diedrich1a1ca862008-05-18 15:03:44 +0200835
836 /* power saved state */
837 u32 saved_config_space[NV_PCI_REGSZ_MAX/4];
Yinghai Luddb213f2009-02-06 01:29:23 -0800838
839 /* for different msi-x irq type */
840 char name_rx[IFNAMSIZ + 3]; /* -rx */
841 char name_tx[IFNAMSIZ + 3]; /* -tx */
842 char name_other[IFNAMSIZ + 6]; /* -other */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843};
844
845/*
846 * Maximum number of loops until we assume that a bit in the irq mask
847 * is stuck. Overridable with module param.
848 */
Ayaz Abdulla4145ade2009-03-05 08:02:26 +0000849static int max_interrupt_work = 4;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700850
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500851/*
852 * Optimization can be either throuput mode or cpu mode
Jeff Garzikf3b197a2006-05-26 21:39:03 -0400853 *
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500854 * Throughput Mode: Every tx and rx packet will generate an interrupt.
855 * CPU Mode: Interrupts are controlled by a timer.
856 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400857enum {
858 NV_OPTIMIZATION_MODE_THROUGHPUT,
Ayaz Abdulla9e184762009-03-05 08:02:18 +0000859 NV_OPTIMIZATION_MODE_CPU,
860 NV_OPTIMIZATION_MODE_DYNAMIC
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400861};
Ayaz Abdulla9e184762009-03-05 08:02:18 +0000862static int optimization_mode = NV_OPTIMIZATION_MODE_DYNAMIC;
Ayaz Abdullaa971c322005-11-11 08:30:38 -0500863
864/*
865 * Poll interval for timer irq
866 *
867 * This interval determines how frequent an interrupt is generated.
868 * The is value is determined by [(time_in_micro_secs * 100) / (2^10)]
869 * Min = 0, and Max = 65535
870 */
871static int poll_interval = -1;
872
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500873/*
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400874 * MSI interrupts
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500875 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400876enum {
877 NV_MSI_INT_DISABLED,
878 NV_MSI_INT_ENABLED
879};
880static int msi = NV_MSI_INT_ENABLED;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500881
882/*
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400883 * MSIX interrupts
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500884 */
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400885enum {
886 NV_MSIX_INT_DISABLED,
887 NV_MSIX_INT_ENABLED
888};
Yinghai Lu39482792009-02-06 01:31:12 -0800889static int msix = NV_MSIX_INT_ENABLED;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -0400890
891/*
892 * DMA 64bit
893 */
894enum {
895 NV_DMA_64BIT_DISABLED,
896 NV_DMA_64BIT_ENABLED
897};
898static int dma_64bit = NV_DMA_64BIT_ENABLED;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -0500899
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -0400900/*
901 * Crossover Detection
902 * Realtek 8201 phy + some OEM boards do not work properly.
903 */
904enum {
905 NV_CROSSOVER_DETECTION_DISABLED,
906 NV_CROSSOVER_DETECTION_ENABLED
907};
908static int phy_cross = NV_CROSSOVER_DETECTION_DISABLED;
909
Ed Swierk5a9a8e32009-06-02 00:19:52 -0700910/*
911 * Power down phy when interface is down (persists through reboot;
912 * older Linux and other OSes may not power it up again)
913 */
Szymon Janc78aea4f2010-11-27 08:39:43 +0000914static int phy_power_down;
Ed Swierk5a9a8e32009-06-02 00:19:52 -0700915
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916static inline struct fe_priv *get_nvpriv(struct net_device *dev)
917{
918 return netdev_priv(dev);
919}
920
921static inline u8 __iomem *get_hwbase(struct net_device *dev)
922{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -0400923 return ((struct fe_priv *)netdev_priv(dev))->base;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924}
925
926static inline void pci_push(u8 __iomem *base)
927{
928 /* force out pending posted writes */
929 readl(base);
930}
931
932static inline u32 nv_descr_getlength(struct ring_desc *prd, u32 v)
933{
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700934 return le32_to_cpu(prd->flaglen)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700935 & ((v == DESC_VER_1) ? LEN_MASK_V1 : LEN_MASK_V2);
936}
937
Manfred Spraulee733622005-07-31 18:32:26 +0200938static inline u32 nv_descr_getlength_ex(struct ring_desc_ex *prd, u32 v)
939{
Stephen Hemmingerf82a9352006-07-27 18:50:08 -0700940 return le32_to_cpu(prd->flaglen) & LEN_MASK_V2;
Manfred Spraulee733622005-07-31 18:32:26 +0200941}
942
Jeff Garzik36b30ea2007-10-16 01:40:30 -0400943static bool nv_optimized(struct fe_priv *np)
944{
945 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
946 return false;
947 return true;
948}
949
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950static int reg_delay(struct net_device *dev, int offset, u32 mask, u32 target,
951 int delay, int delaymax, const char *msg)
952{
953 u8 __iomem *base = get_hwbase(dev);
954
955 pci_push(base);
956 do {
957 udelay(delay);
958 delaymax -= delay;
959 if (delaymax < 0) {
960 if (msg)
Stephen Hemminger6a64cd62009-02-26 10:19:35 +0000961 printk("%s", msg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962 return 1;
963 }
964 } while ((readl(base + offset) & mask) != target);
965 return 0;
966}
967
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500968#define NV_SETUP_RX_RING 0x01
969#define NV_SETUP_TX_RING 0x02
970
Al Viro5bb7ea22007-12-09 16:06:41 +0000971static inline u32 dma_low(dma_addr_t addr)
972{
973 return addr;
974}
975
976static inline u32 dma_high(dma_addr_t addr)
977{
978 return addr>>31>>1; /* 0 if 32bit, shift down by 32 if 64bit */
979}
980
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500981static void setup_hw_rings(struct net_device *dev, int rxtx_flags)
982{
983 struct fe_priv *np = get_nvpriv(dev);
984 u8 __iomem *base = get_hwbase(dev);
985
Jeff Garzik36b30ea2007-10-16 01:40:30 -0400986 if (!nv_optimized(np)) {
Szymon Janc78aea4f2010-11-27 08:39:43 +0000987 if (rxtx_flags & NV_SETUP_RX_RING)
Al Viro5bb7ea22007-12-09 16:06:41 +0000988 writel(dma_low(np->ring_addr), base + NvRegRxRingPhysAddr);
Szymon Janc78aea4f2010-11-27 08:39:43 +0000989 if (rxtx_flags & NV_SETUP_TX_RING)
Al Viro5bb7ea22007-12-09 16:06:41 +0000990 writel(dma_low(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr);
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500991 } else {
992 if (rxtx_flags & NV_SETUP_RX_RING) {
Al Viro5bb7ea22007-12-09 16:06:41 +0000993 writel(dma_low(np->ring_addr), base + NvRegRxRingPhysAddr);
994 writel(dma_high(np->ring_addr), base + NvRegRxRingPhysAddrHigh);
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500995 }
996 if (rxtx_flags & NV_SETUP_TX_RING) {
Al Viro5bb7ea22007-12-09 16:06:41 +0000997 writel(dma_low(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr);
998 writel(dma_high(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddrHigh);
Ayaz Abdulla0832b252006-02-04 13:13:26 -0500999 }
1000 }
1001}
1002
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001003static void free_rings(struct net_device *dev)
1004{
1005 struct fe_priv *np = get_nvpriv(dev);
1006
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001007 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001008 if (np->rx_ring.orig)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001009 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
1010 np->rx_ring.orig, np->ring_addr);
1011 } else {
1012 if (np->rx_ring.ex)
1013 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
1014 np->rx_ring.ex, np->ring_addr);
1015 }
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001016 if (np->rx_skb)
1017 kfree(np->rx_skb);
1018 if (np->tx_skb)
1019 kfree(np->tx_skb);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001020}
1021
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001022static int using_multi_irqs(struct net_device *dev)
1023{
1024 struct fe_priv *np = get_nvpriv(dev);
1025
1026 if (!(np->msi_flags & NV_MSI_X_ENABLED) ||
1027 ((np->msi_flags & NV_MSI_X_ENABLED) &&
1028 ((np->msi_flags & NV_MSI_X_VECTORS_MASK) == 0x1)))
1029 return 0;
1030 else
1031 return 1;
1032}
1033
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00001034static void nv_txrx_gate(struct net_device *dev, bool gate)
1035{
1036 struct fe_priv *np = get_nvpriv(dev);
1037 u8 __iomem *base = get_hwbase(dev);
1038 u32 powerstate;
1039
1040 if (!np->mac_in_use &&
1041 (np->driver_data & DEV_HAS_POWER_CNTRL)) {
1042 powerstate = readl(base + NvRegPowerState2);
1043 if (gate)
1044 powerstate |= NVREG_POWERSTATE2_GATE_CLOCKS;
1045 else
1046 powerstate &= ~NVREG_POWERSTATE2_GATE_CLOCKS;
1047 writel(powerstate, base + NvRegPowerState2);
1048 }
1049}
1050
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001051static void nv_enable_irq(struct net_device *dev)
1052{
1053 struct fe_priv *np = get_nvpriv(dev);
1054
1055 if (!using_multi_irqs(dev)) {
1056 if (np->msi_flags & NV_MSI_X_ENABLED)
1057 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1058 else
Manfred Spraula7475902007-10-17 21:52:33 +02001059 enable_irq(np->pci_dev->irq);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001060 } else {
1061 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1062 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
1063 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
1064 }
1065}
1066
1067static void nv_disable_irq(struct net_device *dev)
1068{
1069 struct fe_priv *np = get_nvpriv(dev);
1070
1071 if (!using_multi_irqs(dev)) {
1072 if (np->msi_flags & NV_MSI_X_ENABLED)
1073 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1074 else
Manfred Spraula7475902007-10-17 21:52:33 +02001075 disable_irq(np->pci_dev->irq);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07001076 } else {
1077 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1078 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
1079 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
1080 }
1081}
1082
1083/* In MSIX mode, a write to irqmask behaves as XOR */
1084static void nv_enable_hw_interrupts(struct net_device *dev, u32 mask)
1085{
1086 u8 __iomem *base = get_hwbase(dev);
1087
1088 writel(mask, base + NvRegIrqMask);
1089}
1090
1091static void nv_disable_hw_interrupts(struct net_device *dev, u32 mask)
1092{
1093 struct fe_priv *np = get_nvpriv(dev);
1094 u8 __iomem *base = get_hwbase(dev);
1095
1096 if (np->msi_flags & NV_MSI_X_ENABLED) {
1097 writel(mask, base + NvRegIrqMask);
1098 } else {
1099 if (np->msi_flags & NV_MSI_ENABLED)
1100 writel(0, base + NvRegMSIIrqMask);
1101 writel(0, base + NvRegIrqMask);
1102 }
1103}
1104
Ayaz Abdulla08d93572009-03-05 08:01:55 +00001105static void nv_napi_enable(struct net_device *dev)
1106{
Ayaz Abdulla08d93572009-03-05 08:01:55 +00001107 struct fe_priv *np = get_nvpriv(dev);
1108
1109 napi_enable(&np->napi);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00001110}
1111
1112static void nv_napi_disable(struct net_device *dev)
1113{
Ayaz Abdulla08d93572009-03-05 08:01:55 +00001114 struct fe_priv *np = get_nvpriv(dev);
1115
1116 napi_disable(&np->napi);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00001117}
1118
Linus Torvalds1da177e2005-04-16 15:20:36 -07001119#define MII_READ (-1)
1120/* mii_rw: read/write a register on the PHY.
1121 *
1122 * Caller must guarantee serialization
1123 */
1124static int mii_rw(struct net_device *dev, int addr, int miireg, int value)
1125{
1126 u8 __iomem *base = get_hwbase(dev);
1127 u32 reg;
1128 int retval;
1129
Ayaz Abdullaeb798422008-02-04 15:14:04 -05001130 writel(NVREG_MIISTAT_MASK_RW, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001131
1132 reg = readl(base + NvRegMIIControl);
1133 if (reg & NVREG_MIICTL_INUSE) {
1134 writel(NVREG_MIICTL_INUSE, base + NvRegMIIControl);
1135 udelay(NV_MIIBUSY_DELAY);
1136 }
1137
1138 reg = (addr << NVREG_MIICTL_ADDRSHIFT) | miireg;
1139 if (value != MII_READ) {
1140 writel(value, base + NvRegMIIData);
1141 reg |= NVREG_MIICTL_WRITE;
1142 }
1143 writel(reg, base + NvRegMIIControl);
1144
1145 if (reg_delay(dev, NvRegMIIControl, NVREG_MIICTL_INUSE, 0,
1146 NV_MIIPHY_DELAY, NV_MIIPHY_DELAYMAX, NULL)) {
1147 dprintk(KERN_DEBUG "%s: mii_rw of reg %d at PHY %d timed out.\n",
1148 dev->name, miireg, addr);
1149 retval = -1;
1150 } else if (value != MII_READ) {
1151 /* it was a write operation - fewer failures are detectable */
1152 dprintk(KERN_DEBUG "%s: mii_rw wrote 0x%x to reg %d at PHY %d\n",
1153 dev->name, value, miireg, addr);
1154 retval = 0;
1155 } else if (readl(base + NvRegMIIStatus) & NVREG_MIISTAT_ERROR) {
1156 dprintk(KERN_DEBUG "%s: mii_rw of reg %d at PHY %d failed.\n",
1157 dev->name, miireg, addr);
1158 retval = -1;
1159 } else {
1160 retval = readl(base + NvRegMIIData);
1161 dprintk(KERN_DEBUG "%s: mii_rw read from reg %d at PHY %d: 0x%x.\n",
1162 dev->name, miireg, addr, retval);
1163 }
1164
1165 return retval;
1166}
1167
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001168static int phy_reset(struct net_device *dev, u32 bmcr_setup)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001169{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001170 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001171 u32 miicontrol;
1172 unsigned int tries = 0;
1173
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001174 miicontrol = BMCR_RESET | bmcr_setup;
Szymon Janc78aea4f2010-11-27 08:39:43 +00001175 if (mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176 return -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001177
1178 /* wait for 500ms */
1179 msleep(500);
1180
1181 /* must wait till reset is deasserted */
1182 while (miicontrol & BMCR_RESET) {
1183 msleep(10);
1184 miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1185 /* FIXME: 100 tries seem excessive */
1186 if (tries++ > 100)
1187 return -1;
1188 }
1189 return 0;
1190}
1191
1192static int phy_init(struct net_device *dev)
1193{
1194 struct fe_priv *np = get_nvpriv(dev);
1195 u8 __iomem *base = get_hwbase(dev);
Szymon Janc78aea4f2010-11-27 08:39:43 +00001196 u32 phyinterface, phy_reserved, mii_status, mii_control, mii_control_1000, reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001197
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001198 /* phy errata for E3016 phy */
1199 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
1200 reg = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
1201 reg &= ~PHY_MARVELL_E3016_INITMASK;
1202 if (mii_rw(dev, np->phyaddr, MII_NCONFIG, reg)) {
1203 printk(KERN_INFO "%s: phy write to errata reg failed.\n", pci_name(np->pci_dev));
1204 return PHY_ERROR;
1205 }
1206 }
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -04001207 if (np->phy_oui == PHY_OUI_REALTEK) {
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001208 if (np->phy_model == PHY_MODEL_REALTEK_8211 &&
1209 np->phy_rev == PHY_REV_REALTEK_8211B) {
1210 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1211 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1212 return PHY_ERROR;
1213 }
1214 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, PHY_REALTEK_INIT2)) {
1215 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1216 return PHY_ERROR;
1217 }
1218 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3)) {
1219 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1220 return PHY_ERROR;
1221 }
1222 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG3, PHY_REALTEK_INIT4)) {
1223 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1224 return PHY_ERROR;
1225 }
1226 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG4, PHY_REALTEK_INIT5)) {
1227 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1228 return PHY_ERROR;
1229 }
1230 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG5, PHY_REALTEK_INIT6)) {
1231 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1232 return PHY_ERROR;
1233 }
1234 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1235 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1236 return PHY_ERROR;
1237 }
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -04001238 }
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -04001239 if (np->phy_model == PHY_MODEL_REALTEK_8211 &&
1240 np->phy_rev == PHY_REV_REALTEK_8211C) {
1241 u32 powerstate = readl(base + NvRegPowerState2);
1242
1243 /* need to perform hw phy reset */
1244 powerstate |= NVREG_POWERSTATE2_PHY_RESET;
1245 writel(powerstate, base + NvRegPowerState2);
1246 msleep(25);
1247
1248 powerstate &= ~NVREG_POWERSTATE2_PHY_RESET;
1249 writel(powerstate, base + NvRegPowerState2);
1250 msleep(25);
1251
1252 reg = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, MII_READ);
1253 reg |= PHY_REALTEK_INIT9;
1254 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, reg)) {
1255 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1256 return PHY_ERROR;
1257 }
1258 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT10)) {
1259 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1260 return PHY_ERROR;
1261 }
1262 reg = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG7, MII_READ);
1263 if (!(reg & PHY_REALTEK_INIT11)) {
1264 reg |= PHY_REALTEK_INIT11;
1265 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG7, reg)) {
1266 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1267 return PHY_ERROR;
1268 }
1269 }
1270 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1271 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1272 return PHY_ERROR;
1273 }
1274 }
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001275 if (np->phy_model == PHY_MODEL_REALTEK_8201) {
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00001276 if (np->driver_data & DEV_NEED_PHY_INIT_FIX) {
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001277 phy_reserved = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, MII_READ);
1278 phy_reserved |= PHY_REALTEK_INIT7;
1279 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, phy_reserved)) {
1280 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1281 return PHY_ERROR;
1282 }
1283 }
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -04001284 }
1285 }
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001286
Linus Torvalds1da177e2005-04-16 15:20:36 -07001287 /* set advertise register */
1288 reg = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001289 reg |= (ADVERTISE_10HALF|ADVERTISE_10FULL|ADVERTISE_100HALF|ADVERTISE_100FULL|ADVERTISE_PAUSE_ASYM|ADVERTISE_PAUSE_CAP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001290 if (mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg)) {
1291 printk(KERN_INFO "%s: phy write to advertise failed.\n", pci_name(np->pci_dev));
1292 return PHY_ERROR;
1293 }
1294
1295 /* get phy interface type */
1296 phyinterface = readl(base + NvRegPhyInterface);
1297
1298 /* see if gigabit phy */
1299 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
1300 if (mii_status & PHY_GIGABIT) {
1301 np->gigabit = PHY_GIGABIT;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001302 mii_control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001303 mii_control_1000 &= ~ADVERTISE_1000HALF;
1304 if (phyinterface & PHY_RGMII)
1305 mii_control_1000 |= ADVERTISE_1000FULL;
1306 else
1307 mii_control_1000 &= ~ADVERTISE_1000FULL;
1308
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001309 if (mii_rw(dev, np->phyaddr, MII_CTRL1000, mii_control_1000)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001310 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1311 return PHY_ERROR;
1312 }
Szymon Janc78aea4f2010-11-27 08:39:43 +00001313 } else
Linus Torvalds1da177e2005-04-16 15:20:36 -07001314 np->gigabit = 0;
1315
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04001316 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1317 mii_control |= BMCR_ANENABLE;
1318
Ayaz Abdulla22ae03a2008-07-25 15:31:29 -04001319 if (np->phy_oui == PHY_OUI_REALTEK &&
1320 np->phy_model == PHY_MODEL_REALTEK_8211 &&
1321 np->phy_rev == PHY_REV_REALTEK_8211C) {
1322 /* start autoneg since we already performed hw reset above */
1323 mii_control |= BMCR_ANRESTART;
1324 if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control)) {
1325 printk(KERN_INFO "%s: phy init failed\n", pci_name(np->pci_dev));
1326 return PHY_ERROR;
1327 }
1328 } else {
1329 /* reset the phy
1330 * (certain phys need bmcr to be setup with reset)
1331 */
1332 if (phy_reset(dev, mii_control)) {
1333 printk(KERN_INFO "%s: phy reset failed\n", pci_name(np->pci_dev));
1334 return PHY_ERROR;
1335 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001336 }
1337
1338 /* phy vendor specific configuration */
Szymon Janc78aea4f2010-11-27 08:39:43 +00001339 if ((np->phy_oui == PHY_OUI_CICADA) && (phyinterface & PHY_RGMII)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001340 phy_reserved = mii_rw(dev, np->phyaddr, MII_RESV1, MII_READ);
Ayaz Abdulla14a67f32007-07-15 06:50:28 -04001341 phy_reserved &= ~(PHY_CICADA_INIT1 | PHY_CICADA_INIT2);
1342 phy_reserved |= (PHY_CICADA_INIT3 | PHY_CICADA_INIT4);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001343 if (mii_rw(dev, np->phyaddr, MII_RESV1, phy_reserved)) {
1344 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1345 return PHY_ERROR;
1346 }
1347 phy_reserved = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
Ayaz Abdulla14a67f32007-07-15 06:50:28 -04001348 phy_reserved |= PHY_CICADA_INIT5;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001349 if (mii_rw(dev, np->phyaddr, MII_NCONFIG, phy_reserved)) {
1350 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1351 return PHY_ERROR;
1352 }
1353 }
1354 if (np->phy_oui == PHY_OUI_CICADA) {
1355 phy_reserved = mii_rw(dev, np->phyaddr, MII_SREVISION, MII_READ);
Ayaz Abdulla14a67f32007-07-15 06:50:28 -04001356 phy_reserved |= PHY_CICADA_INIT6;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357 if (mii_rw(dev, np->phyaddr, MII_SREVISION, phy_reserved)) {
1358 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1359 return PHY_ERROR;
1360 }
1361 }
Ayaz Abdullad215d8a2007-07-15 06:50:53 -04001362 if (np->phy_oui == PHY_OUI_VITESSE) {
1363 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG1, PHY_VITESSE_INIT1)) {
1364 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1365 return PHY_ERROR;
1366 }
1367 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT2)) {
1368 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1369 return PHY_ERROR;
1370 }
1371 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, MII_READ);
1372 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved)) {
1373 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1374 return PHY_ERROR;
1375 }
1376 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, MII_READ);
1377 phy_reserved &= ~PHY_VITESSE_INIT_MSK1;
1378 phy_reserved |= PHY_VITESSE_INIT3;
1379 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved)) {
1380 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1381 return PHY_ERROR;
1382 }
1383 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT4)) {
1384 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1385 return PHY_ERROR;
1386 }
1387 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT5)) {
1388 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1389 return PHY_ERROR;
1390 }
1391 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, MII_READ);
1392 phy_reserved &= ~PHY_VITESSE_INIT_MSK1;
1393 phy_reserved |= PHY_VITESSE_INIT3;
1394 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved)) {
1395 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1396 return PHY_ERROR;
1397 }
1398 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, MII_READ);
1399 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved)) {
1400 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1401 return PHY_ERROR;
1402 }
1403 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT6)) {
1404 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1405 return PHY_ERROR;
1406 }
1407 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT7)) {
1408 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1409 return PHY_ERROR;
1410 }
1411 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, MII_READ);
1412 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved)) {
1413 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1414 return PHY_ERROR;
1415 }
1416 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, MII_READ);
1417 phy_reserved &= ~PHY_VITESSE_INIT_MSK2;
1418 phy_reserved |= PHY_VITESSE_INIT8;
1419 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved)) {
1420 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1421 return PHY_ERROR;
1422 }
1423 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT9)) {
1424 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1425 return PHY_ERROR;
1426 }
1427 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG1, PHY_VITESSE_INIT10)) {
1428 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1429 return PHY_ERROR;
1430 }
1431 }
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -04001432 if (np->phy_oui == PHY_OUI_REALTEK) {
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001433 if (np->phy_model == PHY_MODEL_REALTEK_8211 &&
1434 np->phy_rev == PHY_REV_REALTEK_8211B) {
1435 /* reset could have cleared these out, set them back */
1436 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1437 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1438 return PHY_ERROR;
1439 }
1440 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, PHY_REALTEK_INIT2)) {
1441 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1442 return PHY_ERROR;
1443 }
1444 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3)) {
1445 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1446 return PHY_ERROR;
1447 }
1448 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG3, PHY_REALTEK_INIT4)) {
1449 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1450 return PHY_ERROR;
1451 }
1452 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG4, PHY_REALTEK_INIT5)) {
1453 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1454 return PHY_ERROR;
1455 }
1456 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG5, PHY_REALTEK_INIT6)) {
1457 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1458 return PHY_ERROR;
1459 }
1460 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1461 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1462 return PHY_ERROR;
1463 }
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -04001464 }
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001465 if (np->phy_model == PHY_MODEL_REALTEK_8201) {
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00001466 if (np->driver_data & DEV_NEED_PHY_INIT_FIX) {
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04001467 phy_reserved = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, MII_READ);
1468 phy_reserved |= PHY_REALTEK_INIT7;
1469 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, phy_reserved)) {
1470 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1471 return PHY_ERROR;
1472 }
1473 }
1474 if (phy_cross == NV_CROSSOVER_DETECTION_DISABLED) {
1475 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3)) {
1476 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1477 return PHY_ERROR;
1478 }
1479 phy_reserved = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, MII_READ);
1480 phy_reserved &= ~PHY_REALTEK_INIT_MSK1;
1481 phy_reserved |= PHY_REALTEK_INIT3;
1482 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, phy_reserved)) {
1483 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1484 return PHY_ERROR;
1485 }
1486 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1487 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1488 return PHY_ERROR;
1489 }
1490 }
Ayaz Abdullac5e3ae82007-07-15 06:51:03 -04001491 }
1492 }
1493
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04001494 /* some phys clear out pause advertisment on reset, set it back */
1495 mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
Ed Swierkcb52deb2008-12-01 12:24:43 +00001497 /* restart auto negotiation, power down phy */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001498 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ed Swierk5a9a8e32009-06-02 00:19:52 -07001499 mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE);
Szymon Janc78aea4f2010-11-27 08:39:43 +00001500 if (phy_power_down)
Ed Swierk5a9a8e32009-06-02 00:19:52 -07001501 mii_control |= BMCR_PDOWN;
Szymon Janc78aea4f2010-11-27 08:39:43 +00001502 if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001503 return PHY_ERROR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001504
1505 return 0;
1506}
1507
1508static void nv_start_rx(struct net_device *dev)
1509{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001510 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001511 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001512 u32 rx_ctrl = readl(base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513
1514 dprintk(KERN_DEBUG "%s: nv_start_rx\n", dev->name);
1515 /* Already running? Stop it. */
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001516 if ((readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) && !np->mac_in_use) {
1517 rx_ctrl &= ~NVREG_RCVCTL_START;
1518 writel(rx_ctrl, base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519 pci_push(base);
1520 }
1521 writel(np->linkspeed, base + NvRegLinkSpeed);
1522 pci_push(base);
Szymon Janc78aea4f2010-11-27 08:39:43 +00001523 rx_ctrl |= NVREG_RCVCTL_START;
1524 if (np->mac_in_use)
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001525 rx_ctrl &= ~NVREG_RCVCTL_RX_PATH_EN;
1526 writel(rx_ctrl, base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527 dprintk(KERN_DEBUG "%s: nv_start_rx to duplex %d, speed 0x%08x.\n",
1528 dev->name, np->duplex, np->linkspeed);
1529 pci_push(base);
1530}
1531
1532static void nv_stop_rx(struct net_device *dev)
1533{
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001534 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001536 u32 rx_ctrl = readl(base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001537
1538 dprintk(KERN_DEBUG "%s: nv_stop_rx\n", dev->name);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001539 if (!np->mac_in_use)
1540 rx_ctrl &= ~NVREG_RCVCTL_START;
1541 else
1542 rx_ctrl |= NVREG_RCVCTL_RX_PATH_EN;
1543 writel(rx_ctrl, base + NvRegReceiverControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001544 reg_delay(dev, NvRegReceiverStatus, NVREG_RCVSTAT_BUSY, 0,
1545 NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX,
1546 KERN_INFO "nv_stop_rx: ReceiverStatus remained busy");
1547
1548 udelay(NV_RXSTOP_DELAY2);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001549 if (!np->mac_in_use)
1550 writel(0, base + NvRegLinkSpeed);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551}
1552
1553static void nv_start_tx(struct net_device *dev)
1554{
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001555 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001557 u32 tx_ctrl = readl(base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001558
1559 dprintk(KERN_DEBUG "%s: nv_start_tx\n", dev->name);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001560 tx_ctrl |= NVREG_XMITCTL_START;
1561 if (np->mac_in_use)
1562 tx_ctrl &= ~NVREG_XMITCTL_TX_PATH_EN;
1563 writel(tx_ctrl, base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564 pci_push(base);
1565}
1566
1567static void nv_stop_tx(struct net_device *dev)
1568{
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001569 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001570 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001571 u32 tx_ctrl = readl(base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572
1573 dprintk(KERN_DEBUG "%s: nv_stop_tx\n", dev->name);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001574 if (!np->mac_in_use)
1575 tx_ctrl &= ~NVREG_XMITCTL_START;
1576 else
1577 tx_ctrl |= NVREG_XMITCTL_TX_PATH_EN;
1578 writel(tx_ctrl, base + NvRegTransmitterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001579 reg_delay(dev, NvRegTransmitterStatus, NVREG_XMITSTAT_BUSY, 0,
1580 NV_TXSTOP_DELAY1, NV_TXSTOP_DELAY1MAX,
1581 KERN_INFO "nv_stop_tx: TransmitterStatus remained busy");
1582
1583 udelay(NV_TXSTOP_DELAY2);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05001584 if (!np->mac_in_use)
1585 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV,
1586 base + NvRegTransmitPoll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587}
1588
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001589static void nv_start_rxtx(struct net_device *dev)
1590{
1591 nv_start_rx(dev);
1592 nv_start_tx(dev);
1593}
1594
1595static void nv_stop_rxtx(struct net_device *dev)
1596{
1597 nv_stop_rx(dev);
1598 nv_stop_tx(dev);
1599}
1600
Linus Torvalds1da177e2005-04-16 15:20:36 -07001601static void nv_txrx_reset(struct net_device *dev)
1602{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001603 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604 u8 __iomem *base = get_hwbase(dev);
1605
1606 dprintk(KERN_DEBUG "%s: nv_txrx_reset\n", dev->name);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001607 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001608 pci_push(base);
1609 udelay(NV_TXRX_RESET_DELAY);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04001610 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 pci_push(base);
1612}
1613
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001614static void nv_mac_reset(struct net_device *dev)
1615{
1616 struct fe_priv *np = netdev_priv(dev);
1617 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdulla4e84f9b2008-02-04 15:14:09 -05001618 u32 temp1, temp2, temp3;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001619
1620 dprintk(KERN_DEBUG "%s: nv_mac_reset\n", dev->name);
Ayaz Abdulla4e84f9b2008-02-04 15:14:09 -05001621
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001622 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
1623 pci_push(base);
Ayaz Abdulla4e84f9b2008-02-04 15:14:09 -05001624
1625 /* save registers since they will be cleared on reset */
1626 temp1 = readl(base + NvRegMacAddrA);
1627 temp2 = readl(base + NvRegMacAddrB);
1628 temp3 = readl(base + NvRegTransmitPoll);
1629
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001630 writel(NVREG_MAC_RESET_ASSERT, base + NvRegMacReset);
1631 pci_push(base);
1632 udelay(NV_MAC_RESET_DELAY);
1633 writel(0, base + NvRegMacReset);
1634 pci_push(base);
1635 udelay(NV_MAC_RESET_DELAY);
Ayaz Abdulla4e84f9b2008-02-04 15:14:09 -05001636
1637 /* restore saved registers */
1638 writel(temp1, base + NvRegMacAddrA);
1639 writel(temp2, base + NvRegMacAddrB);
1640 writel(temp3, base + NvRegTransmitPoll);
1641
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04001642 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
1643 pci_push(base);
1644}
1645
Ayaz Abdulla57fff692007-01-23 12:27:00 -05001646static void nv_get_hw_stats(struct net_device *dev)
1647{
1648 struct fe_priv *np = netdev_priv(dev);
1649 u8 __iomem *base = get_hwbase(dev);
1650
1651 np->estats.tx_bytes += readl(base + NvRegTxCnt);
1652 np->estats.tx_zero_rexmt += readl(base + NvRegTxZeroReXmt);
1653 np->estats.tx_one_rexmt += readl(base + NvRegTxOneReXmt);
1654 np->estats.tx_many_rexmt += readl(base + NvRegTxManyReXmt);
1655 np->estats.tx_late_collision += readl(base + NvRegTxLateCol);
1656 np->estats.tx_fifo_errors += readl(base + NvRegTxUnderflow);
1657 np->estats.tx_carrier_errors += readl(base + NvRegTxLossCarrier);
1658 np->estats.tx_excess_deferral += readl(base + NvRegTxExcessDef);
1659 np->estats.tx_retry_error += readl(base + NvRegTxRetryErr);
1660 np->estats.rx_frame_error += readl(base + NvRegRxFrameErr);
1661 np->estats.rx_extra_byte += readl(base + NvRegRxExtraByte);
1662 np->estats.rx_late_collision += readl(base + NvRegRxLateCol);
1663 np->estats.rx_runt += readl(base + NvRegRxRunt);
1664 np->estats.rx_frame_too_long += readl(base + NvRegRxFrameTooLong);
1665 np->estats.rx_over_errors += readl(base + NvRegRxOverflow);
1666 np->estats.rx_crc_errors += readl(base + NvRegRxFCSErr);
1667 np->estats.rx_frame_align_error += readl(base + NvRegRxFrameAlignErr);
1668 np->estats.rx_length_error += readl(base + NvRegRxLenErr);
1669 np->estats.rx_unicast += readl(base + NvRegRxUnicast);
1670 np->estats.rx_multicast += readl(base + NvRegRxMulticast);
1671 np->estats.rx_broadcast += readl(base + NvRegRxBroadcast);
1672 np->estats.rx_packets =
1673 np->estats.rx_unicast +
1674 np->estats.rx_multicast +
1675 np->estats.rx_broadcast;
1676 np->estats.rx_errors_total =
1677 np->estats.rx_crc_errors +
1678 np->estats.rx_over_errors +
1679 np->estats.rx_frame_error +
1680 (np->estats.rx_frame_align_error - np->estats.rx_extra_byte) +
1681 np->estats.rx_late_collision +
1682 np->estats.rx_runt +
1683 np->estats.rx_frame_too_long;
1684 np->estats.tx_errors_total =
1685 np->estats.tx_late_collision +
1686 np->estats.tx_fifo_errors +
1687 np->estats.tx_carrier_errors +
1688 np->estats.tx_excess_deferral +
1689 np->estats.tx_retry_error;
1690
1691 if (np->driver_data & DEV_HAS_STATISTICS_V2) {
1692 np->estats.tx_deferral += readl(base + NvRegTxDef);
1693 np->estats.tx_packets += readl(base + NvRegTxFrame);
1694 np->estats.rx_bytes += readl(base + NvRegRxCnt);
1695 np->estats.tx_pause += readl(base + NvRegTxPause);
1696 np->estats.rx_pause += readl(base + NvRegRxPause);
1697 np->estats.rx_drop_frame += readl(base + NvRegRxDropFrame);
1698 }
Ayaz Abdulla9c662432008-08-06 12:11:42 -04001699
1700 if (np->driver_data & DEV_HAS_STATISTICS_V3) {
1701 np->estats.tx_unicast += readl(base + NvRegTxUnicast);
1702 np->estats.tx_multicast += readl(base + NvRegTxMulticast);
1703 np->estats.tx_broadcast += readl(base + NvRegTxBroadcast);
1704 }
Ayaz Abdulla57fff692007-01-23 12:27:00 -05001705}
1706
Linus Torvalds1da177e2005-04-16 15:20:36 -07001707/*
1708 * nv_get_stats: dev->get_stats function
1709 * Get latest stats value from the nic.
1710 * Called with read_lock(&dev_base_lock) held for read -
1711 * only synchronized against unregister_netdevice.
1712 */
1713static struct net_device_stats *nv_get_stats(struct net_device *dev)
1714{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001715 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001716
Ayaz Abdulla21828162007-01-23 12:27:21 -05001717 /* If the nic supports hw counters then retrieve latest values */
Ayaz Abdulla9c662432008-08-06 12:11:42 -04001718 if (np->driver_data & (DEV_HAS_STATISTICS_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_STATISTICS_V3)) {
Ayaz Abdulla21828162007-01-23 12:27:21 -05001719 nv_get_hw_stats(dev);
1720
1721 /* copy to net_device stats */
Jeff Garzik8148ff42007-10-16 20:56:09 -04001722 dev->stats.tx_bytes = np->estats.tx_bytes;
1723 dev->stats.tx_fifo_errors = np->estats.tx_fifo_errors;
1724 dev->stats.tx_carrier_errors = np->estats.tx_carrier_errors;
1725 dev->stats.rx_crc_errors = np->estats.rx_crc_errors;
1726 dev->stats.rx_over_errors = np->estats.rx_over_errors;
1727 dev->stats.rx_errors = np->estats.rx_errors_total;
1728 dev->stats.tx_errors = np->estats.tx_errors_total;
Ayaz Abdulla21828162007-01-23 12:27:21 -05001729 }
Jeff Garzik8148ff42007-10-16 20:56:09 -04001730
1731 return &dev->stats;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001732}
1733
1734/*
1735 * nv_alloc_rx: fill rx ring entries.
1736 * Return 1 if the allocations for the skbs failed and the
1737 * rx engine is without Available descriptors
1738 */
1739static int nv_alloc_rx(struct net_device *dev)
1740{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001741 struct fe_priv *np = netdev_priv(dev);
Szymon Janc78aea4f2010-11-27 08:39:43 +00001742 struct ring_desc *less_rx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001743
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001744 less_rx = np->get_rx.orig;
1745 if (less_rx-- == np->first_rx.orig)
1746 less_rx = np->last_rx.orig;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001747
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001748 while (np->put_rx.orig != less_rx) {
1749 struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001750 if (skb) {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001751 np->put_rx_ctx->skb = skb;
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001752 np->put_rx_ctx->dma = pci_map_single(np->pci_dev,
1753 skb->data,
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001754 skb_tailroom(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001755 PCI_DMA_FROMDEVICE);
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001756 np->put_rx_ctx->dma_len = skb_tailroom(skb);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001757 np->put_rx.orig->buf = cpu_to_le32(np->put_rx_ctx->dma);
1758 wmb();
1759 np->put_rx.orig->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX_AVAIL);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001760 if (unlikely(np->put_rx.orig++ == np->last_rx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001761 np->put_rx.orig = np->first_rx.orig;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001762 if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001763 np->put_rx_ctx = np->first_rx_ctx;
Szymon Janc78aea4f2010-11-27 08:39:43 +00001764 } else
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001765 return 1;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001766 }
1767 return 0;
1768}
1769
1770static int nv_alloc_rx_optimized(struct net_device *dev)
1771{
1772 struct fe_priv *np = netdev_priv(dev);
Szymon Janc78aea4f2010-11-27 08:39:43 +00001773 struct ring_desc_ex *less_rx;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001774
1775 less_rx = np->get_rx.ex;
1776 if (less_rx-- == np->first_rx.ex)
1777 less_rx = np->last_rx.ex;
1778
1779 while (np->put_rx.ex != less_rx) {
1780 struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD);
1781 if (skb) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001782 np->put_rx_ctx->skb = skb;
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001783 np->put_rx_ctx->dma = pci_map_single(np->pci_dev,
1784 skb->data,
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001785 skb_tailroom(skb),
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001786 PCI_DMA_FROMDEVICE);
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03001787 np->put_rx_ctx->dma_len = skb_tailroom(skb);
Al Viro5bb7ea22007-12-09 16:06:41 +00001788 np->put_rx.ex->bufhigh = cpu_to_le32(dma_high(np->put_rx_ctx->dma));
1789 np->put_rx.ex->buflow = cpu_to_le32(dma_low(np->put_rx_ctx->dma));
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001790 wmb();
1791 np->put_rx.ex->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX2_AVAIL);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001792 if (unlikely(np->put_rx.ex++ == np->last_rx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001793 np->put_rx.ex = np->first_rx.ex;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05001794 if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001795 np->put_rx_ctx = np->first_rx_ctx;
Szymon Janc78aea4f2010-11-27 08:39:43 +00001796 } else
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05001797 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001798 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001799 return 0;
1800}
1801
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001802/* If rx bufs are exhausted called after 50ms to attempt to refresh */
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001803static void nv_do_rx_refill(unsigned long data)
1804{
1805 struct net_device *dev = (struct net_device *) data;
Stephen Hemmingerbea33482007-10-03 16:41:36 -07001806 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001807
1808 /* Just reschedule NAPI rx processing */
Ben Hutchings288379f2009-01-19 16:43:59 -08001809 napi_schedule(&np->napi);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07001810}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001811
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001812static void nv_init_rx(struct net_device *dev)
Manfred Sprauld81c0982005-07-31 18:20:30 +02001813{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001814 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02001815 int i;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001816
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001817 np->get_rx = np->put_rx = np->first_rx = np->rx_ring;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001818
1819 if (!nv_optimized(np))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001820 np->last_rx.orig = &np->rx_ring.orig[np->rx_ring_size-1];
1821 else
1822 np->last_rx.ex = &np->rx_ring.ex[np->rx_ring_size-1];
1823 np->get_rx_ctx = np->put_rx_ctx = np->first_rx_ctx = np->rx_skb;
1824 np->last_rx_ctx = &np->rx_skb[np->rx_ring_size-1];
Manfred Sprauld81c0982005-07-31 18:20:30 +02001825
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001826 for (i = 0; i < np->rx_ring_size; i++) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001827 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001828 np->rx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001829 np->rx_ring.orig[i].buf = 0;
1830 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001831 np->rx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001832 np->rx_ring.ex[i].txvlan = 0;
1833 np->rx_ring.ex[i].bufhigh = 0;
1834 np->rx_ring.ex[i].buflow = 0;
1835 }
1836 np->rx_skb[i].skb = NULL;
1837 np->rx_skb[i].dma = 0;
1838 }
Manfred Sprauld81c0982005-07-31 18:20:30 +02001839}
1840
1841static void nv_init_tx(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001842{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001843 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001844 int i;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001845
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001846 np->get_tx = np->put_tx = np->first_tx = np->tx_ring;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001847
1848 if (!nv_optimized(np))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001849 np->last_tx.orig = &np->tx_ring.orig[np->tx_ring_size-1];
1850 else
1851 np->last_tx.ex = &np->tx_ring.ex[np->tx_ring_size-1];
1852 np->get_tx_ctx = np->put_tx_ctx = np->first_tx_ctx = np->tx_skb;
1853 np->last_tx_ctx = &np->tx_skb[np->tx_ring_size-1];
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001854 np->tx_pkts_in_progress = 0;
1855 np->tx_change_owner = NULL;
1856 np->tx_end_flip = NULL;
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00001857 np->tx_stop = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001858
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001859 for (i = 0; i < np->tx_ring_size; i++) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001860 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001861 np->tx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001862 np->tx_ring.orig[i].buf = 0;
1863 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001864 np->tx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001865 np->tx_ring.ex[i].txvlan = 0;
1866 np->tx_ring.ex[i].bufhigh = 0;
1867 np->tx_ring.ex[i].buflow = 0;
1868 }
1869 np->tx_skb[i].skb = NULL;
1870 np->tx_skb[i].dma = 0;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001871 np->tx_skb[i].dma_len = 0;
Eric Dumazet73a37072009-06-17 21:17:59 +00001872 np->tx_skb[i].dma_single = 0;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001873 np->tx_skb[i].first_tx_desc = NULL;
1874 np->tx_skb[i].next_tx_ctx = NULL;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001875 }
Manfred Sprauld81c0982005-07-31 18:20:30 +02001876}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001877
Manfred Sprauld81c0982005-07-31 18:20:30 +02001878static int nv_init_ring(struct net_device *dev)
1879{
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001880 struct fe_priv *np = netdev_priv(dev);
1881
Manfred Sprauld81c0982005-07-31 18:20:30 +02001882 nv_init_tx(dev);
1883 nv_init_rx(dev);
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001884
1885 if (!nv_optimized(np))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05001886 return nv_alloc_rx(dev);
1887 else
1888 return nv_alloc_rx_optimized(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001889}
1890
Eric Dumazet73a37072009-06-17 21:17:59 +00001891static void nv_unmap_txskb(struct fe_priv *np, struct nv_skb_map *tx_skb)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001892{
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001893 if (tx_skb->dma) {
Eric Dumazet73a37072009-06-17 21:17:59 +00001894 if (tx_skb->dma_single)
1895 pci_unmap_single(np->pci_dev, tx_skb->dma,
1896 tx_skb->dma_len,
1897 PCI_DMA_TODEVICE);
1898 else
1899 pci_unmap_page(np->pci_dev, tx_skb->dma,
1900 tx_skb->dma_len,
1901 PCI_DMA_TODEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001902 tx_skb->dma = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001903 }
Eric Dumazet73a37072009-06-17 21:17:59 +00001904}
1905
1906static int nv_release_txskb(struct fe_priv *np, struct nv_skb_map *tx_skb)
1907{
1908 nv_unmap_txskb(np, tx_skb);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001909 if (tx_skb->skb) {
1910 dev_kfree_skb_any(tx_skb->skb);
1911 tx_skb->skb = NULL;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001912 return 1;
Ayaz Abdullafa454592006-01-05 22:45:45 -08001913 }
Eric Dumazet73a37072009-06-17 21:17:59 +00001914 return 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001915}
1916
Linus Torvalds1da177e2005-04-16 15:20:36 -07001917static void nv_drain_tx(struct net_device *dev)
1918{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001919 struct fe_priv *np = netdev_priv(dev);
1920 unsigned int i;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04001921
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001922 for (i = 0; i < np->tx_ring_size; i++) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001923 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001924 np->tx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001925 np->tx_ring.orig[i].buf = 0;
1926 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001927 np->tx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001928 np->tx_ring.ex[i].txvlan = 0;
1929 np->tx_ring.ex[i].bufhigh = 0;
1930 np->tx_ring.ex[i].buflow = 0;
1931 }
Eric Dumazet73a37072009-06-17 21:17:59 +00001932 if (nv_release_txskb(np, &np->tx_skb[i]))
Jeff Garzik8148ff42007-10-16 20:56:09 -04001933 dev->stats.tx_dropped++;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001934 np->tx_skb[i].dma = 0;
1935 np->tx_skb[i].dma_len = 0;
Eric Dumazet73a37072009-06-17 21:17:59 +00001936 np->tx_skb[i].dma_single = 0;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001937 np->tx_skb[i].first_tx_desc = NULL;
1938 np->tx_skb[i].next_tx_ctx = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001939 }
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05001940 np->tx_pkts_in_progress = 0;
1941 np->tx_change_owner = NULL;
1942 np->tx_end_flip = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001943}
1944
1945static void nv_drain_rx(struct net_device *dev)
1946{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04001947 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001948 int i;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001949
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04001950 for (i = 0; i < np->rx_ring_size; i++) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001951 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001952 np->rx_ring.orig[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001953 np->rx_ring.orig[i].buf = 0;
1954 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07001955 np->rx_ring.ex[i].flaglen = 0;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001956 np->rx_ring.ex[i].txvlan = 0;
1957 np->rx_ring.ex[i].bufhigh = 0;
1958 np->rx_ring.ex[i].buflow = 0;
1959 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001960 wmb();
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001961 if (np->rx_skb[i].skb) {
1962 pci_unmap_single(np->pci_dev, np->rx_skb[i].dma,
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07001963 (skb_end_pointer(np->rx_skb[i].skb) -
1964 np->rx_skb[i].skb->data),
1965 PCI_DMA_FROMDEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001966 dev_kfree_skb(np->rx_skb[i].skb);
1967 np->rx_skb[i].skb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 }
1969 }
1970}
1971
Jeff Garzik36b30ea2007-10-16 01:40:30 -04001972static void nv_drain_rxtx(struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001973{
1974 nv_drain_tx(dev);
1975 nv_drain_rx(dev);
1976}
1977
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05001978static inline u32 nv_get_empty_tx_slots(struct fe_priv *np)
1979{
1980 return (u32)(np->tx_ring_size - ((np->tx_ring_size + (np->put_tx_ctx - np->get_tx_ctx)) % np->tx_ring_size));
1981}
1982
Ayaz Abdullaa4336862008-04-18 13:50:43 -07001983static void nv_legacybackoff_reseed(struct net_device *dev)
1984{
1985 u8 __iomem *base = get_hwbase(dev);
1986 u32 reg;
1987 u32 low;
1988 int tx_status = 0;
1989
1990 reg = readl(base + NvRegSlotTime) & ~NVREG_SLOTTIME_MASK;
1991 get_random_bytes(&low, sizeof(low));
1992 reg |= low & NVREG_SLOTTIME_MASK;
1993
1994 /* Need to stop tx before change takes effect.
1995 * Caller has already gained np->lock.
1996 */
1997 tx_status = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_START;
1998 if (tx_status)
1999 nv_stop_tx(dev);
2000 nv_stop_rx(dev);
2001 writel(reg, base + NvRegSlotTime);
2002 if (tx_status)
2003 nv_start_tx(dev);
2004 nv_start_rx(dev);
2005}
2006
2007/* Gear Backoff Seeds */
2008#define BACKOFF_SEEDSET_ROWS 8
2009#define BACKOFF_SEEDSET_LFSRS 15
2010
2011/* Known Good seed sets */
2012static const u32 main_seedset[BACKOFF_SEEDSET_ROWS][BACKOFF_SEEDSET_LFSRS] = {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002013 {145, 155, 165, 175, 185, 196, 235, 245, 255, 265, 275, 285, 660, 690, 874},
2014 {245, 255, 265, 575, 385, 298, 335, 345, 355, 366, 375, 385, 761, 790, 974},
2015 {145, 155, 165, 175, 185, 196, 235, 245, 255, 265, 275, 285, 660, 690, 874},
2016 {245, 255, 265, 575, 385, 298, 335, 345, 355, 366, 375, 386, 761, 790, 974},
2017 {266, 265, 276, 585, 397, 208, 345, 355, 365, 376, 385, 396, 771, 700, 984},
2018 {266, 265, 276, 586, 397, 208, 346, 355, 365, 376, 285, 396, 771, 700, 984},
2019 {366, 365, 376, 686, 497, 308, 447, 455, 466, 476, 485, 496, 871, 800, 84},
2020 {466, 465, 476, 786, 597, 408, 547, 555, 566, 576, 585, 597, 971, 900, 184} };
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002021
2022static const u32 gear_seedset[BACKOFF_SEEDSET_ROWS][BACKOFF_SEEDSET_LFSRS] = {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002023 {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
2024 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
2025 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 397},
2026 {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
2027 {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
2028 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
2029 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
2030 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395} };
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002031
2032static void nv_gear_backoff_reseed(struct net_device *dev)
2033{
2034 u8 __iomem *base = get_hwbase(dev);
2035 u32 miniseed1, miniseed2, miniseed2_reversed, miniseed3, miniseed3_reversed;
2036 u32 temp, seedset, combinedSeed;
2037 int i;
2038
2039 /* Setup seed for free running LFSR */
2040 /* We are going to read the time stamp counter 3 times
2041 and swizzle bits around to increase randomness */
2042 get_random_bytes(&miniseed1, sizeof(miniseed1));
2043 miniseed1 &= 0x0fff;
2044 if (miniseed1 == 0)
2045 miniseed1 = 0xabc;
2046
2047 get_random_bytes(&miniseed2, sizeof(miniseed2));
2048 miniseed2 &= 0x0fff;
2049 if (miniseed2 == 0)
2050 miniseed2 = 0xabc;
2051 miniseed2_reversed =
2052 ((miniseed2 & 0xF00) >> 8) |
2053 (miniseed2 & 0x0F0) |
2054 ((miniseed2 & 0x00F) << 8);
2055
2056 get_random_bytes(&miniseed3, sizeof(miniseed3));
2057 miniseed3 &= 0x0fff;
2058 if (miniseed3 == 0)
2059 miniseed3 = 0xabc;
2060 miniseed3_reversed =
2061 ((miniseed3 & 0xF00) >> 8) |
2062 (miniseed3 & 0x0F0) |
2063 ((miniseed3 & 0x00F) << 8);
2064
2065 combinedSeed = ((miniseed1 ^ miniseed2_reversed) << 12) |
2066 (miniseed2 ^ miniseed3_reversed);
2067
2068 /* Seeds can not be zero */
2069 if ((combinedSeed & NVREG_BKOFFCTRL_SEED_MASK) == 0)
2070 combinedSeed |= 0x08;
2071 if ((combinedSeed & (NVREG_BKOFFCTRL_SEED_MASK << NVREG_BKOFFCTRL_GEAR)) == 0)
2072 combinedSeed |= 0x8000;
2073
2074 /* No need to disable tx here */
2075 temp = NVREG_BKOFFCTRL_DEFAULT | (0 << NVREG_BKOFFCTRL_SELECT);
2076 temp |= combinedSeed & NVREG_BKOFFCTRL_SEED_MASK;
2077 temp |= combinedSeed >> NVREG_BKOFFCTRL_GEAR;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002078 writel(temp, base + NvRegBackOffControl);
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002079
Szymon Janc78aea4f2010-11-27 08:39:43 +00002080 /* Setup seeds for all gear LFSRs. */
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002081 get_random_bytes(&seedset, sizeof(seedset));
2082 seedset = seedset % BACKOFF_SEEDSET_ROWS;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002083 for (i = 1; i <= BACKOFF_SEEDSET_LFSRS; i++) {
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002084 temp = NVREG_BKOFFCTRL_DEFAULT | (i << NVREG_BKOFFCTRL_SELECT);
2085 temp |= main_seedset[seedset][i-1] & 0x3ff;
2086 temp |= ((gear_seedset[seedset][i-1] & 0x3ff) << NVREG_BKOFFCTRL_GEAR);
2087 writel(temp, base + NvRegBackOffControl);
2088 }
2089}
2090
Linus Torvalds1da177e2005-04-16 15:20:36 -07002091/*
2092 * nv_start_xmit: dev->hard_start_xmit function
Herbert Xu932ff272006-06-09 12:20:56 -07002093 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002094 */
Stephen Hemminger613573252009-08-31 19:50:58 +00002095static netdev_tx_t nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002096{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002097 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002098 u32 tx_flags = 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002099 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
2100 unsigned int fragments = skb_shinfo(skb)->nr_frags;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002101 unsigned int i;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002102 u32 offset = 0;
2103 u32 bcnt;
Eric Dumazete743d312010-04-14 15:59:40 -07002104 u32 size = skb_headlen(skb);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002105 u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002106 u32 empty_slots;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002107 struct ring_desc *put_tx;
2108 struct ring_desc *start_tx;
2109 struct ring_desc *prev_tx;
2110 struct nv_skb_map *prev_tx_ctx;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002111 unsigned long flags;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002112
2113 /* add fragments to entries count */
2114 for (i = 0; i < fragments; i++) {
2115 entries += (skb_shinfo(skb)->frags[i].size >> NV_TX2_TSO_MAX_SHIFT) +
2116 ((skb_shinfo(skb)->frags[i].size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
2117 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002118
Ayaz Abdulla001eb842009-01-09 11:03:44 +00002119 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002120 empty_slots = nv_get_empty_tx_slots(np);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002121 if (unlikely(empty_slots <= entries)) {
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002122 netif_stop_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002123 np->tx_stop = 1;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002124 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002125 return NETDEV_TX_BUSY;
2126 }
Ayaz Abdulla001eb842009-01-09 11:03:44 +00002127 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002128
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002129 start_tx = put_tx = np->put_tx.orig;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002130
Ayaz Abdullafa454592006-01-05 22:45:45 -08002131 /* setup the header buffer */
2132 do {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002133 prev_tx = put_tx;
2134 prev_tx_ctx = np->put_tx_ctx;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002135 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002136 np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
Ayaz Abdullafa454592006-01-05 22:45:45 -08002137 PCI_DMA_TODEVICE);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002138 np->put_tx_ctx->dma_len = bcnt;
Eric Dumazet73a37072009-06-17 21:17:59 +00002139 np->put_tx_ctx->dma_single = 1;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002140 put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
2141 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002142
Ayaz Abdullafa454592006-01-05 22:45:45 -08002143 tx_flags = np->tx_flags;
2144 offset += bcnt;
2145 size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002146 if (unlikely(put_tx++ == np->last_tx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002147 put_tx = np->first_tx.orig;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002148 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002149 np->put_tx_ctx = np->first_tx_ctx;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002150 } while (size);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002151
2152 /* setup the fragments */
2153 for (i = 0; i < fragments; i++) {
2154 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
2155 u32 size = frag->size;
2156 offset = 0;
2157
2158 do {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002159 prev_tx = put_tx;
2160 prev_tx_ctx = np->put_tx_ctx;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002161 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002162 np->put_tx_ctx->dma = pci_map_page(np->pci_dev, frag->page, frag->page_offset+offset, bcnt,
2163 PCI_DMA_TODEVICE);
2164 np->put_tx_ctx->dma_len = bcnt;
Eric Dumazet73a37072009-06-17 21:17:59 +00002165 np->put_tx_ctx->dma_single = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002166 put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
2167 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002168
Ayaz Abdullafa454592006-01-05 22:45:45 -08002169 offset += bcnt;
2170 size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002171 if (unlikely(put_tx++ == np->last_tx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002172 put_tx = np->first_tx.orig;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002173 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002174 np->put_tx_ctx = np->first_tx_ctx;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002175 } while (size);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002176 }
2177
Ayaz Abdullafa454592006-01-05 22:45:45 -08002178 /* set last fragment flag */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002179 prev_tx->flaglen |= cpu_to_le32(tx_flags_extra);
Ayaz Abdullafa454592006-01-05 22:45:45 -08002180
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002181 /* save skb in this slot's context area */
2182 prev_tx_ctx->skb = skb;
Ayaz Abdullafa454592006-01-05 22:45:45 -08002183
Herbert Xu89114af2006-07-08 13:34:32 -07002184 if (skb_is_gso(skb))
Herbert Xu79671682006-06-22 02:40:14 -07002185 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
Manfred Spraulee733622005-07-31 18:32:26 +02002186 else
Arjan van de Ven1d39ed52006-12-12 14:06:23 +01002187 tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
Patrick McHardy84fa7932006-08-29 16:44:56 -07002188 NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002189
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002190 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla164a86e2007-01-09 13:30:10 -05002191
Ayaz Abdullafa454592006-01-05 22:45:45 -08002192 /* set tx flags */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002193 start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
2194 np->put_tx.orig = put_tx;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002195
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002196 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002197
2198 dprintk(KERN_DEBUG "%s: nv_start_xmit: entries %d queued for transmission. tx_flags_extra: %x\n",
2199 dev->name, entries, tx_flags_extra);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 {
2201 int j;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002202 for (j = 0; j < 64; j++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002203 if ((j%16) == 0)
2204 dprintk("\n%03x:", j);
Szymon Janc78aea4f2010-11-27 08:39:43 +00002205 dprintk(" %02x", ((unsigned char *)skb->data)[j]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002206 }
2207 dprintk("\n");
2208 }
2209
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002210 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002211 return NETDEV_TX_OK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002212}
2213
Stephen Hemminger613573252009-08-31 19:50:58 +00002214static netdev_tx_t nv_start_xmit_optimized(struct sk_buff *skb,
2215 struct net_device *dev)
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002216{
2217 struct fe_priv *np = netdev_priv(dev);
2218 u32 tx_flags = 0;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002219 u32 tx_flags_extra;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002220 unsigned int fragments = skb_shinfo(skb)->nr_frags;
2221 unsigned int i;
2222 u32 offset = 0;
2223 u32 bcnt;
Eric Dumazete743d312010-04-14 15:59:40 -07002224 u32 size = skb_headlen(skb);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002225 u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
2226 u32 empty_slots;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002227 struct ring_desc_ex *put_tx;
2228 struct ring_desc_ex *start_tx;
2229 struct ring_desc_ex *prev_tx;
2230 struct nv_skb_map *prev_tx_ctx;
2231 struct nv_skb_map *start_tx_ctx;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002232 unsigned long flags;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002233
2234 /* add fragments to entries count */
2235 for (i = 0; i < fragments; i++) {
2236 entries += (skb_shinfo(skb)->frags[i].size >> NV_TX2_TSO_MAX_SHIFT) +
2237 ((skb_shinfo(skb)->frags[i].size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
2238 }
2239
Ayaz Abdulla001eb842009-01-09 11:03:44 +00002240 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002241 empty_slots = nv_get_empty_tx_slots(np);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002242 if (unlikely(empty_slots <= entries)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002243 netif_stop_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002244 np->tx_stop = 1;
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002245 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002246 return NETDEV_TX_BUSY;
2247 }
Ayaz Abdulla001eb842009-01-09 11:03:44 +00002248 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002249
2250 start_tx = put_tx = np->put_tx.ex;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002251 start_tx_ctx = np->put_tx_ctx;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002252
2253 /* setup the header buffer */
2254 do {
2255 prev_tx = put_tx;
2256 prev_tx_ctx = np->put_tx_ctx;
2257 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
2258 np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
2259 PCI_DMA_TODEVICE);
2260 np->put_tx_ctx->dma_len = bcnt;
Eric Dumazet73a37072009-06-17 21:17:59 +00002261 np->put_tx_ctx->dma_single = 1;
Al Viro5bb7ea22007-12-09 16:06:41 +00002262 put_tx->bufhigh = cpu_to_le32(dma_high(np->put_tx_ctx->dma));
2263 put_tx->buflow = cpu_to_le32(dma_low(np->put_tx_ctx->dma));
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002264 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002265
2266 tx_flags = NV_TX2_VALID;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002267 offset += bcnt;
2268 size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002269 if (unlikely(put_tx++ == np->last_tx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002270 put_tx = np->first_tx.ex;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002271 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002272 np->put_tx_ctx = np->first_tx_ctx;
2273 } while (size);
2274
2275 /* setup the fragments */
2276 for (i = 0; i < fragments; i++) {
2277 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
2278 u32 size = frag->size;
2279 offset = 0;
2280
2281 do {
2282 prev_tx = put_tx;
2283 prev_tx_ctx = np->put_tx_ctx;
2284 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
2285 np->put_tx_ctx->dma = pci_map_page(np->pci_dev, frag->page, frag->page_offset+offset, bcnt,
2286 PCI_DMA_TODEVICE);
2287 np->put_tx_ctx->dma_len = bcnt;
Eric Dumazet73a37072009-06-17 21:17:59 +00002288 np->put_tx_ctx->dma_single = 0;
Al Viro5bb7ea22007-12-09 16:06:41 +00002289 put_tx->bufhigh = cpu_to_le32(dma_high(np->put_tx_ctx->dma));
2290 put_tx->buflow = cpu_to_le32(dma_low(np->put_tx_ctx->dma));
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002291 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002292
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002293 offset += bcnt;
2294 size -= bcnt;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002295 if (unlikely(put_tx++ == np->last_tx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002296 put_tx = np->first_tx.ex;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002297 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002298 np->put_tx_ctx = np->first_tx_ctx;
2299 } while (size);
2300 }
2301
2302 /* set last fragment flag */
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002303 prev_tx->flaglen |= cpu_to_le32(NV_TX2_LASTPACKET);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002304
2305 /* save skb in this slot's context area */
2306 prev_tx_ctx->skb = skb;
2307
2308 if (skb_is_gso(skb))
2309 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
2310 else
2311 tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
2312 NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
2313
2314 /* vlan tag */
Jesse Grosseab6d182010-10-20 13:56:03 +00002315 if (vlan_tx_tag_present(skb))
2316 start_tx->txvlan = cpu_to_le32(NV_TX3_VLAN_TAG_PRESENT |
2317 vlan_tx_tag_get(skb));
2318 else
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002319 start_tx->txvlan = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002320
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002321 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002322
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002323 if (np->tx_limit) {
2324 /* Limit the number of outstanding tx. Setup all fragments, but
2325 * do not set the VALID bit on the first descriptor. Save a pointer
2326 * to that descriptor and also for next skb_map element.
2327 */
2328
2329 if (np->tx_pkts_in_progress == NV_TX_LIMIT_COUNT) {
2330 if (!np->tx_change_owner)
2331 np->tx_change_owner = start_tx_ctx;
2332
2333 /* remove VALID bit */
2334 tx_flags &= ~NV_TX2_VALID;
2335 start_tx_ctx->first_tx_desc = start_tx;
2336 start_tx_ctx->next_tx_ctx = np->put_tx_ctx;
2337 np->tx_end_flip = np->put_tx_ctx;
2338 } else {
2339 np->tx_pkts_in_progress++;
2340 }
2341 }
2342
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002343 /* set tx flags */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002344 start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
2345 np->put_tx.ex = put_tx;
2346
Ingo Molnarbd6ca632008-03-28 14:41:30 -07002347 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002348
2349 dprintk(KERN_DEBUG "%s: nv_start_xmit_optimized: entries %d queued for transmission. tx_flags_extra: %x\n",
2350 dev->name, entries, tx_flags_extra);
2351 {
2352 int j;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002353 for (j = 0; j < 64; j++) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002354 if ((j%16) == 0)
2355 dprintk("\n%03x:", j);
Szymon Janc78aea4f2010-11-27 08:39:43 +00002356 dprintk(" %02x", ((unsigned char *)skb->data)[j]);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002357 }
2358 dprintk("\n");
2359 }
2360
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002361 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002362 return NETDEV_TX_OK;
2363}
2364
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002365static inline void nv_tx_flip_ownership(struct net_device *dev)
2366{
2367 struct fe_priv *np = netdev_priv(dev);
2368
2369 np->tx_pkts_in_progress--;
2370 if (np->tx_change_owner) {
Al Viro30ecce92008-03-26 05:57:12 +00002371 np->tx_change_owner->first_tx_desc->flaglen |=
2372 cpu_to_le32(NV_TX2_VALID);
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002373 np->tx_pkts_in_progress++;
2374
2375 np->tx_change_owner = np->tx_change_owner->next_tx_ctx;
2376 if (np->tx_change_owner == np->tx_end_flip)
2377 np->tx_change_owner = NULL;
2378
2379 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
2380 }
2381}
2382
Linus Torvalds1da177e2005-04-16 15:20:36 -07002383/*
2384 * nv_tx_done: check for completed packets, release the skbs.
2385 *
2386 * Caller must own np->lock.
2387 */
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002388static int nv_tx_done(struct net_device *dev, int limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002389{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002390 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002391 u32 flags;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002392 int tx_work = 0;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002393 struct ring_desc *orig_get_tx = np->get_tx.orig;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002394
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002395 while ((np->get_tx.orig != np->put_tx.orig) &&
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002396 !((flags = le32_to_cpu(np->get_tx.orig->flaglen)) & NV_TX_VALID) &&
2397 (tx_work < limit)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002398
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002399 dprintk(KERN_DEBUG "%s: nv_tx_done: flags 0x%x.\n",
2400 dev->name, flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002401
Eric Dumazet73a37072009-06-17 21:17:59 +00002402 nv_unmap_txskb(np, np->get_tx_ctx);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002403
Linus Torvalds1da177e2005-04-16 15:20:36 -07002404 if (np->desc_ver == DESC_VER_1) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002405 if (flags & NV_TX_LASTPACKET) {
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002406 if (flags & NV_TX_ERROR) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002407 if (flags & NV_TX_UNDERFLOW)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002408 dev->stats.tx_fifo_errors++;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002409 if (flags & NV_TX_CARRIERLOST)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002410 dev->stats.tx_carrier_errors++;
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002411 if ((flags & NV_TX_RETRYERROR) && !(flags & NV_TX_RETRYCOUNT_MASK))
2412 nv_legacybackoff_reseed(dev);
Jeff Garzik8148ff42007-10-16 20:56:09 -04002413 dev->stats.tx_errors++;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002414 } else {
Jeff Garzik8148ff42007-10-16 20:56:09 -04002415 dev->stats.tx_packets++;
2416 dev->stats.tx_bytes += np->get_tx_ctx->skb->len;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002417 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002418 dev_kfree_skb_any(np->get_tx_ctx->skb);
2419 np->get_tx_ctx->skb = NULL;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002420 tx_work++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002421 }
2422 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002423 if (flags & NV_TX2_LASTPACKET) {
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002424 if (flags & NV_TX2_ERROR) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002425 if (flags & NV_TX2_UNDERFLOW)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002426 dev->stats.tx_fifo_errors++;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002427 if (flags & NV_TX2_CARRIERLOST)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002428 dev->stats.tx_carrier_errors++;
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002429 if ((flags & NV_TX2_RETRYERROR) && !(flags & NV_TX2_RETRYCOUNT_MASK))
2430 nv_legacybackoff_reseed(dev);
Jeff Garzik8148ff42007-10-16 20:56:09 -04002431 dev->stats.tx_errors++;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002432 } else {
Jeff Garzik8148ff42007-10-16 20:56:09 -04002433 dev->stats.tx_packets++;
2434 dev->stats.tx_bytes += np->get_tx_ctx->skb->len;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002435 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002436 dev_kfree_skb_any(np->get_tx_ctx->skb);
2437 np->get_tx_ctx->skb = NULL;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002438 tx_work++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002439 }
2440 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002441 if (unlikely(np->get_tx.orig++ == np->last_tx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002442 np->get_tx.orig = np->first_tx.orig;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002443 if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002444 np->get_tx_ctx = np->first_tx_ctx;
2445 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002446 if (unlikely((np->tx_stop == 1) && (np->get_tx.orig != orig_get_tx))) {
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002447 np->tx_stop = 0;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002448 netif_wake_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002449 }
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002450 return tx_work;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002451}
2452
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002453static int nv_tx_done_optimized(struct net_device *dev, int limit)
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002454{
2455 struct fe_priv *np = netdev_priv(dev);
2456 u32 flags;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002457 int tx_work = 0;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002458 struct ring_desc_ex *orig_get_tx = np->get_tx.ex;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002459
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002460 while ((np->get_tx.ex != np->put_tx.ex) &&
Julia Lawall217d32d2010-07-05 22:15:47 -07002461 !((flags = le32_to_cpu(np->get_tx.ex->flaglen)) & NV_TX2_VALID) &&
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002462 (tx_work < limit)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002463
2464 dprintk(KERN_DEBUG "%s: nv_tx_done_optimized: flags 0x%x.\n",
2465 dev->name, flags);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002466
Eric Dumazet73a37072009-06-17 21:17:59 +00002467 nv_unmap_txskb(np, np->get_tx_ctx);
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002468
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002469 if (flags & NV_TX2_LASTPACKET) {
Ayaz Abdulla21828162007-01-23 12:27:21 -05002470 if (!(flags & NV_TX2_ERROR))
Jeff Garzik8148ff42007-10-16 20:56:09 -04002471 dev->stats.tx_packets++;
Ayaz Abdullaa4336862008-04-18 13:50:43 -07002472 else {
2473 if ((flags & NV_TX2_RETRYERROR) && !(flags & NV_TX2_RETRYCOUNT_MASK)) {
2474 if (np->driver_data & DEV_HAS_GEAR_MODE)
2475 nv_gear_backoff_reseed(dev);
2476 else
2477 nv_legacybackoff_reseed(dev);
2478 }
2479 }
2480
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002481 dev_kfree_skb_any(np->get_tx_ctx->skb);
2482 np->get_tx_ctx->skb = NULL;
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002483 tx_work++;
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002484
Szymon Janc78aea4f2010-11-27 08:39:43 +00002485 if (np->tx_limit)
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05002486 nv_tx_flip_ownership(dev);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002487 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002488 if (unlikely(np->get_tx.ex++ == np->last_tx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002489 np->get_tx.ex = np->first_tx.ex;
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002490 if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002491 np->get_tx_ctx = np->first_tx_ctx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002492 }
Ayaz Abdulla445583b2007-01-21 18:10:47 -05002493 if (unlikely((np->tx_stop == 1) && (np->get_tx.ex != orig_get_tx))) {
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002494 np->tx_stop = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002495 netif_wake_queue(dev);
Ayaz Abdullaaaa37d22007-01-21 18:10:42 -05002496 }
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002497 return tx_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002498}
2499
2500/*
2501 * nv_tx_timeout: dev->tx_timeout function
Herbert Xu932ff272006-06-09 12:20:56 -07002502 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002503 */
2504static void nv_tx_timeout(struct net_device *dev)
2505{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002506 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002507 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002508 u32 status;
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002509 union ring_type put_tx;
2510 int saved_tx_limit;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002511
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05002512 if (np->msi_flags & NV_MSI_X_ENABLED)
2513 status = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
2514 else
2515 status = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
2516
2517 printk(KERN_INFO "%s: Got tx_timeout. irq: %08x\n", dev->name, status);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002518
Manfred Spraulc2dba062005-07-31 18:29:47 +02002519 {
2520 int i;
2521
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002522 printk(KERN_INFO "%s: Ring at %lx\n",
2523 dev->name, (unsigned long)np->ring_addr);
Manfred Spraulc2dba062005-07-31 18:29:47 +02002524 printk(KERN_INFO "%s: Dumping tx registers\n", dev->name);
Szymon Janc78aea4f2010-11-27 08:39:43 +00002525 for (i = 0; i <= np->register_size; i += 32) {
Manfred Spraulc2dba062005-07-31 18:29:47 +02002526 printk(KERN_INFO "%3x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
2527 i,
2528 readl(base + i + 0), readl(base + i + 4),
2529 readl(base + i + 8), readl(base + i + 12),
2530 readl(base + i + 16), readl(base + i + 20),
2531 readl(base + i + 24), readl(base + i + 28));
2532 }
2533 printk(KERN_INFO "%s: Dumping tx ring\n", dev->name);
Szymon Janc78aea4f2010-11-27 08:39:43 +00002534 for (i = 0; i < np->tx_ring_size; i += 4) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002535 if (!nv_optimized(np)) {
Manfred Spraulee733622005-07-31 18:32:26 +02002536 printk(KERN_INFO "%03x: %08x %08x // %08x %08x // %08x %08x // %08x %08x\n",
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002537 i,
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002538 le32_to_cpu(np->tx_ring.orig[i].buf),
2539 le32_to_cpu(np->tx_ring.orig[i].flaglen),
2540 le32_to_cpu(np->tx_ring.orig[i+1].buf),
2541 le32_to_cpu(np->tx_ring.orig[i+1].flaglen),
2542 le32_to_cpu(np->tx_ring.orig[i+2].buf),
2543 le32_to_cpu(np->tx_ring.orig[i+2].flaglen),
2544 le32_to_cpu(np->tx_ring.orig[i+3].buf),
2545 le32_to_cpu(np->tx_ring.orig[i+3].flaglen));
Manfred Spraulee733622005-07-31 18:32:26 +02002546 } else {
2547 printk(KERN_INFO "%03x: %08x %08x %08x // %08x %08x %08x // %08x %08x %08x // %08x %08x %08x\n",
Jeff Garzikf3b197a2006-05-26 21:39:03 -04002548 i,
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002549 le32_to_cpu(np->tx_ring.ex[i].bufhigh),
2550 le32_to_cpu(np->tx_ring.ex[i].buflow),
2551 le32_to_cpu(np->tx_ring.ex[i].flaglen),
2552 le32_to_cpu(np->tx_ring.ex[i+1].bufhigh),
2553 le32_to_cpu(np->tx_ring.ex[i+1].buflow),
2554 le32_to_cpu(np->tx_ring.ex[i+1].flaglen),
2555 le32_to_cpu(np->tx_ring.ex[i+2].bufhigh),
2556 le32_to_cpu(np->tx_ring.ex[i+2].buflow),
2557 le32_to_cpu(np->tx_ring.ex[i+2].flaglen),
2558 le32_to_cpu(np->tx_ring.ex[i+3].bufhigh),
2559 le32_to_cpu(np->tx_ring.ex[i+3].buflow),
2560 le32_to_cpu(np->tx_ring.ex[i+3].flaglen));
Manfred Spraulee733622005-07-31 18:32:26 +02002561 }
Manfred Spraulc2dba062005-07-31 18:29:47 +02002562 }
2563 }
2564
Linus Torvalds1da177e2005-04-16 15:20:36 -07002565 spin_lock_irq(&np->lock);
2566
2567 /* 1) stop tx engine */
2568 nv_stop_tx(dev);
2569
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002570 /* 2) complete any outstanding tx and do not give HW any limited tx pkts */
2571 saved_tx_limit = np->tx_limit;
2572 np->tx_limit = 0; /* prevent giving HW any limited pkts */
2573 np->tx_stop = 0; /* prevent waking tx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002574 if (!nv_optimized(np))
Ayaz Abdulla33912e72009-03-05 08:02:10 +00002575 nv_tx_done(dev, np->tx_ring_size);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002576 else
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05002577 nv_tx_done_optimized(dev, np->tx_ring_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002578
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002579 /* save current HW postion */
2580 if (np->tx_change_owner)
2581 put_tx.ex = np->tx_change_owner->first_tx_desc;
2582 else
2583 put_tx = np->put_tx;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002584
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002585 /* 3) clear all tx state */
2586 nv_drain_tx(dev);
2587 nv_init_tx(dev);
Ayaz Abdulla3ba4d092007-03-23 05:50:02 -05002588
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002589 /* 4) restore state to current HW position */
2590 np->get_tx = np->put_tx = put_tx;
2591 np->tx_limit = saved_tx_limit;
2592
2593 /* 5) restart tx engine */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002594 nv_start_tx(dev);
Ayaz Abdulla8f955d72009-04-25 09:17:56 +00002595 netif_wake_queue(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002596 spin_unlock_irq(&np->lock);
2597}
2598
Manfred Spraul22c6d142005-04-19 21:17:09 +02002599/*
2600 * Called when the nic notices a mismatch between the actual data len on the
2601 * wire and the len indicated in the 802 header
2602 */
2603static int nv_getlen(struct net_device *dev, void *packet, int datalen)
2604{
2605 int hdrlen; /* length of the 802 header */
2606 int protolen; /* length as stored in the proto field */
2607
2608 /* 1) calculate len according to header */
Szymon Janc78aea4f2010-11-27 08:39:43 +00002609 if (((struct vlan_ethhdr *)packet)->h_vlan_proto == htons(ETH_P_8021Q)) {
2610 protolen = ntohs(((struct vlan_ethhdr *)packet)->h_vlan_encapsulated_proto);
Manfred Spraul22c6d142005-04-19 21:17:09 +02002611 hdrlen = VLAN_HLEN;
2612 } else {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002613 protolen = ntohs(((struct ethhdr *)packet)->h_proto);
Manfred Spraul22c6d142005-04-19 21:17:09 +02002614 hdrlen = ETH_HLEN;
2615 }
2616 dprintk(KERN_DEBUG "%s: nv_getlen: datalen %d, protolen %d, hdrlen %d\n",
2617 dev->name, datalen, protolen, hdrlen);
2618 if (protolen > ETH_DATA_LEN)
2619 return datalen; /* Value in proto field not a len, no checks possible */
2620
2621 protolen += hdrlen;
2622 /* consistency checks: */
2623 if (datalen > ETH_ZLEN) {
2624 if (datalen >= protolen) {
2625 /* more data on wire than in 802 header, trim of
2626 * additional data.
2627 */
2628 dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n",
2629 dev->name, protolen);
2630 return protolen;
2631 } else {
2632 /* less data on wire than mentioned in header.
2633 * Discard the packet.
2634 */
2635 dprintk(KERN_DEBUG "%s: nv_getlen: discarding long packet.\n",
2636 dev->name);
2637 return -1;
2638 }
2639 } else {
2640 /* short packet. Accept only if 802 values are also short */
2641 if (protolen > ETH_ZLEN) {
2642 dprintk(KERN_DEBUG "%s: nv_getlen: discarding short packet.\n",
2643 dev->name);
2644 return -1;
2645 }
2646 dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n",
2647 dev->name, datalen);
2648 return datalen;
2649 }
2650}
2651
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002652static int nv_rx_process(struct net_device *dev, int limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002653{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002654 struct fe_priv *np = netdev_priv(dev);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002655 u32 flags;
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002656 int rx_work = 0;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002657 struct sk_buff *skb;
2658 int len;
Ayaz Abdullaee407b02006-02-04 13:13:17 -05002659
Szymon Janc78aea4f2010-11-27 08:39:43 +00002660 while ((np->get_rx.orig != np->put_rx.orig) &&
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002661 !((flags = le32_to_cpu(np->get_rx.orig->flaglen)) & NV_RX_AVAIL) &&
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002662 (rx_work < limit)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002664 dprintk(KERN_DEBUG "%s: nv_rx_process: flags 0x%x.\n",
2665 dev->name, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002666
Linus Torvalds1da177e2005-04-16 15:20:36 -07002667 /*
2668 * the packet is for us - immediately tear down the pci mapping.
2669 * TODO: check if a prefetch of the first cacheline improves
2670 * the performance.
2671 */
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002672 pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma,
2673 np->get_rx_ctx->dma_len,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002674 PCI_DMA_FROMDEVICE);
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002675 skb = np->get_rx_ctx->skb;
2676 np->get_rx_ctx->skb = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677
2678 {
2679 int j;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002680 dprintk(KERN_DEBUG "Dumping packet (flags 0x%x).", flags);
2681 for (j = 0; j < 64; j++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002682 if ((j%16) == 0)
2683 dprintk("\n%03x:", j);
Szymon Janc78aea4f2010-11-27 08:39:43 +00002684 dprintk(" %02x", ((unsigned char *)skb->data)[j]);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002685 }
2686 dprintk("\n");
2687 }
2688 /* look at what we actually got: */
2689 if (np->desc_ver == DESC_VER_1) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002690 if (likely(flags & NV_RX_DESCRIPTORVALID)) {
2691 len = flags & LEN_MASK_V1;
2692 if (unlikely(flags & NV_RX_ERROR)) {
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002693 if ((flags & NV_RX_ERROR_MASK) == NV_RX_ERROR4) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002694 len = nv_getlen(dev, skb->data, len);
2695 if (len < 0) {
Jeff Garzik8148ff42007-10-16 20:56:09 -04002696 dev->stats.rx_errors++;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002697 dev_kfree_skb(skb);
2698 goto next_pkt;
2699 }
2700 }
2701 /* framing errors are soft errors */
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002702 else if ((flags & NV_RX_ERROR_MASK) == NV_RX_FRAMINGERR) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002703 if (flags & NV_RX_SUBSTRACT1)
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002704 len--;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002705 }
2706 /* the rest are hard errors */
2707 else {
2708 if (flags & NV_RX_MISSEDFRAME)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002709 dev->stats.rx_missed_errors++;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002710 if (flags & NV_RX_CRCERR)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002711 dev->stats.rx_crc_errors++;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002712 if (flags & NV_RX_OVERFLOW)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002713 dev->stats.rx_over_errors++;
2714 dev->stats.rx_errors++;
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002715 dev_kfree_skb(skb);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002716 goto next_pkt;
2717 }
2718 }
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002719 } else {
2720 dev_kfree_skb(skb);
2721 goto next_pkt;
Manfred Spraul22c6d142005-04-19 21:17:09 +02002722 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002723 } else {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002724 if (likely(flags & NV_RX2_DESCRIPTORVALID)) {
2725 len = flags & LEN_MASK_V2;
2726 if (unlikely(flags & NV_RX2_ERROR)) {
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002727 if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_ERROR4) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002728 len = nv_getlen(dev, skb->data, len);
2729 if (len < 0) {
Jeff Garzik8148ff42007-10-16 20:56:09 -04002730 dev->stats.rx_errors++;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002731 dev_kfree_skb(skb);
2732 goto next_pkt;
2733 }
2734 }
2735 /* framing errors are soft errors */
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002736 else if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_FRAMINGERR) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002737 if (flags & NV_RX2_SUBSTRACT1)
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002738 len--;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002739 }
2740 /* the rest are hard errors */
2741 else {
2742 if (flags & NV_RX2_CRCERR)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002743 dev->stats.rx_crc_errors++;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002744 if (flags & NV_RX2_OVERFLOW)
Jeff Garzik8148ff42007-10-16 20:56:09 -04002745 dev->stats.rx_over_errors++;
2746 dev->stats.rx_errors++;
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002747 dev_kfree_skb(skb);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05002748 goto next_pkt;
2749 }
2750 }
Ayaz Abdullabfaffe82008-01-13 16:02:55 -05002751 if (((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_TCP) || /*ip and tcp */
2752 ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_UDP)) /*ip and udp */
Ayaz Abdulla0d63fb32007-01-09 13:30:13 -05002753 skb->ip_summed = CHECKSUM_UNNECESSARY;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002754 } else {
2755 dev_kfree_skb(skb);
2756 goto next_pkt;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757 }
2758 }
2759 /* got a valid packet - forward it to the network core */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760 skb_put(skb, len);
2761 skb->protocol = eth_type_trans(skb, dev);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002762 dprintk(KERN_DEBUG "%s: nv_rx_process: %d bytes, proto %d accepted.\n",
2763 dev->name, len, skb->protocol);
Tom Herbert53f224c2010-05-03 19:08:45 +00002764 napi_gro_receive(&np->napi, skb);
Jeff Garzik8148ff42007-10-16 20:56:09 -04002765 dev->stats.rx_packets++;
2766 dev->stats.rx_bytes += len;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002767next_pkt:
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002768 if (unlikely(np->get_rx.orig++ == np->last_rx.orig))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002769 np->get_rx.orig = np->first_rx.orig;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002770 if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002771 np->get_rx_ctx = np->first_rx_ctx;
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002772
2773 rx_work++;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002774 }
2775
Ingo Molnarbcb5feb2007-10-16 20:44:59 -04002776 return rx_work;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002777}
2778
2779static int nv_rx_process_optimized(struct net_device *dev, int limit)
2780{
2781 struct fe_priv *np = netdev_priv(dev);
2782 u32 flags;
2783 u32 vlanflags = 0;
Ingo Molnarc1b71512007-10-17 12:18:23 +02002784 int rx_work = 0;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002785 struct sk_buff *skb;
2786 int len;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002787
Szymon Janc78aea4f2010-11-27 08:39:43 +00002788 while ((np->get_rx.ex != np->put_rx.ex) &&
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002789 !((flags = le32_to_cpu(np->get_rx.ex->flaglen)) & NV_RX2_AVAIL) &&
Ingo Molnarc1b71512007-10-17 12:18:23 +02002790 (rx_work < limit)) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002791
2792 dprintk(KERN_DEBUG "%s: nv_rx_process_optimized: flags 0x%x.\n",
2793 dev->name, flags);
2794
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002795 /*
2796 * the packet is for us - immediately tear down the pci mapping.
2797 * TODO: check if a prefetch of the first cacheline improves
2798 * the performance.
2799 */
2800 pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma,
2801 np->get_rx_ctx->dma_len,
2802 PCI_DMA_FROMDEVICE);
2803 skb = np->get_rx_ctx->skb;
2804 np->get_rx_ctx->skb = NULL;
2805
2806 {
2807 int j;
Szymon Janc78aea4f2010-11-27 08:39:43 +00002808 dprintk(KERN_DEBUG "Dumping packet (flags 0x%x).", flags);
2809 for (j = 0; j < 64; j++) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002810 if ((j%16) == 0)
2811 dprintk("\n%03x:", j);
Szymon Janc78aea4f2010-11-27 08:39:43 +00002812 dprintk(" %02x", ((unsigned char *)skb->data)[j]);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002813 }
2814 dprintk("\n");
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002815 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002816 /* look at what we actually got: */
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002817 if (likely(flags & NV_RX2_DESCRIPTORVALID)) {
2818 len = flags & LEN_MASK_V2;
2819 if (unlikely(flags & NV_RX2_ERROR)) {
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002820 if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_ERROR4) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002821 len = nv_getlen(dev, skb->data, len);
2822 if (len < 0) {
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002823 dev_kfree_skb(skb);
2824 goto next_pkt;
2825 }
2826 }
2827 /* framing errors are soft errors */
Ayaz Abdulla1ef68412008-08-06 12:11:03 -04002828 else if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_FRAMINGERR) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00002829 if (flags & NV_RX2_SUBSTRACT1)
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002830 len--;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002831 }
2832 /* the rest are hard errors */
2833 else {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002834 dev_kfree_skb(skb);
2835 goto next_pkt;
2836 }
2837 }
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002838
Ayaz Abdullabfaffe82008-01-13 16:02:55 -05002839 if (((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_TCP) || /*ip and tcp */
2840 ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_UDP)) /*ip and udp */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002841 skb->ip_summed = CHECKSUM_UNNECESSARY;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002842
2843 /* got a valid packet - forward it to the network core */
2844 skb_put(skb, len);
2845 skb->protocol = eth_type_trans(skb, dev);
2846 prefetch(skb->data);
2847
2848 dprintk(KERN_DEBUG "%s: nv_rx_process_optimized: %d bytes, proto %d accepted.\n",
2849 dev->name, len, skb->protocol);
2850
2851 if (likely(!np->vlangrp)) {
Tom Herbert53f224c2010-05-03 19:08:45 +00002852 napi_gro_receive(&np->napi, skb);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002853 } else {
2854 vlanflags = le32_to_cpu(np->get_rx.ex->buflow);
2855 if (vlanflags & NV_RX3_VLAN_TAG_PRESENT) {
Tom Herbert53f224c2010-05-03 19:08:45 +00002856 vlan_gro_receive(&np->napi, np->vlangrp,
2857 vlanflags & NV_RX3_VLAN_TAG_MASK, skb);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002858 } else {
Tom Herbert53f224c2010-05-03 19:08:45 +00002859 napi_gro_receive(&np->napi, skb);
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002860 }
2861 }
2862
Jeff Garzik8148ff42007-10-16 20:56:09 -04002863 dev->stats.rx_packets++;
2864 dev->stats.rx_bytes += len;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002865 } else {
2866 dev_kfree_skb(skb);
2867 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002868next_pkt:
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002869 if (unlikely(np->get_rx.ex++ == np->last_rx.ex))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05002870 np->get_rx.ex = np->first_rx.ex;
Ayaz Abdullab01867c2007-01-21 18:10:52 -05002871 if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05002872 np->get_rx_ctx = np->first_rx_ctx;
Ingo Molnarc1b71512007-10-17 12:18:23 +02002873
2874 rx_work++;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002875 }
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07002876
Ingo Molnarc1b71512007-10-17 12:18:23 +02002877 return rx_work;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002878}
2879
Manfred Sprauld81c0982005-07-31 18:20:30 +02002880static void set_bufsize(struct net_device *dev)
2881{
2882 struct fe_priv *np = netdev_priv(dev);
2883
2884 if (dev->mtu <= ETH_DATA_LEN)
2885 np->rx_buf_sz = ETH_DATA_LEN + NV_RX_HEADERS;
2886 else
2887 np->rx_buf_sz = dev->mtu + NV_RX_HEADERS;
2888}
2889
Linus Torvalds1da177e2005-04-16 15:20:36 -07002890/*
2891 * nv_change_mtu: dev->change_mtu function
2892 * Called with dev_base_lock held for read.
2893 */
2894static int nv_change_mtu(struct net_device *dev, int new_mtu)
2895{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002896 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002897 int old_mtu;
2898
2899 if (new_mtu < 64 || new_mtu > np->pkt_limit)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002900 return -EINVAL;
Manfred Sprauld81c0982005-07-31 18:20:30 +02002901
2902 old_mtu = dev->mtu;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903 dev->mtu = new_mtu;
Manfred Sprauld81c0982005-07-31 18:20:30 +02002904
2905 /* return early if the buffer sizes will not change */
2906 if (old_mtu <= ETH_DATA_LEN && new_mtu <= ETH_DATA_LEN)
2907 return 0;
2908 if (old_mtu == new_mtu)
2909 return 0;
2910
2911 /* synchronized against open : rtnl_lock() held by caller */
2912 if (netif_running(dev)) {
viro@ftp.linux.org.uk25097d42005-09-06 01:36:58 +01002913 u8 __iomem *base = get_hwbase(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002914 /*
2915 * It seems that the nic preloads valid ring entries into an
2916 * internal buffer. The procedure for flushing everything is
2917 * guessed, there is probably a simpler approach.
2918 * Changing the MTU is a rare event, it shouldn't matter.
2919 */
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002920 nv_disable_irq(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00002921 nv_napi_disable(dev);
Herbert Xu932ff272006-06-09 12:20:56 -07002922 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07002923 netif_addr_lock(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002924 spin_lock(&np->lock);
2925 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002926 nv_stop_rxtx(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002927 nv_txrx_reset(dev);
2928 /* drain rx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002929 nv_drain_rxtx(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002930 /* reinit driver view of the rx queue */
Manfred Sprauld81c0982005-07-31 18:20:30 +02002931 set_bufsize(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04002932 if (nv_init_ring(dev)) {
Manfred Sprauld81c0982005-07-31 18:20:30 +02002933 if (!np->in_shutdown)
2934 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2935 }
2936 /* reinit nic view of the rx queue */
2937 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
Ayaz Abdulla0832b252006-02-04 13:13:26 -05002938 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00002939 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Manfred Sprauld81c0982005-07-31 18:20:30 +02002940 base + NvRegRingSizes);
2941 pci_push(base);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04002942 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002943 pci_push(base);
2944
2945 /* restart rx engine */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04002946 nv_start_rxtx(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002947 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07002948 netif_addr_unlock(dev);
Herbert Xu932ff272006-06-09 12:20:56 -07002949 netif_tx_unlock_bh(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00002950 nv_napi_enable(dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07002951 nv_enable_irq(dev);
Manfred Sprauld81c0982005-07-31 18:20:30 +02002952 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002953 return 0;
2954}
2955
Manfred Spraul72b31782005-07-31 18:33:34 +02002956static void nv_copy_mac_to_hw(struct net_device *dev)
2957{
viro@ftp.linux.org.uk25097d42005-09-06 01:36:58 +01002958 u8 __iomem *base = get_hwbase(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002959 u32 mac[2];
2960
2961 mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) +
2962 (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24);
2963 mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8);
2964
2965 writel(mac[0], base + NvRegMacAddrA);
2966 writel(mac[1], base + NvRegMacAddrB);
2967}
2968
2969/*
2970 * nv_set_mac_address: dev->set_mac_address function
2971 * Called with rtnl_lock() held.
2972 */
2973static int nv_set_mac_address(struct net_device *dev, void *addr)
2974{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04002975 struct fe_priv *np = netdev_priv(dev);
Szymon Janc78aea4f2010-11-27 08:39:43 +00002976 struct sockaddr *macaddr = (struct sockaddr *)addr;
Manfred Spraul72b31782005-07-31 18:33:34 +02002977
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07002978 if (!is_valid_ether_addr(macaddr->sa_data))
Manfred Spraul72b31782005-07-31 18:33:34 +02002979 return -EADDRNOTAVAIL;
2980
2981 /* synchronized against open : rtnl_lock() held by caller */
2982 memcpy(dev->dev_addr, macaddr->sa_data, ETH_ALEN);
2983
2984 if (netif_running(dev)) {
Herbert Xu932ff272006-06-09 12:20:56 -07002985 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07002986 netif_addr_lock(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02002987 spin_lock_irq(&np->lock);
2988
2989 /* stop rx engine */
2990 nv_stop_rx(dev);
2991
2992 /* set mac address */
2993 nv_copy_mac_to_hw(dev);
2994
2995 /* restart rx engine */
2996 nv_start_rx(dev);
2997 spin_unlock_irq(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07002998 netif_addr_unlock(dev);
Herbert Xu932ff272006-06-09 12:20:56 -07002999 netif_tx_unlock_bh(dev);
Manfred Spraul72b31782005-07-31 18:33:34 +02003000 } else {
3001 nv_copy_mac_to_hw(dev);
3002 }
3003 return 0;
3004}
3005
Linus Torvalds1da177e2005-04-16 15:20:36 -07003006/*
3007 * nv_set_multicast: dev->set_multicast function
Herbert Xu932ff272006-06-09 12:20:56 -07003008 * Called with netif_tx_lock held.
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 */
3010static void nv_set_multicast(struct net_device *dev)
3011{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003012 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003013 u8 __iomem *base = get_hwbase(dev);
3014 u32 addr[2];
3015 u32 mask[2];
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003016 u32 pff = readl(base + NvRegPacketFilterFlags) & NVREG_PFF_PAUSE_RX;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017
3018 memset(addr, 0, sizeof(addr));
3019 memset(mask, 0, sizeof(mask));
3020
3021 if (dev->flags & IFF_PROMISC) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003022 pff |= NVREG_PFF_PROMISC;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003023 } else {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003024 pff |= NVREG_PFF_MYADDR;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003025
Jiri Pirko48e2f182010-02-22 09:22:26 +00003026 if (dev->flags & IFF_ALLMULTI || !netdev_mc_empty(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003027 u32 alwaysOff[2];
3028 u32 alwaysOn[2];
3029
3030 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0xffffffff;
3031 if (dev->flags & IFF_ALLMULTI) {
3032 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0;
3033 } else {
Jiri Pirko22bedad32010-04-01 21:22:57 +00003034 struct netdev_hw_addr *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003035
Jiri Pirko22bedad32010-04-01 21:22:57 +00003036 netdev_for_each_mc_addr(ha, dev) {
3037 unsigned char *addr = ha->addr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003038 u32 a, b;
Jiri Pirko22bedad32010-04-01 21:22:57 +00003039
3040 a = le32_to_cpu(*(__le32 *) addr);
3041 b = le16_to_cpu(*(__le16 *) (&addr[4]));
Linus Torvalds1da177e2005-04-16 15:20:36 -07003042 alwaysOn[0] &= a;
3043 alwaysOff[0] &= ~a;
3044 alwaysOn[1] &= b;
3045 alwaysOff[1] &= ~b;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003046 }
3047 }
3048 addr[0] = alwaysOn[0];
3049 addr[1] = alwaysOn[1];
3050 mask[0] = alwaysOn[0] | alwaysOff[0];
3051 mask[1] = alwaysOn[1] | alwaysOff[1];
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -05003052 } else {
3053 mask[0] = NVREG_MCASTMASKA_NONE;
3054 mask[1] = NVREG_MCASTMASKB_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003055 }
3056 }
3057 addr[0] |= NVREG_MCASTADDRA_FORCE;
3058 pff |= NVREG_PFF_ALWAYS;
3059 spin_lock_irq(&np->lock);
3060 nv_stop_rx(dev);
3061 writel(addr[0], base + NvRegMulticastAddrA);
3062 writel(addr[1], base + NvRegMulticastAddrB);
3063 writel(mask[0], base + NvRegMulticastMaskA);
3064 writel(mask[1], base + NvRegMulticastMaskB);
3065 writel(pff, base + NvRegPacketFilterFlags);
3066 dprintk(KERN_INFO "%s: reconfiguration for multicast lists.\n",
3067 dev->name);
3068 nv_start_rx(dev);
3069 spin_unlock_irq(&np->lock);
3070}
3071
Adrian Bunkc7985052006-06-22 12:03:29 +02003072static void nv_update_pause(struct net_device *dev, u32 pause_flags)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003073{
3074 struct fe_priv *np = netdev_priv(dev);
3075 u8 __iomem *base = get_hwbase(dev);
3076
3077 np->pause_flags &= ~(NV_PAUSEFRAME_TX_ENABLE | NV_PAUSEFRAME_RX_ENABLE);
3078
3079 if (np->pause_flags & NV_PAUSEFRAME_RX_CAPABLE) {
3080 u32 pff = readl(base + NvRegPacketFilterFlags) & ~NVREG_PFF_PAUSE_RX;
3081 if (pause_flags & NV_PAUSEFRAME_RX_ENABLE) {
3082 writel(pff|NVREG_PFF_PAUSE_RX, base + NvRegPacketFilterFlags);
3083 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3084 } else {
3085 writel(pff, base + NvRegPacketFilterFlags);
3086 }
3087 }
3088 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE) {
3089 u32 regmisc = readl(base + NvRegMisc1) & ~NVREG_MISC1_PAUSE_TX;
3090 if (pause_flags & NV_PAUSEFRAME_TX_ENABLE) {
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05003091 u32 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V1;
3092 if (np->driver_data & DEV_HAS_PAUSEFRAME_TX_V2)
3093 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V2;
Ayaz Abdulla9a33e882008-08-06 12:12:34 -04003094 if (np->driver_data & DEV_HAS_PAUSEFRAME_TX_V3) {
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05003095 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V3;
Ayaz Abdulla9a33e882008-08-06 12:12:34 -04003096 /* limit the number of tx pause frames to a default of 8 */
3097 writel(readl(base + NvRegTxPauseFrameLimit)|NVREG_TX_PAUSEFRAMELIMIT_ENABLE, base + NvRegTxPauseFrameLimit);
3098 }
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05003099 writel(pause_enable, base + NvRegTxPauseFrame);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003100 writel(regmisc|NVREG_MISC1_PAUSE_TX, base + NvRegMisc1);
3101 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3102 } else {
3103 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
3104 writel(regmisc, base + NvRegMisc1);
3105 }
3106 }
3107}
3108
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05003109/**
3110 * nv_update_linkspeed: Setup the MAC according to the link partner
3111 * @dev: Network device to be configured
3112 *
3113 * The function queries the PHY and checks if there is a link partner.
3114 * If yes, then it sets up the MAC accordingly. Otherwise, the MAC is
3115 * set to 10 MBit HD.
3116 *
3117 * The function returns 0 if there is no link partner and 1 if there is
3118 * a good link partner.
3119 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07003120static int nv_update_linkspeed(struct net_device *dev)
3121{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003122 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003123 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003124 int adv = 0;
3125 int lpa = 0;
3126 int adv_lpa, adv_pause, lpa_pause;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003127 int newls = np->linkspeed;
3128 int newdup = np->duplex;
3129 int mii_status;
3130 int retval = 0;
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003131 u32 control_1000, status_1000, phyreg, pause_flags, txreg;
Ayaz Abdullab2976d22008-02-04 15:13:59 -05003132 u32 txrxFlags = 0;
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003133 u32 phy_exp;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003134
3135 /* BMSR_LSTATUS is latched, read it twice:
3136 * we want the current value.
3137 */
3138 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
3139 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
3140
3141 if (!(mii_status & BMSR_LSTATUS)) {
3142 dprintk(KERN_DEBUG "%s: no link detected by phy - falling back to 10HD.\n",
3143 dev->name);
3144 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3145 newdup = 0;
3146 retval = 0;
3147 goto set_speed;
3148 }
3149
3150 if (np->autoneg == 0) {
3151 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: autoneg off, PHY set to 0x%04x.\n",
3152 dev->name, np->fixed_mode);
3153 if (np->fixed_mode & LPA_100FULL) {
3154 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3155 newdup = 1;
3156 } else if (np->fixed_mode & LPA_100HALF) {
3157 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3158 newdup = 0;
3159 } else if (np->fixed_mode & LPA_10FULL) {
3160 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3161 newdup = 1;
3162 } else {
3163 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3164 newdup = 0;
3165 }
3166 retval = 1;
3167 goto set_speed;
3168 }
3169 /* check auto negotiation is complete */
3170 if (!(mii_status & BMSR_ANEGCOMPLETE)) {
3171 /* still in autonegotiation - configure nic for 10 MBit HD and wait. */
3172 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3173 newdup = 0;
3174 retval = 0;
3175 dprintk(KERN_DEBUG "%s: autoneg not completed - falling back to 10HD.\n", dev->name);
3176 goto set_speed;
3177 }
3178
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003179 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
3180 lpa = mii_rw(dev, np->phyaddr, MII_LPA, MII_READ);
3181 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: PHY advertises 0x%04x, lpa 0x%04x.\n",
3182 dev->name, adv, lpa);
3183
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184 retval = 1;
3185 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003186 control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
3187 status_1000 = mii_rw(dev, np->phyaddr, MII_STAT1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003188
3189 if ((control_1000 & ADVERTISE_1000FULL) &&
3190 (status_1000 & LPA_1000FULL)) {
3191 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: GBit ethernet detected.\n",
3192 dev->name);
3193 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_1000;
3194 newdup = 1;
3195 goto set_speed;
3196 }
3197 }
3198
Linus Torvalds1da177e2005-04-16 15:20:36 -07003199 /* FIXME: handle parallel detection properly */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003200 adv_lpa = lpa & adv;
3201 if (adv_lpa & LPA_100FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003202 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3203 newdup = 1;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003204 } else if (adv_lpa & LPA_100HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003205 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3206 newdup = 0;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003207 } else if (adv_lpa & LPA_10FULL) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003208 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3209 newdup = 1;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003210 } else if (adv_lpa & LPA_10HALF) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003211 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3212 newdup = 0;
3213 } else {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003214 dprintk(KERN_DEBUG "%s: bad ability %04x - falling back to 10HD.\n", dev->name, adv_lpa);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003215 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3216 newdup = 0;
3217 }
3218
3219set_speed:
3220 if (np->duplex == newdup && np->linkspeed == newls)
3221 return retval;
3222
3223 dprintk(KERN_INFO "%s: changing link setting from %d/%d to %d/%d.\n",
3224 dev->name, np->linkspeed, np->duplex, newls, newdup);
3225
3226 np->duplex = newdup;
3227 np->linkspeed = newls;
3228
Ayaz Abdullab2976d22008-02-04 15:13:59 -05003229 /* The transmitter and receiver must be restarted for safe update */
3230 if (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_START) {
3231 txrxFlags |= NV_RESTART_TX;
3232 nv_stop_tx(dev);
3233 }
3234 if (readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) {
3235 txrxFlags |= NV_RESTART_RX;
3236 nv_stop_rx(dev);
3237 }
3238
Linus Torvalds1da177e2005-04-16 15:20:36 -07003239 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaa4336862008-04-18 13:50:43 -07003240 phyreg = readl(base + NvRegSlotTime);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003241 phyreg &= ~(0x3FF00);
Ayaz Abdullaa4336862008-04-18 13:50:43 -07003242 if (((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10) ||
3243 ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100))
3244 phyreg |= NVREG_SLOTTIME_10_100_FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003245 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000)
Ayaz Abdullaa4336862008-04-18 13:50:43 -07003246 phyreg |= NVREG_SLOTTIME_1000_FULL;
3247 writel(phyreg, base + NvRegSlotTime);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003248 }
3249
3250 phyreg = readl(base + NvRegPhyInterface);
3251 phyreg &= ~(PHY_HALF|PHY_100|PHY_1000);
3252 if (np->duplex == 0)
3253 phyreg |= PHY_HALF;
3254 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100)
3255 phyreg |= PHY_100;
3256 else if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
3257 phyreg |= PHY_1000;
3258 writel(phyreg, base + NvRegPhyInterface);
3259
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003260 phy_exp = mii_rw(dev, np->phyaddr, MII_EXPANSION, MII_READ) & EXPANSION_NWAY; /* autoneg capable */
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003261 if (phyreg & PHY_RGMII) {
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003262 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000) {
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003263 txreg = NVREG_TX_DEFERRAL_RGMII_1000;
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003264 } else {
3265 if (!phy_exp && !np->duplex && (np->driver_data & DEV_HAS_COLLISION_FIX)) {
3266 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_10)
3267 txreg = NVREG_TX_DEFERRAL_RGMII_STRETCH_10;
3268 else
3269 txreg = NVREG_TX_DEFERRAL_RGMII_STRETCH_100;
3270 } else {
3271 txreg = NVREG_TX_DEFERRAL_RGMII_10_100;
3272 }
3273 }
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003274 } else {
Ayaz Abdullafd9b5582008-02-05 12:29:49 -05003275 if (!phy_exp && !np->duplex && (np->driver_data & DEV_HAS_COLLISION_FIX))
3276 txreg = NVREG_TX_DEFERRAL_MII_STRETCH;
3277 else
3278 txreg = NVREG_TX_DEFERRAL_DEFAULT;
Ayaz Abdulla9744e212006-07-06 16:45:58 -04003279 }
3280 writel(txreg, base + NvRegTxDeferral);
3281
Ayaz Abdulla95d161c2006-07-06 16:46:25 -04003282 if (np->desc_ver == DESC_VER_1) {
3283 txreg = NVREG_TX_WM_DESC1_DEFAULT;
3284 } else {
3285 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
3286 txreg = NVREG_TX_WM_DESC2_3_1000;
3287 else
3288 txreg = NVREG_TX_WM_DESC2_3_DEFAULT;
3289 }
3290 writel(txreg, base + NvRegTxWatermark);
3291
Szymon Janc78aea4f2010-11-27 08:39:43 +00003292 writel(NVREG_MISC1_FORCE | (np->duplex ? 0 : NVREG_MISC1_HD),
Linus Torvalds1da177e2005-04-16 15:20:36 -07003293 base + NvRegMisc1);
3294 pci_push(base);
3295 writel(np->linkspeed, base + NvRegLinkSpeed);
3296 pci_push(base);
3297
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003298 pause_flags = 0;
3299 /* setup pause frame */
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003300 if (np->duplex != 0) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003301 if (np->autoneg && np->pause_flags & NV_PAUSEFRAME_AUTONEG) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003302 adv_pause = adv & (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
3303 lpa_pause = lpa & (LPA_PAUSE_CAP | LPA_PAUSE_ASYM);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003304
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003305 switch (adv_pause) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003306 case ADVERTISE_PAUSE_CAP:
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003307 if (lpa_pause & LPA_PAUSE_CAP) {
3308 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3309 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
3310 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3311 }
3312 break;
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07003313 case ADVERTISE_PAUSE_ASYM:
Szymon Janc78aea4f2010-11-27 08:39:43 +00003314 if (lpa_pause == (LPA_PAUSE_CAP | LPA_PAUSE_ASYM))
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003315 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003316 break;
Szymon Janc78aea4f2010-11-27 08:39:43 +00003317 case ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM:
3318 if (lpa_pause & LPA_PAUSE_CAP) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003319 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3320 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
3321 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3322 }
3323 if (lpa_pause == LPA_PAUSE_ASYM)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003324 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003325 break;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003326 }
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003327 } else {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003328 pause_flags = np->pause_flags;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003329 }
3330 }
Ayaz Abdullab6d07732006-06-10 22:47:42 -04003331 nv_update_pause(dev, pause_flags);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04003332
Ayaz Abdullab2976d22008-02-04 15:13:59 -05003333 if (txrxFlags & NV_RESTART_TX)
3334 nv_start_tx(dev);
3335 if (txrxFlags & NV_RESTART_RX)
3336 nv_start_rx(dev);
3337
Linus Torvalds1da177e2005-04-16 15:20:36 -07003338 return retval;
3339}
3340
3341static void nv_linkchange(struct net_device *dev)
3342{
3343 if (nv_update_linkspeed(dev)) {
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05003344 if (!netif_carrier_ok(dev)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07003345 netif_carrier_on(dev);
3346 printk(KERN_INFO "%s: link up.\n", dev->name);
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00003347 nv_txrx_gate(dev, false);
Ayaz Abdulla4ea7f292005-11-11 08:29:59 -05003348 nv_start_rx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003349 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003350 } else {
3351 if (netif_carrier_ok(dev)) {
3352 netif_carrier_off(dev);
3353 printk(KERN_INFO "%s: link down.\n", dev->name);
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00003354 nv_txrx_gate(dev, true);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003355 nv_stop_rx(dev);
3356 }
3357 }
3358}
3359
3360static void nv_link_irq(struct net_device *dev)
3361{
3362 u8 __iomem *base = get_hwbase(dev);
3363 u32 miistat;
3364
3365 miistat = readl(base + NvRegMIIStatus);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05003366 writel(NVREG_MIISTAT_LINKCHANGE, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003367 dprintk(KERN_INFO "%s: link change irq, status 0x%x.\n", dev->name, miistat);
3368
3369 if (miistat & (NVREG_MIISTAT_LINKCHANGE))
3370 nv_linkchange(dev);
3371 dprintk(KERN_DEBUG "%s: link change notification done.\n", dev->name);
3372}
3373
Ayaz Abdulla4db0ee172008-06-09 16:51:06 -07003374static void nv_msi_workaround(struct fe_priv *np)
3375{
3376
3377 /* Need to toggle the msi irq mask within the ethernet device,
3378 * otherwise, future interrupts will not be detected.
3379 */
3380 if (np->msi_flags & NV_MSI_ENABLED) {
3381 u8 __iomem *base = np->base;
3382
3383 writel(0, base + NvRegMSIIrqMask);
3384 writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask);
3385 }
3386}
3387
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003388static inline int nv_change_interrupt_mode(struct net_device *dev, int total_work)
3389{
3390 struct fe_priv *np = netdev_priv(dev);
3391
3392 if (optimization_mode == NV_OPTIMIZATION_MODE_DYNAMIC) {
3393 if (total_work > NV_DYNAMIC_THRESHOLD) {
3394 /* transition to poll based interrupts */
3395 np->quiet_count = 0;
3396 if (np->irqmask != NVREG_IRQMASK_CPU) {
3397 np->irqmask = NVREG_IRQMASK_CPU;
3398 return 1;
3399 }
3400 } else {
3401 if (np->quiet_count < NV_DYNAMIC_MAX_QUIET_COUNT) {
3402 np->quiet_count++;
3403 } else {
3404 /* reached a period of low activity, switch
3405 to per tx/rx packet interrupts */
3406 if (np->irqmask != NVREG_IRQMASK_THROUGHPUT) {
3407 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
3408 return 1;
3409 }
3410 }
3411 }
3412 }
3413 return 0;
3414}
3415
David Howells7d12e782006-10-05 14:55:46 +01003416static irqreturn_t nv_nic_irq(int foo, void *data)
Linus Torvalds1da177e2005-04-16 15:20:36 -07003417{
3418 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003419 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003420 u8 __iomem *base = get_hwbase(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003421
3422 dprintk(KERN_DEBUG "%s: nv_nic_irq\n", dev->name);
3423
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003424 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3425 np->events = readl(base + NvRegIrqStatus);
Ayaz Abdulla1b2bb762009-03-05 08:02:34 +00003426 writel(np->events, base + NvRegIrqStatus);
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003427 } else {
3428 np->events = readl(base + NvRegMSIXIrqStatus);
Ayaz Abdulla1b2bb762009-03-05 08:02:34 +00003429 writel(np->events, base + NvRegMSIXIrqStatus);
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003430 }
3431 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, np->events);
3432 if (!(np->events & np->irqmask))
3433 return IRQ_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003434
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003435 nv_msi_workaround(np);
Ayaz Abdulla4db0ee172008-06-09 16:51:06 -07003436
Eric Dumazet78c29bd2009-07-02 04:04:45 +00003437 if (napi_schedule_prep(&np->napi)) {
3438 /*
3439 * Disable further irq's (msix not enabled with napi)
3440 */
3441 writel(0, base + NvRegIrqMask);
3442 __napi_schedule(&np->napi);
3443 }
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003444
Linus Torvalds1da177e2005-04-16 15:20:36 -07003445 dprintk(KERN_DEBUG "%s: nv_nic_irq completed\n", dev->name);
3446
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003447 return IRQ_HANDLED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003448}
3449
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003450/**
3451 * All _optimized functions are used to help increase performance
3452 * (reduce CPU and increase throughput). They use descripter version 3,
3453 * compiler directives, and reduce memory accesses.
3454 */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003455static irqreturn_t nv_nic_irq_optimized(int foo, void *data)
3456{
3457 struct net_device *dev = (struct net_device *) data;
3458 struct fe_priv *np = netdev_priv(dev);
3459 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003460
3461 dprintk(KERN_DEBUG "%s: nv_nic_irq_optimized\n", dev->name);
3462
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003463 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3464 np->events = readl(base + NvRegIrqStatus);
Ayaz Abdulla1b2bb762009-03-05 08:02:34 +00003465 writel(np->events, base + NvRegIrqStatus);
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003466 } else {
3467 np->events = readl(base + NvRegMSIXIrqStatus);
Ayaz Abdulla1b2bb762009-03-05 08:02:34 +00003468 writel(np->events, base + NvRegMSIXIrqStatus);
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003469 }
3470 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, np->events);
3471 if (!(np->events & np->irqmask))
3472 return IRQ_NONE;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003473
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003474 nv_msi_workaround(np);
Ayaz Abdulla4db0ee172008-06-09 16:51:06 -07003475
Eric Dumazet78c29bd2009-07-02 04:04:45 +00003476 if (napi_schedule_prep(&np->napi)) {
3477 /*
3478 * Disable further irq's (msix not enabled with napi)
3479 */
3480 writel(0, base + NvRegIrqMask);
3481 __napi_schedule(&np->napi);
3482 }
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003483 dprintk(KERN_DEBUG "%s: nv_nic_irq_optimized completed\n", dev->name);
3484
Ayaz Abdullab67874a2009-03-05 08:02:22 +00003485 return IRQ_HANDLED;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003486}
3487
David Howells7d12e782006-10-05 14:55:46 +01003488static irqreturn_t nv_nic_irq_tx(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003489{
3490 struct net_device *dev = (struct net_device *) data;
3491 struct fe_priv *np = netdev_priv(dev);
3492 u8 __iomem *base = get_hwbase(dev);
3493 u32 events;
3494 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003495 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003496
3497 dprintk(KERN_DEBUG "%s: nv_nic_irq_tx\n", dev->name);
3498
Szymon Janc78aea4f2010-11-27 08:39:43 +00003499 for (i = 0;; i++) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003500 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_TX_ALL;
3501 writel(NVREG_IRQ_TX_ALL, base + NvRegMSIXIrqStatus);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003502 dprintk(KERN_DEBUG "%s: tx irq: %08x\n", dev->name, events);
3503 if (!(events & np->irqmask))
3504 break;
3505
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003506 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05003507 nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003508 spin_unlock_irqrestore(&np->lock, flags);
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003509
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003510 if (unlikely(i > max_interrupt_work)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003511 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003512 /* disable interrupts on the nic */
3513 writel(NVREG_IRQ_TX_ALL, base + NvRegIrqMask);
3514 pci_push(base);
3515
3516 if (!np->in_shutdown) {
3517 np->nic_poll_irq |= NVREG_IRQ_TX_ALL;
3518 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3519 }
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003520 spin_unlock_irqrestore(&np->lock, flags);
Timo Jantunen1a2b7332007-08-14 21:56:57 +03003521 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_tx.\n", dev->name, i);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003522 break;
3523 }
3524
3525 }
3526 dprintk(KERN_DEBUG "%s: nv_nic_irq_tx completed\n", dev->name);
3527
3528 return IRQ_RETVAL(i);
3529}
3530
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003531static int nv_napi_poll(struct napi_struct *napi, int budget)
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003532{
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003533 struct fe_priv *np = container_of(napi, struct fe_priv, napi);
3534 struct net_device *dev = np->dev;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003535 u8 __iomem *base = get_hwbase(dev);
Francois Romieud15e9c42006-12-17 23:03:15 +01003536 unsigned long flags;
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003537 int retcode;
Szymon Janc78aea4f2010-11-27 08:39:43 +00003538 int rx_count, tx_work = 0, rx_work = 0;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003539
stephen hemminger81a2e362010-04-28 08:25:28 +00003540 do {
3541 if (!nv_optimized(np)) {
3542 spin_lock_irqsave(&np->lock, flags);
3543 tx_work += nv_tx_done(dev, np->tx_ring_size);
3544 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003545
Tom Herbertd951f722010-05-05 18:15:21 +00003546 rx_count = nv_rx_process(dev, budget - rx_work);
stephen hemminger81a2e362010-04-28 08:25:28 +00003547 retcode = nv_alloc_rx(dev);
3548 } else {
3549 spin_lock_irqsave(&np->lock, flags);
3550 tx_work += nv_tx_done_optimized(dev, np->tx_ring_size);
3551 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003552
Tom Herbertd951f722010-05-05 18:15:21 +00003553 rx_count = nv_rx_process_optimized(dev,
3554 budget - rx_work);
stephen hemminger81a2e362010-04-28 08:25:28 +00003555 retcode = nv_alloc_rx_optimized(dev);
3556 }
3557 } while (retcode == 0 &&
3558 rx_count > 0 && (rx_work += rx_count) < budget);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003559
Ayaz Abdullae0379a12007-02-20 03:34:30 -05003560 if (retcode) {
Francois Romieud15e9c42006-12-17 23:03:15 +01003561 spin_lock_irqsave(&np->lock, flags);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003562 if (!np->in_shutdown)
3563 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Francois Romieud15e9c42006-12-17 23:03:15 +01003564 spin_unlock_irqrestore(&np->lock, flags);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003565 }
3566
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003567 nv_change_interrupt_mode(dev, tx_work + rx_work);
3568
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003569 if (unlikely(np->events & NVREG_IRQ_LINK)) {
3570 spin_lock_irqsave(&np->lock, flags);
3571 nv_link_irq(dev);
3572 spin_unlock_irqrestore(&np->lock, flags);
3573 }
3574 if (unlikely(np->need_linktimer && time_after(jiffies, np->link_timeout))) {
3575 spin_lock_irqsave(&np->lock, flags);
3576 nv_linkchange(dev);
3577 spin_unlock_irqrestore(&np->lock, flags);
3578 np->link_timeout = jiffies + LINK_TIMEOUT;
3579 }
3580 if (unlikely(np->events & NVREG_IRQ_RECOVER_ERROR)) {
3581 spin_lock_irqsave(&np->lock, flags);
3582 if (!np->in_shutdown) {
3583 np->nic_poll_irq = np->irqmask;
3584 np->recover_error = 1;
3585 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3586 }
3587 spin_unlock_irqrestore(&np->lock, flags);
David S. Miller6c2da9c2009-04-09 01:09:33 -07003588 napi_complete(napi);
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003589 return rx_work;
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003590 }
3591
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003592 if (rx_work < budget) {
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003593 /* re-enable interrupts
3594 (msix not enabled in napi) */
David S. Miller6c2da9c2009-04-09 01:09:33 -07003595 napi_complete(napi);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003596
Ayaz Abdullaf27e6f32009-03-05 08:02:14 +00003597 writel(np->irqmask, base + NvRegIrqMask);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003598 }
Ayaz Abdulla4145ade2009-03-05 08:02:26 +00003599 return rx_work;
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003600}
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07003601
David Howells7d12e782006-10-05 14:55:46 +01003602static irqreturn_t nv_nic_irq_rx(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003603{
3604 struct net_device *dev = (struct net_device *) data;
3605 struct fe_priv *np = netdev_priv(dev);
3606 u8 __iomem *base = get_hwbase(dev);
3607 u32 events;
3608 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003609 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003610
3611 dprintk(KERN_DEBUG "%s: nv_nic_irq_rx\n", dev->name);
3612
Szymon Janc78aea4f2010-11-27 08:39:43 +00003613 for (i = 0;; i++) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003614 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
3615 writel(NVREG_IRQ_RX_ALL, base + NvRegMSIXIrqStatus);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003616 dprintk(KERN_DEBUG "%s: rx irq: %08x\n", dev->name, events);
3617 if (!(events & np->irqmask))
3618 break;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003619
Stephen Hemmingerbea33482007-10-03 16:41:36 -07003620 if (nv_rx_process_optimized(dev, RX_WORK_PER_LOOP)) {
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003621 if (unlikely(nv_alloc_rx_optimized(dev))) {
3622 spin_lock_irqsave(&np->lock, flags);
3623 if (!np->in_shutdown)
3624 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3625 spin_unlock_irqrestore(&np->lock, flags);
3626 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003627 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003628
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003629 if (unlikely(i > max_interrupt_work)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003630 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003631 /* disable interrupts on the nic */
3632 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
3633 pci_push(base);
3634
3635 if (!np->in_shutdown) {
3636 np->nic_poll_irq |= NVREG_IRQ_RX_ALL;
3637 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3638 }
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003639 spin_unlock_irqrestore(&np->lock, flags);
Timo Jantunen1a2b7332007-08-14 21:56:57 +03003640 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_rx.\n", dev->name, i);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003641 break;
3642 }
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003643 }
3644 dprintk(KERN_DEBUG "%s: nv_nic_irq_rx completed\n", dev->name);
3645
3646 return IRQ_RETVAL(i);
3647}
3648
David Howells7d12e782006-10-05 14:55:46 +01003649static irqreturn_t nv_nic_irq_other(int foo, void *data)
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003650{
3651 struct net_device *dev = (struct net_device *) data;
3652 struct fe_priv *np = netdev_priv(dev);
3653 u8 __iomem *base = get_hwbase(dev);
3654 u32 events;
3655 int i;
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003656 unsigned long flags;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003657
3658 dprintk(KERN_DEBUG "%s: nv_nic_irq_other\n", dev->name);
3659
Szymon Janc78aea4f2010-11-27 08:39:43 +00003660 for (i = 0;; i++) {
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003661 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_OTHER;
3662 writel(NVREG_IRQ_OTHER, base + NvRegMSIXIrqStatus);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003663 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
3664 if (!(events & np->irqmask))
3665 break;
Jeff Garzikf3b197a2006-05-26 21:39:03 -04003666
Ayaz Abdulla4e16ed12007-01-23 12:00:56 -05003667 /* check tx in case we reached max loop limit in tx isr */
3668 spin_lock_irqsave(&np->lock, flags);
3669 nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
3670 spin_unlock_irqrestore(&np->lock, flags);
3671
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003672 if (events & NVREG_IRQ_LINK) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003673 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003674 nv_link_irq(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003675 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003676 }
3677 if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003678 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003679 nv_linkchange(dev);
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003680 spin_unlock_irqrestore(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003681 np->link_timeout = jiffies + LINK_TIMEOUT;
3682 }
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003683 if (events & NVREG_IRQ_RECOVER_ERROR) {
3684 spin_lock_irq(&np->lock);
3685 /* disable interrupts on the nic */
3686 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
3687 pci_push(base);
3688
3689 if (!np->in_shutdown) {
3690 np->nic_poll_irq |= NVREG_IRQ_OTHER;
3691 np->recover_error = 1;
3692 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3693 }
3694 spin_unlock_irq(&np->lock);
3695 break;
3696 }
Ayaz Abdullaf0734ab2007-01-21 18:10:57 -05003697 if (unlikely(i > max_interrupt_work)) {
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003698 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003699 /* disable interrupts on the nic */
3700 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
3701 pci_push(base);
3702
3703 if (!np->in_shutdown) {
3704 np->nic_poll_irq |= NVREG_IRQ_OTHER;
3705 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3706 }
Peter Zijlstra0a07bc62006-09-19 14:55:22 +02003707 spin_unlock_irqrestore(&np->lock, flags);
Timo Jantunen1a2b7332007-08-14 21:56:57 +03003708 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_other.\n", dev->name, i);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003709 break;
3710 }
3711
3712 }
3713 dprintk(KERN_DEBUG "%s: nv_nic_irq_other completed\n", dev->name);
3714
3715 return IRQ_RETVAL(i);
3716}
3717
David Howells7d12e782006-10-05 14:55:46 +01003718static irqreturn_t nv_nic_irq_test(int foo, void *data)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003719{
3720 struct net_device *dev = (struct net_device *) data;
3721 struct fe_priv *np = netdev_priv(dev);
3722 u8 __iomem *base = get_hwbase(dev);
3723 u32 events;
3724
3725 dprintk(KERN_DEBUG "%s: nv_nic_irq_test\n", dev->name);
3726
3727 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3728 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
3729 writel(NVREG_IRQ_TIMER, base + NvRegIrqStatus);
3730 } else {
3731 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
3732 writel(NVREG_IRQ_TIMER, base + NvRegMSIXIrqStatus);
3733 }
3734 pci_push(base);
3735 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
3736 if (!(events & NVREG_IRQ_TIMER))
3737 return IRQ_RETVAL(0);
3738
Ayaz Abdulla4db0ee172008-06-09 16:51:06 -07003739 nv_msi_workaround(np);
3740
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003741 spin_lock(&np->lock);
3742 np->intr_test = 1;
3743 spin_unlock(&np->lock);
3744
3745 dprintk(KERN_DEBUG "%s: nv_nic_irq_test completed\n", dev->name);
3746
3747 return IRQ_RETVAL(1);
3748}
3749
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003750static void set_msix_vector_map(struct net_device *dev, u32 vector, u32 irqmask)
3751{
3752 u8 __iomem *base = get_hwbase(dev);
3753 int i;
3754 u32 msixmap = 0;
3755
3756 /* Each interrupt bit can be mapped to a MSIX vector (4 bits).
3757 * MSIXMap0 represents the first 8 interrupts and MSIXMap1 represents
3758 * the remaining 8 interrupts.
3759 */
3760 for (i = 0; i < 8; i++) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003761 if ((irqmask >> i) & 0x1)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003762 msixmap |= vector << (i << 2);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003763 }
3764 writel(readl(base + NvRegMSIXMap0) | msixmap, base + NvRegMSIXMap0);
3765
3766 msixmap = 0;
3767 for (i = 0; i < 8; i++) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003768 if ((irqmask >> (i + 8)) & 0x1)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003769 msixmap |= vector << (i << 2);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003770 }
3771 writel(readl(base + NvRegMSIXMap1) | msixmap, base + NvRegMSIXMap1);
3772}
3773
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003774static int nv_request_irq(struct net_device *dev, int intr_test)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003775{
3776 struct fe_priv *np = get_nvpriv(dev);
3777 u8 __iomem *base = get_hwbase(dev);
3778 int ret = 1;
3779 int i;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003780 irqreturn_t (*handler)(int foo, void *data);
3781
3782 if (intr_test) {
3783 handler = nv_nic_irq_test;
3784 } else {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04003785 if (nv_optimized(np))
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003786 handler = nv_nic_irq_optimized;
3787 else
3788 handler = nv_nic_irq;
3789 }
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003790
3791 if (np->msi_flags & NV_MSI_X_CAPABLE) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003792 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003793 np->msi_x_entry[i].entry = i;
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003794 if ((ret = pci_enable_msix(np->pci_dev, np->msi_x_entry, (np->msi_flags & NV_MSI_X_VECTORS_MASK))) == 0) {
3795 np->msi_flags |= NV_MSI_X_ENABLED;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003796 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT && !intr_test) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003797 /* Request irq for rx handling */
Yinghai Luddb213f2009-02-06 01:29:23 -08003798 sprintf(np->name_rx, "%s-rx", dev->name);
3799 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08003800 nv_nic_irq_rx, IRQF_SHARED, np->name_rx, dev) != 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003801 printk(KERN_INFO "forcedeth: request_irq failed for rx %d\n", ret);
3802 pci_disable_msix(np->pci_dev);
3803 np->msi_flags &= ~NV_MSI_X_ENABLED;
3804 goto out_err;
3805 }
3806 /* Request irq for tx handling */
Yinghai Luddb213f2009-02-06 01:29:23 -08003807 sprintf(np->name_tx, "%s-tx", dev->name);
3808 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08003809 nv_nic_irq_tx, IRQF_SHARED, np->name_tx, dev) != 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003810 printk(KERN_INFO "forcedeth: request_irq failed for tx %d\n", ret);
3811 pci_disable_msix(np->pci_dev);
3812 np->msi_flags &= ~NV_MSI_X_ENABLED;
3813 goto out_free_rx;
3814 }
3815 /* Request irq for link and timer handling */
Yinghai Luddb213f2009-02-06 01:29:23 -08003816 sprintf(np->name_other, "%s-other", dev->name);
3817 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector,
Joe Perchesa0607fd2009-11-18 23:29:17 -08003818 nv_nic_irq_other, IRQF_SHARED, np->name_other, dev) != 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003819 printk(KERN_INFO "forcedeth: request_irq failed for link %d\n", ret);
3820 pci_disable_msix(np->pci_dev);
3821 np->msi_flags &= ~NV_MSI_X_ENABLED;
3822 goto out_free_tx;
3823 }
3824 /* map interrupts to their respective vector */
3825 writel(0, base + NvRegMSIXMap0);
3826 writel(0, base + NvRegMSIXMap1);
3827 set_msix_vector_map(dev, NV_MSI_X_VECTOR_RX, NVREG_IRQ_RX_ALL);
3828 set_msix_vector_map(dev, NV_MSI_X_VECTOR_TX, NVREG_IRQ_TX_ALL);
3829 set_msix_vector_map(dev, NV_MSI_X_VECTOR_OTHER, NVREG_IRQ_OTHER);
3830 } else {
3831 /* Request irq for all interrupts */
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003832 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector, handler, IRQF_SHARED, dev->name, dev) != 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003833 printk(KERN_INFO "forcedeth: request_irq failed %d\n", ret);
3834 pci_disable_msix(np->pci_dev);
3835 np->msi_flags &= ~NV_MSI_X_ENABLED;
3836 goto out_err;
3837 }
3838
3839 /* map interrupts to vector 0 */
3840 writel(0, base + NvRegMSIXMap0);
3841 writel(0, base + NvRegMSIXMap1);
3842 }
3843 }
3844 }
3845 if (ret != 0 && np->msi_flags & NV_MSI_CAPABLE) {
3846 if ((ret = pci_enable_msi(np->pci_dev)) == 0) {
3847 np->msi_flags |= NV_MSI_ENABLED;
Manfred Spraula7475902007-10-17 21:52:33 +02003848 dev->irq = np->pci_dev->irq;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003849 if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0) {
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003850 printk(KERN_INFO "forcedeth: request_irq failed %d\n", ret);
3851 pci_disable_msi(np->pci_dev);
3852 np->msi_flags &= ~NV_MSI_ENABLED;
Manfred Spraula7475902007-10-17 21:52:33 +02003853 dev->irq = np->pci_dev->irq;
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003854 goto out_err;
3855 }
3856
3857 /* map interrupts to vector 0 */
3858 writel(0, base + NvRegMSIMap0);
3859 writel(0, base + NvRegMSIMap1);
3860 /* enable msi vector 0 */
3861 writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask);
3862 }
3863 }
3864 if (ret != 0) {
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05003865 if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003866 goto out_err;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04003867
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003868 }
3869
3870 return 0;
3871out_free_tx:
3872 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector, dev);
3873out_free_rx:
3874 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector, dev);
3875out_err:
3876 return 1;
3877}
3878
3879static void nv_free_irq(struct net_device *dev)
3880{
3881 struct fe_priv *np = get_nvpriv(dev);
3882 int i;
3883
3884 if (np->msi_flags & NV_MSI_X_ENABLED) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00003885 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++)
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003886 free_irq(np->msi_x_entry[i].vector, dev);
Ayaz Abdulla7a1854b2006-06-10 22:48:08 -04003887 pci_disable_msix(np->pci_dev);
3888 np->msi_flags &= ~NV_MSI_X_ENABLED;
3889 } else {
3890 free_irq(np->pci_dev->irq, dev);
3891 if (np->msi_flags & NV_MSI_ENABLED) {
3892 pci_disable_msi(np->pci_dev);
3893 np->msi_flags &= ~NV_MSI_ENABLED;
3894 }
3895 }
3896}
3897
Linus Torvalds1da177e2005-04-16 15:20:36 -07003898static void nv_do_nic_poll(unsigned long data)
3899{
3900 struct net_device *dev = (struct net_device *) data;
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04003901 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003902 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003903 u32 mask = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003904
Linus Torvalds1da177e2005-04-16 15:20:36 -07003905 /*
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003906 * First disable irq(s) and then
Linus Torvalds1da177e2005-04-16 15:20:36 -07003907 * reenable interrupts on the nic, we have to do this before calling
3908 * nv_nic_irq because that may decide to do otherwise
3909 */
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003910
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003911 if (!using_multi_irqs(dev)) {
3912 if (np->msi_flags & NV_MSI_X_ENABLED)
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003913 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003914 else
Manfred Spraula7475902007-10-17 21:52:33 +02003915 disable_irq_lockdep(np->pci_dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003916 mask = np->irqmask;
3917 } else {
3918 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003919 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003920 mask |= NVREG_IRQ_RX_ALL;
3921 }
3922 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003923 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003924 mask |= NVREG_IRQ_TX_ALL;
3925 }
3926 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003927 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003928 mask |= NVREG_IRQ_OTHER;
3929 }
3930 }
Manfred Spraula7475902007-10-17 21:52:33 +02003931 /* disable_irq() contains synchronize_irq, thus no irq handler can run now */
3932
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003933 if (np->recover_error) {
3934 np->recover_error = 0;
Ayaz Abdulladaa91a92009-02-07 00:25:00 -08003935 printk(KERN_INFO "%s: MAC in recoverable error state\n", dev->name);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003936 if (netif_running(dev)) {
3937 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07003938 netif_addr_lock(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003939 spin_lock(&np->lock);
3940 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04003941 nv_stop_rxtx(dev);
Ayaz Abdulladaa91a92009-02-07 00:25:00 -08003942 if (np->driver_data & DEV_HAS_POWER_CNTRL)
3943 nv_mac_reset(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003944 nv_txrx_reset(dev);
3945 /* drain rx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04003946 nv_drain_rxtx(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003947 /* reinit driver view of the rx queue */
3948 set_bufsize(dev);
3949 if (nv_init_ring(dev)) {
3950 if (!np->in_shutdown)
3951 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3952 }
3953 /* reinit nic view of the rx queue */
3954 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
3955 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00003956 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003957 base + NvRegRingSizes);
3958 pci_push(base);
3959 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
3960 pci_push(base);
Ayaz Abdulladaa91a92009-02-07 00:25:00 -08003961 /* clear interrupts */
3962 if (!(np->msi_flags & NV_MSI_X_ENABLED))
3963 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
3964 else
3965 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003966
3967 /* restart rx engine */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04003968 nv_start_rxtx(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003969 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07003970 netif_addr_unlock(dev);
Ayaz Abdullac5cf9102006-10-30 17:32:01 -05003971 netif_tx_unlock_bh(dev);
3972 }
3973 }
3974
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003975 writel(mask, base + NvRegIrqMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003976 pci_push(base);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003977
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003978 if (!using_multi_irqs(dev)) {
Yinghai Lu79d30a52009-02-06 01:30:01 -08003979 np->nic_poll_irq = 0;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04003980 if (nv_optimized(np))
Ayaz Abdullafcc5f262007-03-23 05:49:37 -05003981 nv_nic_irq_optimized(0, dev);
3982 else
3983 nv_nic_irq(0, dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003984 if (np->msi_flags & NV_MSI_X_ENABLED)
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003985 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07003986 else
Manfred Spraula7475902007-10-17 21:52:33 +02003987 enable_irq_lockdep(np->pci_dev->irq);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003988 } else {
3989 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
Yinghai Lu79d30a52009-02-06 01:30:01 -08003990 np->nic_poll_irq &= ~NVREG_IRQ_RX_ALL;
David Howells7d12e782006-10-05 14:55:46 +01003991 nv_nic_irq_rx(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003992 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003993 }
3994 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
Yinghai Lu79d30a52009-02-06 01:30:01 -08003995 np->nic_poll_irq &= ~NVREG_IRQ_TX_ALL;
David Howells7d12e782006-10-05 14:55:46 +01003996 nv_nic_irq_tx(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07003997 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05003998 }
3999 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
Yinghai Lu79d30a52009-02-06 01:30:01 -08004000 np->nic_poll_irq &= ~NVREG_IRQ_OTHER;
David Howells7d12e782006-10-05 14:55:46 +01004001 nv_nic_irq_other(0, dev);
Ingo Molnar8688cfc2006-07-03 00:25:39 -07004002 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05004003 }
4004 }
Yinghai Lu79d30a52009-02-06 01:30:01 -08004005
Linus Torvalds1da177e2005-04-16 15:20:36 -07004006}
4007
Michal Schmidt2918c352005-05-12 19:42:06 -04004008#ifdef CONFIG_NET_POLL_CONTROLLER
4009static void nv_poll_controller(struct net_device *dev)
4010{
4011 nv_do_nic_poll((unsigned long) dev);
4012}
4013#endif
4014
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004015static void nv_do_stats_poll(unsigned long data)
4016{
4017 struct net_device *dev = (struct net_device *) data;
4018 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004019
Ayaz Abdulla57fff692007-01-23 12:27:00 -05004020 nv_get_hw_stats(dev);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004021
4022 if (!np->in_shutdown)
Daniel Drakebfebbb82008-03-18 11:07:18 +00004023 mod_timer(&np->stats_poll,
4024 round_jiffies(jiffies + STATS_INTERVAL));
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004025}
4026
Linus Torvalds1da177e2005-04-16 15:20:36 -07004027static void nv_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
4028{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004029 struct fe_priv *np = netdev_priv(dev);
Jeff Garzik3f88ce42007-10-16 04:09:09 -04004030 strcpy(info->driver, DRV_NAME);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004031 strcpy(info->version, FORCEDETH_VERSION);
4032 strcpy(info->bus_info, pci_name(np->pci_dev));
4033}
4034
4035static void nv_get_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
4036{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004037 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004038 wolinfo->supported = WAKE_MAGIC;
4039
4040 spin_lock_irq(&np->lock);
4041 if (np->wolenabled)
4042 wolinfo->wolopts = WAKE_MAGIC;
4043 spin_unlock_irq(&np->lock);
4044}
4045
4046static int nv_set_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
4047{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004048 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004049 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004050 u32 flags = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004051
Linus Torvalds1da177e2005-04-16 15:20:36 -07004052 if (wolinfo->wolopts == 0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004053 np->wolenabled = 0;
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004054 } else if (wolinfo->wolopts & WAKE_MAGIC) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004055 np->wolenabled = 1;
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004056 flags = NVREG_WAKEUPFLAGS_ENABLE;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004057 }
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04004058 if (netif_running(dev)) {
4059 spin_lock_irq(&np->lock);
4060 writel(flags, base + NvRegWakeUpFlags);
4061 spin_unlock_irq(&np->lock);
4062 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004063 return 0;
4064}
4065
4066static int nv_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
4067{
4068 struct fe_priv *np = netdev_priv(dev);
4069 int adv;
4070
4071 spin_lock_irq(&np->lock);
4072 ecmd->port = PORT_MII;
4073 if (!netif_running(dev)) {
4074 /* We do not track link speed / duplex setting if the
4075 * interface is disabled. Force a link check */
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004076 if (nv_update_linkspeed(dev)) {
4077 if (!netif_carrier_ok(dev))
4078 netif_carrier_on(dev);
4079 } else {
4080 if (netif_carrier_ok(dev))
4081 netif_carrier_off(dev);
4082 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004083 }
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004084
4085 if (netif_carrier_ok(dev)) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00004086 switch (np->linkspeed & (NVREG_LINKSPEED_MASK)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07004087 case NVREG_LINKSPEED_10:
4088 ecmd->speed = SPEED_10;
4089 break;
4090 case NVREG_LINKSPEED_100:
4091 ecmd->speed = SPEED_100;
4092 break;
4093 case NVREG_LINKSPEED_1000:
4094 ecmd->speed = SPEED_1000;
4095 break;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004096 }
4097 ecmd->duplex = DUPLEX_HALF;
4098 if (np->duplex)
4099 ecmd->duplex = DUPLEX_FULL;
4100 } else {
4101 ecmd->speed = -1;
4102 ecmd->duplex = -1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004103 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004104
4105 ecmd->autoneg = np->autoneg;
4106
4107 ecmd->advertising = ADVERTISED_MII;
4108 if (np->autoneg) {
4109 ecmd->advertising |= ADVERTISED_Autoneg;
4110 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004111 if (adv & ADVERTISE_10HALF)
4112 ecmd->advertising |= ADVERTISED_10baseT_Half;
4113 if (adv & ADVERTISE_10FULL)
4114 ecmd->advertising |= ADVERTISED_10baseT_Full;
4115 if (adv & ADVERTISE_100HALF)
4116 ecmd->advertising |= ADVERTISED_100baseT_Half;
4117 if (adv & ADVERTISE_100FULL)
4118 ecmd->advertising |= ADVERTISED_100baseT_Full;
4119 if (np->gigabit == PHY_GIGABIT) {
4120 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
4121 if (adv & ADVERTISE_1000FULL)
4122 ecmd->advertising |= ADVERTISED_1000baseT_Full;
4123 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004124 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004125 ecmd->supported = (SUPPORTED_Autoneg |
4126 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
4127 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
4128 SUPPORTED_MII);
4129 if (np->gigabit == PHY_GIGABIT)
4130 ecmd->supported |= SUPPORTED_1000baseT_Full;
4131
4132 ecmd->phy_address = np->phyaddr;
4133 ecmd->transceiver = XCVR_EXTERNAL;
4134
4135 /* ignore maxtxpkt, maxrxpkt for now */
4136 spin_unlock_irq(&np->lock);
4137 return 0;
4138}
4139
4140static int nv_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
4141{
4142 struct fe_priv *np = netdev_priv(dev);
4143
4144 if (ecmd->port != PORT_MII)
4145 return -EINVAL;
4146 if (ecmd->transceiver != XCVR_EXTERNAL)
4147 return -EINVAL;
4148 if (ecmd->phy_address != np->phyaddr) {
4149 /* TODO: support switching between multiple phys. Should be
4150 * trivial, but not enabled due to lack of test hardware. */
4151 return -EINVAL;
4152 }
4153 if (ecmd->autoneg == AUTONEG_ENABLE) {
4154 u32 mask;
4155
4156 mask = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
4157 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full;
4158 if (np->gigabit == PHY_GIGABIT)
4159 mask |= ADVERTISED_1000baseT_Full;
4160
4161 if ((ecmd->advertising & mask) == 0)
4162 return -EINVAL;
4163
4164 } else if (ecmd->autoneg == AUTONEG_DISABLE) {
4165 /* Note: autonegotiation disable, speed 1000 intentionally
4166 * forbidden - noone should need that. */
4167
4168 if (ecmd->speed != SPEED_10 && ecmd->speed != SPEED_100)
4169 return -EINVAL;
4170 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
4171 return -EINVAL;
4172 } else {
4173 return -EINVAL;
4174 }
4175
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004176 netif_carrier_off(dev);
4177 if (netif_running(dev)) {
Tobias Diedrich97bff092008-07-03 23:54:56 -07004178 unsigned long flags;
4179
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004180 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004181 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004182 netif_addr_lock(dev);
Tobias Diedrich97bff092008-07-03 23:54:56 -07004183 /* with plain spinlock lockdep complains */
4184 spin_lock_irqsave(&np->lock, flags);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004185 /* stop engines */
Tobias Diedrich97bff092008-07-03 23:54:56 -07004186 /* FIXME:
4187 * this can take some time, and interrupts are disabled
4188 * due to spin_lock_irqsave, but let's hope no daemon
4189 * is going to change the settings very often...
4190 * Worst case:
4191 * NV_RXSTOP_DELAY1MAX + NV_TXSTOP_DELAY1MAX
4192 * + some minor delays, which is up to a second approximately
4193 */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004194 nv_stop_rxtx(dev);
Tobias Diedrich97bff092008-07-03 23:54:56 -07004195 spin_unlock_irqrestore(&np->lock, flags);
David S. Millere308a5d2008-07-15 00:13:44 -07004196 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004197 netif_tx_unlock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004198 }
4199
Linus Torvalds1da177e2005-04-16 15:20:36 -07004200 if (ecmd->autoneg == AUTONEG_ENABLE) {
4201 int adv, bmcr;
4202
4203 np->autoneg = 1;
4204
4205 /* advertise only what has been requested */
4206 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004207 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004208 if (ecmd->advertising & ADVERTISED_10baseT_Half)
4209 adv |= ADVERTISE_10HALF;
4210 if (ecmd->advertising & ADVERTISED_10baseT_Full)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004211 adv |= ADVERTISE_10FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004212 if (ecmd->advertising & ADVERTISED_100baseT_Half)
4213 adv |= ADVERTISE_100HALF;
4214 if (ecmd->advertising & ADVERTISED_100baseT_Full)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004215 adv |= ADVERTISE_100FULL;
4216 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisments but disable tx pause */
4217 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4218 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
4219 adv |= ADVERTISE_PAUSE_ASYM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004220 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4221
4222 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004223 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004224 adv &= ~ADVERTISE_1000FULL;
4225 if (ecmd->advertising & ADVERTISED_1000baseT_Full)
4226 adv |= ADVERTISE_1000FULL;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004227 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004228 }
4229
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004230 if (netif_running(dev))
4231 printk(KERN_INFO "%s: link down.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004232 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004233 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
4234 bmcr |= BMCR_ANENABLE;
4235 /* reset the phy in order for settings to stick,
4236 * and cause autoneg to start */
4237 if (phy_reset(dev, bmcr)) {
4238 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
4239 return -EINVAL;
4240 }
4241 } else {
4242 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4243 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4244 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004245 } else {
4246 int adv, bmcr;
4247
4248 np->autoneg = 0;
4249
4250 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004251 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004252 if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_HALF)
4253 adv |= ADVERTISE_10HALF;
4254 if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_FULL)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004255 adv |= ADVERTISE_10FULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07004256 if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_HALF)
4257 adv |= ADVERTISE_100HALF;
4258 if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_FULL)
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004259 adv |= ADVERTISE_100FULL;
4260 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
4261 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) {/* for rx we set both advertisments but disable tx pause */
4262 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4263 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
4264 }
4265 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) {
4266 adv |= ADVERTISE_PAUSE_ASYM;
4267 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
4268 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004269 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4270 np->fixed_mode = adv;
4271
4272 if (np->gigabit == PHY_GIGABIT) {
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004273 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004274 adv &= ~ADVERTISE_1000FULL;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04004275 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
Linus Torvalds1da177e2005-04-16 15:20:36 -07004276 }
4277
4278 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004279 bmcr &= ~(BMCR_ANENABLE|BMCR_SPEED100|BMCR_SPEED1000|BMCR_FULLDPLX);
4280 if (np->fixed_mode & (ADVERTISE_10FULL|ADVERTISE_100FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004281 bmcr |= BMCR_FULLDPLX;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004282 if (np->fixed_mode & (ADVERTISE_100HALF|ADVERTISE_100FULL))
Linus Torvalds1da177e2005-04-16 15:20:36 -07004283 bmcr |= BMCR_SPEED100;
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004284 if (np->phy_oui == PHY_OUI_MARVELL) {
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004285 /* reset the phy in order for forced mode settings to stick */
4286 if (phy_reset(dev, bmcr)) {
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004287 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
4288 return -EINVAL;
4289 }
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004290 } else {
4291 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4292 if (netif_running(dev)) {
4293 /* Wait a bit and then reconfigure the nic. */
4294 udelay(10);
4295 nv_linkchange(dev);
4296 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004297 }
4298 }
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004299
4300 if (netif_running(dev)) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004301 nv_start_rxtx(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004302 nv_enable_irq(dev);
4303 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07004304
4305 return 0;
4306}
4307
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004308#define FORCEDETH_REGS_VER 1
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004309
4310static int nv_get_regs_len(struct net_device *dev)
4311{
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04004312 struct fe_priv *np = netdev_priv(dev);
4313 return np->register_size;
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004314}
4315
4316static void nv_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *buf)
4317{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004318 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004319 u8 __iomem *base = get_hwbase(dev);
4320 u32 *rbuf = buf;
4321 int i;
4322
4323 regs->version = FORCEDETH_REGS_VER;
4324 spin_lock_irq(&np->lock);
Szymon Janc78aea4f2010-11-27 08:39:43 +00004325 for (i = 0; i <= np->register_size/sizeof(u32); i++)
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004326 rbuf[i] = readl(base + i*sizeof(u32));
4327 spin_unlock_irq(&np->lock);
4328}
4329
4330static int nv_nway_reset(struct net_device *dev)
4331{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04004332 struct fe_priv *np = netdev_priv(dev);
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004333 int ret;
4334
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004335 if (np->autoneg) {
4336 int bmcr;
4337
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004338 netif_carrier_off(dev);
4339 if (netif_running(dev)) {
4340 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004341 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004342 netif_addr_lock(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004343 spin_lock(&np->lock);
4344 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004345 nv_stop_rxtx(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004346 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07004347 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004348 netif_tx_unlock_bh(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004349 printk(KERN_INFO "%s: link down.\n", dev->name);
4350 }
4351
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004352 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04004353 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
4354 bmcr |= BMCR_ANENABLE;
4355 /* reset the phy in order for settings to stick*/
4356 if (phy_reset(dev, bmcr)) {
4357 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
4358 return -EINVAL;
4359 }
4360 } else {
4361 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4362 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4363 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004364
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004365 if (netif_running(dev)) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004366 nv_start_rxtx(dev);
Ayaz Abdullaf9430a02006-06-10 22:47:47 -04004367 nv_enable_irq(dev);
4368 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004369 ret = 0;
4370 } else {
4371 ret = -EINVAL;
4372 }
Manfred Sprauldc8216c2005-07-31 18:26:05 +02004373
4374 return ret;
4375}
4376
Zachary Amsden0674d592006-06-04 02:51:38 -07004377static int nv_set_tso(struct net_device *dev, u32 value)
4378{
4379 struct fe_priv *np = netdev_priv(dev);
4380
4381 if ((np->driver_data & DEV_HAS_CHECKSUM))
4382 return ethtool_op_set_tso(dev, value);
4383 else
Ayaz Abdulla6a788142006-06-10 22:47:26 -04004384 return -EOPNOTSUPP;
Zachary Amsden0674d592006-06-04 02:51:38 -07004385}
Zachary Amsden0674d592006-06-04 02:51:38 -07004386
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004387static void nv_get_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
4388{
4389 struct fe_priv *np = netdev_priv(dev);
4390
4391 ring->rx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
4392 ring->rx_mini_max_pending = 0;
4393 ring->rx_jumbo_max_pending = 0;
4394 ring->tx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
4395
4396 ring->rx_pending = np->rx_ring_size;
4397 ring->rx_mini_pending = 0;
4398 ring->rx_jumbo_pending = 0;
4399 ring->tx_pending = np->tx_ring_size;
4400}
4401
4402static int nv_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
4403{
4404 struct fe_priv *np = netdev_priv(dev);
4405 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004406 u8 *rxtx_ring, *rx_skbuff, *tx_skbuff;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004407 dma_addr_t ring_addr;
4408
4409 if (ring->rx_pending < RX_RING_MIN ||
4410 ring->tx_pending < TX_RING_MIN ||
4411 ring->rx_mini_pending != 0 ||
4412 ring->rx_jumbo_pending != 0 ||
4413 (np->desc_ver == DESC_VER_1 &&
4414 (ring->rx_pending > RING_MAX_DESC_VER_1 ||
4415 ring->tx_pending > RING_MAX_DESC_VER_1)) ||
4416 (np->desc_ver != DESC_VER_1 &&
4417 (ring->rx_pending > RING_MAX_DESC_VER_2_3 ||
4418 ring->tx_pending > RING_MAX_DESC_VER_2_3))) {
4419 return -EINVAL;
4420 }
4421
4422 /* allocate new rings */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004423 if (!nv_optimized(np)) {
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004424 rxtx_ring = pci_alloc_consistent(np->pci_dev,
4425 sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
4426 &ring_addr);
4427 } else {
4428 rxtx_ring = pci_alloc_consistent(np->pci_dev,
4429 sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
4430 &ring_addr);
4431 }
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004432 rx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->rx_pending, GFP_KERNEL);
4433 tx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->tx_pending, GFP_KERNEL);
4434 if (!rxtx_ring || !rx_skbuff || !tx_skbuff) {
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004435 /* fall back to old rings */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004436 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004437 if (rxtx_ring)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004438 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
4439 rxtx_ring, ring_addr);
4440 } else {
4441 if (rxtx_ring)
4442 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
4443 rxtx_ring, ring_addr);
4444 }
4445 if (rx_skbuff)
4446 kfree(rx_skbuff);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004447 if (tx_skbuff)
4448 kfree(tx_skbuff);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004449 goto exit;
4450 }
4451
4452 if (netif_running(dev)) {
4453 nv_disable_irq(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00004454 nv_napi_disable(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004455 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004456 netif_addr_lock(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004457 spin_lock(&np->lock);
4458 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004459 nv_stop_rxtx(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004460 nv_txrx_reset(dev);
4461 /* drain queues */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004462 nv_drain_rxtx(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004463 /* delete queues */
4464 free_rings(dev);
4465 }
4466
4467 /* set new values */
4468 np->rx_ring_size = ring->rx_pending;
4469 np->tx_ring_size = ring->tx_pending;
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004470
4471 if (!nv_optimized(np)) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00004472 np->rx_ring.orig = (struct ring_desc *)rxtx_ring;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004473 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
4474 } else {
Szymon Janc78aea4f2010-11-27 08:39:43 +00004475 np->rx_ring.ex = (struct ring_desc_ex *)rxtx_ring;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004476 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
4477 }
Szymon Janc78aea4f2010-11-27 08:39:43 +00004478 np->rx_skb = (struct nv_skb_map *)rx_skbuff;
4479 np->tx_skb = (struct nv_skb_map *)tx_skbuff;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004480 np->ring_addr = ring_addr;
4481
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004482 memset(np->rx_skb, 0, sizeof(struct nv_skb_map) * np->rx_ring_size);
4483 memset(np->tx_skb, 0, sizeof(struct nv_skb_map) * np->tx_ring_size);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004484
4485 if (netif_running(dev)) {
4486 /* reinit driver view of the queues */
4487 set_bufsize(dev);
4488 if (nv_init_ring(dev)) {
4489 if (!np->in_shutdown)
4490 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
4491 }
4492
4493 /* reinit nic view of the queues */
4494 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4495 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00004496 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004497 base + NvRegRingSizes);
4498 pci_push(base);
4499 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4500 pci_push(base);
4501
4502 /* restart engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004503 nv_start_rxtx(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004504 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07004505 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004506 netif_tx_unlock_bh(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00004507 nv_napi_enable(dev);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04004508 nv_enable_irq(dev);
4509 }
4510 return 0;
4511exit:
4512 return -ENOMEM;
4513}
4514
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004515static void nv_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
4516{
4517 struct fe_priv *np = netdev_priv(dev);
4518
4519 pause->autoneg = (np->pause_flags & NV_PAUSEFRAME_AUTONEG) != 0;
4520 pause->rx_pause = (np->pause_flags & NV_PAUSEFRAME_RX_ENABLE) != 0;
4521 pause->tx_pause = (np->pause_flags & NV_PAUSEFRAME_TX_ENABLE) != 0;
4522}
4523
4524static int nv_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
4525{
4526 struct fe_priv *np = netdev_priv(dev);
4527 int adv, bmcr;
4528
4529 if ((!np->autoneg && np->duplex == 0) ||
4530 (np->autoneg && !pause->autoneg && np->duplex == 0)) {
4531 printk(KERN_INFO "%s: can not set pause settings when forced link is in half duplex.\n",
4532 dev->name);
4533 return -EINVAL;
4534 }
4535 if (pause->tx_pause && !(np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)) {
4536 printk(KERN_INFO "%s: hardware does not support tx pause frames.\n", dev->name);
4537 return -EINVAL;
4538 }
4539
4540 netif_carrier_off(dev);
4541 if (netif_running(dev)) {
4542 nv_disable_irq(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004543 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004544 netif_addr_lock(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004545 spin_lock(&np->lock);
4546 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004547 nv_stop_rxtx(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004548 spin_unlock(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07004549 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004550 netif_tx_unlock_bh(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004551 }
4552
4553 np->pause_flags &= ~(NV_PAUSEFRAME_RX_REQ|NV_PAUSEFRAME_TX_REQ);
4554 if (pause->rx_pause)
4555 np->pause_flags |= NV_PAUSEFRAME_RX_REQ;
4556 if (pause->tx_pause)
4557 np->pause_flags |= NV_PAUSEFRAME_TX_REQ;
4558
4559 if (np->autoneg && pause->autoneg) {
4560 np->pause_flags |= NV_PAUSEFRAME_AUTONEG;
4561
4562 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
4563 adv &= ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
4564 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisments but disable tx pause */
4565 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4566 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
4567 adv |= ADVERTISE_PAUSE_ASYM;
4568 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4569
4570 if (netif_running(dev))
4571 printk(KERN_INFO "%s: link down.\n", dev->name);
4572 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
4573 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4574 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4575 } else {
4576 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
4577 if (pause->rx_pause)
4578 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
4579 if (pause->tx_pause)
4580 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
4581
4582 if (!netif_running(dev))
4583 nv_update_linkspeed(dev);
4584 else
4585 nv_update_pause(dev, np->pause_flags);
4586 }
4587
4588 if (netif_running(dev)) {
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004589 nv_start_rxtx(dev);
Ayaz Abdullab6d07732006-06-10 22:47:42 -04004590 nv_enable_irq(dev);
4591 }
4592 return 0;
4593}
4594
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004595static u32 nv_get_rx_csum(struct net_device *dev)
4596{
4597 struct fe_priv *np = netdev_priv(dev);
Eric Dumazet807540b2010-09-23 05:40:09 +00004598 return np->rx_csum != 0;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004599}
4600
4601static int nv_set_rx_csum(struct net_device *dev, u32 data)
4602{
4603 struct fe_priv *np = netdev_priv(dev);
4604 u8 __iomem *base = get_hwbase(dev);
4605 int retcode = 0;
4606
4607 if (np->driver_data & DEV_HAS_CHECKSUM) {
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004608 if (data) {
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04004609 np->rx_csum = 1;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004610 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004611 } else {
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04004612 np->rx_csum = 0;
4613 /* vlan is dependent on rx checksum offload */
4614 if (!(np->vlanctl_bits & NVREG_VLANCONTROL_ENABLE))
4615 np->txrxctl_bits &= ~NVREG_TXRXCTL_RXCHECK;
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004616 }
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004617 if (netif_running(dev)) {
4618 spin_lock_irq(&np->lock);
4619 writel(np->txrxctl_bits, base + NvRegTxRxControl);
4620 spin_unlock_irq(&np->lock);
4621 }
4622 } else {
4623 return -EINVAL;
4624 }
4625
4626 return retcode;
4627}
4628
4629static int nv_set_tx_csum(struct net_device *dev, u32 data)
4630{
4631 struct fe_priv *np = netdev_priv(dev);
4632
4633 if (np->driver_data & DEV_HAS_CHECKSUM)
Ayaz Abdullac1086cd2009-02-07 00:24:39 -08004634 return ethtool_op_set_tx_csum(dev, data);
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04004635 else
4636 return -EOPNOTSUPP;
4637}
4638
4639static int nv_set_sg(struct net_device *dev, u32 data)
4640{
4641 struct fe_priv *np = netdev_priv(dev);
4642
4643 if (np->driver_data & DEV_HAS_CHECKSUM)
4644 return ethtool_op_set_sg(dev, data);
4645 else
4646 return -EOPNOTSUPP;
4647}
4648
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004649static int nv_get_sset_count(struct net_device *dev, int sset)
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004650{
4651 struct fe_priv *np = netdev_priv(dev);
4652
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004653 switch (sset) {
4654 case ETH_SS_TEST:
4655 if (np->driver_data & DEV_HAS_TEST_EXTENDED)
4656 return NV_TEST_COUNT_EXTENDED;
4657 else
4658 return NV_TEST_COUNT_BASE;
4659 case ETH_SS_STATS:
Ayaz Abdulla8ed14542009-03-05 08:01:49 +00004660 if (np->driver_data & DEV_HAS_STATISTICS_V3)
4661 return NV_DEV_STATISTICS_V3_COUNT;
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004662 else if (np->driver_data & DEV_HAS_STATISTICS_V2)
4663 return NV_DEV_STATISTICS_V2_COUNT;
Ayaz Abdulla8ed14542009-03-05 08:01:49 +00004664 else if (np->driver_data & DEV_HAS_STATISTICS_V1)
4665 return NV_DEV_STATISTICS_V1_COUNT;
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004666 else
4667 return 0;
4668 default:
4669 return -EOPNOTSUPP;
4670 }
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004671}
4672
4673static void nv_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *estats, u64 *buffer)
4674{
4675 struct fe_priv *np = netdev_priv(dev);
4676
4677 /* update stats */
4678 nv_do_stats_poll((unsigned long)dev);
4679
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004680 memcpy(buffer, &np->estats, nv_get_sset_count(dev, ETH_SS_STATS)*sizeof(u64));
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004681}
4682
4683static int nv_link_test(struct net_device *dev)
4684{
4685 struct fe_priv *np = netdev_priv(dev);
4686 int mii_status;
4687
4688 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
4689 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
4690
4691 /* check phy link status */
4692 if (!(mii_status & BMSR_LSTATUS))
4693 return 0;
4694 else
4695 return 1;
4696}
4697
4698static int nv_register_test(struct net_device *dev)
4699{
4700 u8 __iomem *base = get_hwbase(dev);
4701 int i = 0;
4702 u32 orig_read, new_read;
4703
4704 do {
4705 orig_read = readl(base + nv_registers_test[i].reg);
4706
4707 /* xor with mask to toggle bits */
4708 orig_read ^= nv_registers_test[i].mask;
4709
4710 writel(orig_read, base + nv_registers_test[i].reg);
4711
4712 new_read = readl(base + nv_registers_test[i].reg);
4713
4714 if ((new_read & nv_registers_test[i].mask) != (orig_read & nv_registers_test[i].mask))
4715 return 0;
4716
4717 /* restore original value */
4718 orig_read ^= nv_registers_test[i].mask;
4719 writel(orig_read, base + nv_registers_test[i].reg);
4720
4721 } while (nv_registers_test[++i].reg != 0);
4722
4723 return 1;
4724}
4725
4726static int nv_interrupt_test(struct net_device *dev)
4727{
4728 struct fe_priv *np = netdev_priv(dev);
4729 u8 __iomem *base = get_hwbase(dev);
4730 int ret = 1;
4731 int testcnt;
4732 u32 save_msi_flags, save_poll_interval = 0;
4733
4734 if (netif_running(dev)) {
4735 /* free current irq */
4736 nv_free_irq(dev);
4737 save_poll_interval = readl(base+NvRegPollingInterval);
4738 }
4739
4740 /* flag to test interrupt handler */
4741 np->intr_test = 0;
4742
4743 /* setup test irq */
4744 save_msi_flags = np->msi_flags;
4745 np->msi_flags &= ~NV_MSI_X_VECTORS_MASK;
4746 np->msi_flags |= 0x001; /* setup 1 vector */
4747 if (nv_request_irq(dev, 1))
4748 return 0;
4749
4750 /* setup timer interrupt */
4751 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
4752 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
4753
4754 nv_enable_hw_interrupts(dev, NVREG_IRQ_TIMER);
4755
4756 /* wait for at least one interrupt */
4757 msleep(100);
4758
4759 spin_lock_irq(&np->lock);
4760
4761 /* flag should be set within ISR */
4762 testcnt = np->intr_test;
4763 if (!testcnt)
4764 ret = 2;
4765
4766 nv_disable_hw_interrupts(dev, NVREG_IRQ_TIMER);
4767 if (!(np->msi_flags & NV_MSI_X_ENABLED))
4768 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4769 else
4770 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
4771
4772 spin_unlock_irq(&np->lock);
4773
4774 nv_free_irq(dev);
4775
4776 np->msi_flags = save_msi_flags;
4777
4778 if (netif_running(dev)) {
4779 writel(save_poll_interval, base + NvRegPollingInterval);
4780 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
4781 /* restore original irq */
4782 if (nv_request_irq(dev, 0))
4783 return 0;
4784 }
4785
4786 return ret;
4787}
4788
4789static int nv_loopback_test(struct net_device *dev)
4790{
4791 struct fe_priv *np = netdev_priv(dev);
4792 u8 __iomem *base = get_hwbase(dev);
4793 struct sk_buff *tx_skb, *rx_skb;
4794 dma_addr_t test_dma_addr;
4795 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004796 u32 flags;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004797 int len, i, pkt_len;
4798 u8 *pkt_data;
4799 u32 filter_flags = 0;
4800 u32 misc1_flags = 0;
4801 int ret = 1;
4802
4803 if (netif_running(dev)) {
4804 nv_disable_irq(dev);
4805 filter_flags = readl(base + NvRegPacketFilterFlags);
4806 misc1_flags = readl(base + NvRegMisc1);
4807 } else {
4808 nv_txrx_reset(dev);
4809 }
4810
4811 /* reinit driver view of the rx queue */
4812 set_bufsize(dev);
4813 nv_init_ring(dev);
4814
4815 /* setup hardware for loopback */
4816 writel(NVREG_MISC1_FORCE, base + NvRegMisc1);
4817 writel(NVREG_PFF_ALWAYS | NVREG_PFF_LOOPBACK, base + NvRegPacketFilterFlags);
4818
4819 /* reinit nic view of the rx queue */
4820 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4821 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00004822 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004823 base + NvRegRingSizes);
4824 pci_push(base);
4825
4826 /* restart rx engine */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004827 nv_start_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004828
4829 /* setup packet for tx */
4830 pkt_len = ETH_DATA_LEN;
4831 tx_skb = dev_alloc_skb(pkt_len);
Jesper Juhl46798c82006-09-25 16:39:24 -07004832 if (!tx_skb) {
4833 printk(KERN_ERR "dev_alloc_skb() failed during loopback test"
4834 " of %s\n", dev->name);
4835 ret = 0;
4836 goto out;
4837 }
Arnaldo Carvalho de Melo8b5be262007-03-20 12:08:20 -03004838 test_dma_addr = pci_map_single(np->pci_dev, tx_skb->data,
4839 skb_tailroom(tx_skb),
4840 PCI_DMA_FROMDEVICE);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004841 pkt_data = skb_put(tx_skb, pkt_len);
4842 for (i = 0; i < pkt_len; i++)
4843 pkt_data[i] = (u8)(i & 0xff);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004844
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004845 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004846 np->tx_ring.orig[0].buf = cpu_to_le32(test_dma_addr);
4847 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 -04004848 } else {
Al Viro5bb7ea22007-12-09 16:06:41 +00004849 np->tx_ring.ex[0].bufhigh = cpu_to_le32(dma_high(test_dma_addr));
4850 np->tx_ring.ex[0].buflow = cpu_to_le32(dma_low(test_dma_addr));
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004851 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 -04004852 }
4853 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4854 pci_push(get_hwbase(dev));
4855
4856 msleep(500);
4857
4858 /* check for rx of the packet */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004859 if (!nv_optimized(np)) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004860 flags = le32_to_cpu(np->rx_ring.orig[0].flaglen);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004861 len = nv_descr_getlength(&np->rx_ring.orig[0], np->desc_ver);
4862
4863 } else {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004864 flags = le32_to_cpu(np->rx_ring.ex[0].flaglen);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004865 len = nv_descr_getlength_ex(&np->rx_ring.ex[0], np->desc_ver);
4866 }
4867
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004868 if (flags & NV_RX_AVAIL) {
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004869 ret = 0;
4870 } else if (np->desc_ver == DESC_VER_1) {
Stephen Hemmingerf82a9352006-07-27 18:50:08 -07004871 if (flags & NV_RX_ERROR)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004872 ret = 0;
4873 } else {
Szymon Janc78aea4f2010-11-27 08:39:43 +00004874 if (flags & NV_RX2_ERROR)
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004875 ret = 0;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004876 }
4877
4878 if (ret) {
4879 if (len != pkt_len) {
4880 ret = 0;
4881 dprintk(KERN_DEBUG "%s: loopback len mismatch %d vs %d\n",
4882 dev->name, len, pkt_len);
4883 } else {
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05004884 rx_skb = np->rx_skb[0].skb;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004885 for (i = 0; i < pkt_len; i++) {
4886 if (rx_skb->data[i] != (u8)(i & 0xff)) {
4887 ret = 0;
4888 dprintk(KERN_DEBUG "%s: loopback pattern check failed on byte %d\n",
4889 dev->name, i);
4890 break;
4891 }
4892 }
4893 }
4894 } else {
4895 dprintk(KERN_DEBUG "%s: loopback - did not receive test packet\n", dev->name);
4896 }
4897
Eric Dumazet73a37072009-06-17 21:17:59 +00004898 pci_unmap_single(np->pci_dev, test_dma_addr,
Arnaldo Carvalho de Melo4305b542007-04-19 20:43:29 -07004899 (skb_end_pointer(tx_skb) - tx_skb->data),
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004900 PCI_DMA_TODEVICE);
4901 dev_kfree_skb_any(tx_skb);
Jesper Juhl46798c82006-09-25 16:39:24 -07004902 out:
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004903 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004904 nv_stop_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004905 nv_txrx_reset(dev);
4906 /* drain rx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004907 nv_drain_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004908
4909 if (netif_running(dev)) {
4910 writel(misc1_flags, base + NvRegMisc1);
4911 writel(filter_flags, base + NvRegPacketFilterFlags);
4912 nv_enable_irq(dev);
4913 }
4914
4915 return ret;
4916}
4917
4918static void nv_self_test(struct net_device *dev, struct ethtool_test *test, u64 *buffer)
4919{
4920 struct fe_priv *np = netdev_priv(dev);
4921 u8 __iomem *base = get_hwbase(dev);
4922 int result;
Jeff Garzikb9f2c042007-10-03 18:07:32 -07004923 memset(buffer, 0, nv_get_sset_count(dev, ETH_SS_TEST)*sizeof(u64));
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004924
4925 if (!nv_link_test(dev)) {
4926 test->flags |= ETH_TEST_FL_FAILED;
4927 buffer[0] = 1;
4928 }
4929
4930 if (test->flags & ETH_TEST_FL_OFFLINE) {
4931 if (netif_running(dev)) {
4932 netif_stop_queue(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00004933 nv_napi_disable(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004934 netif_tx_lock_bh(dev);
David S. Millere308a5d2008-07-15 00:13:44 -07004935 netif_addr_lock(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004936 spin_lock_irq(&np->lock);
4937 nv_disable_hw_interrupts(dev, np->irqmask);
Szymon Janc78aea4f2010-11-27 08:39:43 +00004938 if (!(np->msi_flags & NV_MSI_X_ENABLED))
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004939 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
Szymon Janc78aea4f2010-11-27 08:39:43 +00004940 else
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004941 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004942 /* stop engines */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004943 nv_stop_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004944 nv_txrx_reset(dev);
4945 /* drain rx queue */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004946 nv_drain_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004947 spin_unlock_irq(&np->lock);
David S. Millere308a5d2008-07-15 00:13:44 -07004948 netif_addr_unlock(dev);
Herbert Xu58dfd9c2006-06-21 10:53:54 +10004949 netif_tx_unlock_bh(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004950 }
4951
4952 if (!nv_register_test(dev)) {
4953 test->flags |= ETH_TEST_FL_FAILED;
4954 buffer[1] = 1;
4955 }
4956
4957 result = nv_interrupt_test(dev);
4958 if (result != 1) {
4959 test->flags |= ETH_TEST_FL_FAILED;
4960 buffer[2] = 1;
4961 }
4962 if (result == 0) {
4963 /* bail out */
4964 return;
4965 }
4966
4967 if (!nv_loopback_test(dev)) {
4968 test->flags |= ETH_TEST_FL_FAILED;
4969 buffer[3] = 1;
4970 }
4971
4972 if (netif_running(dev)) {
4973 /* reinit driver view of the rx queue */
4974 set_bufsize(dev);
4975 if (nv_init_ring(dev)) {
4976 if (!np->in_shutdown)
4977 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
4978 }
4979 /* reinit nic view of the rx queue */
4980 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4981 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00004982 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004983 base + NvRegRingSizes);
4984 pci_push(base);
4985 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4986 pci_push(base);
4987 /* restart rx engine */
Jeff Garzik36b30ea2007-10-16 01:40:30 -04004988 nv_start_rxtx(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004989 netif_start_queue(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00004990 nv_napi_enable(dev);
Ayaz Abdulla9589c772006-06-10 22:48:13 -04004991 nv_enable_hw_interrupts(dev, np->irqmask);
4992 }
4993 }
4994}
4995
Ayaz Abdulla52da3572006-06-10 22:48:04 -04004996static void nv_get_strings(struct net_device *dev, u32 stringset, u8 *buffer)
4997{
4998 switch (stringset) {
4999 case ETH_SS_STATS:
Jeff Garzikb9f2c042007-10-03 18:07:32 -07005000 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 -04005001 break;
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005002 case ETH_SS_TEST:
Jeff Garzikb9f2c042007-10-03 18:07:32 -07005003 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 -04005004 break;
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005005 }
5006}
5007
Jeff Garzik7282d492006-09-13 14:30:00 -04005008static const struct ethtool_ops ops = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005009 .get_drvinfo = nv_get_drvinfo,
5010 .get_link = ethtool_op_get_link,
5011 .get_wol = nv_get_wol,
5012 .set_wol = nv_set_wol,
5013 .get_settings = nv_get_settings,
5014 .set_settings = nv_set_settings,
Manfred Sprauldc8216c2005-07-31 18:26:05 +02005015 .get_regs_len = nv_get_regs_len,
5016 .get_regs = nv_get_regs,
5017 .nway_reset = nv_nway_reset,
Ayaz Abdulla6a788142006-06-10 22:47:26 -04005018 .set_tso = nv_set_tso,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005019 .get_ringparam = nv_get_ringparam,
5020 .set_ringparam = nv_set_ringparam,
Ayaz Abdullab6d07732006-06-10 22:47:42 -04005021 .get_pauseparam = nv_get_pauseparam,
5022 .set_pauseparam = nv_set_pauseparam,
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04005023 .get_rx_csum = nv_get_rx_csum,
5024 .set_rx_csum = nv_set_rx_csum,
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04005025 .set_tx_csum = nv_set_tx_csum,
Ayaz Abdulla5ed26162006-06-10 22:47:59 -04005026 .set_sg = nv_set_sg,
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005027 .get_strings = nv_get_strings,
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005028 .get_ethtool_stats = nv_get_ethtool_stats,
Jeff Garzikb9f2c042007-10-03 18:07:32 -07005029 .get_sset_count = nv_get_sset_count,
Ayaz Abdulla9589c772006-06-10 22:48:13 -04005030 .self_test = nv_self_test,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005031};
5032
Ayaz Abdullaee407b02006-02-04 13:13:17 -05005033static void nv_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
5034{
5035 struct fe_priv *np = get_nvpriv(dev);
5036
5037 spin_lock_irq(&np->lock);
5038
5039 /* save vlan group */
5040 np->vlangrp = grp;
5041
5042 if (grp) {
5043 /* enable vlan on MAC */
5044 np->txrxctl_bits |= NVREG_TXRXCTL_VLANSTRIP | NVREG_TXRXCTL_VLANINS;
5045 } else {
5046 /* disable vlan on MAC */
5047 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANSTRIP;
5048 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANINS;
5049 }
5050
5051 writel(np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
5052
5053 spin_unlock_irq(&np->lock);
Stephen Hemminger25805dc2007-06-01 09:44:01 -07005054}
Ayaz Abdullaee407b02006-02-04 13:13:17 -05005055
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005056/* The mgmt unit and driver use a semaphore to access the phy during init */
5057static int nv_mgmt_acquire_sema(struct net_device *dev)
5058{
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005059 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005060 u8 __iomem *base = get_hwbase(dev);
5061 int i;
5062 u32 tx_ctrl, mgmt_sema;
5063
5064 for (i = 0; i < 10; i++) {
5065 mgmt_sema = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_SEMA_MASK;
5066 if (mgmt_sema == NVREG_XMITCTL_MGMT_SEMA_FREE)
5067 break;
5068 msleep(500);
5069 }
5070
5071 if (mgmt_sema != NVREG_XMITCTL_MGMT_SEMA_FREE)
5072 return 0;
5073
5074 for (i = 0; i < 2; i++) {
5075 tx_ctrl = readl(base + NvRegTransmitterControl);
5076 tx_ctrl |= NVREG_XMITCTL_HOST_SEMA_ACQ;
5077 writel(tx_ctrl, base + NvRegTransmitterControl);
5078
5079 /* verify that semaphore was acquired */
5080 tx_ctrl = readl(base + NvRegTransmitterControl);
5081 if (((tx_ctrl & NVREG_XMITCTL_HOST_SEMA_MASK) == NVREG_XMITCTL_HOST_SEMA_ACQ) &&
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005082 ((tx_ctrl & NVREG_XMITCTL_MGMT_SEMA_MASK) == NVREG_XMITCTL_MGMT_SEMA_FREE)) {
5083 np->mgmt_sema = 1;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005084 return 1;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005085 } else
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005086 udelay(50);
5087 }
5088
5089 return 0;
5090}
5091
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005092static void nv_mgmt_release_sema(struct net_device *dev)
5093{
5094 struct fe_priv *np = netdev_priv(dev);
5095 u8 __iomem *base = get_hwbase(dev);
5096 u32 tx_ctrl;
5097
5098 if (np->driver_data & DEV_HAS_MGMT_UNIT) {
5099 if (np->mgmt_sema) {
5100 tx_ctrl = readl(base + NvRegTransmitterControl);
5101 tx_ctrl &= ~NVREG_XMITCTL_HOST_SEMA_ACQ;
5102 writel(tx_ctrl, base + NvRegTransmitterControl);
5103 }
5104 }
5105}
5106
5107
5108static int nv_mgmt_get_version(struct net_device *dev)
5109{
5110 struct fe_priv *np = netdev_priv(dev);
5111 u8 __iomem *base = get_hwbase(dev);
5112 u32 data_ready = readl(base + NvRegTransmitterControl);
5113 u32 data_ready2 = 0;
5114 unsigned long start;
5115 int ready = 0;
5116
5117 writel(NVREG_MGMTUNITGETVERSION, base + NvRegMgmtUnitGetVersion);
5118 writel(data_ready ^ NVREG_XMITCTL_DATA_START, base + NvRegTransmitterControl);
5119 start = jiffies;
5120 while (time_before(jiffies, start + 5*HZ)) {
5121 data_ready2 = readl(base + NvRegTransmitterControl);
5122 if ((data_ready & NVREG_XMITCTL_DATA_READY) != (data_ready2 & NVREG_XMITCTL_DATA_READY)) {
5123 ready = 1;
5124 break;
5125 }
5126 schedule_timeout_uninterruptible(1);
5127 }
5128
5129 if (!ready || (data_ready2 & NVREG_XMITCTL_DATA_ERROR))
5130 return 0;
5131
5132 np->mgmt_version = readl(base + NvRegMgmtUnitVersion) & NVREG_MGMTUNITVERSION;
5133
5134 return 1;
5135}
5136
Linus Torvalds1da177e2005-04-16 15:20:36 -07005137static int nv_open(struct net_device *dev)
5138{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005139 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005140 u8 __iomem *base = get_hwbase(dev);
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005141 int ret = 1;
5142 int oom, i;
Ayaz Abdullaa4336862008-04-18 13:50:43 -07005143 u32 low;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005144
5145 dprintk(KERN_DEBUG "nv_open: begin\n");
5146
Ed Swierkcb52deb2008-12-01 12:24:43 +00005147 /* power up phy */
5148 mii_rw(dev, np->phyaddr, MII_BMCR,
5149 mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ) & ~BMCR_PDOWN);
5150
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00005151 nv_txrx_gate(dev, false);
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005152 /* erase previous misconfiguration */
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005153 if (np->driver_data & DEV_HAS_POWER_CNTRL)
5154 nv_mac_reset(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005155 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
5156 writel(0, base + NvRegMulticastAddrB);
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -05005157 writel(NVREG_MCASTMASKA_NONE, base + NvRegMulticastMaskA);
5158 writel(NVREG_MCASTMASKB_NONE, base + NvRegMulticastMaskB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005159 writel(0, base + NvRegPacketFilterFlags);
5160
5161 writel(0, base + NvRegTransmitterControl);
5162 writel(0, base + NvRegReceiverControl);
5163
5164 writel(0, base + NvRegAdapterControl);
5165
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04005166 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)
5167 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
5168
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005169 /* initialize descriptor rings */
Manfred Sprauld81c0982005-07-31 18:20:30 +02005170 set_bufsize(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005171 oom = nv_init_ring(dev);
5172
5173 writel(0, base + NvRegLinkSpeed);
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005174 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005175 nv_txrx_reset(dev);
5176 writel(0, base + NvRegUnknownSetupReg6);
5177
5178 np->in_shutdown = 0;
5179
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005180 /* give hw rings */
Ayaz Abdulla0832b252006-02-04 13:13:26 -05005181 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005182 writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
Linus Torvalds1da177e2005-04-16 15:20:36 -07005183 base + NvRegRingSizes);
5184
Linus Torvalds1da177e2005-04-16 15:20:36 -07005185 writel(np->linkspeed, base + NvRegLinkSpeed);
Ayaz Abdulla95d161c2006-07-06 16:46:25 -04005186 if (np->desc_ver == DESC_VER_1)
5187 writel(NVREG_TX_WM_DESC1_DEFAULT, base + NvRegTxWatermark);
5188 else
5189 writel(NVREG_TX_WM_DESC2_3_DEFAULT, base + NvRegTxWatermark);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005190 writel(np->txrxctl_bits, base + NvRegTxRxControl);
Ayaz Abdullaee407b02006-02-04 13:13:17 -05005191 writel(np->vlanctl_bits, base + NvRegVlanControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005192 pci_push(base);
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005193 writel(NVREG_TXRXCTL_BIT1|np->txrxctl_bits, base + NvRegTxRxControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005194 reg_delay(dev, NvRegUnknownSetupReg5, NVREG_UNKSETUP5_BIT31, NVREG_UNKSETUP5_BIT31,
5195 NV_SETUP5_DELAY, NV_SETUP5_DELAYMAX,
5196 KERN_INFO "open: SetupReg5, Bit 31 remained off\n");
5197
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005198 writel(0, base + NvRegMIIMask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005199 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005200 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005201
Linus Torvalds1da177e2005-04-16 15:20:36 -07005202 writel(NVREG_MISC1_FORCE | NVREG_MISC1_HD, base + NvRegMisc1);
5203 writel(readl(base + NvRegTransmitterStatus), base + NvRegTransmitterStatus);
5204 writel(NVREG_PFF_ALWAYS, base + NvRegPacketFilterFlags);
Manfred Sprauld81c0982005-07-31 18:20:30 +02005205 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005206
5207 writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus);
Ayaz Abdullaa4336862008-04-18 13:50:43 -07005208
5209 get_random_bytes(&low, sizeof(low));
5210 low &= NVREG_SLOTTIME_MASK;
5211 if (np->desc_ver == DESC_VER_1) {
5212 writel(low|NVREG_SLOTTIME_DEFAULT, base + NvRegSlotTime);
5213 } else {
5214 if (!(np->driver_data & DEV_HAS_GEAR_MODE)) {
5215 /* setup legacy backoff */
5216 writel(NVREG_SLOTTIME_LEGBF_ENABLED|NVREG_SLOTTIME_10_100_FULL|low, base + NvRegSlotTime);
5217 } else {
5218 writel(NVREG_SLOTTIME_10_100_FULL, base + NvRegSlotTime);
5219 nv_gear_backoff_reseed(dev);
5220 }
5221 }
Ayaz Abdulla9744e212006-07-06 16:45:58 -04005222 writel(NVREG_TX_DEFERRAL_DEFAULT, base + NvRegTxDeferral);
5223 writel(NVREG_RX_DEFERRAL_DEFAULT, base + NvRegRxDeferral);
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005224 if (poll_interval == -1) {
5225 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT)
5226 writel(NVREG_POLL_DEFAULT_THROUGHPUT, base + NvRegPollingInterval);
5227 else
5228 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005229 } else
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005230 writel(poll_interval & 0xFFFF, base + NvRegPollingInterval);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005231 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
5232 writel((np->phyaddr << NVREG_ADAPTCTL_PHYSHIFT)|NVREG_ADAPTCTL_PHYVALID|NVREG_ADAPTCTL_RUNNING,
5233 base + NvRegAdapterControl);
5234 writel(NVREG_MIISPEED_BIT8|NVREG_MIIDELAY, base + NvRegMIISpeed);
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005235 writel(NVREG_MII_LINKCHANGE, base + NvRegMIIMask);
Ayaz Abdullac42d9df2006-06-10 22:47:52 -04005236 if (np->wolenabled)
5237 writel(NVREG_WAKEUPFLAGS_ENABLE , base + NvRegWakeUpFlags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005238
5239 i = readl(base + NvRegPowerState);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005240 if ((i & NVREG_POWERSTATE_POWEREDUP) == 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005241 writel(NVREG_POWERSTATE_POWEREDUP|i, base + NvRegPowerState);
5242
5243 pci_push(base);
5244 udelay(10);
5245 writel(readl(base + NvRegPowerState) | NVREG_POWERSTATE_VALID, base + NvRegPowerState);
5246
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005247 nv_disable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005248 pci_push(base);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005249 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005250 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
5251 pci_push(base);
5252
Szymon Janc78aea4f2010-11-27 08:39:43 +00005253 if (nv_request_irq(dev, 0))
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005254 goto out_drain;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005255
5256 /* ask for interrupts */
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005257 nv_enable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005258
5259 spin_lock_irq(&np->lock);
5260 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
5261 writel(0, base + NvRegMulticastAddrB);
Ayaz Abdullabb9a4fd2008-01-13 16:03:04 -05005262 writel(NVREG_MCASTMASKA_NONE, base + NvRegMulticastMaskA);
5263 writel(NVREG_MCASTMASKB_NONE, base + NvRegMulticastMaskB);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005264 writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
5265 /* One manual link speed update: Interrupts are enabled, future link
5266 * speed changes cause interrupts and are handled by nv_link_irq().
5267 */
5268 {
5269 u32 miistat;
5270 miistat = readl(base + NvRegMIIStatus);
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005271 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005272 dprintk(KERN_INFO "startup: got 0x%08x.\n", miistat);
5273 }
Manfred Spraul1b1b3c92005-08-06 23:47:55 +02005274 /* set linkspeed to invalid value, thus force nv_update_linkspeed
5275 * to init hw */
5276 np->linkspeed = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005277 ret = nv_update_linkspeed(dev);
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005278 nv_start_rxtx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005279 netif_start_queue(dev);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00005280 nv_napi_enable(dev);
Stephen Hemmingere27cdba2006-07-31 20:37:19 -07005281
Linus Torvalds1da177e2005-04-16 15:20:36 -07005282 if (ret) {
5283 netif_carrier_on(dev);
5284 } else {
Ed Swierkf7ab6972007-09-28 22:42:13 -07005285 printk(KERN_INFO "%s: no link during initialization.\n", dev->name);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005286 netif_carrier_off(dev);
5287 }
5288 if (oom)
5289 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005290
5291 /* start statistics timer */
Ayaz Abdulla9c662432008-08-06 12:11:42 -04005292 if (np->driver_data & (DEV_HAS_STATISTICS_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_STATISTICS_V3))
Daniel Drakebfebbb82008-03-18 11:07:18 +00005293 mod_timer(&np->stats_poll,
5294 round_jiffies(jiffies + STATS_INTERVAL));
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005295
Linus Torvalds1da177e2005-04-16 15:20:36 -07005296 spin_unlock_irq(&np->lock);
5297
5298 return 0;
5299out_drain:
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005300 nv_drain_rxtx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005301 return ret;
5302}
5303
5304static int nv_close(struct net_device *dev)
5305{
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005306 struct fe_priv *np = netdev_priv(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005307 u8 __iomem *base;
5308
5309 spin_lock_irq(&np->lock);
5310 np->in_shutdown = 1;
5311 spin_unlock_irq(&np->lock);
Ayaz Abdulla08d93572009-03-05 08:01:55 +00005312 nv_napi_disable(dev);
Manfred Spraula7475902007-10-17 21:52:33 +02005313 synchronize_irq(np->pci_dev->irq);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005314
5315 del_timer_sync(&np->oom_kick);
5316 del_timer_sync(&np->nic_poll);
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005317 del_timer_sync(&np->stats_poll);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005318
5319 netif_stop_queue(dev);
5320 spin_lock_irq(&np->lock);
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005321 nv_stop_rxtx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005322 nv_txrx_reset(dev);
5323
5324 /* disable interrupts on the nic or we will lock up */
5325 base = get_hwbase(dev);
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005326 nv_disable_hw_interrupts(dev, np->irqmask);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005327 pci_push(base);
5328 dprintk(KERN_INFO "%s: Irqmask is zero again\n", dev->name);
5329
5330 spin_unlock_irq(&np->lock);
5331
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005332 nv_free_irq(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005333
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005334 nv_drain_rxtx(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005335
Ed Swierk5a9a8e32009-06-02 00:19:52 -07005336 if (np->wolenabled || !phy_power_down) {
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00005337 nv_txrx_gate(dev, false);
Tim Mann2cc49a52007-06-14 13:16:38 -07005338 writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005339 nv_start_rx(dev);
Ed Swierkcb52deb2008-12-01 12:24:43 +00005340 } else {
5341 /* power down phy */
5342 mii_rw(dev, np->phyaddr, MII_BMCR,
5343 mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ)|BMCR_PDOWN);
Ayaz Abdulla88d7d8b2009-05-01 01:41:50 +00005344 nv_txrx_gate(dev, true);
Tim Mann2cc49a52007-06-14 13:16:38 -07005345 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005346
5347 /* FIXME: power down nic */
5348
5349 return 0;
5350}
5351
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005352static const struct net_device_ops nv_netdev_ops = {
5353 .ndo_open = nv_open,
5354 .ndo_stop = nv_close,
5355 .ndo_get_stats = nv_get_stats,
Stephen Hemminger00829822008-11-20 20:14:53 -08005356 .ndo_start_xmit = nv_start_xmit,
5357 .ndo_tx_timeout = nv_tx_timeout,
5358 .ndo_change_mtu = nv_change_mtu,
5359 .ndo_validate_addr = eth_validate_addr,
5360 .ndo_set_mac_address = nv_set_mac_address,
5361 .ndo_set_multicast_list = nv_set_multicast,
5362 .ndo_vlan_rx_register = nv_vlan_rx_register,
5363#ifdef CONFIG_NET_POLL_CONTROLLER
5364 .ndo_poll_controller = nv_poll_controller,
5365#endif
5366};
5367
5368static const struct net_device_ops nv_netdev_ops_optimized = {
5369 .ndo_open = nv_open,
5370 .ndo_stop = nv_close,
5371 .ndo_get_stats = nv_get_stats,
5372 .ndo_start_xmit = nv_start_xmit_optimized,
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005373 .ndo_tx_timeout = nv_tx_timeout,
5374 .ndo_change_mtu = nv_change_mtu,
5375 .ndo_validate_addr = eth_validate_addr,
5376 .ndo_set_mac_address = nv_set_mac_address,
5377 .ndo_set_multicast_list = nv_set_multicast,
5378 .ndo_vlan_rx_register = nv_vlan_rx_register,
5379#ifdef CONFIG_NET_POLL_CONTROLLER
5380 .ndo_poll_controller = nv_poll_controller,
5381#endif
5382};
5383
Linus Torvalds1da177e2005-04-16 15:20:36 -07005384static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
5385{
5386 struct net_device *dev;
5387 struct fe_priv *np;
5388 unsigned long addr;
5389 u8 __iomem *base;
5390 int err, i;
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005391 u32 powerstate, txreg;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005392 u32 phystate_orig = 0, phystate;
5393 int phyinitialized = 0;
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005394 static int printed_version;
5395
5396 if (!printed_version++)
5397 printk(KERN_INFO "%s: Reverse Engineered nForce ethernet"
5398 " driver. Version %s.\n", DRV_NAME, FORCEDETH_VERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005399
5400 dev = alloc_etherdev(sizeof(struct fe_priv));
5401 err = -ENOMEM;
5402 if (!dev)
5403 goto out;
5404
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005405 np = netdev_priv(dev);
Stephen Hemmingerbea33482007-10-03 16:41:36 -07005406 np->dev = dev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005407 np->pci_dev = pci_dev;
5408 spin_lock_init(&np->lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005409 SET_NETDEV_DEV(dev, &pci_dev->dev);
5410
5411 init_timer(&np->oom_kick);
5412 np->oom_kick.data = (unsigned long) dev;
Joe Perchesc061b182010-08-23 18:20:03 +00005413 np->oom_kick.function = nv_do_rx_refill; /* timer handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005414 init_timer(&np->nic_poll);
5415 np->nic_poll.data = (unsigned long) dev;
Joe Perchesc061b182010-08-23 18:20:03 +00005416 np->nic_poll.function = nv_do_nic_poll; /* timer handler */
Ayaz Abdulla52da3572006-06-10 22:48:04 -04005417 init_timer(&np->stats_poll);
5418 np->stats_poll.data = (unsigned long) dev;
Joe Perchesc061b182010-08-23 18:20:03 +00005419 np->stats_poll.function = nv_do_stats_poll; /* timer handler */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005420
5421 err = pci_enable_device(pci_dev);
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005422 if (err)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005423 goto out_free;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005424
5425 pci_set_master(pci_dev);
5426
5427 err = pci_request_regions(pci_dev, DRV_NAME);
5428 if (err < 0)
5429 goto out_disable;
5430
Ayaz Abdulla9c662432008-08-06 12:11:42 -04005431 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 -05005432 np->register_size = NV_PCI_REGSZ_VER3;
5433 else if (id->driver_data & DEV_HAS_STATISTICS_V1)
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005434 np->register_size = NV_PCI_REGSZ_VER2;
5435 else
5436 np->register_size = NV_PCI_REGSZ_VER1;
5437
Linus Torvalds1da177e2005-04-16 15:20:36 -07005438 err = -EINVAL;
5439 addr = 0;
5440 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
5441 dprintk(KERN_DEBUG "%s: resource %d start %p len %ld flags 0x%08lx.\n",
Szymon Janc78aea4f2010-11-27 08:39:43 +00005442 pci_name(pci_dev), i, (void *)pci_resource_start(pci_dev, i),
Linus Torvalds1da177e2005-04-16 15:20:36 -07005443 pci_resource_len(pci_dev, i),
5444 pci_resource_flags(pci_dev, i));
5445 if (pci_resource_flags(pci_dev, i) & IORESOURCE_MEM &&
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005446 pci_resource_len(pci_dev, i) >= np->register_size) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005447 addr = pci_resource_start(pci_dev, i);
5448 break;
5449 }
5450 }
5451 if (i == DEVICE_COUNT_RESOURCE) {
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005452 dev_printk(KERN_INFO, &pci_dev->dev,
5453 "Couldn't find register window\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -07005454 goto out_relreg;
5455 }
5456
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005457 /* copy of driver data */
5458 np->driver_data = id->driver_data;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04005459 /* copy of device id */
5460 np->device_id = id->device;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005461
Linus Torvalds1da177e2005-04-16 15:20:36 -07005462 /* handle different descriptor versions */
Manfred Spraulee733622005-07-31 18:32:26 +02005463 if (id->driver_data & DEV_HAS_HIGH_DMA) {
5464 /* packet format 3: supports 40-bit addressing */
5465 np->desc_ver = DESC_VER_3;
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005466 np->txrxctl_bits = NVREG_TXRXCTL_DESC_3;
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005467 if (dma_64bit) {
Yang Hongyang6afd1422009-04-06 19:01:15 -07005468 if (pci_set_dma_mask(pci_dev, DMA_BIT_MASK(39)))
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005469 dev_printk(KERN_INFO, &pci_dev->dev,
5470 "64-bit DMA failed, using 32-bit addressing\n");
5471 else
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005472 dev->features |= NETIF_F_HIGHDMA;
Yang Hongyang6afd1422009-04-06 19:01:15 -07005473 if (pci_set_consistent_dma_mask(pci_dev, DMA_BIT_MASK(39))) {
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005474 dev_printk(KERN_INFO, &pci_dev->dev,
5475 "64-bit DMA (consistent) failed, using 32-bit ring buffers\n");
Ayaz Abdulla69fe3fd2006-06-10 22:48:18 -04005476 }
Ayaz Abdulla84b39322006-05-20 14:59:48 -07005477 }
Manfred Spraulee733622005-07-31 18:32:26 +02005478 } else if (id->driver_data & DEV_HAS_LARGEDESC) {
5479 /* packet format 2: supports jumbo frames */
Linus Torvalds1da177e2005-04-16 15:20:36 -07005480 np->desc_ver = DESC_VER_2;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005481 np->txrxctl_bits = NVREG_TXRXCTL_DESC_2;
Manfred Spraulee733622005-07-31 18:32:26 +02005482 } else {
5483 /* original packet format */
5484 np->desc_ver = DESC_VER_1;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005485 np->txrxctl_bits = NVREG_TXRXCTL_DESC_1;
Manfred Sprauld81c0982005-07-31 18:20:30 +02005486 }
Manfred Spraulee733622005-07-31 18:32:26 +02005487
5488 np->pkt_limit = NV_PKTLIMIT_1;
5489 if (id->driver_data & DEV_HAS_LARGEDESC)
5490 np->pkt_limit = NV_PKTLIMIT_2;
5491
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005492 if (id->driver_data & DEV_HAS_CHECKSUM) {
Ayaz Abdullaf2ad2d92006-08-24 17:35:41 -04005493 np->rx_csum = 1;
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005494 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
Ayaz Abdullaedcfe5f2008-08-20 16:34:37 -07005495 dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
Ayaz Abdullafa454592006-01-05 22:45:45 -08005496 dev->features |= NETIF_F_TSO;
Tom Herbert53f224c2010-05-03 19:08:45 +00005497 dev->features |= NETIF_F_GRO;
Ayaz Abdulla21828162007-01-23 12:27:21 -05005498 }
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005499
Ayaz Abdullaee407b02006-02-04 13:13:17 -05005500 np->vlanctl_bits = 0;
5501 if (id->driver_data & DEV_HAS_VLAN) {
5502 np->vlanctl_bits = NVREG_VLANCONTROL_ENABLE;
5503 dev->features |= NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX;
Ayaz Abdullaee407b02006-02-04 13:13:17 -05005504 }
5505
Ayaz Abdullab6d07732006-06-10 22:47:42 -04005506 np->pause_flags = NV_PAUSEFRAME_RX_CAPABLE | NV_PAUSEFRAME_RX_REQ | NV_PAUSEFRAME_AUTONEG;
Ayaz Abdulla5289b4c2008-02-05 12:30:01 -05005507 if ((id->driver_data & DEV_HAS_PAUSEFRAME_TX_V1) ||
5508 (id->driver_data & DEV_HAS_PAUSEFRAME_TX_V2) ||
5509 (id->driver_data & DEV_HAS_PAUSEFRAME_TX_V3)) {
Ayaz Abdullab6d07732006-06-10 22:47:42 -04005510 np->pause_flags |= NV_PAUSEFRAME_TX_CAPABLE | NV_PAUSEFRAME_TX_REQ;
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04005511 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04005512
Ayaz Abdullaeb91f612006-05-24 18:13:19 -04005513
Linus Torvalds1da177e2005-04-16 15:20:36 -07005514 err = -ENOMEM;
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005515 np->base = ioremap(addr, np->register_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005516 if (!np->base)
5517 goto out_relreg;
5518 dev->base_addr = (unsigned long)np->base;
Manfred Spraulee733622005-07-31 18:32:26 +02005519
Linus Torvalds1da177e2005-04-16 15:20:36 -07005520 dev->irq = pci_dev->irq;
Manfred Spraulee733622005-07-31 18:32:26 +02005521
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005522 np->rx_ring_size = RX_RING_DEFAULT;
5523 np->tx_ring_size = TX_RING_DEFAULT;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005524
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005525 if (!nv_optimized(np)) {
Manfred Spraulee733622005-07-31 18:32:26 +02005526 np->rx_ring.orig = pci_alloc_consistent(pci_dev,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005527 sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
Manfred Spraulee733622005-07-31 18:32:26 +02005528 &np->ring_addr);
5529 if (!np->rx_ring.orig)
5530 goto out_unmap;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005531 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
Manfred Spraulee733622005-07-31 18:32:26 +02005532 } else {
5533 np->rx_ring.ex = pci_alloc_consistent(pci_dev,
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005534 sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
Manfred Spraulee733622005-07-31 18:32:26 +02005535 &np->ring_addr);
5536 if (!np->rx_ring.ex)
5537 goto out_unmap;
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005538 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
Manfred Spraulee733622005-07-31 18:32:26 +02005539 }
Yoann Padioleaudd00cc42007-07-19 01:49:03 -07005540 np->rx_skb = kcalloc(np->rx_ring_size, sizeof(struct nv_skb_map), GFP_KERNEL);
5541 np->tx_skb = kcalloc(np->tx_ring_size, sizeof(struct nv_skb_map), GFP_KERNEL);
Ayaz Abdulla761fcd92007-01-09 13:30:07 -05005542 if (!np->rx_skb || !np->tx_skb)
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005543 goto out_freering;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005544
Jeff Garzik36b30ea2007-10-16 01:40:30 -04005545 if (!nv_optimized(np))
Stephen Hemminger00829822008-11-20 20:14:53 -08005546 dev->netdev_ops = &nv_netdev_ops;
Ayaz Abdulla86b22b02007-01-21 18:10:37 -05005547 else
Stephen Hemminger00829822008-11-20 20:14:53 -08005548 dev->netdev_ops = &nv_netdev_ops_optimized;
Stephen Hemmingerb94426b2008-11-19 22:26:51 -08005549
Stephen Hemmingerbea33482007-10-03 16:41:36 -07005550 netif_napi_add(dev, &np->napi, nv_napi_poll, RX_WORK_PER_LOOP);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005551 SET_ETHTOOL_OPS(dev, &ops);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005552 dev->watchdog_timeo = NV_WATCHDOG_TIMEO;
5553
5554 pci_set_drvdata(pci_dev, dev);
5555
5556 /* read the mac address */
5557 base = get_hwbase(dev);
5558 np->orig_mac[0] = readl(base + NvRegMacAddrA);
5559 np->orig_mac[1] = readl(base + NvRegMacAddrB);
5560
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005561 /* check the workaround bit for correct mac address order */
5562 txreg = readl(base + NvRegTransmitPoll);
Ayaz Abdullaa376e792008-04-10 21:30:35 -07005563 if (id->driver_data & DEV_HAS_CORRECT_MACADDR) {
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005564 /* mac address is already in correct order */
5565 dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff;
5566 dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff;
5567 dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff;
5568 dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff;
5569 dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff;
5570 dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff;
Ayaz Abdullaa376e792008-04-10 21:30:35 -07005571 } else if (txreg & NVREG_TRANSMITPOLL_MAC_ADDR_REV) {
5572 /* mac address is already in correct order */
5573 dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff;
5574 dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff;
5575 dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff;
5576 dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff;
5577 dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff;
5578 dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff;
5579 /*
5580 * Set orig mac address back to the reversed version.
5581 * This flag will be cleared during low power transition.
5582 * Therefore, we should always put back the reversed address.
5583 */
5584 np->orig_mac[0] = (dev->dev_addr[5] << 0) + (dev->dev_addr[4] << 8) +
5585 (dev->dev_addr[3] << 16) + (dev->dev_addr[2] << 24);
5586 np->orig_mac[1] = (dev->dev_addr[1] << 0) + (dev->dev_addr[0] << 8);
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005587 } else {
5588 /* need to reverse mac address to correct order */
5589 dev->dev_addr[0] = (np->orig_mac[1] >> 8) & 0xff;
5590 dev->dev_addr[1] = (np->orig_mac[1] >> 0) & 0xff;
5591 dev->dev_addr[2] = (np->orig_mac[0] >> 24) & 0xff;
5592 dev->dev_addr[3] = (np->orig_mac[0] >> 16) & 0xff;
5593 dev->dev_addr[4] = (np->orig_mac[0] >> 8) & 0xff;
5594 dev->dev_addr[5] = (np->orig_mac[0] >> 0) & 0xff;
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005595 writel(txreg|NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
Yinghai Luf55c21f2008-09-13 13:10:31 -07005596 printk(KERN_DEBUG "nv_probe: set workaround bit for reversed mac addr\n");
Ayaz Abdulla5070d342006-07-31 12:05:01 -04005597 }
John W. Linvillec704b852005-09-12 10:48:56 -04005598 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005599
John W. Linvillec704b852005-09-12 10:48:56 -04005600 if (!is_valid_ether_addr(dev->perm_addr)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005601 /*
5602 * Bad mac address. At least one bios sets the mac address
5603 * to 01:23:45:67:89:ab
5604 */
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005605 dev_printk(KERN_ERR, &pci_dev->dev,
Johannes Berge1749612008-10-27 15:59:26 -07005606 "Invalid Mac address detected: %pM\n",
Szymon Janc78aea4f2010-11-27 08:39:43 +00005607 dev->dev_addr);
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005608 dev_printk(KERN_ERR, &pci_dev->dev,
5609 "Please complain to your hardware vendor. Switching to a random MAC.\n");
Stanislav O. Bezzubtsev655a6592009-11-15 21:17:02 -08005610 random_ether_addr(dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005611 }
5612
Johannes Berge1749612008-10-27 15:59:26 -07005613 dprintk(KERN_DEBUG "%s: MAC Address %pM\n",
5614 pci_name(pci_dev), dev->dev_addr);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005615
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005616 /* set mac address */
5617 nv_copy_mac_to_hw(dev);
5618
Tobias Diedrich9a60a822008-06-01 00:54:42 +02005619 /* Workaround current PCI init glitch: wakeup bits aren't
5620 * being set from PCI PM capability.
5621 */
5622 device_init_wakeup(&pci_dev->dev, 1);
5623
Linus Torvalds1da177e2005-04-16 15:20:36 -07005624 /* disable WOL */
5625 writel(0, base + NvRegWakeUpFlags);
5626 np->wolenabled = 0;
5627
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005628 if (id->driver_data & DEV_HAS_POWER_CNTRL) {
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005629
5630 /* take phy and nic out of low power mode */
5631 powerstate = readl(base + NvRegPowerState2);
5632 powerstate &= ~NVREG_POWERSTATE2_POWERUP_MASK;
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00005633 if ((id->driver_data & DEV_NEED_LOW_POWER_FIX) &&
Auke Kok44c10132007-06-08 15:46:36 -07005634 pci_dev->revision >= 0xA3)
Ayaz Abdulla86a0f042006-04-24 18:41:31 -04005635 powerstate |= NVREG_POWERSTATE2_POWERUP_REV_A3;
5636 writel(powerstate, base + NvRegPowerState2);
5637 }
5638
Szymon Janc78aea4f2010-11-27 08:39:43 +00005639 if (np->desc_ver == DESC_VER_1)
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005640 np->tx_flags = NV_TX_VALID;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005641 else
Ayaz Abdullaac9c1892005-10-26 00:51:24 -04005642 np->tx_flags = NV_TX2_VALID;
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005643
5644 np->msi_flags = 0;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005645 if ((id->driver_data & DEV_HAS_MSI) && msi)
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005646 np->msi_flags |= NV_MSI_CAPABLE;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005647
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005648 if ((id->driver_data & DEV_HAS_MSI_X) && msix) {
5649 /* msix has had reported issues when modifying irqmask
5650 as in the case of napi, therefore, disable for now
5651 */
David S. Miller0a127612010-05-03 23:33:05 -07005652#if 0
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005653 np->msi_flags |= NV_MSI_X_CAPABLE;
5654#endif
5655 }
5656
5657 if (optimization_mode == NV_OPTIMIZATION_MODE_CPU) {
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005658 np->irqmask = NVREG_IRQMASK_CPU;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005659 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
5660 np->msi_flags |= 0x0001;
Ayaz Abdulla9e184762009-03-05 08:02:18 +00005661 } else if (optimization_mode == NV_OPTIMIZATION_MODE_DYNAMIC &&
5662 !(id->driver_data & DEV_NEED_TIMERIRQ)) {
5663 /* start off in throughput mode */
5664 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
5665 /* remove support for msix mode */
5666 np->msi_flags &= ~NV_MSI_X_CAPABLE;
5667 } else {
5668 optimization_mode = NV_OPTIMIZATION_MODE_THROUGHPUT;
5669 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
5670 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
5671 np->msi_flags |= 0x0003;
Ayaz Abdullad33a73c82006-02-04 13:13:31 -05005672 }
Ayaz Abdullaa971c322005-11-11 08:30:38 -05005673
Linus Torvalds1da177e2005-04-16 15:20:36 -07005674 if (id->driver_data & DEV_NEED_TIMERIRQ)
5675 np->irqmask |= NVREG_IRQ_TIMER;
5676 if (id->driver_data & DEV_NEED_LINKTIMER) {
5677 dprintk(KERN_INFO "%s: link timer on.\n", pci_name(pci_dev));
5678 np->need_linktimer = 1;
5679 np->link_timeout = jiffies + LINK_TIMEOUT;
5680 } else {
5681 dprintk(KERN_INFO "%s: link timer off.\n", pci_name(pci_dev));
5682 np->need_linktimer = 0;
5683 }
5684
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005685 /* Limit the number of tx's outstanding for hw bug */
5686 if (id->driver_data & DEV_NEED_TX_LIMIT) {
5687 np->tx_limit = 1;
Ayaz Abdulla5c659322010-04-13 18:49:51 -07005688 if (((id->driver_data & DEV_NEED_TX_LIMIT2) == DEV_NEED_TX_LIMIT2) &&
Ayaz Abdulla3b446c32008-03-10 14:58:21 -05005689 pci_dev->revision >= 0xA2)
5690 np->tx_limit = 0;
5691 }
5692
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005693 /* clear phy state and temporarily halt phy interrupts */
5694 writel(0, base + NvRegMIIMask);
5695 phystate = readl(base + NvRegAdapterControl);
5696 if (phystate & NVREG_ADAPTCTL_RUNNING) {
5697 phystate_orig = 1;
5698 phystate &= ~NVREG_ADAPTCTL_RUNNING;
5699 writel(phystate, base + NvRegAdapterControl);
5700 }
Ayaz Abdullaeb798422008-02-04 15:14:04 -05005701 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005702
5703 if (id->driver_data & DEV_HAS_MGMT_UNIT) {
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005704 /* management unit running on the mac? */
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005705 if ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_ST) &&
5706 (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_PHY_INIT) &&
5707 nv_mgmt_acquire_sema(dev) &&
5708 nv_mgmt_get_version(dev)) {
5709 np->mac_in_use = 1;
Szymon Janc78aea4f2010-11-27 08:39:43 +00005710 if (np->mgmt_version > 0)
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005711 np->mac_in_use = readl(base + NvRegMgmtUnitControl) & NVREG_MGMTUNITCONTROL_INUSE;
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005712 dprintk(KERN_INFO "%s: mgmt unit is running. mac in use %x.\n",
5713 pci_name(pci_dev), np->mac_in_use);
5714 /* management unit setup the phy already? */
5715 if (np->mac_in_use &&
5716 ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK) ==
5717 NVREG_XMITCTL_SYNC_PHY_INIT)) {
5718 /* phy is inited by mgmt unit */
5719 phyinitialized = 1;
5720 dprintk(KERN_INFO "%s: Phy already initialized by mgmt unit.\n",
5721 pci_name(pci_dev));
5722 } else {
5723 /* we need to init the phy */
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005724 }
5725 }
5726 }
5727
Linus Torvalds1da177e2005-04-16 15:20:36 -07005728 /* find a suitable phy */
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005729 for (i = 1; i <= 32; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005730 int id1, id2;
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005731 int phyaddr = i & 0x1F;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005732
5733 spin_lock_irq(&np->lock);
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005734 id1 = mii_rw(dev, phyaddr, MII_PHYSID1, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005735 spin_unlock_irq(&np->lock);
5736 if (id1 < 0 || id1 == 0xffff)
5737 continue;
5738 spin_lock_irq(&np->lock);
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005739 id2 = mii_rw(dev, phyaddr, MII_PHYSID2, MII_READ);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005740 spin_unlock_irq(&np->lock);
5741 if (id2 < 0 || id2 == 0xffff)
5742 continue;
5743
Ayaz Abdullaedf7e5e2006-08-24 15:43:42 -04005744 np->phy_model = id2 & PHYID2_MODEL_MASK;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005745 id1 = (id1 & PHYID1_OUI_MASK) << PHYID1_OUI_SHFT;
5746 id2 = (id2 & PHYID2_OUI_MASK) >> PHYID2_OUI_SHFT;
5747 dprintk(KERN_DEBUG "%s: open: Found PHY %04x:%04x at address %d.\n",
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005748 pci_name(pci_dev), id1, id2, phyaddr);
5749 np->phyaddr = phyaddr;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005750 np->phy_oui = id1 | id2;
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04005751
5752 /* Realtek hardcoded phy id1 to all zero's on certain phys */
5753 if (np->phy_oui == PHY_OUI_REALTEK2)
5754 np->phy_oui = PHY_OUI_REALTEK;
5755 /* Setup phy revision for Realtek */
5756 if (np->phy_oui == PHY_OUI_REALTEK && np->phy_model == PHY_MODEL_REALTEK_8211)
5757 np->phy_rev = mii_rw(dev, phyaddr, MII_RESV1, MII_READ) & PHY_REV_MASK;
5758
Linus Torvalds1da177e2005-04-16 15:20:36 -07005759 break;
5760 }
Ayaz Abdulla7a33e452005-11-11 08:31:11 -05005761 if (i == 33) {
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005762 dev_printk(KERN_INFO, &pci_dev->dev,
5763 "open: Could not find a valid PHY.\n");
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005764 goto out_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005765 }
Jeff Garzikf3b197a2006-05-26 21:39:03 -04005766
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005767 if (!phyinitialized) {
5768 /* reset it */
5769 phy_init(dev);
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05005770 } else {
5771 /* see if it is a gigabit phy */
5772 u32 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
Szymon Janc78aea4f2010-11-27 08:39:43 +00005773 if (mii_status & PHY_GIGABIT)
Ayaz Abdullaf35723e2003-02-20 03:03:54 -05005774 np->gigabit = PHY_GIGABIT;
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005775 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07005776
5777 /* set default link speed settings */
5778 np->linkspeed = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
5779 np->duplex = 0;
5780 np->autoneg = 1;
5781
5782 err = register_netdev(dev);
5783 if (err) {
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005784 dev_printk(KERN_INFO, &pci_dev->dev,
5785 "unable to register netdev: %d\n", err);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005786 goto out_error;
Linus Torvalds1da177e2005-04-16 15:20:36 -07005787 }
Jeff Garzik3f88ce42007-10-16 04:09:09 -04005788
5789 dev_printk(KERN_INFO, &pci_dev->dev, "ifname %s, PHY OUI 0x%x @ %d, "
5790 "addr %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
5791 dev->name,
5792 np->phy_oui,
5793 np->phyaddr,
5794 dev->dev_addr[0],
5795 dev->dev_addr[1],
5796 dev->dev_addr[2],
5797 dev->dev_addr[3],
5798 dev->dev_addr[4],
5799 dev->dev_addr[5]);
5800
5801 dev_printk(KERN_INFO, &pci_dev->dev, "%s%s%s%s%s%s%s%s%s%sdesc-v%u\n",
Szymon Janc78aea4f2010-11-27 08:39:43 +00005802 dev->features & NETIF_F_HIGHDMA ? "highdma " : "",
5803 dev->features & (NETIF_F_IP_CSUM | NETIF_F_SG) ?
5804 "csum " : "",
5805 dev->features & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX) ?
5806 "vlan " : "",
5807 id->driver_data & DEV_HAS_POWER_CNTRL ? "pwrctl " : "",
5808 id->driver_data & DEV_HAS_MGMT_UNIT ? "mgmt " : "",
5809 id->driver_data & DEV_NEED_TIMERIRQ ? "timirq " : "",
5810 np->gigabit == PHY_GIGABIT ? "gbit " : "",
5811 np->need_linktimer ? "lnktim " : "",
5812 np->msi_flags & NV_MSI_CAPABLE ? "msi " : "",
5813 np->msi_flags & NV_MSI_X_CAPABLE ? "msi-x " : "",
5814 np->desc_ver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005815
5816 return 0;
5817
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005818out_error:
Ayaz Abdulla7e680c22006-10-30 17:31:51 -05005819 if (phystate_orig)
5820 writel(phystate|NVREG_ADAPTCTL_RUNNING, base + NvRegAdapterControl);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005821 pci_set_drvdata(pci_dev, NULL);
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005822out_freering:
5823 free_rings(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005824out_unmap:
5825 iounmap(get_hwbase(dev));
5826out_relreg:
5827 pci_release_regions(pci_dev);
5828out_disable:
5829 pci_disable_device(pci_dev);
5830out_free:
5831 free_netdev(dev);
5832out:
5833 return err;
5834}
5835
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04005836static void nv_restore_phy(struct net_device *dev)
5837{
5838 struct fe_priv *np = netdev_priv(dev);
5839 u16 phy_reserved, mii_control;
5840
5841 if (np->phy_oui == PHY_OUI_REALTEK &&
5842 np->phy_model == PHY_MODEL_REALTEK_8201 &&
5843 phy_cross == NV_CROSSOVER_DETECTION_DISABLED) {
5844 mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3);
5845 phy_reserved = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, MII_READ);
5846 phy_reserved &= ~PHY_REALTEK_INIT_MSK1;
5847 phy_reserved |= PHY_REALTEK_INIT8;
5848 mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, phy_reserved);
5849 mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1);
5850
5851 /* restart auto negotiation */
5852 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
5853 mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE);
5854 mii_rw(dev, np->phyaddr, MII_BMCR, mii_control);
5855 }
5856}
5857
Yinghai Luf55c21f2008-09-13 13:10:31 -07005858static void nv_restore_mac_addr(struct pci_dev *pci_dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07005859{
5860 struct net_device *dev = pci_get_drvdata(pci_dev);
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005861 struct fe_priv *np = netdev_priv(dev);
5862 u8 __iomem *base = get_hwbase(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005863
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005864 /* special op: write back the misordered MAC address - otherwise
5865 * the next nv_probe would see a wrong address.
5866 */
5867 writel(np->orig_mac[0], base + NvRegMacAddrA);
5868 writel(np->orig_mac[1], base + NvRegMacAddrB);
Björn Steinbrink2e3884b2008-01-07 23:22:53 -08005869 writel(readl(base + NvRegTransmitPoll) & ~NVREG_TRANSMITPOLL_MAC_ADDR_REV,
5870 base + NvRegTransmitPoll);
Yinghai Luf55c21f2008-09-13 13:10:31 -07005871}
5872
5873static void __devexit nv_remove(struct pci_dev *pci_dev)
5874{
5875 struct net_device *dev = pci_get_drvdata(pci_dev);
5876
5877 unregister_netdev(dev);
5878
5879 nv_restore_mac_addr(pci_dev);
Ayaz Abdullaf1489652006-07-31 12:04:45 -04005880
Ayaz Abdulla9f3f7912008-04-23 14:37:30 -04005881 /* restore any phy related changes */
5882 nv_restore_phy(dev);
5883
Ayaz Abdullacac1c522009-02-07 00:23:57 -08005884 nv_mgmt_release_sema(dev);
5885
Linus Torvalds1da177e2005-04-16 15:20:36 -07005886 /* free all structures */
Ayaz Abdullaeafa59f2006-06-10 22:47:34 -04005887 free_rings(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07005888 iounmap(get_hwbase(dev));
5889 pci_release_regions(pci_dev);
5890 pci_disable_device(pci_dev);
5891 free_netdev(dev);
5892 pci_set_drvdata(pci_dev, NULL);
5893}
5894
Francois Romieua1893172006-10-10 14:33:27 -07005895#ifdef CONFIG_PM
5896static int nv_suspend(struct pci_dev *pdev, pm_message_t state)
5897{
5898 struct net_device *dev = pci_get_drvdata(pdev);
5899 struct fe_priv *np = netdev_priv(dev);
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02005900 u8 __iomem *base = get_hwbase(dev);
5901 int i;
Francois Romieua1893172006-10-10 14:33:27 -07005902
Tobias Diedrich25d90812008-05-18 15:04:29 +02005903 if (netif_running(dev)) {
Szymon Janc78aea4f2010-11-27 08:39:43 +00005904 /* Gross. */
Tobias Diedrich25d90812008-05-18 15:04:29 +02005905 nv_close(dev);
5906 }
Francois Romieua1893172006-10-10 14:33:27 -07005907 netif_device_detach(dev);
5908
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02005909 /* save non-pci configuration space */
Szymon Janc78aea4f2010-11-27 08:39:43 +00005910 for (i = 0; i <= np->register_size/sizeof(u32); i++)
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02005911 np->saved_config_space[i] = readl(base + i*sizeof(u32));
5912
Francois Romieua1893172006-10-10 14:33:27 -07005913 pci_save_state(pdev);
5914 pci_enable_wake(pdev, pci_choose_state(pdev, state), np->wolenabled);
Tobias Diedrich25d90812008-05-18 15:04:29 +02005915 pci_disable_device(pdev);
Francois Romieua1893172006-10-10 14:33:27 -07005916 pci_set_power_state(pdev, pci_choose_state(pdev, state));
Francois Romieua1893172006-10-10 14:33:27 -07005917 return 0;
5918}
5919
5920static int nv_resume(struct pci_dev *pdev)
5921{
5922 struct net_device *dev = pci_get_drvdata(pdev);
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02005923 struct fe_priv *np = netdev_priv(dev);
Ayaz Abdullaa376e792008-04-10 21:30:35 -07005924 u8 __iomem *base = get_hwbase(dev);
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02005925 int i, rc = 0;
Francois Romieua1893172006-10-10 14:33:27 -07005926
Francois Romieua1893172006-10-10 14:33:27 -07005927 pci_set_power_state(pdev, PCI_D0);
5928 pci_restore_state(pdev);
Tobias Diedrich25d90812008-05-18 15:04:29 +02005929 /* ack any pending wake events, disable PME */
Francois Romieua1893172006-10-10 14:33:27 -07005930 pci_enable_wake(pdev, PCI_D0, 0);
5931
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02005932 /* restore non-pci configuration space */
Szymon Janc78aea4f2010-11-27 08:39:43 +00005933 for (i = 0; i <= np->register_size/sizeof(u32); i++)
Tobias Diedrich1a1ca862008-05-18 15:03:44 +02005934 writel(np->saved_config_space[i], base+i*sizeof(u32));
Ayaz Abdullaa376e792008-04-10 21:30:35 -07005935
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00005936 if (np->driver_data & DEV_NEED_MSI_FIX)
5937 pci_write_config_dword(pdev, NV_MSI_PRIV_OFFSET, NV_MSI_PRIV_VALUE);
Ayaz Abdullab6e44052009-02-07 00:24:15 -08005938
Ed Swierk35a74332009-04-06 17:49:12 -07005939 /* restore phy state, including autoneg */
5940 phy_init(dev);
5941
Tobias Diedrich25d90812008-05-18 15:04:29 +02005942 netif_device_attach(dev);
5943 if (netif_running(dev)) {
5944 rc = nv_open(dev);
5945 nv_set_multicast(dev);
5946 }
Francois Romieua1893172006-10-10 14:33:27 -07005947 return rc;
5948}
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02005949
5950static void nv_shutdown(struct pci_dev *pdev)
5951{
5952 struct net_device *dev = pci_get_drvdata(pdev);
5953 struct fe_priv *np = netdev_priv(dev);
5954
5955 if (netif_running(dev))
5956 nv_close(dev);
5957
Tobias Diedrich34edaa82009-02-16 00:13:20 -08005958 /*
5959 * Restore the MAC so a kernel started by kexec won't get confused.
5960 * If we really go for poweroff, we must not restore the MAC,
5961 * otherwise the MAC for WOL will be reversed at least on some boards.
5962 */
Szymon Janc78aea4f2010-11-27 08:39:43 +00005963 if (system_state != SYSTEM_POWER_OFF)
Tobias Diedrich34edaa82009-02-16 00:13:20 -08005964 nv_restore_mac_addr(pdev);
Yinghai Luf55c21f2008-09-13 13:10:31 -07005965
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02005966 pci_disable_device(pdev);
Tobias Diedrich34edaa82009-02-16 00:13:20 -08005967 /*
5968 * Apparently it is not possible to reinitialise from D3 hot,
5969 * only put the device into D3 if we really go for poweroff.
5970 */
Rafael J. Wysocki3cb55992008-09-05 14:00:19 -07005971 if (system_state == SYSTEM_POWER_OFF) {
5972 if (pci_enable_wake(pdev, PCI_D3cold, np->wolenabled))
5973 pci_enable_wake(pdev, PCI_D3hot, np->wolenabled);
5974 pci_set_power_state(pdev, PCI_D3hot);
5975 }
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02005976}
Francois Romieua1893172006-10-10 14:33:27 -07005977#else
5978#define nv_suspend NULL
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02005979#define nv_shutdown NULL
Francois Romieua1893172006-10-10 14:33:27 -07005980#define nv_resume NULL
5981#endif /* CONFIG_PM */
5982
Alexey Dobriyana3aa1882010-01-07 11:58:11 +00005983static DEFINE_PCI_DEVICE_TABLE(pci_tbl) = {
Linus Torvalds1da177e2005-04-16 15:20:36 -07005984 { /* nForce Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00005985 PCI_DEVICE(0x10DE, 0x01C3),
Manfred Spraulc2dba062005-07-31 18:29:47 +02005986 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005987 },
5988 { /* nForce2 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00005989 PCI_DEVICE(0x10DE, 0x0066),
Manfred Spraulc2dba062005-07-31 18:29:47 +02005990 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005991 },
5992 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00005993 PCI_DEVICE(0x10DE, 0x00D6),
Manfred Spraulc2dba062005-07-31 18:29:47 +02005994 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005995 },
5996 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00005997 PCI_DEVICE(0x10DE, 0x0086),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04005998 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07005999 },
6000 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006001 PCI_DEVICE(0x10DE, 0x008C),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04006002 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006003 },
6004 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006005 PCI_DEVICE(0x10DE, 0x00E6),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04006006 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006007 },
6008 { /* nForce3 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006009 PCI_DEVICE(0x10DE, 0x00DF),
Manfred Spraul8a4ae7f2005-09-21 23:22:10 -04006010 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006011 },
6012 { /* CK804 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006013 PCI_DEVICE(0x10DE, 0x0056),
Yinghai Lu033e97b2009-02-06 01:30:56 -08006014 .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 -07006015 },
6016 { /* CK804 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006017 PCI_DEVICE(0x10DE, 0x0057),
Yinghai Lu033e97b2009-02-06 01:30:56 -08006018 .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 -07006019 },
6020 { /* MCP04 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006021 PCI_DEVICE(0x10DE, 0x0037),
Ayaz Abdulla9e184762009-03-05 08:02:18 +00006022 .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 -07006023 },
6024 { /* MCP04 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006025 PCI_DEVICE(0x10DE, 0x0038),
Ayaz Abdulla9e184762009-03-05 08:02:18 +00006026 .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 +02006027 },
6028 { /* MCP51 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006029 PCI_DEVICE(0x10DE, 0x0268),
6030 .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 -07006031 },
Manfred Spraul9992d4a2005-06-05 17:36:11 +02006032 { /* MCP51 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006033 PCI_DEVICE(0x10DE, 0x0269),
6034 .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 +02006035 },
Manfred Spraulf49d16e2005-06-26 11:36:52 +02006036 { /* MCP55 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006037 PCI_DEVICE(0x10DE, 0x0372),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006038 .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 +02006039 },
6040 { /* MCP55 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006041 PCI_DEVICE(0x10DE, 0x0373),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006042 .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 +02006043 },
Ayaz Abdullac99ce7e2006-06-10 22:48:28 -04006044 { /* MCP61 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006045 PCI_DEVICE(0x10DE, 0x03E5),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006046 .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 -04006047 },
6048 { /* MCP61 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006049 PCI_DEVICE(0x10DE, 0x03E6),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006050 .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 -04006051 },
6052 { /* MCP61 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006053 PCI_DEVICE(0x10DE, 0x03EE),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006054 .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 -04006055 },
6056 { /* MCP61 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006057 PCI_DEVICE(0x10DE, 0x03EF),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006058 .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 -04006059 },
6060 { /* MCP65 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006061 PCI_DEVICE(0x10DE, 0x0450),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006062 .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 -04006063 },
6064 { /* MCP65 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006065 PCI_DEVICE(0x10DE, 0x0451),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006066 .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 -04006067 },
6068 { /* MCP65 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006069 PCI_DEVICE(0x10DE, 0x0452),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006070 .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 -04006071 },
6072 { /* MCP65 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006073 PCI_DEVICE(0x10DE, 0x0453),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006074 .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 -04006075 },
Ayaz Abdullaf4344842006-11-06 00:43:40 -08006076 { /* MCP67 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006077 PCI_DEVICE(0x10DE, 0x054C),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006078 .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 -08006079 },
6080 { /* MCP67 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006081 PCI_DEVICE(0x10DE, 0x054D),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006082 .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 -08006083 },
6084 { /* MCP67 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006085 PCI_DEVICE(0x10DE, 0x054E),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006086 .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 -08006087 },
6088 { /* MCP67 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006089 PCI_DEVICE(0x10DE, 0x054F),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006090 .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 -08006091 },
Ayaz Abdulla13986612007-07-22 20:43:26 -04006092 { /* MCP73 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006093 PCI_DEVICE(0x10DE, 0x07DC),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006094 .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 -04006095 },
6096 { /* MCP73 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006097 PCI_DEVICE(0x10DE, 0x07DD),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006098 .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 -04006099 },
6100 { /* MCP73 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006101 PCI_DEVICE(0x10DE, 0x07DE),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006102 .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 -04006103 },
6104 { /* MCP73 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006105 PCI_DEVICE(0x10DE, 0x07DF),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006106 .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 -04006107 },
Ayaz Abdulla96fd4cd2007-10-25 03:36:42 -04006108 { /* MCP77 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006109 PCI_DEVICE(0x10DE, 0x0760),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006110 .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 -04006111 },
6112 { /* MCP77 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006113 PCI_DEVICE(0x10DE, 0x0761),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006114 .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 -04006115 },
6116 { /* MCP77 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006117 PCI_DEVICE(0x10DE, 0x0762),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006118 .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 -04006119 },
6120 { /* MCP77 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006121 PCI_DEVICE(0x10DE, 0x0763),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006122 .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 -04006123 },
Ayaz Abdulla490dde82007-11-23 20:54:01 -05006124 { /* MCP79 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006125 PCI_DEVICE(0x10DE, 0x0AB0),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006126 .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 -05006127 },
6128 { /* MCP79 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006129 PCI_DEVICE(0x10DE, 0x0AB1),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006130 .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 -05006131 },
6132 { /* MCP79 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006133 PCI_DEVICE(0x10DE, 0x0AB2),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006134 .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 -05006135 },
6136 { /* MCP79 Ethernet Controller */
Ayaz Abdulla3c2e1c12009-06-03 15:05:17 +00006137 PCI_DEVICE(0x10DE, 0x0AB3),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006138 .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 -05006139 },
Ayaz Abdulla3df81c42009-06-03 15:05:35 +00006140 { /* MCP89 Ethernet Controller */
6141 PCI_DEVICE(0x10DE, 0x0D7D),
Mike Ditto7b5e0782010-07-25 21:54:28 -07006142 .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 +00006143 },
Linus Torvalds1da177e2005-04-16 15:20:36 -07006144 {0,},
6145};
6146
6147static struct pci_driver driver = {
Jeff Garzik3f88ce42007-10-16 04:09:09 -04006148 .name = DRV_NAME,
6149 .id_table = pci_tbl,
6150 .probe = nv_probe,
6151 .remove = __devexit_p(nv_remove),
6152 .suspend = nv_suspend,
6153 .resume = nv_resume,
Tobias Diedrichf735a2a2008-05-18 15:02:37 +02006154 .shutdown = nv_shutdown,
Linus Torvalds1da177e2005-04-16 15:20:36 -07006155};
6156
Linus Torvalds1da177e2005-04-16 15:20:36 -07006157static int __init init_nic(void)
6158{
Jeff Garzik29917622006-08-19 17:48:59 -04006159 return pci_register_driver(&driver);
Linus Torvalds1da177e2005-04-16 15:20:36 -07006160}
6161
6162static void __exit exit_nic(void)
6163{
6164 pci_unregister_driver(&driver);
6165}
6166
6167module_param(max_interrupt_work, int, 0);
6168MODULE_PARM_DESC(max_interrupt_work, "forcedeth maximum events handled per interrupt");
Ayaz Abdullaa971c322005-11-11 08:30:38 -05006169module_param(optimization_mode, int, 0);
Ayaz Abdulla9e184762009-03-05 08:02:18 +00006170MODULE_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 -05006171module_param(poll_interval, int, 0);
6172MODULE_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 -04006173module_param(msi, int, 0);
6174MODULE_PARM_DESC(msi, "MSI interrupts are enabled by setting to 1 and disabled by setting to 0.");
6175module_param(msix, int, 0);
6176MODULE_PARM_DESC(msix, "MSIX interrupts are enabled by setting to 1 and disabled by setting to 0.");
6177module_param(dma_64bit, int, 0);
6178MODULE_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 -04006179module_param(phy_cross, int, 0);
6180MODULE_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 -07006181module_param(phy_power_down, int, 0);
6182MODULE_PARM_DESC(phy_power_down, "Power down phy and disable link when interface is down (1), or leave phy powered up (0).");
Linus Torvalds1da177e2005-04-16 15:20:36 -07006183
6184MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>");
6185MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver");
6186MODULE_LICENSE("GPL");
6187
6188MODULE_DEVICE_TABLE(pci, pci_tbl);
6189
6190module_init(init_nic);
6191module_exit(exit_nic);