Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * forcedeth: Ethernet driver for NVIDIA nForce media access controllers. |
| 3 | * |
| 4 | * Note: This driver is a cleanroom reimplementation based on reverse |
| 5 | * engineered documentation written by Carl-Daniel Hailfinger |
Ayaz Abdulla | 87046e5 | 2006-12-19 23:33:32 -0500 | [diff] [blame] | 6 | * and Andrew de Quincey. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
| 8 | * NVIDIA, nForce and other NVIDIA marks are trademarks or registered |
| 9 | * trademarks of NVIDIA Corporation in the United States and other |
| 10 | * countries. |
| 11 | * |
Manfred Spraul | 1836098 | 2005-12-24 14:19:24 +0100 | [diff] [blame] | 12 | * Copyright (C) 2003,4,5 Manfred Spraul |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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) |
Ayaz Abdulla | f1405d32 | 2009-01-09 11:03:54 +0000 | [diff] [blame] | 16 | * Copyright (c) 2004,2005,2006,2007,2008,2009 NVIDIA Corporation |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | * |
| 18 | * This program is free software; you can redistribute it and/or modify |
| 19 | * it under the terms of the GNU General Public License as published by |
| 20 | * the Free Software Foundation; either version 2 of the License, or |
| 21 | * (at your option) any later version. |
| 22 | * |
| 23 | * This program is distributed in the hope that it will be useful, |
| 24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 26 | * GNU General Public License for more details. |
| 27 | * |
| 28 | * You should have received a copy of the GNU General Public License |
Jeff Kirsher | 0ab75ae | 2013-12-06 06:28:43 -0800 | [diff] [blame^] | 29 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | * Known bugs: |
| 32 | * We suspect that on some hardware no TX done interrupts are generated. |
| 33 | * This means recovery from netif_stop_queue only happens if the hw timer |
| 34 | * interrupt fires (100 times/second, configurable with NVREG_POLL_DEFAULT) |
| 35 | * and the timer is active in the IRQMask, or if a rx packet arrives by chance. |
| 36 | * If your hardware reliably generates tx done interrupts, then you can remove |
| 37 | * DEV_NEED_TIMERIRQ from the driver_data flags. |
| 38 | * DEV_NEED_TIMERIRQ will not harm you on sane hardware, only generating a few |
| 39 | * superfluous timer interrupts from the nic. |
| 40 | */ |
Joe Perches | 294a554 | 2010-11-29 07:41:56 +0000 | [diff] [blame] | 41 | |
| 42 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 43 | |
Ayaz Abdulla | 3e1a3ce | 2009-03-05 08:02:38 +0000 | [diff] [blame] | 44 | #define FORCEDETH_VERSION "0.64" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #define DRV_NAME "forcedeth" |
| 46 | |
| 47 | #include <linux/module.h> |
| 48 | #include <linux/types.h> |
| 49 | #include <linux/pci.h> |
| 50 | #include <linux/interrupt.h> |
| 51 | #include <linux/netdevice.h> |
| 52 | #include <linux/etherdevice.h> |
| 53 | #include <linux/delay.h> |
Alexey Dobriyan | d43c36d | 2009-10-07 17:09:06 +0400 | [diff] [blame] | 54 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | #include <linux/spinlock.h> |
| 56 | #include <linux/ethtool.h> |
| 57 | #include <linux/timer.h> |
| 58 | #include <linux/skbuff.h> |
| 59 | #include <linux/mii.h> |
| 60 | #include <linux/random.h> |
| 61 | #include <linux/init.h> |
Manfred Spraul | 22c6d14 | 2005-04-19 21:17:09 +0200 | [diff] [blame] | 62 | #include <linux/if_vlan.h> |
Matthias Gehre | 910638a | 2006-03-28 01:56:48 -0800 | [diff] [blame] | 63 | #include <linux/dma-mapping.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 64 | #include <linux/slab.h> |
Szymon Janc | 5504e13 | 2010-11-27 08:39:45 +0000 | [diff] [blame] | 65 | #include <linux/uaccess.h> |
Paul Gortmaker | 70c7160 | 2011-05-22 16:47:17 -0400 | [diff] [blame] | 66 | #include <linux/prefetch.h> |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 67 | #include <linux/u64_stats_sync.h> |
| 68 | #include <linux/io.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | |
| 70 | #include <asm/irq.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 72 | #define TX_WORK_PER_LOOP 64 |
| 73 | #define RX_WORK_PER_LOOP 64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
| 75 | /* |
| 76 | * Hardware access: |
| 77 | */ |
| 78 | |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 79 | #define DEV_NEED_TIMERIRQ 0x0000001 /* set the timer irq flag in the irq mask */ |
| 80 | #define DEV_NEED_LINKTIMER 0x0000002 /* poll link settings. Relies on the timer irq */ |
| 81 | #define DEV_HAS_LARGEDESC 0x0000004 /* device supports jumbo frames and needs packet format 2 */ |
| 82 | #define DEV_HAS_HIGH_DMA 0x0000008 /* device supports 64bit dma */ |
| 83 | #define DEV_HAS_CHECKSUM 0x0000010 /* device supports tx and rx checksum offloads */ |
| 84 | #define DEV_HAS_VLAN 0x0000020 /* device supports vlan tagging and striping */ |
| 85 | #define DEV_HAS_MSI 0x0000040 /* device supports MSI */ |
| 86 | #define DEV_HAS_MSI_X 0x0000080 /* device supports MSI-X */ |
| 87 | #define DEV_HAS_POWER_CNTRL 0x0000100 /* device supports power savings */ |
| 88 | #define DEV_HAS_STATISTICS_V1 0x0000200 /* device supports hw statistics version 1 */ |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 89 | #define DEV_HAS_STATISTICS_V2 0x0000400 /* device supports hw statistics version 2 */ |
| 90 | #define DEV_HAS_STATISTICS_V3 0x0000800 /* device supports hw statistics version 3 */ |
| 91 | #define DEV_HAS_STATISTICS_V12 0x0000600 /* device supports hw statistics version 1 and 2 */ |
| 92 | #define DEV_HAS_STATISTICS_V123 0x0000e00 /* device supports hw statistics version 1, 2, and 3 */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 93 | #define DEV_HAS_TEST_EXTENDED 0x0001000 /* device supports extended diagnostic test */ |
| 94 | #define DEV_HAS_MGMT_UNIT 0x0002000 /* device supports management unit */ |
| 95 | #define DEV_HAS_CORRECT_MACADDR 0x0004000 /* device supports correct mac address order */ |
| 96 | #define DEV_HAS_COLLISION_FIX 0x0008000 /* device supports tx collision fix */ |
| 97 | #define DEV_HAS_PAUSEFRAME_TX_V1 0x0010000 /* device supports tx pause frames version 1 */ |
| 98 | #define DEV_HAS_PAUSEFRAME_TX_V2 0x0020000 /* device supports tx pause frames version 2 */ |
| 99 | #define DEV_HAS_PAUSEFRAME_TX_V3 0x0040000 /* device supports tx pause frames version 3 */ |
| 100 | #define DEV_NEED_TX_LIMIT 0x0080000 /* device needs to limit tx */ |
| 101 | #define DEV_NEED_TX_LIMIT2 0x0180000 /* device needs to limit tx, expect for some revs */ |
| 102 | #define DEV_HAS_GEAR_MODE 0x0200000 /* device supports gear mode */ |
| 103 | #define DEV_NEED_PHY_INIT_FIX 0x0400000 /* device needs specific phy workaround */ |
| 104 | #define DEV_NEED_LOW_POWER_FIX 0x0800000 /* device needs special power up workaround */ |
| 105 | #define DEV_NEED_MSI_FIX 0x1000000 /* device needs msi workaround */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | enum { |
| 108 | NvRegIrqStatus = 0x000, |
| 109 | #define NVREG_IRQSTAT_MIIEVENT 0x040 |
Ayaz Abdulla | daa91a9 | 2009-02-07 00:25:00 -0800 | [diff] [blame] | 110 | #define NVREG_IRQSTAT_MASK 0x83ff |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | NvRegIrqMask = 0x004, |
| 112 | #define NVREG_IRQ_RX_ERROR 0x0001 |
| 113 | #define NVREG_IRQ_RX 0x0002 |
| 114 | #define NVREG_IRQ_RX_NOBUF 0x0004 |
| 115 | #define NVREG_IRQ_TX_ERR 0x0008 |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 116 | #define NVREG_IRQ_TX_OK 0x0010 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | #define NVREG_IRQ_TIMER 0x0020 |
| 118 | #define NVREG_IRQ_LINK 0x0040 |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 119 | #define NVREG_IRQ_RX_FORCED 0x0080 |
| 120 | #define NVREG_IRQ_TX_FORCED 0x0100 |
Ayaz Abdulla | daa91a9 | 2009-02-07 00:25:00 -0800 | [diff] [blame] | 121 | #define NVREG_IRQ_RECOVER_ERROR 0x8200 |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 122 | #define NVREG_IRQMASK_THROUGHPUT 0x00df |
Ayaz Abdulla | 096a458 | 2007-05-21 20:23:11 -0400 | [diff] [blame] | 123 | #define NVREG_IRQMASK_CPU 0x0060 |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 124 | #define NVREG_IRQ_TX_ALL (NVREG_IRQ_TX_ERR|NVREG_IRQ_TX_OK|NVREG_IRQ_TX_FORCED) |
| 125 | #define NVREG_IRQ_RX_ALL (NVREG_IRQ_RX_ERROR|NVREG_IRQ_RX|NVREG_IRQ_RX_NOBUF|NVREG_IRQ_RX_FORCED) |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 126 | #define NVREG_IRQ_OTHER (NVREG_IRQ_TIMER|NVREG_IRQ_LINK|NVREG_IRQ_RECOVER_ERROR) |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 127 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | NvRegUnknownSetupReg6 = 0x008, |
| 129 | #define NVREG_UNKSETUP6_VAL 3 |
| 130 | |
| 131 | /* |
| 132 | * NVREG_POLL_DEFAULT is the interval length of the timer source on the nic |
| 133 | * NVREG_POLL_DEFAULT=97 would result in an interval length of 1 ms |
| 134 | */ |
| 135 | NvRegPollingInterval = 0x00c, |
Ayaz Abdulla | 6cef67a | 2009-03-05 08:02:30 +0000 | [diff] [blame] | 136 | #define NVREG_POLL_DEFAULT_THROUGHPUT 65535 /* backup tx cleanup if loop max reached */ |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 137 | #define NVREG_POLL_DEFAULT_CPU 13 |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 138 | NvRegMSIMap0 = 0x020, |
| 139 | NvRegMSIMap1 = 0x024, |
| 140 | NvRegMSIIrqMask = 0x030, |
| 141 | #define NVREG_MSI_VECTOR_0_ENABLED 0x01 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | NvRegMisc1 = 0x080, |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 143 | #define NVREG_MISC1_PAUSE_TX 0x01 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | #define NVREG_MISC1_HD 0x02 |
| 145 | #define NVREG_MISC1_FORCE 0x3b0f3c |
| 146 | |
Ayaz Abdulla | 0a62677 | 2008-01-13 16:02:42 -0500 | [diff] [blame] | 147 | NvRegMacReset = 0x34, |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 148 | #define NVREG_MAC_RESET_ASSERT 0x0F3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | NvRegTransmitterControl = 0x084, |
| 150 | #define NVREG_XMITCTL_START 0x01 |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 151 | #define NVREG_XMITCTL_MGMT_ST 0x40000000 |
| 152 | #define NVREG_XMITCTL_SYNC_MASK 0x000f0000 |
| 153 | #define NVREG_XMITCTL_SYNC_NOT_READY 0x0 |
| 154 | #define NVREG_XMITCTL_SYNC_PHY_INIT 0x00040000 |
| 155 | #define NVREG_XMITCTL_MGMT_SEMA_MASK 0x00000f00 |
| 156 | #define NVREG_XMITCTL_MGMT_SEMA_FREE 0x0 |
| 157 | #define NVREG_XMITCTL_HOST_SEMA_MASK 0x0000f000 |
| 158 | #define NVREG_XMITCTL_HOST_SEMA_ACQ 0x0000f000 |
| 159 | #define NVREG_XMITCTL_HOST_LOADED 0x00004000 |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 160 | #define NVREG_XMITCTL_TX_PATH_EN 0x01000000 |
Ayaz Abdulla | cac1c52 | 2009-02-07 00:23:57 -0800 | [diff] [blame] | 161 | #define NVREG_XMITCTL_DATA_START 0x00100000 |
| 162 | #define NVREG_XMITCTL_DATA_READY 0x00010000 |
| 163 | #define NVREG_XMITCTL_DATA_ERROR 0x00020000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | NvRegTransmitterStatus = 0x088, |
| 165 | #define NVREG_XMITSTAT_BUSY 0x01 |
| 166 | |
| 167 | NvRegPacketFilterFlags = 0x8c, |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 168 | #define NVREG_PFF_PAUSE_RX 0x08 |
| 169 | #define NVREG_PFF_ALWAYS 0x7F0000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 170 | #define NVREG_PFF_PROMISC 0x80 |
| 171 | #define NVREG_PFF_MYADDR 0x20 |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 172 | #define NVREG_PFF_LOOPBACK 0x10 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 173 | |
| 174 | NvRegOffloadConfig = 0x90, |
| 175 | #define NVREG_OFFLOAD_HOMEPHY 0x601 |
| 176 | #define NVREG_OFFLOAD_NORMAL RX_NIC_BUFSIZE |
| 177 | NvRegReceiverControl = 0x094, |
| 178 | #define NVREG_RCVCTL_START 0x01 |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 179 | #define NVREG_RCVCTL_RX_PATH_EN 0x01000000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 180 | NvRegReceiverStatus = 0x98, |
| 181 | #define NVREG_RCVSTAT_BUSY 0x01 |
| 182 | |
Ayaz Abdulla | a433686 | 2008-04-18 13:50:43 -0700 | [diff] [blame] | 183 | NvRegSlotTime = 0x9c, |
| 184 | #define NVREG_SLOTTIME_LEGBF_ENABLED 0x80000000 |
| 185 | #define NVREG_SLOTTIME_10_100_FULL 0x00007f00 |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 186 | #define NVREG_SLOTTIME_1000_FULL 0x0003ff00 |
Ayaz Abdulla | a433686 | 2008-04-18 13:50:43 -0700 | [diff] [blame] | 187 | #define NVREG_SLOTTIME_HALF 0x0000ff00 |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 188 | #define NVREG_SLOTTIME_DEFAULT 0x00007f00 |
Ayaz Abdulla | a433686 | 2008-04-18 13:50:43 -0700 | [diff] [blame] | 189 | #define NVREG_SLOTTIME_MASK 0x000000ff |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
Ayaz Abdulla | 9744e21 | 2006-07-06 16:45:58 -0400 | [diff] [blame] | 191 | NvRegTxDeferral = 0xA0, |
Ayaz Abdulla | fd9b558 | 2008-02-05 12:29:49 -0500 | [diff] [blame] | 192 | #define NVREG_TX_DEFERRAL_DEFAULT 0x15050f |
| 193 | #define NVREG_TX_DEFERRAL_RGMII_10_100 0x16070f |
| 194 | #define NVREG_TX_DEFERRAL_RGMII_1000 0x14050f |
| 195 | #define NVREG_TX_DEFERRAL_RGMII_STRETCH_10 0x16190f |
| 196 | #define NVREG_TX_DEFERRAL_RGMII_STRETCH_100 0x16300f |
| 197 | #define NVREG_TX_DEFERRAL_MII_STRETCH 0x152000 |
Ayaz Abdulla | 9744e21 | 2006-07-06 16:45:58 -0400 | [diff] [blame] | 198 | NvRegRxDeferral = 0xA4, |
| 199 | #define NVREG_RX_DEFERRAL_DEFAULT 0x16 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | NvRegMacAddrA = 0xA8, |
| 201 | NvRegMacAddrB = 0xAC, |
| 202 | NvRegMulticastAddrA = 0xB0, |
| 203 | #define NVREG_MCASTADDRA_FORCE 0x01 |
| 204 | NvRegMulticastAddrB = 0xB4, |
| 205 | NvRegMulticastMaskA = 0xB8, |
Ayaz Abdulla | bb9a4fd | 2008-01-13 16:03:04 -0500 | [diff] [blame] | 206 | #define NVREG_MCASTMASKA_NONE 0xffffffff |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | NvRegMulticastMaskB = 0xBC, |
Ayaz Abdulla | bb9a4fd | 2008-01-13 16:03:04 -0500 | [diff] [blame] | 208 | #define NVREG_MCASTMASKB_NONE 0xffff |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
| 210 | NvRegPhyInterface = 0xC0, |
| 211 | #define PHY_RGMII 0x10000000 |
Ayaz Abdulla | a433686 | 2008-04-18 13:50:43 -0700 | [diff] [blame] | 212 | NvRegBackOffControl = 0xC4, |
| 213 | #define NVREG_BKOFFCTRL_DEFAULT 0x70000000 |
| 214 | #define NVREG_BKOFFCTRL_SEED_MASK 0x000003ff |
| 215 | #define NVREG_BKOFFCTRL_SELECT 24 |
| 216 | #define NVREG_BKOFFCTRL_GEAR 12 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | |
| 218 | NvRegTxRingPhysAddr = 0x100, |
| 219 | NvRegRxRingPhysAddr = 0x104, |
| 220 | NvRegRingSizes = 0x108, |
| 221 | #define NVREG_RINGSZ_TXSHIFT 0 |
| 222 | #define NVREG_RINGSZ_RXSHIFT 16 |
Ayaz Abdulla | 5070d34 | 2006-07-31 12:05:01 -0400 | [diff] [blame] | 223 | NvRegTransmitPoll = 0x10c, |
| 224 | #define NVREG_TRANSMITPOLL_MAC_ADDR_REV 0x00008000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | NvRegLinkSpeed = 0x110, |
| 226 | #define NVREG_LINKSPEED_FORCE 0x10000 |
| 227 | #define NVREG_LINKSPEED_10 1000 |
| 228 | #define NVREG_LINKSPEED_100 100 |
| 229 | #define NVREG_LINKSPEED_1000 50 |
| 230 | #define NVREG_LINKSPEED_MASK (0xFFF) |
| 231 | NvRegUnknownSetupReg5 = 0x130, |
| 232 | #define NVREG_UNKSETUP5_BIT31 (1<<31) |
Ayaz Abdulla | 95d161c | 2006-07-06 16:46:25 -0400 | [diff] [blame] | 233 | NvRegTxWatermark = 0x13c, |
| 234 | #define NVREG_TX_WM_DESC1_DEFAULT 0x0200010 |
| 235 | #define NVREG_TX_WM_DESC2_3_DEFAULT 0x1e08000 |
| 236 | #define NVREG_TX_WM_DESC2_3_1000 0xfe08000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | NvRegTxRxControl = 0x144, |
| 238 | #define NVREG_TXRXCTL_KICK 0x0001 |
| 239 | #define NVREG_TXRXCTL_BIT1 0x0002 |
| 240 | #define NVREG_TXRXCTL_BIT2 0x0004 |
| 241 | #define NVREG_TXRXCTL_IDLE 0x0008 |
| 242 | #define NVREG_TXRXCTL_RESET 0x0010 |
| 243 | #define NVREG_TXRXCTL_RXCHECK 0x0400 |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 244 | #define NVREG_TXRXCTL_DESC_1 0 |
Ayaz Abdulla | d2f7841 | 2007-01-09 13:30:02 -0500 | [diff] [blame] | 245 | #define NVREG_TXRXCTL_DESC_2 0x002100 |
| 246 | #define NVREG_TXRXCTL_DESC_3 0xc02200 |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 247 | #define NVREG_TXRXCTL_VLANSTRIP 0x00040 |
| 248 | #define NVREG_TXRXCTL_VLANINS 0x00080 |
Ayaz Abdulla | 0832b25 | 2006-02-04 13:13:26 -0500 | [diff] [blame] | 249 | NvRegTxRingPhysAddrHigh = 0x148, |
| 250 | NvRegRxRingPhysAddrHigh = 0x14C, |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 251 | NvRegTxPauseFrame = 0x170, |
Ayaz Abdulla | 5289b4c | 2008-02-05 12:30:01 -0500 | [diff] [blame] | 252 | #define NVREG_TX_PAUSEFRAME_DISABLE 0x0fff0080 |
| 253 | #define NVREG_TX_PAUSEFRAME_ENABLE_V1 0x01800010 |
| 254 | #define NVREG_TX_PAUSEFRAME_ENABLE_V2 0x056003f0 |
| 255 | #define NVREG_TX_PAUSEFRAME_ENABLE_V3 0x09f00880 |
Ayaz Abdulla | 9a33e88 | 2008-08-06 12:12:34 -0400 | [diff] [blame] | 256 | NvRegTxPauseFrameLimit = 0x174, |
| 257 | #define NVREG_TX_PAUSEFRAMELIMIT_ENABLE 0x00010000 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | NvRegMIIStatus = 0x180, |
| 259 | #define NVREG_MIISTAT_ERROR 0x0001 |
| 260 | #define NVREG_MIISTAT_LINKCHANGE 0x0008 |
Ayaz Abdulla | eb79842 | 2008-02-04 15:14:04 -0500 | [diff] [blame] | 261 | #define NVREG_MIISTAT_MASK_RW 0x0007 |
| 262 | #define NVREG_MIISTAT_MASK_ALL 0x000f |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 263 | NvRegMIIMask = 0x184, |
| 264 | #define NVREG_MII_LINKCHANGE 0x0008 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | |
| 266 | NvRegAdapterControl = 0x188, |
| 267 | #define NVREG_ADAPTCTL_START 0x02 |
| 268 | #define NVREG_ADAPTCTL_LINKUP 0x04 |
| 269 | #define NVREG_ADAPTCTL_PHYVALID 0x40000 |
| 270 | #define NVREG_ADAPTCTL_RUNNING 0x100000 |
| 271 | #define NVREG_ADAPTCTL_PHYSHIFT 24 |
| 272 | NvRegMIISpeed = 0x18c, |
| 273 | #define NVREG_MIISPEED_BIT8 (1<<8) |
| 274 | #define NVREG_MIIDELAY 5 |
| 275 | NvRegMIIControl = 0x190, |
| 276 | #define NVREG_MIICTL_INUSE 0x08000 |
| 277 | #define NVREG_MIICTL_WRITE 0x00400 |
| 278 | #define NVREG_MIICTL_ADDRSHIFT 5 |
| 279 | NvRegMIIData = 0x194, |
Ayaz Abdulla | 9c66243 | 2008-08-06 12:11:42 -0400 | [diff] [blame] | 280 | NvRegTxUnicast = 0x1a0, |
| 281 | NvRegTxMulticast = 0x1a4, |
| 282 | NvRegTxBroadcast = 0x1a8, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | NvRegWakeUpFlags = 0x200, |
| 284 | #define NVREG_WAKEUPFLAGS_VAL 0x7770 |
| 285 | #define NVREG_WAKEUPFLAGS_BUSYSHIFT 24 |
| 286 | #define NVREG_WAKEUPFLAGS_ENABLESHIFT 16 |
| 287 | #define NVREG_WAKEUPFLAGS_D3SHIFT 12 |
| 288 | #define NVREG_WAKEUPFLAGS_D2SHIFT 8 |
| 289 | #define NVREG_WAKEUPFLAGS_D1SHIFT 4 |
| 290 | #define NVREG_WAKEUPFLAGS_D0SHIFT 0 |
| 291 | #define NVREG_WAKEUPFLAGS_ACCEPT_MAGPAT 0x01 |
| 292 | #define NVREG_WAKEUPFLAGS_ACCEPT_WAKEUPPAT 0x02 |
| 293 | #define NVREG_WAKEUPFLAGS_ACCEPT_LINKCHANGE 0x04 |
| 294 | #define NVREG_WAKEUPFLAGS_ENABLE 0x1111 |
| 295 | |
Ayaz Abdulla | cac1c52 | 2009-02-07 00:23:57 -0800 | [diff] [blame] | 296 | NvRegMgmtUnitGetVersion = 0x204, |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 297 | #define NVREG_MGMTUNITGETVERSION 0x01 |
Ayaz Abdulla | cac1c52 | 2009-02-07 00:23:57 -0800 | [diff] [blame] | 298 | NvRegMgmtUnitVersion = 0x208, |
| 299 | #define NVREG_MGMTUNITVERSION 0x08 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 300 | NvRegPowerCap = 0x268, |
| 301 | #define NVREG_POWERCAP_D3SUPP (1<<30) |
| 302 | #define NVREG_POWERCAP_D2SUPP (1<<26) |
| 303 | #define NVREG_POWERCAP_D1SUPP (1<<25) |
| 304 | NvRegPowerState = 0x26c, |
| 305 | #define NVREG_POWERSTATE_POWEREDUP 0x8000 |
| 306 | #define NVREG_POWERSTATE_VALID 0x0100 |
| 307 | #define NVREG_POWERSTATE_MASK 0x0003 |
| 308 | #define NVREG_POWERSTATE_D0 0x0000 |
| 309 | #define NVREG_POWERSTATE_D1 0x0001 |
| 310 | #define NVREG_POWERSTATE_D2 0x0002 |
| 311 | #define NVREG_POWERSTATE_D3 0x0003 |
Ayaz Abdulla | cac1c52 | 2009-02-07 00:23:57 -0800 | [diff] [blame] | 312 | NvRegMgmtUnitControl = 0x278, |
| 313 | #define NVREG_MGMTUNITCONTROL_INUSE 0x20000 |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 314 | NvRegTxCnt = 0x280, |
| 315 | NvRegTxZeroReXmt = 0x284, |
| 316 | NvRegTxOneReXmt = 0x288, |
| 317 | NvRegTxManyReXmt = 0x28c, |
| 318 | NvRegTxLateCol = 0x290, |
| 319 | NvRegTxUnderflow = 0x294, |
| 320 | NvRegTxLossCarrier = 0x298, |
| 321 | NvRegTxExcessDef = 0x29c, |
| 322 | NvRegTxRetryErr = 0x2a0, |
| 323 | NvRegRxFrameErr = 0x2a4, |
| 324 | NvRegRxExtraByte = 0x2a8, |
| 325 | NvRegRxLateCol = 0x2ac, |
| 326 | NvRegRxRunt = 0x2b0, |
| 327 | NvRegRxFrameTooLong = 0x2b4, |
| 328 | NvRegRxOverflow = 0x2b8, |
| 329 | NvRegRxFCSErr = 0x2bc, |
| 330 | NvRegRxFrameAlignErr = 0x2c0, |
| 331 | NvRegRxLenErr = 0x2c4, |
| 332 | NvRegRxUnicast = 0x2c8, |
| 333 | NvRegRxMulticast = 0x2cc, |
| 334 | NvRegRxBroadcast = 0x2d0, |
| 335 | NvRegTxDef = 0x2d4, |
| 336 | NvRegTxFrame = 0x2d8, |
| 337 | NvRegRxCnt = 0x2dc, |
| 338 | NvRegTxPause = 0x2e0, |
| 339 | NvRegRxPause = 0x2e4, |
| 340 | NvRegRxDropFrame = 0x2e8, |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 341 | NvRegVlanControl = 0x300, |
| 342 | #define NVREG_VLANCONTROL_ENABLE 0x2000 |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 343 | NvRegMSIXMap0 = 0x3e0, |
| 344 | NvRegMSIXMap1 = 0x3e4, |
| 345 | NvRegMSIXIrqStatus = 0x3f0, |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 346 | |
| 347 | NvRegPowerState2 = 0x600, |
Ayaz Abdulla | 1545e20 | 2008-09-22 09:55:35 -0400 | [diff] [blame] | 348 | #define NVREG_POWERSTATE2_POWERUP_MASK 0x0F15 |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 349 | #define NVREG_POWERSTATE2_POWERUP_REV_A3 0x0001 |
Ayaz Abdulla | 22ae03a | 2008-07-25 15:31:29 -0400 | [diff] [blame] | 350 | #define NVREG_POWERSTATE2_PHY_RESET 0x0004 |
Ayaz Abdulla | 88d7d8b | 2009-05-01 01:41:50 +0000 | [diff] [blame] | 351 | #define NVREG_POWERSTATE2_GATE_CLOCKS 0x0F00 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | }; |
| 353 | |
| 354 | /* Big endian: should work, but is untested */ |
| 355 | struct ring_desc { |
Stephen Hemminger | a8bed49 | 2006-07-27 18:50:09 -0700 | [diff] [blame] | 356 | __le32 buf; |
| 357 | __le32 flaglen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | }; |
| 359 | |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 360 | struct ring_desc_ex { |
Stephen Hemminger | a8bed49 | 2006-07-27 18:50:09 -0700 | [diff] [blame] | 361 | __le32 bufhigh; |
| 362 | __le32 buflow; |
| 363 | __le32 txvlan; |
| 364 | __le32 flaglen; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 365 | }; |
| 366 | |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 367 | union ring_type { |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 368 | struct ring_desc *orig; |
| 369 | struct ring_desc_ex *ex; |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 370 | }; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 371 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | #define FLAG_MASK_V1 0xffff0000 |
| 373 | #define FLAG_MASK_V2 0xffffc000 |
| 374 | #define LEN_MASK_V1 (0xffffffff ^ FLAG_MASK_V1) |
| 375 | #define LEN_MASK_V2 (0xffffffff ^ FLAG_MASK_V2) |
| 376 | |
| 377 | #define NV_TX_LASTPACKET (1<<16) |
| 378 | #define NV_TX_RETRYERROR (1<<19) |
Ayaz Abdulla | a433686 | 2008-04-18 13:50:43 -0700 | [diff] [blame] | 379 | #define NV_TX_RETRYCOUNT_MASK (0xF<<20) |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 380 | #define NV_TX_FORCED_INTERRUPT (1<<24) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | #define NV_TX_DEFERRED (1<<26) |
| 382 | #define NV_TX_CARRIERLOST (1<<27) |
| 383 | #define NV_TX_LATECOLLISION (1<<28) |
| 384 | #define NV_TX_UNDERFLOW (1<<29) |
| 385 | #define NV_TX_ERROR (1<<30) |
| 386 | #define NV_TX_VALID (1<<31) |
| 387 | |
| 388 | #define NV_TX2_LASTPACKET (1<<29) |
| 389 | #define NV_TX2_RETRYERROR (1<<18) |
Ayaz Abdulla | a433686 | 2008-04-18 13:50:43 -0700 | [diff] [blame] | 390 | #define NV_TX2_RETRYCOUNT_MASK (0xF<<19) |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 391 | #define NV_TX2_FORCED_INTERRUPT (1<<30) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 392 | #define NV_TX2_DEFERRED (1<<25) |
| 393 | #define NV_TX2_CARRIERLOST (1<<26) |
| 394 | #define NV_TX2_LATECOLLISION (1<<27) |
| 395 | #define NV_TX2_UNDERFLOW (1<<28) |
| 396 | /* error and valid are the same for both */ |
| 397 | #define NV_TX2_ERROR (1<<30) |
| 398 | #define NV_TX2_VALID (1<<31) |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 399 | #define NV_TX2_TSO (1<<28) |
| 400 | #define NV_TX2_TSO_SHIFT 14 |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 401 | #define NV_TX2_TSO_MAX_SHIFT 14 |
| 402 | #define NV_TX2_TSO_MAX_SIZE (1<<NV_TX2_TSO_MAX_SHIFT) |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 403 | #define NV_TX2_CHECKSUM_L3 (1<<27) |
| 404 | #define NV_TX2_CHECKSUM_L4 (1<<26) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 406 | #define NV_TX3_VLAN_TAG_PRESENT (1<<18) |
| 407 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | #define NV_RX_DESCRIPTORVALID (1<<16) |
| 409 | #define NV_RX_MISSEDFRAME (1<<17) |
| 410 | #define NV_RX_SUBSTRACT1 (1<<18) |
| 411 | #define NV_RX_ERROR1 (1<<23) |
| 412 | #define NV_RX_ERROR2 (1<<24) |
| 413 | #define NV_RX_ERROR3 (1<<25) |
| 414 | #define NV_RX_ERROR4 (1<<26) |
| 415 | #define NV_RX_CRCERR (1<<27) |
| 416 | #define NV_RX_OVERFLOW (1<<28) |
| 417 | #define NV_RX_FRAMINGERR (1<<29) |
| 418 | #define NV_RX_ERROR (1<<30) |
| 419 | #define NV_RX_AVAIL (1<<31) |
Ayaz Abdulla | 1ef6841 | 2008-08-06 12:11:03 -0400 | [diff] [blame] | 420 | #define NV_RX_ERROR_MASK (NV_RX_ERROR1|NV_RX_ERROR2|NV_RX_ERROR3|NV_RX_ERROR4|NV_RX_CRCERR|NV_RX_OVERFLOW|NV_RX_FRAMINGERR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | |
| 422 | #define NV_RX2_CHECKSUMMASK (0x1C000000) |
Ayaz Abdulla | bfaffe8 | 2008-01-13 16:02:55 -0500 | [diff] [blame] | 423 | #define NV_RX2_CHECKSUM_IP (0x10000000) |
| 424 | #define NV_RX2_CHECKSUM_IP_TCP (0x14000000) |
| 425 | #define NV_RX2_CHECKSUM_IP_UDP (0x18000000) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | #define NV_RX2_DESCRIPTORVALID (1<<29) |
| 427 | #define NV_RX2_SUBSTRACT1 (1<<25) |
| 428 | #define NV_RX2_ERROR1 (1<<18) |
| 429 | #define NV_RX2_ERROR2 (1<<19) |
| 430 | #define NV_RX2_ERROR3 (1<<20) |
| 431 | #define NV_RX2_ERROR4 (1<<21) |
| 432 | #define NV_RX2_CRCERR (1<<22) |
| 433 | #define NV_RX2_OVERFLOW (1<<23) |
| 434 | #define NV_RX2_FRAMINGERR (1<<24) |
| 435 | /* error and avail are the same for both */ |
| 436 | #define NV_RX2_ERROR (1<<30) |
| 437 | #define NV_RX2_AVAIL (1<<31) |
Ayaz Abdulla | 1ef6841 | 2008-08-06 12:11:03 -0400 | [diff] [blame] | 438 | #define NV_RX2_ERROR_MASK (NV_RX2_ERROR1|NV_RX2_ERROR2|NV_RX2_ERROR3|NV_RX2_ERROR4|NV_RX2_CRCERR|NV_RX2_OVERFLOW|NV_RX2_FRAMINGERR) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 440 | #define NV_RX3_VLAN_TAG_PRESENT (1<<16) |
| 441 | #define NV_RX3_VLAN_TAG_MASK (0x0000FFFF) |
| 442 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 443 | /* Miscellaneous hardware related defines: */ |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 444 | #define NV_PCI_REGSZ_VER1 0x270 |
| 445 | #define NV_PCI_REGSZ_VER2 0x2d4 |
| 446 | #define NV_PCI_REGSZ_VER3 0x604 |
| 447 | #define NV_PCI_REGSZ_MAX 0x604 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
| 449 | /* various timeout delays: all in usec */ |
| 450 | #define NV_TXRX_RESET_DELAY 4 |
| 451 | #define NV_TXSTOP_DELAY1 10 |
| 452 | #define NV_TXSTOP_DELAY1MAX 500000 |
| 453 | #define NV_TXSTOP_DELAY2 100 |
| 454 | #define NV_RXSTOP_DELAY1 10 |
| 455 | #define NV_RXSTOP_DELAY1MAX 500000 |
| 456 | #define NV_RXSTOP_DELAY2 100 |
| 457 | #define NV_SETUP5_DELAY 5 |
| 458 | #define NV_SETUP5_DELAYMAX 50000 |
| 459 | #define NV_POWERUP_DELAY 5 |
| 460 | #define NV_POWERUP_DELAYMAX 5000 |
| 461 | #define NV_MIIBUSY_DELAY 50 |
| 462 | #define NV_MIIPHY_DELAY 10 |
| 463 | #define NV_MIIPHY_DELAYMAX 10000 |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 464 | #define NV_MAC_RESET_DELAY 64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | |
| 466 | #define NV_WAKEUPPATTERNS 5 |
| 467 | #define NV_WAKEUPMASKENTRIES 4 |
| 468 | |
| 469 | /* General driver defaults */ |
| 470 | #define NV_WATCHDOG_TIMEO (5*HZ) |
| 471 | |
Ayaz Abdulla | 6cef67a | 2009-03-05 08:02:30 +0000 | [diff] [blame] | 472 | #define RX_RING_DEFAULT 512 |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 473 | #define TX_RING_DEFAULT 256 |
| 474 | #define RX_RING_MIN 128 |
| 475 | #define TX_RING_MIN 64 |
| 476 | #define RING_MAX_DESC_VER_1 1024 |
| 477 | #define RING_MAX_DESC_VER_2_3 16384 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | |
| 479 | /* rx/tx mac addr + type + vlan + align + slack*/ |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 480 | #define NV_RX_HEADERS (64) |
| 481 | /* even more slack. */ |
| 482 | #define NV_RX_ALLOC_PAD (64) |
| 483 | |
| 484 | /* maximum mtu size */ |
| 485 | #define NV_PKTLIMIT_1 ETH_DATA_LEN /* hard limit not known */ |
| 486 | #define NV_PKTLIMIT_2 9100 /* Actual limit according to NVidia: 9202 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | |
| 488 | #define OOM_REFILL (1+HZ/20) |
| 489 | #define POLL_WAIT (1+HZ/100) |
| 490 | #define LINK_TIMEOUT (3*HZ) |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 491 | #define STATS_INTERVAL (10*HZ) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 492 | |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 493 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | * desc_ver values: |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 495 | * The nic supports three different descriptor types: |
| 496 | * - DESC_VER_1: Original |
| 497 | * - DESC_VER_2: support for jumbo frames. |
| 498 | * - DESC_VER_3: 64-bit format. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | */ |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 500 | #define DESC_VER_1 1 |
| 501 | #define DESC_VER_2 2 |
| 502 | #define DESC_VER_3 3 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | |
| 504 | /* PHY defines */ |
Ayaz Abdulla | 9f3f791 | 2008-04-23 14:37:30 -0400 | [diff] [blame] | 505 | #define PHY_OUI_MARVELL 0x5043 |
| 506 | #define PHY_OUI_CICADA 0x03f1 |
| 507 | #define PHY_OUI_VITESSE 0x01c1 |
| 508 | #define PHY_OUI_REALTEK 0x0732 |
| 509 | #define PHY_OUI_REALTEK2 0x0020 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | #define PHYID1_OUI_MASK 0x03ff |
| 511 | #define PHYID1_OUI_SHFT 6 |
| 512 | #define PHYID2_OUI_MASK 0xfc00 |
| 513 | #define PHYID2_OUI_SHFT 10 |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 514 | #define PHYID2_MODEL_MASK 0x03f0 |
Ayaz Abdulla | 9f3f791 | 2008-04-23 14:37:30 -0400 | [diff] [blame] | 515 | #define PHY_MODEL_REALTEK_8211 0x0110 |
| 516 | #define PHY_REV_MASK 0x0001 |
| 517 | #define PHY_REV_REALTEK_8211B 0x0000 |
| 518 | #define PHY_REV_REALTEK_8211C 0x0001 |
| 519 | #define PHY_MODEL_REALTEK_8201 0x0200 |
| 520 | #define PHY_MODEL_MARVELL_E3016 0x0220 |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 521 | #define PHY_MARVELL_E3016_INITMASK 0x0300 |
Ayaz Abdulla | 14a67f3 | 2007-07-15 06:50:28 -0400 | [diff] [blame] | 522 | #define PHY_CICADA_INIT1 0x0f000 |
| 523 | #define PHY_CICADA_INIT2 0x0e00 |
| 524 | #define PHY_CICADA_INIT3 0x01000 |
| 525 | #define PHY_CICADA_INIT4 0x0200 |
| 526 | #define PHY_CICADA_INIT5 0x0004 |
| 527 | #define PHY_CICADA_INIT6 0x02000 |
Ayaz Abdulla | d215d8a | 2007-07-15 06:50:53 -0400 | [diff] [blame] | 528 | #define PHY_VITESSE_INIT_REG1 0x1f |
| 529 | #define PHY_VITESSE_INIT_REG2 0x10 |
| 530 | #define PHY_VITESSE_INIT_REG3 0x11 |
| 531 | #define PHY_VITESSE_INIT_REG4 0x12 |
| 532 | #define PHY_VITESSE_INIT_MSK1 0xc |
| 533 | #define PHY_VITESSE_INIT_MSK2 0x0180 |
| 534 | #define PHY_VITESSE_INIT1 0x52b5 |
| 535 | #define PHY_VITESSE_INIT2 0xaf8a |
| 536 | #define PHY_VITESSE_INIT3 0x8 |
| 537 | #define PHY_VITESSE_INIT4 0x8f8a |
| 538 | #define PHY_VITESSE_INIT5 0xaf86 |
| 539 | #define PHY_VITESSE_INIT6 0x8f86 |
| 540 | #define PHY_VITESSE_INIT7 0xaf82 |
| 541 | #define PHY_VITESSE_INIT8 0x0100 |
| 542 | #define PHY_VITESSE_INIT9 0x8f82 |
| 543 | #define PHY_VITESSE_INIT10 0x0 |
Ayaz Abdulla | c5e3ae8 | 2007-07-15 06:51:03 -0400 | [diff] [blame] | 544 | #define PHY_REALTEK_INIT_REG1 0x1f |
| 545 | #define PHY_REALTEK_INIT_REG2 0x19 |
| 546 | #define PHY_REALTEK_INIT_REG3 0x13 |
Ayaz Abdulla | 9f3f791 | 2008-04-23 14:37:30 -0400 | [diff] [blame] | 547 | #define PHY_REALTEK_INIT_REG4 0x14 |
| 548 | #define PHY_REALTEK_INIT_REG5 0x18 |
| 549 | #define PHY_REALTEK_INIT_REG6 0x11 |
Ayaz Abdulla | 22ae03a | 2008-07-25 15:31:29 -0400 | [diff] [blame] | 550 | #define PHY_REALTEK_INIT_REG7 0x01 |
Ayaz Abdulla | c5e3ae8 | 2007-07-15 06:51:03 -0400 | [diff] [blame] | 551 | #define PHY_REALTEK_INIT1 0x0000 |
| 552 | #define PHY_REALTEK_INIT2 0x8e00 |
| 553 | #define PHY_REALTEK_INIT3 0x0001 |
| 554 | #define PHY_REALTEK_INIT4 0xad17 |
Ayaz Abdulla | 9f3f791 | 2008-04-23 14:37:30 -0400 | [diff] [blame] | 555 | #define PHY_REALTEK_INIT5 0xfb54 |
| 556 | #define PHY_REALTEK_INIT6 0xf5c7 |
| 557 | #define PHY_REALTEK_INIT7 0x1000 |
| 558 | #define PHY_REALTEK_INIT8 0x0003 |
Ayaz Abdulla | 22ae03a | 2008-07-25 15:31:29 -0400 | [diff] [blame] | 559 | #define PHY_REALTEK_INIT9 0x0008 |
| 560 | #define PHY_REALTEK_INIT10 0x0005 |
| 561 | #define PHY_REALTEK_INIT11 0x0200 |
Ayaz Abdulla | 9f3f791 | 2008-04-23 14:37:30 -0400 | [diff] [blame] | 562 | #define PHY_REALTEK_INIT_MSK1 0x0003 |
Ayaz Abdulla | d215d8a | 2007-07-15 06:50:53 -0400 | [diff] [blame] | 563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | #define PHY_GIGABIT 0x0100 |
| 565 | |
| 566 | #define PHY_TIMEOUT 0x1 |
| 567 | #define PHY_ERROR 0x2 |
| 568 | |
| 569 | #define PHY_100 0x1 |
| 570 | #define PHY_1000 0x2 |
| 571 | #define PHY_HALF 0x100 |
| 572 | |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 573 | #define NV_PAUSEFRAME_RX_CAPABLE 0x0001 |
| 574 | #define NV_PAUSEFRAME_TX_CAPABLE 0x0002 |
| 575 | #define NV_PAUSEFRAME_RX_ENABLE 0x0004 |
| 576 | #define NV_PAUSEFRAME_TX_ENABLE 0x0008 |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 577 | #define NV_PAUSEFRAME_RX_REQ 0x0010 |
| 578 | #define NV_PAUSEFRAME_TX_REQ 0x0020 |
| 579 | #define NV_PAUSEFRAME_AUTONEG 0x0040 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 581 | /* MSI/MSI-X defines */ |
| 582 | #define NV_MSI_X_MAX_VECTORS 8 |
| 583 | #define NV_MSI_X_VECTORS_MASK 0x000f |
| 584 | #define NV_MSI_CAPABLE 0x0010 |
| 585 | #define NV_MSI_X_CAPABLE 0x0020 |
| 586 | #define NV_MSI_ENABLED 0x0040 |
| 587 | #define NV_MSI_X_ENABLED 0x0080 |
| 588 | |
| 589 | #define NV_MSI_X_VECTOR_ALL 0x0 |
| 590 | #define NV_MSI_X_VECTOR_RX 0x0 |
| 591 | #define NV_MSI_X_VECTOR_TX 0x1 |
| 592 | #define NV_MSI_X_VECTOR_OTHER 0x2 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | |
Ayaz Abdulla | b6e4405 | 2009-02-07 00:24:15 -0800 | [diff] [blame] | 594 | #define NV_MSI_PRIV_OFFSET 0x68 |
| 595 | #define NV_MSI_PRIV_VALUE 0xffffffff |
| 596 | |
Ayaz Abdulla | b2976d2 | 2008-02-04 15:13:59 -0500 | [diff] [blame] | 597 | #define NV_RESTART_TX 0x1 |
| 598 | #define NV_RESTART_RX 0x2 |
| 599 | |
Ayaz Abdulla | 3b446c3 | 2008-03-10 14:58:21 -0500 | [diff] [blame] | 600 | #define NV_TX_LIMIT_COUNT 16 |
| 601 | |
Ayaz Abdulla | 4145ade | 2009-03-05 08:02:26 +0000 | [diff] [blame] | 602 | #define NV_DYNAMIC_THRESHOLD 4 |
| 603 | #define NV_DYNAMIC_MAX_QUIET_COUNT 2048 |
| 604 | |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 605 | /* statistics */ |
| 606 | struct nv_ethtool_str { |
| 607 | char name[ETH_GSTRING_LEN]; |
| 608 | }; |
| 609 | |
| 610 | static const struct nv_ethtool_str nv_estats_str[] = { |
david decotigny | 674aee3 | 2011-11-16 12:15:07 +0000 | [diff] [blame] | 611 | { "tx_bytes" }, /* includes Ethernet FCS CRC */ |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 612 | { "tx_zero_rexmt" }, |
| 613 | { "tx_one_rexmt" }, |
| 614 | { "tx_many_rexmt" }, |
| 615 | { "tx_late_collision" }, |
| 616 | { "tx_fifo_errors" }, |
| 617 | { "tx_carrier_errors" }, |
| 618 | { "tx_excess_deferral" }, |
| 619 | { "tx_retry_error" }, |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 620 | { "rx_frame_error" }, |
| 621 | { "rx_extra_byte" }, |
| 622 | { "rx_late_collision" }, |
| 623 | { "rx_runt" }, |
| 624 | { "rx_frame_too_long" }, |
| 625 | { "rx_over_errors" }, |
| 626 | { "rx_crc_errors" }, |
| 627 | { "rx_frame_align_error" }, |
| 628 | { "rx_length_error" }, |
| 629 | { "rx_unicast" }, |
| 630 | { "rx_multicast" }, |
| 631 | { "rx_broadcast" }, |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 632 | { "rx_packets" }, |
Ayaz Abdulla | 57fff69 | 2007-01-23 12:27:00 -0500 | [diff] [blame] | 633 | { "rx_errors_total" }, |
| 634 | { "tx_errors_total" }, |
| 635 | |
| 636 | /* version 2 stats */ |
| 637 | { "tx_deferral" }, |
| 638 | { "tx_packets" }, |
david decotigny | 674aee3 | 2011-11-16 12:15:07 +0000 | [diff] [blame] | 639 | { "rx_bytes" }, /* includes Ethernet FCS CRC */ |
Ayaz Abdulla | 57fff69 | 2007-01-23 12:27:00 -0500 | [diff] [blame] | 640 | { "tx_pause" }, |
| 641 | { "rx_pause" }, |
Ayaz Abdulla | 9c66243 | 2008-08-06 12:11:42 -0400 | [diff] [blame] | 642 | { "rx_drop_frame" }, |
| 643 | |
| 644 | /* version 3 stats */ |
| 645 | { "tx_unicast" }, |
| 646 | { "tx_multicast" }, |
| 647 | { "tx_broadcast" } |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 648 | }; |
| 649 | |
| 650 | struct nv_ethtool_stats { |
david decotigny | 674aee3 | 2011-11-16 12:15:07 +0000 | [diff] [blame] | 651 | u64 tx_bytes; /* should be ifconfig->tx_bytes + 4*tx_packets */ |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 652 | u64 tx_zero_rexmt; |
| 653 | u64 tx_one_rexmt; |
| 654 | u64 tx_many_rexmt; |
| 655 | u64 tx_late_collision; |
| 656 | u64 tx_fifo_errors; |
| 657 | u64 tx_carrier_errors; |
| 658 | u64 tx_excess_deferral; |
| 659 | u64 tx_retry_error; |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 660 | u64 rx_frame_error; |
| 661 | u64 rx_extra_byte; |
| 662 | u64 rx_late_collision; |
| 663 | u64 rx_runt; |
| 664 | u64 rx_frame_too_long; |
| 665 | u64 rx_over_errors; |
| 666 | u64 rx_crc_errors; |
| 667 | u64 rx_frame_align_error; |
| 668 | u64 rx_length_error; |
| 669 | u64 rx_unicast; |
| 670 | u64 rx_multicast; |
| 671 | u64 rx_broadcast; |
david decotigny | 674aee3 | 2011-11-16 12:15:07 +0000 | [diff] [blame] | 672 | u64 rx_packets; /* should be ifconfig->rx_packets */ |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 673 | u64 rx_errors_total; |
Ayaz Abdulla | 57fff69 | 2007-01-23 12:27:00 -0500 | [diff] [blame] | 674 | u64 tx_errors_total; |
| 675 | |
| 676 | /* version 2 stats */ |
| 677 | u64 tx_deferral; |
david decotigny | 674aee3 | 2011-11-16 12:15:07 +0000 | [diff] [blame] | 678 | u64 tx_packets; /* should be ifconfig->tx_packets */ |
| 679 | u64 rx_bytes; /* should be ifconfig->rx_bytes + 4*rx_packets */ |
Ayaz Abdulla | 57fff69 | 2007-01-23 12:27:00 -0500 | [diff] [blame] | 680 | u64 tx_pause; |
| 681 | u64 rx_pause; |
| 682 | u64 rx_drop_frame; |
Ayaz Abdulla | 9c66243 | 2008-08-06 12:11:42 -0400 | [diff] [blame] | 683 | |
| 684 | /* version 3 stats */ |
| 685 | u64 tx_unicast; |
| 686 | u64 tx_multicast; |
| 687 | u64 tx_broadcast; |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 688 | }; |
| 689 | |
Ayaz Abdulla | 9c66243 | 2008-08-06 12:11:42 -0400 | [diff] [blame] | 690 | #define NV_DEV_STATISTICS_V3_COUNT (sizeof(struct nv_ethtool_stats)/sizeof(u64)) |
| 691 | #define NV_DEV_STATISTICS_V2_COUNT (NV_DEV_STATISTICS_V3_COUNT - 3) |
Ayaz Abdulla | 57fff69 | 2007-01-23 12:27:00 -0500 | [diff] [blame] | 692 | #define NV_DEV_STATISTICS_V1_COUNT (NV_DEV_STATISTICS_V2_COUNT - 6) |
| 693 | |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 694 | /* diagnostics */ |
| 695 | #define NV_TEST_COUNT_BASE 3 |
| 696 | #define NV_TEST_COUNT_EXTENDED 4 |
| 697 | |
| 698 | static const struct nv_ethtool_str nv_etests_str[] = { |
| 699 | { "link (online/offline)" }, |
| 700 | { "register (offline) " }, |
| 701 | { "interrupt (offline) " }, |
| 702 | { "loopback (offline) " } |
| 703 | }; |
| 704 | |
| 705 | struct register_test { |
Al Viro | 5bb7ea2 | 2007-12-09 16:06:41 +0000 | [diff] [blame] | 706 | __u32 reg; |
| 707 | __u32 mask; |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 708 | }; |
| 709 | |
| 710 | static const struct register_test nv_registers_test[] = { |
| 711 | { NvRegUnknownSetupReg6, 0x01 }, |
| 712 | { NvRegMisc1, 0x03c }, |
| 713 | { NvRegOffloadConfig, 0x03ff }, |
| 714 | { NvRegMulticastAddrA, 0xffffffff }, |
Ayaz Abdulla | 95d161c | 2006-07-06 16:46:25 -0400 | [diff] [blame] | 715 | { NvRegTxWatermark, 0x0ff }, |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 716 | { NvRegWakeUpFlags, 0x07777 }, |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 717 | { 0, 0 } |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 718 | }; |
| 719 | |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 720 | struct nv_skb_map { |
| 721 | struct sk_buff *skb; |
| 722 | dma_addr_t dma; |
Eric Dumazet | 73a3707 | 2009-06-17 21:17:59 +0000 | [diff] [blame] | 723 | unsigned int dma_len:31; |
| 724 | unsigned int dma_single:1; |
Ayaz Abdulla | 3b446c3 | 2008-03-10 14:58:21 -0500 | [diff] [blame] | 725 | struct ring_desc_ex *first_tx_desc; |
| 726 | struct nv_skb_map *next_tx_ctx; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 727 | }; |
| 728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | /* |
| 730 | * SMP locking: |
Wang Chen | b74ca3a | 2008-12-08 01:14:16 -0800 | [diff] [blame] | 731 | * All hardware access under netdev_priv(dev)->lock, except the performance |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 732 | * critical parts: |
| 733 | * - rx is (pseudo-) lockless: it relies on the single-threading provided |
| 734 | * by the arch code for interrupts. |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 735 | * - tx setup is lockless: it relies on netif_tx_lock. Actual submission |
Wang Chen | b74ca3a | 2008-12-08 01:14:16 -0800 | [diff] [blame] | 736 | * needs netdev_priv(dev)->lock :-( |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 737 | * - set_multicast_list: preparation lockless, relies on netif_tx_lock. |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 738 | * |
| 739 | * Hardware stats updates are protected by hwstats_lock: |
| 740 | * - updated by nv_do_stats_poll (timer). This is meant to avoid |
| 741 | * integer wraparound in the NIC stats registers, at low frequency |
| 742 | * (0.1 Hz) |
| 743 | * - updated by nv_get_ethtool_stats + nv_get_stats64 |
| 744 | * |
| 745 | * Software stats are accessed only through 64b synchronization points |
| 746 | * and are not subject to other synchronization techniques (single |
| 747 | * update thread on the TX or RX paths). |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | */ |
| 749 | |
| 750 | /* in dev: base, irq */ |
| 751 | struct fe_priv { |
| 752 | spinlock_t lock; |
| 753 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 754 | struct net_device *dev; |
| 755 | struct napi_struct napi; |
| 756 | |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 757 | /* hardware stats are updated in syscall and timer */ |
| 758 | spinlock_t hwstats_lock; |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 759 | struct nv_ethtool_stats estats; |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 760 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | int in_shutdown; |
| 762 | u32 linkspeed; |
| 763 | int duplex; |
| 764 | int autoneg; |
| 765 | int fixed_mode; |
| 766 | int phyaddr; |
| 767 | int wolenabled; |
| 768 | unsigned int phy_oui; |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 769 | unsigned int phy_model; |
Ayaz Abdulla | 9f3f791 | 2008-04-23 14:37:30 -0400 | [diff] [blame] | 770 | unsigned int phy_rev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | u16 gigabit; |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 772 | int intr_test; |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 773 | int recover_error; |
Ayaz Abdulla | 4145ade | 2009-03-05 08:02:26 +0000 | [diff] [blame] | 774 | int quiet_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | |
| 776 | /* General data: RO fields */ |
| 777 | dma_addr_t ring_addr; |
| 778 | struct pci_dev *pci_dev; |
| 779 | u32 orig_mac[2]; |
Ayaz Abdulla | 582806b | 2009-03-05 08:02:03 +0000 | [diff] [blame] | 780 | u32 events; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | u32 irqmask; |
| 782 | u32 desc_ver; |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 783 | u32 txrxctl_bits; |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 784 | u32 vlanctl_bits; |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 785 | u32 driver_data; |
Ayaz Abdulla | 9f3f791 | 2008-04-23 14:37:30 -0400 | [diff] [blame] | 786 | u32 device_id; |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 787 | u32 register_size; |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 788 | u32 mac_in_use; |
Ayaz Abdulla | cac1c52 | 2009-02-07 00:23:57 -0800 | [diff] [blame] | 789 | int mgmt_version; |
| 790 | int mgmt_sema; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | |
| 792 | void __iomem *base; |
| 793 | |
| 794 | /* rx specific fields. |
| 795 | * Locking: Within irq hander or disable_irq+spin_lock(&np->lock); |
| 796 | */ |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 797 | union ring_type get_rx, put_rx, first_rx, last_rx; |
| 798 | struct nv_skb_map *get_rx_ctx, *put_rx_ctx; |
| 799 | struct nv_skb_map *first_rx_ctx, *last_rx_ctx; |
| 800 | struct nv_skb_map *rx_skb; |
| 801 | |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 802 | union ring_type rx_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | unsigned int rx_buf_sz; |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 804 | unsigned int pkt_limit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | struct timer_list oom_kick; |
| 806 | struct timer_list nic_poll; |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 807 | struct timer_list stats_poll; |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 808 | u32 nic_poll_irq; |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 809 | int rx_ring_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 811 | /* RX software stats */ |
| 812 | struct u64_stats_sync swstats_rx_syncp; |
| 813 | u64 stat_rx_packets; |
| 814 | u64 stat_rx_bytes; /* not always available in HW */ |
| 815 | u64 stat_rx_missed_errors; |
david decotigny | 0a1f222 | 2011-11-16 12:15:14 +0000 | [diff] [blame] | 816 | u64 stat_rx_dropped; |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 817 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 818 | /* media detection workaround. |
| 819 | * Locking: Within irq hander or disable_irq+spin_lock(&np->lock); |
| 820 | */ |
| 821 | int need_linktimer; |
| 822 | unsigned long link_timeout; |
| 823 | /* |
| 824 | * tx specific fields. |
| 825 | */ |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 826 | union ring_type get_tx, put_tx, first_tx, last_tx; |
| 827 | struct nv_skb_map *get_tx_ctx, *put_tx_ctx; |
| 828 | struct nv_skb_map *first_tx_ctx, *last_tx_ctx; |
| 829 | struct nv_skb_map *tx_skb; |
| 830 | |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 831 | union ring_type tx_ring; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | u32 tx_flags; |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 833 | int tx_ring_size; |
Ayaz Abdulla | 3b446c3 | 2008-03-10 14:58:21 -0500 | [diff] [blame] | 834 | int tx_limit; |
| 835 | u32 tx_pkts_in_progress; |
| 836 | struct nv_skb_map *tx_change_owner; |
| 837 | struct nv_skb_map *tx_end_flip; |
Ayaz Abdulla | aaa37d2 | 2007-01-21 18:10:42 -0500 | [diff] [blame] | 838 | int tx_stop; |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 839 | |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 840 | /* TX software stats */ |
| 841 | struct u64_stats_sync swstats_tx_syncp; |
| 842 | u64 stat_tx_packets; /* not always available in HW */ |
| 843 | u64 stat_tx_bytes; |
| 844 | u64 stat_tx_dropped; |
| 845 | |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 846 | /* msi/msi-x fields */ |
| 847 | u32 msi_flags; |
| 848 | struct msix_entry msi_x_entry[NV_MSI_X_MAX_VECTORS]; |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 849 | |
| 850 | /* flow control */ |
| 851 | u32 pause_flags; |
Tobias Diedrich | 1a1ca86 | 2008-05-18 15:03:44 +0200 | [diff] [blame] | 852 | |
| 853 | /* power saved state */ |
| 854 | u32 saved_config_space[NV_PCI_REGSZ_MAX/4]; |
Yinghai Lu | ddb213f | 2009-02-06 01:29:23 -0800 | [diff] [blame] | 855 | |
| 856 | /* for different msi-x irq type */ |
| 857 | char name_rx[IFNAMSIZ + 3]; /* -rx */ |
| 858 | char name_tx[IFNAMSIZ + 3]; /* -tx */ |
| 859 | char name_other[IFNAMSIZ + 6]; /* -other */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 860 | }; |
| 861 | |
| 862 | /* |
| 863 | * Maximum number of loops until we assume that a bit in the irq mask |
| 864 | * is stuck. Overridable with module param. |
| 865 | */ |
Ayaz Abdulla | 4145ade | 2009-03-05 08:02:26 +0000 | [diff] [blame] | 866 | static int max_interrupt_work = 4; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 868 | /* |
| 869 | * Optimization can be either throuput mode or cpu mode |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 870 | * |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 871 | * Throughput Mode: Every tx and rx packet will generate an interrupt. |
| 872 | * CPU Mode: Interrupts are controlled by a timer. |
| 873 | */ |
Ayaz Abdulla | 69fe3fd | 2006-06-10 22:48:18 -0400 | [diff] [blame] | 874 | enum { |
| 875 | NV_OPTIMIZATION_MODE_THROUGHPUT, |
Ayaz Abdulla | 9e18476 | 2009-03-05 08:02:18 +0000 | [diff] [blame] | 876 | NV_OPTIMIZATION_MODE_CPU, |
| 877 | NV_OPTIMIZATION_MODE_DYNAMIC |
Ayaz Abdulla | 69fe3fd | 2006-06-10 22:48:18 -0400 | [diff] [blame] | 878 | }; |
Ayaz Abdulla | 9e18476 | 2009-03-05 08:02:18 +0000 | [diff] [blame] | 879 | static int optimization_mode = NV_OPTIMIZATION_MODE_DYNAMIC; |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 880 | |
| 881 | /* |
| 882 | * Poll interval for timer irq |
| 883 | * |
| 884 | * This interval determines how frequent an interrupt is generated. |
| 885 | * The is value is determined by [(time_in_micro_secs * 100) / (2^10)] |
| 886 | * Min = 0, and Max = 65535 |
| 887 | */ |
| 888 | static int poll_interval = -1; |
| 889 | |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 890 | /* |
Ayaz Abdulla | 69fe3fd | 2006-06-10 22:48:18 -0400 | [diff] [blame] | 891 | * MSI interrupts |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 892 | */ |
Ayaz Abdulla | 69fe3fd | 2006-06-10 22:48:18 -0400 | [diff] [blame] | 893 | enum { |
| 894 | NV_MSI_INT_DISABLED, |
| 895 | NV_MSI_INT_ENABLED |
| 896 | }; |
| 897 | static int msi = NV_MSI_INT_ENABLED; |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 898 | |
| 899 | /* |
Ayaz Abdulla | 69fe3fd | 2006-06-10 22:48:18 -0400 | [diff] [blame] | 900 | * MSIX interrupts |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 901 | */ |
Ayaz Abdulla | 69fe3fd | 2006-06-10 22:48:18 -0400 | [diff] [blame] | 902 | enum { |
| 903 | NV_MSIX_INT_DISABLED, |
| 904 | NV_MSIX_INT_ENABLED |
| 905 | }; |
Yinghai Lu | 3948279 | 2009-02-06 01:31:12 -0800 | [diff] [blame] | 906 | static int msix = NV_MSIX_INT_ENABLED; |
Ayaz Abdulla | 69fe3fd | 2006-06-10 22:48:18 -0400 | [diff] [blame] | 907 | |
| 908 | /* |
| 909 | * DMA 64bit |
| 910 | */ |
| 911 | enum { |
| 912 | NV_DMA_64BIT_DISABLED, |
| 913 | NV_DMA_64BIT_ENABLED |
| 914 | }; |
| 915 | static int dma_64bit = NV_DMA_64BIT_ENABLED; |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 916 | |
Ayaz Abdulla | 9f3f791 | 2008-04-23 14:37:30 -0400 | [diff] [blame] | 917 | /* |
Sameer Nanda | 1ec4f2d | 2011-11-16 12:15:12 +0000 | [diff] [blame] | 918 | * Debug output control for tx_timeout |
| 919 | */ |
| 920 | static bool debug_tx_timeout = false; |
| 921 | |
| 922 | /* |
Ayaz Abdulla | 9f3f791 | 2008-04-23 14:37:30 -0400 | [diff] [blame] | 923 | * Crossover Detection |
| 924 | * Realtek 8201 phy + some OEM boards do not work properly. |
| 925 | */ |
| 926 | enum { |
| 927 | NV_CROSSOVER_DETECTION_DISABLED, |
| 928 | NV_CROSSOVER_DETECTION_ENABLED |
| 929 | }; |
| 930 | static int phy_cross = NV_CROSSOVER_DETECTION_DISABLED; |
| 931 | |
Ed Swierk | 5a9a8e3 | 2009-06-02 00:19:52 -0700 | [diff] [blame] | 932 | /* |
| 933 | * Power down phy when interface is down (persists through reboot; |
| 934 | * older Linux and other OSes may not power it up again) |
| 935 | */ |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 936 | static int phy_power_down; |
Ed Swierk | 5a9a8e3 | 2009-06-02 00:19:52 -0700 | [diff] [blame] | 937 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 938 | static inline struct fe_priv *get_nvpriv(struct net_device *dev) |
| 939 | { |
| 940 | return netdev_priv(dev); |
| 941 | } |
| 942 | |
| 943 | static inline u8 __iomem *get_hwbase(struct net_device *dev) |
| 944 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 945 | return ((struct fe_priv *)netdev_priv(dev))->base; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 946 | } |
| 947 | |
| 948 | static inline void pci_push(u8 __iomem *base) |
| 949 | { |
| 950 | /* force out pending posted writes */ |
| 951 | readl(base); |
| 952 | } |
| 953 | |
| 954 | static inline u32 nv_descr_getlength(struct ring_desc *prd, u32 v) |
| 955 | { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 956 | return le32_to_cpu(prd->flaglen) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | & ((v == DESC_VER_1) ? LEN_MASK_V1 : LEN_MASK_V2); |
| 958 | } |
| 959 | |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 960 | static inline u32 nv_descr_getlength_ex(struct ring_desc_ex *prd, u32 v) |
| 961 | { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 962 | return le32_to_cpu(prd->flaglen) & LEN_MASK_V2; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 963 | } |
| 964 | |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 965 | static bool nv_optimized(struct fe_priv *np) |
| 966 | { |
| 967 | if (np->desc_ver == DESC_VER_1 || np->desc_ver == DESC_VER_2) |
| 968 | return false; |
| 969 | return true; |
| 970 | } |
| 971 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | static int reg_delay(struct net_device *dev, int offset, u32 mask, u32 target, |
Joe Perches | 344d0dc | 2010-11-29 07:41:52 +0000 | [diff] [blame] | 973 | int delay, int delaymax) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | { |
| 975 | u8 __iomem *base = get_hwbase(dev); |
| 976 | |
| 977 | pci_push(base); |
| 978 | do { |
| 979 | udelay(delay); |
| 980 | delaymax -= delay; |
Joe Perches | 344d0dc | 2010-11-29 07:41:52 +0000 | [diff] [blame] | 981 | if (delaymax < 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 982 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | } while ((readl(base + offset) & mask) != target); |
| 984 | return 0; |
| 985 | } |
| 986 | |
Ayaz Abdulla | 0832b25 | 2006-02-04 13:13:26 -0500 | [diff] [blame] | 987 | #define NV_SETUP_RX_RING 0x01 |
| 988 | #define NV_SETUP_TX_RING 0x02 |
| 989 | |
Al Viro | 5bb7ea2 | 2007-12-09 16:06:41 +0000 | [diff] [blame] | 990 | static inline u32 dma_low(dma_addr_t addr) |
| 991 | { |
| 992 | return addr; |
| 993 | } |
| 994 | |
| 995 | static inline u32 dma_high(dma_addr_t addr) |
| 996 | { |
| 997 | return addr>>31>>1; /* 0 if 32bit, shift down by 32 if 64bit */ |
| 998 | } |
| 999 | |
Ayaz Abdulla | 0832b25 | 2006-02-04 13:13:26 -0500 | [diff] [blame] | 1000 | static void setup_hw_rings(struct net_device *dev, int rxtx_flags) |
| 1001 | { |
| 1002 | struct fe_priv *np = get_nvpriv(dev); |
| 1003 | u8 __iomem *base = get_hwbase(dev); |
| 1004 | |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 1005 | if (!nv_optimized(np)) { |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 1006 | if (rxtx_flags & NV_SETUP_RX_RING) |
Al Viro | 5bb7ea2 | 2007-12-09 16:06:41 +0000 | [diff] [blame] | 1007 | writel(dma_low(np->ring_addr), base + NvRegRxRingPhysAddr); |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 1008 | if (rxtx_flags & NV_SETUP_TX_RING) |
Al Viro | 5bb7ea2 | 2007-12-09 16:06:41 +0000 | [diff] [blame] | 1009 | writel(dma_low(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc)), base + NvRegTxRingPhysAddr); |
Ayaz Abdulla | 0832b25 | 2006-02-04 13:13:26 -0500 | [diff] [blame] | 1010 | } else { |
| 1011 | if (rxtx_flags & NV_SETUP_RX_RING) { |
Al Viro | 5bb7ea2 | 2007-12-09 16:06:41 +0000 | [diff] [blame] | 1012 | writel(dma_low(np->ring_addr), base + NvRegRxRingPhysAddr); |
| 1013 | writel(dma_high(np->ring_addr), base + NvRegRxRingPhysAddrHigh); |
Ayaz Abdulla | 0832b25 | 2006-02-04 13:13:26 -0500 | [diff] [blame] | 1014 | } |
| 1015 | if (rxtx_flags & NV_SETUP_TX_RING) { |
Al Viro | 5bb7ea2 | 2007-12-09 16:06:41 +0000 | [diff] [blame] | 1016 | writel(dma_low(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddr); |
| 1017 | writel(dma_high(np->ring_addr + np->rx_ring_size*sizeof(struct ring_desc_ex)), base + NvRegTxRingPhysAddrHigh); |
Ayaz Abdulla | 0832b25 | 2006-02-04 13:13:26 -0500 | [diff] [blame] | 1018 | } |
| 1019 | } |
| 1020 | } |
| 1021 | |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 1022 | static void free_rings(struct net_device *dev) |
| 1023 | { |
| 1024 | struct fe_priv *np = get_nvpriv(dev); |
| 1025 | |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 1026 | if (!nv_optimized(np)) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1027 | if (np->rx_ring.orig) |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 1028 | pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size), |
| 1029 | np->rx_ring.orig, np->ring_addr); |
| 1030 | } else { |
| 1031 | if (np->rx_ring.ex) |
| 1032 | pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size), |
| 1033 | np->rx_ring.ex, np->ring_addr); |
| 1034 | } |
Szymon Janc | 9b03b06 | 2010-11-27 08:39:44 +0000 | [diff] [blame] | 1035 | kfree(np->rx_skb); |
| 1036 | kfree(np->tx_skb); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 1037 | } |
| 1038 | |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 1039 | static int using_multi_irqs(struct net_device *dev) |
| 1040 | { |
| 1041 | struct fe_priv *np = get_nvpriv(dev); |
| 1042 | |
| 1043 | if (!(np->msi_flags & NV_MSI_X_ENABLED) || |
| 1044 | ((np->msi_flags & NV_MSI_X_ENABLED) && |
| 1045 | ((np->msi_flags & NV_MSI_X_VECTORS_MASK) == 0x1))) |
| 1046 | return 0; |
| 1047 | else |
| 1048 | return 1; |
| 1049 | } |
| 1050 | |
Ayaz Abdulla | 88d7d8b | 2009-05-01 01:41:50 +0000 | [diff] [blame] | 1051 | static void nv_txrx_gate(struct net_device *dev, bool gate) |
| 1052 | { |
| 1053 | struct fe_priv *np = get_nvpriv(dev); |
| 1054 | u8 __iomem *base = get_hwbase(dev); |
| 1055 | u32 powerstate; |
| 1056 | |
| 1057 | if (!np->mac_in_use && |
| 1058 | (np->driver_data & DEV_HAS_POWER_CNTRL)) { |
| 1059 | powerstate = readl(base + NvRegPowerState2); |
| 1060 | if (gate) |
| 1061 | powerstate |= NVREG_POWERSTATE2_GATE_CLOCKS; |
| 1062 | else |
| 1063 | powerstate &= ~NVREG_POWERSTATE2_GATE_CLOCKS; |
| 1064 | writel(powerstate, base + NvRegPowerState2); |
| 1065 | } |
| 1066 | } |
| 1067 | |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 1068 | static void nv_enable_irq(struct net_device *dev) |
| 1069 | { |
| 1070 | struct fe_priv *np = get_nvpriv(dev); |
| 1071 | |
| 1072 | if (!using_multi_irqs(dev)) { |
| 1073 | if (np->msi_flags & NV_MSI_X_ENABLED) |
| 1074 | enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector); |
| 1075 | else |
Manfred Spraul | a747590 | 2007-10-17 21:52:33 +0200 | [diff] [blame] | 1076 | enable_irq(np->pci_dev->irq); |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 1077 | } else { |
| 1078 | enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector); |
| 1079 | enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector); |
| 1080 | enable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector); |
| 1081 | } |
| 1082 | } |
| 1083 | |
| 1084 | static void nv_disable_irq(struct net_device *dev) |
| 1085 | { |
| 1086 | struct fe_priv *np = get_nvpriv(dev); |
| 1087 | |
| 1088 | if (!using_multi_irqs(dev)) { |
| 1089 | if (np->msi_flags & NV_MSI_X_ENABLED) |
| 1090 | disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector); |
| 1091 | else |
Manfred Spraul | a747590 | 2007-10-17 21:52:33 +0200 | [diff] [blame] | 1092 | disable_irq(np->pci_dev->irq); |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 1093 | } else { |
| 1094 | disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector); |
| 1095 | disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector); |
| 1096 | disable_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector); |
| 1097 | } |
| 1098 | } |
| 1099 | |
| 1100 | /* In MSIX mode, a write to irqmask behaves as XOR */ |
| 1101 | static void nv_enable_hw_interrupts(struct net_device *dev, u32 mask) |
| 1102 | { |
| 1103 | u8 __iomem *base = get_hwbase(dev); |
| 1104 | |
| 1105 | writel(mask, base + NvRegIrqMask); |
| 1106 | } |
| 1107 | |
| 1108 | static void nv_disable_hw_interrupts(struct net_device *dev, u32 mask) |
| 1109 | { |
| 1110 | struct fe_priv *np = get_nvpriv(dev); |
| 1111 | u8 __iomem *base = get_hwbase(dev); |
| 1112 | |
| 1113 | if (np->msi_flags & NV_MSI_X_ENABLED) { |
| 1114 | writel(mask, base + NvRegIrqMask); |
| 1115 | } else { |
| 1116 | if (np->msi_flags & NV_MSI_ENABLED) |
| 1117 | writel(0, base + NvRegMSIIrqMask); |
| 1118 | writel(0, base + NvRegIrqMask); |
| 1119 | } |
| 1120 | } |
| 1121 | |
Ayaz Abdulla | 08d9357 | 2009-03-05 08:01:55 +0000 | [diff] [blame] | 1122 | static void nv_napi_enable(struct net_device *dev) |
| 1123 | { |
Ayaz Abdulla | 08d9357 | 2009-03-05 08:01:55 +0000 | [diff] [blame] | 1124 | struct fe_priv *np = get_nvpriv(dev); |
| 1125 | |
| 1126 | napi_enable(&np->napi); |
Ayaz Abdulla | 08d9357 | 2009-03-05 08:01:55 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | static void nv_napi_disable(struct net_device *dev) |
| 1130 | { |
Ayaz Abdulla | 08d9357 | 2009-03-05 08:01:55 +0000 | [diff] [blame] | 1131 | struct fe_priv *np = get_nvpriv(dev); |
| 1132 | |
| 1133 | napi_disable(&np->napi); |
Ayaz Abdulla | 08d9357 | 2009-03-05 08:01:55 +0000 | [diff] [blame] | 1134 | } |
| 1135 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1136 | #define MII_READ (-1) |
| 1137 | /* mii_rw: read/write a register on the PHY. |
| 1138 | * |
| 1139 | * Caller must guarantee serialization |
| 1140 | */ |
| 1141 | static int mii_rw(struct net_device *dev, int addr, int miireg, int value) |
| 1142 | { |
| 1143 | u8 __iomem *base = get_hwbase(dev); |
| 1144 | u32 reg; |
| 1145 | int retval; |
| 1146 | |
Ayaz Abdulla | eb79842 | 2008-02-04 15:14:04 -0500 | [diff] [blame] | 1147 | writel(NVREG_MIISTAT_MASK_RW, base + NvRegMIIStatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1148 | |
| 1149 | reg = readl(base + NvRegMIIControl); |
| 1150 | if (reg & NVREG_MIICTL_INUSE) { |
| 1151 | writel(NVREG_MIICTL_INUSE, base + NvRegMIIControl); |
| 1152 | udelay(NV_MIIBUSY_DELAY); |
| 1153 | } |
| 1154 | |
| 1155 | reg = (addr << NVREG_MIICTL_ADDRSHIFT) | miireg; |
| 1156 | if (value != MII_READ) { |
| 1157 | writel(value, base + NvRegMIIData); |
| 1158 | reg |= NVREG_MIICTL_WRITE; |
| 1159 | } |
| 1160 | writel(reg, base + NvRegMIIControl); |
| 1161 | |
| 1162 | if (reg_delay(dev, NvRegMIIControl, NVREG_MIICTL_INUSE, 0, |
Joe Perches | 344d0dc | 2010-11-29 07:41:52 +0000 | [diff] [blame] | 1163 | NV_MIIPHY_DELAY, NV_MIIPHY_DELAYMAX)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | retval = -1; |
| 1165 | } else if (value != MII_READ) { |
| 1166 | /* it was a write operation - fewer failures are detectable */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1167 | retval = 0; |
| 1168 | } else if (readl(base + NvRegMIIStatus) & NVREG_MIISTAT_ERROR) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1169 | retval = -1; |
| 1170 | } else { |
| 1171 | retval = readl(base + NvRegMIIData); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1172 | } |
| 1173 | |
| 1174 | return retval; |
| 1175 | } |
| 1176 | |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 1177 | static int phy_reset(struct net_device *dev, u32 bmcr_setup) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1178 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1179 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1180 | u32 miicontrol; |
| 1181 | unsigned int tries = 0; |
| 1182 | |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 1183 | miicontrol = BMCR_RESET | bmcr_setup; |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 1184 | if (mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1185 | return -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | |
| 1187 | /* wait for 500ms */ |
| 1188 | msleep(500); |
| 1189 | |
| 1190 | /* must wait till reset is deasserted */ |
| 1191 | while (miicontrol & BMCR_RESET) { |
Szymon Janc | de855b9 | 2010-11-27 08:39:48 +0000 | [diff] [blame] | 1192 | usleep_range(10000, 20000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1193 | miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
| 1194 | /* FIXME: 100 tries seem excessive */ |
| 1195 | if (tries++ > 100) |
| 1196 | return -1; |
| 1197 | } |
| 1198 | return 0; |
| 1199 | } |
| 1200 | |
Joe Perches | c41d41e | 2010-11-29 07:41:58 +0000 | [diff] [blame] | 1201 | static int init_realtek_8211b(struct net_device *dev, struct fe_priv *np) |
| 1202 | { |
| 1203 | static const struct { |
| 1204 | int reg; |
| 1205 | int init; |
| 1206 | } ri[] = { |
| 1207 | { PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1 }, |
| 1208 | { PHY_REALTEK_INIT_REG2, PHY_REALTEK_INIT2 }, |
| 1209 | { PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3 }, |
| 1210 | { PHY_REALTEK_INIT_REG3, PHY_REALTEK_INIT4 }, |
| 1211 | { PHY_REALTEK_INIT_REG4, PHY_REALTEK_INIT5 }, |
| 1212 | { PHY_REALTEK_INIT_REG5, PHY_REALTEK_INIT6 }, |
| 1213 | { PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1 }, |
| 1214 | }; |
| 1215 | int i; |
| 1216 | |
| 1217 | for (i = 0; i < ARRAY_SIZE(ri); i++) { |
Joe Perches | cd66328 | 2010-11-29 07:41:59 +0000 | [diff] [blame] | 1218 | if (mii_rw(dev, np->phyaddr, ri[i].reg, ri[i].init)) |
Joe Perches | c41d41e | 2010-11-29 07:41:58 +0000 | [diff] [blame] | 1219 | return PHY_ERROR; |
Joe Perches | c41d41e | 2010-11-29 07:41:58 +0000 | [diff] [blame] | 1220 | } |
| 1221 | |
| 1222 | return 0; |
| 1223 | } |
| 1224 | |
Joe Perches | cd66328 | 2010-11-29 07:41:59 +0000 | [diff] [blame] | 1225 | static int init_realtek_8211c(struct net_device *dev, struct fe_priv *np) |
| 1226 | { |
| 1227 | u32 reg; |
| 1228 | u8 __iomem *base = get_hwbase(dev); |
| 1229 | u32 powerstate = readl(base + NvRegPowerState2); |
| 1230 | |
| 1231 | /* need to perform hw phy reset */ |
| 1232 | powerstate |= NVREG_POWERSTATE2_PHY_RESET; |
| 1233 | writel(powerstate, base + NvRegPowerState2); |
| 1234 | msleep(25); |
| 1235 | |
| 1236 | powerstate &= ~NVREG_POWERSTATE2_PHY_RESET; |
| 1237 | writel(powerstate, base + NvRegPowerState2); |
| 1238 | msleep(25); |
| 1239 | |
| 1240 | reg = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, MII_READ); |
| 1241 | reg |= PHY_REALTEK_INIT9; |
| 1242 | if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG6, reg)) |
| 1243 | return PHY_ERROR; |
| 1244 | if (mii_rw(dev, np->phyaddr, |
| 1245 | PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT10)) |
| 1246 | return PHY_ERROR; |
| 1247 | reg = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG7, MII_READ); |
| 1248 | if (!(reg & PHY_REALTEK_INIT11)) { |
| 1249 | reg |= PHY_REALTEK_INIT11; |
| 1250 | if (mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG7, reg)) |
| 1251 | return PHY_ERROR; |
| 1252 | } |
| 1253 | if (mii_rw(dev, np->phyaddr, |
| 1254 | PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) |
| 1255 | return PHY_ERROR; |
| 1256 | |
| 1257 | return 0; |
| 1258 | } |
| 1259 | |
| 1260 | static int init_realtek_8201(struct net_device *dev, struct fe_priv *np) |
| 1261 | { |
| 1262 | u32 phy_reserved; |
| 1263 | |
| 1264 | if (np->driver_data & DEV_NEED_PHY_INIT_FIX) { |
| 1265 | phy_reserved = mii_rw(dev, np->phyaddr, |
| 1266 | PHY_REALTEK_INIT_REG6, MII_READ); |
| 1267 | phy_reserved |= PHY_REALTEK_INIT7; |
| 1268 | if (mii_rw(dev, np->phyaddr, |
| 1269 | PHY_REALTEK_INIT_REG6, phy_reserved)) |
| 1270 | return PHY_ERROR; |
| 1271 | } |
| 1272 | |
| 1273 | return 0; |
| 1274 | } |
| 1275 | |
| 1276 | static int init_realtek_8201_cross(struct net_device *dev, struct fe_priv *np) |
| 1277 | { |
| 1278 | u32 phy_reserved; |
| 1279 | |
| 1280 | if (phy_cross == NV_CROSSOVER_DETECTION_DISABLED) { |
| 1281 | if (mii_rw(dev, np->phyaddr, |
| 1282 | PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3)) |
| 1283 | return PHY_ERROR; |
| 1284 | phy_reserved = mii_rw(dev, np->phyaddr, |
| 1285 | PHY_REALTEK_INIT_REG2, MII_READ); |
| 1286 | phy_reserved &= ~PHY_REALTEK_INIT_MSK1; |
| 1287 | phy_reserved |= PHY_REALTEK_INIT3; |
| 1288 | if (mii_rw(dev, np->phyaddr, |
| 1289 | PHY_REALTEK_INIT_REG2, phy_reserved)) |
| 1290 | return PHY_ERROR; |
| 1291 | if (mii_rw(dev, np->phyaddr, |
| 1292 | PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1)) |
| 1293 | return PHY_ERROR; |
| 1294 | } |
| 1295 | |
| 1296 | return 0; |
| 1297 | } |
| 1298 | |
| 1299 | static int init_cicada(struct net_device *dev, struct fe_priv *np, |
| 1300 | u32 phyinterface) |
| 1301 | { |
| 1302 | u32 phy_reserved; |
| 1303 | |
| 1304 | if (phyinterface & PHY_RGMII) { |
| 1305 | phy_reserved = mii_rw(dev, np->phyaddr, MII_RESV1, MII_READ); |
| 1306 | phy_reserved &= ~(PHY_CICADA_INIT1 | PHY_CICADA_INIT2); |
| 1307 | phy_reserved |= (PHY_CICADA_INIT3 | PHY_CICADA_INIT4); |
| 1308 | if (mii_rw(dev, np->phyaddr, MII_RESV1, phy_reserved)) |
| 1309 | return PHY_ERROR; |
| 1310 | phy_reserved = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ); |
| 1311 | phy_reserved |= PHY_CICADA_INIT5; |
| 1312 | if (mii_rw(dev, np->phyaddr, MII_NCONFIG, phy_reserved)) |
| 1313 | return PHY_ERROR; |
| 1314 | } |
| 1315 | phy_reserved = mii_rw(dev, np->phyaddr, MII_SREVISION, MII_READ); |
| 1316 | phy_reserved |= PHY_CICADA_INIT6; |
| 1317 | if (mii_rw(dev, np->phyaddr, MII_SREVISION, phy_reserved)) |
| 1318 | return PHY_ERROR; |
| 1319 | |
| 1320 | return 0; |
| 1321 | } |
| 1322 | |
| 1323 | static int init_vitesse(struct net_device *dev, struct fe_priv *np) |
| 1324 | { |
| 1325 | u32 phy_reserved; |
| 1326 | |
| 1327 | if (mii_rw(dev, np->phyaddr, |
| 1328 | PHY_VITESSE_INIT_REG1, PHY_VITESSE_INIT1)) |
| 1329 | return PHY_ERROR; |
| 1330 | if (mii_rw(dev, np->phyaddr, |
| 1331 | PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT2)) |
| 1332 | return PHY_ERROR; |
| 1333 | phy_reserved = mii_rw(dev, np->phyaddr, |
| 1334 | PHY_VITESSE_INIT_REG4, MII_READ); |
| 1335 | if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved)) |
| 1336 | return PHY_ERROR; |
| 1337 | phy_reserved = mii_rw(dev, np->phyaddr, |
| 1338 | PHY_VITESSE_INIT_REG3, MII_READ); |
| 1339 | phy_reserved &= ~PHY_VITESSE_INIT_MSK1; |
| 1340 | phy_reserved |= PHY_VITESSE_INIT3; |
| 1341 | if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved)) |
| 1342 | return PHY_ERROR; |
| 1343 | if (mii_rw(dev, np->phyaddr, |
| 1344 | PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT4)) |
| 1345 | return PHY_ERROR; |
| 1346 | if (mii_rw(dev, np->phyaddr, |
| 1347 | PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT5)) |
| 1348 | return PHY_ERROR; |
| 1349 | phy_reserved = mii_rw(dev, np->phyaddr, |
| 1350 | PHY_VITESSE_INIT_REG4, MII_READ); |
| 1351 | phy_reserved &= ~PHY_VITESSE_INIT_MSK1; |
| 1352 | phy_reserved |= PHY_VITESSE_INIT3; |
| 1353 | if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved)) |
| 1354 | return PHY_ERROR; |
| 1355 | phy_reserved = mii_rw(dev, np->phyaddr, |
| 1356 | PHY_VITESSE_INIT_REG3, MII_READ); |
| 1357 | if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved)) |
| 1358 | return PHY_ERROR; |
| 1359 | if (mii_rw(dev, np->phyaddr, |
| 1360 | PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT6)) |
| 1361 | return PHY_ERROR; |
| 1362 | if (mii_rw(dev, np->phyaddr, |
| 1363 | PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT7)) |
| 1364 | return PHY_ERROR; |
| 1365 | phy_reserved = mii_rw(dev, np->phyaddr, |
| 1366 | PHY_VITESSE_INIT_REG4, MII_READ); |
| 1367 | if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG4, phy_reserved)) |
| 1368 | return PHY_ERROR; |
| 1369 | phy_reserved = mii_rw(dev, np->phyaddr, |
| 1370 | PHY_VITESSE_INIT_REG3, MII_READ); |
| 1371 | phy_reserved &= ~PHY_VITESSE_INIT_MSK2; |
| 1372 | phy_reserved |= PHY_VITESSE_INIT8; |
| 1373 | if (mii_rw(dev, np->phyaddr, PHY_VITESSE_INIT_REG3, phy_reserved)) |
| 1374 | return PHY_ERROR; |
| 1375 | if (mii_rw(dev, np->phyaddr, |
| 1376 | PHY_VITESSE_INIT_REG2, PHY_VITESSE_INIT9)) |
| 1377 | return PHY_ERROR; |
| 1378 | if (mii_rw(dev, np->phyaddr, |
| 1379 | PHY_VITESSE_INIT_REG1, PHY_VITESSE_INIT10)) |
| 1380 | return PHY_ERROR; |
| 1381 | |
| 1382 | return 0; |
| 1383 | } |
| 1384 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1385 | static int phy_init(struct net_device *dev) |
| 1386 | { |
| 1387 | struct fe_priv *np = get_nvpriv(dev); |
| 1388 | u8 __iomem *base = get_hwbase(dev); |
Joe Perches | cd66328 | 2010-11-29 07:41:59 +0000 | [diff] [blame] | 1389 | u32 phyinterface; |
| 1390 | u32 mii_status, mii_control, mii_control_1000, reg; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1391 | |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 1392 | /* phy errata for E3016 phy */ |
| 1393 | if (np->phy_model == PHY_MODEL_MARVELL_E3016) { |
| 1394 | reg = mii_rw(dev, np->phyaddr, MII_NCONFIG, MII_READ); |
| 1395 | reg &= ~PHY_MARVELL_E3016_INITMASK; |
| 1396 | if (mii_rw(dev, np->phyaddr, MII_NCONFIG, reg)) { |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 1397 | netdev_info(dev, "%s: phy write to errata reg failed\n", |
| 1398 | pci_name(np->pci_dev)); |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 1399 | return PHY_ERROR; |
| 1400 | } |
| 1401 | } |
Ayaz Abdulla | c5e3ae8 | 2007-07-15 06:51:03 -0400 | [diff] [blame] | 1402 | if (np->phy_oui == PHY_OUI_REALTEK) { |
Ayaz Abdulla | 9f3f791 | 2008-04-23 14:37:30 -0400 | [diff] [blame] | 1403 | if (np->phy_model == PHY_MODEL_REALTEK_8211 && |
| 1404 | np->phy_rev == PHY_REV_REALTEK_8211B) { |
Joe Perches | cd66328 | 2010-11-29 07:41:59 +0000 | [diff] [blame] | 1405 | if (init_realtek_8211b(dev, np)) { |
| 1406 | netdev_info(dev, "%s: phy init failed\n", |
| 1407 | pci_name(np->pci_dev)); |
Ayaz Abdulla | 9f3f791 | 2008-04-23 14:37:30 -0400 | [diff] [blame] | 1408 | return PHY_ERROR; |
Joe Perches | cd66328 | 2010-11-29 07:41:59 +0000 | [diff] [blame] | 1409 | } |
Joe Perches | c41d41e | 2010-11-29 07:41:58 +0000 | [diff] [blame] | 1410 | } else if (np->phy_model == PHY_MODEL_REALTEK_8211 && |
| 1411 | np->phy_rev == PHY_REV_REALTEK_8211C) { |
Joe Perches | cd66328 | 2010-11-29 07:41:59 +0000 | [diff] [blame] | 1412 | if (init_realtek_8211c(dev, np)) { |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 1413 | netdev_info(dev, "%s: phy init failed\n", |
| 1414 | pci_name(np->pci_dev)); |
Ayaz Abdulla | 22ae03a | 2008-07-25 15:31:29 -0400 | [diff] [blame] | 1415 | return PHY_ERROR; |
| 1416 | } |
Joe Perches | cd66328 | 2010-11-29 07:41:59 +0000 | [diff] [blame] | 1417 | } else if (np->phy_model == PHY_MODEL_REALTEK_8201) { |
| 1418 | if (init_realtek_8201(dev, np)) { |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 1419 | netdev_info(dev, "%s: phy init failed\n", |
| 1420 | pci_name(np->pci_dev)); |
Ayaz Abdulla | 22ae03a | 2008-07-25 15:31:29 -0400 | [diff] [blame] | 1421 | return PHY_ERROR; |
| 1422 | } |
Ayaz Abdulla | c5e3ae8 | 2007-07-15 06:51:03 -0400 | [diff] [blame] | 1423 | } |
| 1424 | } |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 1425 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1426 | /* set advertise register */ |
| 1427 | reg = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ); |
Joe Perches | cd66328 | 2010-11-29 07:41:59 +0000 | [diff] [blame] | 1428 | reg |= (ADVERTISE_10HALF | ADVERTISE_10FULL | |
| 1429 | ADVERTISE_100HALF | ADVERTISE_100FULL | |
| 1430 | ADVERTISE_PAUSE_ASYM | ADVERTISE_PAUSE_CAP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1431 | if (mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg)) { |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 1432 | netdev_info(dev, "%s: phy write to advertise failed\n", |
| 1433 | pci_name(np->pci_dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1434 | return PHY_ERROR; |
| 1435 | } |
| 1436 | |
| 1437 | /* get phy interface type */ |
| 1438 | phyinterface = readl(base + NvRegPhyInterface); |
| 1439 | |
| 1440 | /* see if gigabit phy */ |
| 1441 | mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ); |
| 1442 | if (mii_status & PHY_GIGABIT) { |
| 1443 | np->gigabit = PHY_GIGABIT; |
Joe Perches | cd66328 | 2010-11-29 07:41:59 +0000 | [diff] [blame] | 1444 | mii_control_1000 = mii_rw(dev, np->phyaddr, |
| 1445 | MII_CTRL1000, MII_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | mii_control_1000 &= ~ADVERTISE_1000HALF; |
| 1447 | if (phyinterface & PHY_RGMII) |
| 1448 | mii_control_1000 |= ADVERTISE_1000FULL; |
| 1449 | else |
| 1450 | mii_control_1000 &= ~ADVERTISE_1000FULL; |
| 1451 | |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 1452 | if (mii_rw(dev, np->phyaddr, MII_CTRL1000, mii_control_1000)) { |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 1453 | netdev_info(dev, "%s: phy init failed\n", |
| 1454 | pci_name(np->pci_dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1455 | return PHY_ERROR; |
| 1456 | } |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 1457 | } else |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1458 | np->gigabit = 0; |
| 1459 | |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 1460 | mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
| 1461 | mii_control |= BMCR_ANENABLE; |
| 1462 | |
Ayaz Abdulla | 22ae03a | 2008-07-25 15:31:29 -0400 | [diff] [blame] | 1463 | if (np->phy_oui == PHY_OUI_REALTEK && |
| 1464 | np->phy_model == PHY_MODEL_REALTEK_8211 && |
| 1465 | np->phy_rev == PHY_REV_REALTEK_8211C) { |
| 1466 | /* start autoneg since we already performed hw reset above */ |
| 1467 | mii_control |= BMCR_ANRESTART; |
| 1468 | if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control)) { |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 1469 | netdev_info(dev, "%s: phy init failed\n", |
| 1470 | pci_name(np->pci_dev)); |
Ayaz Abdulla | 22ae03a | 2008-07-25 15:31:29 -0400 | [diff] [blame] | 1471 | return PHY_ERROR; |
| 1472 | } |
| 1473 | } else { |
| 1474 | /* reset the phy |
| 1475 | * (certain phys need bmcr to be setup with reset) |
| 1476 | */ |
| 1477 | if (phy_reset(dev, mii_control)) { |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 1478 | netdev_info(dev, "%s: phy reset failed\n", |
| 1479 | pci_name(np->pci_dev)); |
Ayaz Abdulla | 22ae03a | 2008-07-25 15:31:29 -0400 | [diff] [blame] | 1480 | return PHY_ERROR; |
| 1481 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1482 | } |
| 1483 | |
| 1484 | /* phy vendor specific configuration */ |
Joe Perches | cd66328 | 2010-11-29 07:41:59 +0000 | [diff] [blame] | 1485 | if ((np->phy_oui == PHY_OUI_CICADA)) { |
| 1486 | if (init_cicada(dev, np, phyinterface)) { |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 1487 | netdev_info(dev, "%s: phy init failed\n", |
| 1488 | pci_name(np->pci_dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1489 | return PHY_ERROR; |
| 1490 | } |
Joe Perches | cd66328 | 2010-11-29 07:41:59 +0000 | [diff] [blame] | 1491 | } else if (np->phy_oui == PHY_OUI_VITESSE) { |
| 1492 | if (init_vitesse(dev, np)) { |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 1493 | netdev_info(dev, "%s: phy init failed\n", |
| 1494 | pci_name(np->pci_dev)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1495 | return PHY_ERROR; |
| 1496 | } |
Joe Perches | cd66328 | 2010-11-29 07:41:59 +0000 | [diff] [blame] | 1497 | } else if (np->phy_oui == PHY_OUI_REALTEK) { |
Ayaz Abdulla | 9f3f791 | 2008-04-23 14:37:30 -0400 | [diff] [blame] | 1498 | if (np->phy_model == PHY_MODEL_REALTEK_8211 && |
| 1499 | np->phy_rev == PHY_REV_REALTEK_8211B) { |
| 1500 | /* reset could have cleared these out, set them back */ |
Joe Perches | cd66328 | 2010-11-29 07:41:59 +0000 | [diff] [blame] | 1501 | if (init_realtek_8211b(dev, np)) { |
| 1502 | netdev_info(dev, "%s: phy init failed\n", |
| 1503 | pci_name(np->pci_dev)); |
Ayaz Abdulla | 9f3f791 | 2008-04-23 14:37:30 -0400 | [diff] [blame] | 1504 | return PHY_ERROR; |
Ayaz Abdulla | 9f3f791 | 2008-04-23 14:37:30 -0400 | [diff] [blame] | 1505 | } |
Joe Perches | cd66328 | 2010-11-29 07:41:59 +0000 | [diff] [blame] | 1506 | } else if (np->phy_model == PHY_MODEL_REALTEK_8201) { |
| 1507 | if (init_realtek_8201(dev, np) || |
| 1508 | init_realtek_8201_cross(dev, np)) { |
| 1509 | netdev_info(dev, "%s: phy init failed\n", |
| 1510 | pci_name(np->pci_dev)); |
| 1511 | return PHY_ERROR; |
Ayaz Abdulla | 9f3f791 | 2008-04-23 14:37:30 -0400 | [diff] [blame] | 1512 | } |
Ayaz Abdulla | c5e3ae8 | 2007-07-15 06:51:03 -0400 | [diff] [blame] | 1513 | } |
| 1514 | } |
| 1515 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 1516 | /* some phys clear out pause advertisement on reset, set it back */ |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 1517 | mii_rw(dev, np->phyaddr, MII_ADVERTISE, reg); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1518 | |
Ed Swierk | cb52deb | 2008-12-01 12:24:43 +0000 | [diff] [blame] | 1519 | /* restart auto negotiation, power down phy */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
Ed Swierk | 5a9a8e3 | 2009-06-02 00:19:52 -0700 | [diff] [blame] | 1521 | mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE); |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 1522 | if (phy_power_down) |
Ed Swierk | 5a9a8e3 | 2009-06-02 00:19:52 -0700 | [diff] [blame] | 1523 | mii_control |= BMCR_PDOWN; |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 1524 | if (mii_rw(dev, np->phyaddr, MII_BMCR, mii_control)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | return PHY_ERROR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1526 | |
| 1527 | return 0; |
| 1528 | } |
| 1529 | |
| 1530 | static void nv_start_rx(struct net_device *dev) |
| 1531 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1532 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1533 | u8 __iomem *base = get_hwbase(dev); |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1534 | u32 rx_ctrl = readl(base + NvRegReceiverControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1535 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1536 | /* Already running? Stop it. */ |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1537 | if ((readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) && !np->mac_in_use) { |
| 1538 | rx_ctrl &= ~NVREG_RCVCTL_START; |
| 1539 | writel(rx_ctrl, base + NvRegReceiverControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | pci_push(base); |
| 1541 | } |
| 1542 | writel(np->linkspeed, base + NvRegLinkSpeed); |
| 1543 | pci_push(base); |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 1544 | rx_ctrl |= NVREG_RCVCTL_START; |
| 1545 | if (np->mac_in_use) |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1546 | rx_ctrl &= ~NVREG_RCVCTL_RX_PATH_EN; |
| 1547 | writel(rx_ctrl, base + NvRegReceiverControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1548 | pci_push(base); |
| 1549 | } |
| 1550 | |
| 1551 | static void nv_stop_rx(struct net_device *dev) |
| 1552 | { |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1553 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | u8 __iomem *base = get_hwbase(dev); |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1555 | u32 rx_ctrl = readl(base + NvRegReceiverControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1556 | |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1557 | if (!np->mac_in_use) |
| 1558 | rx_ctrl &= ~NVREG_RCVCTL_START; |
| 1559 | else |
| 1560 | rx_ctrl |= NVREG_RCVCTL_RX_PATH_EN; |
| 1561 | writel(rx_ctrl, base + NvRegReceiverControl); |
Joe Perches | 344d0dc | 2010-11-29 07:41:52 +0000 | [diff] [blame] | 1562 | if (reg_delay(dev, NvRegReceiverStatus, NVREG_RCVSTAT_BUSY, 0, |
| 1563 | NV_RXSTOP_DELAY1, NV_RXSTOP_DELAY1MAX)) |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 1564 | netdev_info(dev, "%s: ReceiverStatus remained busy\n", |
| 1565 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1566 | |
| 1567 | udelay(NV_RXSTOP_DELAY2); |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1568 | if (!np->mac_in_use) |
| 1569 | writel(0, base + NvRegLinkSpeed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | static void nv_start_tx(struct net_device *dev) |
| 1573 | { |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1574 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1575 | u8 __iomem *base = get_hwbase(dev); |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1576 | u32 tx_ctrl = readl(base + NvRegTransmitterControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1577 | |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1578 | tx_ctrl |= NVREG_XMITCTL_START; |
| 1579 | if (np->mac_in_use) |
| 1580 | tx_ctrl &= ~NVREG_XMITCTL_TX_PATH_EN; |
| 1581 | writel(tx_ctrl, base + NvRegTransmitterControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | pci_push(base); |
| 1583 | } |
| 1584 | |
| 1585 | static void nv_stop_tx(struct net_device *dev) |
| 1586 | { |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1587 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1588 | u8 __iomem *base = get_hwbase(dev); |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1589 | u32 tx_ctrl = readl(base + NvRegTransmitterControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1591 | if (!np->mac_in_use) |
| 1592 | tx_ctrl &= ~NVREG_XMITCTL_START; |
| 1593 | else |
| 1594 | tx_ctrl |= NVREG_XMITCTL_TX_PATH_EN; |
| 1595 | writel(tx_ctrl, base + NvRegTransmitterControl); |
Joe Perches | 344d0dc | 2010-11-29 07:41:52 +0000 | [diff] [blame] | 1596 | if (reg_delay(dev, NvRegTransmitterStatus, NVREG_XMITSTAT_BUSY, 0, |
| 1597 | NV_TXSTOP_DELAY1, NV_TXSTOP_DELAY1MAX)) |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 1598 | netdev_info(dev, "%s: TransmitterStatus remained busy\n", |
| 1599 | __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1600 | |
| 1601 | udelay(NV_TXSTOP_DELAY2); |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 1602 | if (!np->mac_in_use) |
| 1603 | writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV, |
| 1604 | base + NvRegTransmitPoll); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1605 | } |
| 1606 | |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 1607 | static void nv_start_rxtx(struct net_device *dev) |
| 1608 | { |
| 1609 | nv_start_rx(dev); |
| 1610 | nv_start_tx(dev); |
| 1611 | } |
| 1612 | |
| 1613 | static void nv_stop_rxtx(struct net_device *dev) |
| 1614 | { |
| 1615 | nv_stop_rx(dev); |
| 1616 | nv_stop_tx(dev); |
| 1617 | } |
| 1618 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1619 | static void nv_txrx_reset(struct net_device *dev) |
| 1620 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1621 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1622 | u8 __iomem *base = get_hwbase(dev); |
| 1623 | |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 1624 | writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1625 | pci_push(base); |
| 1626 | udelay(NV_TXRX_RESET_DELAY); |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 1627 | writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1628 | pci_push(base); |
| 1629 | } |
| 1630 | |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 1631 | static void nv_mac_reset(struct net_device *dev) |
| 1632 | { |
| 1633 | struct fe_priv *np = netdev_priv(dev); |
| 1634 | u8 __iomem *base = get_hwbase(dev); |
Ayaz Abdulla | 4e84f9b | 2008-02-04 15:14:09 -0500 | [diff] [blame] | 1635 | u32 temp1, temp2, temp3; |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 1636 | |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 1637 | writel(NVREG_TXRXCTL_BIT2 | NVREG_TXRXCTL_RESET | np->txrxctl_bits, base + NvRegTxRxControl); |
| 1638 | pci_push(base); |
Ayaz Abdulla | 4e84f9b | 2008-02-04 15:14:09 -0500 | [diff] [blame] | 1639 | |
| 1640 | /* save registers since they will be cleared on reset */ |
| 1641 | temp1 = readl(base + NvRegMacAddrA); |
| 1642 | temp2 = readl(base + NvRegMacAddrB); |
| 1643 | temp3 = readl(base + NvRegTransmitPoll); |
| 1644 | |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 1645 | writel(NVREG_MAC_RESET_ASSERT, base + NvRegMacReset); |
| 1646 | pci_push(base); |
| 1647 | udelay(NV_MAC_RESET_DELAY); |
| 1648 | writel(0, base + NvRegMacReset); |
| 1649 | pci_push(base); |
| 1650 | udelay(NV_MAC_RESET_DELAY); |
Ayaz Abdulla | 4e84f9b | 2008-02-04 15:14:09 -0500 | [diff] [blame] | 1651 | |
| 1652 | /* restore saved registers */ |
| 1653 | writel(temp1, base + NvRegMacAddrA); |
| 1654 | writel(temp2, base + NvRegMacAddrB); |
| 1655 | writel(temp3, base + NvRegTransmitPoll); |
| 1656 | |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 1657 | writel(NVREG_TXRXCTL_BIT2 | np->txrxctl_bits, base + NvRegTxRxControl); |
| 1658 | pci_push(base); |
| 1659 | } |
| 1660 | |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 1661 | /* Caller must appropriately lock netdev_priv(dev)->hwstats_lock */ |
| 1662 | static void nv_update_stats(struct net_device *dev) |
Ayaz Abdulla | 57fff69 | 2007-01-23 12:27:00 -0500 | [diff] [blame] | 1663 | { |
| 1664 | struct fe_priv *np = netdev_priv(dev); |
| 1665 | u8 __iomem *base = get_hwbase(dev); |
| 1666 | |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 1667 | /* If it happens that this is run in top-half context, then |
| 1668 | * replace the spin_lock of hwstats_lock with |
| 1669 | * spin_lock_irqsave() in calling functions. */ |
| 1670 | WARN_ONCE(in_irq(), "forcedeth: estats spin_lock(_bh) from top-half"); |
| 1671 | assert_spin_locked(&np->hwstats_lock); |
| 1672 | |
| 1673 | /* query hardware */ |
Ayaz Abdulla | 57fff69 | 2007-01-23 12:27:00 -0500 | [diff] [blame] | 1674 | np->estats.tx_bytes += readl(base + NvRegTxCnt); |
| 1675 | np->estats.tx_zero_rexmt += readl(base + NvRegTxZeroReXmt); |
| 1676 | np->estats.tx_one_rexmt += readl(base + NvRegTxOneReXmt); |
| 1677 | np->estats.tx_many_rexmt += readl(base + NvRegTxManyReXmt); |
| 1678 | np->estats.tx_late_collision += readl(base + NvRegTxLateCol); |
| 1679 | np->estats.tx_fifo_errors += readl(base + NvRegTxUnderflow); |
| 1680 | np->estats.tx_carrier_errors += readl(base + NvRegTxLossCarrier); |
| 1681 | np->estats.tx_excess_deferral += readl(base + NvRegTxExcessDef); |
| 1682 | np->estats.tx_retry_error += readl(base + NvRegTxRetryErr); |
| 1683 | np->estats.rx_frame_error += readl(base + NvRegRxFrameErr); |
| 1684 | np->estats.rx_extra_byte += readl(base + NvRegRxExtraByte); |
| 1685 | np->estats.rx_late_collision += readl(base + NvRegRxLateCol); |
| 1686 | np->estats.rx_runt += readl(base + NvRegRxRunt); |
| 1687 | np->estats.rx_frame_too_long += readl(base + NvRegRxFrameTooLong); |
| 1688 | np->estats.rx_over_errors += readl(base + NvRegRxOverflow); |
| 1689 | np->estats.rx_crc_errors += readl(base + NvRegRxFCSErr); |
| 1690 | np->estats.rx_frame_align_error += readl(base + NvRegRxFrameAlignErr); |
| 1691 | np->estats.rx_length_error += readl(base + NvRegRxLenErr); |
| 1692 | np->estats.rx_unicast += readl(base + NvRegRxUnicast); |
| 1693 | np->estats.rx_multicast += readl(base + NvRegRxMulticast); |
| 1694 | np->estats.rx_broadcast += readl(base + NvRegRxBroadcast); |
| 1695 | np->estats.rx_packets = |
| 1696 | np->estats.rx_unicast + |
| 1697 | np->estats.rx_multicast + |
| 1698 | np->estats.rx_broadcast; |
| 1699 | np->estats.rx_errors_total = |
| 1700 | np->estats.rx_crc_errors + |
| 1701 | np->estats.rx_over_errors + |
| 1702 | np->estats.rx_frame_error + |
| 1703 | (np->estats.rx_frame_align_error - np->estats.rx_extra_byte) + |
| 1704 | np->estats.rx_late_collision + |
| 1705 | np->estats.rx_runt + |
| 1706 | np->estats.rx_frame_too_long; |
| 1707 | np->estats.tx_errors_total = |
| 1708 | np->estats.tx_late_collision + |
| 1709 | np->estats.tx_fifo_errors + |
| 1710 | np->estats.tx_carrier_errors + |
| 1711 | np->estats.tx_excess_deferral + |
| 1712 | np->estats.tx_retry_error; |
| 1713 | |
| 1714 | if (np->driver_data & DEV_HAS_STATISTICS_V2) { |
| 1715 | np->estats.tx_deferral += readl(base + NvRegTxDef); |
| 1716 | np->estats.tx_packets += readl(base + NvRegTxFrame); |
| 1717 | np->estats.rx_bytes += readl(base + NvRegRxCnt); |
| 1718 | np->estats.tx_pause += readl(base + NvRegTxPause); |
| 1719 | np->estats.rx_pause += readl(base + NvRegRxPause); |
| 1720 | np->estats.rx_drop_frame += readl(base + NvRegRxDropFrame); |
Mandeep Baines | 0bdfea8 | 2011-11-05 14:38:23 +0000 | [diff] [blame] | 1721 | np->estats.rx_errors_total += np->estats.rx_drop_frame; |
Ayaz Abdulla | 57fff69 | 2007-01-23 12:27:00 -0500 | [diff] [blame] | 1722 | } |
Ayaz Abdulla | 9c66243 | 2008-08-06 12:11:42 -0400 | [diff] [blame] | 1723 | |
| 1724 | if (np->driver_data & DEV_HAS_STATISTICS_V3) { |
| 1725 | np->estats.tx_unicast += readl(base + NvRegTxUnicast); |
| 1726 | np->estats.tx_multicast += readl(base + NvRegTxMulticast); |
| 1727 | np->estats.tx_broadcast += readl(base + NvRegTxBroadcast); |
| 1728 | } |
Ayaz Abdulla | 57fff69 | 2007-01-23 12:27:00 -0500 | [diff] [blame] | 1729 | } |
| 1730 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1731 | /* |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 1732 | * nv_get_stats64: dev->ndo_get_stats64 function |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1733 | * Get latest stats value from the nic. |
| 1734 | * Called with read_lock(&dev_base_lock) held for read - |
| 1735 | * only synchronized against unregister_netdevice. |
| 1736 | */ |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 1737 | static struct rtnl_link_stats64* |
| 1738 | nv_get_stats64(struct net_device *dev, struct rtnl_link_stats64 *storage) |
| 1739 | __acquires(&netdev_priv(dev)->hwstats_lock) |
| 1740 | __releases(&netdev_priv(dev)->hwstats_lock) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1741 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1742 | struct fe_priv *np = netdev_priv(dev); |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 1743 | unsigned int syncp_start; |
| 1744 | |
| 1745 | /* |
| 1746 | * Note: because HW stats are not always available and for |
| 1747 | * consistency reasons, the following ifconfig stats are |
| 1748 | * managed by software: rx_bytes, tx_bytes, rx_packets and |
| 1749 | * tx_packets. The related hardware stats reported by ethtool |
| 1750 | * should be equivalent to these ifconfig stats, with 4 |
| 1751 | * additional bytes per packet (Ethernet FCS CRC), except for |
| 1752 | * tx_packets when TSO kicks in. |
| 1753 | */ |
| 1754 | |
| 1755 | /* software stats */ |
| 1756 | do { |
david decotigny | 505a467 | 2011-11-17 09:38:23 +0000 | [diff] [blame] | 1757 | syncp_start = u64_stats_fetch_begin_bh(&np->swstats_rx_syncp); |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 1758 | storage->rx_packets = np->stat_rx_packets; |
| 1759 | storage->rx_bytes = np->stat_rx_bytes; |
david decotigny | 0a1f222 | 2011-11-16 12:15:14 +0000 | [diff] [blame] | 1760 | storage->rx_dropped = np->stat_rx_dropped; |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 1761 | storage->rx_missed_errors = np->stat_rx_missed_errors; |
david decotigny | 505a467 | 2011-11-17 09:38:23 +0000 | [diff] [blame] | 1762 | } while (u64_stats_fetch_retry_bh(&np->swstats_rx_syncp, syncp_start)); |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 1763 | |
| 1764 | do { |
david decotigny | 505a467 | 2011-11-17 09:38:23 +0000 | [diff] [blame] | 1765 | syncp_start = u64_stats_fetch_begin_bh(&np->swstats_tx_syncp); |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 1766 | storage->tx_packets = np->stat_tx_packets; |
| 1767 | storage->tx_bytes = np->stat_tx_bytes; |
| 1768 | storage->tx_dropped = np->stat_tx_dropped; |
david decotigny | 505a467 | 2011-11-17 09:38:23 +0000 | [diff] [blame] | 1769 | } while (u64_stats_fetch_retry_bh(&np->swstats_tx_syncp, syncp_start)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1770 | |
Ayaz Abdulla | 2182816 | 2007-01-23 12:27:21 -0500 | [diff] [blame] | 1771 | /* If the nic supports hw counters then retrieve latest values */ |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 1772 | if (np->driver_data & DEV_HAS_STATISTICS_V123) { |
| 1773 | spin_lock_bh(&np->hwstats_lock); |
Ayaz Abdulla | 2182816 | 2007-01-23 12:27:21 -0500 | [diff] [blame] | 1774 | |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 1775 | nv_update_stats(dev); |
david decotigny | 674aee3 | 2011-11-16 12:15:07 +0000 | [diff] [blame] | 1776 | |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 1777 | /* generic stats */ |
| 1778 | storage->rx_errors = np->estats.rx_errors_total; |
| 1779 | storage->tx_errors = np->estats.tx_errors_total; |
| 1780 | |
| 1781 | /* meaningful only when NIC supports stats v3 */ |
| 1782 | storage->multicast = np->estats.rx_multicast; |
| 1783 | |
| 1784 | /* detailed rx_errors */ |
| 1785 | storage->rx_length_errors = np->estats.rx_length_error; |
| 1786 | storage->rx_over_errors = np->estats.rx_over_errors; |
| 1787 | storage->rx_crc_errors = np->estats.rx_crc_errors; |
| 1788 | storage->rx_frame_errors = np->estats.rx_frame_align_error; |
| 1789 | storage->rx_fifo_errors = np->estats.rx_drop_frame; |
| 1790 | |
| 1791 | /* detailed tx_errors */ |
| 1792 | storage->tx_carrier_errors = np->estats.tx_carrier_errors; |
| 1793 | storage->tx_fifo_errors = np->estats.tx_fifo_errors; |
| 1794 | |
| 1795 | spin_unlock_bh(&np->hwstats_lock); |
Ayaz Abdulla | 2182816 | 2007-01-23 12:27:21 -0500 | [diff] [blame] | 1796 | } |
Jeff Garzik | 8148ff4 | 2007-10-16 20:56:09 -0400 | [diff] [blame] | 1797 | |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 1798 | return storage; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1799 | } |
| 1800 | |
| 1801 | /* |
| 1802 | * nv_alloc_rx: fill rx ring entries. |
| 1803 | * Return 1 if the allocations for the skbs failed and the |
| 1804 | * rx engine is without Available descriptors |
| 1805 | */ |
| 1806 | static int nv_alloc_rx(struct net_device *dev) |
| 1807 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1808 | struct fe_priv *np = netdev_priv(dev); |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 1809 | struct ring_desc *less_rx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1810 | |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1811 | less_rx = np->get_rx.orig; |
| 1812 | if (less_rx-- == np->first_rx.orig) |
| 1813 | less_rx = np->last_rx.orig; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1814 | |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1815 | while (np->put_rx.orig != less_rx) { |
Pradeep A. Dalvi | dae2e9f | 2012-02-06 11:16:13 +0000 | [diff] [blame] | 1816 | struct sk_buff *skb = netdev_alloc_skb(dev, np->rx_buf_sz + NV_RX_ALLOC_PAD); |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 1817 | if (skb) { |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1818 | np->put_rx_ctx->skb = skb; |
Arnaldo Carvalho de Melo | 4305b54 | 2007-04-19 20:43:29 -0700 | [diff] [blame] | 1819 | np->put_rx_ctx->dma = pci_map_single(np->pci_dev, |
| 1820 | skb->data, |
Arnaldo Carvalho de Melo | 8b5be26 | 2007-03-20 12:08:20 -0300 | [diff] [blame] | 1821 | skb_tailroom(skb), |
Arnaldo Carvalho de Melo | 4305b54 | 2007-04-19 20:43:29 -0700 | [diff] [blame] | 1822 | PCI_DMA_FROMDEVICE); |
Larry Finger | 612a7c4 | 2012-12-27 17:25:41 +0000 | [diff] [blame] | 1823 | if (pci_dma_mapping_error(np->pci_dev, |
| 1824 | np->put_rx_ctx->dma)) { |
| 1825 | kfree_skb(skb); |
| 1826 | goto packet_dropped; |
| 1827 | } |
Arnaldo Carvalho de Melo | 8b5be26 | 2007-03-20 12:08:20 -0300 | [diff] [blame] | 1828 | np->put_rx_ctx->dma_len = skb_tailroom(skb); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1829 | np->put_rx.orig->buf = cpu_to_le32(np->put_rx_ctx->dma); |
| 1830 | wmb(); |
| 1831 | np->put_rx.orig->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX_AVAIL); |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 1832 | if (unlikely(np->put_rx.orig++ == np->last_rx.orig)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1833 | np->put_rx.orig = np->first_rx.orig; |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 1834 | if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1835 | np->put_rx_ctx = np->first_rx_ctx; |
david decotigny | 0a1f222 | 2011-11-16 12:15:14 +0000 | [diff] [blame] | 1836 | } else { |
Larry Finger | 612a7c4 | 2012-12-27 17:25:41 +0000 | [diff] [blame] | 1837 | packet_dropped: |
david decotigny | 0a1f222 | 2011-11-16 12:15:14 +0000 | [diff] [blame] | 1838 | u64_stats_update_begin(&np->swstats_rx_syncp); |
| 1839 | np->stat_rx_dropped++; |
| 1840 | u64_stats_update_end(&np->swstats_rx_syncp); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1841 | return 1; |
david decotigny | 0a1f222 | 2011-11-16 12:15:14 +0000 | [diff] [blame] | 1842 | } |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1843 | } |
| 1844 | return 0; |
| 1845 | } |
| 1846 | |
| 1847 | static int nv_alloc_rx_optimized(struct net_device *dev) |
| 1848 | { |
| 1849 | struct fe_priv *np = netdev_priv(dev); |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 1850 | struct ring_desc_ex *less_rx; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1851 | |
| 1852 | less_rx = np->get_rx.ex; |
| 1853 | if (less_rx-- == np->first_rx.ex) |
| 1854 | less_rx = np->last_rx.ex; |
| 1855 | |
| 1856 | while (np->put_rx.ex != less_rx) { |
Pradeep A. Dalvi | dae2e9f | 2012-02-06 11:16:13 +0000 | [diff] [blame] | 1857 | struct sk_buff *skb = netdev_alloc_skb(dev, np->rx_buf_sz + NV_RX_ALLOC_PAD); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1858 | if (skb) { |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1859 | np->put_rx_ctx->skb = skb; |
Arnaldo Carvalho de Melo | 4305b54 | 2007-04-19 20:43:29 -0700 | [diff] [blame] | 1860 | np->put_rx_ctx->dma = pci_map_single(np->pci_dev, |
| 1861 | skb->data, |
Arnaldo Carvalho de Melo | 8b5be26 | 2007-03-20 12:08:20 -0300 | [diff] [blame] | 1862 | skb_tailroom(skb), |
Arnaldo Carvalho de Melo | 4305b54 | 2007-04-19 20:43:29 -0700 | [diff] [blame] | 1863 | PCI_DMA_FROMDEVICE); |
Larry Finger | 612a7c4 | 2012-12-27 17:25:41 +0000 | [diff] [blame] | 1864 | if (pci_dma_mapping_error(np->pci_dev, |
| 1865 | np->put_rx_ctx->dma)) { |
| 1866 | kfree_skb(skb); |
| 1867 | goto packet_dropped; |
| 1868 | } |
Arnaldo Carvalho de Melo | 8b5be26 | 2007-03-20 12:08:20 -0300 | [diff] [blame] | 1869 | np->put_rx_ctx->dma_len = skb_tailroom(skb); |
Al Viro | 5bb7ea2 | 2007-12-09 16:06:41 +0000 | [diff] [blame] | 1870 | np->put_rx.ex->bufhigh = cpu_to_le32(dma_high(np->put_rx_ctx->dma)); |
| 1871 | np->put_rx.ex->buflow = cpu_to_le32(dma_low(np->put_rx_ctx->dma)); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1872 | wmb(); |
| 1873 | np->put_rx.ex->flaglen = cpu_to_le32(np->rx_buf_sz | NV_RX2_AVAIL); |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 1874 | if (unlikely(np->put_rx.ex++ == np->last_rx.ex)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1875 | np->put_rx.ex = np->first_rx.ex; |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 1876 | if (unlikely(np->put_rx_ctx++ == np->last_rx_ctx)) |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 1877 | np->put_rx_ctx = np->first_rx_ctx; |
david decotigny | 0a1f222 | 2011-11-16 12:15:14 +0000 | [diff] [blame] | 1878 | } else { |
Larry Finger | 612a7c4 | 2012-12-27 17:25:41 +0000 | [diff] [blame] | 1879 | packet_dropped: |
david decotigny | 0a1f222 | 2011-11-16 12:15:14 +0000 | [diff] [blame] | 1880 | u64_stats_update_begin(&np->swstats_rx_syncp); |
| 1881 | np->stat_rx_dropped++; |
| 1882 | u64_stats_update_end(&np->swstats_rx_syncp); |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 1883 | return 1; |
david decotigny | 0a1f222 | 2011-11-16 12:15:14 +0000 | [diff] [blame] | 1884 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1885 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1886 | return 0; |
| 1887 | } |
| 1888 | |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 1889 | /* If rx bufs are exhausted called after 50ms to attempt to refresh */ |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 1890 | static void nv_do_rx_refill(unsigned long data) |
| 1891 | { |
| 1892 | struct net_device *dev = (struct net_device *) data; |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 1893 | struct fe_priv *np = netdev_priv(dev); |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 1894 | |
| 1895 | /* Just reschedule NAPI rx processing */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1896 | napi_schedule(&np->napi); |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 1897 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1898 | |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 1899 | static void nv_init_rx(struct net_device *dev) |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 1900 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1901 | struct fe_priv *np = netdev_priv(dev); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 1902 | int i; |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 1903 | |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1904 | np->get_rx = np->put_rx = np->first_rx = np->rx_ring; |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 1905 | |
| 1906 | if (!nv_optimized(np)) |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1907 | np->last_rx.orig = &np->rx_ring.orig[np->rx_ring_size-1]; |
| 1908 | else |
| 1909 | np->last_rx.ex = &np->rx_ring.ex[np->rx_ring_size-1]; |
| 1910 | np->get_rx_ctx = np->put_rx_ctx = np->first_rx_ctx = np->rx_skb; |
| 1911 | np->last_rx_ctx = &np->rx_skb[np->rx_ring_size-1]; |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 1912 | |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1913 | for (i = 0; i < np->rx_ring_size; i++) { |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 1914 | if (!nv_optimized(np)) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1915 | np->rx_ring.orig[i].flaglen = 0; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1916 | np->rx_ring.orig[i].buf = 0; |
| 1917 | } else { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1918 | np->rx_ring.ex[i].flaglen = 0; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1919 | np->rx_ring.ex[i].txvlan = 0; |
| 1920 | np->rx_ring.ex[i].bufhigh = 0; |
| 1921 | np->rx_ring.ex[i].buflow = 0; |
| 1922 | } |
| 1923 | np->rx_skb[i].skb = NULL; |
| 1924 | np->rx_skb[i].dma = 0; |
| 1925 | } |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 1926 | } |
| 1927 | |
| 1928 | static void nv_init_tx(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1929 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1930 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1931 | int i; |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 1932 | |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1933 | np->get_tx = np->put_tx = np->first_tx = np->tx_ring; |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 1934 | |
| 1935 | if (!nv_optimized(np)) |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1936 | np->last_tx.orig = &np->tx_ring.orig[np->tx_ring_size-1]; |
| 1937 | else |
| 1938 | np->last_tx.ex = &np->tx_ring.ex[np->tx_ring_size-1]; |
| 1939 | np->get_tx_ctx = np->put_tx_ctx = np->first_tx_ctx = np->tx_skb; |
| 1940 | np->last_tx_ctx = &np->tx_skb[np->tx_ring_size-1]; |
Tom Herbert | b8bfca9 | 2011-11-28 16:33:23 +0000 | [diff] [blame] | 1941 | netdev_reset_queue(np->dev); |
Ayaz Abdulla | 3b446c3 | 2008-03-10 14:58:21 -0500 | [diff] [blame] | 1942 | np->tx_pkts_in_progress = 0; |
| 1943 | np->tx_change_owner = NULL; |
| 1944 | np->tx_end_flip = NULL; |
Ayaz Abdulla | 8f955d7 | 2009-04-25 09:17:56 +0000 | [diff] [blame] | 1945 | np->tx_stop = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1946 | |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 1947 | for (i = 0; i < np->tx_ring_size; i++) { |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 1948 | if (!nv_optimized(np)) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1949 | np->tx_ring.orig[i].flaglen = 0; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1950 | np->tx_ring.orig[i].buf = 0; |
| 1951 | } else { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 1952 | np->tx_ring.ex[i].flaglen = 0; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1953 | np->tx_ring.ex[i].txvlan = 0; |
| 1954 | np->tx_ring.ex[i].bufhigh = 0; |
| 1955 | np->tx_ring.ex[i].buflow = 0; |
| 1956 | } |
| 1957 | np->tx_skb[i].skb = NULL; |
| 1958 | np->tx_skb[i].dma = 0; |
Ayaz Abdulla | 3b446c3 | 2008-03-10 14:58:21 -0500 | [diff] [blame] | 1959 | np->tx_skb[i].dma_len = 0; |
Eric Dumazet | 73a3707 | 2009-06-17 21:17:59 +0000 | [diff] [blame] | 1960 | np->tx_skb[i].dma_single = 0; |
Ayaz Abdulla | 3b446c3 | 2008-03-10 14:58:21 -0500 | [diff] [blame] | 1961 | np->tx_skb[i].first_tx_desc = NULL; |
| 1962 | np->tx_skb[i].next_tx_ctx = NULL; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1963 | } |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 1964 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1965 | |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 1966 | static int nv_init_ring(struct net_device *dev) |
| 1967 | { |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1968 | struct fe_priv *np = netdev_priv(dev); |
| 1969 | |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 1970 | nv_init_tx(dev); |
| 1971 | nv_init_rx(dev); |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 1972 | |
| 1973 | if (!nv_optimized(np)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 1974 | return nv_alloc_rx(dev); |
| 1975 | else |
| 1976 | return nv_alloc_rx_optimized(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1977 | } |
| 1978 | |
Eric Dumazet | 73a3707 | 2009-06-17 21:17:59 +0000 | [diff] [blame] | 1979 | static void nv_unmap_txskb(struct fe_priv *np, struct nv_skb_map *tx_skb) |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1980 | { |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1981 | if (tx_skb->dma) { |
Eric Dumazet | 73a3707 | 2009-06-17 21:17:59 +0000 | [diff] [blame] | 1982 | if (tx_skb->dma_single) |
| 1983 | pci_unmap_single(np->pci_dev, tx_skb->dma, |
| 1984 | tx_skb->dma_len, |
| 1985 | PCI_DMA_TODEVICE); |
| 1986 | else |
| 1987 | pci_unmap_page(np->pci_dev, tx_skb->dma, |
| 1988 | tx_skb->dma_len, |
| 1989 | PCI_DMA_TODEVICE); |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1990 | tx_skb->dma = 0; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 1991 | } |
Eric Dumazet | 73a3707 | 2009-06-17 21:17:59 +0000 | [diff] [blame] | 1992 | } |
| 1993 | |
| 1994 | static int nv_release_txskb(struct fe_priv *np, struct nv_skb_map *tx_skb) |
| 1995 | { |
| 1996 | nv_unmap_txskb(np, tx_skb); |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 1997 | if (tx_skb->skb) { |
| 1998 | dev_kfree_skb_any(tx_skb->skb); |
| 1999 | tx_skb->skb = NULL; |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 2000 | return 1; |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 2001 | } |
Eric Dumazet | 73a3707 | 2009-06-17 21:17:59 +0000 | [diff] [blame] | 2002 | return 0; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2003 | } |
| 2004 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2005 | static void nv_drain_tx(struct net_device *dev) |
| 2006 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2007 | struct fe_priv *np = netdev_priv(dev); |
| 2008 | unsigned int i; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 2009 | |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 2010 | for (i = 0; i < np->tx_ring_size; i++) { |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 2011 | if (!nv_optimized(np)) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2012 | np->tx_ring.orig[i].flaglen = 0; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2013 | np->tx_ring.orig[i].buf = 0; |
| 2014 | } else { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2015 | np->tx_ring.ex[i].flaglen = 0; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2016 | np->tx_ring.ex[i].txvlan = 0; |
| 2017 | np->tx_ring.ex[i].bufhigh = 0; |
| 2018 | np->tx_ring.ex[i].buflow = 0; |
| 2019 | } |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 2020 | if (nv_release_txskb(np, &np->tx_skb[i])) { |
| 2021 | u64_stats_update_begin(&np->swstats_tx_syncp); |
| 2022 | np->stat_tx_dropped++; |
| 2023 | u64_stats_update_end(&np->swstats_tx_syncp); |
| 2024 | } |
Ayaz Abdulla | 3b446c3 | 2008-03-10 14:58:21 -0500 | [diff] [blame] | 2025 | np->tx_skb[i].dma = 0; |
| 2026 | np->tx_skb[i].dma_len = 0; |
Eric Dumazet | 73a3707 | 2009-06-17 21:17:59 +0000 | [diff] [blame] | 2027 | np->tx_skb[i].dma_single = 0; |
Ayaz Abdulla | 3b446c3 | 2008-03-10 14:58:21 -0500 | [diff] [blame] | 2028 | np->tx_skb[i].first_tx_desc = NULL; |
| 2029 | np->tx_skb[i].next_tx_ctx = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2030 | } |
Ayaz Abdulla | 3b446c3 | 2008-03-10 14:58:21 -0500 | [diff] [blame] | 2031 | np->tx_pkts_in_progress = 0; |
| 2032 | np->tx_change_owner = NULL; |
| 2033 | np->tx_end_flip = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2034 | } |
| 2035 | |
| 2036 | static void nv_drain_rx(struct net_device *dev) |
| 2037 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2038 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2039 | int i; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2040 | |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 2041 | for (i = 0; i < np->rx_ring_size; i++) { |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 2042 | if (!nv_optimized(np)) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2043 | np->rx_ring.orig[i].flaglen = 0; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2044 | np->rx_ring.orig[i].buf = 0; |
| 2045 | } else { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2046 | np->rx_ring.ex[i].flaglen = 0; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2047 | np->rx_ring.ex[i].txvlan = 0; |
| 2048 | np->rx_ring.ex[i].bufhigh = 0; |
| 2049 | np->rx_ring.ex[i].buflow = 0; |
| 2050 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2051 | wmb(); |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2052 | if (np->rx_skb[i].skb) { |
| 2053 | pci_unmap_single(np->pci_dev, np->rx_skb[i].dma, |
Arnaldo Carvalho de Melo | 4305b54 | 2007-04-19 20:43:29 -0700 | [diff] [blame] | 2054 | (skb_end_pointer(np->rx_skb[i].skb) - |
| 2055 | np->rx_skb[i].skb->data), |
| 2056 | PCI_DMA_FROMDEVICE); |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2057 | dev_kfree_skb(np->rx_skb[i].skb); |
| 2058 | np->rx_skb[i].skb = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2059 | } |
| 2060 | } |
| 2061 | } |
| 2062 | |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 2063 | static void nv_drain_rxtx(struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2064 | { |
| 2065 | nv_drain_tx(dev); |
| 2066 | nv_drain_rx(dev); |
| 2067 | } |
| 2068 | |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2069 | static inline u32 nv_get_empty_tx_slots(struct fe_priv *np) |
| 2070 | { |
| 2071 | return (u32)(np->tx_ring_size - ((np->tx_ring_size + (np->put_tx_ctx - np->get_tx_ctx)) % np->tx_ring_size)); |
| 2072 | } |
| 2073 | |
Ayaz Abdulla | a433686 | 2008-04-18 13:50:43 -0700 | [diff] [blame] | 2074 | static void nv_legacybackoff_reseed(struct net_device *dev) |
| 2075 | { |
| 2076 | u8 __iomem *base = get_hwbase(dev); |
| 2077 | u32 reg; |
| 2078 | u32 low; |
| 2079 | int tx_status = 0; |
| 2080 | |
| 2081 | reg = readl(base + NvRegSlotTime) & ~NVREG_SLOTTIME_MASK; |
| 2082 | get_random_bytes(&low, sizeof(low)); |
| 2083 | reg |= low & NVREG_SLOTTIME_MASK; |
| 2084 | |
| 2085 | /* Need to stop tx before change takes effect. |
| 2086 | * Caller has already gained np->lock. |
| 2087 | */ |
| 2088 | tx_status = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_START; |
| 2089 | if (tx_status) |
| 2090 | nv_stop_tx(dev); |
| 2091 | nv_stop_rx(dev); |
| 2092 | writel(reg, base + NvRegSlotTime); |
| 2093 | if (tx_status) |
| 2094 | nv_start_tx(dev); |
| 2095 | nv_start_rx(dev); |
| 2096 | } |
| 2097 | |
| 2098 | /* Gear Backoff Seeds */ |
| 2099 | #define BACKOFF_SEEDSET_ROWS 8 |
| 2100 | #define BACKOFF_SEEDSET_LFSRS 15 |
| 2101 | |
| 2102 | /* Known Good seed sets */ |
| 2103 | static const u32 main_seedset[BACKOFF_SEEDSET_ROWS][BACKOFF_SEEDSET_LFSRS] = { |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 2104 | {145, 155, 165, 175, 185, 196, 235, 245, 255, 265, 275, 285, 660, 690, 874}, |
| 2105 | {245, 255, 265, 575, 385, 298, 335, 345, 355, 366, 375, 385, 761, 790, 974}, |
| 2106 | {145, 155, 165, 175, 185, 196, 235, 245, 255, 265, 275, 285, 660, 690, 874}, |
| 2107 | {245, 255, 265, 575, 385, 298, 335, 345, 355, 366, 375, 386, 761, 790, 974}, |
| 2108 | {266, 265, 276, 585, 397, 208, 345, 355, 365, 376, 385, 396, 771, 700, 984}, |
| 2109 | {266, 265, 276, 586, 397, 208, 346, 355, 365, 376, 285, 396, 771, 700, 984}, |
| 2110 | {366, 365, 376, 686, 497, 308, 447, 455, 466, 476, 485, 496, 871, 800, 84}, |
| 2111 | {466, 465, 476, 786, 597, 408, 547, 555, 566, 576, 585, 597, 971, 900, 184} }; |
Ayaz Abdulla | a433686 | 2008-04-18 13:50:43 -0700 | [diff] [blame] | 2112 | |
| 2113 | static const u32 gear_seedset[BACKOFF_SEEDSET_ROWS][BACKOFF_SEEDSET_LFSRS] = { |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 2114 | {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295}, |
| 2115 | {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395}, |
| 2116 | {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 397}, |
| 2117 | {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295}, |
| 2118 | {251, 262, 273, 324, 319, 508, 375, 364, 341, 371, 398, 193, 375, 30, 295}, |
| 2119 | {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395}, |
| 2120 | {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395}, |
| 2121 | {351, 375, 373, 469, 551, 639, 477, 464, 441, 472, 498, 293, 476, 130, 395} }; |
Ayaz Abdulla | a433686 | 2008-04-18 13:50:43 -0700 | [diff] [blame] | 2122 | |
| 2123 | static void nv_gear_backoff_reseed(struct net_device *dev) |
| 2124 | { |
| 2125 | u8 __iomem *base = get_hwbase(dev); |
| 2126 | u32 miniseed1, miniseed2, miniseed2_reversed, miniseed3, miniseed3_reversed; |
| 2127 | u32 temp, seedset, combinedSeed; |
| 2128 | int i; |
| 2129 | |
| 2130 | /* Setup seed for free running LFSR */ |
| 2131 | /* We are going to read the time stamp counter 3 times |
| 2132 | and swizzle bits around to increase randomness */ |
| 2133 | get_random_bytes(&miniseed1, sizeof(miniseed1)); |
| 2134 | miniseed1 &= 0x0fff; |
| 2135 | if (miniseed1 == 0) |
| 2136 | miniseed1 = 0xabc; |
| 2137 | |
| 2138 | get_random_bytes(&miniseed2, sizeof(miniseed2)); |
| 2139 | miniseed2 &= 0x0fff; |
| 2140 | if (miniseed2 == 0) |
| 2141 | miniseed2 = 0xabc; |
| 2142 | miniseed2_reversed = |
| 2143 | ((miniseed2 & 0xF00) >> 8) | |
| 2144 | (miniseed2 & 0x0F0) | |
| 2145 | ((miniseed2 & 0x00F) << 8); |
| 2146 | |
| 2147 | get_random_bytes(&miniseed3, sizeof(miniseed3)); |
| 2148 | miniseed3 &= 0x0fff; |
| 2149 | if (miniseed3 == 0) |
| 2150 | miniseed3 = 0xabc; |
| 2151 | miniseed3_reversed = |
| 2152 | ((miniseed3 & 0xF00) >> 8) | |
| 2153 | (miniseed3 & 0x0F0) | |
| 2154 | ((miniseed3 & 0x00F) << 8); |
| 2155 | |
| 2156 | combinedSeed = ((miniseed1 ^ miniseed2_reversed) << 12) | |
| 2157 | (miniseed2 ^ miniseed3_reversed); |
| 2158 | |
| 2159 | /* Seeds can not be zero */ |
| 2160 | if ((combinedSeed & NVREG_BKOFFCTRL_SEED_MASK) == 0) |
| 2161 | combinedSeed |= 0x08; |
| 2162 | if ((combinedSeed & (NVREG_BKOFFCTRL_SEED_MASK << NVREG_BKOFFCTRL_GEAR)) == 0) |
| 2163 | combinedSeed |= 0x8000; |
| 2164 | |
| 2165 | /* No need to disable tx here */ |
| 2166 | temp = NVREG_BKOFFCTRL_DEFAULT | (0 << NVREG_BKOFFCTRL_SELECT); |
| 2167 | temp |= combinedSeed & NVREG_BKOFFCTRL_SEED_MASK; |
| 2168 | temp |= combinedSeed >> NVREG_BKOFFCTRL_GEAR; |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 2169 | writel(temp, base + NvRegBackOffControl); |
Ayaz Abdulla | a433686 | 2008-04-18 13:50:43 -0700 | [diff] [blame] | 2170 | |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 2171 | /* Setup seeds for all gear LFSRs. */ |
Ayaz Abdulla | a433686 | 2008-04-18 13:50:43 -0700 | [diff] [blame] | 2172 | get_random_bytes(&seedset, sizeof(seedset)); |
| 2173 | seedset = seedset % BACKOFF_SEEDSET_ROWS; |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 2174 | for (i = 1; i <= BACKOFF_SEEDSET_LFSRS; i++) { |
Ayaz Abdulla | a433686 | 2008-04-18 13:50:43 -0700 | [diff] [blame] | 2175 | temp = NVREG_BKOFFCTRL_DEFAULT | (i << NVREG_BKOFFCTRL_SELECT); |
| 2176 | temp |= main_seedset[seedset][i-1] & 0x3ff; |
| 2177 | temp |= ((gear_seedset[seedset][i-1] & 0x3ff) << NVREG_BKOFFCTRL_GEAR); |
| 2178 | writel(temp, base + NvRegBackOffControl); |
| 2179 | } |
| 2180 | } |
| 2181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2182 | /* |
| 2183 | * nv_start_xmit: dev->hard_start_xmit function |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 2184 | * Called with netif_tx_lock held. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2185 | */ |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 2186 | static netdev_tx_t nv_start_xmit(struct sk_buff *skb, struct net_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2187 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2188 | struct fe_priv *np = netdev_priv(dev); |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 2189 | u32 tx_flags = 0; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2190 | u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET); |
| 2191 | unsigned int fragments = skb_shinfo(skb)->nr_frags; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2192 | unsigned int i; |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 2193 | u32 offset = 0; |
| 2194 | u32 bcnt; |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 2195 | u32 size = skb_headlen(skb); |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 2196 | u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0); |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2197 | u32 empty_slots; |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 2198 | struct ring_desc *put_tx; |
| 2199 | struct ring_desc *start_tx; |
| 2200 | struct ring_desc *prev_tx; |
| 2201 | struct nv_skb_map *prev_tx_ctx; |
Neil Horman | f7f2287 | 2013-04-01 04:31:58 +0000 | [diff] [blame] | 2202 | struct nv_skb_map *tmp_tx_ctx = NULL, *start_tx_ctx = NULL; |
Ingo Molnar | bd6ca63 | 2008-03-28 14:41:30 -0700 | [diff] [blame] | 2203 | unsigned long flags; |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 2204 | |
| 2205 | /* add fragments to entries count */ |
| 2206 | for (i = 0; i < fragments; i++) { |
david decotigny | e45a618 | 2011-11-05 14:38:24 +0000 | [diff] [blame] | 2207 | u32 frag_size = skb_frag_size(&skb_shinfo(skb)->frags[i]); |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 2208 | |
david decotigny | e45a618 | 2011-11-05 14:38:24 +0000 | [diff] [blame] | 2209 | entries += (frag_size >> NV_TX2_TSO_MAX_SHIFT) + |
| 2210 | ((frag_size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0); |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 2211 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2212 | |
Ayaz Abdulla | 001eb84 | 2009-01-09 11:03:44 +0000 | [diff] [blame] | 2213 | spin_lock_irqsave(&np->lock, flags); |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2214 | empty_slots = nv_get_empty_tx_slots(np); |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2215 | if (unlikely(empty_slots <= entries)) { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2216 | netif_stop_queue(dev); |
Ayaz Abdulla | aaa37d2 | 2007-01-21 18:10:42 -0500 | [diff] [blame] | 2217 | np->tx_stop = 1; |
Ingo Molnar | bd6ca63 | 2008-03-28 14:41:30 -0700 | [diff] [blame] | 2218 | spin_unlock_irqrestore(&np->lock, flags); |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2219 | return NETDEV_TX_BUSY; |
| 2220 | } |
Ayaz Abdulla | 001eb84 | 2009-01-09 11:03:44 +0000 | [diff] [blame] | 2221 | spin_unlock_irqrestore(&np->lock, flags); |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2222 | |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2223 | start_tx = put_tx = np->put_tx.orig; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2224 | |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 2225 | /* setup the header buffer */ |
| 2226 | do { |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2227 | prev_tx = put_tx; |
| 2228 | prev_tx_ctx = np->put_tx_ctx; |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 2229 | bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size; |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2230 | np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt, |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 2231 | PCI_DMA_TODEVICE); |
Larry Finger | 612a7c4 | 2012-12-27 17:25:41 +0000 | [diff] [blame] | 2232 | if (pci_dma_mapping_error(np->pci_dev, |
| 2233 | np->put_tx_ctx->dma)) { |
| 2234 | /* on DMA mapping error - drop the packet */ |
| 2235 | kfree_skb(skb); |
| 2236 | u64_stats_update_begin(&np->swstats_tx_syncp); |
| 2237 | np->stat_tx_dropped++; |
| 2238 | u64_stats_update_end(&np->swstats_tx_syncp); |
| 2239 | return NETDEV_TX_OK; |
| 2240 | } |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2241 | np->put_tx_ctx->dma_len = bcnt; |
Eric Dumazet | 73a3707 | 2009-06-17 21:17:59 +0000 | [diff] [blame] | 2242 | np->put_tx_ctx->dma_single = 1; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2243 | put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma); |
| 2244 | put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags); |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2245 | |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 2246 | tx_flags = np->tx_flags; |
| 2247 | offset += bcnt; |
| 2248 | size -= bcnt; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2249 | if (unlikely(put_tx++ == np->last_tx.orig)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2250 | put_tx = np->first_tx.orig; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2251 | if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx)) |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2252 | np->put_tx_ctx = np->first_tx_ctx; |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2253 | } while (size); |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 2254 | |
| 2255 | /* setup the fragments */ |
| 2256 | for (i = 0; i < fragments; i++) { |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 2257 | const skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
david decotigny | e45a618 | 2011-11-05 14:38:24 +0000 | [diff] [blame] | 2258 | u32 frag_size = skb_frag_size(frag); |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 2259 | offset = 0; |
| 2260 | |
| 2261 | do { |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2262 | prev_tx = put_tx; |
| 2263 | prev_tx_ctx = np->put_tx_ctx; |
Neil Horman | f7f2287 | 2013-04-01 04:31:58 +0000 | [diff] [blame] | 2264 | if (!start_tx_ctx) |
| 2265 | start_tx_ctx = tmp_tx_ctx = np->put_tx_ctx; |
| 2266 | |
david decotigny | e45a618 | 2011-11-05 14:38:24 +0000 | [diff] [blame] | 2267 | bcnt = (frag_size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : frag_size; |
Ian Campbell | 671173c | 2011-08-29 23:18:28 +0000 | [diff] [blame] | 2268 | np->put_tx_ctx->dma = skb_frag_dma_map( |
| 2269 | &np->pci_dev->dev, |
| 2270 | frag, offset, |
| 2271 | bcnt, |
Ian Campbell | 5d6bcdf | 2011-10-06 11:10:48 +0100 | [diff] [blame] | 2272 | DMA_TO_DEVICE); |
Neil Horman | f7f2287 | 2013-04-01 04:31:58 +0000 | [diff] [blame] | 2273 | if (dma_mapping_error(&np->pci_dev->dev, np->put_tx_ctx->dma)) { |
| 2274 | |
| 2275 | /* Unwind the mapped fragments */ |
| 2276 | do { |
| 2277 | nv_unmap_txskb(np, start_tx_ctx); |
| 2278 | if (unlikely(tmp_tx_ctx++ == np->last_tx_ctx)) |
| 2279 | tmp_tx_ctx = np->first_tx_ctx; |
| 2280 | } while (tmp_tx_ctx != np->put_tx_ctx); |
| 2281 | kfree_skb(skb); |
| 2282 | np->put_tx_ctx = start_tx_ctx; |
| 2283 | u64_stats_update_begin(&np->swstats_tx_syncp); |
| 2284 | np->stat_tx_dropped++; |
| 2285 | u64_stats_update_end(&np->swstats_tx_syncp); |
| 2286 | return NETDEV_TX_OK; |
| 2287 | } |
| 2288 | |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2289 | np->put_tx_ctx->dma_len = bcnt; |
Eric Dumazet | 73a3707 | 2009-06-17 21:17:59 +0000 | [diff] [blame] | 2290 | np->put_tx_ctx->dma_single = 0; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2291 | put_tx->buf = cpu_to_le32(np->put_tx_ctx->dma); |
| 2292 | put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags); |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2293 | |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 2294 | offset += bcnt; |
david decotigny | e45a618 | 2011-11-05 14:38:24 +0000 | [diff] [blame] | 2295 | frag_size -= bcnt; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2296 | if (unlikely(put_tx++ == np->last_tx.orig)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2297 | put_tx = np->first_tx.orig; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2298 | if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx)) |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2299 | np->put_tx_ctx = np->first_tx_ctx; |
david decotigny | e45a618 | 2011-11-05 14:38:24 +0000 | [diff] [blame] | 2300 | } while (frag_size); |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2301 | } |
| 2302 | |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 2303 | /* set last fragment flag */ |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2304 | prev_tx->flaglen |= cpu_to_le32(tx_flags_extra); |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 2305 | |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2306 | /* save skb in this slot's context area */ |
| 2307 | prev_tx_ctx->skb = skb; |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 2308 | |
Herbert Xu | 89114af | 2006-07-08 13:34:32 -0700 | [diff] [blame] | 2309 | if (skb_is_gso(skb)) |
Herbert Xu | 7967168 | 2006-06-22 02:40:14 -0700 | [diff] [blame] | 2310 | tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT); |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 2311 | else |
Arjan van de Ven | 1d39ed5 | 2006-12-12 14:06:23 +0100 | [diff] [blame] | 2312 | tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ? |
Patrick McHardy | 84fa793 | 2006-08-29 16:44:56 -0700 | [diff] [blame] | 2313 | NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2314 | |
Ingo Molnar | bd6ca63 | 2008-03-28 14:41:30 -0700 | [diff] [blame] | 2315 | spin_lock_irqsave(&np->lock, flags); |
Ayaz Abdulla | 164a86e | 2007-01-09 13:30:10 -0500 | [diff] [blame] | 2316 | |
Ayaz Abdulla | fa45459 | 2006-01-05 22:45:45 -0800 | [diff] [blame] | 2317 | /* set tx flags */ |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2318 | start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra); |
Tom Herbert | b8bfca9 | 2011-11-28 16:33:23 +0000 | [diff] [blame] | 2319 | |
| 2320 | netdev_sent_queue(np->dev, skb->len); |
| 2321 | |
Willem de Bruijn | 49cbb1c | 2012-04-27 09:04:07 +0000 | [diff] [blame] | 2322 | skb_tx_timestamp(skb); |
| 2323 | |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2324 | np->put_tx.orig = put_tx; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2325 | |
Ingo Molnar | bd6ca63 | 2008-03-28 14:41:30 -0700 | [diff] [blame] | 2326 | spin_unlock_irqrestore(&np->lock, flags); |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2327 | |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 2328 | writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl); |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2329 | return NETDEV_TX_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2330 | } |
| 2331 | |
Stephen Hemminger | 61357325 | 2009-08-31 19:50:58 +0000 | [diff] [blame] | 2332 | static netdev_tx_t nv_start_xmit_optimized(struct sk_buff *skb, |
| 2333 | struct net_device *dev) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2334 | { |
| 2335 | struct fe_priv *np = netdev_priv(dev); |
| 2336 | u32 tx_flags = 0; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2337 | u32 tx_flags_extra; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2338 | unsigned int fragments = skb_shinfo(skb)->nr_frags; |
| 2339 | unsigned int i; |
| 2340 | u32 offset = 0; |
| 2341 | u32 bcnt; |
Eric Dumazet | e743d31 | 2010-04-14 15:59:40 -0700 | [diff] [blame] | 2342 | u32 size = skb_headlen(skb); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2343 | u32 entries = (size >> NV_TX2_TSO_MAX_SHIFT) + ((size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0); |
| 2344 | u32 empty_slots; |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 2345 | struct ring_desc_ex *put_tx; |
| 2346 | struct ring_desc_ex *start_tx; |
| 2347 | struct ring_desc_ex *prev_tx; |
| 2348 | struct nv_skb_map *prev_tx_ctx; |
Neil Horman | f7f2287 | 2013-04-01 04:31:58 +0000 | [diff] [blame] | 2349 | struct nv_skb_map *start_tx_ctx = NULL; |
| 2350 | struct nv_skb_map *tmp_tx_ctx = NULL; |
Ingo Molnar | bd6ca63 | 2008-03-28 14:41:30 -0700 | [diff] [blame] | 2351 | unsigned long flags; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2352 | |
| 2353 | /* add fragments to entries count */ |
| 2354 | for (i = 0; i < fragments; i++) { |
david decotigny | e45a618 | 2011-11-05 14:38:24 +0000 | [diff] [blame] | 2355 | u32 frag_size = skb_frag_size(&skb_shinfo(skb)->frags[i]); |
Eric Dumazet | 9e903e0 | 2011-10-18 21:00:24 +0000 | [diff] [blame] | 2356 | |
david decotigny | e45a618 | 2011-11-05 14:38:24 +0000 | [diff] [blame] | 2357 | entries += (frag_size >> NV_TX2_TSO_MAX_SHIFT) + |
| 2358 | ((frag_size & (NV_TX2_TSO_MAX_SIZE-1)) ? 1 : 0); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2359 | } |
| 2360 | |
Ayaz Abdulla | 001eb84 | 2009-01-09 11:03:44 +0000 | [diff] [blame] | 2361 | spin_lock_irqsave(&np->lock, flags); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2362 | empty_slots = nv_get_empty_tx_slots(np); |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2363 | if (unlikely(empty_slots <= entries)) { |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2364 | netif_stop_queue(dev); |
Ayaz Abdulla | aaa37d2 | 2007-01-21 18:10:42 -0500 | [diff] [blame] | 2365 | np->tx_stop = 1; |
Ingo Molnar | bd6ca63 | 2008-03-28 14:41:30 -0700 | [diff] [blame] | 2366 | spin_unlock_irqrestore(&np->lock, flags); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2367 | return NETDEV_TX_BUSY; |
| 2368 | } |
Ayaz Abdulla | 001eb84 | 2009-01-09 11:03:44 +0000 | [diff] [blame] | 2369 | spin_unlock_irqrestore(&np->lock, flags); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2370 | |
| 2371 | start_tx = put_tx = np->put_tx.ex; |
Ayaz Abdulla | 3b446c3 | 2008-03-10 14:58:21 -0500 | [diff] [blame] | 2372 | start_tx_ctx = np->put_tx_ctx; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2373 | |
| 2374 | /* setup the header buffer */ |
| 2375 | do { |
| 2376 | prev_tx = put_tx; |
| 2377 | prev_tx_ctx = np->put_tx_ctx; |
| 2378 | bcnt = (size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : size; |
| 2379 | np->put_tx_ctx->dma = pci_map_single(np->pci_dev, skb->data + offset, bcnt, |
| 2380 | PCI_DMA_TODEVICE); |
Larry Finger | 612a7c4 | 2012-12-27 17:25:41 +0000 | [diff] [blame] | 2381 | if (pci_dma_mapping_error(np->pci_dev, |
| 2382 | np->put_tx_ctx->dma)) { |
| 2383 | /* on DMA mapping error - drop the packet */ |
| 2384 | kfree_skb(skb); |
| 2385 | u64_stats_update_begin(&np->swstats_tx_syncp); |
| 2386 | np->stat_tx_dropped++; |
| 2387 | u64_stats_update_end(&np->swstats_tx_syncp); |
| 2388 | return NETDEV_TX_OK; |
| 2389 | } |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2390 | np->put_tx_ctx->dma_len = bcnt; |
Eric Dumazet | 73a3707 | 2009-06-17 21:17:59 +0000 | [diff] [blame] | 2391 | np->put_tx_ctx->dma_single = 1; |
Al Viro | 5bb7ea2 | 2007-12-09 16:06:41 +0000 | [diff] [blame] | 2392 | put_tx->bufhigh = cpu_to_le32(dma_high(np->put_tx_ctx->dma)); |
| 2393 | put_tx->buflow = cpu_to_le32(dma_low(np->put_tx_ctx->dma)); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2394 | put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags); |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2395 | |
| 2396 | tx_flags = NV_TX2_VALID; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2397 | offset += bcnt; |
| 2398 | size -= bcnt; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2399 | if (unlikely(put_tx++ == np->last_tx.ex)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2400 | put_tx = np->first_tx.ex; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2401 | if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2402 | np->put_tx_ctx = np->first_tx_ctx; |
| 2403 | } while (size); |
| 2404 | |
| 2405 | /* setup the fragments */ |
| 2406 | for (i = 0; i < fragments; i++) { |
| 2407 | skb_frag_t *frag = &skb_shinfo(skb)->frags[i]; |
david decotigny | e45a618 | 2011-11-05 14:38:24 +0000 | [diff] [blame] | 2408 | u32 frag_size = skb_frag_size(frag); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2409 | offset = 0; |
| 2410 | |
| 2411 | do { |
| 2412 | prev_tx = put_tx; |
| 2413 | prev_tx_ctx = np->put_tx_ctx; |
david decotigny | e45a618 | 2011-11-05 14:38:24 +0000 | [diff] [blame] | 2414 | bcnt = (frag_size > NV_TX2_TSO_MAX_SIZE) ? NV_TX2_TSO_MAX_SIZE : frag_size; |
Neil Horman | f7f2287 | 2013-04-01 04:31:58 +0000 | [diff] [blame] | 2415 | if (!start_tx_ctx) |
| 2416 | start_tx_ctx = tmp_tx_ctx = np->put_tx_ctx; |
Ian Campbell | 671173c | 2011-08-29 23:18:28 +0000 | [diff] [blame] | 2417 | np->put_tx_ctx->dma = skb_frag_dma_map( |
| 2418 | &np->pci_dev->dev, |
| 2419 | frag, offset, |
| 2420 | bcnt, |
Ian Campbell | 5d6bcdf | 2011-10-06 11:10:48 +0100 | [diff] [blame] | 2421 | DMA_TO_DEVICE); |
Neil Horman | f7f2287 | 2013-04-01 04:31:58 +0000 | [diff] [blame] | 2422 | |
| 2423 | if (dma_mapping_error(&np->pci_dev->dev, np->put_tx_ctx->dma)) { |
| 2424 | |
| 2425 | /* Unwind the mapped fragments */ |
| 2426 | do { |
| 2427 | nv_unmap_txskb(np, start_tx_ctx); |
| 2428 | if (unlikely(tmp_tx_ctx++ == np->last_tx_ctx)) |
| 2429 | tmp_tx_ctx = np->first_tx_ctx; |
| 2430 | } while (tmp_tx_ctx != np->put_tx_ctx); |
| 2431 | kfree_skb(skb); |
| 2432 | np->put_tx_ctx = start_tx_ctx; |
| 2433 | u64_stats_update_begin(&np->swstats_tx_syncp); |
| 2434 | np->stat_tx_dropped++; |
| 2435 | u64_stats_update_end(&np->swstats_tx_syncp); |
| 2436 | return NETDEV_TX_OK; |
| 2437 | } |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2438 | np->put_tx_ctx->dma_len = bcnt; |
Eric Dumazet | 73a3707 | 2009-06-17 21:17:59 +0000 | [diff] [blame] | 2439 | np->put_tx_ctx->dma_single = 0; |
Al Viro | 5bb7ea2 | 2007-12-09 16:06:41 +0000 | [diff] [blame] | 2440 | put_tx->bufhigh = cpu_to_le32(dma_high(np->put_tx_ctx->dma)); |
| 2441 | put_tx->buflow = cpu_to_le32(dma_low(np->put_tx_ctx->dma)); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2442 | put_tx->flaglen = cpu_to_le32((bcnt-1) | tx_flags); |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2443 | |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2444 | offset += bcnt; |
david decotigny | e45a618 | 2011-11-05 14:38:24 +0000 | [diff] [blame] | 2445 | frag_size -= bcnt; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2446 | if (unlikely(put_tx++ == np->last_tx.ex)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2447 | put_tx = np->first_tx.ex; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2448 | if (unlikely(np->put_tx_ctx++ == np->last_tx_ctx)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2449 | np->put_tx_ctx = np->first_tx_ctx; |
david decotigny | e45a618 | 2011-11-05 14:38:24 +0000 | [diff] [blame] | 2450 | } while (frag_size); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2451 | } |
| 2452 | |
| 2453 | /* set last fragment flag */ |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2454 | prev_tx->flaglen |= cpu_to_le32(NV_TX2_LASTPACKET); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2455 | |
| 2456 | /* save skb in this slot's context area */ |
| 2457 | prev_tx_ctx->skb = skb; |
| 2458 | |
| 2459 | if (skb_is_gso(skb)) |
| 2460 | tx_flags_extra = NV_TX2_TSO | (skb_shinfo(skb)->gso_size << NV_TX2_TSO_SHIFT); |
| 2461 | else |
| 2462 | tx_flags_extra = skb->ip_summed == CHECKSUM_PARTIAL ? |
| 2463 | NV_TX2_CHECKSUM_L3 | NV_TX2_CHECKSUM_L4 : 0; |
| 2464 | |
| 2465 | /* vlan tag */ |
Jesse Gross | eab6d18 | 2010-10-20 13:56:03 +0000 | [diff] [blame] | 2466 | if (vlan_tx_tag_present(skb)) |
| 2467 | start_tx->txvlan = cpu_to_le32(NV_TX3_VLAN_TAG_PRESENT | |
| 2468 | vlan_tx_tag_get(skb)); |
| 2469 | else |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2470 | start_tx->txvlan = 0; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2471 | |
Ingo Molnar | bd6ca63 | 2008-03-28 14:41:30 -0700 | [diff] [blame] | 2472 | spin_lock_irqsave(&np->lock, flags); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2473 | |
Ayaz Abdulla | 3b446c3 | 2008-03-10 14:58:21 -0500 | [diff] [blame] | 2474 | if (np->tx_limit) { |
| 2475 | /* Limit the number of outstanding tx. Setup all fragments, but |
| 2476 | * do not set the VALID bit on the first descriptor. Save a pointer |
| 2477 | * to that descriptor and also for next skb_map element. |
| 2478 | */ |
| 2479 | |
| 2480 | if (np->tx_pkts_in_progress == NV_TX_LIMIT_COUNT) { |
| 2481 | if (!np->tx_change_owner) |
| 2482 | np->tx_change_owner = start_tx_ctx; |
| 2483 | |
| 2484 | /* remove VALID bit */ |
| 2485 | tx_flags &= ~NV_TX2_VALID; |
| 2486 | start_tx_ctx->first_tx_desc = start_tx; |
| 2487 | start_tx_ctx->next_tx_ctx = np->put_tx_ctx; |
| 2488 | np->tx_end_flip = np->put_tx_ctx; |
| 2489 | } else { |
| 2490 | np->tx_pkts_in_progress++; |
| 2491 | } |
| 2492 | } |
| 2493 | |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2494 | /* set tx flags */ |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2495 | start_tx->flaglen |= cpu_to_le32(tx_flags | tx_flags_extra); |
Tom Herbert | b8bfca9 | 2011-11-28 16:33:23 +0000 | [diff] [blame] | 2496 | |
| 2497 | netdev_sent_queue(np->dev, skb->len); |
| 2498 | |
Willem de Bruijn | 49cbb1c | 2012-04-27 09:04:07 +0000 | [diff] [blame] | 2499 | skb_tx_timestamp(skb); |
| 2500 | |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2501 | np->put_tx.ex = put_tx; |
| 2502 | |
Ingo Molnar | bd6ca63 | 2008-03-28 14:41:30 -0700 | [diff] [blame] | 2503 | spin_unlock_irqrestore(&np->lock, flags); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2504 | |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2505 | writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2506 | return NETDEV_TX_OK; |
| 2507 | } |
| 2508 | |
Ayaz Abdulla | 3b446c3 | 2008-03-10 14:58:21 -0500 | [diff] [blame] | 2509 | static inline void nv_tx_flip_ownership(struct net_device *dev) |
| 2510 | { |
| 2511 | struct fe_priv *np = netdev_priv(dev); |
| 2512 | |
| 2513 | np->tx_pkts_in_progress--; |
| 2514 | if (np->tx_change_owner) { |
Al Viro | 30ecce9 | 2008-03-26 05:57:12 +0000 | [diff] [blame] | 2515 | np->tx_change_owner->first_tx_desc->flaglen |= |
| 2516 | cpu_to_le32(NV_TX2_VALID); |
Ayaz Abdulla | 3b446c3 | 2008-03-10 14:58:21 -0500 | [diff] [blame] | 2517 | np->tx_pkts_in_progress++; |
| 2518 | |
| 2519 | np->tx_change_owner = np->tx_change_owner->next_tx_ctx; |
| 2520 | if (np->tx_change_owner == np->tx_end_flip) |
| 2521 | np->tx_change_owner = NULL; |
| 2522 | |
| 2523 | writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl); |
| 2524 | } |
| 2525 | } |
| 2526 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2527 | /* |
| 2528 | * nv_tx_done: check for completed packets, release the skbs. |
| 2529 | * |
| 2530 | * Caller must own np->lock. |
| 2531 | */ |
Ayaz Abdulla | 33912e7 | 2009-03-05 08:02:10 +0000 | [diff] [blame] | 2532 | static int nv_tx_done(struct net_device *dev, int limit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2533 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2534 | struct fe_priv *np = netdev_priv(dev); |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2535 | u32 flags; |
Ayaz Abdulla | 33912e7 | 2009-03-05 08:02:10 +0000 | [diff] [blame] | 2536 | int tx_work = 0; |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 2537 | struct ring_desc *orig_get_tx = np->get_tx.orig; |
Tom Herbert | b8bfca9 | 2011-11-28 16:33:23 +0000 | [diff] [blame] | 2538 | unsigned int bytes_compl = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2539 | |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2540 | while ((np->get_tx.orig != np->put_tx.orig) && |
Ayaz Abdulla | 33912e7 | 2009-03-05 08:02:10 +0000 | [diff] [blame] | 2541 | !((flags = le32_to_cpu(np->get_tx.orig->flaglen)) & NV_TX_VALID) && |
| 2542 | (tx_work < limit)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2543 | |
Eric Dumazet | 73a3707 | 2009-06-17 21:17:59 +0000 | [diff] [blame] | 2544 | nv_unmap_txskb(np, np->get_tx_ctx); |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2545 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2546 | if (np->desc_ver == DESC_VER_1) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2547 | if (flags & NV_TX_LASTPACKET) { |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2548 | if (flags & NV_TX_ERROR) { |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 2549 | if ((flags & NV_TX_RETRYERROR) |
| 2550 | && !(flags & NV_TX_RETRYCOUNT_MASK)) |
Ayaz Abdulla | a433686 | 2008-04-18 13:50:43 -0700 | [diff] [blame] | 2551 | nv_legacybackoff_reseed(dev); |
david decotigny | 674aee3 | 2011-11-16 12:15:07 +0000 | [diff] [blame] | 2552 | } else { |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 2553 | u64_stats_update_begin(&np->swstats_tx_syncp); |
| 2554 | np->stat_tx_packets++; |
| 2555 | np->stat_tx_bytes += np->get_tx_ctx->skb->len; |
| 2556 | u64_stats_update_end(&np->swstats_tx_syncp); |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2557 | } |
Tom Herbert | b8bfca9 | 2011-11-28 16:33:23 +0000 | [diff] [blame] | 2558 | bytes_compl += np->get_tx_ctx->skb->len; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2559 | dev_kfree_skb_any(np->get_tx_ctx->skb); |
| 2560 | np->get_tx_ctx->skb = NULL; |
Ayaz Abdulla | 33912e7 | 2009-03-05 08:02:10 +0000 | [diff] [blame] | 2561 | tx_work++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2562 | } |
| 2563 | } else { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2564 | if (flags & NV_TX2_LASTPACKET) { |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2565 | if (flags & NV_TX2_ERROR) { |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 2566 | if ((flags & NV_TX2_RETRYERROR) |
| 2567 | && !(flags & NV_TX2_RETRYCOUNT_MASK)) |
Ayaz Abdulla | a433686 | 2008-04-18 13:50:43 -0700 | [diff] [blame] | 2568 | nv_legacybackoff_reseed(dev); |
david decotigny | 674aee3 | 2011-11-16 12:15:07 +0000 | [diff] [blame] | 2569 | } else { |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 2570 | u64_stats_update_begin(&np->swstats_tx_syncp); |
| 2571 | np->stat_tx_packets++; |
| 2572 | np->stat_tx_bytes += np->get_tx_ctx->skb->len; |
| 2573 | u64_stats_update_end(&np->swstats_tx_syncp); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 2574 | } |
Tom Herbert | b8bfca9 | 2011-11-28 16:33:23 +0000 | [diff] [blame] | 2575 | bytes_compl += np->get_tx_ctx->skb->len; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2576 | dev_kfree_skb_any(np->get_tx_ctx->skb); |
| 2577 | np->get_tx_ctx->skb = NULL; |
Ayaz Abdulla | 33912e7 | 2009-03-05 08:02:10 +0000 | [diff] [blame] | 2578 | tx_work++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2579 | } |
| 2580 | } |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2581 | if (unlikely(np->get_tx.orig++ == np->last_tx.orig)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2582 | np->get_tx.orig = np->first_tx.orig; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2583 | if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2584 | np->get_tx_ctx = np->first_tx_ctx; |
| 2585 | } |
Tom Herbert | b8bfca9 | 2011-11-28 16:33:23 +0000 | [diff] [blame] | 2586 | |
| 2587 | netdev_completed_queue(np->dev, tx_work, bytes_compl); |
| 2588 | |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2589 | if (unlikely((np->tx_stop == 1) && (np->get_tx.orig != orig_get_tx))) { |
Ayaz Abdulla | aaa37d2 | 2007-01-21 18:10:42 -0500 | [diff] [blame] | 2590 | np->tx_stop = 0; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2591 | netif_wake_queue(dev); |
Ayaz Abdulla | aaa37d2 | 2007-01-21 18:10:42 -0500 | [diff] [blame] | 2592 | } |
Ayaz Abdulla | 33912e7 | 2009-03-05 08:02:10 +0000 | [diff] [blame] | 2593 | return tx_work; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2594 | } |
| 2595 | |
Ayaz Abdulla | 33912e7 | 2009-03-05 08:02:10 +0000 | [diff] [blame] | 2596 | static int nv_tx_done_optimized(struct net_device *dev, int limit) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2597 | { |
| 2598 | struct fe_priv *np = netdev_priv(dev); |
| 2599 | u32 flags; |
Ayaz Abdulla | 33912e7 | 2009-03-05 08:02:10 +0000 | [diff] [blame] | 2600 | int tx_work = 0; |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 2601 | struct ring_desc_ex *orig_get_tx = np->get_tx.ex; |
Tom Herbert | b8bfca9 | 2011-11-28 16:33:23 +0000 | [diff] [blame] | 2602 | unsigned long bytes_cleaned = 0; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2603 | |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2604 | while ((np->get_tx.ex != np->put_tx.ex) && |
Julia Lawall | 217d32d | 2010-07-05 22:15:47 -0700 | [diff] [blame] | 2605 | !((flags = le32_to_cpu(np->get_tx.ex->flaglen)) & NV_TX2_VALID) && |
Ayaz Abdulla | 33912e7 | 2009-03-05 08:02:10 +0000 | [diff] [blame] | 2606 | (tx_work < limit)) { |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2607 | |
Eric Dumazet | 73a3707 | 2009-06-17 21:17:59 +0000 | [diff] [blame] | 2608 | nv_unmap_txskb(np, np->get_tx_ctx); |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2609 | |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2610 | if (flags & NV_TX2_LASTPACKET) { |
david decotigny | 4687f3f | 2011-11-05 14:38:22 +0000 | [diff] [blame] | 2611 | if (flags & NV_TX2_ERROR) { |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 2612 | if ((flags & NV_TX2_RETRYERROR) |
| 2613 | && !(flags & NV_TX2_RETRYCOUNT_MASK)) { |
Ayaz Abdulla | a433686 | 2008-04-18 13:50:43 -0700 | [diff] [blame] | 2614 | if (np->driver_data & DEV_HAS_GEAR_MODE) |
| 2615 | nv_gear_backoff_reseed(dev); |
| 2616 | else |
| 2617 | nv_legacybackoff_reseed(dev); |
| 2618 | } |
david decotigny | 674aee3 | 2011-11-16 12:15:07 +0000 | [diff] [blame] | 2619 | } else { |
David S. Miller | efd0bf9 | 2011-11-21 13:50:33 -0500 | [diff] [blame] | 2620 | u64_stats_update_begin(&np->swstats_tx_syncp); |
| 2621 | np->stat_tx_packets++; |
| 2622 | np->stat_tx_bytes += np->get_tx_ctx->skb->len; |
| 2623 | u64_stats_update_end(&np->swstats_tx_syncp); |
Ayaz Abdulla | a433686 | 2008-04-18 13:50:43 -0700 | [diff] [blame] | 2624 | } |
| 2625 | |
Tom Herbert | b8bfca9 | 2011-11-28 16:33:23 +0000 | [diff] [blame] | 2626 | bytes_cleaned += np->get_tx_ctx->skb->len; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2627 | dev_kfree_skb_any(np->get_tx_ctx->skb); |
| 2628 | np->get_tx_ctx->skb = NULL; |
Ayaz Abdulla | 33912e7 | 2009-03-05 08:02:10 +0000 | [diff] [blame] | 2629 | tx_work++; |
Ayaz Abdulla | 3b446c3 | 2008-03-10 14:58:21 -0500 | [diff] [blame] | 2630 | |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 2631 | if (np->tx_limit) |
Ayaz Abdulla | 3b446c3 | 2008-03-10 14:58:21 -0500 | [diff] [blame] | 2632 | nv_tx_flip_ownership(dev); |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2633 | } |
Tom Herbert | b8bfca9 | 2011-11-28 16:33:23 +0000 | [diff] [blame] | 2634 | |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2635 | if (unlikely(np->get_tx.ex++ == np->last_tx.ex)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2636 | np->get_tx.ex = np->first_tx.ex; |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2637 | if (unlikely(np->get_tx_ctx++ == np->last_tx_ctx)) |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2638 | np->get_tx_ctx = np->first_tx_ctx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2639 | } |
Igor Maravic | 7505afe | 2011-12-01 23:48:20 +0000 | [diff] [blame] | 2640 | |
| 2641 | netdev_completed_queue(np->dev, tx_work, bytes_cleaned); |
| 2642 | |
Ayaz Abdulla | 445583b | 2007-01-21 18:10:47 -0500 | [diff] [blame] | 2643 | if (unlikely((np->tx_stop == 1) && (np->get_tx.ex != orig_get_tx))) { |
Ayaz Abdulla | aaa37d2 | 2007-01-21 18:10:42 -0500 | [diff] [blame] | 2644 | np->tx_stop = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2645 | netif_wake_queue(dev); |
Ayaz Abdulla | aaa37d2 | 2007-01-21 18:10:42 -0500 | [diff] [blame] | 2646 | } |
Ayaz Abdulla | 33912e7 | 2009-03-05 08:02:10 +0000 | [diff] [blame] | 2647 | return tx_work; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2648 | } |
| 2649 | |
| 2650 | /* |
| 2651 | * nv_tx_timeout: dev->tx_timeout function |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 2652 | * Called with netif_tx_lock held. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2653 | */ |
| 2654 | static void nv_tx_timeout(struct net_device *dev) |
| 2655 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2656 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2657 | u8 __iomem *base = get_hwbase(dev); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 2658 | u32 status; |
Ayaz Abdulla | 8f955d7 | 2009-04-25 09:17:56 +0000 | [diff] [blame] | 2659 | union ring_type put_tx; |
| 2660 | int saved_tx_limit; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2661 | |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 2662 | if (np->msi_flags & NV_MSI_X_ENABLED) |
| 2663 | status = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK; |
| 2664 | else |
| 2665 | status = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK; |
| 2666 | |
Sameer Nanda | 1ec4f2d | 2011-11-16 12:15:12 +0000 | [diff] [blame] | 2667 | netdev_warn(dev, "Got tx_timeout. irq status: %08x\n", status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2668 | |
Sameer Nanda | 1ec4f2d | 2011-11-16 12:15:12 +0000 | [diff] [blame] | 2669 | if (unlikely(debug_tx_timeout)) { |
| 2670 | int i; |
| 2671 | |
| 2672 | netdev_info(dev, "Ring at %lx\n", (unsigned long)np->ring_addr); |
| 2673 | netdev_info(dev, "Dumping tx registers\n"); |
| 2674 | for (i = 0; i <= np->register_size; i += 32) { |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 2675 | netdev_info(dev, |
Sameer Nanda | 1ec4f2d | 2011-11-16 12:15:12 +0000 | [diff] [blame] | 2676 | "%3x: %08x %08x %08x %08x " |
| 2677 | "%08x %08x %08x %08x\n", |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 2678 | i, |
Sameer Nanda | 1ec4f2d | 2011-11-16 12:15:12 +0000 | [diff] [blame] | 2679 | readl(base + i + 0), readl(base + i + 4), |
| 2680 | readl(base + i + 8), readl(base + i + 12), |
| 2681 | readl(base + i + 16), readl(base + i + 20), |
| 2682 | readl(base + i + 24), readl(base + i + 28)); |
| 2683 | } |
| 2684 | netdev_info(dev, "Dumping tx ring\n"); |
| 2685 | for (i = 0; i < np->tx_ring_size; i += 4) { |
| 2686 | if (!nv_optimized(np)) { |
| 2687 | netdev_info(dev, |
| 2688 | "%03x: %08x %08x // %08x %08x " |
| 2689 | "// %08x %08x // %08x %08x\n", |
| 2690 | i, |
| 2691 | le32_to_cpu(np->tx_ring.orig[i].buf), |
| 2692 | le32_to_cpu(np->tx_ring.orig[i].flaglen), |
| 2693 | le32_to_cpu(np->tx_ring.orig[i+1].buf), |
| 2694 | le32_to_cpu(np->tx_ring.orig[i+1].flaglen), |
| 2695 | le32_to_cpu(np->tx_ring.orig[i+2].buf), |
| 2696 | le32_to_cpu(np->tx_ring.orig[i+2].flaglen), |
| 2697 | le32_to_cpu(np->tx_ring.orig[i+3].buf), |
| 2698 | le32_to_cpu(np->tx_ring.orig[i+3].flaglen)); |
| 2699 | } else { |
| 2700 | netdev_info(dev, |
| 2701 | "%03x: %08x %08x %08x " |
| 2702 | "// %08x %08x %08x " |
| 2703 | "// %08x %08x %08x " |
| 2704 | "// %08x %08x %08x\n", |
| 2705 | i, |
| 2706 | le32_to_cpu(np->tx_ring.ex[i].bufhigh), |
| 2707 | le32_to_cpu(np->tx_ring.ex[i].buflow), |
| 2708 | le32_to_cpu(np->tx_ring.ex[i].flaglen), |
| 2709 | le32_to_cpu(np->tx_ring.ex[i+1].bufhigh), |
| 2710 | le32_to_cpu(np->tx_ring.ex[i+1].buflow), |
| 2711 | le32_to_cpu(np->tx_ring.ex[i+1].flaglen), |
| 2712 | le32_to_cpu(np->tx_ring.ex[i+2].bufhigh), |
| 2713 | le32_to_cpu(np->tx_ring.ex[i+2].buflow), |
| 2714 | le32_to_cpu(np->tx_ring.ex[i+2].flaglen), |
| 2715 | le32_to_cpu(np->tx_ring.ex[i+3].bufhigh), |
| 2716 | le32_to_cpu(np->tx_ring.ex[i+3].buflow), |
| 2717 | le32_to_cpu(np->tx_ring.ex[i+3].flaglen)); |
| 2718 | } |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 2719 | } |
| 2720 | } |
| 2721 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2722 | spin_lock_irq(&np->lock); |
| 2723 | |
| 2724 | /* 1) stop tx engine */ |
| 2725 | nv_stop_tx(dev); |
| 2726 | |
Ayaz Abdulla | 8f955d7 | 2009-04-25 09:17:56 +0000 | [diff] [blame] | 2727 | /* 2) complete any outstanding tx and do not give HW any limited tx pkts */ |
| 2728 | saved_tx_limit = np->tx_limit; |
| 2729 | np->tx_limit = 0; /* prevent giving HW any limited pkts */ |
| 2730 | np->tx_stop = 0; /* prevent waking tx queue */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 2731 | if (!nv_optimized(np)) |
Ayaz Abdulla | 33912e7 | 2009-03-05 08:02:10 +0000 | [diff] [blame] | 2732 | nv_tx_done(dev, np->tx_ring_size); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2733 | else |
Ayaz Abdulla | 4e16ed1 | 2007-01-23 12:00:56 -0500 | [diff] [blame] | 2734 | nv_tx_done_optimized(dev, np->tx_ring_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2735 | |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 2736 | /* save current HW position */ |
Ayaz Abdulla | 8f955d7 | 2009-04-25 09:17:56 +0000 | [diff] [blame] | 2737 | if (np->tx_change_owner) |
| 2738 | put_tx.ex = np->tx_change_owner->first_tx_desc; |
| 2739 | else |
| 2740 | put_tx = np->put_tx; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2741 | |
Ayaz Abdulla | 8f955d7 | 2009-04-25 09:17:56 +0000 | [diff] [blame] | 2742 | /* 3) clear all tx state */ |
| 2743 | nv_drain_tx(dev); |
| 2744 | nv_init_tx(dev); |
Ayaz Abdulla | 3ba4d09 | 2007-03-23 05:50:02 -0500 | [diff] [blame] | 2745 | |
Ayaz Abdulla | 8f955d7 | 2009-04-25 09:17:56 +0000 | [diff] [blame] | 2746 | /* 4) restore state to current HW position */ |
| 2747 | np->get_tx = np->put_tx = put_tx; |
| 2748 | np->tx_limit = saved_tx_limit; |
| 2749 | |
| 2750 | /* 5) restart tx engine */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2751 | nv_start_tx(dev); |
Ayaz Abdulla | 8f955d7 | 2009-04-25 09:17:56 +0000 | [diff] [blame] | 2752 | netif_wake_queue(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2753 | spin_unlock_irq(&np->lock); |
| 2754 | } |
| 2755 | |
Manfred Spraul | 22c6d14 | 2005-04-19 21:17:09 +0200 | [diff] [blame] | 2756 | /* |
| 2757 | * Called when the nic notices a mismatch between the actual data len on the |
| 2758 | * wire and the len indicated in the 802 header |
| 2759 | */ |
| 2760 | static int nv_getlen(struct net_device *dev, void *packet, int datalen) |
| 2761 | { |
| 2762 | int hdrlen; /* length of the 802 header */ |
| 2763 | int protolen; /* length as stored in the proto field */ |
| 2764 | |
| 2765 | /* 1) calculate len according to header */ |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 2766 | if (((struct vlan_ethhdr *)packet)->h_vlan_proto == htons(ETH_P_8021Q)) { |
| 2767 | protolen = ntohs(((struct vlan_ethhdr *)packet)->h_vlan_encapsulated_proto); |
Manfred Spraul | 22c6d14 | 2005-04-19 21:17:09 +0200 | [diff] [blame] | 2768 | hdrlen = VLAN_HLEN; |
| 2769 | } else { |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 2770 | protolen = ntohs(((struct ethhdr *)packet)->h_proto); |
Manfred Spraul | 22c6d14 | 2005-04-19 21:17:09 +0200 | [diff] [blame] | 2771 | hdrlen = ETH_HLEN; |
| 2772 | } |
Manfred Spraul | 22c6d14 | 2005-04-19 21:17:09 +0200 | [diff] [blame] | 2773 | if (protolen > ETH_DATA_LEN) |
| 2774 | return datalen; /* Value in proto field not a len, no checks possible */ |
| 2775 | |
| 2776 | protolen += hdrlen; |
| 2777 | /* consistency checks: */ |
| 2778 | if (datalen > ETH_ZLEN) { |
| 2779 | if (datalen >= protolen) { |
| 2780 | /* more data on wire than in 802 header, trim of |
| 2781 | * additional data. |
| 2782 | */ |
Manfred Spraul | 22c6d14 | 2005-04-19 21:17:09 +0200 | [diff] [blame] | 2783 | return protolen; |
| 2784 | } else { |
| 2785 | /* less data on wire than mentioned in header. |
| 2786 | * Discard the packet. |
| 2787 | */ |
Manfred Spraul | 22c6d14 | 2005-04-19 21:17:09 +0200 | [diff] [blame] | 2788 | return -1; |
| 2789 | } |
| 2790 | } else { |
| 2791 | /* short packet. Accept only if 802 values are also short */ |
| 2792 | if (protolen > ETH_ZLEN) { |
Manfred Spraul | 22c6d14 | 2005-04-19 21:17:09 +0200 | [diff] [blame] | 2793 | return -1; |
| 2794 | } |
Manfred Spraul | 22c6d14 | 2005-04-19 21:17:09 +0200 | [diff] [blame] | 2795 | return datalen; |
| 2796 | } |
| 2797 | } |
| 2798 | |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 2799 | static int nv_rx_process(struct net_device *dev, int limit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2800 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 2801 | struct fe_priv *np = netdev_priv(dev); |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 2802 | u32 flags; |
Ingo Molnar | bcb5feb | 2007-10-16 20:44:59 -0400 | [diff] [blame] | 2803 | int rx_work = 0; |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2804 | struct sk_buff *skb; |
| 2805 | int len; |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 2806 | |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 2807 | while ((np->get_rx.orig != np->put_rx.orig) && |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2808 | !((flags = le32_to_cpu(np->get_rx.orig->flaglen)) & NV_RX_AVAIL) && |
Ingo Molnar | bcb5feb | 2007-10-16 20:44:59 -0400 | [diff] [blame] | 2809 | (rx_work < limit)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2810 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2811 | /* |
| 2812 | * the packet is for us - immediately tear down the pci mapping. |
| 2813 | * TODO: check if a prefetch of the first cacheline improves |
| 2814 | * the performance. |
| 2815 | */ |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2816 | pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma, |
| 2817 | np->get_rx_ctx->dma_len, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2818 | PCI_DMA_FROMDEVICE); |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 2819 | skb = np->get_rx_ctx->skb; |
| 2820 | np->get_rx_ctx->skb = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2821 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2822 | /* look at what we actually got: */ |
| 2823 | if (np->desc_ver == DESC_VER_1) { |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2824 | if (likely(flags & NV_RX_DESCRIPTORVALID)) { |
| 2825 | len = flags & LEN_MASK_V1; |
| 2826 | if (unlikely(flags & NV_RX_ERROR)) { |
Ayaz Abdulla | 1ef6841 | 2008-08-06 12:11:03 -0400 | [diff] [blame] | 2827 | if ((flags & NV_RX_ERROR_MASK) == NV_RX_ERROR4) { |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2828 | len = nv_getlen(dev, skb->data, len); |
| 2829 | if (len < 0) { |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2830 | dev_kfree_skb(skb); |
| 2831 | goto next_pkt; |
| 2832 | } |
| 2833 | } |
| 2834 | /* framing errors are soft errors */ |
Ayaz Abdulla | 1ef6841 | 2008-08-06 12:11:03 -0400 | [diff] [blame] | 2835 | else if ((flags & NV_RX_ERROR_MASK) == NV_RX_FRAMINGERR) { |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 2836 | if (flags & NV_RX_SUBSTRACT1) |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2837 | len--; |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2838 | } |
| 2839 | /* the rest are hard errors */ |
| 2840 | else { |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 2841 | if (flags & NV_RX_MISSEDFRAME) { |
| 2842 | u64_stats_update_begin(&np->swstats_rx_syncp); |
| 2843 | np->stat_rx_missed_errors++; |
| 2844 | u64_stats_update_end(&np->swstats_rx_syncp); |
| 2845 | } |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 2846 | dev_kfree_skb(skb); |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2847 | goto next_pkt; |
| 2848 | } |
| 2849 | } |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2850 | } else { |
| 2851 | dev_kfree_skb(skb); |
| 2852 | goto next_pkt; |
Manfred Spraul | 22c6d14 | 2005-04-19 21:17:09 +0200 | [diff] [blame] | 2853 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2854 | } else { |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2855 | if (likely(flags & NV_RX2_DESCRIPTORVALID)) { |
| 2856 | len = flags & LEN_MASK_V2; |
| 2857 | if (unlikely(flags & NV_RX2_ERROR)) { |
Ayaz Abdulla | 1ef6841 | 2008-08-06 12:11:03 -0400 | [diff] [blame] | 2858 | if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_ERROR4) { |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2859 | len = nv_getlen(dev, skb->data, len); |
| 2860 | if (len < 0) { |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2861 | dev_kfree_skb(skb); |
| 2862 | goto next_pkt; |
| 2863 | } |
| 2864 | } |
| 2865 | /* framing errors are soft errors */ |
Ayaz Abdulla | 1ef6841 | 2008-08-06 12:11:03 -0400 | [diff] [blame] | 2866 | else if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_FRAMINGERR) { |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 2867 | if (flags & NV_RX2_SUBSTRACT1) |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2868 | len--; |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2869 | } |
| 2870 | /* the rest are hard errors */ |
| 2871 | else { |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 2872 | dev_kfree_skb(skb); |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 2873 | goto next_pkt; |
| 2874 | } |
| 2875 | } |
Ayaz Abdulla | bfaffe8 | 2008-01-13 16:02:55 -0500 | [diff] [blame] | 2876 | if (((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_TCP) || /*ip and tcp */ |
| 2877 | ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_UDP)) /*ip and udp */ |
Ayaz Abdulla | 0d63fb3 | 2007-01-09 13:30:13 -0500 | [diff] [blame] | 2878 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2879 | } else { |
| 2880 | dev_kfree_skb(skb); |
| 2881 | goto next_pkt; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2882 | } |
| 2883 | } |
| 2884 | /* got a valid packet - forward it to the network core */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2885 | skb_put(skb, len); |
| 2886 | skb->protocol = eth_type_trans(skb, dev); |
Tom Herbert | 53f224c | 2010-05-03 19:08:45 +0000 | [diff] [blame] | 2887 | napi_gro_receive(&np->napi, skb); |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 2888 | u64_stats_update_begin(&np->swstats_rx_syncp); |
| 2889 | np->stat_rx_packets++; |
| 2890 | np->stat_rx_bytes += len; |
| 2891 | u64_stats_update_end(&np->swstats_rx_syncp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2892 | next_pkt: |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2893 | if (unlikely(np->get_rx.orig++ == np->last_rx.orig)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2894 | np->get_rx.orig = np->first_rx.orig; |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2895 | if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2896 | np->get_rx_ctx = np->first_rx_ctx; |
Ingo Molnar | bcb5feb | 2007-10-16 20:44:59 -0400 | [diff] [blame] | 2897 | |
| 2898 | rx_work++; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2899 | } |
| 2900 | |
Ingo Molnar | bcb5feb | 2007-10-16 20:44:59 -0400 | [diff] [blame] | 2901 | return rx_work; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2902 | } |
| 2903 | |
| 2904 | static int nv_rx_process_optimized(struct net_device *dev, int limit) |
| 2905 | { |
| 2906 | struct fe_priv *np = netdev_priv(dev); |
| 2907 | u32 flags; |
| 2908 | u32 vlanflags = 0; |
Ingo Molnar | c1b7151 | 2007-10-17 12:18:23 +0200 | [diff] [blame] | 2909 | int rx_work = 0; |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2910 | struct sk_buff *skb; |
| 2911 | int len; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2912 | |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 2913 | while ((np->get_rx.ex != np->put_rx.ex) && |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2914 | !((flags = le32_to_cpu(np->get_rx.ex->flaglen)) & NV_RX2_AVAIL) && |
Ingo Molnar | c1b7151 | 2007-10-17 12:18:23 +0200 | [diff] [blame] | 2915 | (rx_work < limit)) { |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2916 | |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2917 | /* |
| 2918 | * the packet is for us - immediately tear down the pci mapping. |
| 2919 | * TODO: check if a prefetch of the first cacheline improves |
| 2920 | * the performance. |
| 2921 | */ |
| 2922 | pci_unmap_single(np->pci_dev, np->get_rx_ctx->dma, |
| 2923 | np->get_rx_ctx->dma_len, |
| 2924 | PCI_DMA_FROMDEVICE); |
| 2925 | skb = np->get_rx_ctx->skb; |
| 2926 | np->get_rx_ctx->skb = NULL; |
| 2927 | |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2928 | /* look at what we actually got: */ |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2929 | if (likely(flags & NV_RX2_DESCRIPTORVALID)) { |
| 2930 | len = flags & LEN_MASK_V2; |
| 2931 | if (unlikely(flags & NV_RX2_ERROR)) { |
Ayaz Abdulla | 1ef6841 | 2008-08-06 12:11:03 -0400 | [diff] [blame] | 2932 | if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_ERROR4) { |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2933 | len = nv_getlen(dev, skb->data, len); |
| 2934 | if (len < 0) { |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2935 | dev_kfree_skb(skb); |
| 2936 | goto next_pkt; |
| 2937 | } |
| 2938 | } |
| 2939 | /* framing errors are soft errors */ |
Ayaz Abdulla | 1ef6841 | 2008-08-06 12:11:03 -0400 | [diff] [blame] | 2940 | else if ((flags & NV_RX2_ERROR_MASK) == NV_RX2_FRAMINGERR) { |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 2941 | if (flags & NV_RX2_SUBSTRACT1) |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2942 | len--; |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2943 | } |
| 2944 | /* the rest are hard errors */ |
| 2945 | else { |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2946 | dev_kfree_skb(skb); |
| 2947 | goto next_pkt; |
| 2948 | } |
| 2949 | } |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2950 | |
Ayaz Abdulla | bfaffe8 | 2008-01-13 16:02:55 -0500 | [diff] [blame] | 2951 | if (((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_TCP) || /*ip and tcp */ |
| 2952 | ((flags & NV_RX2_CHECKSUMMASK) == NV_RX2_CHECKSUM_IP_UDP)) /*ip and udp */ |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2953 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2954 | |
| 2955 | /* got a valid packet - forward it to the network core */ |
| 2956 | skb_put(skb, len); |
| 2957 | skb->protocol = eth_type_trans(skb, dev); |
| 2958 | prefetch(skb->data); |
| 2959 | |
Jiri Pirko | 3326c78 | 2011-07-20 04:54:38 +0000 | [diff] [blame] | 2960 | vlanflags = le32_to_cpu(np->get_rx.ex->buflow); |
Jiri Pirko | 0891b0e | 2011-07-26 10:19:28 +0000 | [diff] [blame] | 2961 | |
| 2962 | /* |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 2963 | * There's need to check for NETIF_F_HW_VLAN_CTAG_RX |
| 2964 | * here. Even if vlan rx accel is disabled, |
Jiri Pirko | 0891b0e | 2011-07-26 10:19:28 +0000 | [diff] [blame] | 2965 | * NV_RX3_VLAN_TAG_PRESENT is pseudo randomly set. |
| 2966 | */ |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 2967 | if (dev->features & NETIF_F_HW_VLAN_CTAG_RX && |
Jiri Pirko | 0891b0e | 2011-07-26 10:19:28 +0000 | [diff] [blame] | 2968 | vlanflags & NV_RX3_VLAN_TAG_PRESENT) { |
Jiri Pirko | 3326c78 | 2011-07-20 04:54:38 +0000 | [diff] [blame] | 2969 | u16 vid = vlanflags & NV_RX3_VLAN_TAG_MASK; |
| 2970 | |
Patrick McHardy | 86a9bad | 2013-04-19 02:04:30 +0000 | [diff] [blame] | 2971 | __vlan_hwaccel_put_tag(skb, htons(ETH_P_8021Q), vid); |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2972 | } |
Jiri Pirko | 3326c78 | 2011-07-20 04:54:38 +0000 | [diff] [blame] | 2973 | napi_gro_receive(&np->napi, skb); |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 2974 | u64_stats_update_begin(&np->swstats_rx_syncp); |
| 2975 | np->stat_rx_packets++; |
| 2976 | np->stat_rx_bytes += len; |
| 2977 | u64_stats_update_end(&np->swstats_rx_syncp); |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2978 | } else { |
| 2979 | dev_kfree_skb(skb); |
| 2980 | } |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2981 | next_pkt: |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2982 | if (unlikely(np->get_rx.ex++ == np->last_rx.ex)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 2983 | np->get_rx.ex = np->first_rx.ex; |
Ayaz Abdulla | b01867c | 2007-01-21 18:10:52 -0500 | [diff] [blame] | 2984 | if (unlikely(np->get_rx_ctx++ == np->last_rx_ctx)) |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 2985 | np->get_rx_ctx = np->first_rx_ctx; |
Ingo Molnar | c1b7151 | 2007-10-17 12:18:23 +0200 | [diff] [blame] | 2986 | |
| 2987 | rx_work++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2988 | } |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 2989 | |
Ingo Molnar | c1b7151 | 2007-10-17 12:18:23 +0200 | [diff] [blame] | 2990 | return rx_work; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2991 | } |
| 2992 | |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 2993 | static void set_bufsize(struct net_device *dev) |
| 2994 | { |
| 2995 | struct fe_priv *np = netdev_priv(dev); |
| 2996 | |
| 2997 | if (dev->mtu <= ETH_DATA_LEN) |
| 2998 | np->rx_buf_sz = ETH_DATA_LEN + NV_RX_HEADERS; |
| 2999 | else |
| 3000 | np->rx_buf_sz = dev->mtu + NV_RX_HEADERS; |
| 3001 | } |
| 3002 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3003 | /* |
| 3004 | * nv_change_mtu: dev->change_mtu function |
| 3005 | * Called with dev_base_lock held for read. |
| 3006 | */ |
| 3007 | static int nv_change_mtu(struct net_device *dev, int new_mtu) |
| 3008 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 3009 | struct fe_priv *np = netdev_priv(dev); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 3010 | int old_mtu; |
| 3011 | |
| 3012 | if (new_mtu < 64 || new_mtu > np->pkt_limit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3013 | return -EINVAL; |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 3014 | |
| 3015 | old_mtu = dev->mtu; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3016 | dev->mtu = new_mtu; |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 3017 | |
| 3018 | /* return early if the buffer sizes will not change */ |
| 3019 | if (old_mtu <= ETH_DATA_LEN && new_mtu <= ETH_DATA_LEN) |
| 3020 | return 0; |
| 3021 | if (old_mtu == new_mtu) |
| 3022 | return 0; |
| 3023 | |
| 3024 | /* synchronized against open : rtnl_lock() held by caller */ |
| 3025 | if (netif_running(dev)) { |
viro@ftp.linux.org.uk | 25097d4 | 2005-09-06 01:36:58 +0100 | [diff] [blame] | 3026 | u8 __iomem *base = get_hwbase(dev); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 3027 | /* |
| 3028 | * It seems that the nic preloads valid ring entries into an |
| 3029 | * internal buffer. The procedure for flushing everything is |
| 3030 | * guessed, there is probably a simpler approach. |
| 3031 | * Changing the MTU is a rare event, it shouldn't matter. |
| 3032 | */ |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 3033 | nv_disable_irq(dev); |
Ayaz Abdulla | 08d9357 | 2009-03-05 08:01:55 +0000 | [diff] [blame] | 3034 | nv_napi_disable(dev); |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 3035 | netif_tx_lock_bh(dev); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 3036 | netif_addr_lock(dev); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 3037 | spin_lock(&np->lock); |
| 3038 | /* stop engines */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 3039 | nv_stop_rxtx(dev); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 3040 | nv_txrx_reset(dev); |
| 3041 | /* drain rx queue */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 3042 | nv_drain_rxtx(dev); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 3043 | /* reinit driver view of the rx queue */ |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 3044 | set_bufsize(dev); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 3045 | if (nv_init_ring(dev)) { |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 3046 | if (!np->in_shutdown) |
| 3047 | mod_timer(&np->oom_kick, jiffies + OOM_REFILL); |
| 3048 | } |
| 3049 | /* reinit nic view of the rx queue */ |
| 3050 | writel(np->rx_buf_sz, base + NvRegOffloadConfig); |
Ayaz Abdulla | 0832b25 | 2006-02-04 13:13:26 -0500 | [diff] [blame] | 3051 | setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING); |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 3052 | writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT), |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 3053 | base + NvRegRingSizes); |
| 3054 | pci_push(base); |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 3055 | writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 3056 | pci_push(base); |
| 3057 | |
| 3058 | /* restart rx engine */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 3059 | nv_start_rxtx(dev); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 3060 | spin_unlock(&np->lock); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 3061 | netif_addr_unlock(dev); |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 3062 | netif_tx_unlock_bh(dev); |
Ayaz Abdulla | 08d9357 | 2009-03-05 08:01:55 +0000 | [diff] [blame] | 3063 | nv_napi_enable(dev); |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 3064 | nv_enable_irq(dev); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 3065 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3066 | return 0; |
| 3067 | } |
| 3068 | |
Manfred Spraul | 72b3178 | 2005-07-31 18:33:34 +0200 | [diff] [blame] | 3069 | static void nv_copy_mac_to_hw(struct net_device *dev) |
| 3070 | { |
viro@ftp.linux.org.uk | 25097d4 | 2005-09-06 01:36:58 +0100 | [diff] [blame] | 3071 | u8 __iomem *base = get_hwbase(dev); |
Manfred Spraul | 72b3178 | 2005-07-31 18:33:34 +0200 | [diff] [blame] | 3072 | u32 mac[2]; |
| 3073 | |
| 3074 | mac[0] = (dev->dev_addr[0] << 0) + (dev->dev_addr[1] << 8) + |
| 3075 | (dev->dev_addr[2] << 16) + (dev->dev_addr[3] << 24); |
| 3076 | mac[1] = (dev->dev_addr[4] << 0) + (dev->dev_addr[5] << 8); |
| 3077 | |
| 3078 | writel(mac[0], base + NvRegMacAddrA); |
| 3079 | writel(mac[1], base + NvRegMacAddrB); |
| 3080 | } |
| 3081 | |
| 3082 | /* |
| 3083 | * nv_set_mac_address: dev->set_mac_address function |
| 3084 | * Called with rtnl_lock() held. |
| 3085 | */ |
| 3086 | static int nv_set_mac_address(struct net_device *dev, void *addr) |
| 3087 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 3088 | struct fe_priv *np = netdev_priv(dev); |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 3089 | struct sockaddr *macaddr = (struct sockaddr *)addr; |
Manfred Spraul | 72b3178 | 2005-07-31 18:33:34 +0200 | [diff] [blame] | 3090 | |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 3091 | if (!is_valid_ether_addr(macaddr->sa_data)) |
Manfred Spraul | 72b3178 | 2005-07-31 18:33:34 +0200 | [diff] [blame] | 3092 | return -EADDRNOTAVAIL; |
| 3093 | |
| 3094 | /* synchronized against open : rtnl_lock() held by caller */ |
| 3095 | memcpy(dev->dev_addr, macaddr->sa_data, ETH_ALEN); |
| 3096 | |
| 3097 | if (netif_running(dev)) { |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 3098 | netif_tx_lock_bh(dev); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 3099 | netif_addr_lock(dev); |
Manfred Spraul | 72b3178 | 2005-07-31 18:33:34 +0200 | [diff] [blame] | 3100 | spin_lock_irq(&np->lock); |
| 3101 | |
| 3102 | /* stop rx engine */ |
| 3103 | nv_stop_rx(dev); |
| 3104 | |
| 3105 | /* set mac address */ |
| 3106 | nv_copy_mac_to_hw(dev); |
| 3107 | |
| 3108 | /* restart rx engine */ |
| 3109 | nv_start_rx(dev); |
| 3110 | spin_unlock_irq(&np->lock); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 3111 | netif_addr_unlock(dev); |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 3112 | netif_tx_unlock_bh(dev); |
Manfred Spraul | 72b3178 | 2005-07-31 18:33:34 +0200 | [diff] [blame] | 3113 | } else { |
| 3114 | nv_copy_mac_to_hw(dev); |
| 3115 | } |
| 3116 | return 0; |
| 3117 | } |
| 3118 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3119 | /* |
| 3120 | * nv_set_multicast: dev->set_multicast function |
Herbert Xu | 932ff27 | 2006-06-09 12:20:56 -0700 | [diff] [blame] | 3121 | * Called with netif_tx_lock held. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3122 | */ |
| 3123 | static void nv_set_multicast(struct net_device *dev) |
| 3124 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 3125 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3126 | u8 __iomem *base = get_hwbase(dev); |
| 3127 | u32 addr[2]; |
| 3128 | u32 mask[2]; |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 3129 | u32 pff = readl(base + NvRegPacketFilterFlags) & NVREG_PFF_PAUSE_RX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3130 | |
| 3131 | memset(addr, 0, sizeof(addr)); |
| 3132 | memset(mask, 0, sizeof(mask)); |
| 3133 | |
| 3134 | if (dev->flags & IFF_PROMISC) { |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 3135 | pff |= NVREG_PFF_PROMISC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3136 | } else { |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 3137 | pff |= NVREG_PFF_MYADDR; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3138 | |
Jiri Pirko | 48e2f18 | 2010-02-22 09:22:26 +0000 | [diff] [blame] | 3139 | if (dev->flags & IFF_ALLMULTI || !netdev_mc_empty(dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3140 | u32 alwaysOff[2]; |
| 3141 | u32 alwaysOn[2]; |
| 3142 | |
| 3143 | alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0xffffffff; |
| 3144 | if (dev->flags & IFF_ALLMULTI) { |
| 3145 | alwaysOn[0] = alwaysOn[1] = alwaysOff[0] = alwaysOff[1] = 0; |
| 3146 | } else { |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3147 | struct netdev_hw_addr *ha; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3148 | |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3149 | netdev_for_each_mc_addr(ha, dev) { |
david decotigny | e45a618 | 2011-11-05 14:38:24 +0000 | [diff] [blame] | 3150 | unsigned char *hw_addr = ha->addr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3151 | u32 a, b; |
Jiri Pirko | 22bedad3 | 2010-04-01 21:22:57 +0000 | [diff] [blame] | 3152 | |
david decotigny | e45a618 | 2011-11-05 14:38:24 +0000 | [diff] [blame] | 3153 | a = le32_to_cpu(*(__le32 *) hw_addr); |
| 3154 | b = le16_to_cpu(*(__le16 *) (&hw_addr[4])); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3155 | alwaysOn[0] &= a; |
| 3156 | alwaysOff[0] &= ~a; |
| 3157 | alwaysOn[1] &= b; |
| 3158 | alwaysOff[1] &= ~b; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3159 | } |
| 3160 | } |
| 3161 | addr[0] = alwaysOn[0]; |
| 3162 | addr[1] = alwaysOn[1]; |
| 3163 | mask[0] = alwaysOn[0] | alwaysOff[0]; |
| 3164 | mask[1] = alwaysOn[1] | alwaysOff[1]; |
Ayaz Abdulla | bb9a4fd | 2008-01-13 16:03:04 -0500 | [diff] [blame] | 3165 | } else { |
| 3166 | mask[0] = NVREG_MCASTMASKA_NONE; |
| 3167 | mask[1] = NVREG_MCASTMASKB_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3168 | } |
| 3169 | } |
| 3170 | addr[0] |= NVREG_MCASTADDRA_FORCE; |
| 3171 | pff |= NVREG_PFF_ALWAYS; |
| 3172 | spin_lock_irq(&np->lock); |
| 3173 | nv_stop_rx(dev); |
| 3174 | writel(addr[0], base + NvRegMulticastAddrA); |
| 3175 | writel(addr[1], base + NvRegMulticastAddrB); |
| 3176 | writel(mask[0], base + NvRegMulticastMaskA); |
| 3177 | writel(mask[1], base + NvRegMulticastMaskB); |
| 3178 | writel(pff, base + NvRegPacketFilterFlags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3179 | nv_start_rx(dev); |
| 3180 | spin_unlock_irq(&np->lock); |
| 3181 | } |
| 3182 | |
Adrian Bunk | c798505 | 2006-06-22 12:03:29 +0200 | [diff] [blame] | 3183 | static void nv_update_pause(struct net_device *dev, u32 pause_flags) |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 3184 | { |
| 3185 | struct fe_priv *np = netdev_priv(dev); |
| 3186 | u8 __iomem *base = get_hwbase(dev); |
| 3187 | |
| 3188 | np->pause_flags &= ~(NV_PAUSEFRAME_TX_ENABLE | NV_PAUSEFRAME_RX_ENABLE); |
| 3189 | |
| 3190 | if (np->pause_flags & NV_PAUSEFRAME_RX_CAPABLE) { |
| 3191 | u32 pff = readl(base + NvRegPacketFilterFlags) & ~NVREG_PFF_PAUSE_RX; |
| 3192 | if (pause_flags & NV_PAUSEFRAME_RX_ENABLE) { |
| 3193 | writel(pff|NVREG_PFF_PAUSE_RX, base + NvRegPacketFilterFlags); |
| 3194 | np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE; |
| 3195 | } else { |
| 3196 | writel(pff, base + NvRegPacketFilterFlags); |
| 3197 | } |
| 3198 | } |
| 3199 | if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE) { |
| 3200 | u32 regmisc = readl(base + NvRegMisc1) & ~NVREG_MISC1_PAUSE_TX; |
| 3201 | if (pause_flags & NV_PAUSEFRAME_TX_ENABLE) { |
Ayaz Abdulla | 5289b4c | 2008-02-05 12:30:01 -0500 | [diff] [blame] | 3202 | u32 pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V1; |
| 3203 | if (np->driver_data & DEV_HAS_PAUSEFRAME_TX_V2) |
| 3204 | pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V2; |
Ayaz Abdulla | 9a33e88 | 2008-08-06 12:12:34 -0400 | [diff] [blame] | 3205 | if (np->driver_data & DEV_HAS_PAUSEFRAME_TX_V3) { |
Ayaz Abdulla | 5289b4c | 2008-02-05 12:30:01 -0500 | [diff] [blame] | 3206 | pause_enable = NVREG_TX_PAUSEFRAME_ENABLE_V3; |
Ayaz Abdulla | 9a33e88 | 2008-08-06 12:12:34 -0400 | [diff] [blame] | 3207 | /* limit the number of tx pause frames to a default of 8 */ |
| 3208 | writel(readl(base + NvRegTxPauseFrameLimit)|NVREG_TX_PAUSEFRAMELIMIT_ENABLE, base + NvRegTxPauseFrameLimit); |
| 3209 | } |
Ayaz Abdulla | 5289b4c | 2008-02-05 12:30:01 -0500 | [diff] [blame] | 3210 | writel(pause_enable, base + NvRegTxPauseFrame); |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 3211 | writel(regmisc|NVREG_MISC1_PAUSE_TX, base + NvRegMisc1); |
| 3212 | np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE; |
| 3213 | } else { |
| 3214 | writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame); |
| 3215 | writel(regmisc, base + NvRegMisc1); |
| 3216 | } |
| 3217 | } |
| 3218 | } |
| 3219 | |
Sanjay Hortikar | e19df76 | 2011-11-11 16:11:21 +0000 | [diff] [blame] | 3220 | static void nv_force_linkspeed(struct net_device *dev, int speed, int duplex) |
| 3221 | { |
| 3222 | struct fe_priv *np = netdev_priv(dev); |
| 3223 | u8 __iomem *base = get_hwbase(dev); |
| 3224 | u32 phyreg, txreg; |
| 3225 | int mii_status; |
| 3226 | |
| 3227 | np->linkspeed = NVREG_LINKSPEED_FORCE|speed; |
| 3228 | np->duplex = duplex; |
| 3229 | |
| 3230 | /* see if gigabit phy */ |
| 3231 | mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ); |
| 3232 | if (mii_status & PHY_GIGABIT) { |
| 3233 | np->gigabit = PHY_GIGABIT; |
| 3234 | phyreg = readl(base + NvRegSlotTime); |
| 3235 | phyreg &= ~(0x3FF00); |
| 3236 | if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10) |
| 3237 | phyreg |= NVREG_SLOTTIME_10_100_FULL; |
| 3238 | else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100) |
| 3239 | phyreg |= NVREG_SLOTTIME_10_100_FULL; |
| 3240 | else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000) |
| 3241 | phyreg |= NVREG_SLOTTIME_1000_FULL; |
| 3242 | writel(phyreg, base + NvRegSlotTime); |
| 3243 | } |
| 3244 | |
| 3245 | phyreg = readl(base + NvRegPhyInterface); |
| 3246 | phyreg &= ~(PHY_HALF|PHY_100|PHY_1000); |
| 3247 | if (np->duplex == 0) |
| 3248 | phyreg |= PHY_HALF; |
| 3249 | if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100) |
| 3250 | phyreg |= PHY_100; |
| 3251 | else if ((np->linkspeed & NVREG_LINKSPEED_MASK) == |
| 3252 | NVREG_LINKSPEED_1000) |
| 3253 | phyreg |= PHY_1000; |
| 3254 | writel(phyreg, base + NvRegPhyInterface); |
| 3255 | |
| 3256 | if (phyreg & PHY_RGMII) { |
| 3257 | if ((np->linkspeed & NVREG_LINKSPEED_MASK) == |
| 3258 | NVREG_LINKSPEED_1000) |
| 3259 | txreg = NVREG_TX_DEFERRAL_RGMII_1000; |
| 3260 | else |
| 3261 | txreg = NVREG_TX_DEFERRAL_RGMII_10_100; |
| 3262 | } else { |
| 3263 | txreg = NVREG_TX_DEFERRAL_DEFAULT; |
| 3264 | } |
| 3265 | writel(txreg, base + NvRegTxDeferral); |
| 3266 | |
| 3267 | if (np->desc_ver == DESC_VER_1) { |
| 3268 | txreg = NVREG_TX_WM_DESC1_DEFAULT; |
| 3269 | } else { |
| 3270 | if ((np->linkspeed & NVREG_LINKSPEED_MASK) == |
| 3271 | NVREG_LINKSPEED_1000) |
| 3272 | txreg = NVREG_TX_WM_DESC2_3_1000; |
| 3273 | else |
| 3274 | txreg = NVREG_TX_WM_DESC2_3_DEFAULT; |
| 3275 | } |
| 3276 | writel(txreg, base + NvRegTxWatermark); |
| 3277 | |
| 3278 | writel(NVREG_MISC1_FORCE | (np->duplex ? 0 : NVREG_MISC1_HD), |
| 3279 | base + NvRegMisc1); |
| 3280 | pci_push(base); |
| 3281 | writel(np->linkspeed, base + NvRegLinkSpeed); |
| 3282 | pci_push(base); |
| 3283 | |
| 3284 | return; |
| 3285 | } |
| 3286 | |
Ayaz Abdulla | 4ea7f29 | 2005-11-11 08:29:59 -0500 | [diff] [blame] | 3287 | /** |
Ben Hutchings | 49ce9c2 | 2012-07-10 10:56:00 +0000 | [diff] [blame] | 3288 | * nv_update_linkspeed - Setup the MAC according to the link partner |
Ayaz Abdulla | 4ea7f29 | 2005-11-11 08:29:59 -0500 | [diff] [blame] | 3289 | * @dev: Network device to be configured |
| 3290 | * |
| 3291 | * The function queries the PHY and checks if there is a link partner. |
| 3292 | * If yes, then it sets up the MAC accordingly. Otherwise, the MAC is |
| 3293 | * set to 10 MBit HD. |
| 3294 | * |
| 3295 | * The function returns 0 if there is no link partner and 1 if there is |
| 3296 | * a good link partner. |
| 3297 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3298 | static int nv_update_linkspeed(struct net_device *dev) |
| 3299 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 3300 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3301 | u8 __iomem *base = get_hwbase(dev); |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 3302 | int adv = 0; |
| 3303 | int lpa = 0; |
| 3304 | int adv_lpa, adv_pause, lpa_pause; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3305 | int newls = np->linkspeed; |
| 3306 | int newdup = np->duplex; |
| 3307 | int mii_status; |
Sanjay Hortikar | e19df76 | 2011-11-11 16:11:21 +0000 | [diff] [blame] | 3308 | u32 bmcr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3309 | int retval = 0; |
Ayaz Abdulla | 9744e21 | 2006-07-06 16:45:58 -0400 | [diff] [blame] | 3310 | u32 control_1000, status_1000, phyreg, pause_flags, txreg; |
Ayaz Abdulla | b2976d2 | 2008-02-04 15:13:59 -0500 | [diff] [blame] | 3311 | u32 txrxFlags = 0; |
Ayaz Abdulla | fd9b558 | 2008-02-05 12:29:49 -0500 | [diff] [blame] | 3312 | u32 phy_exp; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3313 | |
Sanjay Hortikar | e19df76 | 2011-11-11 16:11:21 +0000 | [diff] [blame] | 3314 | /* If device loopback is enabled, set carrier on and enable max link |
| 3315 | * speed. |
| 3316 | */ |
| 3317 | bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
| 3318 | if (bmcr & BMCR_LOOPBACK) { |
| 3319 | if (netif_running(dev)) { |
| 3320 | nv_force_linkspeed(dev, NVREG_LINKSPEED_1000, 1); |
| 3321 | if (!netif_carrier_ok(dev)) |
| 3322 | netif_carrier_on(dev); |
| 3323 | } |
| 3324 | return 1; |
| 3325 | } |
| 3326 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3327 | /* BMSR_LSTATUS is latched, read it twice: |
| 3328 | * we want the current value. |
| 3329 | */ |
| 3330 | mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ); |
| 3331 | mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ); |
| 3332 | |
| 3333 | if (!(mii_status & BMSR_LSTATUS)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3334 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 3335 | newdup = 0; |
| 3336 | retval = 0; |
| 3337 | goto set_speed; |
| 3338 | } |
| 3339 | |
| 3340 | if (np->autoneg == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3341 | if (np->fixed_mode & LPA_100FULL) { |
| 3342 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100; |
| 3343 | newdup = 1; |
| 3344 | } else if (np->fixed_mode & LPA_100HALF) { |
| 3345 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100; |
| 3346 | newdup = 0; |
| 3347 | } else if (np->fixed_mode & LPA_10FULL) { |
| 3348 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 3349 | newdup = 1; |
| 3350 | } else { |
| 3351 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 3352 | newdup = 0; |
| 3353 | } |
| 3354 | retval = 1; |
| 3355 | goto set_speed; |
| 3356 | } |
| 3357 | /* check auto negotiation is complete */ |
| 3358 | if (!(mii_status & BMSR_ANEGCOMPLETE)) { |
| 3359 | /* still in autonegotiation - configure nic for 10 MBit HD and wait. */ |
| 3360 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 3361 | newdup = 0; |
| 3362 | retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3363 | goto set_speed; |
| 3364 | } |
| 3365 | |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 3366 | adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ); |
| 3367 | lpa = mii_rw(dev, np->phyaddr, MII_LPA, MII_READ); |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 3368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3369 | retval = 1; |
| 3370 | if (np->gigabit == PHY_GIGABIT) { |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 3371 | control_1000 = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ); |
| 3372 | status_1000 = mii_rw(dev, np->phyaddr, MII_STAT1000, MII_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3373 | |
| 3374 | if ((control_1000 & ADVERTISE_1000FULL) && |
| 3375 | (status_1000 & LPA_1000FULL)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3376 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_1000; |
| 3377 | newdup = 1; |
| 3378 | goto set_speed; |
| 3379 | } |
| 3380 | } |
| 3381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3382 | /* FIXME: handle parallel detection properly */ |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 3383 | adv_lpa = lpa & adv; |
| 3384 | if (adv_lpa & LPA_100FULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3385 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100; |
| 3386 | newdup = 1; |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 3387 | } else if (adv_lpa & LPA_100HALF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3388 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_100; |
| 3389 | newdup = 0; |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 3390 | } else if (adv_lpa & LPA_10FULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3391 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 3392 | newdup = 1; |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 3393 | } else if (adv_lpa & LPA_10HALF) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3394 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 3395 | newdup = 0; |
| 3396 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3397 | newls = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 3398 | newdup = 0; |
| 3399 | } |
| 3400 | |
| 3401 | set_speed: |
| 3402 | if (np->duplex == newdup && np->linkspeed == newls) |
| 3403 | return retval; |
| 3404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3405 | np->duplex = newdup; |
| 3406 | np->linkspeed = newls; |
| 3407 | |
Ayaz Abdulla | b2976d2 | 2008-02-04 15:13:59 -0500 | [diff] [blame] | 3408 | /* The transmitter and receiver must be restarted for safe update */ |
| 3409 | if (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_START) { |
| 3410 | txrxFlags |= NV_RESTART_TX; |
| 3411 | nv_stop_tx(dev); |
| 3412 | } |
| 3413 | if (readl(base + NvRegReceiverControl) & NVREG_RCVCTL_START) { |
| 3414 | txrxFlags |= NV_RESTART_RX; |
| 3415 | nv_stop_rx(dev); |
| 3416 | } |
| 3417 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3418 | if (np->gigabit == PHY_GIGABIT) { |
Ayaz Abdulla | a433686 | 2008-04-18 13:50:43 -0700 | [diff] [blame] | 3419 | phyreg = readl(base + NvRegSlotTime); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3420 | phyreg &= ~(0x3FF00); |
Ayaz Abdulla | a433686 | 2008-04-18 13:50:43 -0700 | [diff] [blame] | 3421 | if (((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_10) || |
| 3422 | ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_100)) |
| 3423 | phyreg |= NVREG_SLOTTIME_10_100_FULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3424 | else if ((np->linkspeed & 0xFFF) == NVREG_LINKSPEED_1000) |
Ayaz Abdulla | a433686 | 2008-04-18 13:50:43 -0700 | [diff] [blame] | 3425 | phyreg |= NVREG_SLOTTIME_1000_FULL; |
| 3426 | writel(phyreg, base + NvRegSlotTime); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3427 | } |
| 3428 | |
| 3429 | phyreg = readl(base + NvRegPhyInterface); |
| 3430 | phyreg &= ~(PHY_HALF|PHY_100|PHY_1000); |
| 3431 | if (np->duplex == 0) |
| 3432 | phyreg |= PHY_HALF; |
| 3433 | if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_100) |
| 3434 | phyreg |= PHY_100; |
| 3435 | else if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000) |
| 3436 | phyreg |= PHY_1000; |
| 3437 | writel(phyreg, base + NvRegPhyInterface); |
| 3438 | |
Ayaz Abdulla | fd9b558 | 2008-02-05 12:29:49 -0500 | [diff] [blame] | 3439 | phy_exp = mii_rw(dev, np->phyaddr, MII_EXPANSION, MII_READ) & EXPANSION_NWAY; /* autoneg capable */ |
Ayaz Abdulla | 9744e21 | 2006-07-06 16:45:58 -0400 | [diff] [blame] | 3440 | if (phyreg & PHY_RGMII) { |
Ayaz Abdulla | fd9b558 | 2008-02-05 12:29:49 -0500 | [diff] [blame] | 3441 | if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000) { |
Ayaz Abdulla | 9744e21 | 2006-07-06 16:45:58 -0400 | [diff] [blame] | 3442 | txreg = NVREG_TX_DEFERRAL_RGMII_1000; |
Ayaz Abdulla | fd9b558 | 2008-02-05 12:29:49 -0500 | [diff] [blame] | 3443 | } else { |
| 3444 | if (!phy_exp && !np->duplex && (np->driver_data & DEV_HAS_COLLISION_FIX)) { |
| 3445 | if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_10) |
| 3446 | txreg = NVREG_TX_DEFERRAL_RGMII_STRETCH_10; |
| 3447 | else |
| 3448 | txreg = NVREG_TX_DEFERRAL_RGMII_STRETCH_100; |
| 3449 | } else { |
| 3450 | txreg = NVREG_TX_DEFERRAL_RGMII_10_100; |
| 3451 | } |
| 3452 | } |
Ayaz Abdulla | 9744e21 | 2006-07-06 16:45:58 -0400 | [diff] [blame] | 3453 | } else { |
Ayaz Abdulla | fd9b558 | 2008-02-05 12:29:49 -0500 | [diff] [blame] | 3454 | if (!phy_exp && !np->duplex && (np->driver_data & DEV_HAS_COLLISION_FIX)) |
| 3455 | txreg = NVREG_TX_DEFERRAL_MII_STRETCH; |
| 3456 | else |
| 3457 | txreg = NVREG_TX_DEFERRAL_DEFAULT; |
Ayaz Abdulla | 9744e21 | 2006-07-06 16:45:58 -0400 | [diff] [blame] | 3458 | } |
| 3459 | writel(txreg, base + NvRegTxDeferral); |
| 3460 | |
Ayaz Abdulla | 95d161c | 2006-07-06 16:46:25 -0400 | [diff] [blame] | 3461 | if (np->desc_ver == DESC_VER_1) { |
| 3462 | txreg = NVREG_TX_WM_DESC1_DEFAULT; |
| 3463 | } else { |
| 3464 | if ((np->linkspeed & NVREG_LINKSPEED_MASK) == NVREG_LINKSPEED_1000) |
| 3465 | txreg = NVREG_TX_WM_DESC2_3_1000; |
| 3466 | else |
| 3467 | txreg = NVREG_TX_WM_DESC2_3_DEFAULT; |
| 3468 | } |
| 3469 | writel(txreg, base + NvRegTxWatermark); |
| 3470 | |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 3471 | writel(NVREG_MISC1_FORCE | (np->duplex ? 0 : NVREG_MISC1_HD), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3472 | base + NvRegMisc1); |
| 3473 | pci_push(base); |
| 3474 | writel(np->linkspeed, base + NvRegLinkSpeed); |
| 3475 | pci_push(base); |
| 3476 | |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 3477 | pause_flags = 0; |
| 3478 | /* setup pause frame */ |
david decotigny | 1ff39eb | 2012-08-24 17:22:52 +0000 | [diff] [blame] | 3479 | if (netif_running(dev) && (np->duplex != 0)) { |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 3480 | if (np->autoneg && np->pause_flags & NV_PAUSEFRAME_AUTONEG) { |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 3481 | adv_pause = adv & (ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM); |
| 3482 | lpa_pause = lpa & (LPA_PAUSE_CAP | LPA_PAUSE_ASYM); |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 3483 | |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 3484 | switch (adv_pause) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 3485 | case ADVERTISE_PAUSE_CAP: |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 3486 | if (lpa_pause & LPA_PAUSE_CAP) { |
| 3487 | pause_flags |= NV_PAUSEFRAME_RX_ENABLE; |
| 3488 | if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) |
| 3489 | pause_flags |= NV_PAUSEFRAME_TX_ENABLE; |
| 3490 | } |
| 3491 | break; |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 3492 | case ADVERTISE_PAUSE_ASYM: |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 3493 | if (lpa_pause == (LPA_PAUSE_CAP | LPA_PAUSE_ASYM)) |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 3494 | pause_flags |= NV_PAUSEFRAME_TX_ENABLE; |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 3495 | break; |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 3496 | case ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM: |
| 3497 | if (lpa_pause & LPA_PAUSE_CAP) { |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 3498 | pause_flags |= NV_PAUSEFRAME_RX_ENABLE; |
| 3499 | if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) |
| 3500 | pause_flags |= NV_PAUSEFRAME_TX_ENABLE; |
| 3501 | } |
| 3502 | if (lpa_pause == LPA_PAUSE_ASYM) |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 3503 | pause_flags |= NV_PAUSEFRAME_RX_ENABLE; |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 3504 | break; |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 3505 | } |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 3506 | } else { |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 3507 | pause_flags = np->pause_flags; |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 3508 | } |
| 3509 | } |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 3510 | nv_update_pause(dev, pause_flags); |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 3511 | |
Ayaz Abdulla | b2976d2 | 2008-02-04 15:13:59 -0500 | [diff] [blame] | 3512 | if (txrxFlags & NV_RESTART_TX) |
| 3513 | nv_start_tx(dev); |
| 3514 | if (txrxFlags & NV_RESTART_RX) |
| 3515 | nv_start_rx(dev); |
| 3516 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3517 | return retval; |
| 3518 | } |
| 3519 | |
| 3520 | static void nv_linkchange(struct net_device *dev) |
| 3521 | { |
| 3522 | if (nv_update_linkspeed(dev)) { |
Ayaz Abdulla | 4ea7f29 | 2005-11-11 08:29:59 -0500 | [diff] [blame] | 3523 | if (!netif_carrier_ok(dev)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3524 | netif_carrier_on(dev); |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 3525 | netdev_info(dev, "link up\n"); |
Ayaz Abdulla | 88d7d8b | 2009-05-01 01:41:50 +0000 | [diff] [blame] | 3526 | nv_txrx_gate(dev, false); |
Ayaz Abdulla | 4ea7f29 | 2005-11-11 08:29:59 -0500 | [diff] [blame] | 3527 | nv_start_rx(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3528 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3529 | } else { |
| 3530 | if (netif_carrier_ok(dev)) { |
| 3531 | netif_carrier_off(dev); |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 3532 | netdev_info(dev, "link down\n"); |
Ayaz Abdulla | 88d7d8b | 2009-05-01 01:41:50 +0000 | [diff] [blame] | 3533 | nv_txrx_gate(dev, true); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3534 | nv_stop_rx(dev); |
| 3535 | } |
| 3536 | } |
| 3537 | } |
| 3538 | |
| 3539 | static void nv_link_irq(struct net_device *dev) |
| 3540 | { |
| 3541 | u8 __iomem *base = get_hwbase(dev); |
| 3542 | u32 miistat; |
| 3543 | |
| 3544 | miistat = readl(base + NvRegMIIStatus); |
Ayaz Abdulla | eb79842 | 2008-02-04 15:14:04 -0500 | [diff] [blame] | 3545 | writel(NVREG_MIISTAT_LINKCHANGE, base + NvRegMIIStatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3546 | |
| 3547 | if (miistat & (NVREG_MIISTAT_LINKCHANGE)) |
| 3548 | nv_linkchange(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3549 | } |
| 3550 | |
Ayaz Abdulla | 4db0ee17 | 2008-06-09 16:51:06 -0700 | [diff] [blame] | 3551 | static void nv_msi_workaround(struct fe_priv *np) |
| 3552 | { |
| 3553 | |
| 3554 | /* Need to toggle the msi irq mask within the ethernet device, |
| 3555 | * otherwise, future interrupts will not be detected. |
| 3556 | */ |
| 3557 | if (np->msi_flags & NV_MSI_ENABLED) { |
| 3558 | u8 __iomem *base = np->base; |
| 3559 | |
| 3560 | writel(0, base + NvRegMSIIrqMask); |
| 3561 | writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask); |
| 3562 | } |
| 3563 | } |
| 3564 | |
Ayaz Abdulla | 4145ade | 2009-03-05 08:02:26 +0000 | [diff] [blame] | 3565 | static inline int nv_change_interrupt_mode(struct net_device *dev, int total_work) |
| 3566 | { |
| 3567 | struct fe_priv *np = netdev_priv(dev); |
| 3568 | |
| 3569 | if (optimization_mode == NV_OPTIMIZATION_MODE_DYNAMIC) { |
| 3570 | if (total_work > NV_DYNAMIC_THRESHOLD) { |
| 3571 | /* transition to poll based interrupts */ |
| 3572 | np->quiet_count = 0; |
| 3573 | if (np->irqmask != NVREG_IRQMASK_CPU) { |
| 3574 | np->irqmask = NVREG_IRQMASK_CPU; |
| 3575 | return 1; |
| 3576 | } |
| 3577 | } else { |
| 3578 | if (np->quiet_count < NV_DYNAMIC_MAX_QUIET_COUNT) { |
| 3579 | np->quiet_count++; |
| 3580 | } else { |
| 3581 | /* reached a period of low activity, switch |
| 3582 | to per tx/rx packet interrupts */ |
| 3583 | if (np->irqmask != NVREG_IRQMASK_THROUGHPUT) { |
| 3584 | np->irqmask = NVREG_IRQMASK_THROUGHPUT; |
| 3585 | return 1; |
| 3586 | } |
| 3587 | } |
| 3588 | } |
| 3589 | } |
| 3590 | return 0; |
| 3591 | } |
| 3592 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3593 | static irqreturn_t nv_nic_irq(int foo, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3594 | { |
| 3595 | struct net_device *dev = (struct net_device *) data; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 3596 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3597 | u8 __iomem *base = get_hwbase(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3598 | |
Ayaz Abdulla | b67874a | 2009-03-05 08:02:22 +0000 | [diff] [blame] | 3599 | if (!(np->msi_flags & NV_MSI_X_ENABLED)) { |
| 3600 | np->events = readl(base + NvRegIrqStatus); |
Ayaz Abdulla | 1b2bb76 | 2009-03-05 08:02:34 +0000 | [diff] [blame] | 3601 | writel(np->events, base + NvRegIrqStatus); |
Ayaz Abdulla | b67874a | 2009-03-05 08:02:22 +0000 | [diff] [blame] | 3602 | } else { |
| 3603 | np->events = readl(base + NvRegMSIXIrqStatus); |
Ayaz Abdulla | 1b2bb76 | 2009-03-05 08:02:34 +0000 | [diff] [blame] | 3604 | writel(np->events, base + NvRegMSIXIrqStatus); |
Ayaz Abdulla | b67874a | 2009-03-05 08:02:22 +0000 | [diff] [blame] | 3605 | } |
Ayaz Abdulla | b67874a | 2009-03-05 08:02:22 +0000 | [diff] [blame] | 3606 | if (!(np->events & np->irqmask)) |
| 3607 | return IRQ_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3608 | |
Ayaz Abdulla | b67874a | 2009-03-05 08:02:22 +0000 | [diff] [blame] | 3609 | nv_msi_workaround(np); |
Ayaz Abdulla | 4db0ee17 | 2008-06-09 16:51:06 -0700 | [diff] [blame] | 3610 | |
Eric Dumazet | 78c29bd | 2009-07-02 04:04:45 +0000 | [diff] [blame] | 3611 | if (napi_schedule_prep(&np->napi)) { |
| 3612 | /* |
| 3613 | * Disable further irq's (msix not enabled with napi) |
| 3614 | */ |
| 3615 | writel(0, base + NvRegIrqMask); |
| 3616 | __napi_schedule(&np->napi); |
| 3617 | } |
Ayaz Abdulla | f27e6f3 | 2009-03-05 08:02:14 +0000 | [diff] [blame] | 3618 | |
Ayaz Abdulla | b67874a | 2009-03-05 08:02:22 +0000 | [diff] [blame] | 3619 | return IRQ_HANDLED; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 3620 | } |
| 3621 | |
Ben Hutchings | 1aa8b47 | 2012-07-10 10:56:59 +0000 | [diff] [blame] | 3622 | /* All _optimized functions are used to help increase performance |
Ayaz Abdulla | f0734ab | 2007-01-21 18:10:57 -0500 | [diff] [blame] | 3623 | * (reduce CPU and increase throughput). They use descripter version 3, |
| 3624 | * compiler directives, and reduce memory accesses. |
| 3625 | */ |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 3626 | static irqreturn_t nv_nic_irq_optimized(int foo, void *data) |
| 3627 | { |
| 3628 | struct net_device *dev = (struct net_device *) data; |
| 3629 | struct fe_priv *np = netdev_priv(dev); |
| 3630 | u8 __iomem *base = get_hwbase(dev); |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 3631 | |
Ayaz Abdulla | b67874a | 2009-03-05 08:02:22 +0000 | [diff] [blame] | 3632 | if (!(np->msi_flags & NV_MSI_X_ENABLED)) { |
| 3633 | np->events = readl(base + NvRegIrqStatus); |
Ayaz Abdulla | 1b2bb76 | 2009-03-05 08:02:34 +0000 | [diff] [blame] | 3634 | writel(np->events, base + NvRegIrqStatus); |
Ayaz Abdulla | b67874a | 2009-03-05 08:02:22 +0000 | [diff] [blame] | 3635 | } else { |
| 3636 | np->events = readl(base + NvRegMSIXIrqStatus); |
Ayaz Abdulla | 1b2bb76 | 2009-03-05 08:02:34 +0000 | [diff] [blame] | 3637 | writel(np->events, base + NvRegMSIXIrqStatus); |
Ayaz Abdulla | b67874a | 2009-03-05 08:02:22 +0000 | [diff] [blame] | 3638 | } |
Ayaz Abdulla | b67874a | 2009-03-05 08:02:22 +0000 | [diff] [blame] | 3639 | if (!(np->events & np->irqmask)) |
| 3640 | return IRQ_NONE; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 3641 | |
Ayaz Abdulla | b67874a | 2009-03-05 08:02:22 +0000 | [diff] [blame] | 3642 | nv_msi_workaround(np); |
Ayaz Abdulla | 4db0ee17 | 2008-06-09 16:51:06 -0700 | [diff] [blame] | 3643 | |
Eric Dumazet | 78c29bd | 2009-07-02 04:04:45 +0000 | [diff] [blame] | 3644 | if (napi_schedule_prep(&np->napi)) { |
| 3645 | /* |
| 3646 | * Disable further irq's (msix not enabled with napi) |
| 3647 | */ |
| 3648 | writel(0, base + NvRegIrqMask); |
| 3649 | __napi_schedule(&np->napi); |
| 3650 | } |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 3651 | |
Ayaz Abdulla | b67874a | 2009-03-05 08:02:22 +0000 | [diff] [blame] | 3652 | return IRQ_HANDLED; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 3653 | } |
| 3654 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3655 | static irqreturn_t nv_nic_irq_tx(int foo, void *data) |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3656 | { |
| 3657 | struct net_device *dev = (struct net_device *) data; |
| 3658 | struct fe_priv *np = netdev_priv(dev); |
| 3659 | u8 __iomem *base = get_hwbase(dev); |
| 3660 | u32 events; |
| 3661 | int i; |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3662 | unsigned long flags; |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3663 | |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 3664 | for (i = 0;; i++) { |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3665 | events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_TX_ALL; |
Mike Ditto | 2a4e7a0 | 2011-11-05 14:38:21 +0000 | [diff] [blame] | 3666 | writel(events, base + NvRegMSIXIrqStatus); |
| 3667 | netdev_dbg(dev, "tx irq events: %08x\n", events); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3668 | if (!(events & np->irqmask)) |
| 3669 | break; |
| 3670 | |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3671 | spin_lock_irqsave(&np->lock, flags); |
Ayaz Abdulla | 4e16ed1 | 2007-01-23 12:00:56 -0500 | [diff] [blame] | 3672 | nv_tx_done_optimized(dev, TX_WORK_PER_LOOP); |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3673 | spin_unlock_irqrestore(&np->lock, flags); |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 3674 | |
Ayaz Abdulla | f0734ab | 2007-01-21 18:10:57 -0500 | [diff] [blame] | 3675 | if (unlikely(i > max_interrupt_work)) { |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3676 | spin_lock_irqsave(&np->lock, flags); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3677 | /* disable interrupts on the nic */ |
| 3678 | writel(NVREG_IRQ_TX_ALL, base + NvRegIrqMask); |
| 3679 | pci_push(base); |
| 3680 | |
| 3681 | if (!np->in_shutdown) { |
| 3682 | np->nic_poll_irq |= NVREG_IRQ_TX_ALL; |
| 3683 | mod_timer(&np->nic_poll, jiffies + POLL_WAIT); |
| 3684 | } |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3685 | spin_unlock_irqrestore(&np->lock, flags); |
Joe Perches | c20ec76 | 2010-11-29 07:42:02 +0000 | [diff] [blame] | 3686 | netdev_dbg(dev, "%s: too many iterations (%d)\n", |
| 3687 | __func__, i); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3688 | break; |
| 3689 | } |
| 3690 | |
| 3691 | } |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3692 | |
| 3693 | return IRQ_RETVAL(i); |
| 3694 | } |
| 3695 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3696 | static int nv_napi_poll(struct napi_struct *napi, int budget) |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 3697 | { |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3698 | struct fe_priv *np = container_of(napi, struct fe_priv, napi); |
| 3699 | struct net_device *dev = np->dev; |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 3700 | u8 __iomem *base = get_hwbase(dev); |
Francois Romieu | d15e9c4 | 2006-12-17 23:03:15 +0100 | [diff] [blame] | 3701 | unsigned long flags; |
Ayaz Abdulla | 4145ade | 2009-03-05 08:02:26 +0000 | [diff] [blame] | 3702 | int retcode; |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 3703 | int rx_count, tx_work = 0, rx_work = 0; |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 3704 | |
stephen hemminger | 81a2e36 | 2010-04-28 08:25:28 +0000 | [diff] [blame] | 3705 | do { |
| 3706 | if (!nv_optimized(np)) { |
| 3707 | spin_lock_irqsave(&np->lock, flags); |
| 3708 | tx_work += nv_tx_done(dev, np->tx_ring_size); |
| 3709 | spin_unlock_irqrestore(&np->lock, flags); |
Ayaz Abdulla | f27e6f3 | 2009-03-05 08:02:14 +0000 | [diff] [blame] | 3710 | |
Tom Herbert | d951f72 | 2010-05-05 18:15:21 +0000 | [diff] [blame] | 3711 | rx_count = nv_rx_process(dev, budget - rx_work); |
stephen hemminger | 81a2e36 | 2010-04-28 08:25:28 +0000 | [diff] [blame] | 3712 | retcode = nv_alloc_rx(dev); |
| 3713 | } else { |
| 3714 | spin_lock_irqsave(&np->lock, flags); |
| 3715 | tx_work += nv_tx_done_optimized(dev, np->tx_ring_size); |
| 3716 | spin_unlock_irqrestore(&np->lock, flags); |
Ayaz Abdulla | f27e6f3 | 2009-03-05 08:02:14 +0000 | [diff] [blame] | 3717 | |
Tom Herbert | d951f72 | 2010-05-05 18:15:21 +0000 | [diff] [blame] | 3718 | rx_count = nv_rx_process_optimized(dev, |
| 3719 | budget - rx_work); |
stephen hemminger | 81a2e36 | 2010-04-28 08:25:28 +0000 | [diff] [blame] | 3720 | retcode = nv_alloc_rx_optimized(dev); |
| 3721 | } |
| 3722 | } while (retcode == 0 && |
| 3723 | rx_count > 0 && (rx_work += rx_count) < budget); |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 3724 | |
Ayaz Abdulla | e0379a1 | 2007-02-20 03:34:30 -0500 | [diff] [blame] | 3725 | if (retcode) { |
Francois Romieu | d15e9c4 | 2006-12-17 23:03:15 +0100 | [diff] [blame] | 3726 | spin_lock_irqsave(&np->lock, flags); |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 3727 | if (!np->in_shutdown) |
| 3728 | mod_timer(&np->oom_kick, jiffies + OOM_REFILL); |
Francois Romieu | d15e9c4 | 2006-12-17 23:03:15 +0100 | [diff] [blame] | 3729 | spin_unlock_irqrestore(&np->lock, flags); |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 3730 | } |
| 3731 | |
Ayaz Abdulla | 4145ade | 2009-03-05 08:02:26 +0000 | [diff] [blame] | 3732 | nv_change_interrupt_mode(dev, tx_work + rx_work); |
| 3733 | |
Ayaz Abdulla | f27e6f3 | 2009-03-05 08:02:14 +0000 | [diff] [blame] | 3734 | if (unlikely(np->events & NVREG_IRQ_LINK)) { |
| 3735 | spin_lock_irqsave(&np->lock, flags); |
| 3736 | nv_link_irq(dev); |
| 3737 | spin_unlock_irqrestore(&np->lock, flags); |
| 3738 | } |
| 3739 | if (unlikely(np->need_linktimer && time_after(jiffies, np->link_timeout))) { |
| 3740 | spin_lock_irqsave(&np->lock, flags); |
| 3741 | nv_linkchange(dev); |
| 3742 | spin_unlock_irqrestore(&np->lock, flags); |
| 3743 | np->link_timeout = jiffies + LINK_TIMEOUT; |
| 3744 | } |
| 3745 | if (unlikely(np->events & NVREG_IRQ_RECOVER_ERROR)) { |
| 3746 | spin_lock_irqsave(&np->lock, flags); |
| 3747 | if (!np->in_shutdown) { |
| 3748 | np->nic_poll_irq = np->irqmask; |
| 3749 | np->recover_error = 1; |
| 3750 | mod_timer(&np->nic_poll, jiffies + POLL_WAIT); |
| 3751 | } |
| 3752 | spin_unlock_irqrestore(&np->lock, flags); |
David S. Miller | 6c2da9c | 2009-04-09 01:09:33 -0700 | [diff] [blame] | 3753 | napi_complete(napi); |
Ayaz Abdulla | 4145ade | 2009-03-05 08:02:26 +0000 | [diff] [blame] | 3754 | return rx_work; |
Ayaz Abdulla | f27e6f3 | 2009-03-05 08:02:14 +0000 | [diff] [blame] | 3755 | } |
| 3756 | |
Ayaz Abdulla | 4145ade | 2009-03-05 08:02:26 +0000 | [diff] [blame] | 3757 | if (rx_work < budget) { |
Ayaz Abdulla | f27e6f3 | 2009-03-05 08:02:14 +0000 | [diff] [blame] | 3758 | /* re-enable interrupts |
| 3759 | (msix not enabled in napi) */ |
David S. Miller | 6c2da9c | 2009-04-09 01:09:33 -0700 | [diff] [blame] | 3760 | napi_complete(napi); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3761 | |
Ayaz Abdulla | f27e6f3 | 2009-03-05 08:02:14 +0000 | [diff] [blame] | 3762 | writel(np->irqmask, base + NvRegIrqMask); |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 3763 | } |
Ayaz Abdulla | 4145ade | 2009-03-05 08:02:26 +0000 | [diff] [blame] | 3764 | return rx_work; |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 3765 | } |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 3766 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3767 | static irqreturn_t nv_nic_irq_rx(int foo, void *data) |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3768 | { |
| 3769 | struct net_device *dev = (struct net_device *) data; |
| 3770 | struct fe_priv *np = netdev_priv(dev); |
| 3771 | u8 __iomem *base = get_hwbase(dev); |
| 3772 | u32 events; |
| 3773 | int i; |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3774 | unsigned long flags; |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3775 | |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 3776 | for (i = 0;; i++) { |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3777 | events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_RX_ALL; |
Mike Ditto | 2a4e7a0 | 2011-11-05 14:38:21 +0000 | [diff] [blame] | 3778 | writel(events, base + NvRegMSIXIrqStatus); |
| 3779 | netdev_dbg(dev, "rx irq events: %08x\n", events); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3780 | if (!(events & np->irqmask)) |
| 3781 | break; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 3782 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 3783 | if (nv_rx_process_optimized(dev, RX_WORK_PER_LOOP)) { |
Ayaz Abdulla | f0734ab | 2007-01-21 18:10:57 -0500 | [diff] [blame] | 3784 | if (unlikely(nv_alloc_rx_optimized(dev))) { |
| 3785 | spin_lock_irqsave(&np->lock, flags); |
| 3786 | if (!np->in_shutdown) |
| 3787 | mod_timer(&np->oom_kick, jiffies + OOM_REFILL); |
| 3788 | spin_unlock_irqrestore(&np->lock, flags); |
| 3789 | } |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3790 | } |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 3791 | |
Ayaz Abdulla | f0734ab | 2007-01-21 18:10:57 -0500 | [diff] [blame] | 3792 | if (unlikely(i > max_interrupt_work)) { |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3793 | spin_lock_irqsave(&np->lock, flags); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3794 | /* disable interrupts on the nic */ |
| 3795 | writel(NVREG_IRQ_RX_ALL, base + NvRegIrqMask); |
| 3796 | pci_push(base); |
| 3797 | |
| 3798 | if (!np->in_shutdown) { |
| 3799 | np->nic_poll_irq |= NVREG_IRQ_RX_ALL; |
| 3800 | mod_timer(&np->nic_poll, jiffies + POLL_WAIT); |
| 3801 | } |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3802 | spin_unlock_irqrestore(&np->lock, flags); |
Joe Perches | c20ec76 | 2010-11-29 07:42:02 +0000 | [diff] [blame] | 3803 | netdev_dbg(dev, "%s: too many iterations (%d)\n", |
| 3804 | __func__, i); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3805 | break; |
| 3806 | } |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3807 | } |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3808 | |
| 3809 | return IRQ_RETVAL(i); |
| 3810 | } |
| 3811 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3812 | static irqreturn_t nv_nic_irq_other(int foo, void *data) |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3813 | { |
| 3814 | struct net_device *dev = (struct net_device *) data; |
| 3815 | struct fe_priv *np = netdev_priv(dev); |
| 3816 | u8 __iomem *base = get_hwbase(dev); |
| 3817 | u32 events; |
| 3818 | int i; |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3819 | unsigned long flags; |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3820 | |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 3821 | for (i = 0;; i++) { |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3822 | events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQ_OTHER; |
Mike Ditto | 2a4e7a0 | 2011-11-05 14:38:21 +0000 | [diff] [blame] | 3823 | writel(events, base + NvRegMSIXIrqStatus); |
| 3824 | netdev_dbg(dev, "irq events: %08x\n", events); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3825 | if (!(events & np->irqmask)) |
| 3826 | break; |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 3827 | |
Ayaz Abdulla | 4e16ed1 | 2007-01-23 12:00:56 -0500 | [diff] [blame] | 3828 | /* check tx in case we reached max loop limit in tx isr */ |
| 3829 | spin_lock_irqsave(&np->lock, flags); |
| 3830 | nv_tx_done_optimized(dev, TX_WORK_PER_LOOP); |
| 3831 | spin_unlock_irqrestore(&np->lock, flags); |
| 3832 | |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3833 | if (events & NVREG_IRQ_LINK) { |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3834 | spin_lock_irqsave(&np->lock, flags); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3835 | nv_link_irq(dev); |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3836 | spin_unlock_irqrestore(&np->lock, flags); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3837 | } |
| 3838 | if (np->need_linktimer && time_after(jiffies, np->link_timeout)) { |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3839 | spin_lock_irqsave(&np->lock, flags); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3840 | nv_linkchange(dev); |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3841 | spin_unlock_irqrestore(&np->lock, flags); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3842 | np->link_timeout = jiffies + LINK_TIMEOUT; |
| 3843 | } |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 3844 | if (events & NVREG_IRQ_RECOVER_ERROR) { |
Denis Efremov | 186e8687 | 2012-07-21 01:54:34 +0400 | [diff] [blame] | 3845 | spin_lock_irqsave(&np->lock, flags); |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 3846 | /* disable interrupts on the nic */ |
| 3847 | writel(NVREG_IRQ_OTHER, base + NvRegIrqMask); |
| 3848 | pci_push(base); |
| 3849 | |
| 3850 | if (!np->in_shutdown) { |
| 3851 | np->nic_poll_irq |= NVREG_IRQ_OTHER; |
| 3852 | np->recover_error = 1; |
| 3853 | mod_timer(&np->nic_poll, jiffies + POLL_WAIT); |
| 3854 | } |
Denis Efremov | 186e8687 | 2012-07-21 01:54:34 +0400 | [diff] [blame] | 3855 | spin_unlock_irqrestore(&np->lock, flags); |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 3856 | break; |
| 3857 | } |
Ayaz Abdulla | f0734ab | 2007-01-21 18:10:57 -0500 | [diff] [blame] | 3858 | if (unlikely(i > max_interrupt_work)) { |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3859 | spin_lock_irqsave(&np->lock, flags); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3860 | /* disable interrupts on the nic */ |
| 3861 | writel(NVREG_IRQ_OTHER, base + NvRegIrqMask); |
| 3862 | pci_push(base); |
| 3863 | |
| 3864 | if (!np->in_shutdown) { |
| 3865 | np->nic_poll_irq |= NVREG_IRQ_OTHER; |
| 3866 | mod_timer(&np->nic_poll, jiffies + POLL_WAIT); |
| 3867 | } |
Peter Zijlstra | 0a07bc6 | 2006-09-19 14:55:22 +0200 | [diff] [blame] | 3868 | spin_unlock_irqrestore(&np->lock, flags); |
Joe Perches | c20ec76 | 2010-11-29 07:42:02 +0000 | [diff] [blame] | 3869 | netdev_dbg(dev, "%s: too many iterations (%d)\n", |
| 3870 | __func__, i); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3871 | break; |
| 3872 | } |
| 3873 | |
| 3874 | } |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 3875 | |
| 3876 | return IRQ_RETVAL(i); |
| 3877 | } |
| 3878 | |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 3879 | static irqreturn_t nv_nic_irq_test(int foo, void *data) |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 3880 | { |
| 3881 | struct net_device *dev = (struct net_device *) data; |
| 3882 | struct fe_priv *np = netdev_priv(dev); |
| 3883 | u8 __iomem *base = get_hwbase(dev); |
| 3884 | u32 events; |
| 3885 | |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 3886 | if (!(np->msi_flags & NV_MSI_X_ENABLED)) { |
| 3887 | events = readl(base + NvRegIrqStatus) & NVREG_IRQSTAT_MASK; |
Mike Ditto | 2a4e7a0 | 2011-11-05 14:38:21 +0000 | [diff] [blame] | 3888 | writel(events & NVREG_IRQ_TIMER, base + NvRegIrqStatus); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 3889 | } else { |
| 3890 | events = readl(base + NvRegMSIXIrqStatus) & NVREG_IRQSTAT_MASK; |
Mike Ditto | 2a4e7a0 | 2011-11-05 14:38:21 +0000 | [diff] [blame] | 3891 | writel(events & NVREG_IRQ_TIMER, base + NvRegMSIXIrqStatus); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 3892 | } |
| 3893 | pci_push(base); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 3894 | if (!(events & NVREG_IRQ_TIMER)) |
| 3895 | return IRQ_RETVAL(0); |
| 3896 | |
Ayaz Abdulla | 4db0ee17 | 2008-06-09 16:51:06 -0700 | [diff] [blame] | 3897 | nv_msi_workaround(np); |
| 3898 | |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 3899 | spin_lock(&np->lock); |
| 3900 | np->intr_test = 1; |
| 3901 | spin_unlock(&np->lock); |
| 3902 | |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 3903 | return IRQ_RETVAL(1); |
| 3904 | } |
| 3905 | |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3906 | static void set_msix_vector_map(struct net_device *dev, u32 vector, u32 irqmask) |
| 3907 | { |
| 3908 | u8 __iomem *base = get_hwbase(dev); |
| 3909 | int i; |
| 3910 | u32 msixmap = 0; |
| 3911 | |
| 3912 | /* Each interrupt bit can be mapped to a MSIX vector (4 bits). |
| 3913 | * MSIXMap0 represents the first 8 interrupts and MSIXMap1 represents |
| 3914 | * the remaining 8 interrupts. |
| 3915 | */ |
| 3916 | for (i = 0; i < 8; i++) { |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 3917 | if ((irqmask >> i) & 0x1) |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3918 | msixmap |= vector << (i << 2); |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3919 | } |
| 3920 | writel(readl(base + NvRegMSIXMap0) | msixmap, base + NvRegMSIXMap0); |
| 3921 | |
| 3922 | msixmap = 0; |
| 3923 | for (i = 0; i < 8; i++) { |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 3924 | if ((irqmask >> (i + 8)) & 0x1) |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3925 | msixmap |= vector << (i << 2); |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3926 | } |
| 3927 | writel(readl(base + NvRegMSIXMap1) | msixmap, base + NvRegMSIXMap1); |
| 3928 | } |
| 3929 | |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 3930 | static int nv_request_irq(struct net_device *dev, int intr_test) |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3931 | { |
| 3932 | struct fe_priv *np = get_nvpriv(dev); |
| 3933 | u8 __iomem *base = get_hwbase(dev); |
| 3934 | int ret = 1; |
| 3935 | int i; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 3936 | irqreturn_t (*handler)(int foo, void *data); |
| 3937 | |
| 3938 | if (intr_test) { |
| 3939 | handler = nv_nic_irq_test; |
| 3940 | } else { |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 3941 | if (nv_optimized(np)) |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 3942 | handler = nv_nic_irq_optimized; |
| 3943 | else |
| 3944 | handler = nv_nic_irq; |
| 3945 | } |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3946 | |
| 3947 | if (np->msi_flags & NV_MSI_X_CAPABLE) { |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 3948 | for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++) |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3949 | np->msi_x_entry[i].entry = i; |
Szymon Janc | 34cf97e | 2010-11-27 08:39:46 +0000 | [diff] [blame] | 3950 | ret = pci_enable_msix(np->pci_dev, np->msi_x_entry, (np->msi_flags & NV_MSI_X_VECTORS_MASK)); |
| 3951 | if (ret == 0) { |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3952 | np->msi_flags |= NV_MSI_X_ENABLED; |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 3953 | if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT && !intr_test) { |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3954 | /* Request irq for rx handling */ |
Yinghai Lu | ddb213f | 2009-02-06 01:29:23 -0800 | [diff] [blame] | 3955 | sprintf(np->name_rx, "%s-rx", dev->name); |
| 3956 | if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 3957 | nv_nic_irq_rx, IRQF_SHARED, np->name_rx, dev) != 0) { |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 3958 | netdev_info(dev, |
| 3959 | "request_irq failed for rx %d\n", |
| 3960 | ret); |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3961 | pci_disable_msix(np->pci_dev); |
| 3962 | np->msi_flags &= ~NV_MSI_X_ENABLED; |
| 3963 | goto out_err; |
| 3964 | } |
| 3965 | /* Request irq for tx handling */ |
Yinghai Lu | ddb213f | 2009-02-06 01:29:23 -0800 | [diff] [blame] | 3966 | sprintf(np->name_tx, "%s-tx", dev->name); |
| 3967 | if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 3968 | nv_nic_irq_tx, IRQF_SHARED, np->name_tx, dev) != 0) { |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 3969 | netdev_info(dev, |
| 3970 | "request_irq failed for tx %d\n", |
| 3971 | ret); |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3972 | pci_disable_msix(np->pci_dev); |
| 3973 | np->msi_flags &= ~NV_MSI_X_ENABLED; |
| 3974 | goto out_free_rx; |
| 3975 | } |
| 3976 | /* Request irq for link and timer handling */ |
Yinghai Lu | ddb213f | 2009-02-06 01:29:23 -0800 | [diff] [blame] | 3977 | sprintf(np->name_other, "%s-other", dev->name); |
| 3978 | if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 3979 | nv_nic_irq_other, IRQF_SHARED, np->name_other, dev) != 0) { |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 3980 | netdev_info(dev, |
| 3981 | "request_irq failed for link %d\n", |
| 3982 | ret); |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3983 | pci_disable_msix(np->pci_dev); |
| 3984 | np->msi_flags &= ~NV_MSI_X_ENABLED; |
| 3985 | goto out_free_tx; |
| 3986 | } |
| 3987 | /* map interrupts to their respective vector */ |
| 3988 | writel(0, base + NvRegMSIXMap0); |
| 3989 | writel(0, base + NvRegMSIXMap1); |
| 3990 | set_msix_vector_map(dev, NV_MSI_X_VECTOR_RX, NVREG_IRQ_RX_ALL); |
| 3991 | set_msix_vector_map(dev, NV_MSI_X_VECTOR_TX, NVREG_IRQ_TX_ALL); |
| 3992 | set_msix_vector_map(dev, NV_MSI_X_VECTOR_OTHER, NVREG_IRQ_OTHER); |
| 3993 | } else { |
| 3994 | /* Request irq for all interrupts */ |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 3995 | if (request_irq(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector, handler, IRQF_SHARED, dev->name, dev) != 0) { |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 3996 | netdev_info(dev, |
| 3997 | "request_irq failed %d\n", |
| 3998 | ret); |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 3999 | pci_disable_msix(np->pci_dev); |
| 4000 | np->msi_flags &= ~NV_MSI_X_ENABLED; |
| 4001 | goto out_err; |
| 4002 | } |
| 4003 | |
| 4004 | /* map interrupts to vector 0 */ |
| 4005 | writel(0, base + NvRegMSIXMap0); |
| 4006 | writel(0, base + NvRegMSIXMap1); |
| 4007 | } |
Mike Ditto | 8932878 | 2011-11-16 12:15:11 +0000 | [diff] [blame] | 4008 | netdev_info(dev, "MSI-X enabled\n"); |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 4009 | } |
| 4010 | } |
| 4011 | if (ret != 0 && np->msi_flags & NV_MSI_CAPABLE) { |
Szymon Janc | 34cf97e | 2010-11-27 08:39:46 +0000 | [diff] [blame] | 4012 | ret = pci_enable_msi(np->pci_dev); |
| 4013 | if (ret == 0) { |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 4014 | np->msi_flags |= NV_MSI_ENABLED; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 4015 | if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0) { |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 4016 | netdev_info(dev, "request_irq failed %d\n", |
| 4017 | ret); |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 4018 | pci_disable_msi(np->pci_dev); |
| 4019 | np->msi_flags &= ~NV_MSI_ENABLED; |
| 4020 | goto out_err; |
| 4021 | } |
| 4022 | |
| 4023 | /* map interrupts to vector 0 */ |
| 4024 | writel(0, base + NvRegMSIMap0); |
| 4025 | writel(0, base + NvRegMSIMap1); |
| 4026 | /* enable msi vector 0 */ |
| 4027 | writel(NVREG_MSI_VECTOR_0_ENABLED, base + NvRegMSIIrqMask); |
Mike Ditto | 8932878 | 2011-11-16 12:15:11 +0000 | [diff] [blame] | 4028 | netdev_info(dev, "MSI enabled\n"); |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 4029 | } |
| 4030 | } |
| 4031 | if (ret != 0) { |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 4032 | if (request_irq(np->pci_dev->irq, handler, IRQF_SHARED, dev->name, dev) != 0) |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 4033 | goto out_err; |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 4034 | |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 4035 | } |
| 4036 | |
| 4037 | return 0; |
| 4038 | out_free_tx: |
| 4039 | free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector, dev); |
| 4040 | out_free_rx: |
| 4041 | free_irq(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector, dev); |
| 4042 | out_err: |
| 4043 | return 1; |
| 4044 | } |
| 4045 | |
| 4046 | static void nv_free_irq(struct net_device *dev) |
| 4047 | { |
| 4048 | struct fe_priv *np = get_nvpriv(dev); |
| 4049 | int i; |
| 4050 | |
| 4051 | if (np->msi_flags & NV_MSI_X_ENABLED) { |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 4052 | for (i = 0; i < (np->msi_flags & NV_MSI_X_VECTORS_MASK); i++) |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 4053 | free_irq(np->msi_x_entry[i].vector, dev); |
Ayaz Abdulla | 7a1854b | 2006-06-10 22:48:08 -0400 | [diff] [blame] | 4054 | pci_disable_msix(np->pci_dev); |
| 4055 | np->msi_flags &= ~NV_MSI_X_ENABLED; |
| 4056 | } else { |
| 4057 | free_irq(np->pci_dev->irq, dev); |
| 4058 | if (np->msi_flags & NV_MSI_ENABLED) { |
| 4059 | pci_disable_msi(np->pci_dev); |
| 4060 | np->msi_flags &= ~NV_MSI_ENABLED; |
| 4061 | } |
| 4062 | } |
| 4063 | } |
| 4064 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4065 | static void nv_do_nic_poll(unsigned long data) |
| 4066 | { |
| 4067 | struct net_device *dev = (struct net_device *) data; |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 4068 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4069 | u8 __iomem *base = get_hwbase(dev); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 4070 | u32 mask = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4071 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4072 | /* |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 4073 | * First disable irq(s) and then |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4074 | * reenable interrupts on the nic, we have to do this before calling |
| 4075 | * nv_nic_irq because that may decide to do otherwise |
| 4076 | */ |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 4077 | |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 4078 | if (!using_multi_irqs(dev)) { |
| 4079 | if (np->msi_flags & NV_MSI_X_ENABLED) |
Ingo Molnar | 8688cfc | 2006-07-03 00:25:39 -0700 | [diff] [blame] | 4080 | disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector); |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 4081 | else |
Manfred Spraul | a747590 | 2007-10-17 21:52:33 +0200 | [diff] [blame] | 4082 | disable_irq_lockdep(np->pci_dev->irq); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 4083 | mask = np->irqmask; |
| 4084 | } else { |
| 4085 | if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) { |
Ingo Molnar | 8688cfc | 2006-07-03 00:25:39 -0700 | [diff] [blame] | 4086 | disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 4087 | mask |= NVREG_IRQ_RX_ALL; |
| 4088 | } |
| 4089 | if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) { |
Ingo Molnar | 8688cfc | 2006-07-03 00:25:39 -0700 | [diff] [blame] | 4090 | disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 4091 | mask |= NVREG_IRQ_TX_ALL; |
| 4092 | } |
| 4093 | if (np->nic_poll_irq & NVREG_IRQ_OTHER) { |
Ingo Molnar | 8688cfc | 2006-07-03 00:25:39 -0700 | [diff] [blame] | 4094 | disable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 4095 | mask |= NVREG_IRQ_OTHER; |
| 4096 | } |
| 4097 | } |
Manfred Spraul | a747590 | 2007-10-17 21:52:33 +0200 | [diff] [blame] | 4098 | /* disable_irq() contains synchronize_irq, thus no irq handler can run now */ |
| 4099 | |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 4100 | if (np->recover_error) { |
| 4101 | np->recover_error = 0; |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 4102 | netdev_info(dev, "MAC in recoverable error state\n"); |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 4103 | if (netif_running(dev)) { |
| 4104 | netif_tx_lock_bh(dev); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 4105 | netif_addr_lock(dev); |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 4106 | spin_lock(&np->lock); |
| 4107 | /* stop engines */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 4108 | nv_stop_rxtx(dev); |
Ayaz Abdulla | daa91a9 | 2009-02-07 00:25:00 -0800 | [diff] [blame] | 4109 | if (np->driver_data & DEV_HAS_POWER_CNTRL) |
| 4110 | nv_mac_reset(dev); |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 4111 | nv_txrx_reset(dev); |
| 4112 | /* drain rx queue */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 4113 | nv_drain_rxtx(dev); |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 4114 | /* reinit driver view of the rx queue */ |
| 4115 | set_bufsize(dev); |
| 4116 | if (nv_init_ring(dev)) { |
| 4117 | if (!np->in_shutdown) |
| 4118 | mod_timer(&np->oom_kick, jiffies + OOM_REFILL); |
| 4119 | } |
| 4120 | /* reinit nic view of the rx queue */ |
| 4121 | writel(np->rx_buf_sz, base + NvRegOffloadConfig); |
| 4122 | setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING); |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 4123 | writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT), |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 4124 | base + NvRegRingSizes); |
| 4125 | pci_push(base); |
| 4126 | writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl); |
| 4127 | pci_push(base); |
Ayaz Abdulla | daa91a9 | 2009-02-07 00:25:00 -0800 | [diff] [blame] | 4128 | /* clear interrupts */ |
| 4129 | if (!(np->msi_flags & NV_MSI_X_ENABLED)) |
| 4130 | writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus); |
| 4131 | else |
| 4132 | writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus); |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 4133 | |
| 4134 | /* restart rx engine */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 4135 | nv_start_rxtx(dev); |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 4136 | spin_unlock(&np->lock); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 4137 | netif_addr_unlock(dev); |
Ayaz Abdulla | c5cf910 | 2006-10-30 17:32:01 -0500 | [diff] [blame] | 4138 | netif_tx_unlock_bh(dev); |
| 4139 | } |
| 4140 | } |
| 4141 | |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 4142 | writel(mask, base + NvRegIrqMask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4143 | pci_push(base); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 4144 | |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 4145 | if (!using_multi_irqs(dev)) { |
Yinghai Lu | 79d30a5 | 2009-02-06 01:30:01 -0800 | [diff] [blame] | 4146 | np->nic_poll_irq = 0; |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 4147 | if (nv_optimized(np)) |
Ayaz Abdulla | fcc5f26 | 2007-03-23 05:49:37 -0500 | [diff] [blame] | 4148 | nv_nic_irq_optimized(0, dev); |
| 4149 | else |
| 4150 | nv_nic_irq(0, dev); |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 4151 | if (np->msi_flags & NV_MSI_X_ENABLED) |
Ingo Molnar | 8688cfc | 2006-07-03 00:25:39 -0700 | [diff] [blame] | 4152 | enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_ALL].vector); |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 4153 | else |
Manfred Spraul | a747590 | 2007-10-17 21:52:33 +0200 | [diff] [blame] | 4154 | enable_irq_lockdep(np->pci_dev->irq); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 4155 | } else { |
| 4156 | if (np->nic_poll_irq & NVREG_IRQ_RX_ALL) { |
Yinghai Lu | 79d30a5 | 2009-02-06 01:30:01 -0800 | [diff] [blame] | 4157 | np->nic_poll_irq &= ~NVREG_IRQ_RX_ALL; |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 4158 | nv_nic_irq_rx(0, dev); |
Ingo Molnar | 8688cfc | 2006-07-03 00:25:39 -0700 | [diff] [blame] | 4159 | enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_RX].vector); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 4160 | } |
| 4161 | if (np->nic_poll_irq & NVREG_IRQ_TX_ALL) { |
Yinghai Lu | 79d30a5 | 2009-02-06 01:30:01 -0800 | [diff] [blame] | 4162 | np->nic_poll_irq &= ~NVREG_IRQ_TX_ALL; |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 4163 | nv_nic_irq_tx(0, dev); |
Ingo Molnar | 8688cfc | 2006-07-03 00:25:39 -0700 | [diff] [blame] | 4164 | enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_TX].vector); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 4165 | } |
| 4166 | if (np->nic_poll_irq & NVREG_IRQ_OTHER) { |
Yinghai Lu | 79d30a5 | 2009-02-06 01:30:01 -0800 | [diff] [blame] | 4167 | np->nic_poll_irq &= ~NVREG_IRQ_OTHER; |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 4168 | nv_nic_irq_other(0, dev); |
Ingo Molnar | 8688cfc | 2006-07-03 00:25:39 -0700 | [diff] [blame] | 4169 | enable_irq_lockdep(np->msi_x_entry[NV_MSI_X_VECTOR_OTHER].vector); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 4170 | } |
| 4171 | } |
Yinghai Lu | 79d30a5 | 2009-02-06 01:30:01 -0800 | [diff] [blame] | 4172 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4173 | } |
| 4174 | |
Michal Schmidt | 2918c35 | 2005-05-12 19:42:06 -0400 | [diff] [blame] | 4175 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 4176 | static void nv_poll_controller(struct net_device *dev) |
| 4177 | { |
| 4178 | nv_do_nic_poll((unsigned long) dev); |
| 4179 | } |
| 4180 | #endif |
| 4181 | |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 4182 | static void nv_do_stats_poll(unsigned long data) |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 4183 | __acquires(&netdev_priv(dev)->hwstats_lock) |
| 4184 | __releases(&netdev_priv(dev)->hwstats_lock) |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 4185 | { |
| 4186 | struct net_device *dev = (struct net_device *) data; |
| 4187 | struct fe_priv *np = netdev_priv(dev); |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 4188 | |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 4189 | /* If lock is currently taken, the stats are being refreshed |
| 4190 | * and hence fresh enough */ |
| 4191 | if (spin_trylock(&np->hwstats_lock)) { |
| 4192 | nv_update_stats(dev); |
| 4193 | spin_unlock(&np->hwstats_lock); |
| 4194 | } |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 4195 | |
| 4196 | if (!np->in_shutdown) |
Daniel Drake | bfebbb8 | 2008-03-18 11:07:18 +0000 | [diff] [blame] | 4197 | mod_timer(&np->stats_poll, |
| 4198 | round_jiffies(jiffies + STATS_INTERVAL)); |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 4199 | } |
| 4200 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4201 | static void nv_get_drvinfo(struct net_device *dev, struct ethtool_drvinfo *info) |
| 4202 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 4203 | struct fe_priv *np = netdev_priv(dev); |
Rick Jones | 68aad78 | 2011-11-07 13:29:27 +0000 | [diff] [blame] | 4204 | strlcpy(info->driver, DRV_NAME, sizeof(info->driver)); |
| 4205 | strlcpy(info->version, FORCEDETH_VERSION, sizeof(info->version)); |
| 4206 | strlcpy(info->bus_info, pci_name(np->pci_dev), sizeof(info->bus_info)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4207 | } |
| 4208 | |
| 4209 | static void nv_get_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo) |
| 4210 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 4211 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4212 | wolinfo->supported = WAKE_MAGIC; |
| 4213 | |
| 4214 | spin_lock_irq(&np->lock); |
| 4215 | if (np->wolenabled) |
| 4216 | wolinfo->wolopts = WAKE_MAGIC; |
| 4217 | spin_unlock_irq(&np->lock); |
| 4218 | } |
| 4219 | |
| 4220 | static int nv_set_wol(struct net_device *dev, struct ethtool_wolinfo *wolinfo) |
| 4221 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 4222 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4223 | u8 __iomem *base = get_hwbase(dev); |
Ayaz Abdulla | c42d9df | 2006-06-10 22:47:52 -0400 | [diff] [blame] | 4224 | u32 flags = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4225 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4226 | if (wolinfo->wolopts == 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4227 | np->wolenabled = 0; |
Ayaz Abdulla | c42d9df | 2006-06-10 22:47:52 -0400 | [diff] [blame] | 4228 | } else if (wolinfo->wolopts & WAKE_MAGIC) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4229 | np->wolenabled = 1; |
Ayaz Abdulla | c42d9df | 2006-06-10 22:47:52 -0400 | [diff] [blame] | 4230 | flags = NVREG_WAKEUPFLAGS_ENABLE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4231 | } |
Ayaz Abdulla | c42d9df | 2006-06-10 22:47:52 -0400 | [diff] [blame] | 4232 | if (netif_running(dev)) { |
| 4233 | spin_lock_irq(&np->lock); |
| 4234 | writel(flags, base + NvRegWakeUpFlags); |
| 4235 | spin_unlock_irq(&np->lock); |
| 4236 | } |
Rafael J. Wysocki | dba5a68 | 2011-01-07 11:12:05 +0000 | [diff] [blame] | 4237 | device_set_wakeup_enable(&np->pci_dev->dev, np->wolenabled); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4238 | return 0; |
| 4239 | } |
| 4240 | |
| 4241 | static int nv_get_settings(struct net_device *dev, struct ethtool_cmd *ecmd) |
| 4242 | { |
| 4243 | struct fe_priv *np = netdev_priv(dev); |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 4244 | u32 speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4245 | int adv; |
| 4246 | |
| 4247 | spin_lock_irq(&np->lock); |
| 4248 | ecmd->port = PORT_MII; |
| 4249 | if (!netif_running(dev)) { |
| 4250 | /* We do not track link speed / duplex setting if the |
| 4251 | * interface is disabled. Force a link check */ |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 4252 | if (nv_update_linkspeed(dev)) { |
| 4253 | if (!netif_carrier_ok(dev)) |
| 4254 | netif_carrier_on(dev); |
| 4255 | } else { |
| 4256 | if (netif_carrier_ok(dev)) |
| 4257 | netif_carrier_off(dev); |
| 4258 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4259 | } |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 4260 | |
| 4261 | if (netif_carrier_ok(dev)) { |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 4262 | switch (np->linkspeed & (NVREG_LINKSPEED_MASK)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4263 | case NVREG_LINKSPEED_10: |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 4264 | speed = SPEED_10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4265 | break; |
| 4266 | case NVREG_LINKSPEED_100: |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 4267 | speed = SPEED_100; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4268 | break; |
| 4269 | case NVREG_LINKSPEED_1000: |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 4270 | speed = SPEED_1000; |
| 4271 | break; |
| 4272 | default: |
| 4273 | speed = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4274 | break; |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 4275 | } |
| 4276 | ecmd->duplex = DUPLEX_HALF; |
| 4277 | if (np->duplex) |
| 4278 | ecmd->duplex = DUPLEX_FULL; |
| 4279 | } else { |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 4280 | speed = -1; |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 4281 | ecmd->duplex = -1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4282 | } |
David Decotigny | 7073949 | 2011-04-27 18:32:40 +0000 | [diff] [blame] | 4283 | ethtool_cmd_speed_set(ecmd, speed); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4284 | ecmd->autoneg = np->autoneg; |
| 4285 | |
| 4286 | ecmd->advertising = ADVERTISED_MII; |
| 4287 | if (np->autoneg) { |
| 4288 | ecmd->advertising |= ADVERTISED_Autoneg; |
| 4289 | adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ); |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 4290 | if (adv & ADVERTISE_10HALF) |
| 4291 | ecmd->advertising |= ADVERTISED_10baseT_Half; |
| 4292 | if (adv & ADVERTISE_10FULL) |
| 4293 | ecmd->advertising |= ADVERTISED_10baseT_Full; |
| 4294 | if (adv & ADVERTISE_100HALF) |
| 4295 | ecmd->advertising |= ADVERTISED_100baseT_Half; |
| 4296 | if (adv & ADVERTISE_100FULL) |
| 4297 | ecmd->advertising |= ADVERTISED_100baseT_Full; |
| 4298 | if (np->gigabit == PHY_GIGABIT) { |
| 4299 | adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ); |
| 4300 | if (adv & ADVERTISE_1000FULL) |
| 4301 | ecmd->advertising |= ADVERTISED_1000baseT_Full; |
| 4302 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4303 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4304 | ecmd->supported = (SUPPORTED_Autoneg | |
| 4305 | SUPPORTED_10baseT_Half | SUPPORTED_10baseT_Full | |
| 4306 | SUPPORTED_100baseT_Half | SUPPORTED_100baseT_Full | |
| 4307 | SUPPORTED_MII); |
| 4308 | if (np->gigabit == PHY_GIGABIT) |
| 4309 | ecmd->supported |= SUPPORTED_1000baseT_Full; |
| 4310 | |
| 4311 | ecmd->phy_address = np->phyaddr; |
| 4312 | ecmd->transceiver = XCVR_EXTERNAL; |
| 4313 | |
| 4314 | /* ignore maxtxpkt, maxrxpkt for now */ |
| 4315 | spin_unlock_irq(&np->lock); |
| 4316 | return 0; |
| 4317 | } |
| 4318 | |
| 4319 | static int nv_set_settings(struct net_device *dev, struct ethtool_cmd *ecmd) |
| 4320 | { |
| 4321 | struct fe_priv *np = netdev_priv(dev); |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 4322 | u32 speed = ethtool_cmd_speed(ecmd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4323 | |
| 4324 | if (ecmd->port != PORT_MII) |
| 4325 | return -EINVAL; |
| 4326 | if (ecmd->transceiver != XCVR_EXTERNAL) |
| 4327 | return -EINVAL; |
| 4328 | if (ecmd->phy_address != np->phyaddr) { |
| 4329 | /* TODO: support switching between multiple phys. Should be |
| 4330 | * trivial, but not enabled due to lack of test hardware. */ |
| 4331 | return -EINVAL; |
| 4332 | } |
| 4333 | if (ecmd->autoneg == AUTONEG_ENABLE) { |
| 4334 | u32 mask; |
| 4335 | |
| 4336 | mask = ADVERTISED_10baseT_Half | ADVERTISED_10baseT_Full | |
| 4337 | ADVERTISED_100baseT_Half | ADVERTISED_100baseT_Full; |
| 4338 | if (np->gigabit == PHY_GIGABIT) |
| 4339 | mask |= ADVERTISED_1000baseT_Full; |
| 4340 | |
| 4341 | if ((ecmd->advertising & mask) == 0) |
| 4342 | return -EINVAL; |
| 4343 | |
| 4344 | } else if (ecmd->autoneg == AUTONEG_DISABLE) { |
| 4345 | /* Note: autonegotiation disable, speed 1000 intentionally |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4346 | * forbidden - no one should need that. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4347 | |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 4348 | if (speed != SPEED_10 && speed != SPEED_100) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4349 | return -EINVAL; |
| 4350 | if (ecmd->duplex != DUPLEX_HALF && ecmd->duplex != DUPLEX_FULL) |
| 4351 | return -EINVAL; |
| 4352 | } else { |
| 4353 | return -EINVAL; |
| 4354 | } |
| 4355 | |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 4356 | netif_carrier_off(dev); |
| 4357 | if (netif_running(dev)) { |
Tobias Diedrich | 97bff09 | 2008-07-03 23:54:56 -0700 | [diff] [blame] | 4358 | unsigned long flags; |
| 4359 | |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 4360 | nv_disable_irq(dev); |
Herbert Xu | 58dfd9c | 2006-06-21 10:53:54 +1000 | [diff] [blame] | 4361 | netif_tx_lock_bh(dev); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 4362 | netif_addr_lock(dev); |
Tobias Diedrich | 97bff09 | 2008-07-03 23:54:56 -0700 | [diff] [blame] | 4363 | /* with plain spinlock lockdep complains */ |
| 4364 | spin_lock_irqsave(&np->lock, flags); |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 4365 | /* stop engines */ |
Tobias Diedrich | 97bff09 | 2008-07-03 23:54:56 -0700 | [diff] [blame] | 4366 | /* FIXME: |
| 4367 | * this can take some time, and interrupts are disabled |
| 4368 | * due to spin_lock_irqsave, but let's hope no daemon |
| 4369 | * is going to change the settings very often... |
| 4370 | * Worst case: |
| 4371 | * NV_RXSTOP_DELAY1MAX + NV_TXSTOP_DELAY1MAX |
| 4372 | * + some minor delays, which is up to a second approximately |
| 4373 | */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 4374 | nv_stop_rxtx(dev); |
Tobias Diedrich | 97bff09 | 2008-07-03 23:54:56 -0700 | [diff] [blame] | 4375 | spin_unlock_irqrestore(&np->lock, flags); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 4376 | netif_addr_unlock(dev); |
Herbert Xu | 58dfd9c | 2006-06-21 10:53:54 +1000 | [diff] [blame] | 4377 | netif_tx_unlock_bh(dev); |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 4378 | } |
| 4379 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4380 | if (ecmd->autoneg == AUTONEG_ENABLE) { |
| 4381 | int adv, bmcr; |
| 4382 | |
| 4383 | np->autoneg = 1; |
| 4384 | |
| 4385 | /* advertise only what has been requested */ |
| 4386 | adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ); |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 4387 | adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4388 | if (ecmd->advertising & ADVERTISED_10baseT_Half) |
| 4389 | adv |= ADVERTISE_10HALF; |
| 4390 | if (ecmd->advertising & ADVERTISED_10baseT_Full) |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 4391 | adv |= ADVERTISE_10FULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4392 | if (ecmd->advertising & ADVERTISED_100baseT_Half) |
| 4393 | adv |= ADVERTISE_100HALF; |
| 4394 | if (ecmd->advertising & ADVERTISED_100baseT_Full) |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 4395 | adv |= ADVERTISE_100FULL; |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4396 | if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisements but disable tx pause */ |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 4397 | adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 4398 | if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) |
| 4399 | adv |= ADVERTISE_PAUSE_ASYM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4400 | mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv); |
| 4401 | |
| 4402 | if (np->gigabit == PHY_GIGABIT) { |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 4403 | adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4404 | adv &= ~ADVERTISE_1000FULL; |
| 4405 | if (ecmd->advertising & ADVERTISED_1000baseT_Full) |
| 4406 | adv |= ADVERTISE_1000FULL; |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 4407 | mii_rw(dev, np->phyaddr, MII_CTRL1000, adv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4408 | } |
| 4409 | |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 4410 | if (netif_running(dev)) |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 4411 | netdev_info(dev, "link down\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4412 | bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 4413 | if (np->phy_model == PHY_MODEL_MARVELL_E3016) { |
| 4414 | bmcr |= BMCR_ANENABLE; |
| 4415 | /* reset the phy in order for settings to stick, |
| 4416 | * and cause autoneg to start */ |
| 4417 | if (phy_reset(dev, bmcr)) { |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 4418 | netdev_info(dev, "phy reset failed\n"); |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 4419 | return -EINVAL; |
| 4420 | } |
| 4421 | } else { |
| 4422 | bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART); |
| 4423 | mii_rw(dev, np->phyaddr, MII_BMCR, bmcr); |
| 4424 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4425 | } else { |
| 4426 | int adv, bmcr; |
| 4427 | |
| 4428 | np->autoneg = 0; |
| 4429 | |
| 4430 | adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ); |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 4431 | adv &= ~(ADVERTISE_ALL | ADVERTISE_100BASE4 | ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM); |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 4432 | if (speed == SPEED_10 && ecmd->duplex == DUPLEX_HALF) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4433 | adv |= ADVERTISE_10HALF; |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 4434 | if (speed == SPEED_10 && ecmd->duplex == DUPLEX_FULL) |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 4435 | adv |= ADVERTISE_10FULL; |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 4436 | if (speed == SPEED_100 && ecmd->duplex == DUPLEX_HALF) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4437 | adv |= ADVERTISE_100HALF; |
David Decotigny | 25db033 | 2011-04-27 18:32:39 +0000 | [diff] [blame] | 4438 | if (speed == SPEED_100 && ecmd->duplex == DUPLEX_FULL) |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 4439 | adv |= ADVERTISE_100FULL; |
| 4440 | np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4441 | if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) {/* for rx we set both advertisements but disable tx pause */ |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 4442 | adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 4443 | np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE; |
| 4444 | } |
| 4445 | if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) { |
| 4446 | adv |= ADVERTISE_PAUSE_ASYM; |
| 4447 | np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE; |
| 4448 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4449 | mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv); |
| 4450 | np->fixed_mode = adv; |
| 4451 | |
| 4452 | if (np->gigabit == PHY_GIGABIT) { |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 4453 | adv = mii_rw(dev, np->phyaddr, MII_CTRL1000, MII_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4454 | adv &= ~ADVERTISE_1000FULL; |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 4455 | mii_rw(dev, np->phyaddr, MII_CTRL1000, adv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4456 | } |
| 4457 | |
| 4458 | bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 4459 | bmcr &= ~(BMCR_ANENABLE|BMCR_SPEED100|BMCR_SPEED1000|BMCR_FULLDPLX); |
| 4460 | if (np->fixed_mode & (ADVERTISE_10FULL|ADVERTISE_100FULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4461 | bmcr |= BMCR_FULLDPLX; |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 4462 | if (np->fixed_mode & (ADVERTISE_100HALF|ADVERTISE_100FULL)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4463 | bmcr |= BMCR_SPEED100; |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 4464 | if (np->phy_oui == PHY_OUI_MARVELL) { |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 4465 | /* reset the phy in order for forced mode settings to stick */ |
| 4466 | if (phy_reset(dev, bmcr)) { |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 4467 | netdev_info(dev, "phy reset failed\n"); |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 4468 | return -EINVAL; |
| 4469 | } |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 4470 | } else { |
| 4471 | mii_rw(dev, np->phyaddr, MII_BMCR, bmcr); |
| 4472 | if (netif_running(dev)) { |
| 4473 | /* Wait a bit and then reconfigure the nic. */ |
| 4474 | udelay(10); |
| 4475 | nv_linkchange(dev); |
| 4476 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4477 | } |
| 4478 | } |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 4479 | |
| 4480 | if (netif_running(dev)) { |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 4481 | nv_start_rxtx(dev); |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 4482 | nv_enable_irq(dev); |
| 4483 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4484 | |
| 4485 | return 0; |
| 4486 | } |
| 4487 | |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 4488 | #define FORCEDETH_REGS_VER 1 |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 4489 | |
| 4490 | static int nv_get_regs_len(struct net_device *dev) |
| 4491 | { |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 4492 | struct fe_priv *np = netdev_priv(dev); |
| 4493 | return np->register_size; |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 4494 | } |
| 4495 | |
| 4496 | static void nv_get_regs(struct net_device *dev, struct ethtool_regs *regs, void *buf) |
| 4497 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 4498 | struct fe_priv *np = netdev_priv(dev); |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 4499 | u8 __iomem *base = get_hwbase(dev); |
| 4500 | u32 *rbuf = buf; |
| 4501 | int i; |
| 4502 | |
| 4503 | regs->version = FORCEDETH_REGS_VER; |
| 4504 | spin_lock_irq(&np->lock); |
david decotigny | ba9aa13 | 2012-08-24 17:22:51 +0000 | [diff] [blame] | 4505 | for (i = 0; i < np->register_size/sizeof(u32); i++) |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 4506 | rbuf[i] = readl(base + i*sizeof(u32)); |
| 4507 | spin_unlock_irq(&np->lock); |
| 4508 | } |
| 4509 | |
| 4510 | static int nv_nway_reset(struct net_device *dev) |
| 4511 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 4512 | struct fe_priv *np = netdev_priv(dev); |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 4513 | int ret; |
| 4514 | |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 4515 | if (np->autoneg) { |
| 4516 | int bmcr; |
| 4517 | |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 4518 | netif_carrier_off(dev); |
| 4519 | if (netif_running(dev)) { |
| 4520 | nv_disable_irq(dev); |
Herbert Xu | 58dfd9c | 2006-06-21 10:53:54 +1000 | [diff] [blame] | 4521 | netif_tx_lock_bh(dev); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 4522 | netif_addr_lock(dev); |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 4523 | spin_lock(&np->lock); |
| 4524 | /* stop engines */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 4525 | nv_stop_rxtx(dev); |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 4526 | spin_unlock(&np->lock); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 4527 | netif_addr_unlock(dev); |
Herbert Xu | 58dfd9c | 2006-06-21 10:53:54 +1000 | [diff] [blame] | 4528 | netif_tx_unlock_bh(dev); |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 4529 | netdev_info(dev, "link down\n"); |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 4530 | } |
| 4531 | |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 4532 | bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 4533 | if (np->phy_model == PHY_MODEL_MARVELL_E3016) { |
| 4534 | bmcr |= BMCR_ANENABLE; |
| 4535 | /* reset the phy in order for settings to stick*/ |
| 4536 | if (phy_reset(dev, bmcr)) { |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 4537 | netdev_info(dev, "phy reset failed\n"); |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 4538 | return -EINVAL; |
| 4539 | } |
| 4540 | } else { |
| 4541 | bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART); |
| 4542 | mii_rw(dev, np->phyaddr, MII_BMCR, bmcr); |
| 4543 | } |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 4544 | |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 4545 | if (netif_running(dev)) { |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 4546 | nv_start_rxtx(dev); |
Ayaz Abdulla | f9430a0 | 2006-06-10 22:47:47 -0400 | [diff] [blame] | 4547 | nv_enable_irq(dev); |
| 4548 | } |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 4549 | ret = 0; |
| 4550 | } else { |
| 4551 | ret = -EINVAL; |
| 4552 | } |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 4553 | |
| 4554 | return ret; |
| 4555 | } |
| 4556 | |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4557 | static void nv_get_ringparam(struct net_device *dev, struct ethtool_ringparam* ring) |
| 4558 | { |
| 4559 | struct fe_priv *np = netdev_priv(dev); |
| 4560 | |
| 4561 | ring->rx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3; |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4562 | ring->tx_max_pending = (np->desc_ver == DESC_VER_1) ? RING_MAX_DESC_VER_1 : RING_MAX_DESC_VER_2_3; |
| 4563 | |
| 4564 | ring->rx_pending = np->rx_ring_size; |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4565 | ring->tx_pending = np->tx_ring_size; |
| 4566 | } |
| 4567 | |
| 4568 | static int nv_set_ringparam(struct net_device *dev, struct ethtool_ringparam* ring) |
| 4569 | { |
| 4570 | struct fe_priv *np = netdev_priv(dev); |
| 4571 | u8 __iomem *base = get_hwbase(dev); |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 4572 | u8 *rxtx_ring, *rx_skbuff, *tx_skbuff; |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4573 | dma_addr_t ring_addr; |
| 4574 | |
| 4575 | if (ring->rx_pending < RX_RING_MIN || |
| 4576 | ring->tx_pending < TX_RING_MIN || |
| 4577 | ring->rx_mini_pending != 0 || |
| 4578 | ring->rx_jumbo_pending != 0 || |
| 4579 | (np->desc_ver == DESC_VER_1 && |
| 4580 | (ring->rx_pending > RING_MAX_DESC_VER_1 || |
| 4581 | ring->tx_pending > RING_MAX_DESC_VER_1)) || |
| 4582 | (np->desc_ver != DESC_VER_1 && |
| 4583 | (ring->rx_pending > RING_MAX_DESC_VER_2_3 || |
| 4584 | ring->tx_pending > RING_MAX_DESC_VER_2_3))) { |
| 4585 | return -EINVAL; |
| 4586 | } |
| 4587 | |
| 4588 | /* allocate new rings */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 4589 | if (!nv_optimized(np)) { |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4590 | rxtx_ring = pci_alloc_consistent(np->pci_dev, |
| 4591 | sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending), |
| 4592 | &ring_addr); |
| 4593 | } else { |
| 4594 | rxtx_ring = pci_alloc_consistent(np->pci_dev, |
| 4595 | sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending), |
| 4596 | &ring_addr); |
| 4597 | } |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 4598 | rx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->rx_pending, GFP_KERNEL); |
| 4599 | tx_skbuff = kmalloc(sizeof(struct nv_skb_map) * ring->tx_pending, GFP_KERNEL); |
| 4600 | if (!rxtx_ring || !rx_skbuff || !tx_skbuff) { |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4601 | /* fall back to old rings */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 4602 | if (!nv_optimized(np)) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 4603 | if (rxtx_ring) |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4604 | pci_free_consistent(np->pci_dev, sizeof(struct ring_desc) * (ring->rx_pending + ring->tx_pending), |
| 4605 | rxtx_ring, ring_addr); |
| 4606 | } else { |
| 4607 | if (rxtx_ring) |
| 4608 | pci_free_consistent(np->pci_dev, sizeof(struct ring_desc_ex) * (ring->rx_pending + ring->tx_pending), |
| 4609 | rxtx_ring, ring_addr); |
| 4610 | } |
Szymon Janc | 9b03b06 | 2010-11-27 08:39:44 +0000 | [diff] [blame] | 4611 | |
| 4612 | kfree(rx_skbuff); |
| 4613 | kfree(tx_skbuff); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4614 | goto exit; |
| 4615 | } |
| 4616 | |
| 4617 | if (netif_running(dev)) { |
| 4618 | nv_disable_irq(dev); |
Ayaz Abdulla | 08d9357 | 2009-03-05 08:01:55 +0000 | [diff] [blame] | 4619 | nv_napi_disable(dev); |
Herbert Xu | 58dfd9c | 2006-06-21 10:53:54 +1000 | [diff] [blame] | 4620 | netif_tx_lock_bh(dev); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 4621 | netif_addr_lock(dev); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4622 | spin_lock(&np->lock); |
| 4623 | /* stop engines */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 4624 | nv_stop_rxtx(dev); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4625 | nv_txrx_reset(dev); |
| 4626 | /* drain queues */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 4627 | nv_drain_rxtx(dev); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4628 | /* delete queues */ |
| 4629 | free_rings(dev); |
| 4630 | } |
| 4631 | |
| 4632 | /* set new values */ |
| 4633 | np->rx_ring_size = ring->rx_pending; |
| 4634 | np->tx_ring_size = ring->tx_pending; |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 4635 | |
| 4636 | if (!nv_optimized(np)) { |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 4637 | np->rx_ring.orig = (struct ring_desc *)rxtx_ring; |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4638 | np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size]; |
| 4639 | } else { |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 4640 | np->rx_ring.ex = (struct ring_desc_ex *)rxtx_ring; |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4641 | np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size]; |
| 4642 | } |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 4643 | np->rx_skb = (struct nv_skb_map *)rx_skbuff; |
| 4644 | np->tx_skb = (struct nv_skb_map *)tx_skbuff; |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4645 | np->ring_addr = ring_addr; |
| 4646 | |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 4647 | memset(np->rx_skb, 0, sizeof(struct nv_skb_map) * np->rx_ring_size); |
| 4648 | memset(np->tx_skb, 0, sizeof(struct nv_skb_map) * np->tx_ring_size); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4649 | |
| 4650 | if (netif_running(dev)) { |
| 4651 | /* reinit driver view of the queues */ |
| 4652 | set_bufsize(dev); |
| 4653 | if (nv_init_ring(dev)) { |
| 4654 | if (!np->in_shutdown) |
| 4655 | mod_timer(&np->oom_kick, jiffies + OOM_REFILL); |
| 4656 | } |
| 4657 | |
| 4658 | /* reinit nic view of the queues */ |
| 4659 | writel(np->rx_buf_sz, base + NvRegOffloadConfig); |
| 4660 | setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING); |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 4661 | writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT), |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4662 | base + NvRegRingSizes); |
| 4663 | pci_push(base); |
| 4664 | writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl); |
| 4665 | pci_push(base); |
| 4666 | |
| 4667 | /* restart engines */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 4668 | nv_start_rxtx(dev); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4669 | spin_unlock(&np->lock); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 4670 | netif_addr_unlock(dev); |
Herbert Xu | 58dfd9c | 2006-06-21 10:53:54 +1000 | [diff] [blame] | 4671 | netif_tx_unlock_bh(dev); |
Ayaz Abdulla | 08d9357 | 2009-03-05 08:01:55 +0000 | [diff] [blame] | 4672 | nv_napi_enable(dev); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 4673 | nv_enable_irq(dev); |
| 4674 | } |
| 4675 | return 0; |
| 4676 | exit: |
| 4677 | return -ENOMEM; |
| 4678 | } |
| 4679 | |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 4680 | static void nv_get_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause) |
| 4681 | { |
| 4682 | struct fe_priv *np = netdev_priv(dev); |
| 4683 | |
| 4684 | pause->autoneg = (np->pause_flags & NV_PAUSEFRAME_AUTONEG) != 0; |
| 4685 | pause->rx_pause = (np->pause_flags & NV_PAUSEFRAME_RX_ENABLE) != 0; |
| 4686 | pause->tx_pause = (np->pause_flags & NV_PAUSEFRAME_TX_ENABLE) != 0; |
| 4687 | } |
| 4688 | |
| 4689 | static int nv_set_pauseparam(struct net_device *dev, struct ethtool_pauseparam* pause) |
| 4690 | { |
| 4691 | struct fe_priv *np = netdev_priv(dev); |
| 4692 | int adv, bmcr; |
| 4693 | |
| 4694 | if ((!np->autoneg && np->duplex == 0) || |
| 4695 | (np->autoneg && !pause->autoneg && np->duplex == 0)) { |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 4696 | netdev_info(dev, "can not set pause settings when forced link is in half duplex\n"); |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 4697 | return -EINVAL; |
| 4698 | } |
| 4699 | if (pause->tx_pause && !(np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE)) { |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 4700 | netdev_info(dev, "hardware does not support tx pause frames\n"); |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 4701 | return -EINVAL; |
| 4702 | } |
| 4703 | |
| 4704 | netif_carrier_off(dev); |
| 4705 | if (netif_running(dev)) { |
| 4706 | nv_disable_irq(dev); |
Herbert Xu | 58dfd9c | 2006-06-21 10:53:54 +1000 | [diff] [blame] | 4707 | netif_tx_lock_bh(dev); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 4708 | netif_addr_lock(dev); |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 4709 | spin_lock(&np->lock); |
| 4710 | /* stop engines */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 4711 | nv_stop_rxtx(dev); |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 4712 | spin_unlock(&np->lock); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 4713 | netif_addr_unlock(dev); |
Herbert Xu | 58dfd9c | 2006-06-21 10:53:54 +1000 | [diff] [blame] | 4714 | netif_tx_unlock_bh(dev); |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 4715 | } |
| 4716 | |
| 4717 | np->pause_flags &= ~(NV_PAUSEFRAME_RX_REQ|NV_PAUSEFRAME_TX_REQ); |
| 4718 | if (pause->rx_pause) |
| 4719 | np->pause_flags |= NV_PAUSEFRAME_RX_REQ; |
| 4720 | if (pause->tx_pause) |
| 4721 | np->pause_flags |= NV_PAUSEFRAME_TX_REQ; |
| 4722 | |
| 4723 | if (np->autoneg && pause->autoneg) { |
| 4724 | np->pause_flags |= NV_PAUSEFRAME_AUTONEG; |
| 4725 | |
| 4726 | adv = mii_rw(dev, np->phyaddr, MII_ADVERTISE, MII_READ); |
| 4727 | adv &= ~(ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM); |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 4728 | if (np->pause_flags & NV_PAUSEFRAME_RX_REQ) /* for rx we set both advertisements but disable tx pause */ |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 4729 | adv |= ADVERTISE_PAUSE_CAP | ADVERTISE_PAUSE_ASYM; |
| 4730 | if (np->pause_flags & NV_PAUSEFRAME_TX_REQ) |
| 4731 | adv |= ADVERTISE_PAUSE_ASYM; |
| 4732 | mii_rw(dev, np->phyaddr, MII_ADVERTISE, adv); |
| 4733 | |
| 4734 | if (netif_running(dev)) |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 4735 | netdev_info(dev, "link down\n"); |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 4736 | bmcr = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
| 4737 | bmcr |= (BMCR_ANENABLE | BMCR_ANRESTART); |
| 4738 | mii_rw(dev, np->phyaddr, MII_BMCR, bmcr); |
| 4739 | } else { |
| 4740 | np->pause_flags &= ~(NV_PAUSEFRAME_AUTONEG|NV_PAUSEFRAME_RX_ENABLE|NV_PAUSEFRAME_TX_ENABLE); |
| 4741 | if (pause->rx_pause) |
| 4742 | np->pause_flags |= NV_PAUSEFRAME_RX_ENABLE; |
| 4743 | if (pause->tx_pause) |
| 4744 | np->pause_flags |= NV_PAUSEFRAME_TX_ENABLE; |
| 4745 | |
| 4746 | if (!netif_running(dev)) |
| 4747 | nv_update_linkspeed(dev); |
| 4748 | else |
| 4749 | nv_update_pause(dev, np->pause_flags); |
| 4750 | } |
| 4751 | |
| 4752 | if (netif_running(dev)) { |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 4753 | nv_start_rxtx(dev); |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 4754 | nv_enable_irq(dev); |
| 4755 | } |
| 4756 | return 0; |
| 4757 | } |
| 4758 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 4759 | static int nv_set_loopback(struct net_device *dev, netdev_features_t features) |
Sanjay Hortikar | e19df76 | 2011-11-11 16:11:21 +0000 | [diff] [blame] | 4760 | { |
| 4761 | struct fe_priv *np = netdev_priv(dev); |
| 4762 | unsigned long flags; |
| 4763 | u32 miicontrol; |
| 4764 | int err, retval = 0; |
| 4765 | |
| 4766 | spin_lock_irqsave(&np->lock, flags); |
| 4767 | miicontrol = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
| 4768 | if (features & NETIF_F_LOOPBACK) { |
| 4769 | if (miicontrol & BMCR_LOOPBACK) { |
| 4770 | spin_unlock_irqrestore(&np->lock, flags); |
| 4771 | netdev_info(dev, "Loopback already enabled\n"); |
| 4772 | return 0; |
| 4773 | } |
| 4774 | nv_disable_irq(dev); |
| 4775 | /* Turn on loopback mode */ |
| 4776 | miicontrol |= BMCR_LOOPBACK | BMCR_FULLDPLX | BMCR_SPEED1000; |
| 4777 | err = mii_rw(dev, np->phyaddr, MII_BMCR, miicontrol); |
| 4778 | if (err) { |
| 4779 | retval = PHY_ERROR; |
| 4780 | spin_unlock_irqrestore(&np->lock, flags); |
| 4781 | phy_init(dev); |
| 4782 | } else { |
| 4783 | if (netif_running(dev)) { |
| 4784 | /* Force 1000 Mbps full-duplex */ |
| 4785 | nv_force_linkspeed(dev, NVREG_LINKSPEED_1000, |
| 4786 | 1); |
| 4787 | /* Force link up */ |
| 4788 | netif_carrier_on(dev); |
| 4789 | } |
| 4790 | spin_unlock_irqrestore(&np->lock, flags); |
| 4791 | netdev_info(dev, |
| 4792 | "Internal PHY loopback mode enabled.\n"); |
| 4793 | } |
| 4794 | } else { |
| 4795 | if (!(miicontrol & BMCR_LOOPBACK)) { |
| 4796 | spin_unlock_irqrestore(&np->lock, flags); |
| 4797 | netdev_info(dev, "Loopback already disabled\n"); |
| 4798 | return 0; |
| 4799 | } |
| 4800 | nv_disable_irq(dev); |
| 4801 | /* Turn off loopback */ |
| 4802 | spin_unlock_irqrestore(&np->lock, flags); |
| 4803 | netdev_info(dev, "Internal PHY loopback mode disabled.\n"); |
| 4804 | phy_init(dev); |
| 4805 | } |
| 4806 | msleep(500); |
| 4807 | spin_lock_irqsave(&np->lock, flags); |
| 4808 | nv_enable_irq(dev); |
| 4809 | spin_unlock_irqrestore(&np->lock, flags); |
| 4810 | |
| 4811 | return retval; |
| 4812 | } |
| 4813 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 4814 | static netdev_features_t nv_fix_features(struct net_device *dev, |
| 4815 | netdev_features_t features) |
Ayaz Abdulla | 5ed2616 | 2006-06-10 22:47:59 -0400 | [diff] [blame] | 4816 | { |
Michał Mirosław | 569e146 | 2011-04-15 04:50:49 +0000 | [diff] [blame] | 4817 | /* vlan is dependent on rx checksum offload */ |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 4818 | if (features & (NETIF_F_HW_VLAN_CTAG_TX|NETIF_F_HW_VLAN_CTAG_RX)) |
Michał Mirosław | 569e146 | 2011-04-15 04:50:49 +0000 | [diff] [blame] | 4819 | features |= NETIF_F_RXCSUM; |
| 4820 | |
| 4821 | return features; |
Ayaz Abdulla | 5ed2616 | 2006-06-10 22:47:59 -0400 | [diff] [blame] | 4822 | } |
| 4823 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 4824 | static void nv_vlan_mode(struct net_device *dev, netdev_features_t features) |
Jiri Pirko | 3326c78 | 2011-07-20 04:54:38 +0000 | [diff] [blame] | 4825 | { |
| 4826 | struct fe_priv *np = get_nvpriv(dev); |
| 4827 | |
| 4828 | spin_lock_irq(&np->lock); |
| 4829 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 4830 | if (features & NETIF_F_HW_VLAN_CTAG_RX) |
Jiri Pirko | 3326c78 | 2011-07-20 04:54:38 +0000 | [diff] [blame] | 4831 | np->txrxctl_bits |= NVREG_TXRXCTL_VLANSTRIP; |
| 4832 | else |
| 4833 | np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANSTRIP; |
| 4834 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 4835 | if (features & NETIF_F_HW_VLAN_CTAG_TX) |
Jiri Pirko | 3326c78 | 2011-07-20 04:54:38 +0000 | [diff] [blame] | 4836 | np->txrxctl_bits |= NVREG_TXRXCTL_VLANINS; |
| 4837 | else |
| 4838 | np->txrxctl_bits &= ~NVREG_TXRXCTL_VLANINS; |
| 4839 | |
| 4840 | writel(np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl); |
| 4841 | |
| 4842 | spin_unlock_irq(&np->lock); |
| 4843 | } |
| 4844 | |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 4845 | static int nv_set_features(struct net_device *dev, netdev_features_t features) |
Ayaz Abdulla | 5ed2616 | 2006-06-10 22:47:59 -0400 | [diff] [blame] | 4846 | { |
| 4847 | struct fe_priv *np = netdev_priv(dev); |
| 4848 | u8 __iomem *base = get_hwbase(dev); |
Michał Mirosław | c8f44af | 2011-11-15 15:29:55 +0000 | [diff] [blame] | 4849 | netdev_features_t changed = dev->features ^ features; |
Sanjay Hortikar | e19df76 | 2011-11-11 16:11:21 +0000 | [diff] [blame] | 4850 | int retval; |
| 4851 | |
| 4852 | if ((changed & NETIF_F_LOOPBACK) && netif_running(dev)) { |
| 4853 | retval = nv_set_loopback(dev, features); |
| 4854 | if (retval != 0) |
| 4855 | return retval; |
| 4856 | } |
Ayaz Abdulla | 5ed2616 | 2006-06-10 22:47:59 -0400 | [diff] [blame] | 4857 | |
Michał Mirosław | 569e146 | 2011-04-15 04:50:49 +0000 | [diff] [blame] | 4858 | if (changed & NETIF_F_RXCSUM) { |
| 4859 | spin_lock_irq(&np->lock); |
| 4860 | |
| 4861 | if (features & NETIF_F_RXCSUM) |
Ayaz Abdulla | 5ed2616 | 2006-06-10 22:47:59 -0400 | [diff] [blame] | 4862 | np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK; |
Michał Mirosław | 569e146 | 2011-04-15 04:50:49 +0000 | [diff] [blame] | 4863 | else |
| 4864 | np->txrxctl_bits &= ~NVREG_TXRXCTL_RXCHECK; |
| 4865 | |
| 4866 | if (netif_running(dev)) |
Ayaz Abdulla | 5ed2616 | 2006-06-10 22:47:59 -0400 | [diff] [blame] | 4867 | writel(np->txrxctl_bits, base + NvRegTxRxControl); |
Michał Mirosław | 569e146 | 2011-04-15 04:50:49 +0000 | [diff] [blame] | 4868 | |
| 4869 | spin_unlock_irq(&np->lock); |
Ayaz Abdulla | 5ed2616 | 2006-06-10 22:47:59 -0400 | [diff] [blame] | 4870 | } |
| 4871 | |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 4872 | if (changed & (NETIF_F_HW_VLAN_CTAG_TX | NETIF_F_HW_VLAN_CTAG_RX)) |
Jiri Pirko | 3326c78 | 2011-07-20 04:54:38 +0000 | [diff] [blame] | 4873 | nv_vlan_mode(dev, features); |
| 4874 | |
Michał Mirosław | 569e146 | 2011-04-15 04:50:49 +0000 | [diff] [blame] | 4875 | return 0; |
Ayaz Abdulla | 5ed2616 | 2006-06-10 22:47:59 -0400 | [diff] [blame] | 4876 | } |
| 4877 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 4878 | static int nv_get_sset_count(struct net_device *dev, int sset) |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 4879 | { |
| 4880 | struct fe_priv *np = netdev_priv(dev); |
| 4881 | |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 4882 | switch (sset) { |
| 4883 | case ETH_SS_TEST: |
| 4884 | if (np->driver_data & DEV_HAS_TEST_EXTENDED) |
| 4885 | return NV_TEST_COUNT_EXTENDED; |
| 4886 | else |
| 4887 | return NV_TEST_COUNT_BASE; |
| 4888 | case ETH_SS_STATS: |
Ayaz Abdulla | 8ed1454 | 2009-03-05 08:01:49 +0000 | [diff] [blame] | 4889 | if (np->driver_data & DEV_HAS_STATISTICS_V3) |
| 4890 | return NV_DEV_STATISTICS_V3_COUNT; |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 4891 | else if (np->driver_data & DEV_HAS_STATISTICS_V2) |
| 4892 | return NV_DEV_STATISTICS_V2_COUNT; |
Ayaz Abdulla | 8ed1454 | 2009-03-05 08:01:49 +0000 | [diff] [blame] | 4893 | else if (np->driver_data & DEV_HAS_STATISTICS_V1) |
| 4894 | return NV_DEV_STATISTICS_V1_COUNT; |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 4895 | else |
| 4896 | return 0; |
| 4897 | default: |
| 4898 | return -EOPNOTSUPP; |
| 4899 | } |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 4900 | } |
| 4901 | |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 4902 | static void nv_get_ethtool_stats(struct net_device *dev, |
| 4903 | struct ethtool_stats *estats, u64 *buffer) |
| 4904 | __acquires(&netdev_priv(dev)->hwstats_lock) |
| 4905 | __releases(&netdev_priv(dev)->hwstats_lock) |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 4906 | { |
| 4907 | struct fe_priv *np = netdev_priv(dev); |
| 4908 | |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 4909 | spin_lock_bh(&np->hwstats_lock); |
| 4910 | nv_update_stats(dev); |
| 4911 | memcpy(buffer, &np->estats, |
| 4912 | nv_get_sset_count(dev, ETH_SS_STATS)*sizeof(u64)); |
| 4913 | spin_unlock_bh(&np->hwstats_lock); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 4914 | } |
| 4915 | |
| 4916 | static int nv_link_test(struct net_device *dev) |
| 4917 | { |
| 4918 | struct fe_priv *np = netdev_priv(dev); |
| 4919 | int mii_status; |
| 4920 | |
| 4921 | mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ); |
| 4922 | mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ); |
| 4923 | |
| 4924 | /* check phy link status */ |
| 4925 | if (!(mii_status & BMSR_LSTATUS)) |
| 4926 | return 0; |
| 4927 | else |
| 4928 | return 1; |
| 4929 | } |
| 4930 | |
| 4931 | static int nv_register_test(struct net_device *dev) |
| 4932 | { |
| 4933 | u8 __iomem *base = get_hwbase(dev); |
| 4934 | int i = 0; |
| 4935 | u32 orig_read, new_read; |
| 4936 | |
| 4937 | do { |
| 4938 | orig_read = readl(base + nv_registers_test[i].reg); |
| 4939 | |
| 4940 | /* xor with mask to toggle bits */ |
| 4941 | orig_read ^= nv_registers_test[i].mask; |
| 4942 | |
| 4943 | writel(orig_read, base + nv_registers_test[i].reg); |
| 4944 | |
| 4945 | new_read = readl(base + nv_registers_test[i].reg); |
| 4946 | |
| 4947 | if ((new_read & nv_registers_test[i].mask) != (orig_read & nv_registers_test[i].mask)) |
| 4948 | return 0; |
| 4949 | |
| 4950 | /* restore original value */ |
| 4951 | orig_read ^= nv_registers_test[i].mask; |
| 4952 | writel(orig_read, base + nv_registers_test[i].reg); |
| 4953 | |
| 4954 | } while (nv_registers_test[++i].reg != 0); |
| 4955 | |
| 4956 | return 1; |
| 4957 | } |
| 4958 | |
| 4959 | static int nv_interrupt_test(struct net_device *dev) |
| 4960 | { |
| 4961 | struct fe_priv *np = netdev_priv(dev); |
| 4962 | u8 __iomem *base = get_hwbase(dev); |
| 4963 | int ret = 1; |
| 4964 | int testcnt; |
| 4965 | u32 save_msi_flags, save_poll_interval = 0; |
| 4966 | |
| 4967 | if (netif_running(dev)) { |
| 4968 | /* free current irq */ |
| 4969 | nv_free_irq(dev); |
| 4970 | save_poll_interval = readl(base+NvRegPollingInterval); |
| 4971 | } |
| 4972 | |
| 4973 | /* flag to test interrupt handler */ |
| 4974 | np->intr_test = 0; |
| 4975 | |
| 4976 | /* setup test irq */ |
| 4977 | save_msi_flags = np->msi_flags; |
| 4978 | np->msi_flags &= ~NV_MSI_X_VECTORS_MASK; |
| 4979 | np->msi_flags |= 0x001; /* setup 1 vector */ |
| 4980 | if (nv_request_irq(dev, 1)) |
| 4981 | return 0; |
| 4982 | |
| 4983 | /* setup timer interrupt */ |
| 4984 | writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval); |
| 4985 | writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6); |
| 4986 | |
| 4987 | nv_enable_hw_interrupts(dev, NVREG_IRQ_TIMER); |
| 4988 | |
| 4989 | /* wait for at least one interrupt */ |
| 4990 | msleep(100); |
| 4991 | |
| 4992 | spin_lock_irq(&np->lock); |
| 4993 | |
| 4994 | /* flag should be set within ISR */ |
| 4995 | testcnt = np->intr_test; |
| 4996 | if (!testcnt) |
| 4997 | ret = 2; |
| 4998 | |
| 4999 | nv_disable_hw_interrupts(dev, NVREG_IRQ_TIMER); |
| 5000 | if (!(np->msi_flags & NV_MSI_X_ENABLED)) |
| 5001 | writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus); |
| 5002 | else |
| 5003 | writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus); |
| 5004 | |
| 5005 | spin_unlock_irq(&np->lock); |
| 5006 | |
| 5007 | nv_free_irq(dev); |
| 5008 | |
| 5009 | np->msi_flags = save_msi_flags; |
| 5010 | |
| 5011 | if (netif_running(dev)) { |
| 5012 | writel(save_poll_interval, base + NvRegPollingInterval); |
| 5013 | writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6); |
| 5014 | /* restore original irq */ |
| 5015 | if (nv_request_irq(dev, 0)) |
| 5016 | return 0; |
| 5017 | } |
| 5018 | |
| 5019 | return ret; |
| 5020 | } |
| 5021 | |
| 5022 | static int nv_loopback_test(struct net_device *dev) |
| 5023 | { |
| 5024 | struct fe_priv *np = netdev_priv(dev); |
| 5025 | u8 __iomem *base = get_hwbase(dev); |
| 5026 | struct sk_buff *tx_skb, *rx_skb; |
| 5027 | dma_addr_t test_dma_addr; |
| 5028 | u32 tx_flags_extra = (np->desc_ver == DESC_VER_1 ? NV_TX_LASTPACKET : NV_TX2_LASTPACKET); |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 5029 | u32 flags; |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5030 | int len, i, pkt_len; |
| 5031 | u8 *pkt_data; |
| 5032 | u32 filter_flags = 0; |
| 5033 | u32 misc1_flags = 0; |
| 5034 | int ret = 1; |
| 5035 | |
| 5036 | if (netif_running(dev)) { |
| 5037 | nv_disable_irq(dev); |
| 5038 | filter_flags = readl(base + NvRegPacketFilterFlags); |
| 5039 | misc1_flags = readl(base + NvRegMisc1); |
| 5040 | } else { |
| 5041 | nv_txrx_reset(dev); |
| 5042 | } |
| 5043 | |
| 5044 | /* reinit driver view of the rx queue */ |
| 5045 | set_bufsize(dev); |
| 5046 | nv_init_ring(dev); |
| 5047 | |
| 5048 | /* setup hardware for loopback */ |
| 5049 | writel(NVREG_MISC1_FORCE, base + NvRegMisc1); |
| 5050 | writel(NVREG_PFF_ALWAYS | NVREG_PFF_LOOPBACK, base + NvRegPacketFilterFlags); |
| 5051 | |
| 5052 | /* reinit nic view of the rx queue */ |
| 5053 | writel(np->rx_buf_sz, base + NvRegOffloadConfig); |
| 5054 | setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING); |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 5055 | writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT), |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5056 | base + NvRegRingSizes); |
| 5057 | pci_push(base); |
| 5058 | |
| 5059 | /* restart rx engine */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 5060 | nv_start_rxtx(dev); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5061 | |
| 5062 | /* setup packet for tx */ |
| 5063 | pkt_len = ETH_DATA_LEN; |
Pradeep A. Dalvi | dae2e9f | 2012-02-06 11:16:13 +0000 | [diff] [blame] | 5064 | tx_skb = netdev_alloc_skb(dev, pkt_len); |
Jesper Juhl | 46798c8 | 2006-09-25 16:39:24 -0700 | [diff] [blame] | 5065 | if (!tx_skb) { |
Jesper Juhl | 46798c8 | 2006-09-25 16:39:24 -0700 | [diff] [blame] | 5066 | ret = 0; |
| 5067 | goto out; |
| 5068 | } |
Arnaldo Carvalho de Melo | 8b5be26 | 2007-03-20 12:08:20 -0300 | [diff] [blame] | 5069 | test_dma_addr = pci_map_single(np->pci_dev, tx_skb->data, |
| 5070 | skb_tailroom(tx_skb), |
| 5071 | PCI_DMA_FROMDEVICE); |
Larry Finger | 612a7c4 | 2012-12-27 17:25:41 +0000 | [diff] [blame] | 5072 | if (pci_dma_mapping_error(np->pci_dev, |
| 5073 | test_dma_addr)) { |
| 5074 | dev_kfree_skb_any(tx_skb); |
| 5075 | goto out; |
| 5076 | } |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5077 | pkt_data = skb_put(tx_skb, pkt_len); |
| 5078 | for (i = 0; i < pkt_len; i++) |
| 5079 | pkt_data[i] = (u8)(i & 0xff); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5080 | |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 5081 | if (!nv_optimized(np)) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 5082 | np->tx_ring.orig[0].buf = cpu_to_le32(test_dma_addr); |
| 5083 | np->tx_ring.orig[0].flaglen = cpu_to_le32((pkt_len-1) | np->tx_flags | tx_flags_extra); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5084 | } else { |
Al Viro | 5bb7ea2 | 2007-12-09 16:06:41 +0000 | [diff] [blame] | 5085 | np->tx_ring.ex[0].bufhigh = cpu_to_le32(dma_high(test_dma_addr)); |
| 5086 | np->tx_ring.ex[0].buflow = cpu_to_le32(dma_low(test_dma_addr)); |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 5087 | np->tx_ring.ex[0].flaglen = cpu_to_le32((pkt_len-1) | np->tx_flags | tx_flags_extra); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5088 | } |
| 5089 | writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl); |
| 5090 | pci_push(get_hwbase(dev)); |
| 5091 | |
| 5092 | msleep(500); |
| 5093 | |
| 5094 | /* check for rx of the packet */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 5095 | if (!nv_optimized(np)) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 5096 | flags = le32_to_cpu(np->rx_ring.orig[0].flaglen); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5097 | len = nv_descr_getlength(&np->rx_ring.orig[0], np->desc_ver); |
| 5098 | |
| 5099 | } else { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 5100 | flags = le32_to_cpu(np->rx_ring.ex[0].flaglen); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5101 | len = nv_descr_getlength_ex(&np->rx_ring.ex[0], np->desc_ver); |
| 5102 | } |
| 5103 | |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 5104 | if (flags & NV_RX_AVAIL) { |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5105 | ret = 0; |
| 5106 | } else if (np->desc_ver == DESC_VER_1) { |
Stephen Hemminger | f82a935 | 2006-07-27 18:50:08 -0700 | [diff] [blame] | 5107 | if (flags & NV_RX_ERROR) |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5108 | ret = 0; |
| 5109 | } else { |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 5110 | if (flags & NV_RX2_ERROR) |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5111 | ret = 0; |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5112 | } |
| 5113 | |
| 5114 | if (ret) { |
| 5115 | if (len != pkt_len) { |
| 5116 | ret = 0; |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5117 | } else { |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 5118 | rx_skb = np->rx_skb[0].skb; |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5119 | for (i = 0; i < pkt_len; i++) { |
| 5120 | if (rx_skb->data[i] != (u8)(i & 0xff)) { |
| 5121 | ret = 0; |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5122 | break; |
| 5123 | } |
| 5124 | } |
| 5125 | } |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5126 | } |
| 5127 | |
Eric Dumazet | 73a3707 | 2009-06-17 21:17:59 +0000 | [diff] [blame] | 5128 | pci_unmap_single(np->pci_dev, test_dma_addr, |
Arnaldo Carvalho de Melo | 4305b54 | 2007-04-19 20:43:29 -0700 | [diff] [blame] | 5129 | (skb_end_pointer(tx_skb) - tx_skb->data), |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5130 | PCI_DMA_TODEVICE); |
| 5131 | dev_kfree_skb_any(tx_skb); |
Jesper Juhl | 46798c8 | 2006-09-25 16:39:24 -0700 | [diff] [blame] | 5132 | out: |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5133 | /* stop engines */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 5134 | nv_stop_rxtx(dev); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5135 | nv_txrx_reset(dev); |
| 5136 | /* drain rx queue */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 5137 | nv_drain_rxtx(dev); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5138 | |
| 5139 | if (netif_running(dev)) { |
| 5140 | writel(misc1_flags, base + NvRegMisc1); |
| 5141 | writel(filter_flags, base + NvRegPacketFilterFlags); |
| 5142 | nv_enable_irq(dev); |
| 5143 | } |
| 5144 | |
| 5145 | return ret; |
| 5146 | } |
| 5147 | |
| 5148 | static void nv_self_test(struct net_device *dev, struct ethtool_test *test, u64 *buffer) |
| 5149 | { |
| 5150 | struct fe_priv *np = netdev_priv(dev); |
| 5151 | u8 __iomem *base = get_hwbase(dev); |
| 5152 | int result; |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 5153 | memset(buffer, 0, nv_get_sset_count(dev, ETH_SS_TEST)*sizeof(u64)); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5154 | |
| 5155 | if (!nv_link_test(dev)) { |
| 5156 | test->flags |= ETH_TEST_FL_FAILED; |
| 5157 | buffer[0] = 1; |
| 5158 | } |
| 5159 | |
| 5160 | if (test->flags & ETH_TEST_FL_OFFLINE) { |
| 5161 | if (netif_running(dev)) { |
| 5162 | netif_stop_queue(dev); |
Ayaz Abdulla | 08d9357 | 2009-03-05 08:01:55 +0000 | [diff] [blame] | 5163 | nv_napi_disable(dev); |
Herbert Xu | 58dfd9c | 2006-06-21 10:53:54 +1000 | [diff] [blame] | 5164 | netif_tx_lock_bh(dev); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 5165 | netif_addr_lock(dev); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5166 | spin_lock_irq(&np->lock); |
| 5167 | nv_disable_hw_interrupts(dev, np->irqmask); |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 5168 | if (!(np->msi_flags & NV_MSI_X_ENABLED)) |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5169 | writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus); |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 5170 | else |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5171 | writel(NVREG_IRQSTAT_MASK, base + NvRegMSIXIrqStatus); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5172 | /* stop engines */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 5173 | nv_stop_rxtx(dev); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5174 | nv_txrx_reset(dev); |
| 5175 | /* drain rx queue */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 5176 | nv_drain_rxtx(dev); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5177 | spin_unlock_irq(&np->lock); |
David S. Miller | e308a5d | 2008-07-15 00:13:44 -0700 | [diff] [blame] | 5178 | netif_addr_unlock(dev); |
Herbert Xu | 58dfd9c | 2006-06-21 10:53:54 +1000 | [diff] [blame] | 5179 | netif_tx_unlock_bh(dev); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5180 | } |
| 5181 | |
| 5182 | if (!nv_register_test(dev)) { |
| 5183 | test->flags |= ETH_TEST_FL_FAILED; |
| 5184 | buffer[1] = 1; |
| 5185 | } |
| 5186 | |
| 5187 | result = nv_interrupt_test(dev); |
| 5188 | if (result != 1) { |
| 5189 | test->flags |= ETH_TEST_FL_FAILED; |
| 5190 | buffer[2] = 1; |
| 5191 | } |
| 5192 | if (result == 0) { |
| 5193 | /* bail out */ |
| 5194 | return; |
| 5195 | } |
| 5196 | |
| 5197 | if (!nv_loopback_test(dev)) { |
| 5198 | test->flags |= ETH_TEST_FL_FAILED; |
| 5199 | buffer[3] = 1; |
| 5200 | } |
| 5201 | |
| 5202 | if (netif_running(dev)) { |
| 5203 | /* reinit driver view of the rx queue */ |
| 5204 | set_bufsize(dev); |
| 5205 | if (nv_init_ring(dev)) { |
| 5206 | if (!np->in_shutdown) |
| 5207 | mod_timer(&np->oom_kick, jiffies + OOM_REFILL); |
| 5208 | } |
| 5209 | /* reinit nic view of the rx queue */ |
| 5210 | writel(np->rx_buf_sz, base + NvRegOffloadConfig); |
| 5211 | setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING); |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 5212 | writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT), |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5213 | base + NvRegRingSizes); |
| 5214 | pci_push(base); |
| 5215 | writel(NVREG_TXRXCTL_KICK|np->txrxctl_bits, get_hwbase(dev) + NvRegTxRxControl); |
| 5216 | pci_push(base); |
| 5217 | /* restart rx engine */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 5218 | nv_start_rxtx(dev); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5219 | netif_start_queue(dev); |
Ayaz Abdulla | 08d9357 | 2009-03-05 08:01:55 +0000 | [diff] [blame] | 5220 | nv_napi_enable(dev); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5221 | nv_enable_hw_interrupts(dev, np->irqmask); |
| 5222 | } |
| 5223 | } |
| 5224 | } |
| 5225 | |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 5226 | static void nv_get_strings(struct net_device *dev, u32 stringset, u8 *buffer) |
| 5227 | { |
| 5228 | switch (stringset) { |
| 5229 | case ETH_SS_STATS: |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 5230 | memcpy(buffer, &nv_estats_str, nv_get_sset_count(dev, ETH_SS_STATS)*sizeof(struct nv_ethtool_str)); |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 5231 | break; |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5232 | case ETH_SS_TEST: |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 5233 | memcpy(buffer, &nv_etests_str, nv_get_sset_count(dev, ETH_SS_TEST)*sizeof(struct nv_ethtool_str)); |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5234 | break; |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 5235 | } |
| 5236 | } |
| 5237 | |
Jeff Garzik | 7282d49 | 2006-09-13 14:30:00 -0400 | [diff] [blame] | 5238 | static const struct ethtool_ops ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5239 | .get_drvinfo = nv_get_drvinfo, |
| 5240 | .get_link = ethtool_op_get_link, |
| 5241 | .get_wol = nv_get_wol, |
| 5242 | .set_wol = nv_set_wol, |
| 5243 | .get_settings = nv_get_settings, |
| 5244 | .set_settings = nv_set_settings, |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 5245 | .get_regs_len = nv_get_regs_len, |
| 5246 | .get_regs = nv_get_regs, |
| 5247 | .nway_reset = nv_nway_reset, |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 5248 | .get_ringparam = nv_get_ringparam, |
| 5249 | .set_ringparam = nv_set_ringparam, |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 5250 | .get_pauseparam = nv_get_pauseparam, |
| 5251 | .set_pauseparam = nv_set_pauseparam, |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 5252 | .get_strings = nv_get_strings, |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 5253 | .get_ethtool_stats = nv_get_ethtool_stats, |
Jeff Garzik | b9f2c04 | 2007-10-03 18:07:32 -0700 | [diff] [blame] | 5254 | .get_sset_count = nv_get_sset_count, |
Ayaz Abdulla | 9589c77 | 2006-06-10 22:48:13 -0400 | [diff] [blame] | 5255 | .self_test = nv_self_test, |
Richard Cochran | 7491302 | 2012-07-22 07:15:42 +0000 | [diff] [blame] | 5256 | .get_ts_info = ethtool_op_get_ts_info, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5257 | }; |
| 5258 | |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5259 | /* The mgmt unit and driver use a semaphore to access the phy during init */ |
| 5260 | static int nv_mgmt_acquire_sema(struct net_device *dev) |
| 5261 | { |
Ayaz Abdulla | cac1c52 | 2009-02-07 00:23:57 -0800 | [diff] [blame] | 5262 | struct fe_priv *np = netdev_priv(dev); |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5263 | u8 __iomem *base = get_hwbase(dev); |
| 5264 | int i; |
| 5265 | u32 tx_ctrl, mgmt_sema; |
| 5266 | |
| 5267 | for (i = 0; i < 10; i++) { |
| 5268 | mgmt_sema = readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_SEMA_MASK; |
| 5269 | if (mgmt_sema == NVREG_XMITCTL_MGMT_SEMA_FREE) |
| 5270 | break; |
| 5271 | msleep(500); |
| 5272 | } |
| 5273 | |
| 5274 | if (mgmt_sema != NVREG_XMITCTL_MGMT_SEMA_FREE) |
| 5275 | return 0; |
| 5276 | |
| 5277 | for (i = 0; i < 2; i++) { |
| 5278 | tx_ctrl = readl(base + NvRegTransmitterControl); |
| 5279 | tx_ctrl |= NVREG_XMITCTL_HOST_SEMA_ACQ; |
| 5280 | writel(tx_ctrl, base + NvRegTransmitterControl); |
| 5281 | |
| 5282 | /* verify that semaphore was acquired */ |
| 5283 | tx_ctrl = readl(base + NvRegTransmitterControl); |
| 5284 | if (((tx_ctrl & NVREG_XMITCTL_HOST_SEMA_MASK) == NVREG_XMITCTL_HOST_SEMA_ACQ) && |
Ayaz Abdulla | cac1c52 | 2009-02-07 00:23:57 -0800 | [diff] [blame] | 5285 | ((tx_ctrl & NVREG_XMITCTL_MGMT_SEMA_MASK) == NVREG_XMITCTL_MGMT_SEMA_FREE)) { |
| 5286 | np->mgmt_sema = 1; |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5287 | return 1; |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 5288 | } else |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5289 | udelay(50); |
| 5290 | } |
| 5291 | |
| 5292 | return 0; |
| 5293 | } |
| 5294 | |
Ayaz Abdulla | cac1c52 | 2009-02-07 00:23:57 -0800 | [diff] [blame] | 5295 | static void nv_mgmt_release_sema(struct net_device *dev) |
| 5296 | { |
| 5297 | struct fe_priv *np = netdev_priv(dev); |
| 5298 | u8 __iomem *base = get_hwbase(dev); |
| 5299 | u32 tx_ctrl; |
| 5300 | |
| 5301 | if (np->driver_data & DEV_HAS_MGMT_UNIT) { |
| 5302 | if (np->mgmt_sema) { |
| 5303 | tx_ctrl = readl(base + NvRegTransmitterControl); |
| 5304 | tx_ctrl &= ~NVREG_XMITCTL_HOST_SEMA_ACQ; |
| 5305 | writel(tx_ctrl, base + NvRegTransmitterControl); |
| 5306 | } |
| 5307 | } |
| 5308 | } |
| 5309 | |
| 5310 | |
| 5311 | static int nv_mgmt_get_version(struct net_device *dev) |
| 5312 | { |
| 5313 | struct fe_priv *np = netdev_priv(dev); |
| 5314 | u8 __iomem *base = get_hwbase(dev); |
| 5315 | u32 data_ready = readl(base + NvRegTransmitterControl); |
| 5316 | u32 data_ready2 = 0; |
| 5317 | unsigned long start; |
| 5318 | int ready = 0; |
| 5319 | |
| 5320 | writel(NVREG_MGMTUNITGETVERSION, base + NvRegMgmtUnitGetVersion); |
| 5321 | writel(data_ready ^ NVREG_XMITCTL_DATA_START, base + NvRegTransmitterControl); |
| 5322 | start = jiffies; |
| 5323 | while (time_before(jiffies, start + 5*HZ)) { |
| 5324 | data_ready2 = readl(base + NvRegTransmitterControl); |
| 5325 | if ((data_ready & NVREG_XMITCTL_DATA_READY) != (data_ready2 & NVREG_XMITCTL_DATA_READY)) { |
| 5326 | ready = 1; |
| 5327 | break; |
| 5328 | } |
| 5329 | schedule_timeout_uninterruptible(1); |
| 5330 | } |
| 5331 | |
| 5332 | if (!ready || (data_ready2 & NVREG_XMITCTL_DATA_ERROR)) |
| 5333 | return 0; |
| 5334 | |
| 5335 | np->mgmt_version = readl(base + NvRegMgmtUnitVersion) & NVREG_MGMTUNITVERSION; |
| 5336 | |
| 5337 | return 1; |
| 5338 | } |
| 5339 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5340 | static int nv_open(struct net_device *dev) |
| 5341 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 5342 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5343 | u8 __iomem *base = get_hwbase(dev); |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 5344 | int ret = 1; |
| 5345 | int oom, i; |
Ayaz Abdulla | a433686 | 2008-04-18 13:50:43 -0700 | [diff] [blame] | 5346 | u32 low; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5347 | |
Ed Swierk | cb52deb | 2008-12-01 12:24:43 +0000 | [diff] [blame] | 5348 | /* power up phy */ |
| 5349 | mii_rw(dev, np->phyaddr, MII_BMCR, |
| 5350 | mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ) & ~BMCR_PDOWN); |
| 5351 | |
Ayaz Abdulla | 88d7d8b | 2009-05-01 01:41:50 +0000 | [diff] [blame] | 5352 | nv_txrx_gate(dev, false); |
Ayaz Abdulla | f148965 | 2006-07-31 12:04:45 -0400 | [diff] [blame] | 5353 | /* erase previous misconfiguration */ |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 5354 | if (np->driver_data & DEV_HAS_POWER_CNTRL) |
| 5355 | nv_mac_reset(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5356 | writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA); |
| 5357 | writel(0, base + NvRegMulticastAddrB); |
Ayaz Abdulla | bb9a4fd | 2008-01-13 16:03:04 -0500 | [diff] [blame] | 5358 | writel(NVREG_MCASTMASKA_NONE, base + NvRegMulticastMaskA); |
| 5359 | writel(NVREG_MCASTMASKB_NONE, base + NvRegMulticastMaskB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5360 | writel(0, base + NvRegPacketFilterFlags); |
| 5361 | |
| 5362 | writel(0, base + NvRegTransmitterControl); |
| 5363 | writel(0, base + NvRegReceiverControl); |
| 5364 | |
| 5365 | writel(0, base + NvRegAdapterControl); |
| 5366 | |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 5367 | if (np->pause_flags & NV_PAUSEFRAME_TX_CAPABLE) |
| 5368 | writel(NVREG_TX_PAUSEFRAME_DISABLE, base + NvRegTxPauseFrame); |
| 5369 | |
Ayaz Abdulla | f148965 | 2006-07-31 12:04:45 -0400 | [diff] [blame] | 5370 | /* initialize descriptor rings */ |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 5371 | set_bufsize(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5372 | oom = nv_init_ring(dev); |
| 5373 | |
| 5374 | writel(0, base + NvRegLinkSpeed); |
Ayaz Abdulla | 5070d34 | 2006-07-31 12:05:01 -0400 | [diff] [blame] | 5375 | writel(readl(base + NvRegTransmitPoll) & NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5376 | nv_txrx_reset(dev); |
| 5377 | writel(0, base + NvRegUnknownSetupReg6); |
| 5378 | |
| 5379 | np->in_shutdown = 0; |
| 5380 | |
Ayaz Abdulla | f148965 | 2006-07-31 12:04:45 -0400 | [diff] [blame] | 5381 | /* give hw rings */ |
Ayaz Abdulla | 0832b25 | 2006-02-04 13:13:26 -0500 | [diff] [blame] | 5382 | setup_hw_rings(dev, NV_SETUP_RX_RING | NV_SETUP_TX_RING); |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 5383 | writel(((np->rx_ring_size-1) << NVREG_RINGSZ_RXSHIFT) + ((np->tx_ring_size-1) << NVREG_RINGSZ_TXSHIFT), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5384 | base + NvRegRingSizes); |
| 5385 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5386 | writel(np->linkspeed, base + NvRegLinkSpeed); |
Ayaz Abdulla | 95d161c | 2006-07-06 16:46:25 -0400 | [diff] [blame] | 5387 | if (np->desc_ver == DESC_VER_1) |
| 5388 | writel(NVREG_TX_WM_DESC1_DEFAULT, base + NvRegTxWatermark); |
| 5389 | else |
| 5390 | writel(NVREG_TX_WM_DESC2_3_DEFAULT, base + NvRegTxWatermark); |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 5391 | writel(np->txrxctl_bits, base + NvRegTxRxControl); |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 5392 | writel(np->vlanctl_bits, base + NvRegVlanControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5393 | pci_push(base); |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 5394 | writel(NVREG_TXRXCTL_BIT1|np->txrxctl_bits, base + NvRegTxRxControl); |
Joe Perches | 344d0dc | 2010-11-29 07:41:52 +0000 | [diff] [blame] | 5395 | if (reg_delay(dev, NvRegUnknownSetupReg5, |
| 5396 | NVREG_UNKSETUP5_BIT31, NVREG_UNKSETUP5_BIT31, |
| 5397 | NV_SETUP5_DELAY, NV_SETUP5_DELAYMAX)) |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 5398 | netdev_info(dev, |
| 5399 | "%s: SetupReg5, Bit 31 remained off\n", __func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5400 | |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5401 | writel(0, base + NvRegMIIMask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5402 | writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus); |
Ayaz Abdulla | eb79842 | 2008-02-04 15:14:04 -0500 | [diff] [blame] | 5403 | writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5405 | writel(NVREG_MISC1_FORCE | NVREG_MISC1_HD, base + NvRegMisc1); |
| 5406 | writel(readl(base + NvRegTransmitterStatus), base + NvRegTransmitterStatus); |
| 5407 | writel(NVREG_PFF_ALWAYS, base + NvRegPacketFilterFlags); |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 5408 | writel(np->rx_buf_sz, base + NvRegOffloadConfig); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5409 | |
| 5410 | writel(readl(base + NvRegReceiverStatus), base + NvRegReceiverStatus); |
Ayaz Abdulla | a433686 | 2008-04-18 13:50:43 -0700 | [diff] [blame] | 5411 | |
| 5412 | get_random_bytes(&low, sizeof(low)); |
| 5413 | low &= NVREG_SLOTTIME_MASK; |
| 5414 | if (np->desc_ver == DESC_VER_1) { |
| 5415 | writel(low|NVREG_SLOTTIME_DEFAULT, base + NvRegSlotTime); |
| 5416 | } else { |
| 5417 | if (!(np->driver_data & DEV_HAS_GEAR_MODE)) { |
| 5418 | /* setup legacy backoff */ |
| 5419 | writel(NVREG_SLOTTIME_LEGBF_ENABLED|NVREG_SLOTTIME_10_100_FULL|low, base + NvRegSlotTime); |
| 5420 | } else { |
| 5421 | writel(NVREG_SLOTTIME_10_100_FULL, base + NvRegSlotTime); |
| 5422 | nv_gear_backoff_reseed(dev); |
| 5423 | } |
| 5424 | } |
Ayaz Abdulla | 9744e21 | 2006-07-06 16:45:58 -0400 | [diff] [blame] | 5425 | writel(NVREG_TX_DEFERRAL_DEFAULT, base + NvRegTxDeferral); |
| 5426 | writel(NVREG_RX_DEFERRAL_DEFAULT, base + NvRegRxDeferral); |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 5427 | if (poll_interval == -1) { |
| 5428 | if (optimization_mode == NV_OPTIMIZATION_MODE_THROUGHPUT) |
| 5429 | writel(NVREG_POLL_DEFAULT_THROUGHPUT, base + NvRegPollingInterval); |
| 5430 | else |
| 5431 | writel(NVREG_POLL_DEFAULT_CPU, base + NvRegPollingInterval); |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 5432 | } else |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 5433 | writel(poll_interval & 0xFFFF, base + NvRegPollingInterval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5434 | writel(NVREG_UNKSETUP6_VAL, base + NvRegUnknownSetupReg6); |
| 5435 | writel((np->phyaddr << NVREG_ADAPTCTL_PHYSHIFT)|NVREG_ADAPTCTL_PHYVALID|NVREG_ADAPTCTL_RUNNING, |
| 5436 | base + NvRegAdapterControl); |
| 5437 | writel(NVREG_MIISPEED_BIT8|NVREG_MIIDELAY, base + NvRegMIISpeed); |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5438 | writel(NVREG_MII_LINKCHANGE, base + NvRegMIIMask); |
Ayaz Abdulla | c42d9df | 2006-06-10 22:47:52 -0400 | [diff] [blame] | 5439 | if (np->wolenabled) |
| 5440 | writel(NVREG_WAKEUPFLAGS_ENABLE , base + NvRegWakeUpFlags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5441 | |
| 5442 | i = readl(base + NvRegPowerState); |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 5443 | if ((i & NVREG_POWERSTATE_POWEREDUP) == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5444 | writel(NVREG_POWERSTATE_POWEREDUP|i, base + NvRegPowerState); |
| 5445 | |
| 5446 | pci_push(base); |
| 5447 | udelay(10); |
| 5448 | writel(readl(base + NvRegPowerState) | NVREG_POWERSTATE_VALID, base + NvRegPowerState); |
| 5449 | |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 5450 | nv_disable_hw_interrupts(dev, np->irqmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5451 | pci_push(base); |
Ayaz Abdulla | eb79842 | 2008-02-04 15:14:04 -0500 | [diff] [blame] | 5452 | writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5453 | writel(NVREG_IRQSTAT_MASK, base + NvRegIrqStatus); |
| 5454 | pci_push(base); |
| 5455 | |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 5456 | if (nv_request_irq(dev, 0)) |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 5457 | goto out_drain; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5458 | |
| 5459 | /* ask for interrupts */ |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 5460 | nv_enable_hw_interrupts(dev, np->irqmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5461 | |
| 5462 | spin_lock_irq(&np->lock); |
| 5463 | writel(NVREG_MCASTADDRA_FORCE, base + NvRegMulticastAddrA); |
| 5464 | writel(0, base + NvRegMulticastAddrB); |
Ayaz Abdulla | bb9a4fd | 2008-01-13 16:03:04 -0500 | [diff] [blame] | 5465 | writel(NVREG_MCASTMASKA_NONE, base + NvRegMulticastMaskA); |
| 5466 | writel(NVREG_MCASTMASKB_NONE, base + NvRegMulticastMaskB); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5467 | writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags); |
| 5468 | /* One manual link speed update: Interrupts are enabled, future link |
| 5469 | * speed changes cause interrupts and are handled by nv_link_irq(). |
| 5470 | */ |
| 5471 | { |
| 5472 | u32 miistat; |
| 5473 | miistat = readl(base + NvRegMIIStatus); |
Ayaz Abdulla | eb79842 | 2008-02-04 15:14:04 -0500 | [diff] [blame] | 5474 | writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5475 | } |
Manfred Spraul | 1b1b3c9 | 2005-08-06 23:47:55 +0200 | [diff] [blame] | 5476 | /* set linkspeed to invalid value, thus force nv_update_linkspeed |
| 5477 | * to init hw */ |
| 5478 | np->linkspeed = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5479 | ret = nv_update_linkspeed(dev); |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 5480 | nv_start_rxtx(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5481 | netif_start_queue(dev); |
Ayaz Abdulla | 08d9357 | 2009-03-05 08:01:55 +0000 | [diff] [blame] | 5482 | nv_napi_enable(dev); |
Stephen Hemminger | e27cdba | 2006-07-31 20:37:19 -0700 | [diff] [blame] | 5483 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5484 | if (ret) { |
| 5485 | netif_carrier_on(dev); |
| 5486 | } else { |
Joe Perches | 1d397f3 | 2010-11-29 07:41:57 +0000 | [diff] [blame] | 5487 | netdev_info(dev, "no link during initialization\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5488 | netif_carrier_off(dev); |
| 5489 | } |
| 5490 | if (oom) |
| 5491 | mod_timer(&np->oom_kick, jiffies + OOM_REFILL); |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 5492 | |
| 5493 | /* start statistics timer */ |
Ayaz Abdulla | 9c66243 | 2008-08-06 12:11:42 -0400 | [diff] [blame] | 5494 | if (np->driver_data & (DEV_HAS_STATISTICS_V1|DEV_HAS_STATISTICS_V2|DEV_HAS_STATISTICS_V3)) |
Daniel Drake | bfebbb8 | 2008-03-18 11:07:18 +0000 | [diff] [blame] | 5495 | mod_timer(&np->stats_poll, |
| 5496 | round_jiffies(jiffies + STATS_INTERVAL)); |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 5497 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5498 | spin_unlock_irq(&np->lock); |
| 5499 | |
Sanjay Hortikar | e19df76 | 2011-11-11 16:11:21 +0000 | [diff] [blame] | 5500 | /* If the loopback feature was set while the device was down, make sure |
| 5501 | * that it's set correctly now. |
| 5502 | */ |
| 5503 | if (dev->features & NETIF_F_LOOPBACK) |
| 5504 | nv_set_loopback(dev, dev->features); |
| 5505 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5506 | return 0; |
| 5507 | out_drain: |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 5508 | nv_drain_rxtx(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5509 | return ret; |
| 5510 | } |
| 5511 | |
| 5512 | static int nv_close(struct net_device *dev) |
| 5513 | { |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 5514 | struct fe_priv *np = netdev_priv(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5515 | u8 __iomem *base; |
| 5516 | |
| 5517 | spin_lock_irq(&np->lock); |
| 5518 | np->in_shutdown = 1; |
| 5519 | spin_unlock_irq(&np->lock); |
Ayaz Abdulla | 08d9357 | 2009-03-05 08:01:55 +0000 | [diff] [blame] | 5520 | nv_napi_disable(dev); |
Manfred Spraul | a747590 | 2007-10-17 21:52:33 +0200 | [diff] [blame] | 5521 | synchronize_irq(np->pci_dev->irq); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5522 | |
| 5523 | del_timer_sync(&np->oom_kick); |
| 5524 | del_timer_sync(&np->nic_poll); |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 5525 | del_timer_sync(&np->stats_poll); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5526 | |
| 5527 | netif_stop_queue(dev); |
| 5528 | spin_lock_irq(&np->lock); |
david decotigny | 1ff39eb | 2012-08-24 17:22:52 +0000 | [diff] [blame] | 5529 | nv_update_pause(dev, 0); /* otherwise stop_tx bricks NIC */ |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 5530 | nv_stop_rxtx(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5531 | nv_txrx_reset(dev); |
| 5532 | |
| 5533 | /* disable interrupts on the nic or we will lock up */ |
| 5534 | base = get_hwbase(dev); |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 5535 | nv_disable_hw_interrupts(dev, np->irqmask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5536 | pci_push(base); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5537 | |
| 5538 | spin_unlock_irq(&np->lock); |
| 5539 | |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 5540 | nv_free_irq(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5541 | |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 5542 | nv_drain_rxtx(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5543 | |
Ed Swierk | 5a9a8e3 | 2009-06-02 00:19:52 -0700 | [diff] [blame] | 5544 | if (np->wolenabled || !phy_power_down) { |
Ayaz Abdulla | 88d7d8b | 2009-05-01 01:41:50 +0000 | [diff] [blame] | 5545 | nv_txrx_gate(dev, false); |
Tim Mann | 2cc49a5 | 2007-06-14 13:16:38 -0700 | [diff] [blame] | 5546 | writel(NVREG_PFF_ALWAYS|NVREG_PFF_MYADDR, base + NvRegPacketFilterFlags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5547 | nv_start_rx(dev); |
Ed Swierk | cb52deb | 2008-12-01 12:24:43 +0000 | [diff] [blame] | 5548 | } else { |
| 5549 | /* power down phy */ |
| 5550 | mii_rw(dev, np->phyaddr, MII_BMCR, |
| 5551 | mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ)|BMCR_PDOWN); |
Ayaz Abdulla | 88d7d8b | 2009-05-01 01:41:50 +0000 | [diff] [blame] | 5552 | nv_txrx_gate(dev, true); |
Tim Mann | 2cc49a5 | 2007-06-14 13:16:38 -0700 | [diff] [blame] | 5553 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5554 | |
| 5555 | /* FIXME: power down nic */ |
| 5556 | |
| 5557 | return 0; |
| 5558 | } |
| 5559 | |
Stephen Hemminger | b94426b | 2008-11-19 22:26:51 -0800 | [diff] [blame] | 5560 | static const struct net_device_ops nv_netdev_ops = { |
| 5561 | .ndo_open = nv_open, |
| 5562 | .ndo_stop = nv_close, |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 5563 | .ndo_get_stats64 = nv_get_stats64, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 5564 | .ndo_start_xmit = nv_start_xmit, |
| 5565 | .ndo_tx_timeout = nv_tx_timeout, |
| 5566 | .ndo_change_mtu = nv_change_mtu, |
Michał Mirosław | 569e146 | 2011-04-15 04:50:49 +0000 | [diff] [blame] | 5567 | .ndo_fix_features = nv_fix_features, |
| 5568 | .ndo_set_features = nv_set_features, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 5569 | .ndo_validate_addr = eth_validate_addr, |
| 5570 | .ndo_set_mac_address = nv_set_mac_address, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 5571 | .ndo_set_rx_mode = nv_set_multicast, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 5572 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5573 | .ndo_poll_controller = nv_poll_controller, |
| 5574 | #endif |
| 5575 | }; |
| 5576 | |
| 5577 | static const struct net_device_ops nv_netdev_ops_optimized = { |
| 5578 | .ndo_open = nv_open, |
| 5579 | .ndo_stop = nv_close, |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 5580 | .ndo_get_stats64 = nv_get_stats64, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 5581 | .ndo_start_xmit = nv_start_xmit_optimized, |
Stephen Hemminger | b94426b | 2008-11-19 22:26:51 -0800 | [diff] [blame] | 5582 | .ndo_tx_timeout = nv_tx_timeout, |
| 5583 | .ndo_change_mtu = nv_change_mtu, |
Michał Mirosław | 569e146 | 2011-04-15 04:50:49 +0000 | [diff] [blame] | 5584 | .ndo_fix_features = nv_fix_features, |
| 5585 | .ndo_set_features = nv_set_features, |
Stephen Hemminger | b94426b | 2008-11-19 22:26:51 -0800 | [diff] [blame] | 5586 | .ndo_validate_addr = eth_validate_addr, |
| 5587 | .ndo_set_mac_address = nv_set_mac_address, |
Jiri Pirko | afc4b13 | 2011-08-16 06:29:01 +0000 | [diff] [blame] | 5588 | .ndo_set_rx_mode = nv_set_multicast, |
Stephen Hemminger | b94426b | 2008-11-19 22:26:51 -0800 | [diff] [blame] | 5589 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5590 | .ndo_poll_controller = nv_poll_controller, |
| 5591 | #endif |
| 5592 | }; |
| 5593 | |
Bill Pemberton | d05919a | 2012-12-03 09:23:20 -0500 | [diff] [blame] | 5594 | static int nv_probe(struct pci_dev *pci_dev, const struct pci_device_id *id) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5595 | { |
| 5596 | struct net_device *dev; |
| 5597 | struct fe_priv *np; |
| 5598 | unsigned long addr; |
| 5599 | u8 __iomem *base; |
| 5600 | int err, i; |
Ayaz Abdulla | 5070d34 | 2006-07-31 12:05:01 -0400 | [diff] [blame] | 5601 | u32 powerstate, txreg; |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5602 | u32 phystate_orig = 0, phystate; |
| 5603 | int phyinitialized = 0; |
Jeff Garzik | 3f88ce4 | 2007-10-16 04:09:09 -0400 | [diff] [blame] | 5604 | static int printed_version; |
| 5605 | |
| 5606 | if (!printed_version++) |
Joe Perches | 294a554 | 2010-11-29 07:41:56 +0000 | [diff] [blame] | 5607 | pr_info("Reverse Engineered nForce ethernet driver. Version %s.\n", |
| 5608 | FORCEDETH_VERSION); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5609 | |
| 5610 | dev = alloc_etherdev(sizeof(struct fe_priv)); |
| 5611 | err = -ENOMEM; |
| 5612 | if (!dev) |
| 5613 | goto out; |
| 5614 | |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 5615 | np = netdev_priv(dev); |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5616 | np->dev = dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5617 | np->pci_dev = pci_dev; |
| 5618 | spin_lock_init(&np->lock); |
david decotigny | f5d827a | 2011-11-16 12:15:13 +0000 | [diff] [blame] | 5619 | spin_lock_init(&np->hwstats_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5620 | SET_NETDEV_DEV(dev, &pci_dev->dev); |
John Stultz | 827da44 | 2013-10-07 15:51:58 -0700 | [diff] [blame] | 5621 | u64_stats_init(&np->swstats_rx_syncp); |
| 5622 | u64_stats_init(&np->swstats_tx_syncp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5623 | |
| 5624 | init_timer(&np->oom_kick); |
| 5625 | np->oom_kick.data = (unsigned long) dev; |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 5626 | np->oom_kick.function = nv_do_rx_refill; /* timer handler */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5627 | init_timer(&np->nic_poll); |
| 5628 | np->nic_poll.data = (unsigned long) dev; |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 5629 | np->nic_poll.function = nv_do_nic_poll; /* timer handler */ |
david decotigny | 8f5f698 | 2011-11-16 12:15:15 +0000 | [diff] [blame] | 5630 | init_timer_deferrable(&np->stats_poll); |
Ayaz Abdulla | 52da357 | 2006-06-10 22:48:04 -0400 | [diff] [blame] | 5631 | np->stats_poll.data = (unsigned long) dev; |
Joe Perches | c061b18 | 2010-08-23 18:20:03 +0000 | [diff] [blame] | 5632 | np->stats_poll.function = nv_do_stats_poll; /* timer handler */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5633 | |
| 5634 | err = pci_enable_device(pci_dev); |
Jeff Garzik | 3f88ce4 | 2007-10-16 04:09:09 -0400 | [diff] [blame] | 5635 | if (err) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5636 | goto out_free; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5637 | |
| 5638 | pci_set_master(pci_dev); |
| 5639 | |
| 5640 | err = pci_request_regions(pci_dev, DRV_NAME); |
| 5641 | if (err < 0) |
| 5642 | goto out_disable; |
| 5643 | |
Ayaz Abdulla | 9c66243 | 2008-08-06 12:11:42 -0400 | [diff] [blame] | 5644 | if (id->driver_data & (DEV_HAS_VLAN|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS_V2|DEV_HAS_STATISTICS_V3)) |
Ayaz Abdulla | 57fff69 | 2007-01-23 12:27:00 -0500 | [diff] [blame] | 5645 | np->register_size = NV_PCI_REGSZ_VER3; |
| 5646 | else if (id->driver_data & DEV_HAS_STATISTICS_V1) |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 5647 | np->register_size = NV_PCI_REGSZ_VER2; |
| 5648 | else |
| 5649 | np->register_size = NV_PCI_REGSZ_VER1; |
| 5650 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5651 | err = -EINVAL; |
| 5652 | addr = 0; |
| 5653 | for (i = 0; i < DEVICE_COUNT_RESOURCE; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5654 | if (pci_resource_flags(pci_dev, i) & IORESOURCE_MEM && |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 5655 | pci_resource_len(pci_dev, i) >= np->register_size) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5656 | addr = pci_resource_start(pci_dev, i); |
| 5657 | break; |
| 5658 | } |
| 5659 | } |
| 5660 | if (i == DEVICE_COUNT_RESOURCE) { |
Joe Perches | b2ba08e | 2010-11-29 07:42:00 +0000 | [diff] [blame] | 5661 | dev_info(&pci_dev->dev, "Couldn't find register window\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5662 | goto out_relreg; |
| 5663 | } |
| 5664 | |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 5665 | /* copy of driver data */ |
| 5666 | np->driver_data = id->driver_data; |
Ayaz Abdulla | 9f3f791 | 2008-04-23 14:37:30 -0400 | [diff] [blame] | 5667 | /* copy of device id */ |
| 5668 | np->device_id = id->device; |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 5669 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5670 | /* handle different descriptor versions */ |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 5671 | if (id->driver_data & DEV_HAS_HIGH_DMA) { |
| 5672 | /* packet format 3: supports 40-bit addressing */ |
| 5673 | np->desc_ver = DESC_VER_3; |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 5674 | np->txrxctl_bits = NVREG_TXRXCTL_DESC_3; |
Ayaz Abdulla | 69fe3fd | 2006-06-10 22:48:18 -0400 | [diff] [blame] | 5675 | if (dma_64bit) { |
Yang Hongyang | 6afd142 | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5676 | if (pci_set_dma_mask(pci_dev, DMA_BIT_MASK(39))) |
Joe Perches | b2ba08e | 2010-11-29 07:42:00 +0000 | [diff] [blame] | 5677 | dev_info(&pci_dev->dev, |
| 5678 | "64-bit DMA failed, using 32-bit addressing\n"); |
Jeff Garzik | 3f88ce4 | 2007-10-16 04:09:09 -0400 | [diff] [blame] | 5679 | else |
Ayaz Abdulla | 69fe3fd | 2006-06-10 22:48:18 -0400 | [diff] [blame] | 5680 | dev->features |= NETIF_F_HIGHDMA; |
Yang Hongyang | 6afd142 | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5681 | if (pci_set_consistent_dma_mask(pci_dev, DMA_BIT_MASK(39))) { |
Joe Perches | b2ba08e | 2010-11-29 07:42:00 +0000 | [diff] [blame] | 5682 | dev_info(&pci_dev->dev, |
| 5683 | "64-bit DMA (consistent) failed, using 32-bit ring buffers\n"); |
Ayaz Abdulla | 69fe3fd | 2006-06-10 22:48:18 -0400 | [diff] [blame] | 5684 | } |
Ayaz Abdulla | 84b3932 | 2006-05-20 14:59:48 -0700 | [diff] [blame] | 5685 | } |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 5686 | } else if (id->driver_data & DEV_HAS_LARGEDESC) { |
| 5687 | /* packet format 2: supports jumbo frames */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5688 | np->desc_ver = DESC_VER_2; |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 5689 | np->txrxctl_bits = NVREG_TXRXCTL_DESC_2; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 5690 | } else { |
| 5691 | /* original packet format */ |
| 5692 | np->desc_ver = DESC_VER_1; |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 5693 | np->txrxctl_bits = NVREG_TXRXCTL_DESC_1; |
Manfred Spraul | d81c098 | 2005-07-31 18:20:30 +0200 | [diff] [blame] | 5694 | } |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 5695 | |
| 5696 | np->pkt_limit = NV_PKTLIMIT_1; |
| 5697 | if (id->driver_data & DEV_HAS_LARGEDESC) |
| 5698 | np->pkt_limit = NV_PKTLIMIT_2; |
| 5699 | |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 5700 | if (id->driver_data & DEV_HAS_CHECKSUM) { |
| 5701 | np->txrxctl_bits |= NVREG_TXRXCTL_RXCHECK; |
Michał Mirosław | 569e146 | 2011-04-15 04:50:49 +0000 | [diff] [blame] | 5702 | dev->hw_features |= NETIF_F_IP_CSUM | NETIF_F_SG | |
| 5703 | NETIF_F_TSO | NETIF_F_RXCSUM; |
Ayaz Abdulla | 2182816 | 2007-01-23 12:27:21 -0500 | [diff] [blame] | 5704 | } |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 5705 | |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 5706 | np->vlanctl_bits = 0; |
| 5707 | if (id->driver_data & DEV_HAS_VLAN) { |
| 5708 | np->vlanctl_bits = NVREG_VLANCONTROL_ENABLE; |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 5709 | dev->hw_features |= NETIF_F_HW_VLAN_CTAG_RX | |
| 5710 | NETIF_F_HW_VLAN_CTAG_TX; |
Ayaz Abdulla | ee407b0 | 2006-02-04 13:13:17 -0500 | [diff] [blame] | 5711 | } |
| 5712 | |
Jiri Pirko | 0891b0e | 2011-07-26 10:19:28 +0000 | [diff] [blame] | 5713 | dev->features |= dev->hw_features; |
| 5714 | |
Sanjay Hortikar | e19df76 | 2011-11-11 16:11:21 +0000 | [diff] [blame] | 5715 | /* Add loopback capability to the device. */ |
| 5716 | dev->hw_features |= NETIF_F_LOOPBACK; |
| 5717 | |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 5718 | np->pause_flags = NV_PAUSEFRAME_RX_CAPABLE | NV_PAUSEFRAME_RX_REQ | NV_PAUSEFRAME_AUTONEG; |
Ayaz Abdulla | 5289b4c | 2008-02-05 12:30:01 -0500 | [diff] [blame] | 5719 | if ((id->driver_data & DEV_HAS_PAUSEFRAME_TX_V1) || |
| 5720 | (id->driver_data & DEV_HAS_PAUSEFRAME_TX_V2) || |
| 5721 | (id->driver_data & DEV_HAS_PAUSEFRAME_TX_V3)) { |
Ayaz Abdulla | b6d0773 | 2006-06-10 22:47:42 -0400 | [diff] [blame] | 5722 | np->pause_flags |= NV_PAUSEFRAME_TX_CAPABLE | NV_PAUSEFRAME_TX_REQ; |
Ayaz Abdulla | eb91f61 | 2006-05-24 18:13:19 -0400 | [diff] [blame] | 5723 | } |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 5724 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5725 | err = -ENOMEM; |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 5726 | np->base = ioremap(addr, np->register_size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5727 | if (!np->base) |
| 5728 | goto out_relreg; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 5729 | |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 5730 | np->rx_ring_size = RX_RING_DEFAULT; |
| 5731 | np->tx_ring_size = TX_RING_DEFAULT; |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 5732 | |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 5733 | if (!nv_optimized(np)) { |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 5734 | np->rx_ring.orig = pci_alloc_consistent(pci_dev, |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 5735 | sizeof(struct ring_desc) * (np->rx_ring_size + np->tx_ring_size), |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 5736 | &np->ring_addr); |
| 5737 | if (!np->rx_ring.orig) |
| 5738 | goto out_unmap; |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 5739 | np->tx_ring.orig = &np->rx_ring.orig[np->rx_ring_size]; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 5740 | } else { |
| 5741 | np->rx_ring.ex = pci_alloc_consistent(pci_dev, |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 5742 | sizeof(struct ring_desc_ex) * (np->rx_ring_size + np->tx_ring_size), |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 5743 | &np->ring_addr); |
| 5744 | if (!np->rx_ring.ex) |
| 5745 | goto out_unmap; |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 5746 | np->tx_ring.ex = &np->rx_ring.ex[np->rx_ring_size]; |
Manfred Spraul | ee73362 | 2005-07-31 18:32:26 +0200 | [diff] [blame] | 5747 | } |
Yoann Padioleau | dd00cc4 | 2007-07-19 01:49:03 -0700 | [diff] [blame] | 5748 | np->rx_skb = kcalloc(np->rx_ring_size, sizeof(struct nv_skb_map), GFP_KERNEL); |
| 5749 | np->tx_skb = kcalloc(np->tx_ring_size, sizeof(struct nv_skb_map), GFP_KERNEL); |
Ayaz Abdulla | 761fcd9 | 2007-01-09 13:30:07 -0500 | [diff] [blame] | 5750 | if (!np->rx_skb || !np->tx_skb) |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 5751 | goto out_freering; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5752 | |
Jeff Garzik | 36b30ea | 2007-10-16 01:40:30 -0400 | [diff] [blame] | 5753 | if (!nv_optimized(np)) |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 5754 | dev->netdev_ops = &nv_netdev_ops; |
Ayaz Abdulla | 86b22b0 | 2007-01-21 18:10:37 -0500 | [diff] [blame] | 5755 | else |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 5756 | dev->netdev_ops = &nv_netdev_ops_optimized; |
Stephen Hemminger | b94426b | 2008-11-19 22:26:51 -0800 | [diff] [blame] | 5757 | |
Stephen Hemminger | bea3348 | 2007-10-03 16:41:36 -0700 | [diff] [blame] | 5758 | netif_napi_add(dev, &np->napi, nv_napi_poll, RX_WORK_PER_LOOP); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5759 | SET_ETHTOOL_OPS(dev, &ops); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5760 | dev->watchdog_timeo = NV_WATCHDOG_TIMEO; |
| 5761 | |
| 5762 | pci_set_drvdata(pci_dev, dev); |
| 5763 | |
| 5764 | /* read the mac address */ |
| 5765 | base = get_hwbase(dev); |
| 5766 | np->orig_mac[0] = readl(base + NvRegMacAddrA); |
| 5767 | np->orig_mac[1] = readl(base + NvRegMacAddrB); |
| 5768 | |
Ayaz Abdulla | 5070d34 | 2006-07-31 12:05:01 -0400 | [diff] [blame] | 5769 | /* check the workaround bit for correct mac address order */ |
| 5770 | txreg = readl(base + NvRegTransmitPoll); |
Ayaz Abdulla | a376e79 | 2008-04-10 21:30:35 -0700 | [diff] [blame] | 5771 | if (id->driver_data & DEV_HAS_CORRECT_MACADDR) { |
Ayaz Abdulla | 5070d34 | 2006-07-31 12:05:01 -0400 | [diff] [blame] | 5772 | /* mac address is already in correct order */ |
| 5773 | dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff; |
| 5774 | dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff; |
| 5775 | dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff; |
| 5776 | dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff; |
| 5777 | dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff; |
| 5778 | dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff; |
Ayaz Abdulla | a376e79 | 2008-04-10 21:30:35 -0700 | [diff] [blame] | 5779 | } else if (txreg & NVREG_TRANSMITPOLL_MAC_ADDR_REV) { |
| 5780 | /* mac address is already in correct order */ |
| 5781 | dev->dev_addr[0] = (np->orig_mac[0] >> 0) & 0xff; |
| 5782 | dev->dev_addr[1] = (np->orig_mac[0] >> 8) & 0xff; |
| 5783 | dev->dev_addr[2] = (np->orig_mac[0] >> 16) & 0xff; |
| 5784 | dev->dev_addr[3] = (np->orig_mac[0] >> 24) & 0xff; |
| 5785 | dev->dev_addr[4] = (np->orig_mac[1] >> 0) & 0xff; |
| 5786 | dev->dev_addr[5] = (np->orig_mac[1] >> 8) & 0xff; |
| 5787 | /* |
| 5788 | * Set orig mac address back to the reversed version. |
| 5789 | * This flag will be cleared during low power transition. |
| 5790 | * Therefore, we should always put back the reversed address. |
| 5791 | */ |
| 5792 | np->orig_mac[0] = (dev->dev_addr[5] << 0) + (dev->dev_addr[4] << 8) + |
| 5793 | (dev->dev_addr[3] << 16) + (dev->dev_addr[2] << 24); |
| 5794 | np->orig_mac[1] = (dev->dev_addr[1] << 0) + (dev->dev_addr[0] << 8); |
Ayaz Abdulla | 5070d34 | 2006-07-31 12:05:01 -0400 | [diff] [blame] | 5795 | } else { |
| 5796 | /* need to reverse mac address to correct order */ |
| 5797 | dev->dev_addr[0] = (np->orig_mac[1] >> 8) & 0xff; |
| 5798 | dev->dev_addr[1] = (np->orig_mac[1] >> 0) & 0xff; |
| 5799 | dev->dev_addr[2] = (np->orig_mac[0] >> 24) & 0xff; |
| 5800 | dev->dev_addr[3] = (np->orig_mac[0] >> 16) & 0xff; |
| 5801 | dev->dev_addr[4] = (np->orig_mac[0] >> 8) & 0xff; |
| 5802 | dev->dev_addr[5] = (np->orig_mac[0] >> 0) & 0xff; |
Ayaz Abdulla | 5070d34 | 2006-07-31 12:05:01 -0400 | [diff] [blame] | 5803 | writel(txreg|NVREG_TRANSMITPOLL_MAC_ADDR_REV, base + NvRegTransmitPoll); |
Joe Perches | c20ec76 | 2010-11-29 07:42:02 +0000 | [diff] [blame] | 5804 | dev_dbg(&pci_dev->dev, |
| 5805 | "%s: set workaround bit for reversed mac addr\n", |
| 5806 | __func__); |
Ayaz Abdulla | 5070d34 | 2006-07-31 12:05:01 -0400 | [diff] [blame] | 5807 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5808 | |
Jiri Pirko | aaeb6cd | 2013-01-08 01:38:26 +0000 | [diff] [blame] | 5809 | if (!is_valid_ether_addr(dev->dev_addr)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5810 | /* |
| 5811 | * Bad mac address. At least one bios sets the mac address |
| 5812 | * to 01:23:45:67:89:ab |
| 5813 | */ |
Joe Perches | b2ba08e | 2010-11-29 07:42:00 +0000 | [diff] [blame] | 5814 | dev_err(&pci_dev->dev, |
Joe Perches | c20ec76 | 2010-11-29 07:42:02 +0000 | [diff] [blame] | 5815 | "Invalid MAC address detected: %pM - Please complain to your hardware vendor.\n", |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 5816 | dev->dev_addr); |
Danny Kukawka | 7ce5d22 | 2012-02-15 06:45:40 +0000 | [diff] [blame] | 5817 | eth_hw_addr_random(dev); |
Joe Perches | c20ec76 | 2010-11-29 07:42:02 +0000 | [diff] [blame] | 5818 | dev_err(&pci_dev->dev, |
| 5819 | "Using random MAC address: %pM\n", dev->dev_addr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5820 | } |
| 5821 | |
Ayaz Abdulla | f148965 | 2006-07-31 12:04:45 -0400 | [diff] [blame] | 5822 | /* set mac address */ |
| 5823 | nv_copy_mac_to_hw(dev); |
| 5824 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5825 | /* disable WOL */ |
| 5826 | writel(0, base + NvRegWakeUpFlags); |
| 5827 | np->wolenabled = 0; |
Rafael J. Wysocki | dba5a68 | 2011-01-07 11:12:05 +0000 | [diff] [blame] | 5828 | device_set_wakeup_enable(&pci_dev->dev, false); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5829 | |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 5830 | if (id->driver_data & DEV_HAS_POWER_CNTRL) { |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 5831 | |
| 5832 | /* take phy and nic out of low power mode */ |
| 5833 | powerstate = readl(base + NvRegPowerState2); |
| 5834 | powerstate &= ~NVREG_POWERSTATE2_POWERUP_MASK; |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 5835 | if ((id->driver_data & DEV_NEED_LOW_POWER_FIX) && |
Auke Kok | 44c1013 | 2007-06-08 15:46:36 -0700 | [diff] [blame] | 5836 | pci_dev->revision >= 0xA3) |
Ayaz Abdulla | 86a0f04 | 2006-04-24 18:41:31 -0400 | [diff] [blame] | 5837 | powerstate |= NVREG_POWERSTATE2_POWERUP_REV_A3; |
| 5838 | writel(powerstate, base + NvRegPowerState2); |
| 5839 | } |
| 5840 | |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 5841 | if (np->desc_ver == DESC_VER_1) |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 5842 | np->tx_flags = NV_TX_VALID; |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 5843 | else |
Ayaz Abdulla | ac9c189 | 2005-10-26 00:51:24 -0400 | [diff] [blame] | 5844 | np->tx_flags = NV_TX2_VALID; |
Ayaz Abdulla | 9e18476 | 2009-03-05 08:02:18 +0000 | [diff] [blame] | 5845 | |
| 5846 | np->msi_flags = 0; |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 5847 | if ((id->driver_data & DEV_HAS_MSI) && msi) |
Ayaz Abdulla | 9e18476 | 2009-03-05 08:02:18 +0000 | [diff] [blame] | 5848 | np->msi_flags |= NV_MSI_CAPABLE; |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 5849 | |
Ayaz Abdulla | 9e18476 | 2009-03-05 08:02:18 +0000 | [diff] [blame] | 5850 | if ((id->driver_data & DEV_HAS_MSI_X) && msix) { |
| 5851 | /* msix has had reported issues when modifying irqmask |
| 5852 | as in the case of napi, therefore, disable for now |
| 5853 | */ |
David S. Miller | 0a12761 | 2010-05-03 23:33:05 -0700 | [diff] [blame] | 5854 | #if 0 |
Ayaz Abdulla | 9e18476 | 2009-03-05 08:02:18 +0000 | [diff] [blame] | 5855 | np->msi_flags |= NV_MSI_X_CAPABLE; |
| 5856 | #endif |
| 5857 | } |
| 5858 | |
| 5859 | if (optimization_mode == NV_OPTIMIZATION_MODE_CPU) { |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 5860 | np->irqmask = NVREG_IRQMASK_CPU; |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 5861 | if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */ |
| 5862 | np->msi_flags |= 0x0001; |
Ayaz Abdulla | 9e18476 | 2009-03-05 08:02:18 +0000 | [diff] [blame] | 5863 | } else if (optimization_mode == NV_OPTIMIZATION_MODE_DYNAMIC && |
| 5864 | !(id->driver_data & DEV_NEED_TIMERIRQ)) { |
| 5865 | /* start off in throughput mode */ |
| 5866 | np->irqmask = NVREG_IRQMASK_THROUGHPUT; |
| 5867 | /* remove support for msix mode */ |
| 5868 | np->msi_flags &= ~NV_MSI_X_CAPABLE; |
| 5869 | } else { |
| 5870 | optimization_mode = NV_OPTIMIZATION_MODE_THROUGHPUT; |
| 5871 | np->irqmask = NVREG_IRQMASK_THROUGHPUT; |
| 5872 | if (np->msi_flags & NV_MSI_X_CAPABLE) /* set number of vectors */ |
| 5873 | np->msi_flags |= 0x0003; |
Ayaz Abdulla | d33a73c8 | 2006-02-04 13:13:31 -0500 | [diff] [blame] | 5874 | } |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 5875 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5876 | if (id->driver_data & DEV_NEED_TIMERIRQ) |
| 5877 | np->irqmask |= NVREG_IRQ_TIMER; |
| 5878 | if (id->driver_data & DEV_NEED_LINKTIMER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5879 | np->need_linktimer = 1; |
| 5880 | np->link_timeout = jiffies + LINK_TIMEOUT; |
| 5881 | } else { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5882 | np->need_linktimer = 0; |
| 5883 | } |
| 5884 | |
Ayaz Abdulla | 3b446c3 | 2008-03-10 14:58:21 -0500 | [diff] [blame] | 5885 | /* Limit the number of tx's outstanding for hw bug */ |
| 5886 | if (id->driver_data & DEV_NEED_TX_LIMIT) { |
| 5887 | np->tx_limit = 1; |
Ayaz Abdulla | 5c65932 | 2010-04-13 18:49:51 -0700 | [diff] [blame] | 5888 | if (((id->driver_data & DEV_NEED_TX_LIMIT2) == DEV_NEED_TX_LIMIT2) && |
Ayaz Abdulla | 3b446c3 | 2008-03-10 14:58:21 -0500 | [diff] [blame] | 5889 | pci_dev->revision >= 0xA2) |
| 5890 | np->tx_limit = 0; |
| 5891 | } |
| 5892 | |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5893 | /* clear phy state and temporarily halt phy interrupts */ |
| 5894 | writel(0, base + NvRegMIIMask); |
| 5895 | phystate = readl(base + NvRegAdapterControl); |
| 5896 | if (phystate & NVREG_ADAPTCTL_RUNNING) { |
| 5897 | phystate_orig = 1; |
| 5898 | phystate &= ~NVREG_ADAPTCTL_RUNNING; |
| 5899 | writel(phystate, base + NvRegAdapterControl); |
| 5900 | } |
Ayaz Abdulla | eb79842 | 2008-02-04 15:14:04 -0500 | [diff] [blame] | 5901 | writel(NVREG_MIISTAT_MASK_ALL, base + NvRegMIIStatus); |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5902 | |
| 5903 | if (id->driver_data & DEV_HAS_MGMT_UNIT) { |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5904 | /* management unit running on the mac? */ |
Ayaz Abdulla | cac1c52 | 2009-02-07 00:23:57 -0800 | [diff] [blame] | 5905 | if ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_MGMT_ST) && |
| 5906 | (readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_PHY_INIT) && |
| 5907 | nv_mgmt_acquire_sema(dev) && |
| 5908 | nv_mgmt_get_version(dev)) { |
| 5909 | np->mac_in_use = 1; |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 5910 | if (np->mgmt_version > 0) |
Ayaz Abdulla | cac1c52 | 2009-02-07 00:23:57 -0800 | [diff] [blame] | 5911 | np->mac_in_use = readl(base + NvRegMgmtUnitControl) & NVREG_MGMTUNITCONTROL_INUSE; |
Ayaz Abdulla | cac1c52 | 2009-02-07 00:23:57 -0800 | [diff] [blame] | 5912 | /* management unit setup the phy already? */ |
| 5913 | if (np->mac_in_use && |
| 5914 | ((readl(base + NvRegTransmitterControl) & NVREG_XMITCTL_SYNC_MASK) == |
| 5915 | NVREG_XMITCTL_SYNC_PHY_INIT)) { |
| 5916 | /* phy is inited by mgmt unit */ |
| 5917 | phyinitialized = 1; |
Ayaz Abdulla | cac1c52 | 2009-02-07 00:23:57 -0800 | [diff] [blame] | 5918 | } else { |
| 5919 | /* we need to init the phy */ |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5920 | } |
| 5921 | } |
| 5922 | } |
| 5923 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5924 | /* find a suitable phy */ |
Ayaz Abdulla | 7a33e45 | 2005-11-11 08:31:11 -0500 | [diff] [blame] | 5925 | for (i = 1; i <= 32; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5926 | int id1, id2; |
Ayaz Abdulla | 7a33e45 | 2005-11-11 08:31:11 -0500 | [diff] [blame] | 5927 | int phyaddr = i & 0x1F; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5928 | |
| 5929 | spin_lock_irq(&np->lock); |
Ayaz Abdulla | 7a33e45 | 2005-11-11 08:31:11 -0500 | [diff] [blame] | 5930 | id1 = mii_rw(dev, phyaddr, MII_PHYSID1, MII_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5931 | spin_unlock_irq(&np->lock); |
| 5932 | if (id1 < 0 || id1 == 0xffff) |
| 5933 | continue; |
| 5934 | spin_lock_irq(&np->lock); |
Ayaz Abdulla | 7a33e45 | 2005-11-11 08:31:11 -0500 | [diff] [blame] | 5935 | id2 = mii_rw(dev, phyaddr, MII_PHYSID2, MII_READ); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5936 | spin_unlock_irq(&np->lock); |
| 5937 | if (id2 < 0 || id2 == 0xffff) |
| 5938 | continue; |
| 5939 | |
Ayaz Abdulla | edf7e5e | 2006-08-24 15:43:42 -0400 | [diff] [blame] | 5940 | np->phy_model = id2 & PHYID2_MODEL_MASK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5941 | id1 = (id1 & PHYID1_OUI_MASK) << PHYID1_OUI_SHFT; |
| 5942 | id2 = (id2 & PHYID2_OUI_MASK) >> PHYID2_OUI_SHFT; |
Ayaz Abdulla | 7a33e45 | 2005-11-11 08:31:11 -0500 | [diff] [blame] | 5943 | np->phyaddr = phyaddr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5944 | np->phy_oui = id1 | id2; |
Ayaz Abdulla | 9f3f791 | 2008-04-23 14:37:30 -0400 | [diff] [blame] | 5945 | |
| 5946 | /* Realtek hardcoded phy id1 to all zero's on certain phys */ |
| 5947 | if (np->phy_oui == PHY_OUI_REALTEK2) |
| 5948 | np->phy_oui = PHY_OUI_REALTEK; |
| 5949 | /* Setup phy revision for Realtek */ |
| 5950 | if (np->phy_oui == PHY_OUI_REALTEK && np->phy_model == PHY_MODEL_REALTEK_8211) |
| 5951 | np->phy_rev = mii_rw(dev, phyaddr, MII_RESV1, MII_READ) & PHY_REV_MASK; |
| 5952 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5953 | break; |
| 5954 | } |
Ayaz Abdulla | 7a33e45 | 2005-11-11 08:31:11 -0500 | [diff] [blame] | 5955 | if (i == 33) { |
Joe Perches | b2ba08e | 2010-11-29 07:42:00 +0000 | [diff] [blame] | 5956 | dev_info(&pci_dev->dev, "open: Could not find a valid PHY\n"); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 5957 | goto out_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5958 | } |
Jeff Garzik | f3b197a | 2006-05-26 21:39:03 -0400 | [diff] [blame] | 5959 | |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5960 | if (!phyinitialized) { |
| 5961 | /* reset it */ |
| 5962 | phy_init(dev); |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 5963 | } else { |
| 5964 | /* see if it is a gigabit phy */ |
| 5965 | u32 mii_status = mii_rw(dev, np->phyaddr, MII_BMSR, MII_READ); |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 5966 | if (mii_status & PHY_GIGABIT) |
Ayaz Abdulla | f35723e | 2003-02-20 03:03:54 -0500 | [diff] [blame] | 5967 | np->gigabit = PHY_GIGABIT; |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 5968 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5969 | |
| 5970 | /* set default link speed settings */ |
| 5971 | np->linkspeed = NVREG_LINKSPEED_FORCE|NVREG_LINKSPEED_10; |
| 5972 | np->duplex = 0; |
| 5973 | np->autoneg = 1; |
| 5974 | |
| 5975 | err = register_netdev(dev); |
| 5976 | if (err) { |
Joe Perches | b2ba08e | 2010-11-29 07:42:00 +0000 | [diff] [blame] | 5977 | dev_info(&pci_dev->dev, "unable to register netdev: %d\n", err); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 5978 | goto out_error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5979 | } |
Jeff Garzik | 3f88ce4 | 2007-10-16 04:09:09 -0400 | [diff] [blame] | 5980 | |
david decotigny | 3f0a1b5 | 2012-08-24 17:22:53 +0000 | [diff] [blame] | 5981 | netif_carrier_off(dev); |
| 5982 | |
| 5983 | /* Some NICs freeze when TX pause is enabled while NIC is |
| 5984 | * down, and this stays across warm reboots. The sequence |
| 5985 | * below should be enough to recover from that state. |
| 5986 | */ |
| 5987 | nv_update_pause(dev, 0); |
| 5988 | nv_start_tx(dev); |
| 5989 | nv_stop_tx(dev); |
| 5990 | |
David S. Miller | 823dcd2 | 2011-08-20 10:39:12 -0700 | [diff] [blame] | 5991 | if (id->driver_data & DEV_HAS_VLAN) |
| 5992 | nv_vlan_mode(dev, dev->features); |
Jiri Pirko | 0891b0e | 2011-07-26 10:19:28 +0000 | [diff] [blame] | 5993 | |
Joe Perches | b2ba08e | 2010-11-29 07:42:00 +0000 | [diff] [blame] | 5994 | dev_info(&pci_dev->dev, "ifname %s, PHY OUI 0x%x @ %d, addr %pM\n", |
| 5995 | dev->name, np->phy_oui, np->phyaddr, dev->dev_addr); |
Jeff Garzik | 3f88ce4 | 2007-10-16 04:09:09 -0400 | [diff] [blame] | 5996 | |
Sanjay Hortikar | e19df76 | 2011-11-11 16:11:21 +0000 | [diff] [blame] | 5997 | dev_info(&pci_dev->dev, "%s%s%s%s%s%s%s%s%s%s%sdesc-v%u\n", |
Joe Perches | b2ba08e | 2010-11-29 07:42:00 +0000 | [diff] [blame] | 5998 | dev->features & NETIF_F_HIGHDMA ? "highdma " : "", |
| 5999 | dev->features & (NETIF_F_IP_CSUM | NETIF_F_SG) ? |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 6000 | "csum " : "", |
Patrick McHardy | f646968 | 2013-04-19 02:04:27 +0000 | [diff] [blame] | 6001 | dev->features & (NETIF_F_HW_VLAN_CTAG_RX | |
| 6002 | NETIF_F_HW_VLAN_CTAG_TX) ? |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 6003 | "vlan " : "", |
Sanjay Hortikar | e19df76 | 2011-11-11 16:11:21 +0000 | [diff] [blame] | 6004 | dev->features & (NETIF_F_LOOPBACK) ? |
| 6005 | "loopback " : "", |
Joe Perches | b2ba08e | 2010-11-29 07:42:00 +0000 | [diff] [blame] | 6006 | id->driver_data & DEV_HAS_POWER_CNTRL ? "pwrctl " : "", |
| 6007 | id->driver_data & DEV_HAS_MGMT_UNIT ? "mgmt " : "", |
| 6008 | id->driver_data & DEV_NEED_TIMERIRQ ? "timirq " : "", |
| 6009 | np->gigabit == PHY_GIGABIT ? "gbit " : "", |
| 6010 | np->need_linktimer ? "lnktim " : "", |
| 6011 | np->msi_flags & NV_MSI_CAPABLE ? "msi " : "", |
| 6012 | np->msi_flags & NV_MSI_X_CAPABLE ? "msi-x " : "", |
| 6013 | np->desc_ver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6014 | |
| 6015 | return 0; |
| 6016 | |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 6017 | out_error: |
Ayaz Abdulla | 7e680c2 | 2006-10-30 17:31:51 -0500 | [diff] [blame] | 6018 | if (phystate_orig) |
| 6019 | writel(phystate|NVREG_ADAPTCTL_RUNNING, base + NvRegAdapterControl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6020 | pci_set_drvdata(pci_dev, NULL); |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 6021 | out_freering: |
| 6022 | free_rings(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6023 | out_unmap: |
| 6024 | iounmap(get_hwbase(dev)); |
| 6025 | out_relreg: |
| 6026 | pci_release_regions(pci_dev); |
| 6027 | out_disable: |
| 6028 | pci_disable_device(pci_dev); |
| 6029 | out_free: |
| 6030 | free_netdev(dev); |
| 6031 | out: |
| 6032 | return err; |
| 6033 | } |
| 6034 | |
Ayaz Abdulla | 9f3f791 | 2008-04-23 14:37:30 -0400 | [diff] [blame] | 6035 | static void nv_restore_phy(struct net_device *dev) |
| 6036 | { |
| 6037 | struct fe_priv *np = netdev_priv(dev); |
| 6038 | u16 phy_reserved, mii_control; |
| 6039 | |
| 6040 | if (np->phy_oui == PHY_OUI_REALTEK && |
| 6041 | np->phy_model == PHY_MODEL_REALTEK_8201 && |
| 6042 | phy_cross == NV_CROSSOVER_DETECTION_DISABLED) { |
| 6043 | mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT3); |
| 6044 | phy_reserved = mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, MII_READ); |
| 6045 | phy_reserved &= ~PHY_REALTEK_INIT_MSK1; |
| 6046 | phy_reserved |= PHY_REALTEK_INIT8; |
| 6047 | mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG2, phy_reserved); |
| 6048 | mii_rw(dev, np->phyaddr, PHY_REALTEK_INIT_REG1, PHY_REALTEK_INIT1); |
| 6049 | |
| 6050 | /* restart auto negotiation */ |
| 6051 | mii_control = mii_rw(dev, np->phyaddr, MII_BMCR, MII_READ); |
| 6052 | mii_control |= (BMCR_ANRESTART | BMCR_ANENABLE); |
| 6053 | mii_rw(dev, np->phyaddr, MII_BMCR, mii_control); |
| 6054 | } |
| 6055 | } |
| 6056 | |
Yinghai Lu | f55c21f | 2008-09-13 13:10:31 -0700 | [diff] [blame] | 6057 | static void nv_restore_mac_addr(struct pci_dev *pci_dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6058 | { |
| 6059 | struct net_device *dev = pci_get_drvdata(pci_dev); |
Ayaz Abdulla | f148965 | 2006-07-31 12:04:45 -0400 | [diff] [blame] | 6060 | struct fe_priv *np = netdev_priv(dev); |
| 6061 | u8 __iomem *base = get_hwbase(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6062 | |
Ayaz Abdulla | f148965 | 2006-07-31 12:04:45 -0400 | [diff] [blame] | 6063 | /* special op: write back the misordered MAC address - otherwise |
| 6064 | * the next nv_probe would see a wrong address. |
| 6065 | */ |
| 6066 | writel(np->orig_mac[0], base + NvRegMacAddrA); |
| 6067 | writel(np->orig_mac[1], base + NvRegMacAddrB); |
Björn Steinbrink | 2e3884b | 2008-01-07 23:22:53 -0800 | [diff] [blame] | 6068 | writel(readl(base + NvRegTransmitPoll) & ~NVREG_TRANSMITPOLL_MAC_ADDR_REV, |
| 6069 | base + NvRegTransmitPoll); |
Yinghai Lu | f55c21f | 2008-09-13 13:10:31 -0700 | [diff] [blame] | 6070 | } |
| 6071 | |
Bill Pemberton | d05919a | 2012-12-03 09:23:20 -0500 | [diff] [blame] | 6072 | static void nv_remove(struct pci_dev *pci_dev) |
Yinghai Lu | f55c21f | 2008-09-13 13:10:31 -0700 | [diff] [blame] | 6073 | { |
| 6074 | struct net_device *dev = pci_get_drvdata(pci_dev); |
| 6075 | |
| 6076 | unregister_netdev(dev); |
| 6077 | |
| 6078 | nv_restore_mac_addr(pci_dev); |
Ayaz Abdulla | f148965 | 2006-07-31 12:04:45 -0400 | [diff] [blame] | 6079 | |
Ayaz Abdulla | 9f3f791 | 2008-04-23 14:37:30 -0400 | [diff] [blame] | 6080 | /* restore any phy related changes */ |
| 6081 | nv_restore_phy(dev); |
| 6082 | |
Ayaz Abdulla | cac1c52 | 2009-02-07 00:23:57 -0800 | [diff] [blame] | 6083 | nv_mgmt_release_sema(dev); |
| 6084 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6085 | /* free all structures */ |
Ayaz Abdulla | eafa59f | 2006-06-10 22:47:34 -0400 | [diff] [blame] | 6086 | free_rings(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6087 | iounmap(get_hwbase(dev)); |
| 6088 | pci_release_regions(pci_dev); |
| 6089 | pci_disable_device(pci_dev); |
| 6090 | free_netdev(dev); |
| 6091 | pci_set_drvdata(pci_dev, NULL); |
| 6092 | } |
| 6093 | |
Michel Lespinasse | 9425276 | 2011-03-06 16:14:50 +0000 | [diff] [blame] | 6094 | #ifdef CONFIG_PM_SLEEP |
Rafael J. Wysocki | dba5a68 | 2011-01-07 11:12:05 +0000 | [diff] [blame] | 6095 | static int nv_suspend(struct device *device) |
Francois Romieu | a189317 | 2006-10-10 14:33:27 -0700 | [diff] [blame] | 6096 | { |
Rafael J. Wysocki | dba5a68 | 2011-01-07 11:12:05 +0000 | [diff] [blame] | 6097 | struct pci_dev *pdev = to_pci_dev(device); |
Francois Romieu | a189317 | 2006-10-10 14:33:27 -0700 | [diff] [blame] | 6098 | struct net_device *dev = pci_get_drvdata(pdev); |
| 6099 | struct fe_priv *np = netdev_priv(dev); |
Tobias Diedrich | 1a1ca86 | 2008-05-18 15:03:44 +0200 | [diff] [blame] | 6100 | u8 __iomem *base = get_hwbase(dev); |
| 6101 | int i; |
Francois Romieu | a189317 | 2006-10-10 14:33:27 -0700 | [diff] [blame] | 6102 | |
Tobias Diedrich | 25d9081 | 2008-05-18 15:04:29 +0200 | [diff] [blame] | 6103 | if (netif_running(dev)) { |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 6104 | /* Gross. */ |
Tobias Diedrich | 25d9081 | 2008-05-18 15:04:29 +0200 | [diff] [blame] | 6105 | nv_close(dev); |
| 6106 | } |
Francois Romieu | a189317 | 2006-10-10 14:33:27 -0700 | [diff] [blame] | 6107 | netif_device_detach(dev); |
| 6108 | |
Tobias Diedrich | 1a1ca86 | 2008-05-18 15:03:44 +0200 | [diff] [blame] | 6109 | /* save non-pci configuration space */ |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 6110 | for (i = 0; i <= np->register_size/sizeof(u32); i++) |
Tobias Diedrich | 1a1ca86 | 2008-05-18 15:03:44 +0200 | [diff] [blame] | 6111 | np->saved_config_space[i] = readl(base + i*sizeof(u32)); |
| 6112 | |
Francois Romieu | a189317 | 2006-10-10 14:33:27 -0700 | [diff] [blame] | 6113 | return 0; |
| 6114 | } |
| 6115 | |
Rafael J. Wysocki | dba5a68 | 2011-01-07 11:12:05 +0000 | [diff] [blame] | 6116 | static int nv_resume(struct device *device) |
Francois Romieu | a189317 | 2006-10-10 14:33:27 -0700 | [diff] [blame] | 6117 | { |
Rafael J. Wysocki | dba5a68 | 2011-01-07 11:12:05 +0000 | [diff] [blame] | 6118 | struct pci_dev *pdev = to_pci_dev(device); |
Francois Romieu | a189317 | 2006-10-10 14:33:27 -0700 | [diff] [blame] | 6119 | struct net_device *dev = pci_get_drvdata(pdev); |
Tobias Diedrich | 1a1ca86 | 2008-05-18 15:03:44 +0200 | [diff] [blame] | 6120 | struct fe_priv *np = netdev_priv(dev); |
Ayaz Abdulla | a376e79 | 2008-04-10 21:30:35 -0700 | [diff] [blame] | 6121 | u8 __iomem *base = get_hwbase(dev); |
Tobias Diedrich | 1a1ca86 | 2008-05-18 15:03:44 +0200 | [diff] [blame] | 6122 | int i, rc = 0; |
Francois Romieu | a189317 | 2006-10-10 14:33:27 -0700 | [diff] [blame] | 6123 | |
Tobias Diedrich | 1a1ca86 | 2008-05-18 15:03:44 +0200 | [diff] [blame] | 6124 | /* restore non-pci configuration space */ |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 6125 | for (i = 0; i <= np->register_size/sizeof(u32); i++) |
Tobias Diedrich | 1a1ca86 | 2008-05-18 15:03:44 +0200 | [diff] [blame] | 6126 | writel(np->saved_config_space[i], base+i*sizeof(u32)); |
Ayaz Abdulla | a376e79 | 2008-04-10 21:30:35 -0700 | [diff] [blame] | 6127 | |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6128 | if (np->driver_data & DEV_NEED_MSI_FIX) |
| 6129 | pci_write_config_dword(pdev, NV_MSI_PRIV_OFFSET, NV_MSI_PRIV_VALUE); |
Ayaz Abdulla | b6e4405 | 2009-02-07 00:24:15 -0800 | [diff] [blame] | 6130 | |
Ed Swierk | 35a7433 | 2009-04-06 17:49:12 -0700 | [diff] [blame] | 6131 | /* restore phy state, including autoneg */ |
| 6132 | phy_init(dev); |
| 6133 | |
Tobias Diedrich | 25d9081 | 2008-05-18 15:04:29 +0200 | [diff] [blame] | 6134 | netif_device_attach(dev); |
| 6135 | if (netif_running(dev)) { |
| 6136 | rc = nv_open(dev); |
| 6137 | nv_set_multicast(dev); |
| 6138 | } |
Francois Romieu | a189317 | 2006-10-10 14:33:27 -0700 | [diff] [blame] | 6139 | return rc; |
| 6140 | } |
Tobias Diedrich | f735a2a | 2008-05-18 15:02:37 +0200 | [diff] [blame] | 6141 | |
Rafael J. Wysocki | dba5a68 | 2011-01-07 11:12:05 +0000 | [diff] [blame] | 6142 | static SIMPLE_DEV_PM_OPS(nv_pm_ops, nv_suspend, nv_resume); |
| 6143 | #define NV_PM_OPS (&nv_pm_ops) |
| 6144 | |
Michel Lespinasse | 9425276 | 2011-03-06 16:14:50 +0000 | [diff] [blame] | 6145 | #else |
| 6146 | #define NV_PM_OPS NULL |
| 6147 | #endif /* CONFIG_PM_SLEEP */ |
| 6148 | |
| 6149 | #ifdef CONFIG_PM |
Tobias Diedrich | f735a2a | 2008-05-18 15:02:37 +0200 | [diff] [blame] | 6150 | static void nv_shutdown(struct pci_dev *pdev) |
| 6151 | { |
| 6152 | struct net_device *dev = pci_get_drvdata(pdev); |
| 6153 | struct fe_priv *np = netdev_priv(dev); |
| 6154 | |
| 6155 | if (netif_running(dev)) |
| 6156 | nv_close(dev); |
| 6157 | |
Tobias Diedrich | 34edaa8 | 2009-02-16 00:13:20 -0800 | [diff] [blame] | 6158 | /* |
| 6159 | * Restore the MAC so a kernel started by kexec won't get confused. |
| 6160 | * If we really go for poweroff, we must not restore the MAC, |
| 6161 | * otherwise the MAC for WOL will be reversed at least on some boards. |
| 6162 | */ |
Szymon Janc | 78aea4f | 2010-11-27 08:39:43 +0000 | [diff] [blame] | 6163 | if (system_state != SYSTEM_POWER_OFF) |
Tobias Diedrich | 34edaa8 | 2009-02-16 00:13:20 -0800 | [diff] [blame] | 6164 | nv_restore_mac_addr(pdev); |
Yinghai Lu | f55c21f | 2008-09-13 13:10:31 -0700 | [diff] [blame] | 6165 | |
Tobias Diedrich | f735a2a | 2008-05-18 15:02:37 +0200 | [diff] [blame] | 6166 | pci_disable_device(pdev); |
Tobias Diedrich | 34edaa8 | 2009-02-16 00:13:20 -0800 | [diff] [blame] | 6167 | /* |
| 6168 | * Apparently it is not possible to reinitialise from D3 hot, |
| 6169 | * only put the device into D3 if we really go for poweroff. |
| 6170 | */ |
Rafael J. Wysocki | 3cb5599 | 2008-09-05 14:00:19 -0700 | [diff] [blame] | 6171 | if (system_state == SYSTEM_POWER_OFF) { |
Rafael J. Wysocki | dba5a68 | 2011-01-07 11:12:05 +0000 | [diff] [blame] | 6172 | pci_wake_from_d3(pdev, np->wolenabled); |
Rafael J. Wysocki | 3cb5599 | 2008-09-05 14:00:19 -0700 | [diff] [blame] | 6173 | pci_set_power_state(pdev, PCI_D3hot); |
| 6174 | } |
Tobias Diedrich | f735a2a | 2008-05-18 15:02:37 +0200 | [diff] [blame] | 6175 | } |
Francois Romieu | a189317 | 2006-10-10 14:33:27 -0700 | [diff] [blame] | 6176 | #else |
Tobias Diedrich | f735a2a | 2008-05-18 15:02:37 +0200 | [diff] [blame] | 6177 | #define nv_shutdown NULL |
Francois Romieu | a189317 | 2006-10-10 14:33:27 -0700 | [diff] [blame] | 6178 | #endif /* CONFIG_PM */ |
| 6179 | |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 6180 | static DEFINE_PCI_DEVICE_TABLE(pci_tbl) = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6181 | { /* nForce Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6182 | PCI_DEVICE(0x10DE, 0x01C3), |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 6183 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6184 | }, |
| 6185 | { /* nForce2 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6186 | PCI_DEVICE(0x10DE, 0x0066), |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 6187 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6188 | }, |
| 6189 | { /* nForce3 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6190 | PCI_DEVICE(0x10DE, 0x00D6), |
Manfred Spraul | c2dba06 | 2005-07-31 18:29:47 +0200 | [diff] [blame] | 6191 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6192 | }, |
| 6193 | { /* nForce3 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6194 | PCI_DEVICE(0x10DE, 0x0086), |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 6195 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6196 | }, |
| 6197 | { /* nForce3 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6198 | PCI_DEVICE(0x10DE, 0x008C), |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 6199 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6200 | }, |
| 6201 | { /* nForce3 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6202 | PCI_DEVICE(0x10DE, 0x00E6), |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 6203 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6204 | }, |
| 6205 | { /* nForce3 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6206 | PCI_DEVICE(0x10DE, 0x00DF), |
Manfred Spraul | 8a4ae7f | 2005-09-21 23:22:10 -0400 | [diff] [blame] | 6207 | .driver_data = DEV_NEED_TIMERIRQ|DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6208 | }, |
| 6209 | { /* CK804 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6210 | PCI_DEVICE(0x10DE, 0x0056), |
Yinghai Lu | 033e97b | 2009-02-06 01:30:56 -0800 | [diff] [blame] | 6211 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6212 | }, |
| 6213 | { /* CK804 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6214 | PCI_DEVICE(0x10DE, 0x0057), |
Yinghai Lu | 033e97b | 2009-02-06 01:30:56 -0800 | [diff] [blame] | 6215 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6216 | }, |
| 6217 | { /* MCP04 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6218 | PCI_DEVICE(0x10DE, 0x0037), |
Ayaz Abdulla | 9e18476 | 2009-03-05 08:02:18 +0000 | [diff] [blame] | 6219 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6220 | }, |
| 6221 | { /* MCP04 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6222 | PCI_DEVICE(0x10DE, 0x0038), |
Ayaz Abdulla | 9e18476 | 2009-03-05 08:02:18 +0000 | [diff] [blame] | 6223 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_STATISTICS_V1|DEV_NEED_TX_LIMIT, |
Manfred Spraul | dc8216c | 2005-07-31 18:26:05 +0200 | [diff] [blame] | 6224 | }, |
| 6225 | { /* MCP51 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6226 | PCI_DEVICE(0x10DE, 0x0268), |
| 6227 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS_V1|DEV_NEED_LOW_POWER_FIX, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6228 | }, |
Manfred Spraul | 9992d4a | 2005-06-05 17:36:11 +0200 | [diff] [blame] | 6229 | { /* MCP51 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6230 | PCI_DEVICE(0x10DE, 0x0269), |
| 6231 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_STATISTICS_V1|DEV_NEED_LOW_POWER_FIX, |
Manfred Spraul | 9992d4a | 2005-06-05 17:36:11 +0200 | [diff] [blame] | 6232 | }, |
Manfred Spraul | f49d16e | 2005-06-26 11:36:52 +0200 | [diff] [blame] | 6233 | { /* MCP55 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6234 | PCI_DEVICE(0x10DE, 0x0372), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6235 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_VLAN|DEV_HAS_MSI|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_NEED_TX_LIMIT|DEV_NEED_MSI_FIX, |
Manfred Spraul | f49d16e | 2005-06-26 11:36:52 +0200 | [diff] [blame] | 6236 | }, |
| 6237 | { /* MCP55 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6238 | PCI_DEVICE(0x10DE, 0x0373), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6239 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_VLAN|DEV_HAS_MSI|DEV_HAS_MSI_X|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_NEED_TX_LIMIT|DEV_NEED_MSI_FIX, |
Manfred Spraul | f49d16e | 2005-06-26 11:36:52 +0200 | [diff] [blame] | 6240 | }, |
Ayaz Abdulla | c99ce7e | 2006-06-10 22:48:28 -0400 | [diff] [blame] | 6241 | { /* MCP61 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6242 | PCI_DEVICE(0x10DE, 0x03E5), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6243 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | c99ce7e | 2006-06-10 22:48:28 -0400 | [diff] [blame] | 6244 | }, |
| 6245 | { /* MCP61 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6246 | PCI_DEVICE(0x10DE, 0x03E6), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6247 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | c99ce7e | 2006-06-10 22:48:28 -0400 | [diff] [blame] | 6248 | }, |
| 6249 | { /* MCP61 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6250 | PCI_DEVICE(0x10DE, 0x03EE), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6251 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | c99ce7e | 2006-06-10 22:48:28 -0400 | [diff] [blame] | 6252 | }, |
| 6253 | { /* MCP61 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6254 | PCI_DEVICE(0x10DE, 0x03EF), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6255 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | c99ce7e | 2006-06-10 22:48:28 -0400 | [diff] [blame] | 6256 | }, |
| 6257 | { /* MCP65 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6258 | PCI_DEVICE(0x10DE, 0x0450), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6259 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | c99ce7e | 2006-06-10 22:48:28 -0400 | [diff] [blame] | 6260 | }, |
| 6261 | { /* MCP65 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6262 | PCI_DEVICE(0x10DE, 0x0451), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6263 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | c99ce7e | 2006-06-10 22:48:28 -0400 | [diff] [blame] | 6264 | }, |
| 6265 | { /* MCP65 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6266 | PCI_DEVICE(0x10DE, 0x0452), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6267 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | c99ce7e | 2006-06-10 22:48:28 -0400 | [diff] [blame] | 6268 | }, |
| 6269 | { /* MCP65 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6270 | PCI_DEVICE(0x10DE, 0x0453), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6271 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_NEED_TX_LIMIT|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | c99ce7e | 2006-06-10 22:48:28 -0400 | [diff] [blame] | 6272 | }, |
Ayaz Abdulla | f434484 | 2006-11-06 00:43:40 -0800 | [diff] [blame] | 6273 | { /* MCP67 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6274 | PCI_DEVICE(0x10DE, 0x054C), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6275 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | f434484 | 2006-11-06 00:43:40 -0800 | [diff] [blame] | 6276 | }, |
| 6277 | { /* MCP67 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6278 | PCI_DEVICE(0x10DE, 0x054D), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6279 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | f434484 | 2006-11-06 00:43:40 -0800 | [diff] [blame] | 6280 | }, |
| 6281 | { /* MCP67 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6282 | PCI_DEVICE(0x10DE, 0x054E), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6283 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | f434484 | 2006-11-06 00:43:40 -0800 | [diff] [blame] | 6284 | }, |
| 6285 | { /* MCP67 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6286 | PCI_DEVICE(0x10DE, 0x054F), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6287 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | f434484 | 2006-11-06 00:43:40 -0800 | [diff] [blame] | 6288 | }, |
Ayaz Abdulla | 1398661 | 2007-07-22 20:43:26 -0400 | [diff] [blame] | 6289 | { /* MCP73 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6290 | PCI_DEVICE(0x10DE, 0x07DC), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6291 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | 1398661 | 2007-07-22 20:43:26 -0400 | [diff] [blame] | 6292 | }, |
| 6293 | { /* MCP73 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6294 | PCI_DEVICE(0x10DE, 0x07DD), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6295 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | 1398661 | 2007-07-22 20:43:26 -0400 | [diff] [blame] | 6296 | }, |
| 6297 | { /* MCP73 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6298 | PCI_DEVICE(0x10DE, 0x07DE), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6299 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | 1398661 | 2007-07-22 20:43:26 -0400 | [diff] [blame] | 6300 | }, |
| 6301 | { /* MCP73 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6302 | PCI_DEVICE(0x10DE, 0x07DF), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6303 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_HIGH_DMA|DEV_HAS_POWER_CNTRL|DEV_HAS_MSI|DEV_HAS_PAUSEFRAME_TX_V1|DEV_HAS_STATISTICS_V12|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | 1398661 | 2007-07-22 20:43:26 -0400 | [diff] [blame] | 6304 | }, |
Ayaz Abdulla | 96fd4cd | 2007-10-25 03:36:42 -0400 | [diff] [blame] | 6305 | { /* MCP77 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6306 | PCI_DEVICE(0x10DE, 0x0760), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6307 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | 96fd4cd | 2007-10-25 03:36:42 -0400 | [diff] [blame] | 6308 | }, |
| 6309 | { /* MCP77 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6310 | PCI_DEVICE(0x10DE, 0x0761), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6311 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | 96fd4cd | 2007-10-25 03:36:42 -0400 | [diff] [blame] | 6312 | }, |
| 6313 | { /* MCP77 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6314 | PCI_DEVICE(0x10DE, 0x0762), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6315 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | 96fd4cd | 2007-10-25 03:36:42 -0400 | [diff] [blame] | 6316 | }, |
| 6317 | { /* MCP77 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6318 | PCI_DEVICE(0x10DE, 0x0763), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6319 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V2|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_MGMT_UNIT|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | 96fd4cd | 2007-10-25 03:36:42 -0400 | [diff] [blame] | 6320 | }, |
Ayaz Abdulla | 490dde8 | 2007-11-23 20:54:01 -0500 | [diff] [blame] | 6321 | { /* MCP79 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6322 | PCI_DEVICE(0x10DE, 0x0AB0), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6323 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | 490dde8 | 2007-11-23 20:54:01 -0500 | [diff] [blame] | 6324 | }, |
| 6325 | { /* MCP79 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6326 | PCI_DEVICE(0x10DE, 0x0AB1), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6327 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | 490dde8 | 2007-11-23 20:54:01 -0500 | [diff] [blame] | 6328 | }, |
| 6329 | { /* MCP79 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6330 | PCI_DEVICE(0x10DE, 0x0AB2), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6331 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | 490dde8 | 2007-11-23 20:54:01 -0500 | [diff] [blame] | 6332 | }, |
| 6333 | { /* MCP79 Ethernet Controller */ |
Ayaz Abdulla | 3c2e1c1 | 2009-06-03 15:05:17 +0000 | [diff] [blame] | 6334 | PCI_DEVICE(0x10DE, 0x0AB3), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6335 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_NEED_TX_LIMIT2|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX|DEV_NEED_MSI_FIX, |
Ayaz Abdulla | 490dde8 | 2007-11-23 20:54:01 -0500 | [diff] [blame] | 6336 | }, |
Ayaz Abdulla | 3df81c4 | 2009-06-03 15:05:35 +0000 | [diff] [blame] | 6337 | { /* MCP89 Ethernet Controller */ |
| 6338 | PCI_DEVICE(0x10DE, 0x0D7D), |
Mike Ditto | 7b5e078 | 2010-07-25 21:54:28 -0700 | [diff] [blame] | 6339 | .driver_data = DEV_NEED_LINKTIMER|DEV_HAS_LARGEDESC|DEV_HAS_CHECKSUM|DEV_HAS_HIGH_DMA|DEV_HAS_MSI|DEV_HAS_POWER_CNTRL|DEV_HAS_PAUSEFRAME_TX_V3|DEV_HAS_STATISTICS_V123|DEV_HAS_TEST_EXTENDED|DEV_HAS_CORRECT_MACADDR|DEV_HAS_COLLISION_FIX|DEV_HAS_GEAR_MODE|DEV_NEED_PHY_INIT_FIX, |
Ayaz Abdulla | 3df81c4 | 2009-06-03 15:05:35 +0000 | [diff] [blame] | 6340 | }, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6341 | {0,}, |
| 6342 | }; |
| 6343 | |
Peter Hüwe | 4f45c40 | 2013-05-21 13:42:56 +0000 | [diff] [blame] | 6344 | static struct pci_driver forcedeth_pci_driver = { |
Jeff Garzik | 3f88ce4 | 2007-10-16 04:09:09 -0400 | [diff] [blame] | 6345 | .name = DRV_NAME, |
| 6346 | .id_table = pci_tbl, |
| 6347 | .probe = nv_probe, |
Bill Pemberton | d05919a | 2012-12-03 09:23:20 -0500 | [diff] [blame] | 6348 | .remove = nv_remove, |
Tobias Diedrich | f735a2a | 2008-05-18 15:02:37 +0200 | [diff] [blame] | 6349 | .shutdown = nv_shutdown, |
Rafael J. Wysocki | dba5a68 | 2011-01-07 11:12:05 +0000 | [diff] [blame] | 6350 | .driver.pm = NV_PM_OPS, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6351 | }; |
| 6352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6353 | module_param(max_interrupt_work, int, 0); |
| 6354 | MODULE_PARM_DESC(max_interrupt_work, "forcedeth maximum events handled per interrupt"); |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 6355 | module_param(optimization_mode, int, 0); |
Ayaz Abdulla | 9e18476 | 2009-03-05 08:02:18 +0000 | [diff] [blame] | 6356 | 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."); |
Ayaz Abdulla | a971c32 | 2005-11-11 08:30:38 -0500 | [diff] [blame] | 6357 | module_param(poll_interval, int, 0); |
| 6358 | 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."); |
Ayaz Abdulla | 69fe3fd | 2006-06-10 22:48:18 -0400 | [diff] [blame] | 6359 | module_param(msi, int, 0); |
| 6360 | MODULE_PARM_DESC(msi, "MSI interrupts are enabled by setting to 1 and disabled by setting to 0."); |
| 6361 | module_param(msix, int, 0); |
| 6362 | MODULE_PARM_DESC(msix, "MSIX interrupts are enabled by setting to 1 and disabled by setting to 0."); |
| 6363 | module_param(dma_64bit, int, 0); |
| 6364 | MODULE_PARM_DESC(dma_64bit, "High DMA is enabled by setting to 1 and disabled by setting to 0."); |
Ayaz Abdulla | 9f3f791 | 2008-04-23 14:37:30 -0400 | [diff] [blame] | 6365 | module_param(phy_cross, int, 0); |
| 6366 | MODULE_PARM_DESC(phy_cross, "Phy crossover detection for Realtek 8201 phy is enabled by setting to 1 and disabled by setting to 0."); |
Ed Swierk | 5a9a8e3 | 2009-06-02 00:19:52 -0700 | [diff] [blame] | 6367 | module_param(phy_power_down, int, 0); |
| 6368 | MODULE_PARM_DESC(phy_power_down, "Power down phy and disable link when interface is down (1), or leave phy powered up (0)."); |
Sameer Nanda | 1ec4f2d | 2011-11-16 12:15:12 +0000 | [diff] [blame] | 6369 | module_param(debug_tx_timeout, bool, 0); |
| 6370 | MODULE_PARM_DESC(debug_tx_timeout, |
| 6371 | "Dump tx related registers and ring when tx_timeout happens"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6372 | |
Peter Hüwe | 4f45c40 | 2013-05-21 13:42:56 +0000 | [diff] [blame] | 6373 | module_pci_driver(forcedeth_pci_driver); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6374 | MODULE_AUTHOR("Manfred Spraul <manfred@colorfullife.com>"); |
| 6375 | MODULE_DESCRIPTION("Reverse Engineered nForce ethernet driver"); |
| 6376 | MODULE_LICENSE("GPL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 6377 | MODULE_DEVICE_TABLE(pci, pci_tbl); |