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" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 48 | |
| 49 | char ixgbe_driver_name[] = "ixgbe"; |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 50 | static const char ixgbe_driver_string[] = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 51 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 52 | |
Peter P Waskiewicz Jr | e0f4daf | 2009-09-30 12:07:57 +0000 | [diff] [blame] | 53 | #define DRV_VERSION "2.0.44-k2" |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 54 | const char ixgbe_driver_version[] = DRV_VERSION; |
Shannon Nelson | 8c47eaa | 2010-01-13 01:49:34 +0000 | [diff] [blame] | 55 | static char ixgbe_copyright[] = "Copyright (c) 1999-2010 Intel Corporation."; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 56 | |
| 57 | static const struct ixgbe_info *ixgbe_info_tbl[] = { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 58 | [board_82598] = &ixgbe_82598_info, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 59 | [board_82599] = &ixgbe_82599_info, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 60 | }; |
| 61 | |
| 62 | /* ixgbe_pci_tbl - PCI Device ID Table |
| 63 | * |
| 64 | * Wildcard entries (PCI_ANY_ID) should come last |
| 65 | * Last entry must be all 0s |
| 66 | * |
| 67 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 68 | * Class, Class Mask, private data (not used) } |
| 69 | */ |
| 70 | static struct pci_device_id ixgbe_pci_tbl[] = { |
Don Skidmore | 1e336d0 | 2009-01-26 20:57:51 -0800 | [diff] [blame] | 71 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), |
| 72 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 73 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 74 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 75 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 76 | board_82598 }, |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 77 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), |
| 78 | board_82598 }, |
Peter P Waskiewicz Jr | 3845bec | 2009-07-16 15:50:52 +0000 | [diff] [blame] | 79 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), |
| 80 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 81 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 82 | board_82598 }, |
Jesse Brandeburg | 8d792cd | 2008-08-08 16:24:19 -0700 | [diff] [blame] | 83 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), |
| 84 | board_82598 }, |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 85 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), |
| 86 | board_82598 }, |
| 87 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), |
| 88 | board_82598 }, |
Jesse Brandeburg | b95f5fc | 2008-09-11 19:58:59 -0700 | [diff] [blame] | 89 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), |
| 90 | board_82598 }, |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 91 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), |
| 92 | board_82598 }, |
Don Skidmore | 2f21bdd | 2009-02-01 01:18:23 -0800 | [diff] [blame] | 93 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), |
| 94 | board_82598 }, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 95 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), |
| 96 | board_82599 }, |
Peter P Waskiewicz Jr | 1fcf03e | 2009-05-17 20:58:04 +0000 | [diff] [blame] | 97 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), |
| 98 | board_82599 }, |
Don Skidmore | 74757d4 | 2009-12-08 07:22:23 +0000 | [diff] [blame] | 99 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), |
| 100 | board_82599 }, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 101 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), |
| 102 | board_82599 }, |
Don Skidmore | 38ad1c8 | 2009-10-08 15:35:58 +0000 | [diff] [blame] | 103 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), |
| 104 | board_82599 }, |
Don Skidmore | dbfec66 | 2009-10-02 08:58:25 +0000 | [diff] [blame] | 105 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), |
| 106 | board_82599 }, |
Peter P Waskiewicz Jr | 8911184 | 2009-09-14 07:47:49 +0000 | [diff] [blame] | 107 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), |
| 108 | board_82599 }, |
Don Skidmore | 312eb93 | 2009-10-02 08:58:04 +0000 | [diff] [blame] | 109 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), |
| 110 | board_82599 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 111 | |
| 112 | /* required last entry */ |
| 113 | {0, } |
| 114 | }; |
| 115 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 116 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 117 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 118 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 119 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 120 | static struct notifier_block dca_notifier = { |
| 121 | .notifier_call = ixgbe_notify_dca, |
| 122 | .next = NULL, |
| 123 | .priority = 0 |
| 124 | }; |
| 125 | #endif |
| 126 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 127 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 128 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 129 | MODULE_LICENSE("GPL"); |
| 130 | MODULE_VERSION(DRV_VERSION); |
| 131 | |
| 132 | #define DEFAULT_DEBUG_LEVEL_SHIFT 3 |
| 133 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 134 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 135 | { |
| 136 | u32 ctrl_ext; |
| 137 | |
| 138 | /* Let firmware take over control of h/w */ |
| 139 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 140 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 141 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 145 | { |
| 146 | u32 ctrl_ext; |
| 147 | |
| 148 | /* Let firmware know the driver has taken over */ |
| 149 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 150 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 151 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 152 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 153 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 154 | /* |
| 155 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 156 | * @adapter: pointer to adapter struct |
| 157 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 158 | * @queue: queue to map the corresponding interrupt to |
| 159 | * @msix_vector: the vector to map to the corresponding queue |
| 160 | * |
| 161 | */ |
| 162 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
| 163 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 164 | { |
| 165 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 166 | struct ixgbe_hw *hw = &adapter->hw; |
| 167 | switch (hw->mac.type) { |
| 168 | case ixgbe_mac_82598EB: |
| 169 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 170 | if (direction == -1) |
| 171 | direction = 0; |
| 172 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 173 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 174 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 175 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 176 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 177 | break; |
| 178 | case ixgbe_mac_82599EB: |
| 179 | if (direction == -1) { |
| 180 | /* other causes */ |
| 181 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 182 | index = ((queue & 1) * 8); |
| 183 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 184 | ivar &= ~(0xFF << index); |
| 185 | ivar |= (msix_vector << index); |
| 186 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 187 | break; |
| 188 | } else { |
| 189 | /* tx or rx causes */ |
| 190 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 191 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 192 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 193 | ivar &= ~(0xFF << index); |
| 194 | ivar |= (msix_vector << index); |
| 195 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 196 | break; |
| 197 | } |
| 198 | default: |
| 199 | break; |
| 200 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 203 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
| 204 | u64 qmask) |
| 205 | { |
| 206 | u32 mask; |
| 207 | |
| 208 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 209 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 210 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
| 211 | } else { |
| 212 | mask = (qmask & 0xFFFFFFFF); |
| 213 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 214 | mask = (qmask >> 32); |
| 215 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
| 216 | } |
| 217 | } |
| 218 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 219 | 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] | 220 | struct ixgbe_tx_buffer |
| 221 | *tx_buffer_info) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 222 | { |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 223 | if (tx_buffer_info->dma) { |
| 224 | if (tx_buffer_info->mapped_as_page) |
| 225 | pci_unmap_page(adapter->pdev, |
| 226 | tx_buffer_info->dma, |
| 227 | tx_buffer_info->length, |
| 228 | PCI_DMA_TODEVICE); |
| 229 | else |
| 230 | pci_unmap_single(adapter->pdev, |
| 231 | tx_buffer_info->dma, |
| 232 | tx_buffer_info->length, |
| 233 | PCI_DMA_TODEVICE); |
| 234 | tx_buffer_info->dma = 0; |
| 235 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 236 | if (tx_buffer_info->skb) { |
| 237 | dev_kfree_skb_any(tx_buffer_info->skb); |
| 238 | tx_buffer_info->skb = NULL; |
| 239 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 240 | tx_buffer_info->time_stamp = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 241 | /* tx_buffer_info must be completely set up in the transmit path */ |
| 242 | } |
| 243 | |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 244 | /** |
| 245 | * ixgbe_tx_is_paused - check if the tx ring is paused |
| 246 | * @adapter: the ixgbe adapter |
| 247 | * @tx_ring: the corresponding tx_ring |
| 248 | * |
| 249 | * If not in DCB mode, checks TFCS.TXOFF, otherwise, find out the |
| 250 | * corresponding TC of this tx_ring when checking TFCS. |
| 251 | * |
| 252 | * Returns : true if paused |
| 253 | */ |
| 254 | static inline bool ixgbe_tx_is_paused(struct ixgbe_adapter *adapter, |
| 255 | struct ixgbe_ring *tx_ring) |
| 256 | { |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 257 | u32 txoff = IXGBE_TFCS_TXOFF; |
| 258 | |
| 259 | #ifdef CONFIG_IXGBE_DCB |
| 260 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Jaswinder Singh Rajput | 30b76832 | 2009-11-20 04:02:27 +0000 | [diff] [blame] | 261 | int tc; |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 262 | int reg_idx = tx_ring->reg_idx; |
| 263 | int dcb_i = adapter->ring_feature[RING_F_DCB].indices; |
| 264 | |
PJ Waskiewicz | 6837e89 | 2010-01-06 17:50:29 +0000 | [diff] [blame] | 265 | switch (adapter->hw.mac.type) { |
| 266 | case ixgbe_mac_82598EB: |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 267 | tc = reg_idx >> 2; |
| 268 | txoff = IXGBE_TFCS_TXOFF0; |
PJ Waskiewicz | 6837e89 | 2010-01-06 17:50:29 +0000 | [diff] [blame] | 269 | break; |
| 270 | case ixgbe_mac_82599EB: |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 271 | tc = 0; |
| 272 | txoff = IXGBE_TFCS_TXOFF; |
| 273 | if (dcb_i == 8) { |
| 274 | /* TC0, TC1 */ |
| 275 | tc = reg_idx >> 5; |
| 276 | if (tc == 2) /* TC2, TC3 */ |
| 277 | tc += (reg_idx - 64) >> 4; |
| 278 | else if (tc == 3) /* TC4, TC5, TC6, TC7 */ |
| 279 | tc += 1 + ((reg_idx - 96) >> 3); |
| 280 | } else if (dcb_i == 4) { |
| 281 | /* TC0, TC1 */ |
| 282 | tc = reg_idx >> 6; |
| 283 | if (tc == 1) { |
| 284 | tc += (reg_idx - 64) >> 5; |
| 285 | if (tc == 2) /* TC2, TC3 */ |
| 286 | tc += (reg_idx - 96) >> 4; |
| 287 | } |
| 288 | } |
PJ Waskiewicz | 6837e89 | 2010-01-06 17:50:29 +0000 | [diff] [blame] | 289 | break; |
| 290 | default: |
| 291 | tc = 0; |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 292 | } |
| 293 | txoff <<= tc; |
| 294 | } |
| 295 | #endif |
| 296 | return IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & txoff; |
| 297 | } |
| 298 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 299 | static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 300 | struct ixgbe_ring *tx_ring, |
| 301 | unsigned int eop) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 302 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 303 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 304 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 305 | /* Detect a transmit hang in hardware, this serializes the |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 306 | * check with the clearing of time_stamp and movement of eop */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 307 | adapter->detect_tx_hung = false; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 308 | if (tx_ring->tx_buffer_info[eop].time_stamp && |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 309 | time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) && |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 310 | !ixgbe_tx_is_paused(adapter, tx_ring)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 311 | /* detected Tx unit hang */ |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 312 | union ixgbe_adv_tx_desc *tx_desc; |
| 313 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 314 | DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n" |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 315 | " Tx Queue <%d>\n" |
| 316 | " TDH, TDT <%x>, <%x>\n" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 317 | " next_to_use <%x>\n" |
| 318 | " next_to_clean <%x>\n" |
| 319 | "tx_buffer_info[next_to_clean]\n" |
| 320 | " time_stamp <%lx>\n" |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 321 | " jiffies <%lx>\n", |
| 322 | tx_ring->queue_index, |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 323 | IXGBE_READ_REG(hw, tx_ring->head), |
| 324 | IXGBE_READ_REG(hw, tx_ring->tail), |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 325 | tx_ring->next_to_use, eop, |
| 326 | tx_ring->tx_buffer_info[eop].time_stamp, jiffies); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 327 | return true; |
| 328 | } |
| 329 | |
| 330 | return false; |
| 331 | } |
| 332 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 333 | #define IXGBE_MAX_TXD_PWR 14 |
| 334 | #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 335 | |
| 336 | /* Tx Descriptors needed, worst case */ |
| 337 | #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \ |
| 338 | (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0)) |
| 339 | #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] | 340 | MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 341 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 342 | static void ixgbe_tx_timeout(struct net_device *netdev); |
| 343 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 344 | /** |
| 345 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 346 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 347 | * @tx_ring: tx ring to clean |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 348 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 349 | static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 350 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 351 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 352 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 353 | struct net_device *netdev = adapter->netdev; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 354 | union ixgbe_adv_tx_desc *tx_desc, *eop_desc; |
| 355 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 356 | unsigned int i, eop, count = 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 357 | unsigned int total_bytes = 0, total_packets = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 358 | |
| 359 | i = tx_ring->next_to_clean; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 360 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
| 361 | eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
| 362 | |
| 363 | while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) && |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 364 | (count < tx_ring->work_limit)) { |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 365 | bool cleaned = false; |
| 366 | for ( ; !cleaned; count++) { |
| 367 | struct sk_buff *skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 368 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); |
| 369 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 370 | cleaned = (i == eop); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 371 | skb = tx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 372 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 373 | if (cleaned && skb) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 374 | unsigned int segs, bytecount; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 375 | unsigned int hlen = skb_headlen(skb); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 376 | |
| 377 | /* gso_segs is currently only valid for tcp */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 378 | segs = skb_shinfo(skb)->gso_segs ?: 1; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 379 | #ifdef IXGBE_FCOE |
| 380 | /* adjust for FCoE Sequence Offload */ |
| 381 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 382 | && (skb->protocol == htons(ETH_P_FCOE)) && |
| 383 | skb_is_gso(skb)) { |
| 384 | hlen = skb_transport_offset(skb) + |
| 385 | sizeof(struct fc_frame_header) + |
| 386 | sizeof(struct fcoe_crc_eof); |
| 387 | segs = DIV_ROUND_UP(skb->len - hlen, |
| 388 | skb_shinfo(skb)->gso_size); |
| 389 | } |
| 390 | #endif /* IXGBE_FCOE */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 391 | /* multiply data chunks by size of headers */ |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 392 | bytecount = ((segs - 1) * hlen) + skb->len; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 393 | total_packets += segs; |
| 394 | total_bytes += bytecount; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 395 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 396 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 397 | ixgbe_unmap_and_free_tx_resource(adapter, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 398 | tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 399 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 400 | tx_desc->wb.status = 0; |
| 401 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 402 | i++; |
| 403 | if (i == tx_ring->count) |
| 404 | i = 0; |
| 405 | } |
| 406 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 407 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
| 408 | eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
| 409 | } |
| 410 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 411 | tx_ring->next_to_clean = i; |
| 412 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 413 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 414 | if (unlikely(count && netif_carrier_ok(netdev) && |
| 415 | (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 416 | /* Make sure that anybody stopping the queue after this |
| 417 | * sees the new next_to_clean. |
| 418 | */ |
| 419 | smp_mb(); |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 420 | if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) && |
| 421 | !test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 422 | netif_wake_subqueue(netdev, tx_ring->queue_index); |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 423 | ++tx_ring->restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 424 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 425 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 426 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 427 | if (adapter->detect_tx_hung) { |
| 428 | if (ixgbe_check_tx_hang(adapter, tx_ring, i)) { |
| 429 | /* schedule immediate reset if we believe we hung */ |
| 430 | DPRINTK(PROBE, INFO, |
| 431 | "tx hang %d detected, resetting adapter\n", |
| 432 | adapter->tx_timeout_count + 1); |
| 433 | ixgbe_tx_timeout(adapter->netdev); |
| 434 | } |
| 435 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 436 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 437 | /* re-arm the interrupt */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 438 | if (count >= tx_ring->work_limit) |
| 439 | ixgbe_irq_rearm_queues(adapter, ((u64)1 << q_vector->v_idx)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 440 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 441 | tx_ring->total_bytes += total_bytes; |
| 442 | tx_ring->total_packets += total_packets; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 443 | tx_ring->stats.packets += total_packets; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 444 | tx_ring->stats.bytes += total_bytes; |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 445 | return (count < tx_ring->work_limit); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 446 | } |
| 447 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 448 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 449 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 450 | struct ixgbe_ring *rx_ring) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 451 | { |
| 452 | u32 rxctrl; |
| 453 | int cpu = get_cpu(); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 454 | int q = rx_ring - adapter->rx_ring; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 455 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 456 | if (rx_ring->cpu != cpu) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 457 | rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 458 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 459 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK; |
| 460 | rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 461 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 462 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599; |
| 463 | rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 464 | IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599); |
| 465 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 466 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 467 | rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN; |
Don Skidmore | 15005a3 | 2009-01-19 16:54:13 -0800 | [diff] [blame] | 468 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN); |
| 469 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 470 | IXGBE_DCA_RXCTRL_DESC_HSRO_EN); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 471 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 472 | rx_ring->cpu = cpu; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 473 | } |
| 474 | put_cpu(); |
| 475 | } |
| 476 | |
| 477 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 478 | struct ixgbe_ring *tx_ring) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 479 | { |
| 480 | u32 txctrl; |
| 481 | int cpu = get_cpu(); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 482 | int q = tx_ring - adapter->tx_ring; |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 483 | struct ixgbe_hw *hw = &adapter->hw; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 484 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 485 | if (tx_ring->cpu != cpu) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 486 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 487 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 488 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK; |
| 489 | txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 490 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 491 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(q), txctrl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 492 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 493 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 494 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599; |
| 495 | txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 496 | IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599); |
| 497 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 498 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(q), txctrl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 499 | } |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 500 | tx_ring->cpu = cpu; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 501 | } |
| 502 | put_cpu(); |
| 503 | } |
| 504 | |
| 505 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 506 | { |
| 507 | int i; |
| 508 | |
| 509 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 510 | return; |
| 511 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 512 | /* always use CB2 mode, difference is masked in the CB driver */ |
| 513 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); |
| 514 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 515 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 516 | adapter->tx_ring[i].cpu = -1; |
| 517 | ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]); |
| 518 | } |
| 519 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 520 | adapter->rx_ring[i].cpu = -1; |
| 521 | ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]); |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 526 | { |
| 527 | struct net_device *netdev = dev_get_drvdata(dev); |
| 528 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 529 | unsigned long event = *(unsigned long *)data; |
| 530 | |
| 531 | switch (event) { |
| 532 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 533 | /* if we're already enabled, don't do it again */ |
| 534 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 535 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 536 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 537 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 538 | ixgbe_setup_dca(adapter); |
| 539 | break; |
| 540 | } |
| 541 | /* Fall Through since DCA is disabled. */ |
| 542 | case DCA_PROVIDER_REMOVE: |
| 543 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 544 | dca_remove_requester(dev); |
| 545 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 546 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 547 | } |
| 548 | break; |
| 549 | } |
| 550 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 551 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 552 | } |
| 553 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 554 | #endif /* CONFIG_IXGBE_DCA */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 555 | /** |
| 556 | * ixgbe_receive_skb - Send a completed packet up the stack |
| 557 | * @adapter: board private structure |
| 558 | * @skb: packet to send up |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 559 | * @status: hardware indication of status of receive |
| 560 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
| 561 | * @rx_desc: rx descriptor |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 562 | **/ |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 563 | static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 564 | struct sk_buff *skb, u8 status, |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 565 | struct ixgbe_ring *ring, |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 566 | union ixgbe_adv_rx_desc *rx_desc) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 567 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 568 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 569 | struct napi_struct *napi = &q_vector->napi; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 570 | bool is_vlan = (status & IXGBE_RXD_STAT_VP); |
| 571 | u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 572 | |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 573 | skb_record_rx_queue(skb, ring->queue_index); |
Alexander Duyck | 182ff8d | 2009-04-27 22:35:33 +0000 | [diff] [blame] | 574 | if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) { |
Lucy Liu | 8a62bab | 2009-08-13 14:09:38 +0000 | [diff] [blame] | 575 | if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK)) |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 576 | vlan_gro_receive(napi, adapter->vlgrp, tag, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 577 | else |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 578 | napi_gro_receive(napi, skb); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 579 | } else { |
Lucy Liu | 8a62bab | 2009-08-13 14:09:38 +0000 | [diff] [blame] | 580 | if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK)) |
Alexander Duyck | 182ff8d | 2009-04-27 22:35:33 +0000 | [diff] [blame] | 581 | vlan_hwaccel_rx(skb, adapter->vlgrp, tag); |
| 582 | else |
| 583 | netif_rx(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 584 | } |
| 585 | } |
| 586 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 587 | /** |
| 588 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
| 589 | * @adapter: address of board private structure |
| 590 | * @status_err: hardware indication of status of receive |
| 591 | * @skb: skb currently being received and modified |
| 592 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 593 | static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 594 | union ixgbe_adv_rx_desc *rx_desc, |
| 595 | struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 596 | { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 597 | u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 598 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 599 | skb->ip_summed = CHECKSUM_NONE; |
| 600 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 601 | /* Rx csum disabled */ |
| 602 | if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 603 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 604 | |
| 605 | /* if IP and error */ |
| 606 | if ((status_err & IXGBE_RXD_STAT_IPCS) && |
| 607 | (status_err & IXGBE_RXDADV_ERR_IPE)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 608 | adapter->hw_csum_rx_error++; |
| 609 | return; |
| 610 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 611 | |
| 612 | if (!(status_err & IXGBE_RXD_STAT_L4CS)) |
| 613 | return; |
| 614 | |
| 615 | if (status_err & IXGBE_RXDADV_ERR_TCPE) { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 616 | u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 617 | |
| 618 | /* |
| 619 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 620 | * checksum errors. |
| 621 | */ |
| 622 | if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) && |
| 623 | (adapter->hw.mac.type == ixgbe_mac_82599EB)) |
| 624 | return; |
| 625 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 626 | adapter->hw_csum_rx_error++; |
| 627 | return; |
| 628 | } |
| 629 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 630 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 631 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 632 | } |
| 633 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 634 | static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw, |
| 635 | struct ixgbe_ring *rx_ring, u32 val) |
| 636 | { |
| 637 | /* |
| 638 | * Force memory writes to complete before letting h/w |
| 639 | * know there are new descriptors to fetch. (Only |
| 640 | * applicable for weak-ordered memory model archs, |
| 641 | * such as IA-64). |
| 642 | */ |
| 643 | wmb(); |
| 644 | IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val); |
| 645 | } |
| 646 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 647 | /** |
| 648 | * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split |
| 649 | * @adapter: address of board private structure |
| 650 | **/ |
| 651 | static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 652 | struct ixgbe_ring *rx_ring, |
| 653 | int cleaned_count) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 654 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 655 | struct pci_dev *pdev = adapter->pdev; |
| 656 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 657 | struct ixgbe_rx_buffer *bi; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 658 | unsigned int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 659 | |
| 660 | i = rx_ring->next_to_use; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 661 | bi = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 662 | |
| 663 | while (cleaned_count--) { |
| 664 | rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 665 | |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 666 | if (!bi->page_dma && |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 667 | (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 668 | if (!bi->page) { |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 669 | bi->page = alloc_page(GFP_ATOMIC); |
| 670 | if (!bi->page) { |
| 671 | adapter->alloc_rx_page_failed++; |
| 672 | goto no_buffers; |
| 673 | } |
| 674 | bi->page_offset = 0; |
| 675 | } else { |
| 676 | /* use a half page if we're re-using */ |
| 677 | bi->page_offset ^= (PAGE_SIZE / 2); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 678 | } |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 679 | |
| 680 | bi->page_dma = pci_map_page(pdev, bi->page, |
| 681 | bi->page_offset, |
| 682 | (PAGE_SIZE / 2), |
| 683 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 684 | } |
| 685 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 686 | if (!bi->skb) { |
Jesse Brandeburg | 5ecc361 | 2008-12-15 01:00:57 -0800 | [diff] [blame] | 687 | struct sk_buff *skb; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 688 | /* netdev_alloc_skb reserves 32 bytes up front!! */ |
| 689 | uint bufsz = rx_ring->rx_buf_len + SMP_CACHE_BYTES; |
| 690 | skb = netdev_alloc_skb(adapter->netdev, bufsz); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 691 | |
| 692 | if (!skb) { |
| 693 | adapter->alloc_rx_buff_failed++; |
| 694 | goto no_buffers; |
| 695 | } |
| 696 | |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 697 | /* advance the data pointer to the next cache line */ |
| 698 | skb_reserve(skb, (PTR_ALIGN(skb->data, SMP_CACHE_BYTES) |
| 699 | - skb->data)); |
| 700 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 701 | bi->skb = skb; |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 702 | bi->dma = pci_map_single(pdev, skb->data, |
| 703 | rx_ring->rx_buf_len, |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 704 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 705 | } |
| 706 | /* Refresh the desc even if buffer_addrs didn't change because |
| 707 | * each write-back erases this info. */ |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 708 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 709 | rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma); |
| 710 | rx_desc->read.hdr_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 711 | } else { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 712 | rx_desc->read.pkt_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 713 | } |
| 714 | |
| 715 | i++; |
| 716 | if (i == rx_ring->count) |
| 717 | i = 0; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 718 | bi = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 719 | } |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 720 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 721 | no_buffers: |
| 722 | if (rx_ring->next_to_use != i) { |
| 723 | rx_ring->next_to_use = i; |
| 724 | if (i-- == 0) |
| 725 | i = (rx_ring->count - 1); |
| 726 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 727 | ixgbe_release_rx_desc(&adapter->hw, rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 728 | } |
| 729 | } |
| 730 | |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 731 | static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc) |
| 732 | { |
| 733 | return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info; |
| 734 | } |
| 735 | |
| 736 | static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc) |
| 737 | { |
| 738 | return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 739 | } |
| 740 | |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 741 | static inline u32 ixgbe_get_rsc_count(union ixgbe_adv_rx_desc *rx_desc) |
| 742 | { |
| 743 | return (le32_to_cpu(rx_desc->wb.lower.lo_dword.data) & |
| 744 | IXGBE_RXDADV_RSCCNT_MASK) >> |
| 745 | IXGBE_RXDADV_RSCCNT_SHIFT; |
| 746 | } |
| 747 | |
| 748 | /** |
| 749 | * ixgbe_transform_rsc_queue - change rsc queue into a full packet |
| 750 | * @skb: pointer to the last skb in the rsc queue |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 751 | * @count: pointer to number of packets coalesced in this context |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 752 | * |
| 753 | * This function changes a queue full of hw rsc buffers into a completed |
| 754 | * packet. It uses the ->prev pointers to find the first packet and then |
| 755 | * turns it into the frag list owner. |
| 756 | **/ |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 757 | static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb, |
| 758 | u64 *count) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 759 | { |
| 760 | unsigned int frag_list_size = 0; |
| 761 | |
| 762 | while (skb->prev) { |
| 763 | struct sk_buff *prev = skb->prev; |
| 764 | frag_list_size += skb->len; |
| 765 | skb->prev = NULL; |
| 766 | skb = prev; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 767 | *count += 1; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | skb_shinfo(skb)->frag_list = skb->next; |
| 771 | skb->next = NULL; |
| 772 | skb->len += frag_list_size; |
| 773 | skb->data_len += frag_list_size; |
| 774 | skb->truesize += frag_list_size; |
| 775 | return skb; |
| 776 | } |
| 777 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 778 | 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] | 779 | struct ixgbe_ring *rx_ring, |
| 780 | int *work_done, int work_to_do) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 781 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 782 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 783 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 784 | struct pci_dev *pdev = adapter->pdev; |
| 785 | union ixgbe_adv_rx_desc *rx_desc, *next_rxd; |
| 786 | struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer; |
| 787 | struct sk_buff *skb; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 788 | unsigned int i, rsc_count = 0; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 789 | u32 len, staterr; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 790 | u16 hdr_info; |
| 791 | bool cleaned = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 792 | int cleaned_count = 0; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 793 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 794 | #ifdef IXGBE_FCOE |
| 795 | int ddp_bytes = 0; |
| 796 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 797 | |
| 798 | i = rx_ring->next_to_clean; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 799 | rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 800 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 801 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 802 | |
| 803 | while (staterr & IXGBE_RXD_STAT_DD) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 804 | u32 upper_len = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 805 | if (*work_done >= work_to_do) |
| 806 | break; |
| 807 | (*work_done)++; |
| 808 | |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 809 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 810 | hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc)); |
| 811 | len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >> |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 812 | IXGBE_RXDADV_HDRBUFLEN_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 813 | if (len > IXGBE_RX_HDR_SIZE) |
| 814 | len = IXGBE_RX_HDR_SIZE; |
| 815 | upper_len = le16_to_cpu(rx_desc->wb.upper.length); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 816 | } else { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 817 | len = le16_to_cpu(rx_desc->wb.upper.length); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 818 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 819 | |
| 820 | cleaned = true; |
| 821 | skb = rx_buffer_info->skb; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 822 | prefetch(skb->data); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 823 | rx_buffer_info->skb = NULL; |
| 824 | |
Alexander Duyck | 21fa4e6 | 2009-06-04 15:59:49 +0000 | [diff] [blame] | 825 | if (rx_buffer_info->dma) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 826 | pci_unmap_single(pdev, rx_buffer_info->dma, |
Jesse Brandeburg | 5ecc361 | 2008-12-15 01:00:57 -0800 | [diff] [blame] | 827 | rx_ring->rx_buf_len, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 828 | PCI_DMA_FROMDEVICE); |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 829 | rx_buffer_info->dma = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 830 | skb_put(skb, len); |
| 831 | } |
| 832 | |
| 833 | if (upper_len) { |
| 834 | pci_unmap_page(pdev, rx_buffer_info->page_dma, |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 835 | PAGE_SIZE / 2, PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 836 | rx_buffer_info->page_dma = 0; |
| 837 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 838 | rx_buffer_info->page, |
| 839 | rx_buffer_info->page_offset, |
| 840 | upper_len); |
| 841 | |
| 842 | if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) || |
| 843 | (page_count(rx_buffer_info->page) != 1)) |
| 844 | rx_buffer_info->page = NULL; |
| 845 | else |
| 846 | get_page(rx_buffer_info->page); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 847 | |
| 848 | skb->len += upper_len; |
| 849 | skb->data_len += upper_len; |
| 850 | skb->truesize += upper_len; |
| 851 | } |
| 852 | |
| 853 | i++; |
| 854 | if (i == rx_ring->count) |
| 855 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 856 | |
| 857 | next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 858 | prefetch(next_rxd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 859 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 860 | |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 861 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 862 | rsc_count = ixgbe_get_rsc_count(rx_desc); |
| 863 | |
| 864 | if (rsc_count) { |
| 865 | u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >> |
| 866 | IXGBE_RXDADV_NEXTP_SHIFT; |
| 867 | next_buffer = &rx_ring->rx_buffer_info[nextp]; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 868 | } else { |
| 869 | next_buffer = &rx_ring->rx_buffer_info[i]; |
| 870 | } |
| 871 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 872 | if (staterr & IXGBE_RXD_STAT_EOP) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 873 | if (skb->prev) |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 874 | skb = ixgbe_transform_rsc_queue(skb, &(rx_ring->rsc_count)); |
| 875 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
| 876 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) |
| 877 | rx_ring->rsc_count += skb_shinfo(skb)->nr_frags; |
| 878 | else |
| 879 | rx_ring->rsc_count++; |
| 880 | rx_ring->rsc_flush++; |
| 881 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 882 | rx_ring->stats.packets++; |
| 883 | rx_ring->stats.bytes += skb->len; |
| 884 | } else { |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 885 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 886 | rx_buffer_info->skb = next_buffer->skb; |
| 887 | rx_buffer_info->dma = next_buffer->dma; |
| 888 | next_buffer->skb = skb; |
| 889 | next_buffer->dma = 0; |
| 890 | } else { |
| 891 | skb->next = next_buffer->skb; |
| 892 | skb->next->prev = skb; |
| 893 | } |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 894 | rx_ring->non_eop_descs++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 895 | goto next_desc; |
| 896 | } |
| 897 | |
| 898 | if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) { |
| 899 | dev_kfree_skb_irq(skb); |
| 900 | goto next_desc; |
| 901 | } |
| 902 | |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 903 | ixgbe_rx_checksum(adapter, rx_desc, skb); |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 904 | |
| 905 | /* probably a little skewed due to removing CRC */ |
| 906 | total_rx_bytes += skb->len; |
| 907 | total_rx_packets++; |
| 908 | |
Jesse Brandeburg | 74ce8dd | 2008-09-11 20:03:23 -0700 | [diff] [blame] | 909 | skb->protocol = eth_type_trans(skb, adapter->netdev); |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 910 | #ifdef IXGBE_FCOE |
| 911 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 912 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 913 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
| 914 | if (!ddp_bytes) |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 915 | goto next_desc; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 916 | } |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 917 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 918 | ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 919 | |
| 920 | next_desc: |
| 921 | rx_desc->wb.upper.status_error = 0; |
| 922 | |
| 923 | /* return some buffers to hardware, one at a time is too slow */ |
| 924 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 925 | ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count); |
| 926 | cleaned_count = 0; |
| 927 | } |
| 928 | |
| 929 | /* use prefetched values */ |
| 930 | rx_desc = next_rxd; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 931 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 932 | |
| 933 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 934 | } |
| 935 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 936 | rx_ring->next_to_clean = i; |
| 937 | cleaned_count = IXGBE_DESC_UNUSED(rx_ring); |
| 938 | |
| 939 | if (cleaned_count) |
| 940 | ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count); |
| 941 | |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 942 | #ifdef IXGBE_FCOE |
| 943 | /* include DDPed FCoE data */ |
| 944 | if (ddp_bytes > 0) { |
| 945 | unsigned int mss; |
| 946 | |
| 947 | mss = adapter->netdev->mtu - sizeof(struct fcoe_hdr) - |
| 948 | sizeof(struct fc_frame_header) - |
| 949 | sizeof(struct fcoe_crc_eof); |
| 950 | if (mss > 512) |
| 951 | mss &= ~511; |
| 952 | total_rx_bytes += ddp_bytes; |
| 953 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss); |
| 954 | } |
| 955 | #endif /* IXGBE_FCOE */ |
| 956 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 957 | rx_ring->total_packets += total_rx_packets; |
| 958 | rx_ring->total_bytes += total_rx_bytes; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 959 | netdev->stats.rx_bytes += total_rx_bytes; |
| 960 | netdev->stats.rx_packets += total_rx_packets; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 961 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 962 | return cleaned; |
| 963 | } |
| 964 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 965 | static int ixgbe_clean_rxonly(struct napi_struct *, int); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 966 | /** |
| 967 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 968 | * @adapter: board private structure |
| 969 | * |
| 970 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 971 | * interrupts. |
| 972 | **/ |
| 973 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 974 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 975 | struct ixgbe_q_vector *q_vector; |
| 976 | int i, j, q_vectors, v_idx, r_idx; |
| 977 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 978 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 979 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 980 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 981 | /* |
| 982 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 983 | * corresponding register. |
| 984 | */ |
| 985 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 986 | q_vector = adapter->q_vector[v_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 987 | /* XXX for_each_bit(...) */ |
| 988 | r_idx = find_first_bit(q_vector->rxr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 989 | adapter->num_rx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 990 | |
| 991 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 992 | j = adapter->rx_ring[r_idx].reg_idx; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 993 | ixgbe_set_ivar(adapter, 0, j, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 994 | r_idx = find_next_bit(q_vector->rxr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 995 | adapter->num_rx_queues, |
| 996 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 997 | } |
| 998 | r_idx = find_first_bit(q_vector->txr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 999 | adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1000 | |
| 1001 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1002 | j = adapter->tx_ring[r_idx].reg_idx; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1003 | ixgbe_set_ivar(adapter, 1, j, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1004 | r_idx = find_next_bit(q_vector->txr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1005 | adapter->num_tx_queues, |
| 1006 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1007 | } |
| 1008 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1009 | if (q_vector->txr_count && !q_vector->rxr_count) |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1010 | /* tx only */ |
| 1011 | q_vector->eitr = adapter->tx_eitr_param; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1012 | else if (q_vector->rxr_count) |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1013 | /* rx or mixed */ |
| 1014 | q_vector->eitr = adapter->rx_eitr_param; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1015 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1016 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1017 | } |
| 1018 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1019 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 1020 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
| 1021 | v_idx); |
| 1022 | else if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 1023 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1024 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1025 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 1026 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1027 | mask = IXGBE_EIMS_ENABLE_MASK; |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 1028 | mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1029 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1030 | } |
| 1031 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1032 | enum latency_range { |
| 1033 | lowest_latency = 0, |
| 1034 | low_latency = 1, |
| 1035 | bulk_latency = 2, |
| 1036 | latency_invalid = 255 |
| 1037 | }; |
| 1038 | |
| 1039 | /** |
| 1040 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
| 1041 | * @adapter: pointer to adapter |
| 1042 | * @eitr: eitr setting (ints per sec) to give last timeslice |
| 1043 | * @itr_setting: current throttle rate in ints/second |
| 1044 | * @packets: the number of packets during this measurement interval |
| 1045 | * @bytes: the number of bytes during this measurement interval |
| 1046 | * |
| 1047 | * Stores a new ITR value based on packets and byte |
| 1048 | * counts during the last interrupt. The advantage of per interrupt |
| 1049 | * computation is faster updates and more accurate ITR for the current |
| 1050 | * traffic pattern. Constants in this function were computed |
| 1051 | * based on theoretical maximum wire speed and thresholds were set based |
| 1052 | * on testing data as well as attempting to minimize response time |
| 1053 | * while increasing bulk throughput. |
| 1054 | * this functionality is controlled by the InterruptThrottleRate module |
| 1055 | * parameter (see ixgbe_param.c) |
| 1056 | **/ |
| 1057 | static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1058 | u32 eitr, u8 itr_setting, |
| 1059 | int packets, int bytes) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1060 | { |
| 1061 | unsigned int retval = itr_setting; |
| 1062 | u32 timepassed_us; |
| 1063 | u64 bytes_perint; |
| 1064 | |
| 1065 | if (packets == 0) |
| 1066 | goto update_itr_done; |
| 1067 | |
| 1068 | |
| 1069 | /* simple throttlerate management |
| 1070 | * 0-20MB/s lowest (100000 ints/s) |
| 1071 | * 20-100MB/s low (20000 ints/s) |
| 1072 | * 100-1249MB/s bulk (8000 ints/s) |
| 1073 | */ |
| 1074 | /* what was last interrupt timeslice? */ |
| 1075 | timepassed_us = 1000000/eitr; |
| 1076 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 1077 | |
| 1078 | switch (itr_setting) { |
| 1079 | case lowest_latency: |
| 1080 | if (bytes_perint > adapter->eitr_low) |
| 1081 | retval = low_latency; |
| 1082 | break; |
| 1083 | case low_latency: |
| 1084 | if (bytes_perint > adapter->eitr_high) |
| 1085 | retval = bulk_latency; |
| 1086 | else if (bytes_perint <= adapter->eitr_low) |
| 1087 | retval = lowest_latency; |
| 1088 | break; |
| 1089 | case bulk_latency: |
| 1090 | if (bytes_perint <= adapter->eitr_high) |
| 1091 | retval = low_latency; |
| 1092 | break; |
| 1093 | } |
| 1094 | |
| 1095 | update_itr_done: |
| 1096 | return retval; |
| 1097 | } |
| 1098 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1099 | /** |
| 1100 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1101 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1102 | * |
| 1103 | * This function is made to be called by ethtool and by the driver |
| 1104 | * when it needs to update EITR registers at runtime. Hardware |
| 1105 | * specific quirks/differences are taken care of here. |
| 1106 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1107 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1108 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1109 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1110 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1111 | int v_idx = q_vector->v_idx; |
| 1112 | u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr); |
| 1113 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1114 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1115 | /* must write high and low 16 bits to reset counter */ |
| 1116 | itr_reg |= (itr_reg << 16); |
| 1117 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 1118 | /* |
| 1119 | * set the WDIS bit to not clear the timer bits and cause an |
| 1120 | * immediate assertion of the interrupt |
| 1121 | */ |
| 1122 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
| 1123 | } |
| 1124 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 1125 | } |
| 1126 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1127 | static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector) |
| 1128 | { |
| 1129 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1130 | u32 new_itr; |
| 1131 | u8 current_itr, ret_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1132 | int i, r_idx; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1133 | struct ixgbe_ring *rx_ring, *tx_ring; |
| 1134 | |
| 1135 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1136 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1137 | tx_ring = &(adapter->tx_ring[r_idx]); |
| 1138 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1139 | q_vector->tx_itr, |
| 1140 | tx_ring->total_packets, |
| 1141 | tx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1142 | /* if the result for this queue would decrease interrupt |
| 1143 | * rate for this vector then use that result */ |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1144 | q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ? |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1145 | q_vector->tx_itr - 1 : ret_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1146 | 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] | 1147 | r_idx + 1); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1148 | } |
| 1149 | |
| 1150 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1151 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1152 | rx_ring = &(adapter->rx_ring[r_idx]); |
| 1153 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1154 | q_vector->rx_itr, |
| 1155 | rx_ring->total_packets, |
| 1156 | rx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1157 | /* if the result for this queue would decrease interrupt |
| 1158 | * rate for this vector then use that result */ |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1159 | q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ? |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1160 | q_vector->rx_itr - 1 : ret_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1161 | 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] | 1162 | r_idx + 1); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1163 | } |
| 1164 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1165 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1166 | |
| 1167 | switch (current_itr) { |
| 1168 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1169 | case lowest_latency: |
| 1170 | new_itr = 100000; |
| 1171 | break; |
| 1172 | case low_latency: |
| 1173 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 1174 | break; |
| 1175 | case bulk_latency: |
| 1176 | default: |
| 1177 | new_itr = 8000; |
| 1178 | break; |
| 1179 | } |
| 1180 | |
| 1181 | if (new_itr != q_vector->eitr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1182 | /* do an exponential smoothing */ |
| 1183 | new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1184 | |
| 1185 | /* save the algorithm value here, not the smoothed one */ |
| 1186 | q_vector->eitr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1187 | |
| 1188 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1189 | } |
| 1190 | |
| 1191 | return; |
| 1192 | } |
| 1193 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1194 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 1195 | { |
| 1196 | struct ixgbe_hw *hw = &adapter->hw; |
| 1197 | |
| 1198 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
| 1199 | (eicr & IXGBE_EICR_GPI_SDP1)) { |
| 1200 | DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n"); |
| 1201 | /* write to clear the interrupt */ |
| 1202 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 1203 | } |
| 1204 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1205 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1206 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 1207 | { |
| 1208 | struct ixgbe_hw *hw = &adapter->hw; |
| 1209 | |
| 1210 | if (eicr & IXGBE_EICR_GPI_SDP1) { |
| 1211 | /* Clear the interrupt */ |
| 1212 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 1213 | schedule_work(&adapter->multispeed_fiber_task); |
| 1214 | } else if (eicr & IXGBE_EICR_GPI_SDP2) { |
| 1215 | /* Clear the interrupt */ |
| 1216 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2); |
| 1217 | schedule_work(&adapter->sfp_config_module_task); |
| 1218 | } else { |
| 1219 | /* Interrupt isn't for us... */ |
| 1220 | return; |
| 1221 | } |
| 1222 | } |
| 1223 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1224 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 1225 | { |
| 1226 | struct ixgbe_hw *hw = &adapter->hw; |
| 1227 | |
| 1228 | adapter->lsc_int++; |
| 1229 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 1230 | adapter->link_check_timeout = jiffies; |
| 1231 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1232 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
Nelson, Shannon | 8a0717f | 2009-11-12 18:47:11 +0000 | [diff] [blame] | 1233 | IXGBE_WRITE_FLUSH(hw); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1234 | schedule_work(&adapter->watchdog_task); |
| 1235 | } |
| 1236 | } |
| 1237 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1238 | static irqreturn_t ixgbe_msix_lsc(int irq, void *data) |
| 1239 | { |
| 1240 | struct net_device *netdev = data; |
| 1241 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1242 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 1243 | u32 eicr; |
| 1244 | |
| 1245 | /* |
| 1246 | * Workaround for Silicon errata. Use clear-by-write instead |
| 1247 | * of clear-by-read. Reading with EICS will return the |
| 1248 | * interrupt causes without clearing, which later be done |
| 1249 | * with the write to EICR. |
| 1250 | */ |
| 1251 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
| 1252 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1253 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1254 | if (eicr & IXGBE_EICR_LSC) |
| 1255 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1256 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1257 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 1258 | ixgbe_check_fan_failure(adapter, eicr); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1259 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1260 | if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1261 | ixgbe_check_sfp_event(adapter, eicr); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1262 | |
| 1263 | /* Handle Flow Director Full threshold interrupt */ |
| 1264 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
| 1265 | int i; |
| 1266 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR); |
| 1267 | /* Disable transmits before FDIR Re-initialization */ |
| 1268 | netif_tx_stop_all_queues(netdev); |
| 1269 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 1270 | struct ixgbe_ring *tx_ring = |
| 1271 | &adapter->tx_ring[i]; |
| 1272 | if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE, |
| 1273 | &tx_ring->reinit_state)) |
| 1274 | schedule_work(&adapter->fdir_reinit_task); |
| 1275 | } |
| 1276 | } |
| 1277 | } |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1278 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1279 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1280 | |
| 1281 | return IRQ_HANDLED; |
| 1282 | } |
| 1283 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1284 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 1285 | u64 qmask) |
| 1286 | { |
| 1287 | u32 mask; |
| 1288 | |
| 1289 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1290 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 1291 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 1292 | } else { |
| 1293 | mask = (qmask & 0xFFFFFFFF); |
| 1294 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(0), mask); |
| 1295 | mask = (qmask >> 32); |
| 1296 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask); |
| 1297 | } |
| 1298 | /* skip the flush */ |
| 1299 | } |
| 1300 | |
| 1301 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
| 1302 | u64 qmask) |
| 1303 | { |
| 1304 | u32 mask; |
| 1305 | |
| 1306 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1307 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 1308 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask); |
| 1309 | } else { |
| 1310 | mask = (qmask & 0xFFFFFFFF); |
| 1311 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), mask); |
| 1312 | mask = (qmask >> 32); |
| 1313 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), mask); |
| 1314 | } |
| 1315 | /* skip the flush */ |
| 1316 | } |
| 1317 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1318 | static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data) |
| 1319 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1320 | struct ixgbe_q_vector *q_vector = data; |
| 1321 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1322 | struct ixgbe_ring *tx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1323 | int i, r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1324 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1325 | if (!q_vector->txr_count) |
| 1326 | return IRQ_HANDLED; |
| 1327 | |
| 1328 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1329 | for (i = 0; i < q_vector->txr_count; i++) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1330 | tx_ring = &(adapter->tx_ring[r_idx]); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1331 | tx_ring->total_bytes = 0; |
| 1332 | tx_ring->total_packets = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1333 | 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] | 1334 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1335 | } |
| 1336 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 1337 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1338 | napi_schedule(&q_vector->napi); |
| 1339 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1340 | return IRQ_HANDLED; |
| 1341 | } |
| 1342 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1343 | /** |
| 1344 | * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues) |
| 1345 | * @irq: unused |
| 1346 | * @data: pointer to our q_vector struct for this interrupt vector |
| 1347 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1348 | static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data) |
| 1349 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1350 | struct ixgbe_q_vector *q_vector = data; |
| 1351 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1352 | struct ixgbe_ring *rx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1353 | int r_idx; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1354 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1355 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1356 | 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] | 1357 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1358 | rx_ring = &(adapter->rx_ring[r_idx]); |
| 1359 | rx_ring->total_bytes = 0; |
| 1360 | rx_ring->total_packets = 0; |
| 1361 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1362 | r_idx + 1); |
| 1363 | } |
| 1364 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1365 | if (!q_vector->rxr_count) |
| 1366 | return IRQ_HANDLED; |
| 1367 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1368 | /* disable interrupts on this vector only */ |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 1369 | /* EIAM disabled interrupts (on this vector) for us */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1370 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1371 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1372 | return IRQ_HANDLED; |
| 1373 | } |
| 1374 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1375 | static irqreturn_t ixgbe_msix_clean_many(int irq, void *data) |
| 1376 | { |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1377 | struct ixgbe_q_vector *q_vector = data; |
| 1378 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1379 | struct ixgbe_ring *ring; |
| 1380 | int r_idx; |
| 1381 | int i; |
| 1382 | |
| 1383 | if (!q_vector->txr_count && !q_vector->rxr_count) |
| 1384 | return IRQ_HANDLED; |
| 1385 | |
| 1386 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1387 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1388 | ring = &(adapter->tx_ring[r_idx]); |
| 1389 | ring->total_bytes = 0; |
| 1390 | ring->total_packets = 0; |
| 1391 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
| 1392 | r_idx + 1); |
| 1393 | } |
| 1394 | |
| 1395 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1396 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1397 | ring = &(adapter->rx_ring[r_idx]); |
| 1398 | ring->total_bytes = 0; |
| 1399 | ring->total_packets = 0; |
| 1400 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1401 | r_idx + 1); |
| 1402 | } |
| 1403 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 1404 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1405 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1406 | |
| 1407 | return IRQ_HANDLED; |
| 1408 | } |
| 1409 | |
| 1410 | /** |
| 1411 | * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine |
| 1412 | * @napi: napi struct with our devices info in it |
| 1413 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1414 | * |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1415 | * This function is optimized for cleaning one queue only on a single |
| 1416 | * q_vector!!! |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1417 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1418 | static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget) |
| 1419 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1420 | struct ixgbe_q_vector *q_vector = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1421 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1422 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1423 | struct ixgbe_ring *rx_ring = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1424 | int work_done = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1425 | long r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1426 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1427 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1428 | rx_ring = &(adapter->rx_ring[r_idx]); |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1429 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1430 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1431 | ixgbe_update_rx_dca(adapter, rx_ring); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1432 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1433 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1434 | ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1435 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1436 | /* If all Rx work done, exit the polling mode */ |
| 1437 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1438 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1439 | if (adapter->rx_itr_setting & 1) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1440 | ixgbe_set_itr_msix(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1441 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1442 | ixgbe_irq_enable_queues(adapter, |
| 1443 | ((u64)1 << q_vector->v_idx)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1444 | } |
| 1445 | |
| 1446 | return work_done; |
| 1447 | } |
| 1448 | |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1449 | /** |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1450 | * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1451 | * @napi: napi struct with our devices info in it |
| 1452 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1453 | * |
| 1454 | * This function will clean more than one rx queue associated with a |
| 1455 | * q_vector. |
| 1456 | **/ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1457 | static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget) |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1458 | { |
| 1459 | struct ixgbe_q_vector *q_vector = |
| 1460 | container_of(napi, struct ixgbe_q_vector, napi); |
| 1461 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1462 | struct ixgbe_ring *ring = NULL; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1463 | int work_done = 0, i; |
| 1464 | long r_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1465 | bool tx_clean_complete = true; |
| 1466 | |
| 1467 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1468 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1469 | ring = &(adapter->tx_ring[r_idx]); |
| 1470 | #ifdef CONFIG_IXGBE_DCA |
| 1471 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1472 | ixgbe_update_tx_dca(adapter, ring); |
| 1473 | #endif |
| 1474 | tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring); |
| 1475 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
| 1476 | r_idx + 1); |
| 1477 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1478 | |
| 1479 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 1480 | * the budget to go below 1 because we'll exit polling */ |
| 1481 | budget /= (q_vector->rxr_count ?: 1); |
| 1482 | budget = max(budget, 1); |
| 1483 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1484 | for (i = 0; i < q_vector->rxr_count; i++) { |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1485 | ring = &(adapter->rx_ring[r_idx]); |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1486 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1487 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1488 | ixgbe_update_rx_dca(adapter, ring); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1489 | #endif |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1490 | ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1491 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1492 | r_idx + 1); |
| 1493 | } |
| 1494 | |
| 1495 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1496 | ring = &(adapter->rx_ring[r_idx]); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1497 | /* If all Rx work done, exit the polling mode */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 1498 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1499 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1500 | if (adapter->rx_itr_setting & 1) |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1501 | ixgbe_set_itr_msix(q_vector); |
| 1502 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1503 | ixgbe_irq_enable_queues(adapter, |
| 1504 | ((u64)1 << q_vector->v_idx)); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1505 | return 0; |
| 1506 | } |
| 1507 | |
| 1508 | return work_done; |
| 1509 | } |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1510 | |
| 1511 | /** |
| 1512 | * ixgbe_clean_txonly - msix (aka one shot) tx clean routine |
| 1513 | * @napi: napi struct with our devices info in it |
| 1514 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1515 | * |
| 1516 | * This function is optimized for cleaning one queue only on a single |
| 1517 | * q_vector!!! |
| 1518 | **/ |
| 1519 | static int ixgbe_clean_txonly(struct napi_struct *napi, int budget) |
| 1520 | { |
| 1521 | struct ixgbe_q_vector *q_vector = |
| 1522 | container_of(napi, struct ixgbe_q_vector, napi); |
| 1523 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1524 | struct ixgbe_ring *tx_ring = NULL; |
| 1525 | int work_done = 0; |
| 1526 | long r_idx; |
| 1527 | |
| 1528 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1529 | tx_ring = &(adapter->tx_ring[r_idx]); |
| 1530 | #ifdef CONFIG_IXGBE_DCA |
| 1531 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1532 | ixgbe_update_tx_dca(adapter, tx_ring); |
| 1533 | #endif |
| 1534 | |
| 1535 | if (!ixgbe_clean_tx_irq(q_vector, tx_ring)) |
| 1536 | work_done = budget; |
| 1537 | |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1538 | /* If all Tx work done, exit the polling mode */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1539 | if (work_done < budget) { |
| 1540 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1541 | if (adapter->tx_itr_setting & 1) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1542 | ixgbe_set_itr_msix(q_vector); |
| 1543 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1544 | ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 1545 | } |
| 1546 | |
| 1547 | return work_done; |
| 1548 | } |
| 1549 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1550 | 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] | 1551 | int r_idx) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1552 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1553 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
| 1554 | |
| 1555 | set_bit(r_idx, q_vector->rxr_idx); |
| 1556 | q_vector->rxr_count++; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1557 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1558 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1559 | 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] | 1560 | int t_idx) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1561 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1562 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
| 1563 | |
| 1564 | set_bit(t_idx, q_vector->txr_idx); |
| 1565 | q_vector->txr_count++; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1566 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1567 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1568 | /** |
| 1569 | * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors |
| 1570 | * @adapter: board private structure to initialize |
| 1571 | * @vectors: allotted vector count for descriptor rings |
| 1572 | * |
| 1573 | * This function maps descriptor rings to the queue-specific vectors |
| 1574 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 1575 | * one vector per ring/queue, but on a constrained vector budget, we |
| 1576 | * group the rings as "efficiently" as possible. You would add new |
| 1577 | * mapping configurations in here. |
| 1578 | **/ |
| 1579 | static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1580 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1581 | { |
| 1582 | int v_start = 0; |
| 1583 | int rxr_idx = 0, txr_idx = 0; |
| 1584 | int rxr_remaining = adapter->num_rx_queues; |
| 1585 | int txr_remaining = adapter->num_tx_queues; |
| 1586 | int i, j; |
| 1587 | int rqpv, tqpv; |
| 1588 | int err = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1589 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1590 | /* No mapping required if MSI-X is disabled. */ |
| 1591 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1592 | goto out; |
| 1593 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1594 | /* |
| 1595 | * The ideal configuration... |
| 1596 | * We have enough vectors to map one per queue. |
| 1597 | */ |
| 1598 | if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) { |
| 1599 | for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++) |
| 1600 | map_vector_to_rxq(adapter, v_start, rxr_idx); |
| 1601 | |
| 1602 | for (; txr_idx < txr_remaining; v_start++, txr_idx++) |
| 1603 | map_vector_to_txq(adapter, v_start, txr_idx); |
| 1604 | |
| 1605 | goto out; |
| 1606 | } |
| 1607 | |
| 1608 | /* |
| 1609 | * If we don't have enough vectors for a 1-to-1 |
| 1610 | * mapping, we'll have to group them so there are |
| 1611 | * multiple queues per vector. |
| 1612 | */ |
| 1613 | /* Re-adjusting *qpv takes care of the remainder. */ |
| 1614 | for (i = v_start; i < vectors; i++) { |
| 1615 | rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i); |
| 1616 | for (j = 0; j < rqpv; j++) { |
| 1617 | map_vector_to_rxq(adapter, i, rxr_idx); |
| 1618 | rxr_idx++; |
| 1619 | rxr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1620 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1621 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1622 | for (i = v_start; i < vectors; i++) { |
| 1623 | tqpv = DIV_ROUND_UP(txr_remaining, vectors - i); |
| 1624 | for (j = 0; j < tqpv; j++) { |
| 1625 | map_vector_to_txq(adapter, i, txr_idx); |
| 1626 | txr_idx++; |
| 1627 | txr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1628 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1629 | } |
| 1630 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1631 | out: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1632 | return err; |
| 1633 | } |
| 1634 | |
| 1635 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1636 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 1637 | * @adapter: board private structure |
| 1638 | * |
| 1639 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 1640 | * interrupts from the kernel. |
| 1641 | **/ |
| 1642 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 1643 | { |
| 1644 | struct net_device *netdev = adapter->netdev; |
| 1645 | irqreturn_t (*handler)(int, void *); |
| 1646 | int i, vector, q_vectors, err; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 1647 | int ri=0, ti=0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1648 | |
| 1649 | /* Decrement for Other and TCP Timer vectors */ |
| 1650 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1651 | |
| 1652 | /* Map the Tx/Rx rings to the vectors we were allotted. */ |
| 1653 | err = ixgbe_map_rings_to_vectors(adapter, q_vectors); |
| 1654 | if (err) |
| 1655 | goto out; |
| 1656 | |
| 1657 | #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \ |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1658 | (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \ |
| 1659 | &ixgbe_msix_clean_many) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1660 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1661 | handler = SET_HANDLER(adapter->q_vector[vector]); |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 1662 | |
| 1663 | if(handler == &ixgbe_msix_clean_rx) { |
| 1664 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1665 | netdev->name, "rx", ri++); |
| 1666 | } |
| 1667 | else if(handler == &ixgbe_msix_clean_tx) { |
| 1668 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1669 | netdev->name, "tx", ti++); |
| 1670 | } |
| 1671 | else |
| 1672 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1673 | netdev->name, "TxRx", vector); |
| 1674 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1675 | err = request_irq(adapter->msix_entries[vector].vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1676 | handler, 0, adapter->name[vector], |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1677 | adapter->q_vector[vector]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1678 | if (err) { |
| 1679 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1680 | "request_irq failed for MSIX interrupt " |
| 1681 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1682 | goto free_queue_irqs; |
| 1683 | } |
| 1684 | } |
| 1685 | |
| 1686 | sprintf(adapter->name[vector], "%s:lsc", netdev->name); |
| 1687 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1688 | ixgbe_msix_lsc, 0, adapter->name[vector], netdev); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1689 | if (err) { |
| 1690 | DPRINTK(PROBE, ERR, |
| 1691 | "request_irq for msix_lsc failed: %d\n", err); |
| 1692 | goto free_queue_irqs; |
| 1693 | } |
| 1694 | |
| 1695 | return 0; |
| 1696 | |
| 1697 | free_queue_irqs: |
| 1698 | for (i = vector - 1; i >= 0; i--) |
| 1699 | free_irq(adapter->msix_entries[--vector].vector, |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1700 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1701 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 1702 | pci_disable_msix(adapter->pdev); |
| 1703 | kfree(adapter->msix_entries); |
| 1704 | adapter->msix_entries = NULL; |
| 1705 | out: |
| 1706 | return err; |
| 1707 | } |
| 1708 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1709 | static void ixgbe_set_itr(struct ixgbe_adapter *adapter) |
| 1710 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1711 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1712 | u8 current_itr; |
| 1713 | u32 new_itr = q_vector->eitr; |
| 1714 | struct ixgbe_ring *rx_ring = &adapter->rx_ring[0]; |
| 1715 | struct ixgbe_ring *tx_ring = &adapter->tx_ring[0]; |
| 1716 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1717 | q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1718 | q_vector->tx_itr, |
| 1719 | tx_ring->total_packets, |
| 1720 | tx_ring->total_bytes); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1721 | q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1722 | q_vector->rx_itr, |
| 1723 | rx_ring->total_packets, |
| 1724 | rx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1725 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1726 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1727 | |
| 1728 | switch (current_itr) { |
| 1729 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1730 | case lowest_latency: |
| 1731 | new_itr = 100000; |
| 1732 | break; |
| 1733 | case low_latency: |
| 1734 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 1735 | break; |
| 1736 | case bulk_latency: |
| 1737 | new_itr = 8000; |
| 1738 | break; |
| 1739 | default: |
| 1740 | break; |
| 1741 | } |
| 1742 | |
| 1743 | if (new_itr != q_vector->eitr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1744 | /* do an exponential smoothing */ |
| 1745 | new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1746 | |
| 1747 | /* save the algorithm value here, not the smoothed one */ |
| 1748 | q_vector->eitr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1749 | |
| 1750 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | return; |
| 1754 | } |
| 1755 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1756 | /** |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1757 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 1758 | * @adapter: board private structure |
| 1759 | **/ |
| 1760 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter) |
| 1761 | { |
| 1762 | u32 mask; |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1763 | |
| 1764 | mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
David S. Miller | 6ab33d5 | 2008-11-20 16:44:00 -0800 | [diff] [blame] | 1765 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
| 1766 | mask |= IXGBE_EIMS_GPI_SDP1; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1767 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 1768 | mask |= IXGBE_EIMS_ECC; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1769 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 1770 | mask |= IXGBE_EIMS_GPI_SDP2; |
| 1771 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1772 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 1773 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 1774 | mask |= IXGBE_EIMS_FLOW_DIR; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1775 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1776 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1777 | ixgbe_irq_enable_queues(adapter, ~0); |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1778 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 1779 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1780 | |
| 1781 | /** |
| 1782 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1783 | * @irq: interrupt number |
| 1784 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1785 | **/ |
| 1786 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 1787 | { |
| 1788 | struct net_device *netdev = data; |
| 1789 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1790 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1791 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1792 | u32 eicr; |
| 1793 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 1794 | /* |
| 1795 | * Workaround for silicon errata. Mask the interrupts |
| 1796 | * before the read of EICR. |
| 1797 | */ |
| 1798 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 1799 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1800 | /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read |
| 1801 | * therefore no explict interrupt disable is necessary */ |
| 1802 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 1803 | if (!eicr) { |
| 1804 | /* shared interrupt alert! |
| 1805 | * make sure interrupts are enabled because the read will |
| 1806 | * have disabled interrupts due to EIAM */ |
| 1807 | ixgbe_irq_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1808 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 1809 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1810 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1811 | if (eicr & IXGBE_EICR_LSC) |
| 1812 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1813 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1814 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 1815 | ixgbe_check_sfp_event(adapter, eicr); |
| 1816 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1817 | ixgbe_check_fan_failure(adapter, eicr); |
| 1818 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1819 | if (napi_schedule_prep(&(q_vector->napi))) { |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1820 | adapter->tx_ring[0].total_packets = 0; |
| 1821 | adapter->tx_ring[0].total_bytes = 0; |
| 1822 | adapter->rx_ring[0].total_packets = 0; |
| 1823 | adapter->rx_ring[0].total_bytes = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1824 | /* would disable interrupts here but EIAM disabled it */ |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1825 | __napi_schedule(&(q_vector->napi)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1826 | } |
| 1827 | |
| 1828 | return IRQ_HANDLED; |
| 1829 | } |
| 1830 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1831 | static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter) |
| 1832 | { |
| 1833 | int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1834 | |
| 1835 | for (i = 0; i < q_vectors; i++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1836 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1837 | bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES); |
| 1838 | bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES); |
| 1839 | q_vector->rxr_count = 0; |
| 1840 | q_vector->txr_count = 0; |
| 1841 | } |
| 1842 | } |
| 1843 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1844 | /** |
| 1845 | * ixgbe_request_irq - initialize interrupts |
| 1846 | * @adapter: board private structure |
| 1847 | * |
| 1848 | * Attempts to configure interrupts using the best available |
| 1849 | * capabilities of the hardware and kernel. |
| 1850 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1851 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1852 | { |
| 1853 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1854 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1855 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1856 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 1857 | err = ixgbe_request_msix_irqs(adapter); |
| 1858 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1859 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1860 | netdev->name, netdev); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1861 | } else { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1862 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1863 | netdev->name, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1864 | } |
| 1865 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1866 | if (err) |
| 1867 | DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err); |
| 1868 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1869 | return err; |
| 1870 | } |
| 1871 | |
| 1872 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 1873 | { |
| 1874 | struct net_device *netdev = adapter->netdev; |
| 1875 | |
| 1876 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1877 | int i, q_vectors; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1878 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1879 | q_vectors = adapter->num_msix_vectors; |
| 1880 | |
| 1881 | i = q_vectors - 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1882 | free_irq(adapter->msix_entries[i].vector, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1883 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1884 | i--; |
| 1885 | for (; i >= 0; i--) { |
| 1886 | free_irq(adapter->msix_entries[i].vector, |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1887 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1888 | } |
| 1889 | |
| 1890 | ixgbe_reset_q_vectors(adapter); |
| 1891 | } else { |
| 1892 | free_irq(adapter->pdev->irq, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1893 | } |
| 1894 | } |
| 1895 | |
| 1896 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1897 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 1898 | * @adapter: board private structure |
| 1899 | **/ |
| 1900 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 1901 | { |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1902 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1903 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
| 1904 | } else { |
| 1905 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 1906 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1907 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1908 | } |
| 1909 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 1910 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 1911 | int i; |
| 1912 | for (i = 0; i < adapter->num_msix_vectors; i++) |
| 1913 | synchronize_irq(adapter->msix_entries[i].vector); |
| 1914 | } else { |
| 1915 | synchronize_irq(adapter->pdev->irq); |
| 1916 | } |
| 1917 | } |
| 1918 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1919 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1920 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 1921 | * |
| 1922 | **/ |
| 1923 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 1924 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1925 | struct ixgbe_hw *hw = &adapter->hw; |
| 1926 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1927 | IXGBE_WRITE_REG(hw, IXGBE_EITR(0), |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1928 | EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1929 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1930 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 1931 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1932 | |
| 1933 | map_vector_to_rxq(adapter, 0, 0); |
| 1934 | map_vector_to_txq(adapter, 0, 0); |
| 1935 | |
| 1936 | DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1937 | } |
| 1938 | |
| 1939 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1940 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1941 | * @adapter: board private structure |
| 1942 | * |
| 1943 | * Configure the Tx unit of the MAC after a reset. |
| 1944 | **/ |
| 1945 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 1946 | { |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1947 | u64 tdba; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1948 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1949 | u32 i, j, tdlen, txctrl; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1950 | |
| 1951 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 1952 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1953 | struct ixgbe_ring *ring = &adapter->tx_ring[i]; |
| 1954 | j = ring->reg_idx; |
| 1955 | tdba = ring->dma; |
| 1956 | tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1957 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j), |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1958 | (tdba & DMA_BIT_MASK(32))); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1959 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32)); |
| 1960 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen); |
| 1961 | IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0); |
| 1962 | IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0); |
| 1963 | adapter->tx_ring[i].head = IXGBE_TDH(j); |
| 1964 | adapter->tx_ring[i].tail = IXGBE_TDT(j); |
Peter P Waskiewicz Jr | 84f62d4 | 2009-09-30 12:07:16 +0000 | [diff] [blame] | 1965 | /* |
| 1966 | * Disable Tx Head Writeback RO bit, since this hoses |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1967 | * bookkeeping if things aren't delivered in order. |
| 1968 | */ |
Peter P Waskiewicz Jr | 84f62d4 | 2009-09-30 12:07:16 +0000 | [diff] [blame] | 1969 | switch (hw->mac.type) { |
| 1970 | case ixgbe_mac_82598EB: |
| 1971 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j)); |
| 1972 | break; |
| 1973 | case ixgbe_mac_82599EB: |
| 1974 | default: |
| 1975 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(j)); |
| 1976 | break; |
| 1977 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1978 | txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN; |
Peter P Waskiewicz Jr | 84f62d4 | 2009-09-30 12:07:16 +0000 | [diff] [blame] | 1979 | switch (hw->mac.type) { |
| 1980 | case ixgbe_mac_82598EB: |
| 1981 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl); |
| 1982 | break; |
| 1983 | case ixgbe_mac_82599EB: |
| 1984 | default: |
| 1985 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(j), txctrl); |
| 1986 | break; |
| 1987 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1988 | } |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 1989 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1990 | if (hw->mac.type == ixgbe_mac_82599EB) { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 1991 | u32 rttdcs; |
| 1992 | |
| 1993 | /* disable the arbiter while setting MTQC */ |
| 1994 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 1995 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 1996 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 1997 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1998 | /* We enable 8 traffic classes, DCB only */ |
| 1999 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 2000 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA | |
| 2001 | IXGBE_MTQC_8TC_8TQ)); |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 2002 | else |
| 2003 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB); |
| 2004 | |
| 2005 | /* re-eable the arbiter */ |
| 2006 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 2007 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2008 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2009 | } |
| 2010 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2011 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2012 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2013 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
| 2014 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2015 | { |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2016 | u32 srrctl; |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2017 | int index; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2018 | struct ixgbe_ring_feature *feature = adapter->ring_feature; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2019 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2020 | index = rx_ring->reg_idx; |
| 2021 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 2022 | unsigned long mask; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2023 | mask = (unsigned long) feature[RING_F_RSS].mask; |
Alexander Duyck | 3be1adf | 2008-08-30 00:29:10 -0700 | [diff] [blame] | 2024 | index = index & mask; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2025 | } |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2026 | srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index)); |
| 2027 | |
| 2028 | srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2029 | srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK; |
| 2030 | |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2031 | srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) & |
| 2032 | IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2033 | |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 2034 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2035 | #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER |
| 2036 | srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 2037 | #else |
| 2038 | srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 2039 | #endif |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2040 | srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2041 | } else { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2042 | srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >> |
| 2043 | IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2044 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2045 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2046 | |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2047 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl); |
| 2048 | } |
| 2049 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2050 | static u32 ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
| 2051 | { |
| 2052 | u32 mrqc = 0; |
| 2053 | int mask; |
| 2054 | |
| 2055 | if (!(adapter->hw.mac.type == ixgbe_mac_82599EB)) |
| 2056 | return mrqc; |
| 2057 | |
| 2058 | mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED |
| 2059 | #ifdef CONFIG_IXGBE_DCB |
| 2060 | | IXGBE_FLAG_DCB_ENABLED |
| 2061 | #endif |
| 2062 | ); |
| 2063 | |
| 2064 | switch (mask) { |
| 2065 | case (IXGBE_FLAG_RSS_ENABLED): |
| 2066 | mrqc = IXGBE_MRQC_RSSEN; |
| 2067 | break; |
| 2068 | #ifdef CONFIG_IXGBE_DCB |
| 2069 | case (IXGBE_FLAG_DCB_ENABLED): |
| 2070 | mrqc = IXGBE_MRQC_RT8TCEN; |
| 2071 | break; |
| 2072 | #endif /* CONFIG_IXGBE_DCB */ |
| 2073 | default: |
| 2074 | break; |
| 2075 | } |
| 2076 | |
| 2077 | return mrqc; |
| 2078 | } |
| 2079 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2080 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2081 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 2082 | * @adapter: address of board private structure |
| 2083 | * @index: index of ring to set |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2084 | **/ |
Mallikarjuna R Chilakala | edd2ea55 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2085 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, int index) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2086 | { |
| 2087 | struct ixgbe_ring *rx_ring; |
| 2088 | struct ixgbe_hw *hw = &adapter->hw; |
| 2089 | int j; |
| 2090 | u32 rscctrl; |
Mallikarjuna R Chilakala | edd2ea55 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2091 | int rx_buf_len; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2092 | |
| 2093 | rx_ring = &adapter->rx_ring[index]; |
| 2094 | j = rx_ring->reg_idx; |
Mallikarjuna R Chilakala | edd2ea55 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2095 | rx_buf_len = rx_ring->rx_buf_len; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2096 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(j)); |
| 2097 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 2098 | /* |
| 2099 | * we must limit the number of descriptors so that the |
| 2100 | * total size of max desc * buf_len is not greater |
| 2101 | * than 65535 |
| 2102 | */ |
| 2103 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
| 2104 | #if (MAX_SKB_FRAGS > 16) |
| 2105 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2106 | #elif (MAX_SKB_FRAGS > 8) |
| 2107 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
| 2108 | #elif (MAX_SKB_FRAGS > 4) |
| 2109 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
| 2110 | #else |
| 2111 | rscctrl |= IXGBE_RSCCTL_MAXDESC_1; |
| 2112 | #endif |
| 2113 | } else { |
| 2114 | if (rx_buf_len < IXGBE_RXBUFFER_4096) |
| 2115 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2116 | else if (rx_buf_len < IXGBE_RXBUFFER_8192) |
| 2117 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
| 2118 | else |
| 2119 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
| 2120 | } |
| 2121 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(j), rscctrl); |
| 2122 | } |
| 2123 | |
| 2124 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2125 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2126 | * @adapter: board private structure |
| 2127 | * |
| 2128 | * Configure the Rx unit of the MAC after a reset. |
| 2129 | **/ |
| 2130 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 2131 | { |
| 2132 | u64 rdba; |
| 2133 | struct ixgbe_hw *hw = &adapter->hw; |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2134 | struct ixgbe_ring *rx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2135 | struct net_device *netdev = adapter->netdev; |
| 2136 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2137 | int i, j; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2138 | u32 rdlen, rxctrl, rxcsum; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2139 | static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D, |
| 2140 | 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE, |
| 2141 | 0x6A3E67EA, 0x14364D17, 0x3BED200D}; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2142 | u32 fctrl, hlreg0; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2143 | u32 reta = 0, mrqc = 0; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2144 | u32 rdrxctl; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2145 | int rx_buf_len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2146 | |
| 2147 | /* Decide whether to use packet split mode or not */ |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 2148 | adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2149 | |
| 2150 | /* Set the RX buffer length according to the mode */ |
| 2151 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2152 | rx_buf_len = IXGBE_RX_HDR_SIZE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2153 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2154 | /* PSRTYPE must be initialized in 82599 */ |
| 2155 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
| 2156 | IXGBE_PSRTYPE_UDPHDR | |
| 2157 | IXGBE_PSRTYPE_IPV4HDR | |
Yi Zou | dfa12f0 | 2009-05-07 10:39:35 +0000 | [diff] [blame] | 2158 | IXGBE_PSRTYPE_IPV6HDR | |
| 2159 | IXGBE_PSRTYPE_L2HDR; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2160 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype); |
| 2161 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2162 | } else { |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 2163 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) && |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2164 | (netdev->mtu <= ETH_DATA_LEN)) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2165 | rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2166 | else |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2167 | rx_buf_len = ALIGN(max_frame, 1024); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2168 | } |
| 2169 | |
| 2170 | fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL); |
| 2171 | fctrl |= IXGBE_FCTRL_BAM; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2172 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2173 | fctrl |= IXGBE_FCTRL_PMCF; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2174 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl); |
| 2175 | |
| 2176 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
| 2177 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 2178 | hlreg0 &= ~IXGBE_HLREG0_JUMBOEN; |
| 2179 | else |
| 2180 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2181 | #ifdef IXGBE_FCOE |
Yi Zou | f34c5c8 | 2009-08-14 12:42:17 +0000 | [diff] [blame] | 2182 | if (netdev->features & NETIF_F_FCOE_MTU) |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2183 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
| 2184 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2185 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 2186 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2187 | rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc); |
| 2188 | /* disable receives while setting up the descriptors */ |
| 2189 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 2190 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
| 2191 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2192 | /* |
| 2193 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 2194 | * the Base and Length of the Rx Descriptor Ring |
| 2195 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2196 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2197 | rx_ring = &adapter->rx_ring[i]; |
| 2198 | rdba = rx_ring->dma; |
| 2199 | j = rx_ring->reg_idx; |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2200 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_BIT_MASK(32))); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2201 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32)); |
| 2202 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen); |
| 2203 | IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0); |
| 2204 | IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0); |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2205 | rx_ring->head = IXGBE_RDH(j); |
| 2206 | rx_ring->tail = IXGBE_RDT(j); |
| 2207 | rx_ring->rx_buf_len = rx_buf_len; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2208 | |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 2209 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) |
| 2210 | rx_ring->flags |= IXGBE_RING_RX_PS_ENABLED; |
Peter P Waskiewicz Jr | 1b3ff02 | 2009-09-14 07:47:27 +0000 | [diff] [blame] | 2211 | else |
| 2212 | rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2213 | |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2214 | #ifdef IXGBE_FCOE |
Yi Zou | f34c5c8 | 2009-08-14 12:42:17 +0000 | [diff] [blame] | 2215 | if (netdev->features & NETIF_F_FCOE_MTU) { |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2216 | struct ixgbe_ring_feature *f; |
| 2217 | f = &adapter->ring_feature[RING_F_FCOE]; |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 2218 | if ((i >= f->mask) && (i < f->mask + f->indices)) { |
| 2219 | rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED; |
| 2220 | if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE) |
| 2221 | rx_ring->rx_buf_len = |
| 2222 | IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 2223 | } |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2224 | } |
| 2225 | |
| 2226 | #endif /* IXGBE_FCOE */ |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2227 | ixgbe_configure_srrctl(adapter, rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2228 | } |
| 2229 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2230 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 2231 | /* |
| 2232 | * For VMDq support of different descriptor types or |
| 2233 | * buffer sizes through the use of multiple SRRCTL |
| 2234 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 2235 | * |
| 2236 | * also, the manual doesn't mention it clearly but DCA hints |
| 2237 | * will only use queue 0's tags unless this bit is set. Side |
| 2238 | * effects of setting this bit are only that SRRCTL must be |
| 2239 | * fully programmed [0..15] |
| 2240 | */ |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2241 | rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 2242 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 2243 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2244 | } |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2245 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2246 | /* Program MRQC for the distribution of queues */ |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2247 | mrqc = ixgbe_setup_mrqc(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2248 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2249 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2250 | /* Fill out redirection table */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2251 | for (i = 0, j = 0; i < 128; i++, j++) { |
| 2252 | if (j == adapter->ring_feature[RING_F_RSS].indices) |
| 2253 | j = 0; |
| 2254 | /* reta = 4-byte sliding window of |
| 2255 | * 0x00..(indices-1)(indices-1)00..etc. */ |
| 2256 | reta = (reta << 8) | (j * 0x11); |
| 2257 | if ((i & 3) == 3) |
| 2258 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2259 | } |
| 2260 | |
| 2261 | /* Fill out hash function seeds */ |
| 2262 | for (i = 0; i < 10; i++) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2263 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2264 | |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2265 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2266 | mrqc |= IXGBE_MRQC_RSSEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2267 | /* Perform hash on these packet types */ |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2268 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
| 2269 | | IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
| 2270 | | IXGBE_MRQC_RSS_FIELD_IPV4_UDP |
| 2271 | | IXGBE_MRQC_RSS_FIELD_IPV6 |
| 2272 | | IXGBE_MRQC_RSS_FIELD_IPV6_TCP |
| 2273 | | IXGBE_MRQC_RSS_FIELD_IPV6_UDP; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2274 | } |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2275 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2276 | |
| 2277 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 2278 | |
| 2279 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED || |
| 2280 | adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) { |
| 2281 | /* Disable indicating checksum in descriptor, enables |
| 2282 | * RSS hash */ |
| 2283 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 2284 | } |
| 2285 | if (!(rxcsum & IXGBE_RXCSUM_PCSD)) { |
| 2286 | /* Enable IPv4 payload checksum for UDP fragments |
| 2287 | * if PCSD is not set */ |
| 2288 | rxcsum |= IXGBE_RXCSUM_IPPCSE; |
| 2289 | } |
| 2290 | |
| 2291 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2292 | |
| 2293 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2294 | rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 2295 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2296 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2297 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 2298 | } |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2299 | |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 2300 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2301 | /* Enable 82599 HW-RSC */ |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2302 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | edd2ea55 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2303 | ixgbe_configure_rscctl(adapter, i); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2304 | |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2305 | /* Disable RSC for ACK packets */ |
| 2306 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 2307 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 2308 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2309 | } |
| 2310 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2311 | static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 2312 | { |
| 2313 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2314 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2315 | |
| 2316 | /* add VID to filter table */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2317 | hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2318 | } |
| 2319 | |
| 2320 | static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 2321 | { |
| 2322 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2323 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2324 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2325 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2326 | ixgbe_irq_disable(adapter); |
| 2327 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2328 | vlan_group_set_device(adapter->vlgrp, vid, NULL); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2329 | |
| 2330 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2331 | ixgbe_irq_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2332 | |
| 2333 | /* remove VID from filter table */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2334 | hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2335 | } |
| 2336 | |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2337 | static void ixgbe_vlan_rx_register(struct net_device *netdev, |
| 2338 | struct vlan_group *grp) |
| 2339 | { |
| 2340 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2341 | u32 ctrl; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2342 | int i, j; |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2343 | |
| 2344 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2345 | ixgbe_irq_disable(adapter); |
| 2346 | adapter->vlgrp = grp; |
| 2347 | |
| 2348 | /* |
| 2349 | * For a DCB driver, always enable VLAN tag stripping so we can |
| 2350 | * still receive traffic from a DCB-enabled host even if we're |
| 2351 | * not in DCB mode. |
| 2352 | */ |
| 2353 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL); |
Alexander Duyck | dc63d37 | 2009-11-23 06:32:57 +0000 | [diff] [blame] | 2354 | |
| 2355 | /* Disable CFI check */ |
| 2356 | ctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2357 | |
| 2358 | /* enable VLAN tag stripping */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2359 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | dc63d37 | 2009-11-23 06:32:57 +0000 | [diff] [blame] | 2360 | ctrl |= IXGBE_VLNCTRL_VME; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2361 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2362 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | dc63d37 | 2009-11-23 06:32:57 +0000 | [diff] [blame] | 2363 | u32 ctrl; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2364 | j = adapter->rx_ring[i].reg_idx; |
| 2365 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j)); |
| 2366 | ctrl |= IXGBE_RXDCTL_VME; |
| 2367 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl); |
| 2368 | } |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2369 | } |
Alexander Duyck | dc63d37 | 2009-11-23 06:32:57 +0000 | [diff] [blame] | 2370 | |
| 2371 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl); |
| 2372 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2373 | ixgbe_vlan_rx_add_vid(netdev, 0); |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2374 | |
| 2375 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2376 | ixgbe_irq_enable(adapter); |
| 2377 | } |
| 2378 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2379 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 2380 | { |
| 2381 | ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 2382 | |
| 2383 | if (adapter->vlgrp) { |
| 2384 | u16 vid; |
| 2385 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
| 2386 | if (!vlan_group_get_device(adapter->vlgrp, vid)) |
| 2387 | continue; |
| 2388 | ixgbe_vlan_rx_add_vid(adapter->netdev, vid); |
| 2389 | } |
| 2390 | } |
| 2391 | } |
| 2392 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2393 | static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq) |
| 2394 | { |
| 2395 | struct dev_mc_list *mc_ptr; |
| 2396 | u8 *addr = *mc_addr_ptr; |
| 2397 | *vmdq = 0; |
| 2398 | |
| 2399 | mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]); |
| 2400 | if (mc_ptr->next) |
| 2401 | *mc_addr_ptr = mc_ptr->next->dmi_addr; |
| 2402 | else |
| 2403 | *mc_addr_ptr = NULL; |
| 2404 | |
| 2405 | return addr; |
| 2406 | } |
| 2407 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2408 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2409 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2410 | * @netdev: network interface device structure |
| 2411 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2412 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 2413 | * address list or the network interface flags are updated. This routine is |
| 2414 | * responsible for configuring the hardware for proper unicast, multicast and |
| 2415 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2416 | **/ |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2417 | static void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2418 | { |
| 2419 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2420 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2421 | u32 fctrl, vlnctrl; |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2422 | u8 *addr_list = NULL; |
| 2423 | int addr_count = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2424 | |
| 2425 | /* Check for Promiscuous and All Multicast modes */ |
| 2426 | |
| 2427 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2428 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2429 | |
| 2430 | if (netdev->flags & IFF_PROMISC) { |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2431 | hw->addr_ctrl.user_set_promisc = 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2432 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2433 | vlnctrl &= ~IXGBE_VLNCTRL_VFE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2434 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2435 | if (netdev->flags & IFF_ALLMULTI) { |
| 2436 | fctrl |= IXGBE_FCTRL_MPE; |
| 2437 | fctrl &= ~IXGBE_FCTRL_UPE; |
| 2438 | } else { |
| 2439 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
| 2440 | } |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2441 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2442 | hw->addr_ctrl.user_set_promisc = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2443 | } |
| 2444 | |
| 2445 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2446 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2447 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2448 | /* reprogram secondary unicast list */ |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 2449 | hw->mac.ops.update_uc_addr_list(hw, &netdev->uc.list); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2450 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2451 | /* reprogram multicast list */ |
| 2452 | addr_count = netdev->mc_count; |
| 2453 | if (addr_count) |
| 2454 | addr_list = netdev->mc_list->dmi_addr; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2455 | hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count, |
| 2456 | ixgbe_addr_list_itr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2457 | } |
| 2458 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2459 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 2460 | { |
| 2461 | int q_idx; |
| 2462 | struct ixgbe_q_vector *q_vector; |
| 2463 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2464 | |
| 2465 | /* legacy and MSI only use one vector */ |
| 2466 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 2467 | q_vectors = 1; |
| 2468 | |
| 2469 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2470 | struct napi_struct *napi; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2471 | q_vector = adapter->q_vector[q_idx]; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2472 | napi = &q_vector->napi; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2473 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2474 | if (!q_vector->rxr_count || !q_vector->txr_count) { |
| 2475 | if (q_vector->txr_count == 1) |
| 2476 | napi->poll = &ixgbe_clean_txonly; |
| 2477 | else if (q_vector->rxr_count == 1) |
| 2478 | napi->poll = &ixgbe_clean_rxonly; |
| 2479 | } |
| 2480 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2481 | |
| 2482 | napi_enable(napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2483 | } |
| 2484 | } |
| 2485 | |
| 2486 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 2487 | { |
| 2488 | int q_idx; |
| 2489 | struct ixgbe_q_vector *q_vector; |
| 2490 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2491 | |
| 2492 | /* legacy and MSI only use one vector */ |
| 2493 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 2494 | q_vectors = 1; |
| 2495 | |
| 2496 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2497 | q_vector = adapter->q_vector[q_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2498 | napi_disable(&q_vector->napi); |
| 2499 | } |
| 2500 | } |
| 2501 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 2502 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2503 | /* |
| 2504 | * ixgbe_configure_dcb - Configure DCB hardware |
| 2505 | * @adapter: ixgbe adapter struct |
| 2506 | * |
| 2507 | * This is called by the driver on open to configure the DCB hardware. |
| 2508 | * This is also called by the gennetlink interface when reconfiguring |
| 2509 | * the DCB state. |
| 2510 | */ |
| 2511 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 2512 | { |
| 2513 | struct ixgbe_hw *hw = &adapter->hw; |
| 2514 | u32 txdctl, vlnctrl; |
| 2515 | int i, j; |
| 2516 | |
| 2517 | ixgbe_dcb_check_config(&adapter->dcb_cfg); |
| 2518 | ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG); |
| 2519 | ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG); |
| 2520 | |
| 2521 | /* reconfigure the hardware */ |
| 2522 | ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg); |
| 2523 | |
| 2524 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2525 | j = adapter->tx_ring[i].reg_idx; |
| 2526 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
| 2527 | /* PThresh workaround for Tx hang with DFP enabled. */ |
| 2528 | txdctl |= 32; |
| 2529 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
| 2530 | } |
| 2531 | /* Enable VLAN tag insert/strip */ |
| 2532 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2533 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 2534 | vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE; |
| 2535 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2536 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 2537 | } else if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2538 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 2539 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2540 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 2541 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 2542 | j = adapter->rx_ring[i].reg_idx; |
| 2543 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 2544 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 2545 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 2546 | } |
| 2547 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2548 | hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true); |
| 2549 | } |
| 2550 | |
| 2551 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2552 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 2553 | { |
| 2554 | struct net_device *netdev = adapter->netdev; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2555 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2556 | int i; |
| 2557 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2558 | ixgbe_set_rx_mode(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2559 | |
| 2560 | ixgbe_restore_vlan(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 2561 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2562 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Yi Zou | b352e40 | 2009-11-06 12:55:38 +0000 | [diff] [blame] | 2563 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2564 | netif_set_gso_max_size(netdev, 32768); |
| 2565 | else |
| 2566 | netif_set_gso_max_size(netdev, 65536); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2567 | ixgbe_configure_dcb(adapter); |
| 2568 | } else { |
| 2569 | netif_set_gso_max_size(netdev, 65536); |
| 2570 | } |
| 2571 | #else |
| 2572 | netif_set_gso_max_size(netdev, 65536); |
| 2573 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2574 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 2575 | #ifdef IXGBE_FCOE |
| 2576 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 2577 | ixgbe_configure_fcoe(adapter); |
| 2578 | |
| 2579 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2580 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 2581 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2582 | adapter->tx_ring[i].atr_sample_rate = |
| 2583 | adapter->atr_sample_rate; |
| 2584 | ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc); |
| 2585 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 2586 | ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc); |
| 2587 | } |
| 2588 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2589 | ixgbe_configure_tx(adapter); |
| 2590 | ixgbe_configure_rx(adapter); |
| 2591 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 2592 | ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i], |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2593 | (adapter->rx_ring[i].count - 1)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2594 | } |
| 2595 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2596 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 2597 | { |
| 2598 | switch (hw->phy.type) { |
| 2599 | case ixgbe_phy_sfp_avago: |
| 2600 | case ixgbe_phy_sfp_ftl: |
| 2601 | case ixgbe_phy_sfp_intel: |
| 2602 | case ixgbe_phy_sfp_unknown: |
| 2603 | case ixgbe_phy_tw_tyco: |
| 2604 | case ixgbe_phy_tw_unknown: |
| 2605 | return true; |
| 2606 | default: |
| 2607 | return false; |
| 2608 | } |
| 2609 | } |
| 2610 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2611 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2612 | * ixgbe_sfp_link_config - set up SFP+ link |
| 2613 | * @adapter: pointer to private adapter struct |
| 2614 | **/ |
| 2615 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 2616 | { |
| 2617 | struct ixgbe_hw *hw = &adapter->hw; |
| 2618 | |
| 2619 | if (hw->phy.multispeed_fiber) { |
| 2620 | /* |
| 2621 | * In multispeed fiber setups, the device may not have |
| 2622 | * had a physical connection when the driver loaded. |
| 2623 | * If that's the case, the initial link configuration |
| 2624 | * couldn't get the MAC into 10G or 1G mode, so we'll |
| 2625 | * never have a link status change interrupt fire. |
| 2626 | * We need to try and force an autonegotiation |
| 2627 | * session, then bring up link. |
| 2628 | */ |
| 2629 | hw->mac.ops.setup_sfp(hw); |
| 2630 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK)) |
| 2631 | schedule_work(&adapter->multispeed_fiber_task); |
| 2632 | } else { |
| 2633 | /* |
| 2634 | * Direct Attach Cu and non-multispeed fiber modules |
| 2635 | * still need to be configured properly prior to |
| 2636 | * attempting link. |
| 2637 | */ |
| 2638 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK)) |
| 2639 | schedule_work(&adapter->sfp_config_module_task); |
| 2640 | } |
| 2641 | } |
| 2642 | |
| 2643 | /** |
| 2644 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2645 | * @hw: pointer to private hardware struct |
| 2646 | * |
| 2647 | * Returns 0 on success, negative on failure |
| 2648 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2649 | 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] | 2650 | { |
| 2651 | u32 autoneg; |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 2652 | bool negotiation, link_up = false; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2653 | u32 ret = IXGBE_ERR_LINK_SETUP; |
| 2654 | |
| 2655 | if (hw->mac.ops.check_link) |
| 2656 | ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 2657 | |
| 2658 | if (ret) |
| 2659 | goto link_cfg_out; |
| 2660 | |
| 2661 | if (hw->mac.ops.get_link_capabilities) |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 2662 | ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2663 | if (ret) |
| 2664 | goto link_cfg_out; |
| 2665 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 2666 | if (hw->mac.ops.setup_link) |
| 2667 | 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] | 2668 | link_cfg_out: |
| 2669 | return ret; |
| 2670 | } |
| 2671 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2672 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 2673 | static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 2674 | int rxr) |
| 2675 | { |
| 2676 | int j = adapter->rx_ring[rxr].reg_idx; |
| 2677 | int k; |
| 2678 | |
| 2679 | for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) { |
| 2680 | if (IXGBE_READ_REG(&adapter->hw, |
| 2681 | IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE) |
| 2682 | break; |
| 2683 | else |
| 2684 | msleep(1); |
| 2685 | } |
| 2686 | if (k >= IXGBE_MAX_RX_DESC_POLL) { |
| 2687 | DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d " |
| 2688 | "not set within the polling period\n", rxr); |
| 2689 | } |
| 2690 | ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr], |
| 2691 | (adapter->rx_ring[rxr].count - 1)); |
| 2692 | } |
| 2693 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2694 | static int ixgbe_up_complete(struct ixgbe_adapter *adapter) |
| 2695 | { |
| 2696 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2697 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2698 | int i, j = 0; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2699 | int num_rx_rings = adapter->num_rx_queues; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2700 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2701 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2702 | u32 txdctl, rxdctl, mhadd; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2703 | u32 dmatxctl; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2704 | u32 gpie; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2705 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 2706 | ixgbe_get_hw_control(adapter); |
| 2707 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2708 | if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) || |
| 2709 | (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2710 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2711 | gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2712 | IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2713 | } else { |
| 2714 | /* MSI only */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2715 | gpie = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2716 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2717 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 2718 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 2719 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2720 | } |
| 2721 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 2722 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2723 | /* |
| 2724 | * use EIAM to auto-mask when MSI-X interrupt is asserted |
| 2725 | * this saves a register write for every interrupt |
| 2726 | */ |
| 2727 | switch (hw->mac.type) { |
| 2728 | case ixgbe_mac_82598EB: |
| 2729 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
| 2730 | break; |
| 2731 | default: |
| 2732 | case ixgbe_mac_82599EB: |
| 2733 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); |
| 2734 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); |
| 2735 | break; |
| 2736 | } |
| 2737 | } else { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2738 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 2739 | * specifically only auto mask tx and rx interrupts */ |
| 2740 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2741 | } |
| 2742 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2743 | /* Enable fan failure interrupt if media type is copper */ |
| 2744 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 2745 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 2746 | gpie |= IXGBE_SDP1_GPIEN; |
| 2747 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2748 | } |
| 2749 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2750 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2751 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 2752 | gpie |= IXGBE_SDP1_GPIEN; |
| 2753 | gpie |= IXGBE_SDP2_GPIEN; |
| 2754 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2755 | } |
| 2756 | |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2757 | #ifdef IXGBE_FCOE |
| 2758 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
Yi Zou | f34c5c8 | 2009-08-14 12:42:17 +0000 | [diff] [blame] | 2759 | if ((netdev->features & NETIF_F_FCOE_MTU) && |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2760 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 2761 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 2762 | |
| 2763 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2764 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2765 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 2766 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 2767 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 2768 | |
| 2769 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
| 2770 | } |
| 2771 | |
| 2772 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2773 | j = adapter->tx_ring[i].reg_idx; |
| 2774 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 2775 | /* enable WTHRESH=8 descriptors, to encourage burst writeback */ |
| 2776 | txdctl |= (8 << 16); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2777 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
| 2778 | } |
| 2779 | |
| 2780 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2781 | /* DMATXCTL.EN must be set after all Tx queue config is done */ |
| 2782 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 2783 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 2784 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 2785 | } |
| 2786 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2787 | j = adapter->tx_ring[i].reg_idx; |
| 2788 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2789 | txdctl |= IXGBE_TXDCTL_ENABLE; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2790 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2791 | } |
| 2792 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2793 | for (i = 0; i < num_rx_rings; i++) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2794 | j = adapter->rx_ring[i].reg_idx; |
| 2795 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 2796 | /* enable PTHRESH=32 descriptors (half the internal cache) |
| 2797 | * and HTHRESH=0 descriptors (to minimize latency on fetch), |
| 2798 | * this also removes a pesky rx_no_buffer_count increment */ |
| 2799 | rxdctl |= 0x0020; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2800 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2801 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2802 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 2803 | ixgbe_rx_desc_queue_enable(adapter, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2804 | } |
| 2805 | /* enable all receives */ |
| 2806 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2807 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2808 | rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN); |
| 2809 | else |
| 2810 | rxdctl |= IXGBE_RXCTRL_RXEN; |
| 2811 | hw->mac.ops.enable_rx_dma(hw, rxdctl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2812 | |
| 2813 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 2814 | ixgbe_configure_msix(adapter); |
| 2815 | else |
| 2816 | ixgbe_configure_msi_and_legacy(adapter); |
| 2817 | |
| 2818 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2819 | ixgbe_napi_enable_all(adapter); |
| 2820 | |
| 2821 | /* clear any pending interrupts, may auto mask */ |
| 2822 | IXGBE_READ_REG(hw, IXGBE_EICR); |
| 2823 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2824 | ixgbe_irq_enable(adapter); |
| 2825 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2826 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 2827 | * If this adapter has a fan, check to see if we had a failure |
| 2828 | * before we enabled the interrupt. |
| 2829 | */ |
| 2830 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 2831 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 2832 | if (esdp & IXGBE_ESDP_SDP1) |
| 2833 | DPRINTK(DRV, CRIT, |
| 2834 | "Fan has stopped, replace the adapter\n"); |
| 2835 | } |
| 2836 | |
| 2837 | /* |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2838 | * For hot-pluggable SFP+ devices, a new SFP+ module may have |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2839 | * arrived before interrupts were enabled but after probe. Such |
| 2840 | * devices wouldn't have their type identified yet. We need to |
| 2841 | * 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] | 2842 | * If we're not hot-pluggable SFP+, we just need to configure link |
| 2843 | * and bring it up. |
| 2844 | */ |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2845 | if (hw->phy.type == ixgbe_phy_unknown) { |
| 2846 | err = hw->phy.ops.identify(hw); |
| 2847 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 5da43c1 | 2009-07-02 12:50:52 +0000 | [diff] [blame] | 2848 | /* |
| 2849 | * Take the device down and schedule the sfp tasklet |
| 2850 | * which will unregister_netdev and log it. |
| 2851 | */ |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2852 | ixgbe_down(adapter); |
Don Skidmore | 5da43c1 | 2009-07-02 12:50:52 +0000 | [diff] [blame] | 2853 | schedule_work(&adapter->sfp_config_module_task); |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2854 | return err; |
| 2855 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2856 | } |
| 2857 | |
| 2858 | if (ixgbe_is_sfp(hw)) { |
| 2859 | ixgbe_sfp_link_config(adapter); |
| 2860 | } else { |
| 2861 | err = ixgbe_non_sfp_link_config(hw); |
| 2862 | if (err) |
| 2863 | DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err); |
| 2864 | } |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2865 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2866 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2867 | set_bit(__IXGBE_FDIR_INIT_DONE, |
| 2868 | &(adapter->tx_ring[i].reinit_state)); |
| 2869 | |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 2870 | /* enable transmits */ |
| 2871 | netif_tx_start_all_queues(netdev); |
| 2872 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2873 | /* bring the link up in the watchdog, this could race with our first |
| 2874 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2875 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2876 | adapter->link_check_timeout = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2877 | mod_timer(&adapter->watchdog_timer, jiffies); |
| 2878 | return 0; |
| 2879 | } |
| 2880 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2881 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 2882 | { |
| 2883 | WARN_ON(in_interrupt()); |
| 2884 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
| 2885 | msleep(1); |
| 2886 | ixgbe_down(adapter); |
| 2887 | ixgbe_up(adapter); |
| 2888 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 2889 | } |
| 2890 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2891 | int ixgbe_up(struct ixgbe_adapter *adapter) |
| 2892 | { |
| 2893 | /* hardware has been reset, we need to reload some things */ |
| 2894 | ixgbe_configure(adapter); |
| 2895 | |
| 2896 | return ixgbe_up_complete(adapter); |
| 2897 | } |
| 2898 | |
| 2899 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 2900 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2901 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 2902 | int err; |
| 2903 | |
| 2904 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2905 | switch (err) { |
| 2906 | case 0: |
| 2907 | case IXGBE_ERR_SFP_NOT_PRESENT: |
| 2908 | break; |
| 2909 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
| 2910 | dev_err(&adapter->pdev->dev, "master disable timed out\n"); |
| 2911 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 2912 | case IXGBE_ERR_EEPROM_VERSION: |
| 2913 | /* We are running on a pre-production device, log a warning */ |
| 2914 | dev_warn(&adapter->pdev->dev, "This device is a pre-production " |
| 2915 | "adapter/LOM. Please be aware there may be issues " |
| 2916 | "associated with your hardware. If you are " |
| 2917 | "experiencing problems please contact your Intel or " |
| 2918 | "hardware representative who provided you with this " |
| 2919 | "hardware.\n"); |
| 2920 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2921 | default: |
| 2922 | dev_err(&adapter->pdev->dev, "Hardware Error: %d\n", err); |
| 2923 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2924 | |
| 2925 | /* reprogram the RAR[0] in case user changed it. */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2926 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2927 | } |
| 2928 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2929 | /** |
| 2930 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
| 2931 | * @adapter: board private structure |
| 2932 | * @rx_ring: ring to free buffers from |
| 2933 | **/ |
| 2934 | static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2935 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2936 | { |
| 2937 | struct pci_dev *pdev = adapter->pdev; |
| 2938 | unsigned long size; |
| 2939 | unsigned int i; |
| 2940 | |
| 2941 | /* Free all the Rx ring sk_buffs */ |
| 2942 | |
| 2943 | for (i = 0; i < rx_ring->count; i++) { |
| 2944 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 2945 | |
| 2946 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
| 2947 | if (rx_buffer_info->dma) { |
| 2948 | pci_unmap_single(pdev, rx_buffer_info->dma, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2949 | rx_ring->rx_buf_len, |
| 2950 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2951 | rx_buffer_info->dma = 0; |
| 2952 | } |
| 2953 | if (rx_buffer_info->skb) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2954 | struct sk_buff *skb = rx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2955 | rx_buffer_info->skb = NULL; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2956 | do { |
| 2957 | struct sk_buff *this = skb; |
| 2958 | skb = skb->prev; |
| 2959 | dev_kfree_skb(this); |
| 2960 | } while (skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2961 | } |
| 2962 | if (!rx_buffer_info->page) |
| 2963 | continue; |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 2964 | if (rx_buffer_info->page_dma) { |
| 2965 | pci_unmap_page(pdev, rx_buffer_info->page_dma, |
| 2966 | PAGE_SIZE / 2, PCI_DMA_FROMDEVICE); |
| 2967 | rx_buffer_info->page_dma = 0; |
| 2968 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2969 | put_page(rx_buffer_info->page); |
| 2970 | rx_buffer_info->page = NULL; |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 2971 | rx_buffer_info->page_offset = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2972 | } |
| 2973 | |
| 2974 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 2975 | memset(rx_ring->rx_buffer_info, 0, size); |
| 2976 | |
| 2977 | /* Zero out the descriptor ring */ |
| 2978 | memset(rx_ring->desc, 0, rx_ring->size); |
| 2979 | |
| 2980 | rx_ring->next_to_clean = 0; |
| 2981 | rx_ring->next_to_use = 0; |
| 2982 | |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 2983 | if (rx_ring->head) |
| 2984 | writel(0, adapter->hw.hw_addr + rx_ring->head); |
| 2985 | if (rx_ring->tail) |
| 2986 | writel(0, adapter->hw.hw_addr + rx_ring->tail); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2987 | } |
| 2988 | |
| 2989 | /** |
| 2990 | * ixgbe_clean_tx_ring - Free Tx Buffers |
| 2991 | * @adapter: board private structure |
| 2992 | * @tx_ring: ring to be cleaned |
| 2993 | **/ |
| 2994 | static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2995 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2996 | { |
| 2997 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 2998 | unsigned long size; |
| 2999 | unsigned int i; |
| 3000 | |
| 3001 | /* Free all the Tx ring sk_buffs */ |
| 3002 | |
| 3003 | for (i = 0; i < tx_ring->count; i++) { |
| 3004 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 3005 | ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info); |
| 3006 | } |
| 3007 | |
| 3008 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 3009 | memset(tx_ring->tx_buffer_info, 0, size); |
| 3010 | |
| 3011 | /* Zero out the descriptor ring */ |
| 3012 | memset(tx_ring->desc, 0, tx_ring->size); |
| 3013 | |
| 3014 | tx_ring->next_to_use = 0; |
| 3015 | tx_ring->next_to_clean = 0; |
| 3016 | |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 3017 | if (tx_ring->head) |
| 3018 | writel(0, adapter->hw.hw_addr + tx_ring->head); |
| 3019 | if (tx_ring->tail) |
| 3020 | writel(0, adapter->hw.hw_addr + tx_ring->tail); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3021 | } |
| 3022 | |
| 3023 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3024 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 3025 | * @adapter: board private structure |
| 3026 | **/ |
| 3027 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 3028 | { |
| 3029 | int i; |
| 3030 | |
| 3031 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3032 | ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]); |
| 3033 | } |
| 3034 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3035 | /** |
| 3036 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 3037 | * @adapter: board private structure |
| 3038 | **/ |
| 3039 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 3040 | { |
| 3041 | int i; |
| 3042 | |
| 3043 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3044 | ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]); |
| 3045 | } |
| 3046 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3047 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 3048 | { |
| 3049 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3050 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3051 | u32 rxctrl; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3052 | u32 txdctl; |
| 3053 | int i, j; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3054 | |
| 3055 | /* signal that we are down to the interrupt handler */ |
| 3056 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 3057 | |
| 3058 | /* disable receives */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3059 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 3060 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3061 | |
| 3062 | netif_tx_disable(netdev); |
| 3063 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3064 | IXGBE_WRITE_FLUSH(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3065 | msleep(10); |
| 3066 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3067 | netif_tx_stop_all_queues(netdev); |
| 3068 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3069 | ixgbe_irq_disable(adapter); |
| 3070 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3071 | ixgbe_napi_disable_all(adapter); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3072 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 3073 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 3074 | del_timer_sync(&adapter->sfp_timer); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3075 | del_timer_sync(&adapter->watchdog_timer); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3076 | cancel_work_sync(&adapter->watchdog_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3077 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3078 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 3079 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 3080 | cancel_work_sync(&adapter->fdir_reinit_task); |
| 3081 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3082 | /* disable transmits in the hardware now that interrupts are off */ |
| 3083 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 3084 | j = adapter->tx_ring[i].reg_idx; |
| 3085 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
| 3086 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), |
| 3087 | (txdctl & ~IXGBE_TXDCTL_ENABLE)); |
| 3088 | } |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 3089 | /* Disable the Tx DMA engine on 82599 */ |
| 3090 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 3091 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
| 3092 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 3093 | ~IXGBE_DMATXCTL_TE)); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3094 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3095 | netif_carrier_off(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3096 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 3097 | if (!pci_channel_offline(adapter->pdev)) |
| 3098 | ixgbe_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3099 | ixgbe_clean_all_tx_rings(adapter); |
| 3100 | ixgbe_clean_all_rx_rings(adapter); |
| 3101 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 3102 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 3103 | /* since we reset the hardware DCA settings were cleared */ |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 3104 | ixgbe_setup_dca(adapter); |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 3105 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3106 | } |
| 3107 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3108 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3109 | * ixgbe_poll - NAPI Rx polling callback |
| 3110 | * @napi: structure for representing this polling device |
| 3111 | * @budget: how many packets driver is allowed to clean |
| 3112 | * |
| 3113 | * This function is used for legacy and MSI, NAPI mode |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3114 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3115 | static int ixgbe_poll(struct napi_struct *napi, int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3116 | { |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 3117 | struct ixgbe_q_vector *q_vector = |
| 3118 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3119 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 3120 | int tx_clean_complete, work_done = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3121 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 3122 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 3123 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 3124 | ixgbe_update_tx_dca(adapter, adapter->tx_ring); |
| 3125 | ixgbe_update_rx_dca(adapter, adapter->rx_ring); |
| 3126 | } |
| 3127 | #endif |
| 3128 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 3129 | tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring); |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 3130 | ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3131 | |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 3132 | if (!tx_clean_complete) |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 3133 | work_done = budget; |
| 3134 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 3135 | /* If budget not fully consumed, exit the polling mode */ |
| 3136 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3137 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 3138 | if (adapter->rx_itr_setting & 1) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 3139 | ixgbe_set_itr(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3140 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 3141 | ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3142 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3143 | return work_done; |
| 3144 | } |
| 3145 | |
| 3146 | /** |
| 3147 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 3148 | * @netdev: network interface device structure |
| 3149 | **/ |
| 3150 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 3151 | { |
| 3152 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3153 | |
| 3154 | /* Do the reset outside of interrupt context */ |
| 3155 | schedule_work(&adapter->reset_task); |
| 3156 | } |
| 3157 | |
| 3158 | static void ixgbe_reset_task(struct work_struct *work) |
| 3159 | { |
| 3160 | struct ixgbe_adapter *adapter; |
| 3161 | adapter = container_of(work, struct ixgbe_adapter, reset_task); |
| 3162 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3163 | /* If we're already down or resetting, just bail */ |
| 3164 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 3165 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 3166 | return; |
| 3167 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3168 | adapter->tx_timeout_count++; |
| 3169 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3170 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3171 | } |
| 3172 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3173 | #ifdef CONFIG_IXGBE_DCB |
| 3174 | static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3175 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3176 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3177 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB]; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3178 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3179 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) |
| 3180 | return ret; |
| 3181 | |
| 3182 | f->mask = 0x7 << 3; |
| 3183 | adapter->num_rx_queues = f->indices; |
| 3184 | adapter->num_tx_queues = f->indices; |
| 3185 | ret = true; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3186 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3187 | return ret; |
| 3188 | } |
| 3189 | #endif |
| 3190 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3191 | /** |
| 3192 | * ixgbe_set_rss_queues: Allocate queues for RSS |
| 3193 | * @adapter: board private structure to initialize |
| 3194 | * |
| 3195 | * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try |
| 3196 | * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU. |
| 3197 | * |
| 3198 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3199 | static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter) |
| 3200 | { |
| 3201 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3202 | 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] | 3203 | |
| 3204 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3205 | f->mask = 0xF; |
| 3206 | adapter->num_rx_queues = f->indices; |
| 3207 | adapter->num_tx_queues = f->indices; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3208 | ret = true; |
| 3209 | } else { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3210 | ret = false; |
| 3211 | } |
| 3212 | |
| 3213 | return ret; |
| 3214 | } |
| 3215 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3216 | /** |
| 3217 | * ixgbe_set_fdir_queues: Allocate queues for Flow Director |
| 3218 | * @adapter: board private structure to initialize |
| 3219 | * |
| 3220 | * Flow Director is an advanced Rx filter, attempting to get Rx flows back |
| 3221 | * to the original CPU that initiated the Tx session. This runs in addition |
| 3222 | * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the |
| 3223 | * Rx load across CPUs using RSS. |
| 3224 | * |
| 3225 | **/ |
| 3226 | static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter) |
| 3227 | { |
| 3228 | bool ret = false; |
| 3229 | struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR]; |
| 3230 | |
| 3231 | f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices); |
| 3232 | f_fdir->mask = 0; |
| 3233 | |
| 3234 | /* Flow Director must have RSS enabled */ |
| 3235 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED && |
| 3236 | ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 3237 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) { |
| 3238 | adapter->num_tx_queues = f_fdir->indices; |
| 3239 | adapter->num_rx_queues = f_fdir->indices; |
| 3240 | ret = true; |
| 3241 | } else { |
| 3242 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3243 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 3244 | } |
| 3245 | return ret; |
| 3246 | } |
| 3247 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3248 | #ifdef IXGBE_FCOE |
| 3249 | /** |
| 3250 | * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE) |
| 3251 | * @adapter: board private structure to initialize |
| 3252 | * |
| 3253 | * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges. |
| 3254 | * The ring feature mask is not used as a mask for FCoE, as it can take any 8 |
| 3255 | * rx queues out of the max number of rx queues, instead, it is used as the |
| 3256 | * index of the first rx queue used by FCoE. |
| 3257 | * |
| 3258 | **/ |
| 3259 | static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter) |
| 3260 | { |
| 3261 | bool ret = false; |
| 3262 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 3263 | |
| 3264 | f->indices = min((int)num_online_cpus(), f->indices); |
| 3265 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3266 | adapter->num_rx_queues = 1; |
| 3267 | adapter->num_tx_queues = 1; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3268 | #ifdef CONFIG_IXGBE_DCB |
| 3269 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3270 | DPRINTK(PROBE, INFO, "FCoE enabled with DCB \n"); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3271 | ixgbe_set_dcb_queues(adapter); |
| 3272 | } |
| 3273 | #endif |
| 3274 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3275 | DPRINTK(PROBE, INFO, "FCoE enabled with RSS \n"); |
Yi Zou | 8faa2a7 | 2009-07-09 02:29:50 +0000 | [diff] [blame] | 3276 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 3277 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 3278 | ixgbe_set_fdir_queues(adapter); |
| 3279 | else |
| 3280 | ixgbe_set_rss_queues(adapter); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3281 | } |
| 3282 | /* adding FCoE rx rings to the end */ |
| 3283 | f->mask = adapter->num_rx_queues; |
| 3284 | adapter->num_rx_queues += f->indices; |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3285 | adapter->num_tx_queues += f->indices; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3286 | |
| 3287 | ret = true; |
| 3288 | } |
| 3289 | |
| 3290 | return ret; |
| 3291 | } |
| 3292 | |
| 3293 | #endif /* IXGBE_FCOE */ |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3294 | /* |
| 3295 | * ixgbe_set_num_queues: Allocate queues for device, feature dependant |
| 3296 | * @adapter: board private structure to initialize |
| 3297 | * |
| 3298 | * This is the top level queue allocation routine. The order here is very |
| 3299 | * important, starting with the "most" number of features turned on at once, |
| 3300 | * and ending with the smallest set of features. This way large combinations |
| 3301 | * can be allocated if they're turned on, and smaller combinations are the |
| 3302 | * fallthrough conditions. |
| 3303 | * |
| 3304 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3305 | static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter) |
| 3306 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3307 | #ifdef IXGBE_FCOE |
| 3308 | if (ixgbe_set_fcoe_queues(adapter)) |
| 3309 | goto done; |
| 3310 | |
| 3311 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3312 | #ifdef CONFIG_IXGBE_DCB |
| 3313 | if (ixgbe_set_dcb_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 3314 | goto done; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3315 | |
| 3316 | #endif |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3317 | if (ixgbe_set_fdir_queues(adapter)) |
| 3318 | goto done; |
| 3319 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3320 | if (ixgbe_set_rss_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 3321 | goto done; |
| 3322 | |
| 3323 | /* fallback to base case */ |
| 3324 | adapter->num_rx_queues = 1; |
| 3325 | adapter->num_tx_queues = 1; |
| 3326 | |
| 3327 | done: |
| 3328 | /* Notify the stack of the (possibly) reduced Tx Queue count. */ |
| 3329 | adapter->netdev->real_num_tx_queues = adapter->num_tx_queues; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3330 | } |
| 3331 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3332 | static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3333 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3334 | { |
| 3335 | int err, vector_threshold; |
| 3336 | |
| 3337 | /* We'll want at least 3 (vector_threshold): |
| 3338 | * 1) TxQ[0] Cleanup |
| 3339 | * 2) RxQ[0] Cleanup |
| 3340 | * 3) Other (Link Status Change, etc.) |
| 3341 | * 4) TCP Timer (optional) |
| 3342 | */ |
| 3343 | vector_threshold = MIN_MSIX_COUNT; |
| 3344 | |
| 3345 | /* The more we get, the more we will assign to Tx/Rx Cleanup |
| 3346 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 3347 | * Right now, we simply care about how many we'll get; we'll |
| 3348 | * set them up later while requesting irq's. |
| 3349 | */ |
| 3350 | while (vectors >= vector_threshold) { |
| 3351 | err = pci_enable_msix(adapter->pdev, adapter->msix_entries, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3352 | vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3353 | if (!err) /* Success in acquiring all requested vectors. */ |
| 3354 | break; |
| 3355 | else if (err < 0) |
| 3356 | vectors = 0; /* Nasty failure, quit now */ |
| 3357 | else /* err == number of vectors we should try again with */ |
| 3358 | vectors = err; |
| 3359 | } |
| 3360 | |
| 3361 | if (vectors < vector_threshold) { |
| 3362 | /* Can't allocate enough MSI-X interrupts? Oh well. |
| 3363 | * This just means we'll go with either a single MSI |
| 3364 | * vector or fall back to legacy interrupts. |
| 3365 | */ |
| 3366 | DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n"); |
| 3367 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 3368 | kfree(adapter->msix_entries); |
| 3369 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3370 | } else { |
| 3371 | adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */ |
Peter P Waskiewicz Jr | eb7f139 | 2009-02-01 01:18:58 -0800 | [diff] [blame] | 3372 | /* |
| 3373 | * Adjust for only the vectors we'll use, which is minimum |
| 3374 | * of max_msix_q_vectors + NON_Q_VECTORS, or the number of |
| 3375 | * vectors we were allocated. |
| 3376 | */ |
| 3377 | adapter->num_msix_vectors = min(vectors, |
| 3378 | adapter->max_msix_q_vectors + NON_Q_VECTORS); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3379 | } |
| 3380 | } |
| 3381 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3382 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3383 | * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3384 | * @adapter: board private structure to initialize |
| 3385 | * |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3386 | * Cache the descriptor ring offsets for RSS to the assigned rings. |
| 3387 | * |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3388 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3389 | static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3390 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3391 | int i; |
| 3392 | bool ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3393 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3394 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 3395 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3396 | adapter->rx_ring[i].reg_idx = i; |
| 3397 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3398 | adapter->tx_ring[i].reg_idx = i; |
| 3399 | ret = true; |
| 3400 | } else { |
| 3401 | ret = false; |
| 3402 | } |
| 3403 | |
| 3404 | return ret; |
| 3405 | } |
| 3406 | |
| 3407 | #ifdef CONFIG_IXGBE_DCB |
| 3408 | /** |
| 3409 | * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB |
| 3410 | * @adapter: board private structure to initialize |
| 3411 | * |
| 3412 | * Cache the descriptor ring offsets for DCB to the assigned rings. |
| 3413 | * |
| 3414 | **/ |
| 3415 | static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter) |
| 3416 | { |
| 3417 | int i; |
| 3418 | bool ret = false; |
| 3419 | int dcb_i = adapter->ring_feature[RING_F_DCB].indices; |
| 3420 | |
| 3421 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 3422 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3423 | /* the number of queues is assumed to be symmetric */ |
| 3424 | for (i = 0; i < dcb_i; i++) { |
| 3425 | adapter->rx_ring[i].reg_idx = i << 3; |
| 3426 | adapter->tx_ring[i].reg_idx = i << 2; |
| 3427 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3428 | ret = true; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3429 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | f92ef20 | 2009-04-16 15:00:20 +0000 | [diff] [blame] | 3430 | if (dcb_i == 8) { |
| 3431 | /* |
| 3432 | * Tx TC0 starts at: descriptor queue 0 |
| 3433 | * Tx TC1 starts at: descriptor queue 32 |
| 3434 | * Tx TC2 starts at: descriptor queue 64 |
| 3435 | * Tx TC3 starts at: descriptor queue 80 |
| 3436 | * Tx TC4 starts at: descriptor queue 96 |
| 3437 | * Tx TC5 starts at: descriptor queue 104 |
| 3438 | * Tx TC6 starts at: descriptor queue 112 |
| 3439 | * Tx TC7 starts at: descriptor queue 120 |
| 3440 | * |
| 3441 | * Rx TC0-TC7 are offset by 16 queues each |
| 3442 | */ |
| 3443 | for (i = 0; i < 3; i++) { |
| 3444 | adapter->tx_ring[i].reg_idx = i << 5; |
| 3445 | adapter->rx_ring[i].reg_idx = i << 4; |
| 3446 | } |
| 3447 | for ( ; i < 5; i++) { |
| 3448 | adapter->tx_ring[i].reg_idx = |
| 3449 | ((i + 2) << 4); |
| 3450 | adapter->rx_ring[i].reg_idx = i << 4; |
| 3451 | } |
| 3452 | for ( ; i < dcb_i; i++) { |
| 3453 | adapter->tx_ring[i].reg_idx = |
| 3454 | ((i + 8) << 3); |
| 3455 | adapter->rx_ring[i].reg_idx = i << 4; |
| 3456 | } |
| 3457 | |
| 3458 | ret = true; |
| 3459 | } else if (dcb_i == 4) { |
| 3460 | /* |
| 3461 | * Tx TC0 starts at: descriptor queue 0 |
| 3462 | * Tx TC1 starts at: descriptor queue 64 |
| 3463 | * Tx TC2 starts at: descriptor queue 96 |
| 3464 | * Tx TC3 starts at: descriptor queue 112 |
| 3465 | * |
| 3466 | * Rx TC0-TC3 are offset by 32 queues each |
| 3467 | */ |
| 3468 | adapter->tx_ring[0].reg_idx = 0; |
| 3469 | adapter->tx_ring[1].reg_idx = 64; |
| 3470 | adapter->tx_ring[2].reg_idx = 96; |
| 3471 | adapter->tx_ring[3].reg_idx = 112; |
| 3472 | for (i = 0 ; i < dcb_i; i++) |
| 3473 | adapter->rx_ring[i].reg_idx = i << 5; |
| 3474 | |
| 3475 | ret = true; |
| 3476 | } else { |
| 3477 | ret = false; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3478 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3479 | } else { |
| 3480 | ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3481 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3482 | } else { |
| 3483 | ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3484 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3485 | |
| 3486 | return ret; |
| 3487 | } |
| 3488 | #endif |
| 3489 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3490 | /** |
| 3491 | * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director |
| 3492 | * @adapter: board private structure to initialize |
| 3493 | * |
| 3494 | * Cache the descriptor ring offsets for Flow Director to the assigned rings. |
| 3495 | * |
| 3496 | **/ |
| 3497 | static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter) |
| 3498 | { |
| 3499 | int i; |
| 3500 | bool ret = false; |
| 3501 | |
| 3502 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED && |
| 3503 | ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 3504 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) { |
| 3505 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3506 | adapter->rx_ring[i].reg_idx = i; |
| 3507 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3508 | adapter->tx_ring[i].reg_idx = i; |
| 3509 | ret = true; |
| 3510 | } |
| 3511 | |
| 3512 | return ret; |
| 3513 | } |
| 3514 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3515 | #ifdef IXGBE_FCOE |
| 3516 | /** |
| 3517 | * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE |
| 3518 | * @adapter: board private structure to initialize |
| 3519 | * |
| 3520 | * Cache the descriptor ring offsets for FCoE mode to the assigned rings. |
| 3521 | * |
| 3522 | */ |
| 3523 | static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter) |
| 3524 | { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3525 | int i, fcoe_rx_i = 0, fcoe_tx_i = 0; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3526 | bool ret = false; |
| 3527 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 3528 | |
| 3529 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 3530 | #ifdef CONFIG_IXGBE_DCB |
| 3531 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3532 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
| 3533 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3534 | ixgbe_cache_ring_dcb(adapter); |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3535 | /* find out queues in TC for FCoE */ |
| 3536 | fcoe_rx_i = adapter->rx_ring[fcoe->tc].reg_idx + 1; |
| 3537 | fcoe_tx_i = adapter->tx_ring[fcoe->tc].reg_idx + 1; |
| 3538 | /* |
| 3539 | * In 82599, the number of Tx queues for each traffic |
| 3540 | * class for both 8-TC and 4-TC modes are: |
| 3541 | * TCs : TC0 TC1 TC2 TC3 TC4 TC5 TC6 TC7 |
| 3542 | * 8 TCs: 32 32 16 16 8 8 8 8 |
| 3543 | * 4 TCs: 64 64 32 32 |
| 3544 | * We have max 8 queues for FCoE, where 8 the is |
| 3545 | * FCoE redirection table size. If TC for FCoE is |
| 3546 | * less than or equal to TC3, we have enough queues |
| 3547 | * to add max of 8 queues for FCoE, so we start FCoE |
| 3548 | * tx descriptor from the next one, i.e., reg_idx + 1. |
| 3549 | * If TC for FCoE is above TC3, implying 8 TC mode, |
| 3550 | * and we need 8 for FCoE, we have to take all queues |
| 3551 | * in that traffic class for FCoE. |
| 3552 | */ |
| 3553 | if ((f->indices == IXGBE_FCRETA_SIZE) && (fcoe->tc > 3)) |
| 3554 | fcoe_tx_i--; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3555 | } |
| 3556 | #endif /* CONFIG_IXGBE_DCB */ |
| 3557 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Yi Zou | 8faa2a7 | 2009-07-09 02:29:50 +0000 | [diff] [blame] | 3558 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 3559 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 3560 | ixgbe_cache_ring_fdir(adapter); |
| 3561 | else |
| 3562 | ixgbe_cache_ring_rss(adapter); |
| 3563 | |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3564 | fcoe_rx_i = f->mask; |
| 3565 | fcoe_tx_i = f->mask; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3566 | } |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3567 | for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) { |
| 3568 | adapter->rx_ring[f->mask + i].reg_idx = fcoe_rx_i; |
| 3569 | adapter->tx_ring[f->mask + i].reg_idx = fcoe_tx_i; |
| 3570 | } |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3571 | ret = true; |
| 3572 | } |
| 3573 | return ret; |
| 3574 | } |
| 3575 | |
| 3576 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3577 | /** |
| 3578 | * ixgbe_cache_ring_register - Descriptor ring to register mapping |
| 3579 | * @adapter: board private structure to initialize |
| 3580 | * |
| 3581 | * Once we know the feature-set enabled for the device, we'll cache |
| 3582 | * the register offset the descriptor ring is assigned to. |
| 3583 | * |
| 3584 | * Note, the order the various feature calls is important. It must start with |
| 3585 | * the "most" features enabled at the same time, then trickle down to the |
| 3586 | * least amount of features turned on at once. |
| 3587 | **/ |
| 3588 | static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) |
| 3589 | { |
| 3590 | /* start with default case */ |
| 3591 | adapter->rx_ring[0].reg_idx = 0; |
| 3592 | adapter->tx_ring[0].reg_idx = 0; |
| 3593 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3594 | #ifdef IXGBE_FCOE |
| 3595 | if (ixgbe_cache_ring_fcoe(adapter)) |
| 3596 | return; |
| 3597 | |
| 3598 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3599 | #ifdef CONFIG_IXGBE_DCB |
| 3600 | if (ixgbe_cache_ring_dcb(adapter)) |
| 3601 | return; |
| 3602 | |
| 3603 | #endif |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3604 | if (ixgbe_cache_ring_fdir(adapter)) |
| 3605 | return; |
| 3606 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3607 | if (ixgbe_cache_ring_rss(adapter)) |
| 3608 | return; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3609 | } |
| 3610 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3611 | /** |
| 3612 | * ixgbe_alloc_queues - Allocate memory for all rings |
| 3613 | * @adapter: board private structure to initialize |
| 3614 | * |
| 3615 | * 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] | 3616 | * number of queues at compile-time. The polling_netdev array is |
| 3617 | * intended for Multiqueue, but should work fine with a single queue. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3618 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3619 | static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3620 | { |
| 3621 | int i; |
| 3622 | |
| 3623 | adapter->tx_ring = kcalloc(adapter->num_tx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3624 | sizeof(struct ixgbe_ring), GFP_KERNEL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3625 | if (!adapter->tx_ring) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3626 | goto err_tx_ring_allocation; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3627 | |
| 3628 | adapter->rx_ring = kcalloc(adapter->num_rx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3629 | sizeof(struct ixgbe_ring), GFP_KERNEL); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3630 | if (!adapter->rx_ring) |
| 3631 | goto err_rx_ring_allocation; |
| 3632 | |
| 3633 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3634 | adapter->tx_ring[i].count = adapter->tx_ring_count; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3635 | adapter->tx_ring[i].queue_index = i; |
| 3636 | } |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3637 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3638 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3639 | adapter->rx_ring[i].count = adapter->rx_ring_count; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3640 | adapter->rx_ring[i].queue_index = i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3641 | } |
| 3642 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3643 | ixgbe_cache_ring_register(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3644 | |
| 3645 | return 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3646 | |
| 3647 | err_rx_ring_allocation: |
| 3648 | kfree(adapter->tx_ring); |
| 3649 | err_tx_ring_allocation: |
| 3650 | return -ENOMEM; |
| 3651 | } |
| 3652 | |
| 3653 | /** |
| 3654 | * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported |
| 3655 | * @adapter: board private structure to initialize |
| 3656 | * |
| 3657 | * Attempt to configure the interrupts using the best available |
| 3658 | * capabilities of the hardware and the kernel. |
| 3659 | **/ |
Al Viro | feea6a5 | 2008-11-27 15:34:07 -0800 | [diff] [blame] | 3660 | static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3661 | { |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3662 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3663 | int err = 0; |
| 3664 | int vector, v_budget; |
| 3665 | |
| 3666 | /* |
| 3667 | * It's easy to be greedy for MSI-X vectors, but it really |
| 3668 | * doesn't do us much good if we have a lot more vectors |
| 3669 | * than CPU's. So let's be conservative and only ask for |
PJ Waskiewicz | 342bde1 | 2009-11-12 23:50:43 +0000 | [diff] [blame] | 3670 | * (roughly) the same number of vectors as there are CPU's. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3671 | */ |
| 3672 | v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues, |
PJ Waskiewicz | 342bde1 | 2009-11-12 23:50:43 +0000 | [diff] [blame] | 3673 | (int)num_online_cpus()) + NON_Q_VECTORS; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3674 | |
| 3675 | /* |
| 3676 | * At the same time, hardware can only support a maximum of |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3677 | * hw.mac->max_msix_vectors vectors. With features |
| 3678 | * such as RSS and VMDq, we can easily surpass the number of Rx and Tx |
| 3679 | * descriptor queues supported by our device. Thus, we cap it off in |
| 3680 | * those rare cases where the cpu count also exceeds our vector limit. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3681 | */ |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3682 | v_budget = min(v_budget, (int)hw->mac.max_msix_vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3683 | |
| 3684 | /* A failure in MSI-X entry allocation isn't fatal, but it does |
| 3685 | * mean we disable MSI-X capabilities of the adapter. */ |
| 3686 | adapter->msix_entries = kcalloc(v_budget, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3687 | sizeof(struct msix_entry), GFP_KERNEL); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3688 | if (adapter->msix_entries) { |
| 3689 | for (vector = 0; vector < v_budget; vector++) |
| 3690 | adapter->msix_entries[vector].entry = vector; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3691 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3692 | ixgbe_acquire_msix_vectors(adapter, v_budget); |
| 3693 | |
| 3694 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 3695 | goto out; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3696 | } |
| 3697 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3698 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 3699 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3700 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3701 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 3702 | adapter->atr_sample_rate = 0; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3703 | ixgbe_set_num_queues(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3704 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3705 | err = pci_enable_msi(adapter->pdev); |
| 3706 | if (!err) { |
| 3707 | adapter->flags |= IXGBE_FLAG_MSI_ENABLED; |
| 3708 | } else { |
| 3709 | DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3710 | "falling back to legacy. Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3711 | /* reset err */ |
| 3712 | err = 0; |
| 3713 | } |
| 3714 | |
| 3715 | out: |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3716 | return err; |
| 3717 | } |
| 3718 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3719 | /** |
| 3720 | * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors |
| 3721 | * @adapter: board private structure to initialize |
| 3722 | * |
| 3723 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 3724 | * return -ENOMEM. |
| 3725 | **/ |
| 3726 | static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter) |
| 3727 | { |
| 3728 | int q_idx, num_q_vectors; |
| 3729 | struct ixgbe_q_vector *q_vector; |
| 3730 | int napi_vectors; |
| 3731 | int (*poll)(struct napi_struct *, int); |
| 3732 | |
| 3733 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 3734 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3735 | napi_vectors = adapter->num_rx_queues; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3736 | poll = &ixgbe_clean_rxtx_many; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3737 | } else { |
| 3738 | num_q_vectors = 1; |
| 3739 | napi_vectors = 1; |
| 3740 | poll = &ixgbe_poll; |
| 3741 | } |
| 3742 | |
| 3743 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
| 3744 | q_vector = kzalloc(sizeof(struct ixgbe_q_vector), GFP_KERNEL); |
| 3745 | if (!q_vector) |
| 3746 | goto err_out; |
| 3747 | q_vector->adapter = adapter; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 3748 | if (q_vector->txr_count && !q_vector->rxr_count) |
| 3749 | q_vector->eitr = adapter->tx_eitr_param; |
| 3750 | else |
| 3751 | q_vector->eitr = adapter->rx_eitr_param; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 3752 | q_vector->v_idx = q_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3753 | netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3754 | adapter->q_vector[q_idx] = q_vector; |
| 3755 | } |
| 3756 | |
| 3757 | return 0; |
| 3758 | |
| 3759 | err_out: |
| 3760 | while (q_idx) { |
| 3761 | q_idx--; |
| 3762 | q_vector = adapter->q_vector[q_idx]; |
| 3763 | netif_napi_del(&q_vector->napi); |
| 3764 | kfree(q_vector); |
| 3765 | adapter->q_vector[q_idx] = NULL; |
| 3766 | } |
| 3767 | return -ENOMEM; |
| 3768 | } |
| 3769 | |
| 3770 | /** |
| 3771 | * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors |
| 3772 | * @adapter: board private structure to initialize |
| 3773 | * |
| 3774 | * This function frees the memory allocated to the q_vectors. In addition if |
| 3775 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 3776 | * to freeing the q_vector. |
| 3777 | **/ |
| 3778 | static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter) |
| 3779 | { |
| 3780 | int q_idx, num_q_vectors; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3781 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3782 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3783 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3784 | else |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3785 | num_q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3786 | |
| 3787 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
| 3788 | struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx]; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3789 | adapter->q_vector[q_idx] = NULL; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3790 | netif_napi_del(&q_vector->napi); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3791 | kfree(q_vector); |
| 3792 | } |
| 3793 | } |
| 3794 | |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 3795 | static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3796 | { |
| 3797 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 3798 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 3799 | pci_disable_msix(adapter->pdev); |
| 3800 | kfree(adapter->msix_entries); |
| 3801 | adapter->msix_entries = NULL; |
| 3802 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 3803 | adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED; |
| 3804 | pci_disable_msi(adapter->pdev); |
| 3805 | } |
| 3806 | return; |
| 3807 | } |
| 3808 | |
| 3809 | /** |
| 3810 | * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme |
| 3811 | * @adapter: board private structure to initialize |
| 3812 | * |
| 3813 | * We determine which interrupt scheme to use based on... |
| 3814 | * - Kernel support (MSI, MSI-X) |
| 3815 | * - which can be user-defined (via MODULE_PARAM) |
| 3816 | * - Hardware queue count (num_*_queues) |
| 3817 | * - defined by miscellaneous hardware support/features (RSS, etc.) |
| 3818 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3819 | int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3820 | { |
| 3821 | int err; |
| 3822 | |
| 3823 | /* Number of supported queues */ |
| 3824 | ixgbe_set_num_queues(adapter); |
| 3825 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3826 | err = ixgbe_set_interrupt_capability(adapter); |
| 3827 | if (err) { |
| 3828 | DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n"); |
| 3829 | goto err_set_interrupt; |
| 3830 | } |
| 3831 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3832 | err = ixgbe_alloc_q_vectors(adapter); |
| 3833 | if (err) { |
| 3834 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queue " |
| 3835 | "vectors\n"); |
| 3836 | goto err_alloc_q_vectors; |
| 3837 | } |
| 3838 | |
| 3839 | err = ixgbe_alloc_queues(adapter); |
| 3840 | if (err) { |
| 3841 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n"); |
| 3842 | goto err_alloc_queues; |
| 3843 | } |
| 3844 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3845 | DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3846 | "Tx Queue count = %u\n", |
| 3847 | (adapter->num_rx_queues > 1) ? "Enabled" : |
| 3848 | "Disabled", adapter->num_rx_queues, adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3849 | |
| 3850 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 3851 | |
| 3852 | return 0; |
| 3853 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3854 | err_alloc_queues: |
| 3855 | ixgbe_free_q_vectors(adapter); |
| 3856 | err_alloc_q_vectors: |
| 3857 | ixgbe_reset_interrupt_capability(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3858 | err_set_interrupt: |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3859 | return err; |
| 3860 | } |
| 3861 | |
| 3862 | /** |
| 3863 | * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 3864 | * @adapter: board private structure to clear interrupt scheme on |
| 3865 | * |
| 3866 | * We go through and clear interrupt specific resources and reset the structure |
| 3867 | * to pre-load conditions |
| 3868 | **/ |
| 3869 | void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter) |
| 3870 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3871 | kfree(adapter->tx_ring); |
| 3872 | kfree(adapter->rx_ring); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3873 | adapter->tx_ring = NULL; |
| 3874 | adapter->rx_ring = NULL; |
| 3875 | |
| 3876 | ixgbe_free_q_vectors(adapter); |
| 3877 | ixgbe_reset_interrupt_capability(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3878 | } |
| 3879 | |
| 3880 | /** |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3881 | * ixgbe_sfp_timer - worker thread to find a missing module |
| 3882 | * @data: pointer to our adapter struct |
| 3883 | **/ |
| 3884 | static void ixgbe_sfp_timer(unsigned long data) |
| 3885 | { |
| 3886 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 3887 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3888 | /* |
| 3889 | * Do the sfp_timer outside of interrupt context due to the |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3890 | * delays that sfp+ detection requires |
| 3891 | */ |
| 3892 | schedule_work(&adapter->sfp_task); |
| 3893 | } |
| 3894 | |
| 3895 | /** |
| 3896 | * ixgbe_sfp_task - worker thread to find a missing module |
| 3897 | * @work: pointer to work_struct containing our data |
| 3898 | **/ |
| 3899 | static void ixgbe_sfp_task(struct work_struct *work) |
| 3900 | { |
| 3901 | struct ixgbe_adapter *adapter = container_of(work, |
| 3902 | struct ixgbe_adapter, |
| 3903 | sfp_task); |
| 3904 | struct ixgbe_hw *hw = &adapter->hw; |
| 3905 | |
| 3906 | if ((hw->phy.type == ixgbe_phy_nl) && |
| 3907 | (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) { |
| 3908 | s32 ret = hw->phy.ops.identify_sfp(hw); |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 3909 | if (ret == IXGBE_ERR_SFP_NOT_PRESENT) |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3910 | goto reschedule; |
| 3911 | ret = hw->phy.ops.reset(hw); |
| 3912 | if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 88d2b81 | 2009-06-30 11:43:55 +0000 | [diff] [blame] | 3913 | dev_err(&adapter->pdev->dev, "failed to initialize " |
| 3914 | "because an unsupported SFP+ module type " |
| 3915 | "was detected.\n" |
| 3916 | "Reload the driver after installing a " |
| 3917 | "supported module.\n"); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3918 | unregister_netdev(adapter->netdev); |
| 3919 | } else { |
| 3920 | DPRINTK(PROBE, INFO, "detected SFP+: %d\n", |
| 3921 | hw->phy.sfp_type); |
| 3922 | } |
| 3923 | /* don't need this routine any more */ |
| 3924 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 3925 | } |
| 3926 | return; |
| 3927 | reschedule: |
| 3928 | if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state)) |
| 3929 | mod_timer(&adapter->sfp_timer, |
| 3930 | round_jiffies(jiffies + (2 * HZ))); |
| 3931 | } |
| 3932 | |
| 3933 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3934 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 3935 | * @adapter: board private structure to initialize |
| 3936 | * |
| 3937 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 3938 | * Fields are initialized based on PCI device information and |
| 3939 | * OS network device settings (MTU size). |
| 3940 | **/ |
| 3941 | static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter) |
| 3942 | { |
| 3943 | struct ixgbe_hw *hw = &adapter->hw; |
| 3944 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3945 | unsigned int rss; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3946 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3947 | int j; |
| 3948 | struct tc_configuration *tc; |
| 3949 | #endif |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3950 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3951 | /* PCI config space info */ |
| 3952 | |
| 3953 | hw->vendor_id = pdev->vendor; |
| 3954 | hw->device_id = pdev->device; |
| 3955 | hw->revision_id = pdev->revision; |
| 3956 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 3957 | hw->subsystem_device_id = pdev->subsystem_device; |
| 3958 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3959 | /* Set capability flags */ |
| 3960 | rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus()); |
| 3961 | adapter->ring_feature[RING_F_RSS].indices = rss; |
| 3962 | adapter->flags |= IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3963 | adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES; |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3964 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3965 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 3966 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3967 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598; |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3968 | } else if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3969 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 3970 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
| 3971 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3972 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3973 | adapter->ring_feature[RING_F_FDIR].indices = |
| 3974 | IXGBE_MAX_FDIR_INDICES; |
| 3975 | adapter->atr_sample_rate = 20; |
| 3976 | adapter->fdir_pballoc = 0; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 3977 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 3978 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 3979 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 3980 | adapter->ring_feature[RING_F_FCOE].indices = 0; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 3981 | #ifdef CONFIG_IXGBE_DCB |
Yi Zou | 6ee1652 | 2009-08-31 12:34:28 +0000 | [diff] [blame] | 3982 | /* Default traffic class to use for FCoE */ |
| 3983 | adapter->fcoe.tc = IXGBE_FCOE_DEFTC; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 3984 | #endif |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 3985 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3986 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3987 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3988 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3989 | /* Configure DCB traffic classes */ |
| 3990 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 3991 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 3992 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 3993 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 3994 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 3995 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 3996 | tc->dcb_pfc = pfc_disabled; |
| 3997 | } |
| 3998 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 3999 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
| 4000 | adapter->dcb_cfg.rx_pba_cfg = pba_equal; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4001 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4002 | adapter->dcb_cfg.round_robin_enable = false; |
| 4003 | adapter->dcb_set_bitmap = 0x00; |
| 4004 | ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg, |
| 4005 | adapter->ring_feature[RING_F_DCB].indices); |
| 4006 | |
| 4007 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4008 | |
| 4009 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 4010 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 4011 | 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] | 4012 | #ifdef CONFIG_DCB |
| 4013 | adapter->last_lfc_mode = hw->fc.current_mode; |
| 4014 | #endif |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 4015 | hw->fc.high_water = IXGBE_DEFAULT_FCRTH; |
| 4016 | hw->fc.low_water = IXGBE_DEFAULT_FCRTL; |
| 4017 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 4018 | hw->fc.send_xon = true; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 4019 | hw->fc.disable_fc_autoneg = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4020 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 4021 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 4022 | adapter->rx_itr_setting = 1; |
| 4023 | adapter->rx_eitr_param = 20000; |
| 4024 | adapter->tx_itr_setting = 1; |
| 4025 | adapter->tx_eitr_param = 10000; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 4026 | |
| 4027 | /* set defaults for eitr in MegaBytes */ |
| 4028 | adapter->eitr_low = 10; |
| 4029 | adapter->eitr_high = 20; |
| 4030 | |
| 4031 | /* set default ring sizes */ |
| 4032 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 4033 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 4034 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4035 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4036 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4037 | dev_err(&pdev->dev, "EEPROM initialization failed\n"); |
| 4038 | return -EIO; |
| 4039 | } |
| 4040 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4041 | /* enable rx csum by default */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4042 | adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED; |
| 4043 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4044 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 4045 | |
| 4046 | return 0; |
| 4047 | } |
| 4048 | |
| 4049 | /** |
| 4050 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
| 4051 | * @adapter: board private structure |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4052 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4053 | * |
| 4054 | * Return 0 on success, negative on failure |
| 4055 | **/ |
| 4056 | int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4057 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4058 | { |
| 4059 | struct pci_dev *pdev = adapter->pdev; |
| 4060 | int size; |
| 4061 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4062 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 4063 | tx_ring->tx_buffer_info = vmalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4064 | if (!tx_ring->tx_buffer_info) |
| 4065 | goto err; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4066 | memset(tx_ring->tx_buffer_info, 0, size); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4067 | |
| 4068 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 4069 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4070 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4071 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4072 | tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size, |
| 4073 | &tx_ring->dma); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4074 | if (!tx_ring->desc) |
| 4075 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4076 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4077 | tx_ring->next_to_use = 0; |
| 4078 | tx_ring->next_to_clean = 0; |
| 4079 | tx_ring->work_limit = tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4080 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4081 | |
| 4082 | err: |
| 4083 | vfree(tx_ring->tx_buffer_info); |
| 4084 | tx_ring->tx_buffer_info = NULL; |
| 4085 | DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit " |
| 4086 | "descriptor ring\n"); |
| 4087 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4088 | } |
| 4089 | |
| 4090 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4091 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 4092 | * @adapter: board private structure |
| 4093 | * |
| 4094 | * If this function returns with an error, then it's possible one or |
| 4095 | * more of the rings is populated (while the rest are not). It is the |
| 4096 | * callers duty to clean those orphaned rings. |
| 4097 | * |
| 4098 | * Return 0 on success, negative on failure |
| 4099 | **/ |
| 4100 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 4101 | { |
| 4102 | int i, err = 0; |
| 4103 | |
| 4104 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 4105 | err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]); |
| 4106 | if (!err) |
| 4107 | continue; |
| 4108 | DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i); |
| 4109 | break; |
| 4110 | } |
| 4111 | |
| 4112 | return err; |
| 4113 | } |
| 4114 | |
| 4115 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4116 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
| 4117 | * @adapter: board private structure |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4118 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4119 | * |
| 4120 | * Returns 0 on success, negative on failure |
| 4121 | **/ |
| 4122 | int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4123 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4124 | { |
| 4125 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4126 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4127 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4128 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 4129 | rx_ring->rx_buffer_info = vmalloc(size); |
| 4130 | if (!rx_ring->rx_buffer_info) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4131 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4132 | "vmalloc allocation failed for the rx desc ring\n"); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4133 | goto alloc_failed; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4134 | } |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4135 | memset(rx_ring->rx_buffer_info, 0, size); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4136 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4137 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4138 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 4139 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4140 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4141 | 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] | 4142 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4143 | if (!rx_ring->desc) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4144 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4145 | "Memory allocation failed for the rx desc ring\n"); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4146 | vfree(rx_ring->rx_buffer_info); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4147 | goto alloc_failed; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4148 | } |
| 4149 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4150 | rx_ring->next_to_clean = 0; |
| 4151 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4152 | |
| 4153 | return 0; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4154 | |
| 4155 | alloc_failed: |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4156 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4157 | } |
| 4158 | |
| 4159 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4160 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 4161 | * @adapter: board private structure |
| 4162 | * |
| 4163 | * If this function returns with an error, then it's possible one or |
| 4164 | * more of the rings is populated (while the rest are not). It is the |
| 4165 | * callers duty to clean those orphaned rings. |
| 4166 | * |
| 4167 | * Return 0 on success, negative on failure |
| 4168 | **/ |
| 4169 | |
| 4170 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 4171 | { |
| 4172 | int i, err = 0; |
| 4173 | |
| 4174 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 4175 | err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]); |
| 4176 | if (!err) |
| 4177 | continue; |
| 4178 | DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i); |
| 4179 | break; |
| 4180 | } |
| 4181 | |
| 4182 | return err; |
| 4183 | } |
| 4184 | |
| 4185 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4186 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
| 4187 | * @adapter: board private structure |
| 4188 | * @tx_ring: Tx descriptor ring for a specific queue |
| 4189 | * |
| 4190 | * Free all transmit software resources |
| 4191 | **/ |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 4192 | void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter, |
| 4193 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4194 | { |
| 4195 | struct pci_dev *pdev = adapter->pdev; |
| 4196 | |
| 4197 | ixgbe_clean_tx_ring(adapter, tx_ring); |
| 4198 | |
| 4199 | vfree(tx_ring->tx_buffer_info); |
| 4200 | tx_ring->tx_buffer_info = NULL; |
| 4201 | |
| 4202 | pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); |
| 4203 | |
| 4204 | tx_ring->desc = NULL; |
| 4205 | } |
| 4206 | |
| 4207 | /** |
| 4208 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 4209 | * @adapter: board private structure |
| 4210 | * |
| 4211 | * Free all transmit software resources |
| 4212 | **/ |
| 4213 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 4214 | { |
| 4215 | int i; |
| 4216 | |
| 4217 | for (i = 0; i < adapter->num_tx_queues; i++) |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 4218 | if (adapter->tx_ring[i].desc) |
| 4219 | ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4220 | } |
| 4221 | |
| 4222 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4223 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4224 | * @adapter: board private structure |
| 4225 | * @rx_ring: ring to clean the resources from |
| 4226 | * |
| 4227 | * Free all receive software resources |
| 4228 | **/ |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 4229 | void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter, |
| 4230 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4231 | { |
| 4232 | struct pci_dev *pdev = adapter->pdev; |
| 4233 | |
| 4234 | ixgbe_clean_rx_ring(adapter, rx_ring); |
| 4235 | |
| 4236 | vfree(rx_ring->rx_buffer_info); |
| 4237 | rx_ring->rx_buffer_info = NULL; |
| 4238 | |
| 4239 | pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); |
| 4240 | |
| 4241 | rx_ring->desc = NULL; |
| 4242 | } |
| 4243 | |
| 4244 | /** |
| 4245 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 4246 | * @adapter: board private structure |
| 4247 | * |
| 4248 | * Free all receive software resources |
| 4249 | **/ |
| 4250 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 4251 | { |
| 4252 | int i; |
| 4253 | |
| 4254 | for (i = 0; i < adapter->num_rx_queues; i++) |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 4255 | if (adapter->rx_ring[i].desc) |
| 4256 | ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4257 | } |
| 4258 | |
| 4259 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4260 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 4261 | * @netdev: network interface device structure |
| 4262 | * @new_mtu: new value for maximum frame size |
| 4263 | * |
| 4264 | * Returns 0 on success, negative on failure |
| 4265 | **/ |
| 4266 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 4267 | { |
| 4268 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4269 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 4270 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 4271 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 4272 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4273 | return -EINVAL; |
| 4274 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4275 | DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n", |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4276 | netdev->mtu, new_mtu); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4277 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4278 | netdev->mtu = new_mtu; |
| 4279 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4280 | if (netif_running(netdev)) |
| 4281 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4282 | |
| 4283 | return 0; |
| 4284 | } |
| 4285 | |
| 4286 | /** |
| 4287 | * ixgbe_open - Called when a network interface is made active |
| 4288 | * @netdev: network interface device structure |
| 4289 | * |
| 4290 | * Returns 0 on success, negative value on failure |
| 4291 | * |
| 4292 | * The open entry point is called when a network interface is made |
| 4293 | * active by the system (IFF_UP). At this point all resources needed |
| 4294 | * for transmit and receive operations are allocated, the interrupt |
| 4295 | * handler is registered with the OS, the watchdog timer is started, |
| 4296 | * and the stack is notified that the interface is ready. |
| 4297 | **/ |
| 4298 | static int ixgbe_open(struct net_device *netdev) |
| 4299 | { |
| 4300 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4301 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4302 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 4303 | /* disallow open during test */ |
| 4304 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 4305 | return -EBUSY; |
| 4306 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 4307 | netif_carrier_off(netdev); |
| 4308 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4309 | /* allocate transmit descriptors */ |
| 4310 | err = ixgbe_setup_all_tx_resources(adapter); |
| 4311 | if (err) |
| 4312 | goto err_setup_tx; |
| 4313 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4314 | /* allocate receive descriptors */ |
| 4315 | err = ixgbe_setup_all_rx_resources(adapter); |
| 4316 | if (err) |
| 4317 | goto err_setup_rx; |
| 4318 | |
| 4319 | ixgbe_configure(adapter); |
| 4320 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4321 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4322 | if (err) |
| 4323 | goto err_req_irq; |
| 4324 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4325 | err = ixgbe_up_complete(adapter); |
| 4326 | if (err) |
| 4327 | goto err_up; |
| 4328 | |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 4329 | netif_tx_start_all_queues(netdev); |
| 4330 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4331 | return 0; |
| 4332 | |
| 4333 | err_up: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 4334 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4335 | ixgbe_free_irq(adapter); |
| 4336 | err_req_irq: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4337 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 4338 | ixgbe_free_all_rx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4339 | err_setup_tx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 4340 | ixgbe_free_all_tx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4341 | ixgbe_reset(adapter); |
| 4342 | |
| 4343 | return err; |
| 4344 | } |
| 4345 | |
| 4346 | /** |
| 4347 | * ixgbe_close - Disables a network interface |
| 4348 | * @netdev: network interface device structure |
| 4349 | * |
| 4350 | * Returns 0, this is not allowed to fail |
| 4351 | * |
| 4352 | * The close entry point is called when an interface is de-activated |
| 4353 | * by the OS. The hardware is still under the drivers control, but |
| 4354 | * needs to be disabled. A global MAC reset is issued to stop the |
| 4355 | * hardware, and all transmit and receive resources are freed. |
| 4356 | **/ |
| 4357 | static int ixgbe_close(struct net_device *netdev) |
| 4358 | { |
| 4359 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4360 | |
| 4361 | ixgbe_down(adapter); |
| 4362 | ixgbe_free_irq(adapter); |
| 4363 | |
| 4364 | ixgbe_free_all_tx_resources(adapter); |
| 4365 | ixgbe_free_all_rx_resources(adapter); |
| 4366 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 4367 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4368 | |
| 4369 | return 0; |
| 4370 | } |
| 4371 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4372 | #ifdef CONFIG_PM |
| 4373 | static int ixgbe_resume(struct pci_dev *pdev) |
| 4374 | { |
| 4375 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4376 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4377 | u32 err; |
| 4378 | |
| 4379 | pci_set_power_state(pdev, PCI_D0); |
| 4380 | pci_restore_state(pdev); |
Don Skidmore | 656ab81 | 2009-12-23 21:19:19 -0800 | [diff] [blame] | 4381 | /* |
| 4382 | * pci_restore_state clears dev->state_saved so call |
| 4383 | * pci_save_state to restore it. |
| 4384 | */ |
| 4385 | pci_save_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 4386 | |
| 4387 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4388 | if (err) { |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4389 | printk(KERN_ERR "ixgbe: Cannot enable PCI device from " |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4390 | "suspend\n"); |
| 4391 | return err; |
| 4392 | } |
| 4393 | pci_set_master(pdev); |
| 4394 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 4395 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4396 | |
| 4397 | err = ixgbe_init_interrupt_scheme(adapter); |
| 4398 | if (err) { |
| 4399 | printk(KERN_ERR "ixgbe: Cannot initialize interrupts for " |
| 4400 | "device\n"); |
| 4401 | return err; |
| 4402 | } |
| 4403 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4404 | ixgbe_reset(adapter); |
| 4405 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 4406 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 4407 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4408 | if (netif_running(netdev)) { |
| 4409 | err = ixgbe_open(adapter->netdev); |
| 4410 | if (err) |
| 4411 | return err; |
| 4412 | } |
| 4413 | |
| 4414 | netif_device_attach(netdev); |
| 4415 | |
| 4416 | return 0; |
| 4417 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4418 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4419 | |
| 4420 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4421 | { |
| 4422 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4423 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4424 | struct ixgbe_hw *hw = &adapter->hw; |
| 4425 | u32 ctrl, fctrl; |
| 4426 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4427 | #ifdef CONFIG_PM |
| 4428 | int retval = 0; |
| 4429 | #endif |
| 4430 | |
| 4431 | netif_device_detach(netdev); |
| 4432 | |
| 4433 | if (netif_running(netdev)) { |
| 4434 | ixgbe_down(adapter); |
| 4435 | ixgbe_free_irq(adapter); |
| 4436 | ixgbe_free_all_tx_resources(adapter); |
| 4437 | ixgbe_free_all_rx_resources(adapter); |
| 4438 | } |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4439 | ixgbe_clear_interrupt_scheme(adapter); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4440 | |
| 4441 | #ifdef CONFIG_PM |
| 4442 | retval = pci_save_state(pdev); |
| 4443 | if (retval) |
| 4444 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4445 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4446 | #endif |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4447 | if (wufc) { |
| 4448 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4449 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4450 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 4451 | if (wufc & IXGBE_WUFC_MC) { |
| 4452 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 4453 | fctrl |= IXGBE_FCTRL_MPE; |
| 4454 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 4455 | } |
| 4456 | |
| 4457 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 4458 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 4459 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 4460 | |
| 4461 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 4462 | } else { |
| 4463 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 4464 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 4465 | } |
| 4466 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 4467 | if (wufc && hw->mac.type == ixgbe_mac_82599EB) |
| 4468 | pci_wake_from_d3(pdev, true); |
| 4469 | else |
| 4470 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4471 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4472 | *enable_wake = !!wufc; |
| 4473 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4474 | ixgbe_release_hw_control(adapter); |
| 4475 | |
| 4476 | pci_disable_device(pdev); |
| 4477 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4478 | return 0; |
| 4479 | } |
| 4480 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4481 | #ifdef CONFIG_PM |
| 4482 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 4483 | { |
| 4484 | int retval; |
| 4485 | bool wake; |
| 4486 | |
| 4487 | retval = __ixgbe_shutdown(pdev, &wake); |
| 4488 | if (retval) |
| 4489 | return retval; |
| 4490 | |
| 4491 | if (wake) { |
| 4492 | pci_prepare_to_sleep(pdev); |
| 4493 | } else { |
| 4494 | pci_wake_from_d3(pdev, false); |
| 4495 | pci_set_power_state(pdev, PCI_D3hot); |
| 4496 | } |
| 4497 | |
| 4498 | return 0; |
| 4499 | } |
| 4500 | #endif /* CONFIG_PM */ |
| 4501 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4502 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 4503 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4504 | bool wake; |
| 4505 | |
| 4506 | __ixgbe_shutdown(pdev, &wake); |
| 4507 | |
| 4508 | if (system_state == SYSTEM_POWER_OFF) { |
| 4509 | pci_wake_from_d3(pdev, wake); |
| 4510 | pci_set_power_state(pdev, PCI_D3hot); |
| 4511 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4512 | } |
| 4513 | |
| 4514 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4515 | * ixgbe_update_stats - Update the board statistics counters. |
| 4516 | * @adapter: board private structure |
| 4517 | **/ |
| 4518 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 4519 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4520 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4521 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4522 | u64 total_mpc = 0; |
| 4523 | 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] | 4524 | u64 non_eop_descs = 0, restart_queue = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4525 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 4526 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 4527 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 4528 | u64 rsc_flush = 0; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 4529 | for (i = 0; i < 16; i++) |
| 4530 | adapter->hw_rx_no_dma_resources += |
| 4531 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 4532 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 4533 | rsc_count += adapter->rx_ring[i].rsc_count; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 4534 | rsc_flush += adapter->rx_ring[i].rsc_flush; |
| 4535 | } |
| 4536 | adapter->rsc_total_count = rsc_count; |
| 4537 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 4538 | } |
| 4539 | |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 4540 | /* gather some stats to the adapter struct that are per queue */ |
| 4541 | for (i = 0; i < adapter->num_tx_queues; i++) |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 4542 | restart_queue += adapter->tx_ring[i].restart_queue; |
| 4543 | adapter->restart_queue = restart_queue; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 4544 | |
| 4545 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | eb985f0 | 2009-12-15 11:56:59 +0000 | [diff] [blame] | 4546 | non_eop_descs += adapter->rx_ring[i].non_eop_descs; |
| 4547 | adapter->non_eop_descs = non_eop_descs; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 4548 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4549 | adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4550 | for (i = 0; i < 8; i++) { |
| 4551 | /* for packet buffers not used, the register should read 0 */ |
| 4552 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 4553 | missed_rx += mpc; |
| 4554 | adapter->stats.mpc[i] += mpc; |
| 4555 | total_mpc += adapter->stats.mpc[i]; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4556 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4557 | adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4558 | adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 4559 | adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 4560 | adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 4561 | adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4562 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 4563 | adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw, |
| 4564 | IXGBE_PXONRXCNT(i)); |
| 4565 | adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw, |
| 4566 | IXGBE_PXOFFRXCNT(i)); |
| 4567 | adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4568 | } else { |
| 4569 | adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw, |
| 4570 | IXGBE_PXONRXC(i)); |
| 4571 | adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw, |
| 4572 | IXGBE_PXOFFRXC(i)); |
| 4573 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4574 | adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw, |
| 4575 | IXGBE_PXONTXC(i)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4576 | adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4577 | IXGBE_PXOFFTXC(i)); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4578 | } |
| 4579 | adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
| 4580 | /* work around hardware counting issue */ |
| 4581 | adapter->stats.gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4582 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4583 | /* 82598 hardware only has a 32 bit counter in the high register */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4584 | if (hw->mac.type == ixgbe_mac_82599EB) { |
Ben Greear | aad7191 | 2009-09-30 12:08:16 +0000 | [diff] [blame] | 4585 | u64 tmp; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4586 | adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Ben Greear | aad7191 | 2009-09-30 12:08:16 +0000 | [diff] [blame] | 4587 | tmp = IXGBE_READ_REG(hw, IXGBE_GORCH) & 0xF; /* 4 high bits of GORC */ |
| 4588 | adapter->stats.gorc += (tmp << 32); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4589 | adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Ben Greear | aad7191 | 2009-09-30 12:08:16 +0000 | [diff] [blame] | 4590 | tmp = IXGBE_READ_REG(hw, IXGBE_GOTCH) & 0xF; /* 4 high bits of GOTC */ |
| 4591 | adapter->stats.gotc += (tmp << 32); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4592 | adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
| 4593 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
| 4594 | adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
| 4595 | adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4596 | adapter->stats.fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 4597 | adapter->stats.fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 4598 | #ifdef IXGBE_FCOE |
| 4599 | adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 4600 | adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 4601 | adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 4602 | adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 4603 | adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 4604 | adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
| 4605 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4606 | } else { |
| 4607 | adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
| 4608 | adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 4609 | adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 4610 | adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 4611 | adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 4612 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4613 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
| 4614 | adapter->stats.bprc += bprc; |
| 4615 | adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4616 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4617 | adapter->stats.mprc -= bprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4618 | adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 4619 | adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 4620 | adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 4621 | adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 4622 | adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 4623 | adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 4624 | adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4625 | adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4626 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
| 4627 | adapter->stats.lxontxc += lxon; |
| 4628 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
| 4629 | adapter->stats.lxofftxc += lxoff; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4630 | adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 4631 | adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4632 | adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
| 4633 | /* |
| 4634 | * 82598 errata - tx of flow control packets is included in tx counters |
| 4635 | */ |
| 4636 | xon_off_tot = lxon + lxoff; |
| 4637 | adapter->stats.gptc -= xon_off_tot; |
| 4638 | adapter->stats.mptc -= xon_off_tot; |
| 4639 | adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4640 | adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 4641 | adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 4642 | adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4643 | adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 4644 | adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4645 | adapter->stats.ptc64 -= xon_off_tot; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4646 | adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 4647 | adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 4648 | adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 4649 | adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 4650 | adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4651 | adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
| 4652 | |
| 4653 | /* Fill out the OS statistics structure */ |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4654 | netdev->stats.multicast = adapter->stats.mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4655 | |
| 4656 | /* Rx Errors */ |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4657 | netdev->stats.rx_errors = adapter->stats.crcerrs + |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4658 | adapter->stats.rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4659 | netdev->stats.rx_dropped = 0; |
| 4660 | netdev->stats.rx_length_errors = adapter->stats.rlec; |
| 4661 | netdev->stats.rx_crc_errors = adapter->stats.crcerrs; |
| 4662 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4663 | } |
| 4664 | |
| 4665 | /** |
| 4666 | * ixgbe_watchdog - Timer Call-back |
| 4667 | * @data: pointer to adapter cast into an unsigned long |
| 4668 | **/ |
| 4669 | static void ixgbe_watchdog(unsigned long data) |
| 4670 | { |
| 4671 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4672 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4673 | u64 eics = 0; |
| 4674 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4675 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4676 | /* |
| 4677 | * Do the watchdog outside of interrupt context due to the lovely |
| 4678 | * delays that some of the newer hardware requires |
| 4679 | */ |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 4680 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4681 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 4682 | goto watchdog_short_circuit; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 4683 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4684 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
| 4685 | /* |
| 4686 | * for legacy and MSI interrupts don't set any bits |
| 4687 | * that are enabled for EIAM, because this operation |
| 4688 | * would set *both* EIMS and EICS for any bit in EIAM |
| 4689 | */ |
| 4690 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 4691 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
| 4692 | goto watchdog_reschedule; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4693 | } |
| 4694 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4695 | /* get one bit for every active tx/rx interrupt vector */ |
| 4696 | for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) { |
| 4697 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
| 4698 | if (qv->rxr_count || qv->txr_count) |
| 4699 | eics |= ((u64)1 << i); |
| 4700 | } |
| 4701 | |
| 4702 | /* Cause software interrupt to ensure rx rings are cleaned */ |
| 4703 | ixgbe_irq_rearm_queues(adapter, eics); |
| 4704 | |
| 4705 | watchdog_reschedule: |
| 4706 | /* Reset the timer */ |
| 4707 | mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ)); |
| 4708 | |
| 4709 | watchdog_short_circuit: |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4710 | schedule_work(&adapter->watchdog_task); |
| 4711 | } |
| 4712 | |
| 4713 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4714 | * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber |
| 4715 | * @work: pointer to work_struct containing our data |
| 4716 | **/ |
| 4717 | static void ixgbe_multispeed_fiber_task(struct work_struct *work) |
| 4718 | { |
| 4719 | struct ixgbe_adapter *adapter = container_of(work, |
| 4720 | struct ixgbe_adapter, |
| 4721 | multispeed_fiber_task); |
| 4722 | struct ixgbe_hw *hw = &adapter->hw; |
| 4723 | u32 autoneg; |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 4724 | bool negotiation; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4725 | |
| 4726 | adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK; |
Mallikarjuna R Chilakala | a1f2532 | 2009-06-30 11:44:36 +0000 | [diff] [blame] | 4727 | autoneg = hw->phy.autoneg_advertised; |
| 4728 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 4729 | hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
| 4730 | if (hw->mac.ops.setup_link) |
| 4731 | hw->mac.ops.setup_link(hw, autoneg, negotiation, true); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4732 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 4733 | adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK; |
| 4734 | } |
| 4735 | |
| 4736 | /** |
| 4737 | * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module |
| 4738 | * @work: pointer to work_struct containing our data |
| 4739 | **/ |
| 4740 | static void ixgbe_sfp_config_module_task(struct work_struct *work) |
| 4741 | { |
| 4742 | struct ixgbe_adapter *adapter = container_of(work, |
| 4743 | struct ixgbe_adapter, |
| 4744 | sfp_config_module_task); |
| 4745 | struct ixgbe_hw *hw = &adapter->hw; |
| 4746 | u32 err; |
| 4747 | |
| 4748 | adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK; |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 4749 | |
| 4750 | /* Time for electrical oscillations to settle down */ |
| 4751 | msleep(100); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4752 | err = hw->phy.ops.identify_sfp(hw); |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 4753 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4754 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 88d2b81 | 2009-06-30 11:43:55 +0000 | [diff] [blame] | 4755 | dev_err(&adapter->pdev->dev, "failed to initialize because " |
| 4756 | "an unsupported SFP+ module type was detected.\n" |
| 4757 | "Reload the driver after installing a supported " |
| 4758 | "module.\n"); |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 4759 | unregister_netdev(adapter->netdev); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4760 | return; |
| 4761 | } |
| 4762 | hw->mac.ops.setup_sfp(hw); |
| 4763 | |
Tony Breeds | 8d1c3c0 | 2009-04-09 22:29:10 +0000 | [diff] [blame] | 4764 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK)) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4765 | /* This will also work for DA Twinax connections */ |
| 4766 | schedule_work(&adapter->multispeed_fiber_task); |
| 4767 | adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK; |
| 4768 | } |
| 4769 | |
| 4770 | /** |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4771 | * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table |
| 4772 | * @work: pointer to work_struct containing our data |
| 4773 | **/ |
| 4774 | static void ixgbe_fdir_reinit_task(struct work_struct *work) |
| 4775 | { |
| 4776 | struct ixgbe_adapter *adapter = container_of(work, |
| 4777 | struct ixgbe_adapter, |
| 4778 | fdir_reinit_task); |
| 4779 | struct ixgbe_hw *hw = &adapter->hw; |
| 4780 | int i; |
| 4781 | |
| 4782 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 4783 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 4784 | set_bit(__IXGBE_FDIR_INIT_DONE, |
| 4785 | &(adapter->tx_ring[i].reinit_state)); |
| 4786 | } else { |
| 4787 | DPRINTK(PROBE, ERR, "failed to finish FDIR re-initialization, " |
| 4788 | "ignored adding FDIR ATR filters \n"); |
| 4789 | } |
| 4790 | /* Done FDIR Re-initialization, enable transmits */ |
| 4791 | netif_tx_start_all_queues(adapter->netdev); |
| 4792 | } |
| 4793 | |
| 4794 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4795 | * ixgbe_watchdog_task - worker thread to bring link up |
| 4796 | * @work: pointer to work_struct containing our data |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4797 | **/ |
| 4798 | static void ixgbe_watchdog_task(struct work_struct *work) |
| 4799 | { |
| 4800 | struct ixgbe_adapter *adapter = container_of(work, |
| 4801 | struct ixgbe_adapter, |
| 4802 | watchdog_task); |
| 4803 | struct net_device *netdev = adapter->netdev; |
| 4804 | struct ixgbe_hw *hw = &adapter->hw; |
| 4805 | u32 link_speed = adapter->link_speed; |
| 4806 | bool link_up = adapter->link_up; |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 4807 | int i; |
| 4808 | struct ixgbe_ring *tx_ring; |
| 4809 | int some_tx_pending = 0; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4810 | |
| 4811 | adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK; |
| 4812 | |
| 4813 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) { |
| 4814 | 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] | 4815 | if (link_up) { |
| 4816 | #ifdef CONFIG_DCB |
| 4817 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 4818 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 4819 | hw->mac.ops.fc_enable(hw, i); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4820 | } else { |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 4821 | hw->mac.ops.fc_enable(hw, 0); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4822 | } |
| 4823 | #else |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 4824 | hw->mac.ops.fc_enable(hw, 0); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4825 | #endif |
| 4826 | } |
| 4827 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4828 | if (link_up || |
| 4829 | time_after(jiffies, (adapter->link_check_timeout + |
| 4830 | IXGBE_TRY_LINK_TIMEOUT))) { |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4831 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4832 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4833 | } |
| 4834 | adapter->link_up = link_up; |
| 4835 | adapter->link_speed = link_speed; |
| 4836 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4837 | |
| 4838 | if (link_up) { |
| 4839 | if (!netif_carrier_ok(netdev)) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4840 | bool flow_rx, flow_tx; |
| 4841 | |
| 4842 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 4843 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 4844 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
Peter P Waskiewicz Jr | 078788b | 2009-07-16 15:50:32 +0000 | [diff] [blame] | 4845 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 4846 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4847 | } else { |
| 4848 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 4849 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
Peter P Waskiewicz Jr | 078788b | 2009-07-16 15:50:32 +0000 | [diff] [blame] | 4850 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 4851 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4852 | } |
| 4853 | |
Jeff Kirsher | a46e534 | 2008-11-27 00:22:21 -0800 | [diff] [blame] | 4854 | printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, " |
| 4855 | "Flow Control: %s\n", |
| 4856 | netdev->name, |
| 4857 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? |
| 4858 | "10 Gbps" : |
| 4859 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? |
| 4860 | "1 Gbps" : "unknown speed")), |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4861 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 4862 | (flow_rx ? "RX" : |
| 4863 | (flow_tx ? "TX" : "None")))); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4864 | |
| 4865 | netif_carrier_on(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4866 | } else { |
| 4867 | /* Force detection of hung controller */ |
| 4868 | adapter->detect_tx_hung = true; |
| 4869 | } |
| 4870 | } else { |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4871 | adapter->link_up = false; |
| 4872 | adapter->link_speed = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4873 | if (netif_carrier_ok(netdev)) { |
Jeff Kirsher | a46e534 | 2008-11-27 00:22:21 -0800 | [diff] [blame] | 4874 | printk(KERN_INFO "ixgbe: %s NIC Link is Down\n", |
| 4875 | netdev->name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4876 | netif_carrier_off(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4877 | } |
| 4878 | } |
| 4879 | |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 4880 | if (!netif_carrier_ok(netdev)) { |
| 4881 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 4882 | tx_ring = &adapter->tx_ring[i]; |
| 4883 | if (tx_ring->next_to_use != tx_ring->next_to_clean) { |
| 4884 | some_tx_pending = 1; |
| 4885 | break; |
| 4886 | } |
| 4887 | } |
| 4888 | |
| 4889 | if (some_tx_pending) { |
| 4890 | /* We've lost link, so the controller stops DMA, |
| 4891 | * but we've got queued Tx work that's never going |
| 4892 | * to get done, so reset controller to flush Tx. |
| 4893 | * (Do the reset outside of interrupt context). |
| 4894 | */ |
| 4895 | schedule_work(&adapter->reset_task); |
| 4896 | } |
| 4897 | } |
| 4898 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4899 | ixgbe_update_stats(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4900 | adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4901 | } |
| 4902 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4903 | static int ixgbe_tso(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4904 | struct ixgbe_ring *tx_ring, struct sk_buff *skb, |
| 4905 | u32 tx_flags, u8 *hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4906 | { |
| 4907 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 4908 | unsigned int i; |
| 4909 | int err; |
| 4910 | struct ixgbe_tx_buffer *tx_buffer_info; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4911 | u32 vlan_macip_lens = 0, type_tucmd_mlhl; |
| 4912 | u32 mss_l4len_idx, l4len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4913 | |
| 4914 | if (skb_is_gso(skb)) { |
| 4915 | if (skb_header_cloned(skb)) { |
| 4916 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 4917 | if (err) |
| 4918 | return err; |
| 4919 | } |
| 4920 | l4len = tcp_hdrlen(skb); |
| 4921 | *hdr_len += l4len; |
| 4922 | |
Al Viro | 8327d00 | 2007-12-10 18:54:12 +0000 | [diff] [blame] | 4923 | if (skb->protocol == htons(ETH_P_IP)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4924 | struct iphdr *iph = ip_hdr(skb); |
| 4925 | iph->tot_len = 0; |
| 4926 | iph->check = 0; |
| 4927 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4928 | iph->daddr, 0, |
| 4929 | IPPROTO_TCP, |
| 4930 | 0); |
Sridhar Samudrala | 8e1e8a4 | 2010-01-23 02:02:21 -0800 | [diff] [blame^] | 4931 | } else if (skb_is_gso_v6(skb)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4932 | ipv6_hdr(skb)->payload_len = 0; |
| 4933 | tcp_hdr(skb)->check = |
| 4934 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4935 | &ipv6_hdr(skb)->daddr, |
| 4936 | 0, IPPROTO_TCP, 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4937 | } |
| 4938 | |
| 4939 | i = tx_ring->next_to_use; |
| 4940 | |
| 4941 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4942 | context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i); |
| 4943 | |
| 4944 | /* VLAN MACLEN IPLEN */ |
| 4945 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 4946 | vlan_macip_lens |= |
| 4947 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); |
| 4948 | vlan_macip_lens |= ((skb_network_offset(skb)) << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4949 | IXGBE_ADVTXD_MACLEN_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4950 | *hdr_len += skb_network_offset(skb); |
| 4951 | vlan_macip_lens |= |
| 4952 | (skb_transport_header(skb) - skb_network_header(skb)); |
| 4953 | *hdr_len += |
| 4954 | (skb_transport_header(skb) - skb_network_header(skb)); |
| 4955 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 4956 | context_desc->seqnum_seed = 0; |
| 4957 | |
| 4958 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4959 | type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4960 | IXGBE_ADVTXD_DTYP_CTXT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4961 | |
Al Viro | 8327d00 | 2007-12-10 18:54:12 +0000 | [diff] [blame] | 4962 | if (skb->protocol == htons(ETH_P_IP)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4963 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 4964 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 4965 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); |
| 4966 | |
| 4967 | /* MSS L4LEN IDX */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4968 | mss_l4len_idx = |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4969 | (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT); |
| 4970 | mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT); |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 4971 | /* use index 1 for TSO */ |
| 4972 | mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4973 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 4974 | |
| 4975 | tx_buffer_info->time_stamp = jiffies; |
| 4976 | tx_buffer_info->next_to_watch = i; |
| 4977 | |
| 4978 | i++; |
| 4979 | if (i == tx_ring->count) |
| 4980 | i = 0; |
| 4981 | tx_ring->next_to_use = i; |
| 4982 | |
| 4983 | return true; |
| 4984 | } |
| 4985 | return false; |
| 4986 | } |
| 4987 | |
| 4988 | static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4989 | struct ixgbe_ring *tx_ring, |
| 4990 | struct sk_buff *skb, u32 tx_flags) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4991 | { |
| 4992 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 4993 | unsigned int i; |
| 4994 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 4995 | u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0; |
| 4996 | |
| 4997 | if (skb->ip_summed == CHECKSUM_PARTIAL || |
| 4998 | (tx_flags & IXGBE_TX_FLAGS_VLAN)) { |
| 4999 | i = tx_ring->next_to_use; |
| 5000 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5001 | context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i); |
| 5002 | |
| 5003 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 5004 | vlan_macip_lens |= |
| 5005 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); |
| 5006 | vlan_macip_lens |= (skb_network_offset(skb) << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5007 | IXGBE_ADVTXD_MACLEN_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5008 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 5009 | vlan_macip_lens |= (skb_transport_header(skb) - |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5010 | skb_network_header(skb)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5011 | |
| 5012 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 5013 | context_desc->seqnum_seed = 0; |
| 5014 | |
| 5015 | type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5016 | IXGBE_ADVTXD_DTYP_CTXT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5017 | |
| 5018 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Gurucharan Shetty | ca55398 | 2009-12-15 13:00:31 +0000 | [diff] [blame] | 5019 | __be16 protocol; |
| 5020 | |
| 5021 | if (skb->protocol == cpu_to_be16(ETH_P_8021Q)) { |
| 5022 | const struct vlan_ethhdr *vhdr = |
| 5023 | (const struct vlan_ethhdr *)skb->data; |
| 5024 | |
| 5025 | protocol = vhdr->h_vlan_encapsulated_proto; |
| 5026 | } else { |
| 5027 | protocol = skb->protocol; |
| 5028 | } |
| 5029 | |
| 5030 | switch (protocol) { |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 5031 | case cpu_to_be16(ETH_P_IP): |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5032 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5033 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 5034 | type_tucmd_mlhl |= |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5035 | IXGBE_ADVTXD_TUCMD_L4T_TCP; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 5036 | else if (ip_hdr(skb)->protocol == IPPROTO_SCTP) |
| 5037 | type_tucmd_mlhl |= |
| 5038 | IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5039 | break; |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 5040 | case cpu_to_be16(ETH_P_IPV6): |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5041 | /* XXX what about other V6 headers?? */ |
| 5042 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 5043 | type_tucmd_mlhl |= |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5044 | IXGBE_ADVTXD_TUCMD_L4T_TCP; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 5045 | else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP) |
| 5046 | type_tucmd_mlhl |= |
| 5047 | IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5048 | break; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5049 | default: |
| 5050 | if (unlikely(net_ratelimit())) { |
| 5051 | DPRINTK(PROBE, WARNING, |
| 5052 | "partial checksum but proto=%x!\n", |
| 5053 | skb->protocol); |
| 5054 | } |
| 5055 | break; |
| 5056 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5057 | } |
| 5058 | |
| 5059 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 5060 | /* use index zero for tx checksum offload */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5061 | context_desc->mss_l4len_idx = 0; |
| 5062 | |
| 5063 | tx_buffer_info->time_stamp = jiffies; |
| 5064 | tx_buffer_info->next_to_watch = i; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5065 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5066 | i++; |
| 5067 | if (i == tx_ring->count) |
| 5068 | i = 0; |
| 5069 | tx_ring->next_to_use = i; |
| 5070 | |
| 5071 | return true; |
| 5072 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5073 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5074 | return false; |
| 5075 | } |
| 5076 | |
| 5077 | static int ixgbe_tx_map(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5078 | struct ixgbe_ring *tx_ring, |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5079 | struct sk_buff *skb, u32 tx_flags, |
| 5080 | unsigned int first) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5081 | { |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5082 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5083 | struct ixgbe_tx_buffer *tx_buffer_info; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5084 | unsigned int len; |
| 5085 | unsigned int total = skb->len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5086 | unsigned int offset = 0, size, count = 0, i; |
| 5087 | unsigned int nr_frags = skb_shinfo(skb)->nr_frags; |
| 5088 | unsigned int f; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5089 | |
| 5090 | i = tx_ring->next_to_use; |
| 5091 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5092 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) |
| 5093 | /* excluding fcoe_crc_eof for FCoE */ |
| 5094 | total -= sizeof(struct fcoe_crc_eof); |
| 5095 | |
| 5096 | len = min(skb_headlen(skb), total); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5097 | while (len) { |
| 5098 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5099 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 5100 | |
| 5101 | tx_buffer_info->length = size; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5102 | tx_buffer_info->mapped_as_page = false; |
| 5103 | tx_buffer_info->dma = pci_map_single(pdev, |
| 5104 | skb->data + offset, |
| 5105 | size, PCI_DMA_TODEVICE); |
| 5106 | if (pci_dma_mapping_error(pdev, tx_buffer_info->dma)) |
| 5107 | goto dma_error; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5108 | tx_buffer_info->time_stamp = jiffies; |
| 5109 | tx_buffer_info->next_to_watch = i; |
| 5110 | |
| 5111 | len -= size; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5112 | total -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5113 | offset += size; |
| 5114 | count++; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5115 | |
| 5116 | if (len) { |
| 5117 | i++; |
| 5118 | if (i == tx_ring->count) |
| 5119 | i = 0; |
| 5120 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5121 | } |
| 5122 | |
| 5123 | for (f = 0; f < nr_frags; f++) { |
| 5124 | struct skb_frag_struct *frag; |
| 5125 | |
| 5126 | frag = &skb_shinfo(skb)->frags[f]; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5127 | len = min((unsigned int)frag->size, total); |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5128 | offset = frag->page_offset; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5129 | |
| 5130 | while (len) { |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5131 | i++; |
| 5132 | if (i == tx_ring->count) |
| 5133 | i = 0; |
| 5134 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5135 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5136 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 5137 | |
| 5138 | tx_buffer_info->length = size; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5139 | tx_buffer_info->dma = pci_map_page(adapter->pdev, |
| 5140 | frag->page, |
| 5141 | offset, size, |
| 5142 | PCI_DMA_TODEVICE); |
| 5143 | tx_buffer_info->mapped_as_page = true; |
| 5144 | if (pci_dma_mapping_error(pdev, tx_buffer_info->dma)) |
| 5145 | goto dma_error; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5146 | tx_buffer_info->time_stamp = jiffies; |
| 5147 | tx_buffer_info->next_to_watch = i; |
| 5148 | |
| 5149 | len -= size; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5150 | total -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5151 | offset += size; |
| 5152 | count++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5153 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5154 | if (total == 0) |
| 5155 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5156 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5157 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5158 | tx_ring->tx_buffer_info[i].skb = skb; |
| 5159 | tx_ring->tx_buffer_info[first].next_to_watch = i; |
| 5160 | |
| 5161 | return count; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5162 | |
| 5163 | dma_error: |
| 5164 | dev_err(&pdev->dev, "TX DMA map failed\n"); |
| 5165 | |
| 5166 | /* clear timestamp and dma mappings for failed tx_buffer_info map */ |
| 5167 | tx_buffer_info->dma = 0; |
| 5168 | tx_buffer_info->time_stamp = 0; |
| 5169 | tx_buffer_info->next_to_watch = 0; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 5170 | if (count) |
| 5171 | count--; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5172 | |
| 5173 | /* clear timestamp and dma mappings for remaining portion of packet */ |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 5174 | while (count--) { |
| 5175 | if (i==0) |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5176 | i += tx_ring->count; |
Roel Kluin | c1fa347 | 2010-01-19 14:21:45 +0000 | [diff] [blame] | 5177 | i--; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5178 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5179 | ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info); |
| 5180 | } |
| 5181 | |
| 5182 | return count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5183 | } |
| 5184 | |
| 5185 | static void ixgbe_tx_queue(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5186 | struct ixgbe_ring *tx_ring, |
| 5187 | int tx_flags, int count, u32 paylen, u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5188 | { |
| 5189 | union ixgbe_adv_tx_desc *tx_desc = NULL; |
| 5190 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 5191 | u32 olinfo_status = 0, cmd_type_len = 0; |
| 5192 | unsigned int i; |
| 5193 | u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS; |
| 5194 | |
| 5195 | cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA; |
| 5196 | |
| 5197 | cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT; |
| 5198 | |
| 5199 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 5200 | cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE; |
| 5201 | |
| 5202 | if (tx_flags & IXGBE_TX_FLAGS_TSO) { |
| 5203 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 5204 | |
| 5205 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5206 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5207 | |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 5208 | /* use index 1 context for tso */ |
| 5209 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5210 | if (tx_flags & IXGBE_TX_FLAGS_IPV4) |
| 5211 | olinfo_status |= IXGBE_TXD_POPTS_IXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5212 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5213 | |
| 5214 | } else if (tx_flags & IXGBE_TX_FLAGS_CSUM) |
| 5215 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5216 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5217 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5218 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 5219 | olinfo_status |= IXGBE_ADVTXD_CC; |
| 5220 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
| 5221 | if (tx_flags & IXGBE_TX_FLAGS_FSO) |
| 5222 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 5223 | } |
| 5224 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5225 | olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT); |
| 5226 | |
| 5227 | i = tx_ring->next_to_use; |
| 5228 | while (count--) { |
| 5229 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5230 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); |
| 5231 | tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma); |
| 5232 | tx_desc->read.cmd_type_len = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5233 | cpu_to_le32(cmd_type_len | tx_buffer_info->length); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5234 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5235 | i++; |
| 5236 | if (i == tx_ring->count) |
| 5237 | i = 0; |
| 5238 | } |
| 5239 | |
| 5240 | tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd); |
| 5241 | |
| 5242 | /* |
| 5243 | * Force memory writes to complete before letting h/w |
| 5244 | * know there are new descriptors to fetch. (Only |
| 5245 | * applicable for weak-ordered memory model archs, |
| 5246 | * such as IA-64). |
| 5247 | */ |
| 5248 | wmb(); |
| 5249 | |
| 5250 | tx_ring->next_to_use = i; |
| 5251 | writel(i, adapter->hw.hw_addr + tx_ring->tail); |
| 5252 | } |
| 5253 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5254 | static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb, |
| 5255 | int queue, u32 tx_flags) |
| 5256 | { |
| 5257 | /* Right now, we support IPv4 only */ |
| 5258 | struct ixgbe_atr_input atr_input; |
| 5259 | struct tcphdr *th; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5260 | struct iphdr *iph = ip_hdr(skb); |
| 5261 | struct ethhdr *eth = (struct ethhdr *)skb->data; |
| 5262 | u16 vlan_id, src_port, dst_port, flex_bytes; |
| 5263 | u32 src_ipv4_addr, dst_ipv4_addr; |
| 5264 | u8 l4type = 0; |
| 5265 | |
| 5266 | /* check if we're UDP or TCP */ |
| 5267 | if (iph->protocol == IPPROTO_TCP) { |
| 5268 | th = tcp_hdr(skb); |
| 5269 | src_port = th->source; |
| 5270 | dst_port = th->dest; |
| 5271 | l4type |= IXGBE_ATR_L4TYPE_TCP; |
| 5272 | /* l4type IPv4 type is 0, no need to assign */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5273 | } else { |
| 5274 | /* Unsupported L4 header, just bail here */ |
| 5275 | return; |
| 5276 | } |
| 5277 | |
| 5278 | memset(&atr_input, 0, sizeof(struct ixgbe_atr_input)); |
| 5279 | |
| 5280 | vlan_id = (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK) >> |
| 5281 | IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5282 | src_ipv4_addr = iph->saddr; |
| 5283 | dst_ipv4_addr = iph->daddr; |
| 5284 | flex_bytes = eth->h_proto; |
| 5285 | |
| 5286 | ixgbe_atr_set_vlan_id_82599(&atr_input, vlan_id); |
| 5287 | ixgbe_atr_set_src_port_82599(&atr_input, dst_port); |
| 5288 | ixgbe_atr_set_dst_port_82599(&atr_input, src_port); |
| 5289 | ixgbe_atr_set_flex_byte_82599(&atr_input, flex_bytes); |
| 5290 | ixgbe_atr_set_l4type_82599(&atr_input, l4type); |
| 5291 | /* src and dst are inverted, think how the receiver sees them */ |
| 5292 | ixgbe_atr_set_src_ipv4_82599(&atr_input, dst_ipv4_addr); |
| 5293 | ixgbe_atr_set_dst_ipv4_82599(&atr_input, src_ipv4_addr); |
| 5294 | |
| 5295 | /* This assumes the Rx queue and Tx queue are bound to the same CPU */ |
| 5296 | ixgbe_fdir_add_signature_filter_82599(&adapter->hw, &atr_input, queue); |
| 5297 | } |
| 5298 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5299 | static int __ixgbe_maybe_stop_tx(struct net_device *netdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5300 | struct ixgbe_ring *tx_ring, int size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5301 | { |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5302 | netif_stop_subqueue(netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5303 | /* Herbert's original patch had: |
| 5304 | * smp_mb__after_netif_stop_queue(); |
| 5305 | * but since that doesn't exist yet, just open code it. */ |
| 5306 | smp_mb(); |
| 5307 | |
| 5308 | /* We need to check again in a case another CPU has just |
| 5309 | * made room available. */ |
| 5310 | if (likely(IXGBE_DESC_UNUSED(tx_ring) < size)) |
| 5311 | return -EBUSY; |
| 5312 | |
| 5313 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
Jesse Brandeburg | af72166 | 2008-09-11 19:54:23 -0700 | [diff] [blame] | 5314 | netif_start_subqueue(netdev, tx_ring->queue_index); |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 5315 | ++tx_ring->restart_queue; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5316 | return 0; |
| 5317 | } |
| 5318 | |
| 5319 | static int ixgbe_maybe_stop_tx(struct net_device *netdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5320 | struct ixgbe_ring *tx_ring, int size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5321 | { |
| 5322 | if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size)) |
| 5323 | return 0; |
| 5324 | return __ixgbe_maybe_stop_tx(netdev, tx_ring, size); |
| 5325 | } |
| 5326 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5327 | static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb) |
| 5328 | { |
| 5329 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5330 | int txq = smp_processor_id(); |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5331 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5332 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5333 | return txq; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5334 | |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5335 | #ifdef IXGBE_FCOE |
| 5336 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 5337 | (skb->protocol == htons(ETH_P_FCOE))) { |
| 5338 | txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1); |
| 5339 | txq += adapter->ring_feature[RING_F_FCOE].mask; |
| 5340 | return txq; |
| 5341 | } |
| 5342 | #endif |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5343 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
Lucy Liu | 36e89d7 | 2009-08-05 13:06:34 -0700 | [diff] [blame] | 5344 | return (skb->vlan_tci & IXGBE_TX_FLAGS_VLAN_PRIO_MASK) >> 13; |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5345 | |
| 5346 | return skb_tx_hash(dev, skb); |
| 5347 | } |
| 5348 | |
Stephen Hemminger | 3b29a56 | 2009-08-31 19:50:55 +0000 | [diff] [blame] | 5349 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, |
| 5350 | struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5351 | { |
| 5352 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5353 | struct ixgbe_ring *tx_ring; |
Eric Dumazet | 60d5113 | 2009-12-08 07:22:03 +0000 | [diff] [blame] | 5354 | struct netdev_queue *txq; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5355 | unsigned int first; |
| 5356 | unsigned int tx_flags = 0; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5357 | u8 hdr_len = 0; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5358 | int tso; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5359 | int count = 0; |
| 5360 | unsigned int f; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5361 | |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5362 | if (adapter->vlgrp && vlan_tx_tag_present(skb)) { |
| 5363 | tx_flags |= vlan_tx_tag_get(skb); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5364 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 5365 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5366 | tx_flags |= ((skb->queue_mapping & 0x7) << 13); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5367 | } |
| 5368 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5369 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
| 5370 | } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 5371 | if (skb->priority != TC_PRIO_CONTROL) { |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5372 | tx_flags |= ((skb->queue_mapping & 0x7) << 13); |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 5373 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5374 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
| 5375 | } else { |
| 5376 | skb->queue_mapping = |
| 5377 | adapter->ring_feature[RING_F_DCB].indices-1; |
| 5378 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5379 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5380 | |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5381 | tx_ring = &adapter->tx_ring[skb->queue_mapping]; |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 5382 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5383 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
Yi Zou | 09ad1cc | 2009-09-03 14:56:10 +0000 | [diff] [blame] | 5384 | (skb->protocol == htons(ETH_P_FCOE))) { |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5385 | tx_flags |= IXGBE_TX_FLAGS_FCOE; |
Yi Zou | 09ad1cc | 2009-09-03 14:56:10 +0000 | [diff] [blame] | 5386 | #ifdef IXGBE_FCOE |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 5387 | #ifdef CONFIG_IXGBE_DCB |
| 5388 | tx_flags &= ~(IXGBE_TX_FLAGS_VLAN_PRIO_MASK |
| 5389 | << IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 5390 | tx_flags |= ((adapter->fcoe.up << 13) |
| 5391 | << IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 5392 | #endif |
Yi Zou | 09ad1cc | 2009-09-03 14:56:10 +0000 | [diff] [blame] | 5393 | #endif |
| 5394 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5395 | /* four things can cause us to need a context descriptor */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5396 | if (skb_is_gso(skb) || |
| 5397 | (skb->ip_summed == CHECKSUM_PARTIAL) || |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5398 | (tx_flags & IXGBE_TX_FLAGS_VLAN) || |
| 5399 | (tx_flags & IXGBE_TX_FLAGS_FCOE)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5400 | count++; |
| 5401 | |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5402 | count += TXD_USE_COUNT(skb_headlen(skb)); |
| 5403 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5404 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
| 5405 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5406 | if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5407 | adapter->tx_busy++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5408 | return NETDEV_TX_BUSY; |
| 5409 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5410 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5411 | first = tx_ring->next_to_use; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5412 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 5413 | #ifdef IXGBE_FCOE |
| 5414 | /* setup tx offload for FCoE */ |
| 5415 | tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len); |
| 5416 | if (tso < 0) { |
| 5417 | dev_kfree_skb_any(skb); |
| 5418 | return NETDEV_TX_OK; |
| 5419 | } |
| 5420 | if (tso) |
| 5421 | tx_flags |= IXGBE_TX_FLAGS_FSO; |
| 5422 | #endif /* IXGBE_FCOE */ |
| 5423 | } else { |
| 5424 | if (skb->protocol == htons(ETH_P_IP)) |
| 5425 | tx_flags |= IXGBE_TX_FLAGS_IPV4; |
| 5426 | tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len); |
| 5427 | if (tso < 0) { |
| 5428 | dev_kfree_skb_any(skb); |
| 5429 | return NETDEV_TX_OK; |
| 5430 | } |
| 5431 | |
| 5432 | if (tso) |
| 5433 | tx_flags |= IXGBE_TX_FLAGS_TSO; |
| 5434 | else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) && |
| 5435 | (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 5436 | tx_flags |= IXGBE_TX_FLAGS_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5437 | } |
| 5438 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5439 | count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5440 | if (count) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5441 | /* add the ATR filter if ATR is on */ |
| 5442 | if (tx_ring->atr_sample_rate) { |
| 5443 | ++tx_ring->atr_count; |
| 5444 | if ((tx_ring->atr_count >= tx_ring->atr_sample_rate) && |
| 5445 | test_bit(__IXGBE_FDIR_INIT_DONE, |
| 5446 | &tx_ring->reinit_state)) { |
| 5447 | ixgbe_atr(adapter, skb, tx_ring->queue_index, |
| 5448 | tx_flags); |
| 5449 | tx_ring->atr_count = 0; |
| 5450 | } |
| 5451 | } |
Eric Dumazet | 60d5113 | 2009-12-08 07:22:03 +0000 | [diff] [blame] | 5452 | txq = netdev_get_tx_queue(netdev, tx_ring->queue_index); |
| 5453 | txq->tx_bytes += skb->len; |
| 5454 | txq->tx_packets++; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5455 | ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len, |
| 5456 | hdr_len); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5457 | ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5458 | |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5459 | } else { |
| 5460 | dev_kfree_skb_any(skb); |
| 5461 | tx_ring->tx_buffer_info[first].time_stamp = 0; |
| 5462 | tx_ring->next_to_use = first; |
| 5463 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5464 | |
| 5465 | return NETDEV_TX_OK; |
| 5466 | } |
| 5467 | |
| 5468 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5469 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
| 5470 | * @netdev: network interface device structure |
| 5471 | * @p: pointer to an address structure |
| 5472 | * |
| 5473 | * Returns 0 on success, negative on failure |
| 5474 | **/ |
| 5475 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 5476 | { |
| 5477 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5478 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5479 | struct sockaddr *addr = p; |
| 5480 | |
| 5481 | if (!is_valid_ether_addr(addr->sa_data)) |
| 5482 | return -EADDRNOTAVAIL; |
| 5483 | |
| 5484 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5485 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5486 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5487 | hw->mac.ops.set_rar(hw, 0, hw->mac.addr, 0, IXGBE_RAH_AV); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5488 | |
| 5489 | return 0; |
| 5490 | } |
| 5491 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5492 | static int |
| 5493 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 5494 | { |
| 5495 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5496 | struct ixgbe_hw *hw = &adapter->hw; |
| 5497 | u16 value; |
| 5498 | int rc; |
| 5499 | |
| 5500 | if (prtad != hw->phy.mdio.prtad) |
| 5501 | return -EINVAL; |
| 5502 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 5503 | if (!rc) |
| 5504 | rc = value; |
| 5505 | return rc; |
| 5506 | } |
| 5507 | |
| 5508 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 5509 | u16 addr, u16 value) |
| 5510 | { |
| 5511 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5512 | struct ixgbe_hw *hw = &adapter->hw; |
| 5513 | |
| 5514 | if (prtad != hw->phy.mdio.prtad) |
| 5515 | return -EINVAL; |
| 5516 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 5517 | } |
| 5518 | |
| 5519 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 5520 | { |
| 5521 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5522 | |
| 5523 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 5524 | } |
| 5525 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5526 | /** |
| 5527 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 5528 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5529 | * @netdev: network interface device structure |
| 5530 | * |
| 5531 | * Returns non-zero on failure |
| 5532 | **/ |
| 5533 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
| 5534 | { |
| 5535 | int err = 0; |
| 5536 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 5537 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 5538 | |
| 5539 | if (is_valid_ether_addr(mac->san_addr)) { |
| 5540 | rtnl_lock(); |
| 5541 | err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 5542 | rtnl_unlock(); |
| 5543 | } |
| 5544 | return err; |
| 5545 | } |
| 5546 | |
| 5547 | /** |
| 5548 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 5549 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5550 | * @netdev: network interface device structure |
| 5551 | * |
| 5552 | * Returns non-zero on failure |
| 5553 | **/ |
| 5554 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 5555 | { |
| 5556 | int err = 0; |
| 5557 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 5558 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 5559 | |
| 5560 | if (is_valid_ether_addr(mac->san_addr)) { |
| 5561 | rtnl_lock(); |
| 5562 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 5563 | rtnl_unlock(); |
| 5564 | } |
| 5565 | return err; |
| 5566 | } |
| 5567 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5568 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5569 | /* |
| 5570 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 5571 | * without having to re-enable interrupts. It's not called while |
| 5572 | * the interrupt routine is executing. |
| 5573 | */ |
| 5574 | static void ixgbe_netpoll(struct net_device *netdev) |
| 5575 | { |
| 5576 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 5577 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5578 | |
Alexander Duyck | 1a647bd | 2010-01-13 01:49:13 +0000 | [diff] [blame] | 5579 | /* if interface is down do nothing */ |
| 5580 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 5581 | return; |
| 5582 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5583 | adapter->flags |= IXGBE_FLAG_IN_NETPOLL; |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 5584 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 5585 | int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 5586 | for (i = 0; i < num_q_vectors; i++) { |
| 5587 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
| 5588 | ixgbe_msix_clean_many(0, q_vector); |
| 5589 | } |
| 5590 | } else { |
| 5591 | ixgbe_intr(adapter->pdev->irq, netdev); |
| 5592 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5593 | adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5594 | } |
| 5595 | #endif |
| 5596 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5597 | static const struct net_device_ops ixgbe_netdev_ops = { |
| 5598 | .ndo_open = ixgbe_open, |
| 5599 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 5600 | .ndo_start_xmit = ixgbe_xmit_frame, |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5601 | .ndo_select_queue = ixgbe_select_queue, |
Chris Leech | e90d400 | 2009-03-10 16:00:24 +0000 | [diff] [blame] | 5602 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5603 | .ndo_set_multicast_list = ixgbe_set_rx_mode, |
| 5604 | .ndo_validate_addr = eth_validate_addr, |
| 5605 | .ndo_set_mac_address = ixgbe_set_mac, |
| 5606 | .ndo_change_mtu = ixgbe_change_mtu, |
| 5607 | .ndo_tx_timeout = ixgbe_tx_timeout, |
| 5608 | .ndo_vlan_rx_register = ixgbe_vlan_rx_register, |
| 5609 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 5610 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5611 | .ndo_do_ioctl = ixgbe_ioctl, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5612 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5613 | .ndo_poll_controller = ixgbe_netpoll, |
| 5614 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 5615 | #ifdef IXGBE_FCOE |
| 5616 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
| 5617 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 5618 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 5619 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 5620 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 5621 | #endif /* IXGBE_FCOE */ |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5622 | }; |
| 5623 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5624 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5625 | * ixgbe_probe - Device Initialization Routine |
| 5626 | * @pdev: PCI device information struct |
| 5627 | * @ent: entry in ixgbe_pci_tbl |
| 5628 | * |
| 5629 | * Returns 0 on success, negative on failure |
| 5630 | * |
| 5631 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 5632 | * The OS initialization, configuring of the adapter private structure, |
| 5633 | * and a hardware reset occur. |
| 5634 | **/ |
| 5635 | static int __devinit ixgbe_probe(struct pci_dev *pdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5636 | const struct pci_device_id *ent) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5637 | { |
| 5638 | struct net_device *netdev; |
| 5639 | struct ixgbe_adapter *adapter = NULL; |
| 5640 | struct ixgbe_hw *hw; |
| 5641 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5642 | static int cards_found; |
| 5643 | int i, err, pci_using_dac; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5644 | #ifdef IXGBE_FCOE |
| 5645 | u16 device_caps; |
| 5646 | #endif |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5647 | u32 part_num, eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5648 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5649 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5650 | if (err) |
| 5651 | return err; |
| 5652 | |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 5653 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
| 5654 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5655 | pci_using_dac = 1; |
| 5656 | } else { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5657 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5658 | if (err) { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5659 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5660 | if (err) { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5661 | dev_err(&pdev->dev, "No usable DMA " |
| 5662 | "configuration, aborting\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5663 | goto err_dma; |
| 5664 | } |
| 5665 | } |
| 5666 | pci_using_dac = 0; |
| 5667 | } |
| 5668 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5669 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
| 5670 | IORESOURCE_MEM), ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5671 | if (err) { |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5672 | dev_err(&pdev->dev, |
| 5673 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5674 | goto err_pci_reg; |
| 5675 | } |
| 5676 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 5677 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5678 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5679 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 5680 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5681 | |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5682 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5683 | if (!netdev) { |
| 5684 | err = -ENOMEM; |
| 5685 | goto err_alloc_etherdev; |
| 5686 | } |
| 5687 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5688 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 5689 | |
| 5690 | pci_set_drvdata(pdev, netdev); |
| 5691 | adapter = netdev_priv(netdev); |
| 5692 | |
| 5693 | adapter->netdev = netdev; |
| 5694 | adapter->pdev = pdev; |
| 5695 | hw = &adapter->hw; |
| 5696 | hw->back = adapter; |
| 5697 | adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
| 5698 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 5699 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
| 5700 | pci_resource_len(pdev, 0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5701 | if (!hw->hw_addr) { |
| 5702 | err = -EIO; |
| 5703 | goto err_ioremap; |
| 5704 | } |
| 5705 | |
| 5706 | for (i = 1; i <= 5; i++) { |
| 5707 | if (pci_resource_len(pdev, i) == 0) |
| 5708 | continue; |
| 5709 | } |
| 5710 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5711 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5712 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5713 | netdev->watchdog_timeo = 5 * HZ; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5714 | strcpy(netdev->name, pci_name(pdev)); |
| 5715 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5716 | adapter->bd_number = cards_found; |
| 5717 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5718 | /* Setup hw api */ |
| 5719 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5720 | hw->mac.type = ii->mac; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5721 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5722 | /* EEPROM */ |
| 5723 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); |
| 5724 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 5725 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
| 5726 | if (!(eec & (1 << 8))) |
| 5727 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 5728 | |
| 5729 | /* PHY */ |
| 5730 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5731 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5732 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 5733 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 5734 | hw->phy.mdio.mmds = 0; |
| 5735 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 5736 | hw->phy.mdio.dev = netdev; |
| 5737 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 5738 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5739 | |
| 5740 | /* set up this timer and work struct before calling get_invariants |
| 5741 | * which might start the timer |
| 5742 | */ |
| 5743 | init_timer(&adapter->sfp_timer); |
| 5744 | adapter->sfp_timer.function = &ixgbe_sfp_timer; |
| 5745 | adapter->sfp_timer.data = (unsigned long) adapter; |
| 5746 | |
| 5747 | INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5748 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5749 | /* multispeed fiber has its own tasklet, called from GPI SDP1 context */ |
| 5750 | INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task); |
| 5751 | |
| 5752 | /* a new SFP+ module arrival, called from GPI SDP2 context */ |
| 5753 | INIT_WORK(&adapter->sfp_config_module_task, |
| 5754 | ixgbe_sfp_config_module_task); |
| 5755 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5756 | ii->get_invariants(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5757 | |
| 5758 | /* setup the private structure */ |
| 5759 | err = ixgbe_sw_init(adapter); |
| 5760 | if (err) |
| 5761 | goto err_sw_init; |
| 5762 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5763 | /* |
| 5764 | * If there is a fan on this device and it has failed log the |
| 5765 | * failure. |
| 5766 | */ |
| 5767 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 5768 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 5769 | if (esdp & IXGBE_ESDP_SDP1) |
| 5770 | DPRINTK(PROBE, CRIT, |
| 5771 | "Fan has stopped, replace the adapter\n"); |
| 5772 | } |
| 5773 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5774 | /* reset_hw fills in the perm_addr as well */ |
| 5775 | err = hw->mac.ops.reset_hw(hw); |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5776 | if (err == IXGBE_ERR_SFP_NOT_PRESENT && |
| 5777 | hw->mac.type == ixgbe_mac_82598EB) { |
| 5778 | /* |
| 5779 | * Start a kernel thread to watch for a module to arrive. |
| 5780 | * Only do this for 82598, since 82599 will generate |
| 5781 | * interrupts on module arrival. |
| 5782 | */ |
| 5783 | set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 5784 | mod_timer(&adapter->sfp_timer, |
| 5785 | round_jiffies(jiffies + (2 * HZ))); |
| 5786 | err = 0; |
| 5787 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 88d2b81 | 2009-06-30 11:43:55 +0000 | [diff] [blame] | 5788 | dev_err(&adapter->pdev->dev, "failed to initialize because " |
| 5789 | "an unsupported SFP+ module type was detected.\n" |
| 5790 | "Reload the driver after installing a supported " |
| 5791 | "module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 5792 | goto err_sw_init; |
| 5793 | } else if (err) { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5794 | dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err); |
| 5795 | goto err_sw_init; |
| 5796 | } |
| 5797 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5798 | netdev->features = NETIF_F_SG | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5799 | NETIF_F_IP_CSUM | |
| 5800 | NETIF_F_HW_VLAN_TX | |
| 5801 | NETIF_F_HW_VLAN_RX | |
| 5802 | NETIF_F_HW_VLAN_FILTER; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5803 | |
Jesse Brandeburg | e9990a9 | 2008-08-26 04:27:24 -0700 | [diff] [blame] | 5804 | netdev->features |= NETIF_F_IPV6_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5805 | netdev->features |= NETIF_F_TSO; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5806 | netdev->features |= NETIF_F_TSO6; |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 5807 | netdev->features |= NETIF_F_GRO; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 5808 | |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 5809 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 5810 | netdev->features |= NETIF_F_SCTP_CSUM; |
| 5811 | |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 5812 | netdev->vlan_features |= NETIF_F_TSO; |
| 5813 | netdev->vlan_features |= NETIF_F_TSO6; |
Jesse Brandeburg | 22f32b7a5 | 2008-08-26 04:27:18 -0700 | [diff] [blame] | 5814 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Alexander Duyck | cd1da50 | 2009-08-25 04:47:50 +0000 | [diff] [blame] | 5815 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 5816 | netdev->vlan_features |= NETIF_F_SG; |
| 5817 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5818 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 5819 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
| 5820 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5821 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5822 | netdev->dcbnl_ops = &dcbnl_ops; |
| 5823 | #endif |
| 5824 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5825 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 5826 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5827 | if (hw->mac.ops.get_device_caps) { |
| 5828 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 5829 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 5830 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5831 | } |
| 5832 | } |
| 5833 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5834 | if (pci_using_dac) |
| 5835 | netdev->features |= NETIF_F_HIGHDMA; |
| 5836 | |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 5837 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5838 | netdev->features |= NETIF_F_LRO; |
| 5839 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5840 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5841 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5842 | dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n"); |
| 5843 | err = -EIO; |
| 5844 | goto err_eeprom; |
| 5845 | } |
| 5846 | |
| 5847 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
| 5848 | memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len); |
| 5849 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5850 | if (ixgbe_validate_mac_addr(netdev->perm_addr)) { |
| 5851 | dev_err(&pdev->dev, "invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5852 | err = -EIO; |
| 5853 | goto err_eeprom; |
| 5854 | } |
| 5855 | |
| 5856 | init_timer(&adapter->watchdog_timer); |
| 5857 | adapter->watchdog_timer.function = &ixgbe_watchdog; |
| 5858 | adapter->watchdog_timer.data = (unsigned long)adapter; |
| 5859 | |
| 5860 | INIT_WORK(&adapter->reset_task, ixgbe_reset_task); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5861 | INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5862 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5863 | err = ixgbe_init_interrupt_scheme(adapter); |
| 5864 | if (err) |
| 5865 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5866 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5867 | switch (pdev->device) { |
| 5868 | case IXGBE_DEV_ID_82599_KX4: |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 5869 | adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX | |
| 5870 | IXGBE_WUFC_MC | IXGBE_WUFC_BC); |
Peter P Waskiewicz Jr | bdf0a55 | 2009-06-04 11:09:58 +0000 | [diff] [blame] | 5871 | /* Enable ACPI wakeup in GRC */ |
| 5872 | IXGBE_WRITE_REG(hw, IXGBE_GRC, |
| 5873 | (IXGBE_READ_REG(hw, IXGBE_GRC) & ~IXGBE_GRC_APME)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5874 | break; |
| 5875 | default: |
| 5876 | adapter->wol = 0; |
| 5877 | break; |
| 5878 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5879 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 5880 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 5881 | /* pick up the PCI bus settings for reporting later */ |
| 5882 | hw->mac.ops.get_bus_info(hw); |
| 5883 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5884 | /* print bus type/speed/width info */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 5885 | dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n", |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5886 | ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s": |
| 5887 | (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"), |
| 5888 | ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" : |
| 5889 | (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" : |
| 5890 | (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" : |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5891 | "Unknown"), |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 5892 | netdev->dev_addr); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5893 | ixgbe_read_pba_num_generic(hw, &part_num); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5894 | if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present) |
| 5895 | dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n", |
| 5896 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
| 5897 | (part_num >> 8), (part_num & 0xff)); |
| 5898 | else |
| 5899 | dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n", |
| 5900 | hw->mac.type, hw->phy.type, |
| 5901 | (part_num >> 8), (part_num & 0xff)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5902 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5903 | if (hw->bus.width <= ixgbe_bus_width_pcie_x4) { |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 5904 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5905 | "this card is not sufficient for optimal " |
| 5906 | "performance.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 5907 | dev_warn(&pdev->dev, "For optimal performance a x8 " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5908 | "PCI-Express slot is required.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 5909 | } |
| 5910 | |
Peter P Waskiewicz Jr | 34b0368 | 2009-02-05 23:54:42 -0800 | [diff] [blame] | 5911 | /* save off EEPROM version number */ |
| 5912 | hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version); |
| 5913 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5914 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5915 | err = hw->mac.ops.start_hw(hw); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5916 | |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5917 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 5918 | /* We are running on a pre-production device, log a warning */ |
| 5919 | dev_warn(&pdev->dev, "This device is a pre-production " |
| 5920 | "adapter/LOM. Please be aware there may be issues " |
| 5921 | "associated with your hardware. If you are " |
| 5922 | "experiencing problems please contact your Intel or " |
| 5923 | "hardware representative who provided you with this " |
| 5924 | "hardware.\n"); |
| 5925 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5926 | strcpy(netdev->name, "eth%d"); |
| 5927 | err = register_netdev(netdev); |
| 5928 | if (err) |
| 5929 | goto err_register; |
| 5930 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 5931 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 5932 | netif_carrier_off(netdev); |
| 5933 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5934 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 5935 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 5936 | INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task); |
| 5937 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 5938 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 5939 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5940 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5941 | ixgbe_setup_dca(adapter); |
| 5942 | } |
| 5943 | #endif |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5944 | /* add san mac addr to netdev */ |
| 5945 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5946 | |
| 5947 | dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n"); |
| 5948 | cards_found++; |
| 5949 | return 0; |
| 5950 | |
| 5951 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5952 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5953 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5954 | err_sw_init: |
| 5955 | err_eeprom: |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5956 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 5957 | del_timer_sync(&adapter->sfp_timer); |
| 5958 | cancel_work_sync(&adapter->sfp_task); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5959 | cancel_work_sync(&adapter->multispeed_fiber_task); |
| 5960 | cancel_work_sync(&adapter->sfp_config_module_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5961 | iounmap(hw->hw_addr); |
| 5962 | err_ioremap: |
| 5963 | free_netdev(netdev); |
| 5964 | err_alloc_etherdev: |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5965 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
| 5966 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5967 | err_pci_reg: |
| 5968 | err_dma: |
| 5969 | pci_disable_device(pdev); |
| 5970 | return err; |
| 5971 | } |
| 5972 | |
| 5973 | /** |
| 5974 | * ixgbe_remove - Device Removal Routine |
| 5975 | * @pdev: PCI device information struct |
| 5976 | * |
| 5977 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 5978 | * that it should release a PCI device. The could be caused by a |
| 5979 | * Hot-Plug event, or because the driver is going to be removed from |
| 5980 | * memory. |
| 5981 | **/ |
| 5982 | static void __devexit ixgbe_remove(struct pci_dev *pdev) |
| 5983 | { |
| 5984 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5985 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5986 | |
| 5987 | set_bit(__IXGBE_DOWN, &adapter->state); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5988 | /* clear the module not found bit to make sure the worker won't |
| 5989 | * reschedule |
| 5990 | */ |
| 5991 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5992 | del_timer_sync(&adapter->watchdog_timer); |
| 5993 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5994 | del_timer_sync(&adapter->sfp_timer); |
| 5995 | cancel_work_sync(&adapter->watchdog_task); |
| 5996 | cancel_work_sync(&adapter->sfp_task); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5997 | cancel_work_sync(&adapter->multispeed_fiber_task); |
| 5998 | cancel_work_sync(&adapter->sfp_config_module_task); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5999 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 6000 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 6001 | cancel_work_sync(&adapter->fdir_reinit_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6002 | flush_scheduled_work(); |
| 6003 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6004 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6005 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 6006 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 6007 | dca_remove_requester(&pdev->dev); |
| 6008 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 6009 | } |
| 6010 | |
| 6011 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 6012 | #ifdef IXGBE_FCOE |
| 6013 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 6014 | ixgbe_cleanup_fcoe(adapter); |
| 6015 | |
| 6016 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 6017 | |
| 6018 | /* remove the added san mac */ |
| 6019 | ixgbe_del_sanmac_netdev(netdev); |
| 6020 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 6021 | if (netdev->reg_state == NETREG_REGISTERED) |
| 6022 | unregister_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6023 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 6024 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 6025 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6026 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6027 | |
| 6028 | iounmap(adapter->hw.hw_addr); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 6029 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
| 6030 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6031 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6032 | DPRINTK(PROBE, INFO, "complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6033 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6034 | free_netdev(netdev); |
| 6035 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 6036 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6037 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6038 | pci_disable_device(pdev); |
| 6039 | } |
| 6040 | |
| 6041 | /** |
| 6042 | * ixgbe_io_error_detected - called when PCI error is detected |
| 6043 | * @pdev: Pointer to PCI device |
| 6044 | * @state: The current pci connection state |
| 6045 | * |
| 6046 | * This function is called after a PCI bus error affecting |
| 6047 | * this device has been detected. |
| 6048 | */ |
| 6049 | 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] | 6050 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6051 | { |
| 6052 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 6053 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6054 | |
| 6055 | netif_device_detach(netdev); |
| 6056 | |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 6057 | if (state == pci_channel_io_perm_failure) |
| 6058 | return PCI_ERS_RESULT_DISCONNECT; |
| 6059 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6060 | if (netif_running(netdev)) |
| 6061 | ixgbe_down(adapter); |
| 6062 | pci_disable_device(pdev); |
| 6063 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6064 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6065 | return PCI_ERS_RESULT_NEED_RESET; |
| 6066 | } |
| 6067 | |
| 6068 | /** |
| 6069 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 6070 | * @pdev: Pointer to PCI device |
| 6071 | * |
| 6072 | * Restart the card from scratch, as if from a cold-boot. |
| 6073 | */ |
| 6074 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 6075 | { |
| 6076 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 6077 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6078 | pci_ers_result_t result; |
| 6079 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6080 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 6081 | if (pci_enable_device_mem(pdev)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6082 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6083 | "Cannot re-enable PCI device after reset.\n"); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6084 | result = PCI_ERS_RESULT_DISCONNECT; |
| 6085 | } else { |
| 6086 | pci_set_master(pdev); |
| 6087 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 6088 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6089 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 6090 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6091 | |
| 6092 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 6093 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6094 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6095 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6096 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6097 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 6098 | if (err) { |
| 6099 | dev_err(&pdev->dev, |
| 6100 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err); |
| 6101 | /* non-fatal, continue */ |
| 6102 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6103 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6104 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6105 | } |
| 6106 | |
| 6107 | /** |
| 6108 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 6109 | * @pdev: Pointer to PCI device |
| 6110 | * |
| 6111 | * This callback is called when the error recovery driver tells us that |
| 6112 | * its OK to resume normal operation. |
| 6113 | */ |
| 6114 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 6115 | { |
| 6116 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 6117 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6118 | |
| 6119 | if (netif_running(netdev)) { |
| 6120 | if (ixgbe_up(adapter)) { |
| 6121 | DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n"); |
| 6122 | return; |
| 6123 | } |
| 6124 | } |
| 6125 | |
| 6126 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6127 | } |
| 6128 | |
| 6129 | static struct pci_error_handlers ixgbe_err_handler = { |
| 6130 | .error_detected = ixgbe_io_error_detected, |
| 6131 | .slot_reset = ixgbe_io_slot_reset, |
| 6132 | .resume = ixgbe_io_resume, |
| 6133 | }; |
| 6134 | |
| 6135 | static struct pci_driver ixgbe_driver = { |
| 6136 | .name = ixgbe_driver_name, |
| 6137 | .id_table = ixgbe_pci_tbl, |
| 6138 | .probe = ixgbe_probe, |
| 6139 | .remove = __devexit_p(ixgbe_remove), |
| 6140 | #ifdef CONFIG_PM |
| 6141 | .suspend = ixgbe_suspend, |
| 6142 | .resume = ixgbe_resume, |
| 6143 | #endif |
| 6144 | .shutdown = ixgbe_shutdown, |
| 6145 | .err_handler = &ixgbe_err_handler |
| 6146 | }; |
| 6147 | |
| 6148 | /** |
| 6149 | * ixgbe_init_module - Driver Registration Routine |
| 6150 | * |
| 6151 | * ixgbe_init_module is the first routine called when the driver is |
| 6152 | * loaded. All it does is register with the PCI subsystem. |
| 6153 | **/ |
| 6154 | static int __init ixgbe_init_module(void) |
| 6155 | { |
| 6156 | int ret; |
| 6157 | printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name, |
| 6158 | ixgbe_driver_string, ixgbe_driver_version); |
| 6159 | |
| 6160 | printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright); |
| 6161 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6162 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6163 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6164 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6165 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6166 | ret = pci_register_driver(&ixgbe_driver); |
| 6167 | return ret; |
| 6168 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6169 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6170 | module_init(ixgbe_init_module); |
| 6171 | |
| 6172 | /** |
| 6173 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 6174 | * |
| 6175 | * ixgbe_exit_module is called just before the driver is removed |
| 6176 | * from memory. |
| 6177 | **/ |
| 6178 | static void __exit ixgbe_exit_module(void) |
| 6179 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6180 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6181 | dca_unregister_notify(&dca_notifier); |
| 6182 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6183 | pci_unregister_driver(&ixgbe_driver); |
| 6184 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6185 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6186 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6187 | 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] | 6188 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6189 | { |
| 6190 | int ret_val; |
| 6191 | |
| 6192 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6193 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6194 | |
| 6195 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 6196 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6197 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 6198 | #endif /* CONFIG_IXGBE_DCA */ |
| 6199 | #ifdef DEBUG |
| 6200 | /** |
| 6201 | * ixgbe_get_hw_dev_name - return device name string |
| 6202 | * used by hardware layer to print debugging information |
| 6203 | **/ |
| 6204 | char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw) |
| 6205 | { |
| 6206 | struct ixgbe_adapter *adapter = hw->back; |
| 6207 | return adapter->netdev->name; |
| 6208 | } |
| 6209 | |
| 6210 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6211 | module_exit(ixgbe_exit_module); |
| 6212 | |
| 6213 | /* ixgbe_main.c */ |