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 }, |
Don Skidmore | 74757d4 | 2009-12-08 07:22:23 +0000 | [diff] [blame^] | 99 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KR), |
| 100 | board_82599 }, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 101 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), |
| 102 | board_82599 }, |
Don Skidmore | 38ad1c8 | 2009-10-08 15:35:58 +0000 | [diff] [blame] | 103 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP_EM), |
| 104 | board_82599 }, |
Don Skidmore | dbfec66 | 2009-10-02 08:58:25 +0000 | [diff] [blame] | 105 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4_MEZZ), |
| 106 | board_82599 }, |
Peter P Waskiewicz Jr | 8911184 | 2009-09-14 07:47:49 +0000 | [diff] [blame] | 107 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_CX4), |
| 108 | board_82599 }, |
Don Skidmore | 312eb93 | 2009-10-02 08:58:04 +0000 | [diff] [blame] | 109 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_COMBO_BACKPLANE), |
| 110 | board_82599 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 111 | |
| 112 | /* required last entry */ |
| 113 | {0, } |
| 114 | }; |
| 115 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 116 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 117 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 118 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 119 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 120 | static struct notifier_block dca_notifier = { |
| 121 | .notifier_call = ixgbe_notify_dca, |
| 122 | .next = NULL, |
| 123 | .priority = 0 |
| 124 | }; |
| 125 | #endif |
| 126 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 127 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 128 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 129 | MODULE_LICENSE("GPL"); |
| 130 | MODULE_VERSION(DRV_VERSION); |
| 131 | |
| 132 | #define DEFAULT_DEBUG_LEVEL_SHIFT 3 |
| 133 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 134 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 135 | { |
| 136 | u32 ctrl_ext; |
| 137 | |
| 138 | /* Let firmware take over control of h/w */ |
| 139 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 140 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 141 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 145 | { |
| 146 | u32 ctrl_ext; |
| 147 | |
| 148 | /* Let firmware know the driver has taken over */ |
| 149 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 150 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 151 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 152 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 153 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 154 | /* |
| 155 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 156 | * @adapter: pointer to adapter struct |
| 157 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 158 | * @queue: queue to map the corresponding interrupt to |
| 159 | * @msix_vector: the vector to map to the corresponding queue |
| 160 | * |
| 161 | */ |
| 162 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
| 163 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 164 | { |
| 165 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 166 | struct ixgbe_hw *hw = &adapter->hw; |
| 167 | switch (hw->mac.type) { |
| 168 | case ixgbe_mac_82598EB: |
| 169 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 170 | if (direction == -1) |
| 171 | direction = 0; |
| 172 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 173 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 174 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 175 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 176 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 177 | break; |
| 178 | case ixgbe_mac_82599EB: |
| 179 | if (direction == -1) { |
| 180 | /* other causes */ |
| 181 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 182 | index = ((queue & 1) * 8); |
| 183 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 184 | ivar &= ~(0xFF << index); |
| 185 | ivar |= (msix_vector << index); |
| 186 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 187 | break; |
| 188 | } else { |
| 189 | /* tx or rx causes */ |
| 190 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 191 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 192 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 193 | ivar &= ~(0xFF << index); |
| 194 | ivar |= (msix_vector << index); |
| 195 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 196 | break; |
| 197 | } |
| 198 | default: |
| 199 | break; |
| 200 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 201 | } |
| 202 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 203 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
| 204 | u64 qmask) |
| 205 | { |
| 206 | u32 mask; |
| 207 | |
| 208 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 209 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 210 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
| 211 | } else { |
| 212 | mask = (qmask & 0xFFFFFFFF); |
| 213 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 214 | mask = (qmask >> 32); |
| 215 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
| 216 | } |
| 217 | } |
| 218 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 219 | static void ixgbe_unmap_and_free_tx_resource(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 220 | struct ixgbe_tx_buffer |
| 221 | *tx_buffer_info) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 222 | { |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 223 | if (tx_buffer_info->dma) { |
| 224 | if (tx_buffer_info->mapped_as_page) |
| 225 | pci_unmap_page(adapter->pdev, |
| 226 | tx_buffer_info->dma, |
| 227 | tx_buffer_info->length, |
| 228 | PCI_DMA_TODEVICE); |
| 229 | else |
| 230 | pci_unmap_single(adapter->pdev, |
| 231 | tx_buffer_info->dma, |
| 232 | tx_buffer_info->length, |
| 233 | PCI_DMA_TODEVICE); |
| 234 | tx_buffer_info->dma = 0; |
| 235 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 236 | if (tx_buffer_info->skb) { |
| 237 | dev_kfree_skb_any(tx_buffer_info->skb); |
| 238 | tx_buffer_info->skb = NULL; |
| 239 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 240 | tx_buffer_info->time_stamp = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 241 | /* tx_buffer_info must be completely set up in the transmit path */ |
| 242 | } |
| 243 | |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 244 | /** |
| 245 | * ixgbe_tx_is_paused - check if the tx ring is paused |
| 246 | * @adapter: the ixgbe adapter |
| 247 | * @tx_ring: the corresponding tx_ring |
| 248 | * |
| 249 | * If not in DCB mode, checks TFCS.TXOFF, otherwise, find out the |
| 250 | * corresponding TC of this tx_ring when checking TFCS. |
| 251 | * |
| 252 | * Returns : true if paused |
| 253 | */ |
| 254 | static inline bool ixgbe_tx_is_paused(struct ixgbe_adapter *adapter, |
| 255 | struct ixgbe_ring *tx_ring) |
| 256 | { |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 257 | u32 txoff = IXGBE_TFCS_TXOFF; |
| 258 | |
| 259 | #ifdef CONFIG_IXGBE_DCB |
| 260 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Jaswinder Singh Rajput | 30b7683 | 2009-11-20 04:02:27 +0000 | [diff] [blame] | 261 | int tc; |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 262 | int reg_idx = tx_ring->reg_idx; |
| 263 | int dcb_i = adapter->ring_feature[RING_F_DCB].indices; |
| 264 | |
| 265 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 266 | tc = reg_idx >> 2; |
| 267 | txoff = IXGBE_TFCS_TXOFF0; |
| 268 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 269 | tc = 0; |
| 270 | txoff = IXGBE_TFCS_TXOFF; |
| 271 | if (dcb_i == 8) { |
| 272 | /* TC0, TC1 */ |
| 273 | tc = reg_idx >> 5; |
| 274 | if (tc == 2) /* TC2, TC3 */ |
| 275 | tc += (reg_idx - 64) >> 4; |
| 276 | else if (tc == 3) /* TC4, TC5, TC6, TC7 */ |
| 277 | tc += 1 + ((reg_idx - 96) >> 3); |
| 278 | } else if (dcb_i == 4) { |
| 279 | /* TC0, TC1 */ |
| 280 | tc = reg_idx >> 6; |
| 281 | if (tc == 1) { |
| 282 | tc += (reg_idx - 64) >> 5; |
| 283 | if (tc == 2) /* TC2, TC3 */ |
| 284 | tc += (reg_idx - 96) >> 4; |
| 285 | } |
| 286 | } |
| 287 | } |
| 288 | txoff <<= tc; |
| 289 | } |
| 290 | #endif |
| 291 | return IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & txoff; |
| 292 | } |
| 293 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 294 | static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 295 | struct ixgbe_ring *tx_ring, |
| 296 | unsigned int eop) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 297 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 298 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 299 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 300 | /* Detect a transmit hang in hardware, this serializes the |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 301 | * check with the clearing of time_stamp and movement of eop */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 302 | adapter->detect_tx_hung = false; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 303 | if (tx_ring->tx_buffer_info[eop].time_stamp && |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 304 | time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) && |
Yi Zou | 26f23d8 | 2009-11-06 12:56:00 +0000 | [diff] [blame] | 305 | !ixgbe_tx_is_paused(adapter, tx_ring)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 306 | /* detected Tx unit hang */ |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 307 | union ixgbe_adv_tx_desc *tx_desc; |
| 308 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 309 | DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n" |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 310 | " Tx Queue <%d>\n" |
| 311 | " TDH, TDT <%x>, <%x>\n" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 312 | " next_to_use <%x>\n" |
| 313 | " next_to_clean <%x>\n" |
| 314 | "tx_buffer_info[next_to_clean]\n" |
| 315 | " time_stamp <%lx>\n" |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 316 | " jiffies <%lx>\n", |
| 317 | tx_ring->queue_index, |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 318 | IXGBE_READ_REG(hw, tx_ring->head), |
| 319 | IXGBE_READ_REG(hw, tx_ring->tail), |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 320 | tx_ring->next_to_use, eop, |
| 321 | tx_ring->tx_buffer_info[eop].time_stamp, jiffies); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 322 | return true; |
| 323 | } |
| 324 | |
| 325 | return false; |
| 326 | } |
| 327 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 328 | #define IXGBE_MAX_TXD_PWR 14 |
| 329 | #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 330 | |
| 331 | /* Tx Descriptors needed, worst case */ |
| 332 | #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \ |
| 333 | (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0)) |
| 334 | #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] | 335 | MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 336 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 337 | static void ixgbe_tx_timeout(struct net_device *netdev); |
| 338 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 339 | /** |
| 340 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 341 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 342 | * @tx_ring: tx ring to clean |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 343 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 344 | static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 345 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 346 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 347 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 348 | struct net_device *netdev = adapter->netdev; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 349 | union ixgbe_adv_tx_desc *tx_desc, *eop_desc; |
| 350 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 351 | unsigned int i, eop, count = 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 352 | unsigned int total_bytes = 0, total_packets = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 353 | |
| 354 | i = tx_ring->next_to_clean; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 355 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
| 356 | eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
| 357 | |
| 358 | while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) && |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 359 | (count < tx_ring->work_limit)) { |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 360 | bool cleaned = false; |
| 361 | for ( ; !cleaned; count++) { |
| 362 | struct sk_buff *skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 363 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); |
| 364 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 365 | cleaned = (i == eop); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 366 | skb = tx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 367 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 368 | if (cleaned && skb) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 369 | unsigned int segs, bytecount; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 370 | unsigned int hlen = skb_headlen(skb); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 371 | |
| 372 | /* gso_segs is currently only valid for tcp */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 373 | segs = skb_shinfo(skb)->gso_segs ?: 1; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 374 | #ifdef IXGBE_FCOE |
| 375 | /* adjust for FCoE Sequence Offload */ |
| 376 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 377 | && (skb->protocol == htons(ETH_P_FCOE)) && |
| 378 | skb_is_gso(skb)) { |
| 379 | hlen = skb_transport_offset(skb) + |
| 380 | sizeof(struct fc_frame_header) + |
| 381 | sizeof(struct fcoe_crc_eof); |
| 382 | segs = DIV_ROUND_UP(skb->len - hlen, |
| 383 | skb_shinfo(skb)->gso_size); |
| 384 | } |
| 385 | #endif /* IXGBE_FCOE */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 386 | /* multiply data chunks by size of headers */ |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 387 | bytecount = ((segs - 1) * hlen) + skb->len; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 388 | total_packets += segs; |
| 389 | total_bytes += bytecount; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 390 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 391 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 392 | ixgbe_unmap_and_free_tx_resource(adapter, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 393 | tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 394 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 395 | tx_desc->wb.status = 0; |
| 396 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 397 | i++; |
| 398 | if (i == tx_ring->count) |
| 399 | i = 0; |
| 400 | } |
| 401 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 402 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
| 403 | eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
| 404 | } |
| 405 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 406 | tx_ring->next_to_clean = i; |
| 407 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 408 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 409 | if (unlikely(count && netif_carrier_ok(netdev) && |
| 410 | (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 411 | /* Make sure that anybody stopping the queue after this |
| 412 | * sees the new next_to_clean. |
| 413 | */ |
| 414 | smp_mb(); |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 415 | if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) && |
| 416 | !test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 417 | netif_wake_subqueue(netdev, tx_ring->queue_index); |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 418 | ++tx_ring->restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 419 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 420 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 421 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 422 | if (adapter->detect_tx_hung) { |
| 423 | if (ixgbe_check_tx_hang(adapter, tx_ring, i)) { |
| 424 | /* schedule immediate reset if we believe we hung */ |
| 425 | DPRINTK(PROBE, INFO, |
| 426 | "tx hang %d detected, resetting adapter\n", |
| 427 | adapter->tx_timeout_count + 1); |
| 428 | ixgbe_tx_timeout(adapter->netdev); |
| 429 | } |
| 430 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 431 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 432 | /* re-arm the interrupt */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 433 | if (count >= tx_ring->work_limit) |
| 434 | ixgbe_irq_rearm_queues(adapter, ((u64)1 << q_vector->v_idx)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 435 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 436 | tx_ring->total_bytes += total_bytes; |
| 437 | tx_ring->total_packets += total_packets; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 438 | tx_ring->stats.packets += total_packets; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 439 | tx_ring->stats.bytes += total_bytes; |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 440 | return (count < tx_ring->work_limit); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 441 | } |
| 442 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 443 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 444 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 445 | struct ixgbe_ring *rx_ring) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 446 | { |
| 447 | u32 rxctrl; |
| 448 | int cpu = get_cpu(); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 449 | int q = rx_ring - adapter->rx_ring; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 450 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 451 | if (rx_ring->cpu != cpu) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 452 | rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 453 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 454 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK; |
| 455 | rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 456 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 457 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599; |
| 458 | rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 459 | IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599); |
| 460 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 461 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 462 | rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN; |
Don Skidmore | 15005a3 | 2009-01-19 16:54:13 -0800 | [diff] [blame] | 463 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN); |
| 464 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 465 | IXGBE_DCA_RXCTRL_DESC_HSRO_EN); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 466 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 467 | rx_ring->cpu = cpu; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 468 | } |
| 469 | put_cpu(); |
| 470 | } |
| 471 | |
| 472 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 473 | struct ixgbe_ring *tx_ring) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 474 | { |
| 475 | u32 txctrl; |
| 476 | int cpu = get_cpu(); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 477 | int q = tx_ring - adapter->tx_ring; |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 478 | struct ixgbe_hw *hw = &adapter->hw; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 479 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 480 | if (tx_ring->cpu != cpu) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 481 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 482 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 483 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK; |
| 484 | txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 485 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 486 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(q), txctrl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 487 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 488 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 489 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599; |
| 490 | txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 491 | IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599); |
| 492 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 493 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(q), txctrl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 494 | } |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 495 | tx_ring->cpu = cpu; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 496 | } |
| 497 | put_cpu(); |
| 498 | } |
| 499 | |
| 500 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 501 | { |
| 502 | int i; |
| 503 | |
| 504 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 505 | return; |
| 506 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 507 | /* always use CB2 mode, difference is masked in the CB driver */ |
| 508 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); |
| 509 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 510 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 511 | adapter->tx_ring[i].cpu = -1; |
| 512 | ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]); |
| 513 | } |
| 514 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 515 | adapter->rx_ring[i].cpu = -1; |
| 516 | ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]); |
| 517 | } |
| 518 | } |
| 519 | |
| 520 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 521 | { |
| 522 | struct net_device *netdev = dev_get_drvdata(dev); |
| 523 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 524 | unsigned long event = *(unsigned long *)data; |
| 525 | |
| 526 | switch (event) { |
| 527 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 528 | /* if we're already enabled, don't do it again */ |
| 529 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 530 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 531 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 532 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 533 | ixgbe_setup_dca(adapter); |
| 534 | break; |
| 535 | } |
| 536 | /* Fall Through since DCA is disabled. */ |
| 537 | case DCA_PROVIDER_REMOVE: |
| 538 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 539 | dca_remove_requester(dev); |
| 540 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 541 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 542 | } |
| 543 | break; |
| 544 | } |
| 545 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 546 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 547 | } |
| 548 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 549 | #endif /* CONFIG_IXGBE_DCA */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 550 | /** |
| 551 | * ixgbe_receive_skb - Send a completed packet up the stack |
| 552 | * @adapter: board private structure |
| 553 | * @skb: packet to send up |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 554 | * @status: hardware indication of status of receive |
| 555 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
| 556 | * @rx_desc: rx descriptor |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 557 | **/ |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 558 | static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 559 | struct sk_buff *skb, u8 status, |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 560 | struct ixgbe_ring *ring, |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 561 | union ixgbe_adv_rx_desc *rx_desc) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 562 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 563 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 564 | struct napi_struct *napi = &q_vector->napi; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 565 | bool is_vlan = (status & IXGBE_RXD_STAT_VP); |
| 566 | u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 567 | |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 568 | skb_record_rx_queue(skb, ring->queue_index); |
Alexander Duyck | 182ff8d | 2009-04-27 22:35:33 +0000 | [diff] [blame] | 569 | if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) { |
Lucy Liu | 8a62bab | 2009-08-13 14:09:38 +0000 | [diff] [blame] | 570 | if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK)) |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 571 | vlan_gro_receive(napi, adapter->vlgrp, tag, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 572 | else |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 573 | napi_gro_receive(napi, skb); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 574 | } else { |
Lucy Liu | 8a62bab | 2009-08-13 14:09:38 +0000 | [diff] [blame] | 575 | if (adapter->vlgrp && is_vlan && (tag & VLAN_VID_MASK)) |
Alexander Duyck | 182ff8d | 2009-04-27 22:35:33 +0000 | [diff] [blame] | 576 | vlan_hwaccel_rx(skb, adapter->vlgrp, tag); |
| 577 | else |
| 578 | netif_rx(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 579 | } |
| 580 | } |
| 581 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 582 | /** |
| 583 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
| 584 | * @adapter: address of board private structure |
| 585 | * @status_err: hardware indication of status of receive |
| 586 | * @skb: skb currently being received and modified |
| 587 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 588 | static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter, |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 589 | union ixgbe_adv_rx_desc *rx_desc, |
| 590 | struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 591 | { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 592 | u32 status_err = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 593 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 594 | skb->ip_summed = CHECKSUM_NONE; |
| 595 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 596 | /* Rx csum disabled */ |
| 597 | if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 598 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 599 | |
| 600 | /* if IP and error */ |
| 601 | if ((status_err & IXGBE_RXD_STAT_IPCS) && |
| 602 | (status_err & IXGBE_RXDADV_ERR_IPE)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 603 | adapter->hw_csum_rx_error++; |
| 604 | return; |
| 605 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 606 | |
| 607 | if (!(status_err & IXGBE_RXD_STAT_L4CS)) |
| 608 | return; |
| 609 | |
| 610 | if (status_err & IXGBE_RXDADV_ERR_TCPE) { |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 611 | u16 pkt_info = rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 612 | |
| 613 | /* |
| 614 | * 82599 errata, UDP frames with a 0 checksum can be marked as |
| 615 | * checksum errors. |
| 616 | */ |
| 617 | if ((pkt_info & IXGBE_RXDADV_PKTTYPE_UDP) && |
| 618 | (adapter->hw.mac.type == ixgbe_mac_82599EB)) |
| 619 | return; |
| 620 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 621 | adapter->hw_csum_rx_error++; |
| 622 | return; |
| 623 | } |
| 624 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 625 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 626 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 627 | } |
| 628 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 629 | static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw, |
| 630 | struct ixgbe_ring *rx_ring, u32 val) |
| 631 | { |
| 632 | /* |
| 633 | * Force memory writes to complete before letting h/w |
| 634 | * know there are new descriptors to fetch. (Only |
| 635 | * applicable for weak-ordered memory model archs, |
| 636 | * such as IA-64). |
| 637 | */ |
| 638 | wmb(); |
| 639 | IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val); |
| 640 | } |
| 641 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 642 | /** |
| 643 | * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split |
| 644 | * @adapter: address of board private structure |
| 645 | **/ |
| 646 | static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 647 | struct ixgbe_ring *rx_ring, |
| 648 | int cleaned_count) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 649 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 650 | struct pci_dev *pdev = adapter->pdev; |
| 651 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 652 | struct ixgbe_rx_buffer *bi; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 653 | unsigned int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 654 | |
| 655 | i = rx_ring->next_to_use; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 656 | bi = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 657 | |
| 658 | while (cleaned_count--) { |
| 659 | rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 660 | |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 661 | if (!bi->page_dma && |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 662 | (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED)) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 663 | if (!bi->page) { |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 664 | bi->page = alloc_page(GFP_ATOMIC); |
| 665 | if (!bi->page) { |
| 666 | adapter->alloc_rx_page_failed++; |
| 667 | goto no_buffers; |
| 668 | } |
| 669 | bi->page_offset = 0; |
| 670 | } else { |
| 671 | /* use a half page if we're re-using */ |
| 672 | bi->page_offset ^= (PAGE_SIZE / 2); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 673 | } |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 674 | |
| 675 | bi->page_dma = pci_map_page(pdev, bi->page, |
| 676 | bi->page_offset, |
| 677 | (PAGE_SIZE / 2), |
| 678 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 679 | } |
| 680 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 681 | if (!bi->skb) { |
Jesse Brandeburg | 5ecc361 | 2008-12-15 01:00:57 -0800 | [diff] [blame] | 682 | struct sk_buff *skb; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 683 | /* netdev_alloc_skb reserves 32 bytes up front!! */ |
| 684 | uint bufsz = rx_ring->rx_buf_len + SMP_CACHE_BYTES; |
| 685 | skb = netdev_alloc_skb(adapter->netdev, bufsz); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 686 | |
| 687 | if (!skb) { |
| 688 | adapter->alloc_rx_buff_failed++; |
| 689 | goto no_buffers; |
| 690 | } |
| 691 | |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 692 | /* advance the data pointer to the next cache line */ |
| 693 | skb_reserve(skb, (PTR_ALIGN(skb->data, SMP_CACHE_BYTES) |
| 694 | - skb->data)); |
| 695 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 696 | bi->skb = skb; |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 697 | bi->dma = pci_map_single(pdev, skb->data, |
| 698 | rx_ring->rx_buf_len, |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 699 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 700 | } |
| 701 | /* Refresh the desc even if buffer_addrs didn't change because |
| 702 | * each write-back erases this info. */ |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 703 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 704 | rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma); |
| 705 | rx_desc->read.hdr_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 706 | } else { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 707 | rx_desc->read.pkt_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | i++; |
| 711 | if (i == rx_ring->count) |
| 712 | i = 0; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 713 | bi = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 714 | } |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 715 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 716 | no_buffers: |
| 717 | if (rx_ring->next_to_use != i) { |
| 718 | rx_ring->next_to_use = i; |
| 719 | if (i-- == 0) |
| 720 | i = (rx_ring->count - 1); |
| 721 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 722 | ixgbe_release_rx_desc(&adapter->hw, rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 723 | } |
| 724 | } |
| 725 | |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 726 | static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc) |
| 727 | { |
| 728 | return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info; |
| 729 | } |
| 730 | |
| 731 | static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc) |
| 732 | { |
| 733 | return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 734 | } |
| 735 | |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 736 | static inline u32 ixgbe_get_rsc_count(union ixgbe_adv_rx_desc *rx_desc) |
| 737 | { |
| 738 | return (le32_to_cpu(rx_desc->wb.lower.lo_dword.data) & |
| 739 | IXGBE_RXDADV_RSCCNT_MASK) >> |
| 740 | IXGBE_RXDADV_RSCCNT_SHIFT; |
| 741 | } |
| 742 | |
| 743 | /** |
| 744 | * ixgbe_transform_rsc_queue - change rsc queue into a full packet |
| 745 | * @skb: pointer to the last skb in the rsc queue |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 746 | * @count: pointer to number of packets coalesced in this context |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 747 | * |
| 748 | * This function changes a queue full of hw rsc buffers into a completed |
| 749 | * packet. It uses the ->prev pointers to find the first packet and then |
| 750 | * turns it into the frag list owner. |
| 751 | **/ |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 752 | static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb, |
| 753 | u64 *count) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 754 | { |
| 755 | unsigned int frag_list_size = 0; |
| 756 | |
| 757 | while (skb->prev) { |
| 758 | struct sk_buff *prev = skb->prev; |
| 759 | frag_list_size += skb->len; |
| 760 | skb->prev = NULL; |
| 761 | skb = prev; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 762 | *count += 1; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 763 | } |
| 764 | |
| 765 | skb_shinfo(skb)->frag_list = skb->next; |
| 766 | skb->next = NULL; |
| 767 | skb->len += frag_list_size; |
| 768 | skb->data_len += frag_list_size; |
| 769 | skb->truesize += frag_list_size; |
| 770 | return skb; |
| 771 | } |
| 772 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 773 | static bool ixgbe_clean_rx_irq(struct ixgbe_q_vector *q_vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 774 | struct ixgbe_ring *rx_ring, |
| 775 | int *work_done, int work_to_do) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 776 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 777 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 778 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 779 | struct pci_dev *pdev = adapter->pdev; |
| 780 | union ixgbe_adv_rx_desc *rx_desc, *next_rxd; |
| 781 | struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer; |
| 782 | struct sk_buff *skb; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 783 | unsigned int i, rsc_count = 0; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 784 | u32 len, staterr; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 785 | u16 hdr_info; |
| 786 | bool cleaned = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 787 | int cleaned_count = 0; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 788 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 789 | #ifdef IXGBE_FCOE |
| 790 | int ddp_bytes = 0; |
| 791 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 792 | |
| 793 | i = rx_ring->next_to_clean; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 794 | rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 795 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 796 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 797 | |
| 798 | while (staterr & IXGBE_RXD_STAT_DD) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 799 | u32 upper_len = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 800 | if (*work_done >= work_to_do) |
| 801 | break; |
| 802 | (*work_done)++; |
| 803 | |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 804 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 805 | hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc)); |
| 806 | len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >> |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 807 | IXGBE_RXDADV_HDRBUFLEN_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 808 | if (len > IXGBE_RX_HDR_SIZE) |
| 809 | len = IXGBE_RX_HDR_SIZE; |
| 810 | upper_len = le16_to_cpu(rx_desc->wb.upper.length); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 811 | } else { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 812 | len = le16_to_cpu(rx_desc->wb.upper.length); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 813 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 814 | |
| 815 | cleaned = true; |
| 816 | skb = rx_buffer_info->skb; |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 817 | prefetch(skb->data); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 818 | rx_buffer_info->skb = NULL; |
| 819 | |
Alexander Duyck | 21fa4e6 | 2009-06-04 15:59:49 +0000 | [diff] [blame] | 820 | if (rx_buffer_info->dma) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 821 | pci_unmap_single(pdev, rx_buffer_info->dma, |
Jesse Brandeburg | 5ecc361 | 2008-12-15 01:00:57 -0800 | [diff] [blame] | 822 | rx_ring->rx_buf_len, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 823 | PCI_DMA_FROMDEVICE); |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 824 | rx_buffer_info->dma = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 825 | skb_put(skb, len); |
| 826 | } |
| 827 | |
| 828 | if (upper_len) { |
| 829 | pci_unmap_page(pdev, rx_buffer_info->page_dma, |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 830 | PAGE_SIZE / 2, PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 831 | rx_buffer_info->page_dma = 0; |
| 832 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 833 | rx_buffer_info->page, |
| 834 | rx_buffer_info->page_offset, |
| 835 | upper_len); |
| 836 | |
| 837 | if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) || |
| 838 | (page_count(rx_buffer_info->page) != 1)) |
| 839 | rx_buffer_info->page = NULL; |
| 840 | else |
| 841 | get_page(rx_buffer_info->page); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 842 | |
| 843 | skb->len += upper_len; |
| 844 | skb->data_len += upper_len; |
| 845 | skb->truesize += upper_len; |
| 846 | } |
| 847 | |
| 848 | i++; |
| 849 | if (i == rx_ring->count) |
| 850 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 851 | |
| 852 | next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 853 | prefetch(next_rxd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 854 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 855 | |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 856 | if (adapter->flags2 & IXGBE_FLAG2_RSC_CAPABLE) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 857 | rsc_count = ixgbe_get_rsc_count(rx_desc); |
| 858 | |
| 859 | if (rsc_count) { |
| 860 | u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >> |
| 861 | IXGBE_RXDADV_NEXTP_SHIFT; |
| 862 | next_buffer = &rx_ring->rx_buffer_info[nextp]; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 863 | } else { |
| 864 | next_buffer = &rx_ring->rx_buffer_info[i]; |
| 865 | } |
| 866 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 867 | if (staterr & IXGBE_RXD_STAT_EOP) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 868 | if (skb->prev) |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 869 | skb = ixgbe_transform_rsc_queue(skb, &(rx_ring->rsc_count)); |
| 870 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
| 871 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) |
| 872 | rx_ring->rsc_count += skb_shinfo(skb)->nr_frags; |
| 873 | else |
| 874 | rx_ring->rsc_count++; |
| 875 | rx_ring->rsc_flush++; |
| 876 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 877 | rx_ring->stats.packets++; |
| 878 | rx_ring->stats.bytes += skb->len; |
| 879 | } else { |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 880 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 881 | rx_buffer_info->skb = next_buffer->skb; |
| 882 | rx_buffer_info->dma = next_buffer->dma; |
| 883 | next_buffer->skb = skb; |
| 884 | next_buffer->dma = 0; |
| 885 | } else { |
| 886 | skb->next = next_buffer->skb; |
| 887 | skb->next->prev = skb; |
| 888 | } |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 889 | rx_ring->non_eop_descs++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 890 | goto next_desc; |
| 891 | } |
| 892 | |
| 893 | if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) { |
| 894 | dev_kfree_skb_irq(skb); |
| 895 | goto next_desc; |
| 896 | } |
| 897 | |
Don Skidmore | 8bae1b2 | 2009-07-23 18:00:39 +0000 | [diff] [blame] | 898 | ixgbe_rx_checksum(adapter, rx_desc, skb); |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 899 | |
| 900 | /* probably a little skewed due to removing CRC */ |
| 901 | total_rx_bytes += skb->len; |
| 902 | total_rx_packets++; |
| 903 | |
Jesse Brandeburg | 74ce8dd | 2008-09-11 20:03:23 -0700 | [diff] [blame] | 904 | skb->protocol = eth_type_trans(skb, adapter->netdev); |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 905 | #ifdef IXGBE_FCOE |
| 906 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 907 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 908 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
| 909 | if (!ddp_bytes) |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 910 | goto next_desc; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 911 | } |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 912 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 913 | ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 914 | |
| 915 | next_desc: |
| 916 | rx_desc->wb.upper.status_error = 0; |
| 917 | |
| 918 | /* return some buffers to hardware, one at a time is too slow */ |
| 919 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 920 | ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count); |
| 921 | cleaned_count = 0; |
| 922 | } |
| 923 | |
| 924 | /* use prefetched values */ |
| 925 | rx_desc = next_rxd; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 926 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 927 | |
| 928 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 929 | } |
| 930 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 931 | rx_ring->next_to_clean = i; |
| 932 | cleaned_count = IXGBE_DESC_UNUSED(rx_ring); |
| 933 | |
| 934 | if (cleaned_count) |
| 935 | ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count); |
| 936 | |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 937 | #ifdef IXGBE_FCOE |
| 938 | /* include DDPed FCoE data */ |
| 939 | if (ddp_bytes > 0) { |
| 940 | unsigned int mss; |
| 941 | |
| 942 | mss = adapter->netdev->mtu - sizeof(struct fcoe_hdr) - |
| 943 | sizeof(struct fc_frame_header) - |
| 944 | sizeof(struct fcoe_crc_eof); |
| 945 | if (mss > 512) |
| 946 | mss &= ~511; |
| 947 | total_rx_bytes += ddp_bytes; |
| 948 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss); |
| 949 | } |
| 950 | #endif /* IXGBE_FCOE */ |
| 951 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 952 | rx_ring->total_packets += total_rx_packets; |
| 953 | rx_ring->total_bytes += total_rx_bytes; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 954 | netdev->stats.rx_bytes += total_rx_bytes; |
| 955 | netdev->stats.rx_packets += total_rx_packets; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 956 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 957 | return cleaned; |
| 958 | } |
| 959 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 960 | static int ixgbe_clean_rxonly(struct napi_struct *, int); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 961 | /** |
| 962 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 963 | * @adapter: board private structure |
| 964 | * |
| 965 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 966 | * interrupts. |
| 967 | **/ |
| 968 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 969 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 970 | struct ixgbe_q_vector *q_vector; |
| 971 | int i, j, q_vectors, v_idx, r_idx; |
| 972 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 973 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 974 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 975 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 976 | /* |
| 977 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 978 | * corresponding register. |
| 979 | */ |
| 980 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 981 | q_vector = adapter->q_vector[v_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 982 | /* XXX for_each_bit(...) */ |
| 983 | r_idx = find_first_bit(q_vector->rxr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 984 | adapter->num_rx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 985 | |
| 986 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 987 | j = adapter->rx_ring[r_idx].reg_idx; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 988 | ixgbe_set_ivar(adapter, 0, j, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 989 | r_idx = find_next_bit(q_vector->rxr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 990 | adapter->num_rx_queues, |
| 991 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 992 | } |
| 993 | r_idx = find_first_bit(q_vector->txr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 994 | adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 995 | |
| 996 | for (i = 0; i < q_vector->txr_count; i++) { |
| 997 | j = adapter->tx_ring[r_idx].reg_idx; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 998 | ixgbe_set_ivar(adapter, 1, j, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 999 | r_idx = find_next_bit(q_vector->txr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1000 | adapter->num_tx_queues, |
| 1001 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1002 | } |
| 1003 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1004 | if (q_vector->txr_count && !q_vector->rxr_count) |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1005 | /* tx only */ |
| 1006 | q_vector->eitr = adapter->tx_eitr_param; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1007 | else if (q_vector->rxr_count) |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1008 | /* rx or mixed */ |
| 1009 | q_vector->eitr = adapter->rx_eitr_param; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1010 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1011 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1012 | } |
| 1013 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1014 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 1015 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
| 1016 | v_idx); |
| 1017 | else if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 1018 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1019 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1020 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 1021 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1022 | mask = IXGBE_EIMS_ENABLE_MASK; |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 1023 | mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1024 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1025 | } |
| 1026 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1027 | enum latency_range { |
| 1028 | lowest_latency = 0, |
| 1029 | low_latency = 1, |
| 1030 | bulk_latency = 2, |
| 1031 | latency_invalid = 255 |
| 1032 | }; |
| 1033 | |
| 1034 | /** |
| 1035 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
| 1036 | * @adapter: pointer to adapter |
| 1037 | * @eitr: eitr setting (ints per sec) to give last timeslice |
| 1038 | * @itr_setting: current throttle rate in ints/second |
| 1039 | * @packets: the number of packets during this measurement interval |
| 1040 | * @bytes: the number of bytes during this measurement interval |
| 1041 | * |
| 1042 | * Stores a new ITR value based on packets and byte |
| 1043 | * counts during the last interrupt. The advantage of per interrupt |
| 1044 | * computation is faster updates and more accurate ITR for the current |
| 1045 | * traffic pattern. Constants in this function were computed |
| 1046 | * based on theoretical maximum wire speed and thresholds were set based |
| 1047 | * on testing data as well as attempting to minimize response time |
| 1048 | * while increasing bulk throughput. |
| 1049 | * this functionality is controlled by the InterruptThrottleRate module |
| 1050 | * parameter (see ixgbe_param.c) |
| 1051 | **/ |
| 1052 | static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1053 | u32 eitr, u8 itr_setting, |
| 1054 | int packets, int bytes) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1055 | { |
| 1056 | unsigned int retval = itr_setting; |
| 1057 | u32 timepassed_us; |
| 1058 | u64 bytes_perint; |
| 1059 | |
| 1060 | if (packets == 0) |
| 1061 | goto update_itr_done; |
| 1062 | |
| 1063 | |
| 1064 | /* simple throttlerate management |
| 1065 | * 0-20MB/s lowest (100000 ints/s) |
| 1066 | * 20-100MB/s low (20000 ints/s) |
| 1067 | * 100-1249MB/s bulk (8000 ints/s) |
| 1068 | */ |
| 1069 | /* what was last interrupt timeslice? */ |
| 1070 | timepassed_us = 1000000/eitr; |
| 1071 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 1072 | |
| 1073 | switch (itr_setting) { |
| 1074 | case lowest_latency: |
| 1075 | if (bytes_perint > adapter->eitr_low) |
| 1076 | retval = low_latency; |
| 1077 | break; |
| 1078 | case low_latency: |
| 1079 | if (bytes_perint > adapter->eitr_high) |
| 1080 | retval = bulk_latency; |
| 1081 | else if (bytes_perint <= adapter->eitr_low) |
| 1082 | retval = lowest_latency; |
| 1083 | break; |
| 1084 | case bulk_latency: |
| 1085 | if (bytes_perint <= adapter->eitr_high) |
| 1086 | retval = low_latency; |
| 1087 | break; |
| 1088 | } |
| 1089 | |
| 1090 | update_itr_done: |
| 1091 | return retval; |
| 1092 | } |
| 1093 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1094 | /** |
| 1095 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1096 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1097 | * |
| 1098 | * This function is made to be called by ethtool and by the driver |
| 1099 | * when it needs to update EITR registers at runtime. Hardware |
| 1100 | * specific quirks/differences are taken care of here. |
| 1101 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1102 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1103 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1104 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1105 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1106 | int v_idx = q_vector->v_idx; |
| 1107 | u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr); |
| 1108 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1109 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1110 | /* must write high and low 16 bits to reset counter */ |
| 1111 | itr_reg |= (itr_reg << 16); |
| 1112 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 1113 | /* |
| 1114 | * set the WDIS bit to not clear the timer bits and cause an |
| 1115 | * immediate assertion of the interrupt |
| 1116 | */ |
| 1117 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
| 1118 | } |
| 1119 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 1120 | } |
| 1121 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1122 | static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector) |
| 1123 | { |
| 1124 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1125 | u32 new_itr; |
| 1126 | u8 current_itr, ret_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1127 | int i, r_idx; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1128 | struct ixgbe_ring *rx_ring, *tx_ring; |
| 1129 | |
| 1130 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1131 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1132 | tx_ring = &(adapter->tx_ring[r_idx]); |
| 1133 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1134 | q_vector->tx_itr, |
| 1135 | tx_ring->total_packets, |
| 1136 | tx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1137 | /* if the result for this queue would decrease interrupt |
| 1138 | * rate for this vector then use that result */ |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1139 | q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ? |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1140 | q_vector->tx_itr - 1 : ret_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1141 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1142 | r_idx + 1); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1143 | } |
| 1144 | |
| 1145 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1146 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1147 | rx_ring = &(adapter->rx_ring[r_idx]); |
| 1148 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1149 | q_vector->rx_itr, |
| 1150 | rx_ring->total_packets, |
| 1151 | rx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1152 | /* if the result for this queue would decrease interrupt |
| 1153 | * rate for this vector then use that result */ |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1154 | q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ? |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1155 | q_vector->rx_itr - 1 : ret_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1156 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1157 | r_idx + 1); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1158 | } |
| 1159 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1160 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1161 | |
| 1162 | switch (current_itr) { |
| 1163 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1164 | case lowest_latency: |
| 1165 | new_itr = 100000; |
| 1166 | break; |
| 1167 | case low_latency: |
| 1168 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 1169 | break; |
| 1170 | case bulk_latency: |
| 1171 | default: |
| 1172 | new_itr = 8000; |
| 1173 | break; |
| 1174 | } |
| 1175 | |
| 1176 | if (new_itr != q_vector->eitr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1177 | /* do an exponential smoothing */ |
| 1178 | new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1179 | |
| 1180 | /* save the algorithm value here, not the smoothed one */ |
| 1181 | q_vector->eitr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1182 | |
| 1183 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1184 | } |
| 1185 | |
| 1186 | return; |
| 1187 | } |
| 1188 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1189 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 1190 | { |
| 1191 | struct ixgbe_hw *hw = &adapter->hw; |
| 1192 | |
| 1193 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
| 1194 | (eicr & IXGBE_EICR_GPI_SDP1)) { |
| 1195 | DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n"); |
| 1196 | /* write to clear the interrupt */ |
| 1197 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 1198 | } |
| 1199 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1200 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1201 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 1202 | { |
| 1203 | struct ixgbe_hw *hw = &adapter->hw; |
| 1204 | |
| 1205 | if (eicr & IXGBE_EICR_GPI_SDP1) { |
| 1206 | /* Clear the interrupt */ |
| 1207 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 1208 | schedule_work(&adapter->multispeed_fiber_task); |
| 1209 | } else if (eicr & IXGBE_EICR_GPI_SDP2) { |
| 1210 | /* Clear the interrupt */ |
| 1211 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2); |
| 1212 | schedule_work(&adapter->sfp_config_module_task); |
| 1213 | } else { |
| 1214 | /* Interrupt isn't for us... */ |
| 1215 | return; |
| 1216 | } |
| 1217 | } |
| 1218 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1219 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 1220 | { |
| 1221 | struct ixgbe_hw *hw = &adapter->hw; |
| 1222 | |
| 1223 | adapter->lsc_int++; |
| 1224 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 1225 | adapter->link_check_timeout = jiffies; |
| 1226 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1227 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
Nelson, Shannon | 8a0717f | 2009-11-12 18:47:11 +0000 | [diff] [blame] | 1228 | IXGBE_WRITE_FLUSH(hw); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1229 | schedule_work(&adapter->watchdog_task); |
| 1230 | } |
| 1231 | } |
| 1232 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1233 | static irqreturn_t ixgbe_msix_lsc(int irq, void *data) |
| 1234 | { |
| 1235 | struct net_device *netdev = data; |
| 1236 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1237 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 1238 | u32 eicr; |
| 1239 | |
| 1240 | /* |
| 1241 | * Workaround for Silicon errata. Use clear-by-write instead |
| 1242 | * of clear-by-read. Reading with EICS will return the |
| 1243 | * interrupt causes without clearing, which later be done |
| 1244 | * with the write to EICR. |
| 1245 | */ |
| 1246 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
| 1247 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1248 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1249 | if (eicr & IXGBE_EICR_LSC) |
| 1250 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1251 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1252 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 1253 | ixgbe_check_fan_failure(adapter, eicr); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1254 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1255 | if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1256 | ixgbe_check_sfp_event(adapter, eicr); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1257 | |
| 1258 | /* Handle Flow Director Full threshold interrupt */ |
| 1259 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
| 1260 | int i; |
| 1261 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR); |
| 1262 | /* Disable transmits before FDIR Re-initialization */ |
| 1263 | netif_tx_stop_all_queues(netdev); |
| 1264 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 1265 | struct ixgbe_ring *tx_ring = |
| 1266 | &adapter->tx_ring[i]; |
| 1267 | if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE, |
| 1268 | &tx_ring->reinit_state)) |
| 1269 | schedule_work(&adapter->fdir_reinit_task); |
| 1270 | } |
| 1271 | } |
| 1272 | } |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1273 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1274 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1275 | |
| 1276 | return IRQ_HANDLED; |
| 1277 | } |
| 1278 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1279 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 1280 | u64 qmask) |
| 1281 | { |
| 1282 | u32 mask; |
| 1283 | |
| 1284 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1285 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 1286 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 1287 | } else { |
| 1288 | mask = (qmask & 0xFFFFFFFF); |
| 1289 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(0), mask); |
| 1290 | mask = (qmask >> 32); |
| 1291 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask); |
| 1292 | } |
| 1293 | /* skip the flush */ |
| 1294 | } |
| 1295 | |
| 1296 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
| 1297 | u64 qmask) |
| 1298 | { |
| 1299 | u32 mask; |
| 1300 | |
| 1301 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1302 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 1303 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask); |
| 1304 | } else { |
| 1305 | mask = (qmask & 0xFFFFFFFF); |
| 1306 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), mask); |
| 1307 | mask = (qmask >> 32); |
| 1308 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), mask); |
| 1309 | } |
| 1310 | /* skip the flush */ |
| 1311 | } |
| 1312 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1313 | static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data) |
| 1314 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1315 | struct ixgbe_q_vector *q_vector = data; |
| 1316 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1317 | struct ixgbe_ring *tx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1318 | int i, r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1319 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1320 | if (!q_vector->txr_count) |
| 1321 | return IRQ_HANDLED; |
| 1322 | |
| 1323 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1324 | for (i = 0; i < q_vector->txr_count; i++) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1325 | tx_ring = &(adapter->tx_ring[r_idx]); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1326 | tx_ring->total_bytes = 0; |
| 1327 | tx_ring->total_packets = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1328 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1329 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1330 | } |
| 1331 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 1332 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1333 | napi_schedule(&q_vector->napi); |
| 1334 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1335 | return IRQ_HANDLED; |
| 1336 | } |
| 1337 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1338 | /** |
| 1339 | * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues) |
| 1340 | * @irq: unused |
| 1341 | * @data: pointer to our q_vector struct for this interrupt vector |
| 1342 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1343 | static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data) |
| 1344 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1345 | struct ixgbe_q_vector *q_vector = data; |
| 1346 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1347 | struct ixgbe_ring *rx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1348 | int r_idx; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1349 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1350 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1351 | 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] | 1352 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1353 | rx_ring = &(adapter->rx_ring[r_idx]); |
| 1354 | rx_ring->total_bytes = 0; |
| 1355 | rx_ring->total_packets = 0; |
| 1356 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1357 | r_idx + 1); |
| 1358 | } |
| 1359 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1360 | if (!q_vector->rxr_count) |
| 1361 | return IRQ_HANDLED; |
| 1362 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1363 | /* disable interrupts on this vector only */ |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 1364 | /* EIAM disabled interrupts (on this vector) for us */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1365 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1366 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1367 | return IRQ_HANDLED; |
| 1368 | } |
| 1369 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1370 | static irqreturn_t ixgbe_msix_clean_many(int irq, void *data) |
| 1371 | { |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1372 | struct ixgbe_q_vector *q_vector = data; |
| 1373 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1374 | struct ixgbe_ring *ring; |
| 1375 | int r_idx; |
| 1376 | int i; |
| 1377 | |
| 1378 | if (!q_vector->txr_count && !q_vector->rxr_count) |
| 1379 | return IRQ_HANDLED; |
| 1380 | |
| 1381 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1382 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1383 | ring = &(adapter->tx_ring[r_idx]); |
| 1384 | ring->total_bytes = 0; |
| 1385 | ring->total_packets = 0; |
| 1386 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
| 1387 | r_idx + 1); |
| 1388 | } |
| 1389 | |
| 1390 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1391 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1392 | ring = &(adapter->rx_ring[r_idx]); |
| 1393 | ring->total_bytes = 0; |
| 1394 | ring->total_packets = 0; |
| 1395 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1396 | r_idx + 1); |
| 1397 | } |
| 1398 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 1399 | /* EIAM disabled interrupts (on this vector) for us */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1400 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1401 | |
| 1402 | return IRQ_HANDLED; |
| 1403 | } |
| 1404 | |
| 1405 | /** |
| 1406 | * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine |
| 1407 | * @napi: napi struct with our devices info in it |
| 1408 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1409 | * |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1410 | * This function is optimized for cleaning one queue only on a single |
| 1411 | * q_vector!!! |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1412 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1413 | static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget) |
| 1414 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1415 | struct ixgbe_q_vector *q_vector = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1416 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1417 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1418 | struct ixgbe_ring *rx_ring = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1419 | int work_done = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1420 | long r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1421 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1422 | 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] | 1423 | rx_ring = &(adapter->rx_ring[r_idx]); |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1424 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1425 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1426 | ixgbe_update_rx_dca(adapter, rx_ring); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1427 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1428 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1429 | ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1430 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1431 | /* If all Rx work done, exit the polling mode */ |
| 1432 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1433 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1434 | if (adapter->rx_itr_setting & 1) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1435 | ixgbe_set_itr_msix(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1436 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1437 | ixgbe_irq_enable_queues(adapter, |
| 1438 | ((u64)1 << q_vector->v_idx)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1439 | } |
| 1440 | |
| 1441 | return work_done; |
| 1442 | } |
| 1443 | |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1444 | /** |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1445 | * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1446 | * @napi: napi struct with our devices info in it |
| 1447 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1448 | * |
| 1449 | * This function will clean more than one rx queue associated with a |
| 1450 | * q_vector. |
| 1451 | **/ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1452 | static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget) |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1453 | { |
| 1454 | struct ixgbe_q_vector *q_vector = |
| 1455 | container_of(napi, struct ixgbe_q_vector, napi); |
| 1456 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1457 | struct ixgbe_ring *ring = NULL; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1458 | int work_done = 0, i; |
| 1459 | long r_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1460 | bool tx_clean_complete = true; |
| 1461 | |
| 1462 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1463 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1464 | ring = &(adapter->tx_ring[r_idx]); |
| 1465 | #ifdef CONFIG_IXGBE_DCA |
| 1466 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1467 | ixgbe_update_tx_dca(adapter, ring); |
| 1468 | #endif |
| 1469 | tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring); |
| 1470 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
| 1471 | r_idx + 1); |
| 1472 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1473 | |
| 1474 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 1475 | * the budget to go below 1 because we'll exit polling */ |
| 1476 | budget /= (q_vector->rxr_count ?: 1); |
| 1477 | budget = max(budget, 1); |
| 1478 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1479 | for (i = 0; i < q_vector->rxr_count; i++) { |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1480 | ring = &(adapter->rx_ring[r_idx]); |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1481 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1482 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1483 | ixgbe_update_rx_dca(adapter, ring); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1484 | #endif |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1485 | ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1486 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1487 | r_idx + 1); |
| 1488 | } |
| 1489 | |
| 1490 | 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] | 1491 | ring = &(adapter->rx_ring[r_idx]); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1492 | /* If all Rx work done, exit the polling mode */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 1493 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1494 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1495 | if (adapter->rx_itr_setting & 1) |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1496 | ixgbe_set_itr_msix(q_vector); |
| 1497 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1498 | ixgbe_irq_enable_queues(adapter, |
| 1499 | ((u64)1 << q_vector->v_idx)); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1500 | return 0; |
| 1501 | } |
| 1502 | |
| 1503 | return work_done; |
| 1504 | } |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1505 | |
| 1506 | /** |
| 1507 | * ixgbe_clean_txonly - msix (aka one shot) tx clean routine |
| 1508 | * @napi: napi struct with our devices info in it |
| 1509 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1510 | * |
| 1511 | * This function is optimized for cleaning one queue only on a single |
| 1512 | * q_vector!!! |
| 1513 | **/ |
| 1514 | static int ixgbe_clean_txonly(struct napi_struct *napi, int budget) |
| 1515 | { |
| 1516 | struct ixgbe_q_vector *q_vector = |
| 1517 | container_of(napi, struct ixgbe_q_vector, napi); |
| 1518 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1519 | struct ixgbe_ring *tx_ring = NULL; |
| 1520 | int work_done = 0; |
| 1521 | long r_idx; |
| 1522 | |
| 1523 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1524 | tx_ring = &(adapter->tx_ring[r_idx]); |
| 1525 | #ifdef CONFIG_IXGBE_DCA |
| 1526 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1527 | ixgbe_update_tx_dca(adapter, tx_ring); |
| 1528 | #endif |
| 1529 | |
| 1530 | if (!ixgbe_clean_tx_irq(q_vector, tx_ring)) |
| 1531 | work_done = budget; |
| 1532 | |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1533 | /* If all Tx work done, exit the polling mode */ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1534 | if (work_done < budget) { |
| 1535 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1536 | if (adapter->tx_itr_setting & 1) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1537 | ixgbe_set_itr_msix(q_vector); |
| 1538 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1539 | ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 1540 | } |
| 1541 | |
| 1542 | return work_done; |
| 1543 | } |
| 1544 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1545 | 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] | 1546 | int r_idx) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1547 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1548 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
| 1549 | |
| 1550 | set_bit(r_idx, q_vector->rxr_idx); |
| 1551 | q_vector->rxr_count++; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1552 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1553 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1554 | 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] | 1555 | int t_idx) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1556 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1557 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
| 1558 | |
| 1559 | set_bit(t_idx, q_vector->txr_idx); |
| 1560 | q_vector->txr_count++; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1561 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1562 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1563 | /** |
| 1564 | * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors |
| 1565 | * @adapter: board private structure to initialize |
| 1566 | * @vectors: allotted vector count for descriptor rings |
| 1567 | * |
| 1568 | * This function maps descriptor rings to the queue-specific vectors |
| 1569 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 1570 | * one vector per ring/queue, but on a constrained vector budget, we |
| 1571 | * group the rings as "efficiently" as possible. You would add new |
| 1572 | * mapping configurations in here. |
| 1573 | **/ |
| 1574 | static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1575 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1576 | { |
| 1577 | int v_start = 0; |
| 1578 | int rxr_idx = 0, txr_idx = 0; |
| 1579 | int rxr_remaining = adapter->num_rx_queues; |
| 1580 | int txr_remaining = adapter->num_tx_queues; |
| 1581 | int i, j; |
| 1582 | int rqpv, tqpv; |
| 1583 | int err = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1584 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1585 | /* No mapping required if MSI-X is disabled. */ |
| 1586 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1587 | goto out; |
| 1588 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1589 | /* |
| 1590 | * The ideal configuration... |
| 1591 | * We have enough vectors to map one per queue. |
| 1592 | */ |
| 1593 | if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) { |
| 1594 | for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++) |
| 1595 | map_vector_to_rxq(adapter, v_start, rxr_idx); |
| 1596 | |
| 1597 | for (; txr_idx < txr_remaining; v_start++, txr_idx++) |
| 1598 | map_vector_to_txq(adapter, v_start, txr_idx); |
| 1599 | |
| 1600 | goto out; |
| 1601 | } |
| 1602 | |
| 1603 | /* |
| 1604 | * If we don't have enough vectors for a 1-to-1 |
| 1605 | * mapping, we'll have to group them so there are |
| 1606 | * multiple queues per vector. |
| 1607 | */ |
| 1608 | /* Re-adjusting *qpv takes care of the remainder. */ |
| 1609 | for (i = v_start; i < vectors; i++) { |
| 1610 | rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i); |
| 1611 | for (j = 0; j < rqpv; j++) { |
| 1612 | map_vector_to_rxq(adapter, i, rxr_idx); |
| 1613 | rxr_idx++; |
| 1614 | rxr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1615 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1616 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1617 | for (i = v_start; i < vectors; i++) { |
| 1618 | tqpv = DIV_ROUND_UP(txr_remaining, vectors - i); |
| 1619 | for (j = 0; j < tqpv; j++) { |
| 1620 | map_vector_to_txq(adapter, i, txr_idx); |
| 1621 | txr_idx++; |
| 1622 | txr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1623 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1624 | } |
| 1625 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1626 | out: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1627 | return err; |
| 1628 | } |
| 1629 | |
| 1630 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1631 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 1632 | * @adapter: board private structure |
| 1633 | * |
| 1634 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 1635 | * interrupts from the kernel. |
| 1636 | **/ |
| 1637 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 1638 | { |
| 1639 | struct net_device *netdev = adapter->netdev; |
| 1640 | irqreturn_t (*handler)(int, void *); |
| 1641 | int i, vector, q_vectors, err; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 1642 | int ri=0, ti=0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1643 | |
| 1644 | /* Decrement for Other and TCP Timer vectors */ |
| 1645 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1646 | |
| 1647 | /* Map the Tx/Rx rings to the vectors we were allotted. */ |
| 1648 | err = ixgbe_map_rings_to_vectors(adapter, q_vectors); |
| 1649 | if (err) |
| 1650 | goto out; |
| 1651 | |
| 1652 | #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \ |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1653 | (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \ |
| 1654 | &ixgbe_msix_clean_many) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1655 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1656 | handler = SET_HANDLER(adapter->q_vector[vector]); |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 1657 | |
| 1658 | if(handler == &ixgbe_msix_clean_rx) { |
| 1659 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1660 | netdev->name, "rx", ri++); |
| 1661 | } |
| 1662 | else if(handler == &ixgbe_msix_clean_tx) { |
| 1663 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1664 | netdev->name, "tx", ti++); |
| 1665 | } |
| 1666 | else |
| 1667 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1668 | netdev->name, "TxRx", vector); |
| 1669 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1670 | err = request_irq(adapter->msix_entries[vector].vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1671 | handler, 0, adapter->name[vector], |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1672 | adapter->q_vector[vector]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1673 | if (err) { |
| 1674 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1675 | "request_irq failed for MSIX interrupt " |
| 1676 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1677 | goto free_queue_irqs; |
| 1678 | } |
| 1679 | } |
| 1680 | |
| 1681 | sprintf(adapter->name[vector], "%s:lsc", netdev->name); |
| 1682 | err = request_irq(adapter->msix_entries[vector].vector, |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1683 | ixgbe_msix_lsc, 0, adapter->name[vector], netdev); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1684 | if (err) { |
| 1685 | DPRINTK(PROBE, ERR, |
| 1686 | "request_irq for msix_lsc failed: %d\n", err); |
| 1687 | goto free_queue_irqs; |
| 1688 | } |
| 1689 | |
| 1690 | return 0; |
| 1691 | |
| 1692 | free_queue_irqs: |
| 1693 | for (i = vector - 1; i >= 0; i--) |
| 1694 | free_irq(adapter->msix_entries[--vector].vector, |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1695 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1696 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 1697 | pci_disable_msix(adapter->pdev); |
| 1698 | kfree(adapter->msix_entries); |
| 1699 | adapter->msix_entries = NULL; |
| 1700 | out: |
| 1701 | return err; |
| 1702 | } |
| 1703 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1704 | static void ixgbe_set_itr(struct ixgbe_adapter *adapter) |
| 1705 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1706 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1707 | u8 current_itr; |
| 1708 | u32 new_itr = q_vector->eitr; |
| 1709 | struct ixgbe_ring *rx_ring = &adapter->rx_ring[0]; |
| 1710 | struct ixgbe_ring *tx_ring = &adapter->tx_ring[0]; |
| 1711 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1712 | q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1713 | q_vector->tx_itr, |
| 1714 | tx_ring->total_packets, |
| 1715 | tx_ring->total_bytes); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1716 | q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1717 | q_vector->rx_itr, |
| 1718 | rx_ring->total_packets, |
| 1719 | rx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1720 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1721 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1722 | |
| 1723 | switch (current_itr) { |
| 1724 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1725 | case lowest_latency: |
| 1726 | new_itr = 100000; |
| 1727 | break; |
| 1728 | case low_latency: |
| 1729 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 1730 | break; |
| 1731 | case bulk_latency: |
| 1732 | new_itr = 8000; |
| 1733 | break; |
| 1734 | default: |
| 1735 | break; |
| 1736 | } |
| 1737 | |
| 1738 | if (new_itr != q_vector->eitr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1739 | /* do an exponential smoothing */ |
| 1740 | new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1741 | |
| 1742 | /* save the algorithm value here, not the smoothed one */ |
| 1743 | q_vector->eitr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1744 | |
| 1745 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | return; |
| 1749 | } |
| 1750 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1751 | /** |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1752 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 1753 | * @adapter: board private structure |
| 1754 | **/ |
| 1755 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter) |
| 1756 | { |
| 1757 | u32 mask; |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1758 | |
| 1759 | mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
David S. Miller | 6ab33d5 | 2008-11-20 16:44:00 -0800 | [diff] [blame] | 1760 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
| 1761 | mask |= IXGBE_EIMS_GPI_SDP1; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1762 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 1763 | mask |= IXGBE_EIMS_ECC; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1764 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 1765 | mask |= IXGBE_EIMS_GPI_SDP2; |
| 1766 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1767 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 1768 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 1769 | mask |= IXGBE_EIMS_FLOW_DIR; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1770 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1771 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1772 | ixgbe_irq_enable_queues(adapter, ~0); |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1773 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 1774 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1775 | |
| 1776 | /** |
| 1777 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1778 | * @irq: interrupt number |
| 1779 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1780 | **/ |
| 1781 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 1782 | { |
| 1783 | struct net_device *netdev = data; |
| 1784 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1785 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1786 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1787 | u32 eicr; |
| 1788 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 1789 | /* |
| 1790 | * Workaround for silicon errata. Mask the interrupts |
| 1791 | * before the read of EICR. |
| 1792 | */ |
| 1793 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 1794 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1795 | /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read |
| 1796 | * therefore no explict interrupt disable is necessary */ |
| 1797 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 1798 | if (!eicr) { |
| 1799 | /* shared interrupt alert! |
| 1800 | * make sure interrupts are enabled because the read will |
| 1801 | * have disabled interrupts due to EIAM */ |
| 1802 | ixgbe_irq_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1803 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 1804 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1805 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1806 | if (eicr & IXGBE_EICR_LSC) |
| 1807 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1808 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1809 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 1810 | ixgbe_check_sfp_event(adapter, eicr); |
| 1811 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1812 | ixgbe_check_fan_failure(adapter, eicr); |
| 1813 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1814 | if (napi_schedule_prep(&(q_vector->napi))) { |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1815 | adapter->tx_ring[0].total_packets = 0; |
| 1816 | adapter->tx_ring[0].total_bytes = 0; |
| 1817 | adapter->rx_ring[0].total_packets = 0; |
| 1818 | adapter->rx_ring[0].total_bytes = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1819 | /* would disable interrupts here but EIAM disabled it */ |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1820 | __napi_schedule(&(q_vector->napi)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1821 | } |
| 1822 | |
| 1823 | return IRQ_HANDLED; |
| 1824 | } |
| 1825 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1826 | static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter) |
| 1827 | { |
| 1828 | int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1829 | |
| 1830 | for (i = 0; i < q_vectors; i++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1831 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1832 | bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES); |
| 1833 | bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES); |
| 1834 | q_vector->rxr_count = 0; |
| 1835 | q_vector->txr_count = 0; |
| 1836 | } |
| 1837 | } |
| 1838 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1839 | /** |
| 1840 | * ixgbe_request_irq - initialize interrupts |
| 1841 | * @adapter: board private structure |
| 1842 | * |
| 1843 | * Attempts to configure interrupts using the best available |
| 1844 | * capabilities of the hardware and kernel. |
| 1845 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1846 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1847 | { |
| 1848 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1849 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1850 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1851 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 1852 | err = ixgbe_request_msix_irqs(adapter); |
| 1853 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1854 | err = request_irq(adapter->pdev->irq, ixgbe_intr, 0, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1855 | netdev->name, netdev); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1856 | } else { |
Joe Perches | a0607fd | 2009-11-18 23:29:17 -0800 | [diff] [blame] | 1857 | err = request_irq(adapter->pdev->irq, ixgbe_intr, IRQF_SHARED, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1858 | netdev->name, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1859 | } |
| 1860 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1861 | if (err) |
| 1862 | DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err); |
| 1863 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1864 | return err; |
| 1865 | } |
| 1866 | |
| 1867 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 1868 | { |
| 1869 | struct net_device *netdev = adapter->netdev; |
| 1870 | |
| 1871 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1872 | int i, q_vectors; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1873 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1874 | q_vectors = adapter->num_msix_vectors; |
| 1875 | |
| 1876 | i = q_vectors - 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1877 | free_irq(adapter->msix_entries[i].vector, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1878 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1879 | i--; |
| 1880 | for (; i >= 0; i--) { |
| 1881 | free_irq(adapter->msix_entries[i].vector, |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1882 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1883 | } |
| 1884 | |
| 1885 | ixgbe_reset_q_vectors(adapter); |
| 1886 | } else { |
| 1887 | free_irq(adapter->pdev->irq, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1888 | } |
| 1889 | } |
| 1890 | |
| 1891 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1892 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 1893 | * @adapter: board private structure |
| 1894 | **/ |
| 1895 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 1896 | { |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1897 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1898 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
| 1899 | } else { |
| 1900 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 1901 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1902 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1903 | } |
| 1904 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 1905 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 1906 | int i; |
| 1907 | for (i = 0; i < adapter->num_msix_vectors; i++) |
| 1908 | synchronize_irq(adapter->msix_entries[i].vector); |
| 1909 | } else { |
| 1910 | synchronize_irq(adapter->pdev->irq); |
| 1911 | } |
| 1912 | } |
| 1913 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1914 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1915 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 1916 | * |
| 1917 | **/ |
| 1918 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 1919 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1920 | struct ixgbe_hw *hw = &adapter->hw; |
| 1921 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1922 | IXGBE_WRITE_REG(hw, IXGBE_EITR(0), |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 1923 | EITR_INTS_PER_SEC_TO_REG(adapter->rx_eitr_param)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1924 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1925 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 1926 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1927 | |
| 1928 | map_vector_to_rxq(adapter, 0, 0); |
| 1929 | map_vector_to_txq(adapter, 0, 0); |
| 1930 | |
| 1931 | DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1932 | } |
| 1933 | |
| 1934 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1935 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1936 | * @adapter: board private structure |
| 1937 | * |
| 1938 | * Configure the Tx unit of the MAC after a reset. |
| 1939 | **/ |
| 1940 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 1941 | { |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1942 | u64 tdba; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1943 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1944 | u32 i, j, tdlen, txctrl; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1945 | |
| 1946 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 1947 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1948 | struct ixgbe_ring *ring = &adapter->tx_ring[i]; |
| 1949 | j = ring->reg_idx; |
| 1950 | tdba = ring->dma; |
| 1951 | tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1952 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j), |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1953 | (tdba & DMA_BIT_MASK(32))); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1954 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32)); |
| 1955 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen); |
| 1956 | IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0); |
| 1957 | IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0); |
| 1958 | adapter->tx_ring[i].head = IXGBE_TDH(j); |
| 1959 | adapter->tx_ring[i].tail = IXGBE_TDT(j); |
Peter P Waskiewicz Jr | 84f62d4 | 2009-09-30 12:07:16 +0000 | [diff] [blame] | 1960 | /* |
| 1961 | * Disable Tx Head Writeback RO bit, since this hoses |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1962 | * bookkeeping if things aren't delivered in order. |
| 1963 | */ |
Peter P Waskiewicz Jr | 84f62d4 | 2009-09-30 12:07:16 +0000 | [diff] [blame] | 1964 | switch (hw->mac.type) { |
| 1965 | case ixgbe_mac_82598EB: |
| 1966 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j)); |
| 1967 | break; |
| 1968 | case ixgbe_mac_82599EB: |
| 1969 | default: |
| 1970 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL_82599(j)); |
| 1971 | break; |
| 1972 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1973 | txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN; |
Peter P Waskiewicz Jr | 84f62d4 | 2009-09-30 12:07:16 +0000 | [diff] [blame] | 1974 | switch (hw->mac.type) { |
| 1975 | case ixgbe_mac_82598EB: |
| 1976 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl); |
| 1977 | break; |
| 1978 | case ixgbe_mac_82599EB: |
| 1979 | default: |
| 1980 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL_82599(j), txctrl); |
| 1981 | break; |
| 1982 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1983 | } |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 1984 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1985 | if (hw->mac.type == ixgbe_mac_82599EB) { |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 1986 | u32 rttdcs; |
| 1987 | |
| 1988 | /* disable the arbiter while setting MTQC */ |
| 1989 | rttdcs = IXGBE_READ_REG(hw, IXGBE_RTTDCS); |
| 1990 | rttdcs |= IXGBE_RTTDCS_ARBDIS; |
| 1991 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
| 1992 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1993 | /* We enable 8 traffic classes, DCB only */ |
| 1994 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 1995 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA | |
| 1996 | IXGBE_MTQC_8TC_8TQ)); |
Don Skidmore | ee5f784 | 2009-11-06 12:56:20 +0000 | [diff] [blame] | 1997 | else |
| 1998 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, IXGBE_MTQC_64Q_1PB); |
| 1999 | |
| 2000 | /* re-eable the arbiter */ |
| 2001 | rttdcs &= ~IXGBE_RTTDCS_ARBDIS; |
| 2002 | IXGBE_WRITE_REG(hw, IXGBE_RTTDCS, rttdcs); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2003 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2004 | } |
| 2005 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2006 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2007 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2008 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, |
| 2009 | struct ixgbe_ring *rx_ring) |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2010 | { |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2011 | u32 srrctl; |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2012 | int index; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2013 | struct ixgbe_ring_feature *feature = adapter->ring_feature; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2014 | |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2015 | index = rx_ring->reg_idx; |
| 2016 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 2017 | unsigned long mask; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2018 | mask = (unsigned long) feature[RING_F_RSS].mask; |
Alexander Duyck | 3be1adf | 2008-08-30 00:29:10 -0700 | [diff] [blame] | 2019 | index = index & mask; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2020 | } |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2021 | srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index)); |
| 2022 | |
| 2023 | srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2024 | srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK; |
| 2025 | |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2026 | srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) & |
| 2027 | IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 2028 | |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 2029 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2030 | #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER |
| 2031 | srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 2032 | #else |
| 2033 | srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 2034 | #endif |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2035 | srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2036 | } else { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 2037 | srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >> |
| 2038 | IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2039 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2040 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2041 | |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2042 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl); |
| 2043 | } |
| 2044 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2045 | static u32 ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
| 2046 | { |
| 2047 | u32 mrqc = 0; |
| 2048 | int mask; |
| 2049 | |
| 2050 | if (!(adapter->hw.mac.type == ixgbe_mac_82599EB)) |
| 2051 | return mrqc; |
| 2052 | |
| 2053 | mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED |
| 2054 | #ifdef CONFIG_IXGBE_DCB |
| 2055 | | IXGBE_FLAG_DCB_ENABLED |
| 2056 | #endif |
| 2057 | ); |
| 2058 | |
| 2059 | switch (mask) { |
| 2060 | case (IXGBE_FLAG_RSS_ENABLED): |
| 2061 | mrqc = IXGBE_MRQC_RSSEN; |
| 2062 | break; |
| 2063 | #ifdef CONFIG_IXGBE_DCB |
| 2064 | case (IXGBE_FLAG_DCB_ENABLED): |
| 2065 | mrqc = IXGBE_MRQC_RT8TCEN; |
| 2066 | break; |
| 2067 | #endif /* CONFIG_IXGBE_DCB */ |
| 2068 | default: |
| 2069 | break; |
| 2070 | } |
| 2071 | |
| 2072 | return mrqc; |
| 2073 | } |
| 2074 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2075 | /** |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2076 | * ixgbe_configure_rscctl - enable RSC for the indicated ring |
| 2077 | * @adapter: address of board private structure |
| 2078 | * @index: index of ring to set |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2079 | **/ |
Mallikarjuna R Chilakala | edd2ea5 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2080 | static void ixgbe_configure_rscctl(struct ixgbe_adapter *adapter, int index) |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2081 | { |
| 2082 | struct ixgbe_ring *rx_ring; |
| 2083 | struct ixgbe_hw *hw = &adapter->hw; |
| 2084 | int j; |
| 2085 | u32 rscctrl; |
Mallikarjuna R Chilakala | edd2ea5 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2086 | int rx_buf_len; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2087 | |
| 2088 | rx_ring = &adapter->rx_ring[index]; |
| 2089 | j = rx_ring->reg_idx; |
Mallikarjuna R Chilakala | edd2ea5 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2090 | rx_buf_len = rx_ring->rx_buf_len; |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2091 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(j)); |
| 2092 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 2093 | /* |
| 2094 | * we must limit the number of descriptors so that the |
| 2095 | * total size of max desc * buf_len is not greater |
| 2096 | * than 65535 |
| 2097 | */ |
| 2098 | if (rx_ring->flags & IXGBE_RING_RX_PS_ENABLED) { |
| 2099 | #if (MAX_SKB_FRAGS > 16) |
| 2100 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2101 | #elif (MAX_SKB_FRAGS > 8) |
| 2102 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
| 2103 | #elif (MAX_SKB_FRAGS > 4) |
| 2104 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
| 2105 | #else |
| 2106 | rscctrl |= IXGBE_RSCCTL_MAXDESC_1; |
| 2107 | #endif |
| 2108 | } else { |
| 2109 | if (rx_buf_len < IXGBE_RXBUFFER_4096) |
| 2110 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2111 | else if (rx_buf_len < IXGBE_RXBUFFER_8192) |
| 2112 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
| 2113 | else |
| 2114 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
| 2115 | } |
| 2116 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(j), rscctrl); |
| 2117 | } |
| 2118 | |
| 2119 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 2120 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2121 | * @adapter: board private structure |
| 2122 | * |
| 2123 | * Configure the Rx unit of the MAC after a reset. |
| 2124 | **/ |
| 2125 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 2126 | { |
| 2127 | u64 rdba; |
| 2128 | struct ixgbe_hw *hw = &adapter->hw; |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2129 | struct ixgbe_ring *rx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2130 | struct net_device *netdev = adapter->netdev; |
| 2131 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2132 | int i, j; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2133 | u32 rdlen, rxctrl, rxcsum; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2134 | static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D, |
| 2135 | 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE, |
| 2136 | 0x6A3E67EA, 0x14364D17, 0x3BED200D}; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2137 | u32 fctrl, hlreg0; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2138 | u32 reta = 0, mrqc = 0; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2139 | u32 rdrxctl; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2140 | int rx_buf_len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2141 | |
| 2142 | /* Decide whether to use packet split mode or not */ |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 2143 | adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2144 | |
| 2145 | /* Set the RX buffer length according to the mode */ |
| 2146 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2147 | rx_buf_len = IXGBE_RX_HDR_SIZE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2148 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2149 | /* PSRTYPE must be initialized in 82599 */ |
| 2150 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
| 2151 | IXGBE_PSRTYPE_UDPHDR | |
| 2152 | IXGBE_PSRTYPE_IPV4HDR | |
Yi Zou | dfa12f0 | 2009-05-07 10:39:35 +0000 | [diff] [blame] | 2153 | IXGBE_PSRTYPE_IPV6HDR | |
| 2154 | IXGBE_PSRTYPE_L2HDR; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2155 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype); |
| 2156 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2157 | } else { |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 2158 | if (!(adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) && |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2159 | (netdev->mtu <= ETH_DATA_LEN)) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2160 | rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2161 | else |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2162 | rx_buf_len = ALIGN(max_frame, 1024); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2163 | } |
| 2164 | |
| 2165 | fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL); |
| 2166 | fctrl |= IXGBE_FCTRL_BAM; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2167 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2168 | fctrl |= IXGBE_FCTRL_PMCF; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2169 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl); |
| 2170 | |
| 2171 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
| 2172 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 2173 | hlreg0 &= ~IXGBE_HLREG0_JUMBOEN; |
| 2174 | else |
| 2175 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2176 | #ifdef IXGBE_FCOE |
Yi Zou | f34c5c8 | 2009-08-14 12:42:17 +0000 | [diff] [blame] | 2177 | if (netdev->features & NETIF_F_FCOE_MTU) |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2178 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
| 2179 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2180 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 2181 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2182 | rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc); |
| 2183 | /* disable receives while setting up the descriptors */ |
| 2184 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 2185 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
| 2186 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2187 | /* |
| 2188 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 2189 | * the Base and Length of the Rx Descriptor Ring |
| 2190 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2191 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2192 | rx_ring = &adapter->rx_ring[i]; |
| 2193 | rdba = rx_ring->dma; |
| 2194 | j = rx_ring->reg_idx; |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2195 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_BIT_MASK(32))); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2196 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32)); |
| 2197 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen); |
| 2198 | IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0); |
| 2199 | IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0); |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2200 | rx_ring->head = IXGBE_RDH(j); |
| 2201 | rx_ring->tail = IXGBE_RDT(j); |
| 2202 | rx_ring->rx_buf_len = rx_buf_len; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2203 | |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 2204 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) |
| 2205 | rx_ring->flags |= IXGBE_RING_RX_PS_ENABLED; |
Peter P Waskiewicz Jr | 1b3ff02 | 2009-09-14 07:47:27 +0000 | [diff] [blame] | 2206 | else |
| 2207 | rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2208 | |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2209 | #ifdef IXGBE_FCOE |
Yi Zou | f34c5c8 | 2009-08-14 12:42:17 +0000 | [diff] [blame] | 2210 | if (netdev->features & NETIF_F_FCOE_MTU) { |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2211 | struct ixgbe_ring_feature *f; |
| 2212 | f = &adapter->ring_feature[RING_F_FCOE]; |
Yi Zou | 6e455b89 | 2009-08-06 13:05:44 +0000 | [diff] [blame] | 2213 | if ((i >= f->mask) && (i < f->mask + f->indices)) { |
| 2214 | rx_ring->flags &= ~IXGBE_RING_RX_PS_ENABLED; |
| 2215 | if (rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE) |
| 2216 | rx_ring->rx_buf_len = |
| 2217 | IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 2218 | } |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2219 | } |
| 2220 | |
| 2221 | #endif /* IXGBE_FCOE */ |
Yi Zou | a6616b4 | 2009-08-06 13:05:23 +0000 | [diff] [blame] | 2222 | ixgbe_configure_srrctl(adapter, rx_ring); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2223 | } |
| 2224 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2225 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 2226 | /* |
| 2227 | * For VMDq support of different descriptor types or |
| 2228 | * buffer sizes through the use of multiple SRRCTL |
| 2229 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 2230 | * |
| 2231 | * also, the manual doesn't mention it clearly but DCA hints |
| 2232 | * will only use queue 0's tags unless this bit is set. Side |
| 2233 | * effects of setting this bit are only that SRRCTL must be |
| 2234 | * fully programmed [0..15] |
| 2235 | */ |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2236 | rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 2237 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 2238 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2239 | } |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2240 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2241 | /* Program MRQC for the distribution of queues */ |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2242 | mrqc = ixgbe_setup_mrqc(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2243 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2244 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2245 | /* Fill out redirection table */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2246 | for (i = 0, j = 0; i < 128; i++, j++) { |
| 2247 | if (j == adapter->ring_feature[RING_F_RSS].indices) |
| 2248 | j = 0; |
| 2249 | /* reta = 4-byte sliding window of |
| 2250 | * 0x00..(indices-1)(indices-1)00..etc. */ |
| 2251 | reta = (reta << 8) | (j * 0x11); |
| 2252 | if ((i & 3) == 3) |
| 2253 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2254 | } |
| 2255 | |
| 2256 | /* Fill out hash function seeds */ |
| 2257 | for (i = 0; i < 10; i++) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2258 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2259 | |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2260 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2261 | mrqc |= IXGBE_MRQC_RSSEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2262 | /* Perform hash on these packet types */ |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2263 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
| 2264 | | IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
| 2265 | | IXGBE_MRQC_RSS_FIELD_IPV4_UDP |
| 2266 | | IXGBE_MRQC_RSS_FIELD_IPV6 |
| 2267 | | IXGBE_MRQC_RSS_FIELD_IPV6_TCP |
| 2268 | | IXGBE_MRQC_RSS_FIELD_IPV6_UDP; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2269 | } |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2270 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2271 | |
| 2272 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 2273 | |
| 2274 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED || |
| 2275 | adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) { |
| 2276 | /* Disable indicating checksum in descriptor, enables |
| 2277 | * RSS hash */ |
| 2278 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 2279 | } |
| 2280 | if (!(rxcsum & IXGBE_RXCSUM_PCSD)) { |
| 2281 | /* Enable IPv4 payload checksum for UDP fragments |
| 2282 | * if PCSD is not set */ |
| 2283 | rxcsum |= IXGBE_RXCSUM_IPPCSE; |
| 2284 | } |
| 2285 | |
| 2286 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2287 | |
| 2288 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2289 | rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 2290 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2291 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2292 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 2293 | } |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2294 | |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 2295 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2296 | /* Enable 82599 HW-RSC */ |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2297 | for (i = 0; i < adapter->num_rx_queues; i++) |
Mallikarjuna R Chilakala | edd2ea5 | 2009-11-23 10:45:11 -0800 | [diff] [blame] | 2298 | ixgbe_configure_rscctl(adapter, i); |
Nelson, Shannon | bb5a9ad | 2009-09-18 09:46:27 +0000 | [diff] [blame] | 2299 | |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2300 | /* Disable RSC for ACK packets */ |
| 2301 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 2302 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 2303 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2304 | } |
| 2305 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2306 | static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 2307 | { |
| 2308 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2309 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2310 | |
| 2311 | /* add VID to filter table */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2312 | hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2313 | } |
| 2314 | |
| 2315 | static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 2316 | { |
| 2317 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2318 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2319 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2320 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2321 | ixgbe_irq_disable(adapter); |
| 2322 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2323 | vlan_group_set_device(adapter->vlgrp, vid, NULL); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2324 | |
| 2325 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2326 | ixgbe_irq_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2327 | |
| 2328 | /* remove VID from filter table */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2329 | hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2330 | } |
| 2331 | |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2332 | static void ixgbe_vlan_rx_register(struct net_device *netdev, |
| 2333 | struct vlan_group *grp) |
| 2334 | { |
| 2335 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2336 | u32 ctrl; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2337 | int i, j; |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2338 | |
| 2339 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2340 | ixgbe_irq_disable(adapter); |
| 2341 | adapter->vlgrp = grp; |
| 2342 | |
| 2343 | /* |
| 2344 | * For a DCB driver, always enable VLAN tag stripping so we can |
| 2345 | * still receive traffic from a DCB-enabled host even if we're |
| 2346 | * not in DCB mode. |
| 2347 | */ |
| 2348 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL); |
Alexander Duyck | dc63d37 | 2009-11-23 06:32:57 +0000 | [diff] [blame] | 2349 | |
| 2350 | /* Disable CFI check */ |
| 2351 | ctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2352 | |
| 2353 | /* enable VLAN tag stripping */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2354 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | dc63d37 | 2009-11-23 06:32:57 +0000 | [diff] [blame] | 2355 | ctrl |= IXGBE_VLNCTRL_VME; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2356 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2357 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | dc63d37 | 2009-11-23 06:32:57 +0000 | [diff] [blame] | 2358 | u32 ctrl; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2359 | j = adapter->rx_ring[i].reg_idx; |
| 2360 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j)); |
| 2361 | ctrl |= IXGBE_RXDCTL_VME; |
| 2362 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl); |
| 2363 | } |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2364 | } |
Alexander Duyck | dc63d37 | 2009-11-23 06:32:57 +0000 | [diff] [blame] | 2365 | |
| 2366 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl); |
| 2367 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2368 | ixgbe_vlan_rx_add_vid(netdev, 0); |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2369 | |
| 2370 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2371 | ixgbe_irq_enable(adapter); |
| 2372 | } |
| 2373 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2374 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 2375 | { |
| 2376 | ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 2377 | |
| 2378 | if (adapter->vlgrp) { |
| 2379 | u16 vid; |
| 2380 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
| 2381 | if (!vlan_group_get_device(adapter->vlgrp, vid)) |
| 2382 | continue; |
| 2383 | ixgbe_vlan_rx_add_vid(adapter->netdev, vid); |
| 2384 | } |
| 2385 | } |
| 2386 | } |
| 2387 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2388 | static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq) |
| 2389 | { |
| 2390 | struct dev_mc_list *mc_ptr; |
| 2391 | u8 *addr = *mc_addr_ptr; |
| 2392 | *vmdq = 0; |
| 2393 | |
| 2394 | mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]); |
| 2395 | if (mc_ptr->next) |
| 2396 | *mc_addr_ptr = mc_ptr->next->dmi_addr; |
| 2397 | else |
| 2398 | *mc_addr_ptr = NULL; |
| 2399 | |
| 2400 | return addr; |
| 2401 | } |
| 2402 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2403 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2404 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2405 | * @netdev: network interface device structure |
| 2406 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2407 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 2408 | * address list or the network interface flags are updated. This routine is |
| 2409 | * responsible for configuring the hardware for proper unicast, multicast and |
| 2410 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2411 | **/ |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2412 | static void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2413 | { |
| 2414 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2415 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2416 | u32 fctrl, vlnctrl; |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2417 | u8 *addr_list = NULL; |
| 2418 | int addr_count = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2419 | |
| 2420 | /* Check for Promiscuous and All Multicast modes */ |
| 2421 | |
| 2422 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2423 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2424 | |
| 2425 | if (netdev->flags & IFF_PROMISC) { |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2426 | hw->addr_ctrl.user_set_promisc = 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2427 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2428 | vlnctrl &= ~IXGBE_VLNCTRL_VFE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2429 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2430 | if (netdev->flags & IFF_ALLMULTI) { |
| 2431 | fctrl |= IXGBE_FCTRL_MPE; |
| 2432 | fctrl &= ~IXGBE_FCTRL_UPE; |
| 2433 | } else { |
| 2434 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
| 2435 | } |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2436 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2437 | hw->addr_ctrl.user_set_promisc = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2438 | } |
| 2439 | |
| 2440 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2441 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2442 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2443 | /* reprogram secondary unicast list */ |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 2444 | hw->mac.ops.update_uc_addr_list(hw, &netdev->uc.list); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2445 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2446 | /* reprogram multicast list */ |
| 2447 | addr_count = netdev->mc_count; |
| 2448 | if (addr_count) |
| 2449 | addr_list = netdev->mc_list->dmi_addr; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2450 | hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count, |
| 2451 | ixgbe_addr_list_itr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2452 | } |
| 2453 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2454 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 2455 | { |
| 2456 | int q_idx; |
| 2457 | struct ixgbe_q_vector *q_vector; |
| 2458 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2459 | |
| 2460 | /* legacy and MSI only use one vector */ |
| 2461 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 2462 | q_vectors = 1; |
| 2463 | |
| 2464 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2465 | struct napi_struct *napi; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2466 | q_vector = adapter->q_vector[q_idx]; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2467 | napi = &q_vector->napi; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2468 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2469 | if (!q_vector->rxr_count || !q_vector->txr_count) { |
| 2470 | if (q_vector->txr_count == 1) |
| 2471 | napi->poll = &ixgbe_clean_txonly; |
| 2472 | else if (q_vector->rxr_count == 1) |
| 2473 | napi->poll = &ixgbe_clean_rxonly; |
| 2474 | } |
| 2475 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2476 | |
| 2477 | napi_enable(napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2478 | } |
| 2479 | } |
| 2480 | |
| 2481 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 2482 | { |
| 2483 | int q_idx; |
| 2484 | struct ixgbe_q_vector *q_vector; |
| 2485 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2486 | |
| 2487 | /* legacy and MSI only use one vector */ |
| 2488 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 2489 | q_vectors = 1; |
| 2490 | |
| 2491 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2492 | q_vector = adapter->q_vector[q_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2493 | napi_disable(&q_vector->napi); |
| 2494 | } |
| 2495 | } |
| 2496 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 2497 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2498 | /* |
| 2499 | * ixgbe_configure_dcb - Configure DCB hardware |
| 2500 | * @adapter: ixgbe adapter struct |
| 2501 | * |
| 2502 | * This is called by the driver on open to configure the DCB hardware. |
| 2503 | * This is also called by the gennetlink interface when reconfiguring |
| 2504 | * the DCB state. |
| 2505 | */ |
| 2506 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 2507 | { |
| 2508 | struct ixgbe_hw *hw = &adapter->hw; |
| 2509 | u32 txdctl, vlnctrl; |
| 2510 | int i, j; |
| 2511 | |
| 2512 | ixgbe_dcb_check_config(&adapter->dcb_cfg); |
| 2513 | ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG); |
| 2514 | ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG); |
| 2515 | |
| 2516 | /* reconfigure the hardware */ |
| 2517 | ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg); |
| 2518 | |
| 2519 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2520 | j = adapter->tx_ring[i].reg_idx; |
| 2521 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
| 2522 | /* PThresh workaround for Tx hang with DFP enabled. */ |
| 2523 | txdctl |= 32; |
| 2524 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
| 2525 | } |
| 2526 | /* Enable VLAN tag insert/strip */ |
| 2527 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2528 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 2529 | vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE; |
| 2530 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2531 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 2532 | } else if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2533 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 2534 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2535 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 2536 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 2537 | j = adapter->rx_ring[i].reg_idx; |
| 2538 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 2539 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 2540 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 2541 | } |
| 2542 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2543 | hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true); |
| 2544 | } |
| 2545 | |
| 2546 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2547 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 2548 | { |
| 2549 | struct net_device *netdev = adapter->netdev; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2550 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2551 | int i; |
| 2552 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2553 | ixgbe_set_rx_mode(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2554 | |
| 2555 | ixgbe_restore_vlan(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 2556 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2557 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Yi Zou | b352e40 | 2009-11-06 12:55:38 +0000 | [diff] [blame] | 2558 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2559 | netif_set_gso_max_size(netdev, 32768); |
| 2560 | else |
| 2561 | netif_set_gso_max_size(netdev, 65536); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2562 | ixgbe_configure_dcb(adapter); |
| 2563 | } else { |
| 2564 | netif_set_gso_max_size(netdev, 65536); |
| 2565 | } |
| 2566 | #else |
| 2567 | netif_set_gso_max_size(netdev, 65536); |
| 2568 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2569 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 2570 | #ifdef IXGBE_FCOE |
| 2571 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 2572 | ixgbe_configure_fcoe(adapter); |
| 2573 | |
| 2574 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2575 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 2576 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2577 | adapter->tx_ring[i].atr_sample_rate = |
| 2578 | adapter->atr_sample_rate; |
| 2579 | ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc); |
| 2580 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 2581 | ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc); |
| 2582 | } |
| 2583 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2584 | ixgbe_configure_tx(adapter); |
| 2585 | ixgbe_configure_rx(adapter); |
| 2586 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 2587 | ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i], |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2588 | (adapter->rx_ring[i].count - 1)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2589 | } |
| 2590 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2591 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 2592 | { |
| 2593 | switch (hw->phy.type) { |
| 2594 | case ixgbe_phy_sfp_avago: |
| 2595 | case ixgbe_phy_sfp_ftl: |
| 2596 | case ixgbe_phy_sfp_intel: |
| 2597 | case ixgbe_phy_sfp_unknown: |
| 2598 | case ixgbe_phy_tw_tyco: |
| 2599 | case ixgbe_phy_tw_unknown: |
| 2600 | return true; |
| 2601 | default: |
| 2602 | return false; |
| 2603 | } |
| 2604 | } |
| 2605 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2606 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2607 | * ixgbe_sfp_link_config - set up SFP+ link |
| 2608 | * @adapter: pointer to private adapter struct |
| 2609 | **/ |
| 2610 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 2611 | { |
| 2612 | struct ixgbe_hw *hw = &adapter->hw; |
| 2613 | |
| 2614 | if (hw->phy.multispeed_fiber) { |
| 2615 | /* |
| 2616 | * In multispeed fiber setups, the device may not have |
| 2617 | * had a physical connection when the driver loaded. |
| 2618 | * If that's the case, the initial link configuration |
| 2619 | * couldn't get the MAC into 10G or 1G mode, so we'll |
| 2620 | * never have a link status change interrupt fire. |
| 2621 | * We need to try and force an autonegotiation |
| 2622 | * session, then bring up link. |
| 2623 | */ |
| 2624 | hw->mac.ops.setup_sfp(hw); |
| 2625 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK)) |
| 2626 | schedule_work(&adapter->multispeed_fiber_task); |
| 2627 | } else { |
| 2628 | /* |
| 2629 | * Direct Attach Cu and non-multispeed fiber modules |
| 2630 | * still need to be configured properly prior to |
| 2631 | * attempting link. |
| 2632 | */ |
| 2633 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK)) |
| 2634 | schedule_work(&adapter->sfp_config_module_task); |
| 2635 | } |
| 2636 | } |
| 2637 | |
| 2638 | /** |
| 2639 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2640 | * @hw: pointer to private hardware struct |
| 2641 | * |
| 2642 | * Returns 0 on success, negative on failure |
| 2643 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2644 | 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] | 2645 | { |
| 2646 | u32 autoneg; |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 2647 | bool negotiation, link_up = false; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2648 | u32 ret = IXGBE_ERR_LINK_SETUP; |
| 2649 | |
| 2650 | if (hw->mac.ops.check_link) |
| 2651 | ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 2652 | |
| 2653 | if (ret) |
| 2654 | goto link_cfg_out; |
| 2655 | |
| 2656 | if (hw->mac.ops.get_link_capabilities) |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 2657 | ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2658 | if (ret) |
| 2659 | goto link_cfg_out; |
| 2660 | |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 2661 | if (hw->mac.ops.setup_link) |
| 2662 | 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] | 2663 | link_cfg_out: |
| 2664 | return ret; |
| 2665 | } |
| 2666 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2667 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 2668 | static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 2669 | int rxr) |
| 2670 | { |
| 2671 | int j = adapter->rx_ring[rxr].reg_idx; |
| 2672 | int k; |
| 2673 | |
| 2674 | for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) { |
| 2675 | if (IXGBE_READ_REG(&adapter->hw, |
| 2676 | IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE) |
| 2677 | break; |
| 2678 | else |
| 2679 | msleep(1); |
| 2680 | } |
| 2681 | if (k >= IXGBE_MAX_RX_DESC_POLL) { |
| 2682 | DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d " |
| 2683 | "not set within the polling period\n", rxr); |
| 2684 | } |
| 2685 | ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr], |
| 2686 | (adapter->rx_ring[rxr].count - 1)); |
| 2687 | } |
| 2688 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2689 | static int ixgbe_up_complete(struct ixgbe_adapter *adapter) |
| 2690 | { |
| 2691 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2692 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2693 | int i, j = 0; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2694 | int num_rx_rings = adapter->num_rx_queues; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2695 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2696 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2697 | u32 txdctl, rxdctl, mhadd; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2698 | u32 dmatxctl; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2699 | u32 gpie; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2700 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 2701 | ixgbe_get_hw_control(adapter); |
| 2702 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2703 | if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) || |
| 2704 | (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2705 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2706 | gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2707 | IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2708 | } else { |
| 2709 | /* MSI only */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2710 | gpie = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2711 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2712 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 2713 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 2714 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2715 | } |
| 2716 | |
Jesse Brandeburg | 9b47144 | 2009-12-03 11:33:54 +0000 | [diff] [blame] | 2717 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2718 | /* |
| 2719 | * use EIAM to auto-mask when MSI-X interrupt is asserted |
| 2720 | * this saves a register write for every interrupt |
| 2721 | */ |
| 2722 | switch (hw->mac.type) { |
| 2723 | case ixgbe_mac_82598EB: |
| 2724 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
| 2725 | break; |
| 2726 | default: |
| 2727 | case ixgbe_mac_82599EB: |
| 2728 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(0), 0xFFFFFFFF); |
| 2729 | IXGBE_WRITE_REG(hw, IXGBE_EIAM_EX(1), 0xFFFFFFFF); |
| 2730 | break; |
| 2731 | } |
| 2732 | } else { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2733 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 2734 | * specifically only auto mask tx and rx interrupts */ |
| 2735 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2736 | } |
| 2737 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2738 | /* Enable fan failure interrupt if media type is copper */ |
| 2739 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 2740 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 2741 | gpie |= IXGBE_SDP1_GPIEN; |
| 2742 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2743 | } |
| 2744 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2745 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2746 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 2747 | gpie |= IXGBE_SDP1_GPIEN; |
| 2748 | gpie |= IXGBE_SDP2_GPIEN; |
| 2749 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2750 | } |
| 2751 | |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2752 | #ifdef IXGBE_FCOE |
| 2753 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
Yi Zou | f34c5c8 | 2009-08-14 12:42:17 +0000 | [diff] [blame] | 2754 | if ((netdev->features & NETIF_F_FCOE_MTU) && |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2755 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 2756 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 2757 | |
| 2758 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2759 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2760 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 2761 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 2762 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 2763 | |
| 2764 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
| 2765 | } |
| 2766 | |
| 2767 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2768 | j = adapter->tx_ring[i].reg_idx; |
| 2769 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 2770 | /* enable WTHRESH=8 descriptors, to encourage burst writeback */ |
| 2771 | txdctl |= (8 << 16); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2772 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
| 2773 | } |
| 2774 | |
| 2775 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2776 | /* DMATXCTL.EN must be set after all Tx queue config is done */ |
| 2777 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 2778 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 2779 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 2780 | } |
| 2781 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2782 | j = adapter->tx_ring[i].reg_idx; |
| 2783 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2784 | txdctl |= IXGBE_TXDCTL_ENABLE; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2785 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2786 | } |
| 2787 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2788 | for (i = 0; i < num_rx_rings; i++) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2789 | j = adapter->rx_ring[i].reg_idx; |
| 2790 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 2791 | /* enable PTHRESH=32 descriptors (half the internal cache) |
| 2792 | * and HTHRESH=0 descriptors (to minimize latency on fetch), |
| 2793 | * this also removes a pesky rx_no_buffer_count increment */ |
| 2794 | rxdctl |= 0x0020; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2795 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2796 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2797 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 2798 | ixgbe_rx_desc_queue_enable(adapter, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2799 | } |
| 2800 | /* enable all receives */ |
| 2801 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2802 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2803 | rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN); |
| 2804 | else |
| 2805 | rxdctl |= IXGBE_RXCTRL_RXEN; |
| 2806 | hw->mac.ops.enable_rx_dma(hw, rxdctl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2807 | |
| 2808 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 2809 | ixgbe_configure_msix(adapter); |
| 2810 | else |
| 2811 | ixgbe_configure_msi_and_legacy(adapter); |
| 2812 | |
| 2813 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2814 | ixgbe_napi_enable_all(adapter); |
| 2815 | |
| 2816 | /* clear any pending interrupts, may auto mask */ |
| 2817 | IXGBE_READ_REG(hw, IXGBE_EICR); |
| 2818 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2819 | ixgbe_irq_enable(adapter); |
| 2820 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2821 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 2822 | * If this adapter has a fan, check to see if we had a failure |
| 2823 | * before we enabled the interrupt. |
| 2824 | */ |
| 2825 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 2826 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 2827 | if (esdp & IXGBE_ESDP_SDP1) |
| 2828 | DPRINTK(DRV, CRIT, |
| 2829 | "Fan has stopped, replace the adapter\n"); |
| 2830 | } |
| 2831 | |
| 2832 | /* |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2833 | * For hot-pluggable SFP+ devices, a new SFP+ module may have |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2834 | * arrived before interrupts were enabled but after probe. Such |
| 2835 | * devices wouldn't have their type identified yet. We need to |
| 2836 | * 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] | 2837 | * If we're not hot-pluggable SFP+, we just need to configure link |
| 2838 | * and bring it up. |
| 2839 | */ |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2840 | if (hw->phy.type == ixgbe_phy_unknown) { |
| 2841 | err = hw->phy.ops.identify(hw); |
| 2842 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 5da43c1 | 2009-07-02 12:50:52 +0000 | [diff] [blame] | 2843 | /* |
| 2844 | * Take the device down and schedule the sfp tasklet |
| 2845 | * which will unregister_netdev and log it. |
| 2846 | */ |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2847 | ixgbe_down(adapter); |
Don Skidmore | 5da43c1 | 2009-07-02 12:50:52 +0000 | [diff] [blame] | 2848 | schedule_work(&adapter->sfp_config_module_task); |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2849 | return err; |
| 2850 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2851 | } |
| 2852 | |
| 2853 | if (ixgbe_is_sfp(hw)) { |
| 2854 | ixgbe_sfp_link_config(adapter); |
| 2855 | } else { |
| 2856 | err = ixgbe_non_sfp_link_config(hw); |
| 2857 | if (err) |
| 2858 | DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err); |
| 2859 | } |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2860 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2861 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2862 | set_bit(__IXGBE_FDIR_INIT_DONE, |
| 2863 | &(adapter->tx_ring[i].reinit_state)); |
| 2864 | |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 2865 | /* enable transmits */ |
| 2866 | netif_tx_start_all_queues(netdev); |
| 2867 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2868 | /* bring the link up in the watchdog, this could race with our first |
| 2869 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2870 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2871 | adapter->link_check_timeout = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2872 | mod_timer(&adapter->watchdog_timer, jiffies); |
| 2873 | return 0; |
| 2874 | } |
| 2875 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2876 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 2877 | { |
| 2878 | WARN_ON(in_interrupt()); |
| 2879 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
| 2880 | msleep(1); |
| 2881 | ixgbe_down(adapter); |
| 2882 | ixgbe_up(adapter); |
| 2883 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 2884 | } |
| 2885 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2886 | int ixgbe_up(struct ixgbe_adapter *adapter) |
| 2887 | { |
| 2888 | /* hardware has been reset, we need to reload some things */ |
| 2889 | ixgbe_configure(adapter); |
| 2890 | |
| 2891 | return ixgbe_up_complete(adapter); |
| 2892 | } |
| 2893 | |
| 2894 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 2895 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2896 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 2897 | int err; |
| 2898 | |
| 2899 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2900 | switch (err) { |
| 2901 | case 0: |
| 2902 | case IXGBE_ERR_SFP_NOT_PRESENT: |
| 2903 | break; |
| 2904 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
| 2905 | dev_err(&adapter->pdev->dev, "master disable timed out\n"); |
| 2906 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 2907 | case IXGBE_ERR_EEPROM_VERSION: |
| 2908 | /* We are running on a pre-production device, log a warning */ |
| 2909 | dev_warn(&adapter->pdev->dev, "This device is a pre-production " |
| 2910 | "adapter/LOM. Please be aware there may be issues " |
| 2911 | "associated with your hardware. If you are " |
| 2912 | "experiencing problems please contact your Intel or " |
| 2913 | "hardware representative who provided you with this " |
| 2914 | "hardware.\n"); |
| 2915 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2916 | default: |
| 2917 | dev_err(&adapter->pdev->dev, "Hardware Error: %d\n", err); |
| 2918 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2919 | |
| 2920 | /* reprogram the RAR[0] in case user changed it. */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2921 | 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] | 2922 | } |
| 2923 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2924 | /** |
| 2925 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
| 2926 | * @adapter: board private structure |
| 2927 | * @rx_ring: ring to free buffers from |
| 2928 | **/ |
| 2929 | static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2930 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2931 | { |
| 2932 | struct pci_dev *pdev = adapter->pdev; |
| 2933 | unsigned long size; |
| 2934 | unsigned int i; |
| 2935 | |
| 2936 | /* Free all the Rx ring sk_buffs */ |
| 2937 | |
| 2938 | for (i = 0; i < rx_ring->count; i++) { |
| 2939 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 2940 | |
| 2941 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
| 2942 | if (rx_buffer_info->dma) { |
| 2943 | pci_unmap_single(pdev, rx_buffer_info->dma, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2944 | rx_ring->rx_buf_len, |
| 2945 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2946 | rx_buffer_info->dma = 0; |
| 2947 | } |
| 2948 | if (rx_buffer_info->skb) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2949 | struct sk_buff *skb = rx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2950 | rx_buffer_info->skb = NULL; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2951 | do { |
| 2952 | struct sk_buff *this = skb; |
| 2953 | skb = skb->prev; |
| 2954 | dev_kfree_skb(this); |
| 2955 | } while (skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2956 | } |
| 2957 | if (!rx_buffer_info->page) |
| 2958 | continue; |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 2959 | if (rx_buffer_info->page_dma) { |
| 2960 | pci_unmap_page(pdev, rx_buffer_info->page_dma, |
| 2961 | PAGE_SIZE / 2, PCI_DMA_FROMDEVICE); |
| 2962 | rx_buffer_info->page_dma = 0; |
| 2963 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2964 | put_page(rx_buffer_info->page); |
| 2965 | rx_buffer_info->page = NULL; |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 2966 | rx_buffer_info->page_offset = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2967 | } |
| 2968 | |
| 2969 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 2970 | memset(rx_ring->rx_buffer_info, 0, size); |
| 2971 | |
| 2972 | /* Zero out the descriptor ring */ |
| 2973 | memset(rx_ring->desc, 0, rx_ring->size); |
| 2974 | |
| 2975 | rx_ring->next_to_clean = 0; |
| 2976 | rx_ring->next_to_use = 0; |
| 2977 | |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 2978 | if (rx_ring->head) |
| 2979 | writel(0, adapter->hw.hw_addr + rx_ring->head); |
| 2980 | if (rx_ring->tail) |
| 2981 | writel(0, adapter->hw.hw_addr + rx_ring->tail); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2982 | } |
| 2983 | |
| 2984 | /** |
| 2985 | * ixgbe_clean_tx_ring - Free Tx Buffers |
| 2986 | * @adapter: board private structure |
| 2987 | * @tx_ring: ring to be cleaned |
| 2988 | **/ |
| 2989 | static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2990 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2991 | { |
| 2992 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 2993 | unsigned long size; |
| 2994 | unsigned int i; |
| 2995 | |
| 2996 | /* Free all the Tx ring sk_buffs */ |
| 2997 | |
| 2998 | for (i = 0; i < tx_ring->count; i++) { |
| 2999 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 3000 | ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info); |
| 3001 | } |
| 3002 | |
| 3003 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 3004 | memset(tx_ring->tx_buffer_info, 0, size); |
| 3005 | |
| 3006 | /* Zero out the descriptor ring */ |
| 3007 | memset(tx_ring->desc, 0, tx_ring->size); |
| 3008 | |
| 3009 | tx_ring->next_to_use = 0; |
| 3010 | tx_ring->next_to_clean = 0; |
| 3011 | |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 3012 | if (tx_ring->head) |
| 3013 | writel(0, adapter->hw.hw_addr + tx_ring->head); |
| 3014 | if (tx_ring->tail) |
| 3015 | writel(0, adapter->hw.hw_addr + tx_ring->tail); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3016 | } |
| 3017 | |
| 3018 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3019 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 3020 | * @adapter: board private structure |
| 3021 | **/ |
| 3022 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 3023 | { |
| 3024 | int i; |
| 3025 | |
| 3026 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3027 | ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]); |
| 3028 | } |
| 3029 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3030 | /** |
| 3031 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 3032 | * @adapter: board private structure |
| 3033 | **/ |
| 3034 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 3035 | { |
| 3036 | int i; |
| 3037 | |
| 3038 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3039 | ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]); |
| 3040 | } |
| 3041 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3042 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 3043 | { |
| 3044 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3045 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3046 | u32 rxctrl; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3047 | u32 txdctl; |
| 3048 | int i, j; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3049 | |
| 3050 | /* signal that we are down to the interrupt handler */ |
| 3051 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 3052 | |
| 3053 | /* disable receives */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3054 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 3055 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3056 | |
| 3057 | netif_tx_disable(netdev); |
| 3058 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3059 | IXGBE_WRITE_FLUSH(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3060 | msleep(10); |
| 3061 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3062 | netif_tx_stop_all_queues(netdev); |
| 3063 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3064 | ixgbe_irq_disable(adapter); |
| 3065 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3066 | ixgbe_napi_disable_all(adapter); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3067 | |
Don Skidmore | 0a1f87c | 2009-09-18 09:45:43 +0000 | [diff] [blame] | 3068 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 3069 | del_timer_sync(&adapter->sfp_timer); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3070 | del_timer_sync(&adapter->watchdog_timer); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3071 | cancel_work_sync(&adapter->watchdog_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3072 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3073 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 3074 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 3075 | cancel_work_sync(&adapter->fdir_reinit_task); |
| 3076 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3077 | /* disable transmits in the hardware now that interrupts are off */ |
| 3078 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 3079 | j = adapter->tx_ring[i].reg_idx; |
| 3080 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
| 3081 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), |
| 3082 | (txdctl & ~IXGBE_TXDCTL_ENABLE)); |
| 3083 | } |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 3084 | /* Disable the Tx DMA engine on 82599 */ |
| 3085 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 3086 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
| 3087 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 3088 | ~IXGBE_DMATXCTL_TE)); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 3089 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3090 | netif_carrier_off(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3091 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 3092 | if (!pci_channel_offline(adapter->pdev)) |
| 3093 | ixgbe_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3094 | ixgbe_clean_all_tx_rings(adapter); |
| 3095 | ixgbe_clean_all_rx_rings(adapter); |
| 3096 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 3097 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 3098 | /* since we reset the hardware DCA settings were cleared */ |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 3099 | ixgbe_setup_dca(adapter); |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 3100 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3101 | } |
| 3102 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3103 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3104 | * ixgbe_poll - NAPI Rx polling callback |
| 3105 | * @napi: structure for representing this polling device |
| 3106 | * @budget: how many packets driver is allowed to clean |
| 3107 | * |
| 3108 | * This function is used for legacy and MSI, NAPI mode |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3109 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3110 | static int ixgbe_poll(struct napi_struct *napi, int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3111 | { |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 3112 | struct ixgbe_q_vector *q_vector = |
| 3113 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3114 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 3115 | int tx_clean_complete, work_done = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3116 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 3117 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 3118 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 3119 | ixgbe_update_tx_dca(adapter, adapter->tx_ring); |
| 3120 | ixgbe_update_rx_dca(adapter, adapter->rx_ring); |
| 3121 | } |
| 3122 | #endif |
| 3123 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 3124 | tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring); |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 3125 | ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3126 | |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 3127 | if (!tx_clean_complete) |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 3128 | work_done = budget; |
| 3129 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 3130 | /* If budget not fully consumed, exit the polling mode */ |
| 3131 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 3132 | napi_complete(napi); |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 3133 | if (adapter->rx_itr_setting & 1) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 3134 | ixgbe_set_itr(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3135 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 3136 | ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3137 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3138 | return work_done; |
| 3139 | } |
| 3140 | |
| 3141 | /** |
| 3142 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 3143 | * @netdev: network interface device structure |
| 3144 | **/ |
| 3145 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 3146 | { |
| 3147 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3148 | |
| 3149 | /* Do the reset outside of interrupt context */ |
| 3150 | schedule_work(&adapter->reset_task); |
| 3151 | } |
| 3152 | |
| 3153 | static void ixgbe_reset_task(struct work_struct *work) |
| 3154 | { |
| 3155 | struct ixgbe_adapter *adapter; |
| 3156 | adapter = container_of(work, struct ixgbe_adapter, reset_task); |
| 3157 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3158 | /* If we're already down or resetting, just bail */ |
| 3159 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 3160 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 3161 | return; |
| 3162 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3163 | adapter->tx_timeout_count++; |
| 3164 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3165 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3166 | } |
| 3167 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3168 | #ifdef CONFIG_IXGBE_DCB |
| 3169 | static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3170 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3171 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3172 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB]; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3173 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3174 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) |
| 3175 | return ret; |
| 3176 | |
| 3177 | f->mask = 0x7 << 3; |
| 3178 | adapter->num_rx_queues = f->indices; |
| 3179 | adapter->num_tx_queues = f->indices; |
| 3180 | ret = true; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3181 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3182 | return ret; |
| 3183 | } |
| 3184 | #endif |
| 3185 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3186 | /** |
| 3187 | * ixgbe_set_rss_queues: Allocate queues for RSS |
| 3188 | * @adapter: board private structure to initialize |
| 3189 | * |
| 3190 | * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try |
| 3191 | * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU. |
| 3192 | * |
| 3193 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3194 | static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter) |
| 3195 | { |
| 3196 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3197 | 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] | 3198 | |
| 3199 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3200 | f->mask = 0xF; |
| 3201 | adapter->num_rx_queues = f->indices; |
| 3202 | adapter->num_tx_queues = f->indices; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3203 | ret = true; |
| 3204 | } else { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3205 | ret = false; |
| 3206 | } |
| 3207 | |
| 3208 | return ret; |
| 3209 | } |
| 3210 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3211 | /** |
| 3212 | * ixgbe_set_fdir_queues: Allocate queues for Flow Director |
| 3213 | * @adapter: board private structure to initialize |
| 3214 | * |
| 3215 | * Flow Director is an advanced Rx filter, attempting to get Rx flows back |
| 3216 | * to the original CPU that initiated the Tx session. This runs in addition |
| 3217 | * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the |
| 3218 | * Rx load across CPUs using RSS. |
| 3219 | * |
| 3220 | **/ |
| 3221 | static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter) |
| 3222 | { |
| 3223 | bool ret = false; |
| 3224 | struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR]; |
| 3225 | |
| 3226 | f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices); |
| 3227 | f_fdir->mask = 0; |
| 3228 | |
| 3229 | /* Flow Director must have RSS enabled */ |
| 3230 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED && |
| 3231 | ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 3232 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) { |
| 3233 | adapter->num_tx_queues = f_fdir->indices; |
| 3234 | adapter->num_rx_queues = f_fdir->indices; |
| 3235 | ret = true; |
| 3236 | } else { |
| 3237 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3238 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 3239 | } |
| 3240 | return ret; |
| 3241 | } |
| 3242 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3243 | #ifdef IXGBE_FCOE |
| 3244 | /** |
| 3245 | * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE) |
| 3246 | * @adapter: board private structure to initialize |
| 3247 | * |
| 3248 | * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges. |
| 3249 | * The ring feature mask is not used as a mask for FCoE, as it can take any 8 |
| 3250 | * rx queues out of the max number of rx queues, instead, it is used as the |
| 3251 | * index of the first rx queue used by FCoE. |
| 3252 | * |
| 3253 | **/ |
| 3254 | static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter) |
| 3255 | { |
| 3256 | bool ret = false; |
| 3257 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 3258 | |
| 3259 | f->indices = min((int)num_online_cpus(), f->indices); |
| 3260 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3261 | adapter->num_rx_queues = 1; |
| 3262 | adapter->num_tx_queues = 1; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3263 | #ifdef CONFIG_IXGBE_DCB |
| 3264 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3265 | DPRINTK(PROBE, INFO, "FCoE enabled with DCB \n"); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3266 | ixgbe_set_dcb_queues(adapter); |
| 3267 | } |
| 3268 | #endif |
| 3269 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3270 | DPRINTK(PROBE, INFO, "FCoE enabled with RSS \n"); |
Yi Zou | 8faa2a7 | 2009-07-09 02:29:50 +0000 | [diff] [blame] | 3271 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 3272 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 3273 | ixgbe_set_fdir_queues(adapter); |
| 3274 | else |
| 3275 | ixgbe_set_rss_queues(adapter); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3276 | } |
| 3277 | /* adding FCoE rx rings to the end */ |
| 3278 | f->mask = adapter->num_rx_queues; |
| 3279 | adapter->num_rx_queues += f->indices; |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3280 | adapter->num_tx_queues += f->indices; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3281 | |
| 3282 | ret = true; |
| 3283 | } |
| 3284 | |
| 3285 | return ret; |
| 3286 | } |
| 3287 | |
| 3288 | #endif /* IXGBE_FCOE */ |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3289 | /* |
| 3290 | * ixgbe_set_num_queues: Allocate queues for device, feature dependant |
| 3291 | * @adapter: board private structure to initialize |
| 3292 | * |
| 3293 | * This is the top level queue allocation routine. The order here is very |
| 3294 | * important, starting with the "most" number of features turned on at once, |
| 3295 | * and ending with the smallest set of features. This way large combinations |
| 3296 | * can be allocated if they're turned on, and smaller combinations are the |
| 3297 | * fallthrough conditions. |
| 3298 | * |
| 3299 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3300 | static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter) |
| 3301 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3302 | #ifdef IXGBE_FCOE |
| 3303 | if (ixgbe_set_fcoe_queues(adapter)) |
| 3304 | goto done; |
| 3305 | |
| 3306 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3307 | #ifdef CONFIG_IXGBE_DCB |
| 3308 | if (ixgbe_set_dcb_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 3309 | goto done; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3310 | |
| 3311 | #endif |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3312 | if (ixgbe_set_fdir_queues(adapter)) |
| 3313 | goto done; |
| 3314 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3315 | if (ixgbe_set_rss_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 3316 | goto done; |
| 3317 | |
| 3318 | /* fallback to base case */ |
| 3319 | adapter->num_rx_queues = 1; |
| 3320 | adapter->num_tx_queues = 1; |
| 3321 | |
| 3322 | done: |
| 3323 | /* Notify the stack of the (possibly) reduced Tx Queue count. */ |
| 3324 | adapter->netdev->real_num_tx_queues = adapter->num_tx_queues; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3325 | } |
| 3326 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3327 | static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3328 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3329 | { |
| 3330 | int err, vector_threshold; |
| 3331 | |
| 3332 | /* We'll want at least 3 (vector_threshold): |
| 3333 | * 1) TxQ[0] Cleanup |
| 3334 | * 2) RxQ[0] Cleanup |
| 3335 | * 3) Other (Link Status Change, etc.) |
| 3336 | * 4) TCP Timer (optional) |
| 3337 | */ |
| 3338 | vector_threshold = MIN_MSIX_COUNT; |
| 3339 | |
| 3340 | /* The more we get, the more we will assign to Tx/Rx Cleanup |
| 3341 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 3342 | * Right now, we simply care about how many we'll get; we'll |
| 3343 | * set them up later while requesting irq's. |
| 3344 | */ |
| 3345 | while (vectors >= vector_threshold) { |
| 3346 | err = pci_enable_msix(adapter->pdev, adapter->msix_entries, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3347 | vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3348 | if (!err) /* Success in acquiring all requested vectors. */ |
| 3349 | break; |
| 3350 | else if (err < 0) |
| 3351 | vectors = 0; /* Nasty failure, quit now */ |
| 3352 | else /* err == number of vectors we should try again with */ |
| 3353 | vectors = err; |
| 3354 | } |
| 3355 | |
| 3356 | if (vectors < vector_threshold) { |
| 3357 | /* Can't allocate enough MSI-X interrupts? Oh well. |
| 3358 | * This just means we'll go with either a single MSI |
| 3359 | * vector or fall back to legacy interrupts. |
| 3360 | */ |
| 3361 | DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n"); |
| 3362 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 3363 | kfree(adapter->msix_entries); |
| 3364 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3365 | } else { |
| 3366 | adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */ |
Peter P Waskiewicz Jr | eb7f139 | 2009-02-01 01:18:58 -0800 | [diff] [blame] | 3367 | /* |
| 3368 | * Adjust for only the vectors we'll use, which is minimum |
| 3369 | * of max_msix_q_vectors + NON_Q_VECTORS, or the number of |
| 3370 | * vectors we were allocated. |
| 3371 | */ |
| 3372 | adapter->num_msix_vectors = min(vectors, |
| 3373 | adapter->max_msix_q_vectors + NON_Q_VECTORS); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3374 | } |
| 3375 | } |
| 3376 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3377 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3378 | * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3379 | * @adapter: board private structure to initialize |
| 3380 | * |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3381 | * Cache the descriptor ring offsets for RSS to the assigned rings. |
| 3382 | * |
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 | static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3385 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3386 | int i; |
| 3387 | bool ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3388 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3389 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 3390 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3391 | adapter->rx_ring[i].reg_idx = i; |
| 3392 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3393 | adapter->tx_ring[i].reg_idx = i; |
| 3394 | ret = true; |
| 3395 | } else { |
| 3396 | ret = false; |
| 3397 | } |
| 3398 | |
| 3399 | return ret; |
| 3400 | } |
| 3401 | |
| 3402 | #ifdef CONFIG_IXGBE_DCB |
| 3403 | /** |
| 3404 | * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB |
| 3405 | * @adapter: board private structure to initialize |
| 3406 | * |
| 3407 | * Cache the descriptor ring offsets for DCB to the assigned rings. |
| 3408 | * |
| 3409 | **/ |
| 3410 | static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter) |
| 3411 | { |
| 3412 | int i; |
| 3413 | bool ret = false; |
| 3414 | int dcb_i = adapter->ring_feature[RING_F_DCB].indices; |
| 3415 | |
| 3416 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 3417 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3418 | /* the number of queues is assumed to be symmetric */ |
| 3419 | for (i = 0; i < dcb_i; i++) { |
| 3420 | adapter->rx_ring[i].reg_idx = i << 3; |
| 3421 | adapter->tx_ring[i].reg_idx = i << 2; |
| 3422 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3423 | ret = true; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3424 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | f92ef20 | 2009-04-16 15:00:20 +0000 | [diff] [blame] | 3425 | if (dcb_i == 8) { |
| 3426 | /* |
| 3427 | * Tx TC0 starts at: descriptor queue 0 |
| 3428 | * Tx TC1 starts at: descriptor queue 32 |
| 3429 | * Tx TC2 starts at: descriptor queue 64 |
| 3430 | * Tx TC3 starts at: descriptor queue 80 |
| 3431 | * Tx TC4 starts at: descriptor queue 96 |
| 3432 | * Tx TC5 starts at: descriptor queue 104 |
| 3433 | * Tx TC6 starts at: descriptor queue 112 |
| 3434 | * Tx TC7 starts at: descriptor queue 120 |
| 3435 | * |
| 3436 | * Rx TC0-TC7 are offset by 16 queues each |
| 3437 | */ |
| 3438 | for (i = 0; i < 3; i++) { |
| 3439 | adapter->tx_ring[i].reg_idx = i << 5; |
| 3440 | adapter->rx_ring[i].reg_idx = i << 4; |
| 3441 | } |
| 3442 | for ( ; i < 5; i++) { |
| 3443 | adapter->tx_ring[i].reg_idx = |
| 3444 | ((i + 2) << 4); |
| 3445 | adapter->rx_ring[i].reg_idx = i << 4; |
| 3446 | } |
| 3447 | for ( ; i < dcb_i; i++) { |
| 3448 | adapter->tx_ring[i].reg_idx = |
| 3449 | ((i + 8) << 3); |
| 3450 | adapter->rx_ring[i].reg_idx = i << 4; |
| 3451 | } |
| 3452 | |
| 3453 | ret = true; |
| 3454 | } else if (dcb_i == 4) { |
| 3455 | /* |
| 3456 | * Tx TC0 starts at: descriptor queue 0 |
| 3457 | * Tx TC1 starts at: descriptor queue 64 |
| 3458 | * Tx TC2 starts at: descriptor queue 96 |
| 3459 | * Tx TC3 starts at: descriptor queue 112 |
| 3460 | * |
| 3461 | * Rx TC0-TC3 are offset by 32 queues each |
| 3462 | */ |
| 3463 | adapter->tx_ring[0].reg_idx = 0; |
| 3464 | adapter->tx_ring[1].reg_idx = 64; |
| 3465 | adapter->tx_ring[2].reg_idx = 96; |
| 3466 | adapter->tx_ring[3].reg_idx = 112; |
| 3467 | for (i = 0 ; i < dcb_i; i++) |
| 3468 | adapter->rx_ring[i].reg_idx = i << 5; |
| 3469 | |
| 3470 | ret = true; |
| 3471 | } else { |
| 3472 | ret = false; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3473 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3474 | } else { |
| 3475 | ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3476 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3477 | } else { |
| 3478 | ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3479 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3480 | |
| 3481 | return ret; |
| 3482 | } |
| 3483 | #endif |
| 3484 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3485 | /** |
| 3486 | * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director |
| 3487 | * @adapter: board private structure to initialize |
| 3488 | * |
| 3489 | * Cache the descriptor ring offsets for Flow Director to the assigned rings. |
| 3490 | * |
| 3491 | **/ |
| 3492 | static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter) |
| 3493 | { |
| 3494 | int i; |
| 3495 | bool ret = false; |
| 3496 | |
| 3497 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED && |
| 3498 | ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 3499 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) { |
| 3500 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3501 | adapter->rx_ring[i].reg_idx = i; |
| 3502 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3503 | adapter->tx_ring[i].reg_idx = i; |
| 3504 | ret = true; |
| 3505 | } |
| 3506 | |
| 3507 | return ret; |
| 3508 | } |
| 3509 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3510 | #ifdef IXGBE_FCOE |
| 3511 | /** |
| 3512 | * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE |
| 3513 | * @adapter: board private structure to initialize |
| 3514 | * |
| 3515 | * Cache the descriptor ring offsets for FCoE mode to the assigned rings. |
| 3516 | * |
| 3517 | */ |
| 3518 | static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter) |
| 3519 | { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3520 | int i, fcoe_rx_i = 0, fcoe_tx_i = 0; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3521 | bool ret = false; |
| 3522 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 3523 | |
| 3524 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 3525 | #ifdef CONFIG_IXGBE_DCB |
| 3526 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3527 | struct ixgbe_fcoe *fcoe = &adapter->fcoe; |
| 3528 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3529 | ixgbe_cache_ring_dcb(adapter); |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3530 | /* find out queues in TC for FCoE */ |
| 3531 | fcoe_rx_i = adapter->rx_ring[fcoe->tc].reg_idx + 1; |
| 3532 | fcoe_tx_i = adapter->tx_ring[fcoe->tc].reg_idx + 1; |
| 3533 | /* |
| 3534 | * In 82599, the number of Tx queues for each traffic |
| 3535 | * class for both 8-TC and 4-TC modes are: |
| 3536 | * TCs : TC0 TC1 TC2 TC3 TC4 TC5 TC6 TC7 |
| 3537 | * 8 TCs: 32 32 16 16 8 8 8 8 |
| 3538 | * 4 TCs: 64 64 32 32 |
| 3539 | * We have max 8 queues for FCoE, where 8 the is |
| 3540 | * FCoE redirection table size. If TC for FCoE is |
| 3541 | * less than or equal to TC3, we have enough queues |
| 3542 | * to add max of 8 queues for FCoE, so we start FCoE |
| 3543 | * tx descriptor from the next one, i.e., reg_idx + 1. |
| 3544 | * If TC for FCoE is above TC3, implying 8 TC mode, |
| 3545 | * and we need 8 for FCoE, we have to take all queues |
| 3546 | * in that traffic class for FCoE. |
| 3547 | */ |
| 3548 | if ((f->indices == IXGBE_FCRETA_SIZE) && (fcoe->tc > 3)) |
| 3549 | fcoe_tx_i--; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3550 | } |
| 3551 | #endif /* CONFIG_IXGBE_DCB */ |
| 3552 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Yi Zou | 8faa2a7 | 2009-07-09 02:29:50 +0000 | [diff] [blame] | 3553 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 3554 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 3555 | ixgbe_cache_ring_fdir(adapter); |
| 3556 | else |
| 3557 | ixgbe_cache_ring_rss(adapter); |
| 3558 | |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3559 | fcoe_rx_i = f->mask; |
| 3560 | fcoe_tx_i = f->mask; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3561 | } |
Yi Zou | 8de8b2e | 2009-09-03 14:55:50 +0000 | [diff] [blame] | 3562 | for (i = 0; i < f->indices; i++, fcoe_rx_i++, fcoe_tx_i++) { |
| 3563 | adapter->rx_ring[f->mask + i].reg_idx = fcoe_rx_i; |
| 3564 | adapter->tx_ring[f->mask + i].reg_idx = fcoe_tx_i; |
| 3565 | } |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3566 | ret = true; |
| 3567 | } |
| 3568 | return ret; |
| 3569 | } |
| 3570 | |
| 3571 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3572 | /** |
| 3573 | * ixgbe_cache_ring_register - Descriptor ring to register mapping |
| 3574 | * @adapter: board private structure to initialize |
| 3575 | * |
| 3576 | * Once we know the feature-set enabled for the device, we'll cache |
| 3577 | * the register offset the descriptor ring is assigned to. |
| 3578 | * |
| 3579 | * Note, the order the various feature calls is important. It must start with |
| 3580 | * the "most" features enabled at the same time, then trickle down to the |
| 3581 | * least amount of features turned on at once. |
| 3582 | **/ |
| 3583 | static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) |
| 3584 | { |
| 3585 | /* start with default case */ |
| 3586 | adapter->rx_ring[0].reg_idx = 0; |
| 3587 | adapter->tx_ring[0].reg_idx = 0; |
| 3588 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3589 | #ifdef IXGBE_FCOE |
| 3590 | if (ixgbe_cache_ring_fcoe(adapter)) |
| 3591 | return; |
| 3592 | |
| 3593 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3594 | #ifdef CONFIG_IXGBE_DCB |
| 3595 | if (ixgbe_cache_ring_dcb(adapter)) |
| 3596 | return; |
| 3597 | |
| 3598 | #endif |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3599 | if (ixgbe_cache_ring_fdir(adapter)) |
| 3600 | return; |
| 3601 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3602 | if (ixgbe_cache_ring_rss(adapter)) |
| 3603 | return; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3604 | } |
| 3605 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3606 | /** |
| 3607 | * ixgbe_alloc_queues - Allocate memory for all rings |
| 3608 | * @adapter: board private structure to initialize |
| 3609 | * |
| 3610 | * 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] | 3611 | * number of queues at compile-time. The polling_netdev array is |
| 3612 | * intended for Multiqueue, but should work fine with a single queue. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3613 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3614 | static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3615 | { |
| 3616 | int i; |
| 3617 | |
| 3618 | adapter->tx_ring = kcalloc(adapter->num_tx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3619 | sizeof(struct ixgbe_ring), GFP_KERNEL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3620 | if (!adapter->tx_ring) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3621 | goto err_tx_ring_allocation; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3622 | |
| 3623 | adapter->rx_ring = kcalloc(adapter->num_rx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3624 | sizeof(struct ixgbe_ring), GFP_KERNEL); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3625 | if (!adapter->rx_ring) |
| 3626 | goto err_rx_ring_allocation; |
| 3627 | |
| 3628 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3629 | adapter->tx_ring[i].count = adapter->tx_ring_count; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3630 | adapter->tx_ring[i].queue_index = i; |
| 3631 | } |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3632 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3633 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3634 | adapter->rx_ring[i].count = adapter->rx_ring_count; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3635 | adapter->rx_ring[i].queue_index = i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3636 | } |
| 3637 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3638 | ixgbe_cache_ring_register(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3639 | |
| 3640 | return 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3641 | |
| 3642 | err_rx_ring_allocation: |
| 3643 | kfree(adapter->tx_ring); |
| 3644 | err_tx_ring_allocation: |
| 3645 | return -ENOMEM; |
| 3646 | } |
| 3647 | |
| 3648 | /** |
| 3649 | * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported |
| 3650 | * @adapter: board private structure to initialize |
| 3651 | * |
| 3652 | * Attempt to configure the interrupts using the best available |
| 3653 | * capabilities of the hardware and the kernel. |
| 3654 | **/ |
Al Viro | feea6a5 | 2008-11-27 15:34:07 -0800 | [diff] [blame] | 3655 | static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3656 | { |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3657 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3658 | int err = 0; |
| 3659 | int vector, v_budget; |
| 3660 | |
| 3661 | /* |
| 3662 | * It's easy to be greedy for MSI-X vectors, but it really |
| 3663 | * doesn't do us much good if we have a lot more vectors |
| 3664 | * than CPU's. So let's be conservative and only ask for |
PJ Waskiewicz | 342bde1 | 2009-11-12 23:50:43 +0000 | [diff] [blame] | 3665 | * (roughly) the same number of vectors as there are CPU's. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3666 | */ |
| 3667 | v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues, |
PJ Waskiewicz | 342bde1 | 2009-11-12 23:50:43 +0000 | [diff] [blame] | 3668 | (int)num_online_cpus()) + NON_Q_VECTORS; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3669 | |
| 3670 | /* |
| 3671 | * At the same time, hardware can only support a maximum of |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3672 | * hw.mac->max_msix_vectors vectors. With features |
| 3673 | * such as RSS and VMDq, we can easily surpass the number of Rx and Tx |
| 3674 | * descriptor queues supported by our device. Thus, we cap it off in |
| 3675 | * those rare cases where the cpu count also exceeds our vector limit. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3676 | */ |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3677 | v_budget = min(v_budget, (int)hw->mac.max_msix_vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3678 | |
| 3679 | /* A failure in MSI-X entry allocation isn't fatal, but it does |
| 3680 | * mean we disable MSI-X capabilities of the adapter. */ |
| 3681 | adapter->msix_entries = kcalloc(v_budget, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3682 | sizeof(struct msix_entry), GFP_KERNEL); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3683 | if (adapter->msix_entries) { |
| 3684 | for (vector = 0; vector < v_budget; vector++) |
| 3685 | adapter->msix_entries[vector].entry = vector; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3686 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3687 | ixgbe_acquire_msix_vectors(adapter, v_budget); |
| 3688 | |
| 3689 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 3690 | goto out; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3691 | } |
| 3692 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3693 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 3694 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3695 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3696 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 3697 | adapter->atr_sample_rate = 0; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3698 | ixgbe_set_num_queues(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3699 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3700 | err = pci_enable_msi(adapter->pdev); |
| 3701 | if (!err) { |
| 3702 | adapter->flags |= IXGBE_FLAG_MSI_ENABLED; |
| 3703 | } else { |
| 3704 | DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3705 | "falling back to legacy. Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3706 | /* reset err */ |
| 3707 | err = 0; |
| 3708 | } |
| 3709 | |
| 3710 | out: |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3711 | return err; |
| 3712 | } |
| 3713 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3714 | /** |
| 3715 | * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors |
| 3716 | * @adapter: board private structure to initialize |
| 3717 | * |
| 3718 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 3719 | * return -ENOMEM. |
| 3720 | **/ |
| 3721 | static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter) |
| 3722 | { |
| 3723 | int q_idx, num_q_vectors; |
| 3724 | struct ixgbe_q_vector *q_vector; |
| 3725 | int napi_vectors; |
| 3726 | int (*poll)(struct napi_struct *, int); |
| 3727 | |
| 3728 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 3729 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3730 | napi_vectors = adapter->num_rx_queues; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3731 | poll = &ixgbe_clean_rxtx_many; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3732 | } else { |
| 3733 | num_q_vectors = 1; |
| 3734 | napi_vectors = 1; |
| 3735 | poll = &ixgbe_poll; |
| 3736 | } |
| 3737 | |
| 3738 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
| 3739 | q_vector = kzalloc(sizeof(struct ixgbe_q_vector), GFP_KERNEL); |
| 3740 | if (!q_vector) |
| 3741 | goto err_out; |
| 3742 | q_vector->adapter = adapter; |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 3743 | if (q_vector->txr_count && !q_vector->rxr_count) |
| 3744 | q_vector->eitr = adapter->tx_eitr_param; |
| 3745 | else |
| 3746 | q_vector->eitr = adapter->rx_eitr_param; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 3747 | q_vector->v_idx = q_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3748 | netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3749 | adapter->q_vector[q_idx] = q_vector; |
| 3750 | } |
| 3751 | |
| 3752 | return 0; |
| 3753 | |
| 3754 | err_out: |
| 3755 | while (q_idx) { |
| 3756 | q_idx--; |
| 3757 | q_vector = adapter->q_vector[q_idx]; |
| 3758 | netif_napi_del(&q_vector->napi); |
| 3759 | kfree(q_vector); |
| 3760 | adapter->q_vector[q_idx] = NULL; |
| 3761 | } |
| 3762 | return -ENOMEM; |
| 3763 | } |
| 3764 | |
| 3765 | /** |
| 3766 | * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors |
| 3767 | * @adapter: board private structure to initialize |
| 3768 | * |
| 3769 | * This function frees the memory allocated to the q_vectors. In addition if |
| 3770 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 3771 | * to freeing the q_vector. |
| 3772 | **/ |
| 3773 | static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter) |
| 3774 | { |
| 3775 | int q_idx, num_q_vectors; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3776 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3777 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3778 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3779 | else |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3780 | num_q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3781 | |
| 3782 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
| 3783 | struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx]; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3784 | adapter->q_vector[q_idx] = NULL; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3785 | netif_napi_del(&q_vector->napi); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3786 | kfree(q_vector); |
| 3787 | } |
| 3788 | } |
| 3789 | |
Don Skidmore | 7b25cdb | 2009-08-25 04:47:32 +0000 | [diff] [blame] | 3790 | static void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3791 | { |
| 3792 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 3793 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 3794 | pci_disable_msix(adapter->pdev); |
| 3795 | kfree(adapter->msix_entries); |
| 3796 | adapter->msix_entries = NULL; |
| 3797 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 3798 | adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED; |
| 3799 | pci_disable_msi(adapter->pdev); |
| 3800 | } |
| 3801 | return; |
| 3802 | } |
| 3803 | |
| 3804 | /** |
| 3805 | * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme |
| 3806 | * @adapter: board private structure to initialize |
| 3807 | * |
| 3808 | * We determine which interrupt scheme to use based on... |
| 3809 | * - Kernel support (MSI, MSI-X) |
| 3810 | * - which can be user-defined (via MODULE_PARAM) |
| 3811 | * - Hardware queue count (num_*_queues) |
| 3812 | * - defined by miscellaneous hardware support/features (RSS, etc.) |
| 3813 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3814 | int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3815 | { |
| 3816 | int err; |
| 3817 | |
| 3818 | /* Number of supported queues */ |
| 3819 | ixgbe_set_num_queues(adapter); |
| 3820 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3821 | err = ixgbe_set_interrupt_capability(adapter); |
| 3822 | if (err) { |
| 3823 | DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n"); |
| 3824 | goto err_set_interrupt; |
| 3825 | } |
| 3826 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3827 | err = ixgbe_alloc_q_vectors(adapter); |
| 3828 | if (err) { |
| 3829 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queue " |
| 3830 | "vectors\n"); |
| 3831 | goto err_alloc_q_vectors; |
| 3832 | } |
| 3833 | |
| 3834 | err = ixgbe_alloc_queues(adapter); |
| 3835 | if (err) { |
| 3836 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n"); |
| 3837 | goto err_alloc_queues; |
| 3838 | } |
| 3839 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3840 | DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3841 | "Tx Queue count = %u\n", |
| 3842 | (adapter->num_rx_queues > 1) ? "Enabled" : |
| 3843 | "Disabled", adapter->num_rx_queues, adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3844 | |
| 3845 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 3846 | |
| 3847 | return 0; |
| 3848 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3849 | err_alloc_queues: |
| 3850 | ixgbe_free_q_vectors(adapter); |
| 3851 | err_alloc_q_vectors: |
| 3852 | ixgbe_reset_interrupt_capability(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3853 | err_set_interrupt: |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3854 | return err; |
| 3855 | } |
| 3856 | |
| 3857 | /** |
| 3858 | * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 3859 | * @adapter: board private structure to clear interrupt scheme on |
| 3860 | * |
| 3861 | * We go through and clear interrupt specific resources and reset the structure |
| 3862 | * to pre-load conditions |
| 3863 | **/ |
| 3864 | void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter) |
| 3865 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3866 | kfree(adapter->tx_ring); |
| 3867 | kfree(adapter->rx_ring); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3868 | adapter->tx_ring = NULL; |
| 3869 | adapter->rx_ring = NULL; |
| 3870 | |
| 3871 | ixgbe_free_q_vectors(adapter); |
| 3872 | ixgbe_reset_interrupt_capability(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3873 | } |
| 3874 | |
| 3875 | /** |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3876 | * ixgbe_sfp_timer - worker thread to find a missing module |
| 3877 | * @data: pointer to our adapter struct |
| 3878 | **/ |
| 3879 | static void ixgbe_sfp_timer(unsigned long data) |
| 3880 | { |
| 3881 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 3882 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3883 | /* |
| 3884 | * Do the sfp_timer outside of interrupt context due to the |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3885 | * delays that sfp+ detection requires |
| 3886 | */ |
| 3887 | schedule_work(&adapter->sfp_task); |
| 3888 | } |
| 3889 | |
| 3890 | /** |
| 3891 | * ixgbe_sfp_task - worker thread to find a missing module |
| 3892 | * @work: pointer to work_struct containing our data |
| 3893 | **/ |
| 3894 | static void ixgbe_sfp_task(struct work_struct *work) |
| 3895 | { |
| 3896 | struct ixgbe_adapter *adapter = container_of(work, |
| 3897 | struct ixgbe_adapter, |
| 3898 | sfp_task); |
| 3899 | struct ixgbe_hw *hw = &adapter->hw; |
| 3900 | |
| 3901 | if ((hw->phy.type == ixgbe_phy_nl) && |
| 3902 | (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) { |
| 3903 | s32 ret = hw->phy.ops.identify_sfp(hw); |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 3904 | if (ret == IXGBE_ERR_SFP_NOT_PRESENT) |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3905 | goto reschedule; |
| 3906 | ret = hw->phy.ops.reset(hw); |
| 3907 | if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 88d2b81 | 2009-06-30 11:43:55 +0000 | [diff] [blame] | 3908 | dev_err(&adapter->pdev->dev, "failed to initialize " |
| 3909 | "because an unsupported SFP+ module type " |
| 3910 | "was detected.\n" |
| 3911 | "Reload the driver after installing a " |
| 3912 | "supported module.\n"); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3913 | unregister_netdev(adapter->netdev); |
| 3914 | } else { |
| 3915 | DPRINTK(PROBE, INFO, "detected SFP+: %d\n", |
| 3916 | hw->phy.sfp_type); |
| 3917 | } |
| 3918 | /* don't need this routine any more */ |
| 3919 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 3920 | } |
| 3921 | return; |
| 3922 | reschedule: |
| 3923 | if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state)) |
| 3924 | mod_timer(&adapter->sfp_timer, |
| 3925 | round_jiffies(jiffies + (2 * HZ))); |
| 3926 | } |
| 3927 | |
| 3928 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3929 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 3930 | * @adapter: board private structure to initialize |
| 3931 | * |
| 3932 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 3933 | * Fields are initialized based on PCI device information and |
| 3934 | * OS network device settings (MTU size). |
| 3935 | **/ |
| 3936 | static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter) |
| 3937 | { |
| 3938 | struct ixgbe_hw *hw = &adapter->hw; |
| 3939 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3940 | unsigned int rss; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3941 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3942 | int j; |
| 3943 | struct tc_configuration *tc; |
| 3944 | #endif |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3945 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3946 | /* PCI config space info */ |
| 3947 | |
| 3948 | hw->vendor_id = pdev->vendor; |
| 3949 | hw->device_id = pdev->device; |
| 3950 | hw->revision_id = pdev->revision; |
| 3951 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 3952 | hw->subsystem_device_id = pdev->subsystem_device; |
| 3953 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3954 | /* Set capability flags */ |
| 3955 | rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus()); |
| 3956 | adapter->ring_feature[RING_F_RSS].indices = rss; |
| 3957 | adapter->flags |= IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3958 | adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES; |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3959 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3960 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 3961 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3962 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598; |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3963 | } else if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3964 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599; |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 3965 | adapter->flags2 |= IXGBE_FLAG2_RSC_CAPABLE; |
| 3966 | adapter->flags2 |= IXGBE_FLAG2_RSC_ENABLED; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3967 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3968 | adapter->ring_feature[RING_F_FDIR].indices = |
| 3969 | IXGBE_MAX_FDIR_INDICES; |
| 3970 | adapter->atr_sample_rate = 20; |
| 3971 | adapter->fdir_pballoc = 0; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 3972 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 3973 | adapter->flags |= IXGBE_FLAG_FCOE_CAPABLE; |
| 3974 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 3975 | adapter->ring_feature[RING_F_FCOE].indices = 0; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 3976 | #ifdef CONFIG_IXGBE_DCB |
Yi Zou | 6ee1652 | 2009-08-31 12:34:28 +0000 | [diff] [blame] | 3977 | /* Default traffic class to use for FCoE */ |
| 3978 | adapter->fcoe.tc = IXGBE_FCOE_DEFTC; |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 3979 | #endif |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 3980 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3981 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3982 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3983 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3984 | /* Configure DCB traffic classes */ |
| 3985 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 3986 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 3987 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 3988 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 3989 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 3990 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 3991 | tc->dcb_pfc = pfc_disabled; |
| 3992 | } |
| 3993 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 3994 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
| 3995 | adapter->dcb_cfg.rx_pba_cfg = pba_equal; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 3996 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3997 | adapter->dcb_cfg.round_robin_enable = false; |
| 3998 | adapter->dcb_set_bitmap = 0x00; |
| 3999 | ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg, |
| 4000 | adapter->ring_feature[RING_F_DCB].indices); |
| 4001 | |
| 4002 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4003 | |
| 4004 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 4005 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 4006 | 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] | 4007 | #ifdef CONFIG_DCB |
| 4008 | adapter->last_lfc_mode = hw->fc.current_mode; |
| 4009 | #endif |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 4010 | hw->fc.high_water = IXGBE_DEFAULT_FCRTH; |
| 4011 | hw->fc.low_water = IXGBE_DEFAULT_FCRTL; |
| 4012 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 4013 | hw->fc.send_xon = true; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 4014 | hw->fc.disable_fc_autoneg = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4015 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 4016 | /* enable itr by default in dynamic mode */ |
Nelson, Shannon | f7554a2 | 2009-09-18 09:46:06 +0000 | [diff] [blame] | 4017 | adapter->rx_itr_setting = 1; |
| 4018 | adapter->rx_eitr_param = 20000; |
| 4019 | adapter->tx_itr_setting = 1; |
| 4020 | adapter->tx_eitr_param = 10000; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 4021 | |
| 4022 | /* set defaults for eitr in MegaBytes */ |
| 4023 | adapter->eitr_low = 10; |
| 4024 | adapter->eitr_high = 20; |
| 4025 | |
| 4026 | /* set default ring sizes */ |
| 4027 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 4028 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 4029 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4030 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4031 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4032 | dev_err(&pdev->dev, "EEPROM initialization failed\n"); |
| 4033 | return -EIO; |
| 4034 | } |
| 4035 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4036 | /* enable rx csum by default */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4037 | adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED; |
| 4038 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4039 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 4040 | |
| 4041 | return 0; |
| 4042 | } |
| 4043 | |
| 4044 | /** |
| 4045 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
| 4046 | * @adapter: board private structure |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4047 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4048 | * |
| 4049 | * Return 0 on success, negative on failure |
| 4050 | **/ |
| 4051 | int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4052 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4053 | { |
| 4054 | struct pci_dev *pdev = adapter->pdev; |
| 4055 | int size; |
| 4056 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4057 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 4058 | tx_ring->tx_buffer_info = vmalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4059 | if (!tx_ring->tx_buffer_info) |
| 4060 | goto err; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4061 | memset(tx_ring->tx_buffer_info, 0, size); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4062 | |
| 4063 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 4064 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4065 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4066 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4067 | tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size, |
| 4068 | &tx_ring->dma); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4069 | if (!tx_ring->desc) |
| 4070 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4071 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4072 | tx_ring->next_to_use = 0; |
| 4073 | tx_ring->next_to_clean = 0; |
| 4074 | tx_ring->work_limit = tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4075 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 4076 | |
| 4077 | err: |
| 4078 | vfree(tx_ring->tx_buffer_info); |
| 4079 | tx_ring->tx_buffer_info = NULL; |
| 4080 | DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit " |
| 4081 | "descriptor ring\n"); |
| 4082 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4083 | } |
| 4084 | |
| 4085 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4086 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 4087 | * @adapter: board private structure |
| 4088 | * |
| 4089 | * If this function returns with an error, then it's possible one or |
| 4090 | * more of the rings is populated (while the rest are not). It is the |
| 4091 | * callers duty to clean those orphaned rings. |
| 4092 | * |
| 4093 | * Return 0 on success, negative on failure |
| 4094 | **/ |
| 4095 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 4096 | { |
| 4097 | int i, err = 0; |
| 4098 | |
| 4099 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 4100 | err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]); |
| 4101 | if (!err) |
| 4102 | continue; |
| 4103 | DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i); |
| 4104 | break; |
| 4105 | } |
| 4106 | |
| 4107 | return err; |
| 4108 | } |
| 4109 | |
| 4110 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4111 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
| 4112 | * @adapter: board private structure |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4113 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4114 | * |
| 4115 | * Returns 0 on success, negative on failure |
| 4116 | **/ |
| 4117 | int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4118 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4119 | { |
| 4120 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4121 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4122 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4123 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 4124 | rx_ring->rx_buffer_info = vmalloc(size); |
| 4125 | if (!rx_ring->rx_buffer_info) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4126 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4127 | "vmalloc allocation failed for the rx desc ring\n"); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4128 | goto alloc_failed; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4129 | } |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4130 | memset(rx_ring->rx_buffer_info, 0, size); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4131 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4132 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4133 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 4134 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
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 | 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] | 4137 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4138 | if (!rx_ring->desc) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4139 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4140 | "Memory allocation failed for the rx desc ring\n"); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4141 | vfree(rx_ring->rx_buffer_info); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4142 | goto alloc_failed; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4143 | } |
| 4144 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 4145 | rx_ring->next_to_clean = 0; |
| 4146 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4147 | |
| 4148 | return 0; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4149 | |
| 4150 | alloc_failed: |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 4151 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4152 | } |
| 4153 | |
| 4154 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4155 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 4156 | * @adapter: board private structure |
| 4157 | * |
| 4158 | * If this function returns with an error, then it's possible one or |
| 4159 | * more of the rings is populated (while the rest are not). It is the |
| 4160 | * callers duty to clean those orphaned rings. |
| 4161 | * |
| 4162 | * Return 0 on success, negative on failure |
| 4163 | **/ |
| 4164 | |
| 4165 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 4166 | { |
| 4167 | int i, err = 0; |
| 4168 | |
| 4169 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 4170 | err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]); |
| 4171 | if (!err) |
| 4172 | continue; |
| 4173 | DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i); |
| 4174 | break; |
| 4175 | } |
| 4176 | |
| 4177 | return err; |
| 4178 | } |
| 4179 | |
| 4180 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4181 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
| 4182 | * @adapter: board private structure |
| 4183 | * @tx_ring: Tx descriptor ring for a specific queue |
| 4184 | * |
| 4185 | * Free all transmit software resources |
| 4186 | **/ |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 4187 | void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter, |
| 4188 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4189 | { |
| 4190 | struct pci_dev *pdev = adapter->pdev; |
| 4191 | |
| 4192 | ixgbe_clean_tx_ring(adapter, tx_ring); |
| 4193 | |
| 4194 | vfree(tx_ring->tx_buffer_info); |
| 4195 | tx_ring->tx_buffer_info = NULL; |
| 4196 | |
| 4197 | pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); |
| 4198 | |
| 4199 | tx_ring->desc = NULL; |
| 4200 | } |
| 4201 | |
| 4202 | /** |
| 4203 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 4204 | * @adapter: board private structure |
| 4205 | * |
| 4206 | * Free all transmit software resources |
| 4207 | **/ |
| 4208 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 4209 | { |
| 4210 | int i; |
| 4211 | |
| 4212 | for (i = 0; i < adapter->num_tx_queues; i++) |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 4213 | if (adapter->tx_ring[i].desc) |
| 4214 | ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4215 | } |
| 4216 | |
| 4217 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4218 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4219 | * @adapter: board private structure |
| 4220 | * @rx_ring: ring to clean the resources from |
| 4221 | * |
| 4222 | * Free all receive software resources |
| 4223 | **/ |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 4224 | void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter, |
| 4225 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4226 | { |
| 4227 | struct pci_dev *pdev = adapter->pdev; |
| 4228 | |
| 4229 | ixgbe_clean_rx_ring(adapter, rx_ring); |
| 4230 | |
| 4231 | vfree(rx_ring->rx_buffer_info); |
| 4232 | rx_ring->rx_buffer_info = NULL; |
| 4233 | |
| 4234 | pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); |
| 4235 | |
| 4236 | rx_ring->desc = NULL; |
| 4237 | } |
| 4238 | |
| 4239 | /** |
| 4240 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 4241 | * @adapter: board private structure |
| 4242 | * |
| 4243 | * Free all receive software resources |
| 4244 | **/ |
| 4245 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 4246 | { |
| 4247 | int i; |
| 4248 | |
| 4249 | for (i = 0; i < adapter->num_rx_queues; i++) |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 4250 | if (adapter->rx_ring[i].desc) |
| 4251 | ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4252 | } |
| 4253 | |
| 4254 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4255 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 4256 | * @netdev: network interface device structure |
| 4257 | * @new_mtu: new value for maximum frame size |
| 4258 | * |
| 4259 | * Returns 0 on success, negative on failure |
| 4260 | **/ |
| 4261 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 4262 | { |
| 4263 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4264 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 4265 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 4266 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 4267 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4268 | return -EINVAL; |
| 4269 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4270 | DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n", |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4271 | netdev->mtu, new_mtu); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4272 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4273 | netdev->mtu = new_mtu; |
| 4274 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4275 | if (netif_running(netdev)) |
| 4276 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4277 | |
| 4278 | return 0; |
| 4279 | } |
| 4280 | |
| 4281 | /** |
| 4282 | * ixgbe_open - Called when a network interface is made active |
| 4283 | * @netdev: network interface device structure |
| 4284 | * |
| 4285 | * Returns 0 on success, negative value on failure |
| 4286 | * |
| 4287 | * The open entry point is called when a network interface is made |
| 4288 | * active by the system (IFF_UP). At this point all resources needed |
| 4289 | * for transmit and receive operations are allocated, the interrupt |
| 4290 | * handler is registered with the OS, the watchdog timer is started, |
| 4291 | * and the stack is notified that the interface is ready. |
| 4292 | **/ |
| 4293 | static int ixgbe_open(struct net_device *netdev) |
| 4294 | { |
| 4295 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4296 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4297 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 4298 | /* disallow open during test */ |
| 4299 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 4300 | return -EBUSY; |
| 4301 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 4302 | netif_carrier_off(netdev); |
| 4303 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4304 | /* allocate transmit descriptors */ |
| 4305 | err = ixgbe_setup_all_tx_resources(adapter); |
| 4306 | if (err) |
| 4307 | goto err_setup_tx; |
| 4308 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4309 | /* allocate receive descriptors */ |
| 4310 | err = ixgbe_setup_all_rx_resources(adapter); |
| 4311 | if (err) |
| 4312 | goto err_setup_rx; |
| 4313 | |
| 4314 | ixgbe_configure(adapter); |
| 4315 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4316 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4317 | if (err) |
| 4318 | goto err_req_irq; |
| 4319 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4320 | err = ixgbe_up_complete(adapter); |
| 4321 | if (err) |
| 4322 | goto err_up; |
| 4323 | |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 4324 | netif_tx_start_all_queues(netdev); |
| 4325 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4326 | return 0; |
| 4327 | |
| 4328 | err_up: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 4329 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4330 | ixgbe_free_irq(adapter); |
| 4331 | err_req_irq: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4332 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 4333 | ixgbe_free_all_rx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4334 | err_setup_tx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 4335 | ixgbe_free_all_tx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4336 | ixgbe_reset(adapter); |
| 4337 | |
| 4338 | return err; |
| 4339 | } |
| 4340 | |
| 4341 | /** |
| 4342 | * ixgbe_close - Disables a network interface |
| 4343 | * @netdev: network interface device structure |
| 4344 | * |
| 4345 | * Returns 0, this is not allowed to fail |
| 4346 | * |
| 4347 | * The close entry point is called when an interface is de-activated |
| 4348 | * by the OS. The hardware is still under the drivers control, but |
| 4349 | * needs to be disabled. A global MAC reset is issued to stop the |
| 4350 | * hardware, and all transmit and receive resources are freed. |
| 4351 | **/ |
| 4352 | static int ixgbe_close(struct net_device *netdev) |
| 4353 | { |
| 4354 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4355 | |
| 4356 | ixgbe_down(adapter); |
| 4357 | ixgbe_free_irq(adapter); |
| 4358 | |
| 4359 | ixgbe_free_all_tx_resources(adapter); |
| 4360 | ixgbe_free_all_rx_resources(adapter); |
| 4361 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 4362 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4363 | |
| 4364 | return 0; |
| 4365 | } |
| 4366 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4367 | #ifdef CONFIG_PM |
| 4368 | static int ixgbe_resume(struct pci_dev *pdev) |
| 4369 | { |
| 4370 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4371 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4372 | u32 err; |
| 4373 | |
| 4374 | pci_set_power_state(pdev, PCI_D0); |
| 4375 | pci_restore_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 4376 | |
| 4377 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4378 | if (err) { |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4379 | printk(KERN_ERR "ixgbe: Cannot enable PCI device from " |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4380 | "suspend\n"); |
| 4381 | return err; |
| 4382 | } |
| 4383 | pci_set_master(pdev); |
| 4384 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 4385 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4386 | |
| 4387 | err = ixgbe_init_interrupt_scheme(adapter); |
| 4388 | if (err) { |
| 4389 | printk(KERN_ERR "ixgbe: Cannot initialize interrupts for " |
| 4390 | "device\n"); |
| 4391 | return err; |
| 4392 | } |
| 4393 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4394 | ixgbe_reset(adapter); |
| 4395 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 4396 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 4397 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4398 | if (netif_running(netdev)) { |
| 4399 | err = ixgbe_open(adapter->netdev); |
| 4400 | if (err) |
| 4401 | return err; |
| 4402 | } |
| 4403 | |
| 4404 | netif_device_attach(netdev); |
| 4405 | |
| 4406 | return 0; |
| 4407 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4408 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4409 | |
| 4410 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4411 | { |
| 4412 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4413 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4414 | struct ixgbe_hw *hw = &adapter->hw; |
| 4415 | u32 ctrl, fctrl; |
| 4416 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4417 | #ifdef CONFIG_PM |
| 4418 | int retval = 0; |
| 4419 | #endif |
| 4420 | |
| 4421 | netif_device_detach(netdev); |
| 4422 | |
| 4423 | if (netif_running(netdev)) { |
| 4424 | ixgbe_down(adapter); |
| 4425 | ixgbe_free_irq(adapter); |
| 4426 | ixgbe_free_all_tx_resources(adapter); |
| 4427 | ixgbe_free_all_rx_resources(adapter); |
| 4428 | } |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4429 | ixgbe_clear_interrupt_scheme(adapter); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4430 | |
| 4431 | #ifdef CONFIG_PM |
| 4432 | retval = pci_save_state(pdev); |
| 4433 | if (retval) |
| 4434 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4435 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4436 | #endif |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4437 | if (wufc) { |
| 4438 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4439 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4440 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 4441 | if (wufc & IXGBE_WUFC_MC) { |
| 4442 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 4443 | fctrl |= IXGBE_FCTRL_MPE; |
| 4444 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 4445 | } |
| 4446 | |
| 4447 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 4448 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 4449 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 4450 | |
| 4451 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 4452 | } else { |
| 4453 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 4454 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 4455 | } |
| 4456 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 4457 | if (wufc && hw->mac.type == ixgbe_mac_82599EB) |
| 4458 | pci_wake_from_d3(pdev, true); |
| 4459 | else |
| 4460 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4461 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4462 | *enable_wake = !!wufc; |
| 4463 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4464 | ixgbe_release_hw_control(adapter); |
| 4465 | |
| 4466 | pci_disable_device(pdev); |
| 4467 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4468 | return 0; |
| 4469 | } |
| 4470 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4471 | #ifdef CONFIG_PM |
| 4472 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 4473 | { |
| 4474 | int retval; |
| 4475 | bool wake; |
| 4476 | |
| 4477 | retval = __ixgbe_shutdown(pdev, &wake); |
| 4478 | if (retval) |
| 4479 | return retval; |
| 4480 | |
| 4481 | if (wake) { |
| 4482 | pci_prepare_to_sleep(pdev); |
| 4483 | } else { |
| 4484 | pci_wake_from_d3(pdev, false); |
| 4485 | pci_set_power_state(pdev, PCI_D3hot); |
| 4486 | } |
| 4487 | |
| 4488 | return 0; |
| 4489 | } |
| 4490 | #endif /* CONFIG_PM */ |
| 4491 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4492 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 4493 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4494 | bool wake; |
| 4495 | |
| 4496 | __ixgbe_shutdown(pdev, &wake); |
| 4497 | |
| 4498 | if (system_state == SYSTEM_POWER_OFF) { |
| 4499 | pci_wake_from_d3(pdev, wake); |
| 4500 | pci_set_power_state(pdev, PCI_D3hot); |
| 4501 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4502 | } |
| 4503 | |
| 4504 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4505 | * ixgbe_update_stats - Update the board statistics counters. |
| 4506 | * @adapter: board private structure |
| 4507 | **/ |
| 4508 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 4509 | { |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4510 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4511 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4512 | u64 total_mpc = 0; |
| 4513 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4514 | |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 4515 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 4516 | u64 rsc_count = 0; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 4517 | u64 rsc_flush = 0; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 4518 | for (i = 0; i < 16; i++) |
| 4519 | adapter->hw_rx_no_dma_resources += |
| 4520 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 4521 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 4522 | rsc_count += adapter->rx_ring[i].rsc_count; |
Mallikarjuna R Chilakala | 94b982b | 2009-11-23 06:32:06 +0000 | [diff] [blame] | 4523 | rsc_flush += adapter->rx_ring[i].rsc_flush; |
| 4524 | } |
| 4525 | adapter->rsc_total_count = rsc_count; |
| 4526 | adapter->rsc_total_flush = rsc_flush; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 4527 | } |
| 4528 | |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 4529 | /* gather some stats to the adapter struct that are per queue */ |
| 4530 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 4531 | adapter->restart_queue += adapter->tx_ring[i].restart_queue; |
| 4532 | |
| 4533 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4534 | adapter->non_eop_descs += adapter->tx_ring[i].non_eop_descs; |
| 4535 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4536 | adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4537 | for (i = 0; i < 8; i++) { |
| 4538 | /* for packet buffers not used, the register should read 0 */ |
| 4539 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 4540 | missed_rx += mpc; |
| 4541 | adapter->stats.mpc[i] += mpc; |
| 4542 | total_mpc += adapter->stats.mpc[i]; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4543 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4544 | adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4545 | adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 4546 | adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 4547 | adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 4548 | adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4549 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 4550 | adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw, |
| 4551 | IXGBE_PXONRXCNT(i)); |
| 4552 | adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw, |
| 4553 | IXGBE_PXOFFRXCNT(i)); |
| 4554 | adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4555 | } else { |
| 4556 | adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw, |
| 4557 | IXGBE_PXONRXC(i)); |
| 4558 | adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw, |
| 4559 | IXGBE_PXOFFRXC(i)); |
| 4560 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4561 | adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw, |
| 4562 | IXGBE_PXONTXC(i)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4563 | adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4564 | IXGBE_PXOFFTXC(i)); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4565 | } |
| 4566 | adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
| 4567 | /* work around hardware counting issue */ |
| 4568 | adapter->stats.gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4569 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4570 | /* 82598 hardware only has a 32 bit counter in the high register */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4571 | if (hw->mac.type == ixgbe_mac_82599EB) { |
Ben Greear | aad7191 | 2009-09-30 12:08:16 +0000 | [diff] [blame] | 4572 | u64 tmp; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4573 | adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
Ben Greear | aad7191 | 2009-09-30 12:08:16 +0000 | [diff] [blame] | 4574 | tmp = IXGBE_READ_REG(hw, IXGBE_GORCH) & 0xF; /* 4 high bits of GORC */ |
| 4575 | adapter->stats.gorc += (tmp << 32); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4576 | adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
Ben Greear | aad7191 | 2009-09-30 12:08:16 +0000 | [diff] [blame] | 4577 | tmp = IXGBE_READ_REG(hw, IXGBE_GOTCH) & 0xF; /* 4 high bits of GOTC */ |
| 4578 | adapter->stats.gotc += (tmp << 32); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4579 | adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
| 4580 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
| 4581 | adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
| 4582 | adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4583 | adapter->stats.fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 4584 | adapter->stats.fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 4585 | #ifdef IXGBE_FCOE |
| 4586 | adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 4587 | adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 4588 | adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 4589 | adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 4590 | adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 4591 | adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
| 4592 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4593 | } else { |
| 4594 | adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
| 4595 | adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 4596 | adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 4597 | adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 4598 | adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 4599 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4600 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
| 4601 | adapter->stats.bprc += bprc; |
| 4602 | adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4603 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4604 | adapter->stats.mprc -= bprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4605 | adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 4606 | adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 4607 | adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 4608 | adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 4609 | adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 4610 | adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 4611 | adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4612 | adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4613 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
| 4614 | adapter->stats.lxontxc += lxon; |
| 4615 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
| 4616 | adapter->stats.lxofftxc += lxoff; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4617 | adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 4618 | adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4619 | adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
| 4620 | /* |
| 4621 | * 82598 errata - tx of flow control packets is included in tx counters |
| 4622 | */ |
| 4623 | xon_off_tot = lxon + lxoff; |
| 4624 | adapter->stats.gptc -= xon_off_tot; |
| 4625 | adapter->stats.mptc -= xon_off_tot; |
| 4626 | adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4627 | adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 4628 | adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 4629 | adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4630 | adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 4631 | adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4632 | adapter->stats.ptc64 -= xon_off_tot; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4633 | adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 4634 | adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 4635 | adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 4636 | adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 4637 | adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4638 | adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
| 4639 | |
| 4640 | /* Fill out the OS statistics structure */ |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4641 | netdev->stats.multicast = adapter->stats.mprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4642 | |
| 4643 | /* Rx Errors */ |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4644 | netdev->stats.rx_errors = adapter->stats.crcerrs + |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4645 | adapter->stats.rlec; |
Ajit Khaparde | 2d86f13 | 2009-10-07 02:43:49 +0000 | [diff] [blame] | 4646 | netdev->stats.rx_dropped = 0; |
| 4647 | netdev->stats.rx_length_errors = adapter->stats.rlec; |
| 4648 | netdev->stats.rx_crc_errors = adapter->stats.crcerrs; |
| 4649 | netdev->stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4650 | } |
| 4651 | |
| 4652 | /** |
| 4653 | * ixgbe_watchdog - Timer Call-back |
| 4654 | * @data: pointer to adapter cast into an unsigned long |
| 4655 | **/ |
| 4656 | static void ixgbe_watchdog(unsigned long data) |
| 4657 | { |
| 4658 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4659 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4660 | u64 eics = 0; |
| 4661 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4662 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4663 | /* |
| 4664 | * Do the watchdog outside of interrupt context due to the lovely |
| 4665 | * delays that some of the newer hardware requires |
| 4666 | */ |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 4667 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4668 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 4669 | goto watchdog_short_circuit; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 4670 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4671 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
| 4672 | /* |
| 4673 | * for legacy and MSI interrupts don't set any bits |
| 4674 | * that are enabled for EIAM, because this operation |
| 4675 | * would set *both* EIMS and EICS for any bit in EIAM |
| 4676 | */ |
| 4677 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 4678 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
| 4679 | goto watchdog_reschedule; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4680 | } |
| 4681 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4682 | /* get one bit for every active tx/rx interrupt vector */ |
| 4683 | for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) { |
| 4684 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
| 4685 | if (qv->rxr_count || qv->txr_count) |
| 4686 | eics |= ((u64)1 << i); |
| 4687 | } |
| 4688 | |
| 4689 | /* Cause software interrupt to ensure rx rings are cleaned */ |
| 4690 | ixgbe_irq_rearm_queues(adapter, eics); |
| 4691 | |
| 4692 | watchdog_reschedule: |
| 4693 | /* Reset the timer */ |
| 4694 | mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ)); |
| 4695 | |
| 4696 | watchdog_short_circuit: |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4697 | schedule_work(&adapter->watchdog_task); |
| 4698 | } |
| 4699 | |
| 4700 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4701 | * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber |
| 4702 | * @work: pointer to work_struct containing our data |
| 4703 | **/ |
| 4704 | static void ixgbe_multispeed_fiber_task(struct work_struct *work) |
| 4705 | { |
| 4706 | struct ixgbe_adapter *adapter = container_of(work, |
| 4707 | struct ixgbe_adapter, |
| 4708 | multispeed_fiber_task); |
| 4709 | struct ixgbe_hw *hw = &adapter->hw; |
| 4710 | u32 autoneg; |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 4711 | bool negotiation; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4712 | |
| 4713 | adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK; |
Mallikarjuna R Chilakala | a1f2532 | 2009-06-30 11:44:36 +0000 | [diff] [blame] | 4714 | autoneg = hw->phy.autoneg_advertised; |
| 4715 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
Mallikarjuna R Chilakala | 8620a10 | 2009-09-01 13:49:35 +0000 | [diff] [blame] | 4716 | hw->mac.ops.get_link_capabilities(hw, &autoneg, &negotiation); |
| 4717 | if (hw->mac.ops.setup_link) |
| 4718 | hw->mac.ops.setup_link(hw, autoneg, negotiation, true); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4719 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 4720 | adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK; |
| 4721 | } |
| 4722 | |
| 4723 | /** |
| 4724 | * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module |
| 4725 | * @work: pointer to work_struct containing our data |
| 4726 | **/ |
| 4727 | static void ixgbe_sfp_config_module_task(struct work_struct *work) |
| 4728 | { |
| 4729 | struct ixgbe_adapter *adapter = container_of(work, |
| 4730 | struct ixgbe_adapter, |
| 4731 | sfp_config_module_task); |
| 4732 | struct ixgbe_hw *hw = &adapter->hw; |
| 4733 | u32 err; |
| 4734 | |
| 4735 | adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK; |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 4736 | |
| 4737 | /* Time for electrical oscillations to settle down */ |
| 4738 | msleep(100); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4739 | err = hw->phy.ops.identify_sfp(hw); |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 4740 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4741 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 88d2b81 | 2009-06-30 11:43:55 +0000 | [diff] [blame] | 4742 | dev_err(&adapter->pdev->dev, "failed to initialize because " |
| 4743 | "an unsupported SFP+ module type was detected.\n" |
| 4744 | "Reload the driver after installing a supported " |
| 4745 | "module.\n"); |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 4746 | unregister_netdev(adapter->netdev); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4747 | return; |
| 4748 | } |
| 4749 | hw->mac.ops.setup_sfp(hw); |
| 4750 | |
Tony Breeds | 8d1c3c0 | 2009-04-09 22:29:10 +0000 | [diff] [blame] | 4751 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK)) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4752 | /* This will also work for DA Twinax connections */ |
| 4753 | schedule_work(&adapter->multispeed_fiber_task); |
| 4754 | adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK; |
| 4755 | } |
| 4756 | |
| 4757 | /** |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4758 | * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table |
| 4759 | * @work: pointer to work_struct containing our data |
| 4760 | **/ |
| 4761 | static void ixgbe_fdir_reinit_task(struct work_struct *work) |
| 4762 | { |
| 4763 | struct ixgbe_adapter *adapter = container_of(work, |
| 4764 | struct ixgbe_adapter, |
| 4765 | fdir_reinit_task); |
| 4766 | struct ixgbe_hw *hw = &adapter->hw; |
| 4767 | int i; |
| 4768 | |
| 4769 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 4770 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 4771 | set_bit(__IXGBE_FDIR_INIT_DONE, |
| 4772 | &(adapter->tx_ring[i].reinit_state)); |
| 4773 | } else { |
| 4774 | DPRINTK(PROBE, ERR, "failed to finish FDIR re-initialization, " |
| 4775 | "ignored adding FDIR ATR filters \n"); |
| 4776 | } |
| 4777 | /* Done FDIR Re-initialization, enable transmits */ |
| 4778 | netif_tx_start_all_queues(adapter->netdev); |
| 4779 | } |
| 4780 | |
| 4781 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4782 | * ixgbe_watchdog_task - worker thread to bring link up |
| 4783 | * @work: pointer to work_struct containing our data |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4784 | **/ |
| 4785 | static void ixgbe_watchdog_task(struct work_struct *work) |
| 4786 | { |
| 4787 | struct ixgbe_adapter *adapter = container_of(work, |
| 4788 | struct ixgbe_adapter, |
| 4789 | watchdog_task); |
| 4790 | struct net_device *netdev = adapter->netdev; |
| 4791 | struct ixgbe_hw *hw = &adapter->hw; |
| 4792 | u32 link_speed = adapter->link_speed; |
| 4793 | bool link_up = adapter->link_up; |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 4794 | int i; |
| 4795 | struct ixgbe_ring *tx_ring; |
| 4796 | int some_tx_pending = 0; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4797 | |
| 4798 | adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK; |
| 4799 | |
| 4800 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) { |
| 4801 | 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] | 4802 | if (link_up) { |
| 4803 | #ifdef CONFIG_DCB |
| 4804 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 4805 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 4806 | hw->mac.ops.fc_enable(hw, i); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4807 | } else { |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 4808 | hw->mac.ops.fc_enable(hw, 0); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4809 | } |
| 4810 | #else |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 4811 | hw->mac.ops.fc_enable(hw, 0); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4812 | #endif |
| 4813 | } |
| 4814 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4815 | if (link_up || |
| 4816 | time_after(jiffies, (adapter->link_check_timeout + |
| 4817 | IXGBE_TRY_LINK_TIMEOUT))) { |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4818 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4819 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4820 | } |
| 4821 | adapter->link_up = link_up; |
| 4822 | adapter->link_speed = link_speed; |
| 4823 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4824 | |
| 4825 | if (link_up) { |
| 4826 | if (!netif_carrier_ok(netdev)) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4827 | bool flow_rx, flow_tx; |
| 4828 | |
| 4829 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 4830 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 4831 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
Peter P Waskiewicz Jr | 078788b | 2009-07-16 15:50:32 +0000 | [diff] [blame] | 4832 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 4833 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4834 | } else { |
| 4835 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 4836 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
Peter P Waskiewicz Jr | 078788b | 2009-07-16 15:50:32 +0000 | [diff] [blame] | 4837 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 4838 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4839 | } |
| 4840 | |
Jeff Kirsher | a46e534 | 2008-11-27 00:22:21 -0800 | [diff] [blame] | 4841 | printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, " |
| 4842 | "Flow Control: %s\n", |
| 4843 | netdev->name, |
| 4844 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? |
| 4845 | "10 Gbps" : |
| 4846 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? |
| 4847 | "1 Gbps" : "unknown speed")), |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4848 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 4849 | (flow_rx ? "RX" : |
| 4850 | (flow_tx ? "TX" : "None")))); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4851 | |
| 4852 | netif_carrier_on(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4853 | } else { |
| 4854 | /* Force detection of hung controller */ |
| 4855 | adapter->detect_tx_hung = true; |
| 4856 | } |
| 4857 | } else { |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4858 | adapter->link_up = false; |
| 4859 | adapter->link_speed = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4860 | if (netif_carrier_ok(netdev)) { |
Jeff Kirsher | a46e534 | 2008-11-27 00:22:21 -0800 | [diff] [blame] | 4861 | printk(KERN_INFO "ixgbe: %s NIC Link is Down\n", |
| 4862 | netdev->name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4863 | netif_carrier_off(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4864 | } |
| 4865 | } |
| 4866 | |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 4867 | if (!netif_carrier_ok(netdev)) { |
| 4868 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 4869 | tx_ring = &adapter->tx_ring[i]; |
| 4870 | if (tx_ring->next_to_use != tx_ring->next_to_clean) { |
| 4871 | some_tx_pending = 1; |
| 4872 | break; |
| 4873 | } |
| 4874 | } |
| 4875 | |
| 4876 | if (some_tx_pending) { |
| 4877 | /* We've lost link, so the controller stops DMA, |
| 4878 | * but we've got queued Tx work that's never going |
| 4879 | * to get done, so reset controller to flush Tx. |
| 4880 | * (Do the reset outside of interrupt context). |
| 4881 | */ |
| 4882 | schedule_work(&adapter->reset_task); |
| 4883 | } |
| 4884 | } |
| 4885 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4886 | ixgbe_update_stats(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4887 | adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4888 | } |
| 4889 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4890 | static int ixgbe_tso(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4891 | struct ixgbe_ring *tx_ring, struct sk_buff *skb, |
| 4892 | u32 tx_flags, u8 *hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4893 | { |
| 4894 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 4895 | unsigned int i; |
| 4896 | int err; |
| 4897 | struct ixgbe_tx_buffer *tx_buffer_info; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4898 | u32 vlan_macip_lens = 0, type_tucmd_mlhl; |
| 4899 | u32 mss_l4len_idx, l4len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4900 | |
| 4901 | if (skb_is_gso(skb)) { |
| 4902 | if (skb_header_cloned(skb)) { |
| 4903 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 4904 | if (err) |
| 4905 | return err; |
| 4906 | } |
| 4907 | l4len = tcp_hdrlen(skb); |
| 4908 | *hdr_len += l4len; |
| 4909 | |
Al Viro | 8327d00 | 2007-12-10 18:54:12 +0000 | [diff] [blame] | 4910 | if (skb->protocol == htons(ETH_P_IP)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4911 | struct iphdr *iph = ip_hdr(skb); |
| 4912 | iph->tot_len = 0; |
| 4913 | iph->check = 0; |
| 4914 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4915 | iph->daddr, 0, |
| 4916 | IPPROTO_TCP, |
| 4917 | 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4918 | } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) { |
| 4919 | ipv6_hdr(skb)->payload_len = 0; |
| 4920 | tcp_hdr(skb)->check = |
| 4921 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4922 | &ipv6_hdr(skb)->daddr, |
| 4923 | 0, IPPROTO_TCP, 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4924 | } |
| 4925 | |
| 4926 | i = tx_ring->next_to_use; |
| 4927 | |
| 4928 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4929 | context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i); |
| 4930 | |
| 4931 | /* VLAN MACLEN IPLEN */ |
| 4932 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 4933 | vlan_macip_lens |= |
| 4934 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); |
| 4935 | vlan_macip_lens |= ((skb_network_offset(skb)) << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4936 | IXGBE_ADVTXD_MACLEN_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4937 | *hdr_len += skb_network_offset(skb); |
| 4938 | vlan_macip_lens |= |
| 4939 | (skb_transport_header(skb) - skb_network_header(skb)); |
| 4940 | *hdr_len += |
| 4941 | (skb_transport_header(skb) - skb_network_header(skb)); |
| 4942 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 4943 | context_desc->seqnum_seed = 0; |
| 4944 | |
| 4945 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4946 | type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4947 | IXGBE_ADVTXD_DTYP_CTXT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4948 | |
Al Viro | 8327d00 | 2007-12-10 18:54:12 +0000 | [diff] [blame] | 4949 | if (skb->protocol == htons(ETH_P_IP)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4950 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 4951 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 4952 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); |
| 4953 | |
| 4954 | /* MSS L4LEN IDX */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4955 | mss_l4len_idx = |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4956 | (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT); |
| 4957 | mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT); |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 4958 | /* use index 1 for TSO */ |
| 4959 | mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4960 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 4961 | |
| 4962 | tx_buffer_info->time_stamp = jiffies; |
| 4963 | tx_buffer_info->next_to_watch = i; |
| 4964 | |
| 4965 | i++; |
| 4966 | if (i == tx_ring->count) |
| 4967 | i = 0; |
| 4968 | tx_ring->next_to_use = i; |
| 4969 | |
| 4970 | return true; |
| 4971 | } |
| 4972 | return false; |
| 4973 | } |
| 4974 | |
| 4975 | static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4976 | struct ixgbe_ring *tx_ring, |
| 4977 | struct sk_buff *skb, u32 tx_flags) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4978 | { |
| 4979 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 4980 | unsigned int i; |
| 4981 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 4982 | u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0; |
| 4983 | |
| 4984 | if (skb->ip_summed == CHECKSUM_PARTIAL || |
| 4985 | (tx_flags & IXGBE_TX_FLAGS_VLAN)) { |
| 4986 | i = tx_ring->next_to_use; |
| 4987 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4988 | context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i); |
| 4989 | |
| 4990 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 4991 | vlan_macip_lens |= |
| 4992 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); |
| 4993 | vlan_macip_lens |= (skb_network_offset(skb) << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4994 | IXGBE_ADVTXD_MACLEN_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4995 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 4996 | vlan_macip_lens |= (skb_transport_header(skb) - |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4997 | skb_network_header(skb)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4998 | |
| 4999 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 5000 | context_desc->seqnum_seed = 0; |
| 5001 | |
| 5002 | type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5003 | IXGBE_ADVTXD_DTYP_CTXT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5004 | |
| 5005 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5006 | switch (skb->protocol) { |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 5007 | case cpu_to_be16(ETH_P_IP): |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5008 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5009 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 5010 | type_tucmd_mlhl |= |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5011 | IXGBE_ADVTXD_TUCMD_L4T_TCP; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 5012 | else if (ip_hdr(skb)->protocol == IPPROTO_SCTP) |
| 5013 | type_tucmd_mlhl |= |
| 5014 | IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5015 | break; |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 5016 | case cpu_to_be16(ETH_P_IPV6): |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5017 | /* XXX what about other V6 headers?? */ |
| 5018 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 5019 | type_tucmd_mlhl |= |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5020 | IXGBE_ADVTXD_TUCMD_L4T_TCP; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 5021 | else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP) |
| 5022 | type_tucmd_mlhl |= |
| 5023 | IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5024 | break; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 5025 | default: |
| 5026 | if (unlikely(net_ratelimit())) { |
| 5027 | DPRINTK(PROBE, WARNING, |
| 5028 | "partial checksum but proto=%x!\n", |
| 5029 | skb->protocol); |
| 5030 | } |
| 5031 | break; |
| 5032 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5033 | } |
| 5034 | |
| 5035 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 5036 | /* use index zero for tx checksum offload */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5037 | context_desc->mss_l4len_idx = 0; |
| 5038 | |
| 5039 | tx_buffer_info->time_stamp = jiffies; |
| 5040 | tx_buffer_info->next_to_watch = i; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5041 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5042 | i++; |
| 5043 | if (i == tx_ring->count) |
| 5044 | i = 0; |
| 5045 | tx_ring->next_to_use = i; |
| 5046 | |
| 5047 | return true; |
| 5048 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5049 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5050 | return false; |
| 5051 | } |
| 5052 | |
| 5053 | static int ixgbe_tx_map(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5054 | struct ixgbe_ring *tx_ring, |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5055 | struct sk_buff *skb, u32 tx_flags, |
| 5056 | unsigned int first) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5057 | { |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5058 | struct pci_dev *pdev = adapter->pdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5059 | struct ixgbe_tx_buffer *tx_buffer_info; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5060 | unsigned int len; |
| 5061 | unsigned int total = skb->len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5062 | unsigned int offset = 0, size, count = 0, i; |
| 5063 | unsigned int nr_frags = skb_shinfo(skb)->nr_frags; |
| 5064 | unsigned int f; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5065 | |
| 5066 | i = tx_ring->next_to_use; |
| 5067 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5068 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) |
| 5069 | /* excluding fcoe_crc_eof for FCoE */ |
| 5070 | total -= sizeof(struct fcoe_crc_eof); |
| 5071 | |
| 5072 | len = min(skb_headlen(skb), total); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5073 | while (len) { |
| 5074 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5075 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 5076 | |
| 5077 | tx_buffer_info->length = size; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5078 | tx_buffer_info->mapped_as_page = false; |
| 5079 | tx_buffer_info->dma = pci_map_single(pdev, |
| 5080 | skb->data + offset, |
| 5081 | size, PCI_DMA_TODEVICE); |
| 5082 | if (pci_dma_mapping_error(pdev, tx_buffer_info->dma)) |
| 5083 | goto dma_error; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5084 | tx_buffer_info->time_stamp = jiffies; |
| 5085 | tx_buffer_info->next_to_watch = i; |
| 5086 | |
| 5087 | len -= size; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5088 | total -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5089 | offset += size; |
| 5090 | count++; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5091 | |
| 5092 | if (len) { |
| 5093 | i++; |
| 5094 | if (i == tx_ring->count) |
| 5095 | i = 0; |
| 5096 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5097 | } |
| 5098 | |
| 5099 | for (f = 0; f < nr_frags; f++) { |
| 5100 | struct skb_frag_struct *frag; |
| 5101 | |
| 5102 | frag = &skb_shinfo(skb)->frags[f]; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5103 | len = min((unsigned int)frag->size, total); |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5104 | offset = frag->page_offset; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5105 | |
| 5106 | while (len) { |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5107 | i++; |
| 5108 | if (i == tx_ring->count) |
| 5109 | i = 0; |
| 5110 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5111 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5112 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 5113 | |
| 5114 | tx_buffer_info->length = size; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5115 | tx_buffer_info->dma = pci_map_page(adapter->pdev, |
| 5116 | frag->page, |
| 5117 | offset, size, |
| 5118 | PCI_DMA_TODEVICE); |
| 5119 | tx_buffer_info->mapped_as_page = true; |
| 5120 | if (pci_dma_mapping_error(pdev, tx_buffer_info->dma)) |
| 5121 | goto dma_error; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5122 | tx_buffer_info->time_stamp = jiffies; |
| 5123 | tx_buffer_info->next_to_watch = i; |
| 5124 | |
| 5125 | len -= size; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5126 | total -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5127 | offset += size; |
| 5128 | count++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5129 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5130 | if (total == 0) |
| 5131 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5132 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5133 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5134 | tx_ring->tx_buffer_info[i].skb = skb; |
| 5135 | tx_ring->tx_buffer_info[first].next_to_watch = i; |
| 5136 | |
| 5137 | return count; |
Alexander Duyck | e5a4354 | 2009-12-02 16:46:56 +0000 | [diff] [blame] | 5138 | |
| 5139 | dma_error: |
| 5140 | dev_err(&pdev->dev, "TX DMA map failed\n"); |
| 5141 | |
| 5142 | /* clear timestamp and dma mappings for failed tx_buffer_info map */ |
| 5143 | tx_buffer_info->dma = 0; |
| 5144 | tx_buffer_info->time_stamp = 0; |
| 5145 | tx_buffer_info->next_to_watch = 0; |
| 5146 | count--; |
| 5147 | |
| 5148 | /* clear timestamp and dma mappings for remaining portion of packet */ |
| 5149 | while (count >= 0) { |
| 5150 | count--; |
| 5151 | i--; |
| 5152 | if (i < 0) |
| 5153 | i += tx_ring->count; |
| 5154 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5155 | ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info); |
| 5156 | } |
| 5157 | |
| 5158 | return count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5159 | } |
| 5160 | |
| 5161 | static void ixgbe_tx_queue(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5162 | struct ixgbe_ring *tx_ring, |
| 5163 | int tx_flags, int count, u32 paylen, u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5164 | { |
| 5165 | union ixgbe_adv_tx_desc *tx_desc = NULL; |
| 5166 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 5167 | u32 olinfo_status = 0, cmd_type_len = 0; |
| 5168 | unsigned int i; |
| 5169 | u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS; |
| 5170 | |
| 5171 | cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA; |
| 5172 | |
| 5173 | cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT; |
| 5174 | |
| 5175 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 5176 | cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE; |
| 5177 | |
| 5178 | if (tx_flags & IXGBE_TX_FLAGS_TSO) { |
| 5179 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 5180 | |
| 5181 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5182 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5183 | |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 5184 | /* use index 1 context for tso */ |
| 5185 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5186 | if (tx_flags & IXGBE_TX_FLAGS_IPV4) |
| 5187 | olinfo_status |= IXGBE_TXD_POPTS_IXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5188 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5189 | |
| 5190 | } else if (tx_flags & IXGBE_TX_FLAGS_CSUM) |
| 5191 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5192 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5193 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5194 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 5195 | olinfo_status |= IXGBE_ADVTXD_CC; |
| 5196 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
| 5197 | if (tx_flags & IXGBE_TX_FLAGS_FSO) |
| 5198 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 5199 | } |
| 5200 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5201 | olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT); |
| 5202 | |
| 5203 | i = tx_ring->next_to_use; |
| 5204 | while (count--) { |
| 5205 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5206 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); |
| 5207 | tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma); |
| 5208 | tx_desc->read.cmd_type_len = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5209 | cpu_to_le32(cmd_type_len | tx_buffer_info->length); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5210 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5211 | i++; |
| 5212 | if (i == tx_ring->count) |
| 5213 | i = 0; |
| 5214 | } |
| 5215 | |
| 5216 | tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd); |
| 5217 | |
| 5218 | /* |
| 5219 | * Force memory writes to complete before letting h/w |
| 5220 | * know there are new descriptors to fetch. (Only |
| 5221 | * applicable for weak-ordered memory model archs, |
| 5222 | * such as IA-64). |
| 5223 | */ |
| 5224 | wmb(); |
| 5225 | |
| 5226 | tx_ring->next_to_use = i; |
| 5227 | writel(i, adapter->hw.hw_addr + tx_ring->tail); |
| 5228 | } |
| 5229 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5230 | static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb, |
| 5231 | int queue, u32 tx_flags) |
| 5232 | { |
| 5233 | /* Right now, we support IPv4 only */ |
| 5234 | struct ixgbe_atr_input atr_input; |
| 5235 | struct tcphdr *th; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5236 | struct iphdr *iph = ip_hdr(skb); |
| 5237 | struct ethhdr *eth = (struct ethhdr *)skb->data; |
| 5238 | u16 vlan_id, src_port, dst_port, flex_bytes; |
| 5239 | u32 src_ipv4_addr, dst_ipv4_addr; |
| 5240 | u8 l4type = 0; |
| 5241 | |
| 5242 | /* check if we're UDP or TCP */ |
| 5243 | if (iph->protocol == IPPROTO_TCP) { |
| 5244 | th = tcp_hdr(skb); |
| 5245 | src_port = th->source; |
| 5246 | dst_port = th->dest; |
| 5247 | l4type |= IXGBE_ATR_L4TYPE_TCP; |
| 5248 | /* l4type IPv4 type is 0, no need to assign */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5249 | } else { |
| 5250 | /* Unsupported L4 header, just bail here */ |
| 5251 | return; |
| 5252 | } |
| 5253 | |
| 5254 | memset(&atr_input, 0, sizeof(struct ixgbe_atr_input)); |
| 5255 | |
| 5256 | vlan_id = (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK) >> |
| 5257 | IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5258 | src_ipv4_addr = iph->saddr; |
| 5259 | dst_ipv4_addr = iph->daddr; |
| 5260 | flex_bytes = eth->h_proto; |
| 5261 | |
| 5262 | ixgbe_atr_set_vlan_id_82599(&atr_input, vlan_id); |
| 5263 | ixgbe_atr_set_src_port_82599(&atr_input, dst_port); |
| 5264 | ixgbe_atr_set_dst_port_82599(&atr_input, src_port); |
| 5265 | ixgbe_atr_set_flex_byte_82599(&atr_input, flex_bytes); |
| 5266 | ixgbe_atr_set_l4type_82599(&atr_input, l4type); |
| 5267 | /* src and dst are inverted, think how the receiver sees them */ |
| 5268 | ixgbe_atr_set_src_ipv4_82599(&atr_input, dst_ipv4_addr); |
| 5269 | ixgbe_atr_set_dst_ipv4_82599(&atr_input, src_ipv4_addr); |
| 5270 | |
| 5271 | /* This assumes the Rx queue and Tx queue are bound to the same CPU */ |
| 5272 | ixgbe_fdir_add_signature_filter_82599(&adapter->hw, &atr_input, queue); |
| 5273 | } |
| 5274 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5275 | static int __ixgbe_maybe_stop_tx(struct net_device *netdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5276 | struct ixgbe_ring *tx_ring, int size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5277 | { |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5278 | netif_stop_subqueue(netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5279 | /* Herbert's original patch had: |
| 5280 | * smp_mb__after_netif_stop_queue(); |
| 5281 | * but since that doesn't exist yet, just open code it. */ |
| 5282 | smp_mb(); |
| 5283 | |
| 5284 | /* We need to check again in a case another CPU has just |
| 5285 | * made room available. */ |
| 5286 | if (likely(IXGBE_DESC_UNUSED(tx_ring) < size)) |
| 5287 | return -EBUSY; |
| 5288 | |
| 5289 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
Jesse Brandeburg | af72166 | 2008-09-11 19:54:23 -0700 | [diff] [blame] | 5290 | netif_start_subqueue(netdev, tx_ring->queue_index); |
Jesse Brandeburg | 7ca3bc5 | 2009-12-03 11:33:29 +0000 | [diff] [blame] | 5291 | ++tx_ring->restart_queue; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5292 | return 0; |
| 5293 | } |
| 5294 | |
| 5295 | static int ixgbe_maybe_stop_tx(struct net_device *netdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5296 | struct ixgbe_ring *tx_ring, int size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5297 | { |
| 5298 | if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size)) |
| 5299 | return 0; |
| 5300 | return __ixgbe_maybe_stop_tx(netdev, tx_ring, size); |
| 5301 | } |
| 5302 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5303 | static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb) |
| 5304 | { |
| 5305 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5306 | int txq = smp_processor_id(); |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5307 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5308 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5309 | return txq; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5310 | |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5311 | #ifdef IXGBE_FCOE |
| 5312 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 5313 | (skb->protocol == htons(ETH_P_FCOE))) { |
| 5314 | txq &= (adapter->ring_feature[RING_F_FCOE].indices - 1); |
| 5315 | txq += adapter->ring_feature[RING_F_FCOE].mask; |
| 5316 | return txq; |
| 5317 | } |
| 5318 | #endif |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5319 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
Lucy Liu | 36e89d7 | 2009-08-05 13:06:34 -0700 | [diff] [blame] | 5320 | return (skb->vlan_tci & IXGBE_TX_FLAGS_VLAN_PRIO_MASK) >> 13; |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5321 | |
| 5322 | return skb_tx_hash(dev, skb); |
| 5323 | } |
| 5324 | |
Stephen Hemminger | 3b29a56 | 2009-08-31 19:50:55 +0000 | [diff] [blame] | 5325 | static netdev_tx_t ixgbe_xmit_frame(struct sk_buff *skb, |
| 5326 | struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5327 | { |
| 5328 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5329 | struct ixgbe_ring *tx_ring; |
Eric Dumazet | 60d5113 | 2009-12-08 07:22:03 +0000 | [diff] [blame] | 5330 | struct netdev_queue *txq; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5331 | unsigned int first; |
| 5332 | unsigned int tx_flags = 0; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5333 | u8 hdr_len = 0; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5334 | int tso; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5335 | int count = 0; |
| 5336 | unsigned int f; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5337 | |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5338 | if (adapter->vlgrp && vlan_tx_tag_present(skb)) { |
| 5339 | tx_flags |= vlan_tx_tag_get(skb); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5340 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 5341 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5342 | tx_flags |= ((skb->queue_mapping & 0x7) << 13); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5343 | } |
| 5344 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5345 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
| 5346 | } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 5347 | if (skb->priority != TC_PRIO_CONTROL) { |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5348 | tx_flags |= ((skb->queue_mapping & 0x7) << 13); |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 5349 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5350 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
| 5351 | } else { |
| 5352 | skb->queue_mapping = |
| 5353 | adapter->ring_feature[RING_F_DCB].indices-1; |
| 5354 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5355 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5356 | |
Yi Zou | 5f71582 | 2009-12-03 11:32:44 +0000 | [diff] [blame] | 5357 | tx_ring = &adapter->tx_ring[skb->queue_mapping]; |
Lucy Liu | 6012786 | 2009-07-22 14:07:33 +0000 | [diff] [blame] | 5358 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5359 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
Yi Zou | 09ad1cc | 2009-09-03 14:56:10 +0000 | [diff] [blame] | 5360 | (skb->protocol == htons(ETH_P_FCOE))) { |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5361 | tx_flags |= IXGBE_TX_FLAGS_FCOE; |
Yi Zou | 09ad1cc | 2009-09-03 14:56:10 +0000 | [diff] [blame] | 5362 | #ifdef IXGBE_FCOE |
Yi Zou | 61a0f42 | 2009-12-03 11:32:22 +0000 | [diff] [blame] | 5363 | #ifdef CONFIG_IXGBE_DCB |
| 5364 | tx_flags &= ~(IXGBE_TX_FLAGS_VLAN_PRIO_MASK |
| 5365 | << IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 5366 | tx_flags |= ((adapter->fcoe.up << 13) |
| 5367 | << IXGBE_TX_FLAGS_VLAN_SHIFT); |
| 5368 | #endif |
Yi Zou | 09ad1cc | 2009-09-03 14:56:10 +0000 | [diff] [blame] | 5369 | #endif |
| 5370 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5371 | /* four things can cause us to need a context descriptor */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5372 | if (skb_is_gso(skb) || |
| 5373 | (skb->ip_summed == CHECKSUM_PARTIAL) || |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5374 | (tx_flags & IXGBE_TX_FLAGS_VLAN) || |
| 5375 | (tx_flags & IXGBE_TX_FLAGS_FCOE)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5376 | count++; |
| 5377 | |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5378 | count += TXD_USE_COUNT(skb_headlen(skb)); |
| 5379 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5380 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
| 5381 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5382 | if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5383 | adapter->tx_busy++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5384 | return NETDEV_TX_BUSY; |
| 5385 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5386 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5387 | first = tx_ring->next_to_use; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5388 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 5389 | #ifdef IXGBE_FCOE |
| 5390 | /* setup tx offload for FCoE */ |
| 5391 | tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len); |
| 5392 | if (tso < 0) { |
| 5393 | dev_kfree_skb_any(skb); |
| 5394 | return NETDEV_TX_OK; |
| 5395 | } |
| 5396 | if (tso) |
| 5397 | tx_flags |= IXGBE_TX_FLAGS_FSO; |
| 5398 | #endif /* IXGBE_FCOE */ |
| 5399 | } else { |
| 5400 | if (skb->protocol == htons(ETH_P_IP)) |
| 5401 | tx_flags |= IXGBE_TX_FLAGS_IPV4; |
| 5402 | tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len); |
| 5403 | if (tso < 0) { |
| 5404 | dev_kfree_skb_any(skb); |
| 5405 | return NETDEV_TX_OK; |
| 5406 | } |
| 5407 | |
| 5408 | if (tso) |
| 5409 | tx_flags |= IXGBE_TX_FLAGS_TSO; |
| 5410 | else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) && |
| 5411 | (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 5412 | tx_flags |= IXGBE_TX_FLAGS_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5413 | } |
| 5414 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5415 | count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5416 | if (count) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5417 | /* add the ATR filter if ATR is on */ |
| 5418 | if (tx_ring->atr_sample_rate) { |
| 5419 | ++tx_ring->atr_count; |
| 5420 | if ((tx_ring->atr_count >= tx_ring->atr_sample_rate) && |
| 5421 | test_bit(__IXGBE_FDIR_INIT_DONE, |
| 5422 | &tx_ring->reinit_state)) { |
| 5423 | ixgbe_atr(adapter, skb, tx_ring->queue_index, |
| 5424 | tx_flags); |
| 5425 | tx_ring->atr_count = 0; |
| 5426 | } |
| 5427 | } |
Eric Dumazet | 60d5113 | 2009-12-08 07:22:03 +0000 | [diff] [blame] | 5428 | txq = netdev_get_tx_queue(netdev, tx_ring->queue_index); |
| 5429 | txq->tx_bytes += skb->len; |
| 5430 | txq->tx_packets++; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5431 | ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len, |
| 5432 | hdr_len); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5433 | ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5434 | |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5435 | } else { |
| 5436 | dev_kfree_skb_any(skb); |
| 5437 | tx_ring->tx_buffer_info[first].time_stamp = 0; |
| 5438 | tx_ring->next_to_use = first; |
| 5439 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5440 | |
| 5441 | return NETDEV_TX_OK; |
| 5442 | } |
| 5443 | |
| 5444 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5445 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
| 5446 | * @netdev: network interface device structure |
| 5447 | * @p: pointer to an address structure |
| 5448 | * |
| 5449 | * Returns 0 on success, negative on failure |
| 5450 | **/ |
| 5451 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 5452 | { |
| 5453 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5454 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5455 | struct sockaddr *addr = p; |
| 5456 | |
| 5457 | if (!is_valid_ether_addr(addr->sa_data)) |
| 5458 | return -EADDRNOTAVAIL; |
| 5459 | |
| 5460 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5461 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5462 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5463 | 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] | 5464 | |
| 5465 | return 0; |
| 5466 | } |
| 5467 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5468 | static int |
| 5469 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 5470 | { |
| 5471 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5472 | struct ixgbe_hw *hw = &adapter->hw; |
| 5473 | u16 value; |
| 5474 | int rc; |
| 5475 | |
| 5476 | if (prtad != hw->phy.mdio.prtad) |
| 5477 | return -EINVAL; |
| 5478 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 5479 | if (!rc) |
| 5480 | rc = value; |
| 5481 | return rc; |
| 5482 | } |
| 5483 | |
| 5484 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 5485 | u16 addr, u16 value) |
| 5486 | { |
| 5487 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5488 | struct ixgbe_hw *hw = &adapter->hw; |
| 5489 | |
| 5490 | if (prtad != hw->phy.mdio.prtad) |
| 5491 | return -EINVAL; |
| 5492 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 5493 | } |
| 5494 | |
| 5495 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 5496 | { |
| 5497 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5498 | |
| 5499 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 5500 | } |
| 5501 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5502 | /** |
| 5503 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 5504 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5505 | * @netdev: network interface device structure |
| 5506 | * |
| 5507 | * Returns non-zero on failure |
| 5508 | **/ |
| 5509 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
| 5510 | { |
| 5511 | int err = 0; |
| 5512 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 5513 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 5514 | |
| 5515 | if (is_valid_ether_addr(mac->san_addr)) { |
| 5516 | rtnl_lock(); |
| 5517 | err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 5518 | rtnl_unlock(); |
| 5519 | } |
| 5520 | return err; |
| 5521 | } |
| 5522 | |
| 5523 | /** |
| 5524 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 5525 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5526 | * @netdev: network interface device structure |
| 5527 | * |
| 5528 | * Returns non-zero on failure |
| 5529 | **/ |
| 5530 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 5531 | { |
| 5532 | int err = 0; |
| 5533 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 5534 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 5535 | |
| 5536 | if (is_valid_ether_addr(mac->san_addr)) { |
| 5537 | rtnl_lock(); |
| 5538 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 5539 | rtnl_unlock(); |
| 5540 | } |
| 5541 | return err; |
| 5542 | } |
| 5543 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5544 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5545 | /* |
| 5546 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 5547 | * without having to re-enable interrupts. It's not called while |
| 5548 | * the interrupt routine is executing. |
| 5549 | */ |
| 5550 | static void ixgbe_netpoll(struct net_device *netdev) |
| 5551 | { |
| 5552 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 5553 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5554 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5555 | adapter->flags |= IXGBE_FLAG_IN_NETPOLL; |
Peter P Waskiewicz Jr | 8f9a716 | 2009-07-30 12:25:09 +0000 | [diff] [blame] | 5556 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 5557 | int num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 5558 | for (i = 0; i < num_q_vectors; i++) { |
| 5559 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
| 5560 | ixgbe_msix_clean_many(0, q_vector); |
| 5561 | } |
| 5562 | } else { |
| 5563 | ixgbe_intr(adapter->pdev->irq, netdev); |
| 5564 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5565 | adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5566 | } |
| 5567 | #endif |
| 5568 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5569 | static const struct net_device_ops ixgbe_netdev_ops = { |
| 5570 | .ndo_open = ixgbe_open, |
| 5571 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 5572 | .ndo_start_xmit = ixgbe_xmit_frame, |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5573 | .ndo_select_queue = ixgbe_select_queue, |
Chris Leech | e90d400 | 2009-03-10 16:00:24 +0000 | [diff] [blame] | 5574 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5575 | .ndo_set_multicast_list = ixgbe_set_rx_mode, |
| 5576 | .ndo_validate_addr = eth_validate_addr, |
| 5577 | .ndo_set_mac_address = ixgbe_set_mac, |
| 5578 | .ndo_change_mtu = ixgbe_change_mtu, |
| 5579 | .ndo_tx_timeout = ixgbe_tx_timeout, |
| 5580 | .ndo_vlan_rx_register = ixgbe_vlan_rx_register, |
| 5581 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 5582 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5583 | .ndo_do_ioctl = ixgbe_ioctl, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5584 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5585 | .ndo_poll_controller = ixgbe_netpoll, |
| 5586 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 5587 | #ifdef IXGBE_FCOE |
| 5588 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
| 5589 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
Yi Zou | 8450ff8 | 2009-08-31 12:32:14 +0000 | [diff] [blame] | 5590 | .ndo_fcoe_enable = ixgbe_fcoe_enable, |
| 5591 | .ndo_fcoe_disable = ixgbe_fcoe_disable, |
Yi Zou | 61a1fa1 | 2009-10-28 18:24:56 +0000 | [diff] [blame] | 5592 | .ndo_fcoe_get_wwn = ixgbe_fcoe_get_wwn, |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 5593 | #endif /* IXGBE_FCOE */ |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5594 | }; |
| 5595 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5596 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5597 | * ixgbe_probe - Device Initialization Routine |
| 5598 | * @pdev: PCI device information struct |
| 5599 | * @ent: entry in ixgbe_pci_tbl |
| 5600 | * |
| 5601 | * Returns 0 on success, negative on failure |
| 5602 | * |
| 5603 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 5604 | * The OS initialization, configuring of the adapter private structure, |
| 5605 | * and a hardware reset occur. |
| 5606 | **/ |
| 5607 | static int __devinit ixgbe_probe(struct pci_dev *pdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5608 | const struct pci_device_id *ent) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5609 | { |
| 5610 | struct net_device *netdev; |
| 5611 | struct ixgbe_adapter *adapter = NULL; |
| 5612 | struct ixgbe_hw *hw; |
| 5613 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5614 | static int cards_found; |
| 5615 | int i, err, pci_using_dac; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5616 | #ifdef IXGBE_FCOE |
| 5617 | u16 device_caps; |
| 5618 | #endif |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5619 | u32 part_num, eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5620 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5621 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5622 | if (err) |
| 5623 | return err; |
| 5624 | |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 5625 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
| 5626 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5627 | pci_using_dac = 1; |
| 5628 | } else { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5629 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5630 | if (err) { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5631 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5632 | if (err) { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5633 | dev_err(&pdev->dev, "No usable DMA " |
| 5634 | "configuration, aborting\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5635 | goto err_dma; |
| 5636 | } |
| 5637 | } |
| 5638 | pci_using_dac = 0; |
| 5639 | } |
| 5640 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5641 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
| 5642 | IORESOURCE_MEM), ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5643 | if (err) { |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5644 | dev_err(&pdev->dev, |
| 5645 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5646 | goto err_pci_reg; |
| 5647 | } |
| 5648 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 5649 | pci_enable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5650 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5651 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 5652 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5653 | |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5654 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5655 | if (!netdev) { |
| 5656 | err = -ENOMEM; |
| 5657 | goto err_alloc_etherdev; |
| 5658 | } |
| 5659 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5660 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 5661 | |
| 5662 | pci_set_drvdata(pdev, netdev); |
| 5663 | adapter = netdev_priv(netdev); |
| 5664 | |
| 5665 | adapter->netdev = netdev; |
| 5666 | adapter->pdev = pdev; |
| 5667 | hw = &adapter->hw; |
| 5668 | hw->back = adapter; |
| 5669 | adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
| 5670 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 5671 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
| 5672 | pci_resource_len(pdev, 0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5673 | if (!hw->hw_addr) { |
| 5674 | err = -EIO; |
| 5675 | goto err_ioremap; |
| 5676 | } |
| 5677 | |
| 5678 | for (i = 1; i <= 5; i++) { |
| 5679 | if (pci_resource_len(pdev, i) == 0) |
| 5680 | continue; |
| 5681 | } |
| 5682 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5683 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5684 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5685 | netdev->watchdog_timeo = 5 * HZ; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5686 | strcpy(netdev->name, pci_name(pdev)); |
| 5687 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5688 | adapter->bd_number = cards_found; |
| 5689 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5690 | /* Setup hw api */ |
| 5691 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5692 | hw->mac.type = ii->mac; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5693 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5694 | /* EEPROM */ |
| 5695 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); |
| 5696 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 5697 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
| 5698 | if (!(eec & (1 << 8))) |
| 5699 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 5700 | |
| 5701 | /* PHY */ |
| 5702 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5703 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5704 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 5705 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 5706 | hw->phy.mdio.mmds = 0; |
| 5707 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 5708 | hw->phy.mdio.dev = netdev; |
| 5709 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 5710 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5711 | |
| 5712 | /* set up this timer and work struct before calling get_invariants |
| 5713 | * which might start the timer |
| 5714 | */ |
| 5715 | init_timer(&adapter->sfp_timer); |
| 5716 | adapter->sfp_timer.function = &ixgbe_sfp_timer; |
| 5717 | adapter->sfp_timer.data = (unsigned long) adapter; |
| 5718 | |
| 5719 | INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5720 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5721 | /* multispeed fiber has its own tasklet, called from GPI SDP1 context */ |
| 5722 | INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task); |
| 5723 | |
| 5724 | /* a new SFP+ module arrival, called from GPI SDP2 context */ |
| 5725 | INIT_WORK(&adapter->sfp_config_module_task, |
| 5726 | ixgbe_sfp_config_module_task); |
| 5727 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5728 | ii->get_invariants(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5729 | |
| 5730 | /* setup the private structure */ |
| 5731 | err = ixgbe_sw_init(adapter); |
| 5732 | if (err) |
| 5733 | goto err_sw_init; |
| 5734 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5735 | /* |
| 5736 | * If there is a fan on this device and it has failed log the |
| 5737 | * failure. |
| 5738 | */ |
| 5739 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 5740 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 5741 | if (esdp & IXGBE_ESDP_SDP1) |
| 5742 | DPRINTK(PROBE, CRIT, |
| 5743 | "Fan has stopped, replace the adapter\n"); |
| 5744 | } |
| 5745 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5746 | /* reset_hw fills in the perm_addr as well */ |
| 5747 | err = hw->mac.ops.reset_hw(hw); |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5748 | if (err == IXGBE_ERR_SFP_NOT_PRESENT && |
| 5749 | hw->mac.type == ixgbe_mac_82598EB) { |
| 5750 | /* |
| 5751 | * Start a kernel thread to watch for a module to arrive. |
| 5752 | * Only do this for 82598, since 82599 will generate |
| 5753 | * interrupts on module arrival. |
| 5754 | */ |
| 5755 | set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 5756 | mod_timer(&adapter->sfp_timer, |
| 5757 | round_jiffies(jiffies + (2 * HZ))); |
| 5758 | err = 0; |
| 5759 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 88d2b81 | 2009-06-30 11:43:55 +0000 | [diff] [blame] | 5760 | dev_err(&adapter->pdev->dev, "failed to initialize because " |
| 5761 | "an unsupported SFP+ module type was detected.\n" |
| 5762 | "Reload the driver after installing a supported " |
| 5763 | "module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 5764 | goto err_sw_init; |
| 5765 | } else if (err) { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5766 | dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err); |
| 5767 | goto err_sw_init; |
| 5768 | } |
| 5769 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5770 | netdev->features = NETIF_F_SG | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5771 | NETIF_F_IP_CSUM | |
| 5772 | NETIF_F_HW_VLAN_TX | |
| 5773 | NETIF_F_HW_VLAN_RX | |
| 5774 | NETIF_F_HW_VLAN_FILTER; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5775 | |
Jesse Brandeburg | e9990a9 | 2008-08-26 04:27:24 -0700 | [diff] [blame] | 5776 | netdev->features |= NETIF_F_IPV6_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5777 | netdev->features |= NETIF_F_TSO; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5778 | netdev->features |= NETIF_F_TSO6; |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 5779 | netdev->features |= NETIF_F_GRO; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 5780 | |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 5781 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 5782 | netdev->features |= NETIF_F_SCTP_CSUM; |
| 5783 | |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 5784 | netdev->vlan_features |= NETIF_F_TSO; |
| 5785 | netdev->vlan_features |= NETIF_F_TSO6; |
Jesse Brandeburg | 22f32b7a5 | 2008-08-26 04:27:18 -0700 | [diff] [blame] | 5786 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Alexander Duyck | cd1da50 | 2009-08-25 04:47:50 +0000 | [diff] [blame] | 5787 | netdev->vlan_features |= NETIF_F_IPV6_CSUM; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 5788 | netdev->vlan_features |= NETIF_F_SG; |
| 5789 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5790 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 5791 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
| 5792 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5793 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5794 | netdev->dcbnl_ops = &dcbnl_ops; |
| 5795 | #endif |
| 5796 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5797 | #ifdef IXGBE_FCOE |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 5798 | if (adapter->flags & IXGBE_FLAG_FCOE_CAPABLE) { |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5799 | if (hw->mac.ops.get_device_caps) { |
| 5800 | hw->mac.ops.get_device_caps(hw, &device_caps); |
Yi Zou | 0d55158 | 2009-07-22 14:07:12 +0000 | [diff] [blame] | 5801 | if (device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS) |
| 5802 | adapter->flags &= ~IXGBE_FLAG_FCOE_CAPABLE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5803 | } |
| 5804 | } |
| 5805 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5806 | if (pci_using_dac) |
| 5807 | netdev->features |= NETIF_F_HIGHDMA; |
| 5808 | |
Peter P Waskiewicz Jr | 0c19d6a | 2009-07-30 12:25:28 +0000 | [diff] [blame] | 5809 | if (adapter->flags2 & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5810 | netdev->features |= NETIF_F_LRO; |
| 5811 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5812 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5813 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5814 | dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n"); |
| 5815 | err = -EIO; |
| 5816 | goto err_eeprom; |
| 5817 | } |
| 5818 | |
| 5819 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
| 5820 | memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len); |
| 5821 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5822 | if (ixgbe_validate_mac_addr(netdev->perm_addr)) { |
| 5823 | dev_err(&pdev->dev, "invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5824 | err = -EIO; |
| 5825 | goto err_eeprom; |
| 5826 | } |
| 5827 | |
| 5828 | init_timer(&adapter->watchdog_timer); |
| 5829 | adapter->watchdog_timer.function = &ixgbe_watchdog; |
| 5830 | adapter->watchdog_timer.data = (unsigned long)adapter; |
| 5831 | |
| 5832 | INIT_WORK(&adapter->reset_task, ixgbe_reset_task); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5833 | INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5834 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5835 | err = ixgbe_init_interrupt_scheme(adapter); |
| 5836 | if (err) |
| 5837 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5838 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5839 | switch (pdev->device) { |
| 5840 | case IXGBE_DEV_ID_82599_KX4: |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 5841 | adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX | |
| 5842 | IXGBE_WUFC_MC | IXGBE_WUFC_BC); |
Peter P Waskiewicz Jr | bdf0a55 | 2009-06-04 11:09:58 +0000 | [diff] [blame] | 5843 | /* Enable ACPI wakeup in GRC */ |
| 5844 | IXGBE_WRITE_REG(hw, IXGBE_GRC, |
| 5845 | (IXGBE_READ_REG(hw, IXGBE_GRC) & ~IXGBE_GRC_APME)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5846 | break; |
| 5847 | default: |
| 5848 | adapter->wol = 0; |
| 5849 | break; |
| 5850 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5851 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 5852 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 5853 | /* pick up the PCI bus settings for reporting later */ |
| 5854 | hw->mac.ops.get_bus_info(hw); |
| 5855 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5856 | /* print bus type/speed/width info */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 5857 | dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n", |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5858 | ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s": |
| 5859 | (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"), |
| 5860 | ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" : |
| 5861 | (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" : |
| 5862 | (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" : |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5863 | "Unknown"), |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 5864 | netdev->dev_addr); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5865 | ixgbe_read_pba_num_generic(hw, &part_num); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5866 | if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present) |
| 5867 | dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n", |
| 5868 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
| 5869 | (part_num >> 8), (part_num & 0xff)); |
| 5870 | else |
| 5871 | dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n", |
| 5872 | hw->mac.type, hw->phy.type, |
| 5873 | (part_num >> 8), (part_num & 0xff)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5874 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5875 | if (hw->bus.width <= ixgbe_bus_width_pcie_x4) { |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 5876 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5877 | "this card is not sufficient for optimal " |
| 5878 | "performance.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 5879 | dev_warn(&pdev->dev, "For optimal performance a x8 " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5880 | "PCI-Express slot is required.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 5881 | } |
| 5882 | |
Peter P Waskiewicz Jr | 34b0368 | 2009-02-05 23:54:42 -0800 | [diff] [blame] | 5883 | /* save off EEPROM version number */ |
| 5884 | hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version); |
| 5885 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5886 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5887 | err = hw->mac.ops.start_hw(hw); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5888 | |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5889 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 5890 | /* We are running on a pre-production device, log a warning */ |
| 5891 | dev_warn(&pdev->dev, "This device is a pre-production " |
| 5892 | "adapter/LOM. Please be aware there may be issues " |
| 5893 | "associated with your hardware. If you are " |
| 5894 | "experiencing problems please contact your Intel or " |
| 5895 | "hardware representative who provided you with this " |
| 5896 | "hardware.\n"); |
| 5897 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5898 | strcpy(netdev->name, "eth%d"); |
| 5899 | err = register_netdev(netdev); |
| 5900 | if (err) |
| 5901 | goto err_register; |
| 5902 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 5903 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 5904 | netif_carrier_off(netdev); |
| 5905 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5906 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 5907 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 5908 | INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task); |
| 5909 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 5910 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 5911 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5912 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5913 | ixgbe_setup_dca(adapter); |
| 5914 | } |
| 5915 | #endif |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5916 | /* add san mac addr to netdev */ |
| 5917 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5918 | |
| 5919 | dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n"); |
| 5920 | cards_found++; |
| 5921 | return 0; |
| 5922 | |
| 5923 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5924 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5925 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5926 | err_sw_init: |
| 5927 | err_eeprom: |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5928 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 5929 | del_timer_sync(&adapter->sfp_timer); |
| 5930 | cancel_work_sync(&adapter->sfp_task); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5931 | cancel_work_sync(&adapter->multispeed_fiber_task); |
| 5932 | cancel_work_sync(&adapter->sfp_config_module_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5933 | iounmap(hw->hw_addr); |
| 5934 | err_ioremap: |
| 5935 | free_netdev(netdev); |
| 5936 | err_alloc_etherdev: |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5937 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
| 5938 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5939 | err_pci_reg: |
| 5940 | err_dma: |
| 5941 | pci_disable_device(pdev); |
| 5942 | return err; |
| 5943 | } |
| 5944 | |
| 5945 | /** |
| 5946 | * ixgbe_remove - Device Removal Routine |
| 5947 | * @pdev: PCI device information struct |
| 5948 | * |
| 5949 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 5950 | * that it should release a PCI device. The could be caused by a |
| 5951 | * Hot-Plug event, or because the driver is going to be removed from |
| 5952 | * memory. |
| 5953 | **/ |
| 5954 | static void __devexit ixgbe_remove(struct pci_dev *pdev) |
| 5955 | { |
| 5956 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5957 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5958 | |
| 5959 | set_bit(__IXGBE_DOWN, &adapter->state); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5960 | /* clear the module not found bit to make sure the worker won't |
| 5961 | * reschedule |
| 5962 | */ |
| 5963 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5964 | del_timer_sync(&adapter->watchdog_timer); |
| 5965 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5966 | del_timer_sync(&adapter->sfp_timer); |
| 5967 | cancel_work_sync(&adapter->watchdog_task); |
| 5968 | cancel_work_sync(&adapter->sfp_task); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5969 | cancel_work_sync(&adapter->multispeed_fiber_task); |
| 5970 | cancel_work_sync(&adapter->sfp_config_module_task); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5971 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 5972 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 5973 | cancel_work_sync(&adapter->fdir_reinit_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5974 | flush_scheduled_work(); |
| 5975 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 5976 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5977 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 5978 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 5979 | dca_remove_requester(&pdev->dev); |
| 5980 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 5981 | } |
| 5982 | |
| 5983 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 5984 | #ifdef IXGBE_FCOE |
| 5985 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 5986 | ixgbe_cleanup_fcoe(adapter); |
| 5987 | |
| 5988 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5989 | |
| 5990 | /* remove the added san mac */ |
| 5991 | ixgbe_del_sanmac_netdev(netdev); |
| 5992 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5993 | if (netdev->reg_state == NETREG_REGISTERED) |
| 5994 | unregister_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5995 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5996 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5997 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5998 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5999 | |
| 6000 | iounmap(adapter->hw.hw_addr); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 6001 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
| 6002 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6003 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6004 | DPRINTK(PROBE, INFO, "complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 6005 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6006 | free_netdev(netdev); |
| 6007 | |
Frans Pop | 19d5afd | 2009-10-02 10:04:12 -0700 | [diff] [blame] | 6008 | pci_disable_pcie_error_reporting(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6009 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6010 | pci_disable_device(pdev); |
| 6011 | } |
| 6012 | |
| 6013 | /** |
| 6014 | * ixgbe_io_error_detected - called when PCI error is detected |
| 6015 | * @pdev: Pointer to PCI device |
| 6016 | * @state: The current pci connection state |
| 6017 | * |
| 6018 | * This function is called after a PCI bus error affecting |
| 6019 | * this device has been detected. |
| 6020 | */ |
| 6021 | 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] | 6022 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6023 | { |
| 6024 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 6025 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6026 | |
| 6027 | netif_device_detach(netdev); |
| 6028 | |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 6029 | if (state == pci_channel_io_perm_failure) |
| 6030 | return PCI_ERS_RESULT_DISCONNECT; |
| 6031 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6032 | if (netif_running(netdev)) |
| 6033 | ixgbe_down(adapter); |
| 6034 | pci_disable_device(pdev); |
| 6035 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6036 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6037 | return PCI_ERS_RESULT_NEED_RESET; |
| 6038 | } |
| 6039 | |
| 6040 | /** |
| 6041 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 6042 | * @pdev: Pointer to PCI device |
| 6043 | * |
| 6044 | * Restart the card from scratch, as if from a cold-boot. |
| 6045 | */ |
| 6046 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 6047 | { |
| 6048 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 6049 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6050 | pci_ers_result_t result; |
| 6051 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6052 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 6053 | if (pci_enable_device_mem(pdev)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6054 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6055 | "Cannot re-enable PCI device after reset.\n"); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6056 | result = PCI_ERS_RESULT_DISCONNECT; |
| 6057 | } else { |
| 6058 | pci_set_master(pdev); |
| 6059 | pci_restore_state(pdev); |
Breno Leitao | c0e1f68 | 2009-11-10 08:37:47 +0000 | [diff] [blame] | 6060 | pci_save_state(pdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6061 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 6062 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6063 | |
| 6064 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 6065 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6066 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6067 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6068 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6069 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 6070 | if (err) { |
| 6071 | dev_err(&pdev->dev, |
| 6072 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err); |
| 6073 | /* non-fatal, continue */ |
| 6074 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6075 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 6076 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6077 | } |
| 6078 | |
| 6079 | /** |
| 6080 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 6081 | * @pdev: Pointer to PCI device |
| 6082 | * |
| 6083 | * This callback is called when the error recovery driver tells us that |
| 6084 | * its OK to resume normal operation. |
| 6085 | */ |
| 6086 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 6087 | { |
| 6088 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 6089 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6090 | |
| 6091 | if (netif_running(netdev)) { |
| 6092 | if (ixgbe_up(adapter)) { |
| 6093 | DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n"); |
| 6094 | return; |
| 6095 | } |
| 6096 | } |
| 6097 | |
| 6098 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6099 | } |
| 6100 | |
| 6101 | static struct pci_error_handlers ixgbe_err_handler = { |
| 6102 | .error_detected = ixgbe_io_error_detected, |
| 6103 | .slot_reset = ixgbe_io_slot_reset, |
| 6104 | .resume = ixgbe_io_resume, |
| 6105 | }; |
| 6106 | |
| 6107 | static struct pci_driver ixgbe_driver = { |
| 6108 | .name = ixgbe_driver_name, |
| 6109 | .id_table = ixgbe_pci_tbl, |
| 6110 | .probe = ixgbe_probe, |
| 6111 | .remove = __devexit_p(ixgbe_remove), |
| 6112 | #ifdef CONFIG_PM |
| 6113 | .suspend = ixgbe_suspend, |
| 6114 | .resume = ixgbe_resume, |
| 6115 | #endif |
| 6116 | .shutdown = ixgbe_shutdown, |
| 6117 | .err_handler = &ixgbe_err_handler |
| 6118 | }; |
| 6119 | |
| 6120 | /** |
| 6121 | * ixgbe_init_module - Driver Registration Routine |
| 6122 | * |
| 6123 | * ixgbe_init_module is the first routine called when the driver is |
| 6124 | * loaded. All it does is register with the PCI subsystem. |
| 6125 | **/ |
| 6126 | static int __init ixgbe_init_module(void) |
| 6127 | { |
| 6128 | int ret; |
| 6129 | printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name, |
| 6130 | ixgbe_driver_string, ixgbe_driver_version); |
| 6131 | |
| 6132 | printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright); |
| 6133 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6134 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6135 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6136 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6137 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6138 | ret = pci_register_driver(&ixgbe_driver); |
| 6139 | return ret; |
| 6140 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6141 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6142 | module_init(ixgbe_init_module); |
| 6143 | |
| 6144 | /** |
| 6145 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 6146 | * |
| 6147 | * ixgbe_exit_module is called just before the driver is removed |
| 6148 | * from memory. |
| 6149 | **/ |
| 6150 | static void __exit ixgbe_exit_module(void) |
| 6151 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6152 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6153 | dca_unregister_notify(&dca_notifier); |
| 6154 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6155 | pci_unregister_driver(&ixgbe_driver); |
| 6156 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6157 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 6158 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6159 | 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] | 6160 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6161 | { |
| 6162 | int ret_val; |
| 6163 | |
| 6164 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 6165 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6166 | |
| 6167 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 6168 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 6169 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 6170 | #endif /* CONFIG_IXGBE_DCA */ |
| 6171 | #ifdef DEBUG |
| 6172 | /** |
| 6173 | * ixgbe_get_hw_dev_name - return device name string |
| 6174 | * used by hardware layer to print debugging information |
| 6175 | **/ |
| 6176 | char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw) |
| 6177 | { |
| 6178 | struct ixgbe_adapter *adapter = hw->back; |
| 6179 | return adapter->netdev->name; |
| 6180 | } |
| 6181 | |
| 6182 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 6183 | module_exit(ixgbe_exit_module); |
| 6184 | |
| 6185 | /* ixgbe_main.c */ |