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> |
| 37 | #include <linux/ipv6.h> |
| 38 | #include <net/checksum.h> |
| 39 | #include <net/ip6_checksum.h> |
| 40 | #include <linux/ethtool.h> |
| 41 | #include <linux/if_vlan.h> |
| 42 | |
| 43 | #include "ixgbe.h" |
| 44 | #include "ixgbe_common.h" |
| 45 | |
| 46 | char ixgbe_driver_name[] = "ixgbe"; |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 47 | static const char ixgbe_driver_string[] = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 48 | "Intel(R) 10 Gigabit PCI Express Network Driver"; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 49 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 50 | #define DRV_VERSION "2.0.8-k2" |
Stephen Hemminger | 9c8eb72 | 2007-10-29 10:46:24 -0700 | [diff] [blame] | 51 | const char ixgbe_driver_version[] = DRV_VERSION; |
Peter P Waskiewicz Jr | 3efac5a | 2009-02-01 01:19:20 -0800 | [diff] [blame] | 52 | static char ixgbe_copyright[] = "Copyright (c) 1999-2009 Intel Corporation."; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 53 | |
| 54 | static const struct ixgbe_info *ixgbe_info_tbl[] = { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 55 | [board_82598] = &ixgbe_82598_info, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 56 | [board_82599] = &ixgbe_82599_info, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 57 | }; |
| 58 | |
| 59 | /* ixgbe_pci_tbl - PCI Device ID Table |
| 60 | * |
| 61 | * Wildcard entries (PCI_ANY_ID) should come last |
| 62 | * Last entry must be all 0s |
| 63 | * |
| 64 | * { Vendor ID, Device ID, SubVendor ID, SubDevice ID, |
| 65 | * Class, Class Mask, private data (not used) } |
| 66 | */ |
| 67 | static struct pci_device_id ixgbe_pci_tbl[] = { |
Don Skidmore | 1e336d0 | 2009-01-26 20:57:51 -0800 | [diff] [blame] | 68 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598), |
| 69 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 70 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_DUAL_PORT), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 71 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 72 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AF_SINGLE_PORT), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 73 | board_82598 }, |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 74 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT), |
| 75 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 76 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 77 | board_82598 }, |
Jesse Brandeburg | 8d792cd | 2008-08-08 16:24:19 -0700 | [diff] [blame] | 78 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), |
| 79 | board_82598 }, |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 80 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), |
| 81 | board_82598 }, |
| 82 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), |
| 83 | board_82598 }, |
Jesse Brandeburg | b95f5fc | 2008-09-11 19:58:59 -0700 | [diff] [blame] | 84 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), |
| 85 | board_82598 }, |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 86 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), |
| 87 | board_82598 }, |
Don Skidmore | 2f21bdd | 2009-02-01 01:18:23 -0800 | [diff] [blame] | 88 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), |
| 89 | board_82598 }, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 90 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), |
| 91 | board_82599 }, |
| 92 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), |
| 93 | board_82599 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 94 | |
| 95 | /* required last entry */ |
| 96 | {0, } |
| 97 | }; |
| 98 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 99 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 100 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 101 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 102 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 103 | static struct notifier_block dca_notifier = { |
| 104 | .notifier_call = ixgbe_notify_dca, |
| 105 | .next = NULL, |
| 106 | .priority = 0 |
| 107 | }; |
| 108 | #endif |
| 109 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 110 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 111 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 112 | MODULE_LICENSE("GPL"); |
| 113 | MODULE_VERSION(DRV_VERSION); |
| 114 | |
| 115 | #define DEFAULT_DEBUG_LEVEL_SHIFT 3 |
| 116 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 117 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 118 | { |
| 119 | u32 ctrl_ext; |
| 120 | |
| 121 | /* Let firmware take over control of h/w */ |
| 122 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 123 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 124 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 125 | } |
| 126 | |
| 127 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 128 | { |
| 129 | u32 ctrl_ext; |
| 130 | |
| 131 | /* Let firmware know the driver has taken over */ |
| 132 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 133 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 134 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 135 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 136 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 137 | /* |
| 138 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 139 | * @adapter: pointer to adapter struct |
| 140 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 141 | * @queue: queue to map the corresponding interrupt to |
| 142 | * @msix_vector: the vector to map to the corresponding queue |
| 143 | * |
| 144 | */ |
| 145 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
| 146 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 147 | { |
| 148 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 149 | struct ixgbe_hw *hw = &adapter->hw; |
| 150 | switch (hw->mac.type) { |
| 151 | case ixgbe_mac_82598EB: |
| 152 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 153 | if (direction == -1) |
| 154 | direction = 0; |
| 155 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 156 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 157 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 158 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 159 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 160 | break; |
| 161 | case ixgbe_mac_82599EB: |
| 162 | if (direction == -1) { |
| 163 | /* other causes */ |
| 164 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 165 | index = ((queue & 1) * 8); |
| 166 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 167 | ivar &= ~(0xFF << index); |
| 168 | ivar |= (msix_vector << index); |
| 169 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 170 | break; |
| 171 | } else { |
| 172 | /* tx or rx causes */ |
| 173 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 174 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 175 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 176 | ivar &= ~(0xFF << index); |
| 177 | ivar |= (msix_vector << index); |
| 178 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 179 | break; |
| 180 | } |
| 181 | default: |
| 182 | break; |
| 183 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 184 | } |
| 185 | |
| 186 | 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] | 187 | struct ixgbe_tx_buffer |
| 188 | *tx_buffer_info) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 189 | { |
| 190 | if (tx_buffer_info->dma) { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 191 | pci_unmap_page(adapter->pdev, tx_buffer_info->dma, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 192 | tx_buffer_info->length, PCI_DMA_TODEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 193 | tx_buffer_info->dma = 0; |
| 194 | } |
| 195 | if (tx_buffer_info->skb) { |
| 196 | dev_kfree_skb_any(tx_buffer_info->skb); |
| 197 | tx_buffer_info->skb = NULL; |
| 198 | } |
| 199 | /* tx_buffer_info must be completely set up in the transmit path */ |
| 200 | } |
| 201 | |
| 202 | static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 203 | struct ixgbe_ring *tx_ring, |
| 204 | unsigned int eop) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 205 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 206 | struct ixgbe_hw *hw = &adapter->hw; |
| 207 | u32 head, tail; |
| 208 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 209 | /* Detect a transmit hang in hardware, this serializes the |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 210 | * check with the clearing of time_stamp and movement of eop */ |
| 211 | head = IXGBE_READ_REG(hw, tx_ring->head); |
| 212 | tail = IXGBE_READ_REG(hw, tx_ring->tail); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 213 | adapter->detect_tx_hung = false; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 214 | if ((head != tail) && |
| 215 | tx_ring->tx_buffer_info[eop].time_stamp && |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 216 | time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) && |
| 217 | !(IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)) { |
| 218 | /* detected Tx unit hang */ |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 219 | union ixgbe_adv_tx_desc *tx_desc; |
| 220 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 221 | DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n" |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 222 | " Tx Queue <%d>\n" |
| 223 | " TDH, TDT <%x>, <%x>\n" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 224 | " next_to_use <%x>\n" |
| 225 | " next_to_clean <%x>\n" |
| 226 | "tx_buffer_info[next_to_clean]\n" |
| 227 | " time_stamp <%lx>\n" |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 228 | " jiffies <%lx>\n", |
| 229 | tx_ring->queue_index, |
| 230 | head, tail, |
| 231 | tx_ring->next_to_use, eop, |
| 232 | tx_ring->tx_buffer_info[eop].time_stamp, jiffies); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 233 | return true; |
| 234 | } |
| 235 | |
| 236 | return false; |
| 237 | } |
| 238 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 239 | #define IXGBE_MAX_TXD_PWR 14 |
| 240 | #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 241 | |
| 242 | /* Tx Descriptors needed, worst case */ |
| 243 | #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \ |
| 244 | (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0)) |
| 245 | #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] | 246 | MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 247 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 248 | static void ixgbe_tx_timeout(struct net_device *netdev); |
| 249 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 250 | /** |
| 251 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
| 252 | * @adapter: board private structure |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 253 | * @tx_ring: tx ring to clean |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 254 | * |
| 255 | * returns true if transmit work is done |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 256 | **/ |
| 257 | static bool ixgbe_clean_tx_irq(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 258 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 259 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 260 | struct net_device *netdev = adapter->netdev; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 261 | union ixgbe_adv_tx_desc *tx_desc, *eop_desc; |
| 262 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 263 | unsigned int i, eop, count = 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 264 | unsigned int total_bytes = 0, total_packets = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 265 | |
| 266 | i = tx_ring->next_to_clean; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 267 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
| 268 | eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
| 269 | |
| 270 | while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) && |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 271 | (count < tx_ring->work_limit)) { |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 272 | bool cleaned = false; |
| 273 | for ( ; !cleaned; count++) { |
| 274 | struct sk_buff *skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 275 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); |
| 276 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 277 | cleaned = (i == eop); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 278 | skb = tx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 279 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 280 | if (cleaned && skb) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 281 | unsigned int segs, bytecount; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 282 | |
| 283 | /* gso_segs is currently only valid for tcp */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 284 | segs = skb_shinfo(skb)->gso_segs ?: 1; |
| 285 | /* multiply data chunks by size of headers */ |
| 286 | bytecount = ((segs - 1) * skb_headlen(skb)) + |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 287 | skb->len; |
| 288 | total_packets += segs; |
| 289 | total_bytes += bytecount; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 290 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 291 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 292 | ixgbe_unmap_and_free_tx_resource(adapter, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 293 | tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 294 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 295 | tx_desc->wb.status = 0; |
| 296 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 297 | i++; |
| 298 | if (i == tx_ring->count) |
| 299 | i = 0; |
| 300 | } |
| 301 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 302 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
| 303 | eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
| 304 | } |
| 305 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 306 | tx_ring->next_to_clean = i; |
| 307 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 308 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 309 | if (unlikely(count && netif_carrier_ok(netdev) && |
| 310 | (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 311 | /* Make sure that anybody stopping the queue after this |
| 312 | * sees the new next_to_clean. |
| 313 | */ |
| 314 | smp_mb(); |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 315 | if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) && |
| 316 | !test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 317 | netif_wake_subqueue(netdev, tx_ring->queue_index); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 318 | ++adapter->restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 319 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 320 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 321 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 322 | if (adapter->detect_tx_hung) { |
| 323 | if (ixgbe_check_tx_hang(adapter, tx_ring, i)) { |
| 324 | /* schedule immediate reset if we believe we hung */ |
| 325 | DPRINTK(PROBE, INFO, |
| 326 | "tx hang %d detected, resetting adapter\n", |
| 327 | adapter->tx_timeout_count + 1); |
| 328 | ixgbe_tx_timeout(adapter->netdev); |
| 329 | } |
| 330 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 331 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 332 | /* re-arm the interrupt */ |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 333 | if (count >= tx_ring->work_limit) |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 334 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, tx_ring->v_idx); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 335 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 336 | tx_ring->total_bytes += total_bytes; |
| 337 | tx_ring->total_packets += total_packets; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 338 | tx_ring->stats.packets += total_packets; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 339 | tx_ring->stats.bytes += total_bytes; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 340 | adapter->net_stats.tx_bytes += total_bytes; |
| 341 | adapter->net_stats.tx_packets += total_packets; |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 342 | return (count < tx_ring->work_limit); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 343 | } |
| 344 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 345 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 346 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 347 | struct ixgbe_ring *rx_ring) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 348 | { |
| 349 | u32 rxctrl; |
| 350 | int cpu = get_cpu(); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 351 | int q = rx_ring - adapter->rx_ring; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 352 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 353 | if (rx_ring->cpu != cpu) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 354 | rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 355 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 356 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK; |
| 357 | rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 358 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 359 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599; |
| 360 | rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 361 | IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599); |
| 362 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 363 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 364 | rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN; |
Don Skidmore | 15005a3 | 2009-01-19 16:54:13 -0800 | [diff] [blame] | 365 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN); |
| 366 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 367 | IXGBE_DCA_RXCTRL_DESC_HSRO_EN); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 368 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 369 | rx_ring->cpu = cpu; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 370 | } |
| 371 | put_cpu(); |
| 372 | } |
| 373 | |
| 374 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 375 | struct ixgbe_ring *tx_ring) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 376 | { |
| 377 | u32 txctrl; |
| 378 | int cpu = get_cpu(); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 379 | int q = tx_ring - adapter->tx_ring; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 380 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 381 | if (tx_ring->cpu != cpu) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 382 | txctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 383 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 384 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK; |
| 385 | txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 386 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 387 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599; |
| 388 | txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 389 | IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599); |
| 390 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 391 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 392 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q), txctrl); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 393 | tx_ring->cpu = cpu; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 394 | } |
| 395 | put_cpu(); |
| 396 | } |
| 397 | |
| 398 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 399 | { |
| 400 | int i; |
| 401 | |
| 402 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 403 | return; |
| 404 | |
| 405 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 406 | adapter->tx_ring[i].cpu = -1; |
| 407 | ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]); |
| 408 | } |
| 409 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 410 | adapter->rx_ring[i].cpu = -1; |
| 411 | ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]); |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 416 | { |
| 417 | struct net_device *netdev = dev_get_drvdata(dev); |
| 418 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 419 | unsigned long event = *(unsigned long *)data; |
| 420 | |
| 421 | switch (event) { |
| 422 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 423 | /* if we're already enabled, don't do it again */ |
| 424 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 425 | break; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 426 | /* Always use CB2 mode, difference is masked |
| 427 | * in the CB driver. */ |
| 428 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 429 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 430 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 431 | ixgbe_setup_dca(adapter); |
| 432 | break; |
| 433 | } |
| 434 | /* Fall Through since DCA is disabled. */ |
| 435 | case DCA_PROVIDER_REMOVE: |
| 436 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 437 | dca_remove_requester(dev); |
| 438 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 439 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 440 | } |
| 441 | break; |
| 442 | } |
| 443 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 444 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 445 | } |
| 446 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 447 | #endif /* CONFIG_IXGBE_DCA */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 448 | /** |
| 449 | * ixgbe_receive_skb - Send a completed packet up the stack |
| 450 | * @adapter: board private structure |
| 451 | * @skb: packet to send up |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 452 | * @status: hardware indication of status of receive |
| 453 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
| 454 | * @rx_desc: rx descriptor |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 455 | **/ |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 456 | static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 457 | struct sk_buff *skb, u8 status, |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 458 | union ixgbe_adv_rx_desc *rx_desc) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 459 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 460 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 461 | struct napi_struct *napi = &q_vector->napi; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 462 | bool is_vlan = (status & IXGBE_RXD_STAT_VP); |
| 463 | u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 464 | |
David S. Miller | 0c8dfc8 | 2009-01-27 16:22:32 -0800 | [diff] [blame] | 465 | skb_record_rx_queue(skb, q_vector - &adapter->q_vector[0]); |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 466 | if (skb->ip_summed == CHECKSUM_UNNECESSARY) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 467 | if (adapter->vlgrp && is_vlan && (tag != 0)) |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 468 | vlan_gro_receive(napi, adapter->vlgrp, tag, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 469 | else |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 470 | napi_gro_receive(napi, skb); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 471 | } else { |
| 472 | if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 473 | if (adapter->vlgrp && is_vlan && (tag != 0)) |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 474 | vlan_hwaccel_receive_skb(skb, adapter->vlgrp, tag); |
| 475 | else |
| 476 | netif_receive_skb(skb); |
| 477 | } else { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 478 | if (adapter->vlgrp && is_vlan && (tag != 0)) |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 479 | vlan_hwaccel_rx(skb, adapter->vlgrp, tag); |
| 480 | else |
| 481 | netif_rx(skb); |
| 482 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 483 | } |
| 484 | } |
| 485 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 486 | /** |
| 487 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
| 488 | * @adapter: address of board private structure |
| 489 | * @status_err: hardware indication of status of receive |
| 490 | * @skb: skb currently being received and modified |
| 491 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 492 | static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 493 | u32 status_err, struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 494 | { |
| 495 | skb->ip_summed = CHECKSUM_NONE; |
| 496 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 497 | /* Rx csum disabled */ |
| 498 | if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 499 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 500 | |
| 501 | /* if IP and error */ |
| 502 | if ((status_err & IXGBE_RXD_STAT_IPCS) && |
| 503 | (status_err & IXGBE_RXDADV_ERR_IPE)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 504 | adapter->hw_csum_rx_error++; |
| 505 | return; |
| 506 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 507 | |
| 508 | if (!(status_err & IXGBE_RXD_STAT_L4CS)) |
| 509 | return; |
| 510 | |
| 511 | if (status_err & IXGBE_RXDADV_ERR_TCPE) { |
| 512 | adapter->hw_csum_rx_error++; |
| 513 | return; |
| 514 | } |
| 515 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 516 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 517 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 518 | adapter->hw_csum_rx_good++; |
| 519 | } |
| 520 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 521 | static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw, |
| 522 | struct ixgbe_ring *rx_ring, u32 val) |
| 523 | { |
| 524 | /* |
| 525 | * Force memory writes to complete before letting h/w |
| 526 | * know there are new descriptors to fetch. (Only |
| 527 | * applicable for weak-ordered memory model archs, |
| 528 | * such as IA-64). |
| 529 | */ |
| 530 | wmb(); |
| 531 | IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val); |
| 532 | } |
| 533 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 534 | /** |
| 535 | * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split |
| 536 | * @adapter: address of board private structure |
| 537 | **/ |
| 538 | static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 539 | struct ixgbe_ring *rx_ring, |
| 540 | int cleaned_count) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 541 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 542 | struct pci_dev *pdev = adapter->pdev; |
| 543 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 544 | struct ixgbe_rx_buffer *bi; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 545 | unsigned int i; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 546 | unsigned int bufsz = rx_ring->rx_buf_len + NET_IP_ALIGN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 547 | |
| 548 | i = rx_ring->next_to_use; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 549 | bi = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 550 | |
| 551 | while (cleaned_count--) { |
| 552 | rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 553 | |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 554 | if (!bi->page_dma && |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 555 | (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 556 | if (!bi->page) { |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 557 | bi->page = alloc_page(GFP_ATOMIC); |
| 558 | if (!bi->page) { |
| 559 | adapter->alloc_rx_page_failed++; |
| 560 | goto no_buffers; |
| 561 | } |
| 562 | bi->page_offset = 0; |
| 563 | } else { |
| 564 | /* use a half page if we're re-using */ |
| 565 | bi->page_offset ^= (PAGE_SIZE / 2); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 566 | } |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 567 | |
| 568 | bi->page_dma = pci_map_page(pdev, bi->page, |
| 569 | bi->page_offset, |
| 570 | (PAGE_SIZE / 2), |
| 571 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 572 | } |
| 573 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 574 | if (!bi->skb) { |
Jesse Brandeburg | 5ecc361 | 2008-12-15 01:00:57 -0800 | [diff] [blame] | 575 | struct sk_buff *skb; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 576 | skb = netdev_alloc_skb(adapter->netdev, bufsz); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 577 | |
| 578 | if (!skb) { |
| 579 | adapter->alloc_rx_buff_failed++; |
| 580 | goto no_buffers; |
| 581 | } |
| 582 | |
| 583 | /* |
| 584 | * Make buffer alignment 2 beyond a 16 byte boundary |
| 585 | * this will result in a 16 byte aligned IP header after |
| 586 | * the 14 byte MAC header is removed |
| 587 | */ |
| 588 | skb_reserve(skb, NET_IP_ALIGN); |
| 589 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 590 | bi->skb = skb; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 591 | bi->dma = pci_map_single(pdev, skb->data, bufsz, |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 592 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 593 | } |
| 594 | /* Refresh the desc even if buffer_addrs didn't change because |
| 595 | * each write-back erases this info. */ |
| 596 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 597 | rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma); |
| 598 | rx_desc->read.hdr_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 599 | } else { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 600 | rx_desc->read.pkt_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 601 | } |
| 602 | |
| 603 | i++; |
| 604 | if (i == rx_ring->count) |
| 605 | i = 0; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 606 | bi = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 607 | } |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 608 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 609 | no_buffers: |
| 610 | if (rx_ring->next_to_use != i) { |
| 611 | rx_ring->next_to_use = i; |
| 612 | if (i-- == 0) |
| 613 | i = (rx_ring->count - 1); |
| 614 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 615 | ixgbe_release_rx_desc(&adapter->hw, rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 616 | } |
| 617 | } |
| 618 | |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 619 | static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc) |
| 620 | { |
| 621 | return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info; |
| 622 | } |
| 623 | |
| 624 | static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc) |
| 625 | { |
| 626 | return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 627 | } |
| 628 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 629 | 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] | 630 | struct ixgbe_ring *rx_ring, |
| 631 | int *work_done, int work_to_do) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 632 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 633 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 634 | struct pci_dev *pdev = adapter->pdev; |
| 635 | union ixgbe_adv_rx_desc *rx_desc, *next_rxd; |
| 636 | struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer; |
| 637 | struct sk_buff *skb; |
| 638 | unsigned int i; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 639 | u32 len, staterr; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 640 | u16 hdr_info; |
| 641 | bool cleaned = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 642 | int cleaned_count = 0; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 643 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 644 | |
| 645 | i = rx_ring->next_to_clean; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 646 | rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 647 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 648 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 649 | |
| 650 | while (staterr & IXGBE_RXD_STAT_DD) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 651 | u32 upper_len = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 652 | if (*work_done >= work_to_do) |
| 653 | break; |
| 654 | (*work_done)++; |
| 655 | |
| 656 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 657 | hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc)); |
| 658 | len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >> |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 659 | IXGBE_RXDADV_HDRBUFLEN_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 660 | if (hdr_info & IXGBE_RXDADV_SPH) |
| 661 | adapter->rx_hdr_split++; |
| 662 | if (len > IXGBE_RX_HDR_SIZE) |
| 663 | len = IXGBE_RX_HDR_SIZE; |
| 664 | upper_len = le16_to_cpu(rx_desc->wb.upper.length); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 665 | } else { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 666 | len = le16_to_cpu(rx_desc->wb.upper.length); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 667 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 668 | |
| 669 | cleaned = true; |
| 670 | skb = rx_buffer_info->skb; |
| 671 | prefetch(skb->data - NET_IP_ALIGN); |
| 672 | rx_buffer_info->skb = NULL; |
| 673 | |
| 674 | if (len && !skb_shinfo(skb)->nr_frags) { |
| 675 | pci_unmap_single(pdev, rx_buffer_info->dma, |
Jesse Brandeburg | 5ecc361 | 2008-12-15 01:00:57 -0800 | [diff] [blame] | 676 | rx_ring->rx_buf_len, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 677 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 678 | skb_put(skb, len); |
| 679 | } |
| 680 | |
| 681 | if (upper_len) { |
| 682 | pci_unmap_page(pdev, rx_buffer_info->page_dma, |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 683 | PAGE_SIZE / 2, PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 684 | rx_buffer_info->page_dma = 0; |
| 685 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 686 | rx_buffer_info->page, |
| 687 | rx_buffer_info->page_offset, |
| 688 | upper_len); |
| 689 | |
| 690 | if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) || |
| 691 | (page_count(rx_buffer_info->page) != 1)) |
| 692 | rx_buffer_info->page = NULL; |
| 693 | else |
| 694 | get_page(rx_buffer_info->page); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 695 | |
| 696 | skb->len += upper_len; |
| 697 | skb->data_len += upper_len; |
| 698 | skb->truesize += upper_len; |
| 699 | } |
| 700 | |
| 701 | i++; |
| 702 | if (i == rx_ring->count) |
| 703 | i = 0; |
| 704 | next_buffer = &rx_ring->rx_buffer_info[i]; |
| 705 | |
| 706 | next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 707 | prefetch(next_rxd); |
| 708 | |
| 709 | cleaned_count++; |
| 710 | if (staterr & IXGBE_RXD_STAT_EOP) { |
| 711 | rx_ring->stats.packets++; |
| 712 | rx_ring->stats.bytes += skb->len; |
| 713 | } else { |
| 714 | rx_buffer_info->skb = next_buffer->skb; |
| 715 | rx_buffer_info->dma = next_buffer->dma; |
| 716 | next_buffer->skb = skb; |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 717 | next_buffer->dma = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 718 | adapter->non_eop_descs++; |
| 719 | goto next_desc; |
| 720 | } |
| 721 | |
| 722 | if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) { |
| 723 | dev_kfree_skb_irq(skb); |
| 724 | goto next_desc; |
| 725 | } |
| 726 | |
| 727 | ixgbe_rx_checksum(adapter, staterr, skb); |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 728 | |
| 729 | /* probably a little skewed due to removing CRC */ |
| 730 | total_rx_bytes += skb->len; |
| 731 | total_rx_packets++; |
| 732 | |
Jesse Brandeburg | 74ce8dd | 2008-09-11 20:03:23 -0700 | [diff] [blame] | 733 | skb->protocol = eth_type_trans(skb, adapter->netdev); |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 734 | ixgbe_receive_skb(q_vector, skb, staterr, rx_desc); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 735 | |
| 736 | next_desc: |
| 737 | rx_desc->wb.upper.status_error = 0; |
| 738 | |
| 739 | /* return some buffers to hardware, one at a time is too slow */ |
| 740 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 741 | ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count); |
| 742 | cleaned_count = 0; |
| 743 | } |
| 744 | |
| 745 | /* use prefetched values */ |
| 746 | rx_desc = next_rxd; |
| 747 | rx_buffer_info = next_buffer; |
| 748 | |
| 749 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 750 | } |
| 751 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 752 | rx_ring->next_to_clean = i; |
| 753 | cleaned_count = IXGBE_DESC_UNUSED(rx_ring); |
| 754 | |
| 755 | if (cleaned_count) |
| 756 | ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count); |
| 757 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 758 | rx_ring->total_packets += total_rx_packets; |
| 759 | rx_ring->total_bytes += total_rx_bytes; |
| 760 | adapter->net_stats.rx_bytes += total_rx_bytes; |
| 761 | adapter->net_stats.rx_packets += total_rx_packets; |
| 762 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 763 | return cleaned; |
| 764 | } |
| 765 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 766 | static int ixgbe_clean_rxonly(struct napi_struct *, int); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 767 | /** |
| 768 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 769 | * @adapter: board private structure |
| 770 | * |
| 771 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 772 | * interrupts. |
| 773 | **/ |
| 774 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 775 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 776 | struct ixgbe_q_vector *q_vector; |
| 777 | int i, j, q_vectors, v_idx, r_idx; |
| 778 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 779 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 780 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 781 | |
| 782 | /* Populate the IVAR table and set the ITR values to the |
| 783 | * corresponding register. |
| 784 | */ |
| 785 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { |
| 786 | q_vector = &adapter->q_vector[v_idx]; |
| 787 | /* XXX for_each_bit(...) */ |
| 788 | r_idx = find_first_bit(q_vector->rxr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 789 | adapter->num_rx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 790 | |
| 791 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 792 | j = adapter->rx_ring[r_idx].reg_idx; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 793 | ixgbe_set_ivar(adapter, 0, j, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 794 | r_idx = find_next_bit(q_vector->rxr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 795 | adapter->num_rx_queues, |
| 796 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 797 | } |
| 798 | r_idx = find_first_bit(q_vector->txr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 799 | adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 800 | |
| 801 | for (i = 0; i < q_vector->txr_count; i++) { |
| 802 | j = adapter->tx_ring[r_idx].reg_idx; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 803 | ixgbe_set_ivar(adapter, 1, j, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 804 | r_idx = find_next_bit(q_vector->txr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 805 | adapter->num_tx_queues, |
| 806 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 807 | } |
| 808 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 809 | /* if this is a tx only vector halve the interrupt rate */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 810 | if (q_vector->txr_count && !q_vector->rxr_count) |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 811 | q_vector->eitr = (adapter->eitr_param >> 1); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 812 | else if (q_vector->rxr_count) |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 813 | /* rx only */ |
| 814 | q_vector->eitr = adapter->eitr_param; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 815 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 816 | /* |
| 817 | * since ths is initial set up don't need to call |
| 818 | * ixgbe_write_eitr helper |
| 819 | */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 820 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 821 | EITR_INTS_PER_SEC_TO_REG(q_vector->eitr)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 822 | } |
| 823 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 824 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 825 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
| 826 | v_idx); |
| 827 | else if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 828 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 829 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 830 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 831 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 832 | mask = IXGBE_EIMS_ENABLE_MASK; |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 833 | mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 834 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 835 | } |
| 836 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 837 | enum latency_range { |
| 838 | lowest_latency = 0, |
| 839 | low_latency = 1, |
| 840 | bulk_latency = 2, |
| 841 | latency_invalid = 255 |
| 842 | }; |
| 843 | |
| 844 | /** |
| 845 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
| 846 | * @adapter: pointer to adapter |
| 847 | * @eitr: eitr setting (ints per sec) to give last timeslice |
| 848 | * @itr_setting: current throttle rate in ints/second |
| 849 | * @packets: the number of packets during this measurement interval |
| 850 | * @bytes: the number of bytes during this measurement interval |
| 851 | * |
| 852 | * Stores a new ITR value based on packets and byte |
| 853 | * counts during the last interrupt. The advantage of per interrupt |
| 854 | * computation is faster updates and more accurate ITR for the current |
| 855 | * traffic pattern. Constants in this function were computed |
| 856 | * based on theoretical maximum wire speed and thresholds were set based |
| 857 | * on testing data as well as attempting to minimize response time |
| 858 | * while increasing bulk throughput. |
| 859 | * this functionality is controlled by the InterruptThrottleRate module |
| 860 | * parameter (see ixgbe_param.c) |
| 861 | **/ |
| 862 | static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 863 | u32 eitr, u8 itr_setting, |
| 864 | int packets, int bytes) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 865 | { |
| 866 | unsigned int retval = itr_setting; |
| 867 | u32 timepassed_us; |
| 868 | u64 bytes_perint; |
| 869 | |
| 870 | if (packets == 0) |
| 871 | goto update_itr_done; |
| 872 | |
| 873 | |
| 874 | /* simple throttlerate management |
| 875 | * 0-20MB/s lowest (100000 ints/s) |
| 876 | * 20-100MB/s low (20000 ints/s) |
| 877 | * 100-1249MB/s bulk (8000 ints/s) |
| 878 | */ |
| 879 | /* what was last interrupt timeslice? */ |
| 880 | timepassed_us = 1000000/eitr; |
| 881 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 882 | |
| 883 | switch (itr_setting) { |
| 884 | case lowest_latency: |
| 885 | if (bytes_perint > adapter->eitr_low) |
| 886 | retval = low_latency; |
| 887 | break; |
| 888 | case low_latency: |
| 889 | if (bytes_perint > adapter->eitr_high) |
| 890 | retval = bulk_latency; |
| 891 | else if (bytes_perint <= adapter->eitr_low) |
| 892 | retval = lowest_latency; |
| 893 | break; |
| 894 | case bulk_latency: |
| 895 | if (bytes_perint <= adapter->eitr_high) |
| 896 | retval = low_latency; |
| 897 | break; |
| 898 | } |
| 899 | |
| 900 | update_itr_done: |
| 901 | return retval; |
| 902 | } |
| 903 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 904 | /** |
| 905 | * ixgbe_write_eitr - write EITR register in hardware specific way |
| 906 | * @adapter: pointer to adapter struct |
| 907 | * @v_idx: vector index into q_vector array |
| 908 | * @itr_reg: new value to be written in *register* format, not ints/s |
| 909 | * |
| 910 | * This function is made to be called by ethtool and by the driver |
| 911 | * when it needs to update EITR registers at runtime. Hardware |
| 912 | * specific quirks/differences are taken care of here. |
| 913 | */ |
| 914 | void ixgbe_write_eitr(struct ixgbe_adapter *adapter, int v_idx, u32 itr_reg) |
| 915 | { |
| 916 | struct ixgbe_hw *hw = &adapter->hw; |
| 917 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 918 | /* must write high and low 16 bits to reset counter */ |
| 919 | itr_reg |= (itr_reg << 16); |
| 920 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 921 | /* |
| 922 | * set the WDIS bit to not clear the timer bits and cause an |
| 923 | * immediate assertion of the interrupt |
| 924 | */ |
| 925 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
| 926 | } |
| 927 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 928 | } |
| 929 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 930 | static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector) |
| 931 | { |
| 932 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 933 | u32 new_itr; |
| 934 | u8 current_itr, ret_itr; |
| 935 | int i, r_idx, v_idx = ((void *)q_vector - (void *)(adapter->q_vector)) / |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 936 | sizeof(struct ixgbe_q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 937 | struct ixgbe_ring *rx_ring, *tx_ring; |
| 938 | |
| 939 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 940 | for (i = 0; i < q_vector->txr_count; i++) { |
| 941 | tx_ring = &(adapter->tx_ring[r_idx]); |
| 942 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 943 | q_vector->tx_itr, |
| 944 | tx_ring->total_packets, |
| 945 | tx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 946 | /* if the result for this queue would decrease interrupt |
| 947 | * rate for this vector then use that result */ |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 948 | q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ? |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 949 | q_vector->tx_itr - 1 : ret_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 950 | 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] | 951 | r_idx + 1); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 952 | } |
| 953 | |
| 954 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 955 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 956 | rx_ring = &(adapter->rx_ring[r_idx]); |
| 957 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 958 | q_vector->rx_itr, |
| 959 | rx_ring->total_packets, |
| 960 | rx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 961 | /* if the result for this queue would decrease interrupt |
| 962 | * rate for this vector then use that result */ |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 963 | q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ? |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 964 | q_vector->rx_itr - 1 : ret_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 965 | 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] | 966 | r_idx + 1); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 967 | } |
| 968 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 969 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 970 | |
| 971 | switch (current_itr) { |
| 972 | /* counts and packets in update_itr are dependent on these numbers */ |
| 973 | case lowest_latency: |
| 974 | new_itr = 100000; |
| 975 | break; |
| 976 | case low_latency: |
| 977 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 978 | break; |
| 979 | case bulk_latency: |
| 980 | default: |
| 981 | new_itr = 8000; |
| 982 | break; |
| 983 | } |
| 984 | |
| 985 | if (new_itr != q_vector->eitr) { |
| 986 | u32 itr_reg; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 987 | |
| 988 | /* save the algorithm value here, not the smoothed one */ |
| 989 | q_vector->eitr = new_itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 990 | /* do an exponential smoothing */ |
| 991 | new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 992 | itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 993 | ixgbe_write_eitr(adapter, v_idx, itr_reg); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 994 | } |
| 995 | |
| 996 | return; |
| 997 | } |
| 998 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 999 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 1000 | { |
| 1001 | struct ixgbe_hw *hw = &adapter->hw; |
| 1002 | |
| 1003 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
| 1004 | (eicr & IXGBE_EICR_GPI_SDP1)) { |
| 1005 | DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n"); |
| 1006 | /* write to clear the interrupt */ |
| 1007 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 1008 | } |
| 1009 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1010 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1011 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 1012 | { |
| 1013 | struct ixgbe_hw *hw = &adapter->hw; |
| 1014 | |
| 1015 | if (eicr & IXGBE_EICR_GPI_SDP1) { |
| 1016 | /* Clear the interrupt */ |
| 1017 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 1018 | schedule_work(&adapter->multispeed_fiber_task); |
| 1019 | } else if (eicr & IXGBE_EICR_GPI_SDP2) { |
| 1020 | /* Clear the interrupt */ |
| 1021 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2); |
| 1022 | schedule_work(&adapter->sfp_config_module_task); |
| 1023 | } else { |
| 1024 | /* Interrupt isn't for us... */ |
| 1025 | return; |
| 1026 | } |
| 1027 | } |
| 1028 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1029 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 1030 | { |
| 1031 | struct ixgbe_hw *hw = &adapter->hw; |
| 1032 | |
| 1033 | adapter->lsc_int++; |
| 1034 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 1035 | adapter->link_check_timeout = jiffies; |
| 1036 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1037 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
| 1038 | schedule_work(&adapter->watchdog_task); |
| 1039 | } |
| 1040 | } |
| 1041 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1042 | static irqreturn_t ixgbe_msix_lsc(int irq, void *data) |
| 1043 | { |
| 1044 | struct net_device *netdev = data; |
| 1045 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1046 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 1047 | u32 eicr; |
| 1048 | |
| 1049 | /* |
| 1050 | * Workaround for Silicon errata. Use clear-by-write instead |
| 1051 | * of clear-by-read. Reading with EICS will return the |
| 1052 | * interrupt causes without clearing, which later be done |
| 1053 | * with the write to EICR. |
| 1054 | */ |
| 1055 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
| 1056 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1057 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1058 | if (eicr & IXGBE_EICR_LSC) |
| 1059 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1060 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1061 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 1062 | ixgbe_check_fan_failure(adapter, eicr); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1063 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1064 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 1065 | ixgbe_check_sfp_event(adapter, eicr); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1066 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1067 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1068 | |
| 1069 | return IRQ_HANDLED; |
| 1070 | } |
| 1071 | |
| 1072 | static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data) |
| 1073 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1074 | struct ixgbe_q_vector *q_vector = data; |
| 1075 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1076 | struct ixgbe_ring *tx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1077 | int i, r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1078 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1079 | if (!q_vector->txr_count) |
| 1080 | return IRQ_HANDLED; |
| 1081 | |
| 1082 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1083 | for (i = 0; i < q_vector->txr_count; i++) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1084 | tx_ring = &(adapter->tx_ring[r_idx]); |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1085 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1086 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1087 | ixgbe_update_tx_dca(adapter, tx_ring); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1088 | #endif |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1089 | tx_ring->total_bytes = 0; |
| 1090 | tx_ring->total_packets = 0; |
| 1091 | ixgbe_clean_tx_irq(adapter, tx_ring); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1092 | 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] | 1093 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1094 | } |
| 1095 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1096 | return IRQ_HANDLED; |
| 1097 | } |
| 1098 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1099 | /** |
| 1100 | * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues) |
| 1101 | * @irq: unused |
| 1102 | * @data: pointer to our q_vector struct for this interrupt vector |
| 1103 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1104 | static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data) |
| 1105 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1106 | struct ixgbe_q_vector *q_vector = data; |
| 1107 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1108 | struct ixgbe_ring *rx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1109 | int r_idx; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1110 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1111 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1112 | 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] | 1113 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1114 | rx_ring = &(adapter->rx_ring[r_idx]); |
| 1115 | rx_ring->total_bytes = 0; |
| 1116 | rx_ring->total_packets = 0; |
| 1117 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1118 | r_idx + 1); |
| 1119 | } |
| 1120 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1121 | if (!q_vector->rxr_count) |
| 1122 | return IRQ_HANDLED; |
| 1123 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1124 | 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] | 1125 | rx_ring = &(adapter->rx_ring[r_idx]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1126 | /* disable interrupts on this vector only */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1127 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, rx_ring->v_idx); |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1128 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1129 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1130 | return IRQ_HANDLED; |
| 1131 | } |
| 1132 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1133 | static irqreturn_t ixgbe_msix_clean_many(int irq, void *data) |
| 1134 | { |
| 1135 | ixgbe_msix_clean_rx(irq, data); |
| 1136 | ixgbe_msix_clean_tx(irq, data); |
| 1137 | |
| 1138 | return IRQ_HANDLED; |
| 1139 | } |
| 1140 | |
| 1141 | /** |
| 1142 | * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine |
| 1143 | * @napi: napi struct with our devices info in it |
| 1144 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1145 | * |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1146 | * This function is optimized for cleaning one queue only on a single |
| 1147 | * q_vector!!! |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1148 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1149 | static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget) |
| 1150 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1151 | struct ixgbe_q_vector *q_vector = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1152 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1153 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1154 | struct ixgbe_ring *rx_ring = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1155 | int work_done = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1156 | long r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1157 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1158 | 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] | 1159 | rx_ring = &(adapter->rx_ring[r_idx]); |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1160 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1161 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1162 | ixgbe_update_rx_dca(adapter, rx_ring); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1163 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1164 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1165 | ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1166 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1167 | /* If all Rx work done, exit the polling mode */ |
| 1168 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1169 | napi_complete(napi); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1170 | if (adapter->itr_setting & 1) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1171 | ixgbe_set_itr_msix(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1172 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1173 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, rx_ring->v_idx); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1174 | } |
| 1175 | |
| 1176 | return work_done; |
| 1177 | } |
| 1178 | |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1179 | /** |
| 1180 | * ixgbe_clean_rxonly_many - msix (aka one shot) rx clean routine |
| 1181 | * @napi: napi struct with our devices info in it |
| 1182 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1183 | * |
| 1184 | * This function will clean more than one rx queue associated with a |
| 1185 | * q_vector. |
| 1186 | **/ |
| 1187 | static int ixgbe_clean_rxonly_many(struct napi_struct *napi, int budget) |
| 1188 | { |
| 1189 | struct ixgbe_q_vector *q_vector = |
| 1190 | container_of(napi, struct ixgbe_q_vector, napi); |
| 1191 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1192 | struct ixgbe_ring *rx_ring = NULL; |
| 1193 | int work_done = 0, i; |
| 1194 | long r_idx; |
| 1195 | u16 enable_mask = 0; |
| 1196 | |
| 1197 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 1198 | * the budget to go below 1 because we'll exit polling */ |
| 1199 | budget /= (q_vector->rxr_count ?: 1); |
| 1200 | budget = max(budget, 1); |
| 1201 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1202 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1203 | rx_ring = &(adapter->rx_ring[r_idx]); |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1204 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1205 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1206 | ixgbe_update_rx_dca(adapter, rx_ring); |
| 1207 | #endif |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1208 | ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1209 | enable_mask |= rx_ring->v_idx; |
| 1210 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1211 | r_idx + 1); |
| 1212 | } |
| 1213 | |
| 1214 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1215 | rx_ring = &(adapter->rx_ring[r_idx]); |
| 1216 | /* If all Rx work done, exit the polling mode */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 1217 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1218 | napi_complete(napi); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1219 | if (adapter->itr_setting & 1) |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1220 | ixgbe_set_itr_msix(q_vector); |
| 1221 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1222 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, enable_mask); |
| 1223 | return 0; |
| 1224 | } |
| 1225 | |
| 1226 | return work_done; |
| 1227 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1228 | 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] | 1229 | int r_idx) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1230 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1231 | a->q_vector[v_idx].adapter = a; |
| 1232 | set_bit(r_idx, a->q_vector[v_idx].rxr_idx); |
| 1233 | a->q_vector[v_idx].rxr_count++; |
| 1234 | a->rx_ring[r_idx].v_idx = 1 << v_idx; |
| 1235 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1236 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1237 | static inline void map_vector_to_txq(struct ixgbe_adapter *a, int v_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1238 | int r_idx) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1239 | { |
| 1240 | a->q_vector[v_idx].adapter = a; |
| 1241 | set_bit(r_idx, a->q_vector[v_idx].txr_idx); |
| 1242 | a->q_vector[v_idx].txr_count++; |
| 1243 | a->tx_ring[r_idx].v_idx = 1 << v_idx; |
| 1244 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1245 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1246 | /** |
| 1247 | * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors |
| 1248 | * @adapter: board private structure to initialize |
| 1249 | * @vectors: allotted vector count for descriptor rings |
| 1250 | * |
| 1251 | * This function maps descriptor rings to the queue-specific vectors |
| 1252 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 1253 | * one vector per ring/queue, but on a constrained vector budget, we |
| 1254 | * group the rings as "efficiently" as possible. You would add new |
| 1255 | * mapping configurations in here. |
| 1256 | **/ |
| 1257 | static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1258 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1259 | { |
| 1260 | int v_start = 0; |
| 1261 | int rxr_idx = 0, txr_idx = 0; |
| 1262 | int rxr_remaining = adapter->num_rx_queues; |
| 1263 | int txr_remaining = adapter->num_tx_queues; |
| 1264 | int i, j; |
| 1265 | int rqpv, tqpv; |
| 1266 | int err = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1267 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1268 | /* No mapping required if MSI-X is disabled. */ |
| 1269 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1270 | goto out; |
| 1271 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1272 | /* |
| 1273 | * The ideal configuration... |
| 1274 | * We have enough vectors to map one per queue. |
| 1275 | */ |
| 1276 | if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) { |
| 1277 | for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++) |
| 1278 | map_vector_to_rxq(adapter, v_start, rxr_idx); |
| 1279 | |
| 1280 | for (; txr_idx < txr_remaining; v_start++, txr_idx++) |
| 1281 | map_vector_to_txq(adapter, v_start, txr_idx); |
| 1282 | |
| 1283 | goto out; |
| 1284 | } |
| 1285 | |
| 1286 | /* |
| 1287 | * If we don't have enough vectors for a 1-to-1 |
| 1288 | * mapping, we'll have to group them so there are |
| 1289 | * multiple queues per vector. |
| 1290 | */ |
| 1291 | /* Re-adjusting *qpv takes care of the remainder. */ |
| 1292 | for (i = v_start; i < vectors; i++) { |
| 1293 | rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i); |
| 1294 | for (j = 0; j < rqpv; j++) { |
| 1295 | map_vector_to_rxq(adapter, i, rxr_idx); |
| 1296 | rxr_idx++; |
| 1297 | rxr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1298 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1299 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1300 | for (i = v_start; i < vectors; i++) { |
| 1301 | tqpv = DIV_ROUND_UP(txr_remaining, vectors - i); |
| 1302 | for (j = 0; j < tqpv; j++) { |
| 1303 | map_vector_to_txq(adapter, i, txr_idx); |
| 1304 | txr_idx++; |
| 1305 | txr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1306 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1307 | } |
| 1308 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1309 | out: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1310 | return err; |
| 1311 | } |
| 1312 | |
| 1313 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1314 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 1315 | * @adapter: board private structure |
| 1316 | * |
| 1317 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 1318 | * interrupts from the kernel. |
| 1319 | **/ |
| 1320 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 1321 | { |
| 1322 | struct net_device *netdev = adapter->netdev; |
| 1323 | irqreturn_t (*handler)(int, void *); |
| 1324 | int i, vector, q_vectors, err; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 1325 | int ri=0, ti=0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1326 | |
| 1327 | /* Decrement for Other and TCP Timer vectors */ |
| 1328 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1329 | |
| 1330 | /* Map the Tx/Rx rings to the vectors we were allotted. */ |
| 1331 | err = ixgbe_map_rings_to_vectors(adapter, q_vectors); |
| 1332 | if (err) |
| 1333 | goto out; |
| 1334 | |
| 1335 | #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \ |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1336 | (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \ |
| 1337 | &ixgbe_msix_clean_many) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1338 | for (vector = 0; vector < q_vectors; vector++) { |
| 1339 | handler = SET_HANDLER(&adapter->q_vector[vector]); |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 1340 | |
| 1341 | if(handler == &ixgbe_msix_clean_rx) { |
| 1342 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1343 | netdev->name, "rx", ri++); |
| 1344 | } |
| 1345 | else if(handler == &ixgbe_msix_clean_tx) { |
| 1346 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1347 | netdev->name, "tx", ti++); |
| 1348 | } |
| 1349 | else |
| 1350 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1351 | netdev->name, "TxRx", vector); |
| 1352 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1353 | err = request_irq(adapter->msix_entries[vector].vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1354 | handler, 0, adapter->name[vector], |
| 1355 | &(adapter->q_vector[vector])); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1356 | if (err) { |
| 1357 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1358 | "request_irq failed for MSIX interrupt " |
| 1359 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1360 | goto free_queue_irqs; |
| 1361 | } |
| 1362 | } |
| 1363 | |
| 1364 | sprintf(adapter->name[vector], "%s:lsc", netdev->name); |
| 1365 | err = request_irq(adapter->msix_entries[vector].vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1366 | &ixgbe_msix_lsc, 0, adapter->name[vector], netdev); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1367 | if (err) { |
| 1368 | DPRINTK(PROBE, ERR, |
| 1369 | "request_irq for msix_lsc failed: %d\n", err); |
| 1370 | goto free_queue_irqs; |
| 1371 | } |
| 1372 | |
| 1373 | return 0; |
| 1374 | |
| 1375 | free_queue_irqs: |
| 1376 | for (i = vector - 1; i >= 0; i--) |
| 1377 | free_irq(adapter->msix_entries[--vector].vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1378 | &(adapter->q_vector[i])); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1379 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 1380 | pci_disable_msix(adapter->pdev); |
| 1381 | kfree(adapter->msix_entries); |
| 1382 | adapter->msix_entries = NULL; |
| 1383 | out: |
| 1384 | return err; |
| 1385 | } |
| 1386 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1387 | static void ixgbe_set_itr(struct ixgbe_adapter *adapter) |
| 1388 | { |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1389 | struct ixgbe_q_vector *q_vector = adapter->q_vector; |
| 1390 | u8 current_itr; |
| 1391 | u32 new_itr = q_vector->eitr; |
| 1392 | struct ixgbe_ring *rx_ring = &adapter->rx_ring[0]; |
| 1393 | struct ixgbe_ring *tx_ring = &adapter->tx_ring[0]; |
| 1394 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1395 | q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1396 | q_vector->tx_itr, |
| 1397 | tx_ring->total_packets, |
| 1398 | tx_ring->total_bytes); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1399 | q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1400 | q_vector->rx_itr, |
| 1401 | rx_ring->total_packets, |
| 1402 | rx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1403 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1404 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1405 | |
| 1406 | switch (current_itr) { |
| 1407 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1408 | case lowest_latency: |
| 1409 | new_itr = 100000; |
| 1410 | break; |
| 1411 | case low_latency: |
| 1412 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 1413 | break; |
| 1414 | case bulk_latency: |
| 1415 | new_itr = 8000; |
| 1416 | break; |
| 1417 | default: |
| 1418 | break; |
| 1419 | } |
| 1420 | |
| 1421 | if (new_itr != q_vector->eitr) { |
| 1422 | u32 itr_reg; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1423 | |
| 1424 | /* save the algorithm value here, not the smoothed one */ |
| 1425 | q_vector->eitr = new_itr; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1426 | /* do an exponential smoothing */ |
| 1427 | new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1428 | itr_reg = EITR_INTS_PER_SEC_TO_REG(new_itr); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1429 | ixgbe_write_eitr(adapter, 0, itr_reg); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1430 | } |
| 1431 | |
| 1432 | return; |
| 1433 | } |
| 1434 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1435 | /** |
| 1436 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 1437 | * @adapter: board private structure |
| 1438 | **/ |
| 1439 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 1440 | { |
| 1441 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1442 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 1443 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
| 1444 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(2), ~0); |
| 1445 | } |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1446 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 1447 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 1448 | int i; |
| 1449 | for (i = 0; i < adapter->num_msix_vectors; i++) |
| 1450 | synchronize_irq(adapter->msix_entries[i].vector); |
| 1451 | } else { |
| 1452 | synchronize_irq(adapter->pdev->irq); |
| 1453 | } |
| 1454 | } |
| 1455 | |
| 1456 | /** |
| 1457 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 1458 | * @adapter: board private structure |
| 1459 | **/ |
| 1460 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter) |
| 1461 | { |
| 1462 | u32 mask; |
| 1463 | mask = IXGBE_EIMS_ENABLE_MASK; |
David S. Miller | 6ab33d5 | 2008-11-20 16:44:00 -0800 | [diff] [blame] | 1464 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
| 1465 | mask |= IXGBE_EIMS_GPI_SDP1; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1466 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame^] | 1467 | mask |= IXGBE_EIMS_ECC; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1468 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 1469 | mask |= IXGBE_EIMS_GPI_SDP2; |
| 1470 | } |
| 1471 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1472 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1473 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 1474 | /* enable the rest of the queue vectors */ |
| 1475 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), |
| 1476 | (IXGBE_EIMS_RTX_QUEUE << 16)); |
| 1477 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(2), |
| 1478 | ((IXGBE_EIMS_RTX_QUEUE << 16) | |
| 1479 | IXGBE_EIMS_RTX_QUEUE)); |
| 1480 | } |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1481 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 1482 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1483 | |
| 1484 | /** |
| 1485 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1486 | * @irq: interrupt number |
| 1487 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1488 | **/ |
| 1489 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 1490 | { |
| 1491 | struct net_device *netdev = data; |
| 1492 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1493 | struct ixgbe_hw *hw = &adapter->hw; |
| 1494 | u32 eicr; |
| 1495 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 1496 | /* |
| 1497 | * Workaround for silicon errata. Mask the interrupts |
| 1498 | * before the read of EICR. |
| 1499 | */ |
| 1500 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 1501 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1502 | /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read |
| 1503 | * therefore no explict interrupt disable is necessary */ |
| 1504 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 1505 | if (!eicr) { |
| 1506 | /* shared interrupt alert! |
| 1507 | * make sure interrupts are enabled because the read will |
| 1508 | * have disabled interrupts due to EIAM */ |
| 1509 | ixgbe_irq_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1510 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 1511 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1512 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1513 | if (eicr & IXGBE_EICR_LSC) |
| 1514 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1515 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1516 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 1517 | ixgbe_check_sfp_event(adapter, eicr); |
| 1518 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1519 | ixgbe_check_fan_failure(adapter, eicr); |
| 1520 | |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1521 | if (napi_schedule_prep(&adapter->q_vector[0].napi)) { |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1522 | adapter->tx_ring[0].total_packets = 0; |
| 1523 | adapter->tx_ring[0].total_bytes = 0; |
| 1524 | adapter->rx_ring[0].total_packets = 0; |
| 1525 | adapter->rx_ring[0].total_bytes = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1526 | /* would disable interrupts here but EIAM disabled it */ |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1527 | __napi_schedule(&adapter->q_vector[0].napi); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1528 | } |
| 1529 | |
| 1530 | return IRQ_HANDLED; |
| 1531 | } |
| 1532 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1533 | static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter) |
| 1534 | { |
| 1535 | int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1536 | |
| 1537 | for (i = 0; i < q_vectors; i++) { |
| 1538 | struct ixgbe_q_vector *q_vector = &adapter->q_vector[i]; |
| 1539 | bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES); |
| 1540 | bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES); |
| 1541 | q_vector->rxr_count = 0; |
| 1542 | q_vector->txr_count = 0; |
| 1543 | } |
| 1544 | } |
| 1545 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1546 | /** |
| 1547 | * ixgbe_request_irq - initialize interrupts |
| 1548 | * @adapter: board private structure |
| 1549 | * |
| 1550 | * Attempts to configure interrupts using the best available |
| 1551 | * capabilities of the hardware and kernel. |
| 1552 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1553 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1554 | { |
| 1555 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1556 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1557 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1558 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 1559 | err = ixgbe_request_msix_irqs(adapter); |
| 1560 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 1561 | err = request_irq(adapter->pdev->irq, &ixgbe_intr, 0, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1562 | netdev->name, netdev); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1563 | } else { |
| 1564 | err = request_irq(adapter->pdev->irq, &ixgbe_intr, IRQF_SHARED, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1565 | netdev->name, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1566 | } |
| 1567 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1568 | if (err) |
| 1569 | DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err); |
| 1570 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1571 | return err; |
| 1572 | } |
| 1573 | |
| 1574 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 1575 | { |
| 1576 | struct net_device *netdev = adapter->netdev; |
| 1577 | |
| 1578 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1579 | int i, q_vectors; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1580 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1581 | q_vectors = adapter->num_msix_vectors; |
| 1582 | |
| 1583 | i = q_vectors - 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1584 | free_irq(adapter->msix_entries[i].vector, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1585 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1586 | i--; |
| 1587 | for (; i >= 0; i--) { |
| 1588 | free_irq(adapter->msix_entries[i].vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1589 | &(adapter->q_vector[i])); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1590 | } |
| 1591 | |
| 1592 | ixgbe_reset_q_vectors(adapter); |
| 1593 | } else { |
| 1594 | free_irq(adapter->pdev->irq, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1595 | } |
| 1596 | } |
| 1597 | |
| 1598 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1599 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 1600 | * |
| 1601 | **/ |
| 1602 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 1603 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1604 | struct ixgbe_hw *hw = &adapter->hw; |
| 1605 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1606 | IXGBE_WRITE_REG(hw, IXGBE_EITR(0), |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1607 | EITR_INTS_PER_SEC_TO_REG(adapter->eitr_param)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1608 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1609 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 1610 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1611 | |
| 1612 | map_vector_to_rxq(adapter, 0, 0); |
| 1613 | map_vector_to_txq(adapter, 0, 0); |
| 1614 | |
| 1615 | DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1616 | } |
| 1617 | |
| 1618 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1619 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1620 | * @adapter: board private structure |
| 1621 | * |
| 1622 | * Configure the Tx unit of the MAC after a reset. |
| 1623 | **/ |
| 1624 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 1625 | { |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1626 | u64 tdba; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1627 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1628 | u32 i, j, tdlen, txctrl; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1629 | |
| 1630 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 1631 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1632 | struct ixgbe_ring *ring = &adapter->tx_ring[i]; |
| 1633 | j = ring->reg_idx; |
| 1634 | tdba = ring->dma; |
| 1635 | tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1636 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j), |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1637 | (tdba & DMA_32BIT_MASK)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1638 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32)); |
| 1639 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen); |
| 1640 | IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0); |
| 1641 | IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0); |
| 1642 | adapter->tx_ring[i].head = IXGBE_TDH(j); |
| 1643 | adapter->tx_ring[i].tail = IXGBE_TDT(j); |
| 1644 | /* Disable Tx Head Writeback RO bit, since this hoses |
| 1645 | * bookkeeping if things aren't delivered in order. |
| 1646 | */ |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1647 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1648 | txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1649 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1650 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1651 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 1652 | /* We enable 8 traffic classes, DCB only */ |
| 1653 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 1654 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA | |
| 1655 | IXGBE_MTQC_8TC_8TQ)); |
| 1656 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1657 | } |
| 1658 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1659 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1660 | |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1661 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, int index) |
| 1662 | { |
| 1663 | struct ixgbe_ring *rx_ring; |
| 1664 | u32 srrctl; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1665 | int queue0 = 0; |
Alexander Duyck | 3be1adf | 2008-08-30 00:29:10 -0700 | [diff] [blame] | 1666 | unsigned long mask; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1667 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1668 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 1669 | queue0 = index; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1670 | } else { |
Alexander Duyck | 3be1adf | 2008-08-30 00:29:10 -0700 | [diff] [blame] | 1671 | mask = (unsigned long) adapter->ring_feature[RING_F_RSS].mask; |
| 1672 | queue0 = index & mask; |
| 1673 | index = index & mask; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1674 | } |
Alexander Duyck | 3be1adf | 2008-08-30 00:29:10 -0700 | [diff] [blame] | 1675 | |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1676 | rx_ring = &adapter->rx_ring[queue0]; |
| 1677 | |
| 1678 | srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index)); |
| 1679 | |
| 1680 | srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 1681 | srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK; |
| 1682 | |
| 1683 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 32344a3 | 2009-02-24 16:37:31 -0800 | [diff] [blame] | 1684 | u16 bufsz = IXGBE_RXBUFFER_2048; |
| 1685 | /* grow the amount we can receive on large page machines */ |
| 1686 | if (bufsz < (PAGE_SIZE / 2)) |
| 1687 | bufsz = (PAGE_SIZE / 2); |
| 1688 | /* cap the bufsz at our largest descriptor size */ |
| 1689 | bufsz = min((u16)IXGBE_MAX_RXBUFFER, bufsz); |
| 1690 | |
| 1691 | srrctl |= bufsz >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1692 | srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS; |
| 1693 | srrctl |= ((IXGBE_RX_HDR_SIZE << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1694 | IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) & |
| 1695 | IXGBE_SRRCTL_BSIZEHDR_MASK); |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1696 | } else { |
| 1697 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
| 1698 | |
| 1699 | if (rx_ring->rx_buf_len == MAXIMUM_ETHERNET_VLAN_SIZE) |
| 1700 | srrctl |= IXGBE_RXBUFFER_2048 >> |
| 1701 | IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 1702 | else |
| 1703 | srrctl |= rx_ring->rx_buf_len >> |
| 1704 | IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 1705 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1706 | |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1707 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl); |
| 1708 | } |
| 1709 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 1710 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1711 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1712 | * @adapter: board private structure |
| 1713 | * |
| 1714 | * Configure the Rx unit of the MAC after a reset. |
| 1715 | **/ |
| 1716 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 1717 | { |
| 1718 | u64 rdba; |
| 1719 | struct ixgbe_hw *hw = &adapter->hw; |
| 1720 | struct net_device *netdev = adapter->netdev; |
| 1721 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1722 | int i, j; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1723 | u32 rdlen, rxctrl, rxcsum; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1724 | static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D, |
| 1725 | 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE, |
| 1726 | 0x6A3E67EA, 0x14364D17, 0x3BED200D}; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1727 | u32 fctrl, hlreg0; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1728 | u32 reta = 0, mrqc = 0; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1729 | u32 rdrxctl; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1730 | int rx_buf_len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1731 | |
| 1732 | /* Decide whether to use packet split mode or not */ |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 1733 | adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1734 | |
| 1735 | /* Set the RX buffer length according to the mode */ |
| 1736 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1737 | rx_buf_len = IXGBE_RX_HDR_SIZE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1738 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 1739 | /* PSRTYPE must be initialized in 82599 */ |
| 1740 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
| 1741 | IXGBE_PSRTYPE_UDPHDR | |
| 1742 | IXGBE_PSRTYPE_IPV4HDR | |
| 1743 | IXGBE_PSRTYPE_IPV6HDR; |
| 1744 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype); |
| 1745 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1746 | } else { |
| 1747 | if (netdev->mtu <= ETH_DATA_LEN) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1748 | rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1749 | else |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1750 | rx_buf_len = ALIGN(max_frame, 1024); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1751 | } |
| 1752 | |
| 1753 | fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL); |
| 1754 | fctrl |= IXGBE_FCTRL_BAM; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1755 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1756 | fctrl |= IXGBE_FCTRL_PMCF; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1757 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl); |
| 1758 | |
| 1759 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
| 1760 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 1761 | hlreg0 &= ~IXGBE_HLREG0_JUMBOEN; |
| 1762 | else |
| 1763 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
| 1764 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 1765 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1766 | rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc); |
| 1767 | /* disable receives while setting up the descriptors */ |
| 1768 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 1769 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
| 1770 | |
| 1771 | /* Setup the HW Rx Head and Tail Descriptor Pointers and |
| 1772 | * the Base and Length of the Rx Descriptor Ring */ |
| 1773 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 1774 | rdba = adapter->rx_ring[i].dma; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1775 | j = adapter->rx_ring[i].reg_idx; |
| 1776 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_32BIT_MASK)); |
| 1777 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32)); |
| 1778 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen); |
| 1779 | IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0); |
| 1780 | IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0); |
| 1781 | adapter->rx_ring[i].head = IXGBE_RDH(j); |
| 1782 | adapter->rx_ring[i].tail = IXGBE_RDT(j); |
| 1783 | adapter->rx_ring[i].rx_buf_len = rx_buf_len; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1784 | |
| 1785 | ixgbe_configure_srrctl(adapter, j); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1786 | } |
| 1787 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1788 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 1789 | /* |
| 1790 | * For VMDq support of different descriptor types or |
| 1791 | * buffer sizes through the use of multiple SRRCTL |
| 1792 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 1793 | * |
| 1794 | * also, the manual doesn't mention it clearly but DCA hints |
| 1795 | * will only use queue 0's tags unless this bit is set. Side |
| 1796 | * effects of setting this bit are only that SRRCTL must be |
| 1797 | * fully programmed [0..15] |
| 1798 | */ |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame^] | 1799 | rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 1800 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 1801 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 1802 | } |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 1803 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1804 | /* Program MRQC for the distribution of queues */ |
| 1805 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 1806 | int mask = adapter->flags & ( |
| 1807 | IXGBE_FLAG_RSS_ENABLED |
| 1808 | | IXGBE_FLAG_DCB_ENABLED |
| 1809 | ); |
| 1810 | |
| 1811 | switch (mask) { |
| 1812 | case (IXGBE_FLAG_RSS_ENABLED): |
| 1813 | mrqc = IXGBE_MRQC_RSSEN; |
| 1814 | break; |
| 1815 | case (IXGBE_FLAG_DCB_ENABLED): |
| 1816 | mrqc = IXGBE_MRQC_RT8TCEN; |
| 1817 | break; |
| 1818 | default: |
| 1819 | break; |
| 1820 | } |
| 1821 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1822 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1823 | /* Fill out redirection table */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1824 | for (i = 0, j = 0; i < 128; i++, j++) { |
| 1825 | if (j == adapter->ring_feature[RING_F_RSS].indices) |
| 1826 | j = 0; |
| 1827 | /* reta = 4-byte sliding window of |
| 1828 | * 0x00..(indices-1)(indices-1)00..etc. */ |
| 1829 | reta = (reta << 8) | (j * 0x11); |
| 1830 | if ((i & 3) == 3) |
| 1831 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1832 | } |
| 1833 | |
| 1834 | /* Fill out hash function seeds */ |
| 1835 | for (i = 0; i < 10; i++) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1836 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1837 | |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame^] | 1838 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 1839 | mrqc |= IXGBE_MRQC_RSSEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1840 | /* Perform hash on these packet types */ |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame^] | 1841 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
| 1842 | | IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
| 1843 | | IXGBE_MRQC_RSS_FIELD_IPV4_UDP |
| 1844 | | IXGBE_MRQC_RSS_FIELD_IPV6 |
| 1845 | | IXGBE_MRQC_RSS_FIELD_IPV6_TCP |
| 1846 | | IXGBE_MRQC_RSS_FIELD_IPV6_UDP; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1847 | } |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame^] | 1848 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1849 | |
| 1850 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 1851 | |
| 1852 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED || |
| 1853 | adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) { |
| 1854 | /* Disable indicating checksum in descriptor, enables |
| 1855 | * RSS hash */ |
| 1856 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 1857 | } |
| 1858 | if (!(rxcsum & IXGBE_RXCSUM_PCSD)) { |
| 1859 | /* Enable IPv4 payload checksum for UDP fragments |
| 1860 | * if PCSD is not set */ |
| 1861 | rxcsum |= IXGBE_RXCSUM_IPPCSE; |
| 1862 | } |
| 1863 | |
| 1864 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1865 | |
| 1866 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 1867 | rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 1868 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
| 1869 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 1870 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1871 | } |
| 1872 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1873 | static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 1874 | { |
| 1875 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1876 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1877 | |
| 1878 | /* add VID to filter table */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1879 | hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1880 | } |
| 1881 | |
| 1882 | static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 1883 | { |
| 1884 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1885 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1886 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1887 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1888 | ixgbe_irq_disable(adapter); |
| 1889 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1890 | vlan_group_set_device(adapter->vlgrp, vid, NULL); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1891 | |
| 1892 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1893 | ixgbe_irq_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1894 | |
| 1895 | /* remove VID from filter table */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 1896 | hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1897 | } |
| 1898 | |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 1899 | static void ixgbe_vlan_rx_register(struct net_device *netdev, |
| 1900 | struct vlan_group *grp) |
| 1901 | { |
| 1902 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1903 | u32 ctrl; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1904 | int i, j; |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 1905 | |
| 1906 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1907 | ixgbe_irq_disable(adapter); |
| 1908 | adapter->vlgrp = grp; |
| 1909 | |
| 1910 | /* |
| 1911 | * For a DCB driver, always enable VLAN tag stripping so we can |
| 1912 | * still receive traffic from a DCB-enabled host even if we're |
| 1913 | * not in DCB mode. |
| 1914 | */ |
| 1915 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1916 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1917 | ctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE; |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 1918 | ctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 1919 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1920 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 1921 | ctrl |= IXGBE_VLNCTRL_VFE; |
| 1922 | /* enable VLAN tag insert/strip */ |
| 1923 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL); |
| 1924 | ctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 1925 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl); |
| 1926 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 1927 | j = adapter->rx_ring[i].reg_idx; |
| 1928 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j)); |
| 1929 | ctrl |= IXGBE_RXDCTL_VME; |
| 1930 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl); |
| 1931 | } |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 1932 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1933 | ixgbe_vlan_rx_add_vid(netdev, 0); |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 1934 | |
| 1935 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1936 | ixgbe_irq_enable(adapter); |
| 1937 | } |
| 1938 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1939 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 1940 | { |
| 1941 | ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 1942 | |
| 1943 | if (adapter->vlgrp) { |
| 1944 | u16 vid; |
| 1945 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
| 1946 | if (!vlan_group_get_device(adapter->vlgrp, vid)) |
| 1947 | continue; |
| 1948 | ixgbe_vlan_rx_add_vid(adapter->netdev, vid); |
| 1949 | } |
| 1950 | } |
| 1951 | } |
| 1952 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 1953 | static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq) |
| 1954 | { |
| 1955 | struct dev_mc_list *mc_ptr; |
| 1956 | u8 *addr = *mc_addr_ptr; |
| 1957 | *vmdq = 0; |
| 1958 | |
| 1959 | mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]); |
| 1960 | if (mc_ptr->next) |
| 1961 | *mc_addr_ptr = mc_ptr->next->dmi_addr; |
| 1962 | else |
| 1963 | *mc_addr_ptr = NULL; |
| 1964 | |
| 1965 | return addr; |
| 1966 | } |
| 1967 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1968 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 1969 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1970 | * @netdev: network interface device structure |
| 1971 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 1972 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 1973 | * address list or the network interface flags are updated. This routine is |
| 1974 | * responsible for configuring the hardware for proper unicast, multicast and |
| 1975 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1976 | **/ |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 1977 | static void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1978 | { |
| 1979 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1980 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 1981 | u32 fctrl, vlnctrl; |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 1982 | u8 *addr_list = NULL; |
| 1983 | int addr_count = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1984 | |
| 1985 | /* Check for Promiscuous and All Multicast modes */ |
| 1986 | |
| 1987 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 1988 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1989 | |
| 1990 | if (netdev->flags & IFF_PROMISC) { |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 1991 | hw->addr_ctrl.user_set_promisc = 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1992 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 1993 | vlnctrl &= ~IXGBE_VLNCTRL_VFE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1994 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 1995 | if (netdev->flags & IFF_ALLMULTI) { |
| 1996 | fctrl |= IXGBE_FCTRL_MPE; |
| 1997 | fctrl &= ~IXGBE_FCTRL_UPE; |
| 1998 | } else { |
| 1999 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
| 2000 | } |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2001 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2002 | hw->addr_ctrl.user_set_promisc = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2003 | } |
| 2004 | |
| 2005 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2006 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2007 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2008 | /* reprogram secondary unicast list */ |
| 2009 | addr_count = netdev->uc_count; |
| 2010 | if (addr_count) |
| 2011 | addr_list = netdev->uc_list->dmi_addr; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2012 | hw->mac.ops.update_uc_addr_list(hw, addr_list, addr_count, |
| 2013 | ixgbe_addr_list_itr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2014 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2015 | /* reprogram multicast list */ |
| 2016 | addr_count = netdev->mc_count; |
| 2017 | if (addr_count) |
| 2018 | addr_list = netdev->mc_list->dmi_addr; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2019 | hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count, |
| 2020 | ixgbe_addr_list_itr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2021 | } |
| 2022 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2023 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 2024 | { |
| 2025 | int q_idx; |
| 2026 | struct ixgbe_q_vector *q_vector; |
| 2027 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2028 | |
| 2029 | /* legacy and MSI only use one vector */ |
| 2030 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 2031 | q_vectors = 1; |
| 2032 | |
| 2033 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2034 | struct napi_struct *napi; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2035 | q_vector = &adapter->q_vector[q_idx]; |
| 2036 | if (!q_vector->rxr_count) |
| 2037 | continue; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2038 | napi = &q_vector->napi; |
| 2039 | if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) && |
| 2040 | (q_vector->rxr_count > 1)) |
| 2041 | napi->poll = &ixgbe_clean_rxonly_many; |
| 2042 | |
| 2043 | napi_enable(napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2044 | } |
| 2045 | } |
| 2046 | |
| 2047 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 2048 | { |
| 2049 | int q_idx; |
| 2050 | struct ixgbe_q_vector *q_vector; |
| 2051 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2052 | |
| 2053 | /* legacy and MSI only use one vector */ |
| 2054 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 2055 | q_vectors = 1; |
| 2056 | |
| 2057 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
| 2058 | q_vector = &adapter->q_vector[q_idx]; |
| 2059 | if (!q_vector->rxr_count) |
| 2060 | continue; |
| 2061 | napi_disable(&q_vector->napi); |
| 2062 | } |
| 2063 | } |
| 2064 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 2065 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2066 | /* |
| 2067 | * ixgbe_configure_dcb - Configure DCB hardware |
| 2068 | * @adapter: ixgbe adapter struct |
| 2069 | * |
| 2070 | * This is called by the driver on open to configure the DCB hardware. |
| 2071 | * This is also called by the gennetlink interface when reconfiguring |
| 2072 | * the DCB state. |
| 2073 | */ |
| 2074 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 2075 | { |
| 2076 | struct ixgbe_hw *hw = &adapter->hw; |
| 2077 | u32 txdctl, vlnctrl; |
| 2078 | int i, j; |
| 2079 | |
| 2080 | ixgbe_dcb_check_config(&adapter->dcb_cfg); |
| 2081 | ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG); |
| 2082 | ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG); |
| 2083 | |
| 2084 | /* reconfigure the hardware */ |
| 2085 | ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg); |
| 2086 | |
| 2087 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2088 | j = adapter->tx_ring[i].reg_idx; |
| 2089 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
| 2090 | /* PThresh workaround for Tx hang with DFP enabled. */ |
| 2091 | txdctl |= 32; |
| 2092 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
| 2093 | } |
| 2094 | /* Enable VLAN tag insert/strip */ |
| 2095 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2096 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 2097 | vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE; |
| 2098 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2099 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 2100 | } else if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2101 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 2102 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2103 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 2104 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 2105 | j = adapter->rx_ring[i].reg_idx; |
| 2106 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 2107 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 2108 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 2109 | } |
| 2110 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2111 | hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true); |
| 2112 | } |
| 2113 | |
| 2114 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2115 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 2116 | { |
| 2117 | struct net_device *netdev = adapter->netdev; |
| 2118 | int i; |
| 2119 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2120 | ixgbe_set_rx_mode(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2121 | |
| 2122 | ixgbe_restore_vlan(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 2123 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2124 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 2125 | netif_set_gso_max_size(netdev, 32768); |
| 2126 | ixgbe_configure_dcb(adapter); |
| 2127 | } else { |
| 2128 | netif_set_gso_max_size(netdev, 65536); |
| 2129 | } |
| 2130 | #else |
| 2131 | netif_set_gso_max_size(netdev, 65536); |
| 2132 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2133 | |
| 2134 | ixgbe_configure_tx(adapter); |
| 2135 | ixgbe_configure_rx(adapter); |
| 2136 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 2137 | ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i], |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2138 | (adapter->rx_ring[i].count - 1)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2139 | } |
| 2140 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2141 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 2142 | { |
| 2143 | switch (hw->phy.type) { |
| 2144 | case ixgbe_phy_sfp_avago: |
| 2145 | case ixgbe_phy_sfp_ftl: |
| 2146 | case ixgbe_phy_sfp_intel: |
| 2147 | case ixgbe_phy_sfp_unknown: |
| 2148 | case ixgbe_phy_tw_tyco: |
| 2149 | case ixgbe_phy_tw_unknown: |
| 2150 | return true; |
| 2151 | default: |
| 2152 | return false; |
| 2153 | } |
| 2154 | } |
| 2155 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2156 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2157 | * ixgbe_sfp_link_config - set up SFP+ link |
| 2158 | * @adapter: pointer to private adapter struct |
| 2159 | **/ |
| 2160 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 2161 | { |
| 2162 | struct ixgbe_hw *hw = &adapter->hw; |
| 2163 | |
| 2164 | if (hw->phy.multispeed_fiber) { |
| 2165 | /* |
| 2166 | * In multispeed fiber setups, the device may not have |
| 2167 | * had a physical connection when the driver loaded. |
| 2168 | * If that's the case, the initial link configuration |
| 2169 | * couldn't get the MAC into 10G or 1G mode, so we'll |
| 2170 | * never have a link status change interrupt fire. |
| 2171 | * We need to try and force an autonegotiation |
| 2172 | * session, then bring up link. |
| 2173 | */ |
| 2174 | hw->mac.ops.setup_sfp(hw); |
| 2175 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK)) |
| 2176 | schedule_work(&adapter->multispeed_fiber_task); |
| 2177 | } else { |
| 2178 | /* |
| 2179 | * Direct Attach Cu and non-multispeed fiber modules |
| 2180 | * still need to be configured properly prior to |
| 2181 | * attempting link. |
| 2182 | */ |
| 2183 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK)) |
| 2184 | schedule_work(&adapter->sfp_config_module_task); |
| 2185 | } |
| 2186 | } |
| 2187 | |
| 2188 | /** |
| 2189 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2190 | * @hw: pointer to private hardware struct |
| 2191 | * |
| 2192 | * Returns 0 on success, negative on failure |
| 2193 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2194 | 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] | 2195 | { |
| 2196 | u32 autoneg; |
| 2197 | bool link_up = false; |
| 2198 | u32 ret = IXGBE_ERR_LINK_SETUP; |
| 2199 | |
| 2200 | if (hw->mac.ops.check_link) |
| 2201 | ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 2202 | |
| 2203 | if (ret) |
| 2204 | goto link_cfg_out; |
| 2205 | |
| 2206 | if (hw->mac.ops.get_link_capabilities) |
| 2207 | ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, |
| 2208 | &hw->mac.autoneg); |
| 2209 | if (ret) |
| 2210 | goto link_cfg_out; |
| 2211 | |
| 2212 | if (hw->mac.ops.setup_link_speed) |
| 2213 | ret = hw->mac.ops.setup_link_speed(hw, autoneg, true, link_up); |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2214 | link_cfg_out: |
| 2215 | return ret; |
| 2216 | } |
| 2217 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2218 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 2219 | static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 2220 | int rxr) |
| 2221 | { |
| 2222 | int j = adapter->rx_ring[rxr].reg_idx; |
| 2223 | int k; |
| 2224 | |
| 2225 | for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) { |
| 2226 | if (IXGBE_READ_REG(&adapter->hw, |
| 2227 | IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE) |
| 2228 | break; |
| 2229 | else |
| 2230 | msleep(1); |
| 2231 | } |
| 2232 | if (k >= IXGBE_MAX_RX_DESC_POLL) { |
| 2233 | DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d " |
| 2234 | "not set within the polling period\n", rxr); |
| 2235 | } |
| 2236 | ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr], |
| 2237 | (adapter->rx_ring[rxr].count - 1)); |
| 2238 | } |
| 2239 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2240 | static int ixgbe_up_complete(struct ixgbe_adapter *adapter) |
| 2241 | { |
| 2242 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2243 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2244 | int i, j = 0; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2245 | int num_rx_rings = adapter->num_rx_queues; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2246 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2247 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2248 | u32 txdctl, rxdctl, mhadd; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2249 | u32 dmatxctl; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2250 | u32 gpie; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2251 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 2252 | ixgbe_get_hw_control(adapter); |
| 2253 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2254 | if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) || |
| 2255 | (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2256 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2257 | gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2258 | IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2259 | } else { |
| 2260 | /* MSI only */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2261 | gpie = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2262 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2263 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 2264 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 2265 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2266 | } |
| 2267 | |
| 2268 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
| 2269 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 2270 | * specifically only auto mask tx and rx interrupts */ |
| 2271 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2272 | } |
| 2273 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2274 | /* Enable fan failure interrupt if media type is copper */ |
| 2275 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 2276 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 2277 | gpie |= IXGBE_SDP1_GPIEN; |
| 2278 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2279 | } |
| 2280 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2281 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2282 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 2283 | gpie |= IXGBE_SDP1_GPIEN; |
| 2284 | gpie |= IXGBE_SDP2_GPIEN; |
| 2285 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2286 | } |
| 2287 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2288 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2289 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 2290 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 2291 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 2292 | |
| 2293 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
| 2294 | } |
| 2295 | |
| 2296 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2297 | j = adapter->tx_ring[i].reg_idx; |
| 2298 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 2299 | /* enable WTHRESH=8 descriptors, to encourage burst writeback */ |
| 2300 | txdctl |= (8 << 16); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2301 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
| 2302 | } |
| 2303 | |
| 2304 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2305 | /* DMATXCTL.EN must be set after all Tx queue config is done */ |
| 2306 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 2307 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 2308 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 2309 | } |
| 2310 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2311 | j = adapter->tx_ring[i].reg_idx; |
| 2312 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2313 | txdctl |= IXGBE_TXDCTL_ENABLE; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2314 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2315 | } |
| 2316 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2317 | for (i = 0; i < num_rx_rings; i++) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2318 | j = adapter->rx_ring[i].reg_idx; |
| 2319 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 2320 | /* enable PTHRESH=32 descriptors (half the internal cache) |
| 2321 | * and HTHRESH=0 descriptors (to minimize latency on fetch), |
| 2322 | * this also removes a pesky rx_no_buffer_count increment */ |
| 2323 | rxdctl |= 0x0020; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2324 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2325 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2326 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 2327 | ixgbe_rx_desc_queue_enable(adapter, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2328 | } |
| 2329 | /* enable all receives */ |
| 2330 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2331 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2332 | rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN); |
| 2333 | else |
| 2334 | rxdctl |= IXGBE_RXCTRL_RXEN; |
| 2335 | hw->mac.ops.enable_rx_dma(hw, rxdctl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2336 | |
| 2337 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 2338 | ixgbe_configure_msix(adapter); |
| 2339 | else |
| 2340 | ixgbe_configure_msi_and_legacy(adapter); |
| 2341 | |
| 2342 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2343 | ixgbe_napi_enable_all(adapter); |
| 2344 | |
| 2345 | /* clear any pending interrupts, may auto mask */ |
| 2346 | IXGBE_READ_REG(hw, IXGBE_EICR); |
| 2347 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2348 | ixgbe_irq_enable(adapter); |
| 2349 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2350 | /* |
| 2351 | * For hot-pluggable SFP+ devices, a new SFP+ module may have |
| 2352 | * arrived before interrupts were enabled. We need to kick off |
| 2353 | * the SFP+ module setup first, then try to bring up link. |
| 2354 | * If we're not hot-pluggable SFP+, we just need to configure link |
| 2355 | * and bring it up. |
| 2356 | */ |
| 2357 | err = hw->phy.ops.identify(hw); |
| 2358 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
| 2359 | DPRINTK(PROBE, ERR, "PHY not supported on this NIC %d\n", err); |
| 2360 | ixgbe_down(adapter); |
| 2361 | return err; |
| 2362 | } |
| 2363 | |
| 2364 | if (ixgbe_is_sfp(hw)) { |
| 2365 | ixgbe_sfp_link_config(adapter); |
| 2366 | } else { |
| 2367 | err = ixgbe_non_sfp_link_config(hw); |
| 2368 | if (err) |
| 2369 | DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err); |
| 2370 | } |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2371 | |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 2372 | /* enable transmits */ |
| 2373 | netif_tx_start_all_queues(netdev); |
| 2374 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2375 | /* bring the link up in the watchdog, this could race with our first |
| 2376 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2377 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2378 | adapter->link_check_timeout = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2379 | mod_timer(&adapter->watchdog_timer, jiffies); |
| 2380 | return 0; |
| 2381 | } |
| 2382 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2383 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 2384 | { |
| 2385 | WARN_ON(in_interrupt()); |
| 2386 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
| 2387 | msleep(1); |
| 2388 | ixgbe_down(adapter); |
| 2389 | ixgbe_up(adapter); |
| 2390 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 2391 | } |
| 2392 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2393 | int ixgbe_up(struct ixgbe_adapter *adapter) |
| 2394 | { |
| 2395 | /* hardware has been reset, we need to reload some things */ |
| 2396 | ixgbe_configure(adapter); |
| 2397 | |
Jesse Brandeburg | 4dd64df | 2009-03-13 22:13:49 +0000 | [diff] [blame] | 2398 | ixgbe_napi_add_all(adapter); |
| 2399 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2400 | return ixgbe_up_complete(adapter); |
| 2401 | } |
| 2402 | |
| 2403 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 2404 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2405 | struct ixgbe_hw *hw = &adapter->hw; |
| 2406 | if (hw->mac.ops.init_hw(hw)) |
| 2407 | dev_err(&adapter->pdev->dev, "Hardware Error\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2408 | |
| 2409 | /* reprogram the RAR[0] in case user changed it. */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2410 | 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] | 2411 | |
| 2412 | } |
| 2413 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2414 | /** |
| 2415 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
| 2416 | * @adapter: board private structure |
| 2417 | * @rx_ring: ring to free buffers from |
| 2418 | **/ |
| 2419 | static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2420 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2421 | { |
| 2422 | struct pci_dev *pdev = adapter->pdev; |
| 2423 | unsigned long size; |
| 2424 | unsigned int i; |
| 2425 | |
| 2426 | /* Free all the Rx ring sk_buffs */ |
| 2427 | |
| 2428 | for (i = 0; i < rx_ring->count; i++) { |
| 2429 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 2430 | |
| 2431 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
| 2432 | if (rx_buffer_info->dma) { |
| 2433 | pci_unmap_single(pdev, rx_buffer_info->dma, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2434 | rx_ring->rx_buf_len, |
| 2435 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2436 | rx_buffer_info->dma = 0; |
| 2437 | } |
| 2438 | if (rx_buffer_info->skb) { |
| 2439 | dev_kfree_skb(rx_buffer_info->skb); |
| 2440 | rx_buffer_info->skb = NULL; |
| 2441 | } |
| 2442 | if (!rx_buffer_info->page) |
| 2443 | continue; |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 2444 | pci_unmap_page(pdev, rx_buffer_info->page_dma, PAGE_SIZE / 2, |
| 2445 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2446 | rx_buffer_info->page_dma = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2447 | put_page(rx_buffer_info->page); |
| 2448 | rx_buffer_info->page = NULL; |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 2449 | rx_buffer_info->page_offset = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2450 | } |
| 2451 | |
| 2452 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 2453 | memset(rx_ring->rx_buffer_info, 0, size); |
| 2454 | |
| 2455 | /* Zero out the descriptor ring */ |
| 2456 | memset(rx_ring->desc, 0, rx_ring->size); |
| 2457 | |
| 2458 | rx_ring->next_to_clean = 0; |
| 2459 | rx_ring->next_to_use = 0; |
| 2460 | |
| 2461 | writel(0, adapter->hw.hw_addr + rx_ring->head); |
| 2462 | writel(0, adapter->hw.hw_addr + rx_ring->tail); |
| 2463 | } |
| 2464 | |
| 2465 | /** |
| 2466 | * ixgbe_clean_tx_ring - Free Tx Buffers |
| 2467 | * @adapter: board private structure |
| 2468 | * @tx_ring: ring to be cleaned |
| 2469 | **/ |
| 2470 | static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2471 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2472 | { |
| 2473 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 2474 | unsigned long size; |
| 2475 | unsigned int i; |
| 2476 | |
| 2477 | /* Free all the Tx ring sk_buffs */ |
| 2478 | |
| 2479 | for (i = 0; i < tx_ring->count; i++) { |
| 2480 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 2481 | ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info); |
| 2482 | } |
| 2483 | |
| 2484 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 2485 | memset(tx_ring->tx_buffer_info, 0, size); |
| 2486 | |
| 2487 | /* Zero out the descriptor ring */ |
| 2488 | memset(tx_ring->desc, 0, tx_ring->size); |
| 2489 | |
| 2490 | tx_ring->next_to_use = 0; |
| 2491 | tx_ring->next_to_clean = 0; |
| 2492 | |
| 2493 | writel(0, adapter->hw.hw_addr + tx_ring->head); |
| 2494 | writel(0, adapter->hw.hw_addr + tx_ring->tail); |
| 2495 | } |
| 2496 | |
| 2497 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2498 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 2499 | * @adapter: board private structure |
| 2500 | **/ |
| 2501 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 2502 | { |
| 2503 | int i; |
| 2504 | |
| 2505 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 2506 | ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]); |
| 2507 | } |
| 2508 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2509 | /** |
| 2510 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 2511 | * @adapter: board private structure |
| 2512 | **/ |
| 2513 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 2514 | { |
| 2515 | int i; |
| 2516 | |
| 2517 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2518 | ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]); |
| 2519 | } |
| 2520 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2521 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 2522 | { |
| 2523 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2524 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2525 | u32 rxctrl; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2526 | u32 txdctl; |
| 2527 | int i, j; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2528 | |
| 2529 | /* signal that we are down to the interrupt handler */ |
| 2530 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 2531 | |
| 2532 | /* disable receives */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2533 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 2534 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2535 | |
| 2536 | netif_tx_disable(netdev); |
| 2537 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2538 | IXGBE_WRITE_FLUSH(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2539 | msleep(10); |
| 2540 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2541 | netif_tx_stop_all_queues(netdev); |
| 2542 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2543 | ixgbe_irq_disable(adapter); |
| 2544 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2545 | ixgbe_napi_disable_all(adapter); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2546 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2547 | del_timer_sync(&adapter->watchdog_timer); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2548 | cancel_work_sync(&adapter->watchdog_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2549 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2550 | /* disable transmits in the hardware now that interrupts are off */ |
| 2551 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2552 | j = adapter->tx_ring[i].reg_idx; |
| 2553 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
| 2554 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), |
| 2555 | (txdctl & ~IXGBE_TXDCTL_ENABLE)); |
| 2556 | } |
| 2557 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2558 | netif_carrier_off(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2559 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 2560 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 2561 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 2562 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 2563 | dca_remove_requester(&adapter->pdev->dev); |
| 2564 | } |
| 2565 | |
| 2566 | #endif |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 2567 | if (!pci_channel_offline(adapter->pdev)) |
| 2568 | ixgbe_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2569 | ixgbe_clean_all_tx_rings(adapter); |
| 2570 | ixgbe_clean_all_rx_rings(adapter); |
| 2571 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 2572 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 2573 | /* since we reset the hardware DCA settings were cleared */ |
| 2574 | if (dca_add_requester(&adapter->pdev->dev) == 0) { |
| 2575 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
| 2576 | /* always use CB2 mode, difference is masked |
| 2577 | * in the CB driver */ |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2578 | IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2); |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 2579 | ixgbe_setup_dca(adapter); |
| 2580 | } |
| 2581 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2582 | } |
| 2583 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2584 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2585 | * ixgbe_poll - NAPI Rx polling callback |
| 2586 | * @napi: structure for representing this polling device |
| 2587 | * @budget: how many packets driver is allowed to clean |
| 2588 | * |
| 2589 | * This function is used for legacy and MSI, NAPI mode |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2590 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2591 | static int ixgbe_poll(struct napi_struct *napi, int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2592 | { |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 2593 | struct ixgbe_q_vector *q_vector = |
| 2594 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2595 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 2596 | int tx_clean_complete, work_done = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2597 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 2598 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 2599 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 2600 | ixgbe_update_tx_dca(adapter, adapter->tx_ring); |
| 2601 | ixgbe_update_rx_dca(adapter, adapter->rx_ring); |
| 2602 | } |
| 2603 | #endif |
| 2604 | |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 2605 | tx_clean_complete = ixgbe_clean_tx_irq(adapter, adapter->tx_ring); |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 2606 | ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2607 | |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 2608 | if (!tx_clean_complete) |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 2609 | work_done = budget; |
| 2610 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 2611 | /* If budget not fully consumed, exit the polling mode */ |
| 2612 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 2613 | napi_complete(napi); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2614 | if (adapter->itr_setting & 1) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 2615 | ixgbe_set_itr(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2616 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2617 | ixgbe_irq_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2618 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2619 | return work_done; |
| 2620 | } |
| 2621 | |
| 2622 | /** |
| 2623 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 2624 | * @netdev: network interface device structure |
| 2625 | **/ |
| 2626 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 2627 | { |
| 2628 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2629 | |
| 2630 | /* Do the reset outside of interrupt context */ |
| 2631 | schedule_work(&adapter->reset_task); |
| 2632 | } |
| 2633 | |
| 2634 | static void ixgbe_reset_task(struct work_struct *work) |
| 2635 | { |
| 2636 | struct ixgbe_adapter *adapter; |
| 2637 | adapter = container_of(work, struct ixgbe_adapter, reset_task); |
| 2638 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2639 | /* If we're already down or resetting, just bail */ |
| 2640 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 2641 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 2642 | return; |
| 2643 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2644 | adapter->tx_timeout_count++; |
| 2645 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2646 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2647 | } |
| 2648 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2649 | #ifdef CONFIG_IXGBE_DCB |
| 2650 | static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 2651 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2652 | bool ret = false; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 2653 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2654 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 2655 | adapter->ring_feature[RING_F_DCB].mask = 0x7 << 3; |
| 2656 | adapter->num_rx_queues = |
| 2657 | adapter->ring_feature[RING_F_DCB].indices; |
| 2658 | adapter->num_tx_queues = |
| 2659 | adapter->ring_feature[RING_F_DCB].indices; |
| 2660 | ret = true; |
| 2661 | } else { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2662 | ret = false; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 2663 | } |
| 2664 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2665 | return ret; |
| 2666 | } |
| 2667 | #endif |
| 2668 | |
| 2669 | static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter) |
| 2670 | { |
| 2671 | bool ret = false; |
| 2672 | |
| 2673 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 2674 | adapter->ring_feature[RING_F_RSS].mask = 0xF; |
| 2675 | adapter->num_rx_queues = |
| 2676 | adapter->ring_feature[RING_F_RSS].indices; |
| 2677 | adapter->num_tx_queues = |
| 2678 | adapter->ring_feature[RING_F_RSS].indices; |
| 2679 | ret = true; |
| 2680 | } else { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2681 | ret = false; |
| 2682 | } |
| 2683 | |
| 2684 | return ret; |
| 2685 | } |
| 2686 | |
| 2687 | static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter) |
| 2688 | { |
| 2689 | /* Start with base case */ |
| 2690 | adapter->num_rx_queues = 1; |
| 2691 | adapter->num_tx_queues = 1; |
| 2692 | |
| 2693 | #ifdef CONFIG_IXGBE_DCB |
| 2694 | if (ixgbe_set_dcb_queues(adapter)) |
| 2695 | return; |
| 2696 | |
| 2697 | #endif |
| 2698 | if (ixgbe_set_rss_queues(adapter)) |
| 2699 | return; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 2700 | } |
| 2701 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2702 | static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2703 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2704 | { |
| 2705 | int err, vector_threshold; |
| 2706 | |
| 2707 | /* We'll want at least 3 (vector_threshold): |
| 2708 | * 1) TxQ[0] Cleanup |
| 2709 | * 2) RxQ[0] Cleanup |
| 2710 | * 3) Other (Link Status Change, etc.) |
| 2711 | * 4) TCP Timer (optional) |
| 2712 | */ |
| 2713 | vector_threshold = MIN_MSIX_COUNT; |
| 2714 | |
| 2715 | /* The more we get, the more we will assign to Tx/Rx Cleanup |
| 2716 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 2717 | * Right now, we simply care about how many we'll get; we'll |
| 2718 | * set them up later while requesting irq's. |
| 2719 | */ |
| 2720 | while (vectors >= vector_threshold) { |
| 2721 | err = pci_enable_msix(adapter->pdev, adapter->msix_entries, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2722 | vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2723 | if (!err) /* Success in acquiring all requested vectors. */ |
| 2724 | break; |
| 2725 | else if (err < 0) |
| 2726 | vectors = 0; /* Nasty failure, quit now */ |
| 2727 | else /* err == number of vectors we should try again with */ |
| 2728 | vectors = err; |
| 2729 | } |
| 2730 | |
| 2731 | if (vectors < vector_threshold) { |
| 2732 | /* Can't allocate enough MSI-X interrupts? Oh well. |
| 2733 | * This just means we'll go with either a single MSI |
| 2734 | * vector or fall back to legacy interrupts. |
| 2735 | */ |
| 2736 | DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n"); |
| 2737 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 2738 | kfree(adapter->msix_entries); |
| 2739 | adapter->msix_entries = NULL; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2740 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2741 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 2742 | ixgbe_set_num_queues(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2743 | } else { |
| 2744 | adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */ |
Peter P Waskiewicz Jr | eb7f139 | 2009-02-01 01:18:58 -0800 | [diff] [blame] | 2745 | /* |
| 2746 | * Adjust for only the vectors we'll use, which is minimum |
| 2747 | * of max_msix_q_vectors + NON_Q_VECTORS, or the number of |
| 2748 | * vectors we were allocated. |
| 2749 | */ |
| 2750 | adapter->num_msix_vectors = min(vectors, |
| 2751 | adapter->max_msix_q_vectors + NON_Q_VECTORS); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2752 | } |
| 2753 | } |
| 2754 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2755 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2756 | * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2757 | * @adapter: board private structure to initialize |
| 2758 | * |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2759 | * Cache the descriptor ring offsets for RSS to the assigned rings. |
| 2760 | * |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2761 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2762 | static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2763 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2764 | int i; |
| 2765 | bool ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2766 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2767 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 2768 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 2769 | adapter->rx_ring[i].reg_idx = i; |
| 2770 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2771 | adapter->tx_ring[i].reg_idx = i; |
| 2772 | ret = true; |
| 2773 | } else { |
| 2774 | ret = false; |
| 2775 | } |
| 2776 | |
| 2777 | return ret; |
| 2778 | } |
| 2779 | |
| 2780 | #ifdef CONFIG_IXGBE_DCB |
| 2781 | /** |
| 2782 | * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB |
| 2783 | * @adapter: board private structure to initialize |
| 2784 | * |
| 2785 | * Cache the descriptor ring offsets for DCB to the assigned rings. |
| 2786 | * |
| 2787 | **/ |
| 2788 | static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter) |
| 2789 | { |
| 2790 | int i; |
| 2791 | bool ret = false; |
| 2792 | int dcb_i = adapter->ring_feature[RING_F_DCB].indices; |
| 2793 | |
| 2794 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 2795 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2796 | /* the number of queues is assumed to be symmetric */ |
| 2797 | for (i = 0; i < dcb_i; i++) { |
| 2798 | adapter->rx_ring[i].reg_idx = i << 3; |
| 2799 | adapter->tx_ring[i].reg_idx = i << 2; |
| 2800 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2801 | ret = true; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2802 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 2803 | for (i = 0; i < dcb_i; i++) { |
| 2804 | adapter->rx_ring[i].reg_idx = i << 4; |
| 2805 | adapter->tx_ring[i].reg_idx = i << 4; |
| 2806 | } |
| 2807 | ret = true; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2808 | } else { |
| 2809 | ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2810 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2811 | } else { |
| 2812 | ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2813 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 2814 | |
| 2815 | return ret; |
| 2816 | } |
| 2817 | #endif |
| 2818 | |
| 2819 | /** |
| 2820 | * ixgbe_cache_ring_register - Descriptor ring to register mapping |
| 2821 | * @adapter: board private structure to initialize |
| 2822 | * |
| 2823 | * Once we know the feature-set enabled for the device, we'll cache |
| 2824 | * the register offset the descriptor ring is assigned to. |
| 2825 | * |
| 2826 | * Note, the order the various feature calls is important. It must start with |
| 2827 | * the "most" features enabled at the same time, then trickle down to the |
| 2828 | * least amount of features turned on at once. |
| 2829 | **/ |
| 2830 | static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) |
| 2831 | { |
| 2832 | /* start with default case */ |
| 2833 | adapter->rx_ring[0].reg_idx = 0; |
| 2834 | adapter->tx_ring[0].reg_idx = 0; |
| 2835 | |
| 2836 | #ifdef CONFIG_IXGBE_DCB |
| 2837 | if (ixgbe_cache_ring_dcb(adapter)) |
| 2838 | return; |
| 2839 | |
| 2840 | #endif |
| 2841 | if (ixgbe_cache_ring_rss(adapter)) |
| 2842 | return; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2843 | } |
| 2844 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2845 | /** |
| 2846 | * ixgbe_alloc_queues - Allocate memory for all rings |
| 2847 | * @adapter: board private structure to initialize |
| 2848 | * |
| 2849 | * We allocate one ring per queue at run-time since we don't know the |
Wang Chen | a4d2f34 | 2008-12-03 22:05:58 -0800 | [diff] [blame] | 2850 | * number of queues at compile-time. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2851 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2852 | static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2853 | { |
| 2854 | int i; |
| 2855 | |
| 2856 | adapter->tx_ring = kcalloc(adapter->num_tx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2857 | sizeof(struct ixgbe_ring), GFP_KERNEL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2858 | if (!adapter->tx_ring) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2859 | goto err_tx_ring_allocation; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2860 | |
| 2861 | adapter->rx_ring = kcalloc(adapter->num_rx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2862 | sizeof(struct ixgbe_ring), GFP_KERNEL); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2863 | if (!adapter->rx_ring) |
| 2864 | goto err_rx_ring_allocation; |
| 2865 | |
| 2866 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 2867 | adapter->tx_ring[i].count = adapter->tx_ring_count; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2868 | adapter->tx_ring[i].queue_index = i; |
| 2869 | } |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 2870 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2871 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 2872 | adapter->rx_ring[i].count = adapter->rx_ring_count; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2873 | adapter->rx_ring[i].queue_index = i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2874 | } |
| 2875 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2876 | ixgbe_cache_ring_register(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2877 | |
| 2878 | return 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2879 | |
| 2880 | err_rx_ring_allocation: |
| 2881 | kfree(adapter->tx_ring); |
| 2882 | err_tx_ring_allocation: |
| 2883 | return -ENOMEM; |
| 2884 | } |
| 2885 | |
| 2886 | /** |
| 2887 | * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported |
| 2888 | * @adapter: board private structure to initialize |
| 2889 | * |
| 2890 | * Attempt to configure the interrupts using the best available |
| 2891 | * capabilities of the hardware and the kernel. |
| 2892 | **/ |
Al Viro | feea6a5 | 2008-11-27 15:34:07 -0800 | [diff] [blame] | 2893 | static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2894 | { |
| 2895 | int err = 0; |
| 2896 | int vector, v_budget; |
| 2897 | |
| 2898 | /* |
| 2899 | * It's easy to be greedy for MSI-X vectors, but it really |
| 2900 | * doesn't do us much good if we have a lot more vectors |
| 2901 | * than CPU's. So let's be conservative and only ask for |
| 2902 | * (roughly) twice the number of vectors as there are CPU's. |
| 2903 | */ |
| 2904 | v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2905 | (int)(num_online_cpus() * 2)) + NON_Q_VECTORS; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2906 | |
| 2907 | /* |
| 2908 | * At the same time, hardware can only support a maximum of |
| 2909 | * MAX_MSIX_COUNT vectors. With features such as RSS and VMDq, |
| 2910 | * we can easily reach upwards of 64 Rx descriptor queues and |
| 2911 | * 32 Tx queues. Thus, we cap it off in those rare cases where |
| 2912 | * the cpu count also exceeds our vector limit. |
| 2913 | */ |
| 2914 | v_budget = min(v_budget, MAX_MSIX_COUNT); |
| 2915 | |
| 2916 | /* A failure in MSI-X entry allocation isn't fatal, but it does |
| 2917 | * mean we disable MSI-X capabilities of the adapter. */ |
| 2918 | adapter->msix_entries = kcalloc(v_budget, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2919 | sizeof(struct msix_entry), GFP_KERNEL); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2920 | if (!adapter->msix_entries) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2921 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2922 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
| 2923 | ixgbe_set_num_queues(adapter); |
| 2924 | kfree(adapter->tx_ring); |
| 2925 | kfree(adapter->rx_ring); |
| 2926 | err = ixgbe_alloc_queues(adapter); |
| 2927 | if (err) { |
| 2928 | DPRINTK(PROBE, ERR, "Unable to allocate memory " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2929 | "for queues\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2930 | goto out; |
| 2931 | } |
| 2932 | |
| 2933 | goto try_msi; |
| 2934 | } |
| 2935 | |
| 2936 | for (vector = 0; vector < v_budget; vector++) |
| 2937 | adapter->msix_entries[vector].entry = vector; |
| 2938 | |
| 2939 | ixgbe_acquire_msix_vectors(adapter, v_budget); |
| 2940 | |
| 2941 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 2942 | goto out; |
| 2943 | |
| 2944 | try_msi: |
| 2945 | err = pci_enable_msi(adapter->pdev); |
| 2946 | if (!err) { |
| 2947 | adapter->flags |= IXGBE_FLAG_MSI_ENABLED; |
| 2948 | } else { |
| 2949 | DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2950 | "falling back to legacy. Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2951 | /* reset err */ |
| 2952 | err = 0; |
| 2953 | } |
| 2954 | |
| 2955 | out: |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 2956 | /* Notify the stack of the (possibly) reduced Tx Queue count. */ |
David S. Miller | fd2ea0a | 2008-07-17 01:56:23 -0700 | [diff] [blame] | 2957 | adapter->netdev->real_num_tx_queues = adapter->num_tx_queues; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2958 | |
| 2959 | return err; |
| 2960 | } |
| 2961 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2962 | void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2963 | { |
| 2964 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2965 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 2966 | pci_disable_msix(adapter->pdev); |
| 2967 | kfree(adapter->msix_entries); |
| 2968 | adapter->msix_entries = NULL; |
| 2969 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 2970 | adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED; |
| 2971 | pci_disable_msi(adapter->pdev); |
| 2972 | } |
| 2973 | return; |
| 2974 | } |
| 2975 | |
| 2976 | /** |
| 2977 | * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme |
| 2978 | * @adapter: board private structure to initialize |
| 2979 | * |
| 2980 | * We determine which interrupt scheme to use based on... |
| 2981 | * - Kernel support (MSI, MSI-X) |
| 2982 | * - which can be user-defined (via MODULE_PARAM) |
| 2983 | * - Hardware queue count (num_*_queues) |
| 2984 | * - defined by miscellaneous hardware support/features (RSS, etc.) |
| 2985 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2986 | int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2987 | { |
| 2988 | int err; |
| 2989 | |
| 2990 | /* Number of supported queues */ |
| 2991 | ixgbe_set_num_queues(adapter); |
| 2992 | |
| 2993 | err = ixgbe_alloc_queues(adapter); |
| 2994 | if (err) { |
| 2995 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n"); |
| 2996 | goto err_alloc_queues; |
| 2997 | } |
| 2998 | |
| 2999 | err = ixgbe_set_interrupt_capability(adapter); |
| 3000 | if (err) { |
| 3001 | DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n"); |
| 3002 | goto err_set_interrupt; |
| 3003 | } |
| 3004 | |
| 3005 | DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3006 | "Tx Queue count = %u\n", |
| 3007 | (adapter->num_rx_queues > 1) ? "Enabled" : |
| 3008 | "Disabled", adapter->num_rx_queues, adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3009 | |
| 3010 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 3011 | |
| 3012 | return 0; |
| 3013 | |
| 3014 | err_set_interrupt: |
| 3015 | kfree(adapter->tx_ring); |
| 3016 | kfree(adapter->rx_ring); |
| 3017 | err_alloc_queues: |
| 3018 | return err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3019 | } |
| 3020 | |
| 3021 | /** |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3022 | * ixgbe_sfp_timer - worker thread to find a missing module |
| 3023 | * @data: pointer to our adapter struct |
| 3024 | **/ |
| 3025 | static void ixgbe_sfp_timer(unsigned long data) |
| 3026 | { |
| 3027 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 3028 | |
| 3029 | /* Do the sfp_timer outside of interrupt context due to the |
| 3030 | * delays that sfp+ detection requires |
| 3031 | */ |
| 3032 | schedule_work(&adapter->sfp_task); |
| 3033 | } |
| 3034 | |
| 3035 | /** |
| 3036 | * ixgbe_sfp_task - worker thread to find a missing module |
| 3037 | * @work: pointer to work_struct containing our data |
| 3038 | **/ |
| 3039 | static void ixgbe_sfp_task(struct work_struct *work) |
| 3040 | { |
| 3041 | struct ixgbe_adapter *adapter = container_of(work, |
| 3042 | struct ixgbe_adapter, |
| 3043 | sfp_task); |
| 3044 | struct ixgbe_hw *hw = &adapter->hw; |
| 3045 | |
| 3046 | if ((hw->phy.type == ixgbe_phy_nl) && |
| 3047 | (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) { |
| 3048 | s32 ret = hw->phy.ops.identify_sfp(hw); |
| 3049 | if (ret) |
| 3050 | goto reschedule; |
| 3051 | ret = hw->phy.ops.reset(hw); |
| 3052 | if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
| 3053 | DPRINTK(PROBE, ERR, "failed to initialize because an " |
| 3054 | "unsupported SFP+ module type was detected.\n" |
| 3055 | "Reload the driver after installing a " |
| 3056 | "supported module.\n"); |
| 3057 | unregister_netdev(adapter->netdev); |
| 3058 | } else { |
| 3059 | DPRINTK(PROBE, INFO, "detected SFP+: %d\n", |
| 3060 | hw->phy.sfp_type); |
| 3061 | } |
| 3062 | /* don't need this routine any more */ |
| 3063 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 3064 | } |
| 3065 | return; |
| 3066 | reschedule: |
| 3067 | if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state)) |
| 3068 | mod_timer(&adapter->sfp_timer, |
| 3069 | round_jiffies(jiffies + (2 * HZ))); |
| 3070 | } |
| 3071 | |
| 3072 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3073 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 3074 | * @adapter: board private structure to initialize |
| 3075 | * |
| 3076 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 3077 | * Fields are initialized based on PCI device information and |
| 3078 | * OS network device settings (MTU size). |
| 3079 | **/ |
| 3080 | static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter) |
| 3081 | { |
| 3082 | struct ixgbe_hw *hw = &adapter->hw; |
| 3083 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3084 | unsigned int rss; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3085 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3086 | int j; |
| 3087 | struct tc_configuration *tc; |
| 3088 | #endif |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3089 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3090 | /* PCI config space info */ |
| 3091 | |
| 3092 | hw->vendor_id = pdev->vendor; |
| 3093 | hw->device_id = pdev->device; |
| 3094 | hw->revision_id = pdev->revision; |
| 3095 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 3096 | hw->subsystem_device_id = pdev->subsystem_device; |
| 3097 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3098 | /* Set capability flags */ |
| 3099 | rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus()); |
| 3100 | adapter->ring_feature[RING_F_RSS].indices = rss; |
| 3101 | adapter->flags |= IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3102 | adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3103 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3104 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598; |
| 3105 | else if (hw->mac.type == ixgbe_mac_82599EB) |
| 3106 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3107 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3108 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3109 | /* Configure DCB traffic classes */ |
| 3110 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 3111 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 3112 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 3113 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 3114 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 3115 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 3116 | tc->dcb_pfc = pfc_disabled; |
| 3117 | } |
| 3118 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 3119 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
| 3120 | adapter->dcb_cfg.rx_pba_cfg = pba_equal; |
| 3121 | adapter->dcb_cfg.round_robin_enable = false; |
| 3122 | adapter->dcb_set_bitmap = 0x00; |
| 3123 | ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg, |
| 3124 | adapter->ring_feature[RING_F_DCB].indices); |
| 3125 | |
| 3126 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3127 | |
| 3128 | /* default flow control settings */ |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 3129 | hw->fc.requested_mode = ixgbe_fc_none; |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 3130 | hw->fc.high_water = IXGBE_DEFAULT_FCRTH; |
| 3131 | hw->fc.low_water = IXGBE_DEFAULT_FCRTL; |
| 3132 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 3133 | hw->fc.send_xon = true; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3134 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 3135 | /* enable itr by default in dynamic mode */ |
| 3136 | adapter->itr_setting = 1; |
| 3137 | adapter->eitr_param = 20000; |
| 3138 | |
| 3139 | /* set defaults for eitr in MegaBytes */ |
| 3140 | adapter->eitr_low = 10; |
| 3141 | adapter->eitr_high = 20; |
| 3142 | |
| 3143 | /* set default ring sizes */ |
| 3144 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 3145 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 3146 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3147 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3148 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3149 | dev_err(&pdev->dev, "EEPROM initialization failed\n"); |
| 3150 | return -EIO; |
| 3151 | } |
| 3152 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3153 | /* enable rx csum by default */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3154 | adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED; |
| 3155 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3156 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 3157 | |
| 3158 | return 0; |
| 3159 | } |
| 3160 | |
| 3161 | /** |
| 3162 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
| 3163 | * @adapter: board private structure |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3164 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3165 | * |
| 3166 | * Return 0 on success, negative on failure |
| 3167 | **/ |
| 3168 | int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 3169 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3170 | { |
| 3171 | struct pci_dev *pdev = adapter->pdev; |
| 3172 | int size; |
| 3173 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3174 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 3175 | tx_ring->tx_buffer_info = vmalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 3176 | if (!tx_ring->tx_buffer_info) |
| 3177 | goto err; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3178 | memset(tx_ring->tx_buffer_info, 0, size); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3179 | |
| 3180 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 3181 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3182 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3183 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3184 | tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size, |
| 3185 | &tx_ring->dma); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 3186 | if (!tx_ring->desc) |
| 3187 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3188 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3189 | tx_ring->next_to_use = 0; |
| 3190 | tx_ring->next_to_clean = 0; |
| 3191 | tx_ring->work_limit = tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3192 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 3193 | |
| 3194 | err: |
| 3195 | vfree(tx_ring->tx_buffer_info); |
| 3196 | tx_ring->tx_buffer_info = NULL; |
| 3197 | DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit " |
| 3198 | "descriptor ring\n"); |
| 3199 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3200 | } |
| 3201 | |
| 3202 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 3203 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 3204 | * @adapter: board private structure |
| 3205 | * |
| 3206 | * If this function returns with an error, then it's possible one or |
| 3207 | * more of the rings is populated (while the rest are not). It is the |
| 3208 | * callers duty to clean those orphaned rings. |
| 3209 | * |
| 3210 | * Return 0 on success, negative on failure |
| 3211 | **/ |
| 3212 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 3213 | { |
| 3214 | int i, err = 0; |
| 3215 | |
| 3216 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 3217 | err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]); |
| 3218 | if (!err) |
| 3219 | continue; |
| 3220 | DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i); |
| 3221 | break; |
| 3222 | } |
| 3223 | |
| 3224 | return err; |
| 3225 | } |
| 3226 | |
| 3227 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3228 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
| 3229 | * @adapter: board private structure |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3230 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3231 | * |
| 3232 | * Returns 0 on success, negative on failure |
| 3233 | **/ |
| 3234 | int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3235 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3236 | { |
| 3237 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3238 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3239 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3240 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 3241 | rx_ring->rx_buffer_info = vmalloc(size); |
| 3242 | if (!rx_ring->rx_buffer_info) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3243 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3244 | "vmalloc allocation failed for the rx desc ring\n"); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3245 | goto alloc_failed; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3246 | } |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3247 | memset(rx_ring->rx_buffer_info, 0, size); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3248 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3249 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3250 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 3251 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3252 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3253 | 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] | 3254 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3255 | if (!rx_ring->desc) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3256 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3257 | "Memory allocation failed for the rx desc ring\n"); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3258 | vfree(rx_ring->rx_buffer_info); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3259 | goto alloc_failed; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3260 | } |
| 3261 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3262 | rx_ring->next_to_clean = 0; |
| 3263 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3264 | |
| 3265 | return 0; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3266 | |
| 3267 | alloc_failed: |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3268 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3269 | } |
| 3270 | |
| 3271 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 3272 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 3273 | * @adapter: board private structure |
| 3274 | * |
| 3275 | * If this function returns with an error, then it's possible one or |
| 3276 | * more of the rings is populated (while the rest are not). It is the |
| 3277 | * callers duty to clean those orphaned rings. |
| 3278 | * |
| 3279 | * Return 0 on success, negative on failure |
| 3280 | **/ |
| 3281 | |
| 3282 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 3283 | { |
| 3284 | int i, err = 0; |
| 3285 | |
| 3286 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 3287 | err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]); |
| 3288 | if (!err) |
| 3289 | continue; |
| 3290 | DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i); |
| 3291 | break; |
| 3292 | } |
| 3293 | |
| 3294 | return err; |
| 3295 | } |
| 3296 | |
| 3297 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3298 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
| 3299 | * @adapter: board private structure |
| 3300 | * @tx_ring: Tx descriptor ring for a specific queue |
| 3301 | * |
| 3302 | * Free all transmit software resources |
| 3303 | **/ |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 3304 | void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter, |
| 3305 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3306 | { |
| 3307 | struct pci_dev *pdev = adapter->pdev; |
| 3308 | |
| 3309 | ixgbe_clean_tx_ring(adapter, tx_ring); |
| 3310 | |
| 3311 | vfree(tx_ring->tx_buffer_info); |
| 3312 | tx_ring->tx_buffer_info = NULL; |
| 3313 | |
| 3314 | pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); |
| 3315 | |
| 3316 | tx_ring->desc = NULL; |
| 3317 | } |
| 3318 | |
| 3319 | /** |
| 3320 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 3321 | * @adapter: board private structure |
| 3322 | * |
| 3323 | * Free all transmit software resources |
| 3324 | **/ |
| 3325 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 3326 | { |
| 3327 | int i; |
| 3328 | |
| 3329 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3330 | ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]); |
| 3331 | } |
| 3332 | |
| 3333 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3334 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3335 | * @adapter: board private structure |
| 3336 | * @rx_ring: ring to clean the resources from |
| 3337 | * |
| 3338 | * Free all receive software resources |
| 3339 | **/ |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 3340 | void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter, |
| 3341 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3342 | { |
| 3343 | struct pci_dev *pdev = adapter->pdev; |
| 3344 | |
| 3345 | ixgbe_clean_rx_ring(adapter, rx_ring); |
| 3346 | |
| 3347 | vfree(rx_ring->rx_buffer_info); |
| 3348 | rx_ring->rx_buffer_info = NULL; |
| 3349 | |
| 3350 | pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); |
| 3351 | |
| 3352 | rx_ring->desc = NULL; |
| 3353 | } |
| 3354 | |
| 3355 | /** |
| 3356 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 3357 | * @adapter: board private structure |
| 3358 | * |
| 3359 | * Free all receive software resources |
| 3360 | **/ |
| 3361 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 3362 | { |
| 3363 | int i; |
| 3364 | |
| 3365 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3366 | ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]); |
| 3367 | } |
| 3368 | |
| 3369 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3370 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 3371 | * @netdev: network interface device structure |
| 3372 | * @new_mtu: new value for maximum frame size |
| 3373 | * |
| 3374 | * Returns 0 on success, negative on failure |
| 3375 | **/ |
| 3376 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 3377 | { |
| 3378 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3379 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 3380 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 3381 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 3382 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3383 | return -EINVAL; |
| 3384 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3385 | DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n", |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3386 | netdev->mtu, new_mtu); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3387 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3388 | netdev->mtu = new_mtu; |
| 3389 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3390 | if (netif_running(netdev)) |
| 3391 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3392 | |
| 3393 | return 0; |
| 3394 | } |
| 3395 | |
| 3396 | /** |
| 3397 | * ixgbe_open - Called when a network interface is made active |
| 3398 | * @netdev: network interface device structure |
| 3399 | * |
| 3400 | * Returns 0 on success, negative value on failure |
| 3401 | * |
| 3402 | * The open entry point is called when a network interface is made |
| 3403 | * active by the system (IFF_UP). At this point all resources needed |
| 3404 | * for transmit and receive operations are allocated, the interrupt |
| 3405 | * handler is registered with the OS, the watchdog timer is started, |
| 3406 | * and the stack is notified that the interface is ready. |
| 3407 | **/ |
| 3408 | static int ixgbe_open(struct net_device *netdev) |
| 3409 | { |
| 3410 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3411 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3412 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 3413 | /* disallow open during test */ |
| 3414 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 3415 | return -EBUSY; |
| 3416 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3417 | /* allocate transmit descriptors */ |
| 3418 | err = ixgbe_setup_all_tx_resources(adapter); |
| 3419 | if (err) |
| 3420 | goto err_setup_tx; |
| 3421 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3422 | /* allocate receive descriptors */ |
| 3423 | err = ixgbe_setup_all_rx_resources(adapter); |
| 3424 | if (err) |
| 3425 | goto err_setup_rx; |
| 3426 | |
| 3427 | ixgbe_configure(adapter); |
| 3428 | |
Jesse Brandeburg | 4dd64df | 2009-03-13 22:13:49 +0000 | [diff] [blame] | 3429 | ixgbe_napi_add_all(adapter); |
| 3430 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3431 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3432 | if (err) |
| 3433 | goto err_req_irq; |
| 3434 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3435 | err = ixgbe_up_complete(adapter); |
| 3436 | if (err) |
| 3437 | goto err_up; |
| 3438 | |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 3439 | netif_tx_start_all_queues(netdev); |
| 3440 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3441 | return 0; |
| 3442 | |
| 3443 | err_up: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 3444 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3445 | ixgbe_free_irq(adapter); |
| 3446 | err_req_irq: |
| 3447 | ixgbe_free_all_rx_resources(adapter); |
| 3448 | err_setup_rx: |
| 3449 | ixgbe_free_all_tx_resources(adapter); |
| 3450 | err_setup_tx: |
| 3451 | ixgbe_reset(adapter); |
| 3452 | |
| 3453 | return err; |
| 3454 | } |
| 3455 | |
| 3456 | /** |
| 3457 | * ixgbe_close - Disables a network interface |
| 3458 | * @netdev: network interface device structure |
| 3459 | * |
| 3460 | * Returns 0, this is not allowed to fail |
| 3461 | * |
| 3462 | * The close entry point is called when an interface is de-activated |
| 3463 | * by the OS. The hardware is still under the drivers control, but |
| 3464 | * needs to be disabled. A global MAC reset is issued to stop the |
| 3465 | * hardware, and all transmit and receive resources are freed. |
| 3466 | **/ |
| 3467 | static int ixgbe_close(struct net_device *netdev) |
| 3468 | { |
| 3469 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3470 | |
| 3471 | ixgbe_down(adapter); |
| 3472 | ixgbe_free_irq(adapter); |
| 3473 | |
| 3474 | ixgbe_free_all_tx_resources(adapter); |
| 3475 | ixgbe_free_all_rx_resources(adapter); |
| 3476 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 3477 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3478 | |
| 3479 | return 0; |
| 3480 | } |
| 3481 | |
| 3482 | /** |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 3483 | * ixgbe_napi_add_all - prep napi structs for use |
| 3484 | * @adapter: private struct |
Jesse Brandeburg | 4dd64df | 2009-03-13 22:13:49 +0000 | [diff] [blame] | 3485 | * |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 3486 | * helper function to napi_add each possible q_vector->napi |
| 3487 | */ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3488 | void ixgbe_napi_add_all(struct ixgbe_adapter *adapter) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 3489 | { |
| 3490 | int q_idx, q_vectors; |
Peter P Waskiewicz Jr | 7adf152 | 2008-12-26 01:36:05 -0800 | [diff] [blame] | 3491 | struct net_device *netdev = adapter->netdev; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 3492 | int (*poll)(struct napi_struct *, int); |
| 3493 | |
Peter P Waskiewicz Jr | 7adf152 | 2008-12-26 01:36:05 -0800 | [diff] [blame] | 3494 | /* check if we already have our netdev->napi_list populated */ |
| 3495 | if (&netdev->napi_list != netdev->napi_list.next) |
| 3496 | return; |
| 3497 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 3498 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 3499 | poll = &ixgbe_clean_rxonly; |
| 3500 | /* Only enable as many vectors as we have rx queues. */ |
| 3501 | q_vectors = adapter->num_rx_queues; |
| 3502 | } else { |
| 3503 | poll = &ixgbe_poll; |
| 3504 | /* only one q_vector for legacy modes */ |
| 3505 | q_vectors = 1; |
| 3506 | } |
| 3507 | |
| 3508 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
| 3509 | struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx]; |
| 3510 | netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64); |
| 3511 | } |
| 3512 | } |
| 3513 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3514 | void ixgbe_napi_del_all(struct ixgbe_adapter *adapter) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 3515 | { |
| 3516 | int q_idx; |
| 3517 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3518 | |
| 3519 | /* legacy and MSI only use one vector */ |
| 3520 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 3521 | q_vectors = 1; |
| 3522 | |
| 3523 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
| 3524 | struct ixgbe_q_vector *q_vector = &adapter->q_vector[q_idx]; |
| 3525 | if (!q_vector->rxr_count) |
| 3526 | continue; |
| 3527 | netif_napi_del(&q_vector->napi); |
| 3528 | } |
| 3529 | } |
| 3530 | |
| 3531 | #ifdef CONFIG_PM |
| 3532 | static int ixgbe_resume(struct pci_dev *pdev) |
| 3533 | { |
| 3534 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 3535 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3536 | u32 err; |
| 3537 | |
| 3538 | pci_set_power_state(pdev, PCI_D0); |
| 3539 | pci_restore_state(pdev); |
| 3540 | err = pci_enable_device(pdev); |
| 3541 | if (err) { |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 3542 | printk(KERN_ERR "ixgbe: Cannot enable PCI device from " |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 3543 | "suspend\n"); |
| 3544 | return err; |
| 3545 | } |
| 3546 | pci_set_master(pdev); |
| 3547 | |
| 3548 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 3549 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 3550 | |
| 3551 | err = ixgbe_init_interrupt_scheme(adapter); |
| 3552 | if (err) { |
| 3553 | printk(KERN_ERR "ixgbe: Cannot initialize interrupts for " |
| 3554 | "device\n"); |
| 3555 | return err; |
| 3556 | } |
| 3557 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 3558 | ixgbe_reset(adapter); |
| 3559 | |
| 3560 | if (netif_running(netdev)) { |
| 3561 | err = ixgbe_open(adapter->netdev); |
| 3562 | if (err) |
| 3563 | return err; |
| 3564 | } |
| 3565 | |
| 3566 | netif_device_attach(netdev); |
| 3567 | |
| 3568 | return 0; |
| 3569 | } |
| 3570 | |
| 3571 | #endif /* CONFIG_PM */ |
| 3572 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 3573 | { |
| 3574 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 3575 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3576 | struct ixgbe_hw *hw = &adapter->hw; |
| 3577 | u32 ctrl, fctrl; |
| 3578 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 3579 | #ifdef CONFIG_PM |
| 3580 | int retval = 0; |
| 3581 | #endif |
| 3582 | |
| 3583 | netif_device_detach(netdev); |
| 3584 | |
| 3585 | if (netif_running(netdev)) { |
| 3586 | ixgbe_down(adapter); |
| 3587 | ixgbe_free_irq(adapter); |
| 3588 | ixgbe_free_all_tx_resources(adapter); |
| 3589 | ixgbe_free_all_rx_resources(adapter); |
| 3590 | } |
| 3591 | ixgbe_reset_interrupt_capability(adapter); |
| 3592 | ixgbe_napi_del_all(adapter); |
Peter P Waskiewicz Jr | 7adf152 | 2008-12-26 01:36:05 -0800 | [diff] [blame] | 3593 | INIT_LIST_HEAD(&netdev->napi_list); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 3594 | kfree(adapter->tx_ring); |
| 3595 | kfree(adapter->rx_ring); |
| 3596 | |
| 3597 | #ifdef CONFIG_PM |
| 3598 | retval = pci_save_state(pdev); |
| 3599 | if (retval) |
| 3600 | return retval; |
| 3601 | #endif |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3602 | if (wufc) { |
| 3603 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 3604 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3605 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 3606 | if (wufc & IXGBE_WUFC_MC) { |
| 3607 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 3608 | fctrl |= IXGBE_FCTRL_MPE; |
| 3609 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 3610 | } |
| 3611 | |
| 3612 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 3613 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 3614 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 3615 | |
| 3616 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 3617 | } else { |
| 3618 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 3619 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 3620 | } |
| 3621 | |
| 3622 | if (wufc && hw->mac.type == ixgbe_mac_82599EB) { |
| 3623 | pci_enable_wake(pdev, PCI_D3hot, 1); |
| 3624 | pci_enable_wake(pdev, PCI_D3cold, 1); |
| 3625 | } else { |
| 3626 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 3627 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 3628 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 3629 | |
| 3630 | ixgbe_release_hw_control(adapter); |
| 3631 | |
| 3632 | pci_disable_device(pdev); |
| 3633 | |
| 3634 | pci_set_power_state(pdev, pci_choose_state(pdev, state)); |
| 3635 | |
| 3636 | return 0; |
| 3637 | } |
| 3638 | |
| 3639 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 3640 | { |
| 3641 | ixgbe_suspend(pdev, PMSG_SUSPEND); |
| 3642 | } |
| 3643 | |
| 3644 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3645 | * ixgbe_update_stats - Update the board statistics counters. |
| 3646 | * @adapter: board private structure |
| 3647 | **/ |
| 3648 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 3649 | { |
| 3650 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 3651 | u64 total_mpc = 0; |
| 3652 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3653 | |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 3654 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 3655 | for (i = 0; i < 16; i++) |
| 3656 | adapter->hw_rx_no_dma_resources += |
| 3657 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
| 3658 | } |
| 3659 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3660 | adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 3661 | for (i = 0; i < 8; i++) { |
| 3662 | /* for packet buffers not used, the register should read 0 */ |
| 3663 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 3664 | missed_rx += mpc; |
| 3665 | adapter->stats.mpc[i] += mpc; |
| 3666 | total_mpc += adapter->stats.mpc[i]; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3667 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3668 | adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3669 | adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 3670 | adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 3671 | adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 3672 | adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3673 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 3674 | adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw, |
| 3675 | IXGBE_PXONRXCNT(i)); |
| 3676 | adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw, |
| 3677 | IXGBE_PXOFFRXCNT(i)); |
| 3678 | adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3679 | } else { |
| 3680 | adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw, |
| 3681 | IXGBE_PXONRXC(i)); |
| 3682 | adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw, |
| 3683 | IXGBE_PXOFFRXC(i)); |
| 3684 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3685 | adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw, |
| 3686 | IXGBE_PXONTXC(i)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3687 | adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3688 | IXGBE_PXOFFTXC(i)); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 3689 | } |
| 3690 | adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
| 3691 | /* work around hardware counting issue */ |
| 3692 | adapter->stats.gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3693 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 3694 | /* 82598 hardware only has a 32 bit counter in the high register */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3695 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 3696 | adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
| 3697 | IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */ |
| 3698 | adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
| 3699 | IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */ |
| 3700 | adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
| 3701 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
| 3702 | adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
| 3703 | adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
| 3704 | } else { |
| 3705 | adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
| 3706 | adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 3707 | adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 3708 | adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 3709 | adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 3710 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3711 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
| 3712 | adapter->stats.bprc += bprc; |
| 3713 | adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3714 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 3715 | adapter->stats.mprc -= bprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3716 | adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 3717 | adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 3718 | adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 3719 | adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 3720 | adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 3721 | adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 3722 | adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3723 | adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 3724 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
| 3725 | adapter->stats.lxontxc += lxon; |
| 3726 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
| 3727 | adapter->stats.lxofftxc += lxoff; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3728 | adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 3729 | adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 3730 | adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
| 3731 | /* |
| 3732 | * 82598 errata - tx of flow control packets is included in tx counters |
| 3733 | */ |
| 3734 | xon_off_tot = lxon + lxoff; |
| 3735 | adapter->stats.gptc -= xon_off_tot; |
| 3736 | adapter->stats.mptc -= xon_off_tot; |
| 3737 | adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3738 | adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 3739 | adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 3740 | adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3741 | adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 3742 | adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 3743 | adapter->stats.ptc64 -= xon_off_tot; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3744 | adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 3745 | adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 3746 | adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 3747 | adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 3748 | adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3749 | adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
| 3750 | |
| 3751 | /* Fill out the OS statistics structure */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3752 | adapter->net_stats.multicast = adapter->stats.mprc; |
| 3753 | |
| 3754 | /* Rx Errors */ |
| 3755 | adapter->net_stats.rx_errors = adapter->stats.crcerrs + |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3756 | adapter->stats.rlec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3757 | adapter->net_stats.rx_dropped = 0; |
| 3758 | adapter->net_stats.rx_length_errors = adapter->stats.rlec; |
| 3759 | adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 3760 | adapter->net_stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3761 | } |
| 3762 | |
| 3763 | /** |
| 3764 | * ixgbe_watchdog - Timer Call-back |
| 3765 | * @data: pointer to adapter cast into an unsigned long |
| 3766 | **/ |
| 3767 | static void ixgbe_watchdog(unsigned long data) |
| 3768 | { |
| 3769 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3770 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3771 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3772 | /* Do the watchdog outside of interrupt context due to the lovely |
| 3773 | * delays that some of the newer hardware requires */ |
| 3774 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 3775 | /* Cause software interrupt to ensure rx rings are cleaned */ |
| 3776 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 3777 | u32 eics = |
| 3778 | (1 << (adapter->num_msix_vectors - NON_Q_VECTORS)) - 1; |
| 3779 | IXGBE_WRITE_REG(hw, IXGBE_EICS, eics); |
| 3780 | } else { |
| 3781 | /* For legacy and MSI interrupts don't set any bits that |
| 3782 | * are enabled for EIAM, because this operation would |
| 3783 | * set *both* EIMS and EICS for any bit in EIAM */ |
| 3784 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 3785 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
| 3786 | } |
| 3787 | /* Reset the timer */ |
| 3788 | mod_timer(&adapter->watchdog_timer, |
| 3789 | round_jiffies(jiffies + 2 * HZ)); |
| 3790 | } |
| 3791 | |
| 3792 | schedule_work(&adapter->watchdog_task); |
| 3793 | } |
| 3794 | |
| 3795 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3796 | * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber |
| 3797 | * @work: pointer to work_struct containing our data |
| 3798 | **/ |
| 3799 | static void ixgbe_multispeed_fiber_task(struct work_struct *work) |
| 3800 | { |
| 3801 | struct ixgbe_adapter *adapter = container_of(work, |
| 3802 | struct ixgbe_adapter, |
| 3803 | multispeed_fiber_task); |
| 3804 | struct ixgbe_hw *hw = &adapter->hw; |
| 3805 | u32 autoneg; |
| 3806 | |
| 3807 | adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK; |
| 3808 | if (hw->mac.ops.get_link_capabilities) |
| 3809 | hw->mac.ops.get_link_capabilities(hw, &autoneg, |
| 3810 | &hw->mac.autoneg); |
| 3811 | if (hw->mac.ops.setup_link_speed) |
| 3812 | hw->mac.ops.setup_link_speed(hw, autoneg, true, true); |
| 3813 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 3814 | adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK; |
| 3815 | } |
| 3816 | |
| 3817 | /** |
| 3818 | * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module |
| 3819 | * @work: pointer to work_struct containing our data |
| 3820 | **/ |
| 3821 | static void ixgbe_sfp_config_module_task(struct work_struct *work) |
| 3822 | { |
| 3823 | struct ixgbe_adapter *adapter = container_of(work, |
| 3824 | struct ixgbe_adapter, |
| 3825 | sfp_config_module_task); |
| 3826 | struct ixgbe_hw *hw = &adapter->hw; |
| 3827 | u32 err; |
| 3828 | |
| 3829 | adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK; |
| 3830 | err = hw->phy.ops.identify_sfp(hw); |
| 3831 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
| 3832 | DPRINTK(PROBE, ERR, "PHY not supported on this NIC %d\n", err); |
| 3833 | ixgbe_down(adapter); |
| 3834 | return; |
| 3835 | } |
| 3836 | hw->mac.ops.setup_sfp(hw); |
| 3837 | |
| 3838 | if (!adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK) |
| 3839 | /* This will also work for DA Twinax connections */ |
| 3840 | schedule_work(&adapter->multispeed_fiber_task); |
| 3841 | adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK; |
| 3842 | } |
| 3843 | |
| 3844 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 3845 | * ixgbe_watchdog_task - worker thread to bring link up |
| 3846 | * @work: pointer to work_struct containing our data |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3847 | **/ |
| 3848 | static void ixgbe_watchdog_task(struct work_struct *work) |
| 3849 | { |
| 3850 | struct ixgbe_adapter *adapter = container_of(work, |
| 3851 | struct ixgbe_adapter, |
| 3852 | watchdog_task); |
| 3853 | struct net_device *netdev = adapter->netdev; |
| 3854 | struct ixgbe_hw *hw = &adapter->hw; |
| 3855 | u32 link_speed = adapter->link_speed; |
| 3856 | bool link_up = adapter->link_up; |
| 3857 | |
| 3858 | adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK; |
| 3859 | |
| 3860 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) { |
| 3861 | hw->mac.ops.check_link(hw, &link_speed, &link_up, false); |
| 3862 | if (link_up || |
| 3863 | time_after(jiffies, (adapter->link_check_timeout + |
| 3864 | IXGBE_TRY_LINK_TIMEOUT))) { |
| 3865 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
| 3866 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
| 3867 | } |
| 3868 | adapter->link_up = link_up; |
| 3869 | adapter->link_speed = link_speed; |
| 3870 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3871 | |
| 3872 | if (link_up) { |
| 3873 | if (!netif_carrier_ok(netdev)) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3874 | bool flow_rx, flow_tx; |
| 3875 | |
| 3876 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 3877 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 3878 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
| 3879 | flow_rx = (mflcn & IXGBE_MFLCN_RFCE); |
| 3880 | flow_tx = (fccfg & IXGBE_FCCFG_TFCE_802_3X); |
| 3881 | } else { |
| 3882 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 3883 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
| 3884 | flow_rx = (frctl & IXGBE_FCTRL_RFCE); |
| 3885 | flow_tx = (rmcs & IXGBE_RMCS_TFCE_802_3X); |
| 3886 | } |
| 3887 | |
Jeff Kirsher | a46e534 | 2008-11-27 00:22:21 -0800 | [diff] [blame] | 3888 | printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, " |
| 3889 | "Flow Control: %s\n", |
| 3890 | netdev->name, |
| 3891 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? |
| 3892 | "10 Gbps" : |
| 3893 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? |
| 3894 | "1 Gbps" : "unknown speed")), |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3895 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 3896 | (flow_rx ? "RX" : |
| 3897 | (flow_tx ? "TX" : "None")))); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3898 | |
| 3899 | netif_carrier_on(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3900 | } else { |
| 3901 | /* Force detection of hung controller */ |
| 3902 | adapter->detect_tx_hung = true; |
| 3903 | } |
| 3904 | } else { |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3905 | adapter->link_up = false; |
| 3906 | adapter->link_speed = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3907 | if (netif_carrier_ok(netdev)) { |
Jeff Kirsher | a46e534 | 2008-11-27 00:22:21 -0800 | [diff] [blame] | 3908 | printk(KERN_INFO "ixgbe: %s NIC Link is Down\n", |
| 3909 | netdev->name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3910 | netif_carrier_off(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3911 | } |
| 3912 | } |
| 3913 | |
| 3914 | ixgbe_update_stats(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 3915 | adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3916 | } |
| 3917 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3918 | static int ixgbe_tso(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3919 | struct ixgbe_ring *tx_ring, struct sk_buff *skb, |
| 3920 | u32 tx_flags, u8 *hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3921 | { |
| 3922 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 3923 | unsigned int i; |
| 3924 | int err; |
| 3925 | struct ixgbe_tx_buffer *tx_buffer_info; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 3926 | u32 vlan_macip_lens = 0, type_tucmd_mlhl; |
| 3927 | u32 mss_l4len_idx, l4len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3928 | |
| 3929 | if (skb_is_gso(skb)) { |
| 3930 | if (skb_header_cloned(skb)) { |
| 3931 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 3932 | if (err) |
| 3933 | return err; |
| 3934 | } |
| 3935 | l4len = tcp_hdrlen(skb); |
| 3936 | *hdr_len += l4len; |
| 3937 | |
Al Viro | 8327d00 | 2007-12-10 18:54:12 +0000 | [diff] [blame] | 3938 | if (skb->protocol == htons(ETH_P_IP)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3939 | struct iphdr *iph = ip_hdr(skb); |
| 3940 | iph->tot_len = 0; |
| 3941 | iph->check = 0; |
| 3942 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3943 | iph->daddr, 0, |
| 3944 | IPPROTO_TCP, |
| 3945 | 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3946 | adapter->hw_tso_ctxt++; |
| 3947 | } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) { |
| 3948 | ipv6_hdr(skb)->payload_len = 0; |
| 3949 | tcp_hdr(skb)->check = |
| 3950 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3951 | &ipv6_hdr(skb)->daddr, |
| 3952 | 0, IPPROTO_TCP, 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3953 | adapter->hw_tso6_ctxt++; |
| 3954 | } |
| 3955 | |
| 3956 | i = tx_ring->next_to_use; |
| 3957 | |
| 3958 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 3959 | context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i); |
| 3960 | |
| 3961 | /* VLAN MACLEN IPLEN */ |
| 3962 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 3963 | vlan_macip_lens |= |
| 3964 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); |
| 3965 | vlan_macip_lens |= ((skb_network_offset(skb)) << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3966 | IXGBE_ADVTXD_MACLEN_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3967 | *hdr_len += skb_network_offset(skb); |
| 3968 | vlan_macip_lens |= |
| 3969 | (skb_transport_header(skb) - skb_network_header(skb)); |
| 3970 | *hdr_len += |
| 3971 | (skb_transport_header(skb) - skb_network_header(skb)); |
| 3972 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 3973 | context_desc->seqnum_seed = 0; |
| 3974 | |
| 3975 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 3976 | type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3977 | IXGBE_ADVTXD_DTYP_CTXT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3978 | |
Al Viro | 8327d00 | 2007-12-10 18:54:12 +0000 | [diff] [blame] | 3979 | if (skb->protocol == htons(ETH_P_IP)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3980 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 3981 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 3982 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); |
| 3983 | |
| 3984 | /* MSS L4LEN IDX */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 3985 | mss_l4len_idx = |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3986 | (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT); |
| 3987 | mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT); |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 3988 | /* use index 1 for TSO */ |
| 3989 | mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3990 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 3991 | |
| 3992 | tx_buffer_info->time_stamp = jiffies; |
| 3993 | tx_buffer_info->next_to_watch = i; |
| 3994 | |
| 3995 | i++; |
| 3996 | if (i == tx_ring->count) |
| 3997 | i = 0; |
| 3998 | tx_ring->next_to_use = i; |
| 3999 | |
| 4000 | return true; |
| 4001 | } |
| 4002 | return false; |
| 4003 | } |
| 4004 | |
| 4005 | static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4006 | struct ixgbe_ring *tx_ring, |
| 4007 | struct sk_buff *skb, u32 tx_flags) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4008 | { |
| 4009 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 4010 | unsigned int i; |
| 4011 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 4012 | u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0; |
| 4013 | |
| 4014 | if (skb->ip_summed == CHECKSUM_PARTIAL || |
| 4015 | (tx_flags & IXGBE_TX_FLAGS_VLAN)) { |
| 4016 | i = tx_ring->next_to_use; |
| 4017 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4018 | context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i); |
| 4019 | |
| 4020 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 4021 | vlan_macip_lens |= |
| 4022 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); |
| 4023 | vlan_macip_lens |= (skb_network_offset(skb) << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4024 | IXGBE_ADVTXD_MACLEN_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4025 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 4026 | vlan_macip_lens |= (skb_transport_header(skb) - |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4027 | skb_network_header(skb)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4028 | |
| 4029 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 4030 | context_desc->seqnum_seed = 0; |
| 4031 | |
| 4032 | type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4033 | IXGBE_ADVTXD_DTYP_CTXT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4034 | |
| 4035 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4036 | switch (skb->protocol) { |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 4037 | case cpu_to_be16(ETH_P_IP): |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4038 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4039 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 4040 | type_tucmd_mlhl |= |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4041 | IXGBE_ADVTXD_TUCMD_L4T_TCP; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4042 | break; |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 4043 | case cpu_to_be16(ETH_P_IPV6): |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4044 | /* XXX what about other V6 headers?? */ |
| 4045 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 4046 | type_tucmd_mlhl |= |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4047 | IXGBE_ADVTXD_TUCMD_L4T_TCP; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4048 | break; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4049 | default: |
| 4050 | if (unlikely(net_ratelimit())) { |
| 4051 | DPRINTK(PROBE, WARNING, |
| 4052 | "partial checksum but proto=%x!\n", |
| 4053 | skb->protocol); |
| 4054 | } |
| 4055 | break; |
| 4056 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4057 | } |
| 4058 | |
| 4059 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 4060 | /* use index zero for tx checksum offload */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4061 | context_desc->mss_l4len_idx = 0; |
| 4062 | |
| 4063 | tx_buffer_info->time_stamp = jiffies; |
| 4064 | tx_buffer_info->next_to_watch = i; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4065 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4066 | adapter->hw_csum_tx_good++; |
| 4067 | i++; |
| 4068 | if (i == tx_ring->count) |
| 4069 | i = 0; |
| 4070 | tx_ring->next_to_use = i; |
| 4071 | |
| 4072 | return true; |
| 4073 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4074 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4075 | return false; |
| 4076 | } |
| 4077 | |
| 4078 | static int ixgbe_tx_map(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4079 | struct ixgbe_ring *tx_ring, |
| 4080 | struct sk_buff *skb, unsigned int first) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4081 | { |
| 4082 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 4083 | unsigned int len = skb->len; |
| 4084 | unsigned int offset = 0, size, count = 0, i; |
| 4085 | unsigned int nr_frags = skb_shinfo(skb)->nr_frags; |
| 4086 | unsigned int f; |
| 4087 | |
| 4088 | len -= skb->data_len; |
| 4089 | |
| 4090 | i = tx_ring->next_to_use; |
| 4091 | |
| 4092 | while (len) { |
| 4093 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4094 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 4095 | |
| 4096 | tx_buffer_info->length = size; |
| 4097 | tx_buffer_info->dma = pci_map_single(adapter->pdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4098 | skb->data + offset, |
| 4099 | size, PCI_DMA_TODEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4100 | tx_buffer_info->time_stamp = jiffies; |
| 4101 | tx_buffer_info->next_to_watch = i; |
| 4102 | |
| 4103 | len -= size; |
| 4104 | offset += size; |
| 4105 | count++; |
| 4106 | i++; |
| 4107 | if (i == tx_ring->count) |
| 4108 | i = 0; |
| 4109 | } |
| 4110 | |
| 4111 | for (f = 0; f < nr_frags; f++) { |
| 4112 | struct skb_frag_struct *frag; |
| 4113 | |
| 4114 | frag = &skb_shinfo(skb)->frags[f]; |
| 4115 | len = frag->size; |
| 4116 | offset = frag->page_offset; |
| 4117 | |
| 4118 | while (len) { |
| 4119 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4120 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 4121 | |
| 4122 | tx_buffer_info->length = size; |
| 4123 | tx_buffer_info->dma = pci_map_page(adapter->pdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4124 | frag->page, |
| 4125 | offset, |
| 4126 | size, |
| 4127 | PCI_DMA_TODEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4128 | tx_buffer_info->time_stamp = jiffies; |
| 4129 | tx_buffer_info->next_to_watch = i; |
| 4130 | |
| 4131 | len -= size; |
| 4132 | offset += size; |
| 4133 | count++; |
| 4134 | i++; |
| 4135 | if (i == tx_ring->count) |
| 4136 | i = 0; |
| 4137 | } |
| 4138 | } |
| 4139 | if (i == 0) |
| 4140 | i = tx_ring->count - 1; |
| 4141 | else |
| 4142 | i = i - 1; |
| 4143 | tx_ring->tx_buffer_info[i].skb = skb; |
| 4144 | tx_ring->tx_buffer_info[first].next_to_watch = i; |
| 4145 | |
| 4146 | return count; |
| 4147 | } |
| 4148 | |
| 4149 | static void ixgbe_tx_queue(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4150 | struct ixgbe_ring *tx_ring, |
| 4151 | int tx_flags, int count, u32 paylen, u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4152 | { |
| 4153 | union ixgbe_adv_tx_desc *tx_desc = NULL; |
| 4154 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 4155 | u32 olinfo_status = 0, cmd_type_len = 0; |
| 4156 | unsigned int i; |
| 4157 | u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS; |
| 4158 | |
| 4159 | cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA; |
| 4160 | |
| 4161 | cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT; |
| 4162 | |
| 4163 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 4164 | cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE; |
| 4165 | |
| 4166 | if (tx_flags & IXGBE_TX_FLAGS_TSO) { |
| 4167 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 4168 | |
| 4169 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4170 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4171 | |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 4172 | /* use index 1 context for tso */ |
| 4173 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4174 | if (tx_flags & IXGBE_TX_FLAGS_IPV4) |
| 4175 | olinfo_status |= IXGBE_TXD_POPTS_IXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4176 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4177 | |
| 4178 | } else if (tx_flags & IXGBE_TX_FLAGS_CSUM) |
| 4179 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4180 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4181 | |
| 4182 | olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT); |
| 4183 | |
| 4184 | i = tx_ring->next_to_use; |
| 4185 | while (count--) { |
| 4186 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4187 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); |
| 4188 | tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma); |
| 4189 | tx_desc->read.cmd_type_len = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4190 | cpu_to_le32(cmd_type_len | tx_buffer_info->length); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4191 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4192 | i++; |
| 4193 | if (i == tx_ring->count) |
| 4194 | i = 0; |
| 4195 | } |
| 4196 | |
| 4197 | tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd); |
| 4198 | |
| 4199 | /* |
| 4200 | * Force memory writes to complete before letting h/w |
| 4201 | * know there are new descriptors to fetch. (Only |
| 4202 | * applicable for weak-ordered memory model archs, |
| 4203 | * such as IA-64). |
| 4204 | */ |
| 4205 | wmb(); |
| 4206 | |
| 4207 | tx_ring->next_to_use = i; |
| 4208 | writel(i, adapter->hw.hw_addr + tx_ring->tail); |
| 4209 | } |
| 4210 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 4211 | static int __ixgbe_maybe_stop_tx(struct net_device *netdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4212 | struct ixgbe_ring *tx_ring, int size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 4213 | { |
| 4214 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4215 | |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 4216 | netif_stop_subqueue(netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 4217 | /* Herbert's original patch had: |
| 4218 | * smp_mb__after_netif_stop_queue(); |
| 4219 | * but since that doesn't exist yet, just open code it. */ |
| 4220 | smp_mb(); |
| 4221 | |
| 4222 | /* We need to check again in a case another CPU has just |
| 4223 | * made room available. */ |
| 4224 | if (likely(IXGBE_DESC_UNUSED(tx_ring) < size)) |
| 4225 | return -EBUSY; |
| 4226 | |
| 4227 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
Jesse Brandeburg | af72166 | 2008-09-11 19:54:23 -0700 | [diff] [blame] | 4228 | netif_start_subqueue(netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 4229 | ++adapter->restart_queue; |
| 4230 | return 0; |
| 4231 | } |
| 4232 | |
| 4233 | static int ixgbe_maybe_stop_tx(struct net_device *netdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4234 | struct ixgbe_ring *tx_ring, int size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 4235 | { |
| 4236 | if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size)) |
| 4237 | return 0; |
| 4238 | return __ixgbe_maybe_stop_tx(netdev, tx_ring, size); |
| 4239 | } |
| 4240 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4241 | static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 4242 | { |
| 4243 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4244 | struct ixgbe_ring *tx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4245 | unsigned int first; |
| 4246 | unsigned int tx_flags = 0; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 4247 | u8 hdr_len = 0; |
| 4248 | int r_idx = 0, tso; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4249 | int count = 0; |
| 4250 | unsigned int f; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4251 | |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 4252 | r_idx = (adapter->num_tx_queues - 1) & skb->queue_mapping; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 4253 | tx_ring = &adapter->tx_ring[r_idx]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4254 | |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4255 | if (adapter->vlgrp && vlan_tx_tag_present(skb)) { |
| 4256 | tx_flags |= vlan_tx_tag_get(skb); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4257 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 4258 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
| 4259 | tx_flags |= (skb->queue_mapping << 13); |
| 4260 | } |
| 4261 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 4262 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
| 4263 | } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 4264 | tx_flags |= (skb->queue_mapping << 13); |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4265 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 4266 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4267 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4268 | /* three things can cause us to need a context descriptor */ |
| 4269 | if (skb_is_gso(skb) || |
| 4270 | (skb->ip_summed == CHECKSUM_PARTIAL) || |
| 4271 | (tx_flags & IXGBE_TX_FLAGS_VLAN)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4272 | count++; |
| 4273 | |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4274 | count += TXD_USE_COUNT(skb_headlen(skb)); |
| 4275 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4276 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
| 4277 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 4278 | if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4279 | adapter->tx_busy++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4280 | return NETDEV_TX_BUSY; |
| 4281 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4282 | |
Al Viro | 8327d00 | 2007-12-10 18:54:12 +0000 | [diff] [blame] | 4283 | if (skb->protocol == htons(ETH_P_IP)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4284 | tx_flags |= IXGBE_TX_FLAGS_IPV4; |
| 4285 | first = tx_ring->next_to_use; |
| 4286 | tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len); |
| 4287 | if (tso < 0) { |
| 4288 | dev_kfree_skb_any(skb); |
| 4289 | return NETDEV_TX_OK; |
| 4290 | } |
| 4291 | |
| 4292 | if (tso) |
| 4293 | tx_flags |= IXGBE_TX_FLAGS_TSO; |
| 4294 | else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) && |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4295 | (skb->ip_summed == CHECKSUM_PARTIAL)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4296 | tx_flags |= IXGBE_TX_FLAGS_CSUM; |
| 4297 | |
| 4298 | ixgbe_tx_queue(adapter, tx_ring, tx_flags, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4299 | ixgbe_tx_map(adapter, tx_ring, skb, first), |
| 4300 | skb->len, hdr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4301 | |
| 4302 | netdev->trans_start = jiffies; |
| 4303 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 4304 | ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4305 | |
| 4306 | return NETDEV_TX_OK; |
| 4307 | } |
| 4308 | |
| 4309 | /** |
| 4310 | * ixgbe_get_stats - Get System Network Statistics |
| 4311 | * @netdev: network interface device structure |
| 4312 | * |
| 4313 | * Returns the address of the device statistics structure. |
| 4314 | * The statistics are actually updated from the timer callback. |
| 4315 | **/ |
| 4316 | static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev) |
| 4317 | { |
| 4318 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4319 | |
| 4320 | /* only return the current stats */ |
| 4321 | return &adapter->net_stats; |
| 4322 | } |
| 4323 | |
| 4324 | /** |
| 4325 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
| 4326 | * @netdev: network interface device structure |
| 4327 | * @p: pointer to an address structure |
| 4328 | * |
| 4329 | * Returns 0 on success, negative on failure |
| 4330 | **/ |
| 4331 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 4332 | { |
| 4333 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4334 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4335 | struct sockaddr *addr = p; |
| 4336 | |
| 4337 | if (!is_valid_ether_addr(addr->sa_data)) |
| 4338 | return -EADDRNOTAVAIL; |
| 4339 | |
| 4340 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4341 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4342 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4343 | 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] | 4344 | |
| 4345 | return 0; |
| 4346 | } |
| 4347 | |
| 4348 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 4349 | /* |
| 4350 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 4351 | * without having to re-enable interrupts. It's not called while |
| 4352 | * the interrupt routine is executing. |
| 4353 | */ |
| 4354 | static void ixgbe_netpoll(struct net_device *netdev) |
| 4355 | { |
| 4356 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4357 | |
| 4358 | disable_irq(adapter->pdev->irq); |
| 4359 | adapter->flags |= IXGBE_FLAG_IN_NETPOLL; |
| 4360 | ixgbe_intr(adapter->pdev->irq, netdev); |
| 4361 | adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL; |
| 4362 | enable_irq(adapter->pdev->irq); |
| 4363 | } |
| 4364 | #endif |
| 4365 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 4366 | static const struct net_device_ops ixgbe_netdev_ops = { |
| 4367 | .ndo_open = ixgbe_open, |
| 4368 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 4369 | .ndo_start_xmit = ixgbe_xmit_frame, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 4370 | .ndo_get_stats = ixgbe_get_stats, |
| 4371 | .ndo_set_multicast_list = ixgbe_set_rx_mode, |
| 4372 | .ndo_validate_addr = eth_validate_addr, |
| 4373 | .ndo_set_mac_address = ixgbe_set_mac, |
| 4374 | .ndo_change_mtu = ixgbe_change_mtu, |
| 4375 | .ndo_tx_timeout = ixgbe_tx_timeout, |
| 4376 | .ndo_vlan_rx_register = ixgbe_vlan_rx_register, |
| 4377 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 4378 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
| 4379 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 4380 | .ndo_poll_controller = ixgbe_netpoll, |
| 4381 | #endif |
| 4382 | }; |
| 4383 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4384 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4385 | * ixgbe_probe - Device Initialization Routine |
| 4386 | * @pdev: PCI device information struct |
| 4387 | * @ent: entry in ixgbe_pci_tbl |
| 4388 | * |
| 4389 | * Returns 0 on success, negative on failure |
| 4390 | * |
| 4391 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 4392 | * The OS initialization, configuring of the adapter private structure, |
| 4393 | * and a hardware reset occur. |
| 4394 | **/ |
| 4395 | static int __devinit ixgbe_probe(struct pci_dev *pdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4396 | const struct pci_device_id *ent) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4397 | { |
| 4398 | struct net_device *netdev; |
| 4399 | struct ixgbe_adapter *adapter = NULL; |
| 4400 | struct ixgbe_hw *hw; |
| 4401 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4402 | static int cards_found; |
| 4403 | int i, err, pci_using_dac; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4404 | u16 pm_value = 0; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4405 | u32 part_num, eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4406 | |
| 4407 | err = pci_enable_device(pdev); |
| 4408 | if (err) |
| 4409 | return err; |
| 4410 | |
| 4411 | if (!pci_set_dma_mask(pdev, DMA_64BIT_MASK) && |
| 4412 | !pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK)) { |
| 4413 | pci_using_dac = 1; |
| 4414 | } else { |
| 4415 | err = pci_set_dma_mask(pdev, DMA_32BIT_MASK); |
| 4416 | if (err) { |
| 4417 | err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK); |
| 4418 | if (err) { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4419 | dev_err(&pdev->dev, "No usable DMA " |
| 4420 | "configuration, aborting\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4421 | goto err_dma; |
| 4422 | } |
| 4423 | } |
| 4424 | pci_using_dac = 0; |
| 4425 | } |
| 4426 | |
| 4427 | err = pci_request_regions(pdev, ixgbe_driver_name); |
| 4428 | if (err) { |
| 4429 | dev_err(&pdev->dev, "pci_request_regions failed 0x%x\n", err); |
| 4430 | goto err_pci_reg; |
| 4431 | } |
| 4432 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 4433 | err = pci_enable_pcie_error_reporting(pdev); |
| 4434 | if (err) { |
| 4435 | dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed " |
| 4436 | "0x%x\n", err); |
| 4437 | /* non-fatal, continue */ |
| 4438 | } |
| 4439 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4440 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 4441 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4442 | |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 4443 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4444 | if (!netdev) { |
| 4445 | err = -ENOMEM; |
| 4446 | goto err_alloc_etherdev; |
| 4447 | } |
| 4448 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4449 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 4450 | |
| 4451 | pci_set_drvdata(pdev, netdev); |
| 4452 | adapter = netdev_priv(netdev); |
| 4453 | |
| 4454 | adapter->netdev = netdev; |
| 4455 | adapter->pdev = pdev; |
| 4456 | hw = &adapter->hw; |
| 4457 | hw->back = adapter; |
| 4458 | adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
| 4459 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 4460 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
| 4461 | pci_resource_len(pdev, 0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4462 | if (!hw->hw_addr) { |
| 4463 | err = -EIO; |
| 4464 | goto err_ioremap; |
| 4465 | } |
| 4466 | |
| 4467 | for (i = 1; i <= 5; i++) { |
| 4468 | if (pci_resource_len(pdev, i) == 0) |
| 4469 | continue; |
| 4470 | } |
| 4471 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 4472 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4473 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4474 | netdev->watchdog_timeo = 5 * HZ; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4475 | strcpy(netdev->name, pci_name(pdev)); |
| 4476 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4477 | adapter->bd_number = cards_found; |
| 4478 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4479 | /* Setup hw api */ |
| 4480 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4481 | hw->mac.type = ii->mac; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4482 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4483 | /* EEPROM */ |
| 4484 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); |
| 4485 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 4486 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
| 4487 | if (!(eec & (1 << 8))) |
| 4488 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 4489 | |
| 4490 | /* PHY */ |
| 4491 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 4492 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
| 4493 | |
| 4494 | /* set up this timer and work struct before calling get_invariants |
| 4495 | * which might start the timer |
| 4496 | */ |
| 4497 | init_timer(&adapter->sfp_timer); |
| 4498 | adapter->sfp_timer.function = &ixgbe_sfp_timer; |
| 4499 | adapter->sfp_timer.data = (unsigned long) adapter; |
| 4500 | |
| 4501 | INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4502 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4503 | /* multispeed fiber has its own tasklet, called from GPI SDP1 context */ |
| 4504 | INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task); |
| 4505 | |
| 4506 | /* a new SFP+ module arrival, called from GPI SDP2 context */ |
| 4507 | INIT_WORK(&adapter->sfp_config_module_task, |
| 4508 | ixgbe_sfp_config_module_task); |
| 4509 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4510 | err = ii->get_invariants(hw); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 4511 | if (err == IXGBE_ERR_SFP_NOT_PRESENT) { |
| 4512 | /* start a kernel thread to watch for a module to arrive */ |
| 4513 | set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 4514 | mod_timer(&adapter->sfp_timer, |
| 4515 | round_jiffies(jiffies + (2 * HZ))); |
| 4516 | err = 0; |
| 4517 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
| 4518 | DPRINTK(PROBE, ERR, "failed to load because an " |
| 4519 | "unsupported SFP+ module type was detected.\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4520 | goto err_hw_init; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 4521 | } else if (err) { |
| 4522 | goto err_hw_init; |
| 4523 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4524 | |
| 4525 | /* setup the private structure */ |
| 4526 | err = ixgbe_sw_init(adapter); |
| 4527 | if (err) |
| 4528 | goto err_sw_init; |
| 4529 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4530 | /* reset_hw fills in the perm_addr as well */ |
| 4531 | err = hw->mac.ops.reset_hw(hw); |
| 4532 | if (err) { |
| 4533 | dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err); |
| 4534 | goto err_sw_init; |
| 4535 | } |
| 4536 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4537 | netdev->features = NETIF_F_SG | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4538 | NETIF_F_IP_CSUM | |
| 4539 | NETIF_F_HW_VLAN_TX | |
| 4540 | NETIF_F_HW_VLAN_RX | |
| 4541 | NETIF_F_HW_VLAN_FILTER; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4542 | |
Jesse Brandeburg | e9990a9 | 2008-08-26 04:27:24 -0700 | [diff] [blame] | 4543 | netdev->features |= NETIF_F_IPV6_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4544 | netdev->features |= NETIF_F_TSO; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4545 | netdev->features |= NETIF_F_TSO6; |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 4546 | netdev->features |= NETIF_F_GRO; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 4547 | |
| 4548 | netdev->vlan_features |= NETIF_F_TSO; |
| 4549 | netdev->vlan_features |= NETIF_F_TSO6; |
Jesse Brandeburg | 22f32b7a5 | 2008-08-26 04:27:18 -0700 | [diff] [blame] | 4550 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 4551 | netdev->vlan_features |= NETIF_F_SG; |
| 4552 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4553 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 4554 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
| 4555 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 4556 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4557 | netdev->dcbnl_ops = &dcbnl_ops; |
| 4558 | #endif |
| 4559 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4560 | if (pci_using_dac) |
| 4561 | netdev->features |= NETIF_F_HIGHDMA; |
| 4562 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4563 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4564 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4565 | dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n"); |
| 4566 | err = -EIO; |
| 4567 | goto err_eeprom; |
| 4568 | } |
| 4569 | |
| 4570 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
| 4571 | memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len); |
| 4572 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4573 | if (ixgbe_validate_mac_addr(netdev->perm_addr)) { |
| 4574 | dev_err(&pdev->dev, "invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4575 | err = -EIO; |
| 4576 | goto err_eeprom; |
| 4577 | } |
| 4578 | |
| 4579 | init_timer(&adapter->watchdog_timer); |
| 4580 | adapter->watchdog_timer.function = &ixgbe_watchdog; |
| 4581 | adapter->watchdog_timer.data = (unsigned long)adapter; |
| 4582 | |
| 4583 | INIT_WORK(&adapter->reset_task, ixgbe_reset_task); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4584 | INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4585 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4586 | err = ixgbe_init_interrupt_scheme(adapter); |
| 4587 | if (err) |
| 4588 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4589 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4590 | switch (pdev->device) { |
| 4591 | case IXGBE_DEV_ID_82599_KX4: |
| 4592 | #define IXGBE_PCIE_PMCSR 0x44 |
| 4593 | adapter->wol = IXGBE_WUFC_MAG; |
| 4594 | pci_read_config_word(pdev, IXGBE_PCIE_PMCSR, &pm_value); |
| 4595 | pci_write_config_word(pdev, IXGBE_PCIE_PMCSR, |
| 4596 | (pm_value | (1 << 8))); |
| 4597 | break; |
| 4598 | default: |
| 4599 | adapter->wol = 0; |
| 4600 | break; |
| 4601 | } |
| 4602 | device_init_wakeup(&adapter->pdev->dev, true); |
| 4603 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 4604 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4605 | /* print bus type/speed/width info */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 4606 | dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n", |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4607 | ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s": |
| 4608 | (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"), |
| 4609 | ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" : |
| 4610 | (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" : |
| 4611 | (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" : |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4612 | "Unknown"), |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 4613 | netdev->dev_addr); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4614 | ixgbe_read_pba_num_generic(hw, &part_num); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4615 | if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present) |
| 4616 | dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n", |
| 4617 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
| 4618 | (part_num >> 8), (part_num & 0xff)); |
| 4619 | else |
| 4620 | dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n", |
| 4621 | hw->mac.type, hw->phy.type, |
| 4622 | (part_num >> 8), (part_num & 0xff)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4623 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4624 | if (hw->bus.width <= ixgbe_bus_width_pcie_x4) { |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 4625 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4626 | "this card is not sufficient for optimal " |
| 4627 | "performance.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 4628 | dev_warn(&pdev->dev, "For optimal performance a x8 " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4629 | "PCI-Express slot is required.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 4630 | } |
| 4631 | |
Peter P Waskiewicz Jr | 34b0368 | 2009-02-05 23:54:42 -0800 | [diff] [blame] | 4632 | /* save off EEPROM version number */ |
| 4633 | hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version); |
| 4634 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4635 | /* reset the hardware with the new settings */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 4636 | hw->mac.ops.start_hw(hw); |
| 4637 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4638 | netif_carrier_off(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4639 | |
| 4640 | strcpy(netdev->name, "eth%d"); |
| 4641 | err = register_netdev(netdev); |
| 4642 | if (err) |
| 4643 | goto err_register; |
| 4644 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4645 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 4646 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4647 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
| 4648 | /* always use CB2 mode, difference is masked |
| 4649 | * in the CB driver */ |
| 4650 | IXGBE_WRITE_REG(hw, IXGBE_DCA_CTRL, 2); |
| 4651 | ixgbe_setup_dca(adapter); |
| 4652 | } |
| 4653 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4654 | |
| 4655 | dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n"); |
| 4656 | cards_found++; |
| 4657 | return 0; |
| 4658 | |
| 4659 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 4660 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4661 | err_hw_init: |
| 4662 | err_sw_init: |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4663 | ixgbe_reset_interrupt_capability(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4664 | err_eeprom: |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 4665 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 4666 | del_timer_sync(&adapter->sfp_timer); |
| 4667 | cancel_work_sync(&adapter->sfp_task); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4668 | cancel_work_sync(&adapter->multispeed_fiber_task); |
| 4669 | cancel_work_sync(&adapter->sfp_config_module_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4670 | iounmap(hw->hw_addr); |
| 4671 | err_ioremap: |
| 4672 | free_netdev(netdev); |
| 4673 | err_alloc_etherdev: |
| 4674 | pci_release_regions(pdev); |
| 4675 | err_pci_reg: |
| 4676 | err_dma: |
| 4677 | pci_disable_device(pdev); |
| 4678 | return err; |
| 4679 | } |
| 4680 | |
| 4681 | /** |
| 4682 | * ixgbe_remove - Device Removal Routine |
| 4683 | * @pdev: PCI device information struct |
| 4684 | * |
| 4685 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 4686 | * that it should release a PCI device. The could be caused by a |
| 4687 | * Hot-Plug event, or because the driver is going to be removed from |
| 4688 | * memory. |
| 4689 | **/ |
| 4690 | static void __devexit ixgbe_remove(struct pci_dev *pdev) |
| 4691 | { |
| 4692 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4693 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 4694 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4695 | |
| 4696 | set_bit(__IXGBE_DOWN, &adapter->state); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 4697 | /* clear the module not found bit to make sure the worker won't |
| 4698 | * reschedule |
| 4699 | */ |
| 4700 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4701 | del_timer_sync(&adapter->watchdog_timer); |
| 4702 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 4703 | del_timer_sync(&adapter->sfp_timer); |
| 4704 | cancel_work_sync(&adapter->watchdog_task); |
| 4705 | cancel_work_sync(&adapter->sfp_task); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4706 | cancel_work_sync(&adapter->multispeed_fiber_task); |
| 4707 | cancel_work_sync(&adapter->sfp_config_module_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4708 | flush_scheduled_work(); |
| 4709 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4710 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4711 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 4712 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 4713 | dca_remove_requester(&pdev->dev); |
| 4714 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 4715 | } |
| 4716 | |
| 4717 | #endif |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 4718 | if (netdev->reg_state == NETREG_REGISTERED) |
| 4719 | unregister_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4720 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4721 | ixgbe_reset_interrupt_capability(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 4722 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4723 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4724 | |
| 4725 | iounmap(adapter->hw.hw_addr); |
| 4726 | pci_release_regions(pdev); |
| 4727 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4728 | DPRINTK(PROBE, INFO, "complete\n"); |
| 4729 | kfree(adapter->tx_ring); |
| 4730 | kfree(adapter->rx_ring); |
| 4731 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4732 | free_netdev(netdev); |
| 4733 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 4734 | err = pci_disable_pcie_error_reporting(pdev); |
| 4735 | if (err) |
| 4736 | dev_err(&pdev->dev, |
| 4737 | "pci_disable_pcie_error_reporting failed 0x%x\n", err); |
| 4738 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4739 | pci_disable_device(pdev); |
| 4740 | } |
| 4741 | |
| 4742 | /** |
| 4743 | * ixgbe_io_error_detected - called when PCI error is detected |
| 4744 | * @pdev: Pointer to PCI device |
| 4745 | * @state: The current pci connection state |
| 4746 | * |
| 4747 | * This function is called after a PCI bus error affecting |
| 4748 | * this device has been detected. |
| 4749 | */ |
| 4750 | 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] | 4751 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4752 | { |
| 4753 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 4754 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4755 | |
| 4756 | netif_device_detach(netdev); |
| 4757 | |
| 4758 | if (netif_running(netdev)) |
| 4759 | ixgbe_down(adapter); |
| 4760 | pci_disable_device(pdev); |
| 4761 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4762 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4763 | return PCI_ERS_RESULT_NEED_RESET; |
| 4764 | } |
| 4765 | |
| 4766 | /** |
| 4767 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 4768 | * @pdev: Pointer to PCI device |
| 4769 | * |
| 4770 | * Restart the card from scratch, as if from a cold-boot. |
| 4771 | */ |
| 4772 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 4773 | { |
| 4774 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 4775 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 4776 | pci_ers_result_t result; |
| 4777 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4778 | |
| 4779 | if (pci_enable_device(pdev)) { |
| 4780 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4781 | "Cannot re-enable PCI device after reset.\n"); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 4782 | result = PCI_ERS_RESULT_DISCONNECT; |
| 4783 | } else { |
| 4784 | pci_set_master(pdev); |
| 4785 | pci_restore_state(pdev); |
| 4786 | |
| 4787 | pci_enable_wake(pdev, PCI_D3hot, 0); |
| 4788 | pci_enable_wake(pdev, PCI_D3cold, 0); |
| 4789 | |
| 4790 | ixgbe_reset(adapter); |
| 4791 | |
| 4792 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4793 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4794 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 4795 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 4796 | if (err) { |
| 4797 | dev_err(&pdev->dev, |
| 4798 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err); |
| 4799 | /* non-fatal, continue */ |
| 4800 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4801 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 4802 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4803 | } |
| 4804 | |
| 4805 | /** |
| 4806 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 4807 | * @pdev: Pointer to PCI device |
| 4808 | * |
| 4809 | * This callback is called when the error recovery driver tells us that |
| 4810 | * its OK to resume normal operation. |
| 4811 | */ |
| 4812 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 4813 | { |
| 4814 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 4815 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4816 | |
| 4817 | if (netif_running(netdev)) { |
| 4818 | if (ixgbe_up(adapter)) { |
| 4819 | DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n"); |
| 4820 | return; |
| 4821 | } |
| 4822 | } |
| 4823 | |
| 4824 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4825 | } |
| 4826 | |
| 4827 | static struct pci_error_handlers ixgbe_err_handler = { |
| 4828 | .error_detected = ixgbe_io_error_detected, |
| 4829 | .slot_reset = ixgbe_io_slot_reset, |
| 4830 | .resume = ixgbe_io_resume, |
| 4831 | }; |
| 4832 | |
| 4833 | static struct pci_driver ixgbe_driver = { |
| 4834 | .name = ixgbe_driver_name, |
| 4835 | .id_table = ixgbe_pci_tbl, |
| 4836 | .probe = ixgbe_probe, |
| 4837 | .remove = __devexit_p(ixgbe_remove), |
| 4838 | #ifdef CONFIG_PM |
| 4839 | .suspend = ixgbe_suspend, |
| 4840 | .resume = ixgbe_resume, |
| 4841 | #endif |
| 4842 | .shutdown = ixgbe_shutdown, |
| 4843 | .err_handler = &ixgbe_err_handler |
| 4844 | }; |
| 4845 | |
| 4846 | /** |
| 4847 | * ixgbe_init_module - Driver Registration Routine |
| 4848 | * |
| 4849 | * ixgbe_init_module is the first routine called when the driver is |
| 4850 | * loaded. All it does is register with the PCI subsystem. |
| 4851 | **/ |
| 4852 | static int __init ixgbe_init_module(void) |
| 4853 | { |
| 4854 | int ret; |
| 4855 | printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name, |
| 4856 | ixgbe_driver_string, ixgbe_driver_version); |
| 4857 | |
| 4858 | printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright); |
| 4859 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4860 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4861 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4862 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4863 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4864 | ret = pci_register_driver(&ixgbe_driver); |
| 4865 | return ret; |
| 4866 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4867 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4868 | module_init(ixgbe_init_module); |
| 4869 | |
| 4870 | /** |
| 4871 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 4872 | * |
| 4873 | * ixgbe_exit_module is called just before the driver is removed |
| 4874 | * from memory. |
| 4875 | **/ |
| 4876 | static void __exit ixgbe_exit_module(void) |
| 4877 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4878 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4879 | dca_unregister_notify(&dca_notifier); |
| 4880 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4881 | pci_unregister_driver(&ixgbe_driver); |
| 4882 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4883 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4884 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4885 | 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] | 4886 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4887 | { |
| 4888 | int ret_val; |
| 4889 | |
| 4890 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4891 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4892 | |
| 4893 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 4894 | } |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 4895 | #endif /* CONFIG_IXGBE_DCA */ |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 4896 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4897 | module_exit(ixgbe_exit_module); |
| 4898 | |
| 4899 | /* ixgbe_main.c */ |