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 | bbf50e4 | 2009-07-16 15:51:11 +0000 | [diff] [blame^] | 51 | #define DRV_VERSION "2.0.37-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 }, |
Peter P Waskiewicz Jr | 3845bec | 2009-07-16 15:50:52 +0000 | [diff] [blame] | 77 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598AT2), |
| 78 | board_82598 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 79 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_CX4), |
Auke Kok | 3957d63 | 2007-10-31 15:22:10 -0700 | [diff] [blame] | 80 | board_82598 }, |
Jesse Brandeburg | 8d792cd | 2008-08-08 16:24:19 -0700 | [diff] [blame] | 81 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_CX4_DUAL_PORT), |
| 82 | board_82598 }, |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 83 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_DA_DUAL_PORT), |
| 84 | board_82598 }, |
| 85 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_SR_DUAL_PORT_EM), |
| 86 | board_82598 }, |
Jesse Brandeburg | b95f5fc | 2008-09-11 19:58:59 -0700 | [diff] [blame] | 87 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_XF_LR), |
| 88 | board_82598 }, |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 89 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598EB_SFP_LOM), |
| 90 | board_82598 }, |
Don Skidmore | 2f21bdd | 2009-02-01 01:18:23 -0800 | [diff] [blame] | 91 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82598_BX), |
| 92 | board_82598 }, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 93 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_KX4), |
| 94 | board_82599 }, |
Peter P Waskiewicz Jr | 1fcf03e | 2009-05-17 20:58:04 +0000 | [diff] [blame] | 95 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_XAUI_LOM), |
| 96 | board_82599 }, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 97 | {PCI_VDEVICE(INTEL, IXGBE_DEV_ID_82599_SFP), |
| 98 | board_82599 }, |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 99 | |
| 100 | /* required last entry */ |
| 101 | {0, } |
| 102 | }; |
| 103 | MODULE_DEVICE_TABLE(pci, ixgbe_pci_tbl); |
| 104 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 105 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 106 | static int ixgbe_notify_dca(struct notifier_block *, unsigned long event, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 107 | void *p); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 108 | static struct notifier_block dca_notifier = { |
| 109 | .notifier_call = ixgbe_notify_dca, |
| 110 | .next = NULL, |
| 111 | .priority = 0 |
| 112 | }; |
| 113 | #endif |
| 114 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 115 | MODULE_AUTHOR("Intel Corporation, <linux.nics@intel.com>"); |
| 116 | MODULE_DESCRIPTION("Intel(R) 10 Gigabit PCI Express Network Driver"); |
| 117 | MODULE_LICENSE("GPL"); |
| 118 | MODULE_VERSION(DRV_VERSION); |
| 119 | |
| 120 | #define DEFAULT_DEBUG_LEVEL_SHIFT 3 |
| 121 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 122 | static void ixgbe_release_hw_control(struct ixgbe_adapter *adapter) |
| 123 | { |
| 124 | u32 ctrl_ext; |
| 125 | |
| 126 | /* Let firmware take over control of h/w */ |
| 127 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 128 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 129 | ctrl_ext & ~IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 130 | } |
| 131 | |
| 132 | static void ixgbe_get_hw_control(struct ixgbe_adapter *adapter) |
| 133 | { |
| 134 | u32 ctrl_ext; |
| 135 | |
| 136 | /* Let firmware know the driver has taken over */ |
| 137 | ctrl_ext = IXGBE_READ_REG(&adapter->hw, IXGBE_CTRL_EXT); |
| 138 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_CTRL_EXT, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 139 | ctrl_ext | IXGBE_CTRL_EXT_DRV_LOAD); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 140 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 141 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 142 | /* |
| 143 | * ixgbe_set_ivar - set the IVAR registers, mapping interrupt causes to vectors |
| 144 | * @adapter: pointer to adapter struct |
| 145 | * @direction: 0 for Rx, 1 for Tx, -1 for other causes |
| 146 | * @queue: queue to map the corresponding interrupt to |
| 147 | * @msix_vector: the vector to map to the corresponding queue |
| 148 | * |
| 149 | */ |
| 150 | static void ixgbe_set_ivar(struct ixgbe_adapter *adapter, s8 direction, |
| 151 | u8 queue, u8 msix_vector) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 152 | { |
| 153 | u32 ivar, index; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 154 | struct ixgbe_hw *hw = &adapter->hw; |
| 155 | switch (hw->mac.type) { |
| 156 | case ixgbe_mac_82598EB: |
| 157 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 158 | if (direction == -1) |
| 159 | direction = 0; |
| 160 | index = (((direction * 64) + queue) >> 2) & 0x1F; |
| 161 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(index)); |
| 162 | ivar &= ~(0xFF << (8 * (queue & 0x3))); |
| 163 | ivar |= (msix_vector << (8 * (queue & 0x3))); |
| 164 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(index), ivar); |
| 165 | break; |
| 166 | case ixgbe_mac_82599EB: |
| 167 | if (direction == -1) { |
| 168 | /* other causes */ |
| 169 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 170 | index = ((queue & 1) * 8); |
| 171 | ivar = IXGBE_READ_REG(&adapter->hw, IXGBE_IVAR_MISC); |
| 172 | ivar &= ~(0xFF << index); |
| 173 | ivar |= (msix_vector << index); |
| 174 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_IVAR_MISC, ivar); |
| 175 | break; |
| 176 | } else { |
| 177 | /* tx or rx causes */ |
| 178 | msix_vector |= IXGBE_IVAR_ALLOC_VAL; |
| 179 | index = ((16 * (queue & 1)) + (8 * direction)); |
| 180 | ivar = IXGBE_READ_REG(hw, IXGBE_IVAR(queue >> 1)); |
| 181 | ivar &= ~(0xFF << index); |
| 182 | ivar |= (msix_vector << index); |
| 183 | IXGBE_WRITE_REG(hw, IXGBE_IVAR(queue >> 1), ivar); |
| 184 | break; |
| 185 | } |
| 186 | default: |
| 187 | break; |
| 188 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 189 | } |
| 190 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 191 | static inline void ixgbe_irq_rearm_queues(struct ixgbe_adapter *adapter, |
| 192 | u64 qmask) |
| 193 | { |
| 194 | u32 mask; |
| 195 | |
| 196 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 197 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 198 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS, mask); |
| 199 | } else { |
| 200 | mask = (qmask & 0xFFFFFFFF); |
| 201 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(0), mask); |
| 202 | mask = (qmask >> 32); |
| 203 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EICS_EX(1), mask); |
| 204 | } |
| 205 | } |
| 206 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 207 | 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] | 208 | struct ixgbe_tx_buffer |
| 209 | *tx_buffer_info) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 210 | { |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 211 | tx_buffer_info->dma = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 212 | if (tx_buffer_info->skb) { |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 213 | skb_dma_unmap(&adapter->pdev->dev, tx_buffer_info->skb, |
| 214 | DMA_TO_DEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 215 | dev_kfree_skb_any(tx_buffer_info->skb); |
| 216 | tx_buffer_info->skb = NULL; |
| 217 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 218 | tx_buffer_info->time_stamp = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 219 | /* tx_buffer_info must be completely set up in the transmit path */ |
| 220 | } |
| 221 | |
| 222 | static inline bool ixgbe_check_tx_hang(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 223 | struct ixgbe_ring *tx_ring, |
| 224 | unsigned int eop) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 225 | { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 226 | struct ixgbe_hw *hw = &adapter->hw; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 227 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 228 | /* Detect a transmit hang in hardware, this serializes the |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 229 | * check with the clearing of time_stamp and movement of eop */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 230 | adapter->detect_tx_hung = false; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 231 | if (tx_ring->tx_buffer_info[eop].time_stamp && |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 232 | time_after(jiffies, tx_ring->tx_buffer_info[eop].time_stamp + HZ) && |
| 233 | !(IXGBE_READ_REG(&adapter->hw, IXGBE_TFCS) & IXGBE_TFCS_TXOFF)) { |
| 234 | /* detected Tx unit hang */ |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 235 | union ixgbe_adv_tx_desc *tx_desc; |
| 236 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 237 | DPRINTK(DRV, ERR, "Detected Tx Unit Hang\n" |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 238 | " Tx Queue <%d>\n" |
| 239 | " TDH, TDT <%x>, <%x>\n" |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 240 | " next_to_use <%x>\n" |
| 241 | " next_to_clean <%x>\n" |
| 242 | "tx_buffer_info[next_to_clean]\n" |
| 243 | " time_stamp <%lx>\n" |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 244 | " jiffies <%lx>\n", |
| 245 | tx_ring->queue_index, |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 246 | IXGBE_READ_REG(hw, tx_ring->head), |
| 247 | IXGBE_READ_REG(hw, tx_ring->tail), |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 248 | tx_ring->next_to_use, eop, |
| 249 | tx_ring->tx_buffer_info[eop].time_stamp, jiffies); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 250 | return true; |
| 251 | } |
| 252 | |
| 253 | return false; |
| 254 | } |
| 255 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 256 | #define IXGBE_MAX_TXD_PWR 14 |
| 257 | #define IXGBE_MAX_DATA_PER_TXD (1 << IXGBE_MAX_TXD_PWR) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 258 | |
| 259 | /* Tx Descriptors needed, worst case */ |
| 260 | #define TXD_USE_COUNT(S) (((S) >> IXGBE_MAX_TXD_PWR) + \ |
| 261 | (((S) & (IXGBE_MAX_DATA_PER_TXD - 1)) ? 1 : 0)) |
| 262 | #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] | 263 | MAX_SKB_FRAGS * TXD_USE_COUNT(PAGE_SIZE) + 1) /* for context */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 264 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 265 | static void ixgbe_tx_timeout(struct net_device *netdev); |
| 266 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 267 | /** |
| 268 | * ixgbe_clean_tx_irq - Reclaim resources after transmit completes |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 269 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 270 | * @tx_ring: tx ring to clean |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 271 | **/ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 272 | static bool ixgbe_clean_tx_irq(struct ixgbe_q_vector *q_vector, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 273 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 274 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 275 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 276 | struct net_device *netdev = adapter->netdev; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 277 | union ixgbe_adv_tx_desc *tx_desc, *eop_desc; |
| 278 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 279 | unsigned int i, eop, count = 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 280 | unsigned int total_bytes = 0, total_packets = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 281 | |
| 282 | i = tx_ring->next_to_clean; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 283 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
| 284 | eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
| 285 | |
| 286 | while ((eop_desc->wb.status & cpu_to_le32(IXGBE_TXD_STAT_DD)) && |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 287 | (count < tx_ring->work_limit)) { |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 288 | bool cleaned = false; |
| 289 | for ( ; !cleaned; count++) { |
| 290 | struct sk_buff *skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 291 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); |
| 292 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 293 | cleaned = (i == eop); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 294 | skb = tx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 295 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 296 | if (cleaned && skb) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 297 | unsigned int segs, bytecount; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 298 | unsigned int hlen = skb_headlen(skb); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 299 | |
| 300 | /* gso_segs is currently only valid for tcp */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 301 | segs = skb_shinfo(skb)->gso_segs ?: 1; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 302 | #ifdef IXGBE_FCOE |
| 303 | /* adjust for FCoE Sequence Offload */ |
| 304 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 305 | && (skb->protocol == htons(ETH_P_FCOE)) && |
| 306 | skb_is_gso(skb)) { |
| 307 | hlen = skb_transport_offset(skb) + |
| 308 | sizeof(struct fc_frame_header) + |
| 309 | sizeof(struct fcoe_crc_eof); |
| 310 | segs = DIV_ROUND_UP(skb->len - hlen, |
| 311 | skb_shinfo(skb)->gso_size); |
| 312 | } |
| 313 | #endif /* IXGBE_FCOE */ |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 314 | /* multiply data chunks by size of headers */ |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 315 | bytecount = ((segs - 1) * hlen) + skb->len; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 316 | total_packets += segs; |
| 317 | total_bytes += bytecount; |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 318 | } |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 319 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 320 | ixgbe_unmap_and_free_tx_resource(adapter, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 321 | tx_buffer_info); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 322 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 323 | tx_desc->wb.status = 0; |
| 324 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 325 | i++; |
| 326 | if (i == tx_ring->count) |
| 327 | i = 0; |
| 328 | } |
| 329 | |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 330 | eop = tx_ring->tx_buffer_info[i].next_to_watch; |
| 331 | eop_desc = IXGBE_TX_DESC_ADV(*tx_ring, eop); |
| 332 | } |
| 333 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 334 | tx_ring->next_to_clean = i; |
| 335 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 336 | #define TX_WAKE_THRESHOLD (DESC_NEEDED * 2) |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 337 | if (unlikely(count && netif_carrier_ok(netdev) && |
| 338 | (IXGBE_DESC_UNUSED(tx_ring) >= TX_WAKE_THRESHOLD))) { |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 339 | /* Make sure that anybody stopping the queue after this |
| 340 | * sees the new next_to_clean. |
| 341 | */ |
| 342 | smp_mb(); |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 343 | if (__netif_subqueue_stopped(netdev, tx_ring->queue_index) && |
| 344 | !test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 345 | netif_wake_subqueue(netdev, tx_ring->queue_index); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 346 | ++adapter->restart_queue; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 347 | } |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 348 | } |
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 | if (adapter->detect_tx_hung) { |
| 351 | if (ixgbe_check_tx_hang(adapter, tx_ring, i)) { |
| 352 | /* schedule immediate reset if we believe we hung */ |
| 353 | DPRINTK(PROBE, INFO, |
| 354 | "tx hang %d detected, resetting adapter\n", |
| 355 | adapter->tx_timeout_count + 1); |
| 356 | ixgbe_tx_timeout(adapter->netdev); |
| 357 | } |
| 358 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 359 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 360 | /* re-arm the interrupt */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 361 | if (count >= tx_ring->work_limit) |
| 362 | ixgbe_irq_rearm_queues(adapter, ((u64)1 << q_vector->v_idx)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 363 | |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 364 | tx_ring->total_bytes += total_bytes; |
| 365 | tx_ring->total_packets += total_packets; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 366 | tx_ring->stats.packets += total_packets; |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 367 | tx_ring->stats.bytes += total_bytes; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 368 | adapter->net_stats.tx_bytes += total_bytes; |
| 369 | adapter->net_stats.tx_packets += total_packets; |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 370 | return (count < tx_ring->work_limit); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 371 | } |
| 372 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 373 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 374 | static void ixgbe_update_rx_dca(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 375 | struct ixgbe_ring *rx_ring) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 376 | { |
| 377 | u32 rxctrl; |
| 378 | int cpu = get_cpu(); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 379 | int q = rx_ring - adapter->rx_ring; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 380 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 381 | if (rx_ring->cpu != cpu) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 382 | rxctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 383 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 384 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK; |
| 385 | rxctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 386 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 387 | rxctrl &= ~IXGBE_DCA_RXCTRL_CPUID_MASK_82599; |
| 388 | rxctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 389 | IXGBE_DCA_RXCTRL_CPUID_SHIFT_82599); |
| 390 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 391 | rxctrl |= IXGBE_DCA_RXCTRL_DESC_DCA_EN; |
| 392 | rxctrl |= IXGBE_DCA_RXCTRL_HEAD_DCA_EN; |
Don Skidmore | 15005a3 | 2009-01-19 16:54:13 -0800 | [diff] [blame] | 393 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_RRO_EN); |
| 394 | rxctrl &= ~(IXGBE_DCA_RXCTRL_DESC_WRO_EN | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 395 | IXGBE_DCA_RXCTRL_DESC_HSRO_EN); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 396 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_RXCTRL(q), rxctrl); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 397 | rx_ring->cpu = cpu; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 398 | } |
| 399 | put_cpu(); |
| 400 | } |
| 401 | |
| 402 | static void ixgbe_update_tx_dca(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 403 | struct ixgbe_ring *tx_ring) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 404 | { |
| 405 | u32 txctrl; |
| 406 | int cpu = get_cpu(); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 407 | int q = tx_ring - adapter->tx_ring; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 408 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 409 | if (tx_ring->cpu != cpu) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 410 | txctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 411 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 412 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK; |
| 413 | txctrl |= dca3_get_tag(&adapter->pdev->dev, cpu); |
| 414 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 415 | txctrl &= ~IXGBE_DCA_TXCTRL_CPUID_MASK_82599; |
| 416 | txctrl |= (dca3_get_tag(&adapter->pdev->dev, cpu) << |
| 417 | IXGBE_DCA_TXCTRL_CPUID_SHIFT_82599); |
| 418 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 419 | txctrl |= IXGBE_DCA_TXCTRL_DESC_DCA_EN; |
| 420 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_TXCTRL(q), txctrl); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 421 | tx_ring->cpu = cpu; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 422 | } |
| 423 | put_cpu(); |
| 424 | } |
| 425 | |
| 426 | static void ixgbe_setup_dca(struct ixgbe_adapter *adapter) |
| 427 | { |
| 428 | int i; |
| 429 | |
| 430 | if (!(adapter->flags & IXGBE_FLAG_DCA_ENABLED)) |
| 431 | return; |
| 432 | |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 433 | /* always use CB2 mode, difference is masked in the CB driver */ |
| 434 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 2); |
| 435 | |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 436 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 437 | adapter->tx_ring[i].cpu = -1; |
| 438 | ixgbe_update_tx_dca(adapter, &adapter->tx_ring[i]); |
| 439 | } |
| 440 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 441 | adapter->rx_ring[i].cpu = -1; |
| 442 | ixgbe_update_rx_dca(adapter, &adapter->rx_ring[i]); |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | static int __ixgbe_notify_dca(struct device *dev, void *data) |
| 447 | { |
| 448 | struct net_device *netdev = dev_get_drvdata(dev); |
| 449 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 450 | unsigned long event = *(unsigned long *)data; |
| 451 | |
| 452 | switch (event) { |
| 453 | case DCA_PROVIDER_ADD: |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 454 | /* if we're already enabled, don't do it again */ |
| 455 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 456 | break; |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 457 | if (dca_add_requester(dev) == 0) { |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 458 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 459 | ixgbe_setup_dca(adapter); |
| 460 | break; |
| 461 | } |
| 462 | /* Fall Through since DCA is disabled. */ |
| 463 | case DCA_PROVIDER_REMOVE: |
| 464 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 465 | dca_remove_requester(dev); |
| 466 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 467 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 468 | } |
| 469 | break; |
| 470 | } |
| 471 | |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 472 | return 0; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 473 | } |
| 474 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 475 | #endif /* CONFIG_IXGBE_DCA */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 476 | /** |
| 477 | * ixgbe_receive_skb - Send a completed packet up the stack |
| 478 | * @adapter: board private structure |
| 479 | * @skb: packet to send up |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 480 | * @status: hardware indication of status of receive |
| 481 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
| 482 | * @rx_desc: rx descriptor |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 483 | **/ |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 484 | static void ixgbe_receive_skb(struct ixgbe_q_vector *q_vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 485 | struct sk_buff *skb, u8 status, |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 486 | struct ixgbe_ring *ring, |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 487 | union ixgbe_adv_rx_desc *rx_desc) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 488 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 489 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 490 | struct napi_struct *napi = &q_vector->napi; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 491 | bool is_vlan = (status & IXGBE_RXD_STAT_VP); |
| 492 | u16 tag = le16_to_cpu(rx_desc->wb.upper.vlan); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 493 | |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 494 | skb_record_rx_queue(skb, ring->queue_index); |
Alexander Duyck | 182ff8d | 2009-04-27 22:35:33 +0000 | [diff] [blame] | 495 | if (!(adapter->flags & IXGBE_FLAG_IN_NETPOLL)) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 496 | if (adapter->vlgrp && is_vlan && (tag != 0)) |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 497 | vlan_gro_receive(napi, adapter->vlgrp, tag, skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 498 | else |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 499 | napi_gro_receive(napi, skb); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 500 | } else { |
Alexander Duyck | 182ff8d | 2009-04-27 22:35:33 +0000 | [diff] [blame] | 501 | if (adapter->vlgrp && is_vlan && (tag != 0)) |
| 502 | vlan_hwaccel_rx(skb, adapter->vlgrp, tag); |
| 503 | else |
| 504 | netif_rx(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 505 | } |
| 506 | } |
| 507 | |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 508 | /** |
| 509 | * ixgbe_rx_checksum - indicate in skb if hw indicated a good cksum |
| 510 | * @adapter: address of board private structure |
| 511 | * @status_err: hardware indication of status of receive |
| 512 | * @skb: skb currently being received and modified |
| 513 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 514 | static inline void ixgbe_rx_checksum(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 515 | u32 status_err, struct sk_buff *skb) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 516 | { |
| 517 | skb->ip_summed = CHECKSUM_NONE; |
| 518 | |
Jesse Brandeburg | 712744b | 2008-08-26 04:26:56 -0700 | [diff] [blame] | 519 | /* Rx csum disabled */ |
| 520 | if (!(adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 521 | return; |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 522 | |
| 523 | /* if IP and error */ |
| 524 | if ((status_err & IXGBE_RXD_STAT_IPCS) && |
| 525 | (status_err & IXGBE_RXDADV_ERR_IPE)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 526 | adapter->hw_csum_rx_error++; |
| 527 | return; |
| 528 | } |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 529 | |
| 530 | if (!(status_err & IXGBE_RXD_STAT_L4CS)) |
| 531 | return; |
| 532 | |
| 533 | if (status_err & IXGBE_RXDADV_ERR_TCPE) { |
| 534 | adapter->hw_csum_rx_error++; |
| 535 | return; |
| 536 | } |
| 537 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 538 | /* It must be a TCP or UDP packet with a valid checksum */ |
Ayyappan Veeraiyan | e59bd25 | 2008-02-01 15:59:09 -0800 | [diff] [blame] | 539 | skb->ip_summed = CHECKSUM_UNNECESSARY; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 540 | adapter->hw_csum_rx_good++; |
| 541 | } |
| 542 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 543 | static inline void ixgbe_release_rx_desc(struct ixgbe_hw *hw, |
| 544 | struct ixgbe_ring *rx_ring, u32 val) |
| 545 | { |
| 546 | /* |
| 547 | * Force memory writes to complete before letting h/w |
| 548 | * know there are new descriptors to fetch. (Only |
| 549 | * applicable for weak-ordered memory model archs, |
| 550 | * such as IA-64). |
| 551 | */ |
| 552 | wmb(); |
| 553 | IXGBE_WRITE_REG(hw, IXGBE_RDT(rx_ring->reg_idx), val); |
| 554 | } |
| 555 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 556 | /** |
| 557 | * ixgbe_alloc_rx_buffers - Replace used receive buffers; packet split |
| 558 | * @adapter: address of board private structure |
| 559 | **/ |
| 560 | static void ixgbe_alloc_rx_buffers(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 561 | struct ixgbe_ring *rx_ring, |
| 562 | int cleaned_count) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 563 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 564 | struct pci_dev *pdev = adapter->pdev; |
| 565 | union ixgbe_adv_rx_desc *rx_desc; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 566 | struct ixgbe_rx_buffer *bi; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 567 | unsigned int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 568 | |
| 569 | i = rx_ring->next_to_use; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 570 | bi = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 571 | |
| 572 | while (cleaned_count--) { |
| 573 | rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 574 | |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 575 | if (!bi->page_dma && |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 576 | (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED)) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 577 | if (!bi->page) { |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 578 | bi->page = alloc_page(GFP_ATOMIC); |
| 579 | if (!bi->page) { |
| 580 | adapter->alloc_rx_page_failed++; |
| 581 | goto no_buffers; |
| 582 | } |
| 583 | bi->page_offset = 0; |
| 584 | } else { |
| 585 | /* use a half page if we're re-using */ |
| 586 | bi->page_offset ^= (PAGE_SIZE / 2); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 587 | } |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 588 | |
| 589 | bi->page_dma = pci_map_page(pdev, bi->page, |
| 590 | bi->page_offset, |
| 591 | (PAGE_SIZE / 2), |
| 592 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 593 | } |
| 594 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 595 | if (!bi->skb) { |
Jesse Brandeburg | 5ecc361 | 2008-12-15 01:00:57 -0800 | [diff] [blame] | 596 | struct sk_buff *skb; |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 597 | skb = netdev_alloc_skb(adapter->netdev, |
| 598 | (rx_ring->rx_buf_len + |
| 599 | NET_IP_ALIGN)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 600 | |
| 601 | if (!skb) { |
| 602 | adapter->alloc_rx_buff_failed++; |
| 603 | goto no_buffers; |
| 604 | } |
| 605 | |
| 606 | /* |
| 607 | * Make buffer alignment 2 beyond a 16 byte boundary |
| 608 | * this will result in a 16 byte aligned IP header after |
| 609 | * the 14 byte MAC header is removed |
| 610 | */ |
| 611 | skb_reserve(skb, NET_IP_ALIGN); |
| 612 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 613 | bi->skb = skb; |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 614 | bi->dma = pci_map_single(pdev, skb->data, |
| 615 | rx_ring->rx_buf_len, |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 616 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 617 | } |
| 618 | /* Refresh the desc even if buffer_addrs didn't change because |
| 619 | * each write-back erases this info. */ |
| 620 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 621 | rx_desc->read.pkt_addr = cpu_to_le64(bi->page_dma); |
| 622 | rx_desc->read.hdr_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 623 | } else { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 624 | rx_desc->read.pkt_addr = cpu_to_le64(bi->dma); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 625 | } |
| 626 | |
| 627 | i++; |
| 628 | if (i == rx_ring->count) |
| 629 | i = 0; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 630 | bi = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 631 | } |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 632 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 633 | no_buffers: |
| 634 | if (rx_ring->next_to_use != i) { |
| 635 | rx_ring->next_to_use = i; |
| 636 | if (i-- == 0) |
| 637 | i = (rx_ring->count - 1); |
| 638 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 639 | ixgbe_release_rx_desc(&adapter->hw, rx_ring, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 640 | } |
| 641 | } |
| 642 | |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 643 | static inline u16 ixgbe_get_hdr_info(union ixgbe_adv_rx_desc *rx_desc) |
| 644 | { |
| 645 | return rx_desc->wb.lower.lo_dword.hs_rss.hdr_info; |
| 646 | } |
| 647 | |
| 648 | static inline u16 ixgbe_get_pkt_info(union ixgbe_adv_rx_desc *rx_desc) |
| 649 | { |
| 650 | return rx_desc->wb.lower.lo_dword.hs_rss.pkt_info; |
| 651 | } |
| 652 | |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 653 | static inline u32 ixgbe_get_rsc_count(union ixgbe_adv_rx_desc *rx_desc) |
| 654 | { |
| 655 | return (le32_to_cpu(rx_desc->wb.lower.lo_dword.data) & |
| 656 | IXGBE_RXDADV_RSCCNT_MASK) >> |
| 657 | IXGBE_RXDADV_RSCCNT_SHIFT; |
| 658 | } |
| 659 | |
| 660 | /** |
| 661 | * ixgbe_transform_rsc_queue - change rsc queue into a full packet |
| 662 | * @skb: pointer to the last skb in the rsc queue |
| 663 | * |
| 664 | * This function changes a queue full of hw rsc buffers into a completed |
| 665 | * packet. It uses the ->prev pointers to find the first packet and then |
| 666 | * turns it into the frag list owner. |
| 667 | **/ |
| 668 | static inline struct sk_buff *ixgbe_transform_rsc_queue(struct sk_buff *skb) |
| 669 | { |
| 670 | unsigned int frag_list_size = 0; |
| 671 | |
| 672 | while (skb->prev) { |
| 673 | struct sk_buff *prev = skb->prev; |
| 674 | frag_list_size += skb->len; |
| 675 | skb->prev = NULL; |
| 676 | skb = prev; |
| 677 | } |
| 678 | |
| 679 | skb_shinfo(skb)->frag_list = skb->next; |
| 680 | skb->next = NULL; |
| 681 | skb->len += frag_list_size; |
| 682 | skb->data_len += frag_list_size; |
| 683 | skb->truesize += frag_list_size; |
| 684 | return skb; |
| 685 | } |
| 686 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 687 | 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] | 688 | struct ixgbe_ring *rx_ring, |
| 689 | int *work_done, int work_to_do) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 690 | { |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 691 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 692 | struct pci_dev *pdev = adapter->pdev; |
| 693 | union ixgbe_adv_rx_desc *rx_desc, *next_rxd; |
| 694 | struct ixgbe_rx_buffer *rx_buffer_info, *next_buffer; |
| 695 | struct sk_buff *skb; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 696 | unsigned int i, rsc_count = 0; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 697 | u32 len, staterr; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 698 | u16 hdr_info; |
| 699 | bool cleaned = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 700 | int cleaned_count = 0; |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 701 | unsigned int total_rx_bytes = 0, total_rx_packets = 0; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 702 | #ifdef IXGBE_FCOE |
| 703 | int ddp_bytes = 0; |
| 704 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 705 | |
| 706 | i = rx_ring->next_to_clean; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 707 | rx_desc = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 708 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
| 709 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 710 | |
| 711 | while (staterr & IXGBE_RXD_STAT_DD) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 712 | u32 upper_len = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 713 | if (*work_done >= work_to_do) |
| 714 | break; |
| 715 | (*work_done)++; |
| 716 | |
| 717 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 718 | hdr_info = le16_to_cpu(ixgbe_get_hdr_info(rx_desc)); |
| 719 | len = (hdr_info & IXGBE_RXDADV_HDRBUFLEN_MASK) >> |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 720 | IXGBE_RXDADV_HDRBUFLEN_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 721 | if (hdr_info & IXGBE_RXDADV_SPH) |
| 722 | adapter->rx_hdr_split++; |
| 723 | if (len > IXGBE_RX_HDR_SIZE) |
| 724 | len = IXGBE_RX_HDR_SIZE; |
| 725 | upper_len = le16_to_cpu(rx_desc->wb.upper.length); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 726 | } else { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 727 | len = le16_to_cpu(rx_desc->wb.upper.length); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 728 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 729 | |
| 730 | cleaned = true; |
| 731 | skb = rx_buffer_info->skb; |
| 732 | prefetch(skb->data - NET_IP_ALIGN); |
| 733 | rx_buffer_info->skb = NULL; |
| 734 | |
Alexander Duyck | 21fa4e6 | 2009-06-04 15:59:49 +0000 | [diff] [blame] | 735 | if (rx_buffer_info->dma) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 736 | pci_unmap_single(pdev, rx_buffer_info->dma, |
Jesse Brandeburg | 5ecc361 | 2008-12-15 01:00:57 -0800 | [diff] [blame] | 737 | rx_ring->rx_buf_len, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 738 | PCI_DMA_FROMDEVICE); |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 739 | rx_buffer_info->dma = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 740 | skb_put(skb, len); |
| 741 | } |
| 742 | |
| 743 | if (upper_len) { |
| 744 | pci_unmap_page(pdev, rx_buffer_info->page_dma, |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 745 | PAGE_SIZE / 2, PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 746 | rx_buffer_info->page_dma = 0; |
| 747 | skb_fill_page_desc(skb, skb_shinfo(skb)->nr_frags, |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 748 | rx_buffer_info->page, |
| 749 | rx_buffer_info->page_offset, |
| 750 | upper_len); |
| 751 | |
| 752 | if ((rx_ring->rx_buf_len > (PAGE_SIZE / 2)) || |
| 753 | (page_count(rx_buffer_info->page) != 1)) |
| 754 | rx_buffer_info->page = NULL; |
| 755 | else |
| 756 | get_page(rx_buffer_info->page); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 757 | |
| 758 | skb->len += upper_len; |
| 759 | skb->data_len += upper_len; |
| 760 | skb->truesize += upper_len; |
| 761 | } |
| 762 | |
| 763 | i++; |
| 764 | if (i == rx_ring->count) |
| 765 | i = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 766 | |
| 767 | next_rxd = IXGBE_RX_DESC_ADV(*rx_ring, i); |
| 768 | prefetch(next_rxd); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 769 | cleaned_count++; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 770 | |
Peter P Waskiewicz Jr | df647b5 | 2009-06-04 16:00:47 +0000 | [diff] [blame] | 771 | if (adapter->flags & IXGBE_FLAG2_RSC_CAPABLE) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 772 | rsc_count = ixgbe_get_rsc_count(rx_desc); |
| 773 | |
| 774 | if (rsc_count) { |
| 775 | u32 nextp = (staterr & IXGBE_RXDADV_NEXTP_MASK) >> |
| 776 | IXGBE_RXDADV_NEXTP_SHIFT; |
| 777 | next_buffer = &rx_ring->rx_buffer_info[nextp]; |
| 778 | rx_ring->rsc_count += (rsc_count - 1); |
| 779 | } else { |
| 780 | next_buffer = &rx_ring->rx_buffer_info[i]; |
| 781 | } |
| 782 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 783 | if (staterr & IXGBE_RXD_STAT_EOP) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 784 | if (skb->prev) |
| 785 | skb = ixgbe_transform_rsc_queue(skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 786 | rx_ring->stats.packets++; |
| 787 | rx_ring->stats.bytes += skb->len; |
| 788 | } else { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 789 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
| 790 | rx_buffer_info->skb = next_buffer->skb; |
| 791 | rx_buffer_info->dma = next_buffer->dma; |
| 792 | next_buffer->skb = skb; |
| 793 | next_buffer->dma = 0; |
| 794 | } else { |
| 795 | skb->next = next_buffer->skb; |
| 796 | skb->next->prev = skb; |
| 797 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 798 | adapter->non_eop_descs++; |
| 799 | goto next_desc; |
| 800 | } |
| 801 | |
| 802 | if (staterr & IXGBE_RXDADV_ERR_FRAME_ERR_MASK) { |
| 803 | dev_kfree_skb_irq(skb); |
| 804 | goto next_desc; |
| 805 | } |
| 806 | |
| 807 | ixgbe_rx_checksum(adapter, staterr, skb); |
Ayyappan Veeraiyan | d2f4fbe | 2008-02-01 15:59:19 -0800 | [diff] [blame] | 808 | |
| 809 | /* probably a little skewed due to removing CRC */ |
| 810 | total_rx_bytes += skb->len; |
| 811 | total_rx_packets++; |
| 812 | |
Jesse Brandeburg | 74ce8dd | 2008-09-11 20:03:23 -0700 | [diff] [blame] | 813 | skb->protocol = eth_type_trans(skb, adapter->netdev); |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 814 | #ifdef IXGBE_FCOE |
| 815 | /* if ddp, not passing to ULD unless for FCP_RSP or error */ |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 816 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 817 | ddp_bytes = ixgbe_fcoe_ddp(adapter, rx_desc, skb); |
| 818 | if (!ddp_bytes) |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 819 | goto next_desc; |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 820 | } |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 821 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | fdaff1c | 2009-05-06 10:43:47 +0000 | [diff] [blame] | 822 | ixgbe_receive_skb(q_vector, skb, staterr, rx_ring, rx_desc); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 823 | |
| 824 | next_desc: |
| 825 | rx_desc->wb.upper.status_error = 0; |
| 826 | |
| 827 | /* return some buffers to hardware, one at a time is too slow */ |
| 828 | if (cleaned_count >= IXGBE_RX_BUFFER_WRITE) { |
| 829 | ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count); |
| 830 | cleaned_count = 0; |
| 831 | } |
| 832 | |
| 833 | /* use prefetched values */ |
| 834 | rx_desc = next_rxd; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 835 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 836 | |
| 837 | staterr = le32_to_cpu(rx_desc->wb.upper.status_error); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 838 | } |
| 839 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 840 | rx_ring->next_to_clean = i; |
| 841 | cleaned_count = IXGBE_DESC_UNUSED(rx_ring); |
| 842 | |
| 843 | if (cleaned_count) |
| 844 | ixgbe_alloc_rx_buffers(adapter, rx_ring, cleaned_count); |
| 845 | |
Yi Zou | 3d8fd38 | 2009-06-08 14:38:44 +0000 | [diff] [blame] | 846 | #ifdef IXGBE_FCOE |
| 847 | /* include DDPed FCoE data */ |
| 848 | if (ddp_bytes > 0) { |
| 849 | unsigned int mss; |
| 850 | |
| 851 | mss = adapter->netdev->mtu - sizeof(struct fcoe_hdr) - |
| 852 | sizeof(struct fc_frame_header) - |
| 853 | sizeof(struct fcoe_crc_eof); |
| 854 | if (mss > 512) |
| 855 | mss &= ~511; |
| 856 | total_rx_bytes += ddp_bytes; |
| 857 | total_rx_packets += DIV_ROUND_UP(ddp_bytes, mss); |
| 858 | } |
| 859 | #endif /* IXGBE_FCOE */ |
| 860 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 861 | rx_ring->total_packets += total_rx_packets; |
| 862 | rx_ring->total_bytes += total_rx_bytes; |
| 863 | adapter->net_stats.rx_bytes += total_rx_bytes; |
| 864 | adapter->net_stats.rx_packets += total_rx_packets; |
| 865 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 866 | return cleaned; |
| 867 | } |
| 868 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 869 | static int ixgbe_clean_rxonly(struct napi_struct *, int); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 870 | /** |
| 871 | * ixgbe_configure_msix - Configure MSI-X hardware |
| 872 | * @adapter: board private structure |
| 873 | * |
| 874 | * ixgbe_configure_msix sets up the hardware to properly generate MSI-X |
| 875 | * interrupts. |
| 876 | **/ |
| 877 | static void ixgbe_configure_msix(struct ixgbe_adapter *adapter) |
| 878 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 879 | struct ixgbe_q_vector *q_vector; |
| 880 | int i, j, q_vectors, v_idx, r_idx; |
| 881 | u32 mask; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 882 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 883 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 884 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 885 | /* |
| 886 | * Populate the IVAR table and set the ITR values to the |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 887 | * corresponding register. |
| 888 | */ |
| 889 | for (v_idx = 0; v_idx < q_vectors; v_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 890 | q_vector = adapter->q_vector[v_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 891 | /* XXX for_each_bit(...) */ |
| 892 | r_idx = find_first_bit(q_vector->rxr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 893 | adapter->num_rx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 894 | |
| 895 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 896 | j = adapter->rx_ring[r_idx].reg_idx; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 897 | ixgbe_set_ivar(adapter, 0, j, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 898 | r_idx = find_next_bit(q_vector->rxr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 899 | adapter->num_rx_queues, |
| 900 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 901 | } |
| 902 | r_idx = find_first_bit(q_vector->txr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 903 | adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 904 | |
| 905 | for (i = 0; i < q_vector->txr_count; i++) { |
| 906 | j = adapter->tx_ring[r_idx].reg_idx; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 907 | ixgbe_set_ivar(adapter, 1, j, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 908 | r_idx = find_next_bit(q_vector->txr_idx, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 909 | adapter->num_tx_queues, |
| 910 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 911 | } |
| 912 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 913 | /* if this is a tx only vector halve the interrupt rate */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 914 | if (q_vector->txr_count && !q_vector->rxr_count) |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 915 | q_vector->eitr = (adapter->eitr_param >> 1); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 916 | else if (q_vector->rxr_count) |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 917 | /* rx only */ |
| 918 | q_vector->eitr = adapter->eitr_param; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 919 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 920 | ixgbe_write_eitr(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 921 | } |
| 922 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 923 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) |
| 924 | ixgbe_set_ivar(adapter, -1, IXGBE_IVAR_OTHER_CAUSES_INDEX, |
| 925 | v_idx); |
| 926 | else if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 927 | ixgbe_set_ivar(adapter, -1, 1, v_idx); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 928 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EITR(v_idx), 1950); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 929 | |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 930 | /* set up to autoclear timer, and the vectors */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 931 | mask = IXGBE_EIMS_ENABLE_MASK; |
Jesse Brandeburg | 41fb924 | 2008-09-11 19:55:58 -0700 | [diff] [blame] | 932 | mask &= ~(IXGBE_EIMS_OTHER | IXGBE_EIMS_LSC); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 933 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIAC, mask); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 934 | } |
| 935 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 936 | enum latency_range { |
| 937 | lowest_latency = 0, |
| 938 | low_latency = 1, |
| 939 | bulk_latency = 2, |
| 940 | latency_invalid = 255 |
| 941 | }; |
| 942 | |
| 943 | /** |
| 944 | * ixgbe_update_itr - update the dynamic ITR value based on statistics |
| 945 | * @adapter: pointer to adapter |
| 946 | * @eitr: eitr setting (ints per sec) to give last timeslice |
| 947 | * @itr_setting: current throttle rate in ints/second |
| 948 | * @packets: the number of packets during this measurement interval |
| 949 | * @bytes: the number of bytes during this measurement interval |
| 950 | * |
| 951 | * Stores a new ITR value based on packets and byte |
| 952 | * counts during the last interrupt. The advantage of per interrupt |
| 953 | * computation is faster updates and more accurate ITR for the current |
| 954 | * traffic pattern. Constants in this function were computed |
| 955 | * based on theoretical maximum wire speed and thresholds were set based |
| 956 | * on testing data as well as attempting to minimize response time |
| 957 | * while increasing bulk throughput. |
| 958 | * this functionality is controlled by the InterruptThrottleRate module |
| 959 | * parameter (see ixgbe_param.c) |
| 960 | **/ |
| 961 | static u8 ixgbe_update_itr(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 962 | u32 eitr, u8 itr_setting, |
| 963 | int packets, int bytes) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 964 | { |
| 965 | unsigned int retval = itr_setting; |
| 966 | u32 timepassed_us; |
| 967 | u64 bytes_perint; |
| 968 | |
| 969 | if (packets == 0) |
| 970 | goto update_itr_done; |
| 971 | |
| 972 | |
| 973 | /* simple throttlerate management |
| 974 | * 0-20MB/s lowest (100000 ints/s) |
| 975 | * 20-100MB/s low (20000 ints/s) |
| 976 | * 100-1249MB/s bulk (8000 ints/s) |
| 977 | */ |
| 978 | /* what was last interrupt timeslice? */ |
| 979 | timepassed_us = 1000000/eitr; |
| 980 | bytes_perint = bytes / timepassed_us; /* bytes/usec */ |
| 981 | |
| 982 | switch (itr_setting) { |
| 983 | case lowest_latency: |
| 984 | if (bytes_perint > adapter->eitr_low) |
| 985 | retval = low_latency; |
| 986 | break; |
| 987 | case low_latency: |
| 988 | if (bytes_perint > adapter->eitr_high) |
| 989 | retval = bulk_latency; |
| 990 | else if (bytes_perint <= adapter->eitr_low) |
| 991 | retval = lowest_latency; |
| 992 | break; |
| 993 | case bulk_latency: |
| 994 | if (bytes_perint <= adapter->eitr_high) |
| 995 | retval = low_latency; |
| 996 | break; |
| 997 | } |
| 998 | |
| 999 | update_itr_done: |
| 1000 | return retval; |
| 1001 | } |
| 1002 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1003 | /** |
| 1004 | * ixgbe_write_eitr - write EITR register in hardware specific way |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1005 | * @q_vector: structure containing interrupt and ring information |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1006 | * |
| 1007 | * This function is made to be called by ethtool and by the driver |
| 1008 | * when it needs to update EITR registers at runtime. Hardware |
| 1009 | * specific quirks/differences are taken care of here. |
| 1010 | */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1011 | void ixgbe_write_eitr(struct ixgbe_q_vector *q_vector) |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1012 | { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1013 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1014 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1015 | int v_idx = q_vector->v_idx; |
| 1016 | u32 itr_reg = EITR_INTS_PER_SEC_TO_REG(q_vector->eitr); |
| 1017 | |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1018 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1019 | /* must write high and low 16 bits to reset counter */ |
| 1020 | itr_reg |= (itr_reg << 16); |
| 1021 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 1022 | /* |
| 1023 | * set the WDIS bit to not clear the timer bits and cause an |
| 1024 | * immediate assertion of the interrupt |
| 1025 | */ |
| 1026 | itr_reg |= IXGBE_EITR_CNT_WDIS; |
| 1027 | } |
| 1028 | IXGBE_WRITE_REG(hw, IXGBE_EITR(v_idx), itr_reg); |
| 1029 | } |
| 1030 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1031 | static void ixgbe_set_itr_msix(struct ixgbe_q_vector *q_vector) |
| 1032 | { |
| 1033 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1034 | u32 new_itr; |
| 1035 | u8 current_itr, ret_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1036 | int i, r_idx; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1037 | struct ixgbe_ring *rx_ring, *tx_ring; |
| 1038 | |
| 1039 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1040 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1041 | tx_ring = &(adapter->tx_ring[r_idx]); |
| 1042 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1043 | q_vector->tx_itr, |
| 1044 | tx_ring->total_packets, |
| 1045 | tx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1046 | /* if the result for this queue would decrease interrupt |
| 1047 | * rate for this vector then use that result */ |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1048 | q_vector->tx_itr = ((q_vector->tx_itr > ret_itr) ? |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1049 | q_vector->tx_itr - 1 : ret_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1050 | 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] | 1051 | r_idx + 1); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1052 | } |
| 1053 | |
| 1054 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1055 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1056 | rx_ring = &(adapter->rx_ring[r_idx]); |
| 1057 | ret_itr = ixgbe_update_itr(adapter, q_vector->eitr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1058 | q_vector->rx_itr, |
| 1059 | rx_ring->total_packets, |
| 1060 | rx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1061 | /* if the result for this queue would decrease interrupt |
| 1062 | * rate for this vector then use that result */ |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1063 | q_vector->rx_itr = ((q_vector->rx_itr > ret_itr) ? |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1064 | q_vector->rx_itr - 1 : ret_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1065 | 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] | 1066 | r_idx + 1); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1067 | } |
| 1068 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1069 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1070 | |
| 1071 | switch (current_itr) { |
| 1072 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1073 | case lowest_latency: |
| 1074 | new_itr = 100000; |
| 1075 | break; |
| 1076 | case low_latency: |
| 1077 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 1078 | break; |
| 1079 | case bulk_latency: |
| 1080 | default: |
| 1081 | new_itr = 8000; |
| 1082 | break; |
| 1083 | } |
| 1084 | |
| 1085 | if (new_itr != q_vector->eitr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1086 | /* do an exponential smoothing */ |
| 1087 | new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1088 | |
| 1089 | /* save the algorithm value here, not the smoothed one */ |
| 1090 | q_vector->eitr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1091 | |
| 1092 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1093 | } |
| 1094 | |
| 1095 | return; |
| 1096 | } |
| 1097 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1098 | static void ixgbe_check_fan_failure(struct ixgbe_adapter *adapter, u32 eicr) |
| 1099 | { |
| 1100 | struct ixgbe_hw *hw = &adapter->hw; |
| 1101 | |
| 1102 | if ((adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) && |
| 1103 | (eicr & IXGBE_EICR_GPI_SDP1)) { |
| 1104 | DPRINTK(PROBE, CRIT, "Fan has stopped, replace the adapter\n"); |
| 1105 | /* write to clear the interrupt */ |
| 1106 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 1107 | } |
| 1108 | } |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1109 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1110 | static void ixgbe_check_sfp_event(struct ixgbe_adapter *adapter, u32 eicr) |
| 1111 | { |
| 1112 | struct ixgbe_hw *hw = &adapter->hw; |
| 1113 | |
| 1114 | if (eicr & IXGBE_EICR_GPI_SDP1) { |
| 1115 | /* Clear the interrupt */ |
| 1116 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP1); |
| 1117 | schedule_work(&adapter->multispeed_fiber_task); |
| 1118 | } else if (eicr & IXGBE_EICR_GPI_SDP2) { |
| 1119 | /* Clear the interrupt */ |
| 1120 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_GPI_SDP2); |
| 1121 | schedule_work(&adapter->sfp_config_module_task); |
| 1122 | } else { |
| 1123 | /* Interrupt isn't for us... */ |
| 1124 | return; |
| 1125 | } |
| 1126 | } |
| 1127 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1128 | static void ixgbe_check_lsc(struct ixgbe_adapter *adapter) |
| 1129 | { |
| 1130 | struct ixgbe_hw *hw = &adapter->hw; |
| 1131 | |
| 1132 | adapter->lsc_int++; |
| 1133 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 1134 | adapter->link_check_timeout = jiffies; |
| 1135 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) { |
| 1136 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_EIMC_LSC); |
| 1137 | schedule_work(&adapter->watchdog_task); |
| 1138 | } |
| 1139 | } |
| 1140 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1141 | static irqreturn_t ixgbe_msix_lsc(int irq, void *data) |
| 1142 | { |
| 1143 | struct net_device *netdev = data; |
| 1144 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1145 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 1146 | u32 eicr; |
| 1147 | |
| 1148 | /* |
| 1149 | * Workaround for Silicon errata. Use clear-by-write instead |
| 1150 | * of clear-by-read. Reading with EICS will return the |
| 1151 | * interrupt causes without clearing, which later be done |
| 1152 | * with the write to EICR. |
| 1153 | */ |
| 1154 | eicr = IXGBE_READ_REG(hw, IXGBE_EICS); |
| 1155 | IXGBE_WRITE_REG(hw, IXGBE_EICR, eicr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1156 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1157 | if (eicr & IXGBE_EICR_LSC) |
| 1158 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1159 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1160 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 1161 | ixgbe_check_fan_failure(adapter, eicr); |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1162 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1163 | if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1164 | ixgbe_check_sfp_event(adapter, eicr); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1165 | |
| 1166 | /* Handle Flow Director Full threshold interrupt */ |
| 1167 | if (eicr & IXGBE_EICR_FLOW_DIR) { |
| 1168 | int i; |
| 1169 | IXGBE_WRITE_REG(hw, IXGBE_EICR, IXGBE_EICR_FLOW_DIR); |
| 1170 | /* Disable transmits before FDIR Re-initialization */ |
| 1171 | netif_tx_stop_all_queues(netdev); |
| 1172 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 1173 | struct ixgbe_ring *tx_ring = |
| 1174 | &adapter->tx_ring[i]; |
| 1175 | if (test_and_clear_bit(__IXGBE_FDIR_INIT_DONE, |
| 1176 | &tx_ring->reinit_state)) |
| 1177 | schedule_work(&adapter->fdir_reinit_task); |
| 1178 | } |
| 1179 | } |
| 1180 | } |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 1181 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1182 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMS_OTHER); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1183 | |
| 1184 | return IRQ_HANDLED; |
| 1185 | } |
| 1186 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1187 | static inline void ixgbe_irq_enable_queues(struct ixgbe_adapter *adapter, |
| 1188 | u64 qmask) |
| 1189 | { |
| 1190 | u32 mask; |
| 1191 | |
| 1192 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1193 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 1194 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
| 1195 | } else { |
| 1196 | mask = (qmask & 0xFFFFFFFF); |
| 1197 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(0), mask); |
| 1198 | mask = (qmask >> 32); |
| 1199 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS_EX(1), mask); |
| 1200 | } |
| 1201 | /* skip the flush */ |
| 1202 | } |
| 1203 | |
| 1204 | static inline void ixgbe_irq_disable_queues(struct ixgbe_adapter *adapter, |
| 1205 | u64 qmask) |
| 1206 | { |
| 1207 | u32 mask; |
| 1208 | |
| 1209 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1210 | mask = (IXGBE_EIMS_RTX_QUEUE & qmask); |
| 1211 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, mask); |
| 1212 | } else { |
| 1213 | mask = (qmask & 0xFFFFFFFF); |
| 1214 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), mask); |
| 1215 | mask = (qmask >> 32); |
| 1216 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), mask); |
| 1217 | } |
| 1218 | /* skip the flush */ |
| 1219 | } |
| 1220 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1221 | static irqreturn_t ixgbe_msix_clean_tx(int irq, void *data) |
| 1222 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1223 | struct ixgbe_q_vector *q_vector = data; |
| 1224 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1225 | struct ixgbe_ring *tx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1226 | int i, r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1227 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1228 | if (!q_vector->txr_count) |
| 1229 | return IRQ_HANDLED; |
| 1230 | |
| 1231 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1232 | for (i = 0; i < q_vector->txr_count; i++) { |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1233 | tx_ring = &(adapter->tx_ring[r_idx]); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1234 | tx_ring->total_bytes = 0; |
| 1235 | tx_ring->total_packets = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1236 | 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] | 1237 | r_idx + 1); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1238 | } |
| 1239 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1240 | /* disable interrupts on this vector only */ |
| 1241 | ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 1242 | napi_schedule(&q_vector->napi); |
| 1243 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1244 | return IRQ_HANDLED; |
| 1245 | } |
| 1246 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1247 | /** |
| 1248 | * ixgbe_msix_clean_rx - single unshared vector rx clean (all queues) |
| 1249 | * @irq: unused |
| 1250 | * @data: pointer to our q_vector struct for this interrupt vector |
| 1251 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1252 | static irqreturn_t ixgbe_msix_clean_rx(int irq, void *data) |
| 1253 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1254 | struct ixgbe_q_vector *q_vector = data; |
| 1255 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1256 | struct ixgbe_ring *rx_ring; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1257 | int r_idx; |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1258 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1259 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1260 | 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] | 1261 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1262 | rx_ring = &(adapter->rx_ring[r_idx]); |
| 1263 | rx_ring->total_bytes = 0; |
| 1264 | rx_ring->total_packets = 0; |
| 1265 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1266 | r_idx + 1); |
| 1267 | } |
| 1268 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1269 | if (!q_vector->rxr_count) |
| 1270 | return IRQ_HANDLED; |
| 1271 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1272 | 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] | 1273 | rx_ring = &(adapter->rx_ring[r_idx]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1274 | /* disable interrupts on this vector only */ |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1275 | ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1276 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1277 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1278 | return IRQ_HANDLED; |
| 1279 | } |
| 1280 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1281 | static irqreturn_t ixgbe_msix_clean_many(int irq, void *data) |
| 1282 | { |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1283 | struct ixgbe_q_vector *q_vector = data; |
| 1284 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1285 | struct ixgbe_ring *ring; |
| 1286 | int r_idx; |
| 1287 | int i; |
| 1288 | |
| 1289 | if (!q_vector->txr_count && !q_vector->rxr_count) |
| 1290 | return IRQ_HANDLED; |
| 1291 | |
| 1292 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1293 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1294 | ring = &(adapter->tx_ring[r_idx]); |
| 1295 | ring->total_bytes = 0; |
| 1296 | ring->total_packets = 0; |
| 1297 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
| 1298 | r_idx + 1); |
| 1299 | } |
| 1300 | |
| 1301 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1302 | for (i = 0; i < q_vector->rxr_count; i++) { |
| 1303 | ring = &(adapter->rx_ring[r_idx]); |
| 1304 | ring->total_bytes = 0; |
| 1305 | ring->total_packets = 0; |
| 1306 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1307 | r_idx + 1); |
| 1308 | } |
| 1309 | |
| 1310 | /* disable interrupts on this vector only */ |
| 1311 | ixgbe_irq_disable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 1312 | napi_schedule(&q_vector->napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1313 | |
| 1314 | return IRQ_HANDLED; |
| 1315 | } |
| 1316 | |
| 1317 | /** |
| 1318 | * ixgbe_clean_rxonly - msix (aka one shot) rx clean routine |
| 1319 | * @napi: napi struct with our devices info in it |
| 1320 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1321 | * |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1322 | * This function is optimized for cleaning one queue only on a single |
| 1323 | * q_vector!!! |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1324 | **/ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1325 | static int ixgbe_clean_rxonly(struct napi_struct *napi, int budget) |
| 1326 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1327 | struct ixgbe_q_vector *q_vector = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1328 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1329 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1330 | struct ixgbe_ring *rx_ring = NULL; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1331 | int work_done = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1332 | long r_idx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1333 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1334 | 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] | 1335 | rx_ring = &(adapter->rx_ring[r_idx]); |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1336 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1337 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1338 | ixgbe_update_rx_dca(adapter, rx_ring); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 1339 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1340 | |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 1341 | ixgbe_clean_rx_irq(q_vector, rx_ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1342 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1343 | /* If all Rx work done, exit the polling mode */ |
| 1344 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1345 | napi_complete(napi); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1346 | if (adapter->itr_setting & 1) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1347 | ixgbe_set_itr_msix(q_vector); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1348 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1349 | ixgbe_irq_enable_queues(adapter, |
| 1350 | ((u64)1 << q_vector->v_idx)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | return work_done; |
| 1354 | } |
| 1355 | |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1356 | /** |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1357 | * ixgbe_clean_rxtx_many - msix (aka one shot) rx clean routine |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1358 | * @napi: napi struct with our devices info in it |
| 1359 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1360 | * |
| 1361 | * This function will clean more than one rx queue associated with a |
| 1362 | * q_vector. |
| 1363 | **/ |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1364 | static int ixgbe_clean_rxtx_many(struct napi_struct *napi, int budget) |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1365 | { |
| 1366 | struct ixgbe_q_vector *q_vector = |
| 1367 | container_of(napi, struct ixgbe_q_vector, napi); |
| 1368 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1369 | struct ixgbe_ring *ring = NULL; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1370 | int work_done = 0, i; |
| 1371 | long r_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1372 | bool tx_clean_complete = true; |
| 1373 | |
| 1374 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1375 | for (i = 0; i < q_vector->txr_count; i++) { |
| 1376 | ring = &(adapter->tx_ring[r_idx]); |
| 1377 | #ifdef CONFIG_IXGBE_DCA |
| 1378 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1379 | ixgbe_update_tx_dca(adapter, ring); |
| 1380 | #endif |
| 1381 | tx_clean_complete &= ixgbe_clean_tx_irq(q_vector, ring); |
| 1382 | r_idx = find_next_bit(q_vector->txr_idx, adapter->num_tx_queues, |
| 1383 | r_idx + 1); |
| 1384 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1385 | |
| 1386 | /* attempt to distribute budget to each queue fairly, but don't allow |
| 1387 | * the budget to go below 1 because we'll exit polling */ |
| 1388 | budget /= (q_vector->rxr_count ?: 1); |
| 1389 | budget = max(budget, 1); |
| 1390 | r_idx = find_first_bit(q_vector->rxr_idx, adapter->num_rx_queues); |
| 1391 | for (i = 0; i < q_vector->rxr_count; i++) { |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1392 | ring = &(adapter->rx_ring[r_idx]); |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 1393 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1394 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1395 | ixgbe_update_rx_dca(adapter, ring); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1396 | #endif |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1397 | ixgbe_clean_rx_irq(q_vector, ring, &work_done, budget); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1398 | r_idx = find_next_bit(q_vector->rxr_idx, adapter->num_rx_queues, |
| 1399 | r_idx + 1); |
| 1400 | } |
| 1401 | |
| 1402 | 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] | 1403 | ring = &(adapter->rx_ring[r_idx]); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1404 | /* If all Rx work done, exit the polling mode */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 1405 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 1406 | napi_complete(napi); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1407 | if (adapter->itr_setting & 1) |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1408 | ixgbe_set_itr_msix(q_vector); |
| 1409 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1410 | ixgbe_irq_enable_queues(adapter, |
| 1411 | ((u64)1 << q_vector->v_idx)); |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 1412 | return 0; |
| 1413 | } |
| 1414 | |
| 1415 | return work_done; |
| 1416 | } |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 1417 | |
| 1418 | /** |
| 1419 | * ixgbe_clean_txonly - msix (aka one shot) tx clean routine |
| 1420 | * @napi: napi struct with our devices info in it |
| 1421 | * @budget: amount of work driver is allowed to do this pass, in packets |
| 1422 | * |
| 1423 | * This function is optimized for cleaning one queue only on a single |
| 1424 | * q_vector!!! |
| 1425 | **/ |
| 1426 | static int ixgbe_clean_txonly(struct napi_struct *napi, int budget) |
| 1427 | { |
| 1428 | struct ixgbe_q_vector *q_vector = |
| 1429 | container_of(napi, struct ixgbe_q_vector, napi); |
| 1430 | struct ixgbe_adapter *adapter = q_vector->adapter; |
| 1431 | struct ixgbe_ring *tx_ring = NULL; |
| 1432 | int work_done = 0; |
| 1433 | long r_idx; |
| 1434 | |
| 1435 | r_idx = find_first_bit(q_vector->txr_idx, adapter->num_tx_queues); |
| 1436 | tx_ring = &(adapter->tx_ring[r_idx]); |
| 1437 | #ifdef CONFIG_IXGBE_DCA |
| 1438 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) |
| 1439 | ixgbe_update_tx_dca(adapter, tx_ring); |
| 1440 | #endif |
| 1441 | |
| 1442 | if (!ixgbe_clean_tx_irq(q_vector, tx_ring)) |
| 1443 | work_done = budget; |
| 1444 | |
| 1445 | /* If all Rx work done, exit the polling mode */ |
| 1446 | if (work_done < budget) { |
| 1447 | napi_complete(napi); |
| 1448 | if (adapter->itr_setting & 1) |
| 1449 | ixgbe_set_itr_msix(q_vector); |
| 1450 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 1451 | ixgbe_irq_enable_queues(adapter, ((u64)1 << q_vector->v_idx)); |
| 1452 | } |
| 1453 | |
| 1454 | return work_done; |
| 1455 | } |
| 1456 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1457 | 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] | 1458 | int r_idx) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1459 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1460 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
| 1461 | |
| 1462 | set_bit(r_idx, q_vector->rxr_idx); |
| 1463 | q_vector->rxr_count++; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1464 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1465 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1466 | 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] | 1467 | int t_idx) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1468 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1469 | struct ixgbe_q_vector *q_vector = a->q_vector[v_idx]; |
| 1470 | |
| 1471 | set_bit(t_idx, q_vector->txr_idx); |
| 1472 | q_vector->txr_count++; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1473 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1474 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1475 | /** |
| 1476 | * ixgbe_map_rings_to_vectors - Maps descriptor rings to vectors |
| 1477 | * @adapter: board private structure to initialize |
| 1478 | * @vectors: allotted vector count for descriptor rings |
| 1479 | * |
| 1480 | * This function maps descriptor rings to the queue-specific vectors |
| 1481 | * we were allotted through the MSI-X enabling code. Ideally, we'd have |
| 1482 | * one vector per ring/queue, but on a constrained vector budget, we |
| 1483 | * group the rings as "efficiently" as possible. You would add new |
| 1484 | * mapping configurations in here. |
| 1485 | **/ |
| 1486 | static int ixgbe_map_rings_to_vectors(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1487 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1488 | { |
| 1489 | int v_start = 0; |
| 1490 | int rxr_idx = 0, txr_idx = 0; |
| 1491 | int rxr_remaining = adapter->num_rx_queues; |
| 1492 | int txr_remaining = adapter->num_tx_queues; |
| 1493 | int i, j; |
| 1494 | int rqpv, tqpv; |
| 1495 | int err = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1496 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1497 | /* No mapping required if MSI-X is disabled. */ |
| 1498 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1499 | goto out; |
| 1500 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1501 | /* |
| 1502 | * The ideal configuration... |
| 1503 | * We have enough vectors to map one per queue. |
| 1504 | */ |
| 1505 | if (vectors == adapter->num_rx_queues + adapter->num_tx_queues) { |
| 1506 | for (; rxr_idx < rxr_remaining; v_start++, rxr_idx++) |
| 1507 | map_vector_to_rxq(adapter, v_start, rxr_idx); |
| 1508 | |
| 1509 | for (; txr_idx < txr_remaining; v_start++, txr_idx++) |
| 1510 | map_vector_to_txq(adapter, v_start, txr_idx); |
| 1511 | |
| 1512 | goto out; |
| 1513 | } |
| 1514 | |
| 1515 | /* |
| 1516 | * If we don't have enough vectors for a 1-to-1 |
| 1517 | * mapping, we'll have to group them so there are |
| 1518 | * multiple queues per vector. |
| 1519 | */ |
| 1520 | /* Re-adjusting *qpv takes care of the remainder. */ |
| 1521 | for (i = v_start; i < vectors; i++) { |
| 1522 | rqpv = DIV_ROUND_UP(rxr_remaining, vectors - i); |
| 1523 | for (j = 0; j < rqpv; j++) { |
| 1524 | map_vector_to_rxq(adapter, i, rxr_idx); |
| 1525 | rxr_idx++; |
| 1526 | rxr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1527 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1528 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1529 | for (i = v_start; i < vectors; i++) { |
| 1530 | tqpv = DIV_ROUND_UP(txr_remaining, vectors - i); |
| 1531 | for (j = 0; j < tqpv; j++) { |
| 1532 | map_vector_to_txq(adapter, i, txr_idx); |
| 1533 | txr_idx++; |
| 1534 | txr_remaining--; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1535 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1536 | } |
| 1537 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1538 | out: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1539 | return err; |
| 1540 | } |
| 1541 | |
| 1542 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1543 | * ixgbe_request_msix_irqs - Initialize MSI-X interrupts |
| 1544 | * @adapter: board private structure |
| 1545 | * |
| 1546 | * ixgbe_request_msix_irqs allocates MSI-X vectors and requests |
| 1547 | * interrupts from the kernel. |
| 1548 | **/ |
| 1549 | static int ixgbe_request_msix_irqs(struct ixgbe_adapter *adapter) |
| 1550 | { |
| 1551 | struct net_device *netdev = adapter->netdev; |
| 1552 | irqreturn_t (*handler)(int, void *); |
| 1553 | int i, vector, q_vectors, err; |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 1554 | int ri=0, ti=0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1555 | |
| 1556 | /* Decrement for Other and TCP Timer vectors */ |
| 1557 | q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1558 | |
| 1559 | /* Map the Tx/Rx rings to the vectors we were allotted. */ |
| 1560 | err = ixgbe_map_rings_to_vectors(adapter, q_vectors); |
| 1561 | if (err) |
| 1562 | goto out; |
| 1563 | |
| 1564 | #define SET_HANDLER(_v) ((!(_v)->rxr_count) ? &ixgbe_msix_clean_tx : \ |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1565 | (!(_v)->txr_count) ? &ixgbe_msix_clean_rx : \ |
| 1566 | &ixgbe_msix_clean_many) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1567 | for (vector = 0; vector < q_vectors; vector++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1568 | handler = SET_HANDLER(adapter->q_vector[vector]); |
Robert Olsson | cb13fc2 | 2008-11-25 16:43:52 -0800 | [diff] [blame] | 1569 | |
| 1570 | if(handler == &ixgbe_msix_clean_rx) { |
| 1571 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1572 | netdev->name, "rx", ri++); |
| 1573 | } |
| 1574 | else if(handler == &ixgbe_msix_clean_tx) { |
| 1575 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1576 | netdev->name, "tx", ti++); |
| 1577 | } |
| 1578 | else |
| 1579 | sprintf(adapter->name[vector], "%s-%s-%d", |
| 1580 | netdev->name, "TxRx", vector); |
| 1581 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1582 | err = request_irq(adapter->msix_entries[vector].vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1583 | handler, 0, adapter->name[vector], |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1584 | adapter->q_vector[vector]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1585 | if (err) { |
| 1586 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1587 | "request_irq failed for MSIX interrupt " |
| 1588 | "Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1589 | goto free_queue_irqs; |
| 1590 | } |
| 1591 | } |
| 1592 | |
| 1593 | sprintf(adapter->name[vector], "%s:lsc", netdev->name); |
| 1594 | err = request_irq(adapter->msix_entries[vector].vector, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1595 | &ixgbe_msix_lsc, 0, adapter->name[vector], netdev); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1596 | if (err) { |
| 1597 | DPRINTK(PROBE, ERR, |
| 1598 | "request_irq for msix_lsc failed: %d\n", err); |
| 1599 | goto free_queue_irqs; |
| 1600 | } |
| 1601 | |
| 1602 | return 0; |
| 1603 | |
| 1604 | free_queue_irqs: |
| 1605 | for (i = vector - 1; i >= 0; i--) |
| 1606 | free_irq(adapter->msix_entries[--vector].vector, |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1607 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1608 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 1609 | pci_disable_msix(adapter->pdev); |
| 1610 | kfree(adapter->msix_entries); |
| 1611 | adapter->msix_entries = NULL; |
| 1612 | out: |
| 1613 | return err; |
| 1614 | } |
| 1615 | |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1616 | static void ixgbe_set_itr(struct ixgbe_adapter *adapter) |
| 1617 | { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1618 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1619 | u8 current_itr; |
| 1620 | u32 new_itr = q_vector->eitr; |
| 1621 | struct ixgbe_ring *rx_ring = &adapter->rx_ring[0]; |
| 1622 | struct ixgbe_ring *tx_ring = &adapter->tx_ring[0]; |
| 1623 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1624 | q_vector->tx_itr = ixgbe_update_itr(adapter, new_itr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1625 | q_vector->tx_itr, |
| 1626 | tx_ring->total_packets, |
| 1627 | tx_ring->total_bytes); |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1628 | q_vector->rx_itr = ixgbe_update_itr(adapter, new_itr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1629 | q_vector->rx_itr, |
| 1630 | rx_ring->total_packets, |
| 1631 | rx_ring->total_bytes); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1632 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1633 | current_itr = max(q_vector->rx_itr, q_vector->tx_itr); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1634 | |
| 1635 | switch (current_itr) { |
| 1636 | /* counts and packets in update_itr are dependent on these numbers */ |
| 1637 | case lowest_latency: |
| 1638 | new_itr = 100000; |
| 1639 | break; |
| 1640 | case low_latency: |
| 1641 | new_itr = 20000; /* aka hwitr = ~200 */ |
| 1642 | break; |
| 1643 | case bulk_latency: |
| 1644 | new_itr = 8000; |
| 1645 | break; |
| 1646 | default: |
| 1647 | break; |
| 1648 | } |
| 1649 | |
| 1650 | if (new_itr != q_vector->eitr) { |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1651 | /* do an exponential smoothing */ |
| 1652 | new_itr = ((q_vector->eitr * 90)/100) + ((new_itr * 10)/100); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 1653 | |
| 1654 | /* save the algorithm value here, not the smoothed one */ |
| 1655 | q_vector->eitr = new_itr; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 1656 | |
| 1657 | ixgbe_write_eitr(q_vector); |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1658 | } |
| 1659 | |
| 1660 | return; |
| 1661 | } |
| 1662 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1663 | /** |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1664 | * ixgbe_irq_enable - Enable default interrupt generation settings |
| 1665 | * @adapter: board private structure |
| 1666 | **/ |
| 1667 | static inline void ixgbe_irq_enable(struct ixgbe_adapter *adapter) |
| 1668 | { |
| 1669 | u32 mask; |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1670 | |
| 1671 | mask = (IXGBE_EIMS_ENABLE_MASK & ~IXGBE_EIMS_RTX_QUEUE); |
David S. Miller | 6ab33d5 | 2008-11-20 16:44:00 -0800 | [diff] [blame] | 1672 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) |
| 1673 | mask |= IXGBE_EIMS_GPI_SDP1; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1674 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 1675 | mask |= IXGBE_EIMS_ECC; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1676 | mask |= IXGBE_EIMS_GPI_SDP1; |
| 1677 | mask |= IXGBE_EIMS_GPI_SDP2; |
| 1678 | } |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 1679 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 1680 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 1681 | mask |= IXGBE_EIMS_FLOW_DIR; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1682 | |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1683 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMS, mask); |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1684 | ixgbe_irq_enable_queues(adapter, ~0); |
Alexey Dobriyan | 79aefa4 | 2008-11-19 14:17:02 -0800 | [diff] [blame] | 1685 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 1686 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1687 | |
| 1688 | /** |
| 1689 | * ixgbe_intr - legacy mode Interrupt Handler |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1690 | * @irq: interrupt number |
| 1691 | * @data: pointer to a network interface device structure |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1692 | **/ |
| 1693 | static irqreturn_t ixgbe_intr(int irq, void *data) |
| 1694 | { |
| 1695 | struct net_device *netdev = data; |
| 1696 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 1697 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1698 | struct ixgbe_q_vector *q_vector = adapter->q_vector[0]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1699 | u32 eicr; |
| 1700 | |
Don Skidmore | 5403750 | 2009-02-21 15:42:56 -0800 | [diff] [blame] | 1701 | /* |
| 1702 | * Workaround for silicon errata. Mask the interrupts |
| 1703 | * before the read of EICR. |
| 1704 | */ |
| 1705 | IXGBE_WRITE_REG(hw, IXGBE_EIMC, IXGBE_IRQ_CLEAR_MASK); |
| 1706 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1707 | /* for NAPI, using EIAM to auto-mask tx/rx interrupt bits on read |
| 1708 | * therefore no explict interrupt disable is necessary */ |
| 1709 | eicr = IXGBE_READ_REG(hw, IXGBE_EICR); |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 1710 | if (!eicr) { |
| 1711 | /* shared interrupt alert! |
| 1712 | * make sure interrupts are enabled because the read will |
| 1713 | * have disabled interrupts due to EIAM */ |
| 1714 | ixgbe_irq_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1715 | return IRQ_NONE; /* Not our interrupt */ |
Jesse Brandeburg | f47cf66 | 2008-09-11 19:56:14 -0700 | [diff] [blame] | 1716 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1717 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 1718 | if (eicr & IXGBE_EICR_LSC) |
| 1719 | ixgbe_check_lsc(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1720 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1721 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 1722 | ixgbe_check_sfp_event(adapter, eicr); |
| 1723 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 1724 | ixgbe_check_fan_failure(adapter, eicr); |
| 1725 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1726 | if (napi_schedule_prep(&(q_vector->napi))) { |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 1727 | adapter->tx_ring[0].total_packets = 0; |
| 1728 | adapter->tx_ring[0].total_bytes = 0; |
| 1729 | adapter->rx_ring[0].total_packets = 0; |
| 1730 | adapter->rx_ring[0].total_bytes = 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1731 | /* would disable interrupts here but EIAM disabled it */ |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1732 | __napi_schedule(&(q_vector->napi)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1733 | } |
| 1734 | |
| 1735 | return IRQ_HANDLED; |
| 1736 | } |
| 1737 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1738 | static inline void ixgbe_reset_q_vectors(struct ixgbe_adapter *adapter) |
| 1739 | { |
| 1740 | int i, q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 1741 | |
| 1742 | for (i = 0; i < q_vectors; i++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1743 | struct ixgbe_q_vector *q_vector = adapter->q_vector[i]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1744 | bitmap_zero(q_vector->rxr_idx, MAX_RX_QUEUES); |
| 1745 | bitmap_zero(q_vector->txr_idx, MAX_TX_QUEUES); |
| 1746 | q_vector->rxr_count = 0; |
| 1747 | q_vector->txr_count = 0; |
| 1748 | } |
| 1749 | } |
| 1750 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1751 | /** |
| 1752 | * ixgbe_request_irq - initialize interrupts |
| 1753 | * @adapter: board private structure |
| 1754 | * |
| 1755 | * Attempts to configure interrupts using the best available |
| 1756 | * capabilities of the hardware and kernel. |
| 1757 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1758 | static int ixgbe_request_irq(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1759 | { |
| 1760 | struct net_device *netdev = adapter->netdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1761 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1762 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1763 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 1764 | err = ixgbe_request_msix_irqs(adapter); |
| 1765 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 1766 | err = request_irq(adapter->pdev->irq, &ixgbe_intr, 0, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1767 | netdev->name, netdev); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1768 | } else { |
| 1769 | err = request_irq(adapter->pdev->irq, &ixgbe_intr, IRQF_SHARED, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 1770 | netdev->name, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1771 | } |
| 1772 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1773 | if (err) |
| 1774 | DPRINTK(PROBE, ERR, "request_irq failed, Error %d\n", err); |
| 1775 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1776 | return err; |
| 1777 | } |
| 1778 | |
| 1779 | static void ixgbe_free_irq(struct ixgbe_adapter *adapter) |
| 1780 | { |
| 1781 | struct net_device *netdev = adapter->netdev; |
| 1782 | |
| 1783 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1784 | int i, q_vectors; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1785 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1786 | q_vectors = adapter->num_msix_vectors; |
| 1787 | |
| 1788 | i = q_vectors - 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1789 | free_irq(adapter->msix_entries[i].vector, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1790 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1791 | i--; |
| 1792 | for (; i >= 0; i--) { |
| 1793 | free_irq(adapter->msix_entries[i].vector, |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 1794 | adapter->q_vector[i]); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1795 | } |
| 1796 | |
| 1797 | ixgbe_reset_q_vectors(adapter); |
| 1798 | } else { |
| 1799 | free_irq(adapter->pdev->irq, netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1800 | } |
| 1801 | } |
| 1802 | |
| 1803 | /** |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1804 | * ixgbe_irq_disable - Mask off interrupt generation on the NIC |
| 1805 | * @adapter: board private structure |
| 1806 | **/ |
| 1807 | static inline void ixgbe_irq_disable(struct ixgbe_adapter *adapter) |
| 1808 | { |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 1809 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 1810 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, ~0); |
| 1811 | } else { |
| 1812 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC, 0xFFFF0000); |
| 1813 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(0), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1814 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_EIMC_EX(1), ~0); |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1815 | } |
| 1816 | IXGBE_WRITE_FLUSH(&adapter->hw); |
| 1817 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 1818 | int i; |
| 1819 | for (i = 0; i < adapter->num_msix_vectors; i++) |
| 1820 | synchronize_irq(adapter->msix_entries[i].vector); |
| 1821 | } else { |
| 1822 | synchronize_irq(adapter->pdev->irq); |
| 1823 | } |
| 1824 | } |
| 1825 | |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 1826 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1827 | * ixgbe_configure_msi_and_legacy - Initialize PIN (INTA...) and MSI interrupts |
| 1828 | * |
| 1829 | **/ |
| 1830 | static void ixgbe_configure_msi_and_legacy(struct ixgbe_adapter *adapter) |
| 1831 | { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1832 | struct ixgbe_hw *hw = &adapter->hw; |
| 1833 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1834 | IXGBE_WRITE_REG(hw, IXGBE_EITR(0), |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 1835 | EITR_INTS_PER_SEC_TO_REG(adapter->eitr_param)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1836 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1837 | ixgbe_set_ivar(adapter, 0, 0, 0); |
| 1838 | ixgbe_set_ivar(adapter, 1, 0, 0); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1839 | |
| 1840 | map_vector_to_rxq(adapter, 0, 0); |
| 1841 | map_vector_to_txq(adapter, 0, 0); |
| 1842 | |
| 1843 | DPRINTK(HW, INFO, "Legacy interrupt IVAR setup done\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1844 | } |
| 1845 | |
| 1846 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1847 | * ixgbe_configure_tx - Configure 8259x Transmit Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1848 | * @adapter: board private structure |
| 1849 | * |
| 1850 | * Configure the Tx unit of the MAC after a reset. |
| 1851 | **/ |
| 1852 | static void ixgbe_configure_tx(struct ixgbe_adapter *adapter) |
| 1853 | { |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 1854 | u64 tdba; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1855 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1856 | u32 i, j, tdlen, txctrl; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1857 | |
| 1858 | /* Setup the HW Tx Head and Tail descriptor pointers */ |
| 1859 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1860 | struct ixgbe_ring *ring = &adapter->tx_ring[i]; |
| 1861 | j = ring->reg_idx; |
| 1862 | tdba = ring->dma; |
| 1863 | tdlen = ring->count * sizeof(union ixgbe_adv_tx_desc); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1864 | IXGBE_WRITE_REG(hw, IXGBE_TDBAL(j), |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 1865 | (tdba & DMA_BIT_MASK(32))); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1866 | IXGBE_WRITE_REG(hw, IXGBE_TDBAH(j), (tdba >> 32)); |
| 1867 | IXGBE_WRITE_REG(hw, IXGBE_TDLEN(j), tdlen); |
| 1868 | IXGBE_WRITE_REG(hw, IXGBE_TDH(j), 0); |
| 1869 | IXGBE_WRITE_REG(hw, IXGBE_TDT(j), 0); |
| 1870 | adapter->tx_ring[i].head = IXGBE_TDH(j); |
| 1871 | adapter->tx_ring[i].tail = IXGBE_TDT(j); |
| 1872 | /* Disable Tx Head Writeback RO bit, since this hoses |
| 1873 | * bookkeeping if things aren't delivered in order. |
| 1874 | */ |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1875 | txctrl = IXGBE_READ_REG(hw, IXGBE_DCA_TXCTRL(j)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1876 | txctrl &= ~IXGBE_DCA_TXCTRL_TX_WB_RO_EN; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 1877 | IXGBE_WRITE_REG(hw, IXGBE_DCA_TXCTRL(j), txctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1878 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1879 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 1880 | /* We enable 8 traffic classes, DCB only */ |
| 1881 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 1882 | IXGBE_WRITE_REG(hw, IXGBE_MTQC, (IXGBE_MTQC_RT_ENA | |
| 1883 | IXGBE_MTQC_8TC_8TQ)); |
| 1884 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1885 | } |
| 1886 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1887 | #define IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT 2 |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1888 | |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1889 | static void ixgbe_configure_srrctl(struct ixgbe_adapter *adapter, int index) |
| 1890 | { |
| 1891 | struct ixgbe_ring *rx_ring; |
| 1892 | u32 srrctl; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1893 | int queue0 = 0; |
Alexander Duyck | 3be1adf | 2008-08-30 00:29:10 -0700 | [diff] [blame] | 1894 | unsigned long mask; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 1895 | struct ixgbe_ring_feature *feature = adapter->ring_feature; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1896 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1897 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
Alexander Duyck | 163de42 | 2009-05-07 10:39:16 +0000 | [diff] [blame] | 1898 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 1899 | int dcb_i = feature[RING_F_DCB].indices; |
Alexander Duyck | 163de42 | 2009-05-07 10:39:16 +0000 | [diff] [blame] | 1900 | if (dcb_i == 8) |
| 1901 | queue0 = index >> 4; |
| 1902 | else if (dcb_i == 4) |
| 1903 | queue0 = index >> 5; |
| 1904 | else |
| 1905 | dev_err(&adapter->pdev->dev, "Invalid DCB " |
| 1906 | "configuration\n"); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 1907 | #ifdef IXGBE_FCOE |
| 1908 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 1909 | struct ixgbe_ring_feature *f; |
| 1910 | |
| 1911 | rx_ring = &adapter->rx_ring[queue0]; |
| 1912 | f = &adapter->ring_feature[RING_F_FCOE]; |
| 1913 | if ((queue0 == 0) && (index > rx_ring->reg_idx)) |
| 1914 | queue0 = f->mask + index - |
| 1915 | rx_ring->reg_idx - 1; |
| 1916 | } |
| 1917 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | 163de42 | 2009-05-07 10:39:16 +0000 | [diff] [blame] | 1918 | } else { |
| 1919 | queue0 = index; |
| 1920 | } |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1921 | } else { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 1922 | mask = (unsigned long) feature[RING_F_RSS].mask; |
Alexander Duyck | 3be1adf | 2008-08-30 00:29:10 -0700 | [diff] [blame] | 1923 | queue0 = index & mask; |
| 1924 | index = index & mask; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1925 | } |
Alexander Duyck | 3be1adf | 2008-08-30 00:29:10 -0700 | [diff] [blame] | 1926 | |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1927 | rx_ring = &adapter->rx_ring[queue0]; |
| 1928 | |
| 1929 | srrctl = IXGBE_READ_REG(&adapter->hw, IXGBE_SRRCTL(index)); |
| 1930 | |
| 1931 | srrctl &= ~IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 1932 | srrctl &= ~IXGBE_SRRCTL_BSIZEPKT_MASK; |
| 1933 | |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 1934 | srrctl |= (IXGBE_RX_HDR_SIZE << IXGBE_SRRCTL_BSIZEHDRSIZE_SHIFT) & |
| 1935 | IXGBE_SRRCTL_BSIZEHDR_MASK; |
| 1936 | |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1937 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 1938 | #if (PAGE_SIZE / 2) > IXGBE_MAX_RXBUFFER |
| 1939 | srrctl |= IXGBE_MAX_RXBUFFER >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 1940 | #else |
| 1941 | srrctl |= (PAGE_SIZE / 2) >> IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
| 1942 | #endif |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1943 | srrctl |= IXGBE_SRRCTL_DESCTYPE_HDR_SPLIT_ALWAYS; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1944 | } else { |
Alexander Duyck | afafd5b | 2009-05-07 10:38:56 +0000 | [diff] [blame] | 1945 | srrctl |= ALIGN(rx_ring->rx_buf_len, 1024) >> |
| 1946 | IXGBE_SRRCTL_BSIZEPKT_SHIFT; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1947 | srrctl |= IXGBE_SRRCTL_DESCTYPE_ADV_ONEBUF; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1948 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 1949 | |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 1950 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_SRRCTL(index), srrctl); |
| 1951 | } |
| 1952 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 1953 | static u32 ixgbe_setup_mrqc(struct ixgbe_adapter *adapter) |
| 1954 | { |
| 1955 | u32 mrqc = 0; |
| 1956 | int mask; |
| 1957 | |
| 1958 | if (!(adapter->hw.mac.type == ixgbe_mac_82599EB)) |
| 1959 | return mrqc; |
| 1960 | |
| 1961 | mask = adapter->flags & (IXGBE_FLAG_RSS_ENABLED |
| 1962 | #ifdef CONFIG_IXGBE_DCB |
| 1963 | | IXGBE_FLAG_DCB_ENABLED |
| 1964 | #endif |
| 1965 | ); |
| 1966 | |
| 1967 | switch (mask) { |
| 1968 | case (IXGBE_FLAG_RSS_ENABLED): |
| 1969 | mrqc = IXGBE_MRQC_RSSEN; |
| 1970 | break; |
| 1971 | #ifdef CONFIG_IXGBE_DCB |
| 1972 | case (IXGBE_FLAG_DCB_ENABLED): |
| 1973 | mrqc = IXGBE_MRQC_RT8TCEN; |
| 1974 | break; |
| 1975 | #endif /* CONFIG_IXGBE_DCB */ |
| 1976 | default: |
| 1977 | break; |
| 1978 | } |
| 1979 | |
| 1980 | return mrqc; |
| 1981 | } |
| 1982 | |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 1983 | /** |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 1984 | * ixgbe_configure_rx - Configure 8259x Receive Unit after Reset |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1985 | * @adapter: board private structure |
| 1986 | * |
| 1987 | * Configure the Rx unit of the MAC after a reset. |
| 1988 | **/ |
| 1989 | static void ixgbe_configure_rx(struct ixgbe_adapter *adapter) |
| 1990 | { |
| 1991 | u64 rdba; |
| 1992 | struct ixgbe_hw *hw = &adapter->hw; |
| 1993 | struct net_device *netdev = adapter->netdev; |
| 1994 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 1995 | int i, j; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 1996 | u32 rdlen, rxctrl, rxcsum; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 1997 | static const u32 seed[10] = { 0xE291D73D, 0x1805EC6C, 0x2A94B30D, |
| 1998 | 0xA54F2BEC, 0xEA49AF7C, 0xE214AD3D, 0xB855AABE, |
| 1999 | 0x6A3E67EA, 0x14364D17, 0x3BED200D}; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2000 | u32 fctrl, hlreg0; |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2001 | u32 reta = 0, mrqc = 0; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2002 | u32 rdrxctl; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2003 | u32 rscctrl; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2004 | int rx_buf_len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2005 | |
| 2006 | /* Decide whether to use packet split mode or not */ |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 2007 | adapter->flags |= IXGBE_FLAG_RX_PS_ENABLED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2008 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 2009 | #ifdef IXGBE_FCOE |
| 2010 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 2011 | adapter->flags &= ~IXGBE_FLAG_RX_PS_ENABLED; |
| 2012 | #endif /* IXGBE_FCOE */ |
| 2013 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2014 | /* Set the RX buffer length according to the mode */ |
| 2015 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2016 | rx_buf_len = IXGBE_RX_HDR_SIZE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2017 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2018 | /* PSRTYPE must be initialized in 82599 */ |
| 2019 | u32 psrtype = IXGBE_PSRTYPE_TCPHDR | |
| 2020 | IXGBE_PSRTYPE_UDPHDR | |
| 2021 | IXGBE_PSRTYPE_IPV4HDR | |
Yi Zou | dfa12f0 | 2009-05-07 10:39:35 +0000 | [diff] [blame] | 2022 | IXGBE_PSRTYPE_IPV6HDR | |
| 2023 | IXGBE_PSRTYPE_L2HDR; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2024 | IXGBE_WRITE_REG(hw, IXGBE_PSRTYPE(0), psrtype); |
| 2025 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2026 | } else { |
Peter P Waskiewicz Jr | df647b5 | 2009-06-04 16:00:47 +0000 | [diff] [blame] | 2027 | if (!(adapter->flags & IXGBE_FLAG2_RSC_ENABLED) && |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2028 | (netdev->mtu <= ETH_DATA_LEN)) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2029 | rx_buf_len = MAXIMUM_ETHERNET_VLAN_SIZE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2030 | else |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2031 | rx_buf_len = ALIGN(max_frame, 1024); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2032 | } |
| 2033 | |
| 2034 | fctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_FCTRL); |
| 2035 | fctrl |= IXGBE_FCTRL_BAM; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2036 | fctrl |= IXGBE_FCTRL_DPF; /* discard pause frames when FC enabled */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2037 | fctrl |= IXGBE_FCTRL_PMCF; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2038 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_FCTRL, fctrl); |
| 2039 | |
| 2040 | hlreg0 = IXGBE_READ_REG(hw, IXGBE_HLREG0); |
| 2041 | if (adapter->netdev->mtu <= ETH_DATA_LEN) |
| 2042 | hlreg0 &= ~IXGBE_HLREG0_JUMBOEN; |
| 2043 | else |
| 2044 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2045 | #ifdef IXGBE_FCOE |
| 2046 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 2047 | hlreg0 |= IXGBE_HLREG0_JUMBOEN; |
| 2048 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2049 | IXGBE_WRITE_REG(hw, IXGBE_HLREG0, hlreg0); |
| 2050 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2051 | rdlen = adapter->rx_ring[0].count * sizeof(union ixgbe_adv_rx_desc); |
| 2052 | /* disable receives while setting up the descriptors */ |
| 2053 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 2054 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
| 2055 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2056 | /* |
| 2057 | * Setup the HW Rx Head and Tail Descriptor Pointers and |
| 2058 | * the Base and Length of the Rx Descriptor Ring |
| 2059 | */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2060 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 2061 | rdba = adapter->rx_ring[i].dma; |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2062 | j = adapter->rx_ring[i].reg_idx; |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 2063 | IXGBE_WRITE_REG(hw, IXGBE_RDBAL(j), (rdba & DMA_BIT_MASK(32))); |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2064 | IXGBE_WRITE_REG(hw, IXGBE_RDBAH(j), (rdba >> 32)); |
| 2065 | IXGBE_WRITE_REG(hw, IXGBE_RDLEN(j), rdlen); |
| 2066 | IXGBE_WRITE_REG(hw, IXGBE_RDH(j), 0); |
| 2067 | IXGBE_WRITE_REG(hw, IXGBE_RDT(j), 0); |
| 2068 | adapter->rx_ring[i].head = IXGBE_RDH(j); |
| 2069 | adapter->rx_ring[i].tail = IXGBE_RDT(j); |
| 2070 | adapter->rx_ring[i].rx_buf_len = rx_buf_len; |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2071 | |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2072 | #ifdef IXGBE_FCOE |
| 2073 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 2074 | struct ixgbe_ring_feature *f; |
| 2075 | f = &adapter->ring_feature[RING_F_FCOE]; |
| 2076 | if ((rx_buf_len < IXGBE_FCOE_JUMBO_FRAME_SIZE) && |
| 2077 | (i >= f->mask) && (i < f->mask + f->indices)) |
| 2078 | adapter->rx_ring[i].rx_buf_len = |
| 2079 | IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 2080 | } |
| 2081 | |
| 2082 | #endif /* IXGBE_FCOE */ |
Jesse Brandeburg | cc41ac7 | 2008-08-26 04:27:27 -0700 | [diff] [blame] | 2083 | ixgbe_configure_srrctl(adapter, j); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2084 | } |
| 2085 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2086 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 2087 | /* |
| 2088 | * For VMDq support of different descriptor types or |
| 2089 | * buffer sizes through the use of multiple SRRCTL |
| 2090 | * registers, RDRXCTL.MVMEN must be set to 1 |
| 2091 | * |
| 2092 | * also, the manual doesn't mention it clearly but DCA hints |
| 2093 | * will only use queue 0's tags unless this bit is set. Side |
| 2094 | * effects of setting this bit are only that SRRCTL must be |
| 2095 | * fully programmed [0..15] |
| 2096 | */ |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2097 | rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 2098 | rdrxctl |= IXGBE_RDRXCTL_MVMEN; |
| 2099 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2100 | } |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 2101 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2102 | /* Program MRQC for the distribution of queues */ |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 2103 | mrqc = ixgbe_setup_mrqc(adapter); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2104 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2105 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2106 | /* Fill out redirection table */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2107 | for (i = 0, j = 0; i < 128; i++, j++) { |
| 2108 | if (j == adapter->ring_feature[RING_F_RSS].indices) |
| 2109 | j = 0; |
| 2110 | /* reta = 4-byte sliding window of |
| 2111 | * 0x00..(indices-1)(indices-1)00..etc. */ |
| 2112 | reta = (reta << 8) | (j * 0x11); |
| 2113 | if ((i & 3) == 3) |
| 2114 | IXGBE_WRITE_REG(hw, IXGBE_RETA(i >> 2), reta); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2115 | } |
| 2116 | |
| 2117 | /* Fill out hash function seeds */ |
| 2118 | for (i = 0; i < 10; i++) |
Jesse Brandeburg | 7c6e0a4 | 2008-08-26 04:27:16 -0700 | [diff] [blame] | 2119 | IXGBE_WRITE_REG(hw, IXGBE_RSSRK(i), seed[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2120 | |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2121 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2122 | mrqc |= IXGBE_MRQC_RSSEN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2123 | /* Perform hash on these packet types */ |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2124 | mrqc |= IXGBE_MRQC_RSS_FIELD_IPV4 |
| 2125 | | IXGBE_MRQC_RSS_FIELD_IPV4_TCP |
| 2126 | | IXGBE_MRQC_RSS_FIELD_IPV4_UDP |
| 2127 | | IXGBE_MRQC_RSS_FIELD_IPV6 |
| 2128 | | IXGBE_MRQC_RSS_FIELD_IPV6_TCP |
| 2129 | | IXGBE_MRQC_RSS_FIELD_IPV6_UDP; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2130 | } |
Jesse Brandeburg | 2a41ff8 | 2009-03-13 22:14:30 +0000 | [diff] [blame] | 2131 | IXGBE_WRITE_REG(hw, IXGBE_MRQC, mrqc); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2132 | |
| 2133 | rxcsum = IXGBE_READ_REG(hw, IXGBE_RXCSUM); |
| 2134 | |
| 2135 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED || |
| 2136 | adapter->flags & IXGBE_FLAG_RX_CSUM_ENABLED) { |
| 2137 | /* Disable indicating checksum in descriptor, enables |
| 2138 | * RSS hash */ |
| 2139 | rxcsum |= IXGBE_RXCSUM_PCSD; |
| 2140 | } |
| 2141 | if (!(rxcsum & IXGBE_RXCSUM_PCSD)) { |
| 2142 | /* Enable IPv4 payload checksum for UDP fragments |
| 2143 | * if PCSD is not set */ |
| 2144 | rxcsum |= IXGBE_RXCSUM_IPPCSE; |
| 2145 | } |
| 2146 | |
| 2147 | IXGBE_WRITE_REG(hw, IXGBE_RXCSUM, rxcsum); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2148 | |
| 2149 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2150 | rdrxctl = IXGBE_READ_REG(hw, IXGBE_RDRXCTL); |
| 2151 | rdrxctl |= IXGBE_RDRXCTL_CRCSTRIP; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2152 | rdrxctl &= ~IXGBE_RDRXCTL_RSCFRSTSIZE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2153 | IXGBE_WRITE_REG(hw, IXGBE_RDRXCTL, rdrxctl); |
| 2154 | } |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2155 | |
Peter P Waskiewicz Jr | df647b5 | 2009-06-04 16:00:47 +0000 | [diff] [blame] | 2156 | if (adapter->flags & IXGBE_FLAG2_RSC_ENABLED) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2157 | /* Enable 82599 HW-RSC */ |
| 2158 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 2159 | j = adapter->rx_ring[i].reg_idx; |
| 2160 | rscctrl = IXGBE_READ_REG(hw, IXGBE_RSCCTL(j)); |
| 2161 | rscctrl |= IXGBE_RSCCTL_RSCEN; |
| 2162 | /* |
Alexander Duyck | e76678d | 2009-05-17 20:57:47 +0000 | [diff] [blame] | 2163 | * we must limit the number of descriptors so that the |
| 2164 | * total size of max desc * buf_len is not greater |
| 2165 | * than 65535 |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2166 | */ |
Alexander Duyck | e76678d | 2009-05-17 20:57:47 +0000 | [diff] [blame] | 2167 | if (adapter->flags & IXGBE_FLAG_RX_PS_ENABLED) { |
| 2168 | #if (MAX_SKB_FRAGS > 16) |
| 2169 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2170 | #elif (MAX_SKB_FRAGS > 8) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2171 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
Alexander Duyck | e76678d | 2009-05-17 20:57:47 +0000 | [diff] [blame] | 2172 | #elif (MAX_SKB_FRAGS > 4) |
| 2173 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2174 | #else |
Alexander Duyck | e76678d | 2009-05-17 20:57:47 +0000 | [diff] [blame] | 2175 | rscctrl |= IXGBE_RSCCTL_MAXDESC_1; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2176 | #endif |
Alexander Duyck | e76678d | 2009-05-17 20:57:47 +0000 | [diff] [blame] | 2177 | } else { |
| 2178 | if (rx_buf_len < IXGBE_RXBUFFER_4096) |
| 2179 | rscctrl |= IXGBE_RSCCTL_MAXDESC_16; |
| 2180 | else if (rx_buf_len < IXGBE_RXBUFFER_8192) |
| 2181 | rscctrl |= IXGBE_RSCCTL_MAXDESC_8; |
| 2182 | else |
| 2183 | rscctrl |= IXGBE_RSCCTL_MAXDESC_4; |
| 2184 | } |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2185 | IXGBE_WRITE_REG(hw, IXGBE_RSCCTL(j), rscctrl); |
| 2186 | } |
| 2187 | /* Disable RSC for ACK packets */ |
| 2188 | IXGBE_WRITE_REG(hw, IXGBE_RSCDBU, |
| 2189 | (IXGBE_RSCDBU_RSCACKDIS | IXGBE_READ_REG(hw, IXGBE_RSCDBU))); |
| 2190 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2191 | } |
| 2192 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2193 | static void ixgbe_vlan_rx_add_vid(struct net_device *netdev, u16 vid) |
| 2194 | { |
| 2195 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2196 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2197 | |
| 2198 | /* add VID to filter table */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2199 | hw->mac.ops.set_vfta(&adapter->hw, vid, 0, true); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | static void ixgbe_vlan_rx_kill_vid(struct net_device *netdev, u16 vid) |
| 2203 | { |
| 2204 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2205 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2206 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2207 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2208 | ixgbe_irq_disable(adapter); |
| 2209 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2210 | vlan_group_set_device(adapter->vlgrp, vid, NULL); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2211 | |
| 2212 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2213 | ixgbe_irq_enable(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2214 | |
| 2215 | /* remove VID from filter table */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2216 | hw->mac.ops.set_vfta(&adapter->hw, vid, 0, false); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2217 | } |
| 2218 | |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2219 | static void ixgbe_vlan_rx_register(struct net_device *netdev, |
| 2220 | struct vlan_group *grp) |
| 2221 | { |
| 2222 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2223 | u32 ctrl; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2224 | int i, j; |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2225 | |
| 2226 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2227 | ixgbe_irq_disable(adapter); |
| 2228 | adapter->vlgrp = grp; |
| 2229 | |
| 2230 | /* |
| 2231 | * For a DCB driver, always enable VLAN tag stripping so we can |
| 2232 | * still receive traffic from a DCB-enabled host even if we're |
| 2233 | * not in DCB mode. |
| 2234 | */ |
| 2235 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2236 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
| 2237 | ctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE; |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2238 | ctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2239 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2240 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
| 2241 | ctrl |= IXGBE_VLNCTRL_VFE; |
| 2242 | /* enable VLAN tag insert/strip */ |
| 2243 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_VLNCTRL); |
| 2244 | ctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2245 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_VLNCTRL, ctrl); |
| 2246 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 2247 | j = adapter->rx_ring[i].reg_idx; |
| 2248 | ctrl = IXGBE_READ_REG(&adapter->hw, IXGBE_RXDCTL(j)); |
| 2249 | ctrl |= IXGBE_RXDCTL_VME; |
| 2250 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_RXDCTL(j), ctrl); |
| 2251 | } |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2252 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2253 | ixgbe_vlan_rx_add_vid(netdev, 0); |
Don Skidmore | 068c89b | 2009-01-19 16:54:36 -0800 | [diff] [blame] | 2254 | |
| 2255 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
| 2256 | ixgbe_irq_enable(adapter); |
| 2257 | } |
| 2258 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2259 | static void ixgbe_restore_vlan(struct ixgbe_adapter *adapter) |
| 2260 | { |
| 2261 | ixgbe_vlan_rx_register(adapter->netdev, adapter->vlgrp); |
| 2262 | |
| 2263 | if (adapter->vlgrp) { |
| 2264 | u16 vid; |
| 2265 | for (vid = 0; vid < VLAN_GROUP_ARRAY_LEN; vid++) { |
| 2266 | if (!vlan_group_get_device(adapter->vlgrp, vid)) |
| 2267 | continue; |
| 2268 | ixgbe_vlan_rx_add_vid(adapter->netdev, vid); |
| 2269 | } |
| 2270 | } |
| 2271 | } |
| 2272 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2273 | static u8 *ixgbe_addr_list_itr(struct ixgbe_hw *hw, u8 **mc_addr_ptr, u32 *vmdq) |
| 2274 | { |
| 2275 | struct dev_mc_list *mc_ptr; |
| 2276 | u8 *addr = *mc_addr_ptr; |
| 2277 | *vmdq = 0; |
| 2278 | |
| 2279 | mc_ptr = container_of(addr, struct dev_mc_list, dmi_addr[0]); |
| 2280 | if (mc_ptr->next) |
| 2281 | *mc_addr_ptr = mc_ptr->next->dmi_addr; |
| 2282 | else |
| 2283 | *mc_addr_ptr = NULL; |
| 2284 | |
| 2285 | return addr; |
| 2286 | } |
| 2287 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2288 | /** |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2289 | * ixgbe_set_rx_mode - Unicast, Multicast and Promiscuous mode set |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2290 | * @netdev: network interface device structure |
| 2291 | * |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2292 | * The set_rx_method entry point is called whenever the unicast/multicast |
| 2293 | * address list or the network interface flags are updated. This routine is |
| 2294 | * responsible for configuring the hardware for proper unicast, multicast and |
| 2295 | * promiscuous mode. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2296 | **/ |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2297 | static void ixgbe_set_rx_mode(struct net_device *netdev) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2298 | { |
| 2299 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 2300 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2301 | u32 fctrl, vlnctrl; |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2302 | u8 *addr_list = NULL; |
| 2303 | int addr_count = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2304 | |
| 2305 | /* Check for Promiscuous and All Multicast modes */ |
| 2306 | |
| 2307 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2308 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2309 | |
| 2310 | if (netdev->flags & IFF_PROMISC) { |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2311 | hw->addr_ctrl.user_set_promisc = 1; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2312 | fctrl |= (IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2313 | vlnctrl &= ~IXGBE_VLNCTRL_VFE; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2314 | } else { |
Patrick McHardy | 746b9f0 | 2008-07-16 20:15:45 -0700 | [diff] [blame] | 2315 | if (netdev->flags & IFF_ALLMULTI) { |
| 2316 | fctrl |= IXGBE_FCTRL_MPE; |
| 2317 | fctrl &= ~IXGBE_FCTRL_UPE; |
| 2318 | } else { |
| 2319 | fctrl &= ~(IXGBE_FCTRL_UPE | IXGBE_FCTRL_MPE); |
| 2320 | } |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2321 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2322 | hw->addr_ctrl.user_set_promisc = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2323 | } |
| 2324 | |
| 2325 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
Alexander Duyck | 3d01625 | 2008-08-26 18:30:04 -0700 | [diff] [blame] | 2326 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2327 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2328 | /* reprogram secondary unicast list */ |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 2329 | hw->mac.ops.update_uc_addr_list(hw, &netdev->uc.list); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2330 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2331 | /* reprogram multicast list */ |
| 2332 | addr_count = netdev->mc_count; |
| 2333 | if (addr_count) |
| 2334 | addr_list = netdev->mc_list->dmi_addr; |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2335 | hw->mac.ops.update_mc_addr_list(hw, addr_list, addr_count, |
| 2336 | ixgbe_addr_list_itr); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2337 | } |
| 2338 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2339 | static void ixgbe_napi_enable_all(struct ixgbe_adapter *adapter) |
| 2340 | { |
| 2341 | int q_idx; |
| 2342 | struct ixgbe_q_vector *q_vector; |
| 2343 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2344 | |
| 2345 | /* legacy and MSI only use one vector */ |
| 2346 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 2347 | q_vectors = 1; |
| 2348 | |
| 2349 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2350 | struct napi_struct *napi; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2351 | q_vector = adapter->q_vector[q_idx]; |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2352 | napi = &q_vector->napi; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 2353 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2354 | if (!q_vector->rxr_count || !q_vector->txr_count) { |
| 2355 | if (q_vector->txr_count == 1) |
| 2356 | napi->poll = &ixgbe_clean_txonly; |
| 2357 | else if (q_vector->rxr_count == 1) |
| 2358 | napi->poll = &ixgbe_clean_rxonly; |
| 2359 | } |
| 2360 | } |
Jesse Brandeburg | f084827 | 2008-09-11 19:59:42 -0700 | [diff] [blame] | 2361 | |
| 2362 | napi_enable(napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2363 | } |
| 2364 | } |
| 2365 | |
| 2366 | static void ixgbe_napi_disable_all(struct ixgbe_adapter *adapter) |
| 2367 | { |
| 2368 | int q_idx; |
| 2369 | struct ixgbe_q_vector *q_vector; |
| 2370 | int q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 2371 | |
| 2372 | /* legacy and MSI only use one vector */ |
| 2373 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) |
| 2374 | q_vectors = 1; |
| 2375 | |
| 2376 | for (q_idx = 0; q_idx < q_vectors; q_idx++) { |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 2377 | q_vector = adapter->q_vector[q_idx]; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2378 | napi_disable(&q_vector->napi); |
| 2379 | } |
| 2380 | } |
| 2381 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 2382 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2383 | /* |
| 2384 | * ixgbe_configure_dcb - Configure DCB hardware |
| 2385 | * @adapter: ixgbe adapter struct |
| 2386 | * |
| 2387 | * This is called by the driver on open to configure the DCB hardware. |
| 2388 | * This is also called by the gennetlink interface when reconfiguring |
| 2389 | * the DCB state. |
| 2390 | */ |
| 2391 | static void ixgbe_configure_dcb(struct ixgbe_adapter *adapter) |
| 2392 | { |
| 2393 | struct ixgbe_hw *hw = &adapter->hw; |
| 2394 | u32 txdctl, vlnctrl; |
| 2395 | int i, j; |
| 2396 | |
| 2397 | ixgbe_dcb_check_config(&adapter->dcb_cfg); |
| 2398 | ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_TX_CONFIG); |
| 2399 | ixgbe_dcb_calculate_tc_credits(&adapter->dcb_cfg, DCB_RX_CONFIG); |
| 2400 | |
| 2401 | /* reconfigure the hardware */ |
| 2402 | ixgbe_dcb_hw_config(&adapter->hw, &adapter->dcb_cfg); |
| 2403 | |
| 2404 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2405 | j = adapter->tx_ring[i].reg_idx; |
| 2406 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
| 2407 | /* PThresh workaround for Tx hang with DFP enabled. */ |
| 2408 | txdctl |= 32; |
| 2409 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
| 2410 | } |
| 2411 | /* Enable VLAN tag insert/strip */ |
| 2412 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_VLNCTRL); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2413 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 2414 | vlnctrl |= IXGBE_VLNCTRL_VME | IXGBE_VLNCTRL_VFE; |
| 2415 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2416 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 2417 | } else if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2418 | vlnctrl |= IXGBE_VLNCTRL_VFE; |
| 2419 | vlnctrl &= ~IXGBE_VLNCTRL_CFIEN; |
| 2420 | IXGBE_WRITE_REG(hw, IXGBE_VLNCTRL, vlnctrl); |
| 2421 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 2422 | j = adapter->rx_ring[i].reg_idx; |
| 2423 | vlnctrl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 2424 | vlnctrl |= IXGBE_RXDCTL_VME; |
| 2425 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), vlnctrl); |
| 2426 | } |
| 2427 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2428 | hw->mac.ops.set_vfta(&adapter->hw, 0, 0, true); |
| 2429 | } |
| 2430 | |
| 2431 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2432 | static void ixgbe_configure(struct ixgbe_adapter *adapter) |
| 2433 | { |
| 2434 | struct net_device *netdev = adapter->netdev; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2435 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2436 | int i; |
| 2437 | |
Christopher Leech | 2c5645c | 2008-08-26 04:27:02 -0700 | [diff] [blame] | 2438 | ixgbe_set_rx_mode(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2439 | |
| 2440 | ixgbe_restore_vlan(adapter); |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 2441 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 2442 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 2443 | netif_set_gso_max_size(netdev, 32768); |
| 2444 | ixgbe_configure_dcb(adapter); |
| 2445 | } else { |
| 2446 | netif_set_gso_max_size(netdev, 65536); |
| 2447 | } |
| 2448 | #else |
| 2449 | netif_set_gso_max_size(netdev, 65536); |
| 2450 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2451 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 2452 | #ifdef IXGBE_FCOE |
| 2453 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 2454 | ixgbe_configure_fcoe(adapter); |
| 2455 | |
| 2456 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2457 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) { |
| 2458 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2459 | adapter->tx_ring[i].atr_sample_rate = |
| 2460 | adapter->atr_sample_rate; |
| 2461 | ixgbe_init_fdir_signature_82599(hw, adapter->fdir_pballoc); |
| 2462 | } else if (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) { |
| 2463 | ixgbe_init_fdir_perfect_82599(hw, adapter->fdir_pballoc); |
| 2464 | } |
| 2465 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2466 | ixgbe_configure_tx(adapter); |
| 2467 | ixgbe_configure_rx(adapter); |
| 2468 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 2469 | ixgbe_alloc_rx_buffers(adapter, &adapter->rx_ring[i], |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2470 | (adapter->rx_ring[i].count - 1)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2471 | } |
| 2472 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2473 | static inline bool ixgbe_is_sfp(struct ixgbe_hw *hw) |
| 2474 | { |
| 2475 | switch (hw->phy.type) { |
| 2476 | case ixgbe_phy_sfp_avago: |
| 2477 | case ixgbe_phy_sfp_ftl: |
| 2478 | case ixgbe_phy_sfp_intel: |
| 2479 | case ixgbe_phy_sfp_unknown: |
| 2480 | case ixgbe_phy_tw_tyco: |
| 2481 | case ixgbe_phy_tw_unknown: |
| 2482 | return true; |
| 2483 | default: |
| 2484 | return false; |
| 2485 | } |
| 2486 | } |
| 2487 | |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2488 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2489 | * ixgbe_sfp_link_config - set up SFP+ link |
| 2490 | * @adapter: pointer to private adapter struct |
| 2491 | **/ |
| 2492 | static void ixgbe_sfp_link_config(struct ixgbe_adapter *adapter) |
| 2493 | { |
| 2494 | struct ixgbe_hw *hw = &adapter->hw; |
| 2495 | |
| 2496 | if (hw->phy.multispeed_fiber) { |
| 2497 | /* |
| 2498 | * In multispeed fiber setups, the device may not have |
| 2499 | * had a physical connection when the driver loaded. |
| 2500 | * If that's the case, the initial link configuration |
| 2501 | * couldn't get the MAC into 10G or 1G mode, so we'll |
| 2502 | * never have a link status change interrupt fire. |
| 2503 | * We need to try and force an autonegotiation |
| 2504 | * session, then bring up link. |
| 2505 | */ |
| 2506 | hw->mac.ops.setup_sfp(hw); |
| 2507 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK)) |
| 2508 | schedule_work(&adapter->multispeed_fiber_task); |
| 2509 | } else { |
| 2510 | /* |
| 2511 | * Direct Attach Cu and non-multispeed fiber modules |
| 2512 | * still need to be configured properly prior to |
| 2513 | * attempting link. |
| 2514 | */ |
| 2515 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_MOD_TASK)) |
| 2516 | schedule_work(&adapter->sfp_config_module_task); |
| 2517 | } |
| 2518 | } |
| 2519 | |
| 2520 | /** |
| 2521 | * ixgbe_non_sfp_link_config - set up non-SFP+ link |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2522 | * @hw: pointer to private hardware struct |
| 2523 | * |
| 2524 | * Returns 0 on success, negative on failure |
| 2525 | **/ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2526 | 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] | 2527 | { |
| 2528 | u32 autoneg; |
| 2529 | bool link_up = false; |
| 2530 | u32 ret = IXGBE_ERR_LINK_SETUP; |
| 2531 | |
| 2532 | if (hw->mac.ops.check_link) |
| 2533 | ret = hw->mac.ops.check_link(hw, &autoneg, &link_up, false); |
| 2534 | |
| 2535 | if (ret) |
| 2536 | goto link_cfg_out; |
| 2537 | |
| 2538 | if (hw->mac.ops.get_link_capabilities) |
| 2539 | ret = hw->mac.ops.get_link_capabilities(hw, &autoneg, |
| 2540 | &hw->mac.autoneg); |
| 2541 | if (ret) |
| 2542 | goto link_cfg_out; |
| 2543 | |
| 2544 | if (hw->mac.ops.setup_link_speed) |
| 2545 | 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] | 2546 | link_cfg_out: |
| 2547 | return ret; |
| 2548 | } |
| 2549 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2550 | #define IXGBE_MAX_RX_DESC_POLL 10 |
| 2551 | static inline void ixgbe_rx_desc_queue_enable(struct ixgbe_adapter *adapter, |
| 2552 | int rxr) |
| 2553 | { |
| 2554 | int j = adapter->rx_ring[rxr].reg_idx; |
| 2555 | int k; |
| 2556 | |
| 2557 | for (k = 0; k < IXGBE_MAX_RX_DESC_POLL; k++) { |
| 2558 | if (IXGBE_READ_REG(&adapter->hw, |
| 2559 | IXGBE_RXDCTL(j)) & IXGBE_RXDCTL_ENABLE) |
| 2560 | break; |
| 2561 | else |
| 2562 | msleep(1); |
| 2563 | } |
| 2564 | if (k >= IXGBE_MAX_RX_DESC_POLL) { |
| 2565 | DPRINTK(DRV, ERR, "RXDCTL.ENABLE on Rx queue %d " |
| 2566 | "not set within the polling period\n", rxr); |
| 2567 | } |
| 2568 | ixgbe_release_rx_desc(&adapter->hw, &adapter->rx_ring[rxr], |
| 2569 | (adapter->rx_ring[rxr].count - 1)); |
| 2570 | } |
| 2571 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2572 | static int ixgbe_up_complete(struct ixgbe_adapter *adapter) |
| 2573 | { |
| 2574 | struct net_device *netdev = adapter->netdev; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2575 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2576 | int i, j = 0; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2577 | int num_rx_rings = adapter->num_rx_queues; |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2578 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2579 | int max_frame = netdev->mtu + ETH_HLEN + ETH_FCS_LEN; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2580 | u32 txdctl, rxdctl, mhadd; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2581 | u32 dmatxctl; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2582 | u32 gpie; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2583 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 2584 | ixgbe_get_hw_control(adapter); |
| 2585 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2586 | if ((adapter->flags & IXGBE_FLAG_MSIX_ENABLED) || |
| 2587 | (adapter->flags & IXGBE_FLAG_MSI_ENABLED)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2588 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 2589 | gpie = (IXGBE_GPIE_MSIX_MODE | IXGBE_GPIE_EIAME | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2590 | IXGBE_GPIE_PBA_SUPPORT | IXGBE_GPIE_OCD); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2591 | } else { |
| 2592 | /* MSI only */ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2593 | gpie = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2594 | } |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2595 | /* XXX: to interrupt immediately for EICS writes, enable this */ |
| 2596 | /* gpie |= IXGBE_GPIE_EIMEN; */ |
| 2597 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2598 | } |
| 2599 | |
| 2600 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
| 2601 | /* legacy interrupts, use EIAM to auto-mask when reading EICR, |
| 2602 | * specifically only auto mask tx and rx interrupts */ |
| 2603 | IXGBE_WRITE_REG(hw, IXGBE_EIAM, IXGBE_EICS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2604 | } |
| 2605 | |
Jesse Brandeburg | 0befdb3 | 2008-10-31 00:46:40 -0700 | [diff] [blame] | 2606 | /* Enable fan failure interrupt if media type is copper */ |
| 2607 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 2608 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 2609 | gpie |= IXGBE_SDP1_GPIEN; |
| 2610 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2611 | } |
| 2612 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2613 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2614 | gpie = IXGBE_READ_REG(hw, IXGBE_GPIE); |
| 2615 | gpie |= IXGBE_SDP1_GPIEN; |
| 2616 | gpie |= IXGBE_SDP2_GPIEN; |
| 2617 | IXGBE_WRITE_REG(hw, IXGBE_GPIE, gpie); |
| 2618 | } |
| 2619 | |
Yi Zou | 63f39bd | 2009-05-17 12:34:35 +0000 | [diff] [blame] | 2620 | #ifdef IXGBE_FCOE |
| 2621 | /* adjust max frame to be able to do baby jumbo for FCoE */ |
| 2622 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 2623 | (max_frame < IXGBE_FCOE_JUMBO_FRAME_SIZE)) |
| 2624 | max_frame = IXGBE_FCOE_JUMBO_FRAME_SIZE; |
| 2625 | |
| 2626 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2627 | mhadd = IXGBE_READ_REG(hw, IXGBE_MHADD); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2628 | if (max_frame != (mhadd >> IXGBE_MHADD_MFS_SHIFT)) { |
| 2629 | mhadd &= ~IXGBE_MHADD_MFS_MASK; |
| 2630 | mhadd |= max_frame << IXGBE_MHADD_MFS_SHIFT; |
| 2631 | |
| 2632 | IXGBE_WRITE_REG(hw, IXGBE_MHADD, mhadd); |
| 2633 | } |
| 2634 | |
| 2635 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2636 | j = adapter->tx_ring[i].reg_idx; |
| 2637 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 2638 | /* enable WTHRESH=8 descriptors, to encourage burst writeback */ |
| 2639 | txdctl |= (8 << 16); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2640 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
| 2641 | } |
| 2642 | |
| 2643 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 2644 | /* DMATXCTL.EN must be set after all Tx queue config is done */ |
| 2645 | dmatxctl = IXGBE_READ_REG(hw, IXGBE_DMATXCTL); |
| 2646 | dmatxctl |= IXGBE_DMATXCTL_TE; |
| 2647 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, dmatxctl); |
| 2648 | } |
| 2649 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2650 | j = adapter->tx_ring[i].reg_idx; |
| 2651 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2652 | txdctl |= IXGBE_TXDCTL_ENABLE; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2653 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), txdctl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2654 | } |
| 2655 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2656 | for (i = 0; i < num_rx_rings; i++) { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2657 | j = adapter->rx_ring[i].reg_idx; |
| 2658 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXDCTL(j)); |
| 2659 | /* enable PTHRESH=32 descriptors (half the internal cache) |
| 2660 | * and HTHRESH=0 descriptors (to minimize latency on fetch), |
| 2661 | * this also removes a pesky rx_no_buffer_count increment */ |
| 2662 | rxdctl |= 0x0020; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2663 | rxdctl |= IXGBE_RXDCTL_ENABLE; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2664 | IXGBE_WRITE_REG(hw, IXGBE_RXDCTL(j), rxdctl); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2665 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 2666 | ixgbe_rx_desc_queue_enable(adapter, i); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2667 | } |
| 2668 | /* enable all receives */ |
| 2669 | rxdctl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2670 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 2671 | rxdctl |= (IXGBE_RXCTRL_DMBYPS | IXGBE_RXCTRL_RXEN); |
| 2672 | else |
| 2673 | rxdctl |= IXGBE_RXCTRL_RXEN; |
| 2674 | hw->mac.ops.enable_rx_dma(hw, rxdctl); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2675 | |
| 2676 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 2677 | ixgbe_configure_msix(adapter); |
| 2678 | else |
| 2679 | ixgbe_configure_msi_and_legacy(adapter); |
| 2680 | |
| 2681 | clear_bit(__IXGBE_DOWN, &adapter->state); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2682 | ixgbe_napi_enable_all(adapter); |
| 2683 | |
| 2684 | /* clear any pending interrupts, may auto mask */ |
| 2685 | IXGBE_READ_REG(hw, IXGBE_EICR); |
| 2686 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2687 | ixgbe_irq_enable(adapter); |
| 2688 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2689 | /* |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 2690 | * If this adapter has a fan, check to see if we had a failure |
| 2691 | * before we enabled the interrupt. |
| 2692 | */ |
| 2693 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 2694 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 2695 | if (esdp & IXGBE_ESDP_SDP1) |
| 2696 | DPRINTK(DRV, CRIT, |
| 2697 | "Fan has stopped, replace the adapter\n"); |
| 2698 | } |
| 2699 | |
| 2700 | /* |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2701 | * For hot-pluggable SFP+ devices, a new SFP+ module may have |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2702 | * arrived before interrupts were enabled but after probe. Such |
| 2703 | * devices wouldn't have their type identified yet. We need to |
| 2704 | * kick off the SFP+ module setup first, then try to bring up link. |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2705 | * If we're not hot-pluggable SFP+, we just need to configure link |
| 2706 | * and bring it up. |
| 2707 | */ |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2708 | if (hw->phy.type == ixgbe_phy_unknown) { |
| 2709 | err = hw->phy.ops.identify(hw); |
| 2710 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 5da43c1 | 2009-07-02 12:50:52 +0000 | [diff] [blame] | 2711 | /* |
| 2712 | * Take the device down and schedule the sfp tasklet |
| 2713 | * which will unregister_netdev and log it. |
| 2714 | */ |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2715 | ixgbe_down(adapter); |
Don Skidmore | 5da43c1 | 2009-07-02 12:50:52 +0000 | [diff] [blame] | 2716 | schedule_work(&adapter->sfp_config_module_task); |
Don Skidmore | 19343de | 2009-07-02 12:50:31 +0000 | [diff] [blame] | 2717 | return err; |
| 2718 | } |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 2719 | } |
| 2720 | |
| 2721 | if (ixgbe_is_sfp(hw)) { |
| 2722 | ixgbe_sfp_link_config(adapter); |
| 2723 | } else { |
| 2724 | err = ixgbe_non_sfp_link_config(hw); |
| 2725 | if (err) |
| 2726 | DPRINTK(PROBE, ERR, "link_config FAILED %d\n", err); |
| 2727 | } |
Peter P Waskiewicz Jr | 0ecc061 | 2009-02-06 21:46:54 -0800 | [diff] [blame] | 2728 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2729 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2730 | set_bit(__IXGBE_FDIR_INIT_DONE, |
| 2731 | &(adapter->tx_ring[i].reinit_state)); |
| 2732 | |
Peter P Waskiewicz Jr | 1da100b | 2009-01-19 16:55:03 -0800 | [diff] [blame] | 2733 | /* enable transmits */ |
| 2734 | netif_tx_start_all_queues(netdev); |
| 2735 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2736 | /* bring the link up in the watchdog, this could race with our first |
| 2737 | * link up interrupt but shouldn't be a problem */ |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2738 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 2739 | adapter->link_check_timeout = jiffies; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2740 | mod_timer(&adapter->watchdog_timer, jiffies); |
| 2741 | return 0; |
| 2742 | } |
| 2743 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 2744 | void ixgbe_reinit_locked(struct ixgbe_adapter *adapter) |
| 2745 | { |
| 2746 | WARN_ON(in_interrupt()); |
| 2747 | while (test_and_set_bit(__IXGBE_RESETTING, &adapter->state)) |
| 2748 | msleep(1); |
| 2749 | ixgbe_down(adapter); |
| 2750 | ixgbe_up(adapter); |
| 2751 | clear_bit(__IXGBE_RESETTING, &adapter->state); |
| 2752 | } |
| 2753 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2754 | int ixgbe_up(struct ixgbe_adapter *adapter) |
| 2755 | { |
| 2756 | /* hardware has been reset, we need to reload some things */ |
| 2757 | ixgbe_configure(adapter); |
| 2758 | |
| 2759 | return ixgbe_up_complete(adapter); |
| 2760 | } |
| 2761 | |
| 2762 | void ixgbe_reset(struct ixgbe_adapter *adapter) |
| 2763 | { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2764 | struct ixgbe_hw *hw = &adapter->hw; |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 2765 | int err; |
| 2766 | |
| 2767 | err = hw->mac.ops.init_hw(hw); |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2768 | switch (err) { |
| 2769 | case 0: |
| 2770 | case IXGBE_ERR_SFP_NOT_PRESENT: |
| 2771 | break; |
| 2772 | case IXGBE_ERR_MASTER_REQUESTS_PENDING: |
| 2773 | dev_err(&adapter->pdev->dev, "master disable timed out\n"); |
| 2774 | break; |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 2775 | case IXGBE_ERR_EEPROM_VERSION: |
| 2776 | /* We are running on a pre-production device, log a warning */ |
| 2777 | dev_warn(&adapter->pdev->dev, "This device is a pre-production " |
| 2778 | "adapter/LOM. Please be aware there may be issues " |
| 2779 | "associated with your hardware. If you are " |
| 2780 | "experiencing problems please contact your Intel or " |
| 2781 | "hardware representative who provided you with this " |
| 2782 | "hardware.\n"); |
| 2783 | break; |
Peter P Waskiewicz Jr | da4dd0f | 2009-06-04 11:10:35 +0000 | [diff] [blame] | 2784 | default: |
| 2785 | dev_err(&adapter->pdev->dev, "Hardware Error: %d\n", err); |
| 2786 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2787 | |
| 2788 | /* reprogram the RAR[0] in case user changed it. */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 2789 | 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] | 2790 | } |
| 2791 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2792 | /** |
| 2793 | * ixgbe_clean_rx_ring - Free Rx Buffers per Queue |
| 2794 | * @adapter: board private structure |
| 2795 | * @rx_ring: ring to free buffers from |
| 2796 | **/ |
| 2797 | static void ixgbe_clean_rx_ring(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2798 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2799 | { |
| 2800 | struct pci_dev *pdev = adapter->pdev; |
| 2801 | unsigned long size; |
| 2802 | unsigned int i; |
| 2803 | |
| 2804 | /* Free all the Rx ring sk_buffs */ |
| 2805 | |
| 2806 | for (i = 0; i < rx_ring->count; i++) { |
| 2807 | struct ixgbe_rx_buffer *rx_buffer_info; |
| 2808 | |
| 2809 | rx_buffer_info = &rx_ring->rx_buffer_info[i]; |
| 2810 | if (rx_buffer_info->dma) { |
| 2811 | pci_unmap_single(pdev, rx_buffer_info->dma, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2812 | rx_ring->rx_buf_len, |
| 2813 | PCI_DMA_FROMDEVICE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2814 | rx_buffer_info->dma = 0; |
| 2815 | } |
| 2816 | if (rx_buffer_info->skb) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2817 | struct sk_buff *skb = rx_buffer_info->skb; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2818 | rx_buffer_info->skb = NULL; |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 2819 | do { |
| 2820 | struct sk_buff *this = skb; |
| 2821 | skb = skb->prev; |
| 2822 | dev_kfree_skb(this); |
| 2823 | } while (skb); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2824 | } |
| 2825 | if (!rx_buffer_info->page) |
| 2826 | continue; |
Jesse Brandeburg | 4f57ca6 | 2009-06-30 11:44:56 +0000 | [diff] [blame] | 2827 | if (rx_buffer_info->page_dma) { |
| 2828 | pci_unmap_page(pdev, rx_buffer_info->page_dma, |
| 2829 | PAGE_SIZE / 2, PCI_DMA_FROMDEVICE); |
| 2830 | rx_buffer_info->page_dma = 0; |
| 2831 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2832 | put_page(rx_buffer_info->page); |
| 2833 | rx_buffer_info->page = NULL; |
Jesse Brandeburg | 762f4c5 | 2008-09-11 19:58:43 -0700 | [diff] [blame] | 2834 | rx_buffer_info->page_offset = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2835 | } |
| 2836 | |
| 2837 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 2838 | memset(rx_ring->rx_buffer_info, 0, size); |
| 2839 | |
| 2840 | /* Zero out the descriptor ring */ |
| 2841 | memset(rx_ring->desc, 0, rx_ring->size); |
| 2842 | |
| 2843 | rx_ring->next_to_clean = 0; |
| 2844 | rx_ring->next_to_use = 0; |
| 2845 | |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 2846 | if (rx_ring->head) |
| 2847 | writel(0, adapter->hw.hw_addr + rx_ring->head); |
| 2848 | if (rx_ring->tail) |
| 2849 | writel(0, adapter->hw.hw_addr + rx_ring->tail); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2850 | } |
| 2851 | |
| 2852 | /** |
| 2853 | * ixgbe_clean_tx_ring - Free Tx Buffers |
| 2854 | * @adapter: board private structure |
| 2855 | * @tx_ring: ring to be cleaned |
| 2856 | **/ |
| 2857 | static void ixgbe_clean_tx_ring(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 2858 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2859 | { |
| 2860 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 2861 | unsigned long size; |
| 2862 | unsigned int i; |
| 2863 | |
| 2864 | /* Free all the Tx ring sk_buffs */ |
| 2865 | |
| 2866 | for (i = 0; i < tx_ring->count; i++) { |
| 2867 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 2868 | ixgbe_unmap_and_free_tx_resource(adapter, tx_buffer_info); |
| 2869 | } |
| 2870 | |
| 2871 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 2872 | memset(tx_ring->tx_buffer_info, 0, size); |
| 2873 | |
| 2874 | /* Zero out the descriptor ring */ |
| 2875 | memset(tx_ring->desc, 0, tx_ring->size); |
| 2876 | |
| 2877 | tx_ring->next_to_use = 0; |
| 2878 | tx_ring->next_to_clean = 0; |
| 2879 | |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 2880 | if (tx_ring->head) |
| 2881 | writel(0, adapter->hw.hw_addr + tx_ring->head); |
| 2882 | if (tx_ring->tail) |
| 2883 | writel(0, adapter->hw.hw_addr + tx_ring->tail); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2884 | } |
| 2885 | |
| 2886 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2887 | * ixgbe_clean_all_rx_rings - Free Rx Buffers for all queues |
| 2888 | * @adapter: board private structure |
| 2889 | **/ |
| 2890 | static void ixgbe_clean_all_rx_rings(struct ixgbe_adapter *adapter) |
| 2891 | { |
| 2892 | int i; |
| 2893 | |
| 2894 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 2895 | ixgbe_clean_rx_ring(adapter, &adapter->rx_ring[i]); |
| 2896 | } |
| 2897 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2898 | /** |
| 2899 | * ixgbe_clean_all_tx_rings - Free Tx Buffers for all queues |
| 2900 | * @adapter: board private structure |
| 2901 | **/ |
| 2902 | static void ixgbe_clean_all_tx_rings(struct ixgbe_adapter *adapter) |
| 2903 | { |
| 2904 | int i; |
| 2905 | |
| 2906 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 2907 | ixgbe_clean_tx_ring(adapter, &adapter->tx_ring[i]); |
| 2908 | } |
| 2909 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2910 | void ixgbe_down(struct ixgbe_adapter *adapter) |
| 2911 | { |
| 2912 | struct net_device *netdev = adapter->netdev; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2913 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2914 | u32 rxctrl; |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2915 | u32 txdctl; |
| 2916 | int i, j; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2917 | |
| 2918 | /* signal that we are down to the interrupt handler */ |
| 2919 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 2920 | |
| 2921 | /* disable receives */ |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2922 | rxctrl = IXGBE_READ_REG(hw, IXGBE_RXCTRL); |
| 2923 | IXGBE_WRITE_REG(hw, IXGBE_RXCTRL, rxctrl & ~IXGBE_RXCTRL_RXEN); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2924 | |
| 2925 | netif_tx_disable(netdev); |
| 2926 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2927 | IXGBE_WRITE_FLUSH(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2928 | msleep(10); |
| 2929 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2930 | netif_tx_stop_all_queues(netdev); |
| 2931 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2932 | ixgbe_irq_disable(adapter); |
| 2933 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2934 | ixgbe_napi_disable_all(adapter); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2935 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2936 | del_timer_sync(&adapter->watchdog_timer); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 2937 | cancel_work_sync(&adapter->watchdog_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2938 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 2939 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 2940 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 2941 | cancel_work_sync(&adapter->fdir_reinit_task); |
| 2942 | |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2943 | /* disable transmits in the hardware now that interrupts are off */ |
| 2944 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 2945 | j = adapter->tx_ring[i].reg_idx; |
| 2946 | txdctl = IXGBE_READ_REG(hw, IXGBE_TXDCTL(j)); |
| 2947 | IXGBE_WRITE_REG(hw, IXGBE_TXDCTL(j), |
| 2948 | (txdctl & ~IXGBE_TXDCTL_ENABLE)); |
| 2949 | } |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 2950 | /* Disable the Tx DMA engine on 82599 */ |
| 2951 | if (hw->mac.type == ixgbe_mac_82599EB) |
| 2952 | IXGBE_WRITE_REG(hw, IXGBE_DMATXCTL, |
| 2953 | (IXGBE_READ_REG(hw, IXGBE_DMATXCTL) & |
| 2954 | ~IXGBE_DMATXCTL_TE)); |
Jesse Brandeburg | 7f82187 | 2008-09-11 20:00:16 -0700 | [diff] [blame] | 2955 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2956 | netif_carrier_off(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2957 | |
Paul Larson | 6f4a0e4 | 2008-06-24 17:00:56 -0700 | [diff] [blame] | 2958 | if (!pci_channel_offline(adapter->pdev)) |
| 2959 | ixgbe_reset(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2960 | ixgbe_clean_all_tx_rings(adapter); |
| 2961 | ixgbe_clean_all_rx_rings(adapter); |
| 2962 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 2963 | #ifdef CONFIG_IXGBE_DCA |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 2964 | /* since we reset the hardware DCA settings were cleared */ |
Alexander Duyck | e35ec12 | 2009-05-21 13:07:12 +0000 | [diff] [blame] | 2965 | ixgbe_setup_dca(adapter); |
Jesse Brandeburg | 96b0e0f | 2008-08-26 04:27:21 -0700 | [diff] [blame] | 2966 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2967 | } |
| 2968 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2969 | /** |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2970 | * ixgbe_poll - NAPI Rx polling callback |
| 2971 | * @napi: structure for representing this polling device |
| 2972 | * @budget: how many packets driver is allowed to clean |
| 2973 | * |
| 2974 | * This function is used for legacy and MSI, NAPI mode |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2975 | **/ |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2976 | static int ixgbe_poll(struct napi_struct *napi, int budget) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2977 | { |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 2978 | struct ixgbe_q_vector *q_vector = |
| 2979 | container_of(napi, struct ixgbe_q_vector, napi); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 2980 | struct ixgbe_adapter *adapter = q_vector->adapter; |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 2981 | int tx_clean_complete, work_done = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2982 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 2983 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 2984 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 2985 | ixgbe_update_tx_dca(adapter, adapter->tx_ring); |
| 2986 | ixgbe_update_rx_dca(adapter, adapter->rx_ring); |
| 2987 | } |
| 2988 | #endif |
| 2989 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 2990 | tx_clean_complete = ixgbe_clean_tx_irq(q_vector, adapter->tx_ring); |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 2991 | ixgbe_clean_rx_irq(q_vector, adapter->rx_ring, &work_done, budget); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 2992 | |
Jesse Brandeburg | 9a1a69ad | 2009-03-13 22:14:10 +0000 | [diff] [blame] | 2993 | if (!tx_clean_complete) |
David S. Miller | d2c7ddd | 2008-01-15 22:43:24 -0800 | [diff] [blame] | 2994 | work_done = budget; |
| 2995 | |
David S. Miller | 53e52c7 | 2008-01-07 21:06:12 -0800 | [diff] [blame] | 2996 | /* If budget not fully consumed, exit the polling mode */ |
| 2997 | if (work_done < budget) { |
Ben Hutchings | 288379f | 2009-01-19 16:43:59 -0800 | [diff] [blame] | 2998 | napi_complete(napi); |
Jesse Brandeburg | 509ee93 | 2009-03-13 22:13:28 +0000 | [diff] [blame] | 2999 | if (adapter->itr_setting & 1) |
Ayyappan Veeraiyan | f494e8f | 2008-03-03 15:03:57 -0800 | [diff] [blame] | 3000 | ixgbe_set_itr(adapter); |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3001 | if (!test_bit(__IXGBE_DOWN, &adapter->state)) |
Nelson, Shannon | 835462f | 2009-04-27 22:42:54 +0000 | [diff] [blame] | 3002 | ixgbe_irq_enable_queues(adapter, IXGBE_EIMS_RTX_QUEUE); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3003 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3004 | return work_done; |
| 3005 | } |
| 3006 | |
| 3007 | /** |
| 3008 | * ixgbe_tx_timeout - Respond to a Tx Hang |
| 3009 | * @netdev: network interface device structure |
| 3010 | **/ |
| 3011 | static void ixgbe_tx_timeout(struct net_device *netdev) |
| 3012 | { |
| 3013 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 3014 | |
| 3015 | /* Do the reset outside of interrupt context */ |
| 3016 | schedule_work(&adapter->reset_task); |
| 3017 | } |
| 3018 | |
| 3019 | static void ixgbe_reset_task(struct work_struct *work) |
| 3020 | { |
| 3021 | struct ixgbe_adapter *adapter; |
| 3022 | adapter = container_of(work, struct ixgbe_adapter, reset_task); |
| 3023 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3024 | /* If we're already down or resetting, just bail */ |
| 3025 | if (test_bit(__IXGBE_DOWN, &adapter->state) || |
| 3026 | test_bit(__IXGBE_RESETTING, &adapter->state)) |
| 3027 | return; |
| 3028 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3029 | adapter->tx_timeout_count++; |
| 3030 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 3031 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3032 | } |
| 3033 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3034 | #ifdef CONFIG_IXGBE_DCB |
| 3035 | static inline bool ixgbe_set_dcb_queues(struct ixgbe_adapter *adapter) |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3036 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3037 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3038 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_DCB]; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3039 | |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3040 | if (!(adapter->flags & IXGBE_FLAG_DCB_ENABLED)) |
| 3041 | return ret; |
| 3042 | |
| 3043 | f->mask = 0x7 << 3; |
| 3044 | adapter->num_rx_queues = f->indices; |
| 3045 | adapter->num_tx_queues = f->indices; |
| 3046 | ret = true; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3047 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3048 | return ret; |
| 3049 | } |
| 3050 | #endif |
| 3051 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3052 | /** |
| 3053 | * ixgbe_set_rss_queues: Allocate queues for RSS |
| 3054 | * @adapter: board private structure to initialize |
| 3055 | * |
| 3056 | * This is our "base" multiqueue mode. RSS (Receive Side Scaling) will try |
| 3057 | * to allocate one Rx queue per CPU, and if available, one Tx queue per CPU. |
| 3058 | * |
| 3059 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3060 | static inline bool ixgbe_set_rss_queues(struct ixgbe_adapter *adapter) |
| 3061 | { |
| 3062 | bool ret = false; |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3063 | 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] | 3064 | |
| 3065 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Jesse Brandeburg | 0cefafa | 2009-05-19 09:19:11 +0000 | [diff] [blame] | 3066 | f->mask = 0xF; |
| 3067 | adapter->num_rx_queues = f->indices; |
| 3068 | adapter->num_tx_queues = f->indices; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3069 | ret = true; |
| 3070 | } else { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3071 | ret = false; |
| 3072 | } |
| 3073 | |
| 3074 | return ret; |
| 3075 | } |
| 3076 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3077 | /** |
| 3078 | * ixgbe_set_fdir_queues: Allocate queues for Flow Director |
| 3079 | * @adapter: board private structure to initialize |
| 3080 | * |
| 3081 | * Flow Director is an advanced Rx filter, attempting to get Rx flows back |
| 3082 | * to the original CPU that initiated the Tx session. This runs in addition |
| 3083 | * to RSS, so if a packet doesn't match an FDIR filter, we can still spread the |
| 3084 | * Rx load across CPUs using RSS. |
| 3085 | * |
| 3086 | **/ |
| 3087 | static bool inline ixgbe_set_fdir_queues(struct ixgbe_adapter *adapter) |
| 3088 | { |
| 3089 | bool ret = false; |
| 3090 | struct ixgbe_ring_feature *f_fdir = &adapter->ring_feature[RING_F_FDIR]; |
| 3091 | |
| 3092 | f_fdir->indices = min((int)num_online_cpus(), f_fdir->indices); |
| 3093 | f_fdir->mask = 0; |
| 3094 | |
| 3095 | /* Flow Director must have RSS enabled */ |
| 3096 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED && |
| 3097 | ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 3098 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)))) { |
| 3099 | adapter->num_tx_queues = f_fdir->indices; |
| 3100 | adapter->num_rx_queues = f_fdir->indices; |
| 3101 | ret = true; |
| 3102 | } else { |
| 3103 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3104 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 3105 | } |
| 3106 | return ret; |
| 3107 | } |
| 3108 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3109 | #ifdef IXGBE_FCOE |
| 3110 | /** |
| 3111 | * ixgbe_set_fcoe_queues: Allocate queues for Fiber Channel over Ethernet (FCoE) |
| 3112 | * @adapter: board private structure to initialize |
| 3113 | * |
| 3114 | * FCoE RX FCRETA can use up to 8 rx queues for up to 8 different exchanges. |
| 3115 | * The ring feature mask is not used as a mask for FCoE, as it can take any 8 |
| 3116 | * rx queues out of the max number of rx queues, instead, it is used as the |
| 3117 | * index of the first rx queue used by FCoE. |
| 3118 | * |
| 3119 | **/ |
| 3120 | static inline bool ixgbe_set_fcoe_queues(struct ixgbe_adapter *adapter) |
| 3121 | { |
| 3122 | bool ret = false; |
| 3123 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 3124 | |
| 3125 | f->indices = min((int)num_online_cpus(), f->indices); |
| 3126 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 3127 | #ifdef CONFIG_IXGBE_DCB |
| 3128 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 3129 | DPRINTK(PROBE, INFO, "FCOE enabled with DCB \n"); |
| 3130 | ixgbe_set_dcb_queues(adapter); |
| 3131 | } |
| 3132 | #endif |
| 3133 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 3134 | DPRINTK(PROBE, INFO, "FCOE enabled with RSS \n"); |
Yi Zou | 8faa2a7 | 2009-07-09 02:29:50 +0000 | [diff] [blame] | 3135 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 3136 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 3137 | ixgbe_set_fdir_queues(adapter); |
| 3138 | else |
| 3139 | ixgbe_set_rss_queues(adapter); |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3140 | } |
| 3141 | /* adding FCoE rx rings to the end */ |
| 3142 | f->mask = adapter->num_rx_queues; |
| 3143 | adapter->num_rx_queues += f->indices; |
| 3144 | if (adapter->num_tx_queues == 0) |
| 3145 | adapter->num_tx_queues = f->indices; |
| 3146 | |
| 3147 | ret = true; |
| 3148 | } |
| 3149 | |
| 3150 | return ret; |
| 3151 | } |
| 3152 | |
| 3153 | #endif /* IXGBE_FCOE */ |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3154 | /* |
| 3155 | * ixgbe_set_num_queues: Allocate queues for device, feature dependant |
| 3156 | * @adapter: board private structure to initialize |
| 3157 | * |
| 3158 | * This is the top level queue allocation routine. The order here is very |
| 3159 | * important, starting with the "most" number of features turned on at once, |
| 3160 | * and ending with the smallest set of features. This way large combinations |
| 3161 | * can be allocated if they're turned on, and smaller combinations are the |
| 3162 | * fallthrough conditions. |
| 3163 | * |
| 3164 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3165 | static void ixgbe_set_num_queues(struct ixgbe_adapter *adapter) |
| 3166 | { |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3167 | #ifdef IXGBE_FCOE |
| 3168 | if (ixgbe_set_fcoe_queues(adapter)) |
| 3169 | goto done; |
| 3170 | |
| 3171 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3172 | #ifdef CONFIG_IXGBE_DCB |
| 3173 | if (ixgbe_set_dcb_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 3174 | goto done; |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3175 | |
| 3176 | #endif |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3177 | if (ixgbe_set_fdir_queues(adapter)) |
| 3178 | goto done; |
| 3179 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3180 | if (ixgbe_set_rss_queues(adapter)) |
Wu Fengguang | af22ab1 | 2009-04-14 21:54:07 -0700 | [diff] [blame] | 3181 | goto done; |
| 3182 | |
| 3183 | /* fallback to base case */ |
| 3184 | adapter->num_rx_queues = 1; |
| 3185 | adapter->num_tx_queues = 1; |
| 3186 | |
| 3187 | done: |
| 3188 | /* Notify the stack of the (possibly) reduced Tx Queue count. */ |
| 3189 | adapter->netdev->real_num_tx_queues = adapter->num_tx_queues; |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3190 | } |
| 3191 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3192 | static void ixgbe_acquire_msix_vectors(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3193 | int vectors) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3194 | { |
| 3195 | int err, vector_threshold; |
| 3196 | |
| 3197 | /* We'll want at least 3 (vector_threshold): |
| 3198 | * 1) TxQ[0] Cleanup |
| 3199 | * 2) RxQ[0] Cleanup |
| 3200 | * 3) Other (Link Status Change, etc.) |
| 3201 | * 4) TCP Timer (optional) |
| 3202 | */ |
| 3203 | vector_threshold = MIN_MSIX_COUNT; |
| 3204 | |
| 3205 | /* The more we get, the more we will assign to Tx/Rx Cleanup |
| 3206 | * for the separate queues...where Rx Cleanup >= Tx Cleanup. |
| 3207 | * Right now, we simply care about how many we'll get; we'll |
| 3208 | * set them up later while requesting irq's. |
| 3209 | */ |
| 3210 | while (vectors >= vector_threshold) { |
| 3211 | err = pci_enable_msix(adapter->pdev, adapter->msix_entries, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3212 | vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3213 | if (!err) /* Success in acquiring all requested vectors. */ |
| 3214 | break; |
| 3215 | else if (err < 0) |
| 3216 | vectors = 0; /* Nasty failure, quit now */ |
| 3217 | else /* err == number of vectors we should try again with */ |
| 3218 | vectors = err; |
| 3219 | } |
| 3220 | |
| 3221 | if (vectors < vector_threshold) { |
| 3222 | /* Can't allocate enough MSI-X interrupts? Oh well. |
| 3223 | * This just means we'll go with either a single MSI |
| 3224 | * vector or fall back to legacy interrupts. |
| 3225 | */ |
| 3226 | DPRINTK(HW, DEBUG, "Unable to allocate MSI-X interrupts\n"); |
| 3227 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 3228 | kfree(adapter->msix_entries); |
| 3229 | adapter->msix_entries = NULL; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3230 | } else { |
| 3231 | adapter->flags |= IXGBE_FLAG_MSIX_ENABLED; /* Woot! */ |
Peter P Waskiewicz Jr | eb7f139 | 2009-02-01 01:18:58 -0800 | [diff] [blame] | 3232 | /* |
| 3233 | * Adjust for only the vectors we'll use, which is minimum |
| 3234 | * of max_msix_q_vectors + NON_Q_VECTORS, or the number of |
| 3235 | * vectors we were allocated. |
| 3236 | */ |
| 3237 | adapter->num_msix_vectors = min(vectors, |
| 3238 | adapter->max_msix_q_vectors + NON_Q_VECTORS); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3239 | } |
| 3240 | } |
| 3241 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3242 | /** |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3243 | * ixgbe_cache_ring_rss - Descriptor ring to register mapping for RSS |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3244 | * @adapter: board private structure to initialize |
| 3245 | * |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3246 | * Cache the descriptor ring offsets for RSS to the assigned rings. |
| 3247 | * |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3248 | **/ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3249 | static inline bool ixgbe_cache_ring_rss(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3250 | { |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3251 | int i; |
| 3252 | bool ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3253 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3254 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
| 3255 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3256 | adapter->rx_ring[i].reg_idx = i; |
| 3257 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3258 | adapter->tx_ring[i].reg_idx = i; |
| 3259 | ret = true; |
| 3260 | } else { |
| 3261 | ret = false; |
| 3262 | } |
| 3263 | |
| 3264 | return ret; |
| 3265 | } |
| 3266 | |
| 3267 | #ifdef CONFIG_IXGBE_DCB |
| 3268 | /** |
| 3269 | * ixgbe_cache_ring_dcb - Descriptor ring to register mapping for DCB |
| 3270 | * @adapter: board private structure to initialize |
| 3271 | * |
| 3272 | * Cache the descriptor ring offsets for DCB to the assigned rings. |
| 3273 | * |
| 3274 | **/ |
| 3275 | static inline bool ixgbe_cache_ring_dcb(struct ixgbe_adapter *adapter) |
| 3276 | { |
| 3277 | int i; |
| 3278 | bool ret = false; |
| 3279 | int dcb_i = adapter->ring_feature[RING_F_DCB].indices; |
| 3280 | |
| 3281 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 3282 | if (adapter->hw.mac.type == ixgbe_mac_82598EB) { |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3283 | /* the number of queues is assumed to be symmetric */ |
| 3284 | for (i = 0; i < dcb_i; i++) { |
| 3285 | adapter->rx_ring[i].reg_idx = i << 3; |
| 3286 | adapter->tx_ring[i].reg_idx = i << 2; |
| 3287 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3288 | ret = true; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3289 | } else if (adapter->hw.mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | f92ef20 | 2009-04-16 15:00:20 +0000 | [diff] [blame] | 3290 | if (dcb_i == 8) { |
| 3291 | /* |
| 3292 | * Tx TC0 starts at: descriptor queue 0 |
| 3293 | * Tx TC1 starts at: descriptor queue 32 |
| 3294 | * Tx TC2 starts at: descriptor queue 64 |
| 3295 | * Tx TC3 starts at: descriptor queue 80 |
| 3296 | * Tx TC4 starts at: descriptor queue 96 |
| 3297 | * Tx TC5 starts at: descriptor queue 104 |
| 3298 | * Tx TC6 starts at: descriptor queue 112 |
| 3299 | * Tx TC7 starts at: descriptor queue 120 |
| 3300 | * |
| 3301 | * Rx TC0-TC7 are offset by 16 queues each |
| 3302 | */ |
| 3303 | for (i = 0; i < 3; i++) { |
| 3304 | adapter->tx_ring[i].reg_idx = i << 5; |
| 3305 | adapter->rx_ring[i].reg_idx = i << 4; |
| 3306 | } |
| 3307 | for ( ; i < 5; i++) { |
| 3308 | adapter->tx_ring[i].reg_idx = |
| 3309 | ((i + 2) << 4); |
| 3310 | adapter->rx_ring[i].reg_idx = i << 4; |
| 3311 | } |
| 3312 | for ( ; i < dcb_i; i++) { |
| 3313 | adapter->tx_ring[i].reg_idx = |
| 3314 | ((i + 8) << 3); |
| 3315 | adapter->rx_ring[i].reg_idx = i << 4; |
| 3316 | } |
| 3317 | |
| 3318 | ret = true; |
| 3319 | } else if (dcb_i == 4) { |
| 3320 | /* |
| 3321 | * Tx TC0 starts at: descriptor queue 0 |
| 3322 | * Tx TC1 starts at: descriptor queue 64 |
| 3323 | * Tx TC2 starts at: descriptor queue 96 |
| 3324 | * Tx TC3 starts at: descriptor queue 112 |
| 3325 | * |
| 3326 | * Rx TC0-TC3 are offset by 32 queues each |
| 3327 | */ |
| 3328 | adapter->tx_ring[0].reg_idx = 0; |
| 3329 | adapter->tx_ring[1].reg_idx = 64; |
| 3330 | adapter->tx_ring[2].reg_idx = 96; |
| 3331 | adapter->tx_ring[3].reg_idx = 112; |
| 3332 | for (i = 0 ; i < dcb_i; i++) |
| 3333 | adapter->rx_ring[i].reg_idx = i << 5; |
| 3334 | |
| 3335 | ret = true; |
| 3336 | } else { |
| 3337 | ret = false; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3338 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3339 | } else { |
| 3340 | ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3341 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3342 | } else { |
| 3343 | ret = false; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3344 | } |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3345 | |
| 3346 | return ret; |
| 3347 | } |
| 3348 | #endif |
| 3349 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3350 | /** |
| 3351 | * ixgbe_cache_ring_fdir - Descriptor ring to register mapping for Flow Director |
| 3352 | * @adapter: board private structure to initialize |
| 3353 | * |
| 3354 | * Cache the descriptor ring offsets for Flow Director to the assigned rings. |
| 3355 | * |
| 3356 | **/ |
| 3357 | static bool inline ixgbe_cache_ring_fdir(struct ixgbe_adapter *adapter) |
| 3358 | { |
| 3359 | int i; |
| 3360 | bool ret = false; |
| 3361 | |
| 3362 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED && |
| 3363 | ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 3364 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE))) { |
| 3365 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 3366 | adapter->rx_ring[i].reg_idx = i; |
| 3367 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 3368 | adapter->tx_ring[i].reg_idx = i; |
| 3369 | ret = true; |
| 3370 | } |
| 3371 | |
| 3372 | return ret; |
| 3373 | } |
| 3374 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3375 | #ifdef IXGBE_FCOE |
| 3376 | /** |
| 3377 | * ixgbe_cache_ring_fcoe - Descriptor ring to register mapping for the FCoE |
| 3378 | * @adapter: board private structure to initialize |
| 3379 | * |
| 3380 | * Cache the descriptor ring offsets for FCoE mode to the assigned rings. |
| 3381 | * |
| 3382 | */ |
| 3383 | static inline bool ixgbe_cache_ring_fcoe(struct ixgbe_adapter *adapter) |
| 3384 | { |
| 3385 | int i, fcoe_i = 0; |
| 3386 | bool ret = false; |
| 3387 | struct ixgbe_ring_feature *f = &adapter->ring_feature[RING_F_FCOE]; |
| 3388 | |
| 3389 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 3390 | #ifdef CONFIG_IXGBE_DCB |
| 3391 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 3392 | ixgbe_cache_ring_dcb(adapter); |
| 3393 | fcoe_i = adapter->rx_ring[0].reg_idx + 1; |
| 3394 | } |
| 3395 | #endif /* CONFIG_IXGBE_DCB */ |
| 3396 | if (adapter->flags & IXGBE_FLAG_RSS_ENABLED) { |
Yi Zou | 8faa2a7 | 2009-07-09 02:29:50 +0000 | [diff] [blame] | 3397 | if ((adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) || |
| 3398 | (adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE)) |
| 3399 | ixgbe_cache_ring_fdir(adapter); |
| 3400 | else |
| 3401 | ixgbe_cache_ring_rss(adapter); |
| 3402 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3403 | fcoe_i = f->mask; |
| 3404 | } |
| 3405 | for (i = 0; i < f->indices; i++, fcoe_i++) |
| 3406 | adapter->rx_ring[f->mask + i].reg_idx = fcoe_i; |
| 3407 | ret = true; |
| 3408 | } |
| 3409 | return ret; |
| 3410 | } |
| 3411 | |
| 3412 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3413 | /** |
| 3414 | * ixgbe_cache_ring_register - Descriptor ring to register mapping |
| 3415 | * @adapter: board private structure to initialize |
| 3416 | * |
| 3417 | * Once we know the feature-set enabled for the device, we'll cache |
| 3418 | * the register offset the descriptor ring is assigned to. |
| 3419 | * |
| 3420 | * Note, the order the various feature calls is important. It must start with |
| 3421 | * the "most" features enabled at the same time, then trickle down to the |
| 3422 | * least amount of features turned on at once. |
| 3423 | **/ |
| 3424 | static void ixgbe_cache_ring_register(struct ixgbe_adapter *adapter) |
| 3425 | { |
| 3426 | /* start with default case */ |
| 3427 | adapter->rx_ring[0].reg_idx = 0; |
| 3428 | adapter->tx_ring[0].reg_idx = 0; |
| 3429 | |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3430 | #ifdef IXGBE_FCOE |
| 3431 | if (ixgbe_cache_ring_fcoe(adapter)) |
| 3432 | return; |
| 3433 | |
| 3434 | #endif /* IXGBE_FCOE */ |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3435 | #ifdef CONFIG_IXGBE_DCB |
| 3436 | if (ixgbe_cache_ring_dcb(adapter)) |
| 3437 | return; |
| 3438 | |
| 3439 | #endif |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3440 | if (ixgbe_cache_ring_fdir(adapter)) |
| 3441 | return; |
| 3442 | |
Peter P Waskiewicz Jr | bc97114 | 2009-02-05 23:53:59 -0800 | [diff] [blame] | 3443 | if (ixgbe_cache_ring_rss(adapter)) |
| 3444 | return; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3445 | } |
| 3446 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3447 | /** |
| 3448 | * ixgbe_alloc_queues - Allocate memory for all rings |
| 3449 | * @adapter: board private structure to initialize |
| 3450 | * |
| 3451 | * 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] | 3452 | * number of queues at compile-time. The polling_netdev array is |
| 3453 | * intended for Multiqueue, but should work fine with a single queue. |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3454 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3455 | static int ixgbe_alloc_queues(struct ixgbe_adapter *adapter) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3456 | { |
| 3457 | int i; |
| 3458 | |
| 3459 | adapter->tx_ring = kcalloc(adapter->num_tx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3460 | sizeof(struct ixgbe_ring), GFP_KERNEL); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3461 | if (!adapter->tx_ring) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3462 | goto err_tx_ring_allocation; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3463 | |
| 3464 | adapter->rx_ring = kcalloc(adapter->num_rx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3465 | sizeof(struct ixgbe_ring), GFP_KERNEL); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3466 | if (!adapter->rx_ring) |
| 3467 | goto err_rx_ring_allocation; |
| 3468 | |
| 3469 | for (i = 0; i < adapter->num_tx_queues; i++) { |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3470 | adapter->tx_ring[i].count = adapter->tx_ring_count; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3471 | adapter->tx_ring[i].queue_index = i; |
| 3472 | } |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3473 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3474 | for (i = 0; i < adapter->num_rx_queues; i++) { |
Jesse Brandeburg | b980497 | 2008-09-11 20:00:29 -0700 | [diff] [blame] | 3475 | adapter->rx_ring[i].count = adapter->rx_ring_count; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3476 | adapter->rx_ring[i].queue_index = i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3477 | } |
| 3478 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3479 | ixgbe_cache_ring_register(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3480 | |
| 3481 | return 0; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3482 | |
| 3483 | err_rx_ring_allocation: |
| 3484 | kfree(adapter->tx_ring); |
| 3485 | err_tx_ring_allocation: |
| 3486 | return -ENOMEM; |
| 3487 | } |
| 3488 | |
| 3489 | /** |
| 3490 | * ixgbe_set_interrupt_capability - set MSI-X or MSI if supported |
| 3491 | * @adapter: board private structure to initialize |
| 3492 | * |
| 3493 | * Attempt to configure the interrupts using the best available |
| 3494 | * capabilities of the hardware and the kernel. |
| 3495 | **/ |
Al Viro | feea6a5 | 2008-11-27 15:34:07 -0800 | [diff] [blame] | 3496 | static int ixgbe_set_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3497 | { |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3498 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3499 | int err = 0; |
| 3500 | int vector, v_budget; |
| 3501 | |
| 3502 | /* |
| 3503 | * It's easy to be greedy for MSI-X vectors, but it really |
| 3504 | * doesn't do us much good if we have a lot more vectors |
| 3505 | * than CPU's. So let's be conservative and only ask for |
| 3506 | * (roughly) twice the number of vectors as there are CPU's. |
| 3507 | */ |
| 3508 | v_budget = min(adapter->num_rx_queues + adapter->num_tx_queues, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3509 | (int)(num_online_cpus() * 2)) + NON_Q_VECTORS; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3510 | |
| 3511 | /* |
| 3512 | * At the same time, hardware can only support a maximum of |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3513 | * hw.mac->max_msix_vectors vectors. With features |
| 3514 | * such as RSS and VMDq, we can easily surpass the number of Rx and Tx |
| 3515 | * descriptor queues supported by our device. Thus, we cap it off in |
| 3516 | * those rare cases where the cpu count also exceeds our vector limit. |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3517 | */ |
PJ Waskiewicz | 8be0e46 | 2009-03-31 21:34:05 +0000 | [diff] [blame] | 3518 | v_budget = min(v_budget, (int)hw->mac.max_msix_vectors); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3519 | |
| 3520 | /* A failure in MSI-X entry allocation isn't fatal, but it does |
| 3521 | * mean we disable MSI-X capabilities of the adapter. */ |
| 3522 | adapter->msix_entries = kcalloc(v_budget, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3523 | sizeof(struct msix_entry), GFP_KERNEL); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3524 | if (adapter->msix_entries) { |
| 3525 | for (vector = 0; vector < v_budget; vector++) |
| 3526 | adapter->msix_entries[vector].entry = vector; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3527 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3528 | ixgbe_acquire_msix_vectors(adapter, v_budget); |
| 3529 | |
| 3530 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
| 3531 | goto out; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3532 | } |
| 3533 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3534 | adapter->flags &= ~IXGBE_FLAG_DCB_ENABLED; |
| 3535 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3536 | adapter->flags &= ~IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3537 | adapter->flags &= ~IXGBE_FLAG_FDIR_PERFECT_CAPABLE; |
| 3538 | adapter->atr_sample_rate = 0; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3539 | ixgbe_set_num_queues(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3540 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3541 | err = pci_enable_msi(adapter->pdev); |
| 3542 | if (!err) { |
| 3543 | adapter->flags |= IXGBE_FLAG_MSI_ENABLED; |
| 3544 | } else { |
| 3545 | DPRINTK(HW, DEBUG, "Unable to allocate MSI interrupt, " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3546 | "falling back to legacy. Error: %d\n", err); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3547 | /* reset err */ |
| 3548 | err = 0; |
| 3549 | } |
| 3550 | |
| 3551 | out: |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3552 | return err; |
| 3553 | } |
| 3554 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3555 | /** |
| 3556 | * ixgbe_alloc_q_vectors - Allocate memory for interrupt vectors |
| 3557 | * @adapter: board private structure to initialize |
| 3558 | * |
| 3559 | * We allocate one q_vector per queue interrupt. If allocation fails we |
| 3560 | * return -ENOMEM. |
| 3561 | **/ |
| 3562 | static int ixgbe_alloc_q_vectors(struct ixgbe_adapter *adapter) |
| 3563 | { |
| 3564 | int q_idx, num_q_vectors; |
| 3565 | struct ixgbe_q_vector *q_vector; |
| 3566 | int napi_vectors; |
| 3567 | int (*poll)(struct napi_struct *, int); |
| 3568 | |
| 3569 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 3570 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
| 3571 | napi_vectors = adapter->num_rx_queues; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3572 | poll = &ixgbe_clean_rxtx_many; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3573 | } else { |
| 3574 | num_q_vectors = 1; |
| 3575 | napi_vectors = 1; |
| 3576 | poll = &ixgbe_poll; |
| 3577 | } |
| 3578 | |
| 3579 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
| 3580 | q_vector = kzalloc(sizeof(struct ixgbe_q_vector), GFP_KERNEL); |
| 3581 | if (!q_vector) |
| 3582 | goto err_out; |
| 3583 | q_vector->adapter = adapter; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3584 | q_vector->eitr = adapter->eitr_param; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 3585 | q_vector->v_idx = q_idx; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3586 | netif_napi_add(adapter->netdev, &q_vector->napi, (*poll), 64); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3587 | adapter->q_vector[q_idx] = q_vector; |
| 3588 | } |
| 3589 | |
| 3590 | return 0; |
| 3591 | |
| 3592 | err_out: |
| 3593 | while (q_idx) { |
| 3594 | q_idx--; |
| 3595 | q_vector = adapter->q_vector[q_idx]; |
| 3596 | netif_napi_del(&q_vector->napi); |
| 3597 | kfree(q_vector); |
| 3598 | adapter->q_vector[q_idx] = NULL; |
| 3599 | } |
| 3600 | return -ENOMEM; |
| 3601 | } |
| 3602 | |
| 3603 | /** |
| 3604 | * ixgbe_free_q_vectors - Free memory allocated for interrupt vectors |
| 3605 | * @adapter: board private structure to initialize |
| 3606 | * |
| 3607 | * This function frees the memory allocated to the q_vectors. In addition if |
| 3608 | * NAPI is enabled it will delete any references to the NAPI struct prior |
| 3609 | * to freeing the q_vector. |
| 3610 | **/ |
| 3611 | static void ixgbe_free_q_vectors(struct ixgbe_adapter *adapter) |
| 3612 | { |
| 3613 | int q_idx, num_q_vectors; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3614 | |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3615 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3616 | num_q_vectors = adapter->num_msix_vectors - NON_Q_VECTORS; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3617 | else |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3618 | num_q_vectors = 1; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3619 | |
| 3620 | for (q_idx = 0; q_idx < num_q_vectors; q_idx++) { |
| 3621 | struct ixgbe_q_vector *q_vector = adapter->q_vector[q_idx]; |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3622 | adapter->q_vector[q_idx] = NULL; |
Alexander Duyck | 91281fd | 2009-06-04 16:00:27 +0000 | [diff] [blame] | 3623 | netif_napi_del(&q_vector->napi); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3624 | kfree(q_vector); |
| 3625 | } |
| 3626 | } |
| 3627 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3628 | void ixgbe_reset_interrupt_capability(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3629 | { |
| 3630 | if (adapter->flags & IXGBE_FLAG_MSIX_ENABLED) { |
| 3631 | adapter->flags &= ~IXGBE_FLAG_MSIX_ENABLED; |
| 3632 | pci_disable_msix(adapter->pdev); |
| 3633 | kfree(adapter->msix_entries); |
| 3634 | adapter->msix_entries = NULL; |
| 3635 | } else if (adapter->flags & IXGBE_FLAG_MSI_ENABLED) { |
| 3636 | adapter->flags &= ~IXGBE_FLAG_MSI_ENABLED; |
| 3637 | pci_disable_msi(adapter->pdev); |
| 3638 | } |
| 3639 | return; |
| 3640 | } |
| 3641 | |
| 3642 | /** |
| 3643 | * ixgbe_init_interrupt_scheme - Determine proper interrupt scheme |
| 3644 | * @adapter: board private structure to initialize |
| 3645 | * |
| 3646 | * We determine which interrupt scheme to use based on... |
| 3647 | * - Kernel support (MSI, MSI-X) |
| 3648 | * - which can be user-defined (via MODULE_PARAM) |
| 3649 | * - Hardware queue count (num_*_queues) |
| 3650 | * - defined by miscellaneous hardware support/features (RSS, etc.) |
| 3651 | **/ |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3652 | int ixgbe_init_interrupt_scheme(struct ixgbe_adapter *adapter) |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3653 | { |
| 3654 | int err; |
| 3655 | |
| 3656 | /* Number of supported queues */ |
| 3657 | ixgbe_set_num_queues(adapter); |
| 3658 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3659 | err = ixgbe_set_interrupt_capability(adapter); |
| 3660 | if (err) { |
| 3661 | DPRINTK(PROBE, ERR, "Unable to setup interrupt capabilities\n"); |
| 3662 | goto err_set_interrupt; |
| 3663 | } |
| 3664 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3665 | err = ixgbe_alloc_q_vectors(adapter); |
| 3666 | if (err) { |
| 3667 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queue " |
| 3668 | "vectors\n"); |
| 3669 | goto err_alloc_q_vectors; |
| 3670 | } |
| 3671 | |
| 3672 | err = ixgbe_alloc_queues(adapter); |
| 3673 | if (err) { |
| 3674 | DPRINTK(PROBE, ERR, "Unable to allocate memory for queues\n"); |
| 3675 | goto err_alloc_queues; |
| 3676 | } |
| 3677 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3678 | DPRINTK(DRV, INFO, "Multiqueue %s: Rx Queue count = %u, " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3679 | "Tx Queue count = %u\n", |
| 3680 | (adapter->num_rx_queues > 1) ? "Enabled" : |
| 3681 | "Disabled", adapter->num_rx_queues, adapter->num_tx_queues); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3682 | |
| 3683 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 3684 | |
| 3685 | return 0; |
| 3686 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3687 | err_alloc_queues: |
| 3688 | ixgbe_free_q_vectors(adapter); |
| 3689 | err_alloc_q_vectors: |
| 3690 | ixgbe_reset_interrupt_capability(adapter); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3691 | err_set_interrupt: |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3692 | return err; |
| 3693 | } |
| 3694 | |
| 3695 | /** |
| 3696 | * ixgbe_clear_interrupt_scheme - Clear the current interrupt scheme settings |
| 3697 | * @adapter: board private structure to clear interrupt scheme on |
| 3698 | * |
| 3699 | * We go through and clear interrupt specific resources and reset the structure |
| 3700 | * to pre-load conditions |
| 3701 | **/ |
| 3702 | void ixgbe_clear_interrupt_scheme(struct ixgbe_adapter *adapter) |
| 3703 | { |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3704 | kfree(adapter->tx_ring); |
| 3705 | kfree(adapter->rx_ring); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 3706 | adapter->tx_ring = NULL; |
| 3707 | adapter->rx_ring = NULL; |
| 3708 | |
| 3709 | ixgbe_free_q_vectors(adapter); |
| 3710 | ixgbe_reset_interrupt_capability(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3711 | } |
| 3712 | |
| 3713 | /** |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3714 | * ixgbe_sfp_timer - worker thread to find a missing module |
| 3715 | * @data: pointer to our adapter struct |
| 3716 | **/ |
| 3717 | static void ixgbe_sfp_timer(unsigned long data) |
| 3718 | { |
| 3719 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
| 3720 | |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 3721 | /* |
| 3722 | * Do the sfp_timer outside of interrupt context due to the |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3723 | * delays that sfp+ detection requires |
| 3724 | */ |
| 3725 | schedule_work(&adapter->sfp_task); |
| 3726 | } |
| 3727 | |
| 3728 | /** |
| 3729 | * ixgbe_sfp_task - worker thread to find a missing module |
| 3730 | * @work: pointer to work_struct containing our data |
| 3731 | **/ |
| 3732 | static void ixgbe_sfp_task(struct work_struct *work) |
| 3733 | { |
| 3734 | struct ixgbe_adapter *adapter = container_of(work, |
| 3735 | struct ixgbe_adapter, |
| 3736 | sfp_task); |
| 3737 | struct ixgbe_hw *hw = &adapter->hw; |
| 3738 | |
| 3739 | if ((hw->phy.type == ixgbe_phy_nl) && |
| 3740 | (hw->phy.sfp_type == ixgbe_sfp_type_not_present)) { |
| 3741 | s32 ret = hw->phy.ops.identify_sfp(hw); |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 3742 | if (ret == IXGBE_ERR_SFP_NOT_PRESENT) |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3743 | goto reschedule; |
| 3744 | ret = hw->phy.ops.reset(hw); |
| 3745 | if (ret == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 88d2b81 | 2009-06-30 11:43:55 +0000 | [diff] [blame] | 3746 | dev_err(&adapter->pdev->dev, "failed to initialize " |
| 3747 | "because an unsupported SFP+ module type " |
| 3748 | "was detected.\n" |
| 3749 | "Reload the driver after installing a " |
| 3750 | "supported module.\n"); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 3751 | unregister_netdev(adapter->netdev); |
| 3752 | } else { |
| 3753 | DPRINTK(PROBE, INFO, "detected SFP+: %d\n", |
| 3754 | hw->phy.sfp_type); |
| 3755 | } |
| 3756 | /* don't need this routine any more */ |
| 3757 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 3758 | } |
| 3759 | return; |
| 3760 | reschedule: |
| 3761 | if (test_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state)) |
| 3762 | mod_timer(&adapter->sfp_timer, |
| 3763 | round_jiffies(jiffies + (2 * HZ))); |
| 3764 | } |
| 3765 | |
| 3766 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3767 | * ixgbe_sw_init - Initialize general software structures (struct ixgbe_adapter) |
| 3768 | * @adapter: board private structure to initialize |
| 3769 | * |
| 3770 | * ixgbe_sw_init initializes the Adapter private data structure. |
| 3771 | * Fields are initialized based on PCI device information and |
| 3772 | * OS network device settings (MTU size). |
| 3773 | **/ |
| 3774 | static int __devinit ixgbe_sw_init(struct ixgbe_adapter *adapter) |
| 3775 | { |
| 3776 | struct ixgbe_hw *hw = &adapter->hw; |
| 3777 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3778 | unsigned int rss; |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3779 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3780 | int j; |
| 3781 | struct tc_configuration *tc; |
| 3782 | #endif |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3783 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3784 | /* PCI config space info */ |
| 3785 | |
| 3786 | hw->vendor_id = pdev->vendor; |
| 3787 | hw->device_id = pdev->device; |
| 3788 | hw->revision_id = pdev->revision; |
| 3789 | hw->subsystem_vendor_id = pdev->subsystem_vendor; |
| 3790 | hw->subsystem_device_id = pdev->subsystem_device; |
| 3791 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3792 | /* Set capability flags */ |
| 3793 | rss = min(IXGBE_MAX_RSS_INDICES, (int)num_online_cpus()); |
| 3794 | adapter->ring_feature[RING_F_RSS].indices = rss; |
| 3795 | adapter->flags |= IXGBE_FLAG_RSS_ENABLED; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3796 | adapter->ring_feature[RING_F_DCB].indices = IXGBE_MAX_DCB_INDICES; |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3797 | if (hw->mac.type == ixgbe_mac_82598EB) { |
| 3798 | if (hw->device_id == IXGBE_DEV_ID_82598AT) |
| 3799 | adapter->flags |= IXGBE_FLAG_FAN_FAIL_CAPABLE; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3800 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82598; |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 3801 | } else if (hw->mac.type == ixgbe_mac_82599EB) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 3802 | adapter->max_msix_q_vectors = MAX_MSIX_Q_VECTORS_82599; |
Peter P Waskiewicz Jr | df647b5 | 2009-06-04 16:00:47 +0000 | [diff] [blame] | 3803 | adapter->flags |= IXGBE_FLAG2_RSC_CAPABLE; |
| 3804 | adapter->flags |= IXGBE_FLAG2_RSC_ENABLED; |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 3805 | adapter->flags |= IXGBE_FLAG_FDIR_HASH_CAPABLE; |
| 3806 | adapter->ring_feature[RING_F_FDIR].indices = |
| 3807 | IXGBE_MAX_FDIR_INDICES; |
| 3808 | adapter->atr_sample_rate = 20; |
| 3809 | adapter->fdir_pballoc = 0; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 3810 | #ifdef IXGBE_FCOE |
| 3811 | adapter->flags |= IXGBE_FLAG_FCOE_ENABLED; |
Yi Zou | 0331a83 | 2009-05-17 12:33:52 +0000 | [diff] [blame] | 3812 | adapter->ring_feature[RING_F_FCOE].indices = IXGBE_FCRETA_SIZE; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 3813 | #endif /* IXGBE_FCOE */ |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 3814 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3815 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 3816 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3817 | /* Configure DCB traffic classes */ |
| 3818 | for (j = 0; j < MAX_TRAFFIC_CLASS; j++) { |
| 3819 | tc = &adapter->dcb_cfg.tc_config[j]; |
| 3820 | tc->path[DCB_TX_CONFIG].bwg_id = 0; |
| 3821 | tc->path[DCB_TX_CONFIG].bwg_percent = 12 + (j & 1); |
| 3822 | tc->path[DCB_RX_CONFIG].bwg_id = 0; |
| 3823 | tc->path[DCB_RX_CONFIG].bwg_percent = 12 + (j & 1); |
| 3824 | tc->dcb_pfc = pfc_disabled; |
| 3825 | } |
| 3826 | adapter->dcb_cfg.bw_percentage[DCB_TX_CONFIG][0] = 100; |
| 3827 | adapter->dcb_cfg.bw_percentage[DCB_RX_CONFIG][0] = 100; |
| 3828 | adapter->dcb_cfg.rx_pba_cfg = pba_equal; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 3829 | adapter->dcb_cfg.pfc_mode_enable = false; |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 3830 | adapter->dcb_cfg.round_robin_enable = false; |
| 3831 | adapter->dcb_set_bitmap = 0x00; |
| 3832 | ixgbe_copy_dcb_cfg(&adapter->dcb_cfg, &adapter->temp_dcb_cfg, |
| 3833 | adapter->ring_feature[RING_F_DCB].indices); |
| 3834 | |
| 3835 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3836 | |
| 3837 | /* default flow control settings */ |
Don Skidmore | cd7664f | 2009-03-31 21:33:44 +0000 | [diff] [blame] | 3838 | hw->fc.requested_mode = ixgbe_fc_full; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 3839 | 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] | 3840 | #ifdef CONFIG_DCB |
| 3841 | adapter->last_lfc_mode = hw->fc.current_mode; |
| 3842 | #endif |
Jesse Brandeburg | 2b9ade9 | 2008-08-26 04:27:10 -0700 | [diff] [blame] | 3843 | hw->fc.high_water = IXGBE_DEFAULT_FCRTH; |
| 3844 | hw->fc.low_water = IXGBE_DEFAULT_FCRTL; |
| 3845 | hw->fc.pause_time = IXGBE_DEFAULT_FCPAUSE; |
| 3846 | hw->fc.send_xon = true; |
Don Skidmore | 71fd570 | 2009-03-31 21:35:05 +0000 | [diff] [blame] | 3847 | hw->fc.disable_fc_autoneg = false; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3848 | |
Jesse Brandeburg | 30efa5a | 2008-09-11 19:58:14 -0700 | [diff] [blame] | 3849 | /* enable itr by default in dynamic mode */ |
| 3850 | adapter->itr_setting = 1; |
| 3851 | adapter->eitr_param = 20000; |
| 3852 | |
| 3853 | /* set defaults for eitr in MegaBytes */ |
| 3854 | adapter->eitr_low = 10; |
| 3855 | adapter->eitr_high = 20; |
| 3856 | |
| 3857 | /* set default ring sizes */ |
| 3858 | adapter->tx_ring_count = IXGBE_DEFAULT_TXD; |
| 3859 | adapter->rx_ring_count = IXGBE_DEFAULT_RXD; |
| 3860 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3861 | /* initialize eeprom parameters */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 3862 | if (ixgbe_init_eeprom_params_generic(hw)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3863 | dev_err(&pdev->dev, "EEPROM initialization failed\n"); |
| 3864 | return -EIO; |
| 3865 | } |
| 3866 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3867 | /* enable rx csum by default */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3868 | adapter->flags |= IXGBE_FLAG_RX_CSUM_ENABLED; |
| 3869 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3870 | set_bit(__IXGBE_DOWN, &adapter->state); |
| 3871 | |
| 3872 | return 0; |
| 3873 | } |
| 3874 | |
| 3875 | /** |
| 3876 | * ixgbe_setup_tx_resources - allocate Tx resources (Descriptors) |
| 3877 | * @adapter: board private structure |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3878 | * @tx_ring: tx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3879 | * |
| 3880 | * Return 0 on success, negative on failure |
| 3881 | **/ |
| 3882 | int ixgbe_setup_tx_resources(struct ixgbe_adapter *adapter, |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 3883 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3884 | { |
| 3885 | struct pci_dev *pdev = adapter->pdev; |
| 3886 | int size; |
| 3887 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3888 | size = sizeof(struct ixgbe_tx_buffer) * tx_ring->count; |
| 3889 | tx_ring->tx_buffer_info = vmalloc(size); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 3890 | if (!tx_ring->tx_buffer_info) |
| 3891 | goto err; |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3892 | memset(tx_ring->tx_buffer_info, 0, size); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3893 | |
| 3894 | /* round up to nearest 4K */ |
Peter P Waskiewicz Jr | 12207e4 | 2009-02-06 21:47:24 -0800 | [diff] [blame] | 3895 | tx_ring->size = tx_ring->count * sizeof(union ixgbe_adv_tx_desc); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3896 | tx_ring->size = ALIGN(tx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3897 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3898 | tx_ring->desc = pci_alloc_consistent(pdev, tx_ring->size, |
| 3899 | &tx_ring->dma); |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 3900 | if (!tx_ring->desc) |
| 3901 | goto err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3902 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3903 | tx_ring->next_to_use = 0; |
| 3904 | tx_ring->next_to_clean = 0; |
| 3905 | tx_ring->work_limit = tx_ring->count; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3906 | return 0; |
Jesse Brandeburg | e01c31a | 2008-08-26 04:27:13 -0700 | [diff] [blame] | 3907 | |
| 3908 | err: |
| 3909 | vfree(tx_ring->tx_buffer_info); |
| 3910 | tx_ring->tx_buffer_info = NULL; |
| 3911 | DPRINTK(PROBE, ERR, "Unable to allocate memory for the transmit " |
| 3912 | "descriptor ring\n"); |
| 3913 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3914 | } |
| 3915 | |
| 3916 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 3917 | * ixgbe_setup_all_tx_resources - allocate all queues Tx resources |
| 3918 | * @adapter: board private structure |
| 3919 | * |
| 3920 | * If this function returns with an error, then it's possible one or |
| 3921 | * more of the rings is populated (while the rest are not). It is the |
| 3922 | * callers duty to clean those orphaned rings. |
| 3923 | * |
| 3924 | * Return 0 on success, negative on failure |
| 3925 | **/ |
| 3926 | static int ixgbe_setup_all_tx_resources(struct ixgbe_adapter *adapter) |
| 3927 | { |
| 3928 | int i, err = 0; |
| 3929 | |
| 3930 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 3931 | err = ixgbe_setup_tx_resources(adapter, &adapter->tx_ring[i]); |
| 3932 | if (!err) |
| 3933 | continue; |
| 3934 | DPRINTK(PROBE, ERR, "Allocation for Tx Queue %u failed\n", i); |
| 3935 | break; |
| 3936 | } |
| 3937 | |
| 3938 | return err; |
| 3939 | } |
| 3940 | |
| 3941 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3942 | * ixgbe_setup_rx_resources - allocate Rx resources (Descriptors) |
| 3943 | * @adapter: board private structure |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3944 | * @rx_ring: rx descriptor ring (for a specific queue) to setup |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3945 | * |
| 3946 | * Returns 0 on success, negative on failure |
| 3947 | **/ |
| 3948 | int ixgbe_setup_rx_resources(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3949 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3950 | { |
| 3951 | struct pci_dev *pdev = adapter->pdev; |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 3952 | int size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3953 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3954 | size = sizeof(struct ixgbe_rx_buffer) * rx_ring->count; |
| 3955 | rx_ring->rx_buffer_info = vmalloc(size); |
| 3956 | if (!rx_ring->rx_buffer_info) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3957 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3958 | "vmalloc allocation failed for the rx desc ring\n"); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3959 | goto alloc_failed; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3960 | } |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3961 | memset(rx_ring->rx_buffer_info, 0, size); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3962 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3963 | /* Round up to nearest 4K */ |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3964 | rx_ring->size = rx_ring->count * sizeof(union ixgbe_adv_rx_desc); |
| 3965 | rx_ring->size = ALIGN(rx_ring->size, 4096); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3966 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3967 | 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] | 3968 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3969 | if (!rx_ring->desc) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3970 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 3971 | "Memory allocation failed for the rx desc ring\n"); |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3972 | vfree(rx_ring->rx_buffer_info); |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3973 | goto alloc_failed; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3974 | } |
| 3975 | |
Jesse Brandeburg | 3a58107 | 2008-08-26 04:27:08 -0700 | [diff] [blame] | 3976 | rx_ring->next_to_clean = 0; |
| 3977 | rx_ring->next_to_use = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3978 | |
| 3979 | return 0; |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3980 | |
| 3981 | alloc_failed: |
Mallikarjuna R Chilakala | 177db6f | 2008-06-18 15:32:19 -0700 | [diff] [blame] | 3982 | return -ENOMEM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 3983 | } |
| 3984 | |
| 3985 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 3986 | * ixgbe_setup_all_rx_resources - allocate all queues Rx resources |
| 3987 | * @adapter: board private structure |
| 3988 | * |
| 3989 | * If this function returns with an error, then it's possible one or |
| 3990 | * more of the rings is populated (while the rest are not). It is the |
| 3991 | * callers duty to clean those orphaned rings. |
| 3992 | * |
| 3993 | * Return 0 on success, negative on failure |
| 3994 | **/ |
| 3995 | |
| 3996 | static int ixgbe_setup_all_rx_resources(struct ixgbe_adapter *adapter) |
| 3997 | { |
| 3998 | int i, err = 0; |
| 3999 | |
| 4000 | for (i = 0; i < adapter->num_rx_queues; i++) { |
| 4001 | err = ixgbe_setup_rx_resources(adapter, &adapter->rx_ring[i]); |
| 4002 | if (!err) |
| 4003 | continue; |
| 4004 | DPRINTK(PROBE, ERR, "Allocation for Rx Queue %u failed\n", i); |
| 4005 | break; |
| 4006 | } |
| 4007 | |
| 4008 | return err; |
| 4009 | } |
| 4010 | |
| 4011 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4012 | * ixgbe_free_tx_resources - Free Tx Resources per Queue |
| 4013 | * @adapter: board private structure |
| 4014 | * @tx_ring: Tx descriptor ring for a specific queue |
| 4015 | * |
| 4016 | * Free all transmit software resources |
| 4017 | **/ |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 4018 | void ixgbe_free_tx_resources(struct ixgbe_adapter *adapter, |
| 4019 | struct ixgbe_ring *tx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4020 | { |
| 4021 | struct pci_dev *pdev = adapter->pdev; |
| 4022 | |
| 4023 | ixgbe_clean_tx_ring(adapter, tx_ring); |
| 4024 | |
| 4025 | vfree(tx_ring->tx_buffer_info); |
| 4026 | tx_ring->tx_buffer_info = NULL; |
| 4027 | |
| 4028 | pci_free_consistent(pdev, tx_ring->size, tx_ring->desc, tx_ring->dma); |
| 4029 | |
| 4030 | tx_ring->desc = NULL; |
| 4031 | } |
| 4032 | |
| 4033 | /** |
| 4034 | * ixgbe_free_all_tx_resources - Free Tx Resources for All Queues |
| 4035 | * @adapter: board private structure |
| 4036 | * |
| 4037 | * Free all transmit software resources |
| 4038 | **/ |
| 4039 | static void ixgbe_free_all_tx_resources(struct ixgbe_adapter *adapter) |
| 4040 | { |
| 4041 | int i; |
| 4042 | |
| 4043 | for (i = 0; i < adapter->num_tx_queues; i++) |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 4044 | if (adapter->tx_ring[i].desc) |
| 4045 | ixgbe_free_tx_resources(adapter, &adapter->tx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4046 | } |
| 4047 | |
| 4048 | /** |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4049 | * ixgbe_free_rx_resources - Free Rx Resources |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4050 | * @adapter: board private structure |
| 4051 | * @rx_ring: ring to clean the resources from |
| 4052 | * |
| 4053 | * Free all receive software resources |
| 4054 | **/ |
Jesse Brandeburg | c431f97 | 2008-09-11 19:59:16 -0700 | [diff] [blame] | 4055 | void ixgbe_free_rx_resources(struct ixgbe_adapter *adapter, |
| 4056 | struct ixgbe_ring *rx_ring) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4057 | { |
| 4058 | struct pci_dev *pdev = adapter->pdev; |
| 4059 | |
| 4060 | ixgbe_clean_rx_ring(adapter, rx_ring); |
| 4061 | |
| 4062 | vfree(rx_ring->rx_buffer_info); |
| 4063 | rx_ring->rx_buffer_info = NULL; |
| 4064 | |
| 4065 | pci_free_consistent(pdev, rx_ring->size, rx_ring->desc, rx_ring->dma); |
| 4066 | |
| 4067 | rx_ring->desc = NULL; |
| 4068 | } |
| 4069 | |
| 4070 | /** |
| 4071 | * ixgbe_free_all_rx_resources - Free Rx Resources for All Queues |
| 4072 | * @adapter: board private structure |
| 4073 | * |
| 4074 | * Free all receive software resources |
| 4075 | **/ |
| 4076 | static void ixgbe_free_all_rx_resources(struct ixgbe_adapter *adapter) |
| 4077 | { |
| 4078 | int i; |
| 4079 | |
| 4080 | for (i = 0; i < adapter->num_rx_queues; i++) |
Jesse Brandeburg | 9891ca7 | 2009-03-13 22:14:50 +0000 | [diff] [blame] | 4081 | if (adapter->rx_ring[i].desc) |
| 4082 | ixgbe_free_rx_resources(adapter, &adapter->rx_ring[i]); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4083 | } |
| 4084 | |
| 4085 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4086 | * ixgbe_change_mtu - Change the Maximum Transfer Unit |
| 4087 | * @netdev: network interface device structure |
| 4088 | * @new_mtu: new value for maximum frame size |
| 4089 | * |
| 4090 | * Returns 0 on success, negative on failure |
| 4091 | **/ |
| 4092 | static int ixgbe_change_mtu(struct net_device *netdev, int new_mtu) |
| 4093 | { |
| 4094 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4095 | int max_frame = new_mtu + ETH_HLEN + ETH_FCS_LEN; |
| 4096 | |
Jesse Brandeburg | 42c783c | 2008-09-11 19:56:28 -0700 | [diff] [blame] | 4097 | /* MTU < 68 is an error and causes problems on some kernels */ |
| 4098 | if ((new_mtu < 68) || (max_frame > IXGBE_MAX_JUMBO_FRAME_SIZE)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4099 | return -EINVAL; |
| 4100 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4101 | DPRINTK(PROBE, INFO, "changing MTU from %d to %d\n", |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4102 | netdev->mtu, new_mtu); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4103 | /* must set new MTU before calling down or up */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4104 | netdev->mtu = new_mtu; |
| 4105 | |
Ayyappan Veeraiyan | d4f8088 | 2008-02-01 15:58:41 -0800 | [diff] [blame] | 4106 | if (netif_running(netdev)) |
| 4107 | ixgbe_reinit_locked(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4108 | |
| 4109 | return 0; |
| 4110 | } |
| 4111 | |
| 4112 | /** |
| 4113 | * ixgbe_open - Called when a network interface is made active |
| 4114 | * @netdev: network interface device structure |
| 4115 | * |
| 4116 | * Returns 0 on success, negative value on failure |
| 4117 | * |
| 4118 | * The open entry point is called when a network interface is made |
| 4119 | * active by the system (IFF_UP). At this point all resources needed |
| 4120 | * for transmit and receive operations are allocated, the interrupt |
| 4121 | * handler is registered with the OS, the watchdog timer is started, |
| 4122 | * and the stack is notified that the interface is ready. |
| 4123 | **/ |
| 4124 | static int ixgbe_open(struct net_device *netdev) |
| 4125 | { |
| 4126 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4127 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4128 | |
Auke Kok | 4bebfaa | 2008-02-11 09:26:01 -0800 | [diff] [blame] | 4129 | /* disallow open during test */ |
| 4130 | if (test_bit(__IXGBE_TESTING, &adapter->state)) |
| 4131 | return -EBUSY; |
| 4132 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 4133 | netif_carrier_off(netdev); |
| 4134 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4135 | /* allocate transmit descriptors */ |
| 4136 | err = ixgbe_setup_all_tx_resources(adapter); |
| 4137 | if (err) |
| 4138 | goto err_setup_tx; |
| 4139 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4140 | /* allocate receive descriptors */ |
| 4141 | err = ixgbe_setup_all_rx_resources(adapter); |
| 4142 | if (err) |
| 4143 | goto err_setup_rx; |
| 4144 | |
| 4145 | ixgbe_configure(adapter); |
| 4146 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 4147 | err = ixgbe_request_irq(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4148 | if (err) |
| 4149 | goto err_req_irq; |
| 4150 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4151 | err = ixgbe_up_complete(adapter); |
| 4152 | if (err) |
| 4153 | goto err_up; |
| 4154 | |
Jeff Kirsher | d55b53f | 2008-07-18 04:33:03 -0700 | [diff] [blame] | 4155 | netif_tx_start_all_queues(netdev); |
| 4156 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4157 | return 0; |
| 4158 | |
| 4159 | err_up: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 4160 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4161 | ixgbe_free_irq(adapter); |
| 4162 | err_req_irq: |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4163 | err_setup_rx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 4164 | ixgbe_free_all_rx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4165 | err_setup_tx: |
Mallikarjuna R Chilakala | a20a119 | 2009-03-31 21:34:44 +0000 | [diff] [blame] | 4166 | ixgbe_free_all_tx_resources(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4167 | ixgbe_reset(adapter); |
| 4168 | |
| 4169 | return err; |
| 4170 | } |
| 4171 | |
| 4172 | /** |
| 4173 | * ixgbe_close - Disables a network interface |
| 4174 | * @netdev: network interface device structure |
| 4175 | * |
| 4176 | * Returns 0, this is not allowed to fail |
| 4177 | * |
| 4178 | * The close entry point is called when an interface is de-activated |
| 4179 | * by the OS. The hardware is still under the drivers control, but |
| 4180 | * needs to be disabled. A global MAC reset is issued to stop the |
| 4181 | * hardware, and all transmit and receive resources are freed. |
| 4182 | **/ |
| 4183 | static int ixgbe_close(struct net_device *netdev) |
| 4184 | { |
| 4185 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4186 | |
| 4187 | ixgbe_down(adapter); |
| 4188 | ixgbe_free_irq(adapter); |
| 4189 | |
| 4190 | ixgbe_free_all_tx_resources(adapter); |
| 4191 | ixgbe_free_all_rx_resources(adapter); |
| 4192 | |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 4193 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4194 | |
| 4195 | return 0; |
| 4196 | } |
| 4197 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4198 | #ifdef CONFIG_PM |
| 4199 | static int ixgbe_resume(struct pci_dev *pdev) |
| 4200 | { |
| 4201 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4202 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 4203 | u32 err; |
| 4204 | |
| 4205 | pci_set_power_state(pdev, PCI_D0); |
| 4206 | pci_restore_state(pdev); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 4207 | |
| 4208 | err = pci_enable_device_mem(pdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4209 | if (err) { |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4210 | printk(KERN_ERR "ixgbe: Cannot enable PCI device from " |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4211 | "suspend\n"); |
| 4212 | return err; |
| 4213 | } |
| 4214 | pci_set_master(pdev); |
| 4215 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 4216 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4217 | |
| 4218 | err = ixgbe_init_interrupt_scheme(adapter); |
| 4219 | if (err) { |
| 4220 | printk(KERN_ERR "ixgbe: Cannot initialize interrupts for " |
| 4221 | "device\n"); |
| 4222 | return err; |
| 4223 | } |
| 4224 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4225 | ixgbe_reset(adapter); |
| 4226 | |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 4227 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
| 4228 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4229 | if (netif_running(netdev)) { |
| 4230 | err = ixgbe_open(adapter->netdev); |
| 4231 | if (err) |
| 4232 | return err; |
| 4233 | } |
| 4234 | |
| 4235 | netif_device_attach(netdev); |
| 4236 | |
| 4237 | return 0; |
| 4238 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4239 | #endif /* CONFIG_PM */ |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4240 | |
| 4241 | static int __ixgbe_shutdown(struct pci_dev *pdev, bool *enable_wake) |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4242 | { |
| 4243 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 4244 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4245 | struct ixgbe_hw *hw = &adapter->hw; |
| 4246 | u32 ctrl, fctrl; |
| 4247 | u32 wufc = adapter->wol; |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4248 | #ifdef CONFIG_PM |
| 4249 | int retval = 0; |
| 4250 | #endif |
| 4251 | |
| 4252 | netif_device_detach(netdev); |
| 4253 | |
| 4254 | if (netif_running(netdev)) { |
| 4255 | ixgbe_down(adapter); |
| 4256 | ixgbe_free_irq(adapter); |
| 4257 | ixgbe_free_all_tx_resources(adapter); |
| 4258 | ixgbe_free_all_rx_resources(adapter); |
| 4259 | } |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 4260 | ixgbe_clear_interrupt_scheme(adapter); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4261 | |
| 4262 | #ifdef CONFIG_PM |
| 4263 | retval = pci_save_state(pdev); |
| 4264 | if (retval) |
| 4265 | return retval; |
Jesse Brandeburg | 4df1046 | 2009-03-13 22:15:31 +0000 | [diff] [blame] | 4266 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4267 | #endif |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4268 | if (wufc) { |
| 4269 | ixgbe_set_rx_mode(netdev); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4270 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4271 | /* turn on all-multi mode if wake on multicast is enabled */ |
| 4272 | if (wufc & IXGBE_WUFC_MC) { |
| 4273 | fctrl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 4274 | fctrl |= IXGBE_FCTRL_MPE; |
| 4275 | IXGBE_WRITE_REG(hw, IXGBE_FCTRL, fctrl); |
| 4276 | } |
| 4277 | |
| 4278 | ctrl = IXGBE_READ_REG(hw, IXGBE_CTRL); |
| 4279 | ctrl |= IXGBE_CTRL_GIO_DIS; |
| 4280 | IXGBE_WRITE_REG(hw, IXGBE_CTRL, ctrl); |
| 4281 | |
| 4282 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, wufc); |
| 4283 | } else { |
| 4284 | IXGBE_WRITE_REG(hw, IXGBE_WUC, 0); |
| 4285 | IXGBE_WRITE_REG(hw, IXGBE_WUFC, 0); |
| 4286 | } |
| 4287 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 4288 | if (wufc && hw->mac.type == ixgbe_mac_82599EB) |
| 4289 | pci_wake_from_d3(pdev, true); |
| 4290 | else |
| 4291 | pci_wake_from_d3(pdev, false); |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4292 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4293 | *enable_wake = !!wufc; |
| 4294 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4295 | ixgbe_release_hw_control(adapter); |
| 4296 | |
| 4297 | pci_disable_device(pdev); |
| 4298 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4299 | return 0; |
| 4300 | } |
| 4301 | |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4302 | #ifdef CONFIG_PM |
| 4303 | static int ixgbe_suspend(struct pci_dev *pdev, pm_message_t state) |
| 4304 | { |
| 4305 | int retval; |
| 4306 | bool wake; |
| 4307 | |
| 4308 | retval = __ixgbe_shutdown(pdev, &wake); |
| 4309 | if (retval) |
| 4310 | return retval; |
| 4311 | |
| 4312 | if (wake) { |
| 4313 | pci_prepare_to_sleep(pdev); |
| 4314 | } else { |
| 4315 | pci_wake_from_d3(pdev, false); |
| 4316 | pci_set_power_state(pdev, PCI_D3hot); |
| 4317 | } |
| 4318 | |
| 4319 | return 0; |
| 4320 | } |
| 4321 | #endif /* CONFIG_PM */ |
| 4322 | |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4323 | static void ixgbe_shutdown(struct pci_dev *pdev) |
| 4324 | { |
Rafael J. Wysocki | 9d8d05a | 2009-04-15 17:44:01 +0000 | [diff] [blame] | 4325 | bool wake; |
| 4326 | |
| 4327 | __ixgbe_shutdown(pdev, &wake); |
| 4328 | |
| 4329 | if (system_state == SYSTEM_POWER_OFF) { |
| 4330 | pci_wake_from_d3(pdev, wake); |
| 4331 | pci_set_power_state(pdev, PCI_D3hot); |
| 4332 | } |
Alexander Duyck | b3c8b4b | 2008-09-11 20:04:56 -0700 | [diff] [blame] | 4333 | } |
| 4334 | |
| 4335 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4336 | * ixgbe_update_stats - Update the board statistics counters. |
| 4337 | * @adapter: board private structure |
| 4338 | **/ |
| 4339 | void ixgbe_update_stats(struct ixgbe_adapter *adapter) |
| 4340 | { |
| 4341 | struct ixgbe_hw *hw = &adapter->hw; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4342 | u64 total_mpc = 0; |
| 4343 | u32 i, missed_rx = 0, mpc, bprc, lxon, lxoff, xon_off_tot; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4344 | |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 4345 | if (hw->mac.type == ixgbe_mac_82599EB) { |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 4346 | u64 rsc_count = 0; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 4347 | for (i = 0; i < 16; i++) |
| 4348 | adapter->hw_rx_no_dma_resources += |
| 4349 | IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 4350 | for (i = 0; i < adapter->num_rx_queues; i++) |
| 4351 | rsc_count += adapter->rx_ring[i].rsc_count; |
| 4352 | adapter->rsc_count = rsc_count; |
PJ Waskiewicz | d51019a | 2009-03-13 22:12:48 +0000 | [diff] [blame] | 4353 | } |
| 4354 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4355 | adapter->stats.crcerrs += IXGBE_READ_REG(hw, IXGBE_CRCERRS); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4356 | for (i = 0; i < 8; i++) { |
| 4357 | /* for packet buffers not used, the register should read 0 */ |
| 4358 | mpc = IXGBE_READ_REG(hw, IXGBE_MPC(i)); |
| 4359 | missed_rx += mpc; |
| 4360 | adapter->stats.mpc[i] += mpc; |
| 4361 | total_mpc += adapter->stats.mpc[i]; |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4362 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4363 | adapter->stats.rnbc[i] += IXGBE_READ_REG(hw, IXGBE_RNBC(i)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4364 | adapter->stats.qptc[i] += IXGBE_READ_REG(hw, IXGBE_QPTC(i)); |
| 4365 | adapter->stats.qbtc[i] += IXGBE_READ_REG(hw, IXGBE_QBTC(i)); |
| 4366 | adapter->stats.qprc[i] += IXGBE_READ_REG(hw, IXGBE_QPRC(i)); |
| 4367 | adapter->stats.qbrc[i] += IXGBE_READ_REG(hw, IXGBE_QBRC(i)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4368 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 4369 | adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw, |
| 4370 | IXGBE_PXONRXCNT(i)); |
| 4371 | adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw, |
| 4372 | IXGBE_PXOFFRXCNT(i)); |
| 4373 | adapter->stats.qprdc[i] += IXGBE_READ_REG(hw, IXGBE_QPRDC(i)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4374 | } else { |
| 4375 | adapter->stats.pxonrxc[i] += IXGBE_READ_REG(hw, |
| 4376 | IXGBE_PXONRXC(i)); |
| 4377 | adapter->stats.pxoffrxc[i] += IXGBE_READ_REG(hw, |
| 4378 | IXGBE_PXOFFRXC(i)); |
| 4379 | } |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4380 | adapter->stats.pxontxc[i] += IXGBE_READ_REG(hw, |
| 4381 | IXGBE_PXONTXC(i)); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 4382 | adapter->stats.pxofftxc[i] += IXGBE_READ_REG(hw, |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4383 | IXGBE_PXOFFTXC(i)); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4384 | } |
| 4385 | adapter->stats.gprc += IXGBE_READ_REG(hw, IXGBE_GPRC); |
| 4386 | /* work around hardware counting issue */ |
| 4387 | adapter->stats.gprc -= missed_rx; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4388 | |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4389 | /* 82598 hardware only has a 32 bit counter in the high register */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4390 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 4391 | adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCL); |
| 4392 | IXGBE_READ_REG(hw, IXGBE_GORCH); /* to clear */ |
| 4393 | adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCL); |
| 4394 | IXGBE_READ_REG(hw, IXGBE_GOTCH); /* to clear */ |
| 4395 | adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORL); |
| 4396 | IXGBE_READ_REG(hw, IXGBE_TORH); /* to clear */ |
| 4397 | adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXCNT); |
| 4398 | adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXCNT); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4399 | adapter->stats.fdirmatch += IXGBE_READ_REG(hw, IXGBE_FDIRMATCH); |
| 4400 | adapter->stats.fdirmiss += IXGBE_READ_REG(hw, IXGBE_FDIRMISS); |
Yi Zou | 6d45522 | 2009-05-13 13:12:16 +0000 | [diff] [blame] | 4401 | #ifdef IXGBE_FCOE |
| 4402 | adapter->stats.fccrc += IXGBE_READ_REG(hw, IXGBE_FCCRC); |
| 4403 | adapter->stats.fcoerpdc += IXGBE_READ_REG(hw, IXGBE_FCOERPDC); |
| 4404 | adapter->stats.fcoeprc += IXGBE_READ_REG(hw, IXGBE_FCOEPRC); |
| 4405 | adapter->stats.fcoeptc += IXGBE_READ_REG(hw, IXGBE_FCOEPTC); |
| 4406 | adapter->stats.fcoedwrc += IXGBE_READ_REG(hw, IXGBE_FCOEDWRC); |
| 4407 | adapter->stats.fcoedwtc += IXGBE_READ_REG(hw, IXGBE_FCOEDWTC); |
| 4408 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4409 | } else { |
| 4410 | adapter->stats.lxonrxc += IXGBE_READ_REG(hw, IXGBE_LXONRXC); |
| 4411 | adapter->stats.lxoffrxc += IXGBE_READ_REG(hw, IXGBE_LXOFFRXC); |
| 4412 | adapter->stats.gorc += IXGBE_READ_REG(hw, IXGBE_GORCH); |
| 4413 | adapter->stats.gotc += IXGBE_READ_REG(hw, IXGBE_GOTCH); |
| 4414 | adapter->stats.tor += IXGBE_READ_REG(hw, IXGBE_TORH); |
| 4415 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4416 | bprc = IXGBE_READ_REG(hw, IXGBE_BPRC); |
| 4417 | adapter->stats.bprc += bprc; |
| 4418 | adapter->stats.mprc += IXGBE_READ_REG(hw, IXGBE_MPRC); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4419 | if (hw->mac.type == ixgbe_mac_82598EB) |
| 4420 | adapter->stats.mprc -= bprc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4421 | adapter->stats.roc += IXGBE_READ_REG(hw, IXGBE_ROC); |
| 4422 | adapter->stats.prc64 += IXGBE_READ_REG(hw, IXGBE_PRC64); |
| 4423 | adapter->stats.prc127 += IXGBE_READ_REG(hw, IXGBE_PRC127); |
| 4424 | adapter->stats.prc255 += IXGBE_READ_REG(hw, IXGBE_PRC255); |
| 4425 | adapter->stats.prc511 += IXGBE_READ_REG(hw, IXGBE_PRC511); |
| 4426 | adapter->stats.prc1023 += IXGBE_READ_REG(hw, IXGBE_PRC1023); |
| 4427 | adapter->stats.prc1522 += IXGBE_READ_REG(hw, IXGBE_PRC1522); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4428 | adapter->stats.rlec += IXGBE_READ_REG(hw, IXGBE_RLEC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4429 | lxon = IXGBE_READ_REG(hw, IXGBE_LXONTXC); |
| 4430 | adapter->stats.lxontxc += lxon; |
| 4431 | lxoff = IXGBE_READ_REG(hw, IXGBE_LXOFFTXC); |
| 4432 | adapter->stats.lxofftxc += lxoff; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4433 | adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 4434 | adapter->stats.gptc += IXGBE_READ_REG(hw, IXGBE_GPTC); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4435 | adapter->stats.mptc += IXGBE_READ_REG(hw, IXGBE_MPTC); |
| 4436 | /* |
| 4437 | * 82598 errata - tx of flow control packets is included in tx counters |
| 4438 | */ |
| 4439 | xon_off_tot = lxon + lxoff; |
| 4440 | adapter->stats.gptc -= xon_off_tot; |
| 4441 | adapter->stats.mptc -= xon_off_tot; |
| 4442 | adapter->stats.gotc -= (xon_off_tot * (ETH_ZLEN + ETH_FCS_LEN)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4443 | adapter->stats.ruc += IXGBE_READ_REG(hw, IXGBE_RUC); |
| 4444 | adapter->stats.rfc += IXGBE_READ_REG(hw, IXGBE_RFC); |
| 4445 | adapter->stats.rjc += IXGBE_READ_REG(hw, IXGBE_RJC); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4446 | adapter->stats.tpr += IXGBE_READ_REG(hw, IXGBE_TPR); |
| 4447 | adapter->stats.ptc64 += IXGBE_READ_REG(hw, IXGBE_PTC64); |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4448 | adapter->stats.ptc64 -= xon_off_tot; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4449 | adapter->stats.ptc127 += IXGBE_READ_REG(hw, IXGBE_PTC127); |
| 4450 | adapter->stats.ptc255 += IXGBE_READ_REG(hw, IXGBE_PTC255); |
| 4451 | adapter->stats.ptc511 += IXGBE_READ_REG(hw, IXGBE_PTC511); |
| 4452 | adapter->stats.ptc1023 += IXGBE_READ_REG(hw, IXGBE_PTC1023); |
| 4453 | adapter->stats.ptc1522 += IXGBE_READ_REG(hw, IXGBE_PTC1522); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4454 | adapter->stats.bptc += IXGBE_READ_REG(hw, IXGBE_BPTC); |
| 4455 | |
| 4456 | /* Fill out the OS statistics structure */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4457 | adapter->net_stats.multicast = adapter->stats.mprc; |
| 4458 | |
| 4459 | /* Rx Errors */ |
| 4460 | adapter->net_stats.rx_errors = adapter->stats.crcerrs + |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4461 | adapter->stats.rlec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4462 | adapter->net_stats.rx_dropped = 0; |
| 4463 | adapter->net_stats.rx_length_errors = adapter->stats.rlec; |
| 4464 | adapter->net_stats.rx_crc_errors = adapter->stats.crcerrs; |
Ayyappan Veeraiyan | 6f11eef | 2008-02-01 15:59:14 -0800 | [diff] [blame] | 4465 | adapter->net_stats.rx_missed_errors = total_mpc; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4466 | } |
| 4467 | |
| 4468 | /** |
| 4469 | * ixgbe_watchdog - Timer Call-back |
| 4470 | * @data: pointer to adapter cast into an unsigned long |
| 4471 | **/ |
| 4472 | static void ixgbe_watchdog(unsigned long data) |
| 4473 | { |
| 4474 | struct ixgbe_adapter *adapter = (struct ixgbe_adapter *)data; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4475 | struct ixgbe_hw *hw = &adapter->hw; |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4476 | u64 eics = 0; |
| 4477 | int i; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4478 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4479 | /* |
| 4480 | * Do the watchdog outside of interrupt context due to the lovely |
| 4481 | * delays that some of the newer hardware requires |
| 4482 | */ |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 4483 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4484 | if (test_bit(__IXGBE_DOWN, &adapter->state)) |
| 4485 | goto watchdog_short_circuit; |
Jesse Brandeburg | 22d5a71 | 2009-03-19 01:24:04 +0000 | [diff] [blame] | 4486 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4487 | if (!(adapter->flags & IXGBE_FLAG_MSIX_ENABLED)) { |
| 4488 | /* |
| 4489 | * for legacy and MSI interrupts don't set any bits |
| 4490 | * that are enabled for EIAM, because this operation |
| 4491 | * would set *both* EIMS and EICS for any bit in EIAM |
| 4492 | */ |
| 4493 | IXGBE_WRITE_REG(hw, IXGBE_EICS, |
| 4494 | (IXGBE_EICS_TCP_TIMER | IXGBE_EICS_OTHER)); |
| 4495 | goto watchdog_reschedule; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4496 | } |
| 4497 | |
Alexander Duyck | fe49f04 | 2009-06-04 16:00:09 +0000 | [diff] [blame] | 4498 | /* get one bit for every active tx/rx interrupt vector */ |
| 4499 | for (i = 0; i < adapter->num_msix_vectors - NON_Q_VECTORS; i++) { |
| 4500 | struct ixgbe_q_vector *qv = adapter->q_vector[i]; |
| 4501 | if (qv->rxr_count || qv->txr_count) |
| 4502 | eics |= ((u64)1 << i); |
| 4503 | } |
| 4504 | |
| 4505 | /* Cause software interrupt to ensure rx rings are cleaned */ |
| 4506 | ixgbe_irq_rearm_queues(adapter, eics); |
| 4507 | |
| 4508 | watchdog_reschedule: |
| 4509 | /* Reset the timer */ |
| 4510 | mod_timer(&adapter->watchdog_timer, round_jiffies(jiffies + 2 * HZ)); |
| 4511 | |
| 4512 | watchdog_short_circuit: |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4513 | schedule_work(&adapter->watchdog_task); |
| 4514 | } |
| 4515 | |
| 4516 | /** |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4517 | * ixgbe_multispeed_fiber_task - worker thread to configure multispeed fiber |
| 4518 | * @work: pointer to work_struct containing our data |
| 4519 | **/ |
| 4520 | static void ixgbe_multispeed_fiber_task(struct work_struct *work) |
| 4521 | { |
| 4522 | struct ixgbe_adapter *adapter = container_of(work, |
| 4523 | struct ixgbe_adapter, |
| 4524 | multispeed_fiber_task); |
| 4525 | struct ixgbe_hw *hw = &adapter->hw; |
| 4526 | u32 autoneg; |
| 4527 | |
| 4528 | adapter->flags |= IXGBE_FLAG_IN_SFP_LINK_TASK; |
Mallikarjuna R Chilakala | a1f2532 | 2009-06-30 11:44:36 +0000 | [diff] [blame] | 4529 | autoneg = hw->phy.autoneg_advertised; |
| 4530 | if ((!autoneg) && (hw->mac.ops.get_link_capabilities)) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4531 | hw->mac.ops.get_link_capabilities(hw, &autoneg, |
| 4532 | &hw->mac.autoneg); |
| 4533 | if (hw->mac.ops.setup_link_speed) |
| 4534 | hw->mac.ops.setup_link_speed(hw, autoneg, true, true); |
| 4535 | adapter->flags |= IXGBE_FLAG_NEED_LINK_UPDATE; |
| 4536 | adapter->flags &= ~IXGBE_FLAG_IN_SFP_LINK_TASK; |
| 4537 | } |
| 4538 | |
| 4539 | /** |
| 4540 | * ixgbe_sfp_config_module_task - worker thread to configure a new SFP+ module |
| 4541 | * @work: pointer to work_struct containing our data |
| 4542 | **/ |
| 4543 | static void ixgbe_sfp_config_module_task(struct work_struct *work) |
| 4544 | { |
| 4545 | struct ixgbe_adapter *adapter = container_of(work, |
| 4546 | struct ixgbe_adapter, |
| 4547 | sfp_config_module_task); |
| 4548 | struct ixgbe_hw *hw = &adapter->hw; |
| 4549 | u32 err; |
| 4550 | |
| 4551 | adapter->flags |= IXGBE_FLAG_IN_SFP_MOD_TASK; |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 4552 | |
| 4553 | /* Time for electrical oscillations to settle down */ |
| 4554 | msleep(100); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4555 | err = hw->phy.ops.identify_sfp(hw); |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 4556 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4557 | if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 88d2b81 | 2009-06-30 11:43:55 +0000 | [diff] [blame] | 4558 | dev_err(&adapter->pdev->dev, "failed to initialize because " |
| 4559 | "an unsupported SFP+ module type was detected.\n" |
| 4560 | "Reload the driver after installing a supported " |
| 4561 | "module.\n"); |
Don Skidmore | 63d6e1d | 2009-07-02 12:50:12 +0000 | [diff] [blame] | 4562 | unregister_netdev(adapter->netdev); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4563 | return; |
| 4564 | } |
| 4565 | hw->mac.ops.setup_sfp(hw); |
| 4566 | |
Tony Breeds | 8d1c3c0 | 2009-04-09 22:29:10 +0000 | [diff] [blame] | 4567 | if (!(adapter->flags & IXGBE_FLAG_IN_SFP_LINK_TASK)) |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4568 | /* This will also work for DA Twinax connections */ |
| 4569 | schedule_work(&adapter->multispeed_fiber_task); |
| 4570 | adapter->flags &= ~IXGBE_FLAG_IN_SFP_MOD_TASK; |
| 4571 | } |
| 4572 | |
| 4573 | /** |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 4574 | * ixgbe_fdir_reinit_task - worker thread to reinit FDIR filter table |
| 4575 | * @work: pointer to work_struct containing our data |
| 4576 | **/ |
| 4577 | static void ixgbe_fdir_reinit_task(struct work_struct *work) |
| 4578 | { |
| 4579 | struct ixgbe_adapter *adapter = container_of(work, |
| 4580 | struct ixgbe_adapter, |
| 4581 | fdir_reinit_task); |
| 4582 | struct ixgbe_hw *hw = &adapter->hw; |
| 4583 | int i; |
| 4584 | |
| 4585 | if (ixgbe_reinit_fdir_tables_82599(hw) == 0) { |
| 4586 | for (i = 0; i < adapter->num_tx_queues; i++) |
| 4587 | set_bit(__IXGBE_FDIR_INIT_DONE, |
| 4588 | &(adapter->tx_ring[i].reinit_state)); |
| 4589 | } else { |
| 4590 | DPRINTK(PROBE, ERR, "failed to finish FDIR re-initialization, " |
| 4591 | "ignored adding FDIR ATR filters \n"); |
| 4592 | } |
| 4593 | /* Done FDIR Re-initialization, enable transmits */ |
| 4594 | netif_tx_start_all_queues(adapter->netdev); |
| 4595 | } |
| 4596 | |
| 4597 | /** |
Alexander Duyck | 6988867 | 2008-09-11 20:05:39 -0700 | [diff] [blame] | 4598 | * ixgbe_watchdog_task - worker thread to bring link up |
| 4599 | * @work: pointer to work_struct containing our data |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4600 | **/ |
| 4601 | static void ixgbe_watchdog_task(struct work_struct *work) |
| 4602 | { |
| 4603 | struct ixgbe_adapter *adapter = container_of(work, |
| 4604 | struct ixgbe_adapter, |
| 4605 | watchdog_task); |
| 4606 | struct net_device *netdev = adapter->netdev; |
| 4607 | struct ixgbe_hw *hw = &adapter->hw; |
| 4608 | u32 link_speed = adapter->link_speed; |
| 4609 | bool link_up = adapter->link_up; |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 4610 | int i; |
| 4611 | struct ixgbe_ring *tx_ring; |
| 4612 | int some_tx_pending = 0; |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4613 | |
| 4614 | adapter->flags |= IXGBE_FLAG_IN_WATCHDOG_TASK; |
| 4615 | |
| 4616 | if (adapter->flags & IXGBE_FLAG_NEED_LINK_UPDATE) { |
| 4617 | 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] | 4618 | if (link_up) { |
| 4619 | #ifdef CONFIG_DCB |
| 4620 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 4621 | for (i = 0; i < MAX_TRAFFIC_CLASS; i++) |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 4622 | hw->mac.ops.fc_enable(hw, i); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4623 | } else { |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 4624 | hw->mac.ops.fc_enable(hw, 0); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4625 | } |
| 4626 | #else |
Mallikarjuna R Chilakala | 620fa03 | 2009-06-04 11:11:13 +0000 | [diff] [blame] | 4627 | hw->mac.ops.fc_enable(hw, 0); |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4628 | #endif |
| 4629 | } |
| 4630 | |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4631 | if (link_up || |
| 4632 | time_after(jiffies, (adapter->link_check_timeout + |
| 4633 | IXGBE_TRY_LINK_TIMEOUT))) { |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4634 | adapter->flags &= ~IXGBE_FLAG_NEED_LINK_UPDATE; |
Peter P Waskiewicz Jr | 264857b | 2009-05-17 12:35:16 +0000 | [diff] [blame] | 4635 | IXGBE_WRITE_REG(hw, IXGBE_EIMS, IXGBE_EIMC_LSC); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4636 | } |
| 4637 | adapter->link_up = link_up; |
| 4638 | adapter->link_speed = link_speed; |
| 4639 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4640 | |
| 4641 | if (link_up) { |
| 4642 | if (!netif_carrier_ok(netdev)) { |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4643 | bool flow_rx, flow_tx; |
| 4644 | |
| 4645 | if (hw->mac.type == ixgbe_mac_82599EB) { |
| 4646 | u32 mflcn = IXGBE_READ_REG(hw, IXGBE_MFLCN); |
| 4647 | u32 fccfg = IXGBE_READ_REG(hw, IXGBE_FCCFG); |
Peter P Waskiewicz Jr | 078788b | 2009-07-16 15:50:32 +0000 | [diff] [blame] | 4648 | flow_rx = !!(mflcn & IXGBE_MFLCN_RFCE); |
| 4649 | flow_tx = !!(fccfg & IXGBE_FCCFG_TFCE_802_3X); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4650 | } else { |
| 4651 | u32 frctl = IXGBE_READ_REG(hw, IXGBE_FCTRL); |
| 4652 | u32 rmcs = IXGBE_READ_REG(hw, IXGBE_RMCS); |
Peter P Waskiewicz Jr | 078788b | 2009-07-16 15:50:32 +0000 | [diff] [blame] | 4653 | flow_rx = !!(frctl & IXGBE_FCTRL_RFCE); |
| 4654 | flow_tx = !!(rmcs & IXGBE_RMCS_TFCE_802_3X); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4655 | } |
| 4656 | |
Jeff Kirsher | a46e534 | 2008-11-27 00:22:21 -0800 | [diff] [blame] | 4657 | printk(KERN_INFO "ixgbe: %s NIC Link is Up %s, " |
| 4658 | "Flow Control: %s\n", |
| 4659 | netdev->name, |
| 4660 | (link_speed == IXGBE_LINK_SPEED_10GB_FULL ? |
| 4661 | "10 Gbps" : |
| 4662 | (link_speed == IXGBE_LINK_SPEED_1GB_FULL ? |
| 4663 | "1 Gbps" : "unknown speed")), |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 4664 | ((flow_rx && flow_tx) ? "RX/TX" : |
| 4665 | (flow_rx ? "RX" : |
| 4666 | (flow_tx ? "TX" : "None")))); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4667 | |
| 4668 | netif_carrier_on(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4669 | } else { |
| 4670 | /* Force detection of hung controller */ |
| 4671 | adapter->detect_tx_hung = true; |
| 4672 | } |
| 4673 | } else { |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4674 | adapter->link_up = false; |
| 4675 | adapter->link_speed = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4676 | if (netif_carrier_ok(netdev)) { |
Jeff Kirsher | a46e534 | 2008-11-27 00:22:21 -0800 | [diff] [blame] | 4677 | printk(KERN_INFO "ixgbe: %s NIC Link is Down\n", |
| 4678 | netdev->name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4679 | netif_carrier_off(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4680 | } |
| 4681 | } |
| 4682 | |
Nelson, Shannon | bc59fcd | 2009-04-27 22:43:12 +0000 | [diff] [blame] | 4683 | if (!netif_carrier_ok(netdev)) { |
| 4684 | for (i = 0; i < adapter->num_tx_queues; i++) { |
| 4685 | tx_ring = &adapter->tx_ring[i]; |
| 4686 | if (tx_ring->next_to_use != tx_ring->next_to_clean) { |
| 4687 | some_tx_pending = 1; |
| 4688 | break; |
| 4689 | } |
| 4690 | } |
| 4691 | |
| 4692 | if (some_tx_pending) { |
| 4693 | /* We've lost link, so the controller stops DMA, |
| 4694 | * but we've got queued Tx work that's never going |
| 4695 | * to get done, so reset controller to flush Tx. |
| 4696 | * (Do the reset outside of interrupt context). |
| 4697 | */ |
| 4698 | schedule_work(&adapter->reset_task); |
| 4699 | } |
| 4700 | } |
| 4701 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4702 | ixgbe_update_stats(adapter); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 4703 | adapter->flags &= ~IXGBE_FLAG_IN_WATCHDOG_TASK; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4704 | } |
| 4705 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4706 | static int ixgbe_tso(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4707 | struct ixgbe_ring *tx_ring, struct sk_buff *skb, |
| 4708 | u32 tx_flags, u8 *hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4709 | { |
| 4710 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 4711 | unsigned int i; |
| 4712 | int err; |
| 4713 | struct ixgbe_tx_buffer *tx_buffer_info; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4714 | u32 vlan_macip_lens = 0, type_tucmd_mlhl; |
| 4715 | u32 mss_l4len_idx, l4len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4716 | |
| 4717 | if (skb_is_gso(skb)) { |
| 4718 | if (skb_header_cloned(skb)) { |
| 4719 | err = pskb_expand_head(skb, 0, 0, GFP_ATOMIC); |
| 4720 | if (err) |
| 4721 | return err; |
| 4722 | } |
| 4723 | l4len = tcp_hdrlen(skb); |
| 4724 | *hdr_len += l4len; |
| 4725 | |
Al Viro | 8327d00 | 2007-12-10 18:54:12 +0000 | [diff] [blame] | 4726 | if (skb->protocol == htons(ETH_P_IP)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4727 | struct iphdr *iph = ip_hdr(skb); |
| 4728 | iph->tot_len = 0; |
| 4729 | iph->check = 0; |
| 4730 | tcp_hdr(skb)->check = ~csum_tcpudp_magic(iph->saddr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4731 | iph->daddr, 0, |
| 4732 | IPPROTO_TCP, |
| 4733 | 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4734 | adapter->hw_tso_ctxt++; |
| 4735 | } else if (skb_shinfo(skb)->gso_type == SKB_GSO_TCPV6) { |
| 4736 | ipv6_hdr(skb)->payload_len = 0; |
| 4737 | tcp_hdr(skb)->check = |
| 4738 | ~csum_ipv6_magic(&ipv6_hdr(skb)->saddr, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4739 | &ipv6_hdr(skb)->daddr, |
| 4740 | 0, IPPROTO_TCP, 0); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4741 | adapter->hw_tso6_ctxt++; |
| 4742 | } |
| 4743 | |
| 4744 | i = tx_ring->next_to_use; |
| 4745 | |
| 4746 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4747 | context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i); |
| 4748 | |
| 4749 | /* VLAN MACLEN IPLEN */ |
| 4750 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 4751 | vlan_macip_lens |= |
| 4752 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); |
| 4753 | vlan_macip_lens |= ((skb_network_offset(skb)) << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4754 | IXGBE_ADVTXD_MACLEN_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4755 | *hdr_len += skb_network_offset(skb); |
| 4756 | vlan_macip_lens |= |
| 4757 | (skb_transport_header(skb) - skb_network_header(skb)); |
| 4758 | *hdr_len += |
| 4759 | (skb_transport_header(skb) - skb_network_header(skb)); |
| 4760 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 4761 | context_desc->seqnum_seed = 0; |
| 4762 | |
| 4763 | /* ADV DTYP TUCMD MKRLOC/ISCSIHEDLEN */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4764 | type_tucmd_mlhl = (IXGBE_TXD_CMD_DEXT | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4765 | IXGBE_ADVTXD_DTYP_CTXT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4766 | |
Al Viro | 8327d00 | 2007-12-10 18:54:12 +0000 | [diff] [blame] | 4767 | if (skb->protocol == htons(ETH_P_IP)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4768 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
| 4769 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_L4T_TCP; |
| 4770 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); |
| 4771 | |
| 4772 | /* MSS L4LEN IDX */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4773 | mss_l4len_idx = |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4774 | (skb_shinfo(skb)->gso_size << IXGBE_ADVTXD_MSS_SHIFT); |
| 4775 | mss_l4len_idx |= (l4len << IXGBE_ADVTXD_L4LEN_SHIFT); |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 4776 | /* use index 1 for TSO */ |
| 4777 | mss_l4len_idx |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4778 | context_desc->mss_l4len_idx = cpu_to_le32(mss_l4len_idx); |
| 4779 | |
| 4780 | tx_buffer_info->time_stamp = jiffies; |
| 4781 | tx_buffer_info->next_to_watch = i; |
| 4782 | |
| 4783 | i++; |
| 4784 | if (i == tx_ring->count) |
| 4785 | i = 0; |
| 4786 | tx_ring->next_to_use = i; |
| 4787 | |
| 4788 | return true; |
| 4789 | } |
| 4790 | return false; |
| 4791 | } |
| 4792 | |
| 4793 | static bool ixgbe_tx_csum(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4794 | struct ixgbe_ring *tx_ring, |
| 4795 | struct sk_buff *skb, u32 tx_flags) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4796 | { |
| 4797 | struct ixgbe_adv_tx_context_desc *context_desc; |
| 4798 | unsigned int i; |
| 4799 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 4800 | u32 vlan_macip_lens = 0, type_tucmd_mlhl = 0; |
| 4801 | |
| 4802 | if (skb->ip_summed == CHECKSUM_PARTIAL || |
| 4803 | (tx_flags & IXGBE_TX_FLAGS_VLAN)) { |
| 4804 | i = tx_ring->next_to_use; |
| 4805 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4806 | context_desc = IXGBE_TX_CTXTDESC_ADV(*tx_ring, i); |
| 4807 | |
| 4808 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 4809 | vlan_macip_lens |= |
| 4810 | (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK); |
| 4811 | vlan_macip_lens |= (skb_network_offset(skb) << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4812 | IXGBE_ADVTXD_MACLEN_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4813 | if (skb->ip_summed == CHECKSUM_PARTIAL) |
| 4814 | vlan_macip_lens |= (skb_transport_header(skb) - |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4815 | skb_network_header(skb)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4816 | |
| 4817 | context_desc->vlan_macip_lens = cpu_to_le32(vlan_macip_lens); |
| 4818 | context_desc->seqnum_seed = 0; |
| 4819 | |
| 4820 | type_tucmd_mlhl |= (IXGBE_TXD_CMD_DEXT | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4821 | IXGBE_ADVTXD_DTYP_CTXT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4822 | |
| 4823 | if (skb->ip_summed == CHECKSUM_PARTIAL) { |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4824 | switch (skb->protocol) { |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 4825 | case cpu_to_be16(ETH_P_IP): |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4826 | type_tucmd_mlhl |= IXGBE_ADVTXD_TUCMD_IPV4; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4827 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
| 4828 | type_tucmd_mlhl |= |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4829 | IXGBE_ADVTXD_TUCMD_L4T_TCP; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 4830 | else if (ip_hdr(skb)->protocol == IPPROTO_SCTP) |
| 4831 | type_tucmd_mlhl |= |
| 4832 | IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4833 | break; |
Harvey Harrison | 09640e6 | 2009-02-01 00:45:17 -0800 | [diff] [blame] | 4834 | case cpu_to_be16(ETH_P_IPV6): |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4835 | /* XXX what about other V6 headers?? */ |
| 4836 | if (ipv6_hdr(skb)->nexthdr == IPPROTO_TCP) |
| 4837 | type_tucmd_mlhl |= |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4838 | IXGBE_ADVTXD_TUCMD_L4T_TCP; |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 4839 | else if (ipv6_hdr(skb)->nexthdr == IPPROTO_SCTP) |
| 4840 | type_tucmd_mlhl |= |
| 4841 | IXGBE_ADVTXD_TUCMD_L4T_SCTP; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4842 | break; |
Auke Kok | 41825d7 | 2008-02-12 15:20:33 -0800 | [diff] [blame] | 4843 | default: |
| 4844 | if (unlikely(net_ratelimit())) { |
| 4845 | DPRINTK(PROBE, WARNING, |
| 4846 | "partial checksum but proto=%x!\n", |
| 4847 | skb->protocol); |
| 4848 | } |
| 4849 | break; |
| 4850 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4851 | } |
| 4852 | |
| 4853 | context_desc->type_tucmd_mlhl = cpu_to_le32(type_tucmd_mlhl); |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 4854 | /* use index zero for tx checksum offload */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4855 | context_desc->mss_l4len_idx = 0; |
| 4856 | |
| 4857 | tx_buffer_info->time_stamp = jiffies; |
| 4858 | tx_buffer_info->next_to_watch = i; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4859 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4860 | adapter->hw_csum_tx_good++; |
| 4861 | i++; |
| 4862 | if (i == tx_ring->count) |
| 4863 | i = 0; |
| 4864 | tx_ring->next_to_use = i; |
| 4865 | |
| 4866 | return true; |
| 4867 | } |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 4868 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4869 | return false; |
| 4870 | } |
| 4871 | |
| 4872 | static int ixgbe_tx_map(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4873 | struct ixgbe_ring *tx_ring, |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4874 | struct sk_buff *skb, u32 tx_flags, |
| 4875 | unsigned int first) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4876 | { |
| 4877 | struct ixgbe_tx_buffer *tx_buffer_info; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4878 | unsigned int len; |
| 4879 | unsigned int total = skb->len; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4880 | unsigned int offset = 0, size, count = 0, i; |
| 4881 | unsigned int nr_frags = skb_shinfo(skb)->nr_frags; |
| 4882 | unsigned int f; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 4883 | dma_addr_t *map; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4884 | |
| 4885 | i = tx_ring->next_to_use; |
| 4886 | |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 4887 | if (skb_dma_map(&adapter->pdev->dev, skb, DMA_TO_DEVICE)) { |
| 4888 | dev_err(&adapter->pdev->dev, "TX DMA map failed\n"); |
| 4889 | return 0; |
| 4890 | } |
| 4891 | |
| 4892 | map = skb_shinfo(skb)->dma_maps; |
| 4893 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4894 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) |
| 4895 | /* excluding fcoe_crc_eof for FCoE */ |
| 4896 | total -= sizeof(struct fcoe_crc_eof); |
| 4897 | |
| 4898 | len = min(skb_headlen(skb), total); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4899 | while (len) { |
| 4900 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4901 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 4902 | |
| 4903 | tx_buffer_info->length = size; |
Eric Dumazet | 042a53a | 2009-06-05 04:04:16 +0000 | [diff] [blame] | 4904 | tx_buffer_info->dma = skb_shinfo(skb)->dma_head + offset; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4905 | tx_buffer_info->time_stamp = jiffies; |
| 4906 | tx_buffer_info->next_to_watch = i; |
| 4907 | |
| 4908 | len -= size; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4909 | total -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4910 | offset += size; |
| 4911 | count++; |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 4912 | |
| 4913 | if (len) { |
| 4914 | i++; |
| 4915 | if (i == tx_ring->count) |
| 4916 | i = 0; |
| 4917 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4918 | } |
| 4919 | |
| 4920 | for (f = 0; f < nr_frags; f++) { |
| 4921 | struct skb_frag_struct *frag; |
| 4922 | |
| 4923 | frag = &skb_shinfo(skb)->frags[f]; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4924 | len = min((unsigned int)frag->size, total); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 4925 | offset = 0; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4926 | |
| 4927 | while (len) { |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 4928 | i++; |
| 4929 | if (i == tx_ring->count) |
| 4930 | i = 0; |
| 4931 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4932 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 4933 | size = min(len, (uint)IXGBE_MAX_DATA_PER_TXD); |
| 4934 | |
| 4935 | tx_buffer_info->length = size; |
Eric Dumazet | 042a53a | 2009-06-05 04:04:16 +0000 | [diff] [blame] | 4936 | tx_buffer_info->dma = map[f] + offset; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4937 | tx_buffer_info->time_stamp = jiffies; |
| 4938 | tx_buffer_info->next_to_watch = i; |
| 4939 | |
| 4940 | len -= size; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4941 | total -= size; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4942 | offset += size; |
| 4943 | count++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4944 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4945 | if (total == 0) |
| 4946 | break; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4947 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 4948 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4949 | tx_ring->tx_buffer_info[i].skb = skb; |
| 4950 | tx_ring->tx_buffer_info[first].next_to_watch = i; |
| 4951 | |
| 4952 | return count; |
| 4953 | } |
| 4954 | |
| 4955 | static void ixgbe_tx_queue(struct ixgbe_adapter *adapter, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4956 | struct ixgbe_ring *tx_ring, |
| 4957 | int tx_flags, int count, u32 paylen, u8 hdr_len) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4958 | { |
| 4959 | union ixgbe_adv_tx_desc *tx_desc = NULL; |
| 4960 | struct ixgbe_tx_buffer *tx_buffer_info; |
| 4961 | u32 olinfo_status = 0, cmd_type_len = 0; |
| 4962 | unsigned int i; |
| 4963 | u32 txd_cmd = IXGBE_TXD_CMD_EOP | IXGBE_TXD_CMD_RS | IXGBE_TXD_CMD_IFCS; |
| 4964 | |
| 4965 | cmd_type_len |= IXGBE_ADVTXD_DTYP_DATA; |
| 4966 | |
| 4967 | cmd_type_len |= IXGBE_ADVTXD_DCMD_IFCS | IXGBE_ADVTXD_DCMD_DEXT; |
| 4968 | |
| 4969 | if (tx_flags & IXGBE_TX_FLAGS_VLAN) |
| 4970 | cmd_type_len |= IXGBE_ADVTXD_DCMD_VLE; |
| 4971 | |
| 4972 | if (tx_flags & IXGBE_TX_FLAGS_TSO) { |
| 4973 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 4974 | |
| 4975 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4976 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4977 | |
PJ Waskiewicz | 4eeae6f | 2008-08-26 04:27:30 -0700 | [diff] [blame] | 4978 | /* use index 1 context for tso */ |
| 4979 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4980 | if (tx_flags & IXGBE_TX_FLAGS_IPV4) |
| 4981 | olinfo_status |= IXGBE_TXD_POPTS_IXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4982 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4983 | |
| 4984 | } else if (tx_flags & IXGBE_TX_FLAGS_CSUM) |
| 4985 | olinfo_status |= IXGBE_TXD_POPTS_TXSM << |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 4986 | IXGBE_ADVTXD_POPTS_SHIFT; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4987 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 4988 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 4989 | olinfo_status |= IXGBE_ADVTXD_CC; |
| 4990 | olinfo_status |= (1 << IXGBE_ADVTXD_IDX_SHIFT); |
| 4991 | if (tx_flags & IXGBE_TX_FLAGS_FSO) |
| 4992 | cmd_type_len |= IXGBE_ADVTXD_DCMD_TSE; |
| 4993 | } |
| 4994 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 4995 | olinfo_status |= ((paylen - hdr_len) << IXGBE_ADVTXD_PAYLEN_SHIFT); |
| 4996 | |
| 4997 | i = tx_ring->next_to_use; |
| 4998 | while (count--) { |
| 4999 | tx_buffer_info = &tx_ring->tx_buffer_info[i]; |
| 5000 | tx_desc = IXGBE_TX_DESC_ADV(*tx_ring, i); |
| 5001 | tx_desc->read.buffer_addr = cpu_to_le64(tx_buffer_info->dma); |
| 5002 | tx_desc->read.cmd_type_len = |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5003 | cpu_to_le32(cmd_type_len | tx_buffer_info->length); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5004 | tx_desc->read.olinfo_status = cpu_to_le32(olinfo_status); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5005 | i++; |
| 5006 | if (i == tx_ring->count) |
| 5007 | i = 0; |
| 5008 | } |
| 5009 | |
| 5010 | tx_desc->read.cmd_type_len |= cpu_to_le32(txd_cmd); |
| 5011 | |
| 5012 | /* |
| 5013 | * Force memory writes to complete before letting h/w |
| 5014 | * know there are new descriptors to fetch. (Only |
| 5015 | * applicable for weak-ordered memory model archs, |
| 5016 | * such as IA-64). |
| 5017 | */ |
| 5018 | wmb(); |
| 5019 | |
| 5020 | tx_ring->next_to_use = i; |
| 5021 | writel(i, adapter->hw.hw_addr + tx_ring->tail); |
| 5022 | } |
| 5023 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5024 | static void ixgbe_atr(struct ixgbe_adapter *adapter, struct sk_buff *skb, |
| 5025 | int queue, u32 tx_flags) |
| 5026 | { |
| 5027 | /* Right now, we support IPv4 only */ |
| 5028 | struct ixgbe_atr_input atr_input; |
| 5029 | struct tcphdr *th; |
| 5030 | struct udphdr *uh; |
| 5031 | struct iphdr *iph = ip_hdr(skb); |
| 5032 | struct ethhdr *eth = (struct ethhdr *)skb->data; |
| 5033 | u16 vlan_id, src_port, dst_port, flex_bytes; |
| 5034 | u32 src_ipv4_addr, dst_ipv4_addr; |
| 5035 | u8 l4type = 0; |
| 5036 | |
| 5037 | /* check if we're UDP or TCP */ |
| 5038 | if (iph->protocol == IPPROTO_TCP) { |
| 5039 | th = tcp_hdr(skb); |
| 5040 | src_port = th->source; |
| 5041 | dst_port = th->dest; |
| 5042 | l4type |= IXGBE_ATR_L4TYPE_TCP; |
| 5043 | /* l4type IPv4 type is 0, no need to assign */ |
| 5044 | } else if(iph->protocol == IPPROTO_UDP) { |
| 5045 | uh = udp_hdr(skb); |
| 5046 | src_port = uh->source; |
| 5047 | dst_port = uh->dest; |
| 5048 | l4type |= IXGBE_ATR_L4TYPE_UDP; |
| 5049 | /* l4type IPv4 type is 0, no need to assign */ |
| 5050 | } else { |
| 5051 | /* Unsupported L4 header, just bail here */ |
| 5052 | return; |
| 5053 | } |
| 5054 | |
| 5055 | memset(&atr_input, 0, sizeof(struct ixgbe_atr_input)); |
| 5056 | |
| 5057 | vlan_id = (tx_flags & IXGBE_TX_FLAGS_VLAN_MASK) >> |
| 5058 | IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5059 | src_ipv4_addr = iph->saddr; |
| 5060 | dst_ipv4_addr = iph->daddr; |
| 5061 | flex_bytes = eth->h_proto; |
| 5062 | |
| 5063 | ixgbe_atr_set_vlan_id_82599(&atr_input, vlan_id); |
| 5064 | ixgbe_atr_set_src_port_82599(&atr_input, dst_port); |
| 5065 | ixgbe_atr_set_dst_port_82599(&atr_input, src_port); |
| 5066 | ixgbe_atr_set_flex_byte_82599(&atr_input, flex_bytes); |
| 5067 | ixgbe_atr_set_l4type_82599(&atr_input, l4type); |
| 5068 | /* src and dst are inverted, think how the receiver sees them */ |
| 5069 | ixgbe_atr_set_src_ipv4_82599(&atr_input, dst_ipv4_addr); |
| 5070 | ixgbe_atr_set_dst_ipv4_82599(&atr_input, src_ipv4_addr); |
| 5071 | |
| 5072 | /* This assumes the Rx queue and Tx queue are bound to the same CPU */ |
| 5073 | ixgbe_fdir_add_signature_filter_82599(&adapter->hw, &atr_input, queue); |
| 5074 | } |
| 5075 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5076 | static int __ixgbe_maybe_stop_tx(struct net_device *netdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5077 | struct ixgbe_ring *tx_ring, int size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5078 | { |
| 5079 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5080 | |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5081 | netif_stop_subqueue(netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5082 | /* Herbert's original patch had: |
| 5083 | * smp_mb__after_netif_stop_queue(); |
| 5084 | * but since that doesn't exist yet, just open code it. */ |
| 5085 | smp_mb(); |
| 5086 | |
| 5087 | /* We need to check again in a case another CPU has just |
| 5088 | * made room available. */ |
| 5089 | if (likely(IXGBE_DESC_UNUSED(tx_ring) < size)) |
| 5090 | return -EBUSY; |
| 5091 | |
| 5092 | /* A reprieve! - use start_queue because it doesn't call schedule */ |
Jesse Brandeburg | af72166 | 2008-09-11 19:54:23 -0700 | [diff] [blame] | 5093 | netif_start_subqueue(netdev, tx_ring->queue_index); |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5094 | ++adapter->restart_queue; |
| 5095 | return 0; |
| 5096 | } |
| 5097 | |
| 5098 | static int ixgbe_maybe_stop_tx(struct net_device *netdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5099 | struct ixgbe_ring *tx_ring, int size) |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5100 | { |
| 5101 | if (likely(IXGBE_DESC_UNUSED(tx_ring) >= size)) |
| 5102 | return 0; |
| 5103 | return __ixgbe_maybe_stop_tx(netdev, tx_ring, size); |
| 5104 | } |
| 5105 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5106 | static u16 ixgbe_select_queue(struct net_device *dev, struct sk_buff *skb) |
| 5107 | { |
| 5108 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 5109 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5110 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE) |
| 5111 | return smp_processor_id(); |
| 5112 | |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5113 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 5114 | return 0; /* All traffic should default to class 0 */ |
| 5115 | |
| 5116 | return skb_tx_hash(dev, skb); |
| 5117 | } |
| 5118 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5119 | static int ixgbe_xmit_frame(struct sk_buff *skb, struct net_device *netdev) |
| 5120 | { |
| 5121 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5122 | struct ixgbe_ring *tx_ring; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5123 | unsigned int first; |
| 5124 | unsigned int tx_flags = 0; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5125 | u8 hdr_len = 0; |
| 5126 | int r_idx = 0, tso; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5127 | int count = 0; |
| 5128 | unsigned int f; |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5129 | |
Wu Fengguang | 95615d9 | 2009-04-14 21:53:48 -0700 | [diff] [blame] | 5130 | r_idx = skb->queue_mapping; |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5131 | tx_ring = &adapter->tx_ring[r_idx]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5132 | |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5133 | if (adapter->vlgrp && vlan_tx_tag_present(skb)) { |
| 5134 | tx_flags |= vlan_tx_tag_get(skb); |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5135 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 5136 | tx_flags &= ~IXGBE_TX_FLAGS_VLAN_PRIO_MASK; |
| 5137 | tx_flags |= (skb->queue_mapping << 13); |
| 5138 | } |
| 5139 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5140 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
| 5141 | } else if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) { |
| 5142 | tx_flags |= (skb->queue_mapping << 13); |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5143 | tx_flags <<= IXGBE_TX_FLAGS_VLAN_SHIFT; |
| 5144 | tx_flags |= IXGBE_TX_FLAGS_VLAN; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5145 | } |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5146 | |
| 5147 | if ((adapter->flags & IXGBE_FLAG_FCOE_ENABLED) && |
| 5148 | (skb->protocol == htons(ETH_P_FCOE))) |
| 5149 | tx_flags |= IXGBE_TX_FLAGS_FCOE; |
| 5150 | |
| 5151 | /* four things can cause us to need a context descriptor */ |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5152 | if (skb_is_gso(skb) || |
| 5153 | (skb->ip_summed == CHECKSUM_PARTIAL) || |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5154 | (tx_flags & IXGBE_TX_FLAGS_VLAN) || |
| 5155 | (tx_flags & IXGBE_TX_FLAGS_FCOE)) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5156 | count++; |
| 5157 | |
Jesse Brandeburg | 9f8cdf4 | 2008-09-11 20:03:35 -0700 | [diff] [blame] | 5158 | count += TXD_USE_COUNT(skb_headlen(skb)); |
| 5159 | for (f = 0; f < skb_shinfo(skb)->nr_frags; f++) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5160 | count += TXD_USE_COUNT(skb_shinfo(skb)->frags[f].size); |
| 5161 | |
Ayyappan Veeraiyan | e092be6 | 2008-02-01 15:58:49 -0800 | [diff] [blame] | 5162 | if (ixgbe_maybe_stop_tx(netdev, tx_ring, count)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5163 | adapter->tx_busy++; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5164 | return NETDEV_TX_BUSY; |
| 5165 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5166 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5167 | first = tx_ring->next_to_use; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5168 | if (tx_flags & IXGBE_TX_FLAGS_FCOE) { |
| 5169 | #ifdef IXGBE_FCOE |
| 5170 | /* setup tx offload for FCoE */ |
| 5171 | tso = ixgbe_fso(adapter, tx_ring, skb, tx_flags, &hdr_len); |
| 5172 | if (tso < 0) { |
| 5173 | dev_kfree_skb_any(skb); |
| 5174 | return NETDEV_TX_OK; |
| 5175 | } |
| 5176 | if (tso) |
| 5177 | tx_flags |= IXGBE_TX_FLAGS_FSO; |
| 5178 | #endif /* IXGBE_FCOE */ |
| 5179 | } else { |
| 5180 | if (skb->protocol == htons(ETH_P_IP)) |
| 5181 | tx_flags |= IXGBE_TX_FLAGS_IPV4; |
| 5182 | tso = ixgbe_tso(adapter, tx_ring, skb, tx_flags, &hdr_len); |
| 5183 | if (tso < 0) { |
| 5184 | dev_kfree_skb_any(skb); |
| 5185 | return NETDEV_TX_OK; |
| 5186 | } |
| 5187 | |
| 5188 | if (tso) |
| 5189 | tx_flags |= IXGBE_TX_FLAGS_TSO; |
| 5190 | else if (ixgbe_tx_csum(adapter, tx_ring, skb, tx_flags) && |
| 5191 | (skb->ip_summed == CHECKSUM_PARTIAL)) |
| 5192 | tx_flags |= IXGBE_TX_FLAGS_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5193 | } |
| 5194 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5195 | count = ixgbe_tx_map(adapter, tx_ring, skb, tx_flags, first); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5196 | if (count) { |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5197 | /* add the ATR filter if ATR is on */ |
| 5198 | if (tx_ring->atr_sample_rate) { |
| 5199 | ++tx_ring->atr_count; |
| 5200 | if ((tx_ring->atr_count >= tx_ring->atr_sample_rate) && |
| 5201 | test_bit(__IXGBE_FDIR_INIT_DONE, |
| 5202 | &tx_ring->reinit_state)) { |
| 5203 | ixgbe_atr(adapter, skb, tx_ring->queue_index, |
| 5204 | tx_flags); |
| 5205 | tx_ring->atr_count = 0; |
| 5206 | } |
| 5207 | } |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5208 | ixgbe_tx_queue(adapter, tx_ring, tx_flags, count, skb->len, |
| 5209 | hdr_len); |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5210 | ixgbe_maybe_stop_tx(netdev, tx_ring, DESC_NEEDED); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5211 | |
Alexander Duyck | 44df32c | 2009-03-31 21:34:23 +0000 | [diff] [blame] | 5212 | } else { |
| 5213 | dev_kfree_skb_any(skb); |
| 5214 | tx_ring->tx_buffer_info[first].time_stamp = 0; |
| 5215 | tx_ring->next_to_use = first; |
| 5216 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5217 | |
| 5218 | return NETDEV_TX_OK; |
| 5219 | } |
| 5220 | |
| 5221 | /** |
| 5222 | * ixgbe_get_stats - Get System Network Statistics |
| 5223 | * @netdev: network interface device structure |
| 5224 | * |
| 5225 | * Returns the address of the device statistics structure. |
| 5226 | * The statistics are actually updated from the timer callback. |
| 5227 | **/ |
| 5228 | static struct net_device_stats *ixgbe_get_stats(struct net_device *netdev) |
| 5229 | { |
| 5230 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5231 | |
| 5232 | /* only return the current stats */ |
| 5233 | return &adapter->net_stats; |
| 5234 | } |
| 5235 | |
| 5236 | /** |
| 5237 | * ixgbe_set_mac - Change the Ethernet Address of the NIC |
| 5238 | * @netdev: network interface device structure |
| 5239 | * @p: pointer to an address structure |
| 5240 | * |
| 5241 | * Returns 0 on success, negative on failure |
| 5242 | **/ |
| 5243 | static int ixgbe_set_mac(struct net_device *netdev, void *p) |
| 5244 | { |
| 5245 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5246 | struct ixgbe_hw *hw = &adapter->hw; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5247 | struct sockaddr *addr = p; |
| 5248 | |
| 5249 | if (!is_valid_ether_addr(addr->sa_data)) |
| 5250 | return -EADDRNOTAVAIL; |
| 5251 | |
| 5252 | memcpy(netdev->dev_addr, addr->sa_data, netdev->addr_len); |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5253 | memcpy(hw->mac.addr, addr->sa_data, netdev->addr_len); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5254 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5255 | 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] | 5256 | |
| 5257 | return 0; |
| 5258 | } |
| 5259 | |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5260 | static int |
| 5261 | ixgbe_mdio_read(struct net_device *netdev, int prtad, int devad, u16 addr) |
| 5262 | { |
| 5263 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5264 | struct ixgbe_hw *hw = &adapter->hw; |
| 5265 | u16 value; |
| 5266 | int rc; |
| 5267 | |
| 5268 | if (prtad != hw->phy.mdio.prtad) |
| 5269 | return -EINVAL; |
| 5270 | rc = hw->phy.ops.read_reg(hw, addr, devad, &value); |
| 5271 | if (!rc) |
| 5272 | rc = value; |
| 5273 | return rc; |
| 5274 | } |
| 5275 | |
| 5276 | static int ixgbe_mdio_write(struct net_device *netdev, int prtad, int devad, |
| 5277 | u16 addr, u16 value) |
| 5278 | { |
| 5279 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5280 | struct ixgbe_hw *hw = &adapter->hw; |
| 5281 | |
| 5282 | if (prtad != hw->phy.mdio.prtad) |
| 5283 | return -EINVAL; |
| 5284 | return hw->phy.ops.write_reg(hw, addr, devad, value); |
| 5285 | } |
| 5286 | |
| 5287 | static int ixgbe_ioctl(struct net_device *netdev, struct ifreq *req, int cmd) |
| 5288 | { |
| 5289 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5290 | |
| 5291 | return mdio_mii_ioctl(&adapter->hw.phy.mdio, if_mii(req), cmd); |
| 5292 | } |
| 5293 | |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5294 | /** |
| 5295 | * ixgbe_add_sanmac_netdev - Add the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 5296 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5297 | * @netdev: network interface device structure |
| 5298 | * |
| 5299 | * Returns non-zero on failure |
| 5300 | **/ |
| 5301 | static int ixgbe_add_sanmac_netdev(struct net_device *dev) |
| 5302 | { |
| 5303 | int err = 0; |
| 5304 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 5305 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 5306 | |
| 5307 | if (is_valid_ether_addr(mac->san_addr)) { |
| 5308 | rtnl_lock(); |
| 5309 | err = dev_addr_add(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 5310 | rtnl_unlock(); |
| 5311 | } |
| 5312 | return err; |
| 5313 | } |
| 5314 | |
| 5315 | /** |
| 5316 | * ixgbe_del_sanmac_netdev - Removes the SAN MAC address to the corresponding |
Jiri Pirko | 31278e7 | 2009-06-17 01:12:19 +0000 | [diff] [blame] | 5317 | * netdev->dev_addrs |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5318 | * @netdev: network interface device structure |
| 5319 | * |
| 5320 | * Returns non-zero on failure |
| 5321 | **/ |
| 5322 | static int ixgbe_del_sanmac_netdev(struct net_device *dev) |
| 5323 | { |
| 5324 | int err = 0; |
| 5325 | struct ixgbe_adapter *adapter = netdev_priv(dev); |
| 5326 | struct ixgbe_mac_info *mac = &adapter->hw.mac; |
| 5327 | |
| 5328 | if (is_valid_ether_addr(mac->san_addr)) { |
| 5329 | rtnl_lock(); |
| 5330 | err = dev_addr_del(dev, mac->san_addr, NETDEV_HW_ADDR_T_SAN); |
| 5331 | rtnl_unlock(); |
| 5332 | } |
| 5333 | return err; |
| 5334 | } |
| 5335 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5336 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5337 | /* |
| 5338 | * Polling 'interrupt' - used by things like netconsole to send skbs |
| 5339 | * without having to re-enable interrupts. It's not called while |
| 5340 | * the interrupt routine is executing. |
| 5341 | */ |
| 5342 | static void ixgbe_netpoll(struct net_device *netdev) |
| 5343 | { |
| 5344 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
| 5345 | |
| 5346 | disable_irq(adapter->pdev->irq); |
| 5347 | adapter->flags |= IXGBE_FLAG_IN_NETPOLL; |
| 5348 | ixgbe_intr(adapter->pdev->irq, netdev); |
| 5349 | adapter->flags &= ~IXGBE_FLAG_IN_NETPOLL; |
| 5350 | enable_irq(adapter->pdev->irq); |
| 5351 | } |
| 5352 | #endif |
| 5353 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5354 | static const struct net_device_ops ixgbe_netdev_ops = { |
| 5355 | .ndo_open = ixgbe_open, |
| 5356 | .ndo_stop = ixgbe_close, |
Stephen Hemminger | 0082982 | 2008-11-20 20:14:53 -0800 | [diff] [blame] | 5357 | .ndo_start_xmit = ixgbe_xmit_frame, |
Stephen Hemminger | 09a3b1f | 2009-03-21 13:40:01 -0700 | [diff] [blame] | 5358 | .ndo_select_queue = ixgbe_select_queue, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5359 | .ndo_get_stats = ixgbe_get_stats, |
Chris Leech | e90d400 | 2009-03-10 16:00:24 +0000 | [diff] [blame] | 5360 | .ndo_set_rx_mode = ixgbe_set_rx_mode, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5361 | .ndo_set_multicast_list = ixgbe_set_rx_mode, |
| 5362 | .ndo_validate_addr = eth_validate_addr, |
| 5363 | .ndo_set_mac_address = ixgbe_set_mac, |
| 5364 | .ndo_change_mtu = ixgbe_change_mtu, |
| 5365 | .ndo_tx_timeout = ixgbe_tx_timeout, |
| 5366 | .ndo_vlan_rx_register = ixgbe_vlan_rx_register, |
| 5367 | .ndo_vlan_rx_add_vid = ixgbe_vlan_rx_add_vid, |
| 5368 | .ndo_vlan_rx_kill_vid = ixgbe_vlan_rx_kill_vid, |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5369 | .ndo_do_ioctl = ixgbe_ioctl, |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5370 | #ifdef CONFIG_NET_POLL_CONTROLLER |
| 5371 | .ndo_poll_controller = ixgbe_netpoll, |
| 5372 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 5373 | #ifdef IXGBE_FCOE |
| 5374 | .ndo_fcoe_ddp_setup = ixgbe_fcoe_ddp_get, |
| 5375 | .ndo_fcoe_ddp_done = ixgbe_fcoe_ddp_put, |
| 5376 | #endif /* IXGBE_FCOE */ |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5377 | }; |
| 5378 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5379 | /** |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5380 | * ixgbe_probe - Device Initialization Routine |
| 5381 | * @pdev: PCI device information struct |
| 5382 | * @ent: entry in ixgbe_pci_tbl |
| 5383 | * |
| 5384 | * Returns 0 on success, negative on failure |
| 5385 | * |
| 5386 | * ixgbe_probe initializes an adapter identified by a pci_dev structure. |
| 5387 | * The OS initialization, configuring of the adapter private structure, |
| 5388 | * and a hardware reset occur. |
| 5389 | **/ |
| 5390 | static int __devinit ixgbe_probe(struct pci_dev *pdev, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5391 | const struct pci_device_id *ent) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5392 | { |
| 5393 | struct net_device *netdev; |
| 5394 | struct ixgbe_adapter *adapter = NULL; |
| 5395 | struct ixgbe_hw *hw; |
| 5396 | const struct ixgbe_info *ii = ixgbe_info_tbl[ent->driver_data]; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5397 | static int cards_found; |
| 5398 | int i, err, pci_using_dac; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5399 | #ifdef IXGBE_FCOE |
| 5400 | u16 device_caps; |
| 5401 | #endif |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5402 | u32 part_num, eec; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5403 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5404 | err = pci_enable_device_mem(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5405 | if (err) |
| 5406 | return err; |
| 5407 | |
Yang Hongyang | 6a35528 | 2009-04-06 19:01:13 -0700 | [diff] [blame] | 5408 | if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64)) && |
| 5409 | !pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64))) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5410 | pci_using_dac = 1; |
| 5411 | } else { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5412 | err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5413 | if (err) { |
Yang Hongyang | 284901a | 2009-04-06 19:01:15 -0700 | [diff] [blame] | 5414 | err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5415 | if (err) { |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5416 | dev_err(&pdev->dev, "No usable DMA " |
| 5417 | "configuration, aborting\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5418 | goto err_dma; |
| 5419 | } |
| 5420 | } |
| 5421 | pci_using_dac = 0; |
| 5422 | } |
| 5423 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5424 | err = pci_request_selected_regions(pdev, pci_select_bars(pdev, |
| 5425 | IORESOURCE_MEM), ixgbe_driver_name); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5426 | if (err) { |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5427 | dev_err(&pdev->dev, |
| 5428 | "pci_request_selected_regions failed 0x%x\n", err); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5429 | goto err_pci_reg; |
| 5430 | } |
| 5431 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5432 | err = pci_enable_pcie_error_reporting(pdev); |
| 5433 | if (err) { |
| 5434 | dev_err(&pdev->dev, "pci_enable_pcie_error_reporting failed " |
| 5435 | "0x%x\n", err); |
| 5436 | /* non-fatal, continue */ |
| 5437 | } |
| 5438 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5439 | pci_set_master(pdev); |
Wendy Xiong | fb3b27b | 2008-04-23 11:09:24 -0700 | [diff] [blame] | 5440 | pci_save_state(pdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5441 | |
Ayyappan Veeraiyan | 30eba97 | 2008-03-03 15:03:52 -0800 | [diff] [blame] | 5442 | netdev = alloc_etherdev_mq(sizeof(struct ixgbe_adapter), MAX_TX_QUEUES); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5443 | if (!netdev) { |
| 5444 | err = -ENOMEM; |
| 5445 | goto err_alloc_etherdev; |
| 5446 | } |
| 5447 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5448 | SET_NETDEV_DEV(netdev, &pdev->dev); |
| 5449 | |
| 5450 | pci_set_drvdata(pdev, netdev); |
| 5451 | adapter = netdev_priv(netdev); |
| 5452 | |
| 5453 | adapter->netdev = netdev; |
| 5454 | adapter->pdev = pdev; |
| 5455 | hw = &adapter->hw; |
| 5456 | hw->back = adapter; |
| 5457 | adapter->msg_enable = (1 << DEFAULT_DEBUG_LEVEL_SHIFT) - 1; |
| 5458 | |
Jeff Kirsher | 0585798 | 2008-09-11 19:57:00 -0700 | [diff] [blame] | 5459 | hw->hw_addr = ioremap(pci_resource_start(pdev, 0), |
| 5460 | pci_resource_len(pdev, 0)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5461 | if (!hw->hw_addr) { |
| 5462 | err = -EIO; |
| 5463 | goto err_ioremap; |
| 5464 | } |
| 5465 | |
| 5466 | for (i = 1; i <= 5; i++) { |
| 5467 | if (pci_resource_len(pdev, i) == 0) |
| 5468 | continue; |
| 5469 | } |
| 5470 | |
Stephen Hemminger | 0edc352 | 2008-11-19 22:24:29 -0800 | [diff] [blame] | 5471 | netdev->netdev_ops = &ixgbe_netdev_ops; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5472 | ixgbe_set_ethtool_ops(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5473 | netdev->watchdog_timeo = 5 * HZ; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5474 | strcpy(netdev->name, pci_name(pdev)); |
| 5475 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5476 | adapter->bd_number = cards_found; |
| 5477 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5478 | /* Setup hw api */ |
| 5479 | memcpy(&hw->mac.ops, ii->mac_ops, sizeof(hw->mac.ops)); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5480 | hw->mac.type = ii->mac; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5481 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5482 | /* EEPROM */ |
| 5483 | memcpy(&hw->eeprom.ops, ii->eeprom_ops, sizeof(hw->eeprom.ops)); |
| 5484 | eec = IXGBE_READ_REG(hw, IXGBE_EEC); |
| 5485 | /* If EEPROM is valid (bit 8 = 1), use default otherwise use bit bang */ |
| 5486 | if (!(eec & (1 << 8))) |
| 5487 | hw->eeprom.ops.read = &ixgbe_read_eeprom_bit_bang_generic; |
| 5488 | |
| 5489 | /* PHY */ |
| 5490 | memcpy(&hw->phy.ops, ii->phy_ops, sizeof(hw->phy.ops)); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5491 | hw->phy.sfp_type = ixgbe_sfp_type_unknown; |
Ben Hutchings | 6b73e10 | 2009-04-29 08:08:58 +0000 | [diff] [blame] | 5492 | /* ixgbe_identify_phy_generic will set prtad and mmds properly */ |
| 5493 | hw->phy.mdio.prtad = MDIO_PRTAD_NONE; |
| 5494 | hw->phy.mdio.mmds = 0; |
| 5495 | hw->phy.mdio.mode_support = MDIO_SUPPORTS_C45 | MDIO_EMULATE_C22; |
| 5496 | hw->phy.mdio.dev = netdev; |
| 5497 | hw->phy.mdio.mdio_read = ixgbe_mdio_read; |
| 5498 | hw->phy.mdio.mdio_write = ixgbe_mdio_write; |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5499 | |
| 5500 | /* set up this timer and work struct before calling get_invariants |
| 5501 | * which might start the timer |
| 5502 | */ |
| 5503 | init_timer(&adapter->sfp_timer); |
| 5504 | adapter->sfp_timer.function = &ixgbe_sfp_timer; |
| 5505 | adapter->sfp_timer.data = (unsigned long) adapter; |
| 5506 | |
| 5507 | INIT_WORK(&adapter->sfp_task, ixgbe_sfp_task); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5508 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5509 | /* multispeed fiber has its own tasklet, called from GPI SDP1 context */ |
| 5510 | INIT_WORK(&adapter->multispeed_fiber_task, ixgbe_multispeed_fiber_task); |
| 5511 | |
| 5512 | /* a new SFP+ module arrival, called from GPI SDP2 context */ |
| 5513 | INIT_WORK(&adapter->sfp_config_module_task, |
| 5514 | ixgbe_sfp_config_module_task); |
| 5515 | |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5516 | ii->get_invariants(hw); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5517 | |
| 5518 | /* setup the private structure */ |
| 5519 | err = ixgbe_sw_init(adapter); |
| 5520 | if (err) |
| 5521 | goto err_sw_init; |
| 5522 | |
Don Skidmore | bf069c9 | 2009-05-07 10:39:54 +0000 | [diff] [blame] | 5523 | /* |
| 5524 | * If there is a fan on this device and it has failed log the |
| 5525 | * failure. |
| 5526 | */ |
| 5527 | if (adapter->flags & IXGBE_FLAG_FAN_FAIL_CAPABLE) { |
| 5528 | u32 esdp = IXGBE_READ_REG(hw, IXGBE_ESDP); |
| 5529 | if (esdp & IXGBE_ESDP_SDP1) |
| 5530 | DPRINTK(PROBE, CRIT, |
| 5531 | "Fan has stopped, replace the adapter\n"); |
| 5532 | } |
| 5533 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5534 | /* reset_hw fills in the perm_addr as well */ |
| 5535 | err = hw->mac.ops.reset_hw(hw); |
Don Skidmore | 8ca783a | 2009-05-26 20:40:47 -0700 | [diff] [blame] | 5536 | if (err == IXGBE_ERR_SFP_NOT_PRESENT && |
| 5537 | hw->mac.type == ixgbe_mac_82598EB) { |
| 5538 | /* |
| 5539 | * Start a kernel thread to watch for a module to arrive. |
| 5540 | * Only do this for 82598, since 82599 will generate |
| 5541 | * interrupts on module arrival. |
| 5542 | */ |
| 5543 | set_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 5544 | mod_timer(&adapter->sfp_timer, |
| 5545 | round_jiffies(jiffies + (2 * HZ))); |
| 5546 | err = 0; |
| 5547 | } else if (err == IXGBE_ERR_SFP_NOT_SUPPORTED) { |
Don Skidmore | 88d2b81 | 2009-06-30 11:43:55 +0000 | [diff] [blame] | 5548 | dev_err(&adapter->pdev->dev, "failed to initialize because " |
| 5549 | "an unsupported SFP+ module type was detected.\n" |
| 5550 | "Reload the driver after installing a supported " |
| 5551 | "module.\n"); |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 5552 | goto err_sw_init; |
| 5553 | } else if (err) { |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5554 | dev_err(&adapter->pdev->dev, "HW Init failed: %d\n", err); |
| 5555 | goto err_sw_init; |
| 5556 | } |
| 5557 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5558 | netdev->features = NETIF_F_SG | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5559 | NETIF_F_IP_CSUM | |
| 5560 | NETIF_F_HW_VLAN_TX | |
| 5561 | NETIF_F_HW_VLAN_RX | |
| 5562 | NETIF_F_HW_VLAN_FILTER; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5563 | |
Jesse Brandeburg | e9990a9 | 2008-08-26 04:27:24 -0700 | [diff] [blame] | 5564 | netdev->features |= NETIF_F_IPV6_CSUM; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5565 | netdev->features |= NETIF_F_TSO; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5566 | netdev->features |= NETIF_F_TSO6; |
Herbert Xu | 78b6f4c | 2009-01-18 21:49:45 -0800 | [diff] [blame] | 5567 | netdev->features |= NETIF_F_GRO; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 5568 | |
Jesse Brandeburg | 45a5ead | 2009-04-27 22:36:35 +0000 | [diff] [blame] | 5569 | if (adapter->hw.mac.type == ixgbe_mac_82599EB) |
| 5570 | netdev->features |= NETIF_F_SCTP_CSUM; |
| 5571 | |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 5572 | netdev->vlan_features |= NETIF_F_TSO; |
| 5573 | netdev->vlan_features |= NETIF_F_TSO6; |
Jesse Brandeburg | 22f32b7a5 | 2008-08-26 04:27:18 -0700 | [diff] [blame] | 5574 | netdev->vlan_features |= NETIF_F_IP_CSUM; |
Jeff Kirsher | ad31c40 | 2008-06-05 04:05:30 -0700 | [diff] [blame] | 5575 | netdev->vlan_features |= NETIF_F_SG; |
| 5576 | |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5577 | if (adapter->flags & IXGBE_FLAG_DCB_ENABLED) |
| 5578 | adapter->flags &= ~IXGBE_FLAG_RSS_ENABLED; |
| 5579 | |
Jeff Kirsher | 7a6b6f5 | 2008-11-25 01:02:08 -0800 | [diff] [blame] | 5580 | #ifdef CONFIG_IXGBE_DCB |
Alexander Duyck | 2f90b86 | 2008-11-20 20:52:10 -0800 | [diff] [blame] | 5581 | netdev->dcbnl_ops = &dcbnl_ops; |
| 5582 | #endif |
| 5583 | |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5584 | #ifdef IXGBE_FCOE |
| 5585 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) { |
| 5586 | if (hw->mac.ops.get_device_caps) { |
| 5587 | hw->mac.ops.get_device_caps(hw, &device_caps); |
| 5588 | if (!(device_caps & IXGBE_DEVICE_CAPS_FCOE_OFFLOADS)) { |
| 5589 | netdev->features |= NETIF_F_FCOE_CRC; |
| 5590 | netdev->features |= NETIF_F_FSO; |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 5591 | netdev->fcoe_ddp_xid = IXGBE_FCOE_DDP_MAX - 1; |
Yi Zou | eacd73f | 2009-05-13 13:11:06 +0000 | [diff] [blame] | 5592 | } else { |
| 5593 | adapter->flags &= ~IXGBE_FLAG_FCOE_ENABLED; |
| 5594 | } |
| 5595 | } |
| 5596 | } |
| 5597 | #endif /* IXGBE_FCOE */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5598 | if (pci_using_dac) |
| 5599 | netdev->features |= NETIF_F_HIGHDMA; |
| 5600 | |
Peter P Waskiewicz Jr | df647b5 | 2009-06-04 16:00:47 +0000 | [diff] [blame] | 5601 | if (adapter->flags & IXGBE_FLAG2_RSC_ENABLED) |
Alexander Duyck | f8212f9 | 2009-04-27 22:42:37 +0000 | [diff] [blame] | 5602 | netdev->features |= NETIF_F_LRO; |
| 5603 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5604 | /* make sure the EEPROM is good */ |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5605 | if (hw->eeprom.ops.validate_checksum(hw, NULL) < 0) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5606 | dev_err(&pdev->dev, "The EEPROM Checksum Is Not Valid\n"); |
| 5607 | err = -EIO; |
| 5608 | goto err_eeprom; |
| 5609 | } |
| 5610 | |
| 5611 | memcpy(netdev->dev_addr, hw->mac.perm_addr, netdev->addr_len); |
| 5612 | memcpy(netdev->perm_addr, hw->mac.perm_addr, netdev->addr_len); |
| 5613 | |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5614 | if (ixgbe_validate_mac_addr(netdev->perm_addr)) { |
| 5615 | dev_err(&pdev->dev, "invalid MAC address\n"); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5616 | err = -EIO; |
| 5617 | goto err_eeprom; |
| 5618 | } |
| 5619 | |
| 5620 | init_timer(&adapter->watchdog_timer); |
| 5621 | adapter->watchdog_timer.function = &ixgbe_watchdog; |
| 5622 | adapter->watchdog_timer.data = (unsigned long)adapter; |
| 5623 | |
| 5624 | INIT_WORK(&adapter->reset_task, ixgbe_reset_task); |
Jesse Brandeburg | cf8280e | 2008-09-11 19:55:32 -0700 | [diff] [blame] | 5625 | INIT_WORK(&adapter->watchdog_task, ixgbe_watchdog_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5626 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5627 | err = ixgbe_init_interrupt_scheme(adapter); |
| 5628 | if (err) |
| 5629 | goto err_sw_init; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5630 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5631 | switch (pdev->device) { |
| 5632 | case IXGBE_DEV_ID_82599_KX4: |
Waskiewicz Jr, Peter P | 495dce1 | 2009-04-23 11:15:18 +0000 | [diff] [blame] | 5633 | adapter->wol = (IXGBE_WUFC_MAG | IXGBE_WUFC_EX | |
| 5634 | IXGBE_WUFC_MC | IXGBE_WUFC_BC); |
Peter P Waskiewicz Jr | bdf0a55 | 2009-06-04 11:09:58 +0000 | [diff] [blame] | 5635 | /* Enable ACPI wakeup in GRC */ |
| 5636 | IXGBE_WRITE_REG(hw, IXGBE_GRC, |
| 5637 | (IXGBE_READ_REG(hw, IXGBE_GRC) & ~IXGBE_GRC_APME)); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5638 | break; |
| 5639 | default: |
| 5640 | adapter->wol = 0; |
| 5641 | break; |
| 5642 | } |
| 5643 | device_init_wakeup(&adapter->pdev->dev, true); |
| 5644 | device_set_wakeup_enable(&adapter->pdev->dev, adapter->wol); |
| 5645 | |
PJ Waskiewicz | 04f165e | 2009-04-09 22:27:57 +0000 | [diff] [blame] | 5646 | /* pick up the PCI bus settings for reporting later */ |
| 5647 | hw->mac.ops.get_bus_info(hw); |
| 5648 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5649 | /* print bus type/speed/width info */ |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 5650 | dev_info(&pdev->dev, "(PCI Express:%s:%s) %pM\n", |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5651 | ((hw->bus.speed == ixgbe_bus_speed_5000) ? "5.0Gb/s": |
| 5652 | (hw->bus.speed == ixgbe_bus_speed_2500) ? "2.5Gb/s":"Unknown"), |
| 5653 | ((hw->bus.width == ixgbe_bus_width_pcie_x8) ? "Width x8" : |
| 5654 | (hw->bus.width == ixgbe_bus_width_pcie_x4) ? "Width x4" : |
| 5655 | (hw->bus.width == ixgbe_bus_width_pcie_x1) ? "Width x1" : |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5656 | "Unknown"), |
Johannes Berg | 7c510e4 | 2008-10-27 17:47:26 -0700 | [diff] [blame] | 5657 | netdev->dev_addr); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5658 | ixgbe_read_pba_num_generic(hw, &part_num); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5659 | if (ixgbe_is_sfp(hw) && hw->phy.sfp_type != ixgbe_sfp_type_not_present) |
| 5660 | dev_info(&pdev->dev, "MAC: %d, PHY: %d, SFP+: %d, PBA No: %06x-%03x\n", |
| 5661 | hw->mac.type, hw->phy.type, hw->phy.sfp_type, |
| 5662 | (part_num >> 8), (part_num & 0xff)); |
| 5663 | else |
| 5664 | dev_info(&pdev->dev, "MAC: %d, PHY: %d, PBA No: %06x-%03x\n", |
| 5665 | hw->mac.type, hw->phy.type, |
| 5666 | (part_num >> 8), (part_num & 0xff)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5667 | |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5668 | if (hw->bus.width <= ixgbe_bus_width_pcie_x4) { |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 5669 | dev_warn(&pdev->dev, "PCI-Express bandwidth available for " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5670 | "this card is not sufficient for optimal " |
| 5671 | "performance.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 5672 | dev_warn(&pdev->dev, "For optimal performance a x8 " |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5673 | "PCI-Express slot is required.\n"); |
Auke Kok | 0c254d8 | 2008-02-11 09:25:56 -0800 | [diff] [blame] | 5674 | } |
| 5675 | |
Peter P Waskiewicz Jr | 34b0368 | 2009-02-05 23:54:42 -0800 | [diff] [blame] | 5676 | /* save off EEPROM version number */ |
| 5677 | hw->eeprom.ops.read(hw, 0x29, &adapter->eeprom_version); |
| 5678 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5679 | /* reset the hardware with the new settings */ |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5680 | err = hw->mac.ops.start_hw(hw); |
Jesse Brandeburg | c44ade9 | 2008-09-11 19:59:59 -0700 | [diff] [blame] | 5681 | |
Peter P Waskiewicz Jr | 794caeb | 2009-06-04 16:02:24 +0000 | [diff] [blame] | 5682 | if (err == IXGBE_ERR_EEPROM_VERSION) { |
| 5683 | /* We are running on a pre-production device, log a warning */ |
| 5684 | dev_warn(&pdev->dev, "This device is a pre-production " |
| 5685 | "adapter/LOM. Please be aware there may be issues " |
| 5686 | "associated with your hardware. If you are " |
| 5687 | "experiencing problems please contact your Intel or " |
| 5688 | "hardware representative who provided you with this " |
| 5689 | "hardware.\n"); |
| 5690 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5691 | strcpy(netdev->name, "eth%d"); |
| 5692 | err = register_netdev(netdev); |
| 5693 | if (err) |
| 5694 | goto err_register; |
| 5695 | |
Jesse Brandeburg | 5438646 | 2009-04-17 20:44:27 +0000 | [diff] [blame] | 5696 | /* carrier off reporting is important to ethtool even BEFORE open */ |
| 5697 | netif_carrier_off(netdev); |
| 5698 | |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5699 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 5700 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 5701 | INIT_WORK(&adapter->fdir_reinit_task, ixgbe_fdir_reinit_task); |
| 5702 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 5703 | #ifdef CONFIG_IXGBE_DCA |
Denis V. Lunev | 652f093 | 2008-03-27 14:39:17 +0300 | [diff] [blame] | 5704 | if (dca_add_requester(&pdev->dev) == 0) { |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5705 | adapter->flags |= IXGBE_FLAG_DCA_ENABLED; |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5706 | ixgbe_setup_dca(adapter); |
| 5707 | } |
| 5708 | #endif |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5709 | /* add san mac addr to netdev */ |
| 5710 | ixgbe_add_sanmac_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5711 | |
| 5712 | dev_info(&pdev->dev, "Intel(R) 10 Gigabit Network Connection\n"); |
| 5713 | cards_found++; |
| 5714 | return 0; |
| 5715 | |
| 5716 | err_register: |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5717 | ixgbe_release_hw_control(adapter); |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5718 | ixgbe_clear_interrupt_scheme(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5719 | err_sw_init: |
| 5720 | err_eeprom: |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5721 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
| 5722 | del_timer_sync(&adapter->sfp_timer); |
| 5723 | cancel_work_sync(&adapter->sfp_task); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5724 | cancel_work_sync(&adapter->multispeed_fiber_task); |
| 5725 | cancel_work_sync(&adapter->sfp_config_module_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5726 | iounmap(hw->hw_addr); |
| 5727 | err_ioremap: |
| 5728 | free_netdev(netdev); |
| 5729 | err_alloc_etherdev: |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5730 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
| 5731 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5732 | err_pci_reg: |
| 5733 | err_dma: |
| 5734 | pci_disable_device(pdev); |
| 5735 | return err; |
| 5736 | } |
| 5737 | |
| 5738 | /** |
| 5739 | * ixgbe_remove - Device Removal Routine |
| 5740 | * @pdev: PCI device information struct |
| 5741 | * |
| 5742 | * ixgbe_remove is called by the PCI subsystem to alert the driver |
| 5743 | * that it should release a PCI device. The could be caused by a |
| 5744 | * Hot-Plug event, or because the driver is going to be removed from |
| 5745 | * memory. |
| 5746 | **/ |
| 5747 | static void __devexit ixgbe_remove(struct pci_dev *pdev) |
| 5748 | { |
| 5749 | struct net_device *netdev = pci_get_drvdata(pdev); |
| 5750 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5751 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5752 | |
| 5753 | set_bit(__IXGBE_DOWN, &adapter->state); |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5754 | /* clear the module not found bit to make sure the worker won't |
| 5755 | * reschedule |
| 5756 | */ |
| 5757 | clear_bit(__IXGBE_SFP_MODULE_NOT_FOUND, &adapter->state); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5758 | del_timer_sync(&adapter->watchdog_timer); |
| 5759 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5760 | del_timer_sync(&adapter->sfp_timer); |
| 5761 | cancel_work_sync(&adapter->watchdog_task); |
| 5762 | cancel_work_sync(&adapter->sfp_task); |
PJ Waskiewicz | e8e2635 | 2009-02-27 15:45:05 +0000 | [diff] [blame] | 5763 | cancel_work_sync(&adapter->multispeed_fiber_task); |
| 5764 | cancel_work_sync(&adapter->sfp_config_module_task); |
Peter P Waskiewicz Jr | c4cf55e | 2009-06-04 16:01:43 +0000 | [diff] [blame] | 5765 | if (adapter->flags & IXGBE_FLAG_FDIR_HASH_CAPABLE || |
| 5766 | adapter->flags & IXGBE_FLAG_FDIR_PERFECT_CAPABLE) |
| 5767 | cancel_work_sync(&adapter->fdir_reinit_task); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5768 | flush_scheduled_work(); |
| 5769 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 5770 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5771 | if (adapter->flags & IXGBE_FLAG_DCA_ENABLED) { |
| 5772 | adapter->flags &= ~IXGBE_FLAG_DCA_ENABLED; |
| 5773 | dca_remove_requester(&pdev->dev); |
| 5774 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_DCA_CTRL, 1); |
| 5775 | } |
| 5776 | |
| 5777 | #endif |
Yi Zou | 332d4a7 | 2009-05-13 13:11:53 +0000 | [diff] [blame] | 5778 | #ifdef IXGBE_FCOE |
| 5779 | if (adapter->flags & IXGBE_FLAG_FCOE_ENABLED) |
| 5780 | ixgbe_cleanup_fcoe(adapter); |
| 5781 | |
| 5782 | #endif /* IXGBE_FCOE */ |
PJ Waskiewicz | 0365e6e | 2009-05-17 12:32:25 +0000 | [diff] [blame] | 5783 | |
| 5784 | /* remove the added san mac */ |
| 5785 | ixgbe_del_sanmac_netdev(netdev); |
| 5786 | |
Donald Skidmore | c4900be | 2008-11-20 21:11:42 -0800 | [diff] [blame] | 5787 | if (netdev->reg_state == NETREG_REGISTERED) |
| 5788 | unregister_netdev(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5789 | |
Alexander Duyck | 7a921c9 | 2009-05-06 10:43:28 +0000 | [diff] [blame] | 5790 | ixgbe_clear_interrupt_scheme(adapter); |
Ayyappan Veeraiyan | 5eba369 | 2008-02-01 15:59:04 -0800 | [diff] [blame] | 5791 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5792 | ixgbe_release_hw_control(adapter); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5793 | |
| 5794 | iounmap(adapter->hw.hw_addr); |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5795 | pci_release_selected_regions(pdev, pci_select_bars(pdev, |
| 5796 | IORESOURCE_MEM)); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5797 | |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5798 | DPRINTK(PROBE, INFO, "complete\n"); |
Ayyappan Veeraiyan | 021230d | 2008-03-03 15:03:45 -0800 | [diff] [blame] | 5799 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5800 | free_netdev(netdev); |
| 5801 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5802 | err = pci_disable_pcie_error_reporting(pdev); |
| 5803 | if (err) |
| 5804 | dev_err(&pdev->dev, |
| 5805 | "pci_disable_pcie_error_reporting failed 0x%x\n", err); |
| 5806 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5807 | pci_disable_device(pdev); |
| 5808 | } |
| 5809 | |
| 5810 | /** |
| 5811 | * ixgbe_io_error_detected - called when PCI error is detected |
| 5812 | * @pdev: Pointer to PCI device |
| 5813 | * @state: The current pci connection state |
| 5814 | * |
| 5815 | * This function is called after a PCI bus error affecting |
| 5816 | * this device has been detected. |
| 5817 | */ |
| 5818 | 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] | 5819 | pci_channel_state_t state) |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5820 | { |
| 5821 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 5822 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5823 | |
| 5824 | netif_device_detach(netdev); |
| 5825 | |
Breno Leitao | 3044b8d | 2009-05-06 10:44:26 +0000 | [diff] [blame] | 5826 | if (state == pci_channel_io_perm_failure) |
| 5827 | return PCI_ERS_RESULT_DISCONNECT; |
| 5828 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5829 | if (netif_running(netdev)) |
| 5830 | ixgbe_down(adapter); |
| 5831 | pci_disable_device(pdev); |
| 5832 | |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5833 | /* Request a slot reset. */ |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5834 | return PCI_ERS_RESULT_NEED_RESET; |
| 5835 | } |
| 5836 | |
| 5837 | /** |
| 5838 | * ixgbe_io_slot_reset - called after the pci bus has been reset. |
| 5839 | * @pdev: Pointer to PCI device |
| 5840 | * |
| 5841 | * Restart the card from scratch, as if from a cold-boot. |
| 5842 | */ |
| 5843 | static pci_ers_result_t ixgbe_io_slot_reset(struct pci_dev *pdev) |
| 5844 | { |
| 5845 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 5846 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5847 | pci_ers_result_t result; |
| 5848 | int err; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5849 | |
gouji-new | 9ce7766 | 2009-05-06 10:44:45 +0000 | [diff] [blame] | 5850 | if (pci_enable_device_mem(pdev)) { |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5851 | DPRINTK(PROBE, ERR, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5852 | "Cannot re-enable PCI device after reset.\n"); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5853 | result = PCI_ERS_RESULT_DISCONNECT; |
| 5854 | } else { |
| 5855 | pci_set_master(pdev); |
| 5856 | pci_restore_state(pdev); |
| 5857 | |
Don Skidmore | dd4d8ca | 2009-04-29 00:22:31 -0700 | [diff] [blame] | 5858 | pci_wake_from_d3(pdev, false); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5859 | |
| 5860 | ixgbe_reset(adapter); |
PJ Waskiewicz | 8851253 | 2009-03-13 22:15:10 +0000 | [diff] [blame] | 5861 | IXGBE_WRITE_REG(&adapter->hw, IXGBE_WUS, ~0); |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5862 | result = PCI_ERS_RESULT_RECOVERED; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5863 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5864 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5865 | err = pci_cleanup_aer_uncorrect_error_status(pdev); |
| 5866 | if (err) { |
| 5867 | dev_err(&pdev->dev, |
| 5868 | "pci_cleanup_aer_uncorrect_error_status failed 0x%0x\n", err); |
| 5869 | /* non-fatal, continue */ |
| 5870 | } |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5871 | |
Peter P Waskiewicz Jr | 6fabd71 | 2008-12-10 01:13:08 -0800 | [diff] [blame] | 5872 | return result; |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5873 | } |
| 5874 | |
| 5875 | /** |
| 5876 | * ixgbe_io_resume - called when traffic can start flowing again. |
| 5877 | * @pdev: Pointer to PCI device |
| 5878 | * |
| 5879 | * This callback is called when the error recovery driver tells us that |
| 5880 | * its OK to resume normal operation. |
| 5881 | */ |
| 5882 | static void ixgbe_io_resume(struct pci_dev *pdev) |
| 5883 | { |
| 5884 | struct net_device *netdev = pci_get_drvdata(pdev); |
Wang Chen | 454d7c9 | 2008-11-12 23:37:49 -0800 | [diff] [blame] | 5885 | struct ixgbe_adapter *adapter = netdev_priv(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5886 | |
| 5887 | if (netif_running(netdev)) { |
| 5888 | if (ixgbe_up(adapter)) { |
| 5889 | DPRINTK(PROBE, INFO, "ixgbe_up failed after reset\n"); |
| 5890 | return; |
| 5891 | } |
| 5892 | } |
| 5893 | |
| 5894 | netif_device_attach(netdev); |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5895 | } |
| 5896 | |
| 5897 | static struct pci_error_handlers ixgbe_err_handler = { |
| 5898 | .error_detected = ixgbe_io_error_detected, |
| 5899 | .slot_reset = ixgbe_io_slot_reset, |
| 5900 | .resume = ixgbe_io_resume, |
| 5901 | }; |
| 5902 | |
| 5903 | static struct pci_driver ixgbe_driver = { |
| 5904 | .name = ixgbe_driver_name, |
| 5905 | .id_table = ixgbe_pci_tbl, |
| 5906 | .probe = ixgbe_probe, |
| 5907 | .remove = __devexit_p(ixgbe_remove), |
| 5908 | #ifdef CONFIG_PM |
| 5909 | .suspend = ixgbe_suspend, |
| 5910 | .resume = ixgbe_resume, |
| 5911 | #endif |
| 5912 | .shutdown = ixgbe_shutdown, |
| 5913 | .err_handler = &ixgbe_err_handler |
| 5914 | }; |
| 5915 | |
| 5916 | /** |
| 5917 | * ixgbe_init_module - Driver Registration Routine |
| 5918 | * |
| 5919 | * ixgbe_init_module is the first routine called when the driver is |
| 5920 | * loaded. All it does is register with the PCI subsystem. |
| 5921 | **/ |
| 5922 | static int __init ixgbe_init_module(void) |
| 5923 | { |
| 5924 | int ret; |
| 5925 | printk(KERN_INFO "%s: %s - version %s\n", ixgbe_driver_name, |
| 5926 | ixgbe_driver_string, ixgbe_driver_version); |
| 5927 | |
| 5928 | printk(KERN_INFO "%s: %s\n", ixgbe_driver_name, ixgbe_copyright); |
| 5929 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 5930 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5931 | dca_register_notify(&dca_notifier); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5932 | #endif |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 5933 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5934 | ret = pci_register_driver(&ixgbe_driver); |
| 5935 | return ret; |
| 5936 | } |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5937 | |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5938 | module_init(ixgbe_init_module); |
| 5939 | |
| 5940 | /** |
| 5941 | * ixgbe_exit_module - Driver Exit Cleanup Routine |
| 5942 | * |
| 5943 | * ixgbe_exit_module is called just before the driver is removed |
| 5944 | * from memory. |
| 5945 | **/ |
| 5946 | static void __exit ixgbe_exit_module(void) |
| 5947 | { |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 5948 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5949 | dca_unregister_notify(&dca_notifier); |
| 5950 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5951 | pci_unregister_driver(&ixgbe_driver); |
| 5952 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5953 | |
Jeff Garzik | 5dd2d33 | 2008-10-16 05:09:31 -0400 | [diff] [blame] | 5954 | #ifdef CONFIG_IXGBE_DCA |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5955 | 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] | 5956 | void *p) |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5957 | { |
| 5958 | int ret_val; |
| 5959 | |
| 5960 | ret_val = driver_for_each_device(&ixgbe_driver.driver, NULL, &event, |
Peter P Waskiewicz | b461724 | 2008-09-11 20:04:46 -0700 | [diff] [blame] | 5961 | __ixgbe_notify_dca); |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5962 | |
| 5963 | return ret_val ? NOTIFY_BAD : NOTIFY_DONE; |
| 5964 | } |
Jeb Cramer | bd0362d | 2008-03-03 15:04:02 -0800 | [diff] [blame] | 5965 | |
Alexander Duyck | b453368 | 2009-03-31 21:32:42 +0000 | [diff] [blame] | 5966 | #endif /* CONFIG_IXGBE_DCA */ |
| 5967 | #ifdef DEBUG |
| 5968 | /** |
| 5969 | * ixgbe_get_hw_dev_name - return device name string |
| 5970 | * used by hardware layer to print debugging information |
| 5971 | **/ |
| 5972 | char *ixgbe_get_hw_dev_name(struct ixgbe_hw *hw) |
| 5973 | { |
| 5974 | struct ixgbe_adapter *adapter = hw->back; |
| 5975 | return adapter->netdev->name; |
| 5976 | } |
| 5977 | |
| 5978 | #endif |
Auke Kok | 9a799d7 | 2007-09-15 14:07:45 -0700 | [diff] [blame] | 5979 | module_exit(ixgbe_exit_module); |
| 5980 | |
| 5981 | /* ixgbe_main.c */ |