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