Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Shannon Nelson | 8c47eaa | 2010-01-13 01:49:34 +0000 | [diff] [blame] | 4 | Copyright(c) 1999 - 2010 Intel Corporation. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify it |
| 7 | under the terms and conditions of the GNU General Public License, |
| 8 | version 2, as published by the Free Software Foundation. |
| 9 | |
| 10 | This program is distributed in the hope it will be useful, but WITHOUT |
| 11 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 12 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 13 | more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License along with |
| 16 | this program; if not, write to the Free Software Foundation, Inc., |
| 17 | 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA. |
| 18 | |
| 19 | The full GNU General Public License is included in this distribution in |
| 20 | the file called "COPYING". |
| 21 | |
| 22 | Contact Information: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 23 | e1000-devel Mailing List <e1000-devel@lists.sourceforge.net> |
| 24 | Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 25 | |
| 26 | *******************************************************************************/ |
| 27 | |
| 28 | #include <linux/types.h> |
| 29 | #include <linux/module.h> |
| 30 | #include <linux/pci.h> |
| 31 | #include <linux/netdevice.h> |
| 32 | #include <linux/vmalloc.h> |
| 33 | #include <linux/string.h> |
| 34 | #include <linux/in.h> |
| 35 | #include <linux/ip.h> |
| 36 | #include <linux/tcp.h> |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 37 | #include <linux/pkt_sched.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 38 | #include <linux/ipv6.h> |
| 39 | #include <net/checksum.h> |
| 40 | #include <net/ip6_checksum.h> |
| 41 | #include <linux/ethtool.h> |
| 42 | #include <linux/if_vlan.h> |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 43 | #include <scsi/fc/fc_fcoe.h> |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 44 | |
| 45 | #include "ixgbe.h" |
| 46 | #include "ixgbe_common.h" |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 47 | #include "ixgbe_dcb_82599.h" |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 48 | #include "ixgbe_sriov.h" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 49 | |
| 50 | char ixgbe_driver_name[] = "ixgbe"; |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 51 | static const char ixgbe_driver_string[] = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 52 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 53 | |
Peter Waskiewicz | 92eb879 | 2010-02-10 16:08:13 +0000 | [diff] [blame] | 54 | #define DRV_VERSION "2.0.62-k2" |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 55 | const char ixgbe_driver_version[] = DRV_VERSION; |
Shannon Nelson | 8c47eaa | 2010-01-13 01:49:34 +0000 | [diff] [blame] | 56 | static char ixgbe_copyright[] = "Copyright (c) 1999-2010 Intel Corporation."; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 57 | |
| 58 | static const struct ixgbe_info *ixgbe_info_tbl[] = { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 59 | [board_82598] = &ixgbe_82598_info, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 60 | [board_82599] = &ixgbe_82599_info, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 61 | }; |
| 62 | |
| 63 | /* ixgbe_pci_tbl - PCI Device ID Table |
| 64 | * |
| 65 | * Wildcard entries (PCI_ANY_ID) should come last |
| 66 | * Last entry must be all 0s |
| 67 | * |
| 68 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 69 | * Class, Class Mask, private data (not used) } |
| 70 | */ |
Alexey Dobriyan | a3aa188 | 2010-01-07 11:58:11 +0000 | [diff] [blame] | 71 | static DEFINE_PCI_DEVICE_TABLE(ixgbe_pci_tbl) = { |
Don Skidmore | 1e336d0 | 2009-01-26 20:57:51 -0800 | [diff] [blame] | 72 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), |
| 73 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 74 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 75 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 76 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 77 | board_82598 }, |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 78 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), |
| 79 | board_82598 }, |
Peter P Waskiewicz Jr | 3845bec | 2009-07-16 15:50:52 +0000 | [diff] [blame] | 80 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), |
| 81 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 82 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 83 | board_82598 }, |
Jesse Brandeburg | 8d792cd | 2008-08-08 16:24:19 -0700 | [diff] [blame] | 84 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), |
| 85 | board_82598 }, |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 86 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), |
| 87 | board_82598 }, |
| 88 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), |
| 89 | board_82598 }, |
Jesse Brandeburg | b95f5fc | 2008-09-11 19:58:59 -0700 | [diff] [blame] | 90 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), |
| 91 | board_82598 }, |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 92 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), |
| 93 | board_82598 }, |
Don Skidmore | 2f21bdd | 2009-02-01 01:18:23 -0800 | [diff] [blame] | 94 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), |
| 95 | board_82598 }, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 96 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), |
| 97 | board_82599 }, |
Peter P Waskiewicz Jr | 1fcf03e | 2009-05-17 20:58:04 +0000 | [diff] [blame] | 98 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), |
| 99 | board_82599 }, |
Don Skidmore | 74757d4 | 2009-12-08 07:22:23 +0000 | [diff] [blame] | 100 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), |
| 101 | board_82599 }, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 102 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), |
| 103 | board_82599 }, |
Don Skidmore | 38ad1c8 | 2009-10-08 15:35:58 +0000 | [diff] [blame] | 104 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), |
| 105 | board_82599 }, |
Don Skidmore | dbfec66 | 2009-10-02 08:58:25 +0000 | [diff] [blame] | 106 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), |
| 107 | board_82599 }, |
Peter P Waskiewicz Jr | 8911184 | 2009-09-14 07:47:49 +0000 | [diff] [blame] | 108 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), |
| 109 | board_82599 }, |
Don Skidmore | 312eb93 | 2009-10-02 08:58:04 +0000 | [diff] [blame] | 110 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), |
| 111 | board_82599 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 112 | |
| 113 | /* required last entry */ |
| 114 | {0, } |
| 115 | }; |
| 116 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 117 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 118 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 119 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 120 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 121 | static struct notifier_block dca_notifier = { |
| 122 | .notifier_call = ixgbe_notify_dca, |
| 123 | .next = NULL, |
| 124 | .priority = 0 |
| 125 | }; |
| 126 | #endif |
| 127 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 128 | #ifdef CONFIG_PCI_IOV |
| 129 | static unsigned int max_vfs; |
| 130 | module_param(max_vfs, uint, 0); |
| 131 | MODULE_PARM_DESC(max_vfs, "Maximum number of virtual functions to allocate " |
| 132 | "per physical function"); |
| 133 | #endif /* CONFIG_PCI_IOV */ |
| 134 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 135 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 136 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 137 | MODULE_LICENSE("GPL"); |
| 138 | MODULE_VERSION(DRV_VERSION); |
| 139 | |
| 140 | #define DEFAULT_DEBUG_LEVEL_SHIFT 3 |
| 141 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 142 | static inline void ixgbe_disable_sriov(struct ixgbe_adapter *adapter) |
| 143 | { |
| 144 | struct ixgbe_hw *hw = &adapter->hw; |
| 145 | u32 gcr; |
| 146 | u32 gpie; |
| 147 | u32 vmdctl; |
| 148 | |
| 149 | #ifdef CONFIG_PCI_IOV |
| 150 | /* disable iov and allow time for transactions to clear */ |
| 151 | pci_disable_sriov(adapter->pdev); |
| 152 | #endif |
| 153 | |
| 154 | /* turn off device IOV mode */ |
| 155 | gcr = IXGBE_READ_REG(hw, IXGBE_GCR_EXT); |
| 156 | gcr &= ~(IXGBE_GCR_EXT_SRIOV); |
| 157 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, gcr); |
| 158 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 159 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
| 160 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 161 | |
| 162 | /* set default pool back to 0 */ |
| 163 | vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
| 164 | vmdctl &= ~IXGBE_VT_CTL_POOL_MASK; |
| 165 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl); |
| 166 | |
| 167 | /* take a breather then clean up driver data */ |
| 168 | msleep(100); |
| 169 | if (adapter->vfinfo) |
| 170 | kfree(adapter->vfinfo); |
| 171 | adapter->vfinfo = NULL; |
| 172 | |
| 173 | adapter->num_vfs = 0; |
| 174 | adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED; |
| 175 | } |
| 176 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 177 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 178 | { |
| 179 | u32 ctrl_ext; |
| 180 | |
| 181 | /* Let firmware take over control of h/w */ |
| 182 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 183 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 184 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 188 | { |
| 189 | u32 ctrl_ext; |
| 190 | |
| 191 | /* Let firmware know the driver has taken over */ |
| 192 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 193 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 194 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 195 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 196 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 197 | /* |
| 198 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 199 | * @adapter: pointer to adapter struct |
| 200 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 201 | * @queue: queue to map the corresponding interrupt to |
| 202 | * @msix_vector: the vector to map to the corresponding queue |
| 203 | * |
| 204 | */ |
| 205 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
| 206 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 207 | { |
| 208 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 209 | struct ixgbe_hw *hw = &adapter->hw; |
| 210 | switch (hw->mac.type) { |
| 211 | case ixgbe_mac_82598EB: |
| 212 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 213 | if (direction == -1) |
| 214 | direction = 0; |
| 215 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 216 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 217 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 218 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 219 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 220 | break; |
| 221 | case ixgbe_mac_82599EB: |
| 222 | if (direction == -1) { |
| 223 | /* other causes */ |
| 224 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 225 | index = ((queue & 1) * 8); |
| 226 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 227 | ivar &= ~(0xFF << index); |
| 228 | ivar |= (msix_vector << index); |
| 229 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 230 | break; |
| 231 | } else { |
| 232 | /* tx or rx causes */ |
| 233 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 234 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 235 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 236 | ivar &= ~(0xFF << index); |
| 237 | ivar |= (msix_vector << index); |
| 238 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 239 | break; |
| 240 | } |
| 241 | default: |
| 242 | break; |
| 243 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 244 | } |
| 245 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 246 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
| 247 | u64 qmask) |
| 248 | { |
| 249 | u32 mask; |
| 250 | |
| 251 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 252 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 253 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
| 254 | } else { |
| 255 | mask = (qmask & 0xFFFFFFFF); |
| 256 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 257 | mask = (qmask >> 32); |
| 258 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
| 259 | } |
| 260 | } |
| 261 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 262 | static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 263 | struct ixgbe_tx_buffer |
| 264 | *tx_buffer_info) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 265 | { |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 266 | if (tx_buffer_info->dma) { |
| 267 | if (tx_buffer_info->mapped_as_page) |
| 268 | pci_unmap_page(adapter->pdev, |
| 269 | tx_buffer_info->dma, |
| 270 | tx_buffer_info->length, |
| 271 | PCI_DMA_TODEVICE); |
| 272 | else |
| 273 | pci_unmap_single(adapter->pdev, |
| 274 | tx_buffer_info->dma, |
| 275 | tx_buffer_info->length, |
| 276 | PCI_DMA_TODEVICE); |
| 277 | tx_buffer_info->dma = 0; |
| 278 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 279 | if (tx_buffer_info->skb) { |
| 280 | dev_kfree_skb_any(tx_buffer_info->skb); |
| 281 | tx_buffer_info->skb = NULL; |
| 282 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 283 | tx_buffer_info->time_stamp = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 284 | /* tx_buffer_info must be completely set up in the transmit path */ |
| 285 | } |
| 286 | |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 287 | /** |
| 288 | * ixgbe_tx_is_paused - check if the tx ring is paused |
| 289 | * @adapter: the ixgbe adapter |
| 290 | * @tx_ring: the corresponding tx_ring |
| 291 | * |
| 292 | * If not in DCB mode, checks TFCS.TXOFF, otherwise, find out the |
| 293 | * corresponding TC of this tx_ring when checking TFCS. |
| 294 | * |
| 295 | * Returns : true if paused |
| 296 | */ |
| 297 | static inline bool ixgbe_tx_is_paused(struct ixgbe_adapter *adapter, |
| 298 | struct ixgbe_ring *tx_ring) |
| 299 | { |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 300 | u32 txoff = IXGBE_TFCS_TXOFF; |
| 301 | |
| 302 | #ifdef CONFIG_IXGBE_DCB |
| 303 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Jaswinder Singh Rajput | 30b76832 | 2009-11-20 04:02:27 +0000 | [diff] [blame] | 304 | int tc; |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 305 | int reg_idx = tx_ring->reg_idx; |
| 306 | int dcb_i = adapter->ring_feature[RING_F_DCB].indices; |
| 307 | |
PJ Waskiewicz | 6837e89 | 2010-01-06 17:50:29 +0000 | [diff] [blame] | 308 | switch (adapter->hw.mac.type) { |
| 309 | case ixgbe_mac_82598EB: |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 310 | tc = reg_idx >> 2; |
| 311 | txoff = IXGBE_TFCS_TXOFF0; |
PJ Waskiewicz | 6837e89 | 2010-01-06 17:50:29 +0000 | [diff] [blame] | 312 | break; |
| 313 | case ixgbe_mac_82599EB: |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 314 | tc = 0; |
| 315 | txoff = IXGBE_TFCS_TXOFF; |
| 316 | if (dcb_i == 8) { |
| 317 | /* TC0, TC1 */ |
| 318 | tc = reg_idx >> 5; |
| 319 | if (tc == 2) /* TC2, TC3 */ |
| 320 | tc += (reg_idx - 64) >> 4; |
| 321 | else if (tc == 3) /* TC4, TC5, TC6, TC7 */ |
| 322 | tc += 1 + ((reg_idx - 96) >> 3); |
| 323 | } else if (dcb_i == 4) { |
| 324 | /* TC0, TC1 */ |
| 325 | tc = reg_idx >> 6; |
| 326 | if (tc == 1) { |
| 327 | tc += (reg_idx - 64) >> 5; |
| 328 | if (tc == 2) /* TC2, TC3 */ |
| 329 | tc += (reg_idx - 96) >> 4; |
| 330 | } |
| 331 | } |
PJ Waskiewicz | 6837e89 | 2010-01-06 17:50:29 +0000 | [diff] [blame] | 332 | break; |
| 333 | default: |
| 334 | tc = 0; |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 335 | } |
| 336 | txoff <<= tc; |
| 337 | } |
| 338 | #endif |
| 339 | return IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & txoff; |
| 340 | } |
| 341 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 342 | static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 343 | struct ixgbe_ring *tx_ring, |
| 344 | unsigned int eop) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 345 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 346 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 347 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 348 | /* Detect a transmit hang in hardware, this serializes the |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 349 | * check with the clearing of time_stamp and movement of eop */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 350 | adapter->detect_tx_hung = false; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 351 | if (tx_ring->tx_buffer_info[eop].time_stamp && |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 352 | time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) && |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 353 | !ixgbe_tx_is_paused(adapter, tx_ring)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 354 | /* detected Tx unit hang */ |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 355 | union ixgbe_adv_tx_desc *tx_desc; |
| 356 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 357 | DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n" |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 358 | " Tx Queue <%d>\n" |
| 359 | " TDH, TDT <%x>, <%x>\n" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 360 | " next_to_use <%x>\n" |
| 361 | " next_to_clean <%x>\n" |
| 362 | "tx_buffer_info[next_to_clean]\n" |
| 363 | " time_stamp <%lx>\n" |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 364 | " jiffies <%lx>\n", |
| 365 | tx_ring->queue_index, |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 366 | IXGBE_READ_REG(hw, tx_ring->head), |
| 367 | IXGBE_READ_REG(hw, tx_ring->tail), |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 368 | tx_ring->next_to_use, eop, |
| 369 | tx_ring->tx_buffer_info[eop].time_stamp, jiffies); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 370 | return true; |
| 371 | } |
| 372 | |
| 373 | return false; |
| 374 | } |
| 375 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 376 | #define IXGBE_MAX_TXD_PWR 14 |
| 377 | #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 378 | |
| 379 | /* Tx Descriptors needed, worst case */ |
| 380 | #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \ |
| 381 | (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0)) |
| 382 | #define DESC_NEEDED (TXD_USE_COUNT(IXGBE_MAX_DATA_PER_TXD) /* skb->data */ + \ |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 383 | MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 384 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 385 | static void ixgbe_tx_timeout(struct net_device *netdev); |
| 386 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 387 | /** |
| 388 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 389 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 390 | * @tx_ring: tx ring to clean |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 391 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 392 | static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 393 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 394 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 395 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 396 | struct net_device *netdev = adapter->netdev; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 397 | union ixgbe_adv_tx_desc *tx_desc, *eop_desc; |
| 398 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 399 | unsigned int i, eop, count = 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 400 | unsigned int total_bytes = 0, total_packets = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 401 | |
| 402 | i = tx_ring->next_to_clean; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 403 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
| 404 | eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
| 405 | |
| 406 | while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) && |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 407 | (count < tx_ring->work_limit)) { |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 408 | bool cleaned = false; |
| 409 | for ( ; !cleaned; count++) { |
| 410 | struct sk_buff *skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 411 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); |
| 412 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 413 | cleaned = (i == eop); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 414 | skb = tx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 415 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 416 | if (cleaned && skb) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 417 | unsigned int segs, bytecount; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 418 | unsigned int hlen = skb_headlen(skb); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 419 | |
| 420 | /* gso_segs is currently only valid for tcp */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 421 | segs = skb_shinfo(skb)->gso_segs ?: 1; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 422 | #ifdef IXGBE_FCOE |
| 423 | /* adjust for FCoE Sequence Offload */ |
| 424 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 425 | && (skb->protocol == htons(ETH_P_FCOE)) && |
| 426 | skb_is_gso(skb)) { |
| 427 | hlen = skb_transport_offset(skb) + |
| 428 | sizeof(struct fc_frame_header) + |
| 429 | sizeof(struct fcoe_crc_eof); |
| 430 | segs = DIV_ROUND_UP(skb->len - hlen, |
| 431 | skb_shinfo(skb)->gso_size); |
| 432 | } |
| 433 | #endif /* IXGBE_FCOE */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 434 | /* multiply data chunks by size of headers */ |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 435 | bytecount = ((segs - 1) * hlen) + skb->len; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 436 | total_packets += segs; |
| 437 | total_bytes += bytecount; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 438 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 439 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 440 | ixgbe_unmap_and_free_tx_resource(adapter, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 441 | tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 442 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 443 | tx_desc->wb.status = 0; |
| 444 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 445 | i++; |
| 446 | if (i == tx_ring->count) |
| 447 | i = 0; |
| 448 | } |
| 449 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 450 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
| 451 | eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
| 452 | } |
| 453 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 454 | tx_ring->next_to_clean = i; |
| 455 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 456 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 457 | if (unlikely(count && netif_carrier_ok(netdev) && |
| 458 | (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 459 | /* Make sure that anybody stopping the queue after this |
| 460 | * sees the new next_to_clean. |
| 461 | */ |
| 462 | smp_mb(); |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 463 | if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) && |
| 464 | !test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 465 | netif_wake_subqueue(netdev, tx_ring->queue_index); |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 466 | ++tx_ring->restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 467 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 468 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 469 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 470 | if (adapter->detect_tx_hung) { |
| 471 | if (ixgbe_check_tx_hang(adapter, tx_ring, i)) { |
| 472 | /* schedule immediate reset if we believe we hung */ |
| 473 | DPRINTK(PROBE, INFO, |
| 474 | "tx hang %d detected, resetting adapter\n", |
| 475 | adapter->tx_timeout_count + 1); |
| 476 | ixgbe_tx_timeout(adapter->netdev); |
| 477 | } |
| 478 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 479 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 480 | /* re-arm the interrupt */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 481 | if (count >= tx_ring->work_limit) |
| 482 | ixgbe_irq_rearm_queues(adapter, ((u64)1 << q_vector->v_idx)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 483 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 484 | tx_ring->total_bytes += total_bytes; |
| 485 | tx_ring->total_packets += total_packets; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 486 | tx_ring->stats.packets += total_packets; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 487 | tx_ring->stats.bytes += total_bytes; |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 488 | return (count < tx_ring->work_limit); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 489 | } |
| 490 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 491 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 492 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 493 | struct ixgbe_ring *rx_ring) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 494 | { |
| 495 | u32 rxctrl; |
| 496 | int cpu = get_cpu(); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 497 | int q = rx_ring->reg_idx; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 498 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 499 | if (rx_ring->cpu != cpu) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 500 | rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 501 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 502 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK; |
| 503 | rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 504 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 505 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599; |
| 506 | rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 507 | IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599); |
| 508 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 509 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 510 | rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN; |
Don Skidmore | 15005a3 | 2009-01-19 16:54:13 -0800 | [diff] [blame] | 511 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN); |
| 512 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 513 | IXGBE_DCA_RXCTRL_DESC_HSRO_EN); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 514 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 515 | rx_ring->cpu = cpu; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 516 | } |
| 517 | put_cpu(); |
| 518 | } |
| 519 | |
| 520 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 521 | struct ixgbe_ring *tx_ring) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 522 | { |
| 523 | u32 txctrl; |
| 524 | int cpu = get_cpu(); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 525 | int q = tx_ring->reg_idx; |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 526 | struct ixgbe_hw *hw = &adapter->hw; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 527 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 528 | if (tx_ring->cpu != cpu) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 529 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 530 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 531 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK; |
| 532 | txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 533 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 534 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(q), txctrl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 535 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 536 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 537 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599; |
| 538 | txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 539 | IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599); |
| 540 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 541 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(q), txctrl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 542 | } |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 543 | tx_ring->cpu = cpu; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 544 | } |
| 545 | put_cpu(); |
| 546 | } |
| 547 | |
| 548 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 549 | { |
| 550 | int i; |
| 551 | |
| 552 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 553 | return; |
| 554 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 555 | /* always use CB2 mode, difference is masked in the CB driver */ |
| 556 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); |
| 557 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 558 | for (i = 0; i < adapter->num_tx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 559 | adapter->tx_ring[i]->cpu = -1; |
| 560 | ixgbe_update_tx_dca(adapter, adapter->tx_ring[i]); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 561 | } |
| 562 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 563 | adapter->rx_ring[i]->cpu = -1; |
| 564 | ixgbe_update_rx_dca(adapter, adapter->rx_ring[i]); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 565 | } |
| 566 | } |
| 567 | |
| 568 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 569 | { |
| 570 | struct net_device *netdev = dev_get_drvdata(dev); |
| 571 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 572 | unsigned long event = *(unsigned long *)data; |
| 573 | |
| 574 | switch (event) { |
| 575 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 576 | /* if we're already enabled, don't do it again */ |
| 577 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 578 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 579 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 580 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 581 | ixgbe_setup_dca(adapter); |
| 582 | break; |
| 583 | } |
| 584 | /* Fall Through since DCA is disabled. */ |
| 585 | case DCA_PROVIDER_REMOVE: |
| 586 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 587 | dca_remove_requester(dev); |
| 588 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 589 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 590 | } |
| 591 | break; |
| 592 | } |
| 593 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 594 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 595 | } |
| 596 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 597 | #endif /* CONFIG_IXGBE_DCA */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 598 | /** |
| 599 | * ixgbe_receive_skb - Send a completed packet up the stack |
| 600 | * @adapter: board private structure |
| 601 | * @skb: packet to send up |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 602 | * @status: hardware indication of status of receive |
| 603 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
| 604 | * @rx_desc: rx descriptor |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 605 | **/ |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 606 | static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 607 | struct sk_buff *skb, u8 status, |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 608 | struct ixgbe_ring *ring, |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 609 | union ixgbe_adv_rx_desc *rx_desc) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 610 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 611 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 612 | struct napi_struct *napi = &q_vector->napi; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 613 | bool is_vlan = (status & IXGBE_RXD_STAT_VP); |
| 614 | u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 615 | |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 616 | skb_record_rx_queue(skb, ring->queue_index); |
Alexander Duyck | 182ff8d | 2009-04-27 22:35:33 +0000 | [diff] [blame] | 617 | if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) { |
Lucy Liu | 8a62bab | 2009-08-13 14:09:38 +0000 | [diff] [blame] | 618 | if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK)) |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 619 | vlan_gro_receive(napi, adapter->vlgrp, tag, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 620 | else |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 621 | napi_gro_receive(napi, skb); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 622 | } else { |
Lucy Liu | 8a62bab | 2009-08-13 14:09:38 +0000 | [diff] [blame] | 623 | if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK)) |
Alexander Duyck | 182ff8d | 2009-04-27 22:35:33 +0000 | [diff] [blame] | 624 | vlan_hwaccel_rx(skb, adapter->vlgrp, tag); |
| 625 | else |
| 626 | netif_rx(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 627 | } |
| 628 | } |
| 629 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 630 | /** |
| 631 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
| 632 | * @adapter: address of board private structure |
| 633 | * @status_err: hardware indication of status of receive |
| 634 | * @skb: skb currently being received and modified |
| 635 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 636 | static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 637 | union ixgbe_adv_rx_desc *rx_desc, |
| 638 | struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 639 | { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 640 | u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 641 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 642 | skb->ip_summed = CHECKSUM_NONE; |
| 643 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 644 | /* Rx csum disabled */ |
| 645 | if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 646 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 647 | |
| 648 | /* if IP and error */ |
| 649 | if ((status_err & IXGBE_RXD_STAT_IPCS) && |
| 650 | (status_err & IXGBE_RXDADV_ERR_IPE)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 651 | adapter->hw_csum_rx_error++; |
| 652 | return; |
| 653 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 654 | |
| 655 | if (!(status_err & IXGBE_RXD_STAT_L4CS)) |
| 656 | return; |
| 657 | |
| 658 | if (status_err & IXGBE_RXDADV_ERR_TCPE) { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 659 | u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 660 | |
| 661 | /* |
| 662 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 663 | * checksum errors. |
| 664 | */ |
| 665 | if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) && |
| 666 | (adapter->hw.mac.type == ixgbe_mac_82599EB)) |
| 667 | return; |
| 668 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 669 | adapter->hw_csum_rx_error++; |
| 670 | return; |
| 671 | } |
| 672 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 673 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 674 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 675 | } |
| 676 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 677 | static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw, |
| 678 | struct ixgbe_ring *rx_ring, u32 val) |
| 679 | { |
| 680 | /* |
| 681 | * Force memory writes to complete before letting h/w |
| 682 | * know there are new descriptors to fetch. (Only |
| 683 | * applicable for weak-ordered memory model archs, |
| 684 | * such as IA-64). |
| 685 | */ |
| 686 | wmb(); |
| 687 | IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val); |
| 688 | } |
| 689 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 690 | /** |
| 691 | * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split |
| 692 | * @adapter: address of board private structure |
| 693 | **/ |
| 694 | static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 695 | struct ixgbe_ring *rx_ring, |
| 696 | int cleaned_count) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 697 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 698 | struct pci_dev *pdev = adapter->pdev; |
| 699 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 700 | struct ixgbe_rx_buffer *bi; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 701 | unsigned int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 702 | |
| 703 | i = rx_ring->next_to_use; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 704 | bi = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 705 | |
| 706 | while (cleaned_count--) { |
| 707 | rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 708 | |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 709 | if (!bi->page_dma && |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 710 | (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 711 | if (!bi->page) { |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 712 | bi->page = alloc_page(GFP_ATOMIC); |
| 713 | if (!bi->page) { |
| 714 | adapter->alloc_rx_page_failed++; |
| 715 | goto no_buffers; |
| 716 | } |
| 717 | bi->page_offset = 0; |
| 718 | } else { |
| 719 | /* use a half page if we're re-using */ |
| 720 | bi->page_offset ^= (PAGE_SIZE / 2); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 721 | } |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 722 | |
| 723 | bi->page_dma = pci_map_page(pdev, bi->page, |
| 724 | bi->page_offset, |
| 725 | (PAGE_SIZE / 2), |
| 726 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 727 | } |
| 728 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 729 | if (!bi->skb) { |
Jesse Brandeburg | 5ecc361 | 2008-12-15 01:00:57 -0800 | [diff] [blame] | 730 | struct sk_buff *skb; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 731 | /* netdev_alloc_skb reserves 32 bytes up front!! */ |
| 732 | uint bufsz = rx_ring->rx_buf_len + SMP_CACHE_BYTES; |
| 733 | skb = netdev_alloc_skb(adapter->netdev, bufsz); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 734 | |
| 735 | if (!skb) { |
| 736 | adapter->alloc_rx_buff_failed++; |
| 737 | goto no_buffers; |
| 738 | } |
| 739 | |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 740 | /* advance the data pointer to the next cache line */ |
| 741 | skb_reserve(skb, (PTR_ALIGN(skb->data, SMP_CACHE_BYTES) |
| 742 | - skb->data)); |
| 743 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 744 | bi->skb = skb; |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 745 | bi->dma = pci_map_single(pdev, skb->data, |
| 746 | rx_ring->rx_buf_len, |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 747 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 748 | } |
| 749 | /* Refresh the desc even if buffer_addrs didn't change because |
| 750 | * each write-back erases this info. */ |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 751 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 752 | rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma); |
| 753 | rx_desc->read.hdr_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 754 | } else { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 755 | rx_desc->read.pkt_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 756 | } |
| 757 | |
| 758 | i++; |
| 759 | if (i == rx_ring->count) |
| 760 | i = 0; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 761 | bi = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 762 | } |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 763 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 764 | no_buffers: |
| 765 | if (rx_ring->next_to_use != i) { |
| 766 | rx_ring->next_to_use = i; |
| 767 | if (i-- == 0) |
| 768 | i = (rx_ring->count - 1); |
| 769 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 770 | ixgbe_release_rx_desc(&adapter->hw, rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 771 | } |
| 772 | } |
| 773 | |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 774 | static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc) |
| 775 | { |
| 776 | return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info; |
| 777 | } |
| 778 | |
| 779 | static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc) |
| 780 | { |
| 781 | return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 782 | } |
| 783 | |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 784 | static inline u32 ixgbe_get_rsc_count(union ixgbe_adv_rx_desc *rx_desc) |
| 785 | { |
| 786 | return (le32_to_cpu(rx_desc->wb.lower.lo_dword.data) & |
| 787 | IXGBE_RXDADV_RSCCNT_MASK) >> |
| 788 | IXGBE_RXDADV_RSCCNT_SHIFT; |
| 789 | } |
| 790 | |
| 791 | /** |
| 792 | * ixgbe_transform_rsc_queue - change rsc queue into a full packet |
| 793 | * @skb: pointer to the last skb in the rsc queue |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 794 | * @count: pointer to number of packets coalesced in this context |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 795 | * |
| 796 | * This function changes a queue full of hw rsc buffers into a completed |
| 797 | * packet. It uses the ->prev pointers to find the first packet and then |
| 798 | * turns it into the frag list owner. |
| 799 | **/ |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 800 | static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb, |
| 801 | u64 *count) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 802 | { |
| 803 | unsigned int frag_list_size = 0; |
| 804 | |
| 805 | while (skb->prev) { |
| 806 | struct sk_buff *prev = skb->prev; |
| 807 | frag_list_size += skb->len; |
| 808 | skb->prev = NULL; |
| 809 | skb = prev; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 810 | *count += 1; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 811 | } |
| 812 | |
| 813 | skb_shinfo(skb)->frag_list = skb->next; |
| 814 | skb->next = NULL; |
| 815 | skb->len += frag_list_size; |
| 816 | skb->data_len += frag_list_size; |
| 817 | skb->truesize += frag_list_size; |
| 818 | return skb; |
| 819 | } |
| 820 | |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 821 | struct ixgbe_rsc_cb { |
| 822 | dma_addr_t dma; |
| 823 | }; |
| 824 | |
| 825 | #define IXGBE_RSC_CB(skb) ((struct ixgbe_rsc_cb *)(skb)->cb) |
| 826 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 827 | static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 828 | struct ixgbe_ring *rx_ring, |
| 829 | int *work_done, int work_to_do) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 830 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 831 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 832 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 833 | struct pci_dev *pdev = adapter->pdev; |
| 834 | union ixgbe_adv_rx_desc *rx_desc, *next_rxd; |
| 835 | struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer; |
| 836 | struct sk_buff *skb; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 837 | unsigned int i, rsc_count = 0; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 838 | u32 len, staterr; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 839 | u16 hdr_info; |
| 840 | bool cleaned = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 841 | int cleaned_count = 0; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 842 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 843 | #ifdef IXGBE_FCOE |
| 844 | int ddp_bytes = 0; |
| 845 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 846 | |
| 847 | i = rx_ring->next_to_clean; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 848 | rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 849 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 850 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 851 | |
| 852 | while (staterr & IXGBE_RXD_STAT_DD) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 853 | u32 upper_len = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 854 | if (*work_done >= work_to_do) |
| 855 | break; |
| 856 | (*work_done)++; |
| 857 | |
Milton Miller | 3c945e5 | 2010-02-19 17:44:42 +0000 | [diff] [blame] | 858 | rmb(); /* read descriptor and rx_buffer_info after status DD */ |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 859 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 860 | hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc)); |
| 861 | len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >> |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 862 | IXGBE_RXDADV_HDRBUFLEN_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 863 | if (len > IXGBE_RX_HDR_SIZE) |
| 864 | len = IXGBE_RX_HDR_SIZE; |
| 865 | upper_len = le16_to_cpu(rx_desc->wb.upper.length); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 866 | } else { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 867 | len = le16_to_cpu(rx_desc->wb.upper.length); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 868 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 869 | |
| 870 | cleaned = true; |
| 871 | skb = rx_buffer_info->skb; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 872 | prefetch(skb->data); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 873 | rx_buffer_info->skb = NULL; |
| 874 | |
Alexander Duyck | 21fa4e6 | 2009-06-04 15:59:49 +0000 | [diff] [blame] | 875 | if (rx_buffer_info->dma) { |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 876 | if ((adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) && |
| 877 | (!(staterr & IXGBE_RXD_STAT_EOP)) && |
| 878 | (!(skb->prev))) |
| 879 | /* |
| 880 | * When HWRSC is enabled, delay unmapping |
| 881 | * of the first packet. It carries the |
| 882 | * header information, HW may still |
| 883 | * access the header after the writeback. |
| 884 | * Only unmap it when EOP is reached |
| 885 | */ |
| 886 | IXGBE_RSC_CB(skb)->dma = rx_buffer_info->dma; |
| 887 | else |
| 888 | pci_unmap_single(pdev, rx_buffer_info->dma, |
| 889 | rx_ring->rx_buf_len, |
| 890 | PCI_DMA_FROMDEVICE); |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 891 | rx_buffer_info->dma = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 892 | skb_put(skb, len); |
| 893 | } |
| 894 | |
| 895 | if (upper_len) { |
| 896 | pci_unmap_page(pdev, rx_buffer_info->page_dma, |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 897 | PAGE_SIZE / 2, PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 898 | rx_buffer_info->page_dma = 0; |
| 899 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 900 | rx_buffer_info->page, |
| 901 | rx_buffer_info->page_offset, |
| 902 | upper_len); |
| 903 | |
| 904 | if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) || |
| 905 | (page_count(rx_buffer_info->page) != 1)) |
| 906 | rx_buffer_info->page = NULL; |
| 907 | else |
| 908 | get_page(rx_buffer_info->page); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 909 | |
| 910 | skb->len += upper_len; |
| 911 | skb->data_len += upper_len; |
| 912 | skb->truesize += upper_len; |
| 913 | } |
| 914 | |
| 915 | i++; |
| 916 | if (i == rx_ring->count) |
| 917 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 918 | |
| 919 | next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 920 | prefetch(next_rxd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 921 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 922 | |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 923 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 924 | rsc_count = ixgbe_get_rsc_count(rx_desc); |
| 925 | |
| 926 | if (rsc_count) { |
| 927 | u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >> |
| 928 | IXGBE_RXDADV_NEXTP_SHIFT; |
| 929 | next_buffer = &rx_ring->rx_buffer_info[nextp]; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 930 | } else { |
| 931 | next_buffer = &rx_ring->rx_buffer_info[i]; |
| 932 | } |
| 933 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 934 | if (staterr & IXGBE_RXD_STAT_EOP) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 935 | if (skb->prev) |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 936 | skb = ixgbe_transform_rsc_queue(skb, &(rx_ring->rsc_count)); |
| 937 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Mallikarjuna R Chilakala | fd3686a | 2010-03-19 04:41:33 +0000 | [diff] [blame] | 938 | if (IXGBE_RSC_CB(skb)->dma) { |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 939 | pci_unmap_single(pdev, IXGBE_RSC_CB(skb)->dma, |
| 940 | rx_ring->rx_buf_len, |
| 941 | PCI_DMA_FROMDEVICE); |
Mallikarjuna R Chilakala | fd3686a | 2010-03-19 04:41:33 +0000 | [diff] [blame] | 942 | IXGBE_RSC_CB(skb)->dma = 0; |
| 943 | } |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 944 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) |
| 945 | rx_ring->rsc_count += skb_shinfo(skb)->nr_frags; |
| 946 | else |
| 947 | rx_ring->rsc_count++; |
| 948 | rx_ring->rsc_flush++; |
| 949 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 950 | rx_ring->stats.packets++; |
| 951 | rx_ring->stats.bytes += skb->len; |
| 952 | } else { |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 953 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 954 | rx_buffer_info->skb = next_buffer->skb; |
| 955 | rx_buffer_info->dma = next_buffer->dma; |
| 956 | next_buffer->skb = skb; |
| 957 | next_buffer->dma = 0; |
| 958 | } else { |
| 959 | skb->next = next_buffer->skb; |
| 960 | skb->next->prev = skb; |
| 961 | } |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 962 | rx_ring->non_eop_descs++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 963 | goto next_desc; |
| 964 | } |
| 965 | |
| 966 | if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) { |
| 967 | dev_kfree_skb_irq(skb); |
| 968 | goto next_desc; |
| 969 | } |
| 970 | |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 971 | ixgbe_rx_checksum(adapter, rx_desc, skb); |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 972 | |
| 973 | /* probably a little skewed due to removing CRC */ |
| 974 | total_rx_bytes += skb->len; |
| 975 | total_rx_packets++; |
| 976 | |
Jesse Brandeburg | 74ce8dd | 2008-09-11 20:03:23 -0700 | [diff] [blame] | 977 | skb->protocol = eth_type_trans(skb, adapter->netdev); |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 978 | #ifdef IXGBE_FCOE |
| 979 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 980 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 981 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
| 982 | if (!ddp_bytes) |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 983 | goto next_desc; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 984 | } |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 985 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 986 | ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 987 | |
| 988 | next_desc: |
| 989 | rx_desc->wb.upper.status_error = 0; |
| 990 | |
| 991 | /* return some buffers to hardware, one at a time is too slow */ |
| 992 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 993 | ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count); |
| 994 | cleaned_count = 0; |
| 995 | } |
| 996 | |
| 997 | /* use prefetched values */ |
| 998 | rx_desc = next_rxd; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 999 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1000 | |
| 1001 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 1002 | } |
| 1003 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1004 | rx_ring->next_to_clean = i; |
| 1005 | cleaned_count = IXGBE_DESC_UNUSED(rx_ring); |
| 1006 | |
| 1007 | if (cleaned_count) |
| 1008 | ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count); |
| 1009 | |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 1010 | #ifdef IXGBE_FCOE |
| 1011 | /* include DDPed FCoE data */ |
| 1012 | if (ddp_bytes > 0) { |
| 1013 | unsigned int mss; |
| 1014 | |
| 1015 | mss = adapter->netdev->mtu - sizeof(struct fcoe_hdr) - |
| 1016 | sizeof(struct fc_frame_header) - |
| 1017 | sizeof(struct fcoe_crc_eof); |
| 1018 | if (mss > 512) |
| 1019 | mss &= ~511; |
| 1020 | total_rx_bytes += ddp_bytes; |
| 1021 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss); |
| 1022 | } |
| 1023 | #endif /* IXGBE_FCOE */ |
| 1024 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1025 | rx_ring->total_packets += total_rx_packets; |
| 1026 | rx_ring->total_bytes += total_rx_bytes; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 1027 | netdev->stats.rx_bytes += total_rx_bytes; |
| 1028 | netdev->stats.rx_packets += total_rx_packets; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1029 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1030 | return cleaned; |
| 1031 | } |
| 1032 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1033 | static int ixgbe_clean_rxonly(struct napi_struct *, int); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1034 | /** |
| 1035 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 1036 | * @adapter: board private structure |
| 1037 | * |
| 1038 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 1039 | * interrupts. |
| 1040 | **/ |
| 1041 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 1042 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1043 | struct ixgbe_q_vector *q_vector; |
| 1044 | int i, j, q_vectors, v_idx, r_idx; |
| 1045 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1046 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1047 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1048 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 1049 | /* |
| 1050 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1051 | * corresponding register. |
| 1052 | */ |
| 1053 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1054 | q_vector = adapter->q_vector[v_idx]; |
Akinobu Mita | 984b3f5 | 2010-03-05 13:41:37 -0800 | [diff] [blame] | 1055 | /* XXX for_each_set_bit(...) */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1056 | r_idx = find_first_bit(q_vector->rxr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1057 | adapter->num_rx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1058 | |
| 1059 | for (i = 0; i < q_vector->rxr_count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1060 | j = adapter->rx_ring[r_idx]->reg_idx; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1061 | ixgbe_set_ivar(adapter, 0, j, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1062 | r_idx = find_next_bit(q_vector->rxr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1063 | adapter->num_rx_queues, |
| 1064 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1065 | } |
| 1066 | r_idx = find_first_bit(q_vector->txr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1067 | adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1068 | |
| 1069 | for (i = 0; i < q_vector->txr_count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1070 | j = adapter->tx_ring[r_idx]->reg_idx; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1071 | ixgbe_set_ivar(adapter, 1, j, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1072 | r_idx = find_next_bit(q_vector->txr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1073 | adapter->num_tx_queues, |
| 1074 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1075 | } |
| 1076 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1077 | if (q_vector->txr_count && !q_vector->rxr_count) |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1078 | /* tx only */ |
| 1079 | q_vector->eitr = adapter->tx_eitr_param; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1080 | else if (q_vector->rxr_count) |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1081 | /* rx or mixed */ |
| 1082 | q_vector->eitr = adapter->rx_eitr_param; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1083 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1084 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1085 | } |
| 1086 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1087 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 1088 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
| 1089 | v_idx); |
| 1090 | else if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 1091 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1092 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1093 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 1094 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1095 | mask = IXGBE_EIMS_ENABLE_MASK; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 1096 | if (adapter->num_vfs) |
| 1097 | mask &= ~(IXGBE_EIMS_OTHER | |
| 1098 | IXGBE_EIMS_MAILBOX | |
| 1099 | IXGBE_EIMS_LSC); |
| 1100 | else |
| 1101 | mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1102 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1103 | } |
| 1104 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1105 | enum latency_range { |
| 1106 | lowest_latency = 0, |
| 1107 | low_latency = 1, |
| 1108 | bulk_latency = 2, |
| 1109 | latency_invalid = 255 |
| 1110 | }; |
| 1111 | |
| 1112 | /** |
| 1113 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
| 1114 | * @adapter: pointer to adapter |
| 1115 | * @eitr: eitr setting (ints per sec) to give last timeslice |
| 1116 | * @itr_setting: current throttle rate in ints/second |
| 1117 | * @packets: the number of packets during this measurement interval |
| 1118 | * @bytes: the number of bytes during this measurement interval |
| 1119 | * |
| 1120 | * Stores a new ITR value based on packets and byte |
| 1121 | * counts during the last interrupt. The advantage of per interrupt |
| 1122 | * computation is faster updates and more accurate ITR for the current |
| 1123 | * traffic pattern. Constants in this function were computed |
| 1124 | * based on theoretical maximum wire speed and thresholds were set based |
| 1125 | * on testing data as well as attempting to minimize response time |
| 1126 | * while increasing bulk throughput. |
| 1127 | * this functionality is controlled by the InterruptThrottleRate module |
| 1128 | * parameter (see ixgbe_param.c) |
| 1129 | **/ |
| 1130 | static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1131 | u32 eitr, u8 itr_setting, |
| 1132 | int packets, int bytes) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1133 | { |
| 1134 | unsigned int retval = itr_setting; |
| 1135 | u32 timepassed_us; |
| 1136 | u64 bytes_perint; |
| 1137 | |
| 1138 | if (packets == 0) |
| 1139 | goto update_itr_done; |
| 1140 | |
| 1141 | |
| 1142 | /* simple throttlerate management |
| 1143 | * 0-20MB/s lowest (100000 ints/s) |
| 1144 | * 20-100MB/s low (20000 ints/s) |
| 1145 | * 100-1249MB/s bulk (8000 ints/s) |
| 1146 | */ |
| 1147 | /* what was last interrupt timeslice? */ |
| 1148 | timepassed_us = 1000000/eitr; |
| 1149 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 1150 | |
| 1151 | switch (itr_setting) { |
| 1152 | case lowest_latency: |
| 1153 | if (bytes_perint > adapter->eitr_low) |
| 1154 | retval = low_latency; |
| 1155 | break; |
| 1156 | case low_latency: |
| 1157 | if (bytes_perint > adapter->eitr_high) |
| 1158 | retval = bulk_latency; |
| 1159 | else if (bytes_perint <= adapter->eitr_low) |
| 1160 | retval = lowest_latency; |
| 1161 | break; |
| 1162 | case bulk_latency: |
| 1163 | if (bytes_perint <= adapter->eitr_high) |
| 1164 | retval = low_latency; |
| 1165 | break; |
| 1166 | } |
| 1167 | |
| 1168 | update_itr_done: |
| 1169 | return retval; |
| 1170 | } |
| 1171 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1172 | /** |
| 1173 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1174 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1175 | * |
| 1176 | * This function is made to be called by ethtool and by the driver |
| 1177 | * when it needs to update EITR registers at runtime. Hardware |
| 1178 | * specific quirks/differences are taken care of here. |
| 1179 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1180 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1181 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1182 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1183 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1184 | int v_idx = q_vector->v_idx; |
| 1185 | u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr); |
| 1186 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1187 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1188 | /* must write high and low 16 bits to reset counter */ |
| 1189 | itr_reg |= (itr_reg << 16); |
| 1190 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 1191 | /* |
| 1192 | * set the WDIS bit to not clear the timer bits and cause an |
| 1193 | * immediate assertion of the interrupt |
| 1194 | */ |
| 1195 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
| 1196 | } |
| 1197 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 1198 | } |
| 1199 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1200 | static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector) |
| 1201 | { |
| 1202 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1203 | u32 new_itr; |
| 1204 | u8 current_itr, ret_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1205 | int i, r_idx; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1206 | struct ixgbe_ring *rx_ring, *tx_ring; |
| 1207 | |
| 1208 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1209 | for (i = 0; i < q_vector->txr_count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1210 | tx_ring = adapter->tx_ring[r_idx]; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1211 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1212 | q_vector->tx_itr, |
| 1213 | tx_ring->total_packets, |
| 1214 | tx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1215 | /* if the result for this queue would decrease interrupt |
| 1216 | * rate for this vector then use that result */ |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1217 | q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ? |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1218 | q_vector->tx_itr - 1 : ret_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1219 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1220 | r_idx + 1); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1221 | } |
| 1222 | |
| 1223 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1224 | for (i = 0; i < q_vector->rxr_count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1225 | rx_ring = adapter->rx_ring[r_idx]; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1226 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1227 | q_vector->rx_itr, |
| 1228 | rx_ring->total_packets, |
| 1229 | rx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1230 | /* if the result for this queue would decrease interrupt |
| 1231 | * rate for this vector then use that result */ |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1232 | q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ? |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1233 | q_vector->rx_itr - 1 : ret_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1234 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1235 | r_idx + 1); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1236 | } |
| 1237 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1238 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1239 | |
| 1240 | switch (current_itr) { |
| 1241 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1242 | case lowest_latency: |
| 1243 | new_itr = 100000; |
| 1244 | break; |
| 1245 | case low_latency: |
| 1246 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 1247 | break; |
| 1248 | case bulk_latency: |
| 1249 | default: |
| 1250 | new_itr = 8000; |
| 1251 | break; |
| 1252 | } |
| 1253 | |
| 1254 | if (new_itr != q_vector->eitr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1255 | /* do an exponential smoothing */ |
| 1256 | new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1257 | |
| 1258 | /* save the algorithm value here, not the smoothed one */ |
| 1259 | q_vector->eitr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1260 | |
| 1261 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | return; |
| 1265 | } |
| 1266 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1267 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 1268 | { |
| 1269 | struct ixgbe_hw *hw = &adapter->hw; |
| 1270 | |
| 1271 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
| 1272 | (eicr & IXGBE_EICR_GPI_SDP1)) { |
| 1273 | DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n"); |
| 1274 | /* write to clear the interrupt */ |
| 1275 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 1276 | } |
| 1277 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1278 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1279 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 1280 | { |
| 1281 | struct ixgbe_hw *hw = &adapter->hw; |
| 1282 | |
| 1283 | if (eicr & IXGBE_EICR_GPI_SDP1) { |
| 1284 | /* Clear the interrupt */ |
| 1285 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 1286 | schedule_work(&adapter->multispeed_fiber_task); |
| 1287 | } else if (eicr & IXGBE_EICR_GPI_SDP2) { |
| 1288 | /* Clear the interrupt */ |
| 1289 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2); |
| 1290 | schedule_work(&adapter->sfp_config_module_task); |
| 1291 | } else { |
| 1292 | /* Interrupt isn't for us... */ |
| 1293 | return; |
| 1294 | } |
| 1295 | } |
| 1296 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1297 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 1298 | { |
| 1299 | struct ixgbe_hw *hw = &adapter->hw; |
| 1300 | |
| 1301 | adapter->lsc_int++; |
| 1302 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 1303 | adapter->link_check_timeout = jiffies; |
| 1304 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1305 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
Nelson, Shannon | 8a0717f | 2009-11-12 18:47:11 +0000 | [diff] [blame] | 1306 | IXGBE_WRITE_FLUSH(hw); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1307 | schedule_work(&adapter->watchdog_task); |
| 1308 | } |
| 1309 | } |
| 1310 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1311 | static irqreturn_t ixgbe_msix_lsc(int irq, void *data) |
| 1312 | { |
| 1313 | struct net_device *netdev = data; |
| 1314 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1315 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 1316 | u32 eicr; |
| 1317 | |
| 1318 | /* |
| 1319 | * Workaround for Silicon errata. Use clear-by-write instead |
| 1320 | * of clear-by-read. Reading with EICS will return the |
| 1321 | * interrupt causes without clearing, which later be done |
| 1322 | * with the write to EICR. |
| 1323 | */ |
| 1324 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
| 1325 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1326 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1327 | if (eicr & IXGBE_EICR_LSC) |
| 1328 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1329 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 1330 | if (eicr & IXGBE_EICR_MAILBOX) |
| 1331 | ixgbe_msg_task(adapter); |
| 1332 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1333 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 1334 | ixgbe_check_fan_failure(adapter, eicr); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1335 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1336 | if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1337 | ixgbe_check_sfp_event(adapter, eicr); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1338 | |
| 1339 | /* Handle Flow Director Full threshold interrupt */ |
| 1340 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
| 1341 | int i; |
| 1342 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR); |
| 1343 | /* Disable transmits before FDIR Re-initialization */ |
| 1344 | netif_tx_stop_all_queues(netdev); |
| 1345 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 1346 | struct ixgbe_ring *tx_ring = |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1347 | adapter->tx_ring[i]; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1348 | if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE, |
| 1349 | &tx_ring->reinit_state)) |
| 1350 | schedule_work(&adapter->fdir_reinit_task); |
| 1351 | } |
| 1352 | } |
| 1353 | } |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1354 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1355 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1356 | |
| 1357 | return IRQ_HANDLED; |
| 1358 | } |
| 1359 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1360 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 1361 | u64 qmask) |
| 1362 | { |
| 1363 | u32 mask; |
| 1364 | |
| 1365 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1366 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 1367 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 1368 | } else { |
| 1369 | mask = (qmask & 0xFFFFFFFF); |
| 1370 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(0), mask); |
| 1371 | mask = (qmask >> 32); |
| 1372 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask); |
| 1373 | } |
| 1374 | /* skip the flush */ |
| 1375 | } |
| 1376 | |
| 1377 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
| 1378 | u64 qmask) |
| 1379 | { |
| 1380 | u32 mask; |
| 1381 | |
| 1382 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1383 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 1384 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask); |
| 1385 | } else { |
| 1386 | mask = (qmask & 0xFFFFFFFF); |
| 1387 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), mask); |
| 1388 | mask = (qmask >> 32); |
| 1389 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), mask); |
| 1390 | } |
| 1391 | /* skip the flush */ |
| 1392 | } |
| 1393 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1394 | static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data) |
| 1395 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1396 | struct ixgbe_q_vector *q_vector = data; |
| 1397 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1398 | struct ixgbe_ring *tx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1399 | int i, r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1400 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1401 | if (!q_vector->txr_count) |
| 1402 | return IRQ_HANDLED; |
| 1403 | |
| 1404 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1405 | for (i = 0; i < q_vector->txr_count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1406 | tx_ring = adapter->tx_ring[r_idx]; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1407 | tx_ring->total_bytes = 0; |
| 1408 | tx_ring->total_packets = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1409 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1410 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1411 | } |
| 1412 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 1413 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1414 | napi_schedule(&q_vector->napi); |
| 1415 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1416 | return IRQ_HANDLED; |
| 1417 | } |
| 1418 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1419 | /** |
| 1420 | * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues) |
| 1421 | * @irq: unused |
| 1422 | * @data: pointer to our q_vector struct for this interrupt vector |
| 1423 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1424 | static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data) |
| 1425 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1426 | struct ixgbe_q_vector *q_vector = data; |
| 1427 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1428 | struct ixgbe_ring *rx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1429 | int r_idx; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1430 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1431 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1432 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1433 | for (i = 0; i < q_vector->rxr_count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1434 | rx_ring = adapter->rx_ring[r_idx]; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1435 | rx_ring->total_bytes = 0; |
| 1436 | rx_ring->total_packets = 0; |
| 1437 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1438 | r_idx + 1); |
| 1439 | } |
| 1440 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1441 | if (!q_vector->rxr_count) |
| 1442 | return IRQ_HANDLED; |
| 1443 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1444 | /* disable interrupts on this vector only */ |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 1445 | /* EIAM disabled interrupts (on this vector) for us */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1446 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1447 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1448 | return IRQ_HANDLED; |
| 1449 | } |
| 1450 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1451 | static irqreturn_t ixgbe_msix_clean_many(int irq, void *data) |
| 1452 | { |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1453 | struct ixgbe_q_vector *q_vector = data; |
| 1454 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1455 | struct ixgbe_ring *ring; |
| 1456 | int r_idx; |
| 1457 | int i; |
| 1458 | |
| 1459 | if (!q_vector->txr_count && !q_vector->rxr_count) |
| 1460 | return IRQ_HANDLED; |
| 1461 | |
| 1462 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1463 | for (i = 0; i < q_vector->txr_count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1464 | ring = adapter->tx_ring[r_idx]; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1465 | ring->total_bytes = 0; |
| 1466 | ring->total_packets = 0; |
| 1467 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
| 1468 | r_idx + 1); |
| 1469 | } |
| 1470 | |
| 1471 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1472 | for (i = 0; i < q_vector->rxr_count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1473 | ring = adapter->rx_ring[r_idx]; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1474 | ring->total_bytes = 0; |
| 1475 | ring->total_packets = 0; |
| 1476 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1477 | r_idx + 1); |
| 1478 | } |
| 1479 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 1480 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1481 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1482 | |
| 1483 | return IRQ_HANDLED; |
| 1484 | } |
| 1485 | |
| 1486 | /** |
| 1487 | * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine |
| 1488 | * @napi: napi struct with our devices info in it |
| 1489 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1490 | * |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1491 | * This function is optimized for cleaning one queue only on a single |
| 1492 | * q_vector!!! |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1493 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1494 | static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget) |
| 1495 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1496 | struct ixgbe_q_vector *q_vector = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1497 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1498 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1499 | struct ixgbe_ring *rx_ring = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1500 | int work_done = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1501 | long r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1502 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1503 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1504 | rx_ring = adapter->rx_ring[r_idx]; |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1505 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1506 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1507 | ixgbe_update_rx_dca(adapter, rx_ring); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1508 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1509 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1510 | ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1511 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1512 | /* If all Rx work done, exit the polling mode */ |
| 1513 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1514 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1515 | if (adapter->rx_itr_setting & 1) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1516 | ixgbe_set_itr_msix(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1517 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1518 | ixgbe_irq_enable_queues(adapter, |
| 1519 | ((u64)1 << q_vector->v_idx)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1520 | } |
| 1521 | |
| 1522 | return work_done; |
| 1523 | } |
| 1524 | |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1525 | /** |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1526 | * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1527 | * @napi: napi struct with our devices info in it |
| 1528 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1529 | * |
| 1530 | * This function will clean more than one rx queue associated with a |
| 1531 | * q_vector. |
| 1532 | **/ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1533 | static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget) |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1534 | { |
| 1535 | struct ixgbe_q_vector *q_vector = |
| 1536 | container_of(napi, struct ixgbe_q_vector, napi); |
| 1537 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1538 | struct ixgbe_ring *ring = NULL; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1539 | int work_done = 0, i; |
| 1540 | long r_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1541 | bool tx_clean_complete = true; |
| 1542 | |
| 1543 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1544 | for (i = 0; i < q_vector->txr_count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1545 | ring = adapter->tx_ring[r_idx]; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1546 | #ifdef CONFIG_IXGBE_DCA |
| 1547 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1548 | ixgbe_update_tx_dca(adapter, ring); |
| 1549 | #endif |
| 1550 | tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring); |
| 1551 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
| 1552 | r_idx + 1); |
| 1553 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1554 | |
| 1555 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 1556 | * the budget to go below 1 because we'll exit polling */ |
| 1557 | budget /= (q_vector->rxr_count ?: 1); |
| 1558 | budget = max(budget, 1); |
| 1559 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1560 | for (i = 0; i < q_vector->rxr_count; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1561 | ring = adapter->rx_ring[r_idx]; |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1562 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1563 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1564 | ixgbe_update_rx_dca(adapter, ring); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1565 | #endif |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1566 | ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1567 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1568 | r_idx + 1); |
| 1569 | } |
| 1570 | |
| 1571 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1572 | ring = adapter->rx_ring[r_idx]; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1573 | /* If all Rx work done, exit the polling mode */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 1574 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1575 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1576 | if (adapter->rx_itr_setting & 1) |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1577 | ixgbe_set_itr_msix(q_vector); |
| 1578 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1579 | ixgbe_irq_enable_queues(adapter, |
| 1580 | ((u64)1 << q_vector->v_idx)); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1581 | return 0; |
| 1582 | } |
| 1583 | |
| 1584 | return work_done; |
| 1585 | } |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1586 | |
| 1587 | /** |
| 1588 | * ixgbe_clean_txonly - msix (aka one shot) tx clean routine |
| 1589 | * @napi: napi struct with our devices info in it |
| 1590 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1591 | * |
| 1592 | * This function is optimized for cleaning one queue only on a single |
| 1593 | * q_vector!!! |
| 1594 | **/ |
| 1595 | static int ixgbe_clean_txonly(struct napi_struct *napi, int budget) |
| 1596 | { |
| 1597 | struct ixgbe_q_vector *q_vector = |
| 1598 | container_of(napi, struct ixgbe_q_vector, napi); |
| 1599 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1600 | struct ixgbe_ring *tx_ring = NULL; |
| 1601 | int work_done = 0; |
| 1602 | long r_idx; |
| 1603 | |
| 1604 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1605 | tx_ring = adapter->tx_ring[r_idx]; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1606 | #ifdef CONFIG_IXGBE_DCA |
| 1607 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1608 | ixgbe_update_tx_dca(adapter, tx_ring); |
| 1609 | #endif |
| 1610 | |
| 1611 | if (!ixgbe_clean_tx_irq(q_vector, tx_ring)) |
| 1612 | work_done = budget; |
| 1613 | |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1614 | /* If all Tx work done, exit the polling mode */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1615 | if (work_done < budget) { |
| 1616 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1617 | if (adapter->tx_itr_setting & 1) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1618 | ixgbe_set_itr_msix(q_vector); |
| 1619 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1620 | ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 1621 | } |
| 1622 | |
| 1623 | return work_done; |
| 1624 | } |
| 1625 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1626 | static inline void map_vector_to_rxq(struct ixgbe_adapter *a, int v_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1627 | int r_idx) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1628 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1629 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
| 1630 | |
| 1631 | set_bit(r_idx, q_vector->rxr_idx); |
| 1632 | q_vector->rxr_count++; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1633 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1634 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1635 | static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx, |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1636 | int t_idx) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1637 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1638 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
| 1639 | |
| 1640 | set_bit(t_idx, q_vector->txr_idx); |
| 1641 | q_vector->txr_count++; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1642 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1643 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1644 | /** |
| 1645 | * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors |
| 1646 | * @adapter: board private structure to initialize |
| 1647 | * @vectors: allotted vector count for descriptor rings |
| 1648 | * |
| 1649 | * This function maps descriptor rings to the queue-specific vectors |
| 1650 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 1651 | * one vector per ring/queue, but on a constrained vector budget, we |
| 1652 | * group the rings as "efficiently" as possible. You would add new |
| 1653 | * mapping configurations in here. |
| 1654 | **/ |
| 1655 | static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1656 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1657 | { |
| 1658 | int v_start = 0; |
| 1659 | int rxr_idx = 0, txr_idx = 0; |
| 1660 | int rxr_remaining = adapter->num_rx_queues; |
| 1661 | int txr_remaining = adapter->num_tx_queues; |
| 1662 | int i, j; |
| 1663 | int rqpv, tqpv; |
| 1664 | int err = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1665 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1666 | /* No mapping required if MSI-X is disabled. */ |
| 1667 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1668 | goto out; |
| 1669 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1670 | /* |
| 1671 | * The ideal configuration... |
| 1672 | * We have enough vectors to map one per queue. |
| 1673 | */ |
| 1674 | if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) { |
| 1675 | for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++) |
| 1676 | map_vector_to_rxq(adapter, v_start, rxr_idx); |
| 1677 | |
| 1678 | for (; txr_idx < txr_remaining; v_start++, txr_idx++) |
| 1679 | map_vector_to_txq(adapter, v_start, txr_idx); |
| 1680 | |
| 1681 | goto out; |
| 1682 | } |
| 1683 | |
| 1684 | /* |
| 1685 | * If we don't have enough vectors for a 1-to-1 |
| 1686 | * mapping, we'll have to group them so there are |
| 1687 | * multiple queues per vector. |
| 1688 | */ |
| 1689 | /* Re-adjusting *qpv takes care of the remainder. */ |
| 1690 | for (i = v_start; i < vectors; i++) { |
| 1691 | rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i); |
| 1692 | for (j = 0; j < rqpv; j++) { |
| 1693 | map_vector_to_rxq(adapter, i, rxr_idx); |
| 1694 | rxr_idx++; |
| 1695 | rxr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1696 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1697 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1698 | for (i = v_start; i < vectors; i++) { |
| 1699 | tqpv = DIV_ROUND_UP(txr_remaining, vectors - i); |
| 1700 | for (j = 0; j < tqpv; j++) { |
| 1701 | map_vector_to_txq(adapter, i, txr_idx); |
| 1702 | txr_idx++; |
| 1703 | txr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1704 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1705 | } |
| 1706 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1707 | out: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1708 | return err; |
| 1709 | } |
| 1710 | |
| 1711 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1712 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 1713 | * @adapter: board private structure |
| 1714 | * |
| 1715 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 1716 | * interrupts from the kernel. |
| 1717 | **/ |
| 1718 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 1719 | { |
| 1720 | struct net_device *netdev = adapter->netdev; |
| 1721 | irqreturn_t (*handler)(int, void *); |
| 1722 | int i, vector, q_vectors, err; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 1723 | int ri=0, ti=0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1724 | |
| 1725 | /* Decrement for Other and TCP Timer vectors */ |
| 1726 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1727 | |
| 1728 | /* Map the Tx/Rx rings to the vectors we were allotted. */ |
| 1729 | err = ixgbe_map_rings_to_vectors(adapter, q_vectors); |
| 1730 | if (err) |
| 1731 | goto out; |
| 1732 | |
| 1733 | #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \ |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1734 | (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \ |
| 1735 | &ixgbe_msix_clean_many) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1736 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1737 | handler = SET_HANDLER(adapter->q_vector[vector]); |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 1738 | |
| 1739 | if(handler == &ixgbe_msix_clean_rx) { |
| 1740 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1741 | netdev->name, "rx", ri++); |
| 1742 | } |
| 1743 | else if(handler == &ixgbe_msix_clean_tx) { |
| 1744 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1745 | netdev->name, "tx", ti++); |
| 1746 | } |
| 1747 | else |
| 1748 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1749 | netdev->name, "TxRx", vector); |
| 1750 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1751 | err = request_irq(adapter->msix_entries[vector].vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1752 | handler, 0, adapter->name[vector], |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1753 | adapter->q_vector[vector]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1754 | if (err) { |
| 1755 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1756 | "request_irq failed for MSIX interrupt " |
| 1757 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1758 | goto free_queue_irqs; |
| 1759 | } |
| 1760 | } |
| 1761 | |
| 1762 | sprintf(adapter->name[vector], "%s:lsc", netdev->name); |
| 1763 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1764 | ixgbe_msix_lsc, 0, adapter->name[vector], netdev); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1765 | if (err) { |
| 1766 | DPRINTK(PROBE, ERR, |
| 1767 | "request_irq for msix_lsc failed: %d\n", err); |
| 1768 | goto free_queue_irqs; |
| 1769 | } |
| 1770 | |
| 1771 | return 0; |
| 1772 | |
| 1773 | free_queue_irqs: |
| 1774 | for (i = vector - 1; i >= 0; i--) |
| 1775 | free_irq(adapter->msix_entries[--vector].vector, |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1776 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1777 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 1778 | pci_disable_msix(adapter->pdev); |
| 1779 | kfree(adapter->msix_entries); |
| 1780 | adapter->msix_entries = NULL; |
| 1781 | out: |
| 1782 | return err; |
| 1783 | } |
| 1784 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1785 | static void ixgbe_set_itr(struct ixgbe_adapter *adapter) |
| 1786 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1787 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1788 | u8 current_itr; |
| 1789 | u32 new_itr = q_vector->eitr; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1790 | struct ixgbe_ring *rx_ring = adapter->rx_ring[0]; |
| 1791 | struct ixgbe_ring *tx_ring = adapter->tx_ring[0]; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1792 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1793 | q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1794 | q_vector->tx_itr, |
| 1795 | tx_ring->total_packets, |
| 1796 | tx_ring->total_bytes); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1797 | q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1798 | q_vector->rx_itr, |
| 1799 | rx_ring->total_packets, |
| 1800 | rx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1801 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1802 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1803 | |
| 1804 | switch (current_itr) { |
| 1805 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1806 | case lowest_latency: |
| 1807 | new_itr = 100000; |
| 1808 | break; |
| 1809 | case low_latency: |
| 1810 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 1811 | break; |
| 1812 | case bulk_latency: |
| 1813 | new_itr = 8000; |
| 1814 | break; |
| 1815 | default: |
| 1816 | break; |
| 1817 | } |
| 1818 | |
| 1819 | if (new_itr != q_vector->eitr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1820 | /* do an exponential smoothing */ |
| 1821 | new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1822 | |
| 1823 | /* save the algorithm value here, not the smoothed one */ |
| 1824 | q_vector->eitr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1825 | |
| 1826 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1827 | } |
| 1828 | |
| 1829 | return; |
| 1830 | } |
| 1831 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1832 | /** |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1833 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 1834 | * @adapter: board private structure |
| 1835 | **/ |
| 1836 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter) |
| 1837 | { |
| 1838 | u32 mask; |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1839 | |
| 1840 | mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
David S. Miller | 6ab33d5 | 2008-11-20 16:44:00 -0800 | [diff] [blame] | 1841 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
| 1842 | mask |= IXGBE_EIMS_GPI_SDP1; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1843 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 1844 | mask |= IXGBE_EIMS_ECC; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1845 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 1846 | mask |= IXGBE_EIMS_GPI_SDP2; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 1847 | if (adapter->num_vfs) |
| 1848 | mask |= IXGBE_EIMS_MAILBOX; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1849 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1850 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 1851 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 1852 | mask |= IXGBE_EIMS_FLOW_DIR; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1853 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1854 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1855 | ixgbe_irq_enable_queues(adapter, ~0); |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1856 | IXGBE_WRITE_FLUSH(&adapter->hw); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 1857 | |
| 1858 | if (adapter->num_vfs > 32) { |
| 1859 | u32 eitrsel = (1 << (adapter->num_vfs - 32)) - 1; |
| 1860 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, eitrsel); |
| 1861 | } |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1862 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1863 | |
| 1864 | /** |
| 1865 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1866 | * @irq: interrupt number |
| 1867 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1868 | **/ |
| 1869 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 1870 | { |
| 1871 | struct net_device *netdev = data; |
| 1872 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1873 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1874 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1875 | u32 eicr; |
| 1876 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 1877 | /* |
| 1878 | * Workaround for silicon errata. Mask the interrupts |
| 1879 | * before the read of EICR. |
| 1880 | */ |
| 1881 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 1882 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1883 | /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read |
| 1884 | * therefore no explict interrupt disable is necessary */ |
| 1885 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 1886 | if (!eicr) { |
| 1887 | /* shared interrupt alert! |
| 1888 | * make sure interrupts are enabled because the read will |
| 1889 | * have disabled interrupts due to EIAM */ |
| 1890 | ixgbe_irq_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1891 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 1892 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1893 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1894 | if (eicr & IXGBE_EICR_LSC) |
| 1895 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1896 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1897 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 1898 | ixgbe_check_sfp_event(adapter, eicr); |
| 1899 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1900 | ixgbe_check_fan_failure(adapter, eicr); |
| 1901 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1902 | if (napi_schedule_prep(&(q_vector->napi))) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 1903 | adapter->tx_ring[0]->total_packets = 0; |
| 1904 | adapter->tx_ring[0]->total_bytes = 0; |
| 1905 | adapter->rx_ring[0]->total_packets = 0; |
| 1906 | adapter->rx_ring[0]->total_bytes = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1907 | /* would disable interrupts here but EIAM disabled it */ |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1908 | __napi_schedule(&(q_vector->napi)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1909 | } |
| 1910 | |
| 1911 | return IRQ_HANDLED; |
| 1912 | } |
| 1913 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1914 | static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter) |
| 1915 | { |
| 1916 | int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1917 | |
| 1918 | for (i = 0; i < q_vectors; i++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1919 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1920 | bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES); |
| 1921 | bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES); |
| 1922 | q_vector->rxr_count = 0; |
| 1923 | q_vector->txr_count = 0; |
| 1924 | } |
| 1925 | } |
| 1926 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1927 | /** |
| 1928 | * ixgbe_request_irq - initialize interrupts |
| 1929 | * @adapter: board private structure |
| 1930 | * |
| 1931 | * Attempts to configure interrupts using the best available |
| 1932 | * capabilities of the hardware and kernel. |
| 1933 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1934 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1935 | { |
| 1936 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1937 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1938 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1939 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 1940 | err = ixgbe_request_msix_irqs(adapter); |
| 1941 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1942 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1943 | netdev->name, netdev); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1944 | } else { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1945 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1946 | netdev->name, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1947 | } |
| 1948 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1949 | if (err) |
| 1950 | DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err); |
| 1951 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1952 | return err; |
| 1953 | } |
| 1954 | |
| 1955 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 1956 | { |
| 1957 | struct net_device *netdev = adapter->netdev; |
| 1958 | |
| 1959 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1960 | int i, q_vectors; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1961 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1962 | q_vectors = adapter->num_msix_vectors; |
| 1963 | |
| 1964 | i = q_vectors - 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1965 | free_irq(adapter->msix_entries[i].vector, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1966 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1967 | i--; |
| 1968 | for (; i >= 0; i--) { |
| 1969 | free_irq(adapter->msix_entries[i].vector, |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1970 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1971 | } |
| 1972 | |
| 1973 | ixgbe_reset_q_vectors(adapter); |
| 1974 | } else { |
| 1975 | free_irq(adapter->pdev->irq, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1976 | } |
| 1977 | } |
| 1978 | |
| 1979 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1980 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 1981 | * @adapter: board private structure |
| 1982 | **/ |
| 1983 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 1984 | { |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1985 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1986 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
| 1987 | } else { |
| 1988 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 1989 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1990 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 1991 | if (adapter->num_vfs > 32) |
| 1992 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITRSEL, 0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1993 | } |
| 1994 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 1995 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 1996 | int i; |
| 1997 | for (i = 0; i < adapter->num_msix_vectors; i++) |
| 1998 | synchronize_irq(adapter->msix_entries[i].vector); |
| 1999 | } else { |
| 2000 | synchronize_irq(adapter->pdev->irq); |
| 2001 | } |
| 2002 | } |
| 2003 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 2004 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2005 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 2006 | * |
| 2007 | **/ |
| 2008 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 2009 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2010 | struct ixgbe_hw *hw = &adapter->hw; |
| 2011 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2012 | IXGBE_WRITE_REG(hw, IXGBE_EITR(0), |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 2013 | EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2014 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2015 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 2016 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2017 | |
| 2018 | map_vector_to_rxq(adapter, 0, 0); |
| 2019 | map_vector_to_txq(adapter, 0, 0); |
| 2020 | |
| 2021 | DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2022 | } |
| 2023 | |
| 2024 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2025 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2026 | * @adapter: board private structure |
| 2027 | * |
| 2028 | * Configure the Tx unit of the MAC after a reset. |
| 2029 | **/ |
| 2030 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 2031 | { |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 2032 | u64 tdba; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2033 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2034 | u32 i, j, tdlen, txctrl; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2035 | |
| 2036 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 2037 | for (i = 0; i < adapter->num_tx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2038 | struct ixgbe_ring *ring = adapter->tx_ring[i]; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 2039 | j = ring->reg_idx; |
| 2040 | tdba = ring->dma; |
| 2041 | tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2042 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j), |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2043 | (tdba & DMA_BIT_MASK(32))); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2044 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32)); |
| 2045 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen); |
| 2046 | IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0); |
| 2047 | IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2048 | adapter->tx_ring[i]->head = IXGBE_TDH(j); |
| 2049 | adapter->tx_ring[i]->tail = IXGBE_TDT(j); |
Peter P Waskiewicz Jr | 84f62d4 | 2009-09-30 12:07:16 +0000 | [diff] [blame] | 2050 | /* |
| 2051 | * Disable Tx Head Writeback RO bit, since this hoses |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2052 | * bookkeeping if things aren't delivered in order. |
| 2053 | */ |
Peter P Waskiewicz Jr | 84f62d4 | 2009-09-30 12:07:16 +0000 | [diff] [blame] | 2054 | switch (hw->mac.type) { |
| 2055 | case ixgbe_mac_82598EB: |
| 2056 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j)); |
| 2057 | break; |
| 2058 | case ixgbe_mac_82599EB: |
| 2059 | default: |
| 2060 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(j)); |
| 2061 | break; |
| 2062 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2063 | txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN; |
Peter P Waskiewicz Jr | 84f62d4 | 2009-09-30 12:07:16 +0000 | [diff] [blame] | 2064 | switch (hw->mac.type) { |
| 2065 | case ixgbe_mac_82598EB: |
| 2066 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl); |
| 2067 | break; |
| 2068 | case ixgbe_mac_82599EB: |
| 2069 | default: |
| 2070 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(j), txctrl); |
| 2071 | break; |
| 2072 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2073 | } |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 2074 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2075 | if (hw->mac.type == ixgbe_mac_82599EB) { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 2076 | u32 rttdcs; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2077 | u32 mask; |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 2078 | |
| 2079 | /* disable the arbiter while setting MTQC */ |
| 2080 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 2081 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 2082 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 2083 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2084 | /* set transmit pool layout */ |
| 2085 | mask = (IXGBE_FLAG_SRIOV_ENABLED | IXGBE_FLAG_DCB_ENABLED); |
| 2086 | switch (adapter->flags & mask) { |
| 2087 | |
| 2088 | case (IXGBE_FLAG_SRIOV_ENABLED): |
| 2089 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, |
| 2090 | (IXGBE_MTQC_VT_ENA | IXGBE_MTQC_64VF)); |
| 2091 | break; |
| 2092 | |
| 2093 | case (IXGBE_FLAG_DCB_ENABLED): |
| 2094 | /* We enable 8 traffic classes, DCB only */ |
| 2095 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, |
| 2096 | (IXGBE_MTQC_RT_ENA | IXGBE_MTQC_8TC_8TQ)); |
| 2097 | break; |
| 2098 | |
| 2099 | default: |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 2100 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2101 | break; |
| 2102 | } |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 2103 | |
| 2104 | /* re-eable the arbiter */ |
| 2105 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 2106 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2107 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2108 | } |
| 2109 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2110 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2111 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2112 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
| 2113 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2114 | { |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2115 | u32 srrctl; |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2116 | int index; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2117 | struct ixgbe_ring_feature *feature = adapter->ring_feature; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2118 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2119 | index = rx_ring->reg_idx; |
| 2120 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 2121 | unsigned long mask; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2122 | mask = (unsigned long) feature[RING_F_RSS].mask; |
Alexander Duyck | 3be1adf | 2008-08-30 00:29:10 -0700 | [diff] [blame] | 2123 | index = index & mask; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2124 | } |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2125 | srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index)); |
| 2126 | |
| 2127 | srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2128 | srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK; |
| 2129 | |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2130 | srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) & |
| 2131 | IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2132 | |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 2133 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2134 | #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER |
| 2135 | srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 2136 | #else |
| 2137 | srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 2138 | #endif |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2139 | srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2140 | } else { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2141 | srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >> |
| 2142 | IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2143 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2144 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2145 | |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2146 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl); |
| 2147 | } |
| 2148 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2149 | static u32 ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
| 2150 | { |
| 2151 | u32 mrqc = 0; |
| 2152 | int mask; |
| 2153 | |
| 2154 | if (!(adapter->hw.mac.type == ixgbe_mac_82599EB)) |
| 2155 | return mrqc; |
| 2156 | |
| 2157 | mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED |
| 2158 | #ifdef CONFIG_IXGBE_DCB |
| 2159 | | IXGBE_FLAG_DCB_ENABLED |
| 2160 | #endif |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2161 | | IXGBE_FLAG_SRIOV_ENABLED |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2162 | ); |
| 2163 | |
| 2164 | switch (mask) { |
| 2165 | case (IXGBE_FLAG_RSS_ENABLED): |
| 2166 | mrqc = IXGBE_MRQC_RSSEN; |
| 2167 | break; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2168 | case (IXGBE_FLAG_SRIOV_ENABLED): |
| 2169 | mrqc = IXGBE_MRQC_VMDQEN; |
| 2170 | break; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2171 | #ifdef CONFIG_IXGBE_DCB |
| 2172 | case (IXGBE_FLAG_DCB_ENABLED): |
| 2173 | mrqc = IXGBE_MRQC_RT8TCEN; |
| 2174 | break; |
| 2175 | #endif /* CONFIG_IXGBE_DCB */ |
| 2176 | default: |
| 2177 | break; |
| 2178 | } |
| 2179 | |
| 2180 | return mrqc; |
| 2181 | } |
| 2182 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2183 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2184 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 2185 | * @adapter: address of board private structure |
| 2186 | * @index: index of ring to set |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2187 | **/ |
Mallikarjuna R Chilakala | edd2ea55 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2188 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, int index) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2189 | { |
| 2190 | struct ixgbe_ring *rx_ring; |
| 2191 | struct ixgbe_hw *hw = &adapter->hw; |
| 2192 | int j; |
| 2193 | u32 rscctrl; |
Mallikarjuna R Chilakala | edd2ea55 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2194 | int rx_buf_len; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2195 | |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2196 | rx_ring = adapter->rx_ring[index]; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2197 | j = rx_ring->reg_idx; |
Mallikarjuna R Chilakala | edd2ea55 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2198 | rx_buf_len = rx_ring->rx_buf_len; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2199 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(j)); |
| 2200 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 2201 | /* |
| 2202 | * we must limit the number of descriptors so that the |
| 2203 | * total size of max desc * buf_len is not greater |
| 2204 | * than 65535 |
| 2205 | */ |
| 2206 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
| 2207 | #if (MAX_SKB_FRAGS > 16) |
| 2208 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2209 | #elif (MAX_SKB_FRAGS > 8) |
| 2210 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
| 2211 | #elif (MAX_SKB_FRAGS > 4) |
| 2212 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
| 2213 | #else |
| 2214 | rscctrl |= IXGBE_RSCCTL_MAXDESC_1; |
| 2215 | #endif |
| 2216 | } else { |
| 2217 | if (rx_buf_len < IXGBE_RXBUFFER_4096) |
| 2218 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2219 | else if (rx_buf_len < IXGBE_RXBUFFER_8192) |
| 2220 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
| 2221 | else |
| 2222 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
| 2223 | } |
| 2224 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(j), rscctrl); |
| 2225 | } |
| 2226 | |
| 2227 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2228 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2229 | * @adapter: board private structure |
| 2230 | * |
| 2231 | * Configure the Rx unit of the MAC after a reset. |
| 2232 | **/ |
| 2233 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 2234 | { |
| 2235 | u64 rdba; |
| 2236 | struct ixgbe_hw *hw = &adapter->hw; |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2237 | struct ixgbe_ring *rx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2238 | struct net_device *netdev = adapter->netdev; |
| 2239 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2240 | int i, j; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2241 | u32 rdlen, rxctrl, rxcsum; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2242 | static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D, |
| 2243 | 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE, |
| 2244 | 0x6A3E67EA, 0x14364D17, 0x3BED200D}; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2245 | u32 fctrl, hlreg0; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2246 | u32 reta = 0, mrqc = 0; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2247 | u32 rdrxctl; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2248 | int rx_buf_len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2249 | |
| 2250 | /* Decide whether to use packet split mode or not */ |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2251 | /* Do not use packet split if we're in SR-IOV Mode */ |
| 2252 | if (!adapter->num_vfs) |
| 2253 | adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2254 | |
| 2255 | /* Set the RX buffer length according to the mode */ |
| 2256 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2257 | rx_buf_len = IXGBE_RX_HDR_SIZE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2258 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2259 | /* PSRTYPE must be initialized in 82599 */ |
| 2260 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
| 2261 | IXGBE_PSRTYPE_UDPHDR | |
| 2262 | IXGBE_PSRTYPE_IPV4HDR | |
Yi Zou | dfa12f0 | 2009-05-07 10:39:35 +0000 | [diff] [blame] | 2263 | IXGBE_PSRTYPE_IPV6HDR | |
| 2264 | IXGBE_PSRTYPE_L2HDR; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2265 | IXGBE_WRITE_REG(hw, |
| 2266 | IXGBE_PSRTYPE(adapter->num_vfs), |
| 2267 | psrtype); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2268 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2269 | } else { |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 2270 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) && |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2271 | (netdev->mtu <= ETH_DATA_LEN)) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2272 | rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2273 | else |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2274 | rx_buf_len = ALIGN(max_frame, 1024); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2275 | } |
| 2276 | |
| 2277 | fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL); |
| 2278 | fctrl |= IXGBE_FCTRL_BAM; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2279 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2280 | fctrl |= IXGBE_FCTRL_PMCF; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2281 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl); |
| 2282 | |
| 2283 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
| 2284 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 2285 | hlreg0 &= ~IXGBE_HLREG0_JUMBOEN; |
| 2286 | else |
| 2287 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2288 | #ifdef IXGBE_FCOE |
Yi Zou | f34c5c8 | 2009-08-14 12:42:17 +0000 | [diff] [blame] | 2289 | if (netdev->features & NETIF_F_FCOE_MTU) |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2290 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
| 2291 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2292 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 2293 | |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2294 | rdlen = adapter->rx_ring[0]->count * sizeof(union ixgbe_adv_rx_desc); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2295 | /* disable receives while setting up the descriptors */ |
| 2296 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 2297 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
| 2298 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2299 | /* |
| 2300 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 2301 | * the Base and Length of the Rx Descriptor Ring |
| 2302 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2303 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2304 | rx_ring = adapter->rx_ring[i]; |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2305 | rdba = rx_ring->dma; |
| 2306 | j = rx_ring->reg_idx; |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2307 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_BIT_MASK(32))); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2308 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32)); |
| 2309 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen); |
| 2310 | IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0); |
| 2311 | IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0); |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2312 | rx_ring->head = IXGBE_RDH(j); |
| 2313 | rx_ring->tail = IXGBE_RDT(j); |
| 2314 | rx_ring->rx_buf_len = rx_buf_len; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2315 | |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 2316 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) |
| 2317 | rx_ring->flags |= IXGBE_RING_RX_PS_ENABLED; |
Peter P Waskiewicz Jr | 1b3ff02 | 2009-09-14 07:47:27 +0000 | [diff] [blame] | 2318 | else |
| 2319 | rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2320 | |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2321 | #ifdef IXGBE_FCOE |
Yi Zou | f34c5c8 | 2009-08-14 12:42:17 +0000 | [diff] [blame] | 2322 | if (netdev->features & NETIF_F_FCOE_MTU) { |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2323 | struct ixgbe_ring_feature *f; |
| 2324 | f = &adapter->ring_feature[RING_F_FCOE]; |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 2325 | if ((i >= f->mask) && (i < f->mask + f->indices)) { |
| 2326 | rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED; |
| 2327 | if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE) |
| 2328 | rx_ring->rx_buf_len = |
| 2329 | IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 2330 | } |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2331 | } |
| 2332 | |
| 2333 | #endif /* IXGBE_FCOE */ |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2334 | ixgbe_configure_srrctl(adapter, rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2335 | } |
| 2336 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2337 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 2338 | /* |
| 2339 | * For VMDq support of different descriptor types or |
| 2340 | * buffer sizes through the use of multiple SRRCTL |
| 2341 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 2342 | * |
| 2343 | * also, the manual doesn't mention it clearly but DCA hints |
| 2344 | * will only use queue 0's tags unless this bit is set. Side |
| 2345 | * effects of setting this bit are only that SRRCTL must be |
| 2346 | * fully programmed [0..15] |
| 2347 | */ |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2348 | rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 2349 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 2350 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2351 | } |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2352 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2353 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 2354 | u32 vt_reg_bits; |
| 2355 | u32 reg_offset, vf_shift; |
| 2356 | u32 vmdctl = IXGBE_READ_REG(hw, IXGBE_VT_CTL); |
| 2357 | vt_reg_bits = IXGBE_VMD_CTL_VMDQ_EN |
| 2358 | | IXGBE_VT_CTL_REPLEN; |
| 2359 | vt_reg_bits |= (adapter->num_vfs << |
| 2360 | IXGBE_VT_CTL_POOL_SHIFT); |
| 2361 | IXGBE_WRITE_REG(hw, IXGBE_VT_CTL, vmdctl | vt_reg_bits); |
| 2362 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, 0); |
| 2363 | |
| 2364 | vf_shift = adapter->num_vfs % 32; |
| 2365 | reg_offset = adapter->num_vfs / 32; |
| 2366 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(0), 0); |
| 2367 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(1), 0); |
| 2368 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(0), 0); |
| 2369 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(1), 0); |
| 2370 | /* Enable only the PF's pool for Tx/Rx */ |
| 2371 | IXGBE_WRITE_REG(hw, IXGBE_VFRE(reg_offset), (1 << vf_shift)); |
| 2372 | IXGBE_WRITE_REG(hw, IXGBE_VFTE(reg_offset), (1 << vf_shift)); |
| 2373 | IXGBE_WRITE_REG(hw, IXGBE_PFDTXGSWC, IXGBE_PFDTXGSWC_VT_LBEN); |
| 2374 | ixgbe_set_vmolr(hw, adapter->num_vfs); |
| 2375 | } |
| 2376 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2377 | /* Program MRQC for the distribution of queues */ |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2378 | mrqc = ixgbe_setup_mrqc(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2379 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2380 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2381 | /* Fill out redirection table */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2382 | for (i = 0, j = 0; i < 128; i++, j++) { |
| 2383 | if (j == adapter->ring_feature[RING_F_RSS].indices) |
| 2384 | j = 0; |
| 2385 | /* reta = 4-byte sliding window of |
| 2386 | * 0x00..(indices-1)(indices-1)00..etc. */ |
| 2387 | reta = (reta << 8) | (j * 0x11); |
| 2388 | if ((i & 3) == 3) |
| 2389 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2390 | } |
| 2391 | |
| 2392 | /* Fill out hash function seeds */ |
| 2393 | for (i = 0; i < 10; i++) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2394 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2395 | |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2396 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2397 | mrqc |= IXGBE_MRQC_RSSEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2398 | /* Perform hash on these packet types */ |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2399 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
| 2400 | | IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
| 2401 | | IXGBE_MRQC_RSS_FIELD_IPV4_UDP |
| 2402 | | IXGBE_MRQC_RSS_FIELD_IPV6 |
| 2403 | | IXGBE_MRQC_RSS_FIELD_IPV6_TCP |
| 2404 | | IXGBE_MRQC_RSS_FIELD_IPV6_UDP; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2405 | } |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2406 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2407 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2408 | if (adapter->num_vfs) { |
| 2409 | u32 reg; |
| 2410 | |
| 2411 | /* Map PF MAC address in RAR Entry 0 to first pool |
| 2412 | * following VFs */ |
| 2413 | hw->mac.ops.set_vmdq(hw, 0, adapter->num_vfs); |
| 2414 | |
| 2415 | /* Set up VF register offsets for selected VT Mode, i.e. |
| 2416 | * 64 VFs for SR-IOV */ |
| 2417 | reg = IXGBE_READ_REG(hw, IXGBE_GCR_EXT); |
| 2418 | reg |= IXGBE_GCR_EXT_SRIOV; |
| 2419 | IXGBE_WRITE_REG(hw, IXGBE_GCR_EXT, reg); |
| 2420 | } |
| 2421 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2422 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 2423 | |
| 2424 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED || |
| 2425 | adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) { |
| 2426 | /* Disable indicating checksum in descriptor, enables |
| 2427 | * RSS hash */ |
| 2428 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 2429 | } |
| 2430 | if (!(rxcsum & IXGBE_RXCSUM_PCSD)) { |
| 2431 | /* Enable IPv4 payload checksum for UDP fragments |
| 2432 | * if PCSD is not set */ |
| 2433 | rxcsum |= IXGBE_RXCSUM_IPPCSE; |
| 2434 | } |
| 2435 | |
| 2436 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2437 | |
| 2438 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2439 | rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 2440 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2441 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2442 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 2443 | } |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2444 | |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 2445 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2446 | /* Enable 82599 HW-RSC */ |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2447 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | edd2ea55 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2448 | ixgbe_configure_rscctl(adapter, i); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2449 | |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2450 | /* Disable RSC for ACK packets */ |
| 2451 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 2452 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 2453 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2454 | } |
| 2455 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2456 | static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 2457 | { |
| 2458 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2459 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 2460 | int pool_ndx = adapter->num_vfs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2461 | |
| 2462 | /* add VID to filter table */ |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 2463 | hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2464 | } |
| 2465 | |
| 2466 | static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 2467 | { |
| 2468 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2469 | struct ixgbe_hw *hw = &adapter->hw; |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 2470 | int pool_ndx = adapter->num_vfs; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2471 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2472 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2473 | ixgbe_irq_disable(adapter); |
| 2474 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2475 | vlan_group_set_device(adapter->vlgrp, vid, NULL); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2476 | |
| 2477 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2478 | ixgbe_irq_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2479 | |
| 2480 | /* remove VID from filter table */ |
Greg Rose | 1ada1b1 | 2010-01-22 22:45:43 +0000 | [diff] [blame] | 2481 | hw->mac.ops.set_vfta(&adapter->hw, vid, pool_ndx, false); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2482 | } |
| 2483 | |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2484 | static void ixgbe_vlan_rx_register(struct net_device *netdev, |
| 2485 | struct vlan_group *grp) |
| 2486 | { |
| 2487 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2488 | u32 ctrl; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2489 | int i, j; |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2490 | |
| 2491 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2492 | ixgbe_irq_disable(adapter); |
| 2493 | adapter->vlgrp = grp; |
| 2494 | |
| 2495 | /* |
| 2496 | * For a DCB driver, always enable VLAN tag stripping so we can |
| 2497 | * still receive traffic from a DCB-enabled host even if we're |
| 2498 | * not in DCB mode. |
| 2499 | */ |
| 2500 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL); |
Alexander Duyck | dc63d37 | 2009-11-23 06:32:57 +0000 | [diff] [blame] | 2501 | |
| 2502 | /* Disable CFI check */ |
| 2503 | ctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2504 | |
| 2505 | /* enable VLAN tag stripping */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2506 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | dc63d37 | 2009-11-23 06:32:57 +0000 | [diff] [blame] | 2507 | ctrl |= IXGBE_VLNCTRL_VME; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2508 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2509 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | dc63d37 | 2009-11-23 06:32:57 +0000 | [diff] [blame] | 2510 | u32 ctrl; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2511 | j = adapter->rx_ring[i]->reg_idx; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2512 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j)); |
| 2513 | ctrl |= IXGBE_RXDCTL_VME; |
| 2514 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl); |
| 2515 | } |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2516 | } |
Alexander Duyck | dc63d37 | 2009-11-23 06:32:57 +0000 | [diff] [blame] | 2517 | |
| 2518 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl); |
| 2519 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2520 | ixgbe_vlan_rx_add_vid(netdev, 0); |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2521 | |
| 2522 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2523 | ixgbe_irq_enable(adapter); |
| 2524 | } |
| 2525 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2526 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 2527 | { |
| 2528 | ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 2529 | |
| 2530 | if (adapter->vlgrp) { |
| 2531 | u16 vid; |
| 2532 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
| 2533 | if (!vlan_group_get_device(adapter->vlgrp, vid)) |
| 2534 | continue; |
| 2535 | ixgbe_vlan_rx_add_vid(adapter->netdev, vid); |
| 2536 | } |
| 2537 | } |
| 2538 | } |
| 2539 | |
| 2540 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2541 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2542 | * @netdev: network interface device structure |
| 2543 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2544 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 2545 | * address list or the network interface flags are updated. This routine is |
| 2546 | * responsible for configuring the hardware for proper unicast, multicast and |
| 2547 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2548 | **/ |
Greg Rose | 7f87047 | 2010-01-09 02:25:29 +0000 | [diff] [blame] | 2549 | void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2550 | { |
| 2551 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2552 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2553 | u32 fctrl, vlnctrl; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2554 | |
| 2555 | /* Check for Promiscuous and All Multicast modes */ |
| 2556 | |
| 2557 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2558 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2559 | |
| 2560 | if (netdev->flags & IFF_PROMISC) { |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2561 | hw->addr_ctrl.user_set_promisc = 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2562 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2563 | vlnctrl &= ~IXGBE_VLNCTRL_VFE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2564 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2565 | if (netdev->flags & IFF_ALLMULTI) { |
| 2566 | fctrl |= IXGBE_FCTRL_MPE; |
| 2567 | fctrl &= ~IXGBE_FCTRL_UPE; |
| 2568 | } else { |
| 2569 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
| 2570 | } |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2571 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2572 | hw->addr_ctrl.user_set_promisc = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2573 | } |
| 2574 | |
| 2575 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2576 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2577 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2578 | /* reprogram secondary unicast list */ |
Jiri Pirko | 32e7bfc | 2010-01-25 13:36:10 -0800 | [diff] [blame] | 2579 | hw->mac.ops.update_uc_addr_list(hw, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2580 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2581 | /* reprogram multicast list */ |
Jiri Pirko | 2853eb8 | 2010-03-23 22:58:01 +0000 | [diff] [blame^] | 2582 | hw->mac.ops.update_mc_addr_list(hw, netdev); |
| 2583 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2584 | if (adapter->num_vfs) |
| 2585 | ixgbe_restore_vf_multicasts(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2586 | } |
| 2587 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2588 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 2589 | { |
| 2590 | int q_idx; |
| 2591 | struct ixgbe_q_vector *q_vector; |
| 2592 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2593 | |
| 2594 | /* legacy and MSI only use one vector */ |
| 2595 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 2596 | q_vectors = 1; |
| 2597 | |
| 2598 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2599 | struct napi_struct *napi; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2600 | q_vector = adapter->q_vector[q_idx]; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2601 | napi = &q_vector->napi; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2602 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2603 | if (!q_vector->rxr_count || !q_vector->txr_count) { |
| 2604 | if (q_vector->txr_count == 1) |
| 2605 | napi->poll = &ixgbe_clean_txonly; |
| 2606 | else if (q_vector->rxr_count == 1) |
| 2607 | napi->poll = &ixgbe_clean_rxonly; |
| 2608 | } |
| 2609 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2610 | |
| 2611 | napi_enable(napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2612 | } |
| 2613 | } |
| 2614 | |
| 2615 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 2616 | { |
| 2617 | int q_idx; |
| 2618 | struct ixgbe_q_vector *q_vector; |
| 2619 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2620 | |
| 2621 | /* legacy and MSI only use one vector */ |
| 2622 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 2623 | q_vectors = 1; |
| 2624 | |
| 2625 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2626 | q_vector = adapter->q_vector[q_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2627 | napi_disable(&q_vector->napi); |
| 2628 | } |
| 2629 | } |
| 2630 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 2631 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2632 | /* |
| 2633 | * ixgbe_configure_dcb - Configure DCB hardware |
| 2634 | * @adapter: ixgbe adapter struct |
| 2635 | * |
| 2636 | * This is called by the driver on open to configure the DCB hardware. |
| 2637 | * This is also called by the gennetlink interface when reconfiguring |
| 2638 | * the DCB state. |
| 2639 | */ |
| 2640 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 2641 | { |
| 2642 | struct ixgbe_hw *hw = &adapter->hw; |
| 2643 | u32 txdctl, vlnctrl; |
| 2644 | int i, j; |
| 2645 | |
| 2646 | ixgbe_dcb_check_config(&adapter->dcb_cfg); |
| 2647 | ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG); |
| 2648 | ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG); |
| 2649 | |
| 2650 | /* reconfigure the hardware */ |
| 2651 | ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg); |
| 2652 | |
| 2653 | for (i = 0; i < adapter->num_tx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2654 | j = adapter->tx_ring[i]->reg_idx; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2655 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
| 2656 | /* PThresh workaround for Tx hang with DFP enabled. */ |
| 2657 | txdctl |= 32; |
| 2658 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
| 2659 | } |
| 2660 | /* Enable VLAN tag insert/strip */ |
| 2661 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2662 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 2663 | vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE; |
| 2664 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2665 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 2666 | } else if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2667 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 2668 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2669 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 2670 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2671 | j = adapter->rx_ring[i]->reg_idx; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2672 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 2673 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 2674 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 2675 | } |
| 2676 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2677 | hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true); |
| 2678 | } |
| 2679 | |
| 2680 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2681 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 2682 | { |
| 2683 | struct net_device *netdev = adapter->netdev; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2684 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2685 | int i; |
| 2686 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2687 | ixgbe_set_rx_mode(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2688 | |
| 2689 | ixgbe_restore_vlan(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 2690 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2691 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Yi Zou | b352e40 | 2009-11-06 12:55:38 +0000 | [diff] [blame] | 2692 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2693 | netif_set_gso_max_size(netdev, 32768); |
| 2694 | else |
| 2695 | netif_set_gso_max_size(netdev, 65536); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2696 | ixgbe_configure_dcb(adapter); |
| 2697 | } else { |
| 2698 | netif_set_gso_max_size(netdev, 65536); |
| 2699 | } |
| 2700 | #else |
| 2701 | netif_set_gso_max_size(netdev, 65536); |
| 2702 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2703 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 2704 | #ifdef IXGBE_FCOE |
| 2705 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 2706 | ixgbe_configure_fcoe(adapter); |
| 2707 | |
| 2708 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2709 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 2710 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2711 | adapter->tx_ring[i]->atr_sample_rate = |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2712 | adapter->atr_sample_rate; |
| 2713 | ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc); |
| 2714 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 2715 | ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc); |
| 2716 | } |
| 2717 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2718 | ixgbe_configure_tx(adapter); |
| 2719 | ixgbe_configure_rx(adapter); |
| 2720 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2721 | ixgbe_alloc_rx_buffers(adapter, adapter->rx_ring[i], |
| 2722 | (adapter->rx_ring[i]->count - 1)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2723 | } |
| 2724 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2725 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 2726 | { |
| 2727 | switch (hw->phy.type) { |
| 2728 | case ixgbe_phy_sfp_avago: |
| 2729 | case ixgbe_phy_sfp_ftl: |
| 2730 | case ixgbe_phy_sfp_intel: |
| 2731 | case ixgbe_phy_sfp_unknown: |
| 2732 | case ixgbe_phy_tw_tyco: |
| 2733 | case ixgbe_phy_tw_unknown: |
| 2734 | return true; |
| 2735 | default: |
| 2736 | return false; |
| 2737 | } |
| 2738 | } |
| 2739 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2740 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2741 | * ixgbe_sfp_link_config - set up SFP+ link |
| 2742 | * @adapter: pointer to private adapter struct |
| 2743 | **/ |
| 2744 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 2745 | { |
| 2746 | struct ixgbe_hw *hw = &adapter->hw; |
| 2747 | |
| 2748 | if (hw->phy.multispeed_fiber) { |
| 2749 | /* |
| 2750 | * In multispeed fiber setups, the device may not have |
| 2751 | * had a physical connection when the driver loaded. |
| 2752 | * If that's the case, the initial link configuration |
| 2753 | * couldn't get the MAC into 10G or 1G mode, so we'll |
| 2754 | * never have a link status change interrupt fire. |
| 2755 | * We need to try and force an autonegotiation |
| 2756 | * session, then bring up link. |
| 2757 | */ |
| 2758 | hw->mac.ops.setup_sfp(hw); |
| 2759 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK)) |
| 2760 | schedule_work(&adapter->multispeed_fiber_task); |
| 2761 | } else { |
| 2762 | /* |
| 2763 | * Direct Attach Cu and non-multispeed fiber modules |
| 2764 | * still need to be configured properly prior to |
| 2765 | * attempting link. |
| 2766 | */ |
| 2767 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK)) |
| 2768 | schedule_work(&adapter->sfp_config_module_task); |
| 2769 | } |
| 2770 | } |
| 2771 | |
| 2772 | /** |
| 2773 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2774 | * @hw: pointer to private hardware struct |
| 2775 | * |
| 2776 | * Returns 0 on success, negative on failure |
| 2777 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2778 | static int ixgbe_non_sfp_link_config(struct ixgbe_hw *hw) |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2779 | { |
| 2780 | u32 autoneg; |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 2781 | bool negotiation, link_up = false; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2782 | u32 ret = IXGBE_ERR_LINK_SETUP; |
| 2783 | |
| 2784 | if (hw->mac.ops.check_link) |
| 2785 | ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 2786 | |
| 2787 | if (ret) |
| 2788 | goto link_cfg_out; |
| 2789 | |
| 2790 | if (hw->mac.ops.get_link_capabilities) |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 2791 | ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2792 | if (ret) |
| 2793 | goto link_cfg_out; |
| 2794 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 2795 | if (hw->mac.ops.setup_link) |
| 2796 | ret = hw->mac.ops.setup_link(hw, autoneg, negotiation, link_up); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2797 | link_cfg_out: |
| 2798 | return ret; |
| 2799 | } |
| 2800 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2801 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 2802 | static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 2803 | int rxr) |
| 2804 | { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2805 | int j = adapter->rx_ring[rxr]->reg_idx; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2806 | int k; |
| 2807 | |
| 2808 | for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) { |
| 2809 | if (IXGBE_READ_REG(&adapter->hw, |
| 2810 | IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE) |
| 2811 | break; |
| 2812 | else |
| 2813 | msleep(1); |
| 2814 | } |
| 2815 | if (k >= IXGBE_MAX_RX_DESC_POLL) { |
| 2816 | DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d " |
| 2817 | "not set within the polling period\n", rxr); |
| 2818 | } |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2819 | ixgbe_release_rx_desc(&adapter->hw, adapter->rx_ring[rxr], |
| 2820 | (adapter->rx_ring[rxr]->count - 1)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2821 | } |
| 2822 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2823 | static int ixgbe_up_complete(struct ixgbe_adapter *adapter) |
| 2824 | { |
| 2825 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2826 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2827 | int i, j = 0; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2828 | int num_rx_rings = adapter->num_rx_queues; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2829 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2830 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2831 | u32 txdctl, rxdctl, mhadd; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2832 | u32 dmatxctl; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2833 | u32 gpie; |
Greg Rose | c920569 | 2010-01-22 22:46:22 +0000 | [diff] [blame] | 2834 | u32 ctrl_ext; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2835 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 2836 | ixgbe_get_hw_control(adapter); |
| 2837 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2838 | if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) || |
| 2839 | (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2840 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2841 | gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2842 | IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2843 | } else { |
| 2844 | /* MSI only */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2845 | gpie = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2846 | } |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2847 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 2848 | gpie &= ~IXGBE_GPIE_VTMODE_MASK; |
| 2849 | gpie |= IXGBE_GPIE_VTMODE_64; |
| 2850 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2851 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 2852 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 2853 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2854 | } |
| 2855 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 2856 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2857 | /* |
| 2858 | * use EIAM to auto-mask when MSI-X interrupt is asserted |
| 2859 | * this saves a register write for every interrupt |
| 2860 | */ |
| 2861 | switch (hw->mac.type) { |
| 2862 | case ixgbe_mac_82598EB: |
| 2863 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
| 2864 | break; |
| 2865 | default: |
| 2866 | case ixgbe_mac_82599EB: |
| 2867 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); |
| 2868 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); |
| 2869 | break; |
| 2870 | } |
| 2871 | } else { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2872 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 2873 | * specifically only auto mask tx and rx interrupts */ |
| 2874 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2875 | } |
| 2876 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2877 | /* Enable fan failure interrupt if media type is copper */ |
| 2878 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 2879 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 2880 | gpie |= IXGBE_SDP1_GPIEN; |
| 2881 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2882 | } |
| 2883 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2884 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2885 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 2886 | gpie |= IXGBE_SDP1_GPIEN; |
| 2887 | gpie |= IXGBE_SDP2_GPIEN; |
| 2888 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2889 | } |
| 2890 | |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2891 | #ifdef IXGBE_FCOE |
| 2892 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
Yi Zou | f34c5c8 | 2009-08-14 12:42:17 +0000 | [diff] [blame] | 2893 | if ((netdev->features & NETIF_F_FCOE_MTU) && |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2894 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 2895 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 2896 | |
| 2897 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2898 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2899 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 2900 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 2901 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 2902 | |
| 2903 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
| 2904 | } |
| 2905 | |
| 2906 | for (i = 0; i < adapter->num_tx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2907 | j = adapter->tx_ring[i]->reg_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2908 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 2909 | /* enable WTHRESH=8 descriptors, to encourage burst writeback */ |
| 2910 | txdctl |= (8 << 16); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2911 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
| 2912 | } |
| 2913 | |
| 2914 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2915 | /* DMATXCTL.EN must be set after all Tx queue config is done */ |
| 2916 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 2917 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 2918 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 2919 | } |
| 2920 | for (i = 0; i < adapter->num_tx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2921 | j = adapter->tx_ring[i]->reg_idx; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2922 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2923 | txdctl |= IXGBE_TXDCTL_ENABLE; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2924 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 2925 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2926 | int wait_loop = 10; |
| 2927 | /* poll for Tx Enable ready */ |
| 2928 | do { |
| 2929 | msleep(1); |
| 2930 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
| 2931 | } while (--wait_loop && |
| 2932 | !(txdctl & IXGBE_TXDCTL_ENABLE)); |
| 2933 | if (!wait_loop) |
| 2934 | DPRINTK(DRV, ERR, "Could not enable " |
| 2935 | "Tx Queue %d\n", j); |
| 2936 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2937 | } |
| 2938 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2939 | for (i = 0; i < num_rx_rings; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 2940 | j = adapter->rx_ring[i]->reg_idx; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2941 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 2942 | /* enable PTHRESH=32 descriptors (half the internal cache) |
| 2943 | * and HTHRESH=0 descriptors (to minimize latency on fetch), |
| 2944 | * this also removes a pesky rx_no_buffer_count increment */ |
| 2945 | rxdctl |= 0x0020; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2946 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2947 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2948 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 2949 | ixgbe_rx_desc_queue_enable(adapter, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2950 | } |
| 2951 | /* enable all receives */ |
| 2952 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2953 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2954 | rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN); |
| 2955 | else |
| 2956 | rxdctl |= IXGBE_RXCTRL_RXEN; |
| 2957 | hw->mac.ops.enable_rx_dma(hw, rxdctl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2958 | |
| 2959 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 2960 | ixgbe_configure_msix(adapter); |
| 2961 | else |
| 2962 | ixgbe_configure_msi_and_legacy(adapter); |
| 2963 | |
| 2964 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2965 | ixgbe_napi_enable_all(adapter); |
| 2966 | |
| 2967 | /* clear any pending interrupts, may auto mask */ |
| 2968 | IXGBE_READ_REG(hw, IXGBE_EICR); |
| 2969 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2970 | ixgbe_irq_enable(adapter); |
| 2971 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2972 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 2973 | * If this adapter has a fan, check to see if we had a failure |
| 2974 | * before we enabled the interrupt. |
| 2975 | */ |
| 2976 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 2977 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 2978 | if (esdp & IXGBE_ESDP_SDP1) |
| 2979 | DPRINTK(DRV, CRIT, |
| 2980 | "Fan has stopped, replace the adapter\n"); |
| 2981 | } |
| 2982 | |
| 2983 | /* |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2984 | * For hot-pluggable SFP+ devices, a new SFP+ module may have |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2985 | * arrived before interrupts were enabled but after probe. Such |
| 2986 | * devices wouldn't have their type identified yet. We need to |
| 2987 | * kick off the SFP+ module setup first, then try to bring up link. |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2988 | * If we're not hot-pluggable SFP+, we just need to configure link |
| 2989 | * and bring it up. |
| 2990 | */ |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2991 | if (hw->phy.type == ixgbe_phy_unknown) { |
| 2992 | err = hw->phy.ops.identify(hw); |
| 2993 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 5da43c1 | 2009-07-02 12:50:52 +0000 | [diff] [blame] | 2994 | /* |
| 2995 | * Take the device down and schedule the sfp tasklet |
| 2996 | * which will unregister_netdev and log it. |
| 2997 | */ |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2998 | ixgbe_down(adapter); |
Don Skidmore | 5da43c1 | 2009-07-02 12:50:52 +0000 | [diff] [blame] | 2999 | schedule_work(&adapter->sfp_config_module_task); |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 3000 | return err; |
| 3001 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3002 | } |
| 3003 | |
| 3004 | if (ixgbe_is_sfp(hw)) { |
| 3005 | ixgbe_sfp_link_config(adapter); |
| 3006 | } else { |
| 3007 | err = ixgbe_non_sfp_link_config(hw); |
| 3008 | if (err) |
| 3009 | DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err); |
| 3010 | } |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3011 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3012 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3013 | set_bit(__IXGBE_FDIR_INIT_DONE, |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3014 | &(adapter->tx_ring[i]->reinit_state)); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3015 | |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 3016 | /* enable transmits */ |
| 3017 | netif_tx_start_all_queues(netdev); |
| 3018 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3019 | /* bring the link up in the watchdog, this could race with our first |
| 3020 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3021 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 3022 | adapter->link_check_timeout = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3023 | mod_timer(&adapter->watchdog_timer, jiffies); |
Greg Rose | c920569 | 2010-01-22 22:46:22 +0000 | [diff] [blame] | 3024 | |
| 3025 | /* Set PF Reset Done bit so PF/VF Mail Ops can work */ |
| 3026 | ctrl_ext = IXGBE_READ_REG(hw, IXGBE_CTRL_EXT); |
| 3027 | ctrl_ext |= IXGBE_CTRL_EXT_PFRSTD; |
| 3028 | IXGBE_WRITE_REG(hw, IXGBE_CTRL_EXT, ctrl_ext); |
| 3029 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3030 | return 0; |
| 3031 | } |
| 3032 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3033 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 3034 | { |
| 3035 | WARN_ON(in_interrupt()); |
| 3036 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
| 3037 | msleep(1); |
| 3038 | ixgbe_down(adapter); |
| 3039 | ixgbe_up(adapter); |
| 3040 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 3041 | } |
| 3042 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3043 | int ixgbe_up(struct ixgbe_adapter *adapter) |
| 3044 | { |
| 3045 | /* hardware has been reset, we need to reload some things */ |
| 3046 | ixgbe_configure(adapter); |
| 3047 | |
| 3048 | return ixgbe_up_complete(adapter); |
| 3049 | } |
| 3050 | |
| 3051 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 3052 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3053 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 3054 | int err; |
| 3055 | |
| 3056 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3057 | switch (err) { |
| 3058 | case 0: |
| 3059 | case IXGBE_ERR_SFP_NOT_PRESENT: |
| 3060 | break; |
| 3061 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
| 3062 | dev_err(&adapter->pdev->dev, "master disable timed out\n"); |
| 3063 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 3064 | case IXGBE_ERR_EEPROM_VERSION: |
| 3065 | /* We are running on a pre-production device, log a warning */ |
| 3066 | dev_warn(&adapter->pdev->dev, "This device is a pre-production " |
| 3067 | "adapter/LOM. Please be aware there may be issues " |
| 3068 | "associated with your hardware. If you are " |
| 3069 | "experiencing problems please contact your Intel or " |
| 3070 | "hardware representative who provided you with this " |
| 3071 | "hardware.\n"); |
| 3072 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 3073 | default: |
| 3074 | dev_err(&adapter->pdev->dev, "Hardware Error: %d\n", err); |
| 3075 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3076 | |
| 3077 | /* reprogram the RAR[0] in case user changed it. */ |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 3078 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs, |
| 3079 | IXGBE_RAH_AV); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3080 | } |
| 3081 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3082 | /** |
| 3083 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
| 3084 | * @adapter: board private structure |
| 3085 | * @rx_ring: ring to free buffers from |
| 3086 | **/ |
| 3087 | static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3088 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3089 | { |
| 3090 | struct pci_dev *pdev = adapter->pdev; |
| 3091 | unsigned long size; |
| 3092 | unsigned int i; |
| 3093 | |
| 3094 | /* Free all the Rx ring sk_buffs */ |
| 3095 | |
| 3096 | for (i = 0; i < rx_ring->count; i++) { |
| 3097 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 3098 | |
| 3099 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
| 3100 | if (rx_buffer_info->dma) { |
| 3101 | pci_unmap_single(pdev, rx_buffer_info->dma, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3102 | rx_ring->rx_buf_len, |
| 3103 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3104 | rx_buffer_info->dma = 0; |
| 3105 | } |
| 3106 | if (rx_buffer_info->skb) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3107 | struct sk_buff *skb = rx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3108 | rx_buffer_info->skb = NULL; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3109 | do { |
| 3110 | struct sk_buff *this = skb; |
Mallikarjuna R Chilakala | fd3686a | 2010-03-19 04:41:33 +0000 | [diff] [blame] | 3111 | if (IXGBE_RSC_CB(this)->dma) { |
Mallikarjuna R Chilakala | 43634e8 | 2010-02-25 23:14:37 +0000 | [diff] [blame] | 3112 | pci_unmap_single(pdev, IXGBE_RSC_CB(this)->dma, |
| 3113 | rx_ring->rx_buf_len, |
| 3114 | PCI_DMA_FROMDEVICE); |
Mallikarjuna R Chilakala | fd3686a | 2010-03-19 04:41:33 +0000 | [diff] [blame] | 3115 | IXGBE_RSC_CB(this)->dma = 0; |
| 3116 | } |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3117 | skb = skb->prev; |
| 3118 | dev_kfree_skb(this); |
| 3119 | } while (skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3120 | } |
| 3121 | if (!rx_buffer_info->page) |
| 3122 | continue; |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 3123 | if (rx_buffer_info->page_dma) { |
| 3124 | pci_unmap_page(pdev, rx_buffer_info->page_dma, |
| 3125 | PAGE_SIZE / 2, PCI_DMA_FROMDEVICE); |
| 3126 | rx_buffer_info->page_dma = 0; |
| 3127 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3128 | put_page(rx_buffer_info->page); |
| 3129 | rx_buffer_info->page = NULL; |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 3130 | rx_buffer_info->page_offset = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3131 | } |
| 3132 | |
| 3133 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 3134 | memset(rx_ring->rx_buffer_info, 0, size); |
| 3135 | |
| 3136 | /* Zero out the descriptor ring */ |
| 3137 | memset(rx_ring->desc, 0, rx_ring->size); |
| 3138 | |
| 3139 | rx_ring->next_to_clean = 0; |
| 3140 | rx_ring->next_to_use = 0; |
| 3141 | |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 3142 | if (rx_ring->head) |
| 3143 | writel(0, adapter->hw.hw_addr + rx_ring->head); |
| 3144 | if (rx_ring->tail) |
| 3145 | writel(0, adapter->hw.hw_addr + rx_ring->tail); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3146 | } |
| 3147 | |
| 3148 | /** |
| 3149 | * ixgbe_clean_tx_ring - Free Tx Buffers |
| 3150 | * @adapter: board private structure |
| 3151 | * @tx_ring: ring to be cleaned |
| 3152 | **/ |
| 3153 | static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3154 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3155 | { |
| 3156 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 3157 | unsigned long size; |
| 3158 | unsigned int i; |
| 3159 | |
| 3160 | /* Free all the Tx ring sk_buffs */ |
| 3161 | |
| 3162 | for (i = 0; i < tx_ring->count; i++) { |
| 3163 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 3164 | ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info); |
| 3165 | } |
| 3166 | |
| 3167 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 3168 | memset(tx_ring->tx_buffer_info, 0, size); |
| 3169 | |
| 3170 | /* Zero out the descriptor ring */ |
| 3171 | memset(tx_ring->desc, 0, tx_ring->size); |
| 3172 | |
| 3173 | tx_ring->next_to_use = 0; |
| 3174 | tx_ring->next_to_clean = 0; |
| 3175 | |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 3176 | if (tx_ring->head) |
| 3177 | writel(0, adapter->hw.hw_addr + tx_ring->head); |
| 3178 | if (tx_ring->tail) |
| 3179 | writel(0, adapter->hw.hw_addr + tx_ring->tail); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3180 | } |
| 3181 | |
| 3182 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3183 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 3184 | * @adapter: board private structure |
| 3185 | **/ |
| 3186 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 3187 | { |
| 3188 | int i; |
| 3189 | |
| 3190 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3191 | ixgbe_clean_rx_ring(adapter, adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3192 | } |
| 3193 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3194 | /** |
| 3195 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 3196 | * @adapter: board private structure |
| 3197 | **/ |
| 3198 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 3199 | { |
| 3200 | int i; |
| 3201 | |
| 3202 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3203 | ixgbe_clean_tx_ring(adapter, adapter->tx_ring[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3204 | } |
| 3205 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3206 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 3207 | { |
| 3208 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3209 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3210 | u32 rxctrl; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3211 | u32 txdctl; |
| 3212 | int i, j; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3213 | |
| 3214 | /* signal that we are down to the interrupt handler */ |
| 3215 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 3216 | |
Greg Rose | 767081a | 2010-01-22 22:46:40 +0000 | [diff] [blame] | 3217 | /* disable receive for all VFs and wait one second */ |
| 3218 | if (adapter->num_vfs) { |
| 3219 | for (i = 0 ; i < adapter->num_vfs; i++) |
| 3220 | adapter->vfinfo[i].clear_to_send = 0; |
| 3221 | |
| 3222 | /* ping all the active vfs to let them know we are going down */ |
| 3223 | ixgbe_ping_all_vfs(adapter); |
| 3224 | /* Disable all VFTE/VFRE TX/RX */ |
| 3225 | ixgbe_disable_tx_rx(adapter); |
| 3226 | } |
| 3227 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3228 | /* disable receives */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3229 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 3230 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3231 | |
| 3232 | netif_tx_disable(netdev); |
| 3233 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3234 | IXGBE_WRITE_FLUSH(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3235 | msleep(10); |
| 3236 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3237 | netif_tx_stop_all_queues(netdev); |
| 3238 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3239 | ixgbe_irq_disable(adapter); |
| 3240 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3241 | ixgbe_napi_disable_all(adapter); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3242 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 3243 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 3244 | del_timer_sync(&adapter->sfp_timer); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3245 | del_timer_sync(&adapter->watchdog_timer); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3246 | cancel_work_sync(&adapter->watchdog_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3247 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3248 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 3249 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 3250 | cancel_work_sync(&adapter->fdir_reinit_task); |
| 3251 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3252 | /* disable transmits in the hardware now that interrupts are off */ |
| 3253 | for (i = 0; i < adapter->num_tx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3254 | j = adapter->tx_ring[i]->reg_idx; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3255 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
| 3256 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), |
| 3257 | (txdctl & ~IXGBE_TXDCTL_ENABLE)); |
| 3258 | } |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 3259 | /* Disable the Tx DMA engine on 82599 */ |
| 3260 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 3261 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
| 3262 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 3263 | ~IXGBE_DMATXCTL_TE)); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3264 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3265 | netif_carrier_off(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3266 | |
Peter Waskiewicz | 9a713e7 | 2010-02-10 16:07:54 +0000 | [diff] [blame] | 3267 | /* clear n-tuple filters that are cached */ |
| 3268 | ethtool_ntuple_flush(netdev); |
| 3269 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 3270 | if (!pci_channel_offline(adapter->pdev)) |
| 3271 | ixgbe_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3272 | ixgbe_clean_all_tx_rings(adapter); |
| 3273 | ixgbe_clean_all_rx_rings(adapter); |
| 3274 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 3275 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 3276 | /* since we reset the hardware DCA settings were cleared */ |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 3277 | ixgbe_setup_dca(adapter); |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 3278 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3279 | } |
| 3280 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3281 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3282 | * ixgbe_poll - NAPI Rx polling callback |
| 3283 | * @napi: structure for representing this polling device |
| 3284 | * @budget: how many packets driver is allowed to clean |
| 3285 | * |
| 3286 | * This function is used for legacy and MSI, NAPI mode |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3287 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3288 | static int ixgbe_poll(struct napi_struct *napi, int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3289 | { |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 3290 | struct ixgbe_q_vector *q_vector = |
| 3291 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3292 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 3293 | int tx_clean_complete, work_done = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3294 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 3295 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 3296 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3297 | ixgbe_update_tx_dca(adapter, adapter->tx_ring[0]); |
| 3298 | ixgbe_update_rx_dca(adapter, adapter->rx_ring[0]); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 3299 | } |
| 3300 | #endif |
| 3301 | |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3302 | tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring[0]); |
| 3303 | ixgbe_clean_rx_irq(q_vector, adapter->rx_ring[0], &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3304 | |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 3305 | if (!tx_clean_complete) |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 3306 | work_done = budget; |
| 3307 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 3308 | /* If budget not fully consumed, exit the polling mode */ |
| 3309 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3310 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 3311 | if (adapter->rx_itr_setting & 1) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 3312 | ixgbe_set_itr(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3313 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 3314 | ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3315 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3316 | return work_done; |
| 3317 | } |
| 3318 | |
| 3319 | /** |
| 3320 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 3321 | * @netdev: network interface device structure |
| 3322 | **/ |
| 3323 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 3324 | { |
| 3325 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3326 | |
| 3327 | /* Do the reset outside of interrupt context */ |
| 3328 | schedule_work(&adapter->reset_task); |
| 3329 | } |
| 3330 | |
| 3331 | static void ixgbe_reset_task(struct work_struct *work) |
| 3332 | { |
| 3333 | struct ixgbe_adapter *adapter; |
| 3334 | adapter = container_of(work, struct ixgbe_adapter, reset_task); |
| 3335 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3336 | /* If we're already down or resetting, just bail */ |
| 3337 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 3338 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 3339 | return; |
| 3340 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3341 | adapter->tx_timeout_count++; |
| 3342 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3343 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3344 | } |
| 3345 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3346 | #ifdef CONFIG_IXGBE_DCB |
| 3347 | static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3348 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3349 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3350 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB]; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3351 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3352 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) |
| 3353 | return ret; |
| 3354 | |
| 3355 | f->mask = 0x7 << 3; |
| 3356 | adapter->num_rx_queues = f->indices; |
| 3357 | adapter->num_tx_queues = f->indices; |
| 3358 | ret = true; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3359 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3360 | return ret; |
| 3361 | } |
| 3362 | #endif |
| 3363 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3364 | /** |
| 3365 | * ixgbe_set_rss_queues: Allocate queues for RSS |
| 3366 | * @adapter: board private structure to initialize |
| 3367 | * |
| 3368 | * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try |
| 3369 | * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU. |
| 3370 | * |
| 3371 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3372 | static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter) |
| 3373 | { |
| 3374 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3375 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_RSS]; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3376 | |
| 3377 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3378 | f->mask = 0xF; |
| 3379 | adapter->num_rx_queues = f->indices; |
| 3380 | adapter->num_tx_queues = f->indices; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3381 | ret = true; |
| 3382 | } else { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3383 | ret = false; |
| 3384 | } |
| 3385 | |
| 3386 | return ret; |
| 3387 | } |
| 3388 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3389 | /** |
| 3390 | * ixgbe_set_fdir_queues: Allocate queues for Flow Director |
| 3391 | * @adapter: board private structure to initialize |
| 3392 | * |
| 3393 | * Flow Director is an advanced Rx filter, attempting to get Rx flows back |
| 3394 | * to the original CPU that initiated the Tx session. This runs in addition |
| 3395 | * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the |
| 3396 | * Rx load across CPUs using RSS. |
| 3397 | * |
| 3398 | **/ |
| 3399 | static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter) |
| 3400 | { |
| 3401 | bool ret = false; |
| 3402 | struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR]; |
| 3403 | |
| 3404 | f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices); |
| 3405 | f_fdir->mask = 0; |
| 3406 | |
| 3407 | /* Flow Director must have RSS enabled */ |
| 3408 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED && |
| 3409 | ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 3410 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) { |
| 3411 | adapter->num_tx_queues = f_fdir->indices; |
| 3412 | adapter->num_rx_queues = f_fdir->indices; |
| 3413 | ret = true; |
| 3414 | } else { |
| 3415 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3416 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 3417 | } |
| 3418 | return ret; |
| 3419 | } |
| 3420 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3421 | #ifdef IXGBE_FCOE |
| 3422 | /** |
| 3423 | * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE) |
| 3424 | * @adapter: board private structure to initialize |
| 3425 | * |
| 3426 | * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges. |
| 3427 | * The ring feature mask is not used as a mask for FCoE, as it can take any 8 |
| 3428 | * rx queues out of the max number of rx queues, instead, it is used as the |
| 3429 | * index of the first rx queue used by FCoE. |
| 3430 | * |
| 3431 | **/ |
| 3432 | static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter) |
| 3433 | { |
| 3434 | bool ret = false; |
| 3435 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 3436 | |
| 3437 | f->indices = min((int)num_online_cpus(), f->indices); |
| 3438 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3439 | adapter->num_rx_queues = 1; |
| 3440 | adapter->num_tx_queues = 1; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3441 | #ifdef CONFIG_IXGBE_DCB |
| 3442 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Frans Pop | d6dbee8 | 2010-03-24 07:57:35 +0000 | [diff] [blame] | 3443 | DPRINTK(PROBE, INFO, "FCoE enabled with DCB\n"); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3444 | ixgbe_set_dcb_queues(adapter); |
| 3445 | } |
| 3446 | #endif |
| 3447 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Frans Pop | d6dbee8 | 2010-03-24 07:57:35 +0000 | [diff] [blame] | 3448 | DPRINTK(PROBE, INFO, "FCoE enabled with RSS\n"); |
Yi Zou | 8faa2a7 | 2009-07-09 02:29:50 +0000 | [diff] [blame] | 3449 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 3450 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 3451 | ixgbe_set_fdir_queues(adapter); |
| 3452 | else |
| 3453 | ixgbe_set_rss_queues(adapter); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3454 | } |
| 3455 | /* adding FCoE rx rings to the end */ |
| 3456 | f->mask = adapter->num_rx_queues; |
| 3457 | adapter->num_rx_queues += f->indices; |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3458 | adapter->num_tx_queues += f->indices; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3459 | |
| 3460 | ret = true; |
| 3461 | } |
| 3462 | |
| 3463 | return ret; |
| 3464 | } |
| 3465 | |
| 3466 | #endif /* IXGBE_FCOE */ |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 3467 | /** |
| 3468 | * ixgbe_set_sriov_queues: Allocate queues for IOV use |
| 3469 | * @adapter: board private structure to initialize |
| 3470 | * |
| 3471 | * IOV doesn't actually use anything, so just NAK the |
| 3472 | * request for now and let the other queue routines |
| 3473 | * figure out what to do. |
| 3474 | */ |
| 3475 | static inline bool ixgbe_set_sriov_queues(struct ixgbe_adapter *adapter) |
| 3476 | { |
| 3477 | return false; |
| 3478 | } |
| 3479 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3480 | /* |
| 3481 | * ixgbe_set_num_queues: Allocate queues for device, feature dependant |
| 3482 | * @adapter: board private structure to initialize |
| 3483 | * |
| 3484 | * This is the top level queue allocation routine. The order here is very |
| 3485 | * important, starting with the "most" number of features turned on at once, |
| 3486 | * and ending with the smallest set of features. This way large combinations |
| 3487 | * can be allocated if they're turned on, and smaller combinations are the |
| 3488 | * fallthrough conditions. |
| 3489 | * |
| 3490 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3491 | static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter) |
| 3492 | { |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 3493 | /* Start with base case */ |
| 3494 | adapter->num_rx_queues = 1; |
| 3495 | adapter->num_tx_queues = 1; |
| 3496 | adapter->num_rx_pools = adapter->num_rx_queues; |
| 3497 | adapter->num_rx_queues_per_pool = 1; |
| 3498 | |
| 3499 | if (ixgbe_set_sriov_queues(adapter)) |
| 3500 | return; |
| 3501 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3502 | #ifdef IXGBE_FCOE |
| 3503 | if (ixgbe_set_fcoe_queues(adapter)) |
| 3504 | goto done; |
| 3505 | |
| 3506 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3507 | #ifdef CONFIG_IXGBE_DCB |
| 3508 | if (ixgbe_set_dcb_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 3509 | goto done; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3510 | |
| 3511 | #endif |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3512 | if (ixgbe_set_fdir_queues(adapter)) |
| 3513 | goto done; |
| 3514 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3515 | if (ixgbe_set_rss_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 3516 | goto done; |
| 3517 | |
| 3518 | /* fallback to base case */ |
| 3519 | adapter->num_rx_queues = 1; |
| 3520 | adapter->num_tx_queues = 1; |
| 3521 | |
| 3522 | done: |
| 3523 | /* Notify the stack of the (possibly) reduced Tx Queue count. */ |
| 3524 | adapter->netdev->real_num_tx_queues = adapter->num_tx_queues; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3525 | } |
| 3526 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3527 | static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3528 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3529 | { |
| 3530 | int err, vector_threshold; |
| 3531 | |
| 3532 | /* We'll want at least 3 (vector_threshold): |
| 3533 | * 1) TxQ[0] Cleanup |
| 3534 | * 2) RxQ[0] Cleanup |
| 3535 | * 3) Other (Link Status Change, etc.) |
| 3536 | * 4) TCP Timer (optional) |
| 3537 | */ |
| 3538 | vector_threshold = MIN_MSIX_COUNT; |
| 3539 | |
| 3540 | /* The more we get, the more we will assign to Tx/Rx Cleanup |
| 3541 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 3542 | * Right now, we simply care about how many we'll get; we'll |
| 3543 | * set them up later while requesting irq's. |
| 3544 | */ |
| 3545 | while (vectors >= vector_threshold) { |
| 3546 | err = pci_enable_msix(adapter->pdev, adapter->msix_entries, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3547 | vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3548 | if (!err) /* Success in acquiring all requested vectors. */ |
| 3549 | break; |
| 3550 | else if (err < 0) |
| 3551 | vectors = 0; /* Nasty failure, quit now */ |
| 3552 | else /* err == number of vectors we should try again with */ |
| 3553 | vectors = err; |
| 3554 | } |
| 3555 | |
| 3556 | if (vectors < vector_threshold) { |
| 3557 | /* Can't allocate enough MSI-X interrupts? Oh well. |
| 3558 | * This just means we'll go with either a single MSI |
| 3559 | * vector or fall back to legacy interrupts. |
| 3560 | */ |
| 3561 | DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n"); |
| 3562 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 3563 | kfree(adapter->msix_entries); |
| 3564 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3565 | } else { |
| 3566 | adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */ |
Peter P Waskiewicz Jr | eb7f139 | 2009-02-01 01:18:58 -0800 | [diff] [blame] | 3567 | /* |
| 3568 | * Adjust for only the vectors we'll use, which is minimum |
| 3569 | * of max_msix_q_vectors + NON_Q_VECTORS, or the number of |
| 3570 | * vectors we were allocated. |
| 3571 | */ |
| 3572 | adapter->num_msix_vectors = min(vectors, |
| 3573 | adapter->max_msix_q_vectors + NON_Q_VECTORS); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3574 | } |
| 3575 | } |
| 3576 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3577 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3578 | * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3579 | * @adapter: board private structure to initialize |
| 3580 | * |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3581 | * Cache the descriptor ring offsets for RSS to the assigned rings. |
| 3582 | * |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3583 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3584 | static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3585 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3586 | int i; |
| 3587 | bool ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3588 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3589 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 3590 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3591 | adapter->rx_ring[i]->reg_idx = i; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3592 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3593 | adapter->tx_ring[i]->reg_idx = i; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3594 | ret = true; |
| 3595 | } else { |
| 3596 | ret = false; |
| 3597 | } |
| 3598 | |
| 3599 | return ret; |
| 3600 | } |
| 3601 | |
| 3602 | #ifdef CONFIG_IXGBE_DCB |
| 3603 | /** |
| 3604 | * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB |
| 3605 | * @adapter: board private structure to initialize |
| 3606 | * |
| 3607 | * Cache the descriptor ring offsets for DCB to the assigned rings. |
| 3608 | * |
| 3609 | **/ |
| 3610 | static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter) |
| 3611 | { |
| 3612 | int i; |
| 3613 | bool ret = false; |
| 3614 | int dcb_i = adapter->ring_feature[RING_F_DCB].indices; |
| 3615 | |
| 3616 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 3617 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3618 | /* the number of queues is assumed to be symmetric */ |
| 3619 | for (i = 0; i < dcb_i; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3620 | adapter->rx_ring[i]->reg_idx = i << 3; |
| 3621 | adapter->tx_ring[i]->reg_idx = i << 2; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3622 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3623 | ret = true; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3624 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | f92ef20 | 2009-04-16 15:00:20 +0000 | [diff] [blame] | 3625 | if (dcb_i == 8) { |
| 3626 | /* |
| 3627 | * Tx TC0 starts at: descriptor queue 0 |
| 3628 | * Tx TC1 starts at: descriptor queue 32 |
| 3629 | * Tx TC2 starts at: descriptor queue 64 |
| 3630 | * Tx TC3 starts at: descriptor queue 80 |
| 3631 | * Tx TC4 starts at: descriptor queue 96 |
| 3632 | * Tx TC5 starts at: descriptor queue 104 |
| 3633 | * Tx TC6 starts at: descriptor queue 112 |
| 3634 | * Tx TC7 starts at: descriptor queue 120 |
| 3635 | * |
| 3636 | * Rx TC0-TC7 are offset by 16 queues each |
| 3637 | */ |
| 3638 | for (i = 0; i < 3; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3639 | adapter->tx_ring[i]->reg_idx = i << 5; |
| 3640 | adapter->rx_ring[i]->reg_idx = i << 4; |
PJ Waskiewicz | f92ef20 | 2009-04-16 15:00:20 +0000 | [diff] [blame] | 3641 | } |
| 3642 | for ( ; i < 5; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3643 | adapter->tx_ring[i]->reg_idx = |
PJ Waskiewicz | f92ef20 | 2009-04-16 15:00:20 +0000 | [diff] [blame] | 3644 | ((i + 2) << 4); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3645 | adapter->rx_ring[i]->reg_idx = i << 4; |
PJ Waskiewicz | f92ef20 | 2009-04-16 15:00:20 +0000 | [diff] [blame] | 3646 | } |
| 3647 | for ( ; i < dcb_i; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3648 | adapter->tx_ring[i]->reg_idx = |
PJ Waskiewicz | f92ef20 | 2009-04-16 15:00:20 +0000 | [diff] [blame] | 3649 | ((i + 8) << 3); |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3650 | adapter->rx_ring[i]->reg_idx = i << 4; |
PJ Waskiewicz | f92ef20 | 2009-04-16 15:00:20 +0000 | [diff] [blame] | 3651 | } |
| 3652 | |
| 3653 | ret = true; |
| 3654 | } else if (dcb_i == 4) { |
| 3655 | /* |
| 3656 | * Tx TC0 starts at: descriptor queue 0 |
| 3657 | * Tx TC1 starts at: descriptor queue 64 |
| 3658 | * Tx TC2 starts at: descriptor queue 96 |
| 3659 | * Tx TC3 starts at: descriptor queue 112 |
| 3660 | * |
| 3661 | * Rx TC0-TC3 are offset by 32 queues each |
| 3662 | */ |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3663 | adapter->tx_ring[0]->reg_idx = 0; |
| 3664 | adapter->tx_ring[1]->reg_idx = 64; |
| 3665 | adapter->tx_ring[2]->reg_idx = 96; |
| 3666 | adapter->tx_ring[3]->reg_idx = 112; |
PJ Waskiewicz | f92ef20 | 2009-04-16 15:00:20 +0000 | [diff] [blame] | 3667 | for (i = 0 ; i < dcb_i; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3668 | adapter->rx_ring[i]->reg_idx = i << 5; |
PJ Waskiewicz | f92ef20 | 2009-04-16 15:00:20 +0000 | [diff] [blame] | 3669 | |
| 3670 | ret = true; |
| 3671 | } else { |
| 3672 | ret = false; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3673 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3674 | } else { |
| 3675 | ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3676 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3677 | } else { |
| 3678 | ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3679 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3680 | |
| 3681 | return ret; |
| 3682 | } |
| 3683 | #endif |
| 3684 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3685 | /** |
| 3686 | * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director |
| 3687 | * @adapter: board private structure to initialize |
| 3688 | * |
| 3689 | * Cache the descriptor ring offsets for Flow Director to the assigned rings. |
| 3690 | * |
| 3691 | **/ |
| 3692 | static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter) |
| 3693 | { |
| 3694 | int i; |
| 3695 | bool ret = false; |
| 3696 | |
| 3697 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED && |
| 3698 | ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 3699 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) { |
| 3700 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3701 | adapter->rx_ring[i]->reg_idx = i; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3702 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3703 | adapter->tx_ring[i]->reg_idx = i; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3704 | ret = true; |
| 3705 | } |
| 3706 | |
| 3707 | return ret; |
| 3708 | } |
| 3709 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3710 | #ifdef IXGBE_FCOE |
| 3711 | /** |
| 3712 | * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE |
| 3713 | * @adapter: board private structure to initialize |
| 3714 | * |
| 3715 | * Cache the descriptor ring offsets for FCoE mode to the assigned rings. |
| 3716 | * |
| 3717 | */ |
| 3718 | static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter) |
| 3719 | { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3720 | int i, fcoe_rx_i = 0, fcoe_tx_i = 0; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3721 | bool ret = false; |
| 3722 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 3723 | |
| 3724 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 3725 | #ifdef CONFIG_IXGBE_DCB |
| 3726 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3727 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
| 3728 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3729 | ixgbe_cache_ring_dcb(adapter); |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3730 | /* find out queues in TC for FCoE */ |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3731 | fcoe_rx_i = adapter->rx_ring[fcoe->tc]->reg_idx + 1; |
| 3732 | fcoe_tx_i = adapter->tx_ring[fcoe->tc]->reg_idx + 1; |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3733 | /* |
| 3734 | * In 82599, the number of Tx queues for each traffic |
| 3735 | * class for both 8-TC and 4-TC modes are: |
| 3736 | * TCs : TC0 TC1 TC2 TC3 TC4 TC5 TC6 TC7 |
| 3737 | * 8 TCs: 32 32 16 16 8 8 8 8 |
| 3738 | * 4 TCs: 64 64 32 32 |
| 3739 | * We have max 8 queues for FCoE, where 8 the is |
| 3740 | * FCoE redirection table size. If TC for FCoE is |
| 3741 | * less than or equal to TC3, we have enough queues |
| 3742 | * to add max of 8 queues for FCoE, so we start FCoE |
| 3743 | * tx descriptor from the next one, i.e., reg_idx + 1. |
| 3744 | * If TC for FCoE is above TC3, implying 8 TC mode, |
| 3745 | * and we need 8 for FCoE, we have to take all queues |
| 3746 | * in that traffic class for FCoE. |
| 3747 | */ |
| 3748 | if ((f->indices == IXGBE_FCRETA_SIZE) && (fcoe->tc > 3)) |
| 3749 | fcoe_tx_i--; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3750 | } |
| 3751 | #endif /* CONFIG_IXGBE_DCB */ |
| 3752 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Yi Zou | 8faa2a7 | 2009-07-09 02:29:50 +0000 | [diff] [blame] | 3753 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 3754 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 3755 | ixgbe_cache_ring_fdir(adapter); |
| 3756 | else |
| 3757 | ixgbe_cache_ring_rss(adapter); |
| 3758 | |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3759 | fcoe_rx_i = f->mask; |
| 3760 | fcoe_tx_i = f->mask; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3761 | } |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3762 | for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3763 | adapter->rx_ring[f->mask + i]->reg_idx = fcoe_rx_i; |
| 3764 | adapter->tx_ring[f->mask + i]->reg_idx = fcoe_tx_i; |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3765 | } |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3766 | ret = true; |
| 3767 | } |
| 3768 | return ret; |
| 3769 | } |
| 3770 | |
| 3771 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3772 | /** |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 3773 | * ixgbe_cache_ring_sriov - Descriptor ring to register mapping for sriov |
| 3774 | * @adapter: board private structure to initialize |
| 3775 | * |
| 3776 | * SR-IOV doesn't use any descriptor rings but changes the default if |
| 3777 | * no other mapping is used. |
| 3778 | * |
| 3779 | */ |
| 3780 | static inline bool ixgbe_cache_ring_sriov(struct ixgbe_adapter *adapter) |
| 3781 | { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3782 | adapter->rx_ring[0]->reg_idx = adapter->num_vfs * 2; |
| 3783 | adapter->tx_ring[0]->reg_idx = adapter->num_vfs * 2; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 3784 | if (adapter->num_vfs) |
| 3785 | return true; |
| 3786 | else |
| 3787 | return false; |
| 3788 | } |
| 3789 | |
| 3790 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3791 | * ixgbe_cache_ring_register - Descriptor ring to register mapping |
| 3792 | * @adapter: board private structure to initialize |
| 3793 | * |
| 3794 | * Once we know the feature-set enabled for the device, we'll cache |
| 3795 | * the register offset the descriptor ring is assigned to. |
| 3796 | * |
| 3797 | * Note, the order the various feature calls is important. It must start with |
| 3798 | * the "most" features enabled at the same time, then trickle down to the |
| 3799 | * least amount of features turned on at once. |
| 3800 | **/ |
| 3801 | static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) |
| 3802 | { |
| 3803 | /* start with default case */ |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3804 | adapter->rx_ring[0]->reg_idx = 0; |
| 3805 | adapter->tx_ring[0]->reg_idx = 0; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3806 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 3807 | if (ixgbe_cache_ring_sriov(adapter)) |
| 3808 | return; |
| 3809 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3810 | #ifdef IXGBE_FCOE |
| 3811 | if (ixgbe_cache_ring_fcoe(adapter)) |
| 3812 | return; |
| 3813 | |
| 3814 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3815 | #ifdef CONFIG_IXGBE_DCB |
| 3816 | if (ixgbe_cache_ring_dcb(adapter)) |
| 3817 | return; |
| 3818 | |
| 3819 | #endif |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3820 | if (ixgbe_cache_ring_fdir(adapter)) |
| 3821 | return; |
| 3822 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3823 | if (ixgbe_cache_ring_rss(adapter)) |
| 3824 | return; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3825 | } |
| 3826 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3827 | /** |
| 3828 | * ixgbe_alloc_queues - Allocate memory for all rings |
| 3829 | * @adapter: board private structure to initialize |
| 3830 | * |
| 3831 | * We allocate one ring per queue at run-time since we don't know the |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3832 | * number of queues at compile-time. The polling_netdev array is |
| 3833 | * intended for Multiqueue, but should work fine with a single queue. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3834 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3835 | static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3836 | { |
| 3837 | int i; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3838 | int orig_node = adapter->node; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3839 | |
| 3840 | for (i = 0; i < adapter->num_tx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3841 | struct ixgbe_ring *ring = adapter->tx_ring[i]; |
| 3842 | if (orig_node == -1) { |
| 3843 | int cur_node = next_online_node(adapter->node); |
| 3844 | if (cur_node == MAX_NUMNODES) |
| 3845 | cur_node = first_online_node; |
| 3846 | adapter->node = cur_node; |
| 3847 | } |
| 3848 | ring = kzalloc_node(sizeof(struct ixgbe_ring), GFP_KERNEL, |
| 3849 | adapter->node); |
| 3850 | if (!ring) |
| 3851 | ring = kzalloc(sizeof(struct ixgbe_ring), GFP_KERNEL); |
| 3852 | if (!ring) |
| 3853 | goto err_tx_ring_allocation; |
| 3854 | ring->count = adapter->tx_ring_count; |
| 3855 | ring->queue_index = i; |
| 3856 | ring->numa_node = adapter->node; |
| 3857 | |
| 3858 | adapter->tx_ring[i] = ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3859 | } |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3860 | |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3861 | /* Restore the adapter's original node */ |
| 3862 | adapter->node = orig_node; |
| 3863 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3864 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3865 | struct ixgbe_ring *ring = adapter->rx_ring[i]; |
| 3866 | if (orig_node == -1) { |
| 3867 | int cur_node = next_online_node(adapter->node); |
| 3868 | if (cur_node == MAX_NUMNODES) |
| 3869 | cur_node = first_online_node; |
| 3870 | adapter->node = cur_node; |
| 3871 | } |
| 3872 | ring = kzalloc_node(sizeof(struct ixgbe_ring), GFP_KERNEL, |
| 3873 | adapter->node); |
| 3874 | if (!ring) |
| 3875 | ring = kzalloc(sizeof(struct ixgbe_ring), GFP_KERNEL); |
| 3876 | if (!ring) |
| 3877 | goto err_rx_ring_allocation; |
| 3878 | ring->count = adapter->rx_ring_count; |
| 3879 | ring->queue_index = i; |
| 3880 | ring->numa_node = adapter->node; |
| 3881 | |
| 3882 | adapter->rx_ring[i] = ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3883 | } |
| 3884 | |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3885 | /* Restore the adapter's original node */ |
| 3886 | adapter->node = orig_node; |
| 3887 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3888 | ixgbe_cache_ring_register(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3889 | |
| 3890 | return 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3891 | |
| 3892 | err_rx_ring_allocation: |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 3893 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3894 | kfree(adapter->tx_ring[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3895 | err_tx_ring_allocation: |
| 3896 | return -ENOMEM; |
| 3897 | } |
| 3898 | |
| 3899 | /** |
| 3900 | * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported |
| 3901 | * @adapter: board private structure to initialize |
| 3902 | * |
| 3903 | * Attempt to configure the interrupts using the best available |
| 3904 | * capabilities of the hardware and the kernel. |
| 3905 | **/ |
Al Viro | feea6a5 | 2008-11-27 15:34:07 -0800 | [diff] [blame] | 3906 | static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3907 | { |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3908 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3909 | int err = 0; |
| 3910 | int vector, v_budget; |
| 3911 | |
| 3912 | /* |
| 3913 | * It's easy to be greedy for MSI-X vectors, but it really |
| 3914 | * doesn't do us much good if we have a lot more vectors |
| 3915 | * than CPU's. So let's be conservative and only ask for |
PJ Waskiewicz | 342bde1 | 2009-11-12 23:50:43 +0000 | [diff] [blame] | 3916 | * (roughly) the same number of vectors as there are CPU's. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3917 | */ |
| 3918 | v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues, |
PJ Waskiewicz | 342bde1 | 2009-11-12 23:50:43 +0000 | [diff] [blame] | 3919 | (int)num_online_cpus()) + NON_Q_VECTORS; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3920 | |
| 3921 | /* |
| 3922 | * At the same time, hardware can only support a maximum of |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3923 | * hw.mac->max_msix_vectors vectors. With features |
| 3924 | * such as RSS and VMDq, we can easily surpass the number of Rx and Tx |
| 3925 | * descriptor queues supported by our device. Thus, we cap it off in |
| 3926 | * those rare cases where the cpu count also exceeds our vector limit. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3927 | */ |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3928 | v_budget = min(v_budget, (int)hw->mac.max_msix_vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3929 | |
| 3930 | /* A failure in MSI-X entry allocation isn't fatal, but it does |
| 3931 | * mean we disable MSI-X capabilities of the adapter. */ |
| 3932 | adapter->msix_entries = kcalloc(v_budget, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3933 | sizeof(struct msix_entry), GFP_KERNEL); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3934 | if (adapter->msix_entries) { |
| 3935 | for (vector = 0; vector < v_budget; vector++) |
| 3936 | adapter->msix_entries[vector].entry = vector; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3937 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3938 | ixgbe_acquire_msix_vectors(adapter, v_budget); |
| 3939 | |
| 3940 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 3941 | goto out; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3942 | } |
| 3943 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3944 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 3945 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3946 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3947 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 3948 | adapter->atr_sample_rate = 0; |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 3949 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 3950 | ixgbe_disable_sriov(adapter); |
| 3951 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3952 | ixgbe_set_num_queues(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3953 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3954 | err = pci_enable_msi(adapter->pdev); |
| 3955 | if (!err) { |
| 3956 | adapter->flags |= IXGBE_FLAG_MSI_ENABLED; |
| 3957 | } else { |
| 3958 | DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3959 | "falling back to legacy. Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3960 | /* reset err */ |
| 3961 | err = 0; |
| 3962 | } |
| 3963 | |
| 3964 | out: |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3965 | return err; |
| 3966 | } |
| 3967 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3968 | /** |
| 3969 | * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors |
| 3970 | * @adapter: board private structure to initialize |
| 3971 | * |
| 3972 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 3973 | * return -ENOMEM. |
| 3974 | **/ |
| 3975 | static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter) |
| 3976 | { |
| 3977 | int q_idx, num_q_vectors; |
| 3978 | struct ixgbe_q_vector *q_vector; |
| 3979 | int napi_vectors; |
| 3980 | int (*poll)(struct napi_struct *, int); |
| 3981 | |
| 3982 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 3983 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3984 | napi_vectors = adapter->num_rx_queues; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3985 | poll = &ixgbe_clean_rxtx_many; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3986 | } else { |
| 3987 | num_q_vectors = 1; |
| 3988 | napi_vectors = 1; |
| 3989 | poll = &ixgbe_poll; |
| 3990 | } |
| 3991 | |
| 3992 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 3993 | q_vector = kzalloc_node(sizeof(struct ixgbe_q_vector), |
| 3994 | GFP_KERNEL, adapter->node); |
| 3995 | if (!q_vector) |
| 3996 | q_vector = kzalloc(sizeof(struct ixgbe_q_vector), |
| 3997 | GFP_KERNEL); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3998 | if (!q_vector) |
| 3999 | goto err_out; |
| 4000 | q_vector->adapter = adapter; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 4001 | if (q_vector->txr_count && !q_vector->rxr_count) |
| 4002 | q_vector->eitr = adapter->tx_eitr_param; |
| 4003 | else |
| 4004 | q_vector->eitr = adapter->rx_eitr_param; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4005 | q_vector->v_idx = q_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 4006 | netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4007 | adapter->q_vector[q_idx] = q_vector; |
| 4008 | } |
| 4009 | |
| 4010 | return 0; |
| 4011 | |
| 4012 | err_out: |
| 4013 | while (q_idx) { |
| 4014 | q_idx--; |
| 4015 | q_vector = adapter->q_vector[q_idx]; |
| 4016 | netif_napi_del(&q_vector->napi); |
| 4017 | kfree(q_vector); |
| 4018 | adapter->q_vector[q_idx] = NULL; |
| 4019 | } |
| 4020 | return -ENOMEM; |
| 4021 | } |
| 4022 | |
| 4023 | /** |
| 4024 | * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors |
| 4025 | * @adapter: board private structure to initialize |
| 4026 | * |
| 4027 | * This function frees the memory allocated to the q_vectors. In addition if |
| 4028 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 4029 | * to freeing the q_vector. |
| 4030 | **/ |
| 4031 | static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter) |
| 4032 | { |
| 4033 | int q_idx, num_q_vectors; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4034 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 4035 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4036 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 4037 | else |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4038 | num_q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4039 | |
| 4040 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
| 4041 | struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx]; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4042 | adapter->q_vector[q_idx] = NULL; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 4043 | netif_napi_del(&q_vector->napi); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4044 | kfree(q_vector); |
| 4045 | } |
| 4046 | } |
| 4047 | |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 4048 | static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4049 | { |
| 4050 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 4051 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 4052 | pci_disable_msix(adapter->pdev); |
| 4053 | kfree(adapter->msix_entries); |
| 4054 | adapter->msix_entries = NULL; |
| 4055 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 4056 | adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED; |
| 4057 | pci_disable_msi(adapter->pdev); |
| 4058 | } |
| 4059 | return; |
| 4060 | } |
| 4061 | |
| 4062 | /** |
| 4063 | * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme |
| 4064 | * @adapter: board private structure to initialize |
| 4065 | * |
| 4066 | * We determine which interrupt scheme to use based on... |
| 4067 | * - Kernel support (MSI, MSI-X) |
| 4068 | * - which can be user-defined (via MODULE_PARAM) |
| 4069 | * - Hardware queue count (num_*_queues) |
| 4070 | * - defined by miscellaneous hardware support/features (RSS, etc.) |
| 4071 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4072 | int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4073 | { |
| 4074 | int err; |
| 4075 | |
| 4076 | /* Number of supported queues */ |
| 4077 | ixgbe_set_num_queues(adapter); |
| 4078 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4079 | err = ixgbe_set_interrupt_capability(adapter); |
| 4080 | if (err) { |
| 4081 | DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n"); |
| 4082 | goto err_set_interrupt; |
| 4083 | } |
| 4084 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4085 | err = ixgbe_alloc_q_vectors(adapter); |
| 4086 | if (err) { |
| 4087 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queue " |
| 4088 | "vectors\n"); |
| 4089 | goto err_alloc_q_vectors; |
| 4090 | } |
| 4091 | |
| 4092 | err = ixgbe_alloc_queues(adapter); |
| 4093 | if (err) { |
| 4094 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n"); |
| 4095 | goto err_alloc_queues; |
| 4096 | } |
| 4097 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4098 | DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4099 | "Tx Queue count = %u\n", |
| 4100 | (adapter->num_rx_queues > 1) ? "Enabled" : |
| 4101 | "Disabled", adapter->num_rx_queues, adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4102 | |
| 4103 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 4104 | |
| 4105 | return 0; |
| 4106 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4107 | err_alloc_queues: |
| 4108 | ixgbe_free_q_vectors(adapter); |
| 4109 | err_alloc_q_vectors: |
| 4110 | ixgbe_reset_interrupt_capability(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4111 | err_set_interrupt: |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4112 | return err; |
| 4113 | } |
| 4114 | |
| 4115 | /** |
| 4116 | * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 4117 | * @adapter: board private structure to clear interrupt scheme on |
| 4118 | * |
| 4119 | * We go through and clear interrupt specific resources and reset the structure |
| 4120 | * to pre-load conditions |
| 4121 | **/ |
| 4122 | void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter) |
| 4123 | { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4124 | int i; |
| 4125 | |
| 4126 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 4127 | kfree(adapter->tx_ring[i]); |
| 4128 | adapter->tx_ring[i] = NULL; |
| 4129 | } |
| 4130 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 4131 | kfree(adapter->rx_ring[i]); |
| 4132 | adapter->rx_ring[i] = NULL; |
| 4133 | } |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4134 | |
| 4135 | ixgbe_free_q_vectors(adapter); |
| 4136 | ixgbe_reset_interrupt_capability(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4137 | } |
| 4138 | |
| 4139 | /** |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 4140 | * ixgbe_sfp_timer - worker thread to find a missing module |
| 4141 | * @data: pointer to our adapter struct |
| 4142 | **/ |
| 4143 | static void ixgbe_sfp_timer(unsigned long data) |
| 4144 | { |
| 4145 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 4146 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4147 | /* |
| 4148 | * Do the sfp_timer outside of interrupt context due to the |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 4149 | * delays that sfp+ detection requires |
| 4150 | */ |
| 4151 | schedule_work(&adapter->sfp_task); |
| 4152 | } |
| 4153 | |
| 4154 | /** |
| 4155 | * ixgbe_sfp_task - worker thread to find a missing module |
| 4156 | * @work: pointer to work_struct containing our data |
| 4157 | **/ |
| 4158 | static void ixgbe_sfp_task(struct work_struct *work) |
| 4159 | { |
| 4160 | struct ixgbe_adapter *adapter = container_of(work, |
| 4161 | struct ixgbe_adapter, |
| 4162 | sfp_task); |
| 4163 | struct ixgbe_hw *hw = &adapter->hw; |
| 4164 | |
| 4165 | if ((hw->phy.type == ixgbe_phy_nl) && |
| 4166 | (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) { |
| 4167 | s32 ret = hw->phy.ops.identify_sfp(hw); |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 4168 | if (ret == IXGBE_ERR_SFP_NOT_PRESENT) |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 4169 | goto reschedule; |
| 4170 | ret = hw->phy.ops.reset(hw); |
| 4171 | if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 88d2b81 | 2009-06-30 11:43:55 +0000 | [diff] [blame] | 4172 | dev_err(&adapter->pdev->dev, "failed to initialize " |
| 4173 | "because an unsupported SFP+ module type " |
| 4174 | "was detected.\n" |
| 4175 | "Reload the driver after installing a " |
| 4176 | "supported module.\n"); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 4177 | unregister_netdev(adapter->netdev); |
| 4178 | } else { |
| 4179 | DPRINTK(PROBE, INFO, "detected SFP+: %d\n", |
| 4180 | hw->phy.sfp_type); |
| 4181 | } |
| 4182 | /* don't need this routine any more */ |
| 4183 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 4184 | } |
| 4185 | return; |
| 4186 | reschedule: |
| 4187 | if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state)) |
| 4188 | mod_timer(&adapter->sfp_timer, |
| 4189 | round_jiffies(jiffies + (2 * HZ))); |
| 4190 | } |
| 4191 | |
| 4192 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4193 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 4194 | * @adapter: board private structure to initialize |
| 4195 | * |
| 4196 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 4197 | * Fields are initialized based on PCI device information and |
| 4198 | * OS network device settings (MTU size). |
| 4199 | **/ |
| 4200 | static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter) |
| 4201 | { |
| 4202 | struct ixgbe_hw *hw = &adapter->hw; |
| 4203 | struct pci_dev *pdev = adapter->pdev; |
Peter Waskiewicz | 9a713e7 | 2010-02-10 16:07:54 +0000 | [diff] [blame] | 4204 | struct net_device *dev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4205 | unsigned int rss; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 4206 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4207 | int j; |
| 4208 | struct tc_configuration *tc; |
| 4209 | #endif |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4210 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4211 | /* PCI config space info */ |
| 4212 | |
| 4213 | hw->vendor_id = pdev->vendor; |
| 4214 | hw->device_id = pdev->device; |
| 4215 | hw->revision_id = pdev->revision; |
| 4216 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 4217 | hw->subsystem_device_id = pdev->subsystem_device; |
| 4218 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4219 | /* Set capability flags */ |
| 4220 | rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus()); |
| 4221 | adapter->ring_feature[RING_F_RSS].indices = rss; |
| 4222 | adapter->flags |= IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4223 | adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES; |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 4224 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 4225 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 4226 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4227 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598; |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 4228 | } else if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4229 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 4230 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
| 4231 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
Peter Waskiewicz | 9a713e7 | 2010-02-10 16:07:54 +0000 | [diff] [blame] | 4232 | if (dev->features & NETIF_F_NTUPLE) { |
| 4233 | /* Flow Director perfect filter enabled */ |
| 4234 | adapter->flags |= IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 4235 | adapter->atr_sample_rate = 0; |
| 4236 | spin_lock_init(&adapter->fdir_perfect_lock); |
| 4237 | } else { |
| 4238 | /* Flow Director hash filters enabled */ |
| 4239 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 4240 | adapter->atr_sample_rate = 20; |
| 4241 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4242 | adapter->ring_feature[RING_F_FDIR].indices = |
| 4243 | IXGBE_MAX_FDIR_INDICES; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4244 | adapter->fdir_pballoc = 0; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4245 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 4246 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 4247 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 4248 | adapter->ring_feature[RING_F_FCOE].indices = 0; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 4249 | #ifdef CONFIG_IXGBE_DCB |
Yi Zou | 6ee1652 | 2009-08-31 12:34:28 +0000 | [diff] [blame] | 4250 | /* Default traffic class to use for FCoE */ |
| 4251 | adapter->fcoe.tc = IXGBE_FCOE_DEFTC; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 4252 | #endif |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4253 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 4254 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4255 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 4256 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4257 | /* Configure DCB traffic classes */ |
| 4258 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 4259 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 4260 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 4261 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 4262 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 4263 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 4264 | tc->dcb_pfc = pfc_disabled; |
| 4265 | } |
| 4266 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 4267 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
| 4268 | adapter->dcb_cfg.rx_pba_cfg = pba_equal; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4269 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4270 | adapter->dcb_cfg.round_robin_enable = false; |
| 4271 | adapter->dcb_set_bitmap = 0x00; |
| 4272 | ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg, |
| 4273 | adapter->ring_feature[RING_F_DCB].indices); |
| 4274 | |
| 4275 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4276 | |
| 4277 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 4278 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 4279 | hw->fc.current_mode = ixgbe_fc_full; /* init for ethtool output */ |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4280 | #ifdef CONFIG_DCB |
| 4281 | adapter->last_lfc_mode = hw->fc.current_mode; |
| 4282 | #endif |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 4283 | hw->fc.high_water = IXGBE_DEFAULT_FCRTH; |
| 4284 | hw->fc.low_water = IXGBE_DEFAULT_FCRTL; |
| 4285 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 4286 | hw->fc.send_xon = true; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 4287 | hw->fc.disable_fc_autoneg = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4288 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 4289 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 4290 | adapter->rx_itr_setting = 1; |
| 4291 | adapter->rx_eitr_param = 20000; |
| 4292 | adapter->tx_itr_setting = 1; |
| 4293 | adapter->tx_eitr_param = 10000; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 4294 | |
| 4295 | /* set defaults for eitr in MegaBytes */ |
| 4296 | adapter->eitr_low = 10; |
| 4297 | adapter->eitr_high = 20; |
| 4298 | |
| 4299 | /* set default ring sizes */ |
| 4300 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 4301 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 4302 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4303 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4304 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4305 | dev_err(&pdev->dev, "EEPROM initialization failed\n"); |
| 4306 | return -EIO; |
| 4307 | } |
| 4308 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4309 | /* enable rx csum by default */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4310 | adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED; |
| 4311 | |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 4312 | /* get assigned NUMA node */ |
| 4313 | adapter->node = dev_to_node(&pdev->dev); |
| 4314 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4315 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 4316 | |
| 4317 | return 0; |
| 4318 | } |
| 4319 | |
| 4320 | /** |
| 4321 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
| 4322 | * @adapter: board private structure |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4323 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4324 | * |
| 4325 | * Return 0 on success, negative on failure |
| 4326 | **/ |
| 4327 | int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4328 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4329 | { |
| 4330 | struct pci_dev *pdev = adapter->pdev; |
| 4331 | int size; |
| 4332 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4333 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4334 | tx_ring->tx_buffer_info = vmalloc_node(size, tx_ring->numa_node); |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 4335 | if (!tx_ring->tx_buffer_info) |
| 4336 | tx_ring->tx_buffer_info = vmalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4337 | if (!tx_ring->tx_buffer_info) |
| 4338 | goto err; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4339 | memset(tx_ring->tx_buffer_info, 0, size); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4340 | |
| 4341 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 4342 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4343 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4344 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4345 | tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size, |
| 4346 | &tx_ring->dma); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4347 | if (!tx_ring->desc) |
| 4348 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4349 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4350 | tx_ring->next_to_use = 0; |
| 4351 | tx_ring->next_to_clean = 0; |
| 4352 | tx_ring->work_limit = tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4353 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4354 | |
| 4355 | err: |
| 4356 | vfree(tx_ring->tx_buffer_info); |
| 4357 | tx_ring->tx_buffer_info = NULL; |
| 4358 | DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit " |
| 4359 | "descriptor ring\n"); |
| 4360 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4361 | } |
| 4362 | |
| 4363 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4364 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 4365 | * @adapter: board private structure |
| 4366 | * |
| 4367 | * If this function returns with an error, then it's possible one or |
| 4368 | * more of the rings is populated (while the rest are not). It is the |
| 4369 | * callers duty to clean those orphaned rings. |
| 4370 | * |
| 4371 | * Return 0 on success, negative on failure |
| 4372 | **/ |
| 4373 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 4374 | { |
| 4375 | int i, err = 0; |
| 4376 | |
| 4377 | for (i = 0; i < adapter->num_tx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4378 | err = ixgbe_setup_tx_resources(adapter, adapter->tx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4379 | if (!err) |
| 4380 | continue; |
| 4381 | DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i); |
| 4382 | break; |
| 4383 | } |
| 4384 | |
| 4385 | return err; |
| 4386 | } |
| 4387 | |
| 4388 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4389 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
| 4390 | * @adapter: board private structure |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4391 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4392 | * |
| 4393 | * Returns 0 on success, negative on failure |
| 4394 | **/ |
| 4395 | int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4396 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4397 | { |
| 4398 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4399 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4400 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4401 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
Jesse Brandeburg | 1a6c14a | 2010-02-03 14:18:50 +0000 | [diff] [blame] | 4402 | rx_ring->rx_buffer_info = vmalloc_node(size, adapter->node); |
| 4403 | if (!rx_ring->rx_buffer_info) |
| 4404 | rx_ring->rx_buffer_info = vmalloc(size); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4405 | if (!rx_ring->rx_buffer_info) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4406 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4407 | "vmalloc allocation failed for the rx desc ring\n"); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4408 | goto alloc_failed; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4409 | } |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4410 | memset(rx_ring->rx_buffer_info, 0, size); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4411 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4412 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4413 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 4414 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4415 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4416 | rx_ring->desc = pci_alloc_consistent(pdev, rx_ring->size, &rx_ring->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4417 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4418 | if (!rx_ring->desc) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4419 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4420 | "Memory allocation failed for the rx desc ring\n"); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4421 | vfree(rx_ring->rx_buffer_info); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4422 | goto alloc_failed; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4423 | } |
| 4424 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4425 | rx_ring->next_to_clean = 0; |
| 4426 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4427 | |
| 4428 | return 0; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4429 | |
| 4430 | alloc_failed: |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4431 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4432 | } |
| 4433 | |
| 4434 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4435 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 4436 | * @adapter: board private structure |
| 4437 | * |
| 4438 | * If this function returns with an error, then it's possible one or |
| 4439 | * more of the rings is populated (while the rest are not). It is the |
| 4440 | * callers duty to clean those orphaned rings. |
| 4441 | * |
| 4442 | * Return 0 on success, negative on failure |
| 4443 | **/ |
| 4444 | |
| 4445 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 4446 | { |
| 4447 | int i, err = 0; |
| 4448 | |
| 4449 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4450 | err = ixgbe_setup_rx_resources(adapter, adapter->rx_ring[i]); |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4451 | if (!err) |
| 4452 | continue; |
| 4453 | DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i); |
| 4454 | break; |
| 4455 | } |
| 4456 | |
| 4457 | return err; |
| 4458 | } |
| 4459 | |
| 4460 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4461 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
| 4462 | * @adapter: board private structure |
| 4463 | * @tx_ring: Tx descriptor ring for a specific queue |
| 4464 | * |
| 4465 | * Free all transmit software resources |
| 4466 | **/ |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 4467 | void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter, |
| 4468 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4469 | { |
| 4470 | struct pci_dev *pdev = adapter->pdev; |
| 4471 | |
| 4472 | ixgbe_clean_tx_ring(adapter, tx_ring); |
| 4473 | |
| 4474 | vfree(tx_ring->tx_buffer_info); |
| 4475 | tx_ring->tx_buffer_info = NULL; |
| 4476 | |
| 4477 | pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); |
| 4478 | |
| 4479 | tx_ring->desc = NULL; |
| 4480 | } |
| 4481 | |
| 4482 | /** |
| 4483 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 4484 | * @adapter: board private structure |
| 4485 | * |
| 4486 | * Free all transmit software resources |
| 4487 | **/ |
| 4488 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 4489 | { |
| 4490 | int i; |
| 4491 | |
| 4492 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4493 | if (adapter->tx_ring[i]->desc) |
| 4494 | ixgbe_free_tx_resources(adapter, adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4495 | } |
| 4496 | |
| 4497 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4498 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4499 | * @adapter: board private structure |
| 4500 | * @rx_ring: ring to clean the resources from |
| 4501 | * |
| 4502 | * Free all receive software resources |
| 4503 | **/ |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 4504 | void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter, |
| 4505 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4506 | { |
| 4507 | struct pci_dev *pdev = adapter->pdev; |
| 4508 | |
| 4509 | ixgbe_clean_rx_ring(adapter, rx_ring); |
| 4510 | |
| 4511 | vfree(rx_ring->rx_buffer_info); |
| 4512 | rx_ring->rx_buffer_info = NULL; |
| 4513 | |
| 4514 | pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); |
| 4515 | |
| 4516 | rx_ring->desc = NULL; |
| 4517 | } |
| 4518 | |
| 4519 | /** |
| 4520 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 4521 | * @adapter: board private structure |
| 4522 | * |
| 4523 | * Free all receive software resources |
| 4524 | **/ |
| 4525 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 4526 | { |
| 4527 | int i; |
| 4528 | |
| 4529 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4530 | if (adapter->rx_ring[i]->desc) |
| 4531 | ixgbe_free_rx_resources(adapter, adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4532 | } |
| 4533 | |
| 4534 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4535 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 4536 | * @netdev: network interface device structure |
| 4537 | * @new_mtu: new value for maximum frame size |
| 4538 | * |
| 4539 | * Returns 0 on success, negative on failure |
| 4540 | **/ |
| 4541 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 4542 | { |
| 4543 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4544 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 4545 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 4546 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 4547 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4548 | return -EINVAL; |
| 4549 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4550 | DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n", |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4551 | netdev->mtu, new_mtu); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4552 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4553 | netdev->mtu = new_mtu; |
| 4554 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4555 | if (netif_running(netdev)) |
| 4556 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4557 | |
| 4558 | return 0; |
| 4559 | } |
| 4560 | |
| 4561 | /** |
| 4562 | * ixgbe_open - Called when a network interface is made active |
| 4563 | * @netdev: network interface device structure |
| 4564 | * |
| 4565 | * Returns 0 on success, negative value on failure |
| 4566 | * |
| 4567 | * The open entry point is called when a network interface is made |
| 4568 | * active by the system (IFF_UP). At this point all resources needed |
| 4569 | * for transmit and receive operations are allocated, the interrupt |
| 4570 | * handler is registered with the OS, the watchdog timer is started, |
| 4571 | * and the stack is notified that the interface is ready. |
| 4572 | **/ |
| 4573 | static int ixgbe_open(struct net_device *netdev) |
| 4574 | { |
| 4575 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4576 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4577 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 4578 | /* disallow open during test */ |
| 4579 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 4580 | return -EBUSY; |
| 4581 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 4582 | netif_carrier_off(netdev); |
| 4583 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4584 | /* allocate transmit descriptors */ |
| 4585 | err = ixgbe_setup_all_tx_resources(adapter); |
| 4586 | if (err) |
| 4587 | goto err_setup_tx; |
| 4588 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4589 | /* allocate receive descriptors */ |
| 4590 | err = ixgbe_setup_all_rx_resources(adapter); |
| 4591 | if (err) |
| 4592 | goto err_setup_rx; |
| 4593 | |
| 4594 | ixgbe_configure(adapter); |
| 4595 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4596 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4597 | if (err) |
| 4598 | goto err_req_irq; |
| 4599 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4600 | err = ixgbe_up_complete(adapter); |
| 4601 | if (err) |
| 4602 | goto err_up; |
| 4603 | |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 4604 | netif_tx_start_all_queues(netdev); |
| 4605 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4606 | return 0; |
| 4607 | |
| 4608 | err_up: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 4609 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4610 | ixgbe_free_irq(adapter); |
| 4611 | err_req_irq: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4612 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 4613 | ixgbe_free_all_rx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4614 | err_setup_tx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 4615 | ixgbe_free_all_tx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4616 | ixgbe_reset(adapter); |
| 4617 | |
| 4618 | return err; |
| 4619 | } |
| 4620 | |
| 4621 | /** |
| 4622 | * ixgbe_close - Disables a network interface |
| 4623 | * @netdev: network interface device structure |
| 4624 | * |
| 4625 | * Returns 0, this is not allowed to fail |
| 4626 | * |
| 4627 | * The close entry point is called when an interface is de-activated |
| 4628 | * by the OS. The hardware is still under the drivers control, but |
| 4629 | * needs to be disabled. A global MAC reset is issued to stop the |
| 4630 | * hardware, and all transmit and receive resources are freed. |
| 4631 | **/ |
| 4632 | static int ixgbe_close(struct net_device *netdev) |
| 4633 | { |
| 4634 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4635 | |
| 4636 | ixgbe_down(adapter); |
| 4637 | ixgbe_free_irq(adapter); |
| 4638 | |
| 4639 | ixgbe_free_all_tx_resources(adapter); |
| 4640 | ixgbe_free_all_rx_resources(adapter); |
| 4641 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 4642 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4643 | |
| 4644 | return 0; |
| 4645 | } |
| 4646 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4647 | #ifdef CONFIG_PM |
| 4648 | static int ixgbe_resume(struct pci_dev *pdev) |
| 4649 | { |
| 4650 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4651 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4652 | u32 err; |
| 4653 | |
| 4654 | pci_set_power_state(pdev, PCI_D0); |
| 4655 | pci_restore_state(pdev); |
Don Skidmore | 656ab81 | 2009-12-23 21:19:19 -0800 | [diff] [blame] | 4656 | /* |
| 4657 | * pci_restore_state clears dev->state_saved so call |
| 4658 | * pci_save_state to restore it. |
| 4659 | */ |
| 4660 | pci_save_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 4661 | |
| 4662 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4663 | if (err) { |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4664 | printk(KERN_ERR "ixgbe: Cannot enable PCI device from " |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4665 | "suspend\n"); |
| 4666 | return err; |
| 4667 | } |
| 4668 | pci_set_master(pdev); |
| 4669 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 4670 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4671 | |
| 4672 | err = ixgbe_init_interrupt_scheme(adapter); |
| 4673 | if (err) { |
| 4674 | printk(KERN_ERR "ixgbe: Cannot initialize interrupts for " |
| 4675 | "device\n"); |
| 4676 | return err; |
| 4677 | } |
| 4678 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4679 | ixgbe_reset(adapter); |
| 4680 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 4681 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 4682 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4683 | if (netif_running(netdev)) { |
| 4684 | err = ixgbe_open(adapter->netdev); |
| 4685 | if (err) |
| 4686 | return err; |
| 4687 | } |
| 4688 | |
| 4689 | netif_device_attach(netdev); |
| 4690 | |
| 4691 | return 0; |
| 4692 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4693 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4694 | |
| 4695 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4696 | { |
| 4697 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4698 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4699 | struct ixgbe_hw *hw = &adapter->hw; |
| 4700 | u32 ctrl, fctrl; |
| 4701 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4702 | #ifdef CONFIG_PM |
| 4703 | int retval = 0; |
| 4704 | #endif |
| 4705 | |
| 4706 | netif_device_detach(netdev); |
| 4707 | |
| 4708 | if (netif_running(netdev)) { |
| 4709 | ixgbe_down(adapter); |
| 4710 | ixgbe_free_irq(adapter); |
| 4711 | ixgbe_free_all_tx_resources(adapter); |
| 4712 | ixgbe_free_all_rx_resources(adapter); |
| 4713 | } |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4714 | ixgbe_clear_interrupt_scheme(adapter); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4715 | |
| 4716 | #ifdef CONFIG_PM |
| 4717 | retval = pci_save_state(pdev); |
| 4718 | if (retval) |
| 4719 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4720 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4721 | #endif |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4722 | if (wufc) { |
| 4723 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4724 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4725 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 4726 | if (wufc & IXGBE_WUFC_MC) { |
| 4727 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 4728 | fctrl |= IXGBE_FCTRL_MPE; |
| 4729 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 4730 | } |
| 4731 | |
| 4732 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 4733 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 4734 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 4735 | |
| 4736 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 4737 | } else { |
| 4738 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 4739 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 4740 | } |
| 4741 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 4742 | if (wufc && hw->mac.type == ixgbe_mac_82599EB) |
| 4743 | pci_wake_from_d3(pdev, true); |
| 4744 | else |
| 4745 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4746 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4747 | *enable_wake = !!wufc; |
| 4748 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4749 | ixgbe_release_hw_control(adapter); |
| 4750 | |
| 4751 | pci_disable_device(pdev); |
| 4752 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4753 | return 0; |
| 4754 | } |
| 4755 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4756 | #ifdef CONFIG_PM |
| 4757 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 4758 | { |
| 4759 | int retval; |
| 4760 | bool wake; |
| 4761 | |
| 4762 | retval = __ixgbe_shutdown(pdev, &wake); |
| 4763 | if (retval) |
| 4764 | return retval; |
| 4765 | |
| 4766 | if (wake) { |
| 4767 | pci_prepare_to_sleep(pdev); |
| 4768 | } else { |
| 4769 | pci_wake_from_d3(pdev, false); |
| 4770 | pci_set_power_state(pdev, PCI_D3hot); |
| 4771 | } |
| 4772 | |
| 4773 | return 0; |
| 4774 | } |
| 4775 | #endif /* CONFIG_PM */ |
| 4776 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4777 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 4778 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4779 | bool wake; |
| 4780 | |
| 4781 | __ixgbe_shutdown(pdev, &wake); |
| 4782 | |
| 4783 | if (system_state == SYSTEM_POWER_OFF) { |
| 4784 | pci_wake_from_d3(pdev, wake); |
| 4785 | pci_set_power_state(pdev, PCI_D3hot); |
| 4786 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4787 | } |
| 4788 | |
| 4789 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4790 | * ixgbe_update_stats - Update the board statistics counters. |
| 4791 | * @adapter: board private structure |
| 4792 | **/ |
| 4793 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 4794 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4795 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4796 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4797 | u64 total_mpc = 0; |
| 4798 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 4799 | u64 non_eop_descs = 0, restart_queue = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4800 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 4801 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 4802 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 4803 | u64 rsc_flush = 0; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 4804 | for (i = 0; i < 16; i++) |
| 4805 | adapter->hw_rx_no_dma_resources += |
| 4806 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 4807 | for (i = 0; i < adapter->num_rx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4808 | rsc_count += adapter->rx_ring[i]->rsc_count; |
| 4809 | rsc_flush += adapter->rx_ring[i]->rsc_flush; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 4810 | } |
| 4811 | adapter->rsc_total_count = rsc_count; |
| 4812 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 4813 | } |
| 4814 | |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 4815 | /* gather some stats to the adapter struct that are per queue */ |
| 4816 | for (i = 0; i < adapter->num_tx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4817 | restart_queue += adapter->tx_ring[i]->restart_queue; |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 4818 | adapter->restart_queue = restart_queue; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 4819 | |
| 4820 | for (i = 0; i < adapter->num_rx_queues; i++) |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 4821 | non_eop_descs += adapter->rx_ring[i]->non_eop_descs; |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 4822 | adapter->non_eop_descs = non_eop_descs; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 4823 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4824 | adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4825 | for (i = 0; i < 8; i++) { |
| 4826 | /* for packet buffers not used, the register should read 0 */ |
| 4827 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 4828 | missed_rx += mpc; |
| 4829 | adapter->stats.mpc[i] += mpc; |
| 4830 | total_mpc += adapter->stats.mpc[i]; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4831 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4832 | adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4833 | adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 4834 | adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 4835 | adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 4836 | adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4837 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 4838 | adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw, |
| 4839 | IXGBE_PXONRXCNT(i)); |
| 4840 | adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw, |
| 4841 | IXGBE_PXOFFRXCNT(i)); |
| 4842 | adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4843 | } else { |
| 4844 | adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw, |
| 4845 | IXGBE_PXONRXC(i)); |
| 4846 | adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw, |
| 4847 | IXGBE_PXOFFRXC(i)); |
| 4848 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4849 | adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw, |
| 4850 | IXGBE_PXONTXC(i)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4851 | adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4852 | IXGBE_PXOFFTXC(i)); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4853 | } |
| 4854 | adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
| 4855 | /* work around hardware counting issue */ |
| 4856 | adapter->stats.gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4857 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4858 | /* 82598 hardware only has a 32 bit counter in the high register */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4859 | if (hw->mac.type == ixgbe_mac_82599EB) { |
Ben Greear | aad7191 | 2009-09-30 12:08:16 +0000 | [diff] [blame] | 4860 | u64 tmp; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4861 | adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Ben Greear | aad7191 | 2009-09-30 12:08:16 +0000 | [diff] [blame] | 4862 | tmp = IXGBE_READ_REG(hw, IXGBE_GORCH) & 0xF; /* 4 high bits of GORC */ |
| 4863 | adapter->stats.gorc += (tmp << 32); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4864 | adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Ben Greear | aad7191 | 2009-09-30 12:08:16 +0000 | [diff] [blame] | 4865 | tmp = IXGBE_READ_REG(hw, IXGBE_GOTCH) & 0xF; /* 4 high bits of GOTC */ |
| 4866 | adapter->stats.gotc += (tmp << 32); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4867 | adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
| 4868 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
| 4869 | adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
| 4870 | adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4871 | adapter->stats.fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 4872 | adapter->stats.fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 4873 | #ifdef IXGBE_FCOE |
| 4874 | adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 4875 | adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 4876 | adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 4877 | adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 4878 | adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 4879 | adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
| 4880 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4881 | } else { |
| 4882 | adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
| 4883 | adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 4884 | adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 4885 | adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 4886 | adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 4887 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4888 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
| 4889 | adapter->stats.bprc += bprc; |
| 4890 | adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4891 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4892 | adapter->stats.mprc -= bprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4893 | adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 4894 | adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 4895 | adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 4896 | adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 4897 | adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 4898 | adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 4899 | adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4900 | adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4901 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
| 4902 | adapter->stats.lxontxc += lxon; |
| 4903 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
| 4904 | adapter->stats.lxofftxc += lxoff; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4905 | adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 4906 | adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4907 | adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
| 4908 | /* |
| 4909 | * 82598 errata - tx of flow control packets is included in tx counters |
| 4910 | */ |
| 4911 | xon_off_tot = lxon + lxoff; |
| 4912 | adapter->stats.gptc -= xon_off_tot; |
| 4913 | adapter->stats.mptc -= xon_off_tot; |
| 4914 | adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4915 | adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 4916 | adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 4917 | adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4918 | adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 4919 | adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4920 | adapter->stats.ptc64 -= xon_off_tot; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4921 | adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 4922 | adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 4923 | adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 4924 | adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 4925 | adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4926 | adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
| 4927 | |
| 4928 | /* Fill out the OS statistics structure */ |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4929 | netdev->stats.multicast = adapter->stats.mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4930 | |
| 4931 | /* Rx Errors */ |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4932 | netdev->stats.rx_errors = adapter->stats.crcerrs + |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4933 | adapter->stats.rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4934 | netdev->stats.rx_dropped = 0; |
| 4935 | netdev->stats.rx_length_errors = adapter->stats.rlec; |
| 4936 | netdev->stats.rx_crc_errors = adapter->stats.crcerrs; |
| 4937 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4938 | } |
| 4939 | |
| 4940 | /** |
| 4941 | * ixgbe_watchdog - Timer Call-back |
| 4942 | * @data: pointer to adapter cast into an unsigned long |
| 4943 | **/ |
| 4944 | static void ixgbe_watchdog(unsigned long data) |
| 4945 | { |
| 4946 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4947 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4948 | u64 eics = 0; |
| 4949 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4950 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4951 | /* |
| 4952 | * Do the watchdog outside of interrupt context due to the lovely |
| 4953 | * delays that some of the newer hardware requires |
| 4954 | */ |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 4955 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4956 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 4957 | goto watchdog_short_circuit; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 4958 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4959 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
| 4960 | /* |
| 4961 | * for legacy and MSI interrupts don't set any bits |
| 4962 | * that are enabled for EIAM, because this operation |
| 4963 | * would set *both* EIMS and EICS for any bit in EIAM |
| 4964 | */ |
| 4965 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 4966 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
| 4967 | goto watchdog_reschedule; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4968 | } |
| 4969 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4970 | /* get one bit for every active tx/rx interrupt vector */ |
| 4971 | for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) { |
| 4972 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
| 4973 | if (qv->rxr_count || qv->txr_count) |
| 4974 | eics |= ((u64)1 << i); |
| 4975 | } |
| 4976 | |
| 4977 | /* Cause software interrupt to ensure rx rings are cleaned */ |
| 4978 | ixgbe_irq_rearm_queues(adapter, eics); |
| 4979 | |
| 4980 | watchdog_reschedule: |
| 4981 | /* Reset the timer */ |
| 4982 | mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ)); |
| 4983 | |
| 4984 | watchdog_short_circuit: |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4985 | schedule_work(&adapter->watchdog_task); |
| 4986 | } |
| 4987 | |
| 4988 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4989 | * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber |
| 4990 | * @work: pointer to work_struct containing our data |
| 4991 | **/ |
| 4992 | static void ixgbe_multispeed_fiber_task(struct work_struct *work) |
| 4993 | { |
| 4994 | struct ixgbe_adapter *adapter = container_of(work, |
| 4995 | struct ixgbe_adapter, |
| 4996 | multispeed_fiber_task); |
| 4997 | struct ixgbe_hw *hw = &adapter->hw; |
| 4998 | u32 autoneg; |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 4999 | bool negotiation; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5000 | |
| 5001 | adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK; |
Mallikarjuna R Chilakala | a1f2532 | 2009-06-30 11:44:36 +0000 | [diff] [blame] | 5002 | autoneg = hw->phy.autoneg_advertised; |
| 5003 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 5004 | hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
Mallikarjuna R Chilakala | 1097cd1 | 2010-03-18 14:34:52 +0000 | [diff] [blame] | 5005 | hw->mac.autotry_restart = false; |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 5006 | if (hw->mac.ops.setup_link) |
| 5007 | hw->mac.ops.setup_link(hw, autoneg, negotiation, true); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5008 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 5009 | adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK; |
| 5010 | } |
| 5011 | |
| 5012 | /** |
| 5013 | * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module |
| 5014 | * @work: pointer to work_struct containing our data |
| 5015 | **/ |
| 5016 | static void ixgbe_sfp_config_module_task(struct work_struct *work) |
| 5017 | { |
| 5018 | struct ixgbe_adapter *adapter = container_of(work, |
| 5019 | struct ixgbe_adapter, |
| 5020 | sfp_config_module_task); |
| 5021 | struct ixgbe_hw *hw = &adapter->hw; |
| 5022 | u32 err; |
| 5023 | |
| 5024 | adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK; |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 5025 | |
| 5026 | /* Time for electrical oscillations to settle down */ |
| 5027 | msleep(100); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5028 | err = hw->phy.ops.identify_sfp(hw); |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 5029 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5030 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 88d2b81 | 2009-06-30 11:43:55 +0000 | [diff] [blame] | 5031 | dev_err(&adapter->pdev->dev, "failed to initialize because " |
| 5032 | "an unsupported SFP+ module type was detected.\n" |
| 5033 | "Reload the driver after installing a supported " |
| 5034 | "module.\n"); |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 5035 | unregister_netdev(adapter->netdev); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5036 | return; |
| 5037 | } |
| 5038 | hw->mac.ops.setup_sfp(hw); |
| 5039 | |
Tony Breeds | 8d1c3c0 | 2009-04-09 22:29:10 +0000 | [diff] [blame] | 5040 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK)) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5041 | /* This will also work for DA Twinax connections */ |
| 5042 | schedule_work(&adapter->multispeed_fiber_task); |
| 5043 | adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK; |
| 5044 | } |
| 5045 | |
| 5046 | /** |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5047 | * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table |
| 5048 | * @work: pointer to work_struct containing our data |
| 5049 | **/ |
| 5050 | static void ixgbe_fdir_reinit_task(struct work_struct *work) |
| 5051 | { |
| 5052 | struct ixgbe_adapter *adapter = container_of(work, |
| 5053 | struct ixgbe_adapter, |
| 5054 | fdir_reinit_task); |
| 5055 | struct ixgbe_hw *hw = &adapter->hw; |
| 5056 | int i; |
| 5057 | |
| 5058 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 5059 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 5060 | set_bit(__IXGBE_FDIR_INIT_DONE, |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5061 | &(adapter->tx_ring[i]->reinit_state)); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5062 | } else { |
| 5063 | DPRINTK(PROBE, ERR, "failed to finish FDIR re-initialization, " |
Frans Pop | d6dbee8 | 2010-03-24 07:57:35 +0000 | [diff] [blame] | 5064 | "ignored adding FDIR ATR filters\n"); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5065 | } |
| 5066 | /* Done FDIR Re-initialization, enable transmits */ |
| 5067 | netif_tx_start_all_queues(adapter->netdev); |
| 5068 | } |
| 5069 | |
John Fastabend | 10eec95 | 2010-02-03 14:23:32 +0000 | [diff] [blame] | 5070 | static DEFINE_MUTEX(ixgbe_watchdog_lock); |
| 5071 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5072 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 5073 | * ixgbe_watchdog_task - worker thread to bring link up |
| 5074 | * @work: pointer to work_struct containing our data |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5075 | **/ |
| 5076 | static void ixgbe_watchdog_task(struct work_struct *work) |
| 5077 | { |
| 5078 | struct ixgbe_adapter *adapter = container_of(work, |
| 5079 | struct ixgbe_adapter, |
| 5080 | watchdog_task); |
| 5081 | struct net_device *netdev = adapter->netdev; |
| 5082 | struct ixgbe_hw *hw = &adapter->hw; |
John Fastabend | 10eec95 | 2010-02-03 14:23:32 +0000 | [diff] [blame] | 5083 | u32 link_speed; |
| 5084 | bool link_up; |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 5085 | int i; |
| 5086 | struct ixgbe_ring *tx_ring; |
| 5087 | int some_tx_pending = 0; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5088 | |
John Fastabend | 10eec95 | 2010-02-03 14:23:32 +0000 | [diff] [blame] | 5089 | mutex_lock(&ixgbe_watchdog_lock); |
| 5090 | |
| 5091 | link_up = adapter->link_up; |
| 5092 | link_speed = adapter->link_speed; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5093 | |
| 5094 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) { |
| 5095 | hw->mac.ops.check_link(hw, &link_speed, &link_up, false); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 5096 | if (link_up) { |
| 5097 | #ifdef CONFIG_DCB |
| 5098 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 5099 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 5100 | hw->mac.ops.fc_enable(hw, i); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 5101 | } else { |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 5102 | hw->mac.ops.fc_enable(hw, 0); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 5103 | } |
| 5104 | #else |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 5105 | hw->mac.ops.fc_enable(hw, 0); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 5106 | #endif |
| 5107 | } |
| 5108 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5109 | if (link_up || |
| 5110 | time_after(jiffies, (adapter->link_check_timeout + |
| 5111 | IXGBE_TRY_LINK_TIMEOUT))) { |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5112 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 5113 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5114 | } |
| 5115 | adapter->link_up = link_up; |
| 5116 | adapter->link_speed = link_speed; |
| 5117 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5118 | |
| 5119 | if (link_up) { |
| 5120 | if (!netif_carrier_ok(netdev)) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5121 | bool flow_rx, flow_tx; |
| 5122 | |
| 5123 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 5124 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 5125 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
Peter P Waskiewicz Jr | 078788b | 2009-07-16 15:50:32 +0000 | [diff] [blame] | 5126 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 5127 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5128 | } else { |
| 5129 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 5130 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
Peter P Waskiewicz Jr | 078788b | 2009-07-16 15:50:32 +0000 | [diff] [blame] | 5131 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 5132 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5133 | } |
| 5134 | |
Jeff Kirsher | a46e534 | 2008-11-27 00:22:21 -0800 | [diff] [blame] | 5135 | printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, " |
| 5136 | "Flow Control: %s\n", |
| 5137 | netdev->name, |
| 5138 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? |
| 5139 | "10 Gbps" : |
| 5140 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? |
| 5141 | "1 Gbps" : "unknown speed")), |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5142 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 5143 | (flow_rx ? "RX" : |
| 5144 | (flow_tx ? "TX" : "None")))); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5145 | |
| 5146 | netif_carrier_on(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5147 | } else { |
| 5148 | /* Force detection of hung controller */ |
| 5149 | adapter->detect_tx_hung = true; |
| 5150 | } |
| 5151 | } else { |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5152 | adapter->link_up = false; |
| 5153 | adapter->link_speed = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5154 | if (netif_carrier_ok(netdev)) { |
Jeff Kirsher | a46e534 | 2008-11-27 00:22:21 -0800 | [diff] [blame] | 5155 | printk(KERN_INFO "ixgbe: %s NIC Link is Down\n", |
| 5156 | netdev->name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5157 | netif_carrier_off(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5158 | } |
| 5159 | } |
| 5160 | |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 5161 | if (!netif_carrier_ok(netdev)) { |
| 5162 | for (i = 0; i < adapter->num_tx_queues; i++) { |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5163 | tx_ring = adapter->tx_ring[i]; |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 5164 | if (tx_ring->next_to_use != tx_ring->next_to_clean) { |
| 5165 | some_tx_pending = 1; |
| 5166 | break; |
| 5167 | } |
| 5168 | } |
| 5169 | |
| 5170 | if (some_tx_pending) { |
| 5171 | /* We've lost link, so the controller stops DMA, |
| 5172 | * but we've got queued Tx work that's never going |
| 5173 | * to get done, so reset controller to flush Tx. |
| 5174 | * (Do the reset outside of interrupt context). |
| 5175 | */ |
| 5176 | schedule_work(&adapter->reset_task); |
| 5177 | } |
| 5178 | } |
| 5179 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5180 | ixgbe_update_stats(adapter); |
John Fastabend | 10eec95 | 2010-02-03 14:23:32 +0000 | [diff] [blame] | 5181 | mutex_unlock(&ixgbe_watchdog_lock); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5182 | } |
| 5183 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5184 | static int ixgbe_tso(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5185 | struct ixgbe_ring *tx_ring, struct sk_buff *skb, |
| 5186 | u32 tx_flags, u8 *hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5187 | { |
| 5188 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 5189 | unsigned int i; |
| 5190 | int err; |
| 5191 | struct ixgbe_tx_buffer *tx_buffer_info; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5192 | u32 vlan_macip_lens = 0, type_tucmd_mlhl; |
| 5193 | u32 mss_l4len_idx, l4len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5194 | |
| 5195 | if (skb_is_gso(skb)) { |
| 5196 | if (skb_header_cloned(skb)) { |
| 5197 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 5198 | if (err) |
| 5199 | return err; |
| 5200 | } |
| 5201 | l4len = tcp_hdrlen(skb); |
| 5202 | *hdr_len += l4len; |
| 5203 | |
Al Viro | 8327d00 | 2007-12-10 18:54:12 +0000 | [diff] [blame] | 5204 | if (skb->protocol == htons(ETH_P_IP)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5205 | struct iphdr *iph = ip_hdr(skb); |
| 5206 | iph->tot_len = 0; |
| 5207 | iph->check = 0; |
| 5208 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5209 | iph->daddr, 0, |
| 5210 | IPPROTO_TCP, |
| 5211 | 0); |
Sridhar Samudrala | 8e1e8a4 | 2010-01-23 02:02:21 -0800 | [diff] [blame] | 5212 | } else if (skb_is_gso_v6(skb)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5213 | ipv6_hdr(skb)->payload_len = 0; |
| 5214 | tcp_hdr(skb)->check = |
| 5215 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5216 | &ipv6_hdr(skb)->daddr, |
| 5217 | 0, IPPROTO_TCP, 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5218 | } |
| 5219 | |
| 5220 | i = tx_ring->next_to_use; |
| 5221 | |
| 5222 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5223 | context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i); |
| 5224 | |
| 5225 | /* VLAN MACLEN IPLEN */ |
| 5226 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 5227 | vlan_macip_lens |= |
| 5228 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); |
| 5229 | vlan_macip_lens |= ((skb_network_offset(skb)) << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5230 | IXGBE_ADVTXD_MACLEN_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5231 | *hdr_len += skb_network_offset(skb); |
| 5232 | vlan_macip_lens |= |
| 5233 | (skb_transport_header(skb) - skb_network_header(skb)); |
| 5234 | *hdr_len += |
| 5235 | (skb_transport_header(skb) - skb_network_header(skb)); |
| 5236 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 5237 | context_desc->seqnum_seed = 0; |
| 5238 | |
| 5239 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5240 | type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5241 | IXGBE_ADVTXD_DTYP_CTXT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5242 | |
Al Viro | 8327d00 | 2007-12-10 18:54:12 +0000 | [diff] [blame] | 5243 | if (skb->protocol == htons(ETH_P_IP)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5244 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 5245 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 5246 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); |
| 5247 | |
| 5248 | /* MSS L4LEN IDX */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5249 | mss_l4len_idx = |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5250 | (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT); |
| 5251 | mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT); |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 5252 | /* use index 1 for TSO */ |
| 5253 | mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5254 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 5255 | |
| 5256 | tx_buffer_info->time_stamp = jiffies; |
| 5257 | tx_buffer_info->next_to_watch = i; |
| 5258 | |
| 5259 | i++; |
| 5260 | if (i == tx_ring->count) |
| 5261 | i = 0; |
| 5262 | tx_ring->next_to_use = i; |
| 5263 | |
| 5264 | return true; |
| 5265 | } |
| 5266 | return false; |
| 5267 | } |
| 5268 | |
| 5269 | static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5270 | struct ixgbe_ring *tx_ring, |
| 5271 | struct sk_buff *skb, u32 tx_flags) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5272 | { |
| 5273 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 5274 | unsigned int i; |
| 5275 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 5276 | u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0; |
| 5277 | |
| 5278 | if (skb->ip_summed == CHECKSUM_PARTIAL || |
| 5279 | (tx_flags & IXGBE_TX_FLAGS_VLAN)) { |
| 5280 | i = tx_ring->next_to_use; |
| 5281 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5282 | context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i); |
| 5283 | |
| 5284 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 5285 | vlan_macip_lens |= |
| 5286 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); |
| 5287 | vlan_macip_lens |= (skb_network_offset(skb) << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5288 | IXGBE_ADVTXD_MACLEN_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5289 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 5290 | vlan_macip_lens |= (skb_transport_header(skb) - |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5291 | skb_network_header(skb)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5292 | |
| 5293 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 5294 | context_desc->seqnum_seed = 0; |
| 5295 | |
| 5296 | type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5297 | IXGBE_ADVTXD_DTYP_CTXT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5298 | |
| 5299 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Gurucharan Shetty | ca55398 | 2009-12-15 13:00:31 +0000 | [diff] [blame] | 5300 | __be16 protocol; |
| 5301 | |
| 5302 | if (skb->protocol == cpu_to_be16(ETH_P_8021Q)) { |
| 5303 | const struct vlan_ethhdr *vhdr = |
| 5304 | (const struct vlan_ethhdr *)skb->data; |
| 5305 | |
| 5306 | protocol = vhdr->h_vlan_encapsulated_proto; |
| 5307 | } else { |
| 5308 | protocol = skb->protocol; |
| 5309 | } |
| 5310 | |
| 5311 | switch (protocol) { |
Harvey Harrison | 09640e63 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 5312 | case cpu_to_be16(ETH_P_IP): |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5313 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5314 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 5315 | type_tucmd_mlhl |= |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5316 | IXGBE_ADVTXD_TUCMD_L4T_TCP; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 5317 | else if (ip_hdr(skb)->protocol == IPPROTO_SCTP) |
| 5318 | type_tucmd_mlhl |= |
| 5319 | IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5320 | break; |
Harvey Harrison | 09640e63 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 5321 | case cpu_to_be16(ETH_P_IPV6): |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5322 | /* XXX what about other V6 headers?? */ |
| 5323 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 5324 | type_tucmd_mlhl |= |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5325 | IXGBE_ADVTXD_TUCMD_L4T_TCP; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 5326 | else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP) |
| 5327 | type_tucmd_mlhl |= |
| 5328 | IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5329 | break; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5330 | default: |
| 5331 | if (unlikely(net_ratelimit())) { |
| 5332 | DPRINTK(PROBE, WARNING, |
| 5333 | "partial checksum but proto=%x!\n", |
| 5334 | skb->protocol); |
| 5335 | } |
| 5336 | break; |
| 5337 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5338 | } |
| 5339 | |
| 5340 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 5341 | /* use index zero for tx checksum offload */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5342 | context_desc->mss_l4len_idx = 0; |
| 5343 | |
| 5344 | tx_buffer_info->time_stamp = jiffies; |
| 5345 | tx_buffer_info->next_to_watch = i; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5346 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5347 | i++; |
| 5348 | if (i == tx_ring->count) |
| 5349 | i = 0; |
| 5350 | tx_ring->next_to_use = i; |
| 5351 | |
| 5352 | return true; |
| 5353 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5354 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5355 | return false; |
| 5356 | } |
| 5357 | |
| 5358 | static int ixgbe_tx_map(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5359 | struct ixgbe_ring *tx_ring, |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5360 | struct sk_buff *skb, u32 tx_flags, |
| 5361 | unsigned int first) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5362 | { |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5363 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5364 | struct ixgbe_tx_buffer *tx_buffer_info; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5365 | unsigned int len; |
| 5366 | unsigned int total = skb->len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5367 | unsigned int offset = 0, size, count = 0, i; |
| 5368 | unsigned int nr_frags = skb_shinfo(skb)->nr_frags; |
| 5369 | unsigned int f; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5370 | |
| 5371 | i = tx_ring->next_to_use; |
| 5372 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5373 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) |
| 5374 | /* excluding fcoe_crc_eof for FCoE */ |
| 5375 | total -= sizeof(struct fcoe_crc_eof); |
| 5376 | |
| 5377 | len = min(skb_headlen(skb), total); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5378 | while (len) { |
| 5379 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5380 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 5381 | |
| 5382 | tx_buffer_info->length = size; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5383 | tx_buffer_info->mapped_as_page = false; |
| 5384 | tx_buffer_info->dma = pci_map_single(pdev, |
| 5385 | skb->data + offset, |
| 5386 | size, PCI_DMA_TODEVICE); |
| 5387 | if (pci_dma_mapping_error(pdev, tx_buffer_info->dma)) |
| 5388 | goto dma_error; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5389 | tx_buffer_info->time_stamp = jiffies; |
| 5390 | tx_buffer_info->next_to_watch = i; |
| 5391 | |
| 5392 | len -= size; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5393 | total -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5394 | offset += size; |
| 5395 | count++; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5396 | |
| 5397 | if (len) { |
| 5398 | i++; |
| 5399 | if (i == tx_ring->count) |
| 5400 | i = 0; |
| 5401 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5402 | } |
| 5403 | |
| 5404 | for (f = 0; f < nr_frags; f++) { |
| 5405 | struct skb_frag_struct *frag; |
| 5406 | |
| 5407 | frag = &skb_shinfo(skb)->frags[f]; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5408 | len = min((unsigned int)frag->size, total); |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5409 | offset = frag->page_offset; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5410 | |
| 5411 | while (len) { |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5412 | i++; |
| 5413 | if (i == tx_ring->count) |
| 5414 | i = 0; |
| 5415 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5416 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5417 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 5418 | |
| 5419 | tx_buffer_info->length = size; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5420 | tx_buffer_info->dma = pci_map_page(adapter->pdev, |
| 5421 | frag->page, |
| 5422 | offset, size, |
| 5423 | PCI_DMA_TODEVICE); |
| 5424 | tx_buffer_info->mapped_as_page = true; |
| 5425 | if (pci_dma_mapping_error(pdev, tx_buffer_info->dma)) |
| 5426 | goto dma_error; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5427 | tx_buffer_info->time_stamp = jiffies; |
| 5428 | tx_buffer_info->next_to_watch = i; |
| 5429 | |
| 5430 | len -= size; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5431 | total -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5432 | offset += size; |
| 5433 | count++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5434 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5435 | if (total == 0) |
| 5436 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5437 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5438 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5439 | tx_ring->tx_buffer_info[i].skb = skb; |
| 5440 | tx_ring->tx_buffer_info[first].next_to_watch = i; |
| 5441 | |
| 5442 | return count; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5443 | |
| 5444 | dma_error: |
| 5445 | dev_err(&pdev->dev, "TX DMA map failed\n"); |
| 5446 | |
| 5447 | /* clear timestamp and dma mappings for failed tx_buffer_info map */ |
| 5448 | tx_buffer_info->dma = 0; |
| 5449 | tx_buffer_info->time_stamp = 0; |
| 5450 | tx_buffer_info->next_to_watch = 0; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 5451 | if (count) |
| 5452 | count--; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5453 | |
| 5454 | /* clear timestamp and dma mappings for remaining portion of packet */ |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 5455 | while (count--) { |
| 5456 | if (i==0) |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5457 | i += tx_ring->count; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 5458 | i--; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5459 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5460 | ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info); |
| 5461 | } |
| 5462 | |
Anton Blanchard | e44d38e | 2010-02-03 13:12:51 +0000 | [diff] [blame] | 5463 | return 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5464 | } |
| 5465 | |
| 5466 | static void ixgbe_tx_queue(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5467 | struct ixgbe_ring *tx_ring, |
| 5468 | int tx_flags, int count, u32 paylen, u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5469 | { |
| 5470 | union ixgbe_adv_tx_desc *tx_desc = NULL; |
| 5471 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 5472 | u32 olinfo_status = 0, cmd_type_len = 0; |
| 5473 | unsigned int i; |
| 5474 | u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS; |
| 5475 | |
| 5476 | cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA; |
| 5477 | |
| 5478 | cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT; |
| 5479 | |
| 5480 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 5481 | cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE; |
| 5482 | |
| 5483 | if (tx_flags & IXGBE_TX_FLAGS_TSO) { |
| 5484 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 5485 | |
| 5486 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5487 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5488 | |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 5489 | /* use index 1 context for tso */ |
| 5490 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5491 | if (tx_flags & IXGBE_TX_FLAGS_IPV4) |
| 5492 | olinfo_status |= IXGBE_TXD_POPTS_IXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5493 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5494 | |
| 5495 | } else if (tx_flags & IXGBE_TX_FLAGS_CSUM) |
| 5496 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5497 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5498 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5499 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 5500 | olinfo_status |= IXGBE_ADVTXD_CC; |
| 5501 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
| 5502 | if (tx_flags & IXGBE_TX_FLAGS_FSO) |
| 5503 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 5504 | } |
| 5505 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5506 | olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT); |
| 5507 | |
| 5508 | i = tx_ring->next_to_use; |
| 5509 | while (count--) { |
| 5510 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5511 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); |
| 5512 | tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma); |
| 5513 | tx_desc->read.cmd_type_len = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5514 | cpu_to_le32(cmd_type_len | tx_buffer_info->length); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5515 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5516 | i++; |
| 5517 | if (i == tx_ring->count) |
| 5518 | i = 0; |
| 5519 | } |
| 5520 | |
| 5521 | tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd); |
| 5522 | |
| 5523 | /* |
| 5524 | * Force memory writes to complete before letting h/w |
| 5525 | * know there are new descriptors to fetch. (Only |
| 5526 | * applicable for weak-ordered memory model archs, |
| 5527 | * such as IA-64). |
| 5528 | */ |
| 5529 | wmb(); |
| 5530 | |
| 5531 | tx_ring->next_to_use = i; |
| 5532 | writel(i, adapter->hw.hw_addr + tx_ring->tail); |
| 5533 | } |
| 5534 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5535 | static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb, |
| 5536 | int queue, u32 tx_flags) |
| 5537 | { |
| 5538 | /* Right now, we support IPv4 only */ |
| 5539 | struct ixgbe_atr_input atr_input; |
| 5540 | struct tcphdr *th; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5541 | struct iphdr *iph = ip_hdr(skb); |
| 5542 | struct ethhdr *eth = (struct ethhdr *)skb->data; |
| 5543 | u16 vlan_id, src_port, dst_port, flex_bytes; |
| 5544 | u32 src_ipv4_addr, dst_ipv4_addr; |
| 5545 | u8 l4type = 0; |
| 5546 | |
| 5547 | /* check if we're UDP or TCP */ |
| 5548 | if (iph->protocol == IPPROTO_TCP) { |
| 5549 | th = tcp_hdr(skb); |
| 5550 | src_port = th->source; |
| 5551 | dst_port = th->dest; |
| 5552 | l4type |= IXGBE_ATR_L4TYPE_TCP; |
| 5553 | /* l4type IPv4 type is 0, no need to assign */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5554 | } else { |
| 5555 | /* Unsupported L4 header, just bail here */ |
| 5556 | return; |
| 5557 | } |
| 5558 | |
| 5559 | memset(&atr_input, 0, sizeof(struct ixgbe_atr_input)); |
| 5560 | |
| 5561 | vlan_id = (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK) >> |
| 5562 | IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5563 | src_ipv4_addr = iph->saddr; |
| 5564 | dst_ipv4_addr = iph->daddr; |
| 5565 | flex_bytes = eth->h_proto; |
| 5566 | |
| 5567 | ixgbe_atr_set_vlan_id_82599(&atr_input, vlan_id); |
| 5568 | ixgbe_atr_set_src_port_82599(&atr_input, dst_port); |
| 5569 | ixgbe_atr_set_dst_port_82599(&atr_input, src_port); |
| 5570 | ixgbe_atr_set_flex_byte_82599(&atr_input, flex_bytes); |
| 5571 | ixgbe_atr_set_l4type_82599(&atr_input, l4type); |
| 5572 | /* src and dst are inverted, think how the receiver sees them */ |
| 5573 | ixgbe_atr_set_src_ipv4_82599(&atr_input, dst_ipv4_addr); |
| 5574 | ixgbe_atr_set_dst_ipv4_82599(&atr_input, src_ipv4_addr); |
| 5575 | |
| 5576 | /* This assumes the Rx queue and Tx queue are bound to the same CPU */ |
| 5577 | ixgbe_fdir_add_signature_filter_82599(&adapter->hw, &atr_input, queue); |
| 5578 | } |
| 5579 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5580 | static int __ixgbe_maybe_stop_tx(struct net_device *netdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5581 | struct ixgbe_ring *tx_ring, int size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5582 | { |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5583 | netif_stop_subqueue(netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5584 | /* Herbert's original patch had: |
| 5585 | * smp_mb__after_netif_stop_queue(); |
| 5586 | * but since that doesn't exist yet, just open code it. */ |
| 5587 | smp_mb(); |
| 5588 | |
| 5589 | /* We need to check again in a case another CPU has just |
| 5590 | * made room available. */ |
| 5591 | if (likely(IXGBE_DESC_UNUSED(tx_ring) < size)) |
| 5592 | return -EBUSY; |
| 5593 | |
| 5594 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
Jesse Brandeburg | af72166 | 2008-09-11 19:54:23 -0700 | [diff] [blame] | 5595 | netif_start_subqueue(netdev, tx_ring->queue_index); |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 5596 | ++tx_ring->restart_queue; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5597 | return 0; |
| 5598 | } |
| 5599 | |
| 5600 | static int ixgbe_maybe_stop_tx(struct net_device *netdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5601 | struct ixgbe_ring *tx_ring, int size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5602 | { |
| 5603 | if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size)) |
| 5604 | return 0; |
| 5605 | return __ixgbe_maybe_stop_tx(netdev, tx_ring, size); |
| 5606 | } |
| 5607 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5608 | static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb) |
| 5609 | { |
| 5610 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5611 | int txq = smp_processor_id(); |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5612 | |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 5613 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 5614 | while (unlikely(txq >= dev->real_num_tx_queues)) |
| 5615 | txq -= dev->real_num_tx_queues; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5616 | return txq; |
Krishna Kumar | fdd3d63 | 2010-02-03 13:13:10 +0000 | [diff] [blame] | 5617 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5618 | |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5619 | #ifdef IXGBE_FCOE |
| 5620 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 5621 | (skb->protocol == htons(ETH_P_FCOE))) { |
| 5622 | txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1); |
| 5623 | txq += adapter->ring_feature[RING_F_FCOE].mask; |
| 5624 | return txq; |
| 5625 | } |
| 5626 | #endif |
John Fastabend | 2ea186a | 2010-02-27 03:28:24 -0800 | [diff] [blame] | 5627 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 5628 | if (skb->priority == TC_PRIO_CONTROL) |
| 5629 | txq = adapter->ring_feature[RING_F_DCB].indices-1; |
| 5630 | else |
| 5631 | txq = (skb->vlan_tci & IXGBE_TX_FLAGS_VLAN_PRIO_MASK) |
| 5632 | >> 13; |
| 5633 | return txq; |
| 5634 | } |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5635 | |
| 5636 | return skb_tx_hash(dev, skb); |
| 5637 | } |
| 5638 | |
Stephen Hemminger | 3b29a56 | 2009-08-31 19:50:55 +0000 | [diff] [blame] | 5639 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, |
| 5640 | struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5641 | { |
| 5642 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5643 | struct ixgbe_ring *tx_ring; |
Eric Dumazet | 60d5113 | 2009-12-08 07:22:03 +0000 | [diff] [blame] | 5644 | struct netdev_queue *txq; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5645 | unsigned int first; |
| 5646 | unsigned int tx_flags = 0; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5647 | u8 hdr_len = 0; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5648 | int tso; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5649 | int count = 0; |
| 5650 | unsigned int f; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5651 | |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5652 | if (adapter->vlgrp && vlan_tx_tag_present(skb)) { |
| 5653 | tx_flags |= vlan_tx_tag_get(skb); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5654 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 5655 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5656 | tx_flags |= ((skb->queue_mapping & 0x7) << 13); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5657 | } |
| 5658 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5659 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
| 5660 | } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
John Fastabend | 2ea186a | 2010-02-27 03:28:24 -0800 | [diff] [blame] | 5661 | tx_flags |= ((skb->queue_mapping & 0x7) << 13); |
| 5662 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5663 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5664 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5665 | |
PJ Waskiewicz | 4a0b9ca | 2010-02-03 14:19:12 +0000 | [diff] [blame] | 5666 | tx_ring = adapter->tx_ring[skb->queue_mapping]; |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 5667 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5668 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
Yi Zou | 09ad1cc | 2009-09-03 14:56:10 +0000 | [diff] [blame] | 5669 | (skb->protocol == htons(ETH_P_FCOE))) { |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5670 | tx_flags |= IXGBE_TX_FLAGS_FCOE; |
Yi Zou | 09ad1cc | 2009-09-03 14:56:10 +0000 | [diff] [blame] | 5671 | #ifdef IXGBE_FCOE |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 5672 | #ifdef CONFIG_IXGBE_DCB |
| 5673 | tx_flags &= ~(IXGBE_TX_FLAGS_VLAN_PRIO_MASK |
| 5674 | << IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 5675 | tx_flags |= ((adapter->fcoe.up << 13) |
| 5676 | << IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 5677 | #endif |
Yi Zou | 09ad1cc | 2009-09-03 14:56:10 +0000 | [diff] [blame] | 5678 | #endif |
| 5679 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5680 | /* four things can cause us to need a context descriptor */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5681 | if (skb_is_gso(skb) || |
| 5682 | (skb->ip_summed == CHECKSUM_PARTIAL) || |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5683 | (tx_flags & IXGBE_TX_FLAGS_VLAN) || |
| 5684 | (tx_flags & IXGBE_TX_FLAGS_FCOE)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5685 | count++; |
| 5686 | |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5687 | count += TXD_USE_COUNT(skb_headlen(skb)); |
| 5688 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5689 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
| 5690 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5691 | if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5692 | adapter->tx_busy++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5693 | return NETDEV_TX_BUSY; |
| 5694 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5695 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5696 | first = tx_ring->next_to_use; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5697 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 5698 | #ifdef IXGBE_FCOE |
| 5699 | /* setup tx offload for FCoE */ |
| 5700 | tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len); |
| 5701 | if (tso < 0) { |
| 5702 | dev_kfree_skb_any(skb); |
| 5703 | return NETDEV_TX_OK; |
| 5704 | } |
| 5705 | if (tso) |
| 5706 | tx_flags |= IXGBE_TX_FLAGS_FSO; |
| 5707 | #endif /* IXGBE_FCOE */ |
| 5708 | } else { |
| 5709 | if (skb->protocol == htons(ETH_P_IP)) |
| 5710 | tx_flags |= IXGBE_TX_FLAGS_IPV4; |
| 5711 | tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len); |
| 5712 | if (tso < 0) { |
| 5713 | dev_kfree_skb_any(skb); |
| 5714 | return NETDEV_TX_OK; |
| 5715 | } |
| 5716 | |
| 5717 | if (tso) |
| 5718 | tx_flags |= IXGBE_TX_FLAGS_TSO; |
| 5719 | else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) && |
| 5720 | (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 5721 | tx_flags |= IXGBE_TX_FLAGS_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5722 | } |
| 5723 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5724 | count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5725 | if (count) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5726 | /* add the ATR filter if ATR is on */ |
| 5727 | if (tx_ring->atr_sample_rate) { |
| 5728 | ++tx_ring->atr_count; |
| 5729 | if ((tx_ring->atr_count >= tx_ring->atr_sample_rate) && |
| 5730 | test_bit(__IXGBE_FDIR_INIT_DONE, |
| 5731 | &tx_ring->reinit_state)) { |
| 5732 | ixgbe_atr(adapter, skb, tx_ring->queue_index, |
| 5733 | tx_flags); |
| 5734 | tx_ring->atr_count = 0; |
| 5735 | } |
| 5736 | } |
Eric Dumazet | 60d5113 | 2009-12-08 07:22:03 +0000 | [diff] [blame] | 5737 | txq = netdev_get_tx_queue(netdev, tx_ring->queue_index); |
| 5738 | txq->tx_bytes += skb->len; |
| 5739 | txq->tx_packets++; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5740 | ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len, |
| 5741 | hdr_len); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5742 | ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5743 | |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5744 | } else { |
| 5745 | dev_kfree_skb_any(skb); |
| 5746 | tx_ring->tx_buffer_info[first].time_stamp = 0; |
| 5747 | tx_ring->next_to_use = first; |
| 5748 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5749 | |
| 5750 | return NETDEV_TX_OK; |
| 5751 | } |
| 5752 | |
| 5753 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5754 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
| 5755 | * @netdev: network interface device structure |
| 5756 | * @p: pointer to an address structure |
| 5757 | * |
| 5758 | * Returns 0 on success, negative on failure |
| 5759 | **/ |
| 5760 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 5761 | { |
| 5762 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5763 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5764 | struct sockaddr *addr = p; |
| 5765 | |
| 5766 | if (!is_valid_ether_addr(addr->sa_data)) |
| 5767 | return -EADDRNOTAVAIL; |
| 5768 | |
| 5769 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5770 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5771 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 5772 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, adapter->num_vfs, |
| 5773 | IXGBE_RAH_AV); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5774 | |
| 5775 | return 0; |
| 5776 | } |
| 5777 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5778 | static int |
| 5779 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 5780 | { |
| 5781 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5782 | struct ixgbe_hw *hw = &adapter->hw; |
| 5783 | u16 value; |
| 5784 | int rc; |
| 5785 | |
| 5786 | if (prtad != hw->phy.mdio.prtad) |
| 5787 | return -EINVAL; |
| 5788 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 5789 | if (!rc) |
| 5790 | rc = value; |
| 5791 | return rc; |
| 5792 | } |
| 5793 | |
| 5794 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 5795 | u16 addr, u16 value) |
| 5796 | { |
| 5797 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5798 | struct ixgbe_hw *hw = &adapter->hw; |
| 5799 | |
| 5800 | if (prtad != hw->phy.mdio.prtad) |
| 5801 | return -EINVAL; |
| 5802 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 5803 | } |
| 5804 | |
| 5805 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 5806 | { |
| 5807 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5808 | |
| 5809 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 5810 | } |
| 5811 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5812 | /** |
| 5813 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 5814 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5815 | * @netdev: network interface device structure |
| 5816 | * |
| 5817 | * Returns non-zero on failure |
| 5818 | **/ |
| 5819 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
| 5820 | { |
| 5821 | int err = 0; |
| 5822 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 5823 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 5824 | |
| 5825 | if (is_valid_ether_addr(mac->san_addr)) { |
| 5826 | rtnl_lock(); |
| 5827 | err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 5828 | rtnl_unlock(); |
| 5829 | } |
| 5830 | return err; |
| 5831 | } |
| 5832 | |
| 5833 | /** |
| 5834 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 5835 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5836 | * @netdev: network interface device structure |
| 5837 | * |
| 5838 | * Returns non-zero on failure |
| 5839 | **/ |
| 5840 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 5841 | { |
| 5842 | int err = 0; |
| 5843 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 5844 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 5845 | |
| 5846 | if (is_valid_ether_addr(mac->san_addr)) { |
| 5847 | rtnl_lock(); |
| 5848 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 5849 | rtnl_unlock(); |
| 5850 | } |
| 5851 | return err; |
| 5852 | } |
| 5853 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5854 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5855 | /* |
| 5856 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 5857 | * without having to re-enable interrupts. It's not called while |
| 5858 | * the interrupt routine is executing. |
| 5859 | */ |
| 5860 | static void ixgbe_netpoll(struct net_device *netdev) |
| 5861 | { |
| 5862 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 5863 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5864 | |
Alexander Duyck | 1a647bd | 2010-01-13 01:49:13 +0000 | [diff] [blame] | 5865 | /* if interface is down do nothing */ |
| 5866 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 5867 | return; |
| 5868 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5869 | adapter->flags |= IXGBE_FLAG_IN_NETPOLL; |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 5870 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 5871 | int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 5872 | for (i = 0; i < num_q_vectors; i++) { |
| 5873 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
| 5874 | ixgbe_msix_clean_many(0, q_vector); |
| 5875 | } |
| 5876 | } else { |
| 5877 | ixgbe_intr(adapter->pdev->irq, netdev); |
| 5878 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5879 | adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5880 | } |
| 5881 | #endif |
| 5882 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5883 | static const struct net_device_ops ixgbe_netdev_ops = { |
| 5884 | .ndo_open = ixgbe_open, |
| 5885 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 5886 | .ndo_start_xmit = ixgbe_xmit_frame, |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5887 | .ndo_select_queue = ixgbe_select_queue, |
Chris Leech | e90d400 | 2009-03-10 16:00:24 +0000 | [diff] [blame] | 5888 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5889 | .ndo_set_multicast_list = ixgbe_set_rx_mode, |
| 5890 | .ndo_validate_addr = eth_validate_addr, |
| 5891 | .ndo_set_mac_address = ixgbe_set_mac, |
| 5892 | .ndo_change_mtu = ixgbe_change_mtu, |
| 5893 | .ndo_tx_timeout = ixgbe_tx_timeout, |
| 5894 | .ndo_vlan_rx_register = ixgbe_vlan_rx_register, |
| 5895 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 5896 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5897 | .ndo_do_ioctl = ixgbe_ioctl, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5898 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5899 | .ndo_poll_controller = ixgbe_netpoll, |
| 5900 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 5901 | #ifdef IXGBE_FCOE |
| 5902 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
| 5903 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 5904 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 5905 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 5906 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 5907 | #endif /* IXGBE_FCOE */ |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5908 | }; |
| 5909 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 5910 | static void __devinit ixgbe_probe_vf(struct ixgbe_adapter *adapter, |
| 5911 | const struct ixgbe_info *ii) |
| 5912 | { |
| 5913 | #ifdef CONFIG_PCI_IOV |
| 5914 | struct ixgbe_hw *hw = &adapter->hw; |
| 5915 | int err; |
| 5916 | |
| 5917 | if (hw->mac.type != ixgbe_mac_82599EB || !max_vfs) |
| 5918 | return; |
| 5919 | |
| 5920 | /* The 82599 supports up to 64 VFs per physical function |
| 5921 | * but this implementation limits allocation to 63 so that |
| 5922 | * basic networking resources are still available to the |
| 5923 | * physical function |
| 5924 | */ |
| 5925 | adapter->num_vfs = (max_vfs > 63) ? 63 : max_vfs; |
| 5926 | adapter->flags |= IXGBE_FLAG_SRIOV_ENABLED; |
| 5927 | err = pci_enable_sriov(adapter->pdev, adapter->num_vfs); |
| 5928 | if (err) { |
| 5929 | DPRINTK(PROBE, ERR, |
| 5930 | "Failed to enable PCI sriov: %d\n", err); |
| 5931 | goto err_novfs; |
| 5932 | } |
| 5933 | /* If call to enable VFs succeeded then allocate memory |
| 5934 | * for per VF control structures. |
| 5935 | */ |
| 5936 | adapter->vfinfo = |
| 5937 | kcalloc(adapter->num_vfs, |
| 5938 | sizeof(struct vf_data_storage), GFP_KERNEL); |
| 5939 | if (adapter->vfinfo) { |
| 5940 | /* Now that we're sure SR-IOV is enabled |
| 5941 | * and memory allocated set up the mailbox parameters |
| 5942 | */ |
| 5943 | ixgbe_init_mbx_params_pf(hw); |
| 5944 | memcpy(&hw->mbx.ops, ii->mbx_ops, |
| 5945 | sizeof(hw->mbx.ops)); |
| 5946 | |
| 5947 | /* Disable RSC when in SR-IOV mode */ |
| 5948 | adapter->flags2 &= ~(IXGBE_FLAG2_RSC_CAPABLE | |
| 5949 | IXGBE_FLAG2_RSC_ENABLED); |
| 5950 | return; |
| 5951 | } |
| 5952 | |
| 5953 | /* Oh oh */ |
| 5954 | DPRINTK(PROBE, ERR, |
| 5955 | "Unable to allocate memory for VF " |
| 5956 | "Data Storage - SRIOV disabled\n"); |
| 5957 | pci_disable_sriov(adapter->pdev); |
| 5958 | |
| 5959 | err_novfs: |
| 5960 | adapter->flags &= ~IXGBE_FLAG_SRIOV_ENABLED; |
| 5961 | adapter->num_vfs = 0; |
| 5962 | #endif /* CONFIG_PCI_IOV */ |
| 5963 | } |
| 5964 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5965 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5966 | * ixgbe_probe - Device Initialization Routine |
| 5967 | * @pdev: PCI device information struct |
| 5968 | * @ent: entry in ixgbe_pci_tbl |
| 5969 | * |
| 5970 | * Returns 0 on success, negative on failure |
| 5971 | * |
| 5972 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 5973 | * The OS initialization, configuring of the adapter private structure, |
| 5974 | * and a hardware reset occur. |
| 5975 | **/ |
| 5976 | static int __devinit ixgbe_probe(struct pci_dev *pdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5977 | const struct pci_device_id *ent) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5978 | { |
| 5979 | struct net_device *netdev; |
| 5980 | struct ixgbe_adapter *adapter = NULL; |
| 5981 | struct ixgbe_hw *hw; |
| 5982 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5983 | static int cards_found; |
| 5984 | int i, err, pci_using_dac; |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 5985 | unsigned int indices = num_possible_cpus(); |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5986 | #ifdef IXGBE_FCOE |
| 5987 | u16 device_caps; |
| 5988 | #endif |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5989 | u32 part_num, eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5990 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5991 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5992 | if (err) |
| 5993 | return err; |
| 5994 | |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 5995 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
| 5996 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5997 | pci_using_dac = 1; |
| 5998 | } else { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5999 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6000 | if (err) { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 6001 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6002 | if (err) { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6003 | dev_err(&pdev->dev, "No usable DMA " |
| 6004 | "configuration, aborting\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6005 | goto err_dma; |
| 6006 | } |
| 6007 | } |
| 6008 | pci_using_dac = 0; |
| 6009 | } |
| 6010 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 6011 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
| 6012 | IORESOURCE_MEM), ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6013 | if (err) { |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 6014 | dev_err(&pdev->dev, |
| 6015 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6016 | goto err_pci_reg; |
| 6017 | } |
| 6018 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 6019 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6020 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6021 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 6022 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6023 | |
John Fastabend | c85a261 | 2010-02-25 23:15:21 +0000 | [diff] [blame] | 6024 | if (ii->mac == ixgbe_mac_82598EB) |
| 6025 | indices = min_t(unsigned int, indices, IXGBE_MAX_RSS_INDICES); |
| 6026 | else |
| 6027 | indices = min_t(unsigned int, indices, IXGBE_MAX_FDIR_INDICES); |
| 6028 | |
| 6029 | indices = max_t(unsigned int, indices, IXGBE_MAX_DCB_INDICES); |
| 6030 | #ifdef IXGBE_FCOE |
| 6031 | indices += min_t(unsigned int, num_possible_cpus(), |
| 6032 | IXGBE_MAX_FCOE_INDICES); |
| 6033 | #endif |
| 6034 | indices = min_t(unsigned int, indices, MAX_TX_QUEUES); |
| 6035 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), indices); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6036 | if (!netdev) { |
| 6037 | err = -ENOMEM; |
| 6038 | goto err_alloc_etherdev; |
| 6039 | } |
| 6040 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6041 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 6042 | |
| 6043 | pci_set_drvdata(pdev, netdev); |
| 6044 | adapter = netdev_priv(netdev); |
| 6045 | |
| 6046 | adapter->netdev = netdev; |
| 6047 | adapter->pdev = pdev; |
| 6048 | hw = &adapter->hw; |
| 6049 | hw->back = adapter; |
| 6050 | adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
| 6051 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 6052 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
| 6053 | pci_resource_len(pdev, 0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6054 | if (!hw->hw_addr) { |
| 6055 | err = -EIO; |
| 6056 | goto err_ioremap; |
| 6057 | } |
| 6058 | |
| 6059 | for (i = 1; i <= 5; i++) { |
| 6060 | if (pci_resource_len(pdev, i) == 0) |
| 6061 | continue; |
| 6062 | } |
| 6063 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 6064 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6065 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6066 | netdev->watchdog_timeo = 5 * HZ; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6067 | strcpy(netdev->name, pci_name(pdev)); |
| 6068 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6069 | adapter->bd_number = cards_found; |
| 6070 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6071 | /* Setup hw api */ |
| 6072 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6073 | hw->mac.type = ii->mac; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6074 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 6075 | /* EEPROM */ |
| 6076 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); |
| 6077 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 6078 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
| 6079 | if (!(eec & (1 << 8))) |
| 6080 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 6081 | |
| 6082 | /* PHY */ |
| 6083 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 6084 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 6085 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 6086 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 6087 | hw->phy.mdio.mmds = 0; |
| 6088 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 6089 | hw->phy.mdio.dev = netdev; |
| 6090 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 6091 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 6092 | |
| 6093 | /* set up this timer and work struct before calling get_invariants |
| 6094 | * which might start the timer |
| 6095 | */ |
| 6096 | init_timer(&adapter->sfp_timer); |
| 6097 | adapter->sfp_timer.function = &ixgbe_sfp_timer; |
| 6098 | adapter->sfp_timer.data = (unsigned long) adapter; |
| 6099 | |
| 6100 | INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 6101 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6102 | /* multispeed fiber has its own tasklet, called from GPI SDP1 context */ |
| 6103 | INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task); |
| 6104 | |
| 6105 | /* a new SFP+ module arrival, called from GPI SDP2 context */ |
| 6106 | INIT_WORK(&adapter->sfp_config_module_task, |
| 6107 | ixgbe_sfp_config_module_task); |
| 6108 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 6109 | ii->get_invariants(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6110 | |
| 6111 | /* setup the private structure */ |
| 6112 | err = ixgbe_sw_init(adapter); |
| 6113 | if (err) |
| 6114 | goto err_sw_init; |
| 6115 | |
Don Skidmore | e86bff0 | 2010-02-11 04:14:08 +0000 | [diff] [blame] | 6116 | /* Make it possible the adapter to be woken up via WOL */ |
| 6117 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 6118 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 6119 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 6120 | /* |
| 6121 | * If there is a fan on this device and it has failed log the |
| 6122 | * failure. |
| 6123 | */ |
| 6124 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 6125 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 6126 | if (esdp & IXGBE_ESDP_SDP1) |
| 6127 | DPRINTK(PROBE, CRIT, |
| 6128 | "Fan has stopped, replace the adapter\n"); |
| 6129 | } |
| 6130 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 6131 | /* reset_hw fills in the perm_addr as well */ |
| 6132 | err = hw->mac.ops.reset_hw(hw); |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 6133 | if (err == IXGBE_ERR_SFP_NOT_PRESENT && |
| 6134 | hw->mac.type == ixgbe_mac_82598EB) { |
| 6135 | /* |
| 6136 | * Start a kernel thread to watch for a module to arrive. |
| 6137 | * Only do this for 82598, since 82599 will generate |
| 6138 | * interrupts on module arrival. |
| 6139 | */ |
| 6140 | set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 6141 | mod_timer(&adapter->sfp_timer, |
| 6142 | round_jiffies(jiffies + (2 * HZ))); |
| 6143 | err = 0; |
| 6144 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 88d2b81 | 2009-06-30 11:43:55 +0000 | [diff] [blame] | 6145 | dev_err(&adapter->pdev->dev, "failed to initialize because " |
| 6146 | "an unsupported SFP+ module type was detected.\n" |
| 6147 | "Reload the driver after installing a supported " |
| 6148 | "module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 6149 | goto err_sw_init; |
| 6150 | } else if (err) { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 6151 | dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err); |
| 6152 | goto err_sw_init; |
| 6153 | } |
| 6154 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 6155 | ixgbe_probe_vf(adapter, ii); |
| 6156 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6157 | netdev->features = NETIF_F_SG | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6158 | NETIF_F_IP_CSUM | |
| 6159 | NETIF_F_HW_VLAN_TX | |
| 6160 | NETIF_F_HW_VLAN_RX | |
| 6161 | NETIF_F_HW_VLAN_FILTER; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6162 | |
Jesse Brandeburg | e9990a9 | 2008-08-26 04:27:24 -0700 | [diff] [blame] | 6163 | netdev->features |= NETIF_F_IPV6_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6164 | netdev->features |= NETIF_F_TSO; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6165 | netdev->features |= NETIF_F_TSO6; |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 6166 | netdev->features |= NETIF_F_GRO; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 6167 | |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 6168 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 6169 | netdev->features |= NETIF_F_SCTP_CSUM; |
| 6170 | |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 6171 | netdev->vlan_features |= NETIF_F_TSO; |
| 6172 | netdev->vlan_features |= NETIF_F_TSO6; |
Jesse Brandeburg | 22f32b7a5 | 2008-08-26 04:27:18 -0700 | [diff] [blame] | 6173 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Alexander Duyck | cd1da50 | 2009-08-25 04:47:50 +0000 | [diff] [blame] | 6174 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 6175 | netdev->vlan_features |= NETIF_F_SG; |
| 6176 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 6177 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 6178 | adapter->flags &= ~(IXGBE_FLAG_RSS_ENABLED | |
| 6179 | IXGBE_FLAG_DCB_ENABLED); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 6180 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 6181 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
| 6182 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 6183 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 6184 | netdev->dcbnl_ops = &dcbnl_ops; |
| 6185 | #endif |
| 6186 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6187 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 6188 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6189 | if (hw->mac.ops.get_device_caps) { |
| 6190 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 6191 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 6192 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 6193 | } |
| 6194 | } |
| 6195 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6196 | if (pci_using_dac) |
| 6197 | netdev->features |= NETIF_F_HIGHDMA; |
| 6198 | |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 6199 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 6200 | netdev->features |= NETIF_F_LRO; |
| 6201 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6202 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 6203 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6204 | dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n"); |
| 6205 | err = -EIO; |
| 6206 | goto err_eeprom; |
| 6207 | } |
| 6208 | |
| 6209 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
| 6210 | memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len); |
| 6211 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 6212 | if (ixgbe_validate_mac_addr(netdev->perm_addr)) { |
| 6213 | dev_err(&pdev->dev, "invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6214 | err = -EIO; |
| 6215 | goto err_eeprom; |
| 6216 | } |
| 6217 | |
| 6218 | init_timer(&adapter->watchdog_timer); |
| 6219 | adapter->watchdog_timer.function = &ixgbe_watchdog; |
| 6220 | adapter->watchdog_timer.data = (unsigned long)adapter; |
| 6221 | |
| 6222 | INIT_WORK(&adapter->reset_task, ixgbe_reset_task); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 6223 | INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6224 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6225 | err = ixgbe_init_interrupt_scheme(adapter); |
| 6226 | if (err) |
| 6227 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6228 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6229 | switch (pdev->device) { |
| 6230 | case IXGBE_DEV_ID_82599_KX4: |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 6231 | adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX | |
| 6232 | IXGBE_WUFC_MC | IXGBE_WUFC_BC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6233 | break; |
| 6234 | default: |
| 6235 | adapter->wol = 0; |
| 6236 | break; |
| 6237 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6238 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 6239 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 6240 | /* pick up the PCI bus settings for reporting later */ |
| 6241 | hw->mac.ops.get_bus_info(hw); |
| 6242 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6243 | /* print bus type/speed/width info */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 6244 | dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n", |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6245 | ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s": |
| 6246 | (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"), |
| 6247 | ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" : |
| 6248 | (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" : |
| 6249 | (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" : |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6250 | "Unknown"), |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 6251 | netdev->dev_addr); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 6252 | ixgbe_read_pba_num_generic(hw, &part_num); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6253 | if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present) |
| 6254 | dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n", |
| 6255 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
| 6256 | (part_num >> 8), (part_num & 0xff)); |
| 6257 | else |
| 6258 | dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n", |
| 6259 | hw->mac.type, hw->phy.type, |
| 6260 | (part_num >> 8), (part_num & 0xff)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6261 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6262 | if (hw->bus.width <= ixgbe_bus_width_pcie_x4) { |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 6263 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6264 | "this card is not sufficient for optimal " |
| 6265 | "performance.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 6266 | dev_warn(&pdev->dev, "For optimal performance a x8 " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6267 | "PCI-Express slot is required.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 6268 | } |
| 6269 | |
Peter P Waskiewicz Jr | 34b0368 | 2009-02-05 23:54:42 -0800 | [diff] [blame] | 6270 | /* save off EEPROM version number */ |
| 6271 | hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version); |
| 6272 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6273 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 6274 | err = hw->mac.ops.start_hw(hw); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 6275 | |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 6276 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 6277 | /* We are running on a pre-production device, log a warning */ |
| 6278 | dev_warn(&pdev->dev, "This device is a pre-production " |
| 6279 | "adapter/LOM. Please be aware there may be issues " |
| 6280 | "associated with your hardware. If you are " |
| 6281 | "experiencing problems please contact your Intel or " |
| 6282 | "hardware representative who provided you with this " |
| 6283 | "hardware.\n"); |
| 6284 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6285 | strcpy(netdev->name, "eth%d"); |
| 6286 | err = register_netdev(netdev); |
| 6287 | if (err) |
| 6288 | goto err_register; |
| 6289 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 6290 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 6291 | netif_carrier_off(netdev); |
| 6292 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6293 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 6294 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 6295 | INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task); |
| 6296 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6297 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 6298 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6299 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6300 | ixgbe_setup_dca(adapter); |
| 6301 | } |
| 6302 | #endif |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 6303 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) { |
| 6304 | DPRINTK(PROBE, INFO, "IOV is enabled with %d VFs\n", |
| 6305 | adapter->num_vfs); |
| 6306 | for (i = 0; i < adapter->num_vfs; i++) |
| 6307 | ixgbe_vf_configuration(pdev, (i | 0x10000000)); |
| 6308 | } |
| 6309 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 6310 | /* add san mac addr to netdev */ |
| 6311 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6312 | |
| 6313 | dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n"); |
| 6314 | cards_found++; |
| 6315 | return 0; |
| 6316 | |
| 6317 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 6318 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 6319 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6320 | err_sw_init: |
| 6321 | err_eeprom: |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 6322 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 6323 | ixgbe_disable_sriov(adapter); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 6324 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 6325 | del_timer_sync(&adapter->sfp_timer); |
| 6326 | cancel_work_sync(&adapter->sfp_task); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6327 | cancel_work_sync(&adapter->multispeed_fiber_task); |
| 6328 | cancel_work_sync(&adapter->sfp_config_module_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6329 | iounmap(hw->hw_addr); |
| 6330 | err_ioremap: |
| 6331 | free_netdev(netdev); |
| 6332 | err_alloc_etherdev: |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 6333 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
| 6334 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6335 | err_pci_reg: |
| 6336 | err_dma: |
| 6337 | pci_disable_device(pdev); |
| 6338 | return err; |
| 6339 | } |
| 6340 | |
| 6341 | /** |
| 6342 | * ixgbe_remove - Device Removal Routine |
| 6343 | * @pdev: PCI device information struct |
| 6344 | * |
| 6345 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 6346 | * that it should release a PCI device. The could be caused by a |
| 6347 | * Hot-Plug event, or because the driver is going to be removed from |
| 6348 | * memory. |
| 6349 | **/ |
| 6350 | static void __devexit ixgbe_remove(struct pci_dev *pdev) |
| 6351 | { |
| 6352 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 6353 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 6354 | |
| 6355 | set_bit(__IXGBE_DOWN, &adapter->state); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 6356 | /* clear the module not found bit to make sure the worker won't |
| 6357 | * reschedule |
| 6358 | */ |
| 6359 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6360 | del_timer_sync(&adapter->watchdog_timer); |
| 6361 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 6362 | del_timer_sync(&adapter->sfp_timer); |
| 6363 | cancel_work_sync(&adapter->watchdog_task); |
| 6364 | cancel_work_sync(&adapter->sfp_task); |
Mallikarjuna R Chilakala | 1097cd1 | 2010-03-18 14:34:52 +0000 | [diff] [blame] | 6365 | if (adapter->hw.phy.multispeed_fiber) { |
| 6366 | struct ixgbe_hw *hw = &adapter->hw; |
| 6367 | /* |
| 6368 | * Restart clause 37 autoneg, disable and re-enable |
| 6369 | * the tx laser, to clear & alert the link partner |
| 6370 | * that it needs to restart autotry |
| 6371 | */ |
| 6372 | hw->mac.autotry_restart = true; |
| 6373 | hw->mac.ops.flap_tx_laser(hw); |
| 6374 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 6375 | cancel_work_sync(&adapter->multispeed_fiber_task); |
| 6376 | cancel_work_sync(&adapter->sfp_config_module_task); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 6377 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 6378 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 6379 | cancel_work_sync(&adapter->fdir_reinit_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6380 | flush_scheduled_work(); |
| 6381 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6382 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6383 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 6384 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 6385 | dca_remove_requester(&pdev->dev); |
| 6386 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 6387 | } |
| 6388 | |
| 6389 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 6390 | #ifdef IXGBE_FCOE |
| 6391 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 6392 | ixgbe_cleanup_fcoe(adapter); |
| 6393 | |
| 6394 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 6395 | |
| 6396 | /* remove the added san mac */ |
| 6397 | ixgbe_del_sanmac_netdev(netdev); |
| 6398 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 6399 | if (netdev->reg_state == NETREG_REGISTERED) |
| 6400 | unregister_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6401 | |
Greg Rose | 1cdd1ec | 2010-01-09 02:26:46 +0000 | [diff] [blame] | 6402 | if (adapter->flags & IXGBE_FLAG_SRIOV_ENABLED) |
| 6403 | ixgbe_disable_sriov(adapter); |
| 6404 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 6405 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 6406 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6407 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6408 | |
| 6409 | iounmap(adapter->hw.hw_addr); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 6410 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
| 6411 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6412 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6413 | DPRINTK(PROBE, INFO, "complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6414 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6415 | free_netdev(netdev); |
| 6416 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 6417 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6418 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6419 | pci_disable_device(pdev); |
| 6420 | } |
| 6421 | |
| 6422 | /** |
| 6423 | * ixgbe_io_error_detected - called when PCI error is detected |
| 6424 | * @pdev: Pointer to PCI device |
| 6425 | * @state: The current pci connection state |
| 6426 | * |
| 6427 | * This function is called after a PCI bus error affecting |
| 6428 | * this device has been detected. |
| 6429 | */ |
| 6430 | static pci_ers_result_t ixgbe_io_error_detected(struct pci_dev *pdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6431 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6432 | { |
| 6433 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 6434 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6435 | |
| 6436 | netif_device_detach(netdev); |
| 6437 | |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 6438 | if (state == pci_channel_io_perm_failure) |
| 6439 | return PCI_ERS_RESULT_DISCONNECT; |
| 6440 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6441 | if (netif_running(netdev)) |
| 6442 | ixgbe_down(adapter); |
| 6443 | pci_disable_device(pdev); |
| 6444 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6445 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6446 | return PCI_ERS_RESULT_NEED_RESET; |
| 6447 | } |
| 6448 | |
| 6449 | /** |
| 6450 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 6451 | * @pdev: Pointer to PCI device |
| 6452 | * |
| 6453 | * Restart the card from scratch, as if from a cold-boot. |
| 6454 | */ |
| 6455 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 6456 | { |
| 6457 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 6458 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6459 | pci_ers_result_t result; |
| 6460 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6461 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 6462 | if (pci_enable_device_mem(pdev)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6463 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6464 | "Cannot re-enable PCI device after reset.\n"); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6465 | result = PCI_ERS_RESULT_DISCONNECT; |
| 6466 | } else { |
| 6467 | pci_set_master(pdev); |
| 6468 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 6469 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6470 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 6471 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6472 | |
| 6473 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 6474 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6475 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6476 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6477 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6478 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 6479 | if (err) { |
| 6480 | dev_err(&pdev->dev, |
| 6481 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err); |
| 6482 | /* non-fatal, continue */ |
| 6483 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6484 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6485 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6486 | } |
| 6487 | |
| 6488 | /** |
| 6489 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 6490 | * @pdev: Pointer to PCI device |
| 6491 | * |
| 6492 | * This callback is called when the error recovery driver tells us that |
| 6493 | * its OK to resume normal operation. |
| 6494 | */ |
| 6495 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 6496 | { |
| 6497 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 6498 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6499 | |
| 6500 | if (netif_running(netdev)) { |
| 6501 | if (ixgbe_up(adapter)) { |
| 6502 | DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n"); |
| 6503 | return; |
| 6504 | } |
| 6505 | } |
| 6506 | |
| 6507 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6508 | } |
| 6509 | |
| 6510 | static struct pci_error_handlers ixgbe_err_handler = { |
| 6511 | .error_detected = ixgbe_io_error_detected, |
| 6512 | .slot_reset = ixgbe_io_slot_reset, |
| 6513 | .resume = ixgbe_io_resume, |
| 6514 | }; |
| 6515 | |
| 6516 | static struct pci_driver ixgbe_driver = { |
| 6517 | .name = ixgbe_driver_name, |
| 6518 | .id_table = ixgbe_pci_tbl, |
| 6519 | .probe = ixgbe_probe, |
| 6520 | .remove = __devexit_p(ixgbe_remove), |
| 6521 | #ifdef CONFIG_PM |
| 6522 | .suspend = ixgbe_suspend, |
| 6523 | .resume = ixgbe_resume, |
| 6524 | #endif |
| 6525 | .shutdown = ixgbe_shutdown, |
| 6526 | .err_handler = &ixgbe_err_handler |
| 6527 | }; |
| 6528 | |
| 6529 | /** |
| 6530 | * ixgbe_init_module - Driver Registration Routine |
| 6531 | * |
| 6532 | * ixgbe_init_module is the first routine called when the driver is |
| 6533 | * loaded. All it does is register with the PCI subsystem. |
| 6534 | **/ |
| 6535 | static int __init ixgbe_init_module(void) |
| 6536 | { |
| 6537 | int ret; |
| 6538 | printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name, |
| 6539 | ixgbe_driver_string, ixgbe_driver_version); |
| 6540 | |
| 6541 | printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright); |
| 6542 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6543 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6544 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6545 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6546 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6547 | ret = pci_register_driver(&ixgbe_driver); |
| 6548 | return ret; |
| 6549 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6550 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6551 | module_init(ixgbe_init_module); |
| 6552 | |
| 6553 | /** |
| 6554 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 6555 | * |
| 6556 | * ixgbe_exit_module is called just before the driver is removed |
| 6557 | * from memory. |
| 6558 | **/ |
| 6559 | static void __exit ixgbe_exit_module(void) |
| 6560 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6561 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6562 | dca_unregister_notify(&dca_notifier); |
| 6563 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6564 | pci_unregister_driver(&ixgbe_driver); |
| 6565 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6566 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6567 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6568 | static int ixgbe_notify_dca(struct notifier_block *nb, unsigned long event, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6569 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6570 | { |
| 6571 | int ret_val; |
| 6572 | |
| 6573 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6574 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6575 | |
| 6576 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 6577 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6578 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 6579 | #endif /* CONFIG_IXGBE_DCA */ |
| 6580 | #ifdef DEBUG |
| 6581 | /** |
| 6582 | * ixgbe_get_hw_dev_name - return device name string |
| 6583 | * used by hardware layer to print debugging information |
| 6584 | **/ |
| 6585 | char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw) |
| 6586 | { |
| 6587 | struct ixgbe_adapter *adapter = hw->back; |
| 6588 | return adapter->netdev->name; |
| 6589 | } |
| 6590 | |
| 6591 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6592 | module_exit(ixgbe_exit_module); |
| 6593 | |
| 6594 | /* ixgbe_main.c */ |