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 | 30b76832 | 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; |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 438 | return (count < tx_ring->work_limit); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 439 | } |
| 440 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 441 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 442 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 443 | struct ixgbe_ring *rx_ring) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 444 | { |
| 445 | u32 rxctrl; |
| 446 | int cpu = get_cpu(); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 447 | int q = rx_ring - adapter->rx_ring; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 448 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 449 | if (rx_ring->cpu != cpu) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 450 | rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 451 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 452 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK; |
| 453 | rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 454 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 455 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599; |
| 456 | rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 457 | IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599); |
| 458 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 459 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 460 | rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN; |
Don Skidmore | 15005a3 | 2009-01-19 16:54:13 -0800 | [diff] [blame] | 461 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN); |
| 462 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 463 | IXGBE_DCA_RXCTRL_DESC_HSRO_EN); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 464 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 465 | rx_ring->cpu = cpu; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 466 | } |
| 467 | put_cpu(); |
| 468 | } |
| 469 | |
| 470 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 471 | struct ixgbe_ring *tx_ring) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 472 | { |
| 473 | u32 txctrl; |
| 474 | int cpu = get_cpu(); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 475 | int q = tx_ring - adapter->tx_ring; |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 476 | struct ixgbe_hw *hw = &adapter->hw; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 477 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 478 | if (tx_ring->cpu != cpu) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 479 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 480 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 481 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK; |
| 482 | txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 483 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 484 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(q), txctrl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 485 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 486 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 487 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599; |
| 488 | txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 489 | IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599); |
| 490 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 491 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(q), txctrl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 492 | } |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 493 | tx_ring->cpu = cpu; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 494 | } |
| 495 | put_cpu(); |
| 496 | } |
| 497 | |
| 498 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 499 | { |
| 500 | int i; |
| 501 | |
| 502 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 503 | return; |
| 504 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 505 | /* always use CB2 mode, difference is masked in the CB driver */ |
| 506 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); |
| 507 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 508 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 509 | adapter->tx_ring[i].cpu = -1; |
| 510 | ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]); |
| 511 | } |
| 512 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 513 | adapter->rx_ring[i].cpu = -1; |
| 514 | ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]); |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 519 | { |
| 520 | struct net_device *netdev = dev_get_drvdata(dev); |
| 521 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 522 | unsigned long event = *(unsigned long *)data; |
| 523 | |
| 524 | switch (event) { |
| 525 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 526 | /* if we're already enabled, don't do it again */ |
| 527 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 528 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 529 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 530 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 531 | ixgbe_setup_dca(adapter); |
| 532 | break; |
| 533 | } |
| 534 | /* Fall Through since DCA is disabled. */ |
| 535 | case DCA_PROVIDER_REMOVE: |
| 536 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 537 | dca_remove_requester(dev); |
| 538 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 539 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 540 | } |
| 541 | break; |
| 542 | } |
| 543 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 544 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 545 | } |
| 546 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 547 | #endif /* CONFIG_IXGBE_DCA */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 548 | /** |
| 549 | * ixgbe_receive_skb - Send a completed packet up the stack |
| 550 | * @adapter: board private structure |
| 551 | * @skb: packet to send up |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 552 | * @status: hardware indication of status of receive |
| 553 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
| 554 | * @rx_desc: rx descriptor |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 555 | **/ |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 556 | static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 557 | struct sk_buff *skb, u8 status, |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 558 | struct ixgbe_ring *ring, |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 559 | union ixgbe_adv_rx_desc *rx_desc) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 560 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 561 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 562 | struct napi_struct *napi = &q_vector->napi; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 563 | bool is_vlan = (status & IXGBE_RXD_STAT_VP); |
| 564 | u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 565 | |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 566 | skb_record_rx_queue(skb, ring->queue_index); |
Alexander Duyck | 182ff8d | 2009-04-27 22:35:33 +0000 | [diff] [blame] | 567 | if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) { |
Lucy Liu | 8a62bab | 2009-08-13 14:09:38 +0000 | [diff] [blame] | 568 | if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK)) |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 569 | vlan_gro_receive(napi, adapter->vlgrp, tag, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 570 | else |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 571 | napi_gro_receive(napi, skb); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 572 | } else { |
Lucy Liu | 8a62bab | 2009-08-13 14:09:38 +0000 | [diff] [blame] | 573 | if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK)) |
Alexander Duyck | 182ff8d | 2009-04-27 22:35:33 +0000 | [diff] [blame] | 574 | vlan_hwaccel_rx(skb, adapter->vlgrp, tag); |
| 575 | else |
| 576 | netif_rx(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 577 | } |
| 578 | } |
| 579 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 580 | /** |
| 581 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
| 582 | * @adapter: address of board private structure |
| 583 | * @status_err: hardware indication of status of receive |
| 584 | * @skb: skb currently being received and modified |
| 585 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 586 | static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 587 | union ixgbe_adv_rx_desc *rx_desc, |
| 588 | struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 589 | { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 590 | u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 591 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 592 | skb->ip_summed = CHECKSUM_NONE; |
| 593 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 594 | /* Rx csum disabled */ |
| 595 | if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 596 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 597 | |
| 598 | /* if IP and error */ |
| 599 | if ((status_err & IXGBE_RXD_STAT_IPCS) && |
| 600 | (status_err & IXGBE_RXDADV_ERR_IPE)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 601 | adapter->hw_csum_rx_error++; |
| 602 | return; |
| 603 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 604 | |
| 605 | if (!(status_err & IXGBE_RXD_STAT_L4CS)) |
| 606 | return; |
| 607 | |
| 608 | if (status_err & IXGBE_RXDADV_ERR_TCPE) { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 609 | u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 610 | |
| 611 | /* |
| 612 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 613 | * checksum errors. |
| 614 | */ |
| 615 | if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) && |
| 616 | (adapter->hw.mac.type == ixgbe_mac_82599EB)) |
| 617 | return; |
| 618 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 619 | adapter->hw_csum_rx_error++; |
| 620 | return; |
| 621 | } |
| 622 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 623 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 624 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 625 | } |
| 626 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 627 | static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw, |
| 628 | struct ixgbe_ring *rx_ring, u32 val) |
| 629 | { |
| 630 | /* |
| 631 | * Force memory writes to complete before letting h/w |
| 632 | * know there are new descriptors to fetch. (Only |
| 633 | * applicable for weak-ordered memory model archs, |
| 634 | * such as IA-64). |
| 635 | */ |
| 636 | wmb(); |
| 637 | IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val); |
| 638 | } |
| 639 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 640 | /** |
| 641 | * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split |
| 642 | * @adapter: address of board private structure |
| 643 | **/ |
| 644 | static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 645 | struct ixgbe_ring *rx_ring, |
| 646 | int cleaned_count) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 647 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 648 | struct pci_dev *pdev = adapter->pdev; |
| 649 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 650 | struct ixgbe_rx_buffer *bi; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 651 | unsigned int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 652 | |
| 653 | i = rx_ring->next_to_use; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 654 | bi = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 655 | |
| 656 | while (cleaned_count--) { |
| 657 | rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 658 | |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 659 | if (!bi->page_dma && |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 660 | (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 661 | if (!bi->page) { |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 662 | bi->page = alloc_page(GFP_ATOMIC); |
| 663 | if (!bi->page) { |
| 664 | adapter->alloc_rx_page_failed++; |
| 665 | goto no_buffers; |
| 666 | } |
| 667 | bi->page_offset = 0; |
| 668 | } else { |
| 669 | /* use a half page if we're re-using */ |
| 670 | bi->page_offset ^= (PAGE_SIZE / 2); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 671 | } |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 672 | |
| 673 | bi->page_dma = pci_map_page(pdev, bi->page, |
| 674 | bi->page_offset, |
| 675 | (PAGE_SIZE / 2), |
| 676 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 677 | } |
| 678 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 679 | if (!bi->skb) { |
Jesse Brandeburg | 5ecc361 | 2008-12-15 01:00:57 -0800 | [diff] [blame] | 680 | struct sk_buff *skb; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 681 | /* netdev_alloc_skb reserves 32 bytes up front!! */ |
| 682 | uint bufsz = rx_ring->rx_buf_len + SMP_CACHE_BYTES; |
| 683 | skb = netdev_alloc_skb(adapter->netdev, bufsz); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 684 | |
| 685 | if (!skb) { |
| 686 | adapter->alloc_rx_buff_failed++; |
| 687 | goto no_buffers; |
| 688 | } |
| 689 | |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 690 | /* advance the data pointer to the next cache line */ |
| 691 | skb_reserve(skb, (PTR_ALIGN(skb->data, SMP_CACHE_BYTES) |
| 692 | - skb->data)); |
| 693 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 694 | bi->skb = skb; |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 695 | bi->dma = pci_map_single(pdev, skb->data, |
| 696 | rx_ring->rx_buf_len, |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 697 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 698 | } |
| 699 | /* Refresh the desc even if buffer_addrs didn't change because |
| 700 | * each write-back erases this info. */ |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 701 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 702 | rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma); |
| 703 | rx_desc->read.hdr_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 704 | } else { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 705 | rx_desc->read.pkt_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 706 | } |
| 707 | |
| 708 | i++; |
| 709 | if (i == rx_ring->count) |
| 710 | i = 0; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 711 | bi = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 712 | } |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 713 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 714 | no_buffers: |
| 715 | if (rx_ring->next_to_use != i) { |
| 716 | rx_ring->next_to_use = i; |
| 717 | if (i-- == 0) |
| 718 | i = (rx_ring->count - 1); |
| 719 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 720 | ixgbe_release_rx_desc(&adapter->hw, rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 721 | } |
| 722 | } |
| 723 | |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 724 | static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc) |
| 725 | { |
| 726 | return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info; |
| 727 | } |
| 728 | |
| 729 | static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc) |
| 730 | { |
| 731 | return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 732 | } |
| 733 | |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 734 | static inline u32 ixgbe_get_rsc_count(union ixgbe_adv_rx_desc *rx_desc) |
| 735 | { |
| 736 | return (le32_to_cpu(rx_desc->wb.lower.lo_dword.data) & |
| 737 | IXGBE_RXDADV_RSCCNT_MASK) >> |
| 738 | IXGBE_RXDADV_RSCCNT_SHIFT; |
| 739 | } |
| 740 | |
| 741 | /** |
| 742 | * ixgbe_transform_rsc_queue - change rsc queue into a full packet |
| 743 | * @skb: pointer to the last skb in the rsc queue |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 744 | * @count: pointer to number of packets coalesced in this context |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 745 | * |
| 746 | * This function changes a queue full of hw rsc buffers into a completed |
| 747 | * packet. It uses the ->prev pointers to find the first packet and then |
| 748 | * turns it into the frag list owner. |
| 749 | **/ |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 750 | static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb, |
| 751 | u64 *count) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 752 | { |
| 753 | unsigned int frag_list_size = 0; |
| 754 | |
| 755 | while (skb->prev) { |
| 756 | struct sk_buff *prev = skb->prev; |
| 757 | frag_list_size += skb->len; |
| 758 | skb->prev = NULL; |
| 759 | skb = prev; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 760 | *count += 1; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 761 | } |
| 762 | |
| 763 | skb_shinfo(skb)->frag_list = skb->next; |
| 764 | skb->next = NULL; |
| 765 | skb->len += frag_list_size; |
| 766 | skb->data_len += frag_list_size; |
| 767 | skb->truesize += frag_list_size; |
| 768 | return skb; |
| 769 | } |
| 770 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 771 | 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] | 772 | struct ixgbe_ring *rx_ring, |
| 773 | int *work_done, int work_to_do) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 774 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 775 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 776 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 777 | struct pci_dev *pdev = adapter->pdev; |
| 778 | union ixgbe_adv_rx_desc *rx_desc, *next_rxd; |
| 779 | struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer; |
| 780 | struct sk_buff *skb; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 781 | unsigned int i, rsc_count = 0; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 782 | u32 len, staterr; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 783 | u16 hdr_info; |
| 784 | bool cleaned = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 785 | int cleaned_count = 0; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 786 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 787 | #ifdef IXGBE_FCOE |
| 788 | int ddp_bytes = 0; |
| 789 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 790 | |
| 791 | i = rx_ring->next_to_clean; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 792 | rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 793 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 794 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 795 | |
| 796 | while (staterr & IXGBE_RXD_STAT_DD) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 797 | u32 upper_len = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 798 | if (*work_done >= work_to_do) |
| 799 | break; |
| 800 | (*work_done)++; |
| 801 | |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 802 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 803 | hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc)); |
| 804 | len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >> |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 805 | IXGBE_RXDADV_HDRBUFLEN_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 806 | if (len > IXGBE_RX_HDR_SIZE) |
| 807 | len = IXGBE_RX_HDR_SIZE; |
| 808 | upper_len = le16_to_cpu(rx_desc->wb.upper.length); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 809 | } else { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 810 | len = le16_to_cpu(rx_desc->wb.upper.length); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 811 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 812 | |
| 813 | cleaned = true; |
| 814 | skb = rx_buffer_info->skb; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 815 | prefetch(skb->data); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 816 | rx_buffer_info->skb = NULL; |
| 817 | |
Alexander Duyck | 21fa4e6 | 2009-06-04 15:59:49 +0000 | [diff] [blame] | 818 | if (rx_buffer_info->dma) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 819 | pci_unmap_single(pdev, rx_buffer_info->dma, |
Jesse Brandeburg | 5ecc361 | 2008-12-15 01:00:57 -0800 | [diff] [blame] | 820 | rx_ring->rx_buf_len, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 821 | PCI_DMA_FROMDEVICE); |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 822 | rx_buffer_info->dma = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 823 | skb_put(skb, len); |
| 824 | } |
| 825 | |
| 826 | if (upper_len) { |
| 827 | pci_unmap_page(pdev, rx_buffer_info->page_dma, |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 828 | PAGE_SIZE / 2, PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 829 | rx_buffer_info->page_dma = 0; |
| 830 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 831 | rx_buffer_info->page, |
| 832 | rx_buffer_info->page_offset, |
| 833 | upper_len); |
| 834 | |
| 835 | if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) || |
| 836 | (page_count(rx_buffer_info->page) != 1)) |
| 837 | rx_buffer_info->page = NULL; |
| 838 | else |
| 839 | get_page(rx_buffer_info->page); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 840 | |
| 841 | skb->len += upper_len; |
| 842 | skb->data_len += upper_len; |
| 843 | skb->truesize += upper_len; |
| 844 | } |
| 845 | |
| 846 | i++; |
| 847 | if (i == rx_ring->count) |
| 848 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 849 | |
| 850 | next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 851 | prefetch(next_rxd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 852 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 853 | |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 854 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 855 | rsc_count = ixgbe_get_rsc_count(rx_desc); |
| 856 | |
| 857 | if (rsc_count) { |
| 858 | u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >> |
| 859 | IXGBE_RXDADV_NEXTP_SHIFT; |
| 860 | next_buffer = &rx_ring->rx_buffer_info[nextp]; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 861 | } else { |
| 862 | next_buffer = &rx_ring->rx_buffer_info[i]; |
| 863 | } |
| 864 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 865 | if (staterr & IXGBE_RXD_STAT_EOP) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 866 | if (skb->prev) |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 867 | skb = ixgbe_transform_rsc_queue(skb, &(rx_ring->rsc_count)); |
| 868 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
| 869 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) |
| 870 | rx_ring->rsc_count += skb_shinfo(skb)->nr_frags; |
| 871 | else |
| 872 | rx_ring->rsc_count++; |
| 873 | rx_ring->rsc_flush++; |
| 874 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 875 | rx_ring->stats.packets++; |
| 876 | rx_ring->stats.bytes += skb->len; |
| 877 | } else { |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 878 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 879 | rx_buffer_info->skb = next_buffer->skb; |
| 880 | rx_buffer_info->dma = next_buffer->dma; |
| 881 | next_buffer->skb = skb; |
| 882 | next_buffer->dma = 0; |
| 883 | } else { |
| 884 | skb->next = next_buffer->skb; |
| 885 | skb->next->prev = skb; |
| 886 | } |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 887 | rx_ring->non_eop_descs++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 888 | goto next_desc; |
| 889 | } |
| 890 | |
| 891 | if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) { |
| 892 | dev_kfree_skb_irq(skb); |
| 893 | goto next_desc; |
| 894 | } |
| 895 | |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 896 | ixgbe_rx_checksum(adapter, rx_desc, skb); |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 897 | |
| 898 | /* probably a little skewed due to removing CRC */ |
| 899 | total_rx_bytes += skb->len; |
| 900 | total_rx_packets++; |
| 901 | |
Jesse Brandeburg | 74ce8dd | 2008-09-11 20:03:23 -0700 | [diff] [blame] | 902 | skb->protocol = eth_type_trans(skb, adapter->netdev); |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 903 | #ifdef IXGBE_FCOE |
| 904 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 905 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 906 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
| 907 | if (!ddp_bytes) |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 908 | goto next_desc; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 909 | } |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 910 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 911 | ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 912 | |
| 913 | next_desc: |
| 914 | rx_desc->wb.upper.status_error = 0; |
| 915 | |
| 916 | /* return some buffers to hardware, one at a time is too slow */ |
| 917 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 918 | ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count); |
| 919 | cleaned_count = 0; |
| 920 | } |
| 921 | |
| 922 | /* use prefetched values */ |
| 923 | rx_desc = next_rxd; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 924 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 925 | |
| 926 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 927 | } |
| 928 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 929 | rx_ring->next_to_clean = i; |
| 930 | cleaned_count = IXGBE_DESC_UNUSED(rx_ring); |
| 931 | |
| 932 | if (cleaned_count) |
| 933 | ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count); |
| 934 | |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 935 | #ifdef IXGBE_FCOE |
| 936 | /* include DDPed FCoE data */ |
| 937 | if (ddp_bytes > 0) { |
| 938 | unsigned int mss; |
| 939 | |
| 940 | mss = adapter->netdev->mtu - sizeof(struct fcoe_hdr) - |
| 941 | sizeof(struct fc_frame_header) - |
| 942 | sizeof(struct fcoe_crc_eof); |
| 943 | if (mss > 512) |
| 944 | mss &= ~511; |
| 945 | total_rx_bytes += ddp_bytes; |
| 946 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss); |
| 947 | } |
| 948 | #endif /* IXGBE_FCOE */ |
| 949 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 950 | rx_ring->total_packets += total_rx_packets; |
| 951 | rx_ring->total_bytes += total_rx_bytes; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 952 | netdev->stats.rx_bytes += total_rx_bytes; |
| 953 | netdev->stats.rx_packets += total_rx_packets; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 954 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 955 | return cleaned; |
| 956 | } |
| 957 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 958 | static int ixgbe_clean_rxonly(struct napi_struct *, int); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 959 | /** |
| 960 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 961 | * @adapter: board private structure |
| 962 | * |
| 963 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 964 | * interrupts. |
| 965 | **/ |
| 966 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 967 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 968 | struct ixgbe_q_vector *q_vector; |
| 969 | int i, j, q_vectors, v_idx, r_idx; |
| 970 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 971 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 972 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 973 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 974 | /* |
| 975 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 976 | * corresponding register. |
| 977 | */ |
| 978 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 979 | q_vector = adapter->q_vector[v_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 980 | /* XXX for_each_bit(...) */ |
| 981 | r_idx = find_first_bit(q_vector->rxr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 982 | adapter->num_rx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 983 | |
| 984 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 985 | j = adapter->rx_ring[r_idx].reg_idx; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 986 | ixgbe_set_ivar(adapter, 0, j, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 987 | r_idx = find_next_bit(q_vector->rxr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 988 | adapter->num_rx_queues, |
| 989 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 990 | } |
| 991 | r_idx = find_first_bit(q_vector->txr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 992 | adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 993 | |
| 994 | for (i = 0; i < q_vector->txr_count; i++) { |
| 995 | j = adapter->tx_ring[r_idx].reg_idx; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 996 | ixgbe_set_ivar(adapter, 1, j, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 997 | r_idx = find_next_bit(q_vector->txr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 998 | adapter->num_tx_queues, |
| 999 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1000 | } |
| 1001 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1002 | if (q_vector->txr_count && !q_vector->rxr_count) |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1003 | /* tx only */ |
| 1004 | q_vector->eitr = adapter->tx_eitr_param; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1005 | else if (q_vector->rxr_count) |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1006 | /* rx or mixed */ |
| 1007 | q_vector->eitr = adapter->rx_eitr_param; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1008 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1009 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1010 | } |
| 1011 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1012 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 1013 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
| 1014 | v_idx); |
| 1015 | else if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 1016 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1017 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1018 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 1019 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1020 | mask = IXGBE_EIMS_ENABLE_MASK; |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 1021 | mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1022 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1023 | } |
| 1024 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1025 | enum latency_range { |
| 1026 | lowest_latency = 0, |
| 1027 | low_latency = 1, |
| 1028 | bulk_latency = 2, |
| 1029 | latency_invalid = 255 |
| 1030 | }; |
| 1031 | |
| 1032 | /** |
| 1033 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
| 1034 | * @adapter: pointer to adapter |
| 1035 | * @eitr: eitr setting (ints per sec) to give last timeslice |
| 1036 | * @itr_setting: current throttle rate in ints/second |
| 1037 | * @packets: the number of packets during this measurement interval |
| 1038 | * @bytes: the number of bytes during this measurement interval |
| 1039 | * |
| 1040 | * Stores a new ITR value based on packets and byte |
| 1041 | * counts during the last interrupt. The advantage of per interrupt |
| 1042 | * computation is faster updates and more accurate ITR for the current |
| 1043 | * traffic pattern. Constants in this function were computed |
| 1044 | * based on theoretical maximum wire speed and thresholds were set based |
| 1045 | * on testing data as well as attempting to minimize response time |
| 1046 | * while increasing bulk throughput. |
| 1047 | * this functionality is controlled by the InterruptThrottleRate module |
| 1048 | * parameter (see ixgbe_param.c) |
| 1049 | **/ |
| 1050 | static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1051 | u32 eitr, u8 itr_setting, |
| 1052 | int packets, int bytes) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1053 | { |
| 1054 | unsigned int retval = itr_setting; |
| 1055 | u32 timepassed_us; |
| 1056 | u64 bytes_perint; |
| 1057 | |
| 1058 | if (packets == 0) |
| 1059 | goto update_itr_done; |
| 1060 | |
| 1061 | |
| 1062 | /* simple throttlerate management |
| 1063 | * 0-20MB/s lowest (100000 ints/s) |
| 1064 | * 20-100MB/s low (20000 ints/s) |
| 1065 | * 100-1249MB/s bulk (8000 ints/s) |
| 1066 | */ |
| 1067 | /* what was last interrupt timeslice? */ |
| 1068 | timepassed_us = 1000000/eitr; |
| 1069 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 1070 | |
| 1071 | switch (itr_setting) { |
| 1072 | case lowest_latency: |
| 1073 | if (bytes_perint > adapter->eitr_low) |
| 1074 | retval = low_latency; |
| 1075 | break; |
| 1076 | case low_latency: |
| 1077 | if (bytes_perint > adapter->eitr_high) |
| 1078 | retval = bulk_latency; |
| 1079 | else if (bytes_perint <= adapter->eitr_low) |
| 1080 | retval = lowest_latency; |
| 1081 | break; |
| 1082 | case bulk_latency: |
| 1083 | if (bytes_perint <= adapter->eitr_high) |
| 1084 | retval = low_latency; |
| 1085 | break; |
| 1086 | } |
| 1087 | |
| 1088 | update_itr_done: |
| 1089 | return retval; |
| 1090 | } |
| 1091 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1092 | /** |
| 1093 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1094 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1095 | * |
| 1096 | * This function is made to be called by ethtool and by the driver |
| 1097 | * when it needs to update EITR registers at runtime. Hardware |
| 1098 | * specific quirks/differences are taken care of here. |
| 1099 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1100 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1101 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1102 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1103 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1104 | int v_idx = q_vector->v_idx; |
| 1105 | u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr); |
| 1106 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1107 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1108 | /* must write high and low 16 bits to reset counter */ |
| 1109 | itr_reg |= (itr_reg << 16); |
| 1110 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 1111 | /* |
| 1112 | * set the WDIS bit to not clear the timer bits and cause an |
| 1113 | * immediate assertion of the interrupt |
| 1114 | */ |
| 1115 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
| 1116 | } |
| 1117 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 1118 | } |
| 1119 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1120 | static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector) |
| 1121 | { |
| 1122 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1123 | u32 new_itr; |
| 1124 | u8 current_itr, ret_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1125 | int i, r_idx; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1126 | struct ixgbe_ring *rx_ring, *tx_ring; |
| 1127 | |
| 1128 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1129 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1130 | tx_ring = &(adapter->tx_ring[r_idx]); |
| 1131 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1132 | q_vector->tx_itr, |
| 1133 | tx_ring->total_packets, |
| 1134 | tx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1135 | /* if the result for this queue would decrease interrupt |
| 1136 | * rate for this vector then use that result */ |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1137 | q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ? |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1138 | q_vector->tx_itr - 1 : ret_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1139 | 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] | 1140 | r_idx + 1); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1141 | } |
| 1142 | |
| 1143 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1144 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1145 | rx_ring = &(adapter->rx_ring[r_idx]); |
| 1146 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1147 | q_vector->rx_itr, |
| 1148 | rx_ring->total_packets, |
| 1149 | rx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1150 | /* if the result for this queue would decrease interrupt |
| 1151 | * rate for this vector then use that result */ |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1152 | q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ? |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1153 | q_vector->rx_itr - 1 : ret_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1154 | 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] | 1155 | r_idx + 1); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1156 | } |
| 1157 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1158 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1159 | |
| 1160 | switch (current_itr) { |
| 1161 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1162 | case lowest_latency: |
| 1163 | new_itr = 100000; |
| 1164 | break; |
| 1165 | case low_latency: |
| 1166 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 1167 | break; |
| 1168 | case bulk_latency: |
| 1169 | default: |
| 1170 | new_itr = 8000; |
| 1171 | break; |
| 1172 | } |
| 1173 | |
| 1174 | if (new_itr != q_vector->eitr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1175 | /* do an exponential smoothing */ |
| 1176 | new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1177 | |
| 1178 | /* save the algorithm value here, not the smoothed one */ |
| 1179 | q_vector->eitr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1180 | |
| 1181 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1182 | } |
| 1183 | |
| 1184 | return; |
| 1185 | } |
| 1186 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1187 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 1188 | { |
| 1189 | struct ixgbe_hw *hw = &adapter->hw; |
| 1190 | |
| 1191 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
| 1192 | (eicr & IXGBE_EICR_GPI_SDP1)) { |
| 1193 | DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n"); |
| 1194 | /* write to clear the interrupt */ |
| 1195 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 1196 | } |
| 1197 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1198 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1199 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 1200 | { |
| 1201 | struct ixgbe_hw *hw = &adapter->hw; |
| 1202 | |
| 1203 | if (eicr & IXGBE_EICR_GPI_SDP1) { |
| 1204 | /* Clear the interrupt */ |
| 1205 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 1206 | schedule_work(&adapter->multispeed_fiber_task); |
| 1207 | } else if (eicr & IXGBE_EICR_GPI_SDP2) { |
| 1208 | /* Clear the interrupt */ |
| 1209 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2); |
| 1210 | schedule_work(&adapter->sfp_config_module_task); |
| 1211 | } else { |
| 1212 | /* Interrupt isn't for us... */ |
| 1213 | return; |
| 1214 | } |
| 1215 | } |
| 1216 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1217 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 1218 | { |
| 1219 | struct ixgbe_hw *hw = &adapter->hw; |
| 1220 | |
| 1221 | adapter->lsc_int++; |
| 1222 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 1223 | adapter->link_check_timeout = jiffies; |
| 1224 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1225 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
Nelson, Shannon | 8a0717f | 2009-11-12 18:47:11 +0000 | [diff] [blame] | 1226 | IXGBE_WRITE_FLUSH(hw); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1227 | schedule_work(&adapter->watchdog_task); |
| 1228 | } |
| 1229 | } |
| 1230 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1231 | static irqreturn_t ixgbe_msix_lsc(int irq, void *data) |
| 1232 | { |
| 1233 | struct net_device *netdev = data; |
| 1234 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1235 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 1236 | u32 eicr; |
| 1237 | |
| 1238 | /* |
| 1239 | * Workaround for Silicon errata. Use clear-by-write instead |
| 1240 | * of clear-by-read. Reading with EICS will return the |
| 1241 | * interrupt causes without clearing, which later be done |
| 1242 | * with the write to EICR. |
| 1243 | */ |
| 1244 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
| 1245 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1246 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1247 | if (eicr & IXGBE_EICR_LSC) |
| 1248 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1249 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1250 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 1251 | ixgbe_check_fan_failure(adapter, eicr); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1252 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1253 | if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1254 | ixgbe_check_sfp_event(adapter, eicr); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1255 | |
| 1256 | /* Handle Flow Director Full threshold interrupt */ |
| 1257 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
| 1258 | int i; |
| 1259 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR); |
| 1260 | /* Disable transmits before FDIR Re-initialization */ |
| 1261 | netif_tx_stop_all_queues(netdev); |
| 1262 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 1263 | struct ixgbe_ring *tx_ring = |
| 1264 | &adapter->tx_ring[i]; |
| 1265 | if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE, |
| 1266 | &tx_ring->reinit_state)) |
| 1267 | schedule_work(&adapter->fdir_reinit_task); |
| 1268 | } |
| 1269 | } |
| 1270 | } |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1271 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1272 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1273 | |
| 1274 | return IRQ_HANDLED; |
| 1275 | } |
| 1276 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1277 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 1278 | u64 qmask) |
| 1279 | { |
| 1280 | u32 mask; |
| 1281 | |
| 1282 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1283 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 1284 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 1285 | } else { |
| 1286 | mask = (qmask & 0xFFFFFFFF); |
| 1287 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(0), mask); |
| 1288 | mask = (qmask >> 32); |
| 1289 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask); |
| 1290 | } |
| 1291 | /* skip the flush */ |
| 1292 | } |
| 1293 | |
| 1294 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
| 1295 | u64 qmask) |
| 1296 | { |
| 1297 | u32 mask; |
| 1298 | |
| 1299 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1300 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 1301 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask); |
| 1302 | } else { |
| 1303 | mask = (qmask & 0xFFFFFFFF); |
| 1304 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), mask); |
| 1305 | mask = (qmask >> 32); |
| 1306 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), mask); |
| 1307 | } |
| 1308 | /* skip the flush */ |
| 1309 | } |
| 1310 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1311 | static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data) |
| 1312 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1313 | struct ixgbe_q_vector *q_vector = data; |
| 1314 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1315 | struct ixgbe_ring *tx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1316 | int i, r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1317 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1318 | if (!q_vector->txr_count) |
| 1319 | return IRQ_HANDLED; |
| 1320 | |
| 1321 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1322 | for (i = 0; i < q_vector->txr_count; i++) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1323 | tx_ring = &(adapter->tx_ring[r_idx]); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1324 | tx_ring->total_bytes = 0; |
| 1325 | tx_ring->total_packets = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1326 | 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] | 1327 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1328 | } |
| 1329 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 1330 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1331 | napi_schedule(&q_vector->napi); |
| 1332 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1333 | return IRQ_HANDLED; |
| 1334 | } |
| 1335 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1336 | /** |
| 1337 | * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues) |
| 1338 | * @irq: unused |
| 1339 | * @data: pointer to our q_vector struct for this interrupt vector |
| 1340 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1341 | static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data) |
| 1342 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1343 | struct ixgbe_q_vector *q_vector = data; |
| 1344 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1345 | struct ixgbe_ring *rx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1346 | int r_idx; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1347 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1348 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1349 | 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] | 1350 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1351 | rx_ring = &(adapter->rx_ring[r_idx]); |
| 1352 | rx_ring->total_bytes = 0; |
| 1353 | rx_ring->total_packets = 0; |
| 1354 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1355 | r_idx + 1); |
| 1356 | } |
| 1357 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1358 | if (!q_vector->rxr_count) |
| 1359 | return IRQ_HANDLED; |
| 1360 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1361 | /* disable interrupts on this vector only */ |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 1362 | /* EIAM disabled interrupts (on this vector) for us */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1363 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1364 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1365 | return IRQ_HANDLED; |
| 1366 | } |
| 1367 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1368 | static irqreturn_t ixgbe_msix_clean_many(int irq, void *data) |
| 1369 | { |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1370 | struct ixgbe_q_vector *q_vector = data; |
| 1371 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1372 | struct ixgbe_ring *ring; |
| 1373 | int r_idx; |
| 1374 | int i; |
| 1375 | |
| 1376 | if (!q_vector->txr_count && !q_vector->rxr_count) |
| 1377 | return IRQ_HANDLED; |
| 1378 | |
| 1379 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1380 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1381 | ring = &(adapter->tx_ring[r_idx]); |
| 1382 | ring->total_bytes = 0; |
| 1383 | ring->total_packets = 0; |
| 1384 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
| 1385 | r_idx + 1); |
| 1386 | } |
| 1387 | |
| 1388 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1389 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1390 | ring = &(adapter->rx_ring[r_idx]); |
| 1391 | ring->total_bytes = 0; |
| 1392 | ring->total_packets = 0; |
| 1393 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1394 | r_idx + 1); |
| 1395 | } |
| 1396 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 1397 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1398 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1399 | |
| 1400 | return IRQ_HANDLED; |
| 1401 | } |
| 1402 | |
| 1403 | /** |
| 1404 | * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine |
| 1405 | * @napi: napi struct with our devices info in it |
| 1406 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1407 | * |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1408 | * This function is optimized for cleaning one queue only on a single |
| 1409 | * q_vector!!! |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1410 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1411 | static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget) |
| 1412 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1413 | struct ixgbe_q_vector *q_vector = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1414 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1415 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1416 | struct ixgbe_ring *rx_ring = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1417 | int work_done = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1418 | long r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1419 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1420 | 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] | 1421 | rx_ring = &(adapter->rx_ring[r_idx]); |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1422 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1423 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1424 | ixgbe_update_rx_dca(adapter, rx_ring); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1425 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1426 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1427 | ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1428 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1429 | /* If all Rx work done, exit the polling mode */ |
| 1430 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1431 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1432 | if (adapter->rx_itr_setting & 1) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1433 | ixgbe_set_itr_msix(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1434 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1435 | ixgbe_irq_enable_queues(adapter, |
| 1436 | ((u64)1 << q_vector->v_idx)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1437 | } |
| 1438 | |
| 1439 | return work_done; |
| 1440 | } |
| 1441 | |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1442 | /** |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1443 | * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1444 | * @napi: napi struct with our devices info in it |
| 1445 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1446 | * |
| 1447 | * This function will clean more than one rx queue associated with a |
| 1448 | * q_vector. |
| 1449 | **/ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1450 | static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget) |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1451 | { |
| 1452 | struct ixgbe_q_vector *q_vector = |
| 1453 | container_of(napi, struct ixgbe_q_vector, napi); |
| 1454 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1455 | struct ixgbe_ring *ring = NULL; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1456 | int work_done = 0, i; |
| 1457 | long r_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1458 | bool tx_clean_complete = true; |
| 1459 | |
| 1460 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1461 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1462 | ring = &(adapter->tx_ring[r_idx]); |
| 1463 | #ifdef CONFIG_IXGBE_DCA |
| 1464 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1465 | ixgbe_update_tx_dca(adapter, ring); |
| 1466 | #endif |
| 1467 | tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring); |
| 1468 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
| 1469 | r_idx + 1); |
| 1470 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1471 | |
| 1472 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 1473 | * the budget to go below 1 because we'll exit polling */ |
| 1474 | budget /= (q_vector->rxr_count ?: 1); |
| 1475 | budget = max(budget, 1); |
| 1476 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1477 | for (i = 0; i < q_vector->rxr_count; i++) { |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1478 | ring = &(adapter->rx_ring[r_idx]); |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1479 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1480 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1481 | ixgbe_update_rx_dca(adapter, ring); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1482 | #endif |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1483 | ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1484 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1485 | r_idx + 1); |
| 1486 | } |
| 1487 | |
| 1488 | 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] | 1489 | ring = &(adapter->rx_ring[r_idx]); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1490 | /* If all Rx work done, exit the polling mode */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 1491 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1492 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1493 | if (adapter->rx_itr_setting & 1) |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1494 | ixgbe_set_itr_msix(q_vector); |
| 1495 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1496 | ixgbe_irq_enable_queues(adapter, |
| 1497 | ((u64)1 << q_vector->v_idx)); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1498 | return 0; |
| 1499 | } |
| 1500 | |
| 1501 | return work_done; |
| 1502 | } |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1503 | |
| 1504 | /** |
| 1505 | * ixgbe_clean_txonly - msix (aka one shot) tx clean routine |
| 1506 | * @napi: napi struct with our devices info in it |
| 1507 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1508 | * |
| 1509 | * This function is optimized for cleaning one queue only on a single |
| 1510 | * q_vector!!! |
| 1511 | **/ |
| 1512 | static int ixgbe_clean_txonly(struct napi_struct *napi, int budget) |
| 1513 | { |
| 1514 | struct ixgbe_q_vector *q_vector = |
| 1515 | container_of(napi, struct ixgbe_q_vector, napi); |
| 1516 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1517 | struct ixgbe_ring *tx_ring = NULL; |
| 1518 | int work_done = 0; |
| 1519 | long r_idx; |
| 1520 | |
| 1521 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1522 | tx_ring = &(adapter->tx_ring[r_idx]); |
| 1523 | #ifdef CONFIG_IXGBE_DCA |
| 1524 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1525 | ixgbe_update_tx_dca(adapter, tx_ring); |
| 1526 | #endif |
| 1527 | |
| 1528 | if (!ixgbe_clean_tx_irq(q_vector, tx_ring)) |
| 1529 | work_done = budget; |
| 1530 | |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1531 | /* If all Tx work done, exit the polling mode */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1532 | if (work_done < budget) { |
| 1533 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1534 | if (adapter->tx_itr_setting & 1) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1535 | ixgbe_set_itr_msix(q_vector); |
| 1536 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1537 | ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 1538 | } |
| 1539 | |
| 1540 | return work_done; |
| 1541 | } |
| 1542 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1543 | 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] | 1544 | int r_idx) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1545 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1546 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
| 1547 | |
| 1548 | set_bit(r_idx, q_vector->rxr_idx); |
| 1549 | q_vector->rxr_count++; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1550 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1551 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1552 | 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] | 1553 | int t_idx) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1554 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1555 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
| 1556 | |
| 1557 | set_bit(t_idx, q_vector->txr_idx); |
| 1558 | q_vector->txr_count++; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1559 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1560 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1561 | /** |
| 1562 | * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors |
| 1563 | * @adapter: board private structure to initialize |
| 1564 | * @vectors: allotted vector count for descriptor rings |
| 1565 | * |
| 1566 | * This function maps descriptor rings to the queue-specific vectors |
| 1567 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 1568 | * one vector per ring/queue, but on a constrained vector budget, we |
| 1569 | * group the rings as "efficiently" as possible. You would add new |
| 1570 | * mapping configurations in here. |
| 1571 | **/ |
| 1572 | static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1573 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1574 | { |
| 1575 | int v_start = 0; |
| 1576 | int rxr_idx = 0, txr_idx = 0; |
| 1577 | int rxr_remaining = adapter->num_rx_queues; |
| 1578 | int txr_remaining = adapter->num_tx_queues; |
| 1579 | int i, j; |
| 1580 | int rqpv, tqpv; |
| 1581 | int err = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1582 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1583 | /* No mapping required if MSI-X is disabled. */ |
| 1584 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1585 | goto out; |
| 1586 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1587 | /* |
| 1588 | * The ideal configuration... |
| 1589 | * We have enough vectors to map one per queue. |
| 1590 | */ |
| 1591 | if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) { |
| 1592 | for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++) |
| 1593 | map_vector_to_rxq(adapter, v_start, rxr_idx); |
| 1594 | |
| 1595 | for (; txr_idx < txr_remaining; v_start++, txr_idx++) |
| 1596 | map_vector_to_txq(adapter, v_start, txr_idx); |
| 1597 | |
| 1598 | goto out; |
| 1599 | } |
| 1600 | |
| 1601 | /* |
| 1602 | * If we don't have enough vectors for a 1-to-1 |
| 1603 | * mapping, we'll have to group them so there are |
| 1604 | * multiple queues per vector. |
| 1605 | */ |
| 1606 | /* Re-adjusting *qpv takes care of the remainder. */ |
| 1607 | for (i = v_start; i < vectors; i++) { |
| 1608 | rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i); |
| 1609 | for (j = 0; j < rqpv; j++) { |
| 1610 | map_vector_to_rxq(adapter, i, rxr_idx); |
| 1611 | rxr_idx++; |
| 1612 | rxr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1613 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1614 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1615 | for (i = v_start; i < vectors; i++) { |
| 1616 | tqpv = DIV_ROUND_UP(txr_remaining, vectors - i); |
| 1617 | for (j = 0; j < tqpv; j++) { |
| 1618 | map_vector_to_txq(adapter, i, txr_idx); |
| 1619 | txr_idx++; |
| 1620 | txr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1621 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1622 | } |
| 1623 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1624 | out: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1625 | return err; |
| 1626 | } |
| 1627 | |
| 1628 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1629 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 1630 | * @adapter: board private structure |
| 1631 | * |
| 1632 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 1633 | * interrupts from the kernel. |
| 1634 | **/ |
| 1635 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 1636 | { |
| 1637 | struct net_device *netdev = adapter->netdev; |
| 1638 | irqreturn_t (*handler)(int, void *); |
| 1639 | int i, vector, q_vectors, err; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 1640 | int ri=0, ti=0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1641 | |
| 1642 | /* Decrement for Other and TCP Timer vectors */ |
| 1643 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1644 | |
| 1645 | /* Map the Tx/Rx rings to the vectors we were allotted. */ |
| 1646 | err = ixgbe_map_rings_to_vectors(adapter, q_vectors); |
| 1647 | if (err) |
| 1648 | goto out; |
| 1649 | |
| 1650 | #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \ |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1651 | (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \ |
| 1652 | &ixgbe_msix_clean_many) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1653 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1654 | handler = SET_HANDLER(adapter->q_vector[vector]); |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 1655 | |
| 1656 | if(handler == &ixgbe_msix_clean_rx) { |
| 1657 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1658 | netdev->name, "rx", ri++); |
| 1659 | } |
| 1660 | else if(handler == &ixgbe_msix_clean_tx) { |
| 1661 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1662 | netdev->name, "tx", ti++); |
| 1663 | } |
| 1664 | else |
| 1665 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1666 | netdev->name, "TxRx", vector); |
| 1667 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1668 | err = request_irq(adapter->msix_entries[vector].vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1669 | handler, 0, adapter->name[vector], |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1670 | adapter->q_vector[vector]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1671 | if (err) { |
| 1672 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1673 | "request_irq failed for MSIX interrupt " |
| 1674 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1675 | goto free_queue_irqs; |
| 1676 | } |
| 1677 | } |
| 1678 | |
| 1679 | sprintf(adapter->name[vector], "%s:lsc", netdev->name); |
| 1680 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1681 | ixgbe_msix_lsc, 0, adapter->name[vector], netdev); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1682 | if (err) { |
| 1683 | DPRINTK(PROBE, ERR, |
| 1684 | "request_irq for msix_lsc failed: %d\n", err); |
| 1685 | goto free_queue_irqs; |
| 1686 | } |
| 1687 | |
| 1688 | return 0; |
| 1689 | |
| 1690 | free_queue_irqs: |
| 1691 | for (i = vector - 1; i >= 0; i--) |
| 1692 | free_irq(adapter->msix_entries[--vector].vector, |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1693 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1694 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 1695 | pci_disable_msix(adapter->pdev); |
| 1696 | kfree(adapter->msix_entries); |
| 1697 | adapter->msix_entries = NULL; |
| 1698 | out: |
| 1699 | return err; |
| 1700 | } |
| 1701 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1702 | static void ixgbe_set_itr(struct ixgbe_adapter *adapter) |
| 1703 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1704 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1705 | u8 current_itr; |
| 1706 | u32 new_itr = q_vector->eitr; |
| 1707 | struct ixgbe_ring *rx_ring = &adapter->rx_ring[0]; |
| 1708 | struct ixgbe_ring *tx_ring = &adapter->tx_ring[0]; |
| 1709 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1710 | q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1711 | q_vector->tx_itr, |
| 1712 | tx_ring->total_packets, |
| 1713 | tx_ring->total_bytes); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1714 | q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1715 | q_vector->rx_itr, |
| 1716 | rx_ring->total_packets, |
| 1717 | rx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1718 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1719 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1720 | |
| 1721 | switch (current_itr) { |
| 1722 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1723 | case lowest_latency: |
| 1724 | new_itr = 100000; |
| 1725 | break; |
| 1726 | case low_latency: |
| 1727 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 1728 | break; |
| 1729 | case bulk_latency: |
| 1730 | new_itr = 8000; |
| 1731 | break; |
| 1732 | default: |
| 1733 | break; |
| 1734 | } |
| 1735 | |
| 1736 | if (new_itr != q_vector->eitr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1737 | /* do an exponential smoothing */ |
| 1738 | new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1739 | |
| 1740 | /* save the algorithm value here, not the smoothed one */ |
| 1741 | q_vector->eitr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1742 | |
| 1743 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1744 | } |
| 1745 | |
| 1746 | return; |
| 1747 | } |
| 1748 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1749 | /** |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1750 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 1751 | * @adapter: board private structure |
| 1752 | **/ |
| 1753 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter) |
| 1754 | { |
| 1755 | u32 mask; |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1756 | |
| 1757 | mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
David S. Miller | 6ab33d5 | 2008-11-20 16:44:00 -0800 | [diff] [blame] | 1758 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
| 1759 | mask |= IXGBE_EIMS_GPI_SDP1; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1760 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 1761 | mask |= IXGBE_EIMS_ECC; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1762 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 1763 | mask |= IXGBE_EIMS_GPI_SDP2; |
| 1764 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1765 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 1766 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 1767 | mask |= IXGBE_EIMS_FLOW_DIR; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1768 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1769 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1770 | ixgbe_irq_enable_queues(adapter, ~0); |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1771 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 1772 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1773 | |
| 1774 | /** |
| 1775 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1776 | * @irq: interrupt number |
| 1777 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1778 | **/ |
| 1779 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 1780 | { |
| 1781 | struct net_device *netdev = data; |
| 1782 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1783 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1784 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1785 | u32 eicr; |
| 1786 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 1787 | /* |
| 1788 | * Workaround for silicon errata. Mask the interrupts |
| 1789 | * before the read of EICR. |
| 1790 | */ |
| 1791 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 1792 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1793 | /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read |
| 1794 | * therefore no explict interrupt disable is necessary */ |
| 1795 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 1796 | if (!eicr) { |
| 1797 | /* shared interrupt alert! |
| 1798 | * make sure interrupts are enabled because the read will |
| 1799 | * have disabled interrupts due to EIAM */ |
| 1800 | ixgbe_irq_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1801 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 1802 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1803 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1804 | if (eicr & IXGBE_EICR_LSC) |
| 1805 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1806 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1807 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 1808 | ixgbe_check_sfp_event(adapter, eicr); |
| 1809 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1810 | ixgbe_check_fan_failure(adapter, eicr); |
| 1811 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1812 | if (napi_schedule_prep(&(q_vector->napi))) { |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1813 | adapter->tx_ring[0].total_packets = 0; |
| 1814 | adapter->tx_ring[0].total_bytes = 0; |
| 1815 | adapter->rx_ring[0].total_packets = 0; |
| 1816 | adapter->rx_ring[0].total_bytes = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1817 | /* would disable interrupts here but EIAM disabled it */ |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1818 | __napi_schedule(&(q_vector->napi)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1819 | } |
| 1820 | |
| 1821 | return IRQ_HANDLED; |
| 1822 | } |
| 1823 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1824 | static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter) |
| 1825 | { |
| 1826 | int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1827 | |
| 1828 | for (i = 0; i < q_vectors; i++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1829 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1830 | bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES); |
| 1831 | bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES); |
| 1832 | q_vector->rxr_count = 0; |
| 1833 | q_vector->txr_count = 0; |
| 1834 | } |
| 1835 | } |
| 1836 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1837 | /** |
| 1838 | * ixgbe_request_irq - initialize interrupts |
| 1839 | * @adapter: board private structure |
| 1840 | * |
| 1841 | * Attempts to configure interrupts using the best available |
| 1842 | * capabilities of the hardware and kernel. |
| 1843 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1844 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1845 | { |
| 1846 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1847 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1848 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1849 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 1850 | err = ixgbe_request_msix_irqs(adapter); |
| 1851 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1852 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1853 | netdev->name, netdev); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1854 | } else { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1855 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1856 | netdev->name, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1857 | } |
| 1858 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1859 | if (err) |
| 1860 | DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err); |
| 1861 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1862 | return err; |
| 1863 | } |
| 1864 | |
| 1865 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 1866 | { |
| 1867 | struct net_device *netdev = adapter->netdev; |
| 1868 | |
| 1869 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1870 | int i, q_vectors; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1871 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1872 | q_vectors = adapter->num_msix_vectors; |
| 1873 | |
| 1874 | i = q_vectors - 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1875 | free_irq(adapter->msix_entries[i].vector, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1876 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1877 | i--; |
| 1878 | for (; i >= 0; i--) { |
| 1879 | free_irq(adapter->msix_entries[i].vector, |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1880 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1881 | } |
| 1882 | |
| 1883 | ixgbe_reset_q_vectors(adapter); |
| 1884 | } else { |
| 1885 | free_irq(adapter->pdev->irq, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1886 | } |
| 1887 | } |
| 1888 | |
| 1889 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1890 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 1891 | * @adapter: board private structure |
| 1892 | **/ |
| 1893 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 1894 | { |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1895 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1896 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
| 1897 | } else { |
| 1898 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 1899 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1900 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1901 | } |
| 1902 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 1903 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 1904 | int i; |
| 1905 | for (i = 0; i < adapter->num_msix_vectors; i++) |
| 1906 | synchronize_irq(adapter->msix_entries[i].vector); |
| 1907 | } else { |
| 1908 | synchronize_irq(adapter->pdev->irq); |
| 1909 | } |
| 1910 | } |
| 1911 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1912 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1913 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 1914 | * |
| 1915 | **/ |
| 1916 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 1917 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1918 | struct ixgbe_hw *hw = &adapter->hw; |
| 1919 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1920 | IXGBE_WRITE_REG(hw, IXGBE_EITR(0), |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1921 | EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1922 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1923 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 1924 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1925 | |
| 1926 | map_vector_to_rxq(adapter, 0, 0); |
| 1927 | map_vector_to_txq(adapter, 0, 0); |
| 1928 | |
| 1929 | DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1930 | } |
| 1931 | |
| 1932 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1933 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1934 | * @adapter: board private structure |
| 1935 | * |
| 1936 | * Configure the Tx unit of the MAC after a reset. |
| 1937 | **/ |
| 1938 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 1939 | { |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1940 | u64 tdba; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1941 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1942 | u32 i, j, tdlen, txctrl; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1943 | |
| 1944 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 1945 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1946 | struct ixgbe_ring *ring = &adapter->tx_ring[i]; |
| 1947 | j = ring->reg_idx; |
| 1948 | tdba = ring->dma; |
| 1949 | tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1950 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j), |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1951 | (tdba & DMA_BIT_MASK(32))); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1952 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32)); |
| 1953 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen); |
| 1954 | IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0); |
| 1955 | IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0); |
| 1956 | adapter->tx_ring[i].head = IXGBE_TDH(j); |
| 1957 | adapter->tx_ring[i].tail = IXGBE_TDT(j); |
Peter P Waskiewicz Jr | 84f62d4 | 2009-09-30 12:07:16 +0000 | [diff] [blame] | 1958 | /* |
| 1959 | * Disable Tx Head Writeback RO bit, since this hoses |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1960 | * bookkeeping if things aren't delivered in order. |
| 1961 | */ |
Peter P Waskiewicz Jr | 84f62d4 | 2009-09-30 12:07:16 +0000 | [diff] [blame] | 1962 | switch (hw->mac.type) { |
| 1963 | case ixgbe_mac_82598EB: |
| 1964 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j)); |
| 1965 | break; |
| 1966 | case ixgbe_mac_82599EB: |
| 1967 | default: |
| 1968 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(j)); |
| 1969 | break; |
| 1970 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1971 | txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN; |
Peter P Waskiewicz Jr | 84f62d4 | 2009-09-30 12:07:16 +0000 | [diff] [blame] | 1972 | switch (hw->mac.type) { |
| 1973 | case ixgbe_mac_82598EB: |
| 1974 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl); |
| 1975 | break; |
| 1976 | case ixgbe_mac_82599EB: |
| 1977 | default: |
| 1978 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(j), txctrl); |
| 1979 | break; |
| 1980 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1981 | } |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 1982 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1983 | if (hw->mac.type == ixgbe_mac_82599EB) { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 1984 | u32 rttdcs; |
| 1985 | |
| 1986 | /* disable the arbiter while setting MTQC */ |
| 1987 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 1988 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 1989 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 1990 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1991 | /* We enable 8 traffic classes, DCB only */ |
| 1992 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 1993 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA | |
| 1994 | IXGBE_MTQC_8TC_8TQ)); |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 1995 | else |
| 1996 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB); |
| 1997 | |
| 1998 | /* re-eable the arbiter */ |
| 1999 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 2000 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2001 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2002 | } |
| 2003 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2004 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2005 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2006 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
| 2007 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2008 | { |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2009 | u32 srrctl; |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2010 | int index; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2011 | struct ixgbe_ring_feature *feature = adapter->ring_feature; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2012 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2013 | index = rx_ring->reg_idx; |
| 2014 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 2015 | unsigned long mask; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2016 | mask = (unsigned long) feature[RING_F_RSS].mask; |
Alexander Duyck | 3be1adf | 2008-08-30 00:29:10 -0700 | [diff] [blame] | 2017 | index = index & mask; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2018 | } |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2019 | srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index)); |
| 2020 | |
| 2021 | srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2022 | srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK; |
| 2023 | |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2024 | srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) & |
| 2025 | IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2026 | |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 2027 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2028 | #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER |
| 2029 | srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 2030 | #else |
| 2031 | srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 2032 | #endif |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2033 | srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2034 | } else { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2035 | srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >> |
| 2036 | IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2037 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2038 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2039 | |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2040 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl); |
| 2041 | } |
| 2042 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2043 | static u32 ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
| 2044 | { |
| 2045 | u32 mrqc = 0; |
| 2046 | int mask; |
| 2047 | |
| 2048 | if (!(adapter->hw.mac.type == ixgbe_mac_82599EB)) |
| 2049 | return mrqc; |
| 2050 | |
| 2051 | mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED |
| 2052 | #ifdef CONFIG_IXGBE_DCB |
| 2053 | | IXGBE_FLAG_DCB_ENABLED |
| 2054 | #endif |
| 2055 | ); |
| 2056 | |
| 2057 | switch (mask) { |
| 2058 | case (IXGBE_FLAG_RSS_ENABLED): |
| 2059 | mrqc = IXGBE_MRQC_RSSEN; |
| 2060 | break; |
| 2061 | #ifdef CONFIG_IXGBE_DCB |
| 2062 | case (IXGBE_FLAG_DCB_ENABLED): |
| 2063 | mrqc = IXGBE_MRQC_RT8TCEN; |
| 2064 | break; |
| 2065 | #endif /* CONFIG_IXGBE_DCB */ |
| 2066 | default: |
| 2067 | break; |
| 2068 | } |
| 2069 | |
| 2070 | return mrqc; |
| 2071 | } |
| 2072 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2073 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2074 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 2075 | * @adapter: address of board private structure |
| 2076 | * @index: index of ring to set |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2077 | **/ |
Mallikarjuna R Chilakala | edd2ea55 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2078 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, int index) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2079 | { |
| 2080 | struct ixgbe_ring *rx_ring; |
| 2081 | struct ixgbe_hw *hw = &adapter->hw; |
| 2082 | int j; |
| 2083 | u32 rscctrl; |
Mallikarjuna R Chilakala | edd2ea55 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2084 | int rx_buf_len; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2085 | |
| 2086 | rx_ring = &adapter->rx_ring[index]; |
| 2087 | j = rx_ring->reg_idx; |
Mallikarjuna R Chilakala | edd2ea55 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2088 | rx_buf_len = rx_ring->rx_buf_len; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2089 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(j)); |
| 2090 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 2091 | /* |
| 2092 | * we must limit the number of descriptors so that the |
| 2093 | * total size of max desc * buf_len is not greater |
| 2094 | * than 65535 |
| 2095 | */ |
| 2096 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
| 2097 | #if (MAX_SKB_FRAGS > 16) |
| 2098 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2099 | #elif (MAX_SKB_FRAGS > 8) |
| 2100 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
| 2101 | #elif (MAX_SKB_FRAGS > 4) |
| 2102 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
| 2103 | #else |
| 2104 | rscctrl |= IXGBE_RSCCTL_MAXDESC_1; |
| 2105 | #endif |
| 2106 | } else { |
| 2107 | if (rx_buf_len < IXGBE_RXBUFFER_4096) |
| 2108 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2109 | else if (rx_buf_len < IXGBE_RXBUFFER_8192) |
| 2110 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
| 2111 | else |
| 2112 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
| 2113 | } |
| 2114 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(j), rscctrl); |
| 2115 | } |
| 2116 | |
| 2117 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2118 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2119 | * @adapter: board private structure |
| 2120 | * |
| 2121 | * Configure the Rx unit of the MAC after a reset. |
| 2122 | **/ |
| 2123 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 2124 | { |
| 2125 | u64 rdba; |
| 2126 | struct ixgbe_hw *hw = &adapter->hw; |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2127 | struct ixgbe_ring *rx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2128 | struct net_device *netdev = adapter->netdev; |
| 2129 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2130 | int i, j; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2131 | u32 rdlen, rxctrl, rxcsum; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2132 | static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D, |
| 2133 | 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE, |
| 2134 | 0x6A3E67EA, 0x14364D17, 0x3BED200D}; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2135 | u32 fctrl, hlreg0; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2136 | u32 reta = 0, mrqc = 0; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2137 | u32 rdrxctl; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2138 | int rx_buf_len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2139 | |
| 2140 | /* Decide whether to use packet split mode or not */ |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 2141 | adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2142 | |
| 2143 | /* Set the RX buffer length according to the mode */ |
| 2144 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2145 | rx_buf_len = IXGBE_RX_HDR_SIZE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2146 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2147 | /* PSRTYPE must be initialized in 82599 */ |
| 2148 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
| 2149 | IXGBE_PSRTYPE_UDPHDR | |
| 2150 | IXGBE_PSRTYPE_IPV4HDR | |
Yi Zou | dfa12f0 | 2009-05-07 10:39:35 +0000 | [diff] [blame] | 2151 | IXGBE_PSRTYPE_IPV6HDR | |
| 2152 | IXGBE_PSRTYPE_L2HDR; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2153 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype); |
| 2154 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2155 | } else { |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 2156 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) && |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2157 | (netdev->mtu <= ETH_DATA_LEN)) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2158 | rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2159 | else |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2160 | rx_buf_len = ALIGN(max_frame, 1024); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2161 | } |
| 2162 | |
| 2163 | fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL); |
| 2164 | fctrl |= IXGBE_FCTRL_BAM; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2165 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2166 | fctrl |= IXGBE_FCTRL_PMCF; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2167 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl); |
| 2168 | |
| 2169 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
| 2170 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 2171 | hlreg0 &= ~IXGBE_HLREG0_JUMBOEN; |
| 2172 | else |
| 2173 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2174 | #ifdef IXGBE_FCOE |
Yi Zou | f34c5c8 | 2009-08-14 12:42:17 +0000 | [diff] [blame] | 2175 | if (netdev->features & NETIF_F_FCOE_MTU) |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2176 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
| 2177 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2178 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 2179 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2180 | rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc); |
| 2181 | /* disable receives while setting up the descriptors */ |
| 2182 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 2183 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
| 2184 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2185 | /* |
| 2186 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 2187 | * the Base and Length of the Rx Descriptor Ring |
| 2188 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2189 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2190 | rx_ring = &adapter->rx_ring[i]; |
| 2191 | rdba = rx_ring->dma; |
| 2192 | j = rx_ring->reg_idx; |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2193 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_BIT_MASK(32))); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2194 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32)); |
| 2195 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen); |
| 2196 | IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0); |
| 2197 | IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0); |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2198 | rx_ring->head = IXGBE_RDH(j); |
| 2199 | rx_ring->tail = IXGBE_RDT(j); |
| 2200 | rx_ring->rx_buf_len = rx_buf_len; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2201 | |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 2202 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) |
| 2203 | rx_ring->flags |= IXGBE_RING_RX_PS_ENABLED; |
Peter P Waskiewicz Jr | 1b3ff02 | 2009-09-14 07:47:27 +0000 | [diff] [blame] | 2204 | else |
| 2205 | rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2206 | |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2207 | #ifdef IXGBE_FCOE |
Yi Zou | f34c5c8 | 2009-08-14 12:42:17 +0000 | [diff] [blame] | 2208 | if (netdev->features & NETIF_F_FCOE_MTU) { |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2209 | struct ixgbe_ring_feature *f; |
| 2210 | f = &adapter->ring_feature[RING_F_FCOE]; |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 2211 | if ((i >= f->mask) && (i < f->mask + f->indices)) { |
| 2212 | rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED; |
| 2213 | if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE) |
| 2214 | rx_ring->rx_buf_len = |
| 2215 | IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 2216 | } |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2217 | } |
| 2218 | |
| 2219 | #endif /* IXGBE_FCOE */ |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2220 | ixgbe_configure_srrctl(adapter, rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2221 | } |
| 2222 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2223 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 2224 | /* |
| 2225 | * For VMDq support of different descriptor types or |
| 2226 | * buffer sizes through the use of multiple SRRCTL |
| 2227 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 2228 | * |
| 2229 | * also, the manual doesn't mention it clearly but DCA hints |
| 2230 | * will only use queue 0's tags unless this bit is set. Side |
| 2231 | * effects of setting this bit are only that SRRCTL must be |
| 2232 | * fully programmed [0..15] |
| 2233 | */ |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2234 | rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 2235 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 2236 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2237 | } |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2238 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2239 | /* Program MRQC for the distribution of queues */ |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2240 | mrqc = ixgbe_setup_mrqc(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2241 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2242 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2243 | /* Fill out redirection table */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2244 | for (i = 0, j = 0; i < 128; i++, j++) { |
| 2245 | if (j == adapter->ring_feature[RING_F_RSS].indices) |
| 2246 | j = 0; |
| 2247 | /* reta = 4-byte sliding window of |
| 2248 | * 0x00..(indices-1)(indices-1)00..etc. */ |
| 2249 | reta = (reta << 8) | (j * 0x11); |
| 2250 | if ((i & 3) == 3) |
| 2251 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2252 | } |
| 2253 | |
| 2254 | /* Fill out hash function seeds */ |
| 2255 | for (i = 0; i < 10; i++) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2256 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2257 | |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2258 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2259 | mrqc |= IXGBE_MRQC_RSSEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2260 | /* Perform hash on these packet types */ |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2261 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
| 2262 | | IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
| 2263 | | IXGBE_MRQC_RSS_FIELD_IPV4_UDP |
| 2264 | | IXGBE_MRQC_RSS_FIELD_IPV6 |
| 2265 | | IXGBE_MRQC_RSS_FIELD_IPV6_TCP |
| 2266 | | IXGBE_MRQC_RSS_FIELD_IPV6_UDP; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2267 | } |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2268 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2269 | |
| 2270 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 2271 | |
| 2272 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED || |
| 2273 | adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) { |
| 2274 | /* Disable indicating checksum in descriptor, enables |
| 2275 | * RSS hash */ |
| 2276 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 2277 | } |
| 2278 | if (!(rxcsum & IXGBE_RXCSUM_PCSD)) { |
| 2279 | /* Enable IPv4 payload checksum for UDP fragments |
| 2280 | * if PCSD is not set */ |
| 2281 | rxcsum |= IXGBE_RXCSUM_IPPCSE; |
| 2282 | } |
| 2283 | |
| 2284 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2285 | |
| 2286 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2287 | rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 2288 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2289 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2290 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 2291 | } |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2292 | |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 2293 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2294 | /* Enable 82599 HW-RSC */ |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2295 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | edd2ea55 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2296 | ixgbe_configure_rscctl(adapter, i); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2297 | |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2298 | /* Disable RSC for ACK packets */ |
| 2299 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 2300 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 2301 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2302 | } |
| 2303 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2304 | static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 2305 | { |
| 2306 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2307 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2308 | |
| 2309 | /* add VID to filter table */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2310 | hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2311 | } |
| 2312 | |
| 2313 | static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 2314 | { |
| 2315 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2316 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2317 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2318 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2319 | ixgbe_irq_disable(adapter); |
| 2320 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2321 | vlan_group_set_device(adapter->vlgrp, vid, NULL); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2322 | |
| 2323 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2324 | ixgbe_irq_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2325 | |
| 2326 | /* remove VID from filter table */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2327 | hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2328 | } |
| 2329 | |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2330 | static void ixgbe_vlan_rx_register(struct net_device *netdev, |
| 2331 | struct vlan_group *grp) |
| 2332 | { |
| 2333 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2334 | u32 ctrl; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2335 | int i, j; |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2336 | |
| 2337 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2338 | ixgbe_irq_disable(adapter); |
| 2339 | adapter->vlgrp = grp; |
| 2340 | |
| 2341 | /* |
| 2342 | * For a DCB driver, always enable VLAN tag stripping so we can |
| 2343 | * still receive traffic from a DCB-enabled host even if we're |
| 2344 | * not in DCB mode. |
| 2345 | */ |
| 2346 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL); |
Alexander Duyck | dc63d37 | 2009-11-23 06:32:57 +0000 | [diff] [blame] | 2347 | |
| 2348 | /* Disable CFI check */ |
| 2349 | ctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2350 | |
| 2351 | /* enable VLAN tag stripping */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2352 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | dc63d37 | 2009-11-23 06:32:57 +0000 | [diff] [blame] | 2353 | ctrl |= IXGBE_VLNCTRL_VME; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2354 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2355 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | dc63d37 | 2009-11-23 06:32:57 +0000 | [diff] [blame] | 2356 | u32 ctrl; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2357 | j = adapter->rx_ring[i].reg_idx; |
| 2358 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j)); |
| 2359 | ctrl |= IXGBE_RXDCTL_VME; |
| 2360 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl); |
| 2361 | } |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2362 | } |
Alexander Duyck | dc63d37 | 2009-11-23 06:32:57 +0000 | [diff] [blame] | 2363 | |
| 2364 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl); |
| 2365 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2366 | ixgbe_vlan_rx_add_vid(netdev, 0); |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2367 | |
| 2368 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2369 | ixgbe_irq_enable(adapter); |
| 2370 | } |
| 2371 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2372 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 2373 | { |
| 2374 | ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 2375 | |
| 2376 | if (adapter->vlgrp) { |
| 2377 | u16 vid; |
| 2378 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
| 2379 | if (!vlan_group_get_device(adapter->vlgrp, vid)) |
| 2380 | continue; |
| 2381 | ixgbe_vlan_rx_add_vid(adapter->netdev, vid); |
| 2382 | } |
| 2383 | } |
| 2384 | } |
| 2385 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2386 | static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq) |
| 2387 | { |
| 2388 | struct dev_mc_list *mc_ptr; |
| 2389 | u8 *addr = *mc_addr_ptr; |
| 2390 | *vmdq = 0; |
| 2391 | |
| 2392 | mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]); |
| 2393 | if (mc_ptr->next) |
| 2394 | *mc_addr_ptr = mc_ptr->next->dmi_addr; |
| 2395 | else |
| 2396 | *mc_addr_ptr = NULL; |
| 2397 | |
| 2398 | return addr; |
| 2399 | } |
| 2400 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2401 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2402 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2403 | * @netdev: network interface device structure |
| 2404 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2405 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 2406 | * address list or the network interface flags are updated. This routine is |
| 2407 | * responsible for configuring the hardware for proper unicast, multicast and |
| 2408 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2409 | **/ |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2410 | static void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2411 | { |
| 2412 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2413 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2414 | u32 fctrl, vlnctrl; |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2415 | u8 *addr_list = NULL; |
| 2416 | int addr_count = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2417 | |
| 2418 | /* Check for Promiscuous and All Multicast modes */ |
| 2419 | |
| 2420 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2421 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2422 | |
| 2423 | if (netdev->flags & IFF_PROMISC) { |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2424 | hw->addr_ctrl.user_set_promisc = 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2425 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2426 | vlnctrl &= ~IXGBE_VLNCTRL_VFE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2427 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2428 | if (netdev->flags & IFF_ALLMULTI) { |
| 2429 | fctrl |= IXGBE_FCTRL_MPE; |
| 2430 | fctrl &= ~IXGBE_FCTRL_UPE; |
| 2431 | } else { |
| 2432 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
| 2433 | } |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2434 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2435 | hw->addr_ctrl.user_set_promisc = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2436 | } |
| 2437 | |
| 2438 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2439 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2440 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2441 | /* reprogram secondary unicast list */ |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 2442 | hw->mac.ops.update_uc_addr_list(hw, &netdev->uc.list); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2443 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2444 | /* reprogram multicast list */ |
| 2445 | addr_count = netdev->mc_count; |
| 2446 | if (addr_count) |
| 2447 | addr_list = netdev->mc_list->dmi_addr; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2448 | hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count, |
| 2449 | ixgbe_addr_list_itr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2450 | } |
| 2451 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2452 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 2453 | { |
| 2454 | int q_idx; |
| 2455 | struct ixgbe_q_vector *q_vector; |
| 2456 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2457 | |
| 2458 | /* legacy and MSI only use one vector */ |
| 2459 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 2460 | q_vectors = 1; |
| 2461 | |
| 2462 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2463 | struct napi_struct *napi; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2464 | q_vector = adapter->q_vector[q_idx]; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2465 | napi = &q_vector->napi; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2466 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2467 | if (!q_vector->rxr_count || !q_vector->txr_count) { |
| 2468 | if (q_vector->txr_count == 1) |
| 2469 | napi->poll = &ixgbe_clean_txonly; |
| 2470 | else if (q_vector->rxr_count == 1) |
| 2471 | napi->poll = &ixgbe_clean_rxonly; |
| 2472 | } |
| 2473 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2474 | |
| 2475 | napi_enable(napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2476 | } |
| 2477 | } |
| 2478 | |
| 2479 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 2480 | { |
| 2481 | int q_idx; |
| 2482 | struct ixgbe_q_vector *q_vector; |
| 2483 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2484 | |
| 2485 | /* legacy and MSI only use one vector */ |
| 2486 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 2487 | q_vectors = 1; |
| 2488 | |
| 2489 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2490 | q_vector = adapter->q_vector[q_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2491 | napi_disable(&q_vector->napi); |
| 2492 | } |
| 2493 | } |
| 2494 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 2495 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2496 | /* |
| 2497 | * ixgbe_configure_dcb - Configure DCB hardware |
| 2498 | * @adapter: ixgbe adapter struct |
| 2499 | * |
| 2500 | * This is called by the driver on open to configure the DCB hardware. |
| 2501 | * This is also called by the gennetlink interface when reconfiguring |
| 2502 | * the DCB state. |
| 2503 | */ |
| 2504 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 2505 | { |
| 2506 | struct ixgbe_hw *hw = &adapter->hw; |
| 2507 | u32 txdctl, vlnctrl; |
| 2508 | int i, j; |
| 2509 | |
| 2510 | ixgbe_dcb_check_config(&adapter->dcb_cfg); |
| 2511 | ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG); |
| 2512 | ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG); |
| 2513 | |
| 2514 | /* reconfigure the hardware */ |
| 2515 | ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg); |
| 2516 | |
| 2517 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2518 | j = adapter->tx_ring[i].reg_idx; |
| 2519 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
| 2520 | /* PThresh workaround for Tx hang with DFP enabled. */ |
| 2521 | txdctl |= 32; |
| 2522 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
| 2523 | } |
| 2524 | /* Enable VLAN tag insert/strip */ |
| 2525 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2526 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 2527 | vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE; |
| 2528 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2529 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 2530 | } else if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2531 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 2532 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2533 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 2534 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 2535 | j = adapter->rx_ring[i].reg_idx; |
| 2536 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 2537 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 2538 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 2539 | } |
| 2540 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2541 | hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true); |
| 2542 | } |
| 2543 | |
| 2544 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2545 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 2546 | { |
| 2547 | struct net_device *netdev = adapter->netdev; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2548 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2549 | int i; |
| 2550 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2551 | ixgbe_set_rx_mode(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2552 | |
| 2553 | ixgbe_restore_vlan(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 2554 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2555 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Yi Zou | b352e40 | 2009-11-06 12:55:38 +0000 | [diff] [blame] | 2556 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2557 | netif_set_gso_max_size(netdev, 32768); |
| 2558 | else |
| 2559 | netif_set_gso_max_size(netdev, 65536); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2560 | ixgbe_configure_dcb(adapter); |
| 2561 | } else { |
| 2562 | netif_set_gso_max_size(netdev, 65536); |
| 2563 | } |
| 2564 | #else |
| 2565 | netif_set_gso_max_size(netdev, 65536); |
| 2566 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2567 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 2568 | #ifdef IXGBE_FCOE |
| 2569 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 2570 | ixgbe_configure_fcoe(adapter); |
| 2571 | |
| 2572 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2573 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 2574 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2575 | adapter->tx_ring[i].atr_sample_rate = |
| 2576 | adapter->atr_sample_rate; |
| 2577 | ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc); |
| 2578 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 2579 | ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc); |
| 2580 | } |
| 2581 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2582 | ixgbe_configure_tx(adapter); |
| 2583 | ixgbe_configure_rx(adapter); |
| 2584 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 2585 | ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i], |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2586 | (adapter->rx_ring[i].count - 1)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2587 | } |
| 2588 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2589 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 2590 | { |
| 2591 | switch (hw->phy.type) { |
| 2592 | case ixgbe_phy_sfp_avago: |
| 2593 | case ixgbe_phy_sfp_ftl: |
| 2594 | case ixgbe_phy_sfp_intel: |
| 2595 | case ixgbe_phy_sfp_unknown: |
| 2596 | case ixgbe_phy_tw_tyco: |
| 2597 | case ixgbe_phy_tw_unknown: |
| 2598 | return true; |
| 2599 | default: |
| 2600 | return false; |
| 2601 | } |
| 2602 | } |
| 2603 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2604 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2605 | * ixgbe_sfp_link_config - set up SFP+ link |
| 2606 | * @adapter: pointer to private adapter struct |
| 2607 | **/ |
| 2608 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 2609 | { |
| 2610 | struct ixgbe_hw *hw = &adapter->hw; |
| 2611 | |
| 2612 | if (hw->phy.multispeed_fiber) { |
| 2613 | /* |
| 2614 | * In multispeed fiber setups, the device may not have |
| 2615 | * had a physical connection when the driver loaded. |
| 2616 | * If that's the case, the initial link configuration |
| 2617 | * couldn't get the MAC into 10G or 1G mode, so we'll |
| 2618 | * never have a link status change interrupt fire. |
| 2619 | * We need to try and force an autonegotiation |
| 2620 | * session, then bring up link. |
| 2621 | */ |
| 2622 | hw->mac.ops.setup_sfp(hw); |
| 2623 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK)) |
| 2624 | schedule_work(&adapter->multispeed_fiber_task); |
| 2625 | } else { |
| 2626 | /* |
| 2627 | * Direct Attach Cu and non-multispeed fiber modules |
| 2628 | * still need to be configured properly prior to |
| 2629 | * attempting link. |
| 2630 | */ |
| 2631 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK)) |
| 2632 | schedule_work(&adapter->sfp_config_module_task); |
| 2633 | } |
| 2634 | } |
| 2635 | |
| 2636 | /** |
| 2637 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2638 | * @hw: pointer to private hardware struct |
| 2639 | * |
| 2640 | * Returns 0 on success, negative on failure |
| 2641 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2642 | 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] | 2643 | { |
| 2644 | u32 autoneg; |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 2645 | bool negotiation, link_up = false; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2646 | u32 ret = IXGBE_ERR_LINK_SETUP; |
| 2647 | |
| 2648 | if (hw->mac.ops.check_link) |
| 2649 | ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 2650 | |
| 2651 | if (ret) |
| 2652 | goto link_cfg_out; |
| 2653 | |
| 2654 | if (hw->mac.ops.get_link_capabilities) |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 2655 | ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2656 | if (ret) |
| 2657 | goto link_cfg_out; |
| 2658 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 2659 | if (hw->mac.ops.setup_link) |
| 2660 | 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] | 2661 | link_cfg_out: |
| 2662 | return ret; |
| 2663 | } |
| 2664 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2665 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 2666 | static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 2667 | int rxr) |
| 2668 | { |
| 2669 | int j = adapter->rx_ring[rxr].reg_idx; |
| 2670 | int k; |
| 2671 | |
| 2672 | for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) { |
| 2673 | if (IXGBE_READ_REG(&adapter->hw, |
| 2674 | IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE) |
| 2675 | break; |
| 2676 | else |
| 2677 | msleep(1); |
| 2678 | } |
| 2679 | if (k >= IXGBE_MAX_RX_DESC_POLL) { |
| 2680 | DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d " |
| 2681 | "not set within the polling period\n", rxr); |
| 2682 | } |
| 2683 | ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr], |
| 2684 | (adapter->rx_ring[rxr].count - 1)); |
| 2685 | } |
| 2686 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2687 | static int ixgbe_up_complete(struct ixgbe_adapter *adapter) |
| 2688 | { |
| 2689 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2690 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2691 | int i, j = 0; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2692 | int num_rx_rings = adapter->num_rx_queues; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2693 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2694 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2695 | u32 txdctl, rxdctl, mhadd; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2696 | u32 dmatxctl; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2697 | u32 gpie; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2698 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 2699 | ixgbe_get_hw_control(adapter); |
| 2700 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2701 | if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) || |
| 2702 | (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2703 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2704 | gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2705 | IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2706 | } else { |
| 2707 | /* MSI only */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2708 | gpie = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2709 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2710 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 2711 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 2712 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2713 | } |
| 2714 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 2715 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2716 | /* |
| 2717 | * use EIAM to auto-mask when MSI-X interrupt is asserted |
| 2718 | * this saves a register write for every interrupt |
| 2719 | */ |
| 2720 | switch (hw->mac.type) { |
| 2721 | case ixgbe_mac_82598EB: |
| 2722 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
| 2723 | break; |
| 2724 | default: |
| 2725 | case ixgbe_mac_82599EB: |
| 2726 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); |
| 2727 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); |
| 2728 | break; |
| 2729 | } |
| 2730 | } else { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2731 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 2732 | * specifically only auto mask tx and rx interrupts */ |
| 2733 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2734 | } |
| 2735 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2736 | /* Enable fan failure interrupt if media type is copper */ |
| 2737 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 2738 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 2739 | gpie |= IXGBE_SDP1_GPIEN; |
| 2740 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2741 | } |
| 2742 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2743 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2744 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 2745 | gpie |= IXGBE_SDP1_GPIEN; |
| 2746 | gpie |= IXGBE_SDP2_GPIEN; |
| 2747 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2748 | } |
| 2749 | |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2750 | #ifdef IXGBE_FCOE |
| 2751 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
Yi Zou | f34c5c8 | 2009-08-14 12:42:17 +0000 | [diff] [blame] | 2752 | if ((netdev->features & NETIF_F_FCOE_MTU) && |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2753 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 2754 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 2755 | |
| 2756 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2757 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2758 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 2759 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 2760 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 2761 | |
| 2762 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
| 2763 | } |
| 2764 | |
| 2765 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2766 | j = adapter->tx_ring[i].reg_idx; |
| 2767 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 2768 | /* enable WTHRESH=8 descriptors, to encourage burst writeback */ |
| 2769 | txdctl |= (8 << 16); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2770 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
| 2771 | } |
| 2772 | |
| 2773 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2774 | /* DMATXCTL.EN must be set after all Tx queue config is done */ |
| 2775 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 2776 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 2777 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 2778 | } |
| 2779 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2780 | j = adapter->tx_ring[i].reg_idx; |
| 2781 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2782 | txdctl |= IXGBE_TXDCTL_ENABLE; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2783 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2784 | } |
| 2785 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2786 | for (i = 0; i < num_rx_rings; i++) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2787 | j = adapter->rx_ring[i].reg_idx; |
| 2788 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 2789 | /* enable PTHRESH=32 descriptors (half the internal cache) |
| 2790 | * and HTHRESH=0 descriptors (to minimize latency on fetch), |
| 2791 | * this also removes a pesky rx_no_buffer_count increment */ |
| 2792 | rxdctl |= 0x0020; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2793 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2794 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2795 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 2796 | ixgbe_rx_desc_queue_enable(adapter, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2797 | } |
| 2798 | /* enable all receives */ |
| 2799 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2800 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2801 | rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN); |
| 2802 | else |
| 2803 | rxdctl |= IXGBE_RXCTRL_RXEN; |
| 2804 | hw->mac.ops.enable_rx_dma(hw, rxdctl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2805 | |
| 2806 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 2807 | ixgbe_configure_msix(adapter); |
| 2808 | else |
| 2809 | ixgbe_configure_msi_and_legacy(adapter); |
| 2810 | |
| 2811 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2812 | ixgbe_napi_enable_all(adapter); |
| 2813 | |
| 2814 | /* clear any pending interrupts, may auto mask */ |
| 2815 | IXGBE_READ_REG(hw, IXGBE_EICR); |
| 2816 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2817 | ixgbe_irq_enable(adapter); |
| 2818 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2819 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 2820 | * If this adapter has a fan, check to see if we had a failure |
| 2821 | * before we enabled the interrupt. |
| 2822 | */ |
| 2823 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 2824 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 2825 | if (esdp & IXGBE_ESDP_SDP1) |
| 2826 | DPRINTK(DRV, CRIT, |
| 2827 | "Fan has stopped, replace the adapter\n"); |
| 2828 | } |
| 2829 | |
| 2830 | /* |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2831 | * For hot-pluggable SFP+ devices, a new SFP+ module may have |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2832 | * arrived before interrupts were enabled but after probe. Such |
| 2833 | * devices wouldn't have their type identified yet. We need to |
| 2834 | * 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] | 2835 | * If we're not hot-pluggable SFP+, we just need to configure link |
| 2836 | * and bring it up. |
| 2837 | */ |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2838 | if (hw->phy.type == ixgbe_phy_unknown) { |
| 2839 | err = hw->phy.ops.identify(hw); |
| 2840 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 5da43c1 | 2009-07-02 12:50:52 +0000 | [diff] [blame] | 2841 | /* |
| 2842 | * Take the device down and schedule the sfp tasklet |
| 2843 | * which will unregister_netdev and log it. |
| 2844 | */ |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2845 | ixgbe_down(adapter); |
Don Skidmore | 5da43c1 | 2009-07-02 12:50:52 +0000 | [diff] [blame] | 2846 | schedule_work(&adapter->sfp_config_module_task); |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2847 | return err; |
| 2848 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2849 | } |
| 2850 | |
| 2851 | if (ixgbe_is_sfp(hw)) { |
| 2852 | ixgbe_sfp_link_config(adapter); |
| 2853 | } else { |
| 2854 | err = ixgbe_non_sfp_link_config(hw); |
| 2855 | if (err) |
| 2856 | DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err); |
| 2857 | } |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2858 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2859 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2860 | set_bit(__IXGBE_FDIR_INIT_DONE, |
| 2861 | &(adapter->tx_ring[i].reinit_state)); |
| 2862 | |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 2863 | /* enable transmits */ |
| 2864 | netif_tx_start_all_queues(netdev); |
| 2865 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2866 | /* bring the link up in the watchdog, this could race with our first |
| 2867 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2868 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2869 | adapter->link_check_timeout = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2870 | mod_timer(&adapter->watchdog_timer, jiffies); |
| 2871 | return 0; |
| 2872 | } |
| 2873 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2874 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 2875 | { |
| 2876 | WARN_ON(in_interrupt()); |
| 2877 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
| 2878 | msleep(1); |
| 2879 | ixgbe_down(adapter); |
| 2880 | ixgbe_up(adapter); |
| 2881 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 2882 | } |
| 2883 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2884 | int ixgbe_up(struct ixgbe_adapter *adapter) |
| 2885 | { |
| 2886 | /* hardware has been reset, we need to reload some things */ |
| 2887 | ixgbe_configure(adapter); |
| 2888 | |
| 2889 | return ixgbe_up_complete(adapter); |
| 2890 | } |
| 2891 | |
| 2892 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 2893 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2894 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 2895 | int err; |
| 2896 | |
| 2897 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2898 | switch (err) { |
| 2899 | case 0: |
| 2900 | case IXGBE_ERR_SFP_NOT_PRESENT: |
| 2901 | break; |
| 2902 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
| 2903 | dev_err(&adapter->pdev->dev, "master disable timed out\n"); |
| 2904 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 2905 | case IXGBE_ERR_EEPROM_VERSION: |
| 2906 | /* We are running on a pre-production device, log a warning */ |
| 2907 | dev_warn(&adapter->pdev->dev, "This device is a pre-production " |
| 2908 | "adapter/LOM. Please be aware there may be issues " |
| 2909 | "associated with your hardware. If you are " |
| 2910 | "experiencing problems please contact your Intel or " |
| 2911 | "hardware representative who provided you with this " |
| 2912 | "hardware.\n"); |
| 2913 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2914 | default: |
| 2915 | dev_err(&adapter->pdev->dev, "Hardware Error: %d\n", err); |
| 2916 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2917 | |
| 2918 | /* reprogram the RAR[0] in case user changed it. */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2919 | 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] | 2920 | } |
| 2921 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2922 | /** |
| 2923 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
| 2924 | * @adapter: board private structure |
| 2925 | * @rx_ring: ring to free buffers from |
| 2926 | **/ |
| 2927 | static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2928 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2929 | { |
| 2930 | struct pci_dev *pdev = adapter->pdev; |
| 2931 | unsigned long size; |
| 2932 | unsigned int i; |
| 2933 | |
| 2934 | /* Free all the Rx ring sk_buffs */ |
| 2935 | |
| 2936 | for (i = 0; i < rx_ring->count; i++) { |
| 2937 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 2938 | |
| 2939 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
| 2940 | if (rx_buffer_info->dma) { |
| 2941 | pci_unmap_single(pdev, rx_buffer_info->dma, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2942 | rx_ring->rx_buf_len, |
| 2943 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2944 | rx_buffer_info->dma = 0; |
| 2945 | } |
| 2946 | if (rx_buffer_info->skb) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2947 | struct sk_buff *skb = rx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2948 | rx_buffer_info->skb = NULL; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2949 | do { |
| 2950 | struct sk_buff *this = skb; |
| 2951 | skb = skb->prev; |
| 2952 | dev_kfree_skb(this); |
| 2953 | } while (skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2954 | } |
| 2955 | if (!rx_buffer_info->page) |
| 2956 | continue; |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 2957 | if (rx_buffer_info->page_dma) { |
| 2958 | pci_unmap_page(pdev, rx_buffer_info->page_dma, |
| 2959 | PAGE_SIZE / 2, PCI_DMA_FROMDEVICE); |
| 2960 | rx_buffer_info->page_dma = 0; |
| 2961 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2962 | put_page(rx_buffer_info->page); |
| 2963 | rx_buffer_info->page = NULL; |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 2964 | rx_buffer_info->page_offset = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2965 | } |
| 2966 | |
| 2967 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 2968 | memset(rx_ring->rx_buffer_info, 0, size); |
| 2969 | |
| 2970 | /* Zero out the descriptor ring */ |
| 2971 | memset(rx_ring->desc, 0, rx_ring->size); |
| 2972 | |
| 2973 | rx_ring->next_to_clean = 0; |
| 2974 | rx_ring->next_to_use = 0; |
| 2975 | |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 2976 | if (rx_ring->head) |
| 2977 | writel(0, adapter->hw.hw_addr + rx_ring->head); |
| 2978 | if (rx_ring->tail) |
| 2979 | writel(0, adapter->hw.hw_addr + rx_ring->tail); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2980 | } |
| 2981 | |
| 2982 | /** |
| 2983 | * ixgbe_clean_tx_ring - Free Tx Buffers |
| 2984 | * @adapter: board private structure |
| 2985 | * @tx_ring: ring to be cleaned |
| 2986 | **/ |
| 2987 | static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2988 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2989 | { |
| 2990 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 2991 | unsigned long size; |
| 2992 | unsigned int i; |
| 2993 | |
| 2994 | /* Free all the Tx ring sk_buffs */ |
| 2995 | |
| 2996 | for (i = 0; i < tx_ring->count; i++) { |
| 2997 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 2998 | ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info); |
| 2999 | } |
| 3000 | |
| 3001 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 3002 | memset(tx_ring->tx_buffer_info, 0, size); |
| 3003 | |
| 3004 | /* Zero out the descriptor ring */ |
| 3005 | memset(tx_ring->desc, 0, tx_ring->size); |
| 3006 | |
| 3007 | tx_ring->next_to_use = 0; |
| 3008 | tx_ring->next_to_clean = 0; |
| 3009 | |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 3010 | if (tx_ring->head) |
| 3011 | writel(0, adapter->hw.hw_addr + tx_ring->head); |
| 3012 | if (tx_ring->tail) |
| 3013 | writel(0, adapter->hw.hw_addr + tx_ring->tail); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3014 | } |
| 3015 | |
| 3016 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3017 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 3018 | * @adapter: board private structure |
| 3019 | **/ |
| 3020 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 3021 | { |
| 3022 | int i; |
| 3023 | |
| 3024 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3025 | ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]); |
| 3026 | } |
| 3027 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3028 | /** |
| 3029 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 3030 | * @adapter: board private structure |
| 3031 | **/ |
| 3032 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 3033 | { |
| 3034 | int i; |
| 3035 | |
| 3036 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3037 | ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]); |
| 3038 | } |
| 3039 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3040 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 3041 | { |
| 3042 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3043 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3044 | u32 rxctrl; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3045 | u32 txdctl; |
| 3046 | int i, j; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3047 | |
| 3048 | /* signal that we are down to the interrupt handler */ |
| 3049 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 3050 | |
| 3051 | /* disable receives */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3052 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 3053 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3054 | |
| 3055 | netif_tx_disable(netdev); |
| 3056 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3057 | IXGBE_WRITE_FLUSH(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3058 | msleep(10); |
| 3059 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3060 | netif_tx_stop_all_queues(netdev); |
| 3061 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3062 | ixgbe_irq_disable(adapter); |
| 3063 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3064 | ixgbe_napi_disable_all(adapter); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3065 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 3066 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 3067 | del_timer_sync(&adapter->sfp_timer); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3068 | del_timer_sync(&adapter->watchdog_timer); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3069 | cancel_work_sync(&adapter->watchdog_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3070 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3071 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 3072 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 3073 | cancel_work_sync(&adapter->fdir_reinit_task); |
| 3074 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3075 | /* disable transmits in the hardware now that interrupts are off */ |
| 3076 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 3077 | j = adapter->tx_ring[i].reg_idx; |
| 3078 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
| 3079 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), |
| 3080 | (txdctl & ~IXGBE_TXDCTL_ENABLE)); |
| 3081 | } |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 3082 | /* Disable the Tx DMA engine on 82599 */ |
| 3083 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 3084 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
| 3085 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 3086 | ~IXGBE_DMATXCTL_TE)); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3087 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3088 | netif_carrier_off(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3089 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 3090 | if (!pci_channel_offline(adapter->pdev)) |
| 3091 | ixgbe_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3092 | ixgbe_clean_all_tx_rings(adapter); |
| 3093 | ixgbe_clean_all_rx_rings(adapter); |
| 3094 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 3095 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 3096 | /* since we reset the hardware DCA settings were cleared */ |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 3097 | ixgbe_setup_dca(adapter); |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 3098 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3099 | } |
| 3100 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3101 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3102 | * ixgbe_poll - NAPI Rx polling callback |
| 3103 | * @napi: structure for representing this polling device |
| 3104 | * @budget: how many packets driver is allowed to clean |
| 3105 | * |
| 3106 | * This function is used for legacy and MSI, NAPI mode |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3107 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3108 | static int ixgbe_poll(struct napi_struct *napi, int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3109 | { |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 3110 | struct ixgbe_q_vector *q_vector = |
| 3111 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3112 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 3113 | int tx_clean_complete, work_done = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3114 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 3115 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 3116 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 3117 | ixgbe_update_tx_dca(adapter, adapter->tx_ring); |
| 3118 | ixgbe_update_rx_dca(adapter, adapter->rx_ring); |
| 3119 | } |
| 3120 | #endif |
| 3121 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 3122 | tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring); |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 3123 | ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3124 | |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 3125 | if (!tx_clean_complete) |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 3126 | work_done = budget; |
| 3127 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 3128 | /* If budget not fully consumed, exit the polling mode */ |
| 3129 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3130 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 3131 | if (adapter->rx_itr_setting & 1) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 3132 | ixgbe_set_itr(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3133 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 3134 | ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3135 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3136 | return work_done; |
| 3137 | } |
| 3138 | |
| 3139 | /** |
| 3140 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 3141 | * @netdev: network interface device structure |
| 3142 | **/ |
| 3143 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 3144 | { |
| 3145 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3146 | |
| 3147 | /* Do the reset outside of interrupt context */ |
| 3148 | schedule_work(&adapter->reset_task); |
| 3149 | } |
| 3150 | |
| 3151 | static void ixgbe_reset_task(struct work_struct *work) |
| 3152 | { |
| 3153 | struct ixgbe_adapter *adapter; |
| 3154 | adapter = container_of(work, struct ixgbe_adapter, reset_task); |
| 3155 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3156 | /* If we're already down or resetting, just bail */ |
| 3157 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 3158 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 3159 | return; |
| 3160 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3161 | adapter->tx_timeout_count++; |
| 3162 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3163 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3164 | } |
| 3165 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3166 | #ifdef CONFIG_IXGBE_DCB |
| 3167 | static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter) |
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 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3170 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB]; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3171 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3172 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) |
| 3173 | return ret; |
| 3174 | |
| 3175 | f->mask = 0x7 << 3; |
| 3176 | adapter->num_rx_queues = f->indices; |
| 3177 | adapter->num_tx_queues = f->indices; |
| 3178 | ret = true; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3179 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3180 | return ret; |
| 3181 | } |
| 3182 | #endif |
| 3183 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3184 | /** |
| 3185 | * ixgbe_set_rss_queues: Allocate queues for RSS |
| 3186 | * @adapter: board private structure to initialize |
| 3187 | * |
| 3188 | * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try |
| 3189 | * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU. |
| 3190 | * |
| 3191 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3192 | static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter) |
| 3193 | { |
| 3194 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3195 | 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] | 3196 | |
| 3197 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3198 | f->mask = 0xF; |
| 3199 | adapter->num_rx_queues = f->indices; |
| 3200 | adapter->num_tx_queues = f->indices; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3201 | ret = true; |
| 3202 | } else { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3203 | ret = false; |
| 3204 | } |
| 3205 | |
| 3206 | return ret; |
| 3207 | } |
| 3208 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3209 | /** |
| 3210 | * ixgbe_set_fdir_queues: Allocate queues for Flow Director |
| 3211 | * @adapter: board private structure to initialize |
| 3212 | * |
| 3213 | * Flow Director is an advanced Rx filter, attempting to get Rx flows back |
| 3214 | * to the original CPU that initiated the Tx session. This runs in addition |
| 3215 | * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the |
| 3216 | * Rx load across CPUs using RSS. |
| 3217 | * |
| 3218 | **/ |
| 3219 | static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter) |
| 3220 | { |
| 3221 | bool ret = false; |
| 3222 | struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR]; |
| 3223 | |
| 3224 | f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices); |
| 3225 | f_fdir->mask = 0; |
| 3226 | |
| 3227 | /* Flow Director must have RSS enabled */ |
| 3228 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED && |
| 3229 | ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 3230 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) { |
| 3231 | adapter->num_tx_queues = f_fdir->indices; |
| 3232 | adapter->num_rx_queues = f_fdir->indices; |
| 3233 | ret = true; |
| 3234 | } else { |
| 3235 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3236 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 3237 | } |
| 3238 | return ret; |
| 3239 | } |
| 3240 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3241 | #ifdef IXGBE_FCOE |
| 3242 | /** |
| 3243 | * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE) |
| 3244 | * @adapter: board private structure to initialize |
| 3245 | * |
| 3246 | * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges. |
| 3247 | * The ring feature mask is not used as a mask for FCoE, as it can take any 8 |
| 3248 | * rx queues out of the max number of rx queues, instead, it is used as the |
| 3249 | * index of the first rx queue used by FCoE. |
| 3250 | * |
| 3251 | **/ |
| 3252 | static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter) |
| 3253 | { |
| 3254 | bool ret = false; |
| 3255 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 3256 | |
| 3257 | f->indices = min((int)num_online_cpus(), f->indices); |
| 3258 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3259 | adapter->num_rx_queues = 1; |
| 3260 | adapter->num_tx_queues = 1; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3261 | #ifdef CONFIG_IXGBE_DCB |
| 3262 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3263 | DPRINTK(PROBE, INFO, "FCoE enabled with DCB \n"); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3264 | ixgbe_set_dcb_queues(adapter); |
| 3265 | } |
| 3266 | #endif |
| 3267 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3268 | DPRINTK(PROBE, INFO, "FCoE enabled with RSS \n"); |
Yi Zou | 8faa2a7 | 2009-07-09 02:29:50 +0000 | [diff] [blame] | 3269 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 3270 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 3271 | ixgbe_set_fdir_queues(adapter); |
| 3272 | else |
| 3273 | ixgbe_set_rss_queues(adapter); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3274 | } |
| 3275 | /* adding FCoE rx rings to the end */ |
| 3276 | f->mask = adapter->num_rx_queues; |
| 3277 | adapter->num_rx_queues += f->indices; |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3278 | adapter->num_tx_queues += f->indices; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3279 | |
| 3280 | ret = true; |
| 3281 | } |
| 3282 | |
| 3283 | return ret; |
| 3284 | } |
| 3285 | |
| 3286 | #endif /* IXGBE_FCOE */ |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3287 | /* |
| 3288 | * ixgbe_set_num_queues: Allocate queues for device, feature dependant |
| 3289 | * @adapter: board private structure to initialize |
| 3290 | * |
| 3291 | * This is the top level queue allocation routine. The order here is very |
| 3292 | * important, starting with the "most" number of features turned on at once, |
| 3293 | * and ending with the smallest set of features. This way large combinations |
| 3294 | * can be allocated if they're turned on, and smaller combinations are the |
| 3295 | * fallthrough conditions. |
| 3296 | * |
| 3297 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3298 | static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter) |
| 3299 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3300 | #ifdef IXGBE_FCOE |
| 3301 | if (ixgbe_set_fcoe_queues(adapter)) |
| 3302 | goto done; |
| 3303 | |
| 3304 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3305 | #ifdef CONFIG_IXGBE_DCB |
| 3306 | if (ixgbe_set_dcb_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 3307 | goto done; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3308 | |
| 3309 | #endif |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3310 | if (ixgbe_set_fdir_queues(adapter)) |
| 3311 | goto done; |
| 3312 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3313 | if (ixgbe_set_rss_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 3314 | goto done; |
| 3315 | |
| 3316 | /* fallback to base case */ |
| 3317 | adapter->num_rx_queues = 1; |
| 3318 | adapter->num_tx_queues = 1; |
| 3319 | |
| 3320 | done: |
| 3321 | /* Notify the stack of the (possibly) reduced Tx Queue count. */ |
| 3322 | adapter->netdev->real_num_tx_queues = adapter->num_tx_queues; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3323 | } |
| 3324 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3325 | static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3326 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3327 | { |
| 3328 | int err, vector_threshold; |
| 3329 | |
| 3330 | /* We'll want at least 3 (vector_threshold): |
| 3331 | * 1) TxQ[0] Cleanup |
| 3332 | * 2) RxQ[0] Cleanup |
| 3333 | * 3) Other (Link Status Change, etc.) |
| 3334 | * 4) TCP Timer (optional) |
| 3335 | */ |
| 3336 | vector_threshold = MIN_MSIX_COUNT; |
| 3337 | |
| 3338 | /* The more we get, the more we will assign to Tx/Rx Cleanup |
| 3339 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 3340 | * Right now, we simply care about how many we'll get; we'll |
| 3341 | * set them up later while requesting irq's. |
| 3342 | */ |
| 3343 | while (vectors >= vector_threshold) { |
| 3344 | err = pci_enable_msix(adapter->pdev, adapter->msix_entries, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3345 | vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3346 | if (!err) /* Success in acquiring all requested vectors. */ |
| 3347 | break; |
| 3348 | else if (err < 0) |
| 3349 | vectors = 0; /* Nasty failure, quit now */ |
| 3350 | else /* err == number of vectors we should try again with */ |
| 3351 | vectors = err; |
| 3352 | } |
| 3353 | |
| 3354 | if (vectors < vector_threshold) { |
| 3355 | /* Can't allocate enough MSI-X interrupts? Oh well. |
| 3356 | * This just means we'll go with either a single MSI |
| 3357 | * vector or fall back to legacy interrupts. |
| 3358 | */ |
| 3359 | DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n"); |
| 3360 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 3361 | kfree(adapter->msix_entries); |
| 3362 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3363 | } else { |
| 3364 | adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */ |
Peter P Waskiewicz Jr | eb7f139 | 2009-02-01 01:18:58 -0800 | [diff] [blame] | 3365 | /* |
| 3366 | * Adjust for only the vectors we'll use, which is minimum |
| 3367 | * of max_msix_q_vectors + NON_Q_VECTORS, or the number of |
| 3368 | * vectors we were allocated. |
| 3369 | */ |
| 3370 | adapter->num_msix_vectors = min(vectors, |
| 3371 | adapter->max_msix_q_vectors + NON_Q_VECTORS); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3372 | } |
| 3373 | } |
| 3374 | |
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 | * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3377 | * @adapter: board private structure to initialize |
| 3378 | * |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3379 | * Cache the descriptor ring offsets for RSS to the assigned rings. |
| 3380 | * |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3381 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3382 | static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3383 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3384 | int i; |
| 3385 | bool ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3386 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3387 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 3388 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3389 | adapter->rx_ring[i].reg_idx = i; |
| 3390 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3391 | adapter->tx_ring[i].reg_idx = i; |
| 3392 | ret = true; |
| 3393 | } else { |
| 3394 | ret = false; |
| 3395 | } |
| 3396 | |
| 3397 | return ret; |
| 3398 | } |
| 3399 | |
| 3400 | #ifdef CONFIG_IXGBE_DCB |
| 3401 | /** |
| 3402 | * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB |
| 3403 | * @adapter: board private structure to initialize |
| 3404 | * |
| 3405 | * Cache the descriptor ring offsets for DCB to the assigned rings. |
| 3406 | * |
| 3407 | **/ |
| 3408 | static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter) |
| 3409 | { |
| 3410 | int i; |
| 3411 | bool ret = false; |
| 3412 | int dcb_i = adapter->ring_feature[RING_F_DCB].indices; |
| 3413 | |
| 3414 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 3415 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3416 | /* the number of queues is assumed to be symmetric */ |
| 3417 | for (i = 0; i < dcb_i; i++) { |
| 3418 | adapter->rx_ring[i].reg_idx = i << 3; |
| 3419 | adapter->tx_ring[i].reg_idx = i << 2; |
| 3420 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3421 | ret = true; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3422 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | f92ef20 | 2009-04-16 15:00:20 +0000 | [diff] [blame] | 3423 | if (dcb_i == 8) { |
| 3424 | /* |
| 3425 | * Tx TC0 starts at: descriptor queue 0 |
| 3426 | * Tx TC1 starts at: descriptor queue 32 |
| 3427 | * Tx TC2 starts at: descriptor queue 64 |
| 3428 | * Tx TC3 starts at: descriptor queue 80 |
| 3429 | * Tx TC4 starts at: descriptor queue 96 |
| 3430 | * Tx TC5 starts at: descriptor queue 104 |
| 3431 | * Tx TC6 starts at: descriptor queue 112 |
| 3432 | * Tx TC7 starts at: descriptor queue 120 |
| 3433 | * |
| 3434 | * Rx TC0-TC7 are offset by 16 queues each |
| 3435 | */ |
| 3436 | for (i = 0; i < 3; i++) { |
| 3437 | adapter->tx_ring[i].reg_idx = i << 5; |
| 3438 | adapter->rx_ring[i].reg_idx = i << 4; |
| 3439 | } |
| 3440 | for ( ; i < 5; i++) { |
| 3441 | adapter->tx_ring[i].reg_idx = |
| 3442 | ((i + 2) << 4); |
| 3443 | adapter->rx_ring[i].reg_idx = i << 4; |
| 3444 | } |
| 3445 | for ( ; i < dcb_i; i++) { |
| 3446 | adapter->tx_ring[i].reg_idx = |
| 3447 | ((i + 8) << 3); |
| 3448 | adapter->rx_ring[i].reg_idx = i << 4; |
| 3449 | } |
| 3450 | |
| 3451 | ret = true; |
| 3452 | } else if (dcb_i == 4) { |
| 3453 | /* |
| 3454 | * Tx TC0 starts at: descriptor queue 0 |
| 3455 | * Tx TC1 starts at: descriptor queue 64 |
| 3456 | * Tx TC2 starts at: descriptor queue 96 |
| 3457 | * Tx TC3 starts at: descriptor queue 112 |
| 3458 | * |
| 3459 | * Rx TC0-TC3 are offset by 32 queues each |
| 3460 | */ |
| 3461 | adapter->tx_ring[0].reg_idx = 0; |
| 3462 | adapter->tx_ring[1].reg_idx = 64; |
| 3463 | adapter->tx_ring[2].reg_idx = 96; |
| 3464 | adapter->tx_ring[3].reg_idx = 112; |
| 3465 | for (i = 0 ; i < dcb_i; i++) |
| 3466 | adapter->rx_ring[i].reg_idx = i << 5; |
| 3467 | |
| 3468 | ret = true; |
| 3469 | } else { |
| 3470 | ret = false; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3471 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3472 | } else { |
| 3473 | ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3474 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3475 | } else { |
| 3476 | ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3477 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3478 | |
| 3479 | return ret; |
| 3480 | } |
| 3481 | #endif |
| 3482 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3483 | /** |
| 3484 | * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director |
| 3485 | * @adapter: board private structure to initialize |
| 3486 | * |
| 3487 | * Cache the descriptor ring offsets for Flow Director to the assigned rings. |
| 3488 | * |
| 3489 | **/ |
| 3490 | static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter) |
| 3491 | { |
| 3492 | int i; |
| 3493 | bool ret = false; |
| 3494 | |
| 3495 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED && |
| 3496 | ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 3497 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) { |
| 3498 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3499 | adapter->rx_ring[i].reg_idx = i; |
| 3500 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3501 | adapter->tx_ring[i].reg_idx = i; |
| 3502 | ret = true; |
| 3503 | } |
| 3504 | |
| 3505 | return ret; |
| 3506 | } |
| 3507 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3508 | #ifdef IXGBE_FCOE |
| 3509 | /** |
| 3510 | * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE |
| 3511 | * @adapter: board private structure to initialize |
| 3512 | * |
| 3513 | * Cache the descriptor ring offsets for FCoE mode to the assigned rings. |
| 3514 | * |
| 3515 | */ |
| 3516 | static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter) |
| 3517 | { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3518 | int i, fcoe_rx_i = 0, fcoe_tx_i = 0; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3519 | bool ret = false; |
| 3520 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 3521 | |
| 3522 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 3523 | #ifdef CONFIG_IXGBE_DCB |
| 3524 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3525 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
| 3526 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3527 | ixgbe_cache_ring_dcb(adapter); |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3528 | /* find out queues in TC for FCoE */ |
| 3529 | fcoe_rx_i = adapter->rx_ring[fcoe->tc].reg_idx + 1; |
| 3530 | fcoe_tx_i = adapter->tx_ring[fcoe->tc].reg_idx + 1; |
| 3531 | /* |
| 3532 | * In 82599, the number of Tx queues for each traffic |
| 3533 | * class for both 8-TC and 4-TC modes are: |
| 3534 | * TCs : TC0 TC1 TC2 TC3 TC4 TC5 TC6 TC7 |
| 3535 | * 8 TCs: 32 32 16 16 8 8 8 8 |
| 3536 | * 4 TCs: 64 64 32 32 |
| 3537 | * We have max 8 queues for FCoE, where 8 the is |
| 3538 | * FCoE redirection table size. If TC for FCoE is |
| 3539 | * less than or equal to TC3, we have enough queues |
| 3540 | * to add max of 8 queues for FCoE, so we start FCoE |
| 3541 | * tx descriptor from the next one, i.e., reg_idx + 1. |
| 3542 | * If TC for FCoE is above TC3, implying 8 TC mode, |
| 3543 | * and we need 8 for FCoE, we have to take all queues |
| 3544 | * in that traffic class for FCoE. |
| 3545 | */ |
| 3546 | if ((f->indices == IXGBE_FCRETA_SIZE) && (fcoe->tc > 3)) |
| 3547 | fcoe_tx_i--; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3548 | } |
| 3549 | #endif /* CONFIG_IXGBE_DCB */ |
| 3550 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Yi Zou | 8faa2a7 | 2009-07-09 02:29:50 +0000 | [diff] [blame] | 3551 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 3552 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 3553 | ixgbe_cache_ring_fdir(adapter); |
| 3554 | else |
| 3555 | ixgbe_cache_ring_rss(adapter); |
| 3556 | |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3557 | fcoe_rx_i = f->mask; |
| 3558 | fcoe_tx_i = f->mask; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3559 | } |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3560 | for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) { |
| 3561 | adapter->rx_ring[f->mask + i].reg_idx = fcoe_rx_i; |
| 3562 | adapter->tx_ring[f->mask + i].reg_idx = fcoe_tx_i; |
| 3563 | } |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3564 | ret = true; |
| 3565 | } |
| 3566 | return ret; |
| 3567 | } |
| 3568 | |
| 3569 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3570 | /** |
| 3571 | * ixgbe_cache_ring_register - Descriptor ring to register mapping |
| 3572 | * @adapter: board private structure to initialize |
| 3573 | * |
| 3574 | * Once we know the feature-set enabled for the device, we'll cache |
| 3575 | * the register offset the descriptor ring is assigned to. |
| 3576 | * |
| 3577 | * Note, the order the various feature calls is important. It must start with |
| 3578 | * the "most" features enabled at the same time, then trickle down to the |
| 3579 | * least amount of features turned on at once. |
| 3580 | **/ |
| 3581 | static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) |
| 3582 | { |
| 3583 | /* start with default case */ |
| 3584 | adapter->rx_ring[0].reg_idx = 0; |
| 3585 | adapter->tx_ring[0].reg_idx = 0; |
| 3586 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3587 | #ifdef IXGBE_FCOE |
| 3588 | if (ixgbe_cache_ring_fcoe(adapter)) |
| 3589 | return; |
| 3590 | |
| 3591 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3592 | #ifdef CONFIG_IXGBE_DCB |
| 3593 | if (ixgbe_cache_ring_dcb(adapter)) |
| 3594 | return; |
| 3595 | |
| 3596 | #endif |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3597 | if (ixgbe_cache_ring_fdir(adapter)) |
| 3598 | return; |
| 3599 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3600 | if (ixgbe_cache_ring_rss(adapter)) |
| 3601 | return; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3602 | } |
| 3603 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3604 | /** |
| 3605 | * ixgbe_alloc_queues - Allocate memory for all rings |
| 3606 | * @adapter: board private structure to initialize |
| 3607 | * |
| 3608 | * 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] | 3609 | * number of queues at compile-time. The polling_netdev array is |
| 3610 | * intended for Multiqueue, but should work fine with a single queue. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3611 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3612 | static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3613 | { |
| 3614 | int i; |
| 3615 | |
| 3616 | adapter->tx_ring = kcalloc(adapter->num_tx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3617 | sizeof(struct ixgbe_ring), GFP_KERNEL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3618 | if (!adapter->tx_ring) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3619 | goto err_tx_ring_allocation; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3620 | |
| 3621 | adapter->rx_ring = kcalloc(adapter->num_rx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3622 | sizeof(struct ixgbe_ring), GFP_KERNEL); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3623 | if (!adapter->rx_ring) |
| 3624 | goto err_rx_ring_allocation; |
| 3625 | |
| 3626 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3627 | adapter->tx_ring[i].count = adapter->tx_ring_count; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3628 | adapter->tx_ring[i].queue_index = i; |
| 3629 | } |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3630 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3631 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3632 | adapter->rx_ring[i].count = adapter->rx_ring_count; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3633 | adapter->rx_ring[i].queue_index = i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3634 | } |
| 3635 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3636 | ixgbe_cache_ring_register(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3637 | |
| 3638 | return 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3639 | |
| 3640 | err_rx_ring_allocation: |
| 3641 | kfree(adapter->tx_ring); |
| 3642 | err_tx_ring_allocation: |
| 3643 | return -ENOMEM; |
| 3644 | } |
| 3645 | |
| 3646 | /** |
| 3647 | * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported |
| 3648 | * @adapter: board private structure to initialize |
| 3649 | * |
| 3650 | * Attempt to configure the interrupts using the best available |
| 3651 | * capabilities of the hardware and the kernel. |
| 3652 | **/ |
Al Viro | feea6a5 | 2008-11-27 15:34:07 -0800 | [diff] [blame] | 3653 | static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3654 | { |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3655 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3656 | int err = 0; |
| 3657 | int vector, v_budget; |
| 3658 | |
| 3659 | /* |
| 3660 | * It's easy to be greedy for MSI-X vectors, but it really |
| 3661 | * doesn't do us much good if we have a lot more vectors |
| 3662 | * than CPU's. So let's be conservative and only ask for |
PJ Waskiewicz | 342bde1 | 2009-11-12 23:50:43 +0000 | [diff] [blame] | 3663 | * (roughly) the same number of vectors as there are CPU's. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3664 | */ |
| 3665 | v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues, |
PJ Waskiewicz | 342bde1 | 2009-11-12 23:50:43 +0000 | [diff] [blame] | 3666 | (int)num_online_cpus()) + NON_Q_VECTORS; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3667 | |
| 3668 | /* |
| 3669 | * At the same time, hardware can only support a maximum of |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3670 | * hw.mac->max_msix_vectors vectors. With features |
| 3671 | * such as RSS and VMDq, we can easily surpass the number of Rx and Tx |
| 3672 | * descriptor queues supported by our device. Thus, we cap it off in |
| 3673 | * those rare cases where the cpu count also exceeds our vector limit. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3674 | */ |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3675 | v_budget = min(v_budget, (int)hw->mac.max_msix_vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3676 | |
| 3677 | /* A failure in MSI-X entry allocation isn't fatal, but it does |
| 3678 | * mean we disable MSI-X capabilities of the adapter. */ |
| 3679 | adapter->msix_entries = kcalloc(v_budget, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3680 | sizeof(struct msix_entry), GFP_KERNEL); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3681 | if (adapter->msix_entries) { |
| 3682 | for (vector = 0; vector < v_budget; vector++) |
| 3683 | adapter->msix_entries[vector].entry = vector; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3684 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3685 | ixgbe_acquire_msix_vectors(adapter, v_budget); |
| 3686 | |
| 3687 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 3688 | goto out; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3689 | } |
| 3690 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3691 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 3692 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3693 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3694 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 3695 | adapter->atr_sample_rate = 0; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3696 | ixgbe_set_num_queues(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3697 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3698 | err = pci_enable_msi(adapter->pdev); |
| 3699 | if (!err) { |
| 3700 | adapter->flags |= IXGBE_FLAG_MSI_ENABLED; |
| 3701 | } else { |
| 3702 | DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3703 | "falling back to legacy. Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3704 | /* reset err */ |
| 3705 | err = 0; |
| 3706 | } |
| 3707 | |
| 3708 | out: |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3709 | return err; |
| 3710 | } |
| 3711 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3712 | /** |
| 3713 | * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors |
| 3714 | * @adapter: board private structure to initialize |
| 3715 | * |
| 3716 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 3717 | * return -ENOMEM. |
| 3718 | **/ |
| 3719 | static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter) |
| 3720 | { |
| 3721 | int q_idx, num_q_vectors; |
| 3722 | struct ixgbe_q_vector *q_vector; |
| 3723 | int napi_vectors; |
| 3724 | int (*poll)(struct napi_struct *, int); |
| 3725 | |
| 3726 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 3727 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3728 | napi_vectors = adapter->num_rx_queues; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3729 | poll = &ixgbe_clean_rxtx_many; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3730 | } else { |
| 3731 | num_q_vectors = 1; |
| 3732 | napi_vectors = 1; |
| 3733 | poll = &ixgbe_poll; |
| 3734 | } |
| 3735 | |
| 3736 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
| 3737 | q_vector = kzalloc(sizeof(struct ixgbe_q_vector), GFP_KERNEL); |
| 3738 | if (!q_vector) |
| 3739 | goto err_out; |
| 3740 | q_vector->adapter = adapter; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 3741 | if (q_vector->txr_count && !q_vector->rxr_count) |
| 3742 | q_vector->eitr = adapter->tx_eitr_param; |
| 3743 | else |
| 3744 | q_vector->eitr = adapter->rx_eitr_param; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 3745 | q_vector->v_idx = q_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3746 | netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3747 | adapter->q_vector[q_idx] = q_vector; |
| 3748 | } |
| 3749 | |
| 3750 | return 0; |
| 3751 | |
| 3752 | err_out: |
| 3753 | while (q_idx) { |
| 3754 | q_idx--; |
| 3755 | q_vector = adapter->q_vector[q_idx]; |
| 3756 | netif_napi_del(&q_vector->napi); |
| 3757 | kfree(q_vector); |
| 3758 | adapter->q_vector[q_idx] = NULL; |
| 3759 | } |
| 3760 | return -ENOMEM; |
| 3761 | } |
| 3762 | |
| 3763 | /** |
| 3764 | * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors |
| 3765 | * @adapter: board private structure to initialize |
| 3766 | * |
| 3767 | * This function frees the memory allocated to the q_vectors. In addition if |
| 3768 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 3769 | * to freeing the q_vector. |
| 3770 | **/ |
| 3771 | static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter) |
| 3772 | { |
| 3773 | int q_idx, num_q_vectors; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3774 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3775 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3776 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3777 | else |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3778 | num_q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3779 | |
| 3780 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
| 3781 | struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx]; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3782 | adapter->q_vector[q_idx] = NULL; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3783 | netif_napi_del(&q_vector->napi); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3784 | kfree(q_vector); |
| 3785 | } |
| 3786 | } |
| 3787 | |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 3788 | static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3789 | { |
| 3790 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 3791 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 3792 | pci_disable_msix(adapter->pdev); |
| 3793 | kfree(adapter->msix_entries); |
| 3794 | adapter->msix_entries = NULL; |
| 3795 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 3796 | adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED; |
| 3797 | pci_disable_msi(adapter->pdev); |
| 3798 | } |
| 3799 | return; |
| 3800 | } |
| 3801 | |
| 3802 | /** |
| 3803 | * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme |
| 3804 | * @adapter: board private structure to initialize |
| 3805 | * |
| 3806 | * We determine which interrupt scheme to use based on... |
| 3807 | * - Kernel support (MSI, MSI-X) |
| 3808 | * - which can be user-defined (via MODULE_PARAM) |
| 3809 | * - Hardware queue count (num_*_queues) |
| 3810 | * - defined by miscellaneous hardware support/features (RSS, etc.) |
| 3811 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3812 | int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3813 | { |
| 3814 | int err; |
| 3815 | |
| 3816 | /* Number of supported queues */ |
| 3817 | ixgbe_set_num_queues(adapter); |
| 3818 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3819 | err = ixgbe_set_interrupt_capability(adapter); |
| 3820 | if (err) { |
| 3821 | DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n"); |
| 3822 | goto err_set_interrupt; |
| 3823 | } |
| 3824 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3825 | err = ixgbe_alloc_q_vectors(adapter); |
| 3826 | if (err) { |
| 3827 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queue " |
| 3828 | "vectors\n"); |
| 3829 | goto err_alloc_q_vectors; |
| 3830 | } |
| 3831 | |
| 3832 | err = ixgbe_alloc_queues(adapter); |
| 3833 | if (err) { |
| 3834 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n"); |
| 3835 | goto err_alloc_queues; |
| 3836 | } |
| 3837 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3838 | DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3839 | "Tx Queue count = %u\n", |
| 3840 | (adapter->num_rx_queues > 1) ? "Enabled" : |
| 3841 | "Disabled", adapter->num_rx_queues, adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3842 | |
| 3843 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 3844 | |
| 3845 | return 0; |
| 3846 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3847 | err_alloc_queues: |
| 3848 | ixgbe_free_q_vectors(adapter); |
| 3849 | err_alloc_q_vectors: |
| 3850 | ixgbe_reset_interrupt_capability(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3851 | err_set_interrupt: |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3852 | return err; |
| 3853 | } |
| 3854 | |
| 3855 | /** |
| 3856 | * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 3857 | * @adapter: board private structure to clear interrupt scheme on |
| 3858 | * |
| 3859 | * We go through and clear interrupt specific resources and reset the structure |
| 3860 | * to pre-load conditions |
| 3861 | **/ |
| 3862 | void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter) |
| 3863 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3864 | kfree(adapter->tx_ring); |
| 3865 | kfree(adapter->rx_ring); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3866 | adapter->tx_ring = NULL; |
| 3867 | adapter->rx_ring = NULL; |
| 3868 | |
| 3869 | ixgbe_free_q_vectors(adapter); |
| 3870 | ixgbe_reset_interrupt_capability(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3871 | } |
| 3872 | |
| 3873 | /** |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3874 | * ixgbe_sfp_timer - worker thread to find a missing module |
| 3875 | * @data: pointer to our adapter struct |
| 3876 | **/ |
| 3877 | static void ixgbe_sfp_timer(unsigned long data) |
| 3878 | { |
| 3879 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 3880 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3881 | /* |
| 3882 | * Do the sfp_timer outside of interrupt context due to the |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3883 | * delays that sfp+ detection requires |
| 3884 | */ |
| 3885 | schedule_work(&adapter->sfp_task); |
| 3886 | } |
| 3887 | |
| 3888 | /** |
| 3889 | * ixgbe_sfp_task - worker thread to find a missing module |
| 3890 | * @work: pointer to work_struct containing our data |
| 3891 | **/ |
| 3892 | static void ixgbe_sfp_task(struct work_struct *work) |
| 3893 | { |
| 3894 | struct ixgbe_adapter *adapter = container_of(work, |
| 3895 | struct ixgbe_adapter, |
| 3896 | sfp_task); |
| 3897 | struct ixgbe_hw *hw = &adapter->hw; |
| 3898 | |
| 3899 | if ((hw->phy.type == ixgbe_phy_nl) && |
| 3900 | (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) { |
| 3901 | s32 ret = hw->phy.ops.identify_sfp(hw); |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 3902 | if (ret == IXGBE_ERR_SFP_NOT_PRESENT) |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3903 | goto reschedule; |
| 3904 | ret = hw->phy.ops.reset(hw); |
| 3905 | if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 88d2b81 | 2009-06-30 11:43:55 +0000 | [diff] [blame] | 3906 | dev_err(&adapter->pdev->dev, "failed to initialize " |
| 3907 | "because an unsupported SFP+ module type " |
| 3908 | "was detected.\n" |
| 3909 | "Reload the driver after installing a " |
| 3910 | "supported module.\n"); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3911 | unregister_netdev(adapter->netdev); |
| 3912 | } else { |
| 3913 | DPRINTK(PROBE, INFO, "detected SFP+: %d\n", |
| 3914 | hw->phy.sfp_type); |
| 3915 | } |
| 3916 | /* don't need this routine any more */ |
| 3917 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 3918 | } |
| 3919 | return; |
| 3920 | reschedule: |
| 3921 | if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state)) |
| 3922 | mod_timer(&adapter->sfp_timer, |
| 3923 | round_jiffies(jiffies + (2 * HZ))); |
| 3924 | } |
| 3925 | |
| 3926 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3927 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 3928 | * @adapter: board private structure to initialize |
| 3929 | * |
| 3930 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 3931 | * Fields are initialized based on PCI device information and |
| 3932 | * OS network device settings (MTU size). |
| 3933 | **/ |
| 3934 | static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter) |
| 3935 | { |
| 3936 | struct ixgbe_hw *hw = &adapter->hw; |
| 3937 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3938 | unsigned int rss; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3939 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3940 | int j; |
| 3941 | struct tc_configuration *tc; |
| 3942 | #endif |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3943 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3944 | /* PCI config space info */ |
| 3945 | |
| 3946 | hw->vendor_id = pdev->vendor; |
| 3947 | hw->device_id = pdev->device; |
| 3948 | hw->revision_id = pdev->revision; |
| 3949 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 3950 | hw->subsystem_device_id = pdev->subsystem_device; |
| 3951 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3952 | /* Set capability flags */ |
| 3953 | rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus()); |
| 3954 | adapter->ring_feature[RING_F_RSS].indices = rss; |
| 3955 | adapter->flags |= IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3956 | adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES; |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3957 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3958 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 3959 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3960 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598; |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3961 | } else if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3962 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 3963 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
| 3964 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3965 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3966 | adapter->ring_feature[RING_F_FDIR].indices = |
| 3967 | IXGBE_MAX_FDIR_INDICES; |
| 3968 | adapter->atr_sample_rate = 20; |
| 3969 | adapter->fdir_pballoc = 0; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 3970 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 3971 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 3972 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 3973 | adapter->ring_feature[RING_F_FCOE].indices = 0; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 3974 | #ifdef CONFIG_IXGBE_DCB |
Yi Zou | 6ee1652 | 2009-08-31 12:34:28 +0000 | [diff] [blame] | 3975 | /* Default traffic class to use for FCoE */ |
| 3976 | adapter->fcoe.tc = IXGBE_FCOE_DEFTC; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 3977 | #endif |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 3978 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3979 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3980 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3981 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3982 | /* Configure DCB traffic classes */ |
| 3983 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 3984 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 3985 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 3986 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 3987 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 3988 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 3989 | tc->dcb_pfc = pfc_disabled; |
| 3990 | } |
| 3991 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 3992 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
| 3993 | adapter->dcb_cfg.rx_pba_cfg = pba_equal; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 3994 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3995 | adapter->dcb_cfg.round_robin_enable = false; |
| 3996 | adapter->dcb_set_bitmap = 0x00; |
| 3997 | ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg, |
| 3998 | adapter->ring_feature[RING_F_DCB].indices); |
| 3999 | |
| 4000 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4001 | |
| 4002 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 4003 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 4004 | 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] | 4005 | #ifdef CONFIG_DCB |
| 4006 | adapter->last_lfc_mode = hw->fc.current_mode; |
| 4007 | #endif |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 4008 | hw->fc.high_water = IXGBE_DEFAULT_FCRTH; |
| 4009 | hw->fc.low_water = IXGBE_DEFAULT_FCRTL; |
| 4010 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 4011 | hw->fc.send_xon = true; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 4012 | hw->fc.disable_fc_autoneg = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4013 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 4014 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 4015 | adapter->rx_itr_setting = 1; |
| 4016 | adapter->rx_eitr_param = 20000; |
| 4017 | adapter->tx_itr_setting = 1; |
| 4018 | adapter->tx_eitr_param = 10000; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 4019 | |
| 4020 | /* set defaults for eitr in MegaBytes */ |
| 4021 | adapter->eitr_low = 10; |
| 4022 | adapter->eitr_high = 20; |
| 4023 | |
| 4024 | /* set default ring sizes */ |
| 4025 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 4026 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 4027 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4028 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4029 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4030 | dev_err(&pdev->dev, "EEPROM initialization failed\n"); |
| 4031 | return -EIO; |
| 4032 | } |
| 4033 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4034 | /* enable rx csum by default */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4035 | adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED; |
| 4036 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4037 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 4038 | |
| 4039 | return 0; |
| 4040 | } |
| 4041 | |
| 4042 | /** |
| 4043 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
| 4044 | * @adapter: board private structure |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4045 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4046 | * |
| 4047 | * Return 0 on success, negative on failure |
| 4048 | **/ |
| 4049 | int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4050 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4051 | { |
| 4052 | struct pci_dev *pdev = adapter->pdev; |
| 4053 | int size; |
| 4054 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4055 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 4056 | tx_ring->tx_buffer_info = vmalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4057 | if (!tx_ring->tx_buffer_info) |
| 4058 | goto err; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4059 | memset(tx_ring->tx_buffer_info, 0, size); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4060 | |
| 4061 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 4062 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4063 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4064 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4065 | tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size, |
| 4066 | &tx_ring->dma); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4067 | if (!tx_ring->desc) |
| 4068 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4069 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4070 | tx_ring->next_to_use = 0; |
| 4071 | tx_ring->next_to_clean = 0; |
| 4072 | tx_ring->work_limit = tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4073 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4074 | |
| 4075 | err: |
| 4076 | vfree(tx_ring->tx_buffer_info); |
| 4077 | tx_ring->tx_buffer_info = NULL; |
| 4078 | DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit " |
| 4079 | "descriptor ring\n"); |
| 4080 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4081 | } |
| 4082 | |
| 4083 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4084 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 4085 | * @adapter: board private structure |
| 4086 | * |
| 4087 | * If this function returns with an error, then it's possible one or |
| 4088 | * more of the rings is populated (while the rest are not). It is the |
| 4089 | * callers duty to clean those orphaned rings. |
| 4090 | * |
| 4091 | * Return 0 on success, negative on failure |
| 4092 | **/ |
| 4093 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 4094 | { |
| 4095 | int i, err = 0; |
| 4096 | |
| 4097 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 4098 | err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]); |
| 4099 | if (!err) |
| 4100 | continue; |
| 4101 | DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i); |
| 4102 | break; |
| 4103 | } |
| 4104 | |
| 4105 | return err; |
| 4106 | } |
| 4107 | |
| 4108 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4109 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
| 4110 | * @adapter: board private structure |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4111 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4112 | * |
| 4113 | * Returns 0 on success, negative on failure |
| 4114 | **/ |
| 4115 | int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4116 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4117 | { |
| 4118 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4119 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4120 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4121 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 4122 | rx_ring->rx_buffer_info = vmalloc(size); |
| 4123 | if (!rx_ring->rx_buffer_info) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4124 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4125 | "vmalloc allocation failed for the rx desc ring\n"); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4126 | goto alloc_failed; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4127 | } |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4128 | memset(rx_ring->rx_buffer_info, 0, size); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4129 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4130 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4131 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 4132 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4133 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4134 | 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] | 4135 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4136 | if (!rx_ring->desc) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4137 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4138 | "Memory allocation failed for the rx desc ring\n"); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4139 | vfree(rx_ring->rx_buffer_info); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4140 | goto alloc_failed; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4141 | } |
| 4142 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4143 | rx_ring->next_to_clean = 0; |
| 4144 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4145 | |
| 4146 | return 0; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4147 | |
| 4148 | alloc_failed: |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4149 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4150 | } |
| 4151 | |
| 4152 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4153 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 4154 | * @adapter: board private structure |
| 4155 | * |
| 4156 | * If this function returns with an error, then it's possible one or |
| 4157 | * more of the rings is populated (while the rest are not). It is the |
| 4158 | * callers duty to clean those orphaned rings. |
| 4159 | * |
| 4160 | * Return 0 on success, negative on failure |
| 4161 | **/ |
| 4162 | |
| 4163 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 4164 | { |
| 4165 | int i, err = 0; |
| 4166 | |
| 4167 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 4168 | err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]); |
| 4169 | if (!err) |
| 4170 | continue; |
| 4171 | DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i); |
| 4172 | break; |
| 4173 | } |
| 4174 | |
| 4175 | return err; |
| 4176 | } |
| 4177 | |
| 4178 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4179 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
| 4180 | * @adapter: board private structure |
| 4181 | * @tx_ring: Tx descriptor ring for a specific queue |
| 4182 | * |
| 4183 | * Free all transmit software resources |
| 4184 | **/ |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 4185 | void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter, |
| 4186 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4187 | { |
| 4188 | struct pci_dev *pdev = adapter->pdev; |
| 4189 | |
| 4190 | ixgbe_clean_tx_ring(adapter, tx_ring); |
| 4191 | |
| 4192 | vfree(tx_ring->tx_buffer_info); |
| 4193 | tx_ring->tx_buffer_info = NULL; |
| 4194 | |
| 4195 | pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); |
| 4196 | |
| 4197 | tx_ring->desc = NULL; |
| 4198 | } |
| 4199 | |
| 4200 | /** |
| 4201 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 4202 | * @adapter: board private structure |
| 4203 | * |
| 4204 | * Free all transmit software resources |
| 4205 | **/ |
| 4206 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 4207 | { |
| 4208 | int i; |
| 4209 | |
| 4210 | for (i = 0; i < adapter->num_tx_queues; i++) |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 4211 | if (adapter->tx_ring[i].desc) |
| 4212 | ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4213 | } |
| 4214 | |
| 4215 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4216 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4217 | * @adapter: board private structure |
| 4218 | * @rx_ring: ring to clean the resources from |
| 4219 | * |
| 4220 | * Free all receive software resources |
| 4221 | **/ |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 4222 | void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter, |
| 4223 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4224 | { |
| 4225 | struct pci_dev *pdev = adapter->pdev; |
| 4226 | |
| 4227 | ixgbe_clean_rx_ring(adapter, rx_ring); |
| 4228 | |
| 4229 | vfree(rx_ring->rx_buffer_info); |
| 4230 | rx_ring->rx_buffer_info = NULL; |
| 4231 | |
| 4232 | pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); |
| 4233 | |
| 4234 | rx_ring->desc = NULL; |
| 4235 | } |
| 4236 | |
| 4237 | /** |
| 4238 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 4239 | * @adapter: board private structure |
| 4240 | * |
| 4241 | * Free all receive software resources |
| 4242 | **/ |
| 4243 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 4244 | { |
| 4245 | int i; |
| 4246 | |
| 4247 | for (i = 0; i < adapter->num_rx_queues; i++) |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 4248 | if (adapter->rx_ring[i].desc) |
| 4249 | ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4250 | } |
| 4251 | |
| 4252 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4253 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 4254 | * @netdev: network interface device structure |
| 4255 | * @new_mtu: new value for maximum frame size |
| 4256 | * |
| 4257 | * Returns 0 on success, negative on failure |
| 4258 | **/ |
| 4259 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 4260 | { |
| 4261 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4262 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 4263 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 4264 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 4265 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4266 | return -EINVAL; |
| 4267 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4268 | DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n", |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4269 | netdev->mtu, new_mtu); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4270 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4271 | netdev->mtu = new_mtu; |
| 4272 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4273 | if (netif_running(netdev)) |
| 4274 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4275 | |
| 4276 | return 0; |
| 4277 | } |
| 4278 | |
| 4279 | /** |
| 4280 | * ixgbe_open - Called when a network interface is made active |
| 4281 | * @netdev: network interface device structure |
| 4282 | * |
| 4283 | * Returns 0 on success, negative value on failure |
| 4284 | * |
| 4285 | * The open entry point is called when a network interface is made |
| 4286 | * active by the system (IFF_UP). At this point all resources needed |
| 4287 | * for transmit and receive operations are allocated, the interrupt |
| 4288 | * handler is registered with the OS, the watchdog timer is started, |
| 4289 | * and the stack is notified that the interface is ready. |
| 4290 | **/ |
| 4291 | static int ixgbe_open(struct net_device *netdev) |
| 4292 | { |
| 4293 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4294 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4295 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 4296 | /* disallow open during test */ |
| 4297 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 4298 | return -EBUSY; |
| 4299 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 4300 | netif_carrier_off(netdev); |
| 4301 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4302 | /* allocate transmit descriptors */ |
| 4303 | err = ixgbe_setup_all_tx_resources(adapter); |
| 4304 | if (err) |
| 4305 | goto err_setup_tx; |
| 4306 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4307 | /* allocate receive descriptors */ |
| 4308 | err = ixgbe_setup_all_rx_resources(adapter); |
| 4309 | if (err) |
| 4310 | goto err_setup_rx; |
| 4311 | |
| 4312 | ixgbe_configure(adapter); |
| 4313 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4314 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4315 | if (err) |
| 4316 | goto err_req_irq; |
| 4317 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4318 | err = ixgbe_up_complete(adapter); |
| 4319 | if (err) |
| 4320 | goto err_up; |
| 4321 | |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 4322 | netif_tx_start_all_queues(netdev); |
| 4323 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4324 | return 0; |
| 4325 | |
| 4326 | err_up: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 4327 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4328 | ixgbe_free_irq(adapter); |
| 4329 | err_req_irq: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4330 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 4331 | ixgbe_free_all_rx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4332 | err_setup_tx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 4333 | ixgbe_free_all_tx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4334 | ixgbe_reset(adapter); |
| 4335 | |
| 4336 | return err; |
| 4337 | } |
| 4338 | |
| 4339 | /** |
| 4340 | * ixgbe_close - Disables a network interface |
| 4341 | * @netdev: network interface device structure |
| 4342 | * |
| 4343 | * Returns 0, this is not allowed to fail |
| 4344 | * |
| 4345 | * The close entry point is called when an interface is de-activated |
| 4346 | * by the OS. The hardware is still under the drivers control, but |
| 4347 | * needs to be disabled. A global MAC reset is issued to stop the |
| 4348 | * hardware, and all transmit and receive resources are freed. |
| 4349 | **/ |
| 4350 | static int ixgbe_close(struct net_device *netdev) |
| 4351 | { |
| 4352 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4353 | |
| 4354 | ixgbe_down(adapter); |
| 4355 | ixgbe_free_irq(adapter); |
| 4356 | |
| 4357 | ixgbe_free_all_tx_resources(adapter); |
| 4358 | ixgbe_free_all_rx_resources(adapter); |
| 4359 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 4360 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4361 | |
| 4362 | return 0; |
| 4363 | } |
| 4364 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4365 | #ifdef CONFIG_PM |
| 4366 | static int ixgbe_resume(struct pci_dev *pdev) |
| 4367 | { |
| 4368 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4369 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4370 | u32 err; |
| 4371 | |
| 4372 | pci_set_power_state(pdev, PCI_D0); |
| 4373 | pci_restore_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 4374 | |
| 4375 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4376 | if (err) { |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4377 | printk(KERN_ERR "ixgbe: Cannot enable PCI device from " |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4378 | "suspend\n"); |
| 4379 | return err; |
| 4380 | } |
| 4381 | pci_set_master(pdev); |
| 4382 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 4383 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4384 | |
| 4385 | err = ixgbe_init_interrupt_scheme(adapter); |
| 4386 | if (err) { |
| 4387 | printk(KERN_ERR "ixgbe: Cannot initialize interrupts for " |
| 4388 | "device\n"); |
| 4389 | return err; |
| 4390 | } |
| 4391 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4392 | ixgbe_reset(adapter); |
| 4393 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 4394 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 4395 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4396 | if (netif_running(netdev)) { |
| 4397 | err = ixgbe_open(adapter->netdev); |
| 4398 | if (err) |
| 4399 | return err; |
| 4400 | } |
| 4401 | |
| 4402 | netif_device_attach(netdev); |
| 4403 | |
| 4404 | return 0; |
| 4405 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4406 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4407 | |
| 4408 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4409 | { |
| 4410 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4411 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4412 | struct ixgbe_hw *hw = &adapter->hw; |
| 4413 | u32 ctrl, fctrl; |
| 4414 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4415 | #ifdef CONFIG_PM |
| 4416 | int retval = 0; |
| 4417 | #endif |
| 4418 | |
| 4419 | netif_device_detach(netdev); |
| 4420 | |
| 4421 | if (netif_running(netdev)) { |
| 4422 | ixgbe_down(adapter); |
| 4423 | ixgbe_free_irq(adapter); |
| 4424 | ixgbe_free_all_tx_resources(adapter); |
| 4425 | ixgbe_free_all_rx_resources(adapter); |
| 4426 | } |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4427 | ixgbe_clear_interrupt_scheme(adapter); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4428 | |
| 4429 | #ifdef CONFIG_PM |
| 4430 | retval = pci_save_state(pdev); |
| 4431 | if (retval) |
| 4432 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4433 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4434 | #endif |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4435 | if (wufc) { |
| 4436 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4437 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4438 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 4439 | if (wufc & IXGBE_WUFC_MC) { |
| 4440 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 4441 | fctrl |= IXGBE_FCTRL_MPE; |
| 4442 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 4443 | } |
| 4444 | |
| 4445 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 4446 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 4447 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 4448 | |
| 4449 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 4450 | } else { |
| 4451 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 4452 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 4453 | } |
| 4454 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 4455 | if (wufc && hw->mac.type == ixgbe_mac_82599EB) |
| 4456 | pci_wake_from_d3(pdev, true); |
| 4457 | else |
| 4458 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4459 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4460 | *enable_wake = !!wufc; |
| 4461 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4462 | ixgbe_release_hw_control(adapter); |
| 4463 | |
| 4464 | pci_disable_device(pdev); |
| 4465 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4466 | return 0; |
| 4467 | } |
| 4468 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4469 | #ifdef CONFIG_PM |
| 4470 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 4471 | { |
| 4472 | int retval; |
| 4473 | bool wake; |
| 4474 | |
| 4475 | retval = __ixgbe_shutdown(pdev, &wake); |
| 4476 | if (retval) |
| 4477 | return retval; |
| 4478 | |
| 4479 | if (wake) { |
| 4480 | pci_prepare_to_sleep(pdev); |
| 4481 | } else { |
| 4482 | pci_wake_from_d3(pdev, false); |
| 4483 | pci_set_power_state(pdev, PCI_D3hot); |
| 4484 | } |
| 4485 | |
| 4486 | return 0; |
| 4487 | } |
| 4488 | #endif /* CONFIG_PM */ |
| 4489 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4490 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 4491 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4492 | bool wake; |
| 4493 | |
| 4494 | __ixgbe_shutdown(pdev, &wake); |
| 4495 | |
| 4496 | if (system_state == SYSTEM_POWER_OFF) { |
| 4497 | pci_wake_from_d3(pdev, wake); |
| 4498 | pci_set_power_state(pdev, PCI_D3hot); |
| 4499 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4500 | } |
| 4501 | |
| 4502 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4503 | * ixgbe_update_stats - Update the board statistics counters. |
| 4504 | * @adapter: board private structure |
| 4505 | **/ |
| 4506 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 4507 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4508 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4509 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4510 | u64 total_mpc = 0; |
| 4511 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4512 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 4513 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 4514 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 4515 | u64 rsc_flush = 0; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 4516 | for (i = 0; i < 16; i++) |
| 4517 | adapter->hw_rx_no_dma_resources += |
| 4518 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 4519 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 4520 | rsc_count += adapter->rx_ring[i].rsc_count; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 4521 | rsc_flush += adapter->rx_ring[i].rsc_flush; |
| 4522 | } |
| 4523 | adapter->rsc_total_count = rsc_count; |
| 4524 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 4525 | } |
| 4526 | |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 4527 | /* gather some stats to the adapter struct that are per queue */ |
| 4528 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 4529 | adapter->restart_queue += adapter->tx_ring[i].restart_queue; |
| 4530 | |
| 4531 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4532 | adapter->non_eop_descs += adapter->tx_ring[i].non_eop_descs; |
| 4533 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4534 | adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4535 | for (i = 0; i < 8; i++) { |
| 4536 | /* for packet buffers not used, the register should read 0 */ |
| 4537 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 4538 | missed_rx += mpc; |
| 4539 | adapter->stats.mpc[i] += mpc; |
| 4540 | total_mpc += adapter->stats.mpc[i]; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4541 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4542 | adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4543 | adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 4544 | adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 4545 | adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 4546 | adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4547 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 4548 | adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw, |
| 4549 | IXGBE_PXONRXCNT(i)); |
| 4550 | adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw, |
| 4551 | IXGBE_PXOFFRXCNT(i)); |
| 4552 | adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4553 | } else { |
| 4554 | adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw, |
| 4555 | IXGBE_PXONRXC(i)); |
| 4556 | adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw, |
| 4557 | IXGBE_PXOFFRXC(i)); |
| 4558 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4559 | adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw, |
| 4560 | IXGBE_PXONTXC(i)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4561 | adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4562 | IXGBE_PXOFFTXC(i)); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4563 | } |
| 4564 | adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
| 4565 | /* work around hardware counting issue */ |
| 4566 | adapter->stats.gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4567 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4568 | /* 82598 hardware only has a 32 bit counter in the high register */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4569 | if (hw->mac.type == ixgbe_mac_82599EB) { |
Ben Greear | aad7191 | 2009-09-30 12:08:16 +0000 | [diff] [blame] | 4570 | u64 tmp; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4571 | adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Ben Greear | aad7191 | 2009-09-30 12:08:16 +0000 | [diff] [blame] | 4572 | tmp = IXGBE_READ_REG(hw, IXGBE_GORCH) & 0xF; /* 4 high bits of GORC */ |
| 4573 | adapter->stats.gorc += (tmp << 32); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4574 | adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Ben Greear | aad7191 | 2009-09-30 12:08:16 +0000 | [diff] [blame] | 4575 | tmp = IXGBE_READ_REG(hw, IXGBE_GOTCH) & 0xF; /* 4 high bits of GOTC */ |
| 4576 | adapter->stats.gotc += (tmp << 32); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4577 | adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
| 4578 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
| 4579 | adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
| 4580 | adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4581 | adapter->stats.fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 4582 | adapter->stats.fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 4583 | #ifdef IXGBE_FCOE |
| 4584 | adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 4585 | adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 4586 | adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 4587 | adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 4588 | adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 4589 | adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
| 4590 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4591 | } else { |
| 4592 | adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
| 4593 | adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 4594 | adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 4595 | adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 4596 | adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 4597 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4598 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
| 4599 | adapter->stats.bprc += bprc; |
| 4600 | adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4601 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4602 | adapter->stats.mprc -= bprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4603 | adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 4604 | adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 4605 | adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 4606 | adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 4607 | adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 4608 | adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 4609 | adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4610 | adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4611 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
| 4612 | adapter->stats.lxontxc += lxon; |
| 4613 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
| 4614 | adapter->stats.lxofftxc += lxoff; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4615 | adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 4616 | adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4617 | adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
| 4618 | /* |
| 4619 | * 82598 errata - tx of flow control packets is included in tx counters |
| 4620 | */ |
| 4621 | xon_off_tot = lxon + lxoff; |
| 4622 | adapter->stats.gptc -= xon_off_tot; |
| 4623 | adapter->stats.mptc -= xon_off_tot; |
| 4624 | adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4625 | adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 4626 | adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 4627 | adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4628 | adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 4629 | adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4630 | adapter->stats.ptc64 -= xon_off_tot; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4631 | adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 4632 | adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 4633 | adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 4634 | adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 4635 | adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4636 | adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
| 4637 | |
| 4638 | /* Fill out the OS statistics structure */ |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4639 | netdev->stats.multicast = adapter->stats.mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4640 | |
| 4641 | /* Rx Errors */ |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4642 | netdev->stats.rx_errors = adapter->stats.crcerrs + |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4643 | adapter->stats.rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4644 | netdev->stats.rx_dropped = 0; |
| 4645 | netdev->stats.rx_length_errors = adapter->stats.rlec; |
| 4646 | netdev->stats.rx_crc_errors = adapter->stats.crcerrs; |
| 4647 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4648 | } |
| 4649 | |
| 4650 | /** |
| 4651 | * ixgbe_watchdog - Timer Call-back |
| 4652 | * @data: pointer to adapter cast into an unsigned long |
| 4653 | **/ |
| 4654 | static void ixgbe_watchdog(unsigned long data) |
| 4655 | { |
| 4656 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4657 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4658 | u64 eics = 0; |
| 4659 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4660 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4661 | /* |
| 4662 | * Do the watchdog outside of interrupt context due to the lovely |
| 4663 | * delays that some of the newer hardware requires |
| 4664 | */ |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 4665 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4666 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 4667 | goto watchdog_short_circuit; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 4668 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4669 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
| 4670 | /* |
| 4671 | * for legacy and MSI interrupts don't set any bits |
| 4672 | * that are enabled for EIAM, because this operation |
| 4673 | * would set *both* EIMS and EICS for any bit in EIAM |
| 4674 | */ |
| 4675 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 4676 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
| 4677 | goto watchdog_reschedule; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4678 | } |
| 4679 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4680 | /* get one bit for every active tx/rx interrupt vector */ |
| 4681 | for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) { |
| 4682 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
| 4683 | if (qv->rxr_count || qv->txr_count) |
| 4684 | eics |= ((u64)1 << i); |
| 4685 | } |
| 4686 | |
| 4687 | /* Cause software interrupt to ensure rx rings are cleaned */ |
| 4688 | ixgbe_irq_rearm_queues(adapter, eics); |
| 4689 | |
| 4690 | watchdog_reschedule: |
| 4691 | /* Reset the timer */ |
| 4692 | mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ)); |
| 4693 | |
| 4694 | watchdog_short_circuit: |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4695 | schedule_work(&adapter->watchdog_task); |
| 4696 | } |
| 4697 | |
| 4698 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4699 | * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber |
| 4700 | * @work: pointer to work_struct containing our data |
| 4701 | **/ |
| 4702 | static void ixgbe_multispeed_fiber_task(struct work_struct *work) |
| 4703 | { |
| 4704 | struct ixgbe_adapter *adapter = container_of(work, |
| 4705 | struct ixgbe_adapter, |
| 4706 | multispeed_fiber_task); |
| 4707 | struct ixgbe_hw *hw = &adapter->hw; |
| 4708 | u32 autoneg; |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 4709 | bool negotiation; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4710 | |
| 4711 | adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK; |
Mallikarjuna R Chilakala | a1f2532 | 2009-06-30 11:44:36 +0000 | [diff] [blame] | 4712 | autoneg = hw->phy.autoneg_advertised; |
| 4713 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 4714 | hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
| 4715 | if (hw->mac.ops.setup_link) |
| 4716 | hw->mac.ops.setup_link(hw, autoneg, negotiation, true); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4717 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 4718 | adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK; |
| 4719 | } |
| 4720 | |
| 4721 | /** |
| 4722 | * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module |
| 4723 | * @work: pointer to work_struct containing our data |
| 4724 | **/ |
| 4725 | static void ixgbe_sfp_config_module_task(struct work_struct *work) |
| 4726 | { |
| 4727 | struct ixgbe_adapter *adapter = container_of(work, |
| 4728 | struct ixgbe_adapter, |
| 4729 | sfp_config_module_task); |
| 4730 | struct ixgbe_hw *hw = &adapter->hw; |
| 4731 | u32 err; |
| 4732 | |
| 4733 | adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK; |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 4734 | |
| 4735 | /* Time for electrical oscillations to settle down */ |
| 4736 | msleep(100); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4737 | err = hw->phy.ops.identify_sfp(hw); |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 4738 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4739 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 88d2b81 | 2009-06-30 11:43:55 +0000 | [diff] [blame] | 4740 | dev_err(&adapter->pdev->dev, "failed to initialize because " |
| 4741 | "an unsupported SFP+ module type was detected.\n" |
| 4742 | "Reload the driver after installing a supported " |
| 4743 | "module.\n"); |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 4744 | unregister_netdev(adapter->netdev); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4745 | return; |
| 4746 | } |
| 4747 | hw->mac.ops.setup_sfp(hw); |
| 4748 | |
Tony Breeds | 8d1c3c0 | 2009-04-09 22:29:10 +0000 | [diff] [blame] | 4749 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK)) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4750 | /* This will also work for DA Twinax connections */ |
| 4751 | schedule_work(&adapter->multispeed_fiber_task); |
| 4752 | adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK; |
| 4753 | } |
| 4754 | |
| 4755 | /** |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4756 | * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table |
| 4757 | * @work: pointer to work_struct containing our data |
| 4758 | **/ |
| 4759 | static void ixgbe_fdir_reinit_task(struct work_struct *work) |
| 4760 | { |
| 4761 | struct ixgbe_adapter *adapter = container_of(work, |
| 4762 | struct ixgbe_adapter, |
| 4763 | fdir_reinit_task); |
| 4764 | struct ixgbe_hw *hw = &adapter->hw; |
| 4765 | int i; |
| 4766 | |
| 4767 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 4768 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 4769 | set_bit(__IXGBE_FDIR_INIT_DONE, |
| 4770 | &(adapter->tx_ring[i].reinit_state)); |
| 4771 | } else { |
| 4772 | DPRINTK(PROBE, ERR, "failed to finish FDIR re-initialization, " |
| 4773 | "ignored adding FDIR ATR filters \n"); |
| 4774 | } |
| 4775 | /* Done FDIR Re-initialization, enable transmits */ |
| 4776 | netif_tx_start_all_queues(adapter->netdev); |
| 4777 | } |
| 4778 | |
| 4779 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4780 | * ixgbe_watchdog_task - worker thread to bring link up |
| 4781 | * @work: pointer to work_struct containing our data |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4782 | **/ |
| 4783 | static void ixgbe_watchdog_task(struct work_struct *work) |
| 4784 | { |
| 4785 | struct ixgbe_adapter *adapter = container_of(work, |
| 4786 | struct ixgbe_adapter, |
| 4787 | watchdog_task); |
| 4788 | struct net_device *netdev = adapter->netdev; |
| 4789 | struct ixgbe_hw *hw = &adapter->hw; |
| 4790 | u32 link_speed = adapter->link_speed; |
| 4791 | bool link_up = adapter->link_up; |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 4792 | int i; |
| 4793 | struct ixgbe_ring *tx_ring; |
| 4794 | int some_tx_pending = 0; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4795 | |
| 4796 | adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK; |
| 4797 | |
| 4798 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) { |
| 4799 | 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] | 4800 | if (link_up) { |
| 4801 | #ifdef CONFIG_DCB |
| 4802 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 4803 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 4804 | hw->mac.ops.fc_enable(hw, i); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4805 | } else { |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 4806 | hw->mac.ops.fc_enable(hw, 0); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4807 | } |
| 4808 | #else |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 4809 | hw->mac.ops.fc_enable(hw, 0); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4810 | #endif |
| 4811 | } |
| 4812 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4813 | if (link_up || |
| 4814 | time_after(jiffies, (adapter->link_check_timeout + |
| 4815 | IXGBE_TRY_LINK_TIMEOUT))) { |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4816 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4817 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4818 | } |
| 4819 | adapter->link_up = link_up; |
| 4820 | adapter->link_speed = link_speed; |
| 4821 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4822 | |
| 4823 | if (link_up) { |
| 4824 | if (!netif_carrier_ok(netdev)) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4825 | bool flow_rx, flow_tx; |
| 4826 | |
| 4827 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 4828 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 4829 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
Peter P Waskiewicz Jr | 078788b | 2009-07-16 15:50:32 +0000 | [diff] [blame] | 4830 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 4831 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4832 | } else { |
| 4833 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 4834 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
Peter P Waskiewicz Jr | 078788b | 2009-07-16 15:50:32 +0000 | [diff] [blame] | 4835 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 4836 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4837 | } |
| 4838 | |
Jeff Kirsher | a46e534 | 2008-11-27 00:22:21 -0800 | [diff] [blame] | 4839 | printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, " |
| 4840 | "Flow Control: %s\n", |
| 4841 | netdev->name, |
| 4842 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? |
| 4843 | "10 Gbps" : |
| 4844 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? |
| 4845 | "1 Gbps" : "unknown speed")), |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4846 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 4847 | (flow_rx ? "RX" : |
| 4848 | (flow_tx ? "TX" : "None")))); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4849 | |
| 4850 | netif_carrier_on(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4851 | } else { |
| 4852 | /* Force detection of hung controller */ |
| 4853 | adapter->detect_tx_hung = true; |
| 4854 | } |
| 4855 | } else { |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4856 | adapter->link_up = false; |
| 4857 | adapter->link_speed = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4858 | if (netif_carrier_ok(netdev)) { |
Jeff Kirsher | a46e534 | 2008-11-27 00:22:21 -0800 | [diff] [blame] | 4859 | printk(KERN_INFO "ixgbe: %s NIC Link is Down\n", |
| 4860 | netdev->name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4861 | netif_carrier_off(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4862 | } |
| 4863 | } |
| 4864 | |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 4865 | if (!netif_carrier_ok(netdev)) { |
| 4866 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 4867 | tx_ring = &adapter->tx_ring[i]; |
| 4868 | if (tx_ring->next_to_use != tx_ring->next_to_clean) { |
| 4869 | some_tx_pending = 1; |
| 4870 | break; |
| 4871 | } |
| 4872 | } |
| 4873 | |
| 4874 | if (some_tx_pending) { |
| 4875 | /* We've lost link, so the controller stops DMA, |
| 4876 | * but we've got queued Tx work that's never going |
| 4877 | * to get done, so reset controller to flush Tx. |
| 4878 | * (Do the reset outside of interrupt context). |
| 4879 | */ |
| 4880 | schedule_work(&adapter->reset_task); |
| 4881 | } |
| 4882 | } |
| 4883 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4884 | ixgbe_update_stats(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4885 | adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4886 | } |
| 4887 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4888 | static int ixgbe_tso(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4889 | struct ixgbe_ring *tx_ring, struct sk_buff *skb, |
| 4890 | u32 tx_flags, u8 *hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4891 | { |
| 4892 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 4893 | unsigned int i; |
| 4894 | int err; |
| 4895 | struct ixgbe_tx_buffer *tx_buffer_info; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4896 | u32 vlan_macip_lens = 0, type_tucmd_mlhl; |
| 4897 | u32 mss_l4len_idx, l4len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4898 | |
| 4899 | if (skb_is_gso(skb)) { |
| 4900 | if (skb_header_cloned(skb)) { |
| 4901 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 4902 | if (err) |
| 4903 | return err; |
| 4904 | } |
| 4905 | l4len = tcp_hdrlen(skb); |
| 4906 | *hdr_len += l4len; |
| 4907 | |
Al Viro | 8327d00 | 2007-12-10 18:54:12 +0000 | [diff] [blame] | 4908 | if (skb->protocol == htons(ETH_P_IP)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4909 | struct iphdr *iph = ip_hdr(skb); |
| 4910 | iph->tot_len = 0; |
| 4911 | iph->check = 0; |
| 4912 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4913 | iph->daddr, 0, |
| 4914 | IPPROTO_TCP, |
| 4915 | 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4916 | } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) { |
| 4917 | ipv6_hdr(skb)->payload_len = 0; |
| 4918 | tcp_hdr(skb)->check = |
| 4919 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4920 | &ipv6_hdr(skb)->daddr, |
| 4921 | 0, IPPROTO_TCP, 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4922 | } |
| 4923 | |
| 4924 | i = tx_ring->next_to_use; |
| 4925 | |
| 4926 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4927 | context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i); |
| 4928 | |
| 4929 | /* VLAN MACLEN IPLEN */ |
| 4930 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 4931 | vlan_macip_lens |= |
| 4932 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); |
| 4933 | vlan_macip_lens |= ((skb_network_offset(skb)) << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4934 | IXGBE_ADVTXD_MACLEN_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4935 | *hdr_len += skb_network_offset(skb); |
| 4936 | vlan_macip_lens |= |
| 4937 | (skb_transport_header(skb) - skb_network_header(skb)); |
| 4938 | *hdr_len += |
| 4939 | (skb_transport_header(skb) - skb_network_header(skb)); |
| 4940 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 4941 | context_desc->seqnum_seed = 0; |
| 4942 | |
| 4943 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4944 | type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4945 | IXGBE_ADVTXD_DTYP_CTXT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4946 | |
Al Viro | 8327d00 | 2007-12-10 18:54:12 +0000 | [diff] [blame] | 4947 | if (skb->protocol == htons(ETH_P_IP)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4948 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 4949 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 4950 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); |
| 4951 | |
| 4952 | /* MSS L4LEN IDX */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4953 | mss_l4len_idx = |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4954 | (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT); |
| 4955 | mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT); |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 4956 | /* use index 1 for TSO */ |
| 4957 | mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4958 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 4959 | |
| 4960 | tx_buffer_info->time_stamp = jiffies; |
| 4961 | tx_buffer_info->next_to_watch = i; |
| 4962 | |
| 4963 | i++; |
| 4964 | if (i == tx_ring->count) |
| 4965 | i = 0; |
| 4966 | tx_ring->next_to_use = i; |
| 4967 | |
| 4968 | return true; |
| 4969 | } |
| 4970 | return false; |
| 4971 | } |
| 4972 | |
| 4973 | static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4974 | struct ixgbe_ring *tx_ring, |
| 4975 | struct sk_buff *skb, u32 tx_flags) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4976 | { |
| 4977 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 4978 | unsigned int i; |
| 4979 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 4980 | u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0; |
| 4981 | |
| 4982 | if (skb->ip_summed == CHECKSUM_PARTIAL || |
| 4983 | (tx_flags & IXGBE_TX_FLAGS_VLAN)) { |
| 4984 | i = tx_ring->next_to_use; |
| 4985 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4986 | context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i); |
| 4987 | |
| 4988 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 4989 | vlan_macip_lens |= |
| 4990 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); |
| 4991 | vlan_macip_lens |= (skb_network_offset(skb) << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4992 | IXGBE_ADVTXD_MACLEN_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4993 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 4994 | vlan_macip_lens |= (skb_transport_header(skb) - |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4995 | skb_network_header(skb)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4996 | |
| 4997 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 4998 | context_desc->seqnum_seed = 0; |
| 4999 | |
| 5000 | type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5001 | IXGBE_ADVTXD_DTYP_CTXT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5002 | |
| 5003 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5004 | switch (skb->protocol) { |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 5005 | case cpu_to_be16(ETH_P_IP): |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5006 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5007 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 5008 | type_tucmd_mlhl |= |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5009 | IXGBE_ADVTXD_TUCMD_L4T_TCP; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 5010 | else if (ip_hdr(skb)->protocol == IPPROTO_SCTP) |
| 5011 | type_tucmd_mlhl |= |
| 5012 | IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5013 | break; |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 5014 | case cpu_to_be16(ETH_P_IPV6): |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5015 | /* XXX what about other V6 headers?? */ |
| 5016 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 5017 | type_tucmd_mlhl |= |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5018 | IXGBE_ADVTXD_TUCMD_L4T_TCP; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 5019 | else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP) |
| 5020 | type_tucmd_mlhl |= |
| 5021 | IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5022 | break; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5023 | default: |
| 5024 | if (unlikely(net_ratelimit())) { |
| 5025 | DPRINTK(PROBE, WARNING, |
| 5026 | "partial checksum but proto=%x!\n", |
| 5027 | skb->protocol); |
| 5028 | } |
| 5029 | break; |
| 5030 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5031 | } |
| 5032 | |
| 5033 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 5034 | /* use index zero for tx checksum offload */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5035 | context_desc->mss_l4len_idx = 0; |
| 5036 | |
| 5037 | tx_buffer_info->time_stamp = jiffies; |
| 5038 | tx_buffer_info->next_to_watch = i; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5039 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5040 | i++; |
| 5041 | if (i == tx_ring->count) |
| 5042 | i = 0; |
| 5043 | tx_ring->next_to_use = i; |
| 5044 | |
| 5045 | return true; |
| 5046 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5047 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5048 | return false; |
| 5049 | } |
| 5050 | |
| 5051 | static int ixgbe_tx_map(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5052 | struct ixgbe_ring *tx_ring, |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5053 | struct sk_buff *skb, u32 tx_flags, |
| 5054 | unsigned int first) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5055 | { |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5056 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5057 | struct ixgbe_tx_buffer *tx_buffer_info; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5058 | unsigned int len; |
| 5059 | unsigned int total = skb->len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5060 | unsigned int offset = 0, size, count = 0, i; |
| 5061 | unsigned int nr_frags = skb_shinfo(skb)->nr_frags; |
| 5062 | unsigned int f; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5063 | |
| 5064 | i = tx_ring->next_to_use; |
| 5065 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5066 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) |
| 5067 | /* excluding fcoe_crc_eof for FCoE */ |
| 5068 | total -= sizeof(struct fcoe_crc_eof); |
| 5069 | |
| 5070 | len = min(skb_headlen(skb), total); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5071 | while (len) { |
| 5072 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5073 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 5074 | |
| 5075 | tx_buffer_info->length = size; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5076 | tx_buffer_info->mapped_as_page = false; |
| 5077 | tx_buffer_info->dma = pci_map_single(pdev, |
| 5078 | skb->data + offset, |
| 5079 | size, PCI_DMA_TODEVICE); |
| 5080 | if (pci_dma_mapping_error(pdev, tx_buffer_info->dma)) |
| 5081 | goto dma_error; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5082 | tx_buffer_info->time_stamp = jiffies; |
| 5083 | tx_buffer_info->next_to_watch = i; |
| 5084 | |
| 5085 | len -= size; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5086 | total -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5087 | offset += size; |
| 5088 | count++; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5089 | |
| 5090 | if (len) { |
| 5091 | i++; |
| 5092 | if (i == tx_ring->count) |
| 5093 | i = 0; |
| 5094 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5095 | } |
| 5096 | |
| 5097 | for (f = 0; f < nr_frags; f++) { |
| 5098 | struct skb_frag_struct *frag; |
| 5099 | |
| 5100 | frag = &skb_shinfo(skb)->frags[f]; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5101 | len = min((unsigned int)frag->size, total); |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5102 | offset = frag->page_offset; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5103 | |
| 5104 | while (len) { |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5105 | i++; |
| 5106 | if (i == tx_ring->count) |
| 5107 | i = 0; |
| 5108 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5109 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5110 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 5111 | |
| 5112 | tx_buffer_info->length = size; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5113 | tx_buffer_info->dma = pci_map_page(adapter->pdev, |
| 5114 | frag->page, |
| 5115 | offset, size, |
| 5116 | PCI_DMA_TODEVICE); |
| 5117 | tx_buffer_info->mapped_as_page = true; |
| 5118 | if (pci_dma_mapping_error(pdev, tx_buffer_info->dma)) |
| 5119 | goto dma_error; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5120 | tx_buffer_info->time_stamp = jiffies; |
| 5121 | tx_buffer_info->next_to_watch = i; |
| 5122 | |
| 5123 | len -= size; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5124 | total -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5125 | offset += size; |
| 5126 | count++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5127 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5128 | if (total == 0) |
| 5129 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5130 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5131 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5132 | tx_ring->tx_buffer_info[i].skb = skb; |
| 5133 | tx_ring->tx_buffer_info[first].next_to_watch = i; |
| 5134 | |
| 5135 | return count; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5136 | |
| 5137 | dma_error: |
| 5138 | dev_err(&pdev->dev, "TX DMA map failed\n"); |
| 5139 | |
| 5140 | /* clear timestamp and dma mappings for failed tx_buffer_info map */ |
| 5141 | tx_buffer_info->dma = 0; |
| 5142 | tx_buffer_info->time_stamp = 0; |
| 5143 | tx_buffer_info->next_to_watch = 0; |
| 5144 | count--; |
| 5145 | |
| 5146 | /* clear timestamp and dma mappings for remaining portion of packet */ |
| 5147 | while (count >= 0) { |
| 5148 | count--; |
| 5149 | i--; |
| 5150 | if (i < 0) |
| 5151 | i += tx_ring->count; |
| 5152 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5153 | ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info); |
| 5154 | } |
| 5155 | |
| 5156 | return count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5157 | } |
| 5158 | |
| 5159 | static void ixgbe_tx_queue(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5160 | struct ixgbe_ring *tx_ring, |
| 5161 | int tx_flags, int count, u32 paylen, u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5162 | { |
| 5163 | union ixgbe_adv_tx_desc *tx_desc = NULL; |
| 5164 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 5165 | u32 olinfo_status = 0, cmd_type_len = 0; |
| 5166 | unsigned int i; |
| 5167 | u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS; |
| 5168 | |
| 5169 | cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA; |
| 5170 | |
| 5171 | cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT; |
| 5172 | |
| 5173 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 5174 | cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE; |
| 5175 | |
| 5176 | if (tx_flags & IXGBE_TX_FLAGS_TSO) { |
| 5177 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 5178 | |
| 5179 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5180 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5181 | |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 5182 | /* use index 1 context for tso */ |
| 5183 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5184 | if (tx_flags & IXGBE_TX_FLAGS_IPV4) |
| 5185 | olinfo_status |= IXGBE_TXD_POPTS_IXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5186 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5187 | |
| 5188 | } else if (tx_flags & IXGBE_TX_FLAGS_CSUM) |
| 5189 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5190 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5191 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5192 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 5193 | olinfo_status |= IXGBE_ADVTXD_CC; |
| 5194 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
| 5195 | if (tx_flags & IXGBE_TX_FLAGS_FSO) |
| 5196 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 5197 | } |
| 5198 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5199 | olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT); |
| 5200 | |
| 5201 | i = tx_ring->next_to_use; |
| 5202 | while (count--) { |
| 5203 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5204 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); |
| 5205 | tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma); |
| 5206 | tx_desc->read.cmd_type_len = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5207 | cpu_to_le32(cmd_type_len | tx_buffer_info->length); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5208 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5209 | i++; |
| 5210 | if (i == tx_ring->count) |
| 5211 | i = 0; |
| 5212 | } |
| 5213 | |
| 5214 | tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd); |
| 5215 | |
| 5216 | /* |
| 5217 | * Force memory writes to complete before letting h/w |
| 5218 | * know there are new descriptors to fetch. (Only |
| 5219 | * applicable for weak-ordered memory model archs, |
| 5220 | * such as IA-64). |
| 5221 | */ |
| 5222 | wmb(); |
| 5223 | |
| 5224 | tx_ring->next_to_use = i; |
| 5225 | writel(i, adapter->hw.hw_addr + tx_ring->tail); |
| 5226 | } |
| 5227 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5228 | static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb, |
| 5229 | int queue, u32 tx_flags) |
| 5230 | { |
| 5231 | /* Right now, we support IPv4 only */ |
| 5232 | struct ixgbe_atr_input atr_input; |
| 5233 | struct tcphdr *th; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5234 | struct iphdr *iph = ip_hdr(skb); |
| 5235 | struct ethhdr *eth = (struct ethhdr *)skb->data; |
| 5236 | u16 vlan_id, src_port, dst_port, flex_bytes; |
| 5237 | u32 src_ipv4_addr, dst_ipv4_addr; |
| 5238 | u8 l4type = 0; |
| 5239 | |
| 5240 | /* check if we're UDP or TCP */ |
| 5241 | if (iph->protocol == IPPROTO_TCP) { |
| 5242 | th = tcp_hdr(skb); |
| 5243 | src_port = th->source; |
| 5244 | dst_port = th->dest; |
| 5245 | l4type |= IXGBE_ATR_L4TYPE_TCP; |
| 5246 | /* l4type IPv4 type is 0, no need to assign */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5247 | } else { |
| 5248 | /* Unsupported L4 header, just bail here */ |
| 5249 | return; |
| 5250 | } |
| 5251 | |
| 5252 | memset(&atr_input, 0, sizeof(struct ixgbe_atr_input)); |
| 5253 | |
| 5254 | vlan_id = (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK) >> |
| 5255 | IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5256 | src_ipv4_addr = iph->saddr; |
| 5257 | dst_ipv4_addr = iph->daddr; |
| 5258 | flex_bytes = eth->h_proto; |
| 5259 | |
| 5260 | ixgbe_atr_set_vlan_id_82599(&atr_input, vlan_id); |
| 5261 | ixgbe_atr_set_src_port_82599(&atr_input, dst_port); |
| 5262 | ixgbe_atr_set_dst_port_82599(&atr_input, src_port); |
| 5263 | ixgbe_atr_set_flex_byte_82599(&atr_input, flex_bytes); |
| 5264 | ixgbe_atr_set_l4type_82599(&atr_input, l4type); |
| 5265 | /* src and dst are inverted, think how the receiver sees them */ |
| 5266 | ixgbe_atr_set_src_ipv4_82599(&atr_input, dst_ipv4_addr); |
| 5267 | ixgbe_atr_set_dst_ipv4_82599(&atr_input, src_ipv4_addr); |
| 5268 | |
| 5269 | /* This assumes the Rx queue and Tx queue are bound to the same CPU */ |
| 5270 | ixgbe_fdir_add_signature_filter_82599(&adapter->hw, &atr_input, queue); |
| 5271 | } |
| 5272 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5273 | static int __ixgbe_maybe_stop_tx(struct net_device *netdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5274 | struct ixgbe_ring *tx_ring, int size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5275 | { |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5276 | netif_stop_subqueue(netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5277 | /* Herbert's original patch had: |
| 5278 | * smp_mb__after_netif_stop_queue(); |
| 5279 | * but since that doesn't exist yet, just open code it. */ |
| 5280 | smp_mb(); |
| 5281 | |
| 5282 | /* We need to check again in a case another CPU has just |
| 5283 | * made room available. */ |
| 5284 | if (likely(IXGBE_DESC_UNUSED(tx_ring) < size)) |
| 5285 | return -EBUSY; |
| 5286 | |
| 5287 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
Jesse Brandeburg | af72166 | 2008-09-11 19:54:23 -0700 | [diff] [blame] | 5288 | netif_start_subqueue(netdev, tx_ring->queue_index); |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 5289 | ++tx_ring->restart_queue; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5290 | return 0; |
| 5291 | } |
| 5292 | |
| 5293 | static int ixgbe_maybe_stop_tx(struct net_device *netdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5294 | struct ixgbe_ring *tx_ring, int size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5295 | { |
| 5296 | if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size)) |
| 5297 | return 0; |
| 5298 | return __ixgbe_maybe_stop_tx(netdev, tx_ring, size); |
| 5299 | } |
| 5300 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5301 | static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb) |
| 5302 | { |
| 5303 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5304 | int txq = smp_processor_id(); |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5305 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5306 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5307 | return txq; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5308 | |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5309 | #ifdef IXGBE_FCOE |
| 5310 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 5311 | (skb->protocol == htons(ETH_P_FCOE))) { |
| 5312 | txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1); |
| 5313 | txq += adapter->ring_feature[RING_F_FCOE].mask; |
| 5314 | return txq; |
| 5315 | } |
| 5316 | #endif |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5317 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
Lucy Liu | 36e89d7 | 2009-08-05 13:06:34 -0700 | [diff] [blame] | 5318 | return (skb->vlan_tci & IXGBE_TX_FLAGS_VLAN_PRIO_MASK) >> 13; |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5319 | |
| 5320 | return skb_tx_hash(dev, skb); |
| 5321 | } |
| 5322 | |
Stephen Hemminger | 3b29a56 | 2009-08-31 19:50:55 +0000 | [diff] [blame] | 5323 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, |
| 5324 | struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5325 | { |
| 5326 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5327 | struct ixgbe_ring *tx_ring; |
Eric Dumazet | 60d5113 | 2009-12-08 07:22:03 +0000 | [diff] [blame^] | 5328 | struct netdev_queue *txq; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5329 | unsigned int first; |
| 5330 | unsigned int tx_flags = 0; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5331 | u8 hdr_len = 0; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5332 | int tso; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5333 | int count = 0; |
| 5334 | unsigned int f; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5335 | |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5336 | if (adapter->vlgrp && vlan_tx_tag_present(skb)) { |
| 5337 | tx_flags |= vlan_tx_tag_get(skb); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5338 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 5339 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5340 | tx_flags |= ((skb->queue_mapping & 0x7) << 13); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5341 | } |
| 5342 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5343 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
| 5344 | } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 5345 | if (skb->priority != TC_PRIO_CONTROL) { |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5346 | tx_flags |= ((skb->queue_mapping & 0x7) << 13); |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 5347 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5348 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
| 5349 | } else { |
| 5350 | skb->queue_mapping = |
| 5351 | adapter->ring_feature[RING_F_DCB].indices-1; |
| 5352 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5353 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5354 | |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5355 | tx_ring = &adapter->tx_ring[skb->queue_mapping]; |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 5356 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5357 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
Yi Zou | 09ad1cc | 2009-09-03 14:56:10 +0000 | [diff] [blame] | 5358 | (skb->protocol == htons(ETH_P_FCOE))) { |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5359 | tx_flags |= IXGBE_TX_FLAGS_FCOE; |
Yi Zou | 09ad1cc | 2009-09-03 14:56:10 +0000 | [diff] [blame] | 5360 | #ifdef IXGBE_FCOE |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 5361 | #ifdef CONFIG_IXGBE_DCB |
| 5362 | tx_flags &= ~(IXGBE_TX_FLAGS_VLAN_PRIO_MASK |
| 5363 | << IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 5364 | tx_flags |= ((adapter->fcoe.up << 13) |
| 5365 | << IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 5366 | #endif |
Yi Zou | 09ad1cc | 2009-09-03 14:56:10 +0000 | [diff] [blame] | 5367 | #endif |
| 5368 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5369 | /* four things can cause us to need a context descriptor */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5370 | if (skb_is_gso(skb) || |
| 5371 | (skb->ip_summed == CHECKSUM_PARTIAL) || |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5372 | (tx_flags & IXGBE_TX_FLAGS_VLAN) || |
| 5373 | (tx_flags & IXGBE_TX_FLAGS_FCOE)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5374 | count++; |
| 5375 | |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5376 | count += TXD_USE_COUNT(skb_headlen(skb)); |
| 5377 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5378 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
| 5379 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5380 | if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5381 | adapter->tx_busy++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5382 | return NETDEV_TX_BUSY; |
| 5383 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5384 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5385 | first = tx_ring->next_to_use; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5386 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 5387 | #ifdef IXGBE_FCOE |
| 5388 | /* setup tx offload for FCoE */ |
| 5389 | tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len); |
| 5390 | if (tso < 0) { |
| 5391 | dev_kfree_skb_any(skb); |
| 5392 | return NETDEV_TX_OK; |
| 5393 | } |
| 5394 | if (tso) |
| 5395 | tx_flags |= IXGBE_TX_FLAGS_FSO; |
| 5396 | #endif /* IXGBE_FCOE */ |
| 5397 | } else { |
| 5398 | if (skb->protocol == htons(ETH_P_IP)) |
| 5399 | tx_flags |= IXGBE_TX_FLAGS_IPV4; |
| 5400 | tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len); |
| 5401 | if (tso < 0) { |
| 5402 | dev_kfree_skb_any(skb); |
| 5403 | return NETDEV_TX_OK; |
| 5404 | } |
| 5405 | |
| 5406 | if (tso) |
| 5407 | tx_flags |= IXGBE_TX_FLAGS_TSO; |
| 5408 | else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) && |
| 5409 | (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 5410 | tx_flags |= IXGBE_TX_FLAGS_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5411 | } |
| 5412 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5413 | count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5414 | if (count) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5415 | /* add the ATR filter if ATR is on */ |
| 5416 | if (tx_ring->atr_sample_rate) { |
| 5417 | ++tx_ring->atr_count; |
| 5418 | if ((tx_ring->atr_count >= tx_ring->atr_sample_rate) && |
| 5419 | test_bit(__IXGBE_FDIR_INIT_DONE, |
| 5420 | &tx_ring->reinit_state)) { |
| 5421 | ixgbe_atr(adapter, skb, tx_ring->queue_index, |
| 5422 | tx_flags); |
| 5423 | tx_ring->atr_count = 0; |
| 5424 | } |
| 5425 | } |
Eric Dumazet | 60d5113 | 2009-12-08 07:22:03 +0000 | [diff] [blame^] | 5426 | txq = netdev_get_tx_queue(netdev, tx_ring->queue_index); |
| 5427 | txq->tx_bytes += skb->len; |
| 5428 | txq->tx_packets++; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5429 | ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len, |
| 5430 | hdr_len); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5431 | ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5432 | |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5433 | } else { |
| 5434 | dev_kfree_skb_any(skb); |
| 5435 | tx_ring->tx_buffer_info[first].time_stamp = 0; |
| 5436 | tx_ring->next_to_use = first; |
| 5437 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5438 | |
| 5439 | return NETDEV_TX_OK; |
| 5440 | } |
| 5441 | |
| 5442 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5443 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
| 5444 | * @netdev: network interface device structure |
| 5445 | * @p: pointer to an address structure |
| 5446 | * |
| 5447 | * Returns 0 on success, negative on failure |
| 5448 | **/ |
| 5449 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 5450 | { |
| 5451 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5452 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5453 | struct sockaddr *addr = p; |
| 5454 | |
| 5455 | if (!is_valid_ether_addr(addr->sa_data)) |
| 5456 | return -EADDRNOTAVAIL; |
| 5457 | |
| 5458 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5459 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5460 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5461 | 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] | 5462 | |
| 5463 | return 0; |
| 5464 | } |
| 5465 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5466 | static int |
| 5467 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 5468 | { |
| 5469 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5470 | struct ixgbe_hw *hw = &adapter->hw; |
| 5471 | u16 value; |
| 5472 | int rc; |
| 5473 | |
| 5474 | if (prtad != hw->phy.mdio.prtad) |
| 5475 | return -EINVAL; |
| 5476 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 5477 | if (!rc) |
| 5478 | rc = value; |
| 5479 | return rc; |
| 5480 | } |
| 5481 | |
| 5482 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 5483 | u16 addr, u16 value) |
| 5484 | { |
| 5485 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5486 | struct ixgbe_hw *hw = &adapter->hw; |
| 5487 | |
| 5488 | if (prtad != hw->phy.mdio.prtad) |
| 5489 | return -EINVAL; |
| 5490 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 5491 | } |
| 5492 | |
| 5493 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 5494 | { |
| 5495 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5496 | |
| 5497 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 5498 | } |
| 5499 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5500 | /** |
| 5501 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 5502 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5503 | * @netdev: network interface device structure |
| 5504 | * |
| 5505 | * Returns non-zero on failure |
| 5506 | **/ |
| 5507 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
| 5508 | { |
| 5509 | int err = 0; |
| 5510 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 5511 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 5512 | |
| 5513 | if (is_valid_ether_addr(mac->san_addr)) { |
| 5514 | rtnl_lock(); |
| 5515 | err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 5516 | rtnl_unlock(); |
| 5517 | } |
| 5518 | return err; |
| 5519 | } |
| 5520 | |
| 5521 | /** |
| 5522 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 5523 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5524 | * @netdev: network interface device structure |
| 5525 | * |
| 5526 | * Returns non-zero on failure |
| 5527 | **/ |
| 5528 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 5529 | { |
| 5530 | int err = 0; |
| 5531 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 5532 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 5533 | |
| 5534 | if (is_valid_ether_addr(mac->san_addr)) { |
| 5535 | rtnl_lock(); |
| 5536 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 5537 | rtnl_unlock(); |
| 5538 | } |
| 5539 | return err; |
| 5540 | } |
| 5541 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5542 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5543 | /* |
| 5544 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 5545 | * without having to re-enable interrupts. It's not called while |
| 5546 | * the interrupt routine is executing. |
| 5547 | */ |
| 5548 | static void ixgbe_netpoll(struct net_device *netdev) |
| 5549 | { |
| 5550 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 5551 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5552 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5553 | adapter->flags |= IXGBE_FLAG_IN_NETPOLL; |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 5554 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 5555 | int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 5556 | for (i = 0; i < num_q_vectors; i++) { |
| 5557 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
| 5558 | ixgbe_msix_clean_many(0, q_vector); |
| 5559 | } |
| 5560 | } else { |
| 5561 | ixgbe_intr(adapter->pdev->irq, netdev); |
| 5562 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5563 | adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5564 | } |
| 5565 | #endif |
| 5566 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5567 | static const struct net_device_ops ixgbe_netdev_ops = { |
| 5568 | .ndo_open = ixgbe_open, |
| 5569 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 5570 | .ndo_start_xmit = ixgbe_xmit_frame, |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5571 | .ndo_select_queue = ixgbe_select_queue, |
Chris Leech | e90d400 | 2009-03-10 16:00:24 +0000 | [diff] [blame] | 5572 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5573 | .ndo_set_multicast_list = ixgbe_set_rx_mode, |
| 5574 | .ndo_validate_addr = eth_validate_addr, |
| 5575 | .ndo_set_mac_address = ixgbe_set_mac, |
| 5576 | .ndo_change_mtu = ixgbe_change_mtu, |
| 5577 | .ndo_tx_timeout = ixgbe_tx_timeout, |
| 5578 | .ndo_vlan_rx_register = ixgbe_vlan_rx_register, |
| 5579 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 5580 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5581 | .ndo_do_ioctl = ixgbe_ioctl, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5582 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5583 | .ndo_poll_controller = ixgbe_netpoll, |
| 5584 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 5585 | #ifdef IXGBE_FCOE |
| 5586 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
| 5587 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 5588 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 5589 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 5590 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 5591 | #endif /* IXGBE_FCOE */ |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5592 | }; |
| 5593 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5594 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5595 | * ixgbe_probe - Device Initialization Routine |
| 5596 | * @pdev: PCI device information struct |
| 5597 | * @ent: entry in ixgbe_pci_tbl |
| 5598 | * |
| 5599 | * Returns 0 on success, negative on failure |
| 5600 | * |
| 5601 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 5602 | * The OS initialization, configuring of the adapter private structure, |
| 5603 | * and a hardware reset occur. |
| 5604 | **/ |
| 5605 | static int __devinit ixgbe_probe(struct pci_dev *pdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5606 | const struct pci_device_id *ent) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5607 | { |
| 5608 | struct net_device *netdev; |
| 5609 | struct ixgbe_adapter *adapter = NULL; |
| 5610 | struct ixgbe_hw *hw; |
| 5611 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5612 | static int cards_found; |
| 5613 | int i, err, pci_using_dac; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5614 | #ifdef IXGBE_FCOE |
| 5615 | u16 device_caps; |
| 5616 | #endif |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5617 | u32 part_num, eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5618 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5619 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5620 | if (err) |
| 5621 | return err; |
| 5622 | |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 5623 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
| 5624 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5625 | pci_using_dac = 1; |
| 5626 | } else { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5627 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5628 | if (err) { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5629 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5630 | if (err) { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5631 | dev_err(&pdev->dev, "No usable DMA " |
| 5632 | "configuration, aborting\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5633 | goto err_dma; |
| 5634 | } |
| 5635 | } |
| 5636 | pci_using_dac = 0; |
| 5637 | } |
| 5638 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5639 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
| 5640 | IORESOURCE_MEM), ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5641 | if (err) { |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5642 | dev_err(&pdev->dev, |
| 5643 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5644 | goto err_pci_reg; |
| 5645 | } |
| 5646 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 5647 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5648 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5649 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 5650 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5651 | |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5652 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5653 | if (!netdev) { |
| 5654 | err = -ENOMEM; |
| 5655 | goto err_alloc_etherdev; |
| 5656 | } |
| 5657 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5658 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 5659 | |
| 5660 | pci_set_drvdata(pdev, netdev); |
| 5661 | adapter = netdev_priv(netdev); |
| 5662 | |
| 5663 | adapter->netdev = netdev; |
| 5664 | adapter->pdev = pdev; |
| 5665 | hw = &adapter->hw; |
| 5666 | hw->back = adapter; |
| 5667 | adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
| 5668 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 5669 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
| 5670 | pci_resource_len(pdev, 0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5671 | if (!hw->hw_addr) { |
| 5672 | err = -EIO; |
| 5673 | goto err_ioremap; |
| 5674 | } |
| 5675 | |
| 5676 | for (i = 1; i <= 5; i++) { |
| 5677 | if (pci_resource_len(pdev, i) == 0) |
| 5678 | continue; |
| 5679 | } |
| 5680 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5681 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5682 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5683 | netdev->watchdog_timeo = 5 * HZ; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5684 | strcpy(netdev->name, pci_name(pdev)); |
| 5685 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5686 | adapter->bd_number = cards_found; |
| 5687 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5688 | /* Setup hw api */ |
| 5689 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5690 | hw->mac.type = ii->mac; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5691 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5692 | /* EEPROM */ |
| 5693 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); |
| 5694 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 5695 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
| 5696 | if (!(eec & (1 << 8))) |
| 5697 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 5698 | |
| 5699 | /* PHY */ |
| 5700 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5701 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5702 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 5703 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 5704 | hw->phy.mdio.mmds = 0; |
| 5705 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 5706 | hw->phy.mdio.dev = netdev; |
| 5707 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 5708 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5709 | |
| 5710 | /* set up this timer and work struct before calling get_invariants |
| 5711 | * which might start the timer |
| 5712 | */ |
| 5713 | init_timer(&adapter->sfp_timer); |
| 5714 | adapter->sfp_timer.function = &ixgbe_sfp_timer; |
| 5715 | adapter->sfp_timer.data = (unsigned long) adapter; |
| 5716 | |
| 5717 | INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5718 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5719 | /* multispeed fiber has its own tasklet, called from GPI SDP1 context */ |
| 5720 | INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task); |
| 5721 | |
| 5722 | /* a new SFP+ module arrival, called from GPI SDP2 context */ |
| 5723 | INIT_WORK(&adapter->sfp_config_module_task, |
| 5724 | ixgbe_sfp_config_module_task); |
| 5725 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5726 | ii->get_invariants(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5727 | |
| 5728 | /* setup the private structure */ |
| 5729 | err = ixgbe_sw_init(adapter); |
| 5730 | if (err) |
| 5731 | goto err_sw_init; |
| 5732 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5733 | /* |
| 5734 | * If there is a fan on this device and it has failed log the |
| 5735 | * failure. |
| 5736 | */ |
| 5737 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 5738 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 5739 | if (esdp & IXGBE_ESDP_SDP1) |
| 5740 | DPRINTK(PROBE, CRIT, |
| 5741 | "Fan has stopped, replace the adapter\n"); |
| 5742 | } |
| 5743 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5744 | /* reset_hw fills in the perm_addr as well */ |
| 5745 | err = hw->mac.ops.reset_hw(hw); |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5746 | if (err == IXGBE_ERR_SFP_NOT_PRESENT && |
| 5747 | hw->mac.type == ixgbe_mac_82598EB) { |
| 5748 | /* |
| 5749 | * Start a kernel thread to watch for a module to arrive. |
| 5750 | * Only do this for 82598, since 82599 will generate |
| 5751 | * interrupts on module arrival. |
| 5752 | */ |
| 5753 | set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 5754 | mod_timer(&adapter->sfp_timer, |
| 5755 | round_jiffies(jiffies + (2 * HZ))); |
| 5756 | err = 0; |
| 5757 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 88d2b81 | 2009-06-30 11:43:55 +0000 | [diff] [blame] | 5758 | dev_err(&adapter->pdev->dev, "failed to initialize because " |
| 5759 | "an unsupported SFP+ module type was detected.\n" |
| 5760 | "Reload the driver after installing a supported " |
| 5761 | "module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 5762 | goto err_sw_init; |
| 5763 | } else if (err) { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5764 | dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err); |
| 5765 | goto err_sw_init; |
| 5766 | } |
| 5767 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5768 | netdev->features = NETIF_F_SG | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5769 | NETIF_F_IP_CSUM | |
| 5770 | NETIF_F_HW_VLAN_TX | |
| 5771 | NETIF_F_HW_VLAN_RX | |
| 5772 | NETIF_F_HW_VLAN_FILTER; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5773 | |
Jesse Brandeburg | e9990a9 | 2008-08-26 04:27:24 -0700 | [diff] [blame] | 5774 | netdev->features |= NETIF_F_IPV6_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5775 | netdev->features |= NETIF_F_TSO; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5776 | netdev->features |= NETIF_F_TSO6; |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 5777 | netdev->features |= NETIF_F_GRO; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 5778 | |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 5779 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 5780 | netdev->features |= NETIF_F_SCTP_CSUM; |
| 5781 | |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 5782 | netdev->vlan_features |= NETIF_F_TSO; |
| 5783 | netdev->vlan_features |= NETIF_F_TSO6; |
Jesse Brandeburg | 22f32b7a5 | 2008-08-26 04:27:18 -0700 | [diff] [blame] | 5784 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Alexander Duyck | cd1da50 | 2009-08-25 04:47:50 +0000 | [diff] [blame] | 5785 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 5786 | netdev->vlan_features |= NETIF_F_SG; |
| 5787 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5788 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 5789 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
| 5790 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5791 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5792 | netdev->dcbnl_ops = &dcbnl_ops; |
| 5793 | #endif |
| 5794 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5795 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 5796 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5797 | if (hw->mac.ops.get_device_caps) { |
| 5798 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 5799 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 5800 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5801 | } |
| 5802 | } |
| 5803 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5804 | if (pci_using_dac) |
| 5805 | netdev->features |= NETIF_F_HIGHDMA; |
| 5806 | |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 5807 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5808 | netdev->features |= NETIF_F_LRO; |
| 5809 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5810 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5811 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5812 | dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n"); |
| 5813 | err = -EIO; |
| 5814 | goto err_eeprom; |
| 5815 | } |
| 5816 | |
| 5817 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
| 5818 | memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len); |
| 5819 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5820 | if (ixgbe_validate_mac_addr(netdev->perm_addr)) { |
| 5821 | dev_err(&pdev->dev, "invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5822 | err = -EIO; |
| 5823 | goto err_eeprom; |
| 5824 | } |
| 5825 | |
| 5826 | init_timer(&adapter->watchdog_timer); |
| 5827 | adapter->watchdog_timer.function = &ixgbe_watchdog; |
| 5828 | adapter->watchdog_timer.data = (unsigned long)adapter; |
| 5829 | |
| 5830 | INIT_WORK(&adapter->reset_task, ixgbe_reset_task); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5831 | INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5832 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5833 | err = ixgbe_init_interrupt_scheme(adapter); |
| 5834 | if (err) |
| 5835 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5836 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5837 | switch (pdev->device) { |
| 5838 | case IXGBE_DEV_ID_82599_KX4: |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 5839 | adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX | |
| 5840 | IXGBE_WUFC_MC | IXGBE_WUFC_BC); |
Peter P Waskiewicz Jr | bdf0a55 | 2009-06-04 11:09:58 +0000 | [diff] [blame] | 5841 | /* Enable ACPI wakeup in GRC */ |
| 5842 | IXGBE_WRITE_REG(hw, IXGBE_GRC, |
| 5843 | (IXGBE_READ_REG(hw, IXGBE_GRC) & ~IXGBE_GRC_APME)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5844 | break; |
| 5845 | default: |
| 5846 | adapter->wol = 0; |
| 5847 | break; |
| 5848 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5849 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 5850 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 5851 | /* pick up the PCI bus settings for reporting later */ |
| 5852 | hw->mac.ops.get_bus_info(hw); |
| 5853 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5854 | /* print bus type/speed/width info */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 5855 | dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n", |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5856 | ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s": |
| 5857 | (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"), |
| 5858 | ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" : |
| 5859 | (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" : |
| 5860 | (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" : |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5861 | "Unknown"), |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 5862 | netdev->dev_addr); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5863 | ixgbe_read_pba_num_generic(hw, &part_num); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5864 | if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present) |
| 5865 | dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n", |
| 5866 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
| 5867 | (part_num >> 8), (part_num & 0xff)); |
| 5868 | else |
| 5869 | dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n", |
| 5870 | hw->mac.type, hw->phy.type, |
| 5871 | (part_num >> 8), (part_num & 0xff)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5872 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5873 | if (hw->bus.width <= ixgbe_bus_width_pcie_x4) { |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 5874 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5875 | "this card is not sufficient for optimal " |
| 5876 | "performance.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 5877 | dev_warn(&pdev->dev, "For optimal performance a x8 " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5878 | "PCI-Express slot is required.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 5879 | } |
| 5880 | |
Peter P Waskiewicz Jr | 34b0368 | 2009-02-05 23:54:42 -0800 | [diff] [blame] | 5881 | /* save off EEPROM version number */ |
| 5882 | hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version); |
| 5883 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5884 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5885 | err = hw->mac.ops.start_hw(hw); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5886 | |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5887 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 5888 | /* We are running on a pre-production device, log a warning */ |
| 5889 | dev_warn(&pdev->dev, "This device is a pre-production " |
| 5890 | "adapter/LOM. Please be aware there may be issues " |
| 5891 | "associated with your hardware. If you are " |
| 5892 | "experiencing problems please contact your Intel or " |
| 5893 | "hardware representative who provided you with this " |
| 5894 | "hardware.\n"); |
| 5895 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5896 | strcpy(netdev->name, "eth%d"); |
| 5897 | err = register_netdev(netdev); |
| 5898 | if (err) |
| 5899 | goto err_register; |
| 5900 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 5901 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 5902 | netif_carrier_off(netdev); |
| 5903 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5904 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 5905 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 5906 | INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task); |
| 5907 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 5908 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 5909 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5910 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5911 | ixgbe_setup_dca(adapter); |
| 5912 | } |
| 5913 | #endif |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5914 | /* add san mac addr to netdev */ |
| 5915 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5916 | |
| 5917 | dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n"); |
| 5918 | cards_found++; |
| 5919 | return 0; |
| 5920 | |
| 5921 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5922 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5923 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5924 | err_sw_init: |
| 5925 | err_eeprom: |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5926 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 5927 | del_timer_sync(&adapter->sfp_timer); |
| 5928 | cancel_work_sync(&adapter->sfp_task); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5929 | cancel_work_sync(&adapter->multispeed_fiber_task); |
| 5930 | cancel_work_sync(&adapter->sfp_config_module_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5931 | iounmap(hw->hw_addr); |
| 5932 | err_ioremap: |
| 5933 | free_netdev(netdev); |
| 5934 | err_alloc_etherdev: |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5935 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
| 5936 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5937 | err_pci_reg: |
| 5938 | err_dma: |
| 5939 | pci_disable_device(pdev); |
| 5940 | return err; |
| 5941 | } |
| 5942 | |
| 5943 | /** |
| 5944 | * ixgbe_remove - Device Removal Routine |
| 5945 | * @pdev: PCI device information struct |
| 5946 | * |
| 5947 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 5948 | * that it should release a PCI device. The could be caused by a |
| 5949 | * Hot-Plug event, or because the driver is going to be removed from |
| 5950 | * memory. |
| 5951 | **/ |
| 5952 | static void __devexit ixgbe_remove(struct pci_dev *pdev) |
| 5953 | { |
| 5954 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5955 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5956 | |
| 5957 | set_bit(__IXGBE_DOWN, &adapter->state); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5958 | /* clear the module not found bit to make sure the worker won't |
| 5959 | * reschedule |
| 5960 | */ |
| 5961 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5962 | del_timer_sync(&adapter->watchdog_timer); |
| 5963 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5964 | del_timer_sync(&adapter->sfp_timer); |
| 5965 | cancel_work_sync(&adapter->watchdog_task); |
| 5966 | cancel_work_sync(&adapter->sfp_task); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5967 | cancel_work_sync(&adapter->multispeed_fiber_task); |
| 5968 | cancel_work_sync(&adapter->sfp_config_module_task); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5969 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 5970 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 5971 | cancel_work_sync(&adapter->fdir_reinit_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5972 | flush_scheduled_work(); |
| 5973 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 5974 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5975 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 5976 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 5977 | dca_remove_requester(&pdev->dev); |
| 5978 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 5979 | } |
| 5980 | |
| 5981 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 5982 | #ifdef IXGBE_FCOE |
| 5983 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 5984 | ixgbe_cleanup_fcoe(adapter); |
| 5985 | |
| 5986 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5987 | |
| 5988 | /* remove the added san mac */ |
| 5989 | ixgbe_del_sanmac_netdev(netdev); |
| 5990 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5991 | if (netdev->reg_state == NETREG_REGISTERED) |
| 5992 | unregister_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5993 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5994 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5995 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5996 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5997 | |
| 5998 | iounmap(adapter->hw.hw_addr); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5999 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
| 6000 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6001 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6002 | DPRINTK(PROBE, INFO, "complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6003 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6004 | free_netdev(netdev); |
| 6005 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 6006 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6007 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6008 | pci_disable_device(pdev); |
| 6009 | } |
| 6010 | |
| 6011 | /** |
| 6012 | * ixgbe_io_error_detected - called when PCI error is detected |
| 6013 | * @pdev: Pointer to PCI device |
| 6014 | * @state: The current pci connection state |
| 6015 | * |
| 6016 | * This function is called after a PCI bus error affecting |
| 6017 | * this device has been detected. |
| 6018 | */ |
| 6019 | 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] | 6020 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6021 | { |
| 6022 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 6023 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6024 | |
| 6025 | netif_device_detach(netdev); |
| 6026 | |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 6027 | if (state == pci_channel_io_perm_failure) |
| 6028 | return PCI_ERS_RESULT_DISCONNECT; |
| 6029 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6030 | if (netif_running(netdev)) |
| 6031 | ixgbe_down(adapter); |
| 6032 | pci_disable_device(pdev); |
| 6033 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6034 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6035 | return PCI_ERS_RESULT_NEED_RESET; |
| 6036 | } |
| 6037 | |
| 6038 | /** |
| 6039 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 6040 | * @pdev: Pointer to PCI device |
| 6041 | * |
| 6042 | * Restart the card from scratch, as if from a cold-boot. |
| 6043 | */ |
| 6044 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 6045 | { |
| 6046 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 6047 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6048 | pci_ers_result_t result; |
| 6049 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6050 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 6051 | if (pci_enable_device_mem(pdev)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6052 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6053 | "Cannot re-enable PCI device after reset.\n"); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6054 | result = PCI_ERS_RESULT_DISCONNECT; |
| 6055 | } else { |
| 6056 | pci_set_master(pdev); |
| 6057 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 6058 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6059 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 6060 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6061 | |
| 6062 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 6063 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6064 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6065 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6066 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6067 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 6068 | if (err) { |
| 6069 | dev_err(&pdev->dev, |
| 6070 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err); |
| 6071 | /* non-fatal, continue */ |
| 6072 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6073 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6074 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6075 | } |
| 6076 | |
| 6077 | /** |
| 6078 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 6079 | * @pdev: Pointer to PCI device |
| 6080 | * |
| 6081 | * This callback is called when the error recovery driver tells us that |
| 6082 | * its OK to resume normal operation. |
| 6083 | */ |
| 6084 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 6085 | { |
| 6086 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 6087 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6088 | |
| 6089 | if (netif_running(netdev)) { |
| 6090 | if (ixgbe_up(adapter)) { |
| 6091 | DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n"); |
| 6092 | return; |
| 6093 | } |
| 6094 | } |
| 6095 | |
| 6096 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6097 | } |
| 6098 | |
| 6099 | static struct pci_error_handlers ixgbe_err_handler = { |
| 6100 | .error_detected = ixgbe_io_error_detected, |
| 6101 | .slot_reset = ixgbe_io_slot_reset, |
| 6102 | .resume = ixgbe_io_resume, |
| 6103 | }; |
| 6104 | |
| 6105 | static struct pci_driver ixgbe_driver = { |
| 6106 | .name = ixgbe_driver_name, |
| 6107 | .id_table = ixgbe_pci_tbl, |
| 6108 | .probe = ixgbe_probe, |
| 6109 | .remove = __devexit_p(ixgbe_remove), |
| 6110 | #ifdef CONFIG_PM |
| 6111 | .suspend = ixgbe_suspend, |
| 6112 | .resume = ixgbe_resume, |
| 6113 | #endif |
| 6114 | .shutdown = ixgbe_shutdown, |
| 6115 | .err_handler = &ixgbe_err_handler |
| 6116 | }; |
| 6117 | |
| 6118 | /** |
| 6119 | * ixgbe_init_module - Driver Registration Routine |
| 6120 | * |
| 6121 | * ixgbe_init_module is the first routine called when the driver is |
| 6122 | * loaded. All it does is register with the PCI subsystem. |
| 6123 | **/ |
| 6124 | static int __init ixgbe_init_module(void) |
| 6125 | { |
| 6126 | int ret; |
| 6127 | printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name, |
| 6128 | ixgbe_driver_string, ixgbe_driver_version); |
| 6129 | |
| 6130 | printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright); |
| 6131 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6132 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6133 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6134 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6135 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6136 | ret = pci_register_driver(&ixgbe_driver); |
| 6137 | return ret; |
| 6138 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6139 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6140 | module_init(ixgbe_init_module); |
| 6141 | |
| 6142 | /** |
| 6143 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 6144 | * |
| 6145 | * ixgbe_exit_module is called just before the driver is removed |
| 6146 | * from memory. |
| 6147 | **/ |
| 6148 | static void __exit ixgbe_exit_module(void) |
| 6149 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6150 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6151 | dca_unregister_notify(&dca_notifier); |
| 6152 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6153 | pci_unregister_driver(&ixgbe_driver); |
| 6154 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6155 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6156 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6157 | 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] | 6158 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6159 | { |
| 6160 | int ret_val; |
| 6161 | |
| 6162 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6163 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6164 | |
| 6165 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 6166 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6167 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 6168 | #endif /* CONFIG_IXGBE_DCA */ |
| 6169 | #ifdef DEBUG |
| 6170 | /** |
| 6171 | * ixgbe_get_hw_dev_name - return device name string |
| 6172 | * used by hardware layer to print debugging information |
| 6173 | **/ |
| 6174 | char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw) |
| 6175 | { |
| 6176 | struct ixgbe_adapter *adapter = hw->back; |
| 6177 | return adapter->netdev->name; |
| 6178 | } |
| 6179 | |
| 6180 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6181 | module_exit(ixgbe_exit_module); |
| 6182 | |
| 6183 | /* ixgbe_main.c */ |