Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1 | /******************************************************************************* |
| 2 | |
| 3 | Intel 10 Gigabit PCI Express Linux driver |
Peter P Waskiewicz Jr | 3efac5a | 2009-02-01 01:19:20 -0800 | [diff] [blame] | 4 | Copyright(c) 1999 - 2009 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; |
Peter P Waskiewicz Jr | 3efac5a | 2009-02-01 01:19:20 -0800 | [diff] [blame] | 55 | static char ixgbe_copyright[] = "Copyright (c) 1999-2009 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 }, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 99 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), |
| 100 | board_82599 }, |
Don Skidmore | 38ad1c8 | 2009-10-08 15:35:58 +0000 | [diff] [blame] | 101 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), |
| 102 | board_82599 }, |
Don Skidmore | dbfec66 | 2009-10-02 08:58:25 +0000 | [diff] [blame] | 103 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), |
| 104 | board_82599 }, |
Peter P Waskiewicz Jr | 8911184 | 2009-09-14 07:47:49 +0000 | [diff] [blame] | 105 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), |
| 106 | board_82599 }, |
Don Skidmore | 312eb93 | 2009-10-02 08:58:04 +0000 | [diff] [blame] | 107 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), |
| 108 | board_82599 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 109 | |
| 110 | /* required last entry */ |
| 111 | {0, } |
| 112 | }; |
| 113 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 114 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 115 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 116 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 117 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 118 | static struct notifier_block dca_notifier = { |
| 119 | .notifier_call = ixgbe_notify_dca, |
| 120 | .next = NULL, |
| 121 | .priority = 0 |
| 122 | }; |
| 123 | #endif |
| 124 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 125 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 126 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 127 | MODULE_LICENSE("GPL"); |
| 128 | MODULE_VERSION(DRV_VERSION); |
| 129 | |
| 130 | #define DEFAULT_DEBUG_LEVEL_SHIFT 3 |
| 131 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 132 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 133 | { |
| 134 | u32 ctrl_ext; |
| 135 | |
| 136 | /* Let firmware take over control of h/w */ |
| 137 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 138 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 139 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 140 | } |
| 141 | |
| 142 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 143 | { |
| 144 | u32 ctrl_ext; |
| 145 | |
| 146 | /* Let firmware know the driver has taken over */ |
| 147 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 148 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 149 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 150 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 151 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 152 | /* |
| 153 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 154 | * @adapter: pointer to adapter struct |
| 155 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 156 | * @queue: queue to map the corresponding interrupt to |
| 157 | * @msix_vector: the vector to map to the corresponding queue |
| 158 | * |
| 159 | */ |
| 160 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
| 161 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 162 | { |
| 163 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 164 | struct ixgbe_hw *hw = &adapter->hw; |
| 165 | switch (hw->mac.type) { |
| 166 | case ixgbe_mac_82598EB: |
| 167 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 168 | if (direction == -1) |
| 169 | direction = 0; |
| 170 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 171 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 172 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 173 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 174 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 175 | break; |
| 176 | case ixgbe_mac_82599EB: |
| 177 | if (direction == -1) { |
| 178 | /* other causes */ |
| 179 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 180 | index = ((queue & 1) * 8); |
| 181 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 182 | ivar &= ~(0xFF << index); |
| 183 | ivar |= (msix_vector << index); |
| 184 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 185 | break; |
| 186 | } else { |
| 187 | /* tx or rx causes */ |
| 188 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 189 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 190 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 191 | ivar &= ~(0xFF << index); |
| 192 | ivar |= (msix_vector << index); |
| 193 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 194 | break; |
| 195 | } |
| 196 | default: |
| 197 | break; |
| 198 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 199 | } |
| 200 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 201 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
| 202 | u64 qmask) |
| 203 | { |
| 204 | u32 mask; |
| 205 | |
| 206 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 207 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 208 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
| 209 | } else { |
| 210 | mask = (qmask & 0xFFFFFFFF); |
| 211 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 212 | mask = (qmask >> 32); |
| 213 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
| 214 | } |
| 215 | } |
| 216 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 217 | 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] | 218 | struct ixgbe_tx_buffer |
| 219 | *tx_buffer_info) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 220 | { |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 221 | if (tx_buffer_info->dma) { |
| 222 | if (tx_buffer_info->mapped_as_page) |
| 223 | pci_unmap_page(adapter->pdev, |
| 224 | tx_buffer_info->dma, |
| 225 | tx_buffer_info->length, |
| 226 | PCI_DMA_TODEVICE); |
| 227 | else |
| 228 | pci_unmap_single(adapter->pdev, |
| 229 | tx_buffer_info->dma, |
| 230 | tx_buffer_info->length, |
| 231 | PCI_DMA_TODEVICE); |
| 232 | tx_buffer_info->dma = 0; |
| 233 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 234 | if (tx_buffer_info->skb) { |
| 235 | dev_kfree_skb_any(tx_buffer_info->skb); |
| 236 | tx_buffer_info->skb = NULL; |
| 237 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 238 | tx_buffer_info->time_stamp = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 239 | /* tx_buffer_info must be completely set up in the transmit path */ |
| 240 | } |
| 241 | |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 242 | /** |
| 243 | * ixgbe_tx_is_paused - check if the tx ring is paused |
| 244 | * @adapter: the ixgbe adapter |
| 245 | * @tx_ring: the corresponding tx_ring |
| 246 | * |
| 247 | * If not in DCB mode, checks TFCS.TXOFF, otherwise, find out the |
| 248 | * corresponding TC of this tx_ring when checking TFCS. |
| 249 | * |
| 250 | * Returns : true if paused |
| 251 | */ |
| 252 | static inline bool ixgbe_tx_is_paused(struct ixgbe_adapter *adapter, |
| 253 | struct ixgbe_ring *tx_ring) |
| 254 | { |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 255 | u32 txoff = IXGBE_TFCS_TXOFF; |
| 256 | |
| 257 | #ifdef CONFIG_IXGBE_DCB |
| 258 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Jaswinder Singh Rajput | 30b7683 | 2009-11-20 04:02:27 +0000 | [diff] [blame] | 259 | int tc; |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 260 | int reg_idx = tx_ring->reg_idx; |
| 261 | int dcb_i = adapter->ring_feature[RING_F_DCB].indices; |
| 262 | |
| 263 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 264 | tc = reg_idx >> 2; |
| 265 | txoff = IXGBE_TFCS_TXOFF0; |
| 266 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 267 | tc = 0; |
| 268 | txoff = IXGBE_TFCS_TXOFF; |
| 269 | if (dcb_i == 8) { |
| 270 | /* TC0, TC1 */ |
| 271 | tc = reg_idx >> 5; |
| 272 | if (tc == 2) /* TC2, TC3 */ |
| 273 | tc += (reg_idx - 64) >> 4; |
| 274 | else if (tc == 3) /* TC4, TC5, TC6, TC7 */ |
| 275 | tc += 1 + ((reg_idx - 96) >> 3); |
| 276 | } else if (dcb_i == 4) { |
| 277 | /* TC0, TC1 */ |
| 278 | tc = reg_idx >> 6; |
| 279 | if (tc == 1) { |
| 280 | tc += (reg_idx - 64) >> 5; |
| 281 | if (tc == 2) /* TC2, TC3 */ |
| 282 | tc += (reg_idx - 96) >> 4; |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | txoff <<= tc; |
| 287 | } |
| 288 | #endif |
| 289 | return IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & txoff; |
| 290 | } |
| 291 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 292 | static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 293 | struct ixgbe_ring *tx_ring, |
| 294 | unsigned int eop) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 295 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 296 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 297 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 298 | /* Detect a transmit hang in hardware, this serializes the |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 299 | * check with the clearing of time_stamp and movement of eop */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 300 | adapter->detect_tx_hung = false; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 301 | if (tx_ring->tx_buffer_info[eop].time_stamp && |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 302 | time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) && |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 303 | !ixgbe_tx_is_paused(adapter, tx_ring)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 304 | /* detected Tx unit hang */ |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 305 | union ixgbe_adv_tx_desc *tx_desc; |
| 306 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 307 | DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n" |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 308 | " Tx Queue <%d>\n" |
| 309 | " TDH, TDT <%x>, <%x>\n" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 310 | " next_to_use <%x>\n" |
| 311 | " next_to_clean <%x>\n" |
| 312 | "tx_buffer_info[next_to_clean]\n" |
| 313 | " time_stamp <%lx>\n" |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 314 | " jiffies <%lx>\n", |
| 315 | tx_ring->queue_index, |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 316 | IXGBE_READ_REG(hw, tx_ring->head), |
| 317 | IXGBE_READ_REG(hw, tx_ring->tail), |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 318 | tx_ring->next_to_use, eop, |
| 319 | tx_ring->tx_buffer_info[eop].time_stamp, jiffies); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 320 | return true; |
| 321 | } |
| 322 | |
| 323 | return false; |
| 324 | } |
| 325 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 326 | #define IXGBE_MAX_TXD_PWR 14 |
| 327 | #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 328 | |
| 329 | /* Tx Descriptors needed, worst case */ |
| 330 | #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \ |
| 331 | (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0)) |
| 332 | #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] | 333 | MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 334 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 335 | static void ixgbe_tx_timeout(struct net_device *netdev); |
| 336 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 337 | /** |
| 338 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 339 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 340 | * @tx_ring: tx ring to clean |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 341 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 342 | static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 343 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 344 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 345 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 346 | struct net_device *netdev = adapter->netdev; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 347 | union ixgbe_adv_tx_desc *tx_desc, *eop_desc; |
| 348 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 349 | unsigned int i, eop, count = 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 350 | unsigned int total_bytes = 0, total_packets = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 351 | |
| 352 | i = tx_ring->next_to_clean; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 353 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
| 354 | eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
| 355 | |
| 356 | while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) && |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 357 | (count < tx_ring->work_limit)) { |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 358 | bool cleaned = false; |
| 359 | for ( ; !cleaned; count++) { |
| 360 | struct sk_buff *skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 361 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); |
| 362 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 363 | cleaned = (i == eop); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 364 | skb = tx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 365 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 366 | if (cleaned && skb) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 367 | unsigned int segs, bytecount; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 368 | unsigned int hlen = skb_headlen(skb); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 369 | |
| 370 | /* gso_segs is currently only valid for tcp */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 371 | segs = skb_shinfo(skb)->gso_segs ?: 1; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 372 | #ifdef IXGBE_FCOE |
| 373 | /* adjust for FCoE Sequence Offload */ |
| 374 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 375 | && (skb->protocol == htons(ETH_P_FCOE)) && |
| 376 | skb_is_gso(skb)) { |
| 377 | hlen = skb_transport_offset(skb) + |
| 378 | sizeof(struct fc_frame_header) + |
| 379 | sizeof(struct fcoe_crc_eof); |
| 380 | segs = DIV_ROUND_UP(skb->len - hlen, |
| 381 | skb_shinfo(skb)->gso_size); |
| 382 | } |
| 383 | #endif /* IXGBE_FCOE */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 384 | /* multiply data chunks by size of headers */ |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 385 | bytecount = ((segs - 1) * hlen) + skb->len; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 386 | total_packets += segs; |
| 387 | total_bytes += bytecount; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 388 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 389 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 390 | ixgbe_unmap_and_free_tx_resource(adapter, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 391 | tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 392 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 393 | tx_desc->wb.status = 0; |
| 394 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 395 | i++; |
| 396 | if (i == tx_ring->count) |
| 397 | i = 0; |
| 398 | } |
| 399 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 400 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
| 401 | eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
| 402 | } |
| 403 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 404 | tx_ring->next_to_clean = i; |
| 405 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 406 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 407 | if (unlikely(count && netif_carrier_ok(netdev) && |
| 408 | (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 409 | /* Make sure that anybody stopping the queue after this |
| 410 | * sees the new next_to_clean. |
| 411 | */ |
| 412 | smp_mb(); |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 413 | if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) && |
| 414 | !test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 415 | netif_wake_subqueue(netdev, tx_ring->queue_index); |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame^] | 416 | ++tx_ring->restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 417 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 418 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 419 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 420 | if (adapter->detect_tx_hung) { |
| 421 | if (ixgbe_check_tx_hang(adapter, tx_ring, i)) { |
| 422 | /* schedule immediate reset if we believe we hung */ |
| 423 | DPRINTK(PROBE, INFO, |
| 424 | "tx hang %d detected, resetting adapter\n", |
| 425 | adapter->tx_timeout_count + 1); |
| 426 | ixgbe_tx_timeout(adapter->netdev); |
| 427 | } |
| 428 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 429 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 430 | /* re-arm the interrupt */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 431 | if (count >= tx_ring->work_limit) |
| 432 | ixgbe_irq_rearm_queues(adapter, ((u64)1 << q_vector->v_idx)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 433 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 434 | tx_ring->total_bytes += total_bytes; |
| 435 | tx_ring->total_packets += total_packets; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 436 | tx_ring->stats.packets += total_packets; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 437 | tx_ring->stats.bytes += total_bytes; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 438 | netdev->stats.tx_bytes += total_bytes; |
| 439 | netdev->stats.tx_packets += total_packets; |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 440 | return (count < tx_ring->work_limit); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 443 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 444 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 445 | struct ixgbe_ring *rx_ring) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 446 | { |
| 447 | u32 rxctrl; |
| 448 | int cpu = get_cpu(); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 449 | int q = rx_ring - adapter->rx_ring; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 450 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 451 | if (rx_ring->cpu != cpu) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 452 | rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 453 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 454 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK; |
| 455 | rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 456 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 457 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599; |
| 458 | rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 459 | IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599); |
| 460 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 461 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 462 | rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN; |
Don Skidmore | 15005a3 | 2009-01-19 16:54:13 -0800 | [diff] [blame] | 463 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN); |
| 464 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 465 | IXGBE_DCA_RXCTRL_DESC_HSRO_EN); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 466 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 467 | rx_ring->cpu = cpu; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 468 | } |
| 469 | put_cpu(); |
| 470 | } |
| 471 | |
| 472 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 473 | struct ixgbe_ring *tx_ring) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 474 | { |
| 475 | u32 txctrl; |
| 476 | int cpu = get_cpu(); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 477 | int q = tx_ring - adapter->tx_ring; |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 478 | struct ixgbe_hw *hw = &adapter->hw; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 479 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 480 | if (tx_ring->cpu != cpu) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 481 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 482 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 483 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK; |
| 484 | txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 485 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 486 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(q), txctrl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 487 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 488 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 489 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599; |
| 490 | txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 491 | IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599); |
| 492 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 493 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(q), txctrl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 494 | } |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 495 | tx_ring->cpu = cpu; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 496 | } |
| 497 | put_cpu(); |
| 498 | } |
| 499 | |
| 500 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 501 | { |
| 502 | int i; |
| 503 | |
| 504 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 505 | return; |
| 506 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 507 | /* always use CB2 mode, difference is masked in the CB driver */ |
| 508 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); |
| 509 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 510 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 511 | adapter->tx_ring[i].cpu = -1; |
| 512 | ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]); |
| 513 | } |
| 514 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 515 | adapter->rx_ring[i].cpu = -1; |
| 516 | ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]); |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 521 | { |
| 522 | struct net_device *netdev = dev_get_drvdata(dev); |
| 523 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 524 | unsigned long event = *(unsigned long *)data; |
| 525 | |
| 526 | switch (event) { |
| 527 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 528 | /* if we're already enabled, don't do it again */ |
| 529 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 530 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 531 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 532 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 533 | ixgbe_setup_dca(adapter); |
| 534 | break; |
| 535 | } |
| 536 | /* Fall Through since DCA is disabled. */ |
| 537 | case DCA_PROVIDER_REMOVE: |
| 538 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 539 | dca_remove_requester(dev); |
| 540 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 541 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 542 | } |
| 543 | break; |
| 544 | } |
| 545 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 546 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 547 | } |
| 548 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 549 | #endif /* CONFIG_IXGBE_DCA */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 550 | /** |
| 551 | * ixgbe_receive_skb - Send a completed packet up the stack |
| 552 | * @adapter: board private structure |
| 553 | * @skb: packet to send up |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 554 | * @status: hardware indication of status of receive |
| 555 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
| 556 | * @rx_desc: rx descriptor |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 557 | **/ |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 558 | static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 559 | struct sk_buff *skb, u8 status, |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 560 | struct ixgbe_ring *ring, |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 561 | union ixgbe_adv_rx_desc *rx_desc) |
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 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 564 | struct napi_struct *napi = &q_vector->napi; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 565 | bool is_vlan = (status & IXGBE_RXD_STAT_VP); |
| 566 | u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 567 | |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 568 | skb_record_rx_queue(skb, ring->queue_index); |
Alexander Duyck | 182ff8d | 2009-04-27 22:35:33 +0000 | [diff] [blame] | 569 | if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) { |
Lucy Liu | 8a62bab | 2009-08-13 14:09:38 +0000 | [diff] [blame] | 570 | if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK)) |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 571 | vlan_gro_receive(napi, adapter->vlgrp, tag, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 572 | else |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 573 | napi_gro_receive(napi, skb); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 574 | } else { |
Lucy Liu | 8a62bab | 2009-08-13 14:09:38 +0000 | [diff] [blame] | 575 | if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK)) |
Alexander Duyck | 182ff8d | 2009-04-27 22:35:33 +0000 | [diff] [blame] | 576 | vlan_hwaccel_rx(skb, adapter->vlgrp, tag); |
| 577 | else |
| 578 | netif_rx(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 582 | /** |
| 583 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
| 584 | * @adapter: address of board private structure |
| 585 | * @status_err: hardware indication of status of receive |
| 586 | * @skb: skb currently being received and modified |
| 587 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 588 | static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 589 | union ixgbe_adv_rx_desc *rx_desc, |
| 590 | struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 591 | { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 592 | u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 593 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 594 | skb->ip_summed = CHECKSUM_NONE; |
| 595 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 596 | /* Rx csum disabled */ |
| 597 | if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 598 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 599 | |
| 600 | /* if IP and error */ |
| 601 | if ((status_err & IXGBE_RXD_STAT_IPCS) && |
| 602 | (status_err & IXGBE_RXDADV_ERR_IPE)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 603 | adapter->hw_csum_rx_error++; |
| 604 | return; |
| 605 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 606 | |
| 607 | if (!(status_err & IXGBE_RXD_STAT_L4CS)) |
| 608 | return; |
| 609 | |
| 610 | if (status_err & IXGBE_RXDADV_ERR_TCPE) { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 611 | u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 612 | |
| 613 | /* |
| 614 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 615 | * checksum errors. |
| 616 | */ |
| 617 | if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) && |
| 618 | (adapter->hw.mac.type == ixgbe_mac_82599EB)) |
| 619 | return; |
| 620 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 621 | adapter->hw_csum_rx_error++; |
| 622 | return; |
| 623 | } |
| 624 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 625 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 626 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 627 | } |
| 628 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 629 | static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw, |
| 630 | struct ixgbe_ring *rx_ring, u32 val) |
| 631 | { |
| 632 | /* |
| 633 | * Force memory writes to complete before letting h/w |
| 634 | * know there are new descriptors to fetch. (Only |
| 635 | * applicable for weak-ordered memory model archs, |
| 636 | * such as IA-64). |
| 637 | */ |
| 638 | wmb(); |
| 639 | IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val); |
| 640 | } |
| 641 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 642 | /** |
| 643 | * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split |
| 644 | * @adapter: address of board private structure |
| 645 | **/ |
| 646 | static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 647 | struct ixgbe_ring *rx_ring, |
| 648 | int cleaned_count) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 649 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 650 | struct pci_dev *pdev = adapter->pdev; |
| 651 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 652 | struct ixgbe_rx_buffer *bi; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 653 | unsigned int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 654 | |
| 655 | i = rx_ring->next_to_use; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 656 | bi = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 657 | |
| 658 | while (cleaned_count--) { |
| 659 | rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 660 | |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 661 | if (!bi->page_dma && |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 662 | (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 663 | if (!bi->page) { |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 664 | bi->page = alloc_page(GFP_ATOMIC); |
| 665 | if (!bi->page) { |
| 666 | adapter->alloc_rx_page_failed++; |
| 667 | goto no_buffers; |
| 668 | } |
| 669 | bi->page_offset = 0; |
| 670 | } else { |
| 671 | /* use a half page if we're re-using */ |
| 672 | bi->page_offset ^= (PAGE_SIZE / 2); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 673 | } |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 674 | |
| 675 | bi->page_dma = pci_map_page(pdev, bi->page, |
| 676 | bi->page_offset, |
| 677 | (PAGE_SIZE / 2), |
| 678 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 679 | } |
| 680 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 681 | if (!bi->skb) { |
Jesse Brandeburg | 5ecc361 | 2008-12-15 01:00:57 -0800 | [diff] [blame] | 682 | struct sk_buff *skb; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame^] | 683 | /* netdev_alloc_skb reserves 32 bytes up front!! */ |
| 684 | uint bufsz = rx_ring->rx_buf_len + SMP_CACHE_BYTES; |
| 685 | skb = netdev_alloc_skb(adapter->netdev, bufsz); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 686 | |
| 687 | if (!skb) { |
| 688 | adapter->alloc_rx_buff_failed++; |
| 689 | goto no_buffers; |
| 690 | } |
| 691 | |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame^] | 692 | /* advance the data pointer to the next cache line */ |
| 693 | skb_reserve(skb, (PTR_ALIGN(skb->data, SMP_CACHE_BYTES) |
| 694 | - skb->data)); |
| 695 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 696 | bi->skb = skb; |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 697 | bi->dma = pci_map_single(pdev, skb->data, |
| 698 | rx_ring->rx_buf_len, |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 699 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 700 | } |
| 701 | /* Refresh the desc even if buffer_addrs didn't change because |
| 702 | * each write-back erases this info. */ |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 703 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 704 | rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma); |
| 705 | rx_desc->read.hdr_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 706 | } else { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 707 | rx_desc->read.pkt_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | i++; |
| 711 | if (i == rx_ring->count) |
| 712 | i = 0; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 713 | bi = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 714 | } |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 715 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 716 | no_buffers: |
| 717 | if (rx_ring->next_to_use != i) { |
| 718 | rx_ring->next_to_use = i; |
| 719 | if (i-- == 0) |
| 720 | i = (rx_ring->count - 1); |
| 721 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 722 | ixgbe_release_rx_desc(&adapter->hw, rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 723 | } |
| 724 | } |
| 725 | |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 726 | static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc) |
| 727 | { |
| 728 | return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info; |
| 729 | } |
| 730 | |
| 731 | static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc) |
| 732 | { |
| 733 | return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 734 | } |
| 735 | |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 736 | static inline u32 ixgbe_get_rsc_count(union ixgbe_adv_rx_desc *rx_desc) |
| 737 | { |
| 738 | return (le32_to_cpu(rx_desc->wb.lower.lo_dword.data) & |
| 739 | IXGBE_RXDADV_RSCCNT_MASK) >> |
| 740 | IXGBE_RXDADV_RSCCNT_SHIFT; |
| 741 | } |
| 742 | |
| 743 | /** |
| 744 | * ixgbe_transform_rsc_queue - change rsc queue into a full packet |
| 745 | * @skb: pointer to the last skb in the rsc queue |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 746 | * @count: pointer to number of packets coalesced in this context |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 747 | * |
| 748 | * This function changes a queue full of hw rsc buffers into a completed |
| 749 | * packet. It uses the ->prev pointers to find the first packet and then |
| 750 | * turns it into the frag list owner. |
| 751 | **/ |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 752 | static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb, |
| 753 | u64 *count) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 754 | { |
| 755 | unsigned int frag_list_size = 0; |
| 756 | |
| 757 | while (skb->prev) { |
| 758 | struct sk_buff *prev = skb->prev; |
| 759 | frag_list_size += skb->len; |
| 760 | skb->prev = NULL; |
| 761 | skb = prev; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 762 | *count += 1; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | skb_shinfo(skb)->frag_list = skb->next; |
| 766 | skb->next = NULL; |
| 767 | skb->len += frag_list_size; |
| 768 | skb->data_len += frag_list_size; |
| 769 | skb->truesize += frag_list_size; |
| 770 | return skb; |
| 771 | } |
| 772 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 773 | 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] | 774 | struct ixgbe_ring *rx_ring, |
| 775 | int *work_done, int work_to_do) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 776 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 777 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 778 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 779 | struct pci_dev *pdev = adapter->pdev; |
| 780 | union ixgbe_adv_rx_desc *rx_desc, *next_rxd; |
| 781 | struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer; |
| 782 | struct sk_buff *skb; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 783 | unsigned int i, rsc_count = 0; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 784 | u32 len, staterr; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 785 | u16 hdr_info; |
| 786 | bool cleaned = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 787 | int cleaned_count = 0; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 788 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 789 | #ifdef IXGBE_FCOE |
| 790 | int ddp_bytes = 0; |
| 791 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 792 | |
| 793 | i = rx_ring->next_to_clean; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 794 | rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 795 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 796 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 797 | |
| 798 | while (staterr & IXGBE_RXD_STAT_DD) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 799 | u32 upper_len = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 800 | if (*work_done >= work_to_do) |
| 801 | break; |
| 802 | (*work_done)++; |
| 803 | |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 804 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 805 | hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc)); |
| 806 | len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >> |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 807 | IXGBE_RXDADV_HDRBUFLEN_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 808 | if (len > IXGBE_RX_HDR_SIZE) |
| 809 | len = IXGBE_RX_HDR_SIZE; |
| 810 | upper_len = le16_to_cpu(rx_desc->wb.upper.length); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 811 | } else { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 812 | len = le16_to_cpu(rx_desc->wb.upper.length); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 813 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 814 | |
| 815 | cleaned = true; |
| 816 | skb = rx_buffer_info->skb; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame^] | 817 | prefetch(skb->data); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 818 | rx_buffer_info->skb = NULL; |
| 819 | |
Alexander Duyck | 21fa4e6 | 2009-06-04 15:59:49 +0000 | [diff] [blame] | 820 | if (rx_buffer_info->dma) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 821 | pci_unmap_single(pdev, rx_buffer_info->dma, |
Jesse Brandeburg | 5ecc361 | 2008-12-15 01:00:57 -0800 | [diff] [blame] | 822 | rx_ring->rx_buf_len, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 823 | PCI_DMA_FROMDEVICE); |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 824 | rx_buffer_info->dma = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 825 | skb_put(skb, len); |
| 826 | } |
| 827 | |
| 828 | if (upper_len) { |
| 829 | pci_unmap_page(pdev, rx_buffer_info->page_dma, |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 830 | PAGE_SIZE / 2, PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 831 | rx_buffer_info->page_dma = 0; |
| 832 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 833 | rx_buffer_info->page, |
| 834 | rx_buffer_info->page_offset, |
| 835 | upper_len); |
| 836 | |
| 837 | if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) || |
| 838 | (page_count(rx_buffer_info->page) != 1)) |
| 839 | rx_buffer_info->page = NULL; |
| 840 | else |
| 841 | get_page(rx_buffer_info->page); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 842 | |
| 843 | skb->len += upper_len; |
| 844 | skb->data_len += upper_len; |
| 845 | skb->truesize += upper_len; |
| 846 | } |
| 847 | |
| 848 | i++; |
| 849 | if (i == rx_ring->count) |
| 850 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 851 | |
| 852 | next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 853 | prefetch(next_rxd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 854 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 855 | |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 856 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 857 | rsc_count = ixgbe_get_rsc_count(rx_desc); |
| 858 | |
| 859 | if (rsc_count) { |
| 860 | u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >> |
| 861 | IXGBE_RXDADV_NEXTP_SHIFT; |
| 862 | next_buffer = &rx_ring->rx_buffer_info[nextp]; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 863 | } else { |
| 864 | next_buffer = &rx_ring->rx_buffer_info[i]; |
| 865 | } |
| 866 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 867 | if (staterr & IXGBE_RXD_STAT_EOP) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 868 | if (skb->prev) |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 869 | skb = ixgbe_transform_rsc_queue(skb, &(rx_ring->rsc_count)); |
| 870 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
| 871 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) |
| 872 | rx_ring->rsc_count += skb_shinfo(skb)->nr_frags; |
| 873 | else |
| 874 | rx_ring->rsc_count++; |
| 875 | rx_ring->rsc_flush++; |
| 876 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 877 | rx_ring->stats.packets++; |
| 878 | rx_ring->stats.bytes += skb->len; |
| 879 | } else { |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 880 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 881 | rx_buffer_info->skb = next_buffer->skb; |
| 882 | rx_buffer_info->dma = next_buffer->dma; |
| 883 | next_buffer->skb = skb; |
| 884 | next_buffer->dma = 0; |
| 885 | } else { |
| 886 | skb->next = next_buffer->skb; |
| 887 | skb->next->prev = skb; |
| 888 | } |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame^] | 889 | rx_ring->non_eop_descs++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 890 | goto next_desc; |
| 891 | } |
| 892 | |
| 893 | if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) { |
| 894 | dev_kfree_skb_irq(skb); |
| 895 | goto next_desc; |
| 896 | } |
| 897 | |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 898 | ixgbe_rx_checksum(adapter, rx_desc, skb); |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 899 | |
| 900 | /* probably a little skewed due to removing CRC */ |
| 901 | total_rx_bytes += skb->len; |
| 902 | total_rx_packets++; |
| 903 | |
Jesse Brandeburg | 74ce8dd | 2008-09-11 20:03:23 -0700 | [diff] [blame] | 904 | skb->protocol = eth_type_trans(skb, adapter->netdev); |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 905 | #ifdef IXGBE_FCOE |
| 906 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 907 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 908 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
| 909 | if (!ddp_bytes) |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 910 | goto next_desc; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 911 | } |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 912 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 913 | ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 914 | |
| 915 | next_desc: |
| 916 | rx_desc->wb.upper.status_error = 0; |
| 917 | |
| 918 | /* return some buffers to hardware, one at a time is too slow */ |
| 919 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 920 | ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count); |
| 921 | cleaned_count = 0; |
| 922 | } |
| 923 | |
| 924 | /* use prefetched values */ |
| 925 | rx_desc = next_rxd; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 926 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 927 | |
| 928 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 929 | } |
| 930 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 931 | rx_ring->next_to_clean = i; |
| 932 | cleaned_count = IXGBE_DESC_UNUSED(rx_ring); |
| 933 | |
| 934 | if (cleaned_count) |
| 935 | ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count); |
| 936 | |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 937 | #ifdef IXGBE_FCOE |
| 938 | /* include DDPed FCoE data */ |
| 939 | if (ddp_bytes > 0) { |
| 940 | unsigned int mss; |
| 941 | |
| 942 | mss = adapter->netdev->mtu - sizeof(struct fcoe_hdr) - |
| 943 | sizeof(struct fc_frame_header) - |
| 944 | sizeof(struct fcoe_crc_eof); |
| 945 | if (mss > 512) |
| 946 | mss &= ~511; |
| 947 | total_rx_bytes += ddp_bytes; |
| 948 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss); |
| 949 | } |
| 950 | #endif /* IXGBE_FCOE */ |
| 951 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 952 | rx_ring->total_packets += total_rx_packets; |
| 953 | rx_ring->total_bytes += total_rx_bytes; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 954 | netdev->stats.rx_bytes += total_rx_bytes; |
| 955 | netdev->stats.rx_packets += total_rx_packets; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 956 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 957 | return cleaned; |
| 958 | } |
| 959 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 960 | static int ixgbe_clean_rxonly(struct napi_struct *, int); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 961 | /** |
| 962 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 963 | * @adapter: board private structure |
| 964 | * |
| 965 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 966 | * interrupts. |
| 967 | **/ |
| 968 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 969 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 970 | struct ixgbe_q_vector *q_vector; |
| 971 | int i, j, q_vectors, v_idx, r_idx; |
| 972 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 973 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 974 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 975 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 976 | /* |
| 977 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 978 | * corresponding register. |
| 979 | */ |
| 980 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 981 | q_vector = adapter->q_vector[v_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 982 | /* XXX for_each_bit(...) */ |
| 983 | r_idx = find_first_bit(q_vector->rxr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 984 | adapter->num_rx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 985 | |
| 986 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 987 | j = adapter->rx_ring[r_idx].reg_idx; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 988 | ixgbe_set_ivar(adapter, 0, j, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 989 | r_idx = find_next_bit(q_vector->rxr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 990 | adapter->num_rx_queues, |
| 991 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 992 | } |
| 993 | r_idx = find_first_bit(q_vector->txr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 994 | adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 995 | |
| 996 | for (i = 0; i < q_vector->txr_count; i++) { |
| 997 | j = adapter->tx_ring[r_idx].reg_idx; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 998 | ixgbe_set_ivar(adapter, 1, j, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 999 | r_idx = find_next_bit(q_vector->txr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1000 | adapter->num_tx_queues, |
| 1001 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1002 | } |
| 1003 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1004 | if (q_vector->txr_count && !q_vector->rxr_count) |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1005 | /* tx only */ |
| 1006 | q_vector->eitr = adapter->tx_eitr_param; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1007 | else if (q_vector->rxr_count) |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1008 | /* rx or mixed */ |
| 1009 | q_vector->eitr = adapter->rx_eitr_param; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1010 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1011 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1014 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 1015 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
| 1016 | v_idx); |
| 1017 | else if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 1018 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1019 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1020 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 1021 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1022 | mask = IXGBE_EIMS_ENABLE_MASK; |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 1023 | mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1024 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1027 | enum latency_range { |
| 1028 | lowest_latency = 0, |
| 1029 | low_latency = 1, |
| 1030 | bulk_latency = 2, |
| 1031 | latency_invalid = 255 |
| 1032 | }; |
| 1033 | |
| 1034 | /** |
| 1035 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
| 1036 | * @adapter: pointer to adapter |
| 1037 | * @eitr: eitr setting (ints per sec) to give last timeslice |
| 1038 | * @itr_setting: current throttle rate in ints/second |
| 1039 | * @packets: the number of packets during this measurement interval |
| 1040 | * @bytes: the number of bytes during this measurement interval |
| 1041 | * |
| 1042 | * Stores a new ITR value based on packets and byte |
| 1043 | * counts during the last interrupt. The advantage of per interrupt |
| 1044 | * computation is faster updates and more accurate ITR for the current |
| 1045 | * traffic pattern. Constants in this function were computed |
| 1046 | * based on theoretical maximum wire speed and thresholds were set based |
| 1047 | * on testing data as well as attempting to minimize response time |
| 1048 | * while increasing bulk throughput. |
| 1049 | * this functionality is controlled by the InterruptThrottleRate module |
| 1050 | * parameter (see ixgbe_param.c) |
| 1051 | **/ |
| 1052 | static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1053 | u32 eitr, u8 itr_setting, |
| 1054 | int packets, int bytes) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1055 | { |
| 1056 | unsigned int retval = itr_setting; |
| 1057 | u32 timepassed_us; |
| 1058 | u64 bytes_perint; |
| 1059 | |
| 1060 | if (packets == 0) |
| 1061 | goto update_itr_done; |
| 1062 | |
| 1063 | |
| 1064 | /* simple throttlerate management |
| 1065 | * 0-20MB/s lowest (100000 ints/s) |
| 1066 | * 20-100MB/s low (20000 ints/s) |
| 1067 | * 100-1249MB/s bulk (8000 ints/s) |
| 1068 | */ |
| 1069 | /* what was last interrupt timeslice? */ |
| 1070 | timepassed_us = 1000000/eitr; |
| 1071 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 1072 | |
| 1073 | switch (itr_setting) { |
| 1074 | case lowest_latency: |
| 1075 | if (bytes_perint > adapter->eitr_low) |
| 1076 | retval = low_latency; |
| 1077 | break; |
| 1078 | case low_latency: |
| 1079 | if (bytes_perint > adapter->eitr_high) |
| 1080 | retval = bulk_latency; |
| 1081 | else if (bytes_perint <= adapter->eitr_low) |
| 1082 | retval = lowest_latency; |
| 1083 | break; |
| 1084 | case bulk_latency: |
| 1085 | if (bytes_perint <= adapter->eitr_high) |
| 1086 | retval = low_latency; |
| 1087 | break; |
| 1088 | } |
| 1089 | |
| 1090 | update_itr_done: |
| 1091 | return retval; |
| 1092 | } |
| 1093 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1094 | /** |
| 1095 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1096 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1097 | * |
| 1098 | * This function is made to be called by ethtool and by the driver |
| 1099 | * when it needs to update EITR registers at runtime. Hardware |
| 1100 | * specific quirks/differences are taken care of here. |
| 1101 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1102 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1103 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1104 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1105 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1106 | int v_idx = q_vector->v_idx; |
| 1107 | u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr); |
| 1108 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1109 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1110 | /* must write high and low 16 bits to reset counter */ |
| 1111 | itr_reg |= (itr_reg << 16); |
| 1112 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 1113 | /* |
| 1114 | * set the WDIS bit to not clear the timer bits and cause an |
| 1115 | * immediate assertion of the interrupt |
| 1116 | */ |
| 1117 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
| 1118 | } |
| 1119 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 1120 | } |
| 1121 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1122 | static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector) |
| 1123 | { |
| 1124 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1125 | u32 new_itr; |
| 1126 | u8 current_itr, ret_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1127 | int i, r_idx; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1128 | struct ixgbe_ring *rx_ring, *tx_ring; |
| 1129 | |
| 1130 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1131 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1132 | tx_ring = &(adapter->tx_ring[r_idx]); |
| 1133 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1134 | q_vector->tx_itr, |
| 1135 | tx_ring->total_packets, |
| 1136 | tx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1137 | /* if the result for this queue would decrease interrupt |
| 1138 | * rate for this vector then use that result */ |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1139 | q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ? |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1140 | q_vector->tx_itr - 1 : ret_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1141 | 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] | 1142 | r_idx + 1); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1146 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1147 | rx_ring = &(adapter->rx_ring[r_idx]); |
| 1148 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1149 | q_vector->rx_itr, |
| 1150 | rx_ring->total_packets, |
| 1151 | rx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1152 | /* if the result for this queue would decrease interrupt |
| 1153 | * rate for this vector then use that result */ |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1154 | q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ? |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1155 | q_vector->rx_itr - 1 : ret_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1156 | 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] | 1157 | r_idx + 1); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1158 | } |
| 1159 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1160 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1161 | |
| 1162 | switch (current_itr) { |
| 1163 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1164 | case lowest_latency: |
| 1165 | new_itr = 100000; |
| 1166 | break; |
| 1167 | case low_latency: |
| 1168 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 1169 | break; |
| 1170 | case bulk_latency: |
| 1171 | default: |
| 1172 | new_itr = 8000; |
| 1173 | break; |
| 1174 | } |
| 1175 | |
| 1176 | if (new_itr != q_vector->eitr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1177 | /* do an exponential smoothing */ |
| 1178 | new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1179 | |
| 1180 | /* save the algorithm value here, not the smoothed one */ |
| 1181 | q_vector->eitr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1182 | |
| 1183 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | return; |
| 1187 | } |
| 1188 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1189 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 1190 | { |
| 1191 | struct ixgbe_hw *hw = &adapter->hw; |
| 1192 | |
| 1193 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
| 1194 | (eicr & IXGBE_EICR_GPI_SDP1)) { |
| 1195 | DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n"); |
| 1196 | /* write to clear the interrupt */ |
| 1197 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 1198 | } |
| 1199 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1200 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1201 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 1202 | { |
| 1203 | struct ixgbe_hw *hw = &adapter->hw; |
| 1204 | |
| 1205 | if (eicr & IXGBE_EICR_GPI_SDP1) { |
| 1206 | /* Clear the interrupt */ |
| 1207 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 1208 | schedule_work(&adapter->multispeed_fiber_task); |
| 1209 | } else if (eicr & IXGBE_EICR_GPI_SDP2) { |
| 1210 | /* Clear the interrupt */ |
| 1211 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2); |
| 1212 | schedule_work(&adapter->sfp_config_module_task); |
| 1213 | } else { |
| 1214 | /* Interrupt isn't for us... */ |
| 1215 | return; |
| 1216 | } |
| 1217 | } |
| 1218 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1219 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 1220 | { |
| 1221 | struct ixgbe_hw *hw = &adapter->hw; |
| 1222 | |
| 1223 | adapter->lsc_int++; |
| 1224 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 1225 | adapter->link_check_timeout = jiffies; |
| 1226 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1227 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
Nelson, Shannon | 8a0717f | 2009-11-12 18:47:11 +0000 | [diff] [blame] | 1228 | IXGBE_WRITE_FLUSH(hw); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1229 | schedule_work(&adapter->watchdog_task); |
| 1230 | } |
| 1231 | } |
| 1232 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1233 | static irqreturn_t ixgbe_msix_lsc(int irq, void *data) |
| 1234 | { |
| 1235 | struct net_device *netdev = data; |
| 1236 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1237 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 1238 | u32 eicr; |
| 1239 | |
| 1240 | /* |
| 1241 | * Workaround for Silicon errata. Use clear-by-write instead |
| 1242 | * of clear-by-read. Reading with EICS will return the |
| 1243 | * interrupt causes without clearing, which later be done |
| 1244 | * with the write to EICR. |
| 1245 | */ |
| 1246 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
| 1247 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1248 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1249 | if (eicr & IXGBE_EICR_LSC) |
| 1250 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1251 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1252 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 1253 | ixgbe_check_fan_failure(adapter, eicr); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1254 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1255 | if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1256 | ixgbe_check_sfp_event(adapter, eicr); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1257 | |
| 1258 | /* Handle Flow Director Full threshold interrupt */ |
| 1259 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
| 1260 | int i; |
| 1261 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR); |
| 1262 | /* Disable transmits before FDIR Re-initialization */ |
| 1263 | netif_tx_stop_all_queues(netdev); |
| 1264 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 1265 | struct ixgbe_ring *tx_ring = |
| 1266 | &adapter->tx_ring[i]; |
| 1267 | if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE, |
| 1268 | &tx_ring->reinit_state)) |
| 1269 | schedule_work(&adapter->fdir_reinit_task); |
| 1270 | } |
| 1271 | } |
| 1272 | } |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1273 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1274 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1275 | |
| 1276 | return IRQ_HANDLED; |
| 1277 | } |
| 1278 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1279 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 1280 | u64 qmask) |
| 1281 | { |
| 1282 | u32 mask; |
| 1283 | |
| 1284 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1285 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 1286 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 1287 | } else { |
| 1288 | mask = (qmask & 0xFFFFFFFF); |
| 1289 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(0), mask); |
| 1290 | mask = (qmask >> 32); |
| 1291 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask); |
| 1292 | } |
| 1293 | /* skip the flush */ |
| 1294 | } |
| 1295 | |
| 1296 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
| 1297 | u64 qmask) |
| 1298 | { |
| 1299 | u32 mask; |
| 1300 | |
| 1301 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1302 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 1303 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask); |
| 1304 | } else { |
| 1305 | mask = (qmask & 0xFFFFFFFF); |
| 1306 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), mask); |
| 1307 | mask = (qmask >> 32); |
| 1308 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), mask); |
| 1309 | } |
| 1310 | /* skip the flush */ |
| 1311 | } |
| 1312 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1313 | static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data) |
| 1314 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1315 | struct ixgbe_q_vector *q_vector = data; |
| 1316 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1317 | struct ixgbe_ring *tx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1318 | int i, r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1319 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1320 | if (!q_vector->txr_count) |
| 1321 | return IRQ_HANDLED; |
| 1322 | |
| 1323 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1324 | for (i = 0; i < q_vector->txr_count; i++) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1325 | tx_ring = &(adapter->tx_ring[r_idx]); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1326 | tx_ring->total_bytes = 0; |
| 1327 | tx_ring->total_packets = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1328 | 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] | 1329 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1330 | } |
| 1331 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1332 | /* disable interrupts on this vector only */ |
| 1333 | ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 1334 | napi_schedule(&q_vector->napi); |
| 1335 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1336 | return IRQ_HANDLED; |
| 1337 | } |
| 1338 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1339 | /** |
| 1340 | * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues) |
| 1341 | * @irq: unused |
| 1342 | * @data: pointer to our q_vector struct for this interrupt vector |
| 1343 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1344 | static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data) |
| 1345 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1346 | struct ixgbe_q_vector *q_vector = data; |
| 1347 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1348 | struct ixgbe_ring *rx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1349 | int r_idx; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1350 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1351 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1352 | 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] | 1353 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1354 | rx_ring = &(adapter->rx_ring[r_idx]); |
| 1355 | rx_ring->total_bytes = 0; |
| 1356 | rx_ring->total_packets = 0; |
| 1357 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1358 | r_idx + 1); |
| 1359 | } |
| 1360 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1361 | if (!q_vector->rxr_count) |
| 1362 | return IRQ_HANDLED; |
| 1363 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1364 | /* disable interrupts on this vector only */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1365 | ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1366 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1367 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1368 | return IRQ_HANDLED; |
| 1369 | } |
| 1370 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1371 | static irqreturn_t ixgbe_msix_clean_many(int irq, void *data) |
| 1372 | { |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1373 | struct ixgbe_q_vector *q_vector = data; |
| 1374 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1375 | struct ixgbe_ring *ring; |
| 1376 | int r_idx; |
| 1377 | int i; |
| 1378 | |
| 1379 | if (!q_vector->txr_count && !q_vector->rxr_count) |
| 1380 | return IRQ_HANDLED; |
| 1381 | |
| 1382 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1383 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1384 | ring = &(adapter->tx_ring[r_idx]); |
| 1385 | ring->total_bytes = 0; |
| 1386 | ring->total_packets = 0; |
| 1387 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
| 1388 | r_idx + 1); |
| 1389 | } |
| 1390 | |
| 1391 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1392 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1393 | ring = &(adapter->rx_ring[r_idx]); |
| 1394 | ring->total_bytes = 0; |
| 1395 | ring->total_packets = 0; |
| 1396 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1397 | r_idx + 1); |
| 1398 | } |
| 1399 | |
| 1400 | /* disable interrupts on this vector only */ |
| 1401 | ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 1402 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1403 | |
| 1404 | return IRQ_HANDLED; |
| 1405 | } |
| 1406 | |
| 1407 | /** |
| 1408 | * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine |
| 1409 | * @napi: napi struct with our devices info in it |
| 1410 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1411 | * |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1412 | * This function is optimized for cleaning one queue only on a single |
| 1413 | * q_vector!!! |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1414 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1415 | static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget) |
| 1416 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1417 | struct ixgbe_q_vector *q_vector = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1418 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1419 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1420 | struct ixgbe_ring *rx_ring = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1421 | int work_done = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1422 | long r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1423 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1424 | 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] | 1425 | rx_ring = &(adapter->rx_ring[r_idx]); |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1426 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1427 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1428 | ixgbe_update_rx_dca(adapter, rx_ring); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1429 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1430 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1431 | ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1432 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1433 | /* If all Rx work done, exit the polling mode */ |
| 1434 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1435 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1436 | if (adapter->rx_itr_setting & 1) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1437 | ixgbe_set_itr_msix(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1438 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1439 | ixgbe_irq_enable_queues(adapter, |
| 1440 | ((u64)1 << q_vector->v_idx)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1441 | } |
| 1442 | |
| 1443 | return work_done; |
| 1444 | } |
| 1445 | |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1446 | /** |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1447 | * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1448 | * @napi: napi struct with our devices info in it |
| 1449 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1450 | * |
| 1451 | * This function will clean more than one rx queue associated with a |
| 1452 | * q_vector. |
| 1453 | **/ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1454 | static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget) |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1455 | { |
| 1456 | struct ixgbe_q_vector *q_vector = |
| 1457 | container_of(napi, struct ixgbe_q_vector, napi); |
| 1458 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1459 | struct ixgbe_ring *ring = NULL; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1460 | int work_done = 0, i; |
| 1461 | long r_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1462 | bool tx_clean_complete = true; |
| 1463 | |
| 1464 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1465 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1466 | ring = &(adapter->tx_ring[r_idx]); |
| 1467 | #ifdef CONFIG_IXGBE_DCA |
| 1468 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1469 | ixgbe_update_tx_dca(adapter, ring); |
| 1470 | #endif |
| 1471 | tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring); |
| 1472 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
| 1473 | r_idx + 1); |
| 1474 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1475 | |
| 1476 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 1477 | * the budget to go below 1 because we'll exit polling */ |
| 1478 | budget /= (q_vector->rxr_count ?: 1); |
| 1479 | budget = max(budget, 1); |
| 1480 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1481 | for (i = 0; i < q_vector->rxr_count; i++) { |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1482 | ring = &(adapter->rx_ring[r_idx]); |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1483 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1484 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1485 | ixgbe_update_rx_dca(adapter, ring); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1486 | #endif |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1487 | ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1488 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1489 | r_idx + 1); |
| 1490 | } |
| 1491 | |
| 1492 | 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] | 1493 | ring = &(adapter->rx_ring[r_idx]); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1494 | /* If all Rx work done, exit the polling mode */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 1495 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1496 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1497 | if (adapter->rx_itr_setting & 1) |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1498 | ixgbe_set_itr_msix(q_vector); |
| 1499 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1500 | ixgbe_irq_enable_queues(adapter, |
| 1501 | ((u64)1 << q_vector->v_idx)); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1502 | return 0; |
| 1503 | } |
| 1504 | |
| 1505 | return work_done; |
| 1506 | } |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1507 | |
| 1508 | /** |
| 1509 | * ixgbe_clean_txonly - msix (aka one shot) tx clean routine |
| 1510 | * @napi: napi struct with our devices info in it |
| 1511 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1512 | * |
| 1513 | * This function is optimized for cleaning one queue only on a single |
| 1514 | * q_vector!!! |
| 1515 | **/ |
| 1516 | static int ixgbe_clean_txonly(struct napi_struct *napi, int budget) |
| 1517 | { |
| 1518 | struct ixgbe_q_vector *q_vector = |
| 1519 | container_of(napi, struct ixgbe_q_vector, napi); |
| 1520 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1521 | struct ixgbe_ring *tx_ring = NULL; |
| 1522 | int work_done = 0; |
| 1523 | long r_idx; |
| 1524 | |
| 1525 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1526 | tx_ring = &(adapter->tx_ring[r_idx]); |
| 1527 | #ifdef CONFIG_IXGBE_DCA |
| 1528 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1529 | ixgbe_update_tx_dca(adapter, tx_ring); |
| 1530 | #endif |
| 1531 | |
| 1532 | if (!ixgbe_clean_tx_irq(q_vector, tx_ring)) |
| 1533 | work_done = budget; |
| 1534 | |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1535 | /* If all Tx work done, exit the polling mode */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1536 | if (work_done < budget) { |
| 1537 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1538 | if (adapter->tx_itr_setting & 1) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1539 | ixgbe_set_itr_msix(q_vector); |
| 1540 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1541 | ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 1542 | } |
| 1543 | |
| 1544 | return work_done; |
| 1545 | } |
| 1546 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1547 | 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] | 1548 | int r_idx) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1549 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1550 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
| 1551 | |
| 1552 | set_bit(r_idx, q_vector->rxr_idx); |
| 1553 | q_vector->rxr_count++; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1554 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1555 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1556 | 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] | 1557 | int t_idx) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1558 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1559 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
| 1560 | |
| 1561 | set_bit(t_idx, q_vector->txr_idx); |
| 1562 | q_vector->txr_count++; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1563 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1564 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1565 | /** |
| 1566 | * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors |
| 1567 | * @adapter: board private structure to initialize |
| 1568 | * @vectors: allotted vector count for descriptor rings |
| 1569 | * |
| 1570 | * This function maps descriptor rings to the queue-specific vectors |
| 1571 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 1572 | * one vector per ring/queue, but on a constrained vector budget, we |
| 1573 | * group the rings as "efficiently" as possible. You would add new |
| 1574 | * mapping configurations in here. |
| 1575 | **/ |
| 1576 | static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1577 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1578 | { |
| 1579 | int v_start = 0; |
| 1580 | int rxr_idx = 0, txr_idx = 0; |
| 1581 | int rxr_remaining = adapter->num_rx_queues; |
| 1582 | int txr_remaining = adapter->num_tx_queues; |
| 1583 | int i, j; |
| 1584 | int rqpv, tqpv; |
| 1585 | int err = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1586 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1587 | /* No mapping required if MSI-X is disabled. */ |
| 1588 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1589 | goto out; |
| 1590 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1591 | /* |
| 1592 | * The ideal configuration... |
| 1593 | * We have enough vectors to map one per queue. |
| 1594 | */ |
| 1595 | if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) { |
| 1596 | for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++) |
| 1597 | map_vector_to_rxq(adapter, v_start, rxr_idx); |
| 1598 | |
| 1599 | for (; txr_idx < txr_remaining; v_start++, txr_idx++) |
| 1600 | map_vector_to_txq(adapter, v_start, txr_idx); |
| 1601 | |
| 1602 | goto out; |
| 1603 | } |
| 1604 | |
| 1605 | /* |
| 1606 | * If we don't have enough vectors for a 1-to-1 |
| 1607 | * mapping, we'll have to group them so there are |
| 1608 | * multiple queues per vector. |
| 1609 | */ |
| 1610 | /* Re-adjusting *qpv takes care of the remainder. */ |
| 1611 | for (i = v_start; i < vectors; i++) { |
| 1612 | rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i); |
| 1613 | for (j = 0; j < rqpv; j++) { |
| 1614 | map_vector_to_rxq(adapter, i, rxr_idx); |
| 1615 | rxr_idx++; |
| 1616 | rxr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1617 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1618 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1619 | for (i = v_start; i < vectors; i++) { |
| 1620 | tqpv = DIV_ROUND_UP(txr_remaining, vectors - i); |
| 1621 | for (j = 0; j < tqpv; j++) { |
| 1622 | map_vector_to_txq(adapter, i, txr_idx); |
| 1623 | txr_idx++; |
| 1624 | txr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1625 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1626 | } |
| 1627 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1628 | out: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1629 | return err; |
| 1630 | } |
| 1631 | |
| 1632 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1633 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 1634 | * @adapter: board private structure |
| 1635 | * |
| 1636 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 1637 | * interrupts from the kernel. |
| 1638 | **/ |
| 1639 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 1640 | { |
| 1641 | struct net_device *netdev = adapter->netdev; |
| 1642 | irqreturn_t (*handler)(int, void *); |
| 1643 | int i, vector, q_vectors, err; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 1644 | int ri=0, ti=0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1645 | |
| 1646 | /* Decrement for Other and TCP Timer vectors */ |
| 1647 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1648 | |
| 1649 | /* Map the Tx/Rx rings to the vectors we were allotted. */ |
| 1650 | err = ixgbe_map_rings_to_vectors(adapter, q_vectors); |
| 1651 | if (err) |
| 1652 | goto out; |
| 1653 | |
| 1654 | #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \ |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1655 | (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \ |
| 1656 | &ixgbe_msix_clean_many) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1657 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1658 | handler = SET_HANDLER(adapter->q_vector[vector]); |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 1659 | |
| 1660 | if(handler == &ixgbe_msix_clean_rx) { |
| 1661 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1662 | netdev->name, "rx", ri++); |
| 1663 | } |
| 1664 | else if(handler == &ixgbe_msix_clean_tx) { |
| 1665 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1666 | netdev->name, "tx", ti++); |
| 1667 | } |
| 1668 | else |
| 1669 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1670 | netdev->name, "TxRx", vector); |
| 1671 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1672 | err = request_irq(adapter->msix_entries[vector].vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1673 | handler, 0, adapter->name[vector], |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1674 | adapter->q_vector[vector]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1675 | if (err) { |
| 1676 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1677 | "request_irq failed for MSIX interrupt " |
| 1678 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1679 | goto free_queue_irqs; |
| 1680 | } |
| 1681 | } |
| 1682 | |
| 1683 | sprintf(adapter->name[vector], "%s:lsc", netdev->name); |
| 1684 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1685 | ixgbe_msix_lsc, 0, adapter->name[vector], netdev); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1686 | if (err) { |
| 1687 | DPRINTK(PROBE, ERR, |
| 1688 | "request_irq for msix_lsc failed: %d\n", err); |
| 1689 | goto free_queue_irqs; |
| 1690 | } |
| 1691 | |
| 1692 | return 0; |
| 1693 | |
| 1694 | free_queue_irqs: |
| 1695 | for (i = vector - 1; i >= 0; i--) |
| 1696 | free_irq(adapter->msix_entries[--vector].vector, |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1697 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1698 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 1699 | pci_disable_msix(adapter->pdev); |
| 1700 | kfree(adapter->msix_entries); |
| 1701 | adapter->msix_entries = NULL; |
| 1702 | out: |
| 1703 | return err; |
| 1704 | } |
| 1705 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1706 | static void ixgbe_set_itr(struct ixgbe_adapter *adapter) |
| 1707 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1708 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1709 | u8 current_itr; |
| 1710 | u32 new_itr = q_vector->eitr; |
| 1711 | struct ixgbe_ring *rx_ring = &adapter->rx_ring[0]; |
| 1712 | struct ixgbe_ring *tx_ring = &adapter->tx_ring[0]; |
| 1713 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1714 | q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1715 | q_vector->tx_itr, |
| 1716 | tx_ring->total_packets, |
| 1717 | tx_ring->total_bytes); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1718 | q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1719 | q_vector->rx_itr, |
| 1720 | rx_ring->total_packets, |
| 1721 | rx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1722 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1723 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1724 | |
| 1725 | switch (current_itr) { |
| 1726 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1727 | case lowest_latency: |
| 1728 | new_itr = 100000; |
| 1729 | break; |
| 1730 | case low_latency: |
| 1731 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 1732 | break; |
| 1733 | case bulk_latency: |
| 1734 | new_itr = 8000; |
| 1735 | break; |
| 1736 | default: |
| 1737 | break; |
| 1738 | } |
| 1739 | |
| 1740 | if (new_itr != q_vector->eitr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1741 | /* do an exponential smoothing */ |
| 1742 | new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1743 | |
| 1744 | /* save the algorithm value here, not the smoothed one */ |
| 1745 | q_vector->eitr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1746 | |
| 1747 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1748 | } |
| 1749 | |
| 1750 | return; |
| 1751 | } |
| 1752 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1753 | /** |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1754 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 1755 | * @adapter: board private structure |
| 1756 | **/ |
| 1757 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter) |
| 1758 | { |
| 1759 | u32 mask; |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1760 | |
| 1761 | mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
David S. Miller | 6ab33d5 | 2008-11-20 16:44:00 -0800 | [diff] [blame] | 1762 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
| 1763 | mask |= IXGBE_EIMS_GPI_SDP1; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1764 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 1765 | mask |= IXGBE_EIMS_ECC; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1766 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 1767 | mask |= IXGBE_EIMS_GPI_SDP2; |
| 1768 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1769 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 1770 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 1771 | mask |= IXGBE_EIMS_FLOW_DIR; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1772 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1773 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1774 | ixgbe_irq_enable_queues(adapter, ~0); |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1775 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 1776 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1777 | |
| 1778 | /** |
| 1779 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1780 | * @irq: interrupt number |
| 1781 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1782 | **/ |
| 1783 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 1784 | { |
| 1785 | struct net_device *netdev = data; |
| 1786 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1787 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1788 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1789 | u32 eicr; |
| 1790 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 1791 | /* |
| 1792 | * Workaround for silicon errata. Mask the interrupts |
| 1793 | * before the read of EICR. |
| 1794 | */ |
| 1795 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 1796 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1797 | /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read |
| 1798 | * therefore no explict interrupt disable is necessary */ |
| 1799 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 1800 | if (!eicr) { |
| 1801 | /* shared interrupt alert! |
| 1802 | * make sure interrupts are enabled because the read will |
| 1803 | * have disabled interrupts due to EIAM */ |
| 1804 | ixgbe_irq_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1805 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 1806 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1807 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1808 | if (eicr & IXGBE_EICR_LSC) |
| 1809 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1810 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1811 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 1812 | ixgbe_check_sfp_event(adapter, eicr); |
| 1813 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1814 | ixgbe_check_fan_failure(adapter, eicr); |
| 1815 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1816 | if (napi_schedule_prep(&(q_vector->napi))) { |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1817 | adapter->tx_ring[0].total_packets = 0; |
| 1818 | adapter->tx_ring[0].total_bytes = 0; |
| 1819 | adapter->rx_ring[0].total_packets = 0; |
| 1820 | adapter->rx_ring[0].total_bytes = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1821 | /* would disable interrupts here but EIAM disabled it */ |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1822 | __napi_schedule(&(q_vector->napi)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1823 | } |
| 1824 | |
| 1825 | return IRQ_HANDLED; |
| 1826 | } |
| 1827 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1828 | static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter) |
| 1829 | { |
| 1830 | int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1831 | |
| 1832 | for (i = 0; i < q_vectors; i++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1833 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1834 | bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES); |
| 1835 | bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES); |
| 1836 | q_vector->rxr_count = 0; |
| 1837 | q_vector->txr_count = 0; |
| 1838 | } |
| 1839 | } |
| 1840 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1841 | /** |
| 1842 | * ixgbe_request_irq - initialize interrupts |
| 1843 | * @adapter: board private structure |
| 1844 | * |
| 1845 | * Attempts to configure interrupts using the best available |
| 1846 | * capabilities of the hardware and kernel. |
| 1847 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1848 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1849 | { |
| 1850 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1851 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1852 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1853 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 1854 | err = ixgbe_request_msix_irqs(adapter); |
| 1855 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1856 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1857 | netdev->name, netdev); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1858 | } else { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1859 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1860 | netdev->name, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1861 | } |
| 1862 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1863 | if (err) |
| 1864 | DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err); |
| 1865 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1866 | return err; |
| 1867 | } |
| 1868 | |
| 1869 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 1870 | { |
| 1871 | struct net_device *netdev = adapter->netdev; |
| 1872 | |
| 1873 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1874 | int i, q_vectors; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1875 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1876 | q_vectors = adapter->num_msix_vectors; |
| 1877 | |
| 1878 | i = q_vectors - 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1879 | free_irq(adapter->msix_entries[i].vector, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1880 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1881 | i--; |
| 1882 | for (; i >= 0; i--) { |
| 1883 | free_irq(adapter->msix_entries[i].vector, |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1884 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1885 | } |
| 1886 | |
| 1887 | ixgbe_reset_q_vectors(adapter); |
| 1888 | } else { |
| 1889 | free_irq(adapter->pdev->irq, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1890 | } |
| 1891 | } |
| 1892 | |
| 1893 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1894 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 1895 | * @adapter: board private structure |
| 1896 | **/ |
| 1897 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 1898 | { |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1899 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1900 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
| 1901 | } else { |
| 1902 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 1903 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1904 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1905 | } |
| 1906 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 1907 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 1908 | int i; |
| 1909 | for (i = 0; i < adapter->num_msix_vectors; i++) |
| 1910 | synchronize_irq(adapter->msix_entries[i].vector); |
| 1911 | } else { |
| 1912 | synchronize_irq(adapter->pdev->irq); |
| 1913 | } |
| 1914 | } |
| 1915 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1916 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1917 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 1918 | * |
| 1919 | **/ |
| 1920 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 1921 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1922 | struct ixgbe_hw *hw = &adapter->hw; |
| 1923 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1924 | IXGBE_WRITE_REG(hw, IXGBE_EITR(0), |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1925 | EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1926 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1927 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 1928 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1929 | |
| 1930 | map_vector_to_rxq(adapter, 0, 0); |
| 1931 | map_vector_to_txq(adapter, 0, 0); |
| 1932 | |
| 1933 | DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1934 | } |
| 1935 | |
| 1936 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1937 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1938 | * @adapter: board private structure |
| 1939 | * |
| 1940 | * Configure the Tx unit of the MAC after a reset. |
| 1941 | **/ |
| 1942 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 1943 | { |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1944 | u64 tdba; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1945 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1946 | u32 i, j, tdlen, txctrl; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1947 | |
| 1948 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 1949 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1950 | struct ixgbe_ring *ring = &adapter->tx_ring[i]; |
| 1951 | j = ring->reg_idx; |
| 1952 | tdba = ring->dma; |
| 1953 | tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1954 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j), |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1955 | (tdba & DMA_BIT_MASK(32))); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1956 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32)); |
| 1957 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen); |
| 1958 | IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0); |
| 1959 | IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0); |
| 1960 | adapter->tx_ring[i].head = IXGBE_TDH(j); |
| 1961 | adapter->tx_ring[i].tail = IXGBE_TDT(j); |
Peter P Waskiewicz Jr | 84f62d4 | 2009-09-30 12:07:16 +0000 | [diff] [blame] | 1962 | /* |
| 1963 | * Disable Tx Head Writeback RO bit, since this hoses |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1964 | * bookkeeping if things aren't delivered in order. |
| 1965 | */ |
Peter P Waskiewicz Jr | 84f62d4 | 2009-09-30 12:07:16 +0000 | [diff] [blame] | 1966 | switch (hw->mac.type) { |
| 1967 | case ixgbe_mac_82598EB: |
| 1968 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j)); |
| 1969 | break; |
| 1970 | case ixgbe_mac_82599EB: |
| 1971 | default: |
| 1972 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(j)); |
| 1973 | break; |
| 1974 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1975 | txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN; |
Peter P Waskiewicz Jr | 84f62d4 | 2009-09-30 12:07:16 +0000 | [diff] [blame] | 1976 | switch (hw->mac.type) { |
| 1977 | case ixgbe_mac_82598EB: |
| 1978 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl); |
| 1979 | break; |
| 1980 | case ixgbe_mac_82599EB: |
| 1981 | default: |
| 1982 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(j), txctrl); |
| 1983 | break; |
| 1984 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1985 | } |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 1986 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1987 | if (hw->mac.type == ixgbe_mac_82599EB) { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 1988 | u32 rttdcs; |
| 1989 | |
| 1990 | /* disable the arbiter while setting MTQC */ |
| 1991 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 1992 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 1993 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 1994 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1995 | /* We enable 8 traffic classes, DCB only */ |
| 1996 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 1997 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA | |
| 1998 | IXGBE_MTQC_8TC_8TQ)); |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 1999 | else |
| 2000 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB); |
| 2001 | |
| 2002 | /* re-eable the arbiter */ |
| 2003 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 2004 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2005 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2006 | } |
| 2007 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2008 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2009 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2010 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
| 2011 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2012 | { |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2013 | u32 srrctl; |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2014 | int index; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2015 | struct ixgbe_ring_feature *feature = adapter->ring_feature; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2016 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2017 | index = rx_ring->reg_idx; |
| 2018 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 2019 | unsigned long mask; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2020 | mask = (unsigned long) feature[RING_F_RSS].mask; |
Alexander Duyck | 3be1adf | 2008-08-30 00:29:10 -0700 | [diff] [blame] | 2021 | index = index & mask; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2022 | } |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2023 | srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index)); |
| 2024 | |
| 2025 | srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2026 | srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK; |
| 2027 | |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2028 | srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) & |
| 2029 | IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2030 | |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 2031 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2032 | #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER |
| 2033 | srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 2034 | #else |
| 2035 | srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 2036 | #endif |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2037 | srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2038 | } else { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2039 | srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >> |
| 2040 | IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2041 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2042 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2043 | |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2044 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl); |
| 2045 | } |
| 2046 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2047 | static u32 ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
| 2048 | { |
| 2049 | u32 mrqc = 0; |
| 2050 | int mask; |
| 2051 | |
| 2052 | if (!(adapter->hw.mac.type == ixgbe_mac_82599EB)) |
| 2053 | return mrqc; |
| 2054 | |
| 2055 | mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED |
| 2056 | #ifdef CONFIG_IXGBE_DCB |
| 2057 | | IXGBE_FLAG_DCB_ENABLED |
| 2058 | #endif |
| 2059 | ); |
| 2060 | |
| 2061 | switch (mask) { |
| 2062 | case (IXGBE_FLAG_RSS_ENABLED): |
| 2063 | mrqc = IXGBE_MRQC_RSSEN; |
| 2064 | break; |
| 2065 | #ifdef CONFIG_IXGBE_DCB |
| 2066 | case (IXGBE_FLAG_DCB_ENABLED): |
| 2067 | mrqc = IXGBE_MRQC_RT8TCEN; |
| 2068 | break; |
| 2069 | #endif /* CONFIG_IXGBE_DCB */ |
| 2070 | default: |
| 2071 | break; |
| 2072 | } |
| 2073 | |
| 2074 | return mrqc; |
| 2075 | } |
| 2076 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2077 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2078 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 2079 | * @adapter: address of board private structure |
| 2080 | * @index: index of ring to set |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2081 | **/ |
Mallikarjuna R Chilakala | edd2ea5 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2082 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, int index) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2083 | { |
| 2084 | struct ixgbe_ring *rx_ring; |
| 2085 | struct ixgbe_hw *hw = &adapter->hw; |
| 2086 | int j; |
| 2087 | u32 rscctrl; |
Mallikarjuna R Chilakala | edd2ea5 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2088 | int rx_buf_len; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2089 | |
| 2090 | rx_ring = &adapter->rx_ring[index]; |
| 2091 | j = rx_ring->reg_idx; |
Mallikarjuna R Chilakala | edd2ea5 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2092 | rx_buf_len = rx_ring->rx_buf_len; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2093 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(j)); |
| 2094 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 2095 | /* |
| 2096 | * we must limit the number of descriptors so that the |
| 2097 | * total size of max desc * buf_len is not greater |
| 2098 | * than 65535 |
| 2099 | */ |
| 2100 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
| 2101 | #if (MAX_SKB_FRAGS > 16) |
| 2102 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2103 | #elif (MAX_SKB_FRAGS > 8) |
| 2104 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
| 2105 | #elif (MAX_SKB_FRAGS > 4) |
| 2106 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
| 2107 | #else |
| 2108 | rscctrl |= IXGBE_RSCCTL_MAXDESC_1; |
| 2109 | #endif |
| 2110 | } else { |
| 2111 | if (rx_buf_len < IXGBE_RXBUFFER_4096) |
| 2112 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2113 | else if (rx_buf_len < IXGBE_RXBUFFER_8192) |
| 2114 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
| 2115 | else |
| 2116 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
| 2117 | } |
| 2118 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(j), rscctrl); |
| 2119 | } |
| 2120 | |
| 2121 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2122 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2123 | * @adapter: board private structure |
| 2124 | * |
| 2125 | * Configure the Rx unit of the MAC after a reset. |
| 2126 | **/ |
| 2127 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 2128 | { |
| 2129 | u64 rdba; |
| 2130 | struct ixgbe_hw *hw = &adapter->hw; |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2131 | struct ixgbe_ring *rx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2132 | struct net_device *netdev = adapter->netdev; |
| 2133 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2134 | int i, j; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2135 | u32 rdlen, rxctrl, rxcsum; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2136 | static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D, |
| 2137 | 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE, |
| 2138 | 0x6A3E67EA, 0x14364D17, 0x3BED200D}; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2139 | u32 fctrl, hlreg0; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2140 | u32 reta = 0, mrqc = 0; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2141 | u32 rdrxctl; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2142 | int rx_buf_len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2143 | |
| 2144 | /* Decide whether to use packet split mode or not */ |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 2145 | adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2146 | |
| 2147 | /* Set the RX buffer length according to the mode */ |
| 2148 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2149 | rx_buf_len = IXGBE_RX_HDR_SIZE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2150 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2151 | /* PSRTYPE must be initialized in 82599 */ |
| 2152 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
| 2153 | IXGBE_PSRTYPE_UDPHDR | |
| 2154 | IXGBE_PSRTYPE_IPV4HDR | |
Yi Zou | dfa12f0 | 2009-05-07 10:39:35 +0000 | [diff] [blame] | 2155 | IXGBE_PSRTYPE_IPV6HDR | |
| 2156 | IXGBE_PSRTYPE_L2HDR; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2157 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype); |
| 2158 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2159 | } else { |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 2160 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) && |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2161 | (netdev->mtu <= ETH_DATA_LEN)) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2162 | rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2163 | else |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2164 | rx_buf_len = ALIGN(max_frame, 1024); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2165 | } |
| 2166 | |
| 2167 | fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL); |
| 2168 | fctrl |= IXGBE_FCTRL_BAM; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2169 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2170 | fctrl |= IXGBE_FCTRL_PMCF; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2171 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl); |
| 2172 | |
| 2173 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
| 2174 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 2175 | hlreg0 &= ~IXGBE_HLREG0_JUMBOEN; |
| 2176 | else |
| 2177 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2178 | #ifdef IXGBE_FCOE |
Yi Zou | f34c5c8 | 2009-08-14 12:42:17 +0000 | [diff] [blame] | 2179 | if (netdev->features & NETIF_F_FCOE_MTU) |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2180 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
| 2181 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2182 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 2183 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2184 | rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc); |
| 2185 | /* disable receives while setting up the descriptors */ |
| 2186 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 2187 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
| 2188 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2189 | /* |
| 2190 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 2191 | * the Base and Length of the Rx Descriptor Ring |
| 2192 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2193 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2194 | rx_ring = &adapter->rx_ring[i]; |
| 2195 | rdba = rx_ring->dma; |
| 2196 | j = rx_ring->reg_idx; |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2197 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_BIT_MASK(32))); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2198 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32)); |
| 2199 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen); |
| 2200 | IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0); |
| 2201 | IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0); |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2202 | rx_ring->head = IXGBE_RDH(j); |
| 2203 | rx_ring->tail = IXGBE_RDT(j); |
| 2204 | rx_ring->rx_buf_len = rx_buf_len; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2205 | |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 2206 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) |
| 2207 | rx_ring->flags |= IXGBE_RING_RX_PS_ENABLED; |
Peter P Waskiewicz Jr | 1b3ff02 | 2009-09-14 07:47:27 +0000 | [diff] [blame] | 2208 | else |
| 2209 | rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2210 | |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2211 | #ifdef IXGBE_FCOE |
Yi Zou | f34c5c8 | 2009-08-14 12:42:17 +0000 | [diff] [blame] | 2212 | if (netdev->features & NETIF_F_FCOE_MTU) { |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2213 | struct ixgbe_ring_feature *f; |
| 2214 | f = &adapter->ring_feature[RING_F_FCOE]; |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 2215 | if ((i >= f->mask) && (i < f->mask + f->indices)) { |
| 2216 | rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED; |
| 2217 | if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE) |
| 2218 | rx_ring->rx_buf_len = |
| 2219 | IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 2220 | } |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2221 | } |
| 2222 | |
| 2223 | #endif /* IXGBE_FCOE */ |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2224 | ixgbe_configure_srrctl(adapter, rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2225 | } |
| 2226 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2227 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 2228 | /* |
| 2229 | * For VMDq support of different descriptor types or |
| 2230 | * buffer sizes through the use of multiple SRRCTL |
| 2231 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 2232 | * |
| 2233 | * also, the manual doesn't mention it clearly but DCA hints |
| 2234 | * will only use queue 0's tags unless this bit is set. Side |
| 2235 | * effects of setting this bit are only that SRRCTL must be |
| 2236 | * fully programmed [0..15] |
| 2237 | */ |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2238 | rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 2239 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 2240 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2241 | } |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2242 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2243 | /* Program MRQC for the distribution of queues */ |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2244 | mrqc = ixgbe_setup_mrqc(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2245 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2246 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2247 | /* Fill out redirection table */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2248 | for (i = 0, j = 0; i < 128; i++, j++) { |
| 2249 | if (j == adapter->ring_feature[RING_F_RSS].indices) |
| 2250 | j = 0; |
| 2251 | /* reta = 4-byte sliding window of |
| 2252 | * 0x00..(indices-1)(indices-1)00..etc. */ |
| 2253 | reta = (reta << 8) | (j * 0x11); |
| 2254 | if ((i & 3) == 3) |
| 2255 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2256 | } |
| 2257 | |
| 2258 | /* Fill out hash function seeds */ |
| 2259 | for (i = 0; i < 10; i++) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2260 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2261 | |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2262 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2263 | mrqc |= IXGBE_MRQC_RSSEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2264 | /* Perform hash on these packet types */ |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2265 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
| 2266 | | IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
| 2267 | | IXGBE_MRQC_RSS_FIELD_IPV4_UDP |
| 2268 | | IXGBE_MRQC_RSS_FIELD_IPV6 |
| 2269 | | IXGBE_MRQC_RSS_FIELD_IPV6_TCP |
| 2270 | | IXGBE_MRQC_RSS_FIELD_IPV6_UDP; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2271 | } |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2272 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2273 | |
| 2274 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 2275 | |
| 2276 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED || |
| 2277 | adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) { |
| 2278 | /* Disable indicating checksum in descriptor, enables |
| 2279 | * RSS hash */ |
| 2280 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 2281 | } |
| 2282 | if (!(rxcsum & IXGBE_RXCSUM_PCSD)) { |
| 2283 | /* Enable IPv4 payload checksum for UDP fragments |
| 2284 | * if PCSD is not set */ |
| 2285 | rxcsum |= IXGBE_RXCSUM_IPPCSE; |
| 2286 | } |
| 2287 | |
| 2288 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2289 | |
| 2290 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2291 | rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 2292 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2293 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2294 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 2295 | } |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2296 | |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 2297 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2298 | /* Enable 82599 HW-RSC */ |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2299 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | edd2ea5 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2300 | ixgbe_configure_rscctl(adapter, i); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2301 | |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2302 | /* Disable RSC for ACK packets */ |
| 2303 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 2304 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 2305 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2306 | } |
| 2307 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2308 | static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 2309 | { |
| 2310 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2311 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2312 | |
| 2313 | /* add VID to filter table */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2314 | hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2315 | } |
| 2316 | |
| 2317 | static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 2318 | { |
| 2319 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2320 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2321 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2322 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2323 | ixgbe_irq_disable(adapter); |
| 2324 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2325 | vlan_group_set_device(adapter->vlgrp, vid, NULL); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2326 | |
| 2327 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2328 | ixgbe_irq_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2329 | |
| 2330 | /* remove VID from filter table */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2331 | hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2332 | } |
| 2333 | |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2334 | static void ixgbe_vlan_rx_register(struct net_device *netdev, |
| 2335 | struct vlan_group *grp) |
| 2336 | { |
| 2337 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2338 | u32 ctrl; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2339 | int i, j; |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2340 | |
| 2341 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2342 | ixgbe_irq_disable(adapter); |
| 2343 | adapter->vlgrp = grp; |
| 2344 | |
| 2345 | /* |
| 2346 | * For a DCB driver, always enable VLAN tag stripping so we can |
| 2347 | * still receive traffic from a DCB-enabled host even if we're |
| 2348 | * not in DCB mode. |
| 2349 | */ |
| 2350 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL); |
Alexander Duyck | dc63d37 | 2009-11-23 06:32:57 +0000 | [diff] [blame] | 2351 | |
| 2352 | /* Disable CFI check */ |
| 2353 | ctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2354 | |
| 2355 | /* enable VLAN tag stripping */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2356 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | dc63d37 | 2009-11-23 06:32:57 +0000 | [diff] [blame] | 2357 | ctrl |= IXGBE_VLNCTRL_VME; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2358 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2359 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | dc63d37 | 2009-11-23 06:32:57 +0000 | [diff] [blame] | 2360 | u32 ctrl; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2361 | j = adapter->rx_ring[i].reg_idx; |
| 2362 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j)); |
| 2363 | ctrl |= IXGBE_RXDCTL_VME; |
| 2364 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl); |
| 2365 | } |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2366 | } |
Alexander Duyck | dc63d37 | 2009-11-23 06:32:57 +0000 | [diff] [blame] | 2367 | |
| 2368 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl); |
| 2369 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2370 | ixgbe_vlan_rx_add_vid(netdev, 0); |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2371 | |
| 2372 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2373 | ixgbe_irq_enable(adapter); |
| 2374 | } |
| 2375 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2376 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 2377 | { |
| 2378 | ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 2379 | |
| 2380 | if (adapter->vlgrp) { |
| 2381 | u16 vid; |
| 2382 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
| 2383 | if (!vlan_group_get_device(adapter->vlgrp, vid)) |
| 2384 | continue; |
| 2385 | ixgbe_vlan_rx_add_vid(adapter->netdev, vid); |
| 2386 | } |
| 2387 | } |
| 2388 | } |
| 2389 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2390 | static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq) |
| 2391 | { |
| 2392 | struct dev_mc_list *mc_ptr; |
| 2393 | u8 *addr = *mc_addr_ptr; |
| 2394 | *vmdq = 0; |
| 2395 | |
| 2396 | mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]); |
| 2397 | if (mc_ptr->next) |
| 2398 | *mc_addr_ptr = mc_ptr->next->dmi_addr; |
| 2399 | else |
| 2400 | *mc_addr_ptr = NULL; |
| 2401 | |
| 2402 | return addr; |
| 2403 | } |
| 2404 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2405 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2406 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2407 | * @netdev: network interface device structure |
| 2408 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2409 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 2410 | * address list or the network interface flags are updated. This routine is |
| 2411 | * responsible for configuring the hardware for proper unicast, multicast and |
| 2412 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2413 | **/ |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2414 | static void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2415 | { |
| 2416 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2417 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2418 | u32 fctrl, vlnctrl; |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2419 | u8 *addr_list = NULL; |
| 2420 | int addr_count = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2421 | |
| 2422 | /* Check for Promiscuous and All Multicast modes */ |
| 2423 | |
| 2424 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2425 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2426 | |
| 2427 | if (netdev->flags & IFF_PROMISC) { |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2428 | hw->addr_ctrl.user_set_promisc = 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2429 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2430 | vlnctrl &= ~IXGBE_VLNCTRL_VFE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2431 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2432 | if (netdev->flags & IFF_ALLMULTI) { |
| 2433 | fctrl |= IXGBE_FCTRL_MPE; |
| 2434 | fctrl &= ~IXGBE_FCTRL_UPE; |
| 2435 | } else { |
| 2436 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
| 2437 | } |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2438 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2439 | hw->addr_ctrl.user_set_promisc = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2440 | } |
| 2441 | |
| 2442 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2443 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2444 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2445 | /* reprogram secondary unicast list */ |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 2446 | hw->mac.ops.update_uc_addr_list(hw, &netdev->uc.list); |
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 multicast list */ |
| 2449 | addr_count = netdev->mc_count; |
| 2450 | if (addr_count) |
| 2451 | addr_list = netdev->mc_list->dmi_addr; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2452 | hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count, |
| 2453 | ixgbe_addr_list_itr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2454 | } |
| 2455 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2456 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 2457 | { |
| 2458 | int q_idx; |
| 2459 | struct ixgbe_q_vector *q_vector; |
| 2460 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2461 | |
| 2462 | /* legacy and MSI only use one vector */ |
| 2463 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 2464 | q_vectors = 1; |
| 2465 | |
| 2466 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2467 | struct napi_struct *napi; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2468 | q_vector = adapter->q_vector[q_idx]; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2469 | napi = &q_vector->napi; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2470 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2471 | if (!q_vector->rxr_count || !q_vector->txr_count) { |
| 2472 | if (q_vector->txr_count == 1) |
| 2473 | napi->poll = &ixgbe_clean_txonly; |
| 2474 | else if (q_vector->rxr_count == 1) |
| 2475 | napi->poll = &ixgbe_clean_rxonly; |
| 2476 | } |
| 2477 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2478 | |
| 2479 | napi_enable(napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2480 | } |
| 2481 | } |
| 2482 | |
| 2483 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 2484 | { |
| 2485 | int q_idx; |
| 2486 | struct ixgbe_q_vector *q_vector; |
| 2487 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2488 | |
| 2489 | /* legacy and MSI only use one vector */ |
| 2490 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 2491 | q_vectors = 1; |
| 2492 | |
| 2493 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2494 | q_vector = adapter->q_vector[q_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2495 | napi_disable(&q_vector->napi); |
| 2496 | } |
| 2497 | } |
| 2498 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 2499 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2500 | /* |
| 2501 | * ixgbe_configure_dcb - Configure DCB hardware |
| 2502 | * @adapter: ixgbe adapter struct |
| 2503 | * |
| 2504 | * This is called by the driver on open to configure the DCB hardware. |
| 2505 | * This is also called by the gennetlink interface when reconfiguring |
| 2506 | * the DCB state. |
| 2507 | */ |
| 2508 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 2509 | { |
| 2510 | struct ixgbe_hw *hw = &adapter->hw; |
| 2511 | u32 txdctl, vlnctrl; |
| 2512 | int i, j; |
| 2513 | |
| 2514 | ixgbe_dcb_check_config(&adapter->dcb_cfg); |
| 2515 | ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG); |
| 2516 | ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG); |
| 2517 | |
| 2518 | /* reconfigure the hardware */ |
| 2519 | ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg); |
| 2520 | |
| 2521 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2522 | j = adapter->tx_ring[i].reg_idx; |
| 2523 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
| 2524 | /* PThresh workaround for Tx hang with DFP enabled. */ |
| 2525 | txdctl |= 32; |
| 2526 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
| 2527 | } |
| 2528 | /* Enable VLAN tag insert/strip */ |
| 2529 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2530 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 2531 | vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE; |
| 2532 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2533 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 2534 | } else if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2535 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 2536 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2537 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 2538 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 2539 | j = adapter->rx_ring[i].reg_idx; |
| 2540 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 2541 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 2542 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 2543 | } |
| 2544 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2545 | hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true); |
| 2546 | } |
| 2547 | |
| 2548 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2549 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 2550 | { |
| 2551 | struct net_device *netdev = adapter->netdev; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2552 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2553 | int i; |
| 2554 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2555 | ixgbe_set_rx_mode(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2556 | |
| 2557 | ixgbe_restore_vlan(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 2558 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2559 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Yi Zou | b352e40 | 2009-11-06 12:55:38 +0000 | [diff] [blame] | 2560 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2561 | netif_set_gso_max_size(netdev, 32768); |
| 2562 | else |
| 2563 | netif_set_gso_max_size(netdev, 65536); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2564 | ixgbe_configure_dcb(adapter); |
| 2565 | } else { |
| 2566 | netif_set_gso_max_size(netdev, 65536); |
| 2567 | } |
| 2568 | #else |
| 2569 | netif_set_gso_max_size(netdev, 65536); |
| 2570 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2571 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 2572 | #ifdef IXGBE_FCOE |
| 2573 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 2574 | ixgbe_configure_fcoe(adapter); |
| 2575 | |
| 2576 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2577 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 2578 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2579 | adapter->tx_ring[i].atr_sample_rate = |
| 2580 | adapter->atr_sample_rate; |
| 2581 | ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc); |
| 2582 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 2583 | ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc); |
| 2584 | } |
| 2585 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2586 | ixgbe_configure_tx(adapter); |
| 2587 | ixgbe_configure_rx(adapter); |
| 2588 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 2589 | ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i], |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2590 | (adapter->rx_ring[i].count - 1)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2591 | } |
| 2592 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2593 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 2594 | { |
| 2595 | switch (hw->phy.type) { |
| 2596 | case ixgbe_phy_sfp_avago: |
| 2597 | case ixgbe_phy_sfp_ftl: |
| 2598 | case ixgbe_phy_sfp_intel: |
| 2599 | case ixgbe_phy_sfp_unknown: |
| 2600 | case ixgbe_phy_tw_tyco: |
| 2601 | case ixgbe_phy_tw_unknown: |
| 2602 | return true; |
| 2603 | default: |
| 2604 | return false; |
| 2605 | } |
| 2606 | } |
| 2607 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2608 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2609 | * ixgbe_sfp_link_config - set up SFP+ link |
| 2610 | * @adapter: pointer to private adapter struct |
| 2611 | **/ |
| 2612 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 2613 | { |
| 2614 | struct ixgbe_hw *hw = &adapter->hw; |
| 2615 | |
| 2616 | if (hw->phy.multispeed_fiber) { |
| 2617 | /* |
| 2618 | * In multispeed fiber setups, the device may not have |
| 2619 | * had a physical connection when the driver loaded. |
| 2620 | * If that's the case, the initial link configuration |
| 2621 | * couldn't get the MAC into 10G or 1G mode, so we'll |
| 2622 | * never have a link status change interrupt fire. |
| 2623 | * We need to try and force an autonegotiation |
| 2624 | * session, then bring up link. |
| 2625 | */ |
| 2626 | hw->mac.ops.setup_sfp(hw); |
| 2627 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK)) |
| 2628 | schedule_work(&adapter->multispeed_fiber_task); |
| 2629 | } else { |
| 2630 | /* |
| 2631 | * Direct Attach Cu and non-multispeed fiber modules |
| 2632 | * still need to be configured properly prior to |
| 2633 | * attempting link. |
| 2634 | */ |
| 2635 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK)) |
| 2636 | schedule_work(&adapter->sfp_config_module_task); |
| 2637 | } |
| 2638 | } |
| 2639 | |
| 2640 | /** |
| 2641 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2642 | * @hw: pointer to private hardware struct |
| 2643 | * |
| 2644 | * Returns 0 on success, negative on failure |
| 2645 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2646 | 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] | 2647 | { |
| 2648 | u32 autoneg; |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 2649 | bool negotiation, link_up = false; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2650 | u32 ret = IXGBE_ERR_LINK_SETUP; |
| 2651 | |
| 2652 | if (hw->mac.ops.check_link) |
| 2653 | ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 2654 | |
| 2655 | if (ret) |
| 2656 | goto link_cfg_out; |
| 2657 | |
| 2658 | if (hw->mac.ops.get_link_capabilities) |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 2659 | ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2660 | if (ret) |
| 2661 | goto link_cfg_out; |
| 2662 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 2663 | if (hw->mac.ops.setup_link) |
| 2664 | 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] | 2665 | link_cfg_out: |
| 2666 | return ret; |
| 2667 | } |
| 2668 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2669 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 2670 | static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 2671 | int rxr) |
| 2672 | { |
| 2673 | int j = adapter->rx_ring[rxr].reg_idx; |
| 2674 | int k; |
| 2675 | |
| 2676 | for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) { |
| 2677 | if (IXGBE_READ_REG(&adapter->hw, |
| 2678 | IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE) |
| 2679 | break; |
| 2680 | else |
| 2681 | msleep(1); |
| 2682 | } |
| 2683 | if (k >= IXGBE_MAX_RX_DESC_POLL) { |
| 2684 | DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d " |
| 2685 | "not set within the polling period\n", rxr); |
| 2686 | } |
| 2687 | ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr], |
| 2688 | (adapter->rx_ring[rxr].count - 1)); |
| 2689 | } |
| 2690 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2691 | static int ixgbe_up_complete(struct ixgbe_adapter *adapter) |
| 2692 | { |
| 2693 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2694 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2695 | int i, j = 0; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2696 | int num_rx_rings = adapter->num_rx_queues; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2697 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2698 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2699 | u32 txdctl, rxdctl, mhadd; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2700 | u32 dmatxctl; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2701 | u32 gpie; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2702 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 2703 | ixgbe_get_hw_control(adapter); |
| 2704 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2705 | if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) || |
| 2706 | (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2707 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2708 | gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2709 | IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2710 | } else { |
| 2711 | /* MSI only */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2712 | gpie = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2713 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2714 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 2715 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 2716 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2717 | } |
| 2718 | |
| 2719 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
| 2720 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 2721 | * specifically only auto mask tx and rx interrupts */ |
| 2722 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2723 | } |
| 2724 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2725 | /* Enable fan failure interrupt if media type is copper */ |
| 2726 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 2727 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 2728 | gpie |= IXGBE_SDP1_GPIEN; |
| 2729 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2730 | } |
| 2731 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2732 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2733 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 2734 | gpie |= IXGBE_SDP1_GPIEN; |
| 2735 | gpie |= IXGBE_SDP2_GPIEN; |
| 2736 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2737 | } |
| 2738 | |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2739 | #ifdef IXGBE_FCOE |
| 2740 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
Yi Zou | f34c5c8 | 2009-08-14 12:42:17 +0000 | [diff] [blame] | 2741 | if ((netdev->features & NETIF_F_FCOE_MTU) && |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2742 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 2743 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 2744 | |
| 2745 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2746 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2747 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 2748 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 2749 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 2750 | |
| 2751 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
| 2752 | } |
| 2753 | |
| 2754 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2755 | j = adapter->tx_ring[i].reg_idx; |
| 2756 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 2757 | /* enable WTHRESH=8 descriptors, to encourage burst writeback */ |
| 2758 | txdctl |= (8 << 16); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2759 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
| 2760 | } |
| 2761 | |
| 2762 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2763 | /* DMATXCTL.EN must be set after all Tx queue config is done */ |
| 2764 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 2765 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 2766 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 2767 | } |
| 2768 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2769 | j = adapter->tx_ring[i].reg_idx; |
| 2770 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2771 | txdctl |= IXGBE_TXDCTL_ENABLE; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2772 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2773 | } |
| 2774 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2775 | for (i = 0; i < num_rx_rings; i++) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2776 | j = adapter->rx_ring[i].reg_idx; |
| 2777 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 2778 | /* enable PTHRESH=32 descriptors (half the internal cache) |
| 2779 | * and HTHRESH=0 descriptors (to minimize latency on fetch), |
| 2780 | * this also removes a pesky rx_no_buffer_count increment */ |
| 2781 | rxdctl |= 0x0020; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2782 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2783 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2784 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 2785 | ixgbe_rx_desc_queue_enable(adapter, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2786 | } |
| 2787 | /* enable all receives */ |
| 2788 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2789 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2790 | rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN); |
| 2791 | else |
| 2792 | rxdctl |= IXGBE_RXCTRL_RXEN; |
| 2793 | hw->mac.ops.enable_rx_dma(hw, rxdctl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2794 | |
| 2795 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 2796 | ixgbe_configure_msix(adapter); |
| 2797 | else |
| 2798 | ixgbe_configure_msi_and_legacy(adapter); |
| 2799 | |
| 2800 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2801 | ixgbe_napi_enable_all(adapter); |
| 2802 | |
| 2803 | /* clear any pending interrupts, may auto mask */ |
| 2804 | IXGBE_READ_REG(hw, IXGBE_EICR); |
| 2805 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2806 | ixgbe_irq_enable(adapter); |
| 2807 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2808 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 2809 | * If this adapter has a fan, check to see if we had a failure |
| 2810 | * before we enabled the interrupt. |
| 2811 | */ |
| 2812 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 2813 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 2814 | if (esdp & IXGBE_ESDP_SDP1) |
| 2815 | DPRINTK(DRV, CRIT, |
| 2816 | "Fan has stopped, replace the adapter\n"); |
| 2817 | } |
| 2818 | |
| 2819 | /* |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2820 | * For hot-pluggable SFP+ devices, a new SFP+ module may have |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2821 | * arrived before interrupts were enabled but after probe. Such |
| 2822 | * devices wouldn't have their type identified yet. We need to |
| 2823 | * 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] | 2824 | * If we're not hot-pluggable SFP+, we just need to configure link |
| 2825 | * and bring it up. |
| 2826 | */ |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2827 | if (hw->phy.type == ixgbe_phy_unknown) { |
| 2828 | err = hw->phy.ops.identify(hw); |
| 2829 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 5da43c1 | 2009-07-02 12:50:52 +0000 | [diff] [blame] | 2830 | /* |
| 2831 | * Take the device down and schedule the sfp tasklet |
| 2832 | * which will unregister_netdev and log it. |
| 2833 | */ |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2834 | ixgbe_down(adapter); |
Don Skidmore | 5da43c1 | 2009-07-02 12:50:52 +0000 | [diff] [blame] | 2835 | schedule_work(&adapter->sfp_config_module_task); |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2836 | return err; |
| 2837 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2838 | } |
| 2839 | |
| 2840 | if (ixgbe_is_sfp(hw)) { |
| 2841 | ixgbe_sfp_link_config(adapter); |
| 2842 | } else { |
| 2843 | err = ixgbe_non_sfp_link_config(hw); |
| 2844 | if (err) |
| 2845 | DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err); |
| 2846 | } |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2847 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2848 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2849 | set_bit(__IXGBE_FDIR_INIT_DONE, |
| 2850 | &(adapter->tx_ring[i].reinit_state)); |
| 2851 | |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 2852 | /* enable transmits */ |
| 2853 | netif_tx_start_all_queues(netdev); |
| 2854 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2855 | /* bring the link up in the watchdog, this could race with our first |
| 2856 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2857 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2858 | adapter->link_check_timeout = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2859 | mod_timer(&adapter->watchdog_timer, jiffies); |
| 2860 | return 0; |
| 2861 | } |
| 2862 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2863 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 2864 | { |
| 2865 | WARN_ON(in_interrupt()); |
| 2866 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
| 2867 | msleep(1); |
| 2868 | ixgbe_down(adapter); |
| 2869 | ixgbe_up(adapter); |
| 2870 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 2871 | } |
| 2872 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2873 | int ixgbe_up(struct ixgbe_adapter *adapter) |
| 2874 | { |
| 2875 | /* hardware has been reset, we need to reload some things */ |
| 2876 | ixgbe_configure(adapter); |
| 2877 | |
| 2878 | return ixgbe_up_complete(adapter); |
| 2879 | } |
| 2880 | |
| 2881 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 2882 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2883 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 2884 | int err; |
| 2885 | |
| 2886 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2887 | switch (err) { |
| 2888 | case 0: |
| 2889 | case IXGBE_ERR_SFP_NOT_PRESENT: |
| 2890 | break; |
| 2891 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
| 2892 | dev_err(&adapter->pdev->dev, "master disable timed out\n"); |
| 2893 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 2894 | case IXGBE_ERR_EEPROM_VERSION: |
| 2895 | /* We are running on a pre-production device, log a warning */ |
| 2896 | dev_warn(&adapter->pdev->dev, "This device is a pre-production " |
| 2897 | "adapter/LOM. Please be aware there may be issues " |
| 2898 | "associated with your hardware. If you are " |
| 2899 | "experiencing problems please contact your Intel or " |
| 2900 | "hardware representative who provided you with this " |
| 2901 | "hardware.\n"); |
| 2902 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2903 | default: |
| 2904 | dev_err(&adapter->pdev->dev, "Hardware Error: %d\n", err); |
| 2905 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2906 | |
| 2907 | /* reprogram the RAR[0] in case user changed it. */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2908 | 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] | 2909 | } |
| 2910 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2911 | /** |
| 2912 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
| 2913 | * @adapter: board private structure |
| 2914 | * @rx_ring: ring to free buffers from |
| 2915 | **/ |
| 2916 | static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2917 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2918 | { |
| 2919 | struct pci_dev *pdev = adapter->pdev; |
| 2920 | unsigned long size; |
| 2921 | unsigned int i; |
| 2922 | |
| 2923 | /* Free all the Rx ring sk_buffs */ |
| 2924 | |
| 2925 | for (i = 0; i < rx_ring->count; i++) { |
| 2926 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 2927 | |
| 2928 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
| 2929 | if (rx_buffer_info->dma) { |
| 2930 | pci_unmap_single(pdev, rx_buffer_info->dma, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2931 | rx_ring->rx_buf_len, |
| 2932 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2933 | rx_buffer_info->dma = 0; |
| 2934 | } |
| 2935 | if (rx_buffer_info->skb) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2936 | struct sk_buff *skb = rx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2937 | rx_buffer_info->skb = NULL; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2938 | do { |
| 2939 | struct sk_buff *this = skb; |
| 2940 | skb = skb->prev; |
| 2941 | dev_kfree_skb(this); |
| 2942 | } while (skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2943 | } |
| 2944 | if (!rx_buffer_info->page) |
| 2945 | continue; |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 2946 | if (rx_buffer_info->page_dma) { |
| 2947 | pci_unmap_page(pdev, rx_buffer_info->page_dma, |
| 2948 | PAGE_SIZE / 2, PCI_DMA_FROMDEVICE); |
| 2949 | rx_buffer_info->page_dma = 0; |
| 2950 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2951 | put_page(rx_buffer_info->page); |
| 2952 | rx_buffer_info->page = NULL; |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 2953 | rx_buffer_info->page_offset = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2954 | } |
| 2955 | |
| 2956 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 2957 | memset(rx_ring->rx_buffer_info, 0, size); |
| 2958 | |
| 2959 | /* Zero out the descriptor ring */ |
| 2960 | memset(rx_ring->desc, 0, rx_ring->size); |
| 2961 | |
| 2962 | rx_ring->next_to_clean = 0; |
| 2963 | rx_ring->next_to_use = 0; |
| 2964 | |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 2965 | if (rx_ring->head) |
| 2966 | writel(0, adapter->hw.hw_addr + rx_ring->head); |
| 2967 | if (rx_ring->tail) |
| 2968 | writel(0, adapter->hw.hw_addr + rx_ring->tail); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2969 | } |
| 2970 | |
| 2971 | /** |
| 2972 | * ixgbe_clean_tx_ring - Free Tx Buffers |
| 2973 | * @adapter: board private structure |
| 2974 | * @tx_ring: ring to be cleaned |
| 2975 | **/ |
| 2976 | static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2977 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2978 | { |
| 2979 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 2980 | unsigned long size; |
| 2981 | unsigned int i; |
| 2982 | |
| 2983 | /* Free all the Tx ring sk_buffs */ |
| 2984 | |
| 2985 | for (i = 0; i < tx_ring->count; i++) { |
| 2986 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 2987 | ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info); |
| 2988 | } |
| 2989 | |
| 2990 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 2991 | memset(tx_ring->tx_buffer_info, 0, size); |
| 2992 | |
| 2993 | /* Zero out the descriptor ring */ |
| 2994 | memset(tx_ring->desc, 0, tx_ring->size); |
| 2995 | |
| 2996 | tx_ring->next_to_use = 0; |
| 2997 | tx_ring->next_to_clean = 0; |
| 2998 | |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 2999 | if (tx_ring->head) |
| 3000 | writel(0, adapter->hw.hw_addr + tx_ring->head); |
| 3001 | if (tx_ring->tail) |
| 3002 | writel(0, adapter->hw.hw_addr + tx_ring->tail); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3003 | } |
| 3004 | |
| 3005 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3006 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 3007 | * @adapter: board private structure |
| 3008 | **/ |
| 3009 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 3010 | { |
| 3011 | int i; |
| 3012 | |
| 3013 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3014 | ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]); |
| 3015 | } |
| 3016 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3017 | /** |
| 3018 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 3019 | * @adapter: board private structure |
| 3020 | **/ |
| 3021 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 3022 | { |
| 3023 | int i; |
| 3024 | |
| 3025 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3026 | ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]); |
| 3027 | } |
| 3028 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3029 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 3030 | { |
| 3031 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3032 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3033 | u32 rxctrl; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3034 | u32 txdctl; |
| 3035 | int i, j; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3036 | |
| 3037 | /* signal that we are down to the interrupt handler */ |
| 3038 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 3039 | |
| 3040 | /* disable receives */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3041 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 3042 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3043 | |
| 3044 | netif_tx_disable(netdev); |
| 3045 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3046 | IXGBE_WRITE_FLUSH(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3047 | msleep(10); |
| 3048 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3049 | netif_tx_stop_all_queues(netdev); |
| 3050 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3051 | ixgbe_irq_disable(adapter); |
| 3052 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3053 | ixgbe_napi_disable_all(adapter); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3054 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 3055 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 3056 | del_timer_sync(&adapter->sfp_timer); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3057 | del_timer_sync(&adapter->watchdog_timer); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3058 | cancel_work_sync(&adapter->watchdog_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3059 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3060 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 3061 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 3062 | cancel_work_sync(&adapter->fdir_reinit_task); |
| 3063 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3064 | /* disable transmits in the hardware now that interrupts are off */ |
| 3065 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 3066 | j = adapter->tx_ring[i].reg_idx; |
| 3067 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
| 3068 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), |
| 3069 | (txdctl & ~IXGBE_TXDCTL_ENABLE)); |
| 3070 | } |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 3071 | /* Disable the Tx DMA engine on 82599 */ |
| 3072 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 3073 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
| 3074 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 3075 | ~IXGBE_DMATXCTL_TE)); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3076 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3077 | netif_carrier_off(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3078 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 3079 | if (!pci_channel_offline(adapter->pdev)) |
| 3080 | ixgbe_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3081 | ixgbe_clean_all_tx_rings(adapter); |
| 3082 | ixgbe_clean_all_rx_rings(adapter); |
| 3083 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 3084 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 3085 | /* since we reset the hardware DCA settings were cleared */ |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 3086 | ixgbe_setup_dca(adapter); |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 3087 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3088 | } |
| 3089 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3090 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3091 | * ixgbe_poll - NAPI Rx polling callback |
| 3092 | * @napi: structure for representing this polling device |
| 3093 | * @budget: how many packets driver is allowed to clean |
| 3094 | * |
| 3095 | * This function is used for legacy and MSI, NAPI mode |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3096 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3097 | static int ixgbe_poll(struct napi_struct *napi, int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3098 | { |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 3099 | struct ixgbe_q_vector *q_vector = |
| 3100 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3101 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 3102 | int tx_clean_complete, work_done = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3103 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 3104 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 3105 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 3106 | ixgbe_update_tx_dca(adapter, adapter->tx_ring); |
| 3107 | ixgbe_update_rx_dca(adapter, adapter->rx_ring); |
| 3108 | } |
| 3109 | #endif |
| 3110 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 3111 | tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring); |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 3112 | ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3113 | |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 3114 | if (!tx_clean_complete) |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 3115 | work_done = budget; |
| 3116 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 3117 | /* If budget not fully consumed, exit the polling mode */ |
| 3118 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3119 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 3120 | if (adapter->rx_itr_setting & 1) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 3121 | ixgbe_set_itr(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3122 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 3123 | ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3124 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3125 | return work_done; |
| 3126 | } |
| 3127 | |
| 3128 | /** |
| 3129 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 3130 | * @netdev: network interface device structure |
| 3131 | **/ |
| 3132 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 3133 | { |
| 3134 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3135 | |
| 3136 | /* Do the reset outside of interrupt context */ |
| 3137 | schedule_work(&adapter->reset_task); |
| 3138 | } |
| 3139 | |
| 3140 | static void ixgbe_reset_task(struct work_struct *work) |
| 3141 | { |
| 3142 | struct ixgbe_adapter *adapter; |
| 3143 | adapter = container_of(work, struct ixgbe_adapter, reset_task); |
| 3144 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3145 | /* If we're already down or resetting, just bail */ |
| 3146 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 3147 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 3148 | return; |
| 3149 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3150 | adapter->tx_timeout_count++; |
| 3151 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3152 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3153 | } |
| 3154 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3155 | #ifdef CONFIG_IXGBE_DCB |
| 3156 | static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3157 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3158 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3159 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB]; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3160 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3161 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) |
| 3162 | return ret; |
| 3163 | |
| 3164 | f->mask = 0x7 << 3; |
| 3165 | adapter->num_rx_queues = f->indices; |
| 3166 | adapter->num_tx_queues = f->indices; |
| 3167 | ret = true; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3168 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3169 | return ret; |
| 3170 | } |
| 3171 | #endif |
| 3172 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3173 | /** |
| 3174 | * ixgbe_set_rss_queues: Allocate queues for RSS |
| 3175 | * @adapter: board private structure to initialize |
| 3176 | * |
| 3177 | * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try |
| 3178 | * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU. |
| 3179 | * |
| 3180 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3181 | static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter) |
| 3182 | { |
| 3183 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3184 | 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] | 3185 | |
| 3186 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3187 | f->mask = 0xF; |
| 3188 | adapter->num_rx_queues = f->indices; |
| 3189 | adapter->num_tx_queues = f->indices; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3190 | ret = true; |
| 3191 | } else { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3192 | ret = false; |
| 3193 | } |
| 3194 | |
| 3195 | return ret; |
| 3196 | } |
| 3197 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3198 | /** |
| 3199 | * ixgbe_set_fdir_queues: Allocate queues for Flow Director |
| 3200 | * @adapter: board private structure to initialize |
| 3201 | * |
| 3202 | * Flow Director is an advanced Rx filter, attempting to get Rx flows back |
| 3203 | * to the original CPU that initiated the Tx session. This runs in addition |
| 3204 | * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the |
| 3205 | * Rx load across CPUs using RSS. |
| 3206 | * |
| 3207 | **/ |
| 3208 | static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter) |
| 3209 | { |
| 3210 | bool ret = false; |
| 3211 | struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR]; |
| 3212 | |
| 3213 | f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices); |
| 3214 | f_fdir->mask = 0; |
| 3215 | |
| 3216 | /* Flow Director must have RSS enabled */ |
| 3217 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED && |
| 3218 | ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 3219 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) { |
| 3220 | adapter->num_tx_queues = f_fdir->indices; |
| 3221 | adapter->num_rx_queues = f_fdir->indices; |
| 3222 | ret = true; |
| 3223 | } else { |
| 3224 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3225 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 3226 | } |
| 3227 | return ret; |
| 3228 | } |
| 3229 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3230 | #ifdef IXGBE_FCOE |
| 3231 | /** |
| 3232 | * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE) |
| 3233 | * @adapter: board private structure to initialize |
| 3234 | * |
| 3235 | * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges. |
| 3236 | * The ring feature mask is not used as a mask for FCoE, as it can take any 8 |
| 3237 | * rx queues out of the max number of rx queues, instead, it is used as the |
| 3238 | * index of the first rx queue used by FCoE. |
| 3239 | * |
| 3240 | **/ |
| 3241 | static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter) |
| 3242 | { |
| 3243 | bool ret = false; |
| 3244 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 3245 | |
| 3246 | f->indices = min((int)num_online_cpus(), f->indices); |
| 3247 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3248 | adapter->num_rx_queues = 1; |
| 3249 | adapter->num_tx_queues = 1; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3250 | #ifdef CONFIG_IXGBE_DCB |
| 3251 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3252 | DPRINTK(PROBE, INFO, "FCoE enabled with DCB \n"); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3253 | ixgbe_set_dcb_queues(adapter); |
| 3254 | } |
| 3255 | #endif |
| 3256 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3257 | DPRINTK(PROBE, INFO, "FCoE enabled with RSS \n"); |
Yi Zou | 8faa2a7 | 2009-07-09 02:29:50 +0000 | [diff] [blame] | 3258 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 3259 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 3260 | ixgbe_set_fdir_queues(adapter); |
| 3261 | else |
| 3262 | ixgbe_set_rss_queues(adapter); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3263 | } |
| 3264 | /* adding FCoE rx rings to the end */ |
| 3265 | f->mask = adapter->num_rx_queues; |
| 3266 | adapter->num_rx_queues += f->indices; |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3267 | adapter->num_tx_queues += f->indices; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3268 | |
| 3269 | ret = true; |
| 3270 | } |
| 3271 | |
| 3272 | return ret; |
| 3273 | } |
| 3274 | |
| 3275 | #endif /* IXGBE_FCOE */ |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3276 | /* |
| 3277 | * ixgbe_set_num_queues: Allocate queues for device, feature dependant |
| 3278 | * @adapter: board private structure to initialize |
| 3279 | * |
| 3280 | * This is the top level queue allocation routine. The order here is very |
| 3281 | * important, starting with the "most" number of features turned on at once, |
| 3282 | * and ending with the smallest set of features. This way large combinations |
| 3283 | * can be allocated if they're turned on, and smaller combinations are the |
| 3284 | * fallthrough conditions. |
| 3285 | * |
| 3286 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3287 | static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter) |
| 3288 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3289 | #ifdef IXGBE_FCOE |
| 3290 | if (ixgbe_set_fcoe_queues(adapter)) |
| 3291 | goto done; |
| 3292 | |
| 3293 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3294 | #ifdef CONFIG_IXGBE_DCB |
| 3295 | if (ixgbe_set_dcb_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 3296 | goto done; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3297 | |
| 3298 | #endif |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3299 | if (ixgbe_set_fdir_queues(adapter)) |
| 3300 | goto done; |
| 3301 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3302 | if (ixgbe_set_rss_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 3303 | goto done; |
| 3304 | |
| 3305 | /* fallback to base case */ |
| 3306 | adapter->num_rx_queues = 1; |
| 3307 | adapter->num_tx_queues = 1; |
| 3308 | |
| 3309 | done: |
| 3310 | /* Notify the stack of the (possibly) reduced Tx Queue count. */ |
| 3311 | adapter->netdev->real_num_tx_queues = adapter->num_tx_queues; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3312 | } |
| 3313 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3314 | static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3315 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3316 | { |
| 3317 | int err, vector_threshold; |
| 3318 | |
| 3319 | /* We'll want at least 3 (vector_threshold): |
| 3320 | * 1) TxQ[0] Cleanup |
| 3321 | * 2) RxQ[0] Cleanup |
| 3322 | * 3) Other (Link Status Change, etc.) |
| 3323 | * 4) TCP Timer (optional) |
| 3324 | */ |
| 3325 | vector_threshold = MIN_MSIX_COUNT; |
| 3326 | |
| 3327 | /* The more we get, the more we will assign to Tx/Rx Cleanup |
| 3328 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 3329 | * Right now, we simply care about how many we'll get; we'll |
| 3330 | * set them up later while requesting irq's. |
| 3331 | */ |
| 3332 | while (vectors >= vector_threshold) { |
| 3333 | err = pci_enable_msix(adapter->pdev, adapter->msix_entries, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3334 | vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3335 | if (!err) /* Success in acquiring all requested vectors. */ |
| 3336 | break; |
| 3337 | else if (err < 0) |
| 3338 | vectors = 0; /* Nasty failure, quit now */ |
| 3339 | else /* err == number of vectors we should try again with */ |
| 3340 | vectors = err; |
| 3341 | } |
| 3342 | |
| 3343 | if (vectors < vector_threshold) { |
| 3344 | /* Can't allocate enough MSI-X interrupts? Oh well. |
| 3345 | * This just means we'll go with either a single MSI |
| 3346 | * vector or fall back to legacy interrupts. |
| 3347 | */ |
| 3348 | DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n"); |
| 3349 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 3350 | kfree(adapter->msix_entries); |
| 3351 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3352 | } else { |
| 3353 | adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */ |
Peter P Waskiewicz Jr | eb7f139 | 2009-02-01 01:18:58 -0800 | [diff] [blame] | 3354 | /* |
| 3355 | * Adjust for only the vectors we'll use, which is minimum |
| 3356 | * of max_msix_q_vectors + NON_Q_VECTORS, or the number of |
| 3357 | * vectors we were allocated. |
| 3358 | */ |
| 3359 | adapter->num_msix_vectors = min(vectors, |
| 3360 | adapter->max_msix_q_vectors + NON_Q_VECTORS); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3361 | } |
| 3362 | } |
| 3363 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3364 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3365 | * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3366 | * @adapter: board private structure to initialize |
| 3367 | * |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3368 | * Cache the descriptor ring offsets for RSS to the assigned rings. |
| 3369 | * |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3370 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3371 | static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3372 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3373 | int i; |
| 3374 | bool ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3375 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3376 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 3377 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3378 | adapter->rx_ring[i].reg_idx = i; |
| 3379 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3380 | adapter->tx_ring[i].reg_idx = i; |
| 3381 | ret = true; |
| 3382 | } else { |
| 3383 | ret = false; |
| 3384 | } |
| 3385 | |
| 3386 | return ret; |
| 3387 | } |
| 3388 | |
| 3389 | #ifdef CONFIG_IXGBE_DCB |
| 3390 | /** |
| 3391 | * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB |
| 3392 | * @adapter: board private structure to initialize |
| 3393 | * |
| 3394 | * Cache the descriptor ring offsets for DCB to the assigned rings. |
| 3395 | * |
| 3396 | **/ |
| 3397 | static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter) |
| 3398 | { |
| 3399 | int i; |
| 3400 | bool ret = false; |
| 3401 | int dcb_i = adapter->ring_feature[RING_F_DCB].indices; |
| 3402 | |
| 3403 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 3404 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3405 | /* the number of queues is assumed to be symmetric */ |
| 3406 | for (i = 0; i < dcb_i; i++) { |
| 3407 | adapter->rx_ring[i].reg_idx = i << 3; |
| 3408 | adapter->tx_ring[i].reg_idx = i << 2; |
| 3409 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3410 | ret = true; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3411 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | f92ef20 | 2009-04-16 15:00:20 +0000 | [diff] [blame] | 3412 | if (dcb_i == 8) { |
| 3413 | /* |
| 3414 | * Tx TC0 starts at: descriptor queue 0 |
| 3415 | * Tx TC1 starts at: descriptor queue 32 |
| 3416 | * Tx TC2 starts at: descriptor queue 64 |
| 3417 | * Tx TC3 starts at: descriptor queue 80 |
| 3418 | * Tx TC4 starts at: descriptor queue 96 |
| 3419 | * Tx TC5 starts at: descriptor queue 104 |
| 3420 | * Tx TC6 starts at: descriptor queue 112 |
| 3421 | * Tx TC7 starts at: descriptor queue 120 |
| 3422 | * |
| 3423 | * Rx TC0-TC7 are offset by 16 queues each |
| 3424 | */ |
| 3425 | for (i = 0; i < 3; i++) { |
| 3426 | adapter->tx_ring[i].reg_idx = i << 5; |
| 3427 | adapter->rx_ring[i].reg_idx = i << 4; |
| 3428 | } |
| 3429 | for ( ; i < 5; i++) { |
| 3430 | adapter->tx_ring[i].reg_idx = |
| 3431 | ((i + 2) << 4); |
| 3432 | adapter->rx_ring[i].reg_idx = i << 4; |
| 3433 | } |
| 3434 | for ( ; i < dcb_i; i++) { |
| 3435 | adapter->tx_ring[i].reg_idx = |
| 3436 | ((i + 8) << 3); |
| 3437 | adapter->rx_ring[i].reg_idx = i << 4; |
| 3438 | } |
| 3439 | |
| 3440 | ret = true; |
| 3441 | } else if (dcb_i == 4) { |
| 3442 | /* |
| 3443 | * Tx TC0 starts at: descriptor queue 0 |
| 3444 | * Tx TC1 starts at: descriptor queue 64 |
| 3445 | * Tx TC2 starts at: descriptor queue 96 |
| 3446 | * Tx TC3 starts at: descriptor queue 112 |
| 3447 | * |
| 3448 | * Rx TC0-TC3 are offset by 32 queues each |
| 3449 | */ |
| 3450 | adapter->tx_ring[0].reg_idx = 0; |
| 3451 | adapter->tx_ring[1].reg_idx = 64; |
| 3452 | adapter->tx_ring[2].reg_idx = 96; |
| 3453 | adapter->tx_ring[3].reg_idx = 112; |
| 3454 | for (i = 0 ; i < dcb_i; i++) |
| 3455 | adapter->rx_ring[i].reg_idx = i << 5; |
| 3456 | |
| 3457 | ret = true; |
| 3458 | } else { |
| 3459 | ret = false; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3460 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3461 | } else { |
| 3462 | ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3463 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3464 | } else { |
| 3465 | ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3466 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3467 | |
| 3468 | return ret; |
| 3469 | } |
| 3470 | #endif |
| 3471 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3472 | /** |
| 3473 | * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director |
| 3474 | * @adapter: board private structure to initialize |
| 3475 | * |
| 3476 | * Cache the descriptor ring offsets for Flow Director to the assigned rings. |
| 3477 | * |
| 3478 | **/ |
| 3479 | static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter) |
| 3480 | { |
| 3481 | int i; |
| 3482 | bool ret = false; |
| 3483 | |
| 3484 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED && |
| 3485 | ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 3486 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) { |
| 3487 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3488 | adapter->rx_ring[i].reg_idx = i; |
| 3489 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3490 | adapter->tx_ring[i].reg_idx = i; |
| 3491 | ret = true; |
| 3492 | } |
| 3493 | |
| 3494 | return ret; |
| 3495 | } |
| 3496 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3497 | #ifdef IXGBE_FCOE |
| 3498 | /** |
| 3499 | * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE |
| 3500 | * @adapter: board private structure to initialize |
| 3501 | * |
| 3502 | * Cache the descriptor ring offsets for FCoE mode to the assigned rings. |
| 3503 | * |
| 3504 | */ |
| 3505 | static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter) |
| 3506 | { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3507 | int i, fcoe_rx_i = 0, fcoe_tx_i = 0; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3508 | bool ret = false; |
| 3509 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 3510 | |
| 3511 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 3512 | #ifdef CONFIG_IXGBE_DCB |
| 3513 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3514 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
| 3515 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3516 | ixgbe_cache_ring_dcb(adapter); |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3517 | /* find out queues in TC for FCoE */ |
| 3518 | fcoe_rx_i = adapter->rx_ring[fcoe->tc].reg_idx + 1; |
| 3519 | fcoe_tx_i = adapter->tx_ring[fcoe->tc].reg_idx + 1; |
| 3520 | /* |
| 3521 | * In 82599, the number of Tx queues for each traffic |
| 3522 | * class for both 8-TC and 4-TC modes are: |
| 3523 | * TCs : TC0 TC1 TC2 TC3 TC4 TC5 TC6 TC7 |
| 3524 | * 8 TCs: 32 32 16 16 8 8 8 8 |
| 3525 | * 4 TCs: 64 64 32 32 |
| 3526 | * We have max 8 queues for FCoE, where 8 the is |
| 3527 | * FCoE redirection table size. If TC for FCoE is |
| 3528 | * less than or equal to TC3, we have enough queues |
| 3529 | * to add max of 8 queues for FCoE, so we start FCoE |
| 3530 | * tx descriptor from the next one, i.e., reg_idx + 1. |
| 3531 | * If TC for FCoE is above TC3, implying 8 TC mode, |
| 3532 | * and we need 8 for FCoE, we have to take all queues |
| 3533 | * in that traffic class for FCoE. |
| 3534 | */ |
| 3535 | if ((f->indices == IXGBE_FCRETA_SIZE) && (fcoe->tc > 3)) |
| 3536 | fcoe_tx_i--; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3537 | } |
| 3538 | #endif /* CONFIG_IXGBE_DCB */ |
| 3539 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Yi Zou | 8faa2a7 | 2009-07-09 02:29:50 +0000 | [diff] [blame] | 3540 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 3541 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 3542 | ixgbe_cache_ring_fdir(adapter); |
| 3543 | else |
| 3544 | ixgbe_cache_ring_rss(adapter); |
| 3545 | |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3546 | fcoe_rx_i = f->mask; |
| 3547 | fcoe_tx_i = f->mask; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3548 | } |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3549 | for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) { |
| 3550 | adapter->rx_ring[f->mask + i].reg_idx = fcoe_rx_i; |
| 3551 | adapter->tx_ring[f->mask + i].reg_idx = fcoe_tx_i; |
| 3552 | } |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3553 | ret = true; |
| 3554 | } |
| 3555 | return ret; |
| 3556 | } |
| 3557 | |
| 3558 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3559 | /** |
| 3560 | * ixgbe_cache_ring_register - Descriptor ring to register mapping |
| 3561 | * @adapter: board private structure to initialize |
| 3562 | * |
| 3563 | * Once we know the feature-set enabled for the device, we'll cache |
| 3564 | * the register offset the descriptor ring is assigned to. |
| 3565 | * |
| 3566 | * Note, the order the various feature calls is important. It must start with |
| 3567 | * the "most" features enabled at the same time, then trickle down to the |
| 3568 | * least amount of features turned on at once. |
| 3569 | **/ |
| 3570 | static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) |
| 3571 | { |
| 3572 | /* start with default case */ |
| 3573 | adapter->rx_ring[0].reg_idx = 0; |
| 3574 | adapter->tx_ring[0].reg_idx = 0; |
| 3575 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3576 | #ifdef IXGBE_FCOE |
| 3577 | if (ixgbe_cache_ring_fcoe(adapter)) |
| 3578 | return; |
| 3579 | |
| 3580 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3581 | #ifdef CONFIG_IXGBE_DCB |
| 3582 | if (ixgbe_cache_ring_dcb(adapter)) |
| 3583 | return; |
| 3584 | |
| 3585 | #endif |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3586 | if (ixgbe_cache_ring_fdir(adapter)) |
| 3587 | return; |
| 3588 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3589 | if (ixgbe_cache_ring_rss(adapter)) |
| 3590 | return; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3591 | } |
| 3592 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3593 | /** |
| 3594 | * ixgbe_alloc_queues - Allocate memory for all rings |
| 3595 | * @adapter: board private structure to initialize |
| 3596 | * |
| 3597 | * 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] | 3598 | * number of queues at compile-time. The polling_netdev array is |
| 3599 | * intended for Multiqueue, but should work fine with a single queue. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3600 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3601 | static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3602 | { |
| 3603 | int i; |
| 3604 | |
| 3605 | adapter->tx_ring = kcalloc(adapter->num_tx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3606 | sizeof(struct ixgbe_ring), GFP_KERNEL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3607 | if (!adapter->tx_ring) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3608 | goto err_tx_ring_allocation; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3609 | |
| 3610 | adapter->rx_ring = kcalloc(adapter->num_rx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3611 | sizeof(struct ixgbe_ring), GFP_KERNEL); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3612 | if (!adapter->rx_ring) |
| 3613 | goto err_rx_ring_allocation; |
| 3614 | |
| 3615 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3616 | adapter->tx_ring[i].count = adapter->tx_ring_count; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3617 | adapter->tx_ring[i].queue_index = i; |
| 3618 | } |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3619 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3620 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3621 | adapter->rx_ring[i].count = adapter->rx_ring_count; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3622 | adapter->rx_ring[i].queue_index = i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3623 | } |
| 3624 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3625 | ixgbe_cache_ring_register(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3626 | |
| 3627 | return 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3628 | |
| 3629 | err_rx_ring_allocation: |
| 3630 | kfree(adapter->tx_ring); |
| 3631 | err_tx_ring_allocation: |
| 3632 | return -ENOMEM; |
| 3633 | } |
| 3634 | |
| 3635 | /** |
| 3636 | * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported |
| 3637 | * @adapter: board private structure to initialize |
| 3638 | * |
| 3639 | * Attempt to configure the interrupts using the best available |
| 3640 | * capabilities of the hardware and the kernel. |
| 3641 | **/ |
Al Viro | feea6a5 | 2008-11-27 15:34:07 -0800 | [diff] [blame] | 3642 | static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3643 | { |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3644 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3645 | int err = 0; |
| 3646 | int vector, v_budget; |
| 3647 | |
| 3648 | /* |
| 3649 | * It's easy to be greedy for MSI-X vectors, but it really |
| 3650 | * doesn't do us much good if we have a lot more vectors |
| 3651 | * than CPU's. So let's be conservative and only ask for |
PJ Waskiewicz | 342bde1 | 2009-11-12 23:50:43 +0000 | [diff] [blame] | 3652 | * (roughly) the same number of vectors as there are CPU's. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3653 | */ |
| 3654 | v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues, |
PJ Waskiewicz | 342bde1 | 2009-11-12 23:50:43 +0000 | [diff] [blame] | 3655 | (int)num_online_cpus()) + NON_Q_VECTORS; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3656 | |
| 3657 | /* |
| 3658 | * At the same time, hardware can only support a maximum of |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3659 | * hw.mac->max_msix_vectors vectors. With features |
| 3660 | * such as RSS and VMDq, we can easily surpass the number of Rx and Tx |
| 3661 | * descriptor queues supported by our device. Thus, we cap it off in |
| 3662 | * those rare cases where the cpu count also exceeds our vector limit. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3663 | */ |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3664 | v_budget = min(v_budget, (int)hw->mac.max_msix_vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3665 | |
| 3666 | /* A failure in MSI-X entry allocation isn't fatal, but it does |
| 3667 | * mean we disable MSI-X capabilities of the adapter. */ |
| 3668 | adapter->msix_entries = kcalloc(v_budget, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3669 | sizeof(struct msix_entry), GFP_KERNEL); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3670 | if (adapter->msix_entries) { |
| 3671 | for (vector = 0; vector < v_budget; vector++) |
| 3672 | adapter->msix_entries[vector].entry = vector; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3673 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3674 | ixgbe_acquire_msix_vectors(adapter, v_budget); |
| 3675 | |
| 3676 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 3677 | goto out; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3678 | } |
| 3679 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3680 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 3681 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3682 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3683 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 3684 | adapter->atr_sample_rate = 0; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3685 | ixgbe_set_num_queues(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3686 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3687 | err = pci_enable_msi(adapter->pdev); |
| 3688 | if (!err) { |
| 3689 | adapter->flags |= IXGBE_FLAG_MSI_ENABLED; |
| 3690 | } else { |
| 3691 | DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3692 | "falling back to legacy. Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3693 | /* reset err */ |
| 3694 | err = 0; |
| 3695 | } |
| 3696 | |
| 3697 | out: |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3698 | return err; |
| 3699 | } |
| 3700 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3701 | /** |
| 3702 | * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors |
| 3703 | * @adapter: board private structure to initialize |
| 3704 | * |
| 3705 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 3706 | * return -ENOMEM. |
| 3707 | **/ |
| 3708 | static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter) |
| 3709 | { |
| 3710 | int q_idx, num_q_vectors; |
| 3711 | struct ixgbe_q_vector *q_vector; |
| 3712 | int napi_vectors; |
| 3713 | int (*poll)(struct napi_struct *, int); |
| 3714 | |
| 3715 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 3716 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3717 | napi_vectors = adapter->num_rx_queues; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3718 | poll = &ixgbe_clean_rxtx_many; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3719 | } else { |
| 3720 | num_q_vectors = 1; |
| 3721 | napi_vectors = 1; |
| 3722 | poll = &ixgbe_poll; |
| 3723 | } |
| 3724 | |
| 3725 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
| 3726 | q_vector = kzalloc(sizeof(struct ixgbe_q_vector), GFP_KERNEL); |
| 3727 | if (!q_vector) |
| 3728 | goto err_out; |
| 3729 | q_vector->adapter = adapter; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 3730 | if (q_vector->txr_count && !q_vector->rxr_count) |
| 3731 | q_vector->eitr = adapter->tx_eitr_param; |
| 3732 | else |
| 3733 | q_vector->eitr = adapter->rx_eitr_param; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 3734 | q_vector->v_idx = q_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3735 | netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3736 | adapter->q_vector[q_idx] = q_vector; |
| 3737 | } |
| 3738 | |
| 3739 | return 0; |
| 3740 | |
| 3741 | err_out: |
| 3742 | while (q_idx) { |
| 3743 | q_idx--; |
| 3744 | q_vector = adapter->q_vector[q_idx]; |
| 3745 | netif_napi_del(&q_vector->napi); |
| 3746 | kfree(q_vector); |
| 3747 | adapter->q_vector[q_idx] = NULL; |
| 3748 | } |
| 3749 | return -ENOMEM; |
| 3750 | } |
| 3751 | |
| 3752 | /** |
| 3753 | * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors |
| 3754 | * @adapter: board private structure to initialize |
| 3755 | * |
| 3756 | * This function frees the memory allocated to the q_vectors. In addition if |
| 3757 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 3758 | * to freeing the q_vector. |
| 3759 | **/ |
| 3760 | static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter) |
| 3761 | { |
| 3762 | int q_idx, num_q_vectors; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3763 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3764 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3765 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3766 | else |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3767 | num_q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3768 | |
| 3769 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
| 3770 | struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx]; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3771 | adapter->q_vector[q_idx] = NULL; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3772 | netif_napi_del(&q_vector->napi); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3773 | kfree(q_vector); |
| 3774 | } |
| 3775 | } |
| 3776 | |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 3777 | static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3778 | { |
| 3779 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 3780 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 3781 | pci_disable_msix(adapter->pdev); |
| 3782 | kfree(adapter->msix_entries); |
| 3783 | adapter->msix_entries = NULL; |
| 3784 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 3785 | adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED; |
| 3786 | pci_disable_msi(adapter->pdev); |
| 3787 | } |
| 3788 | return; |
| 3789 | } |
| 3790 | |
| 3791 | /** |
| 3792 | * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme |
| 3793 | * @adapter: board private structure to initialize |
| 3794 | * |
| 3795 | * We determine which interrupt scheme to use based on... |
| 3796 | * - Kernel support (MSI, MSI-X) |
| 3797 | * - which can be user-defined (via MODULE_PARAM) |
| 3798 | * - Hardware queue count (num_*_queues) |
| 3799 | * - defined by miscellaneous hardware support/features (RSS, etc.) |
| 3800 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3801 | int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3802 | { |
| 3803 | int err; |
| 3804 | |
| 3805 | /* Number of supported queues */ |
| 3806 | ixgbe_set_num_queues(adapter); |
| 3807 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3808 | err = ixgbe_set_interrupt_capability(adapter); |
| 3809 | if (err) { |
| 3810 | DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n"); |
| 3811 | goto err_set_interrupt; |
| 3812 | } |
| 3813 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3814 | err = ixgbe_alloc_q_vectors(adapter); |
| 3815 | if (err) { |
| 3816 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queue " |
| 3817 | "vectors\n"); |
| 3818 | goto err_alloc_q_vectors; |
| 3819 | } |
| 3820 | |
| 3821 | err = ixgbe_alloc_queues(adapter); |
| 3822 | if (err) { |
| 3823 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n"); |
| 3824 | goto err_alloc_queues; |
| 3825 | } |
| 3826 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3827 | DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3828 | "Tx Queue count = %u\n", |
| 3829 | (adapter->num_rx_queues > 1) ? "Enabled" : |
| 3830 | "Disabled", adapter->num_rx_queues, adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3831 | |
| 3832 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 3833 | |
| 3834 | return 0; |
| 3835 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3836 | err_alloc_queues: |
| 3837 | ixgbe_free_q_vectors(adapter); |
| 3838 | err_alloc_q_vectors: |
| 3839 | ixgbe_reset_interrupt_capability(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3840 | err_set_interrupt: |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3841 | return err; |
| 3842 | } |
| 3843 | |
| 3844 | /** |
| 3845 | * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 3846 | * @adapter: board private structure to clear interrupt scheme on |
| 3847 | * |
| 3848 | * We go through and clear interrupt specific resources and reset the structure |
| 3849 | * to pre-load conditions |
| 3850 | **/ |
| 3851 | void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter) |
| 3852 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3853 | kfree(adapter->tx_ring); |
| 3854 | kfree(adapter->rx_ring); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3855 | adapter->tx_ring = NULL; |
| 3856 | adapter->rx_ring = NULL; |
| 3857 | |
| 3858 | ixgbe_free_q_vectors(adapter); |
| 3859 | ixgbe_reset_interrupt_capability(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3860 | } |
| 3861 | |
| 3862 | /** |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3863 | * ixgbe_sfp_timer - worker thread to find a missing module |
| 3864 | * @data: pointer to our adapter struct |
| 3865 | **/ |
| 3866 | static void ixgbe_sfp_timer(unsigned long data) |
| 3867 | { |
| 3868 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 3869 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3870 | /* |
| 3871 | * Do the sfp_timer outside of interrupt context due to the |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3872 | * delays that sfp+ detection requires |
| 3873 | */ |
| 3874 | schedule_work(&adapter->sfp_task); |
| 3875 | } |
| 3876 | |
| 3877 | /** |
| 3878 | * ixgbe_sfp_task - worker thread to find a missing module |
| 3879 | * @work: pointer to work_struct containing our data |
| 3880 | **/ |
| 3881 | static void ixgbe_sfp_task(struct work_struct *work) |
| 3882 | { |
| 3883 | struct ixgbe_adapter *adapter = container_of(work, |
| 3884 | struct ixgbe_adapter, |
| 3885 | sfp_task); |
| 3886 | struct ixgbe_hw *hw = &adapter->hw; |
| 3887 | |
| 3888 | if ((hw->phy.type == ixgbe_phy_nl) && |
| 3889 | (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) { |
| 3890 | s32 ret = hw->phy.ops.identify_sfp(hw); |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 3891 | if (ret == IXGBE_ERR_SFP_NOT_PRESENT) |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3892 | goto reschedule; |
| 3893 | ret = hw->phy.ops.reset(hw); |
| 3894 | if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 88d2b81 | 2009-06-30 11:43:55 +0000 | [diff] [blame] | 3895 | dev_err(&adapter->pdev->dev, "failed to initialize " |
| 3896 | "because an unsupported SFP+ module type " |
| 3897 | "was detected.\n" |
| 3898 | "Reload the driver after installing a " |
| 3899 | "supported module.\n"); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3900 | unregister_netdev(adapter->netdev); |
| 3901 | } else { |
| 3902 | DPRINTK(PROBE, INFO, "detected SFP+: %d\n", |
| 3903 | hw->phy.sfp_type); |
| 3904 | } |
| 3905 | /* don't need this routine any more */ |
| 3906 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 3907 | } |
| 3908 | return; |
| 3909 | reschedule: |
| 3910 | if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state)) |
| 3911 | mod_timer(&adapter->sfp_timer, |
| 3912 | round_jiffies(jiffies + (2 * HZ))); |
| 3913 | } |
| 3914 | |
| 3915 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3916 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 3917 | * @adapter: board private structure to initialize |
| 3918 | * |
| 3919 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 3920 | * Fields are initialized based on PCI device information and |
| 3921 | * OS network device settings (MTU size). |
| 3922 | **/ |
| 3923 | static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter) |
| 3924 | { |
| 3925 | struct ixgbe_hw *hw = &adapter->hw; |
| 3926 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3927 | unsigned int rss; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3928 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3929 | int j; |
| 3930 | struct tc_configuration *tc; |
| 3931 | #endif |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3932 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3933 | /* PCI config space info */ |
| 3934 | |
| 3935 | hw->vendor_id = pdev->vendor; |
| 3936 | hw->device_id = pdev->device; |
| 3937 | hw->revision_id = pdev->revision; |
| 3938 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 3939 | hw->subsystem_device_id = pdev->subsystem_device; |
| 3940 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3941 | /* Set capability flags */ |
| 3942 | rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus()); |
| 3943 | adapter->ring_feature[RING_F_RSS].indices = rss; |
| 3944 | adapter->flags |= IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3945 | adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES; |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3946 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3947 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 3948 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3949 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598; |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3950 | } else if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3951 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 3952 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
| 3953 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3954 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3955 | adapter->ring_feature[RING_F_FDIR].indices = |
| 3956 | IXGBE_MAX_FDIR_INDICES; |
| 3957 | adapter->atr_sample_rate = 20; |
| 3958 | adapter->fdir_pballoc = 0; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 3959 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 3960 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 3961 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 3962 | adapter->ring_feature[RING_F_FCOE].indices = 0; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 3963 | #ifdef CONFIG_IXGBE_DCB |
Yi Zou | 6ee1652 | 2009-08-31 12:34:28 +0000 | [diff] [blame] | 3964 | /* Default traffic class to use for FCoE */ |
| 3965 | adapter->fcoe.tc = IXGBE_FCOE_DEFTC; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 3966 | #endif |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 3967 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3968 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3969 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3970 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3971 | /* Configure DCB traffic classes */ |
| 3972 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 3973 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 3974 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 3975 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 3976 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 3977 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 3978 | tc->dcb_pfc = pfc_disabled; |
| 3979 | } |
| 3980 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 3981 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
| 3982 | adapter->dcb_cfg.rx_pba_cfg = pba_equal; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 3983 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3984 | adapter->dcb_cfg.round_robin_enable = false; |
| 3985 | adapter->dcb_set_bitmap = 0x00; |
| 3986 | ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg, |
| 3987 | adapter->ring_feature[RING_F_DCB].indices); |
| 3988 | |
| 3989 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3990 | |
| 3991 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 3992 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 3993 | 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] | 3994 | #ifdef CONFIG_DCB |
| 3995 | adapter->last_lfc_mode = hw->fc.current_mode; |
| 3996 | #endif |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 3997 | hw->fc.high_water = IXGBE_DEFAULT_FCRTH; |
| 3998 | hw->fc.low_water = IXGBE_DEFAULT_FCRTL; |
| 3999 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 4000 | hw->fc.send_xon = true; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 4001 | hw->fc.disable_fc_autoneg = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4002 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 4003 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 4004 | adapter->rx_itr_setting = 1; |
| 4005 | adapter->rx_eitr_param = 20000; |
| 4006 | adapter->tx_itr_setting = 1; |
| 4007 | adapter->tx_eitr_param = 10000; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 4008 | |
| 4009 | /* set defaults for eitr in MegaBytes */ |
| 4010 | adapter->eitr_low = 10; |
| 4011 | adapter->eitr_high = 20; |
| 4012 | |
| 4013 | /* set default ring sizes */ |
| 4014 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 4015 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 4016 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4017 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4018 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4019 | dev_err(&pdev->dev, "EEPROM initialization failed\n"); |
| 4020 | return -EIO; |
| 4021 | } |
| 4022 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4023 | /* enable rx csum by default */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4024 | adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED; |
| 4025 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4026 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 4027 | |
| 4028 | return 0; |
| 4029 | } |
| 4030 | |
| 4031 | /** |
| 4032 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
| 4033 | * @adapter: board private structure |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4034 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4035 | * |
| 4036 | * Return 0 on success, negative on failure |
| 4037 | **/ |
| 4038 | int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4039 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4040 | { |
| 4041 | struct pci_dev *pdev = adapter->pdev; |
| 4042 | int size; |
| 4043 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4044 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 4045 | tx_ring->tx_buffer_info = vmalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4046 | if (!tx_ring->tx_buffer_info) |
| 4047 | goto err; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4048 | memset(tx_ring->tx_buffer_info, 0, size); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4049 | |
| 4050 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 4051 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4052 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4053 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4054 | tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size, |
| 4055 | &tx_ring->dma); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4056 | if (!tx_ring->desc) |
| 4057 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4058 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4059 | tx_ring->next_to_use = 0; |
| 4060 | tx_ring->next_to_clean = 0; |
| 4061 | tx_ring->work_limit = tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4062 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4063 | |
| 4064 | err: |
| 4065 | vfree(tx_ring->tx_buffer_info); |
| 4066 | tx_ring->tx_buffer_info = NULL; |
| 4067 | DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit " |
| 4068 | "descriptor ring\n"); |
| 4069 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4070 | } |
| 4071 | |
| 4072 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4073 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 4074 | * @adapter: board private structure |
| 4075 | * |
| 4076 | * If this function returns with an error, then it's possible one or |
| 4077 | * more of the rings is populated (while the rest are not). It is the |
| 4078 | * callers duty to clean those orphaned rings. |
| 4079 | * |
| 4080 | * Return 0 on success, negative on failure |
| 4081 | **/ |
| 4082 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 4083 | { |
| 4084 | int i, err = 0; |
| 4085 | |
| 4086 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 4087 | err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]); |
| 4088 | if (!err) |
| 4089 | continue; |
| 4090 | DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i); |
| 4091 | break; |
| 4092 | } |
| 4093 | |
| 4094 | return err; |
| 4095 | } |
| 4096 | |
| 4097 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4098 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
| 4099 | * @adapter: board private structure |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4100 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4101 | * |
| 4102 | * Returns 0 on success, negative on failure |
| 4103 | **/ |
| 4104 | int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4105 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4106 | { |
| 4107 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4108 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4109 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4110 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 4111 | rx_ring->rx_buffer_info = vmalloc(size); |
| 4112 | if (!rx_ring->rx_buffer_info) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4113 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4114 | "vmalloc allocation failed for the rx desc ring\n"); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4115 | goto alloc_failed; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4116 | } |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4117 | memset(rx_ring->rx_buffer_info, 0, size); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4118 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4119 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4120 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 4121 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4122 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4123 | 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] | 4124 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4125 | if (!rx_ring->desc) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4126 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4127 | "Memory allocation failed for the rx desc ring\n"); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4128 | vfree(rx_ring->rx_buffer_info); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4129 | goto alloc_failed; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4130 | } |
| 4131 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4132 | rx_ring->next_to_clean = 0; |
| 4133 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4134 | |
| 4135 | return 0; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4136 | |
| 4137 | alloc_failed: |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4138 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4139 | } |
| 4140 | |
| 4141 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4142 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 4143 | * @adapter: board private structure |
| 4144 | * |
| 4145 | * If this function returns with an error, then it's possible one or |
| 4146 | * more of the rings is populated (while the rest are not). It is the |
| 4147 | * callers duty to clean those orphaned rings. |
| 4148 | * |
| 4149 | * Return 0 on success, negative on failure |
| 4150 | **/ |
| 4151 | |
| 4152 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 4153 | { |
| 4154 | int i, err = 0; |
| 4155 | |
| 4156 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 4157 | err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]); |
| 4158 | if (!err) |
| 4159 | continue; |
| 4160 | DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i); |
| 4161 | break; |
| 4162 | } |
| 4163 | |
| 4164 | return err; |
| 4165 | } |
| 4166 | |
| 4167 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4168 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
| 4169 | * @adapter: board private structure |
| 4170 | * @tx_ring: Tx descriptor ring for a specific queue |
| 4171 | * |
| 4172 | * Free all transmit software resources |
| 4173 | **/ |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 4174 | void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter, |
| 4175 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4176 | { |
| 4177 | struct pci_dev *pdev = adapter->pdev; |
| 4178 | |
| 4179 | ixgbe_clean_tx_ring(adapter, tx_ring); |
| 4180 | |
| 4181 | vfree(tx_ring->tx_buffer_info); |
| 4182 | tx_ring->tx_buffer_info = NULL; |
| 4183 | |
| 4184 | pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); |
| 4185 | |
| 4186 | tx_ring->desc = NULL; |
| 4187 | } |
| 4188 | |
| 4189 | /** |
| 4190 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 4191 | * @adapter: board private structure |
| 4192 | * |
| 4193 | * Free all transmit software resources |
| 4194 | **/ |
| 4195 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 4196 | { |
| 4197 | int i; |
| 4198 | |
| 4199 | for (i = 0; i < adapter->num_tx_queues; i++) |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 4200 | if (adapter->tx_ring[i].desc) |
| 4201 | ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4202 | } |
| 4203 | |
| 4204 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4205 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4206 | * @adapter: board private structure |
| 4207 | * @rx_ring: ring to clean the resources from |
| 4208 | * |
| 4209 | * Free all receive software resources |
| 4210 | **/ |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 4211 | void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter, |
| 4212 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4213 | { |
| 4214 | struct pci_dev *pdev = adapter->pdev; |
| 4215 | |
| 4216 | ixgbe_clean_rx_ring(adapter, rx_ring); |
| 4217 | |
| 4218 | vfree(rx_ring->rx_buffer_info); |
| 4219 | rx_ring->rx_buffer_info = NULL; |
| 4220 | |
| 4221 | pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); |
| 4222 | |
| 4223 | rx_ring->desc = NULL; |
| 4224 | } |
| 4225 | |
| 4226 | /** |
| 4227 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 4228 | * @adapter: board private structure |
| 4229 | * |
| 4230 | * Free all receive software resources |
| 4231 | **/ |
| 4232 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 4233 | { |
| 4234 | int i; |
| 4235 | |
| 4236 | for (i = 0; i < adapter->num_rx_queues; i++) |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 4237 | if (adapter->rx_ring[i].desc) |
| 4238 | ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4239 | } |
| 4240 | |
| 4241 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4242 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 4243 | * @netdev: network interface device structure |
| 4244 | * @new_mtu: new value for maximum frame size |
| 4245 | * |
| 4246 | * Returns 0 on success, negative on failure |
| 4247 | **/ |
| 4248 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 4249 | { |
| 4250 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4251 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 4252 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 4253 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 4254 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4255 | return -EINVAL; |
| 4256 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4257 | DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n", |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4258 | netdev->mtu, new_mtu); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4259 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4260 | netdev->mtu = new_mtu; |
| 4261 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4262 | if (netif_running(netdev)) |
| 4263 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4264 | |
| 4265 | return 0; |
| 4266 | } |
| 4267 | |
| 4268 | /** |
| 4269 | * ixgbe_open - Called when a network interface is made active |
| 4270 | * @netdev: network interface device structure |
| 4271 | * |
| 4272 | * Returns 0 on success, negative value on failure |
| 4273 | * |
| 4274 | * The open entry point is called when a network interface is made |
| 4275 | * active by the system (IFF_UP). At this point all resources needed |
| 4276 | * for transmit and receive operations are allocated, the interrupt |
| 4277 | * handler is registered with the OS, the watchdog timer is started, |
| 4278 | * and the stack is notified that the interface is ready. |
| 4279 | **/ |
| 4280 | static int ixgbe_open(struct net_device *netdev) |
| 4281 | { |
| 4282 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4283 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4284 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 4285 | /* disallow open during test */ |
| 4286 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 4287 | return -EBUSY; |
| 4288 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 4289 | netif_carrier_off(netdev); |
| 4290 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4291 | /* allocate transmit descriptors */ |
| 4292 | err = ixgbe_setup_all_tx_resources(adapter); |
| 4293 | if (err) |
| 4294 | goto err_setup_tx; |
| 4295 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4296 | /* allocate receive descriptors */ |
| 4297 | err = ixgbe_setup_all_rx_resources(adapter); |
| 4298 | if (err) |
| 4299 | goto err_setup_rx; |
| 4300 | |
| 4301 | ixgbe_configure(adapter); |
| 4302 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4303 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4304 | if (err) |
| 4305 | goto err_req_irq; |
| 4306 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4307 | err = ixgbe_up_complete(adapter); |
| 4308 | if (err) |
| 4309 | goto err_up; |
| 4310 | |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 4311 | netif_tx_start_all_queues(netdev); |
| 4312 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4313 | return 0; |
| 4314 | |
| 4315 | err_up: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 4316 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4317 | ixgbe_free_irq(adapter); |
| 4318 | err_req_irq: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4319 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 4320 | ixgbe_free_all_rx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4321 | err_setup_tx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 4322 | ixgbe_free_all_tx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4323 | ixgbe_reset(adapter); |
| 4324 | |
| 4325 | return err; |
| 4326 | } |
| 4327 | |
| 4328 | /** |
| 4329 | * ixgbe_close - Disables a network interface |
| 4330 | * @netdev: network interface device structure |
| 4331 | * |
| 4332 | * Returns 0, this is not allowed to fail |
| 4333 | * |
| 4334 | * The close entry point is called when an interface is de-activated |
| 4335 | * by the OS. The hardware is still under the drivers control, but |
| 4336 | * needs to be disabled. A global MAC reset is issued to stop the |
| 4337 | * hardware, and all transmit and receive resources are freed. |
| 4338 | **/ |
| 4339 | static int ixgbe_close(struct net_device *netdev) |
| 4340 | { |
| 4341 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4342 | |
| 4343 | ixgbe_down(adapter); |
| 4344 | ixgbe_free_irq(adapter); |
| 4345 | |
| 4346 | ixgbe_free_all_tx_resources(adapter); |
| 4347 | ixgbe_free_all_rx_resources(adapter); |
| 4348 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 4349 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4350 | |
| 4351 | return 0; |
| 4352 | } |
| 4353 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4354 | #ifdef CONFIG_PM |
| 4355 | static int ixgbe_resume(struct pci_dev *pdev) |
| 4356 | { |
| 4357 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4358 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4359 | u32 err; |
| 4360 | |
| 4361 | pci_set_power_state(pdev, PCI_D0); |
| 4362 | pci_restore_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 4363 | |
| 4364 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4365 | if (err) { |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4366 | printk(KERN_ERR "ixgbe: Cannot enable PCI device from " |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4367 | "suspend\n"); |
| 4368 | return err; |
| 4369 | } |
| 4370 | pci_set_master(pdev); |
| 4371 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 4372 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4373 | |
| 4374 | err = ixgbe_init_interrupt_scheme(adapter); |
| 4375 | if (err) { |
| 4376 | printk(KERN_ERR "ixgbe: Cannot initialize interrupts for " |
| 4377 | "device\n"); |
| 4378 | return err; |
| 4379 | } |
| 4380 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4381 | ixgbe_reset(adapter); |
| 4382 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 4383 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 4384 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4385 | if (netif_running(netdev)) { |
| 4386 | err = ixgbe_open(adapter->netdev); |
| 4387 | if (err) |
| 4388 | return err; |
| 4389 | } |
| 4390 | |
| 4391 | netif_device_attach(netdev); |
| 4392 | |
| 4393 | return 0; |
| 4394 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4395 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4396 | |
| 4397 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4398 | { |
| 4399 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4400 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4401 | struct ixgbe_hw *hw = &adapter->hw; |
| 4402 | u32 ctrl, fctrl; |
| 4403 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4404 | #ifdef CONFIG_PM |
| 4405 | int retval = 0; |
| 4406 | #endif |
| 4407 | |
| 4408 | netif_device_detach(netdev); |
| 4409 | |
| 4410 | if (netif_running(netdev)) { |
| 4411 | ixgbe_down(adapter); |
| 4412 | ixgbe_free_irq(adapter); |
| 4413 | ixgbe_free_all_tx_resources(adapter); |
| 4414 | ixgbe_free_all_rx_resources(adapter); |
| 4415 | } |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4416 | ixgbe_clear_interrupt_scheme(adapter); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4417 | |
| 4418 | #ifdef CONFIG_PM |
| 4419 | retval = pci_save_state(pdev); |
| 4420 | if (retval) |
| 4421 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4422 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4423 | #endif |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4424 | if (wufc) { |
| 4425 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4426 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4427 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 4428 | if (wufc & IXGBE_WUFC_MC) { |
| 4429 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 4430 | fctrl |= IXGBE_FCTRL_MPE; |
| 4431 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 4432 | } |
| 4433 | |
| 4434 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 4435 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 4436 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 4437 | |
| 4438 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 4439 | } else { |
| 4440 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 4441 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 4442 | } |
| 4443 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 4444 | if (wufc && hw->mac.type == ixgbe_mac_82599EB) |
| 4445 | pci_wake_from_d3(pdev, true); |
| 4446 | else |
| 4447 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4448 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4449 | *enable_wake = !!wufc; |
| 4450 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4451 | ixgbe_release_hw_control(adapter); |
| 4452 | |
| 4453 | pci_disable_device(pdev); |
| 4454 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4455 | return 0; |
| 4456 | } |
| 4457 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4458 | #ifdef CONFIG_PM |
| 4459 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 4460 | { |
| 4461 | int retval; |
| 4462 | bool wake; |
| 4463 | |
| 4464 | retval = __ixgbe_shutdown(pdev, &wake); |
| 4465 | if (retval) |
| 4466 | return retval; |
| 4467 | |
| 4468 | if (wake) { |
| 4469 | pci_prepare_to_sleep(pdev); |
| 4470 | } else { |
| 4471 | pci_wake_from_d3(pdev, false); |
| 4472 | pci_set_power_state(pdev, PCI_D3hot); |
| 4473 | } |
| 4474 | |
| 4475 | return 0; |
| 4476 | } |
| 4477 | #endif /* CONFIG_PM */ |
| 4478 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4479 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 4480 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4481 | bool wake; |
| 4482 | |
| 4483 | __ixgbe_shutdown(pdev, &wake); |
| 4484 | |
| 4485 | if (system_state == SYSTEM_POWER_OFF) { |
| 4486 | pci_wake_from_d3(pdev, wake); |
| 4487 | pci_set_power_state(pdev, PCI_D3hot); |
| 4488 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4489 | } |
| 4490 | |
| 4491 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4492 | * ixgbe_update_stats - Update the board statistics counters. |
| 4493 | * @adapter: board private structure |
| 4494 | **/ |
| 4495 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 4496 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4497 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4498 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4499 | u64 total_mpc = 0; |
| 4500 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4501 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 4502 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 4503 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 4504 | u64 rsc_flush = 0; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 4505 | for (i = 0; i < 16; i++) |
| 4506 | adapter->hw_rx_no_dma_resources += |
| 4507 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 4508 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 4509 | rsc_count += adapter->rx_ring[i].rsc_count; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 4510 | rsc_flush += adapter->rx_ring[i].rsc_flush; |
| 4511 | } |
| 4512 | adapter->rsc_total_count = rsc_count; |
| 4513 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 4514 | } |
| 4515 | |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame^] | 4516 | /* gather some stats to the adapter struct that are per queue */ |
| 4517 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 4518 | adapter->restart_queue += adapter->tx_ring[i].restart_queue; |
| 4519 | |
| 4520 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4521 | adapter->non_eop_descs += adapter->tx_ring[i].non_eop_descs; |
| 4522 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4523 | adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4524 | for (i = 0; i < 8; i++) { |
| 4525 | /* for packet buffers not used, the register should read 0 */ |
| 4526 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 4527 | missed_rx += mpc; |
| 4528 | adapter->stats.mpc[i] += mpc; |
| 4529 | total_mpc += adapter->stats.mpc[i]; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4530 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4531 | adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4532 | adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 4533 | adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 4534 | adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 4535 | adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4536 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 4537 | adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw, |
| 4538 | IXGBE_PXONRXCNT(i)); |
| 4539 | adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw, |
| 4540 | IXGBE_PXOFFRXCNT(i)); |
| 4541 | adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4542 | } else { |
| 4543 | adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw, |
| 4544 | IXGBE_PXONRXC(i)); |
| 4545 | adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw, |
| 4546 | IXGBE_PXOFFRXC(i)); |
| 4547 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4548 | adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw, |
| 4549 | IXGBE_PXONTXC(i)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4550 | adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4551 | IXGBE_PXOFFTXC(i)); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4552 | } |
| 4553 | adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
| 4554 | /* work around hardware counting issue */ |
| 4555 | adapter->stats.gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4556 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4557 | /* 82598 hardware only has a 32 bit counter in the high register */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4558 | if (hw->mac.type == ixgbe_mac_82599EB) { |
Ben Greear | aad7191 | 2009-09-30 12:08:16 +0000 | [diff] [blame] | 4559 | u64 tmp; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4560 | adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Ben Greear | aad7191 | 2009-09-30 12:08:16 +0000 | [diff] [blame] | 4561 | tmp = IXGBE_READ_REG(hw, IXGBE_GORCH) & 0xF; /* 4 high bits of GORC */ |
| 4562 | adapter->stats.gorc += (tmp << 32); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4563 | adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Ben Greear | aad7191 | 2009-09-30 12:08:16 +0000 | [diff] [blame] | 4564 | tmp = IXGBE_READ_REG(hw, IXGBE_GOTCH) & 0xF; /* 4 high bits of GOTC */ |
| 4565 | adapter->stats.gotc += (tmp << 32); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4566 | adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
| 4567 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
| 4568 | adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
| 4569 | adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4570 | adapter->stats.fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 4571 | adapter->stats.fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 4572 | #ifdef IXGBE_FCOE |
| 4573 | adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 4574 | adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 4575 | adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 4576 | adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 4577 | adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 4578 | adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
| 4579 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4580 | } else { |
| 4581 | adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
| 4582 | adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 4583 | adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 4584 | adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 4585 | adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 4586 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4587 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
| 4588 | adapter->stats.bprc += bprc; |
| 4589 | adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4590 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4591 | adapter->stats.mprc -= bprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4592 | adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 4593 | adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 4594 | adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 4595 | adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 4596 | adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 4597 | adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 4598 | adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4599 | adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4600 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
| 4601 | adapter->stats.lxontxc += lxon; |
| 4602 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
| 4603 | adapter->stats.lxofftxc += lxoff; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4604 | adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 4605 | adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4606 | adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
| 4607 | /* |
| 4608 | * 82598 errata - tx of flow control packets is included in tx counters |
| 4609 | */ |
| 4610 | xon_off_tot = lxon + lxoff; |
| 4611 | adapter->stats.gptc -= xon_off_tot; |
| 4612 | adapter->stats.mptc -= xon_off_tot; |
| 4613 | adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4614 | adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 4615 | adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 4616 | adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4617 | adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 4618 | adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4619 | adapter->stats.ptc64 -= xon_off_tot; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4620 | adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 4621 | adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 4622 | adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 4623 | adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 4624 | adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4625 | adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
| 4626 | |
| 4627 | /* Fill out the OS statistics structure */ |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4628 | netdev->stats.multicast = adapter->stats.mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4629 | |
| 4630 | /* Rx Errors */ |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4631 | netdev->stats.rx_errors = adapter->stats.crcerrs + |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4632 | adapter->stats.rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4633 | netdev->stats.rx_dropped = 0; |
| 4634 | netdev->stats.rx_length_errors = adapter->stats.rlec; |
| 4635 | netdev->stats.rx_crc_errors = adapter->stats.crcerrs; |
| 4636 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4637 | } |
| 4638 | |
| 4639 | /** |
| 4640 | * ixgbe_watchdog - Timer Call-back |
| 4641 | * @data: pointer to adapter cast into an unsigned long |
| 4642 | **/ |
| 4643 | static void ixgbe_watchdog(unsigned long data) |
| 4644 | { |
| 4645 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4646 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4647 | u64 eics = 0; |
| 4648 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4649 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4650 | /* |
| 4651 | * Do the watchdog outside of interrupt context due to the lovely |
| 4652 | * delays that some of the newer hardware requires |
| 4653 | */ |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 4654 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4655 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 4656 | goto watchdog_short_circuit; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 4657 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4658 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
| 4659 | /* |
| 4660 | * for legacy and MSI interrupts don't set any bits |
| 4661 | * that are enabled for EIAM, because this operation |
| 4662 | * would set *both* EIMS and EICS for any bit in EIAM |
| 4663 | */ |
| 4664 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 4665 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
| 4666 | goto watchdog_reschedule; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4667 | } |
| 4668 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4669 | /* get one bit for every active tx/rx interrupt vector */ |
| 4670 | for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) { |
| 4671 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
| 4672 | if (qv->rxr_count || qv->txr_count) |
| 4673 | eics |= ((u64)1 << i); |
| 4674 | } |
| 4675 | |
| 4676 | /* Cause software interrupt to ensure rx rings are cleaned */ |
| 4677 | ixgbe_irq_rearm_queues(adapter, eics); |
| 4678 | |
| 4679 | watchdog_reschedule: |
| 4680 | /* Reset the timer */ |
| 4681 | mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ)); |
| 4682 | |
| 4683 | watchdog_short_circuit: |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4684 | schedule_work(&adapter->watchdog_task); |
| 4685 | } |
| 4686 | |
| 4687 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4688 | * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber |
| 4689 | * @work: pointer to work_struct containing our data |
| 4690 | **/ |
| 4691 | static void ixgbe_multispeed_fiber_task(struct work_struct *work) |
| 4692 | { |
| 4693 | struct ixgbe_adapter *adapter = container_of(work, |
| 4694 | struct ixgbe_adapter, |
| 4695 | multispeed_fiber_task); |
| 4696 | struct ixgbe_hw *hw = &adapter->hw; |
| 4697 | u32 autoneg; |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 4698 | bool negotiation; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4699 | |
| 4700 | adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK; |
Mallikarjuna R Chilakala | a1f2532 | 2009-06-30 11:44:36 +0000 | [diff] [blame] | 4701 | autoneg = hw->phy.autoneg_advertised; |
| 4702 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 4703 | hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
| 4704 | if (hw->mac.ops.setup_link) |
| 4705 | hw->mac.ops.setup_link(hw, autoneg, negotiation, true); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4706 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 4707 | adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK; |
| 4708 | } |
| 4709 | |
| 4710 | /** |
| 4711 | * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module |
| 4712 | * @work: pointer to work_struct containing our data |
| 4713 | **/ |
| 4714 | static void ixgbe_sfp_config_module_task(struct work_struct *work) |
| 4715 | { |
| 4716 | struct ixgbe_adapter *adapter = container_of(work, |
| 4717 | struct ixgbe_adapter, |
| 4718 | sfp_config_module_task); |
| 4719 | struct ixgbe_hw *hw = &adapter->hw; |
| 4720 | u32 err; |
| 4721 | |
| 4722 | adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK; |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 4723 | |
| 4724 | /* Time for electrical oscillations to settle down */ |
| 4725 | msleep(100); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4726 | err = hw->phy.ops.identify_sfp(hw); |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 4727 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4728 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 88d2b81 | 2009-06-30 11:43:55 +0000 | [diff] [blame] | 4729 | dev_err(&adapter->pdev->dev, "failed to initialize because " |
| 4730 | "an unsupported SFP+ module type was detected.\n" |
| 4731 | "Reload the driver after installing a supported " |
| 4732 | "module.\n"); |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 4733 | unregister_netdev(adapter->netdev); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4734 | return; |
| 4735 | } |
| 4736 | hw->mac.ops.setup_sfp(hw); |
| 4737 | |
Tony Breeds | 8d1c3c0 | 2009-04-09 22:29:10 +0000 | [diff] [blame] | 4738 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK)) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4739 | /* This will also work for DA Twinax connections */ |
| 4740 | schedule_work(&adapter->multispeed_fiber_task); |
| 4741 | adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK; |
| 4742 | } |
| 4743 | |
| 4744 | /** |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4745 | * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table |
| 4746 | * @work: pointer to work_struct containing our data |
| 4747 | **/ |
| 4748 | static void ixgbe_fdir_reinit_task(struct work_struct *work) |
| 4749 | { |
| 4750 | struct ixgbe_adapter *adapter = container_of(work, |
| 4751 | struct ixgbe_adapter, |
| 4752 | fdir_reinit_task); |
| 4753 | struct ixgbe_hw *hw = &adapter->hw; |
| 4754 | int i; |
| 4755 | |
| 4756 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 4757 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 4758 | set_bit(__IXGBE_FDIR_INIT_DONE, |
| 4759 | &(adapter->tx_ring[i].reinit_state)); |
| 4760 | } else { |
| 4761 | DPRINTK(PROBE, ERR, "failed to finish FDIR re-initialization, " |
| 4762 | "ignored adding FDIR ATR filters \n"); |
| 4763 | } |
| 4764 | /* Done FDIR Re-initialization, enable transmits */ |
| 4765 | netif_tx_start_all_queues(adapter->netdev); |
| 4766 | } |
| 4767 | |
| 4768 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4769 | * ixgbe_watchdog_task - worker thread to bring link up |
| 4770 | * @work: pointer to work_struct containing our data |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4771 | **/ |
| 4772 | static void ixgbe_watchdog_task(struct work_struct *work) |
| 4773 | { |
| 4774 | struct ixgbe_adapter *adapter = container_of(work, |
| 4775 | struct ixgbe_adapter, |
| 4776 | watchdog_task); |
| 4777 | struct net_device *netdev = adapter->netdev; |
| 4778 | struct ixgbe_hw *hw = &adapter->hw; |
| 4779 | u32 link_speed = adapter->link_speed; |
| 4780 | bool link_up = adapter->link_up; |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 4781 | int i; |
| 4782 | struct ixgbe_ring *tx_ring; |
| 4783 | int some_tx_pending = 0; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4784 | |
| 4785 | adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK; |
| 4786 | |
| 4787 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) { |
| 4788 | 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] | 4789 | if (link_up) { |
| 4790 | #ifdef CONFIG_DCB |
| 4791 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 4792 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 4793 | hw->mac.ops.fc_enable(hw, i); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4794 | } else { |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 4795 | hw->mac.ops.fc_enable(hw, 0); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4796 | } |
| 4797 | #else |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 4798 | hw->mac.ops.fc_enable(hw, 0); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4799 | #endif |
| 4800 | } |
| 4801 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4802 | if (link_up || |
| 4803 | time_after(jiffies, (adapter->link_check_timeout + |
| 4804 | IXGBE_TRY_LINK_TIMEOUT))) { |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4805 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4806 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4807 | } |
| 4808 | adapter->link_up = link_up; |
| 4809 | adapter->link_speed = link_speed; |
| 4810 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4811 | |
| 4812 | if (link_up) { |
| 4813 | if (!netif_carrier_ok(netdev)) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4814 | bool flow_rx, flow_tx; |
| 4815 | |
| 4816 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 4817 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 4818 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
Peter P Waskiewicz Jr | 078788b | 2009-07-16 15:50:32 +0000 | [diff] [blame] | 4819 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 4820 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4821 | } else { |
| 4822 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 4823 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
Peter P Waskiewicz Jr | 078788b | 2009-07-16 15:50:32 +0000 | [diff] [blame] | 4824 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 4825 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4826 | } |
| 4827 | |
Jeff Kirsher | a46e534 | 2008-11-27 00:22:21 -0800 | [diff] [blame] | 4828 | printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, " |
| 4829 | "Flow Control: %s\n", |
| 4830 | netdev->name, |
| 4831 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? |
| 4832 | "10 Gbps" : |
| 4833 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? |
| 4834 | "1 Gbps" : "unknown speed")), |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4835 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 4836 | (flow_rx ? "RX" : |
| 4837 | (flow_tx ? "TX" : "None")))); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4838 | |
| 4839 | netif_carrier_on(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4840 | } else { |
| 4841 | /* Force detection of hung controller */ |
| 4842 | adapter->detect_tx_hung = true; |
| 4843 | } |
| 4844 | } else { |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4845 | adapter->link_up = false; |
| 4846 | adapter->link_speed = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4847 | if (netif_carrier_ok(netdev)) { |
Jeff Kirsher | a46e534 | 2008-11-27 00:22:21 -0800 | [diff] [blame] | 4848 | printk(KERN_INFO "ixgbe: %s NIC Link is Down\n", |
| 4849 | netdev->name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4850 | netif_carrier_off(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4851 | } |
| 4852 | } |
| 4853 | |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 4854 | if (!netif_carrier_ok(netdev)) { |
| 4855 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 4856 | tx_ring = &adapter->tx_ring[i]; |
| 4857 | if (tx_ring->next_to_use != tx_ring->next_to_clean) { |
| 4858 | some_tx_pending = 1; |
| 4859 | break; |
| 4860 | } |
| 4861 | } |
| 4862 | |
| 4863 | if (some_tx_pending) { |
| 4864 | /* We've lost link, so the controller stops DMA, |
| 4865 | * but we've got queued Tx work that's never going |
| 4866 | * to get done, so reset controller to flush Tx. |
| 4867 | * (Do the reset outside of interrupt context). |
| 4868 | */ |
| 4869 | schedule_work(&adapter->reset_task); |
| 4870 | } |
| 4871 | } |
| 4872 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4873 | ixgbe_update_stats(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4874 | adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4875 | } |
| 4876 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4877 | static int ixgbe_tso(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4878 | struct ixgbe_ring *tx_ring, struct sk_buff *skb, |
| 4879 | u32 tx_flags, u8 *hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4880 | { |
| 4881 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 4882 | unsigned int i; |
| 4883 | int err; |
| 4884 | struct ixgbe_tx_buffer *tx_buffer_info; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4885 | u32 vlan_macip_lens = 0, type_tucmd_mlhl; |
| 4886 | u32 mss_l4len_idx, l4len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4887 | |
| 4888 | if (skb_is_gso(skb)) { |
| 4889 | if (skb_header_cloned(skb)) { |
| 4890 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 4891 | if (err) |
| 4892 | return err; |
| 4893 | } |
| 4894 | l4len = tcp_hdrlen(skb); |
| 4895 | *hdr_len += l4len; |
| 4896 | |
Al Viro | 8327d00 | 2007-12-10 18:54:12 +0000 | [diff] [blame] | 4897 | if (skb->protocol == htons(ETH_P_IP)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4898 | struct iphdr *iph = ip_hdr(skb); |
| 4899 | iph->tot_len = 0; |
| 4900 | iph->check = 0; |
| 4901 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4902 | iph->daddr, 0, |
| 4903 | IPPROTO_TCP, |
| 4904 | 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4905 | } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) { |
| 4906 | ipv6_hdr(skb)->payload_len = 0; |
| 4907 | tcp_hdr(skb)->check = |
| 4908 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4909 | &ipv6_hdr(skb)->daddr, |
| 4910 | 0, IPPROTO_TCP, 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4911 | } |
| 4912 | |
| 4913 | i = tx_ring->next_to_use; |
| 4914 | |
| 4915 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4916 | context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i); |
| 4917 | |
| 4918 | /* VLAN MACLEN IPLEN */ |
| 4919 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 4920 | vlan_macip_lens |= |
| 4921 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); |
| 4922 | vlan_macip_lens |= ((skb_network_offset(skb)) << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4923 | IXGBE_ADVTXD_MACLEN_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4924 | *hdr_len += skb_network_offset(skb); |
| 4925 | vlan_macip_lens |= |
| 4926 | (skb_transport_header(skb) - skb_network_header(skb)); |
| 4927 | *hdr_len += |
| 4928 | (skb_transport_header(skb) - skb_network_header(skb)); |
| 4929 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 4930 | context_desc->seqnum_seed = 0; |
| 4931 | |
| 4932 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4933 | type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4934 | IXGBE_ADVTXD_DTYP_CTXT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4935 | |
Al Viro | 8327d00 | 2007-12-10 18:54:12 +0000 | [diff] [blame] | 4936 | if (skb->protocol == htons(ETH_P_IP)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4937 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 4938 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 4939 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); |
| 4940 | |
| 4941 | /* MSS L4LEN IDX */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4942 | mss_l4len_idx = |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4943 | (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT); |
| 4944 | mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT); |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 4945 | /* use index 1 for TSO */ |
| 4946 | mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4947 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 4948 | |
| 4949 | tx_buffer_info->time_stamp = jiffies; |
| 4950 | tx_buffer_info->next_to_watch = i; |
| 4951 | |
| 4952 | i++; |
| 4953 | if (i == tx_ring->count) |
| 4954 | i = 0; |
| 4955 | tx_ring->next_to_use = i; |
| 4956 | |
| 4957 | return true; |
| 4958 | } |
| 4959 | return false; |
| 4960 | } |
| 4961 | |
| 4962 | static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4963 | struct ixgbe_ring *tx_ring, |
| 4964 | struct sk_buff *skb, u32 tx_flags) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4965 | { |
| 4966 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 4967 | unsigned int i; |
| 4968 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 4969 | u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0; |
| 4970 | |
| 4971 | if (skb->ip_summed == CHECKSUM_PARTIAL || |
| 4972 | (tx_flags & IXGBE_TX_FLAGS_VLAN)) { |
| 4973 | i = tx_ring->next_to_use; |
| 4974 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4975 | context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i); |
| 4976 | |
| 4977 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 4978 | vlan_macip_lens |= |
| 4979 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); |
| 4980 | vlan_macip_lens |= (skb_network_offset(skb) << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4981 | IXGBE_ADVTXD_MACLEN_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4982 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 4983 | vlan_macip_lens |= (skb_transport_header(skb) - |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4984 | skb_network_header(skb)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4985 | |
| 4986 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 4987 | context_desc->seqnum_seed = 0; |
| 4988 | |
| 4989 | type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4990 | IXGBE_ADVTXD_DTYP_CTXT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4991 | |
| 4992 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4993 | switch (skb->protocol) { |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 4994 | case cpu_to_be16(ETH_P_IP): |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4995 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4996 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 4997 | type_tucmd_mlhl |= |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4998 | IXGBE_ADVTXD_TUCMD_L4T_TCP; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 4999 | else if (ip_hdr(skb)->protocol == IPPROTO_SCTP) |
| 5000 | type_tucmd_mlhl |= |
| 5001 | IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5002 | break; |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 5003 | case cpu_to_be16(ETH_P_IPV6): |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5004 | /* XXX what about other V6 headers?? */ |
| 5005 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 5006 | type_tucmd_mlhl |= |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5007 | IXGBE_ADVTXD_TUCMD_L4T_TCP; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 5008 | else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP) |
| 5009 | type_tucmd_mlhl |= |
| 5010 | IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5011 | break; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5012 | default: |
| 5013 | if (unlikely(net_ratelimit())) { |
| 5014 | DPRINTK(PROBE, WARNING, |
| 5015 | "partial checksum but proto=%x!\n", |
| 5016 | skb->protocol); |
| 5017 | } |
| 5018 | break; |
| 5019 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5020 | } |
| 5021 | |
| 5022 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 5023 | /* use index zero for tx checksum offload */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5024 | context_desc->mss_l4len_idx = 0; |
| 5025 | |
| 5026 | tx_buffer_info->time_stamp = jiffies; |
| 5027 | tx_buffer_info->next_to_watch = i; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5028 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5029 | i++; |
| 5030 | if (i == tx_ring->count) |
| 5031 | i = 0; |
| 5032 | tx_ring->next_to_use = i; |
| 5033 | |
| 5034 | return true; |
| 5035 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5036 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5037 | return false; |
| 5038 | } |
| 5039 | |
| 5040 | static int ixgbe_tx_map(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5041 | struct ixgbe_ring *tx_ring, |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5042 | struct sk_buff *skb, u32 tx_flags, |
| 5043 | unsigned int first) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5044 | { |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5045 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5046 | struct ixgbe_tx_buffer *tx_buffer_info; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5047 | unsigned int len; |
| 5048 | unsigned int total = skb->len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5049 | unsigned int offset = 0, size, count = 0, i; |
| 5050 | unsigned int nr_frags = skb_shinfo(skb)->nr_frags; |
| 5051 | unsigned int f; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5052 | |
| 5053 | i = tx_ring->next_to_use; |
| 5054 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5055 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) |
| 5056 | /* excluding fcoe_crc_eof for FCoE */ |
| 5057 | total -= sizeof(struct fcoe_crc_eof); |
| 5058 | |
| 5059 | len = min(skb_headlen(skb), total); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5060 | while (len) { |
| 5061 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5062 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 5063 | |
| 5064 | tx_buffer_info->length = size; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5065 | tx_buffer_info->mapped_as_page = false; |
| 5066 | tx_buffer_info->dma = pci_map_single(pdev, |
| 5067 | skb->data + offset, |
| 5068 | size, PCI_DMA_TODEVICE); |
| 5069 | if (pci_dma_mapping_error(pdev, tx_buffer_info->dma)) |
| 5070 | goto dma_error; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5071 | tx_buffer_info->time_stamp = jiffies; |
| 5072 | tx_buffer_info->next_to_watch = i; |
| 5073 | |
| 5074 | len -= size; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5075 | total -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5076 | offset += size; |
| 5077 | count++; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5078 | |
| 5079 | if (len) { |
| 5080 | i++; |
| 5081 | if (i == tx_ring->count) |
| 5082 | i = 0; |
| 5083 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5084 | } |
| 5085 | |
| 5086 | for (f = 0; f < nr_frags; f++) { |
| 5087 | struct skb_frag_struct *frag; |
| 5088 | |
| 5089 | frag = &skb_shinfo(skb)->frags[f]; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5090 | len = min((unsigned int)frag->size, total); |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5091 | offset = frag->page_offset; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5092 | |
| 5093 | while (len) { |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5094 | i++; |
| 5095 | if (i == tx_ring->count) |
| 5096 | i = 0; |
| 5097 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 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->dma = pci_map_page(adapter->pdev, |
| 5103 | frag->page, |
| 5104 | offset, size, |
| 5105 | PCI_DMA_TODEVICE); |
| 5106 | tx_buffer_info->mapped_as_page = true; |
| 5107 | if (pci_dma_mapping_error(pdev, tx_buffer_info->dma)) |
| 5108 | goto dma_error; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5109 | tx_buffer_info->time_stamp = jiffies; |
| 5110 | tx_buffer_info->next_to_watch = i; |
| 5111 | |
| 5112 | len -= size; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5113 | total -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5114 | offset += size; |
| 5115 | count++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5116 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5117 | if (total == 0) |
| 5118 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5119 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5120 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5121 | tx_ring->tx_buffer_info[i].skb = skb; |
| 5122 | tx_ring->tx_buffer_info[first].next_to_watch = i; |
| 5123 | |
| 5124 | return count; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5125 | |
| 5126 | dma_error: |
| 5127 | dev_err(&pdev->dev, "TX DMA map failed\n"); |
| 5128 | |
| 5129 | /* clear timestamp and dma mappings for failed tx_buffer_info map */ |
| 5130 | tx_buffer_info->dma = 0; |
| 5131 | tx_buffer_info->time_stamp = 0; |
| 5132 | tx_buffer_info->next_to_watch = 0; |
| 5133 | count--; |
| 5134 | |
| 5135 | /* clear timestamp and dma mappings for remaining portion of packet */ |
| 5136 | while (count >= 0) { |
| 5137 | count--; |
| 5138 | i--; |
| 5139 | if (i < 0) |
| 5140 | i += tx_ring->count; |
| 5141 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5142 | ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info); |
| 5143 | } |
| 5144 | |
| 5145 | return count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5146 | } |
| 5147 | |
| 5148 | static void ixgbe_tx_queue(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5149 | struct ixgbe_ring *tx_ring, |
| 5150 | int tx_flags, int count, u32 paylen, u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5151 | { |
| 5152 | union ixgbe_adv_tx_desc *tx_desc = NULL; |
| 5153 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 5154 | u32 olinfo_status = 0, cmd_type_len = 0; |
| 5155 | unsigned int i; |
| 5156 | u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS; |
| 5157 | |
| 5158 | cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA; |
| 5159 | |
| 5160 | cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT; |
| 5161 | |
| 5162 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 5163 | cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE; |
| 5164 | |
| 5165 | if (tx_flags & IXGBE_TX_FLAGS_TSO) { |
| 5166 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 5167 | |
| 5168 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5169 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5170 | |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 5171 | /* use index 1 context for tso */ |
| 5172 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5173 | if (tx_flags & IXGBE_TX_FLAGS_IPV4) |
| 5174 | olinfo_status |= IXGBE_TXD_POPTS_IXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5175 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5176 | |
| 5177 | } else if (tx_flags & IXGBE_TX_FLAGS_CSUM) |
| 5178 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5179 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5180 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5181 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 5182 | olinfo_status |= IXGBE_ADVTXD_CC; |
| 5183 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
| 5184 | if (tx_flags & IXGBE_TX_FLAGS_FSO) |
| 5185 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 5186 | } |
| 5187 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5188 | olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT); |
| 5189 | |
| 5190 | i = tx_ring->next_to_use; |
| 5191 | while (count--) { |
| 5192 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5193 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); |
| 5194 | tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma); |
| 5195 | tx_desc->read.cmd_type_len = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5196 | cpu_to_le32(cmd_type_len | tx_buffer_info->length); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5197 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5198 | i++; |
| 5199 | if (i == tx_ring->count) |
| 5200 | i = 0; |
| 5201 | } |
| 5202 | |
| 5203 | tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd); |
| 5204 | |
| 5205 | /* |
| 5206 | * Force memory writes to complete before letting h/w |
| 5207 | * know there are new descriptors to fetch. (Only |
| 5208 | * applicable for weak-ordered memory model archs, |
| 5209 | * such as IA-64). |
| 5210 | */ |
| 5211 | wmb(); |
| 5212 | |
| 5213 | tx_ring->next_to_use = i; |
| 5214 | writel(i, adapter->hw.hw_addr + tx_ring->tail); |
| 5215 | } |
| 5216 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5217 | static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb, |
| 5218 | int queue, u32 tx_flags) |
| 5219 | { |
| 5220 | /* Right now, we support IPv4 only */ |
| 5221 | struct ixgbe_atr_input atr_input; |
| 5222 | struct tcphdr *th; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5223 | struct iphdr *iph = ip_hdr(skb); |
| 5224 | struct ethhdr *eth = (struct ethhdr *)skb->data; |
| 5225 | u16 vlan_id, src_port, dst_port, flex_bytes; |
| 5226 | u32 src_ipv4_addr, dst_ipv4_addr; |
| 5227 | u8 l4type = 0; |
| 5228 | |
| 5229 | /* check if we're UDP or TCP */ |
| 5230 | if (iph->protocol == IPPROTO_TCP) { |
| 5231 | th = tcp_hdr(skb); |
| 5232 | src_port = th->source; |
| 5233 | dst_port = th->dest; |
| 5234 | l4type |= IXGBE_ATR_L4TYPE_TCP; |
| 5235 | /* l4type IPv4 type is 0, no need to assign */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5236 | } else { |
| 5237 | /* Unsupported L4 header, just bail here */ |
| 5238 | return; |
| 5239 | } |
| 5240 | |
| 5241 | memset(&atr_input, 0, sizeof(struct ixgbe_atr_input)); |
| 5242 | |
| 5243 | vlan_id = (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK) >> |
| 5244 | IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5245 | src_ipv4_addr = iph->saddr; |
| 5246 | dst_ipv4_addr = iph->daddr; |
| 5247 | flex_bytes = eth->h_proto; |
| 5248 | |
| 5249 | ixgbe_atr_set_vlan_id_82599(&atr_input, vlan_id); |
| 5250 | ixgbe_atr_set_src_port_82599(&atr_input, dst_port); |
| 5251 | ixgbe_atr_set_dst_port_82599(&atr_input, src_port); |
| 5252 | ixgbe_atr_set_flex_byte_82599(&atr_input, flex_bytes); |
| 5253 | ixgbe_atr_set_l4type_82599(&atr_input, l4type); |
| 5254 | /* src and dst are inverted, think how the receiver sees them */ |
| 5255 | ixgbe_atr_set_src_ipv4_82599(&atr_input, dst_ipv4_addr); |
| 5256 | ixgbe_atr_set_dst_ipv4_82599(&atr_input, src_ipv4_addr); |
| 5257 | |
| 5258 | /* This assumes the Rx queue and Tx queue are bound to the same CPU */ |
| 5259 | ixgbe_fdir_add_signature_filter_82599(&adapter->hw, &atr_input, queue); |
| 5260 | } |
| 5261 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5262 | static int __ixgbe_maybe_stop_tx(struct net_device *netdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5263 | struct ixgbe_ring *tx_ring, int size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5264 | { |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5265 | netif_stop_subqueue(netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5266 | /* Herbert's original patch had: |
| 5267 | * smp_mb__after_netif_stop_queue(); |
| 5268 | * but since that doesn't exist yet, just open code it. */ |
| 5269 | smp_mb(); |
| 5270 | |
| 5271 | /* We need to check again in a case another CPU has just |
| 5272 | * made room available. */ |
| 5273 | if (likely(IXGBE_DESC_UNUSED(tx_ring) < size)) |
| 5274 | return -EBUSY; |
| 5275 | |
| 5276 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
Jesse Brandeburg | af72166 | 2008-09-11 19:54:23 -0700 | [diff] [blame] | 5277 | netif_start_subqueue(netdev, tx_ring->queue_index); |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame^] | 5278 | ++tx_ring->restart_queue; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5279 | return 0; |
| 5280 | } |
| 5281 | |
| 5282 | static int ixgbe_maybe_stop_tx(struct net_device *netdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5283 | struct ixgbe_ring *tx_ring, int size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5284 | { |
| 5285 | if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size)) |
| 5286 | return 0; |
| 5287 | return __ixgbe_maybe_stop_tx(netdev, tx_ring, size); |
| 5288 | } |
| 5289 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5290 | static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb) |
| 5291 | { |
| 5292 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5293 | int txq = smp_processor_id(); |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5294 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5295 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5296 | return txq; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5297 | |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5298 | #ifdef IXGBE_FCOE |
| 5299 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 5300 | (skb->protocol == htons(ETH_P_FCOE))) { |
| 5301 | txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1); |
| 5302 | txq += adapter->ring_feature[RING_F_FCOE].mask; |
| 5303 | return txq; |
| 5304 | } |
| 5305 | #endif |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5306 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
Lucy Liu | 36e89d7 | 2009-08-05 13:06:34 -0700 | [diff] [blame] | 5307 | return (skb->vlan_tci & IXGBE_TX_FLAGS_VLAN_PRIO_MASK) >> 13; |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5308 | |
| 5309 | return skb_tx_hash(dev, skb); |
| 5310 | } |
| 5311 | |
Stephen Hemminger | 3b29a56 | 2009-08-31 19:50:55 +0000 | [diff] [blame] | 5312 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, |
| 5313 | struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5314 | { |
| 5315 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5316 | struct ixgbe_ring *tx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5317 | unsigned int first; |
| 5318 | unsigned int tx_flags = 0; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5319 | u8 hdr_len = 0; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5320 | int tso; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5321 | int count = 0; |
| 5322 | unsigned int f; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5323 | |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5324 | if (adapter->vlgrp && vlan_tx_tag_present(skb)) { |
| 5325 | tx_flags |= vlan_tx_tag_get(skb); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5326 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 5327 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5328 | tx_flags |= ((skb->queue_mapping & 0x7) << 13); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5329 | } |
| 5330 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5331 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
| 5332 | } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 5333 | if (skb->priority != TC_PRIO_CONTROL) { |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5334 | tx_flags |= ((skb->queue_mapping & 0x7) << 13); |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 5335 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5336 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
| 5337 | } else { |
| 5338 | skb->queue_mapping = |
| 5339 | adapter->ring_feature[RING_F_DCB].indices-1; |
| 5340 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5341 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5342 | |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5343 | tx_ring = &adapter->tx_ring[skb->queue_mapping]; |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 5344 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5345 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
Yi Zou | 09ad1cc | 2009-09-03 14:56:10 +0000 | [diff] [blame] | 5346 | (skb->protocol == htons(ETH_P_FCOE))) { |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5347 | tx_flags |= IXGBE_TX_FLAGS_FCOE; |
Yi Zou | 09ad1cc | 2009-09-03 14:56:10 +0000 | [diff] [blame] | 5348 | #ifdef IXGBE_FCOE |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 5349 | #ifdef CONFIG_IXGBE_DCB |
| 5350 | tx_flags &= ~(IXGBE_TX_FLAGS_VLAN_PRIO_MASK |
| 5351 | << IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 5352 | tx_flags |= ((adapter->fcoe.up << 13) |
| 5353 | << IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 5354 | #endif |
Yi Zou | 09ad1cc | 2009-09-03 14:56:10 +0000 | [diff] [blame] | 5355 | #endif |
| 5356 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5357 | /* four things can cause us to need a context descriptor */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5358 | if (skb_is_gso(skb) || |
| 5359 | (skb->ip_summed == CHECKSUM_PARTIAL) || |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5360 | (tx_flags & IXGBE_TX_FLAGS_VLAN) || |
| 5361 | (tx_flags & IXGBE_TX_FLAGS_FCOE)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5362 | count++; |
| 5363 | |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5364 | count += TXD_USE_COUNT(skb_headlen(skb)); |
| 5365 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5366 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
| 5367 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5368 | if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5369 | adapter->tx_busy++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5370 | return NETDEV_TX_BUSY; |
| 5371 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5372 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5373 | first = tx_ring->next_to_use; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5374 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 5375 | #ifdef IXGBE_FCOE |
| 5376 | /* setup tx offload for FCoE */ |
| 5377 | tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len); |
| 5378 | if (tso < 0) { |
| 5379 | dev_kfree_skb_any(skb); |
| 5380 | return NETDEV_TX_OK; |
| 5381 | } |
| 5382 | if (tso) |
| 5383 | tx_flags |= IXGBE_TX_FLAGS_FSO; |
| 5384 | #endif /* IXGBE_FCOE */ |
| 5385 | } else { |
| 5386 | if (skb->protocol == htons(ETH_P_IP)) |
| 5387 | tx_flags |= IXGBE_TX_FLAGS_IPV4; |
| 5388 | tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len); |
| 5389 | if (tso < 0) { |
| 5390 | dev_kfree_skb_any(skb); |
| 5391 | return NETDEV_TX_OK; |
| 5392 | } |
| 5393 | |
| 5394 | if (tso) |
| 5395 | tx_flags |= IXGBE_TX_FLAGS_TSO; |
| 5396 | else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) && |
| 5397 | (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 5398 | tx_flags |= IXGBE_TX_FLAGS_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5399 | } |
| 5400 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5401 | count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5402 | if (count) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5403 | /* add the ATR filter if ATR is on */ |
| 5404 | if (tx_ring->atr_sample_rate) { |
| 5405 | ++tx_ring->atr_count; |
| 5406 | if ((tx_ring->atr_count >= tx_ring->atr_sample_rate) && |
| 5407 | test_bit(__IXGBE_FDIR_INIT_DONE, |
| 5408 | &tx_ring->reinit_state)) { |
| 5409 | ixgbe_atr(adapter, skb, tx_ring->queue_index, |
| 5410 | tx_flags); |
| 5411 | tx_ring->atr_count = 0; |
| 5412 | } |
| 5413 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5414 | ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len, |
| 5415 | hdr_len); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5416 | ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5417 | |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5418 | } else { |
| 5419 | dev_kfree_skb_any(skb); |
| 5420 | tx_ring->tx_buffer_info[first].time_stamp = 0; |
| 5421 | tx_ring->next_to_use = first; |
| 5422 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5423 | |
| 5424 | return NETDEV_TX_OK; |
| 5425 | } |
| 5426 | |
| 5427 | /** |
| 5428 | * ixgbe_get_stats - Get System Network Statistics |
| 5429 | * @netdev: network interface device structure |
| 5430 | * |
| 5431 | * Returns the address of the device statistics structure. |
| 5432 | * The statistics are actually updated from the timer callback. |
| 5433 | **/ |
| 5434 | static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev) |
| 5435 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5436 | /* only return the current stats */ |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 5437 | return &netdev->stats; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5438 | } |
| 5439 | |
| 5440 | /** |
| 5441 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
| 5442 | * @netdev: network interface device structure |
| 5443 | * @p: pointer to an address structure |
| 5444 | * |
| 5445 | * Returns 0 on success, negative on failure |
| 5446 | **/ |
| 5447 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 5448 | { |
| 5449 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5450 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5451 | struct sockaddr *addr = p; |
| 5452 | |
| 5453 | if (!is_valid_ether_addr(addr->sa_data)) |
| 5454 | return -EADDRNOTAVAIL; |
| 5455 | |
| 5456 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5457 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5458 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5459 | 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] | 5460 | |
| 5461 | return 0; |
| 5462 | } |
| 5463 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5464 | static int |
| 5465 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 5466 | { |
| 5467 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5468 | struct ixgbe_hw *hw = &adapter->hw; |
| 5469 | u16 value; |
| 5470 | int rc; |
| 5471 | |
| 5472 | if (prtad != hw->phy.mdio.prtad) |
| 5473 | return -EINVAL; |
| 5474 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 5475 | if (!rc) |
| 5476 | rc = value; |
| 5477 | return rc; |
| 5478 | } |
| 5479 | |
| 5480 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 5481 | u16 addr, u16 value) |
| 5482 | { |
| 5483 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5484 | struct ixgbe_hw *hw = &adapter->hw; |
| 5485 | |
| 5486 | if (prtad != hw->phy.mdio.prtad) |
| 5487 | return -EINVAL; |
| 5488 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 5489 | } |
| 5490 | |
| 5491 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 5492 | { |
| 5493 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5494 | |
| 5495 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 5496 | } |
| 5497 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5498 | /** |
| 5499 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 5500 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5501 | * @netdev: network interface device structure |
| 5502 | * |
| 5503 | * Returns non-zero on failure |
| 5504 | **/ |
| 5505 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
| 5506 | { |
| 5507 | int err = 0; |
| 5508 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 5509 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 5510 | |
| 5511 | if (is_valid_ether_addr(mac->san_addr)) { |
| 5512 | rtnl_lock(); |
| 5513 | err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 5514 | rtnl_unlock(); |
| 5515 | } |
| 5516 | return err; |
| 5517 | } |
| 5518 | |
| 5519 | /** |
| 5520 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 5521 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5522 | * @netdev: network interface device structure |
| 5523 | * |
| 5524 | * Returns non-zero on failure |
| 5525 | **/ |
| 5526 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 5527 | { |
| 5528 | int err = 0; |
| 5529 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 5530 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 5531 | |
| 5532 | if (is_valid_ether_addr(mac->san_addr)) { |
| 5533 | rtnl_lock(); |
| 5534 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 5535 | rtnl_unlock(); |
| 5536 | } |
| 5537 | return err; |
| 5538 | } |
| 5539 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5540 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5541 | /* |
| 5542 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 5543 | * without having to re-enable interrupts. It's not called while |
| 5544 | * the interrupt routine is executing. |
| 5545 | */ |
| 5546 | static void ixgbe_netpoll(struct net_device *netdev) |
| 5547 | { |
| 5548 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 5549 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5550 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5551 | adapter->flags |= IXGBE_FLAG_IN_NETPOLL; |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 5552 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 5553 | int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 5554 | for (i = 0; i < num_q_vectors; i++) { |
| 5555 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
| 5556 | ixgbe_msix_clean_many(0, q_vector); |
| 5557 | } |
| 5558 | } else { |
| 5559 | ixgbe_intr(adapter->pdev->irq, netdev); |
| 5560 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5561 | adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5562 | } |
| 5563 | #endif |
| 5564 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5565 | static const struct net_device_ops ixgbe_netdev_ops = { |
| 5566 | .ndo_open = ixgbe_open, |
| 5567 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 5568 | .ndo_start_xmit = ixgbe_xmit_frame, |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5569 | .ndo_select_queue = ixgbe_select_queue, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5570 | .ndo_get_stats = ixgbe_get_stats, |
Chris Leech | e90d400 | 2009-03-10 16:00:24 +0000 | [diff] [blame] | 5571 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5572 | .ndo_set_multicast_list = ixgbe_set_rx_mode, |
| 5573 | .ndo_validate_addr = eth_validate_addr, |
| 5574 | .ndo_set_mac_address = ixgbe_set_mac, |
| 5575 | .ndo_change_mtu = ixgbe_change_mtu, |
| 5576 | .ndo_tx_timeout = ixgbe_tx_timeout, |
| 5577 | .ndo_vlan_rx_register = ixgbe_vlan_rx_register, |
| 5578 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 5579 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5580 | .ndo_do_ioctl = ixgbe_ioctl, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5581 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5582 | .ndo_poll_controller = ixgbe_netpoll, |
| 5583 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 5584 | #ifdef IXGBE_FCOE |
| 5585 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
| 5586 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 5587 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 5588 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 5589 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 5590 | #endif /* IXGBE_FCOE */ |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5591 | }; |
| 5592 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5593 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5594 | * ixgbe_probe - Device Initialization Routine |
| 5595 | * @pdev: PCI device information struct |
| 5596 | * @ent: entry in ixgbe_pci_tbl |
| 5597 | * |
| 5598 | * Returns 0 on success, negative on failure |
| 5599 | * |
| 5600 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 5601 | * The OS initialization, configuring of the adapter private structure, |
| 5602 | * and a hardware reset occur. |
| 5603 | **/ |
| 5604 | static int __devinit ixgbe_probe(struct pci_dev *pdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5605 | const struct pci_device_id *ent) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5606 | { |
| 5607 | struct net_device *netdev; |
| 5608 | struct ixgbe_adapter *adapter = NULL; |
| 5609 | struct ixgbe_hw *hw; |
| 5610 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5611 | static int cards_found; |
| 5612 | int i, err, pci_using_dac; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5613 | #ifdef IXGBE_FCOE |
| 5614 | u16 device_caps; |
| 5615 | #endif |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5616 | u32 part_num, eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5617 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5618 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5619 | if (err) |
| 5620 | return err; |
| 5621 | |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 5622 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
| 5623 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5624 | pci_using_dac = 1; |
| 5625 | } else { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5626 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5627 | if (err) { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5628 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5629 | if (err) { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5630 | dev_err(&pdev->dev, "No usable DMA " |
| 5631 | "configuration, aborting\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5632 | goto err_dma; |
| 5633 | } |
| 5634 | } |
| 5635 | pci_using_dac = 0; |
| 5636 | } |
| 5637 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5638 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
| 5639 | IORESOURCE_MEM), ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5640 | if (err) { |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5641 | dev_err(&pdev->dev, |
| 5642 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5643 | goto err_pci_reg; |
| 5644 | } |
| 5645 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 5646 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5647 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5648 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 5649 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5650 | |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5651 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5652 | if (!netdev) { |
| 5653 | err = -ENOMEM; |
| 5654 | goto err_alloc_etherdev; |
| 5655 | } |
| 5656 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5657 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 5658 | |
| 5659 | pci_set_drvdata(pdev, netdev); |
| 5660 | adapter = netdev_priv(netdev); |
| 5661 | |
| 5662 | adapter->netdev = netdev; |
| 5663 | adapter->pdev = pdev; |
| 5664 | hw = &adapter->hw; |
| 5665 | hw->back = adapter; |
| 5666 | adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
| 5667 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 5668 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
| 5669 | pci_resource_len(pdev, 0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5670 | if (!hw->hw_addr) { |
| 5671 | err = -EIO; |
| 5672 | goto err_ioremap; |
| 5673 | } |
| 5674 | |
| 5675 | for (i = 1; i <= 5; i++) { |
| 5676 | if (pci_resource_len(pdev, i) == 0) |
| 5677 | continue; |
| 5678 | } |
| 5679 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5680 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5681 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5682 | netdev->watchdog_timeo = 5 * HZ; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5683 | strcpy(netdev->name, pci_name(pdev)); |
| 5684 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5685 | adapter->bd_number = cards_found; |
| 5686 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5687 | /* Setup hw api */ |
| 5688 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5689 | hw->mac.type = ii->mac; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5690 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5691 | /* EEPROM */ |
| 5692 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); |
| 5693 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 5694 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
| 5695 | if (!(eec & (1 << 8))) |
| 5696 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 5697 | |
| 5698 | /* PHY */ |
| 5699 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5700 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5701 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 5702 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 5703 | hw->phy.mdio.mmds = 0; |
| 5704 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 5705 | hw->phy.mdio.dev = netdev; |
| 5706 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 5707 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5708 | |
| 5709 | /* set up this timer and work struct before calling get_invariants |
| 5710 | * which might start the timer |
| 5711 | */ |
| 5712 | init_timer(&adapter->sfp_timer); |
| 5713 | adapter->sfp_timer.function = &ixgbe_sfp_timer; |
| 5714 | adapter->sfp_timer.data = (unsigned long) adapter; |
| 5715 | |
| 5716 | INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5717 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5718 | /* multispeed fiber has its own tasklet, called from GPI SDP1 context */ |
| 5719 | INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task); |
| 5720 | |
| 5721 | /* a new SFP+ module arrival, called from GPI SDP2 context */ |
| 5722 | INIT_WORK(&adapter->sfp_config_module_task, |
| 5723 | ixgbe_sfp_config_module_task); |
| 5724 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5725 | ii->get_invariants(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5726 | |
| 5727 | /* setup the private structure */ |
| 5728 | err = ixgbe_sw_init(adapter); |
| 5729 | if (err) |
| 5730 | goto err_sw_init; |
| 5731 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5732 | /* |
| 5733 | * If there is a fan on this device and it has failed log the |
| 5734 | * failure. |
| 5735 | */ |
| 5736 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 5737 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 5738 | if (esdp & IXGBE_ESDP_SDP1) |
| 5739 | DPRINTK(PROBE, CRIT, |
| 5740 | "Fan has stopped, replace the adapter\n"); |
| 5741 | } |
| 5742 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5743 | /* reset_hw fills in the perm_addr as well */ |
| 5744 | err = hw->mac.ops.reset_hw(hw); |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5745 | if (err == IXGBE_ERR_SFP_NOT_PRESENT && |
| 5746 | hw->mac.type == ixgbe_mac_82598EB) { |
| 5747 | /* |
| 5748 | * Start a kernel thread to watch for a module to arrive. |
| 5749 | * Only do this for 82598, since 82599 will generate |
| 5750 | * interrupts on module arrival. |
| 5751 | */ |
| 5752 | set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 5753 | mod_timer(&adapter->sfp_timer, |
| 5754 | round_jiffies(jiffies + (2 * HZ))); |
| 5755 | err = 0; |
| 5756 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 88d2b81 | 2009-06-30 11:43:55 +0000 | [diff] [blame] | 5757 | dev_err(&adapter->pdev->dev, "failed to initialize because " |
| 5758 | "an unsupported SFP+ module type was detected.\n" |
| 5759 | "Reload the driver after installing a supported " |
| 5760 | "module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 5761 | goto err_sw_init; |
| 5762 | } else if (err) { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5763 | dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err); |
| 5764 | goto err_sw_init; |
| 5765 | } |
| 5766 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5767 | netdev->features = NETIF_F_SG | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5768 | NETIF_F_IP_CSUM | |
| 5769 | NETIF_F_HW_VLAN_TX | |
| 5770 | NETIF_F_HW_VLAN_RX | |
| 5771 | NETIF_F_HW_VLAN_FILTER; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5772 | |
Jesse Brandeburg | e9990a9 | 2008-08-26 04:27:24 -0700 | [diff] [blame] | 5773 | netdev->features |= NETIF_F_IPV6_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5774 | netdev->features |= NETIF_F_TSO; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5775 | netdev->features |= NETIF_F_TSO6; |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 5776 | netdev->features |= NETIF_F_GRO; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 5777 | |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 5778 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 5779 | netdev->features |= NETIF_F_SCTP_CSUM; |
| 5780 | |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 5781 | netdev->vlan_features |= NETIF_F_TSO; |
| 5782 | netdev->vlan_features |= NETIF_F_TSO6; |
Jesse Brandeburg | 22f32b7a5 | 2008-08-26 04:27:18 -0700 | [diff] [blame] | 5783 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Alexander Duyck | cd1da50 | 2009-08-25 04:47:50 +0000 | [diff] [blame] | 5784 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 5785 | netdev->vlan_features |= NETIF_F_SG; |
| 5786 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5787 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 5788 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
| 5789 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5790 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5791 | netdev->dcbnl_ops = &dcbnl_ops; |
| 5792 | #endif |
| 5793 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5794 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 5795 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5796 | if (hw->mac.ops.get_device_caps) { |
| 5797 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 5798 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 5799 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5800 | } |
| 5801 | } |
| 5802 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5803 | if (pci_using_dac) |
| 5804 | netdev->features |= NETIF_F_HIGHDMA; |
| 5805 | |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 5806 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5807 | netdev->features |= NETIF_F_LRO; |
| 5808 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5809 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5810 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5811 | dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n"); |
| 5812 | err = -EIO; |
| 5813 | goto err_eeprom; |
| 5814 | } |
| 5815 | |
| 5816 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
| 5817 | memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len); |
| 5818 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5819 | if (ixgbe_validate_mac_addr(netdev->perm_addr)) { |
| 5820 | dev_err(&pdev->dev, "invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5821 | err = -EIO; |
| 5822 | goto err_eeprom; |
| 5823 | } |
| 5824 | |
| 5825 | init_timer(&adapter->watchdog_timer); |
| 5826 | adapter->watchdog_timer.function = &ixgbe_watchdog; |
| 5827 | adapter->watchdog_timer.data = (unsigned long)adapter; |
| 5828 | |
| 5829 | INIT_WORK(&adapter->reset_task, ixgbe_reset_task); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5830 | INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5831 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5832 | err = ixgbe_init_interrupt_scheme(adapter); |
| 5833 | if (err) |
| 5834 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5835 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5836 | switch (pdev->device) { |
| 5837 | case IXGBE_DEV_ID_82599_KX4: |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 5838 | adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX | |
| 5839 | IXGBE_WUFC_MC | IXGBE_WUFC_BC); |
Peter P Waskiewicz Jr | bdf0a55 | 2009-06-04 11:09:58 +0000 | [diff] [blame] | 5840 | /* Enable ACPI wakeup in GRC */ |
| 5841 | IXGBE_WRITE_REG(hw, IXGBE_GRC, |
| 5842 | (IXGBE_READ_REG(hw, IXGBE_GRC) & ~IXGBE_GRC_APME)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5843 | break; |
| 5844 | default: |
| 5845 | adapter->wol = 0; |
| 5846 | break; |
| 5847 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5848 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 5849 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 5850 | /* pick up the PCI bus settings for reporting later */ |
| 5851 | hw->mac.ops.get_bus_info(hw); |
| 5852 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5853 | /* print bus type/speed/width info */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 5854 | dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n", |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5855 | ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s": |
| 5856 | (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"), |
| 5857 | ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" : |
| 5858 | (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" : |
| 5859 | (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" : |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5860 | "Unknown"), |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 5861 | netdev->dev_addr); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5862 | ixgbe_read_pba_num_generic(hw, &part_num); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5863 | if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present) |
| 5864 | dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n", |
| 5865 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
| 5866 | (part_num >> 8), (part_num & 0xff)); |
| 5867 | else |
| 5868 | dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n", |
| 5869 | hw->mac.type, hw->phy.type, |
| 5870 | (part_num >> 8), (part_num & 0xff)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5871 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5872 | if (hw->bus.width <= ixgbe_bus_width_pcie_x4) { |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 5873 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5874 | "this card is not sufficient for optimal " |
| 5875 | "performance.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 5876 | dev_warn(&pdev->dev, "For optimal performance a x8 " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5877 | "PCI-Express slot is required.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 5878 | } |
| 5879 | |
Peter P Waskiewicz Jr | 34b0368 | 2009-02-05 23:54:42 -0800 | [diff] [blame] | 5880 | /* save off EEPROM version number */ |
| 5881 | hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version); |
| 5882 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5883 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5884 | err = hw->mac.ops.start_hw(hw); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5885 | |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5886 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 5887 | /* We are running on a pre-production device, log a warning */ |
| 5888 | dev_warn(&pdev->dev, "This device is a pre-production " |
| 5889 | "adapter/LOM. Please be aware there may be issues " |
| 5890 | "associated with your hardware. If you are " |
| 5891 | "experiencing problems please contact your Intel or " |
| 5892 | "hardware representative who provided you with this " |
| 5893 | "hardware.\n"); |
| 5894 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5895 | strcpy(netdev->name, "eth%d"); |
| 5896 | err = register_netdev(netdev); |
| 5897 | if (err) |
| 5898 | goto err_register; |
| 5899 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 5900 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 5901 | netif_carrier_off(netdev); |
| 5902 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5903 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 5904 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 5905 | INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task); |
| 5906 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 5907 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 5908 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5909 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5910 | ixgbe_setup_dca(adapter); |
| 5911 | } |
| 5912 | #endif |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5913 | /* add san mac addr to netdev */ |
| 5914 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5915 | |
| 5916 | dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n"); |
| 5917 | cards_found++; |
| 5918 | return 0; |
| 5919 | |
| 5920 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5921 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5922 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5923 | err_sw_init: |
| 5924 | err_eeprom: |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5925 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 5926 | del_timer_sync(&adapter->sfp_timer); |
| 5927 | cancel_work_sync(&adapter->sfp_task); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5928 | cancel_work_sync(&adapter->multispeed_fiber_task); |
| 5929 | cancel_work_sync(&adapter->sfp_config_module_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5930 | iounmap(hw->hw_addr); |
| 5931 | err_ioremap: |
| 5932 | free_netdev(netdev); |
| 5933 | err_alloc_etherdev: |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5934 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
| 5935 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5936 | err_pci_reg: |
| 5937 | err_dma: |
| 5938 | pci_disable_device(pdev); |
| 5939 | return err; |
| 5940 | } |
| 5941 | |
| 5942 | /** |
| 5943 | * ixgbe_remove - Device Removal Routine |
| 5944 | * @pdev: PCI device information struct |
| 5945 | * |
| 5946 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 5947 | * that it should release a PCI device. The could be caused by a |
| 5948 | * Hot-Plug event, or because the driver is going to be removed from |
| 5949 | * memory. |
| 5950 | **/ |
| 5951 | static void __devexit ixgbe_remove(struct pci_dev *pdev) |
| 5952 | { |
| 5953 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5954 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5955 | |
| 5956 | set_bit(__IXGBE_DOWN, &adapter->state); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5957 | /* clear the module not found bit to make sure the worker won't |
| 5958 | * reschedule |
| 5959 | */ |
| 5960 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5961 | del_timer_sync(&adapter->watchdog_timer); |
| 5962 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5963 | del_timer_sync(&adapter->sfp_timer); |
| 5964 | cancel_work_sync(&adapter->watchdog_task); |
| 5965 | cancel_work_sync(&adapter->sfp_task); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5966 | cancel_work_sync(&adapter->multispeed_fiber_task); |
| 5967 | cancel_work_sync(&adapter->sfp_config_module_task); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5968 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 5969 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 5970 | cancel_work_sync(&adapter->fdir_reinit_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5971 | flush_scheduled_work(); |
| 5972 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 5973 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5974 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 5975 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 5976 | dca_remove_requester(&pdev->dev); |
| 5977 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 5978 | } |
| 5979 | |
| 5980 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 5981 | #ifdef IXGBE_FCOE |
| 5982 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 5983 | ixgbe_cleanup_fcoe(adapter); |
| 5984 | |
| 5985 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5986 | |
| 5987 | /* remove the added san mac */ |
| 5988 | ixgbe_del_sanmac_netdev(netdev); |
| 5989 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5990 | if (netdev->reg_state == NETREG_REGISTERED) |
| 5991 | unregister_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5992 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5993 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5994 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5995 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5996 | |
| 5997 | iounmap(adapter->hw.hw_addr); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5998 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
| 5999 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6000 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6001 | DPRINTK(PROBE, INFO, "complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6002 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6003 | free_netdev(netdev); |
| 6004 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 6005 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6006 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6007 | pci_disable_device(pdev); |
| 6008 | } |
| 6009 | |
| 6010 | /** |
| 6011 | * ixgbe_io_error_detected - called when PCI error is detected |
| 6012 | * @pdev: Pointer to PCI device |
| 6013 | * @state: The current pci connection state |
| 6014 | * |
| 6015 | * This function is called after a PCI bus error affecting |
| 6016 | * this device has been detected. |
| 6017 | */ |
| 6018 | 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] | 6019 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6020 | { |
| 6021 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 6022 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6023 | |
| 6024 | netif_device_detach(netdev); |
| 6025 | |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 6026 | if (state == pci_channel_io_perm_failure) |
| 6027 | return PCI_ERS_RESULT_DISCONNECT; |
| 6028 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6029 | if (netif_running(netdev)) |
| 6030 | ixgbe_down(adapter); |
| 6031 | pci_disable_device(pdev); |
| 6032 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6033 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6034 | return PCI_ERS_RESULT_NEED_RESET; |
| 6035 | } |
| 6036 | |
| 6037 | /** |
| 6038 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 6039 | * @pdev: Pointer to PCI device |
| 6040 | * |
| 6041 | * Restart the card from scratch, as if from a cold-boot. |
| 6042 | */ |
| 6043 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 6044 | { |
| 6045 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 6046 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6047 | pci_ers_result_t result; |
| 6048 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6049 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 6050 | if (pci_enable_device_mem(pdev)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6051 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6052 | "Cannot re-enable PCI device after reset.\n"); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6053 | result = PCI_ERS_RESULT_DISCONNECT; |
| 6054 | } else { |
| 6055 | pci_set_master(pdev); |
| 6056 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 6057 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6058 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 6059 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6060 | |
| 6061 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 6062 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6063 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6064 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6065 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6066 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 6067 | if (err) { |
| 6068 | dev_err(&pdev->dev, |
| 6069 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err); |
| 6070 | /* non-fatal, continue */ |
| 6071 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6072 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6073 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6074 | } |
| 6075 | |
| 6076 | /** |
| 6077 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 6078 | * @pdev: Pointer to PCI device |
| 6079 | * |
| 6080 | * This callback is called when the error recovery driver tells us that |
| 6081 | * its OK to resume normal operation. |
| 6082 | */ |
| 6083 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 6084 | { |
| 6085 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 6086 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6087 | |
| 6088 | if (netif_running(netdev)) { |
| 6089 | if (ixgbe_up(adapter)) { |
| 6090 | DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n"); |
| 6091 | return; |
| 6092 | } |
| 6093 | } |
| 6094 | |
| 6095 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6096 | } |
| 6097 | |
| 6098 | static struct pci_error_handlers ixgbe_err_handler = { |
| 6099 | .error_detected = ixgbe_io_error_detected, |
| 6100 | .slot_reset = ixgbe_io_slot_reset, |
| 6101 | .resume = ixgbe_io_resume, |
| 6102 | }; |
| 6103 | |
| 6104 | static struct pci_driver ixgbe_driver = { |
| 6105 | .name = ixgbe_driver_name, |
| 6106 | .id_table = ixgbe_pci_tbl, |
| 6107 | .probe = ixgbe_probe, |
| 6108 | .remove = __devexit_p(ixgbe_remove), |
| 6109 | #ifdef CONFIG_PM |
| 6110 | .suspend = ixgbe_suspend, |
| 6111 | .resume = ixgbe_resume, |
| 6112 | #endif |
| 6113 | .shutdown = ixgbe_shutdown, |
| 6114 | .err_handler = &ixgbe_err_handler |
| 6115 | }; |
| 6116 | |
| 6117 | /** |
| 6118 | * ixgbe_init_module - Driver Registration Routine |
| 6119 | * |
| 6120 | * ixgbe_init_module is the first routine called when the driver is |
| 6121 | * loaded. All it does is register with the PCI subsystem. |
| 6122 | **/ |
| 6123 | static int __init ixgbe_init_module(void) |
| 6124 | { |
| 6125 | int ret; |
| 6126 | printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name, |
| 6127 | ixgbe_driver_string, ixgbe_driver_version); |
| 6128 | |
| 6129 | printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright); |
| 6130 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6131 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6132 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6133 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6134 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6135 | ret = pci_register_driver(&ixgbe_driver); |
| 6136 | return ret; |
| 6137 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6138 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6139 | module_init(ixgbe_init_module); |
| 6140 | |
| 6141 | /** |
| 6142 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 6143 | * |
| 6144 | * ixgbe_exit_module is called just before the driver is removed |
| 6145 | * from memory. |
| 6146 | **/ |
| 6147 | static void __exit ixgbe_exit_module(void) |
| 6148 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6149 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6150 | dca_unregister_notify(&dca_notifier); |
| 6151 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6152 | pci_unregister_driver(&ixgbe_driver); |
| 6153 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6154 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6155 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6156 | 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] | 6157 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6158 | { |
| 6159 | int ret_val; |
| 6160 | |
| 6161 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6162 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6163 | |
| 6164 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 6165 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6166 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 6167 | #endif /* CONFIG_IXGBE_DCA */ |
| 6168 | #ifdef DEBUG |
| 6169 | /** |
| 6170 | * ixgbe_get_hw_dev_name - return device name string |
| 6171 | * used by hardware layer to print debugging information |
| 6172 | **/ |
| 6173 | char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw) |
| 6174 | { |
| 6175 | struct ixgbe_adapter *adapter = hw->back; |
| 6176 | return adapter->netdev->name; |
| 6177 | } |
| 6178 | |
| 6179 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6180 | module_exit(ixgbe_exit_module); |
| 6181 | |
| 6182 | /* ixgbe_main.c */ |