2 * forcedeth: Ethernet driver for NVIDIA nForce media access controllers.
4 * Note: This driver is a cleanroom reimplementation based on reverse
5 * engineered documentation written by Carl-Daniel Hailfinger
6 * and Andrew de Quincey.
8 * NVIDIA, nForce and other NVIDIA marks are trademarks or registered
9 * trademarks of NVIDIA Corporation in the United States and other
12 * Copyright (C) 2003,4,5 Manfred Spraul
13 * 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)
16 * Copyright (c) 2004,2005,2006,2007,2008,2009 NVIDIA Corporation
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.
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.
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
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.
42 #define FORCEDETH_VERSION "0.64"
43 #define DRV_NAME "forcedeth"
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>
52 #include <linux/spinlock.h>
53 #include <linux/ethtool.h>
54 #include <linux/timer.h>
55 #include <linux/skbuff.h>
56 #include <linux/mii.h>
57 #include <linux/random.h>
58 #include <linux/init.h>
59 #include <linux/if_vlan.h>
60 #include <linux/dma-mapping.h>
64 #include <asm/uaccess.h>
65 #include <asm/system.h>
68 #define dprintk printk
70 #define dprintk(x...) do { } while (0)
73 #define TX_WORK_PER_LOOP 64
74 #define RX_WORK_PER_LOOP 64
80 #define DEV_NEED_TIMERIRQ 0x0000001 /* set the timer irq flag in the irq mask */
81 #define DEV_NEED_LINKTIMER 0x0000002 /* poll link settings. Relies on the timer irq */
82 #define DEV_HAS_LARGEDESC 0x0000004 /* device supports jumbo frames and needs packet format 2 */
83 #define DEV_HAS_HIGH_DMA 0x0000008 /* device supports 64bit dma */
84 #define DEV_HAS_CHECKSUM 0x0000010 /* device supports tx and rx checksum offloads */
85 #define DEV_HAS_VLAN 0x0000020 /* device supports vlan tagging and striping */
86 #define DEV_HAS_MSI 0x0000040 /* device supports MSI */
87 #define DEV_HAS_MSI_X 0x0000080 /* device supports MSI-X */
88 #define DEV_HAS_POWER_CNTRL 0x0000100 /* device supports power savings */
89 #define DEV_HAS_STATISTICS_V1 0x0000200 /* device supports hw statistics version 1 */
90 #define DEV_HAS_STATISTICS_V2 0x0000600 /* device supports hw statistics version 2 */
91 #define DEV_HAS_STATISTICS_V3 0x0000e00 /* device supports hw statistics version 3 */
92 #define DEV_HAS_TEST_EXTENDED 0x0001000 /* device supports extended diagnostic test */
93 #define DEV_HAS_MGMT_UNIT 0x0002000 /* device supports management unit */
94 #define DEV_HAS_CORRECT_MACADDR 0x0004000 /* device supports correct mac address order */
95 #define DEV_HAS_COLLISION_FIX 0x0008000 /* device supports tx collision fix */
96 #define DEV_HAS_PAUSEFRAME_TX_V1 0x0010000 /* device supports tx pause frames version 1 */
97 #define DEV_HAS_PAUSEFRAME_TX_V2 0x0020000 /* device supports tx pause frames version 2 */
98 #define DEV_HAS_PAUSEFRAME_TX_V3 0x0040000 /* device supports tx pause frames version 3 */
99 #define DEV_NEED_TX_LIMIT 0x0080000 /* device needs to limit tx */
100 #define DEV_NEED_TX_LIMIT2 0x0180000 /* device needs to limit tx, expect for some revs */
101 #define DEV_HAS_GEAR_MODE 0x0200000 /* device supports gear mode */
102 #define DEV_NEED_PHY_INIT_FIX 0x0400000 /* device needs specific phy workaround */
103 #define DEV_NEED_LOW_POWER_FIX 0x0800000 /* device needs special power up workaround */
104 #define DEV_NEED_MSI_FIX 0x1000000 /* device needs msi workaround */
107 NvRegIrqStatus = 0x000,
108 #define NVREG_IRQSTAT_MIIEVENT 0x040
109 #define NVREG_IRQSTAT_MASK 0x83ff
110 NvRegIrqMask = 0x004,
111 #define NVREG_IRQ_RX_ERROR 0x0001
112 #define NVREG_IRQ_RX 0x0002
113 #define NVREG_IRQ_RX_NOBUF 0x0004
114 #define NVREG_IRQ_TX_ERR 0x0008
115 #define NVREG_IRQ_TX_OK 0x0010
116 #define NVREG_IRQ_TIMER 0x0020
117 #define NVREG_IRQ_LINK 0x0040
118 #define NVREG_IRQ_RX_FORCED 0x0080
119 #define NVREG_IRQ_TX_FORCED 0x0100
120 #define NVREG_IRQ_RECOVER_ERROR 0x8200
121 #define NVREG_IRQMASK_THROUGHPUT 0x00df
122 #define NVREG_IRQMASK_CPU 0x0060
123 #define NVREG_IRQ_TX_ALL (NVREG_IRQ_TX_ERR|NVREG_IRQ_TX_OK|NVREG_IRQ_TX_FORCED)
124 #define NVREG_IRQ_RX_ALL (NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_RX_FORCED)
125 #define NVREG_IRQ_OTHER (NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_RECOVER_ERROR)
127 NvRegUnknownSetupReg6 = 0x008,
128 #define NVREG_UNKSETUP6_VAL 3
131 * NVREG_POLL_DEFAULT is the interval length of the timer source on the nic
132 * NVREG_POLL_DEFAULT=97 would result in an interval length of 1 ms
134 NvRegPollingInterval = 0x00c,
135 #define NVREG_POLL_DEFAULT_THROUGHPUT 65535 /* backup tx cleanup if loop max reached */
136 #define NVREG_POLL_DEFAULT_CPU 13
137 NvRegMSIMap0 = 0x020,
138 NvRegMSIMap1 = 0x024,
139 NvRegMSIIrqMask = 0x030,
140 #define NVREG_MSI_VECTOR_0_ENABLED 0x01
142 #define NVREG_MISC1_PAUSE_TX 0x01
143 #define NVREG_MISC1_HD 0x02
144 #define NVREG_MISC1_FORCE 0x3b0f3c
146 NvRegMacReset = 0x34,
147 #define NVREG_MAC_RESET_ASSERT 0x0F3
148 NvRegTransmitterControl = 0x084,
149 #define NVREG_XMITCTL_START 0x01
150 #define NVREG_XMITCTL_MGMT_ST 0x40000000
151 #define NVREG_XMITCTL_SYNC_MASK 0x000f0000
152 #define NVREG_XMITCTL_SYNC_NOT_READY 0x0
153 #define NVREG_XMITCTL_SYNC_PHY_INIT 0x00040000
154 #define NVREG_XMITCTL_MGMT_SEMA_MASK 0x00000f00
155 #define NVREG_XMITCTL_MGMT_SEMA_FREE 0x0
156 #define NVREG_XMITCTL_HOST_SEMA_MASK 0x0000f000
157 #define NVREG_XMITCTL_HOST_SEMA_ACQ 0x0000f000
158 #define NVREG_XMITCTL_HOST_LOADED 0x00004000
159 #define NVREG_XMITCTL_TX_PATH_EN 0x01000000
160 #define NVREG_XMITCTL_DATA_START 0x00100000
161 #define NVREG_XMITCTL_DATA_READY 0x00010000
162 #define NVREG_XMITCTL_DATA_ERROR 0x00020000
163 NvRegTransmitterStatus = 0x088,
164 #define NVREG_XMITSTAT_BUSY 0x01
166 NvRegPacketFilterFlags = 0x8c,
167 #define NVREG_PFF_PAUSE_RX 0x08
168 #define NVREG_PFF_ALWAYS 0x7F0000
169 #define NVREG_PFF_PROMISC 0x80
170 #define NVREG_PFF_MYADDR 0x20
171 #define NVREG_PFF_LOOPBACK 0x10
173 NvRegOffloadConfig = 0x90,
174 #define NVREG_OFFLOAD_HOMEPHY 0x601
175 #define NVREG_OFFLOAD_NORMAL RX_NIC_BUFSIZE
176 NvRegReceiverControl = 0x094,
177 #define NVREG_RCVCTL_START 0x01
178 #define NVREG_RCVCTL_RX_PATH_EN 0x01000000
179 NvRegReceiverStatus = 0x98,
180 #define NVREG_RCVSTAT_BUSY 0x01
182 NvRegSlotTime = 0x9c,
183 #define NVREG_SLOTTIME_LEGBF_ENABLED 0x80000000
184 #define NVREG_SLOTTIME_10_100_FULL 0x00007f00
185 #define NVREG_SLOTTIME_1000_FULL 0x0003ff00
186 #define NVREG_SLOTTIME_HALF 0x0000ff00
187 #define NVREG_SLOTTIME_DEFAULT 0x00007f00
188 #define NVREG_SLOTTIME_MASK 0x000000ff
190 NvRegTxDeferral = 0xA0,
191 #define NVREG_TX_DEFERRAL_DEFAULT 0x15050f
192 #define NVREG_TX_DEFERRAL_RGMII_10_100 0x16070f
193 #define NVREG_TX_DEFERRAL_RGMII_1000 0x14050f
194 #define NVREG_TX_DEFERRAL_RGMII_STRETCH_10 0x16190f
195 #define NVREG_TX_DEFERRAL_RGMII_STRETCH_100 0x16300f
196 #define NVREG_TX_DEFERRAL_MII_STRETCH 0x152000
197 NvRegRxDeferral = 0xA4,
198 #define NVREG_RX_DEFERRAL_DEFAULT 0x16
199 NvRegMacAddrA = 0xA8,
200 NvRegMacAddrB = 0xAC,
201 NvRegMulticastAddrA = 0xB0,
202 #define NVREG_MCASTADDRA_FORCE 0x01
203 NvRegMulticastAddrB = 0xB4,
204 NvRegMulticastMaskA = 0xB8,
205 #define NVREG_MCASTMASKA_NONE 0xffffffff
206 NvRegMulticastMaskB = 0xBC,
207 #define NVREG_MCASTMASKB_NONE 0xffff
209 NvRegPhyInterface = 0xC0,
210 #define PHY_RGMII 0x10000000
211 NvRegBackOffControl = 0xC4,
212 #define NVREG_BKOFFCTRL_DEFAULT 0x70000000
213 #define NVREG_BKOFFCTRL_SEED_MASK 0x000003ff
214 #define NVREG_BKOFFCTRL_SELECT 24
215 #define NVREG_BKOFFCTRL_GEAR 12
217 NvRegTxRingPhysAddr = 0x100,
218 NvRegRxRingPhysAddr = 0x104,
219 NvRegRingSizes = 0x108,
220 #define NVREG_RINGSZ_TXSHIFT 0
221 #define NVREG_RINGSZ_RXSHIFT 16
222 NvRegTransmitPoll = 0x10c,
223 #define NVREG_TRANSMITPOLL_MAC_ADDR_REV 0x00008000
224 NvRegLinkSpeed = 0x110,
225 #define NVREG_LINKSPEED_FORCE 0x10000
226 #define NVREG_LINKSPEED_10 1000
227 #define NVREG_LINKSPEED_100 100
228 #define NVREG_LINKSPEED_1000 50
229 #define NVREG_LINKSPEED_MASK (0xFFF)
230 NvRegUnknownSetupReg5 = 0x130,
231 #define NVREG_UNKSETUP5_BIT31 (1<<31)
232 NvRegTxWatermark = 0x13c,
233 #define NVREG_TX_WM_DESC1_DEFAULT 0x0200010
234 #define NVREG_TX_WM_DESC2_3_DEFAULT 0x1e08000
235 #define NVREG_TX_WM_DESC2_3_1000 0xfe08000
236 NvRegTxRxControl = 0x144,
237 #define NVREG_TXRXCTL_KICK 0x0001
238 #define NVREG_TXRXCTL_BIT1 0x0002
239 #define NVREG_TXRXCTL_BIT2 0x0004
240 #define NVREG_TXRXCTL_IDLE 0x0008
241 #define NVREG_TXRXCTL_RESET 0x0010
242 #define NVREG_TXRXCTL_RXCHECK 0x0400
243 #define NVREG_TXRXCTL_DESC_1 0
244 #define NVREG_TXRXCTL_DESC_2 0x002100
245 #define NVREG_TXRXCTL_DESC_3 0xc02200
246 #define NVREG_TXRXCTL_VLANSTRIP 0x00040
247 #define NVREG_TXRXCTL_VLANINS 0x00080
248 NvRegTxRingPhysAddrHigh = 0x148,
249 NvRegRxRingPhysAddrHigh = 0x14C,
250 NvRegTxPauseFrame = 0x170,
251 #define NVREG_TX_PAUSEFRAME_DISABLE 0x0fff0080
252 #define NVREG_TX_PAUSEFRAME_ENABLE_V1 0x01800010
253 #define NVREG_TX_PAUSEFRAME_ENABLE_V2 0x056003f0
254 #define NVREG_TX_PAUSEFRAME_ENABLE_V3 0x09f00880
255 NvRegTxPauseFrameLimit = 0x174,
256 #define NVREG_TX_PAUSEFRAMELIMIT_ENABLE 0x00010000
257 NvRegMIIStatus = 0x180,
258 #define NVREG_MIISTAT_ERROR 0x0001
259 #define NVREG_MIISTAT_LINKCHANGE 0x0008
260 #define NVREG_MIISTAT_MASK_RW 0x0007
261 #define NVREG_MIISTAT_MASK_ALL 0x000f
262 NvRegMIIMask = 0x184,
263 #define NVREG_MII_LINKCHANGE 0x0008
265 NvRegAdapterControl = 0x188,
266 #define NVREG_ADAPTCTL_START 0x02
267 #define NVREG_ADAPTCTL_LINKUP 0x04
268 #define NVREG_ADAPTCTL_PHYVALID 0x40000
269 #define NVREG_ADAPTCTL_RUNNING 0x100000
270 #define NVREG_ADAPTCTL_PHYSHIFT 24
271 NvRegMIISpeed = 0x18c,
272 #define NVREG_MIISPEED_BIT8 (1<<8)
273 #define NVREG_MIIDELAY 5
274 NvRegMIIControl = 0x190,
275 #define NVREG_MIICTL_INUSE 0x08000
276 #define NVREG_MIICTL_WRITE 0x00400
277 #define NVREG_MIICTL_ADDRSHIFT 5
278 NvRegMIIData = 0x194,
279 NvRegTxUnicast = 0x1a0,
280 NvRegTxMulticast = 0x1a4,
281 NvRegTxBroadcast = 0x1a8,
282 NvRegWakeUpFlags = 0x200,
283 #define NVREG_WAKEUPFLAGS_VAL 0x7770
284 #define NVREG_WAKEUPFLAGS_BUSYSHIFT 24
285 #define NVREG_WAKEUPFLAGS_ENABLESHIFT 16
286 #define NVREG_WAKEUPFLAGS_D3SHIFT 12
287 #define NVREG_WAKEUPFLAGS_D2SHIFT 8
288 #define NVREG_WAKEUPFLAGS_D1SHIFT 4
289 #define NVREG_WAKEUPFLAGS_D0SHIFT 0
290 #define NVREG_WAKEUPFLAGS_ACCEPT_MAGPAT 0x01
291 #define NVREG_WAKEUPFLAGS_ACCEPT_WAKEUPPAT 0x02
292 #define NVREG_WAKEUPFLAGS_ACCEPT_LINKCHANGE 0x04
293 #define NVREG_WAKEUPFLAGS_ENABLE 0x1111
295 NvRegMgmtUnitGetVersion = 0x204,
296 #define NVREG_MGMTUNITGETVERSION 0x01
297 NvRegMgmtUnitVersion = 0x208,
298 #define NVREG_MGMTUNITVERSION 0x08
299 NvRegPowerCap = 0x268,
300 #define NVREG_POWERCAP_D3SUPP (1<<30)
301 #define NVREG_POWERCAP_D2SUPP (1<<26)
302 #define NVREG_POWERCAP_D1SUPP (1<<25)
303 NvRegPowerState = 0x26c,
304 #define NVREG_POWERSTATE_POWEREDUP 0x8000
305 #define NVREG_POWERSTATE_VALID 0x0100
306 #define NVREG_POWERSTATE_MASK 0x0003
307 #define NVREG_POWERSTATE_D0 0x0000
308 #define NVREG_POWERSTATE_D1 0x0001
309 #define NVREG_POWERSTATE_D2 0x0002
310 #define NVREG_POWERSTATE_D3 0x0003
311 NvRegMgmtUnitControl = 0x278,
312 #define NVREG_MGMTUNITCONTROL_INUSE 0x20000
314 NvRegTxZeroReXmt = 0x284,
315 NvRegTxOneReXmt = 0x288,
316 NvRegTxManyReXmt = 0x28c,
317 NvRegTxLateCol = 0x290,
318 NvRegTxUnderflow = 0x294,
319 NvRegTxLossCarrier = 0x298,
320 NvRegTxExcessDef = 0x29c,
321 NvRegTxRetryErr = 0x2a0,
322 NvRegRxFrameErr = 0x2a4,
323 NvRegRxExtraByte = 0x2a8,
324 NvRegRxLateCol = 0x2ac,
326 NvRegRxFrameTooLong = 0x2b4,
327 NvRegRxOverflow = 0x2b8,
328 NvRegRxFCSErr = 0x2bc,
329 NvRegRxFrameAlignErr = 0x2c0,
330 NvRegRxLenErr = 0x2c4,
331 NvRegRxUnicast = 0x2c8,
332 NvRegRxMulticast = 0x2cc,
333 NvRegRxBroadcast = 0x2d0,
335 NvRegTxFrame = 0x2d8,
337 NvRegTxPause = 0x2e0,
338 NvRegRxPause = 0x2e4,
339 NvRegRxDropFrame = 0x2e8,
340 NvRegVlanControl = 0x300,
341 #define NVREG_VLANCONTROL_ENABLE 0x2000
342 NvRegMSIXMap0 = 0x3e0,
343 NvRegMSIXMap1 = 0x3e4,
344 NvRegMSIXIrqStatus = 0x3f0,
346 NvRegPowerState2 = 0x600,
347 #define NVREG_POWERSTATE2_POWERUP_MASK 0x0F15
348 #define NVREG_POWERSTATE2_POWERUP_REV_A3 0x0001
349 #define NVREG_POWERSTATE2_PHY_RESET 0x0004
350 #define NVREG_POWERSTATE2_GATE_CLOCKS 0x0F00
353 /* Big endian: should work, but is untested */
359 struct ring_desc_ex {
367 struct ring_desc* orig;
368 struct ring_desc_ex* ex;
371 #define FLAG_MASK_V1 0xffff0000
372 #define FLAG_MASK_V2 0xffffc000
373 #define LEN_MASK_V1 (0xffffffff ^ FLAG_MASK_V1)
374 #define LEN_MASK_V2 (0xffffffff ^ FLAG_MASK_V2)
376 #define NV_TX_LASTPACKET (1<<16)
377 #define NV_TX_RETRYERROR (1<<19)
378 #define NV_TX_RETRYCOUNT_MASK (0xF<<20)
379 #define NV_TX_FORCED_INTERRUPT (1<<24)
380 #define NV_TX_DEFERRED (1<<26)
381 #define NV_TX_CARRIERLOST (1<<27)
382 #define NV_TX_LATECOLLISION (1<<28)
383 #define NV_TX_UNDERFLOW (1<<29)
384 #define NV_TX_ERROR (1<<30)
385 #define NV_TX_VALID (1<<31)
387 #define NV_TX2_LASTPACKET (1<<29)
388 #define NV_TX2_RETRYERROR (1<<18)
389 #define NV_TX2_RETRYCOUNT_MASK (0xF<<19)
390 #define NV_TX2_FORCED_INTERRUPT (1<<30)
391 #define NV_TX2_DEFERRED (1<<25)
392 #define NV_TX2_CARRIERLOST (1<<26)
393 #define NV_TX2_LATECOLLISION (1<<27)
394 #define NV_TX2_UNDERFLOW (1<<28)
395 /* error and valid are the same for both */
396 #define NV_TX2_ERROR (1<<30)
397 #define NV_TX2_VALID (1<<31)
398 #define NV_TX2_TSO (1<<28)
399 #define NV_TX2_TSO_SHIFT 14
400 #define NV_TX2_TSO_MAX_SHIFT 14
401 #define NV_TX2_TSO_MAX_SIZE (1<<NV_TX2_TSO_MAX_SHIFT)
402 #define NV_TX2_CHECKSUM_L3 (1<<27)
403 #define NV_TX2_CHECKSUM_L4 (1<<26)
405 #define NV_TX3_VLAN_TAG_PRESENT (1<<18)
407 #define NV_RX_DESCRIPTORVALID (1<<16)
408 #define NV_RX_MISSEDFRAME (1<<17)
409 #define NV_RX_SUBSTRACT1 (1<<18)
410 #define NV_RX_ERROR1 (1<<23)
411 #define NV_RX_ERROR2 (1<<24)
412 #define NV_RX_ERROR3 (1<<25)
413 #define NV_RX_ERROR4 (1<<26)
414 #define NV_RX_CRCERR (1<<27)
415 #define NV_RX_OVERFLOW (1<<28)
416 #define NV_RX_FRAMINGERR (1<<29)
417 #define NV_RX_ERROR (1<<30)
418 #define NV_RX_AVAIL (1<<31)
419 #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)
421 #define NV_RX2_CHECKSUMMASK (0x1C000000)
422 #define NV_RX2_CHECKSUM_IP (0x10000000)
423 #define NV_RX2_CHECKSUM_IP_TCP (0x14000000)
424 #define NV_RX2_CHECKSUM_IP_UDP (0x18000000)
425 #define NV_RX2_DESCRIPTORVALID (1<<29)
426 #define NV_RX2_SUBSTRACT1 (1<<25)
427 #define NV_RX2_ERROR1 (1<<18)
428 #define NV_RX2_ERROR2 (1<<19)
429 #define NV_RX2_ERROR3 (1<<20)
430 #define NV_RX2_ERROR4 (1<<21)
431 #define NV_RX2_CRCERR (1<<22)
432 #define NV_RX2_OVERFLOW (1<<23)
433 #define NV_RX2_FRAMINGERR (1<<24)
434 /* error and avail are the same for both */
435 #define NV_RX2_ERROR (1<<30)
436 #define NV_RX2_AVAIL (1<<31)
437 #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)
439 #define NV_RX3_VLAN_TAG_PRESENT (1<<16)
440 #define NV_RX3_VLAN_TAG_MASK (0x0000FFFF)
442 /* Miscelaneous hardware related defines: */
443 #define NV_PCI_REGSZ_VER1 0x270
444 #define NV_PCI_REGSZ_VER2 0x2d4
445 #define NV_PCI_REGSZ_VER3 0x604
446 #define NV_PCI_REGSZ_MAX 0x604
448 /* various timeout delays: all in usec */
449 #define NV_TXRX_RESET_DELAY 4
450 #define NV_TXSTOP_DELAY1 10
451 #define NV_TXSTOP_DELAY1MAX 500000
452 #define NV_TXSTOP_DELAY2 100
453 #define NV_RXSTOP_DELAY1 10
454 #define NV_RXSTOP_DELAY1MAX 500000
455 #define NV_RXSTOP_DELAY2 100
456 #define NV_SETUP5_DELAY 5
457 #define NV_SETUP5_DELAYMAX 50000
458 #define NV_POWERUP_DELAY 5
459 #define NV_POWERUP_DELAYMAX 5000
460 #define NV_MIIBUSY_DELAY 50
461 #define NV_MIIPHY_DELAY 10
462 #define NV_MIIPHY_DELAYMAX 10000
463 #define NV_MAC_RESET_DELAY 64
465 #define NV_WAKEUPPATTERNS 5
466 #define NV_WAKEUPMASKENTRIES 4
468 /* General driver defaults */
469 #define NV_WATCHDOG_TIMEO (5*HZ)
471 #define RX_RING_DEFAULT 512
472 #define TX_RING_DEFAULT 256
473 #define RX_RING_MIN 128
474 #define TX_RING_MIN 64
475 #define RING_MAX_DESC_VER_1 1024
476 #define RING_MAX_DESC_VER_2_3 16384
478 /* rx/tx mac addr + type + vlan + align + slack*/
479 #define NV_RX_HEADERS (64)
480 /* even more slack. */
481 #define NV_RX_ALLOC_PAD (64)
483 /* maximum mtu size */
484 #define NV_PKTLIMIT_1 ETH_DATA_LEN /* hard limit not known */
485 #define NV_PKTLIMIT_2 9100 /* Actual limit according to NVidia: 9202 */
487 #define OOM_REFILL (1+HZ/20)
488 #define POLL_WAIT (1+HZ/100)
489 #define LINK_TIMEOUT (3*HZ)
490 #define STATS_INTERVAL (10*HZ)
494 * The nic supports three different descriptor types:
495 * - DESC_VER_1: Original
496 * - DESC_VER_2: support for jumbo frames.
497 * - DESC_VER_3: 64-bit format.
504 #define PHY_OUI_MARVELL 0x5043
505 #define PHY_OUI_CICADA 0x03f1
506 #define PHY_OUI_VITESSE 0x01c1
507 #define PHY_OUI_REALTEK 0x0732
508 #define PHY_OUI_REALTEK2 0x0020
509 #define PHYID1_OUI_MASK 0x03ff
510 #define PHYID1_OUI_SHFT 6
511 #define PHYID2_OUI_MASK 0xfc00
512 #define PHYID2_OUI_SHFT 10
513 #define PHYID2_MODEL_MASK 0x03f0
514 #define PHY_MODEL_REALTEK_8211 0x0110
515 #define PHY_REV_MASK 0x0001
516 #define PHY_REV_REALTEK_8211B 0x0000
517 #define PHY_REV_REALTEK_8211C 0x0001
518 #define PHY_MODEL_REALTEK_8201 0x0200
519 #define PHY_MODEL_MARVELL_E3016 0x0220
520 #define PHY_MARVELL_E3016_INITMASK 0x0300
521 #define PHY_CICADA_INIT1 0x0f000
522 #define PHY_CICADA_INIT2 0x0e00
523 #define PHY_CICADA_INIT3 0x01000
524 #define PHY_CICADA_INIT4 0x0200
525 #define PHY_CICADA_INIT5 0x0004
526 #define PHY_CICADA_INIT6 0x02000
527 #define PHY_VITESSE_INIT_REG1 0x1f
528 #define PHY_VITESSE_INIT_REG2 0x10
529 #define PHY_VITESSE_INIT_REG3 0x11
530 #define PHY_VITESSE_INIT_REG4 0x12
531 #define PHY_VITESSE_INIT_MSK1 0xc
532 #define PHY_VITESSE_INIT_MSK2 0x0180
533 #define PHY_VITESSE_INIT1 0x52b5
534 #define PHY_VITESSE_INIT2 0xaf8a
535 #define PHY_VITESSE_INIT3 0x8
536 #define PHY_VITESSE_INIT4 0x8f8a
537 #define PHY_VITESSE_INIT5 0xaf86
538 #define PHY_VITESSE_INIT6 0x8f86
539 #define PHY_VITESSE_INIT7 0xaf82
540 #define PHY_VITESSE_INIT8 0x0100
541 #define PHY_VITESSE_INIT9 0x8f82
542 #define PHY_VITESSE_INIT10 0x0
543 #define PHY_REALTEK_INIT_REG1 0x1f
544 #define PHY_REALTEK_INIT_REG2 0x19
545 #define PHY_REALTEK_INIT_REG3 0x13
546 #define PHY_REALTEK_INIT_REG4 0x14
547 #define PHY_REALTEK_INIT_REG5 0x18
548 #define PHY_REALTEK_INIT_REG6 0x11
549 #define PHY_REALTEK_INIT_REG7 0x01
550 #define PHY_REALTEK_INIT1 0x0000
551 #define PHY_REALTEK_INIT2 0x8e00
552 #define PHY_REALTEK_INIT3 0x0001
553 #define PHY_REALTEK_INIT4 0xad17
554 #define PHY_REALTEK_INIT5 0xfb54
555 #define PHY_REALTEK_INIT6 0xf5c7
556 #define PHY_REALTEK_INIT7 0x1000
557 #define PHY_REALTEK_INIT8 0x0003
558 #define PHY_REALTEK_INIT9 0x0008
559 #define PHY_REALTEK_INIT10 0x0005
560 #define PHY_REALTEK_INIT11 0x0200
561 #define PHY_REALTEK_INIT_MSK1 0x0003
563 #define PHY_GIGABIT 0x0100
565 #define PHY_TIMEOUT 0x1
566 #define PHY_ERROR 0x2
570 #define PHY_HALF 0x100
572 #define NV_PAUSEFRAME_RX_CAPABLE 0x0001
573 #define NV_PAUSEFRAME_TX_CAPABLE 0x0002
574 #define NV_PAUSEFRAME_RX_ENABLE 0x0004
575 #define NV_PAUSEFRAME_TX_ENABLE 0x0008
576 #define NV_PAUSEFRAME_RX_REQ 0x0010
577 #define NV_PAUSEFRAME_TX_REQ 0x0020
578 #define NV_PAUSEFRAME_AUTONEG 0x0040
580 /* MSI/MSI-X defines */
581 #define NV_MSI_X_MAX_VECTORS 8
582 #define NV_MSI_X_VECTORS_MASK 0x000f
583 #define NV_MSI_CAPABLE 0x0010
584 #define NV_MSI_X_CAPABLE 0x0020
585 #define NV_MSI_ENABLED 0x0040
586 #define NV_MSI_X_ENABLED 0x0080
588 #define NV_MSI_X_VECTOR_ALL 0x0
589 #define NV_MSI_X_VECTOR_RX 0x0
590 #define NV_MSI_X_VECTOR_TX 0x1
591 #define NV_MSI_X_VECTOR_OTHER 0x2
593 #define NV_MSI_PRIV_OFFSET 0x68
594 #define NV_MSI_PRIV_VALUE 0xffffffff
596 #define NV_RESTART_TX 0x1
597 #define NV_RESTART_RX 0x2
599 #define NV_TX_LIMIT_COUNT 16
601 #define NV_DYNAMIC_THRESHOLD 4
602 #define NV_DYNAMIC_MAX_QUIET_COUNT 2048
605 struct nv_ethtool_str {
606 char name[ETH_GSTRING_LEN];
609 static const struct nv_ethtool_str nv_estats_str[] = {
614 { "tx_late_collision" },
615 { "tx_fifo_errors" },
616 { "tx_carrier_errors" },
617 { "tx_excess_deferral" },
618 { "tx_retry_error" },
619 { "rx_frame_error" },
621 { "rx_late_collision" },
623 { "rx_frame_too_long" },
624 { "rx_over_errors" },
626 { "rx_frame_align_error" },
627 { "rx_length_error" },
632 { "rx_errors_total" },
633 { "tx_errors_total" },
635 /* version 2 stats */
643 /* version 3 stats */
649 struct nv_ethtool_stats {
654 u64 tx_late_collision;
656 u64 tx_carrier_errors;
657 u64 tx_excess_deferral;
661 u64 rx_late_collision;
663 u64 rx_frame_too_long;
666 u64 rx_frame_align_error;
675 /* version 2 stats */
683 /* version 3 stats */
689 #define NV_DEV_STATISTICS_V3_COUNT (sizeof(struct nv_ethtool_stats)/sizeof(u64))
690 #define NV_DEV_STATISTICS_V2_COUNT (NV_DEV_STATISTICS_V3_COUNT - 3)
691 #define NV_DEV_STATISTICS_V1_COUNT (NV_DEV_STATISTICS_V2_COUNT - 6)
694 #define NV_TEST_COUNT_BASE 3
695 #define NV_TEST_COUNT_EXTENDED 4
697 static const struct nv_ethtool_str nv_etests_str[] = {
698 { "link (online/offline)" },
699 { "register (offline) " },
700 { "interrupt (offline) " },
701 { "loopback (offline) " }
704 struct register_test {
709 static const struct register_test nv_registers_test[] = {
710 { NvRegUnknownSetupReg6, 0x01 },
711 { NvRegMisc1, 0x03c },
712 { NvRegOffloadConfig, 0x03ff },
713 { NvRegMulticastAddrA, 0xffffffff },
714 { NvRegTxWatermark, 0x0ff },
715 { NvRegWakeUpFlags, 0x07777 },
722 unsigned int dma_len;
723 struct ring_desc_ex *first_tx_desc;
724 struct nv_skb_map *next_tx_ctx;
729 * All hardware access under netdev_priv(dev)->lock, except the performance
731 * - rx is (pseudo-) lockless: it relies on the single-threading provided
732 * by the arch code for interrupts.
733 * - tx setup is lockless: it relies on netif_tx_lock. Actual submission
734 * needs netdev_priv(dev)->lock :-(
735 * - set_multicast_list: preparation lockless, relies on netif_tx_lock.
738 /* in dev: base, irq */
742 struct net_device *dev;
743 struct napi_struct napi;
746 * Locking: spin_lock(&np->lock); */
747 struct nv_ethtool_stats estats;
755 unsigned int phy_oui;
756 unsigned int phy_model;
757 unsigned int phy_rev;
763 /* General data: RO fields */
764 dma_addr_t ring_addr;
765 struct pci_dev *pci_dev;
782 /* rx specific fields.
783 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
785 union ring_type get_rx, put_rx, first_rx, last_rx;
786 struct nv_skb_map *get_rx_ctx, *put_rx_ctx;
787 struct nv_skb_map *first_rx_ctx, *last_rx_ctx;
788 struct nv_skb_map *rx_skb;
790 union ring_type rx_ring;
791 unsigned int rx_buf_sz;
792 unsigned int pkt_limit;
793 struct timer_list oom_kick;
794 struct timer_list nic_poll;
795 struct timer_list stats_poll;
799 /* media detection workaround.
800 * Locking: Within irq hander or disable_irq+spin_lock(&np->lock);
803 unsigned long link_timeout;
805 * tx specific fields.
807 union ring_type get_tx, put_tx, first_tx, last_tx;
808 struct nv_skb_map *get_tx_ctx, *put_tx_ctx;
809 struct nv_skb_map *first_tx_ctx, *last_tx_ctx;
810 struct nv_skb_map *tx_skb;
812 union ring_type tx_ring;
816 u32 tx_pkts_in_progress;
817 struct nv_skb_map *tx_change_owner;
818 struct nv_skb_map *tx_end_flip;
822 struct vlan_group *vlangrp;
824 /* msi/msi-x fields */
826 struct msix_entry msi_x_entry[NV_MSI_X_MAX_VECTORS];
831 /* power saved state */
832 u32 saved_config_space[NV_PCI_REGSZ_MAX/4];
834 /* for different msi-x irq type */
835 char name_rx[IFNAMSIZ + 3]; /* -rx */
836 char name_tx[IFNAMSIZ + 3]; /* -tx */
837 char name_other[IFNAMSIZ + 6]; /* -other */
841 * Maximum number of loops until we assume that a bit in the irq mask
842 * is stuck. Overridable with module param.
844 static int max_interrupt_work = 4;
847 * Optimization can be either throuput mode or cpu mode
849 * Throughput Mode: Every tx and rx packet will generate an interrupt.
850 * CPU Mode: Interrupts are controlled by a timer.
853 NV_OPTIMIZATION_MODE_THROUGHPUT,
854 NV_OPTIMIZATION_MODE_CPU,
855 NV_OPTIMIZATION_MODE_DYNAMIC
857 static int optimization_mode = NV_OPTIMIZATION_MODE_DYNAMIC;
860 * Poll interval for timer irq
862 * This interval determines how frequent an interrupt is generated.
863 * The is value is determined by [(time_in_micro_secs * 100) / (2^10)]
864 * Min = 0, and Max = 65535
866 static int poll_interval = -1;
875 static int msi = NV_MSI_INT_ENABLED;
881 NV_MSIX_INT_DISABLED,
884 static int msix = NV_MSIX_INT_ENABLED;
890 NV_DMA_64BIT_DISABLED,
893 static int dma_64bit = NV_DMA_64BIT_ENABLED;
896 * Crossover Detection
897 * Realtek 8201 phy + some OEM boards do not work properly.
900 NV_CROSSOVER_DETECTION_DISABLED,
901 NV_CROSSOVER_DETECTION_ENABLED
903 static int phy_cross = NV_CROSSOVER_DETECTION_DISABLED;
906 * Power down phy when interface is down (persists through reboot;
907 * older Linux and other OSes may not power it up again)
909 static int phy_power_down = 0;
911 static inline struct fe_priv *get_nvpriv(struct net_device *dev)
913 return netdev_priv(dev);
916 static inline u8 __iomem *get_hwbase(struct net_device *dev)
918 return ((struct fe_priv *)netdev_priv(dev))->base;
921 static inline void pci_push(u8 __iomem *base)
923 /* force out pending posted writes */
927 static inline u32 nv_descr_getlength(struct ring_desc *prd, u32 v)
929 return le32_to_cpu(prd->flaglen)
930 & ((v == DESC_VER_1) ? LEN_MASK_V1 : LEN_MASK_V2);
933 static inline u32 nv_descr_getlength_ex(struct ring_desc_ex *prd, u32 v)
935 return le32_to_cpu(prd->flaglen) & LEN_MASK_V2;
938 static bool nv_optimized(struct fe_priv *np)
940 if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2)
945 static int reg_delay(struct net_device *dev, int offset, u32 mask, u32 target,
946 int delay, int delaymax, const char *msg)
948 u8 __iomem *base = get_hwbase(dev);
959 } while ((readl(base + offset) & mask) != target);
963 #define NV_SETUP_RX_RING 0x01
964 #define NV_SETUP_TX_RING 0x02
966 static inline u32 dma_low(dma_addr_t addr)
971 static inline u32 dma_high(dma_addr_t addr)
973 return addr>>31>>1; /* 0 if 32bit, shift down by 32 if 64bit */
976 static void setup_hw_rings(struct net_device *dev, int rxtx_flags)
978 struct fe_priv *np = get_nvpriv(dev);
979 u8 __iomem *base = get_hwbase(dev);
981 if (!nv_optimized(np)) {
982 if (rxtx_flags & NV_SETUP_RX_RING) {
983 writel(dma_low(np->ring_addr), base + NvRegRxRingPhysAddr);
985 if (rxtx_flags & NV_SETUP_TX_RING) {
986 writel(dma_low(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr);
989 if (rxtx_flags & NV_SETUP_RX_RING) {
990 writel(dma_low(np->ring_addr), base + NvRegRxRingPhysAddr);
991 writel(dma_high(np->ring_addr), base + NvRegRxRingPhysAddrHigh);
993 if (rxtx_flags & NV_SETUP_TX_RING) {
994 writel(dma_low(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr);
995 writel(dma_high(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddrHigh);
1000 static void free_rings(struct net_device *dev)
1002 struct fe_priv *np = get_nvpriv(dev);
1004 if (!nv_optimized(np)) {
1005 if (np->rx_ring.orig)
1006 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
1007 np->rx_ring.orig, np->ring_addr);
1010 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
1011 np->rx_ring.ex, np->ring_addr);
1019 static int using_multi_irqs(struct net_device *dev)
1021 struct fe_priv *np = get_nvpriv(dev);
1023 if (!(np->msi_flags & NV_MSI_X_ENABLED) ||
1024 ((np->msi_flags & NV_MSI_X_ENABLED) &&
1025 ((np->msi_flags & NV_MSI_X_VECTORS_MASK) == 0x1)))
1031 static void nv_txrx_gate(struct net_device *dev, bool gate)
1033 struct fe_priv *np = get_nvpriv(dev);
1034 u8 __iomem *base = get_hwbase(dev);
1037 if (!np->mac_in_use &&
1038 (np->driver_data & DEV_HAS_POWER_CNTRL)) {
1039 powerstate = readl(base + NvRegPowerState2);
1041 powerstate |= NVREG_POWERSTATE2_GATE_CLOCKS;
1043 powerstate &= ~NVREG_POWERSTATE2_GATE_CLOCKS;
1044 writel(powerstate, base + NvRegPowerState2);
1048 static void nv_enable_irq(struct net_device *dev)
1050 struct fe_priv *np = get_nvpriv(dev);
1052 if (!using_multi_irqs(dev)) {
1053 if (np->msi_flags & NV_MSI_X_ENABLED)
1054 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1056 enable_irq(np->pci_dev->irq);
1058 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1059 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
1060 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
1064 static void nv_disable_irq(struct net_device *dev)
1066 struct fe_priv *np = get_nvpriv(dev);
1068 if (!using_multi_irqs(dev)) {
1069 if (np->msi_flags & NV_MSI_X_ENABLED)
1070 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1072 disable_irq(np->pci_dev->irq);
1074 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1075 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
1076 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
1080 /* In MSIX mode, a write to irqmask behaves as XOR */
1081 static void nv_enable_hw_interrupts(struct net_device *dev, u32 mask)
1083 u8 __iomem *base = get_hwbase(dev);
1085 writel(mask, base + NvRegIrqMask);
1088 static void nv_disable_hw_interrupts(struct net_device *dev, u32 mask)
1090 struct fe_priv *np = get_nvpriv(dev);
1091 u8 __iomem *base = get_hwbase(dev);
1093 if (np->msi_flags & NV_MSI_X_ENABLED) {
1094 writel(mask, base + NvRegIrqMask);
1096 if (np->msi_flags & NV_MSI_ENABLED)
1097 writel(0, base + NvRegMSIIrqMask);
1098 writel(0, base + NvRegIrqMask);
1102 static void nv_napi_enable(struct net_device *dev)
1104 #ifdef CONFIG_FORCEDETH_NAPI
1105 struct fe_priv *np = get_nvpriv(dev);
1107 napi_enable(&np->napi);
1111 static void nv_napi_disable(struct net_device *dev)
1113 #ifdef CONFIG_FORCEDETH_NAPI
1114 struct fe_priv *np = get_nvpriv(dev);
1116 napi_disable(&np->napi);
1120 #define MII_READ (-1)
1121 /* mii_rw: read/write a register on the PHY.
1123 * Caller must guarantee serialization
1125 static int mii_rw(struct net_device *dev, int addr, int miireg, int value)
1127 u8 __iomem *base = get_hwbase(dev);
1131 writel(NVREG_MIISTAT_MASK_RW, base + NvRegMIIStatus);
1133 reg = readl(base + NvRegMIIControl);
1134 if (reg & NVREG_MIICTL_INUSE) {
1135 writel(NVREG_MIICTL_INUSE, base + NvRegMIIControl);
1136 udelay(NV_MIIBUSY_DELAY);
1139 reg = (addr << NVREG_MIICTL_ADDRSHIFT) | miireg;
1140 if (value != MII_READ) {
1141 writel(value, base + NvRegMIIData);
1142 reg |= NVREG_MIICTL_WRITE;
1144 writel(reg, base + NvRegMIIControl);
1146 if (reg_delay(dev, NvRegMIIControl, NVREG_MIICTL_INUSE, 0,
1147 NV_MIIPHY_DELAY, NV_MIIPHY_DELAYMAX, NULL)) {
1148 dprintk(KERN_DEBUG "%s: mii_rw of reg %d at PHY %d timed out.\n",
1149 dev->name, miireg, addr);
1151 } else if (value != MII_READ) {
1152 /* it was a write operation - fewer failures are detectable */
1153 dprintk(KERN_DEBUG "%s: mii_rw wrote 0x%x to reg %d at PHY %d\n",
1154 dev->name, value, miireg, addr);
1156 } else if (readl(base + NvRegMIIStatus) & NVREG_MIISTAT_ERROR) {
1157 dprintk(KERN_DEBUG "%s: mii_rw of reg %d at PHY %d failed.\n",
1158 dev->name, miireg, addr);
1161 retval = readl(base + NvRegMIIData);
1162 dprintk(KERN_DEBUG "%s: mii_rw read from reg %d at PHY %d: 0x%x.\n",
1163 dev->name, miireg, addr, retval);
1169 static int phy_reset(struct net_device *dev, u32 bmcr_setup)
1171 struct fe_priv *np = netdev_priv(dev);
1173 unsigned int tries = 0;
1175 miicontrol = BMCR_RESET | bmcr_setup;
1176 if (mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol)) {
1180 /* wait for 500ms */
1183 /* must wait till reset is deasserted */
1184 while (miicontrol & BMCR_RESET) {
1186 miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1187 /* FIXME: 100 tries seem excessive */
1194 static int phy_init(struct net_device *dev)
1196 struct fe_priv *np = get_nvpriv(dev);
1197 u8 __iomem *base = get_hwbase(dev);
1198 u32 phyinterface, phy_reserved, mii_status, mii_control, mii_control_1000,reg;
1200 /* phy errata for E3016 phy */
1201 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
1202 reg = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
1203 reg &= ~PHY_MARVELL_E3016_INITMASK;
1204 if (mii_rw(dev, np->phyaddr, MII_NCONFIG, reg)) {
1205 printk(KERN_INFO "%s: phy write to errata reg failed.\n", pci_name(np->pci_dev));
1209 if (np->phy_oui == PHY_OUI_REALTEK) {
1210 if (np->phy_model == PHY_MODEL_REALTEK_8211 &&
1211 np->phy_rev == PHY_REV_REALTEK_8211B) {
1212 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1213 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1216 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, PHY_REALTEK_INIT2)) {
1217 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1220 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3)) {
1221 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1224 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG3, PHY_REALTEK_INIT4)) {
1225 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1228 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG4, PHY_REALTEK_INIT5)) {
1229 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1232 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG5, PHY_REALTEK_INIT6)) {
1233 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1236 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1237 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1241 if (np->phy_model == PHY_MODEL_REALTEK_8211 &&
1242 np->phy_rev == PHY_REV_REALTEK_8211C) {
1243 u32 powerstate = readl(base + NvRegPowerState2);
1245 /* need to perform hw phy reset */
1246 powerstate |= NVREG_POWERSTATE2_PHY_RESET;
1247 writel(powerstate, base + NvRegPowerState2);
1250 powerstate &= ~NVREG_POWERSTATE2_PHY_RESET;
1251 writel(powerstate, base + NvRegPowerState2);
1254 reg = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, MII_READ);
1255 reg |= PHY_REALTEK_INIT9;
1256 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, reg)) {
1257 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1260 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT10)) {
1261 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1264 reg = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG7, MII_READ);
1265 if (!(reg & PHY_REALTEK_INIT11)) {
1266 reg |= PHY_REALTEK_INIT11;
1267 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG7, reg)) {
1268 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1272 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1273 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1277 if (np->phy_model == PHY_MODEL_REALTEK_8201) {
1278 if (np->driver_data & DEV_NEED_PHY_INIT_FIX) {
1279 phy_reserved = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, MII_READ);
1280 phy_reserved |= PHY_REALTEK_INIT7;
1281 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, phy_reserved)) {
1282 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1289 /* set advertise register */
1290 reg = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
1291 reg |= (ADVERTISE_10HALF|ADVERTISE_10FULL|ADVERTISE_100HALF|ADVERTISE_100FULL|ADVERTISE_PAUSE_ASYM|ADVERTISE_PAUSE_CAP);
1292 if (mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg)) {
1293 printk(KERN_INFO "%s: phy write to advertise failed.\n", pci_name(np->pci_dev));
1297 /* get phy interface type */
1298 phyinterface = readl(base + NvRegPhyInterface);
1300 /* see if gigabit phy */
1301 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
1302 if (mii_status & PHY_GIGABIT) {
1303 np->gigabit = PHY_GIGABIT;
1304 mii_control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
1305 mii_control_1000 &= ~ADVERTISE_1000HALF;
1306 if (phyinterface & PHY_RGMII)
1307 mii_control_1000 |= ADVERTISE_1000FULL;
1309 mii_control_1000 &= ~ADVERTISE_1000FULL;
1311 if (mii_rw(dev, np->phyaddr, MII_CTRL1000, mii_control_1000)) {
1312 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1319 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1320 mii_control |= BMCR_ANENABLE;
1322 if (np->phy_oui == PHY_OUI_REALTEK &&
1323 np->phy_model == PHY_MODEL_REALTEK_8211 &&
1324 np->phy_rev == PHY_REV_REALTEK_8211C) {
1325 /* start autoneg since we already performed hw reset above */
1326 mii_control |= BMCR_ANRESTART;
1327 if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control)) {
1328 printk(KERN_INFO "%s: phy init failed\n", pci_name(np->pci_dev));
1333 * (certain phys need bmcr to be setup with reset)
1335 if (phy_reset(dev, mii_control)) {
1336 printk(KERN_INFO "%s: phy reset failed\n", pci_name(np->pci_dev));
1341 /* phy vendor specific configuration */
1342 if ((np->phy_oui == PHY_OUI_CICADA) && (phyinterface & PHY_RGMII) ) {
1343 phy_reserved = mii_rw(dev, np->phyaddr, MII_RESV1, MII_READ);
1344 phy_reserved &= ~(PHY_CICADA_INIT1 | PHY_CICADA_INIT2);
1345 phy_reserved |= (PHY_CICADA_INIT3 | PHY_CICADA_INIT4);
1346 if (mii_rw(dev, np->phyaddr, MII_RESV1, phy_reserved)) {
1347 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1350 phy_reserved = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ);
1351 phy_reserved |= PHY_CICADA_INIT5;
1352 if (mii_rw(dev, np->phyaddr, MII_NCONFIG, phy_reserved)) {
1353 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1357 if (np->phy_oui == PHY_OUI_CICADA) {
1358 phy_reserved = mii_rw(dev, np->phyaddr, MII_SREVISION, MII_READ);
1359 phy_reserved |= PHY_CICADA_INIT6;
1360 if (mii_rw(dev, np->phyaddr, MII_SREVISION, phy_reserved)) {
1361 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1365 if (np->phy_oui == PHY_OUI_VITESSE) {
1366 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG1, PHY_VITESSE_INIT1)) {
1367 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1370 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT2)) {
1371 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1374 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, MII_READ);
1375 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved)) {
1376 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1379 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, MII_READ);
1380 phy_reserved &= ~PHY_VITESSE_INIT_MSK1;
1381 phy_reserved |= PHY_VITESSE_INIT3;
1382 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved)) {
1383 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1386 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT4)) {
1387 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1390 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT5)) {
1391 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1394 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, MII_READ);
1395 phy_reserved &= ~PHY_VITESSE_INIT_MSK1;
1396 phy_reserved |= PHY_VITESSE_INIT3;
1397 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved)) {
1398 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1401 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, MII_READ);
1402 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved)) {
1403 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1406 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT6)) {
1407 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1410 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT7)) {
1411 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1414 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, MII_READ);
1415 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved)) {
1416 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1419 phy_reserved = mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, MII_READ);
1420 phy_reserved &= ~PHY_VITESSE_INIT_MSK2;
1421 phy_reserved |= PHY_VITESSE_INIT8;
1422 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved)) {
1423 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1426 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT9)) {
1427 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1430 if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG1, PHY_VITESSE_INIT10)) {
1431 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1435 if (np->phy_oui == PHY_OUI_REALTEK) {
1436 if (np->phy_model == PHY_MODEL_REALTEK_8211 &&
1437 np->phy_rev == PHY_REV_REALTEK_8211B) {
1438 /* reset could have cleared these out, set them back */
1439 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1440 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1443 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, PHY_REALTEK_INIT2)) {
1444 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1447 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3)) {
1448 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1451 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG3, PHY_REALTEK_INIT4)) {
1452 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1455 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG4, PHY_REALTEK_INIT5)) {
1456 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1459 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG5, PHY_REALTEK_INIT6)) {
1460 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1463 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1464 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1468 if (np->phy_model == PHY_MODEL_REALTEK_8201) {
1469 if (np->driver_data & DEV_NEED_PHY_INIT_FIX) {
1470 phy_reserved = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, MII_READ);
1471 phy_reserved |= PHY_REALTEK_INIT7;
1472 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, phy_reserved)) {
1473 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1477 if (phy_cross == NV_CROSSOVER_DETECTION_DISABLED) {
1478 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3)) {
1479 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1482 phy_reserved = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, MII_READ);
1483 phy_reserved &= ~PHY_REALTEK_INIT_MSK1;
1484 phy_reserved |= PHY_REALTEK_INIT3;
1485 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, phy_reserved)) {
1486 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1489 if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) {
1490 printk(KERN_INFO "%s: phy init failed.\n", pci_name(np->pci_dev));
1497 /* some phys clear out pause advertisment on reset, set it back */
1498 mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg);
1500 /* restart auto negotiation, power down phy */
1501 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
1502 mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE);
1503 if (phy_power_down) {
1504 mii_control |= BMCR_PDOWN;
1506 if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control)) {
1513 static void nv_start_rx(struct net_device *dev)
1515 struct fe_priv *np = netdev_priv(dev);
1516 u8 __iomem *base = get_hwbase(dev);
1517 u32 rx_ctrl = readl(base + NvRegReceiverControl);
1519 dprintk(KERN_DEBUG "%s: nv_start_rx\n", dev->name);
1520 /* Already running? Stop it. */
1521 if ((readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) && !np->mac_in_use) {
1522 rx_ctrl &= ~NVREG_RCVCTL_START;
1523 writel(rx_ctrl, base + NvRegReceiverControl);
1526 writel(np->linkspeed, base + NvRegLinkSpeed);
1528 rx_ctrl |= NVREG_RCVCTL_START;
1530 rx_ctrl &= ~NVREG_RCVCTL_RX_PATH_EN;
1531 writel(rx_ctrl, base + NvRegReceiverControl);
1532 dprintk(KERN_DEBUG "%s: nv_start_rx to duplex %d, speed 0x%08x.\n",
1533 dev->name, np->duplex, np->linkspeed);
1537 static void nv_stop_rx(struct net_device *dev)
1539 struct fe_priv *np = netdev_priv(dev);
1540 u8 __iomem *base = get_hwbase(dev);
1541 u32 rx_ctrl = readl(base + NvRegReceiverControl);
1543 dprintk(KERN_DEBUG "%s: nv_stop_rx\n", dev->name);
1544 if (!np->mac_in_use)
1545 rx_ctrl &= ~NVREG_RCVCTL_START;
1547 rx_ctrl |= NVREG_RCVCTL_RX_PATH_EN;
1548 writel(rx_ctrl, base + NvRegReceiverControl);
1549 reg_delay(dev, NvRegReceiverStatus, NVREG_RCVSTAT_BUSY, 0,
1550 NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX,
1551 KERN_INFO "nv_stop_rx: ReceiverStatus remained busy");
1553 udelay(NV_RXSTOP_DELAY2);
1554 if (!np->mac_in_use)
1555 writel(0, base + NvRegLinkSpeed);
1558 static void nv_start_tx(struct net_device *dev)
1560 struct fe_priv *np = netdev_priv(dev);
1561 u8 __iomem *base = get_hwbase(dev);
1562 u32 tx_ctrl = readl(base + NvRegTransmitterControl);
1564 dprintk(KERN_DEBUG "%s: nv_start_tx\n", dev->name);
1565 tx_ctrl |= NVREG_XMITCTL_START;
1567 tx_ctrl &= ~NVREG_XMITCTL_TX_PATH_EN;
1568 writel(tx_ctrl, base + NvRegTransmitterControl);
1572 static void nv_stop_tx(struct net_device *dev)
1574 struct fe_priv *np = netdev_priv(dev);
1575 u8 __iomem *base = get_hwbase(dev);
1576 u32 tx_ctrl = readl(base + NvRegTransmitterControl);
1578 dprintk(KERN_DEBUG "%s: nv_stop_tx\n", dev->name);
1579 if (!np->mac_in_use)
1580 tx_ctrl &= ~NVREG_XMITCTL_START;
1582 tx_ctrl |= NVREG_XMITCTL_TX_PATH_EN;
1583 writel(tx_ctrl, base + NvRegTransmitterControl);
1584 reg_delay(dev, NvRegTransmitterStatus, NVREG_XMITSTAT_BUSY, 0,
1585 NV_TXSTOP_DELAY1, NV_TXSTOP_DELAY1MAX,
1586 KERN_INFO "nv_stop_tx: TransmitterStatus remained busy");
1588 udelay(NV_TXSTOP_DELAY2);
1589 if (!np->mac_in_use)
1590 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV,
1591 base + NvRegTransmitPoll);
1594 static void nv_start_rxtx(struct net_device *dev)
1600 static void nv_stop_rxtx(struct net_device *dev)
1606 static void nv_txrx_reset(struct net_device *dev)
1608 struct fe_priv *np = netdev_priv(dev);
1609 u8 __iomem *base = get_hwbase(dev);
1611 dprintk(KERN_DEBUG "%s: nv_txrx_reset\n", dev->name);
1612 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
1614 udelay(NV_TXRX_RESET_DELAY);
1615 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
1619 static void nv_mac_reset(struct net_device *dev)
1621 struct fe_priv *np = netdev_priv(dev);
1622 u8 __iomem *base = get_hwbase(dev);
1623 u32 temp1, temp2, temp3;
1625 dprintk(KERN_DEBUG "%s: nv_mac_reset\n", dev->name);
1627 writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl);
1630 /* save registers since they will be cleared on reset */
1631 temp1 = readl(base + NvRegMacAddrA);
1632 temp2 = readl(base + NvRegMacAddrB);
1633 temp3 = readl(base + NvRegTransmitPoll);
1635 writel(NVREG_MAC_RESET_ASSERT, base + NvRegMacReset);
1637 udelay(NV_MAC_RESET_DELAY);
1638 writel(0, base + NvRegMacReset);
1640 udelay(NV_MAC_RESET_DELAY);
1642 /* restore saved registers */
1643 writel(temp1, base + NvRegMacAddrA);
1644 writel(temp2, base + NvRegMacAddrB);
1645 writel(temp3, base + NvRegTransmitPoll);
1647 writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl);
1651 static void nv_get_hw_stats(struct net_device *dev)
1653 struct fe_priv *np = netdev_priv(dev);
1654 u8 __iomem *base = get_hwbase(dev);
1656 np->estats.tx_bytes += readl(base + NvRegTxCnt);
1657 np->estats.tx_zero_rexmt += readl(base + NvRegTxZeroReXmt);
1658 np->estats.tx_one_rexmt += readl(base + NvRegTxOneReXmt);
1659 np->estats.tx_many_rexmt += readl(base + NvRegTxManyReXmt);
1660 np->estats.tx_late_collision += readl(base + NvRegTxLateCol);
1661 np->estats.tx_fifo_errors += readl(base + NvRegTxUnderflow);
1662 np->estats.tx_carrier_errors += readl(base + NvRegTxLossCarrier);
1663 np->estats.tx_excess_deferral += readl(base + NvRegTxExcessDef);
1664 np->estats.tx_retry_error += readl(base + NvRegTxRetryErr);
1665 np->estats.rx_frame_error += readl(base + NvRegRxFrameErr);
1666 np->estats.rx_extra_byte += readl(base + NvRegRxExtraByte);
1667 np->estats.rx_late_collision += readl(base + NvRegRxLateCol);
1668 np->estats.rx_runt += readl(base + NvRegRxRunt);
1669 np->estats.rx_frame_too_long += readl(base + NvRegRxFrameTooLong);
1670 np->estats.rx_over_errors += readl(base + NvRegRxOverflow);
1671 np->estats.rx_crc_errors += readl(base + NvRegRxFCSErr);
1672 np->estats.rx_frame_align_error += readl(base + NvRegRxFrameAlignErr);
1673 np->estats.rx_length_error += readl(base + NvRegRxLenErr);
1674 np->estats.rx_unicast += readl(base + NvRegRxUnicast);
1675 np->estats.rx_multicast += readl(base + NvRegRxMulticast);
1676 np->estats.rx_broadcast += readl(base + NvRegRxBroadcast);
1677 np->estats.rx_packets =
1678 np->estats.rx_unicast +
1679 np->estats.rx_multicast +
1680 np->estats.rx_broadcast;
1681 np->estats.rx_errors_total =
1682 np->estats.rx_crc_errors +
1683 np->estats.rx_over_errors +
1684 np->estats.rx_frame_error +
1685 (np->estats.rx_frame_align_error - np->estats.rx_extra_byte) +
1686 np->estats.rx_late_collision +
1687 np->estats.rx_runt +
1688 np->estats.rx_frame_too_long;
1689 np->estats.tx_errors_total =
1690 np->estats.tx_late_collision +
1691 np->estats.tx_fifo_errors +
1692 np->estats.tx_carrier_errors +
1693 np->estats.tx_excess_deferral +
1694 np->estats.tx_retry_error;
1696 if (np->driver_data & DEV_HAS_STATISTICS_V2) {
1697 np->estats.tx_deferral += readl(base + NvRegTxDef);
1698 np->estats.tx_packets += readl(base + NvRegTxFrame);
1699 np->estats.rx_bytes += readl(base + NvRegRxCnt);
1700 np->estats.tx_pause += readl(base + NvRegTxPause);
1701 np->estats.rx_pause += readl(base + NvRegRxPause);
1702 np->estats.rx_drop_frame += readl(base + NvRegRxDropFrame);
1705 if (np->driver_data & DEV_HAS_STATISTICS_V3) {
1706 np->estats.tx_unicast += readl(base + NvRegTxUnicast);
1707 np->estats.tx_multicast += readl(base + NvRegTxMulticast);
1708 np->estats.tx_broadcast += readl(base + NvRegTxBroadcast);
1713 * nv_get_stats: dev->get_stats function
1714 * Get latest stats value from the nic.
1715 * Called with read_lock(&dev_base_lock) held for read -
1716 * only synchronized against unregister_netdevice.
1718 static struct net_device_stats *nv_get_stats(struct net_device *dev)
1720 struct fe_priv *np = netdev_priv(dev);
1722 /* If the nic supports hw counters then retrieve latest values */
1723 if (np->driver_data & (DEV_HAS_STATISTICS_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_STATISTICS_V3)) {
1724 nv_get_hw_stats(dev);
1726 /* copy to net_device stats */
1727 dev->stats.tx_bytes = np->estats.tx_bytes;
1728 dev->stats.tx_fifo_errors = np->estats.tx_fifo_errors;
1729 dev->stats.tx_carrier_errors = np->estats.tx_carrier_errors;
1730 dev->stats.rx_crc_errors = np->estats.rx_crc_errors;
1731 dev->stats.rx_over_errors = np->estats.rx_over_errors;
1732 dev->stats.rx_errors = np->estats.rx_errors_total;
1733 dev->stats.tx_errors = np->estats.tx_errors_total;
1740 * nv_alloc_rx: fill rx ring entries.
1741 * Return 1 if the allocations for the skbs failed and the
1742 * rx engine is without Available descriptors
1744 static int nv_alloc_rx(struct net_device *dev)
1746 struct fe_priv *np = netdev_priv(dev);
1747 struct ring_desc* less_rx;
1749 less_rx = np->get_rx.orig;
1750 if (less_rx-- == np->first_rx.orig)
1751 less_rx = np->last_rx.orig;
1753 while (np->put_rx.orig != less_rx) {
1754 struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD);
1756 np->put_rx_ctx->skb = skb;
1757 np->put_rx_ctx->dma = pci_map_single(np->pci_dev,
1760 PCI_DMA_FROMDEVICE);
1761 np->put_rx_ctx->dma_len = skb_tailroom(skb);
1762 np->put_rx.orig->buf = cpu_to_le32(np->put_rx_ctx->dma);
1764 np->put_rx.orig->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX_AVAIL);
1765 if (unlikely(np->put_rx.orig++ == np->last_rx.orig))
1766 np->put_rx.orig = np->first_rx.orig;
1767 if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
1768 np->put_rx_ctx = np->first_rx_ctx;
1776 static int nv_alloc_rx_optimized(struct net_device *dev)
1778 struct fe_priv *np = netdev_priv(dev);
1779 struct ring_desc_ex* less_rx;
1781 less_rx = np->get_rx.ex;
1782 if (less_rx-- == np->first_rx.ex)
1783 less_rx = np->last_rx.ex;
1785 while (np->put_rx.ex != less_rx) {
1786 struct sk_buff *skb = dev_alloc_skb(np->rx_buf_sz + NV_RX_ALLOC_PAD);
1788 np->put_rx_ctx->skb = skb;
1789 np->put_rx_ctx->dma = pci_map_single(np->pci_dev,
1792 PCI_DMA_FROMDEVICE);
1793 np->put_rx_ctx->dma_len = skb_tailroom(skb);
1794 np->put_rx.ex->bufhigh = cpu_to_le32(dma_high(np->put_rx_ctx->dma));
1795 np->put_rx.ex->buflow = cpu_to_le32(dma_low(np->put_rx_ctx->dma));
1797 np->put_rx.ex->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX2_AVAIL);
1798 if (unlikely(np->put_rx.ex++ == np->last_rx.ex))
1799 np->put_rx.ex = np->first_rx.ex;
1800 if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx))
1801 np->put_rx_ctx = np->first_rx_ctx;
1809 /* If rx bufs are exhausted called after 50ms to attempt to refresh */
1810 #ifdef CONFIG_FORCEDETH_NAPI
1811 static void nv_do_rx_refill(unsigned long data)
1813 struct net_device *dev = (struct net_device *) data;
1814 struct fe_priv *np = netdev_priv(dev);
1816 /* Just reschedule NAPI rx processing */
1817 napi_schedule(&np->napi);
1820 static void nv_do_rx_refill(unsigned long data)
1822 struct net_device *dev = (struct net_device *) data;
1823 struct fe_priv *np = netdev_priv(dev);
1826 if (!using_multi_irqs(dev)) {
1827 if (np->msi_flags & NV_MSI_X_ENABLED)
1828 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1830 disable_irq(np->pci_dev->irq);
1832 disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1834 if (!nv_optimized(np))
1835 retcode = nv_alloc_rx(dev);
1837 retcode = nv_alloc_rx_optimized(dev);
1839 spin_lock_irq(&np->lock);
1840 if (!np->in_shutdown)
1841 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
1842 spin_unlock_irq(&np->lock);
1844 if (!using_multi_irqs(dev)) {
1845 if (np->msi_flags & NV_MSI_X_ENABLED)
1846 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
1848 enable_irq(np->pci_dev->irq);
1850 enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
1855 static void nv_init_rx(struct net_device *dev)
1857 struct fe_priv *np = netdev_priv(dev);
1860 np->get_rx = np->put_rx = np->first_rx = np->rx_ring;
1862 if (!nv_optimized(np))
1863 np->last_rx.orig = &np->rx_ring.orig[np->rx_ring_size-1];
1865 np->last_rx.ex = &np->rx_ring.ex[np->rx_ring_size-1];
1866 np->get_rx_ctx = np->put_rx_ctx = np->first_rx_ctx = np->rx_skb;
1867 np->last_rx_ctx = &np->rx_skb[np->rx_ring_size-1];
1869 for (i = 0; i < np->rx_ring_size; i++) {
1870 if (!nv_optimized(np)) {
1871 np->rx_ring.orig[i].flaglen = 0;
1872 np->rx_ring.orig[i].buf = 0;
1874 np->rx_ring.ex[i].flaglen = 0;
1875 np->rx_ring.ex[i].txvlan = 0;
1876 np->rx_ring.ex[i].bufhigh = 0;
1877 np->rx_ring.ex[i].buflow = 0;
1879 np->rx_skb[i].skb = NULL;
1880 np->rx_skb[i].dma = 0;
1884 static void nv_init_tx(struct net_device *dev)
1886 struct fe_priv *np = netdev_priv(dev);
1889 np->get_tx = np->put_tx = np->first_tx = np->tx_ring;
1891 if (!nv_optimized(np))
1892 np->last_tx.orig = &np->tx_ring.orig[np->tx_ring_size-1];
1894 np->last_tx.ex = &np->tx_ring.ex[np->tx_ring_size-1];
1895 np->get_tx_ctx = np->put_tx_ctx = np->first_tx_ctx = np->tx_skb;
1896 np->last_tx_ctx = &np->tx_skb[np->tx_ring_size-1];
1897 np->tx_pkts_in_progress = 0;
1898 np->tx_change_owner = NULL;
1899 np->tx_end_flip = NULL;
1902 for (i = 0; i < np->tx_ring_size; i++) {
1903 if (!nv_optimized(np)) {
1904 np->tx_ring.orig[i].flaglen = 0;
1905 np->tx_ring.orig[i].buf = 0;
1907 np->tx_ring.ex[i].flaglen = 0;
1908 np->tx_ring.ex[i].txvlan = 0;
1909 np->tx_ring.ex[i].bufhigh = 0;
1910 np->tx_ring.ex[i].buflow = 0;
1912 np->tx_skb[i].skb = NULL;
1913 np->tx_skb[i].dma = 0;
1914 np->tx_skb[i].dma_len = 0;
1915 np->tx_skb[i].first_tx_desc = NULL;
1916 np->tx_skb[i].next_tx_ctx = NULL;
1920 static int nv_init_ring(struct net_device *dev)
1922 struct fe_priv *np = netdev_priv(dev);
1927 if (!nv_optimized(np))
1928 return nv_alloc_rx(dev);
1930 return nv_alloc_rx_optimized(dev);
1933 static int nv_release_txskb(struct net_device *dev, struct nv_skb_map* tx_skb)
1935 struct fe_priv *np = netdev_priv(dev);
1938 pci_unmap_page(np->pci_dev, tx_skb->dma,
1944 dev_kfree_skb_any(tx_skb->skb);
1952 static void nv_drain_tx(struct net_device *dev)
1954 struct fe_priv *np = netdev_priv(dev);
1957 for (i = 0; i < np->tx_ring_size; i++) {
1958 if (!nv_optimized(np)) {
1959 np->tx_ring.orig[i].flaglen = 0;
1960 np->tx_ring.orig[i].buf = 0;
1962 np->tx_ring.ex[i].flaglen = 0;
1963 np->tx_ring.ex[i].txvlan = 0;
1964 np->tx_ring.ex[i].bufhigh = 0;
1965 np->tx_ring.ex[i].buflow = 0;
1967 if (nv_release_txskb(dev, &np->tx_skb[i]))
1968 dev->stats.tx_dropped++;
1969 np->tx_skb[i].dma = 0;
1970 np->tx_skb[i].dma_len = 0;
1971 np->tx_skb[i].first_tx_desc = NULL;
1972 np->tx_skb[i].next_tx_ctx = NULL;
1974 np->tx_pkts_in_progress = 0;
1975 np->tx_change_owner = NULL;
1976 np->tx_end_flip = NULL;
1979 static void nv_drain_rx(struct net_device *dev)
1981 struct fe_priv *np = netdev_priv(dev);
1984 for (i = 0; i < np->rx_ring_size; i++) {
1985 if (!nv_optimized(np)) {
1986 np->rx_ring.orig[i].flaglen = 0;
1987 np->rx_ring.orig[i].buf = 0;
1989 np->rx_ring.ex[i].flaglen = 0;
1990 np->rx_ring.ex[i].txvlan = 0;
1991 np->rx_ring.ex[i].bufhigh = 0;
1992 np->rx_ring.ex[i].buflow = 0;
1995 if (np->rx_skb[i].skb) {
1996 pci_unmap_single(np->pci_dev, np->rx_skb[i].dma,
1997 (skb_end_pointer(np->rx_skb[i].skb) -
1998 np->rx_skb[i].skb->data),
1999 PCI_DMA_FROMDEVICE);
2000 dev_kfree_skb(np->rx_skb[i].skb);
2001 np->rx_skb[i].skb = NULL;
2006 static void nv_drain_rxtx(struct net_device *dev)
2012 static inline u32 nv_get_empty_tx_slots(struct fe_priv *np)
2014 return (u32)(np->tx_ring_size - ((np->tx_ring_size + (np->put_tx_ctx - np->get_tx_ctx)) % np->tx_ring_size));
2017 static void nv_legacybackoff_reseed(struct net_device *dev)
2019 u8 __iomem *base = get_hwbase(dev);
2024 reg = readl(base + NvRegSlotTime) & ~NVREG_SLOTTIME_MASK;
2025 get_random_bytes(&low, sizeof(low));
2026 reg |= low & NVREG_SLOTTIME_MASK;
2028 /* Need to stop tx before change takes effect.
2029 * Caller has already gained np->lock.
2031 tx_status = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_START;
2035 writel(reg, base + NvRegSlotTime);
2041 /* Gear Backoff Seeds */
2042 #define BACKOFF_SEEDSET_ROWS 8
2043 #define BACKOFF_SEEDSET_LFSRS 15
2045 /* Known Good seed sets */
2046 static const u32 main_seedset[BACKOFF_SEEDSET_ROWS][BACKOFF_SEEDSET_LFSRS] = {
2047 {145, 155, 165, 175, 185, 196, 235, 245, 255, 265, 275, 285, 660, 690, 874},
2048 {245, 255, 265, 575, 385, 298, 335, 345, 355, 366, 375, 385, 761, 790, 974},
2049 {145, 155, 165, 175, 185, 196, 235, 245, 255, 265, 275, 285, 660, 690, 874},
2050 {245, 255, 265, 575, 385, 298, 335, 345, 355, 366, 375, 386, 761, 790, 974},
2051 {266, 265, 276, 585, 397, 208, 345, 355, 365, 376, 385, 396, 771, 700, 984},
2052 {266, 265, 276, 586, 397, 208, 346, 355, 365, 376, 285, 396, 771, 700, 984},
2053 {366, 365, 376, 686, 497, 308, 447, 455, 466, 476, 485, 496, 871, 800, 84},
2054 {466, 465, 476, 786, 597, 408, 547, 555, 566, 576, 585, 597, 971, 900, 184}};
2056 static const u32 gear_seedset[BACKOFF_SEEDSET_ROWS][BACKOFF_SEEDSET_LFSRS] = {
2057 {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
2058 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
2059 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 397},
2060 {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
2061 {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295},
2062 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
2063 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395},
2064 {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395}};
2066 static void nv_gear_backoff_reseed(struct net_device *dev)
2068 u8 __iomem *base = get_hwbase(dev);
2069 u32 miniseed1, miniseed2, miniseed2_reversed, miniseed3, miniseed3_reversed;
2070 u32 temp, seedset, combinedSeed;
2073 /* Setup seed for free running LFSR */
2074 /* We are going to read the time stamp counter 3 times
2075 and swizzle bits around to increase randomness */
2076 get_random_bytes(&miniseed1, sizeof(miniseed1));
2077 miniseed1 &= 0x0fff;
2081 get_random_bytes(&miniseed2, sizeof(miniseed2));
2082 miniseed2 &= 0x0fff;
2085 miniseed2_reversed =
2086 ((miniseed2 & 0xF00) >> 8) |
2087 (miniseed2 & 0x0F0) |
2088 ((miniseed2 & 0x00F) << 8);
2090 get_random_bytes(&miniseed3, sizeof(miniseed3));
2091 miniseed3 &= 0x0fff;
2094 miniseed3_reversed =
2095 ((miniseed3 & 0xF00) >> 8) |
2096 (miniseed3 & 0x0F0) |
2097 ((miniseed3 & 0x00F) << 8);
2099 combinedSeed = ((miniseed1 ^ miniseed2_reversed) << 12) |
2100 (miniseed2 ^ miniseed3_reversed);
2102 /* Seeds can not be zero */
2103 if ((combinedSeed & NVREG_BKOFFCTRL_SEED_MASK) == 0)
2104 combinedSeed |= 0x08;
2105 if ((combinedSeed & (NVREG_BKOFFCTRL_SEED_MASK << NVREG_BKOFFCTRL_GEAR)) == 0)
2106 combinedSeed |= 0x8000;
2108 /* No need to disable tx here */
2109 temp = NVREG_BKOFFCTRL_DEFAULT | (0 << NVREG_BKOFFCTRL_SELECT);
2110 temp |= combinedSeed & NVREG_BKOFFCTRL_SEED_MASK;
2111 temp |= combinedSeed >> NVREG_BKOFFCTRL_GEAR;
2112 writel(temp,base + NvRegBackOffControl);
2114 /* Setup seeds for all gear LFSRs. */
2115 get_random_bytes(&seedset, sizeof(seedset));
2116 seedset = seedset % BACKOFF_SEEDSET_ROWS;
2117 for (i = 1; i <= BACKOFF_SEEDSET_LFSRS; i++)
2119 temp = NVREG_BKOFFCTRL_DEFAULT | (i << NVREG_BKOFFCTRL_SELECT);
2120 temp |= main_seedset[seedset][i-1] & 0x3ff;
2121 temp |= ((gear_seedset[seedset][i-1] & 0x3ff) << NVREG_BKOFFCTRL_GEAR);
2122 writel(temp, base + NvRegBackOffControl);
2127 * nv_start_xmit: dev->hard_start_xmit function
2128 * Called with netif_tx_lock held.
2130 static int nv_start_xmit(struct sk_buff *skb, struct net_device *dev)
2132 struct fe_priv *np = netdev_priv(dev);
2134 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
2135 unsigned int fragments = skb_shinfo(skb)->nr_frags;
2139 u32 size = skb->len-skb->data_len;
2140 u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
2142 struct ring_desc* put_tx;
2143 struct ring_desc* start_tx;
2144 struct ring_desc* prev_tx;
2145 struct nv_skb_map* prev_tx_ctx;
2146 unsigned long flags;
2148 /* add fragments to entries count */
2149 for (i = 0; i < fragments; i++) {
2150 entries += (skb_shinfo(skb)->frags[i].size >> NV_TX2_TSO_MAX_SHIFT) +
2151 ((skb_shinfo(skb)->frags[i].size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
2154 spin_lock_irqsave(&np->lock, flags);
2155 empty_slots = nv_get_empty_tx_slots(np);
2156 if (unlikely(empty_slots <= entries)) {
2157 netif_stop_queue(dev);
2159 spin_unlock_irqrestore(&np->lock, flags);
2160 return NETDEV_TX_BUSY;
2162 spin_unlock_irqrestore(&np->lock, flags);
2164 start_tx = put_tx = np->put_tx.orig;
2166 /* setup the header buffer */
2169 prev_tx_ctx = np->put_tx_ctx;
2170 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
2171 np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
2173 np->put_tx_ctx->dma_len = bcnt;
2174 put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
2175 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
2177 tx_flags = np->tx_flags;
2180 if (unlikely(put_tx++ == np->last_tx.orig))
2181 put_tx = np->first_tx.orig;
2182 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
2183 np->put_tx_ctx = np->first_tx_ctx;
2186 /* setup the fragments */
2187 for (i = 0; i < fragments; i++) {
2188 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
2189 u32 size = frag->size;
2194 prev_tx_ctx = np->put_tx_ctx;
2195 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
2196 np->put_tx_ctx->dma = pci_map_page(np->pci_dev, frag->page, frag->page_offset+offset, bcnt,
2198 np->put_tx_ctx->dma_len = bcnt;
2199 put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma);
2200 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
2204 if (unlikely(put_tx++ == np->last_tx.orig))
2205 put_tx = np->first_tx.orig;
2206 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
2207 np->put_tx_ctx = np->first_tx_ctx;
2211 /* set last fragment flag */
2212 prev_tx->flaglen |= cpu_to_le32(tx_flags_extra);
2214 /* save skb in this slot's context area */
2215 prev_tx_ctx->skb = skb;
2217 if (skb_is_gso(skb))
2218 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
2220 tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
2221 NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
2223 spin_lock_irqsave(&np->lock, flags);
2226 start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
2227 np->put_tx.orig = put_tx;
2229 spin_unlock_irqrestore(&np->lock, flags);
2231 dprintk(KERN_DEBUG "%s: nv_start_xmit: entries %d queued for transmission. tx_flags_extra: %x\n",
2232 dev->name, entries, tx_flags_extra);
2235 for (j=0; j<64; j++) {
2237 dprintk("\n%03x:", j);
2238 dprintk(" %02x", ((unsigned char*)skb->data)[j]);
2243 dev->trans_start = jiffies;
2244 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
2245 return NETDEV_TX_OK;
2248 static int nv_start_xmit_optimized(struct sk_buff *skb, struct net_device *dev)
2250 struct fe_priv *np = netdev_priv(dev);
2253 unsigned int fragments = skb_shinfo(skb)->nr_frags;
2257 u32 size = skb->len-skb->data_len;
2258 u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
2260 struct ring_desc_ex* put_tx;
2261 struct ring_desc_ex* start_tx;
2262 struct ring_desc_ex* prev_tx;
2263 struct nv_skb_map* prev_tx_ctx;
2264 struct nv_skb_map* start_tx_ctx;
2265 unsigned long flags;
2267 /* add fragments to entries count */
2268 for (i = 0; i < fragments; i++) {
2269 entries += (skb_shinfo(skb)->frags[i].size >> NV_TX2_TSO_MAX_SHIFT) +
2270 ((skb_shinfo(skb)->frags[i].size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0);
2273 spin_lock_irqsave(&np->lock, flags);
2274 empty_slots = nv_get_empty_tx_slots(np);
2275 if (unlikely(empty_slots <= entries)) {
2276 netif_stop_queue(dev);
2278 spin_unlock_irqrestore(&np->lock, flags);
2279 return NETDEV_TX_BUSY;
2281 spin_unlock_irqrestore(&np->lock, flags);
2283 start_tx = put_tx = np->put_tx.ex;
2284 start_tx_ctx = np->put_tx_ctx;
2286 /* setup the header buffer */
2289 prev_tx_ctx = np->put_tx_ctx;
2290 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
2291 np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt,
2293 np->put_tx_ctx->dma_len = bcnt;
2294 put_tx->bufhigh = cpu_to_le32(dma_high(np->put_tx_ctx->dma));
2295 put_tx->buflow = cpu_to_le32(dma_low(np->put_tx_ctx->dma));
2296 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
2298 tx_flags = NV_TX2_VALID;
2301 if (unlikely(put_tx++ == np->last_tx.ex))
2302 put_tx = np->first_tx.ex;
2303 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
2304 np->put_tx_ctx = np->first_tx_ctx;
2307 /* setup the fragments */
2308 for (i = 0; i < fragments; i++) {
2309 skb_frag_t *frag = &skb_shinfo(skb)->frags[i];
2310 u32 size = frag->size;
2315 prev_tx_ctx = np->put_tx_ctx;
2316 bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size;
2317 np->put_tx_ctx->dma = pci_map_page(np->pci_dev, frag->page, frag->page_offset+offset, bcnt,
2319 np->put_tx_ctx->dma_len = bcnt;
2320 put_tx->bufhigh = cpu_to_le32(dma_high(np->put_tx_ctx->dma));
2321 put_tx->buflow = cpu_to_le32(dma_low(np->put_tx_ctx->dma));
2322 put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags);
2326 if (unlikely(put_tx++ == np->last_tx.ex))
2327 put_tx = np->first_tx.ex;
2328 if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx))
2329 np->put_tx_ctx = np->first_tx_ctx;
2333 /* set last fragment flag */
2334 prev_tx->flaglen |= cpu_to_le32(NV_TX2_LASTPACKET);
2336 /* save skb in this slot's context area */
2337 prev_tx_ctx->skb = skb;
2339 if (skb_is_gso(skb))
2340 tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT);
2342 tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ?
2343 NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0;
2346 if (likely(!np->vlangrp)) {
2347 start_tx->txvlan = 0;
2349 if (vlan_tx_tag_present(skb))
2350 start_tx->txvlan = cpu_to_le32(NV_TX3_VLAN_TAG_PRESENT | vlan_tx_tag_get(skb));
2352 start_tx->txvlan = 0;
2355 spin_lock_irqsave(&np->lock, flags);
2358 /* Limit the number of outstanding tx. Setup all fragments, but
2359 * do not set the VALID bit on the first descriptor. Save a pointer
2360 * to that descriptor and also for next skb_map element.
2363 if (np->tx_pkts_in_progress == NV_TX_LIMIT_COUNT) {
2364 if (!np->tx_change_owner)
2365 np->tx_change_owner = start_tx_ctx;
2367 /* remove VALID bit */
2368 tx_flags &= ~NV_TX2_VALID;
2369 start_tx_ctx->first_tx_desc = start_tx;
2370 start_tx_ctx->next_tx_ctx = np->put_tx_ctx;
2371 np->tx_end_flip = np->put_tx_ctx;
2373 np->tx_pkts_in_progress++;
2378 start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra);
2379 np->put_tx.ex = put_tx;
2381 spin_unlock_irqrestore(&np->lock, flags);
2383 dprintk(KERN_DEBUG "%s: nv_start_xmit_optimized: entries %d queued for transmission. tx_flags_extra: %x\n",
2384 dev->name, entries, tx_flags_extra);
2387 for (j=0; j<64; j++) {
2389 dprintk("\n%03x:", j);
2390 dprintk(" %02x", ((unsigned char*)skb->data)[j]);
2395 dev->trans_start = jiffies;
2396 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
2397 return NETDEV_TX_OK;
2400 static inline void nv_tx_flip_ownership(struct net_device *dev)
2402 struct fe_priv *np = netdev_priv(dev);
2404 np->tx_pkts_in_progress--;
2405 if (np->tx_change_owner) {
2406 np->tx_change_owner->first_tx_desc->flaglen |=
2407 cpu_to_le32(NV_TX2_VALID);
2408 np->tx_pkts_in_progress++;
2410 np->tx_change_owner = np->tx_change_owner->next_tx_ctx;
2411 if (np->tx_change_owner == np->tx_end_flip)
2412 np->tx_change_owner = NULL;
2414 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
2419 * nv_tx_done: check for completed packets, release the skbs.
2421 * Caller must own np->lock.
2423 static int nv_tx_done(struct net_device *dev, int limit)
2425 struct fe_priv *np = netdev_priv(dev);
2428 struct ring_desc* orig_get_tx = np->get_tx.orig;
2430 while ((np->get_tx.orig != np->put_tx.orig) &&
2431 !((flags = le32_to_cpu(np->get_tx.orig->flaglen)) & NV_TX_VALID) &&
2432 (tx_work < limit)) {
2434 dprintk(KERN_DEBUG "%s: nv_tx_done: flags 0x%x.\n",
2437 pci_unmap_page(np->pci_dev, np->get_tx_ctx->dma,
2438 np->get_tx_ctx->dma_len,
2440 np->get_tx_ctx->dma = 0;
2442 if (np->desc_ver == DESC_VER_1) {
2443 if (flags & NV_TX_LASTPACKET) {
2444 if (flags & NV_TX_ERROR) {
2445 if (flags & NV_TX_UNDERFLOW)
2446 dev->stats.tx_fifo_errors++;
2447 if (flags & NV_TX_CARRIERLOST)
2448 dev->stats.tx_carrier_errors++;
2449 if ((flags & NV_TX_RETRYERROR) && !(flags & NV_TX_RETRYCOUNT_MASK))
2450 nv_legacybackoff_reseed(dev);
2451 dev->stats.tx_errors++;
2453 dev->stats.tx_packets++;
2454 dev->stats.tx_bytes += np->get_tx_ctx->skb->len;
2456 dev_kfree_skb_any(np->get_tx_ctx->skb);
2457 np->get_tx_ctx->skb = NULL;
2461 if (flags & NV_TX2_LASTPACKET) {
2462 if (flags & NV_TX2_ERROR) {
2463 if (flags & NV_TX2_UNDERFLOW)
2464 dev->stats.tx_fifo_errors++;
2465 if (flags & NV_TX2_CARRIERLOST)
2466 dev->stats.tx_carrier_errors++;
2467 if ((flags & NV_TX2_RETRYERROR) && !(flags & NV_TX2_RETRYCOUNT_MASK))
2468 nv_legacybackoff_reseed(dev);
2469 dev->stats.tx_errors++;
2471 dev->stats.tx_packets++;
2472 dev->stats.tx_bytes += np->get_tx_ctx->skb->len;
2474 dev_kfree_skb_any(np->get_tx_ctx->skb);
2475 np->get_tx_ctx->skb = NULL;
2479 if (unlikely(np->get_tx.orig++ == np->last_tx.orig))
2480 np->get_tx.orig = np->first_tx.orig;
2481 if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
2482 np->get_tx_ctx = np->first_tx_ctx;
2484 if (unlikely((np->tx_stop == 1) && (np->get_tx.orig != orig_get_tx))) {
2486 netif_wake_queue(dev);
2491 static int nv_tx_done_optimized(struct net_device *dev, int limit)
2493 struct fe_priv *np = netdev_priv(dev);
2496 struct ring_desc_ex* orig_get_tx = np->get_tx.ex;
2498 while ((np->get_tx.ex != np->put_tx.ex) &&
2499 !((flags = le32_to_cpu(np->get_tx.ex->flaglen)) & NV_TX_VALID) &&
2500 (tx_work < limit)) {
2502 dprintk(KERN_DEBUG "%s: nv_tx_done_optimized: flags 0x%x.\n",
2505 pci_unmap_page(np->pci_dev, np->get_tx_ctx->dma,
2506 np->get_tx_ctx->dma_len,
2508 np->get_tx_ctx->dma = 0;
2510 if (flags & NV_TX2_LASTPACKET) {
2511 if (!(flags & NV_TX2_ERROR))
2512 dev->stats.tx_packets++;
2514 if ((flags & NV_TX2_RETRYERROR) && !(flags & NV_TX2_RETRYCOUNT_MASK)) {
2515 if (np->driver_data & DEV_HAS_GEAR_MODE)
2516 nv_gear_backoff_reseed(dev);
2518 nv_legacybackoff_reseed(dev);
2522 dev_kfree_skb_any(np->get_tx_ctx->skb);
2523 np->get_tx_ctx->skb = NULL;
2527 nv_tx_flip_ownership(dev);
2530 if (unlikely(np->get_tx.ex++ == np->last_tx.ex))
2531 np->get_tx.ex = np->first_tx.ex;
2532 if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx))
2533 np->get_tx_ctx = np->first_tx_ctx;
2535 if (unlikely((np->tx_stop == 1) && (np->get_tx.ex != orig_get_tx))) {
2537 netif_wake_queue(dev);
2543 * nv_tx_timeout: dev->tx_timeout function
2544 * Called with netif_tx_lock held.
2546 static void nv_tx_timeout(struct net_device *dev)
2548 struct fe_priv *np = netdev_priv(dev);
2549 u8 __iomem *base = get_hwbase(dev);
2551 union ring_type put_tx;
2554 if (np->msi_flags & NV_MSI_X_ENABLED)
2555 status = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
2557 status = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
2559 printk(KERN_INFO "%s: Got tx_timeout. irq: %08x\n", dev->name, status);
2564 printk(KERN_INFO "%s: Ring at %lx\n",
2565 dev->name, (unsigned long)np->ring_addr);
2566 printk(KERN_INFO "%s: Dumping tx registers\n", dev->name);
2567 for (i=0;i<=np->register_size;i+= 32) {
2568 printk(KERN_INFO "%3x: %08x %08x %08x %08x %08x %08x %08x %08x\n",
2570 readl(base + i + 0), readl(base + i + 4),
2571 readl(base + i + 8), readl(base + i + 12),
2572 readl(base + i + 16), readl(base + i + 20),
2573 readl(base + i + 24), readl(base + i + 28));
2575 printk(KERN_INFO "%s: Dumping tx ring\n", dev->name);
2576 for (i=0;i<np->tx_ring_size;i+= 4) {
2577 if (!nv_optimized(np)) {
2578 printk(KERN_INFO "%03x: %08x %08x // %08x %08x // %08x %08x // %08x %08x\n",
2580 le32_to_cpu(np->tx_ring.orig[i].buf),
2581 le32_to_cpu(np->tx_ring.orig[i].flaglen),
2582 le32_to_cpu(np->tx_ring.orig[i+1].buf),
2583 le32_to_cpu(np->tx_ring.orig[i+1].flaglen),
2584 le32_to_cpu(np->tx_ring.orig[i+2].buf),
2585 le32_to_cpu(np->tx_ring.orig[i+2].flaglen),
2586 le32_to_cpu(np->tx_ring.orig[i+3].buf),
2587 le32_to_cpu(np->tx_ring.orig[i+3].flaglen));
2589 printk(KERN_INFO "%03x: %08x %08x %08x // %08x %08x %08x // %08x %08x %08x // %08x %08x %08x\n",
2591 le32_to_cpu(np->tx_ring.ex[i].bufhigh),
2592 le32_to_cpu(np->tx_ring.ex[i].buflow),
2593 le32_to_cpu(np->tx_ring.ex[i].flaglen),
2594 le32_to_cpu(np->tx_ring.ex[i+1].bufhigh),
2595 le32_to_cpu(np->tx_ring.ex[i+1].buflow),
2596 le32_to_cpu(np->tx_ring.ex[i+1].flaglen),
2597 le32_to_cpu(np->tx_ring.ex[i+2].bufhigh),
2598 le32_to_cpu(np->tx_ring.ex[i+2].buflow),
2599 le32_to_cpu(np->tx_ring.ex[i+2].flaglen),
2600 le32_to_cpu(np->tx_ring.ex[i+3].bufhigh),
2601 le32_to_cpu(np->tx_ring.ex[i+3].buflow),
2602 le32_to_cpu(np->tx_ring.ex[i+3].flaglen));
2607 spin_lock_irq(&np->lock);
2609 /* 1) stop tx engine */
2612 /* 2) complete any outstanding tx and do not give HW any limited tx pkts */
2613 saved_tx_limit = np->tx_limit;
2614 np->tx_limit = 0; /* prevent giving HW any limited pkts */
2615 np->tx_stop = 0; /* prevent waking tx queue */
2616 if (!nv_optimized(np))
2617 nv_tx_done(dev, np->tx_ring_size);
2619 nv_tx_done_optimized(dev, np->tx_ring_size);
2621 /* save current HW postion */
2622 if (np->tx_change_owner)
2623 put_tx.ex = np->tx_change_owner->first_tx_desc;
2625 put_tx = np->put_tx;
2627 /* 3) clear all tx state */
2631 /* 4) restore state to current HW position */
2632 np->get_tx = np->put_tx = put_tx;
2633 np->tx_limit = saved_tx_limit;
2635 /* 5) restart tx engine */
2637 netif_wake_queue(dev);
2638 spin_unlock_irq(&np->lock);
2642 * Called when the nic notices a mismatch between the actual data len on the
2643 * wire and the len indicated in the 802 header
2645 static int nv_getlen(struct net_device *dev, void *packet, int datalen)
2647 int hdrlen; /* length of the 802 header */
2648 int protolen; /* length as stored in the proto field */
2650 /* 1) calculate len according to header */
2651 if ( ((struct vlan_ethhdr *)packet)->h_vlan_proto == htons(ETH_P_8021Q)) {
2652 protolen = ntohs( ((struct vlan_ethhdr *)packet)->h_vlan_encapsulated_proto );
2655 protolen = ntohs( ((struct ethhdr *)packet)->h_proto);
2658 dprintk(KERN_DEBUG "%s: nv_getlen: datalen %d, protolen %d, hdrlen %d\n",
2659 dev->name, datalen, protolen, hdrlen);
2660 if (protolen > ETH_DATA_LEN)
2661 return datalen; /* Value in proto field not a len, no checks possible */
2664 /* consistency checks: */
2665 if (datalen > ETH_ZLEN) {
2666 if (datalen >= protolen) {
2667 /* more data on wire than in 802 header, trim of
2670 dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n",
2671 dev->name, protolen);
2674 /* less data on wire than mentioned in header.
2675 * Discard the packet.
2677 dprintk(KERN_DEBUG "%s: nv_getlen: discarding long packet.\n",
2682 /* short packet. Accept only if 802 values are also short */
2683 if (protolen > ETH_ZLEN) {
2684 dprintk(KERN_DEBUG "%s: nv_getlen: discarding short packet.\n",
2688 dprintk(KERN_DEBUG "%s: nv_getlen: accepting %d bytes.\n",
2689 dev->name, datalen);
2694 static int nv_rx_process(struct net_device *dev, int limit)
2696 struct fe_priv *np = netdev_priv(dev);
2699 struct sk_buff *skb;
2702 while((np->get_rx.orig != np->put_rx.orig) &&
2703 !((flags = le32_to_cpu(np->get_rx.orig->flaglen)) & NV_RX_AVAIL) &&
2704 (rx_work < limit)) {
2706 dprintk(KERN_DEBUG "%s: nv_rx_process: flags 0x%x.\n",
2710 * the packet is for us - immediately tear down the pci mapping.
2711 * TODO: check if a prefetch of the first cacheline improves
2714 pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma,
2715 np->get_rx_ctx->dma_len,
2716 PCI_DMA_FROMDEVICE);
2717 skb = np->get_rx_ctx->skb;
2718 np->get_rx_ctx->skb = NULL;
2722 dprintk(KERN_DEBUG "Dumping packet (flags 0x%x).",flags);
2723 for (j=0; j<64; j++) {
2725 dprintk("\n%03x:", j);
2726 dprintk(" %02x", ((unsigned char*)skb->data)[j]);
2730 /* look at what we actually got: */
2731 if (np->desc_ver == DESC_VER_1) {
2732 if (likely(flags & NV_RX_DESCRIPTORVALID)) {
2733 len = flags & LEN_MASK_V1;
2734 if (unlikely(flags & NV_RX_ERROR)) {
2735 if ((flags & NV_RX_ERROR_MASK) == NV_RX_ERROR4) {
2736 len = nv_getlen(dev, skb->data, len);
2738 dev->stats.rx_errors++;
2743 /* framing errors are soft errors */
2744 else if ((flags & NV_RX_ERROR_MASK) == NV_RX_FRAMINGERR) {
2745 if (flags & NV_RX_SUBSTRACT1) {
2749 /* the rest are hard errors */
2751 if (flags & NV_RX_MISSEDFRAME)
2752 dev->stats.rx_missed_errors++;
2753 if (flags & NV_RX_CRCERR)
2754 dev->stats.rx_crc_errors++;
2755 if (flags & NV_RX_OVERFLOW)
2756 dev->stats.rx_over_errors++;
2757 dev->stats.rx_errors++;
2767 if (likely(flags & NV_RX2_DESCRIPTORVALID)) {
2768 len = flags & LEN_MASK_V2;
2769 if (unlikely(flags & NV_RX2_ERROR)) {
2770 if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_ERROR4) {
2771 len = nv_getlen(dev, skb->data, len);
2773 dev->stats.rx_errors++;
2778 /* framing errors are soft errors */
2779 else if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_FRAMINGERR) {
2780 if (flags & NV_RX2_SUBSTRACT1) {
2784 /* the rest are hard errors */
2786 if (flags & NV_RX2_CRCERR)
2787 dev->stats.rx_crc_errors++;
2788 if (flags & NV_RX2_OVERFLOW)
2789 dev->stats.rx_over_errors++;
2790 dev->stats.rx_errors++;
2795 if (((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_TCP) || /*ip and tcp */
2796 ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_UDP)) /*ip and udp */
2797 skb->ip_summed = CHECKSUM_UNNECESSARY;
2803 /* got a valid packet - forward it to the network core */
2805 skb->protocol = eth_type_trans(skb, dev);
2806 dprintk(KERN_DEBUG "%s: nv_rx_process: %d bytes, proto %d accepted.\n",
2807 dev->name, len, skb->protocol);
2808 #ifdef CONFIG_FORCEDETH_NAPI
2809 netif_receive_skb(skb);
2813 dev->stats.rx_packets++;
2814 dev->stats.rx_bytes += len;
2816 if (unlikely(np->get_rx.orig++ == np->last_rx.orig))
2817 np->get_rx.orig = np->first_rx.orig;
2818 if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
2819 np->get_rx_ctx = np->first_rx_ctx;
2827 static int nv_rx_process_optimized(struct net_device *dev, int limit)
2829 struct fe_priv *np = netdev_priv(dev);
2833 struct sk_buff *skb;
2836 while((np->get_rx.ex != np->put_rx.ex) &&
2837 !((flags = le32_to_cpu(np->get_rx.ex->flaglen)) & NV_RX2_AVAIL) &&
2838 (rx_work < limit)) {
2840 dprintk(KERN_DEBUG "%s: nv_rx_process_optimized: flags 0x%x.\n",
2844 * the packet is for us - immediately tear down the pci mapping.
2845 * TODO: check if a prefetch of the first cacheline improves
2848 pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma,
2849 np->get_rx_ctx->dma_len,
2850 PCI_DMA_FROMDEVICE);
2851 skb = np->get_rx_ctx->skb;
2852 np->get_rx_ctx->skb = NULL;
2856 dprintk(KERN_DEBUG "Dumping packet (flags 0x%x).",flags);
2857 for (j=0; j<64; j++) {
2859 dprintk("\n%03x:", j);
2860 dprintk(" %02x", ((unsigned char*)skb->data)[j]);
2864 /* look at what we actually got: */
2865 if (likely(flags & NV_RX2_DESCRIPTORVALID)) {
2866 len = flags & LEN_MASK_V2;
2867 if (unlikely(flags & NV_RX2_ERROR)) {
2868 if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_ERROR4) {
2869 len = nv_getlen(dev, skb->data, len);
2875 /* framing errors are soft errors */
2876 else if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_FRAMINGERR) {
2877 if (flags & NV_RX2_SUBSTRACT1) {
2881 /* the rest are hard errors */
2888 if (((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_TCP) || /*ip and tcp */
2889 ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_UDP)) /*ip and udp */
2890 skb->ip_summed = CHECKSUM_UNNECESSARY;
2892 /* got a valid packet - forward it to the network core */
2894 skb->protocol = eth_type_trans(skb, dev);
2895 prefetch(skb->data);
2897 dprintk(KERN_DEBUG "%s: nv_rx_process_optimized: %d bytes, proto %d accepted.\n",
2898 dev->name, len, skb->protocol);
2900 if (likely(!np->vlangrp)) {
2901 #ifdef CONFIG_FORCEDETH_NAPI
2902 netif_receive_skb(skb);
2907 vlanflags = le32_to_cpu(np->get_rx.ex->buflow);
2908 if (vlanflags & NV_RX3_VLAN_TAG_PRESENT) {
2909 #ifdef CONFIG_FORCEDETH_NAPI
2910 vlan_hwaccel_receive_skb(skb, np->vlangrp,
2911 vlanflags & NV_RX3_VLAN_TAG_MASK);
2913 vlan_hwaccel_rx(skb, np->vlangrp,
2914 vlanflags & NV_RX3_VLAN_TAG_MASK);
2917 #ifdef CONFIG_FORCEDETH_NAPI
2918 netif_receive_skb(skb);
2925 dev->stats.rx_packets++;
2926 dev->stats.rx_bytes += len;
2931 if (unlikely(np->get_rx.ex++ == np->last_rx.ex))
2932 np->get_rx.ex = np->first_rx.ex;
2933 if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx))
2934 np->get_rx_ctx = np->first_rx_ctx;
2942 static void set_bufsize(struct net_device *dev)
2944 struct fe_priv *np = netdev_priv(dev);
2946 if (dev->mtu <= ETH_DATA_LEN)
2947 np->rx_buf_sz = ETH_DATA_LEN + NV_RX_HEADERS;
2949 np->rx_buf_sz = dev->mtu + NV_RX_HEADERS;
2953 * nv_change_mtu: dev->change_mtu function
2954 * Called with dev_base_lock held for read.
2956 static int nv_change_mtu(struct net_device *dev, int new_mtu)
2958 struct fe_priv *np = netdev_priv(dev);
2961 if (new_mtu < 64 || new_mtu > np->pkt_limit)
2967 /* return early if the buffer sizes will not change */
2968 if (old_mtu <= ETH_DATA_LEN && new_mtu <= ETH_DATA_LEN)
2970 if (old_mtu == new_mtu)
2973 /* synchronized against open : rtnl_lock() held by caller */
2974 if (netif_running(dev)) {
2975 u8 __iomem *base = get_hwbase(dev);
2977 * It seems that the nic preloads valid ring entries into an
2978 * internal buffer. The procedure for flushing everything is
2979 * guessed, there is probably a simpler approach.
2980 * Changing the MTU is a rare event, it shouldn't matter.
2982 nv_disable_irq(dev);
2983 nv_napi_disable(dev);
2984 netif_tx_lock_bh(dev);
2985 netif_addr_lock(dev);
2986 spin_lock(&np->lock);
2990 /* drain rx queue */
2992 /* reinit driver view of the rx queue */
2994 if (nv_init_ring(dev)) {
2995 if (!np->in_shutdown)
2996 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
2998 /* reinit nic view of the rx queue */
2999 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
3000 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
3001 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
3002 base + NvRegRingSizes);
3004 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
3007 /* restart rx engine */
3009 spin_unlock(&np->lock);
3010 netif_addr_unlock(dev);
3011 netif_tx_unlock_bh(dev);
3012 nv_napi_enable(dev);
3018 static void nv_copy_mac_to_hw(struct net_device *dev)
3020 u8 __iomem *base = get_hwbase(dev);
3023 mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) +
3024 (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24);
3025 mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8);
3027 writel(mac[0], base + NvRegMacAddrA);
3028 writel(mac[1], base + NvRegMacAddrB);
3032 * nv_set_mac_address: dev->set_mac_address function
3033 * Called with rtnl_lock() held.
3035 static int nv_set_mac_address(struct net_device *dev, void *addr)
3037 struct fe_priv *np = netdev_priv(dev);
3038 struct sockaddr *macaddr = (struct sockaddr*)addr;
3040 if (!is_valid_ether_addr(macaddr->sa_data))
3041 return -EADDRNOTAVAIL;
3043 /* synchronized against open : rtnl_lock() held by caller */
3044 memcpy(dev->dev_addr, macaddr->sa_data, ETH_ALEN);
3046 if (netif_running(dev)) {
3047 netif_tx_lock_bh(dev);
3048 netif_addr_lock(dev);
3049 spin_lock_irq(&np->lock);
3051 /* stop rx engine */
3054 /* set mac address */
3055 nv_copy_mac_to_hw(dev);
3057 /* restart rx engine */
3059 spin_unlock_irq(&np->lock);
3060 netif_addr_unlock(dev);
3061 netif_tx_unlock_bh(dev);
3063 nv_copy_mac_to_hw(dev);
3069 * nv_set_multicast: dev->set_multicast function
3070 * Called with netif_tx_lock held.
3072 static void nv_set_multicast(struct net_device *dev)
3074 struct fe_priv *np = netdev_priv(dev);
3075 u8 __iomem *base = get_hwbase(dev);
3078 u32 pff = readl(base + NvRegPacketFilterFlags) & NVREG_PFF_PAUSE_RX;
3080 memset(addr, 0, sizeof(addr));
3081 memset(mask, 0, sizeof(mask));
3083 if (dev->flags & IFF_PROMISC) {
3084 pff |= NVREG_PFF_PROMISC;
3086 pff |= NVREG_PFF_MYADDR;
3088 if (dev->flags & IFF_ALLMULTI || dev->mc_list) {
3092 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0xffffffff;
3093 if (dev->flags & IFF_ALLMULTI) {
3094 alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0;
3096 struct dev_mc_list *walk;
3098 walk = dev->mc_list;
3099 while (walk != NULL) {
3101 a = le32_to_cpu(*(__le32 *) walk->dmi_addr);
3102 b = le16_to_cpu(*(__le16 *) (&walk->dmi_addr[4]));
3110 addr[0] = alwaysOn[0];
3111 addr[1] = alwaysOn[1];
3112 mask[0] = alwaysOn[0] | alwaysOff[0];
3113 mask[1] = alwaysOn[1] | alwaysOff[1];
3115 mask[0] = NVREG_MCASTMASKA_NONE;
3116 mask[1] = NVREG_MCASTMASKB_NONE;
3119 addr[0] |= NVREG_MCASTADDRA_FORCE;
3120 pff |= NVREG_PFF_ALWAYS;
3121 spin_lock_irq(&np->lock);
3123 writel(addr[0], base + NvRegMulticastAddrA);
3124 writel(addr[1], base + NvRegMulticastAddrB);
3125 writel(mask[0], base + NvRegMulticastMaskA);
3126 writel(mask[1], base + NvRegMulticastMaskB);
3127 writel(pff, base + NvRegPacketFilterFlags);
3128 dprintk(KERN_INFO "%s: reconfiguration for multicast lists.\n",
3131 spin_unlock_irq(&np->lock);
3134 static void nv_update_pause(struct net_device *dev, u32 pause_flags)
3136 struct fe_priv *np = netdev_priv(dev);
3137 u8 __iomem *base = get_hwbase(dev);
3139 np->pause_flags &= ~(NV_PAUSEFRAME_TX_ENABLE | NV_PAUSEFRAME_RX_ENABLE);
3141 if (np->pause_flags & NV_PAUSEFRAME_RX_CAPABLE) {
3142 u32 pff = readl(base + NvRegPacketFilterFlags) & ~NVREG_PFF_PAUSE_RX;
3143 if (pause_flags & NV_PAUSEFRAME_RX_ENABLE) {
3144 writel(pff|NVREG_PFF_PAUSE_RX, base + NvRegPacketFilterFlags);
3145 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3147 writel(pff, base + NvRegPacketFilterFlags);
3150 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE) {
3151 u32 regmisc = readl(base + NvRegMisc1) & ~NVREG_MISC1_PAUSE_TX;
3152 if (pause_flags & NV_PAUSEFRAME_TX_ENABLE) {
3153 u32 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V1;
3154 if (np->driver_data & DEV_HAS_PAUSEFRAME_TX_V2)
3155 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V2;
3156 if (np->driver_data & DEV_HAS_PAUSEFRAME_TX_V3) {
3157 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V3;
3158 /* limit the number of tx pause frames to a default of 8 */
3159 writel(readl(base + NvRegTxPauseFrameLimit)|NVREG_TX_PAUSEFRAMELIMIT_ENABLE, base + NvRegTxPauseFrameLimit);
3161 writel(pause_enable, base + NvRegTxPauseFrame);
3162 writel(regmisc|NVREG_MISC1_PAUSE_TX, base + NvRegMisc1);
3163 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3165 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
3166 writel(regmisc, base + NvRegMisc1);
3172 * nv_update_linkspeed: Setup the MAC according to the link partner
3173 * @dev: Network device to be configured
3175 * The function queries the PHY and checks if there is a link partner.
3176 * If yes, then it sets up the MAC accordingly. Otherwise, the MAC is
3177 * set to 10 MBit HD.
3179 * The function returns 0 if there is no link partner and 1 if there is
3180 * a good link partner.
3182 static int nv_update_linkspeed(struct net_device *dev)
3184 struct fe_priv *np = netdev_priv(dev);
3185 u8 __iomem *base = get_hwbase(dev);
3188 int adv_lpa, adv_pause, lpa_pause;
3189 int newls = np->linkspeed;
3190 int newdup = np->duplex;
3193 u32 control_1000, status_1000, phyreg, pause_flags, txreg;
3197 /* BMSR_LSTATUS is latched, read it twice:
3198 * we want the current value.
3200 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
3201 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
3203 if (!(mii_status & BMSR_LSTATUS)) {
3204 dprintk(KERN_DEBUG "%s: no link detected by phy - falling back to 10HD.\n",
3206 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3212 if (np->autoneg == 0) {
3213 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: autoneg off, PHY set to 0x%04x.\n",
3214 dev->name, np->fixed_mode);
3215 if (np->fixed_mode & LPA_100FULL) {
3216 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3218 } else if (np->fixed_mode & LPA_100HALF) {
3219 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3221 } else if (np->fixed_mode & LPA_10FULL) {
3222 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3225 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3231 /* check auto negotiation is complete */
3232 if (!(mii_status & BMSR_ANEGCOMPLETE)) {
3233 /* still in autonegotiation - configure nic for 10 MBit HD and wait. */
3234 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3237 dprintk(KERN_DEBUG "%s: autoneg not completed - falling back to 10HD.\n", dev->name);
3241 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
3242 lpa = mii_rw(dev, np->phyaddr, MII_LPA, MII_READ);
3243 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: PHY advertises 0x%04x, lpa 0x%04x.\n",
3244 dev->name, adv, lpa);
3247 if (np->gigabit == PHY_GIGABIT) {
3248 control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
3249 status_1000 = mii_rw(dev, np->phyaddr, MII_STAT1000, MII_READ);
3251 if ((control_1000 & ADVERTISE_1000FULL) &&
3252 (status_1000 & LPA_1000FULL)) {
3253 dprintk(KERN_DEBUG "%s: nv_update_linkspeed: GBit ethernet detected.\n",
3255 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_1000;
3261 /* FIXME: handle parallel detection properly */
3262 adv_lpa = lpa & adv;
3263 if (adv_lpa & LPA_100FULL) {
3264 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3266 } else if (adv_lpa & LPA_100HALF) {
3267 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100;
3269 } else if (adv_lpa & LPA_10FULL) {
3270 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3272 } else if (adv_lpa & LPA_10HALF) {
3273 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3276 dprintk(KERN_DEBUG "%s: bad ability %04x - falling back to 10HD.\n", dev->name, adv_lpa);
3277 newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
3282 if (np->duplex == newdup && np->linkspeed == newls)
3285 dprintk(KERN_INFO "%s: changing link setting from %d/%d to %d/%d.\n",
3286 dev->name, np->linkspeed, np->duplex, newls, newdup);
3288 np->duplex = newdup;
3289 np->linkspeed = newls;
3291 /* The transmitter and receiver must be restarted for safe update */
3292 if (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_START) {
3293 txrxFlags |= NV_RESTART_TX;
3296 if (readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) {
3297 txrxFlags |= NV_RESTART_RX;
3301 if (np->gigabit == PHY_GIGABIT) {
3302 phyreg = readl(base + NvRegSlotTime);
3303 phyreg &= ~(0x3FF00);
3304 if (((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10) ||
3305 ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100))
3306 phyreg |= NVREG_SLOTTIME_10_100_FULL;
3307 else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000)
3308 phyreg |= NVREG_SLOTTIME_1000_FULL;
3309 writel(phyreg, base + NvRegSlotTime);
3312 phyreg = readl(base + NvRegPhyInterface);
3313 phyreg &= ~(PHY_HALF|PHY_100|PHY_1000);
3314 if (np->duplex == 0)
3316 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100)
3318 else if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
3320 writel(phyreg, base + NvRegPhyInterface);
3322 phy_exp = mii_rw(dev, np->phyaddr, MII_EXPANSION, MII_READ) & EXPANSION_NWAY; /* autoneg capable */
3323 if (phyreg & PHY_RGMII) {
3324 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000) {
3325 txreg = NVREG_TX_DEFERRAL_RGMII_1000;
3327 if (!phy_exp && !np->duplex && (np->driver_data & DEV_HAS_COLLISION_FIX)) {
3328 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_10)
3329 txreg = NVREG_TX_DEFERRAL_RGMII_STRETCH_10;
3331 txreg = NVREG_TX_DEFERRAL_RGMII_STRETCH_100;
3333 txreg = NVREG_TX_DEFERRAL_RGMII_10_100;
3337 if (!phy_exp && !np->duplex && (np->driver_data & DEV_HAS_COLLISION_FIX))
3338 txreg = NVREG_TX_DEFERRAL_MII_STRETCH;
3340 txreg = NVREG_TX_DEFERRAL_DEFAULT;
3342 writel(txreg, base + NvRegTxDeferral);
3344 if (np->desc_ver == DESC_VER_1) {
3345 txreg = NVREG_TX_WM_DESC1_DEFAULT;
3347 if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000)
3348 txreg = NVREG_TX_WM_DESC2_3_1000;
3350 txreg = NVREG_TX_WM_DESC2_3_DEFAULT;
3352 writel(txreg, base + NvRegTxWatermark);
3354 writel(NVREG_MISC1_FORCE | ( np->duplex ? 0 : NVREG_MISC1_HD),
3357 writel(np->linkspeed, base + NvRegLinkSpeed);
3361 /* setup pause frame */
3362 if (np->duplex != 0) {
3363 if (np->autoneg && np->pause_flags & NV_PAUSEFRAME_AUTONEG) {
3364 adv_pause = adv & (ADVERTISE_PAUSE_CAP| ADVERTISE_PAUSE_ASYM);
3365 lpa_pause = lpa & (LPA_PAUSE_CAP| LPA_PAUSE_ASYM);
3367 switch (adv_pause) {
3368 case ADVERTISE_PAUSE_CAP:
3369 if (lpa_pause & LPA_PAUSE_CAP) {
3370 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3371 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
3372 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3375 case ADVERTISE_PAUSE_ASYM:
3376 if (lpa_pause == (LPA_PAUSE_CAP| LPA_PAUSE_ASYM))
3378 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3381 case ADVERTISE_PAUSE_CAP| ADVERTISE_PAUSE_ASYM:
3382 if (lpa_pause & LPA_PAUSE_CAP)
3384 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3385 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
3386 pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
3388 if (lpa_pause == LPA_PAUSE_ASYM)
3390 pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
3395 pause_flags = np->pause_flags;
3398 nv_update_pause(dev, pause_flags);
3400 if (txrxFlags & NV_RESTART_TX)
3402 if (txrxFlags & NV_RESTART_RX)
3408 static void nv_linkchange(struct net_device *dev)
3410 if (nv_update_linkspeed(dev)) {
3411 if (!netif_carrier_ok(dev)) {
3412 netif_carrier_on(dev);
3413 printk(KERN_INFO "%s: link up.\n", dev->name);
3414 nv_txrx_gate(dev, false);
3418 if (netif_carrier_ok(dev)) {
3419 netif_carrier_off(dev);
3420 printk(KERN_INFO "%s: link down.\n", dev->name);
3421 nv_txrx_gate(dev, true);
3427 static void nv_link_irq(struct net_device *dev)
3429 u8 __iomem *base = get_hwbase(dev);
3432 miistat = readl(base + NvRegMIIStatus);
3433 writel(NVREG_MIISTAT_LINKCHANGE, base + NvRegMIIStatus);
3434 dprintk(KERN_INFO "%s: link change irq, status 0x%x.\n", dev->name, miistat);
3436 if (miistat & (NVREG_MIISTAT_LINKCHANGE))
3438 dprintk(KERN_DEBUG "%s: link change notification done.\n", dev->name);
3441 static void nv_msi_workaround(struct fe_priv *np)
3444 /* Need to toggle the msi irq mask within the ethernet device,
3445 * otherwise, future interrupts will not be detected.
3447 if (np->msi_flags & NV_MSI_ENABLED) {
3448 u8 __iomem *base = np->base;
3450 writel(0, base + NvRegMSIIrqMask);
3451 writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask);
3455 static inline int nv_change_interrupt_mode(struct net_device *dev, int total_work)
3457 struct fe_priv *np = netdev_priv(dev);
3459 if (optimization_mode == NV_OPTIMIZATION_MODE_DYNAMIC) {
3460 if (total_work > NV_DYNAMIC_THRESHOLD) {
3461 /* transition to poll based interrupts */
3462 np->quiet_count = 0;
3463 if (np->irqmask != NVREG_IRQMASK_CPU) {
3464 np->irqmask = NVREG_IRQMASK_CPU;
3468 if (np->quiet_count < NV_DYNAMIC_MAX_QUIET_COUNT) {
3471 /* reached a period of low activity, switch
3472 to per tx/rx packet interrupts */
3473 if (np->irqmask != NVREG_IRQMASK_THROUGHPUT) {
3474 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
3483 static irqreturn_t nv_nic_irq(int foo, void *data)
3485 struct net_device *dev = (struct net_device *) data;
3486 struct fe_priv *np = netdev_priv(dev);
3487 u8 __iomem *base = get_hwbase(dev);
3488 #ifndef CONFIG_FORCEDETH_NAPI
3493 dprintk(KERN_DEBUG "%s: nv_nic_irq\n", dev->name);
3495 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3496 np->events = readl(base + NvRegIrqStatus);
3497 writel(np->events, base + NvRegIrqStatus);
3499 np->events = readl(base + NvRegMSIXIrqStatus);
3500 writel(np->events, base + NvRegMSIXIrqStatus);
3502 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, np->events);
3503 if (!(np->events & np->irqmask))
3506 nv_msi_workaround(np);
3508 #ifdef CONFIG_FORCEDETH_NAPI
3509 napi_schedule(&np->napi);
3511 /* Disable furthur irq's
3512 (msix not enabled with napi) */
3513 writel(0, base + NvRegIrqMask);
3519 if ((work = nv_rx_process(dev, RX_WORK_PER_LOOP))) {
3520 if (unlikely(nv_alloc_rx(dev))) {
3521 spin_lock(&np->lock);
3522 if (!np->in_shutdown)
3523 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3524 spin_unlock(&np->lock);
3528 spin_lock(&np->lock);
3529 work += nv_tx_done(dev, TX_WORK_PER_LOOP);
3530 spin_unlock(&np->lock);
3539 while (loop_count < max_interrupt_work);
3541 if (nv_change_interrupt_mode(dev, total_work)) {
3542 /* setup new irq mask */
3543 writel(np->irqmask, base + NvRegIrqMask);
3546 if (unlikely(np->events & NVREG_IRQ_LINK)) {
3547 spin_lock(&np->lock);
3549 spin_unlock(&np->lock);
3551 if (unlikely(np->need_linktimer && time_after(jiffies, np->link_timeout))) {
3552 spin_lock(&np->lock);
3554 spin_unlock(&np->lock);
3555 np->link_timeout = jiffies + LINK_TIMEOUT;
3557 if (unlikely(np->events & NVREG_IRQ_RECOVER_ERROR)) {
3558 spin_lock(&np->lock);
3559 /* disable interrupts on the nic */
3560 if (!(np->msi_flags & NV_MSI_X_ENABLED))
3561 writel(0, base + NvRegIrqMask);
3563 writel(np->irqmask, base + NvRegIrqMask);
3566 if (!np->in_shutdown) {
3567 np->nic_poll_irq = np->irqmask;
3568 np->recover_error = 1;
3569 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3571 spin_unlock(&np->lock);
3574 dprintk(KERN_DEBUG "%s: nv_nic_irq completed\n", dev->name);
3580 * All _optimized functions are used to help increase performance
3581 * (reduce CPU and increase throughput). They use descripter version 3,
3582 * compiler directives, and reduce memory accesses.
3584 static irqreturn_t nv_nic_irq_optimized(int foo, void *data)
3586 struct net_device *dev = (struct net_device *) data;
3587 struct fe_priv *np = netdev_priv(dev);
3588 u8 __iomem *base = get_hwbase(dev);
3589 #ifndef CONFIG_FORCEDETH_NAPI
3594 dprintk(KERN_DEBUG "%s: nv_nic_irq_optimized\n", dev->name);
3596 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3597 np->events = readl(base + NvRegIrqStatus);
3598 writel(np->events, base + NvRegIrqStatus);
3600 np->events = readl(base + NvRegMSIXIrqStatus);
3601 writel(np->events, base + NvRegMSIXIrqStatus);
3603 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, np->events);
3604 if (!(np->events & np->irqmask))
3607 nv_msi_workaround(np);
3609 #ifdef CONFIG_FORCEDETH_NAPI
3610 napi_schedule(&np->napi);
3612 /* Disable furthur irq's
3613 (msix not enabled with napi) */
3614 writel(0, base + NvRegIrqMask);
3620 if ((work = nv_rx_process_optimized(dev, RX_WORK_PER_LOOP))) {
3621 if (unlikely(nv_alloc_rx_optimized(dev))) {
3622 spin_lock(&np->lock);
3623 if (!np->in_shutdown)
3624 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3625 spin_unlock(&np->lock);
3629 spin_lock(&np->lock);
3630 work += nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
3631 spin_unlock(&np->lock);
3640 while (loop_count < max_interrupt_work);
3642 if (nv_change_interrupt_mode(dev, total_work)) {
3643 /* setup new irq mask */
3644 writel(np->irqmask, base + NvRegIrqMask);
3647 if (unlikely(np->events & NVREG_IRQ_LINK)) {
3648 spin_lock(&np->lock);
3650 spin_unlock(&np->lock);
3652 if (unlikely(np->need_linktimer && time_after(jiffies, np->link_timeout))) {
3653 spin_lock(&np->lock);
3655 spin_unlock(&np->lock);
3656 np->link_timeout = jiffies + LINK_TIMEOUT;
3658 if (unlikely(np->events & NVREG_IRQ_RECOVER_ERROR)) {
3659 spin_lock(&np->lock);
3660 /* disable interrupts on the nic */
3661 if (!(np->msi_flags & NV_MSI_X_ENABLED))
3662 writel(0, base + NvRegIrqMask);
3664 writel(np->irqmask, base + NvRegIrqMask);
3667 if (!np->in_shutdown) {
3668 np->nic_poll_irq = np->irqmask;
3669 np->recover_error = 1;
3670 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3672 spin_unlock(&np->lock);
3676 dprintk(KERN_DEBUG "%s: nv_nic_irq_optimized completed\n", dev->name);
3681 static irqreturn_t nv_nic_irq_tx(int foo, void *data)
3683 struct net_device *dev = (struct net_device *) data;
3684 struct fe_priv *np = netdev_priv(dev);
3685 u8 __iomem *base = get_hwbase(dev);
3688 unsigned long flags;
3690 dprintk(KERN_DEBUG "%s: nv_nic_irq_tx\n", dev->name);
3693 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_TX_ALL;
3694 writel(NVREG_IRQ_TX_ALL, base + NvRegMSIXIrqStatus);
3695 dprintk(KERN_DEBUG "%s: tx irq: %08x\n", dev->name, events);
3696 if (!(events & np->irqmask))
3699 spin_lock_irqsave(&np->lock, flags);
3700 nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
3701 spin_unlock_irqrestore(&np->lock, flags);
3703 if (unlikely(i > max_interrupt_work)) {
3704 spin_lock_irqsave(&np->lock, flags);
3705 /* disable interrupts on the nic */
3706 writel(NVREG_IRQ_TX_ALL, base + NvRegIrqMask);
3709 if (!np->in_shutdown) {
3710 np->nic_poll_irq |= NVREG_IRQ_TX_ALL;
3711 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3713 spin_unlock_irqrestore(&np->lock, flags);
3714 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_tx.\n", dev->name, i);
3719 dprintk(KERN_DEBUG "%s: nv_nic_irq_tx completed\n", dev->name);
3721 return IRQ_RETVAL(i);
3724 #ifdef CONFIG_FORCEDETH_NAPI
3725 static int nv_napi_poll(struct napi_struct *napi, int budget)
3727 struct fe_priv *np = container_of(napi, struct fe_priv, napi);
3728 struct net_device *dev = np->dev;
3729 u8 __iomem *base = get_hwbase(dev);
3730 unsigned long flags;
3732 int tx_work, rx_work;
3734 if (!nv_optimized(np)) {
3735 spin_lock_irqsave(&np->lock, flags);
3736 tx_work = nv_tx_done(dev, np->tx_ring_size);
3737 spin_unlock_irqrestore(&np->lock, flags);
3739 rx_work = nv_rx_process(dev, budget);
3740 retcode = nv_alloc_rx(dev);
3742 spin_lock_irqsave(&np->lock, flags);
3743 tx_work = nv_tx_done_optimized(dev, np->tx_ring_size);
3744 spin_unlock_irqrestore(&np->lock, flags);
3746 rx_work = nv_rx_process_optimized(dev, budget);
3747 retcode = nv_alloc_rx_optimized(dev);
3751 spin_lock_irqsave(&np->lock, flags);
3752 if (!np->in_shutdown)
3753 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3754 spin_unlock_irqrestore(&np->lock, flags);
3757 nv_change_interrupt_mode(dev, tx_work + rx_work);
3759 if (unlikely(np->events & NVREG_IRQ_LINK)) {
3760 spin_lock_irqsave(&np->lock, flags);
3762 spin_unlock_irqrestore(&np->lock, flags);
3764 if (unlikely(np->need_linktimer && time_after(jiffies, np->link_timeout))) {
3765 spin_lock_irqsave(&np->lock, flags);
3767 spin_unlock_irqrestore(&np->lock, flags);
3768 np->link_timeout = jiffies + LINK_TIMEOUT;
3770 if (unlikely(np->events & NVREG_IRQ_RECOVER_ERROR)) {
3771 spin_lock_irqsave(&np->lock, flags);
3772 if (!np->in_shutdown) {
3773 np->nic_poll_irq = np->irqmask;
3774 np->recover_error = 1;
3775 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3777 spin_unlock_irqrestore(&np->lock, flags);
3778 napi_complete(napi);
3782 if (rx_work < budget) {
3783 /* re-enable interrupts
3784 (msix not enabled in napi) */
3785 napi_complete(napi);
3787 writel(np->irqmask, base + NvRegIrqMask);
3793 static irqreturn_t nv_nic_irq_rx(int foo, void *data)
3795 struct net_device *dev = (struct net_device *) data;
3796 struct fe_priv *np = netdev_priv(dev);
3797 u8 __iomem *base = get_hwbase(dev);
3800 unsigned long flags;
3802 dprintk(KERN_DEBUG "%s: nv_nic_irq_rx\n", dev->name);
3805 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL;
3806 writel(NVREG_IRQ_RX_ALL, base + NvRegMSIXIrqStatus);
3807 dprintk(KERN_DEBUG "%s: rx irq: %08x\n", dev->name, events);
3808 if (!(events & np->irqmask))
3811 if (nv_rx_process_optimized(dev, RX_WORK_PER_LOOP)) {
3812 if (unlikely(nv_alloc_rx_optimized(dev))) {
3813 spin_lock_irqsave(&np->lock, flags);
3814 if (!np->in_shutdown)
3815 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
3816 spin_unlock_irqrestore(&np->lock, flags);
3820 if (unlikely(i > max_interrupt_work)) {
3821 spin_lock_irqsave(&np->lock, flags);
3822 /* disable interrupts on the nic */
3823 writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask);
3826 if (!np->in_shutdown) {
3827 np->nic_poll_irq |= NVREG_IRQ_RX_ALL;
3828 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3830 spin_unlock_irqrestore(&np->lock, flags);
3831 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_rx.\n", dev->name, i);
3835 dprintk(KERN_DEBUG "%s: nv_nic_irq_rx completed\n", dev->name);
3837 return IRQ_RETVAL(i);
3840 static irqreturn_t nv_nic_irq_other(int foo, void *data)
3842 struct net_device *dev = (struct net_device *) data;
3843 struct fe_priv *np = netdev_priv(dev);
3844 u8 __iomem *base = get_hwbase(dev);
3847 unsigned long flags;
3849 dprintk(KERN_DEBUG "%s: nv_nic_irq_other\n", dev->name);
3852 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_OTHER;
3853 writel(NVREG_IRQ_OTHER, base + NvRegMSIXIrqStatus);
3854 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
3855 if (!(events & np->irqmask))
3858 /* check tx in case we reached max loop limit in tx isr */
3859 spin_lock_irqsave(&np->lock, flags);
3860 nv_tx_done_optimized(dev, TX_WORK_PER_LOOP);
3861 spin_unlock_irqrestore(&np->lock, flags);
3863 if (events & NVREG_IRQ_LINK) {
3864 spin_lock_irqsave(&np->lock, flags);
3866 spin_unlock_irqrestore(&np->lock, flags);
3868 if (np->need_linktimer && time_after(jiffies, np->link_timeout)) {
3869 spin_lock_irqsave(&np->lock, flags);
3871 spin_unlock_irqrestore(&np->lock, flags);
3872 np->link_timeout = jiffies + LINK_TIMEOUT;
3874 if (events & NVREG_IRQ_RECOVER_ERROR) {
3875 spin_lock_irq(&np->lock);
3876 /* disable interrupts on the nic */
3877 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
3880 if (!np->in_shutdown) {
3881 np->nic_poll_irq |= NVREG_IRQ_OTHER;
3882 np->recover_error = 1;
3883 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3885 spin_unlock_irq(&np->lock);
3888 if (unlikely(i > max_interrupt_work)) {
3889 spin_lock_irqsave(&np->lock, flags);
3890 /* disable interrupts on the nic */
3891 writel(NVREG_IRQ_OTHER, base + NvRegIrqMask);
3894 if (!np->in_shutdown) {
3895 np->nic_poll_irq |= NVREG_IRQ_OTHER;
3896 mod_timer(&np->nic_poll, jiffies + POLL_WAIT);
3898 spin_unlock_irqrestore(&np->lock, flags);
3899 printk(KERN_DEBUG "%s: too many iterations (%d) in nv_nic_irq_other.\n", dev->name, i);
3904 dprintk(KERN_DEBUG "%s: nv_nic_irq_other completed\n", dev->name);
3906 return IRQ_RETVAL(i);
3909 static irqreturn_t nv_nic_irq_test(int foo, void *data)
3911 struct net_device *dev = (struct net_device *) data;
3912 struct fe_priv *np = netdev_priv(dev);
3913 u8 __iomem *base = get_hwbase(dev);
3916 dprintk(KERN_DEBUG "%s: nv_nic_irq_test\n", dev->name);
3918 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
3919 events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK;
3920 writel(NVREG_IRQ_TIMER, base + NvRegIrqStatus);
3922 events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK;
3923 writel(NVREG_IRQ_TIMER, base + NvRegMSIXIrqStatus);
3926 dprintk(KERN_DEBUG "%s: irq: %08x\n", dev->name, events);
3927 if (!(events & NVREG_IRQ_TIMER))
3928 return IRQ_RETVAL(0);
3930 nv_msi_workaround(np);
3932 spin_lock(&np->lock);
3934 spin_unlock(&np->lock);
3936 dprintk(KERN_DEBUG "%s: nv_nic_irq_test completed\n", dev->name);
3938 return IRQ_RETVAL(1);
3941 static void set_msix_vector_map(struct net_device *dev, u32 vector, u32 irqmask)
3943 u8 __iomem *base = get_hwbase(dev);
3947 /* Each interrupt bit can be mapped to a MSIX vector (4 bits).
3948 * MSIXMap0 represents the first 8 interrupts and MSIXMap1 represents
3949 * the remaining 8 interrupts.
3951 for (i = 0; i < 8; i++) {
3952 if ((irqmask >> i) & 0x1) {
3953 msixmap |= vector << (i << 2);
3956 writel(readl(base + NvRegMSIXMap0) | msixmap, base + NvRegMSIXMap0);
3959 for (i = 0; i < 8; i++) {
3960 if ((irqmask >> (i + 8)) & 0x1) {
3961 msixmap |= vector << (i << 2);
3964 writel(readl(base + NvRegMSIXMap1) | msixmap, base + NvRegMSIXMap1);
3967 static int nv_request_irq(struct net_device *dev, int intr_test)
3969 struct fe_priv *np = get_nvpriv(dev);
3970 u8 __iomem *base = get_hwbase(dev);
3973 irqreturn_t (*handler)(int foo, void *data);
3976 handler = nv_nic_irq_test;
3978 if (nv_optimized(np))
3979 handler = nv_nic_irq_optimized;
3981 handler = nv_nic_irq;
3984 if (np->msi_flags & NV_MSI_X_CAPABLE) {
3985 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++) {
3986 np->msi_x_entry[i].entry = i;
3988 if ((ret = pci_enable_msix(np->pci_dev, np->msi_x_entry, (np->msi_flags & NV_MSI_X_VECTORS_MASK))) == 0) {
3989 np->msi_flags |= NV_MSI_X_ENABLED;
3990 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT && !intr_test) {
3991 /* Request irq for rx handling */
3992 sprintf(np->name_rx, "%s-rx", dev->name);
3993 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector,
3994 &nv_nic_irq_rx, IRQF_SHARED, np->name_rx, dev) != 0) {
3995 printk(KERN_INFO "forcedeth: request_irq failed for rx %d\n", ret);
3996 pci_disable_msix(np->pci_dev);
3997 np->msi_flags &= ~NV_MSI_X_ENABLED;
4000 /* Request irq for tx handling */
4001 sprintf(np->name_tx, "%s-tx", dev->name);
4002 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector,
4003 &nv_nic_irq_tx, IRQF_SHARED, np->name_tx, dev) != 0) {
4004 printk(KERN_INFO "forcedeth: request_irq failed for tx %d\n", ret);
4005 pci_disable_msix(np->pci_dev);
4006 np->msi_flags &= ~NV_MSI_X_ENABLED;
4009 /* Request irq for link and timer handling */
4010 sprintf(np->name_other, "%s-other", dev->name);
4011 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector,
4012 &nv_nic_irq_other, IRQF_SHARED, np->name_other, dev) != 0) {
4013 printk(KERN_INFO "forcedeth: request_irq failed for link %d\n", ret);
4014 pci_disable_msix(np->pci_dev);
4015 np->msi_flags &= ~NV_MSI_X_ENABLED;
4018 /* map interrupts to their respective vector */
4019 writel(0, base + NvRegMSIXMap0);
4020 writel(0, base + NvRegMSIXMap1);
4021 set_msix_vector_map(dev, NV_MSI_X_VECTOR_RX, NVREG_IRQ_RX_ALL);
4022 set_msix_vector_map(dev, NV_MSI_X_VECTOR_TX, NVREG_IRQ_TX_ALL);
4023 set_msix_vector_map(dev, NV_MSI_X_VECTOR_OTHER, NVREG_IRQ_OTHER);
4025 /* Request irq for all interrupts */
4026 if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector, handler, IRQF_SHARED, dev->name, dev) != 0) {
4027 printk(KERN_INFO "forcedeth: request_irq failed %d\n", ret);
4028 pci_disable_msix(np->pci_dev);
4029 np->msi_flags &= ~NV_MSI_X_ENABLED;
4033 /* map interrupts to vector 0 */
4034 writel(0, base + NvRegMSIXMap0);
4035 writel(0, base + NvRegMSIXMap1);
4039 if (ret != 0 && np->msi_flags & NV_MSI_CAPABLE) {
4040 if ((ret = pci_enable_msi(np->pci_dev)) == 0) {
4041 np->msi_flags |= NV_MSI_ENABLED;
4042 dev->irq = np->pci_dev->irq;
4043 if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0) {
4044 printk(KERN_INFO "forcedeth: request_irq failed %d\n", ret);
4045 pci_disable_msi(np->pci_dev);
4046 np->msi_flags &= ~NV_MSI_ENABLED;
4047 dev->irq = np->pci_dev->irq;
4051 /* map interrupts to vector 0 */
4052 writel(0, base + NvRegMSIMap0);
4053 writel(0, base + NvRegMSIMap1);
4054 /* enable msi vector 0 */
4055 writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask);
4059 if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0)
4066 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector, dev);
4068 free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector, dev);
4073 static void nv_free_irq(struct net_device *dev)
4075 struct fe_priv *np = get_nvpriv(dev);
4078 if (np->msi_flags & NV_MSI_X_ENABLED) {
4079 for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++) {
4080 free_irq(np->msi_x_entry[i].vector, dev);
4082 pci_disable_msix(np->pci_dev);
4083 np->msi_flags &= ~NV_MSI_X_ENABLED;
4085 free_irq(np->pci_dev->irq, dev);
4086 if (np->msi_flags & NV_MSI_ENABLED) {
4087 pci_disable_msi(np->pci_dev);
4088 np->msi_flags &= ~NV_MSI_ENABLED;
4093 static void nv_do_nic_poll(unsigned long data)
4095 struct net_device *dev = (struct net_device *) data;
4096 struct fe_priv *np = netdev_priv(dev);
4097 u8 __iomem *base = get_hwbase(dev);
4101 * First disable irq(s) and then
4102 * reenable interrupts on the nic, we have to do this before calling
4103 * nv_nic_irq because that may decide to do otherwise
4106 if (!using_multi_irqs(dev)) {
4107 if (np->msi_flags & NV_MSI_X_ENABLED)
4108 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
4110 disable_irq_lockdep(np->pci_dev->irq);
4113 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
4114 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
4115 mask |= NVREG_IRQ_RX_ALL;
4117 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
4118 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
4119 mask |= NVREG_IRQ_TX_ALL;
4121 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
4122 disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
4123 mask |= NVREG_IRQ_OTHER;
4126 /* disable_irq() contains synchronize_irq, thus no irq handler can run now */
4128 if (np->recover_error) {
4129 np->recover_error = 0;
4130 printk(KERN_INFO "%s: MAC in recoverable error state\n", dev->name);
4131 if (netif_running(dev)) {
4132 netif_tx_lock_bh(dev);
4133 netif_addr_lock(dev);
4134 spin_lock(&np->lock);
4137 if (np->driver_data & DEV_HAS_POWER_CNTRL)
4140 /* drain rx queue */
4142 /* reinit driver view of the rx queue */
4144 if (nv_init_ring(dev)) {
4145 if (!np->in_shutdown)
4146 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
4148 /* reinit nic view of the rx queue */
4149 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4150 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
4151 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
4152 base + NvRegRingSizes);
4154 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4156 /* clear interrupts */
4157 if (!(np->msi_flags & NV_MSI_X_ENABLED))
4158 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4160 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
4162 /* restart rx engine */
4164 spin_unlock(&np->lock);
4165 netif_addr_unlock(dev);
4166 netif_tx_unlock_bh(dev);
4170 writel(mask, base + NvRegIrqMask);
4173 if (!using_multi_irqs(dev)) {
4174 np->nic_poll_irq = 0;
4175 if (nv_optimized(np))
4176 nv_nic_irq_optimized(0, dev);
4179 if (np->msi_flags & NV_MSI_X_ENABLED)
4180 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector);
4182 enable_irq_lockdep(np->pci_dev->irq);
4184 if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) {
4185 np->nic_poll_irq &= ~NVREG_IRQ_RX_ALL;
4186 nv_nic_irq_rx(0, dev);
4187 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector);
4189 if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) {
4190 np->nic_poll_irq &= ~NVREG_IRQ_TX_ALL;
4191 nv_nic_irq_tx(0, dev);
4192 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector);
4194 if (np->nic_poll_irq & NVREG_IRQ_OTHER) {
4195 np->nic_poll_irq &= ~NVREG_IRQ_OTHER;
4196 nv_nic_irq_other(0, dev);
4197 enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector);
4203 #ifdef CONFIG_NET_POLL_CONTROLLER
4204 static void nv_poll_controller(struct net_device *dev)
4206 nv_do_nic_poll((unsigned long) dev);
4210 static void nv_do_stats_poll(unsigned long data)
4212 struct net_device *dev = (struct net_device *) data;
4213 struct fe_priv *np = netdev_priv(dev);
4215 nv_get_hw_stats(dev);
4217 if (!np->in_shutdown)
4218 mod_timer(&np->stats_poll,
4219 round_jiffies(jiffies + STATS_INTERVAL));
4222 static void nv_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info)
4224 struct fe_priv *np = netdev_priv(dev);
4225 strcpy(info->driver, DRV_NAME);
4226 strcpy(info->version, FORCEDETH_VERSION);
4227 strcpy(info->bus_info, pci_name(np->pci_dev));
4230 static void nv_get_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
4232 struct fe_priv *np = netdev_priv(dev);
4233 wolinfo->supported = WAKE_MAGIC;
4235 spin_lock_irq(&np->lock);
4237 wolinfo->wolopts = WAKE_MAGIC;
4238 spin_unlock_irq(&np->lock);
4241 static int nv_set_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo)
4243 struct fe_priv *np = netdev_priv(dev);
4244 u8 __iomem *base = get_hwbase(dev);
4247 if (wolinfo->wolopts == 0) {
4249 } else if (wolinfo->wolopts & WAKE_MAGIC) {
4251 flags = NVREG_WAKEUPFLAGS_ENABLE;
4253 if (netif_running(dev)) {
4254 spin_lock_irq(&np->lock);
4255 writel(flags, base + NvRegWakeUpFlags);
4256 spin_unlock_irq(&np->lock);
4261 static int nv_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
4263 struct fe_priv *np = netdev_priv(dev);
4266 spin_lock_irq(&np->lock);
4267 ecmd->port = PORT_MII;
4268 if (!netif_running(dev)) {
4269 /* We do not track link speed / duplex setting if the
4270 * interface is disabled. Force a link check */
4271 if (nv_update_linkspeed(dev)) {
4272 if (!netif_carrier_ok(dev))
4273 netif_carrier_on(dev);
4275 if (netif_carrier_ok(dev))
4276 netif_carrier_off(dev);
4280 if (netif_carrier_ok(dev)) {
4281 switch(np->linkspeed & (NVREG_LINKSPEED_MASK)) {
4282 case NVREG_LINKSPEED_10:
4283 ecmd->speed = SPEED_10;
4285 case NVREG_LINKSPEED_100:
4286 ecmd->speed = SPEED_100;
4288 case NVREG_LINKSPEED_1000:
4289 ecmd->speed = SPEED_1000;
4292 ecmd->duplex = DUPLEX_HALF;
4294 ecmd->duplex = DUPLEX_FULL;
4300 ecmd->autoneg = np->autoneg;
4302 ecmd->advertising = ADVERTISED_MII;
4304 ecmd->advertising |= ADVERTISED_Autoneg;
4305 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
4306 if (adv & ADVERTISE_10HALF)
4307 ecmd->advertising |= ADVERTISED_10baseT_Half;
4308 if (adv & ADVERTISE_10FULL)
4309 ecmd->advertising |= ADVERTISED_10baseT_Full;
4310 if (adv & ADVERTISE_100HALF)
4311 ecmd->advertising |= ADVERTISED_100baseT_Half;
4312 if (adv & ADVERTISE_100FULL)
4313 ecmd->advertising |= ADVERTISED_100baseT_Full;
4314 if (np->gigabit == PHY_GIGABIT) {
4315 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
4316 if (adv & ADVERTISE_1000FULL)
4317 ecmd->advertising |= ADVERTISED_1000baseT_Full;
4320 ecmd->supported = (SUPPORTED_Autoneg |
4321 SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full |
4322 SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full |
4324 if (np->gigabit == PHY_GIGABIT)
4325 ecmd->supported |= SUPPORTED_1000baseT_Full;
4327 ecmd->phy_address = np->phyaddr;
4328 ecmd->transceiver = XCVR_EXTERNAL;
4330 /* ignore maxtxpkt, maxrxpkt for now */
4331 spin_unlock_irq(&np->lock);
4335 static int nv_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd)
4337 struct fe_priv *np = netdev_priv(dev);
4339 if (ecmd->port != PORT_MII)
4341 if (ecmd->transceiver != XCVR_EXTERNAL)
4343 if (ecmd->phy_address != np->phyaddr) {
4344 /* TODO: support switching between multiple phys. Should be
4345 * trivial, but not enabled due to lack of test hardware. */
4348 if (ecmd->autoneg == AUTONEG_ENABLE) {
4351 mask = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full |
4352 ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full;
4353 if (np->gigabit == PHY_GIGABIT)
4354 mask |= ADVERTISED_1000baseT_Full;
4356 if ((ecmd->advertising & mask) == 0)
4359 } else if (ecmd->autoneg == AUTONEG_DISABLE) {
4360 /* Note: autonegotiation disable, speed 1000 intentionally
4361 * forbidden - noone should need that. */
4363 if (ecmd->speed != SPEED_10 && ecmd->speed != SPEED_100)
4365 if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL)
4371 netif_carrier_off(dev);
4372 if (netif_running(dev)) {
4373 unsigned long flags;
4375 nv_disable_irq(dev);
4376 netif_tx_lock_bh(dev);
4377 netif_addr_lock(dev);
4378 /* with plain spinlock lockdep complains */
4379 spin_lock_irqsave(&np->lock, flags);
4382 * this can take some time, and interrupts are disabled
4383 * due to spin_lock_irqsave, but let's hope no daemon
4384 * is going to change the settings very often...
4386 * NV_RXSTOP_DELAY1MAX + NV_TXSTOP_DELAY1MAX
4387 * + some minor delays, which is up to a second approximately
4390 spin_unlock_irqrestore(&np->lock, flags);
4391 netif_addr_unlock(dev);
4392 netif_tx_unlock_bh(dev);
4395 if (ecmd->autoneg == AUTONEG_ENABLE) {
4400 /* advertise only what has been requested */
4401 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
4402 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
4403 if (ecmd->advertising & ADVERTISED_10baseT_Half)
4404 adv |= ADVERTISE_10HALF;
4405 if (ecmd->advertising & ADVERTISED_10baseT_Full)
4406 adv |= ADVERTISE_10FULL;
4407 if (ecmd->advertising & ADVERTISED_100baseT_Half)
4408 adv |= ADVERTISE_100HALF;
4409 if (ecmd->advertising & ADVERTISED_100baseT_Full)
4410 adv |= ADVERTISE_100FULL;
4411 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisments but disable tx pause */
4412 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4413 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
4414 adv |= ADVERTISE_PAUSE_ASYM;
4415 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4417 if (np->gigabit == PHY_GIGABIT) {
4418 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
4419 adv &= ~ADVERTISE_1000FULL;
4420 if (ecmd->advertising & ADVERTISED_1000baseT_Full)
4421 adv |= ADVERTISE_1000FULL;
4422 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
4425 if (netif_running(dev))
4426 printk(KERN_INFO "%s: link down.\n", dev->name);
4427 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
4428 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
4429 bmcr |= BMCR_ANENABLE;
4430 /* reset the phy in order for settings to stick,
4431 * and cause autoneg to start */
4432 if (phy_reset(dev, bmcr)) {
4433 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
4437 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4438 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4445 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
4446 adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
4447 if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_HALF)
4448 adv |= ADVERTISE_10HALF;
4449 if (ecmd->speed == SPEED_10 && ecmd->duplex == DUPLEX_FULL)
4450 adv |= ADVERTISE_10FULL;
4451 if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_HALF)
4452 adv |= ADVERTISE_100HALF;
4453 if (ecmd->speed == SPEED_100 && ecmd->duplex == DUPLEX_FULL)
4454 adv |= ADVERTISE_100FULL;
4455 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
4456 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) {/* for rx we set both advertisments but disable tx pause */
4457 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4458 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
4460 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) {
4461 adv |= ADVERTISE_PAUSE_ASYM;
4462 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
4464 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4465 np->fixed_mode = adv;
4467 if (np->gigabit == PHY_GIGABIT) {
4468 adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ);
4469 adv &= ~ADVERTISE_1000FULL;
4470 mii_rw(dev, np->phyaddr, MII_CTRL1000, adv);
4473 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
4474 bmcr &= ~(BMCR_ANENABLE|BMCR_SPEED100|BMCR_SPEED1000|BMCR_FULLDPLX);
4475 if (np->fixed_mode & (ADVERTISE_10FULL|ADVERTISE_100FULL))
4476 bmcr |= BMCR_FULLDPLX;
4477 if (np->fixed_mode & (ADVERTISE_100HALF|ADVERTISE_100FULL))
4478 bmcr |= BMCR_SPEED100;
4479 if (np->phy_oui == PHY_OUI_MARVELL) {
4480 /* reset the phy in order for forced mode settings to stick */
4481 if (phy_reset(dev, bmcr)) {
4482 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
4486 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4487 if (netif_running(dev)) {
4488 /* Wait a bit and then reconfigure the nic. */
4495 if (netif_running(dev)) {
4503 #define FORCEDETH_REGS_VER 1
4505 static int nv_get_regs_len(struct net_device *dev)
4507 struct fe_priv *np = netdev_priv(dev);
4508 return np->register_size;
4511 static void nv_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *buf)
4513 struct fe_priv *np = netdev_priv(dev);
4514 u8 __iomem *base = get_hwbase(dev);
4518 regs->version = FORCEDETH_REGS_VER;
4519 spin_lock_irq(&np->lock);
4520 for (i = 0;i <= np->register_size/sizeof(u32); i++)
4521 rbuf[i] = readl(base + i*sizeof(u32));
4522 spin_unlock_irq(&np->lock);
4525 static int nv_nway_reset(struct net_device *dev)
4527 struct fe_priv *np = netdev_priv(dev);
4533 netif_carrier_off(dev);
4534 if (netif_running(dev)) {
4535 nv_disable_irq(dev);
4536 netif_tx_lock_bh(dev);
4537 netif_addr_lock(dev);
4538 spin_lock(&np->lock);
4541 spin_unlock(&np->lock);
4542 netif_addr_unlock(dev);
4543 netif_tx_unlock_bh(dev);
4544 printk(KERN_INFO "%s: link down.\n", dev->name);
4547 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
4548 if (np->phy_model == PHY_MODEL_MARVELL_E3016) {
4549 bmcr |= BMCR_ANENABLE;
4550 /* reset the phy in order for settings to stick*/
4551 if (phy_reset(dev, bmcr)) {
4552 printk(KERN_INFO "%s: phy reset failed\n", dev->name);
4556 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4557 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4560 if (netif_running(dev)) {
4572 static int nv_set_tso(struct net_device *dev, u32 value)
4574 struct fe_priv *np = netdev_priv(dev);
4576 if ((np->driver_data & DEV_HAS_CHECKSUM))
4577 return ethtool_op_set_tso(dev, value);
4582 static void nv_get_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
4584 struct fe_priv *np = netdev_priv(dev);
4586 ring->rx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
4587 ring->rx_mini_max_pending = 0;
4588 ring->rx_jumbo_max_pending = 0;
4589 ring->tx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3;
4591 ring->rx_pending = np->rx_ring_size;
4592 ring->rx_mini_pending = 0;
4593 ring->rx_jumbo_pending = 0;
4594 ring->tx_pending = np->tx_ring_size;
4597 static int nv_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ring)
4599 struct fe_priv *np = netdev_priv(dev);
4600 u8 __iomem *base = get_hwbase(dev);
4601 u8 *rxtx_ring, *rx_skbuff, *tx_skbuff;
4602 dma_addr_t ring_addr;
4604 if (ring->rx_pending < RX_RING_MIN ||
4605 ring->tx_pending < TX_RING_MIN ||
4606 ring->rx_mini_pending != 0 ||
4607 ring->rx_jumbo_pending != 0 ||
4608 (np->desc_ver == DESC_VER_1 &&
4609 (ring->rx_pending > RING_MAX_DESC_VER_1 ||
4610 ring->tx_pending > RING_MAX_DESC_VER_1)) ||
4611 (np->desc_ver != DESC_VER_1 &&
4612 (ring->rx_pending > RING_MAX_DESC_VER_2_3 ||
4613 ring->tx_pending > RING_MAX_DESC_VER_2_3))) {
4617 /* allocate new rings */
4618 if (!nv_optimized(np)) {
4619 rxtx_ring = pci_alloc_consistent(np->pci_dev,
4620 sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
4623 rxtx_ring = pci_alloc_consistent(np->pci_dev,
4624 sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
4627 rx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->rx_pending, GFP_KERNEL);
4628 tx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->tx_pending, GFP_KERNEL);
4629 if (!rxtx_ring || !rx_skbuff || !tx_skbuff) {
4630 /* fall back to old rings */
4631 if (!nv_optimized(np)) {
4633 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending),
4634 rxtx_ring, ring_addr);
4637 pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending),
4638 rxtx_ring, ring_addr);
4647 if (netif_running(dev)) {
4648 nv_disable_irq(dev);
4649 nv_napi_disable(dev);
4650 netif_tx_lock_bh(dev);
4651 netif_addr_lock(dev);
4652 spin_lock(&np->lock);
4662 /* set new values */
4663 np->rx_ring_size = ring->rx_pending;
4664 np->tx_ring_size = ring->tx_pending;
4666 if (!nv_optimized(np)) {
4667 np->rx_ring.orig = (struct ring_desc*)rxtx_ring;
4668 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
4670 np->rx_ring.ex = (struct ring_desc_ex*)rxtx_ring;
4671 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
4673 np->rx_skb = (struct nv_skb_map*)rx_skbuff;
4674 np->tx_skb = (struct nv_skb_map*)tx_skbuff;
4675 np->ring_addr = ring_addr;
4677 memset(np->rx_skb, 0, sizeof(struct nv_skb_map) * np->rx_ring_size);
4678 memset(np->tx_skb, 0, sizeof(struct nv_skb_map) * np->tx_ring_size);
4680 if (netif_running(dev)) {
4681 /* reinit driver view of the queues */
4683 if (nv_init_ring(dev)) {
4684 if (!np->in_shutdown)
4685 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
4688 /* reinit nic view of the queues */
4689 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
4690 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
4691 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
4692 base + NvRegRingSizes);
4694 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
4697 /* restart engines */
4699 spin_unlock(&np->lock);
4700 netif_addr_unlock(dev);
4701 netif_tx_unlock_bh(dev);
4702 nv_napi_enable(dev);
4710 static void nv_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
4712 struct fe_priv *np = netdev_priv(dev);
4714 pause->autoneg = (np->pause_flags & NV_PAUSEFRAME_AUTONEG) != 0;
4715 pause->rx_pause = (np->pause_flags & NV_PAUSEFRAME_RX_ENABLE) != 0;
4716 pause->tx_pause = (np->pause_flags & NV_PAUSEFRAME_TX_ENABLE) != 0;
4719 static int nv_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause)
4721 struct fe_priv *np = netdev_priv(dev);
4724 if ((!np->autoneg && np->duplex == 0) ||
4725 (np->autoneg && !pause->autoneg && np->duplex == 0)) {
4726 printk(KERN_INFO "%s: can not set pause settings when forced link is in half duplex.\n",
4730 if (pause->tx_pause && !(np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)) {
4731 printk(KERN_INFO "%s: hardware does not support tx pause frames.\n", dev->name);
4735 netif_carrier_off(dev);
4736 if (netif_running(dev)) {
4737 nv_disable_irq(dev);
4738 netif_tx_lock_bh(dev);
4739 netif_addr_lock(dev);
4740 spin_lock(&np->lock);
4743 spin_unlock(&np->lock);
4744 netif_addr_unlock(dev);
4745 netif_tx_unlock_bh(dev);
4748 np->pause_flags &= ~(NV_PAUSEFRAME_RX_REQ|NV_PAUSEFRAME_TX_REQ);
4749 if (pause->rx_pause)
4750 np->pause_flags |= NV_PAUSEFRAME_RX_REQ;
4751 if (pause->tx_pause)
4752 np->pause_flags |= NV_PAUSEFRAME_TX_REQ;
4754 if (np->autoneg && pause->autoneg) {
4755 np->pause_flags |= NV_PAUSEFRAME_AUTONEG;
4757 adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ);
4758 adv &= ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM);
4759 if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisments but disable tx pause */
4760 adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM;
4761 if (np->pause_flags & NV_PAUSEFRAME_TX_REQ)
4762 adv |= ADVERTISE_PAUSE_ASYM;
4763 mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv);
4765 if (netif_running(dev))
4766 printk(KERN_INFO "%s: link down.\n", dev->name);
4767 bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
4768 bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART);
4769 mii_rw(dev, np->phyaddr, MII_BMCR, bmcr);
4771 np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE);
4772 if (pause->rx_pause)
4773 np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE;
4774 if (pause->tx_pause)
4775 np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE;
4777 if (!netif_running(dev))
4778 nv_update_linkspeed(dev);
4780 nv_update_pause(dev, np->pause_flags);
4783 if (netif_running(dev)) {
4790 static u32 nv_get_rx_csum(struct net_device *dev)
4792 struct fe_priv *np = netdev_priv(dev);
4793 return (np->rx_csum) != 0;
4796 static int nv_set_rx_csum(struct net_device *dev, u32 data)
4798 struct fe_priv *np = netdev_priv(dev);
4799 u8 __iomem *base = get_hwbase(dev);
4802 if (np->driver_data & DEV_HAS_CHECKSUM) {
4805 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
4808 /* vlan is dependent on rx checksum offload */
4809 if (!(np->vlanctl_bits & NVREG_VLANCONTROL_ENABLE))
4810 np->txrxctl_bits &= ~NVREG_TXRXCTL_RXCHECK;
4812 if (netif_running(dev)) {
4813 spin_lock_irq(&np->lock);
4814 writel(np->txrxctl_bits, base + NvRegTxRxControl);
4815 spin_unlock_irq(&np->lock);
4824 static int nv_set_tx_csum(struct net_device *dev, u32 data)
4826 struct fe_priv *np = netdev_priv(dev);
4828 if (np->driver_data & DEV_HAS_CHECKSUM)
4829 return ethtool_op_set_tx_csum(dev, data);
4834 static int nv_set_sg(struct net_device *dev, u32 data)
4836 struct fe_priv *np = netdev_priv(dev);
4838 if (np->driver_data & DEV_HAS_CHECKSUM)
4839 return ethtool_op_set_sg(dev, data);
4844 static int nv_get_sset_count(struct net_device *dev, int sset)
4846 struct fe_priv *np = netdev_priv(dev);
4850 if (np->driver_data & DEV_HAS_TEST_EXTENDED)
4851 return NV_TEST_COUNT_EXTENDED;
4853 return NV_TEST_COUNT_BASE;
4855 if (np->driver_data & DEV_HAS_STATISTICS_V3)
4856 return NV_DEV_STATISTICS_V3_COUNT;
4857 else if (np->driver_data & DEV_HAS_STATISTICS_V2)
4858 return NV_DEV_STATISTICS_V2_COUNT;
4859 else if (np->driver_data & DEV_HAS_STATISTICS_V1)
4860 return NV_DEV_STATISTICS_V1_COUNT;
4868 static void nv_get_ethtool_stats(struct net_device *dev, struct ethtool_stats *estats, u64 *buffer)
4870 struct fe_priv *np = netdev_priv(dev);
4873 nv_do_stats_poll((unsigned long)dev);
4875 memcpy(buffer, &np->estats, nv_get_sset_count(dev, ETH_SS_STATS)*sizeof(u64));
4878 static int nv_link_test(struct net_device *dev)
4880 struct fe_priv *np = netdev_priv(dev);
4883 mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
4884 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
4886 /* check phy link status */
4887 if (!(mii_status & BMSR_LSTATUS))
4893 static int nv_register_test(struct net_device *dev)
4895 u8 __iomem *base = get_hwbase(dev);
4897 u32 orig_read, new_read;
4900 orig_read = readl(base + nv_registers_test[i].reg);
4902 /* xor with mask to toggle bits */
4903 orig_read ^= nv_registers_test[i].mask;
4905 writel(orig_read, base + nv_registers_test[i].reg);
4907 new_read = readl(base + nv_registers_test[i].reg);
4909 if ((new_read & nv_registers_test[i].mask) != (orig_read & nv_registers_test[i].mask))
4912 /* restore original value */
4913 orig_read ^= nv_registers_test[i].mask;
4914 writel(orig_read, base + nv_registers_test[i].reg);
4916 } while (nv_registers_test[++i].reg != 0);
4921 static int nv_interrupt_test(struct net_device *dev)
4923 struct fe_priv *np = netdev_priv(dev);
4924 u8 __iomem *base = get_hwbase(dev);
4927 u32 save_msi_flags, save_poll_interval = 0;
4929 if (netif_running(dev)) {
4930 /* free current irq */
4932 save_poll_interval = readl(base+NvRegPollingInterval);
4935 /* flag to test interrupt handler */
4938 /* setup test irq */
4939 save_msi_flags = np->msi_flags;
4940 np->msi_flags &= ~NV_MSI_X_VECTORS_MASK;
4941 np->msi_flags |= 0x001; /* setup 1 vector */
4942 if (nv_request_irq(dev, 1))
4945 /* setup timer interrupt */
4946 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
4947 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
4949 nv_enable_hw_interrupts(dev, NVREG_IRQ_TIMER);
4951 /* wait for at least one interrupt */
4954 spin_lock_irq(&np->lock);
4956 /* flag should be set within ISR */
4957 testcnt = np->intr_test;
4961 nv_disable_hw_interrupts(dev, NVREG_IRQ_TIMER);
4962 if (!(np->msi_flags & NV_MSI_X_ENABLED))
4963 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
4965 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
4967 spin_unlock_irq(&np->lock);
4971 np->msi_flags = save_msi_flags;
4973 if (netif_running(dev)) {
4974 writel(save_poll_interval, base + NvRegPollingInterval);
4975 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
4976 /* restore original irq */
4977 if (nv_request_irq(dev, 0))
4984 static int nv_loopback_test(struct net_device *dev)
4986 struct fe_priv *np = netdev_priv(dev);
4987 u8 __iomem *base = get_hwbase(dev);
4988 struct sk_buff *tx_skb, *rx_skb;
4989 dma_addr_t test_dma_addr;
4990 u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET);
4992 int len, i, pkt_len;
4994 u32 filter_flags = 0;
4995 u32 misc1_flags = 0;
4998 if (netif_running(dev)) {
4999 nv_disable_irq(dev);
5000 filter_flags = readl(base + NvRegPacketFilterFlags);
5001 misc1_flags = readl(base + NvRegMisc1);
5006 /* reinit driver view of the rx queue */
5010 /* setup hardware for loopback */
5011 writel(NVREG_MISC1_FORCE, base + NvRegMisc1);
5012 writel(NVREG_PFF_ALWAYS | NVREG_PFF_LOOPBACK, base + NvRegPacketFilterFlags);
5014 /* reinit nic view of the rx queue */
5015 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
5016 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
5017 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
5018 base + NvRegRingSizes);
5021 /* restart rx engine */
5024 /* setup packet for tx */
5025 pkt_len = ETH_DATA_LEN;
5026 tx_skb = dev_alloc_skb(pkt_len);
5028 printk(KERN_ERR "dev_alloc_skb() failed during loopback test"
5029 " of %s\n", dev->name);
5033 test_dma_addr = pci_map_single(np->pci_dev, tx_skb->data,
5034 skb_tailroom(tx_skb),
5035 PCI_DMA_FROMDEVICE);
5036 pkt_data = skb_put(tx_skb, pkt_len);
5037 for (i = 0; i < pkt_len; i++)
5038 pkt_data[i] = (u8)(i & 0xff);
5040 if (!nv_optimized(np)) {
5041 np->tx_ring.orig[0].buf = cpu_to_le32(test_dma_addr);
5042 np->tx_ring.orig[0].flaglen = cpu_to_le32((pkt_len-1) | np->tx_flags | tx_flags_extra);
5044 np->tx_ring.ex[0].bufhigh = cpu_to_le32(dma_high(test_dma_addr));
5045 np->tx_ring.ex[0].buflow = cpu_to_le32(dma_low(test_dma_addr));
5046 np->tx_ring.ex[0].flaglen = cpu_to_le32((pkt_len-1) | np->tx_flags | tx_flags_extra);
5048 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
5049 pci_push(get_hwbase(dev));
5053 /* check for rx of the packet */
5054 if (!nv_optimized(np)) {
5055 flags = le32_to_cpu(np->rx_ring.orig[0].flaglen);
5056 len = nv_descr_getlength(&np->rx_ring.orig[0], np->desc_ver);
5059 flags = le32_to_cpu(np->rx_ring.ex[0].flaglen);
5060 len = nv_descr_getlength_ex(&np->rx_ring.ex[0], np->desc_ver);
5063 if (flags & NV_RX_AVAIL) {
5065 } else if (np->desc_ver == DESC_VER_1) {
5066 if (flags & NV_RX_ERROR)
5069 if (flags & NV_RX2_ERROR) {
5075 if (len != pkt_len) {
5077 dprintk(KERN_DEBUG "%s: loopback len mismatch %d vs %d\n",
5078 dev->name, len, pkt_len);
5080 rx_skb = np->rx_skb[0].skb;
5081 for (i = 0; i < pkt_len; i++) {
5082 if (rx_skb->data[i] != (u8)(i & 0xff)) {
5084 dprintk(KERN_DEBUG "%s: loopback pattern check failed on byte %d\n",
5091 dprintk(KERN_DEBUG "%s: loopback - did not receive test packet\n", dev->name);
5094 pci_unmap_page(np->pci_dev, test_dma_addr,
5095 (skb_end_pointer(tx_skb) - tx_skb->data),
5097 dev_kfree_skb_any(tx_skb);
5102 /* drain rx queue */
5105 if (netif_running(dev)) {
5106 writel(misc1_flags, base + NvRegMisc1);
5107 writel(filter_flags, base + NvRegPacketFilterFlags);
5114 static void nv_self_test(struct net_device *dev, struct ethtool_test *test, u64 *buffer)
5116 struct fe_priv *np = netdev_priv(dev);
5117 u8 __iomem *base = get_hwbase(dev);
5119 memset(buffer, 0, nv_get_sset_count(dev, ETH_SS_TEST)*sizeof(u64));
5121 if (!nv_link_test(dev)) {
5122 test->flags |= ETH_TEST_FL_FAILED;
5126 if (test->flags & ETH_TEST_FL_OFFLINE) {
5127 if (netif_running(dev)) {
5128 netif_stop_queue(dev);
5129 nv_napi_disable(dev);
5130 netif_tx_lock_bh(dev);
5131 netif_addr_lock(dev);
5132 spin_lock_irq(&np->lock);
5133 nv_disable_hw_interrupts(dev, np->irqmask);
5134 if (!(np->msi_flags & NV_MSI_X_ENABLED)) {
5135 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
5137 writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus);
5142 /* drain rx queue */
5144 spin_unlock_irq(&np->lock);
5145 netif_addr_unlock(dev);
5146 netif_tx_unlock_bh(dev);
5149 if (!nv_register_test(dev)) {
5150 test->flags |= ETH_TEST_FL_FAILED;
5154 result = nv_interrupt_test(dev);
5156 test->flags |= ETH_TEST_FL_FAILED;
5164 if (!nv_loopback_test(dev)) {
5165 test->flags |= ETH_TEST_FL_FAILED;
5169 if (netif_running(dev)) {
5170 /* reinit driver view of the rx queue */
5172 if (nv_init_ring(dev)) {
5173 if (!np->in_shutdown)
5174 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
5176 /* reinit nic view of the rx queue */
5177 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
5178 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
5179 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
5180 base + NvRegRingSizes);
5182 writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
5184 /* restart rx engine */
5186 netif_start_queue(dev);
5187 nv_napi_enable(dev);
5188 nv_enable_hw_interrupts(dev, np->irqmask);
5193 static void nv_get_strings(struct net_device *dev, u32 stringset, u8 *buffer)
5195 switch (stringset) {
5197 memcpy(buffer, &nv_estats_str, nv_get_sset_count(dev, ETH_SS_STATS)*sizeof(struct nv_ethtool_str));
5200 memcpy(buffer, &nv_etests_str, nv_get_sset_count(dev, ETH_SS_TEST)*sizeof(struct nv_ethtool_str));
5205 static const struct ethtool_ops ops = {
5206 .get_drvinfo = nv_get_drvinfo,
5207 .get_link = ethtool_op_get_link,
5208 .get_wol = nv_get_wol,
5209 .set_wol = nv_set_wol,
5210 .get_settings = nv_get_settings,
5211 .set_settings = nv_set_settings,
5212 .get_regs_len = nv_get_regs_len,
5213 .get_regs = nv_get_regs,
5214 .nway_reset = nv_nway_reset,
5215 .set_tso = nv_set_tso,
5216 .get_ringparam = nv_get_ringparam,
5217 .set_ringparam = nv_set_ringparam,
5218 .get_pauseparam = nv_get_pauseparam,
5219 .set_pauseparam = nv_set_pauseparam,
5220 .get_rx_csum = nv_get_rx_csum,
5221 .set_rx_csum = nv_set_rx_csum,
5222 .set_tx_csum = nv_set_tx_csum,
5223 .set_sg = nv_set_sg,
5224 .get_strings = nv_get_strings,
5225 .get_ethtool_stats = nv_get_ethtool_stats,
5226 .get_sset_count = nv_get_sset_count,
5227 .self_test = nv_self_test,
5230 static void nv_vlan_rx_register(struct net_device *dev, struct vlan_group *grp)
5232 struct fe_priv *np = get_nvpriv(dev);
5234 spin_lock_irq(&np->lock);
5236 /* save vlan group */
5240 /* enable vlan on MAC */
5241 np->txrxctl_bits |= NVREG_TXRXCTL_VLANSTRIP | NVREG_TXRXCTL_VLANINS;
5243 /* disable vlan on MAC */
5244 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANSTRIP;
5245 np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANINS;
5248 writel(np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl);
5250 spin_unlock_irq(&np->lock);
5253 /* The mgmt unit and driver use a semaphore to access the phy during init */
5254 static int nv_mgmt_acquire_sema(struct net_device *dev)
5256 struct fe_priv *np = netdev_priv(dev);
5257 u8 __iomem *base = get_hwbase(dev);
5259 u32 tx_ctrl, mgmt_sema;
5261 for (i = 0; i < 10; i++) {
5262 mgmt_sema = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_SEMA_MASK;
5263 if (mgmt_sema == NVREG_XMITCTL_MGMT_SEMA_FREE)
5268 if (mgmt_sema != NVREG_XMITCTL_MGMT_SEMA_FREE)
5271 for (i = 0; i < 2; i++) {
5272 tx_ctrl = readl(base + NvRegTransmitterControl);
5273 tx_ctrl |= NVREG_XMITCTL_HOST_SEMA_ACQ;
5274 writel(tx_ctrl, base + NvRegTransmitterControl);
5276 /* verify that semaphore was acquired */
5277 tx_ctrl = readl(base + NvRegTransmitterControl);
5278 if (((tx_ctrl & NVREG_XMITCTL_HOST_SEMA_MASK) == NVREG_XMITCTL_HOST_SEMA_ACQ) &&
5279 ((tx_ctrl & NVREG_XMITCTL_MGMT_SEMA_MASK) == NVREG_XMITCTL_MGMT_SEMA_FREE)) {
5290 static void nv_mgmt_release_sema(struct net_device *dev)
5292 struct fe_priv *np = netdev_priv(dev);
5293 u8 __iomem *base = get_hwbase(dev);
5296 if (np->driver_data & DEV_HAS_MGMT_UNIT) {
5297 if (np->mgmt_sema) {
5298 tx_ctrl = readl(base + NvRegTransmitterControl);
5299 tx_ctrl &= ~NVREG_XMITCTL_HOST_SEMA_ACQ;
5300 writel(tx_ctrl, base + NvRegTransmitterControl);
5306 static int nv_mgmt_get_version(struct net_device *dev)
5308 struct fe_priv *np = netdev_priv(dev);
5309 u8 __iomem *base = get_hwbase(dev);
5310 u32 data_ready = readl(base + NvRegTransmitterControl);
5311 u32 data_ready2 = 0;
5312 unsigned long start;
5315 writel(NVREG_MGMTUNITGETVERSION, base + NvRegMgmtUnitGetVersion);
5316 writel(data_ready ^ NVREG_XMITCTL_DATA_START, base + NvRegTransmitterControl);
5318 while (time_before(jiffies, start + 5*HZ)) {
5319 data_ready2 = readl(base + NvRegTransmitterControl);
5320 if ((data_ready & NVREG_XMITCTL_DATA_READY) != (data_ready2 & NVREG_XMITCTL_DATA_READY)) {
5324 schedule_timeout_uninterruptible(1);
5327 if (!ready || (data_ready2 & NVREG_XMITCTL_DATA_ERROR))
5330 np->mgmt_version = readl(base + NvRegMgmtUnitVersion) & NVREG_MGMTUNITVERSION;
5335 static int nv_open(struct net_device *dev)
5337 struct fe_priv *np = netdev_priv(dev);
5338 u8 __iomem *base = get_hwbase(dev);
5343 dprintk(KERN_DEBUG "nv_open: begin\n");
5346 mii_rw(dev, np->phyaddr, MII_BMCR,
5347 mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ) & ~BMCR_PDOWN);
5349 nv_txrx_gate(dev, false);
5350 /* erase previous misconfiguration */
5351 if (np->driver_data & DEV_HAS_POWER_CNTRL)
5353 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
5354 writel(0, base + NvRegMulticastAddrB);
5355 writel(NVREG_MCASTMASKA_NONE, base + NvRegMulticastMaskA);
5356 writel(NVREG_MCASTMASKB_NONE, base + NvRegMulticastMaskB);
5357 writel(0, base + NvRegPacketFilterFlags);
5359 writel(0, base + NvRegTransmitterControl);
5360 writel(0, base + NvRegReceiverControl);
5362 writel(0, base + NvRegAdapterControl);
5364 if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)
5365 writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame);
5367 /* initialize descriptor rings */
5369 oom = nv_init_ring(dev);
5371 writel(0, base + NvRegLinkSpeed);
5372 writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
5374 writel(0, base + NvRegUnknownSetupReg6);
5376 np->in_shutdown = 0;
5379 setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING);
5380 writel( ((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT),
5381 base + NvRegRingSizes);
5383 writel(np->linkspeed, base + NvRegLinkSpeed);
5384 if (np->desc_ver == DESC_VER_1)
5385 writel(NVREG_TX_WM_DESC1_DEFAULT, base + NvRegTxWatermark);
5387 writel(NVREG_TX_WM_DESC2_3_DEFAULT, base + NvRegTxWatermark);
5388 writel(np->txrxctl_bits, base + NvRegTxRxControl);
5389 writel(np->vlanctl_bits, base + NvRegVlanControl);
5391 writel(NVREG_TXRXCTL_BIT1|np->txrxctl_bits, base + NvRegTxRxControl);
5392 reg_delay(dev, NvRegUnknownSetupReg5, NVREG_UNKSETUP5_BIT31, NVREG_UNKSETUP5_BIT31,
5393 NV_SETUP5_DELAY, NV_SETUP5_DELAYMAX,
5394 KERN_INFO "open: SetupReg5, Bit 31 remained off\n");
5396 writel(0, base + NvRegMIIMask);
5397 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
5398 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
5400 writel(NVREG_MISC1_FORCE | NVREG_MISC1_HD, base + NvRegMisc1);
5401 writel(readl(base + NvRegTransmitterStatus), base + NvRegTransmitterStatus);
5402 writel(NVREG_PFF_ALWAYS, base + NvRegPacketFilterFlags);
5403 writel(np->rx_buf_sz, base + NvRegOffloadConfig);
5405 writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus);
5407 get_random_bytes(&low, sizeof(low));
5408 low &= NVREG_SLOTTIME_MASK;
5409 if (np->desc_ver == DESC_VER_1) {
5410 writel(low|NVREG_SLOTTIME_DEFAULT, base + NvRegSlotTime);
5412 if (!(np->driver_data & DEV_HAS_GEAR_MODE)) {
5413 /* setup legacy backoff */
5414 writel(NVREG_SLOTTIME_LEGBF_ENABLED|NVREG_SLOTTIME_10_100_FULL|low, base + NvRegSlotTime);
5416 writel(NVREG_SLOTTIME_10_100_FULL, base + NvRegSlotTime);
5417 nv_gear_backoff_reseed(dev);
5420 writel(NVREG_TX_DEFERRAL_DEFAULT, base + NvRegTxDeferral);
5421 writel(NVREG_RX_DEFERRAL_DEFAULT, base + NvRegRxDeferral);
5422 if (poll_interval == -1) {
5423 if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT)
5424 writel(NVREG_POLL_DEFAULT_THROUGHPUT, base + NvRegPollingInterval);
5426 writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval);
5429 writel(poll_interval & 0xFFFF, base + NvRegPollingInterval);
5430 writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6);
5431 writel((np->phyaddr << NVREG_ADAPTCTL_PHYSHIFT)|NVREG_ADAPTCTL_PHYVALID|NVREG_ADAPTCTL_RUNNING,
5432 base + NvRegAdapterControl);
5433 writel(NVREG_MIISPEED_BIT8|NVREG_MIIDELAY, base + NvRegMIISpeed);
5434 writel(NVREG_MII_LINKCHANGE, base + NvRegMIIMask);
5436 writel(NVREG_WAKEUPFLAGS_ENABLE , base + NvRegWakeUpFlags);
5438 i = readl(base + NvRegPowerState);
5439 if ( (i & NVREG_POWERSTATE_POWEREDUP) == 0)
5440 writel(NVREG_POWERSTATE_POWEREDUP|i, base + NvRegPowerState);
5444 writel(readl(base + NvRegPowerState) | NVREG_POWERSTATE_VALID, base + NvRegPowerState);
5446 nv_disable_hw_interrupts(dev, np->irqmask);
5448 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
5449 writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus);
5452 if (nv_request_irq(dev, 0)) {
5456 /* ask for interrupts */
5457 nv_enable_hw_interrupts(dev, np->irqmask);
5459 spin_lock_irq(&np->lock);
5460 writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA);
5461 writel(0, base + NvRegMulticastAddrB);
5462 writel(NVREG_MCASTMASKA_NONE, base + NvRegMulticastMaskA);
5463 writel(NVREG_MCASTMASKB_NONE, base + NvRegMulticastMaskB);
5464 writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
5465 /* One manual link speed update: Interrupts are enabled, future link
5466 * speed changes cause interrupts and are handled by nv_link_irq().
5470 miistat = readl(base + NvRegMIIStatus);
5471 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
5472 dprintk(KERN_INFO "startup: got 0x%08x.\n", miistat);
5474 /* set linkspeed to invalid value, thus force nv_update_linkspeed
5477 ret = nv_update_linkspeed(dev);
5479 netif_start_queue(dev);
5480 nv_napi_enable(dev);
5483 netif_carrier_on(dev);
5485 printk(KERN_INFO "%s: no link during initialization.\n", dev->name);
5486 netif_carrier_off(dev);
5489 mod_timer(&np->oom_kick, jiffies + OOM_REFILL);
5491 /* start statistics timer */
5492 if (np->driver_data & (DEV_HAS_STATISTICS_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_STATISTICS_V3))
5493 mod_timer(&np->stats_poll,
5494 round_jiffies(jiffies + STATS_INTERVAL));
5496 spin_unlock_irq(&np->lock);
5504 static int nv_close(struct net_device *dev)
5506 struct fe_priv *np = netdev_priv(dev);
5509 spin_lock_irq(&np->lock);
5510 np->in_shutdown = 1;
5511 spin_unlock_irq(&np->lock);
5512 nv_napi_disable(dev);
5513 synchronize_irq(np->pci_dev->irq);
5515 del_timer_sync(&np->oom_kick);
5516 del_timer_sync(&np->nic_poll);
5517 del_timer_sync(&np->stats_poll);
5519 netif_stop_queue(dev);
5520 spin_lock_irq(&np->lock);
5524 /* disable interrupts on the nic or we will lock up */
5525 base = get_hwbase(dev);
5526 nv_disable_hw_interrupts(dev, np->irqmask);
5528 dprintk(KERN_INFO "%s: Irqmask is zero again\n", dev->name);
5530 spin_unlock_irq(&np->lock);
5536 if (np->wolenabled || !phy_power_down) {
5537 nv_txrx_gate(dev, false);
5538 writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags);
5541 /* power down phy */
5542 mii_rw(dev, np->phyaddr, MII_BMCR,
5543 mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ)|BMCR_PDOWN);
5544 nv_txrx_gate(dev, true);
5547 /* FIXME: power down nic */
5552 static const struct net_device_ops nv_netdev_ops = {
5553 .ndo_open = nv_open,
5554 .ndo_stop = nv_close,
5555 .ndo_get_stats = nv_get_stats,
5556 .ndo_start_xmit = nv_start_xmit,
5557 .ndo_tx_timeout = nv_tx_timeout,
5558 .ndo_change_mtu = nv_change_mtu,
5559 .ndo_validate_addr = eth_validate_addr,
5560 .ndo_set_mac_address = nv_set_mac_address,
5561 .ndo_set_multicast_list = nv_set_multicast,
5562 .ndo_vlan_rx_register = nv_vlan_rx_register,
5563 #ifdef CONFIG_NET_POLL_CONTROLLER
5564 .ndo_poll_controller = nv_poll_controller,
5568 static const struct net_device_ops nv_netdev_ops_optimized = {
5569 .ndo_open = nv_open,
5570 .ndo_stop = nv_close,
5571 .ndo_get_stats = nv_get_stats,
5572 .ndo_start_xmit = nv_start_xmit_optimized,
5573 .ndo_tx_timeout = nv_tx_timeout,
5574 .ndo_change_mtu = nv_change_mtu,
5575 .ndo_validate_addr = eth_validate_addr,
5576 .ndo_set_mac_address = nv_set_mac_address,
5577 .ndo_set_multicast_list = nv_set_multicast,
5578 .ndo_vlan_rx_register = nv_vlan_rx_register,
5579 #ifdef CONFIG_NET_POLL_CONTROLLER
5580 .ndo_poll_controller = nv_poll_controller,
5584 static int __devinit nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id)
5586 struct net_device *dev;
5591 u32 powerstate, txreg;
5592 u32 phystate_orig = 0, phystate;
5593 int phyinitialized = 0;
5594 static int printed_version;
5596 if (!printed_version++)
5597 printk(KERN_INFO "%s: Reverse Engineered nForce ethernet"
5598 " driver. Version %s.\n", DRV_NAME, FORCEDETH_VERSION);
5600 dev = alloc_etherdev(sizeof(struct fe_priv));
5605 np = netdev_priv(dev);
5607 np->pci_dev = pci_dev;
5608 spin_lock_init(&np->lock);
5609 SET_NETDEV_DEV(dev, &pci_dev->dev);
5611 init_timer(&np->oom_kick);
5612 np->oom_kick.data = (unsigned long) dev;
5613 np->oom_kick.function = &nv_do_rx_refill; /* timer handler */
5614 init_timer(&np->nic_poll);
5615 np->nic_poll.data = (unsigned long) dev;
5616 np->nic_poll.function = &nv_do_nic_poll; /* timer handler */
5617 init_timer(&np->stats_poll);
5618 np->stats_poll.data = (unsigned long) dev;
5619 np->stats_poll.function = &nv_do_stats_poll; /* timer handler */
5621 err = pci_enable_device(pci_dev);
5625 pci_set_master(pci_dev);
5627 err = pci_request_regions(pci_dev, DRV_NAME);
5631 if (id->driver_data & (DEV_HAS_VLAN|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS_V2|DEV_HAS_STATISTICS_V3))
5632 np->register_size = NV_PCI_REGSZ_VER3;
5633 else if (id->driver_data & DEV_HAS_STATISTICS_V1)
5634 np->register_size = NV_PCI_REGSZ_VER2;
5636 np->register_size = NV_PCI_REGSZ_VER1;
5640 for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) {
5641 dprintk(KERN_DEBUG "%s: resource %d start %p len %ld flags 0x%08lx.\n",
5642 pci_name(pci_dev), i, (void*)pci_resource_start(pci_dev, i),
5643 pci_resource_len(pci_dev, i),
5644 pci_resource_flags(pci_dev, i));
5645 if (pci_resource_flags(pci_dev, i) & IORESOURCE_MEM &&
5646 pci_resource_len(pci_dev, i) >= np->register_size) {
5647 addr = pci_resource_start(pci_dev, i);
5651 if (i == DEVICE_COUNT_RESOURCE) {
5652 dev_printk(KERN_INFO, &pci_dev->dev,
5653 "Couldn't find register window\n");
5657 /* copy of driver data */
5658 np->driver_data = id->driver_data;
5659 /* copy of device id */
5660 np->device_id = id->device;
5662 /* handle different descriptor versions */
5663 if (id->driver_data & DEV_HAS_HIGH_DMA) {
5664 /* packet format 3: supports 40-bit addressing */
5665 np->desc_ver = DESC_VER_3;
5666 np->txrxctl_bits = NVREG_TXRXCTL_DESC_3;
5668 if (pci_set_dma_mask(pci_dev, DMA_BIT_MASK(39)))
5669 dev_printk(KERN_INFO, &pci_dev->dev,
5670 "64-bit DMA failed, using 32-bit addressing\n");
5672 dev->features |= NETIF_F_HIGHDMA;
5673 if (pci_set_consistent_dma_mask(pci_dev, DMA_BIT_MASK(39))) {
5674 dev_printk(KERN_INFO, &pci_dev->dev,
5675 "64-bit DMA (consistent) failed, using 32-bit ring buffers\n");
5678 } else if (id->driver_data & DEV_HAS_LARGEDESC) {
5679 /* packet format 2: supports jumbo frames */
5680 np->desc_ver = DESC_VER_2;
5681 np->txrxctl_bits = NVREG_TXRXCTL_DESC_2;
5683 /* original packet format */
5684 np->desc_ver = DESC_VER_1;
5685 np->txrxctl_bits = NVREG_TXRXCTL_DESC_1;
5688 np->pkt_limit = NV_PKTLIMIT_1;
5689 if (id->driver_data & DEV_HAS_LARGEDESC)
5690 np->pkt_limit = NV_PKTLIMIT_2;
5692 if (id->driver_data & DEV_HAS_CHECKSUM) {
5694 np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK;
5695 dev->features |= NETIF_F_IP_CSUM | NETIF_F_SG;
5696 dev->features |= NETIF_F_TSO;
5699 np->vlanctl_bits = 0;
5700 if (id->driver_data & DEV_HAS_VLAN) {
5701 np->vlanctl_bits = NVREG_VLANCONTROL_ENABLE;
5702 dev->features |= NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX;
5705 np->pause_flags = NV_PAUSEFRAME_RX_CAPABLE | NV_PAUSEFRAME_RX_REQ | NV_PAUSEFRAME_AUTONEG;
5706 if ((id->driver_data & DEV_HAS_PAUSEFRAME_TX_V1) ||
5707 (id->driver_data & DEV_HAS_PAUSEFRAME_TX_V2) ||
5708 (id->driver_data & DEV_HAS_PAUSEFRAME_TX_V3)) {
5709 np->pause_flags |= NV_PAUSEFRAME_TX_CAPABLE | NV_PAUSEFRAME_TX_REQ;
5714 np->base = ioremap(addr, np->register_size);
5717 dev->base_addr = (unsigned long)np->base;
5719 dev->irq = pci_dev->irq;
5721 np->rx_ring_size = RX_RING_DEFAULT;
5722 np->tx_ring_size = TX_RING_DEFAULT;
5724 if (!nv_optimized(np)) {
5725 np->rx_ring.orig = pci_alloc_consistent(pci_dev,
5726 sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size),
5728 if (!np->rx_ring.orig)
5730 np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size];
5732 np->rx_ring.ex = pci_alloc_consistent(pci_dev,
5733 sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size),
5735 if (!np->rx_ring.ex)
5737 np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size];
5739 np->rx_skb = kcalloc(np->rx_ring_size, sizeof(struct nv_skb_map), GFP_KERNEL);
5740 np->tx_skb = kcalloc(np->tx_ring_size, sizeof(struct nv_skb_map), GFP_KERNEL);
5741 if (!np->rx_skb || !np->tx_skb)
5744 if (!nv_optimized(np))
5745 dev->netdev_ops = &nv_netdev_ops;
5747 dev->netdev_ops = &nv_netdev_ops_optimized;
5749 #ifdef CONFIG_FORCEDETH_NAPI
5750 netif_napi_add(dev, &np->napi, nv_napi_poll, RX_WORK_PER_LOOP);
5752 SET_ETHTOOL_OPS(dev, &ops);
5753 dev->watchdog_timeo = NV_WATCHDOG_TIMEO;
5755 pci_set_drvdata(pci_dev, dev);
5757 /* read the mac address */
5758 base = get_hwbase(dev);
5759 np->orig_mac[0] = readl(base + NvRegMacAddrA);
5760 np->orig_mac[1] = readl(base + NvRegMacAddrB);
5762 /* check the workaround bit for correct mac address order */
5763 txreg = readl(base + NvRegTransmitPoll);
5764 if (id->driver_data & DEV_HAS_CORRECT_MACADDR) {
5765 /* mac address is already in correct order */
5766 dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff;
5767 dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff;
5768 dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff;
5769 dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff;
5770 dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff;
5771 dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff;
5772 } else if (txreg & NVREG_TRANSMITPOLL_MAC_ADDR_REV) {
5773 /* mac address is already in correct order */
5774 dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff;
5775 dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff;
5776 dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff;
5777 dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff;
5778 dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff;
5779 dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff;
5781 * Set orig mac address back to the reversed version.
5782 * This flag will be cleared during low power transition.
5783 * Therefore, we should always put back the reversed address.
5785 np->orig_mac[0] = (dev->dev_addr[5] << 0) + (dev->dev_addr[4] << 8) +
5786 (dev->dev_addr[3] << 16) + (dev->dev_addr[2] << 24);
5787 np->orig_mac[1] = (dev->dev_addr[1] << 0) + (dev->dev_addr[0] << 8);
5789 /* need to reverse mac address to correct order */
5790 dev->dev_addr[0] = (np->orig_mac[1] >> 8) & 0xff;
5791 dev->dev_addr[1] = (np->orig_mac[1] >> 0) & 0xff;
5792 dev->dev_addr[2] = (np->orig_mac[0] >> 24) & 0xff;
5793 dev->dev_addr[3] = (np->orig_mac[0] >> 16) & 0xff;
5794 dev->dev_addr[4] = (np->orig_mac[0] >> 8) & 0xff;
5795 dev->dev_addr[5] = (np->orig_mac[0] >> 0) & 0xff;
5796 writel(txreg|NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll);
5797 printk(KERN_DEBUG "nv_probe: set workaround bit for reversed mac addr\n");
5799 memcpy(dev->perm_addr, dev->dev_addr, dev->addr_len);
5801 if (!is_valid_ether_addr(dev->perm_addr)) {
5803 * Bad mac address. At least one bios sets the mac address
5804 * to 01:23:45:67:89:ab
5806 dev_printk(KERN_ERR, &pci_dev->dev,
5807 "Invalid Mac address detected: %pM\n",
5809 dev_printk(KERN_ERR, &pci_dev->dev,
5810 "Please complain to your hardware vendor. Switching to a random MAC.\n");
5811 dev->dev_addr[0] = 0x00;
5812 dev->dev_addr[1] = 0x00;
5813 dev->dev_addr[2] = 0x6c;
5814 get_random_bytes(&dev->dev_addr[3], 3);
5817 dprintk(KERN_DEBUG "%s: MAC Address %pM\n",
5818 pci_name(pci_dev), dev->dev_addr);
5820 /* set mac address */
5821 nv_copy_mac_to_hw(dev);
5823 /* Workaround current PCI init glitch: wakeup bits aren't
5824 * being set from PCI PM capability.
5826 device_init_wakeup(&pci_dev->dev, 1);
5829 writel(0, base + NvRegWakeUpFlags);
5832 if (id->driver_data & DEV_HAS_POWER_CNTRL) {
5834 /* take phy and nic out of low power mode */
5835 powerstate = readl(base + NvRegPowerState2);
5836 powerstate &= ~NVREG_POWERSTATE2_POWERUP_MASK;
5837 if ((id->driver_data & DEV_NEED_LOW_POWER_FIX) &&
5838 pci_dev->revision >= 0xA3)
5839 powerstate |= NVREG_POWERSTATE2_POWERUP_REV_A3;
5840 writel(powerstate, base + NvRegPowerState2);
5843 if (np->desc_ver == DESC_VER_1) {
5844 np->tx_flags = NV_TX_VALID;
5846 np->tx_flags = NV_TX2_VALID;
5850 if ((id->driver_data & DEV_HAS_MSI) && msi) {
5851 np->msi_flags |= NV_MSI_CAPABLE;
5853 if ((id->driver_data & DEV_HAS_MSI_X) && msix) {
5854 /* msix has had reported issues when modifying irqmask
5855 as in the case of napi, therefore, disable for now
5857 #ifndef CONFIG_FORCEDETH_NAPI
5858 np->msi_flags |= NV_MSI_X_CAPABLE;
5862 if (optimization_mode == NV_OPTIMIZATION_MODE_CPU) {
5863 np->irqmask = NVREG_IRQMASK_CPU;
5864 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
5865 np->msi_flags |= 0x0001;
5866 } else if (optimization_mode == NV_OPTIMIZATION_MODE_DYNAMIC &&
5867 !(id->driver_data & DEV_NEED_TIMERIRQ)) {
5868 /* start off in throughput mode */
5869 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
5870 /* remove support for msix mode */
5871 np->msi_flags &= ~NV_MSI_X_CAPABLE;
5873 optimization_mode = NV_OPTIMIZATION_MODE_THROUGHPUT;
5874 np->irqmask = NVREG_IRQMASK_THROUGHPUT;
5875 if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */
5876 np->msi_flags |= 0x0003;
5879 if (id->driver_data & DEV_NEED_TIMERIRQ)
5880 np->irqmask |= NVREG_IRQ_TIMER;
5881 if (id->driver_data & DEV_NEED_LINKTIMER) {
5882 dprintk(KERN_INFO "%s: link timer on.\n", pci_name(pci_dev));
5883 np->need_linktimer = 1;
5884 np->link_timeout = jiffies + LINK_TIMEOUT;
5886 dprintk(KERN_INFO "%s: link timer off.\n", pci_name(pci_dev));
5887 np->need_linktimer = 0;
5890 /* Limit the number of tx's outstanding for hw bug */
5891 if (id->driver_data & DEV_NEED_TX_LIMIT) {
5893 if ((id->driver_data & DEV_NEED_TX_LIMIT2) &&
5894 pci_dev->revision >= 0xA2)
5898 /* clear phy state and temporarily halt phy interrupts */
5899 writel(0, base + NvRegMIIMask);
5900 phystate = readl(base + NvRegAdapterControl);
5901 if (phystate & NVREG_ADAPTCTL_RUNNING) {
5903 phystate &= ~NVREG_ADAPTCTL_RUNNING;
5904 writel(phystate, base + NvRegAdapterControl);
5906 writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus);
5908 if (id->driver_data & DEV_HAS_MGMT_UNIT) {
5909 /* management unit running on the mac? */
5910 if ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_ST) &&
5911 (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_PHY_INIT) &&
5912 nv_mgmt_acquire_sema(dev) &&
5913 nv_mgmt_get_version(dev)) {
5915 if (np->mgmt_version > 0) {
5916 np->mac_in_use = readl(base + NvRegMgmtUnitControl) & NVREG_MGMTUNITCONTROL_INUSE;
5918 dprintk(KERN_INFO "%s: mgmt unit is running. mac in use %x.\n",
5919 pci_name(pci_dev), np->mac_in_use);
5920 /* management unit setup the phy already? */
5921 if (np->mac_in_use &&
5922 ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK) ==
5923 NVREG_XMITCTL_SYNC_PHY_INIT)) {
5924 /* phy is inited by mgmt unit */
5926 dprintk(KERN_INFO "%s: Phy already initialized by mgmt unit.\n",
5929 /* we need to init the phy */
5934 /* find a suitable phy */
5935 for (i = 1; i <= 32; i++) {
5937 int phyaddr = i & 0x1F;
5939 spin_lock_irq(&np->lock);
5940 id1 = mii_rw(dev, phyaddr, MII_PHYSID1, MII_READ);
5941 spin_unlock_irq(&np->lock);
5942 if (id1 < 0 || id1 == 0xffff)
5944 spin_lock_irq(&np->lock);
5945 id2 = mii_rw(dev, phyaddr, MII_PHYSID2, MII_READ);
5946 spin_unlock_irq(&np->lock);
5947 if (id2 < 0 || id2 == 0xffff)
5950 np->phy_model = id2 & PHYID2_MODEL_MASK;
5951 id1 = (id1 & PHYID1_OUI_MASK) << PHYID1_OUI_SHFT;
5952 id2 = (id2 & PHYID2_OUI_MASK) >> PHYID2_OUI_SHFT;
5953 dprintk(KERN_DEBUG "%s: open: Found PHY %04x:%04x at address %d.\n",
5954 pci_name(pci_dev), id1, id2, phyaddr);
5955 np->phyaddr = phyaddr;
5956 np->phy_oui = id1 | id2;
5958 /* Realtek hardcoded phy id1 to all zero's on certain phys */
5959 if (np->phy_oui == PHY_OUI_REALTEK2)
5960 np->phy_oui = PHY_OUI_REALTEK;
5961 /* Setup phy revision for Realtek */
5962 if (np->phy_oui == PHY_OUI_REALTEK && np->phy_model == PHY_MODEL_REALTEK_8211)
5963 np->phy_rev = mii_rw(dev, phyaddr, MII_RESV1, MII_READ) & PHY_REV_MASK;
5968 dev_printk(KERN_INFO, &pci_dev->dev,
5969 "open: Could not find a valid PHY.\n");
5973 if (!phyinitialized) {
5977 /* see if it is a gigabit phy */
5978 u32 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ);
5979 if (mii_status & PHY_GIGABIT) {
5980 np->gigabit = PHY_GIGABIT;
5984 /* set default link speed settings */
5985 np->linkspeed = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10;
5989 err = register_netdev(dev);
5991 dev_printk(KERN_INFO, &pci_dev->dev,
5992 "unable to register netdev: %d\n", err);
5996 dev_printk(KERN_INFO, &pci_dev->dev, "ifname %s, PHY OUI 0x%x @ %d, "
5997 "addr %2.2x:%2.2x:%2.2x:%2.2x:%2.2x:%2.2x\n",
6008 dev_printk(KERN_INFO, &pci_dev->dev, "%s%s%s%s%s%s%s%s%s%sdesc-v%u\n",
6009 dev->features & NETIF_F_HIGHDMA ? "highdma " : "",
6010 dev->features & (NETIF_F_IP_CSUM | NETIF_F_SG) ?
6012 dev->features & (NETIF_F_HW_VLAN_RX | NETIF_F_HW_VLAN_TX) ?
6014 id->driver_data & DEV_HAS_POWER_CNTRL ? "pwrctl " : "",
6015 id->driver_data & DEV_HAS_MGMT_UNIT ? "mgmt " : "",
6016 id->driver_data & DEV_NEED_TIMERIRQ ? "timirq " : "",
6017 np->gigabit == PHY_GIGABIT ? "gbit " : "",
6018 np->need_linktimer ? "lnktim " : "",
6019 np->msi_flags & NV_MSI_CAPABLE ? "msi " : "",
6020 np->msi_flags & NV_MSI_X_CAPABLE ? "msi-x " : "",
6027 writel(phystate|NVREG_ADAPTCTL_RUNNING, base + NvRegAdapterControl);
6028 pci_set_drvdata(pci_dev, NULL);
6032 iounmap(get_hwbase(dev));
6034 pci_release_regions(pci_dev);
6036 pci_disable_device(pci_dev);
6043 static void nv_restore_phy(struct net_device *dev)
6045 struct fe_priv *np = netdev_priv(dev);
6046 u16 phy_reserved, mii_control;
6048 if (np->phy_oui == PHY_OUI_REALTEK &&
6049 np->phy_model == PHY_MODEL_REALTEK_8201 &&
6050 phy_cross == NV_CROSSOVER_DETECTION_DISABLED) {
6051 mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3);
6052 phy_reserved = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, MII_READ);
6053 phy_reserved &= ~PHY_REALTEK_INIT_MSK1;
6054 phy_reserved |= PHY_REALTEK_INIT8;
6055 mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, phy_reserved);
6056 mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1);
6058 /* restart auto negotiation */
6059 mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ);
6060 mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE);
6061 mii_rw(dev, np->phyaddr, MII_BMCR, mii_control);
6065 static void nv_restore_mac_addr(struct pci_dev *pci_dev)
6067 struct net_device *dev = pci_get_drvdata(pci_dev);
6068 struct fe_priv *np = netdev_priv(dev);
6069 u8 __iomem *base = get_hwbase(dev);
6071 /* special op: write back the misordered MAC address - otherwise
6072 * the next nv_probe would see a wrong address.
6074 writel(np->orig_mac[0], base + NvRegMacAddrA);
6075 writel(np->orig_mac[1], base + NvRegMacAddrB);
6076 writel(readl(base + NvRegTransmitPoll) & ~NVREG_TRANSMITPOLL_MAC_ADDR_REV,
6077 base + NvRegTransmitPoll);
6080 static void __devexit nv_remove(struct pci_dev *pci_dev)
6082 struct net_device *dev = pci_get_drvdata(pci_dev);
6084 unregister_netdev(dev);
6086 nv_restore_mac_addr(pci_dev);
6088 /* restore any phy related changes */
6089 nv_restore_phy(dev);
6091 nv_mgmt_release_sema(dev);
6093 /* free all structures */
6095 iounmap(get_hwbase(dev));
6096 pci_release_regions(pci_dev);
6097 pci_disable_device(pci_dev);
6099 pci_set_drvdata(pci_dev, NULL);
6103 static int nv_suspend(struct pci_dev *pdev, pm_message_t state)
6105 struct net_device *dev = pci_get_drvdata(pdev);
6106 struct fe_priv *np = netdev_priv(dev);
6107 u8 __iomem *base = get_hwbase(dev);
6110 if (netif_running(dev)) {
6114 netif_device_detach(dev);
6116 /* save non-pci configuration space */
6117 for (i = 0;i <= np->register_size/sizeof(u32); i++)
6118 np->saved_config_space[i] = readl(base + i*sizeof(u32));
6120 pci_save_state(pdev);
6121 pci_enable_wake(pdev, pci_choose_state(pdev, state), np->wolenabled);
6122 pci_disable_device(pdev);
6123 pci_set_power_state(pdev, pci_choose_state(pdev, state));
6127 static int nv_resume(struct pci_dev *pdev)
6129 struct net_device *dev = pci_get_drvdata(pdev);
6130 struct fe_priv *np = netdev_priv(dev);
6131 u8 __iomem *base = get_hwbase(dev);
6134 pci_set_power_state(pdev, PCI_D0);
6135 pci_restore_state(pdev);
6136 /* ack any pending wake events, disable PME */
6137 pci_enable_wake(pdev, PCI_D0, 0);
6139 /* restore non-pci configuration space */
6140 for (i = 0;i <= np->register_size/sizeof(u32); i++)
6141 writel(np->saved_config_space[i], base+i*sizeof(u32));
6143 if (np->driver_data & DEV_NEED_MSI_FIX)
6144 pci_write_config_dword(pdev, NV_MSI_PRIV_OFFSET, NV_MSI_PRIV_VALUE);
6146 /* restore phy state, including autoneg */
6149 netif_device_attach(dev);
6150 if (netif_running(dev)) {
6152 nv_set_multicast(dev);
6157 static void nv_shutdown(struct pci_dev *pdev)
6159 struct net_device *dev = pci_get_drvdata(pdev);
6160 struct fe_priv *np = netdev_priv(dev);
6162 if (netif_running(dev))
6166 * Restore the MAC so a kernel started by kexec won't get confused.
6167 * If we really go for poweroff, we must not restore the MAC,
6168 * otherwise the MAC for WOL will be reversed at least on some boards.
6170 if (system_state != SYSTEM_POWER_OFF) {
6171 nv_restore_mac_addr(pdev);
6174 pci_disable_device(pdev);
6176 * Apparently it is not possible to reinitialise from D3 hot,
6177 * only put the device into D3 if we really go for poweroff.
6179 if (system_state == SYSTEM_POWER_OFF) {
6180 if (pci_enable_wake(pdev, PCI_D3cold, np->wolenabled))
6181 pci_enable_wake(pdev, PCI_D3hot, np->wolenabled);
6182 pci_set_power_state(pdev, PCI_D3hot);
6186 #define nv_suspend NULL
6187 #define nv_shutdown NULL
6188 #define nv_resume NULL
6189 #endif /* CONFIG_PM */
6191 static struct pci_device_id pci_tbl[] = {
6192 { /* nForce Ethernet Controller */
6193 PCI_DEVICE(0x10DE, 0x01C3),
6194 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
6196 { /* nForce2 Ethernet Controller */
6197 PCI_DEVICE(0x10DE, 0x0066),
6198 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
6200 { /* nForce3 Ethernet Controller */
6201 PCI_DEVICE(0x10DE, 0x00D6),
6202 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER,
6204 { /* nForce3 Ethernet Controller */
6205 PCI_DEVICE(0x10DE, 0x0086),
6206 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
6208 { /* nForce3 Ethernet Controller */
6209 PCI_DEVICE(0x10DE, 0x008C),
6210 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
6212 { /* nForce3 Ethernet Controller */
6213 PCI_DEVICE(0x10DE, 0x00E6),
6214 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
6216 { /* nForce3 Ethernet Controller */
6217 PCI_DEVICE(0x10DE, 0x00DF),
6218 .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM,
6220 { /* CK804 Ethernet Controller */
6221 PCI_DEVICE(0x10DE, 0x0056),
6222 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT,
6224 { /* CK804 Ethernet Controller */
6225 PCI_DEVICE(0x10DE, 0x0057),
6226 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT,
6228 { /* MCP04 Ethernet Controller */
6229 PCI_DEVICE(0x10DE, 0x0037),
6230 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT,
6232 { /* MCP04 Ethernet Controller */
6233 PCI_DEVICE(0x10DE, 0x0038),
6234 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT,
6236 { /* MCP51 Ethernet Controller */
6237 PCI_DEVICE(0x10DE, 0x0268),
6238 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS_V1|DEV_NEED_LOW_POWER_FIX,
6240 { /* MCP51 Ethernet Controller */
6241 PCI_DEVICE(0x10DE, 0x0269),
6242 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS_V1|DEV_NEED_LOW_POWER_FIX,
6244 { /* MCP55 Ethernet Controller */
6245 PCI_DEVICE(0x10DE, 0x0372),
6246 .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_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_NEED_TX_LIMIT|DEV_NEED_MSI_FIX,
6248 { /* MCP55 Ethernet Controller */
6249 PCI_DEVICE(0x10DE, 0x0373),
6250 .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_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_NEED_TX_LIMIT|DEV_NEED_MSI_FIX,
6252 { /* MCP61 Ethernet Controller */
6253 PCI_DEVICE(0x10DE, 0x03E5),
6254 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_MSI_FIX,
6256 { /* MCP61 Ethernet Controller */
6257 PCI_DEVICE(0x10DE, 0x03E6),
6258 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_MSI_FIX,
6260 { /* MCP61 Ethernet Controller */
6261 PCI_DEVICE(0x10DE, 0x03EE),
6262 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_MSI_FIX,
6264 { /* MCP61 Ethernet Controller */
6265 PCI_DEVICE(0x10DE, 0x03EF),
6266 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_MSI_FIX,
6268 { /* MCP65 Ethernet Controller */
6269 PCI_DEVICE(0x10DE, 0x0450),
6270 .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_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
6272 { /* MCP65 Ethernet Controller */
6273 PCI_DEVICE(0x10DE, 0x0451),
6274 .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_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
6276 { /* MCP65 Ethernet Controller */
6277 PCI_DEVICE(0x10DE, 0x0452),
6278 .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_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
6280 { /* MCP65 Ethernet Controller */
6281 PCI_DEVICE(0x10DE, 0x0453),
6282 .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_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
6284 { /* MCP67 Ethernet Controller */
6285 PCI_DEVICE(0x10DE, 0x054C),
6286 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
6288 { /* MCP67 Ethernet Controller */
6289 PCI_DEVICE(0x10DE, 0x054D),
6290 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
6292 { /* MCP67 Ethernet Controller */
6293 PCI_DEVICE(0x10DE, 0x054E),
6294 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
6296 { /* MCP67 Ethernet Controller */
6297 PCI_DEVICE(0x10DE, 0x054F),
6298 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
6300 { /* MCP73 Ethernet Controller */
6301 PCI_DEVICE(0x10DE, 0x07DC),
6302 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
6304 { /* MCP73 Ethernet Controller */
6305 PCI_DEVICE(0x10DE, 0x07DD),
6306 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
6308 { /* MCP73 Ethernet Controller */
6309 PCI_DEVICE(0x10DE, 0x07DE),
6310 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
6312 { /* MCP73 Ethernet Controller */
6313 PCI_DEVICE(0x10DE, 0x07DF),
6314 .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX,
6316 { /* MCP77 Ethernet Controller */
6317 PCI_DEVICE(0x10DE, 0x0760),
6318 .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_V3|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,
6320 { /* MCP77 Ethernet Controller */
6321 PCI_DEVICE(0x10DE, 0x0761),
6322 .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_V3|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,
6324 { /* MCP77 Ethernet Controller */
6325 PCI_DEVICE(0x10DE, 0x0762),
6326 .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_V3|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,
6328 { /* MCP77 Ethernet Controller */
6329 PCI_DEVICE(0x10DE, 0x0763),
6330 .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_V3|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,
6332 { /* MCP79 Ethernet Controller */
6333 PCI_DEVICE(0x10DE, 0x0AB0),
6334 .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_V3|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,
6336 { /* MCP79 Ethernet Controller */
6337 PCI_DEVICE(0x10DE, 0x0AB1),
6338 .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_V3|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,
6340 { /* MCP79 Ethernet Controller */
6341 PCI_DEVICE(0x10DE, 0x0AB2),
6342 .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_V3|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,
6344 { /* MCP79 Ethernet Controller */
6345 PCI_DEVICE(0x10DE, 0x0AB3),
6346 .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_V3|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,
6348 { /* MCP89 Ethernet Controller */
6349 PCI_DEVICE(0x10DE, 0x0D7D),
6350 .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_V3|DEV_HAS_TEST_EXTENDED|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX,
6355 static struct pci_driver driver = {
6357 .id_table = pci_tbl,
6359 .remove = __devexit_p(nv_remove),
6360 .suspend = nv_suspend,
6361 .resume = nv_resume,
6362 .shutdown = nv_shutdown,
6365 static int __init init_nic(void)
6367 return pci_register_driver(&driver);
6370 static void __exit exit_nic(void)
6372 pci_unregister_driver(&driver);
6375 module_param(max_interrupt_work, int, 0);
6376 MODULE_PARM_DESC(max_interrupt_work, "forcedeth maximum events handled per interrupt");
6377 module_param(optimization_mode, int, 0);
6378 MODULE_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.");
6379 module_param(poll_interval, int, 0);
6380 MODULE_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.");
6381 module_param(msi, int, 0);
6382 MODULE_PARM_DESC(msi, "MSI interrupts are enabled by setting to 1 and disabled by setting to 0.");
6383 module_param(msix, int, 0);
6384 MODULE_PARM_DESC(msix, "MSIX interrupts are enabled by setting to 1 and disabled by setting to 0.");
6385 module_param(dma_64bit, int, 0);
6386 MODULE_PARM_DESC(dma_64bit, "High DMA is enabled by setting to 1 and disabled by setting to 0.");
6387 module_param(phy_cross, int, 0);
6388 MODULE_PARM_DESC(phy_cross, "Phy crossover detection for Realtek 8201 phy is enabled by setting to 1 and disabled by setting to 0.");
6389 module_param(phy_power_down, int, 0);
6390 MODULE_PARM_DESC(phy_power_down, "Power down phy and disable link when interface is down (1), or leave phy powered up (0).");
6392 MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>");
6393 MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver");
6394 MODULE_LICENSE("GPL");
6396 MODULE_DEVICE_TABLE(pci, pci_tbl);
6398 module_init(init_nic);
6399 module_exit(exit_nic);